From c6c8f1d693ac349d61aa9db7c420f682523555c7 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 6 Aug 2026 17:15:03 +0200 Subject: [PATCH 0001/2126] batman-adv: dat: fix printing of unknown 4addr subtype If an unknown subtype of an unicast 4addr packets was detected in batadv_dbg_arp(), it is printing the (known) packet_type instead of the subtype. This must be switched to the subtype to have any kind of use for the reader of the debug message. Reported-by: Sashiko Signed-off-by: Sven Eckelmann --- net/batman-adv/distributed-arp-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index 011cfdc47fab..270f8d6e2954 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -548,7 +548,7 @@ static void batadv_dbg_arp(struct batadv_priv *bat_priv, struct sk_buff *skb, break; default: batadv_dbg(BATADV_DBG_DAT, bat_priv, "* type: Unknown (%u)!\n", - unicast_4addr_packet->u.packet_type); + unicast_4addr_packet->subtype); } break; case BATADV_BCAST: From b963ee1dc32ce5329818e167b679b843b340d6ae Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 6 Aug 2026 18:33:24 +0200 Subject: [PATCH 0002/2126] batman-adv: drop direction in _batadv_is_ap_isolated kernel-doc The _batadv_is_ap_isolated() is called by * batadv_transtable_search() - tt_local_entry is the source - tt_global_entry is the destination * batadv_is_ap_isolated - tt_local_entry is the destination - tt_global_entry is the source It is therefore incorrect to document the tt_local_entry as sending client and tt_global_entry as the destination client. Reported-by: Sashiko Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 68f79853032e..88aeefa97db6 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -2437,8 +2437,8 @@ static void batadv_tt_global_table_free(struct batadv_priv *bat_priv) /** * _batadv_is_ap_isolated() - check whether two clients are AP-isolated from * each other - * @tt_local_entry: local TT entry of the sending client - * @tt_global_entry: global TT entry of the destination client + * @tt_local_entry: local TT entry of one local client + * @tt_global_entry: global TT entry of the remote client * * Return: true if traffic between the two clients should be dropped because * either both are WiFi clients or both carry the ISOLATION flag; false From 77f653e6f7223634111366a1f5b6b0340770105e Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 6 Aug 2026 20:54:53 +0200 Subject: [PATCH 0003/2126] batman-adv: bat_v: fix bonding candidate selection batadv_v_neigh_is_sob() implements the metric (throughput) similarity check as: neigh2 (the reference) has a better throughput than 3/4 of the neigh1 (candidate) throughput But this results in a selection of bonding candidates in batadv_find_router() which have a really low throughput. But the goal must be to select candidates which have a good throughput. The neigh1/neigh2 operands must be swapped in the comparison to use the reference as such and select only neighbor+interface combinations with good throughput. Reported-by: Sashiko Signed-off-by: Sven Eckelmann --- net/batman-adv/bat_v.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index 0c27447cf688..2d3045733db1 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -519,8 +519,8 @@ err_ifinfo1: * @neigh2: second neighbour to compare * @if_outgoing2: outgoing interface to use for @neigh2 * - * Return: true if the throughput of @neigh2 is at least 3/4 of the - * @neigh1 throughput + * Return: true if the throughput of @neigh1 is at least 3/4 of the + * @neigh2 throughput */ static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1, struct batadv_hard_iface *if_outgoing1, @@ -540,10 +540,10 @@ static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1, if (!ifinfo2) goto err_ifinfo2; - threshold = ifinfo1->bat_v.throughput / 4; - threshold = ifinfo1->bat_v.throughput - threshold; + threshold = ifinfo2->bat_v.throughput / 4; + threshold = ifinfo2->bat_v.throughput - threshold; - ret = ifinfo2->bat_v.throughput > threshold; + ret = ifinfo1->bat_v.throughput > threshold; batadv_neigh_ifinfo_put(ifinfo2); err_ifinfo2: From 7356a9232d9c84e57a71b362370b2397ef58fb26 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 6 Aug 2026 20:54:54 +0200 Subject: [PATCH 0004/2126] batman-adv: clarify cut-off in batadv_v_neigh_is_sob kernel-doc The neigh1 throughput must be more than 3/4 of the neigh2 throughput. Just 3/4 is not enough to return true. Reported-by: Sashiko Signed-off-by: Sven Eckelmann --- net/batman-adv/bat_v.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index 2d3045733db1..0d0a226c3fd0 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -519,7 +519,7 @@ err_ifinfo1: * @neigh2: second neighbour to compare * @if_outgoing2: outgoing interface to use for @neigh2 * - * Return: true if the throughput of @neigh1 is at least 3/4 of the + * Return: true if the throughput of @neigh1 is more than 3/4 of the * @neigh2 throughput */ static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1, From 776c26254d2423e61a704af2d9ab28d39969dfdc Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 6 Aug 2026 20:54:55 +0200 Subject: [PATCH 0005/2126] batman-adv: use more descriptive var names for is_similar_or_better neigh1 and neigh2 is not really helpful when looking at a code which needs to judge the metric similarity between a candidate and a reference. This already caused an implementation error in the B.A.T.M.A.N. V bonding code. Simply using "reference" and "candidate" for the neighbors is a lot more descriptive and makes it easier to understand the code. Signed-off-by: Sven Eckelmann --- net/batman-adv/bat_iv_ogm.c | 25 +++++++++++----------- net/batman-adv/bat_v.c | 42 ++++++++++++++++++------------------- net/batman-adv/types.h | 12 +++++------ 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 53fbdbbe8f4f..3fe09b4c3046 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -2424,25 +2424,26 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1, /** * batadv_iv_ogm_neigh_is_sob() - check if neigh1 is similarly good or better * than neigh2 from the metric prospective - * @neigh1: the first neighbor object of the comparison - * @if_outgoing1: outgoing interface for the first neighbor - * @neigh2: the second neighbor object of the comparison - * @if_outgoing2: outgoing interface for the second neighbor + * @candidate: the first neighbor object of the comparison + * @if_outgoing_cand: outgoing interface for the @candidate neighbor + * @reference: the second neighbor object of the comparison + * @if_outgoing_ref: outgoing interface for the @reference neighbor * - * Return: true if the metric via neigh1 is equally good or better than - * the metric via neigh2, false otherwise. + * Return: true if the metric via @candidate is equally good or better than + * the metric via @reference, false otherwise. */ static bool -batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1, - struct batadv_hard_iface *if_outgoing1, - struct batadv_neigh_node *neigh2, - struct batadv_hard_iface *if_outgoing2) +batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *candidate, + struct batadv_hard_iface *if_outgoing_cand, + struct batadv_neigh_node *reference, + struct batadv_hard_iface *if_outgoing_ref) { bool ret; int diff; - ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2, - if_outgoing2, &diff); + ret = batadv_iv_ogm_neigh_diff(candidate, if_outgoing_cand, + reference, if_outgoing_ref, + &diff); if (!ret) return false; diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index 0d0a226c3fd0..596889b3522d 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -514,40 +514,40 @@ err_ifinfo1: /** * batadv_v_neigh_is_sob() - check whether two B.A.T.M.A.N. V neighbours have * a similar or better throughput - * @neigh1: first neighbour to compare - * @if_outgoing1: outgoing interface to use for @neigh1 - * @neigh2: second neighbour to compare - * @if_outgoing2: outgoing interface to use for @neigh2 + * @candidate: the first neighbor object of the comparison + * @if_outgoing_cand: outgoing interface for the @candidate neighbor + * @reference: the second neighbor object of the comparison + * @if_outgoing_ref: outgoing interface for the @reference neighbor * - * Return: true if the throughput of @neigh1 is more than 3/4 of the - * @neigh2 throughput + * Return: true if the throughput of @candidate is more than 3/4 of the + * @reference throughput */ -static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1, - struct batadv_hard_iface *if_outgoing1, - struct batadv_neigh_node *neigh2, - struct batadv_hard_iface *if_outgoing2) +static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *candidate, + struct batadv_hard_iface *if_outgoing_cand, + struct batadv_neigh_node *reference, + struct batadv_hard_iface *if_outgoing_ref) { - struct batadv_neigh_ifinfo *ifinfo1; - struct batadv_neigh_ifinfo *ifinfo2; + struct batadv_neigh_ifinfo *ifinfo_cand; + struct batadv_neigh_ifinfo *ifinfo_ref; bool ret = false; u32 threshold; - ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); - if (!ifinfo1) + ifinfo_cand = batadv_neigh_ifinfo_get(candidate, if_outgoing_cand); + if (!ifinfo_cand) goto err_ifinfo1; - ifinfo2 = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); - if (!ifinfo2) + ifinfo_ref = batadv_neigh_ifinfo_get(reference, if_outgoing_ref); + if (!ifinfo_ref) goto err_ifinfo2; - threshold = ifinfo2->bat_v.throughput / 4; - threshold = ifinfo2->bat_v.throughput - threshold; + threshold = ifinfo_ref->bat_v.throughput / 4; + threshold = ifinfo_ref->bat_v.throughput - threshold; - ret = ifinfo1->bat_v.throughput > threshold; + ret = ifinfo_cand->bat_v.throughput > threshold; - batadv_neigh_ifinfo_put(ifinfo2); + batadv_neigh_ifinfo_put(ifinfo_ref); err_ifinfo2: - batadv_neigh_ifinfo_put(ifinfo1); + batadv_neigh_ifinfo_put(ifinfo_cand); err_ifinfo1: return ret; } diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 9bdc5a3e799e..99667f632d4d 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -2087,14 +2087,14 @@ struct batadv_algo_neigh_ops { struct batadv_hard_iface *if_outgoing2); /** - * @is_similar_or_better: check if neigh1 is equally similar or better - * than neigh2 for their respective outgoing interface from the metric + * @is_similar_or_better: check if @candidate is equally similar or better + * than @reference for their respective outgoing interface from the metric * prospective */ - bool (*is_similar_or_better)(struct batadv_neigh_node *neigh1, - struct batadv_hard_iface *if_outgoing1, - struct batadv_neigh_node *neigh2, - struct batadv_hard_iface *if_outgoing2); + bool (*is_similar_or_better)(struct batadv_neigh_node *candidate, + struct batadv_hard_iface *if_outgoing_cand, + struct batadv_neigh_node *reference, + struct batadv_hard_iface *if_outgoing_ref); /** @dump: dump neighbors to a netlink socket (optional) */ void (*dump)(struct sk_buff *msg, struct netlink_callback *cb, From a5f7058bee1ec6d0df7a0dc20279775ee116f3fb Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sat, 22 Aug 2026 15:14:03 +0200 Subject: [PATCH 0006/2126] batman-adv: ensure u16 aligned mac address arrays on stack An u8 array on the stack has a natural alignment of only 1 byte. An u8[ETH_ALEN] array on the stack must therefore be assumed to only be 1 byte aligned. But many etherdevices.h functions are requiring a 2 byte (u16) alignment. Annote all u8[ETH_ALEN] arrays on the stack as __aligned(2) to make sure that the compiler takes care of aligning it correctly. Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260821094813.201800-1-sw%40simonwunderlich.de?part=5 Signed-off-by: Sven Eckelmann --- net/batman-adv/bridge_loop_avoidance.c | 6 ++++-- net/batman-adv/distributed-arp-table.c | 8 ++++---- net/batman-adv/mesh-interface.c | 12 ++++++++---- net/batman-adv/multicast.c | 6 +++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index f635da4b8ca6..ad6ab4a50658 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -663,7 +663,7 @@ static void batadv_bla_send_request(struct batadv_bla_backbone_gw *backbone_gw) static void batadv_bla_send_announce(struct batadv_priv *bat_priv, struct batadv_bla_backbone_gw *backbone_gw) { - u8 mac[ETH_ALEN]; + u8 mac[ETH_ALEN] __aligned(2); __be16 crc; memcpy(mac, batadv_announce_mac, 4); @@ -1582,7 +1582,9 @@ static struct lock_class_key batadv_backbone_hash_lock_class_key; */ int batadv_bla_init(struct batadv_priv *bat_priv) { - u8 claim_dest[ETH_ALEN] = {0xff, 0x43, 0x05, 0x00, 0x00, 0x00}; + static const u8 claim_dest[ETH_ALEN] __aligned(2) = { + 0xff, 0x43, 0x05, 0x00, 0x00, 0x00 + }; struct batadv_hard_iface *primary_if; unsigned long entrytime; u16 crc; diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index 270f8d6e2954..a4be5b2a87d7 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -940,7 +940,7 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid, struct netlink_callback *cb, struct batadv_dat_entry *dat_entry) { - u8 mac[ETH_ALEN]; + u8 mac[ETH_ALEN] __aligned(2); u64 u64_mac; int msecs; void *hdr; @@ -1236,10 +1236,10 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, { struct net_device *mesh_iface = bat_priv->mesh_iface; struct batadv_dat_entry *dat_entry = NULL; + u8 mac[ETH_ALEN] __aligned(2); struct sk_buff *skb_new; unsigned short vid; bool ret = false; - u8 mac[ETH_ALEN]; int hdr_size = 0; __be32 ip_dst; __be32 ip_src; @@ -1344,10 +1344,10 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, struct sk_buff *skb, int hdr_size) { struct batadv_dat_entry *dat_entry = NULL; + u8 mac[ETH_ALEN] __aligned(2); struct sk_buff *skb_new; unsigned short vid; bool ret = false; - u8 mac[ETH_ALEN]; __be32 ip_src; __be32 ip_dst; u64 u64_mac; @@ -1474,9 +1474,9 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv, struct sk_buff *skb, int hdr_size) { struct batadv_dat_entry *dat_entry = NULL; + u8 mac[ETH_ALEN] __aligned(2); bool dropped = false; unsigned short vid; - u8 mac[ETH_ALEN]; __be32 ip_src; __be32 ip_dst; u64 u64_mac; diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c index e202088cf1fd..63af21954cf9 100644 --- a/net/batman-adv/mesh-interface.c +++ b/net/batman-adv/mesh-interface.c @@ -141,9 +141,9 @@ static struct net_device_stats *batadv_interface_stats(struct net_device *dev) static int batadv_interface_set_mac_addr(struct net_device *dev, void *p) { struct batadv_priv *bat_priv = netdev_priv(dev); + u8 old_addr[ETH_ALEN] __aligned(2); struct batadv_meshif_vlan *vlan; struct sockaddr *addr = p; - u8 old_addr[ETH_ALEN]; if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL; @@ -213,13 +213,18 @@ static void batadv_interface_set_rx_mode(struct net_device *dev) static netdev_tx_t batadv_interface_tx(struct sk_buff *skb, struct net_device *mesh_iface) { - static const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00, 0x00, 0x00}; - static const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x00}; struct batadv_priv *bat_priv = netdev_priv(mesh_iface); enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO; enum batadv_forw_mode forw_mode = BATADV_FORW_BCAST; + static const u8 ectp_addr[ETH_ALEN] __aligned(2) = { + 0xCF, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + static const u8 stp_addr[ETH_ALEN] __aligned(2) = { + 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 + }; struct batadv_hard_iface *primary_if = NULL; struct batadv_bcast_packet *bcast_packet; + u8 chaddr[ETH_ALEN] __aligned(2); int network_offset = ETH_HLEN; unsigned int header_len = 0; unsigned long brd_delay = 0; @@ -229,7 +234,6 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb, struct ethhdr *ethhdr; bool do_bcast = false; u8 *dst_hint = NULL; - u8 chaddr[ETH_ALEN]; unsigned short vid; bool client_added; __be16 proto; diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c index 82fd527b61c0..22dd28d5e1ab 100644 --- a/net/batman-adv/multicast.c +++ b/net/batman-adv/multicast.c @@ -368,9 +368,9 @@ batadv_mcast_mla_meshif_get_ipv4(struct net_device *dev, struct hlist_head *mcast_list, struct batadv_mcast_mla_flags *flags) { + u8 mcast_addr[ETH_ALEN] __aligned(2); struct batadv_hw_addr *new; struct in_device *in_dev; - u8 mcast_addr[ETH_ALEN]; struct ip_mc_list *pmc; int ret = 0; @@ -435,9 +435,9 @@ batadv_mcast_mla_meshif_get_ipv6(struct net_device *dev, struct hlist_head *mcast_list, struct batadv_mcast_mla_flags *flags) { + u8 mcast_addr[ETH_ALEN] __aligned(2); struct batadv_hw_addr *new; struct inet6_dev *in6_dev; - u8 mcast_addr[ETH_ALEN]; struct ifmcaddr6 *pmc6; int ret = 0; @@ -587,10 +587,10 @@ static int batadv_mcast_mla_bridge_get(struct net_device *dev, struct batadv_mcast_mla_flags *flags) { struct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list); + u8 mcast_addr[ETH_ALEN] __aligned(2); u8 tvlv_flags = flags->tvlv_flags; struct br_ip_list *br_ip_entry; struct batadv_hw_addr *new; - u8 mcast_addr[ETH_ALEN]; struct br_ip_list *tmp; int ret; From d9304a90eca5703ae8301415b417ad63ddd44d7f Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sat, 22 Aug 2026 15:14:04 +0200 Subject: [PATCH 0007/2126] batman-adv: ensure u16 aligned mac address in structs An u8 array in structures have a natural alignment of only 1 byte. An u8[ETH_ALEN] array must therefore be assumed to only be 1 byte aligned. But many etherdevices.h functions are requiring a 2 byte (u16) alignment. All these addresses were either on the start of a struct or after a struct member which required at least an alignment of 2 byte. Still, annote all u8[ETH_ALEN] arrays on the stack as __aligned(2) to make sure that this assumption isn't broken by other modifications inside the structs. Signed-off-by: Sven Eckelmann --- net/batman-adv/types.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 99667f632d4d..c42a4aa8f41a 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -410,7 +410,7 @@ struct batadv_orig_bat_iv { */ struct batadv_orig_node { /** @orig: originator ethernet address */ - u8 orig[ETH_ALEN]; + u8 orig[ETH_ALEN] __aligned(2); /** @ifinfo_list: list for routers per outgoing interface */ struct hlist_head ifinfo_list; @@ -634,12 +634,12 @@ struct batadv_hardif_neigh_node { struct hlist_node list; /** @addr: the MAC address of the neighboring interface */ - u8 addr[ETH_ALEN]; + u8 addr[ETH_ALEN] __aligned(2); /** * @orig: the address of the originator this neighbor node belongs to */ - u8 orig[ETH_ALEN]; + u8 orig[ETH_ALEN] __aligned(2); /** @if_incoming: pointer to incoming hard-interface */ struct batadv_hard_iface *if_incoming; @@ -677,7 +677,7 @@ struct batadv_neigh_node { #endif /** @addr: the MAC address of the neighboring interface */ - u8 addr[ETH_ALEN]; + u8 addr[ETH_ALEN] __aligned(2); /** @ifinfo_list: list for routing metrics per outgoing interface */ struct hlist_head ifinfo_list; @@ -777,7 +777,7 @@ struct batadv_neigh_ifinfo { */ struct batadv_bcast_duplist_entry { /** @orig: mac address of orig node originating the broadcast */ - u8 orig[ETH_ALEN]; + u8 orig[ETH_ALEN] __aligned(2); /** @crc: crc32 checksum of broadcast payload */ u32 crc; @@ -1085,7 +1085,7 @@ struct batadv_priv_bla { struct batadv_hashtable *backbone_hash; /** @loopdetect_addr: MAC address used for own loopdetection frames */ - u8 loopdetect_addr[ETH_ALEN]; + u8 loopdetect_addr[ETH_ALEN] __aligned(2); /** * @loopdetect_lasttime: time when the loopdetection frames were sent @@ -1352,7 +1352,7 @@ struct batadv_tp_vars_common { struct batadv_priv *bat_priv; /** @other_end: mac address of remote */ - u8 other_end[ETH_ALEN]; + u8 other_end[ETH_ALEN] __aligned(2); /** @session: TP session identifier */ u8 session[2]; @@ -1765,7 +1765,7 @@ struct batadv_bla_backbone_gw { * @orig: originator address of backbone node (mac address of primary * iface) */ - u8 orig[ETH_ALEN]; + u8 orig[ETH_ALEN] __aligned(2); /** @vid: vlan id this gateway was detected on */ unsigned short vid; @@ -1810,7 +1810,7 @@ struct batadv_bla_backbone_gw { */ struct batadv_bla_claim { /** @addr: mac address of claimed non-mesh client */ - u8 addr[ETH_ALEN]; + u8 addr[ETH_ALEN] __aligned(2); /** @vid: vlan id this client was detected on */ unsigned short vid; @@ -1840,7 +1840,7 @@ struct batadv_bla_claim { */ struct batadv_tt_common_entry { /** @addr: mac address of non-mesh client */ - u8 addr[ETH_ALEN]; + u8 addr[ETH_ALEN] __aligned(2); /** @vid: VLAN identifier */ unsigned short vid; @@ -1942,7 +1942,7 @@ struct batadv_tt_req_node { /** * @addr: mac address of the originator this request was sent to */ - u8 addr[ETH_ALEN]; + u8 addr[ETH_ALEN] __aligned(2); /** @issued_at: timestamp used for purging stale tt requests */ unsigned long issued_at; @@ -1959,7 +1959,7 @@ struct batadv_tt_req_node { */ struct batadv_tt_roam_node { /** @addr: mac address of the client in the roaming phase */ - u8 addr[ETH_ALEN]; + u8 addr[ETH_ALEN] __aligned(2); /** @vid: VLAN identifier */ u16 vid; @@ -2204,7 +2204,7 @@ struct batadv_hw_addr { struct hlist_node list; /** @addr: the MAC address of this list entry */ - unsigned char addr[ETH_ALEN]; + unsigned char addr[ETH_ALEN] __aligned(2); }; /** From bbfb0d2cf03538d3db0580849720bc5fe773d515 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:38 +0200 Subject: [PATCH 0008/2126] batman-adv: tt: remove only the entry which was looked up from the hash batadv_hash_remove() searches a bucket with a compare callback and unlinks the first matching entry. batadv_compare_tt() matches any entry for the same MAC address and VLAN, not the object which was passed in, and the callers in batadv_tt_local_remove() and batadv_tt_global_free() are not serialized against the rest of the translation table in any way. So when the looked up entry was already unlinked by another context and a new entry for the same client was added in the meantime, these two functions unlink that new entry instead. Add batadv_compare_tt_entry(), which matches the very object which is searched for, and use it for both removals. Nothing is unlinked when the entry is gone already, batadv_hash_remove() then simply returns NULL and only the reference of the calling context is dropped. As a side effect the returned hlist_node can no longer belong to a different object, so both functions can operate on the entry they were given. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 88aeefa97db6..66456a2d45e2 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -95,6 +95,26 @@ static bool batadv_compare_tt(const struct hlist_node *node, const void *data2) return (tt1->vid == tt2->vid) && batadv_compare_eth(data1, data2); } +/** + * batadv_compare_tt_entry() - check if a hash node is a specific TT entry + * @node: the list element pointer of the TT entry stored in the bucket + * @data2: pointer to the tt_common_entry which is looked for + * + * Unlike batadv_compare_tt(), this only matches the very object which is + * passed as @data2 and not just any entry for the same TT client. It is meant + * for batadv_hash_remove() callers which must not unlink an entry they did not + * look up themselves. + * + * Return: true if @node belongs to @data2, false otherwise + */ +static bool batadv_compare_tt_entry(const struct hlist_node *node, + const void *data2) +{ + const struct batadv_tt_common_entry *tt = data2; + + return node == &tt->hash_entry; +} + /** * batadv_choose_tt() - return the index of the tt entry in the hash table * @data: pointer to the tt_common_entry object to map @@ -575,7 +595,6 @@ static void batadv_tt_global_free(struct batadv_priv *bat_priv, struct batadv_tt_global_entry *tt_global, const char *message) { - struct batadv_tt_global_entry *tt_removed_entry; struct hlist_node *tt_removed_node; batadv_dbg(BATADV_DBG_TT, bat_priv, @@ -583,18 +602,16 @@ static void batadv_tt_global_free(struct batadv_priv *bat_priv, tt_global->common.addr, batadv_print_vid(tt_global->common.vid), message); + /* remove exactly this object when still present in hash */ tt_removed_node = batadv_hash_remove(bat_priv->tt.global_hash, - batadv_compare_tt, + batadv_compare_tt_entry, batadv_choose_tt, &tt_global->common); if (!tt_removed_node) return; /* drop reference of remove hash entry */ - tt_removed_entry = hlist_entry(tt_removed_node, - struct batadv_tt_global_entry, - common.hash_entry); - batadv_tt_global_entry_put(tt_removed_entry); + batadv_tt_global_entry_put(tt_global); } /** @@ -1292,7 +1309,6 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, unsigned short vid, const char *message, bool roaming) { - struct batadv_tt_local_entry *tt_removed_entry; struct batadv_tt_local_entry *tt_local_entry; struct hlist_node *tt_removed_node; u16 curr_flags = BATADV_NO_FLAGS; @@ -1325,18 +1341,16 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, */ batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); + /* remove exactly this object when still present in hash */ tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash, - batadv_compare_tt, + batadv_compare_tt_entry, batadv_choose_tt, &tt_local_entry->common); if (!tt_removed_node) goto out; /* drop reference of remove hash entry */ - tt_removed_entry = hlist_entry(tt_removed_node, - struct batadv_tt_local_entry, - common.hash_entry); - batadv_tt_local_entry_put(tt_removed_entry); + batadv_tt_local_entry_put(tt_local_entry); out: batadv_tt_local_entry_put(tt_local_entry); From fd8d892c685ad08915e6cebf8ec125ccd01c8e6f Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:39 +0200 Subject: [PATCH 0009/2126] batman-adv: tt: extract code handling a roam on add The code for handling the roaming of clients is mostly self contained but embedded in the already too large batadv_tt_local_add function. The maintainability can be improved by keeping it in an separate function. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 71 +++++++++++++++++++----------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 66456a2d45e2..01c74d4a7e52 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -614,6 +614,50 @@ static void batadv_tt_global_free(struct batadv_priv *bat_priv, batadv_tt_global_entry_put(tt_global); } +/** + * batadv_tt_local_add_roam() - handle roamed clients during batadv_tt_local_add() + * @bat_priv: the bat priv with all the mesh interface information + * @tt_global: the global TT entry + * @roamed_back: whether @tt_global roamed back + */ +static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv, + struct batadv_tt_global_entry *tt_global, + bool roamed_back) +{ + struct batadv_tt_orig_list_entry *orig_entry; + struct hlist_head *head; + + if (!tt_global) + return; + + /* Check whether it is a roaming, but don't do anything if the roaming + * process has already been handled + */ + if (tt_global->common.flags & BATADV_TT_CLIENT_ROAM) + return; + + /* These node are probably going to update their tt table */ + head = &tt_global->orig_list; + rcu_read_lock(); + hlist_for_each_entry_rcu(orig_entry, head, list) { + batadv_send_roam_adv(bat_priv, tt_global->common.addr, + tt_global->common.vid, + orig_entry->orig_node); + } + rcu_read_unlock(); + + if (roamed_back) { + batadv_tt_global_free(bat_priv, tt_global, + "Roaming canceled"); + } else { + /* The global entry has to be marked as ROAMING and + * has to be kept for consistency purpose + */ + tt_global->common.flags |= BATADV_TT_CLIENT_ROAM; + tt_global->roam_at = jiffies; + } +} + /** * batadv_tt_local_add() - add a new client to the local table or update an * existing client @@ -632,14 +676,12 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, { struct batadv_priv *bat_priv = netdev_priv(mesh_iface); struct batadv_tt_global_entry *tt_global = NULL; - struct batadv_tt_orig_list_entry *orig_entry; struct batadv_tt_local_entry *tt_local; struct net *net = dev_net(mesh_iface); struct net_device *in_dev = NULL; struct batadv_meshif_vlan *vlan; bool roamed_back = false; bool iif_is_wifi = false; - struct hlist_head *head; int packet_size_max; bool ret = false; u8 remote_flags; @@ -758,30 +800,7 @@ add_event: batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); check_roaming: - /* Check whether it is a roaming, but don't do anything if the roaming - * process has already been handled - */ - if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) { - /* These node are probably going to update their tt table */ - head = &tt_global->orig_list; - rcu_read_lock(); - hlist_for_each_entry_rcu(orig_entry, head, list) { - batadv_send_roam_adv(bat_priv, tt_global->common.addr, - tt_global->common.vid, - orig_entry->orig_node); - } - rcu_read_unlock(); - if (roamed_back) { - batadv_tt_global_free(bat_priv, tt_global, - "Roaming canceled"); - } else { - /* The global entry has to be marked as ROAMING and - * has to be kept for consistency purpose - */ - tt_global->common.flags |= BATADV_TT_CLIENT_ROAM; - tt_global->roam_at = jiffies; - } - } + batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back); /* store the current remote flags before altering them. This helps * understanding is flags are changing or not From e103fbefa049d82cac3bec350059e872efecc331 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:40 +0200 Subject: [PATCH 0010/2126] batman-adv: tt: simplify NEW flag transition code The function batadv_tt_local_set_flags() implements support for various flags and to set/unset them. It is also possible to decide whether this change should increase the TT size or not. But in reality, this function is only used to transition tt local entries from the NEW state and count these entries. Remove the rest of the code to simplify the function. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 01c74d4a7e52..2f7951e4c320 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -3815,15 +3815,11 @@ void batadv_tt_free(struct batadv_priv *bat_priv) } /** - * batadv_tt_local_set_flags() - set or unset the specified flags on the local - * table and possibly count them in the TT size + * batadv_tt_local_transition_new() - unset the NEW flag on the local + * table and count them in the TT size * @bat_priv: the bat priv with all the mesh interface information - * @flags: the flag to switch - * @enable: whether to set or unset the flag - * @count: whether to increase the TT size by the number of changed entries */ -static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags, - bool enable, bool count) +static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv) { struct batadv_hashtable *hash = bat_priv->tt.local_hash; struct batadv_tt_common_entry *tt_common_entry; @@ -3839,19 +3835,11 @@ static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags, rcu_read_lock(); hlist_for_each_entry_rcu(tt_common_entry, head, hash_entry) { - if (enable) { - if ((tt_common_entry->flags & flags) == flags) - continue; - tt_common_entry->flags |= flags; - } else { - if (!(tt_common_entry->flags & flags)) - continue; - tt_common_entry->flags &= ~flags; - } - - if (!count) + if (!(tt_common_entry->flags & BATADV_TT_CLIENT_NEW)) continue; + tt_common_entry->flags &= ~BATADV_TT_CLIENT_NEW; + batadv_tt_local_size_inc(bat_priv, tt_common_entry->vid); } @@ -3924,7 +3912,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv) return; } - batadv_tt_local_set_flags(bat_priv, BATADV_TT_CLIENT_NEW, false, true); + batadv_tt_local_transition_new(bat_priv); batadv_tt_local_purge_pending_clients(bat_priv); batadv_tt_local_update_crc(bat_priv); From 52d8c713f464448a055025dab4ceff6afcc68e02 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:41 +0200 Subject: [PATCH 0011/2126] batman-adv: tt: drop unnecessary cleanup goto in helpers To use scoped_guard(), it is not allowed to use goto in the same routine. These goto's should only be used for cleanups but are not necessary of minimal helpers like batadv_is_my_client(), batadv_tt_global_client_is_roaming() and batadv_tt_local_client_is_roaming(). Removing the goto's is actually making these functions more readable. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 2f7951e4c320..fbe75e184153 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -3544,19 +3544,18 @@ bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr, unsigned short vid) { struct batadv_tt_local_entry *tt_local_entry; - bool ret = false; + bool ret; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) - goto out; + return false; + /* Check if the client has been logically deleted (but is kept for * consistency purpose) */ - if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) || - (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM)) - goto out; - ret = true; -out: + ret = !((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) || + (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM)); + batadv_tt_local_entry_put(tt_local_entry); return ret; } @@ -4082,15 +4081,15 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, u8 *addr, unsigned short vid) { struct batadv_tt_global_entry *tt_global_entry; - bool ret = false; + bool ret; tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid); if (!tt_global_entry) - goto out; + return false; ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM; batadv_tt_global_entry_put(tt_global_entry); -out: + return ret; } @@ -4108,15 +4107,15 @@ bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv, u8 *addr, unsigned short vid) { struct batadv_tt_local_entry *tt_local_entry; - bool ret = false; + bool ret; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) - goto out; + return false; ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM; batadv_tt_local_entry_put(tt_local_entry); -out: + return ret; } From 976b159b3c12be89459390bdf950534f639a5200 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:42 +0200 Subject: [PATCH 0012/2126] batman-adv: tt: use protected flag modifications The flags of translation table entries are modified in various places using RMW operations like: * read flags + add flag + store * read flags + remove flag + store These were done without making sure that no other context is doing a similar operation at the same time. If another context does modify the flags then it could happen that a store of the flag modifications is simply lost. This problem can usually be fixed at a later point when the flags are tried to be adjusted again. To reduce the time the wrong flags are used, it is better to use a TT entry specific spinlock when accessing the u16. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 351 ++++++++++++++++++++--------- net/batman-adv/types.h | 11 +- 2 files changed, 255 insertions(+), 107 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index fbe75e184153..163f90962306 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -433,6 +434,22 @@ batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry) kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release); } +/** + * batadv_tt_flags_get() - get a snapshot of the flags of a TT entry + * @common: tt local & tt global common data + * + * Return: the flags of the TT entry as observed under its flags_lock. + */ +static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common) +{ + u16 flags; + + scoped_guard(spinlock_bh, &common->flags_lock) + flags = common->flags; + + return flags; +} + /** * batadv_tt_local_event() - store a local TT event (ADD/DEL) * @bat_priv: the bat priv with all the mesh interface information @@ -445,23 +462,25 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, { struct batadv_tt_common_entry *common = &tt_local_entry->common; struct batadv_tt_change_node *tt_change_node; - u8 flags = common->flags | event_flags; struct batadv_tt_change_node *entry; struct batadv_tt_change_node *safe; bool del_op_requested; bool del_op_entry; size_t changes; + u8 flags; tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); if (!tt_change_node) return; - tt_change_node->change.flags = flags; memset(tt_change_node->change.reserved, 0, sizeof(tt_change_node->change.reserved)); ether_addr_copy(tt_change_node->change.addr, common->addr); tt_change_node->change.vid = htons(common->vid); + flags = batadv_tt_flags_get(common) | event_flags; + + tt_change_node->change.flags = flags; del_op_requested = flags & BATADV_TT_CLIENT_DEL; /* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */ @@ -633,8 +652,23 @@ static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv, /* Check whether it is a roaming, but don't do anything if the roaming * process has already been handled */ - if (tt_global->common.flags & BATADV_TT_CLIENT_ROAM) - return; + scoped_guard(spinlock_bh, &tt_global->common.flags_lock) { + if (tt_global->common.flags & BATADV_TT_CLIENT_ROAM) + return; + + if (!roamed_back) { + /* The global entry has to be marked as ROAMING and has to be + * kept for consistency purpose. + * + * batadv_tt_global_to_purge() evaluates roam_at as soon as it + * observes BATADV_TT_CLIENT_ROAM, so the timeout has to be + * stamped before the flag is published. Otherwise the entry can + * be deleted right away as "Roaming timeout". + */ + tt_global->roam_at = jiffies; + tt_global->common.flags |= BATADV_TT_CLIENT_ROAM; + } + } /* These node are probably going to update their tt table */ head = &tt_global->orig_list; @@ -646,16 +680,8 @@ static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv, } rcu_read_unlock(); - if (roamed_back) { - batadv_tt_global_free(bat_priv, tt_global, - "Roaming canceled"); - } else { - /* The global entry has to be marked as ROAMING and - * has to be kept for consistency purpose - */ - tt_global->common.flags |= BATADV_TT_CLIENT_ROAM; - tt_global->roam_at = jiffies; - } + if (roamed_back) + batadv_tt_global_free(bat_priv, tt_global, "Roaming canceled"); } /** @@ -688,6 +714,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, int hash_added; int table_size; u32 match_mark; + bool modified; if (ifindex != BATADV_NULL_IFINDEX) in_dev = dev_get_by_index(net, ifindex); @@ -705,6 +732,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, if (tt_local) { tt_local->last_seen = jiffies; + + spin_lock_bh(&tt_local->common.flags_lock); if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) { batadv_dbg(BATADV_DBG_TT, bat_priv, "Re-adding pending client %pM (vid: %d)\n", @@ -715,6 +744,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, * flag can be reset like it was never enqueued */ tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING; + spin_unlock_bh(&tt_local->common.flags_lock); + goto add_event; } @@ -730,6 +761,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM; roamed_back = true; } + spin_unlock_bh(&tt_local->common.flags_lock); + goto check_roaming; } @@ -765,18 +798,21 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, (u8)atomic_read(&bat_priv->tt.vn)); ether_addr_copy(tt_local->common.addr, addr); + tt_local->common.vid = vid; + kref_init(&tt_local->common.refcount); + tt_local->last_seen = jiffies; + tt_local->common.added_at = tt_local->last_seen; + tt_local->vlan = vlan; + spin_lock_init(&tt_local->common.flags_lock); + + spin_lock_bh(&tt_local->common.flags_lock); /* The local entry has to be marked as NEW to avoid to send it in * a full table response going out before the next ttvn increment * (consistency check) */ tt_local->common.flags = BATADV_TT_CLIENT_NEW; - tt_local->common.vid = vid; if (iif_is_wifi) tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; - kref_init(&tt_local->common.refcount); - tt_local->last_seen = jiffies; - tt_local->common.added_at = tt_local->last_seen; - tt_local->vlan = vlan; /* the batman interface mac and multicast addresses should never be * purged @@ -784,6 +820,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, if (batadv_compare_eth(addr, mesh_iface->dev_addr) || is_multicast_ether_addr(addr)) tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE; + spin_unlock_bh(&tt_local->common.flags_lock); kref_get(&tt_local->common.refcount); hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, @@ -802,6 +839,7 @@ add_event: check_roaming: batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back); + spin_lock_bh(&tt_local->common.flags_lock); /* store the current remote flags before altering them. This helps * understanding is flags are changing or not */ @@ -823,10 +861,13 @@ check_roaming: else tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA; + modified = remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK); + spin_unlock_bh(&tt_local->common.flags_lock); + /* if any "dynamic" flag has been modified, resend an ADD event for this * entry so that all the nodes can get the new flags */ - if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK)) + if (modified) batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); ret = true; @@ -1151,6 +1192,7 @@ batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid, struct batadv_meshif_vlan *vlan; unsigned int last_seen_msecs; void *hdr; + u16 flags; u32 crc; local = container_of(common, struct batadv_tt_local_entry, common); @@ -1172,13 +1214,15 @@ batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid, genl_dump_check_consistent(cb, hdr); + flags = batadv_tt_flags_get(common); + if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) || nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) || nla_put_u16(msg, BATADV_ATTR_TT_VID, common->vid) || - nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, common->flags)) + nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, flags)) goto nla_put_failure; - if (!(common->flags & BATADV_TT_CLIENT_NOPURGE) && + if (!(flags & BATADV_TT_CLIENT_NOPURGE) && nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, last_seen_msecs)) goto nla_put_failure; @@ -1285,29 +1329,23 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb) } /** - * batadv_tt_local_set_pending() - mark a local TT entry as pending removal + * batadv_tt_local_set_pending_event() - trigger events for TT pending removal * @bat_priv: the bat priv with all the mesh interface information * @tt_local_entry: local TT entry to mark * @flags: TT change flags to announce together with the pending removal * @message: debug message describing the reason for the change * - * Schedule the TT change announcement and set BATADV_TT_CLIENT_PENDING on the - * entry. The entry is kept in the local table until the next TTVN increment - * so that a consistency-check response can still be answered. + * Schedule the TT change announcement for the entry. The entry is kept in the + * local table until the next TTVN increment so that a consistency-check + * response can still be answered. */ static void -batadv_tt_local_set_pending(struct batadv_priv *bat_priv, - struct batadv_tt_local_entry *tt_local_entry, - u16 flags, const char *message) +batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local_entry, + u16 flags, const char *message) { batadv_tt_local_event(bat_priv, tt_local_entry, flags); - /* The local client has to be marked as "pending to be removed" but has - * to be kept in the table in order to send it in a full table - * response issued before the net ttvn increment (consistency check) - */ - tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING; - batadv_dbg(BATADV_DBG_TT, bat_priv, "Local tt entry (%pM, vid: %d) pending to be removed: %s\n", tt_local_entry->common.addr, @@ -1331,12 +1369,14 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, struct batadv_tt_local_entry *tt_local_entry; struct hlist_node *tt_removed_node; u16 curr_flags = BATADV_NO_FLAGS; + bool pending = false; u16 flags; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) goto out; + spin_lock_bh(&tt_local_entry->common.flags_lock); curr_flags = tt_local_entry->common.flags; flags = BATADV_TT_CLIENT_DEL; @@ -1351,10 +1391,17 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, } if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) { - batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags, - message); + tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING; + pending = true; + } + spin_unlock_bh(&tt_local_entry->common.flags_lock); + + if (pending) { + batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, flags, + message); goto out; } + /* if this client has been added right now, it is possible to * immediately purge it */ @@ -1394,21 +1441,37 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv, hlist_for_each_entry_safe(tt_common_entry, node_tmp, head, hash_entry) { + bool cont = false; + tt_local_entry = container_of(tt_common_entry, struct batadv_tt_local_entry, common); - if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE) + + scoped_guard(spinlock_bh, &tt_local_entry->common.flags_lock) { + if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE) { + cont = true; + break; + } + + /* entry already marked for deletion */ + if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) { + cont = true; + break; + } + + if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout)) { + cont = true; + break; + } + + tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING; + } + + if (cont) continue; - /* entry already marked for deletion */ - if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) - continue; - - if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout)) - continue; - - batadv_tt_local_set_pending(bat_priv, tt_local_entry, - BATADV_TT_CLIENT_DEL, "timed out"); + batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, + BATADV_TT_CLIENT_DEL, "timed out"); } } @@ -1614,8 +1677,10 @@ batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global) flags |= orig_entry->flags; rcu_read_unlock(); - flags |= tt_global->common.flags & (~BATADV_TT_SYNC_MASK); - tt_global->common.flags = flags; + scoped_guard(spinlock_bh, &tt_global->common.flags_lock) { + flags |= tt_global->common.flags & (~BATADV_TT_SYNC_MASK); + tt_global->common.flags = flags; + } } /** @@ -1697,8 +1762,10 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, struct batadv_tt_local_entry *tt_local_entry; struct batadv_tt_common_entry *common; bool ret = false; + u16 global_flags; u16 local_flags; int hash_added; + bool delete; /* ignore global entries from backbone nodes */ if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid)) @@ -1711,9 +1778,11 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, * for a roaming advertisement instead of manually messing up the global * table */ - if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry && - !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) - goto out; + if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry) { + local_flags = batadv_tt_flags_get(&tt_local_entry->common); + if (!(local_flags & BATADV_TT_CLIENT_NEW)) + goto out; + } if (!tt_global_entry) { tt_global_entry = kmem_cache_zalloc(batadv_tg_cache, @@ -1724,9 +1793,13 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, common = &tt_global_entry->common; ether_addr_copy(common->addr, tt_addr); common->vid = vid; + spin_lock_init(&common->flags_lock); - if (!is_multicast_ether_addr(common->addr)) + if (!is_multicast_ether_addr(common->addr)) { + spin_lock_bh(&common->flags_lock); common->flags = flags & (~BATADV_TT_SYNC_MASK); + spin_unlock_bh(&common->flags_lock); + } tt_global_entry->roam_at = 0; /* node must store current time in case of roaming. This is @@ -1766,8 +1839,10 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, * originator list and add the new one orig_entry */ if (flags & BATADV_TT_CLIENT_TEMP) { - if (!(common->flags & BATADV_TT_CLIENT_TEMP)) + global_flags = batadv_tt_flags_get(common); + if (!(global_flags & BATADV_TT_CLIENT_TEMP)) goto out; + if (batadv_tt_global_entry_has_orig(tt_global_entry, orig_node, NULL)) goto out_remove; @@ -1775,6 +1850,9 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, goto add_orig_entry; } + delete = false; + + spin_lock_bh(&common->flags_lock); /* if the client was temporary added before receiving the first * OGM announcing it, we have to clear the TEMP flag. Also, * remove the previous temporary orig node and re-add it @@ -1782,7 +1860,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, * is a non-temporary entry is preferred. */ if (common->flags & BATADV_TT_CLIENT_TEMP) { - batadv_tt_global_del_orig_list(tt_global_entry); + delete = true; common->flags &= ~BATADV_TT_CLIENT_TEMP; } @@ -1801,10 +1879,14 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, * new one. */ if (common->flags & BATADV_TT_CLIENT_ROAM) { - batadv_tt_global_del_orig_list(tt_global_entry); - common->flags &= ~BATADV_TT_CLIENT_ROAM; + delete = true; tt_global_entry->roam_at = 0; + common->flags &= ~BATADV_TT_CLIENT_ROAM; } + spin_unlock_bh(&common->flags_lock); + + if (delete) + batadv_tt_global_del_orig_list(tt_global_entry); } add_orig_entry: /* add the new orig_entry (if needed) or update it */ @@ -1828,6 +1910,8 @@ out_remove: local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid, "global tt received", flags & BATADV_TT_CLIENT_ROAM); + + spin_lock_bh(&tt_global_entry->common.flags_lock); tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI; if (!(flags & BATADV_TT_CLIENT_ROAM)) @@ -1835,6 +1919,7 @@ out_remove: * roaming state anymore. */ tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM; + spin_unlock_bh(&tt_global_entry->common.flags_lock); out: batadv_tt_global_entry_put(tt_global_entry); @@ -1904,9 +1989,9 @@ batadv_tt_global_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, struct batadv_tt_orig_list_entry *orig, bool best) { - u16 flags = (common->flags & (~BATADV_TT_SYNC_MASK)) | orig->flags; struct batadv_orig_node_vlan *vlan; u8 last_ttvn; + u16 flags; void *hdr; u32 crc; @@ -1925,6 +2010,7 @@ batadv_tt_global_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, if (!hdr) return -ENOBUFS; + flags = (batadv_tt_flags_get(common) & (~BATADV_TT_SYNC_MASK)) | orig->flags; last_ttvn = READ_ONCE(orig->orig_node->last_ttvn); if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) || @@ -2212,9 +2298,12 @@ batadv_tt_global_del_roaming(struct batadv_priv *bat_priv, rcu_read_unlock(); if (last_entry) { - /* its the last one, mark for roaming. */ - tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM; - tt_global_entry->roam_at = jiffies; + scoped_guard(spinlock_bh, &tt_global_entry->common.flags_lock) { + /* its the last one, mark for roaming. */ + tt_global_entry->roam_at = jiffies; + + tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM; + } } else { /* there is another entry, we can simply delete this * one and can still use the other one. @@ -2363,16 +2452,18 @@ static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global, unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT; bool purge = false; - if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) && - batadv_has_timed_out(tt_global->roam_at, roam_timeout)) { - purge = true; - *msg = "Roaming timeout\n"; - } + scoped_guard(spinlock_bh, &tt_global->common.flags_lock) { + if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) && + batadv_has_timed_out(tt_global->roam_at, roam_timeout)) { + purge = true; + *msg = "Roaming timeout\n"; + } - if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) && - batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) { - purge = true; - *msg = "Temporary client timeout\n"; + if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) && + batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) { + purge = true; + *msg = "Temporary client timeout\n"; + } } return purge; @@ -2481,13 +2572,19 @@ static bool _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry, struct batadv_tt_global_entry *tt_global_entry) { - if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI && - tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI) + u16 global_flags; + u16 local_flags; + + global_flags = batadv_tt_flags_get(&tt_global_entry->common); + local_flags = batadv_tt_flags_get(&tt_local_entry->common); + + if (local_flags & BATADV_TT_CLIENT_WIFI && + global_flags & BATADV_TT_CLIENT_WIFI) return true; /* check if the two clients are marked as isolated */ - if (tt_local_entry->common.flags & BATADV_TT_CLIENT_ISOLA && - tt_global_entry->common.flags & BATADV_TT_CLIENT_ISOLA) + if (local_flags & BATADV_TT_CLIENT_ISOLA && + global_flags & BATADV_TT_CLIENT_ISOLA) return true; return false; @@ -2516,11 +2613,15 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv, struct batadv_tt_local_entry *tt_local_entry = NULL; struct batadv_tt_orig_list_entry *best_entry; struct batadv_orig_node *orig_node = NULL; + u16 flags; if (src && batadv_vlan_ap_isola_get(bat_priv, vid)) { tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid); - if (!tt_local_entry || - (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)) + if (!tt_local_entry) + goto out; + + flags = batadv_tt_flags_get(&tt_local_entry->common); + if (flags & BATADV_TT_CLIENT_PENDING) goto out; } @@ -2595,6 +2696,8 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv, rcu_read_lock(); hlist_for_each_entry_rcu(tt_common, head, hash_entry) { + u16 tt_flags; + tt_global = container_of(tt_common, struct batadv_tt_global_entry, common); @@ -2604,18 +2707,21 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv, if (tt_common->vid != vid) continue; + tt_flags = batadv_tt_flags_get(tt_common); + /* Roaming clients are in the global table for * consistency only. They don't have to be * taken into account while computing the * global crc */ - if (tt_common->flags & BATADV_TT_CLIENT_ROAM) + if (tt_flags & BATADV_TT_CLIENT_ROAM) continue; + /* Temporary clients have not been announced yet, so * they have to be skipped while computing the global * crc */ - if (tt_common->flags & BATADV_TT_CLIENT_TEMP) + if (tt_flags & BATADV_TT_CLIENT_TEMP) continue; /* find out if this global entry is announced by this @@ -2675,18 +2781,24 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv, rcu_read_lock(); hlist_for_each_entry_rcu(tt_common, head, hash_entry) { + u16 tt_flags; + /* compute the CRC only for entries belonging to the * VLAN identified by vid */ if (tt_common->vid != vid) continue; + tt_flags = batadv_tt_flags_get(tt_common); + /* not yet committed clients have not to be taken into * account while computing the CRC */ - if (tt_common->flags & BATADV_TT_CLIENT_NEW) + if (tt_flags & BATADV_TT_CLIENT_NEW) continue; + flags = tt_flags & BATADV_TT_SYNC_MASK; + /* use network order to read the VID: this ensures that * every node reads the bytes in the same order. */ @@ -2696,7 +2808,6 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv, /* compute the CRC on flags that have to be kept in sync * among nodes */ - flags = tt_common->flags & BATADV_TT_SYNC_MASK; crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags)); crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN); @@ -2854,17 +2965,19 @@ unlock: * * Return: true if the entry is a valid, false otherwise. */ -static bool batadv_tt_local_valid(const void *entry_ptr, +static bool batadv_tt_local_valid(void *entry_ptr, const void *data_ptr, u8 *flags) { - const struct batadv_tt_common_entry *tt_common_entry = entry_ptr; + struct batadv_tt_common_entry *tt_common_entry = entry_ptr; + u16 tt_flags; - if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW) + tt_flags = batadv_tt_flags_get(tt_common_entry); + if (tt_flags & BATADV_TT_CLIENT_NEW) return false; if (flags) - *flags = tt_common_entry->flags; + *flags = tt_flags; return true; } @@ -2881,16 +2994,18 @@ static bool batadv_tt_local_valid(const void *entry_ptr, * * Return: true if the entry is a valid, false otherwise. */ -static bool batadv_tt_global_valid(const void *entry_ptr, +static bool batadv_tt_global_valid(void *entry_ptr, const void *data_ptr, u8 *flags) { - const struct batadv_tt_common_entry *tt_common_entry = entry_ptr; - const struct batadv_tt_global_entry *tt_global_entry; + struct batadv_tt_common_entry *tt_common_entry = entry_ptr; const struct batadv_orig_node *orig_node = data_ptr; + struct batadv_tt_global_entry *tt_global_entry; + u16 tt_flags; - if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM || - tt_common_entry->flags & BATADV_TT_CLIENT_TEMP) + tt_flags = batadv_tt_flags_get(tt_common_entry); + if (tt_flags & BATADV_TT_CLIENT_ROAM || + tt_flags & BATADV_TT_CLIENT_TEMP) return false; tt_global_entry = container_of(tt_common_entry, @@ -2919,7 +3034,7 @@ static bool batadv_tt_global_valid(const void *entry_ptr, static u16 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, struct batadv_hashtable *hash, void *tvlv_buff, u16 tt_len, - bool (*valid_cb)(const void *, + bool (*valid_cb)(void *, const void *, u8 *flags), void *cb_data) @@ -3544,17 +3659,20 @@ bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr, unsigned short vid) { struct batadv_tt_local_entry *tt_local_entry; + u16 tt_flags; bool ret; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) return false; + tt_flags = batadv_tt_flags_get(&tt_local_entry->common); + /* Check if the client has been logically deleted (but is kept for * consistency purpose) */ - ret = !((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) || - (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM)); + ret = !((tt_flags & BATADV_TT_CLIENT_PENDING) || + (tt_flags & BATADV_TT_CLIENT_ROAM)); batadv_tt_local_entry_put(tt_local_entry); return ret; @@ -3834,10 +3952,19 @@ static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv) rcu_read_lock(); hlist_for_each_entry_rcu(tt_common_entry, head, hash_entry) { - if (!(tt_common_entry->flags & BATADV_TT_CLIENT_NEW)) - continue; + bool cont = false; - tt_common_entry->flags &= ~BATADV_TT_CLIENT_NEW; + scoped_guard(spinlock_bh, &tt_common_entry->flags_lock) { + if (!(tt_common_entry->flags & BATADV_TT_CLIENT_NEW)) { + cont = true; + break; + } + + tt_common_entry->flags &= ~BATADV_TT_CLIENT_NEW; + } + + if (cont) + continue; batadv_tt_local_size_inc(bat_priv, tt_common_entry->vid); @@ -3874,16 +4001,26 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv) spin_lock_bh(list_lock); hlist_for_each_entry_safe(tt_common, node_tmp, head, hash_entry) { - if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING)) + bool cont = false; + + scoped_guard(spinlock_bh, &tt_common->flags_lock) { + if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING)) { + cont = true; + break; + } + + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Deleting local tt entry (%pM, vid: %d): pending\n", + tt_common->addr, + batadv_print_vid(tt_common->vid)); + + batadv_tt_local_size_dec(bat_priv, tt_common->vid); + hlist_del_rcu(&tt_common->hash_entry); + } + + if (cont) continue; - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Deleting local tt entry (%pM, vid: %d): pending\n", - tt_common->addr, - batadv_print_vid(tt_common->vid)); - - batadv_tt_local_size_dec(bat_priv, tt_common->vid); - hlist_del_rcu(&tt_common->hash_entry); tt_local = container_of(tt_common, struct batadv_tt_local_entry, common); @@ -4087,7 +4224,8 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, if (!tt_global_entry) return false; - ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM; + ret = batadv_tt_flags_get(&tt_global_entry->common) & BATADV_TT_CLIENT_ROAM; + batadv_tt_global_entry_put(tt_global_entry); return ret; @@ -4113,7 +4251,8 @@ bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv, if (!tt_local_entry) return false; - ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM; + ret = batadv_tt_flags_get(&tt_local_entry->common) & BATADV_TT_CLIENT_ROAM; + batadv_tt_local_entry_put(tt_local_entry); return ret; @@ -4424,7 +4563,7 @@ bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv, if (!tt) return false; - ret = tt->common.flags & BATADV_TT_CLIENT_ISOLA; + ret = batadv_tt_flags_get(&tt->common) & BATADV_TT_CLIENT_ISOLA; batadv_tt_global_entry_put(tt); diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index c42a4aa8f41a..67872927cfb5 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -1851,12 +1851,21 @@ struct batadv_tt_common_entry { */ struct hlist_node hash_entry; - /** @flags: various state handling flags (see batadv_tt_client_flags) */ + /** + * @flags: various state handling flags (see batadv_tt_client_flags), + * protected by @flags_lock + */ u16 flags; /** @added_at: timestamp used for purging stale tt common entries */ unsigned long added_at; + /** + * @flags_lock: protect modifications of @flags and + * @batadv_tt_global_entry.roam_at + */ + spinlock_t flags_lock; + /** @refcount: number of contexts the object is used */ struct kref refcount; From f59c4c59df104baf473e20f885071a9d713c3861 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:43 +0200 Subject: [PATCH 0013/2126] batman-adv: tt: transition NEW local entries only under lock The batadv_tt_local_size_inc() must never be called for an entry which was already removed from the list. Otherwise the removal from the hash cannot correctly determine if the batadv_tt_local_size_dec() needs to be called or not. This assumption is broken by the use of rcu_read_lock() in batadv_tt_local_transition_new() because it might still see entries in the list which were already removed by a different context from the list. If it then increments the size counter, nothing will reduce the counter again. Simply because the removal (responsible for the decrement) already happened. Over the whole time, the actual hash list spinlock must be held when transitioning NEW local entries to avoid list manipulations. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 163f90962306..a870d9a97e32 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -333,6 +333,10 @@ static void batadv_tt_local_size_mod(struct batadv_priv *bat_priv, * given vid * @bat_priv: the bat priv with all the mesh interface information * @vid: the VLAN identifier + * + * It must only be called when removing the NEW flag of a + * batadv_tt_local_entry while it is still part of the bat_priv->tt.local_hash. + * It must therefore be checked under the specific list_locks[i]. */ static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv, unsigned short vid) @@ -3938,6 +3942,7 @@ void batadv_tt_free(struct batadv_priv *bat_priv) */ static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv) { + spinlock_t *list_lock; /* protects write access to the hash lists */ struct batadv_hashtable *hash = bat_priv->tt.local_hash; struct batadv_tt_common_entry *tt_common_entry; struct hlist_head *head; @@ -3948,10 +3953,10 @@ static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv) for (i = 0; i < hash->size; i++) { head = &hash->table[i]; + list_lock = &hash->list_locks[i]; - rcu_read_lock(); - hlist_for_each_entry_rcu(tt_common_entry, - head, hash_entry) { + spin_lock_bh(list_lock); + hlist_for_each_entry(tt_common_entry, head, hash_entry) { bool cont = false; scoped_guard(spinlock_bh, &tt_common_entry->flags_lock) { @@ -3969,7 +3974,7 @@ static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv) batadv_tt_local_size_inc(bat_priv, tt_common_entry->vid); } - rcu_read_unlock(); + spin_unlock_bh(list_lock); } } From 01ae63ecd1c098521f2544cb1018b8ec22d9bdb1 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:44 +0200 Subject: [PATCH 0014/2126] batman-adv: tt: don't uncount never committed clients on pending purge batadv_tt_local_purge_pending_clients() decreases vlan->tt.num_entries for every entry it unlinks, but an entry which still carries BATADV_TT_CLIENT_NEW was never counted by batadv_tt_local_transition_new(). batadv_tt_local_resize_to_mtu() calls batadv_tt_local_purge() and batadv_tt_local_purge_pending_clients() directly, without committing in between, and it halves its timeout down towards zero. Once the timeout is short enough, batadv_tt_local_purge_list() marks even freshly added clients as pending. And each of them decreases a counter it never increased. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index a870d9a97e32..794692170b61 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -349,6 +349,10 @@ static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv, * given vid * @bat_priv: the bat priv with all the mesh interface information * @vid: the VLAN identifier + * + * It must only be called after a batadv_tt_local_entry without NEW flag + * was removed from bat_priv->tt.local_hash (under the specific + * list_locks[i]). */ static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv, unsigned short vid) @@ -4019,8 +4023,13 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv) tt_common->addr, batadv_print_vid(tt_common->vid)); - batadv_tt_local_size_dec(bat_priv, tt_common->vid); hlist_del_rcu(&tt_common->hash_entry); + + /* An entry which still carries BATADV_TT_CLIENT_NEW was + * never counted and must not be uncounted here. + */ + if (!(tt_common->flags & BATADV_TT_CLIENT_NEW)) + batadv_tt_local_size_dec(bat_priv, tt_common->vid); } if (cont) From 3273a5cd2d7445e90bcb0851fbb5b7f1f72192be Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:46 +0200 Subject: [PATCH 0015/2126] batman-adv: tt: look up wifi state of incoming interface in helper batadv_tt_local_add() only needs to know whether the client was seen on a wifi interface. But it kept the net_device reference of the incoming interface alive until its own cleanup section, together with a "net" and an "in_dev" variable which are of no interest to the rest of the function. Move the lookup to a small helper which acquires and releases the net_device reference itself. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 41 +++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 44a8cf89382c..1c22db348267 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -693,6 +694,32 @@ static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv, batadv_tt_global_free(bat_priv, tt_global, "Roaming canceled"); } +/** + * batadv_tt_iif_is_wifi() - check whether a client is connected via wifi + * @net: namespace to search the incoming interface in + * @ifindex: index of the interface where the client is connected to + * + * Return: true if @ifindex refers to a wifi interface, false otherwise (which + * includes the case of an unknown or missing incoming interface). + */ +static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex) +{ + struct net_device *in_dev; + u32 wifi_flags; + + if (ifindex == BATADV_NULL_IFINDEX) + return false; + + in_dev = dev_get_by_index(net, ifindex); + if (!in_dev) + return false; + + wifi_flags = batadv_netdev_get_wifi_flags(in_dev); + dev_put(in_dev); + + return batadv_is_wifi(wifi_flags); +} + /** * batadv_tt_local_add() - add a new client to the local table or update an * existing client @@ -712,12 +739,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, struct batadv_priv *bat_priv = netdev_priv(mesh_iface); struct batadv_tt_global_entry *tt_global = NULL; struct batadv_tt_local_entry *tt_local; - struct net *net = dev_net(mesh_iface); - struct net_device *in_dev = NULL; struct batadv_meshif_vlan *vlan; bool roamed_back = false; - bool iif_is_wifi = false; int packet_size_max; + bool iif_is_wifi; bool ret = false; u8 remote_flags; int hash_added; @@ -725,14 +750,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, u32 match_mark; bool modified; - if (ifindex != BATADV_NULL_IFINDEX) - in_dev = dev_get_by_index(net, ifindex); - - if (in_dev) { - u32 wifi_flags = batadv_netdev_get_wifi_flags(in_dev); - - iif_is_wifi = batadv_is_wifi(wifi_flags); - } + iif_is_wifi = batadv_tt_iif_is_wifi(dev_net(mesh_iface), ifindex); tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid); @@ -881,7 +899,6 @@ check_roaming: ret = true; out: - dev_put(in_dev); batadv_tt_local_entry_put(tt_local); batadv_tt_global_entry_put(tt_global); return ret; From defa87f5ce75fee9d8d1f401b95f5ece7418de7e Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:47 +0200 Subject: [PATCH 0016/2126] batman-adv: tt: extract allocation of new local entries The code which allocates and initializes a brand new local TT entry makes up more than a third of batadv_tt_local_add(). It only shares the addr, vid and iif_is_wifi parameters with the rest of the function. Move it to batadv_tt_local_create(), which returns the fully initialized entry. The error paths become plain returns. The insertion into bat_priv->tt.local_hash intentionally stays in batadv_tt_local_add(), keeping the extra reference for the hash next to the error handling which has to drop it again. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 135 +++++++++++++++++------------ 1 file changed, 79 insertions(+), 56 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 1c22db348267..2bc243f0fa69 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -720,6 +720,84 @@ static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex) return batadv_is_wifi(wifi_flags); } +/** + * batadv_tt_local_create() - allocate and initialize a local TT entry + * @mesh_iface: netdev struct of the mesh interface + * @addr: the mac address of the client to add + * @vid: VLAN identifier + * @iif_is_wifi: whether the client is connected via a wifi interface + * + * The returned entry is not yet part of bat_priv->tt.local_hash. It is marked + * as BATADV_TT_CLIENT_NEW to avoid sending it in a full table response going + * out before the next ttvn increment (consistency check). + * + * Return: the new entry with an initialized reference counter on success, NULL + * otherwise. + */ +static struct batadv_tt_local_entry * +batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr, + unsigned short vid, bool iif_is_wifi) +{ + struct batadv_priv *bat_priv = netdev_priv(mesh_iface); + struct batadv_tt_local_entry *tt_local; + struct batadv_meshif_vlan *vlan; + int packet_size_max; + int table_size; + + /* Ignore the client if we cannot send it in a full table response. */ + table_size = batadv_tt_local_table_transmit_size(bat_priv); + table_size += batadv_tt_len(1); + packet_size_max = READ_ONCE(bat_priv->packet_size_max); + if (table_size > packet_size_max) { + net_ratelimited_function(batadv_info, mesh_iface, + "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", + table_size, packet_size_max, addr); + return NULL; + } + + tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC); + if (!tt_local) + return NULL; + + /* increase the refcounter of the related vlan */ + vlan = batadv_meshif_vlan_get(bat_priv, vid); + if (!vlan) { + net_ratelimited_function(batadv_info, mesh_iface, + "adding TT local entry %pM to non-existent VLAN %d\n", + addr, batadv_print_vid(vid)); + kmem_cache_free(batadv_tl_cache, tt_local); + return NULL; + } + + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n", + addr, batadv_print_vid(vid), + (u8)atomic_read(&bat_priv->tt.vn)); + + ether_addr_copy(tt_local->common.addr, addr); + tt_local->common.vid = vid; + kref_init(&tt_local->common.refcount); + tt_local->last_seen = jiffies; + tt_local->common.added_at = tt_local->last_seen; + tt_local->vlan = vlan; + spin_lock_init(&tt_local->common.flags_lock); + + scoped_guard(spinlock_bh, &tt_local->common.flags_lock) { + tt_local->common.flags = BATADV_TT_CLIENT_NEW; + if (iif_is_wifi) + tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; + + /* the batman interface mac and multicast addresses should never + * be purged + */ + if (batadv_compare_eth(addr, mesh_iface->dev_addr) || + is_multicast_ether_addr(addr)) + tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE; + } + + return tt_local; +} + /** * batadv_tt_local_add() - add a new client to the local table or update an * existing client @@ -739,14 +817,11 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, struct batadv_priv *bat_priv = netdev_priv(mesh_iface); struct batadv_tt_global_entry *tt_global = NULL; struct batadv_tt_local_entry *tt_local; - struct batadv_meshif_vlan *vlan; bool roamed_back = false; - int packet_size_max; bool iif_is_wifi; bool ret = false; u8 remote_flags; int hash_added; - int table_size; u32 match_mark; bool modified; @@ -793,62 +868,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, goto check_roaming; } - /* Ignore the client if we cannot send it in a full table response. */ - table_size = batadv_tt_local_table_transmit_size(bat_priv); - table_size += batadv_tt_len(1); - packet_size_max = READ_ONCE(bat_priv->packet_size_max); - if (table_size > packet_size_max) { - net_ratelimited_function(batadv_info, mesh_iface, - "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", - table_size, packet_size_max, addr); - goto out; - } - - tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC); + tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi); if (!tt_local) goto out; - /* increase the refcounter of the related vlan */ - vlan = batadv_meshif_vlan_get(bat_priv, vid); - if (!vlan) { - net_ratelimited_function(batadv_info, mesh_iface, - "adding TT local entry %pM to non-existent VLAN %d\n", - addr, batadv_print_vid(vid)); - kmem_cache_free(batadv_tl_cache, tt_local); - tt_local = NULL; - goto out; - } - - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n", - addr, batadv_print_vid(vid), - (u8)atomic_read(&bat_priv->tt.vn)); - - ether_addr_copy(tt_local->common.addr, addr); - tt_local->common.vid = vid; - kref_init(&tt_local->common.refcount); - tt_local->last_seen = jiffies; - tt_local->common.added_at = tt_local->last_seen; - tt_local->vlan = vlan; - spin_lock_init(&tt_local->common.flags_lock); - - spin_lock_bh(&tt_local->common.flags_lock); - /* The local entry has to be marked as NEW to avoid to send it in - * a full table response going out before the next ttvn increment - * (consistency check) - */ - tt_local->common.flags = BATADV_TT_CLIENT_NEW; - if (iif_is_wifi) - tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; - - /* the batman interface mac and multicast addresses should never be - * purged - */ - if (batadv_compare_eth(addr, mesh_iface->dev_addr) || - is_multicast_ether_addr(addr)) - tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE; - spin_unlock_bh(&tt_local->common.flags_lock); - kref_get(&tt_local->common.refcount); hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, batadv_choose_tt, &tt_local->common, From a5e5d2709d1001279093fd298101eb9d875a8ba0 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:48 +0200 Subject: [PATCH 0017/2126] batman-adv: tt: replace forward gotos in batadv_tt_local_add() batadv_tt_local_add() used two labels in the middle of the function to express which parts of the common tail have to be executed: "add_event" to announce a (re-)added client and "check_roaming" to skip that announcement. Jumping forward into the middle of a function makes it hard to see which path ends up sending an ADD event. Especially since the PENDING branch reached "add_event" while the branch right below it reached "check_roaming" instead. Express the same in an "added" variable and turn the two client cases into a plain if/else. The PENDING check returned early before the ROAM check could run, so it becomes an "else if". Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 47 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 2bc243f0fa69..5d5f270b7eb4 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -818,6 +818,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, struct batadv_tt_global_entry *tt_global = NULL; struct batadv_tt_local_entry *tt_local; bool roamed_back = false; + bool added = false; bool iif_is_wifi; bool ret = false; u8 remote_flags; @@ -846,12 +847,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, * flag can be reset like it was never enqueued */ tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING; - spin_unlock_bh(&tt_local->common.flags_lock); - - goto add_event; - } - - if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) { + added = true; + } else if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) { batadv_dbg(BATADV_DBG_TT, bat_priv, "Roaming client %pM (vid: %d) came back to its original location\n", addr, batadv_print_vid(vid)); @@ -864,29 +861,29 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, roamed_back = true; } spin_unlock_bh(&tt_local->common.flags_lock); + } else { + tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi); + if (!tt_local) + goto out; - goto check_roaming; + kref_get(&tt_local->common.refcount); + hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, + batadv_choose_tt, &tt_local->common, + &tt_local->common.hash_entry); + + if (unlikely(hash_added != 0)) { + /* remove the reference for the hash */ + batadv_tt_local_entry_put(tt_local); + goto out; + } + + added = true; } - tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi); - if (!tt_local) - goto out; + /* announce the (re-)added client to the mesh */ + if (added) + batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); - kref_get(&tt_local->common.refcount); - hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, - batadv_choose_tt, &tt_local->common, - &tt_local->common.hash_entry); - - if (unlikely(hash_added != 0)) { - /* remove the reference for the hash */ - batadv_tt_local_entry_put(tt_local); - goto out; - } - -add_event: - batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); - -check_roaming: batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back); spin_lock_bh(&tt_local->common.flags_lock); From ec6edeb755ece64abf9645aaf7b7058190d35ae6 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:49 +0200 Subject: [PATCH 0018/2126] batman-adv: tt: extract refresh of existing local entries The handling of a client which is already part of the local translation table is independent from the rest of batadv_tt_local_add(): it only refreshes last_seen and evaluates the PENDING and ROAM flags of the entry which was just looked up. Move it to batadv_tt_local_add_existing(). It reports via its return value whether the client has to be announced to the mesh again and whether the client roamed back to its original location. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 78 +++++++++++++++++++----------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 5d5f270b7eb4..91e11e5f1014 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -720,6 +720,55 @@ static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex) return batadv_is_wifi(wifi_flags); } +/** + * batadv_tt_local_add_existing() - refresh an already known local TT entry + * @bat_priv: the bat priv with all the mesh interface information + * @tt_local: the local TT entry which was found in the local table + * @roamed_back: set to true when the client returned to its original location + * + * Return: true when the client has to be announced to the mesh again, false + * otherwise. + */ +static bool batadv_tt_local_add_existing(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local, + bool *roamed_back) +{ + struct batadv_tt_common_entry *common = &tt_local->common; + + tt_local->last_seen = jiffies; + + scoped_guard(spinlock_bh, &common->flags_lock) { + if (common->flags & BATADV_TT_CLIENT_PENDING) { + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Re-adding pending client %pM (vid: %d)\n", + common->addr, batadv_print_vid(common->vid)); + /* whatever the reason why the PENDING flag was set, + * this is a client which was enqueued to be removed in + * this orig_interval. Since it popped up again, the + * flag can be reset like it was never enqueued + */ + common->flags &= ~BATADV_TT_CLIENT_PENDING; + + return true; + } + + if (common->flags & BATADV_TT_CLIENT_ROAM) { + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Roaming client %pM (vid: %d) came back to its original location\n", + common->addr, batadv_print_vid(common->vid)); + /* the ROAM flag is set because this client roamed away + * and the node got a roaming_advertisement message. Now + * that the client popped up again at its original + * location such flag can be unset + */ + common->flags &= ~BATADV_TT_CLIENT_ROAM; + *roamed_back = true; + } + } + + return false; +} + /** * batadv_tt_local_create() - allocate and initialize a local TT entry * @mesh_iface: netdev struct of the mesh interface @@ -834,33 +883,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid); if (tt_local) { - tt_local->last_seen = jiffies; - - spin_lock_bh(&tt_local->common.flags_lock); - if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) { - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Re-adding pending client %pM (vid: %d)\n", - addr, batadv_print_vid(vid)); - /* whatever the reason why the PENDING flag was set, - * this is a client which was enqueued to be removed in - * this orig_interval. Since it popped up again, the - * flag can be reset like it was never enqueued - */ - tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING; - added = true; - } else if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) { - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Roaming client %pM (vid: %d) came back to its original location\n", - addr, batadv_print_vid(vid)); - /* the ROAM flag is set because this client roamed away - * and the node got a roaming_advertisement message. Now - * that the client popped up again at its original - * location such flag can be unset - */ - tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM; - roamed_back = true; - } - spin_unlock_bh(&tt_local->common.flags_lock); + added = batadv_tt_local_add_existing(bat_priv, tt_local, + &roamed_back); } else { tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi); if (!tt_local) From 799152bcf6cbe4393eb03690925a382cefae303c Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:45 +0200 Subject: [PATCH 0019/2126] batman-adv: tt: decrement count for committed client on local_remove Local TT entries which have the BATADV_TT_CLIENT_NEW no longer set are committed. The batadv_tt_local_size_inc() was called for them and thus the batadv_tt_local_size_dec() has to be called also when batadv_tt_local_remove() is called for them when the BATADV_TT_CLIENT_NEW wasn't consumed in the remove path. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 794692170b61..44a8cf89382c 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -352,7 +352,8 @@ static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv, * * It must only be called after a batadv_tt_local_entry without NEW flag * was removed from bat_priv->tt.local_hash (under the specific - * list_locks[i]). + * list_locks[i]) or when it is ensured that it is not accessible + * in this list. */ static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv, unsigned short vid) @@ -1423,6 +1424,13 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, if (!tt_removed_node) goto out; + /* batadv_tt_local_transition_new() may have committed the entry and + * thus counted it in the local table size since the BATADV_TT_CLIENT_NEW + * check above. + */ + if (!(batadv_tt_flags_get(&tt_local_entry->common) & BATADV_TT_CLIENT_NEW)) + batadv_tt_local_size_dec(bat_priv, tt_local_entry->common.vid); + /* drop reference of remove hash entry */ batadv_tt_local_entry_put(tt_local_entry); From d72e16b1c5d527220fb21530d1728de9beb741ef Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:50 +0200 Subject: [PATCH 0020/2126] batman-adv: tt: extract update of dynamic client flags The WIFI and ISOLA flags are re-evaluated on every batadv_tt_local_add() call, no matter whether a new entry was created or an existing one was refreshed. It is mostly isolated from the rest of the batadv_tt_local_add(). Move it to batadv_tt_local_update_flags(). To allow the caller to trigger the queuing of ADD events, it returns whether one of the flags announced to the other nodes actually changed. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 79 +++++++++++++++++++----------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 91e11e5f1014..e0bcef1eba93 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -847,6 +847,55 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr, return tt_local; } +/** + * batadv_tt_local_update_flags() - update the dynamic flags of a local entry + * @bat_priv: the bat priv with all the mesh interface information + * @tt_local: the local TT entry to update + * @iif_is_wifi: whether the client is connected via a wifi interface + * @mark: the value contained in the skb->mark field of the received packet (if + * any) + * + * Return: true if a flag announced to the other nodes was modified, false + * otherwise. + */ +static bool +batadv_tt_local_update_flags(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local, + bool iif_is_wifi, u32 mark) +{ + struct batadv_tt_common_entry *common = &tt_local->common; + u8 remote_flags; + u32 match_mark; + bool modified; + + scoped_guard(spinlock_bh, &common->flags_lock) { + /* store the current remote flags before altering them. This + * helps understanding is flags are changing or not + */ + remote_flags = common->flags & BATADV_TT_REMOTE_MASK; + + if (iif_is_wifi) + common->flags |= BATADV_TT_CLIENT_WIFI; + else + common->flags &= ~BATADV_TT_CLIENT_WIFI; + + /* check the mark in the skb: if it's equal to the configured + * isolation_mark, it means the packet is coming from an + * isolated non-mesh client + */ + match_mark = (mark & bat_priv->isolation_mark_mask); + if (bat_priv->isolation_mark_mask && + match_mark == bat_priv->isolation_mark) + common->flags |= BATADV_TT_CLIENT_ISOLA; + else + common->flags &= ~BATADV_TT_CLIENT_ISOLA; + + modified = remote_flags ^ (common->flags & BATADV_TT_REMOTE_MASK); + } + + return modified; +} + /** * batadv_tt_local_add() - add a new client to the local table or update an * existing client @@ -870,10 +919,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, bool added = false; bool iif_is_wifi; bool ret = false; - u8 remote_flags; int hash_added; - u32 match_mark; - bool modified; iif_is_wifi = batadv_tt_iif_is_wifi(dev_net(mesh_iface), ifindex); @@ -910,35 +956,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back); - spin_lock_bh(&tt_local->common.flags_lock); - /* store the current remote flags before altering them. This helps - * understanding is flags are changing or not - */ - remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK; - - if (iif_is_wifi) - tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; - else - tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI; - - /* check the mark in the skb: if it's equal to the configured - * isolation_mark, it means the packet is coming from an isolated - * non-mesh client - */ - match_mark = (mark & bat_priv->isolation_mark_mask); - if (bat_priv->isolation_mark_mask && - match_mark == bat_priv->isolation_mark) - tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA; - else - tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA; - - modified = remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK); - spin_unlock_bh(&tt_local->common.flags_lock); - /* if any "dynamic" flag has been modified, resend an ADD event for this * entry so that all the nodes can get the new flags */ - if (modified) + if (batadv_tt_local_update_flags(bat_priv, tt_local, iif_is_wifi, mark)) batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); ret = true; From d9017aeb40c1386920248781d24aa8823e6894ba Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:51 +0200 Subject: [PATCH 0021/2126] batman-adv: tt: extract allocation of new global entries The code which allocates and initializes a brand new global TT entry makes up a third of batadv_tt_global_add() and only needs the tt_addr, vid and flags arguments. It is also the only part of the "new entry" branch which does not deal with the global hash. Move it to batadv_tt_global_create() and let it return the initialized entry. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 76 ++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index e0bcef1eba93..d475f8efd44d 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1832,6 +1832,56 @@ out: spin_unlock_bh(&tt_global->list_lock); } +/** + * batadv_tt_global_create() - allocate and initialize a global TT entry + * @tt_addr: the mac address of the non-mesh client + * @vid: VLAN identifier + * @flags: TT flags that have to be set for this non-mesh client + * + * The returned entry is not yet part of bat_priv->tt.global_hash and has an + * empty originator list. + * + * Return: the new entry with an initialized reference counter on success, NULL + * otherwise. + */ +static struct batadv_tt_global_entry * +batadv_tt_global_create(const unsigned char *tt_addr, unsigned short vid, + u16 flags) +{ + struct batadv_tt_global_entry *tt_global_entry; + struct batadv_tt_common_entry *common; + + tt_global_entry = kmem_cache_zalloc(batadv_tg_cache, GFP_ATOMIC); + if (!tt_global_entry) + return NULL; + + common = &tt_global_entry->common; + ether_addr_copy(common->addr, tt_addr); + common->vid = vid; + spin_lock_init(&common->flags_lock); + + if (!is_multicast_ether_addr(common->addr)) { + scoped_guard(spinlock_bh, &common->flags_lock) + common->flags = flags & (~BATADV_TT_SYNC_MASK); + } + + tt_global_entry->roam_at = 0; + /* node must store current time in case of roaming. This is + * needed to purge this entry out on timeout (if nobody claims + * it) + */ + if (flags & BATADV_TT_CLIENT_ROAM) + tt_global_entry->roam_at = jiffies; + kref_init(&common->refcount); + common->added_at = jiffies; + + INIT_HLIST_HEAD(&tt_global_entry->orig_list); + atomic_set(&tt_global_entry->orig_list_count, 0); + spin_lock_init(&tt_global_entry->list_lock); + + return tt_global_entry; +} + /** * batadv_tt_global_add() - add a new TT global entry or update an existing one * @bat_priv: the bat priv with all the mesh interface information @@ -1883,35 +1933,11 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, } if (!tt_global_entry) { - tt_global_entry = kmem_cache_zalloc(batadv_tg_cache, - GFP_ATOMIC); + tt_global_entry = batadv_tt_global_create(tt_addr, vid, flags); if (!tt_global_entry) goto out; common = &tt_global_entry->common; - ether_addr_copy(common->addr, tt_addr); - common->vid = vid; - spin_lock_init(&common->flags_lock); - - if (!is_multicast_ether_addr(common->addr)) { - spin_lock_bh(&common->flags_lock); - common->flags = flags & (~BATADV_TT_SYNC_MASK); - spin_unlock_bh(&common->flags_lock); - } - - tt_global_entry->roam_at = 0; - /* node must store current time in case of roaming. This is - * needed to purge this entry out on timeout (if nobody claims - * it) - */ - if (flags & BATADV_TT_CLIENT_ROAM) - tt_global_entry->roam_at = jiffies; - kref_init(&common->refcount); - common->added_at = jiffies; - - INIT_HLIST_HEAD(&tt_global_entry->orig_list); - atomic_set(&tt_global_entry->orig_list_count, 0); - spin_lock_init(&tt_global_entry->list_lock); kref_get(&common->refcount); hash_added = batadv_hash_add(bat_priv->tt.global_hash, From b535e61347ba4a5e4558d4bb1c12eebe0a60f712 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:52 +0200 Subject: [PATCH 0022/2126] batman-adv: tt: extract merging of flags into existing global entries When an already known global TT entry is announced again, its flags have to be merged with the announced ones. Two of the merge steps also decide whether the originator list has to be purged before the announced originator is added. Move this to batadv_tt_global_merge_flags() and let it report via its return value whether the originator list has to be purged. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 87 ++++++++++++++++++------------ 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index d475f8efd44d..67e4ade5ae99 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1832,6 +1832,57 @@ out: spin_unlock_bh(&tt_global->list_lock); } +/** + * batadv_tt_global_merge_flags() - merge announced flags into a global TT entry + * @tt_global_entry: the global TT entry to update + * @flags: TT flags announced for this non-mesh client + * + * Return: true if the originator list of @tt_global_entry has to be purged + * before the announced originator is added, false otherwise. + */ +static bool +batadv_tt_global_merge_flags(struct batadv_tt_global_entry *tt_global_entry, + u16 flags) +{ + struct batadv_tt_common_entry *common = &tt_global_entry->common; + bool delete = false; + + scoped_guard(spinlock_bh, &common->flags_lock) { + /* if the client was temporary added before receiving the first + * OGM announcing it, we have to clear the TEMP flag. Also, + * remove the previous temporary orig node and re-add it + * if required. If the orig entry changed, the new one which + * is a non-temporary entry is preferred. + */ + if (common->flags & BATADV_TT_CLIENT_TEMP) { + delete = true; + common->flags &= ~BATADV_TT_CLIENT_TEMP; + } + + /* the change can carry possible "attribute" flags like the + * TT_CLIENT_TEMP, therefore they have to be copied in the + * client entry + */ + if (!is_multicast_ether_addr(common->addr)) + common->flags |= flags & (~BATADV_TT_SYNC_MASK); + + /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only + * one originator left in the list and we previously received a + * delete + roaming change for this originator. + * + * We should first delete the old originator before adding the + * new one. + */ + if (common->flags & BATADV_TT_CLIENT_ROAM) { + delete = true; + tt_global_entry->roam_at = 0; + common->flags &= ~BATADV_TT_CLIENT_ROAM; + } + } + + return delete; +} + /** * batadv_tt_global_create() - allocate and initialize a global TT entry * @tt_addr: the mac address of the non-mesh client @@ -1974,41 +2025,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, goto add_orig_entry; } - delete = false; - - spin_lock_bh(&common->flags_lock); - /* if the client was temporary added before receiving the first - * OGM announcing it, we have to clear the TEMP flag. Also, - * remove the previous temporary orig node and re-add it - * if required. If the orig entry changed, the new one which - * is a non-temporary entry is preferred. - */ - if (common->flags & BATADV_TT_CLIENT_TEMP) { - delete = true; - common->flags &= ~BATADV_TT_CLIENT_TEMP; - } - - /* the change can carry possible "attribute" flags like the - * TT_CLIENT_TEMP, therefore they have to be copied in the - * client entry - */ - if (!is_multicast_ether_addr(common->addr)) - common->flags |= flags & (~BATADV_TT_SYNC_MASK); - - /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only - * one originator left in the list and we previously received a - * delete + roaming change for this originator. - * - * We should first delete the old originator before adding the - * new one. - */ - if (common->flags & BATADV_TT_CLIENT_ROAM) { - delete = true; - tt_global_entry->roam_at = 0; - common->flags &= ~BATADV_TT_CLIENT_ROAM; - } - spin_unlock_bh(&common->flags_lock); - + delete = batadv_tt_global_merge_flags(tt_global_entry, flags); if (delete) batadv_tt_global_del_orig_list(tt_global_entry); } From 3f8e8b42f639a0f5c5b699d532f616128f5e2260 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:53 +0200 Subject: [PATCH 0023/2126] batman-adv: tt: replace add_orig_entry goto in batadv_tt_global_add() The "add_orig_entry" label was only used to skip the flag merging of the non-temporary path. Which means that the code jumping to it and the code below it are the two halves of an if/else. Both halves now only decide whether the originator list has to be purged, so turn them into an if/else and purge the list at a single place. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 67e4ade5ae99..760acc7be973 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -2021,15 +2021,16 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, if (batadv_tt_global_entry_has_orig(tt_global_entry, orig_node, NULL)) goto out_remove; - batadv_tt_global_del_orig_list(tt_global_entry); - goto add_orig_entry; + + delete = true; + } else { + delete = batadv_tt_global_merge_flags(tt_global_entry, flags); } - delete = batadv_tt_global_merge_flags(tt_global_entry, flags); if (delete) batadv_tt_global_del_orig_list(tt_global_entry); } -add_orig_entry: + /* add the new orig_entry (if needed) or update it */ batadv_tt_global_orig_entry_add(tt_global_entry, orig_node, ttvn, flags & BATADV_TT_SYNC_MASK); From 228c70d51b10e1ee1ddc4313218b9c7f8567d5cd Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:54 +0200 Subject: [PATCH 0024/2126] batman-adv: tt: extract removal of the superseded local entry A client which was announced by another originator is no longer a local client. The code which drops it from the local table and takes over its WIFI flag is the second cleanup stage of batadv_tt_global_add() and needed its own goto to skip over the multicast case. Move it to batadv_tt_global_purge_local(). Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 61 ++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 760acc7be973..b3e45fb5e9dd 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1832,6 +1832,46 @@ out: spin_unlock_bh(&tt_global->list_lock); } +/** + * batadv_tt_global_purge_local() - drop the local entry of an announced client + * @bat_priv: the bat priv with all the mesh interface information + * @tt_global_entry: the global TT entry of the announced client + * @flags: TT flags announced for this non-mesh client + * + * A client which is announced by another originator is no longer a local + * client. Remove it from the local table and take over the WIFI flag it was + * tracked with. + */ +static void +batadv_tt_global_purge_local(struct batadv_priv *bat_priv, + struct batadv_tt_global_entry *tt_global_entry, + u16 flags) +{ + struct batadv_tt_common_entry *common = &tt_global_entry->common; + u16 local_flags; + + /* Do not remove multicast addresses from the local hash on + * global additions + */ + if (is_multicast_ether_addr(common->addr)) + return; + + /* remove address from local hash if present */ + local_flags = batadv_tt_local_remove(bat_priv, common->addr, common->vid, + "global tt received", + flags & BATADV_TT_CLIENT_ROAM); + + scoped_guard(spinlock_bh, &common->flags_lock) { + common->flags |= local_flags & BATADV_TT_CLIENT_WIFI; + + if (!(flags & BATADV_TT_CLIENT_ROAM)) + /* this is a normal global add. Therefore the client is + * not in a roaming state anymore. + */ + common->flags &= ~BATADV_TT_CLIENT_ROAM; + } +} + /** * batadv_tt_global_merge_flags() - merge announced flags into a global TT entry * @tt_global_entry: the global TT entry to update @@ -2042,26 +2082,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, ret = true; out_remove: - /* Do not remove multicast addresses from the local hash on - * global additions - */ - if (is_multicast_ether_addr(tt_addr)) - goto out; - - /* remove address from local hash if present */ - local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid, - "global tt received", - flags & BATADV_TT_CLIENT_ROAM); - - spin_lock_bh(&tt_global_entry->common.flags_lock); - tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI; - - if (!(flags & BATADV_TT_CLIENT_ROAM)) - /* this is a normal global add. Therefore the client is not in a - * roaming state anymore. - */ - tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM; - spin_unlock_bh(&tt_global_entry->common.flags_lock); + batadv_tt_global_purge_local(bat_priv, tt_global_entry, flags); out: batadv_tt_global_entry_put(tt_global_entry); From 5e02403a4c2eb66ecd1db3e6c4ea4792cf72ad57 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:55 +0200 Subject: [PATCH 0025/2126] batman-adv: tt: extract marking of a removed local entry The first locked section of batadv_tt_local_remove() does three things at once * it snapshots the flags for the return value * it marks the client as ROAMed * it decides whether the entry has to survive until the next ttvn increment But this complex locked section is in the middle of the function and cannot be written as scoped_guard() due to goto's in this routine. Move it to batadv_tt_local_mark_removed() and report the decision via its return value. But leave the batadv_tt_local_set_pending_event() flag assembly outside the function because it has no locking requirements. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 48 ++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index b3e45fb5e9dd..f5b753ed1ae1 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1443,6 +1443,38 @@ batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, batadv_print_vid(tt_local_entry->common.vid), message); } +/** + * batadv_tt_local_mark_removed() - mark a local entry as removed + * @tt_local_entry: local TT entry to mark + * @roaming: true if the deletion is due to a roaming event + * @curr_flags: pointer to store the flags of the entry before it was marked + * + * Return: true if the entry has to be kept in the local table until the next + * ttvn increment, false if it can be purged immediately. + */ +static bool +batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry, + bool roaming, u16 *curr_flags) +{ + struct batadv_tt_common_entry *common = &tt_local_entry->common; + bool pending = false; + + scoped_guard(spinlock_bh, &common->flags_lock) { + *curr_flags = common->flags; + + /* mark the local client as ROAMed */ + if (roaming) + common->flags |= BATADV_TT_CLIENT_ROAM; + + if (!(common->flags & BATADV_TT_CLIENT_NEW)) { + common->flags |= BATADV_TT_CLIENT_PENDING; + pending = true; + } + } + + return pending; +} + /** * batadv_tt_local_remove() - logically remove an entry from the local table * @bat_priv: the bat priv with all the mesh interface information @@ -1467,26 +1499,16 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, if (!tt_local_entry) goto out; - spin_lock_bh(&tt_local_entry->common.flags_lock); - curr_flags = tt_local_entry->common.flags; - flags = BATADV_TT_CLIENT_DEL; /* if this global entry addition is due to a roaming, the node has to * mark the local entry as "roamed" in order to correctly reroute * packets later */ - if (roaming) { + if (roaming) flags |= BATADV_TT_CLIENT_ROAM; - /* mark the local client as ROAMed */ - tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM; - } - - if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) { - tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING; - pending = true; - } - spin_unlock_bh(&tt_local_entry->common.flags_lock); + pending = batadv_tt_local_mark_removed(tt_local_entry, roaming, + &curr_flags); if (pending) { batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, flags, message); From 931de98d3960d220027bdc82ebbea3ea55f7ad66 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:56 +0200 Subject: [PATCH 0026/2126] batman-adv: tt: extract immediate purge of a local entry A client which was added after the last ttvn increment was never announced and can be dropped from the local table right away. The code doing so is the second half of batadv_tt_local_remove() and needed a goto to skip the accounting when the entry was already gone from the hash. Move it to batadv_tt_local_remove_now(). Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 57 +++++++++++++++++++----------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index f5b753ed1ae1..9f61797c6492 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1475,6 +1475,42 @@ batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry, return pending; } +/** + * batadv_tt_local_remove_now() - purge a local entry which was never announced + * @bat_priv: the bat priv with all the mesh interface information + * @tt_local_entry: local TT entry to purge + * + * A client which was added right after the last ttvn increment was never sent + * to the other nodes. It can therefore be dropped from the local table without + * waiting for the next ttvn increment. + */ +static void +batadv_tt_local_remove_now(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local_entry) +{ + struct batadv_tt_common_entry *common = &tt_local_entry->common; + struct hlist_node *tt_removed_node; + + batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); + + /* remove exactly this object when still present in hash */ + tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash, + batadv_compare_tt_entry, + batadv_choose_tt, common); + if (!tt_removed_node) + return; + + /* batadv_tt_local_transition_new() may have committed the entry and + * thus counted it in the local table size since the + * BATADV_TT_CLIENT_NEW check in batadv_tt_local_mark_removed(). + */ + if (!(batadv_tt_flags_get(common) & BATADV_TT_CLIENT_NEW)) + batadv_tt_local_size_dec(bat_priv, common->vid); + + /* drop reference of remove hash entry */ + batadv_tt_local_entry_put(tt_local_entry); +} + /** * batadv_tt_local_remove() - logically remove an entry from the local table * @bat_priv: the bat priv with all the mesh interface information @@ -1490,7 +1526,6 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, bool roaming) { struct batadv_tt_local_entry *tt_local_entry; - struct hlist_node *tt_removed_node; u16 curr_flags = BATADV_NO_FLAGS; bool pending = false; u16 flags; @@ -1518,25 +1553,7 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, /* if this client has been added right now, it is possible to * immediately purge it */ - batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); - - /* remove exactly this object when still present in hash */ - tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash, - batadv_compare_tt_entry, - batadv_choose_tt, - &tt_local_entry->common); - if (!tt_removed_node) - goto out; - - /* batadv_tt_local_transition_new() may have committed the entry and - * thus counted it in the local table size since the BATADV_TT_CLIENT_NEW - * check above. - */ - if (!(batadv_tt_flags_get(&tt_local_entry->common) & BATADV_TT_CLIENT_NEW)) - batadv_tt_local_size_dec(bat_priv, tt_local_entry->common.vid); - - /* drop reference of remove hash entry */ - batadv_tt_local_entry_put(tt_local_entry); + batadv_tt_local_remove_now(bat_priv, tt_local_entry); out: batadv_tt_local_entry_put(tt_local_entry); From 926013fd40f6822ada063df8f82025d3a4a47e5a Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 30 Aug 2026 17:21:57 +0200 Subject: [PATCH 0027/2126] batman-adv: tt: drop the cleanup label from batadv_tt_local_remove() With both locked sections moved to their own helpers, the only thing left in the cleanup section is the reference of the looked up entry. The "out" label is therefore only reached with a valid entry, except for the lookup failure at the very beginning. Return BATADV_NO_FLAGS directly when there is no entry and let the two remaining cases be an if/else. Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 9f61797c6492..6c65d195f375 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1526,13 +1526,12 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, bool roaming) { struct batadv_tt_local_entry *tt_local_entry; - u16 curr_flags = BATADV_NO_FLAGS; - bool pending = false; + u16 curr_flags; u16 flags; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) - goto out; + return BATADV_NO_FLAGS; flags = BATADV_TT_CLIENT_DEL; /* if this global entry addition is due to a roaming, the node has to @@ -1542,20 +1541,15 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, if (roaming) flags |= BATADV_TT_CLIENT_ROAM; - pending = batadv_tt_local_mark_removed(tt_local_entry, roaming, - &curr_flags); - if (pending) { - batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, flags, - message); - goto out; - } + if (batadv_tt_local_mark_removed(tt_local_entry, roaming, &curr_flags)) + batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, + flags, message); + else + /* if this client has been added right now, it is possible to + * immediately purge it + */ + batadv_tt_local_remove_now(bat_priv, tt_local_entry); - /* if this client has been added right now, it is possible to - * immediately purge it - */ - batadv_tt_local_remove_now(bat_priv, tt_local_entry); - -out: batadv_tt_local_entry_put(tt_local_entry); return curr_flags; From b6d201d9714531df2b0194ec7f4a4bcee0a89238 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sun, 23 Aug 2026 11:55:55 +0800 Subject: [PATCH 0028/2126] net: phy: split phy_probe() error paths phy_probe() uses one cleanup path for failures at every initialization stage. This runs cleanup for resources that have not been initialized. After a successful probe and remove, phy_led_triggers_unregister() can leave phy_num_led_triggers non-zero after freeing the trigger array. If a subsequent probe fails before LED trigger registration, the common error path calls phy_led_triggers_unregister() with a NULL array and stale count, causing a NULL dereference. Split the cleanup by initialization stage so each failure path unwinds only the resources that may have been initialized. Unregister LED triggers before releasing the SFP upstream and ports, because the LED triggers are initialized after those resources and must be unwound first. Signed-off-by: Xuanqiang Luo Link: https://patch.msgid.link/20260823035600.188864-2-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 94b2e85e00a3..2cf70471ae08 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3706,7 +3706,7 @@ static int phy_probe(struct device *dev) if (phydev->drv->probe) { err = phydev->drv->probe(phydev); if (err) - goto out; + goto out_reset; } phy_disable_interrupts(phydev); @@ -3727,7 +3727,7 @@ static int phy_probe(struct device *dev) err = genphy_read_abilities(phydev); if (err) - goto out; + goto out_reset; if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported)) @@ -3744,7 +3744,7 @@ static int phy_probe(struct device *dev) err = phy_setup_ports(phydev); if (err) - goto out; + goto out_sfp_release; phy_advertise_supported(phydev); @@ -3753,7 +3753,7 @@ static int phy_probe(struct device *dev) */ err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee); if (err) - goto out; + goto out_sfp_release; /* Get the EEE modes we want to prohibit. */ of_set_phy_eee_broken(phydev); @@ -3806,20 +3806,22 @@ static int phy_probe(struct device *dev) if (IS_ENABLED(CONFIG_PHYLIB_LEDS) && !phy_driver_is_genphy(phydev)) { err = of_phy_leds(phydev); if (err) - goto out; + goto out_unreg_led_triggers; } return 0; -out: +out_unreg_led_triggers: + if (!phydev->is_on_sfp_module) + phy_led_triggers_unregister(phydev); + +out_sfp_release: sfp_bus_del_upstream(phydev->sfp_bus); phydev->sfp_bus = NULL; phy_cleanup_ports(phydev); - if (!phydev->is_on_sfp_module) - phy_led_triggers_unregister(phydev); - +out_reset: /* Re-assert the reset signal on error */ phy_device_reset(phydev, 1); From f558204abcb905adc492f74a9536c794b9371a23 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sun, 23 Aug 2026 11:55:56 +0800 Subject: [PATCH 0029/2126] net: phy: unregister SFP upstream before port cleanup Commit 4497f5028675 ("net: phy: Clean the phy_ports after unregistering the downstream SFP bus") established that an SFP upstream must be unregistered before its phy_ports are destroyed because SFP callbacks may access these ports. phy_setup_ports() does not follow this order when a later port setup step fails after phy_sfp_probe() succeeds. It destroys the SFP phy_port and leaves phy_probe() to unregister the upstream later, creating a race between port destruction and SFP upstream callbacks. The error unwind is also split across three functions. If phy_setup_sfp_port() fails, phy_sfp_probe() leaves the upstream registered and relies on phy_probe() to remove it after phy_setup_ports() returns. Make each layer unwind the resources it successfully set up. Unregister only the upstream in phy_sfp_probe() when SFP port setup fails, since the failed port has already been destroyed. Add phy_sfp_release() for a successful SFP probe, and make phy_setup_ports() use it before cleaning up the remaining ports. Once phy_setup_ports() has rolled back all port setup, make phy_probe() skip this cleanup. Reviewed-by: Andrew Lunn Signed-off-by: Xuanqiang Luo Link: https://patch.msgid.link/20260823035600.188864-3-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2cf70471ae08..4b9b2300422f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1723,12 +1723,41 @@ static int phy_sfp_probe(struct phy_device *phydev) phydev->sfp_bus = NULL; } - if (!ret && phydev->sfp_bus) + if (!ret && phydev->sfp_bus) { ret = phy_setup_sfp_port(phydev); + if (ret) { + sfp_bus_del_upstream(phydev->sfp_bus); + phydev->sfp_bus = NULL; + } + } return ret; } +/** + * phy_sfp_release - release resources set up by phy_sfp_probe() + * @phydev: the PHY device + * + * Release the SFP resources set up by a successful phy_sfp_probe(). Unregister + * the upstream before destroying its phy_port, so SFP upstream callbacks cannot + * race with port destruction. + */ +static void phy_sfp_release(struct phy_device *phydev) +{ + struct phy_port *port, *tmp; + + sfp_bus_del_upstream(phydev->sfp_bus); + phydev->sfp_bus = NULL; + + list_for_each_entry_safe(port, tmp, &phydev->ports, head) { + if (!port->is_sfp) + continue; + + phy_del_port(phydev, port); + phy_port_destroy(port); + } +} + static bool phy_drv_supports_irq(const struct phy_driver *phydrv) { return phydrv->config_intr && phydrv->handle_interrupt; @@ -3547,13 +3576,13 @@ static int phy_setup_ports(struct phy_device *phydev) if (!phydev->is_genphy_driven) { ret = phy_sfp_probe(phydev); if (ret) - goto out; + goto err_ports; } if (phydev->n_ports < phydev->max_n_ports) { ret = phy_default_setup_single_port(phydev); if (ret) - goto out; + goto err_sfp; } linkmode_zero(ports_supported); @@ -3580,7 +3609,9 @@ static int phy_setup_ports(struct phy_device *phydev) return 0; -out: +err_sfp: + phy_sfp_release(phydev); +err_ports: phy_cleanup_ports(phydev); return ret; } @@ -3744,7 +3775,7 @@ static int phy_probe(struct device *dev) err = phy_setup_ports(phydev); if (err) - goto out_sfp_release; + goto out_reset; phy_advertise_supported(phydev); @@ -3816,9 +3847,7 @@ out_unreg_led_triggers: phy_led_triggers_unregister(phydev); out_sfp_release: - sfp_bus_del_upstream(phydev->sfp_bus); - phydev->sfp_bus = NULL; - + phy_sfp_release(phydev); phy_cleanup_ports(phydev); out_reset: @@ -3842,9 +3871,7 @@ static int phy_remove(struct device *dev) phydev->state = PHY_DOWN; - sfp_bus_del_upstream(phydev->sfp_bus); - phydev->sfp_bus = NULL; - + phy_sfp_release(phydev); phy_cleanup_ports(phydev); if (phydev->drv && phydev->drv->remove) From 52dd7eb1a33e51f781e882cfed01de6412613fbc Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sun, 23 Aug 2026 11:55:57 +0800 Subject: [PATCH 0030/2126] net: phy: set PHY_READY after LED setup phy_probe() sets PHY_READY before calling of_phy_leds(). If LED setup fails, the error path releases the initialized resources while the PHY state remains READY even though probing failed. Set PHY_READY only after LED setup succeeds. Reviewed-by: Andrew Lunn Signed-off-by: Xuanqiang Luo Link: https://patch.msgid.link/20260823035600.188864-4-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 4b9b2300422f..891df46d0597 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3824,9 +3824,6 @@ static int phy_probe(struct device *dev) phydev->supported); } - /* Set the state to READY by default */ - phydev->state = PHY_READY; - /* Register the PHY LED triggers */ if (!phydev->is_on_sfp_module) phy_led_triggers_register(phydev); @@ -3840,6 +3837,9 @@ static int phy_probe(struct device *dev) goto out_unreg_led_triggers; } + /* Set the state to READY by default */ + phydev->state = PHY_READY; + return 0; out_unreg_led_triggers: From afd5aecd3c0721a04609992a37904b925e2097f6 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sun, 23 Aug 2026 11:55:58 +0800 Subject: [PATCH 0031/2126] net: phy: call driver remove when core initialization fails phy_probe() may fail while querying features or completing other core initialization after the PHY driver probe callback has succeeded. The driver core does not run the remove path after a probe error, so resources that the PHY driver releases in its remove callback are leaked. Call the PHY driver remove callback on these failures. Reviewed-by: Andrew Lunn Signed-off-by: Xuanqiang Luo Link: https://patch.msgid.link/20260823035600.188864-5-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 891df46d0597..691396794dec 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3758,7 +3758,7 @@ static int phy_probe(struct device *dev) err = genphy_read_abilities(phydev); if (err) - goto out_reset; + goto out_remove; if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported)) @@ -3775,7 +3775,7 @@ static int phy_probe(struct device *dev) err = phy_setup_ports(phydev); if (err) - goto out_reset; + goto out_remove; phy_advertise_supported(phydev); @@ -3850,6 +3850,10 @@ out_sfp_release: phy_sfp_release(phydev); phy_cleanup_ports(phydev); +out_remove: + if (phydev->drv->remove) + phydev->drv->remove(phydev); + out_reset: /* Re-assert the reset signal on error */ phy_device_reset(phydev, 1); From 48378efebbe7bf7a2533bc59a7acb94fcf46021e Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sun, 23 Aug 2026 11:55:59 +0800 Subject: [PATCH 0032/2126] net: phy: propagate errors from default port setup phy_default_setup_single_port() ignores errors from phy_add_port() and always reports success. If a PHY driver attach_mdi_port() callback fails, the phy_port is leaked and PHY probing continues without the expected default port. Destroy the port and return the error. Reviewed-by: Maxime Chevallier Signed-off-by: Xuanqiang Luo Link: https://patch.msgid.link/20260823035600.188864-6-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 691396794dec..8cb0d60fcbba 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3483,6 +3483,7 @@ static int phy_default_setup_single_port(struct phy_device *phydev) { struct phy_port *port = phy_port_alloc(); unsigned long mode; + int ret; if (!port) return -ENOMEM; @@ -3509,9 +3510,11 @@ static int phy_default_setup_single_port(struct phy_device *phydev) port->pairs = max_t(int, port->pairs, ethtool_linkmode_n_pairs(mode)); - phy_add_port(phydev, port); + ret = phy_add_port(phydev, port); + if (ret) + phy_port_destroy(port); - return 0; + return ret; } static int of_phy_ports(struct phy_device *phydev) From f7f619ecda5761bd48578764ef5ff9e8fd97b916 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sun, 23 Aug 2026 11:56:00 +0800 Subject: [PATCH 0033/2126] net: phy: avoid double-free after LED trigger registration failure phy_led_triggers_register() frees phy_led_triggers when a speed trigger registration fails, but leaves the pointer set to the freed allocation before clearing phy_num_led_triggers. phy_probe() ignores the registration error. If a later probe step fails, its error path calls phy_led_triggers_unregister(); normal teardown during an unbind or MDIO bus removal calls the same helper from phy_remove(). In either case, the trigger count is zero, so the per-trigger unregister loop is skipped, but the dangling pointer is still freed unconditionally. Clear the pointer when partial registration cleanup frees the array, and make phy_led_triggers_unregister() free the array only when its pointer is non-NULL. Signed-off-by: Xuanqiang Luo Link: https://patch.msgid.link/20260823035600.188864-7-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_led_triggers.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c index 4eb7716bb9d6..ff6e518395be 100644 --- a/drivers/net/phy/phy_led_triggers.c +++ b/drivers/net/phy/phy_led_triggers.c @@ -126,6 +126,7 @@ out_unreg: while (i--) phy_led_trigger_unregister(&phy->phy_led_triggers[i]); kfree(phy->phy_led_triggers); + phy->phy_led_triggers = NULL; out_unreg_link: phy_led_trigger_unregister(phy->led_link_trigger); out_free_link: @@ -141,10 +142,12 @@ void phy_led_triggers_unregister(struct phy_device *phy) { int i; - for (i = 0; i < phy->phy_num_led_triggers; i++) - phy_led_trigger_unregister(&phy->phy_led_triggers[i]); - kfree(phy->phy_led_triggers); - phy->phy_led_triggers = NULL; + if (phy->phy_led_triggers) { + for (i = 0; i < phy->phy_num_led_triggers; i++) + phy_led_trigger_unregister(&phy->phy_led_triggers[i]); + kfree(phy->phy_led_triggers); + phy->phy_led_triggers = NULL; + } if (phy->led_link_trigger) { phy_led_trigger_unregister(phy->led_link_trigger); From 25c1f6111034aef7fc06cfbdcf1e4f0d6e5ee74b Mon Sep 17 00:00:00 2001 From: ZhaoJinming Date: Thu, 27 Aug 2026 10:54:15 +0800 Subject: [PATCH 0034/2126] net: stmmac: stop DMA before freeing descriptors on open In __stmmac_open() and stmmac_xdp_open(), the DMA engine is started before stmmac_request_irq() is called. If the IRQ request fails, the clean-up paths free the DMA descriptor rings via dma_free_coherent() without stopping the DMA engine first. With the DMA engine still running, hardware may continue to access the descriptor ring memory after it has been freed. Add stmmac_stop_all_dma() to both error paths, matching the teardown order in __stmmac_release(). Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: ZhaoJinming Link: https://patch.msgid.link/32EB352EB66D74E7+20260827025415.2684733-1-zhaojinming@uniontech.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f2fc89176654..66ae365e1c89 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4177,6 +4177,8 @@ static int __stmmac_open(struct net_device *dev, irq_error: phylink_stop(priv->phylink); + stmmac_stop_all_dma(priv); + for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer); @@ -7187,6 +7189,8 @@ int stmmac_xdp_open(struct net_device *dev) return 0; irq_error: + stmmac_stop_all_dma(priv); + for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer); From 85ca3292d7a3e06a6cdc3d7aca7b498f5a4e0ec9 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Mon, 31 Aug 2026 09:13:50 +0200 Subject: [PATCH 0035/2126] net: stmmac: Remove ARP offload code dwmac can do ARP offloading, where the HW replies to incoming ARP requests. This requires multiple steps to work well : - Program the local IP address in a dedicated register - Enable ARP offloading This is halfway implemented in stmmac, as it's only ever used by selftests, and these selftests are failing on at least 2 platforms : stm32mp1, and jh7110. There have been some attempts in the past to support this feature, but this never made it upstream. Let's just remove the test and that code, until someone actually wants that to work. We should likely have a proper API for that so that drivers can use it. Let's also not mention ARP offload in the stmmac documentation. Leave the defines in place and the capability detection, this doesn't hurt and gives some information about how the IP is synthesized. Signed-off-by: Maxime Chevallier Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260831071351.354255-1-maxime.chevallier@bootlin.com Signed-off-by: Paolo Abeni --- .../ethernet/stmicro/stmmac.rst | 1 - .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 19 --- .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 18 --- drivers/net/ethernet/stmicro/stmmac/hwif.h | 3 - .../stmicro/stmmac/stmmac_selftests.c | 112 ------------------ 5 files changed, 153 deletions(-) diff --git a/Documentation/networking/device_drivers/ethernet/stmicro/stmmac.rst b/Documentation/networking/device_drivers/ethernet/stmicro/stmmac.rst index 5d46e5036129..ea347b7e93a2 100644 --- a/Documentation/networking/device_drivers/ethernet/stmicro/stmmac.rst +++ b/Documentation/networking/device_drivers/ethernet/stmicro/stmmac.rst @@ -69,7 +69,6 @@ The following features are available in this driver: - Pulse-Per-Second Output (PPS) - MDIO Clause 22 / Clause 45 Interface - MAC Loopback - - ARP Offloading - Automatic CRC / PAD Insertion and Checking - Checksum Offload for Received and Transmitted Packets - Standard or Jumbo Ethernet Packets diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index 18b357b257cc..70c8b5a373d3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -779,22 +779,6 @@ static void dwmac4_sarc_configure(void __iomem *ioaddr, int val) writel(value, ioaddr + GMAC_CONFIG); } -static void dwmac4_set_arp_offload(struct mac_device_info *hw, bool en, - u32 addr) -{ - void __iomem *ioaddr = hw->pcsr; - u32 value; - - writel(addr, ioaddr + GMAC_ARP_ADDR); - - value = readl(ioaddr + GMAC_CONFIG); - if (en) - value |= GMAC_CONFIG_ARPEN; - else - value &= ~GMAC_CONFIG_ARPEN; - writel(value, ioaddr + GMAC_CONFIG); -} - static int dwmac4_config_l3_filter(struct mac_device_info *hw, u32 filter_no, bool en, bool ipv6, bool sa, bool inv, u32 match) @@ -926,7 +910,6 @@ const struct stmmac_ops dwmac4_ops = { .set_filter = dwmac4_set_filter, .set_mac_loopback = dwmac4_set_mac_loopback, .sarc_configure = dwmac4_sarc_configure, - .set_arp_offload = dwmac4_set_arp_offload, .config_l3_filter = dwmac4_config_l3_filter, .config_l4_filter = dwmac4_config_l4_filter, }; @@ -963,7 +946,6 @@ const struct stmmac_ops dwmac410_ops = { .flex_pps_config = dwmac5_flex_pps_config, .set_mac_loopback = dwmac4_set_mac_loopback, .sarc_configure = dwmac4_sarc_configure, - .set_arp_offload = dwmac4_set_arp_offload, .config_l3_filter = dwmac4_config_l3_filter, .config_l4_filter = dwmac4_config_l4_filter, .fpe_map_preemption_class = dwmac5_fpe_map_preemption_class, @@ -1005,7 +987,6 @@ const struct stmmac_ops dwmac510_ops = { .flex_pps_config = dwmac5_flex_pps_config, .set_mac_loopback = dwmac4_set_mac_loopback, .sarc_configure = dwmac4_sarc_configure, - .set_arp_offload = dwmac4_set_arp_offload, .config_l3_filter = dwmac4_config_l3_filter, .config_l4_filter = dwmac4_config_l4_filter, .fpe_map_preemption_class = dwmac5_fpe_map_preemption_class, diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index fc6ddb51c682..1a88cbaed70c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -1410,22 +1410,6 @@ static int dwxgmac2_config_l4_filter(struct mac_device_info *hw, u32 filter_no, return 0; } -static void dwxgmac2_set_arp_offload(struct mac_device_info *hw, bool en, - u32 addr) -{ - void __iomem *ioaddr = hw->pcsr; - u32 value; - - writel(addr, ioaddr + XGMAC_ARP_ADDR); - - value = readl(ioaddr + XGMAC_RX_CONFIG); - if (en) - value |= XGMAC_CONFIG_ARPEN; - else - value &= ~XGMAC_CONFIG_ARPEN; - writel(value, ioaddr + XGMAC_RX_CONFIG); -} - const struct stmmac_ops dwxgmac210_ops = { .core_init = dwxgmac2_core_init, .irq_modify = dwxgmac2_irq_modify, @@ -1464,7 +1448,6 @@ const struct stmmac_ops dwxgmac210_ops = { .sarc_configure = dwxgmac2_sarc_configure, .config_l3_filter = dwxgmac2_config_l3_filter, .config_l4_filter = dwxgmac2_config_l4_filter, - .set_arp_offload = dwxgmac2_set_arp_offload, .fpe_map_preemption_class = dwxgmac3_fpe_map_preemption_class, }; @@ -1519,7 +1502,6 @@ const struct stmmac_ops dwxlgmac2_ops = { .sarc_configure = dwxgmac2_sarc_configure, .config_l3_filter = dwxgmac2_config_l3_filter, .config_l4_filter = dwxgmac2_config_l4_filter, - .set_arp_offload = dwxgmac2_set_arp_offload, .fpe_map_preemption_class = dwxgmac3_fpe_map_preemption_class, }; diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 04dafec021b4..fe18f98fae45 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -407,7 +407,6 @@ struct stmmac_ops { int (*config_l4_filter)(struct mac_device_info *hw, u32 filter_no, bool en, bool udp, bool sa, bool inv, u32 match); - void (*set_arp_offload)(struct mac_device_info *hw, bool en, u32 addr); int (*fpe_map_preemption_class)(struct net_device *ndev, struct netlink_ext_ack *extack, u32 pclass); @@ -491,8 +490,6 @@ struct stmmac_ops { stmmac_do_callback(__priv, mac, config_l3_filter, __args) #define stmmac_config_l4_filter(__priv, __args...) \ stmmac_do_callback(__priv, mac, config_l4_filter, __args) -#define stmmac_set_arp_offload(__priv, __args...) \ - stmmac_do_void_callback(__priv, mac, set_arp_offload, __args) #define stmmac_fpe_map_preemption_class(__priv, __args...) \ stmmac_do_void_callback(__priv, mac, fpe_map_preemption_class, __args) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 6372ec7c3f31..664d7cfde2f1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -215,24 +215,6 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct stmmac_priv *priv, return skb; } -static struct sk_buff *stmmac_test_get_arp_skb(struct stmmac_priv *priv, - struct stmmac_packet_attrs *attr) -{ - __be32 ip_src = htonl(attr->ip_src); - __be32 ip_dst = htonl(attr->ip_dst); - struct sk_buff *skb = NULL; - - skb = arp_create(ARPOP_REQUEST, ETH_P_ARP, ip_dst, priv->dev, ip_src, - NULL, attr->src, attr->dst); - if (!skb) - return NULL; - - skb->pkt_type = PACKET_HOST; - skb->dev = priv->dev; - - return skb; -} - struct stmmac_test_priv { struct stmmac_packet_attrs *packet; struct packet_type pt; @@ -1603,97 +1585,6 @@ static int stmmac_test_l4filt_sa_udp(struct stmmac_priv *priv) return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, true); } -static int stmmac_test_arp_validate(struct sk_buff *skb, - struct net_device *ndev, - struct packet_type *pt, - struct net_device *orig_ndev) -{ - struct stmmac_test_priv *tpriv = pt->af_packet_priv; - struct ethhdr *ehdr; - struct arphdr *ahdr; - - ehdr = (struct ethhdr *)skb_mac_header(skb); - if (!ether_addr_equal_unaligned(ehdr->h_dest, tpriv->packet->src)) - goto out; - - ahdr = arp_hdr(skb); - if (ahdr->ar_op != htons(ARPOP_REPLY)) - goto out; - - tpriv->ok = true; - complete(&tpriv->comp); -out: - kfree_skb(skb); - return 0; -} - -static int stmmac_test_arpoffload(struct stmmac_priv *priv) -{ - unsigned char src[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; - unsigned char dst[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - struct stmmac_packet_attrs attr = { }; - struct stmmac_test_priv *tpriv; - struct sk_buff *skb = NULL; - u32 ip_addr = 0xdeadcafe; - u32 ip_src = 0xdeadbeef; - int ret; - - if (!priv->dma_cap.arpoffsel) - return -EOPNOTSUPP; - - tpriv = kzalloc_obj(*tpriv); - if (!tpriv) - return -ENOMEM; - - tpriv->ok = false; - init_completion(&tpriv->comp); - - tpriv->pt.type = htons(ETH_P_ARP); - tpriv->pt.func = stmmac_test_arp_validate; - tpriv->pt.dev = priv->dev; - tpriv->pt.af_packet_priv = tpriv; - tpriv->packet = &attr; - dev_add_pack(&tpriv->pt); - - attr.src = src; - attr.ip_src = ip_src; - attr.dst = dst; - attr.ip_dst = ip_addr; - - skb = stmmac_test_get_arp_skb(priv, &attr); - if (!skb) { - ret = -ENOMEM; - goto cleanup; - } - - ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr); - if (ret) { - kfree_skb(skb); - goto cleanup; - } - - ret = dev_set_promiscuity(priv->dev, 1); - if (ret) { - kfree_skb(skb); - goto cleanup; - } - - ret = dev_direct_xmit(skb, 0); - if (ret) - goto cleanup_promisc; - - wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT); - ret = tpriv->ok ? 0 : -ETIMEDOUT; - -cleanup_promisc: - dev_set_promiscuity(priv->dev, -1); -cleanup: - stmmac_set_arp_offload(priv, priv->hw, false, 0x0); - dev_remove_pack(&tpriv->pt); - kfree(tpriv); - return ret; -} - static int __stmmac_test_jumbo(struct stmmac_priv *priv, u16 queue) { struct stmmac_packet_attrs attr = { }; @@ -1911,9 +1802,6 @@ static const struct stmmac_test { }, { .name = "L4 SA UDP Filtering ", .fn = stmmac_test_l4filt_sa_udp, - }, { - .name = "ARP Offload ", - .fn = stmmac_test_arpoffload, }, { .name = "Jumbo Frame ", .fn = stmmac_test_jumbo, From 5e63ade190446c6d0ce60830ecf0553c7a1761b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Mon, 31 Aug 2026 09:34:53 +0000 Subject: [PATCH 0036/2126] netlink: specs: rt-link: update ipv6 devconf doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit devconf is even odder than described in commit 720447bd0b24 ("netlink: specs: rt-link: remove implicit structs from devconf"), where both IPv4 and IPv6 are described in an identical way: "u32 indexed by ipv?-devconf - 1 on output, on input it's a nest". There are two issues with that line for IPv6: 1) The subtraction is an IPv4 specific quirk, to avoid having an unused u32 at index 0, thus saving 4 bytes per net device being dumped: - In include/uapi/linux/ip.h the IPV4_DEVCONF_* enum begins with IPV4_DEVCONF_FORWARDING = 1, so the enum starts at 1, which is the reason for the subtraction in the IPv4 variant. - In include/uapi/linux/ipv6.h the DEVCONF_* enum begins with DEVCONF_FORWARDING = 0, so subtraction would underflow. - ipv6_store_devconf() in net/ipv6/addrconf.c also doesn't do the subtraction in the output path. 2) Setting IPv6 devconf through Netlink is not yet supported, as IFLA_INET6_CONF is not handled in inet6_set_link_af(). Reviewed-by: Fernando Fernandez Mancera Signed-off-by: Asbjørn Sloth Tønnesen Link: https://patch.msgid.link/20260831093458.472180-2-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-link.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index b80c2ac3ac31..00c915031efd 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -2218,7 +2218,7 @@ attribute-sets: name: conf type: binary sub-type: u32 - doc: u32 indexed by ipv6-devconf - 1 on output, on input it's a nest + doc: u32 indexed by ipv6-devconf on output, input is not yet implemented - name: stats type: binary From 2b0aecb7b2b1d8333a122d135c948f714cbc0fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Mon, 31 Aug 2026 09:34:54 +0000 Subject: [PATCH 0037/2126] netlink: specs: rt-link: add accept-ra-min-lft MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing enum member accept-ra-min-lft to ipv6-devconf. In commit 1671bcfd76fd ("net: add sysctl accept_ra_min_rtr_lft") the DEVCONF_* enum was extended with DEVCONF_ACCEPT_RA_MIN_RTR_LFT. It was renamed to DEVCONF_ACCEPT_RA_MIN_LFT in commit 5027d54a9c30 ("net: change accept_ra_min_rtr_lft to affect all RA lifetimes"). Shortly thereafter, this spec was introduced in commit b2f63d904e72 ("doc/netlink: Add spec for rt link messages"). This pre-existing issue was detected by Sashiko, when reviewing the first patch in this series. Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824103816.40040-1-ast%40fiberby.net Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Fernando Fernandez Mancera Link: https://patch.msgid.link/20260831093458.472180-3-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-link.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index 00c915031efd..ab677801cde8 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -494,6 +494,8 @@ definitions: name: ndisc-evict-nocarrier - name: accept-untracked-na + - + name: accept-ra-min-lft - name: ifla-icmp6-stats enum-name: From f952040d7016d13a0b0f19dfa0001f4597cc47d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Mon, 31 Aug 2026 09:34:55 +0000 Subject: [PATCH 0038/2126] netlink: specs: rt-link: add force-forwarding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing enum member force-forwarding to ipv6-devconf. In commit f24987ef6959 ("ipv6: add `force_forwarding` sysctl to enable per-interface forwarding"), the DEVCONF_* enum was extended with DEVCONF_FORCE_FORWARDING, however Gabriel forgot to add it to the spec. This pre-existing issue was detected by Sashiko, when reviewing the first patch in this series. Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824103816.40040-1-ast%40fiberby.net Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Gabriel Goller Link: https://patch.msgid.link/20260831093458.472180-4-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-link.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index ab677801cde8..61ebb9a2bad5 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -496,6 +496,8 @@ definitions: name: accept-untracked-na - name: accept-ra-min-lft + - + name: force-forwarding - name: ifla-icmp6-stats enum-name: From 8b1db02b771f0de1600766f94884817caccabfd0 Mon Sep 17 00:00:00 2001 From: Kohei Enju Date: Thu, 19 Mar 2026 17:16:42 +0000 Subject: [PATCH 0039/2126] i40e: prepare for XDP metadata ops support Prepare 'struct i40e_xdp_buff' that contains an xdp_buff and a pointer to i40e_rx_desc in order to pass the RX descriptor to the XDP kfuncs. Also in ZC path, use XSK_CHECK_PRIV_TYPE() to ensure i40e_xdp_buff doesn't exceed the offset of cb in xdp_buff_xsk. No functional changes. Signed-off-by: Kohei Enju Reviewed-by: Aleksandr Loktionov Tested-by: Patryk Holda Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 5 ++++- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 7 ++++++- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 12 ++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 0cd0e5597c90..4b11ae9ed8d5 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -3622,7 +3622,7 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring) } skip: - xdp_init_buff(&ring->xdp, xdp_frame_sz, &ring->xdp_rxq); + xdp_init_buff(&ring->xdp_ctx.xdp, xdp_frame_sz, &ring->xdp_rxq); rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len, BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c index ef5e657816f0..7f68adb5109b 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -2438,10 +2438,11 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget, unsigned int *rx_cleaned) { unsigned int total_rx_bytes = 0, total_rx_packets = 0; + struct i40e_xdp_buff *xdp_ctx = &rx_ring->xdp_ctx; u16 cleaned_count = I40E_DESC_UNUSED(rx_ring); u16 clean_threshold = rx_ring->count / 2; unsigned int offset = rx_ring->rx_offset; - struct xdp_buff *xdp = &rx_ring->xdp; + struct xdp_buff *xdp = &xdp_ctx->xdp; unsigned int xdp_xmit = 0; struct bpf_prog *xdp_prog; bool failure = false; @@ -2530,6 +2531,8 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget, if (neop) continue; + xdp_ctx->desc = rx_desc; + xdp_res = i40e_run_xdp(rx_ring, xdp, xdp_prog); if (xdp_res) { diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.h b/drivers/net/ethernet/intel/i40e/i40e_txrx.h index 1e5fd63d47f4..bb741ff3e5f2 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.h +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.h @@ -283,6 +283,11 @@ struct i40e_rx_buffer { __u32 page_count; }; +struct i40e_xdp_buff { + struct xdp_buff xdp; + const union i40e_rx_desc *desc; +}; + struct i40e_queue_stats { u64 packets; u64 bytes; @@ -345,7 +350,7 @@ struct i40e_ring { * and to resume packet building for this ring in the next call to * i40e_clean_rx_ring_irq(). */ - struct xdp_buff xdp; + struct i40e_xdp_buff xdp_ctx; /* Next descriptor to be processed; next_to_clean is updated only on * processing EOP descriptor diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 9f47388eaba5..51a05ce4c7ce 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -246,6 +246,8 @@ bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count) u32 nb_buffs, i; dma_addr_t dma; + XSK_CHECK_PRIV_TYPE(struct i40e_xdp_buff); + rx_desc = I40E_RX_DESC(rx_ring, ntu); xdp = i40e_rx_bi(rx_ring, ntu); @@ -396,6 +398,14 @@ static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring, WARN_ON_ONCE(1); } +static struct i40e_xdp_buff *xsk_buff_to_i40e_ctx(struct xdp_buff *xdp) +{ + /* xdp_buff pointer used by ZC code path is allocated as xdp_buff_xsk. + * i40e_xdp_buff private fields overlap with xdp_buff_xsk->cb. + */ + return (struct i40e_xdp_buff *)xdp; +} + /** * i40e_clean_rx_irq_zc - Consumes Rx packets from the hardware ring * @rx_ring: Rx ring @@ -472,6 +482,8 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) if (i40e_is_non_eop(rx_ring, rx_desc)) continue; + xsk_buff_to_i40e_ctx(first)->desc = rx_desc; + xdp_res = i40e_run_xdp_zc(rx_ring, first, xdp_prog); i40e_handle_xdp_result_zc(rx_ring, first, rx_desc, &rx_packets, &rx_bytes, xdp_res, &failure); From cff6f1378df7d7fcb408a8ca2259e98e7cdf7fca Mon Sep 17 00:00:00 2001 From: Kohei Enju Date: Thu, 19 Mar 2026 17:16:43 +0000 Subject: [PATCH 0040/2126] i40e: add support for bpf_xdp_metadata_rx_hash() Introduce i40e_xdp_rx_hash() which takes the same approach as i40e_rx_hash() to extract the hash from RX descriptors. Tested with X710 adapter using xdp_hw_metadata, and verified hash consistency between bpf_xdp_metadata_rx_hash() and skb->hash. Signed-off-by: Kohei Enju Reviewed-by: Aleksandr Loktionov Tested-by: Patryk Holda Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_main.c | 30 +++++++++++++++++++++ drivers/net/ethernet/intel/i40e/i40e_type.h | 5 ++++ 2 files changed, 35 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 4b11ae9ed8d5..e487d697a634 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -13582,6 +13583,34 @@ static int i40e_xdp(struct net_device *dev, } } +static int i40e_xdp_rx_hash(const struct xdp_md *_ctx, u32 *hash, + enum xdp_rss_hash_type *rss_type) +{ + const struct i40e_xdp_buff *ctx = (const void *)_ctx; + const union i40e_rx_desc *desc = ctx->desc; + struct libeth_rx_pt rx_ptype; + u8 raw_rx_ptype; + u64 status; + + status = le64_to_cpu(desc->wb.qword1.status_error_len); + raw_rx_ptype = FIELD_GET(I40E_RXD_QW1_PTYPE_MASK, status); + rx_ptype = libie_rx_pt_parse(raw_rx_ptype); + + if (!libeth_rx_pt_has_hash(ctx->xdp.rxq->dev, rx_ptype) || + FIELD_GET(I40E_RX_DESC_STATUS_FLTSTAT_MASK, status) != + I40E_RX_DESC_FLTSTAT_RSS_HASH) + return -ENODATA; + + *hash = le32_to_cpu(desc->wb.qword0.hi_dword.rss); + *rss_type = rx_ptype.hash_type; + + return 0; +} + +static const struct xdp_metadata_ops i40e_xdp_metadata_ops = { + .xmo_rx_hash = i40e_xdp_rx_hash, +}; + static const struct net_device_ops i40e_netdev_ops = { .ndo_open = i40e_open, .ndo_stop = i40e_close, @@ -13784,6 +13813,7 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); netdev->netdev_ops = &i40e_netdev_ops; + netdev->xdp_metadata_ops = &i40e_xdp_metadata_ops; netdev->watchdog_timeo = 5 * HZ; i40e_set_ethtool_ops(netdev); diff --git a/drivers/net/ethernet/intel/i40e/i40e_type.h b/drivers/net/ethernet/intel/i40e/i40e_type.h index ed8bbdb586da..16a65c6e5153 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_type.h +++ b/drivers/net/ethernet/intel/i40e/i40e_type.h @@ -4,6 +4,7 @@ #ifndef _I40E_TYPE_H_ #define _I40E_TYPE_H_ +#include #include #include "i40e_adminq.h" #include "i40e_hmc.h" @@ -699,6 +700,10 @@ enum i40e_rx_desc_status_bits { I40E_RX_DESC_STATUS_LAST /* this entry must be last!!! */ }; +#define I40E_RX_DESC_STATUS_FLTSTAT_MASK \ + GENMASK_ULL(I40E_RX_DESC_STATUS_FLTSTAT_SHIFT + 1, \ + I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) + #define I40E_RXD_QW1_STATUS_SHIFT 0 #define I40E_RXD_QW1_STATUS_MASK ((BIT(I40E_RX_DESC_STATUS_LAST) - 1) \ << I40E_RXD_QW1_STATUS_SHIFT) From bbcaa1fe8749e21e8936058be8c5b43ceced0a38 Mon Sep 17 00:00:00 2001 From: Kohei Enju Date: Thu, 19 Mar 2026 17:16:44 +0000 Subject: [PATCH 0041/2126] i40e: add support for bpf_xdp_metadata_rx_vlan_tag() Introduce i40e_xdp_rx_vlan_tag() which takes the same approach as i40e_process_skb_fields() to extract the VLAN tag from the RX descriptor. Tested with X710 adapter using xdp_hw_metadata, and confirmed that VLAN tags match between bpf_xdp_metadata_rx_vlan_tag() and skb->vlan_proto/vlan_tci. Signed-off-by: Kohei Enju Reviewed-by: Aleksandr Loktionov Tested-by: Patryk Holda Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index e487d697a634..719f45b5cb40 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -13607,8 +13607,27 @@ static int i40e_xdp_rx_hash(const struct xdp_md *_ctx, u32 *hash, return 0; } +static int i40e_xdp_rx_vlan_tag(const struct xdp_md *_ctx, __be16 *vlan_proto, + u16 *vlan_tci) +{ + const struct i40e_xdp_buff *ctx = (const void *)_ctx; + const union i40e_rx_desc *desc = ctx->desc; + u64 status; + + status = le64_to_cpu(desc->wb.qword1.status_error_len); + + if (!(status & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT))) + return -ENODATA; + + *vlan_proto = cpu_to_be16(ETH_P_8021Q); + *vlan_tci = le16_to_cpu(desc->wb.qword0.lo_dword.l2tag1); + + return 0; +} + static const struct xdp_metadata_ops i40e_xdp_metadata_ops = { .xmo_rx_hash = i40e_xdp_rx_hash, + .xmo_rx_vlan_tag = i40e_xdp_rx_vlan_tag, }; static const struct net_device_ops i40e_netdev_ops = { From 907bd786209ed8c735db94889386aa48d2409d6a Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Thu, 14 May 2026 12:37:33 +1200 Subject: [PATCH 0042/2126] i40e: Avoid repeating RX filter warning When the i40e runs out of space for RX filters the driver switches to promiscuous mode and warns that it has done so. In scenarios with a large number of these filters this can generate a lot of warnings. For example: $ dmesg -c > /dev/null $ ip link add dev br0 type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set dev eth7 master br0 $ bridge vlan add vid 1 dev eth7 pvid untagged self $ bridge vlan add vid 2-4094 dev eth7 tagged $ dmesg [ 25.601705] i40e 0000:01:00.1: Error LIBIE_AQ_RC_ENOSPC, forcing overflow promiscuous on PF [ 25.601833] i40e 0000:01:00.1: Error LIBIE_AQ_RC_ENOSPC, forcing overflow promiscuous on PF [ 25.601961] i40e 0000:01:00.1: Error LIBIE_AQ_RC_ENOSPC, forcing overflow promiscuous on PF [ 25.602088] i40e 0000:01:00.1: Error LIBIE_AQ_RC_ENOSPC, forcing overflow promiscuous on PF [ 25.602216] i40e 0000:01:00.1: Error LIBIE_AQ_RC_ENOSPC, forcing overflow promiscuous on PF [ 25.602344] i40e 0000:01:00.1: Error LIBIE_AQ_RC_ENOSPC, forcing overflow promiscuous on PF ... Use test_and_set_bit() so that the warning is only issued when the driver enables promiscuous mode and not on the addition of subsequent RX filters. Signed-off-by: Chris Packham Reviewed-by: Aleksandr Loktionov Reviewed-by: Simon Horman Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 719f45b5cb40..abbc71e815ae 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -2412,10 +2412,12 @@ void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, if (fcnt != num_add) { if (vsi->type == I40E_VSI_MAIN) { - set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); - dev_warn(&vsi->back->pdev->dev, - "Error %s adding RX filters on %s, promiscuous mode forced on\n", - libie_aq_str(aq_status), vsi_name); + if (!test_and_set_bit(__I40E_VSI_OVERFLOW_PROMISC, + vsi->state)) { + dev_warn(&vsi->back->pdev->dev, + "Error %s adding RX filters on %s, promiscuous mode forced on\n", + libie_aq_str(aq_status), vsi_name); + } } else if (vsi->type == I40E_VSI_SRIOV || vsi->type == I40E_VSI_VMDQ1 || vsi->type == I40E_VSI_VMDQ2) { @@ -2465,10 +2467,11 @@ i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, } if (aq_ret) { - set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); - dev_warn(&vsi->back->pdev->dev, - "Error %s, forcing overflow promiscuous on %s\n", - libie_aq_str(hw->aq.asq_last_status), vsi_name); + if (!test_and_set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state)) { + dev_warn(&vsi->back->pdev->dev, + "Error %s, forcing overflow promiscuous on %s\n", + libie_aq_str(hw->aq.asq_last_status), vsi_name); + } } return aq_ret; From d7470cba6dfaac917710ef77192a94d57cb69f00 Mon Sep 17 00:00:00 2001 From: Jakub Sitnicki Date: Mon, 31 Aug 2026 08:27:38 +0200 Subject: [PATCH 0043/2126] net: Make skb_ext_put_sp() idempotent The sec_path extension can be released either when it is deleted from an skb or when the last skb holding the extension block is freed. Make skb_ext_put_sp() safe to call from both paths by returning when sec_path->len is zero and clearing it after dropping the XFRM state references. This will let __skb_ext_put() release the sec_path without checking whether the extension is present first, which is needed if we want to reuse skb_ext chunks area after skb scrubbing. Signed-off-by: Jakub Sitnicki Link: https://patch.msgid.link/20260831-skb-ext-prep-work-v1-1-ecc2a8542fd9@cloudflare.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 966af3beed94..aa8b42c74f42 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7236,8 +7236,12 @@ static void skb_ext_put_sp(struct sec_path *sp) { unsigned int i; + if (!sp->len) + return; + for (i = 0; i < sp->len; i++) xfrm_state_put(sp->xvec[i]); + sp->len = 0; } #endif @@ -7260,10 +7264,8 @@ void __skb_ext_del(struct sk_buff *skb, enum skb_ext_id id) #ifdef CONFIG_XFRM } else if (id == SKB_EXT_SEC_PATH && refcount_read(&ext->refcnt) == 1) { - struct sec_path *sp = skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH); - skb_ext_put_sp(sp); - sp->len = 0; + skb_ext_put_sp(skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH)); #endif } } From dbe45b209edf9b43ec56a1e6858c055c1eb332c3 Mon Sep 17 00:00:00 2001 From: Jakub Sitnicki Date: Mon, 31 Aug 2026 08:27:39 +0200 Subject: [PATCH 0044/2126] net: Make skb_ext_put_mctp() idempotent The MCTP flow extension can be released either when it is deleted from an skb or when the last skb holding the extension block is freed. Handle the release in __skb_ext_del(), which is currently missing, and make skb_ext_put_mctp() safe to call from both paths. This will let __skb_ext_put() release the MCTP key without checking whether the extension is present first, which is needed if we want to reuse skb_ext chunks area after skb scrubbing. Suggested-by: Florian Westphal Signed-off-by: Jakub Sitnicki Acked-by: Jeremy Kerr Link: https://patch.msgid.link/20260831-skb-ext-prep-work-v1-2-ecc2a8542fd9@cloudflare.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index aa8b42c74f42..ab195b99c853 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7248,8 +7248,11 @@ static void skb_ext_put_sp(struct sec_path *sp) #ifdef CONFIG_MCTP_FLOWS static void skb_ext_put_mctp(struct mctp_flow *flow) { - if (flow->key) - mctp_key_unref(flow->key); + if (!flow->key) + return; + + mctp_key_unref(flow->key); + flow->key = NULL; } #endif @@ -7261,13 +7264,20 @@ void __skb_ext_del(struct sk_buff *skb, enum skb_ext_id id) if (skb->active_extensions == 0) { skb->extensions = NULL; __skb_ext_put(ext); -#ifdef CONFIG_XFRM - } else if (id == SKB_EXT_SEC_PATH && - refcount_read(&ext->refcnt) == 1) { + return; + } + if (refcount_read(&ext->refcnt) > 1) + return; + +#ifdef CONFIG_XFRM + if (id == SKB_EXT_SEC_PATH) skb_ext_put_sp(skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH)); #endif - } +#ifdef CONFIG_MCTP_FLOWS + if (id == SKB_EXT_MCTP) + skb_ext_put_mctp(skb_ext_get_ptr(ext, SKB_EXT_MCTP)); +#endif } EXPORT_SYMBOL(__skb_ext_del); From c29b37ed7a4d9856ed758a82282456d69cee2ed1 Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 30 Aug 2026 22:24:58 +0800 Subject: [PATCH 0045/2126] net: fbnic: validate mailbox TLV extents The mailbox path warns when a message claims more bytes than the descriptor but still parses it. The attribute walkers also validate a child TLV before proving that its declared span fits in the parent remainder. Reject invalid mailbox message extents and bound each child attribute before type-specific validation. Cc: stable+noautosel@kernel.org # assumes malicious PCIe device Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260830142516.38145-1-pengpeng@iscas.ac.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 9 ++++++--- drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c index 283d25fae79e..ff1674eff7ad 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c @@ -1677,16 +1677,19 @@ static void fbnic_mbx_process_rx_msgs(struct fbnic_dev *fbd) if (!length) goto next_page; - /* Report descriptors with length greater than page size */ - if (length > PAGE_SIZE) { + /* Report descriptors with invalid message extents. */ + if (length < sizeof(msg->hdr) || length > PAGE_SIZE) { dev_warn(fbd->dev, "Invalid mailbox descriptor length: %lld\n", length); goto next_page; } - if (le16_to_cpu(msg->hdr.len) * sizeof(u32) > length) + if (!le16_to_cpu(msg->hdr.len) || + le16_to_cpu(msg->hdr.len) * sizeof(u32) > length) { dev_warn(fbd->dev, "Mailbox message length mismatch\n"); + goto next_page; + } /* If parsing fails dump contents of message to dmesg */ err = fbnic_tlv_msg_parse(fbd, msg, fbnic_fw_tlv_parser); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c index c55d4f76a5fc..3ef3935c0419 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c @@ -430,6 +430,10 @@ int fbnic_tlv_attr_parse_array(struct fbnic_tlv_msg *attr, int len, u16 attr_len; int err; + attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len)); + if (!attr_len || attr_len > len) + return -EINVAL; + if (tlv_attr_id != attr_id) return -EINVAL; @@ -443,7 +447,6 @@ int fbnic_tlv_attr_parse_array(struct fbnic_tlv_msg *attr, int len, results[i++] = attr; - attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len)); len -= attr_len; attr += attr_len; } @@ -476,11 +479,16 @@ int fbnic_tlv_attr_parse(struct fbnic_tlv_msg *attr, int len, /* Work through list of attributes, parsing them as necessary */ while (len > 0) { - int err = fbnic_tlv_attr_validate(attr, tlv_index); u16 attr_id = attr->hdr.type; u16 attr_len; + int err; + + attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len)); + if (!attr_len || attr_len > len) + return -EINVAL; /* Stop parsing on full error */ + err = fbnic_tlv_attr_validate(attr, tlv_index); if (err < 0) return err; @@ -493,7 +501,6 @@ int fbnic_tlv_attr_parse(struct fbnic_tlv_msg *attr, int len, results[attr_id] = attr; } - attr_len = FBNIC_TLV_MSG_SIZE(le16_to_cpu(attr->hdr.len)); len -= attr_len; attr += attr_len; } From de25d015c1bc5411ea8c672fbd44d717b84cf49c Mon Sep 17 00:00:00 2001 From: Chelsy Ratnawat Date: Mon, 3 Aug 2026 04:58:25 -0700 Subject: [PATCH 0046/2126] wifi: rtlwifi: rtl8192cu: Remove logically dead code in rtl92cu_update_hal_rate_mask() The variable 'mimo_ps' is initialized to IEEE80211_SMPS_OFF and never modified throughout the function. This makes the condition checking for IEEE80211_SMPS_STATIC always evaluate to false, rendering the entire if-branch unreachable dead code. This warning was reported by Coverity Scan. Signed-off-by: Chelsy Ratnawat Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260803115826.992789-1-chelsyratnawat2001@gmail.com --- .../wireless/realtek/rtlwifi/rtl8192cu/hw.c | 72 ++++++++----------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c index 989e7cff8e20..e75f7ec44e6a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c @@ -1911,7 +1911,6 @@ static void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, bool shortgi = false; u8 rate_mask[5]; u8 macid = 0; - u8 mimo_ps = IEEE80211_SMPS_OFF; sta_entry = (struct rtl_sta_info *) sta->drv_priv; wirelessmode = sta_entry->wireless_mode; @@ -1956,47 +1955,38 @@ static void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, case WIRELESS_MODE_N_5G: ratr_index = RATR_INX_WIRELESS_NGB; - if (mimo_ps == IEEE80211_SMPS_STATIC) { - if (rssi_level == 1) - ratr_bitmap &= 0x00070000; - else if (rssi_level == 2) - ratr_bitmap &= 0x0007f000; - else - ratr_bitmap &= 0x0007f005; - } else { - if (rtlphy->rf_type == RF_1T2R || - rtlphy->rf_type == RF_1T1R) { - if (curtxbw_40mhz) { - if (rssi_level == 1) - ratr_bitmap &= 0x000f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x000ff000; - else - ratr_bitmap &= 0x000ff015; - } else { - if (rssi_level == 1) - ratr_bitmap &= 0x000f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x000ff000; - else - ratr_bitmap &= 0x000ff005; - } + if (rtlphy->rf_type == RF_1T2R || + rtlphy->rf_type == RF_1T1R) { + if (curtxbw_40mhz) { + if (rssi_level == 1) + ratr_bitmap &= 0x000f0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x000ff000; + else + ratr_bitmap &= 0x000ff015; } else { - if (curtxbw_40mhz) { - if (rssi_level == 1) - ratr_bitmap &= 0x0f0f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x0f0ff000; - else - ratr_bitmap &= 0x0f0ff015; - } else { - if (rssi_level == 1) - ratr_bitmap &= 0x0f0f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x0f0ff000; - else - ratr_bitmap &= 0x0f0ff005; - } + if (rssi_level == 1) + ratr_bitmap &= 0x000f0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x000ff000; + else + ratr_bitmap &= 0x000ff005; + } + } else { + if (curtxbw_40mhz) { + if (rssi_level == 1) + ratr_bitmap &= 0x0f0f0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x0f0ff000; + else + ratr_bitmap &= 0x0f0ff015; + } else { + if (rssi_level == 1) + ratr_bitmap &= 0x0f0f0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x0f0ff000; + else + ratr_bitmap &= 0x0f0ff005; } } From bf81c3cb25a384c60dc0736af8806590f706ba0b Mon Sep 17 00:00:00 2001 From: Chelsy Ratnawat Date: Mon, 3 Aug 2026 06:12:03 -0700 Subject: [PATCH 0047/2126] wifi: rtlwifi: rtl8192cu: Remove logically dead code in rtl92cu_update_hal_rate_table() The variable 'mimo_ps' is initialized to IEEE80211_SMPS_OFF and never modified throughout the function. This makes the condition checking for IEEE80211_SMPS_STATIC always evaluate to false, rendering the entire if-branch unreachable dead code. This warning was reported by Coverity Scan. Signed-off-by: Chelsy Ratnawat Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260803131203.998989-1-chelsyratnawat2001@gmail.com --- .../wireless/realtek/rtlwifi/rtl8192cu/hw.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c index e75f7ec44e6a..199bab58363c 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c @@ -1809,10 +1809,9 @@ static void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw, struct rtl_phy *rtlphy = &(rtlpriv->phy); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); - u32 ratr_value; + u32 ratr_value, ratr_mask; u8 ratr_index = 0; u8 nmode = mac->ht_enable; - u8 mimo_ps = IEEE80211_SMPS_OFF; u16 shortgi_rate; u32 tmp_ratr_value; u8 curtxbw_40mhz = mac->bw_40; @@ -1844,19 +1843,14 @@ static void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw, case WIRELESS_MODE_N_24G: case WIRELESS_MODE_N_5G: nmode = 1; - if (mimo_ps == IEEE80211_SMPS_STATIC) { - ratr_value &= 0x0007F005; - } else { - u32 ratr_mask; - if (get_rf_type(rtlphy) == RF_1T2R || - get_rf_type(rtlphy) == RF_1T1R) - ratr_mask = 0x000ff005; - else - ratr_mask = 0x0f0ff005; + if (get_rf_type(rtlphy) == RF_1T2R || + get_rf_type(rtlphy) == RF_1T1R) + ratr_mask = 0x000ff005; + else + ratr_mask = 0x0f0ff005; - ratr_value &= ratr_mask; - } + ratr_value &= ratr_mask; break; default: if (rtlphy->rf_type == RF_1T2R) From 5628372f8feaab14b8d2abfb7f2c03dbc7cf48b0 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 4 Aug 2026 10:58:32 +0100 Subject: [PATCH 0048/2126] wifi: rtw89: coex: Fix spelling mistake "verseion" -> "version" There is a spelling mistake in a rtw89_warn message. Fix it. Signed-off-by: Colin Ian King Reviewed-by: Chelsy Ratnawat Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260804095832.784121-1-colin.i.king@gmail.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 5a9dc4d8a00b..84ae14f993e6 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -4086,7 +4086,7 @@ static void _set_rf_trx_para(struct rtw89_dev *rtwdev) ul_para_num = chip->rf_para_ulink_num_v0; dl_para_num = chip->rf_para_dlink_num_v0; } else { - rtw89_warn(rtwdev, "[BTC]%s(), No rf_para for verseion %d\n", + rtw89_warn(rtwdev, "[BTC]%s(), No rf_para for version %d\n", __func__, ver->fcxtrx); goto next; } From 10d58823cb44681466c022054030b8e68d94ce2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A4=E3=83=A0=E3=83=86=E3=82=A3=E3=83=A4=E3=82=BA?= Date: Thu, 6 Aug 2026 03:09:41 +0600 Subject: [PATCH 0049/2126] wifi: rtw88: fix out-of-bounds CAM write when key table is full MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In rtw_ops_set_key(), when the CAM table is full, rtw_sec_get_free_cam() returns RTW_MAX_SEC_CAM_NUM (32) because find_next_zero_bit()/find_first_zero_bit() return the bitmap size when no free slot exists. The bounds check compares the returned index with ">" against total_cam_num (32), so the invalid index 32 passes the check. rtw_sec_write_cam() then indexes cam_table[32], an array declared with RTW_MAX_SEC_CAM_NUM (32) entries, causing an out-of-bounds write that corrupts the cam_map allocation bitmap. The write also sets bit 32 of cam_map, which overruns the bitmap as well. Fix the off-by-one by rejecting indices >= total_cam_num. Tested on: RTL8821CE (PCIe) on kernel 7.2.0-rc6-rtw88test-00059-g0d8395707651. The patched module loaded and associated to a WPA2 network; ping traffic passed with 0% packet loss. Reassociation and disconnect/reconnect cycles completed without errors, and the CAM table (debugfs dump_cam) showed valid key entries. The CAM-full boundary (28+ pairwise keys) requires an access point with 28+ clients and is not reachable in a single-client setup, so that path was verified by code inspection. Fixes: e3037485c68e ("rtw88: new Realtek 802.11ac driver") Cc: stable@vger.kernel.org Tested-by: イムティヤズ Signed-off-by: イムティヤズ Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260805210941.75136-1-reza1234khan1234@gmail.com --- drivers/net/wireless/realtek/rtw88/mac80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw88/mac80211.c b/drivers/net/wireless/realtek/rtw88/mac80211.c index b01b98d24b0a..0b622d7663b6 100644 --- a/drivers/net/wireless/realtek/rtw88/mac80211.c +++ b/drivers/net/wireless/realtek/rtw88/mac80211.c @@ -603,7 +603,7 @@ static int rtw_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, hw_key_idx = key->keyidx; } - if (hw_key_idx > sec->total_cam_num) { + if (hw_key_idx >= sec->total_cam_num) { ret = -ENOSPC; goto out; } From 7e080e17ca38b72f6cf01e3bc750c243573e69a7 Mon Sep 17 00:00:00 2001 From: Yi Cong Date: Fri, 7 Aug 2026 16:10:06 +0800 Subject: [PATCH 0050/2126] wifi: rtw89: 8851b: fix swapped DPK channel/bandwidth backup fields The .ch and .bw backup fields are swapped; .ch should store the channel and .bw the bandwidth, matching all other chips. Fixes: 0194a95cbe721a ("wifi: rtw89: 8851b: rfk: add DPK") Cc: stable@vger.kernel.org Signed-off-by: Yi Cong Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260807081006.240450-1-cong.yi@linux.dev --- drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c b/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c index c63f0e6364da..71342461f2b3 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c @@ -1895,8 +1895,8 @@ static void _dpk_information(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy, u8 kidx = dpk->cur_idx[path]; dpk->bp[path][kidx].band = chan->band_type; - dpk->bp[path][kidx].ch = chan->band_width; - dpk->bp[path][kidx].bw = chan->channel; + dpk->bp[path][kidx].ch = chan->channel; + dpk->bp[path][kidx].bw = chan->band_width; rtw89_debug(rtwdev, RTW89_DBG_RFK, "[DPK] S%d[%d] (PHY%d): TSSI %s/ DBCC %s/ %s/ CH%d/ %s\n", From c710c7c2e0380d7c0eeb33b686262edcaef7cb07 Mon Sep 17 00:00:00 2001 From: Mehmet Fide Date: Fri, 14 Aug 2026 07:34:26 +0200 Subject: [PATCH 0051/2126] wifi: rtw88: usb: route bmc frames via the high queue only for DTIM delivery In AP mode every broadcast and multicast data frame is routed to TX_DESC_QSEL_HIGH, the after-DTIM queue, whether or not anybody is asleep. The firmware drains that queue at beacon pace, a dozen or so frames per second measured on RTL8822BU, while one associated client's mDNS/SSDP chatter alone exceeds that. The excess accumulates inside the chip until the shared TX page pool is exhausted (measured: 14 of 1803 pages left). From that point every host-sourced frame queues behind the backlog: authentication responses reach the air seconds after the client has given up, so no station can associate anymore, and the beacon reserved-page download fails the BCN_VALID poll ("error beacon valid") because it needs pages from the same pool. The AP keeps beaconing, so the failure looks like a silent RX stall and only a reboot recovers. mac80211 already decides when after-DTIM delivery is needed: it sets IEEE80211_TX_CTL_SEND_AFTER_DTIM on bmc frames only while at least one station is actually dozing. Honor that instead of routing unconditionally: flagged frames keep going through the high queue with the MORE_DATA and HGQMD handling introduced by commit 076f786a0ae1 ("wifi: rtw88: Fix AP mode incorrect DTIM behavior"), everything else leaves at line rate through the AC queues. This partially reverts the usb.c hunk of that commit, whose unconditional routing is what lets the backlog build up. On a bench AP (USB2, 20 MHz, WPA2, hostapd, a Windows client driven through disconnect/reconnect cycles): reconnects fail 0/5 on RTL8822BU and 0/3 on RTL8821CU before this change, and pass 10/10 and 5/5 with it, with the page pool staying healthy and no beacon errors logged. Signed-off-by: Mehmet Fide Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260814053426.2473247-1-mehmet.fide@gmail.com --- drivers/net/wireless/realtek/rtw88/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 64e1c3420e0a..43b9cdb4a79b 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -560,6 +560,7 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size) static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); __le16 fc = hdr->frame_control; u8 qsel; @@ -567,7 +568,8 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) qsel = TX_DESC_QSEL_MGMT; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel = TX_DESC_QSEL_HIGH; + qsel = (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ? + TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority; else From 0de28b917fd35a7ef913a034e77c5819989d1991 Mon Sep 17 00:00:00 2001 From: Chelsy Ratnawat Date: Fri, 14 Aug 2026 09:55:56 -0700 Subject: [PATCH 0052/2126] wifi: rtlwifi: remove dead mimo_ps handling from rate update code Several rtlwifi drivers declare mimo_ps as IEEE80211_SMPS_OFF and never modify it. As a result, conditionals checking for IEEE80211_SMPS_STATIC or IEEE80211_SMPS_DYNAMIC are false, making those branches unreachable. Remove the unused mimo_ps variables, drop the dead SMPS branches, and simplify the remaining rate mask selection logic without changing runtime behavior. Also move ratr_mask declarations out of the removed conditional blocks where appropriate. Signed-off-by: Chelsy Ratnawat Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260814165556.1102547-1-chelsy.ratnawat1@ibm.com --- .../wireless/realtek/rtlwifi/rtl8188ee/hw.c | 2 - .../wireless/realtek/rtlwifi/rtl8192ee/hw.c | 1 - .../wireless/realtek/rtlwifi/rtl8192se/hw.c | 94 ++++++++----------- .../wireless/realtek/rtlwifi/rtl8723ae/hw.c | 1 - .../wireless/realtek/rtlwifi/rtl8821ae/hw.c | 71 ++++++-------- 5 files changed, 69 insertions(+), 100 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c index 53c32e1de7e4..910f8372d83d 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c @@ -1970,7 +1970,6 @@ static void rtl88ee_update_hal_rate_table(struct ieee80211_hw *hw, u32 ratr_value; u8 ratr_index = 0; u8 b_nmode = mac->ht_enable; - /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ u16 shortgi_rate; u32 tmp_ratr_value; u8 curtxbw_40mhz = mac->bw_40; @@ -2070,7 +2069,6 @@ static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw *hw, bool b_shortgi = false; u8 rate_mask[5]; u8 macid = 0; - /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ sta_entry = (struct rtl_sta_info *)sta->drv_priv; wirelessmode = sta_entry->wireless_mode; diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c index 48a3c94606be..00048912900c 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c @@ -2266,7 +2266,6 @@ static void rtl92ee_update_hal_rate_mask(struct ieee80211_hw *hw, bool b_shortgi = false; u8 rate_mask[7] = {0}; u8 macid = 0; - /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ sta_entry = (struct rtl_sta_info *)sta->drv_priv; wirelessmode = sta_entry->wireless_mode; if (mac->opmode == NL80211_IFTYPE_STATION || diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c index e5775b94f04e..6b9f247d11e0 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c @@ -2001,10 +2001,9 @@ static void rtl92se_update_hal_rate_table(struct ieee80211_hw *hw, struct rtl_phy *rtlphy = &(rtlpriv->phy); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); - u32 ratr_value; + u32 ratr_value, ratr_mask; u8 ratr_index = 0; u8 nmode = mac->ht_enable; - u8 mimo_ps = IEEE80211_SMPS_OFF; u16 shortgi_rate = 0; u32 tmp_ratr_value = 0; u8 curtxbw_40mhz = mac->bw_40; @@ -2032,26 +2031,21 @@ static void rtl92se_update_hal_rate_table(struct ieee80211_hw *hw, case WIRELESS_MODE_N_24G: case WIRELESS_MODE_N_5G: nmode = 1; - if (mimo_ps == IEEE80211_SMPS_STATIC) { - ratr_value &= 0x0007F005; + + if (get_rf_type(rtlphy) == RF_1T2R || + get_rf_type(rtlphy) == RF_1T1R) { + if (curtxbw_40mhz) + ratr_mask = 0x000ff015; + else + ratr_mask = 0x000ff005; } else { - u32 ratr_mask; - - if (get_rf_type(rtlphy) == RF_1T2R || - get_rf_type(rtlphy) == RF_1T1R) { - if (curtxbw_40mhz) - ratr_mask = 0x000ff015; - else - ratr_mask = 0x000ff005; - } else { - if (curtxbw_40mhz) - ratr_mask = 0x0f0ff015; - else - ratr_mask = 0x0f0ff005; - } - - ratr_value &= ratr_mask; + if (curtxbw_40mhz) + ratr_mask = 0x0f0ff015; + else + ratr_mask = 0x0f0ff005; } + + ratr_value &= ratr_mask; break; default: if (rtlphy->rf_type == RF_1T2R) @@ -2119,7 +2113,6 @@ static void rtl92se_update_hal_rate_mask(struct ieee80211_hw *hw, u32 band = 0; bool bmulticast = false; u8 macid = 0; - u8 mimo_ps = IEEE80211_SMPS_OFF; sta_entry = (struct rtl_sta_info *) sta->drv_priv; wirelessmode = sta_entry->wireless_mode; @@ -2167,41 +2160,32 @@ static void rtl92se_update_hal_rate_mask(struct ieee80211_hw *hw, band |= (WIRELESS_11N | WIRELESS_11G | WIRELESS_11B); ratr_index = RATR_INX_WIRELESS_NGB; - if (mimo_ps == IEEE80211_SMPS_STATIC) { - if (rssi_level == 1) - ratr_bitmap &= 0x00070000; - else if (rssi_level == 2) - ratr_bitmap &= 0x0007f000; - else - ratr_bitmap &= 0x0007f005; - } else { - if (rtlphy->rf_type == RF_1T2R || - rtlphy->rf_type == RF_1T1R) { - if (rssi_level == 1) { - ratr_bitmap &= 0x000f0000; - } else if (rssi_level == 3) { - ratr_bitmap &= 0x000fc000; - } else if (rssi_level == 5) { - ratr_bitmap &= 0x000ff000; - } else { - if (curtxbw_40mhz) - ratr_bitmap &= 0x000ff015; - else - ratr_bitmap &= 0x000ff005; - } + if (rtlphy->rf_type == RF_1T2R || + rtlphy->rf_type == RF_1T1R) { + if (rssi_level == 1) { + ratr_bitmap &= 0x000f0000; + } else if (rssi_level == 3) { + ratr_bitmap &= 0x000fc000; + } else if (rssi_level == 5) { + ratr_bitmap &= 0x000ff000; } else { - if (rssi_level == 1) { - ratr_bitmap &= 0x0f8f0000; - } else if (rssi_level == 3) { - ratr_bitmap &= 0x0f8fc000; - } else if (rssi_level == 5) { - ratr_bitmap &= 0x0f8ff000; - } else { - if (curtxbw_40mhz) - ratr_bitmap &= 0x0f8ff015; - else - ratr_bitmap &= 0x0f8ff005; - } + if (curtxbw_40mhz) + ratr_bitmap &= 0x000ff015; + else + ratr_bitmap &= 0x000ff005; + } + } else { + if (rssi_level == 1) { + ratr_bitmap &= 0x0f8f0000; + } else if (rssi_level == 3) { + ratr_bitmap &= 0x0f8fc000; + } else if (rssi_level == 5) { + ratr_bitmap &= 0x0f8ff000; + } else { + if (curtxbw_40mhz) + ratr_bitmap &= 0x0f8ff015; + else + ratr_bitmap &= 0x0f8ff005; } } diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c index bd45d9bd40bb..2e50f5c24df8 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c @@ -1924,7 +1924,6 @@ static void rtl8723e_update_hal_rate_mask(struct ieee80211_hw *hw, bool shortgi = false; u8 rate_mask[5]; u8 macid = 0; - /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ sta_entry = (struct rtl_sta_info *)sta->drv_priv; wirelessmode = sta_entry->wireless_mode; diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c index 1ba53e671207..31f499be99a3 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c @@ -3468,7 +3468,6 @@ static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw *hw, bool b_shortgi = false; u8 rate_mask[7]; u8 macid = 0; - u8 mimo_ps = IEEE80211_SMPS_OFF; u8 rf_type; sta_entry = (struct rtl_sta_info *)sta->drv_priv; @@ -3535,47 +3534,37 @@ static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw *hw, else ratr_index = RATR_INX_WIRELESS_NG; - if (mimo_ps == IEEE80211_SMPS_STATIC - || mimo_ps == IEEE80211_SMPS_DYNAMIC) { - if (rssi_level == 1) - ratr_bitmap &= 0x000f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x000ff000; - else - ratr_bitmap &= 0x000ff005; - } else { - if (rf_type == RF_1T1R) { - if (curtxbw_40mhz) { - if (rssi_level == 1) - ratr_bitmap &= 0x000f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x000ff000; - else - ratr_bitmap &= 0x000ff015; - } else { - if (rssi_level == 1) - ratr_bitmap &= 0x000f0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x000ff000; - else - ratr_bitmap &= 0x000ff005; - } + if (rf_type == RF_1T1R) { + if (curtxbw_40mhz) { + if (rssi_level == 1) + ratr_bitmap &= 0x000f0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x000ff000; + else + ratr_bitmap &= 0x000ff015; } else { - if (curtxbw_40mhz) { - if (rssi_level == 1) - ratr_bitmap &= 0x0fff0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x0ffff000; - else - ratr_bitmap &= 0x0ffff015; - } else { - if (rssi_level == 1) - ratr_bitmap &= 0x0fff0000; - else if (rssi_level == 2) - ratr_bitmap &= 0x0ffff000; - else - ratr_bitmap &= 0x0ffff005; - } + if (rssi_level == 1) + ratr_bitmap &= 0x000f0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x000ff000; + else + ratr_bitmap &= 0x000ff005; + } + } else { + if (curtxbw_40mhz) { + if (rssi_level == 1) + ratr_bitmap &= 0x0fff0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x0ffff000; + else + ratr_bitmap &= 0x0ffff015; + } else { + if (rssi_level == 1) + ratr_bitmap &= 0x0fff0000; + else if (rssi_level == 2) + ratr_bitmap &= 0x0ffff000; + else + ratr_bitmap &= 0x0ffff005; } } break; From 0b772bb2d6c0b12e507131c5719c9cc6b826e6cd Mon Sep 17 00:00:00 2001 From: Mehmet Fide Date: Mon, 17 Aug 2026 08:33:19 +0200 Subject: [PATCH 0053/2126] wifi: rtw88: usb: do not log transfers lost to a mode switch An RTL8822BU or RTL8822CU is asked to come back as a USB 3 device by rtw_usb_switch_mode_new(). The chip powers off its MAC and leaves the bus while the last control transfers of that sequence are still in flight, so they complete with -EPROTO and the driver reports them as errors: rtw_8822bu 1-1:1.0: Firmware version 27.2.0, H2C version 13 rtw_8822bu 1-1:1.0: write register 0xc4 failed with -71 usb 1-1: USB disconnect, device number 2 usbcore: registered new interface driver rtw_8822bu rtw_8822bu 1-1:1.0: Firmware version 27.2.0, H2C version 13 Register 0xc4 is REG_PAD_CTRL2 and the access losing the race is the rtw_write32_set() that ends the switch sequence, a few milliseconds before the disconnect. Which transfer gets caught varies from boot to boot: 0xc4 is in the "always on" section, so every write to it is followed by a second one from rtw_usb_reg_sec(), and sometimes that is the one that fails: rtw_8822bu 1-1:1.0: rtw_usb_reg_sec: reg 0x4e0, usb write 1 fail, status: -71 Nothing is wrong here. The device re-enumerates, probes again and registers normally, which is why rtw_usb_probe() already treats a non-zero return from rtw_usb_switch_mode() as "Not a fail". On a USB 2 only port the switch can never succeed, so the message returns on every boot and everyone using such a port has to work out that it is harmless. Mark the window in which the chip is expected to leave the bus and skip the error reports for transfers that fall into it. The mark is a rtw_flags bit set in rtw_usb_switch_mode(), so it covers both the new and the old switch sequence, and it is cleared again right after them: the transfers that lose the race are issued from inside the sequences, and anything that fails later must be reported again. Tested with an RTL8822BU (0x7392:0xb822) on a USB 2 root port of a TI AM62, where the message appears exactly once per boot. With the patch both lines are gone while the disconnect, the re-enumeration and the second firmware load are unchanged. Signed-off-by: Mehmet Fide Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260817063319.389188-1-mehmet.fide@gmail.com --- drivers/net/wireless/realtek/rtw88/main.h | 1 + drivers/net/wireless/realtek/rtw88/usb.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h index c6e981ba7986..6883fbd9f768 100644 --- a/drivers/net/wireless/realtek/rtw88/main.h +++ b/drivers/net/wireless/realtek/rtw88/main.h @@ -377,6 +377,7 @@ enum rtw_flags { RTW_FLAG_RESTARTING, RTW_FLAG_RESTART_TRIGGERING, RTW_FLAG_FORCE_LOWEST_RATE, + RTW_FLAG_SWITCHING_USB_MODE, NUM_OF_RTW_FLAGS, }; diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 43b9cdb4a79b..c90802919473 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -64,7 +64,8 @@ static void rtw_usb_reg_sec(struct rtw_dev *rtwdev, u32 addr, __le32 *data) RTW_USB_CMD_REQ, RTW_USB_CMD_WRITE, t_reg, 0, data, t_len, 500); - if (status != t_len && status != -ENODEV) + if (status != t_len && status != -ENODEV && + !test_bit(RTW_FLAG_SWITCHING_USB_MODE, rtwdev->flags)) rtw_err(rtwdev, "%s: reg 0x%x, usb write %u fail, status: %d\n", __func__, t_reg, t_len, status); } @@ -90,7 +91,9 @@ static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), RTW_USB_CMD_REQ, RTW_USB_CMD_READ, addr, RTW_USB_VENQT_CMD_IDX, data, len, 1000); - if (ret < 0 && ret != -ENODEV && count++ < 4) + if (ret < 0 && ret != -ENODEV && + !test_bit(RTW_FLAG_SWITCHING_USB_MODE, rtwdev->flags) && + count++ < 4) rtw_err(rtwdev, "read register 0x%x failed with %d\n", addr, ret); @@ -140,7 +143,9 @@ static void rtw_usb_write(struct rtw_dev *rtwdev, u32 addr, u32 val, int len) ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), RTW_USB_CMD_REQ, RTW_USB_CMD_WRITE, addr, 0, data, len, 500); - if (ret < 0 && ret != -ENODEV && count++ < 4) + if (ret < 0 && ret != -ENODEV && + !test_bit(RTW_FLAG_SWITCHING_USB_MODE, rtwdev->flags) && + count++ < 4) rtw_err(rtwdev, "write register 0x%x failed with %d\n", addr, ret); @@ -1175,6 +1180,7 @@ static bool rtw_usb3_chip_new(u8 chip_id) static int rtw_usb_switch_mode(struct rtw_dev *rtwdev) { u8 id = rtwdev->chip->id; + int ret; if (!rtw_usb3_chip_new(id) && !rtw_usb3_chip_old(id)) return 0; @@ -1191,10 +1197,16 @@ static int rtw_usb_switch_mode(struct rtw_dev *rtwdev) return 0; } + set_bit(RTW_FLAG_SWITCHING_USB_MODE, rtwdev->flags); + if (rtw_usb3_chip_old(id)) - return rtw_usb_switch_mode_old(rtwdev); + ret = rtw_usb_switch_mode_old(rtwdev); else - return rtw_usb_switch_mode_new(rtwdev); + ret = rtw_usb_switch_mode_new(rtwdev); + + clear_bit(RTW_FLAG_SWITCHING_USB_MODE, rtwdev->flags); + + return ret; } #define USB_REG_PAGE 0xf4 From b1827227176821af9bba0cb643728d23328f3660 Mon Sep 17 00:00:00 2001 From: Bitterblue Smith Date: Wed, 19 Aug 2026 23:06:10 +0300 Subject: [PATCH 0054/2126] wifi: rtw89: usb: Avoid crash with dynamically added device ID Adding a device ID via sysfs causes a crash when the device is plugged in, because the driver_info pointer is null. Check for null driver_info in rtw89_usb_probe() and add a wrapper in each driver to pass it a reasonable default value. Signed-off-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/7a537b2e-67d2-40fb-8ef2-fcbc7bbc93af@gmail.com --- drivers/net/wireless/realtek/rtw89/rtw8851bu.c | 8 +++++++- drivers/net/wireless/realtek/rtw89/rtw8852au.c | 8 +++++++- drivers/net/wireless/realtek/rtw89/rtw8852bu.c | 8 +++++++- drivers/net/wireless/realtek/rtw89/rtw8852cu.c | 8 +++++++- drivers/net/wireless/realtek/rtw89/rtw8922au.c | 8 +++++++- drivers/net/wireless/realtek/rtw89/usb.c | 5 ++++- drivers/net/wireless/realtek/rtw89/usb.h | 3 ++- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851bu.c b/drivers/net/wireless/realtek/rtw89/rtw8851bu.c index 1e827205f254..6672ebe68f17 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8851bu.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8851bu.c @@ -59,10 +59,16 @@ static const struct usb_device_id rtw_8851bu_id_table[] = { }; MODULE_DEVICE_TABLE(usb, rtw_8851bu_id_table); +static int rtw8851bu_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return rtw89_usb_probe(intf, id, &rtw89_8851bu_info); +} + static struct usb_driver rtw_8851bu_driver = { .name = KBUILD_MODNAME, .id_table = rtw_8851bu_id_table, - .probe = rtw89_usb_probe, + .probe = rtw8851bu_probe, .disconnect = rtw89_usb_disconnect, }; module_usb_driver(rtw_8851bu_driver); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852au.c b/drivers/net/wireless/realtek/rtw89/rtw8852au.c index 065f4e5b17af..1a2e5dfbaab3 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852au.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852au.c @@ -73,10 +73,16 @@ static const struct usb_device_id rtw_8852au_id_table[] = { }; MODULE_DEVICE_TABLE(usb, rtw_8852au_id_table); +static int rtw8852au_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return rtw89_usb_probe(intf, id, &rtw89_8852au_info); +} + static struct usb_driver rtw_8852au_driver = { .name = KBUILD_MODNAME, .id_table = rtw_8852au_id_table, - .probe = rtw89_usb_probe, + .probe = rtw8852au_probe, .disconnect = rtw89_usb_disconnect, }; module_usb_driver(rtw_8852au_driver); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852bu.c b/drivers/net/wireless/realtek/rtw89/rtw8852bu.c index de79a19a2824..550fc4ac7a21 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852bu.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852bu.c @@ -73,10 +73,16 @@ static const struct usb_device_id rtw_8852bu_id_table[] = { }; MODULE_DEVICE_TABLE(usb, rtw_8852bu_id_table); +static int rtw8852bu_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return rtw89_usb_probe(intf, id, &rtw89_8852bu_info); +} + static struct usb_driver rtw_8852bu_driver = { .name = KBUILD_MODNAME, .id_table = rtw_8852bu_id_table, - .probe = rtw89_usb_probe, + .probe = rtw8852bu_probe, .disconnect = rtw89_usb_disconnect, }; module_usb_driver(rtw_8852bu_driver); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c index 2dec9b845481..6f852f4a713e 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c @@ -133,10 +133,16 @@ static const struct usb_device_id rtw_8852cu_id_table[] = { }; MODULE_DEVICE_TABLE(usb, rtw_8852cu_id_table); +static int rtw8852cu_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return rtw89_usb_probe(intf, id, &rtw89_8852cu_info); +} + static struct usb_driver rtw_8852cu_driver = { .name = KBUILD_MODNAME, .id_table = rtw_8852cu_id_table, - .probe = rtw89_usb_probe, + .probe = rtw8852cu_probe, .disconnect = rtw89_usb_disconnect, }; module_usb_driver(rtw_8852cu_driver); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922au.c b/drivers/net/wireless/realtek/rtw89/rtw8922au.c index 56c79b1ec865..2cd2b76d19ac 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922au.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922au.c @@ -74,10 +74,16 @@ static const struct usb_device_id rtw_8922au_id_table[] = { }; MODULE_DEVICE_TABLE(usb, rtw_8922au_id_table); +static int rtw8922au_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return rtw89_usb_probe(intf, id, &rtw89_8922au_info); +} + static struct usb_driver rtw_8922au_driver = { .name = KBUILD_MODNAME, .id_table = rtw_8922au_id_table, - .probe = rtw89_usb_probe, + .probe = rtw8922au_probe, .disconnect = rtw89_usb_disconnect, }; module_usb_driver(rtw_8922au_driver); diff --git a/drivers/net/wireless/realtek/rtw89/usb.c b/drivers/net/wireless/realtek/rtw89/usb.c index aafa8b9e93df..dbad42c17761 100644 --- a/drivers/net/wireless/realtek/rtw89/usb.c +++ b/drivers/net/wireless/realtek/rtw89/usb.c @@ -1201,7 +1201,8 @@ static const struct attribute_group rtw89_usb_group = { __ATTRIBUTE_GROUPS(rtw89_usb); int rtw89_usb_probe(struct usb_interface *intf, - const struct usb_device_id *id) + const struct usb_device_id *id, + const struct rtw89_driver_info *default_info) { const struct rtw89_driver_info *info; struct rtw89_dev *rtwdev; @@ -1209,6 +1210,8 @@ int rtw89_usb_probe(struct usb_interface *intf, int ret; info = (const struct rtw89_driver_info *)id->driver_info; + if (!info) + info = default_info; rtwdev = rtw89_alloc_ieee80211_hw(&intf->dev, sizeof(struct rtw89_usb), info); diff --git a/drivers/net/wireless/realtek/rtw89/usb.h b/drivers/net/wireless/realtek/rtw89/usb.h index bdf312559743..d2af29d068f1 100644 --- a/drivers/net/wireless/realtek/rtw89/usb.h +++ b/drivers/net/wireless/realtek/rtw89/usb.h @@ -95,7 +95,8 @@ static inline struct rtw89_usb *rtw89_usb_priv(struct rtw89_dev *rtwdev) } int rtw89_usb_probe(struct usb_interface *intf, - const struct usb_device_id *id); + const struct usb_device_id *id, + const struct rtw89_driver_info *default_info); void rtw89_usb_disconnect(struct usb_interface *intf); #endif From c5a8c4936dc5d80d1e7caa3867ed03de1ed3d766 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Rai Date: Sun, 23 Aug 2026 02:30:32 +0530 Subject: [PATCH 0055/2126] wifi: rtw88: disable ASPM and deep PS on ASUS TUF Gaming A15 FA506IH The RTL8822CE on the ASUS TUF Gaming A15 FA506IH fails to return from PCIe low-power states across system suspend. The device is inaccessible on the way back to D0, so the MAC power-on sequence and the firmware handshake that follow it fail, and the driver gives up. Wi-Fi stays unavailable until the machine is powered off completely: rtw88_8822ce 0000:03:00.0: Unable to change power state from D3cold to D0, device inaccessible rtw88_8822ce 0000:03:00.0: failed to poll offset=0x5 mask=0x2 value=0x0 rtw88_8822ce 0000:03:00.0: mac power on failed rtw88_8822ce 0000:03:00.0: probe with driver rtw88_8822ce failed with error -114 Reads of the ASPM link-configuration register over DBI also time out around the same transitions. This is not a one-off. It has been recurring on this machine for a long time. The kernel logs still on disk begin at 2026-07-20 and already contain six failed D-state transitions and three probe failures of this kind, and the problem was present well before that window. This is the same platform ASPM inter-operability problem already handled for other machines through rtw_pci_quirks[], including the closely related ASUS TUF Gaming A15 FA506II. The FA506IH reports a different DMI board name, so that entry does not match. Disabling PCI ASPM and deep power save stops the failure on this model as well. DMI_SYS_VENDOR = ASUSTeK COMPUTER INC. DMI_BOARD_NAME = FA506IH Signed-off-by: Rahul Kumar Rai Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260823-fa506ih-rtw88-quirk-v1-1-ef0984d59e72@gmail.com --- drivers/net/wireless/realtek/rtw88/pci.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c index 5b00c1e1eec6..fcb6f4c4cc2d 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -1789,6 +1789,16 @@ static const struct dmi_system_id rtw_pci_quirks[] = { .driver_data = (void *)(BIT(QUIRK_DIS_CAP_PCI_ASPM) | BIT(QUIRK_DIS_CAP_LPS_DEEP)), }, + { + .callback = rtw_pci_disable_caps, + .ident = "ASUS TUF Gaming A15 FA506IH", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_BOARD_NAME, "FA506IH"), + }, + .driver_data = (void *)(BIT(QUIRK_DIS_CAP_PCI_ASPM) | + BIT(QUIRK_DIS_CAP_LPS_DEEP)), + }, {} }; From ab468ac0156f0b6acab8fc60d4e975199a5e071e Mon Sep 17 00:00:00 2001 From: Branislav Klocok Date: Sun, 23 Aug 2026 17:42:28 +0200 Subject: [PATCH 0056/2126] wifi: rtw88: add quirks to disable PCI ASPM and deep LPS for Dell Vostro 15 3530 On a Dell Vostro 15 3530 with RTL8821CE [10ec:c821] the driver floods the kernel log with rtw88_8821ce 0000:03:00.0: failed to send h2c command at roughly 220 messages per minute while the interface is associated. On this machine that amounted to 143704 of 167707 journal lines in a single day, or 86 percent of everything logged. The association also dropped its DHCP lease from time to time. Disabling PCI ASPM and deep LPS makes the messages disappear entirely. Measured over one continuous hour with the card as the only route out and 979 MB received / 341 MB transmitted: zero occurrences, against roughly 13000 per hour before the change. The only rtw88 lines left in the log for the whole boot are the interface rename, the firmware version and "enabling device". The measurement was taken with the rtw88_pci.disable_aspm=1 and rtw88_core.disable_lps_deep=1 module parameters, which set the same two variables that rtw_pci_disable_caps() sets for a quirk entry, so the result carries over unchanged. DMI on this machine: sys_vendor: Dell Inc. product_name: Vostro 15 3530 product_sku: 0C32 board_name: 0RRJRM BIOS: 1.3.0 Signed-off-by: Branislav Klocok Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260823154228.129848-1-branislav.klocok@orava.sk --- drivers/net/wireless/realtek/rtw88/pci.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c index fcb6f4c4cc2d..04d751cef46a 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -1799,6 +1799,16 @@ static const struct dmi_system_id rtw_pci_quirks[] = { .driver_data = (void *)(BIT(QUIRK_DIS_CAP_PCI_ASPM) | BIT(QUIRK_DIS_CAP_LPS_DEEP)), }, + { + .callback = rtw_pci_disable_caps, + .ident = "Dell Vostro 15 3530", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15 3530"), + }, + .driver_data = (void *)(BIT(QUIRK_DIS_CAP_PCI_ASPM) | + BIT(QUIRK_DIS_CAP_LPS_DEEP)), + }, {} }; From 53eebd2b7f3e19bf5e94714023d326ab7b8b9c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ata=20=C4=B0lhan=20K=C3=B6kt=C3=BCrk?= Date: Sun, 23 Aug 2026 12:46:40 +0300 Subject: [PATCH 0057/2126] wifi: rtw88: disable ASPM for Lenovo IdeaPad S340-14IWL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Lenovo IdeaPad S340-14IWL (DMI product name "81N4") experiences severe connectivity issues with the Realtek 8822BE rtw88 PCIe wireless card when ASPM is enabled. Reported symptoms include frequent disconnections, cannot resume after sleep, kernel panics, and the driver failing to load time to time. The issue can be worked around by either adding pci=noaspm to the kernel command line or by reloading the driver with disable_aspm=1 via modprobe. Add a DMI quirk to disable ASPM automatically for this device. Signed-off-by: Ata İlhan Köktürk Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260823094640.22585-1-atailhan2006@gmail.com --- drivers/net/wireless/realtek/rtw88/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c index 04d751cef46a..66d2e5f51444 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -1809,6 +1809,15 @@ static const struct dmi_system_id rtw_pci_quirks[] = { .driver_data = (void *)(BIT(QUIRK_DIS_CAP_PCI_ASPM) | BIT(QUIRK_DIS_CAP_LPS_DEEP)), }, + { + .callback = rtw_pci_disable_caps, + .ident = "Lenovo IdeaPad S340-14IWL", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_NAME, "81N4"), + }, + .driver_data = (void *)BIT(QUIRK_DIS_CAP_PCI_ASPM), + }, {} }; From 483e1ebc813280dc566210ec5c48738060355f62 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:10 +1000 Subject: [PATCH 0058/2126] wifi: mm81x: move beacon work and init below the tx op Move mm81x_mac_beacon_work() and mm81x_mac_beacon_init() to below mm81x_mac_ops_tx() to prepare for future multicast handling such that we avoid a forward declaration. No functional change. Link: https://patch.msgid.link/20260827054917.255584-2-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 84 ++++++++++----------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 08ca116a68b4..4d0131246710 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -445,39 +445,6 @@ static void mm81x_beacon_h_fill_tx_info(struct mm81x *mors, cpu_to_le32(MM81X_TX_CONF_FLAGS_IMMEDIATE_REPORT); } -static void mm81x_mac_beacon_work(struct work_struct *work) -{ - struct mm81x_vif *mors_vif = - from_work(mors_vif, work, u.ap.beacon_work); - struct mm81x *mors = mm81x_vif_to_mors(mors_vif); - struct mm81x_skbq *mq; - struct sk_buff *beacon; - struct ieee80211_vif *vif = mm81x_vif_to_ieee80211_vif(mors_vif); - struct mm81x_skb_tx_info tx_info = { 0 }; - int num_bcn_vifs = atomic_read(&mors->num_bcn_vifs); - - mq = mm81x_hif_get_tx_beacon_queue(mors); - if (!mq) { - dev_err(mors->dev, "no matching beacon Q found"); - return; - } - - if (mm81x_skbq_count(mq) >= num_bcn_vifs) { - dev_err(mors->dev, - "previous beacon not consumed, dropping req [id:%d]", - mors_vif->id); - return; - } - - beacon = ieee80211_beacon_get(mors->hw, vif, false); - if (!beacon) - return; - - mm81x_beacon_h_fill_tx_info(mors, &tx_info, mors_vif, - cfg80211_chandef_s1g_pri_width(&mors->chandef)); - mm81x_skbq_skb_tx(mq, &beacon, &tx_info, MM81X_SKB_CHAN_BEACON); -} - void mm81x_mac_beacon_irq_handle(struct mm81x *mors, u32 status) { int vif_id; @@ -497,15 +464,6 @@ void mm81x_mac_beacon_irq_handle(struct mm81x *mors, u32 status) } } -static void mm81x_mac_beacon_init(struct mm81x_vif *mors_vif) -{ - struct mm81x *mors = mm81x_vif_to_mors(mors_vif); - - INIT_WORK(&mors_vif->u.ap.beacon_work, mm81x_mac_beacon_work); - mm81x_mac_beacon_irq_enable(mors_vif, true); - atomic_inc(&mors->num_bcn_vifs); -} - static struct hw_scan_tlv_hdr mm81x_hw_scan_h_pack_tlv_hdr(u16 tag, u16 len) { struct hw_scan_tlv_hdr hdr = { .tag = cpu_to_le16(tag), @@ -1329,6 +1287,48 @@ static void mm81x_mac_ops_tx(struct ieee80211_hw *hw, MM81X_SKB_CHAN_DATA); } +static void mm81x_mac_beacon_work(struct work_struct *work) +{ + struct mm81x_vif *mors_vif = + from_work(mors_vif, work, u.ap.beacon_work); + struct mm81x *mors = mm81x_vif_to_mors(mors_vif); + struct mm81x_skbq *mq; + struct sk_buff *beacon; + struct ieee80211_vif *vif = mm81x_vif_to_ieee80211_vif(mors_vif); + struct mm81x_skb_tx_info tx_info = { 0 }; + int num_bcn_vifs = atomic_read(&mors->num_bcn_vifs); + + mq = mm81x_hif_get_tx_beacon_queue(mors); + if (!mq) { + dev_err(mors->dev, "no matching beacon Q found"); + return; + } + + if (mm81x_skbq_count(mq) >= num_bcn_vifs) { + dev_err(mors->dev, + "previous beacon not consumed, dropping req [id:%d]", + mors_vif->id); + return; + } + + beacon = ieee80211_beacon_get(mors->hw, vif, false); + if (!beacon) + return; + + mm81x_beacon_h_fill_tx_info(mors, &tx_info, mors_vif, + cfg80211_chandef_s1g_pri_width(&mors->chandef)); + mm81x_skbq_skb_tx(mq, &beacon, &tx_info, MM81X_SKB_CHAN_BEACON); +} + +static void mm81x_mac_beacon_init(struct mm81x_vif *mors_vif) +{ + struct mm81x *mors = mm81x_vif_to_mors(mors_vif); + + INIT_WORK(&mors_vif->u.ap.beacon_work, mm81x_mac_beacon_work); + mm81x_mac_beacon_irq_enable(mors_vif, true); + atomic_inc(&mors->num_bcn_vifs); +} + static void mm81x_mac_ops_stop(struct ieee80211_hw *hw, bool suspend) { struct mm81x *mors = hw->priv; From ceebe279826fd781c4e90cc9a9c15c94c8b88765 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:11 +1000 Subject: [PATCH 0059/2126] wifi: mm81x: release buffered broadcast frames after DTIM Since we set the HOST_BROADCAST_PS_BUFFERING, mac80211 handles the buffering of broadcast frames. Make sure after each beacon we call ieee80211_get_buffered_bc() to release buffered broadcast frames after each DTIM beacon. Link: https://patch.msgid.link/20260827054917.255584-3-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 4d0131246710..0bbedcdd0b3d 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -66,6 +66,9 @@ /* HW restart delay time before terminating hardware IF work items */ #define MM81X_HW_RESTART_DELAY_MS 20 +/* Maximum number of multicast frames to release after a DTIM beacon */ +#define MM81X_MAX_MC_FRAMES_AFTER_DTIM 4 + /* clang-format off */ /* mm81x chips do not support 16MHz */ @@ -1287,6 +1290,20 @@ static void mm81x_mac_ops_tx(struct ieee80211_hw *hw, MM81X_SKB_CHAN_DATA); } +static void mm81x_mac_send_buffered_bc(struct mm81x *mors, + struct ieee80211_vif *vif) +{ + int count = MM81X_MAX_MC_FRAMES_AFTER_DTIM; + struct ieee80211_tx_control control = { 0 }; + struct sk_buff *bc_frame; + + while (count-- && + (bc_frame = ieee80211_get_buffered_bc(mors->hw, vif))) { + IEEE80211_SKB_CB(bc_frame)->control.vif = vif; + mm81x_mac_ops_tx(mors->hw, &control, bc_frame); + } +} + static void mm81x_mac_beacon_work(struct work_struct *work) { struct mm81x_vif *mors_vif = @@ -1318,6 +1335,9 @@ static void mm81x_mac_beacon_work(struct work_struct *work) mm81x_beacon_h_fill_tx_info(mors, &tx_info, mors_vif, cfg80211_chandef_s1g_pri_width(&mors->chandef)); mm81x_skbq_skb_tx(mq, &beacon, &tx_info, MM81X_SKB_CHAN_BEACON); + + if (!test_bit(MM81X_STATE_DATA_QS_STOPPED, &mors->state_flags)) + mm81x_mac_send_buffered_bc(mors, vif); } static void mm81x_mac_beacon_init(struct mm81x_vif *mors_vif) From 2d59a60c748362fc9be330334ecd23b0e38372f2 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:12 +1000 Subject: [PATCH 0060/2126] wifi: mm81x: do not drop PS filtered frames in AP mode When the firmware reports a frame as filtered because the station has entered power save, the AP-mode path dropped the frame and returned "handled". In AP mode mac80211 owns the per-station power-save re-buffering, so the frame must instead be reported with IEEE80211_TX_STAT_TX_FILTERED and left for mac80211 to re-queue once the station wakes. Return false for AP interfaces so the tx-status path flags the frame as filtered rather than silently dropping it. Assisted-by: Claude:claude-opus-5 Link: https://patch.msgid.link/20260827054917.255584-4-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/skbq.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/skbq.c b/drivers/net/wireless/morsemicro/mm81x/skbq.c index 25655bd56d14..3bf15e7c38d8 100644 --- a/drivers/net/wireless/morsemicro/mm81x/skbq.c +++ b/drivers/net/wireless/morsemicro/mm81x/skbq.c @@ -231,10 +231,9 @@ static bool mm81x_tx_h_is_ps_filtered(struct mm81x_skbq *mq, WARN_ON_ONCE(!(le32_to_cpu(tx_sts->flags) & MM81X_TX_STATUS_FLAGS_PS_FILTERED)); - if (vif->type == NL80211_IFTYPE_AP) { - __mm81x_skbq_drop_pending_skb(mq, skb); - return true; - } + /* mac80211 buffers frames in AP mode */ + if (vif->type == NL80211_IFTYPE_AP) + return false; if (vif->type == NL80211_IFTYPE_STATION) { mm81x_skbq_insert_pending(mq, skb, tx_sts->pkt_id); From fa17ef70279f8d3ba2a4ba448d0863cf474e0cd1 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:13 +1000 Subject: [PATCH 0061/2126] wifi: mm81x: implement .tx_frames_pending() mac op Implement .tx_frames_pending() to assist mac80211 when deciding whether we should enter powersave such that we don't enter when there are pending tx frames. Link: https://patch.msgid.link/20260827054917.255584-5-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 0bbedcdd0b3d..5bae7c6251df 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -2035,6 +2035,13 @@ static void mm81x_mac_ops_flush(struct ieee80211_hw *hw, mm81x_mac_wait_queues(mors); } +static bool mm81x_mac_ops_tx_frames_pending(struct ieee80211_hw *hw) +{ + struct mm81x *mors = hw->priv; + + return mm81x_mac_has_tx_pending(mors); +} + static int mm81x_mac_ops_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx, u32 value) { @@ -2260,6 +2267,7 @@ static const struct ieee80211_ops mm81x_ops = { .configure_filter = mm81x_mac_ops_configure_filter, .sta_state = mm81x_mac_ops_sta_state, .flush = mm81x_mac_ops_flush, + .tx_frames_pending = mm81x_mac_ops_tx_frames_pending, .set_frag_threshold = mm81x_mac_set_frag_threshold, .set_rts_threshold = mm81x_mac_ops_set_rts_threshold, .sta_statistics = mm81x_mac_ops_sta_statistics, From c9c88ce192a448ce70ac9beb1c859e7923d71cbe Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:14 +1000 Subject: [PATCH 0062/2126] wifi: mm81x: factor out tx width selection The tx mac op is getting busy, lets factor out tx width selection to prepare for some future tx width selection fixes. No functional changes. Link: https://patch.msgid.link/20260827054917.255584-6-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 54 ++++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 5bae7c6251df..1444db98351b 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -1243,38 +1243,44 @@ static void mm81x_tx_h_fill_info(struct mm81x *mors, } } +static int mm81x_tx_h_get_bw(struct mm81x *mors, struct ieee80211_sta *sta, + struct sk_buff *skb, bool is_mgmt) +{ + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + struct mm81x_sta *mors_sta = NULL; + int tx_bw_mhz; + + if (ieee80211_is_probe_resp(hdr->frame_control)) + return 1; + + if (is_mgmt) + return cfg80211_chandef_s1g_pri_width(&mors->chandef); + + if (sta) + mors_sta = (struct mm81x_sta *)sta->drv_priv; + + tx_bw_mhz = min(mm81x_tx_h_get_max_bw(mors), + cfg80211_chandef_get_width(&mors->chandef)); + if (mors_sta && mors_sta->max_bw_mhz) + tx_bw_mhz = min(tx_bw_mhz, mors_sta->max_bw_mhz); + + return tx_bw_mhz; +} + static void mm81x_mac_ops_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb) { - struct mm81x *mors = hw->priv; - struct mm81x_skbq *mq = NULL; - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - struct ieee80211_vif *vif = info->control.vif; - struct mm81x_skb_tx_info tx_info = { 0 }; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); bool is_mgmt = ieee80211_is_mgmt(hdr->frame_control); - int tx_bw_mhz = cfg80211_chandef_get_width(&mors->chandef); struct ieee80211_sta *sta = control->sta; - int max_tx_bw = 0, sta_max_bw_mhz = 0; + struct mm81x_skb_tx_info tx_info = { 0 }; + struct mm81x *mors = hw->priv; + struct mm81x_skbq *mq; - if (sta) { - struct mm81x_sta *mors_sta = (struct mm81x_sta *)sta->drv_priv; - - sta_max_bw_mhz = mors_sta->max_bw_mhz; - } - - max_tx_bw = mm81x_tx_h_get_max_bw(mors); - tx_bw_mhz = min(max_tx_bw, tx_bw_mhz); - - if (is_mgmt) - tx_bw_mhz = cfg80211_chandef_s1g_pri_width(&mors->chandef); - if (sta_max_bw_mhz) - tx_bw_mhz = min(tx_bw_mhz, sta_max_bw_mhz); - if (ieee80211_is_probe_resp(hdr->frame_control)) - tx_bw_mhz = 1; - - mm81x_tx_h_fill_info(mors, &tx_info, skb, vif, tx_bw_mhz, sta); + mm81x_tx_h_fill_info(mors, &tx_info, skb, info->control.vif, + mm81x_tx_h_get_bw(mors, sta, skb, is_mgmt), sta); if (mm81x_tx_h_ps_filtered_for_sta(mors, skb, sta)) return; From 1595123dff32ebf6d459c36cebe6e860d4d8a6d5 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:15 +1000 Subject: [PATCH 0063/2126] wifi: mm81x: tx EAPOLs at primary width Right now port control frames such as EAPOLs are sent at the operating width which, within noisier environments, can lead to increased association times and at higher attenuation potentially prevent association from occurring altogether. Make sure we send EAPOLs and any other port control frames at the primary width. Link: https://patch.msgid.link/20260827054917.255584-7-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 1444db98351b..fa3b0cfccffe 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -1247,13 +1247,14 @@ static int mm81x_tx_h_get_bw(struct mm81x *mors, struct ieee80211_sta *sta, struct sk_buff *skb, bool is_mgmt) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); struct mm81x_sta *mors_sta = NULL; int tx_bw_mhz; if (ieee80211_is_probe_resp(hdr->frame_control)) return 1; - if (is_mgmt) + if (is_mgmt || info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) return cfg80211_chandef_s1g_pri_width(&mors->chandef); if (sta) From 3208462a40d0d844de1ff3f7b0b16d78e2d55f18 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:16 +1000 Subject: [PATCH 0064/2126] wifi: mm81x: clamp tx width to stas max supported width max_bw_mhz is not populated with the stas maximum supported width during association. This means data frames are sent at the operating width, regardless of whether the sta can support the operating width. For example a STA that supports up to 4MHz receiving frames from an AP running on an 8MHz operating channel will be sent frames at 8MHz which it cannot receive. Make sure we initialise the stas maximum support bandwidth and while we are here rename it to max_rx_bw_mhz to indicate its the maximum bandwidth the sta can receive frames from. Note: This should be conveyed via ieee80211_link_sta::bandwidth, but the ieee80211_sta_rx_bandwidth enum does not support S1G widths as of now and will require some non-trivial work to support in the future. Link: https://patch.msgid.link/20260827054917.255584-8-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/core.h | 7 ++++++- drivers/net/wireless/morsemicro/mm81x/mac.c | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/core.h b/drivers/net/wireless/morsemicro/mm81x/core.h index 2fd4b4786e77..75e998e8e324 100644 --- a/drivers/net/wireless/morsemicro/mm81x/core.h +++ b/drivers/net/wireless/morsemicro/mm81x/core.h @@ -192,7 +192,12 @@ struct mm81x_sta { bool tid_tx[IEEE80211_NUM_TIDS]; bool tid_start_tx[IEEE80211_NUM_TIDS]; u8 tid_params[IEEE80211_NUM_TIDS]; - int max_bw_mhz; + + /* + * We really should be using link_sta::bandwidth but + * that requires non-trivial work. + */ + int max_rx_bw_mhz; struct mm81x_rc_sta rc; struct mmrc_rate last_sta_tx_rate; s16 avg_rssi; diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index fa3b0cfccffe..d77df6e9af85 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -325,7 +325,7 @@ static int mm81x_mac_ops_start(struct ieee80211_hw *hw) return 0; } -static int mm81x_tx_h_get_max_bw(struct mm81x *mors) +static int mm81x_tx_h_get_max_tx_bw(struct mm81x *mors) { return MM81X_FW_SUPP(&mors->fw_caps, 8MHZ) ? 8 : MM81X_FW_SUPP(&mors->fw_caps, 4MHZ) ? 4 : @@ -1260,10 +1260,10 @@ static int mm81x_tx_h_get_bw(struct mm81x *mors, struct ieee80211_sta *sta, if (sta) mors_sta = (struct mm81x_sta *)sta->drv_priv; - tx_bw_mhz = min(mm81x_tx_h_get_max_bw(mors), + tx_bw_mhz = min(mm81x_tx_h_get_max_tx_bw(mors), cfg80211_chandef_get_width(&mors->chandef)); - if (mors_sta && mors_sta->max_bw_mhz) - tx_bw_mhz = min(tx_bw_mhz, mors_sta->max_bw_mhz); + if (mors_sta && mors_sta->max_rx_bw_mhz) + tx_bw_mhz = min(tx_bw_mhz, mors_sta->max_rx_bw_mhz); return tx_bw_mhz; } @@ -1718,6 +1718,9 @@ static int mm81x_mac_ops_sta_state(struct ieee80211_hw *hw, mors_vif->u.ap.num_stas++; else if (vif->type == NL80211_IFTYPE_STATION) mors_vif->u.sta.is_assoc = true; + + mors_sta->max_rx_bw_mhz = + S1G_SUPP_CH_WIDTH_MAX(sta->deflink.s1g_cap.cap); } if (new_state < old_state && new_state == IEEE80211_STA_NONE) { From 0f5a5d9290ca1c766dfbdf534ee43f4c0b26253a Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:49:17 +1000 Subject: [PATCH 0065/2126] wifi: mm81x: tx multicast frames from AP at primary width If an AP has stations that are operating on a sub-primary (i.e using the 4MHz primary of the 8MHz operating) multicast frames sent on the operating width will be lost. Make sure we tx them on the primary width to ensure all stations are capabile of receiving them. Link: https://patch.msgid.link/20260827054917.255584-9-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index d77df6e9af85..4485748518b4 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -1257,6 +1257,15 @@ static int mm81x_tx_h_get_bw(struct mm81x *mors, struct ieee80211_sta *sta, if (is_mgmt || info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) return cfg80211_chandef_s1g_pri_width(&mors->chandef); + /* + * In AP mode group addressed frames go out at the primary width so + * that every associated STA can receive them, including any that + * cannot support the operating width. + */ + if (info->control.vif->type == NL80211_IFTYPE_AP && + is_multicast_ether_addr(ieee80211_get_DA(hdr))) + return cfg80211_chandef_s1g_pri_width(&mors->chandef); + if (sta) mors_sta = (struct mm81x_sta *)sta->drv_priv; From 273b0a8be083df6d0319ce62caa870e927f94a31 Mon Sep 17 00:00:00 2001 From: Laxman Acharya Padhya Date: Tue, 25 Aug 2026 23:29:38 +0545 Subject: [PATCH 0066/2126] wifi: rtw89: cap firmware section_num before parsing rtw89_fw_bin_info.section_info has FWDL_SECTION_MAX_NUM (10) entries. The v0/v1 header parsers take section_num from an 8-bit firmware field (0..255) and write info->section_info[i] with no cap. rtw89_fw_download_suit() keeps that object on the stack, so a crafted firmware blob overflows the stack. Reject a truncated header and a section table that does not fit in the firmware image before reading fw_hdr->sections[i]. Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver") Cc: stable@vger.kernel.org Acked-by: Ping-Ke Shih Signed-off-by: Laxman Acharya Padhya Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260825174438.63168-1-acharyalaxman8848@gmail.com --- drivers/net/wireless/realtek/rtw89/fw.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 0099c5c03e7a..b2991bc93f85 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -156,8 +156,24 @@ static int rtw89_fw_hdr_parser_v0(struct rtw89_dev *rtwdev, const u8 *fw, u32 le if (!info) return -EINVAL; + if (len < sizeof(*fw_hdr)) { + rtw89_err(rtwdev, "[ERR]fw header truncated\n"); + return -EINVAL; + } + info->section_num = le32_get_bits(fw_hdr->w6, FW_HDR_W6_SEC_NUM); + if (!info->section_num || info->section_num > FWDL_SECTION_MAX_NUM) { + rtw89_err(rtwdev, "[ERR]invalid fw section num %u\n", + info->section_num); + return -EINVAL; + } + base_hdr_len = struct_size(fw_hdr, sections, info->section_num); + if (base_hdr_len > len) { + rtw89_err(rtwdev, "[ERR]fw header truncated\n"); + return -EINVAL; + } + info->dynamic_hdr_en = le32_get_bits(fw_hdr->w7, FW_HDR_W7_DYN_HDR); info->idmem_share_mode = le32_get_bits(fw_hdr->w7, FW_HDR_W7_IDMEM_SHARE_MODE); @@ -455,9 +471,25 @@ static int rtw89_fw_hdr_parser_v1(struct rtw89_dev *rtwdev, const u8 *fw, u32 le int ret; u32 i; + if (len < sizeof(*fw_hdr)) { + rtw89_err(rtwdev, "[ERR]fw header truncated\n"); + return -EINVAL; + } + info->section_num = le32_get_bits(fw_hdr->w6, FW_HDR_V1_W6_SEC_NUM); + if (!info->section_num || info->section_num > FWDL_SECTION_MAX_NUM) { + rtw89_err(rtwdev, "[ERR]invalid fw section num %u\n", + info->section_num); + return -EINVAL; + } + info->dsp_checksum = le32_get_bits(fw_hdr->w6, FW_HDR_V1_W6_DSP_CHKSUM); base_hdr_len = struct_size(fw_hdr, sections, info->section_num); + if (base_hdr_len > len) { + rtw89_err(rtwdev, "[ERR]fw header truncated\n"); + return -EINVAL; + } + info->dynamic_hdr_en = le32_get_bits(fw_hdr->w7, FW_HDR_V1_W7_DYN_HDR); info->idmem_share_mode = le32_get_bits(fw_hdr->w7, FW_HDR_V1_W7_IDMEM_SHARE_MODE); From fc17fd87d9f210850f81e547ee88eba89d6f2d50 Mon Sep 17 00:00:00 2001 From: Gongwei Li Date: Wed, 26 Aug 2026 11:19:59 +0800 Subject: [PATCH 0067/2126] wifi: rtw89: coex: Fix wrong constant check of GPIO MUX signal In _fw_set_gpio(), the check for an invalid GPIO signal uses `sig == 0xff`. However, _get_gpiosig_for_ver() never returns 0xff. Both of its failure branches return BTC_DBG_NUM (defined as 32) when the requested signal is unsupported for the current firmware version. Check the result against BTC_DBG_NUM instead, the same as _show_gpio_dbg() already does. Fixes: 5c90259b9748 ("wifi: rtw89: coex: complete GPIO debug configuration handler") Signed-off-by: Gongwei Li Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260826031959.2555359-1-13875017792@163.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 84ae14f993e6..e49d75cc55a1 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -3365,7 +3365,7 @@ static void _fw_set_gpio(struct rtw89_dev *rtwdev, u8 type, u32 val) gpio->mux.data.dlen = CXDGPIO_SET_L2; gpio->mux.data.sig = _get_gpiosig_for_ver(rtwdev, FIELD_GET(GENMASK(7, 0), val)); - if (gpio->mux.data.sig == 0xff) + if (gpio->mux.data.sig >= BTC_DBG_NUM) return; gpio->mux.data.gpio = FIELD_GET(GENMASK(15, 8), val); l2_h2c = gpio->mux.fmt; From 37f018809909dfc99646b1b1f79c2b3968e7890a Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 20 Aug 2026 11:30:22 +0300 Subject: [PATCH 0068/2126] wifi: mm81x: fix type bugs handling sdio_readl/writel() The sdio_readl() and sdio_writel() functions, instead of returning kernel error codes, instead stores the error codes in a parameter. These caller functions pass should pass an int pointer to store the error code but instead pass a signed long. This will not work on big endian systems. On little endian systems passing a ssize_t means negative error codes are converted to positive values near UINT_MAX. This doesn't cause a problem at runtime because in mm81x_sdio_reg32_write() the error codes are discarded and we always return -EIO. In mm81x_sdio_reg32_read() the high bits are truncated away so the positive value is re-converted back to negative and the code works as intended. Either way, passing an int is the correct thing and is a cleanup. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Dan Carpenter Link: https://patch.msgid.link/aoa7Hj1W7ETOrOzO@stanley.mountain Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/sdio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/sdio.c b/drivers/net/wireless/morsemicro/mm81x/sdio.c index 96fce187dd35..65277399bf18 100644 --- a/drivers/net/wireless/morsemicro/mm81x/sdio.c +++ b/drivers/net/wireless/morsemicro/mm81x/sdio.c @@ -381,7 +381,7 @@ static int mm81x_sdio_dm_read(struct mm81x *mors, u32 address, u8 *data, static int mm81x_sdio_reg32_write(struct mm81x *mors, u32 address, u32 val) { - ssize_t ret = 0; + int ret = 0; u32 original_address = address; struct mm81x_sdio *sdio = (struct mm81x_sdio *)mors->drv_priv; struct sdio_func *func1 = sdio->func->card->sdio_func[0]; @@ -391,7 +391,7 @@ static int mm81x_sdio_reg32_write(struct mm81x *mors, u32 address, u32 val) address &= 0x0000FFFF; sdio_writel(func1, (__force u32)cpu_to_le32(val), - (__force u32)cpu_to_le32(address), (int *)&ret); + (__force u32)cpu_to_le32(address), &ret); if (ret) goto error; @@ -411,7 +411,7 @@ error: static int mm81x_sdio_reg32_read(struct mm81x *mors, u32 address, u32 *val) { u32 value; - ssize_t ret = 0; + int ret = 0; struct mm81x_sdio *sdio = (struct mm81x_sdio *)mors->drv_priv; struct sdio_func *func1 = sdio->func->card->sdio_func[0]; @@ -419,8 +419,7 @@ static int mm81x_sdio_reg32_read(struct mm81x *mors, u32 address, u32 *val) MM81X_CONFIG_ACCESS_4BYTE); address &= 0x0000FFFF; - value = sdio_readl(func1, (__force u32)cpu_to_le32(address), - (int *)&ret); + value = sdio_readl(func1, (__force u32)cpu_to_le32(address), &ret); if (ret) return ret; From 81510c3d6f2199889a4a936d8cf8b9e05911b10e Mon Sep 17 00:00:00 2001 From: Abdurrahman Karadag Date: Thu, 27 Aug 2026 16:12:44 +0300 Subject: [PATCH 0069/2126] wifi: rtw88: debugfs: don't vzalloc(0) when rsvd_page is read unconfigured Reading the rsvd_page debugfs entry before writing a page offset and count to it calls vzalloc() with a size of zero, because rsvd_page.page_num defaults to 0. vmalloc warns about this: WARNING: mm/vmalloc.c:4019 at __vmalloc_node_range_noprof+0x9ac/0xa30 ... Call Trace: __vmalloc_node_noprof+0x4c/0x70 rtw_debugfs_get_rsvd_page+0x4c/0x110 [rtw88_core] seq_read_iter+0x132/0x4b0 seq_read+0x12e/0x1c0 full_proxy_read+0x6f/0xc0 vfs_read+0xdd/0x490 rtw_fw_dump_fifo() would reject the zero size anyway, but only after the allocation. Check for a zero buffer size first and print a short usage hint instead of allocating. Fixes: e3037485c68e ("rtw88: new Realtek 802.11ac driver") Signed-off-by: Abdurrahman Karadag Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260827131244.35623-1-abdurrahmankaradag19@gmail.com --- drivers/net/wireless/realtek/rtw88/debug.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/debug.c b/drivers/net/wireless/realtek/rtw88/debug.c index b67d69b01f87..84e45af26f52 100644 --- a/drivers/net/wireless/realtek/rtw88/debug.c +++ b/drivers/net/wireless/realtek/rtw88/debug.c @@ -315,6 +315,11 @@ static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v) int i; int ret; + if (!buf_size) { + seq_puts(m, "usage: echo > rsvd_page\n"); + return 0; + } + buf = vzalloc(buf_size); if (!buf) return -ENOMEM; From d0ec95a8a4e79f2fd6063fc8932415db8c227689 Mon Sep 17 00:00:00 2001 From: Dexuan Cui Date: Fri, 28 Aug 2026 14:23:25 -0700 Subject: [PATCH 0070/2126] hv_netvsc: Advertise the SR-IOV capability for CoCo VMs This basically reverts the Feb 2021 change: commit 96854bbda24f ("hv_netvsc: Restrict configurations on isolated guests") In Feb 2021, PCI device assignment for CoCo VMs on Hyper-V was not supported: if the host offered a PCI VF NIC device to the VM, the VM couldn't handle it properly, so the 2021 commit was made to tell the host "I'm unable to handle SR-IOV NICs, so please don't offer a VF to me". If the host offers a VF NIC to the VM anyway, the change to netvsc_receive_inband() ignores the VF NIC. Since Mar 2023, the VM is able to support PCI device assignment due to commit 2c6ba4216844 ("PCI: hv: Enable PCI pass-thru devices in Confidential VMs") and related commits, so hv_netvsc can functionally work with a VF NIC, but we haven't advertised the SR-IOV capability because the MANA NIC driver (drivers/net/ethernet/microsoft/mana/) hadn't been hardened, so a malicious MANA NIC might be able to attack the VM. Recently, we have finished hardening the MANA driver, so we can safely use the MANA NIC in a CoCo VM now. Note: currently the MANA driver in a CoCo VM still uses bounce buffering (i.e. shared decrypted memory) for DMA. In the future, it will be able to use private encrypted memory for DMA with the help of TDISP. Now, advertises the SR-IOV capability for CoCo VMs. Note: for MANA to work properly for CoCo VMs, the following earlier commits are also required: commit 2e2a83b4998a ("net: mana: Validate the packet length reported by the NIC") commit c72a0f09c57f ("net: mana: Sync page pool RX frags for CPU") Note: the host might offer a VF NIC device that's not MANA -- in that case, if the corresponding VF NIC driver isn't hardened for CoCo VMs, the driver should be blacklisted in CoCo VMs. Signed-off-by: Dexuan Cui Reviewed-by: Haiyang Zhang Reviewed-by: Michael Kelley Signed-off-by: David S. Miller --- drivers/net/hyperv/netvsc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 5cd084e5696c..fc6548b16c91 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -625,10 +625,7 @@ static int negotiate_nvsp_ver(struct hv_device *device, init_packet->msg.v2_msg.send_ndis_config.capability.ieee8021q = 1; if (nvsp_ver >= NVSP_PROTOCOL_VERSION_5) { - if (hv_is_isolation_supported()) - netdev_info(ndev, "SR-IOV not advertised by guests on the host supporting isolation\n"); - else - init_packet->msg.v2_msg.send_ndis_config.capability.sriov = 1; + init_packet->msg.v2_msg.send_ndis_config.capability.sriov = 1; /* Teaming bit is needed to receive link speed updates */ init_packet->msg.v2_msg.send_ndis_config.capability.teaming = 1; @@ -1665,10 +1662,7 @@ static void netvsc_receive_inband(struct net_device *ndev, break; case NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION: - if (hv_is_isolation_supported()) - netdev_err(ndev, "Ignore VF_ASSOCIATION msg from the host supporting isolation\n"); - else - netvsc_send_vf(ndev, nvmsg, msglen); + netvsc_send_vf(ndev, nvmsg, msglen); break; } } From 87230a514d2ca128c3fcd96126bb18162459640f Mon Sep 17 00:00:00 2001 From: Linmao Li Date: Wed, 12 Aug 2026 14:07:37 +0800 Subject: [PATCH 0071/2126] wifi: mm81x: free the firmware scratch buffer on parse failures mm81x_fw_load_fw() allocates fw_buf before it inspects the image, but releases it only on the success path. The two early returns taken for a malformed image leave one firmware-sized allocation attached to the device, and mm81x_fw_flash() retries the load three times. Release it on those paths too, the way mm81x_fw_load_bcf() already does. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Linmao Li Link: https://patch.msgid.link/20260812060740.1275280-2-lilinmao@kylinos.cn Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/fw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/fw.c b/drivers/net/wireless/morsemicro/mm81x/fw.c index d6d2ad086c32..d407b57f4c9c 100644 --- a/drivers/net/wireless/morsemicro/mm81x/fw.c +++ b/drivers/net/wireless/morsemicro/mm81x/fw.c @@ -117,13 +117,15 @@ static int mm81x_fw_load_fw(struct mm81x *mors, const struct firmware *fw) if (mm81x_fw_get_header(fw->data, &ehdr)) { dev_err(mors->dev, "Wrong file format"); - return -EINVAL; + ret = -EINVAL; + goto out_free; } if (mm81x_fw_get_section_header(fw->data, &ehdr, &sh_strtab, ehdr.e_shstrndx)) { dev_err(mors->dev, "Invalid firmware. Missing string table"); - return -ENOENT; + ret = -ENOENT; + goto out_free; } sh_strs = (const char *)fw->data + sh_strtab.sh_offset; @@ -179,6 +181,7 @@ static int mm81x_fw_load_fw(struct mm81x *mors, const struct firmware *fw) if (ehdr.e_entry) ret = mm81x_fw_set_boot_addr(mors, ehdr.e_entry); +out_free: devm_kfree(mors->dev, fw_buf); return ret; } From dc1936211335eca00acca53d058dc94fbab02028 Mon Sep 17 00:00:00 2001 From: Linmao Li Date: Wed, 12 Aug 2026 14:07:38 +0800 Subject: [PATCH 0072/2126] wifi: mm81x: do not discard a failed firmware segment write When mm81x_dm_write() fails while downloading a PT_LOAD segment, mm81x_fw_load_fw() sets ret to -EIO and breaks out of the loop. The boot address write at the end of the function then overwrites ret, so a partially downloaded image is reported as loaded and the chip is triggered on it instead of the load being retried. Leave the function as soon as a segment fails. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Linmao Li Link: https://patch.msgid.link/20260812060740.1275280-3-lilinmao@kylinos.cn Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/fw.c b/drivers/net/wireless/morsemicro/mm81x/fw.c index d407b57f4c9c..a2cb97cefc4e 100644 --- a/drivers/net/wireless/morsemicro/mm81x/fw.c +++ b/drivers/net/wireless/morsemicro/mm81x/fw.c @@ -162,7 +162,7 @@ static int mm81x_fw_load_fw(struct mm81x *mors, const struct firmware *fw) mm81x_release_bus(mors); if (status) { ret = -EIO; - break; + goto out_free; } } } From e14761563588281909beaef0a4b5d1b735c7404c Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Mon, 31 Aug 2026 09:50:59 +0800 Subject: [PATCH 0073/2126] bonding: convert unbalanced_load to per-cpu state A later patch widens the bonding TLB tx counters from u32 to u64. The unbalanced_load counter sits in the transmit hot path, and cross-CPU synchronization of a u64 would introduce measurable overhead. Convert unbalanced_load to a per-cpu counter first so that the subsequent widening only touches per-cpu data local to each CPU. Introduce struct unbalanced_load_stats to hold the per-cpu counter, and move the aggregation into a helper, reset_unbalanced_load(), which sums all per-cpu instances. Use the delta of current total load vs variable prev_total_unbalanced to calculate the loading. Reviewed-by: Nikolay Aleksandrov Signed-off-by: Hangbin Liu Acked-by: Jay Vosburgh Link: https://patch.msgid.link/20260831-bond_overflow-v6-1-ffb0ed1f7268@kylinos.cn Signed-off-by: Jakub Kicinski --- drivers/net/bonding/bond_alb.c | 37 +++++++++++++++++++++++++++------- include/net/bond_alb.h | 7 ++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 839f7482dc18..0afed2c39231 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c @@ -133,6 +133,10 @@ static int tlb_initialize(struct bonding *bond) if (!new_hashtbl) return -ENOMEM; + bond_info->unbalanced_load = alloc_percpu(struct unbalanced_load_stats); + if (!bond_info->unbalanced_load) + goto out; + spin_lock_bh(&bond->mode_lock); bond_info->tx_hashtbl = new_hashtbl; @@ -143,6 +147,10 @@ static int tlb_initialize(struct bonding *bond) spin_unlock_bh(&bond->mode_lock); return 0; + +out: + kfree(new_hashtbl); + return -ENOMEM; } /* Must be called only after all slaves have been released */ @@ -154,6 +162,8 @@ static void tlb_deinitialize(struct bonding *bond) kfree(bond_info->tx_hashtbl); bond_info->tx_hashtbl = NULL; + free_percpu(bond_info->unbalanced_load); + bond_info->prev_total_unbalanced = 0; spin_unlock_bh(&bond->mode_lock); } @@ -1345,7 +1355,7 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond, /* unbalanced or unassigned, send through primary */ tx_slave = rcu_dereference(bond->curr_active_slave); if (bond->params.tlb_dynamic_lb) - bond_info->unbalanced_load += skb->len; + this_cpu_add(bond_info->unbalanced_load->tx_bytes, skb->len); } if (tx_slave && bond_slave_can_tx(tx_slave)) { @@ -1529,6 +1539,23 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) return bond_do_alb_xmit(skb, bond, tx_slave); } +static u32 reset_unbalanced_load(struct alb_bond_info *bond_info) +{ + struct unbalanced_load_stats *p; + u32 delta, total_bytes = 0; + int i; + + for_each_possible_cpu(i) { + p = per_cpu_ptr(bond_info->unbalanced_load, i); + total_bytes += READ_ONCE(p->tx_bytes); + } + + delta = total_bytes - bond_info->prev_total_unbalanced; + bond_info->prev_total_unbalanced = total_bytes; + + return delta / BOND_TLB_REBALANCE_INTERVAL; +} + void bond_alb_monitor(struct work_struct *work) { struct bonding *bond = container_of(work, struct bonding, @@ -1570,12 +1597,8 @@ void bond_alb_monitor(struct work_struct *work) if (atomic_read(&bond_info->tx_rebalance_counter) >= BOND_TLB_REBALANCE_TICKS) { bond_for_each_slave_rcu(bond, slave, iter) { tlb_clear_slave(bond, slave, 1); - if (slave == rcu_access_pointer(bond->curr_active_slave)) { - SLAVE_TLB_INFO(slave).load = - bond_info->unbalanced_load / - BOND_TLB_REBALANCE_INTERVAL; - bond_info->unbalanced_load = 0; - } + if (slave == rcu_access_pointer(bond->curr_active_slave)) + SLAVE_TLB_INFO(slave).load = reset_unbalanced_load(bond_info); } atomic_set(&bond_info->tx_rebalance_counter, 0); } diff --git a/include/net/bond_alb.h b/include/net/bond_alb.h index e5945427f38d..6fb09b4fc7e2 100644 --- a/include/net/bond_alb.h +++ b/include/net/bond_alb.h @@ -123,9 +123,14 @@ struct tlb_slave_info { */ }; +struct unbalanced_load_stats { + u32 tx_bytes; +}; + struct alb_bond_info { struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */ - u32 unbalanced_load; + struct unbalanced_load_stats __percpu *unbalanced_load; + u32 prev_total_unbalanced; atomic_t tx_rebalance_counter; int lp_counter; /* -------- rlb parameters -------- */ From 4cef95f72bbd0d5edb232143751251717efb5928 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Mon, 31 Aug 2026 09:51:00 +0800 Subject: [PATCH 0074/2126] bonding: fix u32 overflow in compute_gap() The TLB load-tracking fields tx_bytes, load_history, load, and unbalanced_load are all u32. At sustained throughput above ~3.2 Gbit/s over the 10-second rebalance interval the byte counters wrap, causing compute_gap() to produce incorrect gap values and mis-select slaves. Such speeds are common on modern NICs under heavy traffic. Widen these fields to u64. Use u64_stats_sync to protect the per-cpu unbalanced_load_stats against tearing on 32-bit architectures, and div_u64() for the 64-bit divisions. The tx_bytes and load_history are protected in spin_lock. Also protect the slave load writing in bond_alb_monitor() with spin_lock in case of tear on 32-bit. For compute_gap(), we still use s64 arithmetic throughout, so we can preserve the existing calculation logic. This order of magnitude is sufficiently large, there is no need to worry about overflow for now. Detected by AI code review. Cc: stable+noautosel@kernel.org # never worked Reviewed-by: Nikolay Aleksandrov Signed-off-by: Hangbin Liu Acked-by: Jay Vosburgh Link: https://patch.msgid.link/20260831-bond_overflow-v6-2-ffb0ed1f7268@kylinos.cn Signed-off-by: Jakub Kicinski --- drivers/net/bonding/bond_alb.c | 46 ++++++++++++++++++++++++---------- include/net/bond_alb.h | 11 ++++---- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 0afed2c39231..bbe9a6985f90 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -74,8 +75,8 @@ static inline u8 _simple_hash(const u8 *hash_start, int hash_size) static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load) { if (save_load) { - entry->load_history = 1 + entry->tx_bytes / - BOND_TLB_REBALANCE_INTERVAL; + entry->load_history = 1 + div_u64(entry->tx_bytes, + BOND_TLB_REBALANCE_INTERVAL); entry->tx_bytes = 0; } @@ -133,7 +134,7 @@ static int tlb_initialize(struct bonding *bond) if (!new_hashtbl) return -ENOMEM; - bond_info->unbalanced_load = alloc_percpu(struct unbalanced_load_stats); + bond_info->unbalanced_load = netdev_alloc_pcpu_stats(struct unbalanced_load_stats); if (!bond_info->unbalanced_load) goto out; @@ -170,8 +171,10 @@ static void tlb_deinitialize(struct bonding *bond) static long long compute_gap(struct slave *slave) { - return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */ - (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */ + u32 raw_speed = READ_ONCE(slave->speed); + + return ((s64)raw_speed << 20) - /* Convert to bits per sec */ + ((s64)SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */ } static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) @@ -1354,8 +1357,14 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond, if (!tx_slave) { /* unbalanced or unassigned, send through primary */ tx_slave = rcu_dereference(bond->curr_active_slave); - if (bond->params.tlb_dynamic_lb) - this_cpu_add(bond_info->unbalanced_load->tx_bytes, skb->len); + if (bond->params.tlb_dynamic_lb) { + struct unbalanced_load_stats *pcpu_load; + + pcpu_load = this_cpu_ptr(bond_info->unbalanced_load); + u64_stats_update_begin(&pcpu_load->syncp); + u64_stats_add(&pcpu_load->tx_bytes, skb->len); + u64_stats_update_end(&pcpu_load->syncp); + } } if (tx_slave && bond_slave_can_tx(tx_slave)) { @@ -1539,21 +1548,27 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) return bond_do_alb_xmit(skb, bond, tx_slave); } -static u32 reset_unbalanced_load(struct alb_bond_info *bond_info) +static u64 reset_unbalanced_load(struct alb_bond_info *bond_info) { + u64 delta, tx_bytes, total_bytes = 0; struct unbalanced_load_stats *p; - u32 delta, total_bytes = 0; + unsigned int start; int i; for_each_possible_cpu(i) { p = per_cpu_ptr(bond_info->unbalanced_load, i); - total_bytes += READ_ONCE(p->tx_bytes); + do { + start = u64_stats_fetch_begin(&p->syncp); + tx_bytes = u64_stats_read(&p->tx_bytes); + } while (u64_stats_fetch_retry(&p->syncp, start)); + + total_bytes += tx_bytes; } delta = total_bytes - bond_info->prev_total_unbalanced; bond_info->prev_total_unbalanced = total_bytes; - return delta / BOND_TLB_REBALANCE_INTERVAL; + return div_u64(delta, BOND_TLB_REBALANCE_INTERVAL); } void bond_alb_monitor(struct work_struct *work) @@ -1597,8 +1612,13 @@ void bond_alb_monitor(struct work_struct *work) if (atomic_read(&bond_info->tx_rebalance_counter) >= BOND_TLB_REBALANCE_TICKS) { bond_for_each_slave_rcu(bond, slave, iter) { tlb_clear_slave(bond, slave, 1); - if (slave == rcu_access_pointer(bond->curr_active_slave)) - SLAVE_TLB_INFO(slave).load = reset_unbalanced_load(bond_info); + if (slave == rcu_access_pointer(bond->curr_active_slave)) { + u64 new_load = reset_unbalanced_load(bond_info); + + spin_lock_bh(&bond->mode_lock); + SLAVE_TLB_INFO(slave).load = new_load; + spin_unlock_bh(&bond->mode_lock); + } } atomic_set(&bond_info->tx_rebalance_counter, 0); } diff --git a/include/net/bond_alb.h b/include/net/bond_alb.h index 6fb09b4fc7e2..32f1981033e4 100644 --- a/include/net/bond_alb.h +++ b/include/net/bond_alb.h @@ -57,12 +57,12 @@ struct tlb_client_info { * packets to a Client that the Hash function * gave this entry index. */ - u32 tx_bytes; /* Each Client accumulates the BytesTx that + u64 tx_bytes; /* Each Client accumulates the BytesTx that * were transmitted to it, and after each * CallBack the LoadHistory is divided * by the balance interval */ - u32 load_history; /* This field contains the amount of Bytes + u64 load_history; /* This field contains the amount of Bytes * that were transmitted to this client by * the server on the previous balance * interval in Bps. @@ -118,19 +118,20 @@ struct tlb_slave_info { * are the entries that were assigned to use this * slave for transmit. */ - u32 load; /* Each slave sums the loadHistory of all clients + u64 load; /* Each slave sums the loadHistory of all clients * assigned to it */ }; struct unbalanced_load_stats { - u32 tx_bytes; + u64_stats_t tx_bytes; + struct u64_stats_sync syncp; }; struct alb_bond_info { struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */ struct unbalanced_load_stats __percpu *unbalanced_load; - u32 prev_total_unbalanced; + u64 prev_total_unbalanced; atomic_t tx_rebalance_counter; int lp_counter; /* -------- rlb parameters -------- */ From 4187c29c2abdd2144f5bcf5936c7f997d1fdef66 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 31 Aug 2026 15:41:29 +0000 Subject: [PATCH 0075/2126] net: optimize netif_is_l3_master() and netif_is_l3_slave() IFF_L3MDEV_MASTER and IFF_L3MDEV_SLAVE flags are only set and used by the VRF driver (CONFIG_NET_VRF). netif_is_l3_master() and netif_is_l3_slave() are called in multiple performance-critical fast paths (such as GRO, IP routing/FIB lookups, TCP/UDP processing, etc.). When CONFIG_NET_VRF is disabled, neither flag can ever be set on any net_device. Adding IS_ENABLED(CONFIG_NET_VRF) allows the compiler to optimize these checks away as false at compile time, eliminating unnecessary conditional branches in the fast path when VRF is not enabled. scripts/bloat-o-meter shows a nice code size reduction on a kernel built with CONFIG_NET_VRF=n (and CONFIG_NET_L3_MASTER_DEV=y): add/remove: 2/5 grow/shrink: 18/71 up/down: 1593/-5642 (-4049) Function old new delta ipip6_tunnel_lookup.constprop - 931 +931 tcp_v6_parse_md5_keys 1607 1742 +135 ipip6_err 617 738 +121 bpf_lwt_xmit_reroute 1492 1555 +63 ip6_pol_route 1810 1843 +33 rt6_multipath_rebalance.part 1448 1480 +32 bpf_msg_pull_data 1255 1287 +32 __unlikely_text_end 3092 3124 +32 ipv6_add_addr 2257 2287 +30 __ip4_datagram_connect 1131 1158 +27 ip6_rt_cache_alloc 476 500 +24 fib6_clean_tohost 308 328 +20 sit_exit_rtnl_net 461 477 +16 nf_nat_register_fn 581 597 +16 ip6_forward 4573 4589 +16 inet_rtm_getroute 2906 2922 +16 __pfx_ipip6_tunnel_lookup.constprop - 16 +16 __ip_do_redirect 2005 2021 +16 __bpf_skc_lookup 449 464 +15 addrconf_add_dev 134 136 +2 ip6_rcv_finish 203 201 -2 icmp6_dev 159 153 -6 ipip6_tunnel_bind_dev 419 409 -10 bpf_xdp_skc_lookup_tcp 122 107 -15 bpf_tc_skc_lookup_tcp 125 110 -15 rt6_nh_dump_exceptions 243 227 -16 ip_mc_source 1385 1369 -16 ip6_fragment 2450 2434 -16 input_action_end_x 278 262 -16 fib6_nh_age_exceptions.part 822 806 -16 __pfx_ipip6_tunnel_lookup 16 - -16 __pfx_ip6_rt_get_dev_rcu 16 - -16 __addrconf_sysctl_register 365 349 -16 bpf_xdp_sk_lookup_udp 155 138 -17 bpf_xdp_sk_lookup_tcp 155 138 -17 bpf_tc_sk_lookup_udp 158 141 -17 bpf_tc_sk_lookup_tcp 158 141 -17 addrconf_addr_gen 339 322 -17 ip6_rcv_core 2084 2066 -18 fib_nl2rule_locked 517 499 -18 l3mdev_master_upper_ifindex_by_index_rcu 61 42 -19 ipip6_rcv 1960 1941 -19 addrconf_notify 2563 2543 -20 l3mdev_fib_table_by_index 304 282 -22 nf_nat_inet_fn 777 754 -23 attach_rules 176 150 -26 ipv6_rcv 867 840 -27 ip_sublist_rcv 1342 1315 -27 ip6_sublist_rcv 1528 1501 -27 sit_tunnel_rcv 498 470 -28 ndisc_send_redirect 1474 1445 -29 ip_mr_input 1175 1143 -32 ip6_mr_input 627 595 -32 tcp_ao_add_cmd.cold 33 - -33 ip_error 1059 1023 -36 raw_sendmsg 5291 5253 -38 end_dt_vrf_core 466 426 -40 ip_rcv 886 844 -42 ip_send_unicast_reply 1487 1443 -44 udp_sendmsg 4135 4089 -46 delete_tempaddrs 259 211 -48 udp6_gro_receive 1142 1092 -50 udp4_lib_lookup_skb 259 208 -51 l3mdev_fib_rule_match 337 286 -51 ping_v4_sendmsg 2692 2640 -52 tcp6_check_fraglist_gro 341 288 -53 l3mdev_master_ifindex_rcu 69 16 -53 ip6_dst_lookup_tail.constprop 1533 1480 -53 udp4_gro_receive 1139 1085 -54 igmp_rcv 3215 3160 -55 ndisc_recv_ns 1699 1642 -57 fib_netdev_event 771 714 -57 l3mdev_link_scope_lookup 124 65 -59 udp6_lib_lookup_skb 173 113 -60 __ip_local_out 1182 1120 -62 ipv6_frag_rcv 3670 3601 -69 ip_route_output_key_hash_rcu 3024 2951 -73 __ip6_local_out 1164 1091 -73 tcp_v6_send_response 3056 2982 -74 rt6_fill_node 4103 4027 -76 rawv6_sendmsg 6225 6149 -76 l3mdev_fib_table_rcu 92 16 -76 tcp4_gro_receive 1375 1295 -80 ip6_xmit 2771 2690 -81 fib_select_path 2190 2105 -85 tcp_v4_parse_md5_keys 1160 1058 -102 ip_route_input_slow 4471 4354 -117 ip6_pkt_drop.isra 572 453 -119 l3mdev_update_flow 516 360 -156 ip6_rt_get_dev_rcu 182 - -182 __ipv6_chk_addr_and_flags 750 568 -182 ip_route_input_rcu.part 941 743 -198 nf_confirm 1222 960 -262 ipv6_dev_get_saddr 1321 918 -403 tcp_ao_add_cmd 2643 2211 -432 ipip6_tunnel_lookup 1004 - -1004 Total: Before=33195512, After=33191463, chg -0.01% Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260831154129.4048178-1-edumazet@google.com Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 87cafc932e9e..8454646d6a45 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5606,12 +5606,12 @@ static inline bool netif_has_l3_rx_handler(const struct net_device *dev) static inline bool netif_is_l3_master(const struct net_device *dev) { - return dev->priv_flags & IFF_L3MDEV_MASTER; + return IS_ENABLED(CONFIG_NET_VRF) && (dev->priv_flags & IFF_L3MDEV_MASTER); } static inline bool netif_is_l3_slave(const struct net_device *dev) { - return dev->priv_flags & IFF_L3MDEV_SLAVE; + return IS_ENABLED(CONFIG_NET_VRF) && (dev->priv_flags & IFF_L3MDEV_SLAVE); } static inline int dev_sdif(const struct net_device *dev) From f4d02541872152b5248e84864e72e863902aa495 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Mon, 31 Aug 2026 14:36:35 +0200 Subject: [PATCH 0076/2126] dt-bindings: net: dsa: realtek: add RTL8365MB power supplies Document the RTL8365MB power rails as optional supplies. They are optional because the rails are often always-on; some designs break them out for granular hwmon monitoring and regulator control. They are scoped to realtek,rtl8365mb: different Realtek switch families use different power-rail naming schemes, so these rails do not apply to other families such as realtek,rtl8366rb (VDDA/VDD_CORE/VDDIO/...). Signed-off-by: Oleksij Rempel Reviewed-by: Linus Walleij Reviewed-by: Luiz Angelo Daros de Luca Acked-by: Conor Dooley Link: https://patch.msgid.link/20260831123637.666457-2-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski --- .../devicetree/bindings/net/dsa/realtek.yaml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/realtek.yaml b/Documentation/devicetree/bindings/net/dsa/realtek.yaml index 473facd87a62..b7bb60af623c 100644 --- a/Documentation/devicetree/bindings/net/dsa/realtek.yaml +++ b/Documentation/devicetree/bindings/net/dsa/realtek.yaml @@ -8,6 +8,20 @@ title: Realtek switches for unmanaged switches allOf: - $ref: dsa.yaml#/$defs/ethernet-ports + - if: + not: + properties: + compatible: + contains: + const: realtek,rtl8365mb + then: + properties: + avddh-supply: false + avddl-supply: false + dvddio-supply: false + dvddio1-supply: false + dvddl-supply: false + pllvddl-supply: false maintainers: - Linus Walleij @@ -62,6 +76,24 @@ properties: resets: maxItems: 1 + avddh-supply: + description: AVDDH high-voltage analog supply. + + avddl-supply: + description: AVDDL low-voltage analog supply. + + dvddio-supply: + description: DVDDIO digital I/O supply. + + dvddio1-supply: + description: DVDDIO_1 secondary digital I/O supply for the RGMII bank. + + dvddl-supply: + description: DVDDL digital core supply. + + pllvddl-supply: + description: PLLVDDL PLL analog supply. + realtek,disable-leds: type: boolean description: | @@ -243,6 +275,7 @@ examples: platform { ethernet-switch { compatible = "realtek,rtl8365mb"; + avddh-supply = <&avddh>; mdc-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>; mdio-gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>; reset-gpios = <&gpio5 0 GPIO_ACTIVE_LOW>; From f82364499682159e369e453922fd25d27c3a833f Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 31 Aug 2026 14:36:36 +0200 Subject: [PATCH 0077/2126] net: dsa: realtek: rtl83xx: add support for enabling supplies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The power supplies powering the IC may not necessarily be enabled by the time the driver probes. The binding describes the power rails, so enable them at probe with devm_regulator_bulk_get_enable(), before the reset line is requested and driven, so the chip is powered before its pins are driven. Boards that do not describe these supplies fall back to dummy regulators (with a "supply not found" warning) and keep working as before. A board that describes supplies but no reset line still needs to wait for the chip to boot before the first register access, so apply the existing start delay in that case too. Signed-off-by: Alvin Šipraga Signed-off-by: Ahmad Fatoum Co-developed-by: Oleksij Rempel Signed-off-by: Oleksij Rempel Reviewed-by: Linus Walleij Reviewed-by: Luiz Angelo Daros de Luca Link: https://patch.msgid.link/20260831123637.666457-3-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/realtek.h | 3 +++ drivers/net/dsa/realtek/rtl8365mb_main.c | 6 ++++++ drivers/net/dsa/realtek/rtl83xx.c | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 6e0148cee8d8..75a127545e5d 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -166,6 +166,9 @@ struct realtek_variant { u8 cmd_read; u8 cmd_write; size_t chip_data_sz; + /* Regulator supplies to enable at probe, or NULL */ + const char *const *supplies; + int num_supplies; }; /* RTL8366 library helpers */ diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 728231d8f94c..4c305756116c 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -3334,6 +3334,10 @@ static const struct realtek_ops rtl8365mb_ops = { .phy_write = rtl8365mb_phy_write, }; +static const char *const rtl8365mb_supplies[] = { + "avddh", "avddl", "dvddio", "dvddio1", "dvddl", "pllvddl", +}; + const struct realtek_variant rtl8365mb_variant = { .ds_ops = &rtl8365mb_switch_ops, .ops = &rtl8365mb_ops, @@ -3342,6 +3346,8 @@ const struct realtek_variant rtl8365mb_variant = { .cmd_read = 0xb9, .cmd_write = 0xb8, .chip_data_sz = sizeof(struct rtl8365mb), + .supplies = rtl8365mb_supplies, + .num_supplies = ARRAY_SIZE(rtl8365mb_supplies), }; static const struct of_device_id rtl8365mb_of_match[] = { diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index a96beea72ef5..d6d243131fd2 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -195,7 +196,16 @@ rtl83xx_probe(struct device *dev, priv->leds_disabled = of_property_read_bool(dev->of_node, "realtek,disable-leds"); - /* TODO: if power is software controlled, set up any regulators here */ + /* Enable the supplies before the reset line is requested and driven, + * so the chip is powered before its pins are driven. + */ + if (var->num_supplies) { + ret = devm_regulator_bulk_get_enable(dev, var->num_supplies, + var->supplies); + if (ret) + return dev_err_ptr_probe(dev, ret, "failed to enable supplies\n"); + } + priv->reset_ctl = devm_reset_control_get_optional(dev, NULL); if (IS_ERR(priv->reset_ctl)) return dev_err_cast_probe(dev, priv->reset_ctl, @@ -216,6 +226,11 @@ rtl83xx_probe(struct device *dev, rtl83xx_reset_deassert(priv); msleep(REALTEK_HW_START_DELAY); dev_dbg(dev, "deasserted RESET\n"); + } else if (var->num_supplies) { + /* Powered but no reset line: still wait for the chip to boot + * before the first register access. + */ + msleep(REALTEK_HW_START_DELAY); } return priv; From bd6b764f08deb2356f95d026c3143d5e19280496 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Mon, 31 Aug 2026 14:36:37 +0200 Subject: [PATCH 0078/2126] net: dsa: realtek: rtl83xx: use dev_err_cast_probe() for reset GPIO Replace the open-coded dev_err() + ERR_CAST() on the reset GPIO error path with dev_err_cast_probe(), matching the reset controller above and staying quiet on -EPROBE_DEFER. Signed-off-by: Oleksij Rempel Reviewed-by: Luiz Angelo Daros de Luca Link: https://patch.msgid.link/20260831123637.666457-4-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/rtl83xx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index d6d243131fd2..8121ec12fd8b 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -212,10 +212,8 @@ rtl83xx_probe(struct device *dev, "failed to get reset control\n"); priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(priv->reset)) { - dev_err(dev, "failed to get RESET GPIO\n"); - return ERR_CAST(priv->reset); - } + if (IS_ERR(priv->reset)) + return dev_err_cast_probe(dev, priv->reset, "failed to get RESET GPIO\n"); dev_set_drvdata(dev, priv); From 577b53589d420609e126fb710f23360d8ae96a3b Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Tue, 1 Sep 2026 08:12:56 +0200 Subject: [PATCH 0079/2126] dt-bindings: net: fsl,fman-dtsec: Drop redundant pcs-handle-names dependency The binding references ethernet-controller.yaml schema, which already defines a dependency of pcs-handle-names on pcs-handle, thus duplicating it here is redundant. Signed-off-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260901061255.25734-2-krzysztof.kozlowski@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml b/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml index ef1e30a48c91..5dcb49f2f3b1 100644 --- a/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml +++ b/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml @@ -125,10 +125,6 @@ required: - reg - fsl,fman-ports -dependencies: - pcs-handle-names: - - pcs-handle - allOf: - $ref: ethernet-controller.yaml# - if: From 889b0cca6b29df5bb92507745000e783cc46bf5d Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 1 Sep 2026 13:07:26 -0700 Subject: [PATCH 0080/2126] selftests: drv-net: hw: rename gro_hw.py to gro_stats.py We need to free up the gro_hw.py name for the HW-GRO half of gro.py, which we need to split by mode (sw / hw / lro). The file checks mostly qstat counters, so name it after stats. Reviewed-by: Joe Damato Reviewed-by: Nimrod Oren Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260901200728.2063720-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hw/Makefile | 2 +- .../selftests/drivers/net/hw/{gro_hw.py => gro_stats.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tools/testing/selftests/drivers/net/hw/{gro_hw.py => gro_stats.py} (100%) diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 78bb0169350b..6105be8e590f 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -27,7 +27,7 @@ TEST_PROGS = \ ethtool_mm.sh \ ethtool_rmon.sh \ ethtool_std_stats.sh \ - gro_hw.py \ + gro_stats.py \ hw_stats_l3.sh \ hw_stats_l3_gre.sh \ iou-zcrx.py \ diff --git a/tools/testing/selftests/drivers/net/hw/gro_hw.py b/tools/testing/selftests/drivers/net/hw/gro_stats.py similarity index 100% rename from tools/testing/selftests/drivers/net/hw/gro_hw.py rename to tools/testing/selftests/drivers/net/hw/gro_stats.py From f225a7317c18f2009fb4cdcc75337c726b6dda88 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 1 Sep 2026 13:07:27 -0700 Subject: [PATCH 0081/2126] selftests: drv-net: split gro.py into one test per coalescing mode gro.py runs its full set of cases three times over - against SW GRO, HW GRO and LRO. It's our test with the longest runtime. The 318 cases take 12m30s on mlx5 with a debug kernel. Bumping the timeout for all tests feels wrong when we can so easily split the GRO test by execution mode. Shorter runtime also helps retry just the failing portion / mode (we retry failing tests to try to detect flakes vs real failures). Move the main logic to gro_lib.py and add one program per mode - gro_sw.py, gro_hw.py and gro_lro.py, 102 cases each. Move PPPoE to a dedicated test. It has been tacked onto the tests in an ugly way, and it only runs against SW GRO anyway. Note that unfortunately this will case a rename of all test cases. The mode moves from the case name to the test name gro.py test.sw_ipv4_data_same becomes gro_sw.py test.ipv4_data_same Reviewed-by: Joe Damato Reviewed-by: Nimrod Oren Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260901200728.2063720-3-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/Makefile | 9 ++- tools/testing/selftests/drivers/net/gro_hw.py | 13 ++++ .../drivers/net/{gro.py => gro_lib.py} | 68 +++++++++---------- .../testing/selftests/drivers/net/gro_lro.py | 14 ++++ tools/testing/selftests/drivers/net/gro_sw.py | 13 ++++ .../selftests/drivers/net/pppoe_gro.py | 45 ++++++++++++ .../selftests/net/lib/ksft_setup_loopback.sh | 2 +- 7 files changed, 125 insertions(+), 39 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/gro_hw.py rename tools/testing/selftests/drivers/net/{gro.py => gro_lib.py} (92%) mode change 100755 => 100644 create mode 100755 tools/testing/selftests/drivers/net/gro_lro.py create mode 100755 tools/testing/selftests/drivers/net/gro_sw.py create mode 100755 tools/testing/selftests/drivers/net/pppoe_gro.py diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index d5bf4cb638a8..1f21e17d8c22 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -11,13 +11,16 @@ TEST_GEN_FILES := \ # end of TEST_GEN_FILES TEST_PROGS := \ - gro.py \ + gro_hw.py \ + gro_lro.py \ + gro_sw.py \ hds.py \ macsec.py \ napi_id.py \ napi_threaded.py \ netpoll_basic.py \ ping.py \ + pppoe_gro.py \ psp.py \ queues.py \ ring_reconfig.py \ @@ -27,6 +30,10 @@ TEST_PROGS := \ xdp.py \ # end of TEST_PROGS +TEST_FILES := \ + gro_lib.py \ +# end of TEST_FILES + # YNL files, must be before "include ..lib.mk" YNL_GEN_FILES := psp_responder TEST_GEN_FILES += $(YNL_GEN_FILES) diff --git a/tools/testing/selftests/drivers/net/gro_hw.py b/tools/testing/selftests/drivers/net/gro_hw.py new file mode 100755 index 000000000000..06b980220835 --- /dev/null +++ b/tools/testing/selftests/drivers/net/gro_hw.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +GRO conformance tests against the HW GRO implementation (rx-gro-hw). + +See gro_lib.py for the list of test cases. +""" + +from gro_lib import gro_main + +if __name__ == "__main__": + gro_main(__file__, "hw") diff --git a/tools/testing/selftests/drivers/net/gro.py b/tools/testing/selftests/drivers/net/gro_lib.py old mode 100755 new mode 100644 similarity index 92% rename from tools/testing/selftests/drivers/net/gro.py rename to tools/testing/selftests/drivers/net/gro_lib.py index 6ab8c97880d1..45ded8477a50 --- a/tools/testing/selftests/drivers/net/gro.py +++ b/tools/testing/selftests/drivers/net/gro_lib.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 """ @@ -8,6 +7,13 @@ Validates that GRO coalescing works correctly by running the gro binary in different configurations and checking for correct packet coalescing behavior. +The same test cases are run against all three coalescing implementations, +one mode per test program, because a full sweep takes too long to fit in +a single test's timeout: + - gro_sw.py: SW GRO (generic-receive-offload) + - gro_hw.py: HW GRO (rx-gro-hw) + - gro_lro.py: LRO (large-receive-offload) + Test cases: - data_same: Same size data packets coalesce - data_lrg_sml: Large packet followed by smaller one coalesces @@ -323,32 +329,19 @@ def _gro_variants(): "ip_frag6", "ip_v6ext_same", "ip_v6ext_diff", ] - # Tests specific to PPPoE - pppoe_tests = [ - "data_same", "data_lrg_sml", "data_sml_lrg", "data_lrg_1byte", - "data_burst", "pppoe_sid", - ] + for protocol in ["ipv4", "ipv6", "ipip", "ip6ip6"]: + for test_name in common_tests: + yield protocol, test_name - for mode in ["sw", "hw", "lro"]: - for protocol in ["ipv4", "ipv6", "ipip", "ip6ip6"]: - for test_name in common_tests: - yield mode, protocol, test_name - - if protocol in ["ipv4", "ipip"]: - for test_name in ipv4_tests: - yield mode, protocol, test_name - elif protocol == "ipv6": - for test_name in ipv6_tests: - yield mode, protocol, test_name - - for mode in ["sw"]: - for protocol in ["pppoev4", "pppoev6"]: - for test_name in pppoe_tests: - yield mode, protocol, test_name + if protocol in ["ipv4", "ipip"]: + for test_name in ipv4_tests: + yield protocol, test_name + elif protocol == "ipv6": + for test_name in ipv6_tests: + yield protocol, test_name -@ksft_variants(_gro_variants()) -def test(cfg, mode, protocol, test_name): +def run_test(cfg, mode, protocol, test_name): """Run a single GRO test with retries.""" ipver = "6" if protocol[-1] == "6" else "4" @@ -383,16 +376,21 @@ def test(cfg, mode, protocol, test_name): ksft_pr(f"Attempt {attempt + 1}/{max_retries} failed, retrying...") +@ksft_variants(_gro_variants()) +def test(cfg, mode, protocol, test_name): + """Run a single GRO test case.""" + run_test(cfg, mode, protocol, test_name) + + def _capacity_variants(): - """Generate variants for capacity test: mode x queue setup.""" + """Generate variants for capacity test: queue setup.""" setups = [ ("isolated", _setup_isolated_queue), ("1q", lambda cfg: _setup_queue_count(cfg, 1)), ("8q", lambda cfg: _setup_queue_count(cfg, 8)), ] - for mode in ["sw", "hw", "lro"]: - for name, func in setups: - yield KsftNamedVariant(f"{mode}_{name}", mode, func) + for name, func in setups: + yield KsftNamedVariant(name, func) @ksft_variants(_capacity_variants()) @@ -403,7 +401,7 @@ def test_gro_capacity(cfg, mode, setup_func): Start with 8 flows and increase by 2x on each successful run. Retry up to 3 times on failure. - Variants combine mode (sw, hw, lro) with queue setup: + Queue setup variants: - isolated: Use a single queue isolated from RSS - 1q: Configure NIC to use 1 queue - 8q: Configure NIC to use 8 queues @@ -459,15 +457,11 @@ def test_gro_capacity(cfg, mode, setup_func): num_flows *= 2 -def main() -> None: - """ Ksft boiler plate main """ +def gro_main(src_path, mode) -> None: + """ Ksft boiler plate main, run all the cases in the given mode """ - with NetDrvEpEnv(__file__) as cfg: + with NetDrvEpEnv(src_path) as cfg: cfg.ethnl = EthtoolFamily() cfg.netnl = NetdevFamily() - ksft_run(cases=[test, test_gro_capacity], args=(cfg,)) + ksft_run(cases=[test, test_gro_capacity], args=(cfg, mode)) ksft_exit() - - -if __name__ == "__main__": - main() diff --git a/tools/testing/selftests/drivers/net/gro_lro.py b/tools/testing/selftests/drivers/net/gro_lro.py new file mode 100755 index 000000000000..63428d4aa749 --- /dev/null +++ b/tools/testing/selftests/drivers/net/gro_lro.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +GRO conformance tests against the LRO implementation +(large-receive-offload). + +See gro_lib.py for the list of test cases. +""" + +from gro_lib import gro_main + +if __name__ == "__main__": + gro_main(__file__, "lro") diff --git a/tools/testing/selftests/drivers/net/gro_sw.py b/tools/testing/selftests/drivers/net/gro_sw.py new file mode 100755 index 000000000000..b682c092faad --- /dev/null +++ b/tools/testing/selftests/drivers/net/gro_sw.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +GRO conformance tests against the SW GRO implementation. + +See gro_lib.py for the list of test cases. +""" + +from gro_lib import gro_main + +if __name__ == "__main__": + gro_main(__file__, "sw") diff --git a/tools/testing/selftests/drivers/net/pppoe_gro.py b/tools/testing/selftests/drivers/net/pppoe_gro.py new file mode 100755 index 000000000000..3891d5e17ee1 --- /dev/null +++ b/tools/testing/selftests/drivers/net/pppoe_gro.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +GRO conformance tests for PPPoE. + +Only SW GRO is expected to coalesce PPPoE, the HW offloads are not +exercised. PPPoE runs a subset of the cases described in gro_lib.py, +plus one of its own: + - pppoe_sid: Packets with different PPPoE session ID don't coalesce +""" + +from gro_lib import run_test +from lib.py import NetDrvEpEnv, ksft_exit, ksft_run, ksft_variants + + +def _pppoe_variants(): + """Generator that yields all combinations of protocol and test types.""" + + tests = [ + "data_same", "data_lrg_sml", "data_sml_lrg", "data_lrg_1byte", + "data_burst", "pppoe_sid", + ] + + for protocol in ["pppoev4", "pppoev6"]: + for test_name in tests: + yield protocol, test_name + + +@ksft_variants(_pppoe_variants()) +def test(cfg, protocol, test_name): + """Run a single GRO test case.""" + run_test(cfg, "sw", protocol, test_name) + + +def main() -> None: + """ Ksft boiler plate main """ + + with NetDrvEpEnv(__file__) as cfg: + ksft_run(cases=[test], args=(cfg,)) + ksft_exit() + + +if __name__ == "__main__": + main() diff --git a/tools/testing/selftests/net/lib/ksft_setup_loopback.sh b/tools/testing/selftests/net/lib/ksft_setup_loopback.sh index 3defbb1919c5..9ec4c3616795 100755 --- a/tools/testing/selftests/net/lib/ksft_setup_loopback.sh +++ b/tools/testing/selftests/net/lib/ksft_setup_loopback.sh @@ -12,7 +12,7 @@ # # Example use: # export NETIF=eth0 -# ./net/lib/ksft_setup_loopback.sh ./drivers/net/gro.py +# ./net/lib/ksft_setup_loopback.sh ./drivers/net/gro_sw.py if [ -z "$NETIF" ]; then echo "Error: NETIF variable not set" From 34d89dee719bb5509a50858756ed3d314ceb6af6 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 1 Sep 2026 13:07:28 -0700 Subject: [PATCH 0082/2126] selftests: drv-net: bump the timeout to 15min The XDP test takes 9m30s on the slowest NIC with debug kernel. Let's give ourselves a 50% margin and set the timeout to 15min. Reviewed-by: Joe Damato Reviewed-by: Nimrod Oren Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260901200728.2063720-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/settings b/tools/testing/selftests/drivers/net/settings index eef533824a3c..e2206265f67c 100644 --- a/tools/testing/selftests/drivers/net/settings +++ b/tools/testing/selftests/drivers/net/settings @@ -1 +1 @@ -timeout=360 +timeout=900 From 5add7c8d59fa3a54ebf7b662ef68dce9d44ddbef Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Tue, 1 Sep 2026 14:18:50 +0800 Subject: [PATCH 0083/2126] netdevsim: fix panic when NETIF_F_LOOPBACK is set on a VF port A netdevsim VF port cannot process incoming data. It never runs nsim_queue_init(), so ns->rq is NULL, and nsim_vf_netdev_ops has no ->ndo_open, so its NAPI is never set up either. nsim_setup() offers NETIF_F_LOOPBACK to both PF and VF ports. Turning it on for a VF makes nsim_start_xmit() take ns itself as peer_ns and dereference peer_ns->rq[], which panics. A VF cannot deliver packets at all: it can't be linked as a peer either, since netdev_is_nsim() only matches the PF netdev_ops, so ns->peer is always NULL and every skb ends up dropped. Give VF ports a dedicated xmit that just drops the traffic, so VFs no longer depend on PF-only state in nsim_start_xmit(). Reproduce in qemu: modprobe netdevsim echo "90 1" > /sys/bus/netdevsim/new_device echo 2 > /sys/bus/netdevsim/devices/netdevsim90/sriov_numvfs devlink dev eswitch set netdevsim/netdevsim90 mode switchdev ethtool -K eth2 loopback on # eth2 is the vfnum 0 port ip link set eth2 up Panic: KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 0 UID: 0 PID: 141 Comm: kworker/0:3 Not tainted 7.2.0+ #338 PREEMPT Workqueue: mld mld_ifc_work RIP: 0010:nsim_start_xmit (drivers/net/netdevsim/netdev.c:159) dev_hard_start_xmit ( net/core/dev.c:3953) sch_direct_xmit (net/sched/sch_generic.c:372) __dev_queue_xmit (net/core/dev.c:4262 net/core/dev.c:4884) neigh_resolve_output (net/core/neighbour.c:1616) ip6_finish_output2 (net/ipv6/ip6_output.c:138) ip6_finish_output (net/ipv6/ip6_output.c:221) ip6_output (net/ipv6/ip6_output.c:248) ...... Cc: stable+noautosel@kernel.org # netdevsim is a test harness, it's never loaded on production systems Signed-off-by: Jiayuan Chen Link: https://patch.msgid.link/20260901061851.61734-1-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/netdev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index b4a99f3ceac6..eebc02ccc4a9 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -185,6 +185,14 @@ out_drop_cnt: return NETDEV_TX_OK; } +static netdev_tx_t nsim_start_xmit_vf(struct sk_buff *skb, + struct net_device *dev) +{ + dev_dstats_tx_dropped(dev); + kfree_skb(skb); + return NETDEV_TX_OK; +} + static int nsim_set_rx_mode(struct net_device *dev, struct netdev_hw_addr_list *uc, struct netdev_hw_addr_list *mc) @@ -651,7 +659,7 @@ static const struct net_device_ops nsim_netdev_ops = { }; static const struct net_device_ops nsim_vf_netdev_ops = { - .ndo_start_xmit = nsim_start_xmit, + .ndo_start_xmit = nsim_start_xmit_vf, .ndo_set_rx_mode_async = nsim_set_rx_mode, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, From 7c0ec6288b497fc4dd190e243141a8d429488fd2 Mon Sep 17 00:00:00 2001 From: Sebastian Andrzej Siewior Date: Tue, 1 Sep 2026 18:03:45 +0200 Subject: [PATCH 0084/2126] net: Replace %pK output with 0 Commit 71338aa7d050c ("net: convert %p usage to %pK") which is from 2011 and changed the %p annotation for pointer to %pK. Back then the default behaviour for %p was to print the pointer. The %pK modifier was introduced to able to control the behaviour of specific pointer values without changing the behaviour of %p for everyone. It was dedicated to avoid leaking pointers via /proc. There was also the idea to remove the check from formatting the string and move to the open callback with some helpers but this did not happen. Things changed over time. The default behaviour for %p is now to print a hash pointer which does not leak the address but allows to correlate if two pointers are equal. The policy on %p is to not introduce new ones. This is somehow in between since it already exists. The pointer are usually socket pointers and I don't see any value in exposing them. Therefore I am following the recommendation of removing them. Since their usage in /proc/ can be considered ABI I replace the pointer with a 0. Replace the %pK annotation with 0 value. Correct the spacing for the cases where pointer is at the beginning. Reviewed-by: Kees Cook Signed-off-by: Sebastian Andrzej Siewior Link: https://patch.msgid.link/20260901160345.eeknHmY2@linutronix.de Signed-off-by: Jakub Kicinski --- Documentation/networking/proc_net_tcp.rst | 20 ++++++++++---------- net/atm/proc.c | 7 +++---- net/ipv4/ping.c | 5 ++--- net/ipv4/raw.c | 4 ++-- net/ipv4/tcp_ipv4.c | 13 ++++++------- net/ipv4/udp.c | 5 ++--- net/ipv6/datagram.c | 5 ++--- net/ipv6/tcp_ipv6.c | 12 ++++++------ net/key/af_key.c | 5 ++--- net/netlink/af_netlink.c | 5 ++--- net/packet/af_packet.c | 7 ++----- net/phonet/socket.c | 5 ++--- net/sctp/proc.c | 6 +++--- net/unix/af_unix.c | 3 +-- 14 files changed, 45 insertions(+), 57 deletions(-) diff --git a/Documentation/networking/proc_net_tcp.rst b/Documentation/networking/proc_net_tcp.rst index 7d9dfe36af45..4fa2e58429b9 100644 --- a/Documentation/networking/proc_net_tcp.rst +++ b/Documentation/networking/proc_net_tcp.rst @@ -30,16 +30,16 @@ up into 3 parts because of the length of the line):: | |----------------------> receive-queue |-------------------------------> transmit-queue - 1000 0 54165785 4 cd1e6040 25 4 27 3 -1 - | | | | | | | | | |--> slow start size threshold, - | | | | | | | | | or -1 if the threshold - | | | | | | | | | is >= 0xFFFF - | | | | | | | | |----> sending congestion window - | | | | | | | |-------> (ack.quick<<1)|ack.pingpong - | | | | | | |---------> Predicted tick of soft clock - | | | | | | (delayed ACK control data) - | | | | | |------------> retransmit timeout - | | | | |------------------> location of socket in memory + 1000 0 54165785 4 0 25 4 27 3 -1 + | | | | | | | | | |-------> slow start size threshold, + | | | | | | | | | or -1 if the threshold + | | | | | | | | | is >= 0xFFFF + | | | | | | | | |---------> sending congestion window + | | | | | | | |------------> (ack.quick<<1)|ack.pingpong + | | | | | | |--------------> Predicted tick of soft clock + | | | | | | (delayed ACK control data) + | | | | | |-----------------> retransmit timeout + | | | | |--------------------> always 0 (was memory location). | | | |-----------------------> socket reference count | | |-----------------------------> inode | |----------------------------------> unanswered 0-window probes diff --git a/net/atm/proc.c b/net/atm/proc.c index 8f20b49b9c02..ca0fc6b90998 100644 --- a/net/atm/proc.c +++ b/net/atm/proc.c @@ -159,7 +159,7 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc) { struct sock *sk = sk_atm(vcc); - seq_printf(seq, "%pK ", vcc); + seq_puts(seq, " 0 "); if (!vcc->dev) seq_printf(seq, "Unassigned "); else @@ -228,9 +228,8 @@ static const struct seq_operations pvc_seq_ops = { static int vcc_seq_show(struct seq_file *seq, void *v) { if (v == SEQ_START_TOKEN) { - seq_printf(seq, sizeof(void *) == 4 ? "%-8s%s" : "%-16s%s", - "Address ", "Itf VPI VCI Fam Flags Reply " - "Send buffer Recv buffer [refcnt]\n"); + seq_puts(seq, "Address Itf VPI VCI Fam Flags Reply " + "Send buffer Recv buffer [refcnt]\n"); } else { struct vcc_state *state = seq->private; struct atm_vcc *vcc = atm_sk(state->sk); diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index d36f1e273fde..223a0108b74c 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -1095,15 +1095,14 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f, __u16 srcp = ntohs(inet->inet_sport); seq_printf(f, "%5d: %08X:%04X %08X:%04X" - " %02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d %pK %u", + " %02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d 0 %u", bucket, src, srcp, dest, destp, sp->sk_state, sk_wmem_alloc_get(sp), sk_rmem_alloc_get(sp), 0, 0L, 0, from_kuid_munged(seq_user_ns(f), sk_uid(sp)), 0, sock_i_ino(sp), - refcount_read(&sp->sk_refcnt), sp, - sk_drops_read(sp)); + refcount_read(&sp->sk_refcnt), sk_drops_read(sp)); } static int ping_v4_seq_show(struct seq_file *seq, void *v) diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index d756e5e31b90..9d01006d8189 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -1054,14 +1054,14 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i) srcp = inet->inet_num; seq_printf(seq, "%4d: %08X:%04X %08X:%04X" - " %02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d %pK %u\n", + " %02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d 0 %u\n", i, src, srcp, dest, destp, sp->sk_state, sk_wmem_alloc_get(sp), sk_rmem_alloc_get(sp), 0, 0L, 0, from_kuid_munged(seq_user_ns(seq), sk_uid(sp)), 0, sock_i_ino(sp), - refcount_read(&sp->sk_refcnt), sp, sk_drops_read(sp)); + refcount_read(&sp->sk_refcnt), sk_drops_read(sp)); } static int raw_seq_show(struct seq_file *seq, void *v) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 9f053eb8b46e..142e7b048229 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2748,7 +2748,7 @@ static void get_openreq4(const struct request_sock *req, long delta = req->rsk_timer.expires - jiffies; seq_printf(f, "%4d: %08X:%04X %08X:%04X" - " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK", + " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d 0", i, ireq->ir_loc_addr, ireq->ir_num, @@ -2763,8 +2763,7 @@ static void get_openreq4(const struct request_sock *req, sk_uid(req->rsk_listener)), 0, /* non standard timer */ 0, /* open_requests have no inode */ - 0, - req); + 0); } static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) @@ -2811,7 +2810,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) READ_ONCE(tp->copied_seq), 0); seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " - "%08X %5u %8d %llu %d %pK %lu %lu %u %u %d", + "%08X %5u %8d %llu %d 0 %lu %lu %u %u %d", i, src, srcp, dest, destp, state, READ_ONCE(tp->write_seq) - tp->snd_una, rx_queue, @@ -2821,7 +2820,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) from_kuid_munged(seq_user_ns(f), sk_uid(sk)), READ_ONCE(icsk->icsk_probes_out), sock_i_ino(sk), - refcount_read(&sk->sk_refcnt), sk, + refcount_read(&sk->sk_refcnt), jiffies_to_clock_t(icsk->icsk_rto), jiffies_to_clock_t(icsk->icsk_ack.ato), (icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(sk), @@ -2844,10 +2843,10 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw, srcp = ntohs(tw->tw_sport); seq_printf(f, "%4d: %08X:%04X %08X:%04X" - " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK", + " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0", i, src, srcp, dest, destp, READ_ONCE(tw->tw_substate), 0, 0, 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, - refcount_read(&tw->tw_refcnt), tw); + refcount_read(&tw->tw_refcnt)); } #define TMPSZ 150 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index af9603217444..a01db598c00b 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -3283,15 +3283,14 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f, __u16 srcp = ntohs(inet->inet_sport); seq_printf(f, "%5d: %08X:%04X %08X:%04X" - " %02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d %pK %u", + " %02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d 0 %u", bucket, src, srcp, dest, destp, sp->sk_state, sk_wmem_alloc_get(sp), udp_rqueue_get(sp), 0, 0L, 0, from_kuid_munged(seq_user_ns(f), sk_uid(sp)), 0, sock_i_ino(sp), - refcount_read(&sp->sk_refcnt), sp, - sk_drops_read(sp)); + refcount_read(&sp->sk_refcnt), sk_drops_read(sp)); } static int udp4_seq_show(struct seq_file *seq, void *v) diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index 38d7b4845281..191c9733ff9f 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c @@ -1102,7 +1102,7 @@ void __ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp, src = &sp->sk_v6_rcv_saddr; seq_printf(seq, "%5d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " - "%02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d %pK %u\n", + "%02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d 0 %u\n", bucket, src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[2], src->s6_addr32[3], srcp, @@ -1115,6 +1115,5 @@ void __ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp, from_kuid_munged(seq_user_ns(seq), sk_uid(sp)), 0, sock_i_ino(sp), - refcount_read(&sp->sk_refcnt), sp, - sk_drops_read(sp)); + refcount_read(&sp->sk_refcnt), sk_drops_read(sp)); } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index df9c29eb5c1f..b55d036c7f4d 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -2103,7 +2103,7 @@ static void get_openreq6(struct seq_file *seq, seq_printf(seq, "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " - "%02X %08X:%08X %02X:%08lX %08X %5u %8d %d %d %pK\n", + "%02X %08X:%08X %02X:%08lX %08X %5u %8d %d %d 0\n", i, src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[2], src->s6_addr32[3], @@ -2120,7 +2120,7 @@ static void get_openreq6(struct seq_file *seq, sk_uid(req->rsk_listener)), 0, /* non standard timer */ 0, /* open_requests have no inode */ - 0, req); + 0); } static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) @@ -2171,7 +2171,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) seq_printf(seq, "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " - "%02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d %pK %lu %lu %u %u %d\n", + "%02X %08X:%08X %02X:%08lX %08X %5u %8d %llu %d 0 %lu %lu %u %u %d\n", i, src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[2], src->s6_addr32[3], srcp, @@ -2186,7 +2186,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) from_kuid_munged(seq_user_ns(seq), sk_uid(sp)), READ_ONCE(icsk->icsk_probes_out), sock_i_ino(sp), - refcount_read(&sp->sk_refcnt), sp, + refcount_read(&sp->sk_refcnt), jiffies_to_clock_t(icsk->icsk_rto), jiffies_to_clock_t(icsk->icsk_ack.ato), (icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(sp), @@ -2211,7 +2211,7 @@ static void get_timewait6_sock(struct seq_file *seq, seq_printf(seq, "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " - "%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n", + "%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n", i, src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[2], src->s6_addr32[3], srcp, @@ -2219,7 +2219,7 @@ static void get_timewait6_sock(struct seq_file *seq, dest->s6_addr32[2], dest->s6_addr32[3], destp, READ_ONCE(tw->tw_substate), 0, 0, 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, - refcount_read(&tw->tw_refcnt), tw); + refcount_read(&tw->tw_refcnt)); } static int tcp6_seq_show(struct seq_file *seq, void *v) diff --git a/net/key/af_key.c b/net/key/af_key.c index 1d8965d7f4f3..d215b33b7492 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -3803,10 +3803,9 @@ static int pfkey_seq_show(struct seq_file *f, void *v) struct sock *s = sk_entry(v); if (v == SEQ_START_TOKEN) - seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n"); + seq_puts(f, "sk RefCnt Rmem Wmem User Inode\n"); else - seq_printf(f, "%pK %-6d %-6u %-6u %-6u %-6llu\n", - s, + seq_printf(f, "0 %-6d %-6u %-6u %-6u %-6llu\n", refcount_read(&s->sk_refcnt), sk_rmem_alloc_get(s), sk_wmem_alloc_get(s), diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index e6b1d9758c9c..537562aacb7e 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2700,14 +2700,13 @@ static int netlink_native_seq_show(struct seq_file *seq, void *v) { if (v == SEQ_START_TOKEN) { seq_puts(seq, - "sk Eth Pid Groups " + "sk Eth Pid Groups " "Rmem Wmem Dump Locks Drops Inode\n"); } else { struct sock *s = v; struct netlink_sock *nlk = nlk_sk(s); - seq_printf(seq, "%pK %-3d %-10u %08x %-8d %-8d %-5d %-8d %-8u %-8llu\n", - s, + seq_printf(seq, "0 %-3d %-10u %08x %-8d %-8d %-5d %-8d %-8u %-8llu\n", s->sk_protocol, nlk->portid, nlk->groups ? (u32)nlk->groups[0] : 0, diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index b22cda322136..331f78689075 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4825,16 +4825,13 @@ static void packet_seq_stop(struct seq_file *seq, void *v) static int packet_seq_show(struct seq_file *seq, void *v) { if (v == SEQ_START_TOKEN) - seq_printf(seq, - "%*sRefCnt Type Proto Iface R Rmem User Inode\n", - IS_ENABLED(CONFIG_64BIT) ? -17 : -9, "sk"); + seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n"); else { struct sock *s = sk_entry(v); const struct packet_sock *po = pkt_sk(s); seq_printf(seq, - "%pK %-6d %-4d %04x %-5d %1d %-6u %-6u %-6llu\n", - s, + "0 %-6d %-4d %04x %-5d %1d %-6u %-6u %-6llu\n", refcount_read(&s->sk_refcnt), s->sk_type, ntohs(READ_ONCE(po->num)), diff --git a/net/phonet/socket.c b/net/phonet/socket.c index 631a99cdbd00..ad12b746d4fc 100644 --- a/net/phonet/socket.c +++ b/net/phonet/socket.c @@ -586,14 +586,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v) struct pn_sock *pn = pn_sk(sk); seq_printf(seq, "%2d %04X:%04X:%02X %02X %08X:%08X %5d %llu " - "%d %pK %u", + "%d 0 %u", sk->sk_protocol, pn->sobject, pn->dobject, pn->resource, sk->sk_state, sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk), from_kuid_munged(seq_user_ns(seq), sk_uid(sk)), sock_i_ino(sk), - refcount_read(&sk->sk_refcnt), sk, - sk_drops_read(sk)); + refcount_read(&sk->sk_refcnt), sk_drops_read(sk)); } seq_pad(seq, '\n'); return 0; diff --git a/net/sctp/proc.c b/net/sctp/proc.c index 43433d7e2acd..7ea123b90aa5 100644 --- a/net/sctp/proc.c +++ b/net/sctp/proc.c @@ -174,7 +174,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v) sk = ep->base.sk; if (!net_eq(sock_net(sk), seq_file_net(seq))) continue; - seq_printf(seq, "%8pK %8pK %-3d %-3d %-4d %-5d %5u %5llu ", ep, sk, + seq_printf(seq, "%8d %8d %-3d %-3d %-4d %-5d %5u %5llu ", 0, 0, sctp_sk(sk)->type, sk->sk_state, hash, ep->base.bind_addr.port, from_kuid_munged(seq_user_ns(seq), sk_uid(sk)), @@ -260,9 +260,9 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v) sk = epb->sk; seq_printf(seq, - "%8pK %8pK %-3d %-3d %-2d %-4d " + "%8d %8d %-3d %-3d %-2d %-4d " "%4d %8d %8d %7u %5llu %-5d %5d ", - assoc, sk, sctp_sk(sk)->type, sk->sk_state, + 0, 0, sctp_sk(sk)->type, sk->sk_state, assoc->state, 0, assoc->assoc_id, assoc->sndbuf_used, diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 13f9926bf205..82f951376e0b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -3562,8 +3562,7 @@ static int unix_seq_show(struct seq_file *seq, void *v) struct unix_sock *u = unix_sk(s); unix_state_lock(s); - seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5llu", - s, + seq_printf(seq, "%08u: %08X %08X %08X %04X %02X %5llu", 0, refcount_read(&s->sk_refcnt), 0, s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0, From a3b4826138d453ce74cc7de4adaca08c622b6e07 Mon Sep 17 00:00:00 2001 From: "Mike Rapoport (Microsoft)" Date: Sun, 30 Aug 2026 11:10:38 +0300 Subject: [PATCH 0085/2126] USB: cxacru: replace __get_free_page() with kmalloc() cxacru_fw() allocates a temporary buffer used to feed the firmware to the device and cxacru_bind() allocates the transfer buffers for the command URBs. These buffers can be allocated with kmalloc() as there's nothing special about them to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. Replace use of __get_free_page() with kmalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Signed-off-by: Mike Rapoport (Microsoft) Link: https://patch.msgid.link/20260830-usb-v1-2-aa349c302246@kernel.org Signed-off-by: Jakub Kicinski --- drivers/usb/atm/cxacru.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 636f7886fc26..75d87c31e81f 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c @@ -942,7 +942,7 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw, int offd, offb; const int stride = CMD_PACKET_SIZE - 8; - buf = (u8 *) __get_free_page(GFP_KERNEL); + buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -978,7 +978,7 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw, ret = 0; cleanup: - free_page((unsigned long) buf); + kfree(buf); return ret; } @@ -1146,13 +1146,13 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance, mutex_init(&instance->adsl_state_serialize); - instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL); + instance->rcv_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!instance->rcv_buf) { usb_dbg(usbatm_instance, "cxacru_bind: no memory for rcv_buf\n"); ret = -ENOMEM; goto fail; } - instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL); + instance->snd_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!instance->snd_buf) { usb_dbg(usbatm_instance, "cxacru_bind: no memory for snd_buf\n"); ret = -ENOMEM; @@ -1220,8 +1220,8 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance, return 0; fail: - free_page((unsigned long) instance->snd_buf); - free_page((unsigned long) instance->rcv_buf); + kfree(instance->snd_buf); + kfree(instance->rcv_buf); usb_free_urb(instance->snd_urb); usb_free_urb(instance->rcv_urb); kfree(instance); @@ -1254,8 +1254,8 @@ static void cxacru_unbind(struct usbatm_data *usbatm_instance, usb_free_urb(instance->snd_urb); usb_free_urb(instance->rcv_urb); - free_page((unsigned long) instance->snd_buf); - free_page((unsigned long) instance->rcv_buf); + kfree(instance->snd_buf); + kfree(instance->rcv_buf); kfree(instance); From 534b188139745e0f31274fdb24e7abbeee2df204 Mon Sep 17 00:00:00 2001 From: "Mike Rapoport (Microsoft)" Date: Sun, 30 Aug 2026 11:10:39 +0300 Subject: [PATCH 0086/2126] USB: speedtch: replace __get_free_page() with kmalloc() speedtch_upload_firmware() allocates a temporary buffer used to feed the firmware to the device. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. Replace use of __get_free_page() with kmalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Signed-off-by: Mike Rapoport (Microsoft) Link: https://patch.msgid.link/20260830-usb-v1-3-aa349c302246@kernel.org Signed-off-by: Jakub Kicinski --- drivers/usb/atm/speedtch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index 9d28c652bcd8..e5e021aafbd3 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c @@ -241,7 +241,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance, usb_dbg(usbatm, "%s entered\n", __func__); - buffer = (unsigned char *)__get_free_page(GFP_KERNEL); + buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buffer) { ret = -ENOMEM; usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); @@ -340,7 +340,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance, ret = 0; out_free: - free_page((unsigned long)buffer); + kfree(buffer); out: return ret; } From c3a1b6763f4d76d69cb00e4e3a82ce7e18729507 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:27 +0200 Subject: [PATCH 0087/2126] dt-bindings: net: realtek,rtl9301-mdio: Add RTL83xx series The lower end Realtek Otto switches provide 1G only and are divided into two series: - Maple : RTL838x up to 28 ports - Cypress: RTL839x up to 52 ports The Maple based devices have 3 different SoCs: RTL8380, RTL8381 and RTL8382. The Cypress series consists of the RTL8391, RTL8392 and RTL8393 SoCs. The MDIO controller of these switches works like the existing RTL93xx logic but has different characteristics and different registers. Add new compatibles in the device tree. With the extended compatibility list change the title to better reflect its scope. Especially add the "Ethernet" tag as these devices have multiple MDIO controllers. Signed-off-by: Markus Stockhausen Acked-by: Conor Dooley Link: https://patch.msgid.link/20260831143439.2404484-2-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- .../bindings/net/realtek,rtl9301-mdio.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml index 271e05bae9c5..67e0b23a8470 100644 --- a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml +++ b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/net/realtek,rtl9301-mdio.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Realtek RTL9300 MDIO Controller +title: Realtek Otto Switches Ethernet MDIO Controller maintainers: - Chris Packham @@ -12,6 +12,16 @@ maintainers: properties: compatible: oneOf: + - items: + - enum: + - realtek,rtl8381-mdio + - realtek,rtl8382-mdio + - const: realtek,rtl8380-mdio + - items: + - enum: + - realtek,rtl8392-mdio + - realtek,rtl8393-mdio + - const: realtek,rtl8391-mdio - items: - enum: - realtek,rtl9302b-mdio @@ -24,6 +34,8 @@ properties: - realtek,rtl9313-mdio - const: realtek,rtl9311-mdio - enum: + - realtek,rtl8380-mdio + - realtek,rtl8391-mdio - realtek,rtl9301-mdio - realtek,rtl9311-mdio From 1c86cd6937165b8ea702d8931d09f1df238c2a44 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:28 +0200 Subject: [PATCH 0088/2126] net: mdio: realtek-rtl9300: Add polling documentation Add a detailed explanation how the hardware polling unit in the Realtek Otto switches works. This simplifies developing future patches and reviewing them. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-3-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index afd52a1cd7f8..73ac5fdcd267 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -35,6 +35,81 @@ * * The driver works out the mapping based on the MDIO bus described in device tree and phandles on * the ethernet-ports property. + * + * The devices have a hardware polling unit that runs in the background without any CPU load. It + * constantly scans the MDIO bus and the attached PHYs and updates the MAC status registers. + * + * How does the polling work? + * + * Each device has a SMI_POLL_CTRL register. A per-port bitmask decides if the hardware polling of + * the associated bus/address is active or not. The hardware runs a tight loop over this and for + * each set polling bit it issues a status check for the PHY. Attaching a logic analyzer to the + * MDIO bus of an RTL8380 and RTL8393 gives the following commands (in kernel notation): + * + * RTL8380 RTL8393 + * --------------------------- --------------------------- + * phy_write(phy, 31, 0x0); phy_read(phy, 0); + * phy_write(phy, 13, 0x7); phy_read(phy, 1); + * phy_write(phy, 14, 0x3c); phy_read(phy, 4); + * phy_write(phy, 13, 0x8007); phy_read(phy, 5); + * phy_read(phy, 14); phy_read(phy, 6); + * phy_write(phy, 13, 0x7); phy_read(phy, 9); + * phy_write(phy, 14, 0x3d); phy_read(phy, 10); + * phy_write(phy, 13, 0x8007); phy_read(phy, 15); + * phy_read(phy, 14); phy_write(phy, 13, 0x7); + * phy_read(phy, 9); phy_write(phy, 14, 0x3c); + * phy_read(phy, 10); phy_write(phy, 13, 0x4007); + * phy_read(phy, 15); phy_read(phy, 14); + * phy_read(phy, 0); phy_write(phy, 13, 0x7); + * phy_read(phy, 1); phy_write(phy, 14, 0x3d); + * phy_read(phy, 4); phy_write(phy, 13, 0x4007); + * phy_read(phy, 5); phy_read(phy, 14); + * phy_read(phy, 6); + * + * After one PHY status is read, the polling engine goes over to the next PHY. If one bus is fully + * scanned it switches over to the next bus. Basically the polling system is always busy and the + * MAC state is updated in real-time. + * + * This is a glimpse look at the complexity of the polling and leaves out the C45 case and the MAC + * register update logic afterwards. Important to note: + * + * - 100 MBit downshifts (broken cables) are identified and propagated to the MAC correctly + * - Access to MDIO_AN_EEE_ADV and MDIO_AN_EEE_LPABLE works via C45 over C22. + * - It is unclear if these sequences change for different PHYs. + * - Access to Realtek reserved register 26 (link speed) has not yet been seen. + * + * How does MDIO access from kernel work? + * + * When issuing MDIO accesses via an MMIO based interface the final write to the command register + * sets a "run command now" bit. Between two polling sequences for different PHYs the hardware + * checks if a user command needs to run and sends it onto the bus. Afterwards it simply continues + * its polling work. Inspecting the command sequence for a paged write on the logic analyzer gives: + * + * RTL8380 RTL8393 + * --------------------------- --------------------------- + * phy_write(phy, 31, page); phy_write(phy, 31, page); + * phy_write(phy, reg, value); phy_write(phy, reg, value); + * phy_write(phy, 31, 0); + * + * What does this mean? + * + * There are slight differences in polling and PHY access between the models but the challenge + * stays the same. On the one hand that greatly simplifies the MAC layer, on the other hand it + * has some implications for the kernel PHY subsystem. + * + * - Without the polling and a proper MAC status, some of the link handling features do not work. + * Especially an unpopulated MAC_LINK_STS register cancels operations to other MAC registers. + * - The Realtek page register 31 is magically modified in the background so that polling will + * read the right data. On the RTL838x polling simply resets it to zero. Other devices seem + * to track the page access "magically" in the background. + * - A C45 over C22 kernel access sequence is most likely to fail because chances are high that + * the polling engine overwrites registers 13/14 in between. + * - PHY firmware loading can have issues. Especially if a PHY is designed to expect a clean + * sequence of registers and values without deviation. + * - An access to one PHY will need to wait for the next free slot of the polling engine. + * + * Conclusion: The Realtek MDIO bus driver PHY access must know and handle any interference that + * arises from the above described hardware polling. */ #include From 3383b50c1695f7a7f0895b235706a3f2acf4ab11 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:29 +0200 Subject: [PATCH 0089/2126] net: mdio: realtek-rtl9300: deny C45 over C22 access Hardware polling breaks C45 over C22 PHY access. Currently this is accepted by the driver but it silently fails with undefined results. Make the situation clear to the caller by adding checks, returning an error and giving a one-time warning message. Suggested-by: Andrew Lunn Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-4-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 73ac5fdcd267..69565a87f99d 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -115,6 +115,7 @@ #include #include #include +#include #include #include #include @@ -453,6 +454,12 @@ static int otto_emdio_read_c22(struct mii_bus *bus, int phy_id, int regnum) int ret, port; u32 value; + if (regnum == MII_MMD_CTRL || regnum == MII_MMD_DATA) { + dev_warn_once(&bus->dev, + "C45 over C22 read access broken due to polling\n"); + return -EOPNOTSUPP; + } + port = otto_emdio_phy_to_port(bus, phy_id); if (port < 0) return port; @@ -463,11 +470,18 @@ static int otto_emdio_read_c22(struct mii_bus *bus, int phy_id, int regnum) return ret ? ret : value; } -static int otto_emdio_write_c22(struct mii_bus *bus, int phy_id, int regnum, u16 value) +static int otto_emdio_write_c22(struct mii_bus *bus, int phy_id, int regnum, + u16 value) { struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); int ret, port; + if (regnum == MII_MMD_CTRL || regnum == MII_MMD_DATA) { + dev_warn_once(&bus->dev, + "C45 over C22 write access broken due to polling\n"); + return -EOPNOTSUPP; + } + port = otto_emdio_phy_to_port(bus, phy_id); if (port < 0) return port; From 2df76677c1c08f622cc577a49f0645a5976d7c91 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:30 +0200 Subject: [PATCH 0090/2126] net: phy: add phy_detach_internal() helper For the upcoming MDIO bus notification enhancements the PHY detach path needs to inform the bus about these actions. Until now phy_detach() is used for the regular detach path as well as from the phy_attach_direct() error paths So in the future there must be a clear indication if a notification is needed (normal path) or not (cleanup path). Carve out the phy_detach() code into a new helper phy_detach_internal() and make phy_detach() a short stub that calls the new helper. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-5-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 172 +++++++++++++++++++---------------- 1 file changed, 92 insertions(+), 80 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8cb0d60fcbba..69b04a92b776 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1763,6 +1763,98 @@ static bool phy_drv_supports_irq(const struct phy_driver *phydrv) return phydrv->config_intr && phydrv->handle_interrupt; } +/** + * phy_detach_internal - detach a PHY device from its network device + * @phydev: target phy_device struct + * + * This detaches the phy device from its network device and the phy + * driver, and drops the reference count taken in phy_attach_direct(). + */ +static void phy_detach_internal(struct phy_device *phydev) +{ + struct net_device *dev = phydev->attached_dev; + struct module *ndev_owner = NULL; + struct mii_bus *bus; + + if (phydev->devlink) { + device_link_del(phydev->devlink); + phydev->devlink = NULL; + } + + if (phydev->sysfs_links) { + if (dev) + sysfs_remove_link(&dev->dev.kobj, "phydev"); + sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); + } + + if (!phydev->attached_dev) + sysfs_remove_file(&phydev->mdio.dev.kobj, + &dev_attr_phy_standalone.attr); + + phy_suspend(phydev); + if (dev) { + struct hwtstamp_provider *hwprov; + + /* hwprov may technically be protected by ops lock but + * not for devices with a phydev, see phy_link_topo_add_phy() + */ + hwprov = rtnl_dereference(dev->hwprov); + /* Disable timestamp if it is the one selected */ + if (hwprov && hwprov->phydev == phydev) { + rcu_assign_pointer(dev->hwprov, NULL); + kfree_rcu(hwprov, rcu_head); + } + + phydev->attached_dev->phydev = NULL; + phydev->attached_dev = NULL; + phy_link_topo_del_phy(dev, phydev); + } + + phydev->phy_link_change = NULL; + phydev->phylink = NULL; + + if (phydev->mdio.dev.driver) + module_put(phydev->mdio.dev.driver->owner); + + /* If the device had no specific driver before (i.e. - it + * was using the generic driver), we unbind the device + * from the generic driver so that there's a chance a + * real driver could be loaded + */ + if (phydev->is_genphy_driven) { + device_release_driver(&phydev->mdio.dev); + phydev->is_genphy_driven = 0; + } + + /* Assert the reset signal */ + phy_device_reset(phydev, 1); + + /* + * The phydev might go away on the put_device() below, so avoid + * a use-after-free bug by reading the underlying bus first. + */ + bus = phydev->mdio.bus; + + put_device(&phydev->mdio.dev); + if (dev) + ndev_owner = dev->dev.parent->driver->owner; + if (ndev_owner != bus->owner) + module_put(bus->owner); +} + +/** + * phy_detach - detach a PHY device from its network device + * @phydev: target phy_device struct + * + * This detaches the phy device from its network device and the phy + * driver, and drops the reference count taken in phy_attach_direct(). + */ +void phy_detach(struct phy_device *phydev) +{ + phy_detach_internal(phydev); +} +EXPORT_SYMBOL(phy_detach); + /** * phy_attach_direct - attach a network device to a given PHY device pointer * @dev: network device to attach @@ -1935,86 +2027,6 @@ error_put_device: } EXPORT_SYMBOL(phy_attach_direct); -/** - * phy_detach - detach a PHY device from its network device - * @phydev: target phy_device struct - * - * This detaches the phy device from its network device and the phy - * driver, and drops the reference count taken in phy_attach_direct(). - */ -void phy_detach(struct phy_device *phydev) -{ - struct net_device *dev = phydev->attached_dev; - struct module *ndev_owner = NULL; - struct mii_bus *bus; - - if (phydev->devlink) { - device_link_del(phydev->devlink); - phydev->devlink = NULL; - } - - if (phydev->sysfs_links) { - if (dev) - sysfs_remove_link(&dev->dev.kobj, "phydev"); - sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); - } - - if (!phydev->attached_dev) - sysfs_remove_file(&phydev->mdio.dev.kobj, - &dev_attr_phy_standalone.attr); - - phy_suspend(phydev); - if (dev) { - struct hwtstamp_provider *hwprov; - - /* hwprov may technically be protected by ops lock but - * not for devices with a phydev, see phy_link_topo_add_phy() - */ - hwprov = rtnl_dereference(dev->hwprov); - /* Disable timestamp if it is the one selected */ - if (hwprov && hwprov->phydev == phydev) { - rcu_assign_pointer(dev->hwprov, NULL); - kfree_rcu(hwprov, rcu_head); - } - - phydev->attached_dev->phydev = NULL; - phydev->attached_dev = NULL; - phy_link_topo_del_phy(dev, phydev); - } - - phydev->phy_link_change = NULL; - phydev->phylink = NULL; - - if (phydev->mdio.dev.driver) - module_put(phydev->mdio.dev.driver->owner); - - /* If the device had no specific driver before (i.e. - it - * was using the generic driver), we unbind the device - * from the generic driver so that there's a chance a - * real driver could be loaded - */ - if (phydev->is_genphy_driven) { - device_release_driver(&phydev->mdio.dev); - phydev->is_genphy_driven = 0; - } - - /* Assert the reset signal */ - phy_device_reset(phydev, 1); - - /* - * The phydev might go away on the put_device() below, so avoid - * a use-after-free bug by reading the underlying bus first. - */ - bus = phydev->mdio.bus; - - put_device(&phydev->mdio.dev); - if (dev) - ndev_owner = dev->dev.parent->driver->owner; - if (ndev_owner != bus->owner) - module_put(bus->owner); -} -EXPORT_SYMBOL(phy_detach); - int phy_suspend(struct phy_device *phydev) { struct net_device *netdev = phydev->attached_dev; From 4b1d5d51528a2178aa9abeea4881e15f2344285d Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:34:31 +0200 Subject: [PATCH 0091/2126] net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus Some MDIO buses require programming PHY polling registers depending on the PHY type. RealTek switch SoCs are the most prominent example of a DSA switch which doesn't allow to program MAC speed, duplex and flow-control settings without using PHY polling to do so [1]. Avoid a half-baked solution in the MDIO bus driver because - it must reinvent the bus scanning to determine the PHYs and - it must anticipate the right point in time (e.g. deferred PHYs). Hence there is a need to inform the MDIO bus driver that a PHY is being attached or detached. Provide two hooks in struct mii_bus - notify_phy_attach(): called in phy_attach_direct() after PHY hardware has been initialized and just before PHY is resumed. - notify_phy_detach(): called in phy_detach() right after PHY has been suspended. Worth to notice: As of now phy_detach() is not 100% LIFO symmetric to phy_attach_direct(). E.g. sysfs links are torn down before suspend while being created before resume. Without reordering of the detach function the above mentioned notifier placement is the best possible symmetric implementation. An unconditional call of notify_phy_detach() was favoured [3]. Remark! A slightly different version of this patch was part of a former series [2]. The discussion already showed that an initialization hook should be placed somewhere late during the whole setup. This commit implants it right after phy_init_hw() as suggested. On top of this it adds the detach hook. [1] https://github.com/openwrt/openwrt/pull/21515#discussion_r2714069716 [2] https://lore.kernel.org/netdev/cover.1769053496.git.daniel@makrotopia.org/ [3] https://lore.kernel.org/netdev/9e40f50b-357a-4a93-9f59-94847850835d@lunn.ch/#t Signed-off-by: Daniel Golle Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-6-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 20 ++++++++++++++++---- include/linux/phy.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 69b04a92b776..41d1b20cde2c 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1766,11 +1766,12 @@ static bool phy_drv_supports_irq(const struct phy_driver *phydrv) /** * phy_detach_internal - detach a PHY device from its network device * @phydev: target phy_device struct + * @notify_bus: whether to notify the MDIO bus about the PHY detach * * This detaches the phy device from its network device and the phy * driver, and drops the reference count taken in phy_attach_direct(). */ -static void phy_detach_internal(struct phy_device *phydev) +static void phy_detach_internal(struct phy_device *phydev, bool notify_bus) { struct net_device *dev = phydev->attached_dev; struct module *ndev_owner = NULL; @@ -1792,6 +1793,10 @@ static void phy_detach_internal(struct phy_device *phydev) &dev_attr_phy_standalone.attr); phy_suspend(phydev); + + if (notify_bus && phydev->mdio.bus->notify_phy_detach) + phydev->mdio.bus->notify_phy_detach(phydev); + if (dev) { struct hwtstamp_provider *hwprov; @@ -1851,7 +1856,8 @@ static void phy_detach_internal(struct phy_device *phydev) */ void phy_detach(struct phy_device *phydev) { - phy_detach_internal(phydev); + /* cleanup including bus notification */ + phy_detach_internal(phydev, true); } EXPORT_SYMBOL(phy_detach); @@ -1997,6 +2003,12 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, if (err) goto error; + if (phydev->mdio.bus->notify_phy_attach) { + err = phydev->mdio.bus->notify_phy_attach(phydev); + if (err) + goto error; + } + phy_resume(phydev); /** @@ -2011,8 +2023,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, return err; error: - /* phy_detach() does all of the cleanup below */ - phy_detach(phydev); + /* phy_detach_internal() does all of the cleanup below */ + phy_detach_internal(phydev, false); return err; error_module_put: diff --git a/include/linux/phy.h b/include/linux/phy.h index 5f8d65868e0f..3d8afe6b7f1c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -376,6 +376,24 @@ struct mii_bus { int regnum, u16 val); /** @reset: Perform a reset of the bus */ int (*reset)(struct mii_bus *bus); + /** + * @notify_phy_attach: Perform post-attach handling for MDIO bus + * drivers. Optional and independent of @notify_phy_detach. Called + * in phy_attach_direct() right before phy_resume(). Runs in process + * context, may sleep and may be called with RTNL held. Must not + * acquire or rely on RTNL. Returns 0 on success or negative errno + * on failure. Must unwind its own state on error as attachment is + * aborted. + */ + int (*notify_phy_attach)(struct phy_device *phydev); + /** + * @notify_phy_detach: Perform pre-detach handling for MDIO bus + * drivers. Optional and independent of @notify_phy_attach. Called + * in phy_detach() right after phy_suspend(). Runs in process context, + * may sleep and may be called with RTNL held. Must not acquire or + * rely on RTNL. + */ + void (*notify_phy_detach)(struct phy_device *phydev); /** @stats: Statistic counters per device on the bus */ struct mdio_bus_stats stats[PHY_MAX_ADDR]; From fe7a07ff5194e3b0168ca65c5e0ebde689eb73a9 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:32 +0200 Subject: [PATCH 0092/2126] net: mdio: realtek-rtl9300: suppress sysfs bind/unbind attributes The Realtek MDIO driver relies on devm managed resources for lifetime management and allocates its internal central controller structure otto_emdio_priv via devm_kzalloc(). This can lead to a use-after-free in the following sitauation: - If the driver is removed or unbound via sysfs the controller devm cleanup is triggered immediately. A corrupt devicetree might produce a load failure and a cleanup too. - However the MDIO buses are allocated with devm_mdiobus_alloc_size() and are reference counted. So if a MAC driver still holds a reference to a PHY device on the bus, the mii_bus will remain alive. - Any action that is run for the buses afterwards still relies on the availability of the central priv structure. This will access already freed memory. There are multiple mitigations to choose from - Clone all controller->priv data into the bus->priv structure. - disable sysfs bind/unbind attributes - Check for "bus->state != MDIOBUS_REGISTERED" in all callbacks This SoC-integrated MDIO controller cannot be physically hot-plugged and manual unbinding gives no benefit. The driver is usually integrated into the kernel and not loaded as a module. Avoid a complex driver rewrite (data duplication) for now and set suppress_bind_attrs to true to prevent unbinding via sysfs. This mitigates issues for the known use cases. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-7-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 69565a87f99d..7de8adec243b 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -844,6 +844,7 @@ static struct platform_driver otto_emdio_driver = { .driver = { .name = "mdio-rtl9300", .of_match_table = otto_emdio_ids, + .suppress_bind_attrs = true, }, }; From ee18e22c63424ed9eddacaa3b4480413e29862bc Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:33 +0200 Subject: [PATCH 0093/2126] net: mdio: realtek-rtl9300: Configure hardware polling during probing During PHY probing and configuration complex configuration sequences might be issued and firmware might be loaded. Hardware polling can interfere badly with that. E.g. a hardware polling MMD c45 over c22 request might break an ongoing firmware loading sequence. To avoid such issues the polling of the Realtek Otto switches can be (de)activated with one or two 32 bit mask registers. Each bit enables (=1) or disables (=0) the polling of the corresponding port. Make use of this as follows: - Disable polling for all ports when the MDIO driver starts. - Reenable polling just after the PHY has been attached. - Disable polling just before the PHY is being detached. This synchronizes the kernel and hardware polling to some extent. It gracefully handles deferred probing of PHYs in case the driver is loaded asynchronously during boot. Additionally it brings the hardware polling into a consistent operation mode for devices where U-Boot does not take care. Important notes about the implementation: Realtek is very inconsistent about its register naming. RTL930x uses SMI_POLL_CTRL for polling control while it is SMI_PORT_POLLING_CTRL on RTL931x. Keep these vendor names. These devices do not support power management for the whole system. So mdio_bus_phy_resume() is not used and it is not required to disable/enable hardware polling for that usecase. These devices have no CPU MAC to PHY design. Thus abort phy_attach() in case PHYs are not mapped to valid switch ports. All MDIO bus commands will fail afterwards, leaving it in an unusable state. Enabling/disabling hardware polling is a simple regmap bit access. For this it is enough to rely on the regmap internal lock. This polling enabling/disabling does not solve the current inability of the driver to handle C45-over-C22 access during normal operation. For all existing designs this is not needed. [1] https://github.com/openwrt/openwrt/blob/main/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c#L818 [2] https://lore.kernel.org/netdev/680696024a8648535ce6dee771fe4de67802e0e8.1769053496.git.daniel@makrotopia.org/ Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-8-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 7de8adec243b..a925640290cb 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -146,6 +146,7 @@ #define RTL9300_PHY_CTRL_INDATA GENMASK(31, 16) #define RTL9300_PHY_CTRL_DATA GENMASK(15, 0) #define RTL9300_SMI_ACCESS_PHY_CTRL_3 0xcb7c +#define RTL9300_SMI_POLL_CTRL 0xca90 #define RTL9300_SMI_PORT0_5_ADDR_CTRL 0xcb80 #define RTL9310_NUM_BUSES 4 @@ -171,6 +172,7 @@ #define RTL9310_PHY_CTRL_INDATA GENMASK(15, 0) #define RTL9310_SMI_INDRT_ACCESS_MMD_CTRL 0x0c18 #define RTL9310_SMI_PORT_ADDR_CTRL 0x0c74 +#define RTL9310_SMI_PORT_POLLING_CTRL 0x0ccc #define RTL9310_SMI_PORT_POLLING_SEL 0x0c9c #define PHY_CTRL_CMD BIT(0) @@ -218,6 +220,7 @@ struct otto_emdio_info { u8 num_buses; u8 num_ports; u16 num_pages; + u32 poll_ctrl; int (*setup_controller)(struct otto_emdio_priv *priv); int (*read_c22)(struct mii_bus *bus, int port, int regnum, u32 *value); int (*read_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u32 *value); @@ -253,6 +256,12 @@ static struct otto_emdio_priv *otto_emdio_bus_to_priv(struct mii_bus *bus) return chan->priv; } +static int otto_emdio_set_port_polling(struct otto_emdio_priv *priv, int port, bool active) +{ + return regmap_assign_bits(priv->regmap, priv->info->poll_ctrl + (port / 32) * 4, + BIT(port % 32), active); +} + static int otto_emdio_run_cmd(struct mii_bus *bus, u32 cmd, struct otto_emdio_cmd_regs *cmd_data) { @@ -596,6 +605,36 @@ static int otto_emdio_9310_setup_controller(struct otto_emdio_priv *priv) return 0; } +static int otto_emdio_notify_phy_attach(struct phy_device *phydev) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(phydev->mdio.bus); + int port = otto_emdio_phy_to_port(phydev->mdio.bus, phydev->mdio.addr); + + if (port < 0) { + /* All subsequent bus operations will fail */ + phydev_err(phydev, "PHY is not mapped to a valid switch port\n"); + return port; + } + + return otto_emdio_set_port_polling(priv, port, true); +} + +static void otto_emdio_notify_phy_detach(struct phy_device *phydev) +{ + struct mii_bus *bus = phydev->mdio.bus; + struct otto_emdio_priv *priv; + int port; + + priv = otto_emdio_bus_to_priv(phydev->mdio.bus); + port = otto_emdio_phy_to_port(phydev->mdio.bus, phydev->mdio.addr); + + if (port < 0) + return; + + if (otto_emdio_set_port_polling(priv, port, false)) + dev_err(bus->parent, "failed to disable polling for port %d\n", port); +} + static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv, struct fwnode_handle *node) { @@ -625,6 +664,9 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv bus->write = otto_emdio_write_c22; } bus->parent = dev; + bus->notify_phy_attach = otto_emdio_notify_phy_attach; + bus->notify_phy_detach = otto_emdio_notify_phy_detach; + chan = bus->priv; chan->mdio_bus = mdio_bus; chan->priv = priv; @@ -741,6 +783,19 @@ put_nodes: return err; } +static int otto_emdio_init_polling(struct otto_emdio_priv *priv) +{ + int err; + + for (int port = 0; port < priv->info->num_ports; port++) { + err = otto_emdio_set_port_polling(priv, port, false); + if (err) + return err; + } + + return 0; +} + static int otto_emdio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -760,6 +815,10 @@ static int otto_emdio_probe(struct platform_device *pdev) if (IS_ERR(priv->regmap)) return PTR_ERR(priv->regmap); + err = otto_emdio_init_polling(priv); + if (err) + return err; + platform_set_drvdata(pdev, priv); err = otto_emdio_map_ports(dev); @@ -800,6 +859,7 @@ static const struct otto_emdio_info otto_emdio_9300_info = { .num_buses = RTL9300_NUM_BUSES, .num_ports = RTL9300_NUM_PORTS, .num_pages = RTL9300_NUM_PAGES, + .poll_ctrl = RTL9300_SMI_POLL_CTRL, .setup_controller = otto_emdio_9300_setup_controller, .read_c22 = otto_emdio_9300_read_c22, .read_c45 = otto_emdio_9300_read_c45, @@ -825,6 +885,7 @@ static const struct otto_emdio_info otto_emdio_9310_info = { .num_buses = RTL9310_NUM_BUSES, .num_pages = RTL9310_NUM_PAGES, .num_ports = RTL9310_NUM_PORTS, + .poll_ctrl = RTL9310_SMI_PORT_POLLING_CTRL, .setup_controller = otto_emdio_9310_setup_controller, .read_c22 = otto_emdio_9310_read_c22, .read_c45 = otto_emdio_9310_read_c45, From cc3cb8db1eef9fbe6f2c520312cf6384cf2c2ce7 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:34 +0200 Subject: [PATCH 0094/2126] net: mdio: realtek-rtl9300: Add page tracking The hardware polling unit of the Realtek switches has a very special handling for c22 PHY register 31 (aka Realtek page register) in place. - On the RTL838x it is permanently reset to zero. - On other devices there is some magic saving/restoring (aka parking) in the background in place. This makes access to PHYs a gamble. It is vital to keep the polling alive so the MAC layer can rely on consistent data. Intercept access to c22 register 31 and handle it internally. Store the desired value for each port in the driver. When issuing hardware access to other registers add the page to the command towards the controller. Given this, the hardware will run two c22 commands that are not interrupted by polling. ... hardware poll ... phy_write(phy, 31, page) phy_write(phy, reg, value) ... hardware poll ... Looking at this implementation one might argue that disabling/enabling polling might be a cleaner solution. But one must remember that - This driver differentiates clearly between C22 and C45 buses. During probing it enables only one of the protocols for a bus. - All known devices run RTL8218 (B/D/E) or RTL8214FC on 1G - RTL839x gives link flapping when deactivating polling for a port So a solution for a Realtek-only ecosystem is required. This commit copies the downstream-proven driver-only page handling patch without any new MDIO callbacks and is the lowest common denominator. If a non-Realtek PHY is identified on a c22 bus the attachment aborts. It should be noted that bus scan runs with the page handling already in place before the check in notify_phy_attach(). This is accepted for now. Remark: To keep this simple, writes to register 31 are only accepted if they are lower than the device specific raw page - 0..4094/8190. Otherwise -EINVAL is returned. Under the above assumption (Only 1G Realtek PHYs on a c22 bus) this is no limitation. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-9-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 46 +++++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index a925640290cb..d6027062e452 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -179,6 +179,9 @@ #define PHY_CTRL_MMD_DEVAD GENMASK(20, 16) #define PHY_CTRL_MMD_REG GENMASK(15, 0) +#define RTL_VENDOR_ID 0x001cc800 +#define RTL_PAGE_SELECT 31 + #define MAP_ADDRS_PER_REG 6 #define MAP_BITS_PER_ADDR 5 #define MAP_BITS_PER_BUS 2 @@ -204,6 +207,7 @@ struct otto_emdio_priv { struct regmap *regmap; struct mutex lock; /* protect HW access */ DECLARE_BITMAP(valid_ports, MAX_PORTS); + u16 page[MAX_PORTS]; u8 smi_bus[MAX_PORTS]; u8 smi_addr[MAX_PORTS]; bool smi_bus_is_c45[MAX_SMI_BUSSES]; @@ -355,7 +359,7 @@ static int otto_emdio_9300_read_c22(struct mii_bus *bus, int port, int regnum, u struct otto_emdio_cmd_regs cmd_data = { .c22_data = FIELD_PREP(RTL9300_PHY_CTRL_REG_ADDR, regnum) | FIELD_PREP(RTL9300_PHY_CTRL_PARK_PAGE, 0x1f) | - FIELD_PREP(RTL9300_PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)), + FIELD_PREP(RTL9300_PHY_CTRL_MAIN_PAGE, priv->page[port]), .io_data = FIELD_PREP(RTL9300_PHY_CTRL_INDATA, port), }; @@ -369,7 +373,7 @@ static int otto_emdio_9300_write_c22(struct mii_bus *bus, int port, int regnum, struct otto_emdio_cmd_regs cmd_data = { .c22_data = FIELD_PREP(RTL9300_PHY_CTRL_REG_ADDR, regnum) | FIELD_PREP(RTL9300_PHY_CTRL_PARK_PAGE, 0x1f) | - FIELD_PREP(RTL9300_PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)), + FIELD_PREP(RTL9300_PHY_CTRL_MAIN_PAGE, priv->page[port]), .io_data = FIELD_PREP(RTL9300_PHY_CTRL_INDATA, value), .port_mask_low = BIT(port), }; @@ -409,7 +413,7 @@ static int otto_emdio_9310_read_c22(struct mii_bus *bus, int port, int regnum, u struct otto_emdio_cmd_regs cmd_data = { .broadcast = FIELD_PREP(RTL9310_BC_PORT_ID, port), .c22_data = FIELD_PREP(RTL9310_PHY_CTRL_REG_ADDR, regnum) | - FIELD_PREP(RTL9310_PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)), + FIELD_PREP(RTL9310_PHY_CTRL_MAIN_PAGE, priv->page[port]), }; return otto_emdio_read_cmd(bus, RTL9310_PHY_CTRL_TYPE_C22, &cmd_data, @@ -421,7 +425,7 @@ static int otto_emdio_9310_write_c22(struct mii_bus *bus, int port, int regnum, struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); struct otto_emdio_cmd_regs cmd_data = { .c22_data = FIELD_PREP(RTL9310_PHY_CTRL_REG_ADDR, regnum) | - FIELD_PREP(RTL9310_PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)), + FIELD_PREP(RTL9310_PHY_CTRL_MAIN_PAGE, priv->page[port]), .io_data = FIELD_PREP(RTL9310_PHY_CTRL_INDATA, value), .port_mask_high = (u32)(BIT_ULL(port) >> 32), .port_mask_low = (u32)(BIT_ULL(port)), @@ -473,8 +477,12 @@ static int otto_emdio_read_c22(struct mii_bus *bus, int phy_id, int regnum) if (port < 0) return port; - scoped_guard(mutex, &priv->lock) + scoped_guard(mutex, &priv->lock) { + if (regnum == RTL_PAGE_SELECT) + return priv->page[port]; + ret = priv->info->read_c22(bus, port, regnum, &value); + } return ret ? ret : value; } @@ -495,8 +503,17 @@ static int otto_emdio_write_c22(struct mii_bus *bus, int phy_id, int regnum, if (port < 0) return port; - scoped_guard(mutex, &priv->lock) + scoped_guard(mutex, &priv->lock) { + if (regnum == RTL_PAGE_SELECT) { + if (value >= RAW_PAGE(priv)) + return -EINVAL; + + priv->page[port] = value; + return 0; + } + ret = priv->info->write_c22(bus, port, regnum, value); + } return ret; } @@ -607,8 +624,9 @@ static int otto_emdio_9310_setup_controller(struct otto_emdio_priv *priv) static int otto_emdio_notify_phy_attach(struct phy_device *phydev) { - struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(phydev->mdio.bus); int port = otto_emdio_phy_to_port(phydev->mdio.bus, phydev->mdio.addr); + struct otto_emdio_chan *chan = phydev->mdio.bus->priv; + struct otto_emdio_priv *priv = chan->priv; if (port < 0) { /* All subsequent bus operations will fail */ @@ -616,6 +634,16 @@ static int otto_emdio_notify_phy_attach(struct phy_device *phydev) return port; } + /* "sync" page in case of previously failed attachment */ + scoped_guard(mutex, &priv->lock) + priv->page[port] = 0; + + if (!priv->smi_bus_is_c45[chan->mdio_bus] && + !phy_id_compare_vendor(phydev->phy_id, RTL_VENDOR_ID)) { + phydev_err(phydev, "Only Realtek PHYs allowed on C22 bus\n"); + return -EOPNOTSUPP; + } + return otto_emdio_set_port_polling(priv, port, true); } @@ -631,6 +659,10 @@ static void otto_emdio_notify_phy_detach(struct phy_device *phydev) if (port < 0) return; + /* "sync" page for next attachment */ + scoped_guard(mutex, &priv->lock) + priv->page[port] = 0; + if (otto_emdio_set_port_polling(priv, port, false)) dev_err(bus->parent, "failed to disable polling for port %d\n", port); } From 6be4be074be82ea1196bec504bf1490b6fe6037f Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:35 +0200 Subject: [PATCH 0095/2126] net: mdio: realtek-rtl9300: Increase MDIO timeout RTL838x devices with 28 ports produce PHY access timeout errors during one of three boots while waiting for MDIO command completion. This is currently set to 1ms. Background: Access to the Realtek Otto ethernet MDIO bus must wait for a free slot between two hardware polls. The polling sequence consists of at least 17 commands on the RTL838x devices. This delay can be nicely seen when disabling polling completely. The following times are measured on a bus running on the default 2.5MHz. Time measured is from the last register write that sets the command-start-bit until the hardware responds with the command-finished-bit set. - average c22 read with polling enabled on all ports: ~380us - average c22 read with polling enabled on one port: ~380us - average c22 read with polling completely disabled: ~180us For this bus frequency the bare hardware runtime for a single command (32 bit preamble + 32 bit data) is ~25us. So the hardware adds quite some overhead. On top of this comes the fact that the RTL838x devices are low on resources (500Mhz 4Kec core with 16K cache). Increase the timeout to 10ms to be on the safe side. Remark! In a future patch the bus clock frequency will be made configurable with a minimum frequency of 1.25MHz. Setting this (e.g. for debugging purposes) doubles the command run times but will safely stay below 10ms. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-10-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index d6027062e452..ae7ba86e90b9 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -274,9 +274,9 @@ static int otto_emdio_run_cmd(struct mii_bus *bus, u32 cmd, u32 cmdstate; int ret; - /* Defensive pre check just in case something goes horrible wrong */ + /* Defensive pre check just in case something goes horribly wrong */ ret = regmap_read_poll_timeout(priv->regmap, info->cmd_regs.c22_data, - cmdstate, !(cmdstate & PHY_CTRL_CMD), 10, 1000); + cmdstate, !(cmdstate & PHY_CTRL_CMD), 10, 10000); if (ret) return ret; @@ -316,7 +316,7 @@ static int otto_emdio_run_cmd(struct mii_bus *bus, u32 cmd, return ret; ret = regmap_read_poll_timeout(priv->regmap, info->cmd_regs.c22_data, - cmdstate, !(cmdstate & PHY_CTRL_CMD), 10, 1000); + cmdstate, !(cmdstate & PHY_CTRL_CMD), 10, 10000); if (ret) return ret; From cc7a5bfaea142ebaa84bbcd8ddd14a3b21cc5bd5 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:36 +0200 Subject: [PATCH 0096/2126] net: mdio: realtek-rtl9300: Open up C22 and C45 space in parallel Until now the MDIO driver supports either access to the C22 or to the C45 address space of the PHYs. This is due to the fact that the polling configuration favours one of the address spaces and limits access to the other space. E.g. when polling is set to C22 most of the C45 space can not be accessed. There are however some exceptions from that. EEE register access is allowed independently from the polling mode [1]. As the downstream driver already allows parallel C22/C45 access [2] do this in upstream too. [1] https://github.com/openwrt/openwrt/blob/main/target/linux/realtek/files-6.18/drivers/net/phy/realtek/realtek_multiport.c#L349 [2] https://github.com/openwrt/openwrt/blob/main/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c#L1072 Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-11-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index ae7ba86e90b9..b90972c1dc6a 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -688,13 +688,10 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv return -ENOMEM; bus->name = "Realtek Switch MDIO Bus"; - if (priv->smi_bus_is_c45[mdio_bus]) { - bus->read_c45 = otto_emdio_read_c45; - bus->write_c45 = otto_emdio_write_c45; - } else { - bus->read = otto_emdio_read_c22; - bus->write = otto_emdio_write_c22; - } + bus->read_c45 = otto_emdio_read_c45; + bus->write_c45 = otto_emdio_write_c45; + bus->read = otto_emdio_read_c22; + bus->write = otto_emdio_write_c22; bus->parent = dev; bus->notify_phy_attach = otto_emdio_notify_phy_attach; bus->notify_phy_detach = otto_emdio_notify_phy_detach; From 6ab6cb66b3b94239ae1007de4185c17756040279 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:37 +0200 Subject: [PATCH 0097/2126] net: mdio: realtek-rtl9300: Add support for RTL838x The MDIO driver has been prepared for multiple device support. Add all required bits for the RTL838x (aka maple) series. This is straightforward but some things are worth mentioning. - The device has a lot in common with the RTL930x series. It has 28 ports, 4096 (Realtek) pages and 4 MMIO registers. With this a lot of the existing RTL9300 defines could be reused. But to avoid confusion and for better readability duplicate the defines with a proper prefix. - The MDIO engine has no fail bit. Thus the mask is set to zero. - There is only one SMI bus for 1G PHYs. No bus_map_base register exists. - The setup_controller() function needs no C45 configuration as polling only works in C22 mode - The PHY access must be activated by a special register flag. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-12-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 108 ++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index b90972c1dc6a..57ab89afb9e5 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -126,6 +126,28 @@ #include #include +#define RTL8380_NUM_BUSES 1 +#define RTL8380_NUM_PAGES 4096 +#define RTL8380_NUM_PORTS 28 +#define RTL8380_SMI_GLB_CTRL 0xa100 +#define RTL8380_SMI_PHY_PATCH_DONE BIT(15) +#define RTL8380_SMI_ACCESS_PHY_CTRL_0 0xa1b8 +#define RTL8380_SMI_ACCESS_PHY_CTRL_1 0xa1bc +#define RTL8380_PHY_CTRL_REG_ADDR GENMASK(24, 20) +#define RTL8380_PHY_CTRL_PARK_PAGE GENMASK(19, 15) +#define RTL8380_PHY_CTRL_MAIN_PAGE GENMASK(14, 3) +#define RTL8380_PHY_CTRL_WRITE BIT(2) +#define RTL8380_PHY_CTRL_READ 0 +#define RTL8380_PHY_CTRL_TYPE_C45 BIT(1) +#define RTL8380_PHY_CTRL_TYPE_C22 0 +#define RTL8380_PHY_CTRL_FAIL 0 /* no fail indicator */ +#define RTL8380_SMI_ACCESS_PHY_CTRL_2 0xa1c0 +#define RTL8380_PHY_CTRL_INDATA GENMASK(31, 16) +#define RTL8380_PHY_CTRL_DATA GENMASK(15, 0) +#define RTL8380_SMI_ACCESS_PHY_CTRL_3 0xa1c4 +#define RTL8380_SMI_POLL_CTRL 0xa17c +#define RTL8380_SMI_PORT0_5_ADDR_CTRL 0xa1c8 + #define RTL9300_NUM_BUSES 4 #define RTL9300_NUM_PAGES 4096 #define RTL9300_NUM_PORTS 28 @@ -353,6 +375,60 @@ static int otto_emdio_write_cmd(struct mii_bus *bus, u32 cmd, return otto_emdio_run_cmd(bus, cmd | priv->info->cmd_write, cmd_data); } +static int otto_emdio_8380_read_c22(struct mii_bus *bus, int port, int regnum, u32 *value) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_cmd_regs cmd_data = { + .c22_data = FIELD_PREP(RTL8380_PHY_CTRL_REG_ADDR, regnum) | + FIELD_PREP(RTL8380_PHY_CTRL_PARK_PAGE, 0x1f) | + FIELD_PREP(RTL8380_PHY_CTRL_MAIN_PAGE, priv->page[port]), + .io_data = FIELD_PREP(RTL8380_PHY_CTRL_INDATA, port), + }; + + return otto_emdio_read_cmd(bus, RTL8380_PHY_CTRL_TYPE_C22, &cmd_data, + RTL8380_PHY_CTRL_DATA, value); +} + +static int otto_emdio_8380_write_c22(struct mii_bus *bus, int port, int regnum, u16 value) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_cmd_regs cmd_data = { + .c22_data = FIELD_PREP(RTL8380_PHY_CTRL_REG_ADDR, regnum) | + FIELD_PREP(RTL8380_PHY_CTRL_PARK_PAGE, 0x1f) | + FIELD_PREP(RTL8380_PHY_CTRL_MAIN_PAGE, priv->page[port]), + .io_data = FIELD_PREP(RTL8380_PHY_CTRL_INDATA, value), + .port_mask_low = BIT(port), + }; + + return otto_emdio_write_cmd(bus, RTL8380_PHY_CTRL_TYPE_C22, &cmd_data); +} + +static int otto_emdio_8380_read_c45(struct mii_bus *bus, int port, + int dev_addr, int regnum, u32 *value) +{ + struct otto_emdio_cmd_regs cmd_data = { + .c45_data = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) | + FIELD_PREP(PHY_CTRL_MMD_REG, regnum), + .io_data = FIELD_PREP(RTL8380_PHY_CTRL_INDATA, port), + }; + + return otto_emdio_read_cmd(bus, RTL8380_PHY_CTRL_TYPE_C45, &cmd_data, + RTL8380_PHY_CTRL_DATA, value); +} + +static int otto_emdio_8380_write_c45(struct mii_bus *bus, int port, + int dev_addr, int regnum, u16 value) +{ + struct otto_emdio_cmd_regs cmd_data = { + .c45_data = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) | + FIELD_PREP(PHY_CTRL_MMD_REG, regnum), + .io_data = FIELD_PREP(RTL8380_PHY_CTRL_INDATA, value), + .port_mask_low = BIT(port), + }; + + return otto_emdio_write_cmd(bus, RTL8380_PHY_CTRL_TYPE_C45, &cmd_data); +} + static int otto_emdio_9300_read_c22(struct mii_bus *bus, int port, int regnum, u32 *value) { struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); @@ -586,6 +662,15 @@ static int otto_emdio_setup_topology(struct otto_emdio_priv *priv) return 0; } +static int otto_emdio_8380_setup_controller(struct otto_emdio_priv *priv) +{ + /* + * PHY_PATCH_DONE enables PHY control via SoC. This is required for PHY access, including + * patching and must be set before the PHYs are probed. + */ + return regmap_set_bits(priv->regmap, RTL8380_SMI_GLB_CTRL, RTL8380_SMI_PHY_PATCH_DONE); +} + static int otto_emdio_9300_setup_controller(struct otto_emdio_priv *priv) { u32 glb_ctrl_mask = 0, glb_ctrl_val = 0; @@ -873,6 +958,28 @@ static int otto_emdio_probe(struct platform_device *pdev) return 0; } +static const struct otto_emdio_info otto_emdio_8380_info = { + .addr_map_base = RTL8380_SMI_PORT0_5_ADDR_CTRL, + .cmd_fail = RTL8380_PHY_CTRL_FAIL, + .cmd_read = RTL8380_PHY_CTRL_READ, + .cmd_write = RTL8380_PHY_CTRL_WRITE, + .cmd_regs = { + .c22_data = RTL8380_SMI_ACCESS_PHY_CTRL_1, + .c45_data = RTL8380_SMI_ACCESS_PHY_CTRL_3, + .io_data = RTL8380_SMI_ACCESS_PHY_CTRL_2, + .port_mask_low = RTL8380_SMI_ACCESS_PHY_CTRL_0, + }, + .num_buses = RTL8380_NUM_BUSES, + .num_pages = RTL8380_NUM_PAGES, + .num_ports = RTL8380_NUM_PORTS, + .poll_ctrl = RTL8380_SMI_POLL_CTRL, + .setup_controller = otto_emdio_8380_setup_controller, + .read_c22 = otto_emdio_8380_read_c22, + .read_c45 = otto_emdio_8380_read_c45, + .write_c22 = otto_emdio_8380_write_c22, + .write_c45 = otto_emdio_8380_write_c45, +}; + static const struct otto_emdio_info otto_emdio_9300_info = { .addr_map_base = RTL9300_SMI_PORT0_5_ADDR_CTRL, .bus_map_base = RTL9300_SMI_PORT0_15_POLLING_SEL, @@ -923,6 +1030,7 @@ static const struct otto_emdio_info otto_emdio_9310_info = { }; static const struct of_device_id otto_emdio_ids[] = { + { .compatible = "realtek,rtl8380-mdio", .data = &otto_emdio_8380_info }, { .compatible = "realtek,rtl9301-mdio", .data = &otto_emdio_9300_info }, { .compatible = "realtek,rtl9311-mdio", .data = &otto_emdio_9310_info }, {} From 11b8be84ccafc946c5b3124ad41988e9243309a0 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:38 +0200 Subject: [PATCH 0098/2126] net: mdio: realtek-rtl9300: Add support for RTL839x The MDIO driver has been prepared for multiple device support. Add all required bits for the RTL839x (aka cypress) series. This is straightforward but some things are worth mentioning. - The device has a lot in common with the RTL931x series. It has 8192 (Realtek) pages and 7 MMIO registers. - There are two SMI buses for 1G PHYs. Neither the bus nor address map registers exist. - The hardware has not much to configure. So the setup_controller() function is not needed. - The bit specific registers (polling & port_mask) are 2x32 bit wide. The ports 0..31 got to and the ports 32..51 go to . - C22 read/write functions must be called with PARK_PAGE = 0. Keep code clean and avoid setting it to zero, matching the behavior of the RTL9310 logic. - As per SDK the broadcast register allows to write to multiple ports at the same time. Unlike RTL9310 where this is filled with a bit mask for the current port RTL8390 does not use it for normal reads/writes. It is simply set to 0 like the SDK does. - The SDK fills the EXT_PAGE register with 0x1ff for C22 access and with 0x0 for C45 access. The reason for this is currently unknown and a meaningful name can not be given. Align the driver coding with the RTL9300_PHY_CTRL_PARK_PAGE settings and simply fill the hardcoded value. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-13-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 57ab89afb9e5..86b2040fa333 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -148,6 +148,28 @@ #define RTL8380_SMI_POLL_CTRL 0xa17c #define RTL8380_SMI_PORT0_5_ADDR_CTRL 0xa1c8 +#define RTL8390_NUM_BUSES 2 +#define RTL8390_NUM_PAGES 8192 +#define RTL8390_NUM_PORTS 52 +#define RTL8390_BCAST_PHYID_CTRL 0x03ec +#define RTL8390_PHYREG_ACCESS_CTRL 0x03dc +#define RTL8390_PHY_CTRL_REG_ADDR GENMASK(9, 5) +#define RTL8390_PHY_CTRL_MAIN_PAGE GENMASK(22, 10) +#define RTL8390_PHY_CTRL_FAIL BIT(1) +#define RTL8390_PHY_CTRL_WRITE BIT(3) +#define RTL8390_PHY_CTRL_READ 0 +#define RTL8390_PHY_CTRL_TYPE_C45 BIT(2) +#define RTL8390_PHY_CTRL_TYPE_C22 0 +#define RTL8390_PHYREG_CTRL 0x03e0 +#define RTL8390_PHY_CTRL_EXT_PAGE GENMASK(8, 0) +#define RTL8390_PHYREG_DATA_CTRL 0x03f0 +#define RTL8390_PHY_CTRL_INDATA GENMASK(31, 16) +#define RTL8390_PHY_CTRL_DATA GENMASK(15, 0) +#define RTL8390_PHYREG_MMD_CTRL 0x03f4 +#define RTL8390_PHYREG_PORT_CTRL_LOW 0x03e4 +#define RTL8390_PHYREG_PORT_CTRL_HIGH 0x03e8 +#define RTL8390_SMI_PORT_POLLING_CTRL 0x03fc + #define RTL9300_NUM_BUSES 4 #define RTL9300_NUM_PAGES 4096 #define RTL9300_NUM_PORTS 28 @@ -429,6 +451,62 @@ static int otto_emdio_8380_write_c45(struct mii_bus *bus, int port, return otto_emdio_write_cmd(bus, RTL8380_PHY_CTRL_TYPE_C45, &cmd_data); } +static int otto_emdio_8390_read_c22(struct mii_bus *bus, int port, int regnum, u32 *value) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_cmd_regs cmd_data = { + .c22_data = FIELD_PREP(RTL8390_PHY_CTRL_REG_ADDR, regnum) | + FIELD_PREP(RTL8390_PHY_CTRL_MAIN_PAGE, priv->page[port]), + .ext_page = FIELD_PREP(RTL8390_PHY_CTRL_EXT_PAGE, 0x1ff), + .io_data = FIELD_PREP(RTL8390_PHY_CTRL_INDATA, port), + }; + + return otto_emdio_read_cmd(bus, RTL8390_PHY_CTRL_TYPE_C22, &cmd_data, + RTL8390_PHY_CTRL_DATA, value); +} + +static int otto_emdio_8390_write_c22(struct mii_bus *bus, int port, int regnum, u16 value) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_cmd_regs cmd_data = { + .c22_data = FIELD_PREP(RTL8390_PHY_CTRL_REG_ADDR, regnum) | + FIELD_PREP(RTL8390_PHY_CTRL_MAIN_PAGE, priv->page[port]), + .ext_page = FIELD_PREP(RTL8390_PHY_CTRL_EXT_PAGE, 0x1ff), + .io_data = FIELD_PREP(RTL8390_PHY_CTRL_INDATA, value), + .port_mask_high = (u32)(BIT_ULL(port) >> 32), + .port_mask_low = (u32)(BIT_ULL(port)), + }; + + return otto_emdio_write_cmd(bus, RTL8390_PHY_CTRL_TYPE_C22, &cmd_data); +} + +static int otto_emdio_8390_read_c45(struct mii_bus *bus, int port, + int dev_addr, int regnum, u32 *value) +{ + struct otto_emdio_cmd_regs cmd_data = { + .c45_data = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) | + FIELD_PREP(PHY_CTRL_MMD_REG, regnum), + .io_data = FIELD_PREP(RTL8390_PHY_CTRL_INDATA, port), + }; + + return otto_emdio_read_cmd(bus, RTL8390_PHY_CTRL_TYPE_C45, &cmd_data, + RTL8390_PHY_CTRL_DATA, value); +} + +static int otto_emdio_8390_write_c45(struct mii_bus *bus, int port, + int dev_addr, int regnum, u16 value) +{ + struct otto_emdio_cmd_regs cmd_data = { + .c45_data = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) | + FIELD_PREP(PHY_CTRL_MMD_REG, regnum), + .io_data = FIELD_PREP(RTL8390_PHY_CTRL_INDATA, value), + .port_mask_high = (u32)(BIT_ULL(port) >> 32), + .port_mask_low = (u32)(BIT_ULL(port)), + }; + + return otto_emdio_write_cmd(bus, RTL8390_PHY_CTRL_TYPE_C45, &cmd_data); +} + static int otto_emdio_9300_read_c22(struct mii_bus *bus, int port, int regnum, u32 *value) { struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); @@ -980,6 +1058,29 @@ static const struct otto_emdio_info otto_emdio_8380_info = { .write_c45 = otto_emdio_8380_write_c45, }; +static const struct otto_emdio_info otto_emdio_8390_info = { + .cmd_fail = RTL8390_PHY_CTRL_FAIL, + .cmd_read = RTL8390_PHY_CTRL_READ, + .cmd_write = RTL8390_PHY_CTRL_WRITE, + .cmd_regs = { + .broadcast = RTL8390_BCAST_PHYID_CTRL, + .c22_data = RTL8390_PHYREG_ACCESS_CTRL, + .c45_data = RTL8390_PHYREG_MMD_CTRL, + .ext_page = RTL8390_PHYREG_CTRL, + .io_data = RTL8390_PHYREG_DATA_CTRL, + .port_mask_low = RTL8390_PHYREG_PORT_CTRL_LOW, + .port_mask_high = RTL8390_PHYREG_PORT_CTRL_HIGH, + }, + .num_buses = RTL8390_NUM_BUSES, + .num_pages = RTL8390_NUM_PAGES, + .num_ports = RTL8390_NUM_PORTS, + .poll_ctrl = RTL8390_SMI_PORT_POLLING_CTRL, + .read_c22 = otto_emdio_8390_read_c22, + .read_c45 = otto_emdio_8390_read_c45, + .write_c22 = otto_emdio_8390_write_c22, + .write_c45 = otto_emdio_8390_write_c45, +}; + static const struct otto_emdio_info otto_emdio_9300_info = { .addr_map_base = RTL9300_SMI_PORT0_5_ADDR_CTRL, .bus_map_base = RTL9300_SMI_PORT0_15_POLLING_SEL, @@ -1031,6 +1132,7 @@ static const struct otto_emdio_info otto_emdio_9310_info = { static const struct of_device_id otto_emdio_ids[] = { { .compatible = "realtek,rtl8380-mdio", .data = &otto_emdio_8380_info }, + { .compatible = "realtek,rtl8391-mdio", .data = &otto_emdio_8390_info }, { .compatible = "realtek,rtl9301-mdio", .data = &otto_emdio_9300_info }, { .compatible = "realtek,rtl9311-mdio", .data = &otto_emdio_9310_info }, {} From d4ce2cef189ef4c267d5bcec922f5d390a85bc22 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 31 Aug 2026 16:34:39 +0200 Subject: [PATCH 0099/2126] net: mdio: realtek-rtl9300: reword Kconfig and module description The Realtek MDIO driver has been enhanced to support multiple devices from the RTL83xx/RTL93xx series. Reword Kconfig and module description accordingly. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831143439.2404484-14-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/Kconfig | 4 ++-- drivers/net/mdio/mdio-realtek-rtl9300.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig index a05229838cb4..d44278f26fab 100644 --- a/drivers/net/mdio/Kconfig +++ b/drivers/net/mdio/Kconfig @@ -172,11 +172,11 @@ config MDIO_IPQ8064 interface units of the IPQ8064 SoC config MDIO_REALTEK_RTL9300 - tristate "Realtek RTL9300 MDIO interface support" + tristate "Realtek RTL83xx/RTL93xx MDIO interface support" depends on MACH_REALTEK_RTL || COMPILE_TEST help This driver supports the MDIO interface found in the Realtek - RTL9300 family of Ethernet switches with integrated SoC. + RTL83xx/RTL93xx family of Ethernet switches with integrated SoC. config MDIO_REGMAP tristate diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 86b2040fa333..11d078ef941c 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -1150,5 +1150,5 @@ static struct platform_driver otto_emdio_driver = { module_platform_driver(otto_emdio_driver); -MODULE_DESCRIPTION("RTL9300 MDIO driver"); +MODULE_DESCRIPTION("RTL83xx/RTL93xx MDIO driver"); MODULE_LICENSE("GPL"); From fbf5096f540dd9257a3eb372f8c9daac7e3a375b Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:37:55 +0100 Subject: [PATCH 0100/2126] net: dsa: mt7530: move MDIO bus locking into regmap The switch register regmap was created with .disable_locking = true, relying on callers to manually lock the MDIO bus. Move the locking into the regmap using .lock/.unlock callbacks, matching the PCS regmaps that already do this. This allows any code path reaching the regmap to be automatically protected. With regmap handling bus locking, the manual mt7530_mutex_lock/unlock calls in mt7530_write(), _mt7530_read(), mt7530_rmw() and mt7530_port_change_mtu() become redundant and are removed, as is the bus lock held across the ATC/VTCR command poll sequences. The handle_mask_sync callback added by commit dd52b3df25ed ("net: dsa: mt7530: serialize the regmap IRQ chip like every other user") to hold mt7530_mutex_lock() around the regmap-irq mask register write is likewise removed. With the regmap now self-locking, regmap-irq's default unmask_base sync is serialized on its own, and so are the status read, ack write and init_ack_masked write that had no hook, closing the gaps that commit left open. The per-device copy of the irq chip it needed goes away too. The MT7531 indirect PHY access functions need serialization of their multi-step register sequences, but no longer need to hold bus->mdio_lock across the whole operation. Switch them to reg_mutex. core_write()/core_rmw() are the only remaining callers of mt7530_mutex_lock(). They access TRGMII core PHY registers via the clause 22 MMD indirect protocol -- a separate register space that bypasses regmap and needs manual bus->mdio_lock protection. The lock removals are generated using the following semantic patch: // Collapse mt7530_write() now that regmap serialises bus access. @@ expression priv, reg, val; identifier ret; @@ { - int ret; - - mt7530_mutex_lock(priv); - - ret = mt7530_mii_write(priv, reg, val); - - mt7530_mutex_unlock(priv); - - return ret; + return mt7530_mii_write(priv, reg, val); } // Remove mt7530_mutex_lock/unlock around single regmap-based calls. @@ expression priv, reg, mask, set; @@ { - mt7530_mutex_lock(priv); - regmap_update_bits(priv->regmap, reg, mask, set); - - mt7530_mutex_unlock(priv); } @@ expression p; identifier val; @@ { - u32 val; - mt7530_mutex_lock(p->priv); - val = mt7530_mii_read(p->priv, p->reg); - mt7530_mutex_unlock(p->priv); - return val; + return mt7530_mii_read(p->priv, p->reg); } @@ expression priv; identifier val; @@ - mt7530_mutex_lock(priv); val = mt7530_mii_read(priv, MT7530_GMACCR); ... mt7530_mii_write(priv, MT7530_GMACCR, val); - mt7530_mutex_unlock(priv); // The ATC/VTCR command polls no longer need the bus lock held across // the poll and the status read-back. @@ expression priv, reg, cond; identifier ret, val; @@ - mt7530_mutex_lock(priv); - ret = regmap_read_poll_timeout(priv->regmap, reg, val, cond, 20, 20000); if (!ret) ret = regmap_read(priv->regmap, reg, &val); - - mt7530_mutex_unlock(priv); // The MT7531 indirect PHY sequences keep serialising themselves, but // against reg_mutex rather than the MDIO bus lock. @@ expression priv; identifier ret, val; @@ - mt7530_mutex_lock(priv); + mutex_lock(&priv->reg_mutex); ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val, ...); @@ expression priv; @@ out: - mt7530_mutex_unlock(priv); + mutex_unlock(&priv->reg_mutex); Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/6927a774b87238800de5d6c0c717b0afd02d320b.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530-mdio.c | 9 ++-- drivers/net/dsa/mt7530.c | 78 +++++------------------------------ 2 files changed, 17 insertions(+), 70 deletions(-) diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c index 784dd58a7158..422f785d2143 100644 --- a/drivers/net/dsa/mt7530-mdio.c +++ b/drivers/net/dsa/mt7530-mdio.c @@ -148,12 +148,14 @@ static const struct regmap_config regmap_config = { .val_bits = 32, .reg_stride = 4, .max_register = MT7530_CREV, - .disable_locking = true, + .lock = mt7530_mdio_regmap_lock, + .unlock = mt7530_mdio_regmap_unlock, }; static int mt7530_probe(struct mdio_device *mdiodev) { + struct regmap_config rc = regmap_config; struct mt7530_priv *priv; struct device_node *dn; int ret; @@ -207,8 +209,9 @@ mt7530_probe(struct mdio_device *mdiodev) return PTR_ERR(priv->io_pwr); } - priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, priv, - ®map_config); + rc.lock_arg = &priv->bus->mdio_lock; + priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, + priv, &rc); if (IS_ERR(priv->regmap)) return PTR_ERR(priv->regmap); diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 2b7be091c056..dbf70e5dd55f 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -188,29 +188,13 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg) static int mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val) { - int ret; - - mt7530_mutex_lock(priv); - - ret = mt7530_mii_write(priv, reg, val); - - mt7530_mutex_unlock(priv); - - return ret; + return mt7530_mii_write(priv, reg, val); } static u32 _mt7530_read(struct mt7530_dummy_poll *p) { - u32 val; - - mt7530_mutex_lock(p->priv); - - val = mt7530_mii_read(p->priv, p->reg); - - mt7530_mutex_unlock(p->priv); - - return val; + return mt7530_mii_read(p->priv, p->reg); } static u32 @@ -226,11 +210,7 @@ static void mt7530_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { - mt7530_mutex_lock(priv); - regmap_update_bits(priv->regmap, reg, mask, set); - - mt7530_mutex_unlock(priv); } static void @@ -257,15 +237,11 @@ mt7530_fdb_cmd(struct mt7530_priv *priv, enum mt7530_fdb_cmd cmd, u32 *rsp) if (ret) return ret; - mt7530_mutex_lock(priv); - ret = regmap_read_poll_timeout(priv->regmap, MT7530_ATC, val, !(val & ATC_BUSY), 20, 20000); if (!ret) ret = regmap_read(priv->regmap, MT7530_ATC, &val); - mt7530_mutex_unlock(priv); - if (ret < 0) { dev_err(priv->dev, "reset timeout\n"); return ret; @@ -560,7 +536,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, u32 reg, val; int ret; - mt7530_mutex_lock(priv); + mutex_lock(&priv->reg_mutex); ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -597,7 +573,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, ret = val & MT7531_MDIO_RW_DATA_MASK; out: - mt7530_mutex_unlock(priv); + mutex_unlock(&priv->reg_mutex); return ret; } @@ -609,7 +585,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, u32 val, reg; int ret; - mt7530_mutex_lock(priv); + mutex_lock(&priv->reg_mutex); ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -645,7 +621,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, } out: - mt7530_mutex_unlock(priv); + mutex_unlock(&priv->reg_mutex); return ret; } @@ -656,7 +632,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) int ret; u32 val; - mt7530_mutex_lock(priv); + mutex_lock(&priv->reg_mutex); ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -681,7 +657,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) ret = val & MT7531_MDIO_RW_DATA_MASK; out: - mt7530_mutex_unlock(priv); + mutex_unlock(&priv->reg_mutex); return ret; } @@ -693,7 +669,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, int ret; u32 reg; - mt7530_mutex_lock(priv); + mutex_lock(&priv->reg_mutex); ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, reg, !(reg & MT7531_PHY_ACS_ST), 20, 100000); @@ -717,7 +693,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, } out: - mt7530_mutex_unlock(priv); + mutex_unlock(&priv->reg_mutex); return ret; } @@ -1452,8 +1428,6 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) if (!dsa_is_cpu_port(ds, port)) return 0; - mt7530_mutex_lock(priv); - val = mt7530_mii_read(priv, MT7530_GMACCR); val &= ~MAX_RX_PKT_LEN_MASK; @@ -1473,8 +1447,6 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) mt7530_mii_write(priv, MT7530_GMACCR, val); - mt7530_mutex_unlock(priv); - return 0; } @@ -1642,15 +1614,11 @@ mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid) if (ret) return ret; - mt7530_mutex_lock(priv); - ret = regmap_read_poll_timeout(priv->regmap, MT7530_VTCR, val, !(val & VTCR_BUSY), 20, 20000); if (!ret) ret = regmap_read(priv->regmap, MT7530_VTCR, &val); - mt7530_mutex_unlock(priv); - if (ret < 0) { dev_err(priv->dev, "poll timeout\n"); return ret; @@ -2319,21 +2287,6 @@ static const struct regmap_irq mt7530_irqs[] = { REGMAP_IRQ_REG_LINE(31, 32), /* ACL */ }; -/* Serialize regmap-irq's mask sync like every other regmap user */ -static int mt7530_irq_mask_sync(int index, unsigned int mask_buf_def, - unsigned int mask_buf, void *irq_drv_data) -{ - struct mt7530_priv *priv = irq_drv_data; - int ret; - - mt7530_mutex_lock(priv); - ret = regmap_update_bits(priv->regmap, MT7530_SYS_INT_EN, - mask_buf_def, ~mask_buf); - mt7530_mutex_unlock(priv); - - return ret; -} - static const struct regmap_irq_chip mt7530_regmap_irq_chip = { .name = KBUILD_MODNAME, .status_base = MT7530_SYS_INT_STS, @@ -2343,14 +2296,12 @@ static const struct regmap_irq_chip mt7530_regmap_irq_chip = { .irqs = mt7530_irqs, .num_irqs = ARRAY_SIZE(mt7530_irqs), .num_regs = 1, - .handle_mask_sync = mt7530_irq_mask_sync, }; static int mt7530_setup_irq(struct mt7530_priv *priv) { struct regmap_irq_chip_data *irq_data; - struct regmap_irq_chip *chip; struct device *dev = priv->dev; struct device_node *np = dev->of_node; int irq, ret; @@ -2370,17 +2321,10 @@ mt7530_setup_irq(struct mt7530_priv *priv) if (priv->id == ID_MT7530 || priv->id == ID_MT7621) mt7530_set(priv, MT7530_TOP_SIG_CTRL, TOP_SIG_CTRL_NORMAL); - chip = devm_kmemdup(dev, &mt7530_regmap_irq_chip, sizeof(*chip), - GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->irq_drv_data = priv; - ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev), priv->regmap, irq, IRQF_ONESHOT, - 0, chip, + 0, &mt7530_regmap_irq_chip, &irq_data); if (ret) return ret; From b62351d125adbfea3b292f41bba2a8f2e1922d33 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:38:06 +0100 Subject: [PATCH 0101/2126] net: dsa: mt7530: fold mt7530_mii_write/read into mt7530_write/read With the lock wrappers removed in the previous commit, mt7530_write() was a trivial wrapper around mt7530_mii_write(), and mt7530_read() around mt7530_mii_read() via _mt7530_read(). Fold the function bodies and eliminate the intermediate functions. The _mt7530_read() poll helper for readx_poll_timeout() is renamed to mt7530_mii_poll() and calls mt7530_read(). Callers are updated using the following semantic patch: @@ expression E1, E2, E3; @@ -mt7530_mii_write(E1, E2, E3) +mt7530_write(E1, E2, E3) @@ expression E1, E2; @@ -mt7530_mii_read(E1, E2) +mt7530_read(E1, E2) @@ expression list args; @@ -readx_poll_timeout(_mt7530_read, args) +readx_poll_timeout(mt7530_mii_poll, args) The two readx_poll_timeout() call sites keep their original line wrapping, which spatch reflows for the longer helper name. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/591c4e7ff5b1b6d39aac7f0f04eb67f36f40d8a2.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 43 +++++++++++++--------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index dbf70e5dd55f..3f36a2a9f665 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -155,7 +155,7 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) } static int -mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) +mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val) { int ret; @@ -169,7 +169,7 @@ mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) } static u32 -mt7530_mii_read(struct mt7530_priv *priv, u32 reg) +mt7530_read(struct mt7530_priv *priv, u32 reg) { int ret; u32 val; @@ -185,25 +185,10 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg) return val; } -static int -mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val) -{ - return mt7530_mii_write(priv, reg, val); -} - static u32 -_mt7530_read(struct mt7530_dummy_poll *p) +mt7530_mii_poll(struct mt7530_dummy_poll *p) { - return mt7530_mii_read(p->priv, p->reg); -} - -static u32 -mt7530_read(struct mt7530_priv *priv, u32 reg) -{ - struct mt7530_dummy_poll p; - - INIT_MT7530_DUMMY_POLL(&p, priv, reg); - return _mt7530_read(&p); + return mt7530_read(p->priv, p->reg); } static void @@ -547,7 +532,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad) | regnum; - ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -560,7 +545,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_READ | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad); - ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -596,7 +581,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad) | regnum; - ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -609,7 +594,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_WRITE | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad) | data; - ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -644,7 +629,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) val = MT7531_MDIO_CL22_READ | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_REG_ADDR(regnum); - ret = mt7530_mii_write(priv, MT7531_PHY_IAC, val | MT7531_PHY_ACS_ST); + ret = mt7530_write(priv, MT7531_PHY_IAC, val | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -681,7 +666,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, reg = MT7531_MDIO_CL22_WRITE | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_REG_ADDR(regnum) | data; - ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -1428,7 +1413,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) if (!dsa_is_cpu_port(ds, port)) return 0; - val = mt7530_mii_read(priv, MT7530_GMACCR); + val = mt7530_read(priv, MT7530_GMACCR); val &= ~MAX_RX_PKT_LEN_MASK; /* RX length also includes Ethernet header, MTK tag, and FCS length */ @@ -1445,7 +1430,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) val |= MAX_RX_PKT_LEN_JUMBO; } - mt7530_mii_write(priv, MT7530_GMACCR, val); + mt7530_write(priv, MT7530_GMACCR, val); return 0; } @@ -2467,7 +2452,7 @@ mt7530_setup(struct dsa_switch *ds) /* Waiting for MT7530 got to stable */ INIT_MT7530_DUMMY_POLL(&p, priv, MT753X_TRAP); - ret = readx_poll_timeout(_mt7530_read, &p, val, val != 0, + ret = readx_poll_timeout(mt7530_mii_poll, &p, val, val != 0, 20, 1000000); if (ret < 0) { dev_err(priv->dev, "reset timeout\n"); @@ -2708,7 +2693,7 @@ mt7531_setup(struct dsa_switch *ds) /* Waiting for MT7530 got to stable */ INIT_MT7530_DUMMY_POLL(&p, priv, MT753X_TRAP); - ret = readx_poll_timeout(_mt7530_read, &p, val, val != 0, + ret = readx_poll_timeout(mt7530_mii_poll, &p, val, val != 0, 20, 1000000); if (ret < 0) { dev_err(priv->dev, "reset timeout\n"); From 63ba2b758938d6f2028d2d5935ea7b5ec29443dd Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:38:16 +0100 Subject: [PATCH 0102/2126] net: dsa: mt7530: replace mt7530_write with regmap_write Replace all mt7530_write() calls with direct regmap_write() calls and remove the wrapper function. The per-call error logging is dropped -- regmap has its own tracing infrastructure. Generated using the following semantic patch: @@ expression priv, reg, val; @@ -mt7530_write(priv, reg, val) +regmap_write(priv->regmap, reg, val) Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/fbb6ee8860fa60326a8af132ed114555e7163350.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 136 +++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 71 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 3f36a2a9f665..43c97df638cc 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -154,20 +154,6 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) core_rmw(priv, reg, val, 0); } -static int -mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val) -{ - int ret; - - ret = regmap_write(priv->regmap, reg, val); - - if (ret < 0) - dev_err(priv->dev, - "failed to write mt7530 register\n"); - - return ret; -} - static u32 mt7530_read(struct mt7530_priv *priv, u32 reg) { @@ -218,7 +204,7 @@ mt7530_fdb_cmd(struct mt7530_priv *priv, enum mt7530_fdb_cmd cmd, u32 *rsp) /* Set the command operating upon the MAC address entries */ val = ATC_BUSY | ATC_MAT(0) | cmd; - ret = mt7530_write(priv, MT7530_ATC, val); + ret = regmap_write(priv->regmap, MT7530_ATC, val); if (ret) return ret; @@ -297,7 +283,7 @@ mt7530_fdb_write(struct mt7530_priv *priv, u16 vid, /* Write array into the ARL table */ for (i = 0; i < 3; i++) - mt7530_write(priv, MT7530_ATA1 + (i * 4), reg[i]); + regmap_write(priv->regmap, MT7530_ATA1 + (i * 4), reg[i]); } /* Set up switch core clock for MT7530 */ @@ -415,27 +401,27 @@ mt7531_pll_setup(struct mt7530_priv *priv) /* Step 1 : Disable MT7531 COREPLL */ val = mt7530_read(priv, MT7531_PLLGP_EN); val &= ~EN_COREPLL; - mt7530_write(priv, MT7531_PLLGP_EN, val); + regmap_write(priv->regmap, MT7531_PLLGP_EN, val); /* Step 2: switch to XTAL output */ val = mt7530_read(priv, MT7531_PLLGP_EN); val |= SW_CLKSW; - mt7530_write(priv, MT7531_PLLGP_EN, val); + regmap_write(priv->regmap, MT7531_PLLGP_EN, val); val = mt7530_read(priv, MT7531_PLLGP_CR0); val &= ~RG_COREPLL_EN; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); /* Step 3: disable PLLGP and enable program PLLGP */ val = mt7530_read(priv, MT7531_PLLGP_EN); val |= SW_PLLGP; - mt7530_write(priv, MT7531_PLLGP_EN, val); + regmap_write(priv->regmap, MT7531_PLLGP_EN, val); /* Step 4: program COREPLL output frequency to 500MHz */ val = mt7530_read(priv, MT7531_PLLGP_CR0); val &= ~RG_COREPLL_POSDIV_M; val |= 2 << RG_COREPLL_POSDIV_S; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); usleep_range(25, 35); switch (xtal) { @@ -443,42 +429,42 @@ mt7531_pll_setup(struct mt7530_priv *priv) val = mt7530_read(priv, MT7531_PLLGP_CR0); val &= ~RG_COREPLL_SDM_PCW_M; val |= 0x140000 << RG_COREPLL_SDM_PCW_S; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); break; case MT7531_XTAL_FSEL_40MHZ: val = mt7530_read(priv, MT7531_PLLGP_CR0); val &= ~RG_COREPLL_SDM_PCW_M; val |= 0x190000 << RG_COREPLL_SDM_PCW_S; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); break; } /* Set feedback divide ratio update signal to high */ val = mt7530_read(priv, MT7531_PLLGP_CR0); val |= RG_COREPLL_SDM_PCW_CHG; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); /* Wait for at least 16 XTAL clocks */ usleep_range(10, 20); /* Step 5: set feedback divide ratio update signal to low */ val = mt7530_read(priv, MT7531_PLLGP_CR0); val &= ~RG_COREPLL_SDM_PCW_CHG; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); /* Enable 325M clock for SGMII */ - mt7530_write(priv, MT7531_ANA_PLLGP_CR5, 0xad0000); + regmap_write(priv->regmap, MT7531_ANA_PLLGP_CR5, 0xad0000); /* Enable 250SSC clock for RGMII */ - mt7530_write(priv, MT7531_ANA_PLLGP_CR2, 0x4f40000); + regmap_write(priv->regmap, MT7531_ANA_PLLGP_CR2, 0x4f40000); /* Step 6: Enable MT7531 PLL */ val = mt7530_read(priv, MT7531_PLLGP_CR0); val |= RG_COREPLL_EN; - mt7530_write(priv, MT7531_PLLGP_CR0, val); + regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); val = mt7530_read(priv, MT7531_PLLGP_EN); val |= EN_COREPLL; - mt7530_write(priv, MT7531_PLLGP_EN, val); + regmap_write(priv->regmap, MT7531_PLLGP_EN, val); usleep_range(25, 35); } @@ -487,8 +473,8 @@ mt7530_mib_reset(struct dsa_switch *ds) { struct mt7530_priv *priv = ds->priv; - mt7530_write(priv, MT7530_MIB_CCR, CCR_MIB_FLUSH); - mt7530_write(priv, MT7530_MIB_CCR, CCR_MIB_ACTIVATE); + regmap_write(priv->regmap, MT7530_MIB_CCR, CCR_MIB_FLUSH); + regmap_write(priv->regmap, MT7530_MIB_CCR, CCR_MIB_ACTIVATE); } static int mt7530_phy_read_c22(struct mt7530_priv *priv, int port, int regnum) @@ -532,7 +518,8 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad) | regnum; - ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = regmap_write(priv->regmap, MT7531_PHY_IAC, + reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -545,7 +532,8 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_READ | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad); - ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = regmap_write(priv->regmap, MT7531_PHY_IAC, + reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -581,7 +569,8 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad) | regnum; - ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = regmap_write(priv->regmap, MT7531_PHY_IAC, + reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -594,7 +583,8 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, reg = MT7531_MDIO_CL45_WRITE | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_DEV_ADDR(devad) | data; - ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = regmap_write(priv->regmap, MT7531_PHY_IAC, + reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -629,7 +619,8 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) val = MT7531_MDIO_CL22_READ | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_REG_ADDR(regnum); - ret = mt7530_write(priv, MT7531_PHY_IAC, val | MT7531_PHY_ACS_ST); + ret = regmap_write(priv->regmap, MT7531_PHY_IAC, + val | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -666,7 +657,8 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, reg = MT7531_MDIO_CL22_WRITE | MT7531_MDIO_PHY_ADDR(port) | MT7531_MDIO_REG_ADDR(regnum) | data; - ret = mt7530_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); + ret = regmap_write(priv->regmap, MT7531_PHY_IAC, + reg | MT7531_PHY_ACS_ST); if (ret < 0) goto out; @@ -1021,7 +1013,8 @@ mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) } } - mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit)); + regmap_write(priv->regmap, MT7530_AAC, + AGE_CNT(age_count) | AGE_UNIT(age_unit)); return 0; } @@ -1059,7 +1052,7 @@ static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface) /* MUX_PHY_P4: P4 -> P5 -> SoC MAC */ case MUX_PHY_P4: /* Setup the MAC by default for the cpu port */ - mt7530_write(priv, MT753X_PMCR_P(5), 0x56300); + regmap_write(priv->regmap, MT753X_PMCR_P(5), 0x56300); break; /* GMAC5: P5 -> SoC MAC or external PHY */ @@ -1073,7 +1066,8 @@ static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface) val |= MT7530_P5_RGMII_MODE; /* P5 RGMII RX Clock Control: delay setting for 1000M */ - mt7530_write(priv, MT7530_P5RGMIIRXCR, CSR_RGMII_EDGE_ALIGN); + regmap_write(priv->regmap, MT7530_P5RGMIIRXCR, + CSR_RGMII_EDGE_ALIGN); /* Don't set delay in DSA mode */ if (!dsa_is_dsa_port(priv->ds, 5) && @@ -1082,15 +1076,15 @@ static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface) tx_delay = 4; /* n * 0.5 ns */ /* P5 RGMII TX Clock Control: delay x */ - mt7530_write(priv, MT7530_P5RGMIITXCR, + regmap_write(priv->regmap, MT7530_P5RGMIITXCR, CSR_RGMII_TXC_CFG(0x10 + tx_delay)); /* reduce P5 RGMII Tx driving, 8mA */ - mt7530_write(priv, MT7530_IO_DRV_CR, + regmap_write(priv->regmap, MT7530_IO_DRV_CR, P5_IO_CLK_DRV(1) | P5_IO_DATA_DRV(1)); } - mt7530_write(priv, MT753X_MTRAP, val); + regmap_write(priv->regmap, MT753X_MTRAP, val); dev_dbg(ds->dev, "Setup P5, HWTRAP=0x%x, mode=%s, phy-mode=%s\n", val, mt7530_p5_mode_str(priv->p5_mode), phy_modes(interface)); @@ -1312,8 +1306,7 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) struct mt7530_priv *priv = ds->priv; /* Enable Mediatek header mode on the cpu port */ - mt7530_write(priv, MT7530_PVC_P(port), - PORT_SPEC_TAG); + regmap_write(priv->regmap, MT7530_PVC_P(port), PORT_SPEC_TAG); /* Enable flooding on the CPU port */ mt7530_set(priv, MT753X_MFC, BC_FFP(BIT(port)) | UNM_FFP(BIT(port)) | @@ -1330,7 +1323,7 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) /* CPU port gets connected to all user ports of * the switch. */ - mt7530_write(priv, MT7530_PCR_P(port), + regmap_write(priv->regmap, MT7530_PCR_P(port), PCR_MATRIX(dsa_user_ports(priv->ds))); /* Set to fallback mode for independent VLAN learning */ @@ -1430,7 +1423,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) val |= MAX_RX_PKT_LEN_JUMBO; } - mt7530_write(priv, MT7530_GMACCR, val); + regmap_write(priv->regmap, MT7530_GMACCR, val); return 0; } @@ -1595,7 +1588,7 @@ mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid) int ret; val = VTCR_BUSY | VTCR_FUNC(cmd) | vid; - ret = mt7530_write(priv, MT7530_VTCR, val); + ret = regmap_write(priv->regmap, MT7530_VTCR, val); if (ret) return ret; @@ -1627,8 +1620,8 @@ mt7530_setup_vlan0(struct mt7530_priv *priv) */ val = IVL_MAC | EG_CON | PORT_MEM(MT7530_ALL_MEMBERS) | FID(FID_BRIDGED) | VLAN_VALID; - mt7530_write(priv, MT7530_VAWD1, val); - mt7530_write(priv, MT7530_VAWD2, 0); + regmap_write(priv->regmap, MT7530_VAWD1, val); + regmap_write(priv->regmap, MT7530_VAWD2, 0); return mt7530_vlan_cmd(priv, MT7530_VTCR_WR_VID, 0); } @@ -1898,7 +1891,7 @@ mt7530_hw_vlan_add(struct mt7530_priv *priv, */ val = IVL_MAC | VTAG_EN | PORT_MEM(new_members) | FID(FID_BRIDGED) | VLAN_VALID; - mt7530_write(priv, MT7530_VAWD1, val); + regmap_write(priv->regmap, MT7530_VAWD1, val); /* Decide whether adding tag or not for those outgoing packets from the * port inside the VLAN. @@ -1937,10 +1930,10 @@ mt7530_hw_vlan_del(struct mt7530_priv *priv, if (new_members) { val = IVL_MAC | VTAG_EN | PORT_MEM(new_members) | VLAN_VALID; - mt7530_write(priv, MT7530_VAWD1, val); + regmap_write(priv->regmap, MT7530_VAWD1, val); } else { - mt7530_write(priv, MT7530_VAWD1, 0); - mt7530_write(priv, MT7530_VAWD2, 0); + regmap_write(priv->regmap, MT7530_VAWD1, 0); + regmap_write(priv->regmap, MT7530_VAWD2, 0); } } @@ -2081,7 +2074,7 @@ static int mt753x_port_mirror_add(struct dsa_switch *ds, int port, val |= MT753X_MIRROR_EN(priv->id); val &= ~MT753X_MIRROR_PORT_MASK(priv->id); val |= MT753X_MIRROR_PORT_SET(priv->id, mirror->to_local_port); - mt7530_write(priv, MT753X_MIRROR_REG(priv->id), val); + regmap_write(priv->regmap, MT753X_MIRROR_REG(priv->id), val); val = mt7530_read(priv, MT7530_PCR_P(port)); if (ingress) { @@ -2091,7 +2084,7 @@ static int mt753x_port_mirror_add(struct dsa_switch *ds, int port, val |= PORT_TX_MIR; priv->mirror_tx |= BIT(port); } - mt7530_write(priv, MT7530_PCR_P(port), val); + regmap_write(priv->regmap, MT7530_PCR_P(port), val); return 0; } @@ -2110,12 +2103,12 @@ static void mt753x_port_mirror_del(struct dsa_switch *ds, int port, val &= ~PORT_TX_MIR; priv->mirror_tx &= ~BIT(port); } - mt7530_write(priv, MT7530_PCR_P(port), val); + regmap_write(priv->regmap, MT7530_PCR_P(port), val); if (!priv->mirror_rx && !priv->mirror_tx) { val = mt7530_read(priv, MT753X_MIRROR_REG(priv->id)); val &= ~MT753X_MIRROR_EN(priv->id); - mt7530_write(priv, MT753X_MIRROR_REG(priv->id), val); + regmap_write(priv->regmap, MT753X_MIRROR_REG(priv->id), val); } } @@ -2213,9 +2206,9 @@ mt7530_setup_gpio(struct mt7530_priv *priv) if (!gc) return -ENOMEM; - mt7530_write(priv, MT7530_LED_GPIO_OE, 0); - mt7530_write(priv, MT7530_LED_GPIO_DIR, 0); - mt7530_write(priv, MT7530_LED_IO_MODE, 0); + regmap_write(priv->regmap, MT7530_LED_GPIO_OE, 0); + regmap_write(priv->regmap, MT7530_LED_GPIO_DIR, 0); + regmap_write(priv->regmap, MT7530_LED_IO_MODE, 0); gc->label = "mt7530"; gc->parent = dev; @@ -2473,13 +2466,12 @@ mt7530_setup(struct dsa_switch *ds) } /* Reset the switch through internal reset */ - mt7530_write(priv, MT7530_SYS_CTRL, - SYS_CTRL_PHY_RST | SYS_CTRL_SW_RST | - SYS_CTRL_REG_RST); + regmap_write(priv->regmap, MT7530_SYS_CTRL, + SYS_CTRL_PHY_RST | SYS_CTRL_SW_RST | SYS_CTRL_REG_RST); /* Lower Tx driving for TRGMII path */ for (i = 0; i < NUM_TRGMII_CTRL; i++) - mt7530_write(priv, MT7530_TRGMII_TD_ODT(i), + regmap_write(priv->regmap, MT7530_TRGMII_TD_ODT(i), TD_DM_DRVP(8) | TD_DM_DRVN(8)); for (i = 0; i < NUM_TRGMII_CTRL; i++) @@ -2658,7 +2650,7 @@ mt7531_setup_common(struct dsa_switch *ds) /* Enable Special Tag for rx frames */ if (priv->id == ID_EN7581 || priv->id == ID_AN7583) - mt7530_write(priv, MT753X_CPORT_SPTAG_CFG, + regmap_write(priv->regmap, MT753X_CPORT_SPTAG_CFG, CPORT_SW2FE_STAG_EN | CPORT_FE2SW_STAG_EN); /* Flush the FDB table */ @@ -2716,10 +2708,12 @@ mt7531_setup(struct dsa_switch *ds) /* Force link down on all ports before internal reset */ for (i = 0; i < priv->ds->num_ports; i++) - mt7530_write(priv, MT753X_PMCR_P(i), MT7531_FORCE_MODE_LNK); + regmap_write(priv->regmap, MT753X_PMCR_P(i), + MT7531_FORCE_MODE_LNK); /* Reset the switch through internal reset */ - mt7530_write(priv, MT7530_SYS_CTRL, SYS_CTRL_SW_RST | SYS_CTRL_REG_RST); + regmap_write(priv->regmap, MT7530_SYS_CTRL, + SYS_CTRL_SW_RST | SYS_CTRL_REG_RST); if (!priv->p5_sgmii) { mt7531_pll_setup(priv); @@ -2958,7 +2952,7 @@ static void mt7531_rgmii_setup(struct mt7530_priv *priv, } } - mt7530_write(priv, MT7531_CLKGEN_CTRL, val); + regmap_write(priv->regmap, MT7531_CLKGEN_CTRL, val); } static void @@ -3303,7 +3297,7 @@ static int mt753x_tc_setup_qdisc_tbf(struct dsa_switch *ds, int port, FIELD_PREP(ERLCR_EXP_MASK, tick) | ERLCR_TBF_MODE_MASK | FIELD_PREP(ERLCR_MANT_MASK, 0xf); - mt7530_write(priv, MT753X_ERLCR_P(port), val); + regmap_write(priv->regmap, MT753X_ERLCR_P(port), val); break; } default: @@ -3345,7 +3339,7 @@ static int mt7988_setup(struct dsa_switch *ds) FIELD_PREP(AN7583_CSR_ETHER_AFE_PWD, 0)); /* Reset the switch PHYs */ - mt7530_write(priv, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST); + regmap_write(priv->regmap, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST); return mt7531_setup_common(ds); } From f6692ee8def416c10c47cda97ee5b01e6c7260cf Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:38:26 +0100 Subject: [PATCH 0103/2126] net: dsa: mt7530: replace mt7530_rmw/set/clear with regmap API Replace all mt7530_rmw() calls with regmap_update_bits(), mt7530_set() with regmap_set_bits(), and mt7530_clear() with regmap_clear_bits(). Remove the wrapper function definitions. Generated using the following semantic patch: @@ expression priv, reg, mask, set; @@ -mt7530_rmw(priv, reg, mask, set) +regmap_update_bits(priv->regmap, reg, mask, set) @@ expression priv, reg, val; @@ -mt7530_set(priv, reg, val) +regmap_set_bits(priv->regmap, reg, val) @@ expression priv, reg, val; @@ -mt7530_clear(priv, reg, val) +regmap_clear_bits(priv->regmap, reg, val) Six regmap_update_bits() call sites with multi-line masks are rewrapped by hand afterwards, as spatch joins their argument lines. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/182be19b483e77eb1d4ed835813359a27acd8e9c.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 357 ++++++++++++++++++++------------------- 1 file changed, 181 insertions(+), 176 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 43c97df638cc..0ff8a9eda3e4 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -177,25 +177,6 @@ mt7530_mii_poll(struct mt7530_dummy_poll *p) return mt7530_read(p->priv, p->reg); } -static void -mt7530_rmw(struct mt7530_priv *priv, u32 reg, - u32 mask, u32 set) -{ - regmap_update_bits(priv->regmap, reg, mask, set); -} - -static void -mt7530_set(struct mt7530_priv *priv, u32 reg, u32 val) -{ - mt7530_rmw(priv, reg, val, val); -} - -static void -mt7530_clear(struct mt7530_priv *priv, u32 reg, u32 val) -{ - mt7530_rmw(priv, reg, val, 0); -} - static int mt7530_fdb_cmd(struct mt7530_priv *priv, enum mt7530_fdb_cmd cmd, u32 *rsp) { @@ -337,12 +318,13 @@ mt7530_setup_port6(struct dsa_switch *ds, phy_interface_t interface) core_clear(priv, CORE_TRGMII_GSW_CLK_CG, REG_TRGMIICK_EN); if (interface == PHY_INTERFACE_MODE_RGMII) { - mt7530_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_MASK, - P6_INTF_MODE(0)); + regmap_update_bits(priv->regmap, MT7530_P6ECR, + P6_INTF_MODE_MASK, P6_INTF_MODE(0)); return; } - mt7530_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_MASK, P6_INTF_MODE(1)); + regmap_update_bits(priv->regmap, MT7530_P6ECR, P6_INTF_MODE_MASK, + P6_INTF_MODE(1)); xtal = mt7530_read(priv, MT753X_MTRAP) & MT7530_XTAL_MASK; @@ -1269,35 +1251,35 @@ mt753x_trap_frames(struct mt7530_priv *priv) * switch egress VLAN tag processing. This preserves VLAN tags * for reception on VLAN sub-interfaces. */ - mt7530_rmw(priv, MT753X_BPC, - PAE_BPDU_FR | PAE_EG_TAG_MASK | PAE_PORT_FW_MASK | - BPDU_EG_TAG_MASK | BPDU_PORT_FW_MASK, - PAE_BPDU_FR | PAE_EG_TAG(MT7530_VLAN_EG_DISABLED) | - PAE_PORT_FW(TO_CPU_FW_CPU_ONLY) | - BPDU_EG_TAG(MT7530_VLAN_EG_DISABLED) | - TO_CPU_FW_CPU_ONLY); + regmap_update_bits(priv->regmap, MT753X_BPC, + PAE_BPDU_FR | PAE_EG_TAG_MASK | PAE_PORT_FW_MASK | + BPDU_EG_TAG_MASK | BPDU_PORT_FW_MASK, + PAE_BPDU_FR | PAE_EG_TAG(MT7530_VLAN_EG_DISABLED) | + PAE_PORT_FW(TO_CPU_FW_CPU_ONLY) | + BPDU_EG_TAG(MT7530_VLAN_EG_DISABLED) | + TO_CPU_FW_CPU_ONLY); /* Trap frames with :01 and :02 MAC DAs to the CPU port(s) and * egress them with EG_TAG disabled. */ - mt7530_rmw(priv, MT753X_RGAC1, - R02_BPDU_FR | R02_EG_TAG_MASK | R02_PORT_FW_MASK | - R01_BPDU_FR | R01_EG_TAG_MASK | R01_PORT_FW_MASK, - R02_BPDU_FR | R02_EG_TAG(MT7530_VLAN_EG_DISABLED) | - R02_PORT_FW(TO_CPU_FW_CPU_ONLY) | R01_BPDU_FR | - R01_EG_TAG(MT7530_VLAN_EG_DISABLED) | - TO_CPU_FW_CPU_ONLY); + regmap_update_bits(priv->regmap, MT753X_RGAC1, + R02_BPDU_FR | R02_EG_TAG_MASK | R02_PORT_FW_MASK | + R01_BPDU_FR | R01_EG_TAG_MASK | R01_PORT_FW_MASK, + R02_BPDU_FR | R02_EG_TAG(MT7530_VLAN_EG_DISABLED) | + R02_PORT_FW(TO_CPU_FW_CPU_ONLY) | R01_BPDU_FR | + R01_EG_TAG(MT7530_VLAN_EG_DISABLED) | + TO_CPU_FW_CPU_ONLY); /* Trap frames with :03 and :0E MAC DAs to the CPU port(s) and * egress them with EG_TAG disabled. */ - mt7530_rmw(priv, MT753X_RGAC2, - R0E_BPDU_FR | R0E_EG_TAG_MASK | R0E_PORT_FW_MASK | - R03_BPDU_FR | R03_EG_TAG_MASK | R03_PORT_FW_MASK, - R0E_BPDU_FR | R0E_EG_TAG(MT7530_VLAN_EG_DISABLED) | - R0E_PORT_FW(TO_CPU_FW_CPU_ONLY) | R03_BPDU_FR | - R03_EG_TAG(MT7530_VLAN_EG_DISABLED) | - TO_CPU_FW_CPU_ONLY); + regmap_update_bits(priv->regmap, MT753X_RGAC2, + R0E_BPDU_FR | R0E_EG_TAG_MASK | R0E_PORT_FW_MASK | + R03_BPDU_FR | R03_EG_TAG_MASK | R03_PORT_FW_MASK, + R0E_BPDU_FR | R0E_EG_TAG(MT7530_VLAN_EG_DISABLED) | + R0E_PORT_FW(TO_CPU_FW_CPU_ONLY) | R03_BPDU_FR | + R03_EG_TAG(MT7530_VLAN_EG_DISABLED) | + TO_CPU_FW_CPU_ONLY); } static void @@ -1309,8 +1291,8 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) regmap_write(priv->regmap, MT7530_PVC_P(port), PORT_SPEC_TAG); /* Enable flooding on the CPU port */ - mt7530_set(priv, MT753X_MFC, BC_FFP(BIT(port)) | UNM_FFP(BIT(port)) | - UNU_FFP(BIT(port))); + regmap_set_bits(priv->regmap, MT753X_MFC, + BC_FFP(BIT(port)) | UNM_FFP(BIT(port)) | UNU_FFP(BIT(port))); /* Add the CPU port to the CPU port bitmap for MT7531 and the switch on * the MT7988 SoC. Trapped frames will be forwarded to the CPU port that @@ -1318,7 +1300,8 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) */ if (priv->id == ID_MT7531 || priv->id == ID_MT7988 || priv->id == ID_EN7581 || priv->id == ID_AN7583) - mt7530_set(priv, MT7531_CFC, MT7531_CPU_PMAP(BIT(port))); + regmap_set_bits(priv->regmap, MT7531_CFC, + MT7531_CPU_PMAP(BIT(port))); /* CPU port gets connected to all user ports of * the switch. @@ -1327,8 +1310,8 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) PCR_MATRIX(dsa_user_ports(priv->ds))); /* Set to fallback mode for independent VLAN learning */ - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, - MT7530_PORT_FALLBACK_MODE); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_PORT_VLAN_MASK, MT7530_PORT_FALLBACK_MODE); } static int @@ -1350,8 +1333,8 @@ mt7530_port_enable(struct dsa_switch *ds, int port, priv->ports[port].pm |= PCR_MATRIX(BIT(cpu_dp->index)); } priv->ports[port].enable = true; - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, - priv->ports[port].pm); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), PCR_MATRIX_MASK, + priv->ports[port].pm); mutex_unlock(&priv->reg_mutex); @@ -1359,9 +1342,9 @@ mt7530_port_enable(struct dsa_switch *ds, int port, return 0; if (port == 5) - mt7530_clear(priv, MT753X_MTRAP, MT7530_P5_DIS); + regmap_clear_bits(priv->regmap, MT753X_MTRAP, MT7530_P5_DIS); else if (port == 6) - mt7530_clear(priv, MT753X_MTRAP, MT7530_P6_DIS); + regmap_clear_bits(priv->regmap, MT753X_MTRAP, MT7530_P6_DIS); return 0; } @@ -1377,8 +1360,8 @@ mt7530_port_disable(struct dsa_switch *ds, int port) * enablement for the port. */ priv->ports[port].enable = false; - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, - PCR_MATRIX_CLR); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), PCR_MATRIX_MASK, + PCR_MATRIX_CLR); mutex_unlock(&priv->reg_mutex); @@ -1387,9 +1370,9 @@ mt7530_port_disable(struct dsa_switch *ds, int port) /* Do not set MT7530_P5_DIS when port 5 is being used for PHY muxing. */ if (port == 5 && priv->p5_mode == GMAC5) - mt7530_set(priv, MT753X_MTRAP, MT7530_P5_DIS); + regmap_set_bits(priv->regmap, MT753X_MTRAP, MT7530_P5_DIS); else if (port == 6) - mt7530_set(priv, MT753X_MTRAP, MT7530_P6_DIS); + regmap_set_bits(priv->regmap, MT753X_MTRAP, MT7530_P6_DIS); } static int @@ -1459,8 +1442,9 @@ mt7530_stp_state_set(struct dsa_switch *ds, int port, u8 state) break; } - mt7530_rmw(priv, MT7530_SSP_P(port), FID_PST_MASK(FID_BRIDGED), - FID_PST(FID_BRIDGED, stp_state)); + regmap_update_bits(priv->regmap, MT7530_SSP_P(port), + FID_PST_MASK(FID_BRIDGED), + FID_PST(FID_BRIDGED, stp_state)); } static void mt7530_update_port_member(struct mt7530_priv *priv, int port, @@ -1499,8 +1483,9 @@ static void mt7530_update_port_member(struct mt7530_priv *priv, int port, } if (other_p->enable) - mt7530_rmw(priv, MT7530_PCR_P(other_port), - PCR_MATRIX_MASK, other_p->pm); + regmap_update_bits(priv->regmap, + MT7530_PCR_P(other_port), + PCR_MATRIX_MASK, other_p->pm); } /* Add/remove the all other ports to this port matrix. For !join @@ -1509,7 +1494,8 @@ static void mt7530_update_port_member(struct mt7530_priv *priv, int port, */ p->pm = PCR_MATRIX(port_bitmap); if (priv->ports[port].enable) - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, p->pm); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_MATRIX_MASK, p->pm); } static int @@ -1532,20 +1518,23 @@ mt7530_port_bridge_flags(struct dsa_switch *ds, int port, struct mt7530_priv *priv = ds->priv; if (flags.mask & BR_LEARNING) - mt7530_rmw(priv, MT7530_PSC_P(port), SA_DIS, - flags.val & BR_LEARNING ? 0 : SA_DIS); + regmap_update_bits(priv->regmap, MT7530_PSC_P(port), SA_DIS, + flags.val & BR_LEARNING ? 0 : SA_DIS); if (flags.mask & BR_FLOOD) - mt7530_rmw(priv, MT753X_MFC, UNU_FFP(BIT(port)), - flags.val & BR_FLOOD ? UNU_FFP(BIT(port)) : 0); + regmap_update_bits(priv->regmap, MT753X_MFC, + UNU_FFP(BIT(port)), + flags.val & BR_FLOOD ? UNU_FFP(BIT(port)) : 0); if (flags.mask & BR_MCAST_FLOOD) - mt7530_rmw(priv, MT753X_MFC, UNM_FFP(BIT(port)), - flags.val & BR_MCAST_FLOOD ? UNM_FFP(BIT(port)) : 0); + regmap_update_bits(priv->regmap, MT753X_MFC, + UNM_FFP(BIT(port)), + flags.val & BR_MCAST_FLOOD ? UNM_FFP(BIT(port)) : 0); if (flags.mask & BR_BCAST_FLOOD) - mt7530_rmw(priv, MT753X_MFC, BC_FFP(BIT(port)), - flags.val & BR_BCAST_FLOOD ? BC_FFP(BIT(port)) : 0); + regmap_update_bits(priv->regmap, MT753X_MFC, + BC_FFP(BIT(port)), + flags.val & BR_BCAST_FLOOD ? BC_FFP(BIT(port)) : 0); if (flags.mask & BR_ISOLATED) { struct dsa_port *dp = dsa_to_port(ds, port); @@ -1573,8 +1562,8 @@ mt7530_port_bridge_join(struct dsa_switch *ds, int port, mt7530_update_port_member(priv, port, bridge.dev, true); /* Set to fallback mode for independent VLAN learning */ - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, - MT7530_PORT_FALLBACK_MODE); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_PORT_VLAN_MASK, MT7530_PORT_FALLBACK_MODE); mutex_unlock(&priv->reg_mutex); @@ -1637,18 +1626,19 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port) * bridge. Don't set standalone ports to fallback mode. */ if (dsa_port_bridge_dev_get(dsa_to_port(ds, port))) - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, - MT7530_PORT_FALLBACK_MODE); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_PORT_VLAN_MASK, + MT7530_PORT_FALLBACK_MODE); - mt7530_rmw(priv, MT7530_PVC_P(port), - VLAN_ATTR_MASK | PVC_EG_TAG_MASK | ACC_FRM_MASK, - VLAN_ATTR(MT7530_VLAN_TRANSPARENT) | - PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT) | - MT7530_VLAN_ACC_ALL); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + VLAN_ATTR_MASK | PVC_EG_TAG_MASK | ACC_FRM_MASK, + VLAN_ATTR(MT7530_VLAN_TRANSPARENT) | + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT) | + MT7530_VLAN_ACC_ALL); /* Set PVID to 0 */ - mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, - G0_PORT_VID_DEF); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(port), + G0_PORT_VID_MASK, G0_PORT_VID_DEF); for (i = 0; i < priv->ds->num_ports; i++) { if (i == port) @@ -1679,24 +1669,27 @@ mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port) * table lookup. */ if (dsa_is_user_port(ds, port)) { - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, - MT7530_PORT_SECURITY_MODE); - mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, - G0_PORT_VID(priv->ports[port].pvid)); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_PORT_VLAN_MASK, + MT7530_PORT_SECURITY_MODE); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(port), + G0_PORT_VID_MASK, + G0_PORT_VID(priv->ports[port].pvid)); /* Only accept tagged frames if PVID is not set */ if (!priv->ports[port].pvid) - mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, - MT7530_VLAN_ACC_TAGGED); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + ACC_FRM_MASK, + MT7530_VLAN_ACC_TAGGED); /* Set the port as a user port which is to be able to recognize * VID from incoming packets before fetching entry within the * VLAN table. */ - mt7530_rmw(priv, MT7530_PVC_P(port), - VLAN_ATTR_MASK | PVC_EG_TAG_MASK, - VLAN_ATTR(MT7530_VLAN_USER) | - PVC_EG_TAG(MT7530_VLAN_EG_DISABLED)); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + VLAN_ATTR_MASK | PVC_EG_TAG_MASK, + VLAN_ATTR(MT7530_VLAN_USER) | + PVC_EG_TAG(MT7530_VLAN_EG_DISABLED)); } else { /* Also set CPU ports to the "user" VLAN port attribute, to * allow VLAN classification, but keep the EG_TAG attribute as @@ -1705,8 +1698,9 @@ mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port) * are forwarded to user ports as tagged, and untagged as * untagged. */ - mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK, - VLAN_ATTR(MT7530_VLAN_USER)); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + VLAN_ATTR_MASK, + VLAN_ATTR(MT7530_VLAN_USER)); } } @@ -1724,8 +1718,8 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port, * back to the default as is at initial boot which is a VLAN-unaware * port. */ - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, - MT7530_PORT_MATRIX_MODE); + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_PORT_VLAN_MASK, MT7530_PORT_MATRIX_MODE); mutex_unlock(&priv->reg_mutex); } @@ -1906,9 +1900,9 @@ mt7530_hw_vlan_add(struct mt7530_priv *priv, val = MT7530_VLAN_EGRESS_UNTAG; else val = MT7530_VLAN_EGRESS_TAG; - mt7530_rmw(priv, MT7530_VAWD2, - ETAG_CTRL_P_MASK(entry->port), - ETAG_CTRL_P(entry->port, val)); + regmap_update_bits(priv->regmap, MT7530_VAWD2, + ETAG_CTRL_P_MASK(entry->port), + ETAG_CTRL_P(entry->port, val)); } static void @@ -1986,25 +1980,26 @@ skip_vlan_table: priv->ports[port].pvid = vlan->vid; /* Accept all frames if PVID is set */ - mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, - MT7530_VLAN_ACC_ALL); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + ACC_FRM_MASK, MT7530_VLAN_ACC_ALL); /* Only configure PVID if VLAN filtering is enabled */ if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) - mt7530_rmw(priv, MT7530_PPBV1_P(port), - G0_PORT_VID_MASK, - G0_PORT_VID(vlan->vid)); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(port), + G0_PORT_VID_MASK, + G0_PORT_VID(vlan->vid)); } else if (vlan->vid && priv->ports[port].pvid == vlan->vid) { /* This VLAN is overwritten without PVID, so unset it */ priv->ports[port].pvid = G0_PORT_VID_DEF; /* Only accept tagged frames if the port is VLAN-aware */ if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) - mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, - MT7530_VLAN_ACC_TAGGED); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + ACC_FRM_MASK, + MT7530_VLAN_ACC_TAGGED); - mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, - G0_PORT_VID_DEF); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(port), + G0_PORT_VID_MASK, G0_PORT_VID_DEF); } mutex_unlock(&priv->reg_mutex); @@ -2038,11 +2033,12 @@ skip_vlan_table: /* Only accept tagged frames if the port is VLAN-aware */ if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) - mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, - MT7530_VLAN_ACC_TAGGED); + regmap_update_bits(priv->regmap, MT7530_PVC_P(port), + ACC_FRM_MASK, + MT7530_VLAN_ACC_TAGGED); - mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, - G0_PORT_VID_DEF); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(port), + G0_PORT_VID_MASK, G0_PORT_VID_DEF); } @@ -2149,9 +2145,9 @@ mt7530_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) u32 bit = mt7530_gpio_to_bit(offset); if (value) - mt7530_set(priv, MT7530_LED_GPIO_DATA, bit); + regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); else - mt7530_clear(priv, MT7530_LED_GPIO_DATA, bit); + regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); return 0; } @@ -2172,8 +2168,8 @@ mt7530_gpio_direction_input(struct gpio_chip *gc, unsigned int offset) struct mt7530_priv *priv = gpiochip_get_data(gc); u32 bit = mt7530_gpio_to_bit(offset); - mt7530_clear(priv, MT7530_LED_GPIO_OE, bit); - mt7530_clear(priv, MT7530_LED_GPIO_DIR, bit); + regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_OE, bit); + regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DIR, bit); return 0; } @@ -2184,14 +2180,14 @@ mt7530_gpio_direction_output(struct gpio_chip *gc, unsigned int offset, int valu struct mt7530_priv *priv = gpiochip_get_data(gc); u32 bit = mt7530_gpio_to_bit(offset); - mt7530_set(priv, MT7530_LED_GPIO_DIR, bit); + regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DIR, bit); if (value) - mt7530_set(priv, MT7530_LED_GPIO_DATA, bit); + regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); else - mt7530_clear(priv, MT7530_LED_GPIO_DATA, bit); + regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); - mt7530_set(priv, MT7530_LED_GPIO_OE, bit); + regmap_set_bits(priv->regmap, MT7530_LED_GPIO_OE, bit); return 0; } @@ -2297,7 +2293,8 @@ mt7530_setup_irq(struct mt7530_priv *priv) /* This register must be set for MT7530 to properly fire interrupts */ if (priv->id == ID_MT7530 || priv->id == ID_MT7621) - mt7530_set(priv, MT7530_TOP_SIG_CTRL, TOP_SIG_CTRL_NORMAL); + regmap_set_bits(priv->regmap, MT7530_TOP_SIG_CTRL, + TOP_SIG_CTRL_NORMAL); ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev), priv->regmap, irq, @@ -2475,14 +2472,15 @@ mt7530_setup(struct dsa_switch *ds) TD_DM_DRVP(8) | TD_DM_DRVN(8)); for (i = 0; i < NUM_TRGMII_CTRL; i++) - mt7530_rmw(priv, MT7530_TRGMII_RD(i), - RD_TAP_MASK, RD_TAP(16)); + regmap_update_bits(priv->regmap, MT7530_TRGMII_RD(i), + RD_TAP_MASK, RD_TAP(16)); /* Allow modifying the trap and directly access PHY registers via the * MDIO bus the switch is on. */ - mt7530_rmw(priv, MT753X_MTRAP, MT7530_CHG_TRAP | - MT7530_PHY_INDIRECT_ACCESS, MT7530_CHG_TRAP); + regmap_update_bits(priv->regmap, MT753X_MTRAP, + MT7530_CHG_TRAP | MT7530_PHY_INDIRECT_ACCESS, + MT7530_CHG_TRAP); if ((val & MT7530_XTAL_MASK) == MT7530_XTAL_40MHZ) mt7530_pll_setup(priv); @@ -2496,17 +2494,16 @@ mt7530_setup(struct dsa_switch *ds) /* Clear link settings and enable force mode to force link down * on all ports until they're enabled later. */ - mt7530_rmw(priv, MT753X_PMCR_P(i), - PMCR_LINK_SETTINGS_MASK | - MT753X_FORCE_MODE(priv->id), - MT753X_FORCE_MODE(priv->id)); + regmap_update_bits(priv->regmap, MT753X_PMCR_P(i), + PMCR_LINK_SETTINGS_MASK | MT753X_FORCE_MODE(priv->id), + MT753X_FORCE_MODE(priv->id)); /* Disable forwarding by default on all ports */ - mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, - PCR_MATRIX_CLR); + regmap_update_bits(priv->regmap, MT7530_PCR_P(i), + PCR_MATRIX_MASK, PCR_MATRIX_CLR); /* Disable learning by default on all ports */ - mt7530_set(priv, MT7530_PSC_P(i), SA_DIS); + regmap_set_bits(priv->regmap, MT7530_PSC_P(i), SA_DIS); if (dsa_is_cpu_port(ds, i)) { mt753x_cpu_port_enable(ds, i); @@ -2514,16 +2511,17 @@ mt7530_setup(struct dsa_switch *ds) mt7530_port_disable(ds, i); /* Set default PVID to 0 on all user ports */ - mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK, - G0_PORT_VID_DEF); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(i), + G0_PORT_VID_MASK, G0_PORT_VID_DEF); } /* Enable consistent egress tag */ - mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK, - PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); + regmap_update_bits(priv->regmap, MT7530_PVC_P(i), + PVC_EG_TAG_MASK, + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); } /* Allow mirroring frames received on the local port (monitor port). */ - mt7530_set(priv, MT753X_AGC, LOCAL_EN); + regmap_set_bits(priv->regmap, MT753X_AGC, LOCAL_EN); /* Setup VLAN ID 0 for VLAN-unaware bridges */ ret = mt7530_setup_vlan0(priv); @@ -2570,7 +2568,8 @@ mt7530_setup(struct dsa_switch *ds) if (priv->p5_mode == MUX_PHY_P0 || priv->p5_mode == MUX_PHY_P4) { - mt7530_clear(priv, MT753X_MTRAP, MT7530_P5_DIS); + regmap_clear_bits(priv->regmap, MT753X_MTRAP, + MT7530_P5_DIS); mt7530_setup_port5(ds, interface); } } @@ -2609,26 +2608,26 @@ mt7531_setup_common(struct dsa_switch *ds) mt7530_mib_reset(ds); /* Disable flooding on all ports */ - mt7530_clear(priv, MT753X_MFC, BC_FFP_MASK | UNM_FFP_MASK | - UNU_FFP_MASK); + regmap_clear_bits(priv->regmap, MT753X_MFC, + BC_FFP_MASK | UNM_FFP_MASK | UNU_FFP_MASK); for (i = 0; i < priv->ds->num_ports; i++) { /* Clear link settings and enable force mode to force link down * on all ports until they're enabled later. */ - mt7530_rmw(priv, MT753X_PMCR_P(i), - PMCR_LINK_SETTINGS_MASK | - MT753X_FORCE_MODE(priv->id), - MT753X_FORCE_MODE(priv->id)); + regmap_update_bits(priv->regmap, MT753X_PMCR_P(i), + PMCR_LINK_SETTINGS_MASK | MT753X_FORCE_MODE(priv->id), + MT753X_FORCE_MODE(priv->id)); /* Disable forwarding by default on all ports */ - mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, - PCR_MATRIX_CLR); + regmap_update_bits(priv->regmap, MT7530_PCR_P(i), + PCR_MATRIX_MASK, PCR_MATRIX_CLR); /* Disable learning by default on all ports */ - mt7530_set(priv, MT7530_PSC_P(i), SA_DIS); + regmap_set_bits(priv->regmap, MT7530_PSC_P(i), SA_DIS); - mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); + regmap_set_bits(priv->regmap, MT7531_DBG_CNT(i), + MT7531_DIS_CLR); if (dsa_is_cpu_port(ds, i)) { mt753x_cpu_port_enable(ds, i); @@ -2636,17 +2635,18 @@ mt7531_setup_common(struct dsa_switch *ds) mt7530_port_disable(ds, i); /* Set default PVID to 0 on all user ports */ - mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK, - G0_PORT_VID_DEF); + regmap_update_bits(priv->regmap, MT7530_PPBV1_P(i), + G0_PORT_VID_MASK, G0_PORT_VID_DEF); } /* Enable consistent egress tag */ - mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK, - PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); + regmap_update_bits(priv->regmap, MT7530_PVC_P(i), + PVC_EG_TAG_MASK, + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); } /* Allow mirroring frames received on the local port (monitor port). */ - mt7530_set(priv, MT753X_AGC, LOCAL_EN); + regmap_set_bits(priv->regmap, MT753X_AGC, LOCAL_EN); /* Enable Special Tag for rx frames */ if (priv->id == ID_EN7581 || priv->id == ID_AN7583) @@ -2722,14 +2722,16 @@ mt7531_setup(struct dsa_switch *ds) * MT7531AE. Set the GPIO 11-12 pins to function as MDC and MDIO * to expose the MDIO bus of the switch. */ - mt7530_rmw(priv, MT7531_GPIO_MODE1, MT7531_GPIO11_RG_RXD2_MASK, - MT7531_EXT_P_MDC_11); - mt7530_rmw(priv, MT7531_GPIO_MODE1, MT7531_GPIO12_RG_RXD3_MASK, - MT7531_EXT_P_MDIO_12); + regmap_update_bits(priv->regmap, MT7531_GPIO_MODE1, + MT7531_GPIO11_RG_RXD2_MASK, + MT7531_EXT_P_MDC_11); + regmap_update_bits(priv->regmap, MT7531_GPIO_MODE1, + MT7531_GPIO12_RG_RXD3_MASK, + MT7531_EXT_P_MDIO_12); } - mt7530_rmw(priv, MT7531_GPIO_MODE0, MT7531_GPIO0_MASK, - MT7531_GPIO0_INTERRUPT); + regmap_update_bits(priv->regmap, MT7531_GPIO_MODE0, MT7531_GPIO0_MASK, + MT7531_GPIO0_INTERRUPT); /* Enable Energy-Efficient Ethernet (EEE) and PHY core PLL, since * phy_device has not yet been created provided for @@ -3005,7 +3007,8 @@ mt753x_phylink_mac_config(struct phylink_config *config, unsigned int mode, /* Are we connected to external phy */ if (port == 5 && dsa_is_user_port(ds, 5)) - mt7530_set(priv, MT753X_PMCR_P(port), PMCR_EXT_PHY); + regmap_set_bits(priv->regmap, MT753X_PMCR_P(port), + PMCR_EXT_PHY); } static void mt753x_phylink_mac_link_down(struct phylink_config *config, @@ -3015,7 +3018,8 @@ static void mt753x_phylink_mac_link_down(struct phylink_config *config, struct dsa_port *dp = dsa_phylink_to_port(config); struct mt7530_priv *priv = dp->ds->priv; - mt7530_clear(priv, MT753X_PMCR_P(dp->index), PMCR_LINK_SETTINGS_MASK); + regmap_clear_bits(priv->regmap, MT753X_PMCR_P(dp->index), + PMCR_LINK_SETTINGS_MASK); } static void mt753x_phylink_mac_link_up(struct phylink_config *config, @@ -3049,7 +3053,7 @@ static void mt753x_phylink_mac_link_up(struct phylink_config *config, mcr |= PMCR_FORCE_RX_FC_EN; } - mt7530_set(priv, MT753X_PMCR_P(dp->index), mcr); + regmap_set_bits(priv->regmap, MT753X_PMCR_P(dp->index), mcr); } static void mt753x_phylink_mac_disable_tx_lpi(struct phylink_config *config) @@ -3057,8 +3061,8 @@ static void mt753x_phylink_mac_disable_tx_lpi(struct phylink_config *config) struct dsa_port *dp = dsa_phylink_to_port(config); struct mt7530_priv *priv = dp->ds->priv; - mt7530_clear(priv, MT753X_PMCR_P(dp->index), - PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100); + regmap_clear_bits(priv->regmap, MT753X_PMCR_P(dp->index), + PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100); } static int mt753x_phylink_mac_enable_tx_lpi(struct phylink_config *config, @@ -3079,11 +3083,11 @@ static int mt753x_phylink_mac_enable_tx_lpi(struct phylink_config *config, else val = LPI_THRESH_MASK; - mt7530_rmw(priv, MT753X_PMEEECR_P(dp->index), - LPI_THRESH_MASK | LPI_MODE_EN, val); + regmap_update_bits(priv->regmap, MT753X_PMEEECR_P(dp->index), + LPI_THRESH_MASK | LPI_MODE_EN, val); - mt7530_set(priv, MT753X_PMCR_P(dp->index), - PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100); + regmap_set_bits(priv->regmap, MT753X_PMCR_P(dp->index), + PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100); return 0; } @@ -3268,7 +3272,8 @@ mt753x_conduit_state_change(struct dsa_switch *ds, MT7530_CPU_PORT(__ffs(priv->active_cpu_ports)); } - mt7530_rmw(priv, MT753X_MFC, MT7530_CPU_EN | MT7530_CPU_PORT_MASK, val); + regmap_update_bits(priv->regmap, MT753X_MFC, + MT7530_CPU_EN | MT7530_CPU_PORT_MASK, val); } static int mt753x_tc_setup_qdisc_tbf(struct dsa_switch *ds, int port, @@ -3285,8 +3290,8 @@ static int mt753x_tc_setup_qdisc_tbf(struct dsa_switch *ds, int port, case TC_TBF_DESTROY: { u32 val, tick; - mt7530_rmw(priv, MT753X_GERLCR, EGR_BC_MASK, - EGR_BC_CRC_IPG_PREAMBLE); + regmap_update_bits(priv->regmap, MT753X_GERLCR, EGR_BC_MASK, + EGR_BC_CRC_IPG_PREAMBLE); /* if rate is greater than 10Mbps tick is 1/32 ms, * 1ms otherwise @@ -3330,13 +3335,13 @@ static int mt7988_setup(struct dsa_switch *ds) /* AN7583 require additional tweak to CONN_CFG */ if (priv->id == ID_AN7583) - mt7530_rmw(priv, AN7583_GEPHY_CONN_CFG, - AN7583_CSR_DPHY_CKIN_SEL | - AN7583_CSR_PHY_CORE_REG_CLK_SEL | - AN7583_CSR_ETHER_AFE_PWD, - AN7583_CSR_DPHY_CKIN_SEL | - AN7583_CSR_PHY_CORE_REG_CLK_SEL | - FIELD_PREP(AN7583_CSR_ETHER_AFE_PWD, 0)); + regmap_update_bits(priv->regmap, AN7583_GEPHY_CONN_CFG, + AN7583_CSR_DPHY_CKIN_SEL | + AN7583_CSR_PHY_CORE_REG_CLK_SEL | + AN7583_CSR_ETHER_AFE_PWD, + AN7583_CSR_DPHY_CKIN_SEL | + AN7583_CSR_PHY_CORE_REG_CLK_SEL | + FIELD_PREP(AN7583_CSR_ETHER_AFE_PWD, 0)); /* Reset the switch PHYs */ regmap_write(priv->regmap, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST); From 10d9d8328e8ab4503ef44b7fc958bf57364a2e09 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:38:35 +0100 Subject: [PATCH 0104/2126] net: dsa: mt7530: replace mt7530_read with regmap_read Replace all mt7530_read() calls with direct regmap_read() calls and remove the wrapper function. The wrapper returned 0 on failed reads; preserve that behaviour by zeroing the read-back buffer at the start of mt7530_regmap_read(), so callers that do not check the return code keep seeing a deterministic value. The WARN_ON_ONCE error logging is dropped. Most callsites follow the val = mt7530_read(priv, reg) pattern and are converted mechanically using the following semantic patch: @@ expression priv, reg; identifier val; @@ -val = mt7530_read(priv, reg); +regmap_read(priv->regmap, reg, &val); Remaining inline uses are converted by hand. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/a1dc338ae368554ec6faa974df7ba6f3660ae12b.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530-mdio.c | 3 + drivers/net/dsa/mt7530.c | 119 +++++++++++++++++----------------- 2 files changed, 63 insertions(+), 59 deletions(-) diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c index 422f785d2143..81c5c6f7066d 100644 --- a/drivers/net/dsa/mt7530-mdio.c +++ b/drivers/net/dsa/mt7530-mdio.c @@ -48,6 +48,9 @@ mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val) u16 page, r, lo, hi; int ret; + /* Callers do not check for errors, keep the value deterministic */ + *val = 0; + page = (reg >> 6) & 0x3ff; r = (reg >> 2) & 0xf; diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 0ff8a9eda3e4..57f38d39058a 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -154,27 +154,14 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) core_rmw(priv, reg, val, 0); } -static u32 -mt7530_read(struct mt7530_priv *priv, u32 reg) -{ - int ret; - u32 val; - - ret = regmap_read(priv->regmap, reg, &val); - if (ret) { - WARN_ON_ONCE(1); - dev_err(priv->dev, - "failed to read mt7530 register\n"); - return 0; - } - - return val; -} - static u32 mt7530_mii_poll(struct mt7530_dummy_poll *p) { - return mt7530_read(p->priv, p->reg); + u32 val; + + regmap_read(p->priv->regmap, p->reg, &val); + + return val; } static int @@ -219,7 +206,8 @@ mt7530_fdb_read(struct mt7530_priv *priv, struct mt7530_fdb *fdb) /* Read from ARL table into an array */ for (i = 0; i < 3; i++) { - reg[i] = mt7530_read(priv, MT7530_TSRA1 + (i * 4)); + regmap_read(priv->regmap, MT7530_TSRA1 + (i * 4), + ®[i]); dev_dbg(priv->dev, "%s(%d) reg[%d]=0x%x\n", __func__, __LINE__, i, reg[i]); @@ -326,7 +314,8 @@ mt7530_setup_port6(struct dsa_switch *ds, phy_interface_t interface) regmap_update_bits(priv->regmap, MT7530_P6ECR, P6_INTF_MODE_MASK, P6_INTF_MODE(1)); - xtal = mt7530_read(priv, MT753X_MTRAP) & MT7530_XTAL_MASK; + regmap_read(priv->regmap, MT753X_MTRAP, &xtal); + xtal &= MT7530_XTAL_MASK; if (xtal == MT7530_XTAL_25MHZ) ssc_delta = 0x57; @@ -370,9 +359,9 @@ mt7531_pll_setup(struct mt7530_priv *priv) u32 hwstrap; u32 val; - val = mt7530_read(priv, MT7531_CREV); - top_sig = mt7530_read(priv, MT7531_TOP_SIG_SR); - hwstrap = mt7530_read(priv, MT753X_TRAP); + regmap_read(priv->regmap, MT7531_CREV, &val); + regmap_read(priv->regmap, MT7531_TOP_SIG_SR, &top_sig); + regmap_read(priv->regmap, MT753X_TRAP, &hwstrap); if ((val & CHIP_REV_M) > 0) xtal = (top_sig & PAD_MCM_SMI_EN) ? MT7531_XTAL_FSEL_40MHZ : MT7531_XTAL_FSEL_25MHZ; @@ -381,26 +370,26 @@ mt7531_pll_setup(struct mt7530_priv *priv) MT7531_XTAL_FSEL_40MHZ; /* Step 1 : Disable MT7531 COREPLL */ - val = mt7530_read(priv, MT7531_PLLGP_EN); + regmap_read(priv->regmap, MT7531_PLLGP_EN, &val); val &= ~EN_COREPLL; regmap_write(priv->regmap, MT7531_PLLGP_EN, val); /* Step 2: switch to XTAL output */ - val = mt7530_read(priv, MT7531_PLLGP_EN); + regmap_read(priv->regmap, MT7531_PLLGP_EN, &val); val |= SW_CLKSW; regmap_write(priv->regmap, MT7531_PLLGP_EN, val); - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val &= ~RG_COREPLL_EN; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); /* Step 3: disable PLLGP and enable program PLLGP */ - val = mt7530_read(priv, MT7531_PLLGP_EN); + regmap_read(priv->regmap, MT7531_PLLGP_EN, &val); val |= SW_PLLGP; regmap_write(priv->regmap, MT7531_PLLGP_EN, val); /* Step 4: program COREPLL output frequency to 500MHz */ - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val &= ~RG_COREPLL_POSDIV_M; val |= 2 << RG_COREPLL_POSDIV_S; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); @@ -408,13 +397,13 @@ mt7531_pll_setup(struct mt7530_priv *priv) switch (xtal) { case MT7531_XTAL_FSEL_25MHZ: - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val &= ~RG_COREPLL_SDM_PCW_M; val |= 0x140000 << RG_COREPLL_SDM_PCW_S; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); break; case MT7531_XTAL_FSEL_40MHZ: - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val &= ~RG_COREPLL_SDM_PCW_M; val |= 0x190000 << RG_COREPLL_SDM_PCW_S; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); @@ -422,14 +411,14 @@ mt7531_pll_setup(struct mt7530_priv *priv) } /* Set feedback divide ratio update signal to high */ - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val |= RG_COREPLL_SDM_PCW_CHG; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); /* Wait for at least 16 XTAL clocks */ usleep_range(10, 20); /* Step 5: set feedback divide ratio update signal to low */ - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val &= ~RG_COREPLL_SDM_PCW_CHG; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); @@ -440,11 +429,11 @@ mt7531_pll_setup(struct mt7530_priv *priv) regmap_write(priv->regmap, MT7531_ANA_PLLGP_CR2, 0x4f40000); /* Step 6: Enable MT7531 PLL */ - val = mt7530_read(priv, MT7531_PLLGP_CR0); + regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); val |= RG_COREPLL_EN; regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); - val = mt7530_read(priv, MT7531_PLLGP_EN); + regmap_read(priv->regmap, MT7531_PLLGP_EN, &val); val |= EN_COREPLL; regmap_write(priv->regmap, MT7531_PLLGP_EN, val); usleep_range(25, 35); @@ -709,11 +698,11 @@ mt7530_read_port_stats(struct mt7530_priv *priv, int port, { u32 val, reg = MT7530_PORT_MIB_COUNTER(port) + offset; - val = mt7530_read(priv, reg); + regmap_read(priv->regmap, reg, &val); *data = val; if (size == 2) { - val = mt7530_read(priv, reg + 4); + regmap_read(priv->regmap, reg + 4, &val); *data |= (u64)val << 32; } } @@ -1017,11 +1006,11 @@ static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface) { struct mt7530_priv *priv = ds->priv; u8 tx_delay = 0; - int val; + u32 val; mutex_lock(&priv->reg_mutex); - val = mt7530_read(priv, MT753X_MTRAP); + regmap_read(priv->regmap, MT753X_MTRAP, &val); val &= ~MT7530_P5_PHY0_SEL & ~MT7530_P5_MAC_SEL & ~MT7530_P5_RGMII_MODE; @@ -1389,7 +1378,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) if (!dsa_is_cpu_port(ds, port)) return 0; - val = mt7530_read(priv, MT7530_GMACCR); + regmap_read(priv->regmap, MT7530_GMACCR, &val); val &= ~MAX_RX_PKT_LEN_MASK; /* RX length also includes Ethernet header, MTK tag, and FCS length */ @@ -1802,14 +1791,16 @@ mt7530_port_mdb_add(struct dsa_switch *ds, int port, const u8 *addr = mdb->addr; u16 vid = mdb->vid; u8 port_mask = 0; + u32 val; int ret; mutex_lock(&priv->reg_mutex); mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP); - if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL)) - port_mask = (mt7530_read(priv, MT7530_ATRD) >> PORT_MAP) - & PORT_MAP_MASK; + if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL)) { + regmap_read(priv->regmap, MT7530_ATRD, &val); + port_mask = (val >> PORT_MAP) & PORT_MAP_MASK; + } port_mask |= BIT(port); mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT); @@ -1829,14 +1820,16 @@ mt7530_port_mdb_del(struct dsa_switch *ds, int port, const u8 *addr = mdb->addr; u16 vid = mdb->vid; u8 port_mask = 0; + u32 val; int ret; mutex_lock(&priv->reg_mutex); mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP); - if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL)) - port_mask = (mt7530_read(priv, MT7530_ATRD) >> PORT_MAP) - & PORT_MAP_MASK; + if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL)) { + regmap_read(priv->regmap, MT7530_ATRD, &val); + port_mask = (val >> PORT_MAP) & PORT_MAP_MASK; + } port_mask &= ~BIT(port); mt7530_fdb_write(priv, vid, port_mask, addr, -1, @@ -1914,7 +1907,7 @@ mt7530_hw_vlan_del(struct mt7530_priv *priv, new_members = entry->old_members & ~BIT(entry->port); - val = mt7530_read(priv, MT7530_VAWD1); + regmap_read(priv->regmap, MT7530_VAWD1, &val); if (!(val & VLAN_VALID)) { dev_err(priv->dev, "Cannot be deleted due to invalid entry\n"); @@ -1941,7 +1934,7 @@ mt7530_hw_vlan_update(struct mt7530_priv *priv, u16 vid, /* Fetch entry */ mt7530_vlan_cmd(priv, MT7530_VTCR_RD_VID, vid); - val = mt7530_read(priv, MT7530_VAWD1); + regmap_read(priv->regmap, MT7530_VAWD1, &val); entry->old_members = (val >> PORT_MEM_SHFT) & PORT_MEM_MASK; @@ -2059,7 +2052,7 @@ static int mt753x_port_mirror_add(struct dsa_switch *ds, int port, if ((ingress ? priv->mirror_rx : priv->mirror_tx) & BIT(port)) return -EEXIST; - val = mt7530_read(priv, MT753X_MIRROR_REG(priv->id)); + regmap_read(priv->regmap, MT753X_MIRROR_REG(priv->id), &val); /* MT7530 only supports one monitor port */ monitor_port = MT753X_MIRROR_PORT_GET(priv->id, val); @@ -2072,7 +2065,7 @@ static int mt753x_port_mirror_add(struct dsa_switch *ds, int port, val |= MT753X_MIRROR_PORT_SET(priv->id, mirror->to_local_port); regmap_write(priv->regmap, MT753X_MIRROR_REG(priv->id), val); - val = mt7530_read(priv, MT7530_PCR_P(port)); + regmap_read(priv->regmap, MT7530_PCR_P(port), &val); if (ingress) { val |= PORT_RX_MIR; priv->mirror_rx |= BIT(port); @@ -2091,7 +2084,7 @@ static void mt753x_port_mirror_del(struct dsa_switch *ds, int port, struct mt7530_priv *priv = ds->priv; u32 val; - val = mt7530_read(priv, MT7530_PCR_P(port)); + regmap_read(priv->regmap, MT7530_PCR_P(port), &val); if (mirror->ingress) { val &= ~PORT_RX_MIR; priv->mirror_rx &= ~BIT(port); @@ -2102,7 +2095,7 @@ static void mt753x_port_mirror_del(struct dsa_switch *ds, int port, regmap_write(priv->regmap, MT7530_PCR_P(port), val); if (!priv->mirror_rx && !priv->mirror_tx) { - val = mt7530_read(priv, MT753X_MIRROR_REG(priv->id)); + regmap_read(priv->regmap, MT753X_MIRROR_REG(priv->id), &val); val &= ~MT753X_MIRROR_EN(priv->id); regmap_write(priv->regmap, MT753X_MIRROR_REG(priv->id), val); } @@ -2134,8 +2127,11 @@ mt7530_gpio_get(struct gpio_chip *gc, unsigned int offset) { struct mt7530_priv *priv = gpiochip_get_data(gc); u32 bit = mt7530_gpio_to_bit(offset); + u32 val; - return !!(mt7530_read(priv, MT7530_LED_GPIO_DATA) & bit); + regmap_read(priv->regmap, MT7530_LED_GPIO_DATA, &val); + + return !!(val & bit); } static int @@ -2157,8 +2153,11 @@ mt7530_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) { struct mt7530_priv *priv = gpiochip_get_data(gc); u32 bit = mt7530_gpio_to_bit(offset); + u32 val; - return (mt7530_read(priv, MT7530_LED_GPIO_DIR) & bit) ? + regmap_read(priv->regmap, MT7530_LED_GPIO_DIR, &val); + + return (val & bit) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN; } @@ -2449,7 +2448,7 @@ mt7530_setup(struct dsa_switch *ds) return ret; } - id = mt7530_read(priv, MT7530_CREV); + regmap_read(priv->regmap, MT7530_CREV, &id); id >>= CHIP_NAME_SHIFT; if (id != MT7530_ID) { dev_err(priv->dev, "chip %x can't be supported\n", id); @@ -2692,7 +2691,7 @@ mt7531_setup(struct dsa_switch *ds) return ret; } - id = mt7530_read(priv, MT7531_CREV); + regmap_read(priv->regmap, MT7531_CREV, &id); id >>= CHIP_NAME_SHIFT; if (id != MT7531_ID) { @@ -2703,7 +2702,7 @@ mt7531_setup(struct dsa_switch *ds) /* MT7531AE has got two SGMII units. One for port 5, one for port 6. * MT7531BE has got only one SGMII unit which is for port 6. */ - val = mt7530_read(priv, MT7531_TOP_SIG_SR); + regmap_read(priv->regmap, MT7531_TOP_SIG_SR, &val); priv->p5_sgmii = !!(val & PAD_DUAL_SGMII_EN); /* Force link down on all ports before internal reset */ @@ -2923,7 +2922,7 @@ static void mt7531_rgmii_setup(struct mt7530_priv *priv, { u32 val; - val = mt7530_read(priv, MT7531_CLKGEN_CTRL); + regmap_read(priv->regmap, MT7531_CLKGEN_CTRL, &val); val |= GP_CLK_EN; val &= ~GP_MODE_MASK; val |= GP_MODE(MT7531_GP_MODE_RGMII); @@ -3106,7 +3105,9 @@ static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port, * userspace. */ if (priv->id != ID_EN7528) { - u32 eeecr = mt7530_read(priv, MT753X_PMEEECR_P(port)); + u32 eeecr; + + regmap_read(priv->regmap, MT753X_PMEEECR_P(port), &eeecr); config->lpi_capabilities = MAC_100FD | MAC_1000FD | MAC_2500FD; /* tx_lpi_timer should be in microseconds. The time units for @@ -3137,7 +3138,7 @@ static void mt7530_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, int port = pcs_to_mt753x_pcs(pcs)->port; u32 pmsr; - pmsr = mt7530_read(priv, MT7530_PMSR_P(port)); + regmap_read(priv->regmap, MT7530_PMSR_P(port), &pmsr); state->link = (pmsr & PMSR_LINK); state->an_complete = state->link; From d7110c1dab444c76048244f585532c276a58f93a Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:38:46 +0100 Subject: [PATCH 0105/2126] net: dsa: mt7530: drop the dummy poll machinery Convert the two remaining switch reset polls to regmap_read_poll_timeout() and remove struct mt7530_dummy_poll, INIT_MT7530_DUMMY_POLL() and the mt7530_mii_poll() helper. As with the command polls addressed by the preceding fixes, a failed read now terminates the poll with an error instead of being fed to the loop condition as a zero value. Generated using the following semantic patch, plus removal of the two now-unused definitions from mt7530.h: // Poll the register through regmap so a failed read ends the poll. @@ expression priv, reg; identifier p, ret, val; @@ - INIT_MT7530_DUMMY_POLL(&p, priv, reg); - ret = readx_poll_timeout(mt7530_mii_poll, &p, val, val != 0, - 20, 1000000); + ret = regmap_read_poll_timeout(priv->regmap, reg, val, val != 0, + 20, 1000000); @@ identifier p; @@ - struct mt7530_dummy_poll p; ... when != p @@ identifier p; type T; @@ -static T mt7530_mii_poll(struct mt7530_dummy_poll *p) { ... } Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/609dcd8dd0c335e36bbc8df41413da58af1dbfb4.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 22 ++++------------------ drivers/net/dsa/mt7530.h | 12 ------------ 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 57f38d39058a..9a56b6875ad7 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -154,16 +154,6 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) core_rmw(priv, reg, val, 0); } -static u32 -mt7530_mii_poll(struct mt7530_dummy_poll *p) -{ - u32 val; - - regmap_read(p->priv->regmap, p->reg, &val); - - return val; -} - static int mt7530_fdb_cmd(struct mt7530_priv *priv, enum mt7530_fdb_cmd cmd, u32 *rsp) { @@ -2379,7 +2369,6 @@ mt7530_setup(struct dsa_switch *ds) struct device_node *dn = NULL; struct device_node *phy_node; struct device_node *mac_np; - struct mt7530_dummy_poll p; phy_interface_t interface; struct dsa_port *cpu_dp; u32 id, val; @@ -2440,9 +2429,8 @@ mt7530_setup(struct dsa_switch *ds) } /* Waiting for MT7530 got to stable */ - INIT_MT7530_DUMMY_POLL(&p, priv, MT753X_TRAP); - ret = readx_poll_timeout(mt7530_mii_poll, &p, val, val != 0, - 20, 1000000); + ret = regmap_read_poll_timeout(priv->regmap, MT753X_TRAP, val, + val != 0, 20, 1000000); if (ret < 0) { dev_err(priv->dev, "reset timeout\n"); return ret; @@ -2665,7 +2653,6 @@ static int mt7531_setup(struct dsa_switch *ds) { struct mt7530_priv *priv = ds->priv; - struct mt7530_dummy_poll p; u32 val, id; int ret, i; @@ -2683,9 +2670,8 @@ mt7531_setup(struct dsa_switch *ds) } /* Waiting for MT7530 got to stable */ - INIT_MT7530_DUMMY_POLL(&p, priv, MT753X_TRAP); - ret = readx_poll_timeout(mt7530_mii_poll, &p, val, val != 0, - 20, 1000000); + ret = regmap_read_poll_timeout(priv->regmap, MT753X_TRAP, val, + val != 0, 20, 1000000); if (ret < 0) { dev_err(priv->dev, "reset timeout\n"); return ret; diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index 5f1e841f42c0..ae93bb263249 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -933,18 +933,6 @@ struct mt7530_hw_stats { u8 sizeof_stat; }; -struct mt7530_dummy_poll { - struct mt7530_priv *priv; - u32 reg; -}; - -static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p, - struct mt7530_priv *priv, u32 reg) -{ - p->priv = priv; - p->reg = reg; -} - int mt7530_probe_common(struct mt7530_priv *priv); void mt7530_remove_common(struct mt7530_priv *priv); From 3d8ca6f904750af5fb8a04d7f792e73fc24770ca Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:39:00 +0100 Subject: [PATCH 0106/2126] net: dsa: mt7530: convert to use field accessor macros Use FIELD_GET and FIELD_PREP instead of open-coding register fields. Replace 0x1f constant with (PHY_MAX_ADDR - 1). Some field macros (ATC_HASH, VTCR_VID and STAG_VPID) were previously defined as object-like macros referencing an undeclared 'x' and were therefore unusable; convert them into proper FIELD_PREP() accessors. The masks are equivalent to the open-coded values they replace, with one exception: mt7530_vlan_cmd() now masks vid through VTCR_VID(vid) instead of OR-ing it in raw, guarding the adjacent VTCR_FUNC field against any bits set above the 12-bit VID width. VLAN IDs are always in 0-4094, so this is a no-op in practice; it is a real hardening rather than a strictly equivalent mechanical substitution. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/bd4eaf10fb6aa7a1bd056514b61b4481175708a5.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 64 ++++++------ drivers/net/dsa/mt7530.h | 208 ++++++++++++++++++++++----------------- 2 files changed, 148 insertions(+), 124 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 9a56b6875ad7..4edb57676143 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -203,16 +203,16 @@ mt7530_fdb_read(struct mt7530_priv *priv, struct mt7530_fdb *fdb) __func__, __LINE__, i, reg[i]); } - fdb->vid = (reg[1] >> CVID) & CVID_MASK; - fdb->aging = (reg[2] >> AGE_TIMER) & AGE_TIMER_MASK; - fdb->port_mask = (reg[2] >> PORT_MAP) & PORT_MAP_MASK; - fdb->mac[0] = (reg[0] >> MAC_BYTE_0) & MAC_BYTE_MASK; - fdb->mac[1] = (reg[0] >> MAC_BYTE_1) & MAC_BYTE_MASK; - fdb->mac[2] = (reg[0] >> MAC_BYTE_2) & MAC_BYTE_MASK; - fdb->mac[3] = (reg[0] >> MAC_BYTE_3) & MAC_BYTE_MASK; - fdb->mac[4] = (reg[1] >> MAC_BYTE_4) & MAC_BYTE_MASK; - fdb->mac[5] = (reg[1] >> MAC_BYTE_5) & MAC_BYTE_MASK; - fdb->noarp = ((reg[2] >> ENT_STATUS) & ENT_STATUS_MASK) == STATIC_ENT; + fdb->vid = FIELD_GET(CVID_MASK, reg[1]); + fdb->aging = FIELD_GET(AGE_TIMER_MASK, reg[2]); + fdb->port_mask = FIELD_GET(PORT_MAP_MASK, reg[2]); + fdb->mac[0] = FIELD_GET(MAC_BYTE_0_MASK, reg[0]); + fdb->mac[1] = FIELD_GET(MAC_BYTE_1_MASK, reg[0]); + fdb->mac[2] = FIELD_GET(MAC_BYTE_2_MASK, reg[0]); + fdb->mac[3] = FIELD_GET(MAC_BYTE_3_MASK, reg[0]); + fdb->mac[4] = FIELD_GET(MAC_BYTE_4_MASK, reg[1]); + fdb->mac[5] = FIELD_GET(MAC_BYTE_5_MASK, reg[1]); + fdb->noarp = FIELD_GET(ENT_STATUS_MASK, reg[2]) == STATIC_ENT; } static void @@ -223,22 +223,22 @@ mt7530_fdb_write(struct mt7530_priv *priv, u16 vid, u32 reg[3] = { 0 }; int i; - reg[1] |= vid & CVID_MASK; + reg[1] |= FIELD_PREP(CVID_MASK, vid); reg[1] |= ATA2_IVL; reg[1] |= ATA2_FID(FID_BRIDGED); - reg[2] |= (aging & AGE_TIMER_MASK) << AGE_TIMER; - reg[2] |= (port_mask & PORT_MAP_MASK) << PORT_MAP; + reg[2] |= FIELD_PREP(AGE_TIMER_MASK, aging); + reg[2] |= FIELD_PREP(PORT_MAP_MASK, port_mask); /* STATIC_ENT indicate that entry is static wouldn't * be aged out and STATIC_EMP specified as erasing an * entry */ - reg[2] |= (type & ENT_STATUS_MASK) << ENT_STATUS; - reg[1] |= mac[5] << MAC_BYTE_5; - reg[1] |= mac[4] << MAC_BYTE_4; - reg[0] |= mac[3] << MAC_BYTE_3; - reg[0] |= mac[2] << MAC_BYTE_2; - reg[0] |= mac[1] << MAC_BYTE_1; - reg[0] |= mac[0] << MAC_BYTE_0; + reg[2] |= FIELD_PREP(ENT_STATUS_MASK, type); + reg[1] |= FIELD_PREP(MAC_BYTE_5_MASK, mac[5]); + reg[1] |= FIELD_PREP(MAC_BYTE_4_MASK, mac[4]); + reg[0] |= FIELD_PREP(MAC_BYTE_3_MASK, mac[3]); + reg[0] |= FIELD_PREP(MAC_BYTE_2_MASK, mac[2]); + reg[0] |= FIELD_PREP(MAC_BYTE_1_MASK, mac[1]); + reg[0] |= FIELD_PREP(MAC_BYTE_0_MASK, mac[0]); /* Write array into the ARL table */ for (i = 0; i < 3; i++) @@ -380,22 +380,22 @@ mt7531_pll_setup(struct mt7530_priv *priv) /* Step 4: program COREPLL output frequency to 500MHz */ regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); - val &= ~RG_COREPLL_POSDIV_M; - val |= 2 << RG_COREPLL_POSDIV_S; + val &= ~RG_COREPLL_POSDIV_MASK; + val |= RG_COREPLL_POSDIV(2); regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); usleep_range(25, 35); switch (xtal) { case MT7531_XTAL_FSEL_25MHZ: regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); - val &= ~RG_COREPLL_SDM_PCW_M; - val |= 0x140000 << RG_COREPLL_SDM_PCW_S; + val &= ~RG_COREPLL_SDM_PCW_MASK; + val |= RG_COREPLL_SDM_PCW(0x140000); regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); break; case MT7531_XTAL_FSEL_40MHZ: regmap_read(priv->regmap, MT7531_PLLGP_CR0, &val); - val &= ~RG_COREPLL_SDM_PCW_M; - val |= 0x190000 << RG_COREPLL_SDM_PCW_S; + val &= ~RG_COREPLL_SDM_PCW_MASK; + val |= RG_COREPLL_SDM_PCW(0x190000); regmap_write(priv->regmap, MT7531_PLLGP_CR0, val); break; } @@ -1555,7 +1555,7 @@ mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid) u32 val; int ret; - val = VTCR_BUSY | VTCR_FUNC(cmd) | vid; + val = VTCR_BUSY | VTCR_FUNC(cmd) | VTCR_VID(vid); ret = regmap_write(priv->regmap, MT7530_VTCR, val); if (ret) return ret; @@ -1789,7 +1789,7 @@ mt7530_port_mdb_add(struct dsa_switch *ds, int port, mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP); if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL)) { regmap_read(priv->regmap, MT7530_ATRD, &val); - port_mask = (val >> PORT_MAP) & PORT_MAP_MASK; + port_mask = FIELD_GET(PORT_MAP_MASK, val); } port_mask |= BIT(port); @@ -1818,7 +1818,7 @@ mt7530_port_mdb_del(struct dsa_switch *ds, int port, mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP); if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL)) { regmap_read(priv->regmap, MT7530_ATRD, &val); - port_mask = (val >> PORT_MAP) & PORT_MAP_MASK; + port_mask = FIELD_GET(PORT_MAP_MASK, val); } port_mask &= ~BIT(port); @@ -1926,7 +1926,7 @@ mt7530_hw_vlan_update(struct mt7530_priv *priv, u16 vid, regmap_read(priv->regmap, MT7530_VAWD1, &val); - entry->old_members = (val >> PORT_MEM_SHFT) & PORT_MEM_MASK; + entry->old_members = FIELD_GET(PORT_MEM_MASK, val); /* Manipulate entry */ vlan_op(priv, entry); @@ -2437,7 +2437,7 @@ mt7530_setup(struct dsa_switch *ds) } regmap_read(priv->regmap, MT7530_CREV, &id); - id >>= CHIP_NAME_SHIFT; + id = FIELD_GET(CHIP_NAME_MASK, id); if (id != MT7530_ID) { dev_err(priv->dev, "chip %x can't be supported\n", id); return -ENODEV; @@ -2678,7 +2678,7 @@ mt7531_setup(struct dsa_switch *ds) } regmap_read(priv->regmap, MT7531_CREV, &id); - id >>= CHIP_NAME_SHIFT; + id = FIELD_GET(CHIP_NAME_MASK, id); if (id != MT7531_ID) { dev_err(priv->dev, "chip %x can't be supported\n", id); diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index ae93bb263249..6a148938c60f 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -6,6 +6,8 @@ #ifndef __MT7530_H #define __MT7530_H +#include + #define MT7530_NUM_PORTS 7 #define MT7530_NUM_PHYS 5 #define MT7530_NUM_FDB_RECORDS 2048 @@ -147,19 +149,22 @@ enum mt753x_to_cpu_fw { #define STATIC_ENT 3 #define MT7530_ATA2 0x78 #define ATA2_IVL BIT(15) -#define ATA2_FID(x) (((x) & 0x7) << 12) +#define ATA2_FID_MASK GENMASK(14, 12) +#define ATA2_FID(x) FIELD_PREP(ATA2_FID_MASK, x) /* Register for address table write data */ #define MT7530_ATWD 0x7c /* Register for address table control */ #define MT7530_ATC 0x80 -#define ATC_HASH (((x) & 0xfff) << 16) +#define ATC_HASH_MASK GENMASK(27, 16) +#define ATC_HASH(x) FIELD_PREP(ATC_HASH_MASK, x) #define ATC_BUSY BIT(15) #define ATC_SRCH_END BIT(14) #define ATC_SRCH_HIT BIT(13) #define ATC_INVALID BIT(12) -#define ATC_MAT(x) (((x) & 0xf) << 8) +#define ATC_MAT_MASK GENMASK(11, 8) +#define ATC_MAT(x) FIELD_PREP(ATC_MAT_MASK, x) #define ATC_MAT_MACTAB ATC_MAT(0) enum mt7530_fdb_cmd { @@ -172,32 +177,29 @@ enum mt7530_fdb_cmd { /* Registers for table search read address */ #define MT7530_TSRA1 0x84 -#define MAC_BYTE_0 24 -#define MAC_BYTE_1 16 -#define MAC_BYTE_2 8 -#define MAC_BYTE_3 0 -#define MAC_BYTE_MASK 0xff +#define MAC_BYTE_0_MASK GENMASK(31, 24) +#define MAC_BYTE_1_MASK GENMASK(23, 16) +#define MAC_BYTE_2_MASK GENMASK(15, 8) +#define MAC_BYTE_3_MASK GENMASK(7, 0) #define MT7530_TSRA2 0x88 -#define MAC_BYTE_4 24 -#define MAC_BYTE_5 16 -#define CVID 0 -#define CVID_MASK 0xfff +#define MAC_BYTE_4_MASK GENMASK(31, 24) +#define MAC_BYTE_5_MASK GENMASK(23, 16) +#define CVID_MASK GENMASK(11, 0) #define MT7530_ATRD 0x8C -#define AGE_TIMER 24 -#define AGE_TIMER_MASK 0xff -#define PORT_MAP 4 -#define PORT_MAP_MASK 0xff -#define ENT_STATUS 2 -#define ENT_STATUS_MASK 0x3 +#define AGE_TIMER_MASK GENMASK(31, 24) +#define PORT_MAP_MASK GENMASK(11, 4) +#define ENT_STATUS_MASK GENMASK(3, 2) /* Register for vlan table control */ #define MT7530_VTCR 0x90 #define VTCR_BUSY BIT(31) #define VTCR_INVALID BIT(16) -#define VTCR_FUNC(x) (((x) & 0xf) << 12) -#define VTCR_VID ((x) & 0xfff) +#define VTCR_FUNC_MASK GENMASK(15, 12) +#define VTCR_FUNC(x) FIELD_PREP(VTCR_FUNC_MASK, x) +#define VTCR_VID_MASK GENMASK(11, 0) +#define VTCR_VID(x) FIELD_PREP(VTCR_VID_MASK, x) enum mt7530_vlan_cmd { /* Read/Write the specified VID entry from VAWD register based @@ -217,13 +219,13 @@ enum mt7530_vlan_cmd { /* Per VLAN Egress Tag Control */ #define VTAG_EN BIT(28) /* VLAN Member Control */ -#define PORT_MEM(x) (((x) & 0xff) << 16) +#define PORT_MEM_MASK GENMASK(23, 16) +#define PORT_MEM(x) FIELD_PREP(PORT_MEM_MASK, x) /* Filter ID */ -#define FID(x) (((x) & 0x7) << 1) +#define FID_MASK GENMASK(3, 1) +#define FID(x) FIELD_PREP(FID_MASK, x) /* VLAN Entry Valid */ #define VLAN_VALID BIT(0) -#define PORT_MEM_SHFT 16 -#define PORT_MEM_MASK 0xff enum mt7530_fid { FID_STANDALONE = 0, @@ -248,11 +250,11 @@ enum mt7530_vlan_egress_attr { /* Age count */ #define AGE_CNT_MASK GENMASK(19, 12) #define AGE_CNT_MAX 0xff -#define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12)) +#define AGE_CNT(x) FIELD_PREP(AGE_CNT_MASK, x) /* Age unit */ #define AGE_UNIT_MASK GENMASK(11, 0) #define AGE_UNIT_MAX 0xfff -#define AGE_UNIT(x) (AGE_UNIT_MASK & (x)) +#define AGE_UNIT(x) FIELD_PREP(AGE_UNIT_MASK, x) #define MT753X_ERLCR_P(x) (0x1040 + ((x) * 0x100)) #define ERLCR_CIR_MASK GENMASK(31, 16) @@ -283,30 +285,31 @@ enum mt7530_stp_state { #define MT7530_PCR_P(x) (0x2004 + ((x) * 0x100)) #define PORT_TX_MIR BIT(9) #define PORT_RX_MIR BIT(8) -#define PORT_VLAN(x) ((x) & 0x3) +#define PCR_PORT_VLAN_MASK GENMASK(1, 0) enum mt7530_port_mode { /* Port Matrix Mode: Frames are forwarded by the PCR_MATRIX members. */ - MT7530_PORT_MATRIX_MODE = PORT_VLAN(0), + MT7530_PORT_MATRIX_MODE = 0, /* Fallback Mode: Forward received frames with ingress ports that do * not belong to the VLAN member. Frames whose VID is not listed on * the VLAN table are forwarded by the PCR_MATRIX members. */ - MT7530_PORT_FALLBACK_MODE = PORT_VLAN(1), + MT7530_PORT_FALLBACK_MODE = 1, /* Security Mode: Discard any frame due to ingress membership * violation or VID missed on the VLAN table. */ - MT7530_PORT_SECURITY_MODE = PORT_VLAN(3), + MT7530_PORT_SECURITY_MODE = 3, }; -#define PCR_MATRIX(x) (((x) & 0xff) << 16) -#define PORT_PRI(x) (((x) & 0x7) << 24) -#define EG_TAG(x) (((x) & 0x3) << 28) -#define PCR_MATRIX_MASK PCR_MATRIX(0xff) +#define PCR_MATRIX_MASK GENMASK(23, 16) +#define PCR_MATRIX(x) FIELD_PREP(PCR_MATRIX_MASK, x) +#define PORT_PRI_MASK GENMASK(26, 24) +#define PORT_PRI(x) FIELD_PREP(PORT_PRI_MASK, x) +#define EG_TAG_MASK GENMASK(29, 28) +#define EG_TAG(x) FIELD_PREP(EG_TAG_MASK, x) #define PCR_MATRIX_CLR PCR_MATRIX(0) -#define PCR_PORT_VLAN_MASK PORT_VLAN(3) /* Register for port security control */ #define MT7530_PSC_P(x) (0x200c + ((x) * 0x100)) @@ -315,10 +318,10 @@ enum mt7530_port_mode { /* Register for port vlan control */ #define MT7530_PVC_P(x) (0x2010 + ((x) * 0x100)) #define PORT_SPEC_TAG BIT(5) -#define PVC_EG_TAG(x) (((x) & 0x7) << 8) -#define PVC_EG_TAG_MASK PVC_EG_TAG(7) -#define VLAN_ATTR(x) (((x) & 0x3) << 6) -#define VLAN_ATTR_MASK VLAN_ATTR(3) +#define PVC_EG_TAG_MASK GENMASK(10, 8) +#define PVC_EG_TAG(x) FIELD_PREP(PVC_EG_TAG_MASK, x) +#define VLAN_ATTR_MASK GENMASK(7, 6) +#define VLAN_ATTR(x) FIELD_PREP(VLAN_ATTR_MASK, x) #define ACC_FRM_MASK GENMASK(1, 0) enum mt7530_vlan_port_eg_tag { @@ -338,12 +341,13 @@ enum mt7530_vlan_port_acc_frm { MT7530_VLAN_ACC_UNTAGGED = 2, }; -#define STAG_VPID (((x) & 0xffff) << 16) +#define STAG_VPID_MASK GENMASK(31, 16) +#define STAG_VPID(x) FIELD_PREP(STAG_VPID_MASK, x) /* Register for port port-and-protocol based vlan 1 control */ #define MT7530_PPBV1_P(x) (0x2014 + ((x) * 0x100)) -#define G0_PORT_VID(x) (((x) & 0xfff) << 0) -#define G0_PORT_VID_MASK G0_PORT_VID(0xfff) +#define G0_PORT_VID_MASK GENMASK(11, 0) +#define G0_PORT_VID(x) FIELD_PREP(G0_PORT_VID_MASK, x) #define G0_PORT_VID_DEF G0_PORT_VID(0) /* Register for port MAC control register */ @@ -419,8 +423,8 @@ enum mt7530_vlan_port_acc_frm { #define MT7531_DIS_CLR BIT(31) #define MT7530_GMACCR 0x30e0 -#define MAX_RX_JUMBO(x) ((x) << 2) #define MAX_RX_JUMBO_MASK GENMASK(5, 2) +#define MAX_RX_JUMBO(x) FIELD_PREP(MAX_RX_JUMBO_MASK, x) #define MAX_RX_PKT_LEN_MASK GENMASK(1, 0) #define MAX_RX_PKT_LEN_1522 0x0 #define MAX_RX_PKT_LEN_1536 0x1 @@ -506,16 +510,16 @@ enum mt7530_vlan_port_acc_frm { /* Register for PHY Indirect Access Control */ #define MT7531_PHY_IAC 0x701C #define MT7531_PHY_ACS_ST BIT(31) -#define MT7531_MDIO_REG_ADDR_MASK (0x1f << 25) -#define MT7531_MDIO_PHY_ADDR_MASK (0x1f << 20) -#define MT7531_MDIO_CMD_MASK (0x3 << 18) -#define MT7531_MDIO_ST_MASK (0x3 << 16) -#define MT7531_MDIO_RW_DATA_MASK (0xffff) -#define MT7531_MDIO_REG_ADDR(x) (((x) & 0x1f) << 25) -#define MT7531_MDIO_DEV_ADDR(x) (((x) & 0x1f) << 25) -#define MT7531_MDIO_PHY_ADDR(x) (((x) & 0x1f) << 20) -#define MT7531_MDIO_CMD(x) (((x) & 0x3) << 18) -#define MT7531_MDIO_ST(x) (((x) & 0x3) << 16) +#define MT7531_MDIO_REG_ADDR_MASK GENMASK(29, 25) +#define MT7531_MDIO_PHY_ADDR_MASK GENMASK(24, 20) +#define MT7531_MDIO_CMD_MASK GENMASK(19, 18) +#define MT7531_MDIO_ST_MASK GENMASK(17, 16) +#define MT7531_MDIO_RW_DATA_MASK GENMASK(15, 0) +#define MT7531_MDIO_REG_ADDR(x) FIELD_PREP(MT7531_MDIO_REG_ADDR_MASK, x) +#define MT7531_MDIO_DEV_ADDR(x) FIELD_PREP(MT7531_MDIO_REG_ADDR_MASK, x) +#define MT7531_MDIO_PHY_ADDR(x) FIELD_PREP(MT7531_MDIO_PHY_ADDR_MASK, x) +#define MT7531_MDIO_CMD(x) FIELD_PREP(MT7531_MDIO_CMD_MASK, x) +#define MT7531_MDIO_ST(x) FIELD_PREP(MT7531_MDIO_ST_MASK, x) enum mt7531_phy_iac_cmd { MT7531_MDIO_ADDR = 0, @@ -543,14 +547,14 @@ enum mt7531_mdio_st { /* Register for RGMII clock phase */ #define MT7531_CLKGEN_CTRL 0x7500 -#define CLK_SKEW_OUT(x) (((x) & 0x3) << 8) #define CLK_SKEW_OUT_MASK GENMASK(9, 8) -#define CLK_SKEW_IN(x) (((x) & 0x3) << 6) +#define CLK_SKEW_OUT(x) FIELD_PREP(CLK_SKEW_OUT_MASK, x) #define CLK_SKEW_IN_MASK GENMASK(7, 6) +#define CLK_SKEW_IN(x) FIELD_PREP(CLK_SKEW_IN_MASK, x) #define RXCLK_NO_DELAY BIT(5) #define TXCLK_NO_REVERSE BIT(4) -#define GP_MODE(x) (((x) & 0x3) << 1) #define GP_MODE_MASK GENMASK(2, 1) +#define GP_MODE(x) FIELD_PREP(GP_MODE_MASK, x) #define GP_CLK_EN BIT(0) enum mt7531_gp_mode { @@ -600,8 +604,10 @@ enum mt7531_xtal_fsel { #define PAD_MCM_SMI_EN BIT(0) #define MT7530_IO_DRV_CR 0x7810 -#define P5_IO_CLK_DRV(x) ((x) & 0x3) -#define P5_IO_DATA_DRV(x) (((x) & 0x3) << 4) +#define P5_IO_CLK_DRV_MASK GENMASK(1, 0) +#define P5_IO_CLK_DRV(x) FIELD_PREP(P5_IO_CLK_DRV_MASK, x) +#define P5_IO_DATA_DRV_MASK GENMASK(5, 4) +#define P5_IO_DATA_DRV(x) FIELD_PREP(P5_IO_DATA_DRV_MASK, x) #define MT7531_CHIP_REV 0x781C @@ -611,15 +617,15 @@ enum mt7531_xtal_fsel { #define SW_PLLGP BIT(0) #define MT7530_P6ECR 0x7830 -#define P6_INTF_MODE_MASK 0x3 -#define P6_INTF_MODE(x) ((x) & 0x3) +#define P6_INTF_MODE_MASK GENMASK(1, 0) +#define P6_INTF_MODE(x) FIELD_PREP(P6_INTF_MODE_MASK, x) #define MT7531_PLLGP_CR0 0x78a8 #define RG_COREPLL_EN BIT(22) -#define RG_COREPLL_POSDIV_S 23 -#define RG_COREPLL_POSDIV_M 0x3800000 -#define RG_COREPLL_SDM_PCW_S 1 -#define RG_COREPLL_SDM_PCW_M 0x3ffffe +#define RG_COREPLL_POSDIV_MASK GENMASK(25, 23) +#define RG_COREPLL_POSDIV(x) FIELD_PREP(RG_COREPLL_POSDIV_MASK, x) +#define RG_COREPLL_SDM_PCW_MASK GENMASK(21, 1) +#define RG_COREPLL_SDM_PCW(x) FIELD_PREP(RG_COREPLL_SDM_PCW_MASK, x) #define RG_COREPLL_SDM_PCW_CHG BIT(0) /* Registers for RGMII and SGMII PLL clock */ @@ -630,10 +636,10 @@ enum mt7531_xtal_fsel { #define MT7530_TRGMII_RCK_CTRL 0x7a00 #define RX_RST BIT(31) #define RXC_DQSISEL BIT(30) -#define DQSI1_TAP_MASK (0x7f << 8) -#define DQSI0_TAP_MASK 0x7f -#define DQSI1_TAP(x) (((x) & 0x7f) << 8) -#define DQSI0_TAP(x) ((x) & 0x7f) +#define DQSI1_TAP_MASK GENMASK(14, 8) +#define DQSI0_TAP_MASK GENMASK(6, 0) +#define DQSI1_TAP(x) FIELD_PREP(DQSI1_TAP_MASK, x) +#define DQSI0_TAP(x) FIELD_PREP(DQSI0_TAP_MASK, x) #define MT7530_TRGMII_RCK_RTT 0x7a04 #define DQS1_GATE BIT(31) @@ -642,8 +648,8 @@ enum mt7531_xtal_fsel { #define MT7530_TRGMII_RD(x) (0x7a10 + (x) * 8) #define BSLIP_EN BIT(31) #define EDGE_CHK BIT(30) -#define RD_TAP_MASK 0x7f -#define RD_TAP(x) ((x) & 0x7f) +#define RD_TAP_MASK GENMASK(6, 0) +#define RD_TAP(x) FIELD_PREP(RD_TAP_MASK, x) #define MT7530_TRGMII_TXCTRL 0x7a40 #define TRAIN_TXEN BIT(31) @@ -651,18 +657,23 @@ enum mt7531_xtal_fsel { #define TX_RST BIT(28) #define MT7530_TRGMII_TD_ODT(i) (0x7a54 + 8 * (i)) -#define TD_DM_DRVP(x) ((x) & 0xf) -#define TD_DM_DRVN(x) (((x) & 0xf) << 4) +#define TD_DM_DRVP_MASK GENMASK(3, 0) +#define TD_DM_DRVP(x) FIELD_PREP(TD_DM_DRVP_MASK, x) +#define TD_DM_DRVN_MASK GENMASK(7, 4) +#define TD_DM_DRVN(x) FIELD_PREP(TD_DM_DRVN_MASK, x) #define MT7530_TRGMII_TCK_CTRL 0x7a78 -#define TCK_TAP(x) (((x) & 0xf) << 8) +#define TCK_TAP_MASK GENMASK(11, 8) +#define TCK_TAP(x) FIELD_PREP(TCK_TAP_MASK, x) #define MT7530_P5RGMIIRXCR 0x7b00 #define CSR_RGMII_EDGE_ALIGN BIT(8) -#define CSR_RGMII_RXC_0DEG_CFG(x) ((x) & 0xf) +#define CSR_RGMII_RXC_0DEG_CFG_MASK GENMASK(3, 0) +#define CSR_RGMII_RXC_0DEG_CFG(x) FIELD_PREP(CSR_RGMII_RXC_0DEG_CFG_MASK, x) #define MT7530_P5RGMIITXCR 0x7b04 -#define CSR_RGMII_TXC_CFG(x) ((x) & 0x1f) +#define CSR_RGMII_TXC_CFG_MASK GENMASK(4, 0) +#define CSR_RGMII_TXC_CFG(x) FIELD_PREP(CSR_RGMII_TXC_CFG_MASK, x) /* Registers for GPIO mode */ #define MT7531_GPIO_MODE0 0x7c0c @@ -671,9 +682,9 @@ enum mt7531_xtal_fsel { #define MT7531_GPIO_MODE1 0x7c10 #define MT7531_GPIO11_RG_RXD2_MASK GENMASK(15, 12) -#define MT7531_EXT_P_MDC_11 (2 << 12) +#define MT7531_EXT_P_MDC_11 FIELD_PREP(MT7531_GPIO11_RG_RXD2_MASK, 2) #define MT7531_GPIO12_RG_RXD3_MASK GENMASK(19, 16) -#define MT7531_EXT_P_MDIO_12 (2 << 16) +#define MT7531_EXT_P_MDIO_12 FIELD_PREP(MT7531_GPIO12_RG_RXD3_MASK, 2) #define MT753X_CPORT_SPTAG_CFG 0x7c10 #define CPORT_SW2FE_STAG_EN BIT(1) @@ -705,7 +716,7 @@ enum mt7531_xtal_fsel { #define MT7530_LED_GPIO_DATA 0x7d18 #define MT7530_CREV 0x7ffc -#define CHIP_NAME_SHIFT 16 +#define CHIP_NAME_MASK GENMASK(31, 16) #define MT7530_ID 0x7530 #define MT7531_CREV 0x781C @@ -717,10 +728,13 @@ enum mt7531_xtal_fsel { #define RG_SYSPLL_EN_NORMAL BIT(15) #define RG_SYSPLL_VODEN BIT(14) #define RG_SYSPLL_LF BIT(13) -#define RG_SYSPLL_RST_DLY(x) (((x) & 0x3) << 12) +#define RG_SYSPLL_RST_DLY_MASK GENMASK(13, 12) +#define RG_SYSPLL_RST_DLY(x) FIELD_PREP(RG_SYSPLL_RST_DLY_MASK, x) #define RG_SYSPLL_LVROD_EN BIT(10) -#define RG_SYSPLL_PREDIV(x) (((x) & 0x3) << 8) -#define RG_SYSPLL_POSDIV(x) (((x) & 0x3) << 5) +#define RG_SYSPLL_PREDIV_MASK GENMASK(9, 8) +#define RG_SYSPLL_PREDIV(x) FIELD_PREP(RG_SYSPLL_PREDIV_MASK, x) +#define RG_SYSPLL_POSDIV_MASK GENMASK(6, 5) +#define RG_SYSPLL_POSDIV(x) FIELD_PREP(RG_SYSPLL_POSDIV_MASK, x) #define RG_SYSPLL_FBKSEL BIT(4) #define RT_SYSPLL_EN_AFE_OLT BIT(0) @@ -732,38 +746,48 @@ enum mt7531_xtal_fsel { #define MT7531_PHY_PLL_OFF BIT(5) #define MT7531_PHY_PLL_BYPASS_MODE BIT(4) -#define MT753X_CTRL_PHY_ADDR(addr) ((addr + 1) & 0x1f) +#define MT753X_CTRL_PHY_ADDR(addr) (((addr) + 1) & (PHY_MAX_ADDR - 1)) #define CORE_PLL_GROUP5 0x404 -#define RG_LCDDS_PCW_NCPO1(x) ((x) & 0xffff) +#define RG_LCDDS_PCW_NCPO1_MASK GENMASK(15, 0) +#define RG_LCDDS_PCW_NCPO1(x) FIELD_PREP(RG_LCDDS_PCW_NCPO1_MASK, x) #define CORE_PLL_GROUP6 0x405 -#define RG_LCDDS_PCW_NCPO0(x) ((x) & 0xffff) +#define RG_LCDDS_PCW_NCPO0_MASK GENMASK(15, 0) +#define RG_LCDDS_PCW_NCPO0(x) FIELD_PREP(RG_LCDDS_PCW_NCPO0_MASK, x) #define CORE_PLL_GROUP7 0x406 #define RG_LCDDS_PWDB BIT(15) #define RG_LCDDS_ISO_EN BIT(13) -#define RG_LCCDS_C(x) (((x) & 0x7) << 4) +#define RG_LCCDS_C_MASK GENMASK(6, 4) +#define RG_LCCDS_C(x) FIELD_PREP(RG_LCCDS_C_MASK, x) #define RG_LCDDS_PCW_NCPO_CHG BIT(3) #define CORE_PLL_GROUP10 0x409 -#define RG_LCDDS_SSC_DELTA(x) ((x) & 0xfff) +#define RG_LCDDS_SSC_DELTA_MASK GENMASK(11, 0) +#define RG_LCDDS_SSC_DELTA(x) FIELD_PREP(RG_LCDDS_SSC_DELTA_MASK, x) #define CORE_PLL_GROUP11 0x40a -#define RG_LCDDS_SSC_DELTA1(x) ((x) & 0xfff) +#define RG_LCDDS_SSC_DELTA1_MASK GENMASK(11, 0) +#define RG_LCDDS_SSC_DELTA1(x) FIELD_PREP(RG_LCDDS_SSC_DELTA1_MASK, x) #define CORE_GSWPLL_GRP1 0x40d -#define RG_GSWPLL_PREDIV(x) (((x) & 0x3) << 14) -#define RG_GSWPLL_POSDIV_200M(x) (((x) & 0x3) << 12) +#define RG_GSWPLL_PREDIV_MASK GENMASK(15, 14) +#define RG_GSWPLL_PREDIV(x) FIELD_PREP(RG_GSWPLL_PREDIV_MASK, x) +#define RG_GSWPLL_POSDIV_200M_MASK GENMASK(13, 12) +#define RG_GSWPLL_POSDIV_200M(x) FIELD_PREP(RG_GSWPLL_POSDIV_200M_MASK, x) #define RG_GSWPLL_EN_PRE BIT(11) #define RG_GSWPLL_FBKSEL BIT(10) #define RG_GSWPLL_BP BIT(9) #define RG_GSWPLL_BR BIT(8) -#define RG_GSWPLL_FBKDIV_200M(x) ((x) & 0xff) +#define RG_GSWPLL_FBKDIV_200M_MASK GENMASK(7, 0) +#define RG_GSWPLL_FBKDIV_200M(x) FIELD_PREP(RG_GSWPLL_FBKDIV_200M_MASK, x) #define CORE_GSWPLL_GRP2 0x40e -#define RG_GSWPLL_POSDIV_500M(x) (((x) & 0x3) << 8) -#define RG_GSWPLL_FBKDIV_500M(x) ((x) & 0xff) +#define RG_GSWPLL_POSDIV_500M_MASK GENMASK(9, 8) +#define RG_GSWPLL_POSDIV_500M(x) FIELD_PREP(RG_GSWPLL_POSDIV_500M_MASK, x) +#define RG_GSWPLL_FBKDIV_500M_MASK GENMASK(7, 0) +#define RG_GSWPLL_FBKDIV_500M(x) FIELD_PREP(RG_GSWPLL_FBKDIV_500M_MASK, x) #define CORE_TRGMII_GSW_CLK_CG 0x410 #define REG_GSWCK_EN BIT(0) From e1d532b6b056bc72c51523aeb2187e9f5142f75f Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:39:13 +0100 Subject: [PATCH 0107/2126] net: dsa: mt7530: implement port_fast_age Implement the .port_fast_age DSA operation by flushing all non-static (dynamically learned) MAC address entries from the address table. The switch does not offer a combined "non-static AND per-port" match mode, so the flush is global and the port argument is not used. Unlike b53 and realtek, which flush the dynamic entries of the affected port only, an STP topology change on one port therefore also flushes the dynamically learned entries of the other ports; they are quickly relearned. Access the address table control register under priv->reg_mutex, as done by all other ATC users (FDB and MDB add/del/dump), to serialise the write-then-poll command sequence, and log a message should the command fail. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/60f83ade0e371dfe2d974d5d192056935c3ab5c9.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 21 +++++++++++++++++++++ drivers/net/dsa/mt7530.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 4edb57676143..84e0e888f2d0 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -188,6 +188,26 @@ mt7530_fdb_cmd(struct mt7530_priv *priv, enum mt7530_fdb_cmd cmd, u32 *rsp) return 0; } +static void mt7530_port_fast_age(struct dsa_switch *ds, int port) +{ + struct mt7530_priv *priv = ds->priv; + u32 val; + int ret; + + mutex_lock(&priv->reg_mutex); + + /* Flush all non-static MAC address entries */ + val = ATC_BUSY | ATC_MAT_NON_STATIC_MAC | MT7530_FDB_FLUSH; + ret = regmap_write(priv->regmap, MT7530_ATC, val); + if (!ret) + ret = regmap_read_poll_timeout(priv->regmap, MT7530_ATC, val, + !(val & ATC_BUSY), 20, 20000); + if (ret < 0) + dev_err(priv->dev, "fast age failed: %d\n", ret); + + mutex_unlock(&priv->reg_mutex); +} + static void mt7530_fdb_read(struct mt7530_priv *priv, struct mt7530_fdb *fdb) { @@ -3358,6 +3378,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .port_bridge_flags = mt7530_port_bridge_flags, .port_bridge_join = mt7530_port_bridge_join, .port_bridge_leave = mt7530_port_bridge_leave, + .port_fast_age = mt7530_port_fast_age, .port_fdb_add = mt7530_port_fdb_add, .port_fdb_del = mt7530_port_fdb_del, .port_fdb_dump = mt7530_port_fdb_dump, diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index 6a148938c60f..2bbbe617b52e 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -166,6 +166,7 @@ enum mt753x_to_cpu_fw { #define ATC_MAT_MASK GENMASK(11, 8) #define ATC_MAT(x) FIELD_PREP(ATC_MAT_MASK, x) #define ATC_MAT_MACTAB ATC_MAT(0) +#define ATC_MAT_NON_STATIC_MAC ATC_MAT(4) enum mt7530_fdb_cmd { MT7530_FDB_READ = 0, From e5ed29f1560338c634ef8b68e7fc8501a715c251 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 31 Aug 2026 16:39:26 +0100 Subject: [PATCH 0108/2126] net: dsa: mt7530: implement port_change_conduit op Allow changing the CPU port affinity of user ports at runtime via the IFLA_DSA_CONDUIT netlink attribute. This updates the port matrix to forward to the new CPU port instead of the old one. Limit the operation to MT7531. There, trapped link-local frames follow the per-port affinity, as the MT7531_CPU_PMAP destination mask is further restricted by the port matrix. A conduit change is hence fully honoured by the hardware, for regular traffic as well as for trapped frames. The MT7530 switch, including the variant embedded in the MT7621 SoC, instead traps frames to the single CPU port set in the CPU_PORT field of the MFC register, regardless of the affinity of the inbound user port. With user ports affine to different CPU ports there is no correct value for that field, so per-port CPU affinity cannot be fully implemented for trapped frames. Routing a WAN port via the second SoC GMAC is conventionally covered by the PHY muxing feature on these switches, which bypasses the switch fabric and does not involve a CPU port at all. The switches on the MT7988, EN7581, AN7583 and EN7528 SoCs only have a single CPU port, leaving no other conduit to change to. As the op lives in the shared mt7530_switch_ops, populate the extack when rejecting the unsupported variants instead of returning a bare -EOPNOTSUPP. Also reject a conduit that belongs to a different switch in the tree, whose port index has no meaning in the local port matrix. Signed-off-by: Daniel Golle Acked-by: Chester A. Unal Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/cfc6a478a384a7f309f08d9f76be8fd029c1f202.1788190568.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 84e0e888f2d0..28f94cd25b95 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -3249,6 +3249,43 @@ static int mt753x_set_mac_eee(struct dsa_switch *ds, int port, return 0; } +static int +mt753x_port_change_conduit(struct dsa_switch *ds, int port, + struct net_device *conduit, + struct netlink_ext_ack *extack) +{ + struct dsa_port *new_cpu_dp = conduit->dsa_ptr; + struct dsa_port *dp = dsa_to_port(ds, port); + struct mt7530_priv *priv = ds->priv; + + if (priv->id != ID_MT7531) { + NL_SET_ERR_MSG_MOD(extack, + "Changing DSA conduit is only supported on MT7531"); + return -EOPNOTSUPP; + } + + if (new_cpu_dp->ds != ds) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot assign a conduit on a different switch"); + return -EOPNOTSUPP; + } + + mutex_lock(&priv->reg_mutex); + + /* dp->cpu_dp still points to the old CPU port */ + priv->ports[port].pm &= ~PCR_MATRIX(BIT(dp->cpu_dp->index)); + priv->ports[port].pm |= PCR_MATRIX(BIT(new_cpu_dp->index)); + if (priv->ports[port].enable) + regmap_update_bits(priv->regmap, MT7530_PCR_P(port), + PCR_MATRIX_MASK, priv->ports[port].pm); + + mutex_unlock(&priv->reg_mutex); + + mt7530_port_fast_age(ds, port); + + return 0; +} + static void mt753x_conduit_state_change(struct dsa_switch *ds, const struct net_device *conduit, @@ -3361,6 +3398,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .setup = mt753x_setup, .teardown = mt753x_teardown, .preferred_default_local_cpu_port = mt753x_preferred_default_local_cpu_port, + .port_change_conduit = mt753x_port_change_conduit, .get_strings = mt7530_get_strings, .get_ethtool_stats = mt7530_get_ethtool_stats, .get_sset_count = mt7530_get_sset_count, From e8965b0523f2fb0b6d42deeaaa94c0ede7ce4ebb Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Wed, 2 Sep 2026 19:12:55 -0700 Subject: [PATCH 0109/2126] net: pcs: lynx: add support for 25GBASE-R The Lynx PCS never supported 25GBASE-R. Add it, so that a 25G DPMAC on LX2160A can be driven by phylink. The SerDes side had the mode since the commit 1cab8fba5073 ("phy: lynx-28g: add support for 25GBASER") and dpaa2-mac maps DPMAC_ETH_IF_CAUI to PHY_INTERFACE_MODE_25GBASER, but the PCS never handled it, so phylink_validate() failed with the interface. 25GBASE-R is a serial mode without clause-37 in-band autonegotiation, exactly like 10GBASE-R: it does not needs any configuration, its state is read with phylink_mii_c45_pcs_get_state(), and it reports LINK_INBAND_DISABLE. phylink_mii_c45_pcs_get_state() is extended in the same patch because without it the link comes up reporting Unknown/Unknown. Suggested-by: Ioana Ciornei Co-developed-by: Ioana Ciornei Signed-off-by: Ioana Ciornei Signed-off-by: Vincent Jardin Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260922-for-upstream-lynx-25gbaser-v1-v2-1-1e6cf79c7b52@free.fr Signed-off-by: Jakub Kicinski --- drivers/net/pcs/pcs-lynx.c | 6 +++++- drivers/net/phy/phylink.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/pcs/pcs-lynx.c b/drivers/net/pcs/pcs-lynx.c index a92081560e64..da4f99059eef 100644 --- a/drivers/net/pcs/pcs-lynx.c +++ b/drivers/net/pcs/pcs-lynx.c @@ -46,6 +46,7 @@ static unsigned int lynx_pcs_inband_caps(struct phylink_pcs *pcs, return LINK_INBAND_DISABLE | LINK_INBAND_ENABLE; case PHY_INTERFACE_MODE_10GBASER: + case PHY_INTERFACE_MODE_25GBASER: return LINK_INBAND_DISABLE; case PHY_INTERFACE_MODE_USXGMII: @@ -97,6 +98,7 @@ static void lynx_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, lynx_pcs_get_state_usxgmii(lynx->mdio, state); break; case PHY_INTERFACE_MODE_10GBASER: + case PHY_INTERFACE_MODE_25GBASER: phylink_mii_c45_pcs_get_state(lynx->mdio, state); break; default: @@ -188,7 +190,8 @@ static int lynx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, return lynx_pcs_config_usxgmii(lynx->mdio, ifmode, advertising, neg_mode); case PHY_INTERFACE_MODE_10GBASER: - /* Nothing to do here for 10GBASER */ + case PHY_INTERFACE_MODE_25GBASER: + /* Nothing to do here for 10GBASER and 25GBASER */ break; default: return -EOPNOTSUPP; @@ -279,6 +282,7 @@ static const phy_interface_t lynx_interfaces[] = { PHY_INTERFACE_MODE_1000BASEX, PHY_INTERFACE_MODE_2500BASEX, PHY_INTERFACE_MODE_10GBASER, + PHY_INTERFACE_MODE_25GBASER, PHY_INTERFACE_MODE_USXGMII, PHY_INTERFACE_MODE_10G_QXGMII, }; diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 3ec3bb439109..ff4375f1e910 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -4360,6 +4360,11 @@ void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs, state->duplex = DUPLEX_FULL; break; + case PHY_INTERFACE_MODE_25GBASER: + state->speed = SPEED_25000; + state->duplex = DUPLEX_FULL; + break; + default: break; } From fcfb5ff9dfc3c77094159c4eb15d0539bfa3111d Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 31 Aug 2026 09:41:56 -0700 Subject: [PATCH 0110/2126] netdev: correct error code in netdev_nl_queue_fill_lease() netdev_nl_queue_fill_lease() returns ENOMEM on nla_put failures. This is wrong, the error code should be EMSGSIZE. But it doesn't matter, caller of netdev_nl_queue_fill_lease() just checks if the retcode is zero or not, and uses EMSGSIZE. Reviewed-by: Joe Damato Acked-by: Daniel Borkmann Reviewed-by: Bobby Eshleman Reviewed-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260831164159.1124679-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- net/core/netdev-genl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index cb18db681640..04dcd7fc614e 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -434,7 +434,7 @@ netdev_nl_queue_fill_lease(struct sk_buff *rsp, struct net_device *netdev, nla_put_failure_unlock: rcu_read_unlock(); nla_put_failure: - return -ENOMEM; + return -EMSGSIZE; } static int From 17d7aa69540822d6ef1cd47bf069213941022806 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 31 Aug 2026 09:41:58 -0700 Subject: [PATCH 0111/2126] netdev: don't use dev->flags for IFF_UP dev->flags are not technically ops lock protected. The IFF_UP flag will not change when dev->lock is held, but other flags may change so KCSAN would probably not be impressed. Because of this we added a dedicated dev->up which is safe to read under dev->lock. qstats want to make sure device is up, use dev->up. Reviewed-by: Bobby Eshleman Reviewed-by: Joe Damato Acked-by: Daniel Borkmann Reviewed-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260831164159.1124679-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- net/core/netdev-genl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 04dcd7fc614e..b8ba91cc93da 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -768,7 +768,7 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp, const struct netdev_stat_ops *ops = netdev->stat_ops; int i, err; - if (!(netdev->flags & IFF_UP)) + if (!netdev->up) return 0; i = ctx->rxq_idx; From 3498acda6b68139ec7b8037dbdf1ea720997ed04 Mon Sep 17 00:00:00 2001 From: Ziyou Xu Date: Sat, 29 Aug 2026 11:38:43 +0800 Subject: [PATCH 0112/2126] net: phy: air_en8811h: restore AN8811HB LED GPIO after MCU restart Commit 03b4702fc5e3 ("net: phy: air_en8811h: move LED GPIO configuration to config_init") moved the EN8811H LED GPIO setup from probe to config_init because an MD32 restart clears the output-enable bits. AN8811HB follows the same initialization sequence: an8811hb_probe() enables GPIO3/4/5, and later config_init() calls restart MD32. Move the AN8811HB GPIO setup to the end of an8811hb_config_init(), matching the current EN8811H path. Suggested-by: Jakub Kicinski Signed-off-by: Ziyou Xu Link: https://patch.msgid.link/20260829033844.1975-1-xuziyougm@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/air_en8811h.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index 0eeb7b9a4e26..38eb18f0e9bb 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -1125,13 +1125,6 @@ static int an8811hb_probe(struct phy_device *phydev) if (ret) goto err_dev_create; - /* Configure led gpio pins as output */ - ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_OUTPUT, - AN8811HB_GPIO_OUTPUT_345, - AN8811HB_GPIO_OUTPUT_345); - if (ret < 0) - goto err_dev_create; - return 0; err_dev_create: @@ -1265,9 +1258,15 @@ static int an8811hb_config_init(struct phy_device *phydev) ret = air_leds_init(phydev, EN8811H_LED_COUNT, AIR_PHY_LED_DUR, AIR_LED_MODE_USER_DEFINE); - if (ret < 0) + if (ret < 0) { phydev_err(phydev, "Failed to initialize leds: %d\n", ret); + return ret; + } + /* Restore LED GPIO output enables after MCU initialization. */ + ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_OUTPUT, + AN8811HB_GPIO_OUTPUT_345, + AN8811HB_GPIO_OUTPUT_345); return ret; } From b1950d0426aabdda485c86b504106b1d7b11f325 Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 31 Aug 2026 12:38:54 +0800 Subject: [PATCH 0113/2126] net: dsa: yt921x: Check lock status with lockdep_assert_held_once() mutex_is_locked() was used to check the lock status. While it should not be triggered unless a bug is introduced, it does not warn on lock being held by another thread. Fix it with lockdep helpers. Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x") Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831044818.4103477-2-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/yt921x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c index 159b16606f6c..44fcdd47ffb5 100644 --- a/drivers/net/dsa/yt921x.c +++ b/drivers/net/dsa/yt921x.c @@ -198,14 +198,14 @@ static u32 ethaddr_lo2_to_u32(const unsigned char *addr) static int yt921x_reg_read(struct yt921x_priv *priv, u32 reg, u32 *valp) { - WARN_ON(!mutex_is_locked(&priv->reg_lock)); + lockdep_assert_held_once(&priv->reg_lock); return priv->reg_ops->read(priv->reg_ctx, reg, valp); } static int yt921x_reg_write(struct yt921x_priv *priv, u32 reg, u32 val) { - WARN_ON(!mutex_is_locked(&priv->reg_lock)); + lockdep_assert_held_once(&priv->reg_lock); return priv->reg_ops->write(priv->reg_ctx, reg, val); } From 9c472a0d7c3893e568e1b61728d443a9d10bb3a8 Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 31 Aug 2026 12:38:55 +0800 Subject: [PATCH 0114/2126] net: dsa: motorcomm: Move to subdirectory yt921x is already the longest single-file DSA driver, so it's time to split it into parts. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831044818.4103477-3-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- MAINTAINERS | 2 +- drivers/net/dsa/Kconfig | 10 ++-------- drivers/net/dsa/Makefile | 2 +- drivers/net/dsa/motorcomm/Kconfig | 8 ++++++++ drivers/net/dsa/motorcomm/Makefile | 3 +++ drivers/net/dsa/{yt921x.c => motorcomm/chip.c} | 2 +- drivers/net/dsa/{yt921x.h => motorcomm/chip.h} | 0 7 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/Kconfig create mode 100644 drivers/net/dsa/motorcomm/Makefile rename drivers/net/dsa/{yt921x.c => motorcomm/chip.c} (99%) rename drivers/net/dsa/{yt921x.h => motorcomm/chip.h} (100%) diff --git a/MAINTAINERS b/MAINTAINERS index 0b42e898f4d8..4b0254f62277 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18422,7 +18422,7 @@ M: David Yang L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml -F: drivers/net/dsa/yt921x.* +F: drivers/net/dsa/motorcomm/ F: net/dsa/tag_yt921x.c MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 676fb7dffe14..8d8edcf89f10 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -82,6 +82,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/motorcomm/Kconfig" + source "drivers/net/dsa/mv88e6xxx/Kconfig" source "drivers/net/dsa/mxl862xx/Kconfig" @@ -168,12 +170,4 @@ config NET_DSA_VITESSE_VSC73XX_PLATFORM This enables support for the Vitesse VSC7385, VSC7388, VSC7395 and VSC7398 SparX integrated ethernet switches, connected over a CPU-attached address bus and work in memory-mapped I/O mode. - -config NET_DSA_YT921X - tristate "Motorcomm YT9215 ethernet switch chip support" - select NET_DSA_TAG_YT921X - select NET_IEEE8021Q_HELPERS if DCB - help - This enables support for the Motorcomm YT9215 ethernet switch - chip. endmenu diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile index 6ceb78a755d7..df849cd0e640 100644 --- a/drivers/net/dsa/Makefile +++ b/drivers/net/dsa/Makefile @@ -15,11 +15,11 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX) += vitesse-vsc73xx-core.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_PLATFORM) += vitesse-vsc73xx-platform.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o -obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o obj-y += b53/ obj-y += hirschmann/ obj-y += lantiq/ obj-y += microchip/ +obj-y += motorcomm/ obj-y += mv88e6xxx/ obj-y += mxl862xx/ obj-y += netc/ diff --git a/drivers/net/dsa/motorcomm/Kconfig b/drivers/net/dsa/motorcomm/Kconfig new file mode 100644 index 000000000000..64ff7d07a91b --- /dev/null +++ b/drivers/net/dsa/motorcomm/Kconfig @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_YT921X + tristate "Motorcomm YT9215 ethernet switch chip support" + select NET_DSA_TAG_YT921X + select NET_IEEE8021Q_HELPERS if DCB + help + This enables support for the Motorcomm YT9215 ethernet switch + chip. diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile new file mode 100644 index 000000000000..bf99feb4c454 --- /dev/null +++ b/drivers/net/dsa/motorcomm/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o +yt921x-objs := chip.o diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/motorcomm/chip.c similarity index 99% rename from drivers/net/dsa/yt921x.c rename to drivers/net/dsa/motorcomm/chip.c index 44fcdd47ffb5..019b3a2d5d97 100644 --- a/drivers/net/dsa/yt921x.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -26,7 +26,7 @@ #include #include -#include "yt921x.h" +#include "chip.h" struct yt921x_mib_desc { unsigned int size; diff --git a/drivers/net/dsa/yt921x.h b/drivers/net/dsa/motorcomm/chip.h similarity index 100% rename from drivers/net/dsa/yt921x.h rename to drivers/net/dsa/motorcomm/chip.h From e9423a64d382ba77a2906f365416714ede67328e Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 31 Aug 2026 12:38:56 +0800 Subject: [PATCH 0115/2126] net: dsa: motorcomm: Split SMI module SMI operations are going to be used across different modules. Minor changes are applied to fix build errors. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831044818.4103477-4-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 207 +---------------------------- drivers/net/dsa/motorcomm/smi.c | 180 +++++++++++++++++++++++++ drivers/net/dsa/motorcomm/smi.h | 61 +++++++++ 4 files changed, 243 insertions(+), 206 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/smi.c create mode 100644 drivers/net/dsa/motorcomm/smi.h diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index bf99feb4c454..9fa24929007c 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o +yt921x-objs += smi.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 019b3a2d5d97..6dee25b6754a 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include "chip.h" +#include "smi.h" struct yt921x_mib_desc { unsigned int size; @@ -155,9 +155,6 @@ static const struct yt921x_info yt921x_infos[] = { #define YT921X_VID_UNWARE 4095 -#define YT921X_POLL_SLEEP_US 10000 -#define YT921X_POLL_TIMEOUT_US 100000 - /* The interval should be small enough to avoid overflow of 32bit MIBs. * * Until we can read MIBs from stats64 call directly (i.e. sleep @@ -196,208 +193,6 @@ static u32 ethaddr_lo2_to_u32(const unsigned char *addr) return (addr[4] << 8) | addr[5]; } -static int yt921x_reg_read(struct yt921x_priv *priv, u32 reg, u32 *valp) -{ - lockdep_assert_held_once(&priv->reg_lock); - - return priv->reg_ops->read(priv->reg_ctx, reg, valp); -} - -static int yt921x_reg_write(struct yt921x_priv *priv, u32 reg, u32 val) -{ - lockdep_assert_held_once(&priv->reg_lock); - - return priv->reg_ops->write(priv->reg_ctx, reg, val); -} - -static int -yt921x_reg_wait(struct yt921x_priv *priv, u32 reg, u32 mask, u32 *valp) -{ - u32 val; - int res; - int ret; - - ret = read_poll_timeout(yt921x_reg_read, res, - res || (val & mask) == *valp, - YT921X_POLL_SLEEP_US, YT921X_POLL_TIMEOUT_US, - false, priv, reg, &val); - if (ret) - return ret; - if (res) - return res; - - *valp = val; - return 0; -} - -static int -yt921x_reg_update_bits(struct yt921x_priv *priv, u32 reg, u32 mask, u32 val) -{ - int res; - u32 v; - u32 u; - - res = yt921x_reg_read(priv, reg, &v); - if (res) - return res; - - u = v; - u &= ~mask; - u |= val; - if (u == v) - return 0; - - return yt921x_reg_write(priv, reg, u); -} - -static int yt921x_reg_set_bits(struct yt921x_priv *priv, u32 reg, u32 mask) -{ - return yt921x_reg_update_bits(priv, reg, 0, mask); -} - -static int yt921x_reg_clear_bits(struct yt921x_priv *priv, u32 reg, u32 mask) -{ - return yt921x_reg_update_bits(priv, reg, mask, 0); -} - -static int -yt921x_reg_toggle_bits(struct yt921x_priv *priv, u32 reg, u32 mask, bool set) -{ - return yt921x_reg_update_bits(priv, reg, mask, !set ? 0 : mask); -} - -/* Some multi-word registers, like VLANn_CTRL, should be treated as a single - * long register. More specifically, writes to parts of its words won't become - * visible, until the last word is written. - * - * Here we require full read and write operations over these registers to - * eliminate potential issues, although partial reads/writes are also possible. - */ - -static void update_ctrls_unaligned(u32 *lo, u32 *hi, u64 mask, u64 val) -{ - *lo &= ~lower_32_bits(mask); - *hi &= ~upper_32_bits(mask); - *lo |= lower_32_bits(val); - *hi |= upper_32_bits(val); -} - -static int -yt921x_regs_read(struct yt921x_priv *priv, u32 reg, u32 *vals, - unsigned int num_regs) -{ - int res; - - for (unsigned int i = 0; i < num_regs; i++) { - res = yt921x_reg_read(priv, reg + 4 * i, &vals[i]); - if (res) - return res; - } - - return 0; -} - -static int -yt921x_regs_write(struct yt921x_priv *priv, u32 reg, const u32 *vals, - unsigned int num_regs) -{ - int res; - - for (unsigned int i = 0; i < num_regs; i++) { - res = yt921x_reg_write(priv, reg + 4 * i, vals[i]); - if (res) - return res; - } - - return 0; -} - -static int -yt921x_regs_update_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks, - const u32 *vals, unsigned int num_regs) -{ - bool changed = false; - u32 vs[4]; - int res; - - BUILD_BUG_ON(num_regs > ARRAY_SIZE(vs)); - - res = yt921x_regs_read(priv, reg, vs, num_regs); - if (res) - return res; - - for (unsigned int i = 0; i < num_regs; i++) { - u32 u = vs[i]; - - u &= ~masks[i]; - u |= vals[i]; - if (u != vs[i]) - changed = true; - - vs[i] = u; - } - - if (!changed) - return 0; - - return yt921x_regs_write(priv, reg, vs, num_regs); -} - -static int -yt921x_regs_clear_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks, - unsigned int num_regs) -{ - bool changed = false; - u32 vs[4]; - int res; - - BUILD_BUG_ON(num_regs > ARRAY_SIZE(vs)); - - res = yt921x_regs_read(priv, reg, vs, num_regs); - if (res) - return res; - - for (unsigned int i = 0; i < num_regs; i++) { - u32 u = vs[i]; - - u &= ~masks[i]; - if (u != vs[i]) - changed = true; - - vs[i] = u; - } - - if (!changed) - return 0; - - return yt921x_regs_write(priv, reg, vs, num_regs); -} - -static int -yt921x_reg64_write(struct yt921x_priv *priv, u32 reg, const u32 *vals) -{ - return yt921x_regs_write(priv, reg, vals, 2); -} - -static int -yt921x_reg64_update_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks, - const u32 *vals) -{ - return yt921x_regs_update_bits(priv, reg, masks, vals, 2); -} - -static int -yt921x_reg64_clear_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks) -{ - return yt921x_regs_clear_bits(priv, reg, masks, 2); -} - -static int -yt921x_reg96_write(struct yt921x_priv *priv, u32 reg, const u32 *vals) -{ - return yt921x_regs_write(priv, reg, vals, 3); -} - static int yt921x_reg_mdio_read(void *context, u32 reg, u32 *valp) { struct yt921x_reg_mdio *mdio = context; diff --git a/drivers/net/dsa/motorcomm/smi.c b/drivers/net/dsa/motorcomm/smi.c new file mode 100644 index 000000000000..bf3adfd64165 --- /dev/null +++ b/drivers/net/dsa/motorcomm/smi.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 David Yang + */ + +#include + +#include "chip.h" +#include "smi.h" + +#define YT921X_POLL_SLEEP_US 10000 +#define YT921X_POLL_TIMEOUT_US 100000 + +int yt921x_reg_read(struct yt921x_priv *priv, u32 reg, u32 *valp) +{ + lockdep_assert_held_once(&priv->reg_lock); + + return priv->reg_ops->read(priv->reg_ctx, reg, valp); +} + +int yt921x_reg_write(struct yt921x_priv *priv, u32 reg, u32 val) +{ + lockdep_assert_held_once(&priv->reg_lock); + + return priv->reg_ops->write(priv->reg_ctx, reg, val); +} + +int yt921x_reg_wait(struct yt921x_priv *priv, u32 reg, u32 mask, u32 *valp) +{ + u32 val; + int res; + int ret; + + ret = read_poll_timeout(yt921x_reg_read, res, + res || (val & mask) == *valp, + YT921X_POLL_SLEEP_US, YT921X_POLL_TIMEOUT_US, + false, priv, reg, &val); + if (ret) + return ret; + if (res) + return res; + + *valp = val; + return 0; +} + +int yt921x_reg_update_bits(struct yt921x_priv *priv, u32 reg, u32 mask, u32 val) +{ + int res; + u32 v; + u32 u; + + res = yt921x_reg_read(priv, reg, &v); + if (res) + return res; + + u = v; + u &= ~mask; + u |= val; + if (u == v) + return 0; + + return yt921x_reg_write(priv, reg, u); +} + +static int +yt921x_regs_read(struct yt921x_priv *priv, u32 reg, u32 *vals, + unsigned int num_regs) +{ + int res; + + for (unsigned int i = 0; i < num_regs; i++) { + res = yt921x_reg_read(priv, reg + 4 * i, &vals[i]); + if (res) + return res; + } + + return 0; +} + +static int +yt921x_regs_write(struct yt921x_priv *priv, u32 reg, const u32 *vals, + unsigned int num_regs) +{ + int res; + + for (unsigned int i = 0; i < num_regs; i++) { + res = yt921x_reg_write(priv, reg + 4 * i, vals[i]); + if (res) + return res; + } + + return 0; +} + +static int +yt921x_regs_update_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks, + const u32 *vals, unsigned int num_regs) +{ + bool changed = false; + u32 vs[4]; + int res; + + BUILD_BUG_ON(num_regs > ARRAY_SIZE(vs)); + + res = yt921x_regs_read(priv, reg, vs, num_regs); + if (res) + return res; + + for (unsigned int i = 0; i < num_regs; i++) { + u32 u = vs[i]; + + u &= ~masks[i]; + u |= vals[i]; + if (u != vs[i]) + changed = true; + + vs[i] = u; + } + + if (!changed) + return 0; + + return yt921x_regs_write(priv, reg, vs, num_regs); +} + +static int +yt921x_regs_clear_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks, + unsigned int num_regs) +{ + bool changed = false; + u32 vs[4]; + int res; + + BUILD_BUG_ON(num_regs > ARRAY_SIZE(vs)); + + res = yt921x_regs_read(priv, reg, vs, num_regs); + if (res) + return res; + + for (unsigned int i = 0; i < num_regs; i++) { + u32 u = vs[i]; + + u &= ~masks[i]; + if (u != vs[i]) + changed = true; + + vs[i] = u; + } + + if (!changed) + return 0; + + return yt921x_regs_write(priv, reg, vs, num_regs); +} + +int +yt921x_reg64_write(struct yt921x_priv *priv, u32 reg, const u32 *vals) +{ + return yt921x_regs_write(priv, reg, vals, 2); +} + +int +yt921x_reg64_update_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks, + const u32 *vals) +{ + return yt921x_regs_update_bits(priv, reg, masks, vals, 2); +} + +int +yt921x_reg64_clear_bits(struct yt921x_priv *priv, u32 reg, const u32 *masks) +{ + return yt921x_regs_clear_bits(priv, reg, masks, 2); +} + +int +yt921x_reg96_write(struct yt921x_priv *priv, u32 reg, const u32 *vals) +{ + return yt921x_regs_write(priv, reg, vals, 3); +} diff --git a/drivers/net/dsa/motorcomm/smi.h b/drivers/net/dsa/motorcomm/smi.h new file mode 100644 index 000000000000..212e20f71d80 --- /dev/null +++ b/drivers/net/dsa/motorcomm/smi.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2026 David Yang + */ + +#ifndef _YT_SMI_H +#define _YT_SMI_H + +#include +#include + +struct yt921x_priv; + +int yt921x_reg_read(struct yt921x_priv *priv, u32 reg, u32 *valp); +int yt921x_reg_write(struct yt921x_priv *priv, u32 reg, u32 val); +int yt921x_reg_wait(struct yt921x_priv *priv, u32 reg, u32 mask, u32 *valp); +int yt921x_reg_update_bits(struct yt921x_priv *priv, u32 reg, u32 mask, + u32 val); + +static inline int +yt921x_reg_set_bits(struct yt921x_priv *priv, u32 reg, u32 mask) +{ + return yt921x_reg_update_bits(priv, reg, 0, mask); +} + +static inline int +yt921x_reg_clear_bits(struct yt921x_priv *priv, u32 reg, u32 mask) +{ + return yt921x_reg_update_bits(priv, reg, mask, 0); +} + +static inline int +yt921x_reg_toggle_bits(struct yt921x_priv *priv, u32 reg, u32 mask, bool set) +{ + return yt921x_reg_update_bits(priv, reg, mask, !set ? 0 : mask); +} + +/* Some multi-word registers, like VLANn_CTRL, should be treated as a single + * long register. More specifically, writes to parts of its words won't become + * visible, until the last word is written. + * + * Here we require full read and write operations over these registers to + * eliminate potential issues, although partial reads/writes are also possible. + */ + +static inline void update_ctrls_unaligned(u32 *lo, u32 *hi, u64 mask, u64 val) +{ + *lo &= ~lower_32_bits(mask); + *hi &= ~upper_32_bits(mask); + *lo |= lower_32_bits(val); + *hi |= upper_32_bits(val); +} + +int yt921x_reg64_write(struct yt921x_priv *priv, u32 reg, const u32 *vals); +int yt921x_reg64_update_bits(struct yt921x_priv *priv, u32 reg, + const u32 *masks, const u32 *vals); +int yt921x_reg64_clear_bits(struct yt921x_priv *priv, u32 reg, + const u32 *masks); +int yt921x_reg96_write(struct yt921x_priv *priv, u32 reg, const u32 *vals); + +#endif From 9af9a816821365e57736307bfdfcf06d89065556 Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 31 Aug 2026 12:38:57 +0800 Subject: [PATCH 0116/2126] net: dsa: motorcomm: Add LED support Each port has at most 3 LEDs connected and can be declared using the standard LEDs structure. Currently, only parallel mode and strict 1:1 mapping (i.e. the HW default) are supported. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831044818.4103477-5-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/Kconfig | 9 + drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 19 +- drivers/net/dsa/motorcomm/chip.h | 15 + drivers/net/dsa/motorcomm/leds.c | 641 +++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/leds.h | 118 ++++++ 6 files changed, 801 insertions(+), 2 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/leds.c create mode 100644 drivers/net/dsa/motorcomm/leds.h diff --git a/drivers/net/dsa/motorcomm/Kconfig b/drivers/net/dsa/motorcomm/Kconfig index 64ff7d07a91b..79cdd79a1fd2 100644 --- a/drivers/net/dsa/motorcomm/Kconfig +++ b/drivers/net/dsa/motorcomm/Kconfig @@ -6,3 +6,12 @@ config NET_DSA_YT921X help This enables support for the Motorcomm YT9215 ethernet switch chip. + +config NET_DSA_YT921X_LEDS + bool "LED support for Motorcomm YT9215" + default y + depends on NET_DSA_YT921X + depends on LEDS_CLASS=y || LEDS_CLASS=NET_DSA_YT921X + help + This enables support for controlling the LEDs attached to the + Motorcomm YT9215 switch chips. diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index 9fa24929007c..aeb12cb91f93 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o +yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += smi.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 6dee25b6754a..d663af010f43 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -26,6 +26,7 @@ #include #include "chip.h" +#include "leds.h" #include "smi.h" struct yt921x_mib_desc { @@ -151,8 +152,6 @@ static const struct yt921x_info yt921x_infos[] = { {} }; -#define YT921X_NAME "yt921x" - #define YT921X_VID_UNWARE 4095 /* The interval should be small enough to avoid overflow of 32bit MIBs. @@ -4225,6 +4224,15 @@ static int yt921x_edata_read(struct yt921x_priv *priv, u8 addr, u8 *valp) return yt921x_edata_read_cont(priv, addr, valp); } +static void yt921x_dsa_teardown(struct dsa_switch *ds) +{ + struct yt921x_priv *priv = to_yt921x_priv(ds); + +#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) + yt921x_leds_remove(priv); +#endif +} + static int yt921x_chip_detect(struct yt921x_priv *priv) { struct device *dev = to_device(priv); @@ -4581,6 +4589,12 @@ static int yt921x_dsa_setup(struct dsa_switch *ds) if (res) return res; +#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) + res = yt921x_leds_setup(priv); + if (res) + dev_warn(dev, "Failed to setup LEDs: %d\n", res); +#endif + return 0; } @@ -4661,6 +4675,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .port_add_dscp_prio = yt921x_dsa_port_add_dscp_prio, #endif /* chip */ + .teardown = yt921x_dsa_teardown, .setup = yt921x_dsa_setup, }; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 5f3b99e189c4..83cd454955dd 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -850,9 +850,14 @@ enum yt921x_fdb_entry_status { #define YT921X_ACL_NUM (YT921X_ACL_BLK_NUM * YT921X_ACL_ENT_PER_BLK) #define YT921X_UDF_NUM 8 +#define YT921X_LED_GROUP_NUM 3 +#define YT921X_LED_PORT_NUM 10 + /* 8 internal + 2 external + 1 mcu */ #define YT921X_PORT_NUM 11 +#define YT921X_NAME "yt921x" + #define yt921x_port_is_internal(port) ((port) < 8) #define yt921x_port_is_external(port) ((port) == 8 || (port) == 9) @@ -938,6 +943,16 @@ struct yt921x_port { struct yt921x_mib mib; u64 rx_frames; u64 tx_frames; + +#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) + unsigned char led_duty; + unsigned short led_cycle; + + unsigned char led_duty_mask; + unsigned char led_cycle_mask; + + struct yt921x_led *leds[YT921X_LED_GROUP_NUM]; +#endif }; struct yt921x_reg_ops { diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c new file mode 100644 index 000000000000..7d3c0f68d8ff --- /dev/null +++ b/drivers/net/dsa/motorcomm/leds.c @@ -0,0 +1,641 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 David Yang + */ + +#include + +#include "chip.h" +#include "leds.h" +#include "smi.h" + +#define to_yt921x_led(led_cdev) \ + container_of_const((led_cdev), struct yt921x_led, cdev) +#define to_yt921x_port(led) ((led)->port) +#define to_yt921x_priv(pp) \ + container_of_const((pp), struct yt921x_priv, ports[(pp)->index]) +#define to_device(priv) ((priv)->ds.dev) + +static u32 yt921x_led_regaddr(struct yt921x_priv *priv, int port, int group) +{ + switch (group) { + case 0: + default: + return YT921X_LED0_PORTn(port); + case 1: + return YT921X_LED1_PORTn(port); + case 2: + return YT921X_LED2_PORTn(port); + } +} + +static int +yt921x_led_force_set(struct yt921x_priv *priv, int port, int group, bool on) +{ + struct yt921x_port *pp = &priv->ports[port]; + u32 ctrl; + u32 mask; + + /* No reversion - LED is sacrificed in case of IO error */ + pp->led_duty_mask &= ~BIT(group); + pp->led_cycle_mask &= ~BIT(group); + + mask = YT921X_LED2_PORT_FORCEn_M(group); + ctrl = on ? YT921X_LED2_PORT_FORCEn_ON(group) : + YT921X_LED2_PORT_FORCEn_OFF(group); + return yt921x_reg_update_bits(priv, YT921X_LED2_PORTn(port), mask, + ctrl); +} + +static int +yt921x_led_blink_select(const struct yt921x_priv *priv, unsigned long on, + unsigned long off, unsigned short *cyclep, + unsigned char *dutyp) +{ + static const unsigned char dutys[] = { + YT921X_LED_DUTY(1, 6), + YT921X_LED_DUTY(1, 4), + YT921X_LED_DUTY(1, 3), + YT921X_LED_DUTY(1, 2), + }; + unsigned int cycle_upper; + unsigned int cycle_req; + unsigned int duty_req; + unsigned int cycle; + unsigned int duty; + + cycle = YT921X_LED_BLINK_MAX; + cycle_upper = cycle * 11585 / 8192 + 1; /* M_SQRT2 * cycle */ + if (check_add_overflow(on, off, &cycle_req) || cycle_req >= cycle_upper) + return -EOPNOTSUPP; + + for (; cycle > YT921X_LED_BLINK_MIN; cycle_upper >>= 1, cycle >>= 1) + if (cycle_req >= cycle_upper >> 1) + break; + *cyclep = cycle; + + duty_req = DIV_ROUND_CLOSEST(YT921X_LED_DUTY_DENOM * + (on > off ? off : on), cycle_req); + for (unsigned int i = ARRAY_SIZE(dutys) - 1;; i--) + if (i == 0 || duty_req >= (dutys[i - 1] + dutys[i]) / 2) { + duty = dutys[i]; + break; + } + if (on > off) + duty = YT921X_LED_DUTY_DENOM - duty; + *dutyp = duty; + + return 0; +} + +static int +yt921x_led_blink_set(struct yt921x_priv *priv, int port, int group, + unsigned long *onp, unsigned long *offp) +{ + struct yt921x_port *pp = &priv->ports[port]; + unsigned short cycle; + unsigned char duty; + bool use_cycle; + u32 ctrl; + u32 mask; + u32 val; + int res; + + if (!*onp && !*offp) { + cycle = YT921X_LED_BLINK_DEF; + duty = (pp->led_duty_mask & ~BIT(group)) ? pp->led_duty : + YT921X_LED_DUTY(1, 2); + + use_cycle = false; + } else { + res = yt921x_led_blink_select(priv, *onp, *offp, &cycle, &duty); + if (res) + return res; + + use_cycle = cycle < YT921X_LED_BLINK_DEF; + + if (use_cycle && cycle != pp->led_cycle && + (pp->led_cycle_mask & ~BIT(group))) + return -EOPNOTSUPP; + if (duty != pp->led_duty && (pp->led_duty_mask & ~BIT(group))) + return -EOPNOTSUPP; + } + + pp->led_cycle_mask &= ~BIT(group); + pp->led_duty_mask &= ~BIT(group); + + /* The chip seems to jam a while if changing duty directly */ + res = yt921x_reg_read(priv, YT921X_LED2_PORTn(port), &val); + if (res) + return res; + + ctrl = val & ~YT921X_LED2_PORT_FORCEn_M(group); + ctrl |= YT921X_LED2_PORT_FORCEn_OFF(group); + if (val != ctrl) { + res = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), ctrl); + if (res) + return res; + } + + mask = YT921X_LED1_PORT_BLINK_DUTY_M | YT921X_LED1_PORT_BLINK_DUTY_COMP; + switch (duty >= YT921X_LED_DUTY(1, 2) ? duty : + YT921X_LED_DUTY_DENOM - duty) { + default: + duty = YT921X_LED_DUTY(1, 2); + fallthrough; + case YT921X_LED_DUTY(1, 2): + ctrl = YT921X_LED1_PORT_BLINK_DUTY_1_2; + break; + case YT921X_LED_DUTY(2, 3): + ctrl = YT921X_LED1_PORT_BLINK_DUTY_2_3; + break; + case YT921X_LED_DUTY(3, 4): + ctrl = YT921X_LED1_PORT_BLINK_DUTY_3_4; + break; + case YT921X_LED_DUTY(5, 6): + ctrl = YT921X_LED1_PORT_BLINK_DUTY_5_6; + break; + } + if (duty < YT921X_LED_DUTY(1, 2)) + ctrl |= YT921X_LED1_PORT_BLINK_DUTY_COMP; + if (use_cycle) { + mask |= YT921X_LED1_PORT_OTHER_BLINK_M; + ctrl |= YT921X_LED1_PORT_OTHER_BLINK(9 - __fls(cycle)); + } + res = yt921x_reg_update_bits(priv, YT921X_LED1_PORTn(port), mask, ctrl); + if (res) + return res; + + ctrl = val & ~(YT921X_LED2_PORT_FORCEn_M(group) | + YT921X_LED2_PORT_FORCE_BLINKn_M(group)); + ctrl |= YT921X_LED2_PORT_FORCEn_BLINK(group); + if (use_cycle) + ctrl |= YT921X_LED2_PORT_FORCE_BLINKn_OTHER(group); + else + ctrl |= YT921X_LED2_PORT_FORCE_BLINKn(group, __fls(cycle) - 9); + res = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), ctrl); + if (res) + return res; + + if (use_cycle) { + pp->led_cycle_mask |= BIT(group); + pp->led_cycle = cycle; + } + pp->led_duty_mask |= BIT(group); + pp->led_duty = duty; + + *onp = DIV_ROUND_CLOSEST(duty * cycle, YT921X_LED_DUTY_DENOM); + *offp = cycle - *onp; + return 0; +} + +struct yt921x_led_trigger_map { + unsigned long flags; + u32 mask; +}; + +static const struct yt921x_led_trigger_map yt921x_led_trigger_maps[] = { + {BIT(TRIGGER_NETDEV_LINK), + YT921X_LEDx_PORT_ACT_DUPLEX_HALF | YT921X_LEDx_PORT_ACT_DUPLEX_FULL}, + {BIT(TRIGGER_NETDEV_LINK_10), YT921X_LEDx_PORT_ACT_10M}, + {BIT(TRIGGER_NETDEV_LINK_100), YT921X_LEDx_PORT_ACT_100M}, + {BIT(TRIGGER_NETDEV_LINK_1000), YT921X_LEDx_PORT_ACT_1000M}, + {BIT(TRIGGER_NETDEV_HALF_DUPLEX), YT921X_LEDx_PORT_ACT_DUPLEX_HALF}, + {BIT(TRIGGER_NETDEV_FULL_DUPLEX), YT921X_LEDx_PORT_ACT_DUPLEX_FULL}, + {BIT(TRIGGER_NETDEV_TX), YT921X_LEDx_PORT_ACT_TX_BLINK}, + {BIT(TRIGGER_NETDEV_RX), YT921X_LEDx_PORT_ACT_RX_BLINK}, + {BIT(TRIGGER_NETDEV_TX_ERR) | BIT(TRIGGER_NETDEV_RX_ERR), + YT921X_LEDx_PORT_ACT_COLLISION_BLINK}, +}; + +static bool +yt921x_led_trigger_is_supported(const struct yt921x_priv *priv, int port, + int group, unsigned long flags) +{ + if (!flags) + return true; + + for (unsigned int i = 0; i < ARRAY_SIZE(yt921x_led_trigger_maps); i++) { + const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + + if ((flags & map->flags) == map->flags) { + flags &= ~map->flags; + if (!flags) + return true; + } + } + + return false; +} + +static int +yt921x_led_trigger_get(struct yt921x_priv *priv, int port, int group, + unsigned long *flagsp) +{ + u32 addr; + u32 val; + int res; + + res = yt921x_reg_read(priv, YT921X_LED2_PORTn(port), &val); + if (res) + return res; + + if ((val & YT921X_LED2_PORT_FORCEn_M(group)) != + YT921X_LED2_PORT_FORCEn_DONTCARE(group)) { + *flagsp = 0; + return 0; + } + + if (group != 2) { + addr = yt921x_led_regaddr(priv, port, group); + res = yt921x_reg_read(priv, addr, &val); + if (res) + return res; + } + + *flagsp = 0; + for (unsigned int i = 0; i < ARRAY_SIZE(yt921x_led_trigger_maps); i++) { + const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + + if ((val & map->mask) == map->mask) + *flagsp |= map->flags; + } + + return 0; +} + +static int +yt921x_led_trigger_set(struct yt921x_priv *priv, int port, int group, + unsigned long flags) +{ + struct yt921x_port *pp = &priv->ports[port]; + u32 addr; + u32 ctrl; + u32 mask; + int res; + + ctrl = 0; + for (unsigned int i = 0; i < ARRAY_SIZE(yt921x_led_trigger_maps); i++) { + const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + + if ((flags & map->flags) == map->flags) { + flags &= ~map->flags; + ctrl |= map->mask; + if (!flags) + break; + } + } + if (flags) + return -EOPNOTSUPP; + + pp->led_duty_mask &= ~BIT(group); + pp->led_cycle_mask &= ~BIT(group); + + mask = !group ? YT921X_LED0_PORT_ACT_M : YT921X_LEDx_PORT_ACT_M; + if (group == 2) { + mask |= YT921X_LED2_PORT_FORCEn_M(group); + ctrl |= YT921X_LED2_PORT_FORCEn_DONTCARE(group); + } + addr = yt921x_led_regaddr(priv, port, group); + res = yt921x_reg_update_bits(priv, addr, mask, ctrl); + if (res) + return res; + + if (group != 2) { + mask = YT921X_LED2_PORT_FORCEn_M(group); + ctrl = YT921X_LED2_PORT_FORCEn_DONTCARE(group); + res = yt921x_reg_update_bits(priv, YT921X_LED2_PORTn(port), + mask, ctrl); + if (res) + return res; + } + + return 0; +} + +static int +yt921x_cled_brightness_set_blocking(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct yt921x_led *led = to_yt921x_led(led_cdev); + struct yt921x_port *pp = to_yt921x_port(led); + struct yt921x_priv *priv = to_yt921x_priv(pp); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_led_force_set(priv, pp->index, led->group, brightness); + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int +yt921x_cled_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on, + unsigned long *delay_off) +{ + struct yt921x_led *led = to_yt921x_led(led_cdev); + struct yt921x_port *pp = to_yt921x_port(led); + struct yt921x_priv *priv = to_yt921x_priv(pp); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_led_blink_set(priv, pp->index, led->group, delay_on, + delay_off); + mutex_unlock(&priv->reg_lock); + + return res; +} + +static struct device * __maybe_unused +yt921x_cled_hw_control_get_device(struct led_classdev *led_cdev) +{ + struct yt921x_led *led = to_yt921x_led(led_cdev); + struct yt921x_port *pp = to_yt921x_port(led); + struct yt921x_priv *priv = to_yt921x_priv(pp); + struct dsa_port *dp; + + dp = dsa_to_port(&priv->ds, pp->index); + if (!dp) + return NULL; + + if (dsa_port_is_user(dp)) + return !dp->user ? NULL : &dp->user->dev; + if (dsa_port_is_cpu(dp)) + return !dp->conduit ? NULL : &dp->conduit->dev; + + return NULL; +} + +static int __maybe_unused +yt921x_cled_hw_control_is_supported(struct led_classdev *led_cdev, + unsigned long flags) +{ + struct yt921x_led *led = to_yt921x_led(led_cdev); + struct yt921x_port *pp = to_yt921x_port(led); + struct yt921x_priv *priv = to_yt921x_priv(pp); + + if (yt921x_led_trigger_is_supported(priv, pp->index, led->group, flags)) + return 0; + return -EOPNOTSUPP; +} + +static int __maybe_unused +yt921x_cled_hw_control_get(struct led_classdev *led_cdev, unsigned long *flagsp) +{ + struct yt921x_led *led = to_yt921x_led(led_cdev); + struct yt921x_port *pp = to_yt921x_port(led); + struct yt921x_priv *priv = to_yt921x_priv(pp); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_led_trigger_get(priv, pp->index, led->group, flagsp); + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int __maybe_unused +yt921x_cled_hw_control_set(struct led_classdev *led_cdev, unsigned long flags) +{ + struct yt921x_led *led = to_yt921x_led(led_cdev); + struct yt921x_port *pp = to_yt921x_port(led); + struct yt921x_priv *priv = to_yt921x_priv(pp); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_led_trigger_set(priv, pp->index, led->group, flags); + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int +yt921x_led_setup(struct yt921x_priv *priv, int port, + struct fwnode_handle *fwnode) +{ + struct yt921x_port *pp = &priv->ports[port]; + struct device *dev = to_device(priv); + struct led_init_data init_data; + struct led_classdev *led_cdev; + char name[LED_MAX_NAME_SIZE]; + enum led_default_state state; + struct yt921x_led *led; + bool force_high; + bool force_low; + u32 led2_val; + u32 inv_val; + u32 group; + u32 mask; + u32 ctrl; + bool on; + int res; + int ret; + + res = fwnode_property_read_u32(fwnode, "reg", &group); + if (res) { + dev_err(dev, "Missing LED reg for %pfw\n", fwnode); + return res; + } + if (group >= YT921X_LED_GROUP_NUM) { + dev_err(dev, "Invalid LED reg %u for port %d\n", group, port); + return -EINVAL; + } + if (pp->leds[group]) { + res = -EEXIST; + goto err; + } + + force_high = fwnode_property_read_bool(fwnode, "active-high"); + force_low = fwnode_property_read_bool(fwnode, "active-low"); + if (force_high && force_low) { + dev_err(dev, "Duplicate polarities for LED %02d:%02u\n", + port, group); + return -EINVAL; + } + + led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + if (!led) { + res = -ENOMEM; + goto err; + } + pp->leds[group] = led; + + led->port = pp; + led->group = group; + + state = led_init_default_state_get(fwnode); + + mutex_lock(&priv->reg_lock); + + /* Inversion is internal - force on will give low logic. + * In the rest of the file, treat LEDs as if active-low. + */ + inv_val = U32_MAX; + if (force_high || force_low) { + res = yt921x_reg_read(priv, YT921X_LED_PAR_INV, &inv_val); + if (res) + goto revoke_inv; + + mask = YT921X_LED_PAR_INV_INVnm(group, port); + ctrl = force_high ? inv_val | mask : inv_val & ~mask; + res = yt921x_reg_write(priv, YT921X_LED_PAR_INV, ctrl); + if (res) + goto revoke_inv; + } + + led2_val = U32_MAX; + res = yt921x_reg_read(priv, YT921X_LED2_PORTn(port), &led2_val); + if (res) + goto revoke_led2; + mask = YT921X_LED2_PORT_FORCEn_M(group); + + switch (state) { + case LEDS_DEFSTATE_OFF: + case LEDS_DEFSTATE_ON: + default: + on = state == LEDS_DEFSTATE_ON; + ctrl = on ? YT921X_LED2_PORT_FORCEn_ON(group) : + YT921X_LED2_PORT_FORCEn_OFF(group); + res = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), + (led2_val & ~mask) | ctrl); + if (res) + goto revoke_led2; + break; + case LEDS_DEFSTATE_KEEP: + on = (led2_val & mask) == YT921X_LED2_PORT_FORCEn_ON(group); + led2_val = U32_MAX; + break; + } + + mutex_unlock(&priv->reg_lock); + + led_cdev = &led->cdev; + led_cdev->brightness = on; + led_cdev->max_brightness = 1; + led_cdev->flags = LED_RETAIN_AT_SHUTDOWN; + led_cdev->brightness_set_blocking = yt921x_cled_brightness_set_blocking; + led_cdev->blink_set = yt921x_cled_blink_set; +#ifdef CONFIG_LEDS_TRIGGERS + led_cdev->hw_control_trigger = "netdev"; + led_cdev->hw_control_get_device = yt921x_cled_hw_control_get_device; + led_cdev->hw_control_is_supported = yt921x_cled_hw_control_is_supported; + led_cdev->hw_control_get = yt921x_cled_hw_control_get; + led_cdev->hw_control_set = yt921x_cled_hw_control_set; +#endif + + snprintf(name, sizeof(name), YT921X_NAME "-%u:%02d:%02u", + priv->ds.index, port, group); + init_data = (typeof(init_data)){ + .fwnode = fwnode, + .default_label = ":port", + .devicename = name, + .devname_mandatory = true, + }; + res = devm_led_classdev_register_ext(dev, led_cdev, &init_data); + if (res) + goto revoke; + + return 0; + +revoke: + mutex_lock(&priv->reg_lock); +revoke_led2: + if (led2_val != U32_MAX) { + ret = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), led2_val); + if (ret) + dev_err(dev, + "Failed to restore %s for LED %02d:%02u: %d\n", + "LED2_PORT", port, group, ret); + } +revoke_inv: + if (inv_val != U32_MAX) { + ret = yt921x_reg_write(priv, YT921X_LED_PAR_INV, inv_val); + if (ret) + dev_err(dev, + "Failed to restore %s for LED %02d:%02u: %d\n", + "LED_PAR_INV", port, group, ret); + } + mutex_unlock(&priv->reg_lock); + + pp->leds[group] = NULL; + devm_kfree(dev, led); + +err: + dev_err(dev, "Failed to initialize LED %02d:%02u: %d\n", + port, group, res); + return res; +} + +static void yt921x_leds_remove_port(struct yt921x_priv *priv, int port) +{ + struct yt921x_port *pp = &priv->ports[port]; + struct device *dev = to_device(priv); + + for (int group = 0; group < YT921X_LED_GROUP_NUM; group++) { + struct yt921x_led *led = pp->leds[group]; + + if (led) { + devm_led_classdev_unregister(dev, &led->cdev); + pp->leds[group] = NULL; + devm_kfree(dev, led); + } + } + + pp->led_duty_mask = 0; + pp->led_cycle_mask = 0; +} + +static int yt921x_leds_setup_port(struct yt921x_priv *priv, int port) +{ + struct device *dev = to_device(priv); + struct dsa_switch *ds = &priv->ds; + struct device_node *leds_np; + struct dsa_port *dp; + + dp = dsa_to_port(ds, port); + leds_np = of_get_child_by_name(dp->dn, "leds"); + if (!leds_np) + return 0; + + if (port >= YT921X_LED_PORT_NUM) { + dev_err(dev, "Cannot configure LEDs for port %d\n", port); + of_node_put(leds_np); + return -EINVAL; + } + + for_each_child_of_node_scoped(leds_np, led_np) { + yt921x_led_setup(priv, port, of_fwnode_handle(led_np)); + /* Allow partial configuration: LEDs are optional */ + } + + of_node_put(leds_np); + return 0; +} + +void yt921x_leds_remove(struct yt921x_priv *priv) +{ + for (int port = 0; port < YT921X_LED_PORT_NUM; port++) + yt921x_leds_remove_port(priv, port); +} + +int yt921x_leds_setup(struct yt921x_priv *priv) +{ + struct dsa_switch *ds = &priv->ds; + struct dsa_port *dp; + + /* LEDs are always enabled. There is no way to disable them altogether + * (as far as I know). + */ + + dsa_switch_for_each_port(dp, ds) { + int port = dp->index; + + if (!dp->dn) + continue; + + yt921x_leds_setup_port(priv, port); + /* Allow partial configuration: LEDs are optional */ + } + + return 0; +} diff --git a/drivers/net/dsa/motorcomm/leds.h b/drivers/net/dsa/motorcomm/leds.h new file mode 100644 index 000000000000..11df479ee581 --- /dev/null +++ b/drivers/net/dsa/motorcomm/leds.h @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2026 David Yang + */ + +#ifndef _YT_LEDS_H +#define _YT_LEDS_H + +#include +#include +#include +#include + +#define YT921X_LED_CTRL 0xd0000 +#define YT921X_LED_CTRL_UNK BIT(21) +#define YT921X_LED_CTRL_LOOPDETECT_BLINK_M GENMASK(20, 19) /* cycle = 512 * x ms */ +#define YT921X_LED_CTRL_LOOPDETECT_BLINK(x) FIELD_PREP(YT921X_LED_CTRL_LOOPDETECT_BLINK_M, (x)) +#define YT921X_LED_CTRL_PORT_NUM_M GENMASK(16, 13) +#define YT921X_LED_CTRL_PORT_NUM(x) FIELD_PREP(YT921X_LED_CTRL_PORT_NUM_M, (x)) +#define YT921X_LED_CTRL_MODE_M GENMASK(1, 0) +#define YT921X_LED_CTRL_MODE(x) FIELD_PREP(YT921X_LED_CTRL_MODE_M, (x)) +#define YT921X_LED_CTRL_MODE_PARALLEL YT921X_LED_CTRL_MODE(0) +#define YT921X_LED_CTRL_MODE_SERIAL YT921X_LED_CTRL_MODE(2) +#define YT921X_LED0_PORTn(port) (0xd0004 + 4 * (port)) +#define YT921X_LED0_PORT_ACT_M GENMASK(17, 0) +#define YT921X_LED0_PORT_ACT_LINK_TRY_DIS BIT(17) +#define YT921X_LED0_PORT_ACT_COLLISION_BLINK_INDI BIT(16) +#define YT921X_LED1_PORTn(port) (0xd0040 + 4 * (port)) +#define YT921X_LED1_PORT_OTHER_BLINK_M GENMASK(31, 30) /* cycle = 512 >> x ms */ +#define YT921X_LED1_PORT_OTHER_BLINK(x) FIELD_PREP(YT921X_LED1_PORT_OTHER_BLINK_M, (x)) +#define YT921X_LED1_PORT_EEE_BLINK_M GENMASK(29, 28) /* cycle = 512 >> x ms */ +#define YT921X_LED1_PORT_EEE_BLINK(x) FIELD_PREP(YT921X_LED1_PORT_EEE_BLINK_M, (x)) +#define YT921X_LED1_PORT_BLINK_DUTY_COMP BIT(27) +#define YT921X_LED1_PORT_BLINK_DUTY_M GENMASK(26, 25) +#define YT921X_LED1_PORT_BLINK_DUTY(x) FIELD_PREP(YT921X_LED1_PORT_BLINK_DUTY_M, (x)) +#define YT921X_LED1_PORT_BLINK_DUTY_1_2 YT921X_LED1_PORT_BLINK_DUTY(0) +#define YT921X_LED1_PORT_BLINK_DUTY_2_3 YT921X_LED1_PORT_BLINK_DUTY(1) +#define YT921X_LED1_PORT_BLINK_DUTY_3_4 YT921X_LED1_PORT_BLINK_DUTY(2) +#define YT921X_LED1_PORT_BLINK_DUTY_5_6 YT921X_LED1_PORT_BLINK_DUTY(3) +#define YT921X_LED2_PORTn(port) (0xd0080 + 4 * (port)) +#define YT921X_LED2_PORT_FORCEn_M(grp) GENMASK(4 * (grp) + 19, 4 * (grp) + 18) +#define YT921X_LED2_PORT_FORCEn(grp, x) ((x) << (4 * (grp) + 18)) +#define YT921X_LED2_PORT_FORCEn_DONTCARE(grp) YT921X_LED2_PORT_FORCEn(grp, 0) +#define YT921X_LED2_PORT_FORCEn_BLINK(grp) YT921X_LED2_PORT_FORCEn(grp, 1) +#define YT921X_LED2_PORT_FORCEn_ON(grp) YT921X_LED2_PORT_FORCEn(grp, 2) +#define YT921X_LED2_PORT_FORCEn_OFF(grp) YT921X_LED2_PORT_FORCEn(grp, 3) +#define YT921X_LED2_PORT_FORCE_BLINKn_M(grp) GENMASK(4 * (grp) + 17, 4 * (grp) + 16) /* cycle = 512 << x ms */ +#define YT921X_LED2_PORT_FORCE_BLINKn(grp, x) ((x) << (4 * (grp) + 16)) +#define YT921X_LED2_PORT_FORCE_BLINKn_OTHER(grp) YT921X_LED2_PORT_FORCE_BLINKn(grp, 3) +#define YT921X_LEDx_PORT_ACT_M GENMASK(15, 0) +#define YT921X_LEDx_PORT_ACT_EEE_BLINK BIT(15) +#define YT921X_LEDx_PORT_ACT_LOOPDETECT_BLINK BIT(14) +#define YT921X_LEDx_PORT_ACT_ACTIVE_BLINK BIT(13) +#define YT921X_LEDx_PORT_ACT_DUPLEX_FULL BIT(12) +#define YT921X_LEDx_PORT_ACT_DUPLEX_HALF BIT(11) +#define YT921X_LEDx_PORT_ACT_TX_BLINK BIT(10) +#define YT921X_LEDx_PORT_ACT_RX_BLINK BIT(9) +#define YT921X_LEDx_PORT_ACT_TX BIT(8) +#define YT921X_LEDx_PORT_ACT_RX BIT(7) +#define YT921X_LEDx_PORT_ACT_1000M BIT(6) +#define YT921X_LEDx_PORT_ACT_100M BIT(5) +#define YT921X_LEDx_PORT_ACT_10M BIT(4) +#define YT921X_LEDx_PORT_ACT_COLLISION_BLINK BIT(3) +#define YT921X_LEDx_PORT_ACT_1000M_BLINK BIT(2) +#define YT921X_LEDx_PORT_ACT_100M_BLINK BIT(1) +#define YT921X_LEDx_PORT_ACT_10M_BLINK BIT(0) +#define YT921X_LED_SER_CTRL 0xd0100 +#define YT921X_LED_SER_CTRL_UNK GENMASK(25, 24) /* delay? */ +#define YT921X_LED_SER_CTRL_ACTIVE_LOW BIT(4) +#define YT921X_LED_SER_CTRL_GRP_NUM_M GENMASK(1, 0) /* #grp - 1 */ +#define YT921X_LED_SER_CTRL_GRP_NUM(x) FIELD_PREP(YT921X_LED_SER_CTRL_GRP_NUM_M, (x)) +#define YT921X_LED_SER_MAPnm(grp, port) (0xd0104 + 8 * (2 - (grp)) + 4 * ((port) / 5)) +#define YT921X_LED_SER_MAP_DSTn_PORT_M(port) GENMASK(6 * ((port) % 5) + 5, 6 * ((port) % 5) + 2) +#define YT921X_LED_SER_MAP_DSTn_PORT(port, x) ((x) << (6 * ((port) % 5) + 2)) +#define YT921X_LED_SER_MAP_DSTn_LED_M(port) GENMASK(6 * ((port) % 5) + 1, 6 * ((port) % 5)) +#define YT921X_LED_SER_MAP_DSTn_LED(port, x) ((x) << (6 * ((port) % 5))) +#define YT921X_LED_PAR_PORTS 0xd01c4 +#define YT921X_LED_PAR_INV 0xd01c8 +#define YT921X_LED_PAR_INV_INVnm(grp, port) BIT(10 * (grp) + (port)) +#define YT921X_LED_PAR_MAPn(port) (0xd01d0 + 4 * (port)) +#define YT921X_LED_PAR_MAP_DSTn_PORT_M(grp) GENMASK(6 * (grp) + 5, 6 * (grp) + 2) +#define YT921X_LED_PAR_MAP_DSTn_PORT(grp, x) ((x) << (6 * (grp) + 2)) +#define YT921X_LED_PAR_MAP_DSTn_LED_M(grp) GENMASK(6 * (grp) + 1, 6 * (grp)) +#define YT921X_LED_PAR_MAP_DSTn_LED(grp, x) ((x) << (6 * (grp))) + +#define YT921X_LED_BLINK_MIN 64 +#define YT921X_LED_BLINK_DEF 512 +#define YT921X_LED_BLINK_MAX 2048 + +/* 2 * lcm(2, 3, 4, 6) */ +#define YT921X_LED_DUTY_DENOM 24 +#define YT921X_LED_DUTY(nom, denom) (YT921X_LED_DUTY_DENOM * (nom) / (denom)) + +struct yt921x_priv; + +struct yt921x_led { + struct led_classdev cdev; + struct yt921x_port *port; + unsigned char group; +}; + +#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) + +void yt921x_leds_remove(struct yt921x_priv *priv); +int yt921x_leds_setup(struct yt921x_priv *priv); + +#else + +static inline void yt921x_leds_remove(struct yt921x_priv *priv) {} + +static inline int yt921x_leds_setup(struct yt921x_priv *priv) +{ + return 0; +} + +#endif + +#endif From 5f28f63c5d1984f71685bc39ea62964c068b1a5d Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 31 Aug 2026 12:38:58 +0800 Subject: [PATCH 0117/2126] dt-bindings: net: dsa: yt921x: Add LEDs definition example Add LEDs definition example for yt921x to describe how they should be defined for a correct usage. Signed-off-by: David Yang Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260831044818.4103477-6-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- .../bindings/net/dsa/motorcomm,yt921x.yaml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml index 33a6552e46fc..93ba5b181205 100644 --- a/Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml +++ b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml @@ -21,6 +21,9 @@ description: | Any port can be used as the CPU port. + Each port has at most 3 LEDs connected and can be declared using the standard + LEDs structure. + properties: compatible: const: motorcomm,yt9215 @@ -59,6 +62,7 @@ unevaluatedProperties: false examples: - | #include + #include mdio { #address-cells = <1>; @@ -113,6 +117,25 @@ examples: label = "lan1"; phy-mode = "internal"; phy-handle = <&sw_phy0>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + default-state = "keep"; + }; + + led@1 { + reg = <1>; + color = ; + function = LED_FUNCTION_LAN; + default-state = "keep"; + }; + }; }; ethernet-port@1 { From 384ee2379a66a86903e1acccc30c2f87a3020809 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Mon, 31 Aug 2026 09:01:19 +0200 Subject: [PATCH 0118/2126] net: stmmac: dwmac4: Read the UC filter size from hardware capabilities dwmac4 has multiple banks of perfect filter entries, independently configurable during IP integration. The multi_addr bank reports a number between 0 and 31 corresponding to the actual number of entries in that bank, while the 32 and 64 banks are all-or-nothing. Expose these caps over debugfs as well. Signed-off-by: Maxime Chevallier Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260831070121.349778-2-maxime.chevallier@bootlin.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/common.h | 2 ++ drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 4 +++- drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c | 2 ++ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 927ea6230073..77bd47a83357 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -419,6 +419,8 @@ struct dma_features { unsigned int half_duplex; unsigned int hash_filter; unsigned int multi_addr; + unsigned int additional_32_addr; + unsigned int additional_64_addr; unsigned int pcs; unsigned int sma_mdio; unsigned int pmt_remote_wake_up; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h index 6382836828ba..89368e34a388 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h @@ -176,7 +176,9 @@ enum power_event { /* MAC HW features0 bitmap */ #define GMAC_HW_FEAT_SAVLANINS BIT(27) -#define GMAC_HW_FEAT_ADDMAC BIT(18) +#define GMAC_HW_FEAT_MACADR64SEL BIT(24) +#define GMAC_HW_FEAT_MACADR32SEL BIT(23) +#define GMAC_HW_FEAT_ADDMAC GENMASK(22, 18) #define GMAC_HW_FEAT_RXCOESEL BIT(16) #define GMAC_HW_FEAT_TXCOSEL BIT(14) #define GMAC_HW_FEAT_EEESEL BIT(13) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c index 23ffe1adcd0d..14ac3f0e51f7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c @@ -388,6 +388,8 @@ static int dwmac4_get_hw_feature(void __iomem *ioaddr, dma_cap->half_duplex = (hw_cap & GMAC_HW_FEAT_HDSEL) >> 2; dma_cap->vlhash = (hw_cap & GMAC_HW_FEAT_VLHASH) >> 4; dma_cap->multi_addr = (hw_cap & GMAC_HW_FEAT_ADDMAC) >> 18; + dma_cap->additional_32_addr = (hw_cap & GMAC_HW_FEAT_MACADR32SEL) >> 23; + dma_cap->additional_64_addr = (hw_cap & GMAC_HW_FEAT_MACADR64SEL) >> 24; dma_cap->pcs = (hw_cap & GMAC_HW_FEAT_PCSSEL) >> 3; dma_cap->sma_mdio = (hw_cap & GMAC_HW_FEAT_SMASEL) >> 5; dma_cap->pmt_remote_wake_up = (hw_cap & GMAC_HW_FEAT_RWKSEL) >> 6; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 66ae365e1c89..30a539b100f8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6582,6 +6582,18 @@ static int stmmac_dma_cap_show(struct seq_file *seq, void *v) seq_printf(seq, "\tNumber of Additional MAC address registers: %d\n", priv->dma_cap.multi_addr); + } else if (priv->plat->core_type == DWMAC_CORE_GMAC4) { + seq_printf(seq, + "\tNumber of MAC address registers (1-31): %d\n", + priv->dma_cap.multi_addr); + seq_printf(seq, + "\tAdditional 32 MAC address registers (32-63): %s\n", + priv->dma_cap.additional_32_addr ? "Y" : "N"); + seq_printf(seq, + "\tAdditional 64 MAC address registers (64-127): %s\n", + priv->dma_cap.additional_64_addr ? "Y" : "N"); + seq_printf(seq, "\tHash Filter: %s\n", + (priv->dma_cap.hash_filter) ? "Y" : "N"); } else { seq_printf(seq, "\tHash Filter: %s\n", (priv->dma_cap.hash_filter) ? "Y" : "N"); From 6815415d68b98bd34d22aa0631c71b0fb7cbc7f5 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Mon, 31 Aug 2026 09:01:20 +0200 Subject: [PATCH 0119/2126] net: stmmac: dwmac4: Use the full perfect filter ability for UC filter Contrary to dwmac1000 that gets its number of perfect filter entries through the 'snps,perfect-filter-entries' property, dwmac4 allows reading the filter size from the HW features registers. Perfect filter is used for Unicast filtering, and can contain up to 128 entries, each having its own set of registers to access it. The registers are always at the same location in the map, regardless whether or not the entry is implemented in hardware. Accessing a register for an un-implemented entry just doesn't do anything. The filter is made of one always-available entry, and 3 configurable banks : Entry 0 : Always implemented, stores the primary MAC address Entry 1 \ ... + -- Can contain between 0 and 31 entries. Number of available Entry 31 / entries in HW_Features0[18:22]. Entry 32 \ ... + -- Additional 32 entries, all or nothing. Availability is Entry 63 / specified by HW_Features0[23] Entry 64 \ ... + - Additional 64 entries, all or nothing. Availability is Entry 127 / specified by HW_Features0[24]. Each of the 3 configurable banks are independently selectable, meaning we can have gaps in the register banks. For instance, a setup with 50 addresses enabled will have 17 entries in the first bank and the additional 32 bank enabled (50 = 32 + 17 + 1). Another example with 70 addresses : 64 addr bank on, 5 addresses in the first bank (70 = 64 + 5 + 1). While I haven't seen HW with gaps in the banks, Synopsys confirmed this is a real possibility. Let's therefore introduce a dwmac4 helper to get the physical slot number of a given entry, allowing to configure the correct bank when populating the filter. As we need the HW feature-set to compute the index, store the bank info in the mac_device_info struct. The total number of available entries is computed based on the discovered parameters, instead of using the default value of 1. Results on HW that uses dwmac4 : - imx8mp : goes from 1 entry to 64 (1 + 31 + 32) - stm32mp1 : goes from 1 entry to 4 (1 + 3) - jh7110 : goes from 1 entry to 9 (1 + 8) - yt6801 : goes from 1 entry to hum, 1 entry (no extra addresses) Signed-off-by: Maxime Chevallier Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260831070121.349778-3-maxime.chevallier@bootlin.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/common.h | 3 + drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 2 - .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 60 +++++++++++++++---- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 27 +++++++++ 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 77bd47a83357..1729fb29ece3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -629,6 +629,7 @@ struct mac_device_info { void __iomem *pcsr; /* vpointer to device CSRs */ unsigned int multicast_filter_bins; unsigned int unicast_filter_entries; + unsigned int multi_addr; unsigned int mcast_bits_log2; unsigned int rx_csum; unsigned int num_vlan; @@ -637,6 +638,8 @@ struct mac_device_info { u8 vlan_fail_q; bool hw_vlan_en; bool reverse_sgmii_enable; + bool additional_32_addr; + bool additional_64_addr; /* This spinlock protects read-modify-write of the interrupt * mask/enable registers. diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h index 89368e34a388..696846531229 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h @@ -75,8 +75,6 @@ #define GMAC_PACKET_FILTER_IPFE BIT(20) #define GMAC_PACKET_FILTER_RA BIT(31) -#define GMAC_MAX_PERFECT_ADDRESSES 128 - /* MAC RX Queue Enable */ #define GMAC_RX_QUEUE_CLEAR(queue) ~(GENMASK(1, 0) << ((queue) * 2)) #define GMAC_RX_AV_QUEUE_ENABLE(queue) BIT((queue) * 2) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index 70c8b5a373d3..cd6c5d6f42b5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -365,22 +365,63 @@ static void dwmac4_pmt(struct mac_device_info *hw, unsigned long mode) writel(pmt, ioaddr + GMAC_PMT); } +/** + * dwmac4_umac_addr_slot - Get the UC filter slot for the Nth MAC address + * @hw: The MAC device info + * @reg_n: The MAC address's index in the UC list + * + * On dwmac4 the slots available for Unicast MAC filtering are configured when + * integrating the IP. + * + * - Slot 0 is always available, used to store the primary MAC address + * - From 1 to 31, the number of implemented slots is set in hw->multi_addr + * - From 32 to 63, the range is available if hw->additional_32_addr + * is set + * - From 64 to 127, the range is available if hw->additional_64_addr is set + * + * All the ranges can be configured independently (e.g. 64 -> 127 can be + * available, but not 32 -> 63) + * + * Returns: The physical slot index in the UC filter + */ +static unsigned int dwmac4_umac_addr_slot(struct mac_device_info *hw, + unsigned int reg_n) +{ + unsigned int empty_slots = 0; + + /* reg_n is in the 1-31 bank : 1 to 1 mapping */ + if (reg_n < (hw->multi_addr + 1)) + return reg_n; + + /* Gap between the last address in the 1->31 range and the next slot */ + if (hw->additional_32_addr) + empty_slots = 32 - (hw->multi_addr + 1); + else if (hw->additional_64_addr) + empty_slots = 64 - (hw->multi_addr + 1); + + return reg_n + empty_slots; +} + static void dwmac4_set_umac_addr(struct mac_device_info *hw, const unsigned char *addr, unsigned int reg_n) { void __iomem *ioaddr = hw->pcsr; + unsigned int slot; - stmmac_dwmac4_set_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n), - GMAC_ADDR_LOW(reg_n)); + slot = dwmac4_umac_addr_slot(hw, reg_n); + stmmac_dwmac4_set_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(slot), + GMAC_ADDR_LOW(slot)); } static void dwmac4_get_umac_addr(struct mac_device_info *hw, unsigned char *addr, unsigned int reg_n) { void __iomem *ioaddr = hw->pcsr; + unsigned int slot; - stmmac_get_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n), - GMAC_ADDR_LOW(reg_n)); + slot = dwmac4_umac_addr_slot(hw, reg_n); + stmmac_get_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(slot), + GMAC_ADDR_LOW(slot)); } static int dwmac4_set_lpi_mode(struct mac_device_info *hw, @@ -522,9 +563,6 @@ static void dwmac4_set_filter(struct mac_device_info *hw, /* Handle multiple unicast addresses */ if (netdev_uc_count(dev) + 1 > hw->unicast_filter_entries) { - /* Switch to promiscuous mode if more than 128 addrs - * are required - */ value |= GMAC_PACKET_FILTER_PR; } else { struct netdev_hw_addr *ha; @@ -535,9 +573,11 @@ static void dwmac4_set_filter(struct mac_device_info *hw, reg++; } - while (reg < GMAC_MAX_PERFECT_ADDRESSES) { - writel(0, ioaddr + GMAC_ADDR_HIGH(reg)); - writel(0, ioaddr + GMAC_ADDR_LOW(reg)); + while (reg < hw->unicast_filter_entries) { + unsigned int slot = dwmac4_umac_addr_slot(hw, reg); + + writel(0, ioaddr + GMAC_ADDR_HIGH(slot)); + writel(0, ioaddr + GMAC_ADDR_LOW(slot)); reg++; } } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 30a539b100f8..d4ef05672aa6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7496,6 +7496,33 @@ static int stmmac_hw_init(struct stmmac_priv *priv) priv->plat->tx_fifo_size = priv->dma_cap.tx_fifo_size; } + /* On DWMAC4 we can get the exact number of perfect filter entries from + * the HW_Features. + */ + if (priv->plat->core_type == DWMAC_CORE_GMAC4) { + priv->hw->multi_addr = priv->dma_cap.multi_addr; + priv->hw->additional_32_addr = + !!priv->dma_cap.additional_32_addr; + priv->hw->additional_64_addr = + !!priv->dma_cap.additional_64_addr; + + /* We always have one slot for the primary MAC */ + priv->hw->unicast_filter_entries = 1; + + /* How many slots in the 1 -> 31 range */ + priv->hw->unicast_filter_entries += priv->hw->multi_addr; + + /* Additional 32 entries in the 32 -> 63 range */ + if (priv->hw->additional_32_addr) + priv->hw->unicast_filter_entries += 32; + + /* Additional 64 entries in the 64 -> 127 range, can be enabled + * independently of the 32 -> 63 range + */ + if (priv->hw->additional_64_addr) + priv->hw->unicast_filter_entries += 64; + } + priv->hw->vlan_fail_q_en = (priv->plat->flags & STMMAC_FLAG_VLAN_FAIL_Q_EN); priv->hw->vlan_fail_q = priv->plat->vlan_fail_q; From e048669dccec93e8c91a9e88cc3937e3a03979ed Mon Sep 17 00:00:00 2001 From: Juuso Rinta Date: Tue, 1 Sep 2026 08:17:36 +0300 Subject: [PATCH 0120/2126] octeontx2: use dev_err_probe() for deferred probe The PF and VF drivers warn and return -EPROBE_DEFER when the AF has not programmed the RVUM revision or does not answer the mailbox READY message. That is expected until rvu_af has finished initializing, so the warning is repeated on every deferred retry. Use dev_err_probe() instead of dev_warn() so the expected deferral is not printed at warning level. -EPROBE_DEFER is logged at debug level and the reason is recorded in devices_deferred. Signed-off-by: Juuso Rinta Acked-by: Ratheesh Kannoth Link: https://patch.msgid.link/20260901-octeontx2-dev-err-probe-v1-1-1b5e1affb994@nokia.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 11 ++++------- drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c index c995f2900859..529040f3ece4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -1167,10 +1167,9 @@ int otx2_register_mbox_intr(struct otx2_nic *pf, bool probe_af) } err = otx2_sync_mbox_msg(&pf->mbox); if (err) { - dev_warn(pf->dev, - "AF not responding to mailbox, deferring probe\n"); otx2_disable_mbox_intr(pf); - return -EPROBE_DEFER; + return dev_err_probe(pf->dev, -EPROBE_DEFER, + "AF not responding to mailbox, deferring probe\n"); } return 0; @@ -2993,11 +2992,9 @@ int otx2_check_pf_usable(struct otx2_nic *nic) * otherwise this driver probe should be deferred * until AF driver comes up. */ - if (!rev) { - dev_warn(nic->dev, + if (!rev) + return dev_err_probe(nic->dev, -EPROBE_DEFER, "AF is not initialized, deferring probe\n"); - return -EPROBE_DEFER; - } return 0; } diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c index fcdf891f90b5..a02267978583 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c @@ -297,10 +297,9 @@ static int otx2vf_register_mbox_intr(struct otx2_nic *vf, bool probe_pf) err = otx2_sync_mbox_msg(&vf->mbox); if (err) { - dev_warn(vf->dev, - "AF not responding to mailbox, deferring probe\n"); otx2vf_disable_mbox_intr(vf); - return -EPROBE_DEFER; + return dev_err_probe(vf->dev, -EPROBE_DEFER, + "AF not responding to mailbox, deferring probe\n"); } return 0; } From 8e2faf945a13fc73711a5227af8a1077523b590f Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Mon, 31 Aug 2026 08:48:33 +0200 Subject: [PATCH 0121/2126] net: stmmac: drop the queue-0 pinning for GSO frames stmmac_select_queue() forces every GSO frame (TCPv4/TCPv6/UDP-L4) onto TX queue 0, relying on the legacy assumption that at least queue 0 is always TSO/USO capable. This is no longer needed since stmmac_features_check() already validates each GSO frame against the capabilities of the queue it is mapped to, clearing the checksum and GSO features for queues that cannot perform TSO (e.g. TBS queues or queues without TX checksum offload support). Remove stmmac_select_queue() so GSO frames are selected through the regular queue selection path (XPS, flow hashing and priority mapping) and can be spread across all TX queues. This also fixes the case where queue 0 is not TSO-capable while other queues are, which previously forced all TSO traffic into software GSO. Non-GSO traffic is unaffected, since the core already falls back to netdev_pick_tx() when ndo_select_queue is not set. Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260831-stmmac_select_queue-tso-fix-v3-1-d9c215fe7a85@oss.qualcomm.com Signed-off-by: Paolo Abeni --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index d4ef05672aa6..5603d2cdc5c0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6428,24 +6428,6 @@ static int stmmac_setup_tc(struct net_device *ndev, enum tc_setup_type type, } } -static u16 stmmac_select_queue(struct net_device *dev, struct sk_buff *skb, - struct net_device *sb_dev) -{ - int gso = skb_shinfo(skb)->gso_type; - - if (gso & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6 | SKB_GSO_UDP_L4)) { - /* - * There is no way to determine the number of TSO/USO - * capable Queues. Let's use always the Queue 0 - * because if TSO/USO is supported then at least this - * one will be capable. - */ - return 0; - } - - return netdev_pick_tx(dev, skb, NULL) % dev->real_num_tx_queues; -} - static int stmmac_set_mac_address(struct net_device *ndev, void *addr) { struct stmmac_priv *priv = netdev_priv(ndev); @@ -7314,7 +7296,6 @@ static const struct net_device_ops stmmac_netdev_ops = { .ndo_eth_ioctl = stmmac_ioctl, .ndo_get_stats64 = stmmac_get_stats64, .ndo_setup_tc = stmmac_setup_tc, - .ndo_select_queue = stmmac_select_queue, .ndo_set_mac_address = stmmac_set_mac_address, .ndo_vlan_rx_add_vid = stmmac_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = stmmac_vlan_rx_kill_vid, From 60c1bcdeeb8ecacb35a430f516d11d805922d017 Mon Sep 17 00:00:00 2001 From: Naveen Mamindlapalli Date: Mon, 31 Aug 2026 11:56:00 +0530 Subject: [PATCH 0122/2126] octeontx2-pf: Add NIXLF error and poison interrupt handlers Register and handle the NIX LF error (NIX_LF_ERR_INT) and poison/RAS (NIX_LF_RAS) interrupt vectors, The handlers acknowledge the interrupt and log the status (ratelimited) to help debug NIX LF faults. Signed-off-by: Nitin Shetty J Signed-off-by: Naveen Mamindlapalli Link: https://patch.msgid.link/20260831062600.839203-1-nshettyj@marvell.com Signed-off-by: Paolo Abeni --- .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 88 ++++++++++++++++++- .../ethernet/marvell/octeontx2/nic/otx2_reg.h | 2 + .../ethernet/marvell/octeontx2/nic/otx2_vf.c | 4 +- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c index 529040f3ece4..c0e2100de1d9 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -1523,6 +1523,34 @@ irqreturn_t otx2_cq_intr_handler(int irq, void *cq_irq) } EXPORT_SYMBOL(otx2_cq_intr_handler); +static irqreturn_t otx2_nixlf_err_intr_handler(int irq, void *data) +{ + struct otx2_nic *pf = data; + u64 regval; + + /* Clear interrupt */ + regval = otx2_read64(pf, NIX_LF_ERR_INT); + otx2_write64(pf, NIX_LF_ERR_INT, regval); + + dev_err_ratelimited(pf->dev, "NIXLF Error Interrupt: 0x%llx\n", regval); + + return IRQ_HANDLED; +} + +static irqreturn_t otx2_nixlf_poison_intr_handler(int irq, void *data) +{ + struct otx2_nic *pf = data; + u64 regval; + + /* Clear interrupt */ + regval = otx2_read64(pf, NIX_LF_RAS); + otx2_write64(pf, NIX_LF_RAS, regval); + + dev_err_ratelimited(pf->dev, "NIXLF Poison Interrupt: 0x%llx\n", regval); + + return IRQ_HANDLED; +} + void otx2_disable_napi(struct otx2_nic *pf) { struct otx2_qset *qset = &pf->qset; @@ -2079,6 +2107,34 @@ int otx2_open(struct net_device *netdev) otx2_set_cints_affinity(pf); + /* Register NIXLF error IRQ handler */ + vec = pf->hw.nix_msixoff + NIX_LF_ERR_VEC; + irq_name = &pf->hw.irq_name[vec * NAME_SIZE]; + snprintf(irq_name, NAME_SIZE, "%s-nixlf-err", pf->netdev->name); + err = request_irq(pci_irq_vector(pf->pdev, vec), + otx2_nixlf_err_intr_handler, 0, irq_name, pf); + if (err) { + dev_err(pf->dev, + "RVUPF%d: IRQ registration failed for NIXLF ERR vector\n", + rvu_get_pf(pf->pdev, pf->pcifunc)); + goto err_free_cints; + } + otx2_write64(pf, NIX_LF_ERR_INT_ENA_W1S, NIX_LF_ERR_INT_MASK); + + /* Register NIXLF POISON interrupt handler */ + vec = pf->hw.nix_msixoff + NIX_LF_POISON_VEC; + irq_name = &pf->hw.irq_name[vec * NAME_SIZE]; + snprintf(irq_name, NAME_SIZE, "%s-nixlf-poison", pf->netdev->name); + err = request_irq(pci_irq_vector(pf->pdev, vec), + otx2_nixlf_poison_intr_handler, 0, irq_name, pf); + if (err) { + dev_err(pf->dev, + "RVUPF%d: IRQ registration failed for NIXLF POISON vector\n", + rvu_get_pf(pf->pdev, pf->pcifunc)); + goto err_free_errint; + } + otx2_write64(pf, NIX_LF_RAS_ENA_W1S, NIX_LF_RAS_MASK); + if (pf->flags & OTX2_FLAG_RX_VLAN_SUPPORT) otx2_enable_rxvlan(pf, true); @@ -2131,6 +2187,16 @@ err_tx_stop_queues: netif_tx_stop_all_queues(netdev); netif_carrier_off(netdev); pf->flags |= OTX2_FLAG_INTF_DOWN; + /* free NIXLF POISON irq */ + vec = pci_irq_vector(pf->pdev, + pf->hw.nix_msixoff + NIX_LF_POISON_VEC); + otx2_write64(pf, NIX_LF_RAS_ENA_W1C, NIX_LF_RAS_MASK); + free_irq(vec, pf); +err_free_errint: + vec = pci_irq_vector(pf->pdev, + pf->hw.nix_msixoff + NIX_LF_ERR_VEC); + otx2_write64(pf, NIX_LF_ERR_INT_ENA_W1C, NIX_LF_ERR_INT_MASK); + free_irq(vec, pf); err_free_cints: otx2_free_cints(pf, qidx); vec = pci_irq_vector(pf->pdev, @@ -2170,6 +2236,18 @@ int otx2_stop(struct net_device *netdev) /* Clear RSS enable flag */ pf->hw.rss_info.enable = false; + /* Cleanup NIXLF Poison IRQ */ + vec = pci_irq_vector(pf->pdev, + pf->hw.nix_msixoff + NIX_LF_POISON_VEC); + otx2_write64(pf, NIX_LF_RAS_ENA_W1C, NIX_LF_RAS_MASK); + free_irq(vec, pf); + + /* Cleanup NIXLF Error IRQ */ + vec = pci_irq_vector(pf->pdev, + pf->hw.nix_msixoff + NIX_LF_ERR_VEC); + otx2_write64(pf, NIX_LF_ERR_INT_ENA_W1C, NIX_LF_ERR_INT_MASK); + free_irq(vec, pf); + /* Cleanup Queue IRQ */ vec = pci_irq_vector(pf->pdev, pf->hw.nix_msixoff + NIX_LF_QINT_VEC_START); @@ -3003,11 +3081,15 @@ int otx2_realloc_msix_vectors(struct otx2_nic *pf) struct otx2_hw *hw = &pf->hw; int num_vec, err; - /* NPA interrupts are inot registered, so alloc only - * upto NIX vector offset. + /* Skip NPA vectors. Representors only use CINT vectors, so limit + * the budget to that range. For PF/VF, allocate the full NIX LF + * interrupt range (QINT, CINT, GINT, ERR and POISON vectors). */ num_vec = hw->nix_msixoff; - num_vec += NIX_LF_CINT_VEC_START + hw->max_queues; + if (pf->flags & OTX2_FLAG_REP_MODE_ENABLED) + num_vec += NIX_LF_CINT_VEC_START + hw->max_queues; + else + num_vec += NIX_LF_POISON_VEC + 1; otx2_disable_mbox_intr(pf); pci_free_irq_vectors(hw->pdev); diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h index 1cd576fd09c5..c144fd2bbe51 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h @@ -121,10 +121,12 @@ #define NIX_LF_ERR_INT_W1S (NIX_LFBASE | 0x228) #define NIX_LF_ERR_INT_ENA_W1C (NIX_LFBASE | 0x230) #define NIX_LF_ERR_INT_ENA_W1S (NIX_LFBASE | 0x238) +#define NIX_LF_ERR_INT_MASK GENMASK_ULL(31, 0) #define NIX_LF_RAS (NIX_LFBASE | 0x240) #define NIX_LF_RAS_W1S (NIX_LFBASE | 0x248) #define NIX_LF_RAS_ENA_W1C (NIX_LFBASE | 0x250) #define NIX_LF_RAS_ENA_W1S (NIX_LFBASE | 0x258) +#define NIX_LF_RAS_MASK GENMASK_ULL(10, 0) #define NIX_LF_SQ_OP_ERR_DBG (NIX_LFBASE | 0x260) #define NIX_LF_MNQ_ERR_DBG (NIX_LFBASE | 0x270) #define NIX_LF_SEND_ERR_DBG (NIX_LFBASE | 0x280) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c index a02267978583..f7765e19d78a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c @@ -553,7 +553,7 @@ static int otx2vf_realloc_msix_vectors(struct otx2_nic *vf) int num_vec, err; num_vec = hw->nix_msixoff; - num_vec += NIX_LF_CINT_VEC_START + hw->max_queues; + num_vec += NIX_LF_POISON_VEC + 1; otx2vf_disable_mbox_intr(vf); pci_free_irq_vectors(hw->pdev); @@ -596,7 +596,7 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) pci_set_master(pdev); - qcount = num_online_cpus(); + qcount = min_t(int, num_online_cpus(), OTX2_MAX_CQ_CNT); qos_txqs = min_t(int, qcount, OTX2_QOS_MAX_LEAF_NODES); netdev = alloc_etherdev_mqs(sizeof(*vf), qcount + qos_txqs, qcount); if (!netdev) From b35d3d2fae3058265ba937544a3895cedce18d08 Mon Sep 17 00:00:00 2001 From: Sang-Heon Jeon Date: Tue, 1 Sep 2026 20:09:11 +0900 Subject: [PATCH 0123/2126] octeon_ep: remove redundant memset in octep_setup_pfvf_mbox() vzalloc() returns zeroed memory, so the memset after the allocation is redundant. No functional change. Signed-off-by: Sang-Heon Jeon Reviewed-by: Xuanqiang Luo Link: https://patch.msgid.link/20260901110913.977745-1-ekffu200098@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c b/drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c index 0867fab61b19..e4175d5bdb3b 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_pfvf_mbox.c @@ -274,7 +274,6 @@ int octep_setup_pfvf_mbox(struct octep_device *oct) if (!oct->mbox[ring]) goto free_mbox; - memset(oct->mbox[ring], 0, sizeof(struct octep_mbox)); memset(&oct->vf_info[i], 0, sizeof(struct octep_pfvf_info)); mutex_init(&oct->mbox[ring]->lock); INIT_WORK(&oct->mbox[ring]->wk.work, octep_pfvf_mbox_work); From 7042c8c193e5d634198b7c766bb3a01c8e3ee0e2 Mon Sep 17 00:00:00 2001 From: Jiawen Wu Date: Tue, 1 Sep 2026 14:56:59 +0800 Subject: [PATCH 0124/2126] net: libwx: rename wx_pf_flags to wx_flags The flags defined in `enum wx_pf_flags` and its terminator `WX_PF_FLAGS_NBITS` were originally named with a "PF" (Physical Function) prefix. However, these flags are not exclusive to PFs and are also utilized by Virtual Functions (VFs). Rename the enumeration to `enum wx_flags` and the bit count to `WX_FLAGS_NBITS` to accurately reflect their shared usage across both PF and VF drivers, and to prevent potential confusion. Signed-off-by: Jiawen Wu Reviewed-by: Breno Leitao Link: https://patch.msgid.link/9479B0506F544556+20260901065659.41273-1-jiawenwu@trustnetic.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/wangxun/libwx/wx_hw.c | 2 +- drivers/net/ethernet/wangxun/libwx/wx_type.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c index 122c4952d203..59cdd7d71e44 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c @@ -2520,7 +2520,7 @@ int wx_sw_init(struct wx *wx) spin_lock_init(&wx->hw_stats_lock); mutex_init(&wx->reset_lock); bitmap_zero(wx->state, WX_STATE_NBITS); - bitmap_zero(wx->flags, WX_PF_FLAGS_NBITS); + bitmap_zero(wx->flags, WX_FLAGS_NBITS); set_bit(WX_STATE_DOWN, wx->state); wx->misc_irq_domain = false; diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h index 9454e90258d8..a05a8c1f4049 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_type.h +++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h @@ -1269,7 +1269,7 @@ struct wx_rss_flow_map { u8 flag; }; -enum wx_pf_flags { +enum wx_flags { WX_FLAG_MULTI_64_FUNC, WX_FLAG_SWFW_RING, WX_FLAG_VMDQ_ENABLED, @@ -1291,13 +1291,13 @@ enum wx_pf_flags { WX_FLAG_RX_MERGE_ENABLED, WX_FLAG_TXHEAD_WB_ENABLED, WX_FLAG_NEED_PCIE_RECOVERY, - WX_PF_FLAGS_NBITS /* must be last */ + WX_FLAGS_NBITS /* must be last */ }; struct wx { unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; DECLARE_BITMAP(state, WX_STATE_NBITS); - DECLARE_BITMAP(flags, WX_PF_FLAGS_NBITS); + DECLARE_BITMAP(flags, WX_FLAGS_NBITS); void *priv; u8 __iomem *hw_addr; From bd3e260f496adb0123076a237e5e72598dee0404 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Tue, 28 Jul 2026 18:15:24 -0700 Subject: [PATCH 0125/2126] wifi: ath12k: remove skb->data check in ath12k_wmi_process_tpc_stats() Currently, ath12k_wmi_process_tpc_stats() has a !skb->data check. This check is pointless since skb->data is accessed by ath12k_wmi_op_rx() in order to dispatch the message to this function, therefore it is always non-NULL. Remove the pointless check and its associated warning message. Compile tested only. Assisted-by: Claude:claude-sonnet-4-6 Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260728-ath12k_wmi_process_tpc_stats-skb-check-v1-1-01b7d09be20d@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wmi.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c index d5160af60e00..7a8a0698b9d3 100644 --- a/drivers/net/wireless/ath/ath12k/wmi.c +++ b/drivers/net/wireless/ath/ath12k/wmi.c @@ -9992,11 +9992,6 @@ static void ath12k_wmi_process_tpc_stats(struct ath12k_base *ab, u32 event_count; int ret; - if (!skb->data) { - ath12k_warn(ab, "No data present in tpc stats event\n"); - return; - } - if (skb->len < (sizeof(*fixed_param) + TLV_HDR_SIZE)) { ath12k_warn(ab, "TPC stats event size invalid\n"); return; From f2576dc0f894ef33045ba7ed057ec417988bba8a Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Wed, 29 Jul 2026 15:18:11 +0800 Subject: [PATCH 0126/2126] wifi: ath12k: signal regd update completion when reg event is dropped During driver bring-up, ath12k_mac_hw_register() reinitializes ar->regd_update_completed and sends a set current country command to firmware. It then relies on the regulatory event from firmware to signal that completion via ath12k_reg_chan_list_event(). However, when the country being set is identical to the one already applied at boot time, ath12k_reg_validate_reg_info() returns ATH12K_REG_STATUS_DROP through the "Avoid multiple overwrites to default regd" path. In that case ath12k_reg_chan_list_event() jumps to mem_free before assigning pdev_idx, so pdev_idx stays at its initial value of 255, 'ar' remains NULL and complete_all() is never called. As a result the reinitialized completion is left unsignalled and the next ath12k_regd_update() waits the full timeout, printing: Timeout while waiting for regulatory update Fix this by assigning pdev_idx from the event's phy_id right after it is extracted, before validation, so that the drop and fallback paths still reach complete_all(). Change the guard at the end to check the index against ab->num_radios so that an out-of-range phy_id does not lead to an invalid pdevs[] access. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 906619a00967 ("wifi: ath12k: handle regulatory hints during mac registration") Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260729-ath12k-regd-wait-timeout-v1-1-504aa6e7e93c@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wmi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c index 7a8a0698b9d3..a63bbda0219c 100644 --- a/drivers/net/wireless/ath/ath12k/wmi.c +++ b/drivers/net/wireless/ath/ath12k/wmi.c @@ -6975,6 +6975,14 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk goto mem_free; } + /* + * Set the valid pdev_idx before validating so that, even when the + * event is dropped or falls back, the completion the caller in + * ath12k_mac_hw_register() may be waiting on is still signalled at + * the end and it does not time out. + */ + pdev_idx = reg_info->phy_id; + ret = ath12k_reg_validate_reg_info(ab, reg_info); if (ret == ATH12K_REG_STATUS_FALLBACK) { ath12k_warn(ab, "failed to validate reg info %d\n", ret); @@ -6991,7 +6999,6 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk } /* free old reg_info if it exist */ - pdev_idx = reg_info->phy_id; if (ab->reg_info[pdev_idx]) { ath12k_reg_reset_reg_info(ab->reg_info[pdev_idx]); kfree(ab->reg_info[pdev_idx]); @@ -7030,7 +7037,7 @@ fallback: out: /* In some error cases, even a valid pdev_idx might not be available */ - if (pdev_idx != 255) + if (pdev_idx < ab->num_radios) ar = ab->pdevs[pdev_idx].ar; /* During the boot-time update, 'ar' might not be allocated, From af8d103b2b23f8cf9a1a72b15b3873bad53470df Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Wed, 29 Jul 2026 15:18:12 +0800 Subject: [PATCH 0127/2126] wifi: ath12k: use per-radio ab in ath12k_mac_hw_register() In ath12k_mac_hw_register() the local 'ab' is fetched once from the first radio, i.e. ath12k_ah_to_ar(ah, 0)->ab. When an ath12k_hw spans more than one ath12k_base, the radios walked by for_each_ar() may belong to different ath12k_base instances. Using the function-scope 'ab' inside that loop then refers to the first radio's device, which is stale with respect to the ar being processed. This is not a functional problem currently: the loop only dereferences the stale 'ab' under hw_params->current_cc_support, which is set only for WCN7850 and QCC2072. Both devices expose a single radio per ath12k_hw, so 'ab' and ar->ab always point to the same ath12k_base. Still, relying on that is fragile. Cache ar->ab into a per-iteration 'this_ab' and use it for the country code programming and the log messages so that each radio is handled against its own ath12k_base regardless of how many radios an ath12k_hw spans. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260729-ath12k-regd-wait-timeout-v1-2-504aa6e7e93c@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/mac.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 99bf5cf79d10..9c83811b1312 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -15043,24 +15043,26 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR); for_each_ar(ah, ar, i) { + struct ath12k_base *this_ab = ar->ab; + /* Apply the regd received during initialization */ ret = ath12k_regd_update(ar, true); if (ret) { - ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret); + ath12k_err(this_ab, "ath12k regd update failed: %d\n", ret); goto err_unregister_hw; } - if (ar->ab->hw_params->current_cc_support && ab->new_alpha2[0]) { + if (this_ab->hw_params->current_cc_support && this_ab->new_alpha2[0]) { struct wmi_set_current_country_arg current_cc = {}; - memcpy(¤t_cc.alpha2, ab->new_alpha2, 2); - memcpy(&ar->alpha2, ab->new_alpha2, 2); + memcpy(¤t_cc.alpha2, this_ab->new_alpha2, 2); + memcpy(&ar->alpha2, this_ab->new_alpha2, 2); reinit_completion(&ar->regd_update_completed); ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); if (ret) - ath12k_warn(ar->ab, + ath12k_warn(this_ab, "failed set cc code for mac register: %d\n", ret); } From 04497f2a77216f27f60463c9b3d84c3c8f2cf62c Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Wed, 29 Jul 2026 15:18:13 +0800 Subject: [PATCH 0128/2126] wifi: ath12k: protect new_alpha2 access with base_lock ab->new_alpha2 is written under ab->base_lock by the 11d new country code event handler ath12k_reg_11d_new_cc_event() and by the SMBIOS BDF parser, and read under the same lock by ath12k_update_11d(). ath12k_mac_hw_register() however read ab->new_alpha2 without holding base_lock, racing with those writers. Take base_lock and copy the value into a local wmi_set_current_country_arg, mirroring what ath12k_update_11d() already does, and use the local copy afterwards. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260729-ath12k-regd-wait-timeout-v1-3-504aa6e7e93c@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/mac.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 9c83811b1312..b12e72ca4c9b 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -15052,11 +15052,17 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) goto err_unregister_hw; } - if (this_ab->hw_params->current_cc_support && this_ab->new_alpha2[0]) { + if (this_ab->hw_params->current_cc_support) { struct wmi_set_current_country_arg current_cc = {}; + spin_lock_bh(&this_ab->base_lock); memcpy(¤t_cc.alpha2, this_ab->new_alpha2, 2); - memcpy(&ar->alpha2, this_ab->new_alpha2, 2); + spin_unlock_bh(&this_ab->base_lock); + + if (!current_cc.alpha2[0]) + goto fw_stats_init; + + memcpy(&ar->alpha2, current_cc.alpha2, 2); reinit_completion(&ar->regd_update_completed); @@ -15067,6 +15073,7 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) ret); } +fw_stats_init: ath12k_fw_stats_init(ar); ath12k_debugfs_register(ar); } From 8ab8a5ee16b2fcb06837039dc42405ed53866fec Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Wed, 29 Jul 2026 15:18:14 +0800 Subject: [PATCH 0129/2126] wifi: ath12k: skip setting country code during registration when unchanged Currently ath12k_mac_hw_register() unconditionally sets ab->new_alpha2 to firmware. But when ab->new_alpha2 is the same as the country already applied at boot time (stored in ab->default_regd), setting it again is meaningless. So skip it in that case. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260729-ath12k-regd-wait-timeout-v1-4-504aa6e7e93c@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/mac.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index b12e72ca4c9b..879f5ad80921 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -15054,6 +15054,8 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) if (this_ab->hw_params->current_cc_support) { struct wmi_set_current_country_arg current_cc = {}; + struct ieee80211_regdomain *default_regd; + bool same_cc = false; spin_lock_bh(&this_ab->base_lock); memcpy(¤t_cc.alpha2, this_ab->new_alpha2, 2); @@ -15064,6 +15066,16 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) memcpy(&ar->alpha2, current_cc.alpha2, 2); + spin_lock_bh(&this_ab->base_lock); + default_regd = this_ab->default_regd[ar->pdev_idx]; + if (default_regd) + same_cc = !memcmp(default_regd->alpha2, + current_cc.alpha2, 2); + spin_unlock_bh(&this_ab->base_lock); + + if (same_cc) + goto fw_stats_init; + reinit_completion(&ar->regd_update_completed); ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); From 6132d70d0890c03546f6970893fd71938efb2a2f Mon Sep 17 00:00:00 2001 From: Abdun Nihaal Date: Sat, 1 Aug 2026 17:19:09 +0530 Subject: [PATCH 0130/2126] wifi: ath11k: Fix possible memory leak in ath11k_dp_srng_setup() In ath11k_dp_srng_setup(), the memory allocated for ring->vaddr_unaligned is not freed in the error paths that follow. Fix that by calling ath11k_dp_srng_cleanup() in those error paths. Compile tested only. Issue found using a prototype static analysis tool built on the LLVM compiler infrastructure. Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-sonnet-4-6 Reviewed-by: Baochen Qiang Signed-off-by: Abdun Nihaal Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260801114911.91483-1-nihaal@cse.iitm.ac.in Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/dp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c index f389b97acbdd..be65d73b904b 100644 --- a/drivers/net/wireless/ath/ath11k/dp.c +++ b/drivers/net/wireless/ath/ath11k/dp.c @@ -313,6 +313,7 @@ int ath11k_dp_srng_setup(struct ath11k_base *ab, struct dp_srng *ring, case HAL_RXDMA_DIR_BUF: break; default: + ath11k_dp_srng_cleanup(ab, ring); ath11k_warn(ab, "Not a valid ring type in dp :%d\n", type); return -EINVAL; } @@ -324,6 +325,7 @@ int ath11k_dp_srng_setup(struct ath11k_base *ab, struct dp_srng *ring, ret = ath11k_hal_srng_setup(ab, type, ring_num, mac_id, ¶ms); if (ret < 0) { + ath11k_dp_srng_cleanup(ab, ring); ath11k_warn(ab, "failed to setup srng: %d ring_id %d\n", ret, ring_num); return ret; From a7ab5c835e4253b6577e4137367c05bfddd79fa2 Mon Sep 17 00:00:00 2001 From: Julius Bairaktaris Date: Mon, 27 Jul 2026 00:19:07 +0200 Subject: [PATCH 0131/2126] wifi: ath11k: implement CE interrupt enable/disable for AHB ath11k_core_reset() calls ath11k_hif_ce_irq_disable() right before it powers the target down, but ath11k_ahb_hif_ops_ipq8074 never set the ce_irq_enable/ce_irq_disable pair, and ath11k_hif_ce_irq_disable() does nothing when the op is NULL. On AHB the copy engine interrupts and their tasklets therefore stay live across rproc_shutdown(), where the register space they touch is no longer accessible. Wire the ops up. The sequence is the one ath11k_ahb_stop() already runs, factored into a helper and reused, so behaviour on the stop path is unchanged. wcn6750 is not affected: it uses the pcic ops, which implement the pair already. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julius Bairaktaris Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260726221908.104873-2-julius@bairaktaris.de Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/ahb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index ec5bf5c9fd79..47df9db41fa5 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -391,12 +391,17 @@ static void ath11k_ahb_ext_irq_disable(struct ath11k_base *ab) ath11k_ahb_sync_ext_irqs(ab); } -static void ath11k_ahb_stop(struct ath11k_base *ab) +static void ath11k_ahb_ce_irq_disable_sync(struct ath11k_base *ab) { if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags)) ath11k_ahb_ce_irqs_disable(ab); ath11k_ahb_sync_ce_irqs(ab); ath11k_ahb_kill_tasklets(ab); +} + +static void ath11k_ahb_stop(struct ath11k_base *ab) +{ + ath11k_ahb_ce_irq_disable_sync(ab); timer_delete_sync(&ab->rx_replenish_retry); ath11k_ce_cleanup_pipes(ab); } @@ -804,6 +809,8 @@ static const struct ath11k_hif_ops ath11k_ahb_hif_ops_ipq8074 = { .map_service_to_pipe = ath11k_ahb_map_service_to_pipe, .power_down = ath11k_ahb_power_down, .power_up = ath11k_ahb_power_up, + .ce_irq_enable = ath11k_ahb_ce_irqs_enable, + .ce_irq_disable = ath11k_ahb_ce_irq_disable_sync, }; static const struct ath11k_hif_ops ath11k_ahb_hif_ops_wcn6750 = { From f7a74e131d3f0de04335dbe278bfb82bdafcdb3e Mon Sep 17 00:00:00 2001 From: Julius Bairaktaris Date: Mon, 27 Jul 2026 00:19:08 +0200 Subject: [PATCH 0132/2126] wifi: ath11k: disable interrupts during firmware crash recovery On IPQ8074 a firmware assert reboots the SoC: Unable to handle kernel read from unreadable memory at virtual address 0 pc : ath11k_hal_srng_access_begin+0xc/0x60 [ath11k] lr : ath11k_dp_rx_process_mon_status+0x15c/0xd84 [ath11k] Call trace: ath11k_hal_srng_access_begin+0xc/0x60 [ath11k] ath11k_dp_rx_process_mon_rings+0xa0/0x5d4 [ath11k] ath11k_dp_service_srng+0x1f4/0x348 [ath11k] ath11k_ahb_ext_grp_napi_poll+0x34/0xd4 [ath11k_ahb] __napi_poll+0x38/0x188 net_rx_action+0x120/0x2c0 ath11k_core_reconfigure_on_crash() tears the data path down with ath11k_dp_pdev_free(), ath11k_dp_free() and ath11k_hal_srng_clear(), which memsets the ring list. The DP NAPI is still running while that happens, so it services a ring whose address pointer has just been cleared. That function used to disable the interrupts first, until commit d455e805de70 ("wifi: ath11k: rearrange IRQ enable/disable in reset path") moved the disable into ath11k_core_reset(). reset_work is only queued from mhi.c and from the debugfs hw-restart handler, so AHB parts never run it on a real firmware crash. Their recovery goes QMI server exit -> restart_work -> ath11k_core_reconfigure_on_crash() -> ath11k_core_qmi_firmware_ready(), and nothing disables the interrupts anywhere along it. Disable them again on the crash path. The reset path has already done so by the time it gets here, hence the ab->is_reset check. This is also why the debugfs hw-restart trigger never showed the problem: it goes through ath11k_core_reset(), the one path that still had the disable. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Fixes: d455e805de70 ("wifi: ath11k: rearrange IRQ enable/disable in reset path") Assisted-by: Claude:claude-opus-5 Signed-off-by: Julius Bairaktaris Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260726221908.104873-3-julius@bairaktaris.de Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index 8039124e7832..d2ed6a0ea7e3 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -2334,6 +2334,16 @@ static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab) mutex_lock(&ab->core_lock); ath11k_thermal_unregister(ab); + + /* + * ath11k_core_reset() already disabled the interrupts on the reset + * path; only the firmware crash path reaches here with them live. + */ + if (!ab->is_reset) { + ath11k_hif_irq_disable(ab); + ath11k_hif_ce_irq_disable(ab); + } + ath11k_dp_pdev_free(ab); ath11k_cfr_deinit(ab); ath11k_spectral_deinit(ab); From 7dba43536f743eb93aec1bb4fce2c0f1495a6680 Mon Sep 17 00:00:00 2001 From: Rameshkumar Sundaram Date: Mon, 10 Aug 2026 11:14:52 +0530 Subject: [PATCH 0133/2126] mailmap: add entries for Rameshkumar Sundaram Map past iterations of my e-mail addresses to the current one. Signed-off-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260810054452.3245263-1-rameshkumar.sundaram@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index 8fb9f3898d7a..3f0d5a419032 100644 --- a/.mailmap +++ b/.mailmap @@ -749,6 +749,8 @@ Rakesh Pillai Ralf Baechle Ralf Wildenhues Ram Chandra Jangir +Rameshkumar Sundaram +Rameshkumar Sundaram Randy Dunlap Randy Dunlap Randy Dunlap From ede121c2c2c0894e161d2134fb6c5598ab72085e Mon Sep 17 00:00:00 2001 From: Sriram R Date: Mon, 10 Aug 2026 12:31:09 +0530 Subject: [PATCH 0134/2126] mailmap: add entries for Sriram R Map past iterations of my e-mail addresses to the current one. Signed-off-by: Sriram R Link: https://patch.msgid.link/20260810070109.700301-1-sriram.ramachandran@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .mailmap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 3f0d5a419032..482e6637a797 100644 --- a/.mailmap +++ b/.mailmap @@ -849,7 +849,8 @@ Sricharan Ramabadhran Srinivas Kandagatla Srinivas Kandagatla Srinivas Ramana -Sriram R +Sriram R +Sriram R Sriram Yagnaraman Stanislav Fomichev Stanislav Fomichev From 865b96bf16625aedfec8972d0528d370c245ff2a Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Mon, 10 Aug 2026 17:46:00 +0800 Subject: [PATCH 0135/2126] mailmap: add entries for Baochen Qiang Map past iterations of my e-mail addresses to the current one. Signed-off-by: Baochen Qiang Link: https://patch.msgid.link/20260810-mailmap-v1-1-95129af871ba@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .mailmap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 482e6637a797..4703de1d95d7 100644 --- a/.mailmap +++ b/.mailmap @@ -129,7 +129,8 @@ Axel Dyks Axel Lin Balakrishna Godavarthi Banajit Goswami -Baochen Qiang +Baochen Qiang +Baochen Qiang Baolin Wang Baolin Wang Baolin Wang From 4b8e9bccbe08ce5961540e6c63fac326c31c35bf Mon Sep 17 00:00:00 2001 From: Manish Dharanenthiran Date: Mon, 10 Aug 2026 22:36:09 +0530 Subject: [PATCH 0136/2126] mailmap: add entries for Manish Dharanenthiran Map past iterations of my e-mail addresses to the current one. Signed-off-by: Manish Dharanenthiran Link: https://patch.msgid.link/20260810-mailmap-v1-1-76b680fd0dd4@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index 4703de1d95d7..be1de3422043 100644 --- a/.mailmap +++ b/.mailmap @@ -565,6 +565,7 @@ Maheshwar Ajja Maíra Canal Malathi Gottam Manikanta Pubbisetty +Manish Dharanenthiran Manivannan Sadhasivam Manivannan Sadhasivam Manoj Basapathi From 3cf8fade4b0471db6f28b5ae4c76af1f47883d56 Mon Sep 17 00:00:00 2001 From: Vasanthakumar Thiagarajan Date: Mon, 10 Aug 2026 23:17:46 +0530 Subject: [PATCH 0137/2126] mailmap: update email address for Vasanthakumar Thiagarajan Add my current oss email address and map old codeaurora and quicinc addresses to it. Signed-off-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260810174746.3272636-1-vasanthakumar.thiagarajan@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .mailmap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index be1de3422043..7cd3b9ec4018 100644 --- a/.mailmap +++ b/.mailmap @@ -935,7 +935,8 @@ Vadim Fedorenko Valdis Kletnieks Vara Reddy Varadarajan Narayanan -Vasanthakumar Thiagarajan +Vasanthakumar Thiagarajan +Vasanthakumar Thiagarajan Vasily Averin Vasily Averin Vasily Averin From 52eec2e1fac8fa49ff853ccd30292f85d9751749 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Tue, 11 Aug 2026 11:29:02 +0530 Subject: [PATCH 0138/2126] mailmap: add entries for Aaradhana Sahu Map past iterations of my e-mail addresses to the current one. Signed-off-by: Aaradhana Sahu Link: https://patch.msgid.link/20260811055902.522384-1-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index 7cd3b9ec4018..b95cb85c1c89 100644 --- a/.mailmap +++ b/.mailmap @@ -10,6 +10,7 @@ # # Please keep this list dictionary sorted. # +Aaradhana Sahu Aaron Durbin Abel Vesa Abel Vesa From 06cca100ad083609ca9cc2d1f692546369144189 Mon Sep 17 00:00:00 2001 From: Andrew LaMarche Date: Tue, 30 Jun 2026 13:30:00 +0000 Subject: [PATCH 0139/2126] wifi: ath12k: support calibration-variant from device tree ath10k and ath11k support reading calibration variants from the device tree to locate the correct Board Description File (BDF). The ath12k-wsi binding already describes using qcom,calibration-variant but it is not implemented in the driver. Many ath12k designs expose all the radios under a single phy, each of which typically require a separate BDF. Without this, the radios may not come up or will not be calibrated correctly. Fix this by parsing the device tree for the generation-agnostic qcom,calibration-variant. This allows the driver to properly select, read and apply the correct BDF. Signed-off-by: Andrew LaMarche Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260630133001.1426824-1-andrewjlamarche@gmail.com [fixed checkpatch issues] Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/core.c | 23 +++++++++++++++++++++++ drivers/net/wireless/ath/ath12k/qmi.c | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index 262a2045309b..0c72948f3f56 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -792,6 +792,29 @@ int ath12k_core_check_smbios(struct ath12k_base *ab) return 0; } +int ath12k_core_check_dt(struct ath12k_base *ab) +{ + size_t max_len = sizeof(ab->qmi.target.bdf_ext); + const char *variant = NULL; + struct device_node *node; + + node = ab->dev->of_node; + if (!node) + return -ENOENT; + + of_property_read_string(node, "qcom,calibration-variant", + &variant); + if (!variant) + return -ENODATA; + + if (strscpy(ab->qmi.target.bdf_ext, variant, max_len) < 0) + ath12k_dbg(ab, ATH12K_DBG_BOOT, + "bdf variant string is longer than the buffer can accommodate (variant: %s)\n", + variant); + + return 0; +} + static int ath12k_core_soc_create(struct ath12k_base *ab) { int ret; diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c index 280e50a1f31d..50082505c882 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.c +++ b/drivers/net/wireless/ath/ath12k/qmi.c @@ -2972,6 +2972,10 @@ int ath12k_qmi_request_target_cap(struct ath12k_base *ab) if (r) ath12k_dbg(ab, ATH12K_DBG_QMI, "SMBIOS bdf variant name not set.\n"); + r = ath12k_core_check_dt(ab); + if (r) + ath12k_dbg(ab, ATH12K_DBG_QMI, "DT bdf variant name not set.\n"); + r = ath12k_acpi_start(ab); if (r) /* ACPI is optional so continue in case of an error */ From e6c2d73f27b3948cabec1017c9443fba24f1dcc1 Mon Sep 17 00:00:00 2001 From: Andrew LaMarche Date: Tue, 30 Jun 2026 13:30:01 +0000 Subject: [PATCH 0140/2126] dt-bindings: wireless: ath12k: drop qcom,ath12k-calibration-variant The ath12k-wsi binding documentation describes using the generation-specific qcom,ath12k-calibration-variant binding as well as the generation-agnostic qcom,calibration-variant binding to load board-specific calibration data from the device tree. However, the driver never implemented either of these. Given that no devices currently supported use qcom,ath12k-calibration-variant and the previous patch implements qcom,calibration-variant, drop the generation-specific version from the binding to prevent future confusion. Signed-off-by: Andrew LaMarche Acked-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260630133001.1426824-2-andrewjlamarche@gmail.com Signed-off-by: Jeff Johnson --- .../devicetree/bindings/net/wireless/qcom,ath12k-wsi.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Documentation/devicetree/bindings/net/wireless/qcom,ath12k-wsi.yaml b/Documentation/devicetree/bindings/net/wireless/qcom,ath12k-wsi.yaml index 589960144fe1..fa64c8aa56f5 100644 --- a/Documentation/devicetree/bindings/net/wireless/qcom,ath12k-wsi.yaml +++ b/Documentation/devicetree/bindings/net/wireless/qcom,ath12k-wsi.yaml @@ -58,13 +58,6 @@ properties: String to uniquely identify variant of the calibration data for designs with colliding bus and device ids - qcom,ath12k-calibration-variant: - $ref: /schemas/types.yaml#/definitions/string - deprecated: true - description: - String to uniquely identify variant of the calibration data for designs - with colliding bus and device ids - qcom,wsi-controller: $ref: /schemas/types.yaml#/definitions/flag description: From 32ec8488d75d122768b1977501bcb5ec799230c4 Mon Sep 17 00:00:00 2001 From: Miaoqing Pan Date: Thu, 6 Aug 2026 18:13:29 +0800 Subject: [PATCH 0141/2126] wifi: ath11k: fix sporadic WLAN initialization failures On WCN6750 platforms, reboot stress testing occasionally results in WLAN initialization failures after boot. The WPSS firmware reaches the running state successfully, but no WLAN interface is created. Analysis shows that ath11k_ahb depends on the QRTR SMD transport for QMI communication with WPSS firmware. However, this dependency is not currently expressed in Kconfig, allowing qrtr_smd and ath11k_ahb to load in either order when built as modules. If ath11k_ahb is loaded before qrtr_smd becomes available, WLAN initialization may not complete successfully. Make the QRTR and QRTR_SMD dependencies explicit and add a soft dependency to ensure qrtr_smd is loaded before ath11k_ahb. Tested-on: WCN6750 hw1.0 AHB WLAN.MSL.2.0.c2-00204-QCAMSLSWPLZ-1 Fixes: 00402f49d26f ("ath11k: Add support for WCN6750 device") Signed-off-by: Miaoqing Pan Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260806101331.484063-2-miaoqing.pan@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/Kconfig | 3 +++ drivers/net/wireless/ath/ath11k/ahb.c | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/net/wireless/ath/ath11k/Kconfig b/drivers/net/wireless/ath/ath11k/Kconfig index 122726f84492..44b520d2e66e 100644 --- a/drivers/net/wireless/ath/ath11k/Kconfig +++ b/drivers/net/wireless/ath/ath11k/Kconfig @@ -14,6 +14,9 @@ config ATH11K_AHB tristate "Atheros ath11k AHB support" depends on ATH11K depends on REMOTEPROC + select RPMSG + select QRTR + select QRTR_SMD help This module adds support for AHB bus diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index 47df9db41fa5..9ab255b50f87 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -1350,5 +1350,6 @@ static struct platform_driver ath11k_ahb_driver = { module_platform_driver(ath11k_ahb_driver); +MODULE_SOFTDEP("pre: qrtr_smd"); MODULE_DESCRIPTION("Driver support for Qualcomm Technologies 802.11ax WLAN AHB devices"); MODULE_LICENSE("Dual BSD/GPL"); From 1a7bcf5324c8e2de6512eca5b028b6b283181d3f Mon Sep 17 00:00:00 2001 From: Miaoqing Pan Date: Thu, 6 Aug 2026 18:13:30 +0800 Subject: [PATCH 0142/2126] wifi: ath11k: fix NULL dereference in ahb remove when QMI init incomplete On WCN6750, if QMI messages never arrive (for example when qrtr_smd is not ready), WLAN initialization stops before the device is fully registered. In this case ATH11K_FLAG_QMI_FAIL is not set because no QMI event handler is executed. When the driver is removed, ath11k_ahb_remove() still calls ath11k_core_deinit(), which eventually triggers ath11k_ce_cleanup_pipes() on uninitialized CE pipes and results in a NULL pointer dereference in ath11k_hal_srng_access_begin(): ath11k_hal_srng_access_begin+0x14/0x68 [ath11k] ath11k_ce_cleanup_pipes+0x184/0x190 [ath11k] ath11k_pcic_stop+0x24/0x38 [ath11k] ath11k_core_deinit+0xfc/0x1c0 [ath11k] ath11k_ahb_remove+0x38/0xa0 [ath11k_ahb] Fix this by invoking ath11k_ahb_remove_prepare() before the state check and skipping ath11k_core_deinit() if ATH11K_FLAG_REGISTERED is not set, core initialization did not complete and CE pipes may remain uninitialized, making ath11k_core_deinit() unsafe. Tested-on: WCN6750 hw1.0 AHB WLAN.MSL.2.0.c2-00204-QCAMSLSWPLZ-1 Fixes: 00402f49d26f ("ath11k: Add support for WCN6750 device") Signed-off-by: Miaoqing Pan Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260806101331.484063-3-miaoqing.pan@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/ahb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index 9ab255b50f87..5c41bfe2d52e 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -1303,14 +1303,15 @@ static void ath11k_ahb_remove(struct platform_device *pdev) { struct ath11k_base *ab = platform_get_drvdata(pdev); - if (test_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags)) { + ath11k_ahb_remove_prepare(ab); + + if (!test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) { ath11k_ahb_power_down(ab, false); ath11k_debugfs_soc_destroy(ab); ath11k_qmi_deinit_service(ab); goto qmi_fail; } - ath11k_ahb_remove_prepare(ab); ath11k_core_deinit(ab); qmi_fail: From 1d8e73163ef933624341075f576e2f36ef9133f7 Mon Sep 17 00:00:00 2001 From: Miaoqing Pan Date: Thu, 6 Aug 2026 18:13:31 +0800 Subject: [PATCH 0143/2126] wifi: ath11k: unregister PM notifier on QMI init failure path ath11k_core_init() registers a PM notifier before the QMI server becomes available. If the QMI server never arrives, the device remove() path can take the early-exit path introduced for QMI initialization failures, skipping ath11k_core_deinit(). As a result, the PM notifier remains registered after the ath11k base object has been freed. A subsequent suspend or resume event may invoke the stale notifier and trigger a use-after-free. Fix this by explicitly unregistering the PM notifier in the QMI failure cleanup path before releasing ath11k resources. Tested-on: WCN6750 hw1.0 AHB WLAN.MSL.2.0.c2-00204-QCAMSLSWPLZ-1 Fixes: 32d93b51bc7e ("wifi: ath11k: choose default PM policy for hibernation") Signed-off-by: Miaoqing Pan Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260806101331.484063-4-miaoqing.pan@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/ahb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index 5c41bfe2d52e..27d01411b6e9 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -1309,6 +1309,7 @@ static void ath11k_ahb_remove(struct platform_device *pdev) ath11k_ahb_power_down(ab, false); ath11k_debugfs_soc_destroy(ab); ath11k_qmi_deinit_service(ab); + ath11k_core_pm_notifier_unregister(ab); goto qmi_fail; } From d5f5853f167fe2e584be013e111d03c1207969fe Mon Sep 17 00:00:00 2001 From: Adriano Cordova Date: Tue, 1 Sep 2026 22:57:04 -0400 Subject: [PATCH 0144/2126] netdevsim: take bus device refcount before registering device nsim_bus_dev_release() drops nsim_bus_devs when a device is freed, but the matching increment was done in new_device_store() after nsim_bus_dev_new() returned. When device_register() failed inside nsim_bus_dev_new(), put_device() invoked the release callback and decremented without an increment, driving the refcount to zero; a later creation then incremented from zero (refcount_t: addition on 0). Increment nsim_bus_devs in nsim_bus_dev_new() before device_register(), and drop the bus reference in nsim_bus_exit() only after every device has been removed, so the completion cannot be signaled early. Cc: stable+noautosel@kernel.org # netdevsim is a test harness, it's never loaded on production systems Reported-by: syzbot+989ff6506f5c6d1ff56b@syzkaller.appspot.com Closes: https://syzkaller.appspot.com/bug?extid=989ff6506f5c6d1ff56b Signed-off-by: Adriano Cordova Link: https://patch.msgid.link/20260902025704.34606-1-adrianox@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/bus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index 5c55c308487b..b792ee10b1c1 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -194,7 +194,6 @@ new_device_store(const struct bus_type *bus, const char *buf, size_t count) goto err; } - refcount_inc(&nsim_bus_devs); /* Allow using nsim_bus_dev */ smp_store_release(&nsim_bus_dev->init, true); @@ -465,6 +464,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queu /* Disallow using nsim_bus_dev */ smp_store_release(&nsim_bus_dev->init, false); + refcount_inc(&nsim_bus_devs); err = device_register(&nsim_bus_dev->dev); if (err) goto err_nsim_bus_dev_id_free; @@ -520,8 +520,6 @@ void nsim_bus_exit(void) /* Disallow using resources */ smp_store_release(&nsim_bus_enable, false); - if (refcount_dec_and_test(&nsim_bus_devs)) - complete(&nsim_bus_devs_released); mutex_lock(&nsim_bus_dev_list_lock); list_for_each_entry_safe(nsim_bus_dev, tmp, &nsim_bus_dev_list, list) { @@ -530,6 +528,9 @@ void nsim_bus_exit(void) } mutex_unlock(&nsim_bus_dev_list_lock); + if (refcount_dec_and_test(&nsim_bus_devs)) + complete(&nsim_bus_devs_released); + wait_for_completion(&nsim_bus_devs_released); driver_unregister(&nsim_driver); From 94284e5442bac57a33da5dd48549eb5ec803fa97 Mon Sep 17 00:00:00 2001 From: Miguel Garcia Date: Wed, 2 Sep 2026 11:57:30 +0200 Subject: [PATCH 0145/2126] devlink: use direct firmware requests for flash updates request_firmware() may enter the sysfs fallback and call try_to_freeze(). Devlink invokes it while holding the instance lock, causing syzbot to report: WARNING: syz-executor/... still has locks held! Firmware flash requests already name a file provided by userspace. Use request_firmware_direct() in both flash update paths so a missing file fails immediately instead of entering the sysfs fallback. This keeps the normal devlink locking intact. On systems with CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y, devlink flash can no longer obtain a missing image through that fallback. Callers still receive the existing error result, and netlink users retain the extack message. Cc: stable+noautosel@kernel.org # FW_LOADER_USER_HELPER_FALLBACK=y has no known use Reported-by: syzbot+372a7d84708b07f64d9b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=372a7d84708b07f64d9b Suggested-by: Jakub Kicinski Signed-off-by: Miguel Garcia Link: https://patch.msgid.link/20260902095739.3587287-1-miguelgarciaroman8@gmail.com Signed-off-by: Jakub Kicinski --- net/devlink/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/devlink/dev.c b/net/devlink/dev.c index 55959b0ff5ab..b85bb02a9e80 100644 --- a/net/devlink/dev.c +++ b/net/devlink/dev.c @@ -1169,7 +1169,7 @@ int devlink_nl_flash_update_doit(struct sk_buff *skb, struct genl_info *info) nla_file_name = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]; file_name = nla_data(nla_file_name); - ret = request_firmware(¶ms.fw, file_name, devlink->dev); + ret = request_firmware_direct(¶ms.fw, file_name, devlink->dev); if (ret) { NL_SET_ERR_MSG_ATTR(info->extack, nla_file_name, "failed to locate the requested firmware file"); @@ -1245,7 +1245,7 @@ int devlink_compat_flash_update(struct devlink *devlink, const char *file_name) goto out_unlock; } - ret = request_firmware(¶ms.fw, file_name, devlink->dev); + ret = request_firmware_direct(¶ms.fw, file_name, devlink->dev); if (ret) goto out_unlock; From e84b89f17a12a7cfc526eb1c18ac02e8777e18c9 Mon Sep 17 00:00:00 2001 From: Vitaliy Sochnev Date: Tue, 1 Sep 2026 19:32:54 +0100 Subject: [PATCH 0146/2126] net: airoha: grow the small RX rings Raise the RX_DSCP_NUM() fallback from 16 to 32, the vendor SDK default, and give ring 4 the 128 descriptors already used for rings 2/11/15. Ring 4 is the shared "force to CPU" ring that airoha_fe_vip_setup() routes BOOTP, PPPoE Discovery, PPP LCP/IPCP/CHAP/PAP/IPv6CP, ISAKMP, DHCPv6, SIP and LLDP onto, so it sees the same bursty non-hashed traffic as the rings already on 128 while sitting on the smallest allowance. Both CDMs forward to it: REG_CDM_FWD_CFG(1) and (2) each set CDM_VIP_QSEL_MASK to 4. The NO_CPU_DSCP fix does not cover this. With it in place, at 16 descriptors the ring still dies during PPPoE negotiation on a Nokia XG-040G-MF: over 6455 devmem samples in 60 s, REG_RX_DMA_IDX advanced 0x2c -> 0x52 while REG_RX_CPU_IDX stayed at 15, descriptor 15 had DONE set on a 60-byte frame, descriptors 0-14 were empty, and q->tail was 0. Hw had completed a descriptor the strictly sequential consumer in airoha_qdma_rx_process() cannot reach, and negotiation never completes. At 16 DHCP still works while PPPoE does not: a dial-up bursts Discovery, LCP, IPCP and CHAP where DHCP sends one packet every ~150 s. With this series, 508 forced reconnects over 20 h saw no recurrence. RX_DONE_INT_MASK covers all 32 rings on both QDMA instances, so this costs 544 more descriptors per instance, 1088 in total: 2.1 MiB of RX buffers at PAGE_SIZE/2 each, plus 34 KiB of coherent descriptor memory. Ring 4 and the VIP classification feeding it are shared driver-wide, with no DT or hardware property distinguishing one variant's ring 4 from another's, so this is not scoped to a particular SoC. Acked-by: Lorenzo Bianconi Signed-off-by: Vitaliy Sochnev Link: https://patch.msgid.link/978fe95e4c5ddb05ceb7d8c4d00ea2d2203b79d0.1788286284.git.sochnev.v.74@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/airoha/airoha_eth.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h index 8277c1c87bb3..527e3833e36b 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.h +++ b/drivers/net/ethernet/airoha/airoha_eth.h @@ -41,9 +41,10 @@ #define TX_DSCP_NUM 1024 #define RX_DSCP_NUM(_n) \ ((_n) == 2 ? 128 : \ + (_n) == 4 ? 128 : \ (_n) == 11 ? 128 : \ (_n) == 15 ? 128 : \ - (_n) == 0 ? 1024 : 16) + (_n) == 0 ? 1024 : 32) #define PSE_RSV_PAGES 128 #define PSE_QUEUE_RSV_PAGES 64 From 8c9190bfd18a2548dea677faed7d6ee11f3cb0c8 Mon Sep 17 00:00:00 2001 From: Donggeun Yoo Date: Wed, 2 Sep 2026 15:58:27 +0900 Subject: [PATCH 0147/2126] net: phy: dp83848: check phy_read() return value in config_init() dp83848_config_init() reads BMCR to detect whether auto-negotiation is enabled, but does not check the phy_read() return value. On an MDIO read failure phy_read() returns a negative errno, which is then used directly in a bitwise test; the auto-negotiation state is left undefined while config_init() still reports success. Check the return value and propagate the error. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: Donggeun Yoo Reviewed-by: Maxime Chevallier Reviewed-by: Xuanqiang Luo Link: https://patch.msgid.link/20260902065828.1031113-1-donggeunyoo.kernel@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/dp83848.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/phy/dp83848.c b/drivers/net/phy/dp83848.c index d88b1999d596..e65651ac567a 100644 --- a/drivers/net/phy/dp83848.c +++ b/drivers/net/phy/dp83848.c @@ -117,6 +117,9 @@ static int dp83848_config_init(struct phy_device *phydev) * we check initial value of BMCR Auto negotiation enable bit */ val = phy_read(phydev, MII_BMCR); + if (val < 0) + return val; + if (!(val & BMCR_ANENABLE)) phydev->autoneg = AUTONEG_DISABLE; From 6ebcf5074cff0402730c6981d2397139fee6322d Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Wed, 2 Sep 2026 22:30:41 +0200 Subject: [PATCH 0148/2126] net: openvswitch: don't schedule rebalancing if there are no datapaths During namespace initialization the masks rebalancing work is scheduled and automatically re-scheduled every 4 seconds afterwards. This is happening in every namespace. On a large kubernetes node with 500 pods, i.e., 500+ namespaces, this creates a decent amount of unnecessary churn scheduling 500 jobs every 4 seconds that take the mutex, check that there are no datapaths in their namespace, release the mutex, re-schedule themselves and exit. These 500 unnecessary mutex locks may hold off operations in a single namespace that actually has a datapath configured and has real user requests to handle under this lock. They can also add delay to removal of other namespaces as ovs_exit_net() needs to take that lock as well and synchronously waits for the work to be cancelled. Let's only fire the job when the first datapath is actually created and not re-arm it if there are no more datapaths configured in the namespace. Another approach would be to make ovs_mutex per-namespace, but it's a much larger change that should be handled separately, and the unnecessary work scheduling feels like a waste regardless. It's safe to check and re-arm outside of the mutex as DP_CMD_NEW handler will re-arm if the new datapath appears. The scheduling attempt also doesn't change the work or delay if it is already queued, so it's also safe to call multiple times. Skipping the re-arming is more elegant than canceling on removal of the last datapath as it allows us to not think about potential race conditions at a negligible cost of potentially one extra re-scheduling. msecs_to_jiffies() moved to the macro to save on line length. Signed-off-by: Ilya Maximets Acked-by: Eelco Chaudron Link: https://patch.msgid.link/20260902203200.1416026-1-i.maximets@ovn.org Signed-off-by: Jakub Kicinski --- net/openvswitch/datapath.c | 14 ++++++++++---- net/openvswitch/datapath.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 631a03136fa1..218703414325 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -1921,6 +1921,10 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) ovs_unlock(); + /* Start periodic mask rebalancing if it wasn't already. */ + schedule_delayed_work(&ovs_net->masks_rebalance, + DP_MASKS_REBALANCE_INTERVAL); + ovs_notify(&dp_datapath_genl_family, reply, info); return 0; @@ -2598,16 +2602,20 @@ static void ovs_dp_masks_rebalance(struct work_struct *work) struct ovs_net *ovs_net = container_of(work, struct ovs_net, masks_rebalance.work); struct datapath *dp; + bool rearm; ovs_lock(); list_for_each_entry(dp, &ovs_net->dps, list_node) ovs_flow_masks_rebalance(&dp->table); + rearm = !list_empty(&ovs_net->dps); + ovs_unlock(); - schedule_delayed_work(&ovs_net->masks_rebalance, - msecs_to_jiffies(DP_MASKS_REBALANCE_INTERVAL)); + if (rearm) + schedule_delayed_work(&ovs_net->masks_rebalance, + DP_MASKS_REBALANCE_INTERVAL); } static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { @@ -2713,8 +2721,6 @@ static int __net_init ovs_init_net(struct net *net) if (err) return err; - schedule_delayed_work(&ovs_net->masks_rebalance, - msecs_to_jiffies(DP_MASKS_REBALANCE_INTERVAL)); return 0; } diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h index b2c2b8da12d4..7a7afaeceee5 100644 --- a/net/openvswitch/datapath.h +++ b/net/openvswitch/datapath.h @@ -23,7 +23,7 @@ #define DP_MAX_PORTS USHRT_MAX #define DP_VPORT_HASH_BUCKETS 1024 -#define DP_MASKS_REBALANCE_INTERVAL 4000 +#define DP_MASKS_REBALANCE_INTERVAL msecs_to_jiffies(4000) /** * struct dp_stats_percpu - per-cpu packet processing statistics for a given From 00f623647c331d31df8629af958f7582a7fc874c Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:44:56 +1000 Subject: [PATCH 0149/2126] wifi: mac80211: don't seed an S1G sta's last_rate When initialising the rate control system, ieee80211_s1g_sta_rate_init() is called for S1G stations during association where it initialises a last rate of type STA_STATS_RATE_TYPE_S1G but does not initialise nss, mcs bw etc. Since the last_rate no longer has a value equivalent to STA_STATS_RATE_INVALID, the invalid rate will be decoded and the NL80211_STA_INFO_RX_BITRATE flag will be set. As a result, there is a period during association before the first data frame is rx'ed where the seeded value is overwritten by ieee80211_rx_h_sta_process() while this invalid last_rate lives. If the sta is desroyed during this process, nl80211_put_sta_rate() will call into cfg80211_calculate_bitrate() and attempt to calculate the bitrate using the invalid last_rate leading to a WARN: 4,336,675067400,-;------------[ cut here ]------------ 4,337,675067524,-;WARNING: net/wireless/util.c:1960 at cfg80211_calculate_bitrate+0x4d8/0x8b0 [cfg80211], CPU#3: kworker/u16:3/874 4,338,675068176,-;invalid rate bw=0, mcs=0, nss=0 [snip loaded modules] 4,341,675068954,-;Hardware name: BCM2711 4,342,675068961,-;Workqueue: events_unbound cfg80211_wiphy_work [cfg80211] 4,343,675069386,-;Call trace: 4,344,675069392,-; unwind_backtrace from show_stack+0x10/0x14 4,345,675069440,-; show_stack from dump_stack_lvl+0xa8/0xb8 4,346,675069475,-; dump_stack_lvl from __warn+0x90/0x224 4,347,675069517,-; __warn from warn_slowpath_fmt+0x130/0x1a8 4,348,675069559,-; warn_slowpath_fmt from cfg80211_calculate_bitrate+0x4d8/0x8b0 [cfg80211] 4,349,675070005,-; cfg80211_calculate_bitrate [cfg80211] from nl80211_put_sta_rate+0x48/0x590 [cfg80211] 4,350,675070819,-; nl80211_put_sta_rate [cfg80211] from nl80211_put_sta_info_common+0x4f4/0xd50 [cfg80211] 4,351,675071616,-; nl80211_put_sta_info_common [cfg80211] from nl80211_send_station.constprop.0+0x114/0x424 [cfg80211] 4,352,675072427,-; nl80211_send_station.constprop.0 [cfg80211] from cfg80211_del_sta_sinfo+0xc4/0x368 [cfg80211] 4,353,675073222,-; cfg80211_del_sta_sinfo [cfg80211] from __sta_info_destroy_part2+0x108/0x2c0 [mac80211] 4,354,675074178,-; __sta_info_destroy_part2 [mac80211] from sta_info_destroy_addr+0x4c/0x88 [mac80211] 4,355,675075243,-; sta_info_destroy_addr [mac80211] from ieee80211_destroy_assoc_data+0x194/0x2d8 [mac80211] 4,356,675075920,-; ieee80211_destroy_assoc_data [mac80211] from ieee80211_rx_mgmt_assoc_resp+0x220/0x1d4c [mac80211] 4,357,675076558,-; ieee80211_rx_mgmt_assoc_resp [mac80211] from ieee80211_iface_work+0x1c0/0x5d0 [mac80211] 4,358,675077187,-; ieee80211_iface_work [mac80211] from cfg80211_wiphy_work+0x110/0x368 [cfg80211] 4,359,675077763,-; cfg80211_wiphy_work [cfg80211] from process_one_work+0x260/0x868 4,360,675078022,-; process_one_work from worker_thread+0x1bc/0x3ec 4,361,675078042,-; worker_thread from kthread+0x120/0x154 4,362,675078060,-; kthread from ret_from_fork+0x14/0x20 4,363,675078074,-;Exception stack(0xf0ac1fb0 to 0xf0ac1ff8) 4,364,675078081,-;1fa0: 00000000 00000000 00000000 00000000 4,365,675078088,-;1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 4,366,675078093,-;1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 4,367,675080226,-;irq event stamp: 15780967 4,368,675080287,-;hardirqs last enabled at (15780975): [] __up_console_sem+0x50/0x60 4,369,675080395,-;hardirqs last disabled at (15780982): [] __up_console_sem+0x3c/0x60 4,370,675080497,-;softirqs last enabled at (15780966): [] handle_softirqs+0x398/0x650 4,371,675080608,-;softirqs last disabled at (15780939): [] __irq_exit_rcu+0x150/0x1f0 4,372,675080715,-;---[ end trace 0000000000000000 ]--- To fix, we can simply not seed this psuedo rate. It was originally implemented to avoid errornous paths that S1G shouldn't take, but those have since been fixed / cleaned up. While we are here, we also don't need to initialise the tx side's last rate with IEEE80211_TX_RC_S1G_MCS (which is equivalent to IEEE80211_TX_RC_VHT_MCS). The entire tx reporting side does not support S1G widths and is assumed to be handled by the driver so we can just remove the entire function. Fixes: 12bf8fad4ca3 ("mac80211: initialize last_rate for S1G STAs") Signed-off-by: Lachlan Hodges Link: https://patch.msgid.link/20260827054456.254573-1-lachlan.hodges@morsemicro.com Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 1 - net/mac80211/mlme.c | 14 +++++--------- net/mac80211/rate.c | 1 - net/mac80211/s1g.c | 8 -------- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 5761e9621491..d06cb8e7dfb3 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2388,7 +2388,6 @@ ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif, const struct ieee80211_he_operation *he_op_ie_elem); /* S1G */ -void ieee80211_s1g_sta_rate_init(struct sta_info *sta); bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb); void ieee80211_s1g_rx_twt_action(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb); diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index f51167f0fc46..47ec703f1094 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -6347,7 +6347,6 @@ out: } static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link, - struct sta_info *sta, struct link_sta_info *link_sta, struct cfg80211_bss *cbss) { @@ -6362,11 +6361,9 @@ static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link, memcpy(link_sta->addr, cbss->bssid, ETH_ALEN); memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN); - /* TODO: S1G Basic Rate Set is expressed elsewhere */ - if (cbss->channel->band == NL80211_BAND_S1GHZ) { - ieee80211_s1g_sta_rate_init(sta); + /* S1G does not use basic rates */ + if (cbss->channel->band == NL80211_BAND_S1GHZ) return 0; - } sband = local->hw.wiphy->bands[cbss->channel->band]; @@ -7107,7 +7104,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, } } - err = ieee80211_mgd_setup_link_sta(link, sta, link_sta, + err = ieee80211_mgd_setup_link_sta(link, link_sta, assoc_data->link[link_id].bss); if (err) goto out_err; @@ -9699,8 +9696,7 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, goto out_err; } - err = ieee80211_mgd_setup_link_sta(link, new_sta, - link_sta, cbss); + err = ieee80211_mgd_setup_link_sta(link, link_sta, cbss); if (err) { rcu_read_unlock(); sta_info_free(local, new_sta); @@ -11090,7 +11086,7 @@ ieee80211_process_ml_reconf_resp(struct ieee80211_sub_if_data *sdata, goto disconnect; } - if (ieee80211_mgd_setup_link_sta(link, sta, link_sta, + if (ieee80211_mgd_setup_link_sta(link, link_sta, add_links_data->link[link_id].bss)) goto disconnect; diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index 64768abb0a5f..bcc6c4167395 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c @@ -57,7 +57,6 @@ void rate_control_rate_init(struct link_sta_info *link_sta) /* TODO: check for minstrel_s1g ? */ if (sband->band == NL80211_BAND_S1GHZ) { - ieee80211_s1g_sta_rate_init(sta); rcu_read_unlock(); return; } diff --git a/net/mac80211/s1g.c b/net/mac80211/s1g.c index bd7baf481836..4b70afa6e6d7 100644 --- a/net/mac80211/s1g.c +++ b/net/mac80211/s1g.c @@ -9,14 +9,6 @@ #include "ieee80211_i.h" #include "driver-ops.h" -void ieee80211_s1g_sta_rate_init(struct sta_info *sta) -{ - /* avoid indicating legacy bitrates for S1G STAs */ - sta->deflink.tx_stats.last_rate.flags |= IEEE80211_TX_RC_S1G_MCS; - sta->deflink.rx_stats.last_rate = - STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_S1G); -} - bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb) { struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; From edad0797f1a721f736b5c59fcb2bb6a13ac636f2 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 27 Aug 2026 15:46:08 +1000 Subject: [PATCH 0150/2126] wifi: cfg80211: remove duplicate s1g_cap kerneldoc ieee80211_supported_band::s1g_cap is already annotated. Remove the duplicate. Signed-off-by: Lachlan Hodges Link: https://patch.msgid.link/20260827054608.254883-1-lachlan.hodges@morsemicro.com Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 97c16d4ff127..2abf9e20cc22 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -576,7 +576,6 @@ struct ieee80211_sta_s1g_cap { * @vht_cap: VHT capabilities in this band * @s1g_cap: S1G capabilities in this band * @edmg_cap: EDMG capabilities in this band - * @s1g_cap: S1G capabilities in this band (S1G band only, of course) * @n_iftype_data: number of iftype data entries * @iftype_data: interface type data entries. Note that the bits in * @types_mask inside this structure cannot overlap (i.e. only From b120ec039fae389405549b47ac5cf3a4f5c7b5f3 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 26 Jul 2026 17:30:35 -0700 Subject: [PATCH 0151/2126] wifi: mwifiex: Use flexible array for RX reorder table Embed the RX reorder pointer array in struct mwifiex_rx_reorder_tbl instead of allocating it separately. This ties the array to the reorder table lifetime and removes a separate allocation and cleanup path. Change the void pointer type to the proper one for clarity. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev Link: https://patch.msgid.link/20260727003035.118047-1-rosenp@gmail.com Signed-off-by: Johannes Berg --- .../wireless/marvell/mwifiex/11n_rxreorder.c | 20 +++---------------- drivers/net/wireless/marvell/mwifiex/main.h | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c index 9deb47f22a61..06b005525078 100644 --- a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c +++ b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c @@ -213,7 +213,6 @@ mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv, list_del(&tbl->list); spin_unlock_bh(&priv->rx_reorder_tbl_lock); - kfree(tbl->rx_reorder_ptr); kfree(tbl); spin_lock_bh(&priv->adapter->rx_proc_lock); @@ -329,7 +328,6 @@ static void mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta, int tid, int win_size, int seq_num) { - int i; struct mwifiex_rx_reorder_tbl *tbl, *new_node; u16 last_seq = 0; struct mwifiex_sta_node *node; @@ -344,10 +342,12 @@ mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta, return; } /* if !tbl then create one */ - new_node = kzalloc_obj(struct mwifiex_rx_reorder_tbl); + new_node = kzalloc_flex(*new_node, rx_reorder_ptr, win_size); if (!new_node) return; + new_node->win_size = win_size; + INIT_LIST_HEAD(&new_node->list); new_node->tid = tid; memcpy(new_node->ta, ta, ETH_ALEN); @@ -381,26 +381,12 @@ mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta, new_node->flags |= RXREOR_INIT_WINDOW_SHIFT; } - new_node->win_size = win_size; - - new_node->rx_reorder_ptr = kcalloc(win_size, sizeof(void *), - GFP_KERNEL); - if (!new_node->rx_reorder_ptr) { - kfree(new_node); - mwifiex_dbg(priv->adapter, ERROR, - "%s: failed to alloc reorder_ptr\n", __func__); - return; - } - new_node->timer_context.ptr = new_node; new_node->timer_context.priv = priv; new_node->timer_context.timer_is_set = false; timer_setup(&new_node->timer_context.timer, mwifiex_flush_data, 0); - for (i = 0; i < win_size; ++i) - new_node->rx_reorder_ptr[i] = NULL; - spin_lock_bh(&priv->rx_reorder_tbl_lock); list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr); spin_unlock_bh(&priv->rx_reorder_tbl_lock); diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h index 27559e2ddc31..8e6238c01aa6 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.h +++ b/drivers/net/wireless/marvell/mwifiex/main.h @@ -708,10 +708,10 @@ struct mwifiex_rx_reorder_tbl { int init_win; int start_win; int win_size; - void **rx_reorder_ptr; struct reorder_tmr_cnxt timer_context; u8 amsdu; u8 flags; + struct sk_buff *rx_reorder_ptr[] __counted_by(win_size); }; struct mwifiex_bss_prio_node { From 87beac0a1d3d350c0c0c018967d991a2c2d1aecb Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 10 May 2026 21:19:34 -0700 Subject: [PATCH 0152/2126] wifi: b43legacy: Use flexible array for DMA metadata Store the per-descriptor metadata in the DMA ring allocation instead of allocating it separately. This ties the metadata lifetime directly to the ring, removes a separate allocation failure path, and keeps the descriptor count available for __counted_by() bounds checking. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev Link: https://patch.msgid.link/20260511041934.378209-1-rosenp@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/b43legacy/dma.c | 24 ++++++++----------- drivers/net/wireless/broadcom/b43legacy/dma.h | 4 ++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/broadcom/b43legacy/dma.c b/drivers/net/wireless/broadcom/b43legacy/dma.c index a9557356c9ab..6c3d847242bb 100644 --- a/drivers/net/wireless/broadcom/b43legacy/dma.c +++ b/drivers/net/wireless/broadcom/b43legacy/dma.c @@ -610,25 +610,25 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev, int nr_slots; dma_addr_t dma_test; - ring = kzalloc_obj(*ring); + if (for_tx) + nr_slots = B43legacy_TXRING_SLOTS; + else + nr_slots = B43legacy_RXRING_SLOTS; + + ring = kzalloc_flex(*ring, meta, nr_slots); if (!ring) goto out; + + ring->nr_slots = nr_slots; ring->type = type; ring->dev = dev; - nr_slots = B43legacy_RXRING_SLOTS; - if (for_tx) - nr_slots = B43legacy_TXRING_SLOTS; - - ring->meta = kzalloc_objs(struct b43legacy_dmadesc_meta, nr_slots); - if (!ring->meta) - goto err_kfree_ring; if (for_tx) { ring->txhdr_cache = kcalloc(nr_slots, sizeof(struct b43legacy_txhdr_fw3), GFP_KERNEL); if (!ring->txhdr_cache) - goto err_kfree_meta; + goto err_kfree_ring; /* test for ability to dma to txhdr_cache */ dma_test = dma_map_single(dev->dev->dma_dev, ring->txhdr_cache, @@ -643,7 +643,7 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev, sizeof(struct b43legacy_txhdr_fw3), GFP_KERNEL | GFP_DMA); if (!ring->txhdr_cache) - goto err_kfree_meta; + goto err_kfree_txhdr_cache; dma_test = dma_map_single(dev->dev->dma_dev, ring->txhdr_cache, @@ -660,7 +660,6 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev, DMA_TO_DEVICE); } - ring->nr_slots = nr_slots; ring->mmio_base = b43legacy_dmacontroller_base(type, controller_index); ring->index = controller_index; if (for_tx) { @@ -694,8 +693,6 @@ err_free_ringmemory: free_ringmemory(ring); err_kfree_txhdr_cache: kfree(ring->txhdr_cache); -err_kfree_meta: - kfree(ring->meta); err_kfree_ring: kfree(ring); ring = NULL; @@ -720,7 +717,6 @@ static void b43legacy_destroy_dmaring(struct b43legacy_dmaring *ring) free_ringmemory(ring); kfree(ring->txhdr_cache); - kfree(ring->meta); kfree(ring); } diff --git a/drivers/net/wireless/broadcom/b43legacy/dma.h b/drivers/net/wireless/broadcom/b43legacy/dma.h index b5c1a51db2a4..edd06225b64f 100644 --- a/drivers/net/wireless/broadcom/b43legacy/dma.h +++ b/drivers/net/wireless/broadcom/b43legacy/dma.h @@ -122,8 +122,6 @@ enum b43legacy_dmatype { struct b43legacy_dmaring { /* Kernel virtual base address of the ring memory. */ void *descbase; - /* Meta data about all descriptors. */ - struct b43legacy_dmadesc_meta *meta; /* Cache of TX headers for each slot. * This is to avoid an allocation on each TX. * This is NULL for an RX ring. @@ -161,6 +159,8 @@ struct b43legacy_dmaring { /* Last time we injected a ring overflow. */ unsigned long last_injected_overflow; #endif /* CONFIG_B43LEGACY_DEBUG*/ + /* Meta data about all descriptors. */ + struct b43legacy_dmadesc_meta meta[] __counted_by(nr_slots); }; From fa01779ff9916b7f3895954185af7c2e519c0435 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 31 Jul 2026 14:02:32 +0200 Subject: [PATCH 0153/2126] wifi: skip DUO params when looking for NPCA If DUO parameters are present, they need to be skipped. This was missed during the D1.3 -> D1.4 transition and causes frames to be mis-parsed for NPCA when DUO is also enabled. Link: https://patch.msgid.link/20260731140351.cb57484a68b1.I229dcd80b8e30c3fdfe8eedb81725dc35d9d9fe1@changeid Signed-off-by: Johannes Berg --- include/linux/ieee80211-uhr.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/ieee80211-uhr.h b/include/linux/ieee80211-uhr.h index 665d4b3a5b41..398ce01fcdee 100644 --- a/include/linux/ieee80211-uhr.h +++ b/include/linux/ieee80211-uhr.h @@ -341,6 +341,9 @@ ieee80211_uhr_npca_info(const struct ieee80211_uhr_operation *oper) if (!(oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_NPCA_ENA))) return NULL; + if (oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_DUO_PRES)) + pos += 1; + if (oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_DPS_PRES)) pos += sizeof(struct ieee80211_uhr_dps_info); @@ -372,6 +375,9 @@ ieee80211_uhr_oper_dbe_info(const struct ieee80211_uhr_operation *oper) if (!(oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_DBE_ENA))) return NULL; + if (oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_DUO_PRES)) + pos += 1; + if (oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_DPS_PRES)) pos += sizeof(struct ieee80211_uhr_dps_info); From d25ba7909b2781c827f8b2928f201307c3ad6e44 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 31 Jul 2026 14:02:33 +0200 Subject: [PATCH 0154/2126] wifi: update UHR to Draft_P802.11bn D1.5 Update various definitions and in particular NPCA parsing to D1.5. Link: https://patch.msgid.link/20260731140351.0798bb37908d.I13592341f7f53f7566f9eeb74f0a0b85e73c1fef@changeid Signed-off-by: Johannes Berg --- include/linux/ieee80211-eht.h | 18 ++++++- include/linux/ieee80211-uhr.h | 95 +++++++++++++++++++---------------- net/wireless/chan.c | 11 ++-- 3 files changed, 75 insertions(+), 49 deletions(-) diff --git a/include/linux/ieee80211-eht.h b/include/linux/ieee80211-eht.h index b62297a978e7..a699d108eee6 100644 --- a/include/linux/ieee80211-eht.h +++ b/include/linux/ieee80211-eht.h @@ -482,6 +482,7 @@ struct ieee80211_multi_link_elem { #define IEEE80211_MLC_BASIC_PRES_MLD_ID 0x0200 #define IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP 0x0400 #define IEEE80211_MLC_BASIC_PRES_ENH_CRIT_UPD 0x0800 +#define IEEE80211_MLC_BASIC_PRES_AGE_OF_BSS_LOAD 0x1000 #define IEEE80211_MED_SYNC_DELAY_DURATION 0x00ff #define IEEE80211_MED_SYNC_DELAY_SYNC_OFDM_ED_THRESH 0x0f00 @@ -550,6 +551,8 @@ struct ieee80211_mle_basic_common_info { } __packed; #define IEEE80211_MLC_PREQ_PRES_MLD_ID 0x0010 +#define IEEE80211_MLC_PREQ_PRES_MLD_MAC_ADDR 0x0020 +#define IEEE80211_MLC_PREQ_PRES_NEIGH_AP_MLD_MAC_ADDR 0x0040 struct ieee80211_mle_preq_common_info { u8 len; @@ -560,6 +563,7 @@ struct ieee80211_mle_preq_common_info { #define IEEE80211_MLC_RECONF_PRES_EML_CAPA 0x0020 #define IEEE80211_MLC_RECONF_PRES_MLD_CAPA_OP 0x0040 #define IEEE80211_MLC_RECONF_PRES_EXT_MLD_CAPA_OP 0x0080 +#define IEEE80211_MLC_RECONF_PRES_TARGET_AP_MLD_ADDR 0x0100 /* no fixed fields in RECONF */ @@ -766,7 +770,7 @@ static inline u16 ieee80211_mle_get_mld_capa_op(const u8 *data) #define IEEE80211_EHT_ML_EXT_MLD_CAPA_NSTR_UPDATE 0x0020 #define IEEE80211_EHT_ML_EXT_MLD_CAPA_EMLSR_ENA_ON_ONE_LINK 0x0040 #define IEEE80211_EHT_ML_EXT_MLD_CAPA_BTM_MLD_RECO_MULTI_AP 0x0080 -/* defined by UHR Draft P802.11bn_D1.3 Figure 9-1147 */ +/* defined by UHR Draft P802.11bn_D1.5 Figure 9-1168 */ #define IEEE80211_UHR_ML_EXT_MLD_CAPA_ML_PM 0x0100 /** @@ -928,11 +932,17 @@ static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len) common += 2; if (control & IEEE80211_MLC_BASIC_PRES_ENH_CRIT_UPD) common += 1; + if (control & IEEE80211_MLC_BASIC_PRES_AGE_OF_BSS_LOAD) + common += 1; break; case IEEE80211_ML_CONTROL_TYPE_PREQ: common += sizeof(struct ieee80211_mle_preq_common_info); if (control & IEEE80211_MLC_PREQ_PRES_MLD_ID) common += 1; + if (control & IEEE80211_MLC_PREQ_PRES_MLD_MAC_ADDR) + common += ETH_ALEN; + if (control & IEEE80211_MLC_PREQ_PRES_NEIGH_AP_MLD_MAC_ADDR) + common += ETH_ALEN; break; case IEEE80211_ML_CONTROL_TYPE_RECONF: common += 1; @@ -944,6 +954,8 @@ static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len) common += 2; if (control & IEEE80211_MLC_RECONF_PRES_EXT_MLD_CAPA_OP) common += 2; + if (control & IEEE80211_MLC_RECONF_PRES_TARGET_AP_MLD_ADDR) + common += ETH_ALEN; break; case IEEE80211_ML_CONTROL_TYPE_TDLS: common += sizeof(struct ieee80211_mle_tdls_common_info); @@ -1003,6 +1015,7 @@ enum ieee80211_mle_subelems { #define IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT 0x0800 #define IEEE80211_MLE_STA_CONTROL_ENH_CRIT_UPD_PRESENT 0x1000 #define IEEE80211_MLE_STA_CONTROL_AP_CONDUCTED_TX_PWR_PRESENT 0x2000 +#define IEEE80211_MLE_STA_CONTROL_AGE_OF_BSS_LOAD_PRESENT 0x4000 struct ieee80211_mle_per_sta_profile { __le16 control; @@ -1054,6 +1067,9 @@ static inline bool ieee80211_mle_basic_sta_prof_size_ok(const u8 *data, if (control & IEEE80211_MLE_STA_CONTROL_AP_CONDUCTED_TX_PWR_PRESENT) info_len += 1; + if (control & IEEE80211_MLE_STA_CONTROL_AGE_OF_BSS_LOAD_PRESENT) + info_len += 1; + return prof->sta_info_len >= info_len && fixed + prof->sta_info_len - 1 <= len; } diff --git a/include/linux/ieee80211-uhr.h b/include/linux/ieee80211-uhr.h index 398ce01fcdee..19e9260d0db8 100644 --- a/include/linux/ieee80211-uhr.h +++ b/include/linux/ieee80211-uhr.h @@ -17,32 +17,32 @@ #define IEEE80211_UHR_OPER_PARAMS_PEDCA_ENA 0x0004 #define IEEE80211_UHR_OPER_PARAMS_DBE_ENA 0x0008 #define IEEE80211_UHR_OPER_PARAMS_DBE_BW 0x0070 -#define IEEE80211_UHR_OPER_PARAMS_DUO_PRES 0x0080 -#define IEEE80211_UHR_OPER_PARAMS_DPS_PRES 0x0100 -#define IEEE80211_UHR_OPER_PARAMS_NPCA_PRES 0x0200 -#define IEEE80211_UHR_OPER_PARAMS_PEDCA_PRES 0x0400 -#define IEEE80211_UHR_OPER_PARAMS_DBE_PRES 0x0800 +#define IEEE80211_UHR_OPER_PARAMS_ELR_RX 0x0080 +#define IEEE80211_UHR_OPER_PARAMS_DUO_PRES 0x0100 +#define IEEE80211_UHR_OPER_PARAMS_DPS_PRES 0x0200 +#define IEEE80211_UHR_OPER_PARAMS_NPCA_PRES 0x0400 +#define IEEE80211_UHR_OPER_PARAMS_PEDCA_PRES 0x0800 +#define IEEE80211_UHR_OPER_PARAMS_DBE_PRES 0x1000 struct ieee80211_uhr_operation { __le16 params; - u8 basic_mcs_nss_set[4]; u8 variable[]; } __packed; -#define IEEE80211_UHR_NPCA_PARAMS_PRIMARY_CHAN_OFFS 0x0000000F -#define IEEE80211_UHR_NPCA_PARAMS_MIN_DUR_THRESH 0x000000F0 -#define IEEE80211_UHR_NPCA_PARAMS_SWITCH_DELAY 0x00003F00 -#define IEEE80211_UHR_NPCA_PARAMS_SWITCH_BACK_DELAY 0x000FC000 -#define IEEE80211_UHR_NPCA_PARAMS_INIT_QSRC 0x00300000 -#define IEEE80211_UHR_NPCA_PARAMS_MOPLEN 0x00400000 -#define IEEE80211_UHR_NPCA_PARAMS_DIS_SUBCH_BMAP_PRES 0x00800000 +#define IEEE80211_UHR_NPCA_PARAMS_PRIMARY_CHAN 0x000000FF +#define IEEE80211_UHR_NPCA_PARAMS_MIN_DUR_THRESH 0x00000F00 +#define IEEE80211_UHR_NPCA_PARAMS_SWITCH_DELAY 0x0003F000 +#define IEEE80211_UHR_NPCA_PARAMS_SWITCH_BACK_DELAY 0x00FC0000 +#define IEEE80211_UHR_NPCA_PARAMS_INIT_QSRC 0x03000000 +#define IEEE80211_UHR_NPCA_PARAMS_MOPLEN 0x04000000 +#define IEEE80211_UHR_NPCA_PARAMS_DIS_SUBCH_BMAP_PRES 0x08000000 /** * struct ieee80211_uhr_npca_info - npca operation information * * This structure is the "NPCA Operation Parameters field format" of "UHR - * Operation Element" fields as described in P802.11bn_D1.3 - * subclause 9.4.2.353. See Figure 9-aa4. + * Operation Element" fields as described in P802.11bn_D1.5 + * subclause 9.4.2.355.2, see Figure 9-aa6. * * Refer to IEEE80211_UHR_NPCA* * @params: @@ -97,7 +97,7 @@ struct ieee80211_uhr_npca_info { * struct ieee80211_uhr_dps_info - DPS operation information * * This structure is the "DPS Operation Parameter field" of "UHR - * Operation Element" fields as described in P802.11bn_D1.3 + * Operation Element" fields as described in P802.11bn_D1.5 * subclause 9.4.1.87. See Figure 9-207u. * * Refer to IEEE80211_UHR_DPS* @@ -211,8 +211,8 @@ static inline int ieee80211_uhr_dbe_bw_mhz(enum ieee80211_uhr_dbe_oper_bw bw) * struct ieee80211_uhr_dbe_info - DBE operation information * * This structure is the "DBE Operation Parameters field" of - * "UHR Operation Element" fields as described in P802.11bn_D1.3 - * subclause 9.4.2.353. See Figure 9-aa6. + * "UHR Operation Element" fields as described in P802.11bn_D1.5 + * subclause 9.4.2.355.4, see Figure 9-aa9. * * Refer to IEEE80211_UHR_DBE_OPER* * @params: @@ -234,25 +234,23 @@ struct ieee80211_uhr_dbe_info { __le16 dis_subch_bmap[]; } __packed; -#define IEEE80211_UHR_P_EDCA_ECWMIN 0x0F -#define IEEE80211_UHR_P_EDCA_ECWMAX 0xF0 -#define IEEE80211_UHR_P_EDCA_AIFSN 0x000F -#define IEEE80211_UHR_P_EDCA_CW_DS 0x0030 -#define IEEE80211_UHR_P_EDCA_PSRC_THRESHOLD 0x01C0 -#define IEEE80211_UHR_P_EDCA_QSRC_THRESHOLD 0x0600 +#define IEEE80211_UHR_P_EDCA_ECWMIN 0x0007 +#define IEEE80211_UHR_P_EDCA_ECWMAX 0x0038 +#define IEEE80211_UHR_P_EDCA_AIFSN 0x01C0 +#define IEEE80211_UHR_P_EDCA_CW_DS 0x0600 +#define IEEE80211_UHR_P_EDCA_PSRC_THRESHOLD 0x3800 +#define IEEE80211_UHR_P_EDCA_QSRC_THRESHOLD 0xC000 /** * struct ieee80211_uhr_p_edca_info - P-EDCA operation information * * This structure is the "P-EDCA Operation Parameters field" of - * "UHR Operation Element" fields as described in P802.11bn_D1.3 - * subclause 9.4.2.353. See Figure 9-aa5. + * "UHR Operation Element" fields as described in P802.11bn_D1.5 + * subclause 9.4.2.355.3, see Figure 9-aa8. * * Refer to IEEE80211_UHR_P_EDCA* - * @p_edca_ec: P-EDCA ECWmin and ECWmax. - * These fields indicate the CWmin and CWmax values used by a - * P-EDCA STA during P-EDCA contention. - * @params: AIFSN, CW DS, PSRC threshold, and QSRC threshold. + * @params: ECWmin, ECWmax, AIFSN, CW DS, PSRC threshold, and QSRC threshold. + * - CWmin/CWmax values used by a P-EDCA STA during P-EDCA contention. * - The AIFSN field indicates the AIFSN value used by a P-EDCA STA * during P-EDCA contention. * - The CW DS field indicates the value used for randomization of the @@ -266,7 +264,6 @@ struct ieee80211_uhr_dbe_info { * value 0 is reserved. */ struct ieee80211_uhr_p_edca_info { - u8 p_edca_ec; __le16 params; } __packed; @@ -302,7 +299,7 @@ static inline bool ieee80211_uhr_oper_size_ok(const u8 *data, u8 len) } } - /* P-EDCA Operation Parameters (fixed 3 bytes) */ + /* P-EDCA Operation Parameters */ if (oper->params & cpu_to_le16(IEEE80211_UHR_OPER_PARAMS_PEDCA_PRES)) { needed += sizeof(struct ieee80211_uhr_p_edca_info); if (len < needed) @@ -421,28 +418,42 @@ ieee80211_uhr_oper_dbe_info(const struct ieee80211_uhr_operation *oper) #define IEEE80211_UHR_MAC_CAP2_UHR_OM_PU_TO_LOW 0xC0 #define IEEE80211_UHR_MAC_CAP3_UHR_OM_PU_TO_HIGH 0x03 -#define IEEE80211_UHR_MAC_CAP3_PARAM_UPD_ADV_NOTIF_INTV 0x1C -#define IEEE80211_UHR_MAC_CAP3_UPD_IND_TIM_INTV_LOW 0xE0 +#define IEEE80211_UHR_MAC_CAP3_PARAM_UPD_ADV_NOTIF_INTV 0x7C +#define IEEE80211_UHR_MAC_CAP3_UPD_IND_TIM_INTV_LOW 0x80 -#define IEEE80211_UHR_MAC_CAP4_UPD_IND_TIM_INTV_HIGH 0x03 -#define IEEE80211_UHR_MAC_CAP4_BOUNDED_ESS 0x04 -#define IEEE80211_UHR_MAC_CAP4_BTM_ASSURANCE 0x08 -#define IEEE80211_UHR_MAC_CAP4_CO_BF_SUPP 0x10 +#define IEEE80211_UHR_MAC_CAP4_UPD_IND_TIM_INTV_HIGH 0x0F +#define IEEE80211_UHR_MAC_CAP4_BOUNDED_ESS 0x10 +#define IEEE80211_UHR_MAC_CAP4_BTM_ASSURANCE 0x20 +#define IEEE80211_UHR_MAC_CAP4_CO_BF_SUPP 0x40 +#define IEEE80211_UHR_MAC_CAP4_CO_SR_SUPP 0x80 + +#define IEEE80211_UHR_MAC_CAP5_MAPC_ENH_MSRMT_SUPP 0x01 #define IEEE80211_UHR_MAC_CAP_DBE_MAX_BW 0x07 #define IEEE80211_UHR_MAC_CAP_DBE_EHT_MCS_MAP_160_PRES 0x08 #define IEEE80211_UHR_MAC_CAP_DBE_EHT_MCS_MAP_320_PRES 0x10 +/* struct ieee80211_uhr_cap_dbe::bwcap[].cap */ +#define IEEE80211_UHR_MAC_CAP_DBE_CAP_NUM_SND_DIMS 0x07 +#define IEEE80211_UHR_MAC_CAP_DBE_CAP_NON_OFDMA_UL_MUMIMO 0x08 +#define IEEE80211_UHR_MAC_CAP_DBE_CAP_MU_BEAMFORMER 0x10 +#define IEEE80211_UHR_MAC_CAP_DBE_CAP_BEAMFORMEE_SS 0xe0 + struct ieee80211_uhr_cap_dbe { u8 cap; + u8 max_switch_time_period; + u8 mode_change_intvl; /* present 0, 1 or 2 times depending on _PRES bits */ - struct ieee80211_eht_mcs_nss_supp_bw eht_mcs_map[]; + struct { + struct ieee80211_eht_mcs_nss_supp_bw eht_mcs_map; + u8 cap; + } __packed bwcap[]; } __packed; /** * enum ieee80211_uhr_dbe_max_supported_bw - DBE Maximum Supported Bandwidth * - * As per spec P802.11bn_D1.3 "Table 9-bb5—Encoding of the DBE Maximum + * As per spec P802.11bn_D1.5 Table 9-bb8 "Encoding of the DBE Maximum * Supported Bandwidth field". * * @IEEE80211_UHR_DBE_MAX_BW_40: Indicates 40 MHz DBE max supported bw @@ -526,10 +537,10 @@ static inline bool ieee80211_uhr_capa_size_ok(const u8 *data, u8 len, dbe = (const void *)cap->variable; if (dbe->cap & IEEE80211_UHR_MAC_CAP_DBE_EHT_MCS_MAP_160_PRES) - needed += sizeof(dbe->eht_mcs_map[0]); + needed += sizeof(dbe->bwcap[0]); if (dbe->cap & IEEE80211_UHR_MAC_CAP_DBE_EHT_MCS_MAP_320_PRES) - needed += sizeof(dbe->eht_mcs_map[0]); + needed += sizeof(dbe->bwcap[0]); } return len >= needed; diff --git a/net/wireless/chan.c b/net/wireless/chan.c index 7f6af1790736..1071e823108b 100644 --- a/net/wireless/chan.c +++ b/net/wireless/chan.c @@ -568,8 +568,8 @@ int cfg80211_chandef_add_npca(struct wiphy *wiphy, const struct ieee80211_uhr_npca_info *npca) { struct cfg80211_chan_def new_chandef = *chandef; - u32 width, npca_freq; - u8 offs; + u32 npca_freq; + u8 chan; if (chandef->npca_chan || chandef->npca_punctured) return -EINVAL; @@ -589,11 +589,10 @@ int cfg80211_chandef_add_npca(struct wiphy *wiphy, return -EINVAL; } - offs = le32_get_bits(npca->params, - IEEE80211_UHR_NPCA_PARAMS_PRIMARY_CHAN_OFFS); + chan = le32_get_bits(npca->params, + IEEE80211_UHR_NPCA_PARAMS_PRIMARY_CHAN); - width = cfg80211_chandef_get_width(chandef); - npca_freq = chandef->center_freq1 - width / 2 + 10 + 20 * offs; + npca_freq = ieee80211_channel_to_frequency(chan, chandef->chan->band); new_chandef.npca_chan = ieee80211_get_channel(wiphy, npca_freq); if (!new_chandef.npca_chan) return -EINVAL; From d59b9bf7df49367e01b06e82dd0f6e7ad3be493c Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 2 Aug 2026 10:57:18 +0200 Subject: [PATCH 0155/2126] wifi: mac80211: fix unauthorised port check for encap offload The check in ieee80211_tx_dequeue() reads frame_control, addr1 and addr2 out of the skb, but for encapsulation offload that's just a random part of the ethernet addresses, so dropping depends on bits in the destination address. This is obviously wrong. Refactor the check and short-circuit for ethernet format frames, it only needs the port-control flag check since those are locally generated and not forwarded frames. Fixes: 50ff477a8639 ("mac80211: add 802.11 encapsulation offloading support") Link: https://patch.msgid.link/20260802105818.dd5da579813d.I51ed0121154bb652bebc97bb0597b1fae9ac978f@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 48 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 3a1e2c9e1565..ee792b77a8c6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -3877,6 +3877,38 @@ static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata, return true; } +static bool ieee80211_drop_unauth_port(struct ieee80211_tx_data *tx) +{ + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); + struct ieee80211_hdr *hdr; + + if (likely(test_sta_flag(tx->sta, WLAN_STA_AUTHORIZED))) + return false; + + if (info->flags & IEEE80211_TX_CTL_INJECTED) + return false; + + if (ieee80211_vif_is_mesh(&tx->sdata->vif) || + tx->sdata->vif.type == NL80211_IFTYPE_OCB) + return false; + + /* no need to check forwarding here */ + if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) + return !(info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO); + + hdr = (struct ieee80211_hdr *)tx->skb->data; + + if (!ieee80211_is_data_present(hdr->frame_control) || + is_multicast_ether_addr(hdr->addr1)) + return false; + + if ((info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) && + ieee80211_is_our_addr(tx->sdata, hdr->addr2, NULL)) + return false; + + return true; +} + struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, struct ieee80211_txq *txq) { @@ -3943,20 +3975,8 @@ begin: if (txq->sta) { tx.sta = container_of(txq->sta, struct sta_info, sta); - /* - * Drop unicast frames to unauthorised stations unless they are - * injected frames or EAPOL frames from the local station. - */ - if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) && - ieee80211_is_data_present(hdr->frame_control) && - !ieee80211_vif_is_mesh(&tx.sdata->vif) && - tx.sdata->vif.type != NL80211_IFTYPE_OCB && - !is_multicast_ether_addr(hdr->addr1) && - !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) && - (!(info->control.flags & - IEEE80211_TX_CTRL_PORT_CTRL_PROTO) || - !ieee80211_is_our_addr(tx.sdata, hdr->addr2, - NULL)))) { + + if (unlikely(ieee80211_drop_unauth_port(&tx))) { I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); ieee80211_free_txskb(&local->hw, skb); goto begin; From 0e80db08668b560b3522849cb705623148bcd4b5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 2 Aug 2026 10:57:19 +0200 Subject: [PATCH 0156/2126] wifi: mac80211: fix key selection for encap offload frames ieee80211_tx_h_select_key() assumes the frame is in 802.11 format for picking the key, at least when there's no pairwise TK for the STA to transmit with. For unicast this is likely not relevant because if there's no pairwise TK for the STA there's probably not going to be any other key either. But multicast encapsulation offload frames have no STA, so it looks at the ethernet header as if it was 802.11. This may not matter very much since multicast encapsulation offload is likely to ignore the key selection, but it's still wrong. Create a separate selection function that doesn't (need to) look at the frame header - it's data anyway, so either unicast to a station (with sta pointer) or multicast. For MLO, the driver has to duplicate the frame and select the key anyway, so just skip it in that case entirely. Fixes: 50ff477a8639 ("mac80211: add 802.11 encapsulation offloading support") Link: https://patch.msgid.link/20260802105818.0feb7ad61047.Ia506ca211176a3c466bc60e4cc3e506df34a4a67@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index ee792b77a8c6..a94a5859fbdc 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -589,6 +589,34 @@ ieee80211_select_link_key(struct ieee80211_tx_data *tx) return NULL; } +/* + * An 802.3 frame is always a data frame, so there are no 802.11 addresses to + * look at: with a station the pairwise key is all that can apply, without one + * the frame is group addressed. On an MLD the driver has to pick the group key + * itself, as the same frame goes out on several links that each have their own. + */ +static ieee80211_tx_result +ieee80211_select_key_8023(struct ieee80211_tx_data *tx) +{ + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); + + if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) + return TX_CONTINUE; + + if (tx->sta) { + tx->key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]); + if (!tx->key) + tx->key = rcu_dereference(tx->sdata->default_unicast_key); + } else if (!ieee80211_vif_is_mld(&tx->sdata->vif)) { + tx->key = rcu_dereference(tx->sdata->deflink.default_multicast_key); + } + + if (tx->key && tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) + info->control.hw_key = &tx->key->conf; + + return TX_CONTINUE; +} + static ieee80211_tx_result debug_noinline ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) { @@ -596,6 +624,9 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; + if (info->control.flags & IEEE80211_TX_CTL_HW_80211_ENCAP) + return ieee80211_select_key_8023(tx); + if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) { tx->key = NULL; return TX_CONTINUE; @@ -612,12 +643,6 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) else tx->key = NULL; - if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { - if (tx->key && tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) - info->control.hw_key = &tx->key->conf; - return TX_CONTINUE; - } - if (tx->key) { bool skip_hw = false; From a48daf145fed445d41ef422573411500785415c8 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 2 Aug 2026 10:57:20 +0200 Subject: [PATCH 0157/2126] wifi: mac80211: don't send encap offload frames unencrypted For 802.11 frames, ieee80211_tx_h_select_key() drops a data frame that ended up without a key if the station requires encryption, so that traffic can never leak out unprotected. Encapsulation offload erroneously didn't get this code path. Fix that. Fixes: 50ff477a8639 ("mac80211: add 802.11 encapsulation offloading support") Link: https://patch.msgid.link/20260802085818.1336616-7-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index a94a5859fbdc..c6a4a30d95cc 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -607,6 +607,9 @@ ieee80211_select_key_8023(struct ieee80211_tx_data *tx) tx->key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]); if (!tx->key) tx->key = rcu_dereference(tx->sdata->default_unicast_key); + + if (!tx->key && test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) + return TX_DROP; } else if (!ieee80211_vif_is_mld(&tx->sdata->vif)) { tx->key = rcu_dereference(tx->sdata->deflink.default_multicast_key); } From c8ddbe1e8c43f6d008591c50f8be8de39cdce267 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 2 Aug 2026 10:57:21 +0200 Subject: [PATCH 0158/2126] wifi: mac80211: drop encap offload frames with a tainted key When a key is tainted, which happens in some WoWLAN and extended key ID scenarios, frames that would use it should be dropped. Fix that for encapsulation offload frames. Fixes: 50ff477a8639 ("mac80211: add 802.11 encapsulation offloading support") Link: https://patch.msgid.link/20260802105818.870b6ef31374.Ib87175b55b9fd94c16ba6d9cd816b7a09248df87@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index c6a4a30d95cc..8bfc99958927 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -614,7 +614,13 @@ ieee80211_select_key_8023(struct ieee80211_tx_data *tx) tx->key = rcu_dereference(tx->sdata->deflink.default_multicast_key); } - if (tx->key && tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) + if (!tx->key) + return TX_CONTINUE; + + if (unlikely(tx->key->flags & KEY_FLAG_TAINTED)) + return TX_DROP; + + if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) info->control.hw_key = &tx->key->conf; return TX_CONTINUE; From 7056e1b5ff5abf5a89523ca8357ec669784c2fa1 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 2 Aug 2026 23:08:01 +0200 Subject: [PATCH 0159/2126] wifi: nl80211: don't export nl80211_mlo_reconf_add_done() This function is only used and only usable by cfg80211 itself, so don't export it. Link: https://patch.msgid.link/20260802210800.1733352-2-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 44f2bad08670..8f022bb1413c 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -21523,7 +21523,6 @@ void nl80211_mlo_reconf_add_done(struct net_device *dev, nl80211_send_mlme_event(rdev, dev, &event, GFP_KERNEL); } -EXPORT_SYMBOL(nl80211_mlo_reconf_add_done); void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, struct net_device *netdev, const u8 *bssid, From 0b25b927ce6b3cddfc0f2eb3bdf7ea7ae4e5bff3 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 2 Aug 2026 23:18:20 +0200 Subject: [PATCH 0160/2126] wifi: mac80211: remove ieee80211_sta_ps_transition() return value Nothing cares, so no point calculating it. Also simplify the "no need to do anything" check and fix some docs that should refer to this function instead. Link: https://patch.msgid.link/20260802211819.1738465-2-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- include/net/mac80211.h | 18 +++++------------- net/mac80211/rx.c | 8 +++----- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 9d1fac6e8082..638b8aa5214d 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -2919,8 +2919,8 @@ struct ieee80211_txq { * autonomously manages the PS status of connected stations. When * this flag is set mac80211 will not trigger PS mode for connected * stations based on the PM bit of incoming frames. - * Use ieee80211_start_ps()/ieee8021_end_ps() to manually configure - * the PS mode of connected stations. + * Use ieee80211_sta_ps_transition() to manually toggle the PS mode + * of connected stations. * * @IEEE80211_HW_TX_AMPDU_SETUP_IN_HW: The device handles TX A-MPDU session * setup strictly in HW. mac80211 should not attempt to do this in @@ -5499,10 +5499,8 @@ static inline void ieee80211_rx_ni(struct ieee80211_hw *hw, * * @sta: currently connected sta * @start: start or stop PS - * - * Return: 0 on success. -EINVAL when the requested PS mode is already set. */ -int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start); +void ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start); /** * ieee80211_sta_ps_transition_ni - PS transition for connected sta @@ -5514,19 +5512,13 @@ int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start); * * @sta: currently connected sta * @start: start or stop PS - * - * Return: Like ieee80211_sta_ps_transition(). */ -static inline int ieee80211_sta_ps_transition_ni(struct ieee80211_sta *sta, +static inline void ieee80211_sta_ps_transition_ni(struct ieee80211_sta *sta, bool start) { - int ret; - local_bh_disable(); - ret = ieee80211_sta_ps_transition(sta, start); + ieee80211_sta_ps_transition(sta, start); local_bh_enable(); - - return ret; } /** diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 5e26be8e27d8..40ed03a775ba 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -1744,7 +1744,7 @@ static void sta_ps_end(struct sta_info *sta) ieee80211_sta_ps_deliver_wakeup(sta); } -int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start) +void ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start) { struct sta_info *sta = container_of(pubsta, struct sta_info, sta); bool in_ps; @@ -1753,15 +1753,13 @@ int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start) /* Don't let the same PS state be set twice */ in_ps = test_sta_flag(sta, WLAN_STA_PS_STA); - if ((start && in_ps) || (!start && !in_ps)) - return -EINVAL; + if (start == in_ps) + return; if (start) sta_ps_start(sta); else sta_ps_end(sta); - - return 0; } EXPORT_SYMBOL(ieee80211_sta_ps_transition); From 8d1c320f615dac61240aee9c8a1fc6436ca0ca34 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 13:52:48 +0200 Subject: [PATCH 0161/2126] wifi: mac80211: make ieee80211_is_tx_data() internal This function isn't used by any driver, and we may want to change it in the future. Don't expose it. Drivers may still do the same determination based on the flags, but if we'd ever change the encapsulation internally etc. (which I'm considering) then the use in mac80211 may need to change, or the function itself. Link: https://patch.msgid.link/20260803135248.cd23ccac65d7.I1c238c6abe39f5a1ff1b11d8556599d01dd03ff0@changeid Signed-off-by: Johannes Berg --- include/net/mac80211.h | 19 ------------------- net/mac80211/ieee80211_i.h | 9 +++++++++ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 638b8aa5214d..f147bc019e7b 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -8050,25 +8050,6 @@ void ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif, u64 color_bitmap, u8 link_id); -/** - * ieee80211_is_tx_data - check if frame is a data frame - * - * The function is used to check if a frame is a data frame. Frames with - * hardware encapsulation enabled are data frames. - * - * @skb: the frame to be transmitted. - * - * Return: %true if @skb is a data frame, %false otherwise - */ -static inline bool ieee80211_is_tx_data(struct sk_buff *skb) -{ - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - struct ieee80211_hdr *hdr = (void *) skb->data; - - return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP || - ieee80211_is_data(hdr->frame_control); -} - /** * ieee80211_set_active_links - set active links in client mode * @vif: interface to set active links on diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index d06cb8e7dfb3..04954a963742 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -191,6 +191,15 @@ struct ieee80211_tx_data { unsigned int flags; }; +static inline bool ieee80211_is_tx_data(struct sk_buff *skb) +{ + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); + struct ieee80211_hdr *hdr = (void *)skb->data; + + return info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP || + ieee80211_is_data(hdr->frame_control); +} + /** * enum ieee80211_packet_rx_flags - packet RX flags * @IEEE80211_RX_AMSDU: a-MSDU packet From e035900ffe9e8978f7c0d7b61811b6b578751697 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:37 +0200 Subject: [PATCH 0162/2126] wifi: mac80211: fix IEEE80211_TX_CTL_REQ_TX_STATUS mixup In ieee80211_build_hdr(), IEEE80211_TX_CTL_REQ_TX_STATUS is checked in ctrl_flags, which is wrong - IEEE80211_TX_CTL_REQ_TX_STATUS is in info->flags, so the check is for IEEE80211_TX_CTRL_PORT_CTRL_PROTO instead. This works out OK because the only place setting _that_ at a point before this gets called is in fact ieee80211_tx_control_port() which was intended here. This is actually needed for correctness, if jt were checking info->flags instead, TDLS would fill/leak the status frames created here. However, we can just fix it by using the cookie instead, that'll be set for PREAUTH frames via ieee80211_tx_control_port() as well, and no other frames. Additionally, the code also erroneously set it, but that just caused preauth frames to get it set, since storing the ACK SKB will also set the correct flag. Drop this assignment entirely. Fixes: a7528198add8 ("mac80211: support control port TX status reporting") Link: https://patch.msgid.link/20260803141309.292711-10-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 8bfc99958927..5891e1a8d71c 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2979,8 +2979,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, } if (unlikely(!multicast && - (sk_requests_wifi_status(skb->sk) || - ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS))) + (sk_requests_wifi_status(skb->sk) || cookie))) info_id = ieee80211_store_ack_skb(local, skb, &info_flags, cookie); @@ -6608,9 +6607,6 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, if (unencrypted) flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; - if (cookie) - ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; - flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX; skb = dev_alloc_skb(local->hw.extra_tx_headroom + From d5a014204a3bfaa7538205bdd8a78cfb7628e198 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:38 +0200 Subject: [PATCH 0163/2126] wifi: mac80211: tx: simplify control port frame transmission ieee80211_tx_control_port() already does most of the necessary work, much of which is repeated by __ieee80211_subif_start_xmit(). Most work in the latter function is completely unnecessary since these are special frames we built directly here (long enough, etc.) Call ieee80211_build_hdr() and ieee80211_xmit() directly instead. It also means some errors can now be reported to userspace rather than frames silently getting dropped, but that's a good thing. Link: https://patch.msgid.link/20260803141309.292711-11-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 5891e1a8d71c..c3337015c7b1 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -6650,9 +6650,6 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, skb_reset_network_header(skb); skb_reset_mac_header(skb); - if (local->hw.queues < IEEE80211_NUM_ACS) - goto start_xmit; - /* update QoS header to prioritize control port frames if possible, * prioritization also happens for control port frames send over * AF_PACKET @@ -6665,24 +6662,31 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, return err; } - if (!IS_ERR(sta)) { - u16 queue = ieee80211_select_queue(sdata, sta, skb); + if (IS_ERR(sta)) + sta = NULL; - skb_set_queue_mapping(skb, queue); + skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb)); - /* - * for MLO STA, the SA should be the AP MLD address, but - * the link ID has been selected already - */ - if (sta && sta->sta.mlo) - memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); + /* + * for MLO STA, the SA should be the AP MLD address, but + * the link ID has been selected already + */ + if (sta && sta->sta.mlo) + memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); + + skb = ieee80211_build_hdr(sdata, skb, flags, sta, ctrl_flags, cookie); + if (IS_ERR(skb)) { + rcu_read_unlock(); + return PTR_ERR(skb); } - rcu_read_unlock(); -start_xmit: + dev_sw_netstats_tx_add(dev, 1, skb->len); + ieee80211_tpt_led_trig_tx(local, skb->len); + local_bh_disable(); - __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie); + ieee80211_xmit(sdata, sta, skb); local_bh_enable(); + rcu_read_unlock(); return 0; } From ae29625022137547a7378bd2b4aba8d158a1410c Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:39 +0200 Subject: [PATCH 0164/2126] wifi: mac80211: remove cookie from __ieee80211_subif_start_xmit() This argument is now always zero, so no longer used. Remove it. Link: https://patch.msgid.link/20260803141309.292711-12-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 3 +-- net/mac80211/tdls.c | 2 +- net/mac80211/tx.c | 21 ++++++++------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 04954a963742..259d3735c792 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2242,8 +2242,7 @@ netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb, void __ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev, u32 info_flags, - u32 ctrl_flags, - u64 cookie); + u32 ctrl_flags); struct sk_buff * ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, u32 info_flags); diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c index dc2f662fe4c4..4f4cae9fd274 100644 --- a/net/mac80211/tdls.c +++ b/net/mac80211/tdls.c @@ -1121,7 +1121,7 @@ ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev, /* disable bottom halves when entering the Tx path */ local_bh_disable(); __ieee80211_subif_start_xmit(skb, dev, flags, - IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, 0); + IEEE80211_TX_CTRL_MLO_LINK_UNSPEC); local_bh_enable(); return ret; diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index c3337015c7b1..8834e823344d 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -4421,8 +4421,7 @@ EXPORT_SYMBOL(ieee80211_txq_schedule_start); void __ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev, u32 info_flags, - u32 ctrl_flags, - u64 cookie) + u32 ctrl_flags) { struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_local *local = sdata->local; @@ -4480,7 +4479,7 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP; skb = ieee80211_build_hdr(sdata, skb, info_flags, - sta, ctrl_flags, cookie); + sta, ctrl_flags, 0); if (IS_ERR(skb)) { kfree_skb_list(next); goto out; @@ -4617,7 +4616,7 @@ static void ieee80211_mlo_multicast_tx_one(struct ieee80211_sub_if_data *sdata, return; ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK); - __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags, 0); + __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags); } static void ieee80211_mlo_multicast_tx(struct net_device *dev, @@ -4632,7 +4631,7 @@ static void ieee80211_mlo_multicast_tx(struct net_device *dev, ctrl_flags |= u32_encode_bits(__ffs(links), IEEE80211_TX_CTRL_MLO_LINK); - __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags, 0); + __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags); return; } @@ -4673,8 +4672,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, ieee80211_convert_to_unicast(skb, dev, &queue); while ((skb = __skb_dequeue(&queue))) __ieee80211_subif_start_xmit(skb, dev, 0, - IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, - 0); + IEEE80211_TX_CTRL_MLO_LINK_UNSPEC); } else if (ieee80211_vif_is_mld(&sdata->vif) && ((sdata->vif.type == NL80211_IFTYPE_AP && !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX)) || @@ -4684,8 +4682,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, } else { normal: __ieee80211_subif_start_xmit(skb, dev, 0, - IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, - 0); + IEEE80211_TX_CTRL_MLO_LINK_UNSPEC); } return NETDEV_TX_OK; @@ -4783,8 +4780,7 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { /* fall back to non-offload slow path */ __ieee80211_subif_start_xmit(skb, dev, 0, - IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, - 0); + IEEE80211_TX_CTRL_MLO_LINK_UNSPEC); return; } @@ -6714,8 +6710,7 @@ int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev, local_bh_disable(); __ieee80211_subif_start_xmit(skb, skb->dev, 0, - IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP, - 0); + IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP); local_bh_enable(); return 0; From 1ebbdad2b7986fc1f0af85858a9a78bdc94ee5da Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:40 +0200 Subject: [PATCH 0165/2126] wifi: mac80211: unshare the skb before building the header ieee80211_build_hdr() unshares the skb halfway through, after it has already looked at it but before it writes anything. That's not a problem, but complicates the callers and requires passing the flags to the function, etc. Move the unsharing to the only caller that matters, the new one from the previous patch has a fresh SKB and doesn't need it and the TDLS callers via ieee80211_tdls_build_mgmt_packet_data() are also fresh SKBs. Link: https://patch.msgid.link/20260803141309.292711-13-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 8834e823344d..8bbefe6c8036 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2671,9 +2671,8 @@ static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) * the appropriate IEEE 802.11 header based on which interface the packet is * being transmitted on. * - * Note that this function also takes care of the TX status request and - * potential unsharing of the SKB - this needs to be interleaved with the - * header building. + * Note that this function also takes care of the TX status request. The skb + * must not be shared. * * The function requires the read-side RCU lock held * @@ -2983,15 +2982,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, info_id = ieee80211_store_ack_skb(local, skb, &info_flags, cookie); - /* - * If the skb is shared we need to obtain our own copy. - */ - skb = skb_share_check(skb, GFP_ATOMIC); - if (unlikely(!skb)) { - ret = -ENOMEM; - goto free; - } - hdr.frame_control = fc; hdr.duration_id = 0; hdr.seq_ctrl = 0; @@ -4478,6 +4468,12 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, if (skb->protocol == sdata->control_port_protocol) ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP; + skb = skb_share_check(skb, GFP_ATOMIC); + if (unlikely(!skb)) { + kfree_skb_list(next); + goto out; + } + skb = ieee80211_build_hdr(sdata, skb, info_flags, sta, ctrl_flags, 0); if (IS_ERR(skb)) { From 78b843974fb83ba5a64f5cd0dad434458c52b717 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:41 +0200 Subject: [PATCH 0166/2126] wifi: mac80211: report multicast transmission from lookup_ra_sta() ieee80211_lookup_ra_sta() returns ERR_PTR(-ENOENT) both when the 802.11 frame will be is group addressed and when it's going to an unknown station. Keep reporting an ERR_PTR() for group addressed but set to NULL for individually addressed frames so the callers can use it to distinguish later. This is already explicitly the case for all interface types except mesh, and callers already tolerate (but don't distinguish) both cases. Also change the ieee80211_lookup_ra_sta() to be static. Link: https://patch.msgid.link/20260803141309.292711-14-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 5 ----- net/mac80211/tx.c | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 259d3735c792..53b0b08d3459 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2479,11 +2479,6 @@ static inline bool ieee80211_require_encrypted_assoc(__le16 fc, return sta && sta->sta.epp_peer && ieee80211_is_assoc(fc); } -/* sta_out needs to be checked for ERR_PTR() before using */ -int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, - struct sta_info **sta_out); - static inline void ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, int tid, diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 8bbefe6c8036..33391a7824b7 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2538,9 +2538,16 @@ static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb) skb->data[14] == WLAN_TDLS_SNAP_RFTYPE; } -int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, - struct sta_info **sta_out) +/* + * Returns an error if the frame should be dropped, otherwise + * the *sta_out pointer is filled: + * - valid sta pointer: frame goes to that station + * - NULL: frame will be unicast to a yet unknown station + * - ERR_PTR(-ENOENT): frame will be group addressed + */ +static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, + struct sk_buff *skb, + struct sta_info **sta_out) { struct sta_info *sta; @@ -2565,6 +2572,10 @@ int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, break; #ifdef CONFIG_MAC80211_MESH case NL80211_IFTYPE_MESH_POINT: + if (is_multicast_ether_addr(skb->data)) { + *sta_out = ERR_PTR(-ENOENT); + return 0; + } /* determined much later */ *sta_out = NULL; return 0; @@ -2607,7 +2618,7 @@ int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, return -EINVAL; } - *sta_out = sta ?: ERR_PTR(-ENOENT); + *sta_out = sta; return 0; } From 8516aa4f05b2680c7d66bc766207460ac0f5de27 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:42 +0200 Subject: [PATCH 0167/2126] wifi: mac80211: set flags/ctrl_flags before ieee80211_build_hdr() ieee80211_build_hdr() takes the info and control flags to use as arguments, but that leads to some messy code and missed cleanup. Fill them in the SKB before calling ieee80211_build_hdr(). Link: https://patch.msgid.link/20260803141309.292711-15-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 60 +++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 33391a7824b7..8526c6fa49b8 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2673,9 +2673,7 @@ static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) * ieee80211_build_hdr - build 802.11 header in the given frame * @sdata: virtual interface to build the header for * @skb: the skb to build the header in - * @info_flags: skb flags to set * @sta: the station pointer - * @ctrl_flags: info control flags to set * @cookie: cookie pointer to fill (if not %NULL) * * This function takes the skb with 802.3 header and reformats the header to @@ -2683,19 +2681,20 @@ static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) * being transmitted on. * * Note that this function also takes care of the TX status request. The skb - * must not be shared. + * must not be shared, and its TX info must already be initialised - this + * function only fills in what it determines itself. * * The function requires the read-side RCU lock held * * Returns: the (possibly reallocated) skb or an ERR_PTR() code */ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, u32 info_flags, - struct sta_info *sta, u32 ctrl_flags, + struct sk_buff *skb, + struct sta_info *sta, u64 cookie) { + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); struct ieee80211_local *local = sdata->local; - struct ieee80211_tx_info *info; int head_need; u16 ethertype, hdrlen, meshhdrlen = 0; __le16 fc; @@ -2711,14 +2710,15 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, struct ieee80211_chanctx_conf *chanctx_conf = NULL; enum nl80211_band band; int ret; - u8 link_id = u32_get_bits(ctrl_flags, IEEE80211_TX_CTRL_MLO_LINK); + u8 link_id = u32_get_bits(info->control.flags, + IEEE80211_TX_CTRL_MLO_LINK); if (IS_ERR(sta)) sta = NULL; #ifdef CONFIG_MAC80211_DEBUGFS if (local->force_tx_status) - info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; + info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; #endif /* convert Ethernet header to proper 802.11 header (based on @@ -2859,7 +2859,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, /* For injected frames, fill RA right away as nexthop lookup * will be skipped. */ - if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) && + if ((info->control.flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) && is_zero_ether_addr(hdr.addr1)) memcpy(hdr.addr1, skb->data, ETH_ALEN); break; @@ -2990,7 +2990,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, if (unlikely(!multicast && (sk_requests_wifi_status(skb->sk) || cookie))) - info_id = ieee80211_store_ack_skb(local, skb, &info_flags, + info_id = ieee80211_store_ack_skb(local, skb, &info->flags, cookie); hdr.frame_control = fc; @@ -3061,10 +3061,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, skb_reset_mac_header(skb); - info = IEEE80211_SKB_CB(skb); - memset(info, 0, sizeof(*info)); - - info->flags = info_flags; if (info_id) { info->status_data = info_id; info->status_data_idr = 1; @@ -3072,18 +3068,18 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, info->band = band; if (likely(!cookie)) { - ctrl_flags |= u32_encode_bits(link_id, - IEEE80211_TX_CTRL_MLO_LINK); + info->control.flags |= + u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK); } else { unsigned int pre_conf_link_id; /* - * ctrl_flags already have been set by + * The link ID already has been set by * ieee80211_tx_control_port(), here * we just sanity check that */ - pre_conf_link_id = u32_get_bits(ctrl_flags, + pre_conf_link_id = u32_get_bits(info->control.flags, IEEE80211_TX_CTRL_MLO_LINK); if (pre_conf_link_id != link_id && @@ -3098,8 +3094,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, } } - info->control.flags = ctrl_flags; - return skb; free: if (info_id) @@ -4426,6 +4420,7 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, { struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_local *local = sdata->local; + struct ieee80211_tx_info *info; struct sta_info *sta; struct sk_buff *next; int len = skb->len; @@ -4485,8 +4480,12 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, goto out; } - skb = ieee80211_build_hdr(sdata, skb, info_flags, - sta, ctrl_flags, 0); + info = IEEE80211_SKB_CB(skb); + memset(info, 0, sizeof(*info)); + info->flags = info_flags; + info->control.flags = ctrl_flags; + + skb = ieee80211_build_hdr(sdata, skb, sta, 0); if (IS_ERR(skb)) { kfree_skb_list(next); goto out; @@ -4955,6 +4954,7 @@ ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata, .local = sdata->local, .sdata = sdata, }; + struct ieee80211_tx_info *info; struct sta_info *sta; rcu_read_lock(); @@ -4965,8 +4965,12 @@ ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata, goto out; } - skb = ieee80211_build_hdr(sdata, skb, info_flags, sta, - IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, 0); + info = IEEE80211_SKB_CB(skb); + memset(info, 0, sizeof(*info)); + info->flags = info_flags; + info->control.flags = IEEE80211_TX_CTRL_MLO_LINK_UNSPEC; + + skb = ieee80211_build_hdr(sdata, skb, sta, 0); if (IS_ERR(skb)) goto out; @@ -6586,6 +6590,7 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, { struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_local *local = sdata->local; + struct ieee80211_tx_info *info; struct sta_info *sta; struct sk_buff *skb; struct ethhdr *ehdr; @@ -6677,7 +6682,12 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, if (sta && sta->sta.mlo) memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); - skb = ieee80211_build_hdr(sdata, skb, flags, sta, ctrl_flags, cookie); + info = IEEE80211_SKB_CB(skb); + memset(info, 0, sizeof(*info)); + info->flags = flags; + info->control.flags = ctrl_flags; + + skb = ieee80211_build_hdr(sdata, skb, sta, cookie); if (IS_ERR(skb)) { rcu_read_unlock(); return PTR_ERR(skb); From a64a20fb270f244a25c16c184c015b104278a06f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 3 Aug 2026 16:08:43 +0200 Subject: [PATCH 0168/2126] wifi: mac80211: store the ack skb before building the header The ack skb has to be stored while the frame is still in 802.3 format, since that is what is reported back to userspace. It's currently done in ieee80211_build_hdr(), but that complicates it a bit. Thanks the the previous ieee80211_lookup_ra_sta() change, it's now known whether or not the frame will be group addressed on the air, which is needed for this condition. Also simplify callers of ieee80211_store_ack_skb() by filling the TX info directly and fix the free in ieee80211_build_hdr() to use ieee80211_free_txskb(), reporting the drop to userspace rather than being quiet about it. This also lets use validate the link ID for control port TX in that code itself, rather than interleaving it into build_hdr(). Link: https://patch.msgid.link/20260803141309.292711-16-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 116 ++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 80 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 8526c6fa49b8..7d34b160fddd 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2622,13 +2622,11 @@ static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, return 0; } -static u16 ieee80211_store_ack_skb(struct ieee80211_local *local, - struct sk_buff *skb, - u32 *info_flags, - u64 cookie) +static void ieee80211_store_ack_skb(struct ieee80211_local *local, + struct sk_buff *skb, u64 cookie) { + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); struct sk_buff *ack_skb; - u16 info_id = 0; if (skb->sk) ack_skb = skb_clone_sk(skb); @@ -2645,28 +2643,15 @@ static u16 ieee80211_store_ack_skb(struct ieee80211_local *local, spin_unlock_irqrestore(&local->ack_status_lock, flags); if (id >= 0) { - info_id = id; - *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; + info->status_data = id; + info->status_data_idr = 1; + info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; if (cookie) IEEE80211_SKB_CB(ack_skb)->ack.cookie = cookie; } else { kfree_skb(ack_skb); } } - - return info_id; -} - -static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) -{ - struct sk_buff *ack_skb; - unsigned long flags; - - spin_lock_irqsave(&local->ack_status_lock, flags); - ack_skb = idr_remove(&local->ack_status_frames, info_id); - spin_unlock_irqrestore(&local->ack_status_lock, flags); - - kfree_skb(ack_skb); } /** @@ -2674,7 +2659,6 @@ static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) * @sdata: virtual interface to build the header for * @skb: the skb to build the header in * @sta: the station pointer - * @cookie: cookie pointer to fill (if not %NULL) * * This function takes the skb with 802.3 header and reformats the header to * the appropriate IEEE 802.11 header based on which interface the packet is @@ -2690,8 +2674,7 @@ static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) */ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, - struct sta_info *sta, - u64 cookie) + struct sta_info *sta) { struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); struct ieee80211_local *local = sdata->local; @@ -2706,7 +2689,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, bool wme_sta = false, authorized = false; bool tdls_peer; bool multicast; - u16 info_id = 0; struct ieee80211_chanctx_conf *chanctx_conf = NULL; enum nl80211_band band; int ret; @@ -2988,11 +2970,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, goto free; } - if (unlikely(!multicast && - (sk_requests_wifi_status(skb->sk) || cookie))) - info_id = ieee80211_store_ack_skb(local, skb, &info->flags, - cookie); - hdr.frame_control = fc; hdr.duration_id = 0; hdr.seq_ctrl = 0; @@ -3031,8 +3008,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, head_need += local->tx_headroom; head_need = max_t(int, 0, head_need); if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) { - ieee80211_free_txskb(&local->hw, skb); - skb = NULL; ret = -ENOMEM; goto free; } @@ -3061,44 +3036,14 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, skb_reset_mac_header(skb); - if (info_id) { - info->status_data = info_id; - info->status_data_idr = 1; - } info->band = band; - if (likely(!cookie)) { - info->control.flags |= - u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK); - } else { - unsigned int pre_conf_link_id; - - /* - * The link ID already has been set by - * ieee80211_tx_control_port(), here - * we just sanity check that - */ - - pre_conf_link_id = u32_get_bits(info->control.flags, - IEEE80211_TX_CTRL_MLO_LINK); - - if (pre_conf_link_id != link_id && - link_id != IEEE80211_LINK_UNSPECIFIED) { -#ifdef CONFIG_MAC80211_VERBOSE_DEBUG - net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n", - sdata->name, hdr.addr1, - pre_conf_link_id, link_id); -#endif - ret = -EINVAL; - goto free; - } - } - + info->control.flags = + u32_replace_bits(info->control.flags, link_id, + IEEE80211_TX_CTRL_MLO_LINK); return skb; free: - if (info_id) - ieee80211_remove_ack_skb(local, info_id); - kfree_skb(skb); + ieee80211_free_txskb(&local->hw, skb); return ERR_PTR(ret); } @@ -4423,6 +4368,7 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, struct ieee80211_tx_info *info; struct sta_info *sta; struct sk_buff *next; + bool group_addressed; int len = skb->len; if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) { @@ -4442,6 +4388,7 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) goto out_free; + group_addressed = IS_ERR(sta); if (IS_ERR(sta)) sta = NULL; @@ -4485,7 +4432,11 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, info->flags = info_flags; info->control.flags = ctrl_flags; - skb = ieee80211_build_hdr(sdata, skb, sta, 0); + if (unlikely(!group_addressed && + sk_requests_wifi_status(skb->sk))) + ieee80211_store_ack_skb(local, skb, 0); + + skb = ieee80211_build_hdr(sdata, skb, sta); if (IS_ERR(skb)) { kfree_skb_list(next); goto out; @@ -4820,12 +4771,8 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info)); } - if (unlikely(sk_requests_wifi_status(skb->sk))) { - info->status_data = ieee80211_store_ack_skb(local, skb, - &info->flags, 0); - if (info->status_data) - info->status_data_idr = 1; - } + if (unlikely(sk_requests_wifi_status(skb->sk))) + ieee80211_store_ack_skb(local, skb, 0); dev_sw_netstats_tx_add(dev, skbs, len); @@ -4970,7 +4917,7 @@ ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata, info->flags = info_flags; info->control.flags = IEEE80211_TX_CTRL_MLO_LINK_UNSPEC; - skb = ieee80211_build_hdr(sdata, skb, sta, 0); + skb = ieee80211_build_hdr(sdata, skb, sta); if (IS_ERR(skb)) goto out; @@ -6591,6 +6538,7 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_local *local = sdata->local; struct ieee80211_tx_info *info; + bool group_addressed; struct sta_info *sta; struct sk_buff *skb; struct ethhdr *ehdr; @@ -6631,15 +6579,11 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, /* we may override the SA for MLO STA later */ if (link_id < 0) { - ctrl_flags |= u32_encode_bits(IEEE80211_LINK_UNSPECIFIED, - IEEE80211_TX_CTRL_MLO_LINK); + link_id = IEEE80211_LINK_UNSPECIFIED; memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); } else { struct ieee80211_bss_conf *link_conf; - ctrl_flags |= u32_encode_bits(link_id, - IEEE80211_TX_CTRL_MLO_LINK); - rcu_read_lock(); link_conf = rcu_dereference(sdata->vif.link_conf[link_id]); if (!link_conf) { @@ -6670,6 +6614,7 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, return err; } + group_addressed = IS_ERR(sta); if (IS_ERR(sta)) sta = NULL; @@ -6685,14 +6630,25 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, info = IEEE80211_SKB_CB(skb); memset(info, 0, sizeof(*info)); info->flags = flags; + ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK); info->control.flags = ctrl_flags; - skb = ieee80211_build_hdr(sdata, skb, sta, cookie); + if (!group_addressed) + ieee80211_store_ack_skb(local, skb, cookie); + + skb = ieee80211_build_hdr(sdata, skb, sta); if (IS_ERR(skb)) { rcu_read_unlock(); return PTR_ERR(skb); } + if (link_id != u32_get_bits(info->control.flags, + IEEE80211_TX_CTRL_MLO_LINK)) { + ieee80211_free_txskb(&local->hw, skb); + rcu_read_unlock(); + return -EINVAL; + } + dev_sw_netstats_tx_add(dev, 1, skb->len); ieee80211_tpt_led_trig_tx(local, skb->len); From 102f54dc47be198e9310b18d41305a78d70a0796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Tue, 1 Sep 2026 10:33:19 +0200 Subject: [PATCH 0169/2126] wifi: wfx: fix possible device hang during init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The WFxxx device provides an SDIO interface. In addition to the usual in-band SDIO IRQ, the device also supports out-of-band IRQ line. OOB IRQ requires a specific initialization described in commit f00dc1d789e1c ("staging: wfx: poll IRQ during init"): When the chip starts in SDIO mode, the external IRQ (aka Out-Of-Band IRQ) cannot be used before to configure it. Therefore, the first exchanges with the chip have to be done without the OOB IRQ. This patch allow to poll the data until the OOB IRQ is correctly setup. In order to keep the code simpler, this patch also poll data even if OOB IRQ is not used. Commit 57aa557f110d9 ("staging: wfx: introduce a way to poll IRQ") announce some limitation about the data polling mechanism: This function [wfx_bh_poll_irq()] must used with care: if an IRQ fires while the host reads control register, the IRQ can be lost. However, with last analysis, it seems it does not only impact the IRQ. When this condition happen the hardware is lost and won't reply the next commands. The only way to recover the error is to pull the reset pin and bind the device again. Currently wfx_bh_poll_irq() is only used during the two first exchanges with the hardware. Therefore, it has been reported to only happen after a few hours of bind/rebind in a loop. This explain why it has not been reported before. Fortunately, wfx_bh_poll_irq() is only required for OOB IRQ, which is probably very marginal. The In-Band IRQ case also uses this function, but only to simplify the code. This patch limits the use of wfx_bh_poll_irq() to the OOB IRQ. The bus driver now tells wfx_probe() whether polling is necessary. When it is not (in-band SDIO IRQ and SPI), the IRQ is subscribed before the first exchange with the device and wfx_bh_poll_irq() is never called. When it is (SDIO with OOB IRQ), the behavior is unchanged: the control register is polled until the PDS file has configured the IRQ line. To conclude, In-Band users are now safe. Users of OOB IRQ will be still impacted by the bug, but there is nothing we can do (and nobody complained during the last 6 years). Fixes: f00dc1d789e1c ("staging: wfx: poll IRQ during init") Reported-by: Gerard Salvatella Reported-by: Lukas Stockmann Signed-off-by: Jérôme Pouiller Reviewed-by: Alexander Sverdlin Tested-by: Alexander Sverdlin Link: https://patch.msgid.link/20260901083548.113131-2-jerome.pouiller@silabs.com Signed-off-by: Johannes Berg --- drivers/net/wireless/silabs/wfx/bh.c | 6 ++-- drivers/net/wireless/silabs/wfx/bus_sdio.c | 1 + drivers/net/wireless/silabs/wfx/main.c | 34 ++++++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/silabs/wfx/bh.c b/drivers/net/wireless/silabs/wfx/bh.c index 21dfdcf9cc27..0071659bc9c9 100644 --- a/drivers/net/wireless/silabs/wfx/bh.c +++ b/drivers/net/wireless/silabs/wfx/bh.c @@ -284,10 +284,10 @@ void wfx_bh_request_tx(struct wfx_dev *wdev) } /* If IRQ is not available, this function allow to manually poll the control register and simulate - * an IRQ ahen an event happened. + * an IRQ when an event happened. * - * Note that the device has a bug: If an IRQ raise while host read control register, the IRQ is - * lost. So, use this function carefully (only duing device initialisation). + * Note that the device has a bug: If an IRQ raise while host read control register, the device is + * lost. Unfortunately, this is the only way to initialize the SDIO with out-of-band IRQ. */ void wfx_bh_poll_irq(struct wfx_dev *wdev) { diff --git a/drivers/net/wireless/silabs/wfx/bus_sdio.c b/drivers/net/wireless/silabs/wfx/bus_sdio.c index ab0793b9908f..1ca2cc262feb 100644 --- a/drivers/net/wireless/silabs/wfx/bus_sdio.c +++ b/drivers/net/wireless/silabs/wfx/bus_sdio.c @@ -279,6 +279,7 @@ static int wfx_sdio_probe(struct sdio_func *func, const struct sdio_device_id *i goto sdio_release; } + bus->core->poll_irq = !!bus->of_irq; ret = wfx_probe(bus->core); if (ret) goto sdio_release; diff --git a/drivers/net/wireless/silabs/wfx/main.c b/drivers/net/wireless/silabs/wfx/main.c index dda36e41eed1..4e99fe7e5bb7 100644 --- a/drivers/net/wireless/silabs/wfx/main.c +++ b/drivers/net/wireless/silabs/wfx/main.c @@ -362,7 +362,6 @@ int wfx_probe(struct wfx_dev *wdev) */ gpio_saved = wdev->pdata.gpio_wakeup; wdev->pdata.gpio_wakeup = NULL; - wdev->poll_irq = true; wdev->bh_wq = alloc_workqueue("wfx_bh_wq", WQ_HIGHPRI | WQ_PERCPU, 0); if (!wdev->bh_wq) @@ -370,16 +369,24 @@ int wfx_probe(struct wfx_dev *wdev) wfx_bh_register(wdev); + if (!wdev->poll_irq) { + err = wdev->hwbus_ops->irq_subscribe(wdev->hwbus_priv); + if (err) + goto bh_unregister; + } + err = wfx_init_device(wdev); if (err) - goto bh_unregister; + goto irq_unsubscribe; + + if (wdev->poll_irq) + wfx_bh_poll_irq(wdev); - wfx_bh_poll_irq(wdev); err = wait_for_completion_timeout(&wdev->firmware_ready, 1 * HZ); if (err == 0) { dev_err(wdev->dev, "timeout while waiting for startup indication\n"); err = -ETIMEDOUT; - goto bh_unregister; + goto irq_unsubscribe; } /* FIXME: fill wiphy::hw_version */ @@ -399,12 +406,12 @@ int wfx_probe(struct wfx_dev *wdev) dev_err(wdev->dev, "unsupported firmware API version (expect 1 while firmware returns %d)\n", wdev->hw_caps.api_version_major); err = -EOPNOTSUPP; - goto bh_unregister; + goto irq_unsubscribe; } if (wdev->hw_caps.link_mode == SEC_LINK_ENFORCED) { dev_err(wdev->dev, "chip require secure_link, but can't negotiate it\n"); - goto bh_unregister; + goto irq_unsubscribe; } if (wdev->hw_caps.region_sel_mode) { @@ -420,12 +427,14 @@ int wfx_probe(struct wfx_dev *wdev) dev_dbg(wdev->dev, "sending configuration file %s\n", wdev->pdata.file_pds); err = wfx_send_pdata_pds(wdev); if (err < 0 && err != -ENOENT) - goto bh_unregister; + goto irq_unsubscribe; - wdev->poll_irq = false; - err = wdev->hwbus_ops->irq_subscribe(wdev->hwbus_priv); - if (err) - goto bh_unregister; + if (wdev->poll_irq) { + err = wdev->hwbus_ops->irq_subscribe(wdev->hwbus_priv); + if (err) + goto bh_unregister; + wdev->poll_irq = false; + } err = wfx_hif_use_multi_tx_conf(wdev, true); if (err) @@ -474,7 +483,8 @@ int wfx_probe(struct wfx_dev *wdev) ieee80211_unregister: ieee80211_unregister_hw(wdev->hw); irq_unsubscribe: - wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv); + if (!wdev->poll_irq) + wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv); bh_unregister: wfx_bh_unregister(wdev); destroy_workqueue(wdev->bh_wq); From d8c297ec6bb4aef2dd57e851a9b18607e72ad9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Tue, 1 Sep 2026 10:33:20 +0200 Subject: [PATCH 0170/2126] dt-bindings: net: wireless: wfx: discourage OOB IRQ with SDIO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The WFxxx device provides an SDIO interface. In addition to the usual in-band SDIO IRQ, the device also supports an out-of-band IRQ line. However, using the OOB IRQ with SDIO requires to poll the control register during the device initialization. This polling is unreliable: if an IRQ is raised while the host reads the control register, the device is lost and only a reset allows to recover it. There is no way to fix this in software. So, warn the user that this setup should be reserved to debug. Signed-off-by: Jérôme Pouiller Acked-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260901083548.113131-3-jerome.pouiller@silabs.com Signed-off-by: Johannes Berg --- Documentation/devicetree/bindings/net/wireless/silabs,wfx.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/silabs,wfx.yaml b/Documentation/devicetree/bindings/net/wireless/silabs,wfx.yaml index 6c0888ae4c4e..60dfe257eadc 100644 --- a/Documentation/devicetree/bindings/net/wireless/silabs,wfx.yaml +++ b/Documentation/devicetree/bindings/net/wireless/silabs,wfx.yaml @@ -50,6 +50,9 @@ properties: used, this property is required. When SDIO is used, the "in-band" interrupt provided by the SDIO bus is used unless an interrupt is defined in the Device Tree. + + The hardware suffers from a limitation when this property is used with + SDIO. OOB IRQ with SDIO should only be used for debug. maxItems: 1 reset-gpios: From 5cf9d60d0e2fdf4310fc4687a6791bb1cdf7fa82 Mon Sep 17 00:00:00 2001 From: Georgi Valkov Date: Thu, 27 Aug 2026 20:58:48 +0300 Subject: [PATCH 0171/2126] dt-bindings: net: wireless: add flag marvell,invalid-reg-hint-in-rom WRT3200ACM and WRT32x routers always report a fixed US regulatory domain from the mwifiex ROM, which conflicts with the platform regulatory configuration on units sold outside the US market. For example: - phy0 mwlwifi 5 GHz, hard-coded region 98 EU mapped to FR - phy1 mwlwifi 2.4 GHz, hard-coded region 98 EU mapped to FR - phy2 mwifiex 2.4 and 5 GHz, hard-coded region US When the system boots, it detects a conflict between the user selected region and the radios, e.g. BG FR US, and applies extreme restrictions, preventing phy0 from starting on any DFS channel. phy2 works. Add a device-tree flag, which allows affected devices, where the radio conflicts with the platform to ignore the incorrect regulatory hint in the ROM of the radio, so the platform regulatory domain can be used. This does not allow the user to change the regulatory configuration of any radio. It only allows phy0 to start and operate according to its certified configuration. [1] https://github.com/kaloz/mwlwifi/issues/173#issuecomment-307879699 [2] https://github.com/openwrt/openwrt/issues/9956 Signed-off-by: Georgi Valkov Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260827175850.89395-1-gvalkov@gmail.com Signed-off-by: Johannes Berg --- .../devicetree/bindings/net/wireless/marvell,sd8787.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/marvell,sd8787.yaml b/Documentation/devicetree/bindings/net/wireless/marvell,sd8787.yaml index 930b700b73d0..9f905ef5c2c0 100644 --- a/Documentation/devicetree/bindings/net/wireless/marvell,sd8787.yaml +++ b/Documentation/devicetree/bindings/net/wireless/marvell,sd8787.yaml @@ -59,6 +59,12 @@ properties: description: Calibration data for sub-band 3 in the 5GHz band. maxItems: 502 + marvell,invalid-reg-hint-in-rom: + $ref: /schemas/types.yaml#/definitions/flag + description: + The regulatory hint in ROM conflicts with platform configuration. + It should be ignored, so the platform regulatory domain can be used. + marvell,wakeup-pin: $ref: /schemas/types.yaml#/definitions/uint32 description: From b4572cc9483054dbe0371768bf4075ab4b6c2168 Mon Sep 17 00:00:00 2001 From: Georgi Valkov Date: Thu, 27 Aug 2026 20:58:49 +0300 Subject: [PATCH 0172/2126] wifi: mwifiex: add dt flag to avoid conflict with platform reg domain WRT3200ACM and WRT32x routers always report a fixed US regulatory domain from the mwifiex ROM, which conflicts with the platform regulatory configuration on units sold outside the US market. For example: - phy0 mwlwifi 5 GHz, hard-coded region 98 EU mapped to FR - phy1 mwlwifi 2.4 GHz, hard-coded region 98 EU mapped to FR - phy2 mwifiex 2.4 and 5 GHz, hard-coded region US When the system boots, it detects a conflict between the user selected region and the radios, e.g. BG FR US, and applies extreme restrictions, preventing phy0 from starting on any DFS channel. phy2 works. Add a device-tree flag, which allows affected devices, where the radio conflicts with the platform to ignore the incorrect regulatory hint in the ROM of the radio, so the platform regulatory domain can be used. This does not allow the user to change the regulatory configuration of any radio. It only allows phy0 to start and operate according to its certified configuration. The change affects only platforms which explicitly define this flag, and helps overcome the incorrect behaviour of proprietary radio firmware. The change has been tested on OpenWrt and fixes the issue where phy0 does not start on WRT3200ACM-EU when a DFS channel is used [1] https://github.com/kaloz/mwlwifi/issues/173#issuecomment-307879699 [2] https://github.com/openwrt/openwrt/issues/9956 Signed-off-by: Georgi Valkov Link: https://patch.msgid.link/20260827175850.89395-2-gvalkov@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/mwifiex/cfg80211.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c index 7a1ba32f1fb3..293876397b67 100644 --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c @@ -4897,7 +4897,14 @@ int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter) country_code = mwifiex_11d_code_2_region( adapter->region_code); + + /* If the reg hint in ROM conflicts with platform + * configuration, it should be ignored, so the + * platform regulatory domain can be used. + */ if (country_code && + !device_property_read_bool(adapter->dev, + "marvell,invalid-reg-hint-in-rom") && regulatory_hint(wiphy, country_code)) mwifiex_dbg(priv->adapter, ERROR, "regulatory_hint() failed\n"); From f2e8260ad4093f9921b07686eb5cc027c38b1c7d Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 30 Aug 2026 20:48:10 +0800 Subject: [PATCH 0173/2126] wifi: libertas_tf: validate firmware block extents check_fwfile_format() reads each block header and trusts its data length before proving that both fit in the firmware image. A truncated header or oversized block can therefore pass malformed extents to the download path. Require the remaining image to contain the complete header and payload before accepting each block. Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260830124810.97223-1-pengpeng@iscas.ac.cn Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/libertas_tf/if_usb.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/marvell/libertas_tf/if_usb.c b/drivers/net/wireless/marvell/libertas_tf/if_usb.c index b85c6d783bf7..b9d1a33bddfc 100644 --- a/drivers/net/wireless/marvell/libertas_tf/if_usb.c +++ b/drivers/net/wireless/marvell/libertas_tf/if_usb.c @@ -769,10 +769,18 @@ static int check_fwfile_format(const u8 *data, u32 totlen) exit = len = 0; do { - struct fwheader *fwh = (void *) data; + struct fwheader *fwh; + + if (totlen - len < sizeof(*fwh)) + break; + + fwh = (void *)data; bincmd = le32_to_cpu(fwh->dnldcmd); blksize = le32_to_cpu(fwh->datalength); + if (blksize > totlen - len - sizeof(*fwh)) + break; + switch (bincmd) { case FW_HAS_DATA_TO_RECV: offset = sizeof(struct fwheader) + blksize; From c7fee4aaaf9294ef9f86eb69464e89fe096ba5db Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 30 Aug 2026 22:04:20 +0800 Subject: [PATCH 0174/2126] wifi: libertas: validate firmware block extents check_fwfile_format() reads each block header and trusts its data length before proving that both fit in the firmware image. A truncated header or oversized block can therefore pass malformed extents to the download path. Require the remaining image to contain the complete header and payload before accepting each block. Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260830140420.26399-1-pengpeng@iscas.ac.cn Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/libertas/if_usb.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/marvell/libertas/if_usb.c b/drivers/net/wireless/marvell/libertas/if_usb.c index 5cc0c5cac257..74870c9bd091 100644 --- a/drivers/net/wireless/marvell/libertas/if_usb.c +++ b/drivers/net/wireless/marvell/libertas/if_usb.c @@ -798,10 +798,18 @@ static int check_fwfile_format(const uint8_t *data, uint32_t totlen) exit = len = 0; do { - struct fwheader *fwh = (void *)data; + struct fwheader *fwh; + + if (totlen - len < sizeof(*fwh)) + break; + + fwh = (void *)data; bincmd = le32_to_cpu(fwh->dnldcmd); blksize = le32_to_cpu(fwh->datalength); + if (blksize > totlen - len - sizeof(*fwh)) + break; + switch (bincmd) { case FW_HAS_DATA_TO_RECV: offset = sizeof(struct fwheader) + blksize; From 25f3f2ff88ae604a3b473b501fc55d58fcb0f5eb Mon Sep 17 00:00:00 2001 From: Julius Bairaktaris Date: Fri, 4 Sep 2026 11:06:26 +0200 Subject: [PATCH 0175/2126] wifi: mac80211: fix swapped fq_overlimit/fq_overmemory in aqm debugfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two scnprintf arguments for fq_overlimit and fq_overmemory are in the wrong order, which results in the aqm debugfs file showing the overmemory count under the fq_overlimit label and vice versa. Fixes: 2a4e675d887b ("mac80211: Export fq memory limit information in debugfs") Reviewed-by: Toke Høiland-Jørgensen Assisted-by: Claude:claude-opus-5 Signed-off-by: Julius Bairaktaris Link: https://patch.msgid.link/20260904090626.92727-1-julius@bairaktaris.de Signed-off-by: Johannes Berg --- net/mac80211/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 105653a16b68..8946b027782c 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c @@ -96,8 +96,8 @@ static ssize_t aqm_read(struct file *file, "RW fq_quantum %u\n", fq->flows_cnt, fq->backlog, - fq->overmemory, fq->overlimit, + fq->overmemory, fq->collisions, fq->memory_usage, fq->memory_limit, From 01c15a8b936d319f3daf7ffaddfe44ca5bd40504 Mon Sep 17 00:00:00 2001 From: Manish Dharanenthiran Date: Wed, 5 Aug 2026 14:56:02 +0530 Subject: [PATCH 0176/2126] wifi: nl80211: add support to configure 6 GHz non-HT duplicate transmission As per IEEE Std 802.11-2024, subclause 26.17.2.2, a 6 GHz AP can transmit a Beacon frame using a non-HT duplicate PPDU, so that stations scanning only PSC channels can discover it. Currently, there is no mechanism to request the driver to transmit non-HT duplicate Beacon frames. In [1], changes were made to parse the Beacon from user-space to set the non-HT duplicate flag in the kernel. However, it was suggested that non-HT transmission be part of the Beacon TX rate settings. Hence, add NL80211_TXRATE_6GHZ_NON_HT_DUP as a flag attribute under NL80211_ATTR_TX_RATES to let user-space request the driver to transmit non-HT duplicate Beacons. Also add validation to reject the Beacon if non-HT duplicate Beacon transmission is enabled when legacy rates are not configured. [1] https://lore.kernel.org/all/1644914581-21682-1-git-send-email-quic_ramess@quicinc.com/ Signed-off-by: Manish Dharanenthiran Link: https://patch.msgid.link/20260805-dup-beacon-v1-1-68574869c896@oss.qualcomm.com Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 1 + include/uapi/linux/nl80211.h | 4 ++++ net/wireless/nl80211.c | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 2abf9e20cc22..6461a7bd0169 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -900,6 +900,7 @@ struct cfg80211_bitrate_mask { enum nl80211_eht_gi eht_gi; enum nl80211_he_ltf he_ltf; enum nl80211_eht_ltf eht_ltf; + bool nonht_dup_6ghz; } control[NUM_NL80211_BANDS]; }; diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 020387d76412..d8fefefc11a9 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -5900,6 +5900,9 @@ enum nl80211_key_attributes { * see &struct nl80211_txrate_eht * @NL80211_TXRATE_EHT_GI: configure EHT GI, (u8, see &enum nl80211_eht_gi) * @NL80211_TXRATE_EHT_LTF: configure EHT LTF, (u8, see &enum nl80211_eht_ltf) + * @NL80211_TXRATE_6GHZ_NON_HT_DUP: configure 6 GHz non-HT duplicate Beacon + * transmission. This flag is applicable only in Beacon TX rate setting + * and must be accompanied by a non-HT (legacy) Beacon rate. * @__NL80211_TXRATE_AFTER_LAST: internal * @NL80211_TXRATE_MAX: highest TX rate attribute */ @@ -5915,6 +5918,7 @@ enum nl80211_tx_rate_attributes { NL80211_TXRATE_EHT, NL80211_TXRATE_EHT_GI, NL80211_TXRATE_EHT_LTF, + NL80211_TXRATE_6GHZ_NON_HT_DUP, /* keep last */ __NL80211_TXRATE_AFTER_LAST, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 8f022bb1413c..e585da1d79c9 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -569,6 +569,7 @@ static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { [NL80211_TXRATE_EHT_LTF] = NLA_POLICY_RANGE(NLA_U8, NL80211_RATE_INFO_EHT_1XLTF, NL80211_RATE_INFO_EHT_8XLTF), + [NL80211_TXRATE_6GHZ_NON_HT_DUP] = { .type = NLA_FLAG }, }; @@ -6303,6 +6304,14 @@ static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, mask->control[band].eht_ltf = nla_get_u8(tb[NL80211_TXRATE_EHT_LTF]); + if (tb[NL80211_TXRATE_6GHZ_NON_HT_DUP]) { + if (band != NL80211_BAND_6GHZ || + (wdev->iftype != NL80211_IFTYPE_AP && + wdev->iftype != NL80211_IFTYPE_P2P_GO)) + return -EINVAL; + mask->control[band].nonht_dup_6ghz = true; + } + if (mask->control[band].legacy == 0) { /* don't allow empty legacy rates if HT, VHT, HE or EHT * are not even supported. @@ -6344,6 +6353,7 @@ static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, { u32 count_ht, count_vht, count_he, count_eht, i; u32 rate = beacon_rate->control[band].legacy; + bool nonht_dup = beacon_rate->control[band].nonht_dup_6ghz; /* Allow only one rate */ if (hweight32(rate) > 1) @@ -6405,6 +6415,9 @@ static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, (!rate && !count_ht && !count_vht && !count_he && !count_eht)) return -EINVAL; + if (nonht_dup && !rate) + return -EINVAL; + if (rate && !wiphy_ext_feature_isset(&rdev->wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) From 9d1365e96a920bf79974161e370b5640a0054461 Mon Sep 17 00:00:00 2001 From: Mariano Baragiola Date: Mon, 17 Aug 2026 20:35:21 -0300 Subject: [PATCH 0177/2126] wifi: mac80211: avoid trimming injected FCS twice When packet sockets use PACKET_QDISC_BYPASS, mac80211 can parse the radiotap header while selecting the queue and again before transmit. If the header includes an FCS, both parses trim the skb. Validate the FCS on both parses, but trim it only before transmit. This keeps queue selection read-only and avoids trimming shared skb data twice. Fixes: cb17ed29a7a5 ("mac80211: parse radiotap header when selecting Tx queue") Signed-off-by: Mariano Baragiola Link: https://patch.msgid.link/20260817233521.2747027-1-mbaragiola@linux.com Signed-off-by: Johannes Berg --- include/net/mac80211.h | 3 ++- net/mac80211/iface.c | 2 +- net/mac80211/tx.c | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index f147bc019e7b..7bb4618065b6 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -7630,11 +7630,12 @@ bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw, * * @skb: packet injected by userspace * @dev: the &struct device of this 802.11 device + * @trim_fcs: trim the FCS trailer when present; validate it otherwise * * Return: %true if the radiotap header was parsed, %false otherwise */ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, - struct net_device *dev); + struct net_device *dev, bool trim_fcs); /** * struct ieee80211_noa_data - holds temporary data for tracking P2P NoA state diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 43460a705a6b..fdac729ca580 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -964,7 +964,7 @@ static u16 ieee80211_monitor_select_queue(struct net_device *dev, /* reset flags and info before parsing radiotap header */ memset(info, 0, sizeof(*info)); - if (!ieee80211_parse_tx_radiotap(skb, dev)) + if (!ieee80211_parse_tx_radiotap(skb, dev, false)) return 0; /* doesn't matter, frame will be dropped */ len_rthdr = ieee80211_get_radiotap_len(skb->data); diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 7d34b160fddd..c33092960df2 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2138,7 +2138,7 @@ static bool ieee80211_validate_radiotap_len(struct sk_buff *skb) } bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, - struct net_device *dev) + struct net_device *dev, bool trim_fcs) { struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); struct ieee80211_radiotap_iterator iterator; @@ -2195,7 +2195,8 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, if (skb->len < (iterator._max_length + FCS_LEN)) return false; - skb_trim(skb, skb->len - FCS_LEN); + if (trim_fcs) + skb_trim(skb, skb->len - FCS_LEN); } if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP) info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT; @@ -2511,7 +2512,7 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, * selected chandef above to accurately set injection rates and * retransmissions. */ - if (!ieee80211_parse_tx_radiotap(skb, dev)) + if (!ieee80211_parse_tx_radiotap(skb, dev, true)) goto fail_rcu; /* remove the injection radiotap header */ From 1b60ed34f712e9f606d80951f1586f4274ebadf1 Mon Sep 17 00:00:00 2001 From: Zhiling Zou Date: Mon, 3 Aug 2026 12:07:40 +0800 Subject: [PATCH 0178/2126] wifi: mac80211: serialize debugfs netdev rename with recreate ieee80211_debugfs_rename_netdev() renames sdata->vif.debugfs_dir without sharing synchronization with ieee80211_debugfs_recreate_netdev(). When MLO link updates switch an interface to or from MLO, the recreate path can remove and rebuild that dentry while a concurrent netdev rename still uses the stale pointer. Serialize the rename helper with the same wiphy mutex that protects the recreate path so the dentry cannot be removed while debugfs_change_name() is operating on it. Reported-by: Vega Signed-off-by: Zhiling Zou Link: https://patch.msgid.link/76eecaf74ca2d4e4aedf46c3ee7505917433468b.1785729184.git.zhilinz@nebusec.ai Signed-off-by: Johannes Berg --- net/mac80211/debugfs_netdev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c index f3c6a41e4911..10f8d77852a1 100644 --- a/net/mac80211/debugfs_netdev.c +++ b/net/mac80211/debugfs_netdev.c @@ -1024,7 +1024,13 @@ void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata) { - debugfs_change_name(sdata->vif.debugfs_dir, "netdev:%s", sdata->name); + struct dentry *dir; + + wiphy_lock(sdata->local->hw.wiphy); + dir = sdata->vif.debugfs_dir; + if (dir) + debugfs_change_name(dir, "netdev:%s", sdata->name); + wiphy_unlock(sdata->local->hw.wiphy); } void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data *sdata, From ddffc67d89c80608b26cc0c659d6fa18513ba8c3 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:39 +0800 Subject: [PATCH 0179/2126] r8169: add speed in private struct This patch adds speed in private struct in order to decouple from phydev in the following patch supporting for phylink. Reviewed-by: Andrew Lunn Signed-off-by: Javen Xu Link: https://patch.msgid.link/20260831053745.1197-2-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index ec4fc21fa21f..c60710f9bd21 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -750,6 +750,7 @@ struct rtl8169_private { u32 irq_mask; int irq; struct clk *clk; + int speed; struct { DECLARE_BITMAP(flags, RTL_FLAG_MAX); @@ -1673,16 +1674,14 @@ static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) rtl_pci_commit(tp); } -static void rtl_link_chg_patch(struct rtl8169_private *tp) +static void rtl_link_chg_patch(struct rtl8169_private *tp, int speed) { - struct phy_device *phydev = tp->phydev; - if (tp->mac_version == RTL_GIGA_MAC_VER_34 || tp->mac_version == RTL_GIGA_MAC_VER_38) { - if (phydev->speed == SPEED_1000) { + if (speed == SPEED_1000) { rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); - } else if (phydev->speed == SPEED_100) { + } else if (speed == SPEED_100) { rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); } else { @@ -1692,7 +1691,7 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp) rtl_reset_packet_filter(tp); } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || tp->mac_version == RTL_GIGA_MAC_VER_36) { - if (phydev->speed == SPEED_1000) { + if (speed == SPEED_1000) { rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); } else { @@ -1700,7 +1699,7 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp) rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); } } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { - if (phydev->speed == SPEED_10) { + if (speed == SPEED_10) { rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060a); } else { @@ -2074,11 +2073,11 @@ rtl_coalesce_info(struct rtl8169_private *tp) ci = rtl_coalesce_info_8168_8136; /* if speed is unknown assume highest one */ - if (tp->phydev->speed == SPEED_UNKNOWN) + if (tp->speed == SPEED_UNKNOWN) return ci; for (; ci->speed; ci++) { - if (tp->phydev->speed == ci->speed) + if (tp->speed == ci->speed) return ci; } @@ -2236,7 +2235,7 @@ static void rtl_set_eee_txidle_timer(struct rtl8169_private *tp) static unsigned int r8169_get_tx_lpi_timer_us(struct rtl8169_private *tp) { - unsigned int speed = tp->phydev->speed; + unsigned int speed = tp->speed; unsigned int timer = tp->tx_lpi_timer; if (!timer || speed == SPEED_UNKNOWN) @@ -4968,8 +4967,9 @@ static void r8169_phylink_handler(struct net_device *ndev) struct rtl8169_private *tp = netdev_priv(ndev); struct device *d = tp_to_dev(tp); + tp->speed = tp->phydev->speed; if (netif_carrier_ok(ndev)) { - rtl_link_chg_patch(tp); + rtl_link_chg_patch(tp, tp->speed); rtl_enable_tx_lpi(tp, tp->phydev->enable_tx_lpi); pm_request_resume(d); } else { @@ -5667,6 +5667,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ext_xid_str, xid); tp->mac_version = chip->mac_version; tp->fw_name = chip->fw_name; + tp->speed = SPEED_UNKNOWN; /* Disable ASPM L1 as that cause random device stop working * problems as well as full system hangs for some PCIe devices users. From 9f8cb9cbcdc815d7f7b625705924e9c64e54cac4 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:40 +0800 Subject: [PATCH 0180/2126] net: phy: phylink: add helper to modify pause For Realtek nics, when we enable jumbo, pause are not supported. So we must check the pause capabilities from ourself and lp. Reviewed-by: Andrew Lunn Signed-off-by: Javen Xu Link: https://patch.msgid.link/20260831053745.1197-3-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/phy/phylink.c | 171 +++++++++++++++++++++++++++----------- include/linux/phylink.h | 2 + 2 files changed, 123 insertions(+), 50 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index ff4375f1e910..b9fc8599df74 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1829,6 +1829,126 @@ int phylink_set_fixed_link(struct phylink *pl, } EXPORT_SYMBOL_GPL(phylink_set_fixed_link); +/** + * phylink_update_pause_state() - Update the phylink pause frame configuration + * @pl: a pointer to a &struct phylink instance + * @pause_state: bitmask indicating the new pause state + * + * Update the MAC pause frame (flow control) state for the phylink instance. + */ +static void phylink_update_pause_state(struct phylink *pl, int pause_state) +{ + struct phylink_link_state *config = &pl->link_config; + bool tx_pause = !!(pause_state & MLO_PAUSE_TX); + bool rx_pause = !!(pause_state & MLO_PAUSE_RX); + bool manual_changed; + + mutex_lock(&pl->state_mutex); + + /* + * See the comments for linkmode_set_pause(), wrt the deficiencies + * with the current implementation. A solution to this issue would + * be: + * ethtool Local device + * rx tx Pause AsymDir + * 0 0 0 0 + * 1 0 1 1 + * 0 1 0 1 + * 1 1 1 1 + * and then use the ethtool rx/tx enablement status to mask the + * rx/tx pause resolution. + */ + linkmode_set_pause(config->advertising, tx_pause, + rx_pause); + + manual_changed = (config->pause ^ pause_state) & MLO_PAUSE_AN || + (!(pause_state & MLO_PAUSE_AN) && + (config->pause ^ pause_state) & MLO_PAUSE_TXRX_MASK); + + config->pause = pause_state; + + /* Update our in-band advertisement, triggering a renegotiation if + * the advertisement changed. + */ + if (!pl->phydev) + phylink_change_inband_advert(pl); + + mutex_unlock(&pl->state_mutex); + + /* If we have a PHY, a change of the pause frame advertisement will + * cause phylib to renegotiate (if AN is enabled) which will in turn + * call our phylink_phy_change() and trigger a resolve. Note that + * we can't hold our state mutex while calling phy_set_asym_pause(). + */ + if (pl->phydev) + phy_set_asym_pause(pl->phydev, rx_pause, tx_pause); + + /* If the manual pause settings changed, make sure we trigger a + * resolve to update their state; we can not guarantee that the + * link will cycle. + */ + if (manual_changed) { + pl->link_failed = true; + phylink_run_resolve(pl); + } +} + +/** + * phylink_update_mac_pause_capabilities() - Dynamically update MAC pause + * @pl: a pointer to a &struct phylink returned from phylink_create() + * @mac_pause: the new MAC pause capabilities mask + * + * This function allows a MAC driver to dynamically change its pause state, + * such as losing/gaining Pause frame support based on MTU size. + * It recalculates supported link modes and triggers renegotiation if needed. + */ +void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac_pause) +{ + struct phylink_link_state *config = &pl->link_config; + unsigned long old_pause; + int pause_state; + + ASSERT_RTNL(); + + if (mac_pause & ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE)) { + phylink_err(pl, "Attempted to dynamically change non-pause MAC capabilities\n"); + return; + } + + old_pause = pl->config->mac_capabilities & (MAC_SYM_PAUSE | MAC_ASYM_PAUSE); + if (old_pause == mac_pause) + return; + + mutex_lock(&pl->state_mutex); + + pl->config->mac_capabilities &= ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE); + pl->config->mac_capabilities |= mac_pause; + + phylink_set(pl->supported, Pause); + phylink_set(pl->supported, Asym_Pause); + + if (pl->phydev) + linkmode_and(pl->supported, pl->supported, pl->phydev->supported); + else if (pl->sfp_bus) + linkmode_and(pl->supported, pl->supported, pl->sfp_support); + + phylink_validate(pl, pl->supported, config); + + pause_state = config->pause; + + if (!phylink_test(pl->supported, Pause)) { + pause_state &= ~(MLO_PAUSE_RX | MLO_PAUSE_TX); + } else if (!phylink_test(pl->supported, Asym_Pause)) { + if ((pause_state & MLO_PAUSE_RX) ^ (pause_state & MLO_PAUSE_TX)) + pause_state &= ~(MLO_PAUSE_RX | MLO_PAUSE_TX); + } + + mutex_unlock(&pl->state_mutex); + + phylink_update_pause_state(pl, pause_state); +} +EXPORT_SYMBOL_GPL(phylink_update_mac_pause_capabilities); + /** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config @@ -3188,8 +3308,6 @@ EXPORT_SYMBOL_GPL(phylink_ethtool_get_pauseparam); int phylink_ethtool_set_pauseparam(struct phylink *pl, struct ethtool_pauseparam *pause) { - struct phylink_link_state *config = &pl->link_config; - bool manual_changed; int pause_state; ASSERT_RTNL(); @@ -3213,54 +3331,7 @@ int phylink_ethtool_set_pauseparam(struct phylink *pl, if (pause->tx_pause) pause_state |= MLO_PAUSE_TX; - mutex_lock(&pl->state_mutex); - /* - * See the comments for linkmode_set_pause(), wrt the deficiencies - * with the current implementation. A solution to this issue would - * be: - * ethtool Local device - * rx tx Pause AsymDir - * 0 0 0 0 - * 1 0 1 1 - * 0 1 0 1 - * 1 1 1 1 - * and then use the ethtool rx/tx enablement status to mask the - * rx/tx pause resolution. - */ - linkmode_set_pause(config->advertising, pause->tx_pause, - pause->rx_pause); - - manual_changed = (config->pause ^ pause_state) & MLO_PAUSE_AN || - (!(pause_state & MLO_PAUSE_AN) && - (config->pause ^ pause_state) & MLO_PAUSE_TXRX_MASK); - - config->pause = pause_state; - - /* Update our in-band advertisement, triggering a renegotiation if - * the advertisement changed. - */ - if (!pl->phydev) - phylink_change_inband_advert(pl); - - mutex_unlock(&pl->state_mutex); - - /* If we have a PHY, a change of the pause frame advertisement will - * cause phylib to renegotiate (if AN is enabled) which will in turn - * call our phylink_phy_change() and trigger a resolve. Note that - * we can't hold our state mutex while calling phy_set_asym_pause(). - */ - if (pl->phydev) - phy_set_asym_pause(pl->phydev, pause->rx_pause, - pause->tx_pause); - - /* If the manual pause settings changed, make sure we trigger a - * resolve to update their state; we can not guarantee that the - * link will cycle. - */ - if (manual_changed) { - pl->link_failed = true; - phylink_run_resolve(pl); - } + phylink_update_pause_state(pl, pause_state); return 0; } diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 1dda5c7ed5f1..3a88a69882a6 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -843,4 +843,6 @@ void phylink_replay_link_begin(struct phylink *pl); void phylink_replay_link_end(struct phylink *pl); +void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac_pause); + #endif From 8a3c76523e44978714818d91fa9f80ab5607fdb6 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:41 +0800 Subject: [PATCH 0181/2126] r8169: add support for phylink Transfer old framework to phylink. Phylink can support fiber mode card which can not get link status or link speed from standard phy registers. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831053745.1197-4-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/Kconfig | 2 +- drivers/net/ethernet/realtek/r8169_main.c | 298 ++++++++++++++++------ 2 files changed, 222 insertions(+), 78 deletions(-) diff --git a/drivers/net/ethernet/realtek/Kconfig b/drivers/net/ethernet/realtek/Kconfig index 9b0f4f9631db..5818a9a500a8 100644 --- a/drivers/net/ethernet/realtek/Kconfig +++ b/drivers/net/ethernet/realtek/Kconfig @@ -86,8 +86,8 @@ config R8169 depends on PCI select FW_LOADER select CRC32 - select PHYLIB select REALTEK_PHY + select PHYLINK help Say Y here if you have a Realtek Ethernet adapter belonging to the following families: diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index c60710f9bd21..823763e4f445 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -775,6 +776,8 @@ struct rtl8169_private { struct r8169_led_classdev *leds; u32 ocp_base; + struct phylink *phylink; + struct phylink_config phylink_config; }; typedef void (*rtl_generic_fct)(struct rtl8169_private *tp); @@ -2253,7 +2256,7 @@ static int rtl8169_get_eee(struct net_device *dev, struct ethtool_keee *data) if (!rtl_supports_eee(tp)) return -EOPNOTSUPP; - ret = phy_ethtool_get_eee(tp->phydev, data); + ret = phylink_ethtool_get_eee(tp->phylink, data); if (ret) return ret; @@ -2269,7 +2272,7 @@ static int rtl8169_set_eee(struct net_device *dev, struct ethtool_keee *data) if (!rtl_supports_eee(tp)) return -EOPNOTSUPP; - return phy_ethtool_set_eee(tp->phydev, data); + return phylink_ethtool_set_eee(tp->phylink, data); } static void rtl8169_get_ringparam(struct net_device *dev, @@ -2300,13 +2303,8 @@ static void rtl8169_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *data) { struct rtl8169_private *tp = netdev_priv(dev); - bool tx_pause, rx_pause; - phy_get_pause(tp->phydev, &tx_pause, &rx_pause); - - data->autoneg = tp->phydev->autoneg; - data->tx_pause = tx_pause ? 1 : 0; - data->rx_pause = rx_pause ? 1 : 0; + phylink_ethtool_get_pauseparam(tp->phylink, data); } static int rtl8169_set_pauseparam(struct net_device *dev, @@ -2314,12 +2312,10 @@ static int rtl8169_set_pauseparam(struct net_device *dev, { struct rtl8169_private *tp = netdev_priv(dev); - if (dev->mtu > ETH_DATA_LEN) + if (dev->mtu > ETH_DATA_LEN || data->autoneg == AUTONEG_DISABLE) return -EOPNOTSUPP; - phy_set_asym_pause(tp->phydev, data->rx_pause, data->tx_pause); - - return 0; + return phylink_ethtool_set_pauseparam(tp->phylink, data); } static void rtl8169_get_eth_mac_stats(struct net_device *dev, @@ -2385,6 +2381,14 @@ static void rtl8169_get_eth_ctrl_stats(struct net_device *dev, le32_to_cpu(tp->counters->rx_unknown_opcode); } +static int rtl8169_get_link_ksettings(struct net_device *ndev, + struct ethtool_link_ksettings *cmd) +{ + struct rtl8169_private *tp = netdev_priv(ndev); + + return phylink_ethtool_ksettings_get(tp->phylink, cmd); +} + static int rtl8169_set_link_ksettings(struct net_device *ndev, const struct ethtool_link_ksettings *cmd) { @@ -2394,7 +2398,7 @@ static int rtl8169_set_link_ksettings(struct net_device *ndev, int speed = cmd->base.speed; if (!tp->sfp_mode) - return phy_ethtool_ksettings_set(phydev, cmd); + return phylink_ethtool_ksettings_set(tp->phylink, cmd); if (cmd->base.autoneg != AUTONEG_DISABLE) return -EINVAL; @@ -2415,6 +2419,13 @@ static int rtl8169_set_link_ksettings(struct net_device *ndev, return 0; } +static int rtl8169_nway_reset(struct net_device *dev) +{ + struct rtl8169_private *tp = netdev_priv(dev); + + return phylink_ethtool_nway_reset(tp->phylink); +} + static const struct ethtool_ops rtl8169_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES, @@ -2430,10 +2441,10 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .get_sset_count = rtl8169_get_sset_count, .get_ethtool_stats = rtl8169_get_ethtool_stats, .get_ts_info = ethtool_op_get_ts_info, - .nway_reset = phy_ethtool_nway_reset, + .nway_reset = rtl8169_nway_reset, .get_eee = rtl8169_get_eee, .set_eee = rtl8169_set_eee, - .get_link_ksettings = phy_ethtool_get_link_ksettings, + .get_link_ksettings = rtl8169_get_link_ksettings, .set_link_ksettings = rtl8169_set_link_ksettings, .get_ringparam = rtl8169_get_ringparam, .get_pause_stats = rtl8169_get_pause_stats, @@ -2656,15 +2667,6 @@ static void rtl_jumbo_config(struct rtl8169_private *tp) if (pci_is_pcie(tp->pci_dev) && tp->supports_gmii) pcie_set_readrq(tp->pci_dev, readrq); - - /* Chip doesn't support pause in jumbo mode */ - if (jumbo) { - linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, - tp->phydev->advertising); - linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - tp->phydev->advertising); - phy_start_aneg(tp->phydev); - } } DECLARE_RTL_COND(rtl_chipcmd_cond) @@ -2779,7 +2781,7 @@ static void rtl_prepare_power_down(struct rtl8169_private *tp) rtl_ephy_write(tp, 0x19, 0xff64); if (device_may_wakeup(tp_to_dev(tp))) { - phy_speed_down(tp->phydev, false); + phylink_speed_down(tp->phylink, false); rtl_wol_enable_rx(tp); } } @@ -2831,6 +2833,16 @@ static void rtl8169_set_magic_reg(struct rtl8169_private *tp) RTL_W32(tp, 0x7c, val); } +static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + struct rtl8169_private *tp = netdev_priv(dev); + + if (!netif_running(dev)) + return -ENODEV; + + return phylink_mii_ioctl(tp->phylink, ifr, cmd); +} + static void rtl_set_rx_mode(struct net_device *dev) { u32 rx_mode = AcceptBroadcast | AcceptMyPhys | AcceptMulticast; @@ -4138,12 +4150,23 @@ static void rtl_hw_start(struct rtl8169_private *tp) static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) { struct rtl8169_private *tp = netdev_priv(dev); + bool jumbo_before = dev->mtu > ETH_DATA_LEN; + bool jumbo_after = new_mtu > ETH_DATA_LEN; WRITE_ONCE(dev->mtu, new_mtu); netdev_update_features(dev); rtl_jumbo_config(tp); rtl_set_eee_txidle_timer(tp); + if (jumbo_before != jumbo_after) { + unsigned long caps = 0; + + if (!jumbo_after) + caps |= (MAC_SYM_PAUSE | MAC_ASYM_PAUSE); + + phylink_update_mac_pause_capabilities(tp->phylink, caps); + } + return 0; } @@ -4929,9 +4952,6 @@ static int rtl8169_poll(struct napi_struct *napi, int budget) static void rtl_enable_tx_lpi(struct rtl8169_private *tp, bool enable) { - if (!rtl_supports_eee(tp)) - return; - switch (tp->mac_version) { case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_52: /* Adjust EEE LED frequency */ @@ -4962,41 +4982,15 @@ static void rtl_enable_tx_lpi(struct rtl8169_private *tp, bool enable) } } -static void r8169_phylink_handler(struct net_device *ndev) -{ - struct rtl8169_private *tp = netdev_priv(ndev); - struct device *d = tp_to_dev(tp); - - tp->speed = tp->phydev->speed; - if (netif_carrier_ok(ndev)) { - rtl_link_chg_patch(tp, tp->speed); - rtl_enable_tx_lpi(tp, tp->phydev->enable_tx_lpi); - pm_request_resume(d); - } else { - pm_runtime_idle(d); - } - - phy_print_status(tp->phydev); -} - static int r8169_phy_connect(struct rtl8169_private *tp) { - struct phy_device *phydev = tp->phydev; - phy_interface_t phy_mode; int ret; - phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : - PHY_INTERFACE_MODE_MII; - - ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, - phy_mode); - if (ret) + ret = phylink_connect_phy(tp->phylink, tp->phydev); + if (ret) { + netdev_err(tp->dev, "failed to connect phy\n"); return ret; - - if (!tp->supports_gmii) - phy_set_max_speed(phydev, SPEED_100); - - phy_attached_info(phydev); + } return 0; } @@ -5007,8 +5001,6 @@ static void rtl8169_down(struct rtl8169_private *tp) /* Clear all task flags */ bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); - phy_stop(tp->phydev); - /* Reset SerDes PHY to bring down fiber link */ if (tp->sfp_mode) rtl_sfp_reset(tp); @@ -5038,8 +5030,6 @@ static void rtl8169_up(struct rtl8169_private *tp) napi_enable(&tp->napi); enable_work(&tp->wk.work); rtl_reset_work(tp); - - phy_start(tp->phydev); } static int rtl8169_close(struct net_device *dev) @@ -5049,13 +5039,14 @@ static int rtl8169_close(struct net_device *dev) pm_runtime_get_sync(&pdev->dev); + phylink_stop(tp->phylink); netif_stop_queue(dev); rtl8169_down(tp); rtl8169_rx_clear(tp); free_irq(tp->irq, tp); - phy_disconnect(tp->phydev); + phylink_disconnect_phy(tp->phylink); dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, tp->RxPhyAddr); @@ -5117,6 +5108,7 @@ static int rtl_open(struct net_device *dev) goto err_free_irq; rtl8169_up(tp); + phylink_start(tp->phylink); rtl8169_init_counter_offsets(tp); netif_start_queue(dev); out: @@ -5288,6 +5280,7 @@ static void rtl_remove_one(struct pci_dev *pdev) r8169_remove_leds(tp->leds); unregister_netdev(tp->dev); + phylink_destroy(tp->phylink); if (tp->dash_type != RTL_DASH_NONE) rtl8168_driver_stop(tp); @@ -5310,7 +5303,7 @@ static const struct net_device_ops rtl_netdev_ops = { .ndo_fix_features = rtl8169_fix_features, .ndo_set_features = rtl8169_set_features, .ndo_set_mac_address = rtl_set_mac_address, - .ndo_eth_ioctl = phy_do_ioctl_running, + .ndo_eth_ioctl = rtl8169_ioctl, .ndo_set_rx_mode = rtl_set_rx_mode, #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = rtl8169_netpoll, @@ -5474,16 +5467,6 @@ static int r8169_mdio_register(struct rtl8169_private *tp) return -EUNATCH; } - tp->phydev->mac_managed_pm = true; - if (rtl_supports_eee(tp)) - phy_support_eee(tp->phydev); - phy_support_asym_pause(tp->phydev); - - /* mimic behavior of r8125/r8126 vendor drivers */ - if (tp->mac_version == RTL_GIGA_MAC_VER_61) - phy_disable_eee_mode(tp->phydev, - ETHTOOL_LINK_MODE_2500baseT_Full_BIT); - /* PHY will be woken up in rtl_open() */ phy_suspend(tp->phydev); @@ -5599,6 +5582,159 @@ static bool rtl_aspm_is_safe(struct rtl8169_private *tp) return false; } +static void rtl_mac_link_down(struct phylink_config *config, unsigned int mode, + phy_interface_t interface) +{ + struct rtl8169_private *tp = container_of(config, + struct rtl8169_private, + phylink_config); + + tp->speed = SPEED_UNKNOWN; + pm_runtime_idle(tp_to_dev(tp)); +} + +static void rtl_mac_link_up(struct phylink_config *config, + struct phy_device *phydev, + unsigned int mode, + phy_interface_t interface, + int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + struct rtl8169_private *tp = container_of(config, + struct rtl8169_private, + phylink_config); + struct device *d = tp_to_dev(tp); + + tp->speed = speed; + rtl_link_chg_patch(tp, speed); + + /* + * Note: This hardware does not support forcing flow control. + * Tx/Rx pause is completely hardwired: if autoneg is ON, hardware + * handles it automatically based on PHY result; if autoneg is OFF, + * hardware forces pause to be disabled. No software override exists. + */ + pm_request_resume(d); +} + +static struct phylink_pcs *rtl_mac_select_pcs(struct phylink_config *config, + phy_interface_t interface) +{ + return NULL; +} + +static void rtl_mac_config(struct phylink_config *config, unsigned int mode, + const struct phylink_link_state *state) +{ +} + +static void rtl_mac_disable_tx_lpi(struct phylink_config *config) +{ + struct rtl8169_private *tp = container_of(config, + struct rtl8169_private, + phylink_config); + + rtl_enable_tx_lpi(tp, false); +} + +static int rtl_mac_enable_tx_lpi(struct phylink_config *config, + u32 timer, + bool tx_clk_stop) +{ + struct rtl8169_private *tp = container_of(config, + struct rtl8169_private, + phylink_config); + + rtl_enable_tx_lpi(tp, true); + + return 0; +} + +static const struct phylink_mac_ops rtl_phylink_mac_ops = { + .mac_select_pcs = rtl_mac_select_pcs, + .mac_config = rtl_mac_config, + .mac_link_down = rtl_mac_link_down, + .mac_link_up = rtl_mac_link_up, + .mac_disable_tx_lpi = rtl_mac_disable_tx_lpi, + .mac_enable_tx_lpi = rtl_mac_enable_tx_lpi, +}; + +static unsigned long rtl8169_get_lpi_caps(struct rtl8169_private *tp) +{ + unsigned long caps = 0; + + if (!rtl_supports_eee(tp)) + return 0; + + caps |= MAC_100FD | MAC_1000FD; + + /* mimic behavior of r8125/r8126 vendor drivers + * RTL_GIGA_MAC_VER_61 doesn't support 2.5G eee + */ + if (tp->mac_version >= RTL_GIGA_MAC_VER_63) + caps |= MAC_2500FD; + if (tp->mac_version >= RTL_GIGA_MAC_VER_70) + caps |= MAC_5000FD; + if (tp->mac_version == RTL_GIGA_MAC_VER_80) + caps |= MAC_10000FD; + + return caps; +} + +static int rtl_init_phylink(struct rtl8169_private *tp) +{ + struct phylink *pl; + phy_interface_t phy_mode; + + tp->phylink_config.dev = &tp->dev->dev; + tp->phylink_config.type = PHYLINK_NETDEV; + tp->phylink_config.mac_managed_pm = true; + tp->phylink_config.lpi_capabilities = rtl8169_get_lpi_caps(tp); + tp->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE; + + if (tp->sfp_mode) { + phy_mode = PHY_INTERFACE_MODE_INTERNAL; + tp->phylink_config.mac_capabilities |= MAC_10000FD; + } else { + tp->phylink_config.mac_capabilities |= MAC_10 | MAC_100; + + if (tp->mac_version == RTL_GIGA_MAC_VER_80) + tp->phylink_config.mac_capabilities |= MAC_1000FD | + MAC_2500FD | + MAC_5000FD | + MAC_10000FD; + else if (tp->mac_version == RTL_GIGA_MAC_VER_70) + tp->phylink_config.mac_capabilities |= MAC_1000FD | + MAC_2500FD | + MAC_5000FD; + else if (tp->mac_version >= RTL_GIGA_MAC_VER_61) + tp->phylink_config.mac_capabilities |= MAC_1000FD | + MAC_2500FD; + else + if (tp->supports_gmii) + tp->phylink_config.mac_capabilities |= MAC_1000FD; + + if (tp->mac_version < RTL_GIGA_MAC_VER_61) + phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : + PHY_INTERFACE_MODE_MII; + else + phy_mode = PHY_INTERFACE_MODE_INTERNAL; + } + + __set_bit(phy_mode, tp->phylink_config.supported_interfaces); + if (tp->phylink_config.lpi_capabilities) + __set_bit(phy_mode, tp->phylink_config.lpi_interfaces); + + pl = phylink_create(&tp->phylink_config, tp_to_dev(tp)->fwnode, + phy_mode, &rtl_phylink_mac_ops); + if (IS_ERR(pl)) + return PTR_ERR(pl); + + tp->phylink = pl; + + return 0; +} + static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { const struct rtl_chip_info *chip; @@ -5789,13 +5925,21 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_drvdata(pdev, tp); - rc = r8169_mdio_register(tp); + rc = rtl_init_phylink(tp); if (rc) return rc; - rc = register_netdev(dev); - if (rc) + rc = r8169_mdio_register(tp); + if (rc) { + phylink_destroy(tp->phylink); return rc; + } + + rc = register_netdev(dev); + if (rc) { + phylink_destroy(tp->phylink); + return rc; + } if (IS_ENABLED(CONFIG_R8169_LEDS)) { if (rtl_is_8125(tp)) From dab515216deff51b08c072850c4e21cc61a9471d Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:42 +0800 Subject: [PATCH 0182/2126] r8169: add support for RTL8116af RTL8116af is sfp mode. Phylink uses pcs to get the link status from its serdes reg, instead of standard phy reg. Speed and duplex are hardcoded to 1000Mbps Full-Duplex. Also, RTL8116af doesn't have internal phy, so we add some checks to ensure that tp->phydev is not empty when we need it. In rtl_hw_start_8117(), the MAC calibration for register 0xd412 relies on reading the internal PHY register 0x0c42. Since RTL8116af does not have an internal PHY, this calibration step is intentionally bypassed. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831053745.1197-5-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 192 ++++++++++++++++++---- 1 file changed, 158 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 823763e4f445..a04acb42e995 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -97,6 +97,18 @@ #define JUMBO_9K (9 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN) #define JUMBO_16K (SZ_16K - VLAN_ETH_HLEN - ETH_FCS_LEN) +#define OCP_SDS_ADDR_REG 0xeb10 +#define OCP_SDS_CMD_REG 0xeb0e +#define OCP_SDS_DATA_REG 0xeb14 +#define SDS_CMD_READ 0x0001 +#define RTL_SDS_C22_BASE 0x40 +#define RTL_PKG_DETECT 0xdc00 +#define RTL_PKG_DETECT_MASK 0x0078 +#define RTL_PKG_DETECT_8116AF 0x0030 +#define RTL_INT_HW_ID 0xd006 +#define RTL_INT_HW_ID_MASK 0x00ff +#define RTL_INT_HW_ID_8116AF 0x0000 + static const struct rtl_chip_info { u32 mask; u32 val; @@ -729,6 +741,12 @@ enum rtl_dash_type { RTL_DASH_25_BP, }; +enum rtl_sfp_mode { + RTL_SFP_NONE, + RTL_SFP_8168_AF, + RTL_SFP_8127_ATF, +}; + struct rtl8169_private { void __iomem *mmio_addr; /* memory map physical address */ struct pci_dev *pci_dev; @@ -737,6 +755,7 @@ struct rtl8169_private { struct napi_struct napi; enum mac_version mac_version; enum rtl_dash_type dash_type; + enum rtl_sfp_mode sfp_mode; u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ u32 dirty_tx; @@ -764,7 +783,6 @@ struct rtl8169_private { unsigned supports_gmii:1; unsigned aspm_manageable:1; unsigned dash_enabled:1; - bool sfp_mode:1; dma_addr_t counters_phys_addr; struct rtl8169_counters *counters; struct rtl8169_tc_offsets tc_offset; @@ -778,6 +796,7 @@ struct rtl8169_private { u32 ocp_base; struct phylink *phylink; struct phylink_config phylink_config; + struct phylink_pcs pcs; }; typedef void (*rtl_generic_fct)(struct rtl8169_private *tp); @@ -1133,7 +1152,8 @@ static int r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) return 0; /* Return dummy MII_PHYSID2 in SFP mode to match SFP PHY driver */ - if (tp->sfp_mode && reg == (OCP_STD_PHY_BASE + 2 * MII_PHYSID2)) + if (tp->sfp_mode == RTL_SFP_8127_ATF && + reg == (OCP_STD_PHY_BASE + 2 * MII_PHYSID2)) return PHY_ID_RTL_DUMMY_SFP & 0xffff; RTL_W32(tp, GPHY_OCP, reg << 15); @@ -1287,6 +1307,15 @@ static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); } +static bool rtl_is_8116af(struct rtl8169_private *tp) +{ + return tp->mac_version == RTL_GIGA_MAC_VER_52 && + (r8168_mac_ocp_read(tp, RTL_PKG_DETECT) & RTL_PKG_DETECT_MASK) == + RTL_PKG_DETECT_8116AF && + (r8168_mac_ocp_read(tp, RTL_INT_HW_ID) & RTL_INT_HW_ID_MASK) == + RTL_INT_HW_ID_8116AF; +} + static int mac_mcu_read(struct rtl8169_private *tp, int reg) { return r8168_mac_ocp_read(tp, tp->ocp_base + reg); @@ -1582,6 +1611,20 @@ static bool rtl_dash_is_enabled(struct rtl8169_private *tp) } } +static enum rtl_sfp_mode rtl_get_sfp_mode(struct rtl8169_private *tp) +{ + if (rtl_is_8125(tp)) { + u16 data = r8168_mac_ocp_read(tp, RTL_INT_HW_ID); + + if ((data & 0xff) == 0x07) + return RTL_SFP_8127_ATF; + } else if (rtl_is_8116af(tp)) { + return RTL_SFP_8168_AF; + } + + return RTL_SFP_NONE; +} + static enum rtl_dash_type rtl_get_dash_type(struct rtl8169_private *tp) { switch (tp->mac_version) { @@ -2397,7 +2440,7 @@ static int rtl8169_set_link_ksettings(struct net_device *ndev, int duplex = cmd->base.duplex; int speed = cmd->base.speed; - if (!tp->sfp_mode) + if (tp->sfp_mode != RTL_SFP_8127_ATF) return phylink_ethtool_ksettings_set(tp->phylink, cmd); if (cmd->base.autoneg != AUTONEG_DISABLE) @@ -2509,9 +2552,10 @@ void r8169_apply_firmware(struct rtl8169_private *tp) tp->ocp_base = OCP_STD_PHY_BASE; /* PHY soft reset may still be in progress */ - phy_read_poll_timeout(tp->phydev, MII_BMCR, val, - !(val & BMCR_RESET), - 50000, 600000, true); + if (tp->phydev) + phy_read_poll_timeout(tp->phydev, MII_BMCR, val, + !(val & BMCR_RESET), + 50000, 600000, true); } } @@ -2548,6 +2592,8 @@ static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) static void rtl8169_init_phy(struct rtl8169_private *tp) { + phy_init_hw(tp->phydev); + phy_resume(tp->phydev); r8169_hw_phy_config(tp, tp->phydev, tp->mac_version); if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { @@ -2562,7 +2608,7 @@ static void rtl8169_init_phy(struct rtl8169_private *tp) tp->pci_dev->subsystem_device == 0xe000) phy_write_paged(tp->phydev, 0x0001, 0x10, 0xf01b); - if (tp->sfp_mode) + if (tp->sfp_mode == RTL_SFP_8127_ATF) rtl_sfp_init(tp); /* We may have called phy_speed_down before */ @@ -3704,12 +3750,14 @@ static void rtl_hw_start_8117(struct rtl8169_private *tp) rtl_pcie_state_l2l3_disable(tp); - rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff; - if (rg_saw_cnt > 0) { - u16 sw_cnt_1ms_ini; + if (tp->phydev) { + rg_saw_cnt = phy_read_paged(tp->phydev, 0x0c42, 0x13) & 0x3fff; + if (rg_saw_cnt > 0) { + u16 sw_cnt_1ms_ini; - sw_cnt_1ms_ini = (16000000 / rg_saw_cnt) & 0x0fff; - r8168_mac_ocp_modify(tp, 0xd412, 0x0fff, sw_cnt_1ms_ini); + sw_cnt_1ms_ini = (16000000 / rg_saw_cnt) & 0x0fff; + r8168_mac_ocp_modify(tp, 0xd412, 0x0fff, sw_cnt_1ms_ini); + } } r8168_mac_ocp_modify(tp, 0xe056, 0x00f0, 0x0000); @@ -4891,8 +4939,13 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) goto out; } - if (status & LinkChg) - phy_mac_interrupt(tp->phydev); + if (status & LinkChg) { + if (tp->phydev) + phy_mac_interrupt(tp->phydev); + else if (tp->sfp_mode == RTL_SFP_8168_AF) + phylink_mac_change(tp->phylink, + !!(RTL_R8(tp, PHYstatus) & LinkStatus)); + } rtl_irq_disable(tp); napi_schedule(&tp->napi); @@ -5002,7 +5055,7 @@ static void rtl8169_down(struct rtl8169_private *tp) bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); /* Reset SerDes PHY to bring down fiber link */ - if (tp->sfp_mode) + if (tp->sfp_mode == RTL_SFP_8127_ATF) rtl_sfp_reset(tp); rtl8169_update_counters(tp); @@ -5024,9 +5077,9 @@ static void rtl8169_up(struct rtl8169_private *tp) rtl8168_driver_start(tp); pci_set_master(tp->pci_dev); - phy_init_hw(tp->phydev); - phy_resume(tp->phydev); - rtl8169_init_phy(tp); + if (tp->phydev) + rtl8169_init_phy(tp); + napi_enable(&tp->napi); enable_work(&tp->wk.work); rtl_reset_work(tp); @@ -5103,10 +5156,11 @@ static int rtl_open(struct net_device *dev) if (retval < 0) goto err_release_fw_2; - retval = r8169_phy_connect(tp); - if (retval) - goto err_free_irq; - + if (tp->phydev) { + retval = r8169_phy_connect(tp); + if (retval) + goto err_free_irq; + } rtl8169_up(tp); phylink_start(tp->phylink); rtl8169_init_counter_offsets(tp); @@ -5620,6 +5674,16 @@ static void rtl_mac_link_up(struct phylink_config *config, static struct phylink_pcs *rtl_mac_select_pcs(struct phylink_config *config, phy_interface_t interface) { + struct rtl8169_private *tp = container_of(config, + struct rtl8169_private, + phylink_config); + + if (!tp->pcs.ops) + return NULL; + + if (interface == PHY_INTERFACE_MODE_1000BASEX) + return &tp->pcs; + return NULL; } @@ -5628,6 +5692,53 @@ static void rtl_mac_config(struct phylink_config *config, unsigned int mode, { } +static u16 rtl8169_sds_read(struct rtl8169_private *tp, u16 sds_reg) +{ + unsigned long flags; + u16 val = 0; + + raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags); + __r8168_mac_ocp_write(tp, OCP_SDS_ADDR_REG, sds_reg); + __r8168_mac_ocp_write(tp, OCP_SDS_CMD_REG, SDS_CMD_READ); + val = __r8168_mac_ocp_read(tp, OCP_SDS_DATA_REG); + raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags); + + return val; +} + +static void rtl8169_pcs_get_state(struct phylink_pcs *pcs, + unsigned int neg_mode, + struct phylink_link_state *state) +{ + struct rtl8169_private *tp = container_of(pcs, struct rtl8169_private, + pcs); + u16 bmsr, lpa; + + bmsr = rtl8169_sds_read(tp, RTL_SDS_C22_BASE + MII_BMSR); + lpa = rtl8169_sds_read(tp, RTL_SDS_C22_BASE + MII_LPA); + + phylink_mii_c22_pcs_decode_state(state, neg_mode, bmsr, lpa); +} + +static int rtl8169_pcs_config(struct phylink_pcs *pcs, unsigned int mode, + phy_interface_t interface, + const unsigned long *advertising, + bool permit_pause_to_mac) +{ + return 0; +} + +static int rtl8169_pcs_validate(struct phylink_pcs *pcs, + unsigned long *supported, + const struct phylink_link_state *state) +{ + return 0; +} + +static void rtl8169_pcs_an_restart(struct phylink_pcs *pcs) +{ +} + static void rtl_mac_disable_tx_lpi(struct phylink_config *config) { struct rtl8169_private *tp = container_of(config, @@ -5681,6 +5792,13 @@ static unsigned long rtl8169_get_lpi_caps(struct rtl8169_private *tp) return caps; } +static const struct phylink_pcs_ops r8169_pcs_ops = { + .pcs_validate = rtl8169_pcs_validate, + .pcs_get_state = rtl8169_pcs_get_state, + .pcs_config = rtl8169_pcs_config, + .pcs_an_restart = rtl8169_pcs_an_restart, +}; + static int rtl_init_phylink(struct rtl8169_private *tp) { struct phylink *pl; @@ -5692,10 +5810,18 @@ static int rtl_init_phylink(struct rtl8169_private *tp) tp->phylink_config.lpi_capabilities = rtl8169_get_lpi_caps(tp); tp->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE; - if (tp->sfp_mode) { + switch (tp->sfp_mode) { + case RTL_SFP_8168_AF: + tp->pcs.ops = &r8169_pcs_ops; + tp->phylink_config.default_an_inband = true; + phy_mode = PHY_INTERFACE_MODE_1000BASEX; + tp->phylink_config.mac_capabilities |= MAC_1000FD; + break; + case RTL_SFP_8127_ATF: phy_mode = PHY_INTERFACE_MODE_INTERNAL; tp->phylink_config.mac_capabilities |= MAC_10000FD; - } else { + break; + default: tp->phylink_config.mac_capabilities |= MAC_10 | MAC_100; if (tp->mac_version == RTL_GIGA_MAC_VER_80) @@ -5719,6 +5845,7 @@ static int rtl_init_phylink(struct rtl8169_private *tp) PHY_INTERFACE_MODE_MII; else phy_mode = PHY_INTERFACE_MODE_INTERNAL; + break; } __set_bit(phy_mode, tp->phylink_config.supported_interfaces); @@ -5816,12 +5943,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) } tp->aspm_manageable = !rc; - if (rtl_is_8125(tp)) { - u16 data = r8168_mac_ocp_read(tp, 0xd006); - - if ((data & 0xff) == 0x07) - tp->sfp_mode = true; - } + tp->sfp_mode = rtl_get_sfp_mode(tp); tp->dash_type = rtl_get_dash_type(tp); tp->dash_enabled = rtl_dash_is_enabled(tp); @@ -5929,10 +6051,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - rc = r8169_mdio_register(tp); - if (rc) { - phylink_destroy(tp->phylink); - return rc; + if (tp->sfp_mode != RTL_SFP_8168_AF) { + rc = r8169_mdio_register(tp); + if (rc) { + phylink_destroy(tp->phylink); + return rc; + } } rc = register_netdev(dev); From 97dee72abc37c66de7647439f20f3147a63b409a Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:43 +0800 Subject: [PATCH 0183/2126] r8169: add support for RTL8127atf RTL8127atf is also a fiber mode card, but its sds reg base addr is 0x0080, which is different from RTL8116af. Add 10g and 1g support for RTL8127atf in this patch. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831053745.1197-6-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 180 ++++++++++++++++------ drivers/net/phy/realtek/realtek_main.c | 54 ------- include/net/phy/realtek_phy.h | 7 - 3 files changed, 132 insertions(+), 109 deletions(-) delete mode 100644 include/net/phy/realtek_phy.h diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index a04acb42e995..eecde26d9de2 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "r8169.h" #include "r8169_firmware.h" @@ -97,11 +96,18 @@ #define JUMBO_9K (9 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN) #define JUMBO_16K (SZ_16K - VLAN_ETH_HLEN - ETH_FCS_LEN) +#define R8127_SDS_CMD 0x2348 +#define R8127_SDS_ADDR 0x234a +#define R8127_SDS_DATA_IN 0x234c +#define R8127_SDS_DATA_OUT 0x234e +#define R8127_SDS_CMD_EXEC BIT(0) +#define R8127_SDS_CMD_WE BIT(1) #define OCP_SDS_ADDR_REG 0xeb10 #define OCP_SDS_CMD_REG 0xeb0e #define OCP_SDS_DATA_REG 0xeb14 #define SDS_CMD_READ 0x0001 #define RTL_SDS_C22_BASE 0x40 +#define RTL_SDS_C45_BASE 0x0080 #define RTL_PKG_DETECT 0xdc00 #define RTL_PKG_DETECT_MASK 0x0078 #define RTL_PKG_DETECT_8116AF 0x0030 @@ -1151,11 +1157,6 @@ static int r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) if (rtl_ocp_reg_failure(reg)) return 0; - /* Return dummy MII_PHYSID2 in SFP mode to match SFP PHY driver */ - if (tp->sfp_mode == RTL_SFP_8127_ATF && - reg == (OCP_STD_PHY_BASE + 2 * MII_PHYSID2)) - return PHY_ID_RTL_DUMMY_SFP & 0xffff; - RTL_W32(tp, GPHY_OCP, reg << 15); return rtl_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? @@ -1223,6 +1224,75 @@ static void r8127_sfp_sds_phy_reset(struct rtl8169_private *tp) usleep_range(10, 20); } +DECLARE_RTL_COND(r8127_sds_cmd_cond) +{ + return RTL_R16(tp, R8127_SDS_CMD) & R8127_SDS_CMD_EXEC; +} + +static int r8127_sds_read(struct rtl8169_private *tp, u16 index, + u16 page, u16 reg) +{ + u16 addr = (index << 11) | (page << 5) | reg; + + RTL_W16(tp, R8127_SDS_ADDR, addr); + RTL_W16(tp, R8127_SDS_CMD, R8127_SDS_CMD_EXEC); + + if (rtl_loop_wait_low(tp, &r8127_sds_cmd_cond, 10, 100)) + return RTL_R16(tp, R8127_SDS_DATA_OUT); + + return -ETIMEDOUT; +} + +static int r8127_sds_write(struct rtl8169_private *tp, u16 index, u16 page, + u16 reg, u16 val) +{ + u16 addr = (index << 11) | (page << 5) | reg; + + RTL_W16(tp, R8127_SDS_DATA_IN, val); + RTL_W16(tp, R8127_SDS_ADDR, addr); + RTL_W16(tp, R8127_SDS_CMD, R8127_SDS_CMD_EXEC | R8127_SDS_CMD_WE); + + if (rtl_loop_wait_low(tp, &r8127_sds_cmd_cond, 10, 100)) + return 0; + + return -ETIMEDOUT; +} + +static void r8127_sds_modify(struct rtl8169_private *tp, u16 index, u16 page, + u16 reg, u16 clearmask, u16 setmask) +{ + int val = r8127_sds_read(tp, index, page, reg); + + if (val < 0) + return; + + val = (val & ~clearmask) | setmask; + r8127_sds_write(tp, index, page, reg, val); +} + +static void r8127_sfp_init_1g(struct rtl8169_private *tp) +{ + int val; + + r8127_sfp_sds_phy_reset(tp); + + r8127_sds_modify(tp, 0, 1, 31, 0, BIT(3)); + r8127_sds_modify(tp, 0, 2, 0, BIT(13) | BIT(12) | BIT(6), + BIT(12) | BIT(6)); + r8127_sds_modify(tp, 0, 0, 4, 0, BIT(2)); + + RTL_W16(tp, 0x233a, 0x8004); + RTL_W16(tp, 0x233e, (RTL_R16(tp, 0x233e) & ~0x3003) | 0x0002); + + r8168_phy_ocp_write(tp, 0xc40a, 0x0000); + r8168_phy_ocp_write(tp, 0xc466, 0x0000); + r8168_phy_ocp_write(tp, 0xc808, 0x0000); + r8168_phy_ocp_write(tp, 0xc80a, 0x0000); + + val = r8168_phy_ocp_read(tp, 0xc804); + r8168_phy_ocp_write(tp, 0xc804, (val & ~0x000f) | 0x000c); +} + static void r8127_sfp_init_10g(struct rtl8169_private *tp) { int val; @@ -1241,12 +1311,6 @@ static void r8127_sfp_init_10g(struct rtl8169_private *tp) r8168_phy_ocp_write(tp, 0xc804, (val & ~0x000f) | 0x000c); } -static void rtl_sfp_init(struct rtl8169_private *tp) -{ - if (tp->mac_version == RTL_GIGA_MAC_VER_80) - r8127_sfp_init_10g(tp); -} - static void rtl_sfp_reset(struct rtl8169_private *tp) { if (tp->mac_version == RTL_GIGA_MAC_VER_80) @@ -2436,30 +2500,8 @@ static int rtl8169_set_link_ksettings(struct net_device *ndev, const struct ethtool_link_ksettings *cmd) { struct rtl8169_private *tp = netdev_priv(ndev); - struct phy_device *phydev = tp->phydev; - int duplex = cmd->base.duplex; - int speed = cmd->base.speed; - if (tp->sfp_mode != RTL_SFP_8127_ATF) - return phylink_ethtool_ksettings_set(tp->phylink, cmd); - - if (cmd->base.autoneg != AUTONEG_DISABLE) - return -EINVAL; - - if (!phy_check_valid(speed, duplex, phydev->supported)) - return -EINVAL; - - mutex_lock(&phydev->lock); - - phydev->autoneg = AUTONEG_DISABLE; - phydev->speed = speed; - phydev->duplex = duplex; - - rtl_sfp_init(tp); - - mutex_unlock(&phydev->lock); - - return 0; + return phylink_ethtool_ksettings_set(tp->phylink, cmd); } static int rtl8169_nway_reset(struct net_device *dev) @@ -2608,9 +2650,6 @@ static void rtl8169_init_phy(struct rtl8169_private *tp) tp->pci_dev->subsystem_device == 0xe000) phy_write_paged(tp->phydev, 0x0001, 0x10, 0xf01b); - if (tp->sfp_mode == RTL_SFP_8127_ATF) - rtl_sfp_init(tp); - /* We may have called phy_speed_down before */ phy_speed_up(tp->phydev); @@ -4942,7 +4981,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) if (status & LinkChg) { if (tp->phydev) phy_mac_interrupt(tp->phydev); - else if (tp->sfp_mode == RTL_SFP_8168_AF) + else if (tp->sfp_mode) phylink_mac_change(tp->phylink, !!(RTL_R8(tp, PHYstatus) & LinkStatus)); } @@ -5681,7 +5720,8 @@ static struct phylink_pcs *rtl_mac_select_pcs(struct phylink_config *config, if (!tp->pcs.ops) return NULL; - if (interface == PHY_INTERFACE_MODE_1000BASEX) + if (interface == PHY_INTERFACE_MODE_1000BASEX || + interface == PHY_INTERFACE_MODE_10GBASER) return &tp->pcs; return NULL; @@ -5712,12 +5752,32 @@ static void rtl8169_pcs_get_state(struct phylink_pcs *pcs, { struct rtl8169_private *tp = container_of(pcs, struct rtl8169_private, pcs); - u16 bmsr, lpa; - bmsr = rtl8169_sds_read(tp, RTL_SDS_C22_BASE + MII_BMSR); - lpa = rtl8169_sds_read(tp, RTL_SDS_C22_BASE + MII_LPA); + if (tp->sfp_mode == RTL_SFP_8127_ATF) { + u16 stat1; - phylink_mii_c22_pcs_decode_state(state, neg_mode, bmsr, lpa); + stat1 = rtl8169_sds_read(tp, RTL_SDS_C45_BASE + MDIO_STAT1); + + if (!(stat1 & MDIO_STAT1_LSTATUS)) + stat1 = rtl8169_sds_read(tp, RTL_SDS_C45_BASE + MDIO_STAT1); + + state->link = !!(stat1 & MDIO_STAT1_LSTATUS); + if (!state->link) + return; + + if (state->interface == PHY_INTERFACE_MODE_1000BASEX) + state->speed = SPEED_1000; + else + state->speed = SPEED_10000; + + state->duplex = DUPLEX_FULL; + } else { + u16 bmsr, lpa; + + bmsr = rtl8169_sds_read(tp, RTL_SDS_C22_BASE + MII_BMSR); + lpa = rtl8169_sds_read(tp, RTL_SDS_C22_BASE + MII_LPA); + phylink_mii_c22_pcs_decode_state(state, neg_mode, bmsr, lpa); + } } static int rtl8169_pcs_config(struct phylink_pcs *pcs, unsigned int mode, @@ -5725,6 +5785,24 @@ static int rtl8169_pcs_config(struct phylink_pcs *pcs, unsigned int mode, const unsigned long *advertising, bool permit_pause_to_mac) { + struct rtl8169_private *tp = container_of(pcs, struct rtl8169_private, + pcs); + + if (tp->sfp_mode == RTL_SFP_8127_ATF) { + switch (interface) { + case PHY_INTERFACE_MODE_10GBASER: + r8127_sfp_init_10g(tp); + break; + case PHY_INTERFACE_MODE_1000BASEX: + r8127_sfp_init_1g(tp); + break; + default: + netdev_err(tp->dev, "Unsupported SFP interface mode: %s\n", + phy_modes(interface)); + return -EOPNOTSUPP; + } + } + return 0; } @@ -5774,7 +5852,7 @@ static unsigned long rtl8169_get_lpi_caps(struct rtl8169_private *tp) { unsigned long caps = 0; - if (!rtl_supports_eee(tp)) + if (!rtl_supports_eee(tp) || tp->sfp_mode == RTL_SFP_8127_ATF) return 0; caps |= MAC_100FD | MAC_1000FD; @@ -5818,8 +5896,14 @@ static int rtl_init_phylink(struct rtl8169_private *tp) tp->phylink_config.mac_capabilities |= MAC_1000FD; break; case RTL_SFP_8127_ATF: - phy_mode = PHY_INTERFACE_MODE_INTERNAL; - tp->phylink_config.mac_capabilities |= MAC_10000FD; + tp->pcs.ops = &r8169_pcs_ops; + phy_mode = PHY_INTERFACE_MODE_10GBASER; + tp->phylink_config.default_an_inband = true; + tp->phylink_config.mac_capabilities |= MAC_1000FD | MAC_10000FD; + __set_bit(PHY_INTERFACE_MODE_10GBASER, + tp->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + tp->phylink_config.supported_interfaces); break; default: tp->phylink_config.mac_capabilities |= MAC_10 | MAC_100; @@ -6051,7 +6135,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - if (tp->sfp_mode != RTL_SFP_8168_AF) { + if (tp->sfp_mode == RTL_SFP_NONE) { rc = r8169_mdio_register(tp); if (rc) { phylink_destroy(tp->phylink); diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 177b62a7b2d1..27e31a799e2c 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -19,7 +19,6 @@ #include #include #include -#include #include "../phylib.h" #include "realtek.h" @@ -3044,45 +3043,6 @@ static irqreturn_t rtl8221b_handle_interrupt(struct phy_device *phydev) return IRQ_HANDLED; } -static int rtlgen_sfp_get_features(struct phy_device *phydev) -{ - linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, - phydev->supported); - - /* set default mode */ - phydev->speed = SPEED_10000; - phydev->duplex = DUPLEX_FULL; - - phydev->port = PORT_FIBRE; - - return 0; -} - -static int rtlgen_sfp_read_status(struct phy_device *phydev) -{ - int val, err; - - err = genphy_update_link(phydev); - if (err) - return err; - - if (!phydev->link) - return 0; - - val = phy_read(phydev, RTL_PHYSR); - if (val < 0) - return val; - - rtlgen_decode_physr(phydev, val); - - return 0; -} - -static int rtlgen_sfp_config_aneg(struct phy_device *phydev) -{ - return 0; -} - static struct phy_driver realtek_drvs[] = { { PHY_ID_MATCH_EXACT(0x00008201), @@ -3332,20 +3292,6 @@ static struct phy_driver realtek_drvs[] = { .write_page = rtl821x_write_page, .read_mmd = rtl822x_read_mmd, .write_mmd = rtl822x_write_mmd, - }, { - PHY_ID_MATCH_EXACT(PHY_ID_RTL_DUMMY_SFP), - .name = "Realtek SFP PHY Mode", - .flags = PHY_IS_INTERNAL, - .probe = rtl822x_probe, - .get_features = rtlgen_sfp_get_features, - .config_aneg = rtlgen_sfp_config_aneg, - .read_status = rtlgen_sfp_read_status, - .suspend = genphy_suspend, - .resume = rtlgen_resume, - .read_page = rtl821x_read_page, - .write_page = rtl821x_write_page, - .read_mmd = rtl822x_read_mmd, - .write_mmd = rtl822x_write_mmd, }, { PHY_ID_MATCH_EXACT(0x001ccad0), .name = "RTL8224 2.5Gbps PHY", diff --git a/include/net/phy/realtek_phy.h b/include/net/phy/realtek_phy.h deleted file mode 100644 index d683bc1b0659..000000000000 --- a/include/net/phy/realtek_phy.h +++ /dev/null @@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _REALTEK_PHY_H -#define _REALTEK_PHY_H - -#define PHY_ID_RTL_DUMMY_SFP 0x001ccbff - -#endif /* _REALTEK_PHY_H */ From 6e445f3d9538f1e6c25f77a46dfbef08a4334422 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:44 +0800 Subject: [PATCH 0184/2126] r8169: add ltr support for RTL8117 series This patch adds ltr support for RTL8117 series, enables RTL8117 series enter l1.2 state. This makes sense for the system to enter c10 state. This patch drops the COMBO_LTR_EXTEND_EN write for VER_52. This is intentional, as this bit is not required for RTL8116af. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831053745.1197-7-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index eecde26d9de2..5dbbc3a48c09 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -353,11 +353,13 @@ enum rtl_registers { ALDPS_LTR = 0xe0a2, LTR_OBFF_LOCK = 0xe032, LTR_SNOOP = 0xe034, + SEND_LTR_MSG = 0xe038, #define ALDPS_LTR_EN BIT(0) #define LTR_OBFF_LOCK_EN BIT(0) #define LINK_SPEED_CHANGE_EN BIT(14) #define LTR_SNOOP_EN GENMASK(15, 14) +#define LTR_MSG_EN BIT(0) }; enum rtl8168_8101_registers { @@ -3194,8 +3196,23 @@ static void rtl_enable_ltr(struct rtl8169_private *tp) r8168_mac_ocp_write(tp, 0xcdf2, 0x9003); r8168_mac_ocp_modify(tp, LTR_OBFF_LOCK, 0x0000, LINK_SPEED_CHANGE_EN); break; - case RTL_GIGA_MAC_VER_46 ... RTL_GIGA_MAC_VER_48: case RTL_GIGA_MAC_VER_52: + r8168_mac_ocp_write(tp, 0xcdd0, 0x9003); + r8168_mac_ocp_modify(tp, LTR_SNOOP, 0x0000, LTR_SNOOP_EN); + r8168_mac_ocp_write(tp, 0xe02c, 0x1880); + r8168_mac_ocp_write(tp, 0xe02e, 0x4880); + r8168_mac_ocp_modify(tp, ALDPS_LTR, 0x0000, ALDPS_LTR_EN); + r8168_mac_ocp_write(tp, 0xcdd8, 0x9003); + r8168_mac_ocp_write(tp, 0xcdda, 0x9003); + r8168_mac_ocp_write(tp, 0xcddc, 0x9003); + r8168_mac_ocp_write(tp, 0xcdd2, 0x883c); + r8168_mac_ocp_write(tp, 0xcdd4, 0x8c12); + r8168_mac_ocp_write(tp, 0xcdd6, 0x9003); + r8168_mac_ocp_write(tp, 0xe0a6, 0x9003); + r8168_mac_ocp_write(tp, 0xe0a8, 0x9003); + r8168_mac_ocp_modify(tp, LTR_OBFF_LOCK, 0x0000, LINK_SPEED_CHANGE_EN); + break; + case RTL_GIGA_MAC_VER_46 ... RTL_GIGA_MAC_VER_48: r8168_mac_ocp_modify(tp, ALDPS_LTR, 0x0000, ALDPS_LTR_EN); RTL_W8(tp, COMBO_LTR_EXTEND, RTL_R8(tp, COMBO_LTR_EXTEND) | COMBO_LTR_EXTEND_EN); fallthrough; @@ -3215,6 +3232,7 @@ static void rtl_enable_ltr(struct rtl8169_private *tp) } /* chip can trigger LTR */ r8168_mac_ocp_modify(tp, LTR_OBFF_LOCK, 0x0003, LTR_OBFF_LOCK_EN); + r8168_mac_ocp_modify(tp, SEND_LTR_MSG, 0x0000, LTR_MSG_EN); } static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) @@ -3248,6 +3266,7 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) rtl_enable_ltr(tp); switch (tp->mac_version) { case RTL_GIGA_MAC_VER_46 ... RTL_GIGA_MAC_VER_48: + case RTL_GIGA_MAC_VER_52: case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_LAST: /* reset ephy tx/rx disable timer */ r8168_mac_ocp_modify(tp, 0xe094, 0xff00, 0); @@ -3260,6 +3279,7 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) } else { switch (tp->mac_version) { case RTL_GIGA_MAC_VER_46 ... RTL_GIGA_MAC_VER_48: + case RTL_GIGA_MAC_VER_52: case RTL_GIGA_MAC_VER_61 ... RTL_GIGA_MAC_VER_LAST: r8168_mac_ocp_modify(tp, 0xe092, 0x00ff, 0); break; From a306cbd79e07b4b345cd75c690d63fcca65613a5 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Mon, 31 Aug 2026 13:37:45 +0800 Subject: [PATCH 0185/2126] r8169: fix RTL8116af can not enter s0idle and c10 RTL8116AF is a multi-function device. Functions 2 to 7 are hidden from the PCI core and return an all-ones response when their vendor ID is read, so they are not enumerated as normal PCI functions. However, these hidden functions can still affect platform power management. If they are left in D0 or keep ASPM disabled, the platform may fail to enter the low-power s0ix state and the CPU package may fail to enter Package C10. Put functions 2 to 7 into D3hot and enable ASPM on their PCIe link control register. Since these functions are hidden, access their configuration space through pci_bus_read_config_dword() / pci_bus_write_config_dword() using the same slot and the target function numbers. Ignore functions that return a PCI error response when reading their configuration space. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260831053745.1197-8-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 5dbbc3a48c09..5415ff62a286 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -114,6 +114,7 @@ #define RTL_INT_HW_ID 0xd006 #define RTL_INT_HW_ID_MASK 0x00ff #define RTL_INT_HW_ID_8116AF 0x0000 +#define RTL_PM_CTRL_D3HOT 0x03 static const struct rtl_chip_info { u32 mask; @@ -3773,6 +3774,41 @@ static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) r8168_mac_ocp_modify(tp, 0xe860, 0x0000, 0x0080); } +static void rtl_lowpower_hidden_functions(struct pci_dev *pdev) +{ + unsigned int slot = PCI_SLOT(pdev->devfn); + struct pci_bus *bus = pdev->bus; + int func, pos; + u16 val; + + for (func = 2; func < 8; func++) { + unsigned int devfn = PCI_DEVFN(slot, func); + + pos = pci_bus_find_capability(bus, devfn, PCI_CAP_ID_EXP); + if (pos) { + pci_bus_read_config_word(bus, devfn, pos + PCI_EXP_LNKCTL, &val); + + if (PCI_POSSIBLE_ERROR(val)) + continue; + + val |= (PCI_EXP_LNKCTL_ASPMC | PCI_EXP_LNKCTL_CLKREQ_EN); + pci_bus_write_config_word(bus, devfn, pos + PCI_EXP_LNKCTL, val); + } + + pos = pci_bus_find_capability(bus, devfn, PCI_CAP_ID_PM); + if (pos) { + pci_bus_read_config_word(bus, devfn, pos + PCI_PM_CTRL, &val); + + if (PCI_POSSIBLE_ERROR(val)) + continue; + + val &= ~PCI_PM_CTRL_STATE_MASK; + val |= (RTL_PM_CTRL_D3HOT | PCI_PM_CTRL_PME_STATUS); + pci_bus_write_config_word(bus, devfn, pos + PCI_PM_CTRL, val); + } + } +} + static void rtl_hw_start_8117(struct rtl8169_private *tp) { static const struct ephy_info e_info_8117[] = { @@ -5326,6 +5362,9 @@ static int rtl8169_resume(struct device *device) /* Some chip versions may truncate packets without this initialization */ rtl_init_rxcfg(tp); + if (rtl_is_8116af(tp)) + rtl_lowpower_hidden_functions(tp->pci_dev); + return rtl8169_runtime_resume(device); } @@ -6190,6 +6229,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) rtl8168_driver_start(tp); } + if (rtl_is_8116af(tp)) + rtl_lowpower_hidden_functions(tp->pci_dev); + if (pci_dev_run_wake(pdev)) pm_runtime_put_sync(&pdev->dev); From cc9bccbad049ec9f1ffa377df60757243ceff2da Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:42 +0000 Subject: [PATCH 0186/2126] selftest: net: Deflake Periodic GC test in test_neigh.sh. test_neigh.sh has a test case to check if GC is running periodically. It applies a new value to BASE_REACHABLE_TIME, waits for half of the old value (+2s) to ensure the config is reflected, and waits for BASE_REACHABLE_TIME to see if the next GC is triggered. orig_base_reachable=$(ip -j ntable show name "$tbl_name" | jq '.[] | \ select(has("thresh1")) | .["base_reachable"]') run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable 10000" run_cmd "sleep $(((orig_base_reachable / 1000) / 2 + 2))" This is because neigh_periodic_work() schedules the next GC with (BASE_REACHABLE_TIME / 2) seconds: queue_delayed_work(system_power_efficient_wq, &tbl->gc_work, NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1); However, the very first run is scheduled with a longer period in neigh_table_init(), which will be up to 45s: neigh_set_reach_time(&tbl->parms); queue_delayed_work(system_power_efficient_wq, &tbl->gc_work, tbl->parms.reachable_time); The initial value is randomly chosen, so if it is larger than 27s (larger than two "sleep"s), the test fails. The test fails more frequently when neigh_table is namespacified by the later patch. In addition, the long "sleep" makes the test more flaky on kernel with CONFIG_NO_HZ_IDLE=y, which is enabled by defconfig. The tbl->gc_work is initialised with INIT_DEFERRABLE_WORK() and queued to system_power_efficient_wq. Even when the next GC is supposed to be triggered 5s later, "sleep" makes the CPU idle, delaying GC execution until often 20s later, which is too late. Let's take the initial tbl->parms.reachable_time into account and poll periodic_gc_runs every 0.1s up to the proper timeout, not to make CPU idle. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-2-kuniyu@google.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/test_neigh.sh | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/net/test_neigh.sh b/tools/testing/selftests/net/test_neigh.sh index 7c594bf6ead0..447423713266 100755 --- a/tools/testing/selftests/net/test_neigh.sh +++ b/tools/testing/selftests/net/test_neigh.sh @@ -63,6 +63,15 @@ exit_cleanup_all() exit "${EXIT_STATUS}" } +get_periodic_gc_runs() +{ + local ns=$1 + local tbl_name=$2 + + ip -n "$ns" -j -s ntable show name "$tbl_name" | \ + jq '.[] | select(has("periodic_gc_runs")) | .["periodic_gc_runs"]' +} + ################################################################################ # Tests @@ -282,24 +291,30 @@ extern_valid_common() local periodic_gc_runs_t0 local periodic_gc_runs_t1 local orig_base_reachable + local base_reachable=10000 local orig_gc_stale + local timeout run_cmd "ip -n $ns1 neigh flush dev veth0" orig_thresh1=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["thresh1"]') orig_base_reachable=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["base_reachable"]') - run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable 10000" + run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable $base_reachable" orig_gc_stale=$(ip -n "$ns1" -j ntable show name "$tbl_name" dev veth0 | jq '.[]["gc_stale"]') run_cmd "ip -n $ns1 ntable change name $tbl_name dev veth0 gc_stale 1000" run_cmd "ip -n $ns1 neigh add $ip_addr lladdr $mac nud stale dev veth0 extern_valid" run_cmd "ip -n $ns1 neigh add ${subnet}3 lladdr $mac nud stale dev veth0" - # Wait orig_base_reachable/2 for the new interval to take effect. - run_cmd "sleep $(((orig_base_reachable / 1000) / 2 + 2))" + # Wait up to neigh_set_reach_time(BASE_REACHABLE_TIME) (~45s) + 5s + # for the new interval to take effect, see neigh_table_init(). + timeout=$(((orig_base_reachable / 1000) * 3 / 2 + 5)) + slowwait_for_counter "$timeout" 1 get_periodic_gc_runs "$ns1" "$tbl_name" >/dev/null for i in {1..20}; do run_cmd "ip -n $ns1 neigh add ${subnet}$((i + 4)) nud none dev veth0" done - periodic_gc_runs_t0=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("periodic_gc_runs")) | .["periodic_gc_runs"]') - run_cmd "sleep 10" - periodic_gc_runs_t1=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("periodic_gc_runs")) | .["periodic_gc_runs"]') + periodic_gc_runs_t0=$(get_periodic_gc_runs "$ns1" "$tbl_name") + # Wait up to BASE_REACHABLE_TIME / 2 + 5s, see neigh_periodic_work(). + timeout=$(((base_reachable / 1000) / 2 + 5)) + slowwait_for_counter "$timeout" 1 get_periodic_gc_runs "$ns1" "$tbl_name" >/dev/null + periodic_gc_runs_t1=$(get_periodic_gc_runs "$ns1" "$tbl_name") [[ $periodic_gc_runs_t1 -ne $periodic_gc_runs_t0 ]] check_err $? "Periodic garbage collection did not run" run_cmd "ip -n $ns1 neigh get $ip_addr dev veth0 | grep \"extern_valid\"" From 985f6522d856d70a4625fe07980fccf822ecbe4b Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:43 +0000 Subject: [PATCH 0187/2126] neighbour: Remove __neigh_for_each_release(). Since commit 6deb53595092 ("net: remove unused ATM protocols and legacy ATM device drivers"), there is no in-kernel user of __neigh_for_each_release(). Let's remove it. Signed-off-by: Kuniyuki Iwashima Reviewed-by: David Ahern Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-3-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/neighbour.h | 2 -- net/core/neighbour.c | 31 ------------------------------- 2 files changed, 33 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 8860cc2175fc..7847c29496ae 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -405,8 +405,6 @@ static inline struct net *pneigh_net(const struct pneigh_entry *pneigh) void neigh_app_ns(struct neighbour *n); void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie); -void __neigh_for_each_release(struct neigh_table *tbl, - int (*cb)(struct neighbour *)); int neigh_xmit(int fam, struct net_device *, const void *, struct sk_buff *); struct neigh_seq_state { diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 1349c0eedb64..69a5f9dfa851 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -3161,37 +3161,6 @@ void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void } EXPORT_SYMBOL(neigh_for_each); -/* The tbl->lock must be held as a writer and BH disabled. */ -void __neigh_for_each_release(struct neigh_table *tbl, - int (*cb)(struct neighbour *)) -{ - struct neigh_hash_table *nht; - int chain; - - nht = rcu_dereference_protected(tbl->nht, - lockdep_is_held(&tbl->lock)); - for (chain = 0; chain < (1 << nht->hash_shift); chain++) { - struct hlist_node *tmp; - struct neighbour *n; - - neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[chain]) { - int release; - - write_lock(&n->lock); - release = cb(n); - if (release) { - hlist_del_rcu(&n->hash); - hlist_del_rcu(&n->dev_list); - neigh_mark_dead(n); - } - write_unlock(&n->lock); - if (release) - neigh_cleanup_and_release(n); - } - } -} -EXPORT_SYMBOL(__neigh_for_each_release); - int neigh_xmit(int index, struct net_device *dev, const void *addr, struct sk_buff *skb) { From 2f9ab22897bfd784cf9acd2a193256c3253fa84e Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:44 +0000 Subject: [PATCH 0188/2126] neighbour: Remove lock dance for neigh_update_{gc,managed}_list(). __neigh_update() could call neigh_update_gc_list() and neigh_update_managed_list(). Both of them acquire neigh->tbl->lock and neigh->lock, check neigh->dead, perform link operations, and release the locks. Let's remove the lock dance. Note that neigh->dead is always marked under neigh->tbl->lock. Signed-off-by: Kuniyuki Iwashima Reviewed-by: David Ahern Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-4-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 69a5f9dfa851..13eea09721c6 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -135,6 +135,8 @@ EXPORT_SYMBOL(neigh_rand_reach_time); static void neigh_mark_dead(struct neighbour *n) { + lockdep_assert_held(&n->tbl->lock); + n->dead = 1; if (!list_empty(&n->gc_list)) { list_del_init(&n->gc_list); @@ -148,11 +150,6 @@ static void neigh_update_gc_list(struct neighbour *n) { bool on_gc_list, exempt_from_gc; - spin_lock_bh(&n->tbl->lock); - write_lock(&n->lock); - if (n->dead) - goto out; - /* remove from the gc list if new state is permanent or if neighbor is * externally learned / validated; otherwise entry should be on the gc * list @@ -169,20 +166,12 @@ static void neigh_update_gc_list(struct neighbour *n) list_add_tail(&n->gc_list, &n->tbl->gc_list); atomic_inc(&n->tbl->gc_entries); } -out: - write_unlock(&n->lock); - spin_unlock_bh(&n->tbl->lock); } static void neigh_update_managed_list(struct neighbour *n) { bool on_managed_list, add_to_managed; - spin_lock_bh(&n->tbl->lock); - write_lock(&n->lock); - if (n->dead) - goto out; - add_to_managed = n->flags & NTF_MANAGED; on_managed_list = !list_empty(&n->managed_list); @@ -190,9 +179,6 @@ static void neigh_update_managed_list(struct neighbour *n) list_del_init(&n->managed_list); else if (add_to_managed && !on_managed_list) list_add_tail(&n->managed_list, &n->tbl->managed_list); -out: - write_unlock(&n->lock); - spin_unlock_bh(&n->tbl->lock); } static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify, @@ -1523,10 +1509,23 @@ out: write_unlock_bh(&neigh->lock); - if (((new ^ old) & NUD_PERMANENT) || gc_update) - neigh_update_gc_list(neigh); - if (managed_update) - neigh_update_managed_list(neigh); + gc_update |= !!((new ^ old) & NUD_PERMANENT); + if (gc_update || managed_update) { + spin_lock_bh(&neigh->tbl->lock); + + if (!neigh->dead) { + write_lock(&neigh->lock); + + if (gc_update) + neigh_update_gc_list(neigh); + if (managed_update) + neigh_update_managed_list(neigh); + + write_unlock(&neigh->lock); + } + + spin_unlock_bh(&neigh->tbl->lock); + } if (notify) call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh); From ffc5821e8ab891c434d8b991f8e87379c8e39355 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:45 +0000 Subject: [PATCH 0189/2126] neighbour: Remove unnecessary EXPORT_SYMBOL(). Commit 1bf20cc62a54 ("neighbour: remove obsolete EXPORT_SYMBOL()") unexported some functions in neighbour.c because IPv6 is no longer built as module. Since it unexported neigh_table_init(), no module can register neigh_table dynamically. Let's unexport a few more functions. Signed-off-by: Kuniyuki Iwashima Reviewed-by: David Ahern Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-5-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 13eea09721c6..6fda0052027b 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -131,7 +131,6 @@ unsigned long neigh_rand_reach_time(unsigned long base) { return base ? get_random_u32_below(base) + (base >> 1) : 0; } -EXPORT_SYMBOL(neigh_rand_reach_time); static void neigh_mark_dead(struct neighbour *n) { @@ -1539,7 +1538,6 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, { return __neigh_update(neigh, lladdr, new, flags, nlmsg_pid, NULL); } -EXPORT_SYMBOL(neigh_update); /* Update the neigh to listen temporarily for probe responses, even if it is * in a NUD_FAILED state. The caller has to hold neigh->lock for writing. @@ -1557,7 +1555,6 @@ void __neigh_set_probe_once(struct neighbour *neigh) jiffies + max(NEIGH_VAR(neigh->parms, RETRANS_TIME), HZ/100)); } -EXPORT_SYMBOL(__neigh_set_probe_once); struct neighbour *neigh_event_ns(struct neigh_table *tbl, u8 *lladdr, void *saddr, @@ -1570,7 +1567,6 @@ struct neighbour *neigh_event_ns(struct neigh_table *tbl, NEIGH_UPDATE_F_OVERRIDE, 0); return neigh; } -EXPORT_SYMBOL(neigh_event_ns); /* called with read_lock_bh(&n->lock); */ static void neigh_hh_init(struct neighbour *n) @@ -1623,7 +1619,6 @@ out_kfree_skb: kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_HH_FILLFAIL); goto out; } -EXPORT_SYMBOL(neigh_resolve_output); /* As fast as possible without hh cache */ @@ -1740,7 +1735,6 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, mod_timer(&tbl->proxy_timer, sched_next); spin_unlock(&tbl->proxy_queue.lock); } -EXPORT_SYMBOL(pneigh_enqueue); static inline struct neigh_parms *lookup_neigh_parms(struct neigh_table *tbl, struct net *net, int ifindex) @@ -1788,7 +1782,6 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev, } return p; } -EXPORT_SYMBOL(neigh_parms_alloc); static void neigh_rcu_free_parms(struct rcu_head *head) { @@ -1811,7 +1804,6 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms) netdev_put(parms->dev, &parms->dev_tracker); call_rcu(&parms->rcu_head, neigh_rcu_free_parms); } -EXPORT_SYMBOL(neigh_parms_release); static struct lock_class_key neigh_table_proxy_queue_class; @@ -3398,7 +3390,6 @@ void *neigh_seq_start(struct seq_file *seq, loff_t *pos, struct neigh_table *tbl return *pos ? neigh_get_idx_any(seq, pos) : SEQ_START_TOKEN; } -EXPORT_SYMBOL(neigh_seq_start); void *neigh_seq_next(struct seq_file *seq, void *v, loff_t *pos) { @@ -3425,7 +3416,6 @@ out: ++(*pos); return rc; } -EXPORT_SYMBOL(neigh_seq_next); void neigh_seq_stop(struct seq_file *seq, void *v) __releases(tbl->lock) @@ -3437,7 +3427,6 @@ void neigh_seq_stop(struct seq_file *seq, void *v) spin_unlock_bh(&tbl->lock); rcu_read_unlock(); } -EXPORT_SYMBOL(neigh_seq_stop); /* statistics via seq_file */ @@ -3561,7 +3550,6 @@ void neigh_app_ns(struct neighbour *n) { neigh_notify(n, RTM_GETNEIGH, NLM_F_REQUEST, 0); } -EXPORT_SYMBOL(neigh_app_ns); #ifdef CONFIG_SYSCTL static int unres_qlen_max = INT_MAX / SKB_TRUESIZE(ETH_FRAME_LEN); @@ -3657,7 +3645,6 @@ int neigh_proc_dointvec(const struct ctl_table *ctl, int write, void *buffer, neigh_proc_update(ctl, write); return ret; } -EXPORT_SYMBOL(neigh_proc_dointvec); int neigh_proc_dointvec_jiffies(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos) @@ -3667,7 +3654,6 @@ int neigh_proc_dointvec_jiffies(const struct ctl_table *ctl, int write, void *bu neigh_proc_update(ctl, write); return ret; } -EXPORT_SYMBOL(neigh_proc_dointvec_jiffies); static int neigh_proc_dointvec_userhz_jiffies(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, @@ -3687,7 +3673,6 @@ int neigh_proc_dointvec_ms_jiffies(const struct ctl_table *ctl, int write, neigh_proc_update(ctl, write); return ret; } -EXPORT_SYMBOL(neigh_proc_dointvec_ms_jiffies); static int neigh_proc_dointvec_unres_qlen(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, @@ -3894,7 +3879,6 @@ free: err: return -ENOBUFS; } -EXPORT_SYMBOL(neigh_sysctl_register); void neigh_sysctl_unregister(struct neigh_parms *p) { @@ -3905,7 +3889,6 @@ void neigh_sysctl_unregister(struct neigh_parms *p) kfree(t); } } -EXPORT_SYMBOL(neigh_sysctl_unregister); #endif /* CONFIG_SYSCTL */ From cbc2fbb685f562d3f42a07787b5d8bc835d2bbb9 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:46 +0000 Subject: [PATCH 0190/2126] neighbour: Remove __rcu from neigh_tables[]. Since commit 1bf20cc62a54 ("neighbour: remove obsolete EXPORT_SYMBOL()") unexported neigh_table_init(), neigh_table cannot be registered dynamically. Let's remove RCU protection for neigh_tables[]. Note that neightbl_set() no longer needs RCU because it holds spin_lock_bh(&tbl->lock). Signed-off-by: Kuniyuki Iwashima Reviewed-by: David Ahern Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-6-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6fda0052027b..caa52bf64a2d 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1807,7 +1807,7 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms) static struct lock_class_key neigh_table_proxy_queue_class; -static struct neigh_table __rcu *neigh_tables[NEIGH_NR_TABLES] __read_mostly; +static struct neigh_table *neigh_tables[NEIGH_NR_TABLES] __read_mostly; void neigh_table_init(int index, struct neigh_table *tbl) { @@ -1864,7 +1864,7 @@ void neigh_table_init(int index, struct neigh_table *tbl) tbl->last_flush = now; tbl->last_rand = now + tbl->parms.reachable_time * 20; - rcu_assign_pointer(neigh_tables[index], tbl); + neigh_tables[index] = tbl; } /* @@ -1873,8 +1873,7 @@ void neigh_table_init(int index, struct neigh_table *tbl) */ int neigh_table_clear(int index, struct neigh_table *tbl) { - RCU_INIT_POINTER(neigh_tables[index], NULL); - synchronize_rcu(); + neigh_tables[index] = NULL; /* It is not clean... Fix it to unload IPv6 module safely */ cancel_delayed_work_sync(&tbl->managed_work); @@ -1906,10 +1905,10 @@ static struct neigh_table *neigh_find_table(int family) switch (family) { case AF_INET: - tbl = rcu_dereference_rtnl(neigh_tables[NEIGH_ARP_TABLE]); + tbl = neigh_tables[NEIGH_ARP_TABLE]; break; case AF_INET6: - tbl = rcu_dereference_rtnl(neigh_tables[NEIGH_ND_TABLE]); + tbl = neigh_tables[NEIGH_ND_TABLE]; break; } @@ -2391,10 +2390,8 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, ndtmsg = nlmsg_data(nlh); - rcu_read_lock(); - for (tidx = 0; tidx < NEIGH_NR_TABLES; tidx++) { - tbl = rcu_dereference(neigh_tables[tidx]); + tbl = neigh_tables[tidx]; if (!tbl) continue; @@ -2408,7 +2405,6 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, } if (!found) { - rcu_read_unlock(); err = -ENOENT; goto errout; } @@ -2537,7 +2533,6 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, errout_tbl_lock: spin_unlock_bh(&tbl->lock); - rcu_read_unlock(); errout: return err; } @@ -2589,7 +2584,7 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb) for (tidx = 0; tidx < NEIGH_NR_TABLES; tidx++) { struct neigh_parms *p; - tbl = rcu_dereference(neigh_tables[tidx]); + tbl = neigh_tables[tidx]; if (!tbl) continue; @@ -2949,7 +2944,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb) rcu_read_lock(); for (t = 0; t < NEIGH_NR_TABLES; t++) { - tbl = rcu_dereference(neigh_tables[t]); + tbl = neigh_tables[t]; if (!tbl) continue; @@ -3162,7 +3157,7 @@ int neigh_xmit(int index, struct net_device *dev, struct neighbour *neigh; rcu_read_lock(); - tbl = rcu_dereference(neigh_tables[index]); + tbl = neigh_tables[index]; if (!tbl) { rcu_read_unlock(); goto out_kfree_skb; From b4f0115efd7fdb8b967c3a6315b000d7d682f219 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:47 +0000 Subject: [PATCH 0191/2126] neighbour: Store arp_tbl and nd_tbl in net->neigh_tables[]. We will remove RTNL for neigh_add() and neigh_delete(), but they are still serialised by per-protocol neigh_table.lock. We can avoid contention by converting neigh_tables[] to per-netns, but arp_tbl and nd_tbl are directly used in many places. As a prep, let's store &arp_tbl and &nd_tbl in net->neigh_tables[]. We will replace such users with arp_table(net) and nd_table(net) and then allocate per-netns neigh_table. Note that nd_table() still returns &nd_tbl in case disable_ipv6_mod is 1 because some buggy drivers use nd_tbl without checking it. proc_create_net() is guarded with CONFIG_PROC_FS because it returns NULL when =n and setup_net() fails and panic()s. Also a later patch moves neigh_sysctl_register() under the guard. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-7-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/arp.h | 6 +++++- include/net/ndisc.h | 9 +++++++++ include/net/neighbour.h | 2 ++ include/net/net_namespace.h | 4 ++++ net/core/neighbour.c | 12 ++++++++++++ net/ipv4/arp.c | 23 +++++++++++++++++++++-- net/ipv6/ndisc.c | 12 +++++++++++- 7 files changed, 64 insertions(+), 4 deletions(-) diff --git a/include/net/arp.h b/include/net/arp.h index e8747e0713c7..f8d18b1f8b28 100644 --- a/include/net/arp.h +++ b/include/net/arp.h @@ -7,9 +7,13 @@ #include #include - extern struct neigh_table arp_tbl; +static inline struct neigh_table *arp_table(struct net *net) +{ + return net->neigh_tables[NEIGH_ARP_TABLE]; +} + static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32 *hash_rnd) { u32 key = *(const u32 *)pkey; diff --git a/include/net/ndisc.h b/include/net/ndisc.h index 9e5379ad2d8e..8516c7ff6e92 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -67,6 +67,15 @@ struct prefix_info; extern struct neigh_table nd_tbl; +static inline struct neigh_table *nd_table(struct net *net) +{ +#if IS_ENABLED(CONFIG_IPV6) + if (disable_ipv6_mod) + return &nd_tbl; +#endif + return net->neigh_tables[NEIGH_ND_TABLE]; +} + struct nd_msg { struct icmp6hdr icmph; struct in6_addr target; diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 7847c29496ae..700d62605fab 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -339,6 +339,8 @@ static inline void neigh_confirm(struct neighbour *n) } } +int neigh_table_register(struct net *net, struct neigh_table *tbl, int index); +void neigh_table_unregister(struct net *net, int index); void neigh_table_init(int index, struct neigh_table *tbl); int neigh_table_clear(int index, struct neigh_table *tbl); struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey, diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index e5ee673b9fcf..46b4c67e2966 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ struct user_namespace; struct proc_dir_entry; +struct neigh_table; struct net_device; struct sock; struct ctl_table_header; @@ -103,6 +105,8 @@ struct net { struct proc_dir_entry *proc_net; struct proc_dir_entry *proc_net_stat; + struct neigh_table *neigh_tables[NEIGH_NR_TABLES]; + #ifdef CONFIG_SYSCTL struct ctl_table_set sysctls; #endif diff --git a/net/core/neighbour.c b/net/core/neighbour.c index caa52bf64a2d..286acb7cd504 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1899,6 +1899,18 @@ int neigh_table_clear(int index, struct neigh_table *tbl) return 0; } +int neigh_table_register(struct net *net, struct neigh_table *tbl, int index) +{ + net->neigh_tables[index] = tbl; + + return 0; +} + +void neigh_table_unregister(struct net *net, int index) +{ + net->neigh_tables[index] = NULL; +} + static struct neigh_table *neigh_find_table(int family) { struct neigh_table *tbl = NULL; diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index d409f606aec0..bad17d5aeafc 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1495,15 +1495,34 @@ static const struct seq_operations arp_seq_ops = { static int __net_init arp_net_init(struct net *net) { + int err; + + err = neigh_table_register(net, &arp_tbl, NEIGH_ARP_TABLE); + if (err) + goto err; + +#ifdef CONFIG_PROC_FS if (!proc_create_net("arp", 0444, net->proc_net, &arp_seq_ops, - sizeof(struct neigh_seq_state))) - return -ENOMEM; + sizeof(struct neigh_seq_state))) { + err = -ENOMEM; + goto err_proc_create; + } +#endif + return 0; + +#ifdef CONFIG_PROC_FS +err_proc_create: + neigh_table_unregister(net, NEIGH_ARP_TABLE); +#endif +err: + return err; } static void __net_exit arp_net_exit(struct net *net) { remove_proc_entry("arp", net->proc_net); + neigh_table_unregister(net, NEIGH_ARP_TABLE); } static struct pernet_operations arp_net_ops = { diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 75515fd99383..dc4c083fe27a 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1974,12 +1974,16 @@ static int __net_init ndisc_net_init(struct net *net) struct sock *sk; int err; + err = neigh_table_register(net, &nd_tbl, NEIGH_ND_TABLE); + if (err) + goto err; + err = inet_ctl_sock_create(&sk, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, net); if (err < 0) { net_err_ratelimited("NDISC: Failed to initialize the control socket (err %d)\n", err); - return err; + goto err_sock_create; } net->ipv6.ndisc_sk = sk; @@ -1990,11 +1994,17 @@ static int __net_init ndisc_net_init(struct net *net) inet6_clear_bit(MC6_LOOP, sk); return 0; + +err_sock_create: + neigh_table_unregister(net, NEIGH_ND_TABLE); +err: + return err; } static void __net_exit ndisc_net_exit(struct net *net) { inet_ctl_sock_destroy(net->ipv6.ndisc_sk); + neigh_table_unregister(net, NEIGH_ND_TABLE); } static struct pernet_operations ndisc_net_ops = { From 7bb5d7675cde4dba175ab8dc9dcfb29bc4e51a3d Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:48 +0000 Subject: [PATCH 0192/2126] neighbour: Remove neigh_tables[]. Now, &arp_tbl and &nd_tbl are stored in net->neigh_tables[]. Let's use net->neigh_tables[] in neighbour.c and remove the global neigh_tables[]. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-8-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/neighbour.h | 4 ++-- net/core/neighbour.c | 34 +++++++++++++++------------------- net/ipv4/arp.c | 2 +- net/ipv6/ndisc.c | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 700d62605fab..3e31eebf8663 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -341,8 +341,8 @@ static inline void neigh_confirm(struct neighbour *n) int neigh_table_register(struct net *net, struct neigh_table *tbl, int index); void neigh_table_unregister(struct net *net, int index); -void neigh_table_init(int index, struct neigh_table *tbl); -int neigh_table_clear(int index, struct neigh_table *tbl); +void neigh_table_init(struct neigh_table *tbl); +int neigh_table_clear(struct neigh_table *tbl); struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev); struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey, diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 286acb7cd504..34da4cdc813d 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1807,9 +1807,7 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms) static struct lock_class_key neigh_table_proxy_queue_class; -static struct neigh_table *neigh_tables[NEIGH_NR_TABLES] __read_mostly; - -void neigh_table_init(int index, struct neigh_table *tbl) +void neigh_table_init(struct neigh_table *tbl) { unsigned long now = jiffies; unsigned long phsize; @@ -1863,18 +1861,14 @@ void neigh_table_init(int index, struct neigh_table *tbl) tbl->last_flush = now; tbl->last_rand = now + tbl->parms.reachable_time * 20; - - neigh_tables[index] = tbl; } /* * Only called from ndisc_cleanup(), which means this is dead code * because we no longer can unload IPv6 module. */ -int neigh_table_clear(int index, struct neigh_table *tbl) +int neigh_table_clear(struct neigh_table *tbl) { - neigh_tables[index] = NULL; - /* It is not clean... Fix it to unload IPv6 module safely */ cancel_delayed_work_sync(&tbl->managed_work); cancel_delayed_work_sync(&tbl->gc_work); @@ -1911,16 +1905,16 @@ void neigh_table_unregister(struct net *net, int index) net->neigh_tables[index] = NULL; } -static struct neigh_table *neigh_find_table(int family) +static struct neigh_table *neigh_find_table(struct net *net, int family) { struct neigh_table *tbl = NULL; switch (family) { case AF_INET: - tbl = neigh_tables[NEIGH_ARP_TABLE]; + tbl = net->neigh_tables[NEIGH_ARP_TABLE]; break; case AF_INET6: - tbl = neigh_tables[NEIGH_ND_TABLE]; + tbl = net->neigh_tables[NEIGH_ND_TABLE]; break; } @@ -1974,7 +1968,7 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, } } - tbl = neigh_find_table(ndm->ndm_family); + tbl = neigh_find_table(net, ndm->ndm_family); if (tbl == NULL) return -EAFNOSUPPORT; @@ -2060,7 +2054,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, } } - tbl = neigh_find_table(ndm->ndm_family); + tbl = neigh_find_table(net, ndm->ndm_family); if (tbl == NULL) return -EAFNOSUPPORT; @@ -2403,7 +2397,7 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, ndtmsg = nlmsg_data(nlh); for (tidx = 0; tidx < NEIGH_NR_TABLES; tidx++) { - tbl = neigh_tables[tidx]; + tbl = net->neigh_tables[tidx]; if (!tbl) continue; @@ -2596,7 +2590,7 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb) for (tidx = 0; tidx < NEIGH_NR_TABLES; tidx++) { struct neigh_parms *p; - tbl = neigh_tables[tidx]; + tbl = net->neigh_tables[tidx]; if (!tbl) continue; @@ -2933,6 +2927,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb) { const struct nlmsghdr *nlh = cb->nlh; struct neigh_dump_filter filter = {}; + struct net *net = sock_net(skb->sk); struct neigh_table *tbl; int t, family, s_t; int proxy = 0; @@ -2956,8 +2951,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb) rcu_read_lock(); for (t = 0; t < NEIGH_NR_TABLES; t++) { - tbl = neigh_tables[t]; - + tbl = net->neigh_tables[t]; if (!tbl) continue; if (t < s_t || (family && tbl->family != family)) @@ -3079,7 +3073,7 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh, rcu_read_lock(); - tbl = neigh_find_table(ndm->ndm_family); + tbl = neigh_find_table(net, ndm->ndm_family); if (!tbl) { NL_SET_ERR_MSG(extack, "Unsupported family in header for neighbor get request"); err = -EAFNOSUPPORT; @@ -3167,9 +3161,11 @@ int neigh_xmit(int index, struct net_device *dev, if (likely(index < NEIGH_NR_TABLES)) { struct neigh_table *tbl; struct neighbour *neigh; + struct net *net; rcu_read_lock(); - tbl = neigh_tables[index]; + net = dev_net_rcu(dev); + tbl = net->neigh_tables[index]; if (!tbl) { rcu_read_unlock(); goto out_kfree_skb; diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index bad17d5aeafc..824c65c70408 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1532,7 +1532,7 @@ static struct pernet_operations arp_net_ops = { void __init arp_init(void) { - neigh_table_init(NEIGH_ARP_TABLE, &arp_tbl); + neigh_table_init(&arp_tbl); dev_add_pack(&arp_packet_type); register_pernet_subsys(&arp_net_ops); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index dc4c083fe27a..ed07cf78d223 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -2022,7 +2022,7 @@ int __init ndisc_init(void) /* * Initialize the neighbour table */ - neigh_table_init(NEIGH_ND_TABLE, &nd_tbl); + neigh_table_init(&nd_tbl); #ifdef CONFIG_SYSCTL err = neigh_sysctl_register(NULL, &nd_tbl.parms, @@ -2055,6 +2055,6 @@ void ndisc_cleanup(void) #ifdef CONFIG_SYSCTL neigh_sysctl_unregister(&nd_tbl.parms); #endif - neigh_table_clear(NEIGH_ND_TABLE, &nd_tbl); + neigh_table_clear(&nd_tbl); unregister_pernet_subsys(&ndisc_net_ops); } From 2430df635a59b2a06cc9b5e56da1372cfef7a1e9 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:49 +0000 Subject: [PATCH 0193/2126] ipv4: Replace &arp_tbl with arp_table(net). We will allocate per-netns neigh_table in net->neigh_tables[]. Let's replace &arp_tbl with arp_table(net) and remove extern definition for arp_tbl. Three notes: 1. mlx5e_rep_netevent_event() and nfp_tun_neigh_event_handler() have code assuming neigh_table other than &arp_tbl and &nb_tbl, and the part is removed as it will be false once per-netns table is allocated. 2. prestera and rocker uses init_net because they set dev->netns_immutable to true. 3. mlx5e_tc_update_neigh_used_value() dereferences nhe->neigh_dev in trace_mlx5e_tc_update_neigh_used_value(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-9-kuniyu@google.com Signed-off-by: Jakub Kicinski --- drivers/infiniband/ulp/ipoib/ipoib_main.c | 27 ++++-- .../marvell/prestera/prestera_router.c | 10 +- .../mellanox/mlx5/core/en/rep/neigh.c | 22 ++--- .../mellanox/mlx5/core/en/tc_tun_encap.c | 23 ++--- .../mellanox/mlx5/core/en_accel/ipsec.c | 6 +- .../ethernet/mellanox/mlxsw/spectrum_router.c | 18 ++-- .../ethernet/mellanox/mlxsw/spectrum_span.c | 5 +- .../netronome/nfp/flower/tunnel_conf.c | 10 +- drivers/net/ethernet/rocker/rocker_main.c | 2 +- drivers/net/ethernet/rocker/rocker_ofdpa.c | 2 +- drivers/net/ethernet/sfc/tc_counters.c | 6 +- drivers/net/ethernet/sfc/tc_encap_actions.c | 2 +- drivers/net/vxlan/vxlan_core.c | 10 +- include/net/arp.h | 6 +- include/net/route.h | 7 +- net/bridge/br_arp_nd_proxy.c | 2 +- net/ipv4/arp.c | 94 +++++++++++-------- net/ipv4/devinet.c | 18 ++-- net/ipv4/fib_semantics.c | 5 +- net/ipv4/route.c | 2 +- 20 files changed, 162 insertions(+), 115 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c index 6c14246befb1..dfee72c8e46a 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -1378,7 +1378,8 @@ out_unlock: return neigh; } -static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv) +static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv, + int gc_interval) { struct ipoib_neigh_table *ntbl = &priv->ntbl; struct ipoib_neigh_hash *htbl; @@ -1397,7 +1398,7 @@ static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv) goto out_unlock; /* neigh is obsolete if it was idle for two GC periods */ - dt = 2 * arp_tbl.gc_interval; + dt = 2 * gc_interval; neigh_obsolete = jiffies - dt; for (i = 0; i < htbl->size; i++) { @@ -1433,11 +1434,16 @@ static void ipoib_reap_neigh(struct work_struct *work) { struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, neigh_reap_task.work); + struct net_device *dev = priv->dev; + struct net *net = dev_net(dev); + struct neigh_table *tbl; + int gc_interval; - __ipoib_reap_neigh(priv); + tbl = arp_table(net); + gc_interval = tbl->gc_interval; + __ipoib_reap_neigh(priv, gc_interval); - queue_delayed_work(priv->wq, &priv->neigh_reap_task, - arp_tbl.gc_interval); + queue_delayed_work(priv->wq, &priv->neigh_reap_task, gc_interval); } @@ -1590,8 +1596,11 @@ void ipoib_neigh_free(struct ipoib_neigh *neigh) static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) { struct ipoib_neigh_table *ntbl = &priv->ntbl; - struct ipoib_neigh_hash *htbl; struct ipoib_neigh __rcu **buckets; + struct net_device *dev = priv->dev; + struct net *net = dev_net(dev); + struct ipoib_neigh_hash *htbl; + struct neigh_table *tbl; u32 size; clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); @@ -1599,7 +1608,9 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) htbl = kzalloc_obj(*htbl); if (!htbl) return -ENOMEM; - size = roundup_pow_of_two(arp_tbl.gc_thresh3); + + tbl = arp_table(net); + size = roundup_pow_of_two(tbl->gc_thresh3); buckets = kvzalloc_objs(*buckets, size); if (!buckets) { kfree(htbl); @@ -1614,7 +1625,7 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) /* start garbage collection */ queue_delayed_work(priv->wq, &priv->neigh_reap_task, - arp_tbl.gc_interval); + tbl->gc_interval); return 0; } diff --git a/drivers/net/ethernet/marvell/prestera/prestera_router.c b/drivers/net/ethernet/marvell/prestera/prestera_router.c index 0c4f462baa6e..ba45b61b09bb 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_router.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_router.c @@ -683,7 +683,7 @@ __prestera_k_arb_n_offload_set(struct prestera_switch *sw, { struct neighbour *n; - n = neigh_lookup(&arp_tbl, &nc->key.addr.u.ipv4, + n = neigh_lookup(arp_table(&init_net), &nc->key.addr.u.ipv4, nc->key.dev); if (!n) return; @@ -790,7 +790,7 @@ __prestera_k_arb_nc_kern_n_fetch(struct prestera_switch *sw, int err; memset(&nc->nh_neigh_info, 0, sizeof(nc->nh_neigh_info)); - n = neigh_lookup(&arp_tbl, &nc->key.addr.u.ipv4, nc->key.dev); + n = neigh_lookup(arp_table(&init_net), &nc->key.addr.u.ipv4, nc->key.dev); if (!n) goto out; @@ -1052,10 +1052,12 @@ static void __prestera_k_arb_hw_state_upd(struct prestera_switch *sw, #endif /* PRESTERA_IMPLICITY_RESOLVE_DEAD_NEIGH */ if (nc->key.addr.v == PRESTERA_IPV4) { - n = neigh_lookup(&arp_tbl, &nc->key.addr.u.ipv4, + struct neigh_table *tbl = arp_table(&init_net); + + n = neigh_lookup(tbl, &nc->key.addr.u.ipv4, nc->key.dev); if (!n) - n = neigh_create(&arp_tbl, &nc->key.addr.u.ipv4, + n = neigh_create(tbl, &nc->key.addr.u.ipv4, nc->key.dev); } else { n = NULL; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c index 648f4521c096..9894a0527789 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c @@ -27,10 +27,16 @@ static unsigned long mlx5e_rep_ipv6_interval(void) static void mlx5e_rep_neigh_update_init_interval(struct mlx5e_rep_priv *rpriv) { - unsigned long ipv4_interval = NEIGH_VAR(&arp_tbl.parms, DELAY_PROBE_TIME); unsigned long ipv6_interval = mlx5e_rep_ipv6_interval(); struct net_device *netdev = rpriv->netdev; - struct mlx5e_priv *priv = netdev_priv(netdev); + struct net *net = dev_net(netdev); + unsigned long ipv4_interval; + struct neigh_table *tbl; + struct mlx5e_priv *priv; + + priv = netdev_priv(netdev); + tbl = arp_table(net); + ipv4_interval = NEIGH_VAR(&tbl->parms, DELAY_PROBE_TIME); rpriv->neigh_update.min_interval = min_t(unsigned long, ipv6_interval, ipv4_interval); mlx5_fc_update_sampling_interval(priv->mdev, rpriv->neigh_update.min_interval); @@ -217,12 +223,6 @@ static int mlx5e_rep_netevent_event(struct notifier_block *nb, switch (event) { case NETEVENT_NEIGH_UPDATE: n = ptr; -#if IS_ENABLED(CONFIG_IPV6) - if (n->tbl != &nd_tbl && n->tbl != &arp_tbl) -#else - if (n->tbl != &arp_tbl) -#endif - return NOTIFY_DONE; update_work = mlx5e_alloc_neigh_update_work(priv, n); if (!update_work) @@ -238,11 +238,7 @@ static int mlx5e_rep_netevent_event(struct notifier_block *nb, * changes in the default table, we only care about changes * done per device delay prob time parameter. */ -#if IS_ENABLED(CONFIG_IPV6) - if (!p->dev || (p->tbl != &nd_tbl && p->tbl != &arp_tbl)) -#else - if (!p->dev || p->tbl != &arp_tbl) -#endif + if (!p->dev) return NOTIFY_DONE; rcu_read_lock(); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c index 8b827201935e..33737a29ab97 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c @@ -393,20 +393,10 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) struct mlx5e_encap_entry *e = NULL; struct mlx5e_tc_flow *flow; struct mlx5_fc *counter; - struct neigh_table *tbl; bool neigh_used = false; struct neighbour *n; u64 lastuse; - if (m_neigh->family == AF_INET) - tbl = &arp_tbl; -#if IS_ENABLED(CONFIG_IPV6) - else if (m_neigh->family == AF_INET6) - tbl = &nd_tbl; -#endif - else - return; - /* mlx5e_get_next_valid_encap() releases previous encap before returning * next one. */ @@ -447,12 +437,23 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) trace_mlx5e_tc_update_neigh_used_value(nhe, neigh_used); if (neigh_used) { + struct net_device *dev = READ_ONCE(nhe->neigh_dev); + struct net *net = dev_net(dev); + struct neigh_table *tbl; + nhe->reported_lastuse = jiffies; +#if IS_ENABLED(CONFIG_IPV6) + if (m_neigh->family != AF_INET) + tbl = &nd_tbl; + else +#endif + tbl = arp_table(net); + /* find the relevant neigh according to the cached device and * dst ip pair */ - n = neigh_lookup(tbl, &m_neigh->dst_ip, READ_ONCE(nhe->neigh_dev)); + n = neigh_lookup(tbl, &m_neigh->dst_ip, dev); if (!n) return; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c index db260e3d1412..37a8ddee3ea1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c @@ -262,6 +262,7 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry, struct net_device *netdev = sa_entry->dev; struct xfrm_state *x = sa_entry->x; struct dst_entry *rt_dst_entry; + struct neigh_table *tbl; struct flowi4 fl4 = {}; struct flowi6 fl6 = {}; struct neighbour *n; @@ -364,9 +365,10 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry, return; neigh: - n = neigh_lookup(&arp_tbl, pkey, netdev); + tbl = arp_table(dev_net(netdev)); + n = neigh_lookup(tbl, pkey, netdev); if (!n) { - n = neigh_create(&arp_tbl, pkey, netdev); + n = neigh_create(tbl, pkey, netdev); if (IS_ERR(n)) return; neigh_event_send(n, NULL); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 3d6fdbab05e0..d2a840ce42e3 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -2397,14 +2397,15 @@ mlxsw_sp_neigh_entry_lookup(struct mlxsw_sp *mlxsw_sp, struct neighbour *n) static void mlxsw_sp_router_neighs_update_interval_init(struct mlxsw_sp *mlxsw_sp) { + struct net *net = mlxsw_sp_net(mlxsw_sp); unsigned long interval; #if IS_ENABLED(CONFIG_IPV6) interval = min_t(unsigned long, - NEIGH_VAR(&arp_tbl.parms, DELAY_PROBE_TIME), + NEIGH_VAR(&arp_table(net)->parms, DELAY_PROBE_TIME), NEIGH_VAR(&nd_tbl.parms, DELAY_PROBE_TIME)); #else - interval = NEIGH_VAR(&arp_tbl.parms, DELAY_PROBE_TIME); + interval = NEIGH_VAR(&arp_table(net)->parms, DELAY_PROBE_TIME); #endif mlxsw_sp->router->neighs_update.interval = jiffies_to_msecs(interval); } @@ -2414,6 +2415,8 @@ static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp, int ent_index) { u64 max_rifs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); + struct net *net = mlxsw_sp_net(mlxsw_sp); + struct neigh_table *tbl; struct net_device *dev; struct neighbour *n; __be32 dipn; @@ -2429,9 +2432,10 @@ static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp, return; } + tbl = arp_table(net); dipn = htonl(dip); dev = mlxsw_sp_rif_dev(mlxsw_sp->router->rifs[rif]); - n = neigh_lookup(&arp_tbl, &dipn, dev); + n = neigh_lookup(tbl, &dipn, dev); if (!n) return; @@ -3014,11 +3018,12 @@ static int mlxsw_sp_neigh_rif_made_sync(struct mlxsw_sp *mlxsw_sp, .mlxsw_sp = mlxsw_sp, .rif = rif, }; + struct net *net = mlxsw_sp_net(mlxsw_sp); if (!mlxsw_sp_dev_lower_is_port(mlxsw_sp_rif_dev(rif))) return 0; - neigh_for_each(&arp_tbl, mlxsw_sp_neigh_rif_made_sync_each, &rms); + neigh_for_each(arp_table(net), mlxsw_sp_neigh_rif_made_sync_each, &rms); if (rms.err) goto err_arp; @@ -4622,7 +4627,7 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp, nh->nh_weight = 1; #endif memcpy(&nh->gw_addr, &fib_nh->fib_nh_gw4, sizeof(fib_nh->fib_nh_gw4)); - nh->neigh_tbl = &arp_tbl; + nh->neigh_tbl = arp_table(mlxsw_sp_net(mlxsw_sp)); err = mlxsw_sp_nexthop_insert(mlxsw_sp, nh); if (err) return err; @@ -5112,6 +5117,7 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp, struct nh_notifier_single_info *nh_obj, int weight) { struct net_device *dev = nh_obj->dev; + struct net *net = dev_net(dev); int err; nh->nhgi = nh_grp->nhgi; @@ -5120,7 +5126,7 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp, switch (nh_obj->gw_family) { case AF_INET: memcpy(&nh->gw_addr, &nh_obj->ipv4, sizeof(nh_obj->ipv4)); - nh->neigh_tbl = &arp_tbl; + nh->neigh_tbl = arp_table(net); break; case AF_INET6: memcpy(&nh->gw_addr, &nh_obj->ipv6, sizeof(nh_obj->ipv6)); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index ae63d549b542..2e8577b555ca 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -456,6 +456,7 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp, bool inherit_tos = tparm.iph.tos & 0x1; bool inherit_ttl = !tparm.iph.ttl; union mlxsw_sp_l3addr gw = daddr; + struct neigh_table *tbl = NULL; struct net_device *l3edev; if (!(to_dev->flags & IFF_UP) || @@ -469,9 +470,11 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp, return mlxsw_sp_span_entry_unoffloadable(sparmsp); l3edev = mlxsw_sp_span_gretap4_route(to_dev, &saddr.addr4, &gw.addr4); + if (l3edev) + tbl = arp_table(dev_net(l3edev)); return mlxsw_sp_span_entry_tunnel_parms_common(l3edev, saddr, daddr, gw, tparm.iph.ttl, - &arp_tbl, sparmsp); + tbl, sparmsp); } static int diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c index ca30702f8878..551db6417405 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c @@ -209,6 +209,7 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb) { struct nfp_tun_active_tuns *payload; struct net_device *netdev; + struct neigh_table *tbl; int count, i, pay_len; struct neighbour *n; __be32 ipv4_addr; @@ -235,7 +236,8 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb) if (!netdev) continue; - n = neigh_lookup(&arp_tbl, &ipv4_addr, netdev); + tbl = arp_table(dev_net(netdev)); + n = neigh_lookup(tbl, &ipv4_addr, netdev); if (!n) continue; @@ -729,12 +731,6 @@ nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event, default: return NOTIFY_DONE; } -#if IS_ENABLED(CONFIG_IPV6) - if (n->tbl != &nd_tbl && n->tbl != &arp_tbl) -#else - if (n->tbl != &arp_tbl) -#endif - return NOTIFY_DONE; app_priv = container_of(nb, struct nfp_flower_priv, tun.neigh_nb); app = app_priv->app; diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c index 84a55f2b48ff..0fcd65fc0af7 100644 --- a/drivers/net/ethernet/rocker/rocker_main.c +++ b/drivers/net/ethernet/rocker/rocker_main.c @@ -3134,7 +3134,7 @@ static int rocker_netevent_event(struct notifier_block *unused, switch (event) { case NETEVENT_NEIGH_UPDATE: - if (n->tbl != &arp_tbl) + if (n->tbl != arp_table(&init_net)) return NOTIFY_DONE; dev = n->dev; if (!rocker_port_dev_check(dev)) diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c index 15d19a8a1710..ead8b447b89c 100644 --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c @@ -1336,7 +1336,7 @@ static int ofdpa_port_ipv4_resolve(struct ofdpa_port *ofdpa_port, int err = 0; if (!n) { - n = neigh_create(&arp_tbl, &ip_addr, dev); + n = neigh_create(arp_table(&init_net), &ip_addr, dev); if (IS_ERR(n)) return PTR_ERR(n); } diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index b84235e93ffe..f039836eaec8 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -91,6 +91,7 @@ static void efx_tc_counter_work(struct work_struct *work) struct efx_tc_action_set *act; unsigned long touched; struct neighbour *n; + struct net *net; spin_lock_bh(&cnt->lock); touched = READ_ONCE(cnt->touched); @@ -103,12 +104,15 @@ static void efx_tc_counter_work(struct work_struct *work) continue; if (time_after_eq(encap->neigh->used, touched)) continue; + encap->neigh->used = touched; + net = encap->neigh->net; + /* We have passed traffic using this ARP entry, so * indicate to the ARP cache that it's still active */ if (encap->neigh->dst_ip) - n = neigh_lookup(&arp_tbl, &encap->neigh->dst_ip, + n = neigh_lookup(arp_table(net), &encap->neigh->dst_ip, encap->neigh->egdev); else #if IS_ENABLED(CONFIG_IPV6) diff --git a/drivers/net/ethernet/sfc/tc_encap_actions.c b/drivers/net/ethernet/sfc/tc_encap_actions.c index c2ad3a358d20..f75c87b166ea 100644 --- a/drivers/net/ethernet/sfc/tc_encap_actions.c +++ b/drivers/net/ethernet/sfc/tc_encap_actions.c @@ -527,7 +527,7 @@ static int efx_neigh_event(struct efx_nic *efx, struct neighbour *n) if (WARN_ON(!efx->tc)) return NOTIFY_DONE; - if (n->tbl == &arp_tbl) { + if (n->tbl->family == AF_INET) { keysize = sizeof(keys.dst_ip); #if IS_ENABLED(CONFIG_IPV6) } else if (n->tbl == &nd_tbl) { diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 459f19f7071e..03e932744e3e 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1841,11 +1841,12 @@ static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb) static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) { + struct neigh_table *tbl = arp_table(dev_net(dev)); struct vxlan_dev *vxlan = netdev_priv(dev); + struct neighbour *n; struct arphdr *parp; u8 *arpptr, *sha; __be32 sip, tip; - struct neighbour *n; if (dev->flags & IFF_NOARP) goto out; @@ -1877,7 +1878,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) ipv4_is_multicast(tip)) goto out; - n = neigh_lookup(&arp_tbl, &tip, dev); + n = neigh_lookup(tbl, &tip, dev); if (n) { struct vxlan_rdst *rdst = NULL; @@ -2106,6 +2107,7 @@ out: static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) { struct vxlan_dev *vxlan = netdev_priv(dev); + struct neigh_table *tbl; struct neighbour *n; if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) @@ -2119,8 +2121,10 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) return false; + + tbl = arp_table(dev_net(dev)); pip = ip_hdr(skb); - n = neigh_lookup(&arp_tbl, &pip->daddr, dev); + n = neigh_lookup(tbl, &pip->daddr, dev); if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { union vxlan_addr ipa = { .sin.sin_addr.s_addr = pip->daddr, diff --git a/include/net/arp.h b/include/net/arp.h index f8d18b1f8b28..e932def63d62 100644 --- a/include/net/arp.h +++ b/include/net/arp.h @@ -7,8 +7,6 @@ #include #include -extern struct neigh_table arp_tbl; - static inline struct neigh_table *arp_table(struct net *net) { return net->neigh_tables[NEIGH_ARP_TABLE]; @@ -25,10 +23,12 @@ static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32 #ifdef CONFIG_INET static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key) { + struct neigh_table *tbl = arp_table(dev_net(dev)); + if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) key = INADDR_ANY; - return ___neigh_lookup_noref(&arp_tbl, neigh_key_eq32, arp_hashfn, &key, dev); + return ___neigh_lookup_noref(tbl, neigh_key_eq32, arp_hashfn, &key, dev); } #else static inline diff --git a/include/net/route.h b/include/net/route.h index 45290177a33c..6b55de2e4df8 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -405,8 +405,11 @@ static inline struct neighbour *ip_neigh_gw4(struct net_device *dev, struct neighbour *neigh; neigh = __ipv4_neigh_lookup_noref(dev, (__force u32)daddr); - if (unlikely(!neigh)) - neigh = __neigh_create(&arp_tbl, &daddr, dev, false); + if (unlikely(!neigh)) { + struct neigh_table *tbl = arp_table(dev_net(dev)); + + neigh = __neigh_create(tbl, &daddr, dev, false); + } return neigh; } diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index 87a40e2f1c50..92a3abb1e357 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -193,7 +193,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, return; } - n = neigh_lookup(&arp_tbl, &tip, vlandev); + n = neigh_lookup(arp_table(dev_net(vlandev)), &tip, vlandev); if (n) { struct net_bridge_fdb_entry *f; u8 ha[ETH_ALEN] __aligned(2); diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 824c65c70408..a44fa68fdd07 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -149,7 +149,7 @@ static const struct neigh_ops arp_direct_ops = { .connected_output = neigh_direct_output, }; -struct neigh_table arp_tbl = { +static struct neigh_table arp_tbl = { .family = AF_INET, .key_len = 4, .protocol = cpu_to_be16(ETH_P_IP), @@ -182,7 +182,6 @@ struct neigh_table arp_tbl = { .gc_thresh2 = 512, .gc_thresh3 = 1024, }; -EXPORT_SYMBOL(arp_tbl); int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir) { @@ -222,14 +221,18 @@ static bool arp_key_eq(const struct neighbour *neigh, const void *pkey) static int arp_constructor(struct neighbour *neigh) { - __be32 addr; struct net_device *dev = neigh->dev; - struct in_device *in_dev; - struct neigh_parms *parms; + struct net *net = dev_net(dev); u32 inaddr_any = INADDR_ANY; + struct neigh_parms *parms; + struct in_device *in_dev; + struct neigh_table *tbl; + __be32 addr; + + tbl = arp_table(net); if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) - memcpy(neigh->primary_key, &inaddr_any, arp_tbl.key_len); + memcpy(neigh->primary_key, &inaddr_any, tbl->key_len); addr = *(__be32 *)neigh->primary_key; rcu_read_lock(); @@ -239,7 +242,7 @@ static int arp_constructor(struct neighbour *neigh) return -EINVAL; } - neigh->type = inet_addr_type_dev_table(dev_net(dev), dev, addr); + neigh->type = inet_addr_type_dev_table(net, dev, addr); parms = in_dev->arp_parms; __neigh_parms_put(neigh->parms); @@ -701,24 +704,24 @@ static bool arp_is_garp(struct net *net, struct net_device *dev, static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) { - struct net_device *dev = skb->dev; - struct in_device *in_dev = __in_dev_get_rcu(dev); - struct arphdr *arp; - unsigned char *arp_ptr; - struct rtable *rt; - unsigned char *sha; - unsigned char *tha = NULL; - __be32 sip, tip; - u16 dev_type = dev->type; - int addr_type; - struct neighbour *n; + struct neigh_table *tbl = arp_table(net); struct dst_entry *reply_dst = NULL; + struct net_device *dev = skb->dev; + unsigned char *sha, *tha = NULL; + struct in_device *in_dev; + u16 dev_type = dev->type; + unsigned char *arp_ptr; bool is_garp = false; + struct neighbour *n; + struct arphdr *arp; + struct rtable *rt; + __be32 sip, tip; + int addr_type; /* arp_rcv below verifies the ARP header and verifies the device * is ARP'able. */ - + in_dev = __in_dev_get_rcu(dev); if (!in_dev) goto out_free_skb; @@ -850,7 +853,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) if (!dont_send && IN_DEV_ARPFILTER(in_dev)) dont_send = arp_filter(sip, tip, dev); if (!dont_send) { - n = neigh_event_ns(&arp_tbl, sha, &sip, dev); + n = neigh_event_ns(tbl, sha, &sip, dev); if (n) { arp_send_dst(ARPOP_REPLY, ETH_P_ARP, sip, dev, tip, sha, @@ -865,8 +868,8 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) (arp_fwd_proxy(in_dev, dev, rt) || arp_fwd_pvlan(in_dev, dev, rt, sip, tip) || (rt->dst.dev != dev && - pneigh_lookup(&arp_tbl, net, &tip, dev)))) { - n = neigh_event_ns(&arp_tbl, sha, &sip, dev); + pneigh_lookup(tbl, net, &tip, dev)))) { + n = neigh_event_ns(tbl, sha, &sip, dev); if (n) neigh_release(n); @@ -878,7 +881,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) dev->dev_addr, sha, reply_dst); } else { - pneigh_enqueue(&arp_tbl, + pneigh_enqueue(tbl, in_dev->arp_parms, skb); goto out_free_dst; } @@ -889,7 +892,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) /* Update our ARP tables */ - n = __neigh_lookup(&arp_tbl, &sip, dev, 0); + n = __neigh_lookup(tbl, &sip, dev, 0); addr_type = -1; if (n || arp_accept(in_dev, sip)) { @@ -910,7 +913,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) /* postpone calculation to as late as possible */ inet_addr_type_dev_table(net, dev, sip) == RTN_UNICAST))))) - n = __neigh_lookup(&arp_tbl, &sip, dev, 1); + n = __neigh_lookup(tbl, &sip, dev, 1); } if (n) { @@ -1077,9 +1080,10 @@ static int arp_req_set_proxy(struct net *net, struct net_device *dev, int on) } static int arp_req_set_public(struct net *net, struct arpreq *r, - struct net_device *dev) + struct net_device *dev) { __be32 mask = ((struct sockaddr_in *)&r->arp_netmask)->sin_addr.s_addr; + struct neigh_table *tbl = arp_table(net); if (!dev && (r->arp_flags & ATF_COM)) { dev = dev_getbyhwaddr(net, r->arp_ha.sa_family, @@ -1090,7 +1094,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, if (mask) { __be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - return pneigh_create(&arp_tbl, net, &ip, dev, 0, 0, false); + return pneigh_create(tbl, net, &ip, dev, 0, 0, false); } return arp_req_set_proxy(net, dev, 1); @@ -1098,6 +1102,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, static int arp_req_set(struct net *net, struct arpreq *r) { + struct neigh_table *tbl = arp_table(net); struct neighbour *neigh; struct net_device *dev; __be32 ip; @@ -1133,7 +1138,7 @@ static int arp_req_set(struct net *net, struct arpreq *r) ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - neigh = __neigh_lookup_errno(&arp_tbl, &ip, dev); + neigh = __neigh_lookup_errno(tbl, &ip, dev); err = PTR_ERR(neigh); if (!IS_ERR(neigh)) { unsigned int state = NUD_STALE; @@ -1169,6 +1174,7 @@ static unsigned int arp_state_to_flags(struct neighbour *neigh) static int arp_req_get(struct net *net, struct arpreq *r) { __be32 ip = ((struct sockaddr_in *) &r->arp_pa)->sin_addr.s_addr; + struct neigh_table *tbl = arp_table(net); struct neighbour *neigh; struct net_device *dev; @@ -1179,7 +1185,7 @@ static int arp_req_get(struct net *net, struct arpreq *r) if (IS_ERR(dev)) return PTR_ERR(dev); - neigh = neigh_lookup(&arp_tbl, &ip, dev); + neigh = neigh_lookup(tbl, &ip, dev); if (!neigh) return -ENXIO; @@ -1204,10 +1210,11 @@ static int arp_req_get(struct net *net, struct arpreq *r) int arp_invalidate(struct net_device *dev, __be32 ip, bool force) { - struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev); + struct neigh_table *tbl = arp_table(dev_net(dev)); + struct neighbour *neigh; int err = -ENXIO; - struct neigh_table *tbl = &arp_tbl; + neigh = neigh_lookup(tbl, &ip, dev); if (neigh) { if ((READ_ONCE(neigh->nud_state) & NUD_VALID) && !force) { neigh_release(neigh); @@ -1228,14 +1235,15 @@ int arp_invalidate(struct net_device *dev, __be32 ip, bool force) } static int arp_req_delete_public(struct net *net, struct arpreq *r, - struct net_device *dev) + struct net_device *dev) { __be32 mask = ((struct sockaddr_in *)&r->arp_netmask)->sin_addr.s_addr; + struct neigh_table *tbl = arp_table(net); if (mask) { __be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - return pneigh_delete(&arp_tbl, net, &ip, dev); + return pneigh_delete(tbl, net, &ip, dev); } return arp_req_set_proxy(net, dev, 0); @@ -1325,18 +1333,22 @@ static int arp_netdev_event(struct notifier_block *this, unsigned long event, { struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_change_info *change_info; + struct net *net = dev_net(dev); struct in_device *in_dev; + struct neigh_table *tbl; bool evict_nocarrier; + tbl = arp_table(net); + switch (event) { case NETDEV_CHANGEADDR: - neigh_changeaddr(&arp_tbl, dev); - rt_cache_flush(dev_net(dev)); + neigh_changeaddr(tbl, dev); + rt_cache_flush(net); break; case NETDEV_CHANGE: change_info = ptr; if (change_info->flags_changed & IFF_NOARP) - neigh_changeaddr(&arp_tbl, dev); + neigh_changeaddr(tbl, dev); in_dev = __in_dev_get_rtnl(dev); if (!in_dev) @@ -1345,7 +1357,7 @@ static int arp_netdev_event(struct notifier_block *this, unsigned long event, evict_nocarrier = IN_DEV_ARP_EVICT_NOCARRIER(in_dev); if (evict_nocarrier && !netif_carrier_ok(dev)) - neigh_carrier_down(&arp_tbl, dev); + neigh_carrier_down(tbl, dev); break; default: break; @@ -1364,7 +1376,9 @@ static struct notifier_block arp_netdev_notifier = { */ void arp_ifdown(struct net_device *dev) { - neigh_ifdown(&arp_tbl, dev); + struct neigh_table *tbl = arp_table(dev_net(dev)); + + neigh_ifdown(tbl, dev); } @@ -1479,10 +1493,12 @@ static int arp_seq_show(struct seq_file *seq, void *v) static void *arp_seq_start(struct seq_file *seq, loff_t *pos) { + struct neigh_table *tbl = arp_table(seq_file_net(seq)); + /* Don't want to confuse "arp -a" w/ magic entries, * so we tell the generic iterator to skip NUD_NOARP. */ - return neigh_seq_start(seq, pos, &arp_tbl, NEIGH_SEQ_SKIP_NOARP); + return neigh_seq_start(seq, pos, tbl, NEIGH_SEQ_SKIP_NOARP); } static const struct seq_operations arp_seq_ops = { diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index a90be57c63be..247d666824a4 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -265,7 +265,9 @@ EXPORT_SYMBOL(in_dev_finish_destroy); static struct in_device *inetdev_init(struct net_device *dev) { + struct net *net = dev_net(dev); struct in_device *in_dev; + struct neigh_table *tbl; int err = -ENOMEM; ASSERT_RTNL(); @@ -273,11 +275,12 @@ static struct in_device *inetdev_init(struct net_device *dev) in_dev = kzalloc_obj(*in_dev); if (!in_dev) goto out; - memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt, - sizeof(in_dev->cnf)); + + tbl = arp_table(net); + memcpy(&in_dev->cnf, net->ipv4.devconf_dflt, sizeof(in_dev->cnf)); in_dev->cnf.sysctl = NULL; in_dev->dev = dev; - in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl); + in_dev->arp_parms = neigh_parms_alloc(dev, tbl); if (!in_dev->arp_parms) goto out_kfree; if (IPV4_DEVCONF(in_dev->cnf, FORWARDING)) @@ -291,7 +294,7 @@ static struct in_device *inetdev_init(struct net_device *dev) err = devinet_sysctl_register(in_dev); if (err) { in_dev->dead = 1; - neigh_parms_release(&arp_tbl, in_dev->arp_parms); + neigh_parms_release(tbl, in_dev->arp_parms); in_dev_put(in_dev); in_dev = NULL; goto out; @@ -313,13 +316,12 @@ out_kfree: static void inetdev_destroy(struct in_device *in_dev) { - struct net_device *dev; + struct net_device *dev = in_dev->dev; + struct net *net = dev_net(dev); struct in_ifaddr *ifa; ASSERT_RTNL(); - dev = in_dev->dev; - in_dev->dead = 1; RCU_INIT_POINTER(dev->ip_ptr, NULL); @@ -332,7 +334,7 @@ static void inetdev_destroy(struct in_device *in_dev) } devinet_sysctl_unregister(in_dev); - neigh_parms_release(&arp_tbl, in_dev->arp_parms); + neigh_parms_release(arp_table(net), in_dev->arp_parms); arp_ifdown(dev); in_dev_put(in_dev); diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 7a362f2e2c2b..c9d67550cb60 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -610,11 +610,12 @@ static int fib_detect_death(struct fib_info *fi, int order, int dflt) { const struct fib_nh_common *nhc = fib_info_nhc(fi, 0); - struct neighbour *n; + struct net *net = fi->fib_net; int state = NUD_NONE; + struct neighbour *n; if (likely(nhc->nhc_gw_family == AF_INET)) - n = neigh_lookup(&arp_tbl, &nhc->nhc_gw.ipv4, nhc->nhc_dev); + n = neigh_lookup(arp_table(net), &nhc->nhc_gw.ipv4, nhc->nhc_dev); else if (IS_ENABLED(CONFIG_IPV6) && nhc->nhc_gw_family == AF_INET6) n = neigh_lookup(&nd_tbl, &nhc->nhc_gw.ipv6, nhc->nhc_dev); else diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 37674d76f90f..d7da2f1acbb5 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -817,7 +817,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow n = __ipv4_neigh_lookup(rt->dst.dev, (__force u32)new_gw); if (!n) - n = neigh_create(&arp_tbl, &new_gw, rt->dst.dev); + n = neigh_create(arp_table(net), &new_gw, rt->dst.dev); if (!IS_ERR(n)) { if (!(READ_ONCE(n->nud_state) & NUD_VALID)) { neigh_event_send(n, NULL); From df5f4f372de55e3f0ba24cc2c435e536b297d397 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:50 +0000 Subject: [PATCH 0194/2126] ipv6: Replace &nd_tbl with nd_table(net). We will allocate per-netns neigh_table in net->neigh_tables[]. Let's replace &nd_tbl with nd_table(net). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-10-kuniyu@google.com Signed-off-by: Jakub Kicinski --- .../mellanox/mlx5/core/en/rep/neigh.c | 7 +- .../mellanox/mlx5/core/en/tc_tun_encap.c | 2 +- .../ethernet/mellanox/mlxsw/spectrum_router.c | 13 ++- .../ethernet/mellanox/mlxsw/spectrum_span.c | 5 +- .../netronome/nfp/flower/tunnel_conf.c | 4 +- drivers/net/ethernet/sfc/tc_counters.c | 2 +- drivers/net/ethernet/sfc/tc_encap_actions.c | 2 +- drivers/net/vrf.c | 2 +- drivers/net/vxlan/vxlan_core.c | 6 +- include/net/ndisc.h | 11 ++- net/bridge/br_arp_nd_proxy.c | 2 +- net/ieee802154/6lowpan/tx.c | 3 +- net/ipv4/fib_semantics.c | 2 +- net/ipv6/addrconf.c | 17 ++-- net/ipv6/ip6_output.c | 4 +- net/ipv6/ndisc.c | 93 ++++++++++--------- net/ipv6/route.c | 18 ++-- 17 files changed, 113 insertions(+), 80 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c index 9894a0527789..6a8d8aac7d16 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c @@ -17,26 +17,27 @@ #include "fs_core.h" #include "diag/en_rep_tracepoint.h" -static unsigned long mlx5e_rep_ipv6_interval(void) +static unsigned long mlx5e_rep_ipv6_interval(struct net *net) { if (IS_ENABLED(CONFIG_IPV6) && ipv6_mod_enabled()) - return NEIGH_VAR(&nd_tbl.parms, DELAY_PROBE_TIME); + return NEIGH_VAR(&nd_table(net)->parms, DELAY_PROBE_TIME); return ~0UL; } static void mlx5e_rep_neigh_update_init_interval(struct mlx5e_rep_priv *rpriv) { - unsigned long ipv6_interval = mlx5e_rep_ipv6_interval(); struct net_device *netdev = rpriv->netdev; struct net *net = dev_net(netdev); unsigned long ipv4_interval; + unsigned long ipv6_interval; struct neigh_table *tbl; struct mlx5e_priv *priv; priv = netdev_priv(netdev); tbl = arp_table(net); ipv4_interval = NEIGH_VAR(&tbl->parms, DELAY_PROBE_TIME); + ipv6_interval = mlx5e_rep_ipv6_interval(net); rpriv->neigh_update.min_interval = min_t(unsigned long, ipv6_interval, ipv4_interval); mlx5_fc_update_sampling_interval(priv->mdev, rpriv->neigh_update.min_interval); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c index 33737a29ab97..67c12ca19d59 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c @@ -445,7 +445,7 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) #if IS_ENABLED(CONFIG_IPV6) if (m_neigh->family != AF_INET) - tbl = &nd_tbl; + tbl = nd_table(net); else #endif tbl = arp_table(net); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index d2a840ce42e3..f4a435885ba4 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -2403,7 +2403,7 @@ mlxsw_sp_router_neighs_update_interval_init(struct mlxsw_sp *mlxsw_sp) #if IS_ENABLED(CONFIG_IPV6) interval = min_t(unsigned long, NEIGH_VAR(&arp_table(net)->parms, DELAY_PROBE_TIME), - NEIGH_VAR(&nd_tbl.parms, DELAY_PROBE_TIME)); + NEIGH_VAR(&nd_table(net)->parms, DELAY_PROBE_TIME)); #else interval = NEIGH_VAR(&arp_table(net)->parms, DELAY_PROBE_TIME); #endif @@ -2449,6 +2449,8 @@ static void mlxsw_sp_router_neigh_ent_ipv6_process(struct mlxsw_sp *mlxsw_sp, char *rauhtd_pl, int rec_index) { + struct net *net = mlxsw_sp_net(mlxsw_sp); + struct neigh_table *tbl; struct net_device *dev; struct neighbour *n; struct in6_addr dip; @@ -2462,8 +2464,9 @@ static void mlxsw_sp_router_neigh_ent_ipv6_process(struct mlxsw_sp *mlxsw_sp, return; } + tbl = nd_table(net); dev = mlxsw_sp_rif_dev(mlxsw_sp->router->rifs[rif]); - n = neigh_lookup(&nd_tbl, &dip, dev); + n = neigh_lookup(tbl, &dip, dev); if (!n) return; @@ -3028,7 +3031,7 @@ static int mlxsw_sp_neigh_rif_made_sync(struct mlxsw_sp *mlxsw_sp, goto err_arp; #if IS_ENABLED(CONFIG_IPV6) - neigh_for_each(&nd_tbl, mlxsw_sp_neigh_rif_made_sync_each, &rms); + neigh_for_each(nd_table(net), mlxsw_sp_neigh_rif_made_sync_each, &rms); #endif if (rms.err) goto err_nd; @@ -5131,7 +5134,7 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp, case AF_INET6: memcpy(&nh->gw_addr, &nh_obj->ipv6, sizeof(nh_obj->ipv6)); #if IS_ENABLED(CONFIG_IPV6) - nh->neigh_tbl = &nd_tbl; + nh->neigh_tbl = nd_table(net); #endif break; } @@ -6987,7 +6990,7 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp, nh->nh_weight = rt->fib6_nh->fib_nh_weight; memcpy(&nh->gw_addr, &rt->fib6_nh->fib_nh_gw6, sizeof(nh->gw_addr)); #if IS_ENABLED(CONFIG_IPV6) - nh->neigh_tbl = &nd_tbl; + nh->neigh_tbl = nd_table(mlxsw_sp_net(mlxsw_sp)); #endif err = mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index 2e8577b555ca..1cd8347c274d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -564,6 +564,7 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp, union mlxsw_sp_l3addr daddr = { .addr6 = tparm.raddr }; bool inherit_ttl = !tparm.hop_limit; union mlxsw_sp_l3addr gw = daddr; + struct neigh_table *tbl = NULL; struct net_device *l3edev; if (!(to_dev->flags & IFF_UP) || @@ -577,9 +578,11 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp, return mlxsw_sp_span_entry_unoffloadable(sparmsp); l3edev = mlxsw_sp_span_gretap6_route(to_dev, &saddr.addr6, &gw.addr6); + if (l3edev) + tbl = nd_table(dev_net(l3edev)); return mlxsw_sp_span_entry_tunnel_parms_common(l3edev, saddr, daddr, gw, tparm.hop_limit, - &nd_tbl, sparmsp); + tbl, sparmsp); } static int diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c index 551db6417405..d650d33e3709 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c @@ -253,6 +253,7 @@ void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb) #if IS_ENABLED(CONFIG_IPV6) struct nfp_tun_active_tuns_v6 *payload; struct net_device *netdev; + struct neigh_table *tbl; int count, i, pay_len; struct neighbour *n; void *ipv6_add; @@ -279,7 +280,8 @@ void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb) if (!netdev) continue; - n = neigh_lookup(&nd_tbl, ipv6_add, netdev); + tbl = nd_table(dev_net(netdev)); + n = neigh_lookup(tbl, ipv6_add, netdev); if (!n) continue; diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index f039836eaec8..793a562fc1f7 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -116,7 +116,7 @@ static void efx_tc_counter_work(struct work_struct *work) encap->neigh->egdev); else #if IS_ENABLED(CONFIG_IPV6) - n = neigh_lookup(&nd_tbl, + n = neigh_lookup(nd_table(net), &encap->neigh->dst_ip6, encap->neigh->egdev); #else diff --git a/drivers/net/ethernet/sfc/tc_encap_actions.c b/drivers/net/ethernet/sfc/tc_encap_actions.c index f75c87b166ea..152c4639ecc6 100644 --- a/drivers/net/ethernet/sfc/tc_encap_actions.c +++ b/drivers/net/ethernet/sfc/tc_encap_actions.c @@ -530,7 +530,7 @@ static int efx_neigh_event(struct efx_nic *efx, struct neighbour *n) if (n->tbl->family == AF_INET) { keysize = sizeof(keys.dst_ip); #if IS_ENABLED(CONFIG_IPV6) - } else if (n->tbl == &nd_tbl) { + } else if (n->tbl->family == AF_INET6) { ipv6 = true; keysize = sizeof(keys.dst_ip6); #endif diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index a0557a3a7026..50ec04cc0213 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -616,7 +616,7 @@ static int vrf_finish_output6(struct net *net, struct sock *sk, nexthop = rt6_nexthop(dst_rt6_info(dst), &ipv6_hdr(skb)->daddr); neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop); if (unlikely(!neigh)) - neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false); + neigh = __neigh_create(nd_table(net), nexthop, dst->dev, false); if (!IS_ERR(neigh)) { sock_confirm_neigh(skb, neigh); ret = neigh_output(neigh, skb, false); diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 03e932744e3e..0f0dfb4e176a 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2052,7 +2052,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) ipv6_addr_is_multicast(&msg->target)) goto out; - n = neigh_lookup(&nd_tbl, &msg->target, dev); + n = neigh_lookup(nd_table(dev_net(dev)), &msg->target, dev); if (n) { struct vxlan_rdst *rdst = NULL; @@ -2149,8 +2149,10 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) return false; if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) return false; + + tbl = nd_table(dev_net(dev)); pip6 = ipv6_hdr(skb); - n = neigh_lookup(&nd_tbl, &pip6->daddr, dev); + n = neigh_lookup(tbl, &pip6->daddr, dev); if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { union vxlan_addr ipa = { .sin6.sin6_addr = pip6->daddr, diff --git a/include/net/ndisc.h b/include/net/ndisc.h index 8516c7ff6e92..96e3bb6e83af 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -363,7 +363,9 @@ static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, _ static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey) { - return ___neigh_lookup_noref(&nd_tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev); + struct neigh_table *tbl = nd_table(dev_net(dev)); + + return ___neigh_lookup_noref(tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev); } static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, const void *pkey) @@ -397,8 +399,11 @@ static inline struct neighbour *ip_neigh_gw6(struct net_device *dev, struct neighbour *neigh; neigh = __ipv6_neigh_lookup_noref(dev, addr); - if (unlikely(!neigh)) - neigh = __neigh_create(&nd_tbl, addr, dev, false); + if (unlikely(!neigh)) { + struct neigh_table *tbl = nd_table(dev_net(dev)); + + neigh = __neigh_create(tbl, addr, dev, false); + } return neigh; #else diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index 92a3abb1e357..09458935a49e 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -470,7 +470,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, return; } - n = neigh_lookup(&nd_tbl, &msg->target, vlandev); + n = neigh_lookup(nd_table(dev_net(vlandev)), &msg->target, vlandev); if (n) { struct net_bridge_fdb_entry *f; u8 ha[ETH_ALEN] __aligned(2); diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c index 4df76ff50699..4f511476b992 100644 --- a/net/ieee802154/6lowpan/tx.c +++ b/net/ieee802154/6lowpan/tx.c @@ -58,8 +58,9 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev, info->daddr.mode = IEEE802154_ADDR_SHORT; } else { __le16 short_addr = cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC); + struct neigh_table *tbl = nd_table(dev_net(ldev)); - n = neigh_lookup(&nd_tbl, &hdr->daddr, ldev); + n = neigh_lookup(tbl, &hdr->daddr, ldev); if (n) { llneigh = lowpan_802154_neigh(neighbour_priv(n)); read_lock_bh(&n->lock); diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index c9d67550cb60..50e96f86ca59 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -617,7 +617,7 @@ static int fib_detect_death(struct fib_info *fi, int order, if (likely(nhc->nhc_gw_family == AF_INET)) n = neigh_lookup(arp_table(net), &nhc->nhc_gw.ipv4, nhc->nhc_dev); else if (IS_ENABLED(CONFIG_IPV6) && nhc->nhc_gw_family == AF_INET6) - n = neigh_lookup(&nd_tbl, &nhc->nhc_gw.ipv6, nhc->nhc_dev); + n = neigh_lookup(nd_table(net), &nhc->nhc_gw.ipv6, nhc->nhc_dev); else n = NULL; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 9d89be7e0544..3dba94bd2ba0 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -376,6 +376,8 @@ err_ip: static struct inet6_dev *ipv6_add_dev(struct net_device *dev) { + struct net *net = dev_net(dev); + struct neigh_table *tbl; struct inet6_dev *ndev; int err = -ENOMEM; @@ -393,14 +395,15 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) ndev->dev = dev; INIT_LIST_HEAD(&ndev->addr_list); timer_setup(&ndev->rs_timer, addrconf_rs_timer, 0); - memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); + memcpy(&ndev->cnf, net->ipv6.devconf_dflt, sizeof(ndev->cnf)); if (ndev->cnf.stable_secret.initialized) ndev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY; + tbl = nd_table(net); ndev->cnf.mtu6 = dev->mtu; ndev->ra_mtu = 0; - ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); + ndev->nd_parms = neigh_parms_alloc(dev, tbl); if (!ndev->nd_parms) { kfree(ndev); return ERR_PTR(err); @@ -413,7 +416,7 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) if (snmp6_alloc_dev(ndev) < 0) { netdev_dbg(dev, "%s: cannot allocate memory for statistics\n", __func__); - neigh_parms_release(&nd_tbl, ndev->nd_parms); + neigh_parms_release(tbl, ndev->nd_parms); netdev_put(dev, &ndev->dev_tracker); kfree(ndev); return ERR_PTR(err); @@ -481,7 +484,7 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) return ndev; err_release: - neigh_parms_release(&nd_tbl, ndev->nd_parms); + neigh_parms_release(tbl, ndev->nd_parms); ndev->dead = 1; in6_dev_finish_destroy(ndev); return ERR_PTR(err); @@ -4039,9 +4042,11 @@ restart: /* Last: Shot the device (if unregistered) */ if (unregister) { + struct neigh_table *tbl = nd_table(net); + addrconf_sysctl_unregister(idev); - neigh_parms_release(&nd_tbl, idev->nd_parms); - neigh_ifdown(&nd_tbl, dev); + neigh_parms_release(tbl, idev->nd_parms); + neigh_ifdown(tbl, dev); in6_dev_put(idev); } return 0; diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 8fc4766c8da9..995fad3bf3b2 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -127,7 +127,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * if (IS_ERR_OR_NULL(neigh)) { if (unlikely(!neigh)) - neigh = __neigh_create(&nd_tbl, nexthop, dev, false); + neigh = __neigh_create(nd_table(net), nexthop, dev, false); if (IS_ERR(neigh)) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTNOROUTES); kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL); @@ -583,7 +583,7 @@ int ip6_forward(struct sk_buff *skb) /* XXX: idev->cnf.proxy_ndp? */ if (READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && - pneigh_lookup(&nd_tbl, net, &hdr->daddr, skb->dev)) { + pneigh_lookup(nd_table(net), net, &hdr->daddr, skb->dev)) { int proxied = ip6_forward_proxy_check(skb); hdr = ipv6_hdr(skb); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index ed07cf78d223..e5670af1856c 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -767,10 +767,11 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb) static int pndisc_is_router(const void *pkey, struct net_device *dev) { + struct net *net = dev_net(dev); struct pneigh_entry *n; int ret = -1; - n = pneigh_lookup(&nd_tbl, dev_net(dev), pkey, dev); + n = pneigh_lookup(nd_table(net), net, pkey, dev); if (n) ret = !!(READ_ONCE(n->flags) & NTF_ROUTER); @@ -788,19 +789,21 @@ void ndisc_update(const struct net_device *dev, struct neighbour *neigh, static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb) { + u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) + + offsetof(struct nd_msg, opt)); struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb); const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr; const struct in6_addr *daddr = &ipv6_hdr(skb)->daddr; - u8 *lladdr = NULL; - u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) + - offsetof(struct nd_msg, opt)); - struct ndisc_options ndopts; struct net_device *dev = skb->dev; - struct inet6_ifaddr *ifp; - struct inet6_dev *idev = NULL; - struct neighbour *neigh; + struct net *net = dev_net(dev); int dad = ipv6_addr_any(saddr); + struct inet6_dev *idev = NULL; + struct ndisc_options ndopts; + struct inet6_ifaddr *ifp; + struct neigh_table *tbl; + struct neighbour *neigh; int is_router = -1; + u8 *lladdr = NULL; SKB_DR(reason); u64 nonce = 0; bool inc; @@ -845,9 +848,10 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb) if (ndopts.nd_opts_nonce && ndopts.nd_opts_nonce->nd_opt_len == 1) memcpy(&nonce, (u8 *)(ndopts.nd_opts_nonce + 1), 6); - inc = ipv6_addr_is_multicast(daddr); + tbl = nd_table(net); - ifp = ipv6_get_ifaddr(dev_net(dev), &msg->target, dev, 1); + inc = ipv6_addr_is_multicast(daddr); + ifp = ipv6_get_ifaddr(net, &msg->target, dev, 1); if (ifp) { have_ifp: if (ifp->flags & (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC)) { @@ -880,8 +884,6 @@ have_ifp: idev = ifp->idev; } else { - struct net *net = dev_net(dev); - /* perhaps an address on the master device */ if (netif_is_l3_slave(dev)) { struct net_device *mdev; @@ -918,7 +920,7 @@ have_ifp: */ struct sk_buff *n = skb_clone(skb, GFP_ATOMIC); if (n) - pneigh_enqueue(&nd_tbl, idev->nd_parms, n); + pneigh_enqueue(tbl, idev->nd_parms, n); goto out; } } else { @@ -937,15 +939,15 @@ have_ifp: } if (inc) - NEIGH_CACHE_STAT_INC(&nd_tbl, rcv_probes_mcast); + NEIGH_CACHE_STAT_INC(tbl, rcv_probes_mcast); else - NEIGH_CACHE_STAT_INC(&nd_tbl, rcv_probes_ucast); + NEIGH_CACHE_STAT_INC(tbl, rcv_probes_ucast); /* * update / create cache entry * for the source address */ - neigh = __neigh_lookup(&nd_tbl, saddr, dev, + neigh = __neigh_lookup(tbl, saddr, dev, !inc || lladdr || !dev->addr_len); if (neigh) ndisc_update(dev, neigh, lladdr, NUD_STALE, @@ -987,17 +989,19 @@ static int accept_untracked_na(struct inet6_dev *idev, struct in6_addr *saddr) static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) { - struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb); - struct in6_addr *saddr = &ipv6_hdr(skb)->saddr; - const struct in6_addr *daddr = &ipv6_hdr(skb)->daddr; - u8 *lladdr = NULL; u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) + offsetof(struct nd_msg, opt)); - struct ndisc_options ndopts; + struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb); + const struct in6_addr *daddr = &ipv6_hdr(skb)->daddr; + struct in6_addr *saddr = &ipv6_hdr(skb)->saddr; struct net_device *dev = skb->dev; - struct inet6_dev *idev = __in6_dev_get(dev); + struct net *net = dev_net(dev); + struct ndisc_options ndopts; struct inet6_ifaddr *ifp; + struct neigh_table *tbl; struct neighbour *neigh; + struct inet6_dev *idev; + u8 *lladdr = NULL; SKB_DR(reason); u8 new_state; @@ -1020,6 +1024,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) * and thus should not be accepted. * drop_unsolicited_na takes precedence over accept_untracked_na */ + idev = __in6_dev_get(dev); if (!msg->icmph.icmp6_solicited && idev && READ_ONCE(idev->cnf.drop_unsolicited_na)) return reason; @@ -1034,7 +1039,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) return reason; } } - ifp = ipv6_get_ifaddr(dev_net(dev), &msg->target, dev, 1); + ifp = ipv6_get_ifaddr(net, &msg->target, dev, 1); if (ifp) { if (skb->pkt_type != PACKET_LOOPBACK && (ifp->flags & IFA_F_TENTATIVE)) { @@ -1058,7 +1063,8 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) return reason; } - neigh = neigh_lookup(&nd_tbl, &msg->target, dev); + tbl = nd_table(net); + neigh = neigh_lookup(tbl, &msg->target, dev); /* RFC 9131 updates original Neighbour Discovery RFC 4861. * NAs with Target LL Address option without a corresponding @@ -1078,14 +1084,13 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) new_state = msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE; if (!neigh && lladdr && idev && READ_ONCE(idev->cnf.forwarding)) { if (accept_untracked_na(idev, saddr)) { - neigh = neigh_create(&nd_tbl, &msg->target, dev); + neigh = neigh_create(tbl, &msg->target, dev); new_state = NUD_STALE; } } if (neigh && !IS_ERR(neigh)) { u8 old_flags = neigh->flags; - struct net *net = dev_net(dev); if (READ_ONCE(neigh->nud_state) & NUD_FAILED) goto out; @@ -1098,7 +1103,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) && READ_ONCE(net->ipv6.devconf_all->forwarding) && READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && - pneigh_lookup(&nd_tbl, net, &msg->target, dev)) { + pneigh_lookup(tbl, net, &msg->target, dev)) { /* XXX: idev->cnf.proxy_ndp */ goto out; } @@ -1127,18 +1132,20 @@ out: static enum skb_drop_reason ndisc_recv_rs(struct sk_buff *skb) { struct rs_msg *rs_msg = (struct rs_msg *)skb_transport_header(skb); + const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr; unsigned long ndoptlen = skb->len - sizeof(*rs_msg); + struct net_device *dev = skb->dev; + struct ndisc_options ndopts; + struct neigh_table *tbl; struct neighbour *neigh; struct inet6_dev *idev; - const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr; - struct ndisc_options ndopts; u8 *lladdr = NULL; SKB_DR(reason); if (skb->len < sizeof(*rs_msg)) return SKB_DROP_REASON_PKT_TOO_SMALL; - idev = __in6_dev_get(skb->dev); + idev = __in6_dev_get(dev); if (!idev) { net_err_ratelimited("RS: can't find in6 device\n"); return reason; @@ -1156,19 +1163,19 @@ static enum skb_drop_reason ndisc_recv_rs(struct sk_buff *skb) goto out; /* Parse ND options */ - if (!ndisc_parse_options(skb->dev, rs_msg->opt, ndoptlen, &ndopts)) + if (!ndisc_parse_options(dev, rs_msg->opt, ndoptlen, &ndopts)) return SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS; if (ndopts.nd_opts_src_lladdr) { - lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr, - skb->dev); + lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr, dev); if (!lladdr) goto out; } - neigh = __neigh_lookup(&nd_tbl, saddr, skb->dev, 1); + tbl = nd_table(dev_net(dev)); + neigh = __neigh_lookup(tbl, saddr, dev, 1); if (neigh) { - ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, + ndisc_update(dev, neigh, lladdr, NUD_STALE, NEIGH_UPDATE_F_WEAK_OVERRIDE| NEIGH_UPDATE_F_OVERRIDE| NEIGH_UPDATE_F_OVERRIDE_ISROUTER, @@ -1232,6 +1239,7 @@ errout: static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) { struct ra_msg *ra_msg = (struct ra_msg *)skb_transport_header(skb); + struct net *net = dev_net(skb->dev); bool send_ifinfo_notify = false; struct neighbour *neigh = NULL; struct ndisc_options ndopts; @@ -1241,7 +1249,6 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) u32 defrtr_usr_metric; unsigned int pref = 0; __u32 old_if_flags; - struct net *net; SKB_DR(reason); int lifetime; int optlen; @@ -1330,7 +1337,6 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) /* Do not accept RA with source-addr found on local machine unless * accept_ra_from_local is set to true. */ - net = dev_net(in6_dev->dev); if (!READ_ONCE(in6_dev->cnf.accept_ra_from_local) && ipv6_chk_addr(net, &ipv6_hdr(skb)->saddr, in6_dev->dev, 0)) { net_dbg_ratelimited("RA from local address detected on dev: %s: default router ignored\n", @@ -1468,7 +1474,7 @@ skip_linkparms: */ if (!neigh) - neigh = __neigh_lookup(&nd_tbl, &ipv6_hdr(skb)->saddr, + neigh = __neigh_lookup(nd_table(net), &ipv6_hdr(skb)->saddr, skb->dev, 1); if (neigh) { u8 *lladdr = NULL; @@ -1861,12 +1867,15 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_change_info *change_info; struct net *net = dev_net(dev); + struct neigh_table *tbl; struct inet6_dev *idev; bool evict_nocarrier; + tbl = nd_table(net); + switch (event) { case NETDEV_CHANGEADDR: - neigh_changeaddr(&nd_tbl, dev); + neigh_changeaddr(tbl, dev); fib6_run_gc(0, net, false); fallthrough; case NETDEV_UP: @@ -1890,12 +1899,12 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, change_info = ptr; if (change_info->flags_changed & IFF_NOARP) - neigh_changeaddr(&nd_tbl, dev); + neigh_changeaddr(tbl, dev); if (evict_nocarrier && !netif_carrier_ok(dev)) - neigh_carrier_down(&nd_tbl, dev); + neigh_carrier_down(tbl, dev); break; case NETDEV_DOWN: - neigh_ifdown(&nd_tbl, dev); + neigh_ifdown(tbl, dev); fib6_run_gc(0, net, false); break; case NETDEV_NOTIFY_PEERS: diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 9658939511e0..37e7cbbf49f2 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -217,7 +217,7 @@ struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw, if (n) return n; - n = neigh_create(&nd_tbl, daddr, dev); + n = neigh_create(nd_table(dev_net(dev)), daddr, dev); return IS_ERR(n) ? NULL : n; } @@ -4241,6 +4241,7 @@ static int ip6_route_del(struct fib6_config *cfg, static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_buff *skb) { struct netevent_redirect netevent; + struct net_device *dev = skb->dev; struct rt6_info *rt, *nrt = NULL; struct fib6_result res = {}; struct ndisc_options ndopts; @@ -4274,7 +4275,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu return; } - in6_dev = __in6_dev_get(skb->dev); + in6_dev = __in6_dev_get(dev); if (!in6_dev) return; if (READ_ONCE(in6_dev->cnf.forwarding) || @@ -4286,15 +4287,14 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu * first-hop router for the specified ICMP Destination Address. */ - if (!ndisc_parse_options(skb->dev, msg->opt, optlen, &ndopts)) { + if (!ndisc_parse_options(dev, msg->opt, optlen, &ndopts)) { net_dbg_ratelimited("rt6_redirect: invalid ND options\n"); return; } lladdr = NULL; if (ndopts.nd_opts_tgt_lladdr) { - lladdr = ndisc_opt_addr_data(ndopts.nd_opts_tgt_lladdr, - skb->dev); + lladdr = ndisc_opt_addr_data(ndopts.nd_opts_tgt_lladdr, dev); if (!lladdr) { net_dbg_ratelimited("rt6_redirect: invalid link-layer address length\n"); return; @@ -4313,7 +4313,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu */ dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); - neigh = __neigh_lookup(&nd_tbl, &msg->target, skb->dev, 1); + neigh = __neigh_lookup(nd_table(dev_net(dev)), &msg->target, dev, 1); if (!neigh) return; @@ -4321,7 +4321,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu * We have finally decided to accept it. */ - ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, + ndisc_update(dev, neigh, lladdr, NUD_STALE, NEIGH_UPDATE_F_WEAK_OVERRIDE| NEIGH_UPDATE_F_OVERRIDE| (on_link ? 0 : (NEIGH_UPDATE_F_OVERRIDE_ISROUTER| @@ -5042,9 +5042,11 @@ void rt6_sync_down_dev(struct net_device *dev, unsigned long event) void rt6_disable_ip(struct net_device *dev, unsigned long event) { + struct net *net = dev_net(dev); + rt6_sync_down_dev(dev, event); rt6_uncached_list_flush_dev(dev); - neigh_ifdown(&nd_tbl, dev); + neigh_ifdown(nd_table(net), dev); } struct rt6_mtu_change_arg { From e265c2c432d9331baa06e8a0c2707ff1b8363c10 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:51 +0000 Subject: [PATCH 0195/2126] neighbour: Clean up neigh_table_init() and neigh_table_clear(). Currently, neigh_table_init() and neigh_table_clear() are called once at the boot time, but we will call them for each netns. Let's clean up them. For neigh_table_init(), * Allocate all memory first and unwind on failure * Remove !tbl->entry_size check since it is always true for arp_tbl and nd_tbl * Initialise everything before starting delayed works For neigh_table_clear(), * Reorder function to match neigh_table_init() * Use timer_shutdown_sync() instead of timer_delete_sync() * Remove pneigh_queue_purge() since it is called via neigh_ifdown() * Replace pr_crit() with DEBUG_NET_WARN_ON_ONCE() * Call neigh_hash_free_rcu() directly without call_rcu() In a later patch, neigh_table_clear() will be split so that tbl->{stats,phash_buckets,nht} will be freed only when all neighbour entries are freed. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-11-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 104 ++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 34da4cdc813d..36488dbd1512 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1810,57 +1810,68 @@ static struct lock_class_key neigh_table_proxy_queue_class; void neigh_table_init(struct neigh_table *tbl) { unsigned long now = jiffies; + struct net *net = &init_net; unsigned long phsize; - INIT_LIST_HEAD(&tbl->parms_list); - INIT_LIST_HEAD(&tbl->gc_list); - INIT_LIST_HEAD(&tbl->managed_list); - - list_add(&tbl->parms.list, &tbl->parms_list); - write_pnet(&tbl->parms.net, &init_net); - refcount_set(&tbl->parms.refcnt, 1); - neigh_set_reach_time(&tbl->parms); - tbl->parms.qlen = 0; - - tbl->stats = alloc_percpu(struct neigh_statistics); - if (!tbl->stats) - panic("cannot create neighbour cache statistics"); - -#ifdef CONFIG_PROC_FS - if (!proc_create_seq_data(tbl->id, 0, init_net.proc_net_stat, - &neigh_stat_seq_ops, tbl)) - panic("cannot create neighbour proc dir entry"); -#endif - RCU_INIT_POINTER(tbl->nht, neigh_hash_alloc(3)); + if (!tbl->nht) + goto err_hash; phsize = (PNEIGH_HASHMASK + 1) * sizeof(struct pneigh_entry *); tbl->phash_buckets = kzalloc(phsize, GFP_KERNEL); + if (!tbl->phash_buckets) + goto err_phash; - if (!tbl->nht || !tbl->phash_buckets) - panic("cannot allocate neighbour cache hashes"); + tbl->entry_size = ALIGN(offsetof(struct neighbour, primary_key) + + tbl->key_len, NEIGH_PRIV_ALIGN); - if (!tbl->entry_size) - tbl->entry_size = ALIGN(offsetof(struct neighbour, primary_key) + - tbl->key_len, NEIGH_PRIV_ALIGN); - else - WARN_ON(tbl->entry_size % NEIGH_PRIV_ALIGN); + tbl->stats = alloc_percpu(struct neigh_statistics); + if (!tbl->stats) + goto err_stats; + +#ifdef CONFIG_PROC_FS + if (!proc_create_seq_data(tbl->id, 0, net->proc_net_stat, + &neigh_stat_seq_ops, tbl)) + goto err_proc; +#endif + + tbl->parms.tbl = tbl; + tbl->parms.qlen = 0; + INIT_LIST_HEAD(&tbl->parms_list); + list_add(&tbl->parms.list, &tbl->parms_list); + write_pnet(&tbl->parms.net, net); + refcount_set(&tbl->parms.refcnt, 1); + neigh_set_reach_time(&tbl->parms); + tbl->last_flush = now; + tbl->last_rand = now + tbl->parms.reachable_time * 20; spin_lock_init(&tbl->lock); mutex_init(&tbl->phash_lock); + skb_queue_head_init_class(&tbl->proxy_queue, + &neigh_table_proxy_queue_class); + timer_setup(&tbl->proxy_timer, neigh_proxy_process, 0); + INIT_LIST_HEAD(&tbl->gc_list); INIT_DEFERRABLE_WORK(&tbl->gc_work, neigh_periodic_work); queue_delayed_work(system_power_efficient_wq, &tbl->gc_work, - tbl->parms.reachable_time); + tbl->parms.reachable_time); + + INIT_LIST_HEAD(&tbl->managed_list); INIT_DEFERRABLE_WORK(&tbl->managed_work, neigh_managed_work); queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, 0); - timer_setup(&tbl->proxy_timer, neigh_proxy_process, 0); - skb_queue_head_init_class(&tbl->proxy_queue, - &neigh_table_proxy_queue_class); + return; - tbl->last_flush = now; - tbl->last_rand = now + tbl->parms.reachable_time * 20; +#ifdef CONFIG_PROC_FS +err_proc: + free_percpu(tbl->stats); +#endif +err_stats: + kfree(tbl->phash_buckets); +err_phash: + neigh_hash_free_rcu(&rcu_dereference_protected(tbl->nht, 1)->rcu); +err_hash: + panic("cannot allocate memory"); } /* @@ -1869,26 +1880,27 @@ void neigh_table_init(struct neigh_table *tbl) */ int neigh_table_clear(struct neigh_table *tbl) { - /* It is not clean... Fix it to unload IPv6 module safely */ + struct net *net __maybe_unused = &init_net; + struct neigh_hash_table *nht; + cancel_delayed_work_sync(&tbl->managed_work); cancel_delayed_work_sync(&tbl->gc_work); - timer_delete_sync(&tbl->proxy_timer); - pneigh_queue_purge(&tbl->proxy_queue, NULL, tbl->family); - neigh_ifdown(tbl, NULL); - if (atomic_read(&tbl->entries)) - pr_crit("neighbour leakage\n"); + timer_shutdown_sync(&tbl->proxy_timer); - call_rcu(&rcu_dereference_protected(tbl->nht, 1)->rcu, - neigh_hash_free_rcu); - tbl->nht = NULL; + neigh_ifdown(tbl, NULL); + DEBUG_NET_WARN_ON_ONCE(atomic_read(&tbl->entries)); + + remove_proc_entry(tbl->id, net->proc_net_stat); + + free_percpu(tbl->stats); + tbl->stats = NULL; kfree(tbl->phash_buckets); tbl->phash_buckets = NULL; - remove_proc_entry(tbl->id, init_net.proc_net_stat); - - free_percpu(tbl->stats); - tbl->stats = NULL; + nht = rcu_dereference_protected(tbl->nht, 1); + tbl->nht = NULL; + neigh_hash_free_rcu(&nht->rcu); return 0; } From 1c2b20509463bf4ef4d18b7d1204a3bf051a1bea Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:52 +0000 Subject: [PATCH 0196/2126] neighbour: Convert neigh_table.entries to refcount_t. We will allocate neigh_table for each netns and free it when netns is destroyed. neigh_ifdown() cleans up all neighbour entries during netns dismantle, but there is no synchronisation between timers because neigh_del_timer() uses timer_delete() to stop a timer. If neigh_table were freed while timer were running, neigh_destroy() would touch the freed table. If we called timer_delete_sync() in neigh_flush_one() under tbl->lock, lockdep would complain although it is false-positive. Let's convert neigh_table.entries to refcount_t and destruct neigh_table only when the count reaches 0. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-12-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/neighbour.h | 2 +- net/core/neighbour.c | 64 +++++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 3e31eebf8663..762c8e4cdd96 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -234,7 +234,7 @@ struct neigh_table { struct delayed_work managed_work; struct timer_list proxy_timer; struct sk_buff_head proxy_queue; - atomic_t entries; + refcount_t entries; atomic_t gc_entries; struct list_head gc_list; struct list_head managed_list; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 36488dbd1512..7dc8f0cdbb45 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -55,6 +55,23 @@ static void neigh_notify(struct neighbour *n, int type, int flags, u32 pid); static void __neigh_notify(struct neighbour *n, int type, int flags, u32 pid); static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev, bool skip_perm); +static void neigh_table_free(struct neigh_table *tbl); + +static void neigh_table_get(struct neigh_table *tbl) +{ + refcount_inc(&tbl->entries); +} + +static void neigh_table_put(struct neigh_table *tbl) +{ + if (refcount_dec_and_test(&tbl->entries)) + neigh_table_free(tbl); +} + +static int neigh_table_entries(struct neigh_table *tbl) +{ + return refcount_read(&tbl->entries) - 1; +} #ifdef CONFIG_PROC_FS static const struct seq_operations neigh_stat_seq_ops; @@ -522,7 +539,7 @@ do_alloc: INIT_LIST_HEAD(&n->gc_list); INIT_LIST_HEAD(&n->managed_list); - atomic_inc(&tbl->entries); + neigh_table_get(tbl); out: return n; @@ -672,7 +689,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, nht = rcu_dereference_protected(tbl->nht, lockdep_is_held(&tbl->lock)); - if (atomic_read(&tbl->entries) > (1 << nht->hash_shift)) + if (neigh_table_entries(tbl) > (1 << nht->hash_shift)) nht = neigh_hash_grow(tbl, nht->hash_shift + 1); hash_val = tbl->hash(n->primary_key, dev, nht->hash_rnd) >> (32 - nht->hash_shift); @@ -924,7 +941,7 @@ void neigh_destroy(struct neighbour *neigh) neigh_dbg(2, "neigh %p is destroyed\n", neigh); - atomic_dec(&neigh->tbl->entries); + neigh_table_put(neigh->tbl); kfree_rcu(neigh, rcu); } EXPORT_SYMBOL(neigh_destroy); @@ -979,7 +996,7 @@ static void neigh_periodic_work(struct work_struct *work) neigh_set_reach_time(p); } - if (atomic_read(&tbl->entries) < READ_ONCE(tbl->gc_thresh1)) + if (neigh_table_entries(tbl) < READ_ONCE(tbl->gc_thresh1)) goto out; for (i = 0 ; i < (1 << nht->hash_shift); i++) { @@ -1845,6 +1862,7 @@ void neigh_table_init(struct neigh_table *tbl) tbl->last_flush = now; tbl->last_rand = now + tbl->parms.reachable_time * 20; + refcount_set(&tbl->entries, 1); spin_lock_init(&tbl->lock); mutex_init(&tbl->phash_lock); skb_queue_head_init_class(&tbl->proxy_queue, @@ -1874,24 +1892,10 @@ err_hash: panic("cannot allocate memory"); } -/* - * Only called from ndisc_cleanup(), which means this is dead code - * because we no longer can unload IPv6 module. - */ -int neigh_table_clear(struct neigh_table *tbl) +static void neigh_table_free(struct neigh_table *tbl) { - struct net *net __maybe_unused = &init_net; struct neigh_hash_table *nht; - cancel_delayed_work_sync(&tbl->managed_work); - cancel_delayed_work_sync(&tbl->gc_work); - timer_shutdown_sync(&tbl->proxy_timer); - - neigh_ifdown(tbl, NULL); - DEBUG_NET_WARN_ON_ONCE(atomic_read(&tbl->entries)); - - remove_proc_entry(tbl->id, net->proc_net_stat); - free_percpu(tbl->stats); tbl->stats = NULL; @@ -1901,6 +1905,24 @@ int neigh_table_clear(struct neigh_table *tbl) nht = rcu_dereference_protected(tbl->nht, 1); tbl->nht = NULL; neigh_hash_free_rcu(&nht->rcu); +} + +/* + * Only called from ndisc_cleanup(), which means this is dead code + * because we no longer can unload IPv6 module. + */ +int neigh_table_clear(struct neigh_table *tbl) +{ + struct net *net __maybe_unused = &init_net; + + cancel_delayed_work_sync(&tbl->managed_work); + cancel_delayed_work_sync(&tbl->gc_work); + timer_shutdown_sync(&tbl->proxy_timer); + + neigh_ifdown(tbl, NULL); + remove_proc_entry(tbl->id, net->proc_net_stat); + + neigh_table_put(tbl); return 0; } @@ -2275,7 +2297,7 @@ static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl, struct ndt_config ndc = { .ndtc_key_len = tbl->key_len, .ndtc_entry_size = tbl->entry_size, - .ndtc_entries = atomic_read(&tbl->entries), + .ndtc_entries = neigh_table_entries(tbl), .ndtc_last_flush = jiffies_to_msecs(flush_delta), .ndtc_last_rand = jiffies_to_msecs(rand_delta), .ndtc_proxy_qlen = READ_ONCE(tbl->proxy_queue.qlen), @@ -3495,7 +3517,7 @@ static int neigh_stat_seq_show(struct seq_file *seq, void *v) seq_printf(seq, "%08x %08lx %08lx %08lx %08lx %08lx %08lx " "%08lx %08lx %08lx " "%08lx %08lx %08lx\n", - atomic_read(&tbl->entries), + neigh_table_entries(tbl), st->allocs, st->destroys, From cda2962b6e2b9fc914d6a9ed84c6ca623100ead2 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:53 +0000 Subject: [PATCH 0197/2126] neighbour: Namespacify neigh_tables. Now, neigh_table is ready to be namespacified. Let's allocate per-netns neigh_table in neigh_table_register() and call neigh_table_init() and neigh_sysctl_register() for it. proc_create_seq_data() is changed to proc_create_net_data(). Since each netns has its own sysctl knobs, RTM_SETNEIGHTBL can configure the default table param (ifindex==0) and GC parameters per netns. To avoid potential regression, all the default parameters under /proc/sys/net/ipv{4,6}/neigh/default/, are inherited from init_net by default. This behaviour is controlled by a new sysctl knob, net.core.neigh_inherit_init_net: # sysctl net.core.neigh_inherit_init_net net.core.neigh_inherit_init_net = 1 # sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 128 # sysctl net.ipv4.neigh.default.gc_thresh1=129 net.ipv4.neigh.default.gc_thresh1 = 129 # unshare -n sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 129 If it is turned off, all settings are reset in the new netns: # sysctl net.core.neigh_inherit_init_net=0 net.core.neigh_inherit_init_net = 0 # unshare -n sysctl net.ipv4.neigh.default.gc_thresh1 net.ipv4.neigh.default.gc_thresh1 = 128 The next patch will remove other unnecessary net_eq(). Note that CONFIG_SYSCTL cannot be enabled without CONFIG_PROC_FS. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-13-kuniyu@google.com Signed-off-by: Jakub Kicinski --- Documentation/admin-guide/sysctl/net.rst | 14 ++++ include/net/neighbour.h | 4 +- net/core/neighbour.c | 81 ++++++++++++++++-------- net/core/sysctl_net_core.c | 10 +++ net/ipv4/arp.c | 20 ++++-- net/ipv6/ndisc.c | 43 +++++-------- 6 files changed, 112 insertions(+), 60 deletions(-) diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst index e586e17fc7a5..fe43e8595958 100644 --- a/Documentation/admin-guide/sysctl/net.rst +++ b/Documentation/admin-guide/sysctl/net.rst @@ -413,6 +413,20 @@ new netns has been created. Default : 0 (for compatibility reasons) +neigh_inherit_init_net +---------------------- + +Controls if a new network namespace should inherit all current +settings under /proc/sys/net/ipv{4,6}/neigh/default/. + +By default, the value is set to 1, and all settings are inherited +from init_net. + +If set to 0, both IPv4 and IPv6 settings are reset to their default +values. + +Default : 1 (for compatibility reasons) + txrehash -------- diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 762c8e4cdd96..9ff62d1f8287 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -31,6 +31,8 @@ #include #include +extern int sysctl_neigh_inherit_init_net; + /* * NUD stands for "neighbor unreachability detection" */ @@ -341,8 +343,6 @@ static inline void neigh_confirm(struct neighbour *n) int neigh_table_register(struct net *net, struct neigh_table *tbl, int index); void neigh_table_unregister(struct net *net, int index); -void neigh_table_init(struct neigh_table *tbl); -int neigh_table_clear(struct neigh_table *tbl); struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev); struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey, diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 7dc8f0cdbb45..414422bcc0ec 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1754,13 +1754,13 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, } static inline struct neigh_parms *lookup_neigh_parms(struct neigh_table *tbl, - struct net *net, int ifindex) + int ifindex) { struct neigh_parms *p; list_for_each_entry(p, &tbl->parms_list, list) { - if ((p->dev && p->dev->ifindex == ifindex && net_eq(neigh_parms_net(p), net)) || - (!p->dev && !ifindex && net_eq(net, &init_net))) + if ((p->dev && p->dev->ifindex == ifindex) || + (!p->dev && !ifindex)) return p; } @@ -1824,10 +1824,9 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms) static struct lock_class_key neigh_table_proxy_queue_class; -void neigh_table_init(struct neigh_table *tbl) +static int neigh_table_init(struct net *net, struct neigh_table *tbl) { unsigned long now = jiffies; - struct net *net = &init_net; unsigned long phsize; RCU_INIT_POINTER(tbl->nht, neigh_hash_alloc(3)); @@ -1847,8 +1846,9 @@ void neigh_table_init(struct neigh_table *tbl) goto err_stats; #ifdef CONFIG_PROC_FS - if (!proc_create_seq_data(tbl->id, 0, net->proc_net_stat, - &neigh_stat_seq_ops, tbl)) + if (!proc_create_net_data(tbl->id, 0, net->proc_net_stat, + &neigh_stat_seq_ops, + sizeof(struct seq_net_private), tbl)) goto err_proc; #endif @@ -1878,7 +1878,7 @@ void neigh_table_init(struct neigh_table *tbl) INIT_DEFERRABLE_WORK(&tbl->managed_work, neigh_managed_work); queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, 0); - return; + return 0; #ifdef CONFIG_PROC_FS err_proc: @@ -1889,7 +1889,7 @@ err_stats: err_phash: neigh_hash_free_rcu(&rcu_dereference_protected(tbl->nht, 1)->rcu); err_hash: - panic("cannot allocate memory"); + return -ENOMEM; } static void neigh_table_free(struct neigh_table *tbl) @@ -1905,16 +1905,12 @@ static void neigh_table_free(struct neigh_table *tbl) nht = rcu_dereference_protected(tbl->nht, 1); tbl->nht = NULL; neigh_hash_free_rcu(&nht->rcu); + + kfree(tbl); } -/* - * Only called from ndisc_cleanup(), which means this is dead code - * because we no longer can unload IPv6 module. - */ -int neigh_table_clear(struct neigh_table *tbl) +static void neigh_table_clear(struct net *net, struct neigh_table *tbl) { - struct net *net __maybe_unused = &init_net; - cancel_delayed_work_sync(&tbl->managed_work); cancel_delayed_work_sync(&tbl->gc_work); timer_shutdown_sync(&tbl->proxy_timer); @@ -1923,20 +1919,61 @@ int neigh_table_clear(struct neigh_table *tbl) remove_proc_entry(tbl->id, net->proc_net_stat); neigh_table_put(tbl); +} - return 0; +int sysctl_neigh_inherit_init_net __read_mostly = 1; + +static void neigh_table_inherit(struct net *net, struct neigh_table *tbl, + int index) +{ + const struct neigh_table *init_tbl = init_net.neigh_tables[index]; + bool inherit = READ_ONCE(sysctl_neigh_inherit_init_net); + int i; + + if (net_eq(net, &init_net) || !inherit) + return; + + tbl->gc_interval = READ_ONCE(init_tbl->gc_interval); + tbl->gc_thresh1 = READ_ONCE(init_tbl->gc_thresh1); + tbl->gc_thresh2 = READ_ONCE(init_tbl->gc_thresh2); + tbl->gc_thresh3 = READ_ONCE(init_tbl->gc_thresh3); + + for (i = 0; i < NEIGH_VAR_DATA_MAX; i++) + tbl->parms.data[i] = READ_ONCE(init_tbl->parms.data[i]); } int neigh_table_register(struct net *net, struct neigh_table *tbl, int index) { + int err; + + tbl = kmemdup(tbl, sizeof(*tbl), GFP_KERNEL); + if (!tbl) { + err = -ENOMEM; + goto err; + } + + neigh_table_inherit(net, tbl, index); + + err = neigh_table_init(net, tbl); + if (err) + goto free_table; + net->neigh_tables[index] = tbl; return 0; + +free_table: + kfree(tbl); +err: + return err; } void neigh_table_unregister(struct net *net, int index) { + struct neigh_table *tbl = net->neigh_tables[index]; + net->neigh_tables[index] = NULL; + neigh_table_clear(net, tbl); } static struct neigh_table *neigh_find_table(struct net *net, int family) @@ -2469,8 +2506,8 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, if (tbp[NDTPA_IFINDEX]) ifindex = nla_get_u32(tbp[NDTPA_IFINDEX]); - p = lookup_neigh_parms(tbl, net, ifindex); - if (p == NULL) { + p = lookup_neigh_parms(tbl, ifindex); + if (!p) { err = -ENOENT; goto errout_tbl_lock; } @@ -2551,12 +2588,6 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, } } - err = -ENOENT; - if ((tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || - tb[NDTA_THRESH3] || tb[NDTA_GC_INTERVAL]) && - !net_eq(net, &init_net)) - goto errout_tbl_lock; - if (tb[NDTA_THRESH1]) WRITE_ONCE(tbl->gc_thresh1, nla_get_u32(tb[NDTA_THRESH1])); diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index eb35da3556f4..23310581f494 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -676,6 +677,15 @@ static struct ctl_table net_core_table[] = { .proc_handler = proc_do_skb_defer_max, .extra1 = SYSCTL_ZERO, }, + { + .procname = "neigh_inherit_init_net", + .data = &sysctl_neigh_inherit_init_net, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, }; static const struct ctl_table netns_core_table[] = { diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index a44fa68fdd07..f197051d3aa7 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1518,6 +1518,12 @@ static int __net_init arp_net_init(struct net *net) goto err; #ifdef CONFIG_PROC_FS +#ifdef CONFIG_SYSCTL + err = neigh_sysctl_register(NULL, &arp_table(net)->parms, NULL); + if (err) + goto err_sysctl; +#endif + if (!proc_create_net("arp", 0444, net->proc_net, &arp_seq_ops, sizeof(struct neigh_seq_state))) { err = -ENOMEM; @@ -1529,6 +1535,10 @@ static int __net_init arp_net_init(struct net *net) #ifdef CONFIG_PROC_FS err_proc_create: +#ifdef CONFIG_SYSCTL + neigh_sysctl_unregister(&arp_table(net)->parms); +err_sysctl: +#endif neigh_table_unregister(net, NEIGH_ARP_TABLE); #endif err: @@ -1538,6 +1548,9 @@ err: static void __net_exit arp_net_exit(struct net *net) { remove_proc_entry("arp", net->proc_net); +#ifdef CONFIG_SYSCTL + neigh_sysctl_unregister(&arp_table(net)->parms); +#endif neigh_table_unregister(net, NEIGH_ARP_TABLE); } @@ -1548,12 +1561,9 @@ static struct pernet_operations arp_net_ops = { void __init arp_init(void) { - neigh_table_init(&arp_tbl); + if (register_pernet_subsys(&arp_net_ops)) + panic("Cannot allocate arp table\n"); dev_add_pack(&arp_packet_type); - register_pernet_subsys(&arp_net_ops); -#ifdef CONFIG_SYSCTL - neigh_sysctl_register(NULL, &arp_tbl.parms, NULL); -#endif register_netdevice_notifier(&arp_netdev_notifier); } diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index e5670af1856c..ffb8a8b81821 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1987,6 +1987,13 @@ static int __net_init ndisc_net_init(struct net *net) if (err) goto err; +#ifdef CONFIG_SYSCTL + err = neigh_sysctl_register(NULL, &nd_table(net)->parms, + ndisc_ifinfo_sysctl_change); + if (err) + goto err_sysctl; +#endif + err = inet_ctl_sock_create(&sk, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, net); if (err < 0) { @@ -2005,6 +2012,10 @@ static int __net_init ndisc_net_init(struct net *net) return 0; err_sock_create: +#ifdef CONFIG_SYSCTL + neigh_sysctl_unregister(&nd_table(net)->parms); +err_sysctl: +#endif neigh_table_unregister(net, NEIGH_ND_TABLE); err: return err; @@ -2013,6 +2024,9 @@ err: static void __net_exit ndisc_net_exit(struct net *net) { inet_ctl_sock_destroy(net->ipv6.ndisc_sk); +#ifdef CONFIG_SYSCTL + neigh_sysctl_unregister(&nd_table(net)->parms); +#endif neigh_table_unregister(net, NEIGH_ND_TABLE); } @@ -2023,30 +2037,7 @@ static struct pernet_operations ndisc_net_ops = { int __init ndisc_init(void) { - int err; - - err = register_pernet_subsys(&ndisc_net_ops); - if (err) - return err; - /* - * Initialize the neighbour table - */ - neigh_table_init(&nd_tbl); - -#ifdef CONFIG_SYSCTL - err = neigh_sysctl_register(NULL, &nd_tbl.parms, - ndisc_ifinfo_sysctl_change); - if (err) - goto out_unregister_pernet; -out: -#endif - return err; - -#ifdef CONFIG_SYSCTL -out_unregister_pernet: - unregister_pernet_subsys(&ndisc_net_ops); - goto out; -#endif + return register_pernet_subsys(&ndisc_net_ops); } int __init ndisc_late_init(void) @@ -2061,9 +2052,5 @@ void ndisc_late_cleanup(void) void ndisc_cleanup(void) { -#ifdef CONFIG_SYSCTL - neigh_sysctl_unregister(&nd_tbl.parms); -#endif - neigh_table_clear(&nd_tbl); unregister_pernet_subsys(&ndisc_net_ops); } From da5a7e7a90e625aa796f290451ccf0bab354ba77 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:54 +0000 Subject: [PATCH 0198/2126] neighbour: Don't store net in struct pneigh_entry. neigh_table is now per-netns, so struct pneigh_entry does not need to store a net pointer. Let's remove it and net comparison for pneigh_entry. We no longer need to pass net to pneigh_create(), pneigh_delete(), and pneigh_lookup(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-14-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/neighbour.h | 12 +++------ net/core/neighbour.c | 55 ++++++++++++++--------------------------- net/ipv4/arp.c | 6 ++--- net/ipv6/ip6_output.c | 2 +- net/ipv6/ndisc.c | 4 +-- 5 files changed, 27 insertions(+), 52 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 9ff62d1f8287..ed9d9ae6d3a6 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -181,7 +181,6 @@ struct neigh_ops { struct pneigh_entry { struct pneigh_entry __rcu *next; - possible_net_t net; struct net_device *dev; netdevice_tracker dev_tracker; union { @@ -391,19 +390,14 @@ static inline void neigh_set_reach_time(struct neigh_parms *p) void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, struct sk_buff *skb); -struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net, +struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev); -int pneigh_create(struct neigh_table *tbl, struct net *net, const void *key, +int pneigh_create(struct neigh_table *tbl, const void *key, struct net_device *dev, u32 flags, u8 protocol, bool permanent); -int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key, +int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev); -static inline struct net *pneigh_net(const struct pneigh_entry *pneigh) -{ - return read_pnet(&pneigh->net); -} - void neigh_app_ns(struct neighbour *n); void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie); diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 414422bcc0ec..9649b979918f 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -351,8 +351,7 @@ static void neigh_parms_qlen_dec(struct net_device *dev, int family) rcu_read_unlock(); } -static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net, - int family) +static void pneigh_queue_purge(struct sk_buff_head *list, int family) { struct sk_buff_head tmp; unsigned long flags; @@ -363,13 +362,11 @@ static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net, skb = skb_peek(list); while (skb != NULL) { struct sk_buff *skb_next = skb_peek_next(skb, list); - struct net_device *dev = skb->dev; - if (net == NULL || net_eq(dev_net(dev), net)) { - neigh_parms_qlen_dec(dev, family); - __skb_unlink(skb, list); - __skb_queue_tail(&tmp, skb); - } + neigh_parms_qlen_dec(skb->dev, family); + __skb_unlink(skb, list); + __skb_queue_tail(&tmp, skb); + skb = skb_next; } spin_unlock_irqrestore(&list->lock, flags); @@ -473,8 +470,7 @@ static int __neigh_ifdown(struct neigh_table *tbl, struct net_device *dev, spin_unlock_bh(&tbl->lock); pneigh_ifdown(tbl, dev, skip_perm); - pneigh_queue_purge(&tbl->proxy_queue, dev ? dev_net(dev) : NULL, - tbl->family); + pneigh_queue_purge(&tbl->proxy_queue, tbl->family); if (skb_queue_empty_lockless(&tbl->proxy_queue)) timer_delete_sync(&tbl->proxy_timer); return 0; @@ -754,8 +750,7 @@ static u32 pneigh_hash(const void *pkey, unsigned int key_len) } struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, - struct net *net, const void *pkey, - struct net_device *dev) + const void *pkey, struct net_device *dev) { struct pneigh_entry *n; unsigned int key_len; @@ -768,7 +763,6 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, while (n) { if (!memcmp(n->key, pkey, key_len) && - net_eq(pneigh_net(n), net) && (n->dev == dev || !n->dev)) return n; @@ -778,7 +772,7 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, return NULL; } -int pneigh_create(struct neigh_table *tbl, struct net *net, +int pneigh_create(struct neigh_table *tbl, const void *pkey, struct net_device *dev, u32 flags, u8 protocol, bool permanent) { @@ -789,7 +783,7 @@ int pneigh_create(struct neigh_table *tbl, struct net *net, mutex_lock(&tbl->phash_lock); - n = pneigh_lookup(tbl, net, pkey, dev); + n = pneigh_lookup(tbl, pkey, dev); if (n) goto update; @@ -800,7 +794,6 @@ int pneigh_create(struct neigh_table *tbl, struct net *net, goto out; } - write_pnet(&n->net, net); memcpy(n->key, pkey, key_len); n->dev = dev; netdev_hold(dev, &n->dev_tracker, GFP_KERNEL); @@ -833,7 +826,7 @@ static void pneigh_destroy(struct rcu_head *rcu) kfree(n); } -int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey, +int pneigh_delete(struct neigh_table *tbl, const void *pkey, struct net_device *dev) { struct pneigh_entry *n, __rcu **np; @@ -848,8 +841,7 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey, for (np = &tbl->phash_buckets[hash_val]; (n = rcu_dereference_protected(*np, 1)) != NULL; np = &n->next) { - if (!memcmp(n->key, pkey, key_len) && n->dev == dev && - net_eq(pneigh_net(n), net)) { + if (!memcmp(n->key, pkey, key_len) && n->dev == dev) { rcu_assign_pointer(*np, n->next); mutex_unlock(&tbl->phash_lock); @@ -2049,7 +2041,7 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, } if (ndm->ndm_flags & NTF_PROXY) { - err = pneigh_delete(tbl, net, nla_data(dst_attr), dev); + err = pneigh_delete(tbl, nla_data(dst_attr), dev); goto out; } @@ -2145,7 +2137,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } - err = pneigh_create(tbl, net, dst, dev, ndm_flags, protocol, + err = pneigh_create(tbl, dst, dev, ndm_flags, protocol, !!(ndm->ndm_state & NUD_PERMANENT)); goto out; } @@ -2891,11 +2883,10 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, struct netlink_callback *cb, struct neigh_dump_filter *filter) { - struct pneigh_entry *n; - struct net *net = sock_net(skb->sk); - int err = 0, h, s_h = cb->args[3]; int idx, s_idx = idx = cb->args[4]; + int err = 0, h, s_h = cb->args[3]; unsigned int flags = NLM_F_MULTI; + struct pneigh_entry *n; if (filter->dev_idx || filter->master_idx) flags |= NLM_F_DUMP_FILTERED; @@ -2906,7 +2897,7 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, for (n = rcu_dereference(tbl->phash_buckets[h]), idx = 0; n; n = rcu_dereference(n->next)) { - if (idx < s_idx || pneigh_net(n) != net) + if (idx < s_idx) goto next; if (neigh_ifindex_filtered(n->dev, filter->dev_idx) || neigh_master_filtered(n->dev, filter->master_idx)) @@ -3165,7 +3156,7 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh, if (ndm->ndm_flags & NTF_PROXY) { struct pneigh_entry *pn; - pn = pneigh_lookup(tbl, net, dst, dev); + pn = pneigh_lookup(tbl, dst, dev); if (!pn) { NL_SET_ERR_MSG(extack, "Proxy neighbour entry not found"); err = -ENOENT; @@ -3365,7 +3356,6 @@ static struct neighbour *neigh_get_idx(struct seq_file *seq, loff_t *pos) static struct pneigh_entry *pneigh_get_first(struct seq_file *seq) { struct neigh_seq_state *state = seq->private; - struct net *net = seq_file_net(seq); struct neigh_table *tbl = state->tbl; struct pneigh_entry *pn = NULL; int bucket; @@ -3373,9 +3363,6 @@ static struct pneigh_entry *pneigh_get_first(struct seq_file *seq) state->flags |= NEIGH_SEQ_IS_PNEIGH; for (bucket = 0; bucket <= PNEIGH_HASHMASK; bucket++) { pn = rcu_dereference(tbl->phash_buckets[bucket]); - - while (pn && !net_eq(pneigh_net(pn), net)) - pn = rcu_dereference(pn->next); if (pn) break; } @@ -3389,21 +3376,15 @@ static struct pneigh_entry *pneigh_get_next(struct seq_file *seq, loff_t *pos) { struct neigh_seq_state *state = seq->private; - struct net *net = seq_file_net(seq); struct neigh_table *tbl = state->tbl; - do { - pn = rcu_dereference(pn->next); - } while (pn && !net_eq(pneigh_net(pn), net)); + pn = rcu_dereference(pn->next); while (!pn) { if (++state->bucket > PNEIGH_HASHMASK) break; pn = rcu_dereference(tbl->phash_buckets[state->bucket]); - - while (pn && !net_eq(pneigh_net(pn), net)) - pn = rcu_dereference(pn->next); if (pn) break; } diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index f197051d3aa7..90bc53fb8090 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -868,7 +868,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) (arp_fwd_proxy(in_dev, dev, rt) || arp_fwd_pvlan(in_dev, dev, rt, sip, tip) || (rt->dst.dev != dev && - pneigh_lookup(tbl, net, &tip, dev)))) { + pneigh_lookup(tbl, &tip, dev)))) { n = neigh_event_ns(tbl, sha, &sip, dev); if (n) neigh_release(n); @@ -1094,7 +1094,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, if (mask) { __be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - return pneigh_create(tbl, net, &ip, dev, 0, 0, false); + return pneigh_create(tbl, &ip, dev, 0, 0, false); } return arp_req_set_proxy(net, dev, 1); @@ -1243,7 +1243,7 @@ static int arp_req_delete_public(struct net *net, struct arpreq *r, if (mask) { __be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - return pneigh_delete(tbl, net, &ip, dev); + return pneigh_delete(tbl, &ip, dev); } return arp_req_set_proxy(net, dev, 0); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 995fad3bf3b2..96ee3de55f93 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -583,7 +583,7 @@ int ip6_forward(struct sk_buff *skb) /* XXX: idev->cnf.proxy_ndp? */ if (READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && - pneigh_lookup(nd_table(net), net, &hdr->daddr, skb->dev)) { + pneigh_lookup(nd_table(net), &hdr->daddr, skb->dev)) { int proxied = ip6_forward_proxy_check(skb); hdr = ipv6_hdr(skb); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index ffb8a8b81821..90cd5d852569 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -771,7 +771,7 @@ static int pndisc_is_router(const void *pkey, struct pneigh_entry *n; int ret = -1; - n = pneigh_lookup(nd_table(net), net, pkey, dev); + n = pneigh_lookup(nd_table(net), pkey, dev); if (n) ret = !!(READ_ONCE(n->flags) & NTF_ROUTER); @@ -1103,7 +1103,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) && READ_ONCE(net->ipv6.devconf_all->forwarding) && READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && - pneigh_lookup(tbl, net, &msg->target, dev)) { + pneigh_lookup(tbl, &msg->target, dev)) { /* XXX: idev->cnf.proxy_ndp */ goto out; } From fae1c59810b86a00a31e017a7e787f51957b880b Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:55 +0000 Subject: [PATCH 0199/2126] neighbour: Remove unnecessary net_eq(). neigh_table is now per-netns, and net_eq() is no longer needed. Let's remove them. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-15-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 9649b979918f..27602bcbeb69 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -2662,9 +2662,6 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb) nidx = 0; p = list_next_entry(&tbl->parms, list); list_for_each_entry_from_rcu(p, &tbl->parms_list, list) { - if (!net_eq(neigh_parms_net(p), net)) - continue; - if (nidx < neigh_skip) goto next; @@ -2842,12 +2839,11 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, struct netlink_callback *cb, struct neigh_dump_filter *filter) { - struct net *net = sock_net(skb->sk); - struct neighbour *n; - int err = 0, h, s_h = cb->args[1]; int idx, s_idx = idx = cb->args[2]; - struct neigh_hash_table *nht; + int err = 0, h, s_h = cb->args[1]; unsigned int flags = NLM_F_MULTI; + struct neigh_hash_table *nht; + struct neighbour *n; if (filter->dev_idx || filter->master_idx) flags |= NLM_F_DUMP_FILTERED; @@ -2859,7 +2855,7 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, s_idx = 0; idx = 0; neigh_for_each_in_bucket_rcu(n, &nht->hash_heads[h]) { - if (idx < s_idx || !net_eq(dev_net(n->dev), net)) + if (idx < s_idx) goto next; if (neigh_ifindex_filtered(n->dev, filter->dev_idx) || neigh_master_filtered(n->dev, filter->master_idx)) @@ -3264,10 +3260,6 @@ static struct neighbour *neigh_get_valid(struct seq_file *seq, loff_t *pos) { struct neigh_seq_state *state = seq->private; - struct net *net = seq_file_net(seq); - - if (!net_eq(dev_net(n->dev), net)) - return NULL; if (state->neigh_sub_iter) { loff_t fakep = 0; From 10aa85762861d3c9846ed6ba40e7b16efe60cf07 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 2 Sep 2026 20:36:56 +0000 Subject: [PATCH 0200/2126] selftest: net: Specify netns for ip ntable in test_neigh.sh. test_neigh.sh configures the following attributes in the root netns, but now these can be set per netns. * NDTA_THRESH1 / NDTA_THRESH2 / NDTA_THRESH3 * NDTPA_BASE_REACHABLE_TIME Let's specify netns for "ip ntable". Signed-off-by: Kuniyuki Iwashima Reviewed-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260902203722.926528-16-kuniyu@google.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/test_neigh.sh | 41 ++++++++++++----------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/net/test_neigh.sh b/tools/testing/selftests/net/test_neigh.sh index 447423713266..e70e31edf633 100755 --- a/tools/testing/selftests/net/test_neigh.sh +++ b/tools/testing/selftests/net/test_neigh.sh @@ -240,9 +240,6 @@ extern_valid_common() # Check that an "extern_valid" entry survives a forced garbage # collection. Add an entry, wait 5 seconds and add more entries than # "thresh3" so that forced garbage collection will run. - # - # Note that the garbage collection thresholds are global resources and - # that changes in the initial namespace affect all the namespaces. local forced_gc_runs_t0 local forced_gc_runs_t1 local orig_thresh1 @@ -250,18 +247,23 @@ extern_valid_common() local orig_thresh3 run_cmd "ip -n $ns1 neigh flush dev veth0" - orig_thresh1=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["thresh1"]') - orig_thresh2=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh2")) | .["thresh2"]') - orig_thresh3=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh3")) | .["thresh3"]') - run_cmd "ip ntable change name $tbl_name thresh3 10 thresh2 9 thresh1 8" + orig_thresh1=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh1")) | .["thresh1"]') + orig_thresh2=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh2")) | .["thresh2"]') + orig_thresh3=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh3")) | .["thresh3"]') + run_cmd "ip -n $ns1 ntable change name $tbl_name thresh3 10 thresh2 9 thresh1 8" run_cmd "ip -n $ns1 neigh add $ip_addr lladdr $mac nud stale dev veth0 extern_valid" run_cmd "ip -n $ns1 neigh add ${subnet}3 lladdr $mac nud stale dev veth0" run_cmd "sleep 5" - forced_gc_runs_t0=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') + forced_gc_runs_t0=$(ip -n "$ns1" -j -s ntable show name "$tbl_name" | \ + jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') for i in {1..20}; do run_cmd "ip -n $ns1 neigh add ${subnet}$((i + 4)) nud none dev veth0" done - forced_gc_runs_t1=$(ip -j -s ntable show name "$tbl_name" | jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') + forced_gc_runs_t1=$(ip -n "$ns1" -j -s ntable show name "$tbl_name" | \ + jq '.[] | select(has("forced_gc_runs")) | .["forced_gc_runs"]') if [[ $forced_gc_runs_t1 -eq $forced_gc_runs_t0 ]]; then check_err 1 "Forced garbage collection did not run" fi @@ -272,7 +274,8 @@ extern_valid_common() log_test "$af_str \"extern_valid\" flag: Forced garbage collection" - run_cmd "ip ntable change name $tbl_name thresh3 $orig_thresh3 thresh2 $orig_thresh2 thresh1 $orig_thresh1" + run_cmd "ip -n $ns1 ntable change name $tbl_name \ + thresh3 $orig_thresh3 thresh2 $orig_thresh2 thresh1 $orig_thresh1" RET=0 @@ -284,10 +287,6 @@ extern_valid_common() # collection. Add an "extern_valid" entry, add more than "thresh1" # regular entries, wait "base_reachable" (longer than "gc_stale") # seconds and check that the "extern_valid" entry was not deleted. - # - # Note that the garbage collection thresholds and "base_reachable" are - # global resources and that changes in the initial namespace affect all - # the namespaces. local periodic_gc_runs_t0 local periodic_gc_runs_t1 local orig_base_reachable @@ -296,10 +295,13 @@ extern_valid_common() local timeout run_cmd "ip -n $ns1 neigh flush dev veth0" - orig_thresh1=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["thresh1"]') - orig_base_reachable=$(ip -j ntable show name "$tbl_name" | jq '.[] | select(has("thresh1")) | .["base_reachable"]') - run_cmd "ip ntable change name $tbl_name thresh1 10 base_reachable $base_reachable" - orig_gc_stale=$(ip -n "$ns1" -j ntable show name "$tbl_name" dev veth0 | jq '.[]["gc_stale"]') + orig_thresh1=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh1")) | .["thresh1"]') + orig_base_reachable=$(ip -n "$ns1" -j ntable show name "$tbl_name" | \ + jq '.[] | select(has("thresh1")) | .["base_reachable"]') + run_cmd "ip -n $ns1 ntable change name $tbl_name thresh1 10 base_reachable $base_reachable" + orig_gc_stale=$(ip -n "$ns1" -j ntable show name "$tbl_name" dev veth0 | \ + jq '.[]["gc_stale"]') run_cmd "ip -n $ns1 ntable change name $tbl_name dev veth0 gc_stale 1000" run_cmd "ip -n $ns1 neigh add $ip_addr lladdr $mac nud stale dev veth0 extern_valid" run_cmd "ip -n $ns1 neigh add ${subnet}3 lladdr $mac nud stale dev veth0" @@ -325,7 +327,8 @@ extern_valid_common() log_test "$af_str \"extern_valid\" flag: Periodic garbage collection" run_cmd "ip -n $ns1 ntable change name $tbl_name dev veth0 gc_stale $orig_gc_stale" - run_cmd "ip ntable change name $tbl_name thresh1 $orig_thresh1 base_reachable $orig_base_reachable" + run_cmd "ip -n $ns1 ntable change name $tbl_name \ + thresh1 $orig_thresh1 base_reachable $orig_base_reachable" } extern_valid_ipv4() From 8d5f1bda7e8bbfff4f60b82a150219a72f37e7e5 Mon Sep 17 00:00:00 2001 From: Muhammad Falak R Wani Date: Wed, 2 Sep 2026 14:40:10 +0530 Subject: [PATCH 0201/2126] net: mana: remove unreachable dead code in mana_bpf() mana_bpf() has a trailing 'return ret;' after a switch statement whose every case (XDP_SETUP_PROG and default) already returns unconditionally. The statement is therefore unreachable and 'ret' is never used. Remove both. No functional change intended. Signed-off-by: Muhammad Falak R Wani Reviewed-by: Hamza Mahfooz Link: https://patch.msgid.link/3d8b67307df6fefdc18743274cef3de4fca0e7de.1788339612.git.falakreyaz@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microsoft/mana/mana_bpf.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c index 53308e139cbe..70bb8c9dc341 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c @@ -253,7 +253,6 @@ err_dealloc_rxbuffs: int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf) { struct netlink_ext_ack *extack = bpf->extack; - int ret; switch (bpf->command) { case XDP_SETUP_PROG: @@ -262,6 +261,4 @@ int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf) default: return -EOPNOTSUPP; } - - return ret; } From 7f1de03e31033590279e4f8fc01ddf2c5dcfab51 Mon Sep 17 00:00:00 2001 From: Tristan Madani Date: Wed, 2 Sep 2026 12:30:40 +0000 Subject: [PATCH 0202/2126] net: reduce XMIT_RECURSION_LIMIT under KASAN Virtual network devices (ipvlan, macvlan, bonding) can enter legitimate transmit recursion when combined with packet forwarding configurations such as IPVS NAT. The existing XMIT_RECURSION_LIMIT (8) in __dev_queue_xmit() detects and breaks these loops, but the allowed depth is too high for KASAN-instrumented kernels: each recursion level consumes significantly more stack due to KASAN inline instrumentation, and the cumulative usage overflows the kernel stack before the limit fires. On x86_64, CONFIG_KASAN_GENERIC doubles THREAD_SIZE from 16KB to 32KB (KASAN_STACK_ORDER=1), but KASAN per-access checks inflate individual function frames by roughly 2-3x. For an ipvlan L3 + IPVS NAT routing loop, objdump measurements on a non-KASAN kernel show ~1.4KB of stack consumed per recursion level (across 17 functions from __dev_queue_xmit through the full IP output path and back). At KASAN ~2.3x inflation factor that becomes ~3.3KB per level. Eight levels -- the current limit -- consume ~26KB plus the initial call chain (~8KB), which exceeds the 32KB KASAN stack. The overflow hits the VMAP_STACK guard page and causes a non-recoverable kernel panic (BUG: stack guard page was hit). On non-KASAN kernels the same loop is safely caught by the existing limit: the "Dead loop on virtual device" message fires and the packet is dropped without any stack overflow. Reduce XMIT_RECURSION_LIMIT to 4 when CONFIG_KASAN is enabled. The deepest legitimate transmit recursion observed in the kernel selftests is 5 levels of __dev_queue_xmit nesting, in VXLAN symmetric routing topologies with VRF (vxlan_symmetric, vxlan_asymmetric): __dev_queue_xmit(vrf) depth 1 __dev_queue_xmit(vlan-svi) depth 2 __dev_queue_xmit(bridge) depth 3 __dev_queue_xmit(vxlan) depth 4 __dev_queue_xmit(veth) depth 5 Since the recursion check fires when the counter exceeds the limit (strictly greater than), a limit of 4 permits 5 levels of nesting while blocking the 6th. At ~3.3KB per level, five levels consume ~16.5KB; combined with the ~8KB initial call chain, total usage is ~24.5KB -- well within the 32KB KASAN stack with ~7.5KB of margin. A limit of 3 (v2/v3 of this patch) allows only 4 levels, which broke the VXLAN symmetric selftests: the 5th __dev_queue_xmit call was incorrectly dropped, as reported by Jakub Kicinski and the kernel test robot. The recursion path triggering this is: __dev_queue_xmit -> dev_hard_start_xmit -> ipvlan_start_xmit -> ipvlan_queue_xmit -> ipvlan_process_outbound -> ip_local_out -> nf_hook (IPVS) -> ip_vs_in_hook -> ip_vs_nat_xmit -> ip_output -> ip_finish_output2 -> neigh_resolve_output -> __dev_queue_xmit Tested: - KASAN kernel (6.8.12 x86_64): panic before fix, "Dead loop" drop after fix (at recursion level 4 instead of 8). - Non-KASAN kernel (6.8.12 x86_64): "Dead loop" drop both before and after fix (no behavior change for production kernels). - Measured max __dev_queue_xmit nesting depth via bpftrace in a VXLAN symmetric cross-VLAN topology (VRF + VLAN + bridge + VXLAN + veth underlay): 5 levels, confirming limit=4 is sufficient. Cc: stable+noautosel@kernel.org # KASAN is non-production Signed-off-by: Tristan Madani Link: https://patch.msgid.link/20260902123040.2172805-1-tristmd@gmail.com Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8454646d6a45..3e184994df4b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3669,7 +3669,11 @@ struct page_pool_bh { }; DECLARE_PER_CPU(struct page_pool_bh, system_page_pool); +#ifdef CONFIG_KASAN +#define XMIT_RECURSION_LIMIT 4 +#else #define XMIT_RECURSION_LIMIT 8 +#endif #ifndef CONFIG_PREEMPT_RT static inline int dev_recursion_level(void) From daf0972d38e999dcfd7a409daaeef69812c1f58d Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 3 Sep 2026 12:36:50 +0000 Subject: [PATCH 0203/2126] net: phy: air_en8811h: refuse a firmware blob that is not a multiple of 4 The download loop streams the blob into the MCU as 32-bit words and reads the last word past the end of a blob whose size is not a multiple of four. The shipped blobs happen to be aligned, so the overread never showed; a truncated or foreign file would carry up to three bytes of whatever follows it into the MCU. Reject it before the first write instead. Cc: stable+noautosel@kernel.org # needs real net-admin (non-ns) Reviewed-by: Andrew Lunn Signed-off-by: Aleksei Sviridkin Link: https://patch.msgid.link/20260903123650.23855-1-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/phy/air_en8811h.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index 38eb18f0e9bb..ec7c44ca68e7 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -312,6 +312,12 @@ static int air_write_buf(struct phy_device *phydev, u32 address, int saved_page; int ret = 0; + if (fw->size % 4) { + phydev_err(phydev, "firmware size %zu is not a multiple of 4\n", + fw->size); + return -EINVAL; + } + saved_page = phy_select_page(phydev, AIR_PHY_PAGE_EXTENDED_4); if (saved_page >= 0) { From 761ae184f850f33d1bbf6c4530c7f237be780d21 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Thu, 3 Sep 2026 15:11:54 -0700 Subject: [PATCH 0204/2126] netdev: avoid skipping objects on race with device disappearance If the currently dumped device disappears while we were mid-dump we will get the next device without resetting the sub-object ID. This is quite unlikely, it was reported by an AI tool not a real user. Let's fix it for better dump consistency. We only intend to cover the case where device A disappears and we skip over sub-objects of device B which was stable (B existed before and after the dump). We don't intend to provide stable results for any device that gets created or deleted during the dump. Reviewed-by: Bobby Eshleman Acked-by: Daniel Borkmann Reviewed-by: Nikolay Aleksandrov Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260903221154.3359889-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- net/core/netdev-genl.c | 22 +++++++++++++++++----- net/core/page_pool_user.c | 8 ++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index b8ba91cc93da..fa9edfdb32c2 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -312,11 +312,14 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) err = -ENODEV; } } else { + unsigned long start_ifindex = ctx->ifindex; + for_each_netdev_lock_scoped(net, netdev, ctx->ifindex) { + if (ctx->ifindex != start_ifindex) + ctx->napi_id = 0; err = netdev_nl_napi_dump_one(netdev, skb, info, ctx); if (err < 0) break; - ctx->napi_id = 0; } } @@ -636,13 +639,17 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) err = -ENODEV; } } else { + unsigned long start_ifindex = ctx->ifindex; + for_each_netdev_lock_ops_compat_scoped(net, netdev, ctx->ifindex) { + if (ctx->ifindex != start_ifindex) { + ctx->rxq_idx = 0; + ctx->txq_idx = 0; + } err = netdev_nl_queue_dump_one(netdev, skb, info, ctx); if (err < 0) break; - ctx->rxq_idx = 0; - ctx->txq_idx = 0; } } @@ -788,8 +795,6 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp, ctx->txq_idx = ++i; } - ctx->rxq_idx = 0; - ctx->txq_idx = 0; return 0; } @@ -904,6 +909,7 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb, struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); const struct genl_info *info = genl_info_dump(cb); struct net *net = sock_net(skb->sk); + unsigned long start_ifindex; struct net_device *netdev; unsigned int ifindex; unsigned int scope; @@ -936,7 +942,13 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb, return err; } + start_ifindex = ctx->ifindex; + for_each_netdev_lock_ops_compat_scoped(net, netdev, ctx->ifindex) { + if (ctx->ifindex != start_ifindex) { + ctx->rxq_idx = 0; + ctx->txq_idx = 0; + } err = netdev_nl_qstats_get_dump_one(netdev, scope, skb, info, ctx); if (err < 0) diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c index ef4261c0e8ea..f30f3779624c 100644 --- a/net/core/page_pool_user.c +++ b/net/core/page_pool_user.c @@ -84,6 +84,7 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb, struct page_pool_dump_cb *state = (void *)cb->ctx; const struct genl_info *info = genl_info_dump(cb); struct net *net = sock_net(skb->sk); + unsigned long start_ifindex; struct net_device *netdev; struct page_pool *pool; int err = 0; @@ -91,6 +92,8 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb, if (ifindex_attr) state->ifindex = nla_get_u32(ifindex_attr); + start_ifindex = state->ifindex; + rtnl_lock(); mutex_lock(&page_pools_lock); for_each_netdev_dump(net, netdev, state->ifindex) { @@ -99,6 +102,9 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb, netdev->ifindex != nla_get_u32(ifindex_attr)) break; + if (state->ifindex != start_ifindex) + state->pp_id = 0; + hlist_for_each_entry(pool, &netdev->page_pools, user.list) { if (state->pp_id && state->pp_id < pool->user.id) continue; @@ -108,8 +114,6 @@ netdev_nl_page_pool_get_dump(struct sk_buff *skb, struct netlink_callback *cb, if (err) goto out; } - - state->pp_id = 0; } out: mutex_unlock(&page_pools_lock); From 5cce5d29273c817ba18b866671031ec3aa7564c6 Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Tue, 1 Sep 2026 09:55:02 +0530 Subject: [PATCH 0205/2126] octeontx2-af: Show DMAC filter drop count Show the number of packets dropped by DMAC filters in the CGX/RPM debugfs mac_filter entry. CGX uses RX_STAT4 for this counter, while RPM/RPM2 use RX_STAT2. Signed-off-by: Hariprasad Kelam Signed-off-by: Nitin Shetty J Link: https://patch.msgid.link/20260901042503.1182121-1-nshettyj@marvell.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/marvell/octeontx2/af/cgx.c | 13 +++++- .../net/ethernet/marvell/octeontx2/af/cgx.h | 2 + .../marvell/octeontx2/af/lmac_common.h | 2 + .../net/ethernet/marvell/octeontx2/af/rpm.c | 40 +++++++++++++------ .../net/ethernet/marvell/octeontx2/af/rpm.h | 2 + .../net/ethernet/marvell/octeontx2/af/rvu.h | 1 + .../ethernet/marvell/octeontx2/af/rvu_cgx.c | 12 ++++++ .../marvell/octeontx2/af/rvu_debugfs.c | 8 ++++ 8 files changed, 67 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c index f5fd6138c352..3696bec7a8fc 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -752,6 +752,16 @@ u64 cgx_features_get(void *cgxd) return ((struct cgx *)cgxd)->hw_features; } +u64 cgx_get_dmacflt_dropped_pktcnt(void *cgxd, int lmac_id) +{ + struct cgx *cgx = cgxd; + + if (!is_lmac_valid(cgx, lmac_id)) + return 0; + + return cgx_read(cgx, lmac_id, CGXX_CMRX_RX_STAT4); +} + int cgx_stats_reset(void *cgxd, int lmac_id) { struct cgx *cgx = cgxd; @@ -1943,7 +1953,8 @@ static struct mac_ops cgx_mac_ops = { .pfc_config = cgx_lmac_pfc_config, .mac_get_pfc_frm_cfg = cgx_lmac_get_pfc_frm_cfg, .mac_reset = cgx_lmac_reset, - .mac_stats_reset = cgx_stats_reset, + .get_dmacflt_dropped_pktcnt = cgx_get_dmacflt_dropped_pktcnt, + .mac_stats_reset = cgx_stats_reset, .mac_x2p_reset = cgx_x2p_reset, .mac_enadis_rx = cgx_enadis_rx, }; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h b/drivers/net/ethernet/marvell/octeontx2/af/cgx.h index 8411a75dd723..cd8858c4e41c 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.h @@ -39,6 +39,7 @@ #define CGXX_CMRX_INT_ENA_W1S 0x058 #define CGXX_CMRX_RX_ID_MAP 0x060 #define CGXX_CMRX_RX_STAT0 0x070 +#define CGXX_CMRX_RX_STAT4 0x090 #define CGXX_CMRX_RX_LOGL_XON 0x100 #define CGXX_CMRX_RX_LMACS 0x128 #define CGXX_CMRX_RX_DMAC_CTL0 (0x1F8 + mac_ops->csr_offset) @@ -187,5 +188,6 @@ int cgx_lmac_get_pfc_frm_cfg(void *cgxd, int lmac_id, u8 *tx_pause, int verify_lmac_fc_cfg(void *cgxd, int lmac_id, u8 tx_pause, u8 rx_pause, int pfvf_idx); int cgx_lmac_reset(void *cgxd, int lmac_id, u8 pf_req_flr); +u64 cgx_get_dmacflt_dropped_pktcnt(void *cgx, int lmac_id); u32 cgx_get_fifo_len(void *cgxd); #endif /* CGX_H */ diff --git a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h index 6180e68e1765..f07139e1f4ce 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h @@ -128,6 +128,8 @@ struct mac_ops { u8 *tx_pause, u8 *rx_pause); int (*mac_reset)(void *cgxd, int lmac_id, u8 pf_req_flr); + u64 (*get_dmacflt_dropped_pktcnt)(void *cgxd, int lmac_id); + /* FEC stats */ int (*get_fec_stats)(void *cgxd, int lmac_id, struct cgx_fec_stats_rsp *rsp); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c b/drivers/net/ethernet/marvell/octeontx2/af/rpm.c index 2e9945446199..d46e8ec7230f 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.c @@ -29,18 +29,19 @@ static struct mac_ops rpm_mac_ops = { .mac_get_tx_stats = rpm_get_tx_stats, .get_fec_stats = rpm_get_fec_stats, .mac_enadis_rx_pause_fwding = rpm_lmac_enadis_rx_pause_fwding, - .mac_get_pause_frm_status = rpm_lmac_get_pause_frm_status, - .mac_enadis_pause_frm = rpm_lmac_enadis_pause_frm, - .mac_pause_frm_config = rpm_lmac_pause_frm_config, - .mac_enadis_ptp_config = rpm_lmac_ptp_config, - .mac_rx_tx_enable = rpm_lmac_rx_tx_enable, - .mac_tx_enable = rpm_lmac_tx_enable, - .pfc_config = rpm_lmac_pfc_config, - .mac_get_pfc_frm_cfg = rpm_lmac_get_pfc_frm_cfg, - .mac_reset = rpm_lmac_reset, - .mac_stats_reset = rpm_stats_reset, - .mac_x2p_reset = rpm_x2p_reset, - .mac_enadis_rx = rpm_enadis_rx, + .mac_get_pause_frm_status = rpm_lmac_get_pause_frm_status, + .mac_enadis_pause_frm = rpm_lmac_enadis_pause_frm, + .mac_pause_frm_config = rpm_lmac_pause_frm_config, + .mac_enadis_ptp_config = rpm_lmac_ptp_config, + .mac_rx_tx_enable = rpm_lmac_rx_tx_enable, + .mac_tx_enable = rpm_lmac_tx_enable, + .pfc_config = rpm_lmac_pfc_config, + .mac_get_pfc_frm_cfg = rpm_lmac_get_pfc_frm_cfg, + .mac_reset = rpm_lmac_reset, + .get_dmacflt_dropped_pktcnt = rpm_get_dmacflt_dropped_pktcnt, + .mac_stats_reset = rpm_stats_reset, + .mac_x2p_reset = rpm_x2p_reset, + .mac_enadis_rx = rpm_enadis_rx, }; static struct mac_ops rpm2_mac_ops = { @@ -73,6 +74,7 @@ static struct mac_ops rpm2_mac_ops = { .pfc_config = rpm_lmac_pfc_config, .mac_get_pfc_frm_cfg = rpm_lmac_get_pfc_frm_cfg, .mac_reset = rpm_lmac_reset, + .get_dmacflt_dropped_pktcnt = rpm_get_dmacflt_dropped_pktcnt, .mac_stats_reset = rpm_stats_reset, .mac_x2p_reset = rpm_x2p_reset, .mac_enadis_rx = rpm_enadis_rx, @@ -449,6 +451,20 @@ int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, u64 *tx_stat) return 0; } +u64 rpm_get_dmacflt_dropped_pktcnt(void *rpmd, int lmac_id) +{ + rpm_t *rpm = rpmd; + u64 dmac_flt_stat; + + if (!is_lmac_valid(rpm, lmac_id)) + return 0; + + dmac_flt_stat = is_dev_rpm2(rpm) ? RPM2_CMRX_RX_STAT2 : + RPMX_CMRX_RX_STAT2; + + return rpm_read(rpm, lmac_id, dmac_flt_stat); +} + int rpm_stats_reset(void *rpmd, int lmac_id) { rpm_t *rpm = rpmd; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h b/drivers/net/ethernet/marvell/octeontx2/af/rpm.h index b8d3972e096a..443481010aba 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.h @@ -60,6 +60,7 @@ #define RPMX_MTI_STAT_RX_STAT_PAGES_COUNTERX 0x12000 #define RPMX_MTI_STAT_TX_STAT_PAGES_COUNTERX 0x13000 #define RPMX_MTI_STAT_DATA_HI_CDC 0x10038 +#define RPMX_CMRX_RX_STAT2 0x4010 #define RPM_LMAC_FWI 0xa #define RPM_TX_EN BIT_ULL(0) @@ -129,6 +130,7 @@ int rpm_lmac_enadis_pause_frm(void *rpmd, int lmac_id, u8 tx_pause, u8 rx_pause); int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, u64 *tx_stat); int rpm_get_rx_stats(void *rpmd, int lmac_id, int idx, u64 *rx_stat); +u64 rpm_get_dmacflt_dropped_pktcnt(void *rpmd, int lmac_id); void rpm_lmac_ptp_config(void *rpmd, int lmac_id, bool enable); int rpm_lmac_rx_tx_enable(void *rpmd, int lmac_id, bool enable); int rpm_lmac_tx_enable(void *rpmd, int lmac_id, bool enable); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h index 094227404ef9..9afb7ac8969b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h @@ -1127,6 +1127,7 @@ int rvu_cgx_prio_flow_ctrl_cfg(struct rvu *rvu, u16 pcifunc, u8 tx_pause, u8 rx_ u16 pfc_en); int rvu_cgx_cfg_pause_frm(struct rvu *rvu, u16 pcifunc, u8 tx_pause, u8 rx_pause); void rvu_mac_reset(struct rvu *rvu, u16 pcifunc); +u64 rvu_cgx_get_dmacflt_dropped_pktcnt(void *cgxd, int lmac_id); u32 rvu_cgx_get_lmac_fifolen(struct rvu *rvu, int cgx, int lmac); void cgx_start_linkup(struct rvu *rvu); int npc_get_nixlf_mcam_index(struct npc_mcam *mcam, diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c index 87d21889dc49..41f157ea27f4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c @@ -1356,6 +1356,18 @@ void rvu_mac_reset(struct rvu *rvu, u16 pcifunc) dev_err(rvu->dev, "Failed to reset MAC\n"); } +u64 rvu_cgx_get_dmacflt_dropped_pktcnt(void *cgxd, int lmac_id) +{ + struct mac_ops *mac_ops; + + mac_ops = get_mac_ops(cgxd); + + if (!mac_ops || !mac_ops->get_dmacflt_dropped_pktcnt) + return 0; + + return mac_ops->get_dmacflt_dropped_pktcnt(cgxd, lmac_id); +} + /* Do not allow CGX-mapped VFs to overwrite PKIND when special parse kinds * (HiGig, EDSA, etc.) are in use on the shared LMAC. VFs must not program * NPC_TX_DEF_PKIND on NIX_AF_LFX_TX_PARSE_CFG in that case: the PF owns diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c index 22ee99676879..f6320d6b959f 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c @@ -2963,8 +2963,10 @@ static int cgx_print_dmac_flt(struct seq_file *s, int lmac_id) struct rvu_cgx_lmac_dbgfs_ctx *dctx = s->private; struct rvu *rvu = dctx->rvu; struct pci_dev *pdev = NULL; + struct mac_ops *mac_ops; void *cgxd = dctx->cgxd; char *bcast, *mcast; + u64 drop_cnt; u16 index, domain; u8 dmac[ETH_ALEN]; u64 cfg, mac; @@ -3003,6 +3005,12 @@ static int cgx_print_dmac_flt(struct seq_file *s, int lmac_id) } } + mac_ops = get_mac_ops(cgxd); + if (mac_ops && mac_ops->get_dmacflt_dropped_pktcnt) { + drop_cnt = rvu_cgx_get_dmacflt_dropped_pktcnt(cgxd, lmac_id); + seq_printf(s, "\nDMAC filter drop count: %llu\n", drop_cnt); + } + pci_dev_put(pdev); return 0; } From b910d4220d42ed8e67b79adec6349fc7020e118d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20B=2E=20Marli=C3=A8re=20=28SUSE=29?= Date: Tue, 1 Sep 2026 08:31:58 -0300 Subject: [PATCH 0206/2126] selftests/net: Fix flaky bind_wildcard due to ephemeral port race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bind_wildcard picks an ephemeral port by binding fd[0] with port 0, reads it back with getsockname(), and then reuses that exact port number for the other addresses/families in fd[1..7]. This all happens in the default network namespace, so unrelated processes on the same host are drawing from the very same ephemeral port range (net.ipv4.ip_local_port_range) at the same time. Such a process can independently get assigned that exact port number on a different, non-conflicting address in the short window between fd[0]'s bind() and fd[1]'s, making fd[1]'s bind() fail with EADDRINUSE for reasons that have nothing to do with the wildcard-bind behavior under test, e.g.: # bind_wildcard.c:775:plain:Expected ret (-1) == 0 (0) # plain: Test terminated by assertion not ok N bind_wildcard.v6_local_v4_local.plain Fix it the same way so_incoming_cpu.c, tcp_port_share.c and reuseport_dualstack.c already do: unshare into a fresh network namespace and bring lo up, so there is nobody else to race with for the port. Signed-off-by: Ricardo B. Marlière (SUSE) Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/bind_wildcard.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/net/bind_wildcard.c b/tools/testing/selftests/net/bind_wildcard.c index 7d11548b2c61..be3298c791b2 100644 --- a/tools/testing/selftests/net/bind_wildcard.c +++ b/tools/testing/selftests/net/bind_wildcard.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright Amazon.com Inc. or its affiliates. */ +#define _GNU_SOURCE +#include #include #include @@ -716,6 +718,9 @@ static void setup_addr(FIXTURE_DATA(bind_wildcard) *self, int i, FIXTURE_SETUP(bind_wildcard) { + ASSERT_EQ(unshare(CLONE_NEWNET), 0); + ASSERT_EQ(system("ip link set lo up"), 0); + setup_addr(self, 0, variant->family[0], variant->addr[0]); setup_addr(self, 1, variant->family[1], variant->addr[1]); From 9eab111e765729e93087ff86a2ec9b2ae42d0fa5 Mon Sep 17 00:00:00 2001 From: Christian Melendez Date: Wed, 2 Sep 2026 21:37:11 +0200 Subject: [PATCH 0207/2126] Documentation: netvsc: Remove stale "not yet supported" XDP_REDIRECT note netvsc_run_xdp() in drivers/net/hyperv/netvsc_bpf.c has handled XDP_REDIRECT since commit 1cb9d3b6185b ("hv_netvsc: Add support for XDP_REDIRECT"), and netvsc_drv.c advertises NETDEV_XDP_ACT_REDIRECT in xdp_features. Remove the stale note. Link: https://patch.msgid.link/20260831200357.45390-1-chrismelnu@gmail.com Signed-off-by: Christian Melendez Signed-off-by: Jakub Kicinski --- .../networking/device_drivers/ethernet/microsoft/netvsc.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Documentation/networking/device_drivers/ethernet/microsoft/netvsc.rst b/Documentation/networking/device_drivers/ethernet/microsoft/netvsc.rst index fc5acd427a5d..616f808e885b 100644 --- a/Documentation/networking/device_drivers/ethernet/microsoft/netvsc.rst +++ b/Documentation/networking/device_drivers/ethernet/microsoft/netvsc.rst @@ -116,5 +116,3 @@ XDP support before running XDP:: ethtool -K eth0 lro off - - XDP_REDIRECT action is not yet supported. From cb145191e9d3f29e14cb7386c57181c3dab1bb68 Mon Sep 17 00:00:00 2001 From: Chia-Yu Chang Date: Mon, 31 Aug 2026 18:52:29 +0200 Subject: [PATCH 0208/2126] tcp: Replace min_tso_segs() with tso_segs() CC callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch replaces the existing min_tso_segs() callback with a new tso_segs() callback, allowing congestion control algorithms to provide an explicit TSO segment count for each data burst and bypass tcp_tso_autosize(). The resulting tso_segs value is clamped to [1, sk->sk_gso_max_segs], preventing congestion-control implementations from returning an invalid zero-segment value. This change has the following impacts on BPF struct_ops users: - The callback is renamed from min_tso_segs() to tso_segs() - The signature gains an extra u32 mss_now argument - The return value semantics is changed from "floor value passed into tcp_tso_autosize()" to "final tso_segs value", bypassing autosizing As a result, existing BPF programs must be updated, because returning a small constant will now directly limit the final tso_segs value instead of specifying the minimum value passed to tcp_tso_autosize(). Signed-off-by: Chia-Yu Chang Signed-off-by: Ilpo Järvinen Reviewed-by: Emil Tsalapatis Signed-off-by: Jakub Kicinski --- include/net/tcp.h | 15 +++++++++++++-- net/ipv4/bpf_tcp_ca.c | 4 ++-- net/ipv4/tcp_bbr.c | 13 ++++++++++--- net/ipv4/tcp_output.c | 18 +++++++++--------- .../testing/selftests/bpf/progs/tcp_ca_kfunc.c | 8 ++++---- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 436495ff2271..5e5f5f9b89a3 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -823,6 +823,9 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); unsigned int tcp_current_mss(struct sock *sk); u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when); +u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, + int min_tso_segs); + /* Bound MSS / TSO packet size with the half of the window */ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) { @@ -1360,8 +1363,16 @@ struct tcp_congestion_ops { /* hook for packet ack accounting (optional) */ void (*pkts_acked)(struct sock *sk, const struct ack_sample *sample); - /* override sysctl_tcp_min_tso_segs (optional) */ - u32 (*min_tso_segs)(struct sock *sk); + /* Override tcp_tso_autosize() (optional) + * + * If provided, this callback supplies the TSO segment target count + * instead of using tcp_tso_autosize(). The returned value is + * subsequently clamped to [1, sk->sk_gso_max_segs] by the caller. + * + * For the kernel callback path, mss_now originates from + * tcp_current_mss() and should never be zero. + */ + u32 (*tso_segs)(struct sock *sk, u32 mss_now); /* new value of cwnd after loss (required) */ u32 (*undo_cwnd)(struct sock *sk); diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c index 791e15063237..ed4fea98dfde 100644 --- a/net/ipv4/bpf_tcp_ca.c +++ b/net/ipv4/bpf_tcp_ca.c @@ -284,7 +284,7 @@ static void bpf_tcp_ca_pkts_acked(struct sock *sk, const struct ack_sample *samp { } -static u32 bpf_tcp_ca_min_tso_segs(struct sock *sk) +static u32 bpf_tcp_ca_tso_segs(struct sock *sk, u32 mss_now) { return 0; } @@ -320,7 +320,7 @@ static struct tcp_congestion_ops __bpf_ops_tcp_congestion_ops = { .cwnd_event_tx_start = bpf_tcp_ca_cwnd_event_tx_start, .in_ack_event = bpf_tcp_ca_in_ack_event, .pkts_acked = bpf_tcp_ca_pkts_acked, - .min_tso_segs = bpf_tcp_ca_min_tso_segs, + .tso_segs = bpf_tcp_ca_tso_segs, .cong_control = bpf_tcp_ca_cong_control, .undo_cwnd = bpf_tcp_ca_undo_cwnd, .sndbuf_expand = bpf_tcp_ca_sndbuf_expand, diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c index 82378a2bfd1e..ecf11be46f38 100644 --- a/net/ipv4/tcp_bbr.c +++ b/net/ipv4/tcp_bbr.c @@ -297,11 +297,18 @@ static void bbr_set_pacing_rate(struct sock *sk, u32 bw, int gain) } /* override sysctl_tcp_min_tso_segs */ -__bpf_kfunc static u32 bbr_min_tso_segs(struct sock *sk) +static u32 bbr_min_tso_segs(struct sock *sk) { return READ_ONCE(sk->sk_pacing_rate) < (bbr_min_tso_rate >> 3) ? 1 : 2; } +__bpf_kfunc static u32 bbr_tso_segs(struct sock *sk, u32 mss_now) +{ + if (unlikely(!mss_now)) + return bbr_min_tso_segs(sk); + return tcp_tso_autosize(sk, mss_now, bbr_min_tso_segs(sk)); +} + static u32 bbr_tso_segs_goal(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); @@ -1151,7 +1158,7 @@ static struct tcp_congestion_ops tcp_bbr_cong_ops __read_mostly = { .undo_cwnd = bbr_undo_cwnd, .cwnd_event_tx_start = bbr_cwnd_event_tx_start, .ssthresh = bbr_ssthresh, - .min_tso_segs = bbr_min_tso_segs, + .tso_segs = bbr_tso_segs, .get_info = bbr_get_info, .set_state = bbr_set_state, }; @@ -1163,7 +1170,7 @@ BTF_ID_FLAGS(func, bbr_sndbuf_expand) BTF_ID_FLAGS(func, bbr_undo_cwnd) BTF_ID_FLAGS(func, bbr_cwnd_event_tx_start) BTF_ID_FLAGS(func, bbr_ssthresh) -BTF_ID_FLAGS(func, bbr_min_tso_segs) +BTF_ID_FLAGS(func, bbr_tso_segs) BTF_ID_FLAGS(func, bbr_set_state) BTF_KFUNCS_END(tcp_bbr_check_kfunc_ids) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index d960e3de7d50..ead64b7588a2 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2253,8 +2253,8 @@ static bool tcp_nagle_check(bool partial, const struct tcp_sock *tp, * for every 2^9 usec (aka 512 us) of RTT, so that the RTT-based allowance * is below 1500 bytes after 6 * ~500 usec = 3ms. */ -static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, - int min_tso_segs) +u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, + int min_tso_segs) { unsigned long bytes; u32 r; @@ -2269,6 +2269,7 @@ static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, return max_t(u32, bytes / mss_now, min_tso_segs); } +EXPORT_SYMBOL_GPL(tcp_tso_autosize); /* Return the number of segments we want in the skb we are transmitting. * See if congestion control module wants to decide; otherwise, autosize. @@ -2276,14 +2277,13 @@ static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, static u32 tcp_tso_segs(struct sock *sk, unsigned int mss_now) { const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; - u32 min_tso, tso_segs; + u32 tso_segs; - min_tso = ca_ops->min_tso_segs ? - ca_ops->min_tso_segs(sk) : - READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_tso_segs); - - tso_segs = tcp_tso_autosize(sk, mss_now, min_tso); - return min_t(u32, tso_segs, sk->sk_gso_max_segs); + tso_segs = ca_ops->tso_segs ? + ca_ops->tso_segs(sk, mss_now) : + tcp_tso_autosize(sk, mss_now, + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_tso_segs)); + return clamp_t(u32, tso_segs, 1, sk->sk_gso_max_segs); } /* Returns the portion of skb which can be sent right away */ diff --git a/tools/testing/selftests/bpf/progs/tcp_ca_kfunc.c b/tools/testing/selftests/bpf/progs/tcp_ca_kfunc.c index 0a3e9d35bf6f..58262e490336 100644 --- a/tools/testing/selftests/bpf/progs/tcp_ca_kfunc.c +++ b/tools/testing/selftests/bpf/progs/tcp_ca_kfunc.c @@ -10,7 +10,7 @@ extern u32 bbr_sndbuf_expand(struct sock *sk) __ksym; extern u32 bbr_undo_cwnd(struct sock *sk) __ksym; extern void bbr_cwnd_event_tx_start(struct sock *sk) __ksym; extern u32 bbr_ssthresh(struct sock *sk) __ksym; -extern u32 bbr_min_tso_segs(struct sock *sk) __ksym; +extern u32 bbr_tso_segs(struct sock *sk, u32 mss_now) __ksym; extern void bbr_set_state(struct sock *sk, u8 new_state) __ksym; extern void dctcp_init(struct sock *sk) __ksym; @@ -90,9 +90,9 @@ u32 BPF_PROG(ssthresh, struct sock *sk) } SEC("struct_ops") -u32 BPF_PROG(min_tso_segs, struct sock *sk) +u32 BPF_PROG(tso_segs, struct sock *sk, u32 mss_now) { - return bbr_min_tso_segs(sk); + return bbr_tso_segs(sk, mss_now); } SEC("struct_ops") @@ -120,7 +120,7 @@ struct tcp_congestion_ops tcp_ca_kfunc = { .cwnd_event = (void *)cwnd_event, .cwnd_event_tx_start = (void *)cwnd_event_tx_start, .ssthresh = (void *)ssthresh, - .min_tso_segs = (void *)min_tso_segs, + .tso_segs = (void *)tso_segs, .set_state = (void *)set_state, .pkts_acked = (void *)pkts_acked, .name = "tcp_ca_kfunc", From f69a0944415fdac663565482d56250c5350f130b Mon Sep 17 00:00:00 2001 From: Chia-Yu Chang Date: Mon, 31 Aug 2026 18:52:30 +0200 Subject: [PATCH 0209/2126] bpf: make tcp_tso_autosize() available to BPF congestion controls Expose tcp_tso_autosize() as a BPF kfunc and register it in the TCP congestion-control kfunc set. This allows BPF congestion controls to reuse the kernel TSO autosizing logic while applying their own minimum TSO segment policy. To make the kfunc robust against BPF-provided inputs, min_tso_segs is sanitized to at least 1 and mss_now == 0 returns the sanitized minimum value instead of performing autosizing. Signed-off-by: Chia-Yu Chang Signed-off-by: Jakub Kicinski --- net/ipv4/bpf_tcp_ca.c | 1 + net/ipv4/tcp_output.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c index ed4fea98dfde..9deed2244c2d 100644 --- a/net/ipv4/bpf_tcp_ca.c +++ b/net/ipv4/bpf_tcp_ca.c @@ -194,6 +194,7 @@ BTF_ID_FLAGS(func, tcp_reno_cong_avoid) BTF_ID_FLAGS(func, tcp_reno_undo_cwnd) BTF_ID_FLAGS(func, tcp_slow_start) BTF_ID_FLAGS(func, tcp_cong_avoid_ai) +BTF_ID_FLAGS(func, tcp_tso_autosize) BTF_KFUNCS_END(bpf_tcp_ca_check_kfunc_ids) static const struct btf_kfunc_id_set bpf_tcp_ca_kfunc_set = { diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index ead64b7588a2..00417a429222 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2252,13 +2252,21 @@ static bool tcp_nagle_check(bool partial, const struct tcp_sock *tp, * in bigger TSO bursts. We we cut the RTT-based allowance in half * for every 2^9 usec (aka 512 us) of RTT, so that the RTT-based allowance * is below 1500 bytes after 6 * ~500 usec = 3ms. + * + * The min_tso_segs is floored to 1 to avoid surprising conversion. Also, + * BPF callers may pass mss_now == 0. In that case the function returns the + * sanitized min_tso_segs value and skips autosizing. */ -u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, - int min_tso_segs) +__bpf_kfunc u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, + int min_tso_segs) { + u32 min_tso = max(min_tso_segs, 1); unsigned long bytes; u32 r; + if (unlikely(!mss_now)) + return min_tso; + bytes = READ_ONCE(sk->sk_pacing_rate) >> READ_ONCE(sk->sk_pacing_shift); r = tcp_min_rtt(tcp_sk(sk)) >> READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_tso_rtt_log); @@ -2267,7 +2275,7 @@ u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, bytes = min_t(unsigned long, bytes, sk->sk_gso_max_size); - return max_t(u32, bytes / mss_now, min_tso_segs); + return max_t(u32, bytes / mss_now, min_tso); } EXPORT_SYMBOL_GPL(tcp_tso_autosize); From 2e9ff7bb668b6f62f4789718f70fd1ec2eb87c12 Mon Sep 17 00:00:00 2001 From: Jinjie Ruan Date: Wed, 2 Sep 2026 15:33:33 +0800 Subject: [PATCH 0210/2126] 8021q: Fix data race when publishing vlan net_device pointers A plain C read and assignment of the net_device pointer in the vlan_devices_arrays leaf entries lack proper atomicity and ordering barriers. A concurrent lockless reader on the packet receive fast-path could observe a torn or partially initialized net_device pointer, leading to a potential out-of-bounds read or kernel panic. The data race occurs between the netlink/ioctl configuration paths (holding the per-netns rtnl_nets_lock or RTNL lock) and the softirq receive fast-path (holding rcu_read_lock()): CPU 0 (Writer, rtnl_nets_lock/RTNL) CPU 1 (Reader, rcu_read_lock()) ----------------------------------- ------------------------------- rtnetlink_rcv_msg() // RTM_NEWLINK handler with RTNL_FLAG_DOIT_PERNET rtnl_newlink() ops->newlink() == vlan_newlink() OR vlan_ioctl_handler() [ADD_VLAN_CMD] -> register_vlan_device() register_vlan_dev() vlan_group_set_device() netif_receive_skb_core() vlan_do_receive() vlan_find_dev() __vlan_group_get_device() // Speculative / torn read [Loads bad net_device *] [Plain C store] array[vlan_id] = dev; // Dereferences bad pointer // during device status check vlan_dev->flags (PANIC!) Fix this by using rcu_assign_pointer() in vlan_group_set_device() and rcu_dereference_raw() in __vlan_group_get_device() to enforce proper ordering and memory atomicity for the leaf entry traversal. Link: https://sashiko.dev/#/patchset/20260825095422.3166067-1-ruanjinjie%40huawei.com Signed-off-by: Jinjie Ruan Reviewed-by: Kuniyuki Iwashima Signed-off-by: Jakub Kicinski --- net/8021q/vlan.c | 2 +- net/8021q/vlan.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 2d2efb877975..6df80cad40a2 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -49,7 +49,7 @@ const char vlan_version[] = DRV_VERSION; static int vlan_group_prealloc_vid(struct vlan_group *vg, __be16 vlan_proto, u16 vlan_id) { - struct net_device **array; + struct net_device __rcu **array; unsigned int vidx; unsigned int size; int pidx; diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index c41caaf94095..3cb4c8294130 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -22,8 +22,8 @@ enum vlan_protos { struct vlan_group { unsigned int nr_vlan_devs; struct hlist_node hlist; /* linked list */ - struct net_device **vlan_devices_arrays[VLAN_PROTO_NUM] - [VLAN_GROUP_ARRAY_SPLIT_PARTS]; + struct net_device __rcu **vlan_devices_arrays[VLAN_PROTO_NUM] + [VLAN_GROUP_ARRAY_SPLIT_PARTS]; }; struct vlan_info { @@ -54,7 +54,7 @@ static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg, unsigned int pidx, u16 vlan_id) { - struct net_device **array; + struct net_device __rcu **array; array = vg->vlan_devices_arrays[pidx] [vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; @@ -62,7 +62,7 @@ static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg, /* paired with smp_wmb() in vlan_group_prealloc_vid() */ smp_rmb(); - return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL; + return array ? rcu_dereference_raw(array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN]) : NULL; } static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, @@ -82,13 +82,13 @@ static inline void vlan_group_set_device(struct vlan_group *vg, struct net_device *dev) { int pidx = vlan_proto_idx(vlan_proto); - struct net_device **array; + struct net_device __rcu **array; if (!vg || pidx < 0) return; array = vg->vlan_devices_arrays[pidx] [vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; - array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; + rcu_assign_pointer(array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN], dev); } /* Must be invoked with rcu_read_lock or with RTNL. */ From d199b0d0bb01118f84ca8bccc5419097d67cd18b Mon Sep 17 00:00:00 2001 From: Jinjie Ruan Date: Wed, 2 Sep 2026 15:33:34 +0800 Subject: [PATCH 0211/2126] 8021q: publish vlan_devices_arrays entries with acquire/release Replace the smp_wmb()/smp_rmb() barrier pair with smp_store_release()/smp_load_acquire() on vg->vlan_devices_arrays[pidx][vidx]. vlan_group_prealloc_vid() publishes the array pointer via release; __vlan_group_get_device() acquires it before accessing the array, ensuring the allocated entries are visible. Signed-off-by: Jinjie Ruan Reviewed-by: Kuniyuki Iwashima Signed-off-by: Jakub Kicinski --- net/8021q/vlan.c | 6 ++---- net/8021q/vlan.h | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 6df80cad40a2..ec9a7cc8afc7 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -70,10 +70,8 @@ static int vlan_group_prealloc_vid(struct vlan_group *vg, if (array == NULL) return -ENOBUFS; - /* paired with smp_rmb() in __vlan_group_get_device() */ - smp_wmb(); - - vg->vlan_devices_arrays[pidx][vidx] = array; + /* paired with smp_load_acquire() in __vlan_group_get_device() */ + smp_store_release(&vg->vlan_devices_arrays[pidx][vidx], array); return 0; } diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 3cb4c8294130..d874ab323d32 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -56,11 +56,9 @@ static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg, { struct net_device __rcu **array; - array = vg->vlan_devices_arrays[pidx] - [vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; - - /* paired with smp_wmb() in vlan_group_prealloc_vid() */ - smp_rmb(); + /* Pairs with smp_store_release() in vlan_group_prealloc_vid() */ + array = smp_load_acquire(&vg->vlan_devices_arrays[pidx] + [vlan_id / VLAN_GROUP_ARRAY_PART_LEN]); return array ? rcu_dereference_raw(array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN]) : NULL; } From 31f961de2f90fbf52eb2d4e15b3eeaa09f9b4fc2 Mon Sep 17 00:00:00 2001 From: Li RongQing Date: Wed, 2 Sep 2026 10:34:29 +0800 Subject: [PATCH 0212/2126] net/mlx5: Use dma_wmb() for completion queue doorbell updates dma_*() barriers are specifically for ordering writes to DMA coherent memory that is accessible to both the CPU and DMA capable devices. The dma_wmb() barrier is lighter than wmb() on some architectures because it only ensures ordering for DMA writes, not for all writes including MMIO accesses. In the MLX5 driver, completion queue (CQ) doorbell records are allocated as DMA coherent memory via mlx5_dma_zalloc_coherent_node(). The CQ update pattern is: 1. Update CQ space (device reads via DMA) 2. Update doorbell record (device reads via DMA) 3. Memory barrier 4. Enable more CQEs Since only DMA coherent memory accesses are involved (no MMIO accesses follow), we can safely use dma_wmb() instead of wmb(). This change improves performance slightly on architectures where dma_wmb() is lighter than wmb(). Signed-off-by: Li RongQing Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260902023429.1717-1-lirongqing@baidu.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_tx.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c index 723f66a6bd63..17084d76209e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c @@ -259,7 +259,7 @@ static bool mlx5e_ptp_poll_ts_cq(struct mlx5e_cq *cq, int napi_budget) mlx5_cqwq_update_db_record(cqwq); /* ensure cq space is freed before enabling more cqes */ - wmb(); + dma_wmb(); while (metadata_buff_sz > 0) mlx5e_ptp_metadata_fifo_push(&ptpsq->metadata_freelist, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c index 77ea51bfbaae..ee0986bd5c18 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c @@ -817,7 +817,7 @@ bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq) mlx5_cqwq_update_db_record(&cq->wq); /* ensure cq space is freed before enabling more cqes */ - wmb(); + dma_wmb(); sq->cc = sqcc; return (i == MLX5E_TX_CQ_POLL_BUDGET); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index 7bd0606a5253..e3f915beebe1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -2509,7 +2509,7 @@ int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget) mlx5_cqwq_update_db_record(cqwq); /* ensure cq space is freed before enabling more cqes */ - wmb(); + dma_wmb(); return work_done; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c index 0b5e600e4a6a..14479da98f42 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c @@ -849,7 +849,7 @@ bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget) mlx5_cqwq_update_db_record(&cq->wq); /* ensure cq space is freed before enabling more cqes */ - wmb(); + dma_wmb(); sq->dma_fifo_cc = dma_fifo_cc; sq->cc = sqcc; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c index 1f6bde5d7626..1341874ee58a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c @@ -384,7 +384,7 @@ static inline void mlx5_fpga_conn_cqes(struct mlx5_fpga_conn *conn, mlx5_fpga_dbg(conn->fdev, "Re-arming CQ with cc# %u\n", conn->cq.wq.cc); /* ensure cq space is freed before enabling more cqes */ - wmb(); + dma_wmb(); mlx5_fpga_conn_arm_cq(conn); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c index 614cd57a40d7..8f7a89ae4ad8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c @@ -421,7 +421,7 @@ int mlx5_aso_poll_cq(struct mlx5_aso *aso, bool with_data) mlx5_cqwq_update_db_record(&cq->wq); /* ensure cq space is freed before enabling more cqes */ - wmb(); + dma_wmb(); if (with_data) aso->cc += MLX5_ASO_WQEBBS_DATA; From 857fbd765c65bb7de018f7bf44f565e6125d785e Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 1 Sep 2026 20:36:15 +0200 Subject: [PATCH 0213/2126] batman-adv: tt: clarify kernel doc for batadv_tt_local_set_pending_event() The function batadv_tt_local_set_pending_event() is no longer setting the BATADV_TT_CLIENT_PENDING because it must be done with the flags_lock held. The kernel-doc must therefore correctly state that the flag must already be set. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=12 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 6c65d195f375..12ea557cb803 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1422,13 +1422,12 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb) /** * batadv_tt_local_set_pending_event() - trigger events for TT pending removal * @bat_priv: the bat priv with all the mesh interface information - * @tt_local_entry: local TT entry to mark + * @tt_local_entry: local TT entry which was marked as BATADV_TT_CLIENT_PENDING * @flags: TT change flags to announce together with the pending removal * @message: debug message describing the reason for the change * - * Schedule the TT change announcement for the entry. The entry is kept in the - * local table until the next TTVN increment so that a consistency-check - * response can still be answered. + * Schedule the TT change announcement for the entry. The caller must already + * have added BATADV_TT_CLIENT_PENDING to the @tt_local_entry */ static void batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, From 271f3730fc8756037b51ff1a16950cd8797766a2 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 1 Sep 2026 19:14:49 +0200 Subject: [PATCH 0214/2126] batman-adv: bat_iv: fix ogm_neigh_is_sob parameters references The batadv_iv_ogm_neigh_is_sob() kernel-doc summary line is still referencing the old parameter names "neigh1" and "neigh2". But these are now called "candidate" and "reference". Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=5 Signed-off-by: Sven Eckelmann --- net/batman-adv/bat_iv_ogm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 3fe09b4c3046..89b499f7a37d 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -2422,8 +2422,8 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1, } /** - * batadv_iv_ogm_neigh_is_sob() - check if neigh1 is similarly good or better - * than neigh2 from the metric prospective + * batadv_iv_ogm_neigh_is_sob() - check if @candidate is similarly good or + * better than @reference from the metric prospective * @candidate: the first neighbor object of the comparison * @if_outgoing_cand: outgoing interface for the @candidate neighbor * @reference: the second neighbor object of the comparison From 4c0a6a5b77152dce07804a60a453c779619a79d5 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 1 Sep 2026 18:29:29 +0200 Subject: [PATCH 0215/2126] batman-adv: bla: avoid double free after failed backbone_hash alloc When batadv_bla_init() fails to initialize the backbone_hash, it is freeing the (previously) allocated claim_hash. The initialization function will then return an error and the net_device initialization will stop. The destructor will be called instead and (indirectly via batadv_mesh_free() -> batadv_bla_free()) will try to free the bat_priv->bla.claim_hash again. The pointer must therefore be set to NULL after freeing it in the initialization error path. Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=6 Signed-off-by: Sven Eckelmann --- net/batman-adv/bridge_loop_avoidance.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index ad6ab4a50658..a96f269da8d3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -1625,6 +1625,7 @@ int batadv_bla_init(struct batadv_priv *bat_priv) bat_priv->bla.backbone_hash = batadv_hash_new(32); if (!bat_priv->bla.backbone_hash) { batadv_hash_destroy(bat_priv->bla.claim_hash); + bat_priv->bla.claim_hash = NULL; return -ENOMEM; } From 6d7f71ae4cdcbb22f541638057299fe26c451e65 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 1 Sep 2026 19:33:18 +0200 Subject: [PATCH 0216/2126] batman-adv: correct batadv_hash_remove kdoc return type Not the data is returned after a batadv_hash_remove() but the pointer to the hlist_node which was used to look up the entry in the hash. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=8 Signed-off-by: Sven Eckelmann --- net/batman-adv/hash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h index e67afe01304c..45a432cc1578 100644 --- a/net/batman-adv/hash.h +++ b/net/batman-adv/hash.h @@ -137,7 +137,7 @@ out: * data could be the structure you use with just the key filled, we just need * the key for comparing. * - * Return: returns pointer to data on success, so you can remove the used + * Return: returns pointer to hlist_node on success, so you can remove the used * structure yourself, or NULL on error */ static inline void *batadv_hash_remove(struct batadv_hashtable *hash, From 7b26ff20073901b4e7a0384464da784a5c94d56e Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 3 Sep 2026 18:33:59 -0700 Subject: [PATCH 0217/2126] psp: refactor psp_dev_tx_key_del() No functional changes. Lift the list deletion and tx spi validation code into callers. Deferred key deletion code paths will need similar checks that a tx key needs removal from the underlying device, but will diverge when it comes to list handling and when to call psp_dev_ops::tx_key_del(). Also, move the predicate for tx key deletion into a helper for readability and reuse in later patches. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260903-psp-prep-v1-1-d47e9c4c375d@gmail.com Signed-off-by: Jakub Kicinski --- net/psp/psp.h | 6 ++++++ net/psp/psp_main.c | 7 +++++-- net/psp/psp_sock.c | 11 ++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/net/psp/psp.h b/net/psp/psp.h index 86eeba823ced..8acf9ca84b55 100644 --- a/net/psp/psp.h +++ b/net/psp/psp.h @@ -53,4 +53,10 @@ static inline bool psp_dev_is_registered(struct psp_dev *psd) return !!psd->ops; } +static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas) +{ + lockdep_assert_held(&pas->psd->lock); + return pas->tx.spi; +} + #endif /* __PSP_PSP_H */ diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c index c9c1a8826b7f..2556f0d46ef4 100644 --- a/net/psp/psp_main.c +++ b/net/psp/psp_main.c @@ -147,8 +147,11 @@ void psp_dev_unregister(struct psp_dev *psd) list_splice_init(&psd->active_assocs, &psd->prev_assocs); list_splice_init(&psd->prev_assocs, &psd->stale_assocs); - list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list) - psp_dev_tx_key_del(psd, pas); + list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list) { + if (psp_assoc_needs_tx_key_del(pas)) + psp_dev_tx_key_del(psd, pas); + list_del(&pas->assocs_list); + } list_for_each_entry_safe(entry, entry_tmp, &psd->assoc_dev_list, dev_list) { diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c index 1a2a6b7516b0..045389671d7f 100644 --- a/net/psp/psp_sock.c +++ b/net/psp/psp_sock.c @@ -85,9 +85,7 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas, void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas) { - if (pas->tx.spi) - psd->ops->tx_key_del(psd, pas); - list_del(&pas->assocs_list); + psd->ops->tx_key_del(psd, pas); } static void psp_assoc_free(struct work_struct *work) @@ -96,8 +94,11 @@ static void psp_assoc_free(struct work_struct *work) struct psp_dev *psd = pas->psd; mutex_lock(&psd->lock); - if (psp_dev_is_registered(psd)) - psp_dev_tx_key_del(psd, pas); + if (psp_dev_is_registered(psd)) { + if (psp_assoc_needs_tx_key_del(pas)) + psp_dev_tx_key_del(psd, pas); + list_del(&pas->assocs_list); + } mutex_unlock(&psd->lock); psp_dev_put(psd); kfree(pas); From 4d3a7d1104eb99c0f58d19c2e671d183be5d7f2f Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 3 Sep 2026 18:34:00 -0700 Subject: [PATCH 0218/2126] psp: move code from psp_sock_assoc_set_tx() into helper functions No functional changes. Lift code that needs to be called from both initial tx establishment and tx rekeying into functions that can be reused in both paths. The plaintext in recv queue checks and mss adjustment only run on initial tx keying. The dummy psp_assoc machinery will be used in both paths. psp_dev_tx_key_add() absorbs the dummy assoc machinery, as its main purpose is to populate the device specific psp_assoc:drv_data. psp_assoc_set_tx() exists so that a future change can allow psp_dev_tx_key_add() to be skipped entirely for devices that don't use an SADB, while copying of the tx spi and key into the assoc needs to happen regardless of SADB vs. no SADB. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260903-psp-prep-v1-2-d47e9c4c375d@gmail.com Signed-off-by: Jakub Kicinski --- net/psp/psp_sock.c | 102 +++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c index 045389671d7f..36eb06faa54a 100644 --- a/net/psp/psp_sock.c +++ b/net/psp/psp_sock.c @@ -78,9 +78,28 @@ static struct psp_assoc *psp_assoc_dummy(struct psp_assoc *pas) } static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas, + struct psp_key_parsed *key, struct netlink_ext_ack *extack) { - return psd->ops->tx_key_add(psd, pas, extack); + struct psp_assoc *dummy; + int err; + + /* Pass a fake association to drivers to make sure they don't + * try to store pointers to it. For re-keying we'll need to + * re-allocate the assoc structures. + */ + dummy = psp_assoc_dummy(pas); + if (!dummy) + return -ENOMEM; + + memcpy(&dummy->tx, key, sizeof(*key)); + err = psd->ops->tx_key_add(psd, dummy, extack); + if (!err) + memcpy(pas->drv_data, dummy->drv_data, + psd->caps->assoc_drv_spc); + + kfree(dummy); + return err; } void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas) @@ -156,6 +175,20 @@ exit_unlock: return err; } +static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas, + struct psp_key_parsed *key, + struct netlink_ext_ack *extack) +{ + int err; + + err = psp_dev_tx_key_add(psd, pas, key, extack); + if (err) + return err; + + memcpy(&pas->tx, key, sizeof(*key)); + return 0; +} + static int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas) { struct psp_skb_ext *pse; @@ -175,12 +208,40 @@ static int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas) return 0; } +static int +psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas, + struct psp_key_parsed *key, struct netlink_ext_ack *extack) +{ + struct inet_connection_sock *icsk; + int err; + + err = psp_sock_recv_queue_check(sk, pas); + if (err) { + NL_SET_ERR_MSG(extack, + "Socket has incompatible segments already in the recv queue"); + return err; + } + + err = psp_assoc_set_tx(psd, pas, key, extack); + if (err) + return err; + + WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit); + tcp_write_collapse_fence(sk); + pas->upgrade_seq = tcp_sk(sk)->rcv_nxt; + + icsk = inet_csk(sk); + icsk->icsk_ext_hdr_len += psp_sk_overhead(sk); + icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); + + return err; +} + int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd, u32 version, struct psp_key_parsed *key, struct netlink_ext_ack *extack) { - struct inet_connection_sock *icsk; - struct psp_assoc *pas, *dummy; + struct psp_assoc *pas; int err; lock_sock(sk); @@ -208,40 +269,7 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd, goto exit_unlock; } - err = psp_sock_recv_queue_check(sk, pas); - if (err) { - NL_SET_ERR_MSG(extack, "Socket has incompatible segments already in the recv queue"); - goto exit_unlock; - } - - /* Pass a fake association to drivers to make sure they don't - * try to store pointers to it. For re-keying we'll need to - * re-allocate the assoc structures. - */ - dummy = psp_assoc_dummy(pas); - if (!dummy) { - err = -ENOMEM; - goto exit_unlock; - } - - memcpy(&dummy->tx, key, sizeof(*key)); - err = psp_dev_tx_key_add(psd, dummy, extack); - if (err) - goto exit_free_dummy; - - memcpy(pas->drv_data, dummy->drv_data, psd->caps->assoc_drv_spc); - memcpy(&pas->tx, key, sizeof(*key)); - - WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit); - tcp_write_collapse_fence(sk); - pas->upgrade_seq = tcp_sk(sk)->rcv_nxt; - - icsk = inet_csk(sk); - icsk->icsk_ext_hdr_len += psp_sk_overhead(sk); - icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); - -exit_free_dummy: - kfree(dummy); + err = psp_sock_set_tx_key(sk, psd, pas, key, extack); exit_unlock: release_sock(sk); return err; From 1e16b303109f085880a649842bc80b08214e90a3 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 3 Sep 2026 18:34:01 -0700 Subject: [PATCH 0219/2126] psp: allow drivers to omit tx key add/del ops Drivers that don't use an SADB for tx key storage don't have a use for psp_dev_ops::tx_key_add and psp_dev_ops::tx_key_del. Allowing drivers to leave these as NULL gives PSP core a simple way to determine whether a driver utilizes an SADB, which in turn could affect how PSP core chooses to handle certain situations. For example: - deciding if tx key deletion needs to be delayed during a rekeying event to avoid in-flight packets using old key handles. - choosing whether or not to report device stats like SADB usage to userspace, which only make sense if the driver uses on-device key storage. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260903-psp-prep-v1-3-d47e9c4c375d@gmail.com Signed-off-by: Jakub Kicinski --- include/net/psp/types.h | 4 ++++ net/psp/psp.h | 8 +++++++- net/psp/psp_main.c | 6 +++--- net/psp/psp_sock.c | 8 +++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/net/psp/types.h b/include/net/psp/types.h index 87991a1ea02d..b8905efbd604 100644 --- a/include/net/psp/types.h +++ b/include/net/psp/types.h @@ -219,12 +219,16 @@ struct psp_dev_ops { * @tx_key_add: add a Tx key to the device * Install an association in the device. Core will allocate space * for the driver to use at drv_data. + * Can be left NULL if device does not store Tx keys and @tx_key_del + * is also NULL. */ int (*tx_key_add)(struct psp_dev *psd, struct psp_assoc *pas, struct netlink_ext_ack *extack); /** * @tx_key_del: remove a Tx key from the device * Remove an association from the device. + * Can be left NULL if device does not store Tx keys and @tx_key_add + * is also NULL. */ void (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas); diff --git a/net/psp/psp.h b/net/psp/psp.h index 8acf9ca84b55..bbb39e2f5b0a 100644 --- a/net/psp/psp.h +++ b/net/psp/psp.h @@ -53,10 +53,16 @@ static inline bool psp_dev_is_registered(struct psp_dev *psd) return !!psd->ops; } +static inline bool psp_dev_has_sadb(struct psp_dev *psd) +{ + lockdep_assert_held(&psd->lock); + return !!psd->ops->tx_key_del; +} + static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas) { lockdep_assert_held(&pas->psd->lock); - return pas->tx.spi; + return psp_dev_has_sadb(pas->psd) && pas->tx.spi; } #endif /* __PSP_PSP_H */ diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c index 2556f0d46ef4..91473f96ad21 100644 --- a/net/psp/psp_main.c +++ b/net/psp/psp_main.c @@ -68,9 +68,9 @@ psp_dev_create(struct net_device *netdev, !psd_ops->set_config || !psd_ops->key_rotate || !psd_ops->rx_spi_alloc || - !psd_ops->tx_key_add || - !psd_ops->tx_key_del || - !psd_ops->get_stats)) + !psd_ops->get_stats || + (!psd_ops->tx_key_add != !psd_ops->tx_key_del) || + (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add))) return ERR_PTR(-EINVAL); psd = kzalloc_obj(*psd); diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c index 36eb06faa54a..6a4becc38b55 100644 --- a/net/psp/psp_sock.c +++ b/net/psp/psp_sock.c @@ -181,9 +181,11 @@ static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas, { int err; - err = psp_dev_tx_key_add(psd, pas, key, extack); - if (err) - return err; + if (psp_dev_has_sadb(psd)) { + err = psp_dev_tx_key_add(psd, pas, key, extack); + if (err) + return err; + } memcpy(&pas->tx, key, sizeof(*key)); return 0; From da630d1da2b19442c337bcbe3bb3fa66fda1f5bb Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 3 Sep 2026 18:34:02 -0700 Subject: [PATCH 0220/2126] netdevsim: psp: drop tx key ops netdevsim has no SADB. The usage of psp_assoc_drv_data() was always obsolete given psp_validate_xmit(), so we can remove nsim_assoc_add() and nsim_assoc_del(). netdevsim::assoc_cnt can also be removed. PSP core can track the balance of tx_key_add vs tx_key_del calls in a future change. Delete psp_assoc_drv_data() because there are no more callers left in the tree. mlx5 accesses pas->drv_data directly. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260903-psp-prep-v1-4-d47e9c4c375d@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/netdevsim.h | 1 - drivers/net/netdevsim/psp.c | 33 ------------------------------- include/net/psp/functions.h | 5 ----- 3 files changed, 39 deletions(-) diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 55aec41237b9..181b6baaba7a 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -122,7 +122,6 @@ struct netdevsim { struct dentry *rereg; struct mutex rereg_lock; u32 spi; - u32 assoc_cnt; } psp; struct nsim_bus_dev *nsim_bus_dev; diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c index 6b3532b5e360..b7452c49b581 100644 --- a/drivers/net/netdevsim/psp.c +++ b/drivers/net/netdevsim/psp.c @@ -23,7 +23,6 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, struct psp_assoc *pas; struct net *net; int psp_len; - void **ptr; rcu_read_lock(); pas = psp_skb_get_assoc_rcu(skb); @@ -37,12 +36,6 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, goto out_unlock; } - ptr = psp_assoc_drv_data(pas); - if (*ptr != ns) { - rc = SKB_DROP_REASON_PSP_OUTPUT; - goto out_unlock; - } - net = sock_net(skb->sk); if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0)) { rc = SKB_DROP_REASON_PSP_OUTPUT; @@ -149,19 +142,6 @@ nsim_rx_spi_alloc(struct psp_dev *psd, u32 version, return 0; } -static int nsim_assoc_add(struct psp_dev *psd, struct psp_assoc *pas, - struct netlink_ext_ack *extack) -{ - struct netdevsim *ns = psd->drv_priv; - void **ptr = psp_assoc_drv_data(pas); - - /* Copy drv_priv from psd to assoc */ - *ptr = psd->drv_priv; - ns->psp.assoc_cnt++; - - return 0; -} - static int nsim_key_rotate(struct psp_dev *psd, struct netlink_ext_ack *extack) { struct netdevsim *ns = psd->drv_priv; @@ -177,15 +157,6 @@ static int nsim_key_rotate(struct psp_dev *psd, struct netlink_ext_ack *extack) return 0; } -static void nsim_assoc_del(struct psp_dev *psd, struct psp_assoc *pas) -{ - struct netdevsim *ns = psd->drv_priv; - void **ptr = psp_assoc_drv_data(pas); - - *ptr = NULL; - ns->psp.assoc_cnt--; -} - static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats) { struct netdevsim *ns = psd->drv_priv; @@ -204,8 +175,6 @@ static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats) static struct psp_dev_ops nsim_psp_ops = { .set_config = nsim_psp_set_config, .rx_spi_alloc = nsim_rx_spi_alloc, - .tx_key_add = nsim_assoc_add, - .tx_key_del = nsim_assoc_del, .key_rotate = nsim_key_rotate, .get_stats = nsim_get_stats, }; @@ -215,7 +184,6 @@ static struct psp_dev_caps nsim_psp_caps = { 1 << PSP_VERSION_HDR0_AES_GMAC_128 | 1 << PSP_VERSION_HDR0_AES_GCM_256 | 1 << PSP_VERSION_HDR0_AES_GMAC_256, - .assoc_drv_spc = sizeof(void *), }; static void __nsim_psp_uninit(struct netdevsim *ns, bool teardown) @@ -230,7 +198,6 @@ static void __nsim_psp_uninit(struct netdevsim *ns, bool teardown) synchronize_rcu(); psp_dev_unregister(psd); } - WARN_ON(ns->psp.assoc_cnt); } void nsim_psp_uninit(struct netdevsim *ns) diff --git a/include/net/psp/functions.h b/include/net/psp/functions.h index c5c23a54774e..b23c30898389 100644 --- a/include/net/psp/functions.h +++ b/include/net/psp/functions.h @@ -24,11 +24,6 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv); /* Kernel-facing API */ void psp_assoc_put(struct psp_assoc *pas); -static inline void *psp_assoc_drv_data(struct psp_assoc *pas) -{ - return pas->drv_data; -} - #if IS_ENABLED(CONFIG_INET_PSP) unsigned int psp_key_size(u32 version); void psp_sk_assoc_free(struct sock *sk); From 3fb94a277ff830a9840b4f53a8b3a94d6cbe033e Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:07 +0530 Subject: [PATCH 0221/2126] can: bxcan: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-2-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/bxcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/bxcan.c b/drivers/net/can/bxcan.c index baf494d20bef..4bddd015775b 100644 --- a/drivers/net/can/bxcan.c +++ b/drivers/net/can/bxcan.c @@ -1080,7 +1080,7 @@ static SIMPLE_DEV_PM_OPS(bxcan_pm_ops, bxcan_suspend, bxcan_resume); static const struct of_device_id bxcan_of_match[] = { {.compatible = "st,stm32f4-bxcan"}, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, bxcan_of_match); From fa7291a2527a1f61944d92e20c984b66bebf3e7d Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:08 +0530 Subject: [PATCH 0222/2126] can: c_can: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-3-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/c_can/c_can_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c index 19c86b94a40e..75607b1afd2e 100644 --- a/drivers/net/can/c_can/c_can_platform.c +++ b/drivers/net/can/c_can/c_can_platform.c @@ -239,7 +239,7 @@ static const struct platform_device_id c_can_id_table[] = { .name = "d_can", .driver_data = (kernel_ulong_t)&d_can_drvdata, }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, c_can_id_table); @@ -249,7 +249,7 @@ static const struct of_device_id c_can_of_table[] = { { .compatible = "ti,dra7-d_can", .data = &dra7_dcan_drvdata }, { .compatible = "ti,am3352-d_can", .data = &am3352_dcan_drvdata }, { .compatible = "ti,am4372-d_can", .data = &am3352_dcan_drvdata }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, c_can_of_table); From 4b7e7da65530371ea27e8d4d3639c6890b7b96a7 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:09 +0530 Subject: [PATCH 0223/2126] can: flexcan: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-4-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/flexcan/flexcan-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c index f5d22c61503f..86b40abe9e76 100644 --- a/drivers/net/can/flexcan/flexcan-core.c +++ b/drivers/net/can/flexcan/flexcan-core.c @@ -2070,7 +2070,7 @@ static const struct of_device_id flexcan_of_match[] = { { .compatible = "fsl,ls1021ar2-flexcan", .data = &fsl_ls1021a_r2_devtype_data, }, { .compatible = "fsl,lx2160ar1-flexcan", .data = &fsl_lx2160a_r1_devtype_data, }, { .compatible = "nxp,s32g2-flexcan", .data = &nxp_s32g2_devtype_data, }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, flexcan_of_match); From e6f3617decf3983a2c95679437b6c6496f7e49ab Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:10 +0530 Subject: [PATCH 0224/2126] can: ifi_canfd: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-5-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/ifi_canfd/ifi_canfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c b/drivers/net/can/ifi_canfd/ifi_canfd.c index 0f83335e4d07..9eecfe5a87bd 100644 --- a/drivers/net/can/ifi_canfd/ifi_canfd.c +++ b/drivers/net/can/ifi_canfd/ifi_canfd.c @@ -1044,7 +1044,7 @@ static void ifi_canfd_plat_remove(struct platform_device *pdev) static const struct of_device_id ifi_canfd_of_table[] = { { .compatible = "ifi,canfd-1.0", .data = NULL }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, ifi_canfd_of_table); From 6c507ab36a830f131d17ca74033282e89dec8a3f Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:11 +0530 Subject: [PATCH 0225/2126] can: m_can: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Acked-by: Markus Schneider-Pargmann Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-6-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/m_can/m_can_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c index 56da411878af..51dd41dbf2c9 100644 --- a/drivers/net/can/m_can/m_can_platform.c +++ b/drivers/net/can/m_can/m_can_platform.c @@ -220,7 +220,7 @@ static const struct dev_pm_ops m_can_pmops = { static const struct of_device_id m_can_of_table[] = { { .compatible = "bosch,m_can", .data = NULL }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, m_can_of_table); From 44ef827c95a898dd89055184eac15631ed514bd9 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:12 +0530 Subject: [PATCH 0226/2126] can: sja1000: f81601: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-7-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/sja1000/f81601.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/sja1000/f81601.c b/drivers/net/can/sja1000/f81601.c index 8f25e95814ef..18cf170db457 100644 --- a/drivers/net/can/sja1000/f81601.c +++ b/drivers/net/can/sja1000/f81601.c @@ -40,7 +40,7 @@ struct f81601_pci_card { static const struct pci_device_id f81601_pci_tbl[] = { { PCI_DEVICE(0x1c29, 0x1703) }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(pci, f81601_pci_tbl); From 5b01d57660439d08efa968d6b15f53f760dc1163 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:13 +0530 Subject: [PATCH 0227/2126] can: sja1000_platform: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-8-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/can/sja1000/sja1000_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c index 2d555f854008..da4e1c820b6e 100644 --- a/drivers/net/can/sja1000/sja1000_platform.c +++ b/drivers/net/can/sja1000/sja1000_platform.c @@ -207,7 +207,7 @@ static const struct of_device_id sp_of_table[] = { { .compatible = "nxp,sja1000", .data = NULL, }, { .compatible = "renesas,rzn1-sja1000", .data = &renesas_data, }, { .compatible = "technologic,sja1000", .data = &technologic_data, }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, sp_of_table); From 9869b64b320d419768c651945d8372a3adccb0ee Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:14 +0530 Subject: [PATCH 0228/2126] net: dsa: b53: mdio: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-9-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/b53/b53_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/b53/b53_mdio.c b/drivers/net/dsa/b53/b53_mdio.c index 43a3b37b731b..fc1ce57a80a3 100644 --- a/drivers/net/dsa/b53/b53_mdio.c +++ b/drivers/net/dsa/b53/b53_mdio.c @@ -384,7 +384,7 @@ static const struct of_device_id b53_of_match[] = { { .compatible = "brcm,bcm5395" }, { .compatible = "brcm,bcm5397" }, { .compatible = "brcm,bcm5398" }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, b53_of_match); From 30fccb0c4e760d9790b9f8f2f4828fffda8f3eb7 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:15 +0530 Subject: [PATCH 0229/2126] net: dsa: b53: srab: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-10-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/b53/b53_srab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/b53/b53_srab.c b/drivers/net/dsa/b53/b53_srab.c index b9939bbd2cd5..83a03fca142a 100644 --- a/drivers/net/dsa/b53/b53_srab.c +++ b/drivers/net/dsa/b53/b53_srab.c @@ -515,7 +515,7 @@ static const struct of_device_id b53_srab_of_match[] = { { .compatible = "brcm,cygnus-srab", .data = (void *)BCM583XX_DEVICE_ID }, { .compatible = "brcm,nsp-srab", .data = (void *)BCM58XX_DEVICE_ID }, { .compatible = "brcm,omega-srab", .data = (void *)BCM583XX_DEVICE_ID }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, b53_srab_of_match); From 2d08ac30e2ed2a92dd9439e7615bb49d012376e9 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:16 +0530 Subject: [PATCH 0230/2126] net: dsa: bcm_sf2: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-11-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/bcm_sf2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index de3efa3ce9a7..9e5713015187 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -1358,7 +1358,7 @@ static const struct of_device_id bcm_sf2_of_match[] = { { .compatible = "brcm,bcm7278-switch-v4.8", .data = &bcm_sf2_7278_data }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, bcm_sf2_of_match); From 4ea4ec3653782faf7cf19a493e228632079c0d2a Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:17 +0530 Subject: [PATCH 0231/2126] net: dsa: hellcreek: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Kurt Kanzenbach Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-12-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/hirschmann/hellcreek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/hirschmann/hellcreek.c b/drivers/net/dsa/hirschmann/hellcreek.c index 2c6cabf61143..aec50414986e 100644 --- a/drivers/net/dsa/hirschmann/hellcreek.c +++ b/drivers/net/dsa/hirschmann/hellcreek.c @@ -2093,7 +2093,7 @@ static const struct of_device_id hellcreek_of_match[] = { .compatible = "hirschmann,hellcreek-de1soc-r1", .data = &de1soc_r1_pdata, }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, hellcreek_of_match); From a650dd1fc25448a69879f69a95718e17a21b46c5 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:18 +0530 Subject: [PATCH 0232/2126] net: dsa: lan9303: i2c: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-13-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lan9303_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/lan9303_i2c.c b/drivers/net/dsa/lan9303_i2c.c index 3a09f3907f44..7b70e22371fc 100644 --- a/drivers/net/dsa/lan9303_i2c.c +++ b/drivers/net/dsa/lan9303_i2c.c @@ -96,7 +96,7 @@ MODULE_DEVICE_TABLE(i2c, lan9303_i2c_id); static const struct of_device_id lan9303_i2c_of_match[] = { { .compatible = "smsc,lan9303-i2c", }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, lan9303_i2c_of_match); From 4caa67d082f6118d5ff91d4dace539996d1ca4e1 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:19 +0530 Subject: [PATCH 0233/2126] net: dsa: lan9303: mdio: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-14-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lan9303_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/lan9303_mdio.c b/drivers/net/dsa/lan9303_mdio.c index 0ac4857e5ee8..d3b5062905b1 100644 --- a/drivers/net/dsa/lan9303_mdio.c +++ b/drivers/net/dsa/lan9303_mdio.c @@ -157,7 +157,7 @@ static void lan9303_mdio_shutdown(struct mdio_device *mdiodev) static const struct of_device_id lan9303_mdio_of_match[] = { { .compatible = "smsc,lan9303-mdio" }, { .compatible = "microchip,lan9354-mdio" }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, lan9303_mdio_of_match); From 9a580b3496c4588cc101165311180a2ab0c42e37 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:20 +0530 Subject: [PATCH 0234/2126] net: dsa: mxl-gsw1xx: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Reviewed-by: Daniel Golle Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-15-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lantiq/mxl-gsw1xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.c b/drivers/net/dsa/lantiq/mxl-gsw1xx.c index a1104b2f92a9..347e16e9fdc1 100644 --- a/drivers/net/dsa/lantiq/mxl-gsw1xx.c +++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.c @@ -918,7 +918,7 @@ static const struct of_device_id gsw1xx_of_match[] = { { .compatible = "maxlinear,gsw140", .data = &gsw140_data }, { .compatible = "maxlinear,gsw141", .data = &gsw141_data }, { .compatible = "maxlinear,gsw145", .data = &gsw140_data }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, gsw1xx_of_match); From e86151633076053f6e5628dcf2f7a48510472647 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:21 +0530 Subject: [PATCH 0235/2126] net: dsa: mt7530: mdio: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-16-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530-mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c index 81c5c6f7066d..24ef54f3db2a 100644 --- a/drivers/net/dsa/mt7530-mdio.c +++ b/drivers/net/dsa/mt7530-mdio.c @@ -142,7 +142,7 @@ static const struct of_device_id mt7530_of_match[] = { { .compatible = "mediatek,mt7621", .data = &mt753x_table[ID_MT7621], }, { .compatible = "mediatek,mt7530", .data = &mt753x_table[ID_MT7530], }, { .compatible = "mediatek,mt7531", .data = &mt753x_table[ID_MT7531], }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, mt7530_of_match); From f9bcf01a660836403facaadf1396578c836bca53 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:22 +0530 Subject: [PATCH 0236/2126] net: dsa: mt7530: mmio: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Daniel Golle Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-17-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mt7530-mmio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c index fd68b1cd0630..cf3bdb23a2d5 100644 --- a/drivers/net/dsa/mt7530-mmio.c +++ b/drivers/net/dsa/mt7530-mmio.c @@ -14,7 +14,7 @@ static const struct of_device_id mt7988_of_match[] = { { .compatible = "airoha,en7581-switch", .data = &mt753x_table[ID_EN7581], }, { .compatible = "econet,en7528-switch", .data = &mt753x_table[ID_EN7528], }, { .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, mt7988_of_match); From 6011d062dc7db553d1ac223bcef849f2a1a4aeb9 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:23 +0530 Subject: [PATCH 0237/2126] net: dsa: mv88e6060: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Reviewed-by: Linus Walleij Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-18-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mv88e6060.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c index 9c8ac14cd4f5..64bf3d759d17 100644 --- a/drivers/net/dsa/mv88e6060.c +++ b/drivers/net/dsa/mv88e6060.c @@ -362,7 +362,7 @@ static const struct of_device_id mv88e6060_of_match[] = { { .compatible = "marvell,mv88e6060", }, - { /* sentinel */ }, + { /* sentinel */ } }; static struct mdio_driver mv88e6060_driver = { From ead5894715930b5177305c10e98f8fe06bee0d68 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:24 +0530 Subject: [PATCH 0238/2126] net: dsa: mv88e6xxx: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Reviewed-by: Linus Walleij Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-19-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 80b877c74513..f8aa93e9ee18 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -7513,7 +7513,7 @@ static const struct of_device_id mv88e6xxx_of_match[] = { .compatible = "marvell,mv88e6250", .data = &mv88e6xxx_table[MV88E6250], }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match); From c45695468377196bd8a8932dbd776939ff289618 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:25 +0530 Subject: [PATCH 0239/2126] net: dsa: qca8k: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-20-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/qca/qca8k-8xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 4c928983b862..60f2a615a5cc 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -2215,7 +2215,7 @@ static const struct of_device_id qca8k_of_match[] = { { .compatible = "qca,qca8328", .data = &qca8328 }, { .compatible = "qca,qca8334", .data = &qca833x }, { .compatible = "qca,qca8337", .data = &qca833x }, - { /* sentinel */ }, + { /* sentinel */ } }; static struct mdio_driver qca8kmdio_driver = { From 6233d1ee37717e81697a08aa7b61910f68be7b1f Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:26 +0530 Subject: [PATCH 0240/2126] net: dsa: realtek: rtl8365mb: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Luiz Angelo Daros de Luca Reviewed-by: Linus Walleij Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-21-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/rtl8365mb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 4c305756116c..f8220d832e46 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -3352,7 +3352,7 @@ const struct realtek_variant rtl8365mb_variant = { static const struct of_device_id rtl8365mb_of_match[] = { { .compatible = "realtek,rtl8365mb", .data = &rtl8365mb_variant, }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, rtl8365mb_of_match); From 068d6ebde398586ea8d568d0994fbe1868edf640 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:27 +0530 Subject: [PATCH 0241/2126] net: dsa: realtek: rtl8366rb: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Linus Walleij Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-22-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/rtl8366rb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index f11831b66de8..093a06c599d4 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -1839,7 +1839,7 @@ const struct realtek_variant rtl8366rb_variant = { static const struct of_device_id rtl8366rb_of_match[] = { { .compatible = "realtek,rtl8366rb", .data = &rtl8366rb_variant, }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, rtl8366rb_of_match); From 39063420326f40c3e5f335541463ae9a3130b02c Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:28 +0530 Subject: [PATCH 0242/2126] net: dsa: rzn1_a5psw: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Geert Uytterhoeven Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-23-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/rzn1_a5psw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c index 4d857e3be10b..85ff1fd2bbfb 100644 --- a/drivers/net/dsa/rzn1_a5psw.c +++ b/drivers/net/dsa/rzn1_a5psw.c @@ -1299,7 +1299,7 @@ static void a5psw_shutdown(struct platform_device *pdev) static const struct of_device_id a5psw_of_mtable[] = { { .compatible = "renesas,rzn1-a5psw", }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, a5psw_of_mtable); From 2b46b5c9efc9fc6903f1c417564fb278ab22bca4 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:29 +0530 Subject: [PATCH 0243/2126] net: dsa: sja1105: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-24-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/sja1105/sja1105_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 1653e83d9123..8984ed55ad59 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3374,7 +3374,7 @@ static const struct of_device_id sja1105_dt_ids[] = { { .compatible = "nxp,sja1110b", .data = &sja1110b_info }, { .compatible = "nxp,sja1110c", .data = &sja1110c_info }, { .compatible = "nxp,sja1110d", .data = &sja1110d_info }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, sja1105_dt_ids); From a450f7315155551e0a4764e64212849951600ac4 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:30 +0530 Subject: [PATCH 0244/2126] net: bcmasp: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-25-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c index 972474893a6b..3393b5dcbc9a 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c @@ -1209,7 +1209,7 @@ static const struct of_device_id bcmasp_of_match[] = { { .compatible = "brcm,asp-v2.1", .data = &v21_plat_data }, { .compatible = "brcm,asp-v2.2", .data = &v22_plat_data }, { .compatible = "brcm,asp-v3.0", .data = &v30_plat_data }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, bcmasp_of_match); @@ -1217,7 +1217,7 @@ static const struct of_device_id bcmasp_mdio_of_match[] = { { .compatible = "brcm,asp-v2.1-mdio", }, { .compatible = "brcm,asp-v2.2-mdio", }, { .compatible = "brcm,asp-v3.0-mdio", }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, bcmasp_mdio_of_match); From 435d4b4aa9c862d2a3bf9e7c95725a938d264a2b Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:31 +0530 Subject: [PATCH 0245/2126] net: spacemit: k1_emac: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Acked-by: Vivian Wang Reviewed-by: Troy Mitchell Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-26-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/spacemit/k1_emac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/spacemit/k1_emac.c b/drivers/net/ethernet/spacemit/k1_emac.c index f7f16397a2c2..29385d78fc4b 100644 --- a/drivers/net/ethernet/spacemit/k1_emac.c +++ b/drivers/net/ethernet/spacemit/k1_emac.c @@ -1161,7 +1161,7 @@ static const struct ethtool_rmon_hist_range emac_rmon_hist_ranges[] = { { 512, 1023 }, { 1024, 1518 }, { 1519, 4096 }, - { /* sentinel */ }, + { /* sentinel */ } }; /* Like dev_fetch_dstats(), but we only use tx_drops */ @@ -2066,7 +2066,7 @@ static const struct dev_pm_ops emac_pm_ops = { static const struct of_device_id emac_of_match[] = { { .compatible = "spacemit,k1-emac" }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, emac_of_match); From 8b7eacd6219871e4e6b6221ebce4cfd806afd25f Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:32 +0530 Subject: [PATCH 0246/2126] net: ti: am65-cpsw-nuss: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Signed-off-by: Siddharth Vadapalli Link: https://patch.msgid.link/20260904043724.2955444-27-s-vadapalli@ti.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index 6330540979d7..2551554add17 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -3506,7 +3506,7 @@ static const struct of_device_id am65_cpsw_nuss_of_mtable[] = { { .compatible = "ti,j7200-cpswxg-nuss", .data = &j7200_cpswxg_pdata}, { .compatible = "ti,j721e-cpswxg-nuss", .data = &j721e_cpswxg_pdata}, { .compatible = "ti,j784s4-cpswxg-nuss", .data = &j784s4_cpswxg_pdata}, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, am65_cpsw_nuss_of_mtable); From 1cdf69f1e9a01345a079937147d5fc2fd9f224a5 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:33 +0530 Subject: [PATCH 0247/2126] net: ethernet: ti: cpsw: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ti/cpsw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index aa3531e844e8..63b64faeaca0 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -1529,7 +1529,7 @@ static const struct of_device_id cpsw_of_mtable[] = { { .compatible = "ti,am335x-cpsw"}, { .compatible = "ti,am4372-cpsw"}, { .compatible = "ti,dra7-cpsw"}, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, cpsw_of_mtable); From 6d1c7d7a0731ce32cbc99e419f77260536769cb9 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:34 +0530 Subject: [PATCH 0248/2126] net: ethernet: ti: cpsw_new: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Reviewed-by: Alexander Sverdlin Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ti/cpsw_new.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index b6e25a4658d1..07832cad5e3c 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -1875,7 +1875,7 @@ static const struct of_device_id cpsw_of_mtable[] = { { .compatible = "ti,am335x-cpsw-switch"}, { .compatible = "ti,am4372-cpsw-switch"}, { .compatible = "ti,dra7-cpsw-switch"}, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, cpsw_of_mtable); From 93b9f4f1360830344d076eed72206c822701c583 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:35 +0530 Subject: [PATCH 0249/2126] net: mdio: bcm-iproc: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-bcm-iproc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-bcm-iproc.c b/drivers/net/mdio/mdio-bcm-iproc.c index 91690b496793..22473c988e3b 100644 --- a/drivers/net/mdio/mdio-bcm-iproc.c +++ b/drivers/net/mdio/mdio-bcm-iproc.c @@ -195,7 +195,7 @@ static const struct dev_pm_ops iproc_mdio_pm_ops = { static const struct of_device_id iproc_mdio_of_match[] = { { .compatible = "brcm,iproc-mdio", }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, iproc_mdio_of_match); From dd7a0a75587470e0820e48b4d3d13b237e31baaf Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:36 +0530 Subject: [PATCH 0250/2126] net: mdio: bcm-unimac: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-bcm-unimac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c index 37e35f282d9a..31e396cc9fbf 100644 --- a/drivers/net/mdio/mdio-bcm-unimac.c +++ b/drivers/net/mdio/mdio-bcm-unimac.c @@ -345,7 +345,7 @@ static const struct of_device_id unimac_mdio_ids[] = { { .compatible = "brcm,genet-mdio-v2", }, { .compatible = "brcm,genet-mdio-v1", }, { .compatible = "brcm,unimac-mdio", }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, unimac_mdio_ids); From 3fc32eb28f15be83ac2828d0f4d025b15b6dab5e Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:37 +0530 Subject: [PATCH 0251/2126] net: pcs: xpcs-plat: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/pcs/pcs-xpcs-plat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/pcs/pcs-xpcs-plat.c b/drivers/net/pcs/pcs-xpcs-plat.c index f4b1b8246ce9..e669a7b248ac 100644 --- a/drivers/net/pcs/pcs-xpcs-plat.c +++ b/drivers/net/pcs/pcs-xpcs-plat.c @@ -438,7 +438,7 @@ static const struct of_device_id xpcs_of_ids[] = { { .compatible = "snps,dw-xpcs-gen4-6g", .data = &xpcs_pma_gen4_6g }, { .compatible = "snps,dw-xpcs-gen5-10g", .data = &xpcs_pma_gen5_10g }, { .compatible = "snps,dw-xpcs-gen5-12g", .data = &xpcs_pma_gen5_12g }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, xpcs_of_ids); From af86c0a5800715a525b6e8c6280a3b4a9660dece Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:38 +0530 Subject: [PATCH 0252/2126] net: phy: nxp-c45-tja11xx: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/phy/nxp-c45-tja11xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index f526528d2e32..8df152f6671f 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -2180,7 +2180,7 @@ module_phy_driver(nxp_c45_driver); static const struct mdio_device_id __maybe_unused nxp_c45_tbl[] = { { PHY_ID_MATCH_MODEL(PHY_ID_TJA_1103) }, { PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120) }, - { /*sentinel*/ }, + { /*sentinel*/ } }; MODULE_DEVICE_TABLE(mdio, nxp_c45_tbl); From 8afd6adb071713fc25dbc2d1e3763fdb0fe0b660 Mon Sep 17 00:00:00 2001 From: Siddharth Vadapalli Date: Fri, 4 Sep 2026 10:06:39 +0530 Subject: [PATCH 0253/2126] net: wan: slic_ds26522: Remove comma after sentinel-entry in match-table Since sentinel is the last entry and we do not expect further entries following it, remove the comma. Signed-off-by: Siddharth Vadapalli Signed-off-by: Jakub Kicinski --- drivers/net/wan/slic_ds26522.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wan/slic_ds26522.c b/drivers/net/wan/slic_ds26522.c index cbb99fc5ea9f..c57e7cb98410 100644 --- a/drivers/net/wan/slic_ds26522.c +++ b/drivers/net/wan/slic_ds26522.c @@ -219,7 +219,7 @@ static int slic_ds26522_probe(struct spi_device *spi) static const struct spi_device_id slic_ds26522_id[] = { { .name = "ds26522" }, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(spi, slic_ds26522_id); From a4050ce7e46cecbc25eadfa89e4b907b1906a4f9 Mon Sep 17 00:00:00 2001 From: Henry Hu Date: Thu, 3 Sep 2026 19:30:46 +0800 Subject: [PATCH 0254/2126] net: phy: microchip_t1: fix NULL pointer dereference in lan887x_phy_init() The issue was discovered via smatch static analyzer: make CHECK="smatch -p=kernel" C=2 drivers/net/phy/microchip_t1.o CHECK scripts/mod/empty.c DESCEND objtool CHECK drivers/net/phy/microchip_t1.c drivers/net/phy/microchip_t1.c:1295 lan887x_phy_init() warn: 'priv->clock' can also be NULL mchp_rds_ptp_probe() returns NULL when CONFIG_MICROCHIP_PHY_RDS_PTP or CONFIG_PTP_1588_CLOCK is disabled. However, lan887x_phy_init() only checks for an error pointer before using the returned clock to configure the periodic output pin, which can result in a NULL pointer dereference. Handle the NULL return as PTP being unavailable and skip the event pin configuration in that case. Smatch no longer reports the NULL dereference warning after the change. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Reviewed-by: Divya Koppera Signed-off-by: Henry Hu Link: https://patch.msgid.link/20260903113046.163630-1-15815827059@163.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/microchip_t1.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c index 3292b2235c8f..e38d20bf6aa4 100644 --- a/drivers/net/phy/microchip_t1.c +++ b/drivers/net/phy/microchip_t1.c @@ -1285,14 +1285,16 @@ static int lan887x_phy_init(struct phy_device *phydev) if (IS_ERR(priv->clock)) return PTR_ERR(priv->clock); - /* Enable pin mux for EVT */ - phy_modify_mmd(phydev, MDIO_MMD_VEND1, - LAN887X_MX_CHIP_TOP_REG_CONTROL1, - LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN, - LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN); + if (priv->clock) { + /* Enable pin mux for EVT */ + phy_modify_mmd(phydev, MDIO_MMD_VEND1, + LAN887X_MX_CHIP_TOP_REG_CONTROL1, + LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN, + LAN887X_MX_CHIP_TOP_REG_CONTROL1_EVT_EN); - /* Initialize pin numbers specific to PEROUT */ - priv->clock->event_pin = 3; + /* Initialize pin numbers specific to PEROUT */ + priv->clock->event_pin = 3; + } priv->init_done = true; } From 615bcbb822cbd7e0c2c0b4b85d0ffa9ee564c89c Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 3 Sep 2026 14:06:47 +0200 Subject: [PATCH 0255/2126] net: ethernet: ti: davinci_mdio: Drop commas after match table sentinels It does not make sense to have a comma after a sentinel, as any new elements must be added before the sentinel. Signed-off-by: Geert Uytterhoeven Link: https://patch.msgid.link/e481b6de46cecc6ea604ae165272c667274cc621.1788437140.git.geert+renesas@glider.be Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ti/davinci_mdio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c index 48f85a3649b2..5bec72f2f51d 100644 --- a/drivers/net/ethernet/ti/davinci_mdio.c +++ b/drivers/net/ethernet/ti/davinci_mdio.c @@ -510,7 +510,7 @@ static const struct soc_device_attribute k3_mdio_socinfo[] = { { .family = "J7200", .data = &am65_mdio_soc_data }, { .family = "J721E", .data = &am65_mdio_soc_data }, { .family = "J721S2", .data = &am65_mdio_soc_data }, - { /* sentinel */ }, + { /* sentinel */ } }; #if IS_ENABLED(CONFIG_OF) @@ -521,7 +521,7 @@ static const struct davinci_mdio_of_param of_cpsw_mdio_data = { static const struct of_device_id davinci_mdio_of_mtable[] = { { .compatible = "ti,davinci_mdio", }, { .compatible = "ti,cpsw-mdio", .data = &of_cpsw_mdio_data}, - { /* sentinel */ }, + { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, davinci_mdio_of_mtable); #endif From 581850fa732a0be0bfe6ff13b8e35c0f4a893b5e Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:30 +0300 Subject: [PATCH 0256/2126] net: bridge: vlan: drop legacy memory barriers These memory barriers are legacy code from the old vlan implementation that is not needed anymore. They're also affecting the fast-path. The pvid is changed under lock and is read with rcu only in the fast-path there is no need for a barrier, nothing to commit prior to changing it nor invalidate prior to reading. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-2-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_private.h | 1 - net/bridge/br_vlan.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index d337b1cfb980..5b2c22ad669e 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1687,7 +1687,6 @@ static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) if (!vg) return 0; - smp_rmb(); return vg->pvid; } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 1e0e436629ec..2ae6ffb23399 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -40,7 +40,6 @@ static void __vlan_add_pvid(struct net_bridge_vlan_group *vg, if (vg->pvid == v->vid) return; - smp_wmb(); br_vlan_set_pvid_state(vg, v->state); vg->pvid = v->vid; } @@ -50,7 +49,6 @@ static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid) if (vg->pvid != vid) return; - smp_wmb(); vg->pvid = 0; } From bd1aeca09823f35c693e31b703b999f0ac7a5d81 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:31 +0300 Subject: [PATCH 0257/2126] net: bridge: vlan: annotate lockless pvid use Use READ/WRITE_ONCE to annotate lockless pvid use, br_get_pvid() is the helper that should be used outside of the bridge vlan code. The rest of the vlan places that access pvid directly all have rtnl. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-3-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_private.h | 2 +- net/bridge/br_vlan.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 5b2c22ad669e..0efd2e79e255 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1687,7 +1687,7 @@ static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) if (!vg) return 0; - return vg->pvid; + return READ_ONCE(vg->pvid); } static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 2ae6ffb23399..a53054fcc093 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -41,7 +41,7 @@ static void __vlan_add_pvid(struct net_bridge_vlan_group *vg, return; br_vlan_set_pvid_state(vg, v->state); - vg->pvid = v->vid; + WRITE_ONCE(vg->pvid, v->vid); } static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid) @@ -49,7 +49,7 @@ static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid) if (vg->pvid != vid) return; - vg->pvid = 0; + WRITE_ONCE(vg->pvid, 0); } /* Update the BRIDGE_VLAN_INFO_PVID and BRIDGE_VLAN_INFO_UNTAGGED flags of @v. From e46efd49e05f9b99029cd94b6cec3c7858a10bb9 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:32 +0300 Subject: [PATCH 0258/2126] net: bridge: mst: use br_get_pvid helper The only place that accessed pvid directly outside of the bridge vlan code was mst, change it to use the br_get_pvid helper. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-4-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_mst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bridge/br_mst.c b/net/bridge/br_mst.c index 43a300ae6bfa..95e49ec8065e 100644 --- a/net/bridge/br_mst.c +++ b/net/bridge/br_mst.c @@ -86,7 +86,7 @@ static void br_mst_vlan_set_state(struct net_bridge_vlan_group *vg, if (br_vlan_get_state(v) == state) return; - if (v->vid == vg->pvid) + if (v->vid == br_get_pvid(vg)) br_vlan_set_pvid_state(vg, state); br_vlan_set_state(v, state); From 2b1f8fd3118c125c08ea1c03663c8422113526c9 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:33 +0300 Subject: [PATCH 0259/2126] net: bridge: vlan: annotate lockless vlan flags use Annotate vlan flags data races, they can be read lockless. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-5-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_multicast.c | 2 +- net/bridge/br_netlink.c | 6 +++--- net/bridge/br_private.h | 4 ++-- net/bridge/br_vlan.c | 19 +++++++++++-------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 3e9b10f8abf1..8f84eb5b3cee 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -923,7 +923,7 @@ static void __br_multicast_query_handle_vlan(struct net_bridge_mcast *brmctx, else if (br_multicast_ctx_is_vlan(brmctx)) vlan = brmctx->vlan; - if (vlan && !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)) { + if (vlan && !(READ_ONCE(vlan->flags) & BRIDGE_VLAN_INFO_UNTAGGED)) { u16 vlan_proto; if (br_vlan_get_proto(brmctx->br->dev, &vlan_proto) != 0) diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index b2cd4e39326d..62ce96d9ba32 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -41,7 +41,7 @@ static int __get_num_vlan_infos(struct net_bridge_vlan_group *vg, if (v->vid == pvid) flags |= BRIDGE_VLAN_INFO_PVID; - if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) + if (READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_UNTAGGED) flags |= BRIDGE_VLAN_INFO_UNTAGGED; if (vid_range_start == 0) { @@ -385,7 +385,7 @@ static int br_fill_ifvlaninfo_compressed(struct sk_buff *skb, if (v->vid == pvid) flags |= BRIDGE_VLAN_INFO_PVID; - if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) + if (READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_UNTAGGED) flags |= BRIDGE_VLAN_INFO_UNTAGGED; if (vid_range_start == 0) { @@ -437,7 +437,7 @@ static int br_fill_ifvlaninfo(struct sk_buff *skb, if (v->vid == pvid) vinfo.flags |= BRIDGE_VLAN_INFO_PVID; - if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) + if (READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_UNTAGGED) vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED; if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 0efd2e79e255..96554d293d22 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -665,13 +665,13 @@ static inline int br_is_root_bridge(const struct net_bridge *br) /* check if a VLAN entry is global */ static inline bool br_vlan_is_master(const struct net_bridge_vlan *v) { - return v->flags & BRIDGE_VLAN_INFO_MASTER; + return READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_MASTER; } /* check if a VLAN entry is used by the bridge */ static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v) { - return v->flags & BRIDGE_VLAN_INFO_BRENTRY; + return READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_BRENTRY; } /* check if we should use the vlan entry, returns false if it's only context */ diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index a53054fcc093..c8b2e3bfd42d 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -60,6 +60,7 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, bool commit) { struct net_bridge_vlan_group *vg; + u16 vlan_flags; bool change; if (br_vlan_is_master(v)) @@ -68,8 +69,9 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, vg = nbp_vlan_group(v->port); /* check if anything would be changed on commit */ + vlan_flags = v->flags; change = !!(flags & BRIDGE_VLAN_INFO_PVID) == !!(vg->pvid != v->vid) || - ((flags ^ v->flags) & BRIDGE_VLAN_INFO_UNTAGGED); + ((flags ^ vlan_flags) & BRIDGE_VLAN_INFO_UNTAGGED); if (!commit) goto out; @@ -80,9 +82,10 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, __vlan_delete_pvid(vg, v->vid); if (flags & BRIDGE_VLAN_INFO_UNTAGGED) - v->flags |= BRIDGE_VLAN_INFO_UNTAGGED; + vlan_flags |= BRIDGE_VLAN_INFO_UNTAGGED; else - v->flags &= ~BRIDGE_VLAN_INFO_UNTAGGED; + vlan_flags &= ~BRIDGE_VLAN_INFO_UNTAGGED; + WRITE_ONCE(v->flags, vlan_flags); out: return change; @@ -413,7 +416,7 @@ static int __vlan_del(struct net_bridge_vlan *v) } if (br_vlan_should_use(v)) { - v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY; + WRITE_ONCE(v->flags, v->flags & ~BRIDGE_VLAN_INFO_BRENTRY); vg->num_vlans--; } @@ -522,7 +525,7 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br, * hardware on each egress port as appropriate. So only strip the VLAN * header if forwarding offload is not being used. */ - if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED && + if (READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_UNTAGGED && !br_switchdev_frame_uses_tx_fwd_offload(skb)) __vlan_hwaccel_clear_tag(skb); @@ -753,7 +756,7 @@ static int br_vlan_add_existing(struct net_bridge *br, } refcount_inc(&vlan->refcnt); - vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY; + WRITE_ONCE(vlan->flags, vlan->flags | BRIDGE_VLAN_INFO_BRENTRY); vg->num_vlans++; *changed = true; br_multicast_toggle_one_vlan(vlan, true); @@ -1489,7 +1492,7 @@ int br_vlan_fill_forward_path_mode(struct net_bridge *br, if (!v || !br_vlan_should_use(v)) return -EINVAL; - if (!(v->flags & BRIDGE_VLAN_INFO_UNTAGGED)) + if (!(READ_ONCE(v->flags) & BRIDGE_VLAN_INFO_UNTAGGED)) return 0; if (path->bridge.vlan_mode == DEV_PATH_BR_VLAN_TAG) @@ -1550,7 +1553,7 @@ int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid, return -ENOENT; p_vinfo->vid = vid; - p_vinfo->flags = v->flags; + p_vinfo->flags = READ_ONCE(v->flags); if (vid == br_get_pvid(vg)) p_vinfo->flags |= BRIDGE_VLAN_INFO_PVID; return 0; From b0bb0a45ce7e3dd8dfd1ffd8bbe9480d123fa871 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:34 +0300 Subject: [PATCH 0260/2126] net: bridge: vlan: annotate lockless use of private flags Annotate vlan private flags data races, they can be read lockless. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-6-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_arp_nd_proxy.c | 6 ++++-- net/bridge/br_multicast.c | 16 ++++++++++------ net/bridge/br_private.h | 9 ++++++--- net/bridge/br_vlan.c | 2 +- net/bridge/br_vlan_options.c | 6 ++++-- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index 09458935a49e..9ce8f440e38f 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -521,7 +521,8 @@ bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, u16 vid) v = br_vlan_find(vg, vid); if (!v) return false; - return !!(v->priv_flags & BR_VLFLAG_NEIGH_SUPPRESS_ENABLED); + return !!(READ_ONCE(v->priv_flags) & + BR_VLFLAG_NEIGH_SUPPRESS_ENABLED); } return test_bit(BR_NEIGH_SUPPRESS_BIT, &p->flags); } @@ -535,7 +536,8 @@ bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, u16 vid) v = br_vlan_find(vg, vid); if (!v) return false; - return !!(v->priv_flags & BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED); + return !!(READ_ONCE(v->priv_flags) & + BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED); } return test_bit(BR_NEIGH_FORWARD_GRAT_BIT, &p->flags); } diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 8f84eb5b3cee..d9ff0f7318e5 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -2183,7 +2183,7 @@ static void br_multicast_enable_port_ctx(struct net_bridge_mcast_port *pmctx) spin_lock_bh(&br->multicast_lock); if (br_multicast_port_ctx_is_vlan(pmctx) && - !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED)) { + !(READ_ONCE(pmctx->vlan->priv_flags) & BR_VLFLAG_MCAST_ENABLED)) { spin_unlock_bh(&br->multicast_lock); return; } @@ -2220,7 +2220,7 @@ static void br_multicast_disable_port_ctx(struct net_bridge_mcast_port *pmctx) spin_lock_bh(&br->multicast_lock); if (br_multicast_port_ctx_is_vlan(pmctx) && - !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED)) { + !(READ_ONCE(pmctx->vlan->priv_flags) & BR_VLFLAG_MCAST_ENABLED)) { spin_unlock_bh(&br->multicast_lock); return; } @@ -4094,7 +4094,8 @@ int br_multicast_rcv(struct net_bridge_mcast **brmctx, *pmctx = &vlan->port_mcast_ctx; } - if (!(masterv->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)) + if (!(READ_ONCE(masterv->priv_flags) & + BR_VLFLAG_GLOBAL_MCAST_ENABLED)) return 0; } @@ -4394,7 +4395,8 @@ void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on) return; spin_lock_bh(&br->multicast_lock); - vlan->priv_flags ^= BR_VLFLAG_MCAST_ENABLED; + WRITE_ONCE(vlan->priv_flags, vlan->priv_flags ^ + BR_VLFLAG_MCAST_ENABLED); spin_unlock_bh(&br->multicast_lock); if (on) @@ -4410,7 +4412,8 @@ void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on) br = vlan->port->br; spin_lock_bh(&br->multicast_lock); - vlan->priv_flags ^= BR_VLFLAG_MCAST_ENABLED; + WRITE_ONCE(vlan->priv_flags, vlan->priv_flags ^ + BR_VLFLAG_MCAST_ENABLED); if (on) __br_multicast_enable_port_ctx(&vlan->port_mcast_ctx); else @@ -4488,7 +4491,8 @@ bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on) if (on == !!(vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)) return false; - vlan->priv_flags ^= BR_VLFLAG_GLOBAL_MCAST_ENABLED; + WRITE_ONCE(vlan->priv_flags, vlan->priv_flags ^ + BR_VLFLAG_GLOBAL_MCAST_ENABLED); br_multicast_toggle_vlan(vlan, on); return true; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 96554d293d22..c7b64b5da012 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1273,21 +1273,24 @@ br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx) { return br_multicast_ctx_is_vlan(brmctx) && (!br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) || - !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)); + !(READ_ONCE(brmctx->vlan->priv_flags) & + BR_VLFLAG_GLOBAL_MCAST_ENABLED)); } static inline bool br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx) { return br_multicast_ctx_is_vlan(brmctx) && - !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); + !(READ_ONCE(brmctx->vlan->priv_flags) & + BR_VLFLAG_MCAST_ENABLED); } static inline bool br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx) { return br_multicast_port_ctx_is_vlan(pmctx) && - !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); + !(READ_ONCE(pmctx->vlan->priv_flags) & + BR_VLFLAG_MCAST_ENABLED); } static inline bool diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index c8b2e3bfd42d..102792f20a5e 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -1497,7 +1497,7 @@ int br_vlan_fill_forward_path_mode(struct net_bridge *br, if (path->bridge.vlan_mode == DEV_PATH_BR_VLAN_TAG) path->bridge.vlan_mode = DEV_PATH_BR_VLAN_KEEP; - else if (v->priv_flags & BR_VLFLAG_TAGGING_BY_SWITCHDEV) + else if (READ_ONCE(v->priv_flags) & BR_VLFLAG_TAGGING_BY_SWITCHDEV) path->bridge.vlan_mode = DEV_PATH_BR_VLAN_UNTAG_HW; else path->bridge.vlan_mode = DEV_PATH_BR_VLAN_UNTAG; diff --git a/net/bridge/br_vlan_options.c b/net/bridge/br_vlan_options.c index cb0f556ff40d..bd049d268fe7 100644 --- a/net/bridge/br_vlan_options.c +++ b/net/bridge/br_vlan_options.c @@ -276,7 +276,8 @@ static int br_vlan_process_one_opts(const struct net_bridge *br, } if (val != enabled) { - v->priv_flags ^= BR_VLFLAG_NEIGH_SUPPRESS_ENABLED; + WRITE_ONCE(v->priv_flags, v->priv_flags ^ + BR_VLFLAG_NEIGH_SUPPRESS_ENABLED); *changed = true; } } @@ -292,7 +293,8 @@ static int br_vlan_process_one_opts(const struct net_bridge *br, } if (val != enabled) { - v->priv_flags ^= BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED; + WRITE_ONCE(v->priv_flags, v->priv_flags ^ + BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED); *changed = true; } } From 5bec8f861114a221d774ceb1443078164710537b Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:35 +0300 Subject: [PATCH 0261/2126] net: bridge: vlan: annotate lockless use of num_vlans Annotate data races around vlan group's num_vlans, it can be read lockless. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-7-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_netlink.c | 4 ++-- net/bridge/br_vlan.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 62ce96d9ba32..ae76df0de05a 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -81,7 +81,7 @@ static int br_get_num_vlan_infos(struct net_bridge_vlan_group *vg, return 0; if (filter_mask & RTEXT_FILTER_BRVLAN) - return vg->num_vlans; + return READ_ONCE(vg->num_vlans); rcu_read_lock(); num_vlans = __get_num_vlan_infos(vg, filter_mask); @@ -531,7 +531,7 @@ static int br_fill_ifinfo(struct sk_buff *skb, else vg = br_vlan_group_rcu(br); - if (!vg || !vg->num_vlans) { + if (!vg || !READ_ONCE(vg->num_vlans)) { rcu_read_unlock(); goto done; } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 102792f20a5e..95187a607ec2 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -344,7 +344,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, goto out_filt; } } - vg->num_vlans++; + WRITE_ONCE(vg->num_vlans, vg->num_vlans + 1); } /* set the state before publishing */ @@ -367,7 +367,7 @@ out: out_fdb_insert: if (br_vlan_should_use(v)) { br_fdb_find_delete_local(br, p, dev->dev_addr, v->vid); - vg->num_vlans--; + WRITE_ONCE(vg->num_vlans, vg->num_vlans - 1); } out_filt: @@ -417,7 +417,7 @@ static int __vlan_del(struct net_bridge_vlan *v) if (br_vlan_should_use(v)) { WRITE_ONCE(v->flags, v->flags & ~BRIDGE_VLAN_INFO_BRENTRY); - vg->num_vlans--; + WRITE_ONCE(vg->num_vlans, vg->num_vlans - 1); } if (masterv != v) { @@ -695,7 +695,7 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) return true; vg = nbp_vlan_group_rcu(p); - if (!vg || !vg->num_vlans) + if (!vg || !READ_ONCE(vg->num_vlans)) return false; if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto) @@ -757,7 +757,7 @@ static int br_vlan_add_existing(struct net_bridge *br, refcount_inc(&vlan->refcnt); WRITE_ONCE(vlan->flags, vlan->flags | BRIDGE_VLAN_INFO_BRENTRY); - vg->num_vlans++; + WRITE_ONCE(vg->num_vlans, vg->num_vlans + 1); *changed = true; br_multicast_toggle_one_vlan(vlan, true); } From 120207a08fc093a281e83eb292426249ffcd7512 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:36 +0300 Subject: [PATCH 0262/2126] net: bridge: vlan: annotate lockless use of msti Annotate data races around vlan msti field, it can be read lockless. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-8-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_mst.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/bridge/br_mst.c b/net/bridge/br_mst.c index 95e49ec8065e..76a5bf287578 100644 --- a/net/bridge/br_mst.c +++ b/net/bridge/br_mst.c @@ -123,7 +123,7 @@ int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, err = 0; list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { - if (v->brvlan->msti != msti) + if (READ_ONCE(v->brvlan->msti) != msti) continue; br_mst_vlan_set_state(vg, v, state); @@ -176,7 +176,7 @@ int br_mst_vlan_set_msti(struct net_bridge_vlan *mv, u16 msti) if (err && err != -EOPNOTSUPP) return err; - mv->msti = msti; + WRITE_ONCE(mv->msti, msti); list_for_each_entry(p, &mv->br->port_list, list) { vg = nbp_vlan_group(p); @@ -249,7 +249,9 @@ size_t br_mst_info_size(const struct net_bridge_vlan_group *vg) sz = nla_total_size(0); list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { - if (test_bit(v->brvlan->msti, seen)) + u16 msti = READ_ONCE(v->brvlan->msti); + + if (test_bit(msti, seen)) continue; /* IFLA_BRIDGE_MST_ENTRY */ @@ -259,7 +261,7 @@ size_t br_mst_info_size(const struct net_bridge_vlan_group *vg) /* IFLA_BRIDGE_MST_ENTRY_STATE */ nla_total_size(sizeof(u8)); - __set_bit(v->brvlan->msti, seen); + __set_bit(msti, seen); } return sz; From f20c44811531d94d3b5be080e50b8f08368e8165 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:37 +0300 Subject: [PATCH 0263/2126] net: bridge: vlan: add missing tinfo.tunnel_id annotations When I annotated data races around tinfo.tunnel_id before, I missed a few places (e.g. bridge notifications, rhashtable compare), so add them now. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-9-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_netlink_tunnel.c | 14 ++++++++------ net/bridge/br_vlan_tunnel.c | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/net/bridge/br_netlink_tunnel.c b/net/bridge/br_netlink_tunnel.c index e7eceab5b515..e64054628ac9 100644 --- a/net/bridge/br_netlink_tunnel.c +++ b/net/bridge/br_netlink_tunnel.c @@ -29,8 +29,10 @@ static size_t __get_vlan_tinfo_size(void) bool vlan_tunid_inrange(const struct net_bridge_vlan *v_curr, const struct net_bridge_vlan *v_last) { - __be32 tunid_curr = tunnel_id_to_key32(v_curr->tinfo.tunnel_id); - __be32 tunid_last = tunnel_id_to_key32(v_last->tinfo.tunnel_id); + __be32 tunid_curr, tunid_last; + + tunid_curr = tunnel_id_to_key32(READ_ONCE(v_curr->tinfo.tunnel_id)); + tunid_last = tunnel_id_to_key32(READ_ONCE(v_last->tinfo.tunnel_id)); return (be32_to_cpu(tunid_curr) - be32_to_cpu(tunid_last)) == 1; } @@ -43,7 +45,7 @@ static int __get_num_vlan_tunnel_infos(struct net_bridge_vlan_group *vg) /* Count number of vlan infos */ list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { /* only a context, bridge vlan not activated */ - if (!br_vlan_should_use(v) || !v->tinfo.tunnel_id) + if (!br_vlan_should_use(v) || !READ_ONCE(v->tinfo.tunnel_id)) continue; if (!vtbegin) { @@ -124,19 +126,19 @@ static int br_fill_vlan_tinfo_range(struct sk_buff *skb, if (vtend && (vtend->vid - vtbegin->vid) > 0) { /* add range to skb */ err = br_fill_vlan_tinfo(skb, vtbegin->vid, - vtbegin->tinfo.tunnel_id, + READ_ONCE(vtbegin->tinfo.tunnel_id), BRIDGE_VLAN_INFO_RANGE_BEGIN); if (err) return err; err = br_fill_vlan_tinfo(skb, vtend->vid, - vtend->tinfo.tunnel_id, + READ_ONCE(vtend->tinfo.tunnel_id), BRIDGE_VLAN_INFO_RANGE_END); if (err) return err; } else { err = br_fill_vlan_tinfo(skb, vtbegin->vid, - vtbegin->tinfo.tunnel_id, + READ_ONCE(vtbegin->tinfo.tunnel_id), 0); if (err) return err; diff --git a/net/bridge/br_vlan_tunnel.c b/net/bridge/br_vlan_tunnel.c index 257cae9f1569..04751f15d708 100644 --- a/net/bridge/br_vlan_tunnel.c +++ b/net/bridge/br_vlan_tunnel.c @@ -22,7 +22,7 @@ static inline int br_vlan_tunid_cmp(struct rhashtable_compare_arg *arg, const struct net_bridge_vlan *vle = ptr; __be64 tunid = *(__be64 *)arg->key; - return vle->tinfo.tunnel_id != tunid; + return READ_ONCE(vle->tinfo.tunnel_id) != tunid; } static const struct rhashtable_params br_vlan_tunnel_rht_params = { From 9ef138b168fd97da01ebd258283e0f78528b785f Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Thu, 3 Sep 2026 17:31:38 +0300 Subject: [PATCH 0264/2126] net: bridge: use br_vlan_get_state to get vlan state The vlan state can change under RTNL or RCU (mst), so use the helper to get the state properly throughout the bridge driver. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260903143138.1574598-10-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_mst.c | 7 ++++--- net/bridge/br_private.h | 21 +++++++++++---------- net/bridge/br_vlan.c | 2 +- net/bridge/br_vlan_options.c | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/net/bridge/br_mst.c b/net/bridge/br_mst.c index 76a5bf287578..ecd8bba7430e 100644 --- a/net/bridge/br_mst.c +++ b/net/bridge/br_mst.c @@ -70,7 +70,7 @@ int br_mst_get_state(const struct net_device *dev, u16 msti, u8 *state) list_for_each_entry(v, &vg->vlan_list, vlist) { if (v->brvlan->msti == msti) { - *state = v->state; + *state = br_vlan_get_state(v); return 0; } } @@ -145,7 +145,7 @@ static void br_mst_vlan_sync_state(struct net_bridge_vlan *pv, u16 msti) * it. */ if (v != pv && v->brvlan->msti == msti) { - br_mst_vlan_set_state(vg, pv, v->state); + br_mst_vlan_set_state(vg, pv, br_vlan_get_state(v)); return; } } @@ -282,7 +282,8 @@ int br_mst_fill_info(struct sk_buff *skb, nest = nla_nest_start_noflag(skb, IFLA_BRIDGE_MST_ENTRY); if (!nest || nla_put_u16(skb, IFLA_BRIDGE_MST_ENTRY_MSTI, v->brvlan->msti) || - nla_put_u8(skb, IFLA_BRIDGE_MST_ENTRY_STATE, v->state)) { + nla_put_u8(skb, IFLA_BRIDGE_MST_ENTRY_STATE, + br_vlan_get_state(v))) { err = -EMSGSIZE; break; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index c7b64b5da012..df1500391f1d 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -687,6 +687,15 @@ static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) return true; } +/* The vlan state can be changed with only rcu held by the mst code so + * annotate the lock-free read. br_vlan_set_state() is kept further down + * because it needs br_multicast_update_vlan_mcast_ctx(). + */ +static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) +{ + return READ_ONCE(v->state); +} + static inline bool nbp_state_should_learn(const struct net_bridge_port *p) { return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING; @@ -1299,7 +1308,7 @@ br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx) return pmctx->port->state == BR_STATE_DISABLED || (br_multicast_port_ctx_is_vlan(pmctx) && (br_multicast_port_ctx_vlan_disabled(pmctx) || - pmctx->vlan->state == BR_STATE_DISABLED)); + br_vlan_get_state(pmctx->vlan) == BR_STATE_DISABLED)); } static inline bool @@ -1308,7 +1317,7 @@ br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx) return br_multicast_port_ctx_state_disabled(pmctx) || pmctx->port->state == BR_STATE_BLOCKING || (br_multicast_port_ctx_is_vlan(pmctx) && - pmctx->vlan->state == BR_STATE_BLOCKING); + br_vlan_get_state(pmctx->vlan) == BR_STATE_BLOCKING); } static inline bool @@ -1916,14 +1925,6 @@ bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range, const struct net_bridge_vlan *v_opts); -/* vlan state manipulation helpers using *_ONCE to annotate lock-free access, - * while br_vlan_set_state() may access data protected by multicast_lock. - */ -static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) -{ - return READ_ONCE(v->state); -} - static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) { WRITE_ONCE(v->state, state); diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 95187a607ec2..72b75757ac85 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -40,7 +40,7 @@ static void __vlan_add_pvid(struct net_bridge_vlan_group *vg, if (vg->pvid == v->vid) return; - br_vlan_set_pvid_state(vg, v->state); + br_vlan_set_pvid_state(vg, br_vlan_get_state(v)); WRITE_ONCE(vg->pvid, v->vid); } diff --git a/net/bridge/br_vlan_options.c b/net/bridge/br_vlan_options.c index bd049d268fe7..506668fc31d9 100644 --- a/net/bridge/br_vlan_options.c +++ b/net/bridge/br_vlan_options.c @@ -43,7 +43,7 @@ bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr, u8 range_mc_rtr = br_vlan_multicast_router(range_end); u8 curr_mc_rtr = br_vlan_multicast_router(v_curr); - if (v_curr->state != range_end->state) + if (br_vlan_get_state(v_curr) != br_vlan_get_state(range_end)) return false; if (!__vlan_tun_can_enter_range(v_curr, range_end)) From 8cc3aef0cb198049805ecc061a2cc7b79b0ae43e Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Fri, 4 Sep 2026 03:35:28 +0000 Subject: [PATCH 0265/2126] tcp: Do not allow buggy transitions between ehash and lhash2. The following state transitions have long been a playground for syzbot, and recently AI joined in, reporting a lot more bugs. * listen() + shutdown() + connect() * connect() + connect(AF_UNSPEC) + listen() All the fix attempts would add more code to the fast path, which is not worth it. Instead of playing whack-a-mole with these edge-case bugs, let's disallow these transitions. Note that unhashed_state is placed in the 4-byte hole after icsk_pmtu_cookie. $ pahole -C inet_connection_sock vmlinux struct inet_connection_sock { ... __u32 icsk_pmtu_cookie; /* 1208 4 */ unsigned char unhashed_state; /* 1212 1 */ /* XXX 3 bytes hole, try to pack */ Reported-by: Kyle Zeng Closes: https://lore.kernel.org/netdev/20260731140512.566464-1-david.lee@trailofbits.com/ Reported-by: Michal Luczaj Closes: https://lore.kernel.org/netdev/20260803-sockmap-lookup-tcp-leak-v2-0-306e025bfe66@rbox.co/ Reported-by: Hyunwoo Kim Closes: https://lore.kernel.org/netdev/20260824033331.1084971-1-imv4bel@gmail.com/ Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260904033543.2635540-2-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/inet_connection_sock.h | 1 + net/ipv4/inet_connection_sock.c | 1 + net/ipv4/inet_hashtables.c | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index 433c2df23076..903499581db7 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -94,6 +94,7 @@ struct inet_connection_sock { u32 icsk_rto_max; __u32 icsk_delack_max; __u32 icsk_pmtu_cookie; + unsigned char unhashed_state; const struct tcp_congestion_ops *icsk_ca_ops; const struct inet_connection_sock_af_ops *icsk_af_ops; const struct tcp_ulp_ops *icsk_ulp_ops; diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 6257459bcee2..560ca861b6d0 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1253,6 +1253,7 @@ struct sock *inet_csk_clone_lock(const struct sock *sk, memset(&newicsk->icsk_accept_queue, 0, sizeof(newicsk->icsk_accept_queue)); + newicsk->unhashed_state = 0; inet_sk_set_state(newsk, TCP_SYN_RECV); inet_clone_ulp(req, newsk, priority); diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index ba0faa9ae2bb..5abcb0debb27 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -803,6 +803,11 @@ int inet_hash(struct sock *sk) inet_init_ehash_secret(); WARN_ON(!sk_unhashed(sk)); + + if (unlikely(inet_csk(sk)->unhashed_state && + inet_csk(sk)->unhashed_state != TCP_LISTEN)) + return -EINVAL; + ilb2 = inet_lhash2_bucket_sk(hashinfo, sk); spin_lock(&ilb2->lock); @@ -832,6 +837,9 @@ void inet_unhash(struct sock *sk) return; sock_rps_delete_flow(sk); + + inet_csk(sk)->unhashed_state = sk->sk_state; + if (sk->sk_state == TCP_LISTEN) { struct inet_listen_hashbucket *ilb2; @@ -1058,6 +1066,9 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, int ret, i, low, high; bool local_ports; + if (unlikely(inet_csk(sk)->unhashed_state == TCP_LISTEN)) + return -EINVAL; + if (port) { local_bh_disable(); ret = check_established(death_row, sk, port, NULL, false, From 31c5ea8a3296e1486ac34bccea452bfe8c0bb1f9 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Fri, 4 Sep 2026 03:35:29 +0000 Subject: [PATCH 0266/2126] ipv6: Remove IPV6_ADDRFORM. Recently, IPV6_ADDRFORM has received many AI-driven bug reports. Fixing them properly would needlessly churn the fast paths in TCP and UDP. IPV6_ADDRFORM was initially introduced in RFC 2133 in 1997, but only two years later, it was removed from RFC 2553 in 1999. In 2026, modern applications natively support dual-stack sockets; notably, systemd's socket activation does not use IPV6_ADDRFORM. Also, getsockopt(IPV6_ADDRFORM) can be replaced with SO_DOMAIN. Let's remove IPV6_ADDRFORM. Later, we can remove sk->sk_prot_creator and revert commit c26c192c3d48 ("udp: properly deal with xfrm encap and ADDRFORM"). Reported-by: Daehyeon Ko <4ncienth@gmail.com> Closes: https://lore.kernel.org/netdev/20260902010408.1057857-1-4ncienth@gmail.com/ Reported-by: Hyunwoo Kim Closes: https://lore.kernel.org/netdev/20260824033331.1084971-1-imv4bel@gmail.com/ Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260904033543.2635540-3-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/linux/net.h | 2 +- net/core/sock.c | 4 +- net/ipv4/af_inet.c | 3 -- net/ipv6/af_inet6.c | 4 -- net/ipv6/ipv6_sockglue.c | 87 ---------------------------------------- 5 files changed, 2 insertions(+), 98 deletions(-) diff --git a/include/linux/net.h b/include/linux/net.h index 3d82966e2243..470100ae7107 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -166,7 +166,7 @@ struct socket { struct file *file; struct sock *sk; - const struct proto_ops *ops; /* Might change with IPV6_ADDRFORM or MPTCP. */ + const struct proto_ops *ops; /* Might change with MPTCP. */ struct socket_wq wq; }; diff --git a/net/core/sock.c b/net/core/sock.c index fa60b7494c58..1d5927cd49a1 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -770,7 +770,7 @@ bool sk_mc_loop(const struct sock *sk) return false; if (!sk) return true; - /* IPV6_ADDRFORM can change sk->sk_family under us. */ + switch (READ_ONCE(sk->sk_family)) { case AF_INET: return inet_test_bit(MC_LOOP, sk); @@ -4010,7 +4010,6 @@ int sock_common_getsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ return READ_ONCE(sk->sk_prot)->getsockopt(sk, level, optname, optval, optlen); } EXPORT_SYMBOL(sock_common_getsockopt); @@ -4032,7 +4031,6 @@ int sock_common_setsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ return READ_ONCE(sk->sk_prot)->setsockopt(sk, level, optname, optval, optlen); } EXPORT_SYMBOL(sock_common_setsockopt); diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 32d006c1a8ee..d9421ac38d78 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -582,7 +582,6 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr_unsized *uaddr, if (addr_len < sizeof(uaddr->sa_family)) return -EINVAL; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ prot = READ_ONCE(sk->sk_prot); if (uaddr->sa_family == AF_UNSPEC) @@ -789,7 +788,6 @@ int inet_accept(struct socket *sock, struct socket *newsock, { struct sock *sk1 = sock->sk, *sk2; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ arg->err = -EINVAL; sk2 = READ_ONCE(sk1->sk_prot)->accept(sk1, arg); if (!sk2) @@ -875,7 +873,6 @@ void inet_splice_eof(struct socket *sock) if (unlikely(inet_send_prepare(sk))) return; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ prot = READ_ONCE(sk->sk_prot); if (prot->splice_eof) prot->splice_eof(sock); diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 282912a11999..f0efdc13baf4 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -429,7 +429,6 @@ int inet6_bind_sk(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len) const struct proto *prot; int err = 0; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ prot = READ_ONCE(sk->sk_prot); /* If the socket has its own bind function then use it. */ if (prot->bind) @@ -567,7 +566,6 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) case SIOCSIFDSTADDR: return addrconf_set_dstaddr(net, argp); default: - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ prot = READ_ONCE(sk->sk_prot); if (!prot->ioctl) return -ENOIOCTLCMD; @@ -636,7 +634,6 @@ int inet6_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) if (unlikely(inet_send_prepare(sk))) return -EAGAIN; - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ prot = READ_ONCE(sk->sk_prot); return INDIRECT_CALL_2(prot->sendmsg, tcp_sendmsg, udpv6_sendmsg, sk, msg, size); @@ -651,7 +648,6 @@ int inet6_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, if (likely(!(flags & MSG_ERRQUEUE))) sock_rps_record_flow(sk); - /* IPV6_ADDRFORM can change sk->sk_prot under us. */ prot = READ_ONCE(sk->sk_prot); return INDIRECT_CALL_2(prot->recvmsg, tcp_recvmsg, udpv6_recvmsg, sk, msg, size, flags); diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index b4c977434c2e..1f68fb64a43e 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -547,86 +547,7 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, sockopt_lock_sock(sk); - /* Another thread has converted the socket into IPv4 with - * IPV6_ADDRFORM concurrently. - */ - if (unlikely(sk->sk_family != AF_INET6)) - goto unlock; - switch (optname) { - - case IPV6_ADDRFORM: - if (optlen < sizeof(int)) - goto e_inval; - if (val == PF_INET) { - if (sk->sk_type == SOCK_RAW) - break; - - if (sk->sk_protocol == IPPROTO_UDP) { - if (udp_sk(sk)->pending == AF_INET6) { - retv = -EBUSY; - break; - } - } else if (sk->sk_protocol == IPPROTO_TCP) { - if (sk->sk_prot != &tcpv6_prot) { - retv = -EBUSY; - break; - } - } else { - break; - } - - if (sk->sk_state != TCP_ESTABLISHED) { - retv = -ENOTCONN; - break; - } - - if (ipv6_only_sock(sk) || - !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) { - retv = -EADDRNOTAVAIL; - break; - } - - __ipv6_sock_mc_close(sk); - __ipv6_sock_ac_close(sk); - - if (sk->sk_protocol == IPPROTO_TCP) { - struct inet_connection_sock *icsk = inet_csk(sk); - - sock_prot_inuse_add(net, sk->sk_prot, -1); - sock_prot_inuse_add(net, &tcp_prot, 1); - - /* Paired with READ_ONCE(sk->sk_prot) in inet6_stream_ops */ - WRITE_ONCE(sk->sk_prot, &tcp_prot); - /* Paired with READ_ONCE() in tcp_(get|set)sockopt() */ - WRITE_ONCE(icsk->icsk_af_ops, &ipv4_specific); - WRITE_ONCE(sk->sk_socket->ops, &inet_stream_ops); - WRITE_ONCE(sk->sk_family, PF_INET); - tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); - } else { - sock_prot_inuse_add(net, sk->sk_prot, -1); - sock_prot_inuse_add(net, &udp_prot, 1); - - /* Paired with READ_ONCE(sk->sk_prot) in inet6_dgram_ops */ - WRITE_ONCE(sk->sk_prot, &udp_prot); - WRITE_ONCE(sk->sk_socket->ops, &inet_dgram_ops); - WRITE_ONCE(sk->sk_family, PF_INET); - } - - /* Disable all options not to allocate memory anymore, - * but there is still a race. See the lockless path - * in udpv6_sendmsg() and ipv6_local_rxpmtu(). - */ - np->rxopt.all = 0; - - inet6_cleanup_sock(sk); - - module_put(THIS_MODULE); - retv = 0; - break; - } - goto e_inval; - case IPV6_V6ONLY: if (optlen < sizeof(int) || inet_sk(sk)->inet_num) @@ -1088,14 +1009,6 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname, if (copy_from_sockptr(&len, optlen, sizeof(int))) return -EFAULT; switch (optname) { - case IPV6_ADDRFORM: - if (sk->sk_protocol != IPPROTO_UDP && - sk->sk_protocol != IPPROTO_TCP) - return -ENOPROTOOPT; - if (sk->sk_state != TCP_ESTABLISHED) - return -ENOTCONN; - val = sk->sk_family; - break; case MCAST_MSFILTER: if (in_compat_syscall()) return compat_ipv6_get_msfilter(sk, optval, optlen, len); From 32ca12fbcf6bb001a7121112f113ac0380b4af0f Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 16:11:04 +0530 Subject: [PATCH 0267/2126] mdio-mux: fix typo "framwork" in comment Correct "framwork" to "framework", reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260904104107.12832-2-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- include/linux/mdio-mux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/mdio-mux.h b/include/linux/mdio-mux.h index a5d58f221939..e2af9cb8e017 100644 --- a/include/linux/mdio-mux.h +++ b/include/linux/mdio-mux.h @@ -1,5 +1,5 @@ /* - * MDIO bus multiplexer framwork. + * MDIO bus multiplexer framework. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive From 4e2554eab15a6ef6030008a411c3208e9cc54a1a Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 16:11:05 +0530 Subject: [PATCH 0268/2126] mii: fix typo "asymetric" in comment Correct "asymetric" to "asymmetric", reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260904104107.12832-3-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- include/uapi/linux/mii.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/mii.h b/include/uapi/linux/mii.h index 61d6edad4b94..d662c10ee282 100644 --- a/include/uapi/linux/mii.h +++ b/include/uapi/linux/mii.h @@ -81,7 +81,7 @@ #define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */ #define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */ #define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */ -#define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */ +#define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymmetric pause */ #define ADVERTISE_XNP 0x1000 /* Extended Next Page */ #define ADVERTISE_RESV ADVERTISE_XNP /* Used to be reserved */ #define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */ From fde5a8bc4cc72cc83ec8bca5ffd58dbb7eabe5d0 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 17:29:16 +0530 Subject: [PATCH 0269/2126] net: cortina: fix typo "trigged" in comment Correct "trigged" to "triggered", reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260904115917.13695-1-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cortina/gemini.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h index 24bb989981f2..d359c633c5de 100644 --- a/drivers/net/ethernet/cortina/gemini.h +++ b/drivers/net/ethernet/cortina/gemini.h @@ -726,7 +726,7 @@ union gmac_config0 { unsigned int dis_rx:1; /* 2: transmit data loopback enable */ unsigned int loop_back:1; - /* 3: flow control also trigged by Rx queues */ + /* 3: flow control also triggered by Rx queues */ unsigned int flow_ctrl:1; /* 4-7: adjust IFG from 96+/-56 */ unsigned int adj_ifg:4; From 39fdc543a05b9805368e209387a91463c61f6cb3 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 17:51:56 +0530 Subject: [PATCH 0270/2126] net: ipv6: fix typos in comments Fix typos in comments, reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Link: https://patch.msgid.link/20260904122157.29281-1-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/ah6.c | 2 +- net/ipv6/ip6_vti.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c index c96f7e0d0a48..ec9aba2bc6e4 100644 --- a/net/ipv6/ah6.c +++ b/net/ipv6/ah6.c @@ -169,7 +169,7 @@ bad: /** * ipv6_rearrange_destopt - rearrange IPv6 destination options header * @iph: IPv6 header - * @destopt: destionation options header + * @destopt: destination options header */ static void ipv6_rearrange_destopt(struct ipv6hdr *iph, struct ipv6_opt_hdr *destopt) { diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index ab94b3a4ba9c..c79027839151 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -437,7 +437,7 @@ static bool vti6_state_check(const struct xfrm_state *x, * vti6_xmit - send a packet * @skb: the outgoing socket buffer * @dev: the outgoing tunnel device - * @fl: the flow informations for the xfrm_lookup + * @fl: the flow information for the xfrm_lookup **/ static int vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) From bc6fe9d301d59fe5cb236d646abe792bffae5fa6 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 18:06:37 +0530 Subject: [PATCH 0271/2126] atm: fix typo "protcol" in comment Correct "protcol" to "protocol", reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Link: https://patch.msgid.link/20260904123638.39273-1-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- include/uapi/linux/atm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/atm.h b/include/uapi/linux/atm.h index 95ebdcf4fe88..7a3789f39f52 100644 --- a/include/uapi/linux/atm.h +++ b/include/uapi/linux/atm.h @@ -39,7 +39,7 @@ #define ATM_MAX_VCI 65535 /* maximum VCI */ -/* "protcol" values for the socket system call */ +/* "protocol" values for the socket system call */ #define ATM_NO_AAL 0 /* AAL not specified */ #define ATM_AAL0 13 /* "raw" ATM cells */ #define ATM_AAL1 1 /* AAL1 (CBR) */ From de2cb461456143a69845c24ce38ac14a61d6e166 Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Sat, 29 Aug 2026 14:53:24 +0000 Subject: [PATCH 0272/2126] wifi: rtw89: 8922au: Add support for TP-Link TBE400U idVendor=37ad, idProduct=0104 TP-Link TBE400U (USB-C, no external antenna) idVendor=37ad, idProduct=0106 TP-Link Archer TBE400U Plus (USB-A, antenna) https://github.com/morrownr/rtw89/pull/123 https://github.com/morrownr/rtw89/commit/c98e6ff31c331be35383b5a500cfaf76620e2d0c Signed-off-by: Nick Venenga Acked-by: Ping-Ke Shih Link: https://patch.msgid.link/010f01a04e02d70c-a52abf35-2e60-47a5-99f5-b064b344ac19-000000@us-east-2.amazonses.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/rtw8922au.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922au.c b/drivers/net/wireless/realtek/rtw89/rtw8922au.c index 2cd2b76d19ac..7854e6aca749 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922au.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922au.c @@ -64,6 +64,10 @@ static const struct usb_device_id rtw_8922au_id_table[] = { .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, { USB_DEVICE_AND_INTERFACE_INFO(0x37ad, 0x0101, 0xff, 0xff, 0xff), .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, + { USB_DEVICE_AND_INTERFACE_INFO(0x37ad, 0x0104, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, + { USB_DEVICE_AND_INTERFACE_INFO(0x37ad, 0x0106, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x3822, 0xff, 0xff, 0xff), .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x4822, 0xff, 0xff, 0xff), From 475539db19530b7e134f58555e1afcae21d419f3 Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Wed, 2 Sep 2026 00:59:10 +0000 Subject: [PATCH 0273/2126] wifi: rtw89: 8922au: add ASUS BE93 ASUS USB-BE93 Mini USB-C adapter Originally added and tested here https://github.com/morrownr/rtw89/pull/121 Acked-by: Ping-Ke Shih Signed-off-by: Nick Venenga Link: https://patch.msgid.link/010f01a05fa084ba-80349068-cd1f-4e4e-99f5-8cf6f4c03216-000000@us-east-2.amazonses.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/rtw8922au.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922au.c b/drivers/net/wireless/realtek/rtw89/rtw8922au.c index 7854e6aca749..b146bd79c675 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922au.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922au.c @@ -52,6 +52,8 @@ static const struct usb_device_id rtw_8922au_id_table[] = { .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, { USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x1bd2, 0xff, 0xff, 0xff), .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, + { USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x1d84, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, { USB_DEVICE_AND_INTERFACE_INFO(0x0bda, 0x8912, 0xff, 0xff, 0xff), .driver_info = (kernel_ulong_t)&rtw89_8922au_info }, { USB_DEVICE_AND_INTERFACE_INFO(0x0db0, 0xda0e, 0xff, 0xff, 0xff), From ed9c7dee56be9616f0a57956b8d94583343ab41b Mon Sep 17 00:00:00 2001 From: Gongwei Li Date: Tue, 1 Sep 2026 17:33:31 +0800 Subject: [PATCH 0274/2126] wifi: rtw89: fw: propagate real error code in rtw89_fw_h2c_add_general_pkt() The error path of rtw89_fw_h2c_add_general_pkt() returns -ENOMEM unconditionally, which masks the real reason of a failure. In particular: * rtw89_fw_h2c_add_pkt_offload() can fail with -ENOSPC when no more packet offload slot is available, or with the error of H2C TX, but the callers only see -ENOMEM and get misled when debugging. * For an unsupported type, the switch default case returns -ENOMEM, which is misleading and should be -EINVAL. Return a real error code instead of -ENOMEM, and use -EINVAL for unsupported types. Signed-off-by: Gongwei Li Acked-by: Ping-Ke Shih Link: https://patch.msgid.link/20260901093331.3441469-1-13875017792@163.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/fw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index b2991bc93f85..e409426c92e8 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -3091,11 +3091,14 @@ static int rtw89_fw_h2c_add_general_pkt(struct rtw89_dev *rtwdev, skb = rtw89_arp_response_get(rtwdev, rtwvif_link); break; default: + ret = -EINVAL; goto err; } - if (!skb) + if (!skb) { + ret = -ENOMEM; goto err; + } ret = rtw89_fw_h2c_add_pkt_offload(rtwdev, &info->id, skb); kfree_skb(skb); @@ -3109,7 +3112,7 @@ static int rtw89_fw_h2c_add_general_pkt(struct rtw89_dev *rtwdev, err: kfree(info); - return -ENOMEM; + return ret; } void rtw89_fw_release_general_pkt_list_vif(struct rtw89_dev *rtwdev, From 0fe85a5f9ef3e07a1c656890e7033efe98daffa0 Mon Sep 17 00:00:00 2001 From: YuChia-Kan Date: Wed, 2 Sep 2026 11:14:08 +0800 Subject: [PATCH 0275/2126] wifi: rtw88: use firmware MAC address as fallback Some devices provide the Wi-Fi MAC address through firmware instead of storing a valid address in the Wi-Fi chip efuse. This is the case on the Xiaomi Mi Box 4, which uses an Amlogic S905L SoC and an RTL8723DS Wi-Fi chip. The Wi-Fi MAC address is stored in the S905L efuse rather than the RTL8723DS efuse and is provided to the device through firmware. Try to read the MAC address from firmware before falling back to a randomly generated address. Signed-off-by: YuChia-Kan Acked-by: Ping-Ke Shih Link: https://patch.msgid.link/20260902031408.4155609-1-raspberrykan@stu.hqu.edu.cn Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw88/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c index cd9254370fcc..0f23498b5c96 100644 --- a/drivers/net/wireless/realtek/rtw88/main.c +++ b/drivers/net/wireless/realtek/rtw88/main.c @@ -2060,8 +2060,11 @@ static int rtw_chip_efuse_info_setup(struct rtw_dev *rtwdev) efuse->ext_lna_5g = efuse->lna_type_5g & BIT(3) ? 1 : 0; if (!is_valid_ether_addr(efuse->addr)) { - eth_random_addr(efuse->addr); - dev_warn(rtwdev->dev, "efuse MAC invalid, using random\n"); + if (device_get_mac_address(rtwdev->dev, efuse->addr)) { + eth_random_addr(efuse->addr); + dev_warn(rtwdev->dev, + "failed to get valid MAC address, using random\n"); + } } out_disable: From c4804286629cdd8639de6409c58a38d006162b6b Mon Sep 17 00:00:00 2001 From: Chih-Wen Hsiao Date: Wed, 2 Sep 2026 13:29:46 +0800 Subject: [PATCH 0276/2126] wifi: rtw89: 8922d: disable VCORE for thermal protection by default To ensure the stability of the thermal protection mechanism, the primary approach is to reduce the transmit (TX) duty cycle; the option to lower the voltage(VCORE) is disabled by default. Signed-off-by: Chih-Wen Hsiao Link: https://patch.msgid.link/20260902052958.50371-3-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/rtw8922d.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 2b21d969ece7..ad2c6401971b 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6463,6 +6463,7 @@ enum rtw89_quirks { RTW89_QUIRK_PCI_BER, RTW89_QUIRK_THERMAL_PROT_120C, RTW89_QUIRK_THERMAL_PROT_110C, + RTW89_QUIRK_THERMAL_PROT_VCORE, RTW89_QUIRK_HW_INFO_SYSFS, RTW89_QUIRK_DISABLE_2GHZ, diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 142e693c87bf..a9737c674ecb 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -901,6 +901,9 @@ static int rtw8922d_read_sys(struct rtw89_dev *rtwdev, u8 *log_map) u16 digk; u8 vmin; + if (!test_bit(RTW89_QUIRK_THERMAL_PROT_VCORE, rtwdev->quirks)) + return 0; + digk = log_map[0x200] | log_map[0x201] << 8; hal->thermal_prot_vmax = u16_get_bits(digk, B_BE_PWMTUNE_MASK); From 4aae1be9483dee7877244f1f1a8cc1b469669e49 Mon Sep 17 00:00:00 2001 From: Hsiao-Yung Chen Date: Wed, 2 Sep 2026 13:29:47 +0800 Subject: [PATCH 0277/2126] wifi: rtw89: allow two station interfaces in SCC The single-channel interface combination previously permitted only one STATION interface, alongside one P2P or AP interface. Raise the STATION limit to two so that a STA + STA combination is allowed in the single channel concurrency (SCC) case. This enables concurrent dual-STA use cases on the same channel, such as having one STA interface connected to an AP router for Internet access, while the second STA interface connects to another local peer/device for dedicated media/data streaming. Benchmark results on RTL8922DE in 6 GHz / 80 MHz SCC mode (UDP): STA1 alone SCC STA1+STA2 STA2 alone UDP TX (Gbps) 0.95 0.52 + 0.49 0.99 UDP RX (Gbps) 0.95 0.56 + 0.46 0.95 Signed-off-by: Hsiao-Yung Chen Link: https://patch.msgid.link/20260902052958.50371-4-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 397ebbfcac09..24275c2250e7 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -167,7 +167,7 @@ static struct ieee80211_rate rtw89_bitrates[] = { static const struct ieee80211_iface_limit rtw89_iface_limits[] = { { - .max = 1, + .max = 2, .types = BIT(NL80211_IFTYPE_STATION), }, { From 6aa8d015d1955e8d0c40cce31af186ce72a67b76 Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Wed, 2 Sep 2026 13:29:48 +0800 Subject: [PATCH 0278/2126] wifi: rtw89: 8922d: update BB wrapper RFSI ctrl to v4 Update the BB wrapper RFSI control configuration tables for RTL8922D variants to v4. Remove the redundant table for RFE types 35/41/44, which use the default 7090 configuration, and add table for RFE type 38. Signed-off-by: Eric Huang Link: https://patch.msgid.link/20260902052958.50371-5-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/phy.h | 14 ++- drivers/net/wireless/realtek/rtw89/phy_be.c | 79 +++++++++----- drivers/net/wireless/realtek/rtw89/reg.h | 4 + drivers/net/wireless/realtek/rtw89/rtw8922d.c | 103 ++++++++++++------ 4 files changed, 139 insertions(+), 61 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy.h b/drivers/net/wireless/realtek/rtw89/phy.h index 0963cdfb1594..7fc15e5c5ffc 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.h +++ b/drivers/net/wireless/realtek/rtw89/phy.h @@ -632,7 +632,18 @@ struct rtw89_bb_wrap_common_data { u32 rfsi_ct_opt[2]; u8 pb_tb; } bands[RFSI_CTRL_BAND_NUM]; - u8 qam_th[6]; + u8 qam_th[3]; +}; + +struct rtw89_bb_wrap_common_data_gen2 { + struct { + u8 mdpd_160m; + u8 mdpd_320m; + u8 oob_dpd_20m; + u8 oob_dpd_40m; + u8 oob_dpd_80m; + u8 cim3k; + } qam_th; }; struct rtw89_bb_wrap_common_data_gen3 { @@ -644,6 +655,7 @@ struct rtw89_bb_wrap_common_data_gen3 { struct rtw89_bb_wrap_data { const struct rtw89_bb_wrap_common_data *common; + const struct rtw89_bb_wrap_common_data_gen2 *common_gen2; const struct rtw89_bb_wrap_common_data_gen3 *common_gen3; struct { u16 qam_comp_th0[MAX_TX_RFSI_CTRL_OPT]; diff --git a/drivers/net/wireless/realtek/rtw89/phy_be.c b/drivers/net/wireless/realtek/rtw89/phy_be.c index c06927d1dc78..db33b73ab357 100644 --- a/drivers/net/wireless/realtek/rtw89/phy_be.c +++ b/drivers/net/wireless/realtek/rtw89/phy_be.c @@ -772,6 +772,26 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_QAM_TH2_BE4, B_QAM_TH2_2_BE4, th2, mac_idx); rtw89_write32_idx(rtwdev, R_QAM_TH2_BE4, B_QAM_TH2_5_BE4, th2, mac_idx); rtw89_write32_idx(rtwdev, R_QAM_TH2_BE4, B_QAM_TH2_8_BE4, th2, mac_idx); +} + +static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen2_init(struct rtw89_dev *rtwdev, + enum rtw89_mac_idx mac_idx) +{ + const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; + const struct rtw89_bb_wrap_common_data_gen2 *common_gen2; + u8 th0, th2, th3, th4, th5; + + if (!d || !d->common_gen2) + return; + + common_gen2 = d->common_gen2; + th0 = common_gen2->qam_th.mdpd_160m; + /* th1 (MDPD 320M) has no RTL8922D wrapper register */ + th2 = common_gen2->qam_th.oob_dpd_20m; + th3 = common_gen2->qam_th.oob_dpd_40m; + th4 = common_gen2->qam_th.oob_dpd_80m; + th5 = common_gen2->qam_th.cim3k; + /* DPD 160M */ rtw89_write32_idx(rtwdev, R_DPD_DBW160_TH0_BE4, B_DPD_DBW160_TH0_0_BE4, th0, mac_idx); rtw89_write32_idx(rtwdev, R_DPD_DBW160_TH0_BE4, B_DPD_DBW160_TH0_1_BE4, th0, mac_idx); @@ -782,34 +802,34 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_DPD_DBW160_TH1_BE4, B_DPD_DBW160_TH1_6_BE4, th0, mac_idx); rtw89_write32_idx(rtwdev, R_DPD_DBW160_TH1_BE4, B_DPD_DBW160_TH1_7_BE4, th0, mac_idx); /* DPD 20M */ - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_0_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_1_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_2_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_3_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_4_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_5_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_6_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW20_TH1_7_BE4, 0x2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_0_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_1_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_2_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_3_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_4_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_5_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH0_BE4, B_DPD_CBW20_TH0_6_BE4, th2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW20_TH1_7_BE4, th2, mac_idx); /* DPD 40M */ - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_0_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_1_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_2_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_3_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_4_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW20_TH0_3_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW20_TH0_4_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW20_TH0_5_BE4, 0x2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_0_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_1_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_2_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_3_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_4_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_5_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_6_BE4, th3, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW40_TH1_7_BE4, th3, mac_idx); /* DPD 80M */ - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW80_TH1_0_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_1_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_2_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_3_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_4_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_5_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_6_BE4, 0x2, mac_idx); - rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_7_BE4, 0x2, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH1_BE4, B_DPD_CBW80_TH1_0_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_1_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_2_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_3_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_4_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_5_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_6_BE4, th4, mac_idx); + rtw89_write32_idx(rtwdev, R_DPD_CBW_TH2_BE4, B_DPD_CBW80_TH2_7_BE4, th4, mac_idx); /* CIM3K */ - rtw89_write32_idx(rtwdev, R_COMP_CIM3K_BE4, B_COMP_CIM3K_TH2_BE4, 0x2, mac_idx); + rtw89_write32_idx(rtwdev, R_COMP_CIM3K_BE4, B_COMP_CIM3K_TH2_BE4, th5, mac_idx); } static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen3_init(struct rtw89_dev *rtwdev, @@ -1097,6 +1117,14 @@ static void rtw89_phy_bb_set_cim3k_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_CIM3K_SU_FORCE, B_CIM3K_SU_FORCE_EN, 1, mac_idx); rtw89_write32_idx(rtwdev, R_CIM3K_SU_FORCE, B_CIM3K_SU_FORCE_VAL, 0, mac_idx); + + if (rtwdev->hal.cid == RTL8922D_CID7025) + return; + + rtw89_write32_idx(rtwdev, R_CIM3K_SU_FORCE, B_CIM3K_RU26_FORCE_EN, 1, mac_idx); + rtw89_write32_idx(rtwdev, R_CIM3K_SU_FORCE, B_CIM3K_RU26_FORCE_VAL, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_CIM3K_SU_FORCE, B_CIM3K_RU52_FORCE_EN, 1, mac_idx); + rtw89_write32_idx(rtwdev, R_CIM3K_SU_FORCE, B_CIM3K_RU52_FORCE_VAL, 1, mac_idx); } static void rtw89_phy_bb_set_cck_cfir_filter_val_gen3(struct rtw89_dev *rtwdev, @@ -1147,6 +1175,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_ctrl_init(struct rtw89_dev *rtwdev, chan = conf.chans[phy_idx]; rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(rtwdev, mac_idx); + rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen2_init(rtwdev, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen3_init(rtwdev, chan, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_scenario_def(rtwdev, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(rtwdev, mac_idx); diff --git a/drivers/net/wireless/realtek/rtw89/reg.h b/drivers/net/wireless/realtek/rtw89/reg.h index abeeb61007dc..7a3ca9c82548 100644 --- a/drivers/net/wireless/realtek/rtw89/reg.h +++ b/drivers/net/wireless/realtek/rtw89/reg.h @@ -10696,6 +10696,10 @@ #define B_FBTB_CT_FTM_BE4 GENMASK(23, 20) #define B_FBTB_CT_SENS_BE4 GENMASK(27, 24) #define R_CIM3K_SU_FORCE 0x119F8 +#define B_CIM3K_RU26_FORCE_EN BIT(13) +#define B_CIM3K_RU26_FORCE_VAL BIT(14) +#define B_CIM3K_RU52_FORCE_EN BIT(15) +#define B_CIM3K_RU52_FORCE_VAL BIT(16) #define B_CIM3K_SU_FORCE_EN BIT(17) #define B_CIM3K_SU_FORCE_VAL BIT(18) #define R_QAM3_TH0_BE4 0x119FC diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index a9737c674ecb..42bfbc1c99b2 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -343,35 +343,76 @@ static const struct rtw89_efuse_block_cfg rtw8922d_efuse_blocks[] = { static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7025 = { .bands = { [RFSI_CTRL_BAND_5_6GHZ] = { - .cim3k = {CIM3K_OFF, CIM3K_OFF, CIM3K_ENABLE, CIM3K_ENABLE}, + .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 3, }, [RFSI_CTRL_BAND_2GHZ] = { - .cim3k = {CIM3K_OFF, CIM3K_OFF, CIM3K_ENABLE, CIM3K_ENABLE}, + .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, }}, - .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM, RFSI_MAX, RFSI_MAX, RFSI_MAX}, + .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, }; static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7090 = { .bands = { [RFSI_CTRL_BAND_5_6GHZ] = { - .cim3k = {CIM3K_OFF, CIM3K_OFF, CIM3K_DISABLE, CIM3K_ENABLE}, + .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, - .pb_tb = 3, + .pb_tb = 0, }, [RFSI_CTRL_BAND_2GHZ] = { - .cim3k = {CIM3K_OFF, CIM3K_OFF, CIM3K_DISABLE, CIM3K_ENABLE}, + .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, }}, - .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM, RFSI_MAX, RFSI_MAX, RFSI_MAX}, + .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, +}; + +static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7090_rfe38 = { + .bands = { + [RFSI_CTRL_BAND_5_6GHZ] = { + .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, + .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), + _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, + .pb_tb = 0, + }, + [RFSI_CTRL_BAND_2GHZ] = { + .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, + .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), + _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, + .pb_tb = 0, + }}, + .qam_th = {RFSI_QPSK, RFSI_16QAM, RFSI_256QAM}, +}; + +static const +struct rtw89_bb_wrap_common_data_gen2 rtw8922d_bb_wrap_common_data_gen2_7025 = { + .qam_th = { + .mdpd_160m = RFSI_BPSK, + .mdpd_320m = RFSI_BPSK, + .oob_dpd_20m = RFSI_16QAM, + .oob_dpd_40m = RFSI_16QAM, + .oob_dpd_80m = RFSI_16QAM, + .cim3k = RFSI_16QAM, + }, +}; + +static const +struct rtw89_bb_wrap_common_data_gen2 rtw8922d_bb_wrap_common_data_gen2_7090 = { + .qam_th = { + .mdpd_160m = RFSI_16QAM, + .mdpd_320m = RFSI_16QAM, + .oob_dpd_20m = RFSI_16QAM, + .oob_dpd_40m = RFSI_16QAM, + .oob_dpd_80m = RFSI_16QAM, + .cim3k = RFSI_16QAM, + }, }; static const @@ -390,6 +431,7 @@ struct rtw89_bb_wrap_common_data_gen3 rtw8922d_bb_wrap_common_data_gen3_7090 = { static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7025_default = { .common = &rtw8922d_bb_wrap_common_data_7025, + .common_gen2 = &rtw8922d_bb_wrap_common_data_gen2_7025, .common_gen3 = NULL, .bands = { [RFSI_CTRL_BAND_5_6GHZ] = { @@ -417,15 +459,16 @@ static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7025_default = { static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_default = { .common = &rtw8922d_bb_wrap_common_data_7090, + .common_gen2 = &rtw8922d_bb_wrap_common_data_gen2_7090, .common_gen3 = &rtw8922d_bb_wrap_common_data_gen3_7090, .bands = { [RFSI_CTRL_BAND_5_6GHZ] = { - .qam_comp_th0 = {0x4000, 0x6420, 0x6520, 0x6000, 0, 0, 0, 0, 0, 0}, - .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x6400, 0x6500, 0x6000, + .qam_comp_th0 = {0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0}, + .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0)}, - .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0x4000, + .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, - .qam_comp_ow = {0x4000, 0x4000, 0x4000, 0x4000, 0, 0, 0, 0, 0, 0}, + .qam_comp_ow = {0x4000, 0x4000, 0x4000, 0, 0, 0, 0, 0, 0, 0}, .oob_dpd_by_cbw = {OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF}, }, @@ -442,23 +485,24 @@ static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_default = { .mdpd_by_dbw = {MDPD_OFF, MDPD_OFF, MDPD_ON, MDPD_ON}, }; -static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_rfe35_41_44 = { - .common = &rtw8922d_bb_wrap_common_data_7090, +static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_rfe38 = { + .common = &rtw8922d_bb_wrap_common_data_7090_rfe38, + .common_gen2 = &rtw8922d_bb_wrap_common_data_gen2_7090, .common_gen3 = &rtw8922d_bb_wrap_common_data_gen3_7090, .bands = { [RFSI_CTRL_BAND_5_6GHZ] = { - .qam_comp_th0 = {0x4000, 0x6420, 0x6520, 0x6000, 0, 0, 0, 0, 0, 0}, - .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x6400, 0x6500, 0x6000, + .qam_comp_th0 = {0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0}, + .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0)}, - .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0x4000, + .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, - .qam_comp_ow = {0x4000, 0x4000, 0x4000, 0x4000, 0, 0, 0, 0, 0, 0}, + .qam_comp_ow = {0x4000, 0x4000, 0x4000, 0, 0, 0, 0, 0, 0, 0}, .oob_dpd_by_cbw = {OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF}, }, [RFSI_CTRL_BAND_2GHZ] = { .qam_comp_th0 = {0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0}, - .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4500, 0, 0, + .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, @@ -466,7 +510,7 @@ static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_rfe35_41_44 = .oob_dpd_by_cbw = {OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF, OOB_DPD_OFF}, }}, - .mdpd_by_dbw = {MDPD_OFF, MDPD_OFF, MDPD_ON, MDPD_ON}, + .mdpd_by_dbw = {MDPD_ON, MDPD_ON, MDPD_ON, MDPD_ON}, }; static void rtw8922d_sel_bt_rx_path(struct rtw89_dev *rtwdev, u8 val, @@ -1145,24 +1189,13 @@ static int rtw8922d_data_setup(struct rtw89_dev *rtwdev) { const struct rtw89_bb_wrap_data *data; struct rtw89_hal *hal = &rtwdev->hal; - bool rfe35_41_44 = false; - switch (rtwdev->efuse.rfe_type) { - case 35: - case 41: - case 44: - rfe35_41_44 = true; - break; - } - - if (hal->cid == RTL8922D_CID7025) { + if (hal->cid == RTL8922D_CID7025) data = &rtw8922d_bb_wrap_data_7025_default; - } else { - if (rfe35_41_44) - data = &rtw8922d_bb_wrap_data_7090_rfe35_41_44; - else - data = &rtw8922d_bb_wrap_data_7090_default; - } + else if (rtwdev->efuse.rfe_type == 38) + data = &rtw8922d_bb_wrap_data_7090_rfe38; + else + data = &rtw8922d_bb_wrap_data_7090_default; rtwdev->phy_info.bb_wrap_data = data; From 88e8ac8506a919192ebda6a59e9d386a7230372f Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 2 Sep 2026 13:29:49 +0800 Subject: [PATCH 0279/2126] wifi: rtw89: 8922d: set BB wrapper settings according to operating channel The BB wrapper settings are estimated and filled by operating channel. Set the values according to channels to yield better performance. Link: https://patch.msgid.link/20260902052958.50371-6-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/phy.h | 6 +- drivers/net/wireless/realtek/rtw89/phy_be.c | 64 +++++++++++-------- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 3 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy.h b/drivers/net/wireless/realtek/rtw89/phy.h index 7fc15e5c5ffc..977cc680ee08 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.h +++ b/drivers/net/wireless/realtek/rtw89/phy.h @@ -1051,9 +1051,9 @@ static inline void rtw89_phy_bb_wrap_init(struct rtw89_dev *rtwdev) phy->bb_wrap_init(rtwdev); } -void rtw89_phy_bb_wrap_set_rfsi_ct_opt(struct rtw89_dev *rtwdev, - enum rtw89_rfsi_ctrl_band ctrl_band, - enum rtw89_phy_idx phy_idx); +void rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, + u8 mac_idx); void rtw89_phy_bb_wrap_set_rfsi_bandedge_ch(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, enum rtw89_phy_idx phy_idx); diff --git a/drivers/net/wireless/realtek/rtw89/phy_be.c b/drivers/net/wireless/realtek/rtw89/phy_be.c index db33b73ab357..5b32910d4661 100644 --- a/drivers/net/wireless/realtek/rtw89/phy_be.c +++ b/drivers/net/wireless/realtek/rtw89/phy_be.c @@ -682,9 +682,9 @@ static u32 rtw89_phy_bb_wrap_be_bandedge_decision(struct rtw89_dev *rtwdev, return val; } -void rtw89_phy_bb_wrap_set_rfsi_ct_opt(struct rtw89_dev *rtwdev, - enum rtw89_rfsi_ctrl_band rfsi_band, - enum rtw89_phy_idx phy_idx) +static void rtw89_phy_bb_wrap_set_rfsi_ct_opt(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, + enum rtw89_mac_idx mac_idx) { const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; const u32 *val; @@ -693,15 +693,14 @@ void rtw89_phy_bb_wrap_set_rfsi_ct_opt(struct rtw89_dev *rtwdev, if (!d || !d->common) return; - val = d->common->bands[rfsi_band].rfsi_ct_opt; + val = d->common->bands[chan->rfsi_band].rfsi_ct_opt; - reg = rtw89_mac_reg_by_idx(rtwdev, R_RFSI_CT_OPT_0_BE4, phy_idx); + reg = rtw89_mac_reg_by_idx(rtwdev, R_RFSI_CT_OPT_0_BE4, mac_idx); rtw89_write32(rtwdev, reg, val[0]); - reg = rtw89_mac_reg_by_idx(rtwdev, R_RFSI_CT_OPT_8_BE4, phy_idx); + reg = rtw89_mac_reg_by_idx(rtwdev, R_RFSI_CT_OPT_8_BE4, mac_idx); rtw89_write32(rtwdev, reg, val[1]); } -EXPORT_SYMBOL(rtw89_phy_bb_wrap_set_rfsi_ct_opt); void rtw89_phy_bb_wrap_set_rfsi_bandedge_ch(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, @@ -902,13 +901,14 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen3_init(struct rtw89_dev *rt } static void rtw89_phy_bb_wrap_tx_rfsi_scenario_def(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, enum rtw89_mac_idx mac_idx) { const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; u8 pb_tb = 0; if (d && d->common) - pb_tb = d->common->bands[0].pb_tb; + pb_tb = d->common->bands[chan->rfsi_band].pb_tb; rtw89_write32_idx(rtwdev, R_RFSI_CT_DEF_BE4, B_RFSI_CT_ER_BE4, 0x0, mac_idx); rtw89_write32_idx(rtwdev, R_RFSI_CT_DEF_BE4, B_RFSI_CT_SUBF_BE4, 0x0, mac_idx); @@ -925,6 +925,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_scenario_def(struct rtw89_dev *rtwdev, } static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, enum rtw89_mac_idx mac_idx) { const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; @@ -933,7 +934,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, if (!d || !d->common) return; - th = d->bands[0].qam_comp_th0; + th = d->bands[chan->rfsi_band].qam_comp_th0; rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, MASKLWORD, th[0], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, MASKHWORD, th[1], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, MASKLWORD, th[2], mac_idx); @@ -943,7 +944,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, MASKLWORD, th[6], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, MASKHWORD, th[7], mac_idx); - th = d->bands[0].qam_comp_th1; + th = d->bands[chan->rfsi_band].qam_comp_th1; rtw89_write32_idx(rtwdev, R_QAM_COMP_TH4_BE4, B_QAM_COMP_TH4_L, th[0], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH4_BE4, B_QAM_COMP_TH4_M, th[1], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH4_BE4, B_QAM_COMP_TH4_H, th[2], mac_idx); @@ -953,7 +954,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_QAM_COMP_TH6_BE4, B_QAM_COMP_TH6_L, th[6], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH6_BE4, B_QAM_COMP_TH6_M, th[7], mac_idx); - th = d->bands[0].qam_comp_th2; + th = d->bands[chan->rfsi_band].qam_comp_th2; rtw89_write32_idx(rtwdev, R_QAM_COMP_TH4_BE4, B_QAM_COMP_TH4_2L, th[0], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH4_BE4, B_QAM_COMP_TH4_2M, th[1], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH4_BE4, B_QAM_COMP_TH4_2H, th[2], mac_idx); @@ -963,7 +964,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_QAM_COMP_TH6_BE4, B_QAM_COMP_TH6_2L, th[6], mac_idx); rtw89_write32_idx(rtwdev, R_QAM_COMP_TH6_BE4, B_QAM_COMP_TH6_2M, th[7], mac_idx); - th = d->bands[0].qam_comp_ow; + th = d->bands[chan->rfsi_band].qam_comp_ow; rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, MASKLWORD, th[0], mac_idx); rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, MASKHWORD, th[1], mac_idx); rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, MASKLWORD, th[2], mac_idx); @@ -975,6 +976,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, } static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, enum rtw89_mac_idx mac_idx) { const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; @@ -983,7 +985,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, if (!d) return; - th = d->bands[0].oob_dpd_by_cbw[0]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[0]; rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_CCK0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_CCK1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_CCK2_BE4, th, mac_idx); @@ -993,7 +995,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_CCK6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_CCK7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[1]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[1]; rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_CCK0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_CCK1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_CCK2_BE4, th, mac_idx); @@ -1003,7 +1005,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_CCK6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_CCK7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[2]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[2]; rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_TH0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_TH1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_TH2_BE4, th, mac_idx); @@ -1013,7 +1015,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_TH6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW20_BE4, B_OOB_CBW20_TH7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[3]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[3]; rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_TH0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_TH1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_TH2_BE4, th, mac_idx); @@ -1023,7 +1025,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_TH6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_TH7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[4]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[4]; rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_TH0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_TH1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_TH2_BE4, th, mac_idx); @@ -1033,7 +1035,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_TH6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_TH7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[5]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[5]; rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW20_OW0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW20_OW1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW20_OW2_BE4, th, mac_idx); @@ -1043,7 +1045,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW20_OW6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW20_OW7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[6]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[6]; rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_OW0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_OW1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_OW2_BE4, th, mac_idx); @@ -1053,7 +1055,7 @@ static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_OW6_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW40_BE4, B_OOB_CBW40_OW7_BE4, th, mac_idx); - th = d->bands[0].oob_dpd_by_cbw[7]; + th = d->bands[chan->rfsi_band].oob_dpd_by_cbw[7]; rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_OW0_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_OW1_BE4, th, mac_idx); rtw89_write32_idx(rtwdev, R_OOB_CBW80_BE4, B_OOB_CBW80_OW2_BE4, th, mac_idx); @@ -1095,6 +1097,7 @@ static void rtw89_phy_bb_set_mdpd_qam_comp_val(struct rtw89_dev *rtwdev, } static void rtw89_phy_bb_set_cim3k_val(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, enum rtw89_mac_idx mac_idx) { const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; @@ -1103,7 +1106,7 @@ static void rtw89_phy_bb_set_cim3k_val(struct rtw89_dev *rtwdev, if (!d || !d->common) return; - p = &d->common->bands[0].cim3k; + p = &d->common->bands[chan->rfsi_band].cim3k; rtw89_write32_idx(rtwdev, R_COMP_CIM3K_BE4, B_COMP_CIM3K_TH_BE4, p->th, mac_idx); rtw89_write32_idx(rtwdev, R_COMP_CIM3K_BE4, B_COMP_CIM3K_OW_BE4, p->ow, mac_idx); @@ -1174,18 +1177,25 @@ static void rtw89_phy_bb_wrap_tx_rfsi_ctrl_init(struct rtw89_dev *rtwdev, rtw89_entity_get_conf(rtwdev, &conf); chan = conf.chans[phy_idx]; + rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan(rtwdev, chan, mac_idx); +} + +void rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, + u8 mac_idx) +{ rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(rtwdev, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen2_init(rtwdev, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen3_init(rtwdev, chan, mac_idx); - rtw89_phy_bb_wrap_tx_rfsi_scenario_def(rtwdev, mac_idx); - rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(rtwdev, mac_idx); - rtw89_phy_bb_set_oob_dpd_qam_comp_val(rtwdev, mac_idx); + rtw89_phy_bb_wrap_tx_rfsi_scenario_def(rtwdev, chan, mac_idx); + rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(rtwdev, chan, mac_idx); + rtw89_phy_bb_set_oob_dpd_qam_comp_val(rtwdev, chan, mac_idx); rtw89_phy_bb_set_mdpd_qam_comp_val(rtwdev, mac_idx); - rtw89_phy_bb_set_cim3k_val(rtwdev, mac_idx); + rtw89_phy_bb_set_cim3k_val(rtwdev, chan, mac_idx); rtw89_phy_bb_set_cck_cfir_filter_val_gen3(rtwdev, mac_idx); - rtw89_phy_bb_wrap_set_rfsi_ct_opt(rtwdev, 0, phy_idx); - rtw89_phy_bb_wrap_set_rfsi_bandedge_ch(rtwdev, chan, phy_idx); + rtw89_phy_bb_wrap_set_rfsi_ct_opt(rtwdev, chan, mac_idx); } +EXPORT_SYMBOL(rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan); static void rtw89_phy_bb_wrap_ul_pwr(struct rtw89_dev *rtwdev) { diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 42bfbc1c99b2..828914ad03af 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -2544,7 +2544,8 @@ static void rtw8922d_set_channel_bb(struct rtw89_dev *rtwdev, u8 pri_sb = chan->pri_sb_idx; u32 val; - rtw89_phy_bb_wrap_set_rfsi_ct_opt(rtwdev, chan->rfsi_band, phy_idx); + rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan(rtwdev, chan, phy_idx); + rtw8922d_ctrl_ch(rtwdev, chan, phy_idx); rtw8922d_ctrl_bw(rtwdev, pri_sb, chan->band_width, phy_idx); rtw89_phy_bb_wrap_set_rfsi_bandedge_ch(rtwdev, chan, phy_idx); From 88cc74e0153836a653125cb7839bff6ed4c3be93 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 2 Sep 2026 13:29:50 +0800 Subject: [PATCH 0280/2126] wifi: rtw89: 8922d: move conditionally disabled TX shape to common flow By default, the TX shape settings are written to registers. However, if TX shape type for current operating band isn't necessary, set the disable-bit to avoid considering TX shape settings. Link: https://patch.msgid.link/20260902052958.50371-7-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/phy_be.c | 41 +++++++++++++- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 56 ------------------- 2 files changed, 40 insertions(+), 57 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy_be.c b/drivers/net/wireless/realtek/rtw89/phy_be.c index 5b32910d4661..a8fdf22e06c8 100644 --- a/drivers/net/wireless/realtek/rtw89/phy_be.c +++ b/drivers/net/wireless/realtek/rtw89/phy_be.c @@ -931,7 +931,7 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; const u16 *th; - if (!d || !d->common) + if (!d) return; th = d->bands[chan->rfsi_band].qam_comp_th0; @@ -975,6 +975,44 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(struct rtw89_dev *rtwdev, rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, MASKHWORD, th[7], mac_idx); } +static void rtw89_phy_trig_spect_tx_shape_disabled(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, + enum rtw89_mac_idx mac_idx) +{ + const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; + u8 band = chan->band_type; + u8 tx_shape_idx; + + /* + * Only needed by chips with d->bands[].{qam_comp_th0, qam_comp_ow} as + * what rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val() does. + */ + if (!d) + return; + + tx_shape_idx = rtw89_get_tx_shape_idx(rtwdev, band, RTW89_RS_OFDM); + if (tx_shape_idx) + return; + + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH2_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH2_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, mac_idx); + + rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, B_OW_VAL_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, B_OW_VAL_TRIANGULAR_H, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, B_OW_VAL_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, B_OW_VAL_TRIANGULAR_H, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_2_BE4, B_OW_VAL_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_2_BE4, B_OW_VAL_TRIANGULAR_H, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, B_OW_VAL_TRIANGULAR_L, 0, mac_idx); + rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, B_OW_VAL_TRIANGULAR_H, 0, mac_idx); +} + static void rtw89_phy_bb_set_oob_dpd_qam_comp_val(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, enum rtw89_mac_idx mac_idx) @@ -1189,6 +1227,7 @@ void rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan(struct rtw89_dev *rtwdev, rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen3_init(rtwdev, chan, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_scenario_def(rtwdev, chan, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_val(rtwdev, chan, mac_idx); + rtw89_phy_trig_spect_tx_shape_disabled(rtwdev, chan, mac_idx); rtw89_phy_bb_set_oob_dpd_qam_comp_val(rtwdev, chan, mac_idx); rtw89_phy_bb_set_mdpd_qam_comp_val(rtwdev, mac_idx); rtw89_phy_bb_set_cim3k_val(rtwdev, chan, mac_idx); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 828914ad03af..4d779ebf6121 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -2946,61 +2946,6 @@ static void rtw8922d_set_txpwr_ref(struct rtw89_dev *rtwdev, B_BE_PWR_REF_CTRL_CCK, ref_cck); } -static void rtw8922d_set_tx_shape(struct rtw89_dev *rtwdev, - const struct rtw89_chan *chan, - enum rtw89_phy_idx phy_idx) -{ - const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; - u8 band = chan->band_type; - u8 tx_shape_idx; - const u16 *th; - - tx_shape_idx = rtw89_get_tx_shape_idx(rtwdev, band, RTW89_RS_OFDM); - if (tx_shape_idx == 0) - goto disable; - - th = d->bands[chan->rfsi_band].qam_comp_th0; - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, MASKLWORD, th[0], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, MASKHWORD, th[1], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, MASKLWORD, th[2], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, MASKHWORD, th[3], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH2_BE4, MASKLWORD, th[4], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH2_BE4, MASKHWORD, th[5], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, MASKLWORD, th[6], phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, MASKHWORD, th[7], phy_idx); - - th = d->bands[chan->rfsi_band].qam_comp_ow; - rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, MASKLWORD, th[0], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, MASKHWORD, th[1], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, MASKLWORD, th[2], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, MASKHWORD, th[3], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_2_BE4, MASKLWORD, th[4], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_2_BE4, MASKHWORD, th[5], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, MASKLWORD, th[6], phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, MASKHWORD, th[7], phy_idx); - - return; - -disable: - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH0_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH1_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH2_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH2_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, B_QAM_COMP_TH_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_QAM_COMP_TH3_BE4, B_QAM_COMP_TH_TRIANGULAR_H, 0, phy_idx); - - rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, B_OW_VAL_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_0_BE4, B_OW_VAL_TRIANGULAR_H, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, B_OW_VAL_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_1_BE4, B_OW_VAL_TRIANGULAR_H, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_2_BE4, B_OW_VAL_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_2_BE4, B_OW_VAL_TRIANGULAR_H, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, B_OW_VAL_TRIANGULAR_L, 0, phy_idx); - rtw89_write32_idx(rtwdev, R_OW_VAL_3_BE4, B_OW_VAL_TRIANGULAR_H, 0, phy_idx); -} - static void rtw8922d_set_txpwr_sar_diff(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, enum rtw89_phy_idx phy_idx) @@ -3032,7 +2977,6 @@ static void rtw8922d_set_txpwr(struct rtw89_dev *rtwdev, { rtw89_phy_set_txpwr_byrate(rtwdev, chan, phy_idx); rtw89_phy_set_txpwr_offset(rtwdev, chan, phy_idx); - rtw8922d_set_tx_shape(rtwdev, chan, phy_idx); rtw89_phy_set_txpwr_limit(rtwdev, chan, phy_idx); rtw89_phy_set_txpwr_limit_ru(rtwdev, chan, phy_idx); rtw8922d_set_txpwr_ref(rtwdev, chan, phy_idx); From ca7b805204431914ce9e300bdfbbc93811adf23d Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 2 Sep 2026 13:29:51 +0800 Subject: [PATCH 0281/2126] wifi: rtw89: 8922d: update BB wrapper RFSI ctrl to v5 Update the BB wrapper RFSI control configuration tables for RTL8922D variants to v5. The major change is to define qam_th[] per band to optimize performance for RTL8922D_CID7090 variant, and others variants keep to use the same values for both bands. Link: https://patch.msgid.link/20260902052958.50371-8-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/phy.h | 2 +- drivers/net/wireless/realtek/rtw89/phy_be.c | 9 +++++---- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 15 +++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy.h b/drivers/net/wireless/realtek/rtw89/phy.h index 977cc680ee08..7bbda2ba5b5c 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.h +++ b/drivers/net/wireless/realtek/rtw89/phy.h @@ -631,8 +631,8 @@ struct rtw89_bb_wrap_common_data { } cim3k; u32 rfsi_ct_opt[2]; u8 pb_tb; + u8 qam_th[3]; } bands[RFSI_CTRL_BAND_NUM]; - u8 qam_th[3]; }; struct rtw89_bb_wrap_common_data_gen2 { diff --git a/drivers/net/wireless/realtek/rtw89/phy_be.c b/drivers/net/wireless/realtek/rtw89/phy_be.c index a8fdf22e06c8..b94754d38673 100644 --- a/drivers/net/wireless/realtek/rtw89/phy_be.c +++ b/drivers/net/wireless/realtek/rtw89/phy_be.c @@ -732,6 +732,7 @@ void rtw89_phy_bb_wrap_set_rfsi_bandedge_ch(struct rtw89_dev *rtwdev, EXPORT_SYMBOL(rtw89_phy_bb_wrap_set_rfsi_bandedge_ch); static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(struct rtw89_dev *rtwdev, + const struct rtw89_chan *chan, enum rtw89_mac_idx mac_idx) { const struct rtw89_bb_wrap_data *d = rtwdev->phy_info.bb_wrap_data; @@ -740,9 +741,9 @@ static void rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(struct rtw89_dev *rtwdev, if (!d || !d->common) return; - th0 = d->common->qam_th[0]; - th1 = d->common->qam_th[1]; - th2 = d->common->qam_th[2]; + th0 = d->common->bands[chan->rfsi_band].qam_th[0]; + th1 = d->common->bands[chan->rfsi_band].qam_th[1]; + th2 = d->common->bands[chan->rfsi_band].qam_th[2]; /* TH0 */ rtw89_write32_idx(rtwdev, R_QAM_TH0_BE4, B_QAM_TH0_0_BE4, th0, mac_idx); @@ -1222,7 +1223,7 @@ void rtw89_phy_bb_wrap_tx_rfsi_ctrl_init_by_chan(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, u8 mac_idx) { - rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(rtwdev, mac_idx); + rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_init(rtwdev, chan, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen2_init(rtwdev, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_qam_comp_th_gen3_init(rtwdev, chan, mac_idx); rtw89_phy_bb_wrap_tx_rfsi_scenario_def(rtwdev, chan, mac_idx); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 4d779ebf6121..5f910163163f 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -347,14 +347,15 @@ static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7025 .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 3, + .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, }, [RFSI_CTRL_BAND_2GHZ] = { .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, + .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, }}, - .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, }; static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7090 = { @@ -364,14 +365,15 @@ static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7090 .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, + .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, }, [RFSI_CTRL_BAND_2GHZ] = { .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, + .qam_th = {RFSI_QPSK, RFSI_16QAM, RFSI_256QAM}, }}, - .qam_th = {RFSI_BPSK, RFSI_QPSK, RFSI_256QAM}, }; static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7090_rfe38 = { @@ -381,14 +383,15 @@ static const struct rtw89_bb_wrap_common_data rtw8922d_bb_wrap_common_data_7090_ .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, + .qam_th = {RFSI_QPSK, RFSI_16QAM, RFSI_256QAM}, }, [RFSI_CTRL_BAND_2GHZ] = { .cim3k = {CIM3K_ON, CIM3K_ON, CIM3K_ENABLE, CIM3K_ENABLE}, .rfsi_ct_opt = {_8nibble(2, 2, 2, 2, 1, 1, 1, 1), _8nibble(2, 2, 2, 2, 1, 1, 1, 1)}, .pb_tb = 0, + .qam_th = {RFSI_QPSK, RFSI_16QAM, RFSI_256QAM}, }}, - .qam_th = {RFSI_QPSK, RFSI_16QAM, RFSI_256QAM}, }; static const @@ -474,7 +477,7 @@ static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_default = { }, [RFSI_CTRL_BAND_2GHZ] = { .qam_comp_th0 = {0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0}, - .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4500, 0, 0, + .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4600, 0, 0, 0, 0, 0, 0, 0)}, .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, @@ -492,7 +495,7 @@ static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_rfe38 = { .bands = { [RFSI_CTRL_BAND_5_6GHZ] = { .qam_comp_th0 = {0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0}, - .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4500, 0, + .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4600, 0, 0, 0, 0, 0, 0, 0)}, .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, @@ -502,7 +505,7 @@ static const struct rtw89_bb_wrap_data rtw8922d_bb_wrap_data_7090_rfe38 = { }, [RFSI_CTRL_BAND_2GHZ] = { .qam_comp_th0 = {0x4000, 0x4400, 0x4500, 0, 0, 0, 0, 0, 0, 0}, - .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, + .qam_comp_th1 = {_10qam_comp_code(0x4000, 0x4400, 0x4700, 0, 0, 0, 0, 0, 0, 0)}, .qam_comp_th2 = {_10qam_comp_code(0x4000, 0x4400, 0x4400, 0, 0, 0, 0, 0, 0, 0)}, From e908721fe32bb0a3b3f8651f1cfeeea3f3a41a48 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 2 Sep 2026 13:29:52 +0800 Subject: [PATCH 0282/2126] wifi: rtw89: 8922d: send RFE type to firmware To configure BT in firmware according to RFE type, send it via H2C command. Link: https://patch.msgid.link/20260902052958.50371-9-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/fw.c | 40 +++++++++++++++++++ drivers/net/wireless/realtek/rtw89/fw.h | 7 ++++ drivers/net/wireless/realtek/rtw89/rtw8922d.c | 2 + 3 files changed, 49 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index e409426c92e8..128017bac1d9 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -3570,6 +3570,46 @@ fail: return ret; } +int rtw89_fw_h2c_phy_rfe_type(struct rtw89_dev *rtwdev) +{ + const struct rtw89_chip_info *chip = rtwdev->chip; + struct rtw89_efuse *efuse = &rtwdev->efuse; + struct rtw89_h2c_phy_rfe_type *h2c; + u32 len = sizeof(*h2c); + struct sk_buff *skb; + int ret; + + if (chip->chip_id != RTL8922D) + return 0; + + skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); + if (!skb) { + rtw89_err(rtwdev, "failed to alloc skb for h2c phy_rfe_type\n"); + return -ENOMEM; + } + skb_put(skb, len); + h2c = (struct rtw89_h2c_phy_rfe_type *)skb->data; + + h2c->rfe_type = efuse->rfe_type; + + rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, + H2C_CAT_OUTSRC, H2C_CL_OUTSRC_DM, + H2C_FUNC_FW_RFE_TYPE, 0, 0, len); + + ret = rtw89_h2c_tx(rtwdev, skb, false); + if (ret) { + rtw89_err(rtwdev, "failed to send h2c\n"); + goto fail; + } + + return 0; +fail: + dev_kfree_skb_any(skb); + + return ret; +} +EXPORT_SYMBOL(rtw89_fw_h2c_phy_rfe_type); + #define H2C_P2P_ACT_LEN 20 int rtw89_fw_h2c_p2p_act(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_link, diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 375ca0a243a6..f7d017d3ced0 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -2101,6 +2101,11 @@ struct rtw89_h2c_lps_ml_cmn_info_v1 { struct rtw89_bb_link_info_rx_gain rx_gain[RTW89_BB_PS_LINK_BUF_MAX]; } __packed; +struct rtw89_h2c_phy_rfe_type { + u8 rfe_type; + u8 rsvd[3]; +} __packed; + struct rtw89_h2c_trig_cpu_except { __le32 w0; } __packed; @@ -4886,6 +4891,7 @@ enum rtw89_mrc_h2c_func { #define H2C_FUNC_FW_MCC_DIG 0x6 #define H2C_FUNC_FW_LPS_CH_INFO 0xb #define H2C_FUNC_FW_LPS_ML_CMN_INFO 0xe +#define H2C_FUNC_FW_RFE_TYPE 0x1b #define H2C_CL_OUTSRC_RF_REG_A 0x8 #define H2C_CL_OUTSRC_RF_REG_B 0x9 @@ -5568,6 +5574,7 @@ int rtw89_fw_h2c_lps_ml_cmn_info_v1(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif); int rtw89_fw_h2c_fwips(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_link, bool enable); +int rtw89_fw_h2c_phy_rfe_type(struct rtw89_dev *rtwdev); struct sk_buff *rtw89_fw_h2c_alloc_skb_with_hdr(struct rtw89_dev *rtwdev, u32 len); struct sk_buff *rtw89_fw_h2c_alloc_skb_no_hdr(struct rtw89_dev *rtwdev, u32 len); int rtw89_fw_msg_reg(struct rtw89_dev *rtwdev, diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 5f910163163f..4d003b303ae7 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -2504,6 +2504,8 @@ static void rtw8922d_bb_sethw(struct rtw89_dev *rtwdev) enum rtw89_phy_idx phy_idx; u32 reg; + rtw89_fw_h2c_phy_rfe_type(rtwdev); + reg = rtw89_mac_reg_by_idx(rtwdev, R_BE_PWR_BOOST, RTW89_PHY_0); rtw89_write32_clr(rtwdev, reg, B_BE_PWR_CTRL_SEL); reg = rtw89_mac_reg_by_idx(rtwdev, R_BE_PWR_BOOST, RTW89_PHY_1); From 942dce611ce022eef5842a43cb31cdb4b9a7afac Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 2 Sep 2026 13:29:53 +0800 Subject: [PATCH 0283/2126] wifi: rtw89: 8922d: bypass RX IQK when scan Similar to TX IQK, when connected to an AP and a scan is triggered, the FW may fail to receive frames because switching channels may load an uninitialized RX IQK table. Therefore, bypass RXIQK during scanning to avoid using invalid calibration values. Link: https://patch.msgid.link/20260902052958.50371-10-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/phy.c | 5 ++ drivers/net/wireless/realtek/rtw89/reg.h | 4 ++ drivers/net/wireless/realtek/rtw89/rtw8922d.c | 60 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index c78107e92206..3ecf94274c41 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -3574,6 +3574,8 @@ static void rtw89_phy_c2h_rfk_rpt_log(struct rtw89_dev *rtwdev, "[IQK] iqk->fwk_status = %x\n", iqk->fwk_status); for (i = 0; i < 2; i++) { + struct rtw89_iqk_info *iqk_info = &rtwdev->iqk; + rtw89_debug(rtwdev, RTW89_DBG_RFK, "[IQK] ======== Path %x ========\n", i); rtw89_debug(rtwdev, RTW89_DBG_RFK, "[IQK] iqk->iqk_band[%d] = %x\n", @@ -3592,6 +3594,9 @@ static void rtw89_phy_c2h_rfk_rpt_log(struct rtw89_dev *rtwdev, i, iqk->iqk_tx_fail[i]); rtw89_debug(rtwdev, RTW89_DBG_RFK, "[IQK] iqk->iqk_rx_fail[%d] = %x\n", i, iqk->iqk_rx_fail[i]); + + iqk_info->iqk_rx_fail[0][i] = iqk->iqk_rx_fail[i]; + for (j = 0; j < 6; j++) rtw89_debug(rtwdev, RTW89_DBG_RFK, "[IQK] iqk->rftxgain[%d][%d] = %x\n", diff --git a/drivers/net/wireless/realtek/rtw89/reg.h b/drivers/net/wireless/realtek/rtw89/reg.h index 7a3ca9c82548..4291e8115f10 100644 --- a/drivers/net/wireless/realtek/rtw89/reg.h +++ b/drivers/net/wireless/realtek/rtw89/reg.h @@ -11072,13 +11072,17 @@ #define B_KTBL0_RST BIT(31) #define R_CFIR_CTRL_A_BE4 0x38124 #define R_CFIR_CTRL_B_BE4 0x38224 +#define B_CFIR_CTRL_RXKIDX0_EN BIT(0) #define B_CFIR_CTRL_KIDX0_EN BIT(8) +#define B_CFIR_CTRL_RXKIDX1_EN BIT(16) #define B_CFIR_CTRL_KIDX1_EN BIT(24) #define R_TX_IQC_A_BE4 0x38138 #define R_TX_IQC_B_BE4 0x38238 #define B_TX_IQC_X GENMASK(31, 20) #define B_TX_IQC_Y GENMASK(19, 8) #define B_TX_IQC_DPK BIT(3) +#define R_RX_IQC_A_BE4 0x3813c +#define R_RX_IQC_B_BE4 0x3823c #define R_KTBL1A_BE4 0x38154 #define R_KTBL1B_BE4 0x38254 #define B_KTBL1_TBL0 BIT(3) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 4d003b303ae7..287a9476bb77 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -2864,6 +2864,64 @@ static void __rtw8922d_txiqk_enable(struct rtw89_dev *rtwdev) } } +static void __rtw8922d_rxiqk_disable(struct rtw89_dev *rtwdev) +{ + struct rtw89_rfk_mcc_info_data *rfk_mcc = rtwdev->rfk_mcc.data; + u8 path, kidx; + + for (path = RF_PATH_A; path <= RF_PATH_B; path++) { + kidx = rfk_mcc[path].table_idx; + + if (kidx == 0) { + rtw89_phy_write32_clr(rtwdev, R_CFIR_CTRL_A_BE4 + (path << 8), + B_CFIR_CTRL_RXKIDX0_EN); + } else if (kidx == 1) { + rtw89_phy_write32_clr(rtwdev, R_CFIR_CTRL_A_BE4 + (path << 8), + B_CFIR_CTRL_RXKIDX1_EN); + } else { + rtw89_phy_write32_mask(rtwdev, R_NCTL_CFG_BE4, + B_NCTL_CFG_BE4_SPAGE, 0x1); + rtw89_phy_write32_clr(rtwdev, R_CFIR_CTRL_A_BE4 + (path << 8), + B_CFIR_CTRL_RXKIDX0_EN); + rtw89_phy_write32_mask(rtwdev, R_NCTL_CFG_BE4, + B_NCTL_CFG_BE4_SPAGE, 0x0); + } + + rtw89_phy_write32(rtwdev, R_RX_IQC_A_BE4 + (path << 8), 0x40000002); + } +} + +static void __rtw8922d_rxiqk_enable(struct rtw89_dev *rtwdev) +{ + struct rtw89_rfk_mcc_info_data *rfk_mcc = rtwdev->rfk_mcc.data; + struct rtw89_iqk_info *iqk_info = &rtwdev->iqk; + u8 path, kidx; + + for (path = RF_PATH_A; path <= RF_PATH_B; path++) { + if (iqk_info->iqk_rx_fail[0][path]) + continue; + + kidx = rfk_mcc[path].table_idx; + + if (kidx == 0) { + rtw89_phy_write32_set(rtwdev, R_CFIR_CTRL_A_BE4 + (path << 8), + B_CFIR_CTRL_RXKIDX0_EN); + } else if (kidx == 1) { + rtw89_phy_write32_set(rtwdev, R_CFIR_CTRL_A_BE4 + (path << 8), + B_CFIR_CTRL_RXKIDX1_EN); + } else { + rtw89_phy_write32_mask(rtwdev, R_NCTL_CFG_BE4, + B_NCTL_CFG_BE4_SPAGE, 0x1); + rtw89_phy_write32_set(rtwdev, R_CFIR_CTRL_A_BE4 + (path << 8), + B_CFIR_CTRL_RXKIDX0_EN); + rtw89_phy_write32_mask(rtwdev, R_NCTL_CFG_BE4, + B_NCTL_CFG_BE4_SPAGE, 0x0); + } + + rtw89_phy_write32(rtwdev, R_RX_IQC_A_BE4 + (path << 8), 0x40000000); + } +} + static void rtw8922d_rfk_scan(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_link, bool start) @@ -2871,9 +2929,11 @@ static void rtw8922d_rfk_scan(struct rtw89_dev *rtwdev, if (start) { __rtw8922d_tssi_disable(rtwdev, rtwvif_link->phy_idx); __rtw8922d_txiqk_disable(rtwdev); + __rtw8922d_rxiqk_disable(rtwdev); } else { __rtw8922d_tssi_enable(rtwdev, rtwvif_link->phy_idx); __rtw8922d_txiqk_enable(rtwdev); + __rtw8922d_rxiqk_enable(rtwdev); } } From 571bae72c68ac060ba6d22245a17933f604d1833 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 2 Sep 2026 13:29:54 +0800 Subject: [PATCH 0284/2126] wifi: rtw89: 8922d: correct selection of CCK rate circuit The RTL8922D has single one shared CCK rate circuit. When operating on 0+2 mode, the selection should be on RTW89_PHY_1. For 1+1 operating mode, select RTW89_PHY_1 only if PHY0 isn't on 2GHz band but PHY1 does. Also, change the operating mode of debugging value from decimal to hexadecimal to be easier to read. Link: https://patch.msgid.link/20260902052958.50371-11-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/chan.c | 2 +- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/chan.c b/drivers/net/wireless/realtek/rtw89/chan.c index 6f11335b4968..99b52ca05fe2 100644 --- a/drivers/net/wireless/realtek/rtw89/chan.c +++ b/drivers/net/wireless/realtek/rtw89/chan.c @@ -527,7 +527,7 @@ static void rtw89_entity_recalc_mlo_dbcc_mode(struct rtw89_dev *rtwdev) mode = rtw89_entity_sel_mlo_dbcc_mode(rtwdev, active_hws); rtwdev->mlo_dbcc_mode = mode; - rtw89_debug(rtwdev, RTW89_DBG_STATE, "recalc mlo dbcc mode to %d\n", mode); + rtw89_debug(rtwdev, RTW89_DBG_STATE, "recalc mlo dbcc mode to 0x%x\n", mode); } static void rtw89_entity_recalc_mgnt_roles(struct rtw89_dev *rtwdev) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 287a9476bb77..75297b39c4d7 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -2471,14 +2471,15 @@ static int rtw8922d_ctrl_mlo(struct rtw89_dev *rtwdev, enum rtw89_mlo_dbcc_mode rtw89_write32_mask(rtwdev, reg1, B_BBWRAP_ELMSR_EN_BE4, 0); } else if (mode == MLO_0_PLUS_2_1RF) { rtw89_phy_write32_mask(rtwdev, R_SYS_DBCC_BE4, - B_SYS_DBCC_24G_BAND_SEL_BE4, RTW89_PHY_0); + B_SYS_DBCC_24G_BAND_SEL_BE4, RTW89_PHY_1); rtw89_write32_mask(rtwdev, reg0, B_BBWRAP_ELMSR_EN_BE4, 0); rtw89_write32_mask(rtwdev, reg1, B_BBWRAP_ELMSR_EN_BE4, 0); } else if ((mode == MLO_1_PLUS_1_1RF) || (mode == DBCC_LEGACY)) { struct rtw89_entity_conf conf; rtw89_entity_get_conf(rtwdev, &conf); - cck_phy_idx = conf.chans[1]->band_type == RTW89_BAND_2G ? + cck_phy_idx = conf.chans[0]->band_type != RTW89_BAND_2G && + conf.chans[1]->band_type == RTW89_BAND_2G ? RTW89_PHY_1 : RTW89_PHY_0; rtw89_phy_write32_mask(rtwdev, R_SYS_DBCC_BE4, From 3fa8db7c708e26924e523351a4c17cd6c15b8035 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 2 Sep 2026 13:29:55 +0800 Subject: [PATCH 0285/2126] wifi: rtw89: chan: introduce helper and refine active list iteration Add a helper macro to iterate active vifs. Some chanctx handling iterated all vifs and then checked if the link is active. In logical, it means only the active vifs need to be counted there. So, also refine them to iterate only active list. Signed-off-by: Zong-Zhe Yang Link: https://patch.msgid.link/20260902052958.50371-12-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/chan.c | 14 ++++++-------- drivers/net/wireless/realtek/rtw89/debug.c | 3 +-- drivers/net/wireless/realtek/rtw89/fw.c | 6 ++---- drivers/net/wireless/realtek/rtw89/util.h | 4 ++++ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/chan.c b/drivers/net/wireless/realtek/rtw89/chan.c index 99b52ca05fe2..7205fca8ac1a 100644 --- a/drivers/net/wireless/realtek/rtw89/chan.c +++ b/drivers/net/wireless/realtek/rtw89/chan.c @@ -185,7 +185,7 @@ static void rtw89_chan_update_punctured(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif; unsigned int link_id; - rtw89_for_each_rtwvif(rtwdev, rtwvif) { + rtw89_for_each_active_rtwvif(rtwdev, rtwvif) { rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id) { if (!rtwvif_link->chanctx_assigned || rtwvif_link->chanctx_idx != idx) @@ -358,10 +358,8 @@ static void rtw89_entity_calculate_weight(struct rtw89_dev *rtwdev, w->active_chanctxs++; } - rtw89_for_each_rtwvif(rtwdev, rtwvif) { - if (rtw89_vif_is_active_role(rtwvif)) - w->active_roles++; - } + rtw89_for_each_active_rtwvif(rtwdev, rtwvif) + w->active_roles++; } static void rtw89_normalize_link_chanctx(struct rtw89_dev *rtwdev, @@ -553,7 +551,7 @@ static void rtw89_entity_recalc_mgnt_roles(struct rtw89_dev *rtwdev) * which uses RTW89_CHANCTX_0 to put at position 0 and its designated * link take RTW89_CHANCTX_0. (normalizing) */ - list_for_each_entry(role, &mgnt->active_list, mgnt_entry) { + rtw89_for_each_active_rtwvif(rtwdev, role) { for (i = 0; i < role->links_inst_valid_num; i++) { link = rtw89_vif_get_link_inst(role, i); if (!link || !link->chanctx_assigned) @@ -570,7 +568,7 @@ static void rtw89_entity_recalc_mgnt_roles(struct rtw89_dev *rtwdev) } fill: - list_for_each_entry(role, &mgnt->active_list, mgnt_entry) { + rtw89_for_each_active_rtwvif(rtwdev, role) { if (unlikely(pos >= RTW89_MAX_INTERFACE_NUM)) { rtw89_warn(rtwdev, "%s: active roles are over max iface num\n", @@ -3335,7 +3333,7 @@ static void rtw89_swap_chanctx(struct rtw89_dev *rtwdev, swap(hal->chanctx[idx1], hal->chanctx[idx2]); - rtw89_for_each_rtwvif(rtwdev, rtwvif) + rtw89_for_each_active_rtwvif(rtwdev, rtwvif) __rtw89_swap_chanctx(rtwvif, idx1, idx2); cur = atomic_read(&hal->roc_chanctx_idx); diff --git a/drivers/net/wireless/realtek/rtw89/debug.c b/drivers/net/wireless/realtek/rtw89/debug.c index 7e640c7166e4..2417381bca1c 100644 --- a/drivers/net/wireless/realtek/rtw89/debug.c +++ b/drivers/net/wireless/realtek/rtw89/debug.c @@ -5463,12 +5463,11 @@ rtw89_debug_priv_diag_rf_get(struct rtw89_dev *rtwdev, static void rtw89_dbg_diag_rf_set_rfk(struct rtw89_dev *rtwdev) { - struct rtw89_entity_mgnt *mgnt = &rtwdev->hal.entity_mgnt; struct rtw89_vif_link *rtwvif_link; struct rtw89_vif *rtwvif; unsigned int link_id; - list_for_each_entry(rtwvif, &mgnt->active_list, mgnt_entry) + rtw89_for_each_active_rtwvif(rtwdev, rtwvif) rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id) rtw89_chip_rfk_channel(rtwdev, rtwvif_link); } diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 128017bac1d9..2f0cee0f4f6e 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -10346,7 +10346,6 @@ static void rtw89_hw_scan_update_link_beacon_noa(struct rtw89_dev *rtwdev, static void rtw89_hw_scan_update_beacon_noa(struct rtw89_dev *rtwdev, bool scan) { - const struct rtw89_entity_mgnt *mgnt = &rtwdev->hal.entity_mgnt; const struct rtw89_hw_scan_info *scan_info = &rtwdev->scan_info; const struct rtw89_chip_info *chip = rtwdev->chip; struct rtw89_mac_chinfo_ax *chinfo_ax; @@ -10386,7 +10385,7 @@ static void rtw89_hw_scan_update_beacon_noa(struct rtw89_dev *rtwdev, bool scan) } update: - list_for_each_entry(rtwvif, &mgnt->active_list, mgnt_entry) { + rtw89_for_each_active_rtwvif(rtwdev, rtwvif) { unsigned int link_id; vif = rtwvif_to_vif(rtwvif); @@ -10403,7 +10402,6 @@ static void rtw89_hw_scan_set_extra_op_info(struct rtw89_dev *rtwdev, struct rtw89_vif *scan_rtwvif, const struct rtw89_chan *scan_op) { - struct rtw89_entity_mgnt *mgnt = &rtwdev->hal.entity_mgnt; struct rtw89_hw_scan_info *scan_info = &rtwdev->scan_info; struct rtw89_hw_scan_extra_op *ext = &scan_info->extra_op; struct rtw89_vif *tmp; @@ -10412,7 +10410,7 @@ static void rtw89_hw_scan_set_extra_op_info(struct rtw89_dev *rtwdev, if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD_EXTRA_OP, &rtwdev->fw)) return; - list_for_each_entry(tmp, &mgnt->active_list, mgnt_entry) { + rtw89_for_each_active_rtwvif(rtwdev, tmp) { const struct rtw89_chan *tmp_chan; struct rtw89_vif_link *tmp_link; diff --git a/drivers/net/wireless/realtek/rtw89/util.h b/drivers/net/wireless/realtek/rtw89/util.h index c16e7a7f8bc9..aa87a520bdc3 100644 --- a/drivers/net/wireless/realtek/rtw89/util.h +++ b/drivers/net/wireless/realtek/rtw89/util.h @@ -21,6 +21,10 @@ #define rtw89_for_each_rtwvif(rtwdev, rtwvif) \ list_for_each_entry(rtwvif, &(rtwdev)->rtwvifs_list, list) +/* call this function with wiphy mutex is held */ +#define rtw89_for_each_active_rtwvif(rtwdev, rtwvif) \ + list_for_each_entry(rtwvif, &(rtwdev)->hal.entity_mgnt.active_list, mgnt_entry) + /* Before adding rtwvif to list, we need to check if it already exist, beacase * in some case such as SER L2 happen during WoWLAN flow, calling reconfig * twice cause the list to be added twice. From 76100369889872eac003e373008f82299adf9161 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 2 Sep 2026 13:29:56 +0800 Subject: [PATCH 0286/2126] wifi: rtw89: regd: check only active vifs when recalculating 6 GHz power type Originally, recalculating 6 GHz power type iterates all vifs including idle ones and takes an intersection. However, driver chanctx management will treat idle vifs as ones who also use the first chanctx which might be 6 GHz. Since idle vifs have no 6 GHz power type, default power type will be taken for them. Then, intersection result would be the default one. It means the strictest 6 GHz power type. So, fix it by iterating only active vifs. Signed-off-by: Zong-Zhe Yang Link: https://patch.msgid.link/20260902052958.50371-13-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/regd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/regd.c b/drivers/net/wireless/realtek/rtw89/regd.c index 14fab6b1a74a..942f55633942 100644 --- a/drivers/net/wireless/realtek/rtw89/regd.c +++ b/drivers/net/wireless/realtek/rtw89/regd.c @@ -1091,7 +1091,7 @@ static bool __rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev) int count = 0; u8 index; - rtw89_for_each_rtwvif(rtwdev, rtwvif) { + rtw89_for_each_active_rtwvif(rtwdev, rtwvif) { rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id) { chan = rtw89_chan_get(rtwdev, rtwvif_link->chanctx_idx); if (chan->band_type != RTW89_BAND_6G) From c43eedc4b6a867200593764593a9182d8988be6e Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 2 Sep 2026 13:29:57 +0800 Subject: [PATCH 0287/2126] wifi: rtw89: skip tracking things when entity is paused In some situation, such as HW scan/ROC, entity will temporarily be paused. They usually have special handling on chanctx. However, things in tracking work focus on the operating channel. It would be better not to count these temporary periods. So, add a check before doing tracking things. Also, LPS will be expected to be off before pausing entity and during the period when entity is paused. Besides, since the flow where to call rtw89_recalc_lps() is based on iface adding/removing, disabling has no need to depend on whether entity mode has became MCC. Before MCC starts, there must be at least two ifaces first. If two ifaces exist, rtw89_recalc_lps() will have already disabled LPS. Signed-off-by: Zong-Zhe Yang Link: https://patch.msgid.link/20260902052958.50371-14-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/chan.c | 12 ++++++++++++ drivers/net/wireless/realtek/rtw89/chan.h | 1 + drivers/net/wireless/realtek/rtw89/core.c | 6 ++++++ drivers/net/wireless/realtek/rtw89/ps.c | 6 ------ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/chan.c b/drivers/net/wireless/realtek/rtw89/chan.c index 7205fca8ac1a..a7ba47bd9abd 100644 --- a/drivers/net/wireless/realtek/rtw89/chan.c +++ b/drivers/net/wireless/realtek/rtw89/chan.c @@ -3230,6 +3230,9 @@ void rtw89_chanctx_pause(struct rtw89_dev *rtwdev, lockdep_assert_wiphy(rtwdev->hw->wiphy); + if (test_bit(RTW89_FLAG_LEISURE_PS, rtwdev->flags)) + rtw89_warn(rtwdev, "LPS isn't off when pausing chanctx\n"); + if (hal->entity_pause) return; @@ -3247,6 +3250,15 @@ void rtw89_chanctx_pause(struct rtw89_dev *rtwdev, hal->entity_pause = true; } +bool rtw89_chanctx_paused(struct rtw89_dev *rtwdev) +{ + struct rtw89_hal *hal = &rtwdev->hal; + + lockdep_assert_wiphy(rtwdev->hw->wiphy); + + return hal->entity_pause; +} + static void rtw89_chanctx_proceed_cb(struct rtw89_dev *rtwdev, const struct rtw89_chanctx_cb_parm *parm) { diff --git a/drivers/net/wireless/realtek/rtw89/chan.h b/drivers/net/wireless/realtek/rtw89/chan.h index a9a5f1b307a2..f99aca9ef6a4 100644 --- a/drivers/net/wireless/realtek/rtw89/chan.h +++ b/drivers/net/wireless/realtek/rtw89/chan.h @@ -185,6 +185,7 @@ void rtw89_query_mr_chanctx_info(struct rtw89_dev *rtwdev, u8 inst_idx, void rtw89_chanctx_track(struct rtw89_dev *rtwdev); void rtw89_chanctx_pause(struct rtw89_dev *rtwdev, const struct rtw89_chanctx_pause_parm *parm); +bool __must_check rtw89_chanctx_paused(struct rtw89_dev *rtwdev); void rtw89_chanctx_proceed(struct rtw89_dev *rtwdev, const struct rtw89_chanctx_cb_parm *cb_parm); diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 24275c2250e7..80c4877e2dab 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -5496,6 +5496,9 @@ static void rtw89_track_ps_work(struct wiphy *wiphy, struct wiphy_work *work) if (rtwdev->scanning) return; + if (rtw89_chanctx_paused(rtwdev)) + return; + if (rtwdev->lps_enabled && !rtwdev->btc.btc_ctrl_lps) rtw89_enter_lps_track(rtwdev, RTW89_TFC_INTERVAL_100MS); } @@ -5521,6 +5524,9 @@ static void rtw89_track_work(struct wiphy *wiphy, struct wiphy_work *work) if (rtwdev->scanning) return; + if (rtw89_chanctx_paused(rtwdev)) + return; + rtw89_leave_lps(rtwdev); if (tfc_changed) { diff --git a/drivers/net/wireless/realtek/rtw89/ps.c b/drivers/net/wireless/realtek/rtw89/ps.c index 31bb5dcd284a..34105d030537 100644 --- a/drivers/net/wireless/realtek/rtw89/ps.c +++ b/drivers/net/wireless/realtek/rtw89/ps.c @@ -363,13 +363,8 @@ void rtw89_recalc_lps(struct rtw89_dev *rtwdev) { struct ieee80211_vif *vif, *found_vif = NULL; struct rtw89_vif *rtwvif; - enum rtw89_entity_mode mode; int count = 0; - mode = rtw89_get_entity_mode(rtwdev); - if (mode == RTW89_ENTITY_MODE_MCC) - goto disable_lps; - rtw89_for_each_rtwvif(rtwdev, rtwvif) { vif = rtwvif_to_vif(rtwvif); @@ -387,7 +382,6 @@ void rtw89_recalc_lps(struct rtw89_dev *rtwdev) return; } -disable_lps: rtw89_leave_lps(rtwdev); rtwdev->lps_enabled = false; } From 69628cef92cfb7a6198e17183f261129fa64efa0 Mon Sep 17 00:00:00 2001 From: Po-Hao Huang Date: Wed, 2 Sep 2026 13:29:58 +0800 Subject: [PATCH 0288/2126] wifi: rtw89: add p2p device declaration Use separate interface for P2P operations. This is required for concurrent operations under MLO, so that address conversion can be applied to correct frames. The wpa_cli commands for P2P operations should be changed to under p2p-dev- after this commit. Signed-off-by: Po-Hao Huang Signed-off-by: Zong-Zhe Yang Link: https://patch.msgid.link/20260902052958.50371-15-pkshih@realtek.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/core.c | 16 +++++++++++++++- drivers/net/wireless/realtek/rtw89/core.h | 2 +- drivers/net/wireless/realtek/rtw89/ps.c | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 80c4877e2dab..572d9c65a2dd 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -176,6 +176,10 @@ static const struct ieee80211_iface_limit rtw89_iface_limits[] = { BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_AP), }, + { + .max = 1, + .types = BIT(NL80211_IFTYPE_P2P_DEVICE), + }, }; static const struct ieee80211_iface_limit rtw89_iface_limits_mcc[] = { @@ -188,6 +192,10 @@ static const struct ieee80211_iface_limit rtw89_iface_limits_mcc[] = { .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO), }, + { + .max = 1, + .types = BIT(NL80211_IFTYPE_P2P_DEVICE), + }, }; static const struct ieee80211_iface_combination rtw89_iface_combs[] = { @@ -5697,6 +5705,7 @@ void rtw89_vif_type_mapping(struct rtw89_vif_link *rtwvif_link, bool assoc) else rtwvif_link->wifi_role = RTW89_WIFI_ROLE_AP; break; + RTW89_TYPE_MAPPING(P2P_DEVICE); RTW89_TYPE_MAPPING(ADHOC); RTW89_TYPE_MAPPING(MONITOR); RTW89_TYPE_MAPPING(MESH_POINT); @@ -5730,6 +5739,10 @@ void rtw89_vif_type_mapping(struct rtw89_vif_link *rtwvif_link, bool assoc) rtwvif_link->self_role = RTW89_SELF_ROLE_CLIENT; rtwvif_link->addr_cam.sec_ent_mode = RTW89_ADDR_CAM_SEC_NORMAL; break; + case NL80211_IFTYPE_P2P_DEVICE: + rtwvif_link->net_type = RTW89_NET_TYPE_NO_LINK; + rtwvif_link->self_role = RTW89_SELF_ROLE_CLIENT; + break; case NL80211_IFTYPE_MONITOR: break; default: @@ -7523,7 +7536,8 @@ static int rtw89_core_register_hw(struct rtw89_dev *rtwdev) hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_P2P_CLIENT) | - BIT(NL80211_IFTYPE_P2P_GO); + BIT(NL80211_IFTYPE_P2P_GO) | + BIT(NL80211_IFTYPE_P2P_DEVICE); if (hal->ant_diversity) { hw->wiphy->available_antennas_tx = 0x3; diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index ad2c6401971b..98c1b900ab72 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6340,7 +6340,7 @@ enum rtw89_entity_mode { RTW89_ENTITY_MODE_UNHANDLED = -ESRCH, }; -#define RTW89_MAX_INTERFACE_NUM 2 +#define RTW89_MAX_INTERFACE_NUM 3 /* only valid when running with chanctx_ops */ struct rtw89_entity_mgnt { diff --git a/drivers/net/wireless/realtek/rtw89/ps.c b/drivers/net/wireless/realtek/rtw89/ps.c index 34105d030537..23a9c7a0704a 100644 --- a/drivers/net/wireless/realtek/rtw89/ps.c +++ b/drivers/net/wireless/realtek/rtw89/ps.c @@ -367,6 +367,8 @@ void rtw89_recalc_lps(struct rtw89_dev *rtwdev) rtw89_for_each_rtwvif(rtwdev, rtwvif) { vif = rtwvif_to_vif(rtwvif); + if (vif->type == NL80211_IFTYPE_P2P_DEVICE) + continue; if (vif->type != NL80211_IFTYPE_STATION) { count = 0; From f71dd599a98182d6bc34dce39977f928068ecd64 Mon Sep 17 00:00:00 2001 From: Maxim Skokov Date: Sat, 5 Sep 2026 01:25:33 +0300 Subject: [PATCH 0289/2126] wifi: rtw89: fix typos in comments, debug messages and struct field Correct several misspellings found by codespell: moniter -> monitor (struct rtw89_btc_wl_role_info_bpos field) serach -> search (comment) Unsupport -> Unsupported (error message) nofity -> notify (comment) updat -> update (debug message) lagacy -> legacy (comment) The renamed struct field has no users, so no further changes are needed. No functional changes. Assisted-by: Claude:claude-opus-5 codespell Signed-off-by: Maxim Skokov Acked-by: Ping-Ke Shih Link: https://patch.msgid.link/20260904222548.19732-1-skokovmaksimevg@gmail.com Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/core.h | 4 ++-- drivers/net/wireless/realtek/rtw89/fw.c | 4 ++-- drivers/net/wireless/realtek/rtw89/phy.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 98c1b900ab72..c300d15581fc 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -1904,7 +1904,7 @@ struct rtw89_btc_wl_role_info_bpos { u16 adhoc: 1; u16 adhoc_master: 1; u16 mesh: 1; - u16 moniter: 1; + u16 monitor: 1; u16 p2p_device: 1; u16 p2p_gc: 1; u16 p2p_go: 1; @@ -3925,7 +3925,7 @@ struct rtw89_btc_fddr_cell { struct rtw89_btc_fddr_result { u8 wl_rx_limit; u8 wl_rx_limit_step[6]; /* record search process */ - u8 search_cnt; /* the rx-limit serach count */ + u8 search_cnt; /* the rx-limit search count */ u32 wl_tp; u32 wl_tp_step[6]; /* record search process */ }; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 2f0cee0f4f6e..6760e0053665 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -322,7 +322,7 @@ static int __parse_formatted_mssc(struct rtw89_dev *rtwdev, if (mss_hdr->defen) rmp_tbl_size += FWDL_MSS_POOL_DEFKEYSETS_SIZE; } else { - rtw89_err(rtwdev, "[ERR] MSS Key Pool Remap Table Format Unsupport:%X\n", + rtw89_err(rtwdev, "[ERR] MSS Key Pool Remap Table Format Unsupported:%X\n", mss_hdr->rmpfmt); return -EINVAL; } @@ -11287,7 +11287,7 @@ int rtw89_fw_h2c_wow_request_aoac(struct rtw89_dev *rtwdev) skb_put(skb, len); - /* This H2C only nofity firmware to generate AOAC report C2H, + /* This H2C only notify firmware to generate AOAC report C2H, * no need any parameter. */ rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index 3ecf94274c41..501923d97971 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -525,7 +525,7 @@ void rtw89_phy_ra_update_sta_link(struct rtw89_dev *rtwdev, ra->upd_bw_nss_mask = 1; rtw89_debug(rtwdev, RTW89_DBG_RA, - "ra updat: macid = %d, bw = %d, nss = %d, gi = %d %d", + "ra update: macid = %d, bw = %d, nss = %d, gi = %d %d", ra->macid, ra->bw_cap, ra->ss_num, @@ -659,7 +659,7 @@ rs_11ax: 0, true)) goto out; - /* lagacy cannot be empty for nl80211_parse_tx_bitrate_mask, and + /* legacy cannot be empty for nl80211_parse_tx_bitrate_mask, and * require at least one basic rate for ieee80211_set_bitrate_mask, * so the decision just depends on if all bitrates are set or not. */ From 3ef961d01c2c082ec55c7c62a3eae3a8d5b97eb9 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Thu, 3 Sep 2026 14:46:38 +0700 Subject: [PATCH 0290/2126] net: marvell: mvmdio: Handle errors from optional IRQ lookup platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors should be propagated so that the caller can handle them appropriately. The existing code propagates -EPROBE_DEFER, but ignores other negative errors. Propagate negative errors other than -ENXIO. Found by manual code inspection. Signed-off-by: bui duc phuc Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260903074638.345952-1-phucduc.bui@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/mvmdio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 2ccb8c8f5feb..d59cf332d1ec 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -373,8 +373,8 @@ static int orion_mdio_probe(struct platform_device *pdev) writel(MVMDIO_ERR_INT_SMI_DONE, dev->regs + MVMDIO_ERR_INT_MASK); - } else if (dev->err_interrupt == -EPROBE_DEFER) { - ret = -EPROBE_DEFER; + } else if (dev->err_interrupt < 0 && dev->err_interrupt != -ENXIO) { + ret = dev->err_interrupt; goto out_mdio; } From 83e6bb28644ad6ca91feee6a0c93a2d0bf10c0e5 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 3 Sep 2026 11:00:39 +0200 Subject: [PATCH 0291/2126] net: macb: Make sure clk_init_data is fully initialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled. Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents. Signed-off-by: Geert Uytterhoeven Reviewed-by: Brian Masney Reviewed-by: Théo Lebrun Link: https://patch.msgid.link/62cfa62a8f39e0014d2fe9b30a668df20ace4a0c.1788425654.git.geert+renesas@glider.be Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index b1939da4c95a..a427a5b9d894 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5380,7 +5380,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk, struct clk **hclk, struct clk **tx_clk, struct clk **rx_clk, struct clk **tsu_clk) { - struct clk_init_data init; + struct clk_init_data init = {}; int err = 0; err = macb_clk_init_dflt(pdev, pclk, hclk, tx_clk, rx_clk, tsu_clk); From 4bee840c7e4309a77043de7c1064ce88be9813d8 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 3 Sep 2026 11:00:40 +0200 Subject: [PATCH 0292/2126] net: mdio: mux-meson-g12a: Make sure clk_init_data is fully initialized The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled. Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents. Signed-off-by: Geert Uytterhoeven Reviewed-by: Brian Masney Link: https://patch.msgid.link/98e2b71c333fea0ed59bf615c818cb7b56e2f2b5.1788425654.git.geert+renesas@glider.be Signed-off-by: Paolo Abeni --- drivers/net/mdio/mdio-mux-meson-g12a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-mux-meson-g12a.c b/drivers/net/mdio/mdio-mux-meson-g12a.c index 08d6a6c93fb8..e6c9ef3641af 100644 --- a/drivers/net/mdio/mdio-mux-meson-g12a.c +++ b/drivers/net/mdio/mdio-mux-meson-g12a.c @@ -223,7 +223,7 @@ static int g12a_ephy_glue_clk_register(struct device *dev) { struct g12a_mdio_mux *priv = dev_get_drvdata(dev); const char *parent_names[PLL_MUX_NUM_PARENT]; - struct clk_init_data init; + struct clk_init_data init = {}; struct g12a_ephy_pll *pll; struct clk_mux *mux; struct clk *clk; From 64adb67e4568261e1eddc1fd4df47ad4a98758b3 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 3 Sep 2026 11:00:41 +0200 Subject: [PATCH 0293/2126] net: phy: air_en8811h: Make sure clk_init_data is fully initialized The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled. Make sure all members are fully initialized, to avoid such bugs, and to prevent future breakage when converting drivers to a different method for specifying the parents. Signed-off-by: Geert Uytterhoeven Reviewed-by: Brian Masney Link: https://patch.msgid.link/0e869f49c910ce054aa22ae84480aab69420bb92.1788425654.git.geert+renesas@glider.be Signed-off-by: Paolo Abeni --- drivers/net/phy/air_en8811h.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index ec7c44ca68e7..16a9171cb838 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -938,7 +938,7 @@ static const struct clk_ops an8811hb_clk_ops = { static int an8811hb_clk_provider_setup(struct device *dev, struct clk_hw *hw) { - struct clk_init_data init; + struct clk_init_data init = {}; int ret; if (!IS_ENABLED(CONFIG_COMMON_CLK)) @@ -1037,7 +1037,7 @@ static const struct clk_ops en8811h_clk_ops = { static int en8811h_clk_provider_setup(struct device *dev, struct clk_hw *hw) { - struct clk_init_data init; + struct clk_init_data init = {}; int ret; if (!IS_ENABLED(CONFIG_COMMON_CLK)) From fc7aa4b30acf126bd4e8d0aeee21e6d772072b28 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:14:10 -0700 Subject: [PATCH 0294/2126] netlink: specs: fou: add af to the shared attribute list parse_nl_config() is the only place the address family is chosen: it defaults cfg->udp_config.family to AF_INET and only switches to AF_INET6 when FOU_ATTR_AF is present. The &all_attrs anchor - the add request, and the get do and dump reply - does not list af, so a ynl generated client has no fou_add_req_set_af() and can never create an IPv6 FOU port; the local-v6 / peer-v6 attributes it does list are read by nothing. On the reply side fou_fill_info() puts FOU_ATTR_AF unconditionally, and struct fou_get_rsp has no member for it. kernel-policy is global, so fou_nl_ops[] carries no per-op attribute list and af is already in fou_nl_policy through &select_attrs - only the user space codegen and the rendered docs change, ynl-regen.sh produces no diff. Signed-off-by: Jakub Kicinski Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20260904191412.3872344-2-kuba@kernel.org Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/fou.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/netlink/specs/fou.yaml b/Documentation/netlink/specs/fou.yaml index 331f1b342b3a..32d34be1dc63 100644 --- a/Documentation/netlink/specs/fou.yaml +++ b/Documentation/netlink/specs/fou.yaml @@ -90,6 +90,7 @@ operations: request: &all_attrs attributes: - port + - af - ipproto - type - remcsum-nopartial From 3f4285d741b4017a3f36cc4cfa272d0343b60a5d Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:14:11 -0700 Subject: [PATCH 0295/2126] netlink: specs: fou: local-v4 and peer-v4 are big endian fou_core.c uses nla_get_in_addr() / nla_put_in_addr() on both, i.e. they are __be32, and port / peer-port in the same spec are already annotated. Without byte-order YNL swaps them on little endian hosts. The generated policy goes from NLA_U32 to NLA_BE32, which changes nothing: lib/nlattr.c gives the two the same length in nla_attr_len[] and the same range handling, and neither attribute has a range check. Signed-off-by: Jakub Kicinski Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20260904191412.3872344-3-kuba@kernel.org Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/fou.yaml | 2 ++ net/ipv4/fou_nl.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/fou.yaml b/Documentation/netlink/specs/fou.yaml index 32d34be1dc63..1d0db6ba7e52 100644 --- a/Documentation/netlink/specs/fou.yaml +++ b/Documentation/netlink/specs/fou.yaml @@ -50,6 +50,7 @@ attribute-sets: - name: local-v4 type: u32 + byte-order: big-endian - name: local-v6 type: binary @@ -58,6 +59,7 @@ attribute-sets: - name: peer-v4 type: u32 + byte-order: big-endian - name: peer-v6 type: binary diff --git a/net/ipv4/fou_nl.c b/net/ipv4/fou_nl.c index 309d5ba983d0..cdb174b92cdd 100644 --- a/net/ipv4/fou_nl.c +++ b/net/ipv4/fou_nl.c @@ -18,9 +18,9 @@ const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = { [FOU_ATTR_IPPROTO] = NLA_POLICY_MIN(NLA_U8, 1), [FOU_ATTR_TYPE] = { .type = NLA_U8, }, [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, }, - [FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, }, + [FOU_ATTR_LOCAL_V4] = { .type = NLA_BE32, }, [FOU_ATTR_LOCAL_V6] = NLA_POLICY_EXACT_LEN(16), - [FOU_ATTR_PEER_V4] = { .type = NLA_U32, }, + [FOU_ATTR_PEER_V4] = { .type = NLA_BE32, }, [FOU_ATTR_PEER_V6] = NLA_POLICY_EXACT_LEN(16), [FOU_ATTR_PEER_PORT] = { .type = NLA_BE16, }, [FOU_ATTR_IFINDEX] = { .type = NLA_S32, }, From 1859a0cc3adbc4ed2cb2dfe1cdb3bbc96b5d2cab Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:14:12 -0700 Subject: [PATCH 0296/2126] netlink: specs: fou: link the type attribute to the encap-type enum The spec defines encap-type (unspec / direct / gue), but no attribute references it, so the definition exists only to emit FOU_ENCAP_* into the uAPI header - while FOU_ATTR_TYPE is exactly that value space: fou_create() switches on FOU_ENCAP_DIRECT / FOU_ENCAP_GUE and returns -EINVAL for anything else. Python YNL could not accept or display the names and the generated C exposed a raw __u8 setter. The global policy entry becomes NLA_POLICY_MAX(NLA_U8, 2). For add that only moves the existing fou_create() rejection earlier; del and get ignore FOU_ATTR_TYPE altogether, so a bogus type there now fails validation instead of being dropped on the floor. Signed-off-by: Jakub Kicinski Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20260904191412.3872344-4-kuba@kernel.org Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/fou.yaml | 1 + net/ipv4/fou_nl.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/fou.yaml b/Documentation/netlink/specs/fou.yaml index 1d0db6ba7e52..3e6a38e31202 100644 --- a/Documentation/netlink/specs/fou.yaml +++ b/Documentation/netlink/specs/fou.yaml @@ -44,6 +44,7 @@ attribute-sets: - name: type type: u8 + enum: encap-type - name: remcsum-nopartial type: flag diff --git a/net/ipv4/fou_nl.c b/net/ipv4/fou_nl.c index cdb174b92cdd..ccd134ba352d 100644 --- a/net/ipv4/fou_nl.c +++ b/net/ipv4/fou_nl.c @@ -16,7 +16,7 @@ const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = { [FOU_ATTR_PORT] = { .type = NLA_BE16, }, [FOU_ATTR_AF] = { .type = NLA_U8, }, [FOU_ATTR_IPPROTO] = NLA_POLICY_MIN(NLA_U8, 1), - [FOU_ATTR_TYPE] = { .type = NLA_U8, }, + [FOU_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U8, 2), [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, }, [FOU_ATTR_LOCAL_V4] = { .type = NLA_BE32, }, [FOU_ATTR_LOCAL_V6] = NLA_POLICY_EXACT_LEN(16), From 6a41ab891fe8202593e47d48a73957330b72ba58 Mon Sep 17 00:00:00 2001 From: Longjun Tang Date: Thu, 3 Sep 2026 10:28:48 +0800 Subject: [PATCH 0297/2126] virtio_net: add rx-alloc-fail counter Count the cases where the driver fails to allocate a buffer or an skb, such as when try_fill_recv() fails with ENOMEM, and report them via the rx-alloc-fail qstat. Plumb alloc-fail into virtnet_get_base_stats() to keep this new stat reported consistently at both queue and device scope, matching how packets, bytes, stop and wake are handled. This counter does not cover every allocation failure in all RX paths. It is intentionally limited to the common skb and RX buffer allocation paths to keep its meaning clear. $ ./tools/net/ynl/ynltool/ynltool qstats show --json scope queue [{"ifname":"ens3", "ifindex":2, "queue-type":"rx", "queue-id":0, "rx":{"packets":3722,"bytes":374806,"alloc-fail":0}}, {"ifname":"ens3", "ifindex":2, "queue-type":"tx", "queue-id":0, "tx":{"packets":622,"bytes":77495,"stop":0,"wake":0}}] Signed-off-by: Longjun Tang Link: https://patch.msgid.link/20260903022848.33595-1-lange_tang@163.com Signed-off-by: Paolo Abeni --- drivers/net/virtio_net.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index e34c52d059d3..360cc3435e90 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -125,6 +125,7 @@ struct virtnet_rq_stats { u64_stats_t packets; u64_stats_t bytes; u64_stats_t drops; + u64_stats_t alloc_fail; u64_stats_t xdp_packets; u64_stats_t xdp_tx; u64_stats_t xdp_redirects; @@ -173,8 +174,9 @@ static const struct virtnet_stat_desc virtnet_sq_stats_desc_qstat[] = { }; static const struct virtnet_stat_desc virtnet_rq_stats_desc_qstat[] = { - VIRTNET_RQ_STAT_QSTAT("packets", packets), - VIRTNET_RQ_STAT_QSTAT("bytes", bytes), + VIRTNET_RQ_STAT_QSTAT("packets", packets), + VIRTNET_RQ_STAT_QSTAT("bytes", bytes), + VIRTNET_RQ_STAT_QSTAT("alloc_fail", alloc_fail), }; #define VIRTNET_STATS_DESC_CQ(name) \ @@ -1917,8 +1919,10 @@ static struct sk_buff *receive_small_xdp(struct net_device *dev, } skb = virtnet_build_skb(buf, buflen, xdp.data - buf, len); - if (unlikely(!skb)) + if (unlikely(!skb)) { + u64_stats_inc(&stats->alloc_fail); goto err; + } if (metasize) skb_metadata_set(skb, metasize); @@ -1985,6 +1989,7 @@ static struct sk_buff *receive_small(struct net_device *dev, return skb; } + u64_stats_inc(&stats->alloc_fail); err: u64_stats_inc(&stats->drops); page_pool_put_page(rq->page_pool, page, -1, true); @@ -2016,8 +2021,10 @@ static struct sk_buff *receive_big(struct net_device *dev, skb = page_to_skb(vi, rq, page, 0, len, PAGE_SIZE, 0); u64_stats_add(&stats->bytes, len - vi->hdr_len); - if (unlikely(!skb)) + if (unlikely(!skb)) { + u64_stats_inc(&stats->alloc_fail); goto err; + } return skb; @@ -2298,8 +2305,10 @@ static struct sk_buff *receive_mergeable_xdp(struct net_device *dev, switch (act) { case XDP_PASS: head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz); - if (unlikely(!head_skb)) + if (unlikely(!head_skb)) { + u64_stats_inc(&stats->alloc_fail); break; + } skb_mark_for_recycle(head_skb); return head_skb; @@ -2414,8 +2423,10 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, head_skb = page_to_skb(vi, rq, page, offset, len, truesize, headroom); curr_skb = head_skb; - if (unlikely(!curr_skb)) + if (unlikely(!curr_skb)) { + u64_stats_inc(&stats->alloc_fail); goto err_skb; + } skb_mark_for_recycle(head_skb); while (--num_buf) { @@ -2444,8 +2455,10 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, truesize = mergeable_ctx_to_truesize(ctx); curr_skb = virtnet_skb_append_frag(rq, head_skb, curr_skb, page, buf, len, truesize); - if (!curr_skb) + if (!curr_skb) { + u64_stats_inc(&stats->alloc_fail); goto err_skb; + } } ewma_pkt_len_add(&rq->mrg_avg_pkt_len, head_skb->len); @@ -2928,12 +2941,14 @@ static int virtnet_receive(struct receive_queue *rq, int budget, u64_stats_set(&stats.packets, packets); if (rq->vq->num_free > min((unsigned int)budget, virtqueue_get_vring_size(rq->vq)) / 2) { - if (!try_fill_recv(vi, rq, GFP_ATOMIC)) + if (!try_fill_recv(vi, rq, GFP_ATOMIC)) { /* We need to retry refilling in the next NAPI poll so * we must return budget to make sure the NAPI is * repolled. */ packets = budget; + u64_stats_inc(&stats.alloc_fail); + } } u64_stats_update_begin(&rq->stats.syncp); @@ -2948,6 +2963,7 @@ static int virtnet_receive(struct receive_queue *rq, int budget, u64_stats_add(&rq->stats.packets, u64_stats_read(&stats.packets)); u64_stats_add(&rq->stats.bytes, u64_stats_read(&stats.bytes)); + u64_stats_add(&rq->stats.alloc_fail, u64_stats_read(&stats.alloc_fail)); u64_stats_update_end(&rq->stats.syncp); @@ -5666,6 +5682,7 @@ static void virtnet_get_base_stats(struct net_device *dev, */ rx->bytes = 0; rx->packets = 0; + rx->alloc_fail = 0; if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_RX_BASIC) { rx->hw_drops = 0; From 5f2530a4df8e0573e54cc0f4175c06ecb810a4dd Mon Sep 17 00:00:00 2001 From: Bert Karwatzki Date: Tue, 8 Sep 2026 11:43:40 +0200 Subject: [PATCH 0298/2126] mac80211: tx: Use info->flags in ieee80211_tx_h_select_key() Without this ieee80211_select_key_8023() is never called and wifi never connects. Fixes: 0e80db08668b ("wifi: mac80211: fix key selection for encap offload frames") Signed-off-by: Bert Karwatzki Link: https://patch.msgid.link/20260908094341.12196-1-spasswolf@web.de Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index c33092960df2..fd7981466137 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -633,7 +633,7 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; - if (info->control.flags & IEEE80211_TX_CTL_HW_80211_ENCAP) + if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) return ieee80211_select_key_8023(tx); if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) { From 1773727507edcf48f1a402dc35b77ae46a181df7 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 12:13:46 +0530 Subject: [PATCH 0299/2126] net: fix typos in comments Fix typos in comments, reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam Reviewed-by: Miquel Raynal Link: https://patch.msgid.link/20260907064346.3288-1-hemanth.selam@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ieee802154/at86rf230.c | 2 +- net/mac802154/iface.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 6156cf379916..f1adca942e3d 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -1370,7 +1370,7 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim) * but this is different on each board setup. You need to fine * tuning this value via CTRIM. * CTRIM = variable capacitor setting. Resolution is 0.3 pF range is - * 0 pF upto 4.5 pF. + * 0 pF up to 4.5 pF. * * Examples: * atben transceiver: diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c index b823720630e7..ff6e99257bc8 100644 --- a/net/mac802154/iface.c +++ b/net/mac802154/iface.c @@ -521,7 +521,7 @@ static void ieee802154_if_setup(struct net_device *dev) /* Let hard_header_len set to IEEE802154_MIN_HEADER_LEN. AF_PACKET * will not send frames without any payload, but ack frames - * has no payload, so substract one that we can send a 3 bytes + * has no payload, so subtract one that we can send a 3 bytes * frame. The xmit callback assumes at least a hard header where two * bytes fc and sequence field are set. */ From 4596be8a15db2e7f45cbb140f6644e2dd2b290db Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Mon, 7 Sep 2026 13:13:58 +0300 Subject: [PATCH 0300/2126] ipv6: udp: Use ip6_sk_redirect() for tunnel sockets After commit cd51b74bdd0b ("ipv6: Fix redirect exception creation for UDP/RAW sockets") the two redirect calls are now equivalent and there is no need to specifically call ip6_redirect() for tunnel sockets. Simplify and call ip6_sk_redirect() for both tunnel sockets and regular sockets. Note that for ICMPv6 Redirect Message packets the VRF driver does not reset skb->dev to the VRF device, so skb->dev->ifindex is equivalent to inet6_iif(skb), even when the packet was received from a VRF port. Suggested-by: Eric Dumazet Signed-off-by: Ido Schimmel Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260907101358.596953-1-idosch@nvidia.com Signed-off-by: Paolo Abeni --- net/ipv6/udp.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 93478d1ad576..59f9872c3552 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -751,13 +751,7 @@ static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, harderr = 1; } if (type == NDISC_REDIRECT) { - if (tunnel) { - ip6_redirect(skb, sock_net(sk), inet6_iif(skb), - READ_ONCE(sk->sk_mark), - sk_uid(sk)); - } else { - ip6_sk_redirect(skb, sk); - } + ip6_sk_redirect(skb, sk); goto out; } From 73db35350c5e1cadb47e9b65633539469e1c5c5a Mon Sep 17 00:00:00 2001 From: Alexandra Winter Date: Fri, 4 Sep 2026 11:44:46 +0200 Subject: [PATCH 0301/2126] dibs: Avoid inconsistent lockstate warning in dibs_lo_move_data() dibs->lock is acquired in process context and interrupt context (ism_handle_irq()). So always use spin_lock_irqsave() in process context. Note that this is not a real deadlock, as dibs_lo devices don't have any interrupt context. Example warning: [ 153.760872] ================================ [ 153.760878] WARNING: inconsistent lock state [ 153.760885] 7.2.0-15871-g544d85de4dc2 #16 Not tainted [ 153.760891] -------------------------------- [ 153.760896] inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage. [ 153.760901] python3/5134 [HC0[0]:SC0[2]:HE1:SE0] takes: [ 153.760909] 0001222c0fe72428 (&dibs->lock){?...}-{2:2}, at: dibs_lo_move_data+0x1ce/0x380 [ 153.760932] {IN-HARDIRQ-W} state was registered at: [ 153.760937] __lock_acquire+0x59c/0x15d0 [ 153.760947] lock_acquire.part.0+0x11c/0x290 [ 153.760953] lock_acquire+0xb4/0x1e0 [ 153.760959] _raw_spin_lock+0x58/0xb0 [ 153.760966] ism_handle_irq+0x80/0x3f0 [ism] [ 153.760974] __handle_irq_event_percpu+0x282/0x920 [ 153.760983] handle_irq_event_percpu+0x26/0xe0 [ 153.760989] handle_percpu_irq+0x10e/0x1a0 [ 153.760997] handle_irq_desc+0xa6/0x100 [ 153.761003] zpci_floating_irq_handler+0x3ca/0x610 [ 153.761011] do_airq_interrupt+0x206/0x500 [ 153.761018] __handle_irq_event_percpu+0x282/0x920 [ 153.761025] handle_irq_event_percpu+0x26/0xe0 [ 153.761031] handle_percpu_irq+0x10e/0x1a0 [ 153.761039] handle_irq_desc+0xa6/0x100 [ 153.761045] do_irq_async+0xec/0x150 [ 153.761052] do_io_irq+0x150/0x2e0 [ 153.761060] io_int_handler+0xec/0x118 [ 153.761066] arch_cpu_idle+0x120/0x130 [ 153.761118] arch_cpu_idle+0xbe/0x130 [ 153.761124] s390_enter_idle+0x20/0x30 [ 153.761131] cpuidle_enter_state+0xb6/0x440 [ 153.761138] cpuidle_enter+0x64/0xb0 [ 153.761144] cpuidle_idle_call+0x174/0x380 [ 153.761151] do_idle+0x16e/0x250 [ 153.761157] cpu_startup_entry+0x70/0x80 [ 153.761163] smp_start_secondary+0x36e/0x440 [ 153.761171] restart_int_handler+0x72/0x88 [ 153.761178] irq event stamp: 46536 [ 153.761182] hardirqs last enabled at (46536): [<000127b697450a90>] __local_bh_enable_ip+0x140/0x270 [ 153.761193] hardirqs last disabled at (46535): [<000127b697450b20>] __local_bh_enable_ip+0x1d0/0x270 [ 153.761202] softirqs last enabled at (46532): [<000127b6185f82c8>] smc_close_active+0x438/0xba0 [smc] [ 153.761232] softirqs last disabled at (46534): [<000127b6185ee998>] smc_cdc_get_slot_and_msg_send+0x218/0x370 [smc] [ 153.761257] other info that might help us debug this: [ 153.761262] Possible unsafe locking scenario: [ 153.761267] CPU0 [ 153.761271] ---- [ 153.761274] lock(&dibs->lock); [ 153.761282] [ 153.761286] lock(&dibs->lock); [ 153.761294] *** DEADLOCK *** [ 153.761299] locks held by python3/5134: 3, last CPU#1: [ 153.761305] #0: 0001222bab975f50 (&sb->s_type->i_mutex_key#11){+.+.}-{3:3}, at: __sock_release+0x7e/0x230 [ 153.761329] #1: 0001222ba5450378 (sk_lock-AF_SMC){+.+.}-{0:0}, at: smc_close_active+0x438/0xba0 [smc] [ 153.761360] #2: 0001222ba54508a0 (&smc->conn.send_lock){+...}-{2:2}, at: smc_cdc_get_slot_and_msg_send+0x218/0x370 [smc] [ 153.761394] stack backtrace: [ 153.761400] CPU: 1 UID: 0 PID: 5134 Comm: python3 Not tainted 7.2.0-15871-g544d85de4dc2 #16 PREEMPT [ 153.761406] Hardware name: IBM 3931 A01 703 (LPAR) [ 153.761408] Call Trace: [ 153.761409] [<000127b697366190>] dump_stack_lvl+0xe8/0x140 [ 153.761415] [<000127b6975ccc8c>] print_usage_bug.part.0+0x2ec/0x3a0 [ 153.761419] [<000127b6975cd454>] mark_lock_irq+0x714/0xa20 [ 153.761422] [<000127b6975cda52>] mark_lock+0x2f2/0x790 [ 153.761426] [<000127b6975ce2e6>] mark_usage+0x136/0x1c0 [ 153.761430] [<000127b6975ce90c>] __lock_acquire+0x59c/0x15d0 [ 153.761433] [<000127b6975cfa5c>] lock_acquire.part.0+0x11c/0x290 [ 153.761437] [<000127b6975cfc84>] lock_acquire+0xb4/0x1e0 [ 153.761441] [<000127b699d02a98>] _raw_spin_lock+0x58/0xb0 [ 153.761444] [<000127b6992ca4fe>] dibs_lo_move_data+0x1ce/0x380 [ 153.761449] [<000127b6185f0912>] smcd_tx_ism_write+0x182/0x250 [smc] [ 153.761469] [<000127b6185ee4c6>] smcd_cdc_msg_send+0x156/0x410 [smc] [ 153.761487] [<000127b6185ee9a2>] smc_cdc_get_slot_and_msg_send+0x222/0x370 [smc] [ 153.761507] [<000127b6185f8370>] smc_close_active+0x4e0/0xba0 [smc] [ 153.761526] [<000127b6185a293c>] __smc_release+0x4ac/0x6a0 [smc] [ 153.761546] [<000127b6185a2c6e>] smc_release+0x13e/0x480 [smc] [ 153.761565] [<000127b6994544d4>] __sock_release+0xa4/0x230 [ 153.761569] [<000127b69945468c>] sock_close+0x2c/0x40 [ 153.761573] [<000127b697e57180>] __fput+0x2f0/0x880 [ 153.761579] [<000127b697e58440>] fput_close_sync+0xd0/0x1c0 [ 153.761583] [<000127b697e4b3f0>] __s390x_sys_close+0x90/0xf0 [ 153.761586] [<000127b699cdc19e>] __do_syscall+0x1be/0x5a0 [ 153.761590] [<000127b699d04c7a>] system_call+0x72/0x90 [ 153.761594] INFO: lockdep is turned off. Signed-off-by: Alexandra Winter Reviewed-by: Dust Li Reviewed-by: Sidraya Jayagond Link: https://patch.msgid.link/20260904094446.1342654-1-wintera@linux.ibm.com Signed-off-by: Paolo Abeni --- drivers/dibs/dibs_loopback.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/dibs/dibs_loopback.c b/drivers/dibs/dibs_loopback.c index 649e4e375be3..44a2e74c2efc 100644 --- a/drivers/dibs/dibs_loopback.c +++ b/drivers/dibs/dibs_loopback.c @@ -238,6 +238,7 @@ static int dibs_lo_move_data(struct dibs_dev *dibs, u64 dmb_tok, { struct dibs_lo_dmb_node *rmb_node = NULL, *tmp_node; struct dibs_lo_dev *ldev; + unsigned long flags; u16 s_mask; u8 client_id; u32 sba_idx; @@ -267,12 +268,12 @@ static int dibs_lo_move_data(struct dibs_dev *dibs, u64 dmb_tok, if (!sf) return 0; - spin_lock(&dibs->lock); + spin_lock_irqsave(&dibs->lock, flags); client_id = dibs->dmb_clientid_arr[sba_idx]; s_mask = ror16(0x1000, idx); if (likely(client_id != NO_DIBS_CLIENT && dibs->subs[client_id])) dibs->subs[client_id]->ops->handle_irq(dibs, sba_idx, s_mask); - spin_unlock(&dibs->lock); + spin_unlock_irqrestore(&dibs->lock, flags); return 0; } From bf6f89ccd9748d895fa861da0edaccb9194e41be Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Thu, 3 Sep 2026 14:57:53 +0700 Subject: [PATCH 0302/2126] net: mvpp2: simplify IRQ validity check irq_of_parse_and_map() returns 0 when parsing or mapping an IRQ fails. The current condition also checks for negative values, even though irq_of_parse_and_map() does not return negative error codes. Check only for a zero return value to match the semantics of irq_of_parse_and_map(). Signed-off-by: bui duc phuc Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260903075753.346647-1-phucduc.bui@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index ccc24a1301f2..1c50174c9f1e 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -5874,7 +5874,7 @@ static int mvpp2_simple_queue_vectors_init(struct mvpp2_port *port, v->sw_thread_mask = *cpumask_bits(cpu_online_mask); v->port = port; v->irq = irq_of_parse_and_map(port_node, 0); - if (v->irq <= 0) + if (!v->irq) return -EINVAL; netif_napi_add(port->dev, &v->napi, mvpp2_poll); From fc73b71c1bdbf293d3fca7158424d6117466d4f8 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 3 Sep 2026 21:33:13 +0800 Subject: [PATCH 0303/2126] net: sysfs: factor out link settings read speed_show() and duplex_show() duplicate device validation, RTNL locking and the link settings query. Move this common work to sysfs_get_link_ksettings() so later locking changes stay in one place. RTNL is released before calling sysfs_emit(). The lock only protects the link settings query; formatting uses the local cmd copy, so the sysfs output and error handling remain unchanged. No functional changes. Assisted-by: LLM Signed-off-by: Wang Zhan Link: https://patch.msgid.link/20260903133314.3703381-2-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- net/core/net-sysfs.c | 97 ++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 352173df7578..7bb8bbc1f71e 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -118,6 +118,34 @@ unbreak: return ret; } +static int sysfs_get_link_ksettings(struct device *dev, + struct device_attribute *attr, + struct ethtool_link_ksettings *cmd) +{ + struct net_device *netdev = to_net_dev(dev); + int ret; + + /* + * The check is also done in __ethtool_get_link_ksettings; this helps + * returning early without hitting the locking section below. + */ + if (!netdev->ethtool_ops->get_link_ksettings) + return -EINVAL; + + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); + if (ret) + return ret; + + ret = -EINVAL; + if (netif_running(netdev)) { + if (!__ethtool_get_link_ksettings(netdev, cmd)) + ret = 0; + } + + rtnl_unlock(); + return ret; +} + /* use same locking rules as GIF* ioctl's */ static ssize_t netdev_show(const struct device *dev, struct device_attribute *attr, char *buf, @@ -332,70 +360,41 @@ static DEVICE_ATTR_RW(carrier); static ssize_t speed_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct net_device *netdev = to_net_dev(dev); - int ret = -EINVAL; + struct ethtool_link_ksettings cmd; + int ret; - /* The check is also done in __ethtool_get_link_ksettings; this helps - * returning early without hitting the locking section below. - */ - if (!netdev->ethtool_ops->get_link_ksettings) - return ret; - - ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); + ret = sysfs_get_link_ksettings(dev, attr, &cmd); if (ret) return ret; - ret = -EINVAL; - if (netif_running(netdev)) { - struct ethtool_link_ksettings cmd; - - if (!__ethtool_get_link_ksettings(netdev, &cmd)) - ret = sysfs_emit(buf, fmt_dec, cmd.base.speed); - } - rtnl_unlock(); - return ret; + return sysfs_emit(buf, fmt_dec, cmd.base.speed); } static DEVICE_ATTR_RO(speed); static ssize_t duplex_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct net_device *netdev = to_net_dev(dev); - int ret = -EINVAL; + struct ethtool_link_ksettings cmd; + const char *duplex; + int ret; - /* The check is also done in __ethtool_get_link_ksettings; this helps - * returning early without hitting the locking section below. - */ - if (!netdev->ethtool_ops->get_link_ksettings) - return ret; - - ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); + ret = sysfs_get_link_ksettings(dev, attr, &cmd); if (ret) return ret; - ret = -EINVAL; - if (netif_running(netdev)) { - struct ethtool_link_ksettings cmd; - - if (!__ethtool_get_link_ksettings(netdev, &cmd)) { - const char *duplex; - - switch (cmd.base.duplex) { - case DUPLEX_HALF: - duplex = "half"; - break; - case DUPLEX_FULL: - duplex = "full"; - break; - default: - duplex = "unknown"; - break; - } - ret = sysfs_emit(buf, "%s\n", duplex); - } + switch (cmd.base.duplex) { + case DUPLEX_HALF: + duplex = "half"; + break; + case DUPLEX_FULL: + duplex = "full"; + break; + default: + duplex = "unknown"; + break; } - rtnl_unlock(); - return ret; + + return sysfs_emit(buf, "%s\n", duplex); } static DEVICE_ATTR_RO(duplex); From 5d074ded6714fe44edd10b5f20cc43d74612579f Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 3 Sep 2026 21:33:14 +0800 Subject: [PATCH 0304/2126] net: sysfs: use ops lock for speed and duplex Reading /sys/class/net//{speed,duplex} takes rtnl_lock() even for ops-locked devices whose get_link_ksettings callback does not require it. This unnecessarily serializes monitoring reads with unrelated rtnetlink operations. On CPU-throttled hosts, a periodic reader such as node-exporter can hold RTNL for hundreds of milliseconds while an mlx5 callback runs, delaying unrelated rtnetlink operations. Use the netdev instance lock for these devices. Retain sysfs_rtnl_lock() for legacy devices and callbacks that request ETHTOOL_OP_NEEDS_RTNL_LINKSETTINGS. Preserve the existing speed and duplex sysfs ABI, including -EINVAL for devices that are down or callbacks that fail. Assisted-by: LLM Signed-off-by: Wang Zhan Link: https://patch.msgid.link/20260903133314.3703381-3-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- net/core/net-sysfs.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 7bb8bbc1f71e..fa790e442570 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -123,26 +123,41 @@ static int sysfs_get_link_ksettings(struct device *dev, struct ethtool_link_ksettings *cmd) { struct net_device *netdev = to_net_dev(dev); + bool need_rtnl; int ret; /* - * The check is also done in __ethtool_get_link_ksettings; this helps + * The check is also done in netif_get_link_ksettings; this helps * returning early without hitting the locking section below. */ if (!netdev->ethtool_ops->get_link_ksettings) return -EINVAL; - ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); - if (ret) - return ret; + need_rtnl = !netdev_need_ops_lock(netdev) || + (netdev->ethtool_ops->op_needs_rtnl & + ETHTOOL_OP_NEEDS_RTNL_LINKSETTINGS); + if (need_rtnl) { + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); + if (ret) + return ret; + } + netdev_lock_ops(netdev); + + if (!dev_isalive(netdev)) { + ret = -ENODEV; + goto unlock; + } ret = -EINVAL; if (netif_running(netdev)) { - if (!__ethtool_get_link_ksettings(netdev, cmd)) + if (!netif_get_link_ksettings(netdev, cmd)) ret = 0; } - rtnl_unlock(); +unlock: + netdev_unlock_ops(netdev); + if (need_rtnl) + rtnl_unlock(); return ret; } From 13e51269b6656768dc595ed6025e4974f2026543 Mon Sep 17 00:00:00 2001 From: Stanislaw Gruszka Date: Tue, 8 Sep 2026 14:46:51 +0200 Subject: [PATCH 0305/2126] wifi: mac80211: queue frames while off-channel Drivers without FAST_XMIT and hardware scan support currently drop TX frames during software scanning while being off-channel. This happens in ieee80211_tx_h_check_assoc() before frames reach internal TX queue. Move the off-channel check to invoke_tx_handlers_late(), after ieee80211_queue_skb(). Frames can then remain queued and be transmitted when the interface returns on-channel. This how TX works currently when code goes via ieee80211_xmit_fast() path. Below is rt2x00 driver ping output example while scanning, before and after the fix. After the fix, packets are no longer lost. Some have increased latency, what is expected behavior. BEFORE: 64 bytes from 192.168.0.1: icmp_seq=29 ttl=64 time=3.61 ms 64 bytes from 192.168.0.1: icmp_seq=31 ttl=64 time=3.33 ms # Missed 30 64 bytes from 192.168.0.1: icmp_seq=32 ttl=64 time=4.03 ms 64 bytes from 192.168.0.1: icmp_seq=34 ttl=64 time=3.10 ms # Missed 33 64 bytes from 192.168.0.1: icmp_seq=36 ttl=64 time=3.04 ms # Missed 35 64 bytes from 192.168.0.1: icmp_seq=38 ttl=64 time=3.05 ms # Missed 37 64 bytes from 192.168.0.1: icmp_seq=40 ttl=64 time=4.14 ms # Missed 39 64 bytes from 192.168.0.1: icmp_seq=41 ttl=64 time=4.50 ms AFTER: 64 bytes from 192.168.0.1: icmp_seq=29 ttl=64 time=3.40 ms 64 bytes from 192.168.0.1: icmp_seq=30 ttl=64 time=6.10 ms 64 bytes from 192.168.0.1: icmp_seq=31 ttl=64 time=4.69 ms 64 bytes from 192.168.0.1: icmp_seq=32 ttl=64 time=4.49 ms 64 bytes from 192.168.0.1: icmp_seq=33 ttl=64 time=148 ms 64 bytes from 192.168.0.1: icmp_seq=34 ttl=64 time=6.83 ms 64 bytes from 192.168.0.1: icmp_seq=35 ttl=64 time=8.66 ms 64 bytes from 192.168.0.1: icmp_seq=36 ttl=64 time=13.0 ms 64 bytes from 192.168.0.1: icmp_seq=37 ttl=64 time=4.78 ms 64 bytes from 192.168.0.1: icmp_seq=38 ttl=64 time=3.85 ms Cc: Signed-off-by: Stanislaw Gruszka Link: https://patch.msgid.link/20260908124651.2995-1-stf_xl@wp.pl Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 52 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index fd7981466137..d85c84a738f7 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -269,7 +269,6 @@ ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) static ieee80211_tx_result debug_noinline ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) { - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); bool assoc = false; @@ -277,20 +276,6 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) return TX_CONTINUE; - if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) && - test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) && - !ieee80211_is_probe_req(hdr->frame_control) && - !ieee80211_is_any_nullfunc(hdr->frame_control)) - /* - * When software scanning only nullfunc frames (to notify - * the sleep state to the AP) and probe requests (for the - * active scan) are allowed, all other frames should not be - * sent and we should not get here, but if we do - * nonetheless, drop them to avoid sending them - * off-channel. See __ieee80211_start_scan() for more. - */ - return TX_DROP; - if (tx->sdata->vif.type == NL80211_IFTYPE_OCB) return TX_CONTINUE; @@ -839,6 +824,33 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) return TX_CONTINUE; } +static ieee80211_tx_result debug_noinline +ieee80211_tx_h_check_offchannel(struct ieee80211_tx_data *tx) +{ + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); + + if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) + return TX_CONTINUE; + + if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) && + test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) && + !ieee80211_is_probe_req(hdr->frame_control) && + !ieee80211_is_any_nullfunc(hdr->frame_control)) { + /* + * When software scanning only nullfunc frames (to notify + * the sleep state to the AP) and probe requests (for the + * active scan) are allowed, all other frames should not be + * sent and we should not get here, but if we do + * nonetheless, drop them to avoid sending them + * off-channel. See __ieee80211_start_scan() for more. + */ + return TX_DROP; + } + + return TX_CONTINUE; +} + static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid) { u16 *seq = &sta->tid_seq[tid]; @@ -1905,6 +1917,7 @@ static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx) goto txh_done; } + CALL_TXH(ieee80211_tx_h_check_offchannel); CALL_TXH(ieee80211_tx_h_michael_mic_add); CALL_TXH(ieee80211_tx_h_sequence); CALL_TXH(ieee80211_tx_h_fragment); @@ -4720,10 +4733,6 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, queue = ieee80211_select_queue(sdata, sta, skb); skb_set_queue_mapping(skb, queue); - if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) && - test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) - goto out_free; - skb = skb_share_check(skb, GFP_ATOMIC); if (unlikely(!skb)) return; @@ -4785,11 +4794,6 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, ieee80211_tpt_led_trig_tx(local, len); ieee80211_tx_8023(sdata, skb, sta, false); - - return; - -out_free: - kfree_skb(skb); } static bool ieee80211_check_mcast_offload(struct ieee80211_sub_if_data *sdata, From e72d09173c1219272c70895eb5181f416f9113d7 Mon Sep 17 00:00:00 2001 From: Grzegorz Nitka Date: Mon, 3 Aug 2026 13:35:05 +0200 Subject: [PATCH 0306/2126] ice: monitor TSPLL lock from PTP periodic worker On E825 devices that own the source timer, the TSPLL can lose lock when the TCXO or TIME_REF signal is disrupted. Recovery requires re-enabling the TSPLL via CGU register writes; without it, the PHC keeps running on a degraded reference indefinitely. The DPLL periodic worker (ice_dpll_periodic_work()) would be a natural home for this monitoring, but placing it there has two problems: 1. ice_dpll_init_e825() sets ICE_FLAG_DPLL only after all initialization steps succeed. If any earlier step fails, the driver would run without any TSPLL recovery mechanism. 2. When CONFIG_DPLL=n, the DPLL worker is compiled out and TSPLL recovery would be silently absent. Add the monitor to ice_ptp_periodic_work() instead, which always runs on E825 owner PFs regardless of DPLL init state or config. Introduce two small helpers, ice_tspll_lost_lock_e825c() and ice_tspll_restart_e825c(), which encapsulate the CGU register reads/writes required to observe and recover the TSPLL. Cache the observed lock state in pf->ptp.tspll_locked using WRITE_ONCE()/READ_ONCE() so a follow-up change can consume it from the DPLL periodic worker (for user-space notification via dpll_device_change_ntf()) and drop the redundant poll+recovery from that path. Precise synchronization is not required: both workers converge on the same value within one poll period. Reviewed-by: Przemyslaw Korba Signed-off-by: Grzegorz Nitka Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_ptp.c | 70 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_ptp.h | 11 +++ drivers/net/ethernet/intel/ice/ice_tspll.c | 86 +++++++++++++++++++++- drivers/net/ethernet/intel/ice/ice_tspll.h | 4 + 4 files changed, 170 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index eaec36ab6ae3..4b1040d09f70 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -4,8 +4,11 @@ #include "ice.h" #include "ice_lib.h" #include "ice_trace.h" +#include "ice_tspll.h" #include "ice_txclk.h" +#define ICE_TSPLL_LOG_INTERVAL 120 + static const char ice_pin_names[][64] = { "SDP0", "SDP1", @@ -2849,6 +2852,67 @@ static void ice_ptp_maybe_trigger_tx_interrupt(struct ice_pf *pf) } } +/** + * ice_ptp_tspll_monitor - poll and recover TSPLL lock on E825 owner PFs + * @pf: Board private structure + * + * Called from the PTP periodic worker. On E825 devices that own the source + * timer, poll the TSPLL lock status via CGU registers and trigger a restart + * if the lock has been lost. The result is cached in @pf->ptp.tspll_locked + * so it can be consumed by the DPLL periodic worker via READ_ONCE(). + * + * TSPLL lock is critical for PHC operation and must be monitored regardless + * of whether DPLL init succeeded or CONFIG_DPLL is enabled. Placing the + * monitor here makes recovery independent of the dpll subsystem. + * + * AQ read errors are rate-limited and do not stop monitoring. Lock-lost + * events are logged every 120 retries (~60 s at normal poll rate) to + * surface persistent failures without flooding the log. + */ +static void ice_ptp_tspll_monitor(struct ice_pf *pf) +{ + bool lock_lost; + int err; + + if (pf->hw.mac_type != ICE_MAC_GENERIC_3K_E825 || + !ice_pf_src_tmr_owned(pf)) + return; + + err = ice_tspll_lost_lock_e825c(&pf->hw, &lock_lost); + if (err) { + dev_err_ratelimited(ice_pf_to_dev(pf), + "Failed reading TimeSync PLL lock status (err: %d). Retrying.\n", + err); + return; + } + + if (lock_lost) { + WRITE_ONCE(pf->ptp.tspll_locked, false); + if (!(pf->ptp.tspll_lock_retries % ICE_TSPLL_LOG_INTERVAL)) + dev_warn(ice_pf_to_dev(pf), + "TimeSync PLL lock lost. Retrying to acquire lock.\n"); + err = ice_tspll_restart_e825c(&pf->hw); + if (err) + dev_err_ratelimited(ice_pf_to_dev(pf), + "Failed to restart TimeSync PLL (err: %d).\n", + err); + pf->ptp.tspll_lock_retries++; + } else { + if (pf->ptp.tspll_lock_retries) { + const char *src_str = "unknown"; + enum ice_clk_src clk_src; + + if (!ice_tspll_get_clk_src(&pf->hw, &clk_src)) + src_str = ice_tspll_clk_src_str(clk_src); + dev_info(ice_pf_to_dev(pf), + "TimeSync PLL lock acquired with %s clock source after %u retries.\n", + src_str, pf->ptp.tspll_lock_retries); + } + WRITE_ONCE(pf->ptp.tspll_locked, true); + pf->ptp.tspll_lock_retries = 0; + } +} + static void ice_ptp_periodic_work(struct kthread_work *work) { struct ice_ptp *ptp = container_of(work, struct ice_ptp, work.work); @@ -2858,6 +2922,8 @@ static void ice_ptp_periodic_work(struct kthread_work *work) if (pf->ptp.state != ICE_PTP_READY) return; + ice_ptp_tspll_monitor(pf); + err = ice_ptp_update_cached_phctime(pf); ice_ptp_maybe_trigger_tx_interrupt(pf); @@ -2975,6 +3041,9 @@ static int ice_ptp_rebuild_owner(struct ice_pf *pf) err = ice_tspll_init(hw); if (err) return err; + /* Rebuild reinitialized TSPLL, so reset monitor retry state. */ + WRITE_ONCE(ptp->tspll_locked, true); + ptp->tspll_lock_retries = 0; /* Acquire the global hardware lock */ if (!ice_ptp_lock(hw)) { @@ -3319,6 +3388,7 @@ void ice_ptp_init(struct ice_pf *pf) } ptp->port.port_num = hw->lane_num; + ptp->tspll_locked = true; ice_ptp_init_hw(hw); ice_ptp_init_tx_interrupt_mode(pf); diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.h b/drivers/net/ethernet/intel/ice/ice_ptp.h index c4b0da7ce20e..0e40fef3b4e8 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.h +++ b/drivers/net/ethernet/intel/ice/ice_ptp.h @@ -249,6 +249,15 @@ struct ice_ptp_pin_desc { * @tx_hwtstamp_discarded: number of Tx skbs discarded due to cached PHC time * being too old to correctly extend timestamp * @late_cached_phc_updates: number of times cached PHC update is late + * @tspll_locked: last observed TSPLL lock state on E825 owner PFs. + * Written by the PTP periodic worker after polling the TSPLL and + * intended to be read (without pf->dplls.lock) by the DPLL periodic + * worker in a follow-up change. Access via READ_ONCE()/WRITE_ONCE(); + * precise synchronization is not required because both workers + * converge on the same value within one poll period. + * @tspll_lock_retries: counts consecutive poll cycles in which the TSPLL + * was found unlocked. Reset to zero when lock is re-acquired. Used to + * rate-limit the lock-lost log message (~every 120 retries / ~60 s). */ struct ice_ptp { enum ice_ptp_state state; @@ -274,6 +283,8 @@ struct ice_ptp { u32 tx_hwtstamp_flushed; u32 tx_hwtstamp_discarded; u32 late_cached_phc_updates; + bool tspll_locked; + u32 tspll_lock_retries; }; #define __ptp_port_to_ptp(p) \ diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.c b/drivers/net/ethernet/intel/ice/ice_tspll.c index fd4b58eb9bc0..78752dc1e762 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.c +++ b/drivers/net/ethernet/intel/ice/ice_tspll.c @@ -129,7 +129,7 @@ static bool ice_tspll_check_params(struct ice_hw *hw, * * Return: specified clock source converted to its string name */ -static const char *ice_tspll_clk_src_str(enum ice_clk_src clk_src) +const char *ice_tspll_clk_src_str(enum ice_clk_src clk_src) { switch (clk_src) { case ICE_CLK_SRC_TCXO: @@ -531,6 +531,62 @@ int ice_tspll_cfg_pps_out_e825c(struct ice_hw *hw, bool enable) return ice_write_cgu_reg(hw, ICE_CGU_R9, val); } +/** + * ice_tspll_lost_lock_e825c - check if TSPLL lost lock + * @hw: Pointer to the HW struct + * @lost_lock: Output flag for reporting lost lock + * + * Get E825 device TSPLL DPLL lock status. + * + * Return: + * * 0 - OK + * * negative - error + */ +int ice_tspll_lost_lock_e825c(struct ice_hw *hw, bool *lost_lock) +{ + u32 val; + int err; + + err = ice_read_cgu_reg(hw, ICE_CGU_RO_LOCK, &val); + if (err) + return err; + + *lost_lock = !FIELD_GET(ICE_CGU_RO_LOCK_TRUE_LOCK, val); + + return 0; +} + +/** + * ice_tspll_restart_e825c - trigger TSPLL restart + * @hw: Pointer to the HW struct + * + * Re-enable TSPLL for E825 device. + * + * Return: + * * 0 - OK + * * negative - error + */ +int ice_tspll_restart_e825c(struct ice_hw *hw) +{ + u32 val; + int err; + + /* Read the initial values of r23 and disable the PLL */ + err = ice_read_cgu_reg(hw, ICE_CGU_R23, &val); + if (err) + return err; + + val &= ~ICE_CGU_R23_R24_TSPLL_ENABLE; + err = ice_write_cgu_reg(hw, ICE_CGU_R23, val); + if (err) + return err; + + /* Wait at least 1 ms before reenabling PLL */ + usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC); + val |= ICE_CGU_R23_R24_TSPLL_ENABLE; + return ice_write_cgu_reg(hw, ICE_CGU_R23, val); +} + /** * ice_tspll_cfg - Configure the Clock Generation Unit TSPLL * @hw: Pointer to the HW struct @@ -577,6 +633,34 @@ static int ice_tspll_dis_sticky_bits(struct ice_hw *hw) } } +/** + * ice_tspll_get_clk_src - get current TSPLL clock source + * @hw: board private hw structure + * @clk_src: pointer to store clk_src value + * + * Get current TSPLL clock source settings. + * + * Return: + * * 0 - OK + * * negative - error + */ +int ice_tspll_get_clk_src(struct ice_hw *hw, enum ice_clk_src *clk_src) +{ + u32 val; + int err; + + err = (hw->mac_type == ICE_MAC_GENERIC_3K_E825) ? + ice_read_cgu_reg(hw, ICE_CGU_R23, &val) : + ice_read_cgu_reg(hw, ICE_CGU_R24, &val); + if (err) + return err; + + *clk_src = (enum ice_clk_src)FIELD_GET(ICE_CGU_R23_R24_TIME_REF_SEL, + val); + + return 0; +} + /** * ice_tspll_init - Initialize TSPLL with settings from firmware * @hw: Pointer to the HW structure diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.h b/drivers/net/ethernet/intel/ice/ice_tspll.h index d650867004d1..05917ae51ded 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.h +++ b/drivers/net/ethernet/intel/ice/ice_tspll.h @@ -32,6 +32,9 @@ struct ice_tspll_params_e82x { #define ICE_TSPLL_FBDIV_INTGR_E825 256 int ice_tspll_cfg_pps_out_e825c(struct ice_hw *hw, bool enable); +int ice_tspll_lost_lock_e825c(struct ice_hw *hw, bool *lost_lock); +int ice_tspll_restart_e825c(struct ice_hw *hw); +int ice_tspll_get_clk_src(struct ice_hw *hw, enum ice_clk_src *clk_src); int ice_tspll_init(struct ice_hw *hw); int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active, enum ice_synce_clk output); @@ -39,4 +42,5 @@ int ice_tspll_cfg_bypass_mux_e825c(struct ice_hw *hw, bool ena, u32 port_num, enum ice_synce_clk output); int ice_tspll_cfg_synce_ethdiv_e825c(struct ice_hw *hw, enum ice_synce_clk output); +const char *ice_tspll_clk_src_str(enum ice_clk_src clk_src); #endif /* _ICE_TSPLL_H_ */ From 41dfc378867f012b3c6c9feb72da0a15a675685d Mon Sep 17 00:00:00 2001 From: Grzegorz Nitka Date: Mon, 3 Aug 2026 13:35:06 +0200 Subject: [PATCH 0307/2126] ice: add TSPLL DPLL device and TIME_REF pin for E825 This extends the E825 advanced sync-timing support introduced by the tx-clk series, which added the TXC DPLL device for TX reference clock control. The TSPLL, the source timer PLL, is now also exposed through the dpll subsystem so that its lock status and clock source selection are visible and controllable from userspace. On E825 devices the TSPLL is the source timer PLL, distinct from the EEC and PPS DPLLs used on E810. Register it as a DPLL_TYPE_GENERIC device for owner PFs. Add struct ice_dplls::tspll_in, a fwnode-backed input pin named "time_ref". The state_on_dpll_get callback queries ICE_CGU_R23 via ice_tspll_get_clk_src() and returns CONNECTED when TIME_REF is selected as clock source, DISCONNECTED otherwise. The state_on_dpll_set callback switches the source between TIME_REF and TCXO via the new ice_tspll_set_cfg() helper. Registration is deferred via the dpll notifier path if the pin is not yet visible in the subsystem at probe time. Initialize TSPLL DPLL state from direct clock-source/lock reads so the first published state reflects hardware and prev_dpll_state matches. During periodic polling, the DPLL worker consumes READ_ONCE(pf->ptp.tspll_locked), maintained and recovered by the PTP periodic worker. When the TSPLL clock source is TCXO (TIME_REF pin not selected), UNLOCKED is reported unconditionally to reflect the free-running state of the oscillator regardless of the raw lock bit. To avoid stale lock-status reads after synchronous source changes, the set callback now refreshes tspll.dpll_state immediately and emits a DPLL change notification when the cached state changed. If a TSPLL reconfiguration is applied but the PLL has not yet re-acquired lock, treat the internal -EAGAIN result as success so the PTP periodic worker can complete recovery, while real -EBUSY failures from reset/SBQ paths still propagate to userspace. The TSPLL userspace reconfiguration path (state_on_dpll_set) and the PTP periodic worker (ice_ptp_tspll_monitor) both read TSPLL HW state and write the pf->ptp.tspll_locked cache consumed by the DPLL worker. Serialize both with pf->dplls.lock across their HW-read -> cache-write sequence; otherwise a preempted monitor could overwrite an accurate cache update from the DPLL callback with stale HW state. The mutex lifetime is lifted to PF-features scope (initialized in ice_init_features() before ice_ptp_init(), destroyed in ice_deinit_features() after ice_ptp_release()) so the PTP monitor can take it unconditionally regardless of DPLL init state. Extend ice_dpll_deinit_txclk_pins() with a "flush" parameter so the E825 init error path for the TSPLL fwnode pin can tear down TXCLK pins without flushing pf->dplls.wq. If the flush ran here, notifier work items queued during earlier init steps would be blocked on pf->dplls.dpll_init, which is only completed at the unregister_pins label reached after this teardown. destroy_workqueue() at that label drains the queued items safely. Existing full-teardown callers pass flush=true and keep current behavior. Reviewed-by: Przemyslaw Korba Signed-off-by: Grzegorz Nitka Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_dpll.c | 413 ++++++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 4 + drivers/net/ethernet/intel/ice/ice_main.c | 9 + drivers/net/ethernet/intel/ice/ice_ptp.c | 12 + drivers/net/ethernet/intel/ice/ice_tspll.c | 34 +- drivers/net/ethernet/intel/ice/ice_tspll.h | 2 + 6 files changed, 424 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index 85a74cd6ea1f..00e3f7de7810 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -22,6 +22,8 @@ #define E825_RCLK_PARENT_0_PIN_IDX 0 #define E825_RCLK_PARENT_1_PIN_IDX 1 +#define E825_DPLL_TSPLL_BASE_IDX 0 +#define E825_DPLL_TXCLK_BASE_IDX 1 #define ICE_DPLL_PIN_SW_INPUT_ABS(in_idx) \ (ICE_DPLL_SW_PIN_INPUT_BASE_SFP + (in_idx)) @@ -84,6 +86,7 @@ static const char * const ice_dpll_sw_pin_sma[] = { "SMA1", "SMA2" }; static const char * const ice_dpll_sw_pin_ufl[] = { "U.FL1", "U.FL2" }; static const char * const ice_dpll_ext_eref_pin = "EXT_EREF0"; static const char * const ice_dpll_fwnode_ext_synce = "clk_ref_synce"; +static const char * const ice_dpll_fwnode_time_ref = "time_ref"; static const struct dpll_pin_frequency ice_esync_range[] = { DPLL_PIN_FREQUENCY_RANGE(0, DPLL_PIN_FREQUENCY_1_HZ), @@ -2814,6 +2817,160 @@ static const struct dpll_pin_ops ice_dpll_txclk_ops = { .direction_get = ice_dpll_input_direction, }; +/** + * ice_dpll_tspll_lock_status_get - derive TSPLL state for dpll subsystem + * @pf: board private structure + * @use_cached: if true, read lock state from pf->ptp.tspll_locked (maintained + * by the PTP periodic worker); if false, query hardware directly + * + * If TIME_REF is not selected, TSPLL is treated as unlocked from the dpll + * subsystem perspective, regardless of raw lock bit. + * + * Return: TSPLL lock status + */ +static enum dpll_lock_status +ice_dpll_tspll_lock_status_get(struct ice_pf *pf, bool use_cached) +{ + enum ice_clk_src clk_src; + bool locked; + + if (ice_tspll_get_clk_src(&pf->hw, &clk_src) || + clk_src != ICE_CLK_SRC_TIME_REF) + return DPLL_LOCK_STATUS_UNLOCKED; + + if (use_cached) { + locked = READ_ONCE(pf->ptp.tspll_locked); + } else { + bool lock_lost; + + if (ice_tspll_lost_lock_e825c(&pf->hw, &lock_lost)) + return DPLL_LOCK_STATUS_UNLOCKED; + locked = !lock_lost; + } + return locked ? DPLL_LOCK_STATUS_LOCKED : DPLL_LOCK_STATUS_UNLOCKED; +} + +/** + * ice_dpll_tspll_state_on_dpll_get - get TIME_REF pin state on TSPLL DPLL + * @pin: pointer to a pin + * @pin_priv: private data pointer passed on pin registration + * @dpll: registered dpll pointer + * @dpll_priv: private data pointer passed on dpll registration + * @state: on success holds pin state on parent dpll + * @extack: error reporting + * + * Dpll subsystem callback. Returns CONNECTED if the TSPLL is using + * TIME_REF as its clock source, DISCONNECTED otherwise. + * + * Return: + * * 0 - success + * * negative - failed to read clock source + */ +static int +ice_dpll_tspll_state_on_dpll_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, + void *dpll_priv, + enum dpll_pin_state *state, + struct netlink_ext_ack *extack) +{ + struct ice_dpll_pin *p = pin_priv; + enum ice_clk_src clk_src; + int err; + + if (ice_dpll_is_reset(p->pf, extack)) + return -EBUSY; + + err = ice_tspll_get_clk_src(&p->pf->hw, &clk_src); + if (err) + return err; + + *state = clk_src == ICE_CLK_SRC_TIME_REF ? DPLL_PIN_STATE_CONNECTED : + DPLL_PIN_STATE_DISCONNECTED; + return 0; +} + +/** + * ice_dpll_tspll_state_on_dpll_set - set TIME_REF pin state on TSPLL DPLL + * @pin: pointer to a pin + * @pin_priv: private data pointer passed on pin registration + * @dpll: registered dpll pointer + * @dpll_priv: private data pointer passed on dpll registration + * @state: requested state of the pin + * @extack: error reporting + * + * Dpll subsystem callback. Enables (CONNECTED) or disables (DISCONNECTED) + * the TIME_REF signal as the TSPLL clock source. Selects TCXO when disabled. + * + * Return: + * * 0 - success + * * negative - error + */ +static int +ice_dpll_tspll_state_on_dpll_set(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, + void *dpll_priv, enum dpll_pin_state state, + struct netlink_ext_ack *extack) +{ + struct ice_dpll_pin *p = pin_priv; + struct ice_pf *pf = p->pf; + enum ice_clk_src clk_src; + bool changed = false; + struct ice_dpll *tp; + int ret; + + if (ice_dpll_is_reset(pf, extack)) + return -EBUSY; + + if (state != DPLL_PIN_STATE_CONNECTED && + state != DPLL_PIN_STATE_DISCONNECTED) { + NL_SET_ERR_MSG(extack, + "unsupported pin state for TSPLL reference clock"); + return -EINVAL; + } + + clk_src = (state == DPLL_PIN_STATE_CONNECTED) ? ICE_CLK_SRC_TIME_REF : + ICE_CLK_SRC_TCXO; + tp = &pf->dplls.tspll; + /* Serialize multi-register TSPLL reconfiguration with restart path. */ + mutex_lock(&pf->dplls.lock); + ret = ice_tspll_set_cfg(&pf->hw, ICE_TSPLL_FREQ_156_250, clk_src); + if (!ret || ret == -EAGAIN) { + enum dpll_lock_status new_state; + + new_state = ice_dpll_tspll_lock_status_get(pf, false); + + /* Sync the cached lock state to what we just observed from HW + * so ice_dpll_periodic_work_e825() (cached path) does not emit + * a spurious UNLOCKED notification between now and the next + * PTP monitor tick. + */ + WRITE_ONCE(pf->ptp.tspll_locked, + new_state == DPLL_LOCK_STATUS_LOCKED); + + if (tp->prev_dpll_state != new_state) { + tp->dpll_state = new_state; + tp->prev_dpll_state = new_state; + changed = true; + } + } + mutex_unlock(&pf->dplls.lock); + if (changed) + __dpll_device_change_ntf(tp->dpll); + /* TSPLL reconfiguration may complete before lock is reacquired. + * PTP periodic monitoring tracks and restores the final lock state. + */ + if (ret == -EAGAIN) + ret = 0; + + return ret; +} + +static const struct dpll_pin_ops ice_dpll_tspll_in_ops = { + .state_on_dpll_set = ice_dpll_tspll_state_on_dpll_set, + .state_on_dpll_get = ice_dpll_tspll_state_on_dpll_get, + .direction_get = ice_dpll_input_direction, +}; + static const struct dpll_pin_ops ice_dpll_pin_sma_ops = { .state_on_dpll_set = ice_dpll_sma_pin_state_set, .state_on_dpll_get = ice_dpll_sw_pin_state_get, @@ -3134,12 +3291,44 @@ ice_dpll_update_state(struct ice_pf *pf, struct ice_dpll *d, bool init) return ret; } +/** + * ice_dpll_periodic_work_e825 - TSPLL DPLL periodic update for E825 + * @pf: board private structure + * + * Publish TSPLL lock status to the dpll subsystem. The PTP periodic worker + * owns TSPLL lock polling and recovery; this function consumes the cached + * result for dpll notifications. + * + * Context: Must be called without pf->dplls.lock held. + */ +static void ice_dpll_periodic_work_e825(struct ice_pf *pf) +{ + struct ice_dpll *tp = &pf->dplls.tspll; + enum dpll_lock_status new_state; + bool changed = false; + + mutex_lock(&pf->dplls.lock); + new_state = ice_dpll_tspll_lock_status_get(pf, true); + + if (tp->prev_dpll_state != new_state) { + tp->dpll_state = new_state; + tp->prev_dpll_state = new_state; + changed = true; + } + mutex_unlock(&pf->dplls.lock); + if (changed) + dpll_device_change_ntf(tp->dpll); +} + /** * ice_dpll_periodic_work - DPLLs periodic worker * @work: pointer to kthread_work structure * - * DPLLs periodic worker is responsible for polling state of dpll. - * Context: Holds pf->dplls.lock + * Periodic worker responsible for polling DPLL state. On E810 devices it + * polls the EEC and PPS DPLLs. On E825 devices, when this PF owns the + * source timer, it publishes TSPLL lock status to the dpll subsystem. + * + * Context: Acquires and releases pf->dplls.lock */ static void ice_dpll_periodic_work(struct kthread_work *work) { @@ -3147,38 +3336,43 @@ static void ice_dpll_periodic_work(struct kthread_work *work) struct ice_pf *pf = container_of(d, struct ice_pf, dplls); struct ice_dpll *de = &pf->dplls.eec; struct ice_dpll *dp = &pf->dplls.pps; - u32 phase_offset_ntf = 0; + u32 ntf_mask = 0; int ret = 0; if (ice_is_reset_in_progress(pf->state)) goto resched; - mutex_lock(&pf->dplls.lock); - d->periodic_counter++; - ret = ice_dpll_update_state(pf, de, false); - if (!ret) - ret = ice_dpll_update_state(pf, dp, false); - if (!ret && dp->phase_offset_monitor_period && - d->periodic_counter % dp->phase_offset_monitor_period == 0) - ret = ice_dpll_pps_update_phase_offsets(pf, &phase_offset_ntf); - if (ret) { - /* EBUSY is expected during reset recovery */ - if (pf->hw.adminq.sq_last_status != LIBIE_AQ_RC_EBUSY) - d->cgu_state_acq_err_num++; - /* stop rescheduling this worker */ - if (d->cgu_state_acq_err_num > - ICE_CGU_STATE_ACQ_ERR_THRESHOLD) { - dev_err(ice_pf_to_dev(pf), - "EEC/PPS DPLLs periodic work disabled\n"); - mutex_unlock(&pf->dplls.lock); - return; + + if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) { + ice_dpll_periodic_work_e825(pf); + } else { + mutex_lock(&pf->dplls.lock); + d->periodic_counter++; + ret = ice_dpll_update_state(pf, de, false); + if (!ret) + ret = ice_dpll_update_state(pf, dp, false); + if (!ret && dp->phase_offset_monitor_period && + d->periodic_counter % dp->phase_offset_monitor_period == 0) + ret = ice_dpll_pps_update_phase_offsets(pf, &ntf_mask); + if (ret) { + /* EBUSY is expected during reset recovery */ + if (pf->hw.adminq.sq_last_status != LIBIE_AQ_RC_EBUSY) + d->cgu_state_acq_err_num++; + /* stop rescheduling this worker */ + if (d->cgu_state_acq_err_num > + ICE_CGU_STATE_ACQ_ERR_THRESHOLD) { + dev_err(ice_pf_to_dev(pf), + "EEC/PPS DPLLs periodic work disabled\n"); + mutex_unlock(&pf->dplls.lock); + return; + } } + mutex_unlock(&pf->dplls.lock); + ice_dpll_notify_changes(de); + ice_dpll_notify_changes(dp); + if (ntf_mask) + ice_dpll_pins_notify_mask(d, d->inputs, d->num_inputs, + ntf_mask); } - mutex_unlock(&pf->dplls.lock); - ice_dpll_notify_changes(de); - ice_dpll_notify_changes(dp); - if (phase_offset_ntf) - ice_dpll_pins_notify_mask(d, d->inputs, d->num_inputs, - phase_offset_ntf); resched: /* Run twice a second or reschedule if update failed */ @@ -3536,6 +3730,7 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) work); struct ice_dpll_pin *pin, *parent = w->pin; bool is_tx_synce_parent = false; + bool is_tspll_time_ref = false; struct ice_pf *pf = parent->pf; bool is_rclk_parent = false; int ret; @@ -3556,7 +3751,11 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) is_tx_synce_parent = ice_dpll_fwnode_eq(parent->fwnode, pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX].fwnode); - if (!is_rclk_parent && !is_tx_synce_parent) + + is_tspll_time_ref = + ice_dpll_fwnode_eq(parent->fwnode, pf->dplls.tspll_in.fwnode); + + if (!is_rclk_parent && !is_tx_synce_parent && !is_tspll_time_ref) goto out; switch (w->action) { @@ -3597,6 +3796,18 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) ERR_PTR(ret)); goto drop_parent_ref; } + } else if (is_tspll_time_ref) { + /* Register TIME_REF pin directly to TSPLL DPLL */ + ret = dpll_pin_register(pf->dplls.tspll.dpll, + parent->pin, + &ice_dpll_tspll_in_ops, + parent); + if (ret) { + dev_err(ice_pf_to_dev(pf), + "TSPLL TIME_REF pin register failed: %pe\n", + ERR_PTR(ret)); + goto drop_parent_ref; + } } break; case DPLL_PIN_DELETED: @@ -3615,6 +3826,11 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) pin = &pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX]; dpll_pin_unregister(pf->dplls.txc.dpll, pin->pin, &ice_dpll_txclk_ops, pin); + } else if (is_tspll_time_ref) { + /* Unregister TIME_REF pin from TSPLL DPLL */ + dpll_pin_unregister(pf->dplls.tspll.dpll, + parent->pin, + &ice_dpll_tspll_in_ops, parent); } drop_parent_ref: /* Drop fwnode pin reference */ @@ -3786,12 +4002,12 @@ ice_dpll_deinit_fwnode_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, destroy_workqueue(pf->dplls.wq); } -static int ice_dpll_deinit_txclk_pins(struct ice_pf *pf) +static int ice_dpll_deinit_txclk_pins(struct ice_pf *pf, bool flush) { struct ice_dpll_pin *synce_pin = &pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX]; struct ice_dpll *dt = &pf->dplls.txc; - ice_dpll_stop_fwnode_pin_activity(synce_pin, true); + ice_dpll_stop_fwnode_pin_activity(synce_pin, flush); ice_dpll_unregister_pins(dt->dpll, pf->dplls.txclks, &ice_dpll_txclk_ops, ARRAY_SIZE(pf->dplls.txclks)); @@ -3806,6 +4022,25 @@ static int ice_dpll_deinit_txclk_pins(struct ice_pf *pf) return 0; } +/** + * ice_dpll_deinit_tspll_pins - deinitialize TSPLL fwnode pin + * @pf: board private structure + * + * Stop notifier activity and release the TIME_REF fwnode pin, unregistering + * it from the TSPLL DPLL if it was registered. + */ +static void ice_dpll_deinit_tspll_pins(struct ice_pf *pf) +{ + struct ice_dpll_pin *time_ref = &pf->dplls.tspll_in; + struct ice_dpll *tp = &pf->dplls.tspll; + + ice_dpll_stop_fwnode_pin_activity(time_ref, true); + if (!IS_ERR_OR_NULL(time_ref->pin)) + dpll_pin_unregister(tp->dpll, time_ref->pin, + &ice_dpll_tspll_in_ops, time_ref); + ice_dpll_release_fwnode_pin(time_ref); +} + /** * ice_dpll_deinit_pins - deinitialize direct pins * @pf: board private structure @@ -3826,7 +4061,10 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu) ice_dpll_deinit_rclk_pin(pf); if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) { - ice_dpll_deinit_txclk_pins(pf); + if (ice_pf_src_tmr_owned(pf) && + test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) + ice_dpll_deinit_tspll_pins(pf); + ice_dpll_deinit_txclk_pins(pf, true); ice_dpll_deinit_fwnode_pins(pf, pf->dplls.inputs, 0); } if (cgu) { @@ -4022,6 +4260,45 @@ err_release_ext_eref: return ret; } +/** + * ice_dpll_init_tspll_pins - init and register TSPLL TIME_REF fwnode pin + * @pf: board private structure + * + * Initialize the fwnode-based TIME_REF input pin for the TSPLL DPLL on E825. + * If the pin is not yet available in the dpll subsystem, registration will + * be deferred via the notifier path. + * + * Return: + * * 0 - success + * * negative - initialization failure reason + */ +static int ice_dpll_init_tspll_pins(struct ice_pf *pf) +{ + struct ice_dpll_pin *time_ref = &pf->dplls.tspll_in; + struct ice_dpll *tp = &pf->dplls.tspll; + int ret; + + time_ref->pf = pf; + ret = ice_dpll_init_fwnode_pin(time_ref, ice_dpll_fwnode_time_ref); + if (ret) + return ret; + + if (IS_ERR_OR_NULL(time_ref->pin)) { + dev_dbg(ice_pf_to_dev(pf), + "TSPLL TIME_REF pin not registered yet\n"); + return 0; + } + + ret = dpll_pin_register(tp->dpll, time_ref->pin, + &ice_dpll_tspll_in_ops, time_ref); + if (ret) { + ice_dpll_stop_fwnode_pin_activity(time_ref, false); + ice_dpll_release_fwnode_pin(time_ref); + } + + return ret; +} + /** * ice_dpll_init_pins_e825 - init pins and register pins with a dplls * @pf: board private structure @@ -4049,8 +4326,24 @@ static int ice_dpll_init_pins_e825(struct ice_pf *pf) goto unregister_pins; ret = ice_dpll_init_txclk_pins(pf, 0); - if (ret) + if (ret) { ice_dpll_deinit_rclk_pin(pf); + goto unregister_pins; + } + + if (ice_pf_src_tmr_owned(pf) && + test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) { + ret = ice_dpll_init_tspll_pins(pf); + if (ret) { + /* Avoid flushing pf->dplls.wq here: notifier work + * items block on pf->dplls.dpll_init which is + * completed by the unregister_pins path below. + * destroy_workqueue() there drains queued items. + */ + ice_dpll_deinit_txclk_pins(pf, false); + ice_dpll_deinit_rclk_pin(pf); + } + } unregister_pins: if (ret) { @@ -4237,6 +4530,7 @@ static void ice_dpll_deinit_worker(struct ice_pf *pf) kthread_cancel_delayed_work_sync(&d->work); kthread_destroy_worker(d->kworker); + d->kworker = NULL; } /** @@ -4673,6 +4967,7 @@ static void ice_dpll_deinit_info(struct ice_pf *pf) static int ice_dpll_init_info_e825c(struct ice_pf *pf) { struct ice_dplls *d = &pf->dplls; + struct ice_dpll *tp = &d->tspll; struct ice_dpll *dt = &d->txc; int ret = 0; int i; @@ -4681,7 +4976,11 @@ static int ice_dpll_init_info_e825c(struct ice_pf *pf) d->num_inputs = ICE_SYNCE_CLK_NUM; dt->dpll_state = ice_txclk_lock_status(pf->ptp.port.tx_clk); dt->mode = DPLL_MODE_MANUAL; - dt->dpll_idx = pf->ptp.port.port_num; + dt->dpll_idx = E825_DPLL_TXCLK_BASE_IDX + pf->ptp.port.port_num; + tp->dpll_state = ice_dpll_tspll_lock_status_get(pf, false); + tp->prev_dpll_state = tp->dpll_state; + tp->mode = DPLL_MODE_MANUAL; + tp->dpll_idx = E825_DPLL_TSPLL_BASE_IDX; d->inputs = kzalloc_objs(*d->inputs, d->num_inputs); if (!d->inputs) @@ -4824,7 +5123,8 @@ deinit_info: * resources and unregistering the dpll, pin and all resources used for * handling them. * - * Context: Destroys pf->dplls.lock mutex. Call only if ICE_FLAG_DPLL was set. + * Context: Call only if ICE_FLAG_DPLL was set. pf->dplls.lock lifetime is + * managed by ice_init_features()/ice_deinit_features(). */ void ice_dpll_deinit(struct ice_pf *pf) { @@ -4848,7 +5148,7 @@ void ice_dpll_deinit(struct ice_pf *pf) up_write(&pf->dplls.txclk_notify_rwsem); } - if (cgu) + if (pf->dplls.kworker) ice_dpll_deinit_worker(pf); if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) @@ -4861,9 +5161,10 @@ void ice_dpll_deinit(struct ice_pf *pf) ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu); if (!IS_ERR_OR_NULL(pf->dplls.txc.dpll)) ice_dpll_deinit_dpll(pf, &pf->dplls.txc, false); + if (!IS_ERR_OR_NULL(pf->dplls.tspll.dpll)) + ice_dpll_deinit_dpll(pf, &pf->dplls.tspll, false); ice_dpll_deinit_info(pf); - mutex_destroy(&pf->dplls.lock); } /** @@ -4873,8 +5174,6 @@ void ice_dpll_deinit(struct ice_pf *pf) * Set up the device dplls, register them and pins connected within Linux dpll * subsystem. Allow userspace to obtain state of DPLL and handling of DPLL * configuration requests. - * - * Context: Initializes pf->dplls.lock mutex. */ static void ice_dpll_init_e825(struct ice_pf *pf) { @@ -4892,7 +5191,6 @@ static void ice_dpll_init_e825(struct ice_pf *pf) pf->ptp.port.port_num = pf->hw.lane_num; } - mutex_init(&d->lock); /* Initialize the txclk worker and its notification rwsem before any * code path can fail: ice_dpll_deinit() runs unconditionally on * failure and calls cancel_work_sync() / down_write() on these. @@ -4904,9 +5202,30 @@ static void ice_dpll_init_e825(struct ice_pf *pf) err = ice_dpll_init_info_e825c(pf); if (err) goto err_exit; + if (ice_pf_src_tmr_owned(pf) && + test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) { + err = ice_dpll_init_dpll(pf, &pf->dplls.tspll, false, + DPLL_TYPE_GENERIC); + if (err) + goto deinit_info; + /* Start the periodic worker before registering fwnode pins. The + * fwnode notifier path (ice_dpll_pin_notify_work()) blocks on + * pf->dplls.dpll_init, which is only signalled on the success + * return below. Starting the worker before any fwnode notifier + * is registered means a subsequent init failure cannot leave + * notifier work items queued on pf->dplls.wq, so the deinit + * flush_workqueue() paths in ice_dpll_deinit_pins() cannot + * deadlock. The E825 periodic worker only touches + * pf->dplls.tspll (already registered above) and pf->ptp state, + * so it is safe to run before pins. + */ + err = ice_dpll_init_worker(pf); + if (err) + goto deinit_tspll; + } err = ice_dpll_init_dpll(pf, &pf->dplls.txc, false, DPLL_TYPE_GENERIC); if (err) - goto deinit_info; + goto deinit_worker; err = ice_dpll_init_pins_e825(pf); if (err) goto deinit_txclk; @@ -4917,10 +5236,15 @@ static void ice_dpll_init_e825(struct ice_pf *pf) deinit_txclk: ice_dpll_deinit_dpll(pf, &pf->dplls.txc, false); +deinit_worker: + if (pf->dplls.kworker) + ice_dpll_deinit_worker(pf); +deinit_tspll: + if (!IS_ERR_OR_NULL(pf->dplls.tspll.dpll)) + ice_dpll_deinit_dpll(pf, &pf->dplls.tspll, false); deinit_info: ice_dpll_deinit_info(pf); err_exit: - mutex_destroy(&d->lock); dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err); } @@ -4931,16 +5255,12 @@ err_exit: * Set up the device dplls, register them and pins connected within Linux dpll * subsystem. Allow userspace to obtain state of DPLL and handling of DPLL * configuration requests. - * - * Context: Initializes pf->dplls.lock mutex. */ static void ice_dpll_init_e810(struct ice_pf *pf) { bool cgu = ice_is_feature_supported(pf, ICE_F_CGU); - struct ice_dplls *d = &pf->dplls; int err = 0; - mutex_init(&d->lock); err = ice_dpll_init_info(pf, cgu); if (err) goto err_exit; @@ -4971,7 +5291,6 @@ deinit_eec: deinit_info: ice_dpll_deinit_info(pf); err_exit: - mutex_destroy(&d->lock); dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err); } diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.h b/drivers/net/ethernet/intel/ice/ice_dpll.h index 103ba3e49068..bce0bea9a664 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.h +++ b/drivers/net/ethernet/intel/ice/ice_dpll.h @@ -133,10 +133,12 @@ struct ice_dpll { * @eec: pointer to EEC dpll dev * @pps: pointer to PPS dpll dev * @txc: pointer to TXC dpll dev + * @tspll: pointer to TSPLL dpll dev (E825 only) * @inputs: input pins pointer * @outputs: output pins pointer * @rclk: recovered pins pointer * @txclks: TX clock reference pins pointer + * @tspll_in: TSPLL TIME_REF fwnode input pin (E825 only) * @num_inputs: number of input pins available on dpll * @num_outputs: number of output pins available on dpll * @cgu_state_acq_err_num: number of errors returned during periodic work @@ -177,12 +179,14 @@ struct ice_dplls { struct ice_dpll eec; struct ice_dpll pps; struct ice_dpll txc; + struct ice_dpll tspll; struct ice_dpll_pin *inputs; struct ice_dpll_pin *outputs; struct ice_dpll_pin sma[ICE_DPLL_PIN_SW_NUM]; struct ice_dpll_pin ufl[ICE_DPLL_PIN_SW_NUM]; struct ice_dpll_pin rclk; struct ice_dpll_pin txclks[ICE_DPLL_TXCLK_NUM_MAX]; + struct ice_dpll_pin tspll_in; u8 num_inputs; u8 num_outputs; u8 sma_data; diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index d88835482d3a..2f372dd37b53 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -4725,6 +4725,14 @@ static void ice_init_features(struct ice_pf *pf) if (ice_is_safe_mode(pf)) return; + /* pf->dplls.lock guards TSPLL/CGU access shared between the DPLL + * subsystem callbacks and the PTP periodic worker's TSPLL monitor. + * Initialize it before ice_ptp_init() so the PTP kworker never sees + * an uninitialized mutex, and destroy it in ice_deinit_features() + * only after ice_ptp_release() has drained the kworker. + */ + mutex_init(&pf->dplls.lock); + /* initialize DDP driven features */ if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) ice_ptp_init(pf); @@ -4769,6 +4777,7 @@ static void ice_deinit_features(struct ice_pf *pf) ice_ptp_release(pf); if (test_bit(ICE_FLAG_DPLL, pf->flags)) ice_dpll_deinit(pf); + mutex_destroy(&pf->dplls.lock); if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) xa_destroy(&pf->eswitch.reprs); ice_hwmon_exit(pf); diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index 4b1040d09f70..e54a98a0bdd0 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -2878,8 +2878,19 @@ static void ice_ptp_tspll_monitor(struct ice_pf *pf) !ice_pf_src_tmr_owned(pf)) return; + /* Serialize the entire monitor tick against TSPLL userspace reconfig + * (ice_dpll_tspll_state_on_dpll_set()). Both paths read HW state and + * write pf->ptp.tspll_locked; without holding pf->dplls.lock across + * the HW read here, a preempted monitor could observe stale HW state + * and then overwrite an accurate cache update from the DPLL callback. + * pf->dplls.lock is initialized in ice_init_features() before the PTP + * kworker starts and destroyed in ice_deinit_features() only after + * ice_ptp_release() has drained the kworker, so it is always valid. + */ + mutex_lock(&pf->dplls.lock); err = ice_tspll_lost_lock_e825c(&pf->hw, &lock_lost); if (err) { + mutex_unlock(&pf->dplls.lock); dev_err_ratelimited(ice_pf_to_dev(pf), "Failed reading TimeSync PLL lock status (err: %d). Retrying.\n", err); @@ -2911,6 +2922,7 @@ static void ice_ptp_tspll_monitor(struct ice_pf *pf) WRITE_ONCE(pf->ptp.tspll_locked, true); pf->ptp.tspll_lock_retries = 0; } + mutex_unlock(&pf->dplls.lock); } static void ice_ptp_periodic_work(struct kthread_work *work) diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.c b/drivers/net/ethernet/intel/ice/ice_tspll.c index 78752dc1e762..85bacb7c3a79 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.c +++ b/drivers/net/ethernet/intel/ice/ice_tspll.c @@ -334,8 +334,9 @@ static int ice_tspll_dis_sticky_bits_e82x(struct ice_hw *hw) * Return: * * %0 - success * * %-EINVAL - input parameters are incorrect - * * %-EBUSY - failed to lock TSPLL - * * %other - CGU read/write failure + * * %-EAGAIN - TSPLL configuration succeeded but lock is not acquired yet + * * %-EBUSY - CGU access is busy (for example during reset) + * * %other - other CGU read/write failures */ static int ice_tspll_cfg_e825c(struct ice_hw *hw, enum ice_tspll_freq clk_freq, enum ice_clk_src clk_src) @@ -467,7 +468,7 @@ static int ice_tspll_cfg_e825c(struct ice_hw *hw, enum ice_tspll_freq clk_freq, if (!(val & ICE_CGU_RO_LOCK_TRUE_LOCK)) { dev_warn(ice_hw_to_dev(hw), "CGU PLL failed to lock\n"); - return -EBUSY; + return -EAGAIN; } err = ice_read_cgu_reg(hw, ICE_CGU_R9, &r9); @@ -661,6 +662,33 @@ int ice_tspll_get_clk_src(struct ice_hw *hw, enum ice_clk_src *clk_src) return 0; } +/** + * ice_tspll_set_cfg - configure TS PLL with new settings + * @hw: board private hw structure + * @clk_freq: clock frequency to program + * @clk_src: clock source to select (TIME_REF, or TCXO) + * + * Configure CGU with new clock source and clock frequency settings. + * + * Return: + * * 0 - OK + * * negative - error + */ +int ice_tspll_set_cfg(struct ice_hw *hw, enum ice_tspll_freq clk_freq, + enum ice_clk_src clk_src) +{ + int ret; + + if (!ice_tspll_check_params(hw, clk_freq, clk_src)) + return -EINVAL; + + ret = ice_tspll_dis_sticky_bits(hw); + if (ret) + return ret; + + return ice_tspll_cfg(hw, clk_freq, clk_src); +} + /** * ice_tspll_init - Initialize TSPLL with settings from firmware * @hw: Pointer to the HW structure diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.h b/drivers/net/ethernet/intel/ice/ice_tspll.h index 05917ae51ded..832c049e686c 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.h +++ b/drivers/net/ethernet/intel/ice/ice_tspll.h @@ -35,6 +35,8 @@ int ice_tspll_cfg_pps_out_e825c(struct ice_hw *hw, bool enable); int ice_tspll_lost_lock_e825c(struct ice_hw *hw, bool *lost_lock); int ice_tspll_restart_e825c(struct ice_hw *hw); int ice_tspll_get_clk_src(struct ice_hw *hw, enum ice_clk_src *clk_src); +int ice_tspll_set_cfg(struct ice_hw *hw, enum ice_tspll_freq clk_freq, + enum ice_clk_src clk_src); int ice_tspll_init(struct ice_hw *hw); int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active, enum ice_synce_clk output); From 97bd063c08a27d0cc5c9367cca5590725c970fa6 Mon Sep 17 00:00:00 2001 From: Grzegorz Nitka Date: Mon, 3 Aug 2026 13:35:07 +0200 Subject: [PATCH 0308/2126] ice: use per-interface clock_id for E825 generic DPLLs On E825, the TX-CLK and TSPLL DPLL devices are registered as DPLL_TYPE_GENERIC. Their clock_id was derived from the board-level PCIe DSN, which is identical for all interfaces sharing the same NAC/quad. As a result, userspace (e.g. 'dpll device show') reports several DPLL devices with the same clock_id and no board or signal label, making it impossible to unambiguously map a DPLL device to the interface it belongs to. Since these DPLLs are per-interface, use the permanent port MAC as the clock_id basis for E825 generic DPLLs: * TX-CLK uses the plain MAC-derived value. * TSPLL on the source-timer owner PF uses the same MAC-derived value with a dedicated tag bit, so it stays distinct from TX-CLK while remaining stable per interface. Other DPLL objects (EEC/PPS and non-E825 paths) keep the board DSN-derived clock_id. When the permanent MAC is not yet valid, fall back to the existing board-level clock_id to preserve init behavior. Reviewed-by: Przemyslaw Korba Signed-off-by: Grzegorz Nitka Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_dpll.c | 80 +++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index 00e3f7de7810..0109fc34307c 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -3059,6 +3059,68 @@ static u64 ice_generate_clock_id(struct ice_pf *pf) return pci_get_dsn(pf->pdev); } +/** + * ice_generate_dpll_clock_id - generate clock_id for a specific dpll device + * @pf: board private structure + * @d: dpll device context + * @type: dpll type being registered + * + * For E825 generic DPLLs, use per-interface permanent MAC as the clock_id + * basis so userspace can unambiguously map DPLL devices to interfaces. + * TX-CLK keeps plain MAC-derived ID, while TSPLL uses the same basis with + * a dedicated tag bit to remain distinct on source-timer owner PFs. + * Other DPLL objects keep board-level DSN-derived clock_id. + * + * Return: generated clock id for a dpll device + */ +static u64 ice_generate_dpll_clock_id(struct ice_pf *pf, struct ice_dpll *d, + enum dpll_type type) +{ + struct ice_hw *hw = &pf->hw; + u64 mac_clock_id; + + if (hw->mac_type == ICE_MAC_GENERIC_3K_E825 && + type == DPLL_TYPE_GENERIC && + hw->port_info && + is_valid_ether_addr(hw->port_info->mac.perm_addr)) { + mac_clock_id = ether_addr_to_u64(hw->port_info->mac.perm_addr); + + if (d->dpll_idx >= E825_DPLL_TXCLK_BASE_IDX) + return mac_clock_id; + + if (d->dpll_idx == E825_DPLL_TSPLL_BASE_IDX) + return mac_clock_id | BIT_ULL(63); + } + + return pf->dplls.clock_id; +} + +/** + * ice_dpll_is_own_dpll_clock_id - check if clock_id belongs to this pf's DPLLs + * @pf: board private structure + * @clock_id: clock_id from a DPLL notification + * + * Match info->src_clock_id from a DPLL pin notification against any DPLL + * device this PF has registered. Used to suppress self-notifications + * generated as a side effect of our own dpll_pin_register() and + * dpll_pin_unregister() calls on the fwnode-backed SYNCE and TIME_REF pins, + * whose DPLLs (TXC and TSPLL) use MAC-derived clock_ids on E825. + * + * Return: true if clock_id matches one of this PF's registered DPLL devices. + */ +static bool ice_dpll_is_own_dpll_clock_id(struct ice_pf *pf, u64 clock_id) +{ + if (clock_id == pf->dplls.clock_id) + return true; + if (pf->hw.mac_type != ICE_MAC_GENERIC_3K_E825) + return false; + if (clock_id == ice_generate_dpll_clock_id(pf, &pf->dplls.txc, + DPLL_TYPE_GENERIC)) + return true; + return clock_id == ice_generate_dpll_clock_id(pf, &pf->dplls.tspll, + DPLL_TYPE_GENERIC); +} + /** * ice_dpll_pin_ntf - notify pin change including any SW pin wrappers * @dplls: pointer to dplls struct @@ -3858,10 +3920,12 @@ static int ice_dpll_pin_notify(struct notifier_block *nb, unsigned long action, if (pin->fwnode != info->fwnode) return NOTIFY_DONE; /* Not this pin */ - /* Ignore notification which are the outcome of internal pin - * registration/unregistration calls - synce pin case. + /* Ignore notifications that are a side effect of internal pin + * registration/unregistration calls. E825 uses per-device + * MAC-derived clock_ids for the TXC and TSPLL generic DPLLs, so + * info->src_clock_id may not equal pf->dplls.clock_id. */ - if (info->src_clock_id == pin->pf->dplls.clock_id) + if (ice_dpll_is_own_dpll_clock_id(pin->pf, info->src_clock_id)) return NOTIFY_DONE; work = kzalloc_obj(*work); @@ -4206,10 +4270,16 @@ static int ice_dpll_init_txclk_pins(struct ice_pf *pf, int start_idx) { struct ice_dpll_pin *ref_pin = pf->dplls.txclks; struct ice_dpll *txc = &pf->dplls.txc; + u64 clock_id; int ret; + /* EXT_EREF0 is a non-fwnode pin; its clock_id must match the TX-CLK + * DPLL device clock_id (see dpll_pin_register()). + */ + clock_id = ice_generate_dpll_clock_id(pf, txc, DPLL_TYPE_GENERIC); + /* Configure EXT_EREF0 pin */ - ret = ice_dpll_get_pins(pf, ref_pin, start_idx, 1, pf->dplls.clock_id); + ret = ice_dpll_get_pins(pf, ref_pin, start_idx, 1, clock_id); if (ret) return ret; ret = dpll_pin_register(txc->dpll, ref_pin->pin, &ice_dpll_txclk_ops, @@ -4487,7 +4557,7 @@ static int ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu, enum dpll_type type) { - u64 clock_id = pf->dplls.clock_id; + u64 clock_id = ice_generate_dpll_clock_id(pf, d, type); int ret; d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE, From f11712fc3d5f9a92880a9474376692c28ada891c Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 8 Sep 2026 18:52:50 +0200 Subject: [PATCH 0309/2126] batman-adv: tt: clarify kernel-doc for batadv_tt_global_purge_local The new kernel-doc didn't mention the "non-multicast clients" limitation. It was also not clear that the roaming flag gets cleared when the announcement didn't contain the roaming flag. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907081824.2474040-1-sw%40simonwunderlich.de?part=9 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 12ea557cb803..6d8fa6d28fee 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1870,9 +1870,10 @@ out: * @tt_global_entry: the global TT entry of the announced client * @flags: TT flags announced for this non-mesh client * - * A client which is announced by another originator is no longer a local - * client. Remove it from the local table and take over the WIFI flag it was - * tracked with. + * A non-multicast client which is announced by another originator is no longer + * a local client. Remove it from the local table and (for the global entry) + * take over the WIFI flag it was tracked with. Reset the roaming flag in case + * the announcement didn't contain the roaming flag. */ static void batadv_tt_global_purge_local(struct batadv_priv *bat_priv, From 08967c26cc8d2dfc451354d4b5ba064e166c9e23 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 8 Sep 2026 18:52:50 +0200 Subject: [PATCH 0310/2126] batman-adv: tt: clarify responsibility for roam flag during removal If an local client gets removed due to an roam, then the local entry must be marked as "roamed" to handle the rerouting correctly. But this is not done by batadv_tt_local_remove() directly but by the new helper batadv_tt_local_mark_removed(). The former will only create similar flags for the roaming event. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907081824.2474040-1-sw%40simonwunderlich.de?part=10 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 6d8fa6d28fee..78f032c9ad65 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1461,7 +1461,10 @@ batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry, scoped_guard(spinlock_bh, &common->flags_lock) { *curr_flags = common->flags; - /* mark the local client as ROAMed */ + /* if this global entry addition is due to a roaming, the node + * has to mark the local entry as "roamed" in order to + * correctly reroute packets later + */ if (roaming) common->flags |= BATADV_TT_CLIENT_ROAM; @@ -1532,22 +1535,22 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, if (!tt_local_entry) return BATADV_NO_FLAGS; - flags = BATADV_TT_CLIENT_DEL; - /* if this global entry addition is due to a roaming, the node has to - * mark the local entry as "roamed" in order to correctly reroute - * packets later - */ - if (roaming) - flags |= BATADV_TT_CLIENT_ROAM; + if (batadv_tt_local_mark_removed(tt_local_entry, roaming, &curr_flags)) { + /* queue (roamed) del event which was prepared by + * batadv_tt_local_mark_removed() + */ + flags = BATADV_TT_CLIENT_DEL; + if (roaming) + flags |= BATADV_TT_CLIENT_ROAM; - if (batadv_tt_local_mark_removed(tt_local_entry, roaming, &curr_flags)) batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, flags, message); - else + } else { /* if this client has been added right now, it is possible to * immediately purge it */ batadv_tt_local_remove_now(bat_priv, tt_local_entry); + } batadv_tt_local_entry_put(tt_local_entry); From be66c5ac5485b8902f10d16b30b45e6fbdaab339 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 8 Sep 2026 18:52:50 +0200 Subject: [PATCH 0311/2126] batman-adv: tt: soften kernel-doc for batadv_tt_local_remove_now() The "never announced" statement is too harsh for an entry which could have been actually be announced by a different context while the batadv_tt_local_remove_now() is in the process of being called. "not yet" might be more appropriate. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907081824.2474040-1-sw%40simonwunderlich.de?part=11 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 78f032c9ad65..354d9416c1b7 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1478,13 +1478,16 @@ batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry, } /** - * batadv_tt_local_remove_now() - purge a local entry which was never announced + * batadv_tt_local_remove_now() - purge a local entry which was not (yet) announced * @bat_priv: the bat priv with all the mesh interface information * @tt_local_entry: local TT entry to purge * - * A client which was added right after the last ttvn increment was never sent - * to the other nodes. It can therefore be dropped from the local table without - * waiting for the next ttvn increment. + * A client which was added right after the last ttvn increment was not (yet) + * sent to the other nodes. It can therefore be dropped from the local table + * without waiting for the next ttvn increment. + * + * If it was still announced by a parallel context before it was removed from + * the hash, then the local TT size adjustment will be handled automatically. */ static void batadv_tt_local_remove_now(struct batadv_priv *bat_priv, From 413999d2e588a28aec1a1c580b16dccd7bc4ec84 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 5 Sep 2026 12:41:23 +0200 Subject: [PATCH 0312/2126] docs: phonet: Fix the struct sockaddr_pn name in the example struct sockaddr_spn does not exist; the name is struct sockaddr_pn. Use struct sockaddr_pn. Signed-off-by: Karl Mehltretter Acked-by: Randy Dunlap Link: https://patch.msgid.link/20260905104123.43511-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/phonet.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/phonet.rst b/Documentation/networking/phonet.rst index d705cc5b09fc..e5551fc45c78 100644 --- a/Documentation/networking/phonet.rst +++ b/Documentation/networking/phonet.rst @@ -172,7 +172,7 @@ two endpoints directly, using connect() on the active side. This is intended to support the newer Nokia Wireless Modem API, as found in e.g. the Nokia Slim Modem in the ST-Ericsson U8500 platform:: - struct sockaddr_spn spn; + struct sockaddr_pn spn; int fd; fd = socket(PF_PHONET, SOCK_SEQPACKET, PN_PROTO_PIPE); From 78113e4c4002964aa1428471b8612e267a332983 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:26 +0800 Subject: [PATCH 0313/2126] net: atlantic: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure still aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-2-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c index 005d6ef4fc36..04b3ef840b36 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c @@ -125,8 +125,6 @@ static int aq_pci_func_init(struct pci_dev *pdev) int err; err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); - if (err) - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (err) { err = -ENOSR; goto err_exit; From fc5a6ed4992c5892aac6001c121e18c5b2463621 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:27 +0800 Subject: [PATCH 0314/2126] net: alx: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-3-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/atheros/alx/main.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/atheros/alx/main.c b/drivers/net/ethernet/atheros/alx/main.c index ab262e66f986..3ca69fd14a5c 100644 --- a/drivers/net/ethernet/atheros/alx/main.c +++ b/drivers/net/ethernet/atheros/alx/main.c @@ -1727,15 +1727,12 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) * shared register for the high 32 bits, so only a single, aligned, * 4 GB physical address range can be used for descriptors. */ - if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { - dev_dbg(&pdev->dev, "DMA to 64-BIT addresses\n"); - } else { - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (err) { - dev_err(&pdev->dev, "No usable DMA config, aborting\n"); - goto out_pci_disable; - } + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (err) { + dev_err(&pdev->dev, "No usable DMA config, aborting\n"); + goto out_pci_disable; } + dev_dbg(&pdev->dev, "DMA to 64-BIT addresses\n"); err = pci_request_mem_regions(pdev, alx_drv_name); if (err) { From 12a924aebcf58fbf954921afaad2dceb5047f91b Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:28 +0800 Subject: [PATCH 0315/2126] net: systemport: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-4-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bcmsysport.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 4d06c6ba6641..4f0ec136b606 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2453,8 +2453,6 @@ static int bcm_sysport_probe(struct platform_device *pdev) return -EINVAL; ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); - if (ret) - ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (ret) { dev_err(&pdev->dev, "unable to set DMA mask: %d\n", ret); return ret; From f60b86ea886493cc622d6589ea87ec64126fc2b7 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:29 +0800 Subject: [PATCH 0316/2126] bnxt_en: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-5-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index d59bcca73a2b..1d5cb53f4258 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -15610,8 +15610,8 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) goto init_err_disable; } - if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 && - dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) { + rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (rc) { dev_err(&pdev->dev, "System does not support DMA, aborting\n"); rc = -EIO; goto init_err_release; From 0b861b6ee2ec79dd941820436bbb03991947f5a5 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:30 +0800 Subject: [PATCH 0317/2126] enic: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. A successful setup now necessarily uses the 47-bit mask, so remove the redundant using_dac flag and advertise NETIF_F_HIGHDMA directly. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-6-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cisco/enic/enic_main.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c index 0baef7a120ec..d32fd03bbf6a 100644 --- a/drivers/net/ethernet/cisco/enic/enic_main.c +++ b/drivers/net/ethernet/cisco/enic/enic_main.c @@ -2991,7 +2991,6 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) struct device *dev = &pdev->dev; struct net_device *netdev; struct enic *enic; - int using_dac = 0; unsigned int i; int err; #ifdef CONFIG_PCI_IOV @@ -3033,20 +3032,11 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); - /* Query PCI controller on system for DMA addressing - * limitation for the device. Try 47-bit first, and - * fail to 32-bit. - */ - + /* The device supports DMA addresses up to 47 bits. */ err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(47)); if (err) { - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (err) { - dev_err(dev, "No usable DMA configuration, aborting\n"); - goto err_out_release_regions; - } - } else { - using_dac = 1; + dev_err(dev, "No usable DMA configuration, aborting\n"); + goto err_out_release_regions; } /* Map vNIC resources from BAR0-5 @@ -3319,8 +3309,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->hw_features |= NETIF_F_NTUPLE; #endif - if (using_dac) - netdev->features |= NETIF_F_HIGHDMA; + netdev->features |= NETIF_F_HIGHDMA; netdev->priv_flags |= IFF_UNICAST_FLT; From e7d0cff7773bc11699eb27ebe81ad131498facb3 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:31 +0800 Subject: [PATCH 0318/2126] net: hns3: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-7-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index e6af939c1c19..e43bd2035edb 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -9156,13 +9156,8 @@ static int hclge_pci_init(struct hclge_dev *hdev) ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (ret) { - ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (ret) { - dev_err(&pdev->dev, - "can't set consistent PCI DMA\n"); - goto err_disable_device; - } - dev_warn(&pdev->dev, "set DMA mask to 32 bits\n"); + dev_err(&pdev->dev, "can't set consistent PCI DMA\n"); + goto err_disable_device; } ret = pci_request_regions(pdev, HCLGE_DRIVER_NAME); From f7cf8452c58f79849c67a2fc81a699d1010af08b Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:32 +0800 Subject: [PATCH 0319/2126] fm10k: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-8-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_pci.c b/drivers/net/ethernet/intel/fm10k/fm10k_pci.c index f5b4d062709a..afe939f8f4ef 100644 --- a/drivers/net/ethernet/intel/fm10k/fm10k_pci.c +++ b/drivers/net/ethernet/intel/fm10k/fm10k_pci.c @@ -2111,8 +2111,6 @@ static int fm10k_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); - if (err) - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (err) { dev_err(&pdev->dev, "DMA configuration failed: %d\n", err); From ee95313d1aef5730765199fe256f3518a6dc50cb Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:33 +0800 Subject: [PATCH 0320/2126] net/mlx4: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20260903084339.870562-9-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx4/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index c851daa5da9f..036135df23bf 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -3863,12 +3863,8 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data, err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (err) { - dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (err) { - dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); - goto err_release_regions; - } + dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); + goto err_release_regions; } /* Allow large DMA segments, up to the firmware limit of 1 GB */ From 7b85fba09ebe33fa9a5441f4ffcde388b5beff71 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:34 +0800 Subject: [PATCH 0321/2126] net/mlx5: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20260903084339.870562-10-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 5f28d906c35b..3a3b0ec4aad1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -184,12 +184,8 @@ static int set_dma_caps(struct pci_dev *pdev) err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (err) { - dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (err) { - dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); - return err; - } + dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); + return err; } dma_set_max_seg_size(&pdev->dev, 2u * 1024 * 1024 * 1024); From 68161cab4810f07e1fa29374277212ce51c319a5 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:35 +0800 Subject: [PATCH 0322/2126] mlxsw: pci: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Update the error message to identify the combined streaming and coherent DMA mask operation. Signed-off-by: Ruizhe Zhou Reviewed-by: Petr Machata Link: https://patch.msgid.link/20260903084339.870562-11-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c index bfe3268dfdc1..dceb69945d26 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci.c +++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c @@ -2429,11 +2429,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (err) { - err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); - if (err) { - dev_err(&pdev->dev, "dma_set_mask failed\n"); - goto err_pci_set_dma_mask; - } + dev_err(&pdev->dev, "dma_set_mask_and_coherent failed\n"); + goto err_pci_set_dma_mask; } if (pci_resource_len(pdev, 0) < MLXSW_PCI_BAR0_SIZE) { From 453248082a5d58884ed8e07e77ab3087f5c14d7c Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:36 +0800 Subject: [PATCH 0323/2126] eth: fbnic: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-12-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_pci.c b/drivers/net/ethernet/meta/fbnic/fbnic_pci.c index 8b9bc9e8ea56..47d5dfbf3368 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_pci.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_pci.c @@ -276,8 +276,6 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(46)); - if (err) - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (err) { dev_err(&pdev->dev, "DMA configuration failed: %d\n", err); return err; From 85996f11032593390ca727f6634f8bacae2a983c Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:37 +0800 Subject: [PATCH 0324/2126] net: pch_gbe: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-13-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c index 88c5c52e0e38..ba3d10f9aec6 100644 --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c @@ -2504,12 +2504,10 @@ static int pch_gbe_probe(struct pci_dev *pdev, if (ret) return ret; - if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { - ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (ret) { - dev_err(&pdev->dev, "ERR: No usable DMA configuration, aborting\n"); - return ret; - } + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (ret) { + dev_err(&pdev->dev, "ERR: No usable DMA configuration, aborting\n"); + return ret; } ret = pcim_iomap_regions(pdev, 1 << PCH_GBE_PCI_BAR, pci_name(pdev)); From 0a8bc1ad90ad990dbd1e1761f183b844b02ebb42 Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:38 +0800 Subject: [PATCH 0325/2126] net: renesas: rswitch: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure still aborts initialization. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-14-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/rswitch_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c index 755232994fcc..64b821ca02f8 100644 --- a/drivers/net/ethernet/renesas/rswitch_main.c +++ b/drivers/net/ethernet/renesas/rswitch_main.c @@ -2162,11 +2162,8 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) return -ENOMEM; ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); - if (ret < 0) { - ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); - if (ret < 0) - return ret; - } + if (ret) + return ret; priv->gwca.index = AGENT_INDEX_GWCA; priv->gwca.num_queues = min(RSWITCH_NUM_PORTS * NUM_QUEUES_PER_NDEV, From 03011820f02feedbffa25254bdc25ff3a9800c6a Mon Sep 17 00:00:00 2001 From: Ruizhe Zhou Date: Thu, 3 Sep 2026 16:43:39 +0800 Subject: [PATCH 0326/2126] net: niu: Remove obsolete 32-bit DMA mask fallback The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect: https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. A successful setup now necessarily uses the 44-bit mask, so advertise NETIF_F_HIGHDMA directly after checking the result. Signed-off-by: Ruizhe Zhou Link: https://patch.msgid.link/20260903084339.870562-15-zhouruizhe@resnics.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/sun/niu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c index 54dd7281191d..c74a97fe5464 100644 --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -9835,15 +9835,11 @@ static int niu_pci_init_one(struct pci_dev *pdev, PCI_EXP_DEVCTL_RELAX_EN); err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44)); - if (!err) - dev->features |= NETIF_F_HIGHDMA; if (err) { - err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); - if (err) { - dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); - goto err_out_release_parent; - } + dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); + goto err_out_release_parent; } + dev->features |= NETIF_F_HIGHDMA; niu_set_basic_features(dev); From 3d80284b244ed2992feb98d9f937accff6fc33a8 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 3 Sep 2026 14:32:41 -0700 Subject: [PATCH 0327/2126] net: ll_temac: Return actual error from of_get_mac_address() When of_get_mac_address() fails, return the actual error code (rc) instead of the hardcoded -ENODEV. This preserves the original error information, which may be more specific (e.g., -EINVAL, -EPROBE_DEFER) and helps callers handle the failure appropriately. Use dev_err_probe() to avoid printing an extra error message in case of -EPROBE_DEFER. Signed-off-by: Rosen Penev Link: https://patch.msgid.link/20260903213241.1040204-1-rosenp@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/ll_temac_main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c index 711ed9c2631b..303b4da66399 100644 --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -1579,10 +1579,9 @@ static int temac_probe(struct platform_device *pdev) if (temac_np) { /* Retrieve the MAC address */ rc = of_get_mac_address(temac_np, addr); - if (rc) { - dev_err(&pdev->dev, "could not find MAC address\n"); - return -ENODEV; - } + if (rc) + return dev_err_probe(&pdev->dev, rc, + "could not find MAC address\n"); temac_init_mac_address(ndev, addr); } else if (pdata) { temac_init_mac_address(ndev, pdata->mac_addr); From 4c1028a34760a2541d3dae43c8863fd5f7d917ae Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Sat, 5 Sep 2026 09:28:26 +0200 Subject: [PATCH 0328/2126] net: phy: motorcomm: Split yt8521_config_init() page management In preparation for separate .config_init() implementations for YT8521 and YT8531S, let's split the yt8521_config_init() into a high-level helper that deals with page handling, and another one that implements the logic. This will ease splitting the YT8531S-specific logic out. Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20260905072830.28986-2-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/motorcomm.c | 66 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index c5a2cda8d31b..58e4d67b945f 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -1680,6 +1680,41 @@ static int yt8521_resume(struct phy_device *phydev) return yt8521_modify_utp_fiber_bmcr(phydev, BMCR_PDOWN, 0); } +static int __yt8521_config_init(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + int ret = 0; + + /* set rgmii delay mode */ + if (phydev->interface != PHY_INTERFACE_MODE_SGMII) { + ret = ytphy_rgmii_clk_delay_config(phydev); + if (ret < 0) + return ret; + } + + if (device_property_read_bool(dev, "motorcomm,auto-sleep-disabled")) { + /* disable auto sleep */ + ret = ytphy_modify_ext(phydev, YT8521_EXTREG_SLEEP_CONTROL1_REG, + YT8521_ESC1R_SLEEP_SW, 0); + if (ret < 0) + return ret; + } + + if (device_property_read_bool(dev, "motorcomm,keep-pll-enabled")) { + /* enable RXC clock when no wire plug */ + ret = ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, + YT8521_CGR_RX_CLK_EN, 0); + if (ret < 0) + return ret; + } + + if (phy_interface_is_rgmii(phydev) && + phydev_id_compare(phydev, PHY_ID_YT8531S)) + ret = yt8531_set_ds(phydev); + + return ret; +} + /** * yt8521_config_init() - called to initialize the PHY * @phydev: a pointer to a &struct phy_device @@ -1688,40 +1723,13 @@ static int yt8521_resume(struct phy_device *phydev) */ static int yt8521_config_init(struct phy_device *phydev) { - struct device *dev = &phydev->mdio.dev; - int old_page; - int ret = 0; + int old_page, ret = 0; old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); if (old_page < 0) goto err_restore_page; - /* set rgmii delay mode */ - if (phydev->interface != PHY_INTERFACE_MODE_SGMII) { - ret = ytphy_rgmii_clk_delay_config(phydev); - if (ret < 0) - goto err_restore_page; - } - - if (device_property_read_bool(dev, "motorcomm,auto-sleep-disabled")) { - /* disable auto sleep */ - ret = ytphy_modify_ext(phydev, YT8521_EXTREG_SLEEP_CONTROL1_REG, - YT8521_ESC1R_SLEEP_SW, 0); - if (ret < 0) - goto err_restore_page; - } - - if (device_property_read_bool(dev, "motorcomm,keep-pll-enabled")) { - /* enable RXC clock when no wire plug */ - ret = ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, - YT8521_CGR_RX_CLK_EN, 0); - if (ret < 0) - goto err_restore_page; - } - - if (phy_interface_is_rgmii(phydev) && - phydev_id_compare(phydev, PHY_ID_YT8531S)) - ret = yt8531_set_ds(phydev); + ret = __yt8521_config_init(phydev); err_restore_page: return phy_restore_page(phydev, old_page, ret); From 58e1bbfe4713202b211288b838f08fc3558a0098 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Sat, 5 Sep 2026 09:28:27 +0200 Subject: [PATCH 0329/2126] net: phy: motorcomm: Add a dedicated .config_init for YT8531S The YT8531S PHY configuration logic is similar to the YT8521, but with some extra steps for the RGMII configuration. In preparation for improvements in the YT8531S configuration for the version found integrated with the YT6801 PCIe NIC, let's split the logic out by extending the YT8521 configuration sequence. Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20260905072830.28986-3-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/motorcomm.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index 58e4d67b945f..36c229460a77 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -1700,19 +1700,12 @@ static int __yt8521_config_init(struct phy_device *phydev) return ret; } - if (device_property_read_bool(dev, "motorcomm,keep-pll-enabled")) { + if (device_property_read_bool(dev, "motorcomm,keep-pll-enabled")) /* enable RXC clock when no wire plug */ - ret = ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, - YT8521_CGR_RX_CLK_EN, 0); - if (ret < 0) - return ret; - } + return ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, + YT8521_CGR_RX_CLK_EN, 0); - if (phy_interface_is_rgmii(phydev) && - phydev_id_compare(phydev, PHY_ID_YT8531S)) - ret = yt8531_set_ds(phydev); - - return ret; + return 0; } /** @@ -1735,6 +1728,25 @@ err_restore_page: return phy_restore_page(phydev, old_page, ret); } +static int yt8531s_config_init(struct phy_device *phydev) +{ + int old_page, ret = 0; + + old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); + if (old_page < 0) + goto err_restore_page; + + ret = __yt8521_config_init(phydev); + if (ret) + goto err_restore_page; + + if (phy_interface_is_rgmii(phydev)) + ret = yt8531_set_ds(phydev); + +err_restore_page: + return phy_restore_page(phydev, old_page, ret); +} + static const unsigned long supported_trgs = (BIT(TRIGGER_NETDEV_FULL_DUPLEX) | BIT(TRIGGER_NETDEV_HALF_DUPLEX) | BIT(TRIGGER_NETDEV_LINK) | @@ -3143,7 +3155,7 @@ static struct phy_driver motorcomm_phy_drvs[] = { .set_wol = ytphy_set_wol, .config_aneg = yt8521_config_aneg, .aneg_done = yt8521_aneg_done, - .config_init = yt8521_config_init, + .config_init = yt8531s_config_init, .read_status = yt8521_read_status, .soft_reset = yt8521_soft_reset, .suspend = yt8521_suspend, From 031c64bd1b02905f0f7d14530f39f262ccaf9c24 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Sat, 5 Sep 2026 09:28:28 +0200 Subject: [PATCH 0330/2126] net: phy: motorcomm: Enable analog frontend on YT8531S The YT6801 PCIe NIC includes the dwmac-motorcomm IP for the MAC part, as well as a YT8531S PHY, configured in GMII mode. It seems this PHY requires the Analog Front-end (AFE) DAC clock to be enabled for link to reliably establish, otherwise the link just doesn't come up. Let's enable it at config_init() whenever the PHY is in GMII mode. This logic has been extracted from the vendor driver provided by Motorcomm. It's really unclear if this is specific to the integrated version of that PHY, and how this potentially interacts with the fiber mode this PHY supports, so this configuration is only enabled when the interface is GMII, i.e. the PHY is integrated. With this, the PHY reliably establishes link and the YT6801 PCIe card becomes fully functional. Supend/Resume was also tested, the link stays operational after resume. Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20260905072830.28986-4-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/motorcomm.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index 36c229460a77..90a4f86f2758 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -144,6 +144,11 @@ #define YT8521_CLOCK_GATING_REG 0xC #define YT8521_CGR_RX_CLK_EN BIT(12) +/* Analog front-end control register 3 */ +#define YT8531S_EXT_AFE_CTRL3 0x12 +/* Analog front-end DAC clock enable */ +#define YT8531S_AFE_CTRL3_CLKDAC_AON BIT(13) + #define YT8521_EXTREG_SLEEP_CONTROL1_REG 0x27 #define YT8521_ESC1R_SLEEP_SW BIT(15) #define YT8521_ESC1R_PLLON_SLP BIT(14) @@ -1740,8 +1745,15 @@ static int yt8531s_config_init(struct phy_device *phydev) if (ret) goto err_restore_page; - if (phy_interface_is_rgmii(phydev)) + if (phy_interface_is_rgmii(phydev)) { ret = yt8531_set_ds(phydev); + if (ret) + goto err_restore_page; + } + + if (phydev->interface == PHY_INTERFACE_MODE_GMII) + ret = ytphy_modify_ext(phydev, YT8531S_EXT_AFE_CTRL3, + 0, YT8531S_AFE_CTRL3_CLKDAC_AON); err_restore_page: return phy_restore_page(phydev, old_page, ret); From 917f713b4ec4ffcc068993e8c7a1d93a8457d467 Mon Sep 17 00:00:00 2001 From: "Maxime Chevallier (Netdev Foundation)" Date: Mon, 7 Sep 2026 18:14:35 +0200 Subject: [PATCH 0331/2126] tools: ynl: Allow cross-compiling ynl and associated tools The ynl tool and libraries may be built standalone or through the drivers/net/hw selftest machinery. This may target a different arch, so we need to take the CROSS_COMPILE variable into account for LLVM and gcc. Let's include the tools/scripts/Makefile.include that deals with the CC/AR resolution. Fixup the ynltool CFLAGS handling to use +=, so that we don't override the ones set in Makefile.include. Makefile.include also sets the Q variable for verbose mode, so we can drop it from the ynltool Makefile. This will allow properly selection the verbosity of ynltool builds with the V=1 make flag. Reviewed-by: Matthieu Baerts (Netdev Foundation) Signed-off-by: Maxime Chevallier (Netdev Foundation) Link: https://patch.msgid.link/20260907161438.755125-2-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- tools/net/ynl/Makefile | 1 + tools/net/ynl/generated/Makefile | 3 ++- tools/net/ynl/lib/Makefile | 3 ++- tools/net/ynl/tests/Makefile | 2 +- tools/net/ynl/ynltool/Makefile | 6 ++---- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/net/ynl/Makefile b/tools/net/ynl/Makefile index 3cefe4ed96cb..838c465d65aa 100644 --- a/tools/net/ynl/Makefile +++ b/tools/net/ynl/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +include ../../scripts/Makefile.include include ../../scripts/Makefile.arch INSTALL ?= install diff --git a/tools/net/ynl/generated/Makefile b/tools/net/ynl/generated/Makefile index ea4128f612d6..5a186349b5a8 100644 --- a/tools/net/ynl/generated/Makefile +++ b/tools/net/ynl/generated/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 -CC=gcc +include ../../../scripts/Makefile.include + CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \ -I../lib/ -idirafter $(UAPI_PATH) ifeq ("$(DEBUG)","1") diff --git a/tools/net/ynl/lib/Makefile b/tools/net/ynl/lib/Makefile index 9b98c0599600..7b3eae89982f 100644 --- a/tools/net/ynl/lib/Makefile +++ b/tools/net/ynl/lib/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 -CC=gcc +include ../../../scripts/Makefile.include + CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow ifeq ("$(DEBUG)","1") CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan diff --git a/tools/net/ynl/tests/Makefile b/tools/net/ynl/tests/Makefile index 40827ca8e579..99ae7dcd6348 100644 --- a/tools/net/ynl/tests/Makefile +++ b/tools/net/ynl/tests/Makefile @@ -2,8 +2,8 @@ # Makefile for YNL tests include ../Makefile.deps +include ../../../scripts/Makefile.include -CC=gcc CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \ -I../lib/ -I../generated/ -I../../../testing/selftests/ \ -idirafter $(UAPI_PATH) diff --git a/tools/net/ynl/ynltool/Makefile b/tools/net/ynl/ynltool/Makefile index 48b0f32050f0..b8c67cdb4fdf 100644 --- a/tools/net/ynl/ynltool/Makefile +++ b/tools/net/ynl/ynltool/Makefile @@ -1,12 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only include ../Makefile.deps +include ../../../scripts/Makefile.include INSTALL ?= install prefix ?= /usr -CC := gcc -CFLAGS := -Wall -Wextra -Werror -O2 +CFLAGS += -Wall -Wextra -Werror -O2 ifeq ("$(DEBUG)","1") CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan endif @@ -27,8 +27,6 @@ include $(wildcard *.d) all: $(YNLTOOL) -Q = @ - $(YNLTOOL): ../libynl.a $(OBJS) $(Q)echo -e "\tLINK $@" $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) ../libynl.a -lm From 0c5588740e2204b4005a807b6f5a06ae5a2d0b75 Mon Sep 17 00:00:00 2001 From: "Maxime Chevallier (Netdev Foundation)" Date: Mon, 7 Sep 2026 18:14:36 +0200 Subject: [PATCH 0332/2126] selftests: drv-net: Use cross-compilation environment for the io_uring check To test for the presence of zerocopy support in the available liburing, a small check program is compiled. The CC value used for the io_uring library check defaults to the host compiler, which will incorrectly validate liburing based on the host's sysroot and not the target's. Normally the CC for cross-compile is set in lib.mk, but this also requires the test list to be set when we include it, and this check needs to run first. Note that this doesn't cover the LLVM cross-compiling case though, as with LLVM we may still detect based on the host liburing. Suggested-by: Matthieu Baerts (NGI0) Reviewed-by: Matthieu Baerts (Netdev Foundation) Signed-off-by: Maxime Chevallier (Netdev Foundation) Link: https://patch.msgid.link/20260907161438.755125-3-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hw/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 6105be8e590f..f9458dc6c150 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -1,5 +1,10 @@ # SPDX-License-Identifier: GPL-2.0+ OR MIT +# Set CC for the io_uring check +ifeq ($(LLVM)$(CC),cc) +CC := $(CROSS_COMPILE)gcc +endif + # Check if io_uring supports zero-copy receive HAS_IOURING_ZCRX := $(shell \ echo -e '#include \n' \ From 52176ca4e4d030bacc1232d3a31237c741ff7ccb Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Mon, 7 Sep 2026 15:28:09 +0800 Subject: [PATCH 0333/2126] selftests/drivers/net: include lib/sh/*.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When I tried to install and run bonding selftests via: make INSTALL_PATH=/tmp/kself TARGETS=drivers/net/bonding \ -C tools/testing/selftests install Some tests fail because net/lib/sh/defer.sh is missing: /tmp/kself/net/forwarding/../lib.sh: line 5: /tmp/kself/net/lib/sh/defer.sh: No such file or directory One option is to add defer.sh directly to TEST_INCLUDES. Alternatively, follow the approach from commit f72aa1b27628 ("selftests: net: include lib/sh/*.sh with lib.sh"), which pulls in all .sh files to accommodate future changes to the library directory. This patch adds a wildcard to include all shell files for drivers/net tests that consume net lib.sh. TEST_INCLUDES is also sorted to avoid ordering‑related problems for future modifications. The team driver is not affected by this bug, but we use the wildcard for it as well, rather than listing only defer.sh. Signed-off-by: Hangbin Liu Reviewed-by: Petr Machata Reviewed-by: Breno Leitao Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260907-selftest_lib_defer-v1-1-8af94645aaa3@kylinos.cn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/Makefile | 1 + tools/testing/selftests/drivers/net/bonding/Makefile | 3 ++- tools/testing/selftests/drivers/net/dsa/Makefile | 1 + tools/testing/selftests/drivers/net/hw/Makefile | 3 ++- tools/testing/selftests/drivers/net/netconsole/Makefile | 3 ++- tools/testing/selftests/drivers/net/team/Makefile | 4 ++-- tools/testing/selftests/drivers/net/virtio_net/Makefile | 1 + 7 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index 1f21e17d8c22..b98c0e240b7d 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -3,6 +3,7 @@ CFLAGS += $(KHDR_INCLUDES) TEST_INCLUDES := $(wildcard lib/py/*.py) \ $(wildcard lib/sh/*.sh) \ + $(wildcard ../../net/lib/sh/*.sh) \ ../../net/lib.sh \ TEST_GEN_FILES := \ diff --git a/tools/testing/selftests/drivers/net/bonding/Makefile b/tools/testing/selftests/drivers/net/bonding/Makefile index 6364ca02642d..e337c099fb40 100644 --- a/tools/testing/selftests/drivers/net/bonding/Makefile +++ b/tools/testing/selftests/drivers/net/bonding/Makefile @@ -27,9 +27,10 @@ TEST_FILES := \ # end of TEST_FILES TEST_INCLUDES := \ - ../../../net/lib.sh \ + $(wildcard ../../../net/lib/sh/*.sh) \ ../lib/sh/lib_netcons.sh \ ../../../net/forwarding/lib.sh \ + ../../../net/lib.sh \ # end of TEST_INCLUDES include ../../../lib.mk diff --git a/tools/testing/selftests/drivers/net/dsa/Makefile b/tools/testing/selftests/drivers/net/dsa/Makefile index 7994bd0e5c44..7893011b3842 100644 --- a/tools/testing/selftests/drivers/net/dsa/Makefile +++ b/tools/testing/selftests/drivers/net/dsa/Makefile @@ -19,6 +19,7 @@ TEST_FILES := \ # end of TEST_FILES TEST_INCLUDES := \ + $(wildcard ../../../net/lib/sh/*.sh) \ ../../../net/forwarding/bridge_locked_port.sh \ ../../../net/forwarding/bridge_mdb.sh \ ../../../net/forwarding/bridge_mld.sh \ diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index f9458dc6c150..bd3b8d2fa47e 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -69,10 +69,11 @@ TEST_FILES := \ TEST_INCLUDES := \ $(wildcard lib/py/*.py ../lib/py/*.py) \ - ../../../net/lib.sh \ + $(wildcard ../../../net/lib/sh/*.sh) \ ../../../net/forwarding/ipip_lib.sh \ ../../../net/forwarding/lib.sh \ ../../../net/forwarding/tc_common.sh \ + ../../../net/lib.sh \ # # YNL files, must be before "include ..lib.mk" diff --git a/tools/testing/selftests/drivers/net/netconsole/Makefile b/tools/testing/selftests/drivers/net/netconsole/Makefile index f0674c0017fc..c7972a40babf 100644 --- a/tools/testing/selftests/drivers/net/netconsole/Makefile +++ b/tools/testing/selftests/drivers/net/netconsole/Makefile @@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 TEST_INCLUDES := \ - ../../../net/lib.sh \ + $(wildcard ../../../net/lib/sh/*.sh) \ ../lib/sh/lib_netcons.sh \ + ../../../net/lib.sh \ # end of TEST_INCLUDES TEST_PROGS := \ diff --git a/tools/testing/selftests/drivers/net/team/Makefile b/tools/testing/selftests/drivers/net/team/Makefile index 7c58cf82121e..e40c83a92724 100644 --- a/tools/testing/selftests/drivers/net/team/Makefile +++ b/tools/testing/selftests/drivers/net/team/Makefile @@ -13,12 +13,12 @@ TEST_PROGS := \ # end of TEST_PROGS TEST_INCLUDES := \ - team_lib.sh \ + $(wildcard ../../../net/lib/sh/*.sh) \ ../bonding/lag_lib.sh \ ../../../net/forwarding/lib.sh \ ../../../net/in_netns.sh \ ../../../net/lib.sh \ - ../../../net/lib/sh/defer.sh \ + team_lib.sh \ # end of TEST_INCLUDES include ../../../lib.mk diff --git a/tools/testing/selftests/drivers/net/virtio_net/Makefile b/tools/testing/selftests/drivers/net/virtio_net/Makefile index 868ece3fea1f..df34e29b5680 100644 --- a/tools/testing/selftests/drivers/net/virtio_net/Makefile +++ b/tools/testing/selftests/drivers/net/virtio_net/Makefile @@ -5,6 +5,7 @@ TEST_PROGS = basic_features.sh TEST_FILES = virtio_net_common.sh TEST_INCLUDES = \ + $(wildcard ../../../net/lib/sh/*.sh) \ ../../../net/forwarding/lib.sh \ ../../../net/lib.sh \ # end of TEST_INCLUDES From 789842b671a842f961b299842bd590d130cec07f Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 5 Sep 2026 07:19:44 +0200 Subject: [PATCH 0334/2126] net: smc91x: Remove stale documentation reference smc9.rst was removed with the separate smc91c92 driver. Stop pointing SMC91X users to the nonexistent file. Signed-off-by: Karl Mehltretter Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260905051944.11604-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/smsc/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/smsc/Kconfig b/drivers/net/ethernet/smsc/Kconfig index 66bca803b19c..99e22d3e16ef 100644 --- a/drivers/net/ethernet/smsc/Kconfig +++ b/drivers/net/ethernet/smsc/Kconfig @@ -29,8 +29,7 @@ config SMC91X help This is a driver for SMC's 91x series of Ethernet chipsets, including the SMC91C94 and the SMC91C111. Say Y if you want it - compiled into the kernel, and read the file - . + compiled into the kernel. This driver is also available as a module ( = code which can be inserted in and removed from the running kernel whenever you want). From 548b86839f7fb819a4d6c83b71c73ec378d24275 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 5 Sep 2026 11:27:19 +0200 Subject: [PATCH 0335/2126] net: ipa: Drop the monitor_rx endpoint_id ABI entry The ABI file documents .../endpoint_id/monitor_rx, but drivers/net/ipa/ipa_sysfs.c has only ever created modem_rx and modem_tx in the endpoint_id group. No monitor endpoint attribute exists. Drop the entry. Signed-off-by: Karl Mehltretter Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260905092719.41497-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- .../ABI/testing/sysfs-devices-platform-soc-ipa | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-devices-platform-soc-ipa b/Documentation/ABI/testing/sysfs-devices-platform-soc-ipa index 364b1ba41242..3b3bae2369d4 100644 --- a/Documentation/ABI/testing/sysfs-devices-platform-soc-ipa +++ b/Documentation/ABI/testing/sysfs-devices-platform-soc-ipa @@ -75,20 +75,6 @@ Description: the ID of the AP endpoint on which packets destined for the embedded modem are sent. -What: .../XXXXXXX.ipa/endpoint_id/monitor_rx -Date: July 2022 -KernelVersion: v5.19 -Contact: Alex Elder -Description: - The .../XXXXXXX.ipa/endpoint_id/monitor_rx file contains - the ID of the AP endpoint on which IPA "monitor" data is - received. The monitor endpoint supplies replicas of - packets that enter the IPA hardware for processing. - Each replicated packet is preceded by a fixed-size "ODL" - header (see .../XXXXXXX.ipa/feature/monitor, above). - Large packets are truncated, to reduce the bandwidth - required to provide the monitor function. - What: .../XXXXXXX.ipa/modem/ Date: June 2021 KernelVersion: v5.14 From 52953d149ab4da0432d54b09f3c8add42b4d4a82 Mon Sep 17 00:00:00 2001 From: Mikhail Lobanov Date: Mon, 9 Sep 2024 11:08:20 -0400 Subject: [PATCH 0336/2126] wifi: ath11k: modify null check logic in ath11k_ce_rx_post_pipe() The previous logic in ath11k_ce_rx_post_pipe() incorrectly required both dest_ring and status_ring to be NULL in order to exit the function. This caused the function to continue even if only one of the pointers was NULL, potentially leading to null pointer dereferences in ath11k_ce_rx_buf_enqueue_pipe(). Fix the condition by modifying the logic so that the function returns early if either dest_ring or status_ring is NULL. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices") Signed-off-by: Mikhail Lobanov Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Acked-by: Jeff Johnson Link: https://patch.msgid.link/20240909150824.28195-1-m.lobanov@rosalinux.ru Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/ce.c b/drivers/net/wireless/ath/ath11k/ce.c index c56dd8a86760..1e08b0970b14 100644 --- a/drivers/net/wireless/ath/ath11k/ce.c +++ b/drivers/net/wireless/ath/ath11k/ce.c @@ -325,7 +325,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe) dma_addr_t paddr; int ret = 0; - if (!(pipe->dest_ring || pipe->status_ring)) + if (!pipe->dest_ring || !pipe->status_ring) return 0; spin_lock_bh(&ab->ce.ce_lock); From c7555d47b1d051e0406474349deccf74b491ae01 Mon Sep 17 00:00:00 2001 From: Nicolas Escande Date: Thu, 13 Aug 2026 14:15:28 +0200 Subject: [PATCH 0337/2126] wifi: ath11k: fix locking problem in ath11k_dp_rx_tid_del_func() In this function, we iterate over dp->reo_cmd_cache_flush_list using list_for_each_entry_safe(), under dp->reo_cmd_lock for concurrent access, and for each expired entries we : - drop the lock - call ath11k_dp_reo_cache_flush() - kfree() the entry - retake the lock to keep on iterating list_for_each_entry_safe() protects us from deleting the entry during iteration but doesn't protect for concurrent access. So another thread can take the lock and modify the list in between and crash like below. To fix the issue, move all entries that needs to be freed to a local list while under the lock and then iterate over the list to free the entries without holding the lock. BUG: Unable to handle kernel paging request at virtual address 00000010ddbeef8c Call trace: ath11k_dp_rx_tid_del_func+0x164/0x3c8 ath11k_dp_process_reo_status+0x1d4/0x2fc ath11k_dp_service_srng+0x334/0x338 ath11k_pcic_ext_grp_napi_poll+0x30/0xc0 __napi_poll+0x34/0x184 napi_threaded_poll+0xb4/0x1d8 kthread+0xdc/0xe0 ret_from_fork+0x10/0x20 Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.9.0.1-01977-QCAHKSWPL_SILICONZ-1 Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices") Suggested-by: Baochen Qiang Signed-off-by: Nicolas Escande Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260813-ath11k-locking-v2-1-f4113a0bd0f4@gmail.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/dp_rx.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index 33425707c084..5b717b731197 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -762,6 +762,9 @@ static void ath11k_dp_rx_tid_del_func(struct ath11k_dp *dp, void *ctx, struct ath11k_base *ab = dp->ab; struct dp_rx_tid *rx_tid = ctx; struct dp_reo_cache_flush_elem *elem, *tmp; + struct list_head flush_list; + + INIT_LIST_HEAD(&flush_list); if (status == HAL_REO_CMD_DRAIN) { goto free_desc; @@ -783,23 +786,25 @@ static void ath11k_dp_rx_tid_del_func(struct ath11k_dp *dp, void *ctx, list_add_tail(&elem->list, &dp->reo_cmd_cache_flush_list); dp->reo_cmd_cache_flush_count++; - /* Flush and invalidate aged REO desc from HW cache */ + /* identify aged REO desc that needs removal */ list_for_each_entry_safe(elem, tmp, &dp->reo_cmd_cache_flush_list, list) { if (dp->reo_cmd_cache_flush_count > DP_REO_DESC_FREE_THRESHOLD || time_after(jiffies, elem->ts + msecs_to_jiffies(DP_REO_DESC_FREE_TIMEOUT_MS))) { - list_del(&elem->list); + list_move_tail(&elem->list, &flush_list); dp->reo_cmd_cache_flush_count--; - spin_unlock_bh(&dp->reo_cmd_lock); - - ath11k_dp_reo_cache_flush(ab, &elem->data); - kfree(elem); - spin_lock_bh(&dp->reo_cmd_lock); } } spin_unlock_bh(&dp->reo_cmd_lock); + /* remove aged REO desc from HW */ + list_for_each_entry_safe(elem, tmp, &flush_list, list) { + ath11k_dp_reo_cache_flush(ab, &elem->data); + list_del(&elem->list); + kfree(elem); + } + return; free_desc: dma_free_noncoherent(ab->dev, rx_tid->unaligned_size, From 6a0832c986f14518645714be87724f13e9d59a95 Mon Sep 17 00:00:00 2001 From: Kamil Bienkiewicz Date: Fri, 28 Aug 2026 02:51:26 +0200 Subject: [PATCH 0338/2126] wifi: ath12k: advertise AP_VLAN interface mode for IPQ5332 Only the two QCN9274 hw_params advertise NL80211_IFTYPE_AP_VLAN; the IPQ5332 entry does not. ath12k sets SW_CRYPTO_CONTROL, so mac80211 does not add the mode on the driver's behalf either -- ieee80211_alloc_hw_nm() only does that for drivers that leave SW_CRYPTO_CONTROL clear, leaving the declaration to drivers that can transmit software-encrypted frames. AP/VLAN is therefore absent from the wiphy, and creating an AP_VLAN interface without NL80211_ATTR_4ADDR is rejected by cfg80211_iftype_allowed(): nl80211: Failed to create interface : -95 (Operation not supported) That is the path hostapd uses for dynamic per-station VLANs, in hostapd_vlan_if_add(). The 4-address (WDS) case is not affected, as cfg80211_iftype_allowed() short-circuits it on WIPHY_FLAG_4ADDR_AP, which mac80211 sets unconditionally at alloc time. The QCN9274 entries already declare AP_VLAN, and the transmit path is shared Wi-Fi 7 code with no per-chip or per-bus gating, so IPQ5332 can deliver it as well. AP_VLAN is a software interface type, so no interface combination changes are needed. On a mixed-bus single-wiphy group the effect is wider still, since ath12k_mac_get_ifmodes() intersects interface_modes across all radios: one IPQ5332 masks AP_VLAN for the QCN9274 radios too. Advertise AP_VLAN on IPQ5332 as QCN9274 does. With the mode advertised, a non-4addr AP_VLAN interface can be created on an AP interface of an IPQ5332 + 2x QCN9274 single-wiphy group: # iw dev phy0.0-ap0 interface add tvlan0 type __ap_vlan # iw dev tvlan0 info Interface tvlan0 ifindex 19 wdev 0x9 addr 00:03:7f:12:0b:0b type AP/VLAN wiphy 0 Radios: 0 1 2 RADIUS-assigned dynamic VLANs were not exercised end to end. Tested-on: IPQ5332 hw1.0 AHB WLAN.WBE.1.6-01270-QCAHKSWPL_SILICONZ-1 Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Kamil Bienkiewicz Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260828005126.1685832-1-perceivalpercy@gmail.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/hw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index 7b86f324b2e6..a20c21807344 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -664,7 +664,8 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | - BIT(NL80211_IFTYPE_MESH_POINT), + BIT(NL80211_IFTYPE_MESH_POINT) | + BIT(NL80211_IFTYPE_AP_VLAN), .supports_monitor = true, .supports_cong_ctrl_max_msdus = true, From 958287de1c1e373e634a5751d74e94bb0ad94ad1 Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Wed, 19 Aug 2026 09:43:16 +0800 Subject: [PATCH 0339/2126] wifi: ath12k: use kernel types instead of userspace stdint types Replace the userspace stdint types uint64_t/uint8_t with the kernel types u64/u8 to conform to the surrounding ath12k code, which uses the kernel types everywhere else. No functional changes, compile tested only. Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260819-ath12k-cleanup-userspace-types-v1-1-161a1e8910f5@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/ce.c | 2 +- drivers/net/wireless/ath/ath12k/dp.c | 2 +- drivers/net/wireless/ath/ath12k/mac.c | 2 +- drivers/net/wireless/ath/ath12k/wifi7/hal_tx.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/ce.c b/drivers/net/wireless/ath/ath12k/ce.c index 67bbc6d8d0c9..c99e915e3885 100644 --- a/drivers/net/wireless/ath/ath12k/ce.c +++ b/drivers/net/wireless/ath/ath12k/ce.c @@ -269,7 +269,7 @@ static void ath12k_ce_srng_msi_ring_params_setup(struct ath12k_base *ab, u32 ce_ ath12k_hif_get_ce_msi_idx(ab, ce_id, &msi_data_idx); ring_params->msi_addr = addr_lo; - ring_params->msi_addr |= (dma_addr_t)(((uint64_t)addr_hi) << 32); + ring_params->msi_addr |= (dma_addr_t)(((u64)addr_hi) << 32); ring_params->msi_data = (msi_data_idx % msi_data_count) + msi_data_start; ring_params->flags |= HAL_SRNG_FLAGS_MSI_INTR; } diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index f9b37d75956d..ef9601152f81 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -224,7 +224,7 @@ static void ath12k_dp_srng_msi_setup(struct ath12k_base *ab, ath12k_hif_get_msi_address(ab, &addr_lo, &addr_hi); ring_params->msi_addr = addr_lo; - ring_params->msi_addr |= (dma_addr_t)(((uint64_t)addr_hi) << 32); + ring_params->msi_addr |= (dma_addr_t)(((u64)addr_hi) << 32); ring_params->msi_data = (msi_group_number % msi_data_count) + msi_data_start; ring_params->flags |= HAL_SRNG_FLAGS_MSI_INTR; diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 879f5ad80921..384dea69c178 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -3517,7 +3517,7 @@ static void ath12k_peer_assoc_h_eht(struct ath12k *ar, IEEE80211_EHT_MCS_NSS_RX)); } - max_nss = min(max_nss, (uint8_t)eht_nss); + max_nss = min(max_nss, (u8)eht_nss); arg->peer_nss = min(link_sta->rx_nss, max_nss); diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_tx.c index eeabe9db776e..def540529872 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_tx.c @@ -36,7 +36,7 @@ void ath12k_wifi7_hal_tx_cmd_desc_setup(struct ath12k_base *ab, tcl_cmd->buf_addr_info.info0 = le32_encode_bits(ti->paddr, BUFFER_ADDR_INFO0_ADDR); tcl_cmd->buf_addr_info.info1 = - le32_encode_bits(((uint64_t)ti->paddr >> HAL_ADDR_MSB_REG_SHIFT), + le32_encode_bits(((u64)ti->paddr >> HAL_ADDR_MSB_REG_SHIFT), BUFFER_ADDR_INFO1_ADDR); tcl_cmd->buf_addr_info.info1 |= le32_encode_bits((ti->rbm_id), BUFFER_ADDR_INFO1_RET_BUF_MGR) | From 507478f6f93864978a399173d4f54c8a987c8235 Mon Sep 17 00:00:00 2001 From: Linkai Gong Date: Tue, 11 Aug 2026 10:05:23 +0800 Subject: [PATCH 0340/2126] wifi: ath12k: clear dangling channel pointers on error paths On failure, ath12k_mac_setup_channels_rates() frees band channel arrays but leaves the pointers set, or clears the wrong band after a copy-paste typo (6 GHz free paired with a 2 GHz NULL). Clear the matching sbands[].channels pointer after each kfree(). Compile tested only. Signed-off-by: Linkai Gong Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260811020523.387433-1-gonglinkai@kylinos.cn Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/mac.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 384dea69c178..347bdea9b9ec 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -14294,6 +14294,7 @@ static int ath12k_mac_setup_channels_rates(struct ath12k *ar, sizeof(ath12k_6ghz_channels), GFP_KERNEL); if (!channels) { kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); + ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; return -ENOMEM; } @@ -14344,7 +14345,9 @@ static int ath12k_mac_setup_channels_rates(struct ath12k *ar, GFP_KERNEL); if (!channels) { kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); + ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); + ar->mac.sbands[NL80211_BAND_6GHZ].channels = NULL; return -ENOMEM; } @@ -14384,7 +14387,7 @@ static int ath12k_mac_setup_channels_rates(struct ath12k *ar, kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); - ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; + ar->mac.sbands[NL80211_BAND_6GHZ].channels = NULL; kfree(channels); band->channels = NULL; return ret; From 4de5a8a0edddc453f1a4c93b6d9f09013a23b72e Mon Sep 17 00:00:00 2001 From: Rameshkumar Sundaram Date: Thu, 13 Aug 2026 23:09:20 +0530 Subject: [PATCH 0341/2126] wifi: ath12k: fix DMA unwind for ext MSDU descriptor retry ath12k_wifi7_dp_tx() maps the original MSDU into ti.paddr and stores the address in skb_cb->paddr. When an extended MSDU descriptor is used, the function later maps the ext descriptor and overwrites ti.paddr and ti.data_len with the ext-desc DMA address and length. If TCL ring allocation then fails, the error path first unmaps the ext-desc DMA address from skb_cb->paddr_ext_desc. It then falls through to fail_unmap_dma, which uses ti.paddr/ti.data_len for the original MSDU unmap. At that point ti.paddr still refers to the ext-desc mapping, so the ext descriptor is unmapped twice and the original MSDU mapping is left mapped. Fix the original MSDU unwind to use skb_cb->paddr and skb->len instead of ti.paddr/ti.data_len. The ti fields cannot be used after the ext descriptor is mapped because they are intentionally reused for the buffer submitted to TCL. Also clear skb_cb->paddr_ext_desc after the ext-desc unmap so a TCL ring retry cannot observe stale ext-desc DMA state from the previous attempt. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Fixes: 37a068fc9dc4 ("wifi: ath12k: Handle error cases during extended skb allocation") Signed-off-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260813-ext-msdu-fix-v1-1-c5e80ccd061a@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 587d58eeccfa..0dcb566fd182 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -449,15 +449,17 @@ skip_htt_meta: return 0; fail_unmap_dma_ext: - if (skb_cb->paddr_ext_desc) + if (skb_cb->paddr_ext_desc) { dma_unmap_single(dp->dev, skb_cb->paddr_ext_desc, skb_ext_desc->len, DMA_TO_DEVICE); + skb_cb->paddr_ext_desc = 0; + } fail_free_ext_skb: kfree_skb(skb_ext_desc); fail_unmap_dma: - dma_unmap_single(dp->dev, ti.paddr, ti.data_len, DMA_TO_DEVICE); + dma_unmap_single(dp->dev, skb_cb->paddr, skb->len, DMA_TO_DEVICE); fail_remove_tx_buf: ath12k_dp_tx_release_txbuf(dp, tx_desc, pool_id); From 6c40719489c8d799798989b15bc07b0700c132f8 Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Tue, 18 Aug 2026 09:44:48 +0800 Subject: [PATCH 0342/2126] wifi: ath12k: fix stale skb pointers after aligned TX payload shift ath12k_wifi7_dp_tx() caches hdr, eth, and skb_cb from the skb before calling ath12k_dp_tx_align_payload(). That function may shift skb->data in place (when headroom or tailroom is sufficient) or reallocate the buffer entirely via skb_realloc_headroom(), freeing the original skb. In either case hdr, eth, and skb_cb are left pointing into stale memory. After alignment, only hdr is refreshed, leaving eth and skb_cb stale. skb_cb is written immediately after (storing DMA addresses), and eth is re-read on every TCL ring retry via the tcl_ring_sel goto, so both accesses are use-after-free or stale-pointer bugs depending on which alignment path was taken. Refresh eth (conditionally, to preserve the encap-mode distinction) and skb_cb alongside hdr after ath12k_dp_tx_align_payload() returns, so all three point into the live skb for all subsequent accesses. Issue found during code review, compile tested only. Fixes: 38055789d151 ("wifi: ath12k: use 128 bytes aligned iova in transmit path for WCN7850") Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260818-ath12k-uaf-for-aligned-tx-v1-1-d6ae195b15e7@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 0dcb566fd182..7ea49bcb0f47 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -313,10 +313,15 @@ tcl_ring_sel: goto map; } - /* hdr is pointing to a wrong place after alignment, - * so refresh it for later use. + /* + * The payload may have been shifted or even the entire buffer may have + * been reallocated for alignment. In that case, hdr, eth and skb_cb + * are stale pointers. Refresh them now for later dereference. */ hdr = (void *)skb->data; + if (eth) + eth = (struct ethhdr *)skb->data; + skb_cb = ATH12K_SKB_CB(skb); } map: ti.paddr = dma_map_single(dp->dev, skb->data, skb->len, DMA_TO_DEVICE); From 979ecb88ed3528e08dd7f87b90b029374226ca84 Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Tue, 18 Aug 2026 10:03:41 +0800 Subject: [PATCH 0343/2126] wifi: ath12k: fix truncated TX buffer DMA address in MSDU ext descriptor ath12k_wifi7_hal_tx_cmd_ext_desc_setup() programs the low 32 bits of the TX buffer physical address into HAL_TX_MSDU_EXT_INFO0_BUF_PTR_LO but hardcodes the high bits field HAL_TX_MSDU_EXT_INFO1_BUF_PTR_HI to 0x0. dma_addr_t is 64-bit on platforms with CONFIG_ARCH_DMA_ADDR_T_64BIT, so whenever a TX buffer is mapped above the 4 GB boundary the upper bits of paddr are dropped and the firmware is handed a truncated address, leading to potential TX failures. Write the upper bits of paddr into BUF_PTR_HI to fix this issue. Issue found during code review, compile tested only. Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260818-ath12k-truncated-tx-dma-addr-v1-1-ead978969371@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 7ea49bcb0f47..7c12dba4cc51 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -63,7 +63,7 @@ ath12k_wifi7_hal_tx_cmd_ext_desc_setup(struct ath12k_base *ab, { tcl_ext_cmd->info0 = le32_encode_bits(ti->paddr, HAL_TX_MSDU_EXT_INFO0_BUF_PTR_LO); - tcl_ext_cmd->info1 = le32_encode_bits(0x0, + tcl_ext_cmd->info1 = le32_encode_bits((u64)ti->paddr >> HAL_ADDR_MSB_REG_SHIFT, HAL_TX_MSDU_EXT_INFO1_BUF_PTR_HI) | le32_encode_bits(ti->data_len, HAL_TX_MSDU_EXT_INFO1_BUF_LEN); From 12ca935af2e68447e9218a615ebbb5ff7faf1554 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Wed, 19 Aug 2026 16:32:14 +0530 Subject: [PATCH 0344/2126] wifi: ath12k: Free allocated CE IRQs on request_irq() failure When CE IRQ configuration fails, the driver does not release all IRQs that were successfully requested before the failure. This can leak IRQ resources during probe failure. Free the previously requested CE IRQs before returning from the error path to ensure that partially initialized IRQ resources are properly cleaned up during probe failure. Factor out the CE IRQ cleanup into a helper to reuse the cleanup logic during both error handling and driver teardown. Also free CE IRQs when external IRQ configuration fails, before returning from the error path. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Aaradhana Sahu Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819110215.2485514-2-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/pci.c | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c index 6441927b5382..1525e6866cf4 100644 --- a/drivers/net/wireless/ath/ath12k/pci.c +++ b/drivers/net/wireless/ath/ath12k/pci.c @@ -313,6 +313,19 @@ static void ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on) ath12k_mhi_set_mhictrl_reset(ab); } +static void ath12k_pci_free_ce_irq(struct ath12k_base *ab, int num_ce) +{ + int i, irq_idx; + + for (i = 0; i < num_ce; i++) { + if (ath12k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) + continue; + + irq_idx = ATH12K_PCI_IRQ_CE0_OFFSET + i; + free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]); + } +} + static void ath12k_pci_free_ext_irq(struct ath12k_base *ab) { int i, j; @@ -330,15 +343,7 @@ static void ath12k_pci_free_ext_irq(struct ath12k_base *ab) static void ath12k_pci_free_irq(struct ath12k_base *ab) { - int i, irq_idx; - - for (i = 0; i < ab->hw_params->ce_count; i++) { - if (ath12k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) - continue; - irq_idx = ATH12K_PCI_IRQ_CE0_OFFSET + i; - free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]); - } - + ath12k_pci_free_ce_irq(ab, ab->hw_params->ce_count); ath12k_pci_free_ext_irq(ab); } @@ -671,6 +676,8 @@ static int ath12k_pci_config_irq(struct ath12k_base *ab) if (ret) { ath12k_err(ab, "failed to request irq %d: %d\n", irq_idx, ret); + + ath12k_pci_free_ce_irq(ab, i); return ret; } @@ -681,8 +688,10 @@ static int ath12k_pci_config_irq(struct ath12k_base *ab) } ret = ath12k_pci_ext_irq_config(ab); - if (ret) + if (ret) { + ath12k_pci_free_ce_irq(ab, ab->hw_params->ce_count); return ret; + } return 0; } From 9a78703ec4a895bd2e99bf43bd18d76683126c19 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Wed, 19 Aug 2026 16:32:15 +0530 Subject: [PATCH 0345/2126] wifi: ath12k: Free allocated external IRQs on request_irq() failure When external IRQ configuration fails, the driver does not release all IRQs that were successfully requested before the failure. This can leak IRQ resources during probe failure. Free previously requested external IRQs when external IRQ configuration fails. Also remove the NAPI instance with netif_napi_del() before freeing the associated netdev to properly clean up the NAPI resources. Store the IRQ number only after request_irq() succeeds to avoid recording an IRQ that was not successfully requested. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Aaradhana Sahu Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819110215.2485514-3-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/pci.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c index 1525e6866cf4..af0e882fd0b5 100644 --- a/drivers/net/wireless/ath/ath12k/pci.c +++ b/drivers/net/wireless/ath/ath12k/pci.c @@ -326,11 +326,11 @@ static void ath12k_pci_free_ce_irq(struct ath12k_base *ab, int num_ce) } } -static void ath12k_pci_free_ext_irq(struct ath12k_base *ab) +static void ath12k_pci_free_ext_irq(struct ath12k_base *ab, int num_ext_irq_grp) { int i, j; - for (i = 0; i < ATH12K_EXT_IRQ_GRP_NUM_MAX; i++) { + for (i = 0; i < num_ext_irq_grp; i++) { struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; for (j = 0; j < irq_grp->num_irq; j++) @@ -344,7 +344,7 @@ static void ath12k_pci_free_ext_irq(struct ath12k_base *ab) static void ath12k_pci_free_irq(struct ath12k_base *ab) { ath12k_pci_free_ce_irq(ab, ab->hw_params->ce_count); - ath12k_pci_free_ext_irq(ab); + ath12k_pci_free_ext_irq(ab, ATH12K_EXT_IRQ_GRP_NUM_MAX); } static void ath12k_pci_ce_irq_enable(struct ath12k_base *ab, u16 ce_id) @@ -600,8 +600,6 @@ static int ath12k_pci_ext_irq_config(struct ath12k_base *ab) irq = ath12k_pci_get_msi_irq(ab->dev, vector); - ab->irq_num[irq_idx] = irq; - ath12k_dbg(ab, ATH12K_DBG_PCI, "irq:%d group:%d\n", irq, i); @@ -612,22 +610,24 @@ static int ath12k_pci_ext_irq_config(struct ath12k_base *ab) if (ret) { ath12k_err(ab, "failed request irq %d: %d\n", vector, ret); - goto fail_request; + + for (n = 0; n < j; n++) + free_irq(ab->irq_num[irq_grp->irqs[n]], irq_grp); + + netif_napi_del(&ab->ext_irq_grp[i].napi); + free_netdev(ab->ext_irq_grp[i].napi_ndev); + goto fail_allocate; } + + ab->irq_num[irq_idx] = irq; } ath12k_pci_ext_grp_disable(irq_grp); } return 0; -fail_request: - /* i ->napi_ndev was properly allocated. Free it also */ - i += 1; fail_allocate: - for (n = 0; n < i; n++) { - irq_grp = &ab->ext_irq_grp[n]; - free_netdev(irq_grp->napi_ndev); - } + ath12k_pci_free_ext_irq(ab, i); return ret; } From 69b2d06dafa4a61b718704d655dd370ba660052a Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Fri, 28 Aug 2026 14:55:34 +0800 Subject: [PATCH 0346/2126] wifi: ath12k: preserve PPDU state across monitor status buffers A monitor PPDU may span multiple status buffers. However, __ath12k_wifi7_dp_mon_process_ring() clears mon_ppdu_info before processing every buffer. As a result, continuation buffers lose PPDU state collected from earlier buffers, including ppdu_id and PHY metadata. This can cause monitor RX processing to fail when ath12k_wifi7_dp_rx_mon_dest_process() observes a PPDU ID mismatch between status and destination rings, preventing MSDUs from being delivered. It can also produce incomplete EHT metadata that triggers warnings from mac80211: Rate marked as an EHT rate but data is invalid: MCS:0, NSS:0 ath12k_wifi7_dp_mon_srng_process() already tracks status TLV continuations via ppdu_continuation. Apply the same logic here and only reinitialize mon_ppdu_info when starting a new PPDU. mon_ppdu_info persists across ar->monitor_started transitions. If monitor mode stops while a PPDU is mid-continuation, ppdu_continuation stays set and could leak into the next monitor session. Reset it when monitor mode starts. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 78d3d907d0f1 ("wifi: ath12k: add support to reap and process monitor status ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Tamizh Chelvam Raja Link: https://patch.msgid.link/20260828065534.1537-1-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/mac.c | 7 ++++++ .../net/wireless/ath/ath12k/wifi7/dp_mon.c | 23 +++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 347bdea9b9ec..d4116ba0da08 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -1506,6 +1506,13 @@ static int ath12k_mac_monitor_start(struct ath12k *ar) return ret; } + /* + * A previous monitor session may have stopped mid-PPDU, leaving + * ppdu_continuation set. Clear it so the first status buffer of + * this session is not merged with stale state from before. + */ + ar->dp.mon_data.mon_ppdu_info.ppdu_continuation = false; + ar->monitor_started = true; ar->num_started_vdevs++; diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c index 016b0c38e51e..ded7d56cd79b 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c @@ -3211,18 +3211,23 @@ __ath12k_wifi7_dp_mon_process_ring(struct ath12k *ar, int mac_id, goto exit; while ((skb = __skb_dequeue(&skb_list))) { - memset(ppdu_info, 0, sizeof(*ppdu_info)); - ppdu_info->peer_id = HAL_INVALID_PEERID; + if (!ppdu_info->ppdu_continuation) + ath12k_wifi7_dp_mon_rx_memset_ppdu_info(ppdu_info); hal_status = ath12k_wifi7_dp_mon_parse_rx_dest(&ar->dp, pmon, skb); - if (ar->monitor_started && - pmon->mon_ppdu_status == DP_PPDU_STATUS_START && - hal_status == HAL_TLV_STATUS_PPDU_DONE) { - rx_mon_stats->status_ppdu_done++; - pmon->mon_ppdu_status = DP_PPDU_STATUS_DONE; - ath12k_wifi7_dp_rx_mon_dest_process(ar, mac_id, *budget, napi); - pmon->mon_ppdu_status = DP_PPDU_STATUS_START; + if (hal_status == HAL_TLV_STATUS_PPDU_DONE) { + ppdu_info->ppdu_continuation = false; + if (ar->monitor_started && + pmon->mon_ppdu_status == DP_PPDU_STATUS_START) { + rx_mon_stats->status_ppdu_done++; + pmon->mon_ppdu_status = DP_PPDU_STATUS_DONE; + ath12k_wifi7_dp_rx_mon_dest_process(ar, mac_id, + *budget, napi); + pmon->mon_ppdu_status = DP_PPDU_STATUS_START; + } + } else { + ppdu_info->ppdu_continuation = true; } dev_kfree_skb_any(skb); From 8342c68435dd34b1ecd65b02fff9745cadab2616 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Tue, 8 Sep 2026 11:54:29 -0400 Subject: [PATCH 0347/2126] selftests: net: csum: filter packets by source address and port Add source address and port verification in recv_verify_packet_* and recv_udp: non-matching packets are skipped. The receiver reads from PF_PACKET and UDP sockets to verify incoming packets to test hardware checksum offload. It did not validate the packet source address or source port. During tests expecting an invalid checksum (-E) or zero checksum (-Z), background packets can fail the test. For -Z, build_packet_udp chooses a specific source port that causes the checksum to sum to zero. When running in receive-only mode (-R), call build_packet in do_rx to compute the expected source port so that source port filtering can be applied to -Z as well. Also - add an inter-packet delay to avoid drops from bursts. - remove a comment that is no longer correct. Fixes: 91a7de85600d ("selftests/net: add csum offload test") Signed-off-by: Willem de Bruijn Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908155537.813889-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/csum.c | 55 +++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/lib/csum.c b/tools/testing/selftests/net/lib/csum.c index e28884ce3ab3..ad960e07e31b 100644 --- a/tools/testing/selftests/net/lib/csum.c +++ b/tools/testing/selftests/net/lib/csum.c @@ -2,8 +2,7 @@ /* Test hardware checksum offload: Rx + Tx, IPv4 + IPv6, TCP + UDP. * - * The test runs on two machines to exercise the NIC. For this reason it - * is not integrated in kselftests. + * The test runs on two machines to exercise the NIC. * * CMD=$((./csum -[46] -[tu] -S $SADDR -D $DADDR -[RT] -r 1 $EXTRA_ARGS)) * @@ -236,7 +235,8 @@ static void *build_packet_udp(void *_uh) uh->source = 0; uh->source = checksum(uh, IPPROTO_UDP, sizeof(*uh) + cfg_payload_len); - fprintf(stderr, "tx: changing sport: %hu -> %hu\n", + fprintf(stderr, "%s: changing sport: %hu -> %hu\n", + cfg_do_tx ? "tx" : "rx", cfg_port_src, ntohs(uh->source)); cfg_port_src = ntohs(uh->source); } @@ -249,7 +249,8 @@ static void *build_packet_udp(void *_uh) if (cfg_bad_csum) uh->check = ~uh->check; - fprintf(stderr, "tx: sending checksum: 0x%x\n", uh->check); + if (cfg_do_tx) + fprintf(stderr, "tx: sending checksum: 0x%x\n", uh->check); return uh + 1; } @@ -571,15 +572,36 @@ static int recv_prepare_packet(void) static int recv_udp(int fd) { static char buf[MAX_PAYLOAD_LEN]; + struct sockaddr_storage addr; + socklen_t addrlen; int ret, count = 0; while (1) { - ret = recv(fd, buf, sizeof(buf), MSG_DONTWAIT); + addrlen = sizeof(addr); + ret = recvfrom(fd, buf, sizeof(buf), MSG_DONTWAIT, + (struct sockaddr *)&addr, &addrlen); if (ret == -1 && errno == EAGAIN) break; if (ret == -1) error(1, errno, "recv r"); + if (cfg_family == PF_INET) { + struct sockaddr_in *sin = (void *)&addr; + + if (sin->sin_addr.s_addr != cfg_saddr4.sin_addr.s_addr) + continue; + if (sin->sin_port != htons(cfg_port_src)) + continue; + } else { + struct sockaddr_in6 *sin6 = (void *)&addr; + + if (memcmp(&sin6->sin6_addr, &cfg_saddr6.sin6_addr, + sizeof(sin6->sin6_addr))) + continue; + if (sin6->sin6_port != htons(cfg_port_src)) + continue; + } + fprintf(stderr, "rx: udp: len=%u\n", ret); count++; } @@ -620,6 +642,9 @@ static int recv_verify_packet_tcp(void *th, int len) if (len < sizeof(*tcph) || tcph->dest != htons(cfg_port_dst)) return -1; + if (tcph->source != htons(cfg_port_src)) + return -1; + return recv_verify_csum(th, len, ntohs(tcph->source), tcph->check); } @@ -647,6 +672,9 @@ static int recv_verify_packet_udp(void *th, int len) return recv_verify_packet_udp_encap(udph + 1, len - sizeof(*udph)); + if (udph->source != htons(cfg_port_src)) + return -1; + return recv_verify_csum(th, len, ntohs(udph->source), udph->check); } @@ -659,6 +687,9 @@ static int recv_verify_packet_ipv4(void *nh, int len) if (len < sizeof(*iph) || iph->protocol != proto) return -1; + if (iph->saddr != cfg_saddr4.sin_addr.s_addr) + return -1; + ip_len = ntohs(iph->tot_len); if (ip_len > len || ip_len < sizeof(*iph)) return -1; @@ -680,6 +711,9 @@ static int recv_verify_packet_ipv6(void *nh, int len) if (len < sizeof(*ip6h) || ip6h->nexthdr != proto) return -1; + if (memcmp(&ip6h->saddr, &cfg_saddr6.sin6_addr, sizeof(ip6h->saddr))) + return -1; + payload_len = ntohs(ip6h->payload_len); if (payload_len > len - sizeof(*ip6h)) return -1; @@ -940,6 +974,9 @@ static void do_tx(void) cfg_payload_len = rand() % MAX_PAYLOAD_LEN; buf = build_packet(_buf, sizeof(_buf), &len); } + + /* avoid bursting */ + usleep(20); } if (close(fd)) @@ -952,6 +989,14 @@ static void do_rx(int fdp, int fdr) long tleft, tstop; struct pollfd pfd; + if (!cfg_do_tx && cfg_zero_sum) { + static char _buf[MAX_HEADER_LEN + MAX_PAYLOAD_LEN]; + int len; + + /* calculate source port that causes csum to add up to zero */ + build_packet(_buf, sizeof(_buf), &len); + } + tstop = gettimeofday_ms() + cfg_timeout_ms; tleft = cfg_timeout_ms; From 3929f55da21fb76d931f464c71d2fd27762ef7d8 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 8 Sep 2026 11:19:56 -0700 Subject: [PATCH 0348/2126] selftests: drv-net: warn if LOCAL_V6 has DAD or not kept on link down napi_id.py intermittently fails to start its helper on Intel and Google HW runners: CMD: /srv/netdev/drivers/net/napi_id_helper 3001::1 37569 EXIT: 1 STDERR: bind failed: Cannot assign requested address Either keep_addr_on_down is not set or more likely the address is configured without nodad. Having to make sure that all tests always wait for DAD after impacting the link would be a whack-a-mole so we expect the env to have nodad and keep_addr_on_down set. Warn about both while validating the environment, and document this. We could fail completely but most tests don't impact the link so for quick local testing it'd be annoying to have to apply the settings. I hope the warninging stikes the right balance. Link: https://patch.msgid.link/20260908181956.1357684-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/README.rst | 9 +++++++++ .../selftests/drivers/net/lib/py/env.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tools/testing/selftests/drivers/net/README.rst b/tools/testing/selftests/drivers/net/README.rst index c6bed9a985bc..3fe49bce4f3a 100644 --- a/tools/testing/selftests/drivers/net/README.rst +++ b/tools/testing/selftests/drivers/net/README.rst @@ -70,6 +70,15 @@ LOCAL_V4, LOCAL_V6, REMOTE_V4, REMOTE_V6 Local and remote endpoint IP addresses. +Tests reconfigure the device freely, including taking the link down, and +expect the addresses to work immediately afterwards. IPv6 needs help:: + + ip -6 address add 2001:db8:1::1/64 dev eth0 nodad + sysctl -w net.ipv6.conf.eth0.keep_addr_on_down=1 + +Without those the address is flushed when the link goes down, or spends +a second unusable while waiting for DAD to finish. + LOCAL_PREFIX_V6 ~~~~~~~~~~~~~~~ diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py index 25903f580b40..6262080a8bf4 100644 --- a/tools/testing/selftests/drivers/net/lib/py/env.py +++ b/tools/testing/selftests/drivers/net/lib/py/env.py @@ -239,6 +239,25 @@ class NetDrvEpEnv(NetDrvEnvBase): if missing: raise Exception("Invalid environment, missing configuration:", missing, "Please see tools/testing/selftests/drivers/net/README.rst") + if "LOCAL_V6" in self.env: + self._check_v6_env() + + def _check_v6_env(self): + """Tests bind() to LOCAL_V6 and bounce the link, it must survive both.""" + ifname, addr = self.env["NETIF"], self.env["LOCAL_V6"] + + def _keep_addr(scope): + with open(f"/proc/sys/net/ipv6/conf/{scope}/keep_addr_on_down", + encoding="utf-8") as fp: + return int(fp.read()) + + # 'all' wins when non-zero, see addrconf_ifdown() + if (_keep_addr("all") or _keep_addr(ifname)) <= 0: + ksft_pr(f"WARN: net.ipv6.conf.{ifname}.keep_addr_on_down not set") + + dev = ip(f"-6 address show dev {ifname} to {addr}", json=True) + if not (dev and dev[0]["addr_info"][0].get("nodad")): + ksft_pr(f"WARN: LOCAL_V6 {addr} not configured with nodad") def resolve_remote_ifc(self): v4 = v6 = None From d26840324690f6438beface4b4a03ef10a014922 Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Tue, 8 Sep 2026 15:03:24 +0100 Subject: [PATCH 0349/2126] netdevsim: print IPsec salt/key in network byte order nsim_sa.key[] and nsim_sa.salt hold raw key material in network byte order, but are typed as plain u32 and printed with "%08x" in the debugfs read handler. This prints host-endian, so output differs between little- and big-endian hosts for the same key: little-endian: salt=0x61626364 key=0x34333231 38373635 32313039 36353433 big-endian: salt=0x64636261 key=0x31323334 35363738 39303132 33343536 This breaks selftests/net/rtnetlink.sh's ipsec_offload subtest on big-endian (e.g. s390x), which hardcodes the little-endian output. Retype key[]/salt to __be32, matching ipaddr[], and convert with be32_to_cpu() before printing. Output is now network-order on every host, independent of endianness. A similar fix was proposed in 2022 but kept the u32 typing, so sparse couldn't validate the added ntohl() calls and it stalled in review. Retyping first avoids that problem. `make C=2` on netdevsim reports the same zero warnings as before this change. Selftest update follows in the next patch. Cc: stable+noautosel@kernel.org # never worked Reported-by: Kleber Sacilotto de Souza Link: https://lore.kernel.org/netdev/20220308135106.890270-1-kleber.souza@canonical.com/ Signed-off-by: Andrei Gherzan Link: https://patch.msgid.link/20260908140325.13367-2-andrei.gherzan@canonical.com Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/ipsec.c | 10 +++++----- drivers/net/netdevsim/netdevsim.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/netdevsim/ipsec.c b/drivers/net/netdevsim/ipsec.c index 36a1be4923d6..5722837bcda3 100644 --- a/drivers/net/netdevsim/ipsec.c +++ b/drivers/net/netdevsim/ipsec.c @@ -50,11 +50,11 @@ static ssize_t nsim_dbg_netdev_ops_read(struct file *filp, p += scnprintf(p, bufsize - (p - buf), "sa[%i] spi=0x%08x proto=0x%x salt=0x%08x crypt=%d\n", i, be32_to_cpu(sap->xs->id.spi), - sap->xs->id.proto, sap->salt, sap->crypt); + sap->xs->id.proto, be32_to_cpu(sap->salt), sap->crypt); p += scnprintf(p, bufsize - (p - buf), "sa[%i] key=0x%08x %08x %08x %08x\n", - i, sap->key[0], sap->key[1], - sap->key[2], sap->key[3]); + i, be32_to_cpu(sap->key[0]), be32_to_cpu(sap->key[1]), + be32_to_cpu(sap->key[2]), be32_to_cpu(sap->key[3])); } len = simple_read_from_buffer(buffer, count, ppos, buf, p - buf); @@ -87,7 +87,7 @@ static int nsim_ipsec_find_empty_idx(struct nsim_ipsec *ipsec) static int nsim_ipsec_parse_proto_keys(struct net_device *dev, struct xfrm_state *xs, - u32 *mykey, u32 *mysalt) + __be32 *mykey, __be32 *mysalt) { const char aes_gcm_name[] = "rfc4106(gcm(aes))"; unsigned char *key_data; @@ -117,7 +117,7 @@ static int nsim_ipsec_parse_proto_keys(struct net_device *dev, /* 160 accounts for 16 byte key and 4 byte salt */ if (key_len > NSIM_IPSEC_AUTH_BITS) { - *mysalt = ((u32 *)key_data)[4]; + *mysalt = ((__be32 *)key_data)[4]; } else if (key_len == NSIM_IPSEC_AUTH_BITS) { *mysalt = 0; } else { diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 181b6baaba7a..eb9d684e3bcc 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -42,8 +42,8 @@ struct nsim_sa { struct xfrm_state *xs; __be32 ipaddr[4]; - u32 key[4]; - u32 salt; + __be32 key[4]; + __be32 salt; bool used; bool crypt; bool rx; From a995686117646acb094981c04a6215cef4a329f0 Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Tue, 8 Sep 2026 15:03:25 +0100 Subject: [PATCH 0350/2126] selftests: rtnetlink: update ipsec_offload expected output The previous patch ("netdevsim: print IPsec salt/key in network byte order") makes the netdevsim IPsec debugfs file print salt/key in network byte order on every host, instead of host CPU byte order. Update the expected output of kci_test_ipsec_offload() to match: the values change from the little-endian-only representation to the new, endianness-independent one. No other changes are needed since the output is now the same on every architecture. This depends on the previous driver patch: applied on its own, this change would regress the test on little-endian hosts (which still print the old host-order value), though it happens to have no effect on big-endian hosts (whose old host-order output already matched). Reported-by: Kleber Sacilotto de Souza Link: https://lore.kernel.org/netdev/20220308135106.890270-1-kleber.souza@canonical.com/ Signed-off-by: Andrei Gherzan Link: https://patch.msgid.link/20260908140325.13367-3-andrei.gherzan@canonical.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/rtnetlink.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh index ace3a99023ed..4843d474538f 100755 --- a/tools/testing/selftests/net/rtnetlink.sh +++ b/tools/testing/selftests/net/rtnetlink.sh @@ -932,11 +932,11 @@ kci_test_ipsec_offload() run_cmd diff $sysfsf - << EOF SA count=2 tx=3 sa[0] tx ipaddr=$dstip -sa[0] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1 -sa[0] key=0x34333231 38373635 32313039 36353433 +sa[0] spi=0x00000009 proto=0x32 salt=0x64636261 crypt=1 +sa[0] key=0x31323334 35363738 39303132 33343536 sa[1] rx ipaddr=$srcip -sa[1] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1 -sa[1] key=0x34333231 38373635 32313039 36353433 +sa[1] spi=0x00000009 proto=0x32 salt=0x64636261 crypt=1 +sa[1] key=0x31323334 35363738 39303132 33343536 EOF if [ $? -ne 0 ] ; then end_test "FAIL: ipsec_offload incorrect driver data" From 1c9c07d0ad69deaec73ca755ba5f3815fa493bf8 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 12:08:04 +0530 Subject: [PATCH 0351/2126] net: fix repeated word 'to' in comment Drop the second 'to', reported by checkpatch.pl as a possible repeated word. Only touches a comment, no code changes. Signed-off-by: Hemanth Selam Link: https://patch.msgid.link/20260907063804.26581-1-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/gtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 69fe5717846b..4aff23bcfdd1 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -770,7 +770,7 @@ static int gtp_parse_exthdrs(struct sk_buff *skb, unsigned int *hdrlen) * * This length field includes length field size itself (1 byte), * payload (variable length) and next type (1 byte). The extension - * header is aligned to to 4 bytes. + * header is aligned to 4 bytes. */ do { From 5bb36cd12006500fe6b96c17c2fbe870ae89eb96 Mon Sep 17 00:00:00 2001 From: Kuba Pawlak Date: Fri, 4 Sep 2026 16:03:34 +0200 Subject: [PATCH 0352/2126] selftests: net: Skip so_incoming_cpu on single-CPU systems The test requires at least two CPUs to exercise the distribution of connections between per-CPU listeners. It currently enforces this prerequisite with an assertion, causing all test cases to fail on single-vCPU systems even though no kernel functionality was tested. Report the unsupported environment as a skip instead. Check the prerequisite before setting up the network namespace so skipped tests do not make unnecessary system changes. Link: https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/2023546 Signed-off-by: Kuba Pawlak Link: https://patch.msgid.link/20260904140334.562593-1-kuba.pawlak@canonical.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/so_incoming_cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/so_incoming_cpu.c b/tools/testing/selftests/net/so_incoming_cpu.c index 4740701f1a9a..1b73442386ae 100644 --- a/tools/testing/selftests/net/so_incoming_cpu.c +++ b/tools/testing/selftests/net/so_incoming_cpu.c @@ -81,10 +81,11 @@ static int nr_client_per_server, nr_server, nr_client; FIXTURE_SETUP(so_incoming_cpu) { - setup_netns(_metadata); - nr_server = get_nprocs(); - ASSERT_LE(2, nr_server); + if (nr_server < 2) + SKIP(return, "requires at least two CPUs"); + + setup_netns(_metadata); if (NR_CLIENT_PER_SERVER_DEFAULT * nr_server < NR_PORT) nr_client_per_server = NR_CLIENT_PER_SERVER_DEFAULT; From 9a5d20a88afb5dbb27bbe9003216f06fbdfd1e38 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Fri, 4 Sep 2026 18:13:02 +0200 Subject: [PATCH 0353/2126] selftests: netfilter: use KHDR_INCLUDES in CFLAGS KHDR_INCLUDES is typically used to include headers from the kernel source directory instead of only relying on the ones from the host: they can be missing or outdated. The kselftest doc recommends assigning KHDR_INCLUDES to CFLAGS in a target Makefile. lib.mk will set KHDR_INCLUDES to "-isystem $(top_srcdir)/usr/include" if the user didn't set it, e.g. if the kernel was built in a different build directory. Other net targets have KHDR_INCLUDES added to their CFLAGS. Link: https://docs.kernel.org/dev-tools/kselftest.html#contributing-new-tests-details Signed-off-by: Matthieu Baerts (NGI0) Reviewed-by: Ilya Maximets Link: https://patch.msgid.link/20260904-net-sft-nf-khdr_includes-v1-1-92455af428e9@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/netfilter/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/netfilter/Makefile b/tools/testing/selftests/net/netfilter/Makefile index f88dd4ef8d26..df3c20c90f5d 100644 --- a/tools/testing/selftests/net/netfilter/Makefile +++ b/tools/testing/selftests/net/netfilter/Makefile @@ -2,6 +2,8 @@ top_srcdir = ../../../../.. +CFLAGS += $(KHDR_INCLUDES) + HOSTPKG_CONFIG := pkg-config MNL_CFLAGS := $(shell $(HOSTPKG_CONFIG) --cflags libmnl 2>/dev/null) MNL_LDLIBS := $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl) From f1f4394a8bb466f05acd143057fbe2c5f6ed67a4 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Fri, 4 Sep 2026 18:13:03 +0200 Subject: [PATCH 0354/2126] selftests: forwarding: use KHDR_INCLUDES in CFLAGS KHDR_INCLUDES is typically used to include headers from the kernel source directory instead of only relying on the ones from the host: they can be missing or outdated. The kselftest doc recommends assigning KHDR_INCLUDES to CFLAGS in a target Makefile. lib.mk will set KHDR_INCLUDES to "-isystem $(top_srcdir)/usr/include" if the user didn't set it, e.g. if the kernel was built in a different build directory. Other net targets have KHDR_INCLUDES added to their CFLAGS. Link: https://docs.kernel.org/dev-tools/kselftest.html#contributing-new-tests-details Signed-off-by: Matthieu Baerts (NGI0) Reviewed-by: Ilya Maximets Link: https://patch.msgid.link/20260904-net-sft-nf-khdr_includes-v1-2-92455af428e9@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/forwarding/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/Makefile b/tools/testing/selftests/net/forwarding/Makefile index bbaf4d937dd8..1bdfd141c0fb 100644 --- a/tools/testing/selftests/net/forwarding/Makefile +++ b/tools/testing/selftests/net/forwarding/Makefile @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ OR MIT +CFLAGS += $(KHDR_INCLUDES) + TEST_PROGS := \ bridge_activity_notify.sh \ bridge_fdb_learning_limit.sh \ From f5134d734770e657ba75d59645a54af362ef556f Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:04:09 -0700 Subject: [PATCH 0355/2126] netlink: specs: handshake: type the remaining key serials s32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit include/linux/key.h has "typedef int32_t key_serial_t" and commit 160f404495aa ("handshake: Fix sign of key_serial_t fields") converted x509.cert and x509.privkey to s32, but accept.peer-identity, accept.keyring and done.remote-auth were left as u32 - the same quantity typed both ways inside one family, and a generated user space struct with __s32 cert next to __u32 keyring. All three come from key_serial_t storage in net/handshake/tlshd.c (treq->th_peerid[], treq->th_keyring), and special keyrings are legitimately negative (KEY_SPEC_PROCESS_KEYRING is -2). NLA_U32 and NLA_S32 have the same length and no range check here, so the only wire effect is how the value is printed. Acked-by: Chuck Lever Reviewed-by: Asbjørn Sloth Tønnesen Link: https://patch.msgid.link/20260904190410.3864660-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/handshake.yaml | 6 +++--- net/handshake/genl.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/handshake.yaml b/Documentation/netlink/specs/handshake.yaml index ffec12b46759..9ab46da04c49 100644 --- a/Documentation/netlink/specs/handshake.yaml +++ b/Documentation/netlink/specs/handshake.yaml @@ -67,7 +67,7 @@ attribute-sets: enum: auth - name: peer-identity - type: u32 + type: s32 multi-attr: true - name: certificate @@ -79,7 +79,7 @@ attribute-sets: type: string - name: keyring - type: u32 + type: s32 - name: done attributes: @@ -93,7 +93,7 @@ attribute-sets: type: s32 - name: remote-auth - type: u32 + type: s32 multi-attr: true operations: diff --git a/net/handshake/genl.c b/net/handshake/genl.c index feac1ad063ee..58606c2a4600 100644 --- a/net/handshake/genl.c +++ b/net/handshake/genl.c @@ -21,7 +21,7 @@ static const struct nla_policy handshake_accept_nl_policy[HANDSHAKE_A_ACCEPT_HAN static const struct nla_policy handshake_done_nl_policy[HANDSHAKE_A_DONE_REMOTE_AUTH + 1] = { [HANDSHAKE_A_DONE_STATUS] = NLA_POLICY_MAX(NLA_U32, MAX_ERRNO), [HANDSHAKE_A_DONE_SOCKFD] = { .type = NLA_S32, }, - [HANDSHAKE_A_DONE_REMOTE_AUTH] = { .type = NLA_U32, }, + [HANDSHAKE_A_DONE_REMOTE_AUTH] = { .type = NLA_S32, }, }; /* Ops table for handshake */ From fd0291fad9e763c42ea908e89589c94f1a06eea5 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:04:10 -0700 Subject: [PATCH 0356/2126] netlink: specs: handshake: do not accept the handler-class sentinel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "max" is the exclusive upper bound of enum handshake_handler_class, not a class a handler can ask for, but the spec lists it as a plain entry. _init_checks() derives the policy limit from the highest entry, so the generated policy came out as NLA_POLICY_MAX(NLA_U32, 2) and handshake_nl_accept_doit() takes class 2 all the way into handshake_req_next(), which walks hn_requests under hn_lock before returning -EAGAIN instead of the -EINVAL a bad class deserves. render-max is how YNL spells this, and unlike a hand written limit it stays correct when a second handler class is added. It does change what HANDSHAKE_HANDLER_CLASS_MAX means - the highest valid class rather than one past it, as in every other Netlink/YNL family - with the count left as __HANDSHAKE_HANDLER_CLASS_MAX. The constant is uAPI, but I could not find any user space user, this constant seems to have been added for kernel's benefit. I think the risk of changing this is worth taking, having MAX with different semantics than the rest of Netlink is very confusing. Acked-by: Chuck Lever Reviewed-by: Asbjørn Sloth Tønnesen Link: https://patch.msgid.link/20260904190410.3864660-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/handshake.yaml | 3 ++- include/uapi/linux/handshake.h | 5 ++++- net/handshake/genl.c | 2 +- net/handshake/handshake-test.c | 2 +- net/handshake/request.c | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Documentation/netlink/specs/handshake.yaml b/Documentation/netlink/specs/handshake.yaml index 9ab46da04c49..0498ada2dd97 100644 --- a/Documentation/netlink/specs/handshake.yaml +++ b/Documentation/netlink/specs/handshake.yaml @@ -22,7 +22,8 @@ definitions: type: enum name: handler-class value-start: 0 - entries: [none, tlshd, max] + entries: [none, tlshd] + render-max: true - type: enum name: msg-type diff --git a/include/uapi/linux/handshake.h b/include/uapi/linux/handshake.h index d7e40f594888..f907aa082520 100644 --- a/include/uapi/linux/handshake.h +++ b/include/uapi/linux/handshake.h @@ -13,7 +13,10 @@ enum handshake_handler_class { HANDSHAKE_HANDLER_CLASS_NONE, HANDSHAKE_HANDLER_CLASS_TLSHD, - HANDSHAKE_HANDLER_CLASS_MAX, + + /* private: */ + __HANDSHAKE_HANDLER_CLASS_MAX, + HANDSHAKE_HANDLER_CLASS_MAX = (__HANDSHAKE_HANDLER_CLASS_MAX - 1) }; enum handshake_msg_type { diff --git a/net/handshake/genl.c b/net/handshake/genl.c index 58606c2a4600..26e3efec64ca 100644 --- a/net/handshake/genl.c +++ b/net/handshake/genl.c @@ -14,7 +14,7 @@ /* HANDSHAKE_CMD_ACCEPT - do */ static const struct nla_policy handshake_accept_nl_policy[HANDSHAKE_A_ACCEPT_HANDLER_CLASS + 1] = { - [HANDSHAKE_A_ACCEPT_HANDLER_CLASS] = NLA_POLICY_MAX(NLA_U32, 2), + [HANDSHAKE_A_ACCEPT_HANDLER_CLASS] = NLA_POLICY_MAX(NLA_U32, 1), }; /* HANDSHAKE_CMD_DONE - do */ diff --git a/net/handshake/handshake-test.c b/net/handshake/handshake-test.c index 3dd507470d5f..4b99acd9f9c7 100644 --- a/net/handshake/handshake-test.c +++ b/net/handshake/handshake-test.c @@ -42,7 +42,7 @@ static struct handshake_proto handshake_req_alloc_proto_2 = { }; static struct handshake_proto handshake_req_alloc_proto_3 = { - .hp_handler_class = HANDSHAKE_HANDLER_CLASS_MAX, + .hp_handler_class = __HANDSHAKE_HANDLER_CLASS_MAX, }; static struct handshake_proto handshake_req_alloc_proto_4 = { diff --git a/net/handshake/request.c b/net/handshake/request.c index cd30d54d0501..ff739ee81cb8 100644 --- a/net/handshake/request.c +++ b/net/handshake/request.c @@ -115,7 +115,7 @@ struct handshake_req *handshake_req_alloc(const struct handshake_proto *proto, return NULL; if (proto->hp_handler_class <= HANDSHAKE_HANDLER_CLASS_NONE) return NULL; - if (proto->hp_handler_class >= HANDSHAKE_HANDLER_CLASS_MAX) + if (proto->hp_handler_class > HANDSHAKE_HANDLER_CLASS_MAX) return NULL; if (!proto->hp_accept || !proto->hp_done) return NULL; From 0274de8b9fdc0d880b041588c9f08eccaadd4ca9 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:10:20 -0700 Subject: [PATCH 0357/2126] netlink: specs: dpll: add clock-quality-level to the device-get reply dpll_device_get_one() calls dpll_msg_add_clock_quality_level(), which puts DPLL_A_CLOCK_QUALITY_LEVEL into every device-get reply, dump entry and device-*-ntf of a device whose driver implements clock_quality_level_get() - mlx5 does. The &dev-attrs anchor lists 12 attributes and not this one, so struct dpll_device_get_rsp has no field for it, dpll_device_get_rsp_parse() drops it and dpll.rst does not document it. The attribute itself is correctly declared in the dpll attribute set, only the reply list was missing an entry. Missing since commit a1afb959add1 ("dpll: add clock quality level attribute and op"). Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20260904191023.3869690-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/dpll.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/netlink/specs/dpll.yaml b/Documentation/netlink/specs/dpll.yaml index cdc8c7b456df..64a45088c027 100644 --- a/Documentation/netlink/specs/dpll.yaml +++ b/Documentation/netlink/specs/dpll.yaml @@ -632,6 +632,7 @@ operations: - mode-supported - lock-status - lock-status-error + - clock-quality-level - temp - clock-id - type From 28f363015aea55fcb323b97d97bdf2e4fff0cf4d Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:10:21 -0700 Subject: [PATCH 0358/2126] netlink: specs: dpll: drop the pin-set attributes nothing implements pin-set advertises top level direction, prio and state, so the generated policy accepts them and the generated user space API grows setters for them. dpll_pin_set_from_nlattr() has cases only for FREQUENCY, PHASE_ADJUST, PARENT_DEVICE, PARENT_PIN, ESYNC_FREQUENCY and REFERENCE_SYNC - the request succeeds, does nothing and produces no extack. The three values are only actionable inside the parent-device nest, where dpll_pin_parent_device_set() handles them next to DPLL_A_PIN_PARENT_ID, which is what makes them meaningful: a pin can be registered with more than one device. Never implemented - "git log -S 'case DPLL_A_PIN_PRIO'" on dpll_netlink.c comes up empty - the spec has advertised them since commit 3badff3a25d8 ("dpll: spec: Add Netlink spec in YAML"). Note that this does change what the kernel accepts: sending one of the three now fails validation instead of being ignored. Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20260904191023.3869690-3-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/dpll.yaml | 3 --- drivers/dpll/dpll_nl.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/Documentation/netlink/specs/dpll.yaml b/Documentation/netlink/specs/dpll.yaml index 64a45088c027..93e546ba1f56 100644 --- a/Documentation/netlink/specs/dpll.yaml +++ b/Documentation/netlink/specs/dpll.yaml @@ -760,9 +760,6 @@ operations: attributes: - id - frequency - - direction - - prio - - state - parent-device - parent-pin - phase-adjust diff --git a/drivers/dpll/dpll_nl.c b/drivers/dpll/dpll_nl.c index b1ba490e72b0..3bdabbf2b931 100644 --- a/drivers/dpll/dpll_nl.c +++ b/drivers/dpll/dpll_nl.c @@ -78,9 +78,6 @@ static const struct nla_policy dpll_pin_get_dump_nl_policy[DPLL_A_PIN_ID + 1] = static const struct nla_policy dpll_pin_set_nl_policy[DPLL_A_PIN_REFERENCE_SYNC + 1] = { [DPLL_A_PIN_ID] = { .type = NLA_U32, }, [DPLL_A_PIN_FREQUENCY] = { .type = NLA_U64, }, - [DPLL_A_PIN_DIRECTION] = NLA_POLICY_RANGE(NLA_U32, 1, 2), - [DPLL_A_PIN_PRIO] = { .type = NLA_U32, }, - [DPLL_A_PIN_STATE] = NLA_POLICY_RANGE(NLA_U32, 1, 3), [DPLL_A_PIN_PARENT_DEVICE] = NLA_POLICY_NESTED(dpll_pin_parent_device_nl_policy), [DPLL_A_PIN_PARENT_PIN] = NLA_POLICY_NESTED(dpll_pin_parent_pin_nl_policy), [DPLL_A_PIN_PHASE_ADJUST] = { .type = NLA_S32, }, From f4ac7c7a846d0cea1cfa698ef41e7147e8d22bab Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:10:22 -0700 Subject: [PATCH 0359/2126] netlink: specs: dpll: pin-get has no dump filter The op doc promises "dump request with target dpll - list all the pins registered with a given dpll device" and "do request with target dpll and target pin". Neither exists. pin-get uses attribute-set: pin, so the id in both requests is DPLL_A_PIN_ID, not a device id; there is no reachable "target dpll" attribute at all (DPLL_A_PIN_PARENT_ID is in neither list). dpll_nl_pin_get_dumpit() does not look at the request, it walks dpll_pin_xa from ctx->idx and emits every registered, available pin, and there is no dump start callback to consume an id either. So the generated dpll_pin_get_dump() sends an id, gets the full list back and reports no error. Drop the id from the dump request and the two targeting claims from the doc. Present since commit 3badff3a25d8 ("dpll: spec: Add Netlink spec in YAML"). Same caveat as for pin-set: sending DPLL_A_PIN_ID in a pin-get dump now fails validation instead of being ignored. Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20260904191023.3869690-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/dpll.yaml | 11 +++-------- drivers/dpll/dpll_nl.c | 17 +++++------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Documentation/netlink/specs/dpll.yaml b/Documentation/netlink/specs/dpll.yaml index 93e546ba1f56..e2ca4df5699a 100644 --- a/Documentation/netlink/specs/dpll.yaml +++ b/Documentation/netlink/specs/dpll.yaml @@ -701,11 +701,9 @@ operations: doc: | Get list of pins and its attributes. - - dump request without any attributes given - list all the pins in the - system - - dump request with target dpll - list all the pins registered with - a given dpll device - - do request with target dpll and target pin - single pin attributes + - dump request - list all the registered, available pins in the + system, the request takes no attributes + - do request with target pin - single pin attributes attribute-set: pin flags: [admin-perm] @@ -742,9 +740,6 @@ operations: - measured-frequency dump: - request: - attributes: - - id reply: *pin-attrs - diff --git a/drivers/dpll/dpll_nl.c b/drivers/dpll/dpll_nl.c index 3bdabbf2b931..fa09b524a4a0 100644 --- a/drivers/dpll/dpll_nl.c +++ b/drivers/dpll/dpll_nl.c @@ -65,12 +65,7 @@ static const struct nla_policy dpll_pin_id_get_nl_policy[DPLL_A_PIN_TYPE + 1] = }; /* DPLL_CMD_PIN_GET - do */ -static const struct nla_policy dpll_pin_get_do_nl_policy[DPLL_A_PIN_ID + 1] = { - [DPLL_A_PIN_ID] = { .type = NLA_U32, }, -}; - -/* DPLL_CMD_PIN_GET - dump */ -static const struct nla_policy dpll_pin_get_dump_nl_policy[DPLL_A_PIN_ID + 1] = { +static const struct nla_policy dpll_pin_get_nl_policy[DPLL_A_PIN_ID + 1] = { [DPLL_A_PIN_ID] = { .type = NLA_U32, }, }; @@ -133,16 +128,14 @@ static const struct genl_split_ops dpll_nl_ops[] = { .pre_doit = dpll_pin_pre_doit, .doit = dpll_nl_pin_get_doit, .post_doit = dpll_pin_post_doit, - .policy = dpll_pin_get_do_nl_policy, + .policy = dpll_pin_get_nl_policy, .maxattr = DPLL_A_PIN_ID, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, { - .cmd = DPLL_CMD_PIN_GET, - .dumpit = dpll_nl_pin_get_dumpit, - .policy = dpll_pin_get_dump_nl_policy, - .maxattr = DPLL_A_PIN_ID, - .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP, + .cmd = DPLL_CMD_PIN_GET, + .dumpit = dpll_nl_pin_get_dumpit, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP, }, { .cmd = DPLL_CMD_PIN_SET, From 356635525f5e7c9c0c98551afb53ae7b3e93271f Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 12:10:23 -0700 Subject: [PATCH 0360/2126] MAINTAINERS: dpll: add the netlink spec get_maintainer.pl on Documentation/netlink/specs/dpll.yaml returns only the YNL and NETWORKING [GENERAL] entries, so a change to the DPLL uAPI description does not CC any of the DPLL maintainers. Ten other families (binder, dev-energymodel, ethtool, handshake, mptcp_pm, ovpn, psp, team, wireguard, rt-*) already list their spec explicitly. Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20260904191023.3869690-5-kuba@kernel.org Signed-off-by: Jakub Kicinski --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index b23fb6f2f4ef..b000853829b5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7919,6 +7919,7 @@ S: Supported F: Documentation/devicetree/bindings/dpll/dpll-device.yaml F: Documentation/devicetree/bindings/dpll/dpll-pin.yaml F: Documentation/driver-api/dpll.rst +F: Documentation/netlink/specs/dpll.yaml F: drivers/dpll/ F: include/linux/dpll.h F: include/uapi/linux/dpll.h From 6a64e9d76a794aacbe06f5a3fbf4e5d4542392f7 Mon Sep 17 00:00:00 2001 From: Alessio Faina Date: Mon, 7 Sep 2026 12:06:31 +0200 Subject: [PATCH 0361/2126] selftests/net: skip srv6_end_dt[4/6]_l3vpn_test.sh if vrftable not available In case iproute2 is older than version 5.11.0, released ~Feb 23, 2021, the vrftable support is not available and the tests contained in the following 2 test files - srv6_end_dt4_l3vpn_test.sh - srv6_end_dt6_l3vpn_test.sh are failing in some kernel backports. This is the result of one of those tests in an unsupported environment: ########################################################################## TEST SECTION: SRv6 VPN connectivity test among hosts in the same tenant ########################################################################## TEST: Hosts connectivity: hs-t100-1 -> hs-t100-2 (tenant 100) [FAIL] TEST: Hosts connectivity: hs-t100-2 -> hs-t100-1 (tenant 100) [FAIL] TEST: Hosts connectivity: hs-t200-3 -> hs-t200-4 (tenant 200) [FAIL] TEST: Hosts connectivity: hs-t200-4 -> hs-t200-3 (tenant 200) [FAIL] The test installs a route with the vrftable feature; if this feature is not available, the approach taken is to skip the test rather than failing it. Signed-off-by: Alessio Faina Reviewed-by: Andrea Mayer Link: https://patch.msgid.link/20260907100631.1923148-1-alessio.faina@canonical.com Signed-off-by: Jakub Kicinski --- .../selftests/net/srv6_end_dt4_l3vpn_test.sh | 21 +++++++++++++++++++ .../selftests/net/srv6_end_dt6_l3vpn_test.sh | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh index a649dba3cb77..037e5fe1da2a 100755 --- a/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh @@ -469,12 +469,33 @@ if [ ! -x "$(command -v ip)" ]; then exit $ksft_skip fi +test_vrftable_supp_or_ksft_skip() +{ + local nsname + + setup_ns nsname + ip netns exec "${nsname}" sh -c "echo 1 > /proc/sys/net/vrf/strict_mode" + ip -netns "${nsname}" link add vrf-100 type vrf table 100 + ip -netns "${nsname}" link set vrf-100 up + + if ! ip -netns "${nsname}" -6 route add fc00::1/128 \ + encap seg6local action End.DT4 vrftable 100 dev vrf-100 2>/dev/null; then + cleanup_ns "${nsname}" + echo "SKIP: SRv6 End.DT4 vrftable not supported" + exit "${ksft_skip}" + fi + + cleanup_ns "${nsname}" +} + modprobe vrf &>/dev/null if [ ! -e /proc/sys/net/vrf/strict_mode ]; then echo "SKIP: vrf sysctl does not exist" exit $ksft_skip fi +test_vrftable_supp_or_ksft_skip + cleanup &>/dev/null setup diff --git a/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh index e408406d8489..9a29e0d6c912 100755 --- a/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh @@ -479,12 +479,33 @@ if [ ! -x "$(command -v ip)" ]; then exit $ksft_skip fi +test_vrftable_supp_or_ksft_skip() +{ + local nsname + + setup_ns nsname + ip netns exec "${nsname}" sh -c "echo 1 > /proc/sys/net/vrf/strict_mode" + ip -netns "${nsname}" link add vrf-100 type vrf table 100 + ip -netns "${nsname}" link set vrf-100 up + + if ! ip -netns "${nsname}" -6 route add fc00::1/128 \ + encap seg6local action End.DT6 vrftable 100 dev vrf-100 2>/dev/null; then + cleanup_ns "${nsname}" + echo "SKIP: SRv6 End.DT6 vrftable not supported" + exit "${ksft_skip}" + fi + + cleanup_ns "${nsname}" +} + modprobe vrf &>/dev/null if [ ! -e /proc/sys/net/vrf/strict_mode ]; then echo "SKIP: vrf sysctl does not exist" exit $ksft_skip fi +test_vrftable_supp_or_ksft_skip + cleanup &>/dev/null setup From 42fe5a08078f6124918e72c2ae9d77fc016c4e72 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 15:24:43 +0530 Subject: [PATCH 0362/2126] i40e: fix typos in comments Fix typos in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Acked-by: Randy Dunlap Reviewed-by: Tony Nguyen Link: https://patch.msgid.link/20260907095446.27290-2-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/i40e/i40e_common.c | 2 +- drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_common.c b/drivers/net/ethernet/intel/i40e/i40e_common.c index 8dadfef2c09f..026b35e5a000 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_common.c +++ b/drivers/net/ethernet/intel/i40e/i40e_common.c @@ -676,7 +676,7 @@ int i40e_pf_reset(struct i40e_hw *hw) grst_del = FIELD_GET(I40E_GLGEN_RSTCTL_GRSTDEL_MASK, rd32(hw, I40E_GLGEN_RSTCTL)); - /* It can take upto 15 secs for GRST steady state. + /* It can take up to 15 secs for GRST steady state. * Bump it to 16 secs max to be safe. */ grst_del = grst_del * 20; diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index 3da9ec49cc74..ef9d1e78c16a 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -2614,7 +2614,7 @@ static u64 i40e_eeprom_test(struct net_device *netdev, u64 *data) netif_info(pf, hw, netdev, "eeprom test\n"); *data = i40e_diag_eeprom_test(&pf->hw); - /* forcebly clear the NVM Update state machine */ + /* forcibly clear the NVM Update state machine */ pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT; return *data; From e2700f56c33ee76d563e0566edc31a76832646eb Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 15:24:44 +0530 Subject: [PATCH 0363/2126] ice: fix typos in comments Fix typos in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Acked-by: Randy Dunlap Reviewed-by: Tony Nguyen Link: https://patch.msgid.link/20260907095446.27290-3-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice.h | 2 +- drivers/net/ethernet/intel/ice/ice_main.c | 2 +- drivers/net/ethernet/intel/ice/ice_sriov.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index db3c7015c56c..e5f940d324dc 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -1105,7 +1105,7 @@ extern const struct xdp_metadata_ops ice_xdp_md_ops; * ice_is_dual - Check if given config is multi-NAC * @hw: pointer to HW structure * - * Return: true if the device is running in mutli-NAC (Network + * Return: true if the device is running in multi-NAC (Network * Acceleration Complex) configuration variant, false otherwise * (always false for non-E825 devices). */ diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index d88835482d3a..fe47ec0ba809 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -6202,7 +6202,7 @@ ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[], * * Features that need fixing: * Cannot simultaneously enable CTAG and STAG stripping and/or insertion. - * These are mutually exlusive as the VSI context cannot support multiple + * These are mutually exclusive as the VSI context cannot support multiple * VLAN ethertypes simultaneously for stripping and/or insertion. If this * is not done, then default to clearing the requested STAG offload * settings. diff --git a/drivers/net/ethernet/intel/ice/ice_sriov.c b/drivers/net/ethernet/intel/ice/ice_sriov.c index e04de0215596..9ef1aa66fa2b 100644 --- a/drivers/net/ethernet/intel/ice/ice_sriov.c +++ b/drivers/net/ethernet/intel/ice/ice_sriov.c @@ -924,7 +924,7 @@ static void ice_sriov_remap_vectors(struct ice_pf *pf, u16 restricted_id) * is correct etc. Then disable old mapping (MSI-X and queues registers), change * MSI-X and queues, rebuild VSI and enable new mapping. * - * If it is possible (driver not binded to VF) try to remap also other VFs to + * If it is possible (driver not bound to VF) try to remap also other VFs to * linearize irqs register usage. */ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count) From 47ea470150c8f08618d9664bc2385429676339a0 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 15:24:45 +0530 Subject: [PATCH 0364/2126] ixgbevf: fix typo "enble" in comment Fix a typo in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Signed-off-by: Hemanth Selam Acked-by: Randy Dunlap Reviewed-by: Tony Nguyen Link: https://patch.msgid.link/20260907095446.27290-4-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c index 7ce46b4b4821..7eb4acf59dab 100644 --- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c @@ -3995,7 +3995,7 @@ static void ixgbevf_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, if (tx_flags & IXGBE_TX_FLAGS_CSUM) olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); - /* enble IPv4 checksum for TSO */ + /* enable IPv4 checksum for TSO */ if (tx_flags & IXGBE_TX_FLAGS_IPV4) olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); From f3056082e0846275cdddd66f458ab8292f21d157 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 15:24:46 +0530 Subject: [PATCH 0365/2126] Documentation/eth/intel: fix repeated words in comments Drop repeated words reported by checkpatch.pl. Only touches documentation text. Signed-off-by: Hemanth Selam Acked-by: Randy Dunlap Reviewed-by: Tony Nguyen Link: https://patch.msgid.link/20260907095446.27290-5-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/device_drivers/ethernet/intel/i40e.rst | 2 +- Documentation/networking/device_drivers/ethernet/intel/iavf.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/device_drivers/ethernet/intel/i40e.rst b/Documentation/networking/device_drivers/ethernet/intel/i40e.rst index 53d9d5829d69..e01f0adda3f6 100644 --- a/Documentation/networking/device_drivers/ethernet/intel/i40e.rst +++ b/Documentation/networking/device_drivers/ethernet/intel/i40e.rst @@ -692,7 +692,7 @@ queues: for each tc, @ (e.g. queues 16@0 16@16 assigns 16 queues to tc0 at offset 0 and 16 queues to tc1 at offset 16. Max total number of queues for all tcs is 64 or number of cores, whichever is lower.) -hw 1 mode channel: ‘channel’ with ‘hw’ set to 1 is a new new hardware +hw 1 mode channel: ‘channel’ with ‘hw’ set to 1 is a new hardware offload mode in mqprio that makes full use of the mqprio options, the TCs, the queue configurations, and the QoS parameters. diff --git a/Documentation/networking/device_drivers/ethernet/intel/iavf.rst b/Documentation/networking/device_drivers/ethernet/intel/iavf.rst index eb926c3bd4cd..5840569917f5 100644 --- a/Documentation/networking/device_drivers/ethernet/intel/iavf.rst +++ b/Documentation/networking/device_drivers/ethernet/intel/iavf.rst @@ -171,7 +171,7 @@ queues: for each tc, @ (e.g. queues 16@0 16@16 assigns 16 queues to tc0 at offset 0 and 16 queues to tc1 at offset 16. Max total number of queues for all tcs is 64 or number of cores, whichever is lower.) -hw 1 mode channel: ‘channel’ with ‘hw’ set to 1 is a new new hardware +hw 1 mode channel: ‘channel’ with ‘hw’ set to 1 is a new hardware offload mode in mqprio that makes full use of the mqprio options, the TCs, the queue configurations, and the QoS parameters. From 10973152f2f8f9d266e91c78abf1dca3514da775 Mon Sep 17 00:00:00 2001 From: David Yang Date: Fri, 4 Sep 2026 21:47:46 +0800 Subject: [PATCH 0366/2126] net: dsa: motorcomm: Handle degenerated blink delays The LED core defines delay_on == 0 as steady off and delay_off == 0 as steady on, which was treated as a blink in our LED driver. Fix it. Fixes: 9af9a8168213 ("net: dsa: motorcomm: Add LED support") Signed-off-by: David Yang Link: https://patch.msgid.link/20260904134752.635133-1-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/leds.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c index 7d3c0f68d8ff..87a6b9cf6068 100644 --- a/drivers/net/dsa/motorcomm/leds.c +++ b/drivers/net/dsa/motorcomm/leds.c @@ -107,6 +107,8 @@ yt921x_led_blink_set(struct yt921x_priv *priv, int port, int group, YT921X_LED_DUTY(1, 2); use_cycle = false; + } else if (!*onp || !*offp) { + return yt921x_led_force_set(priv, port, group, *onp); } else { res = yt921x_led_blink_select(priv, *onp, *offp, &cycle, &duty); if (res) From 40c578ceaeecb59c0e277d3bcf39c9af071b5592 Mon Sep 17 00:00:00 2001 From: "Jan Havran (Advantech Czech)" Date: Mon, 7 Sep 2026 15:48:16 +0200 Subject: [PATCH 0367/2126] net: dsa: mxl-gsw1xx: set SerDes NCO rate before SGMII reset gsw1xx_pcs_config() releases the SGMII shell from reset via gsw1xx_pcs_reset() and only afterwards programs NCO_CTRL to select the SerDes clock rate (1G NCO1 vs 2.5G NCO2). The chip boot loader uses the other order: NCO_CTRL -> RST_REQ -> SGMII_PHY_HWBU_CTRL (GSW145 data sheet, section 3.2.8, table 13). Program NCO_CTRL before gsw1xx_pcs_reset() to follow that order. On an Armada 7040 board driving a GSW145 whose switch comes up at 2.5G (pin strap PS_SUBTYPE_MD[2] = 1, pin LED42 / PS1 bit 14; GSW145 data sheet tables 23 and 25), a 1 Gbps SGMII link only carried traffic with this change. It matters when the rate the switch is left at - by the straps or by the boot loader - differs from the rate the driver selects, which is likely why it has not been seen before. Cc: stable+noautosel@kernel.org # never worked Signed-off-by: Jan Havran (Advantech Czech) Reviewed-by: Daniel Golle Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260907134818.16670-2-havran.jan@email.cz Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lantiq/mxl-gsw1xx.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.c b/drivers/net/dsa/lantiq/mxl-gsw1xx.c index 347e16e9fdc1..66bf7e331905 100644 --- a/drivers/net/dsa/lantiq/mxl-gsw1xx.c +++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.c @@ -352,8 +352,22 @@ static int gsw1xx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, /* mark PCS configuration as incomplete */ priv->tbi_interface = PHY_INTERFACE_MODE_NA; - if (!reconf) + if (!reconf) { + /* setup SerDes clock speed */ + if (interface == PHY_INTERFACE_MODE_2500BASEX) + nco_ctrl = GSW1XX_SGMII_2G5 | GSW1XX_SGMII_2G5_NCO2; + else + nco_ctrl = GSW1XX_SGMII_1G | GSW1XX_SGMII_1G_NCO1; + + ret = regmap_update_bits(priv->clk, GSW1XX_CLK_NCO_CTRL, + GSW1XX_SGMII_HSP_MASK | + GSW1XX_SGMII_SEL, + nco_ctrl); + if (ret) + return ret; + ret = gsw1xx_pcs_reset(priv, interface); + } if (ret) return ret; @@ -423,19 +437,6 @@ static int gsw1xx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, return ret; if (!reconf) { - /* setup SerDes clock speed */ - if (interface == PHY_INTERFACE_MODE_2500BASEX) - nco_ctrl = GSW1XX_SGMII_2G5 | GSW1XX_SGMII_2G5_NCO2; - else - nco_ctrl = GSW1XX_SGMII_1G | GSW1XX_SGMII_1G_NCO1; - - ret = regmap_update_bits(priv->clk, GSW1XX_CLK_NCO_CTRL, - GSW1XX_SGMII_HSP_MASK | - GSW1XX_SGMII_SEL, - nco_ctrl); - if (ret) - return ret; - ret = gsw1xx_pcs_phy_xaui_write(priv, 0x30, 0x80); if (ret) return ret; From 6b597ba4c2f67ed268b229c2c7c71f542cf27289 Mon Sep 17 00:00:00 2001 From: "Jan Havran (Advantech Czech)" Date: Mon, 7 Sep 2026 15:48:17 +0200 Subject: [PATCH 0368/2126] net: dsa: lantiq_gswip: handle SPEED_2500 in gswip_port_set_speed() The mxl-gsw1xx driver advertises 2500BASE-X on its SGMII port (via supports_2500m and gsw1xx_phylink_get_caps()), but the shared gswip_port_set_speed() has no SPEED_2500 case: at 2.5G every field keeps its initializer, so mdio_phy = 0 pins the MDIO speed override to 10 Mbps and no data passes. At the MAC/MDIO level 2500BASE-X is identical to 1 Gbps (same wide GMII datapath, same speed override); the rate itself is set in the PCS and SerDes, not here. This matches the boot loader's PHY_ADDR_4 = 0x32A4 for the 2.5G strap ("1 Gbps or above"), whose SPEED field is GSWIP_MDIO_PHY_SPEED_G1 (the field has no encoding above G1). Share the SPEED_1000 arm via a stacked case label. Its mii_cfg value is a no-op for 2.5G: gswip_mii_mask_cfg() writes it only for the RGMII port (mii_cfg[SGMII port] == -1), which cannot reach 2.5G anyway. Cc: stable+noautosel@kernel.org # never worked Signed-off-by: Jan Havran (Advantech Czech) Reviewed-by: Daniel Golle Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260907134818.16670-3-havran.jan@email.cz Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lantiq/lantiq_gswip_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c index 0e8eedf64d3a..6150dc3ffb64 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c @@ -1339,6 +1339,7 @@ static void gswip_port_set_speed(struct gswip_priv *priv, int port, int speed, break; case SPEED_1000: + case SPEED_2500: mdio_phy = GSWIP_MDIO_PHY_SPEED_G1; mii_cfg = GSWIP_MII_CFG_RATE_M125; From a07a9480298f666f92577fbe8c63d28bb9ed5e46 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 5 Sep 2026 11:51:16 +0200 Subject: [PATCH 0369/2126] docs: mctp: Fix the struct net_device name struct netdevice does not exist; the type is struct net_device. Use it. Signed-off-by: Karl Mehltretter Reviewed-by: Randy Dunlap Link: https://patch.msgid.link/20260905095116.42147-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/mctp.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/mctp.rst b/Documentation/networking/mctp.rst index c628cb5406d2..3bff00c11702 100644 --- a/Documentation/networking/mctp.rst +++ b/Documentation/networking/mctp.rst @@ -19,7 +19,7 @@ networks. An interface (or "link") is an instance of an MCTP physical transport binding (as defined by DSP0236, section 3.2.47), likely connected to a specific hardware -device. This is represented as a ``struct netdevice``. +device. This is represented as a ``struct net_device``. A network defines a unique address space for MCTP endpoints by endpoint-ID (described by DSP0236, section 3.2.31). A network has a user-visible identifier From 0b799884350f722208206bdecb3f405138e54d92 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 5 Sep 2026 11:51:50 +0200 Subject: [PATCH 0370/2126] docs: mctp: Fix the struct mctp_sk_key name struct sk_key does not exist; the type is struct mctp_sk_key. Use it. Signed-off-by: Karl Mehltretter Reviewed-by: Randy Dunlap Link: https://patch.msgid.link/20260905095150.42180-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/mctp.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/mctp.rst b/Documentation/networking/mctp.rst index 3bff00c11702..1b4bffa1ed74 100644 --- a/Documentation/networking/mctp.rst +++ b/Documentation/networking/mctp.rst @@ -296,7 +296,7 @@ There are a few possible packet flows in the MCTP stack: : route lookup -> rt->output() (== mctp_route_input) : sk_key lookup - : stores skb in struct sk_key->reasm_head + : stores skb in struct mctp_sk_key->reasm_head mctp_pkttype_receive() : route lookup From f6e96d72f64a83b31655ce504a1029b155c16966 Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:00 +0100 Subject: [PATCH 0371/2126] netconsole: add an address family to struct inet_addr netconsole_target stores a single 'bool ipv6' to denote the target's address family. This makes it hard to detect conditions like "no address set" or ipv4/ipv6 mixup between local_ip and remote_ip. Add a 'family' field to inet_addr so each address stores its own address family: AF_UNSPEC while unset, else AF_INET or AF_INET6. Nothing reads the new field yet. The next patch switches the users over and removes the bool. No functional change. Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-1-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netconsole.c | 24 +++++++++++++++--------- include/linux/netpoll.h | 10 +++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index b358e5c36735..432b66cf111a 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -225,7 +225,7 @@ struct netconsole_target { bool extended; bool release; struct netpoll np; - union inet_addr local_ip, remote_ip; + struct inet_addr local_ip, remote_ip; bool ipv6; u16 local_port, remote_port; u8 remote_mac[ETH_ALEN]; @@ -428,6 +428,7 @@ static int netcons_take_ipv6(struct netconsole_target *nt, continue; /* Got the IP, let's return */ nt->local_ip.in6 = ifp->addr; + nt->local_ip.family = AF_INET6; err = 0; break; } @@ -469,6 +470,7 @@ static int netcons_take_ipv4(struct netconsole_target *nt, } nt->local_ip.ip = ifa->ifa_local; + nt->local_ip.family = AF_INET; np_info(np, "local IP %pI4\n", &nt->local_ip.ip); return 0; @@ -741,10 +743,10 @@ static void netconsole_print_banner(struct netconsole_target *nt) np_info(np, "remote ethernet address %pM\n", nt->remote_mac); } -/* Parse the string and populate the `inet_addr` union. Return 0 if IPv4 is +/* Parse the string and populate the `inet_addr` struct. Return 0 if IPv4 is * populated, 1 if IPv6 is populated, and -1 upon failure. */ -static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr) +static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) { const char *end = NULL; int len; @@ -756,14 +758,18 @@ static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr) if (str[len - 1] == '\n') len -= 1; - if (in4_pton(str, len, (void *)addr, -1, &end) > 0 && - (!end || *end == 0 || *end == '\n')) + if (in4_pton(str, len, (void *)&addr->ip, -1, &end) > 0 && + (!end || *end == 0 || *end == '\n')) { + addr->family = AF_INET; return 0; + } if (IS_ENABLED(CONFIG_IPV6) && - in6_pton(str, len, (void *)addr, -1, &end) > 0 && - (!end || *end == 0 || *end == '\n')) + in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 && + (!end || *end == 0 || *end == '\n')) { + addr->family = AF_INET6; return 1; + } return -1; } @@ -871,7 +877,7 @@ static ssize_t local_ip_show(struct config_item *item, char *buf) if (nt->ipv6) return sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6); else - return sysfs_emit(buf, "%pI4\n", &nt->local_ip); + return sysfs_emit(buf, "%pI4\n", &nt->local_ip.ip); } static ssize_t remote_ip_show(struct config_item *item, char *buf) @@ -881,7 +887,7 @@ static ssize_t remote_ip_show(struct config_item *item, char *buf) if (nt->ipv6) return sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6); else - return sysfs_emit(buf, "%pI4\n", &nt->remote_ip); + return sysfs_emit(buf, "%pI4\n", &nt->remote_ip.ip); } static ssize_t local_mac_show(struct config_item *item, char *buf) diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index 1c6b1eec5efd..de97f001a0f9 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -16,9 +16,13 @@ #include #include -union inet_addr { - __be32 ip; - struct in6_addr in6; +struct inet_addr { + /* Address family: AF_UNSPEC when unset, else AF_INET or AF_INET6 */ + u8 family; + union { + __be32 ip; + struct in6_addr in6; + }; }; struct netpoll { From 46b3f9e7e761d304986860804715af07381df4f1 Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:01 +0100 Subject: [PATCH 0372/2126] netconsole: use the address family instead of the ipv6 flag Now that we have the address family in inet_addr, use that and remove nt->ipv6. We no longer need netcons_local_ip_unset() to check that all bytes are zeroes, as that is now denoted by (family == AF_UNSPEC). Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-2-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netconsole.c | 82 +++++++++++----------------------------- 1 file changed, 23 insertions(+), 59 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 432b66cf111a..351754d53cf9 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -195,7 +195,6 @@ struct netcons_userdata { * local_mac (read-only) * @local_ip: Source IP address of the target (read-write). * @remote_ip: Destination IP address of the target (read-write). - * @ipv6: Whether the target addresses are IPv6 (read-write). * @local_port: Source UDP port of the target (read-write). * @remote_port: Destination UDP port of the target (read-write). * @remote_mac: Destination ethernet address of the target (read-write). @@ -226,7 +225,6 @@ struct netconsole_target { bool release; struct netpoll np; struct inet_addr local_ip, remote_ip; - bool ipv6; u16 local_port, remote_port; u8 remote_mac[ETH_ALEN]; /* protected by target_list_lock; +1 gives scnprintf() room for its @@ -476,23 +474,6 @@ static int netcons_take_ipv4(struct netconsole_target *nt, return 0; } -/* - * Test whether the caller left nt->local_ip unset, so that - * netcons_netpoll_setup() should auto-populate it from the egress device. - * - * nt->local_ip is a union of __be32 (IPv4) and struct in6_addr (IPv6), - * so an IPv6 address whose first 4 bytes are zero (e.g. ::1, ::2, - * IPv4-mapped ::ffff:a.b.c.d) must not be tested via the IPv4 arm — - * doing so would misclassify a caller-supplied address as unset and - * silently overwrite it with whatever address the device exposes. - */ -static bool netcons_local_ip_unset(const struct netconsole_target *nt) -{ - if (nt->ipv6) - return ipv6_addr_any(&nt->local_ip.in6); - return !nt->local_ip.ip; -} - static int netcons_netpoll_setup(struct netconsole_target *nt) { struct net *net = current->nsproxy->net_ns; @@ -538,16 +519,13 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) rtnl_lock(); } - if (netcons_local_ip_unset(nt)) { - if (!nt->ipv6) { - err = netcons_take_ipv4(nt, ndev); - if (err) - goto put; - } else { + if (nt->local_ip.family == AF_UNSPEC) { + if (nt->remote_ip.family == AF_INET6) err = netcons_take_ipv6(nt, ndev); - if (err) - goto put; - } + else + err = netcons_take_ipv4(nt, ndev); + if (err) + goto put; ip_overwritten = true; } @@ -729,22 +707,22 @@ static void netconsole_print_banner(struct netconsole_target *nt) struct netpoll *np = &nt->np; np_info(np, "local port %d\n", nt->local_port); - if (nt->ipv6) + if (nt->local_ip.family == AF_INET6) np_info(np, "local IPv6 address %pI6c\n", &nt->local_ip.in6); else np_info(np, "local IPv4 address %pI4\n", &nt->local_ip.ip); np_info(np, "interface name '%s'\n", np->dev_name); np_info(np, "local ethernet address '%pM'\n", np->dev_mac); np_info(np, "remote port %d\n", nt->remote_port); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) np_info(np, "remote IPv6 address %pI6c\n", &nt->remote_ip.in6); else np_info(np, "remote IPv4 address %pI4\n", &nt->remote_ip.ip); np_info(np, "remote ethernet address %pM\n", nt->remote_mac); } -/* Parse the string and populate the `inet_addr` struct. Return 0 if IPv4 is - * populated, 1 if IPv6 is populated, and -1 upon failure. +/* Parse the string and populate the `inet_addr` struct. Return 0 on success + * and -1 upon failure. */ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) { @@ -768,7 +746,7 @@ static int netpoll_parse_ip_addr(const char *str, struct inet_addr *addr) in6_pton(str, len, (void *)&addr->in6, -1, &end) > 0 && (!end || *end == 0 || *end == '\n')) { addr->family = AF_INET6; - return 1; + return 0; } return -1; @@ -874,7 +852,7 @@ static ssize_t local_ip_show(struct config_item *item, char *buf) { struct netconsole_target *nt = to_target(item); - if (nt->ipv6) + if (nt->local_ip.family == AF_INET6) return sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6); else return sysfs_emit(buf, "%pI4\n", &nt->local_ip.ip); @@ -884,7 +862,7 @@ static ssize_t remote_ip_show(struct config_item *item, char *buf) { struct netconsole_target *nt = to_target(item); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) return sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6); else return sysfs_emit(buf, "%pI4\n", &nt->remote_ip.ip); @@ -1232,7 +1210,6 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); ssize_t ret = -EINVAL; - int ipv6; dynamic_netconsole_mutex_lock(); if (nt->state == STATE_ENABLED) { @@ -1241,10 +1218,8 @@ static ssize_t local_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - ipv6 = netpoll_parse_ip_addr(buf, &nt->local_ip); - if (ipv6 == -1) + if (netpoll_parse_ip_addr(buf, &nt->local_ip) < 0) goto out_unlock; - nt->ipv6 = !!ipv6; ret = count; out_unlock: @@ -1257,7 +1232,6 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, { struct netconsole_target *nt = to_target(item); ssize_t ret = -EINVAL; - int ipv6; dynamic_netconsole_mutex_lock(); if (nt->state == STATE_ENABLED) { @@ -1266,10 +1240,8 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, goto out_unlock; } - ipv6 = netpoll_parse_ip_addr(buf, &nt->remote_ip); - if (ipv6 == -1) + if (netpoll_parse_ip_addr(buf, &nt->remote_ip) < 0) goto out_unlock; - nt->ipv6 = !!ipv6; ret = count; out_unlock: @@ -2078,7 +2050,7 @@ static void netpoll_udp_checksum(struct netconsole_target *nt, /* check needs to be set, since it will be consumed in csum_partial */ udph->check = 0; - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) udph->check = csum_ipv6_magic(&nt->local_ip.in6, &nt->remote_ip.in6, udp_len, IPPROTO_UDP, @@ -2119,7 +2091,7 @@ static void push_eth(struct netconsole_target *nt, struct sk_buff *skb) skb_reset_mac_header(skb); ether_addr_copy(eth->h_source, np->dev->dev_addr); ether_addr_copy(eth->h_dest, nt->remote_mac); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) eth->h_proto = htons(ETH_P_IPV6); else eth->h_proto = htons(ETH_P_IP); @@ -2188,7 +2160,7 @@ static int netpoll_send_udp(struct netconsole_target *nt, const char *msg, WARN_ON_ONCE(!irqs_disabled()); udp_len = len + sizeof(struct udphdr); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) ip_len = udp_len + sizeof(struct ipv6hdr); else ip_len = udp_len + sizeof(struct iphdr); @@ -2204,7 +2176,7 @@ static int netpoll_send_udp(struct netconsole_target *nt, const char *msg, skb_put(skb, len); push_udp(nt, skb, len); - if (nt->ipv6) + if (nt->remote_ip.family == AF_INET6) push_ipv6(nt, skb, len); else push_ipv4(nt, skb, len); @@ -2533,10 +2505,8 @@ __releases(&target_list_lock) static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt) { struct netpoll *np = &nt->np; - bool ipversion_set = false; char *cur = opt; char *delim; - int ipv6; if (*cur != '@') { delim = strchr(cur, '@'); @@ -2550,16 +2520,12 @@ static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt) cur++; if (*cur != '/') { - ipversion_set = true; delim = strchr(cur, '/'); if (!delim) goto parse_failed; *delim = 0; - ipv6 = netpoll_parse_ip_addr(cur, &nt->local_ip); - if (ipv6 < 0) + if (netpoll_parse_ip_addr(cur, &nt->local_ip) < 0) goto parse_failed; - else - nt->ipv6 = (bool)ipv6; cur = delim; } cur++; @@ -2601,13 +2567,11 @@ static int netconsole_parser_cmdline(struct netconsole_target *nt, char *opt) if (!delim) goto parse_failed; *delim = 0; - ipv6 = netpoll_parse_ip_addr(cur, &nt->remote_ip); - if (ipv6 < 0) + if (netpoll_parse_ip_addr(cur, &nt->remote_ip) < 0) goto parse_failed; - else if (ipversion_set && nt->ipv6 != (bool)ipv6) + if (nt->local_ip.family != AF_UNSPEC && + nt->local_ip.family != nt->remote_ip.family) goto parse_failed; - else - nt->ipv6 = (bool)ipv6; cur = delim + 1; if (*cur != 0) { From 2e949954908bd5bcca2fe3cdaac9c42c88275c0b Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:02 +0100 Subject: [PATCH 0373/2126] netconsole: reject enabling a target with no remote IP address The command-line path already requires a remote address, but if a user creates a dynamic target and enables it without setting a remote address, we currently try sending netconsole traffic to "0.0.0.0". Refuse to enable a target if the remote address is unset. Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-3-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netconsole.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 351754d53cf9..4af4f3039d4c 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -483,6 +483,11 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) bool ip_overwritten = false; int err; + if (nt->remote_ip.family == AF_UNSPEC) { + np_err(np, "remote IP address not configured, aborting\n"); + return -EDESTADDRREQ; + } + rtnl_lock(); if (np->dev_name[0]) ndev = __dev_get_by_name(net, np->dev_name); From 32535a1ea962e9123506463ac3e0d1473d492059 Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:03 +0100 Subject: [PATCH 0374/2126] netconsole: reject a target mixing IPv4 and IPv6 addresses The local_ip and remote_ip configfs attributes are written independently and nothing stops a user from mixing ipv4 and ipv6. This leads to an ipv4 address being zero-extended into an ipv6 header or an ipv6 address being truncated to its first 4 bytes for an ipv4 header. The command-line parser already refuses such a mismatch. This adds a similar check when a dynamic target is being enabled. Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-4-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netconsole.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 4af4f3039d4c..abcc8515ddd2 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -488,6 +488,12 @@ static int netcons_netpoll_setup(struct netconsole_target *nt) return -EDESTADDRREQ; } + if (nt->local_ip.family != AF_UNSPEC && + nt->local_ip.family != nt->remote_ip.family) { + np_err(np, "local and remote IP address families differ, aborting\n"); + return -EINVAL; + } + rtnl_lock(); if (np->dev_name[0]) ndev = __dev_get_by_name(net, np->dev_name); From 56ddc8d48e75f48df938f5df80e2f99a0c3548d3 Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:04 +0100 Subject: [PATCH 0375/2126] netconsole: show empty string for an unset IP address An unset address (local_ip/remote_ip), now denoted by AF_UNSPEC, currently shows "0.0.0.0" in configfs. Print an empty string instead, which is more clear. In netconsole_print_banner() we can be even more explicit about it, as we don't have the risk of userspace trying to parse it. Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-5-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netconsole.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index abcc8515ddd2..1f18d0a7d2dd 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -718,14 +718,18 @@ static void netconsole_print_banner(struct netconsole_target *nt) struct netpoll *np = &nt->np; np_info(np, "local port %d\n", nt->local_port); - if (nt->local_ip.family == AF_INET6) + if (nt->local_ip.family == AF_UNSPEC) + np_info(np, "local IP unset\n"); + else if (nt->local_ip.family == AF_INET6) np_info(np, "local IPv6 address %pI6c\n", &nt->local_ip.in6); else np_info(np, "local IPv4 address %pI4\n", &nt->local_ip.ip); np_info(np, "interface name '%s'\n", np->dev_name); np_info(np, "local ethernet address '%pM'\n", np->dev_mac); np_info(np, "remote port %d\n", nt->remote_port); - if (nt->remote_ip.family == AF_INET6) + if (nt->remote_ip.family == AF_UNSPEC) + np_info(np, "remote IP unset\n"); + else if (nt->remote_ip.family == AF_INET6) np_info(np, "remote IPv6 address %pI6c\n", &nt->remote_ip.in6); else np_info(np, "remote IPv4 address %pI4\n", &nt->remote_ip.ip); @@ -863,6 +867,8 @@ static ssize_t local_ip_show(struct config_item *item, char *buf) { struct netconsole_target *nt = to_target(item); + if (nt->local_ip.family == AF_UNSPEC) + return sysfs_emit(buf, "\n"); if (nt->local_ip.family == AF_INET6) return sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6); else @@ -873,6 +879,8 @@ static ssize_t remote_ip_show(struct config_item *item, char *buf) { struct netconsole_target *nt = to_target(item); + if (nt->remote_ip.family == AF_UNSPEC) + return sysfs_emit(buf, "\n"); if (nt->remote_ip.family == AF_INET6) return sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6); else From 7be9bfb7689e875fc94b711dcafe27c86413c966 Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:05 +0100 Subject: [PATCH 0376/2126] netconsole: move struct inet_addr into netconsole.c The struct inet_addr lives in netpoll.h, but since commit a1116396476f ("netconsole: move local_ip/remote_ip/ipv6 to netconsole_target") the only user is netconsole. Move the definition into netconsole.c Suggested-by: Breno Leitao Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-6-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/netconsole.c | 9 +++++++++ include/linux/netpoll.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 1f18d0a7d2dd..267254f046de 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -151,6 +151,15 @@ enum target_state { STATE_DEACTIVATED, }; +struct inet_addr { + /* Address family: AF_UNSPEC when unset, else AF_INET or AF_INET6 */ + u8 family; + union { + __be32 ip; + struct in6_addr in6; + }; +}; + /** * struct netcons_userdata - Formatted userdata payload of a target. * @rcu: Used to free the payload after a grace period. diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index de97f001a0f9..ec0821a5b02d 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -16,15 +16,6 @@ #include #include -struct inet_addr { - /* Address family: AF_UNSPEC when unset, else AF_INET or AF_INET6 */ - u8 family; - union { - __be32 ip; - struct in6_addr in6; - }; -}; - struct netpoll { struct net_device *dev; netdevice_tracker dev_tracker; From a4b9392ef046bd8a165fb5091adebc2c6ea46890 Mon Sep 17 00:00:00 2001 From: Gustavo Luiz Duarte Date: Thu, 3 Sep 2026 17:26:06 +0100 Subject: [PATCH 0377/2126] docs: netconsole: document local_ip auto-selection An unset local_ip is auto-populated from the egress interface at enable time, but any value the user writes, including 0.0.0.0, is used as-is. This deviates from the behavior prior to "netconsole: use the address family instead of the ipv6 flag", which interpreted 0.0.0.0 as unset. Document this so the distinction between "unset" and "set to 0.0.0.0" is clear. Reviewed-by: Breno Leitao Signed-off-by: Gustavo Luiz Duarte Link: https://patch.msgid.link/20260903-netcons_ipv6-v4-7-bdd183c844d3@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/netconsole.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst index 4ab5d7b05cf1..694bca4803d5 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -141,6 +141,11 @@ The interface exposes these parameters of a netconsole target to userspace: transmit_errors Number of packet send errors (read-only) =============== ================================= ============ +local_ip is optional: if it is left unset, netconsole derives a source +address from the egress interface when the target is enabled. Writing any +value to it, including 0.0.0.0, uses that value verbatim and disables the +automatic selection. + The "enabled" attribute is also used to control whether the parameters of a target can be updated or not -- you can modify the parameters of only disabled targets (i.e. if "enabled" is 0). From bcf03907c5ec714f7b4fa0662b01be81f2919a17 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 5 Sep 2026 10:47:11 +0200 Subject: [PATCH 0378/2126] docs: networking: page_pool: Use page_pool_put_netmem_bulk() in the kernel-doc directive page_pool.rst asks net/core/page_pool.c for page_pool_put_page_bulk(). Commit 024bfd2e9d80 ("page_pool: make page_pool_put_page_bulk() handle array of netmems") renamed the function to page_pool_put_netmem_bulk(). Since then the directive finds nothing and the bulk release helper is missing from the rendered page. Use the current name. Signed-off-by: Karl Mehltretter Acked-by: Randy Dunlap Link: https://patch.msgid.link/20260905084711.40105-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/page_pool.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/page_pool.rst b/Documentation/networking/page_pool.rst index 817f8b78d246..d0be2b800a06 100644 --- a/Documentation/networking/page_pool.rst +++ b/Documentation/networking/page_pool.rst @@ -83,7 +83,7 @@ that NAPI context, the page pool may safely access consumer-side resources page_pool_get_dma_addr page_pool_get_dma_dir .. kernel-doc:: net/core/page_pool.c - :identifiers: page_pool_put_page_bulk + :identifiers: page_pool_put_netmem_bulk DMA sync -------- From 3037c2f6a9de3af9775427059546e705237f6723 Mon Sep 17 00:00:00 2001 From: Tapio Reijonen Date: Fri, 4 Sep 2026 06:03:00 +0000 Subject: [PATCH 0379/2126] net: dsa: microchip: enable the SGMII port of the KSZ9897S The KSZ9897 has an SGMII/1000BASE-X capable port 7, but its chip_info entry never set .sgmii_port. ksz_has_sgmii_port() is therefore false, ksz9477_pcs_create() is never called and ksz9477_phylink_mac_select_pcs() returns NULL for port 7, so a phy-mode = "sgmii" or "1000base-x" link on that port cannot come up. Only the KSZ9897S has that port; the KSZ9897R has a second RGMII port instead. Both report chip ID 0x00989700, so the port cannot be enabled from the chip ID alone, and enabling it unconditionally breaks the KSZ9897R badly: ksz9477_setup() propagates the failure of xpcs_create_pcs_mdiodev() on a part without an XPCS, so the switch as a whole stops probing. The variants do differ in the read-only bit 7 of the port 7 XMII control 0 register, which reads one on the KSZ9897S and zero on the KSZ9897R. Compare the KSZ9897S data sheet DS00002394C section 5.2.4.1 with the KSZ9897R data sheet DS00002330D section 5.2.3.1. Read that bit in ksz_switch_register() and use it to select a KSZ9897S chip_data entry, which is the KSZ9897 one plus .sgmii_port = 7, with port 7 no longer marked as supporting MII, RMII and RGMII. On the KSZ9897S that port is permanently an SGMII port and only its differential pairs are brought out, so advertising the xMII modes on it would let phylink accept a mode the driver never programs: ksz_phylink_need_config() skips the XMII control registers for the SGMII port. The KSZ9477, which also has SGMII on port 7, is described the same way. See DS00002394C section 4.11. KSZ9897S_CHIP_ID selects that chip_data entry and nothing else. dev->chip_id keeps the KSZ9897 chip ID that both parts report, so no other chip ID comparison has to know about the variant, ksz_check_device_id() is unchanged, and a device tree naming the KSZ9897 keeps matching whichever part is fitted. No binding change is needed and existing device trees keep working. Tested on a KSZ9897S with a 1000BASE-LX fibre SFP on port 7: bit 7 of the port 7 XMII control 0 register reads one, the switch is identified as a KSZ9897S and the PCS is created. The port advertises 1000baseX/Full, clause 37 in-band autonegotiation completes against the link partner, and the link comes up at 1Gbps/full duplex and passes traffic. Suggested-by: Nicolai Buchwitz Suggested-by: Jerry Ray Suggested-by: Tristram Ha Signed-off-by: Tapio Reijonen Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260904-ksz9897-sgmii-port-v5-1-9bd4a0381aa8@vaisala.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_common.c | 61 ++++++++++++++++++++- drivers/net/dsa/microchip/ksz_common.h | 5 ++ include/linux/platform_data/microchip-ksz.h | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 1a9d6f83a023..81798a9fa671 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1486,6 +1486,41 @@ const struct ksz_chip_data ksz_switch_chips[] = { .gbit_capable = {true, true, true, true, true, true, true}, }, + [KSZ9897S] = { + .chip_id = KSZ9897S_CHIP_ID, + .dev_name = "KSZ9897S", + .num_vlans = 4096, + .num_alus = 4096, + .num_statics = 16, + .cpu_ports = 0x7F, /* can be configured as cpu port */ + .port_cnt = 7, /* total physical port count */ + .port_nirqs = 2, + .num_tx_queues = 4, + .num_ipms = 8, + .ops = &ksz9477_dev_ops, + .switch_ops = &ksz9477_switch_ops, + .phylink_mac_ops = &ksz9477_phylink_mac_ops, + .phy_errata_9477 = true, + .mib_names = ksz9477_mib_names, + .mib_cnt = ARRAY_SIZE(ksz9477_mib_names), + .reg_mib_cnt = MIB_COUNTER_NUM, + .regs = ksz9477_regs, + .masks = ksz9477_masks, + .shifts = ksz9477_shifts, + .xmii_ctrl0 = ksz9477_xmii_ctrl0, + .xmii_ctrl1 = ksz9477_xmii_ctrl1, + .supports_mii = {false, false, false, false, + false, true, false}, + .supports_rmii = {false, false, false, false, + false, true, false}, + .supports_rgmii = {false, false, false, false, + false, true, false}, + .internal_phy = {true, true, true, true, + true, false, false}, + .gbit_capable = {true, true, true, true, true, true, true}, + .sgmii_port = 7, + }, + [KSZ9893] = { .chip_id = KSZ9893_CHIP_ID, .dev_name = "KSZ9893", @@ -3897,6 +3932,7 @@ int ksz_switch_register(struct ksz_device *dev) struct device_node *ports; phy_interface_t interface; unsigned int port_num; + u32 lookup_chip_id; int ret; int i; @@ -3933,7 +3969,30 @@ int ksz_switch_register(struct ksz_device *dev) if (ret) return ret; - info = ksz_lookup_info(dev->chip_id); + lookup_chip_id = dev->chip_id; + + /* The KSZ9897S and the KSZ9897R report the same chip ID and differ + * only in chip_data: only the S has the SGMII port 7, the R has a + * second RGMII port instead. Bit 7 of the port 7 XMII control 0 + * register is read-only and tells them apart; it reads one on the S. + * Compare the KSZ9897S data sheet DS00002394C section 5.2.4.1 with + * the KSZ9897R data sheet DS00002330D section 5.2.3.1. + * + * Only the chip_data entry differs, so dev->chip_id keeps the shared + * chip ID and nothing else has to know about the variant. + */ + if (dev->chip_id == KSZ9897_CHIP_ID) { + u8 val; + + ret = ksz_read8(dev, KSZ9897_REG_PORT7_XMII_CTRL_0, &val); + if (ret) + return ret; + + if (val & KSZ9897_PORT7_SGMII_SEL) + lookup_chip_id = KSZ9897S_CHIP_ID; + } + + info = ksz_lookup_info(lookup_chip_id); if (!info) return -ENODEV; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index cbe98494578c..0cff33df06a4 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -284,6 +284,7 @@ enum ksz_model { KSZ9477, KSZ9896, KSZ9897, + KSZ9897S, KSZ9893, KSZ9563, KSZ9567, @@ -874,6 +875,10 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port) #define SKU_ID_KSZ8563 0x3c #define SKU_ID_KSZ9563 0x1c +/* KSZ9897 specific register: port 7 XMII control 0 */ +#define KSZ9897_REG_PORT7_XMII_CTRL_0 0x7300 +#define KSZ9897_PORT7_SGMII_SEL BIT(7) + /* Driver set switch broadcast storm protection at 10% rate. */ #define BROADCAST_STORM_PROT_RATE 10 diff --git a/include/linux/platform_data/microchip-ksz.h b/include/linux/platform_data/microchip-ksz.h index 028781ad4059..fe8df1774289 100644 --- a/include/linux/platform_data/microchip-ksz.h +++ b/include/linux/platform_data/microchip-ksz.h @@ -34,6 +34,7 @@ enum ksz_chip_id { KSZ9477_CHIP_ID = 0x00947700, KSZ9896_CHIP_ID = 0x00989600, KSZ9897_CHIP_ID = 0x00989700, + KSZ9897S_CHIP_ID = 0x00989701, KSZ9893_CHIP_ID = 0x00989300, KSZ9563_CHIP_ID = 0x00956300, KSZ8567_CHIP_ID = 0x00856700, From b5a252adbe4a7c611c8a131383f278852a2773d2 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 8 Sep 2026 09:13:27 +0000 Subject: [PATCH 0380/2126] selftests: icmp_redirect: remove xfail support Commit 0a36a75c6818 ("selftests: icmp_redirect: support expected failures") added xfail support to icmp_redirect.sh because the test "IPv6: mtu exception plus redirect" was failing at the time due to a perceived kernel bug described in commit 99513cfa16c6 ("selftest: Fixes for icmp_redirect test"). However, commit 0e02bf5de46a ("selftests: icmp_redirect: IPv6 PMTU info should be cleared after redirect") subsequently fixed the test logic: after redirecting to a new path, the old PMTU information should indeed be cleared, so the test was adjusted to verify the redirect without the old PMTU. Since that fix, the test has been passing and is no longer expected to fail. Leaving xfail=1 in log_test() for all IPv6 tests was not only obsolete, but had the undesirable side effect of masking any future IPv6 failure as XFAIL instead of FAIL. Furthermore, commit 3748939bce3f ("selftests: icmp_redirect: pass xfail=0 to log_test()") had to work around a bash syntax error caused by the empty xfail argument on IPv4 tests. Remove the obsolete xfail support from log_test() and restore standard pass/fail reporting across all tests. Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260908091327.349091-1-edumazet@google.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/icmp_redirect.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/net/icmp_redirect.sh b/tools/testing/selftests/net/icmp_redirect.sh index b13c89a99ecb..35357d02e823 100755 --- a/tools/testing/selftests/net/icmp_redirect.sh +++ b/tools/testing/selftests/net/icmp_redirect.sh @@ -64,14 +64,10 @@ log_test() local rc=$1 local expected=$2 local msg="$3" - local xfail=$4 if [ ${rc} -eq ${expected} ]; then printf "TEST: %-60s [ OK ]\n" "${msg}" nsuccess=$((nsuccess+1)) - elif [ ${rc} -eq ${xfail} ]; then - printf "TEST: %-60s [XFAIL]\n" "${msg}" - nxfail=$((nxfail+1)) else ret=1 nfail=$((nfail+1)) @@ -303,7 +299,7 @@ check_exception() ip -netns $h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \ grep -E -v 'mtu|redirected' | grep -q "cache" fi - log_test $? 0 "IPv4: ${desc}" 0 + log_test $? 0 "IPv4: ${desc}" # No PMTU info for test "redirect" and "mtu exception plus redirect" if [ "$with_redirect" = "yes" ] && [ "$desc" != "redirect exception plus mtu" ]; then @@ -319,7 +315,7 @@ check_exception() ip -netns $h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \ grep -v "mtu" | grep -q "${R1_LLADDR}" fi - log_test $? 0 "IPv6: ${desc}" 1 + log_test $? 0 "IPv6: ${desc}" } run_ping() @@ -485,7 +481,6 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) ret=0 nsuccess=0 nfail=0 -nxfail=0 while getopts :pv o do @@ -530,6 +525,5 @@ fi printf "\nTests passed: %3d\n" ${nsuccess} printf "Tests failed: %3d\n" ${nfail} -printf "Tests xfailed: %3d\n" ${nxfail} exit $ret From 3bfa48d011fbf41b50480a12efa0e26990c43b36 Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Fri, 4 Sep 2026 15:57:41 +0800 Subject: [PATCH 0381/2126] net: usb: qmi_wwan: add Compal EXC-T1 support The Compal EXC-T1 is a Qualcomm MDM9207-based LTE modem which reports "EXC-x1" as its USB product string. It exposes its QMI function on interface 5. Add a fixed-interface match for the QMI function. Tested on a Compal EXC-T1 modem using an Ubuntu kernel build. Interface 5 bound to qmi_wwan and exposed cdc-wdm2 and wwan1. Signed-off-by: Ian Lin Link: https://patch.msgid.link/20260904075741.55778-1-ian.lin@jetone.com.tw Signed-off-by: Jakub Kicinski --- drivers/net/usb/qmi_wwan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c index fdfdcf24ddcf..bb9493006618 100644 --- a/drivers/net/usb/qmi_wwan.c +++ b/drivers/net/usb/qmi_wwan.c @@ -1446,6 +1446,7 @@ static const struct usb_device_id products[] = { {QMI_QUIRK_SET_DTR(0x2c7c, 0x0316, 3)}, /* Quectel RG255C */ {QMI_QUIRK_SET_DTR(0x2cb7, 0x0104, 4)}, /* Fibocom NL678 series */ {QMI_QUIRK_SET_DTR(0x2cb7, 0x0112, 0)}, /* Fibocom FG132 */ + {QMI_FIXED_INTF(0x04b7, 0x4d22, 5)}, /* Compal EXC-T1 */ {QMI_QUIRK_SET_DTR(0x04b7, 0x8217, 8)}, /* Compal EXM-G1x */ {QMI_FIXED_INTF(0x0489, 0xe0b4, 0)}, /* Foxconn T77W968 LTE */ {QMI_FIXED_INTF(0x0489, 0xe0b5, 0)}, /* Foxconn T77W968 LTE with eSIM support*/ From f217004a40c49e787372e798785aecb983828d35 Mon Sep 17 00:00:00 2001 From: Sergey Shtylyov Date: Mon, 7 Sep 2026 22:46:32 +0300 Subject: [PATCH 0382/2126] r8152: simplify loops in generic_ocp_{read,write}() In generic_ocp_{read,write}(), the *while* loops look very strange: the last iteration is implemented differently to the previous ones (doing some useless assignments before *break*) for no good reason. Merge the different iterations into one, using the local variables in the loop bodies... Found by a static analysis tool. Suggested-by: Michal Pecio Signed-off-by: Sergey Shtylyov Link: https://patch.msgid.link/863dac62-89ef-42d7-9108-d4a0600913a4@auroraos.dev Signed-off-by: Jakub Kicinski --- drivers/net/usb/r8152.c | 51 ++++++++++++----------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index f61686433031..af3d7dcb2f14 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -1432,24 +1432,15 @@ static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, return -EPERM; while (size) { - if (size > limit) { - ret = get_registers(tp, index, type, limit, data); - if (ret < 0) - break; + u16 n = min(size, limit); - index += limit; - data += limit; - size -= limit; - } else { - ret = get_registers(tp, index, type, size, data); - if (ret < 0) - break; - - index += size; - data += size; - size = 0; + ret = get_registers(tp, index, type, n, data); + if (ret < 0) break; - } + + index += n; + data += n; + size -= n; } if (ret == -ENODEV) @@ -1499,28 +1490,16 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, size -= 4; while (size) { - if (size > limit) { - ret = set_registers(tp, index, - type | BYTE_EN_DWORD, - limit, data); - if (ret < 0) - goto error1; + u16 n = min(size, limit); - index += limit; - data += limit; - size -= limit; - } else { - ret = set_registers(tp, index, - type | BYTE_EN_DWORD, - size, data); - if (ret < 0) - goto error1; + ret = set_registers(tp, index, type | BYTE_EN_DWORD, + n, data); + if (ret < 0) + goto error1; - index += size; - data += size; - size = 0; - break; - } + index += n; + data += n; + size -= n; } /* Set the last DWORD */ From 5a81c72ef9ad6477e03d9d9b0abd794e9e4e639c Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 4 Sep 2026 11:00:58 -0700 Subject: [PATCH 0383/2126] net: run netdev work under the ops-compat lock netdev_work_proc() took rtnl_lock() for the whole batch, forcing even ops-locked drivers onto rtnl just to run their rx_mode / ndo_work callbacks. Take the per-device ops-compat lock instead: the instance lock for ops-locked drivers, rtnl_lock for the rest. That's what the callbacks already assert (e.g. netif_rx_mode_run() asserts netdev_assert_locked_ops_compat()), and non-ops-locked work such as vlan ndo_work keeps rtnl, since its compat lock resolves to rtnl anyway. Without this adding more uses of ndo_work, for cases which don't need rtnl_lock feels like a step back. We can drop the comment about the extra ref now, with the relocking it's a necessity. Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260904180058.3803849-1-kuba@kernel.org Signed-off-by: Paolo Abeni --- Documentation/networking/netdevices.rst | 14 ++++++++++---- include/linux/netdevice.h | 5 ++++- net/core/netdev_work.c | 15 ++------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index db71d4283032..aac33497813f 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -292,15 +292,21 @@ ndo_set_rx_mode: in process context. ndo_set_rx_mode_async: - Synchronization: rtnl_lock() semaphore. In addition, netdev instance - lock if the driver implements queue management or shaper API. + Synchronization: netdev instance lock for "ops locked" drivers, + rtnl_lock() semaphore for all other drivers. Context: process (from a work queue) Notes: Async version of ndo_set_rx_mode which runs in process context. Receives snapshots of the unicast and multicast address lists. ndo_change_rx_flags: - Synchronization: rtnl_lock() semaphore. In addition, netdev instance - lock if the driver implements queue management or shaper API. + Synchronization: netdev instance lock for "ops locked" drivers, + rtnl_lock() semaphore for all other drivers. + +ndo_work: + Synchronization: netdev instance lock for "ops locked" drivers, + rtnl_lock() semaphore for all other drivers. + Context: process (from a work queue) + Notes: Runs deferred work scheduled with netdev_work_sched(). ndo_setup_tc: Locking depends on ``tc_setup_type``. For most types the callback diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3e184994df4b..707b2e51c2b9 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1135,13 +1135,16 @@ struct netdev_net_notifier { * struct netdev_hw_addr_list *uc, * struct netdev_hw_addr_list *mc); * Async version of ndo_set_rx_mode which runs in process context - * with rtnl_lock and netdev_lock_ops(dev) held. The uc/mc parameters + * under the netdev instance lock for "ops locked" drivers, or + * rtnl_lock for all other drivers. The uc/mc parameters * are snapshots of the address lists - iterate with * netdev_hw_addr_list_for_each(ha, uc). Return 0 on success or a * negative errno to request a retry via the core backoff. * * void (*ndo_work)(struct net_device *dev, unsigned long events); * Run deferred work scheduled with netdev_work_sched(@events). + * Runs in process context under the netdev instance lock for "ops + * locked" drivers, or rtnl_lock for all other drivers. * * int (*ndo_set_mac_address)(struct net_device *dev, void *addr); * This function is called when the Media Access Control address diff --git a/net/core/netdev_work.c b/net/core/netdev_work.c index e721a06d58df..c99967907e18 100644 --- a/net/core/netdev_work.c +++ b/net/core/netdev_work.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -129,8 +128,6 @@ static void netdev_work_run(struct net_device *dev, unsigned long events, static void netdev_work_proc(struct work_struct *work) { - rtnl_lock(); - while (true) { unsigned long events = 0, core = 0; netdevice_tracker tracker; @@ -143,16 +140,10 @@ static void netdev_work_proc(struct work_struct *work) } dev = list_first_entry(&netdev_work_list, struct net_device, work_node); - /* Take a temporary reference so @dev can't be freed while we - * drop the lock to grab its ops lock; the work reference is - * only released once we claim the work below. - * The re-locking dance is to ensure that ops lock is enough - * to ensure canceling work is not racy with dequeue. - */ netdev_hold(dev, &tracker, GFP_ATOMIC); spin_unlock_bh(&netdev_work_lock); - netdev_lock_ops(dev); + netdev_lock_ops_compat(dev); spin_lock_bh(&netdev_work_lock); if (!list_empty(&dev->work_node)) { list_del_init(&dev->work_node); @@ -169,10 +160,8 @@ static void netdev_work_proc(struct work_struct *work) spin_unlock_bh(&netdev_work_lock); netdev_work_run(dev, events, core); - netdev_unlock_ops(dev); + netdev_unlock_ops_compat(dev); netdev_put(dev, &tracker); } - - rtnl_unlock(); } From cc54f9667188904b3a20ebee1f1eac56b947b358 Mon Sep 17 00:00:00 2001 From: Jia Wang Date: Mon, 7 Sep 2026 15:46:50 +0800 Subject: [PATCH 0384/2126] net: stmmac: Add common internal RGMII delay handling Some DWMAC integrations add fixed RGMII clock delays internally. Glue drivers need to account for these delays before passing the interface mode to the PHY. Add TX and RX delay capability flags to the common platform data. Apply phy_fix_phy_mode_for_mac_delays() in stmmac_pltfr_probe() when either capability is present. This lets glue drivers describe the MAC capabilities without duplicating the interface-mode validation and conversion. Signed-off-by: Jia Wang Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260907-dwmac-ultrarisc-v2-1-9a39bf8db313@ultrarisc.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +++++++++++ include/linux/stmmac.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 6128ed1bd521..93b9af203a18 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "stmmac.h" #include "stmmac_platform.h" @@ -847,6 +848,16 @@ int stmmac_pltfr_probe(struct platform_device *pdev, struct plat_stmmacenet_data *plat, struct stmmac_resources *res) { + if (plat->has_internal_tx_delay || plat->has_internal_rx_delay) { + plat->phy_interface = + phy_fix_phy_mode_for_mac_delays(plat->phy_interface, + plat->has_internal_tx_delay, + plat->has_internal_rx_delay); + if (plat->phy_interface == PHY_INTERFACE_MODE_NA) + return dev_err_probe(&pdev->dev, -EINVAL, + "unsupported phy interface mode\n"); + } + if (!plat->suspend && plat->exit) plat->suspend = stmmac_plat_suspend; if (!plat->resume && plat->init) diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index 4430b967abde..00be2df63d22 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -242,6 +242,8 @@ struct plat_stmmacenet_data { * that phylink uses. */ phy_interface_t phy_interface; + bool has_internal_tx_delay; + bool has_internal_rx_delay; struct stmmac_mdio_bus_data *mdio_bus_data; struct device_node *phy_node; struct device_node *mdio_node; From 7d1cbb9ba9336780639554581207e8ee147dd7b3 Mon Sep 17 00:00:00 2001 From: Jia Wang Date: Mon, 7 Sep 2026 15:46:51 +0800 Subject: [PATCH 0385/2126] net: stmmac: sophgo: Use common RGMII delay handling Describe the SG2042 internal RX delay through the common stmmac platform data and let stmmac_pltfr_probe() adjust the PHY interface mode. This removes the duplicated mode conversion without changing the hardware behavior. Signed-off-by: Jia Wang Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260907-dwmac-ultrarisc-v2-2-9a39bf8db313@ultrarisc.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c index e02ad3762b5f..f62c803665ad 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c @@ -55,14 +55,10 @@ static int sophgo_dwmac_probe(struct platform_device *pdev) return ret; data = device_get_match_data(&pdev->dev); - if (data && data->has_internal_rx_delay) { - plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface, - false, true); - if (plat_dat->phy_interface == PHY_INTERFACE_MODE_NA) - return -EINVAL; - } + if (data) + plat_dat->has_internal_rx_delay = data->has_internal_rx_delay; - return stmmac_dvr_probe(dev, plat_dat, &stmmac_res); + return stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); } static const struct sophgo_dwmac_data sg2042_dwmac_data = { From 345d78e3098044b792d7d130c7f5e72ca86f5491 Mon Sep 17 00:00:00 2001 From: Jia Wang Date: Mon, 7 Sep 2026 15:46:52 +0800 Subject: [PATCH 0386/2126] net: stmmac: eic7700: Use common RGMII delay handling Describe the EIC7700 inherent TX delay through the common stmmac platform data and let stmmac_pltfr_probe() adjust the PHY interface mode. Keep the existing programmable TX and RX delay configuration in the EIC7700 glue driver. Signed-off-by: Jia Wang Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260907-dwmac-ultrarisc-v2-3-9a39bf8db313@ultrarisc.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c index eab8c13fbdcc..0d654ec07f33 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c @@ -198,18 +198,9 @@ static int eic7700_dwmac_probe(struct platform_device *pdev) /* * The MAC silicon unconditionally adds ~2 ns TX delay; prevent * the PHY from also adding TX delay to avoid doubling it. - * - * DT specifies rgmii-id (TX from MAC silicon, RX from PHY); - * override to rgmii-rxid so the PHY only adds its RX delay. + * The common platform code adjusts the PHY interface accordingly. */ - if (data->has_internal_tx_delay) { - plat_dat->phy_interface = - phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface, - true, false); - if (plat_dat->phy_interface == PHY_INTERFACE_MODE_NA) - return dev_err_probe(&pdev->dev, -EINVAL, - "phy interface mode is NA\n"); - } + plat_dat->has_internal_tx_delay = data->has_internal_tx_delay; /* Read rx-internal-delay-ps and update rx_clk delay */ if (!of_property_read_u32(pdev->dev.of_node, From 8dbfb46c233abe2a3482cca0ff58ade39a95f8c6 Mon Sep 17 00:00:00 2001 From: Jia Wang Date: Mon, 7 Sep 2026 15:46:53 +0800 Subject: [PATCH 0387/2126] dt-bindings: net: Add UltraRISC DP1000 GMAC The DP1000 integrates a Synopsys DesignWare GMAC from the 5.20 series with one MMIO register range, one clock and one interrupt. It also provides fixed TX and RX RGMII clock delays that cannot be disabled. Board connections must therefore not add either delay in PCB traces, making "rgmii-id" the only supported phy-mode. Signed-off-by: Jia Wang Reviewed-by: Conor Dooley Link: https://patch.msgid.link/20260907-dwmac-ultrarisc-v2-4-9a39bf8db313@ultrarisc.com Signed-off-by: Paolo Abeni --- .../devicetree/bindings/net/snps,dwmac.yaml | 1 + .../bindings/net/ultrarisc,dp1000-gmac.yaml | 74 +++++++++++++++++++ MAINTAINERS | 5 ++ 3 files changed, 80 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/ultrarisc,dp1000-gmac.yaml diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml index 2449311c6d28..2ed4564ae99d 100644 --- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml +++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml @@ -119,6 +119,7 @@ properties: - starfive,jh7110-dwmac - tesla,fsd-ethqos - thead,th1520-gmac + - ultrarisc,dp1000-gmac reg: minItems: 1 diff --git a/Documentation/devicetree/bindings/net/ultrarisc,dp1000-gmac.yaml b/Documentation/devicetree/bindings/net/ultrarisc,dp1000-gmac.yaml new file mode 100644 index 000000000000..13029302877b --- /dev/null +++ b/Documentation/devicetree/bindings/net/ultrarisc,dp1000-gmac.yaml @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/ultrarisc,dp1000-gmac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: UltraRISC DP1000 DWMAC Ethernet controller + +maintainers: + - Jia Wang + +description: + The DP1000 integrates a Synopsys DesignWare GMAC controller from the + 5.20 series. The SoC integration adds fixed RGMII TX and RX clock delays + which cannot be disabled. Consequently, a functional RGMII link requires + a PCB without TX or RX clock delays, represented by "rgmii-id". + +select: + properties: + compatible: + contains: + const: ultrarisc,dp1000-gmac + required: + - compatible + +properties: + compatible: + items: + - const: ultrarisc,dp1000-gmac + - const: snps,dwmac-5.20 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + const: stmmaceth + + interrupts: + maxItems: 1 + + interrupt-names: + const: macirq + + phy-mode: + const: rgmii-id + +required: + - compatible + - reg + - clocks + - clock-names + - interrupts + - interrupt-names + - phy-mode + +allOf: + - $ref: snps,dwmac.yaml# + +unevaluatedProperties: false + +examples: + - | + ethernet@38000000 { + compatible = "ultrarisc,dp1000-gmac", "snps,dwmac-5.20"; + reg = <0x38000000 0x1000000>; + clocks = <&clk 0>; + clock-names = "stmmaceth"; + interrupts = <84>; + interrupt-names = "macirq"; + phy-mode = "rgmii-id"; + }; diff --git a/MAINTAINERS b/MAINTAINERS index b000853829b5..17679f5c911d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -27997,6 +27997,11 @@ F: Documentation/devicetree/bindings/clock/ultrarisc,dp1000-clk.yaml F: drivers/clk/ultrarisc/* F: include/dt-bindings/clock/ultrarisc,dp1000-clk.h +ULTRARISC DP1000 DWMAC GLUE LAYER +M: Jia Wang +S: Maintained +F: Documentation/devicetree/bindings/net/ultrarisc,dp1000-gmac.yaml + ULTRARISC DP1000 PINCTRL DRIVER M: Jia Wang L: linux-gpio@vger.kernel.org From c6ff098cb63a5d2ac491be0a307d6058876292f5 Mon Sep 17 00:00:00 2001 From: Jia Wang Date: Mon, 7 Sep 2026 15:46:54 +0800 Subject: [PATCH 0388/2126] net: stmmac: Add UltraRISC DP1000 GMAC support The UltraRISC DP1000 GMAC provides fixed internal delays on both TX and RX RGMII clock paths. Add a platform glue driver and describe both delay capabilities through the common stmmac platform data. This lets the common RGMII delay handling adjust the interface mode passed to the PHY and reject incompatible RGMII modes. Signed-off-by: Jia Wang Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20260907-dwmac-ultrarisc-v2-5-9a39bf8db313@ultrarisc.com Signed-off-by: Paolo Abeni --- MAINTAINERS | 1 + drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 ++++ drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-ultrarisc.c | 52 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-ultrarisc.c diff --git a/MAINTAINERS b/MAINTAINERS index 17679f5c911d..878ecf1fdf27 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -28001,6 +28001,7 @@ ULTRARISC DP1000 DWMAC GLUE LAYER M: Jia Wang S: Maintained F: Documentation/devicetree/bindings/net/ultrarisc,dp1000-gmac.yaml +F: drivers/net/ethernet/stmicro/stmmac/dwmac-ultrarisc.c ULTRARISC DP1000 PINCTRL DRIVER M: Jia Wang diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index e3dd5adda5ac..ab3c4cf96423 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -319,6 +319,17 @@ config DWMAC_THEAD the stmmac device driver. This driver is used for T-HEAD TH1520 ethernet controller. +config DWMAC_ULTRARISC + tristate "UltraRISC DWMAC support" + default ARCH_ULTRARISC + depends on OF && (ARCH_ULTRARISC || COMPILE_TEST) + help + Support for the Ethernet controller on the UltraRISC DP1000 SoC. + + This selects the UltraRISC platform specific glue layer support + for the stmmac device driver. This driver is used for the DP1000 + GMAC Ethernet controller. + config DWMAC_IMX8 tristate "NXP IMX8 DWMAC support" default ARCH_MXC diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index a1cea2f57252..b16a456b730e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_DWMAC_SUNXI) += dwmac-sunxi.o obj-$(CONFIG_DWMAC_SUN8I) += dwmac-sun8i.o obj-$(CONFIG_DWMAC_SUN55I) += dwmac-sun55i.o obj-$(CONFIG_DWMAC_THEAD) += dwmac-thead.o +obj-$(CONFIG_DWMAC_ULTRARISC) += dwmac-ultrarisc.o obj-$(CONFIG_DWMAC_DWC_QOS_ETH) += dwmac-dwc-qos-eth.o obj-$(CONFIG_DWMAC_INTEL_PLAT) += dwmac-intel-plat.o obj-$(CONFIG_DWMAC_LOONGSON1) += dwmac-loongson1.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ultrarisc.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ultrarisc.c new file mode 100644 index 000000000000..0b62a75b782a --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ultrarisc.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * UltraRISC DWMAC platform driver + * + * Copyright (C) 2026 UltraRISC Technology (Shanghai) Co., Ltd. + */ + +#include +#include + +#include "stmmac_platform.h" + +static int ultrarisc_dwmac_probe(struct platform_device *pdev) +{ + struct plat_stmmacenet_data *plat_dat; + struct stmmac_resources stmmac_res; + struct device *dev = &pdev->dev; + int ret; + + ret = stmmac_get_platform_resources(pdev, &stmmac_res); + if (ret) + return dev_err_probe(dev, ret, "failed to get resources\n"); + + plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); + if (IS_ERR(plat_dat)) + return dev_err_probe(dev, PTR_ERR(plat_dat), + "failed to parse DT parameters\n"); + + plat_dat->has_internal_tx_delay = true; + plat_dat->has_internal_rx_delay = true; + + return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); +} + +static const struct of_device_id ultrarisc_dwmac_match[] = { + { .compatible = "ultrarisc,dp1000-gmac" }, + { } +}; +MODULE_DEVICE_TABLE(of, ultrarisc_dwmac_match); + +static struct platform_driver ultrarisc_dwmac_driver = { + .probe = ultrarisc_dwmac_probe, + .driver = { + .name = "ultrarisc-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = ultrarisc_dwmac_match, + }, +}; +module_platform_driver(ultrarisc_dwmac_driver); + +MODULE_DESCRIPTION("UltraRISC DWMAC platform driver"); +MODULE_LICENSE("GPL"); From ae768e41c03e865ec55a70ff1020a18a83976955 Mon Sep 17 00:00:00 2001 From: Marco Crivellari Date: Mon, 7 Sep 2026 11:48:22 +0200 Subject: [PATCH 0389/2126] Octeontx2-af: Add WQ_PERCPU to alloc_workqueue users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in: commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag") The refactoring is going to alter the default behavior of alloc_workqueue() to be unbound by default. With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU. For more details see the Link tag below. This is also enforced by: commit 21c05ca88a548 ("workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present") In order to keep alloc_workqueue() behavior identical, explicitly request WQ_PERCPU. Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@linutronix.de/ Suggested-by: Tejun Heo Signed-off-by: Marco Crivellari Link: https://patch.msgid.link/20260907094822.121457-1-marco.crivellari@suse.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c index 937b085582b5..b8f81e068f53 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c @@ -3371,7 +3371,7 @@ static int rvu_flr_init(struct rvu *rvu) } rvu->flr_wq = alloc_workqueue("rvu_afpf_flr", - WQ_HIGHPRI | WQ_MEM_RECLAIM, 0); + WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_PERCPU, 0); if (!rvu->flr_wq) return -ENOMEM; From 10ca508878b6c0342639b85534ee914edfd0b2a0 Mon Sep 17 00:00:00 2001 From: Weiting Lee Date: Mon, 7 Sep 2026 09:56:37 +0800 Subject: [PATCH 0390/2126] net: phy: air_en8811h: select LED GPIO pins based on AN8811HB package variant The AN8811HB comes in two package variants, AN8811HBCN and AN8811HBN, which use different GPIO pins to drive LED outputs. AN8811HBCN uses GPIOs 0, 1, and 15, while AN8811HBN uses GPIOs 3, 4, and 5. Using a fixed GPIO assignment causes incorrect LED behavior on one of the variants. Read the package variant from the read-only silicon identification bits in AN8811HB_HWTRAP2 at probe time and store it in priv->is_an8811hbcn. Add an8811hb_led_gpio_setup() to configure the correct GPIO output pins and select lines based on the detected variant, and call it from config_init. Signed-off-by: Weiting Lee Link: https://patch.msgid.link/20260907015638.2875763-1-weiting.lee@airoha.com Signed-off-by: Paolo Abeni --- drivers/net/phy/air_en8811h.c | 67 ++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index 16a9171cb838..a03d63dd4ac9 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -145,10 +145,22 @@ #define AN8811HB_GPIO_OUTPUT 0x5cf8b8 #define AN8811HB_GPIO_OUTPUT_345 (BIT(3) | BIT(4) | BIT(5)) +#define AN8811HB_GPIO_OUTPUT_0115 (BIT(0) | BIT(1) | BIT(15)) + +#define AN8811HB_GPIO_SEL1 0x5cf8bc +#define AN8811HB_GPIO_SEL1_0_MASK GENMASK(3, 0) +#define AN8811HB_GPIO_SEL1_1_MASK GENMASK(7, 4) +#define AN8811HB_GPIO_SEL1_0 BIT(0) +#define AN8811HB_GPIO_SEL1_1 0 + +#define AN8811HB_GPIO_SEL2 0x5cf8c0 +#define AN8811HB_GPIO_SEL2_15_MASK GENMASK(31, 28) +#define AN8811HB_GPIO_SEL2_15 BIT(29) #define AN8811HB_HWTRAP1 0x5cf910 #define AN8811HB_HWTRAP2 0x5cf914 #define AN8811HB_HWTRAP2_CKO BIT(28) +#define AN8811HB_HWTRAP2_PKG GENMASK(14, 12) #define AN8811HB_CLK_DRV 0x5cf9e4 #define AN8811HB_CLK_DRV_CKO_MASK GENMASK(14, 12) @@ -202,6 +214,7 @@ struct en8811h_priv { struct phy_device *phydev; unsigned int cko_is_enabled; struct mdio_device *pbusdev; + bool is_an8811hbcn; }; enum { @@ -1077,10 +1090,49 @@ static int en8811h_leds_setup(struct phy_device *phydev) return ret; } +static int an8811hb_led_gpio_setup(struct phy_device *phydev) +{ + struct en8811h_priv *priv = phydev->priv; + int ret; + + if (priv->is_an8811hbcn) { + /* AN8811HBCN: LED GPIOs are 0, 1, 15 */ + ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_OUTPUT, + AN8811HB_GPIO_OUTPUT_0115, + AN8811HB_GPIO_OUTPUT_0115); + if (ret < 0) + return ret; + + ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_SEL1, + AN8811HB_GPIO_SEL1_0_MASK | + AN8811HB_GPIO_SEL1_1_MASK, + AN8811HB_GPIO_SEL1_0 | + AN8811HB_GPIO_SEL1_1); + if (ret < 0) + return ret; + + ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_SEL2, + AN8811HB_GPIO_SEL2_15_MASK, + AN8811HB_GPIO_SEL2_15); + if (ret < 0) + return ret; + } else { + /* AN8811HBN: LED GPIOs are 3, 4, 5 */ + ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_OUTPUT, + AN8811HB_GPIO_OUTPUT_345, + AN8811HB_GPIO_OUTPUT_345); + if (ret < 0) + return ret; + } + + return 0; +} + static int an8811hb_probe(struct phy_device *phydev) { struct mdio_device *mdiodev; struct en8811h_priv *priv; + u32 reg_val; int ret; priv = devm_kzalloc(&phydev->mdio.dev, sizeof(struct en8811h_priv), @@ -1121,6 +1173,12 @@ static int an8811hb_probe(struct phy_device *phydev) /* MDIO_DEVS1/2 empty, so set mmds_present bits here */ phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; + /* Detect package variant */ + ret = air_phy_buckpbus_reg_read(phydev, AN8811HB_HWTRAP2, ®_val); + if (ret < 0) + goto err_dev_create; + priv->is_an8811hbcn = FIELD_GET(AN8811HB_HWTRAP2_PKG, reg_val); + ret = en8811h_leds_setup(phydev); if (ret < 0) goto err_dev_create; @@ -1269,10 +1327,11 @@ static int an8811hb_config_init(struct phy_device *phydev) return ret; } - /* Restore LED GPIO output enables after MCU initialization. */ - ret = air_phy_buckpbus_reg_modify(phydev, AN8811HB_GPIO_OUTPUT, - AN8811HB_GPIO_OUTPUT_345, - AN8811HB_GPIO_OUTPUT_345); + ret = an8811hb_led_gpio_setup(phydev); + if (ret < 0) { + phydev_err(phydev, "Failed to set up LED GPIO: %d\n", ret); + return ret; + } return ret; } From 2d2c2ea6650e423b83f89f919900124a625fd452 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:53 +0530 Subject: [PATCH 0391/2126] net: llc: fix repeated word 'all' in comment Drop the second 'all', reported by checkpatch.pl as a possible repeated word. Only touches a comment, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260908052602.27497-2-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- net/llc/llc_conn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c index 260460d50f54..4b6fe9a473cb 100644 --- a/net/llc/llc_conn.c +++ b/net/llc/llc_conn.c @@ -193,7 +193,7 @@ void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb) } /** - * llc_conn_resend_i_pdu_as_cmd - resend all all unacknowledged I PDUs + * llc_conn_resend_i_pdu_as_cmd - resend all unacknowledged I PDUs * @sk: active connection * @nr: NR * @first_p_bit: p_bit value of first pdu From a2c9decb21b25f9d667fbeb72117be5a312aaf7d Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:54 +0530 Subject: [PATCH 0392/2126] selftests: net: fix repeated word 'use' in comment Drop the second 'use', reported by checkpatch.pl as a possible repeated word. Only touches a comment, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260908052602.27497-3-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/xfrm_policy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/xfrm_policy.sh b/tools/testing/selftests/net/xfrm_policy.sh index 3eeeeffb4005..6294e49a46e0 100755 --- a/tools/testing/selftests/net/xfrm_policy.sh +++ b/tools/testing/selftests/net/xfrm_policy.sh @@ -242,7 +242,7 @@ check_exceptions() echo "PASS: ping to .254 bypassed ipsec tunnel ($logpostfix)" fi - # ping to .253 should use use ipsec due to direct policy exception. + # ping to .253 should use ipsec due to direct policy exception. check_xfrm 1 253 if [ $? -ne 0 ]; then echo "FAIL: expected ping to .253 to use ipsec tunnel ($logpostfix)" From a08b0a9e5e5fb0b05796dcbbc022bd7a16e24e4c Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:55 +0530 Subject: [PATCH 0393/2126] net: broadcom: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-4-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 2 +- drivers/net/ethernet/broadcom/bcm63xx_enet.h | 2 +- drivers/net/ethernet/broadcom/bcmsysport.h | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x.h | 4 ++-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c | 4 ++-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c | 8 ++++---- drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c index 7ef1babfeca6..f6595fdc888d 100644 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c @@ -1564,7 +1564,7 @@ static int bcm_enet_set_pauseparam(struct net_device *dev, if (priv->has_phy) { if (ecmd->autoneg && (ecmd->rx_pause != ecmd->tx_pause)) { - /* asymetric pause mode not supported, + /* asymmetric pause mode not supported, * actually possible but integrated PHY has RO * asym_pause bit */ return -EINVAL; diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.h b/drivers/net/ethernet/broadcom/bcm63xx_enet.h index 78f1830fb3cb..ba8f42cf5fb2 100644 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.h +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.h @@ -265,7 +265,7 @@ struct bcm_enet_priv { /* number of available descriptor for tx */ int tx_desc_count; - /* next tx descriptor avaiable */ + /* next tx descriptor available */ int tx_curr_desc; /* next dirty tx descriptor to reclaim */ diff --git a/drivers/net/ethernet/broadcom/bcmsysport.h b/drivers/net/ethernet/broadcom/bcmsysport.h index a34296f989f1..6f807e96dbd8 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.h +++ b/drivers/net/ethernet/broadcom/bcmsysport.h @@ -402,7 +402,7 @@ struct bcm_rsb { #define TDMA_DESC_RING_BASE(i) (TDMA_DESC_RING_00_BASE + \ ((i) * TDMA_DESC_RING_SIZE)) -/* Ring indexed register addreses */ +/* Ring indexed register addresses */ #define TDMA_DESC_RING_HEAD_TAIL_PTR(i) (TDMA_DESC_RING_BASE(i) + \ RING_HEAD_TAIL_PTR) #define TDMA_DESC_RING_COUNT(i) (TDMA_DESC_RING_BASE(i) + \ diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h index 9580ab83d387..28ea4a33f245 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h @@ -280,7 +280,7 @@ enum { * (db_msg_sz 1 << 7 * cid + 0x40 DPM offset) it can come up with a valid number * We must avoid coming up with cid 8 for iscsi since according to this method * the designated UIO cid will come out 0 and it has a special handling for that - * case which doesn't suit us. Therefore will will cieling to closes cid which + * case which doesn't suit us. Therefore will cieling to closes cid which * has least signigifcant nibble 8 and if it is 8 we will move forward to 0x18. */ @@ -666,7 +666,7 @@ struct bnx2x_fastpath { MAX_TX_DESC_CNT * NEXT_PAGE_TX_DESC_CNT) /* max BDs per tx packet w/o next_pages: * START_BD - describes packed - * START_BD(splitted) - includes unpaged data segment for GSO + * START_BD(split) - includes unpaged data segment for GSO * PARSING_BD - for TSO and CSUM data * PARSING_BD2 - for encapsulation data * Frag BDs - describes pages for frags diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c index 9af81630c8a4..3df8a5988521 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c @@ -1986,7 +1986,7 @@ static void bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device *netdev, int prio, return; /** - * bw_pct ignored - band-width percentage devision between user + * bw_pct ignored - band-width percentage division between user * priorities within the same group is not * standard and hence not supported * @@ -2038,7 +2038,7 @@ static void bnx2x_dcbnl_get_pg_tccfg_tx(struct net_device *netdev, int prio, DP(BNX2X_MSG_DCB, "prio = %d\n", prio); /** - * bw_pct ignored - band-width percentage devision between user + * bw_pct ignored - band-width percentage division between user * priorities within the same group is not * standard and hence not supported * diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h index 611efee75834..5297ab578a6f 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h @@ -2342,7 +2342,7 @@ struct shmem2_region { u32 oem_i2c_data_addr; }; - /* 9 entires for the C2S PCP map for each inner VLAN PCP + 1 default */ + /* 9 entries for the C2S PCP map for each inner VLAN PCP + 1 default */ /* For PCP values 0-3 use the map lower */ /* 0xFF000000 - PCP 0, 0x00FF0000 - PCP 1, * 0x0000FF00 - PCP 2, 0x000000FF PCP 3 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h index fc7fce642666..b5004aab124d 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h @@ -582,7 +582,7 @@ static void bnx2x_init_pxp_arb(struct bnx2x *bp, int r_order, REG_WR(bp, PXP2_REG_WR_CDU_MPS, val); } - /* Validate number of tags suppoted by device */ + /* Validate number of tags supported by device */ #define PCIE_REG_PCIER_TL_HDR_FC_ST 0x2980 val = REG_RD(bp, PCIE_REG_PCIER_TL_HDR_FC_ST); val &= 0xFF; diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c index ea310057fe3a..84d002b31920 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c @@ -2536,7 +2536,7 @@ static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl, } /** - * bnx2x_get_emac_base - retrive emac base address + * bnx2x_get_emac_base - retrieve emac base address * * @bp: driver handle * @mdc_mdio_access: access type @@ -3593,7 +3593,7 @@ static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy, u8 ret = 0; vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE; if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) { - /* Update the advertised flow-controled of LD/LP in AN */ + /* Update the advertised flow-controlled of LD/LP in AN */ if (phy->req_line_speed == SPEED_AUTO_NEG) bnx2x_ext_phy_update_adv_fc(phy, params, vars); /* But set the flow-control result as the requested one */ @@ -3743,7 +3743,7 @@ static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy, {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0}, }; DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n"); - /* Set to default registers that may be overriden by 10G force */ + /* Set to default registers that may be overridden by 10G force */ for (i = 0; i < ARRAY_SIZE(reg_set); i++) bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg, reg_set[i].val); @@ -5425,7 +5425,7 @@ static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy, /* Resolve from gp_status in case of AN complete and not sgmii */ if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) { - /* Update the advertised flow-controled of LD/LP in AN */ + /* Update the advertised flow-controlled of LD/LP in AN */ if (phy->req_line_speed == SPEED_AUTO_NEG) bnx2x_update_adv_fc(phy, params, vars, gp_status); /* But set the flow-control result as the requested one */ diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c index 39eb6ab5f805..277c7bd9c6e7 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c @@ -12669,7 +12669,7 @@ static int bnx2x_set_mc_list(struct bnx2x *bp) if (rc) return rc; - /* Override the curently configured set of mc filters */ + /* Override the currently configured set of mc filters */ rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_SET); if (rc < 0) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h index a018f251d198..30943f347164 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h @@ -2236,7 +2236,7 @@ extern const u32 dmae_reg_go_c[]; /* [RW 1] Output enable for TX PAUSE signal to the MAC. */ #define NIG_REG_P0_MAC_PAUSE_OUT_EN 0x185b4 /* [RW 32] Eight 4-bit configurations for specifying which COS (0-15 for - * future expansion) each priorty is to be mapped to. Bits 3:0 specify the + * future expansion) each priority is to be mapped to. Bits 3:0 specify the * COS for priority 0. Bits 31:28 specify the COS for priority 7. The 3-bit * priority field is extracted from the outer-most VLAN in receive packet. * Only COS 0 and COS 1 are supported in E2. */ @@ -2434,7 +2434,7 @@ extern const u32 dmae_reg_go_c[]; /* [RW 1] Output enable for TX PAUSE signal to the MAC. */ #define NIG_REG_P1_MAC_PAUSE_OUT_EN 0x185c8 /* [RW 32] Eight 4-bit configurations for specifying which COS (0-15 for - * future expansion) each priorty is to be mapped to. Bits 3:0 specify the + * future expansion) each priority is to be mapped to. Bits 3:0 specify the * COS for priority 0. Bits 31:28 specify the COS for priority 7. The 3-bit * priority field is extracted from the outer-most VLAN in receive packet. * Only COS 0 and COS 1 are supported in E2. */ From 405829119fdc8df5fe894ba21834a0968110d0f0 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:56 +0530 Subject: [PATCH 0394/2126] net: cavium: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-5-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cavium/liquidio/cn66xx_device.c | 2 +- drivers/net/ethernet/cavium/liquidio/lio_core.c | 2 +- drivers/net/ethernet/cavium/liquidio/octeon_config.h | 4 ++-- drivers/net/ethernet/cavium/liquidio/octeon_iq.h | 2 +- drivers/net/ethernet/cavium/liquidio/octeon_main.h | 2 +- drivers/net/ethernet/cavium/liquidio/octeon_nic.h | 2 +- drivers/net/ethernet/cavium/liquidio/request_manager.c | 2 +- drivers/net/ethernet/cavium/thunder/nic.h | 2 +- drivers/net/ethernet/cavium/thunder/nic_main.c | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/cn66xx_device.c b/drivers/net/ethernet/cavium/liquidio/cn66xx_device.c index 93fccfec288d..d3ebbb40579e 100644 --- a/drivers/net/ethernet/cavium/liquidio/cn66xx_device.c +++ b/drivers/net/ethernet/cavium/liquidio/cn66xx_device.c @@ -177,7 +177,7 @@ static void lio_cn66xx_setup_pkt_ctl_regs(struct octeon_device *oct) /* 66XX SPECIFIC */ if (CFG_GET_OQ_MAX_Q(cn6xxx->conf) <= 4) - /* Disable RING_EN if only upto 4 rings are used. */ + /* Disable RING_EN if only up to 4 rings are used. */ pktctl &= ~(1 << 4); else pktctl |= (1 << 4); diff --git a/drivers/net/ethernet/cavium/liquidio/lio_core.c b/drivers/net/ethernet/cavium/liquidio/lio_core.c index 93b06d599eed..bed450bfad38 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_core.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_core.c @@ -565,7 +565,7 @@ static int octeon_setup_droq(struct octeon_device *oct, int q_no, int num_descs, } /** - * liquidio_push_packet - Routine to push packets arriving on Octeon interface upto network layer. + * liquidio_push_packet - Routine to push packets arriving on Octeon interface up to network layer. * @octeon_id:octeon device id. * @skbuff: skbuff struct to be passed to network layer. * @len: size of total data received. diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_config.h b/drivers/net/ethernet/cavium/liquidio/octeon_config.h index 24c212001212..d2d64edaf3bf 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_config.h +++ b/drivers/net/ethernet/cavium/liquidio/octeon_config.h @@ -254,7 +254,7 @@ struct octeon_oq_config { u64 pkts_per_intr:16; /** Interrupt Coalescing (Time Interval). Octeon will interrupt the - * host if atleast one packet was sent in the time interval specified + * host if at least one packet was sent in the time interval specified * by this field. The driver uses time interval interrupt coalescing * by default. The time is specified in microseconds. */ @@ -296,7 +296,7 @@ struct octeon_oq_config { u64 oq_intr_pkt:16; /** Interrupt Coalescing (Time Interval). Octeon will interrupt the - * host if atleast one packet was sent in the time interval specified + * host if at least one packet was sent in the time interval specified * by this field. The driver uses time interval interrupt coalescing * by default. The time is specified in microseconds. */ diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_iq.h b/drivers/net/ethernet/cavium/liquidio/octeon_iq.h index a04f36a0e1a0..fdd7d3a77a2d 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_iq.h +++ b/drivers/net/ethernet/cavium/liquidio/octeon_iq.h @@ -70,7 +70,7 @@ struct oct_iq_stats { /** The instruction (input) queue. * The input queue is used to post raw (instruction) mode data or packet - * data to Octeon device from the host. Each input queue (upto 4) for + * data to Octeon device from the host. Each input queue (up to 4) for * a Octeon device has one such structure to represent it. */ struct octeon_instr_queue { diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_main.h b/drivers/net/ethernet/cavium/liquidio/octeon_main.h index 953edf0c7096..d2a52673cac5 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_main.h +++ b/drivers/net/ethernet/cavium/liquidio/octeon_main.h @@ -166,7 +166,7 @@ err_release_region: * errno -EINTR: user abort the command. * errno -ETIME: user spefified timeout value has been expired. * errno -EBUSY: the response of the request does not return in - * resonable time (LIO_SC_MAX_TMO_MS). + * reasonable time (LIO_SC_MAX_TMO_MS). * the sc wll be move to zombie response list by * lio_process_ordered_list() * diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_nic.h b/drivers/net/ethernet/cavium/liquidio/octeon_nic.h index c139fc423764..8341faaa0c24 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_nic.h +++ b/drivers/net/ethernet/cavium/liquidio/octeon_nic.h @@ -277,7 +277,7 @@ int octnet_send_nic_data_pkt(struct octeon_device *oct, /** Send a NIC control packet to the device * @param oct - octeon device pointer - * @param nctrl - control structure with command, timout, and callback info + * @param nctrl - control structure with command, timeout, and callback info * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if the * queue should be stopped, and IQ_SEND_OK if it sent okay. */ diff --git a/drivers/net/ethernet/cavium/liquidio/request_manager.c b/drivers/net/ethernet/cavium/liquidio/request_manager.c index d7cfb20eea00..a983e7f79461 100644 --- a/drivers/net/ethernet/cavium/liquidio/request_manager.c +++ b/drivers/net/ethernet/cavium/liquidio/request_manager.c @@ -40,7 +40,7 @@ static void __check_db_timeout(struct octeon_device *oct, u64 iq_no); static void (*reqtype_free_fn[MAX_OCTEON_DEVICES][REQTYPE_LAST + 1]) (void *); -/* Define this to return the request status comaptible to old code */ +/* Define this to return the request status compatible to old code */ /*#define OCTEON_USE_OLD_REQ_STATUS*/ /* Return 0 on success, 1 on failure */ diff --git a/drivers/net/ethernet/cavium/thunder/nic.h b/drivers/net/ethernet/cavium/thunder/nic.h index 090d6b83982a..bb3f4fa6b995 100644 --- a/drivers/net/ethernet/cavium/thunder/nic.h +++ b/drivers/net/ethernet/cavium/thunder/nic.h @@ -97,7 +97,7 @@ * This value ensures that once a packet has been "accepted" * for reception it will not get dropped due to non-availability * of CQ descriptor. An errata in HW mandates this value to be - * atleast 0x100. + * at least 0x100. */ #define NICPF_CQM_MIN_DROP_LEVEL 0x100 diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c b/drivers/net/ethernet/cavium/thunder/nic_main.c index 0ec65ec634df..086f32b61580 100644 --- a/drivers/net/ethernet/cavium/thunder/nic_main.c +++ b/drivers/net/ethernet/cavium/thunder/nic_main.c @@ -595,7 +595,7 @@ static void nic_config_rss(struct nicpf *nic, struct rss_cfg_msg *cfg) nic_reg_write(nic, idx_addr | (cpi_base << 3), cpi_cfg); } -/* 4 level transmit side scheduler configutation +/* 4 level transmit side scheduler configuration * for TNS bypass mode * * Sample configuration for SQ0 on 88xx From 12ae2a2b298a124874492d48a4052ffd75ccb5e9 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:57 +0530 Subject: [PATCH 0395/2126] net: qlogic: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-6-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c | 2 +- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 2 +- drivers/net/ethernet/qlogic/qed/qed_mcp.h | 2 +- drivers/net/ethernet/qlogic/qlcnic/qlcnic.h | 2 +- drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c | 4 ++-- drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 2 +- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c index fef4b2b0b1f2..79d6a819bf90 100644 --- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c @@ -17,7 +17,7 @@ netxen_poll_rsp(struct netxen_adapter *adapter) int timeout = 0; do { - /* give atleast 1ms for firmware to respond */ + /* give at least 1ms for firmware to respond */ msleep(1); if (++timeout > NX_OS_CRB_RETRY_COUNT) diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c b/drivers/net/ethernet/qlogic/qed/qed_cxt.c index b70262e70baf..89b947f82cf0 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c +++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c @@ -561,7 +561,7 @@ int qed_cxt_cfg_ilt_compute(struct qed_hwfn *p_hwfn, u32 *line_count) * block in the ILT client. This is later used to * configure the CDU segment offset registers and * results in an FL command for TIDs of this - * segement behaves as regular load commands + * segment behaves as regular load commands * (loading TIDs from the working memory). */ line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line; diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.h b/drivers/net/ethernet/qlogic/qed/qed_mcp.h index 9bd0565fe8ab..50699d600b8e 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_mcp.h +++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.h @@ -783,7 +783,7 @@ struct qed_mcp_info { u16 mfw_mb_length; u32 mcp_hist; - /* Capabilties negotiated with the MFW */ + /* Capabilities negotiated with the MFW */ u32 capabilities; /* S/N for debug data mailbox commands */ diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h b/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h index d7c8fadb49de..9728d583b891 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h @@ -909,7 +909,7 @@ struct qlcnic_mac_vlan_list { #define QLCNIC_LRO_REQUEST_CLEANUP 4 -/* Capabilites received */ +/* Capabilities received */ #define QLCNIC_FW_CAPABILITY_TSO BIT_1 #define QLCNIC_FW_CAPABILITY_BDG BIT_8 #define QLCNIC_FW_CAPABILITY_FVLANTX BIT_9 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c index 47cd9ec665ee..ff337a917243 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c @@ -1957,9 +1957,9 @@ static void qlcnic_83xx_template_end(struct qlcnic_adapter *p_dev) * qlcnic_83xx_exec_template_cmd * * @p_dev: adapter structure -* @p_buff: Poiter to instruction template +* @p_buff: Pointer to instruction template * -* Template provides instructions to stop, restart and initalize firmware. +* Template provides instructions to stop, restart and initialize firmware. * These instructions are abstracted as a series of read, write and * poll operations on hardware registers. Register information and operation * specifics are not exposed to the driver. Driver reads the template from diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c index eb827b86ecae..1b94c42d669b 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c @@ -95,7 +95,7 @@ qlcnic_poll_rsp(struct qlcnic_adapter *adapter) int timeout = 0, err = 0; do { - /* give atleast 1ms for firmware to respond */ + /* give at least 1ms for firmware to respond */ mdelay(1); if (++timeout > QLCNIC_OS_CRB_RETRY_COUNT) diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c index ff4f7cd20c79..23ae76ca81db 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c @@ -640,7 +640,7 @@ static int qlcnic_max_rings(struct qlcnic_adapter *adapter, u8 ring_cnt, void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt) { - /* 83xx adapter does not have max_tx_rings intialized in probe */ + /* 83xx adapter does not have max_tx_rings initialized in probe */ if (adapter->max_tx_rings) adapter->drv_tx_rings = qlcnic_max_rings(adapter, tx_cnt, QLCNIC_TX_QUEUE); @@ -650,7 +650,7 @@ void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt) void qlcnic_set_sds_ring_count(struct qlcnic_adapter *adapter, u8 rx_cnt) { - /* 83xx adapter does not have max_sds_rings intialized in probe */ + /* 83xx adapter does not have max_sds_rings initialized in probe */ if (adapter->max_sds_rings) adapter->drv_sds_rings = qlcnic_max_rings(adapter, rx_cnt, QLCNIC_RX_QUEUE); From ef7ed063b48ff3de9df36098d78b9f23e6876a26 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:58 +0530 Subject: [PATCH 0396/2126] net: fddi: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-7-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/fddi/skfp/cfm.c | 2 +- drivers/net/fddi/skfp/ecm.c | 2 +- drivers/net/fddi/skfp/fplustm.c | 4 ++-- drivers/net/fddi/skfp/h/hwmtm.h | 2 +- drivers/net/fddi/skfp/h/sba.h | 2 +- drivers/net/fddi/skfp/pcmplc.c | 2 +- drivers/net/fddi/skfp/rmt.c | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/fddi/skfp/cfm.c b/drivers/net/fddi/skfp/cfm.c index 4eea3408034b..b722a195d831 100644 --- a/drivers/net/fddi/skfp/cfm.c +++ b/drivers/net/fddi/skfp/cfm.c @@ -17,7 +17,7 @@ */ /* - * Hardware independent state machine implemantation + * Hardware independent state machine implementation * The following external SMT functions are referenced : * * queue_event() diff --git a/drivers/net/fddi/skfp/ecm.c b/drivers/net/fddi/skfp/ecm.c index 2f5f5f26bb43..e418ab65cb61 100644 --- a/drivers/net/fddi/skfp/ecm.c +++ b/drivers/net/fddi/skfp/ecm.c @@ -17,7 +17,7 @@ */ /* - * Hardware independent state machine implemantation + * Hardware independent state machine implementation * The following external SMT functions are referenced : * * queue_event() diff --git a/drivers/net/fddi/skfp/fplustm.c b/drivers/net/fddi/skfp/fplustm.c index 036062376c06..0d4201345f9b 100644 --- a/drivers/net/fddi/skfp/fplustm.c +++ b/drivers/net/fddi/skfp/fplustm.c @@ -150,7 +150,7 @@ static u_long read_mdr(struct s_smc *smc, unsigned int addr) CHECK_NPP() ; MARR(addr) ; outpw(FM_A(FM_CMDREG1),FM_IRMEMWO) ; - CHECK_NPP() ; /* needed for PCI to prevent from timeing violations */ + CHECK_NPP() ; /* needed for PCI to prevent from timing violations */ /* p = MDRR() ; */ /* bad read values if the workaround */ /* smc->hw.mc_dummy = *((short volatile far *)(addr)))*/ /* is used */ @@ -572,7 +572,7 @@ Note After any ring operational change the transmit complete The operating system dependent module must enable the transmit complete interrupt of a queue, - when it queues the first frame, - because of no transmit resources are beeing + because of no transmit resources are being available and - when it escapes from the function llc_restart_tx while some frames are still queued. diff --git a/drivers/net/fddi/skfp/h/hwmtm.h b/drivers/net/fddi/skfp/h/hwmtm.h index e97db826cdd4..0ab49cc0a8bd 100644 --- a/drivers/net/fddi/skfp/h/hwmtm.h +++ b/drivers/net/fddi/skfp/h/hwmtm.h @@ -113,7 +113,7 @@ struct hw_modul { struct s_mbuf_pool mbuf_pool ; struct hwm_r r ; - union s_fp_descr volatile *descr_p ; /* points to the desriptor area */ + union s_fp_descr volatile *descr_p ; /* points to the descriptor area */ u_short pass_SMT ; /* pass SMT frames */ u_short pass_NSA ; /* pass all NSA frames */ diff --git a/drivers/net/fddi/skfp/h/sba.h b/drivers/net/fddi/skfp/h/sba.h index f30301fcd022..7fe99c12e201 100644 --- a/drivers/net/fddi/skfp/h/sba.h +++ b/drivers/net/fddi/skfp/h/sba.h @@ -94,7 +94,7 @@ struct s_sba { long msg_mib_ov ; /* Current Overhead for this Path*/ long msg_category ; /* Category of the Allocation */ u_long msg_max_t_neg ; /* longest T_Neg acceptable */ - u_long msg_min_seg_siz ; /* minimum segement size */ + u_long msg_min_seg_siz ; /* minimum segment size */ struct smt_header *sm ; /* points to the rec message */ struct fddi_addr *msg_alloc_addr ; /* Allocation Address */ diff --git a/drivers/net/fddi/skfp/pcmplc.c b/drivers/net/fddi/skfp/pcmplc.c index 90e8df6d9a88..745285d4d6d2 100644 --- a/drivers/net/fddi/skfp/pcmplc.c +++ b/drivers/net/fddi/skfp/pcmplc.c @@ -16,7 +16,7 @@ */ /* - * Hardware independent state machine implemantation + * Hardware independent state machine implementation * The following external SMT functions are referenced : * * queue_event() diff --git a/drivers/net/fddi/skfp/rmt.c b/drivers/net/fddi/skfp/rmt.c index 314623650a84..5708124f05d2 100644 --- a/drivers/net/fddi/skfp/rmt.c +++ b/drivers/net/fddi/skfp/rmt.c @@ -16,7 +16,7 @@ */ /* - * Hardware independent state machine implemantation + * Hardware independent state machine implementation * The following external SMT functions are referenced : * * queue_event() From 36ca708b7cc7dd224c2e2ef257f68e06fbc15837 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:55:59 +0530 Subject: [PATCH 0397/2126] net: marvell: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Ratheesh Kannoth Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260908052602.27497-8-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 2 +- drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 8 ++++---- drivers/net/ethernet/marvell/octeontx2/af/npc.h | 4 ++-- drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 2 +- drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c | 2 +- drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c | 2 +- drivers/net/ethernet/marvell/pxa168_eth.c | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h index 061fcd444d50..3ed5670f01c2 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h @@ -729,7 +729,7 @@ #define MVPP2_MAX_TXQ 8 /* MVPP2_MAX_TSO_SEGS is the maximum number of fragments to allow in the GSO - * skb. As we need a maxium of two descriptors per fragments (1 header, 1 data), + * skb. As we need a maximum of two descriptors per fragments (1 header, 1 data), * multiply this value by two to count the maximum number of skb descs needed. */ #define MVPP2_MAX_TSO_SEGS 300 diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c index 93e978bdf303..ad677cfddb4d 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c @@ -382,7 +382,7 @@ static int mvpp2_prs_flow_find(struct mvpp2 *priv, int flow) struct mvpp2_prs_entry pe; int tid; - /* Go through the all entires with MVPP2_PRS_LU_FLOWS */ + /* Go through the all entries with MVPP2_PRS_LU_FLOWS */ for (tid = MVPP2_PRS_TCAM_SRAM_SIZE - 1; tid >= 0; tid--) { u8 bits; @@ -1212,7 +1212,7 @@ static void mvpp2_prs_mh_init(struct mvpp2 *priv) mvpp2_prs_hw_write(priv, &pe); } -/* Set default entires (place holder) for promiscuous, non-promiscuous and +/* Set default entries (place holder) for promiscuous, non-promiscuous and * multicast MAC addresses */ static void mvpp2_prs_mac_init(struct mvpp2 *priv) @@ -2241,7 +2241,7 @@ mvpp2_prs_mac_da_range_find(struct mvpp2 *priv, int pmap, const u8 *da, struct mvpp2_prs_entry pe; int tid; - /* Go through the all entires with MVPP2_PRS_LU_MAC */ + /* Go through the all entries with MVPP2_PRS_LU_MAC */ for (tid = MVPP2_PE_MAC_RANGE_START; tid <= MVPP2_PE_MAC_RANGE_END; tid++) { unsigned int entry_pmap; @@ -2539,7 +2539,7 @@ int mvpp2_prs_def_flow(struct mvpp2_port *port) /* Such entry not exist */ if (tid < 0) { - /* Go through the all entires from last to first */ + /* Go through the all entries from last to first */ tid = mvpp2_prs_tcam_first_free(port->priv, MVPP2_PE_LAST_FREE_TID, MVPP2_PE_FIRST_FREE_TID); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/npc.h b/drivers/net/ethernet/marvell/octeontx2/af/npc.h index 719b3618eeb5..309244fe8754 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/npc.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/npc.h @@ -84,7 +84,7 @@ enum npc_kpu_lc_ltype { NPC_LT_LC_CUSTOM1 = 0xF, }; -/* Don't modify Ltypes upto SCTP, otherwise it will +/* Don't modify Ltypes up to SCTP, otherwise it will * effect flow tag calculation and thus RSS. */ enum npc_kpu_ld_ltype { @@ -140,7 +140,7 @@ enum npc_kpu_lg_ltype { NPC_LT_LG_CUSTOM1 = 0xF, }; -/* Don't modify Ltypes upto SCTP, otherwise it will +/* Don't modify Ltypes up to SCTP, otherwise it will * effect flow tag calculation and thus RSS. */ enum npc_kpu_lh_ltype { diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c index 153eb57bad06..d80d2c00bd84 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -4974,7 +4974,7 @@ static void rvu_nix_setup_capabilities(struct rvu *rvu, int blkaddr) /* On OcteonTx2 DWRR quantum is directly configured into each of * the transmit scheduler queues. And PF/VF drivers were free to - * config any value upto 2^24. + * config any value up to 2^24. * On CN10K, HW is modified, the quantum configuration at scheduler * queues is in terms of weight. And SW needs to setup a base DWRR MTU * at NIX_AF_DWRR_RPM_MTU / NIX_AF_DWRR_SDP_MTU. HW will do diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c b/drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c index 3e1bf22cba69..f98ef5431c90 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c @@ -301,7 +301,7 @@ static void cn10k_get_ingress_rate_cfg(u64 rate, u32 *rate_exp, * policer timeunit * 2^rdiv ie 2 * 2^rdiv usecs, to the token bucket. * Here policer timeunit is 2 usecs and rate is in bits per sec. * Since floating point cannot be used below algorithm uses 1000000 - * scale factor to support rates upto 100Gbps. + * scale factor to support rates up to 100Gbps. */ tmp = rate * 32 * 2; if (tmp < 256000000) { diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c index f110dfa42360..91d346d114af 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c @@ -67,7 +67,7 @@ static int otx2_pfc_txschq_alloc_one(struct otx2_nic *pfvf, u8 prio) if (!req) return -ENOMEM; - /* Request one schq per level upto max level as configured + /* Request one schq per level up to max level as configured * link config level. These rest of the scheduler can be * same as hw.txschq_list. */ diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c index bbbbbba63e15..2370b2ddba6b 100644 --- a/drivers/net/ethernet/marvell/pxa168_eth.c +++ b/drivers/net/ethernet/marvell/pxa168_eth.c @@ -514,7 +514,7 @@ static int add_del_hash_entry(struct pxa168_eth_private *pep, /* * ---------------------------------------------------------------------------- * Create an addressTable entry from MAC address info - * found in the specifed net_device struct + * found in the specified net_device struct * * Input : pointer to ethernet interface network device structure * Output : N/A @@ -806,7 +806,7 @@ static int rxq_process(struct net_device *dev, int budget) stats->rx_bytes += rx_desc->byte_cnt; /* * In case received a packet without first / last bits on OR - * the error summary bit is on, the packets needs to be droped. + * the error summary bit is on, the packets needs to be dropped. */ if (((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) != (RX_FIRST_DESC | RX_LAST_DESC)) From 1b4109e4a024eb51b5b81fcaed511256e0ce502e Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:56:00 +0530 Subject: [PATCH 0398/2126] net: hisilicon: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Reviewed-by: Jijie Shao Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-9-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 2 +- drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c | 2 +- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 4 ++-- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 +- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 2 +- drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c index 91391a49fcea..a59fd280a045 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c @@ -591,7 +591,7 @@ static int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, bool en) #define HILINK_ACCESS_SEL_CFG 0x40008 /* hilink4 & hilink3 use the same xge training and * xge u adaptor. There is a hilink access sel cfg - * register to select which one to be configed + * register to select which one to be configured */ if ((!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) && (mac_cb->mac_id <= 3)) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c index 5013beb4d282..408d36d85fb1 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c @@ -139,7 +139,7 @@ static void hns_ppe_set_vlan_strip(struct hns_ppe_cb *ppe_cb, int en) } /** - * hns_ppe_checksum_hw - set ppe checksum caculate + * hns_ppe_checksum_hw - set ppe checksum calculate * @ppe_cb: ppe device * @value: value */ diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c index e905f10b894e..d819d2bb3450 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -1230,7 +1230,7 @@ static void hns_nic_update_stats(struct net_device *netdev) h->dev->ops->update_stats(h, &netdev->stats); } -/* set mac addr if it is configed. or leave it to the AE driver */ +/* set mac addr if it is configured. or leave it to the AE driver */ static void hns_init_mac_addr(struct net_device *ndev) { struct hns_nic_priv *priv = netdev_priv(ndev); @@ -2317,7 +2317,7 @@ static int hns_nic_dev_probe(struct platform_device *pdev) ret = device_property_read_u32(dev, "port-id", &port_id); if (ret) goto out_read_prop_fail; - /* for old dts, we need to caculate the port offset */ + /* for old dts, we need to calculate the port offset */ port_id = port_id < HNS_SRV_OFFSET ? port_id + HNS_DEBUG_OFFSET : port_id - HNS_SRV_OFFSET; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index e43bd2035edb..d117a0b442d0 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -10522,7 +10522,7 @@ static int hclge_get_link_diagnosis_info(struct hnae3_handle *handle, } /* After disable sriov, VF still has some config and info need clean, - * which configed by PF. + * which configured by PF. */ static void hclge_clear_vport_vf_info(struct hclge_vport *vport, int vfid) { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c index 00c3f2548bf6..bf533b8f46ae 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c @@ -35,7 +35,7 @@ enum hclge_shaper_level { * IR(Mbps) = ------------------------- * CLOCK(1000Mbps) * Tick * (2 ^ IR_s) * - * @return: 0: calculate sucessful, negative: fail + * @return: 0: calculate successful, negative: fail */ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level, struct hclge_shaper_ir_para *ir_para, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index 063a692c2b41..5d14d29b0296 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -1880,7 +1880,7 @@ static void hclgevf_reset_service_task(struct hclgevf_dev *hdev) * from PF as cmdq would be in unreliable state i.e. mailbox * communication between PF and VF would be broken. * - * if we are never geting into pending state it means either: + * if we are never getting into pending state it means either: * 1. PF is not receiving our request which could be due to IMP * reset * 2. PF is screwed From eeea715379b27a27350b2f77ed36213177229671 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:56:01 +0530 Subject: [PATCH 0399/2126] net: atheros: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-10-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/atheros/atl1c/atl1c_hw.h | 2 +- drivers/net/ethernet/atheros/atl1e/atl1e.h | 2 +- drivers/net/ethernet/atheros/atl1e/atl1e_hw.c | 2 +- drivers/net/ethernet/atheros/atl1e/atl1e_main.c | 2 +- drivers/net/ethernet/atheros/atlx/atl1.c | 2 +- drivers/net/ethernet/atheros/atlx/atl2.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h b/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h index c567c920628f..8f03bb561d44 100644 --- a/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h @@ -659,7 +659,7 @@ void atl1c_post_phy_linkchg(struct atl1c_hw *hw, u16 link_speed); /* INT-triggle/SMB Control Register */ #define REG_SMB_STAT_TIMER 0x15C4 /* 2us resolution */ #define SMB_STAT_TIMER_MASK 0xFFFFFF -#define REG_TINT_TPD_THRESH 0x15C8 /* tpd th to trig intrrupt */ +#define REG_TINT_TPD_THRESH 0x15C8 /* tpd th to trig interrupt */ /* Mail box */ #define MB_RFDX_PROD_IDX_MASK 0xFFFF diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e.h b/drivers/net/ethernet/atheros/atl1e/atl1e.h index 9fcad783c939..6b0066f47e9e 100644 --- a/drivers/net/ethernet/atheros/atl1e/atl1e.h +++ b/drivers/net/ethernet/atheros/atl1e/atl1e.h @@ -381,7 +381,7 @@ struct atl1e_rx_page { u8 *addr; /* receive rage virtual address */ dma_addr_t write_offset_dma; /* the DMA address which contain the receive data offset in the page */ - u32 *write_offset_addr; /* the virtaul address which contain + u32 *write_offset_addr; /* the virtual address which contain the receive data offset in the page */ u32 read_offset; /* the offset where we have read */ }; diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_hw.c b/drivers/net/ethernet/atheros/atl1e/atl1e_hw.c index fa89bc27f62d..25d3e7469058 100644 --- a/drivers/net/ethernet/atheros/atl1e/atl1e_hw.c +++ b/drivers/net/ethernet/atheros/atl1e/atl1e_hw.c @@ -369,7 +369,7 @@ static int atl1e_phy_setup_autoneg_adv(struct atl1e_hw *hw) * * hw - Struct containing variables accessed by shared code * - * Sets bit 15 and 12 of the MII control regiser (for F001 bug) + * Sets bit 15 and 12 of the MII control register (for F001 bug) */ int atl1e_phy_commit(struct atl1e_hw *hw) { diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c index 40290028580b..cc6c262868a5 100644 --- a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c +++ b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c @@ -2117,7 +2117,7 @@ static int atl1e_suspend(struct pci_dev *pdev, pm_message_t state) wol_ctrl_data |= WOL_MAGIC_EN | WOL_MAGIC_PME_EN; if (wufc & AT_WUFC_LNKC) { - /* if orignal link status is link, just wait for retrive link */ + /* if original link status is link, just wait for retrieve link */ if (mii_bmsr_data & BMSR_LSTATUS) { for (i = 0; i < AT_SUSPEND_LINK_TIMEOUT; i++) { msleep(100); diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c index 98a4d089270e..179d74e93efd 100644 --- a/drivers/net/ethernet/atheros/atlx/atl1.c +++ b/drivers/net/ethernet/atheros/atlx/atl1.c @@ -628,7 +628,7 @@ static s32 atl1_phy_leave_power_saving(struct atl1_hw *hw) * Resets the PHY and make all config validate * hw - Struct containing variables accessed by shared code * - * Sets bit 15 and 12 of the MII Control regiser (for F001 bug) + * Sets bit 15 and 12 of the MII Control register (for F001 bug) */ static s32 atl1_phy_reset(struct atl1_hw *hw) { diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c index 5560d5cc3169..c9aca219ec9c 100644 --- a/drivers/net/ethernet/atheros/atlx/atl2.c +++ b/drivers/net/ethernet/atheros/atlx/atl2.c @@ -2591,7 +2591,7 @@ static s32 atl2_phy_setup_autoneg_adv(struct atl2_hw *hw) * * hw - Struct containing variables accessed by shared code * - * Sets bit 15 and 12 of the MII Control regiser (for F001 bug) + * Sets bit 15 and 12 of the MII Control register (for F001 bug) */ static s32 atl2_phy_commit(struct atl2_hw *hw) { From f36cb539fd9718d48f88d6e8c6afe25e2178c4c6 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Tue, 8 Sep 2026 10:56:02 +0530 Subject: [PATCH 0400/2126] net: dec: fix typos in comments Fix misspellings in comments, found with scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Comments only, no code changes. Signed-off-by: Hemanth Selam Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260908052602.27497-11-hemanth.selam@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/dec/tulip/de2104x.c | 2 +- drivers/net/ethernet/dec/tulip/interrupt.c | 4 ++-- drivers/net/ethernet/dec/tulip/media.c | 2 +- drivers/net/ethernet/dec/tulip/tulip.h | 4 ++-- drivers/net/ethernet/dec/tulip/winbond-840.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/dec/tulip/de2104x.c b/drivers/net/ethernet/dec/tulip/de2104x.c index f38a10c79907..fa52e099409c 100644 --- a/drivers/net/ethernet/dec/tulip/de2104x.c +++ b/drivers/net/ethernet/dec/tulip/de2104x.c @@ -373,7 +373,7 @@ static void de_rx_err_acct (struct de_private *de, unsigned rx_tail, rx_tail, status, len); if ((status & 0x38000300) != 0x0300) { - /* Ingore earlier buffers. */ + /* Ignore earlier buffers. */ if ((status & 0xffff) != 0x7fff) { netif_warn(de, rx_err, de->dev, "Oversized Ethernet frame spanned multiple buffers, status %08x!\n", diff --git a/drivers/net/ethernet/dec/tulip/interrupt.c b/drivers/net/ethernet/dec/tulip/interrupt.c index 0a12cb9b3ba7..8c02771b28e4 100644 --- a/drivers/net/ethernet/dec/tulip/interrupt.c +++ b/drivers/net/ethernet/dec/tulip/interrupt.c @@ -177,7 +177,7 @@ int tulip_poll(struct napi_struct *napi, int budget) pkt_len > 1518) { if ((status & (RxLengthOver2047 | RxWholePkt)) != RxWholePkt) { - /* Ingore earlier buffers. */ + /* Ignore earlier buffers. */ if ((status & 0xffff) != 0x7fff) { if (tulip_debug > 1) dev_warn(&dev->dev, @@ -408,7 +408,7 @@ static int tulip_rx(struct net_device *dev) pkt_len > 1518) { if ((status & (RxLengthOver2047 | RxWholePkt)) != RxWholePkt) { - /* Ingore earlier buffers. */ + /* Ignore earlier buffers. */ if ((status & 0xffff) != 0x7fff) { if (tulip_debug > 1) netdev_warn(dev, diff --git a/drivers/net/ethernet/dec/tulip/media.c b/drivers/net/ethernet/dec/tulip/media.c index 55d6fc99f40b..0c9694d2b38a 100644 --- a/drivers/net/ethernet/dec/tulip/media.c +++ b/drivers/net/ethernet/dec/tulip/media.c @@ -24,7 +24,7 @@ /* Read and write the MII registers using software-generated serial MDIO protocol. It is just different enough from the EEPROM protocol - to not share code. The maxium data clock rate is 2.5 Mhz. */ + to not share code. The maximum data clock rate is 2.5 Mhz. */ #define MDIO_SHIFT_CLK 0x10000 #define MDIO_DATA_WRITE0 0x00000 #define MDIO_DATA_WRITE1 0x20000 diff --git a/drivers/net/ethernet/dec/tulip/tulip.h b/drivers/net/ethernet/dec/tulip/tulip.h index 5e010e1fa6f7..e39e5c78d4cc 100644 --- a/drivers/net/ethernet/dec/tulip/tulip.h +++ b/drivers/net/ethernet/dec/tulip/tulip.h @@ -250,7 +250,7 @@ enum t21143_csr6_bits { csr6_ttm = (1<<22), /* Transmit Threshold Mode, set for 10baseT, 0 for 100BaseTX */ csr6_sf = (1<<21), /* Store and forward. If set ignores TR bits */ csr6_hbd = (1<<19), /* Heart beat disable. Disables SQE function in 10baseT */ - csr6_ps = (1<<18), /* Port Select. 0 (defualt) = 10baseT, 1 = 100baseTX: can't be set */ + csr6_ps = (1<<18), /* Port Select. 0 (default) = 10baseT, 1 = 100baseTX: can't be set */ csr6_ca = (1<<17), /* Collision Offset Enable. If set uses special algorithm in low collision situations */ csr6_trh = (1<<15), /* Transmit Threshold high bit */ csr6_trl = (1<<14), /* Transmit Threshold low bit */ @@ -274,7 +274,7 @@ enum t21143_csr6_bits { csr6_om_int_loop = (1<<10), /* internal (FIFO) loopback flag */ csr6_om_ext_loop = (1<<11), /* external (PMD) loopback flag */ /* set both and you get (PHY) loopback */ - csr6_fd = (1<<9), /* Full duplex mode, disables hearbeat, no loopback */ + csr6_fd = (1<<9), /* Full duplex mode, disables heartbeat, no loopback */ csr6_pm = (1<<7), /* Pass All Multicast */ csr6_pr = (1<<6), /* Promiscuous mode */ csr6_sb = (1<<5), /* Start(1)/Stop(0) backoff counter */ diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c index a5581f1d0141..be9199f55a8a 100644 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c @@ -1188,7 +1188,7 @@ static int netdev_rx(struct net_device *dev) break; if ((status & 0x38008300) != 0x0300) { if ((status & 0x38000300) != 0x0300) { - /* Ingore earlier buffers. */ + /* Ignore earlier buffers. */ if ((status & 0xffff) != 0x7fff) { dev_warn(&dev->dev, "Oversized Ethernet frame spanned multiple buffers, entry %#x status %04x!\n", From 93de43318ecdf0ff5f0e6125fe33a8b30fd10c66 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Thu, 13 Aug 2026 10:41:02 -0700 Subject: [PATCH 0401/2126] wifi: ath9k: use rcu_dereference_bh() for sta->rates in ath_merge_ratetbl() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit c4f518736472 ("wifi: ath9k: Remove redundant rcu_read_lock/unlock() in spin_lock") removed the explicit rcu_read_lock()/rcu_read_unlock() pair from ath_txq_schedule(), relying on spin_lock_bh() to provide an implicit RCU read-side critical section. That is correct on kernels without CONFIG_DEBUG_LOCK_ALLOC, where rcu_read_lock_any_held() falls back to !preemptible() as a proxy, and spin_lock_bh() disables preemption. However, rcu_dereference() in ath_merge_ratetbl() checks rcu_read_lock_held(), which under CONFIG_DEBUG_LOCK_ALLOC only returns true when lock_is_held(&rcu_lock_map) — set exclusively by an explicit rcu_read_lock(). A spin_lock_bh() does not set rcu_lock_map, so on a CONFIG_DEBUG_LOCK_ALLOC + CONFIG_PROVE_RCU kernel, any call path that reaches ath_merge_ratetbl() with a non-NULL sta will produce a lockdep splat. The correct fix is to use rcu_dereference_bh(), whose validity check calls rcu_read_lock_bh_held(), which returns true whenever BH is disabled (in_softirq() || irqs_disabled()). This matches the actual protection at all callers of ath_set_rates() that pass a non-NULL sta: they all hold a spin_lock_bh() (either sc->chan_lock or txq->axq_lock). Fixes: c4f518736472 ("wifi: ath9k: Remove redundant rcu_read_lock/unlock() in spin_lock") Assisted-by: LLM Acked-by: Toke Høiland-Jørgensen Link: https://patch.msgid.link/20260813-ath9k-rcu-fix-v1-1-424665a1ce60@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath9k/xmit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c index 89d8b3178784..3413bb4906d4 100644 --- a/drivers/net/wireless/ath/ath9k/xmit.c +++ b/drivers/net/wireless/ath/ath9k/xmit.c @@ -168,7 +168,7 @@ static bool ath_merge_ratetbl(struct ieee80211_sta *sta, struct ath_buf *bf, if (!sta) return false; - ratetbl = rcu_dereference(sta->rates); + ratetbl = rcu_dereference_bh(sta->rates); if (!ratetbl) return false; From c3bace8584ca707e34ba837f65c2e9d566af4c2c Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Tue, 11 Aug 2026 11:13:16 +0530 Subject: [PATCH 0402/2126] wifi: ath12k: add support to load shared firmware on multiPD IPQ5332 platform uses a MultiPD architecture where multiple firmware instances share common read-only code segments. The driver currently loads only the per-UserPD firmware, which leaves the shared read-only firmware unloaded. Add support for loading the shared read-only firmware once before the UserPDs are powered up. The shared segment contains common code that is identical across all UserPDs and reduces the total firmware memory requirement. Store the reserved memory mapping in struct ath12k_ahb_rproc_info so it can be shared by all UserPDs and mapped only once. Keep the mapping valid across UserPD power cycles, and unmap it when the last UserPD is removed. Shut down the shared firmware from the rproc deconfiguration path when the last UserPD is removed. Also, pass NULL for the reloc_base parameter because the driver uses fixed memory regions configured through device tree and does not need the adjusted physical address after relocation. Tested-on: IPQ5332 hw1.0 AHB WLAN.WBE.1.6-01275-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260811054316.518494-1-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/ahb.c | 166 +++++++++++++++++--- drivers/net/wireless/ath/ath12k/ahb.h | 9 ++ drivers/net/wireless/ath/ath12k/wifi7/ahb.c | 3 + 3 files changed, 157 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/ahb.c b/drivers/net/wireless/ath/ath12k/ahb.c index 0fc55c9169e1..3985f4e1c067 100644 --- a/drivers/net/wireless/ath/ath12k/ahb.c +++ b/drivers/net/wireless/ath/ath12k/ahb.c @@ -347,35 +347,60 @@ static void ath12k_ahb_stop(struct ath12k_base *ab) ath12k_ce_cleanup_pipes(ab); } +static int ath12k_ahb_get_fw_load_region(struct ath12k_base *ab) +{ + struct ath12k_ahb *ab_ahb = ath12k_ab_to_ahb(ab); + struct ath12k_ahb_rproc_info *rproc_info = ab_ahb->rproc_info; + struct device *dev = ab->dev; + struct resource res; + int ret; + + if (rproc_info->mem_region) + return 0; + + ret = of_reserved_mem_region_to_resource_byname(dev->of_node, "q6-region", &res); + if (ret) + return ret; + + rproc_info->mem_phys = res.start; + rproc_info->mem_size = resource_size(&res); + rproc_info->mem_region = memremap(rproc_info->mem_phys, rproc_info->mem_size, + MEMREMAP_WC); + if (!rproc_info->mem_region) { + ath12k_err(ab, "unable to map memory region: %pa+%zx\n", + &res.start, rproc_info->mem_size); + rproc_info->mem_phys = 0; + rproc_info->mem_size = 0; + return -ENOMEM; + } + + return 0; +} + +static void ath12k_ahb_put_fw_load_region(struct ath12k_ahb_rproc_info *rproc_info) +{ + memunmap(rproc_info->mem_region); + rproc_info->mem_region = NULL; + rproc_info->mem_phys = 0; + rproc_info->mem_size = 0; +} + static int ath12k_ahb_power_up(struct ath12k_base *ab) { struct ath12k_ahb *ab_ahb = ath12k_ab_to_ahb(ab); + struct ath12k_ahb_rproc_info *rproc_info = ab_ahb->rproc_info; char fw_name[ATH12K_USERPD_FW_NAME_LEN]; char fw2_name[ATH12K_USERPD_FW_NAME_LEN]; struct device *dev = ab->dev; const struct firmware *fw, *fw2; unsigned long time_left; - phys_addr_t mem_phys; - struct resource res; - void *mem_region; - size_t mem_size; u32 pasid; int ret; - ret = of_reserved_mem_region_to_resource_byname(dev->of_node, "q6-region", - &res); + ret = ath12k_ahb_get_fw_load_region(ab); if (ret) return ret; - mem_phys = res.start; - mem_size = resource_size(&res); - mem_region = devm_memremap(dev, mem_phys, mem_size, MEMREMAP_WC); - if (IS_ERR(mem_region)) { - ath12k_err(ab, "unable to map memory region: %pa+%zx\n", - &res.start, mem_size); - return PTR_ERR(mem_region); - } - snprintf(fw_name, sizeof(fw_name), "%s/%s/%s%d%s", ATH12K_FW_DIR, ab->hw_params->fw.dir, ATH12K_AHB_FW_PREFIX, ab_ahb->userpd_id, ATH12K_AHB_FW_SUFFIX); @@ -400,11 +425,13 @@ static int ath12k_ahb_power_up(struct ath12k_base *ab) /* Load FW image to a reserved memory location */ if (ab_ahb->scm_auth_enabled) - ret = qcom_mdt_load(dev, fw, fw_name, pasid, mem_region, - mem_phys, mem_size, &mem_phys); + ret = qcom_mdt_load(dev, fw, fw_name, pasid, rproc_info->mem_region, + rproc_info->mem_phys, rproc_info->mem_size, + NULL); else - ret = qcom_mdt_load_no_init(dev, fw, fw_name, mem_region, - mem_phys, mem_size, &mem_phys); + ret = qcom_mdt_load_no_init(dev, fw, fw_name, rproc_info->mem_region, + rproc_info->mem_phys, rproc_info->mem_size, + NULL); if (ret) { ath12k_err(ab, "Failed to load MDT segments: %d\n", ret); goto err_fw; @@ -428,8 +455,9 @@ static int ath12k_ahb_power_up(struct ath12k_base *ab) goto err_fw2; } - ret = qcom_mdt_load_no_init(dev, fw2, fw2_name, mem_region, mem_phys, - mem_size, &mem_phys); + ret = qcom_mdt_load_no_init(dev, fw2, fw2_name, rproc_info->mem_region, + rproc_info->mem_phys, rproc_info->mem_size, + NULL); if (ret) { ath12k_err(ab, "Failed to load MDT segments: %d\n", ret); goto err_fw2; @@ -877,6 +905,7 @@ static struct ath12k_ahb_rproc_info *ath12k_ahb_rproc_info_alloc(struct ath12k_b rproc_info->rootpd_booted_by_driver = false; rproc_info->userpd[ab_ahb->userpd_id - 1] = ab_ahb; rproc_info->num_userpd = 1; + rproc_info->shared_fw_loaded = false; init_completion(&rproc_info->rootpd_ready); ab_ahb->rproc_info = rproc_info; @@ -961,6 +990,76 @@ static int ath12k_ahb_boot_root_pd(struct ath12k_base *ab) return 0; } +static int ath12k_ahb_load_auth_shared_fw(struct ath12k_base *ab, + struct ath12k_ahb_rproc_info *rproc_info, + const char *fw_name, u32 pasid) +{ + int ret; + + const struct firmware *fw __free(firmware) = NULL; + ret = request_firmware(&fw, fw_name, ab->dev); + if (ret) { + ath12k_err(ab, "failed to request shared firmware %s: %d\n", + fw_name, ret); + return ret; + } + + if (!fw->size) { + ath12k_err(ab, "Invalid firmware size\n"); + return -EINVAL; + } + + ath12k_dbg(ab, ATH12K_DBG_AHB, "loading firmware %s, size %zd\n", fw_name, + fw->size); + + ret = qcom_mdt_load(ab->dev, fw, fw_name, pasid, rproc_info->mem_region, + rproc_info->mem_phys, rproc_info->mem_size, NULL); + if (ret) { + ath12k_err(ab, "failed to load RO firmware %s: %d\n", fw_name, ret); + return ret; + } + + ret = qcom_pas_auth_and_reset(pasid); + if (ret) + ath12k_err(ab, "failed to authenticate and boot shared firmware: %d\n", + ret); + return ret; +} + +static int ath12k_ahb_load_shared_firmware(struct ath12k_base *ab) +{ + struct ath12k_ahb *ab_ahb = ath12k_ab_to_ahb(ab); + struct ath12k_ahb_rproc_info *rproc_info = ab_ahb->rproc_info; + char fw_name[ATH12K_USERPD_FW_NAME_LEN]; + u32 pasid; + int ret; + + lockdep_assert_held(&ath12k_rproc_info_lock); + + if (!ab_ahb->supports_multipd) + return 0; + + ret = ath12k_ahb_get_fw_load_region(ab); + if (ret) + return ret; + + snprintf(fw_name, sizeof(fw_name), "%s/%s/%s%d%s", ATH12K_FW_DIR, + ab->hw_params->fw.dir, ATH12K_AHB_FW_PREFIX, ATH12K_AHB_RO_ID, + ATH12K_AHB_FW_SUFFIX); + + pasid = u32_encode_bits(ATH12K_AHB_RO_ID, ATH12K_USERPD_ID_MASK) | + ATH12K_AHB_UPD_SWID; + + ret = ath12k_ahb_load_auth_shared_fw(ab, rproc_info, fw_name, pasid); + if (ret) { + ath12k_ahb_put_fw_load_region(rproc_info); + return ret; + } + + rproc_info->shared_fw_loaded = true; + return 0; +} + static int ath12k_ahb_configure_rproc(struct ath12k_base *ab) { int ret; @@ -989,6 +1088,15 @@ static int ath12k_ahb_configure_rproc(struct ath12k_base *ab) g_rproc_info->rootpd_booted_by_driver = true; } + if (!g_rproc_info->shared_fw_loaded) { + ret = ath12k_ahb_load_shared_firmware(ab); + if (ret) { + if (g_rproc_info->rootpd_booted_by_driver) + rproc_shutdown(g_rproc_info->tgt_rproc); + goto err_unreg_notifier; + } + } + mutex_unlock(&ath12k_rproc_info_lock); return 0; @@ -1012,6 +1120,8 @@ static void ath12k_ahb_deconfigure_rproc(struct ath12k_base *ab) { struct ath12k_ahb *ab_ahb = ath12k_ab_to_ahb(ab); struct ath12k_ahb_rproc_info *rproc_info = ab_ahb->rproc_info; + u32 pasid; + int ret; lockdep_assert_held(&ath12k_rproc_info_lock); @@ -1023,6 +1133,20 @@ static void ath12k_ahb_deconfigure_rproc(struct ath12k_base *ab) if (!g_rproc_info->num_userpd) { ath12k_ahb_unregister_rproc_notifier(); + if (g_rproc_info->shared_fw_loaded) { + pasid = u32_encode_bits(ATH12K_AHB_RO_ID, ATH12K_USERPD_ID_MASK) | + ATH12K_AHB_UPD_SWID; + ret = qcom_pas_shutdown(pasid); + if (ret) + ath12k_err(ab, "pas shutdown failed for shared firmware: %d\n", + ret); + + g_rproc_info->shared_fw_loaded = false; + } + + if (g_rproc_info->mem_region) + ath12k_ahb_put_fw_load_region(g_rproc_info); + if (g_rproc_info->rootpd_booted_by_driver && g_rproc_info->tgt_rproc->state == RPROC_RUNNING) rproc_shutdown(g_rproc_info->tgt_rproc); diff --git a/drivers/net/wireless/ath/ath12k/ahb.h b/drivers/net/wireless/ath/ath12k/ahb.h index cdb58b07338f..46a4420d41bd 100644 --- a/drivers/net/wireless/ath/ath12k/ahb.h +++ b/drivers/net/wireless/ath/ath12k/ahb.h @@ -30,6 +30,9 @@ #define ATH12K_USERPD_ID_MASK GENMASK(10, 8) #define ATH12K_USERPD_FW_NAME_LEN 35 +/* Shared read-only firmware ID, mandated by MultiPD firmware architecture */ +#define ATH12K_AHB_RO_ID 4 + enum ath12k_ahb_userpd_id { ATH12K_AHB_USERPD_ID_0 = 1, ATH12K_AHB_USERPD_ID_1, @@ -46,6 +49,7 @@ struct ath12k_ahb_desc { enum ath12k_hw_rev hw_rev; bool auth_enabled; const struct ath12k_hif_ops *ops; + bool supports_multipd; }; enum ath12k_ahb_smp2p_msg_id { @@ -77,6 +81,10 @@ struct ath12k_ahb_rproc_info { u8 num_userpd; bool rootpd_booted_by_driver; struct ath12k_ahb *userpd[ATH12K_MAX_DEVICES]; + bool shared_fw_loaded; + phys_addr_t mem_phys; + size_t mem_size; + void *mem_region; }; struct ath12k_ahb { @@ -95,6 +103,7 @@ struct ath12k_ahb { const struct ath12k_ahb_device_family_ops *device_family_ops; bool scm_auth_enabled; struct ath12k_ahb_rproc_info *rproc_info; + bool supports_multipd; }; struct ath12k_ahb_driver { diff --git a/drivers/net/wireless/ath/ath12k/wifi7/ahb.c b/drivers/net/wireless/ath/ath12k/wifi7/ahb.c index 98a6606ffd76..a8f5cf8cc2a6 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/ahb.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/ahb.c @@ -35,11 +35,13 @@ static const struct ath12k_ahb_desc ath12k_wifi7_ahb_desc[] = { .hw_rev = ATH12K_HW_IPQ5332_HW10, .auth_enabled = true, .ops = &ath12k_ahb_hif_ops, + .supports_multipd = true, }, [ATH12K_HW_IPQ5424_HW10] = { .hw_rev = ATH12K_HW_IPQ5424_HW10, .auth_enabled = false, .ops = &ath12k_ahb_hif_ops, + .supports_multipd = false, }, }; @@ -106,6 +108,7 @@ static int ath12k_wifi7_ahb_probe(struct platform_device *pdev) ab->hw_rev = desc->hw_rev; ab->hif.ops = desc->ops; ab_ahb->scm_auth_enabled = desc->auth_enabled; + ab_ahb->supports_multipd = desc->supports_multipd; ab_ahb->userpd_id = ath12k_wifi7_ahb_get_userpd_id(ab); if (!ab_ahb->userpd_id) return -EOPNOTSUPP; From f5f0fcfcb30c677c1069c131f8e00e728e0a4fc5 Mon Sep 17 00:00:00 2001 From: Ivy Lopez Date: Tue, 8 Sep 2026 18:28:29 -0600 Subject: [PATCH 0403/2126] net: starfire: fix ioaddr sign-extension causing ioremap() failure ioaddr is declared as a signed long, but is assigned the result of pci_resource_start(), which returns an unsigned resource_size_t. On configurations where the BAR address has its high bit set, the value sign-extends when passed to ioremap(), producing a bogus 64-bit address and causing device probe to fail: ioremap: invalid physical address fffffffffe480000 starfire 0000:08:04.0: cannot Remap 0x80000 @ 0xfe480000, aborting Change ioaddr to resource_size_t, matching both the return type of pci_resource_start() and the type ioremap() expects for its physical address argument, rather than unsigned long, which is not guaranteed to be wide enough on all configurations. Switch the associated error print to %pa accordingly. Link: https://bugzilla.kernel.org/show_bug.cgi?id=198035 Signed-off-by: Ivy Lopez Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260909002829.224639-1-skunkolee@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/adaptec/starfire.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/adaptec/starfire.c b/drivers/net/ethernet/adaptec/starfire.c index f1109d90e1fc..b2f3998e128b 100644 --- a/drivers/net/ethernet/adaptec/starfire.c +++ b/drivers/net/ethernet/adaptec/starfire.c @@ -634,7 +634,7 @@ static int starfire_init_one(struct pci_dev *pdev, int i, irq, chip_idx = ent->driver_data; struct net_device *dev; u8 addr[ETH_ALEN]; - long ioaddr; + resource_size_t ioaddr; void __iomem *base; int drv_flags, io_size; int boguscnt; @@ -664,8 +664,8 @@ static int starfire_init_one(struct pci_dev *pdev, base = ioremap(ioaddr, io_size); if (!base) { - dev_err(d, "cannot remap %#x @ %#lx, aborting\n", - io_size, ioaddr); + dev_err(d, "cannot remap %#x @ %pa, aborting\n", + io_size, &ioaddr); goto err_out_free_res; } From 75a73afd0b32d19512f50db197e8794456e4f738 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Wed, 9 Sep 2026 11:57:37 +0700 Subject: [PATCH 0404/2126] net: davicom: Propagate wakeup IRQ errors The wakeup IRQ is optional, but errors from platform_get_irq_optional() are currently ignored. Propagate errors from the IRQ lookup, except -ENXIO which indicates that the optional IRQ is not available. Found by manual code inspection. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: bui duc phuc Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260909045738.16705-1-phucduc.bui@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/davicom/dm9000.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c index b87eaf0c250c..e294b365eb06 100644 --- a/drivers/net/ethernet/davicom/dm9000.c +++ b/drivers/net/ethernet/davicom/dm9000.c @@ -1511,7 +1511,11 @@ dm9000_probe(struct platform_device *pdev) } db->irq_wake = platform_get_irq_optional(pdev, 1); - if (db->irq_wake >= 0) { + if (db->irq_wake < 0 && db->irq_wake != -ENXIO) { + ret = db->irq_wake; + goto out; + } + if (db->irq_wake > 0) { dev_dbg(db->dev, "wakeup irq %d\n", db->irq_wake); ret = request_irq(db->irq_wake, dm9000_wol_interrupt, From 5145bb6a2c2683d541828f86d5321e0565f2e30c Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:38 +0000 Subject: [PATCH 0405/2126] sit: fix UAF in ipip6_tunnel_del_prl() When flushing all potential router list (PRL) entries, ipip6_tunnel_del_prl() called call_rcu(&x->rcu_head, prl_list_destroy_rcu) before clearing t->prl. A concurrent reader in isatap_chksrc() could enter an RCU read-side critical section after call_rcu() but before t->prl is set to NULL, allowing prl_list_destroy_rcu() to free nodes while the reader traverses them. Clear t->prl using RCU_INIT_POINTER() before invoking call_rcu(). Also use rcu_assign_pointer() when unlinking individual entries. Fixes: ef9a9d1183b3 ("ipv6 sit: RCU conversion phase I") Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260907075846.2913645-2-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/sit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 19b7fa8d1a2a..4438b2472b28 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -436,7 +436,7 @@ ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) (x = rtnl_dereference(*p)) != NULL; p = &x->next) { if (x->addr == a->addr) { - *p = x->next; + rcu_assign_pointer(*p, rtnl_dereference(x->next)); kfree_rcu(x, rcu_head); t->prl_count--; goto out; @@ -447,8 +447,8 @@ ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) x = rtnl_dereference(t->prl); if (x) { t->prl_count = 0; + RCU_INIT_POINTER(t->prl, NULL); call_rcu(&x->rcu_head, prl_list_destroy_rcu); - t->prl = NULL; } } out: From 40a2b90f5190fcc7b083809fa93f2799abefeeb1 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:39 +0000 Subject: [PATCH 0406/2126] sit: charge ip_tunnel_prl_entry allocations to memcg ipip6_tunnel_add_prl() allocates struct ip_tunnel_prl_entry for each potential router entry added via SIOCADDPRL. An unprivileged user with CAP_NET_ADMIN in a user namespace can add an unbounded number of entries, consuming uncharged kernel memory. Commit 1b51d8271973 ("memcg: ipv6/sit: account and don't WARN on ip_tunnel_prl structs allocation") added accounting to the temporary buffer in ipip6_tunnel_get_prl(), but missed the entry allocations in ipip6_tunnel_add_prl(). Use GFP_KERNEL_ACCOUNT when allocating struct ip_tunnel_prl_entry. Fixes: 1b51d8271973 ("memcg: ipv6/sit: account and don't WARN on ip_tunnel_prl structs allocation") Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-3-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/sit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 4438b2472b28..9a2bbd76d379 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -395,7 +395,7 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) goto out; } - p = kzalloc_obj(struct ip_tunnel_prl_entry); + p = kzalloc_obj(struct ip_tunnel_prl_entry, GFP_KERNEL_ACCOUNT); if (!p) { err = -ENOBUFS; goto out; From 88b84cae6b94087d3a9679845fe28ad19c7bef8b Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:40 +0000 Subject: [PATCH 0407/2126] ip_tunnel: use WRITE_ONCE in ip_tunnel_encap_setup Update ip_tunnel_encap_setup() to use WRITE_ONCE() when writing to encap fields (type, sport, dport, flags) and hlen fields. This ensures that concurrent lockless readers (like fill_info) do not see torn writes. Also remove the unsafe memset() on t->encap which could cause concurrent readers to transiently see zeroed fields. Removing it also fixes a bug where t->encap was left cleared even if ip_encap_hlen() failed, resulting in partial configuration. Fixes: 56328486539d ("net: Changes to ip_tunnel to support foo-over-udp encapsulation") Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-4-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv4/ip_tunnel.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index e6bcf01411d0..13b5e35e8790 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -491,19 +491,17 @@ int ip_tunnel_encap_setup(struct ip_tunnel *t, { int hlen; - memset(&t->encap, 0, sizeof(t->encap)); - hlen = ip_encap_hlen(ipencap); if (hlen < 0) return hlen; - t->encap.type = ipencap->type; - t->encap.sport = ipencap->sport; - t->encap.dport = ipencap->dport; - t->encap.flags = ipencap->flags; + WRITE_ONCE(t->encap.type, ipencap->type); + WRITE_ONCE(t->encap.sport, ipencap->sport); + WRITE_ONCE(t->encap.dport, ipencap->dport); + WRITE_ONCE(t->encap.flags, ipencap->flags); - t->encap_hlen = hlen; - t->hlen = t->encap_hlen + t->tun_hlen; + WRITE_ONCE(t->encap_hlen, hlen); + WRITE_ONCE(t->hlen, hlen + t->tun_hlen); return 0; } From b5e8eadb1c8a800b1fe7bec42b5e0c696f69e1aa Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:41 +0000 Subject: [PATCH 0408/2126] sit: annotate data-races around tunnel->fwmark ipip6_tunnel_xmit() runs locklessly (dev->lltx == true) and reads tunnel->fwmark. In preparation for converting ipip6_fill_info() to run without RTNL, add READ_ONCE() and WRITE_ONCE() annotations around tunnel->fwmark. Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-5-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/sit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 9a2bbd76d379..e85fa80e80d1 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -929,7 +929,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, if (!dst && !ipip6_tunnel_dst_find(skb, &dst, false)) goto tx_error; - flowi4_init_output(&fl4, tunnel->parms.link, tunnel->fwmark, + flowi4_init_output(&fl4, tunnel->parms.link, READ_ONCE(tunnel->fwmark), tos & INET_DSCP_MASK, RT_SCOPE_UNIVERSE, IPPROTO_IPV6, 0, dst, tiph->saddr, 0, 0, sock_net_uid(tunnel->net, NULL)); @@ -1153,7 +1153,7 @@ static void ipip6_tunnel_update(struct ip_tunnel *t, t->parms.iph.frag_off = p->iph.frag_off; if (t->parms.link != p->link || t->fwmark != fwmark) { t->parms.link = p->link; - t->fwmark = fwmark; + WRITE_ONCE(t->fwmark, fwmark); ipip6_tunnel_bind_dev(t->dev); } dst_cache_reset(&t->dst_cache); @@ -1706,7 +1706,7 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->iph.protocol) || nla_put_be16(skb, IFLA_IPTUN_FLAGS, ip_tunnel_flags_to_be16(parm->i_flags)) || - nla_put_u32(skb, IFLA_IPTUN_FWMARK, tunnel->fwmark)) + nla_put_u32(skb, IFLA_IPTUN_FWMARK, READ_ONCE(tunnel->fwmark))) goto nla_put_failure; #ifdef CONFIG_IPV6_SIT_6RD From eaa2098a94cdd726c8c96764de19ecbc95719d37 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:42 +0000 Subject: [PATCH 0409/2126] sit: convert 6RD configuration to RCU protection In order to allow lockless readers in future patches, convert 'tunnel->ip6rd' to an RCU protected pointer. Updating 6RD configuration via ipip6_tunnel_update_6rd() or ipip6_tunnel_clone_6rd() now allocates a struct ip_tunnel_6rd_parm and uses rcu_assign_pointer() to publish it, freeing the previous parameters with kfree_rcu(). Readers in check_6rd() and only_dnatted() use rcu_dereference() under existing RCU read lock, preventing torn reads on the 128-bit IPv6 prefix. Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-6-edumazet@google.com Signed-off-by: Jakub Kicinski --- include/net/ip_tunnels.h | 3 +- net/ipv6/sit.c | 160 ++++++++++++++++++++++++++++----------- 2 files changed, 117 insertions(+), 46 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 7c9aadfe8fe3..7fff59bab53b 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -127,6 +127,7 @@ struct ip_tunnel_6rd_parm { __be32 relay_prefix; u16 prefixlen; u16 relay_prefixlen; + struct rcu_head rcu; }; #endif @@ -185,7 +186,7 @@ struct ip_tunnel { /* for SIT */ #ifdef CONFIG_IPV6_SIT_6RD - struct ip_tunnel_6rd_parm ip6rd; + struct ip_tunnel_6rd_parm __rcu *ip6rd; #endif struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */ unsigned int prl_count; /* # of entries in PRL */ diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index e85fa80e80d1..7cabcd3afbc4 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -183,21 +183,47 @@ static void ipip6_tunnel_link(struct sit_net *sitn, struct ip_tunnel *t) rcu_assign_pointer(*tp, t); } -static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) +static int ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) { #ifdef CONFIG_IPV6_SIT_6RD struct ip_tunnel *t = netdev_priv(dev); + struct ip_tunnel_6rd_parm *new_6rd, *old_6rd; + + new_6rd = kmalloc_obj(*new_6rd); + if (!new_6rd) + return -ENOMEM; if (dev == sitn->fb_tunnel_dev || !sitn->fb_tunnel_dev) { - ipv6_addr_set(&t->ip6rd.prefix, htonl(0x20020000), 0, 0, 0); - t->ip6rd.relay_prefix = 0; - t->ip6rd.prefixlen = 16; - t->ip6rd.relay_prefixlen = 0; + ipv6_addr_set(&new_6rd->prefix, htonl(0x20020000), 0, 0, 0); + new_6rd->relay_prefix = 0; + new_6rd->prefixlen = 16; + new_6rd->relay_prefixlen = 0; } else { struct ip_tunnel *t0 = netdev_priv(sitn->fb_tunnel_dev); - memcpy(&t->ip6rd, &t0->ip6rd, sizeof(t->ip6rd)); + struct ip_tunnel_6rd_parm *t0_6rd; + + t0_6rd = rtnl_dereference(t0->ip6rd); + if (t0_6rd) { + *new_6rd = *t0_6rd; + } else { + ipv6_addr_set(&new_6rd->prefix, htonl(0x20020000), 0, 0, 0); + new_6rd->relay_prefix = 0; + new_6rd->prefixlen = 16; + new_6rd->relay_prefixlen = 0; + } + } + + old_6rd = rcu_dereference_protected(t->ip6rd, + lockdep_rtnl_is_held() || + dev->reg_state == NETREG_UNINITIALIZED); + rcu_assign_pointer(t->ip6rd, new_6rd); + if (old_6rd) { + dst_cache_reset(&t->dst_cache); + netdev_state_change(t->dev); + kfree_rcu(old_6rd, rcu); } #endif + return 0; } static int ipip6_tunnel_create(struct net_device *dev) @@ -206,6 +232,10 @@ static int ipip6_tunnel_create(struct net_device *dev) struct sit_net *sitn = net_generic(t->net, sit_net_id); int err; + err = ipip6_tunnel_clone_6rd(dev, sitn); + if (err < 0) + goto out; + __dev_addr_set(dev, &t->parms.iph.saddr, 4); memcpy(dev->broadcast, &t->parms.iph.daddr, 4); @@ -218,8 +248,6 @@ static int ipip6_tunnel_create(struct net_device *dev) if (err < 0) goto out; - ipip6_tunnel_clone_6rd(dev, sitn); - ipip6_tunnel_link(sitn, t); return 0; @@ -281,6 +309,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, return nt; failed_free: + ipip6_dev_free(dev); free_netdev(dev); failed: return NULL; @@ -631,8 +660,13 @@ static bool only_dnatted(const struct ip_tunnel *tunnel, int prefix_len; #ifdef CONFIG_IPV6_SIT_6RD - prefix_len = tunnel->ip6rd.prefixlen + 32 - - tunnel->ip6rd.relay_prefixlen; + const struct ip_tunnel_6rd_parm *ip6rd; + + ip6rd = rcu_dereference(tunnel->ip6rd); + if (ip6rd) + prefix_len = ip6rd->prefixlen + 32 - ip6rd->relay_prefixlen; + else + prefix_len = 48; #else prefix_len = 48; #endif @@ -810,25 +844,28 @@ static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst, __be32 *v4dst) { #ifdef CONFIG_IPV6_SIT_6RD - if (ipv6_prefix_equal(v6dst, &tunnel->ip6rd.prefix, - tunnel->ip6rd.prefixlen)) { + const struct ip_tunnel_6rd_parm *ip6rd; + + ip6rd = rcu_dereference(tunnel->ip6rd); + if (ip6rd && ipv6_prefix_equal(v6dst, &ip6rd->prefix, + ip6rd->prefixlen)) { unsigned int pbw0, pbi0; int pbi1; u32 d; - pbw0 = tunnel->ip6rd.prefixlen >> 5; - pbi0 = tunnel->ip6rd.prefixlen & 0x1f; + pbw0 = ip6rd->prefixlen >> 5; + pbi0 = ip6rd->prefixlen & 0x1f; - d = tunnel->ip6rd.relay_prefixlen < 32 ? + d = ip6rd->relay_prefixlen < 32 ? (ntohl(v6dst->s6_addr32[pbw0]) << pbi0) >> - tunnel->ip6rd.relay_prefixlen : 0; + ip6rd->relay_prefixlen : 0; - pbi1 = pbi0 - tunnel->ip6rd.relay_prefixlen; + pbi1 = pbi0 - ip6rd->relay_prefixlen; if (pbi1 > 0) d |= ntohl(v6dst->s6_addr32[pbw0 + 1]) >> (32 - pbi1); - *v4dst = tunnel->ip6rd.relay_prefix | htonl(d); + *v4dst = ip6rd->relay_prefix | htonl(d); return true; } #else @@ -1164,6 +1201,7 @@ static void ipip6_tunnel_update(struct ip_tunnel *t, static int ipip6_tunnel_update_6rd(struct ip_tunnel *t, struct ip_tunnel_6rd *ip6rd) { + struct ip_tunnel_6rd_parm *new_6rd, *old_6rd; struct in6_addr prefix; __be32 relay_prefix; @@ -1183,10 +1221,20 @@ static int ipip6_tunnel_update_6rd(struct ip_tunnel *t, if (relay_prefix != ip6rd->relay_prefix) return -EINVAL; - t->ip6rd.prefix = prefix; - t->ip6rd.relay_prefix = relay_prefix; - t->ip6rd.prefixlen = ip6rd->prefixlen; - t->ip6rd.relay_prefixlen = ip6rd->relay_prefixlen; + new_6rd = kmalloc_obj(*new_6rd); + if (!new_6rd) + return -ENOMEM; + + new_6rd->prefix = prefix; + new_6rd->relay_prefix = relay_prefix; + new_6rd->prefixlen = ip6rd->prefixlen; + new_6rd->relay_prefixlen = ip6rd->relay_prefixlen; + + old_6rd = rtnl_dereference(t->ip6rd); + rcu_assign_pointer(t->ip6rd, new_6rd); + if (old_6rd) + kfree_rcu(old_6rd, rcu); + dst_cache_reset(&t->dst_cache); netdev_state_change(t->dev); return 0; @@ -1195,6 +1243,7 @@ static int ipip6_tunnel_update_6rd(struct ip_tunnel *t, static int ipip6_tunnel_get6rd(struct net_device *dev, struct ip_tunnel_parm __user *data) { + const struct ip_tunnel_6rd_parm *ip6rd_parm; struct ip_tunnel *t = netdev_priv(dev); struct ip_tunnel_parm_kern p; struct ip_tunnel_6rd ip6rd; @@ -1207,10 +1256,15 @@ ipip6_tunnel_get6rd(struct net_device *dev, struct ip_tunnel_parm __user *data) if (!t) t = netdev_priv(dev); - ip6rd.prefix = t->ip6rd.prefix; - ip6rd.relay_prefix = t->ip6rd.relay_prefix; - ip6rd.prefixlen = t->ip6rd.prefixlen; - ip6rd.relay_prefixlen = t->ip6rd.relay_prefixlen; + ip6rd_parm = rtnl_dereference(t->ip6rd); + if (ip6rd_parm) { + ip6rd.prefix = ip6rd_parm->prefix; + ip6rd.relay_prefix = ip6rd_parm->relay_prefix; + ip6rd.prefixlen = ip6rd_parm->prefixlen; + ip6rd.relay_prefixlen = ip6rd_parm->relay_prefixlen; + } else { + memset(&ip6rd, 0, sizeof(ip6rd)); + } if (copy_to_user(data, &ip6rd, sizeof(ip6rd))) return -EFAULT; return 0; @@ -1222,20 +1276,16 @@ ipip6_tunnel_6rdctl(struct net_device *dev, struct ip_tunnel_6rd __user *data, { struct ip_tunnel *t = netdev_priv(dev); struct ip_tunnel_6rd ip6rd; - int err; if (!ns_capable(t->net->user_ns, CAP_NET_ADMIN)) return -EPERM; if (copy_from_user(&ip6rd, data, sizeof(ip6rd))) return -EFAULT; - if (cmd != SIOCDEL6RD) { - err = ipip6_tunnel_update_6rd(t, &ip6rd); - if (err < 0) - return err; - } else - ipip6_tunnel_clone_6rd(dev, dev_to_sit_net(dev)); - return 0; + if (cmd != SIOCDEL6RD) + return ipip6_tunnel_update_6rd(t, &ip6rd); + + return ipip6_tunnel_clone_6rd(dev, dev_to_sit_net(dev)); } #endif /* CONFIG_IPV6_SIT_6RD */ @@ -1406,8 +1456,17 @@ static const struct net_device_ops ipip6_netdev_ops = { static void ipip6_dev_free(struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); +#ifdef CONFIG_IPV6_SIT_6RD + struct ip_tunnel_6rd_parm *ip6rd; - dst_cache_destroy(&tunnel->dst_cache); + ip6rd = rcu_dereference_protected(tunnel->ip6rd, 1); + RCU_INIT_POINTER(tunnel->ip6rd, NULL); + kfree(ip6rd); +#endif + if (tunnel->dst_cache.cache) { + dst_cache_destroy(&tunnel->dst_cache); + tunnel->dst_cache.cache = NULL; + } } #define SIT_FEATURES (NETIF_F_SG | \ @@ -1576,8 +1635,10 @@ static int ipip6_newlink(struct net_device *dev, return -EEXIST; err = ipip6_tunnel_create(dev); - if (err < 0) + if (err < 0) { + ipip6_dev_free(dev); return err; + } if (tb[IFLA_MTU]) { u32 mtu = nla_get_u32(tb[IFLA_MTU]); @@ -1695,6 +1756,9 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); struct ip_tunnel_parm_kern *parm = &tunnel->parms; +#ifdef CONFIG_IPV6_SIT_6RD + const struct ip_tunnel_6rd_parm *ip6rd; +#endif if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || @@ -1710,14 +1774,16 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) goto nla_put_failure; #ifdef CONFIG_IPV6_SIT_6RD - if (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX, - &tunnel->ip6rd.prefix) || - nla_put_in_addr(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, - tunnel->ip6rd.relay_prefix) || - nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN, - tunnel->ip6rd.prefixlen) || - nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, - tunnel->ip6rd.relay_prefixlen)) + ip6rd = rcu_dereference_rtnl(tunnel->ip6rd); + if (ip6rd && + (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX, + &ip6rd->prefix) || + nla_put_in_addr(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, + ip6rd->relay_prefix) || + nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN, + ip6rd->prefixlen) || + nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, + ip6rd->relay_prefixlen))) goto nla_put_failure; #endif @@ -1863,17 +1929,21 @@ static int __net_init sit_init_net(struct net *net) t = netdev_priv(sitn->fb_tunnel_dev); t->net = net; + err = ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); + if (err < 0) + goto err_reg_dev; + err = register_netdev(sitn->fb_tunnel_dev); if (err) goto err_reg_dev; - ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); ipip6_fb_tunnel_init(sitn->fb_tunnel_dev); strscpy(t->parms.name, sitn->fb_tunnel_dev->name); return 0; err_reg_dev: + ipip6_dev_free(sitn->fb_tunnel_dev); free_netdev(sitn->fb_tunnel_dev); err_alloc_dev: return err; From e3434672b7ad38cfd58006d4361966e61b508f5e Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:43 +0000 Subject: [PATCH 0410/2126] sit: implement ipip6_get_iflink() SIT currently uses ip_tunnel_get_iflink() which reads tunnel->parms.link. In order to decouple SIT parameter handling from ip_tunnel, implement its own ndo_get_iflink callback. Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-7-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/sit.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 7cabcd3afbc4..35c669590901 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1444,12 +1444,19 @@ ipip6_tunnel_siocdevprivate(struct net_device *dev, struct ifreq *ifr, } } +static int ipip6_get_iflink(const struct net_device *dev) +{ + struct ip_tunnel *tunnel = netdev_priv(dev); + + return READ_ONCE(tunnel->parms.link); +} + static const struct net_device_ops ipip6_netdev_ops = { .ndo_init = ipip6_tunnel_init, .ndo_uninit = ipip6_tunnel_uninit, .ndo_start_xmit = sit_tunnel_xmit, .ndo_siocdevprivate = ipip6_tunnel_siocdevprivate, - .ndo_get_iflink = ip_tunnel_get_iflink, + .ndo_get_iflink = ipip6_get_iflink, .ndo_tunnel_ctl = ipip6_tunnel_ctl, }; From 3cd52b7c0bbfbcd90f5a0fb9284e722852e04899 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:44 +0000 Subject: [PATCH 0411/2126] sit: dynamically allocate struct ip_tunnel_parm_kern In preparation for converting SIT configuration parameters to RCU, dynamically allocate struct ip_tunnel_parm_kern as sit_parms in struct ip_tunnel. Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-8-edumazet@google.com Signed-off-by: Jakub Kicinski --- include/net/ip_tunnels.h | 1 + net/ipv6/sit.c | 152 +++++++++++++++++++++++---------------- 2 files changed, 92 insertions(+), 61 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 7fff59bab53b..f464c4480eda 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -190,6 +190,7 @@ struct ip_tunnel { #endif struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */ unsigned int prl_count; /* # of entries in PRL */ + struct ip_tunnel_parm_kern *sit_parms; unsigned int ip_tnl_net_id; struct gro_cells gro_cells; __u32 fwmark; diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 35c669590901..dc37c7109af5 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -108,24 +108,24 @@ static struct ip_tunnel *ipip6_tunnel_lookup(struct net *net, int ifindex = dev ? dev->ifindex : 0; for_each_ip_tunnel_rcu(t, sitn->tunnels_r_l[h0 ^ h1]) { - if (local == t->parms.iph.saddr && - remote == t->parms.iph.daddr && - (!dev || !t->parms.link || ifindex == t->parms.link || - sifindex == t->parms.link) && + if (local == t->sit_parms->iph.saddr && + remote == t->sit_parms->iph.daddr && + (!dev || !t->sit_parms->link || ifindex == t->sit_parms->link || + sifindex == t->sit_parms->link) && (t->dev->flags & IFF_UP)) return t; } for_each_ip_tunnel_rcu(t, sitn->tunnels_r[h0]) { - if (remote == t->parms.iph.daddr && - (!dev || !t->parms.link || ifindex == t->parms.link || - sifindex == t->parms.link) && + if (remote == t->sit_parms->iph.daddr && + (!dev || !t->sit_parms->link || ifindex == t->sit_parms->link || + sifindex == t->sit_parms->link) && (t->dev->flags & IFF_UP)) return t; } for_each_ip_tunnel_rcu(t, sitn->tunnels_l[h1]) { - if (local == t->parms.iph.saddr && - (!dev || !t->parms.link || ifindex == t->parms.link || - sifindex == t->parms.link) && + if (local == t->sit_parms->iph.saddr && + (!dev || !t->sit_parms->link || ifindex == t->sit_parms->link || + sifindex == t->sit_parms->link) && (t->dev->flags & IFF_UP)) return t; } @@ -157,7 +157,7 @@ __ipip6_bucket(struct sit_net *sitn, struct ip_tunnel_parm_kern *parms) static inline struct ip_tunnel __rcu **ipip6_bucket(struct sit_net *sitn, struct ip_tunnel *t) { - return __ipip6_bucket(sitn, &t->parms); + return __ipip6_bucket(sitn, t->sit_parms); } static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t) @@ -236,10 +236,11 @@ static int ipip6_tunnel_create(struct net_device *dev) if (err < 0) goto out; - __dev_addr_set(dev, &t->parms.iph.saddr, 4); - memcpy(dev->broadcast, &t->parms.iph.daddr, 4); + t->parms = *t->sit_parms; + __dev_addr_set(dev, &t->sit_parms->iph.saddr, 4); + memcpy(dev->broadcast, &t->sit_parms->iph.daddr, 4); - if (test_bit(IP_TUNNEL_SIT_ISATAP_BIT, t->parms.i_flags)) + if (test_bit(IP_TUNNEL_SIT_ISATAP_BIT, t->sit_parms->i_flags)) dev->priv_flags |= IFF_ISATAP; dev->rtnl_link_ops = &sit_link_ops; @@ -270,9 +271,9 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, for (tp = __ipip6_bucket(sitn, parms); (t = rtnl_dereference(*tp)) != NULL; tp = &t->next) { - if (local == t->parms.iph.saddr && - remote == t->parms.iph.daddr && - parms->link == t->parms.link) { + if (local == t->sit_parms->iph.saddr && + remote == t->sit_parms->iph.daddr && + parms->link == t->sit_parms->link) { if (create) return NULL; else @@ -299,7 +300,10 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, nt = netdev_priv(dev); nt->net = net; - nt->parms = *parms; + nt->sit_parms = kmalloc_obj(*nt->sit_parms); + if (!nt->sit_parms) + goto failed_free; + *nt->sit_parms = *parms; if (ipip6_tunnel_create(dev) < 0) goto failed_free; @@ -602,12 +606,12 @@ static int ipip6_err(struct sk_buff *skb, u32 info) if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) { ipv4_update_pmtu(skb, dev_net(skb->dev), info, - t->parms.link, iph->protocol); + t->sit_parms->link, iph->protocol); err = 0; goto out; } if (type == ICMP_REDIRECT) { - ipv4_redirect(skb, dev_net(skb->dev), t->parms.link, + ipv4_redirect(skb, dev_net(skb->dev), t->sit_parms->link, iph->protocol); err = 0; goto out; @@ -618,10 +622,10 @@ static int ipip6_err(struct sk_buff *skb, u32 info) !ip6_err_gen_icmpv6_unreach(skb, iph->ihl * 4, type, data_len)) goto out; - if (t->parms.iph.daddr == 0) + if (t->sit_parms->iph.daddr == 0) goto out; - if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) + if (t->sit_parms->iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) goto out; if (time_before(jiffies, READ_ONCE(t->err_time) + IPTUNNEL_ERR_TIMEO)) @@ -722,8 +726,8 @@ static int ipip6_rcv(struct sk_buff *skb) tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, iph->saddr, iph->daddr, sifindex); if (tunnel) { - if (tunnel->parms.iph.protocol != IPPROTO_IPV6 && - tunnel->parms.iph.protocol != 0) + if (tunnel->sit_parms->iph.protocol != IPPROTO_IPV6 && + tunnel->sit_parms->iph.protocol != 0) goto out; skb->mac_header = skb->network_header; @@ -798,8 +802,8 @@ static int sit_tunnel_rcv(struct sk_buff *skb, u8 ipproto) if (tunnel) { const struct tnl_ptk_info *tpi; - if (tunnel->parms.iph.protocol != ipproto && - tunnel->parms.iph.protocol != 0) + if (tunnel->sit_parms->iph.protocol != ipproto && + tunnel->sit_parms->iph.protocol != 0) goto drop; if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) @@ -938,9 +942,9 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - const struct iphdr *tiph = &tunnel->parms.iph; + const struct iphdr *tiph = &tunnel->sit_parms->iph; const struct ipv6hdr *iph6 = ipv6_hdr(skb); - u8 tos = tunnel->parms.iph.tos; + u8 tos = tunnel->sit_parms->iph.tos; __be16 df = tiph->frag_off; struct rtable *rt; /* Route to the other host */ struct net_device *tdev; /* Device to other host */ @@ -966,7 +970,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, if (!dst && !ipip6_tunnel_dst_find(skb, &dst, false)) goto tx_error; - flowi4_init_output(&fl4, tunnel->parms.link, READ_ONCE(tunnel->fwmark), + flowi4_init_output(&fl4, tunnel->sit_parms->link, READ_ONCE(tunnel->fwmark), tos & INET_DSCP_MASK, RT_SCOPE_UNIVERSE, IPPROTO_IPV6, 0, dst, tiph->saddr, 0, 0, sock_net_uid(tunnel->net, NULL)); @@ -1014,7 +1018,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, df = 0; } - if (tunnel->parms.iph.daddr) + if (tunnel->sit_parms->iph.daddr) skb_dst_update_pmtu_no_confirm(skb, mtu); if (skb->len > mtu && !skb_is_gso(skb)) { @@ -1083,7 +1087,7 @@ static netdev_tx_t sit_tunnel_xmit__(struct sk_buff *skb, struct net_device *dev, u8 ipproto) { struct ip_tunnel *tunnel = netdev_priv(dev); - const struct iphdr *tiph = &tunnel->parms.iph; + const struct iphdr *tiph = &tunnel->sit_parms->iph; if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4)) goto tx_error; @@ -1138,7 +1142,7 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) const struct iphdr *iph; struct flowi4 fl4; - iph = &tunnel->parms.iph; + iph = &tunnel->sit_parms->iph; if (iph->daddr) { struct rtable *rt = ip_route_output_ports(tunnel->net, &fl4, @@ -1147,7 +1151,7 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) 0, 0, IPPROTO_IPV6, iph->tos & INET_DSCP_MASK, - tunnel->parms.link); + tunnel->sit_parms->link); if (!IS_ERR(rt)) { tdev = rt->dst.dev; @@ -1156,8 +1160,8 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) dev->flags |= IFF_POINTOPOINT; } - if (!tdev && tunnel->parms.link) - tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link); + if (!tdev && tunnel->sit_parms->link) + tdev = __dev_get_by_index(tunnel->net, tunnel->sit_parms->link); if (tdev && !netif_is_l3_master(tdev)) { int mtu; @@ -1171,30 +1175,41 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) dev->needed_headroom = ip_tunnel_limit_headroom(t_hlen + hlen); } -static void ipip6_tunnel_update(struct ip_tunnel *t, - struct ip_tunnel_parm_kern *p, - __u32 fwmark) +static int ipip6_tunnel_update(struct ip_tunnel *t, + struct ip_tunnel_parm_kern *p, + __u32 fwmark) { struct net *net = t->net; struct sit_net *sitn = net_generic(net, sit_net_id); + struct ip_tunnel_parm_kern *new_p, *old_p; + old_p = t->sit_parms; + new_p = kmalloc_obj(*new_p); + if (!new_p) + return -ENOMEM; + *new_p = *old_p; + new_p->iph.saddr = p->iph.saddr; + new_p->iph.daddr = p->iph.daddr; + new_p->iph.ttl = p->iph.ttl; + new_p->iph.tos = p->iph.tos; + new_p->iph.frag_off = p->iph.frag_off; + new_p->link = p->link; ipip6_tunnel_unlink(sitn, t); synchronize_net(); - t->parms.iph.saddr = p->iph.saddr; - t->parms.iph.daddr = p->iph.daddr; + t->sit_parms = new_p; + t->parms.iph = new_p->iph; + WRITE_ONCE(t->parms.link, new_p->link); __dev_addr_set(t->dev, &p->iph.saddr, 4); memcpy(t->dev->broadcast, &p->iph.daddr, 4); ipip6_tunnel_link(sitn, t); - t->parms.iph.ttl = p->iph.ttl; - t->parms.iph.tos = p->iph.tos; - t->parms.iph.frag_off = p->iph.frag_off; - if (t->parms.link != p->link || t->fwmark != fwmark) { - t->parms.link = p->link; + if (old_p->link != p->link || t->fwmark != fwmark) { WRITE_ONCE(t->fwmark, fwmark); ipip6_tunnel_bind_dev(t->dev); } dst_cache_reset(&t->dst_cache); netdev_state_change(t->dev); + kfree(old_p); + return 0; } #ifdef CONFIG_IPV6_SIT_6RD @@ -1326,7 +1341,7 @@ ipip6_tunnel_get(struct net_device *dev, struct ip_tunnel_parm_kern *p) t = ipip6_tunnel_locate(t->net, p, 0); if (!t) t = netdev_priv(dev); - memcpy(p, &t->parms, sizeof(*p)); + memcpy(p, t->sit_parms, sizeof(*p)); return 0; } @@ -1371,7 +1386,9 @@ ipip6_tunnel_change(struct net_device *dev, struct ip_tunnel_parm_kern *p) t = netdev_priv(dev); } - ipip6_tunnel_update(t, p, t->fwmark); + err = ipip6_tunnel_update(t, p, t->fwmark); + if (err) + return err; } return 0; @@ -1448,7 +1465,7 @@ static int ipip6_get_iflink(const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - return READ_ONCE(tunnel->parms.link); + return READ_ONCE(tunnel->sit_parms->link); } static const struct net_device_ops ipip6_netdev_ops = { @@ -1470,6 +1487,8 @@ static void ipip6_dev_free(struct net_device *dev) RCU_INIT_POINTER(tunnel->ip6rd, NULL); kfree(ip6rd); #endif + kfree(tunnel->sit_parms); + tunnel->sit_parms = NULL; if (tunnel->dst_cache.cache) { dst_cache_destroy(&tunnel->dst_cache); tunnel->dst_cache.cache = NULL; @@ -1512,7 +1531,7 @@ static int ipip6_tunnel_init(struct net_device *dev) int err; tunnel->dev = dev; - strscpy(tunnel->parms.name, dev->name); + strscpy(tunnel->sit_parms->name, dev->name); ipip6_tunnel_bind_dev(dev); @@ -1528,15 +1547,9 @@ static int ipip6_tunnel_init(struct net_device *dev) static void __net_init ipip6_fb_tunnel_init(struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - struct iphdr *iph = &tunnel->parms.iph; struct net *net = dev_net(dev); struct sit_net *sitn = net_generic(net, sit_net_id); - iph->version = 4; - iph->protocol = IPPROTO_IPV6; - iph->ihl = 5; - iph->ttl = 64; - rcu_assign_pointer(sitn->tunnels_wc[0], tunnel); } @@ -1623,6 +1636,7 @@ static int ipip6_newlink(struct net_device *dev, #ifdef CONFIG_IPV6_SIT_6RD struct ip_tunnel_6rd ip6rd; #endif + struct ip_tunnel_parm_kern p; struct net *net; int err; @@ -1636,11 +1650,16 @@ static int ipip6_newlink(struct net_device *dev, return err; } - ipip6_netlink_parms(data, &nt->parms, &nt->fwmark); + ipip6_netlink_parms(data, &p, &nt->fwmark); - if (ipip6_tunnel_locate(net, &nt->parms, 0)) + if (ipip6_tunnel_locate(net, &p, 0)) return -EEXIST; + nt->sit_parms = kmalloc_obj(*nt->sit_parms); + if (!nt->sit_parms) + return -ENOMEM; + *nt->sit_parms = p; + err = ipip6_tunnel_create(dev); if (err < 0) { ipip6_dev_free(dev); @@ -1707,7 +1726,9 @@ static int ipip6_changelink(struct net_device *dev, struct nlattr *tb[], } else t = netdev_priv(dev); - ipip6_tunnel_update(t, &p, fwmark); + err = ipip6_tunnel_update(t, &p, fwmark); + if (err) + return err; #ifdef CONFIG_IPV6_SIT_6RD if (ipip6_netlink_6rd_parms(data, &ip6rd)) @@ -1762,7 +1783,7 @@ static size_t ipip6_get_size(const struct net_device *dev) static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - struct ip_tunnel_parm_kern *parm = &tunnel->parms; + struct ip_tunnel_parm_kern *parm = tunnel->sit_parms; #ifdef CONFIG_IPV6_SIT_6RD const struct ip_tunnel_6rd_parm *ip6rd; #endif @@ -1935,6 +1956,17 @@ static int __net_init sit_init_net(struct net *net) t = netdev_priv(sitn->fb_tunnel_dev); t->net = net; + t->sit_parms = kzalloc_obj(*t->sit_parms); + if (!t->sit_parms) { + err = -ENOMEM; + goto err_reg_dev; + } + t->sit_parms->iph.version = 4; + t->sit_parms->iph.protocol = IPPROTO_IPV6; + t->sit_parms->iph.ihl = 5; + t->sit_parms->iph.ttl = 64; + strscpy(t->sit_parms->name, sitn->fb_tunnel_dev->name); + t->parms = *t->sit_parms; err = ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); if (err < 0) @@ -1945,8 +1977,6 @@ static int __net_init sit_init_net(struct net *net) goto err_reg_dev; ipip6_fb_tunnel_init(sitn->fb_tunnel_dev); - - strscpy(t->parms.name, sitn->fb_tunnel_dev->name); return 0; err_reg_dev: From 0301127e4d984d06300b539127f5922d97482bd9 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:45 +0000 Subject: [PATCH 0412/2126] sit: convert configuration to RCU protection Now that SIT parameters are dynamically allocated, convert tunnel->sit_parms to an RCU-protected pointer. Updates in ipip6_tunnel_update() allocate a new parameter block, publish it using rcu_assign_pointer(), and free the old one via kfree_rcu(). We only need to unlink and re-link the tunnel in the hash table if either saddr or daddr changed. When neither address changes, the unhash/re-hash and synchronize_net() can be completely skipped. Readers in ipip6_tunnel_lookup(), ipip6_tunnel_xmit(), ipip6_err(), and ipip6_rcv() now safely dereference tunnel->sit_parms under RCU. Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-9-edumazet@google.com Signed-off-by: Jakub Kicinski --- include/net/ip_tunnels.h | 3 +- net/ipv6/sit.c | 249 ++++++++++++++++++++++++--------------- 2 files changed, 159 insertions(+), 93 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index f464c4480eda..be4cc10f88ed 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -149,6 +149,7 @@ struct ip_tunnel_parm_kern { __be32 o_key; int link; struct iphdr iph; + struct rcu_head rcu; }; struct ip_tunnel { @@ -190,7 +191,7 @@ struct ip_tunnel { #endif struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */ unsigned int prl_count; /* # of entries in PRL */ - struct ip_tunnel_parm_kern *sit_parms; + struct ip_tunnel_parm_kern __rcu *sit_parms; unsigned int ip_tnl_net_id; struct gro_cells gro_cells; __u32 fwmark; diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index dc37c7109af5..c9049ab87e01 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -108,24 +108,33 @@ static struct ip_tunnel *ipip6_tunnel_lookup(struct net *net, int ifindex = dev ? dev->ifindex : 0; for_each_ip_tunnel_rcu(t, sitn->tunnels_r_l[h0 ^ h1]) { - if (local == t->sit_parms->iph.saddr && - remote == t->sit_parms->iph.daddr && - (!dev || !t->sit_parms->link || ifindex == t->sit_parms->link || - sifindex == t->sit_parms->link) && + const struct ip_tunnel_parm_kern *parms; + + parms = rcu_dereference(t->sit_parms); + if (local == parms->iph.saddr && + remote == parms->iph.daddr && + (!dev || !parms->link || ifindex == parms->link || + sifindex == parms->link) && (t->dev->flags & IFF_UP)) return t; } for_each_ip_tunnel_rcu(t, sitn->tunnels_r[h0]) { - if (remote == t->sit_parms->iph.daddr && - (!dev || !t->sit_parms->link || ifindex == t->sit_parms->link || - sifindex == t->sit_parms->link) && + const struct ip_tunnel_parm_kern *parms; + + parms = rcu_dereference(t->sit_parms); + if (remote == parms->iph.daddr && + (!dev || !parms->link || ifindex == parms->link || + sifindex == parms->link) && (t->dev->flags & IFF_UP)) return t; } for_each_ip_tunnel_rcu(t, sitn->tunnels_l[h1]) { - if (local == t->sit_parms->iph.saddr && - (!dev || !t->sit_parms->link || ifindex == t->sit_parms->link || - sifindex == t->sit_parms->link) && + const struct ip_tunnel_parm_kern *parms; + + parms = rcu_dereference(t->sit_parms); + if (local == parms->iph.saddr && + (!dev || !parms->link || ifindex == parms->link || + sifindex == parms->link) && (t->dev->flags & IFF_UP)) return t; } @@ -157,7 +166,7 @@ __ipip6_bucket(struct sit_net *sitn, struct ip_tunnel_parm_kern *parms) static inline struct ip_tunnel __rcu **ipip6_bucket(struct sit_net *sitn, struct ip_tunnel *t) { - return __ipip6_bucket(sitn, t->sit_parms); + return __ipip6_bucket(sitn, rtnl_dereference(t->sit_parms)); } static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t) @@ -230,17 +239,19 @@ static int ipip6_tunnel_create(struct net_device *dev) { struct ip_tunnel *t = netdev_priv(dev); struct sit_net *sitn = net_generic(t->net, sit_net_id); + struct ip_tunnel_parm_kern *parms; int err; err = ipip6_tunnel_clone_6rd(dev, sitn); if (err < 0) goto out; - t->parms = *t->sit_parms; - __dev_addr_set(dev, &t->sit_parms->iph.saddr, 4); - memcpy(dev->broadcast, &t->sit_parms->iph.daddr, 4); + parms = rtnl_dereference(t->sit_parms); + t->parms = *parms; + __dev_addr_set(dev, &parms->iph.saddr, 4); + memcpy(dev->broadcast, &parms->iph.daddr, 4); - if (test_bit(IP_TUNNEL_SIT_ISATAP_BIT, t->sit_parms->i_flags)) + if (test_bit(IP_TUNNEL_SIT_ISATAP_BIT, parms->i_flags)) dev->priv_flags |= IFF_ISATAP; dev->rtnl_link_ops = &sit_link_ops; @@ -264,6 +275,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, __be32 local = parms->iph.saddr; struct ip_tunnel *t, *nt; struct ip_tunnel __rcu **tp; + struct ip_tunnel_parm_kern *nt_parms; struct net_device *dev; char name[IFNAMSIZ]; struct sit_net *sitn = net_generic(net, sit_net_id); @@ -271,9 +283,12 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, for (tp = __ipip6_bucket(sitn, parms); (t = rtnl_dereference(*tp)) != NULL; tp = &t->next) { - if (local == t->sit_parms->iph.saddr && - remote == t->sit_parms->iph.daddr && - parms->link == t->sit_parms->link) { + const struct ip_tunnel_parm_kern *tparms; + + tparms = rtnl_dereference(t->sit_parms); + if (local == tparms->iph.saddr && + remote == tparms->iph.daddr && + parms->link == tparms->link) { if (create) return NULL; else @@ -300,10 +315,11 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, nt = netdev_priv(dev); nt->net = net; - nt->sit_parms = kmalloc_obj(*nt->sit_parms); - if (!nt->sit_parms) + nt_parms = kmalloc_obj(*nt_parms); + if (!nt_parms) goto failed_free; - *nt->sit_parms = *parms; + *nt_parms = *parms; + rcu_assign_pointer(nt->sit_parms, nt_parms); if (ipip6_tunnel_create(dev) < 0) goto failed_free; @@ -599,41 +615,45 @@ static int ipip6_err(struct sk_buff *skb, u32 info) err = -ENOENT; sifindex = netif_is_l3_master(skb->dev) ? IPCB(skb)->iif : 0; + rcu_read_lock(); t = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, iph->daddr, iph->saddr, sifindex); - if (!t) - goto out; + if (t) { + const struct ip_tunnel_parm_kern *parms; + + parms = rcu_dereference(t->sit_parms); + if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) { + ipv4_update_pmtu(skb, dev_net(skb->dev), info, + parms->link, iph->protocol); + err = 0; + goto out; + } + if (type == ICMP_REDIRECT) { + ipv4_redirect(skb, dev_net(skb->dev), parms->link, + iph->protocol); + err = 0; + goto out; + } - if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) { - ipv4_update_pmtu(skb, dev_net(skb->dev), info, - t->sit_parms->link, iph->protocol); err = 0; - goto out; + if (__in6_dev_get(skb->dev) && + !ip6_err_gen_icmpv6_unreach(skb, iph->ihl * 4, type, data_len)) + goto out; + + if (parms->iph.daddr == 0) + goto out; + + if (parms->iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) + goto out; + + if (time_before(jiffies, READ_ONCE(t->err_time) + IPTUNNEL_ERR_TIMEO)) + WRITE_ONCE(t->err_count, READ_ONCE(t->err_count) + 1); + else + WRITE_ONCE(t->err_count, 1); + WRITE_ONCE(t->err_time, jiffies); } - if (type == ICMP_REDIRECT) { - ipv4_redirect(skb, dev_net(skb->dev), t->sit_parms->link, - iph->protocol); - err = 0; - goto out; - } - - err = 0; - if (__in6_dev_get(skb->dev) && - !ip6_err_gen_icmpv6_unreach(skb, iph->ihl * 4, type, data_len)) - goto out; - - if (t->sit_parms->iph.daddr == 0) - goto out; - - if (t->sit_parms->iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) - goto out; - - if (time_before(jiffies, READ_ONCE(t->err_time) + IPTUNNEL_ERR_TIMEO)) - WRITE_ONCE(t->err_count, READ_ONCE(t->err_count) + 1); - else - WRITE_ONCE(t->err_count, 1); - WRITE_ONCE(t->err_time, jiffies); out: + rcu_read_unlock(); return err; } @@ -726,8 +746,11 @@ static int ipip6_rcv(struct sk_buff *skb) tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, iph->saddr, iph->daddr, sifindex); if (tunnel) { - if (tunnel->sit_parms->iph.protocol != IPPROTO_IPV6 && - tunnel->sit_parms->iph.protocol != 0) + const struct ip_tunnel_parm_kern *parms; + + parms = rcu_dereference(tunnel->sit_parms); + if (parms->iph.protocol != IPPROTO_IPV6 && + parms->iph.protocol != 0) goto out; skb->mac_header = skb->network_header; @@ -800,10 +823,12 @@ static int sit_tunnel_rcv(struct sk_buff *skb, u8 ipproto) tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, iph->saddr, iph->daddr, sifindex); if (tunnel) { + const struct ip_tunnel_parm_kern *parms; const struct tnl_ptk_info *tpi; - if (tunnel->sit_parms->iph.protocol != ipproto && - tunnel->sit_parms->iph.protocol != 0) + parms = rcu_dereference(tunnel->sit_parms); + if (parms->iph.protocol != ipproto && + parms->iph.protocol != 0) goto drop; if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) @@ -942,20 +967,27 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - const struct iphdr *tiph = &tunnel->sit_parms->iph; + const struct ip_tunnel_parm_kern *parms; + const struct iphdr *tiph; const struct ipv6hdr *iph6 = ipv6_hdr(skb); - u8 tos = tunnel->sit_parms->iph.tos; - __be16 df = tiph->frag_off; + u8 tos; + __be16 df; struct rtable *rt; /* Route to the other host */ struct net_device *tdev; /* Device to other host */ unsigned int max_headroom; /* The extra header space needed */ - __be32 dst = tiph->daddr; + __be32 dst; int err_count, mtu; struct flowi4 fl4; u8 ttl; u8 protocol = IPPROTO_IPV6; int t_hlen = tunnel->hlen + sizeof(struct iphdr); + parms = rcu_dereference(tunnel->sit_parms); + tiph = &parms->iph; + tos = parms->iph.tos; + df = tiph->frag_off; + dst = tiph->daddr; + if (tos == 1) tos = ipv6_get_dsfield(iph6); @@ -970,7 +1002,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, if (!dst && !ipip6_tunnel_dst_find(skb, &dst, false)) goto tx_error; - flowi4_init_output(&fl4, tunnel->sit_parms->link, READ_ONCE(tunnel->fwmark), + flowi4_init_output(&fl4, parms->link, READ_ONCE(tunnel->fwmark), tos & INET_DSCP_MASK, RT_SCOPE_UNIVERSE, IPPROTO_IPV6, 0, dst, tiph->saddr, 0, 0, sock_net_uid(tunnel->net, NULL)); @@ -1018,7 +1050,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, df = 0; } - if (tunnel->sit_parms->iph.daddr) + if (parms->iph.daddr) skb_dst_update_pmtu_no_confirm(skb, mtu); if (skb->len > mtu && !skb_is_gso(skb)) { @@ -1087,13 +1119,17 @@ static netdev_tx_t sit_tunnel_xmit__(struct sk_buff *skb, struct net_device *dev, u8 ipproto) { struct ip_tunnel *tunnel = netdev_priv(dev); - const struct iphdr *tiph = &tunnel->sit_parms->iph; + const struct ip_tunnel_parm_kern *parms; + const struct iphdr *tiph; if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4)) goto tx_error; skb_set_inner_ipproto(skb, ipproto); + parms = rcu_dereference(tunnel->sit_parms); + tiph = &parms->iph; + ip_tunnel_xmit(skb, dev, tiph, ipproto); return NETDEV_TX_OK; tx_error: @@ -1108,6 +1144,7 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb, if (!pskb_inet_may_pull(skb)) goto tx_err; + rcu_read_lock(); switch (skb->protocol) { case htons(ETH_P_IP): sit_tunnel_xmit__(skb, dev, IPPROTO_IPIP); @@ -1121,8 +1158,10 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb, break; #endif default: + rcu_read_unlock(); goto tx_err; } + rcu_read_unlock(); return NETDEV_TX_OK; @@ -1130,19 +1169,20 @@ tx_err: DEV_STATS_INC(dev, tx_errors); kfree_skb(skb); return NETDEV_TX_OK; - } static void ipip6_tunnel_bind_dev(struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); int t_hlen = tunnel->hlen + sizeof(struct iphdr); + const struct ip_tunnel_parm_kern *parms; struct net_device *tdev = NULL; int hlen = LL_MAX_HEADER; const struct iphdr *iph; struct flowi4 fl4; - iph = &tunnel->sit_parms->iph; + parms = rtnl_dereference(tunnel->sit_parms); + iph = &parms->iph; if (iph->daddr) { struct rtable *rt = ip_route_output_ports(tunnel->net, &fl4, @@ -1151,7 +1191,7 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) 0, 0, IPPROTO_IPV6, iph->tos & INET_DSCP_MASK, - tunnel->sit_parms->link); + parms->link); if (!IS_ERR(rt)) { tdev = rt->dst.dev; @@ -1160,8 +1200,8 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) dev->flags |= IFF_POINTOPOINT; } - if (!tdev && tunnel->sit_parms->link) - tdev = __dev_get_by_index(tunnel->net, tunnel->sit_parms->link); + if (!tdev && parms->link) + tdev = __dev_get_by_index(tunnel->net, parms->link); if (tdev && !netif_is_l3_master(tdev)) { int mtu; @@ -1182,8 +1222,9 @@ static int ipip6_tunnel_update(struct ip_tunnel *t, struct net *net = t->net; struct sit_net *sitn = net_generic(net, sit_net_id); struct ip_tunnel_parm_kern *new_p, *old_p; + bool move; - old_p = t->sit_parms; + old_p = rtnl_dereference(t->sit_parms); new_p = kmalloc_obj(*new_p); if (!new_p) return -ENOMEM; @@ -1194,21 +1235,29 @@ static int ipip6_tunnel_update(struct ip_tunnel *t, new_p->iph.tos = p->iph.tos; new_p->iph.frag_off = p->iph.frag_off; new_p->link = p->link; - ipip6_tunnel_unlink(sitn, t); - synchronize_net(); - t->sit_parms = new_p; + move = old_p->iph.saddr != p->iph.saddr || + old_p->iph.daddr != p->iph.daddr; + + if (move) + ipip6_tunnel_unlink(sitn, t); + t->parms.iph = new_p->iph; WRITE_ONCE(t->parms.link, new_p->link); - __dev_addr_set(t->dev, &p->iph.saddr, 4); - memcpy(t->dev->broadcast, &p->iph.daddr, 4); - ipip6_tunnel_link(sitn, t); + rcu_assign_pointer(t->sit_parms, new_p); + + if (move) { + synchronize_net(); + __dev_addr_set(t->dev, &p->iph.saddr, 4); + memcpy(t->dev->broadcast, &p->iph.daddr, 4); + ipip6_tunnel_link(sitn, t); + } if (old_p->link != p->link || t->fwmark != fwmark) { WRITE_ONCE(t->fwmark, fwmark); ipip6_tunnel_bind_dev(t->dev); } dst_cache_reset(&t->dst_cache); netdev_state_change(t->dev); - kfree(old_p); + kfree_rcu(old_p, rcu); return 0; } @@ -1336,12 +1385,14 @@ static int ipip6_tunnel_get(struct net_device *dev, struct ip_tunnel_parm_kern *p) { struct ip_tunnel *t = netdev_priv(dev); + const struct ip_tunnel_parm_kern *parms; if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) t = ipip6_tunnel_locate(t->net, p, 0); if (!t) t = netdev_priv(dev); - memcpy(p, t->sit_parms, sizeof(*p)); + parms = rtnl_dereference(t->sit_parms); + memcpy(p, parms, sizeof(*p)); return 0; } @@ -1464,8 +1515,15 @@ ipip6_tunnel_siocdevprivate(struct net_device *dev, struct ifreq *ifr, static int ipip6_get_iflink(const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); + const struct ip_tunnel_parm_kern *parms; + int link; - return READ_ONCE(tunnel->sit_parms->link); + rcu_read_lock(); + parms = rcu_dereference(tunnel->sit_parms); + link = parms ? parms->link : 0; + rcu_read_unlock(); + + return link; } static const struct net_device_ops ipip6_netdev_ops = { @@ -1480,6 +1538,7 @@ static const struct net_device_ops ipip6_netdev_ops = { static void ipip6_dev_free(struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); + struct ip_tunnel_parm_kern *parms; #ifdef CONFIG_IPV6_SIT_6RD struct ip_tunnel_6rd_parm *ip6rd; @@ -1487,8 +1546,9 @@ static void ipip6_dev_free(struct net_device *dev) RCU_INIT_POINTER(tunnel->ip6rd, NULL); kfree(ip6rd); #endif - kfree(tunnel->sit_parms); - tunnel->sit_parms = NULL; + parms = rcu_dereference_protected(tunnel->sit_parms, 1); + RCU_INIT_POINTER(tunnel->sit_parms, NULL); + kfree(parms); if (tunnel->dst_cache.cache) { dst_cache_destroy(&tunnel->dst_cache); tunnel->dst_cache.cache = NULL; @@ -1528,10 +1588,12 @@ static void ipip6_tunnel_setup(struct net_device *dev) static int ipip6_tunnel_init(struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); + struct ip_tunnel_parm_kern *parms; int err; tunnel->dev = dev; - strscpy(tunnel->sit_parms->name, dev->name); + parms = rtnl_dereference(tunnel->sit_parms); + strscpy(parms->name, dev->name); ipip6_tunnel_bind_dev(dev); @@ -1549,7 +1611,6 @@ static void __net_init ipip6_fb_tunnel_init(struct net_device *dev) struct ip_tunnel *tunnel = netdev_priv(dev); struct net *net = dev_net(dev); struct sit_net *sitn = net_generic(net, sit_net_id); - rcu_assign_pointer(sitn->tunnels_wc[0], tunnel); } @@ -1636,6 +1697,7 @@ static int ipip6_newlink(struct net_device *dev, #ifdef CONFIG_IPV6_SIT_6RD struct ip_tunnel_6rd ip6rd; #endif + struct ip_tunnel_parm_kern *nt_parms; struct ip_tunnel_parm_kern p; struct net *net; int err; @@ -1655,10 +1717,11 @@ static int ipip6_newlink(struct net_device *dev, if (ipip6_tunnel_locate(net, &p, 0)) return -EEXIST; - nt->sit_parms = kmalloc_obj(*nt->sit_parms); - if (!nt->sit_parms) + nt_parms = kmalloc_obj(*nt_parms); + if (!nt_parms) return -ENOMEM; - *nt->sit_parms = p; + *nt_parms = p; + rcu_assign_pointer(nt->sit_parms, nt_parms); err = ipip6_tunnel_create(dev); if (err < 0) { @@ -1783,7 +1846,7 @@ static size_t ipip6_get_size(const struct net_device *dev) static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - struct ip_tunnel_parm_kern *parm = tunnel->sit_parms; + const struct ip_tunnel_parm_kern *parm = rtnl_dereference(tunnel->sit_parms); #ifdef CONFIG_IPV6_SIT_6RD const struct ip_tunnel_6rd_parm *ip6rd; #endif @@ -1929,6 +1992,7 @@ static void __net_exit sit_exit_rtnl_net(struct net *net, struct list_head *head static int __net_init sit_init_net(struct net *net) { struct sit_net *sitn = net_generic(net, sit_net_id); + struct ip_tunnel_parm_kern *nt_parms; struct ip_tunnel *t; int err; @@ -1956,17 +2020,18 @@ static int __net_init sit_init_net(struct net *net) t = netdev_priv(sitn->fb_tunnel_dev); t->net = net; - t->sit_parms = kzalloc_obj(*t->sit_parms); - if (!t->sit_parms) { + nt_parms = kzalloc_obj(*nt_parms); + if (!nt_parms) { err = -ENOMEM; goto err_reg_dev; } - t->sit_parms->iph.version = 4; - t->sit_parms->iph.protocol = IPPROTO_IPV6; - t->sit_parms->iph.ihl = 5; - t->sit_parms->iph.ttl = 64; - strscpy(t->sit_parms->name, sitn->fb_tunnel_dev->name); - t->parms = *t->sit_parms; + nt_parms->iph.version = 4; + nt_parms->iph.protocol = IPPROTO_IPV6; + nt_parms->iph.ihl = 5; + nt_parms->iph.ttl = 64; + strscpy(nt_parms->name, sitn->fb_tunnel_dev->name); + t->parms = *nt_parms; + rcu_assign_pointer(t->sit_parms, nt_parms); err = ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); if (err < 0) From f712bf6f17d881763547d6c33ccdcf3e62d4ae84 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 7 Sep 2026 07:58:46 +0000 Subject: [PATCH 0413/2126] sit: no longer rely on RTNL in ipip6_fill_info() Now that SIT parameters and 6RD parameters are RCU-protected, and fwmark/encap are annotated with READ_ONCE()/WRITE_ONCE(), ipip6_fill_info() no longer requires RTNL to be held. Wrap the attribute serialization in rcu_read_lock() and rcu_read_unlock(). Signed-off-by: Eric Dumazet Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260907075846.2913645-10-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/sit.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index c9049ab87e01..14ba3cfb304a 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1846,11 +1846,18 @@ static size_t ipip6_get_size(const struct net_device *dev) static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - const struct ip_tunnel_parm_kern *parm = rtnl_dereference(tunnel->sit_parms); + const struct ip_tunnel_parm_kern *parm; #ifdef CONFIG_IPV6_SIT_6RD const struct ip_tunnel_6rd_parm *ip6rd; #endif + rcu_read_lock(); + parm = rcu_dereference(tunnel->sit_parms); + if (!parm) { + rcu_read_unlock(); + return -ENODEV; + } + if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || @@ -1865,7 +1872,7 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) goto nla_put_failure; #ifdef CONFIG_IPV6_SIT_6RD - ip6rd = rcu_dereference_rtnl(tunnel->ip6rd); + ip6rd = rcu_dereference(tunnel->ip6rd); if (ip6rd && (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX, &ip6rd->prefix) || @@ -1879,18 +1886,20 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) #endif if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE, - tunnel->encap.type) || + READ_ONCE(tunnel->encap.type)) || nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT, - tunnel->encap.sport) || + READ_ONCE(tunnel->encap.sport)) || nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT, - tunnel->encap.dport) || + READ_ONCE(tunnel->encap.dport)) || nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS, - tunnel->encap.flags)) + READ_ONCE(tunnel->encap.flags))) goto nla_put_failure; + rcu_read_unlock(); return 0; nla_put_failure: + rcu_read_unlock(); return -EMSGSIZE; } From 348ea4642f56ab3dc93621c8e3ab0ccd0e5f1782 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 11:00:09 -0700 Subject: [PATCH 0414/2126] selftests: net: add ctl_file_write() helper Setting a sysctl or a sysfs attribute for the duration of a test and putting the old value back has been open coded multiple times. We generally avoid creating library helpers but this one is very common, and the defer is a little tricky as using the same function for defer as the initial write leads to an infinite loop (not that I would ever make such mistake!) Some of the conversions are not identical, but arguably ctl_file_write() semantics are more correct. Reviewed-by: Nimrod Oren Reviewed-by: Bobby Eshleman Link: https://patch.msgid.link/20260909180009.1894019-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/gro_lib.py | 17 +++--------- .../drivers/net/hw/devlink_rate_tc_bw.py | 5 ++-- .../drivers/net/hw/lib/py/__init__.py | 4 +-- .../selftests/drivers/net/hw/toeplitz.py | 10 +++---- .../selftests/drivers/net/lib/py/__init__.py | 4 +-- .../selftests/drivers/net/ring_reconfig.py | 26 ++++--------------- .../testing/selftests/net/lib/py/__init__.py | 4 +-- tools/testing/selftests/net/lib/py/utils.py | 22 ++++++++++++++++ 8 files changed, 42 insertions(+), 50 deletions(-) diff --git a/tools/testing/selftests/drivers/net/gro_lib.py b/tools/testing/selftests/drivers/net/gro_lib.py index 45ded8477a50..b7ac0660adc0 100644 --- a/tools/testing/selftests/drivers/net/gro_lib.py +++ b/tools/testing/selftests/drivers/net/gro_lib.py @@ -48,7 +48,7 @@ import re from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import NetDrvEpEnv, KsftFailEx, KsftXfailEx from lib.py import NetdevFamily, EthtoolFamily -from lib.py import bkg, cmd, defer, ethtool, ip +from lib.py import bkg, cmd, ctl_file_write, defer, ethtool, ip from lib.py import ksft_variants, KsftNamedVariant @@ -85,17 +85,6 @@ def _resolve_dmac(cfg, ipver): return getattr(cfg, attr) -def _write_defer_restore(cfg, path, val, defer_undo=False): - with open(path, "r", encoding="utf-8") as fp: - orig_val = fp.read().strip() - if str(val) == orig_val: - return - with open(path, "w", encoding="utf-8") as fp: - fp.write(val) - if defer_undo: - defer(_write_defer_restore, cfg, path, orig_val) - - def _set_mtu_restore(dev, mtu, host): if dev['mtu'] < mtu: ip(f"link set dev {dev['ifname']} mtu {mtu}", host=host) @@ -250,8 +239,8 @@ def _setup(cfg, mode, test_name): flush_path = f"/sys/class/net/{cfg.ifname}/gro_flush_timeout" irq_path = f"/sys/class/net/{cfg.ifname}/napi_defer_hard_irqs" - _write_defer_restore(cfg, flush_path, "200000", defer_undo=True) - _write_defer_restore(cfg, irq_path, "10", defer_undo=True) + ctl_file_write(flush_path, "200000") + ctl_file_write(irq_path, "10") _set_ethtool_feat(cfg.ifname, cfg.feat, {"generic-receive-offload": True, diff --git a/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py b/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py index 4e4faa9275bb..38d712755257 100755 --- a/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py +++ b/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py @@ -63,7 +63,7 @@ from lib.py import ksft_pr, ksft_run, ksft_exit from lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx from lib.py import NetDrvEpEnv, DevlinkFamily from lib.py import NlError -from lib.py import cmd, defer, ethtool, ip +from lib.py import cmd, ctl_file_write, defer, ethtool, ip from lib.py import Iperf3Runner @@ -113,8 +113,7 @@ def setup_vf(cfg, set_tc_mapping=True): except Exception as exc: raise KsftSkipEx(f"Failed to enable switchdev mode on {cfg.pci}") from exc try: - cmd(f"echo 1 > /sys/class/net/{cfg.ifname}/device/sriov_numvfs", shell=True) - defer(cmd, f"echo 0 > /sys/class/net/{cfg.ifname}/device/sriov_numvfs", shell=True) + ctl_file_write(f"/sys/class/net/{cfg.ifname}/device/sriov_numvfs", 1) except Exception as exc: raise KsftSkipEx(f"Failed to enable SR-IOV on {cfg.ifname}") from exc diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py index 8a58cb17cc06..81e1d1865cd5 100644 --- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py @@ -24,7 +24,7 @@ try: from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, \ - wait_file, tool + wait_file, ctl_file_write, tool from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ @@ -40,7 +40,7 @@ try: "CmdExitFailure", "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool", "fd_read_timeout", "ip", "rand_port", "rand_ports", - "wait_port_listen", "wait_file", "tool", + "wait_port_listen", "wait_file", "ctl_file_write", "tool", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "KsftSkipEx", "KsftFailEx", "KsftXfailEx", "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run", diff --git a/tools/testing/selftests/drivers/net/hw/toeplitz.py b/tools/testing/selftests/drivers/net/hw/toeplitz.py index 571732198b93..962d1aca2bc9 100755 --- a/tools/testing/selftests/drivers/net/hw/toeplitz.py +++ b/tools/testing/selftests/drivers/net/hw/toeplitz.py @@ -13,7 +13,7 @@ import os import socket from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import NetDrvEpEnv, EthtoolFamily, NetdevFamily -from lib.py import cmd, bkg, rand_port, defer +from lib.py import cmd, bkg, ctl_file_write, rand_port, defer from lib.py import ksft_in from lib.py import ksft_variants, KsftNamedVariant, KsftSkipEx, KsftFailEx @@ -113,7 +113,7 @@ def _get_unused_rps_cpus(cfg, count=2): def _configure_rps(cfg, rps_cpus): - """Configure RPS for all Rx queues.""" + """Configure RPS for all Rx queues, restored at the end of the test.""" mask = 0 for cpu in rps_cpus: @@ -123,9 +123,8 @@ def _configure_rps(cfg, rps_cpus): # Set RPS bitmap for all rx queues for rps_file in glob.glob(f"/sys/class/net/{cfg.ifname}/queues/rx-*/rps_cpus"): - with open(rps_file, "w", encoding="utf-8") as fp: - # sysfs expects hex without '0x' prefix, toeplitz.c needs the prefix - fp.write(mask[2:]) + # sysfs expects hex without '0x' prefix, toeplitz.c needs the prefix + ctl_file_write(rps_file, mask[2:]) return mask @@ -208,7 +207,6 @@ def test(cfg, proto_flag, ipver, grp): # Get CPUs not used by Rx queues and configure them for RPS rps_cpus = _get_unused_rps_cpus(cfg, count=2) rps_mask = _configure_rps(cfg, rps_cpus) - defer(_configure_rps, cfg, []) rx_cmd += ["-r", rps_mask] ksft_pr(f"RPS using CPUs: {rps_cpus}, mask: {rps_mask}") diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools/testing/selftests/drivers/net/lib/py/__init__.py index ee903bcf3207..591b1e6c7eea 100644 --- a/tools/testing/selftests/drivers/net/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py @@ -24,7 +24,7 @@ try: from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ fd_read_timeout, ip, rand_port, rand_ports, tc, wait_port_listen, \ - wait_file + wait_file, ctl_file_write from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ @@ -38,7 +38,7 @@ try: "CmdExitFailure", "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool", "fd_read_timeout", "ip", "rand_port", "rand_ports", "tc", - "wait_port_listen", "wait_file", + "wait_port_listen", "wait_file", "ctl_file_write", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "KsftSkipEx", "KsftFailEx", "KsftXfailEx", "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run", diff --git a/tools/testing/selftests/drivers/net/ring_reconfig.py b/tools/testing/selftests/drivers/net/ring_reconfig.py index 2bc329b77134..6682d4badfbf 100755 --- a/tools/testing/selftests/drivers/net/ring_reconfig.py +++ b/tools/testing/selftests/drivers/net/ring_reconfig.py @@ -13,7 +13,7 @@ from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_eq from lib.py import KsftSkipEx, KsftXfailEx from lib.py import NetDrvEpEnv, EthtoolFamily, GenerateTraffic -from lib.py import cmd, defer, rand_port, tc, NlError +from lib.py import cmd, ctl_file_write, defer, rand_port, tc, NlError # Added in Python 3.13; fallback to 61 for x86/ARM/MIPS SO_TXTIME = getattr(socket, "SO_TXTIME", 61) @@ -166,22 +166,6 @@ def ringparam(cfg) -> None: GenerateTraffic(cfg).wait_pkts_and_stop(10000) -def _write_file(path, val): - """Write val to a file.""" - with open(path, "w", encoding="utf-8") as fp: - fp.write(str(val)) - - -def _write_sysfs(path, val): - """Write val to a sysfs file, restoring the original value on exit.""" - with open(path, "r", encoding="utf-8") as fp: - orig_val = fp.read().strip() - if str(val) == orig_val: - return - _write_file(path, val) - defer(_write_file, path, orig_val) - - def _get_qdisc_backlog(cfg, mq_handle, queue): """Return the qdisc backlog (bytes) for the given TX queue's leaf.""" target_parent = f"{mq_handle}{queue + 1:x}" @@ -342,8 +326,8 @@ def reconfig_tx_stall(cfg) -> None: # Slow completions so the ring stays full after FQ releases packets napi_defer = f"/sys/class/net/{cfg.ifname}/napi_defer_hard_irqs" gro_timeout = f"/sys/class/net/{cfg.ifname}/gro_flush_timeout" - _write_sysfs(napi_defer, 100) - _write_sysfs(gro_timeout, 1000000000) + ctl_file_write(napi_defer, 100) + ctl_file_write(gro_timeout, 1000000000) port = rand_port() # A single flow must overflow the ring, so send twice the ring depth and @@ -384,8 +368,8 @@ def reconfig_tx_stall(cfg) -> None: cfg.eth.rings_set(ehdr | {'tx': tx_cur}) # Let completions proceed normally - _write_sysfs(napi_defer, 0) - _write_sysfs(gro_timeout, 0) + ctl_file_write(napi_defer, 0) + ctl_file_write(gro_timeout, 0) # Poll for backlog to drain for _ in range(100): diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py index 34935886b6ad..71df5880b356 100644 --- a/tools/testing/selftests/net/lib/py/__init__.py +++ b/tools/testing/selftests/net/lib/py/__init__.py @@ -14,7 +14,7 @@ from .netns import NetNS, NetNSEnter, UserNetNS from .nsim import NetdevSim, NetdevSimDev from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \ bpftool, ip, ethtool, bpftrace, rand_port, rand_ports, wait_port_listen, \ - wait_file, tool, tc + ctl_file_write, wait_file, tool, tc from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from .ynl import NlError, NlctrlFamily, YnlFamily, \ EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily @@ -29,7 +29,7 @@ __all__ = ["KSRC", "NetNS", "NetNSEnter", "UserNetNS", "CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer", "bpftool", "ip", "ethtool", "bpftrace", "rand_port", "rand_ports", - "wait_port_listen", "wait_file", "tool", "tc", + "wait_port_listen", "ctl_file_write", "wait_file", "tool", "tc", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "NetdevSim", "NetdevSimDev", "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError", diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index 184bb04343f6..1727bc418073 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -357,6 +357,28 @@ def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadlin time.sleep(sleep) +def _ctl_file_write(path, val): + with open(path, "w", encoding="utf-8") as fp: + fp.write(str(val)) + + +def ctl_file_write(path, val): + """ + Write @val to a control file - a sysctl, a sysfs attribute, configfs... + and defer() restoring the old value, so needs a defer queue. + + Writing a value which is already set is skipped, there is nothing + to restore in that case. + """ + with open(path, "r", encoding="utf-8") as fp: + old = fp.read().strip() + if old == str(val): + return + + _ctl_file_write(path, val) + defer(_ctl_file_write, path, old) + + def wait_file(fname, test_fn, sleep=0.005, deadline=5, encoding='utf-8'): """ Wait for file contents on the local system to satisfy a condition. From 1b9c4f3f9cd2bc485255ec1b3103ed9b11af4737 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Wed, 19 Aug 2026 12:24:07 +0200 Subject: [PATCH 0415/2126] netfilter: seqadj: do not take ct lock if seqadj is NULL This is a small optimization, only take ct lock if seqadj is present. In the unlikely case seqadj isn't present we can return immediately. This is consistent with the behavior of other functions that checks seqadj. Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_seqadj.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c index 220216a4edc5..d75e8dafb189 100644 --- a/net/netfilter/nf_conntrack_seqadj.c +++ b/net/netfilter/nf_conntrack_seqadj.c @@ -10,20 +10,19 @@ int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo, s32 off) { + struct nf_conn_seqadj *seqadj = nfct_seqadj(ct); enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); - struct nf_conn_seqadj *seqadj; struct nf_ct_seqadj *this_way; if (off == 0) return 0; - spin_lock_bh(&ct->lock); - seqadj = nfct_seqadj(ct); - if (!seqadj) { - spin_unlock_bh(&ct->lock); + if (unlikely(!seqadj)) return 0; - } + set_bit(IPS_SEQ_ADJUST_BIT, &ct->status); + + spin_lock_bh(&ct->lock); this_way = &seqadj->seq[dir]; this_way->offset_before = off; this_way->offset_after = off; From ba100f6f2a0283d546688ef29b25676f77916449 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 3 Sep 2026 13:30:13 +0200 Subject: [PATCH 0416/2126] netfilter: x_tables: use GFP_KERNEL_ACCOUNT in match/target GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Use GFP_KERNEL_ACCOUNT for objects that are allocated in the xtables .check path. This includes template ct object with extensions such as helper and timeout. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_ovs.c | 2 +- net/netfilter/xt_CT.c | 6 +++--- net/netfilter/xt_IDLETIMER.c | 8 ++++---- net/netfilter/xt_LED.c | 5 +++-- net/netfilter/xt_RATEEST.c | 2 +- net/netfilter/xt_TEE.c | 2 +- net/netfilter/xt_hashlimit.c | 4 ++-- net/netfilter/xt_limit.c | 2 +- net/netfilter/xt_quota.c | 2 +- net/netfilter/xt_recent.c | 3 ++- net/netfilter/xt_statistic.c | 2 +- net/netfilter/xt_string.c | 2 +- 12 files changed, 21 insertions(+), 19 deletions(-) diff --git a/net/netfilter/nf_conntrack_ovs.c b/net/netfilter/nf_conntrack_ovs.c index b4085af3ad1c..fe525b324af4 100644 --- a/net/netfilter/nf_conntrack_ovs.c +++ b/net/netfilter/nf_conntrack_ovs.c @@ -93,7 +93,7 @@ int nf_ct_add_helper(struct nf_conn *ct, const char *name, u8 family, if (!helper) return -EINVAL; - help = nf_ct_helper_ext_add(ct, GFP_KERNEL); + help = nf_ct_helper_ext_add(ct, GFP_KERNEL_ACCOUNT); if (!help) { nf_conntrack_helper_put(helper); return -ENOMEM; diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c index e78660dfdf4b..205bc6dd9812 100644 --- a/net/netfilter/xt_CT.c +++ b/net/netfilter/xt_CT.c @@ -91,7 +91,7 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name, return -ENOENT; } - help = nf_ct_helper_ext_add(ct, GFP_KERNEL); + help = nf_ct_helper_ext_add(ct, GFP_KERNEL_ACCOUNT); if (help == NULL) { nf_conntrack_helper_put(helper); return -ENOMEM; @@ -182,7 +182,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par, if (info->flags & XT_CT_ZONE_MARK) zone.flags |= NF_CT_FLAG_MARK; - ct = nf_ct_tmpl_alloc(par->net, &zone, GFP_KERNEL); + ct = nf_ct_tmpl_alloc(par->net, &zone, GFP_KERNEL_ACCOUNT); if (!ct) { ret = -ENOMEM; goto err2; @@ -190,7 +190,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par, if ((info->ct_events || info->exp_events) && !nf_ct_ecache_ext_add(ct, info->ct_events, info->exp_events, - GFP_KERNEL)) { + GFP_KERNEL_ACCOUNT)) { ret = -EINVAL; goto err3; } diff --git a/net/netfilter/xt_IDLETIMER.c b/net/netfilter/xt_IDLETIMER.c index fe7d8d19629b..71b78b5da698 100644 --- a/net/netfilter/xt_IDLETIMER.c +++ b/net/netfilter/xt_IDLETIMER.c @@ -147,7 +147,7 @@ static int idletimer_tg_create(struct idletimer_tg_info *info) { int ret; - info->timer = kzalloc_obj(*info->timer); + info->timer = kzalloc_obj(*info->timer, GFP_KERNEL_ACCOUNT); if (!info->timer) { ret = -ENOMEM; goto out; @@ -158,7 +158,7 @@ static int idletimer_tg_create(struct idletimer_tg_info *info) goto out_free_timer; sysfs_attr_init(&info->timer->attr.attr); - info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL); + info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL_ACCOUNT); if (!info->timer->attr.attr.name) { ret = -ENOMEM; goto out_free_timer; @@ -196,7 +196,7 @@ static int idletimer_tg_create_v1(struct idletimer_tg_info_v1 *info) { int ret; - info->timer = kmalloc_obj(*info->timer); + info->timer = kmalloc_obj(*info->timer, GFP_KERNEL_ACCOUNT); if (!info->timer) { ret = -ENOMEM; goto out; @@ -207,7 +207,7 @@ static int idletimer_tg_create_v1(struct idletimer_tg_info_v1 *info) goto out_free_timer; sysfs_attr_init(&info->timer->attr.attr); - info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL); + info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL_ACCOUNT); if (!info->timer->attr.attr.name) { ret = -ENOMEM; goto out_free_timer; diff --git a/net/netfilter/xt_LED.c b/net/netfilter/xt_LED.c index caaaf4d2c584..3cbb8d61d417 100644 --- a/net/netfilter/xt_LED.c +++ b/net/netfilter/xt_LED.c @@ -111,11 +111,12 @@ static int led_tg_check(const struct xt_tgchk_param *par) } err = -ENOMEM; - ledinternal = kzalloc_obj(struct xt_led_info_internal); + ledinternal = kzalloc_obj(struct xt_led_info_internal, + GFP_KERNEL_ACCOUNT); if (!ledinternal) goto exit_mutex_only; - ledinternal->trigger_id = kstrdup(ledinfo->id, GFP_KERNEL); + ledinternal->trigger_id = kstrdup(ledinfo->id, GFP_KERNEL_ACCOUNT); if (!ledinternal->trigger_id) goto exit_internal_alloc; diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c index 91270d467ffd..2f6b512b71e8 100644 --- a/net/netfilter/xt_RATEEST.c +++ b/net/netfilter/xt_RATEEST.c @@ -139,7 +139,7 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par) } ret = -ENOMEM; - est = kzalloc_obj(*est); + est = kzalloc_obj(*est, GFP_KERNEL_ACCOUNT); if (!est) goto err1; diff --git a/net/netfilter/xt_TEE.c b/net/netfilter/xt_TEE.c index 5d34ceb893ed..48b4104f0859 100644 --- a/net/netfilter/xt_TEE.c +++ b/net/netfilter/xt_TEE.c @@ -106,7 +106,7 @@ static int tee_tg_check(const struct xt_tgchk_param *par) if (info->oif[sizeof(info->oif)-1] != '\0') return -EINVAL; - priv = kzalloc_obj(*priv); + priv = kzalloc_obj(*priv, GFP_KERNEL_ACCOUNT); if (priv == NULL) return -ENOMEM; diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index 9af0fa895f73..57ac455bc331 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c @@ -294,7 +294,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, if (size < 16) size = 16; } - hinfo = kvmalloc_flex(*hinfo, hash, size); + hinfo = kvmalloc_flex(*hinfo, hash, size, GFP_KERNEL_ACCOUNT); if (hinfo == NULL) return -ENOMEM; *out_hinfo = hinfo; @@ -319,7 +319,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, hinfo->count = 0; hinfo->family = family; hinfo->rnd_initialized = false; - hinfo->name = kstrdup(name, GFP_KERNEL); + hinfo->name = kstrdup(name, GFP_KERNEL_ACCOUNT); if (!hinfo->name) { kvfree(hinfo); return -ENOMEM; diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c index 87d74da14c0b..ad48b6879b13 100644 --- a/net/netfilter/xt_limit.c +++ b/net/netfilter/xt_limit.c @@ -115,7 +115,7 @@ static int limit_mt_check(const struct xt_mtchk_param *par) return -ERANGE; } - priv = kmalloc_obj(*priv); + priv = kmalloc_obj(*priv, GFP_KERNEL_ACCOUNT); if (priv == NULL) return -ENOMEM; diff --git a/net/netfilter/xt_quota.c b/net/netfilter/xt_quota.c index b05c5c8dac78..e21ec152d16a 100644 --- a/net/netfilter/xt_quota.c +++ b/net/netfilter/xt_quota.c @@ -50,7 +50,7 @@ static int quota_mt_check(const struct xt_mtchk_param *par) if (q->flags & ~XT_QUOTA_MASK) return -EINVAL; - q->master = kmalloc_obj(*q->master); + q->master = kmalloc_obj(*q->master, GFP_KERNEL_ACCOUNT); if (q->master == NULL) return -ENOMEM; diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c index d34831ce3adf..55f1f2d89952 100644 --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c @@ -391,7 +391,8 @@ static int recent_mt_check(const struct xt_mtchk_param *par, goto out; } - t = kvzalloc_flex(*t, iphash, ip_list_hash_size); + t = kvzalloc_flex(*t, iphash, ip_list_hash_size, + GFP_KERNEL_ACCOUNT); if (t == NULL) { ret = -ENOMEM; goto out; diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c index 334e09771abf..1ffc59d90bb0 100644 --- a/net/netfilter/xt_statistic.c +++ b/net/netfilter/xt_statistic.c @@ -58,7 +58,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par) info->flags & ~XT_STATISTIC_MASK) return -EINVAL; - info->master = kzalloc_obj(*info->master); + info->master = kzalloc_obj(*info->master, GFP_KERNEL_ACCOUNT); if (info->master == NULL) return -ENOMEM; atomic_set(&info->master->count, info->u.nth.count); diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c index 8ce25bc9b277..52c1deb02cdc 100644 --- a/net/netfilter/xt_string.c +++ b/net/netfilter/xt_string.c @@ -54,7 +54,7 @@ static int string_mt_check(const struct xt_mtchk_param *par) if (conf->u.v1.flags & XT_STRING_FLAG_IGNORECASE) flags |= TS_IGNORECASE; ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen, - GFP_KERNEL, flags); + GFP_KERNEL_ACCOUNT, flags); if (IS_ERR(ts_conf)) return PTR_ERR(ts_conf); From ef2344e67c0cfa4add7edba89881e9ccddad31c0 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 11 Sep 2026 10:00:09 +0200 Subject: [PATCH 0417/2126] netfilter: nfnetlink: use GFP_KERNEL_ACCOUNT GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Use GFP_KERNEL_ACCOUNT for objects that are created from nfnetlink subsystems. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nfnetlink_acct.c | 2 +- net/netfilter/nfnetlink_cthelper.c | 3 ++- net/netfilter/nfnetlink_cttimeout.c | 8 +++++--- net/netfilter/nfnetlink_osf.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c index 8ff1e0ad5cb0..1a366fbd8133 100644 --- a/net/netfilter/nfnetlink_acct.c +++ b/net/netfilter/nfnetlink_acct.c @@ -112,7 +112,7 @@ static int nfnl_acct_new(struct sk_buff *skb, const struct nfnl_info *info, size += sizeof(u64); } - nfacct = kzalloc(sizeof(struct nf_acct) + size, GFP_KERNEL); + nfacct = kzalloc(sizeof(struct nf_acct) + size, GFP_KERNEL_ACCOUNT); if (nfacct == NULL) return -ENOMEM; diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c index 5b6a09f46903..a09b2fdbf9b4 100644 --- a/net/netfilter/nfnetlink_cthelper.c +++ b/net/netfilter/nfnetlink_cthelper.c @@ -335,7 +335,8 @@ static int nfnl_cthelper_update_policy_all(struct nlattr *tb[], struct nf_conntrack_expect_policy *policy; int i, ret = 0; - new_policy = kmalloc_objs(*new_policy, helper->expect_class_max + 1); + new_policy = kmalloc_objs(*new_policy, helper->expect_class_max + 1, + GFP_KERNEL_ACCOUNT); if (!new_policy) return -ENOMEM; diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c index e751f2b9c51d..c667a29d92f1 100644 --- a/net/netfilter/nfnetlink_cttimeout.c +++ b/net/netfilter/nfnetlink_cttimeout.c @@ -71,7 +71,8 @@ ctnl_timeout_parse_policy(void *timeout, struct nlattr **tb; int ret = 0; - tb = kzalloc_objs(*tb, l4proto->ctnl_timeout.nlattr_max + 1); + tb = kzalloc_objs(*tb, l4proto->ctnl_timeout.nlattr_max + 1, + GFP_KERNEL_ACCOUNT); if (!tb) return -ENOMEM; @@ -150,14 +151,15 @@ static int cttimeout_new_timeout(struct sk_buff *skb, goto err_proto_put; } - timeout = kzalloc_obj(*timeout); + timeout = kzalloc_obj(*timeout, GFP_KERNEL_ACCOUNT); if (timeout == NULL) { ret = -ENOMEM; goto err_proto_put; } timeout->timeout = kzalloc(sizeof(*timeout->timeout) + - l4proto->ctnl_timeout.obj_size, GFP_KERNEL); + l4proto->ctnl_timeout.obj_size, + GFP_KERNEL_ACCOUNT); if (!timeout->timeout) { ret = -ENOMEM; goto err; diff --git a/net/netfilter/nfnetlink_osf.c b/net/netfilter/nfnetlink_osf.c index 92002079f8ea..e4835b0f4bb1 100644 --- a/net/netfilter/nfnetlink_osf.c +++ b/net/netfilter/nfnetlink_osf.c @@ -325,7 +325,7 @@ static int nfnl_osf_add_callback(struct sk_buff *skb, !memchr(f->version, 0, MAXGENRELEN)) return -EINVAL; - kf = kmalloc_obj(struct nf_osf_finger); + kf = kmalloc_obj(struct nf_osf_finger, GFP_KERNEL_ACCOUNT); if (!kf) return -ENOMEM; From e8609e8d56fb83e407098ffbe21c068fd5e6cbf9 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 7 Sep 2026 20:55:47 +0200 Subject: [PATCH 0418/2126] netfilter: nf_tables: use GFP_KERNEL_ACCOUNT GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Just a few leftover in nft_ct and the pipapo set backend, including alloc_percpu() calls. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_ct.c | 5 +++-- net/netfilter/nft_set_pipapo.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c index 9dbf127df9c8..3c4c2faa7398 100644 --- a/net/netfilter/nft_ct.c +++ b/net/netfilter/nft_ct.c @@ -848,7 +848,8 @@ nft_ct_timeout_parse_policy(void *timeouts, struct nlattr **tb; int ret = 0; - tb = kzalloc_objs(*tb, l4proto->ctnl_timeout.nlattr_max + 1); + tb = kzalloc_objs(*tb, l4proto->ctnl_timeout.nlattr_max + 1, + GFP_KERNEL_ACCOUNT); if (!tb) return -ENOMEM; @@ -934,7 +935,7 @@ static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx, } timeout = kzalloc(sizeof(struct nf_ct_timeout) + - l4proto->ctnl_timeout.obj_size, GFP_KERNEL); + l4proto->ctnl_timeout.obj_size, GFP_KERNEL_ACCOUNT); if (timeout == NULL) { ret = -ENOMEM; goto err_proto_put; diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index 978bb0c01106..a40f9d952184 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -1441,7 +1441,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) new->field_count = old->field_count; new->bsize_max = old->bsize_max; - new->scratch = alloc_percpu(*new->scratch); + new->scratch = alloc_percpu_gfp(*new->scratch, GFP_KERNEL_ACCOUNT); if (!new->scratch) goto out_scratch; @@ -2298,14 +2298,14 @@ static int nft_pipapo_init(const struct nft_set *set, if (field_count > NFT_PIPAPO_MAX_FIELDS) return -EINVAL; - m = kmalloc_flex(*m, f, field_count); + m = kmalloc_flex(*m, f, field_count, GFP_KERNEL_ACCOUNT); if (!m) return -ENOMEM; m->field_count = field_count; m->bsize_max = 0; - m->scratch = alloc_percpu(struct nft_pipapo_scratch *); + m->scratch = alloc_percpu_gfp(struct nft_pipapo_scratch *, GFP_KERNEL_ACCOUNT); if (!m->scratch) { err = -ENOMEM; goto out_scratch; From 399a0b7f32589c84e30cb800a51f69a178499a5f Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 7 Sep 2026 20:55:48 +0200 Subject: [PATCH 0419/2126] netfilter: synproxy: use GFP_KERNEL_ACCOUNT GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Allocate template conntrack via GFP_KERNEL_ACCOUNT. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_synproxy_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index acd360515972..9fc959ba2030 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -336,7 +336,7 @@ static int __net_init synproxy_net_init(struct net *net) struct nf_conn *ct; int err = -ENOMEM; - ct = nf_ct_tmpl_alloc(net, &nf_ct_zone_dflt, GFP_KERNEL); + ct = nf_ct_tmpl_alloc(net, &nf_ct_zone_dflt, GFP_KERNEL_ACCOUNT); if (!ct) goto err1; From 324ca7a2b6feb50f8a561abb6d189d3b2d604b8f Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 7 Sep 2026 20:55:49 +0200 Subject: [PATCH 0420/2126] netfilter: sysctl: use GFP_KERNEL_ACCOUNT GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Allocate per-netns sysctl via GFP_KERNEL_ACCOUNT. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_standalone.c | 2 +- net/netfilter/nf_hooks_lwtunnel.c | 2 +- net/netfilter/nf_log.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index f4f2d82192d5..d88a10230862 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -1009,7 +1009,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net) BUILD_BUG_ON(ARRAY_SIZE(nf_ct_sysctl_table) != NF_SYSCTL_CT_LAST_SYSCTL); table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!table) return -ENOMEM; diff --git a/net/netfilter/nf_hooks_lwtunnel.c b/net/netfilter/nf_hooks_lwtunnel.c index 4e1eef1ba0f1..40c6fce14a63 100644 --- a/net/netfilter/nf_hooks_lwtunnel.c +++ b/net/netfilter/nf_hooks_lwtunnel.c @@ -73,7 +73,7 @@ static int __net_init nf_lwtunnel_net_init(struct net *net) if (!net_eq(net, &init_net)) { table = kmemdup(nf_lwtunnel_sysctl_table, sizeof(nf_lwtunnel_sysctl_table), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!table) goto err_alloc; } diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c index f4d80654dfe6..f1d3649e3fc6 100644 --- a/net/netfilter/nf_log.c +++ b/net/netfilter/nf_log.c @@ -493,7 +493,7 @@ static int netfilter_log_sysctl_init(struct net *net) if (!net_eq(net, &init_net)) { table = kmemdup(nf_log_sysctl_table, sizeof(nf_log_sysctl_table), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!table) goto err_alloc; } else { From 70deb8ec08cf945af7b110b32d0fa898da5aa852 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 7 Sep 2026 20:55:50 +0200 Subject: [PATCH 0421/2126] netfilter: nat: use GFP_KERNEL_ACCOUNT GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Allocate the internal nat hook via GFP_KERNEL_ACCOUNT. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_nat_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c index 8ac326e1eb5b..09cc5b8fd6af 100644 --- a/net/netfilter/nf_nat_core.c +++ b/net/netfilter/nf_nat_core.c @@ -1204,14 +1204,15 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, if (!nat_proto_net->nat_hook_ops) { WARN_ON(nat_proto_net->users != 0); - nat_ops = kmemdup_array(orig_nat_ops, ops_count, sizeof(*orig_nat_ops), GFP_KERNEL); + nat_ops = kmemdup_array(orig_nat_ops, ops_count, sizeof(*orig_nat_ops), + GFP_KERNEL_ACCOUNT); if (!nat_ops) { mutex_unlock(&nf_nat_proto_mutex); return -ENOMEM; } for (i = 0; i < ops_count; i++) { - priv = kzalloc_obj(*priv); + priv = kzalloc_obj(*priv, GFP_KERNEL_ACCOUNT); if (priv) { nat_ops[i].priv = priv; continue; From 0e28586ee444ae85513c09a7a211483c540df9f5 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 7 Sep 2026 20:55:51 +0200 Subject: [PATCH 0422/2126] netfilter: conncount: use GFP_KERNEL_ACCOUNT GFP_KERNEL_ACCOUNT is preferred these days for memcg, replace GFP_KERNEL by GFP_KERNEL_ACCOUNT. Allocate the internal nf_conncount datastructure via GFP_KERNEL_ACCOUNT. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conncount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nf_conncount.c b/net/netfilter/nf_conncount.c index 4292c3d9addd..eca7a8d330ce 100644 --- a/net/netfilter/nf_conncount.c +++ b/net/netfilter/nf_conncount.c @@ -692,7 +692,7 @@ struct nf_conncount_data *nf_conncount_init(struct net *net, unsigned int keylen keylen == 0) return ERR_PTR(-EINVAL); - data = kvzalloc_obj(*data); + data = kvzalloc_obj(*data, GFP_KERNEL_ACCOUNT); if (!data) return ERR_PTR(-ENOMEM); From 17d3afadf539c93def8106bbb83c88274bdc7ab1 Mon Sep 17 00:00:00 2001 From: Ratheesh Kannoth Date: Tue, 8 Sep 2026 11:41:13 +0530 Subject: [PATCH 0423/2126] octeontx2: collapse consecutive blank lines in source files Remove extra blank lines across the octeontx2 driver source. Signed-off-by: Ratheesh Kannoth Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 2 -- drivers/net/ethernet/marvell/octeontx2/af/mcs_reg.h | 2 -- drivers/net/ethernet/marvell/octeontx2/nic/qos.h | 2 -- 3 files changed, 6 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c index 3696bec7a8fc..8ced44a4495e 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -2043,8 +2043,6 @@ static int cgx_probe(struct pci_dev *pdev, const struct pci_device_id *id) } list_add(&cgx->cgx_list, &cgx_list); - - cgx_populate_features(cgx); mutex_init(&cgx->lock); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs_reg.h b/drivers/net/ethernet/marvell/octeontx2/af/mcs_reg.h index f4c6de89002c..ec932a592707 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/mcs_reg.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs_reg.h @@ -19,8 +19,6 @@ offset = 0xa28ull; \ offset += (a) * 0x8ull; \ offset; }) - - #define MCSX_MCS_TOP_SLAVE_CHANNEL_CFG(a) ({ \ u64 offset; \ \ diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos.h b/drivers/net/ethernet/marvell/octeontx2/nic/qos.h index 221bd0438f60..bd12174bf94e 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/qos.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos.h @@ -73,6 +73,4 @@ struct otx2_qos_node { u8 level; bool is_static; }; - - #endif From 90ab44517ee1f9e5018b6c274b95219cf229e617 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Wed, 9 Sep 2026 11:54:48 +0700 Subject: [PATCH 0424/2126] net: xilinx: axienet: Propagate errors from optional IRQ lookup platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available, while other errors should be propagated. Propagate all error codes returned by platform_get_irq_optional() other than -ENXIO. Another call to platform_get_irq_optional() in the same function already handles the return value this way. Apply the same error handling to this call site for consistency. Reviewed-by: Simon Horman Reviewed-by: Radhey Shyam Pandey Signed-off-by: bui duc phuc Link: https://patch.msgid.link/20260909045450.16176-2-phucduc.bui@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 1722b7038f34..207aecb5f8b9 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -2975,6 +2975,8 @@ static int axienet_probe(struct platform_device *pdev) dev_err(&pdev->dev, "could not determine irqs\n"); return -ENOMEM; } + if (lp->eth_irq < 0 && lp->eth_irq != -ENXIO) + return lp->eth_irq; /* Reset core now that clocks are enabled, prior to accessing MDIO */ ret = __axienet_device_reset(lp); From 2d2f18d49221846a5a3271ce93e08e4f9f784991 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Wed, 9 Sep 2026 11:54:49 +0700 Subject: [PATCH 0425/2126] net: xilinx: axienet: Handle optional IRQ return value correctly lp->eth_irq is assigned from platform_get_irq_optional(), which returns a non-zero interrupt number on success or a negative error number on failure. Errors other than -ENXIO are handled before this check, so -ENXIO is the only error value that can reach this point. Check for a negative value instead of treating 0 as an undefined IRQ. Reviewed-by: Simon Horman Reviewed-by: Radhey Shyam Pandey Signed-off-by: bui duc phuc Link: https://patch.msgid.link/20260909045450.16176-3-phucduc.bui@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 207aecb5f8b9..3927ababf833 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -3052,7 +3052,7 @@ static int axienet_probe(struct platform_device *pdev) ndev->ethtool_ops = &axienet_ethtool_ops; } /* Check for Ethernet core IRQ (optional) */ - if (lp->eth_irq <= 0) + if (lp->eth_irq < 0) dev_info(&pdev->dev, "Ethernet core IRQ not defined\n"); /* Retrieve the MAC address */ From bb2b71024976a39ed57d66bad8f9ca7e93bc3f33 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Wed, 9 Sep 2026 11:54:50 +0700 Subject: [PATCH 0426/2126] net: xilinx: axienet: Fix IRQ error handling irq_of_parse_and_map() returns 0 when parsing or mapping an IRQ fails, while platform_get_irq() returns a negative error code on failure. Handle both failure cases appropriately: return -EINVAL when irq_of_parse_and_map() fails, and propagate the original error code returned by platform_get_irq() instead of returning -ENOMEM. Reviewed-by: Simon Horman Signed-off-by: bui duc phuc Reviewed-by: Suraj Gupta Link: https://patch.msgid.link/20260909045450.16176-4-phucduc.bui@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 3927ababf833..782f903d318f 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -2971,10 +2971,14 @@ static int axienet_probe(struct platform_device *pdev) dev_err(&pdev->dev, "could not map DMA regs\n"); return PTR_ERR(lp->dma_regs); } - if (lp->rx_irq <= 0 || lp->tx_irq <= 0) { + if (!lp->rx_irq || !lp->tx_irq) { dev_err(&pdev->dev, "could not determine irqs\n"); - return -ENOMEM; + return -EINVAL; } + if (lp->rx_irq < 0) + return lp->rx_irq; + if (lp->tx_irq < 0) + return lp->tx_irq; if (lp->eth_irq < 0 && lp->eth_irq != -ENXIO) return lp->eth_irq; From 219c6b768ec7bd69682923e9bb59f1558f1f5b64 Mon Sep 17 00:00:00 2001 From: Junjie Cao Date: Thu, 10 Sep 2026 17:49:37 +0800 Subject: [PATCH 0427/2126] net: dropreason: add SKB_DROP_REASON_IP_TTL_EXCEEDED The forwarding paths report an expired TTL or hop limit as SKB_DROP_REASON_IP_INHDR, the reason otherwise used for a header that is malformed (ip_input.c, exthdrs.c, br_netfilter). Nothing else in the drop path separates the two: IPSTATS_MIB_INHDRERRORS covers both, and the TTL check runs before NF_INET_FORWARD, so netfilter tracing stops at PREROUTING and never sees the drop. The Fedora bug linked below shows how that reads in practice. The reporter took kfree_skb(reason=IP_INHDR, loc=ip_forward) to mean the software header checksum check had failed, and worked through RX checksum offload, tc csum actions and both libvirt firewall backends before the drops turned out to be replies arriving with TTL 1. ip_forward() never verifies the header checksum; that runs earlier, in ip_rcv_core(), and reports IP_CSUM. TTL expiry is not a corner case -- every traceroute through a Linux router goes through too_many_hops. The three loopback hop limit checks in exthdrs.c drop with no reason at all; give them the new one. IPSTATS_MIB_INHDRERRORS stays as it is: RFC 1213 counts time-to-live exceeded under ipInHdrErrors. The drop reason has no such constraint. Link: https://bugzilla.redhat.com/show_bug.cgi?id=2517131 Signed-off-by: Junjie Cao Reviewed-by: Jiayuan Chen Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910094937.536150-1-junjie.cao@intel.com Signed-off-by: Jakub Kicinski --- include/net/dropreason-core.h | 6 ++++++ net/ipv4/ip_forward.c | 2 +- net/ipv6/exthdrs.c | 6 +++--- net/ipv6/ip6_output.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 2f312d1f67d6..12f909651591 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -93,6 +93,7 @@ FN(IP_INVALID_SOURCE) \ FN(IP_LOCALNET) \ FN(IP_INVALID_DEST) \ + FN(IP_TTL_EXCEEDED) \ FN(PKT_TOO_BIG) \ FN(DUP_FRAG) \ FN(FRAG_REASM_TIMEOUT) \ @@ -474,6 +475,11 @@ enum skb_drop_reason { * 1) dest ip is 0 */ SKB_DROP_REASON_IP_INVALID_DEST, + /** + * @SKB_DROP_REASON_IP_TTL_EXCEEDED: IPv4 TTL or IPv6 hop limit <= 1 + * (see IPSTATS_MIB_INHDRERRORS) + */ + SKB_DROP_REASON_IP_TTL_EXCEEDED, /** * @SKB_DROP_REASON_PKT_TOO_BIG: packet size is too big (maybe exceed the * MTU) diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c index 8b65f12583eb..b242561d37e7 100644 --- a/net/ipv4/ip_forward.c +++ b/net/ipv4/ip_forward.c @@ -174,7 +174,7 @@ too_many_hops: /* Tell the sender its packet died... */ __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0); - SKB_DR_SET(reason, IP_INHDR); + SKB_DR_SET(reason, IP_TTL_EXCEEDED); drop: kfree_skb_reason(skb, reason); return NET_RX_DROP; diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 09a4552f7f08..55391e2e5612 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -464,7 +464,7 @@ looped_back: __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_TTL_EXCEEDED); return -1; } ipv6_hdr(skb)->hop_limit--; @@ -623,7 +623,7 @@ looped_back: __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_TTL_EXCEEDED); return -1; } ipv6_hdr(skb)->hop_limit--; @@ -815,7 +815,7 @@ looped_back: __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_TTL_EXCEEDED); return -1; } ipv6_hdr(skb)->hop_limit--; diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 8aedea87e237..10146a57b69e 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -577,7 +577,7 @@ int ip6_forward(struct sk_buff *skb) icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); - kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_TTL_EXCEEDED); return -ETIMEDOUT; } From 68fd293d99e469159bb131e1a965f076adbc160d Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:45 -0700 Subject: [PATCH 0428/2126] netlink: specs: conntrack: timestamp is a nest, not a be64 ctnetlink_dump_timestamp() wraps CTA_TIMESTAMP_START and CTA_TIMESTAMP_STOP in a nest, but the spec declares CTA_TIMESTAMP as a flat be64. ynl picks reply attributes out of the attribute set rather than the operation's attribute list, so the mistyped attribute stops the whole dump: Error decoding 'timestamp' from 'conntrack-attrs' Traceback (most recent call last): File "tools/net/ynl/pyynl/cli.py", line 314, in main reply = ynl.dump(args.dump, attrs) File "tools/net/ynl/pyynl/lib/ynl.py", line 1082, in _decode decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order) File "tools/net/ynl/pyynl/lib/ynl.py", line 291, in as_scalar return format_.unpack(self.raw)[0] struct.error: unpack requires a buffer of 8 bytes The tstamp extension is only attached when CONFIG_NF_CONNTRACK_TIMESTAMP is enabled and nf_conntrack_timestamp is turned on, which is off by default and is why every dump does not hit this. stop is omitted for live entries, so it stays optional like every other member here. The pad member mirrors counter-attrs, which covers the same nla_put_be64() padding. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260826220444.4054714-1-i.maximets@ovn.org Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index b1eb102ab843..2b7f16cc4133 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -345,6 +345,20 @@ attribute-sets: - name: secctx-name type: string + - + name: timestamp-attrs + attributes: + - + name: start + type: u64 + byte-order: big-endian + - + name: stop + type: u64 + byte-order: big-endian + - + name: pad + type: pad - name: synproxy-attrs attributes: @@ -458,8 +472,8 @@ attribute-sets: nested-attributes: secctx-attrs - name: timestamp - type: u64 - byte-order: big-endian + type: nest + nested-attributes: timestamp-attrs - name: mark-mask type: u32 From 19be13c9c1e940c041c52ddeeb93d3f9150865f6 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:46 -0700 Subject: [PATCH 0429/2126] netlink: specs: conntrack: fix the get reply attribute lists CTA_NAT_SRC and CTA_NAT_DST are input-only. The only references to either are cda[] reads in ctnetlink_setup_nat() and the rejection in ctnetlink_change_conntrack(); no path ever puts them into a message, so neither belongs in a reply. nat-dst was listed twice on top of that. CTA_TIMESTAMP is the opposite case - both the do and the dump reach ctnetlink_fill_info() with extinfo set, so ctnetlink_dump_extinfo() -> ctnetlink_dump_timestamp() emits it, but the lists never named it. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260826220444.4054714-1-i.maximets@ovn.org Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-3-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index 2b7f16cc4133..174697ce125e 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -596,20 +596,18 @@ operations: - status - protoinfo - help - - nat-src - - nat-dst - timeout - mark - counters-orig - counters-reply - use - id - - nat-dst - tuple-master - seq-adj-orig - seq-adj-reply - zone - secctx + - timestamp - labels - synproxy dump: @@ -632,20 +630,18 @@ operations: - status - protoinfo - help - - nat-src - - nat-dst - timeout - mark - counters-orig - counters-reply - use - id - - nat-dst - tuple-master - seq-adj-orig - seq-adj-reply - zone - secctx + - timestamp - labels - synproxy - From 924c8a610d3acb186248dd7256e8787cf6a0e422 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:47 -0700 Subject: [PATCH 0430/2126] netlink: specs: conntrack: fix SCTP conntrack state names Correct the names of constants: Value 1 is SCTP_CONNTRACK_CLOSED, not "cloned". Value 6 is SCTP_CONNTRACK_SHUTDOWN_RECD, not "shutdown-received". Value 8 is SCTP_CONNTRACK_HEARTBEAT_SENT, there is no "shutdown-heartbeat" state. Note that there's also a value of 9 (HEARTBEAT_ACKED) but sctp_nla_policy caps the attribute at HEARTBEAT_SENT and HEARTBEAT_ACKED is marked no longer used in the header. Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index 174697ce125e..105b53d4b76a 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -72,14 +72,14 @@ definitions: type: enum entries: - none - - cloned + - closed - cookie-wait - cookie-echoed - established - shutdown-sent - - shutdown-received + - shutdown-recd - shutdown-ack-sent - - shutdown-heartbeat-sent + - heartbeat-sent - name: nf-ct-status type: flags From 58c7df883ada6d97107cffc07e3b3bb965a761a8 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:48 -0700 Subject: [PATCH 0431/2126] netlink: specs: conntrack: fix the nat-attrs attribute IDs The enum for attr IDs says: CTA_NAT_V4_MINIP, #define CTA_NAT_MINIP CTA_NAT_V4_MINIP CTA_NAT_V4_MAXIP, #define CTA_NAT_MAXIP CTA_NAT_V4_MAXIP CTA_NAT_PROTO, CTA_NAT_V6_MINIP, CTA_NAT_V6_MAXIP, Move nat-proto to the right place in the YAML spec to make sure the attr IDs match. Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-5-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index 105b53d4b76a..0d1528507c4b 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -314,16 +314,16 @@ attribute-sets: name: nat-v4-maxip type: u32 byte-order: big-endian + - + name: nat-proto + type: nest + nested-attributes: nat-proto-attrs - name: nat-v6-minip type: binary - name: nat-v6-maxip type: binary - - - name: nat-proto - type: nest - nested-attributes: nat-proto-attrs - name: seqadj-attrs attributes: From 6c98fd455ed507f82047816e07d5856db987cacd Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:49 -0700 Subject: [PATCH 0432/2126] netlink: specs: conntrack: describe CTA_HELP_INFO nfnl_cthelper_to_nlattr() seems to output CTA_HELP_INFO but the spec doesn't have a definition for it, add one. Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-6-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index 0d1528507c4b..ec90d3d05841 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -292,6 +292,12 @@ attribute-sets: name: help-name type: string doc: helper name + - + name: help-info + type: binary + doc: >- + Private data of a user space helper, only present for helpers + registered via nfnetlink_cthelper with a non-zero data length. - name: nat-proto-attrs attributes: From f869aa4ceaa2daeb4320a0d83fa212dad3709785 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:50 -0700 Subject: [PATCH 0433/2126] netlink: specs: conntrack: fix the per-CPU stats reply ctnetlink_ct_stat_cpu_fill_info() emits CTA_STATS_INVALID but does not emit CTA_STATS_SEARCHED. Update the attr list, and remove the false annotation of invalid as obsolete. Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-7-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index ec90d3d05841..9ba93370275d 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -530,7 +530,7 @@ attribute-sets: name: invalid type: u32 byte-order: big-endian - doc: obsolete + doc: packets which could not be tracked - name: ignore type: u32 @@ -661,8 +661,8 @@ operations: reply: value: 0x104 attributes: - - searched - found + - invalid - insert - insert-failed - drop From 55edd9e55711e7e47060fb998a96e968a895fc20 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 9 Sep 2026 17:38:51 -0700 Subject: [PATCH 0434/2126] netlink: specs: conntrack: tweak definition of obsolete attrs CTA_SECMARK, CTA_COUNTERS32_{PACKETS,BYTES} are all obsolete be32 attrs. Since they are obsolete we don't bother with the byte-order annotation, but let's be consistent about marking them as u32 with doc: obsolete. The attrs were obsoleted by: commit 584015727a3b ("netfilter: accounting rework: ct_extend + 64bit counters (v4)") commit 1cc63249adfa ("conntrack: export lsm context rather than internal secid via netlink") Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260910003852.2184031-8-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/conntrack.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index 9ba93370275d..1d163130241a 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -116,9 +116,11 @@ attribute-sets: - name: packets-old type: u32 + doc: obsolete - name: bytes-old type: u32 + doc: obsolete - name: pad type: pad @@ -465,7 +467,7 @@ attribute-sets: nested-attributes: seqadj-attrs - name: secmark - type: binary + type: u32 doc: obsolete - name: zone From 57ca800cd3f7d21561d802645dc03df55d2281db Mon Sep 17 00:00:00 2001 From: Ethan Nelson-Moore Date: Thu, 10 Sep 2026 07:35:05 -0700 Subject: [PATCH 0435/2126] drivers: net: smsc: Remove unused smc9194.h header The smc9194 driver was removed in commit 9fdf9f61fa6d ("drivers: net: smsc: smc9194: Remove this driver"), but smc9194.h was left behind. Remove it. Signed-off-by: Ethan Nelson-Moore Reviewed-by: Andrew Lunn Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260910143516.87304-1-enelsonmoore@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/smsc/smc9194.h | 241 ---------------------------- 1 file changed, 241 deletions(-) delete mode 100644 drivers/net/ethernet/smsc/smc9194.h diff --git a/drivers/net/ethernet/smsc/smc9194.h b/drivers/net/ethernet/smsc/smc9194.h deleted file mode 100644 index cf69d0a5a1cb..000000000000 --- a/drivers/net/ethernet/smsc/smc9194.h +++ /dev/null @@ -1,241 +0,0 @@ -/*------------------------------------------------------------------------ - . smc9194.h - . Copyright (C) 1996 by Erik Stahlman - . - . This software may be used and distributed according to the terms - . of the GNU General Public License, incorporated herein by reference. - . - . This file contains register information and access macros for - . the SMC91xxx chipset. - . - . Information contained in this file was obtained from the SMC91C94 - . manual from SMC. To get a copy, if you really want one, you can find - . information under www.smc.com in the components division. - . ( this thanks to advice from Donald Becker ). - . - . Authors - . Erik Stahlman ( erik@vt.edu ) - . - . History - . 01/06/96 Erik Stahlman moved definitions here from main .c file - . 01/19/96 Erik Stahlman polished this up some, and added better - . error handling - . - ---------------------------------------------------------------------------*/ -#ifndef _SMC9194_H_ -#define _SMC9194_H_ - -/* I want some simple types */ - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned long int dword; - - -/* Because of bank switching, the SMC91xxx uses only 16 I/O ports */ - -#define SMC_IO_EXTENT 16 - - -/*--------------------------------------------------------------- - . - . A description of the SMC registers is probably in order here, - . although for details, the SMC datasheet is invaluable. - . - . Basically, the chip has 4 banks of registers ( 0 to 3 ), which - . are accessed by writing a number into the BANK_SELECT register - . ( I also use a SMC_SELECT_BANK macro for this ). - . - . The banks are configured so that for most purposes, bank 2 is all - . that is needed for simple run time tasks. - -----------------------------------------------------------------------*/ - -/* - . Bank Select Register: - . - . yyyy yyyy 0000 00xx - . xx = bank number - . yyyy yyyy = 0x33, for identification purposes. -*/ -#define BANK_SELECT 14 - -/* BANK 0 */ - -#define TCR 0 /* transmit control register */ -#define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */ -#define TCR_FDUPLX 0x0800 /* receive packets sent out */ -#define TCR_STP_SQET 0x1000 /* stop transmitting if Signal quality error */ -#define TCR_MON_CNS 0x0400 /* monitors the carrier status */ -#define TCR_PAD_ENABLE 0x0080 /* pads short packets to 64 bytes */ - -#define TCR_CLEAR 0 /* do NOTHING */ -/* the normal settings for the TCR register : */ -/* QUESTION: do I want to enable padding of short packets ? */ -#define TCR_NORMAL TCR_ENABLE - - -#define EPH_STATUS 2 -#define ES_LINK_OK 0x4000 /* is the link integrity ok ? */ - -#define RCR 4 -#define RCR_SOFTRESET 0x8000 /* resets the chip */ -#define RCR_STRIP_CRC 0x200 /* strips CRC */ -#define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */ -#define RCR_ALMUL 0x4 /* receive all multicast packets */ -#define RCR_PROMISC 0x2 /* enable promiscuous mode */ - -/* the normal settings for the RCR register : */ -#define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE) -#define RCR_CLEAR 0x0 /* set it to a base state */ - -#define COUNTER 6 -#define MIR 8 -#define MCR 10 -/* 12 is reserved */ - -/* BANK 1 */ -#define CONFIG 0 -#define CFG_AUI_SELECT 0x100 -#define BASE 2 -#define ADDR0 4 -#define ADDR1 6 -#define ADDR2 8 -#define GENERAL 10 -#define CONTROL 12 -#define CTL_POWERDOWN 0x2000 -#define CTL_LE_ENABLE 0x80 -#define CTL_CR_ENABLE 0x40 -#define CTL_TE_ENABLE 0x0020 -#define CTL_AUTO_RELEASE 0x0800 -#define CTL_EPROM_ACCESS 0x0003 /* high if Eprom is being read */ - -/* BANK 2 */ -#define MMU_CMD 0 -#define MC_BUSY 1 /* only readable bit in the register */ -#define MC_NOP 0 -#define MC_ALLOC 0x20 /* or with number of 256 byte packets */ -#define MC_RESET 0x40 -#define MC_REMOVE 0x60 /* remove the current rx packet */ -#define MC_RELEASE 0x80 /* remove and release the current rx packet */ -#define MC_FREEPKT 0xA0 /* Release packet in PNR register */ -#define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */ - -#define PNR_ARR 2 -#define FIFO_PORTS 4 - -#define FP_RXEMPTY 0x8000 -#define FP_TXEMPTY 0x80 - -#define POINTER 6 -#define PTR_READ 0x2000 -#define PTR_RCV 0x8000 -#define PTR_AUTOINC 0x4000 -#define PTR_AUTO_INC 0x0040 - -#define DATA_1 8 -#define DATA_2 10 -#define INTERRUPT 12 - -#define INT_MASK 13 -#define IM_RCV_INT 0x1 -#define IM_TX_INT 0x2 -#define IM_TX_EMPTY_INT 0x4 -#define IM_ALLOC_INT 0x8 -#define IM_RX_OVRN_INT 0x10 -#define IM_EPH_INT 0x20 -#define IM_ERCV_INT 0x40 /* not on SMC9192 */ - -/* BANK 3 */ -#define MULTICAST1 0 -#define MULTICAST2 2 -#define MULTICAST3 4 -#define MULTICAST4 6 -#define MGMT 8 -#define REVISION 10 /* ( hi: chip id low: rev # ) */ - - -/* this is NOT on SMC9192 */ -#define ERCV 12 - -#define CHIP_9190 3 -#define CHIP_9194 4 -#define CHIP_9195 5 -#define CHIP_91100 7 - -static const char * chip_ids[ 15 ] = { - NULL, NULL, NULL, - /* 3 */ "SMC91C90/91C92", - /* 4 */ "SMC91C94", - /* 5 */ "SMC91C95", - NULL, - /* 7 */ "SMC91C100", - /* 8 */ "SMC91C100FD", - NULL, NULL, NULL, - NULL, NULL, NULL}; - -/* - . Transmit status bits -*/ -#define TS_SUCCESS 0x0001 -#define TS_LOSTCAR 0x0400 -#define TS_LATCOL 0x0200 -#define TS_16COL 0x0010 - -/* - . Receive status bits -*/ -#define RS_ALGNERR 0x8000 -#define RS_BADCRC 0x2000 -#define RS_ODDFRAME 0x1000 -#define RS_TOOLONG 0x0800 -#define RS_TOOSHORT 0x0400 -#define RS_MULTICAST 0x0001 -#define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT) - -static const char * interfaces[ 2 ] = { "TP", "AUI" }; - -/*------------------------------------------------------------------------- - . I define some macros to make it easier to do somewhat common - . or slightly complicated, repeated tasks. - --------------------------------------------------------------------------*/ - -/* select a register bank, 0 to 3 */ - -#define SMC_SELECT_BANK(x) { outw( x, ioaddr + BANK_SELECT ); } - -/* define a small delay for the reset */ -#define SMC_DELAY() { inw( ioaddr + RCR );\ - inw( ioaddr + RCR );\ - inw( ioaddr + RCR ); } - -/* this enables an interrupt in the interrupt mask register */ -#define SMC_ENABLE_INT(x) {\ - unsigned char mask;\ - SMC_SELECT_BANK(2);\ - mask = inb( ioaddr + INT_MASK );\ - mask |= (x);\ - outb( mask, ioaddr + INT_MASK ); \ -} - -/* this disables an interrupt from the interrupt mask register */ - -#define SMC_DISABLE_INT(x) {\ - unsigned char mask;\ - SMC_SELECT_BANK(2);\ - mask = inb( ioaddr + INT_MASK );\ - mask &= ~(x);\ - outb( mask, ioaddr + INT_MASK ); \ -} - -/*---------------------------------------------------------------------- - . Define the interrupts that I want to receive from the card - . - . I want: - . IM_EPH_INT, for nasty errors - . IM_RCV_INT, for happy received packets - . IM_RX_OVRN_INT, because I have to kick the receiver - --------------------------------------------------------------------------*/ -#define SMC_INTERRUPT_MASK (IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) - -#endif /* _SMC_9194_H_ */ - From c0aca269ec07b0f2c106d5c11ebc7611f6cf90c5 Mon Sep 17 00:00:00 2001 From: Mohsin Bashir Date: Wed, 9 Sep 2026 14:11:11 -0700 Subject: [PATCH 0436/2126] eth: fbnic: Make Rx completion coalescing configurable The Rx completion queue writeback coalescing window controls how long the queue manager may defer writing completions to host memory. Expose this window through the standard rx-cqe-nsecs ethtool parameter. Preserve the existing 2000 ns default and accept values from 1000 ns through the device maximum (~109 us). Hardware expresses COAL_WAIT in 600 MHz core clock cycles, or 1.667 ns per cycle. Programming rounds the configured value to the nearest clock cycle, resulting in an error of less than 1 ns. Retain the requested value for get_coalesce() because this error is below the one-nanosecond resolution of the ethtool interface. Signed-off-by: Mohsin Bashir Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260909211111.1795726-1-mohsin.bashr@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/fbnic/fbnic.h | 2 ++ drivers/net/ethernet/meta/fbnic/fbnic_devlink.c | 2 ++ drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 15 ++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 9 +-------- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 17 +++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 10 ++++++++++ 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h index d0715695c43e..0e7ae1def5bf 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic.h @@ -57,6 +57,7 @@ struct fbnic_dev { u64 dsn; u32 mps; u32 readrq; + u32 rx_cqe_nsecs; u8 relaxed_ord; /* Local copy of the devices TCAM */ @@ -250,6 +251,7 @@ int fbnic_csr_regs_len(struct fbnic_dev *fbd); void fbnic_config_txrx_usecs(struct fbnic_napi_vector *nv, u32 arm); void fbnic_config_rx_frames(struct fbnic_napi_vector *nv); +void fbnic_config_rx_cqe_nsecs(struct fbnic_dev *fbd); enum fbnic_boards { fbnic_board_asic diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c index 546e1c12d287..0b653c4c20a7 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c @@ -10,6 +10,7 @@ #include "fbnic.h" #include "fbnic_fw.h" #include "fbnic_tlv.h" +#include "fbnic_txrx.h" #define FBNIC_SN_STR_LEN 24 @@ -648,6 +649,7 @@ struct fbnic_dev *fbnic_devlink_alloc(struct pci_dev *pdev) fbd->mps = pcie_get_mps(pdev); fbd->readrq = pcie_get_readrq(pdev); fbd->relaxed_ord = pcie_relaxed_ordering_enabled(pdev); + fbd->rx_cqe_nsecs = FBNIC_RX_CQE_NSECS_DEFAULT; fbd->mac_addr_boundary = FBNIC_RPC_TCAM_MACDA_DEFAULT_BOUNDARY; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c index 0e47088ec44b..e84a97ca5452 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -246,6 +246,7 @@ static int fbnic_get_coalesce(struct net_device *netdev, ec->tx_coalesce_usecs = fbn->tx_usecs; ec->rx_coalesce_usecs = fbn->rx_usecs; ec->rx_max_coalesced_frames = fbn->rx_max_frames; + kernel_coal->rx_cqe_nsecs = fbn->fbd->rx_cqe_nsecs; return 0; } @@ -256,6 +257,7 @@ static int fbnic_set_coalesce(struct net_device *netdev, struct netlink_ext_ack *extack) { struct fbnic_net *fbn = netdev_priv(netdev); + struct fbnic_dev *fbd = fbn->fbd; /* Verify against hardware limits */ if (ec->rx_coalesce_usecs > FIELD_MAX(FBNIC_INTR_CQ_REARM_RCQ_TIMEOUT)) { @@ -272,10 +274,20 @@ static int fbnic_set_coalesce(struct net_device *netdev, NL_SET_ERR_MSG_MOD(extack, "rx_frames is above device max"); return -EINVAL; } + if (kernel_coal->rx_cqe_nsecs < FBNIC_RX_CQE_NSECS_MIN || + kernel_coal->rx_cqe_nsecs > FBNIC_RX_CQE_NSECS_MAX) { + NL_SET_ERR_MSG_FMT_MOD(extack, + "rx-cqe-nsecs must be between %u and %u", + FBNIC_RX_CQE_NSECS_MIN, + FBNIC_RX_CQE_NSECS_MAX); + return -EINVAL; + } fbn->tx_usecs = ec->tx_coalesce_usecs; fbn->rx_usecs = ec->rx_coalesce_usecs; fbn->rx_max_frames = ec->rx_max_coalesced_frames; + fbd->rx_cqe_nsecs = kernel_coal->rx_cqe_nsecs; + fbnic_config_rx_cqe_nsecs(fbd); if (netif_running(netdev)) { int i; @@ -2016,7 +2028,8 @@ static void fbnic_get_link_ext_stats(struct net_device *netdev, static const struct ethtool_ops fbnic_ethtool_ops = { .cap_link_lanes_supported = true, .supported_coalesce_params = ETHTOOL_COALESCE_USECS | - ETHTOOL_COALESCE_RX_MAX_FRAMES, + ETHTOOL_COALESCE_RX_MAX_FRAMES | + ETHTOOL_COALESCE_RX_CQE_NSECS, .supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT | ETHTOOL_RING_USE_HDS_THRS, .rxfh_max_num_contexts = FBNIC_RPC_RSS_TBL_COUNT, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c index 53b7a938b4c2..16271c717a5a 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c @@ -125,14 +125,7 @@ static void fbnic_mac_init_qm(struct fbnic_dev *fbd) FIELD_PREP(FBNIC_QM_TCQ_CTL0_COAL_WAIT, clock_freq / 12500)); - /* We will have the interrupt threshold timer tick once every - * 1 usec and coalesce writes for up to 2 usecs. - */ - wr32(fbd, FBNIC_QM_RCQ_CTL0, - FIELD_PREP(FBNIC_QM_RCQ_CTL0_TICK_CYCLES, - clock_freq / 1000000) | - FIELD_PREP(FBNIC_QM_RCQ_CTL0_COAL_WAIT, - clock_freq / 500000)); + fbnic_config_rx_cqe_nsecs(fbd); /* Configure spacer control to 64 beats. */ wr32(fbd, FBNIC_FAB_AXI4_AR_SPACER_2_CFG, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index 401f8b8ae1ca..4cf87b39829d 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -2643,6 +2644,22 @@ static void fbnic_config_rim_threshold(struct fbnic_ring *rcq, u16 nv_idx, u32 r fbnic_ring_wr32(rcq, FBNIC_QUEUE_RIM_THRESHOLD, threshold); } +void fbnic_config_rx_cqe_nsecs(struct fbnic_dev *fbd) +{ + u32 coal_wait; + + coal_wait = DIV_ROUND_CLOSEST_ULL((u64)fbd->rx_cqe_nsecs * + FBNIC_CLOCK_FREQ, NSEC_PER_SEC); + + /* TICK_CYCLES controls the interrupt threshold timer. COAL_WAIT is + * independent and measured in core clock cycles. + */ + wr32(fbd, FBNIC_QM_RCQ_CTL0, + FIELD_PREP(FBNIC_QM_RCQ_CTL0_TICK_CYCLES, + FBNIC_CLOCK_FREQ / USEC_PER_SEC) | + FIELD_PREP(FBNIC_QM_RCQ_CTL0_COAL_WAIT, coal_wait)); +} + void fbnic_config_txrx_usecs(struct fbnic_napi_vector *nv, u32 arm) { struct fbnic_net *fbn = netdev_priv(nv->napi.dev); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h index e03c9d2c38dc..98bb73765587 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -4,12 +4,16 @@ #ifndef _FBNIC_TXRX_H_ #define _FBNIC_TXRX_H_ +#include #include #include +#include #include #include #include +#include "fbnic_csr.h" + struct fbnic_net; /* Guarantee we have space needed for storing the buffer @@ -49,6 +53,12 @@ struct fbnic_net; #define FBNIC_RX_USECS_DEFAULT 30 #define FBNIC_RX_FRAMES_DEFAULT 0 +#define FBNIC_RX_CQE_NSECS_MIN 1000 +#define FBNIC_RX_CQE_NSECS_DEFAULT 2000 +#define FBNIC_RX_CQE_NSECS_MAX \ + ((u32)(((u64)FIELD_MAX(FBNIC_QM_RCQ_CTL0_COAL_WAIT) * NSEC_PER_SEC) / \ + FBNIC_CLOCK_FREQ)) + #define FBNIC_RX_TROOM \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) #define FBNIC_RX_HROOM_PAD 128 From 879e280b8486d4612ad1aa050d6fada2dd80cf1c Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 10 Sep 2026 16:06:58 +0800 Subject: [PATCH 0437/2126] selftests: netdevsim: add TEST_INCLUDES to Makefile Some netdevsim selftests source forwarding/lib.sh and other files, but the Makefile doesn't have TEST_INCLUDES targets, which makes make INSTALL_PATH=/tmp/kself TARGETS=drivers/net/netdevsim \ -C tools/testing/selftests install failed to install related lib files. Add TEST_INCLUDES to the Makefile to install the dependencies. Signed-off-by: Hangbin Liu Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260910-nsim_lib-v1-1-0be0d49eaa42@kylinos.cn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/netdevsim/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/Makefile b/tools/testing/selftests/drivers/net/netdevsim/Makefile index 9808c2fbae9e..bb90fe89d9a1 100644 --- a/tools/testing/selftests/drivers/net/netdevsim/Makefile +++ b/tools/testing/selftests/drivers/net/netdevsim/Makefile @@ -22,4 +22,12 @@ TEST_FILES := \ ethtool-common.sh # end of TEST_FILES +TEST_INCLUDES := \ + $(wildcard ../../../net/lib/sh/*.sh) \ + ../../../net/forwarding/devlink_lib.sh \ + ../../../net/forwarding/fib_offload_lib.sh \ + ../../../net/forwarding/lib.sh \ + ../../../net/lib.sh \ +# end of TEST_INCLUDES + include ../../../lib.mk From 597c0f2f69c070e8b087f503b12b35771d7c0761 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 1 Sep 2026 20:10:06 +0200 Subject: [PATCH 0438/2126] batman-adv: tt: only queue local del event after successful unlink When batadv_tt_local_remove_now() finds another local TT entry with the same MAC + VLAN, it will not try to remove it. A delete event must not be queued because it would otherwise cause the queued ADD event for the other TT entry to be dropped. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=8 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 354d9416c1b7..c904d67791f8 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1496,8 +1496,6 @@ batadv_tt_local_remove_now(struct batadv_priv *bat_priv, struct batadv_tt_common_entry *common = &tt_local_entry->common; struct hlist_node *tt_removed_node; - batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); - /* remove exactly this object when still present in hash */ tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash, batadv_compare_tt_entry, @@ -1505,6 +1503,8 @@ batadv_tt_local_remove_now(struct batadv_priv *bat_priv, if (!tt_removed_node) return; + batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); + /* batadv_tt_local_transition_new() may have committed the entry and * thus counted it in the local table size since the * BATADV_TT_CLIENT_NEW check in batadv_tt_local_mark_removed(). From feb3a036d1cd7b708969dfc58feed16c51a496dc Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Fri, 4 Sep 2026 13:28:17 -0700 Subject: [PATCH 0439/2126] wifi: mac80211: fix monitor filter refcount leak When bringing a monitor interface up and down again, the refcount is leaked for active monitor interfaces, so the hardware filter is never reset. Move the decrement out so it mirrors the increment. Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260904202817.12564-1-lucid_duck@justthetip.ca [rewrite commit message better] Signed-off-by: Johannes Berg --- net/mac80211/iface.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index fdac729ca580..18e62c5ff0fd 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -630,8 +630,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; } - ieee80211_adjust_monitor_flags(sdata, -1); } + + ieee80211_adjust_monitor_flags(sdata, -1); break; case NL80211_IFTYPE_NAN: /* Check if any open NAN_DATA interfaces */ From eb0a9f21deb3632d9285bbc80a3adb6e87c4c0ab Mon Sep 17 00:00:00 2001 From: Maoyi Xie Date: Fri, 4 Sep 2026 22:03:00 +0800 Subject: [PATCH 0440/2126] wifi: mac80211_hwsim: send config events to the radio's net namespace hwsim_mcast_config_msg() falls back to genlmsg_multicast() when it has no genl_info, and that only reaches init_net. A radio in another namespace therefore has its DEL_RADIO announced in init_net, while its own namespace hears nothing. Multicast to wiphy_net() instead, the net that GET and DUMP already filter on. Tested with a config-group listener in each namespace, on a base and a patched kernel. Assisted-by: Claude:claude-opus-5 codeql Signed-off-by: Maoyi Xie Link: https://patch.msgid.link/20260904140300.3402053-1-maoyixie.tju@gmail.com Signed-off-by: Johannes Berg --- .../wireless/virtual/mac80211_hwsim_main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 02b6d81cccd1..d77f54daefc5 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -4396,15 +4396,15 @@ struct hwsim_new_radio_params { bool background_radar; }; -static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb, +static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb, struct net *net, struct genl_info *info) { if (info) genl_notify(&hwsim_genl_family, mcast_skb, info, HWSIM_MCGRP_CONFIG, GFP_KERNEL); else - genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0, - HWSIM_MCGRP_CONFIG, GFP_KERNEL); + genlmsg_multicast_netns(&hwsim_genl_family, net, mcast_skb, 0, + HWSIM_MCGRP_CONFIG, GFP_KERNEL); } static int append_radio_msg(struct sk_buff *skb, int id, @@ -4488,7 +4488,8 @@ static int append_radio_msg(struct sk_buff *skb, int id, return 0; } -static void hwsim_mcast_new_radio(int id, struct genl_info *info, +static void hwsim_mcast_new_radio(int id, struct net *net, + struct genl_info *info, struct hwsim_new_radio_params *param) { struct sk_buff *mcast_skb; @@ -4508,7 +4509,7 @@ static void hwsim_mcast_new_radio(int id, struct genl_info *info, genlmsg_end(mcast_skb, data); - hwsim_mcast_config_msg(mcast_skb, info); + hwsim_mcast_config_msg(mcast_skb, net, info); return; out_err: @@ -6190,7 +6191,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, hwsim_radios_generation++; spin_unlock_bh(&hwsim_radio_lock); - hwsim_mcast_new_radio(idx, info, param); + hwsim_mcast_new_radio(idx, wiphy_net(data->hw->wiphy), info, param); return idx; @@ -6208,7 +6209,7 @@ failed: } static void hwsim_mcast_del_radio(int id, const char *hwname, - struct genl_info *info) + struct net *net, struct genl_info *info) { struct sk_buff *skb; void *data; @@ -6234,7 +6235,7 @@ static void hwsim_mcast_del_radio(int id, const char *hwname, genlmsg_end(skb, data); - hwsim_mcast_config_msg(skb, info); + hwsim_mcast_config_msg(skb, net, info); return; @@ -6246,7 +6247,7 @@ static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data, const char *hwname, struct genl_info *info) { - hwsim_mcast_del_radio(data->idx, hwname, info); + hwsim_mcast_del_radio(data->idx, hwname, wiphy_net(data->hw->wiphy), info); debugfs_remove_recursive(data->debugfs); ieee80211_unregister_hw(data->hw); device_release_driver(data->dev); From 00f2f21c1474ff5b7fa5085204694231cd388519 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Wed, 9 Sep 2026 17:30:13 +1000 Subject: [PATCH 0441/2126] wifi: radiotap: add S1G TLVs and channel frequency Add the necessary definitions to create radiotap S1G TLVs and channel flags for S1G sniffers. Signed-off-by: Lachlan Hodges Link: https://patch.msgid.link/20260909073014.53344-2-lachlan.hodges@morsemicro.com Signed-off-by: Johannes Berg --- include/net/ieee80211_radiotap.h | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/include/net/ieee80211_radiotap.h b/include/net/ieee80211_radiotap.h index 8bbaf77da7cf..27ee67b38ea8 100644 --- a/include/net/ieee80211_radiotap.h +++ b/include/net/ieee80211_radiotap.h @@ -93,6 +93,7 @@ enum ieee80211_radiotap_presence { IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29, IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, IEEE80211_RADIOTAP_EXT = 31, + IEEE80211_RADIOTAP_S1G = 32, IEEE80211_RADIOTAP_EHT_USIG = 33, IEEE80211_RADIOTAP_EHT = 34, IEEE80211_RADIOTAP_UHR_ELR = 37, @@ -112,6 +113,9 @@ enum ieee80211_radiotap_flags { /* for IEEE80211_RADIOTAP_CHANNEL */ enum ieee80211_radiotap_channel_flags { + IEEE80211_CHAN_700MHZ = 0x0001, + IEEE80211_CHAN_800MHZ = 0x0002, + IEEE80211_CHAN_900MHZ = 0x0004, IEEE80211_CHAN_CCK = 0x0020, IEEE80211_CHAN_OFDM = 0x0040, IEEE80211_CHAN_2GHZ = 0x0080, @@ -792,6 +796,68 @@ enum ieee80211_radiotap_uhr_user_info { IEEE80211_RADIOTAP_UHR_USER_INFO_2X_LDPC = 0x02000000, }; +/* + * ieee80211_radiotap_s1g - content of S1G TLV (type 32) + * see www.radiotap.org/fields/S1G.html for details + */ +struct ieee80211_radiotap_s1g { + __le16 known; + __le16 data1; + __le16 data2; +} __packed; + +enum ieee80211_radiotap_s1g_known { + IEEE80211_RADIOTAP_S1G_KNOWN_PPDU_FORMAT = 0x0001, + IEEE80211_RADIOTAP_S1G_KNOWN_RESPONSE_IND = 0x0002, + IEEE80211_RADIOTAP_S1G_KNOWN_GI = 0x0004, + IEEE80211_RADIOTAP_S1G_KNOWN_NSS = 0x0008, + IEEE80211_RADIOTAP_S1G_KNOWN_BW = 0x0010, + IEEE80211_RADIOTAP_S1G_KNOWN_MCS = 0x0020, + IEEE80211_RADIOTAP_S1G_KNOWN_COLOR = 0x0040, + IEEE80211_RADIOTAP_S1G_KNOWN_UPLINK_IND = 0x0080, +}; + +enum ieee80211_radiotap_s1g_data1 { + IEEE80211_RADIOTAP_S1G_DATA1_PPDU_FORMAT = 0x0003, + IEEE80211_RADIOTAP_S1G_DATA1_RESPONSE_IND = 0x000c, + IEEE80211_RADIOTAP_S1G_DATA1_GI = 0x0020, + IEEE80211_RADIOTAP_S1G_DATA1_NSS = 0x00c0, + IEEE80211_RADIOTAP_S1G_DATA1_BW = 0x0f00, + IEEE80211_RADIOTAP_S1G_DATA1_MCS = 0xf000, +}; + +enum ieee80211_radiotap_s1g_data2 { + IEEE80211_RADIOTAP_S1G_DATA2_COLOR = 0x0007, + IEEE80211_RADIOTAP_S1G_DATA2_UPLINK_IND = 0x0008, + IEEE80211_RADIOTAP_S1G_DATA2_RSSI = 0xff00, +}; + +enum ieee80211_radiotap_s1g_ppdu_format { + IEEE80211_RADIOTAP_S1G_PPDU_FORMAT_1M = 0, + IEEE80211_RADIOTAP_S1G_PPDU_FORMAT_SHORT = 1, + IEEE80211_RADIOTAP_S1G_PPDU_FORMAT_LONG = 2, +}; + +enum ieee80211_radiotap_s1g_response_ind { + IEEE80211_RADIOTAP_S1G_RESPONSE_IND_NONE = 0, + IEEE80211_RADIOTAP_S1G_RESPONSE_IND_NDP = 1, + IEEE80211_RADIOTAP_S1G_RESPONSE_IND_NORMAL = 2, + IEEE80211_RADIOTAP_S1G_RESPONSE_IND_LONG = 3, +}; + +enum ieee80211_radiotap_s1g_gi { + IEEE80211_RADIOTAP_S1G_GI_LONG = 0, + IEEE80211_RADIOTAP_S1G_GI_SHORT = 1, +}; + +enum ieee80211_radiotap_s1g_bw { + IEEE80211_RADIOTAP_S1G_BW_1MHZ = 0, + IEEE80211_RADIOTAP_S1G_BW_2MHZ = 1, + IEEE80211_RADIOTAP_S1G_BW_4MHZ = 2, + IEEE80211_RADIOTAP_S1G_BW_8MHZ = 3, + IEEE80211_RADIOTAP_S1G_BW_16MHZ = 4, +}; + /** * ieee80211_get_radiotap_len - get radiotap header length * @data: pointer to the header From bca17bff4e9d530ecd6f395025231854993d2b9e Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Wed, 9 Sep 2026 17:30:14 +1000 Subject: [PATCH 0442/2126] wifi: mac80211: report 900MHz channel for S1G band radiotap header Currently S1G frames are reported as 2GHz spectrum, use the 900MHz channel flag instead. Signed-off-by: Lachlan Hodges Link: https://patch.msgid.link/20260909073014.53344-3-lachlan.hodges@morsemicro.com Signed-off-by: Johannes Berg --- net/mac80211/rx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 40ed03a775ba..31dc6f83781b 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -452,6 +452,8 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, if (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ) channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ; + else if (status->band == NL80211_BAND_S1GHZ) + channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_900MHZ; else if (status->encoding != RX_ENC_LEGACY) channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; else if (rate && rate->flags & IEEE80211_RATE_ERP_G) From aaf06d7cb648665bdff53a450809234326cbcfe7 Mon Sep 17 00:00:00 2001 From: Deepanshu Kartikey Date: Thu, 10 Sep 2026 09:40:47 +0530 Subject: [PATCH 0443/2126] wifi: mac80211: fix stats/preemption in ieee80211_tx_control_port() ieee80211_tx_control_port() can be called from nl80211_tx_control_port() in normal process context via netlink sendmsg(), where BH/preemption is not disabled. dev_sw_netstats_tx_add() uses this_cpu_ptr() internally, which requires preemption to be disabled, triggering a "BUG: using smp_processor_id() in preemptible code" warning. Fix this by moving the local_bh_disable()/local_bh_enable() section to also cover dev_sw_netstats_tx_add() and ieee80211_tpt_led_trig_tx(). Fixes: d5a014204a3b ("wifi: mac80211: tx: simplify control port frame transmission") Reported-by: syzbot+d979bd35c8a76fd1b6f5@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=d979bd35c8a76fd1b6f5 Signed-off-by: Deepanshu Kartikey Link: https://patch.msgid.link/20260910041047.24437-1-kartikey406@gmail.com Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index d85c84a738f7..dc122d8cf9ad 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -6654,10 +6654,9 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, return -EINVAL; } + local_bh_disable(); dev_sw_netstats_tx_add(dev, 1, skb->len); ieee80211_tpt_led_trig_tx(local, skb->len); - - local_bh_disable(); ieee80211_xmit(sdata, sta, skb); local_bh_enable(); rcu_read_unlock(); From 5c7b043cb1ef4bca9aa2e793dab862c0989d59c3 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 12 Sep 2026 09:28:40 +0200 Subject: [PATCH 0444/2126] wifi: mac80211: Fix the return value in mesh_path_add() kernel-doc mesh_path_add() has returned the new (or the already existing) struct mesh_path, or an ERR_PTR(), since commit ae76eef027f7 ("mac80211: return new mpath from mesh_path_add()"), but its kernel-doc still says "Returns: 0 on success". Describe the pointer. Fixes: ae76eef027f7 ("mac80211: return new mpath from mesh_path_add()") Assisted-by: LLM Signed-off-by: Karl Mehltretter Link: https://patch.msgid.link/20260912072840.50710-1-kmehltretter@gmail.com Signed-off-by: Johannes Berg --- net/mac80211/mesh_pathtbl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c index 03171cf00855..a9c5a3250edb 100644 --- a/net/mac80211/mesh_pathtbl.c +++ b/net/mac80211/mesh_pathtbl.c @@ -673,7 +673,7 @@ void mesh_fast_tx_flush_addr(struct ieee80211_sub_if_data *sdata, * @sdata: local subif * @dst: destination address of the path (ETH_ALEN length) * - * Returns: 0 on success + * Returns: the new or the existing path on success, an ERR_PTR() on failure * * State: the initial state of the new path is set to 0 */ From 8ea81827d3537db7cfcc82c008f052bb1bbe7567 Mon Sep 17 00:00:00 2001 From: Julius Bairaktaris Date: Tue, 8 Sep 2026 16:41:55 +0200 Subject: [PATCH 0445/2126] wifi: mac80211: don't reset the TXQ scheduling round number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A round is ended when ieee80211_next_txq() meets a txq whose remembered round number is the current one, meaning it has gone full circle. When the AC exceeds the airtime limit, ieee80211_txq_schedule_start() sets the round number to 0 to close the round. The next open round is 1. A txq from an earlier round 1 still remembers the "1", so the next round stops on it and serves nothing. Fix: use a separate open/closed flag and let the round number keep counting. Testing: ~4200 skipped selections per 20s without the fix and 20 skipped selections per 20s with the fix on ath11k (with my AQL series applied) at BE 500/1000. Fixes: 8e4bac067105 ("wifi: mac80211: add a per-PHY AQL limit to improve fairness") Assisted-by: Claude:claude-opus-5 Signed-off-by: Julius Bairaktaris Reviewed-by: Toke Høiland-Jørgensen Link: https://patch.msgid.link/20260908144155.756569-1-julius@bairaktaris.de Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 1 + net/mac80211/tx.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 53b0b08d3459..65311340db40 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1468,6 +1468,7 @@ struct ieee80211_local { spinlock_t active_txq_lock[IEEE80211_NUM_ACS]; struct list_head active_txqs[IEEE80211_NUM_ACS]; u16 schedule_round[IEEE80211_NUM_ACS]; + bool schedule_open[IEEE80211_NUM_ACS]; /* serializes ieee80211_handle_wake_tx_queue */ spinlock_t handle_wake_tx_queue_lock; diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index dc122d8cf9ad..06c50183f064 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -4135,7 +4135,7 @@ struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac) spin_lock_bh(&local->active_txq_lock[ac]); - if (!local->schedule_round[ac]) + if (!local->schedule_open[ac]) goto out; begin: @@ -4360,12 +4360,12 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) spin_lock_bh(&local->active_txq_lock[ac]); - if (ieee80211_txq_schedule_airtime_check(local, ac)) { + local->schedule_open[ac] = + ieee80211_txq_schedule_airtime_check(local, ac); + if (local->schedule_open[ac]) { local->schedule_round[ac]++; if (!local->schedule_round[ac]) local->schedule_round[ac]++; - } else { - local->schedule_round[ac] = 0; } spin_unlock_bh(&local->active_txq_lock[ac]); From abc142dab56c649ec11ec3615f2b3b6f50478de5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 11 Sep 2026 15:46:29 +0200 Subject: [PATCH 0446/2126] wifi: mac80211_hwsim: fix potential channel crash If wmediumd is used together with a hwsim radio that has channel contexts enabled, the channel pointer can be NULL. Track the frequency so we don't need it at that point, avoiding the crash but still reporting the right freq. Link: https://patch.msgid.link/20260911154632.44cf5d8492c2.I9448bd3cea76eb90554ae73fc77e0a3092ff1271@changeid Signed-off-by: Johannes Berg --- .../wireless/virtual/mac80211_hwsim_main.c | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index d77f54daefc5..5c9713659ecf 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -1337,7 +1337,7 @@ mac80211_hwsim_get_tx_rate(struct ieee80211_hw *hw, static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, struct sk_buff *tx_skb, - struct ieee80211_channel *chan) + u32 freq) { struct mac80211_hwsim_data *data = hw->priv; struct sk_buff *skb; @@ -1369,7 +1369,7 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, hdr->rt_tsft = __mac80211_hwsim_get_tsf(data); hdr->rt_flags = 0; hdr->rt_rate = bitrate / 5; - hdr->rt_channel = cpu_to_le16(chan->center_freq); + hdr->rt_channel = cpu_to_le16(freq); flags = IEEE80211_CHAN_2GHZ; if (txrate && txrate->flags & IEEE80211_RATE_ERP_G) flags |= IEEE80211_CHAN_OFDM; @@ -1387,8 +1387,7 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, } -static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan, - const u8 *addr) +static void mac80211_hwsim_monitor_ack(u32 freq, const u8 *addr) { struct sk_buff *skb; struct hwsim_radiotap_ack_hdr *hdr; @@ -1410,7 +1409,7 @@ static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan, (1 << IEEE80211_RADIOTAP_CHANNEL)); hdr->rt_flags = 0; hdr->pad = 0; - hdr->rt_channel = cpu_to_le16(chan->center_freq); + hdr->rt_channel = cpu_to_le16(freq); flags = IEEE80211_CHAN_2GHZ; hdr->rt_chbitmask = cpu_to_le16(flags); @@ -1735,6 +1734,9 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD)) goto nla_put_failure; + /* track the frequency */ + info->rate_driver_data[1] = (void *)(uintptr_t)channel->center_freq; + genlmsg_end(skb, msg_head); if (hwsim_virtio_enabled) { @@ -1912,7 +1914,7 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, mac80211_hwsim_write_tsf(data, skb, sim_tsf); - mac80211_hwsim_monitor_rx(hw, skb, chan); + mac80211_hwsim_monitor_rx(hw, skb, chan->center_freq); memset(&rx_status, 0, sizeof(rx_status)); rx_status.flag |= RX_FLAG_MACTIME_START; @@ -2276,7 +2278,7 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw, ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel); if (ack && skb->len >= 16) - mac80211_hwsim_monitor_ack(channel, hdr->addr2); + mac80211_hwsim_monitor_ack(channel->center_freq, hdr->addr2); ieee80211_tx_info_clear_status(txi); @@ -6392,6 +6394,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, int i; unsigned long flags; bool found = false; + u32 freq; if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || !info->attrs[HWSIM_ATTR_FLAGS] || @@ -6437,7 +6440,9 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, if (!found) goto out; - mac80211_hwsim_monitor_rx(data2->hw, skb, data2->channel); + txi = IEEE80211_SKB_CB(skb); + freq = (uintptr_t)txi->rate_driver_data[1]; + mac80211_hwsim_monitor_rx(data2->hw, skb, freq); /* Tx info received because the frame was broadcasted on user space, so we get all the necessary info: tx attempts and skb control buff */ @@ -6446,8 +6451,6 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, info->attrs[HWSIM_ATTR_TX_INFO]); /* now send back TX status */ - txi = IEEE80211_SKB_CB(skb); - ieee80211_tx_info_clear_status(txi); for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { @@ -6467,8 +6470,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) && (hwsim_flags & HWSIM_TX_STAT_ACK)) { if (skb->len >= 16) - mac80211_hwsim_monitor_ack(data2->channel, - hdr->addr2); + mac80211_hwsim_monitor_ack(freq, hdr->addr2); txi->flags |= IEEE80211_TX_STAT_ACK; } From 41416127e37e48ad27e671829fe97316e8cd630a Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 11 Sep 2026 15:46:30 +0200 Subject: [PATCH 0447/2126] wifi: mac80211_hwsim: overwrite report SKB In a new test framework for hwsim I'm working on, tests can modify the frame as it passes through the wmediumd APIs. If then the original frame is reported on the monitor interface, things get a bit confusing. Overwrite the frame that will be reported to the monitor with the frame reported for RX if both transmitter and cookie attributes are present (wmediumd doesn't set them). Also add a HWSIM_ATTR_NO_MONITOR flag to allow a frame to be dropped entirely from monitor report, e.g. in case it was never delivered to any peer. Link: https://patch.msgid.link/20260911154632.c06da6d18055.Iaba24acec4c5765fbad77376418b17d1b863791b@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim.h | 5 +- .../wireless/virtual/mac80211_hwsim_main.c | 52 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim.h b/drivers/net/wireless/virtual/mac80211_hwsim.h index a022cd5c0f1c..1d2fd06c585a 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim.h +++ b/drivers/net/wireless/virtual/mac80211_hwsim.h @@ -3,7 +3,7 @@ * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211 * Copyright (c) 2008, Jouni Malinen * Copyright (c) 2011, Javier Lopez - * Copyright (C) 2020, 2022-2025 Intel Corporation + * Copyright (C) 2020, 2022-2026 Intel Corporation */ #ifndef __MAC80211_HWSIM_H @@ -162,6 +162,8 @@ enum hwsim_commands { * each radio instead of for the wiphy. * @HWSIM_ATTR_SUPPORT_NAN_DEVICE: support NAN Device virtual interface (flag) * @HWSIM_ATTR_SUPPORT_BACKGROUND_RADAR: background radar/CAC support (flag) + * @HWSIM_ATTR_NO_MONITOR: skip monitor report for this TX status, e.g. in case + * the frame was never reported to any receiver (flag) * @__HWSIM_ATTR_MAX: enum limit */ enum hwsim_attrs { @@ -197,6 +199,7 @@ enum hwsim_attrs { HWSIM_ATTR_MULTI_RADIO, HWSIM_ATTR_SUPPORT_NAN_DEVICE, HWSIM_ATTR_SUPPORT_BACKGROUND_RADAR, + HWSIM_ATTR_NO_MONITOR, __HWSIM_ATTR_MAX, }; #define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 5c9713659ecf..9f895ad718e9 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -895,6 +895,7 @@ static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { [HWSIM_ATTR_MULTI_RADIO] = { .type = NLA_FLAG }, [HWSIM_ATTR_SUPPORT_NAN_DEVICE] = { .type = NLA_FLAG }, [HWSIM_ATTR_SUPPORT_BACKGROUND_RADAR] = { .type = NLA_FLAG }, + [HWSIM_ATTR_NO_MONITOR] = { .type = NLA_FLAG }, }; #if IS_REACHABLE(CONFIG_VIRTIO) @@ -6394,6 +6395,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, int i; unsigned long flags; bool found = false; + bool no_monitor; u32 freq; if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || @@ -6406,6 +6408,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); + no_monitor = nla_get_flag(info->attrs[HWSIM_ATTR_NO_MONITOR]); data2 = get_hwsim_data_ref_from_addr(src); if (!data2) @@ -6442,7 +6445,9 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, txi = IEEE80211_SKB_CB(skb); freq = (uintptr_t)txi->rate_driver_data[1]; - mac80211_hwsim_monitor_rx(data2->hw, skb, freq); + + if (!no_monitor) + mac80211_hwsim_monitor_rx(data2->hw, skb, freq); /* Tx info received because the frame was broadcasted on user space, so we get all the necessary info: tx attempts and skb control buff */ @@ -6538,6 +6543,51 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, goto out; } + /* look for the skb matching the cookie passed back from user */ + if (info->attrs[HWSIM_ATTR_COOKIE] && + info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]) { + u64 cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); + struct sk_buff *orig_skb, *found = NULL; + struct mac80211_hwsim_data *txdata; + struct ieee80211_tx_info *txi; + const u8 *transmitter; + unsigned long flags; + + transmitter = nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); + txdata = get_hwsim_data_ref_from_addr(transmitter); + if (!txdata || txdata->netgroup != data2->netgroup) + goto out; + + spin_lock_irqsave(&txdata->pending.lock, flags); + skb_queue_walk(&txdata->pending, orig_skb) { + uintptr_t skb_cookie; + + txi = IEEE80211_SKB_CB(orig_skb); + skb_cookie = (uintptr_t)txi->rate_driver_data[0]; + + if (skb_cookie == cookie) { + found = orig_skb; + break; + } + } + + /* that's weird */ + if (!found) { + spin_unlock_irqrestore(&txdata->pending.lock, flags); + goto out; + } + + if (frame_data_len > found->len && + pskb_expand_head(found, 0, frame_data_len - found->len, + GFP_ATOMIC)) { + spin_unlock_irqrestore(&txdata->pending.lock, flags); + goto out; + } + skb_trim(found, 0); + skb_put_data(found, frame_data, frame_data_len); + spin_unlock_irqrestore(&txdata->pending.lock, flags); + } + /* check if radio is configured properly */ if ((data2->idle && !data2->tmp_chan) || !data2->started) From 17402a869778f6c17b88fd360d7a96378779f97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Sun, 6 Sep 2026 22:47:28 +0200 Subject: [PATCH 0448/2126] wifi: wfx: fix use-after-free of the cooling work on device removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the device reports that it is too hot, wfx_suspend_hot_dev() blocks the Tx queues and arms cooling_timeout_work with a 10s delay. If the device recovers a normal temperature before the delay expires, the work is canceled. Else, the work declares the chip frozen and unblocks the Tx queues. However, this work is never canceled when the device is removed. cooling_timeout_work is queued on the system workqueue, while struct wfx_dev is released by wfx_free_common() (through ieee80211_free_hw()). So, if the device is unbound during this 10s window, the work fires after struct wfx_dev has been freed and dereferences it. Cancel the work during the teardown. It has to be done after wfx_bh_unregister(): the "device too hot" indication is processed by the bh, so canceling the work earlier would allow the bh to rearm it. On the other hand, the work calls wfx_tx_unlock(), which may in turn call wfx_bh_request_tx(). So it has to be canceled before bh_wq is destroyed. Note that the Tx queues are intentionally left blocked: the device is going away, so there is nothing to unblock. The issue was reported by the Sashiko review bot and the fix has been written by Copilot (including the commit log). The use-case is difficult to reproduce, so this code has not been tested. However, I don't believe this patch could cause any regression. Fixes: 1d52d29983e5d ("staging: wfx: add support for 'device too hot' indication") Assisted-by: Sashiko:gemini-3.1-pro-preview Assisted-by: Copilot:claude-opus-5 Signed-off-by: Jérôme Pouiller Tested-by: Alexander Sverdlin Reviewed-by: Alexander Sverdlin Link: https://patch.msgid.link/20260906204831.949692-2-jerome.pouiller@silabs.com Signed-off-by: Johannes Berg --- drivers/net/wireless/silabs/wfx/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/silabs/wfx/main.c b/drivers/net/wireless/silabs/wfx/main.c index 4e99fe7e5bb7..b6fd9d4c1f5f 100644 --- a/drivers/net/wireless/silabs/wfx/main.c +++ b/drivers/net/wireless/silabs/wfx/main.c @@ -487,6 +487,7 @@ irq_unsubscribe: wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv); bh_unregister: wfx_bh_unregister(wdev); + cancel_delayed_work_sync(&wdev->cooling_timeout_work); destroy_workqueue(wdev->bh_wq); return err; } @@ -497,6 +498,7 @@ void wfx_release(struct wfx_dev *wdev) wfx_hif_shutdown(wdev); wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv); wfx_bh_unregister(wdev); + cancel_delayed_work_sync(&wdev->cooling_timeout_work); destroy_workqueue(wdev->bh_wq); } From a137e59948ee2b5e54691738df44c02cfbef3823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Sun, 6 Sep 2026 22:47:29 +0200 Subject: [PATCH 0449/2126] wifi: wfx: fix error code on unsupported firmware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 'secure link' feature is not supported by upstream (the reference code relies on mbedTLS to implement it, which is not an option for the Linux kernel). If the firmware enforce the 'secure link' feature, wfx_probe() exits early. However, err still holds the value returned by the previous call to wait_for_completion_timeout(), which is the number of jiffies left before the timeout, hence strictly positive (the zero case is handled just above). wfx_probe() therefore returns a positive value. The bus probe functions forward it as-is and the driver core negates it (see really_probe()). The device does not get bound, which is the expected outcome, but the reported error code is a meaningless negative jiffies count instead of an errno. Return -EOPNOTSUPP, as already done a few lines above when the firmware API version is not supported. Copilot reviewed the code and wrote some parts of the log. Reported-by: Alexander Sverdlin Closes: https://lore.kernel.org/all/cc4de4e40e3ca50e7288be2b9067802576567c25.camel@siemens.com/ Assisted-by: Copilot:claude-opus-5 Signed-off-by: Jérôme Pouiller Reviewed-by: Alexander Sverdlin Link: https://patch.msgid.link/20260906204831.949692-3-jerome.pouiller@silabs.com Signed-off-by: Johannes Berg --- drivers/net/wireless/silabs/wfx/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/silabs/wfx/main.c b/drivers/net/wireless/silabs/wfx/main.c index b6fd9d4c1f5f..16d5b51f6f03 100644 --- a/drivers/net/wireless/silabs/wfx/main.c +++ b/drivers/net/wireless/silabs/wfx/main.c @@ -411,6 +411,7 @@ int wfx_probe(struct wfx_dev *wdev) if (wdev->hw_caps.link_mode == SEC_LINK_ENFORCED) { dev_err(wdev->dev, "chip require secure_link, but can't negotiate it\n"); + err = -EOPNOTSUPP; goto irq_unsubscribe; } From 27b084bdd009c5c82346d39d7773bab3191dd299 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 4 Sep 2026 14:16:28 -0700 Subject: [PATCH 0450/2126] wifi: rt2x00: Use device-managed register buffers The rt2x00 PCI and USB probe paths allocate EEPROM and RF storage with plain kzalloc() and then free it from bus-specific teardown helpers. The USB path also manages the CSR cache the same way. These buffers are tied to the device lifetime, so the explicit free paths add probe and disconnect cleanup without providing separate ownership. Allocate the buffers with devm_kzalloc() before the mac80211 hardware is allocated, then attach the resulting storage to struct rt2x00_dev after the driver-private state exists. This lets driver detach and probe failure rely on device-managed cleanup and removes the duplicated bus-specific buffer freeing. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev Acked-by: Stanislaw Gruszka Link: https://patch.msgid.link/20260904211628.83180-1-rosenp@gmail.com Signed-off-by: Johannes Berg --- .../net/wireless/ralink/rt2x00/rt2x00pci.c | 104 ++++-------------- .../net/wireless/ralink/rt2x00/rt2x00usb.c | 67 ++++------- 2 files changed, 43 insertions(+), 128 deletions(-) diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00pci.c b/drivers/net/wireless/ralink/rt2x00/rt2x00pci.c index cabeef0dde45..d4635b531481 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00pci.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00pci.c @@ -19,84 +19,50 @@ #include "rt2x00.h" #include "rt2x00pci.h" -/* - * PCI driver handlers. - */ -static void rt2x00pci_free_reg(struct rt2x00_dev *rt2x00dev) -{ - kfree(rt2x00dev->rf); - rt2x00dev->rf = NULL; - - kfree(rt2x00dev->eeprom); - rt2x00dev->eeprom = NULL; - - if (rt2x00dev->csr.base) { - iounmap(rt2x00dev->csr.base); - rt2x00dev->csr.base = NULL; - } -} - -static int rt2x00pci_alloc_reg(struct rt2x00_dev *rt2x00dev) -{ - struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev); - - rt2x00dev->csr.base = pci_ioremap_bar(pci_dev, 0); - if (!rt2x00dev->csr.base) - goto exit; - - rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL); - if (!rt2x00dev->eeprom) - goto exit; - - rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL); - if (!rt2x00dev->rf) - goto exit; - - return 0; - -exit: - rt2x00_probe_err("Failed to allocate registers\n"); - - rt2x00pci_free_reg(rt2x00dev); - - return -ENOMEM; -} - int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops) { - struct ieee80211_hw *hw; struct rt2x00_dev *rt2x00dev; + struct ieee80211_hw *hw; + void __iomem *base; + __le16 *eeprom; int retval; u16 chip; + u32 *rf; - retval = pci_enable_device(pci_dev); + retval = pcim_enable_device(pci_dev); if (retval) { rt2x00_probe_err("Enable device failed\n"); return retval; } - retval = pci_request_regions(pci_dev, pci_name(pci_dev)); - if (retval) { - rt2x00_probe_err("PCI request regions failed\n"); - goto exit_disable_device; + base = pcim_iomap_region(pci_dev, 0, pci_name(pci_dev)); + if (IS_ERR(base)) { + rt2x00_probe_err("PCI iomap region failed\n"); + return PTR_ERR(base); } pci_set_master(pci_dev); - if (pci_set_mwi(pci_dev)) + if (pcim_set_mwi(pci_dev)) rt2x00_probe_err("MWI not available\n"); if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32))) { rt2x00_probe_err("PCI DMA not supported\n"); - retval = -EIO; - goto exit_release_regions; + return -EIO; } + eeprom = devm_kzalloc(&pci_dev->dev, ops->eeprom_size, GFP_KERNEL); + if (!eeprom) + return -ENOMEM; + + rf = devm_kzalloc(&pci_dev->dev, ops->rf_size, GFP_KERNEL); + if (!rf) + return -ENOMEM; + hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw); if (!hw) { rt2x00_probe_err("Failed to allocate hardware\n"); - retval = -ENOMEM; - goto exit_release_regions; + return -ENOMEM; } pci_set_drvdata(pci_dev, hw); @@ -105,18 +71,17 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops) rt2x00dev->dev = &pci_dev->dev; rt2x00dev->ops = ops; rt2x00dev->hw = hw; + rt2x00dev->csr.base = base; rt2x00dev->irq = pci_dev->irq; rt2x00dev->name = ops->name; + rt2x00dev->eeprom = eeprom; + rt2x00dev->rf = rf; if (pci_is_pcie(pci_dev)) rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE); else rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI); - retval = rt2x00pci_alloc_reg(rt2x00dev); - if (retval) - goto exit_free_device; - /* * Because rt3290 chip use different efuse offset to read efuse data. * So before read efuse it need to indicate it is the @@ -127,23 +92,13 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops) retval = rt2x00lib_probe_dev(rt2x00dev); if (retval) - goto exit_free_reg; + goto exit_free_device; return 0; -exit_free_reg: - rt2x00pci_free_reg(rt2x00dev); - exit_free_device: ieee80211_free_hw(hw); -exit_release_regions: - pci_clear_mwi(pci_dev); - pci_release_regions(pci_dev); - -exit_disable_device: - pci_disable_device(pci_dev); - return retval; } EXPORT_SYMBOL_GPL(rt2x00pci_probe); @@ -153,19 +108,8 @@ void rt2x00pci_remove(struct pci_dev *pci_dev) struct ieee80211_hw *hw = pci_get_drvdata(pci_dev); struct rt2x00_dev *rt2x00dev = hw->priv; - /* - * Free all allocated data. - */ rt2x00lib_remove_dev(rt2x00dev); - rt2x00pci_free_reg(rt2x00dev); ieee80211_free_hw(hw); - - /* - * Free the PCI device data. - */ - pci_clear_mwi(pci_dev); - pci_disable_device(pci_dev); - pci_release_regions(pci_dev); } EXPORT_SYMBOL_GPL(rt2x00pci_remove); diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c index 47e427ea8622..c9fbc3710fd8 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c @@ -755,55 +755,31 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev) } EXPORT_SYMBOL_GPL(rt2x00usb_uninitialize); -/* - * USB driver handlers. - */ -static void rt2x00usb_free_reg(struct rt2x00_dev *rt2x00dev) -{ - kfree(rt2x00dev->rf); - rt2x00dev->rf = NULL; - - kfree(rt2x00dev->eeprom); - rt2x00dev->eeprom = NULL; - - kfree(rt2x00dev->csr.cache); - rt2x00dev->csr.cache = NULL; -} - -static int rt2x00usb_alloc_reg(struct rt2x00_dev *rt2x00dev) -{ - rt2x00dev->csr.cache = kzalloc(CSR_CACHE_SIZE, GFP_KERNEL); - if (!rt2x00dev->csr.cache) - goto exit; - - rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL); - if (!rt2x00dev->eeprom) - goto exit; - - rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL); - if (!rt2x00dev->rf) - goto exit; - - return 0; - -exit: - rt2x00_probe_err("Failed to allocate registers\n"); - - rt2x00usb_free_reg(rt2x00dev); - - return -ENOMEM; -} - int rt2x00usb_probe(struct usb_interface *usb_intf, const struct rt2x00_ops *ops) { struct usb_device *usb_dev = interface_to_usbdev(usb_intf); - struct ieee80211_hw *hw; struct rt2x00_dev *rt2x00dev; + struct ieee80211_hw *hw; + __le16 *eeprom; + void *cache; int retval; + u32 *rf; usb_reset_device(usb_dev); + cache = devm_kzalloc(&usb_intf->dev, CSR_CACHE_SIZE, GFP_KERNEL); + if (!cache) + return -ENOMEM; + + eeprom = devm_kzalloc(&usb_intf->dev, ops->eeprom_size, GFP_KERNEL); + if (!eeprom) + return -ENOMEM; + + rf = devm_kzalloc(&usb_intf->dev, ops->rf_size, GFP_KERNEL); + if (!rf) + return -ENOMEM; + hw = ieee80211_alloc_hw(struct_size(rt2x00dev, anchor, 1), ops->hw); if (!hw) { rt2x00_probe_err("Failed to allocate hardware\n"); @@ -816,16 +792,15 @@ int rt2x00usb_probe(struct usb_interface *usb_intf, rt2x00dev->dev = &usb_intf->dev; rt2x00dev->ops = ops; rt2x00dev->hw = hw; + rt2x00dev->csr.cache = cache; + rt2x00dev->eeprom = eeprom; + rt2x00dev->rf = rf; rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_USB); INIT_WORK(&rt2x00dev->rxdone_work, rt2x00usb_work_rxdone); INIT_WORK(&rt2x00dev->txdone_work, rt2x00usb_work_txdone); - retval = rt2x00usb_alloc_reg(rt2x00dev); - if (retval) - goto exit_free_device; - init_usb_anchor(rt2x00dev->anchor); retval = rt2x00lib_probe_dev(rt2x00dev); @@ -836,9 +811,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf, exit_free_anchor: usb_kill_anchored_urbs(rt2x00dev->anchor); - rt2x00usb_free_reg(rt2x00dev); - -exit_free_device: ieee80211_free_hw(hw); usb_set_intfdata(usb_intf, NULL); @@ -855,7 +827,6 @@ void rt2x00usb_disconnect(struct usb_interface *usb_intf) * Free all allocated data. */ rt2x00lib_remove_dev(rt2x00dev); - rt2x00usb_free_reg(rt2x00dev); ieee80211_free_hw(hw); usb_set_intfdata(usb_intf, NULL); From 7b37f110903917cac0bde807ade5440c469dfe8b Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 16:39:26 -0700 Subject: [PATCH 0451/2126] selftests: net: add ruff linter exclusions Fedora is now shipping ruff 0.16 which added a ton of more opinionated rules. Let's add some exclusions for checks which are both noisy and IMO of questionable value. We can still follow them for new code but it's a matter of preference. C401: set(x for x in Y) -> {x for x in Y} I find the set() a little more readable. I001: hard requirements to sort includes A little too much RUF015: list(set_a - set_b)[0] -> next(iter(set_a - set_b)) list + index are more readable to a "C person" for sure. Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260912233926.304768-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/ruff.toml | 4 ++++ tools/testing/selftests/net/ruff.toml | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/ruff.toml create mode 100644 tools/testing/selftests/net/ruff.toml diff --git a/tools/testing/selftests/drivers/net/ruff.toml b/tools/testing/selftests/drivers/net/ruff.toml new file mode 100644 index 000000000000..f58d51f35317 --- /dev/null +++ b/tools/testing/selftests/drivers/net/ruff.toml @@ -0,0 +1,4 @@ +# NOTE: keep in sync between .../net/ and .../drivers/net/ + +[lint] +ignore = ["C401", "I001", "RUF015"] diff --git a/tools/testing/selftests/net/ruff.toml b/tools/testing/selftests/net/ruff.toml new file mode 100644 index 000000000000..f58d51f35317 --- /dev/null +++ b/tools/testing/selftests/net/ruff.toml @@ -0,0 +1,4 @@ +# NOTE: keep in sync between .../net/ and .../drivers/net/ + +[lint] +ignore = ["C401", "I001", "RUF015"] From c0bb05f2d19e83b1a14e61ea704fed598b5c614f Mon Sep 17 00:00:00 2001 From: "Maxime Chevallier (Netdev Foundation)" Date: Fri, 11 Sep 2026 18:41:33 +0200 Subject: [PATCH 0452/2126] tools: ynl: Fix out-of-tree build for ynltool After the blamed commit, running a out-of-tree build for ynltool fails : # make -C tools/net/ynl/ynltool O=/tmp/o1 make: Entering directory 'tools/net/ynl/ynltool' make: *** No rule to make target '/tmp/o1/json_writer.o', needed by '/tmp/o1/ynltool'. Stop. ynltool's Makefile correctly accounts for $(OUTPUT) to get the list of object files to generate : OBJS := $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) but it never actually set $(OUTPUT) before the blamed commit, meaning that out-of-tree buils of ynltool were always actually in-tree. Now, the O= parameter is correctly accounted for, and the %o: %c rule fails. Let's update the %o: %c rule to also use $(OUTPUT), as well as the .d file expansion so that any header change is taken into account. Reported-by: Bobby Eshleman Closes: https://lore.kernel.org/all/aqCyWQxqKDuQnZYR@devvm29614.prn0.facebook.com/ Fixes: 917f713b4ec4 ("tools: ynl: Allow cross-compiling ynl and associated tools") Signed-off-by: Maxime Chevallier (Netdev Foundation) Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260911164135.1428140-1-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- tools/net/ynl/ynltool/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/net/ynl/ynltool/Makefile b/tools/net/ynl/ynltool/Makefile index b8c67cdb4fdf..e79b8af353c3 100644 --- a/tools/net/ynl/ynltool/Makefile +++ b/tools/net/ynl/ynltool/Makefile @@ -23,7 +23,7 @@ OBJS := $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) YNLTOOL := $(OUTPUT)ynltool -include $(wildcard *.d) +include $(wildcard $(OUTPUT)*.d) all: $(YNLTOOL) @@ -31,7 +31,7 @@ $(YNLTOOL): ../libynl.a $(OBJS) $(Q)echo -e "\tLINK $@" $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) ../libynl.a -lm -%.o: %.c ../libynl.a +$(OUTPUT)%.o: %.c ../libynl.a $(Q)echo -e "\tCC $@" $(Q)$(COMPILE.c) -MMD -c -o $@ $< From 043777e948807b5f335f58a0b9f5ed04bba681cf Mon Sep 17 00:00:00 2001 From: Donggeun Yoo Date: Wed, 9 Sep 2026 08:57:40 +0900 Subject: [PATCH 0453/2126] net: phy: dp83867: restore LED configuration after a soft reset The LED configuration lives in LEDCR1 (the per-LED function nibble) and LEDCR2 (per-LED driver enable/value and polarity). The driver programs it through the LED class callbacks -- dp83867_led_brightness_set(), dp83867_led_hw_control_set() and dp83867_led_polarity_set() -- either once from device tree at probe, or at runtime from sysfs and the netdev trigger. dp83867_phy_reset(), the .soft_reset callback, issues a global software reset (CTRL SW_RESET), which the datasheet defines as resetting all registers, including the extended registers, to their defaults. phy_init_hw() runs .soft_reset before .config_init on every attach and resume -- phy_attach_direct(), mdio_bus_phy_resume() and MAC drivers -- so the LED configuration is wiped from the first attach onward and never restored. A device-tree polarity is lost, a manually driven LED goes dark, and an LED offloaded to the netdev trigger whose link stays down after a resume keeps the reset-default function until the next link event. Shadow what the LED callbacks program, as a value and a written-bits mask per register, and replay it from config_init(), which runs right after the soft reset. Only bits the driver actually set are restored. The callbacks run under phydev->lock, but config_init() must not take it: the cable-test abort path in phy_state_machine() already holds phydev->lock when it reaches phy_init_hw(), so config_init() taking it would deadlock. Serialize the shadow and its replay with a dedicated lock instead. Signed-off-by: Donggeun Yoo Link: https://patch.msgid.link/20260908235740.120112-1-donggeunyoo.kernel@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/dp83867.c | 109 +++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 12 deletions(-) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index 61a941aa02d9..a3cd5cb11ea0 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -196,6 +197,16 @@ struct dp83867_private { bool set_clk_output; u32 clk_output_sel; bool sgmii_ref_clk_en; + + /* Shadow of the LED registers, replayed after a soft reset. led_lock + * serializes the shadow and its replay against the LED callbacks, + * because dp83867_config_init() does the replay off phydev->lock. + */ + struct mutex led_lock; + u16 ledcr1; + u16 ledcr1_mask; + u16 ledcr2; + u16 ledcr2_mask; }; static int dp83867_ack_interrupt(struct phy_device *phydev) @@ -722,6 +733,7 @@ static int dp83867_resume(struct phy_device *phydev) static int dp83867_probe(struct phy_device *phydev) { struct dp83867_private *dp83867; + int ret; dp83867 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83867), GFP_KERNEL); @@ -730,9 +742,60 @@ static int dp83867_probe(struct phy_device *phydev) phydev->priv = dp83867; + ret = devm_mutex_init(&phydev->mdio.dev, &dp83867->led_lock); + if (ret) + return ret; + return dp83867_of_init(phydev); } +/* Update an LED register and mirror the change into the shadow, so that + * dp83867_config_init() can replay it after a soft reset. Caller must hold + * dp83867->led_lock. + */ +static int __dp83867_led_modify(struct phy_device *phydev, u32 reg, + u16 mask, u16 val) +{ + struct dp83867_private *dp83867 = phydev->priv; + int ret; + + ret = phy_modify(phydev, reg, mask, val); + if (ret) + return ret; + + if (reg == DP83867_LEDCR1) { + dp83867->ledcr1 = (dp83867->ledcr1 & ~mask) | (val & mask); + dp83867->ledcr1_mask |= mask; + } else if (reg == DP83867_LEDCR2) { + dp83867->ledcr2 = (dp83867->ledcr2 & ~mask) | (val & mask); + dp83867->ledcr2_mask |= mask; + } else { + WARN_ON_ONCE(1); + } + + return 0; +} + +/* Restore the LED registers the driver has programmed, cleared by the soft + * reset in dp83867_phy_reset(). + */ +static int dp83867_led_restore(struct phy_device *phydev) +{ + struct dp83867_private *dp83867 = phydev->priv; + int ret = 0; + + mutex_lock(&dp83867->led_lock); + if (dp83867->ledcr1_mask) + ret = phy_modify(phydev, DP83867_LEDCR1, + dp83867->ledcr1_mask, dp83867->ledcr1); + if (!ret && dp83867->ledcr2_mask) + ret = phy_modify(phydev, DP83867_LEDCR2, + dp83867->ledcr2_mask, dp83867->ledcr2); + mutex_unlock(&dp83867->led_lock); + + return ret; +} + static int dp83867_config_init(struct phy_device *phydev) { struct dp83867_private *dp83867 = phydev->priv; @@ -896,6 +959,10 @@ static int dp83867_config_init(struct phy_device *phydev) mask, val); } + ret = dp83867_led_restore(phydev); + if (ret) + phydev_warn(phydev, "failed to restore LED config: %d\n", ret); + return 0; } @@ -1004,7 +1071,9 @@ static int dp83867_led_brightness_set(struct phy_device *phydev, u8 index, enum led_brightness brightness) { - u32 val; + struct dp83867_private *dp83867 = phydev->priv; + u16 val; + int ret; if (index >= DP83867_LED_COUNT) return -EINVAL; @@ -1015,10 +1084,13 @@ dp83867_led_brightness_set(struct phy_device *phydev, if (brightness) val |= DP83867_LED_DRV_VAL(index); - return phy_modify(phydev, DP83867_LEDCR2, - DP83867_LED_DRV_VAL(index) | - DP83867_LED_DRV_EN(index), - val); + mutex_lock(&dp83867->led_lock); + ret = __dp83867_led_modify(phydev, DP83867_LEDCR2, + DP83867_LED_DRV_VAL(index) | + DP83867_LED_DRV_EN(index), val); + mutex_unlock(&dp83867->led_lock); + + return ret; } static int dp83867_led_mode(u8 index, unsigned long rules) @@ -1069,18 +1141,24 @@ static int dp83867_led_hw_is_supported(struct phy_device *phydev, u8 index, static int dp83867_led_hw_control_set(struct phy_device *phydev, u8 index, unsigned long rules) { + struct dp83867_private *dp83867 = phydev->priv; int mode, ret; mode = dp83867_led_mode(index, rules); if (mode < 0) return mode; - ret = phy_modify(phydev, DP83867_LEDCR1, DP83867_LED_FN_MASK(index), - DP83867_LED_FN(index, mode)); - if (ret) - return ret; + mutex_lock(&dp83867->led_lock); + ret = __dp83867_led_modify(phydev, DP83867_LEDCR1, + DP83867_LED_FN_MASK(index), + DP83867_LED_FN(index, mode)); + if (!ret) + ret = __dp83867_led_modify(phydev, DP83867_LEDCR2, + DP83867_LED_DRV_EN(index) | + DP83867_LED_DRV_VAL(index), 0); + mutex_unlock(&dp83867->led_lock); - return phy_modify(phydev, DP83867_LEDCR2, DP83867_LED_DRV_EN(index), 0); + return ret; } static int dp83867_led_hw_control_get(struct phy_device *phydev, u8 index, @@ -1141,9 +1219,11 @@ static int dp83867_led_hw_control_get(struct phy_device *phydev, u8 index, static int dp83867_led_polarity_set(struct phy_device *phydev, int index, unsigned long modes) { + struct dp83867_private *dp83867 = phydev->priv; /* Default active high */ u16 polarity = DP83867_LED_POLARITY(index); u32 mode; + int ret; for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) { switch (mode) { @@ -1157,8 +1237,13 @@ static int dp83867_led_polarity_set(struct phy_device *phydev, int index, return -EINVAL; } } - return phy_modify(phydev, DP83867_LEDCR2, - DP83867_LED_POLARITY(index), polarity); + + mutex_lock(&dp83867->led_lock); + ret = __dp83867_led_modify(phydev, DP83867_LEDCR2, + DP83867_LED_POLARITY(index), polarity); + mutex_unlock(&dp83867->led_lock); + + return ret; } static unsigned int dp83867_inband_caps(struct phy_device *phydev, From f2109e90a5aaedb10b4ac7927ec074820a452d57 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:20 -0400 Subject: [PATCH 0454/2126] net: rtnetlink: add pacing_offload attribute to net_device Add a new flag to administratively control pacing offload. The feature is disabled by default. That does not cause regressions, as no driver advertises max_pacing_offload_horizon yet. Also add NLA_REJECT for max_pacing_offload_horizon, in line with other such read-only members of link-attrs. Both fields can be read with ynl --family rt-link --do getlink \ --json '{"ifname": "eth0"}' | grep pacing And pacing offload enabled with ynl --family rt-link --do setlink \ --json '{"ifname": "eth0", "pacing-offload": 1}' Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-2-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-link.yaml | 5 +++++ .../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 2 ++ include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 22 +++++++++++++++++++ 5 files changed, 31 insertions(+) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index 5217d0bb4a3a..7a72cd1b7e1e 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -1091,6 +1091,10 @@ attribute-sets: - name: tailroom type: u16 + - + name: pacing-offload + type: u32 + doc: Enable EDT pacing offload (0 - disabled, 1 - enabled). - name: prop-list-link-attrs subset-of: link-attrs @@ -2559,6 +2563,7 @@ operations: - devlink-port - gso-ipv4-max-size - gro-ipv4-max-size + - pacing-offload dump: request: value: 18 diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rst index 512f6d6fa3d8..8eceaa80b686 100644 --- a/Documentation/networking/net_cachelines/net_device.rst +++ b/Documentation/networking/net_cachelines/net_device.rst @@ -11,6 +11,7 @@ Type Name fastpath_tx_acce unsigned_long:32 priv_flags read_mostly __dev_queue_xmit(tx) unsigned_long:1 lltx read_mostly HARD_TX_LOCK,HARD_TX_TRYLOCK,HARD_TX_UNLOCK(tx) unsigned_long:2 netmem_tx:2; read_mostly +unsigned_long:1 pacing_offload read_mostly sch_fq char name[16] struct netdev_name_node* name_node struct dev_ifalias* ifalias diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 707b2e51c2b9..1f0710eef185 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1840,6 +1840,7 @@ enum netdev_reg_state { * drivers. Mainly used by logical interfaces, such as * bonding and tunnels * @netmem_tx: device netmem TX mode + * @pacing_offload: enable EDT pacing offload. * * @name: This is the first field of the "visible" part of this structure * (i.e. as seen by users in the "Space.c" file). It is the name @@ -2170,6 +2171,7 @@ struct net_device { unsigned long priv_flags:32; unsigned long lltx:1; unsigned long netmem_tx:2; + unsigned long pacing_offload:1; ); const struct net_device_ops *netdev_ops; const struct header_ops *header_ops; diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 43cecca49f01..245b36204525 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -381,6 +381,7 @@ enum { IFLA_NETNS_IMMUTABLE, IFLA_HEADROOM, IFLA_TAILROOM, + IFLA_PACING_OFFLOAD, __IFLA_MAX }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index be9d1625bac3..e3444fd24061 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1396,6 +1396,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, + rtnl_devlink_port_size(dev) + rtnl_dpll_pin_size() + nla_total_size(8) /* IFLA_MAX_PACING_OFFLOAD_HORIZON */ + + nla_total_size(4) /* IFLA_PACING_OFFLOAD */ + nla_total_size(2) /* IFLA_HEADROOM */ + nla_total_size(2) /* IFLA_TAILROOM */ + rtnl_dev_parent_size(dev) @@ -2176,6 +2177,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, READ_ONCE(dev->tso_max_segs)) || nla_put_uint(skb, IFLA_MAX_PACING_OFFLOAD_HORIZON, READ_ONCE(dev->max_pacing_offload_horizon)) || + nla_put_u32(skb, IFLA_PACING_OFFLOAD, + dev->pacing_offload) || #ifdef CONFIG_RPS nla_put_u32(skb, IFLA_NUM_RX_QUEUES, READ_ONCE(dev->num_rx_queues)) || @@ -2349,9 +2352,11 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_ALLMULTI] = { .type = NLA_REJECT }, [IFLA_GSO_IPV4_MAX_SIZE] = NLA_POLICY_MIN(NLA_U32, MAX_TCP_HEADER + 1), [IFLA_GRO_IPV4_MAX_SIZE] = { .type = NLA_U32 }, + [IFLA_MAX_PACING_OFFLOAD_HORIZON] = { .type = NLA_REJECT }, [IFLA_NETNS_IMMUTABLE] = { .type = NLA_REJECT }, [IFLA_HEADROOM] = { .type = NLA_REJECT }, [IFLA_TAILROOM] = { .type = NLA_REJECT }, + [IFLA_PACING_OFFLOAD] = NLA_POLICY_MAX(NLA_U32, 1), }; static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { @@ -2825,6 +2830,14 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[], return -EINVAL; } + if (tb[IFLA_PACING_OFFLOAD]) { + if (nla_get_u32(tb[IFLA_PACING_OFFLOAD]) && + !dev->max_pacing_offload_horizon) { + NL_SET_ERR_MSG(extack, "pacing offload not supported by device"); + return -EOPNOTSUPP; + } + } + if (tb[IFLA_AF_SPEC]) { struct nlattr *af; int rem, err; @@ -3342,6 +3355,15 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev, } } + if (tb[IFLA_PACING_OFFLOAD]) { + bool val = nla_get_u32(tb[IFLA_PACING_OFFLOAD]); + + if (dev->pacing_offload != val) { + dev->pacing_offload = val; + status |= DO_SETLINK_MODIFIED; + } + } + if (tb[IFLA_OPERSTATE]) set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE])); From 8036cbf026b512378a024fadb1c452356f01ed8b Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:21 -0400 Subject: [PATCH 0455/2126] net_sched: sch_fq: check device pacing offload Network devices can modify pacing offload administratively or device renegotiation. In FQ, only offload if the feature is enabled and within the supported device horizon. Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-3-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- net/sched/sch_fq.c | 53 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c index 35f940b2205d..dfc7f98b600f 100644 --- a/net/sched/sch_fq.c +++ b/net/sched/sch_fq.c @@ -301,6 +301,26 @@ static void fq_gc(struct fq_sched_data *q, q->stat_gc_flows += fcnt; } +static u64 fq_offload_horizon(const struct Qdisc *sch, + const struct fq_sched_data *q) +{ + const struct net_device *dev; + u64 offload_horizon; + + offload_horizon = READ_ONCE(q->offload_horizon); + if (!offload_horizon) + return 0; + + dev = qdisc_dev(sch); + if (!dev->pacing_offload) + return 0; + + if (offload_horizon > READ_ONCE(dev->max_pacing_offload_horizon)) + return 0; + + return offload_horizon; +} + /* Fast path can be used if : * 1) Packet tstamp is in the past, or within the pacing offload horizon. * 2) FQ qlen == 0 OR @@ -312,12 +332,12 @@ static void fq_gc(struct fq_sched_data *q, * FQ can not use generic TCQ_F_CAN_BYPASS infrastructure. */ static bool fq_fastpath_check(const struct Qdisc *sch, struct sk_buff *skb, - u64 now) + u64 now, u64 offload_horizon) { const struct fq_sched_data *q = qdisc_priv(sch); const struct sock *sk; - if (fq_skb_cb(skb)->time_to_send > now + q->offload_horizon) + if (fq_skb_cb(skb)->time_to_send > now + offload_horizon) return false; if (sch->q.qlen != 0) { @@ -338,7 +358,7 @@ static bool fq_fastpath_check(const struct Qdisc *sch, struct sk_buff *skb, /* Ordering invariants fall apart if some delayed flows * are ready but we haven't serviced them, yet. */ - if (q->time_next_delayed_flow <= now + q->offload_horizon) + if (q->time_next_delayed_flow <= now + offload_horizon) return false; } @@ -357,6 +377,7 @@ static struct fq_flow *fq_classify(struct Qdisc *sch, struct sk_buff *skb, u64 now) { struct fq_sched_data *q = qdisc_priv(sch); + u64 offload_horizon = fq_offload_horizon(sch, q); struct rb_node **p, *parent; struct sock *sk = skb->sk; struct rb_root *root; @@ -393,12 +414,13 @@ static struct fq_flow *fq_classify(struct Qdisc *sch, struct sk_buff *skb, sk = (struct sock *)((hash << 1) | 1UL); } - if (fq_fastpath_check(sch, skb, now)) { + if (fq_fastpath_check(sch, skb, now, offload_horizon)) { q->internal.stat_fastpath_packets++; if (skb->sk == sk && q->rate_enable && READ_ONCE(sk->sk_pacing_status) != SK_PACING_FQ) smp_store_release(&sk->sk_pacing_status, SK_PACING_FQ); + return &q->internal; } @@ -661,12 +683,13 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch, return NET_XMIT_SUCCESS; } -static void fq_check_throttled(struct fq_sched_data *q, u64 now) +static void fq_check_throttled(struct fq_sched_data *q, u64 now, + u64 offload_horizon) { unsigned long sample; struct rb_node *p; - if (q->time_next_delayed_flow > now + q->offload_horizon) + if (q->time_next_delayed_flow > now + offload_horizon) return; /* Update unthrottle latency EWMA. @@ -677,7 +700,7 @@ static void fq_check_throttled(struct fq_sched_data *q, u64 now) q->unthrottle_latency_ns -= q->unthrottle_latency_ns >> 3; q->unthrottle_latency_ns += sample >> 3; } - now += q->offload_horizon; + now += offload_horizon; q->time_next_delayed_flow = ~0ULL; while ((p = rb_first(&q->delayed)) != NULL) { @@ -705,6 +728,7 @@ static struct fq_flow_head *fq_pband_head_select(struct fq_perband_flows *pband) static struct sk_buff *fq_dequeue(struct Qdisc *sch) { struct fq_sched_data *q = qdisc_priv(sch); + u64 offload_horizon = fq_offload_horizon(sch, q); struct fq_perband_flows *pband; struct fq_flow_head *head; struct sk_buff *skb; @@ -725,7 +749,7 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch) } now = ktime_get_ns(); - fq_check_throttled(q, now); + fq_check_throttled(q, now, offload_horizon); retry = 0; pband = &q->band_flows[q->band_nr]; begin: @@ -761,7 +785,7 @@ begin: u64 time_next_packet = max_t(u64, fq_skb_cb(skb)->time_to_send, f->time_next_packet); - if (now + q->offload_horizon < time_next_packet) { + if (now + offload_horizon < time_next_packet) { head->first = f->next; f->time_next_packet = time_next_packet; fq_flow_set_throttled(q, f); @@ -836,6 +860,7 @@ begin: } f->time_next_packet = now + len; } + out: return skb; } @@ -1179,11 +1204,15 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt, u64 offload_horizon = (u64)NSEC_PER_USEC * nla_get_u32(tb[TCA_FQ_OFFLOAD_HORIZON]); - if (offload_horizon <= qdisc_dev(sch)->max_pacing_offload_horizon) { - WRITE_ONCE(q->offload_horizon, offload_horizon); - } else { + if (offload_horizon && !qdisc_dev(sch)->pacing_offload) { + NL_SET_ERR_MSG_MOD(extack, "device pacing offload is disabled"); + err = -EINVAL; + } else if (offload_horizon > + qdisc_dev(sch)->max_pacing_offload_horizon) { NL_SET_ERR_MSG_MOD(extack, "invalid offload_horizon"); err = -EINVAL; + } else { + WRITE_ONCE(q->offload_horizon, offload_horizon); } } if (!err) { From e628a85c69ab01d81801fd0b0e51a43b3b999320 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:22 -0400 Subject: [PATCH 0456/2126] net_sched: sch_fq: clear past skb->tstamp if offloading pacing When hardware offload is enabled, FQ will forward packets to the netdevice for pacing. The device has to test that skb->tstamp is in the future. Avoid this cost for packets whose txtime has already passed, by clearing skb->tstamp. Also clear slightly into the future, for EDT timestamps that are so close to now that they fall within a reasonable normal Tx latency. This slack is set to 400 nsec. Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-4-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- net/sched/sch_fq.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c index dfc7f98b600f..a282812c192e 100644 --- a/net/sched/sch_fq.c +++ b/net/sched/sch_fq.c @@ -159,6 +159,9 @@ struct fq_sched_data { u64 stat_allocation_errors; }; +/* EDT timestamps to clear beyond now. */ +static const int fq_offload_slack_ns = 400; + /* return the i-th 2-bit value ("crumb") */ static u8 fq_prio2band(const u8 *prio2band, unsigned int prio) { @@ -421,6 +424,10 @@ static struct fq_flow *fq_classify(struct Qdisc *sch, struct sk_buff *skb, smp_store_release(&sk->sk_pacing_status, SK_PACING_FQ); + if (offload_horizon && + fq_skb_cb(skb)->time_to_send <= now + fq_offload_slack_ns) + skb_set_delivery_time(skb, 0, SKB_CLOCK_REALTIME); + return &q->internal; } @@ -731,6 +738,7 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch) u64 offload_horizon = fq_offload_horizon(sch, q); struct fq_perband_flows *pband; struct fq_flow_head *head; + u64 time_next_packet = 0; struct sk_buff *skb; struct fq_flow *f; unsigned long rate; @@ -745,7 +753,7 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch) if (skb) { q->internal.qlen--; fq_dequeue_skb(sch, &q->internal, skb); - goto out; + return skb; } now = ktime_get_ns(); @@ -782,8 +790,8 @@ begin: skb = fq_peek(f); if (skb) { - u64 time_next_packet = max_t(u64, fq_skb_cb(skb)->time_to_send, - f->time_next_packet); + time_next_packet = max_t(u64, fq_skb_cb(skb)->time_to_send, + f->time_next_packet); if (now + offload_horizon < time_next_packet) { head->first = f->next; @@ -862,6 +870,10 @@ begin: } out: + if (offload_horizon && + time_next_packet && time_next_packet <= now + fq_offload_slack_ns) + skb_set_delivery_time(skb, 0, SKB_CLOCK_REALTIME); + return skb; } From 4aa8b5cadeb3955a30d696d20d8067fdec0d4b4c Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:23 -0400 Subject: [PATCH 0457/2126] idpf: support pacing offload If skb->tstamp is in the future, program this future delivery txtime in the transmit descriptor. TCP pacing offload is only offloaded if SK_PACING_FQ is negotiated and the FQ offload_horizon is configured. But device support for pacing offload must be more robust: it can also be reached through SO_TXTIME. Bounds check txtime. Only packets with timestamp between now and the horizon (max_pacing_offload_horizon) are offloaded when pacing offload is enabled on the device via pacing_offload. Negotiate the feature with the device using virtchnl. Support is conditional on - splitq mode, where tx and tx completion queues are separate, so completions can be returned out of order. - flow scheduling mode, where completions can arrive out of order. - PTP to ensure the NIC clock is synced to CLOCK_TAI. These features are negotiated per adapter, but expect all vports to uniformly request splitq (req_[rt]x_splitq) and flow scheduling (flow_sch_en) when available. Packets beyond the horizon are sent immediately with the overflow bit set. On device reset, EDT capabilities are re-negotiated with firmware. If re-negotiation succeeds, dev->max_pacing_offload_horizon is refreshed. If pacing offload is no longer supported, dev->max_pacing_offload_horizon is set to 0. Must not be called from netpoll due to ktime_get. But netpoll does not generate packets with EDT, so no explicit test is needed. Do not fail device initialization on EDT init error. Log an error, but continue without EDT, similar to PTP. Cc: Tony Nguyen Cc: Przemek Kitszel Cc: Joshua A Hay Cc: intel-wired-lan@lists.osuosl.org Cc: Aleksandr Loktionov Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-5-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/idpf/idpf.h | 12 ++++ drivers/net/ethernet/intel/idpf/idpf_lib.c | 19 +++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 69 ++++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 8 ++- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 60 +++++++++++++++- 5 files changed, 165 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf.h b/drivers/net/ethernet/intel/idpf/idpf.h index 470bc23c844c..f214023095ee 100644 --- a/drivers/net/ethernet/intel/idpf/idpf.h +++ b/drivers/net/ethernet/intel/idpf/idpf.h @@ -604,6 +604,16 @@ struct idpf_vport_config { DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS); }; +/** + * struct idpf_edt_caps_ilog2 - Host parsed EDT capabilities. + * @time_horizon_ns: Total time window in nanoseconds. + * @tstamp_granularity_pow2: Log2 of timestamp granularity in nanoseconds. + */ +struct idpf_edt_caps_ilog2 { + u32 time_horizon_ns; + u8 tstamp_granularity_pow2; +}; + #define idpf_for_each_vport(adapter, iter) \ for (struct idpf_vport **__##iter = &(adapter)->vports[0], \ *iter = (adapter)->max_vports ? *__##iter : NULL; \ @@ -657,6 +667,7 @@ struct idpf_vport_config { * @stats_task: Periodic statistics retrieval task * @stats_wq: Workqueue for statistics task * @caps: Negotiated capabilities with device + * @edt_caps: Negotiated EDT capabilities with device * @dev_ops: See idpf_dev_ops * @cdev_info: IDC core device info pointer * @num_vfs: Number of allocated VFs through sysfs. PF does not directly talk @@ -720,6 +731,7 @@ struct idpf_adapter { struct delayed_work stats_task; struct workqueue_struct *stats_wq; struct virtchnl2_get_capabilities caps; + struct idpf_edt_caps_ilog2 edt_caps; struct idpf_dev_ops dev_ops; struct iidc_rdma_core_dev_info *cdev_info; diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c index 827c795afcb6..cd1b173e3b27 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c @@ -817,6 +817,21 @@ static void idpf_attach_and_open(struct idpf_adapter *adapter) } } +static void idpf_vport_set_pacing_offload(struct idpf_vport *vport, + struct net_device *netdev) +{ + struct idpf_adapter *adapter = vport->adapter; + u32 max_horizon = 0; + + if (adapter->edt_caps.time_horizon_ns && + idpf_is_queue_model_split(vport->dflt_qv_rsrc.txq_model) && + !idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, + VIRTCHNL2_CAP_SPLITQ_QSCHED)) + max_horizon = adapter->edt_caps.time_horizon_ns; + + WRITE_ONCE(netdev->max_pacing_offload_horizon, max_horizon); +} + /** * idpf_cfg_netdev - Allocate, configure and register a netdev * @vport: main vport structure @@ -850,6 +865,8 @@ static int idpf_cfg_netdev(struct idpf_vport *vport) np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter); vport->netdev = netdev; + idpf_vport_set_pacing_offload(vport, netdev); + return idpf_init_mac_addr(vport, netdev); } @@ -890,6 +907,8 @@ static int idpf_cfg_netdev(struct idpf_vport *vport) netdev->min_mtu = ETH_MIN_MTU; netdev->max_mtu = vport->max_mtu; + idpf_vport_set_pacing_offload(vport, netdev); + dflt_features = NETIF_F_SG | NETIF_F_HIGHDMA; diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index 4311ffa30bb1..215a62161a04 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -1742,6 +1742,7 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, q->desc_count = rsrc->txq_desc_count; q->tx_max_bufs = idpf_get_max_tx_bufs(adapter); q->tx_min_pkt_len = idpf_get_min_tx_pkt_len(adapter); + q->ts_gran_pow2 = adapter->edt_caps.tstamp_granularity_pow2; q->netdev = vport->netdev; q->txq_grp = tx_qgrp; q->rel_q_id = j; @@ -2408,7 +2409,12 @@ void idpf_tx_splitq_build_flow_desc(union idpf_tx_flex_desc *desc, struct idpf_tx_splitq_params *params, u16 td_cmd, u16 size) { - *(__le32 *)&desc->flow.qw1.cmd_dtype = cpu_to_le32((u8)(params->dtype | td_cmd)); + desc->flow.qw1.cmd_dtype = (u8)(params->dtype | td_cmd); + + desc->flow.qw1.ts[0] = params->offload.desc_ts[0]; + desc->flow.qw1.ts[1] = params->offload.desc_ts[1]; + desc->flow.qw1.ts[2] = params->offload.desc_ts[2]; + desc->flow.qw1.rxr_bufsize = cpu_to_le16((u16)size); desc->flow.qw1.compl_tag = cpu_to_le16(params->compl_tag); } @@ -3011,6 +3017,63 @@ static bool idpf_tx_splitq_need_re(struct idpf_tx_queue *tx_q) return gap >= IDPF_TX_SPLITQ_RE_MIN_GAP; } +static void idpf_tx_splitq_set_txtime(const struct sk_buff *skb, + const struct idpf_tx_queue *tx_q, + struct idpf_tx_splitq_params *tx_params) +{ + const int offload_slack_ns = 400; + u64 ts, now, horizon; + + if (!tx_q->netdev->pacing_offload) + return; + + horizon = READ_ONCE(tx_q->netdev->max_pacing_offload_horizon); + if (!horizon) + return; + + switch (skb->tstamp_type) { + case SKB_CLOCK_REALTIME: + ts = ktime_to_ns(ktime_add(skb->tstamp, + ktime_mono_to_any(0, TK_OFFS_TAI) - + ktime_mono_to_any(0, TK_OFFS_REAL))); + break; + case SKB_CLOCK_MONOTONIC: + ts = ktime_to_ns(ktime_mono_to_any(skb->tstamp, TK_OFFS_TAI)); + break; + case SKB_CLOCK_TAI: + ts = ktime_to_ns(skb->tstamp); + break; + default: + WARN_ON_ONCE(1); + return; + } + + now = ktime_get_clocktai_ns(); + if (ts < now + offload_slack_ns) + return; + + /* beyond offload horizon? set overflow bit only */ + if (ts > now + horizon) { + tx_params->offload.desc_ts[2] = + IDPF_TXD_FLOW_SCH_HORIZON_OVERFLOW_M; + return; + } + + ts >>= tx_q->ts_gran_pow2; + + /* 0 is valid 23b timestamp, but also means field unset. + * Increase by one to avoid this case + */ + if ((ts & 0x7fffff) == 0) { + tx_params->offload.desc_ts[0] = 1; + return; + } + + tx_params->offload.desc_ts[0] = ts & 0xff; + tx_params->offload.desc_ts[1] = (ts >> 8) & 0xff; + tx_params->offload.desc_ts[2] = ((ts >> 16) & 0x7f); +} + /** * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors * @skb: send buffer @@ -3097,6 +3160,10 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_FLOW_SCHE; tx_params.eop_cmd = IDPF_TXD_FLEX_FLOW_CMD_EOP; + + if (skb->tstamp) + idpf_tx_splitq_set_txtime(skb, tx_q, &tx_params); + /* Set the RE bit periodically to "clean" the descriptor ring */ if (idpf_tx_splitq_need_re(tx_q)) { tx_params.eop_cmd |= IDPF_TXD_FLEX_FLOW_CMD_RE; diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h index 93547597efd2..fe0c913f9bb9 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h @@ -161,6 +161,7 @@ union idpf_tx_flex_desc { * @tso_segs: Number of segments to be sent * @tso_hdr_len: Length of headers to be duplicated * @td_cmd: Command field to be inserted into descriptor + * @desc_ts: Flow scheduling offload timestamp */ struct idpf_tx_offload_params { u32 tx_flags; @@ -174,6 +175,7 @@ struct idpf_tx_offload_params { u16 tso_hdr_len; u16 td_cmd; + u8 desc_ts[3]; }; /** @@ -608,6 +610,7 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, * hot path TX pointers stored in vport. Used in both singleq/splitq. * @desc_count: Number of descriptors * @tx_min_pkt_len: Min supported packet length + * @ts_gran_pow2: Txtime timestamp granularity in nanoseconds (log2). * @thresh: XDP queue cleaning threshold * @netdev: &net_device corresponding to this queue * @next_to_use: Next descriptor to use @@ -666,7 +669,10 @@ struct idpf_tx_queue { u16 desc_count; union { - u16 tx_min_pkt_len; + struct { + u16 tx_min_pkt_len; + u8 ts_gran_pow2; + }; u32 thresh; }; diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index 1caf52706973..928de868fa62 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -3,6 +3,7 @@ #include #include +#include #include #include "idpf.h" @@ -553,7 +554,8 @@ static int idpf_send_get_caps_msg(struct idpf_adapter *adapter) VIRTCHNL2_CAP_SPLITQ_QSCHED | VIRTCHNL2_CAP_PROMISC | VIRTCHNL2_CAP_LOOPBACK | - VIRTCHNL2_CAP_PTP); + VIRTCHNL2_CAP_PTP | + VIRTCHNL2_CAP_EDT); err = idpf_send_mb_msg_stack(adapter, &xn_params, &caps); if (err) @@ -573,6 +575,54 @@ free_rx_buf: return err; } +/** + * idpf_send_get_edt_caps_msg - Send virtchnl get EDT caps msg + * @adapter: Driver specific private struct + * + * Return: 0 on success or error code on failure. + */ +static int idpf_send_get_edt_caps_msg(struct idpf_adapter *adapter) +{ + struct libie_ctlq_xn_send_params xn_params = { + .timeout_ms = IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC, + .chnl_opcode = VIRTCHNL2_OP_GET_EDT_CAPS, + }; + struct virtchnl2_edt_caps caps = {}; + u64 gran_ns, horizon_ns; + int err; + + err = idpf_send_mb_msg_stack(adapter, &xn_params, &caps); + if (err) + return err; + + if (xn_params.recv_mem.iov_len < sizeof(caps)) { + err = -EIO; + goto free_rx_buf; + } + + memcpy(&caps, xn_params.recv_mem.iov_base, sizeof(caps)); + horizon_ns = le64_to_cpu(caps.time_horizon_ns); + gran_ns = le64_to_cpu(caps.tstamp_granularity_ns); + if (horizon_ns > U32_MAX) { + dev_warn(&adapter->pdev->dev, "EDT horizon exceeds U32\n"); + err = -EINVAL; + goto free_rx_buf; + } + if (!gran_ns || !is_power_of_2(gran_ns)) { + dev_warn(&adapter->pdev->dev, "Invalid EDT granularity\n"); + err = -EINVAL; + goto free_rx_buf; + } + + adapter->edt_caps.time_horizon_ns = horizon_ns; + adapter->edt_caps.tstamp_granularity_pow2 = ilog2(gran_ns); + +free_rx_buf: + libie_ctlq_release_rx_buf(&xn_params.recv_mem); + + return err; +} + /** * idpf_mmio_region_non_static - Check if region is not static * @mmio_info: PCI resources info @@ -3085,6 +3135,14 @@ restart: } } + memset(&adapter->edt_caps, 0, sizeof(adapter->edt_caps)); + if (idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, VIRTCHNL2_CAP_EDT)) { + err = idpf_send_get_edt_caps_msg(adapter); + if (err) + dev_err(&adapter->pdev->dev, + "EDT init failed, err=%d\n", err); + } + pci_sriov_set_totalvfs(adapter->pdev, idpf_get_max_vfs(adapter)); num_max_vports = idpf_get_max_vports(adapter); adapter->vports = kzalloc_objs(*adapter->vports, num_max_vports); From 2d5c630e6cd52f2ee53167bf2d84220c22b5a480 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:24 -0400 Subject: [PATCH 0458/2126] selftests: drv-net: refactor so_txtime errqueue handling Prepare error queue handling for upcoming SO_EE_ORIGIN_TIMESTAMPING messages in the next patch in this series. Convert do_recv_errqueue_timeout into dispatcher do_recv_errqueue and move SO_EE_ORIGIN_TXTIME specific code into a separate helper. This will make the next patch a lot more readable. No functional changes. Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-6-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/so_txtime.c | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/drivers/net/so_txtime.c b/tools/testing/selftests/drivers/net/so_txtime.c index 55a386f3d1b9..f6f3253ed174 100644 --- a/tools/testing/selftests/drivers/net/so_txtime.c +++ b/tools/testing/selftests/drivers/net/so_txtime.c @@ -158,7 +158,40 @@ static void do_recv_verify_empty(int fdr) error(1, 0, "recv: not empty as expected (%d, %d)", ret, errno); } -static int do_recv_errqueue_timeout(int fdt) +static int do_recv_errqueue_txtime(struct sock_extended_err *err, + const char payload_char) +{ + const char *reason = NULL; + int64_t tstamp = 0; + + switch (err->ee_errno) { + case ECANCELED: + if (err->ee_code != SO_EE_CODE_TXTIME_MISSED) + error(1, 0, "errqueue: unknown ECANCELED %u\n", + err->ee_code); + reason = "missed txtime"; + break; + case EINVAL: + if (err->ee_code != SO_EE_CODE_TXTIME_INVALID_PARAM) + error(1, 0, "errqueue: unknown EINVAL %u\n", + err->ee_code); + reason = "invalid txtime"; + break; + default: + error(1, 0, "errqueue: errno %u code %u\n", + err->ee_errno, err->ee_code); + } + + tstamp = ((int64_t)err->ee_data) << 32 | err->ee_info; + tstamp -= (int64_t)glob_tstart; + tstamp /= 1000 * 1000; + fprintf(stderr, "send: pkt %c at %" PRId64 "ms dropped: %s\n", + payload_char, tstamp, reason); + + return 1; +} + +static int do_recv_errqueue(int fdt) { char control[CMSG_SPACE(sizeof(struct sock_extended_err)) + CMSG_SPACE(sizeof(struct sockaddr_in6))] = {0}; @@ -169,7 +202,6 @@ static int do_recv_errqueue_timeout(int fdt) struct msghdr msg = {0}; struct iovec iov = {0}; struct cmsghdr *cm; - int64_t tstamp = 0; iov.iov_base = data; iov.iov_len = sizeof(data); @@ -181,8 +213,6 @@ static int do_recv_errqueue_timeout(int fdt) msg.msg_controllen = sizeof(control); while (1) { - const char *reason = NULL; - ret = recvmsg(fdt, &msg, MSG_ERRQUEUE); if (ret == -1 && errno == EAGAIN) break; @@ -201,33 +231,9 @@ static int do_recv_errqueue_timeout(int fdt) if (err->ee_origin != SO_EE_ORIGIN_TXTIME) error(1, 0, "errqueue: origin 0x%x\n", err->ee_origin); - switch (err->ee_errno) { - case ECANCELED: - if (err->ee_code != SO_EE_CODE_TXTIME_MISSED) - error(1, 0, "errqueue: unknown ECANCELED %u\n", - err->ee_code); - reason = "missed txtime"; - break; - case EINVAL: - if (err->ee_code != SO_EE_CODE_TXTIME_INVALID_PARAM) - error(1, 0, "errqueue: unknown EINVAL %u\n", - err->ee_code); - reason = "invalid txtime"; - break; - default: - error(1, 0, "errqueue: errno %u code %u\n", - err->ee_errno, err->ee_code); - } - - tstamp = ((int64_t) err->ee_data) << 32 | err->ee_info; - tstamp -= (int64_t) glob_tstart; - tstamp /= 1000 * 1000; - fprintf(stderr, "send: pkt %c at %" PRId64 "ms dropped: %s\n", - data[ret - 1], tstamp, reason); - + num_tstamp += do_recv_errqueue_txtime(err, data[ret - 1]); msg.msg_flags = 0; msg.msg_controllen = sizeof(control); - num_tstamp++; } return num_tstamp; @@ -245,7 +251,7 @@ static void recv_errqueue_msgs(int fdt) error(1, errno, "poll"); if (ret && (pfd.revents & POLLERR)) - num_tstamp += do_recv_errqueue_timeout(fdt); + num_tstamp += do_recv_errqueue(fdt); if (num_tstamp == cfg_num_pkt) break; From 4e50c0265f2f96e60dc967539d3b85b90038da26 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:25 -0400 Subject: [PATCH 0459/2126] selftests: drv-net: in so_txtime tell apart sw from hw pacing Detect software pacing in so_txtime.c using SO_TIMESTAMPING. If '-H' (hw) is passed 1. measure sw tx delay with SOF_TIMESTAMPING_TX_SOFTWARE, and 2. fail if delay exceeds a threshold, indicating pacing This will be used in the next patch in the series. Also extend while condition to account for possible variance. This applies to all tests, not just the new '-H' variants. Also reorder getopt parameters to make them alphabetical. Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-7-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/so_txtime.c | 97 +++++++++++++++---- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/drivers/net/so_txtime.c b/tools/testing/selftests/drivers/net/so_txtime.c index f6f3253ed174..9ebe9f91227c 100644 --- a/tools/testing/selftests/drivers/net/so_txtime.c +++ b/tools/testing/selftests/drivers/net/so_txtime.c @@ -42,8 +42,10 @@ static bool cfg_machine_slow; static uint64_t cfg_start_time_ns; static int cfg_mark; static bool cfg_rx; +static bool cfg_verify_hw_offload; static uint64_t glob_tstart; +static uint64_t glob_tstart_real; static uint64_t tdeliver_max; static int errors; @@ -191,12 +193,32 @@ static int do_recv_errqueue_txtime(struct sock_extended_err *err, return 1; } -static int do_recv_errqueue(int fdt) +static int do_recv_errqueue_timestamping(struct scm_timestamping *tss) +{ + int64_t ts; + + ts = tss->ts[0].tv_sec * 1000ULL * 1000 * 1000; + ts += tss->ts[0].tv_nsec; + ts -= glob_tstart_real; + ts /= 1000; + + if (ts > cfg_variance_us) { + fprintf(stderr, "sw delay %" PRId64 "us exceeds bounds\n", ts); + if (!cfg_machine_slow) + errors++; + } + + return 1; +} + +static int do_recv_errqueue(int fdt, int *num_ts) { char control[CMSG_SPACE(sizeof(struct sock_extended_err)) + + CMSG_SPACE(sizeof(struct scm_timestamping)) + CMSG_SPACE(sizeof(struct sockaddr_in6))] = {0}; char data[sizeof(struct ethhdr) + sizeof(struct ipv6hdr) + sizeof(struct udphdr) + 1]; + struct scm_timestamping *tss; struct sock_extended_err *err; int ret, num_tstamp = 0; struct msghdr msg = {0}; @@ -222,16 +244,29 @@ static int do_recv_errqueue(int fdt) error(1, 0, "errqueue: flags 0x%x\n", msg.msg_flags); cm = CMSG_FIRSTHDR(&msg); + tss = NULL; + + if (cm->cmsg_level == SOL_SOCKET && + cm->cmsg_type == SCM_TIMESTAMPING) { + tss = (void *)CMSG_DATA(cm); + cm = CMSG_NXTHDR(&msg, cm); + if (!cm) + error(1, 0, "timestamp missing ip err\n"); + } + if (cm->cmsg_level != cfg_errq_level || cm->cmsg_type != cfg_errq_type) error(1, 0, "errqueue: type 0x%x.0x%x\n", cm->cmsg_level, cm->cmsg_type); err = (struct sock_extended_err *)CMSG_DATA(cm); - if (err->ee_origin != SO_EE_ORIGIN_TXTIME) + if (err->ee_origin == SO_EE_ORIGIN_TXTIME) + num_tstamp += do_recv_errqueue_txtime(err, data[ret - 1]); + else if (err->ee_origin == SO_EE_ORIGIN_TIMESTAMPING && tss) + *num_ts += do_recv_errqueue_timestamping(tss); + else error(1, 0, "errqueue: origin 0x%x\n", err->ee_origin); - num_tstamp += do_recv_errqueue_txtime(err, data[ret - 1]); msg.msg_flags = 0; msg.msg_controllen = sizeof(control); } @@ -243,7 +278,7 @@ static void recv_errqueue_msgs(int fdt) { struct pollfd pfd = { .fd = fdt, .events = POLLERR }; const int timeout_ms = 10; - int ret, num_tstamp = 0; + int ret, num_tstamp = 0, num_ts = 0; do { ret = poll(&pfd, 1, timeout_ms); @@ -251,12 +286,20 @@ static void recv_errqueue_msgs(int fdt) error(1, errno, "poll"); if (ret && (pfd.revents & POLLERR)) - num_tstamp += do_recv_errqueue(fdt); + num_tstamp += do_recv_errqueue(fdt, &num_ts); - if (num_tstamp == cfg_num_pkt) + if (num_tstamp == cfg_num_pkt || num_ts == cfg_num_pkt) break; - } while (gettime_ns(cfg_clockid) < tdeliver_max); + } while (gettime_ns(cfg_clockid) < + tdeliver_max + (cfg_variance_us * 1000)); + + if (cfg_verify_hw_offload && num_ts != cfg_num_pkt) { + fprintf(stderr, "missing timestamps: expected %d, got %d\n", + cfg_num_pkt, num_ts); + if (!cfg_machine_slow) + errors++; + } } static void start_time_wait(void) @@ -301,6 +344,17 @@ static void setsockopt_txtime(int fd) error(1, 0, "getsockopt txtime: mismatch"); } +static void setsockopt_txtimestamping(int fd) +{ + int val = SOF_TIMESTAMPING_TX_SOFTWARE | + SOF_TIMESTAMPING_SOFTWARE | + SOF_TIMESTAMPING_OPT_TSONLY; + + if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, + &val, sizeof(val))) + error(1, errno, "setsockopt timestamping"); +} + static int setup_tx(struct sockaddr *addr, socklen_t alen) { int fd; @@ -314,6 +368,9 @@ static int setup_tx(struct sockaddr *addr, socklen_t alen) setsockopt_txtime(fd); + if (cfg_verify_hw_offload) + setsockopt_txtimestamping(fd); + if (cfg_mark && setsockopt(fd, SOL_SOCKET, SO_MARK, &cfg_mark, sizeof(cfg_mark))) error(1, errno, "setsockopt mark"); @@ -354,6 +411,8 @@ static void do_test_tx(struct sockaddr *addr, socklen_t alen) start_time_wait(); glob_tstart = gettime_ns(cfg_clockid); + glob_tstart_real = gettime_ns(CLOCK_REALTIME); + tdeliver_max = glob_tstart; for (i = 0; i < cfg_num_pkt; i++) do_send_one(fdt, &cfg_buf[i]); @@ -446,10 +505,11 @@ static void usage(const char *progname) " -6 only IPv6\n" " -c monotonic or tai (default)\n" " -D destination IP address (server)\n" - " -S source IP address (client)\n" - " -r run rx mode\n" - " -t start time (UTC nanoseconds)\n" + " -H verify hardware offload (tx)\n" " -m socket mark\n" + " -r run rx mode\n" + " -S source IP address (client)\n" + " -t start time (UTC nanoseconds)\n" "\n", progname); exit(1); @@ -461,7 +521,7 @@ static void parse_opts(int argc, char **argv) int domain = PF_UNSPEC; int c; - while ((c = getopt(argc, argv, "46c:S:D:rt:m:")) != -1) { + while ((c = getopt(argc, argv, "46c:D:Hm:rS:t:")) != -1) { switch (c) { case '4': if (domain != PF_UNSPEC) @@ -488,21 +548,24 @@ static void parse_opts(int argc, char **argv) else error(1, 0, "unknown clock id %s", optarg); break; - case 'S': - saddr = optarg; - break; case 'D': daddr = optarg; break; + case 'H': + cfg_verify_hw_offload = true; + break; + case 'm': + cfg_mark = strtol(optarg, NULL, 0); + break; case 'r': cfg_rx = true; break; + case 'S': + saddr = optarg; + break; case 't': cfg_start_time_ns = strtoll(optarg, NULL, 0); break; - case 'm': - cfg_mark = strtol(optarg, NULL, 0); - break; default: usage(argv[0]); } From ac48ee533902d405eee5997a1fa1fe10924ed27e Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Thu, 10 Sep 2026 13:10:26 -0400 Subject: [PATCH 0460/2126] selftests: drv-net: extend so_txtime with hw offload Add two pacing hardware offload variants 1. one that uses FQ to safely offload when within bounds. 2. one that uses pfifo_fast and thus forwards all packets. Verify that the packets are paced in hardware with new flag '-H'. Also increase rcvtimeout significantly to reduce flakiness. Especially for the new beyond_hw_horizon test, which is close to the 100ms limit. But update recv_verify_empty to take MSG_DONTWAIT. That last empty check must not delay each testcase by the receive timeout. Hardware pacing offload can complete packets out of order. So the reverse_order test is expected to pass with pfifo_fast too. Do not test ETF, which does not change its dequeue behavior based on pacing_offload. The pfifo_fast beyond_hw_horizon testcase expects a failure because the packet exceeds the hardware horizon and is transmitted immediately, violating receiver arrival bounds. On slow machines (KSFT_MACHINE_SLOW), timing variance errors are suppressed by the receiver, so relax the failure expectation only for this timing-sensitive case while preserving deterministic checks for other tests (such as ETF invalid txtime). Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260910171131.2532487-8-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/so_txtime.c | 4 +- .../selftests/drivers/net/so_txtime.py | 80 ++++++++++++++++++- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/drivers/net/so_txtime.c b/tools/testing/selftests/drivers/net/so_txtime.c index 9ebe9f91227c..5bb15498da30 100644 --- a/tools/testing/selftests/drivers/net/so_txtime.c +++ b/tools/testing/selftests/drivers/net/so_txtime.c @@ -155,7 +155,7 @@ static void do_recv_verify_empty(int fdr) char rbuf[1]; int ret; - ret = recv(fdr, rbuf, sizeof(rbuf), 0); + ret = recv(fdr, rbuf, sizeof(rbuf), MSG_DONTWAIT); if (ret != -1 || errno != EAGAIN) error(1, 0, "recv: not empty as expected (%d, %d)", ret, errno); } @@ -380,7 +380,7 @@ static int setup_tx(struct sockaddr *addr, socklen_t alen) static int setup_rx(struct sockaddr *addr, socklen_t alen) { - struct timeval tv = { .tv_usec = 100 * 1000 }; + struct timeval tv = { .tv_usec = 600 * 1000 }; int fd; fd = socket(addr->sa_family, SOCK_DGRAM, 0); diff --git a/tools/testing/selftests/drivers/net/so_txtime.py b/tools/testing/selftests/drivers/net/so_txtime.py index a097fae0b335..66a87205e02d 100755 --- a/tools/testing/selftests/drivers/net/so_txtime.py +++ b/tools/testing/selftests/drivers/net/so_txtime.py @@ -12,10 +12,12 @@ import time from lib.py import ksft_exit, ksft_run, ksft_variants from lib.py import KsftNamedVariant, KsftSkipEx from lib.py import NetDrvEpEnv, bkg, cmd, defer, tc -from lib.py import CmdExitFailure +from lib.py import CmdExitFailure, RtnlFamily, NlError +_HW_OFFLOAD_HORIZON_MS = 50 -def test_so_txtime(cfg, clockid, ipver, args_tx, args_rx, expect_success): +def test_so_txtime(cfg, clockid, ipver, args_tx, args_rx, expect_success, + timing_sensitive=False): """Main function. Run so_txtime as sender and receiver.""" slow_machine = os.environ.get('KSFT_MACHINE_SLOW') @@ -33,12 +35,42 @@ def test_so_txtime(cfg, clockid, ipver, args_tx, args_rx, expect_success): expect_fail = not expect_success if slow_machine: expect_success = False + if timing_sensitive: + expect_fail = None with bkg(cmd_rx, host=cfg.remote, fail=expect_success, expect_fail=expect_fail, exit_wait=True): cmd(cmd_tx) +def _dev_setup_pacing_offload(cfg): + """Configure pacing-offload.""" + rtnl = RtnlFamily() + + try: + link = rtnl.getlink({'ifi-index': cfg.ifindex}) + except NlError as e: + raise KsftSkipEx('getlink not supported by device') from e + + if 'pacing-offload' not in link or \ + 'max-pacing-offload-horizon' not in link: + raise KsftSkipEx('pacing offload not supported by device') + + horizon = _HW_OFFLOAD_HORIZON_MS * 1000_000 + if link['max-pacing-offload-horizon'] < horizon: + raise KsftSkipEx('pacing offload max horizon too small') + + cur_offload = link['pacing-offload'] + rtnl.setlink({ + 'ifi-index': cfg.ifindex, + 'pacing-offload': 1, + }) + defer(rtnl.setlink, { + 'ifi-index': cfg.ifindex, + 'pacing-offload': cur_offload + }) + + def _qdisc_setup(ifname, qdisc, optargs=""): """Replace root qdisc. Restore the original after the test. @@ -61,6 +93,7 @@ def _test_variants_fq(): ["one_pkt", "a,10", "a,10"], ["in_order", "a,10,b,20", "a,10,b,20"], ["reverse_order", "a,20,b,10", "b,10,a,20"], + ["beyond_hw_horizon", "a,70", "a,70"], ]: name = f"v{ipver}_{testcase[0]}" yield KsftNamedVariant(name, ipver, testcase[1], testcase[2]) @@ -74,6 +107,41 @@ def test_so_txtime_fq_mono(cfg, ipver, args_tx, args_rx): test_so_txtime(cfg, "mono", ipver, args_tx, args_rx, True) +@ksft_variants(_test_variants_fq()) +def test_so_txtime_fq_mono_hw(cfg, ipver, args_tx, args_rx): + """Run all variants of monotonic fq tests, with offload horizon.""" + cfg.require_ipver(ipver) + cfg.require_nsim(nsim_test=False) + + _dev_setup_pacing_offload(cfg) + try: + _qdisc_setup(cfg.ifname, "fq", f"offload_horizon {_HW_OFFLOAD_HORIZON_MS}ms") + except Exception as e: + raise KsftSkipEx("netdev does not support offload. skipping") from e + + # Expect all tests to use only hw pacing, except beyond_hw_horizon. + # Do not pass -H to that test so that with sw pacing fallback it passes. + hw_only = "-H" if args_tx != "a,70" else "" + test_so_txtime(cfg, "mono", ipver, f"{hw_only} {args_tx}", args_rx, True) + + +@ksft_variants(_test_variants_fq()) +def test_so_txtime_pfifofast_mono_hw(cfg, ipver, args_tx, args_rx): + """Run all variants of monotonic tests, without fq pacing sw backup.""" + cfg.require_ipver(ipver) + cfg.require_nsim(nsim_test=False) + + _dev_setup_pacing_offload(cfg) + _qdisc_setup(cfg.ifname, "pfifo_fast") + + # Expect all tests to pass, except beyond_hw_horizon without sw fallback. + # It will send immediately, failing the receiver arrival bounds check. + expect_pass = args_tx != "a,70" + timing_sensitive = not expect_pass + test_so_txtime(cfg, "mono", ipver, f"-H {args_tx}", args_rx, expect_pass, + timing_sensitive=timing_sensitive) + + @ksft_variants(_test_variants_fq()) def test_so_txtime_fq_tai(cfg, ipver, args_tx, args_rx): """Run all variants of fq tests, but pass CLOCK_TAI to test conversion.""" @@ -123,7 +191,13 @@ def main() -> None: """Boilerplate ksft main.""" with NetDrvEpEnv(__file__) as cfg: ksft_run( - [test_so_txtime_fq_mono, test_so_txtime_fq_tai, test_so_txtime_etf], + [ + test_so_txtime_fq_mono, + test_so_txtime_fq_mono_hw, + test_so_txtime_pfifofast_mono_hw, + test_so_txtime_fq_tai, + test_so_txtime_etf, + ], args=(cfg,), ) ksft_exit() From 0019aa65bbc6223b3c29f519c0c8e040b26ef97e Mon Sep 17 00:00:00 2001 From: Linkui Xiao Date: Thu, 10 Sep 2026 17:34:52 +0800 Subject: [PATCH 0461/2126] ipmr, ip6mr: annotate data-races in vif_seq_show() ipmr_vif_seq_show() and ip6mr_vif_seq_show() read vif->bytes_in, vif->pkt_in, vif->bytes_out and vif->pkt_out with only rcu_read_lock() held: since commit b96ef16d2f83 ("ipmr: convert /proc handlers to rcu_read_lock()") both seq_start helpers are annotated __acquires(RCU) and no longer take mrt_lock. Those counters are updated from softirq context and the writers already use WRITE_ONCE(): ipmr_prepare_xmit() and ip_mr_forward() on the IPv4 side, ip6mr_prepare_xmit() and ip6_mr_forward() on the IPv6 side. The other lockless readers use READ_ONCE() as well - ipmr_ioctl(), ipmr_compat_ioctl(), ipmr_fill_vif(), ip6mr_ioctl() and ip6mr_compat_ioctl(). The two vif_seq_show() helpers are the only remaining bare readers, so KCSAN flags them and the compiler is free to tear or reload the values while the /proc/net/ip_mr_vif and /proc/net/ip6_mr_vif lines are being formatted. Annotate them like the other readers; these are plain statistics, no locking is needed. Signed-off-by: Linkui Xiao Link: https://patch.msgid.link/20260910093452.2070079-1-xiaolinkui@126.com Signed-off-by: Jakub Kicinski --- net/ipv4/ipmr.c | 5 +++-- net/ipv6/ip6mr.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index b9c544d48c45..1187bfc8a09d 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -3178,8 +3178,9 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v) seq_printf(seq, "%2td %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", vif - mrt->vif_table, - name, vif->bytes_in, vif->pkt_in, - vif->bytes_out, vif->pkt_out, + name, + READ_ONCE(vif->bytes_in), READ_ONCE(vif->pkt_in), + READ_ONCE(vif->bytes_out), READ_ONCE(vif->pkt_out), vif->flags, vif->local, vif->remote); } return 0; diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 9d8116b5edb1..36f117ad3670 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -485,8 +485,9 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v) seq_printf(seq, "%2td %-10s %8ld %7ld %8ld %7ld %05X\n", vif - mrt->vif_table, - name, vif->bytes_in, vif->pkt_in, - vif->bytes_out, vif->pkt_out, + name, + READ_ONCE(vif->bytes_in), READ_ONCE(vif->pkt_in), + READ_ONCE(vif->bytes_out), READ_ONCE(vif->pkt_out), vif->flags); } return 0; From a952507ca094d4e77bea78b462a0482d3c546c9e Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Wed, 9 Sep 2026 21:06:05 +0200 Subject: [PATCH 0462/2126] net: airoha: add LRO offload support Introduce LRO offload support to the airoha_eth driver, leveraging the EN7581/AN7583 SoC's 8 dedicated LRO hardware queues mapped to RX queues 24-31. LRO offloading does not support Scatter-Gather (SG) so it is required to increase the page_pool allocation order to 2 for RX queues 24-31 (LRO queues). Since LRO is configured per-QDMA and shared across all devices using it, LRO is mutually exclusive with multiple devices bound to the same QDMA block. NETIF_F_LRO availability is re-evaluated whenever the QDMA user count changes (device registration and runtime QDMA migration): airoha_update_netdev_features() drops the feature when the QDMA has more than one user, while airoha_dev_set_qdma() re-enables LRO on the destination QDMA after a migration so that a running device keeps it active on the new QDMA block. Set the GSO metadata (gso_type/gso_size/gso_segs) on aggregated packets, together with CHECKSUM_PARTIAL and the pseudo-header checksum, so that L3-forwarded traffic is correctly re-segmented by the GSO/TSO path on the egress device. The HW does not report the per-segment MSS (msg3[31:16] only reports the max aggregated size), so the gso_size of an aggregated packet is approximated as DIV_ROUND_UP(data_len, agg_count), i.e. the mean segment size. Since this can never exceed the largest merged segment, re-segmentation only produces smaller packets, which is safe. Aggregated skbs are marked SKB_GSO_DODGY so that the stack recomputes gso_segs from gso_size and does not merge the aggregate into the GRO engine. Performance comparison between sw GRO and LRO has been carried out using a 10Gbps NIC: GRO: ~2.7 Gbps LRO: ~8.2 Gbps Tested-by: Madhur Agrawal Signed-off-by: Lorenzo Bianconi Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260909-airoha-eth-lro-v7-1-e6317be79067@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/airoha/airoha_eth.c | 363 ++++++++++++++++++++-- drivers/net/ethernet/airoha/airoha_eth.h | 26 ++ drivers/net/ethernet/airoha/airoha_regs.h | 23 +- 3 files changed, 390 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c index 64619e9a704d..21ac80bdd084 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.c +++ b/drivers/net/ethernet/airoha/airoha_eth.c @@ -10,8 +10,10 @@ #include #include #include +#include #include #include +#include #include #include "airoha_regs.h" @@ -491,6 +493,88 @@ static void airoha_fe_crsn_qsel_init(struct airoha_eth *eth) CDM_CRSN_QSEL_Q1)); } +static void airoha_fe_lro_rxq_enable(struct airoha_eth *eth, int qdma_id, + int lro_queue_index, int qid, + int buf_size) +{ + int id = qdma_id + 1; + + airoha_fe_rmw(eth, REG_CDM_LRO_LIMIT(id), + CDM_LRO_AGG_NUM_MASK | CDM_LRO_AGG_SIZE_MASK, + FIELD_PREP(CDM_LRO_AGG_SIZE_MASK, buf_size) | + FIELD_PREP(CDM_LRO_AGG_NUM_MASK, + AIROHA_RXQ_LRO_MAX_AGG_COUNT)); + airoha_fe_rmw(eth, REG_CDM_LRO_AGE_TIME(id), + CDM_LRO_AGE_TIME_MASK | CDM_LRO_AGG_TIME_MASK, + FIELD_PREP(CDM_LRO_AGE_TIME_MASK, + AIROHA_RXQ_LRO_MAX_AGE_TIME) | + FIELD_PREP(CDM_LRO_AGG_TIME_MASK, + AIROHA_RXQ_LRO_MAX_AGG_TIME)); + airoha_fe_rmw(eth, REG_CDM_LRO_RXQ(id, lro_queue_index), + LRO_RXQ_MASK(lro_queue_index), + __field_prep(LRO_RXQ_MASK(lro_queue_index), qid)); + airoha_fe_set(eth, REG_CDM_LRO_EN(id), BIT(lro_queue_index)); +} + +static void airoha_fe_lro_disable(struct airoha_eth *eth, int qdma_id) +{ + int i, id = qdma_id + 1; + + airoha_fe_clear(eth, REG_CDM_LRO_EN(id), LRO_RXQ_EN_MASK); + airoha_fe_clear(eth, REG_CDM_LRO_LIMIT(id), + CDM_LRO_AGG_NUM_MASK | CDM_LRO_AGG_SIZE_MASK); + airoha_fe_clear(eth, REG_CDM_LRO_AGE_TIME(id), + CDM_LRO_AGE_TIME_MASK | CDM_LRO_AGG_TIME_MASK); + for (i = 0; i < AIROHA_MAX_NUM_LRO_QUEUES; i++) + airoha_fe_clear(eth, REG_CDM_LRO_RXQ(id, i), LRO_RXQ_MASK(i)); +} + +static bool airoha_fe_lro_is_enabled(struct airoha_eth *eth, int qdma_id) +{ + return airoha_fe_get(eth, REG_CDM_LRO_EN(qdma_id + 1), + LRO_RXQ_EN_MASK); +} + +static void airoha_dev_lro_enable(struct airoha_gdm_dev *dev) +{ + struct airoha_qdma *qdma = airoha_qdma_deref(dev); + struct airoha_eth *eth = qdma->eth; + int qdma_id = qdma - ð->qdma[0]; + int i, lro_queue_index = 0; + + if (airoha_fe_lro_is_enabled(eth, qdma_id)) + return; + + for (i = 0; i < ARRAY_SIZE(qdma->q_rx); i++) { + struct airoha_queue *q = &qdma->q_rx[i]; + u32 size; + + if (!q->ndesc) + continue; + + if (!airoha_qdma_is_lro_queue(q)) + continue; + + size = SKB_WITH_OVERHEAD(AIROHA_RX_LEN(q->buf_size)); + size = min_t(u32, size, AIROHA_MAX_RX_SIZE); + airoha_fe_lro_rxq_enable(eth, qdma_id, lro_queue_index, i, + size); + lro_queue_index++; + } +} + +static void airoha_dev_lro_disable(struct airoha_gdm_dev *dev) +{ + struct airoha_qdma *qdma = airoha_qdma_deref(dev); + struct airoha_eth *eth = qdma->eth; + int qdma_id = qdma - ð->qdma[0]; + + if (!airoha_fe_lro_is_enabled(eth, qdma_id)) + return; + + airoha_fe_lro_disable(eth, qdma_id); +} + static int airoha_fe_init(struct airoha_eth *eth) { airoha_fe_maccr_init(eth); @@ -616,6 +700,7 @@ static int airoha_qdma_fill_rx_queue(struct airoha_queue *q) e->dma_addr = page_pool_get_dma_addr(page) + offset; e->dma_len = SKB_WITH_OVERHEAD(AIROHA_RX_LEN(q->buf_size)); + WRITE_ONCE(desc->tcp_ts_reply, 0); val = FIELD_PREP(QDMA_DESC_LEN_MASK, e->dma_len); WRITE_ONCE(desc->ctrl, cpu_to_le32(val)); WRITE_ONCE(desc->addr, cpu_to_le32(e->dma_addr)); @@ -657,13 +742,146 @@ airoha_qdma_get_gdm_dev(struct airoha_eth *eth, struct airoha_qdma_desc *desc) return port->devs[d] ? port->devs[d] : ERR_PTR(-ENODEV); } +static int airoha_qdma_lro_rx_skb(struct airoha_queue *q, + struct airoha_qdma_desc *desc, + u32 msg1, u32 len) +{ + u32 th_off, tcp_ack_seq, data_off, agg_count = 1; + u32 msg2 = le32_to_cpu(READ_ONCE(desc->msg2)); + struct skb_shared_info *shinfo; + struct sk_buff *skb = q->skb; + u16 tcp_win, l2_len; + struct tcphdr *th; + bool ipv4, ipv6; + + if (airoha_qdma_is_lro_queue(q)) { + agg_count = FIELD_GET(QDMA_ETH_RXMSG_AGG_COUNT_MASK, msg2); + if (agg_count > AIROHA_RXQ_LRO_MAX_AGG_COUNT) + return -EINVAL; + } + + if (likely(agg_count <= 1)) /* not LRO */ + return 0; + + ipv4 = FIELD_GET(QDMA_ETH_RXMSG_IP4_MASK, msg1); + ipv6 = FIELD_GET(QDMA_ETH_RXMSG_IP6_MASK, msg1); + if (!ipv4 && !ipv6) + return 0; + + l2_len = FIELD_GET(QDMA_ETH_RXMSG_L2_LEN_MASK, msg2); + + if (ipv4) { + struct iphdr *iph, _iph; + + iph = skb_header_pointer(skb, l2_len, sizeof(*iph), &_iph); + if (!iph) + return -EINVAL; + + if (iph->protocol != IPPROTO_TCP) + return -EINVAL; + + if (iph->ihl < 5) + return -EINVAL; + + th_off = l2_len + (iph->ihl << 2); + if (!pskb_may_pull(skb, th_off)) + return -EINVAL; + + iph = (struct iphdr *)(skb->data + l2_len); + iph->tot_len = cpu_to_be16(len - l2_len); + iph->check = 0; + iph->check = ip_fast_csum((void *)iph, iph->ihl); + } else { + struct ipv6hdr *ip6h; + + th_off = l2_len + sizeof(*ip6h); + if (!pskb_may_pull(skb, th_off)) + return -EINVAL; + + ip6h = (struct ipv6hdr *)(skb->data + l2_len); + if (ip6h->nexthdr != NEXTHDR_TCP) + return -EINVAL; + + ip6h->payload_len = cpu_to_be16(len - th_off); + } + + data_off = th_off + sizeof(*th); + if (len < data_off) + return -EINVAL; + + if (!pskb_may_pull(skb, data_off)) + return -EINVAL; + + th = (struct tcphdr *)(skb->data + th_off); + if (th->doff < 5) + return -EINVAL; + + data_off = th_off + (th->doff << 2); + if (len <= data_off) + return -EINVAL; + + tcp_win = FIELD_GET(QDMA_ETH_RXMSG_TCP_WIN_MASK, + le32_to_cpu(READ_ONCE(desc->msg3))); + tcp_ack_seq = le32_to_cpu(READ_ONCE(desc->data)); + th->ack_seq = cpu_to_be32(tcp_ack_seq); + th->window = cpu_to_be16(tcp_win); + + /* Check tcp timestamp option */ + if (th->doff == (sizeof(*th) + TCPOLEN_TSTAMP_ALIGNED) / 4) { + u32 topt; + + if (!pskb_may_pull(skb, data_off)) + return -EINVAL; + + th = (struct tcphdr *)(skb->data + th_off); + topt = get_unaligned_be32(th + 1); + if (topt == ((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) | + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) { + u8 *ptr = (u8 *)th + sizeof(*th) + 2 * sizeof(__be32); + __le32 tcp_ts_reply = READ_ONCE(desc->tcp_ts_reply); + + /* The field is pre-zeroed in the posted descriptor, + * so a non-zero value is the hardware confirming the + * timestamp echo reply is valid. Leave TSecr + * untouched otherwise, since the hardware may not + * populate it for every aggregate. + */ + if (tcp_ts_reply) + put_unaligned_be32(le32_to_cpu(tcp_ts_reply), + ptr); + } + } + + if (ipv4) { + struct iphdr *iph = (struct iphdr *)(skb->data + l2_len); + + th->check = ~tcp_v4_check(len - th_off, iph->saddr, + iph->daddr, 0); + } else { + struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + l2_len); + + th->check = ~tcp_v6_check(len - th_off, &ip6h->saddr, + &ip6h->daddr, 0); + } + + shinfo = skb_shinfo(skb); + shinfo->gso_type = ipv4 ? SKB_GSO_TCPV4 : SKB_GSO_TCPV6; + shinfo->gso_type |= SKB_GSO_DODGY; + shinfo->gso_size = DIV_ROUND_UP(len - data_off, agg_count); + shinfo->gso_segs = agg_count; + + skb->csum_start = skb_headroom(skb) + th_off; + skb->csum_offset = offsetof(struct tcphdr, check); + skb->ip_summed = CHECKSUM_PARTIAL; + + return 0; +} + static int airoha_qdma_rx_process(struct airoha_queue *q, int budget) { enum dma_data_direction dir = page_pool_get_dma_dir(q->page_pool); - struct airoha_qdma *qdma = q->qdma; - struct airoha_eth *eth = qdma->eth; - int qid = q - &qdma->q_rx[0]; - int done = 0; + int qid = q - &q->qdma->q_rx[0], done = 0; + struct airoha_eth *eth = q->qdma->eth; while (done < budget) { struct airoha_queue_entry *e = &q->entry[q->tail]; @@ -696,7 +914,9 @@ static int airoha_qdma_rx_process(struct airoha_queue *q, int budget) if (IS_ERR(dev)) goto free_frag; + msg1 = le32_to_cpu(READ_ONCE(desc->msg1)); netdev = netdev_from_priv(dev); + if (!q->skb) { /* first buffer */ q->skb = napi_build_skb(e->buf - AIROHA_RX_HEADROOM, q->buf_size); @@ -707,9 +927,17 @@ static int airoha_qdma_rx_process(struct airoha_queue *q, int budget) __skb_put(q->skb, len); skb_mark_for_recycle(q->skb); q->skb->dev = netdev; - q->skb->protocol = eth_type_trans(q->skb, netdev); q->skb->ip_summed = CHECKSUM_UNNECESSARY; skb_record_rx_queue(q->skb, qid); + + if (airoha_qdma_lro_rx_skb(q, desc, msg1, len)) { + dev_core_stats_rx_dropped_inc(netdev); + dev_kfree_skb(q->skb); + q->skb = NULL; + continue; + } + + q->skb->protocol = eth_type_trans(q->skb, netdev); } else { /* scattered frame */ struct skb_shared_info *shinfo = skb_shinfo(q->skb); int nr_frags = shinfo->nr_frags; @@ -742,7 +970,6 @@ static int airoha_qdma_rx_process(struct airoha_queue *q, int budget) &port->dsa_meta[sptag]->dst); } - msg1 = le32_to_cpu(READ_ONCE(desc->msg1)); hash = FIELD_GET(AIROHA_RXD4_FOE_ENTRY, msg1); if (hash != AIROHA_RXD4_FOE_ENTRY) skb_set_hash(q->skb, jhash_1word(hash, 0), @@ -800,12 +1027,10 @@ static int airoha_qdma_rx_napi_poll(struct napi_struct *napi, int budget) static int airoha_qdma_init_rx_queue(struct airoha_queue *q, struct airoha_qdma *qdma, int ndesc) { - const struct page_pool_params pp_params = { - .order = 0, + struct page_pool_params pp_params = { .pool_size = 256, .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, .dma_dir = DMA_FROM_DEVICE, - .max_len = PAGE_SIZE, .nid = NUMA_NO_NODE, .dev = qdma->eth->dev, .napi = &q->napi, @@ -813,9 +1038,10 @@ static int airoha_qdma_init_rx_queue(struct airoha_queue *q, struct airoha_eth *eth = qdma->eth; int qid = q - &qdma->q_rx[0], thr; dma_addr_t dma_addr; + bool lro_q; - q->buf_size = PAGE_SIZE / 2; q->qdma = qdma; + lro_q = airoha_qdma_is_lro_queue(q); q->entry = devm_kzalloc(eth->dev, ndesc * sizeof(*q->entry), GFP_KERNEL); @@ -827,6 +1053,9 @@ static int airoha_qdma_init_rx_queue(struct airoha_queue *q, if (!q->desc) return -ENOMEM; + pp_params.order = lro_q ? AIROHA_LRO_PAGE_ORDER : 0; + pp_params.max_len = PAGE_SIZE << pp_params.order; + q->page_pool = page_pool_create(&pp_params); if (IS_ERR(q->page_pool)) { int err = PTR_ERR(q->page_pool); @@ -835,6 +1064,7 @@ static int airoha_qdma_init_rx_queue(struct airoha_queue *q, return err; } + q->buf_size = lro_q ? pp_params.max_len : pp_params.max_len / 2; q->ndesc = ndesc; netif_napi_add(eth->napi_dev, &q->napi, airoha_qdma_rx_napi_poll); @@ -848,7 +1078,12 @@ static int airoha_qdma_init_rx_queue(struct airoha_queue *q, FIELD_PREP(RX_RING_THR_MASK, thr)); airoha_qdma_rmw(qdma, REG_RX_DMA_IDX(qid), RX_RING_DMA_IDX_MASK, FIELD_PREP(RX_RING_DMA_IDX_MASK, q->head)); - airoha_qdma_set(qdma, REG_RX_SCATTER_CFG(qid), RX_RING_SG_EN_MASK); + if (lro_q) + airoha_qdma_clear(qdma, REG_RX_SCATTER_CFG(qid), + RX_RING_SG_EN_MASK); + else + airoha_qdma_set(qdma, REG_RX_SCATTER_CFG(qid), + RX_RING_SG_EN_MASK); airoha_qdma_fill_rx_queue(q); @@ -870,6 +1105,7 @@ static void airoha_qdma_cleanup_rx_queue(struct airoha_queue *q) page_pool_get_dma_dir(q->page_pool)); page_pool_put_full_page(q->page_pool, page, false); /* Reset DMA descriptor */ + WRITE_ONCE(desc->tcp_ts_reply, 0); WRITE_ONCE(desc->ctrl, 0); WRITE_ONCE(desc->addr, 0); WRITE_ONCE(desc->data, 0); @@ -1896,6 +2132,34 @@ static void airoha_update_hw_stats(struct airoha_gdm_dev *dev) spin_unlock(&port->stats_lock); } +static void airoha_update_netdev_features(struct airoha_gdm_dev *dev) +{ + struct airoha_eth *eth = dev->eth; + int i; + + for (i = 0; i < ARRAY_SIZE(eth->ports); i++) { + struct airoha_gdm_port *port = eth->ports[i]; + int j; + + if (!port) + continue; + + for (j = 0; j < ARRAY_SIZE(port->devs); j++) { + struct airoha_gdm_dev *iter_dev = port->devs[j]; + struct net_device *netdev; + + if (!iter_dev) + continue; + + netdev = netdev_from_priv(iter_dev); + if (netdev->reg_state != NETREG_REGISTERED) + continue; + + netdev_update_features(netdev); + } + } +} + static void airoha_dev_set_xmit_frame_size(struct net_device *netdev) { struct airoha_gdm_dev *dev = netdev_priv(netdev); @@ -1913,14 +2177,28 @@ static int airoha_dev_open(struct net_device *netdev) struct airoha_gdm_port *port = dev->port; u32 pse_port = FE_PSE_PORT_PPE1; struct airoha_qdma *qdma; - int err; + int qdma_id, err; + + /* LRO is configured on the QDMA and it is shared between all + * the devices using it. Refuse to open a second device on the + * same QDMA if LRO is enabled on any device sharing it or if + * this device has LRO enabled in its feature set. + */ + qdma = airoha_qdma_deref(dev); + qdma_id = qdma - &qdma->eth->qdma[0]; + + if (qdma->users > 1 && (airoha_fe_lro_is_enabled(qdma->eth, qdma_id) || + (netdev->features & NETIF_F_LRO))) { + netdev_warn(netdev, "required to disable LRO on QDMA%d\n", + qdma_id); + return -EBUSY; + } netif_tx_start_all_queues(netdev); err = airoha_set_vip_for_gdm_port(dev, true); if (err) return err; - qdma = airoha_qdma_deref(dev); if (netdev_uses_dsa(netdev)) airoha_fe_set(qdma->eth, REG_GDM_INGRESS_CFG(port->id), GDM_STAG_EN_MASK); @@ -1937,6 +2215,9 @@ static int airoha_dev_open(struct net_device *netdev) airoha_set_gdm_port_fwd_cfg(qdma->eth, REG_GDM_FWD_CFG(port->id), pse_port); + if (netdev->features & NETIF_F_LRO) + airoha_dev_lro_enable(dev); + return 0; } @@ -1954,6 +2235,10 @@ static int airoha_dev_stop(struct net_device *netdev) airoha_set_gdm_port_fwd_cfg(dev->eth, REG_GDM_FWD_CFG(port->id), FE_PSE_PORT_DROP); + + if (netdev->features & NETIF_F_LRO) + airoha_dev_lro_disable(dev); + return 0; } @@ -2115,11 +2400,14 @@ static void airoha_dev_set_qdma(struct airoha_gdm_dev *dev) qdma = ð->qdma[!airoha_is_lan_gdm_dev(dev)]; cur_qdma = airoha_qdma_deref(dev); - if (cur_qdma) + if (cur_qdma) { netif_tx_stop_all_queues(netdev); + airoha_dev_lro_disable(dev); + } rcu_assign_pointer(dev->qdma, qdma); netdev->irq = qdma->irq_banks[0].irq; + qdma->users++; synchronize_rcu(); ppe_id = !airoha_is_lan_gdm_dev(dev) && airoha_ppe_is_enabled(eth, 1); @@ -2136,8 +2424,14 @@ static void airoha_dev_set_qdma(struct airoha_gdm_dev *dev) airoha_qdma_rr(qdma, REG_CNTR_VAL((i << 1) + 1)); } - if (cur_qdma) + if (cur_qdma) { + cur_qdma->users--; netif_tx_wake_all_queues(netdev); + } + + airoha_update_netdev_features(dev); + if (netdev->features & NETIF_F_LRO) + airoha_dev_lro_enable(dev); } static int airoha_dev_init(struct net_device *netdev) @@ -2288,6 +2582,32 @@ int airoha_get_fe_port(struct airoha_gdm_dev *dev) } } +static netdev_features_t airoha_dev_fix_features(struct net_device *netdev, + netdev_features_t features) +{ + struct airoha_gdm_dev *dev = netdev_priv(netdev); + struct airoha_qdma *qdma; + + qdma = airoha_qdma_deref(dev); + if (qdma->users > 1) + features &= ~NETIF_F_LRO; + + return features; +} + +static int airoha_dev_set_features(struct net_device *netdev, + netdev_features_t features) +{ + struct airoha_gdm_dev *dev = netdev_priv(netdev); + + if (features & NETIF_F_LRO) + airoha_dev_lro_enable(dev); + else + airoha_dev_lro_disable(dev); + + return 0; +} + static netdev_tx_t airoha_dev_xmit(struct sk_buff *skb, struct net_device *netdev) { @@ -3199,7 +3519,7 @@ static int airoha_enable_qos_for_gdm34(struct net_device *netdev, struct airoha_gdm_dev *wan_dev, *dev = netdev_priv(netdev); struct airoha_gdm_port *port = dev->port; struct airoha_eth *eth = dev->eth; - int err = -EBUSY; + int err; if (port->id != AIROHA_GDM3_IDX && port->id != AIROHA_GDM4_IDX) { @@ -3218,6 +3538,7 @@ static int airoha_enable_qos_for_gdm34(struct net_device *netdev, wan_dev->port->id == AIROHA_GDM2_IDX) { NL_SET_ERR_MSG_MOD(extack, "QoS configured for WAN device"); + err = -EBUSY; goto error_unlock; } airoha_disable_qos_for_gdm34(netdev_from_priv(wan_dev)); @@ -3343,6 +3664,8 @@ static const struct net_device_ops airoha_netdev_ops = { .ndo_stop = airoha_dev_stop, .ndo_change_mtu = airoha_dev_change_mtu, .ndo_select_queue = airoha_dev_select_queue, + .ndo_fix_features = airoha_dev_fix_features, + .ndo_set_features = airoha_dev_set_features, .ndo_start_xmit = airoha_dev_xmit, .ndo_get_stats64 = airoha_dev_get_stats64, .ndo_set_mac_address = airoha_dev_set_macaddr, @@ -3430,11 +3753,9 @@ static int airoha_alloc_gdm_device(struct airoha_eth *eth, netdev->ethtool_ops = &airoha_ethtool_ops; netdev->max_mtu = AIROHA_MAX_MTU; netdev->watchdog_timeo = 5 * HZ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO6 | - NETIF_F_IPV6_CSUM | NETIF_F_SG | NETIF_F_TSO | - NETIF_F_HW_TC; - netdev->features |= netdev->hw_features; - netdev->vlan_features = netdev->hw_features; + netdev->hw_features = AIROHA_HW_FEATURES | NETIF_F_LRO; + netdev->features |= AIROHA_HW_FEATURES; + netdev->vlan_features = AIROHA_HW_FEATURES; SET_NETDEV_DEV(netdev, eth->dev); /* reserve hw queues for HTB offloading */ diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h index 527e3833e36b..286f73e2e1e0 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.h +++ b/drivers/net/ethernet/airoha/airoha_eth.h @@ -46,6 +46,18 @@ (_n) == 15 ? 128 : \ (_n) == 0 ? 1024 : 32) +#define AIROHA_LRO_PAGE_ORDER get_order(SZ_16K) +#define AIROHA_MAX_NUM_LRO_QUEUES 8 +#define AIROHA_RXQ_LRO_EN_MASK GENMASK(31, 24) +#define AIROHA_RXQ_LRO_MAX_AGG_COUNT 64 +#define AIROHA_RXQ_LRO_MAX_AGG_TIME 100 +#define AIROHA_RXQ_LRO_MAX_AGE_TIME 2000 + +#define AIROHA_HW_FEATURES \ + (NETIF_F_IP_CSUM | NETIF_F_RXCSUM | \ + NETIF_F_TSO6 | NETIF_F_IPV6_CSUM | \ + NETIF_F_SG | NETIF_F_TSO | NETIF_F_HW_TC) + #define PSE_RSV_PAGES 128 #define PSE_QUEUE_RSV_PAGES 64 @@ -561,6 +573,8 @@ struct airoha_qdma { struct airoha_eth *eth; void __iomem *regs; + int users; + struct airoha_irq_bank irq_banks[AIROHA_MAX_NUM_IRQ_BANKS]; struct airoha_tx_irq_queue q_tx_irq[AIROHA_NUM_TX_IRQ]; @@ -715,6 +729,18 @@ static inline bool airoha_is_7583(struct airoha_eth *eth) return eth->soc->version == 0x7583; } +static inline bool airoha_qdma_is_lro_queue(struct airoha_queue *q) +{ + struct airoha_qdma *qdma = q->qdma; + int qid = q - &qdma->q_rx[0]; + + /* EN7581 SoC supports at most 8 LRO rx queues */ + BUILD_BUG_ON(hweight32(AIROHA_RXQ_LRO_EN_MASK) > + AIROHA_MAX_NUM_LRO_QUEUES); + + return !!(AIROHA_RXQ_LRO_EN_MASK & BIT(qid)); +} + int airoha_get_fe_port(struct airoha_gdm_dev *dev); bool airoha_is_valid_gdm_dev(struct airoha_eth *eth, struct airoha_gdm_dev *dev); diff --git a/drivers/net/ethernet/airoha/airoha_regs.h b/drivers/net/ethernet/airoha/airoha_regs.h index 442b48c9b991..07dd04859fde 100644 --- a/drivers/net/ethernet/airoha/airoha_regs.h +++ b/drivers/net/ethernet/airoha/airoha_regs.h @@ -122,6 +122,20 @@ #define CDM_CRSN_QSEL_REASON_MASK(_n) \ GENMASK(4 + (((_n) % 4) << 3), (((_n) % 4) << 3)) +#define REG_CDM_LRO_RXQ(_n, _m) (CDM_BASE(_n) + 0x78 + ((_m) & 0x4)) +#define LRO_RXQ_MASK(_n) GENMASK(4 + (((_n) & 0x3) << 3), ((_n) & 0x3) << 3) + +#define REG_CDM_LRO_EN(_n) (CDM_BASE(_n) + 0x80) +#define LRO_RXQ_EN_MASK GENMASK(7, 0) + +#define REG_CDM_LRO_LIMIT(_n) (CDM_BASE(_n) + 0x84) +#define CDM_LRO_AGG_NUM_MASK GENMASK(23, 16) +#define CDM_LRO_AGG_SIZE_MASK GENMASK(15, 0) + +#define REG_CDM_LRO_AGE_TIME(_n) (CDM_BASE(_n) + 0x88) +#define CDM_LRO_AGE_TIME_MASK GENMASK(31, 16) +#define CDM_LRO_AGG_TIME_MASK GENMASK(15, 0) + #define REG_GDM_FWD_CFG(_n) GDM_BASE(_n) #define GDM_PAD_EN_MASK BIT(28) #define GDM_DROP_CRC_ERR_MASK BIT(23) @@ -887,9 +901,16 @@ #define QDMA_ETH_RXMSG_SPORT_MASK GENMASK(25, 21) #define QDMA_ETH_RXMSG_CRSN_MASK GENMASK(20, 16) #define QDMA_ETH_RXMSG_PPE_ENTRY_MASK GENMASK(15, 0) +/* RX MSG2 */ +#define QDMA_ETH_RXMSG_AGG_COUNT_MASK GENMASK(31, 24) +#define QDMA_ETH_RXMSG_L2_LEN_MASK GENMASK(6, 0) +/* RX MSG3 */ +/* max aggregated size in bytes */ +#define QDMA_ETH_RXMSG_AGG_LEN_MASK GENMASK(31, 16) +#define QDMA_ETH_RXMSG_TCP_WIN_MASK GENMASK(15, 0) struct airoha_qdma_desc { - __le32 rsv; + __le32 tcp_ts_reply; __le32 ctrl; __le32 addr; __le32 data; From 783f6f1fdcd50ca48f4c6805eaf7f43b70253a05 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Wed, 9 Sep 2026 18:15:37 -0600 Subject: [PATCH 0463/2126] dt-bindings: net: x-powers: add AC200/AC300 EPHY packages The AC200 and AC300 contain compatible Fast Ethernet link PHYs which report the same Clause 22 identifier and use the same link-side register layout. Their package control paths differ: AC200 control registers are accessed through the I2C register interface of the companion IC, while the AC300 control range is at a second Clause 22 address fixed at 16 plus the link address. Describe both variants as Ethernet PHY packages. The package reg value is the link PHY base address and the child supplies the documented PHY ID, because the identification registers cannot be read until package setup has completed. The AC300 driver reaches its control range with the PHY package offset helpers. The AC200 package instead references the companion IC described by the separately submitted x-powers,ac200 MFD binding. Its I2C interface provides access to the package controls. Give fixed hardware variant-specific compatibles. Also provide an ACx00 compatible for systems which can contain either package, with one packed NVMEM field containing calibration in bits 3 through 0, the AC300 selector in bit 8 and its low-calibration selector in bit 9. Such a description contains the potential resources for both backends; the driver consumes only those selected by the configuration field. Document the little-endian encoding and two-byte full configuration, while allowing a one-byte calibration value for fixed AC200 packages. Describe the package clock, supply and optional xMII receive-clock inversion needed by some integrations. A fixed AC200 package may omit the NVMEM field and use its internal calibration copy. Limit both the package and child link-PHY addresses in AC300-capable descriptions to 0 through 7 so the control address remains in the documented range 16 through 23. Signed-off-by: James Hilliard Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260909-submit-acx00-of-dynamic-v1-v11-1-eb45e89ef918@gmail.com Signed-off-by: Jakub Kicinski --- .../net/x-powers,acx00-ephy-package.yaml | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/x-powers,acx00-ephy-package.yaml diff --git a/Documentation/devicetree/bindings/net/x-powers,acx00-ephy-package.yaml b/Documentation/devicetree/bindings/net/x-powers,acx00-ephy-package.yaml new file mode 100644 index 000000000000..781695d9d9f1 --- /dev/null +++ b/Documentation/devicetree/bindings/net/x-powers,acx00-ephy-package.yaml @@ -0,0 +1,170 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/x-powers,acx00-ephy-package.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: X-Powers AC200 and AC300 Ethernet PHY packages + +maintainers: + - James Hilliard + +description: + The AC200 and AC300 contain compatible Fast Ethernet PHY blocks which report + the same Clause 22 PHY ID and use the same link-side register layout. The + package control paths differ. AC200 package control registers are accessed + through the companion IC's I2C register interface, while AC300 control + registers occupy a second Clause 22 address fixed at 16 plus the link PHY + address. + + Systems with a known package use the corresponding AC200 or AC300 compatible. + Systems which can contain either package use the ACx00 compatible and a + packed NVMEM configuration field to select the backend at runtime. + + The link PHY cannot report its ID until the package control sequence has + completed, so its child node supplies the documented PHY ID. The package and + child use the same base address. The AC200 driver programs that address into + the package, while the AC300 driver derives its control address from it. + +properties: + compatible: + enum: + - x-powers,ac200-ephy-package + - x-powers,ac300-ephy-package + - x-powers,acx00-ephy-package + + reg: + maximum: 31 + + clocks: + maxItems: 1 + description: AC300 input clock, running at 24, 25, or 27 MHz + + vcc-supply: + description: + 3.3 V package supply. This is connected to EPHY_VCC on AC200 and VCC1 + on AC300. + + nvmem-cells: + maxItems: 1 + description: + Packed little-endian EPHY configuration value, with the least-significant + byte first. Bits 3 through 0 contain the analog calibration code, bits 7 + through 4 are reserved, bit 8 selects AC300 when set and AC200 when clear, + and bit 9 requests the AC300 low-calibration tuning sequence. Bits 15 + through 10 are reserved. + + AC300 and selectable ACx00 packages require the full configuration + field, including bits 8 and 9 even when their values are zero, returned + as two bytes. A fixed AC200 package may provide a one-byte calibration + value or a two-byte configuration with bit 8 clear, or omit the cell + and use its internal eFuse calibration copy. + + nvmem-cell-names: + const: configuration + + x-powers,ac200: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to the AC200 companion IC described by the x-powers,ac200 MFD + binding. Its I2C interface provides access to the package control + registers used to power and configure the Ethernet PHY. + + x-powers,xmii-rx-clock-inverted: + type: boolean + description: + Invert the xMII receive clock inside the PHY. This is required by some + SoC integrations, including the Allwinner H6 AC200 connection. + +patternProperties: + ^ethernet-phy@[a-f0-9]+$: + $ref: ethernet-phy.yaml# + properties: + compatible: + const: ethernet-phy-id0044.1400 + required: + - compatible + unevaluatedProperties: false + +required: + - compatible + - vcc-supply + +dependentRequired: + nvmem-cells: [ nvmem-cell-names ] + +allOf: + - $ref: ethernet-phy-package.yaml# + - if: + properties: + compatible: + const: x-powers,ac200-ephy-package + then: + properties: + clocks: false + required: + - x-powers,ac200 + - if: + properties: + compatible: + const: x-powers,ac300-ephy-package + then: + properties: + x-powers,ac200: false + required: + - clocks + - nvmem-cells + - nvmem-cell-names + - if: + properties: + compatible: + const: x-powers,acx00-ephy-package + then: + required: + - clocks + - nvmem-cells + - nvmem-cell-names + - x-powers,ac200 + - if: + properties: + compatible: + enum: + - x-powers,ac300-ephy-package + - x-powers,acx00-ephy-package + then: + properties: + reg: + maximum: 7 + patternProperties: + ^ethernet-phy@[a-f0-9]+$: + properties: + reg: + maximum: 7 + +unevaluatedProperties: false + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy-package@0 { + compatible = "x-powers,acx00-ephy-package"; + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&pwm 5>; + vcc-supply = <®_3v3>; + nvmem-cells = <&ephy_configuration>; + nvmem-cell-names = "configuration"; + x-powers,ac200 = <&ac200>; + + ethernet-phy@0 { + compatible = "ethernet-phy-id0044.1400"; + reg = <0>; + }; + }; + }; + +... From 6cc2fbceb49be43e4280599162e2dd73d1b40fd9 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Wed, 9 Sep 2026 18:15:38 -0600 Subject: [PATCH 0464/2126] net: phy: add X-Powers AC200/AC300 EPHY driver The AC200 and AC300 contain compatible Fast Ethernet link PHYs, but the link endpoint is inaccessible until package-specific control registers have powered and configured it. Add one PHY driver which binds the link child and joins its parent Ethernet PHY package. Fixed package compatibles select the corresponding backend. The generic ACx00 compatible reads one packed configuration field and selects the backend before touching backend-specific resources. The AC300 path therefore does not resolve or access the candidate AC200 I2C device. Require two returned NVMEM bytes for AC300 and selectable ACx00 packages before selecting the backend. Keep the existing little-endian decoding and one-byte calibration support for fixed AC200 packages. AC200 locates the I2C device referenced by the package and establishes a managed device link. It verifies that the provider is fully bound under the supplier device lock before retrieving the regmap attached to the I2C device. The companion MFD provider enables and exclusively pins the input clock rate while it is bound. The link keeps the supplier bound until the PHY consumer has unbound. Firmware must make the selected AC200 provider path available before the PHY probes. AC300 uses the PHY package helpers to access the control range at base address plus 16. Keeping both backends in the same module lets the common link implementation own the complete PHY without registering artificial control devices. Obtain and manage the selected package supply and calibration, manage the AC300 input clock, validate or program the link address, and apply the required reset, clock, I/O and shutdown sequences. Start in the hardware-default MII mode so the forced PHY device can probe before a MAC attaches, then apply the MAC-provided MII or RMII mode before the normal PHY soft reset. AC200 specifies no additional delay between its EPHY controls; the provider's input-clock startup delay is already complete before its regmap becomes available. Apply the common vendor analog initialization, optional AC300 low-calibration tuning and board-selected receive-clock inversion. Keep MDI/MDI-X in automatic mode. Preserve standard MAC-managed EEE support while disabling the vendor PHY-autonomous Intelligent EEE mode. Restart autonegotiation when restoring the standard EEE advertisement changes it. Serialize package state and the multi-register power sequences across the different phylib callback lock contexts. Power down the package control block and its supply during PHY suspend, then restore them and the vendor configuration during resume. If shutdown fails after resetting the PHY, restore the vendor settings and standard advertisement or forced speed/duplex under the phylib lock before returning the original error. A failed suspend is not followed by a normal resume to restore these settings. Power down again if recovery fails, and unwind package power if reset, resume or configuration fails after power-on. Signed-off-by: James Hilliard Link: https://patch.msgid.link/20260909-submit-acx00-of-dynamic-v1-v11-2-eb45e89ef918@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/Kconfig | 11 + drivers/net/phy/Makefile | 1 + drivers/net/phy/xpowers/Makefile | 3 + drivers/net/phy/xpowers/ac200.c | 314 +++++++++++++++ drivers/net/phy/xpowers/ac300.c | 387 +++++++++++++++++++ drivers/net/phy/xpowers/acx00.c | 633 +++++++++++++++++++++++++++++++ drivers/net/phy/xpowers/acx00.h | 28 ++ 7 files changed, 1377 insertions(+) create mode 100644 drivers/net/phy/xpowers/Makefile create mode 100644 drivers/net/phy/xpowers/ac200.c create mode 100644 drivers/net/phy/xpowers/ac300.c create mode 100644 drivers/net/phy/xpowers/acx00.c create mode 100644 drivers/net/phy/xpowers/acx00.h diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index b4ef927fd4a6..d3835597e379 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -484,6 +484,17 @@ config VITESSE_PHY help Currently supports the vsc8244 +config XPOWERS_ACX00_PHY + tristate "X-Powers AC200/AC300 Ethernet PHY" + depends on COMMON_CLK && NVMEM && OF_MDIO && REGULATOR + depends on I2C || !I2C + select PHY_PACKAGE + help + Enable the Fast Ethernet PHY driver shared by the X-Powers AC200 + and AC300 companion ICs. The driver configures their common MDIO PHY + registers and the package-specific AC200 I2C or AC300 MDIO control + registers. + config XILINX_GMII2RGMII tristate "Xilinx GMII2RGMII converter driver" help diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 25c4a3c2429f..49575fa18522 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -101,4 +101,5 @@ obj-$(CONFIG_SMSC_PHY) += smsc.o obj-$(CONFIG_STE10XP) += ste10Xp.o obj-$(CONFIG_TERANETICS_PHY) += teranetics.o obj-$(CONFIG_VITESSE_PHY) += vitesse.o +obj-$(CONFIG_XPOWERS_ACX00_PHY) += xpowers/ obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o diff --git a/drivers/net/phy/xpowers/Makefile b/drivers/net/phy/xpowers/Makefile new file mode 100644 index 000000000000..ae977a795832 --- /dev/null +++ b/drivers/net/phy/xpowers/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +xpowers-acx00-y := acx00.o ac200.o ac300.o +obj-$(CONFIG_XPOWERS_ACX00_PHY) += xpowers-acx00.o diff --git a/drivers/net/phy/xpowers/ac200.c b/drivers/net/phy/xpowers/ac200.c new file mode 100644 index 000000000000..afdd2a3dfbe4 --- /dev/null +++ b/drivers/net/phy/xpowers/ac200.c @@ -0,0 +1,314 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * X-Powers AC200 Ethernet PHY package backend + * + * Copyright (c) 2022 Arm Ltd. (Andre Przywara ) + * Copyright (C) 2026 James Hilliard + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "acx00.h" + +#define AC200_EPHY_BPS_EFFUSE_OFFSET 3 +#define AC200_EPHY_CLK_RATE_24_MHZ 24000000 +#define AC200_EPHY_CLK_RATE_27_MHZ 27000000 + +#define AC200_SYS_EPHY_CTL0_REG 0x0014 +#define AC200_EPHY_RESET_DEASSERT BIT(0) +#define AC200_EPHY_SYSCLK_ENABLE BIT(1) + +#define AC200_SYS_EPHY_CTL1_REG 0x0016 +#define AC200_EPHY_MII_IO_ENABLE BIT(0) + +/* AC200-internal copy of the Ethernet PHY calibration eFuse. */ +#define AC200_EFUSE_EPHY_REG 0x8004 + +#define AC200_EPHY_CTL_REG 0x6000 +#define AC200_EPHY_SHUTDOWN BIT(0) +#define AC200_EPHY_CLK_SEL_24_MHZ BIT(2) +#define AC200_EPHY_PHY_ADDR_MASK GENMASK(8, 4) +#define AC200_EPHY_RMII_SEL BIT(11) +#define AC200_EPHY_BPS_EFFUSE_MASK GENMASK(15, 12) + +struct ac200_ephy_ctl { + struct acx00_ephy_control control; + struct regmap *regmap; + struct regulator *vcc; + struct device *dev; + u16 ephy_ctl; + unsigned int phy_addr; + phy_interface_t interface; + bool supply_enabled; + bool powered; +}; + +static u16 ac200_ephy_ctl_config(const struct ac200_ephy_ctl *priv) +{ + return priv->ephy_ctl | + (priv->interface == PHY_INTERFACE_MODE_RMII ? + AC200_EPHY_RMII_SEL : 0) | + FIELD_PREP(AC200_EPHY_PHY_ADDR_MASK, priv->phy_addr); +} + +static int ac200_ephy_ctl_write(struct ac200_ephy_ctl *priv, + unsigned int reg, u16 value) +{ + int ret; + + ret = regmap_write(priv->regmap, reg, value); + if (ret) + dev_err(priv->dev, "failed to write register %#x: %pe\n", + reg, ERR_PTR(ret)); + + return ret; +} + +static int ac200_ephy_ctl_disable(struct ac200_ephy_ctl *priv) +{ + int err; + int ret = 0; + + if (priv->powered) { + ret = ac200_ephy_ctl_write(priv, AC200_EPHY_CTL_REG, + ac200_ephy_ctl_config(priv) | + AC200_EPHY_SHUTDOWN); + err = ac200_ephy_ctl_write(priv, AC200_SYS_EPHY_CTL1_REG, 0); + if (!ret) + ret = err; + err = ac200_ephy_ctl_write(priv, AC200_SYS_EPHY_CTL0_REG, 0); + if (!ret) + ret = err; + + priv->powered = false; + } + + if (priv->supply_enabled) { + err = regulator_disable(priv->vcc); + if (!err) + priv->supply_enabled = false; + else if (!ret) + ret = err; + } + + return ret; +} + +static int ac200_ephy_ctl_power_off(struct acx00_ephy_control *control) +{ + struct ac200_ephy_ctl *priv = + container_of(control, struct ac200_ephy_ctl, control); + + return ac200_ephy_ctl_disable(priv); +} + +static int +ac200_ephy_ctl_set_interface(struct acx00_ephy_control *control, + phy_interface_t interface) +{ + struct ac200_ephy_ctl *priv = + container_of(control, struct ac200_ephy_ctl, control); + int ret = 0; + + if (interface != PHY_INTERFACE_MODE_MII && + interface != PHY_INTERFACE_MODE_RMII) + return -EINVAL; + + if (priv->interface == interface) + return 0; + + if (priv->powered) + ret = regmap_update_bits(priv->regmap, AC200_EPHY_CTL_REG, + AC200_EPHY_RMII_SEL, + interface == PHY_INTERFACE_MODE_RMII ? + AC200_EPHY_RMII_SEL : 0); + if (!ret) + priv->interface = interface; + + return ret; +} + +static int ac200_ephy_ctl_power_on(struct acx00_ephy_control *control, + unsigned int phy_addr) +{ + struct ac200_ephy_ctl *priv = + container_of(control, struct ac200_ephy_ctl, control); + u16 ephy_ctl; + int ret; + + if (phy_addr > FIELD_MAX(AC200_EPHY_PHY_ADDR_MASK)) + return -EINVAL; + + if (priv->powered && priv->phy_addr == phy_addr) + return 0; + + if (priv->powered) { + ret = ac200_ephy_ctl_disable(priv); + if (ret) + return ret; + } + priv->phy_addr = phy_addr; + + if (!priv->supply_enabled) { + ret = regulator_enable(priv->vcc); + if (ret) + return ret; + priv->supply_enabled = true; + } + + ephy_ctl = ac200_ephy_ctl_config(priv); + + /* + * Start from a disabled state before applying the configuration. AC200 + * specifies no additional delay between these controls. The companion + * MFD provider has completed its input-clock startup delay before + * publishing the regmap. + */ + ret = ac200_ephy_ctl_write(priv, AC200_SYS_EPHY_CTL0_REG, 0); + if (ret) + goto err_disable; + + ret = ac200_ephy_ctl_write(priv, AC200_SYS_EPHY_CTL1_REG, + AC200_EPHY_MII_IO_ENABLE); + if (ret) + goto err_disable; + + ret = ac200_ephy_ctl_write(priv, AC200_EPHY_CTL_REG, + ephy_ctl | AC200_EPHY_SHUTDOWN); + if (ret) + goto err_disable; + + ret = ac200_ephy_ctl_write(priv, AC200_SYS_EPHY_CTL0_REG, + AC200_EPHY_RESET_DEASSERT | + AC200_EPHY_SYSCLK_ENABLE); + if (ret) + goto err_disable; + + ret = ac200_ephy_ctl_write(priv, AC200_EPHY_CTL_REG, ephy_ctl); + if (ret) + goto err_disable; + + priv->powered = true; + return 0; + +err_disable: + /* Attempt every step of the shutdown sequence after a partial start. */ + priv->powered = true; + ac200_ephy_ctl_disable(priv); + + return ret; +} + +struct acx00_ephy_control * +ac200_ephy_ctl_create(struct phy_device *phydev, + struct device_node *package_node, + bool has_calibration, u8 calibration) +{ + struct device *dev = &phydev->mdio.dev; + unsigned int internal_calibration; + struct device_node *ac200_node; + struct ac200_ephy_ctl *priv; + struct i2c_client *client; + unsigned long clk_rate; + u8 bps_effuse_code; + struct clk *clk; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + priv->dev = dev; + priv->vcc = devm_of_regulator_get(dev, package_node, "vcc"); + if (IS_ERR(priv->vcc)) + return ERR_PTR(dev_err_probe(dev, PTR_ERR(priv->vcc), + "failed to get package supply\n")); + + ac200_node = of_parse_phandle(package_node, "x-powers,ac200", 0); + if (!ac200_node) + return ERR_PTR(dev_err_probe(dev, -EINVAL, + "missing x-powers,ac200 reference\n")); + client = of_find_i2c_device_by_node(ac200_node); + of_node_put(ac200_node); + if (!client) { + ret = IS_ENABLED(CONFIG_I2C) ? -EPROBE_DEFER : -ENODEV; + return ERR_PTR(dev_err_probe(dev, ret, + "AC200 device is not registered\n")); + } + + if (!device_link_add(dev, &client->dev, + DL_FLAG_AUTOREMOVE_CONSUMER)) { + ret = dev_err_probe(dev, -EINVAL, + "failed to link AC200 device\n"); + goto out_put_client; + } + + device_lock(&client->dev); + if (device_is_bound(&client->dev)) + priv->regmap = dev_get_regmap(&client->dev, NULL); + device_unlock(&client->dev); + if (!priv->regmap) { + ret = dev_err_probe(dev, -EPROBE_DEFER, + "AC200 driver is not ready\n"); + goto out_put_client; + } + + if (!has_calibration) { + ret = regmap_read(priv->regmap, AC200_EFUSE_EPHY_REG, + &internal_calibration); + if (ret) + goto out_error; + calibration = internal_calibration; + } + + /* The vendor driver supplies no transfer function beyond this offset. */ + bps_effuse_code = (calibration + AC200_EPHY_BPS_EFFUSE_OFFSET) & + FIELD_MAX(AC200_EPHY_BPS_EFFUSE_MASK); + priv->ephy_ctl = + FIELD_PREP(AC200_EPHY_BPS_EFFUSE_MASK, bps_effuse_code); + /* EPHY_MODE and BIST_CLK_EN stay clear for normal operation. */ + + clk = clk_get(&client->dev, NULL); + if (IS_ERR(clk)) { + ret = PTR_ERR(clk); + goto out_error; + } + + /* The bound AC200 provider enables and exclusively pins this rate. */ + clk_rate = clk_get_rate(clk); + clk_put(clk); + + switch (clk_rate) { + case AC200_EPHY_CLK_RATE_24_MHZ: + priv->ephy_ctl |= AC200_EPHY_CLK_SEL_24_MHZ; + break; + case AC200_EPHY_CLK_RATE_27_MHZ: + break; + default: + ret = dev_err_probe(dev, -EINVAL, + "unsupported AC200 clock rate %lu Hz\n", + clk_rate); + goto out_put_client; + } + + priv->control.power_on = ac200_ephy_ctl_power_on; + priv->control.power_off = ac200_ephy_ctl_power_off; + priv->control.set_interface = ac200_ephy_ctl_set_interface; + /* MII is the reset default used until the MAC supplies its interface. */ + priv->interface = PHY_INTERFACE_MODE_MII; + put_device(&client->dev); + + return &priv->control; + +out_error: + ret = dev_err_probe(dev, ret, "failed to initialize AC200 control\n"); +out_put_client: + put_device(&client->dev); + return ERR_PTR(ret); +} diff --git a/drivers/net/phy/xpowers/ac300.c b/drivers/net/phy/xpowers/ac300.c new file mode 100644 index 000000000000..aa560432a14c --- /dev/null +++ b/drivers/net/phy/xpowers/ac300.c @@ -0,0 +1,387 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * X-Powers AC300 Ethernet PHY package backend + * + * Copyright (C) 2026 James Hilliard + */ + +#include +#include +#include +#include +#include +#include + +#include "../phylib.h" +#include "acx00.h" + +#define AC300_EPHY_BGS_EFFUSE_OFFSET 3 +#define AC300_EPHY_CLK_RATE_24_MHZ 24000000 +#define AC300_EPHY_CLK_RATE_25_MHZ 25000000 +#define AC300_EPHY_CLK_RATE_27_MHZ 27000000 +#define AC300_SYS_CONTROL_REG 0x00 +#define AC300_PACKAGE_STATUS_MASK GENMASK(11, 8) +#define AC300_EPHY_CLK_SEL_MASK GENMASK(7, 6) +#define AC300_EPHY_CLK_SEL_25_MHZ FIELD_PREP(AC300_EPHY_CLK_SEL_MASK, 0) +#define AC300_EPHY_CLK_SEL_27_MHZ FIELD_PREP(AC300_EPHY_CLK_SEL_MASK, 1) +#define AC300_EPHY_CLK_SEL_24_MHZ FIELD_PREP(AC300_EPHY_CLK_SEL_MASK, 2) +#define AC300_EFUSE_CLK_ENABLE BIT(5) +#define AC300_EPHY_REG_CLK_ENABLE BIT(4) +#define AC300_CLKIN_GATING_ENABLE BIT(2) +#define AC300_EPHY_RESET_DEASSERT BIT(1) +#define AC300_CHIP_RESET_DEASSERT BIT(0) + +#define AC300_PACKAGE_POR_INTERNAL_DLDO BIT(3) +#define AC300_PACKAGE_PHY_ADDR_MASK GENMASK(2, 0) + +#define AC300_SYS_BIAS1_REG 0x02 +#define AC300_INTERNAL_DLDO_ENABLE BIT(15) + +#define AC300_SYS_IO_REG 0x05 +#define AC300_MDIO_DRV_MASK GENMASK(15, 14) +#define AC300_MII_DRV_MASK GENMASK(11, 10) +#define AC300_IO_DRV_LEVEL_2 2 +#define AC300_CLKIN_PAD_ENABLE BIT(4) +#define AC300_EPHY_MII_IO_ENABLE BIT(0) + +#define AC300_EPHY_CONFIG_REG 0x06 +#define AC300_EPHY_BGS_EFFUSE_MASK GENMASK(15, 12) +#define AC300_EPHY_RMII_SEL BIT(11) +#define AC300_EPHY_SHUTDOWN BIT(0) + +#define AC300_SYS_CONTROL_ENABLE_BITS \ + (AC300_EFUSE_CLK_ENABLE | AC300_EPHY_REG_CLK_ENABLE | \ + AC300_CLKIN_GATING_ENABLE | AC300_EPHY_RESET_DEASSERT | \ + AC300_CHIP_RESET_DEASSERT) + +#define AC300_SYS_IO_VALUE \ + (FIELD_PREP(AC300_MDIO_DRV_MASK, AC300_IO_DRV_LEVEL_2) | \ + FIELD_PREP(AC300_MII_DRV_MASK, AC300_IO_DRV_LEVEL_2) | \ + AC300_CLKIN_PAD_ENABLE | AC300_EPHY_MII_IO_ENABLE) + +struct ac300_ephy_ctl { + struct acx00_ephy_control control; + struct phy_device *phydev; + struct regulator *vcc; + struct clk *clk; + u16 sys_control; + u16 ephy_config; + phy_interface_t interface; + bool package_known; + bool internal_dldo; + bool supply_enabled; + bool powered; +}; + +static unsigned int +ac300_ephy_ctl_link_addr(const struct ac300_ephy_ctl *priv) +{ + return priv->phydev->mdio.addr; +} + +static int ac300_ephy_ctl_read(struct ac300_ephy_ctl *priv, u32 regnum) +{ + int ret; + + phy_lock_mdio_bus(priv->phydev); + ret = __phy_package_read(priv->phydev, + AC300_EPHY_CONTROL_ADDR_OFFSET, regnum); + phy_unlock_mdio_bus(priv->phydev); + + return ret; +} + +static int ac300_ephy_ctl_write(struct ac300_ephy_ctl *priv, u32 regnum, + u16 val) +{ + int ret; + + phy_lock_mdio_bus(priv->phydev); + ret = __phy_package_write(priv->phydev, + AC300_EPHY_CONTROL_ADDR_OFFSET, regnum, val); + phy_unlock_mdio_bus(priv->phydev); + + return ret; +} + +static int ac300_ephy_ctl_modify(struct ac300_ephy_ctl *priv, u32 regnum, + u16 mask, u16 set) +{ + int ret; + + phy_lock_mdio_bus(priv->phydev); + ret = __phy_package_read(priv->phydev, + AC300_EPHY_CONTROL_ADDR_OFFSET, regnum); + if (ret >= 0) { + u16 val = (ret & ~mask) | (set & mask); + + ret = val == ret ? 0 : + __phy_package_write(priv->phydev, + AC300_EPHY_CONTROL_ADDR_OFFSET, + regnum, val); + } + phy_unlock_mdio_bus(priv->phydev); + + return ret; +} + +static u16 ac300_ephy_ctl_config(const struct ac300_ephy_ctl *priv) +{ + return priv->ephy_config | + (priv->interface == PHY_INTERFACE_MODE_RMII ? + AC300_EPHY_RMII_SEL : 0); +} + +static u16 ac300_ephy_ctl_reset_value(const struct ac300_ephy_ctl *priv) +{ + /* + * A chip reset restores DLDOEN to one. Until PKG_STATUS has identified + * the supply arrangement, preserve any external-VDD setup left by the + * bootloader by asserting only the EPHY reset. + */ + return !priv->package_known || !priv->internal_dldo ? + AC300_CHIP_RESET_DEASSERT : 0; +} + +static int ac300_ephy_ctl_disable(struct ac300_ephy_ctl *priv) +{ + int err; + int ret = 0; + + if (priv->powered) { + ret = ac300_ephy_ctl_write(priv, AC300_EPHY_CONFIG_REG, + ac300_ephy_ctl_config(priv) | + AC300_EPHY_SHUTDOWN); + err = ac300_ephy_ctl_write(priv, AC300_SYS_IO_REG, 0); + if (!ret) + ret = err; + err = ac300_ephy_ctl_write(priv, AC300_SYS_CONTROL_REG, + ac300_ephy_ctl_reset_value(priv)); + if (!ret) + ret = err; + + clk_disable_unprepare(priv->clk); + priv->powered = false; + } + + if (priv->supply_enabled) { + err = regulator_disable(priv->vcc); + if (!err) + priv->supply_enabled = false; + else if (!ret) + ret = err; + } + + return ret; +} + +static int ac300_ephy_ctl_power_off(struct acx00_ephy_control *control) +{ + struct ac300_ephy_ctl *priv = + container_of(control, struct ac300_ephy_ctl, control); + + return ac300_ephy_ctl_disable(priv); +} + +static int +ac300_ephy_ctl_set_interface(struct acx00_ephy_control *control, + phy_interface_t interface) +{ + struct ac300_ephy_ctl *priv = + container_of(control, struct ac300_ephy_ctl, control); + int ret = 0; + + if (interface != PHY_INTERFACE_MODE_MII && + interface != PHY_INTERFACE_MODE_RMII) + return -EINVAL; + + if (priv->interface == interface) + return 0; + + if (priv->powered) + ret = ac300_ephy_ctl_modify(priv, AC300_EPHY_CONFIG_REG, + AC300_EPHY_RMII_SEL, + interface == PHY_INTERFACE_MODE_RMII ? + AC300_EPHY_RMII_SEL : 0); + if (!ret) + priv->interface = interface; + + return ret; +} + +static int ac300_ephy_ctl_power_on(struct acx00_ephy_control *control, + unsigned int phy_addr) +{ + struct ac300_ephy_ctl *priv = + container_of(control, struct ac300_ephy_ctl, control); + u8 package_status; + u16 reset_value; + int sys_control; + int ret; + + if (phy_addr != ac300_ephy_ctl_link_addr(priv)) + return -EINVAL; + + if (priv->powered) + return 0; + + if (!priv->supply_enabled) { + ret = regulator_enable(priv->vcc); + if (ret) + return ret; + priv->supply_enabled = true; + + /* Wait for the power-on reset interval specified by the manual. */ + fsleep(10000); + } + + ret = clk_prepare_enable(priv->clk); + if (ret) + goto err_power_off; + priv->powered = true; + + /* Keep the external-supply configuration across chip resets. */ + reset_value = ac300_ephy_ctl_reset_value(priv); + ret = ac300_ephy_ctl_write(priv, AC300_SYS_CONTROL_REG, reset_value); + if (ret) + goto err_power_off; + + /* The manual requires both resets to be released before the clocks. */ + ret = ac300_ephy_ctl_write(priv, AC300_SYS_CONTROL_REG, + AC300_EPHY_RESET_DEASSERT | + AC300_CHIP_RESET_DEASSERT); + if (ret) + goto err_power_off; + + /* Retain the vendor clock-enable defaults, including the eFuse clock. */ + ret = ac300_ephy_ctl_write(priv, AC300_SYS_CONTROL_REG, + priv->sys_control); + if (ret) + goto err_power_off; + + sys_control = ac300_ephy_ctl_read(priv, AC300_SYS_CONTROL_REG); + if (sys_control < 0) { + ret = sys_control; + goto err_power_off; + } + + package_status = FIELD_GET(AC300_PACKAGE_STATUS_MASK, sys_control); + if ((~package_status & AC300_PACKAGE_PHY_ADDR_MASK) != + ac300_ephy_ctl_link_addr(priv)) { + ret = -EINVAL; + goto err_power_off; + } + + priv->internal_dldo = package_status & AC300_PACKAGE_POR_INTERNAL_DLDO; + priv->package_known = true; + ret = ac300_ephy_ctl_modify(priv, AC300_SYS_BIAS1_REG, + AC300_INTERNAL_DLDO_ENABLE, + priv->internal_dldo ? + AC300_INTERNAL_DLDO_ENABLE : 0); + if (ret) + goto err_power_off; + + /* Keep the documented default drive level and leave the IRQ disabled. */ + ret = ac300_ephy_ctl_write(priv, AC300_SYS_IO_REG, + AC300_SYS_IO_VALUE); + if (ret) + goto err_power_off; + + fsleep(10000); + + ret = ac300_ephy_ctl_write(priv, AC300_EPHY_CONFIG_REG, + ac300_ephy_ctl_config(priv) | + AC300_EPHY_SHUTDOWN); + if (ret) + goto err_power_off; + + fsleep(10000); + + ret = ac300_ephy_ctl_write(priv, AC300_EPHY_CONFIG_REG, + ac300_ephy_ctl_config(priv)); + if (ret) + goto err_power_off; + + return 0; + +err_power_off: + ac300_ephy_ctl_disable(priv); + + return ret; +} + +static void ac300_ephy_clk_put(void *data) +{ + clk_put(data); +} + +struct acx00_ephy_control * +ac300_ephy_ctl_create(struct phy_device *phydev, + struct device_node *package_node, u8 calibration) +{ + struct device *dev = &phydev->mdio.dev; + struct ac300_ephy_ctl *priv; + unsigned long clk_rate; + u8 bgs_effuse_code; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + if (phydev->mdio.addr > FIELD_MAX(AC300_PACKAGE_PHY_ADDR_MASK)) + return ERR_PTR(dev_err_probe(dev, -EINVAL, + "link address is outside the package range\n")); + priv->phydev = phydev; + + priv->vcc = devm_of_regulator_get(dev, package_node, "vcc"); + if (IS_ERR(priv->vcc)) + return ERR_PTR(dev_err_probe(dev, PTR_ERR(priv->vcc), + "failed to get package supply\n")); + + priv->clk = of_clk_get(package_node, 0); + if (IS_ERR(priv->clk)) + return ERR_PTR(dev_err_probe(dev, PTR_ERR(priv->clk), + "failed to get input clock\n")); + + ret = devm_add_action_or_reset(dev, ac300_ephy_clk_put, priv->clk); + if (ret) + return ERR_PTR(ret); + + ret = devm_clk_rate_exclusive_get(dev, priv->clk); + if (ret) + return ERR_PTR(dev_err_probe(dev, ret, + "failed to lock clock rate\n")); + + clk_rate = clk_get_rate(priv->clk); + switch (clk_rate) { + case AC300_EPHY_CLK_RATE_24_MHZ: + priv->sys_control = AC300_EPHY_CLK_SEL_24_MHZ; + break; + case AC300_EPHY_CLK_RATE_25_MHZ: + priv->sys_control = AC300_EPHY_CLK_SEL_25_MHZ; + break; + case AC300_EPHY_CLK_RATE_27_MHZ: + priv->sys_control = AC300_EPHY_CLK_SEL_27_MHZ; + break; + default: + return ERR_PTR(dev_err_probe(dev, -EINVAL, + "unsupported input clock rate %lu Hz\n", + clk_rate)); + } + priv->sys_control |= AC300_SYS_CONTROL_ENABLE_BITS; + + /* The vendor driver supplies no transfer function beyond this offset. */ + bgs_effuse_code = (calibration + AC300_EPHY_BGS_EFFUSE_OFFSET) & + FIELD_MAX(AC300_EPHY_BGS_EFFUSE_MASK); + priv->ephy_config = + FIELD_PREP(AC300_EPHY_BGS_EFFUSE_MASK, bgs_effuse_code); + /* EPHY_MODE and BIST_CLK_EN stay clear for normal operation. */ + + priv->control.power_on = ac300_ephy_ctl_power_on; + priv->control.power_off = ac300_ephy_ctl_power_off; + priv->control.set_interface = ac300_ephy_ctl_set_interface; + /* MII is the reset default used until the MAC supplies its interface. */ + priv->interface = PHY_INTERFACE_MODE_MII; + + return &priv->control; +} diff --git a/drivers/net/phy/xpowers/acx00.c b/drivers/net/phy/xpowers/acx00.c new file mode 100644 index 000000000000..d19ba6d8069a --- /dev/null +++ b/drivers/net/phy/xpowers/acx00.c @@ -0,0 +1,633 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * X-Powers AC200/AC300 Ethernet PHY driver + * + * Copyright (C) 2019 Jernej Skrabec + * Copyright (C) 2026 James Hilliard + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../phylib.h" +#include "acx00.h" + +#define ACX00_EPHY_ID 0x00441400 + +#define ACX00_EPHY_CONFIG_CALIBRATION_MASK GENMASK(3, 0) +#define ACX00_EPHY_CONFIG_VARIANT_AC300 BIT(8) +#define ACX00_EPHY_CONFIG_CALIBRATION_LOW BIT(9) + +#define ACX00_PAGE_SELECT_REG 0x1f +#define ACX00_PAGE_SELECT_MASK GENMASK(12, 8) +#define ACX00_PAGE_0 0 +#define ACX00_PAGE_1 1 +#define ACX00_PAGE_2 2 +#define ACX00_PAGE_6 6 +#define ACX00_PAGE_8 8 + +#define ACX00_PAGE0_GLOBAL_CONFIG_REG 0x13 +#define ACX00_PAGE0_XMII_RX_CLOCK_INVERT BIT(12) +#define ACX00_PAGE0_MDI_MODE_MASK GENMASK(1, 0) +#define ACX00_PAGE0_MDI_MODE_AUTO 2 + +#define ACX00_PAGE1_APS_CONTROL_REG 0x12 +#define ACX00_PAGE1_APS_DISABLED_4S_VALUE 0x4824 +#define ACX00_PAGE1_UAPS_CONTROL_REG 0x13 +#define ACX00_PAGE1_UAPS_ENABLE BIT(15) +#define ACX00_PAGE1_INTELLIGENT_EEE_CONTROL_REG 0x17 +#define ACX00_PAGE1_INTELLIGENT_EEE_ENABLE BIT(3) + +#define ACX00_PAGE2_TX_DATA_CONTROL_REG 0x18 +#define ACX00_PAGE2_10BT_FIR_SELECT_MASK GENMASK(14, 12) +#define ACX00_PAGE2_10BT_FIR_SELECT_DEFAULT 0 + +#define ACX00_PAGE6_ADC_CONTROL_REG 0x10 +#define ACX00_PAGE6_ADC_CONTROL_LOW_CAL_VALUE 0x5523 +#define ACX00_PAGE6_AFE_RX_CONTROL_REG 0x13 +#define ACX00_PAGE6_AFE_RX_CONTROL_VALUE 0xf000 +#define ACX00_PAGE6_AFE_EQ_RX_DETECT_CONTROL_REG 0x14 +#define AC200_PAGE6_AFE_EQ_RX_DETECT_VALUE 0x708f +#define AC300_PAGE6_AFE_EQ_RX_DETECT_VALUE 0x708b +#define ACX00_PAGE6_AFE_EQ_RX_DETECT_LOW_CAL_VALUE 0x7809 +#define ACX00_PAGE6_TX_LEVEL_REG 0x15 +#define ACX00_PAGE6_TX_LEVEL_100M_MASK GENMASK(15, 8) +#define ACX00_PAGE6_TX_LEVEL_10M_MASK GENMASK(7, 0) +#define ACX00_PAGE6_TX_LEVEL_VALUE(_100m, _10m) \ + (FIELD_PREP(ACX00_PAGE6_TX_LEVEL_100M_MASK, (_100m)) | \ + FIELD_PREP(ACX00_PAGE6_TX_LEVEL_10M_MASK, (_10m))) +#define ACX00_PAGE6_TX_LEVEL_DEFAULT_VALUE \ + ACX00_PAGE6_TX_LEVEL_VALUE(0x15, 0x30) +#define ACX00_PAGE6_TX_LEVEL_LOW_CAL_VALUE \ + ACX00_PAGE6_TX_LEVEL_VALUE(0x35, 0x33) + +#define ACX00_PAGE8_AFE_CONTROL_REG 0x18 +#define ACX00_PAGE8_AFE_CONTROL_VALUE 0x00bc +#define ACX00_PAGE8_AUTO_CAL_CONTROL_REG 0x1d +#define ACX00_PAGE8_AUTO_CAL_TX_LEVEL_ADJUST_BYPASS BIT(11) +#define ACX00_PAGE8_AUTO_CAL_LOW_CAL_OPAQUE_BITS 0x0044 +#define ACX00_PAGE8_AUTO_CAL_LOW_VALUE \ + (ACX00_PAGE8_AUTO_CAL_TX_LEVEL_ADJUST_BYPASS | \ + ACX00_PAGE8_AUTO_CAL_LOW_CAL_OPAQUE_BITS) + +/* + * Another integration of this exact-ID PHY documents its digital vendor + * register map, which also matches the observed ACx00 reset values. The ACx00 + * analog-page field encodings remain unpublished, so keep those as opaque + * vendor initialization values instead of inventing bit definitions. + */ + +struct acx00_ephy_priv { + struct phy_device *phydev; + struct acx00_ephy_control *control; + /* Serializes package state and multi-register power sequences. */ + struct mutex state_lock; + bool is_ac300; + bool use_low_calibration_tuning; + bool xmii_rx_clock_inverted; +}; + +static int acx00_ephy_read_page(struct phy_device *phydev) +{ + int ret; + + ret = __phy_read(phydev, ACX00_PAGE_SELECT_REG); + if (ret < 0) + return ret; + + return FIELD_GET(ACX00_PAGE_SELECT_MASK, ret); +} + +static int acx00_ephy_write_page(struct phy_device *phydev, int page) +{ + return __phy_write(phydev, ACX00_PAGE_SELECT_REG, + FIELD_PREP(ACX00_PAGE_SELECT_MASK, page)); +} + +static int acx00_ephy_control_power_on(struct acx00_ephy_priv *priv) +{ + lockdep_assert_held(&priv->state_lock); + + return priv->control->power_on(priv->control, + priv->phydev->mdio.addr); +} + +static int acx00_ephy_control_power_off(struct acx00_ephy_priv *priv) +{ + lockdep_assert_held(&priv->state_lock); + + return priv->control->power_off(priv->control); +} + +static int acx00_ephy_set_interface(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + + lockdep_assert_held(&priv->state_lock); + + if (phydev->interface == PHY_INTERFACE_MODE_NA) + return 0; + if (phydev->interface != PHY_INTERFACE_MODE_MII && + phydev->interface != PHY_INTERFACE_MODE_RMII) + return -EINVAL; + + return priv->control->set_interface(priv->control, + phydev->interface); +} + +static void acx00_ephy_control_power_off_warn(struct acx00_ephy_priv *priv) +{ + int ret; + + ret = acx00_ephy_control_power_off(priv); + if (ret) + phydev_warn(priv->phydev, + "failed to power off control block: %pe\n", + ERR_PTR(ret)); +} + +static void acx00_ephy_control_release(void *data) +{ + struct acx00_ephy_priv *priv = data; + + mutex_lock(&priv->state_lock); + acx00_ephy_control_power_off_warn(priv); + mutex_unlock(&priv->state_lock); +} + +static int acx00_ephy_read_nvmem_u16(struct device_node *node, + const char *name, size_t min_len, + u16 *value) +{ + struct nvmem_cell *cell; + size_t i; + size_t len; + u8 *buf; + u16 val = 0; + + cell = of_nvmem_cell_get(node, name); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + buf = nvmem_cell_read(cell, &len); + nvmem_cell_put(cell); + if (IS_ERR(buf)) + return PTR_ERR(buf); + if (len < min_len || len > sizeof(*value)) { + kfree(buf); + return len > sizeof(*value) ? -ERANGE : -EINVAL; + } + + for (i = 0; i < len; i++) + val |= (u16)buf[i] << (8 * i); + kfree(buf); + *value = val; + + return 0; +} + +static int acx00_ephy_init_package(struct phy_device *phydev, + struct acx00_ephy_priv *priv) +{ + struct device *dev = &phydev->mdio.dev; + struct device_node *package_node; + bool selectable; + bool fixed_ac300; + bool has_configuration; + u8 calibration; + u32 base_addr; + u16 configuration = 0; + int ret; + + package_node = of_get_parent(dev->of_node); + if (!package_node) + return -EINVAL; + if (!of_node_name_eq(package_node, "ethernet-phy-package")) { + ret = dev_err_probe(dev, -EINVAL, + "PHY is not in an Ethernet PHY package\n"); + goto out_put_node; + } + + ret = of_property_read_u32(package_node, "reg", &base_addr); + if (ret || base_addr != phydev->mdio.addr) { + ret = dev_err_probe(dev, -EINVAL, + "package and link PHY addresses differ\n"); + goto out_put_node; + } + + selectable = of_device_is_compatible(package_node, + "x-powers,acx00-ephy-package"); + fixed_ac300 = of_device_is_compatible(package_node, + "x-powers,ac300-ephy-package"); + if (!selectable && !fixed_ac300 && + !of_device_is_compatible(package_node, + "x-powers,ac200-ephy-package")) { + ret = dev_err_probe(dev, -EINVAL, + "unsupported Ethernet PHY package\n"); + goto out_put_node; + } + + ret = devm_of_phy_package_join(dev, phydev, 0); + if (ret) + goto out_put_node; + + has_configuration = + of_property_match_string(package_node, "nvmem-cell-names", + "configuration") >= 0; + if (has_configuration) { + ret = acx00_ephy_read_nvmem_u16(package_node, "configuration", + selectable || fixed_ac300 ? 2 : 1, + &configuration); + if (ret) { + ret = dev_err_probe(dev, ret, + "failed to read package configuration\n"); + goto out_put_node; + } + } else if (selectable || fixed_ac300) { + ret = dev_err_probe(dev, -EINVAL, + "package configuration is required\n"); + goto out_put_node; + } + + if (selectable) { + priv->is_ac300 = + configuration & ACX00_EPHY_CONFIG_VARIANT_AC300; + } else { + priv->is_ac300 = fixed_ac300; + if (has_configuration && + !!(configuration & ACX00_EPHY_CONFIG_VARIANT_AC300) != + priv->is_ac300) { + ret = dev_err_probe(dev, -EINVAL, + "configuration does not match package\n"); + goto out_put_node; + } + } + + calibration = FIELD_GET(ACX00_EPHY_CONFIG_CALIBRATION_MASK, + configuration); + + priv->use_low_calibration_tuning = + priv->is_ac300 && + !!(configuration & ACX00_EPHY_CONFIG_CALIBRATION_LOW); + priv->xmii_rx_clock_inverted = + of_property_read_bool(package_node, + "x-powers,xmii-rx-clock-inverted"); + + if (priv->is_ac300) + priv->control = + ac300_ephy_ctl_create(phydev, package_node, + calibration); + else + priv->control = + ac200_ephy_ctl_create(phydev, package_node, + has_configuration, + calibration); + ret = PTR_ERR_OR_ZERO(priv->control); + +out_put_node: + of_node_put(package_node); + return ret; +} + +static int acx00_ephy_disable_autonomous_eee(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + int ret; + + mutex_lock(&priv->state_lock); + ret = phy_modify_paged(phydev, ACX00_PAGE_1, + ACX00_PAGE1_INTELLIGENT_EEE_CONTROL_REG, + ACX00_PAGE1_INTELLIGENT_EEE_ENABLE, 0); + mutex_unlock(&priv->state_lock); + + return ret; +} + +static int acx00_ephy_probe(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + struct acx00_ephy_priv *priv; + int ret; + + if (!dev->of_node) + return -ENODEV; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->phydev = phydev; + mutex_init(&priv->state_lock); + ret = acx00_ephy_init_package(phydev, priv); + if (ret) + return ret; + + phydev->priv = priv; + ret = devm_add_action_or_reset(dev, acx00_ephy_control_release, priv); + if (ret) + return ret; + + mutex_lock(&priv->state_lock); + ret = acx00_ephy_control_power_on(priv); + mutex_unlock(&priv->state_lock); + if (ret) + return dev_err_probe(dev, ret, + "failed to power on control block\n"); + + return 0; +} + +static int acx00_ephy_soft_reset(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + int ret; + + mutex_lock(&priv->state_lock); + + ret = acx00_ephy_set_interface(phydev); + if (ret) + goto out_power_off; + + ret = acx00_ephy_control_power_on(priv); + if (ret) + goto out_power_off; + + /* ACx00 can acknowledge reset in power-down without restarting. */ + ret = genphy_resume(phydev); + if (ret) + goto out_power_off; + + ret = genphy_soft_reset(phydev); + if (ret) + goto out_power_off; + + goto out_unlock; + +out_power_off: + acx00_ephy_control_power_off_warn(priv); +out_unlock: + mutex_unlock(&priv->state_lock); + + return ret; +} + +static int __acx00_ephy_config_init(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + u16 afe_eq_rx_detect = priv->is_ac300 ? + AC300_PAGE6_AFE_EQ_RX_DETECT_VALUE : + AC200_PAGE6_AFE_EQ_RX_DETECT_VALUE; + u16 tx_level_value = ACX00_PAGE6_TX_LEVEL_DEFAULT_VALUE; + u16 global_config; + int oldpage; + int ret; + + lockdep_assert_held(&priv->state_lock); + + global_config = FIELD_PREP(ACX00_PAGE0_MDI_MODE_MASK, + ACX00_PAGE0_MDI_MODE_AUTO); + if (priv->xmii_rx_clock_inverted) + global_config |= ACX00_PAGE0_XMII_RX_CLOCK_INVERT; + + ret = phy_modify_paged(phydev, ACX00_PAGE_0, + ACX00_PAGE0_GLOBAL_CONFIG_REG, + ACX00_PAGE0_XMII_RX_CLOCK_INVERT | + ACX00_PAGE0_MDI_MODE_MASK, global_config); + if (ret) + return ret; + + if (priv->is_ac300 && priv->use_low_calibration_tuning) { + afe_eq_rx_detect = + ACX00_PAGE6_AFE_EQ_RX_DETECT_LOW_CAL_VALUE; + tx_level_value = ACX00_PAGE6_TX_LEVEL_LOW_CAL_VALUE; + } + + oldpage = phy_select_page(phydev, ACX00_PAGE_1); + if (oldpage < 0) + return phy_restore_page(phydev, oldpage, oldpage); + + ret = __phy_write(phydev, ACX00_PAGE1_APS_CONTROL_REG, + ACX00_PAGE1_APS_DISABLED_4S_VALUE); + if (ret) + goto out_restore_page; + ret = __phy_modify(phydev, ACX00_PAGE1_UAPS_CONTROL_REG, + ACX00_PAGE1_UAPS_ENABLE, 0); + if (ret) + goto out_restore_page; + ret = __phy_modify(phydev, ACX00_PAGE1_INTELLIGENT_EEE_CONTROL_REG, + ACX00_PAGE1_INTELLIGENT_EEE_ENABLE, 0); + if (ret) + goto out_restore_page; + + ret = acx00_ephy_write_page(phydev, ACX00_PAGE_2); + if (ret) + goto out_restore_page; + ret = __phy_modify(phydev, ACX00_PAGE2_TX_DATA_CONTROL_REG, + ACX00_PAGE2_10BT_FIR_SELECT_MASK, + FIELD_PREP(ACX00_PAGE2_10BT_FIR_SELECT_MASK, + ACX00_PAGE2_10BT_FIR_SELECT_DEFAULT)); + if (ret) + goto out_restore_page; + + ret = acx00_ephy_write_page(phydev, ACX00_PAGE_6); + if (ret) + goto out_restore_page; + ret = __phy_write(phydev, ACX00_PAGE6_AFE_EQ_RX_DETECT_CONTROL_REG, + afe_eq_rx_detect); + if (ret) + goto out_restore_page; + ret = __phy_write(phydev, ACX00_PAGE6_AFE_RX_CONTROL_REG, + ACX00_PAGE6_AFE_RX_CONTROL_VALUE); + if (ret) + goto out_restore_page; + if (priv->is_ac300 && priv->use_low_calibration_tuning) { + ret = __phy_write(phydev, ACX00_PAGE6_ADC_CONTROL_REG, + ACX00_PAGE6_ADC_CONTROL_LOW_CAL_VALUE); + if (ret) + goto out_restore_page; + } + ret = __phy_write(phydev, ACX00_PAGE6_TX_LEVEL_REG, tx_level_value); + if (ret) + goto out_restore_page; + + ret = acx00_ephy_write_page(phydev, ACX00_PAGE_8); + if (ret) + goto out_restore_page; + if (priv->is_ac300 && priv->use_low_calibration_tuning) { + ret = __phy_write(phydev, ACX00_PAGE8_AUTO_CAL_CONTROL_REG, + ACX00_PAGE8_AUTO_CAL_LOW_VALUE); + if (ret) + goto out_restore_page; + } + ret = __phy_write(phydev, ACX00_PAGE8_AFE_CONTROL_REG, + ACX00_PAGE8_AFE_CONTROL_VALUE); + +out_restore_page: + ret = phy_restore_page(phydev, oldpage, ret); + if (ret) + return ret; + + /* Restore the standard EEE policy retained by phylib across resets. */ + ret = genphy_c45_an_config_eee_aneg(phydev); + if (ret <= 0) + return ret; + + return genphy_restart_aneg(phydev); +} + +static int acx00_ephy_config_init(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + int ret; + + mutex_lock(&priv->state_lock); + ret = __acx00_ephy_config_init(phydev); + if (ret) + acx00_ephy_control_power_off_warn(priv); + mutex_unlock(&priv->state_lock); + + return ret; +} + +static int __acx00_ephy_power_on_and_resume(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + int ret; + + lockdep_assert_held(&phydev->lock); + lockdep_assert_held(&priv->state_lock); + + ret = acx00_ephy_set_interface(phydev); + if (ret) + goto out_power_off; + + ret = acx00_ephy_control_power_on(priv); + if (ret) + goto out_power_off; + + ret = genphy_resume(phydev); + if (ret) + goto out_power_off; + + /* Powering off the control block loses the vendor-page state. */ + ret = __acx00_ephy_config_init(phydev); + if (ret) + goto out_power_off; + + return 0; + +out_power_off: + acx00_ephy_control_power_off_warn(priv); + + return ret; +} + +static int acx00_ephy_resume(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + int ret; + + mutex_lock(&priv->state_lock); + ret = __acx00_ephy_power_on_and_resume(phydev); + mutex_unlock(&priv->state_lock); + + return ret; +} + +static int acx00_ephy_suspend(struct phy_device *phydev) +{ + struct acx00_ephy_priv *priv = phydev->priv; + int resume_ret; + int ret; + + /* The suspend callback is invoked without the phylib lock held. */ + mutex_lock(&phydev->lock); + mutex_lock(&priv->state_lock); + + ret = genphy_suspend(phydev); + if (ret) + goto out_unlock; + + ret = acx00_ephy_control_power_off(priv); + if (ret) { + resume_ret = __acx00_ephy_power_on_and_resume(phydev); + if (!resume_ret) { + /* + * The package reset also loses the standard link settings. + * A failed suspend is not followed by resume, so restore + * advertisement or forced speed/duplex before returning. + */ + resume_ret = genphy_config_aneg(phydev); + if (resume_ret) + acx00_ephy_control_power_off_warn(priv); + } + if (resume_ret) + phydev_warn(phydev, + "failed to recover from suspend error: %pe\n", + ERR_PTR(resume_ret)); + } + +out_unlock: + mutex_unlock(&priv->state_lock); + mutex_unlock(&phydev->lock); + + return ret; +} + +static int acx00_ephy_match_phy_device(struct phy_device *phydev, + const struct phy_driver *phydrv) +{ + struct device_node *node = phydev->mdio.dev.of_node; + struct device_node *package_node; + bool match; + + if (!genphy_match_phy_device(phydev, phydrv) || !node) + return 0; + + /* RK630 reports the same PHY ID, so also match the package identity. */ + package_node = of_get_parent(node); + if (!package_node) + return 0; + match = of_device_is_compatible(package_node, + "x-powers,ac200-ephy-package") || + of_device_is_compatible(package_node, + "x-powers,ac300-ephy-package") || + of_device_is_compatible(package_node, + "x-powers,acx00-ephy-package"); + of_node_put(package_node); + + return match; +} + +static struct phy_driver acx00_ephy_driver[] = { + { + PHY_ID_MATCH_MODEL(ACX00_EPHY_ID), + .name = "X-Powers AC200/AC300 EPHY", + .match_phy_device = acx00_ephy_match_phy_device, + .probe = acx00_ephy_probe, + .read_page = acx00_ephy_read_page, + .write_page = acx00_ephy_write_page, + .soft_reset = acx00_ephy_soft_reset, + .config_init = acx00_ephy_config_init, + .disable_autonomous_eee = acx00_ephy_disable_autonomous_eee, + .suspend = acx00_ephy_suspend, + .resume = acx00_ephy_resume, + }, +}; +module_phy_driver(acx00_ephy_driver); + +static const struct mdio_device_id __maybe_unused acx00_ephy_tbl[] = { + { PHY_ID_MATCH_MODEL(ACX00_EPHY_ID) }, + { } +}; +MODULE_DEVICE_TABLE(mdio, acx00_ephy_tbl); + +MODULE_AUTHOR("James Hilliard "); +MODULE_DESCRIPTION("X-Powers AC200/AC300 Ethernet PHY driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/phy/xpowers/acx00.h b/drivers/net/phy/xpowers/acx00.h new file mode 100644 index 000000000000..7df6084c7a77 --- /dev/null +++ b/drivers/net/phy/xpowers/acx00.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __DRIVERS_NET_PHY_XPOWERS_ACX00_H +#define __DRIVERS_NET_PHY_XPOWERS_ACX00_H + +#include +#include + +#define AC300_EPHY_CONTROL_ADDR_OFFSET 16 + +struct device_node; + +struct acx00_ephy_control { + int (*power_on)(struct acx00_ephy_control *control, + unsigned int phy_addr); + int (*power_off)(struct acx00_ephy_control *control); + int (*set_interface)(struct acx00_ephy_control *control, + phy_interface_t interface); +}; + +struct acx00_ephy_control * +ac200_ephy_ctl_create(struct phy_device *phydev, + struct device_node *package_node, + bool has_calibration, u8 calibration); +struct acx00_ephy_control * +ac300_ephy_ctl_create(struct phy_device *phydev, + struct device_node *package_node, u8 calibration); + +#endif From afabe5e67b67401aab9002014af56cf2a42743d9 Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Wed, 9 Sep 2026 09:36:20 +0530 Subject: [PATCH 0465/2126] octeontx2-pf: report port connector type in ethtool link ksettings otx2_get_link_ksettings() already reports speed, duplex, autoneg, link modes and FEC from CGX firmware shared data, but never fills cmd->base.port. As a result, ethtool does not show the physical connector type even though firmware provides it in fwdata.port. Read the connector type from shared firmware data and expose it via ethtool. Extract only the low 8 bits of the firmware field and validate the value against the standard ethtool PORT_* definitions before publishing it to userspace. Signed-off-by: Hariprasad Kelam Signed-off-by: Ratheesh Kannoth Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260909040621.397255-1-rkannoth@marvell.com Signed-off-by: Jakub Kicinski --- .../marvell/octeontx2/nic/otx2_ethtool.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c index 9bee1b91eeaa..a05dee0085a3 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c @@ -1209,6 +1209,7 @@ static int otx2_get_link_ksettings(struct net_device *netdev, { struct otx2_nic *pfvf = netdev_priv(netdev); struct cgx_fw_data *rsp = NULL; + u8 port; cmd->base.duplex = pfvf->linfo.full_duplex; cmd->base.speed = pfvf->linfo.speed; @@ -1231,6 +1232,23 @@ static int otx2_get_link_ksettings(struct net_device *netdev, OTX2_MODE_SUPPORTED, cmd); otx2_get_fec_info(rsp->fwdata.supported_fec, OTX2_MODE_SUPPORTED, cmd); + + port = FIELD_GET(GENMASK(7, 0), rsp->fwdata.port); + switch (port) { + case PORT_TP: + case PORT_AUI: + case PORT_MII: + case PORT_FIBRE: + case PORT_BNC: + case PORT_DA: + case PORT_NONE: + cmd->base.port = port; + break; + default: + cmd->base.port = PORT_OTHER; + break; + } + return 0; } From aa5ec571b93ff8a8d7c0716d6a70b45c02756263 Mon Sep 17 00:00:00 2001 From: Alexandra Winter Date: Thu, 10 Sep 2026 18:29:19 +0200 Subject: [PATCH 0466/2126] net/iucv: Add lock nesting annotation in iucv_sock_close() iucv_sock_close() acquires lock_sock(sk) and then, when the socket is in IUCV_LISTEN state, calls iucv_sock_cleanup_listen() which acquires lock_sock(child_sk) for each pending child socket. Moreover iucv_sock_close(child_sk) is called on the pending child sockets. Avoid lockdep warning by using lock_sock_nested() in iucv_sock_close(). Split off __iucv_sock_close(), so iucv_sock_cleanup_listen() can call it without nesting. This is a missing lockdep annotation - not a real deadlock. Example warning: [ 6690.906930] ============================================ [ 6690.906935] WARNING: possible recursive locking detected [ 6690.906942] 7.3.0-rc1net_KCSAN_KASAN-00240-g641d03105cc0 #23 Not tainted [ 6690.906948] -------------------------------------------- [ 6690.906953] afiucv_test_loc/5183 is trying to acquire lock: [ 6690.906959] 000601ad13f20a78 (sk_lock-IUCV){+.+.}-{0:0}, at: iucv_accept_dequeue+0xdc/0x340 [af_iucv] [ 6690.906984] but task is already holding lock: [ 6690.906989] 000601ad1c115278 (sk_lock-IUCV){+.+.}-{0:0}, at: iucv_sock_close+0x82/0x7d0 [af_iucv] [ 6690.907006] other info that might help us debug this: [ 6690.907010] Possible unsafe locking scenario: [ 6690.907014] CPU0 [ 6690.907018] ---- [ 6690.907021] lock(sk_lock-IUCV); [ 6690.907028] lock(sk_lock-IUCV); [ 6690.907034] *** DEADLOCK *** [ 6690.907038] May be due to missing lock nesting notation [ 6690.907043] locks held by afiucv_test_loc/5183: 2, last CPU#0: [ 6690.907085] #0: 000601ad137a5550 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3}, at: __sock_release+0x7e/0x230 [ 6690.907109] #1: 000601ad1c115278 (sk_lock-IUCV){+.+.}-{0:0}, at: iucv_sock_close+0x82/0x7d0 [af_iucv] [ 6690.907127] stack backtrace: [ 6690.907135] CPU: 0 UID: 0 PID: 5183 Comm: afiucv_test_loc Kdump: loaded Not tainted 7.3.0-rc1net_KCSAN_KASAN-00240-g641d03105cc0 #23 PREEMPT [ 6690.907140] Hardware name: IBM 8561 T01 703 (z/VM 7.4.0) [ 6690.907142] Call Trace: [ 6690.907144] [<00061ab555fd6208>] dump_stack_lvl+0xe8/0x140 [ 6690.907151] [<00061ab55623a110>] print_deadlock_bug+0x340/0x350 [ 6690.907156] [<00061ab55623f768>] __lock_acquire+0x11b8/0x15d0 [ 6690.907159] [<00061ab55623fc9c>] lock_acquire.part.0+0x11c/0x290 [ 6690.907162] [<00061ab55623fec4>] lock_acquire+0xb4/0x1e0 [ 6690.907164] [<00061ab5580d6b96>] lock_sock_nested+0x46/0xf0 [ 6690.907167] [<00061ab4d66e38dc>] iucv_accept_dequeue+0xdc/0x340 [af_iucv] [ 6690.907171] [<00061ab4d66e541c>] iucv_sock_close+0xdc/0x7d0 [af_iucv] [ 6690.907174] [<00061ab4d66e5b62>] iucv_sock_release+0x52/0x130 [af_iucv] [ 6690.907177] [<00061ab5580c5b24>] __sock_release+0xa4/0x230 [ 6690.907180] [<00061ab5580c5cdc>] sock_close+0x2c/0x40 [ 6690.907183] [<00061ab556ac7a00>] __fput+0x2f0/0x880 [ 6690.907187] [<00061ab556ac8cc0>] fput_close_sync+0xd0/0x1c0 [ 6690.907189] [<00061ab556abbc70>] __s390x_sys_close+0x90/0xf0 [ 6690.907192] [<00061ab55894df0e>] __do_syscall+0x1be/0x5a0 [ 6690.907196] [<00061ab558976a7a>] system_call+0x72/0x90 [ 6690.907200] INFO: lockdep is turned off. Signed-off-by: Alexandra Winter Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260910162919.2100124-1-wintera@linux.ibm.com Signed-off-by: Jakub Kicinski --- net/iucv/af_iucv.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c index db261ecd19af..5ba875798aa4 100644 --- a/net/iucv/af_iucv.c +++ b/net/iucv/af_iucv.c @@ -90,7 +90,7 @@ do { \ static struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock); static void iucv_sock_kill(struct sock *sk); -static void iucv_sock_close(struct sock *sk); +static void __iucv_sock_close(struct sock *sk); static void afiucv_hs_callback_txnotify(struct sock *sk, enum iucv_tx_notify); @@ -302,7 +302,9 @@ static void iucv_sock_cleanup_listen(struct sock *parent) /* Close non-accepted connections */ while ((sk = iucv_accept_dequeue(parent, NULL))) { - iucv_sock_close(sk); + lock_sock(sk); + __iucv_sock_close(sk); + release_sock(sk); iucv_sock_kill(sk); } @@ -394,15 +396,16 @@ static int iucv_send_ctrl(struct sock *sk, u8 flags) return err; } -/* Close an IUCV socket */ -static void iucv_sock_close(struct sock *sk) +/** + * __iucv_sock_close() - close socket, caller holds lock_sock(sk) + * @sk: network socket + */ +static void __iucv_sock_close(struct sock *sk) { struct iucv_sock *iucv = iucv_sk(sk); unsigned long timeo; int err = 0; - lock_sock(sk); - switch (sk->sk_state) { case IUCV_LISTEN: iucv_sock_cleanup_listen(sk); @@ -454,7 +457,12 @@ static void iucv_sock_close(struct sock *sk) /* mark socket for deletion by iucv_sock_kill() */ sock_set_flag(sk, SOCK_ZAPPED); +} +static void iucv_sock_close(struct sock *sk) +{ + lock_sock_nested(sk, SINGLE_DEPTH_NESTING); + __iucv_sock_close(sk); release_sock(sk); } From f7cd8d2dc74d7926df91214237f83e67113b7ea1 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Sat, 12 Sep 2026 00:54:42 +0000 Subject: [PATCH 0467/2126] sit: do not report an error from ipip6_fill_info() ipip6_fill_info() returns -ENODEV if tunnel->sit_parms is NULL. This can not happen yet: sit_parms is only cleared from ipip6_dev_free(), the priv_destructor, which runs long after RTM_DELLINK has been built. Returning an error from a fill_info() handler is still a trap, because rtnl_dump_ifinfo() stops at the first failure and propagates it, letting one device hide all the remaining ones. Return 0 instead, there is nothing to report for a device that is going away. Signed-off-by: Eric Dumazet Reviewed-by: Xuanqiang Luo Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260912005442.1795813-1-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/sit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 14ba3cfb304a..a7ec800216ad 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1853,9 +1853,10 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) rcu_read_lock(); parm = rcu_dereference(tunnel->sit_parms); + /* If the device is being dismantled, there is nothing to report. */ if (!parm) { rcu_read_unlock(); - return -ENODEV; + return 0; } if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || From ce71c433395e040d83c77e39f1d98cd813d1f6af Mon Sep 17 00:00:00 2001 From: Jiangshan Yi Date: Thu, 10 Sep 2026 18:41:02 +0800 Subject: [PATCH 0468/2126] octeontx2-af: consolidate RVU AFVF device id definitions commit f695390ea639 ("octeontx2-af: Fix limiting SRIOV VF count logic") added a local PCI_DEVID_OCTEONTX2_RVU_AFVF define in rvu.c, although the same value was already defined twice elsewhere: as RVU_LBK_VF_DEVID in af/rvu.h and as PCI_DEVID_OCTEONTX2_RVU_AFVF in nic/otx2_common.h. Move the definition into the "PCI device IDs" block in af/rvu.h, rename RVU_LBK_VF_DEVID to match the PCI_DEVID_* naming convention of its peers, and drop the redundant copies in rvu.c and nic/otx2_common.h, the latter already including through the af include path. No functional change. Signed-off-by: Jiangshan Yi Acked-by: Ratheesh Kannoth Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260910104102.590989-1-yijiangshan@kylinos.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 2 -- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 4 ++-- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c index b8f81e068f53..30e148291581 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c @@ -3468,8 +3468,6 @@ err: return ret; } -#define PCI_DEVID_OCTEONTX2_RVU_AFVF 0xA0F8 - static int rvu_enable_sriov(struct rvu *rvu) { struct pci_dev *pdev = rvu->pdev; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h index 9afb7ac8969b..fb4870cd18e9 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h @@ -22,6 +22,7 @@ /* PCI device IDs */ #define PCI_DEVID_OCTEONTX2_RVU_AF 0xA065 +#define PCI_DEVID_OCTEONTX2_RVU_AFVF 0xA0F8 #define PCI_DEVID_OCTEONTX2_LBK 0xA061 /* Subsystem Device ID */ @@ -882,11 +883,10 @@ static inline bool is_rvu_supports_nix1(struct rvu *rvu) /* Function Prototypes * RVU */ -#define RVU_LBK_VF_DEVID 0xA0F8 static inline bool is_lbk_vf(struct rvu *rvu, u16 pcifunc) { return (!(pcifunc & ~RVU_PFVF_FUNC_MASK) && - (rvu->vf_devid == RVU_LBK_VF_DEVID)); + (rvu->vf_devid == PCI_DEVID_OCTEONTX2_RVU_AFVF)); } static inline bool is_vf(u16 pcifunc) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h index eecee612b7b2..5850bc1870a1 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h @@ -42,7 +42,6 @@ /* PCI device IDs */ #define PCI_DEVID_OCTEONTX2_RVU_PF 0xA063 #define PCI_DEVID_OCTEONTX2_RVU_VF 0xA064 -#define PCI_DEVID_OCTEONTX2_RVU_AFVF 0xA0F8 #define PCI_SUBSYS_DEVID_96XX_RVU_PFVF 0xB200 #define PCI_SUBSYS_DEVID_CN10K_A_RVU_PFVF 0xB900 From 649936a0daaa5ccd50f66b4218775cfcebaa90a9 Mon Sep 17 00:00:00 2001 From: Juanlu Herrero Date: Wed, 9 Sep 2026 14:51:23 -0500 Subject: [PATCH 0469/2126] selftests: net: fix get_refill_ring_size() to use its local variable In preparation for multi-threaded rss selftests, fix get_refill_ring_size() to use its local `size` variable instead of assigning to the file-global `ring_size`. Signed-off-by: Juanlu Herrero Link: https://patch.msgid.link/20260909-iou-zcrx-v7-1-6b5d48a2a922@fastmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hw/iou-zcrx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c index f6a8fc5fac24..df6b62204343 100644 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c @@ -132,10 +132,10 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries) { size_t size; - ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe); + size = rq_entries * sizeof(struct io_uring_zcrx_rqe); /* add space for the header (head/tail/etc.) */ - ring_size += page_size; - return ALIGN_UP(ring_size, page_size); + size += page_size; + return ALIGN_UP(size, page_size); } static void setup_zcrx(struct io_uring *ring) From 3fb2892382446156ef613603200eab6c82a0a033 Mon Sep 17 00:00:00 2001 From: Juanlu Herrero Date: Wed, 9 Sep 2026 14:51:24 -0500 Subject: [PATCH 0470/2126] selftests: net: remove unused variable in process_recvzc() Remove the unused `sqe` variable in preparation for the multiqueue rss selftest changes to process_recvzc() in the following commits. Signed-off-by: Juanlu Herrero Link: https://patch.msgid.link/20260909-iou-zcrx-v7-2-6b5d48a2a922@fastmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hw/iou-zcrx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c index df6b62204343..c6dbd0ad5368 100644 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c @@ -269,7 +269,6 @@ static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe) unsigned rq_mask = rq_ring.ring_entries - 1; struct io_uring_zcrx_cqe *rcqe; struct io_uring_zcrx_rqe *rqe; - struct io_uring_sqe *sqe; uint64_t mask; char *data; ssize_t n; From 72ac4f0c53987284880e5a94a5c91d71ec5091bf Mon Sep 17 00:00:00 2001 From: Juanlu Herrero Date: Wed, 9 Sep 2026 14:51:25 -0500 Subject: [PATCH 0471/2126] selftests: net: refactor server state into struct thread_ctx Move server-side state (io_uring ring, zcrx area, refill ring, receive tracking) from global variables into a local struct thread_ctx. This is a pure refactor with no behavior change: run_server still allocates a single context on the stack and runs single-threaded, using io_uring accept and recvzc as before. This prepares the ground for the multithread server support in the following commits, which spawns N worker threads each with their own struct thread_ctx. Reviewed-by: David Wei Signed-off-by: Juanlu Herrero Link: https://patch.msgid.link/20260909-iou-zcrx-v7-3-6b5d48a2a922@fastmail.com Signed-off-by: Jakub Kicinski --- .../selftests/drivers/net/hw/iou-zcrx.c | 156 +++++++++--------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c index c6dbd0ad5368..9b62fd0703e6 100644 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c @@ -87,14 +87,18 @@ static unsigned int cfg_rx_buf_len; static bool cfg_dry_run; static char *payload; -static void *area_ptr; -static void *ring_ptr; -static size_t ring_size; -static struct io_uring_zcrx_rq rq_ring; -static unsigned long area_token; -static int connfd; -static bool stop; -static size_t received; + +struct thread_ctx { + struct io_uring ring; + void *area_ptr; + void *ring_ptr; + size_t ring_size; + struct io_uring_zcrx_rq rq_ring; + unsigned long area_token; + int connfd; + bool stop; + size_t received; +}; static unsigned long gettimeofday_ms(void) { @@ -138,7 +142,7 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries) return ALIGN_UP(size, page_size); } -static void setup_zcrx(struct io_uring *ring) +static void setup_zcrx(struct thread_ctx *ctx) { unsigned int ifindex; unsigned int rq_entries = 4096; @@ -149,44 +153,44 @@ static void setup_zcrx(struct io_uring *ring) error(1, 0, "bad interface name: %s", cfg_ifname); if (cfg_rx_buf_len && cfg_rx_buf_len != page_size) { - area_ptr = mmap(NULL, - AREA_SIZE, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | - MAP_HUGETLB | MAP_HUGE_2MB, - -1, - 0); - if (area_ptr == MAP_FAILED) { + ctx->area_ptr = mmap(NULL, + AREA_SIZE, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | + MAP_HUGETLB | MAP_HUGE_2MB, + -1, + 0); + if (ctx->area_ptr == MAP_FAILED) { printf("Can't allocate huge pages\n"); exit(SKIP_CODE); } } else { - area_ptr = mmap(NULL, - AREA_SIZE, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, - 0, - 0); - if (area_ptr == MAP_FAILED) + ctx->area_ptr = mmap(NULL, + AREA_SIZE, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + 0, + 0); + if (ctx->area_ptr == MAP_FAILED) error(1, 0, "mmap(): zero copy area"); } - ring_size = get_refill_ring_size(rq_entries); - ring_ptr = mmap(NULL, - ring_size, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, - 0, - 0); + ctx->ring_size = get_refill_ring_size(rq_entries); + ctx->ring_ptr = mmap(NULL, + ctx->ring_size, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + 0, + 0); struct io_uring_region_desc region_reg = { - .size = ring_size, - .user_addr = (__u64)(unsigned long)ring_ptr, + .size = ctx->ring_size, + .user_addr = (__u64)(unsigned long)ctx->ring_ptr, .flags = IORING_MEM_REGION_TYPE_USER, }; struct io_uring_zcrx_area_reg area_reg = { - .addr = (__u64)(unsigned long)area_ptr, + .addr = (__u64)(unsigned long)ctx->area_ptr, .len = AREA_SIZE, .flags = 0, }; @@ -200,7 +204,7 @@ static void setup_zcrx(struct io_uring *ring) .rx_buf_len = cfg_rx_buf_len, }; - ret = io_uring_register_ifq(ring, (void *)®); + ret = io_uring_register_ifq(&ctx->ring, (void *)®); if (cfg_rx_buf_len && (ret == -EINVAL || ret == -EOPNOTSUPP || ret == -ERANGE)) { printf("Large chunks are not supported %i\n", ret); @@ -209,64 +213,64 @@ static void setup_zcrx(struct io_uring *ring) error(1, 0, "io_uring_register_ifq(): %d", ret); } - rq_ring.khead = (unsigned int *)((char *)ring_ptr + reg.offsets.head); - rq_ring.ktail = (unsigned int *)((char *)ring_ptr + reg.offsets.tail); - rq_ring.rqes = (struct io_uring_zcrx_rqe *)((char *)ring_ptr + reg.offsets.rqes); - rq_ring.rq_tail = 0; - rq_ring.ring_entries = reg.rq_entries; + ctx->rq_ring.khead = (unsigned int *)((char *)ctx->ring_ptr + reg.offsets.head); + ctx->rq_ring.ktail = (unsigned int *)((char *)ctx->ring_ptr + reg.offsets.tail); + ctx->rq_ring.rqes = (struct io_uring_zcrx_rqe *)((char *)ctx->ring_ptr + reg.offsets.rqes); + ctx->rq_ring.rq_tail = 0; + ctx->rq_ring.ring_entries = reg.rq_entries; - area_token = area_reg.rq_area_token; + ctx->area_token = area_reg.rq_area_token; } -static void add_accept(struct io_uring *ring, int sockfd) +static void add_accept(struct thread_ctx *ctx, int sockfd) { struct io_uring_sqe *sqe; - sqe = io_uring_get_sqe(ring); + sqe = io_uring_get_sqe(&ctx->ring); io_uring_prep_accept(sqe, sockfd, NULL, NULL, 0); sqe->user_data = 1; } -static void add_recvzc(struct io_uring *ring, int sockfd) +static void add_recvzc(struct thread_ctx *ctx, int sockfd) { struct io_uring_sqe *sqe; - sqe = io_uring_get_sqe(ring); + sqe = io_uring_get_sqe(&ctx->ring); io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, 0, 0); sqe->ioprio |= IORING_RECV_MULTISHOT; sqe->user_data = 2; } -static void add_recvzc_oneshot(struct io_uring *ring, int sockfd, size_t len) +static void add_recvzc_oneshot(struct thread_ctx *ctx, int sockfd, size_t len) { struct io_uring_sqe *sqe; - sqe = io_uring_get_sqe(ring); + sqe = io_uring_get_sqe(&ctx->ring); io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, len, 0); sqe->ioprio |= IORING_RECV_MULTISHOT; sqe->user_data = 2; } -static void process_accept(struct io_uring *ring, struct io_uring_cqe *cqe) +static void process_accept(struct thread_ctx *ctx, struct io_uring_cqe *cqe) { if (cqe->res < 0) error(1, 0, "accept()"); - if (connfd) + if (ctx->connfd) error(1, 0, "Unexpected second connection"); - connfd = cqe->res; + ctx->connfd = cqe->res; if (cfg_oneshot) - add_recvzc_oneshot(ring, connfd, page_size); + add_recvzc_oneshot(ctx, ctx->connfd, page_size); else - add_recvzc(ring, connfd); + add_recvzc(ctx, ctx->connfd); } -static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe) +static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe) { - unsigned rq_mask = rq_ring.ring_entries - 1; + unsigned int rq_mask = ctx->rq_ring.ring_entries - 1; struct io_uring_zcrx_cqe *rcqe; struct io_uring_zcrx_rqe *rqe; uint64_t mask; @@ -275,7 +279,7 @@ static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe) int i; if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs == 0) { - stop = true; + ctx->stop = true; return; } @@ -284,56 +288,56 @@ static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe) if (cfg_oneshot) { if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs) { - add_recvzc_oneshot(ring, connfd, page_size); + add_recvzc_oneshot(ctx, ctx->connfd, page_size); cfg_oneshot_recvs--; } } else if (!(cqe->flags & IORING_CQE_F_MORE)) { - add_recvzc(ring, connfd); + add_recvzc(ctx, ctx->connfd); } rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1); n = cqe->res; mask = (1ULL << IORING_ZCRX_AREA_SHIFT) - 1; - data = (char *)area_ptr + (rcqe->off & mask); + data = (char *)ctx->area_ptr + (rcqe->off & mask); for (i = 0; i < n; i++) { - if (*(data + i) != payload[(received + i)]) + if (*(data + i) != payload[(ctx->received + i)]) error(1, 0, "payload mismatch at %d", i); } - received += n; + ctx->received += n; - rqe = &rq_ring.rqes[(rq_ring.rq_tail & rq_mask)]; - rqe->off = (rcqe->off & ~IORING_ZCRX_AREA_MASK) | area_token; + rqe = &ctx->rq_ring.rqes[(ctx->rq_ring.rq_tail & rq_mask)]; + rqe->off = (rcqe->off & ~IORING_ZCRX_AREA_MASK) | ctx->area_token; rqe->len = cqe->res; - io_uring_smp_store_release(rq_ring.ktail, ++rq_ring.rq_tail); + io_uring_smp_store_release(ctx->rq_ring.ktail, ++ctx->rq_ring.rq_tail); } -static void server_loop(struct io_uring *ring) +static void server_loop(struct thread_ctx *ctx) { struct io_uring_cqe *cqe; unsigned int count = 0; unsigned int head; int i, ret; - io_uring_submit_and_wait(ring, 1); + io_uring_submit_and_wait(&ctx->ring, 1); - io_uring_for_each_cqe(ring, head, cqe) { + io_uring_for_each_cqe(&ctx->ring, head, cqe) { if (cqe->user_data == 1) - process_accept(ring, cqe); + process_accept(ctx, cqe); else if (cqe->user_data == 2) - process_recvzc(ring, cqe); + process_recvzc(ctx, cqe); else error(1, 0, "unknown cqe"); count++; } - io_uring_cq_advance(ring, count); + io_uring_cq_advance(&ctx->ring, count); } static void run_server(void) { + struct thread_ctx ctx = {}; unsigned int flags = 0; - struct io_uring ring; int fd, enable, ret; uint64_t tstop; @@ -356,22 +360,22 @@ static void run_server(void) flags |= IORING_SETUP_SUBMIT_ALL; flags |= IORING_SETUP_CQE32; - io_uring_queue_init(512, &ring, flags); + io_uring_queue_init(512, &ctx.ring, flags); - setup_zcrx(&ring); + setup_zcrx(&ctx); if (cfg_dry_run) return; if (listen(fd, 1024) < 0) error(1, 0, "listen()"); - add_accept(&ring, fd); + add_accept(&ctx, fd); tstop = gettimeofday_ms() + 5000; - while (!stop && gettimeofday_ms() < tstop) - server_loop(&ring); + while (!ctx.stop && gettimeofday_ms() < tstop) + server_loop(&ctx); - if (!stop) + if (!ctx.stop) error(1, 0, "test failed\n"); } From 2801895746294168cbf254d5f96372c092576101 Mon Sep 17 00:00:00 2001 From: Juanlu Herrero Date: Wed, 9 Sep 2026 14:51:26 -0500 Subject: [PATCH 0472/2126] selftests: net: add multithread client support to iou-zcrx Add pthreads to the iou-zcrx client so that multiple connections can be established simultaneously. Each client thread connects to the server and sends its payload independently. Introduce the -t option to control the number of threads (default 1), preserving backwards compatibility with existing tests. Reviewed-by: David Wei Signed-off-by: Juanlu Herrero Link: https://patch.msgid.link/20260909-iou-zcrx-v7-4-6b5d48a2a922@fastmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/Makefile | 2 +- .../selftests/drivers/net/hw/iou-zcrx.c | 35 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index bd3b8d2fa47e..69be4d052ef5 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -97,5 +97,5 @@ include ../../../net/ynl.mk include ../../../net/bpf.mk ifeq ($(HAS_IOURING_ZCRX),y) -$(OUTPUT)/iou-zcrx: LDLIBS += -luring +$(OUTPUT)/iou-zcrx: LDLIBS += -luring -lpthread endif diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c index 9b62fd0703e6..f793a6c04e41 100644 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,7 @@ static int cfg_send_size = SEND_SIZE; static struct sockaddr_in6 cfg_addr; static unsigned int cfg_rx_buf_len; static bool cfg_dry_run; +static int cfg_num_threads = 1; static char *payload; @@ -379,7 +381,7 @@ static void run_server(void) error(1, 0, "test failed\n"); } -static void run_client(void) +static void *client_worker(void *arg) { ssize_t to_send = cfg_send_size; ssize_t sent = 0; @@ -405,12 +407,36 @@ static void run_client(void) } close(fd); + return NULL; +} + +static void run_client(void) +{ + int total_conns = cfg_num_threads * cfg_num_threads; + pthread_t *threads; + int i, ret; + + threads = calloc(total_conns, sizeof(*threads)); + if (!threads) + error(1, 0, "calloc()"); + + for (i = 0; i < total_conns; i++) { + ret = pthread_create(&threads[i], NULL, client_worker, NULL); + if (ret) + error(1, ret, "pthread_create()"); + } + + for (i = 0; i < total_conns; i++) + pthread_join(threads[i], NULL); + + free(threads); } static void usage(const char *filepath) { error(1, 0, "Usage: %s (-4|-6) (-s|-c) -h -p " - "-l -i -q", filepath); + "-l -i -q -t", + filepath); } static void parse_opts(int argc, char **argv) @@ -428,7 +454,7 @@ static void parse_opts(int argc, char **argv) usage(argv[0]); cfg_payload_len = max_payload_len; - while ((c = getopt(argc, argv, "sch:p:l:i:q:o:z:x:d")) != -1) { + while ((c = getopt(argc, argv, "sch:p:l:i:q:o:z:x:dt:")) != -1) { switch (c) { case 's': if (cfg_client) @@ -469,6 +495,9 @@ static void parse_opts(int argc, char **argv) case 'd': cfg_dry_run = true; break; + case 't': + cfg_num_threads = strtoul(optarg, NULL, 0); + break; } } From 5d3416ebe55568ae84021606c2b1d8ec0ebd7feb Mon Sep 17 00:00:00 2001 From: Juanlu Herrero Date: Wed, 9 Sep 2026 14:51:27 -0500 Subject: [PATCH 0473/2126] selftests: net: add multithread server support to iou-zcrx Run the iou-zcrx server as N worker threads, each owning one receive queue with its own io_uring and zero-copy receive (zcrx) ifq, so the test can exercise multi-queue zero-copy receive. The main thread owns the listening socket, accepts connections, and dispatches each to the worker owning the queue it landed on by matching SO_INCOMING_NAPI_ID against per-queue NAPI IDs. Signed-off-by: Juanlu Herrero Link: https://patch.msgid.link/20260909-iou-zcrx-v7-5-6b5d48a2a922@fastmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/Makefile | 5 +- .../selftests/drivers/net/hw/iou-zcrx.c | 278 +++++++++++++----- 2 files changed, 210 insertions(+), 73 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 69be4d052ef5..8aebdc6feb17 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -18,10 +18,6 @@ else $(warning excluding iouring tests, liburing not installed or too old) endif -TEST_GEN_FILES := \ - $(COND_GEN_FILES) \ -# end of TEST_GEN_FILES - TEST_PROGS = \ csum.py \ devlink_rate_cross_esw.py \ @@ -80,6 +76,7 @@ TEST_INCLUDES := \ YNL_GEN_FILES := \ ncdevmem \ toeplitz \ + $(COND_GEN_FILES) \ # end of YNL_GEN_FILES TEST_GEN_FILES += $(YNL_GEN_FILES) TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c)) diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c index f793a6c04e41..91b025a8771e 100644 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c @@ -38,6 +38,8 @@ #include #include +#include +#include "netdev-user.h" #define SKIP_CODE 42 @@ -90,6 +92,8 @@ static int cfg_num_threads = 1; static char *payload; +#define MAX_CONNS_PER_THREAD 64 + struct thread_ctx { struct io_uring ring; void *area_ptr; @@ -97,9 +101,15 @@ struct thread_ctx { size_t ring_size; struct io_uring_zcrx_rq rq_ring; unsigned long area_token; - int connfd; - bool stop; - size_t received; + int queue_id; + int napi_id; + pthread_barrier_t *setup_done; + pthread_barrier_t *dispatch_done; + + int connfds[MAX_CONNS_PER_THREAD]; + size_t received[MAX_CONNS_PER_THREAD]; + int oneshot_recvs[MAX_CONNS_PER_THREAD]; + int nr_conns; }; static unsigned long gettimeofday_ms(void) @@ -146,8 +156,8 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries) static void setup_zcrx(struct thread_ctx *ctx) { + unsigned int rq_entries = AREA_SIZE / page_size; unsigned int ifindex; - unsigned int rq_entries = 4096; int ret; ifindex = if_nametoindex(cfg_ifname); @@ -199,7 +209,7 @@ static void setup_zcrx(struct thread_ctx *ctx) struct t_io_uring_zcrx_ifq_reg reg = { .if_idx = ifindex, - .if_rxq = cfg_queue_id, + .if_rxq = ctx->queue_id, .rq_entries = rq_entries, .area_ptr = (__u64)(unsigned long)&area_reg, .region_ptr = (__u64)(unsigned long)®ion_reg, @@ -224,53 +234,32 @@ static void setup_zcrx(struct thread_ctx *ctx) ctx->area_token = area_reg.rq_area_token; } -static void add_accept(struct thread_ctx *ctx, int sockfd) +static void add_recvzc(struct thread_ctx *ctx, int conn_idx) { struct io_uring_sqe *sqe; sqe = io_uring_get_sqe(&ctx->ring); - io_uring_prep_accept(sqe, sockfd, NULL, NULL, 0); - sqe->user_data = 1; -} - -static void add_recvzc(struct thread_ctx *ctx, int sockfd) -{ - struct io_uring_sqe *sqe; - - sqe = io_uring_get_sqe(&ctx->ring); - - io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, 0, 0); + io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, ctx->connfds[conn_idx], + NULL, 0, 0); sqe->ioprio |= IORING_RECV_MULTISHOT; - sqe->user_data = 2; + sqe->user_data = conn_idx; } -static void add_recvzc_oneshot(struct thread_ctx *ctx, int sockfd, size_t len) +static void add_recvzc_oneshot(struct thread_ctx *ctx, int conn_idx, size_t len) { struct io_uring_sqe *sqe; sqe = io_uring_get_sqe(&ctx->ring); - io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, len, 0); + io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, ctx->connfds[conn_idx], + NULL, len, 0); sqe->ioprio |= IORING_RECV_MULTISHOT; - sqe->user_data = 2; + sqe->user_data = conn_idx; } -static void process_accept(struct thread_ctx *ctx, struct io_uring_cqe *cqe) -{ - if (cqe->res < 0) - error(1, 0, "accept()"); - if (ctx->connfd) - error(1, 0, "Unexpected second connection"); - - ctx->connfd = cqe->res; - if (cfg_oneshot) - add_recvzc_oneshot(ctx, ctx->connfd, page_size); - else - add_recvzc(ctx, ctx->connfd); -} - -static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe) +static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe, + int conn_idx) { unsigned int rq_mask = ctx->rq_ring.ring_entries - 1; struct io_uring_zcrx_cqe *rcqe; @@ -280,8 +269,9 @@ static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe) ssize_t n; int i; - if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs == 0) { - ctx->stop = true; + if (cqe->res == 0 && cqe->flags == 0 && + ctx->oneshot_recvs[conn_idx] == 0) { + ctx->nr_conns--; return; } @@ -289,12 +279,14 @@ static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe) error(1, 0, "recvzc(): %d", cqe->res); if (cfg_oneshot) { - if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs) { - add_recvzc_oneshot(ctx, ctx->connfd, page_size); - cfg_oneshot_recvs--; + if (cqe->res == 0 && cqe->flags == 0 && + ctx->oneshot_recvs[conn_idx]) { + add_recvzc_oneshot(ctx, conn_idx, page_size); + ctx->oneshot_recvs[conn_idx]--; + return; } } else if (!(cqe->flags & IORING_CQE_F_MORE)) { - add_recvzc(ctx, ctx->connfd); + add_recvzc(ctx, conn_idx); } rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1); @@ -304,10 +296,10 @@ static void process_recvzc(struct thread_ctx *ctx, struct io_uring_cqe *cqe) data = (char *)ctx->area_ptr + (rcqe->off & mask); for (i = 0; i < n; i++) { - if (*(data + i) != payload[(ctx->received + i)]) + if (*(data + i) != payload[(ctx->received[conn_idx] + i)]) error(1, 0, "payload mismatch at %d", i); } - ctx->received += n; + ctx->received[conn_idx] += n; rqe = &ctx->rq_ring.rqes[(ctx->rq_ring.rq_tail & rq_mask)]; rqe->off = (rcqe->off & ~IORING_ZCRX_AREA_MASK) | ctx->area_token; @@ -320,28 +312,137 @@ static void server_loop(struct thread_ctx *ctx) struct io_uring_cqe *cqe; unsigned int count = 0; unsigned int head; - int i, ret; io_uring_submit_and_wait(&ctx->ring, 1); io_uring_for_each_cqe(&ctx->ring, head, cqe) { - if (cqe->user_data == 1) - process_accept(ctx, cqe); - else if (cqe->user_data == 2) - process_recvzc(ctx, cqe); - else - error(1, 0, "unknown cqe"); + process_recvzc(ctx, cqe, cqe->user_data); count++; } io_uring_cq_advance(&ctx->ring, count); } +static void *server_worker(void *arg) +{ + struct io_uring_params params = { }; + struct thread_ctx *ctx = arg; + uint64_t tstop; + int nr_conns; + int i; + + params.flags |= IORING_SETUP_COOP_TASKRUN; + params.flags |= IORING_SETUP_SINGLE_ISSUER; + params.flags |= IORING_SETUP_DEFER_TASKRUN; + params.flags |= IORING_SETUP_SUBMIT_ALL; + params.flags |= IORING_SETUP_CQE32; + params.flags |= IORING_SETUP_CQSIZE; + params.cq_entries = AREA_SIZE / page_size; + + io_uring_queue_init_params(512, &ctx->ring, ¶ms); + setup_zcrx(ctx); + + if (cfg_dry_run) + return NULL; + + pthread_barrier_wait(ctx->setup_done); + pthread_barrier_wait(ctx->dispatch_done); + + nr_conns = ctx->nr_conns; + + for (i = 0; i < ctx->nr_conns; i++) { + if (cfg_oneshot) { + ctx->oneshot_recvs[i] = cfg_oneshot_recvs; + add_recvzc_oneshot(ctx, i, page_size); + } else { + add_recvzc(ctx, i); + } + } + + tstop = gettimeofday_ms() + 5000; + while (ctx->nr_conns > 0 && gettimeofday_ms() < tstop) + server_loop(ctx); + + if (ctx->nr_conns != 0) + error(1, 0, "test failed: %d connections incomplete", + ctx->nr_conns); + + for (i = 0; i < nr_conns; i++) { + if (cfg_oneshot) { + if (!ctx->received[i]) + error(1, 0, "connection %d received no data", i); + } else if (ctx->received[i] != (size_t)cfg_send_size) { + error(1, 0, "connection %d received %zu of %d bytes", + i, ctx->received[i], cfg_send_size); + } + } + + return NULL; +} + +static int query_napi_id(unsigned int ifindex, int queue_id) +{ + struct netdev_queue_get_req *req; + struct netdev_queue_get_rsp *rsp; + struct ynl_error yerr; + struct ynl_sock *ys; + int napi_id; + + ys = ynl_sock_create(&ynl_netdev_family, &yerr); + if (!ys) + error(1, 0, "ynl_sock_create: %s", yerr.msg); + + req = netdev_queue_get_req_alloc(); + netdev_queue_get_req_set_ifindex(req, ifindex); + netdev_queue_get_req_set_type(req, NETDEV_QUEUE_TYPE_RX); + netdev_queue_get_req_set_id(req, queue_id); + + rsp = netdev_queue_get(ys, req); + if (!rsp) + error(1, 0, "netdev_queue_get(q=%d): %s", queue_id, + ys->err.msg); + if (!rsp->_present.napi_id) + error(1, 0, "netdev_queue_get(q=%d): napi_id not present", + queue_id); + + napi_id = rsp->napi_id; + + netdev_queue_get_req_free(req); + netdev_queue_get_rsp_free(rsp); + ynl_sock_destroy(ys); + + return napi_id; +} + +static int find_thread_by_conn(struct thread_ctx *ctxs, int connfd) +{ + socklen_t len = sizeof(int); + int napi_id, i; + + if (getsockopt(connfd, SOL_SOCKET, SO_INCOMING_NAPI_ID, &napi_id, &len)) + error(1, errno, "getsockopt(SO_INCOMING_NAPI_ID)"); + + for (i = 0; i < cfg_num_threads; i++) { + if (ctxs[i].napi_id == napi_id) + return i; + } + + error(1, 0, "unknown NAPI ID: %d", napi_id); + return -1; +} + static void run_server(void) { - struct thread_ctx ctx = {}; - unsigned int flags = 0; - int fd, enable, ret; - uint64_t tstop; + pthread_barrier_t setup_done, dispatch_done; + int total_conns, accepted = 0, connfd; + struct thread_ctx *ctxs; + int fd, ret, enable, i; + unsigned int ifindex; + pthread_t *threads; + + ctxs = calloc(cfg_num_threads, sizeof(*ctxs)); + threads = calloc(cfg_num_threads, sizeof(*threads)); + if (!ctxs || !threads) + error(1, 0, "calloc()"); fd = socket(AF_INET6, SOCK_STREAM, 0); if (fd == -1) @@ -356,29 +457,68 @@ static void run_server(void) if (ret < 0) error(1, 0, "bind()"); - flags |= IORING_SETUP_COOP_TASKRUN; - flags |= IORING_SETUP_SINGLE_ISSUER; - flags |= IORING_SETUP_DEFER_TASKRUN; - flags |= IORING_SETUP_SUBMIT_ALL; - flags |= IORING_SETUP_CQE32; + pthread_barrier_init(&setup_done, NULL, cfg_num_threads + 1); + pthread_barrier_init(&dispatch_done, NULL, cfg_num_threads + 1); - io_uring_queue_init(512, &ctx.ring, flags); + for (i = 0; i < cfg_num_threads; i++) { + ctxs[i].queue_id = cfg_queue_id + i; + ctxs[i].setup_done = &setup_done; + ctxs[i].dispatch_done = &dispatch_done; + } + + for (i = 0; i < cfg_num_threads; i++) { + ret = pthread_create(&threads[i], NULL, + server_worker, &ctxs[i]); + if (ret) + error(1, ret, "pthread_create()"); + } - setup_zcrx(&ctx); if (cfg_dry_run) - return; + goto join; + + pthread_barrier_wait(&setup_done); if (listen(fd, 1024) < 0) error(1, 0, "listen()"); - add_accept(&ctx, fd); + if (cfg_num_threads > 1) { + ifindex = if_nametoindex(cfg_ifname); + if (!ifindex) + error(1, 0, "bad interface name: %s", cfg_ifname); + for (i = 0; i < cfg_num_threads; i++) + ctxs[i].napi_id = query_napi_id(ifindex, + ctxs[i].queue_id); + } - tstop = gettimeofday_ms() + 5000; - while (!ctx.stop && gettimeofday_ms() < tstop) - server_loop(&ctx); + total_conns = cfg_num_threads * cfg_num_threads; - if (!ctx.stop) - error(1, 0, "test failed\n"); + while (accepted < total_conns) { + int idx = 0; + + connfd = accept(fd, NULL, NULL); + if (connfd < 0) + error(1, errno, "accept()"); + + if (cfg_num_threads > 1) + idx = find_thread_by_conn(ctxs, connfd); + + if (ctxs[idx].nr_conns >= MAX_CONNS_PER_THREAD) + error(1, 0, "worker %d connection overflow", idx); + ctxs[idx].connfds[ctxs[idx].nr_conns++] = connfd; + accepted++; + } + + pthread_barrier_wait(&dispatch_done); + +join: + for (i = 0; i < cfg_num_threads; i++) + pthread_join(threads[i], NULL); + + pthread_barrier_destroy(&setup_done); + pthread_barrier_destroy(&dispatch_done); + close(fd); + free(threads); + free(ctxs); } static void *client_worker(void *arg) From 9814d2fa87427a2642e54b67d761a499437058fa Mon Sep 17 00:00:00 2001 From: Juanlu Herrero Date: Wed, 9 Sep 2026 14:51:28 -0500 Subject: [PATCH 0474/2126] selftests: net: add rss_multiqueue test variant to iou-zcrx Add a rss_multiqueue Python test variant that exercises multi-queue zero-copy receive on a single listening socket. Reviewed-by: David Wei Signed-off-by: Juanlu Herrero Link: https://patch.msgid.link/20260909-iou-zcrx-v7-6-6b5d48a2a922@fastmail.com Signed-off-by: Jakub Kicinski --- .../selftests/drivers/net/hw/iou-zcrx.py | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py index b7a225fe4bea..c833535d8a03 100755 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py @@ -30,6 +30,13 @@ def create_rss_ctx(cfg): return int(values) +def create_rss_ctx_multi(cfg, start, count): + """Create an RSS context spanning count queues from start, return its ID.""" + output = ethtool(f"-X {cfg.ifname} context new start {start} equal {count}").stdout + values = re.search(r'New RSS context is (\d+)', output).group(1) + return int(values) + + def set_flow_rule(cfg): output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {cfg.port} action {cfg.target}").stdout values = re.search(r'ID (\d+)', output).group(1) @@ -127,17 +134,56 @@ def _require_ntuple(cfg): defer(ethtool, f"-K {cfg.ifname} ntuple-filters off") +def rss_multiqueue(cfg): + """Steer the test flow to a multi-queue RSS context for multi-thread zcrx.""" + channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}}) + channels = channels['combined-count'] + if channels < 3: + raise KsftSkipEx('Test requires NETIF with at least 3 combined channels') + + rings = cfg.ethnl.rings_get({'header': {'dev-index': cfg.ifindex}}) + rx_rings = rings['rx'] + hds_thresh = rings.get('hds-thresh', 0) + + cfg.ethnl.rings_set({'header': {'dev-index': cfg.ifindex}, + 'tcp-data-split': 'enabled', + 'hds-thresh': 0, + 'rx': 64}) + defer(cfg.ethnl.rings_set, {'header': {'dev-index': cfg.ifindex}, + 'tcp-data-split': 'unknown', + 'hds-thresh': hds_thresh, + 'rx': rx_rings}) + defer(mp_clear_wait, cfg) + + cfg.num_threads = 2 + cfg.target = channels - cfg.num_threads + ethtool(f"-X {cfg.ifname} equal {cfg.target}") + defer(ethtool, f"-X {cfg.ifname} default") + + rss_ctx_id = create_rss_ctx_multi(cfg, cfg.target, cfg.num_threads) + defer(ethtool, f"-X {cfg.ifname} delete context {rss_ctx_id}") + + flow_rule_id = set_flow_rule_rss(cfg, rss_ctx_id) + defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}") + + @ksft_variants([ KsftNamedVariant("single", single), KsftNamedVariant("rss", rss), + KsftNamedVariant("rss_multiqueue", rss_multiqueue), ]) def test_zcrx(cfg, setup) -> None: cfg.require_ipver('6') _require_ntuple(cfg) + cfg.num_threads = 1 + setup(cfg) - rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.target}" - tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 12840" + + rx_cmd = (f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} " + f"-q {cfg.target} -t {cfg.num_threads}") + tx_cmd = (f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} " + f"-l 12840 -t {cfg.num_threads}") with bkg(rx_cmd, exit_wait=True): wait_port_listen(cfg.port, proto="tcp") cmd(tx_cmd, host=cfg.remote) From 2343cff0b382c9e9c965c75cebfe83d2150a96c7 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Fri, 11 Sep 2026 11:00:20 +0700 Subject: [PATCH 0475/2126] net: fec: Propagate PTP initialization errors Change fec_ptp_init() to return an error code instead of silently ignoring failures during PTP initialization. The PPS IRQ is not required for the FEC/PTP functionality, so its absence should not make the probe fail. However, an unavailable optional IRQ should be distinguished from an actual error returned during the IRQ lookup. If a platform does not support the PPS IRQ, it can omit the IRQ from its device tree and the optional lookup will return -ENXIO. Propagate other errors from the IRQ lookup instead of silently ignoring them. In particular, silently ignoring -EPROBE_DEFER can cause the driver to continue probing instead of deferring as required. Also propagate failures from devm_request_irq() and ptp_clock_register(). Update the function declaration in fec.h accordingly. Found by manual code inspection. Reviewed-by: Wei Fang Signed-off-by: bui duc phuc Link: https://patch.msgid.link/20260911040021.12289-1-phucduc.bui@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/fec.h | 2 +- drivers/net/ethernet/freescale/fec_main.c | 7 +++++-- drivers/net/ethernet/freescale/fec_ptp.c | 24 +++++++++++++++-------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 7176803146f3..8831da37326b 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -692,7 +692,7 @@ struct fec_enet_private { u64 ethtool_stats[]; }; -void fec_ptp_init(struct platform_device *pdev, int irq_idx); +int fec_ptp_init(struct platform_device *pdev, int irq_idx); void fec_ptp_restore_state(struct fec_enet_private *fep); void fec_ptp_save_state(struct fec_enet_private *fep); void fec_ptp_stop(struct platform_device *pdev); diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 794ec427b0ee..c6e29b5c2abb 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -5384,8 +5384,11 @@ fec_probe(struct platform_device *pdev) goto failed_reset; irq_cnt = fec_enet_get_irq_cnt(pdev); - if (fep->bufdesc_ex) - fec_ptp_init(pdev, irq_cnt); + if (fep->bufdesc_ex) { + ret = fec_ptp_init(pdev, irq_cnt); + if (ret) + goto failed_reset; + } ret = fec_enet_init(ndev); if (ret) diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index 56801c2009d5..0574a1a18702 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -734,9 +734,11 @@ static irqreturn_t fec_pps_interrupt(int irq, void *dev_id) * This function performs the required steps for enabling ptp * support. If ptp support has already been loaded it simply calls the * cyclecounter init routine and exits. + * + * Return: 0 on success, or a negative error code on failure. */ -void fec_ptp_init(struct platform_device *pdev, int irq_idx) +int fec_ptp_init(struct platform_device *pdev, int irq_idx) { struct net_device *ndev = platform_get_drvdata(pdev); struct fec_enet_private *fep = netdev_priv(ndev); @@ -779,26 +781,32 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx) HRTIMER_MODE_REL); irq = platform_get_irq_byname_optional(pdev, "pps"); - if (irq < 0) + if (irq < 0 && irq != -ENXIO) + return irq; + if (irq == -ENXIO) { irq = platform_get_irq_optional(pdev, irq_idx); - /* Failure to get an irq is not fatal, - * only the PTP_CLOCK_PPS clock events should stop - */ - if (irq >= 0) { + if (irq < 0 && irq != -ENXIO) + return irq; + } + + if (irq > 0) { ret = devm_request_irq(&pdev->dev, irq, fec_pps_interrupt, 0, pdev->name, ndev); if (ret < 0) - dev_warn(&pdev->dev, "request for pps irq failed(%d)\n", - ret); + return ret; } fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev); if (IS_ERR(fep->ptp_clock)) { + ret = PTR_ERR(fep->ptp_clock); fep->ptp_clock = NULL; dev_err(&pdev->dev, "ptp_clock_register failed\n"); + return ret; } schedule_delayed_work(&fep->time_keep, HZ); + + return 0; } void fec_ptp_save_state(struct fec_enet_private *fep) From 20d1b74a32d0044bb797da599069b382cb58f1d2 Mon Sep 17 00:00:00 2001 From: bui duc phuc Date: Fri, 11 Sep 2026 11:00:21 +0700 Subject: [PATCH 0476/2126] net: fec: Handle optional IRQ lookup errors correctly Handle errors from platform_get_irq_byname_optional() explicitly while preserving the existing fallback to platform_get_irq() when the named IRQ is not available. Propagate errors other than -ENXIO from the optional IRQ lookup instead of silently falling back to the indexed IRQ lookup. In particular, silently ignoring -EPROBE_DEFER can cause the driver to continue probing instead of deferring as required. Reviewed-by: Wei Fang Signed-off-by: bui duc phuc Link: https://patch.msgid.link/20260911040021.12289-2-phucduc.bui@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/fec_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index c6e29b5c2abb..f7636f23d1eb 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -5397,12 +5397,17 @@ fec_probe(struct platform_device *pdev) for (i = 0; i < irq_cnt; i++) { snprintf(irq_name, sizeof(irq_name), "int%d", i); irq = platform_get_irq_byname_optional(pdev, irq_name); - if (irq < 0) - irq = platform_get_irq(pdev, i); - if (irq < 0) { + if (irq < 0 && irq != -ENXIO) { ret = irq; goto failed_irq; } + if (irq == -ENXIO) { + irq = platform_get_irq(pdev, i); + if (irq < 0) { + ret = irq; + goto failed_irq; + } + } ret = devm_request_irq(&pdev->dev, irq, fec_enet_interrupt, 0, pdev->name, ndev); if (ret) From aeb505f83f7b16ec67c24fe3e87060e530221e2d Mon Sep 17 00:00:00 2001 From: Claudiu Manoil Date: Wed, 9 Sep 2026 18:07:19 +0800 Subject: [PATCH 0477/2126] net: enetc: add trusted VF support Some mailbox messages require a higher privilege level to be executed on behalf of the requesting VF. Introduce a trusted VF flag (ENETC_VF_FLAG_TRUSTED) and wire up the ndo_set_vf_trust callback via enetc_pf_set_vf_trust(), which is shared between the enetc and enetc4 PF drivers. Trust is a PF/host-side policy bound to the VF index, decoupled from whether SR-IOV is enabled. It may be set on a slot before SR-IOV is enabled so a trusted VF can apply configuration right at init time, and it is intentionally preserved across an SR-IOV disable/enable cycle. The bounds check uses pf->total_vfs, the hardware maximum and the size of pf->vf_state[], so pre-configuring an uninstantiated slot is in-bounds. If a slot may be reassigned to another guest, the admin clears trust with "ip link set vf trust off". The first message gated on trust is the VF primary MAC address change. An untrusted VF that attempts to set its own MAC address will receive a ENETC_MSG_CLASS_ID_PERMISSION_DENY response and the hardware will not be programmed. This prevents a malicious VM from setting the VF address to the MAC address of other VFs or the PF and eavesdropping on the traffic of other SIs, and it stops a malicious VM from arbitrarily changing the VF MAC address to achieve MAC address spoofing and bypass security policies. This does not regress VF bring-up. The PF programs a valid primary MAC into every VF slot at probe, and the VF loads it from its own SIPMAR0/1 registers. Signed-off-by: Claudiu Manoil Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-2-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../net/ethernet/freescale/enetc/enetc4_pf.c | 7 +++- .../net/ethernet/freescale/enetc/enetc_msg.c | 38 ++++++++++++++----- .../net/ethernet/freescale/enetc/enetc_pf.c | 1 + .../net/ethernet/freescale/enetc/enetc_pf.h | 1 + .../freescale/enetc/enetc_pf_common.c | 23 +++++++++++ .../freescale/enetc/enetc_pf_common.h | 1 + 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index 9bb1004548ab..935a6a03b14f 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -225,11 +225,15 @@ static const struct enetc_pf_ops enetc4_pf_ops = { static int enetc4_pf_struct_init(struct enetc_si *si) { struct enetc_pf *pf = enetc_si_priv(si); + int err; pf->si = si; - pf->total_vfs = pci_sriov_get_totalvfs(si->pdev); pf->ops = &enetc4_pf_ops; + err = enetc_init_sriov_resources(pf); + if (err) + return err; + enetc4_get_port_caps(pf); enetc4_get_psi_hw_features(si); @@ -574,6 +578,7 @@ static const struct net_device_ops enetc4_ndev_ops = { .ndo_eth_ioctl = enetc_ioctl, .ndo_hwtstamp_get = enetc_hwtstamp_get, .ndo_hwtstamp_set = enetc_hwtstamp_set, + .ndo_set_vf_trust = enetc_pf_set_vf_trust, }; static struct phylink_pcs * diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index edc1277bb586..78114ab3e482 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -7,6 +7,8 @@ ENETC_MSG_CLASS_ID_CMD_SUCCESS) #define ENETC_PF_MSG_NOTSUPP FIELD_PREP(ENETC_PF_MSG_CLASS_ID, \ ENETC_MSG_CLASS_ID_CMD_NOT_SUPPORT) +#define ENETC_PF_MSG_PERM_DENY FIELD_PREP(ENETC_PF_MSG_CLASS_ID, \ + ENETC_MSG_CLASS_ID_PERMISSION_DENY) static void enetc_msg_disable_mr_int(struct enetc_pf *pf) { @@ -61,31 +63,49 @@ static u16 enetc_msg_set_vf_primary_mac_addr(struct enetc_pf *pf, int vf_id, struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; struct enetc_msg_mac_exact_filter *msg = vf_msg; struct device *dev = &pf->si->pdev->dev; + u16 pf_msg = ENETC_PF_MSG_SUCCESS; char *addr = msg->mac[0].addr; + mutex_lock(&vf_state->lock); + + /* Untrusted VFs cannot set their MAC addresses by the mailbox + * messages. + */ + if (!(vf_state->flags & ENETC_VF_FLAG_TRUSTED)) { + pf_msg = ENETC_PF_MSG_PERM_DENY; + goto vf_state_unlock; + } + if (!is_valid_ether_addr(addr)) { dev_err_ratelimited(dev, "VF%d attempted to set invalid MAC\n", vf_id); - return (FIELD_PREP(ENETC_PF_MSG_CLASS_ID, - ENETC_MSG_CLASS_ID_MAC_FILTER) | - FIELD_PREP(ENETC_PF_MSG_CLASS_CODE, - ENETC_MF_CLASS_CODE_INVALID_MAC)); + pf_msg = FIELD_PREP(ENETC_PF_MSG_CLASS_ID, + ENETC_MSG_CLASS_ID_MAC_FILTER) | + FIELD_PREP(ENETC_PF_MSG_CLASS_CODE, + ENETC_MF_CLASS_CODE_INVALID_MAC); + goto vf_state_unlock; } - mutex_lock(&vf_state->lock); + /* PF has higher privileges. If PF has already modified the MAC + * address for VF through .ndo_set_vf_mac() interface, VF is not + * allowed to set its MAC address via mailbox messages, even if + * it is trusted. + */ if (vf_state->flags & ENETC_VF_FLAG_PF_SET_MAC) { - mutex_unlock(&vf_state->lock); dev_err_ratelimited(dev, "VF%d attempted to override PF set MAC\n", vf_id); - return FIELD_PREP(ENETC_PF_MSG_CLASS_ID, - ENETC_MSG_CLASS_ID_CMD_NOT_PERMITTED); + pf_msg = FIELD_PREP(ENETC_PF_MSG_CLASS_ID, + ENETC_MSG_CLASS_ID_CMD_NOT_PERMITTED); + goto vf_state_unlock; } enetc_set_si_hw_addr(pf, vf_id + 1, addr); + +vf_state_unlock: mutex_unlock(&vf_state->lock); - return ENETC_PF_MSG_SUCCESS; + return pf_msg; } static u16 enetc_msg_handle_mac_filter(struct enetc_pf *pf, int vf_id, diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index 55c07c528f22..a7bf4bfc25b7 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -488,6 +488,7 @@ static const struct net_device_ops enetc_ndev_ops = { .ndo_set_rx_mode = enetc_pf_set_rx_mode, .ndo_vlan_rx_add_vid = enetc_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = enetc_vlan_rx_del_vid, + .ndo_set_vf_trust = enetc_pf_set_vf_trust, .ndo_set_vf_mac = enetc_pf_set_vf_mac, .ndo_set_vf_vlan = enetc_pf_set_vf_vlan, .ndo_set_vf_spoofchk = enetc_pf_set_vf_spoofchk, diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index 56d23a8a11a0..6789f92d005e 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -9,6 +9,7 @@ enum enetc_vf_flags { ENETC_VF_FLAG_PF_SET_MAC = BIT(0), + ENETC_VF_FLAG_TRUSTED = BIT(1), }; struct enetc_vf_state { diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index d32a195a04c9..519fc90d2647 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -586,5 +586,28 @@ int enetc_init_sriov_resources(struct enetc_pf *pf) } EXPORT_SYMBOL_GPL(enetc_init_sriov_resources); +int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting) +{ + struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_pf *pf = enetc_si_priv(priv->si); + struct enetc_vf_state *vf_state; + + if (vf >= pf->total_vfs) + return -EINVAL; + + vf_state = &pf->vf_state[vf]; + mutex_lock(&vf_state->lock); + + if (setting) + vf_state->flags |= ENETC_VF_FLAG_TRUSTED; + else + vf_state->flags &= ~ENETC_VF_FLAG_TRUSTED; + + mutex_unlock(&vf_state->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(enetc_pf_set_vf_trust); + MODULE_DESCRIPTION("NXP ENETC PF common functionality driver"); MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h index 8243ce0de57f..96a4dc63da57 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h @@ -22,6 +22,7 @@ void enetc_set_si_mc_promisc(struct enetc_si *si, int si_id, bool promisc); void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash); void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash); void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc); +int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting); static inline u16 enetc_get_ip_revision(struct enetc_hw *hw) { From 99ace7602482c40414961d7257f75a5806aa4e2f Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:20 +0800 Subject: [PATCH 0478/2126] net: enetc: move msg_task and msg_int_name to struct enetc_si The ENETC PF currently uses msg_task and msg_int_name in struct enetc_pf to handle VSI-to-PSI mailbox messages via a workqueue and a dedicated interrupt. PSI-to-VSI message support will be added to the VF driver, which will require the same mechanism: a message interrupt and a workqueue handler. Since struct enetc_si is the common structure shared between PF and VF, move msg_task and msg_int_name from struct enetc_pf to struct enetc_si to allow both drivers to use them without duplication. Also relocate the ENETC_INT_NAME_MAX macro definition ahead of struct enetc_si so it can be used for the msg_int_name array declaration. Signed-off-by: Wei Fang Reviewed-by: Claudiu Manoil Link: https://patch.msgid.link/20260909100733.1139689-3-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/enetc.h | 4 +++- .../net/ethernet/freescale/enetc/enetc_msg.c | 19 ++++++++++--------- .../net/ethernet/freescale/enetc/enetc_pf.h | 3 --- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index d1e9d9130057..bc713a7c3aa1 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -25,6 +25,7 @@ #define ENETC_CBD_DATA_MEM_ALIGN 64 #define ENETC_MADDR_HASH_TBL_SZ 64 +#define ENETC_INT_NAME_MAX (IFNAMSIZ + 8) enum enetc_mac_addr_type {UC, MC, MADDR_TYPE}; @@ -333,6 +334,8 @@ struct enetc_si { struct dentry *debugfs_root; struct enetc_msg_swbd msg; /* Only valid for VSI */ + struct work_struct msg_task; + char msg_int_name[ENETC_INT_NAME_MAX]; }; #define ENETC_SI_ALIGN 32 @@ -374,7 +377,6 @@ static inline bool enetc_is_pseudo_mac(struct enetc_si *si) } #define ENETC_MAX_NUM_TXQS 8 -#define ENETC_INT_NAME_MAX (IFNAMSIZ + 8) struct enetc_int_vector { void __iomem *rbier; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index 78114ab3e482..a89a5a418a23 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -37,7 +37,7 @@ static irqreturn_t enetc_msg_psi_msix(int irq, void *data) struct enetc_pf *pf = enetc_si_priv(si); enetc_msg_disable_mr_int(pf); - schedule_work(&pf->msg_task); + schedule_work(&si->msg_task); return IRQ_HANDLED; } @@ -223,12 +223,13 @@ free_msg: static void enetc_msg_task(struct work_struct *work) { - struct enetc_pf *pf = container_of(work, struct enetc_pf, msg_task); - u32 mr_mask = ENETC_PSIMR_MASK(pf->num_vfs); - struct enetc_hw *hw = &pf->si->hw; - u32 mr_status; + struct enetc_si *si = container_of(work, struct enetc_si, msg_task); + struct enetc_pf *pf = enetc_si_priv(si); + struct enetc_hw *hw = &si->hw; + u32 mr_status, mr_mask; int i; + mr_mask = ENETC_PSIMR_MASK(pf->num_vfs); mr_status = (enetc_rd(hw, ENETC_PSIMSGRR) & mr_mask) | (enetc_rd(hw, ENETC_PSIIDR) & mr_mask); if (!mr_status) @@ -311,13 +312,13 @@ static int enetc_msg_psi_init(struct enetc_pf *pf) } /* initialize PSI mailbox */ - INIT_WORK(&pf->msg_task, enetc_msg_task); + INIT_WORK(&si->msg_task, enetc_msg_task); /* register message passing interrupt handler */ - snprintf(pf->msg_int_name, sizeof(pf->msg_int_name), "%s-vfmsg", + snprintf(si->msg_int_name, sizeof(si->msg_int_name), "%s-vfmsg", si->ndev->name); vector = pci_irq_vector(si->pdev, ENETC_SI_INT_IDX); - err = request_irq(vector, enetc_msg_psi_msix, 0, pf->msg_int_name, si); + err = request_irq(vector, enetc_msg_psi_msix, 0, si->msg_int_name, si); if (err) { dev_err(&si->pdev->dev, "PSI messaging: request_irq() failed!\n"); @@ -350,7 +351,7 @@ static void enetc_msg_psi_free(struct enetc_pf *pf) /* de-register message passing interrupt handler */ free_irq(pci_irq_vector(si->pdev, ENETC_SI_INT_IDX), si); - cancel_work_sync(&pf->msg_task); + cancel_work_sync(&si->msg_task); /* MR interrupts may be re-enabled by workqueue */ enetc_msg_disable_mr_int(pf); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index 6789f92d005e..142c911f1dfc 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -40,10 +40,7 @@ struct enetc_pf { struct enetc_vf_state *vf_state; struct enetc_mac_filter mac_filter[MADDR_TYPE]; - struct enetc_msg_swbd *rxmsg; - struct work_struct msg_task; - char msg_int_name[ENETC_INT_NAME_MAX]; DECLARE_BITMAP(vlan_ht_filter, ENETC_VLAN_HT_SIZE); DECLARE_BITMAP(active_vlans, VLAN_N_VID); From 83d385c67af569e0052f3371b1aeda3ec19ad3ab Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:21 +0800 Subject: [PATCH 0479/2126] net: enetc: add link status message support to PF driver Add a mechanism for VFs to learn the PF link state, using message class 0x80 (ENETC_MSG_CLASS_ID_LINK_STATUS) with three VSI-to-PSI commands: 1. ENETC_MSG_GET_CURRENT_LINK_STATUS: the VF queries the current PF link status synchronously. This is intended for DPDK-owned VFs and is not used by the Linux VF driver. 2. ENETC_MSG_REGISTER_LINK_CHANGE_NOTIFIER: the VF registers for link change notification. The PF then reports the current link status and notifies the VF on every later link change. 3. ENETC_MSG_UNREGISTER_LINK_CHANGE_NOTIFIER: the VF unregisters. The PSI-to-VSI notification is 16 bits wide: the upper 8 bits carry the class ID and the lower 8 bits the class code. Bit 0 of the class code indicates the link state (1 = down, 0 = up) and bit 1 indicates whether TX PAUSE is enabled on the PF. The TX PAUSE state is included so a VF can decide whether to enable congestion mode on its RX BD rings, which only works when the PF can actually send PAUSE frames. Notifications are sent through the ENETC_PSIMSGSR register. Since sending a notification may take a long time, as it polls the per-VF message status bits, the actual transmission is deferred to an ordered workqueue rather than running in the phylink link_up/link_down callbacks. The link_status_ms_mask tracks the VFs registered for notification and is cleared when SR-IOV is disabled. Export enetc_pf_notify_vf_link_up() and enetc_pf_notify_vf_link_down() for the PF phylink callbacks. Through this, VFs can perceive the link status and report it to upper layers such as the kernel network stack, containers and virtual machines. Currently only the ENETC v4 driver supports this feature; v1 does not. And the SR-IOV feature of ENETC v4 will be added by subsequent patches. Signed-off-by: Wei Fang Reviewed-by: Claudiu Manoil Link: https://patch.msgid.link/20260909100733.1139689-4-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/enetc.h | 1 + .../net/ethernet/freescale/enetc/enetc4_pf.c | 39 +++ .../net/ethernet/freescale/enetc/enetc_hw.h | 5 + .../ethernet/freescale/enetc/enetc_mailbox.h | 26 +- .../net/ethernet/freescale/enetc/enetc_msg.c | 264 +++++++++++++++++- .../net/ethernet/freescale/enetc/enetc_pf.h | 7 + .../freescale/enetc/enetc_pf_common.h | 15 + 7 files changed, 347 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index bc713a7c3aa1..0eff25b0c81b 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -334,6 +334,7 @@ struct enetc_si { struct dentry *debugfs_root; struct enetc_msg_swbd msg; /* Only valid for VSI */ + struct workqueue_struct *workqueue; struct work_struct msg_task; char msg_int_name[ENETC_INT_NAME_MAX]; }; diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index 935a6a03b14f..e20989b6f8b4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -899,6 +899,7 @@ static void enetc4_pl_mac_link_up(struct phylink_config *config, enetc4_set_rx_pause(pf, rx_pause); enetc4_mac_tx_enable(pf); enetc4_mac_rx_enable(pf); + enetc_pf_notify_vf_link_up(pf); } static void enetc4_pl_mac_link_down(struct phylink_config *config, @@ -907,6 +908,7 @@ static void enetc4_pl_mac_link_down(struct phylink_config *config, { struct enetc_pf *pf = phylink_to_enetc_pf(config); + enetc_pf_notify_vf_link_down(pf); enetc4_mac_rx_graceful_stop(pf); enetc4_mac_tx_graceful_stop(pf); } @@ -966,6 +968,36 @@ static void enetc4_link_deinit(struct enetc_ndev_priv *priv) enetc_mdiobus_destroy(pf); } +static void enetc4_pf_link_status_task(struct work_struct *work) +{ + struct enetc_pf *pf = container_of(work, struct enetc_pf, + link_status_task); + + enetc_pf_send_link_status_msg(pf); +} + +static int enetc4_pf_wq_task_init(struct enetc_si *si) +{ + struct enetc_pf *pf = enetc_si_priv(si); + + si->workqueue = alloc_ordered_workqueue("enetc-%s-wq", 0, + pci_name(si->pdev)); + if (!si->workqueue) + return -ENOMEM; + + INIT_WORK(&pf->link_status_task, enetc4_pf_link_status_task); + + return 0; +} + +static void enetc4_pf_wq_task_destroy(struct enetc_si *si) +{ + struct enetc_pf *pf = enetc_si_priv(si); + + disable_work_sync(&pf->link_status_task); + destroy_workqueue(si->workqueue); +} + static int enetc4_pf_netdev_create(struct enetc_si *si) { struct device *dev = &si->pdev->dev; @@ -1006,6 +1038,10 @@ static int enetc4_pf_netdev_create(struct enetc_si *si) if (err) goto err_link_init; + err = enetc4_pf_wq_task_init(si); + if (err) + goto err_wq_init; + err = register_netdev(ndev); if (err) { dev_err(dev, "Failed to register netdev\n"); @@ -1015,6 +1051,8 @@ static int enetc4_pf_netdev_create(struct enetc_si *si) return 0; err_reg_netdev: + enetc4_pf_wq_task_destroy(si); +err_wq_init: enetc4_link_deinit(priv); err_link_init: enetc_free_msix(priv); @@ -1032,6 +1070,7 @@ static void enetc4_pf_netdev_destroy(struct enetc_si *si) struct net_device *ndev = si->ndev; unregister_netdev(ndev); + enetc4_pf_wq_task_destroy(si); enetc4_link_deinit(priv); enetc_free_msix(priv); free_netdev(ndev); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h index 16da732dc5de..f97602714118 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -80,6 +80,11 @@ static inline u32 enetc_vsi_set_msize(u32 size) #define ENETC_SIMSGSR_SET_MC(val) ((val) << 16) #define ENETC_SIMSGSR_GET_MC(val) ((val) >> 16) +#define ENETC_PSIMSGSR 0x208 +/* n is VF index, which is less than 15 */ +#define PSIMSGSR_MS(n) BIT((n) + 1) +#define PSIMSGSR_MC GENMASK(31, 16) + /* SI statistics */ #define ENETC_SIROCT 0x300 #define ENETC_SIRFRM 0x308 diff --git a/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h b/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h index d9677da38989..846998f07989 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h @@ -66,8 +66,8 @@ * 2) PSI_TX_control: PSIMSGSR[MC] - for PSI to VSI notification messages * (async mode) * - * Note that for some GET messages, there is no COOKIE field, and the CLASS - * CODE field is expanded to 8 bits. + * Note that for some PSI-to-VSI messages, there is no COOKIE field, and the + * CLASS CODE field is expanded to 8 bits. */ #ifndef __ENETC_MAILBOX_H @@ -87,7 +87,11 @@ /* The fileds of PSI-to-VSI message, the message is only 16-bit */ #define ENETC_PF_MSG_COOKIE GENMASK(3, 0) #define ENETC_PF_MSG_CLASS_CODE GENMASK(7, 4) -/* Extend the class code to 8-bit for GET messages without COOKIE */ +/* Extend the class code to 8-bit for PSI-to-VSI messages without COOKIE + * The class code for the following messages is 8-bit. + * 1. Get IP revision messages + * 2. Link status messages + */ #define ENETC_PF_MSG_CLASS_CODE_U8 GENMASK(7, 0) #define ENETC_PF_MSG_CLASS_ID GENMASK(15, 8) @@ -107,6 +111,7 @@ enum enetc_msg_class_id { /* Common Class ID for PSI-to-VSI and VSI-to-PSI messages */ ENETC_MSG_CLASS_ID_MAC_FILTER = 0x20, + ENETC_MSG_CLASS_ID_LINK_STATUS = 0x80, ENETC_MSG_CLASS_ID_IP_REVISION = 0xf0, }; @@ -118,11 +123,21 @@ enum enetc_msg_ip_revision_cmd_id { ENETC_MSG_GET_IP_MN = 1, }; +enum enetc_msg_link_status_cmd_id { + ENETC_MSG_GET_CURRENT_LINK_STATUS, + ENETC_MSG_REGISTER_LINK_CHANGE_NOTIFIER, + ENETC_MSG_UNREGISTER_LINK_CHANGE_NOTIFIER, +}; + /* Class-specific error return codes of MAC filter */ enum enetc_mac_filter_class_code { ENETC_MF_CLASS_CODE_INVALID_MAC, }; +/* Class-specific notifications/codes of link status */ +#define ENETC_CLASS_CODE_LINK_DOWN BIT(0) +#define ENETC_CLASS_CODE_TX_PAUSE_EN BIT(1) + struct enetc_msg_swbd { void *vaddr; dma_addr_t dma; @@ -161,6 +176,11 @@ struct enetc_msg_mac_exact_filter { /* The generic message format applies to the following messages: * Get IP revision message, class_id 0xf0. * cmd_id 1: get IP minor revision + * + * Link status message, class id 0x80. + * cmd_id 0x0: get the current link status + * cmd_id 0x1: register link status change notification + * cmd_id 0x2: unregister link status change notification */ struct enetc_msg_generic { struct enetc_msg_header hdr; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index a89a5a418a23..79dbaf72fcff 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -136,6 +136,104 @@ static u16 enetc_msg_handle_ip_revision(struct enetc_pf *pf, void *vf_msg) } } +static void enetc_pf_reply_msg(struct enetc_hw *hw, int vf_id, u16 pf_msg) +{ + /* w1c to clear the corresponding VF MR bit */ + enetc_wr(hw, ENETC_PSIIDR, ENETC_PSIMR_BIT(vf_id)); + enetc_wr(hw, ENETC_PSIMSGRR, ENETC_SIMSGSR_SET_MC(pf_msg) | + ENETC_PSIMR_BIT(vf_id)); +} + +static u16 enetc_build_link_status_msg(struct enetc_ndev_priv *priv, + bool link_up) +{ + u8 status = 0; + + if (link_up) { + if (test_bit(ENETC_RXBDR_CM, &priv->flags)) + status |= ENETC_CLASS_CODE_TX_PAUSE_EN; + } else { + status |= ENETC_CLASS_CODE_LINK_DOWN; + } + + return FIELD_PREP(ENETC_PF_MSG_CLASS_ID, + ENETC_MSG_CLASS_ID_LINK_STATUS) | + FIELD_PREP(ENETC_PF_MSG_CLASS_CODE_U8, status); +} + +static void enetc_msg_get_link_status(struct enetc_pf *pf, int vf_id) +{ + struct enetc_ndev_priv *priv = netdev_priv(pf->si->ndev); + struct enetc_si *si = pf->si; + u16 pf_msg; + + spin_lock(&si->gen_lock); + pf_msg = enetc_build_link_status_msg(priv, pf->link_up); + enetc_pf_reply_msg(&si->hw, vf_id, pf_msg); + spin_unlock(&si->gen_lock); +} + +static void enetc_msg_register_link_status_notifier(struct enetc_pf *pf, + int vf_id) +{ + struct enetc_si *si = pf->si; + + spin_lock(&si->gen_lock); + enetc_pf_reply_msg(&si->hw, vf_id, ENETC_PF_MSG_SUCCESS); + + /* SR-IOV is being disabled if pf->sriov_enabled is false, so no + * need to set link_status_ms_mask and notify the link status. + */ + if (!pf->sriov_enabled) { + spin_unlock(&si->gen_lock); + return; + } + + pf->link_status_ms_mask |= PSIMSGSR_MS(vf_id); + spin_unlock(&si->gen_lock); + + /* Notify VF the current link status */ + queue_work(si->workqueue, &pf->link_status_task); +} + +static void enetc_msg_unregister_link_status_notifier(struct enetc_pf *pf, + int vf_id) +{ + spin_lock(&pf->si->gen_lock); + pf->link_status_ms_mask &= ~PSIMSGSR_MS(vf_id); + enetc_pf_reply_msg(&pf->si->hw, vf_id, ENETC_PF_MSG_SUCCESS); + spin_unlock(&pf->si->gen_lock); +} + +static u16 enetc_msg_handle_link_status(struct enetc_pf *pf, int vf_id, + void *vf_msg) +{ + struct enetc_msg_header *msg_hdr = vf_msg; + + switch (msg_hdr->cmd_id) { + case ENETC_MSG_GET_CURRENT_LINK_STATUS: + /* Currently, this message is intended only for + * DPDK-owned VFs. + */ + enetc_msg_get_link_status(pf, vf_id); + break; + case ENETC_MSG_REGISTER_LINK_CHANGE_NOTIFIER: + enetc_msg_register_link_status_notifier(pf, vf_id); + break; + case ENETC_MSG_UNREGISTER_LINK_CHANGE_NOTIFIER: + enetc_msg_unregister_link_status_notifier(pf, vf_id); + break; + default: + return ENETC_PF_MSG_NOTSUPP; + } + + return 0; +} + +/* If *pf_msg is set to 0, it means that PF has responded to VF in + * enetc_msg_handle_rxmsg() through enetc_pf_reply_msg(), which also + * clears the corresponding VF MR bit in PSIIDR. + */ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, u16 *pf_msg) { @@ -211,6 +309,9 @@ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, case ENETC_MSG_CLASS_ID_IP_REVISION: *pf_msg = enetc_msg_handle_ip_revision(pf, msg); break; + case ENETC_MSG_CLASS_ID_LINK_STATUS: + *pf_msg = enetc_msg_handle_link_status(pf, vf_id, msg); + break; default: dev_err_ratelimited(dev, "Unsupported message class ID: 0x%x\n", @@ -236,7 +337,6 @@ static void enetc_msg_task(struct work_struct *work) goto out; for (i = 0; i < pf->num_vfs; i++) { - u32 psimsgrr; u16 msg_code; if (!(ENETC_PSIMR_BIT(i) & mr_status)) @@ -244,12 +344,14 @@ static void enetc_msg_task(struct work_struct *work) enetc_msg_handle_rxmsg(pf, i, &msg_code); - /* w1c to clear the corresponding VF MR bit */ - enetc_wr(hw, ENETC_PSIIDR, ENETC_PSIMR_BIT(i)); + /* If msg_code is 0, it means that PF has responded to VF + * in enetc_msg_handle_rxmsg() through enetc_pf_reply_msg(), + * which also clears the corresponding VF MR bit in PSIIDR. + */ + if (!msg_code) + continue; - psimsgrr = ENETC_SIMSGSR_SET_MC(msg_code); - psimsgrr |= ENETC_PSIMR_BIT(i); /* w1c */ - enetc_wr(hw, ENETC_PSIMSGRR, psimsgrr); + enetc_pf_reply_msg(hw, i, msg_code); } out: @@ -340,6 +442,22 @@ free_mbx: return err; } +static void enetc_msg_clear_vf_config(struct enetc_pf *pf, int vf_id) +{ + struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; + struct enetc_si *si = pf->si; + + /* For ENETC v1, we only support setting the VF's MAC address via + * VSI-to-PSI messages, so there is no configuration to clear. + */ + if (is_enetc_rev1(si)) + return; + + spin_lock(&si->gen_lock); + vf_state->msg_fail_cnt = 0; + spin_unlock(&si->gen_lock); +} + static void enetc_msg_psi_free(struct enetc_pf *pf) { struct enetc_si *si = pf->si; @@ -356,8 +474,10 @@ static void enetc_msg_psi_free(struct enetc_pf *pf) /* MR interrupts may be re-enabled by workqueue */ enetc_msg_disable_mr_int(pf); - for (i = 0; i < pf->num_vfs; i++) + for (i = 0; i < pf->num_vfs; i++) { enetc_msg_free_mbx(si, i); + enetc_msg_clear_vf_config(pf, i); + } } int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs) @@ -367,6 +487,11 @@ int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs) int err; if (!num_vfs) { + spin_lock(&si->gen_lock); + pf->sriov_enabled = false; + pf->link_status_ms_mask = 0; + spin_unlock(&si->gen_lock); + pci_disable_sriov(pdev); enetc_msg_psi_free(pf); pf->num_vfs = 0; @@ -379,6 +504,11 @@ int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs) goto err_msg_psi; } + /* As PCI SR-IOV is not enabled at the moment, there is no + * concurrent access to sriov_enabled. So no need to use + * gen_lock to protect sriov_enabled. + */ + pf->sriov_enabled = true; err = pci_enable_sriov(pdev, num_vfs); if (err) { dev_err(&pdev->dev, "pci_enable_sriov err %d\n", err); @@ -389,6 +519,15 @@ int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs) return num_vfs; err_en_sriov: + /* If pci_enable_sriov() fails after partially creating VFs, a VF + * driver that successfully bound to one of the created VFs could + * have sent a registration message, setting its bit in + * link_status_ms_mask. + */ + spin_lock(&si->gen_lock); + pf->sriov_enabled = false; + pf->link_status_ms_mask = 0; + spin_unlock(&si->gen_lock); enetc_msg_psi_free(pf); err_msg_psi: pf->num_vfs = 0; @@ -396,3 +535,114 @@ err_msg_psi: return err; } EXPORT_SYMBOL_GPL(enetc_sriov_configure); + +void enetc_pf_send_link_status_msg(struct enetc_pf *pf) +{ + struct enetc_ndev_priv *priv = netdev_priv(pf->si->ndev); + u16 pf_msg, ms_mask, new_ms_msk, ms_status; + struct enetc_si *si = pf->si; + int retry_num = 0; + +retry: + spin_lock(&si->gen_lock); + ms_mask = pf->link_status_ms_mask; + /* VFs have unregistered link status notification, return directly */ + if (!ms_mask) + goto unlock; + + /* The MS bit is set, indicating that the corresponding VF has not + * read the last message, PF cannot send new message to the VF. To + * avoid sending messages to such a VF, the bit corresponding to VF + * is cleared from ms_mask. Because the MS bit can only be written + * as 1, writing a 0 has no effect. Writing a 1 when the bit is + * already set is undefined. + */ + ms_status = enetc_rd(&si->hw, ENETC_PSIMSGSR) & 0xfffe; + if ((ms_mask & ms_status) && retry_num++ < 200) { + spin_unlock(&si->gen_lock); + /* Wait VFs to handle the last message */ + usleep_range(1000, 1020); + goto retry; + } + + /* None of the relevant VFs have processed the previous message, and + * the PF has tried 200 times. This situation indicates that VF has + * malfunctioned. + */ + new_ms_msk = ms_mask & (~ms_status); + if (!new_ms_msk) { + dev_err_ratelimited(&si->pdev->dev, + "All registered VFs (MS: 0x%x) are busy\n", + ms_mask); + goto ms_status_check; + } + + if (new_ms_msk != ms_mask) + dev_warn_ratelimited(&si->pdev->dev, + "Failed to notify link status to VFs (MS: 0x%x)\n", + ms_mask ^ new_ms_msk); + + pf_msg = enetc_build_link_status_msg(priv, pf->link_up); + enetc_wr(&si->hw, ENETC_PSIMSGSR, + FIELD_PREP(PSIMSGSR_MC, pf_msg) | new_ms_msk); + +ms_status_check: + /* If the PF fails to send messages to the corresponding VF for 10 + * consecutive times, clear that VF's bit in link_status_ms_mask. + */ + for (int i = 0; i < pf->num_vfs; i++) { + struct enetc_vf_state *vf_state = &pf->vf_state[i]; + + if (!(PSIMSGSR_MS(i) & ms_mask)) + continue; + + if (!(PSIMSGSR_MS(i) & ms_status)) { + vf_state->msg_fail_cnt = 0; + continue; + } + + if (vf_state->msg_fail_cnt++ < 10) + continue; + + vf_state->msg_fail_cnt = 0; + pf->link_status_ms_mask &= ~PSIMSGSR_MS(i); + dev_warn_ratelimited(&si->pdev->dev, + "Clear VF%d's link status MS bit\n", i); + } + +unlock: + spin_unlock(&si->gen_lock); +} +EXPORT_SYMBOL_GPL(enetc_pf_send_link_status_msg); + +static void enetc_pf_notify_vf_link_status(struct enetc_pf *pf, + bool link_up) +{ + struct enetc_si *si = pf->si; + + /* Currently we do not add link status message support for ENETC v1 */ + if (!pf->total_vfs || is_enetc_rev1(si)) + return; + + spin_lock(&si->gen_lock); + pf->link_up = link_up; + if (!pf->link_status_ms_mask) { + spin_unlock(&si->gen_lock); + return; + } + spin_unlock(&si->gen_lock); + + queue_work(si->workqueue, &pf->link_status_task); +} + +void enetc_pf_notify_vf_link_up(struct enetc_pf *pf) +{ + enetc_pf_notify_vf_link_status(pf, true); +} +EXPORT_SYMBOL_GPL(enetc_pf_notify_vf_link_up); + +void enetc_pf_notify_vf_link_down(struct enetc_pf *pf) +{ + enetc_pf_notify_vf_link_status(pf, false); +} +EXPORT_SYMBOL_GPL(enetc_pf_notify_vf_link_down); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index 142c911f1dfc..b3ad498f91a0 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -15,6 +15,8 @@ enum enetc_vf_flags { struct enetc_vf_state { struct mutex lock; /* Prevent concurrent access */ enum enetc_vf_flags flags; + /* Number of consecutive failures to send PF-to-VF messages */ + int msg_fail_cnt; }; struct enetc_port_caps { @@ -54,6 +56,11 @@ struct enetc_pf { struct enetc_port_caps caps; const struct enetc_pf_ops *ops; + + struct work_struct link_status_task; + bool sriov_enabled; + bool link_up; + u16 link_status_ms_mask; }; #define phylink_to_enetc_pf(config) \ diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h index 96a4dc63da57..bcf113efc2ef 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h @@ -31,9 +31,24 @@ static inline u16 enetc_get_ip_revision(struct enetc_hw *hw) #if IS_ENABLED(CONFIG_PCI_IOV) int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs); +void enetc_pf_send_link_status_msg(struct enetc_pf *pf); +void enetc_pf_notify_vf_link_up(struct enetc_pf *pf); +void enetc_pf_notify_vf_link_down(struct enetc_pf *pf); #else static inline int enetc_sriov_configure(struct pci_dev *pdev, int num_vfs) { return 0; } + +static inline void enetc_pf_send_link_status_msg(struct enetc_pf *pf) +{ +} + +static inline void enetc_pf_notify_vf_link_up(struct enetc_pf *pf) +{ +} + +static inline void enetc_pf_notify_vf_link_down(struct enetc_pf *pf) +{ +} #endif From f7e86f8ae699f3a508929650415829e3c382af38 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:22 +0800 Subject: [PATCH 0480/2126] net: enetc: add link speed message support to PF driver When a VF is driven by DPDK, its user space application needs accurate link speed information to make correct forwarding and configuration decisions. Add link speed message support so the PF replies with the current link speed when it receives a get-link-speed message from a VF. Use a new message class 0x81 (ENETC_MSG_CLASS_ID_LINK_SPEED). The PSI-to-VSI message is 16 bits: the high 8 bits are the class ID and the low 8 bits are the speed code, so up to 255 speed values are supported (ENETC_MSG_SPEED_MAX = 0xff). Instead of enumerating every speed above 5Gbps, use a formula so future high speeds need no enum or switch changes: speed_code = (link_speed - 5000) / 1000 + ENETC_MSG_SPEED_5G The speed is read via phylink_ethtool_ksettings_get() rather than the speed passed to the mac_link_up() callback. When the MAC has a PCS layer, mac_link_up() reports the PCS link speed, which may differ from the external PHY link speed; phylink_ethtool_ksettings_get() returns the actual external link speed. Unlike the link status message (class 0x80), the get-link-speed message is only permitted for trusted VFs. Reading the speed requires the PF to take rtnl_lock(), so an untrusted VF spamming this query could cause rtnl_lock contention and starve routine network configuration on the host. An untrusted VF therefore receives a permission-deny response; a VF can be marked trusted via 'ip link set vf N trust on'. Note that link speed change notification is not supported yet. Signed-off-by: Wei Fang Reviewed-by: Claudiu Manoil Link: https://patch.msgid.link/20260909100733.1139689-5-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../ethernet/freescale/enetc/enetc_mailbox.h | 41 +++++++++ .../net/ethernet/freescale/enetc/enetc_msg.c | 90 +++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h b/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h index 846998f07989..832d2f6ddcd8 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h @@ -91,6 +91,7 @@ * The class code for the following messages is 8-bit. * 1. Get IP revision messages * 2. Link status messages + * 3. Link speed messages */ #define ENETC_PF_MSG_CLASS_CODE_U8 GENMASK(7, 0) #define ENETC_PF_MSG_CLASS_ID GENMASK(15, 8) @@ -112,6 +113,7 @@ enum enetc_msg_class_id { /* Common Class ID for PSI-to-VSI and VSI-to-PSI messages */ ENETC_MSG_CLASS_ID_MAC_FILTER = 0x20, ENETC_MSG_CLASS_ID_LINK_STATUS = 0x80, + ENETC_MSG_CLASS_ID_LINK_SPEED = 0x81, ENETC_MSG_CLASS_ID_IP_REVISION = 0xf0, }; @@ -129,6 +131,13 @@ enum enetc_msg_link_status_cmd_id { ENETC_MSG_UNREGISTER_LINK_CHANGE_NOTIFIER, }; +enum enetc_msg_link_speed_cmd_id { + ENETC_MSG_GET_CURRENT_LINK_SPEED, + /* The following command IDs are not currently supported */ + ENETC_MSG_REGISTER_SPEED_CHANGE_NOTIFIER, + ENETC_MSG_UNREGISTER_SPEED_CHANGE_NOTIFIER, +}; + /* Class-specific error return codes of MAC filter */ enum enetc_mac_filter_class_code { ENETC_MF_CLASS_CODE_INVALID_MAC, @@ -138,6 +147,28 @@ enum enetc_mac_filter_class_code { #define ENETC_CLASS_CODE_LINK_DOWN BIT(0) #define ENETC_CLASS_CODE_TX_PAUSE_EN BIT(1) +/* Class-specific notifications/codes of link speed */ +enum enetc_link_speed_class_code { + ENETC_MSG_SPEED_UNKNOWN, + ENETC_MSG_SPEED_10M_HD, + ENETC_MSG_SPEED_10M_FD, + ENETC_MSG_SPEED_100M_HD, + ENETC_MSG_SPEED_100M_FD, + ENETC_MSG_SPEED_1000M, + ENETC_MSG_SPEED_2500M, + ENETC_MSG_SPEED_5G, + /* Do not add enumeration values for any speed greater than + * 5Gbps. For any speed greater than 5Gbps, its speed class + * code should follow the formula below. + * + * SPEED = (link_speed - 5000) / 1000 + ENETC_MSG_SPEED_5G + * + * The unit of link_speed should be Mbps, the max SPEED + * should <= ENETC_MSG_SPEED_MAX. + */ + ENETC_MSG_SPEED_MAX = 0xff, +}; + struct enetc_msg_swbd { void *vaddr; dma_addr_t dma; @@ -181,6 +212,16 @@ struct enetc_msg_mac_exact_filter { * cmd_id 0x0: get the current link status * cmd_id 0x1: register link status change notification * cmd_id 0x2: unregister link status change notification + * + * Link speed message, class_id 0x81. + * cmd_id 0x0: get the current link speed. Unlike the link status + * query (class 0x80), this query is only permitted for trusted VFs; + * an untrusted VF receives a permission-deny response. This is + * because the PF must take rtnl_lock() to read the link speed, so + * restricting it to trusted VFs avoids rtnl_lock contention on the + * host from a misbehaving VF. + * cmd_id 0x1: register link speed change notification, not supported yet + * cmd_id 0x2: unregister link speed change notification, not supported yet */ struct enetc_msg_generic { struct enetc_msg_header hdr; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index 79dbaf72fcff..08a9ffdd3eb0 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -230,6 +230,93 @@ static u16 enetc_msg_handle_link_status(struct enetc_pf *pf, int vf_id, return 0; } +static u16 enetc_build_link_speed_msg(int speed, int duplex) +{ + u32 speed_code = ENETC_MSG_SPEED_UNKNOWN; + + switch (speed) { + case SPEED_10: + if (duplex == DUPLEX_HALF) + speed_code = ENETC_MSG_SPEED_10M_HD; + else if (duplex == DUPLEX_FULL) + speed_code = ENETC_MSG_SPEED_10M_FD; + break; + case SPEED_100: + if (duplex == DUPLEX_HALF) + speed_code = ENETC_MSG_SPEED_100M_HD; + else if (duplex == DUPLEX_FULL) + speed_code = ENETC_MSG_SPEED_100M_FD; + break; + case SPEED_1000: + speed_code = ENETC_MSG_SPEED_1000M; + break; + case SPEED_2500: + speed_code = ENETC_MSG_SPEED_2500M; + break; + case SPEED_5000: + speed_code = ENETC_MSG_SPEED_5G; + break; + default: + if (speed < SPEED_5000) + break; + + speed_code = (speed - SPEED_5000) / SPEED_1000 + + ENETC_MSG_SPEED_5G; + if (speed_code > ENETC_MSG_SPEED_MAX) + speed_code = ENETC_MSG_SPEED_UNKNOWN; + } + + return FIELD_PREP(ENETC_PF_MSG_CLASS_ID, + ENETC_MSG_CLASS_ID_LINK_SPEED) | + FIELD_PREP(ENETC_PF_MSG_CLASS_CODE_U8, speed_code); +} + +static u16 enetc_msg_get_link_speed(struct enetc_pf *pf, int vf_id) +{ + struct enetc_ndev_priv *priv = netdev_priv(pf->si->ndev); + struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; + struct ethtool_link_ksettings link_info = {}; + + /* A malicious or malfunctioning VM could potentially spam these + * messages in a tight loop causing global rtnl_lock contention, + * which may severely starve other processes on the host that + * require rtnl_lock for routine network configuration, resulting + * in a system-wide control-plane denial of service. Therefore, + * we expect the VF query for link speed to be trusted. There's no + * need to consider the transition from trusted to untrusted here, + * as this won't cause rtnl_lock() to be called frequently. + */ + mutex_lock(&vf_state->lock); + if (!(vf_state->flags & ENETC_VF_FLAG_TRUSTED)) { + mutex_unlock(&vf_state->lock); + + return ENETC_PF_MSG_PERM_DENY; + } + mutex_unlock(&vf_state->lock); + + rtnl_lock(); + phylink_ethtool_ksettings_get(priv->phylink, &link_info); + rtnl_unlock(); + + return enetc_build_link_speed_msg(link_info.base.speed, + link_info.base.duplex); +} + +static u16 enetc_msg_handle_link_speed(struct enetc_pf *pf, int vf_id, + void *vf_msg) +{ + struct enetc_msg_header *msg_hdr = vf_msg; + + switch (msg_hdr->cmd_id) { + case ENETC_MSG_GET_CURRENT_LINK_SPEED: + return enetc_msg_get_link_speed(pf, vf_id); + case ENETC_MSG_REGISTER_SPEED_CHANGE_NOTIFIER: + case ENETC_MSG_UNREGISTER_SPEED_CHANGE_NOTIFIER: + default: + return ENETC_PF_MSG_NOTSUPP; + } +} + /* If *pf_msg is set to 0, it means that PF has responded to VF in * enetc_msg_handle_rxmsg() through enetc_pf_reply_msg(), which also * clears the corresponding VF MR bit in PSIIDR. @@ -312,6 +399,9 @@ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, case ENETC_MSG_CLASS_ID_LINK_STATUS: *pf_msg = enetc_msg_handle_link_status(pf, vf_id, msg); break; + case ENETC_MSG_CLASS_ID_LINK_SPEED: + *pf_msg = enetc_msg_handle_link_speed(pf, vf_id, msg); + break; default: dev_err_ratelimited(dev, "Unsupported message class ID: 0x%x\n", From fba13302b99616abbcec67d1d385d568ea4ec447 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:23 +0800 Subject: [PATCH 0481/2126] net: enetc: use enetc_set_si_hw_addr() to set VF MAC address Prepare for moving enetc_pf_set_vf_mac() into the enetc-pf-common driver by replacing enetc_pf_set_primary_mac_addr() with enetc_set_si_hw_addr(). This makes the VF primary MAC configuration path generic and allows future enetc v4 PF driver to reuse the same interface. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-6-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/enetc_pf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index a7bf4bfc25b7..b74d965e403e 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -207,7 +207,7 @@ static int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac) mutex_lock(&vf_state->lock); vf_state->flags |= ENETC_VF_FLAG_PF_SET_MAC; - enetc_pf_set_primary_mac_addr(&priv->si->hw, vf + 1, mac); + enetc_set_si_hw_addr(pf, vf + 1, mac); mutex_unlock(&vf_state->lock); return 0; From f37718e9210b31228975646567cfe16ccc3a4543 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:24 +0800 Subject: [PATCH 0482/2126] net: enetc: relocate enetc_pf_set_vf_mac() for common PF support Move enetc_pf_set_vf_mac() into enetc-pf-common driver as a generic interface for both ENETC v1 and v4 PF driver to use. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-7-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../net/ethernet/freescale/enetc/enetc_pf.c | 22 ------------------ .../freescale/enetc/enetc_pf_common.c | 23 +++++++++++++++++++ .../freescale/enetc/enetc_pf_common.h | 1 + 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index b74d965e403e..c467dc05510e 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -191,28 +191,6 @@ static void enetc_set_loopback(struct net_device *ndev, bool en) } } -static int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac) -{ - struct enetc_ndev_priv *priv = netdev_priv(ndev); - struct enetc_pf *pf = enetc_si_priv(priv->si); - struct enetc_vf_state *vf_state; - - if (vf >= pf->total_vfs) - return -EINVAL; - - if (!is_valid_ether_addr(mac)) - return -EADDRNOTAVAIL; - - vf_state = &pf->vf_state[vf]; - - mutex_lock(&vf_state->lock); - vf_state->flags |= ENETC_VF_FLAG_PF_SET_MAC; - enetc_set_si_hw_addr(pf, vf + 1, mac); - mutex_unlock(&vf_state->lock); - - return 0; -} - static int enetc_pf_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos, __be16 proto) { diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index 519fc90d2647..1b2ca2b31a80 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -609,5 +609,28 @@ int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting) } EXPORT_SYMBOL_GPL(enetc_pf_set_vf_trust); +int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac) +{ + struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_pf *pf = enetc_si_priv(priv->si); + struct enetc_vf_state *vf_state; + + if (vf >= pf->total_vfs) + return -EINVAL; + + if (!is_valid_ether_addr(mac)) + return -EADDRNOTAVAIL; + + vf_state = &pf->vf_state[vf]; + + mutex_lock(&vf_state->lock); + vf_state->flags |= ENETC_VF_FLAG_PF_SET_MAC; + enetc_set_si_hw_addr(pf, vf + 1, mac); + mutex_unlock(&vf_state->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(enetc_pf_set_vf_mac); + MODULE_DESCRIPTION("NXP ENETC PF common functionality driver"); MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h index bcf113efc2ef..7d7e67a12278 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h @@ -23,6 +23,7 @@ void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash); void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash); void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc); int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting); +int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac); static inline u16 enetc_get_ip_revision(struct enetc_hw *hw) { From 18c66a9a4faeb8cb088c80d7af53773ad58d35ae Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:25 +0800 Subject: [PATCH 0483/2126] net: enetc: add .ndo_set_vf_mac() to the enetc v4 driver Add .ndo_set_vf_mac() to the enetc v4 driver to configure the MAC addresses of VFs. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-8-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index e20989b6f8b4..a44d50b7fd2a 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -579,6 +579,7 @@ static const struct net_device_ops enetc4_ndev_ops = { .ndo_hwtstamp_get = enetc_hwtstamp_get, .ndo_hwtstamp_set = enetc_hwtstamp_set, .ndo_set_vf_trust = enetc_pf_set_vf_trust, + .ndo_set_vf_mac = enetc_pf_set_vf_mac, }; static struct phylink_pcs * From 261be512194db447320f3eef9846b9301ad2c375 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:26 +0800 Subject: [PATCH 0484/2126] net: enetc: move mac_filter from struct enetc_pf to struct enetc_si The mac_filter array currently resides in struct enetc_pf and is used to track unicast and multicast MAC address filters for the PF. Since struct enetc_si is the common structure shared between the PF and VF drivers, move mac_filter into struct enetc_si to prepare for MAC filter support in the VF driver. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-9-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/enetc.h | 2 ++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 6 +++--- drivers/net/ethernet/freescale/enetc/enetc_pf.c | 17 ++++++++--------- drivers/net/ethernet/freescale/enetc/enetc_pf.h | 2 -- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 0eff25b0c81b..0501cc2fc304 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -337,6 +337,8 @@ struct enetc_si { struct workqueue_struct *workqueue; struct work_struct msg_task; char msg_int_name[ENETC_INT_NAME_MAX]; + + struct enetc_mac_filter mac_filter[MADDR_TYPE]; }; #define ENETC_SI_ALIGN 32 diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index a44d50b7fd2a..eedcaf2d7bc9 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -137,7 +137,7 @@ clear_maft_entries: static void enetc4_pf_set_uc_hash_filter(struct enetc_pf *pf, struct netdev_hw_addr_list *uc) { - struct enetc_mac_filter *mac_filter = &pf->mac_filter[UC]; + struct enetc_mac_filter *mac_filter = &pf->si->mac_filter[UC]; struct netdev_hw_addr *ha; u64 hash; @@ -172,7 +172,7 @@ static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf, err = enetc4_pf_add_maft_entries(pf, uc); if (!err) { - enetc_reset_mac_addr_filter(&pf->mac_filter[UC]); + enetc_reset_mac_addr_filter(&si->mac_filter[UC]); enetc_set_si_uc_hash_filter(si, 0, 0); } @@ -182,7 +182,7 @@ static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf, static void enetc4_pf_set_mc_hash_filter(struct enetc_pf *pf, struct netdev_hw_addr_list *mc) { - struct enetc_mac_filter *mac_filter = &pf->mac_filter[MC]; + struct enetc_mac_filter *mac_filter = &pf->si->mac_filter[MC]; struct netdev_hw_addr *ha; u64 hash; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index c467dc05510e..523c71324780 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -60,10 +60,9 @@ static void enetc_add_mac_addr_em_filter(struct enetc_mac_filter *filter, filter->mac_addr_cnt++; } -static void enetc_sync_mac_filters(struct enetc_pf *pf) +static void enetc_sync_mac_filters(struct enetc_si *si) { - struct enetc_mac_filter *f = pf->mac_filter; - struct enetc_si *si = pf->si; + struct enetc_mac_filter *f = si->mac_filter; int i, pos; pos = EMETC_MAC_ADDR_FILT_RES; @@ -115,9 +114,9 @@ static void enetc_sync_mac_filters(struct enetc_pf *pf) static void enetc_pf_set_rx_mode(struct net_device *ndev) { struct enetc_ndev_priv *priv = netdev_priv(ndev); - struct enetc_pf *pf = enetc_si_priv(priv->si); bool uprom = false, mprom = false; struct enetc_mac_filter *filter; + struct enetc_si *si = priv->si; struct netdev_hw_addr *ha; bool em; @@ -133,7 +132,7 @@ static void enetc_pf_set_rx_mode(struct net_device *ndev) /* first 2 filter entries belong to PF */ if (!uprom) { /* Update unicast filters */ - filter = &pf->mac_filter[UC]; + filter = &si->mac_filter[UC]; enetc_reset_mac_addr_filter(filter); em = (netdev_uc_count(ndev) == 1); @@ -149,7 +148,7 @@ static void enetc_pf_set_rx_mode(struct net_device *ndev) if (!mprom) { /* Update multicast filters */ - filter = &pf->mac_filter[MC]; + filter = &si->mac_filter[MC]; enetc_reset_mac_addr_filter(filter); netdev_for_each_mc_addr(ha, ndev) { @@ -162,10 +161,10 @@ static void enetc_pf_set_rx_mode(struct net_device *ndev) if (!uprom || !mprom) /* update PF entries */ - enetc_sync_mac_filters(pf); + enetc_sync_mac_filters(si); - enetc_set_si_uc_promisc(priv->si, 0, uprom); - enetc_set_si_mc_promisc(priv->si, 0, mprom); + enetc_set_si_uc_promisc(si, 0, uprom); + enetc_set_si_mc_promisc(si, 0, mprom); } static void enetc_set_loopback(struct net_device *ndev, bool en) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index b3ad498f91a0..88a558649c68 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -40,8 +40,6 @@ struct enetc_pf { int num_vfs; /* number of active VFs, after sriov_init */ int total_vfs; /* max number of VFs, set for PF at probe */ struct enetc_vf_state *vf_state; - - struct enetc_mac_filter mac_filter[MADDR_TYPE]; struct enetc_msg_swbd *rxmsg; DECLARE_BITMAP(vlan_ht_filter, ENETC_VLAN_HT_SIZE); From e7ac83644e28b2ebc8e4945460ea4fc3445c5609 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:27 +0800 Subject: [PATCH 0485/2126] net: enetc: add MAC address filtering support for VFs of ENETC v4 ENETC v4 VF hardware supports MAC address filtering, but the underlying resources (the PSIPMMR register and per-SI hash filter tables) are owned by the PF. Add VSI-to-PSI mailbox messages so a VF can request MAC filter configuration from the PF, using two new command IDs under the existing MAC filter class (0x20): 1. ENETC_MSG_SET_MAC_HASH_TABLE (cmd_id 3): program the unicast and/or multicast MAC hash filter table. Unicast filtering is only allowed for a trusted VF, since it could be used to receive traffic destined for other SIs. Multicast filtering is allowed even for an untrusted VF, but limited to ENETC_VF_MC_HASH_BITS_MAX (8) buckets, enough for basic operation such as IPv6 neighbor discovery and mDNS; a trusted VF may use all 64 buckets. 2. ENETC_MSG_SET_MAC_PROMISC_MODE (cmd_id 5): enable or disable unicast/ multicast promiscuous mode, and optionally flush the hash filter table. Enabling promiscuous mode requires a trusted VF; flushing the table alone does not. The PSIPMMR register is a shared resource accessed by both enetc4_pf_set_rx_mode() and the VF message handler via a non-atomic read-modify-write, so protect these accesses with si->gen_lock to avoid lost updates on SMP. When a VF loses trusted status via ndo_set_vf_trust(), clear its unicast hash filter and disable promiscuous mode so it cannot receive traffic beyond its allowed scope. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-10-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../ethernet/freescale/enetc/enetc4_debugfs.c | 51 ++++-- .../net/ethernet/freescale/enetc/enetc4_pf.c | 7 +- .../ethernet/freescale/enetc/enetc_mailbox.h | 42 +++++ .../net/ethernet/freescale/enetc/enetc_msg.c | 160 +++++++++++++++++- .../net/ethernet/freescale/enetc/enetc_pf.h | 1 + .../freescale/enetc/enetc_pf_common.c | 72 ++++++-- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 +- 7 files changed, 302 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c index 5029038bf99f..c73722e2285f 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c @@ -6,24 +6,48 @@ #include #include -#include "enetc_pf.h" +#include "enetc_pf_common.h" #include "enetc4_debugfs.h" -static void enetc_show_si_mac_hash_filter(struct seq_file *s, int i) +static void enetc_vf_state_lock(struct enetc_pf *pf, int vf_id) { - struct enetc_si *si = s->private; - struct enetc_hw *hw = &si->hw; + struct enetc_vf_state *vf_state; + + if (vf_id < 0) + return; + + vf_state = &pf->vf_state[vf_id]; + mutex_lock(&vf_state->lock); +} + +static void enetc_vf_state_unlock(struct enetc_pf *pf, int vf_id) +{ + struct enetc_vf_state *vf_state; + + if (vf_id < 0) + return; + + vf_state = &pf->vf_state[vf_id]; + mutex_unlock(&vf_state->lock); +} + +static void enetc_show_si_mac_hash_filter(struct seq_file *s, int si_id) +{ + struct enetc_pf *pf = enetc_si_priv(s->private); + struct enetc_hw *hw = &pf->si->hw; u32 hash_h, hash_l; - hash_l = enetc_port_rd(hw, ENETC4_PSIUMHFR0(i)); - hash_h = enetc_port_rd(hw, ENETC4_PSIUMHFR1(i)); + enetc_vf_state_lock(pf, si_id - 1); + hash_l = enetc_port_rd(hw, ENETC4_PSIUMHFR0(si_id)); + hash_h = enetc_port_rd(hw, ENETC4_PSIUMHFR1(si_id)); seq_printf(s, "SI %d unicast MAC hash filter: 0x%08x%08x\n", - i, hash_h, hash_l); + si_id, hash_h, hash_l); - hash_l = enetc_port_rd(hw, ENETC4_PSIMMHFR0(i)); - hash_h = enetc_port_rd(hw, ENETC4_PSIMMHFR1(i)); + hash_l = enetc_port_rd(hw, ENETC4_PSIMMHFR0(si_id)); + hash_h = enetc_port_rd(hw, ENETC4_PSIMMHFR1(si_id)); seq_printf(s, "SI %d multicast MAC hash filter: 0x%08x%08x\n", - i, hash_h, hash_l); + si_id, hash_h, hash_l); + enetc_vf_state_unlock(pf, si_id - 1); } static int enetc_mac_filter_show(struct seq_file *s, void *data) @@ -37,7 +61,11 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data) int err = 0; int i; + /* Prevent concurrent access from causing PSIPMMR to be modified */ + spin_lock(&pf->si->gen_lock); val = enetc_port_rd(hw, ENETC4_PSIPMMR); + spin_unlock(&pf->si->gen_lock); + for (i = 0; i < num_si; i++) { seq_printf(s, "SI %d Unicast Promiscuous mode: %s\n", i, str_enabled_disabled(PSIPMMR_SI_MAC_UP(i) & val)); @@ -45,13 +73,12 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data) str_enabled_disabled(PSIPMMR_SI_MAC_MP(i) & val)); } + rtnl_lock(); /* MAC hash filter table */ for (i = 0; i < num_si; i++) enetc_show_si_mac_hash_filter(s, i); user = &pf->si->ntmp_user; - rtnl_lock(); - if (bitmap_empty(user->maft_eid_bitmap, user->maft_num_entries)) goto unlock_rtnl; diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index eedcaf2d7bc9..abe1e8dafe24 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -12,11 +12,6 @@ #define ENETC_SI_MAX_RING_NUM 8 -#define ENETC_MAC_FILTER_TYPE_UC BIT(0) -#define ENETC_MAC_FILTER_TYPE_MC BIT(1) -#define ENETC_MAC_FILTER_TYPE_ALL (ENETC_MAC_FILTER_TYPE_UC | \ - ENETC_MAC_FILTER_TYPE_MC) - static void enetc4_get_port_caps(struct enetc_pf *pf) { struct enetc_hw *hw = &pf->si->hw; @@ -528,8 +523,10 @@ static int enetc4_pf_set_rx_mode(struct net_device *ndev, type = ENETC_MAC_FILTER_TYPE_ALL; } + spin_lock(&si->gen_lock); enetc_set_si_uc_promisc(si, 0, uc_promisc); enetc_set_si_mc_promisc(si, 0, mc_promisc); + spin_unlock(&si->gen_lock); if (uc_promisc) { enetc_set_si_uc_hash_filter(si, 0, 0); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h b/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h index 832d2f6ddcd8..6fa66c863748 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h @@ -96,6 +96,17 @@ #define ENETC_PF_MSG_CLASS_CODE_U8 GENMASK(7, 0) #define ENETC_PF_MSG_CLASS_ID GENMASK(15, 8) +#define ENETC_MAC_HASH_TABLE_SIZE_64 0 +#define ENETC_MSG_MAC_HASH_SIZE GENMASK(5, 0) +#define ENETC_MSG_MAC_TYPE GENMASK(7, 6) +#define ENETC_MAC_FILTER_TYPE_UC BIT(0) +#define ENETC_MAC_FILTER_TYPE_MC BIT(1) +#define ENETC_MAC_FILTER_TYPE_ALL (ENETC_MAC_FILTER_TYPE_UC | \ + ENETC_MAC_FILTER_TYPE_MC) + +#define ENETC_MSG_MAC_FLUSH_MACS BIT(0) +#define ENETC_MSG_MAC_PROMISC_MODE BIT(1) + enum enetc_msg_class_id { /* Class ID for PSI-to-VSI messages */ ENETC_MSG_CLASS_ID_CMD_SUCCESS = 1, @@ -119,6 +130,8 @@ enum enetc_msg_class_id { enum enetc_msg_mac_filter_cmd_id { ENETC_MSG_SET_PRIMARY_MAC, + ENETC_MSG_SET_MAC_HASH_TABLE = 3, + ENETC_MSG_SET_MAC_PROMISC_MODE = 5, }; enum enetc_msg_ip_revision_cmd_id { @@ -141,6 +154,9 @@ enum enetc_msg_link_speed_cmd_id { /* Class-specific error return codes of MAC filter */ enum enetc_mac_filter_class_code { ENETC_MF_CLASS_CODE_INVALID_MAC, + ENETC_MF_CLASS_CODE_INVALID_TYPE = 4, + /* Unicast Filter Is Denied */ + ENETC_MF_CLASS_CODE_UCF_DENY = 5, }; /* Class-specific notifications/codes of link status */ @@ -204,6 +220,32 @@ struct enetc_msg_mac_exact_filter { struct enetc_mac_addr mac[]; }; +/* message format of class_id 0x20 for hash MAC filter. + * cmd_id 0x3: set MAC hash table + */ +struct enetc_msg_mac_hash_filter { + struct enetc_msg_header hdr; + /* bit 0 ~ 5: ENETC_MSG_MAC_HASH_SIZE + * bit 6~7: ENETC_MSG_MAC_TYPE + */ + u8 sz_type; + u8 resv[3]; + u32 hash_tbl[]; +}; + +/* message format of class_id 0x20 for MAC promiscuous mode. + * cmd_id 0x5: set MAC promiscuous mode + */ +struct enetc_msg_mac_promisc_mode { + struct enetc_msg_header hdr; + /* bit 0: ENETC_MSG_MAC_FLUSH_MACS + * bit 1: ENETC_MSG_MAC_PROMISC_MODE + * bit 6~7: ENETC_MSG_MAC_TYPE + */ + u8 config; + u8 resv[15]; +}; + /* The generic message format applies to the following messages: * Get IP revision message, class_id 0xf0. * cmd_id 1: get IP minor revision diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index 08a9ffdd3eb0..22f5485e968a 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -9,6 +9,11 @@ ENETC_MSG_CLASS_ID_CMD_NOT_SUPPORT) #define ENETC_PF_MSG_PERM_DENY FIELD_PREP(ENETC_PF_MSG_CLASS_ID, \ ENETC_MSG_CLASS_ID_PERMISSION_DENY) +#define ENETC_PF_MSG_INV_LEN FIELD_PREP(ENETC_PF_MSG_CLASS_ID, \ + ENETC_MSG_CLASS_ID_INVALID_MSG_LEN) +#define ENETC_PF_MSG_MF(code) (FIELD_PREP(ENETC_PF_MSG_CLASS_ID, \ + ENETC_MSG_CLASS_ID_MAC_FILTER) | \ + FIELD_PREP(ENETC_PF_MSG_CLASS_CODE, (code))) static void enetc_msg_disable_mr_int(struct enetc_pf *pf) { @@ -79,10 +84,7 @@ static u16 enetc_msg_set_vf_primary_mac_addr(struct enetc_pf *pf, int vf_id, if (!is_valid_ether_addr(addr)) { dev_err_ratelimited(dev, "VF%d attempted to set invalid MAC\n", vf_id); - pf_msg = FIELD_PREP(ENETC_PF_MSG_CLASS_ID, - ENETC_MSG_CLASS_ID_MAC_FILTER) | - FIELD_PREP(ENETC_PF_MSG_CLASS_CODE, - ENETC_MF_CLASS_CODE_INVALID_MAC); + pf_msg = ENETC_PF_MSG_MF(ENETC_MF_CLASS_CODE_INVALID_MAC); goto vf_state_unlock; } @@ -108,6 +110,130 @@ vf_state_unlock: return pf_msg; } +static u16 enetc_msg_set_vf_mac_hash_filter(struct enetc_pf *pf, int vf_id, + void *vf_msg) +{ + struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; + struct enetc_msg_mac_hash_filter *msg = vf_msg; + u16 pf_msg = ENETC_PF_MSG_SUCCESS; + struct enetc_si *si = pf->si; + int si_id = vf_id + 1; + u64 uc_hash, mc_hash; + bool trusted; + int type; + + /* Currently, hardware only supports 64 bits table size */ + if (FIELD_GET(ENETC_MSG_MAC_HASH_SIZE, msg->sz_type) != + ENETC_MAC_HASH_TABLE_SIZE_64) + return ENETC_PF_MSG_NOTSUPP; + + mutex_lock(&vf_state->lock); + + /* For an untrusted VF, unicast MAC hash filtering is not permitted. + * For multicast, the MAC hash filter is strictly limited to a maximum + * of 8 bits to satisfy its basic multicast communication requirements + * while preventing potential network abuse. + */ + trusted = !!(vf_state->flags & ENETC_VF_FLAG_TRUSTED); + type = FIELD_GET(ENETC_MSG_MAC_TYPE, msg->sz_type); + switch (type) { + case ENETC_MAC_FILTER_TYPE_UC: + if (!trusted) { + pf_msg = ENETC_PF_MSG_PERM_DENY; + goto vf_state_unlock; + } + + uc_hash = (u64)msg->hash_tbl[1] << 32 | msg->hash_tbl[0]; + enetc_set_si_uc_hash_filter(si, si_id, uc_hash); + break; + case ENETC_MAC_FILTER_TYPE_MC: + mc_hash = (u64)msg->hash_tbl[1] << 32 | msg->hash_tbl[0]; + if (!trusted && + hweight64(mc_hash) > ENETC_VF_MC_HASH_BITS_MAX) { + pf_msg = ENETC_PF_MSG_PERM_DENY; + goto vf_state_unlock; + } + + enetc_set_si_mc_hash_filter(si, si_id, mc_hash); + break; + case ENETC_MAC_FILTER_TYPE_ALL: + if (!msg->hdr.len) { + pf_msg = ENETC_PF_MSG_INV_LEN; + goto vf_state_unlock; + } + + uc_hash = (u64)msg->hash_tbl[1] << 32 | msg->hash_tbl[0]; + mc_hash = (u64)msg->hash_tbl[3] << 32 | msg->hash_tbl[2]; + + if (!trusted && + (hweight64(mc_hash) <= ENETC_VF_MC_HASH_BITS_MAX)) { + enetc_set_si_mc_hash_filter(si, si_id, mc_hash); + pf_msg = ENETC_PF_MSG_MF(ENETC_MF_CLASS_CODE_UCF_DENY); + goto vf_state_unlock; + } + + if (!trusted) { + pf_msg = ENETC_PF_MSG_PERM_DENY; + goto vf_state_unlock; + } + + enetc_set_si_uc_hash_filter(si, si_id, uc_hash); + enetc_set_si_mc_hash_filter(si, si_id, mc_hash); + break; + default: + pf_msg = ENETC_PF_MSG_MF(ENETC_MF_CLASS_CODE_INVALID_TYPE); + } + +vf_state_unlock: + mutex_unlock(&vf_state->lock); + + return pf_msg; +} + +static u16 enetc_msg_set_vf_mac_promisc_mode(struct enetc_pf *pf, int vf_id, + void *vf_msg) +{ + struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; + struct enetc_msg_mac_promisc_mode *msg = vf_msg; + u16 pf_msg = ENETC_PF_MSG_SUCCESS; + struct enetc_si *si = pf->si; + bool promisc, flush_macs; + int si_id = vf_id + 1; + int type; + + flush_macs = !!(msg->config & ENETC_MSG_MAC_FLUSH_MACS); + type = FIELD_GET(ENETC_MSG_MAC_TYPE, msg->config); + if (!type) + return ENETC_PF_MSG_MF(ENETC_MF_CLASS_CODE_INVALID_TYPE); + + mutex_lock(&vf_state->lock); + + promisc = !!(msg->config & ENETC_MSG_MAC_PROMISC_MODE); + if (promisc && !(vf_state->flags & ENETC_VF_FLAG_TRUSTED)) { + pf_msg = ENETC_PF_MSG_PERM_DENY; + goto vf_state_unlock; + } + + spin_lock(&si->gen_lock); + if (type & ENETC_MAC_FILTER_TYPE_UC) + enetc_set_si_uc_promisc(si, si_id, promisc); + + if (type & ENETC_MAC_FILTER_TYPE_MC) + enetc_set_si_mc_promisc(si, si_id, promisc); + spin_unlock(&si->gen_lock); + + if ((type & ENETC_MAC_FILTER_TYPE_UC) && flush_macs) + enetc_set_si_uc_hash_filter(si, si_id, 0); + + if ((type & ENETC_MAC_FILTER_TYPE_MC) && flush_macs) + enetc_set_si_mc_hash_filter(si, si_id, 0); + +vf_state_unlock: + mutex_unlock(&vf_state->lock); + + return pf_msg; +} + static u16 enetc_msg_handle_mac_filter(struct enetc_pf *pf, int vf_id, void *vf_msg) { @@ -116,6 +242,10 @@ static u16 enetc_msg_handle_mac_filter(struct enetc_pf *pf, int vf_id, switch (msg_hdr->cmd_id) { case ENETC_MSG_SET_PRIMARY_MAC: return enetc_msg_set_vf_primary_mac_addr(pf, vf_id, vf_msg); + case ENETC_MSG_SET_MAC_HASH_TABLE: + return enetc_msg_set_vf_mac_hash_filter(pf, vf_id, vf_msg); + case ENETC_MSG_SET_MAC_PROMISC_MODE: + return enetc_msg_set_vf_mac_promisc_mode(pf, vf_id, vf_msg); default: return ENETC_PF_MSG_NOTSUPP; } @@ -333,8 +463,7 @@ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, if (msg_size > ENETC_DEFAULT_MSG_SIZE) { dev_err_ratelimited(dev, "Invalid message size: %u\n", msg_size); - *pf_msg = FIELD_PREP(ENETC_PF_MSG_CLASS_ID, - ENETC_MSG_CLASS_ID_INVALID_MSG_LEN); + *pf_msg = ENETC_PF_MSG_INV_LEN; return; } @@ -352,6 +481,14 @@ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, } memcpy(msg, msg_swbd->vaddr, msg_size); + msg_hdr = (struct enetc_msg_header *)msg; + + /* Check message length whether is changed */ + if (ENETC_MSG_SIZE(msg_hdr->len) != msg_size) { + *pf_msg = ENETC_PF_MSG_INV_LEN; + goto free_msg; + } + if (!enetc_msg_check_crc16(msg, msg_size)) { dev_err_ratelimited(dev, "VSI to PSI Message CRC16 error\n"); *pf_msg = FIELD_PREP(ENETC_PF_MSG_CLASS_ID, @@ -362,7 +499,6 @@ static void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int vf_id, /* Default to not supported */ *pf_msg = ENETC_PF_MSG_NOTSUPP; - msg_hdr = (struct enetc_msg_header *)msg; /* Currently, asynchronous actions are not supported */ if (FIELD_GET(ENETC_VF_MSG_COOKIE, msg_hdr->cookie)) { @@ -536,6 +672,7 @@ static void enetc_msg_clear_vf_config(struct enetc_pf *pf, int vf_id) { struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; struct enetc_si *si = pf->si; + int si_id = vf_id + 1; /* For ENETC v1, we only support setting the VF's MAC address via * VSI-to-PSI messages, so there is no configuration to clear. @@ -543,9 +680,18 @@ static void enetc_msg_clear_vf_config(struct enetc_pf *pf, int vf_id) if (is_enetc_rev1(si)) return; + mutex_lock(&vf_state->lock); + spin_lock(&si->gen_lock); vf_state->msg_fail_cnt = 0; + enetc_set_si_uc_promisc(si, si_id, false); + enetc_set_si_mc_promisc(si, si_id, false); spin_unlock(&si->gen_lock); + + enetc_set_si_uc_hash_filter(si, si_id, 0); + enetc_set_si_mc_hash_filter(si, si_id, 0); + + mutex_unlock(&vf_state->lock); } static void enetc_msg_psi_free(struct enetc_pf *pf) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index 88a558649c68..c5eda6c8eaf0 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -6,6 +6,7 @@ #define ENETC_PF_NUM_RINGS 8 #define ENETC_VLAN_HT_SIZE 64 +#define ENETC_VF_MC_HASH_BITS_MAX 8 /* For untrusted VFs */ enum enetc_vf_flags { ENETC_VF_FLAG_PF_SET_MAC = BIT(0), diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index 1b2ca2b31a80..9dbb0a1417ea 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -151,26 +151,44 @@ void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash) } EXPORT_SYMBOL_GPL(enetc_set_si_uc_hash_filter); +static void enetc_get_psimmhfr_offsets(struct enetc_si *si, int si_id, + int *psimmhfr0, int *psimmhfr1) +{ + if (is_enetc_rev1(si)) { + bool err = si->errata & ENETC_ERR_UCMCSWP; + + *psimmhfr0 = ENETC_PSIMMHFR0(si_id, err); + *psimmhfr1 = ENETC_PSIMMHFR1(si_id); + } else { + *psimmhfr0 = ENETC4_PSIMMHFR0(si_id); + *psimmhfr1 = ENETC4_PSIMMHFR1(si_id); + } +} + void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash) { int psimmhfr0_off, psimmhfr1_off; struct enetc_hw *hw = &si->hw; - if (is_enetc_rev1(si)) { - bool err = si->errata & ENETC_ERR_UCMCSWP; - - psimmhfr0_off = ENETC_PSIMMHFR0(si_id, err); - psimmhfr1_off = ENETC_PSIMMHFR1(si_id); - } else { - psimmhfr0_off = ENETC4_PSIMMHFR0(si_id); - psimmhfr1_off = ENETC4_PSIMMHFR1(si_id); - } - + enetc_get_psimmhfr_offsets(si, si_id, &psimmhfr0_off, &psimmhfr1_off); enetc_port_wr(hw, psimmhfr0_off, lower_32_bits(hash)); enetc_port_wr(hw, psimmhfr1_off, upper_32_bits(hash)); } EXPORT_SYMBOL_GPL(enetc_set_si_mc_hash_filter); +static u64 enetc_get_si_mc_hash_filter(struct enetc_si *si, int si_id) +{ + int psimmhfr0_off, psimmhfr1_off; + struct enetc_hw *hw = &si->hw; + u32 hash_h, hash_l; + + enetc_get_psimmhfr_offsets(si, si_id, &psimmhfr0_off, &psimmhfr1_off); + hash_l = enetc_port_rd(hw, psimmhfr0_off); + hash_h = enetc_port_rd(hw, psimmhfr1_off); + + return ((u64)hash_h << 32) | hash_l; +} + void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc) { struct enetc_hw *hw = &si->hw; @@ -591,6 +609,8 @@ int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting) struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_pf *pf = enetc_si_priv(priv->si); struct enetc_vf_state *vf_state; + struct enetc_si *si = priv->si; + int si_id = vf + 1; if (vf >= pf->total_vfs) return -EINVAL; @@ -598,11 +618,39 @@ int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting) vf_state = &pf->vf_state[vf]; mutex_lock(&vf_state->lock); - if (setting) + if (setting) { vf_state->flags |= ENETC_VF_FLAG_TRUSTED; - else + } else { + u64 hash; + vf_state->flags &= ~ENETC_VF_FLAG_TRUSTED; + /* For ENETC v1, we only support setting the VF's MAC address + * via VSI-to-PSI messages. Unicast and multicast promiscuous + * mode and hash filters are not supported, so there is no need + * to clear these configurations. + */ + if (is_enetc_rev1(si)) + goto vf_state_unlock; + + /* Disable unicast and multicast promiscuous modes */ + spin_lock(&si->gen_lock); + enetc_set_si_uc_promisc(si, si_id, false); + enetc_set_si_mc_promisc(si, si_id, false); + spin_unlock(&si->gen_lock); + + /* Clear unicast hash filter */ + enetc_set_si_uc_hash_filter(si, si_id, 0); + + /* Clear multicast hash filter if its set bits exceed + * ENETC_VF_MC_HASH_BITS_MAX. + */ + hash = enetc_get_si_mc_hash_filter(si, si_id); + if (hweight64(hash) > ENETC_VF_MC_HASH_BITS_MAX) + enetc_set_si_mc_hash_filter(si, si_id, 0); + } + +vf_state_unlock: mutex_unlock(&vf_state->lock); return 0; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c index 7dcb4a0246f5..a60af40d8546 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c @@ -107,8 +107,12 @@ static int enetc_msg_vsi_send(struct enetc_si *si, struct enetc_msg_swbd *msg) case ENETC_MSG_CLASS_ID_CMD_TIMEOUT: err = -ETIME; break; - case ENETC_MSG_CLASS_ID_INVALID_MSG_LEN: case ENETC_MSG_CLASS_ID_MAC_FILTER: + if (FIELD_GET(ENETC_PF_MSG_CLASS_CODE, pf_msg) == + ENETC_MF_CLASS_CODE_UCF_DENY) + return -EACCES; + fallthrough; + case ENETC_MSG_CLASS_ID_INVALID_MSG_LEN: err = -EINVAL; break; case ENETC_MSG_CLASS_ID_CMD_NOT_PERMITTED: From 76fb8ad66d3dc3d06cb6ad7bc8ed70a450829663 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:28 +0800 Subject: [PATCH 0486/2126] net: enetc: simplify and rename PSIIER enable/disable helpers The PSIIER register controls two categories of interrupt sources: message-receive (MR) interrupts, which fire when a VF sends a mailbox message to the PSI, and VF FLR interrupts, which fire when a VF performs a Function Level Reset. The current helpers enetc_msg_enable_mr_int() and enetc_msg_disable_mr_int() use a read-modify-write sequence to update only the MR bits in PSIIER, intending to preserve any other bits that may be set. However, VF FLR interrupt support is not yet implemented, so PSIIER only ever holds MR interrupt bits at this point. The read-modify-write is therefore unnecessary overhead. Simplify enetc_disable_psiier_interrupts() to write 0 directly to PSIIER, disabling all interrupt sources at once, and simplify enetc_enable_psiier_interrupts() to write the MR mask directly without reading the current register value first. Rename both helpers from the MR-specific names to names that reflect their true scope, i.e. managing all PSIIER interrupt sources rather than just the MR bits. This prepares the code for a future patch that adds VF FLR interrupt support, at which point enetc_enable_psiier_interrupts() will be extended to also set the corresponding FLR bits. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-11-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../net/ethernet/freescale/enetc/enetc_msg.c | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index 22f5485e968a..aa37a0123274 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -15,23 +15,17 @@ ENETC_MSG_CLASS_ID_MAC_FILTER) | \ FIELD_PREP(ENETC_PF_MSG_CLASS_CODE, (code))) -static void enetc_msg_disable_mr_int(struct enetc_pf *pf) +static void enetc_disable_psiier_interrupts(struct enetc_pf *pf) { struct enetc_hw *hw = &pf->si->hw; - u32 psiier; - psiier = enetc_rd(hw, ENETC_PSIIER) & ~ENETC_PSIMR_MASK(pf->num_vfs); - - /* disable MR int source(s) */ - enetc_wr(hw, ENETC_PSIIER, psiier); + enetc_wr(hw, ENETC_PSIIER, 0); } -static void enetc_msg_enable_mr_int(struct enetc_pf *pf) +static void enetc_enable_psiier_interrupts(struct enetc_pf *pf) { + u32 psiier = ENETC_PSIMR_MASK(pf->num_vfs); struct enetc_hw *hw = &pf->si->hw; - u32 psiier; - - psiier = enetc_rd(hw, ENETC_PSIIER) | ENETC_PSIMR_MASK(pf->num_vfs); enetc_wr(hw, ENETC_PSIIER, psiier); } @@ -41,7 +35,7 @@ static irqreturn_t enetc_msg_psi_msix(int irq, void *data) struct enetc_si *si = (struct enetc_si *)data; struct enetc_pf *pf = enetc_si_priv(si); - enetc_msg_disable_mr_int(pf); + enetc_disable_psiier_interrupts(pf); schedule_work(&si->msg_task); return IRQ_HANDLED; @@ -581,7 +575,7 @@ static void enetc_msg_task(struct work_struct *work) } out: - enetc_msg_enable_mr_int(pf); + enetc_enable_psiier_interrupts(pf); } /* Init */ @@ -656,8 +650,8 @@ static int enetc_msg_psi_init(struct enetc_pf *pf) /* set one IRQ entry for PSI message receive notification (SI int) */ enetc_wr(&si->hw, ENETC_SIMSIVR, ENETC_SI_INT_IDX); - /* enable MR interrupts */ - enetc_msg_enable_mr_int(pf); + /* enable PSIIER interrupts */ + enetc_enable_psiier_interrupts(pf); return 0; @@ -699,16 +693,16 @@ static void enetc_msg_psi_free(struct enetc_pf *pf) struct enetc_si *si = pf->si; int i; - /* disable MR interrupts */ - enetc_msg_disable_mr_int(pf); + /* disable PSIIER interrupts */ + enetc_disable_psiier_interrupts(pf); /* de-register message passing interrupt handler */ free_irq(pci_irq_vector(si->pdev, ENETC_SI_INT_IDX), si); cancel_work_sync(&si->msg_task); - /* MR interrupts may be re-enabled by workqueue */ - enetc_msg_disable_mr_int(pf); + /* PSIIER interrupts may be re-enabled by workqueue */ + enetc_disable_psiier_interrupts(pf); for (i = 0; i < pf->num_vfs; i++) { enetc_msg_free_mbx(si, i); From f539a68b0aa1f77502e8dc0c77e19d5ce80f88d5 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:29 +0800 Subject: [PATCH 0487/2126] net: enetc: restore VF MAC promiscuous mode after FLR for ENETC v4 On ENETC v4, when VF performs a PCI FLR, it resets PSIPMMR[SIn_MAC_UP] and PSIPMMR[SIn_MAC_MP] bits, which control the unicast and multicast promiscuous mode for the corresponding SI. The reset (default) value of these bits enables promiscuous mode, meaning that after a VF FLR, the SI is left in promiscuous mode regardless of the configuration set by the PF driver prior to the reset. This is a potential security vulnerability: a malicious VM could deliberately trigger a VF FLR to force promiscuous mode on its SI, allowing it to capture network traffic not destined for that VF. To mitigate this, make the following changes: - Add ENETC_VF_FLAG_UC_PROMISC and ENETC_VF_FLAG_MC_PROMISC to enetc_vf_flags to track the PF-managed promiscuous mode state for each VF. - Update enetc_msg_set_vf_mac_promisc_mode() to keep these flags in sync whenever a VF requests a promiscuous mode change via messaging. - Update enetc_pf_set_vf_trust() to clear both promisc flags when a VF is untrusted, so that a subsequent FLR cannot restore promiscuous mode that the PF has already revoked. - Add a vf_flr_handler callback to enetc_pf_ops. The ENETC v4 implementation re-applies the tracked UC/MC promiscuous mode settings to the hardware after each FLR, ensuring the hardware state matches the PF-managed policy rather than the insecure reset default. - Add enetc_vf_flr_handler() in enetc_msg.c to detect FLR events via the PSIIDR register and dispatch to the vf_flr_handler callback. Invoke it at the start of enetc_msg_task() before processing VF messages. - Enable FLR interrupts in PSIIER only when a vf_flr_handler callback is registered, keeping ENETC v1 behavior unchanged. Signed-off-by: Wei Fang Reviewed-by: Claudiu Manoil Link: https://patch.msgid.link/20260909100733.1139689-12-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../net/ethernet/freescale/enetc/enetc4_pf.c | 20 ++++++++ .../net/ethernet/freescale/enetc/enetc_hw.h | 12 +++++ .../net/ethernet/freescale/enetc/enetc_msg.c | 50 +++++++++++++++++++ .../net/ethernet/freescale/enetc/enetc_pf.h | 3 ++ .../freescale/enetc/enetc_pf_common.c | 4 +- 5 files changed, 88 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index abe1e8dafe24..6a9b1e079ae2 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -212,9 +212,29 @@ static void enetc4_pf_set_mac_filter(struct enetc_pf *pf, int type, enetc4_pf_set_mc_hash_filter(pf, mc); } +static void enetc4_pf_vf_flr_handler(struct enetc_pf *pf, int vf_id) +{ + struct enetc_vf_state *vf_state; + bool uc_promisc, mc_promisc; + + vf_state = &pf->vf_state[vf_id]; + mutex_lock(&vf_state->lock); + + uc_promisc = !!(vf_state->flags & ENETC_VF_FLAG_UC_PROMISC); + mc_promisc = !!(vf_state->flags & ENETC_VF_FLAG_MC_PROMISC); + + spin_lock(&pf->si->gen_lock); + enetc_set_si_uc_promisc(pf->si, vf_id + 1, uc_promisc); + enetc_set_si_mc_promisc(pf->si, vf_id + 1, mc_promisc); + spin_unlock(&pf->si->gen_lock); + + mutex_unlock(&vf_state->lock); +} + static const struct enetc_pf_ops enetc4_pf_ops = { .set_si_primary_mac = enetc4_pf_set_si_primary_mac, .get_si_primary_mac = enetc4_pf_get_si_primary_mac, + .vf_flr_handler = enetc4_pf_vf_flr_handler, }; static int enetc4_pf_struct_init(struct enetc_si *si) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h index f97602714118..c18ad8b9b071 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -110,6 +110,18 @@ static inline u32 enetc_vsi_set_msize(u32 size) #define ENETC_PSIIER 0xa00 #define ENETC_PSIIDR 0xa08 + +/* VF FLR interrupt mask, n is the active number of VFs. + * It is available for ENETC_PSIIER and ENETC_PSIIDR registers. + */ +#define ENETC_VFFLR_MASK(n) \ + ({ typeof(n) _n = (n); (_n) ? GENMASK(16 + (_n), 17) : 0; }) + +/* VF FLR interrupt bit, n is VF index. It is available + * for ENETC_PSIIER and ENETC_PSIIDR registers. + */ +#define ENETC_VFFLR_BIT(n) BIT(17 + (n)) + #define ENETC_SITXIDR 0xa18 #define ENETC_SIRXIDR 0xa28 #define ENETC_SIMSIVR 0xa30 diff --git a/drivers/net/ethernet/freescale/enetc/enetc_msg.c b/drivers/net/ethernet/freescale/enetc/enetc_msg.c index aa37a0123274..ff99937815c0 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_msg.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_msg.c @@ -27,6 +27,9 @@ static void enetc_enable_psiier_interrupts(struct enetc_pf *pf) u32 psiier = ENETC_PSIMR_MASK(pf->num_vfs); struct enetc_hw *hw = &pf->si->hw; + if (pf->ops->vf_flr_handler) + psiier |= ENETC_VFFLR_MASK(pf->num_vfs); + enetc_wr(hw, ENETC_PSIIER, psiier); } @@ -208,6 +211,20 @@ static u16 enetc_msg_set_vf_mac_promisc_mode(struct enetc_pf *pf, int vf_id, goto vf_state_unlock; } + if (type & ENETC_MAC_FILTER_TYPE_UC) { + if (promisc) + vf_state->flags |= ENETC_VF_FLAG_UC_PROMISC; + else + vf_state->flags &= ~ENETC_VF_FLAG_UC_PROMISC; + } + + if (type & ENETC_MAC_FILTER_TYPE_MC) { + if (promisc) + vf_state->flags |= ENETC_VF_FLAG_MC_PROMISC; + else + vf_state->flags &= ~ENETC_VF_FLAG_MC_PROMISC; + } + spin_lock(&si->gen_lock); if (type & ENETC_MAC_FILTER_TYPE_UC) enetc_set_si_uc_promisc(si, si_id, promisc); @@ -542,6 +559,29 @@ free_msg: kfree(msg); } +static void enetc_vf_flr_handler(struct enetc_pf *pf) +{ + u32 flr_mask = ENETC_VFFLR_MASK(pf->num_vfs); + struct enetc_hw *hw = &pf->si->hw; + u32 flr_status; + + if (!pf->ops->vf_flr_handler) + return; + + flr_status = enetc_rd(hw, ENETC_PSIIDR) & flr_mask; + if (!flr_status) + return; + + for (int i = 0; i < pf->num_vfs; i++) { + if (!(ENETC_VFFLR_BIT(i) & flr_status)) + continue; + + /* Clear FLR interrupt status, W1C */ + enetc_wr(hw, ENETC_PSIIDR, ENETC_VFFLR_BIT(i)); + pf->ops->vf_flr_handler(pf, i); + } +} + static void enetc_msg_task(struct work_struct *work) { struct enetc_si *si = container_of(work, struct enetc_si, msg_task); @@ -550,6 +590,8 @@ static void enetc_msg_task(struct work_struct *work) u32 mr_status, mr_mask; int i; + enetc_vf_flr_handler(pf); + mr_mask = ENETC_PSIMR_MASK(pf->num_vfs); mr_status = (enetc_rd(hw, ENETC_PSIMSGRR) & mr_mask) | (enetc_rd(hw, ENETC_PSIIDR) & mr_mask); @@ -676,6 +718,14 @@ static void enetc_msg_clear_vf_config(struct enetc_pf *pf, int vf_id) mutex_lock(&vf_state->lock); + /* VF may set these flags by mailbox messages, so need to clear these + * flags when enetc_msg_psi_free() is called. PF-set flags (TRUSTED, + * PF_SET_MAC) are not cleared, because these flags are unrelated to + * whether SR-IOV is enabled or disabled. + */ + vf_state->flags &= ~(ENETC_VF_FLAG_UC_PROMISC | + ENETC_VF_FLAG_MC_PROMISC); + spin_lock(&si->gen_lock); vf_state->msg_fail_cnt = 0; enetc_set_si_uc_promisc(si, si_id, false); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index c5eda6c8eaf0..1a9fa3714c3c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -11,6 +11,8 @@ enum enetc_vf_flags { ENETC_VF_FLAG_PF_SET_MAC = BIT(0), ENETC_VF_FLAG_TRUSTED = BIT(1), + ENETC_VF_FLAG_UC_PROMISC = BIT(2), + ENETC_VF_FLAG_MC_PROMISC = BIT(3), }; struct enetc_vf_state { @@ -34,6 +36,7 @@ struct enetc_pf_ops { struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf, struct mii_bus *bus); void (*destroy_pcs)(struct phylink_pcs *pcs); int (*enable_psfp)(struct enetc_ndev_priv *priv); + void (*vf_flr_handler)(struct enetc_pf *pf, int vf_id); }; struct enetc_pf { diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index 9dbb0a1417ea..86958f1e9cd3 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -623,7 +623,9 @@ int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting) } else { u64 hash; - vf_state->flags &= ~ENETC_VF_FLAG_TRUSTED; + vf_state->flags &= ~(ENETC_VF_FLAG_TRUSTED | + ENETC_VF_FLAG_UC_PROMISC | + ENETC_VF_FLAG_MC_PROMISC); /* For ENETC v1, we only support setting the VF's MAC address * via VSI-to-PSI messages. Unicast and multicast promiscuous From fd793705e62f055b94d540a9381740fa67089818 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:30 +0800 Subject: [PATCH 0488/2126] net: enetc: add VF support for i.MX94 and i.MX95 Add VF support for the i.MX94 and i.MX95 platforms. Compared to the LS1028A ENETC, the VF device ID is updated to 0xef00, so add it to the VF driver's PCI device ID table. Also add the enetc4 SI ops and VF driver data, and wire up .sriov_configure for the enetc4 PF driver so that VFs can be created and torn down on these SoCs. The number of VFs is not decided by the driver. It is determined by each ENETC instance's SR-IOV hardware capability, reported through the PCI SR-IOV TotalVFs field and configured by the SoC integration and device tree. The driver derives it from pci_sriov_get_totalvfs() in enetc_init_sriov_resources(); an instance that advertises zero VFs simply cannot enable SR-IOV. So there is no driver-side revision or device-ID check bounding the VF count. For reference, the per-instance VF capability on these SoCs is: - i.MX95 (v4.1): each ENETC instance supports 2 VFs. - i.MX94 (v4.3) has two kinds of ENETC: - standalone ENETC, the same instance type as on i.MX95, but on i.MX94 it advertises no VFs; - internal ENETC connected to the CPU port of the NETC switch, which supports 3 VFs. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-13-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/Kconfig | 1 + drivers/net/ethernet/freescale/enetc/enetc.c | 15 ++++++++++++++ .../net/ethernet/freescale/enetc/enetc4_hw.h | 1 + .../net/ethernet/freescale/enetc/enetc4_pf.c | 4 ++++ .../ethernet/freescale/enetc/enetc_ethtool.c | 6 ++++++ .../net/ethernet/freescale/enetc/enetc_vf.c | 20 ++++++++++++++++++- 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/enetc/Kconfig b/drivers/net/ethernet/freescale/enetc/Kconfig index db5c17a44613..f425f82a6213 100644 --- a/drivers/net/ethernet/freescale/enetc/Kconfig +++ b/drivers/net/ethernet/freescale/enetc/Kconfig @@ -69,6 +69,7 @@ config FSL_ENETC_VF depends on PCI_MSI select FSL_ENETC_CORE select FSL_ENETC_MDIO + select NXP_NTMP select PHYLINK select DIMLIB select CRC_ITU_T diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 80f0082f6c63..803c5c541a5c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -3794,6 +3794,13 @@ static const struct enetc_drvdata enetc_vf_data = { .eth_ops = &enetc_vf_ethtool_ops, }; +static const struct enetc_drvdata enetc4_vf_data = { + .sysclk_freq = ENETC_CLK_333M, + .tx_csum = true, + .max_frags = ENETC4_MAX_SKB_FRAGS, + .eth_ops = &enetc_vf_ethtool_ops, +}; + static const struct enetc_platform_info enetc_info[] = { { .revision = ENETC_REV_1_0, .dev_id = ENETC_DEV_ID_PF, @@ -3807,6 +3814,10 @@ static const struct enetc_platform_info enetc_info[] = { .dev_id = ENETC_DEV_ID_VF, .data = &enetc_vf_data, }, + { .revision = ENETC_REV_4_1, + .dev_id = NXP_ENETC_VF_DEV_ID, + .data = &enetc4_vf_data, + }, { .revision = ENETC_REV_4_3, .dev_id = NXP_ENETC_PPM_DEV_ID, @@ -3816,6 +3827,10 @@ static const struct enetc_platform_info enetc_info[] = { .dev_id = NXP_ENETC_PF_DEV_ID, .data = &enetc4_pf_data, }, + { .revision = ENETC_REV_4_3, + .dev_id = NXP_ENETC_VF_DEV_ID, + .data = &enetc4_vf_data, + }, }; int enetc_get_driver_data(struct enetc_si *si) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h index 09025e7a2a3a..e23d8d82d2ba 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h @@ -12,6 +12,7 @@ #define NXP_ENETC_VENDOR_ID 0x1131 #define NXP_ENETC_PF_DEV_ID 0xe101 #define NXP_ENETC_PPM_DEV_ID 0xe110 +#define NXP_ENETC_VF_DEV_ID 0xef00 /**********************Station interface registers************************/ /* Station interface LSO segmentation flag mask register 0/1 */ diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index 6a9b1e079ae2..24c1fd869c2c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -1158,6 +1158,9 @@ static void enetc4_pf_remove(struct pci_dev *pdev) struct enetc_si *si = pci_get_drvdata(pdev); struct enetc_pf *pf = enetc_si_priv(si); + if (pf->num_vfs) + enetc_sriov_configure(pdev, 0); + enetc_remove_debugfs(si); enetc4_pf_netdev_destroy(si); enetc4_pf_free(pf); @@ -1175,6 +1178,7 @@ static struct pci_driver enetc4_pf_driver = { .id_table = enetc4_pf_id_table, .probe = enetc4_pf_probe, .remove = enetc4_pf_remove, + .sriov_configure = enetc_sriov_configure, }; module_pci_driver(enetc4_pf_driver); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c index 07b7832f2427..7965dfd06f5f 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c @@ -859,6 +859,9 @@ static int enetc_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *rxnfc, struct enetc_ndev_priv *priv = netdev_priv(ndev); int i, j; + if (!is_enetc_rev1(priv->si)) + return -EOPNOTSUPP; + switch (rxnfc->cmd) { case ETHTOOL_GRXCLSRLCNT: /* total number of entries */ @@ -903,6 +906,9 @@ static int enetc_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *rxnfc) struct enetc_ndev_priv *priv = netdev_priv(ndev); int err; + if (!is_enetc_rev1(priv->si)) + return -EOPNOTSUPP; + switch (rxnfc->cmd) { case ETHTOOL_SRXCLSRLINS: if (rxnfc->fs.location >= priv->si->num_fs_entries) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c index a60af40d8546..322705202d49 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c @@ -285,6 +285,12 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ndev->features |= NETIF_F_RXHASH; } + if (si->drvdata->tx_csum) + priv->active_offloads |= ENETC_F_TXCSUM; + + if (si->hw_features & ENETC_SI_F_LSO) + priv->active_offloads |= ENETC_F_LSO; + /* pick up primary MAC address from SI */ enetc_load_primary_mac_addr(&si->hw, ndev); } @@ -296,6 +302,13 @@ static const struct enetc_si_ops enetc_vsi_ops = { .teardown_cbdr = enetc_teardown_cbdr, }; +static const struct enetc_si_ops enetc4_vsi_ops = { + .get_rss_table = enetc4_get_rss_table, + .set_rss_table = enetc4_set_rss_table, + .setup_cbdr = enetc4_setup_cbdr, + .teardown_cbdr = enetc4_teardown_cbdr, +}; + static int enetc_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -311,7 +324,11 @@ static int enetc_vf_probe(struct pci_dev *pdev, si = pci_get_drvdata(pdev); enetc_vf_get_revision(si); - si->ops = &enetc_vsi_ops; + if (is_enetc_rev1(si)) + si->ops = &enetc_vsi_ops; + else + si->ops = &enetc4_vsi_ops; + err = enetc_get_driver_data(si); if (err) { dev_err_probe(&pdev->dev, err, @@ -413,6 +430,7 @@ static void enetc_vf_remove(struct pci_dev *pdev) static const struct pci_device_id enetc_vf_id_table[] = { { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, ENETC_DEV_ID_VF) }, + { PCI_DEVICE(NXP_ENETC_VENDOR_ID, NXP_ENETC_VF_DEV_ID) }, { 0, } /* End of table. */ }; MODULE_DEVICE_TABLE(pci, enetc_vf_id_table); From e05f2902925e494f5c406afcbe4f7ac518ecb077 Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:31 +0800 Subject: [PATCH 0489/2126] net: enetc: implement ndo_set_rx_mode_async for ENETC v4 VF An ENETC VF sends MAC filter changes to the PF over the VSI mailbox, whose send path may sleep for up to 200ms waiting for completion. Since the legacy ndo_set_rx_mode runs in atomic context, use ndo_set_rx_mode_async instead, which runs from a workqueue under rtnl_lock and receives pre-snapshotted unicast and multicast address lists from the core. Add two helpers built on the VSI mailbox: - enetc_vf_set_mac_promisc() sends a promiscuous mode message for a given filter type (unicast, multicast or both). - enetc_vf_set_mac_hash_filter() sends the 64-bit MAC hash filter table, built from the snapshotted address lists. The callback picks the configuration from the current netdev flags: - IFF_PROMISC: enable promiscuous mode for both unicast and multicast. - IFF_ALLMULTI: enable multicast promiscuous mode, disable unicast promiscuous mode and apply a unicast hash filter. - otherwise: disable promiscuous mode and apply both unicast and multicast hash filters. These requests are subject to the PF-side ENETC_VF_FLAG_TRUSTED check. For an untrusted VF (the default) the PF denies promiscuous mode and unicast hash filtering, so only the multicast hash filter is applied, limited to ENETC_VF_MC_HASH_BITS_MAX buckets. Mark a VF trusted via 'ip link set vf N trust on' for the full behaviour. Set IFF_UNICAST_FLT for ENETC v4 VFs so the stack does not needlessly fall back to full promiscuous mode; whether a unicast hash filter is actually programmed still depends on the PF trust policy. Since a denied request always fails, map -EOPNOTSUPP, -EACCES and -EPERM to 0 so the core does not retry an operation that can never succeed. ENETC v1 (LS1028A) does not support VF-to-PF MAC filter messaging and keeps using the legacy ndev ops. On VF removal, disable promiscuous mode and clear the MAC filters, so that stale configuration does not persist if the VF is later bound to another driver. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-14-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../net/ethernet/freescale/enetc/enetc_vf.c | 214 +++++++++++++++++- 1 file changed, 213 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c index 322705202d49..8cf38c426dae 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c @@ -213,6 +213,193 @@ static int enetc_vf_setup_tc(struct net_device *ndev, enum tc_setup_type type, } } +static int enetc_vf_set_mac_promisc(struct enetc_si *si, int type, + bool promisc, bool flush_macs) +{ + struct enetc_msg_mac_promisc_mode *msg; + struct device *dev = &si->pdev->dev; + struct enetc_msg_swbd msg_swbd; + + if (!(type & ENETC_MAC_FILTER_TYPE_ALL)) + return -EINVAL; + + msg_swbd.size = ALIGN(sizeof(*msg), ENETC_MSG_ALIGN); + msg_swbd.vaddr = dma_alloc_coherent(dev, msg_swbd.size, + &msg_swbd.dma, GFP_KERNEL); + if (!msg_swbd.vaddr) + return -ENOMEM; + + msg = (struct enetc_msg_mac_promisc_mode *)msg_swbd.vaddr; + msg->config = FIELD_PREP(ENETC_MSG_MAC_TYPE, + type & ENETC_MAC_FILTER_TYPE_ALL); + msg->config |= FIELD_PREP(ENETC_MSG_MAC_PROMISC_MODE, promisc); + msg->config |= FIELD_PREP(ENETC_MSG_MAC_FLUSH_MACS, flush_macs); + enetc_msg_fill_common_hdr(&msg_swbd, ENETC_MSG_CLASS_ID_MAC_FILTER, + ENETC_MSG_SET_MAC_PROMISC_MODE, 0, 0); + + return enetc_msg_vsi_send(si, &msg_swbd); +} + +static int enetc_vf_set_mac_hash_filter(struct enetc_si *si, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc) +{ + struct enetc_msg_mac_hash_filter *msg; + struct enetc_mac_filter *mac_filter; + struct device *dev = &si->pdev->dev; + struct enetc_msg_swbd msg_swbd; + struct netdev_hw_addr *ha; + int mac_filter_type = 0; + u32 tbl_cnt = 0; + u32 msg_size; + int i = 0; + + if (!uc && !mc) + return 0; + + if (uc) { + tbl_cnt += 2; + mac_filter_type |= ENETC_MAC_FILTER_TYPE_UC; + } + + if (mc) { + tbl_cnt += 2; + mac_filter_type |= ENETC_MAC_FILTER_TYPE_MC; + } + + msg_size = struct_size(msg, hash_tbl, tbl_cnt); + msg_swbd.size = ALIGN(msg_size, ENETC_MSG_ALIGN); + msg_swbd.vaddr = dma_alloc_coherent(dev, msg_swbd.size, + &msg_swbd.dma, GFP_KERNEL); + if (!msg_swbd.vaddr) + return -ENOMEM; + + msg = (struct enetc_msg_mac_hash_filter *)msg_swbd.vaddr; + msg->sz_type = FIELD_PREP(ENETC_MSG_MAC_TYPE, mac_filter_type); + msg->sz_type |= FIELD_PREP(ENETC_MSG_MAC_HASH_SIZE, + ENETC_MAC_HASH_TABLE_SIZE_64); + + if (uc) { + mac_filter = &si->mac_filter[UC]; + enetc_reset_mac_addr_filter(mac_filter); + netdev_hw_addr_list_for_each(ha, uc) + enetc_add_mac_addr_ht_filter(mac_filter, ha->addr); + + bitmap_to_arr32(&msg->hash_tbl[i], mac_filter->mac_hash_table, + ENETC_MADDR_HASH_TBL_SZ); + i += 2; + } + + if (mc) { + mac_filter = &si->mac_filter[MC]; + enetc_reset_mac_addr_filter(mac_filter); + netdev_hw_addr_list_for_each(ha, mc) + enetc_add_mac_addr_ht_filter(mac_filter, ha->addr); + + bitmap_to_arr32(&msg->hash_tbl[i], mac_filter->mac_hash_table, + ENETC_MADDR_HASH_TBL_SZ); + } + + enetc_msg_fill_common_hdr(&msg_swbd, ENETC_MSG_CLASS_ID_MAC_FILTER, + ENETC_MSG_SET_MAC_HASH_TABLE, 0, 0); + + return enetc_msg_vsi_send(si, &msg_swbd); +} + +static int enetc_vf_enable_iff_promisc(struct enetc_si *si) +{ + int err; + + err = enetc_vf_set_mac_promisc(si, ENETC_MAC_FILTER_TYPE_ALL, + true, true); + if (err) + dev_err(&si->pdev->dev, + "Failed to enable promiscuous mode, err: %pe\n", + ERR_PTR(err)); + + return err; +} + +static int enetc_vf_disable_iff_promisc(struct enetc_si *si, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc) +{ + int err; + + err = enetc_vf_set_mac_hash_filter(si, uc, mc); + if (err) { + dev_err_once(&si->pdev->dev, + "Failed to set MAC hash filters, err: %pe\n", + ERR_PTR(err)); + return err; + } + + err = enetc_vf_set_mac_promisc(si, ENETC_MAC_FILTER_TYPE_ALL, + false, false); + if (err) + dev_err_once(&si->pdev->dev, + "Failed to disable promiscuous mode, err: %pe\n", + ERR_PTR(err)); + + return err; +} + +static int enetc_vf_enable_iff_allmulti(struct enetc_si *si, + struct netdev_hw_addr_list *uc) +{ + int err; + + err = enetc_vf_set_mac_promisc(si, ENETC_MAC_FILTER_TYPE_MC, + true, true); + if (err) { + dev_err(&si->pdev->dev, + "Failed to enable multicast promiscuous mode, err: %pe\n", + ERR_PTR(err)); + return err; + } + + err = enetc_vf_set_mac_hash_filter(si, uc, NULL); + if (err) { + dev_err(&si->pdev->dev, + "Failed to set unicast filter, err: %pe\n", + ERR_PTR(err)); + return err; + } + + err = enetc_vf_set_mac_promisc(si, ENETC_MAC_FILTER_TYPE_UC, + false, false); + if (err) + dev_err(&si->pdev->dev, + "Failed to disable unicast promiscuous mode, err: %pe\n", + ERR_PTR(err)); + + return err; +} + +static int enetc_vf_set_rx_mode(struct net_device *ndev, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc) +{ + struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_si *si = priv->si; + int err; + + if (ndev->flags & IFF_PROMISC) + err = enetc_vf_enable_iff_promisc(si); + else if (ndev->flags & IFF_ALLMULTI) + err = enetc_vf_enable_iff_allmulti(si, uc); + else + err = enetc_vf_disable_iff_promisc(si, uc, mc); + + /* If the error code is -EOPNOTSUPP or -EACCES or -EPERM, return 0 + * directly to avoid meaningless retries. + */ + if (err == -EOPNOTSUPP || err == -EACCES || err == -EPERM) + return 0; + + return err; +} + /* Probing/ Init */ static const struct net_device_ops enetc_ndev_ops = { .ndo_open = enetc_open, @@ -227,6 +414,20 @@ static const struct net_device_ops enetc_ndev_ops = { .ndo_hwtstamp_set = enetc_hwtstamp_set, }; +static const struct net_device_ops enetc4_ndev_ops = { + .ndo_open = enetc_open, + .ndo_stop = enetc_close, + .ndo_start_xmit = enetc_xmit, + .ndo_get_stats = enetc_get_stats, + .ndo_set_mac_address = enetc_vf_set_mac_addr, + .ndo_set_features = enetc_vf_set_features, + .ndo_eth_ioctl = enetc_ioctl, + .ndo_setup_tc = enetc_vf_setup_tc, + .ndo_hwtstamp_get = enetc_hwtstamp_get, + .ndo_hwtstamp_set = enetc_hwtstamp_set, + .ndo_set_rx_mode_async = enetc_vf_set_rx_mode, +}; + static void enetc_vf_get_revision(struct enetc_si *si) { int ip_mn; @@ -280,6 +481,9 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ndev->vlan_features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO | NETIF_F_TSO6; + if (!is_enetc_rev1(si)) + ndev->priv_flags |= IFF_UNICAST_FLT; + if (si->num_rss) { ndev->hw_features |= NETIF_F_RXHASH; ndev->features |= NETIF_F_RXHASH; @@ -352,7 +556,10 @@ static int enetc_vf_probe(struct pci_dev *pdev, goto err_alloc_netdev; } - enetc_vf_netdev_setup(si, ndev, &enetc_ndev_ops); + if (is_enetc_rev1(si)) + enetc_vf_netdev_setup(si, ndev, &enetc_ndev_ops); + else + enetc_vf_netdev_setup(si, ndev, &enetc4_ndev_ops); priv = netdev_priv(ndev); @@ -416,6 +623,11 @@ static void enetc_vf_remove(struct pci_dev *pdev) priv = netdev_priv(si->ndev); unregister_netdev(si->ndev); + /* Disable promiscuous mode and clear MAC filters */ + if (!is_enetc_rev1(si)) + enetc_vf_set_mac_promisc(si, ENETC_MAC_FILTER_TYPE_ALL, + false, true); + enetc_free_msix(priv); enetc_free_si_resources(priv); From 36a16ed591b3565b5c5da547221923ead5a3eb6e Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:32 +0800 Subject: [PATCH 0490/2126] net: enetc: add PSI-to-VSI link status notification support for VF Let ENETC v4 VFs track PF link status through the PSI-to-VSI messaging channel. Add two enetc_si_ops hooks, vf_reg_link_status_notifier and vf_unreg_link_status_notifier, populated only in enetc4_vsi_ops; rev1 hardware is unaffected. A dedicated MSI-X vector on the VF handles incoming PSI-to-VSI messages. Its handler schedules a work item on an ordered workqueue that reads the notification via VSIMSGRR, updates the carrier state and sets congestion mode from the PF TX PAUSE state in the message. Reading VSIMSGRR also acknowledges the PF so it can send the next message. The workqueue is set up in enetc_vf_probe() and torn down in enetc_vf_remove(). On a VF, enetc_phylink_connect() registers the notifier with the PF and enetc_close() unregisters it. On registration the PF immediately sends the current link status and then broadcasts every later transition; if registration fails, fall back to the LS1028A behaviour and assert carrier unconditionally. Register the notifier only after the Tx/Rx resources are allocated in enetc_open(), because once registered the PF may queue si->msg_task via a link-up message. An error unwind cannot drain that work item, since enetc_open() and the work item both take the RTNL lock and waiting would deadlock; and as __LINK_STATE_START is set before ndo_open() runs, netif_running() stays true during the unwind, so the queued work could still call netif_carrier_on() and leave carrier 'on' after a failed open. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-15-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/enetc/enetc.c | 48 +++- drivers/net/ethernet/freescale/enetc/enetc.h | 4 + .../net/ethernet/freescale/enetc/enetc_hw.h | 9 + .../net/ethernet/freescale/enetc/enetc_vf.c | 209 +++++++++++++++++- 4 files changed, 261 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 803c5c541a5c..04c49b680709 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -2935,11 +2935,31 @@ static void enetc_clear_interrupts(struct enetc_ndev_priv *priv) static int enetc_phylink_connect(struct net_device *ndev) { struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_si *si = priv->si; struct ethtool_keee edata; int err; if (!priv->phylink) { /* phy-less mode */ + if (!si->ops->vf_reg_link_status_notifier) + goto carrier_on; + + /* For phy-less VFs on ENETC v4, attempt to register a link + * status notifier with the PF via the VSI-to-PSI messaging + * channel. If registration succeeds, the PF will immediately + * send the current link status and broadcast future link + * transitions; carrier state is then managed in + * enetc_vf_msg_handle_link_status(). If registration fails, + * fall back to the LS1028A behaviour and assert carrier + * unconditionally via netif_carrier_on(). + */ + if (!si->ops->vf_reg_link_status_notifier(si)) + return 0; + + dev_warn(&ndev->dev, + "Link status notifier registration failed\n"); + +carrier_on: netif_carrier_on(ndev); return 0; } @@ -3024,10 +3044,6 @@ int enetc_open(struct net_device *ndev) if (err) goto err_setup_irqs; - err = enetc_phylink_connect(ndev); - if (err) - goto err_phy_connect; - tx_res = enetc_alloc_tx_resources(priv); if (IS_ERR(tx_res)) { err = PTR_ERR(tx_res); @@ -3040,6 +3056,10 @@ int enetc_open(struct net_device *ndev) goto err_alloc_rx; } + err = enetc_phylink_connect(ndev); + if (err) + goto err_phy_connect; + enetc_tx_onestep_tstamp_init(priv); enetc_assign_tx_resources(priv, tx_res); enetc_assign_rx_resources(priv, rx_res); @@ -3048,12 +3068,11 @@ int enetc_open(struct net_device *ndev) return 0; +err_phy_connect: + enetc_free_rx_resources(rx_res, priv->num_rx_rings); err_alloc_rx: enetc_free_tx_resources(tx_res, priv->num_tx_rings); err_alloc_tx: - if (priv->phylink) - phylink_disconnect_phy(priv->phylink); -err_phy_connect: enetc_free_irqs(priv); err_setup_irqs: clk_disable_unprepare(priv->ref_clk); @@ -3093,6 +3112,7 @@ EXPORT_SYMBOL_GPL(enetc_stop); int enetc_close(struct net_device *ndev) { struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_si *si = priv->si; enetc_stop(ndev); @@ -3100,6 +3120,20 @@ int enetc_close(struct net_device *ndev) phylink_stop(priv->phylink); phylink_disconnect_phy(priv->phylink); } else { + if (!si->ops->vf_unreg_link_status_notifier) + goto carrier_off; + + /* No need to check whether the previous registration was + * successful. Sending the deregistration message has no + * impact; the PF side simply clears the corresponding bit + * in link_status_ms_mask for the VF. + */ + if (!si->ops->vf_unreg_link_status_notifier(si)) + goto carrier_off; + + dev_warn(&ndev->dev, + "Link status notifier unregistration failed\n"); +carrier_off: netif_carrier_off(ndev); } diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 0501cc2fc304..d9e91832a9c1 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -300,6 +300,10 @@ struct enetc_si_ops { int (*set_rss_table)(struct enetc_si *si, const u32 *table, int count); int (*setup_cbdr)(struct enetc_si *si); void (*teardown_cbdr)(struct enetc_si *si); + + /* VSI-specific hooks */ + int (*vf_reg_link_status_notifier)(struct enetc_si *si); + int (*vf_unreg_link_status_notifier)(struct enetc_si *si); }; /* PCI IEP device data */ diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h index c18ad8b9b071..2c9d9042eb0b 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -85,6 +85,9 @@ static inline u32 enetc_vsi_set_msize(u32 size) #define PSIMSGSR_MS(n) BIT((n) + 1) #define PSIMSGSR_MC GENMASK(31, 16) +#define ENETC_VSIMSGRR 0x208 +#define VSIMSGRR_MC GENMASK(31, 16) + /* SI statistics */ #define ENETC_SIROCT 0x300 #define ENETC_SIRFRM 0x308 @@ -108,6 +111,12 @@ static inline u32 enetc_vsi_set_msize(u32 size) #define ENETC_SICAPR0 0x900 #define ENETC_SICAPR1 0x904 +#define ENETC_VSIIER 0xa00 +#define VSIIER_MRIE BIT(9) + +#define ENETC_VSIIDR 0xa08 +#define VSIIDR_MR BIT(9) + #define ENETC_PSIIER 0xa00 #define ENETC_PSIIDR 0xa08 diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c index 8cf38c426dae..ee9567998c7c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c @@ -135,6 +135,37 @@ static int enetc_msg_vsi_send(struct enetc_si *si, struct enetc_msg_swbd *msg) return err; } +static int enetc_msg_link_status_notifier(struct enetc_si *si, bool reg) +{ + struct device *dev = &si->pdev->dev; + struct enetc_msg_swbd msg_swbd; + u8 cmd_id; + + msg_swbd.size = ALIGN(sizeof(struct enetc_msg_generic), + ENETC_MSG_ALIGN); + msg_swbd.vaddr = dma_alloc_coherent(dev, msg_swbd.size, + &msg_swbd.dma, GFP_KERNEL); + if (!msg_swbd.vaddr) + return -ENOMEM; + + cmd_id = reg ? ENETC_MSG_REGISTER_LINK_CHANGE_NOTIFIER : + ENETC_MSG_UNREGISTER_LINK_CHANGE_NOTIFIER; + enetc_msg_fill_common_hdr(&msg_swbd, ENETC_MSG_CLASS_ID_LINK_STATUS, + cmd_id, 0, 0); + + return enetc_msg_vsi_send(si, &msg_swbd); +} + +static int enetc_vf_reg_link_status_notifier(struct enetc_si *si) +{ + return enetc_msg_link_status_notifier(si, true); +} + +static int enetc_vf_unreg_link_status_notifier(struct enetc_si *si) +{ + return enetc_msg_link_status_notifier(si, false); +} + static int enetc_msg_vsi_set_primary_mac_addr(struct enetc_ndev_priv *priv, struct sockaddr *saddr) { @@ -499,6 +530,128 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev, enetc_load_primary_mac_addr(&si->hw, ndev); } +static void enetc_vf_enable_mr_int(struct enetc_si *si) +{ + if (is_enetc_rev1(si)) + return; + + enetc_wr(&si->hw, ENETC_VSIIER, VSIIER_MRIE); +} + +static void enetc_vf_disable_mr_int(struct enetc_si *si) +{ + if (is_enetc_rev1(si)) + return; + + enetc_wr(&si->hw, ENETC_VSIIER, 0); +} + +static void enetc_vf_msg_handle_link_status(struct enetc_si *si, u8 status) +{ + bool tx_pause = !!(status & ENETC_CLASS_CODE_TX_PAUSE_EN); + bool link_down = !!(status & ENETC_CLASS_CODE_LINK_DOWN); + struct enetc_ndev_priv *priv = netdev_priv(si->ndev); + struct net_device *ndev = si->ndev; + + rtnl_lock(); + if (!netif_running(ndev)) + goto unlock_rtnl; + + if (link_down) { + if (netif_carrier_ok(ndev)) { + netif_carrier_off(ndev); + netdev_info(ndev, "Link is Down\n"); + } + + goto unlock_rtnl; + } + + /* Link is up */ + enetc_set_congestion_mode(priv, tx_pause); + + if (!netif_carrier_ok(ndev)) { + netif_carrier_on(ndev); + netdev_info(ndev, "Link is Up, tx pause %s\n", + tx_pause ? "on" : "off"); + } + +unlock_rtnl: + rtnl_unlock(); +} + +static void enetc_vf_msg_task(struct work_struct *work) +{ + struct enetc_si *si = container_of(work, struct enetc_si, msg_task); + struct enetc_hw *hw = &si->hw; + u8 class_id, class_code; + u16 pf_msg; + + /* W1C to clear the message received interrupt event */ + enetc_wr(hw, ENETC_VSIIDR, VSIIDR_MR); + + /* Reading VSIMSGRR retrieves the message data and acknowledges to + * the PF that the message was received and another message can be + * sent. + */ + pf_msg = FIELD_GET(VSIMSGRR_MC, enetc_rd(hw, ENETC_VSIMSGRR)); + class_id = FIELD_GET(ENETC_PF_MSG_CLASS_ID, pf_msg); + + switch (class_id) { + case ENETC_MSG_CLASS_ID_LINK_STATUS: + class_code = FIELD_GET(ENETC_PF_MSG_CLASS_CODE_U8, pf_msg); + enetc_vf_msg_handle_link_status(si, class_code); + break; + default: + dev_err(&si->pdev->dev, + "Unsupported Message Class ID (0x%02x) from PF\n", + class_id); + } + + enetc_vf_enable_mr_int(si); +} + +static irqreturn_t enetc_vf_msg_msix_handler(int irq, void *data) +{ + struct enetc_si *si = (struct enetc_si *)data; + + enetc_vf_disable_mr_int(si); + queue_work(si->workqueue, &si->msg_task); + + return IRQ_HANDLED; +} + +static int enetc_vf_register_msg_msix(struct enetc_si *si) +{ + int irq, err; + + if (is_enetc_rev1(si)) + return 0; + + snprintf(si->msg_int_name, sizeof(si->msg_int_name), "%s-pfmsg", + pci_name(si->pdev)); + irq = pci_irq_vector(si->pdev, ENETC_SI_INT_IDX); + err = request_irq(irq, enetc_vf_msg_msix_handler, 0, + si->msg_int_name, si); + if (err) { + dev_err(&si->pdev->dev, + "VF messaging: request_irq() failed!\n"); + return err; + } + + /* set one IRQ entry for PSI-to-VSI messaging */ + enetc_wr(&si->hw, ENETC_SIMSIVR, ENETC_SI_INT_IDX); + + return 0; +} + +static void enetc_vf_free_msg_msix(struct enetc_si *si) +{ + if (is_enetc_rev1(si)) + return; + + free_irq(pci_irq_vector(si->pdev, ENETC_SI_INT_IDX), si); +} + static const struct enetc_si_ops enetc_vsi_ops = { .get_rss_table = enetc_get_rss_table, .set_rss_table = enetc_set_rss_table, @@ -511,8 +664,41 @@ static const struct enetc_si_ops enetc4_vsi_ops = { .set_rss_table = enetc4_set_rss_table, .setup_cbdr = enetc4_setup_cbdr, .teardown_cbdr = enetc4_teardown_cbdr, + .vf_reg_link_status_notifier = enetc_vf_reg_link_status_notifier, + .vf_unreg_link_status_notifier = enetc_vf_unreg_link_status_notifier, }; +static int enetc_vf_wq_task_init(struct enetc_si *si) +{ + if (is_enetc_rev1(si)) + return 0; + + si->workqueue = alloc_ordered_workqueue("enetc-%s-wq", WQ_MEM_RECLAIM, + pci_name(si->pdev)); + if (!si->workqueue) + return -ENOMEM; + + INIT_WORK(&si->msg_task, enetc_vf_msg_task); + + return 0; +} + +static void enetc_vf_wq_task_destroy(struct enetc_si *si) +{ + if (!si->workqueue) + return; + + disable_work_sync(&si->msg_task); + + /* Disable the MR interrupt */ + enetc_vf_disable_mr_int(si); + enetc_wr(&si->hw, ENETC_VSIIDR, VSIIDR_MR); + /* Reading VSIMSGRR to clear the MS bit on the PF's side */ + enetc_rd(&si->hw, ENETC_VSIMSGRR); + + destroy_workqueue(si->workqueue); +} + static int enetc_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -587,15 +773,32 @@ static int enetc_vf_probe(struct pci_dev *pdev, goto err_alloc_msix; } + err = enetc_vf_wq_task_init(si); + if (err) { + dev_err(&pdev->dev, "Failed to init workqueue\n"); + goto err_wq_init; + } + + err = enetc_vf_register_msg_msix(si); + if (err) { + dev_err(&pdev->dev, "Failed to register msg irq\n"); + goto err_register_msg_msix; + } + + netif_carrier_off(ndev); + /* Enable message received interrupt */ + enetc_vf_enable_mr_int(si); err = register_netdev(ndev); if (err) goto err_reg_netdev; - netif_carrier_off(ndev); - return 0; err_reg_netdev: + enetc_vf_free_msg_msix(si); +err_register_msg_msix: + enetc_vf_wq_task_destroy(si); +err_wq_init: enetc_free_msix(priv); err_config_si: err_alloc_msix: @@ -628,6 +831,8 @@ static void enetc_vf_remove(struct pci_dev *pdev) enetc_vf_set_mac_promisc(si, ENETC_MAC_FILTER_TYPE_ALL, false, true); + enetc_vf_free_msg_msix(si); + enetc_vf_wq_task_destroy(si); enetc_free_msix(priv); enetc_free_si_resources(priv); From 5822ab0f3e89b35cabe2323dbfd6c2ab883fde4b Mon Sep 17 00:00:00 2001 From: Wei Fang Date: Wed, 9 Sep 2026 18:07:33 +0800 Subject: [PATCH 0491/2126] net: enetc: add ndo_get_vf_config() support Without ndo_get_vf_config(), userspace tools such as 'ip link show' cannot query the current VF configuration from the PF. To support this, extend struct enetc_vf_state to track the per-VF VLAN and spoofchk settings, and update the corresponding setter callbacks to persist their state when the hardware is programmed. enetc_pf_get_vf_config() reads back the persisted state and reports MAC address, VLAN parameters, spoofchk, and trust state through struct ifla_vf_info. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260909100733.1139689-16-wei.fang@oss.nxp.com Signed-off-by: Paolo Abeni --- .../net/ethernet/freescale/enetc/enetc4_pf.c | 1 + .../net/ethernet/freescale/enetc/enetc_pf.c | 24 +++++++++++++ .../net/ethernet/freescale/enetc/enetc_pf.h | 4 +++ .../freescale/enetc/enetc_pf_common.c | 34 +++++++++++++++++++ .../freescale/enetc/enetc_pf_common.h | 2 ++ 5 files changed, 65 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index 24c1fd869c2c..71c971618388 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -597,6 +597,7 @@ static const struct net_device_ops enetc4_ndev_ops = { .ndo_hwtstamp_set = enetc_hwtstamp_set, .ndo_set_vf_trust = enetc_pf_set_vf_trust, .ndo_set_vf_mac = enetc_pf_set_vf_mac, + .ndo_get_vf_config = enetc_pf_get_vf_config, }; static struct phylink_pcs * diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index 523c71324780..d77a07cece28 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -195,6 +195,7 @@ static int enetc_pf_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, { struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_pf *pf = enetc_si_priv(priv->si); + struct enetc_vf_state *vf_state; if (priv->si->errata & ENETC_ERR_VLAN_ISOL) return -EOPNOTSUPP; @@ -207,6 +208,17 @@ static int enetc_pf_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, return -EPROTONOSUPPORT; enetc_set_isol_vlan(&priv->si->hw, vf + 1, vlan, qos); + + vf_state = &pf->vf_state[vf]; + mutex_lock(&vf_state->lock); + /* Currently only C-tags is supported, so tpid is always 0, + * which indicates ETH_P_8021Q. + */ + vf_state->tpid = 0; + vf_state->qos = qos; + vf_state->vid = vlan; + mutex_unlock(&vf_state->lock); + return 0; } @@ -214,6 +226,7 @@ static int enetc_pf_set_vf_spoofchk(struct net_device *ndev, int vf, bool en) { struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_pf *pf = enetc_si_priv(priv->si); + struct enetc_vf_state *vf_state; u32 cfgr; if (vf >= pf->total_vfs) @@ -223,6 +236,16 @@ static int enetc_pf_set_vf_spoofchk(struct net_device *ndev, int vf, bool en) cfgr = (cfgr & ~ENETC_PSICFGR0_ASE) | (en ? ENETC_PSICFGR0_ASE : 0); enetc_port_wr(&priv->si->hw, ENETC_PSICFGR0(vf + 1), cfgr); + vf_state = &pf->vf_state[vf]; + mutex_lock(&vf_state->lock); + + if (en) + vf_state->flags |= ENETC_VF_FLAG_SPOOFCHK; + else + vf_state->flags &= ~ENETC_VF_FLAG_SPOOFCHK; + + mutex_unlock(&vf_state->lock); + return 0; } @@ -476,6 +499,7 @@ static const struct net_device_ops enetc_ndev_ops = { .ndo_xdp_xmit = enetc_xdp_xmit, .ndo_hwtstamp_get = enetc_hwtstamp_get, .ndo_hwtstamp_set = enetc_hwtstamp_set, + .ndo_get_vf_config = enetc_pf_get_vf_config, }; static struct phylink_pcs * diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h index 1a9fa3714c3c..1f92d16d8ca8 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -13,6 +13,7 @@ enum enetc_vf_flags { ENETC_VF_FLAG_TRUSTED = BIT(1), ENETC_VF_FLAG_UC_PROMISC = BIT(2), ENETC_VF_FLAG_MC_PROMISC = BIT(3), + ENETC_VF_FLAG_SPOOFCHK = BIT(4), }; struct enetc_vf_state { @@ -20,6 +21,9 @@ struct enetc_vf_state { enum enetc_vf_flags flags; /* Number of consecutive failures to send PF-to-VF messages */ int msg_fail_cnt; + u8 tpid; /* SI-based VLAN TPID (0: 0x8100, 1: 0x88a8) */ + u8 qos; /* SI-based VLAN QOS (priority) bits */ + u16 vid; /* SI-based VLAN ID */ }; struct enetc_port_caps { diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index 86958f1e9cd3..8206884294a4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -682,5 +682,39 @@ int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac) } EXPORT_SYMBOL_GPL(enetc_pf_set_vf_mac); +int enetc_pf_get_vf_config(struct net_device *ndev, int vf, + struct ifla_vf_info *ivi) +{ + struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_pf *pf = enetc_si_priv(priv->si); + struct enetc_vf_state *vf_state; + + if (vf >= pf->total_vfs) + return -EINVAL; + + vf_state = &pf->vf_state[vf]; + mutex_lock(&vf_state->lock); + + ivi->vf = vf; + /* ENETC v4 has not support spoofchk yet */ + if (is_enetc_rev1(priv->si)) + ivi->spoofchk = !!(vf_state->flags & ENETC_VF_FLAG_SPOOFCHK); + + ivi->trusted = !!(vf_state->flags & ENETC_VF_FLAG_TRUSTED); + enetc_get_si_hw_addr(pf, vf + 1, ivi->mac); + + if (vf_state->vid) { + ivi->vlan = vf_state->vid; + ivi->qos = vf_state->qos; + ivi->vlan_proto = vf_state->tpid ? htons(ETH_P_8021AD) : + htons(ETH_P_8021Q); + } + + mutex_unlock(&vf_state->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(enetc_pf_get_vf_config); + MODULE_DESCRIPTION("NXP ENETC PF common functionality driver"); MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h index 7d7e67a12278..c9eed879d5a3 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.h @@ -24,6 +24,8 @@ void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash); void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc); int enetc_pf_set_vf_trust(struct net_device *ndev, int vf, bool setting); int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac); +int enetc_pf_get_vf_config(struct net_device *ndev, int vf, + struct ifla_vf_info *ivi); static inline u16 enetc_get_ip_revision(struct enetc_hw *hw) { From 578fefdbbdaf3d02949ad9bb94736c81de4a02a8 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:27 +0000 Subject: [PATCH 0492/2126] ipmr: Call ->dellink() to remove DVMRP tunnel device. ipmr.c uses unregister_netdevice() to remove DVMRP tunnel devices created in ipmr_new_tunnel(). This is fine because currently ip_tunnel_uninit() also calls ip_tunnel_del() to unlink the device from the hash table. However, we will move ip_tunnel_del() from ip_tunnel_uninit() to ip_tunnel_dellink(). Removing DVMRP tunnel devices by unregister_netdevice() would leave them in the hash table. Let's call ->dellink for DVMRP tunnel devices. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-2-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- net/ipv4/ipmr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 1187bfc8a09d..e4c51ca47301 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -479,6 +479,7 @@ static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) { struct net_device *tunnel_dev, *new_dev; struct ip_tunnel_parm_kern p = { }; + LIST_HEAD(dev_kill_list); int err; tunnel_dev = __dev_get_by_name(net, "tunl0"); @@ -520,7 +521,8 @@ static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) return new_dev; out_unregister: - unregister_netdevice(new_dev); + new_dev->rtnl_link_ops->dellink(new_dev, &dev_kill_list); + unregister_netdevice_many(&dev_kill_list); out: return ERR_PTR(-ENOBUFS); } @@ -733,8 +735,12 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, ip_rt_multicast_event(in_dev); } - if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER) && !notify) - unregister_netdevice_queue(dev, head); + if (!notify) { + if (v->flags & VIFF_TUNNEL) + dev->rtnl_link_ops->dellink(dev, head); + else if (v->flags & VIFF_REGISTER) + unregister_netdevice_queue(dev, head); + } netdev_put(dev, &v->dev_tracker); return 0; From 0239bd767b3ae5d361f348a88babd33a15d498a6 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:28 +0000 Subject: [PATCH 0493/2126] ip_tunnel: Set itn->fb_tunnel_dev to NULL in ip_tunnel_delete_net(). ip_tunnel_dellink() ignores itn->fb_tunnel_dev, so the per-netns fallback tunnel device cannot be removed by userspace. This also makes default_device_exit_batch() impossible to remove the device since it calls ->dellink(). So, ip_tunnel_delete_net() has to iterate devices in the dying netns and call unregister_netdevice_queue() directly. But then, this duplicates ip_tunnel_del() in ip_tunnel_dellink() and ip_tunnel_uninit(). Let's set itn->fb_tunnel_dev to NULL in ip_tunnel_delete_net() and remove for_each_netdev_safe() in ip_tunnel_delete_net(). Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-3-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- net/ipv4/ip_tunnel.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 13b5e35e8790..d74200ab5762 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1153,26 +1153,19 @@ void ip_tunnel_delete_net(struct net *net, unsigned int id, struct list_head *head) { struct ip_tunnel_net *itn = net_generic(net, id); - struct net_device *dev, *aux; int h; ASSERT_RTNL_NET(net); - for_each_netdev_safe(net, dev, aux) - if (dev->rtnl_link_ops == ops) - unregister_netdevice_queue(dev, head); + WRITE_ONCE(itn->fb_tunnel_dev, NULL); for (h = 0; h < IP_TNL_HASH_SIZE; h++) { - struct ip_tunnel *t; - struct hlist_node *n; struct hlist_head *thead = &itn->tunnels[h]; + struct hlist_node *n; + struct ip_tunnel *t; hlist_for_each_entry_safe(t, n, thead, hash_node) - /* If dev is in the same netns, it has already - * been added to the list by the previous loop. - */ - if (!net_eq(dev_net(t->dev), net)) - unregister_netdevice_queue(t->dev, head); + unregister_netdevice_queue(t->dev, head); } } EXPORT_SYMBOL_GPL(ip_tunnel_delete_net); @@ -1308,8 +1301,6 @@ void ip_tunnel_uninit(struct net_device *dev) itn = net_generic(net, tunnel->ip_tnl_net_id); ip_tunnel_del(itn, netdev_priv(dev)); - if (itn->fb_tunnel_dev == dev) - WRITE_ONCE(itn->fb_tunnel_dev, NULL); dst_cache_reset(&tunnel->dst_cache); } From 7ba090b04ab87b90e714e5fb3ba8748f6f04d2a0 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:29 +0000 Subject: [PATCH 0494/2126] ip_tunnel: Don't pass rtnl_link_ops to ip_tunnel_delete_net(). ip_tunnel_delete_net() no longer uses the 3rd argument, struct rtnl_link_ops *ops. Let's remove it. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-4-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- include/net/ip_tunnels.h | 1 - net/ipv4/ip_gre.c | 6 +++--- net/ipv4/ip_tunnel.c | 1 - net/ipv4/ip_vti.c | 2 +- net/ipv4/ipip.c | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index be4cc10f88ed..a78dfbb98044 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -401,7 +401,6 @@ int ip_tunnel_get_iflink(const struct net_device *dev); int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id, struct rtnl_link_ops *ops, char *devname); void ip_tunnel_delete_net(struct net *net, unsigned int id, - struct rtnl_link_ops *ops, struct list_head *dev_to_kill); void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 82309efd417e..5e877018e006 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1084,7 +1084,7 @@ static int __net_init ipgre_init_net(struct net *net) static void __net_exit ipgre_exit_rtnl(struct net *net, struct list_head *dev_to_kill) { - ip_tunnel_delete_net(net, ipgre_net_id, &ipgre_link_ops, dev_to_kill); + ip_tunnel_delete_net(net, ipgre_net_id, dev_to_kill); } static struct pernet_operations ipgre_net_ops = { @@ -1728,7 +1728,7 @@ static int __net_init ipgre_tap_init_net(struct net *net) static void __net_exit ipgre_tap_exit_rtnl(struct net *net, struct list_head *dev_to_kill) { - ip_tunnel_delete_net(net, gre_tap_net_id, &ipgre_tap_ops, dev_to_kill); + ip_tunnel_delete_net(net, gre_tap_net_id, dev_to_kill); } static struct pernet_operations ipgre_tap_net_ops = { @@ -1747,7 +1747,7 @@ static int __net_init erspan_init_net(struct net *net) static void __net_exit erspan_exit_rtnl(struct net *net, struct list_head *dev_to_kill) { - ip_tunnel_delete_net(net, erspan_net_id, &erspan_link_ops, dev_to_kill); + ip_tunnel_delete_net(net, erspan_net_id, dev_to_kill); } static struct pernet_operations erspan_net_ops = { diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index d74200ab5762..e6bbc5e4c357 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1149,7 +1149,6 @@ int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id, EXPORT_SYMBOL_GPL(ip_tunnel_init_net); void ip_tunnel_delete_net(struct net *net, unsigned int id, - struct rtnl_link_ops *ops, struct list_head *head) { struct ip_tunnel_net *itn = net_generic(net, id); diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index 3b80929994a0..c4f14d42df24 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -526,7 +526,7 @@ static int __net_init vti_init_net(struct net *net) static void __net_exit vti_exit_rtnl(struct net *net, struct list_head *dev_to_kill) { - ip_tunnel_delete_net(net, vti_net_id, &vti_link_ops, dev_to_kill); + ip_tunnel_delete_net(net, vti_net_id, dev_to_kill); } static struct pernet_operations vti_net_ops = { diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index f684baf8e58f..2ffe64e736e0 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -645,7 +645,7 @@ static int __net_init ipip_init_net(struct net *net) static void __net_exit ipip_exit_rtnl(struct net *net, struct list_head *dev_to_kill) { - ip_tunnel_delete_net(net, ipip_net_id, &ipip_link_ops, dev_to_kill); + ip_tunnel_delete_net(net, ipip_net_id, dev_to_kill); } static struct pernet_operations ipip_net_ops = { From e53013fe10c22fc4e2cc1b45180790a5429c7aa9 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:30 +0000 Subject: [PATCH 0495/2126] ip_tunnel: Centralise ip_tunnel_del() to ip_tunnel_dellink(). With the previous patch, itn->fb_tunnel_dev can be removed via ->dellink(). However, ioctl(SIOCDELTUNNEL) still uses unregister_netdevice(), which requires ip_tunnel_del() in ip_tunnel_uninit(). Let's use ip_tunnel_dellink() everywhere to remove ip_tunnel device and remove ip_tunnel_del() in ip_tunnel_uninit(). Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-5-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- net/ipv4/ip_tunnel.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index e6bbc5e4c357..7d7baaa57741 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -895,10 +895,13 @@ static void ip_tunnel_update(struct ip_tunnel_net *itn, int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, int cmd) { - int err = 0; struct ip_tunnel *t = netdev_priv(dev); + struct ip_tunnel_net *itn; + LIST_HEAD(dev_kill_list); struct net *net = t->net; - struct ip_tunnel_net *itn = net_generic(net, t->ip_tnl_net_id); + int err = 0; + + itn = net_generic(net, t->ip_tnl_net_id); switch (cmd) { case SIOCGETTUNNEL: @@ -982,7 +985,8 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, goto done; dev = t->dev; } - unregister_netdevice(dev); + + ip_tunnel_dellink(dev, &dev_kill_list); err = 0; break; @@ -991,6 +995,8 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, } done: + unregister_netdevice_many(&dev_kill_list); + return err; } EXPORT_SYMBOL_GPL(ip_tunnel_ctl); @@ -1164,7 +1170,7 @@ void ip_tunnel_delete_net(struct net *net, unsigned int id, struct ip_tunnel *t; hlist_for_each_entry_safe(t, n, thead, hash_node) - unregister_netdevice_queue(t->dev, head); + ip_tunnel_dellink(t->dev, head); } } EXPORT_SYMBOL_GPL(ip_tunnel_delete_net); @@ -1295,11 +1301,6 @@ EXPORT_SYMBOL_GPL(__ip_tunnel_init); void ip_tunnel_uninit(struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - struct net *net = tunnel->net; - struct ip_tunnel_net *itn; - - itn = net_generic(net, tunnel->ip_tnl_net_id); - ip_tunnel_del(itn, netdev_priv(dev)); dst_cache_reset(&tunnel->dst_cache); } From 6faf19060bd0123b69d7e9b04244fd577223ac3c Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:31 +0000 Subject: [PATCH 0496/2126] ip_tunnel: Unify error paths in ip_tunnel_newlink() and ip_tunnel_changelink(). The next patch will introduce per-netns mutex and acquire it in ip_tunnel_newlink() and ip_tunnel_changelink(). To make the diff cleaner, let's unify the error paths. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-6-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- net/ipv4/ip_tunnel.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 7d7baaa57741..d560ae9f0222 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1179,21 +1179,23 @@ int ip_tunnel_newlink(struct net *net, struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark) { - struct ip_tunnel *nt; struct ip_tunnel_net *itn; + struct ip_tunnel *nt; + int err = 0; int mtu; - int err; nt = netdev_priv(dev); itn = net_generic(net, nt->ip_tnl_net_id); if (nt->collect_md) { if (rtnl_dereference(itn->collect_md_tun)) - return -EEXIST; + err = -EEXIST; } else { if (ip_tunnel_find(itn, p, dev->type)) - return -EEXIST; + err = -EEXIST; } + if (err) + goto out; nt->net = net; nt->parms = *p; @@ -1220,22 +1222,26 @@ int ip_tunnel_newlink(struct net *net, struct net_device *dev, goto err_dev_set_mtu; ip_tunnel_add(itn, nt); - return 0; +out: + return err; err_dev_set_mtu: unregister_netdevice(dev); err_register_netdevice: - return err; + goto out; } EXPORT_SYMBOL_GPL(ip_tunnel_newlink); int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm_kern *p, __u32 fwmark) { - struct ip_tunnel *t; struct ip_tunnel *tunnel = netdev_priv(dev); struct net *net = tunnel->net; - struct ip_tunnel_net *itn = net_generic(net, tunnel->ip_tnl_net_id); + struct ip_tunnel_net *itn; + struct ip_tunnel *t; + int err = 0; + + itn = net_generic(net, tunnel->ip_tnl_net_id); if (dev == itn->fb_tunnel_dev) return -EINVAL; @@ -1243,8 +1249,10 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], t = ip_tunnel_find(itn, p, dev->type); if (t) { - if (t->dev != dev) - return -EEXIST; + if (t->dev != dev) { + err = -EEXIST; + goto out; + } } else { t = tunnel; @@ -1257,13 +1265,16 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], nflags = IFF_POINTOPOINT; if ((dev->flags ^ nflags) & - (IFF_POINTOPOINT | IFF_BROADCAST)) - return -EINVAL; + (IFF_POINTOPOINT | IFF_BROADCAST)) { + err = -EINVAL; + goto out; + } } } ip_tunnel_update(itn, t, dev, p, !tb[IFLA_MTU], fwmark); - return 0; +out: + return err; } EXPORT_SYMBOL_GPL(ip_tunnel_changelink); From 6724a7baf149ee883eb0b694e8818eacb899f5d8 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:32 +0000 Subject: [PATCH 0497/2126] ip_tunnel: Protect ip_tunnel_net.tunnels[] with mutex. struct ip_tunnel.net is the netns where encapsulated packets flow into. struct ip_tunnel is linked to ip_tunnel_net.tunnels[] of netns. During netns dismantle or module unload, ip_tunnel_delete_net() iterates the list and queues devices for destruction regardless of the devices' netns. Thus, once RTNL is removed, the list can be modified concurrently from different netns due to device removal. Let's protect it with per-netns mutex. Note that dev_siocdevprivate() calls netdev_lock_ops() but it must be NOP for tunnel devices to avoid AB-BA deadlock. DEBUG_NET_WARN_ON_ONCE() is added to annotate the locking explicitly. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-7-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- include/net/ip_tunnels.h | 1 + net/ipv4/ip_tunnel.c | 42 +++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index a78dfbb98044..7102aa11fae2 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -218,6 +218,7 @@ struct ip_tunnel_net { struct net_device *fb_tunnel_dev; struct rtnl_link_ops *rtnl_link_ops; struct hlist_head tunnels[IP_TNL_HASH_SIZE]; + struct mutex tunnels_lock; struct ip_tunnel __rcu *collect_md_tun; int type; }; diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index d560ae9f0222..d44976395c7c 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -219,7 +219,8 @@ static struct ip_tunnel *ip_tunnel_find(struct ip_tunnel_net *itn, ip_tunnel_flags_copy(flags, parms->i_flags); - hlist_for_each_entry_rcu(t, head, hash_node, lockdep_rtnl_is_held()) { + hlist_for_each_entry_rcu(t, head, hash_node, + lockdep_is_held(&itn->tunnels_lock)) { if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr && link == READ_ONCE(t->parms.link) && @@ -892,6 +893,16 @@ static void ip_tunnel_update(struct ip_tunnel_net *itn, netdev_state_change(dev); } +static void __ip_tunnel_dellink(struct net_device *dev, struct list_head *head) +{ + struct ip_tunnel *tunnel = netdev_priv(dev); + struct ip_tunnel_net *itn; + + itn = net_generic(tunnel->net, tunnel->ip_tnl_net_id); + ip_tunnel_del(itn, tunnel); + unregister_netdevice_queue(dev, head); +} + int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, int cmd) { @@ -901,8 +912,12 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, struct net *net = t->net; int err = 0; + DEBUG_NET_WARN_ON_ONCE(netdev_need_ops_lock(dev)); + itn = net_generic(net, t->ip_tnl_net_id); + mutex_lock(&itn->tunnels_lock); + switch (cmd) { case SIOCGETTUNNEL: if (dev == itn->fb_tunnel_dev) { @@ -986,7 +1001,7 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, dev = t->dev; } - ip_tunnel_dellink(dev, &dev_kill_list); + __ip_tunnel_dellink(dev, &dev_kill_list); err = 0; break; @@ -995,6 +1010,8 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, } done: + mutex_unlock(&itn->tunnels_lock); + unregister_netdevice_many(&dev_kill_list); return err; @@ -1091,8 +1108,9 @@ void ip_tunnel_dellink(struct net_device *dev, struct list_head *head) itn = net_generic(tunnel->net, tunnel->ip_tnl_net_id); if (itn->fb_tunnel_dev != dev) { - ip_tunnel_del(itn, netdev_priv(dev)); - unregister_netdevice_queue(dev, head); + mutex_lock(&itn->tunnels_lock); + __ip_tunnel_dellink(dev, head); + mutex_unlock(&itn->tunnels_lock); } } EXPORT_SYMBOL_GPL(ip_tunnel_dellink); @@ -1124,6 +1142,8 @@ int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id, for (i = 0; i < IP_TNL_HASH_SIZE; i++) INIT_HLIST_HEAD(&itn->tunnels[i]); + mutex_init(&itn->tunnels_lock); + if (!ops || !net_has_fallback_tunnels(net)) { struct ip_tunnel_net *it_init_net; @@ -1162,6 +1182,8 @@ void ip_tunnel_delete_net(struct net *net, unsigned int id, ASSERT_RTNL_NET(net); + mutex_lock(&itn->tunnels_lock); + WRITE_ONCE(itn->fb_tunnel_dev, NULL); for (h = 0; h < IP_TNL_HASH_SIZE; h++) { @@ -1170,8 +1192,10 @@ void ip_tunnel_delete_net(struct net *net, unsigned int id, struct ip_tunnel *t; hlist_for_each_entry_safe(t, n, thead, hash_node) - ip_tunnel_dellink(t->dev, head); + __ip_tunnel_dellink(t->dev, head); } + + mutex_unlock(&itn->tunnels_lock); } EXPORT_SYMBOL_GPL(ip_tunnel_delete_net); @@ -1187,6 +1211,8 @@ int ip_tunnel_newlink(struct net *net, struct net_device *dev, nt = netdev_priv(dev); itn = net_generic(net, nt->ip_tnl_net_id); + mutex_lock(&itn->tunnels_lock); + if (nt->collect_md) { if (rtnl_dereference(itn->collect_md_tun)) err = -EEXIST; @@ -1223,6 +1249,8 @@ int ip_tunnel_newlink(struct net *net, struct net_device *dev, ip_tunnel_add(itn, nt); out: + mutex_unlock(&itn->tunnels_lock); + return err; err_dev_set_mtu: @@ -1246,6 +1274,8 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], if (dev == itn->fb_tunnel_dev) return -EINVAL; + mutex_lock(&itn->tunnels_lock); + t = ip_tunnel_find(itn, p, dev->type); if (t) { @@ -1274,6 +1304,8 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], ip_tunnel_update(itn, t, dev, p, !tb[IFLA_MTU], fwmark); out: + mutex_unlock(&itn->tunnels_lock); + return err; } EXPORT_SYMBOL_GPL(ip_tunnel_changelink); From 8f3c724202578644145506486dc1cede108c0a2c Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 12 Sep 2026 23:00:33 +0000 Subject: [PATCH 0498/2126] ip_tunnel: Support per-netns device unregistration. ip_tunnel_delete_net() iterates ip_tunnel devices whose link_net is dying and queues them for destruction. The devices may reside in different netns. Let's use unregister_netdevice_queue_net() to support per-netns device unregistration. Even after ip_tunnel_delete_net() queues a cross-netns ip_tunnel device, ip_tunnel_changelink(), ip_tunnel_dellink(), and ip_tunnel_ctl() could be called concurrently for it (once RTNL is removed). In such a case, __rtnl_net_unlock() will perform the unregistration. Also, ip_tunnel_ctl() needs to check check_net(t->net), otherwise it could create a new dev in dying netns after ip_tunnel_delete_net(). In the example below, we can see the fallback tunnel device (gre0) and the cross-netns device (gre1) are unregistered by different processes: # bpftrace -e '#include kprobe:ip_tunnel_uninit { $dev = (struct net_device *)arg0; printf("PID: %d | DEV: %s%s\n", pid, $dev->name, kstack()); } kprobe:ipgre_exit_rtnl { printf("PID: %d%s\n", pid, kstack()); }' & # ip netns add ns1 # ip netns add ns2 # ip -n ns1 link add name gre1 link-netns ns2 \ type gre local 192.168.0.1 remote 192.168.1.1 # ip netns del ns2 PID: 12 ipgre_exit_rtnl+5 ops_undo_list+702 cleanup_net+1122 process_scheduled_works+2538 ... PID: 12 | DEV: gre0 <------ fallback device (itn->fb_tunnel_dev). ip_tunnel_uninit+5 unregister_netdevice_many_notify+7129 unregister_netdevice_many_net+1050 __rtnl_net_unlock+37 ops_undo_list+754 cleanup_net+1122 process_scheduled_works+2538 ... PID: 10 | DEV: gre1 ip_tunnel_uninit+5 unregister_netdevice_many_notify+7129 unregister_netdevice_many_net+1050 rtnl_net_work_func+136 process_scheduled_works+2538 Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260912230043.2586313-8-kuniyu@google.com Reviewed-by: Ido Schimmel Signed-off-by: Paolo Abeni --- net/ipv4/ip_tunnel.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index d44976395c7c..0875474a578a 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -205,6 +205,11 @@ static void ip_tunnel_del(struct ip_tunnel_net *itn, struct ip_tunnel *t) hlist_del_init_rcu(&t->hash_node); } +static bool ip_tunnel_unregistering(struct ip_tunnel *t) +{ + return hlist_unhashed(&t->hash_node); +} + static struct ip_tunnel *ip_tunnel_find(struct ip_tunnel_net *itn, struct ip_tunnel_parm_kern *parms, int type) @@ -893,20 +898,22 @@ static void ip_tunnel_update(struct ip_tunnel_net *itn, netdev_state_change(dev); } -static void __ip_tunnel_dellink(struct net_device *dev, struct list_head *head) +static void __ip_tunnel_dellink(struct net *net, struct net_device *dev, + struct list_head *head) { struct ip_tunnel *tunnel = netdev_priv(dev); struct ip_tunnel_net *itn; itn = net_generic(tunnel->net, tunnel->ip_tnl_net_id); ip_tunnel_del(itn, tunnel); - unregister_netdevice_queue(dev, head); + unregister_netdevice_queue_net(net, dev, head); } int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, int cmd) { struct ip_tunnel *t = netdev_priv(dev); + struct net *orig_net = dev_net(dev); struct ip_tunnel_net *itn; LIST_HEAD(dev_kill_list); struct net *net = t->net; @@ -918,6 +925,11 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, mutex_lock(&itn->tunnels_lock); + if (!check_net(net)) { + err = -EBUSY; + goto done; + } + switch (cmd) { case SIOCGETTUNNEL: if (dev == itn->fb_tunnel_dev) { @@ -977,7 +989,7 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, } } - if (t) { + if (t && !ip_tunnel_unregistering(t)) { err = 0; ip_tunnel_update(itn, t, dev, p, true, 0); } else { @@ -1001,7 +1013,9 @@ int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, dev = t->dev; } - __ip_tunnel_dellink(dev, &dev_kill_list); + if (!ip_tunnel_unregistering(t)) + __ip_tunnel_dellink(orig_net, dev, &dev_kill_list); + err = 0; break; @@ -1109,7 +1123,8 @@ void ip_tunnel_dellink(struct net_device *dev, struct list_head *head) if (itn->fb_tunnel_dev != dev) { mutex_lock(&itn->tunnels_lock); - __ip_tunnel_dellink(dev, head); + if (!ip_tunnel_unregistering(tunnel)) + __ip_tunnel_dellink(dev_net(dev), dev, head); mutex_unlock(&itn->tunnels_lock); } } @@ -1192,7 +1207,7 @@ void ip_tunnel_delete_net(struct net *net, unsigned int id, struct ip_tunnel *t; hlist_for_each_entry_safe(t, n, thead, hash_node) - __ip_tunnel_dellink(t->dev, head); + __ip_tunnel_dellink(net, t->dev, head); } mutex_unlock(&itn->tunnels_lock); @@ -1302,6 +1317,11 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[], } } + if (ip_tunnel_unregistering(t)) { + err = -ENODEV; + goto out; + } + ip_tunnel_update(itn, t, dev, p, !tb[IFLA_MTU], fwmark); out: mutex_unlock(&itn->tunnels_lock); From e8c06b895281ad68b2818c3f0c99b0d7fb79539f Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Sun, 13 Sep 2026 12:32:24 +0000 Subject: [PATCH 0499/2126] tcp: make smp_rmb() conditional in tcp_poll() Commit a4d258036ed9 ("tcp: Fix race in tcp_poll") added smp_rmb() in tcp_poll() and smp_wmb() in tcp_reset() (now tcp_done_with_error()) to ensure that if tcp_poll() observed socket closure, it would also observe sk->sk_err. Currently, tcp_poll() unconditionally executes smp_rmb() at the end of every invocation, which on weakly-ordered architectures such as ARM64 emits a memory barrier instruction (dmb ishld) on the poll fast path, even for healthy, active sockets. However, tcp_poll() only needs this barrier if socket closure has been observed, to ensure that the error code set by tcp_done_with_error() before socket closure is visible before returning EPOLLERR. Move smp_rmb() inside the conditional block handling socket closure (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE). For healthy connected sockets in epoll, tcp_poll() avoids the barrier entirely. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260913123224.762935-1-edumazet@google.com Signed-off-by: Paolo Abeni --- net/ipv4/tcp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 562752352afe..3ac485685279 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -578,8 +578,13 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait) * blocking on fresh not-connected or disconnected socket. --ANK */ shutdown = READ_ONCE(sk->sk_shutdown); - if (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE) + if (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE) { mask |= EPOLLHUP; + /* Coupled with smp_wmb() in tcp_done_with_error() to ensure + * sk->sk_err is visible if socket closure was observed. + */ + smp_rmb(); + } if (shutdown & RCV_SHUTDOWN) mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; @@ -626,8 +631,6 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait) */ mask |= EPOLLOUT | EPOLLWRNORM; } - /* This barrier is coupled with smp_wmb() in tcp_done_with_error() */ - smp_rmb(); if (READ_ONCE(sk->sk_err) || !skb_queue_empty_lockless(&sk->sk_error_queue)) mask |= EPOLLERR; From 4358a3e8e7cc986f3a589bc0251b7d6d73090faf Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 16:43:36 -0700 Subject: [PATCH 0500/2126] netlink: specs: tcp_metrics: fix the attribute length checks TCP_FASTOPEN_COOKIE_MAX is the longest cookie we accept, not the shortest one. Cookies are even sized, from 4 bytes up, and the ones Linux itself generates are 8 bytes, so a 16 byte minimum declares all but the longest cookie invalid. The reference policy kept under #if 0 in tcp_metrics.c spells it as a maximum, which is what .len means for NLA_BINARY. The IPv6 addresses err the other way. The policy uses NLA_POLICY_EXACT_LEN() for both, so a request carrying a longer address is rejected with -ERANGE, even though the spec advertises 16 bytes as a mere minimum. Were the policy generated from this spec, as kernel-policy: global promises, the check would turn into NLA_POLICY_MIN_LEN() and start accepting over-long addresses, of which nla_get_in6_addr() would take the first 16 bytes. Nothing generated changes. fopen-cookie is reply-only so it never gets a policy entry, and exact-len only feeds the policy (and the fixed size array form, which needs a sub-type). Signed-off-by: Jakub Kicinski Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260912234337.308298-1-kuba@kernel.org Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/tcp_metrics.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/specs/tcp_metrics.yaml b/Documentation/netlink/specs/tcp_metrics.yaml index 13144aeed31a..1d365908084d 100644 --- a/Documentation/netlink/specs/tcp_metrics.yaml +++ b/Documentation/netlink/specs/tcp_metrics.yaml @@ -32,7 +32,7 @@ attribute-sets: name: addr-ipv6 type: binary checks: - min-len: 16 + exact-len: 16 byte-order: big-endian display-hint: ipv6 - @@ -63,7 +63,7 @@ attribute-sets: name: fopen-cookie type: binary checks: - min-len: tcp-fastopen-cookie-max + max-len: tcp-fastopen-cookie-max - name: saddr-ipv4 type: u32 @@ -73,7 +73,7 @@ attribute-sets: name: saddr-ipv6 type: binary checks: - min-len: 16 + exact-len: 16 byte-order: big-endian display-hint: ipv6 - From 1a523f29fe4f663594926005714a3c10b9c04539 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 16:43:37 -0700 Subject: [PATCH 0501/2126] netlink: specs: tcp_metrics: drop the RTT shift instructions All four RTT attributes tell the reader to left-shift, which inflates the value by 16 to 64 times, and the two usec ones say the result is in msecs. The attributes carry srtt_us and mdev_us, which hold 3 and 2 fractional bits. The shift to get the integer part would be a right shift. Drop the instructions instead of turning them around. The number of fractional bits is the part worth documenting, whether to shift, divide or convert to a double is up to the caller. While at it fix the acronym on the two variance attributes. Signed-off-by: Jakub Kicinski Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260912234337.308298-2-kuba@kernel.org Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/tcp_metrics.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Documentation/netlink/specs/tcp_metrics.yaml b/Documentation/netlink/specs/tcp_metrics.yaml index 1d365908084d..779e8a22b765 100644 --- a/Documentation/netlink/specs/tcp_metrics.yaml +++ b/Documentation/netlink/specs/tcp_metrics.yaml @@ -93,14 +93,12 @@ attribute-sets: name: rtt type: u32 doc: | - Round Trip Time (RTT), in msecs with 3 bits fractional - (left-shift by 3 to get the msec value). + Round Trip Time (RTT), in msecs with 3 bits fractional. - name: rttvar type: u32 doc: | - Round Trip Time VARiance (RTT), in msecs with 2 bits fractional - (left-shift by 2 to get the msec value). + Round Trip Time VARiance (RTTVAR), in msecs with 2 bits fractional. - name: ssthresh type: u32 @@ -117,14 +115,12 @@ attribute-sets: name: rtt-us type: u32 doc: | - Round Trip Time (RTT), in usecs, with 3 bits fractional - (left-shift by 3 to get the msec value). + Round Trip Time (RTT), in usecs, with 3 bits fractional. - name: rttvar-us type: u32 doc: | - Round Trip Time (RTT), in usecs, with 2 bits fractional - (left-shift by 3 to get the msec value). + Round Trip Time VARiance (RTTVAR), in usecs, with 2 bits fractional. operations: list: From c924efeda80aa098599815319c57d6c937ad24f5 Mon Sep 17 00:00:00 2001 From: Carella Chen Date: Fri, 11 Sep 2026 14:56:52 +0800 Subject: [PATCH 0502/2126] wifi: nl80211: add fast roam offload extended feature Drivers can offload FT or OKC roaming without necessarily advertising full 802.1X 4-way handshake offload. Add an extended feature bit for that capability and allow PMK configuration when it is present. This gives userspace a way to provide PMK or PMK-R0 material needed by fast roaming firmware implementations while keeping the existing 4-way handshake offload capability unchanged. Assisted-by: GitHub-Copilot-CLI:gpt-5.5 Signed-off-by: Carella Chen Signed-off-by: Jason Huang Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260911065656.1269623-2-Jason.Huang2@infineon.com Signed-off-by: Johannes Berg --- include/uapi/linux/nl80211.h | 5 +++++ net/wireless/nl80211.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index d8fefefc11a9..32553cacf988 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7114,6 +7114,10 @@ enum nl80211_feature_flags { * @NL80211_EXT_FEATURE_PROBE_AP: Driver supports probing the associated AP * in STA mode using @NL80211_CMD_PROBE_PEER. * + * @NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD: Driver supports fast roaming + * offload in station mode, including Fast Transition or Opportunistic + * Key Caching. + * * @NUM_NL80211_EXT_FEATURES: number of extended features. * @MAX_NL80211_EXT_FEATURES: highest extended feature index. */ @@ -7196,6 +7200,7 @@ enum nl80211_ext_feature_index { NL80211_EXT_FEATURE_ROC_ADDR_FILTER, NL80211_EXT_FEATURE_SET_KEY_LTF_SEED, NL80211_EXT_FEATURE_PROBE_AP, + NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD, /* add new features before the definition below */ NUM_NL80211_EXT_FEATURES, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index e585da1d79c9..b081eeaf7016 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -18447,6 +18447,7 @@ static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wiphy *wiphy = &rdev->wiphy; struct net_device *dev = info->user_ptr[1]; struct wireless_dev *wdev = dev->ieee80211_ptr; struct cfg80211_pmk_conf pmk_conf = {}; @@ -18455,7 +18456,9 @@ static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) return -EOPNOTSUPP; - if (!wiphy_ext_feature_isset(&rdev->wiphy, + if (!wiphy_ext_feature_isset(wiphy, + NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD) && + !wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) return -EOPNOTSUPP; @@ -18485,6 +18488,7 @@ static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wiphy *wiphy = &rdev->wiphy; struct net_device *dev = info->user_ptr[1]; struct wireless_dev *wdev = dev->ieee80211_ptr; const u8 *aa; @@ -18493,7 +18497,9 @@ static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) return -EOPNOTSUPP; - if (!wiphy_ext_feature_isset(&rdev->wiphy, + if (!wiphy_ext_feature_isset(wiphy, + NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD) && + !wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) return -EOPNOTSUPP; From b1590c5eef0fadb5bc33689f9d98ce58b91154e7 Mon Sep 17 00:00:00 2001 From: Carella Chen Date: Fri, 11 Sep 2026 14:56:53 +0800 Subject: [PATCH 0503/2126] wifi: brcmfmac: detect firmware FBT and OKC support Some firmware advertises Fast BSS Transition and Opportunistic Key Caching support through the firmware capability string. Track those capabilities so later roaming offload handling can be enabled only when firmware reports support. Assisted-by: GitHub-Copilot-CLI:gpt-5.5 Signed-off-by: Carella Chen Signed-off-by: Jason Huang Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260911065656.1269623-3-Jason.Huang2@infineon.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c | 2 ++ drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index 488364ef8ff2..cc19e5e7ebf5 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -45,6 +45,8 @@ static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { { BRCMF_FEAT_SAE, "sae " }, { BRCMF_FEAT_FWAUTH, "idauth" }, { BRCMF_FEAT_SAE_EXT, "sae_ext" }, + { BRCMF_FEAT_FBT, "fbt " }, + { BRCMF_FEAT_OKC, "okc" }, }; #ifdef DEBUG diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h index 31f8695ca417..8165a286b630 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h @@ -59,7 +59,9 @@ BRCMF_FEAT_DEF(SCAN_V2) \ BRCMF_FEAT_DEF(PMKID_V2) \ BRCMF_FEAT_DEF(PMKID_V3) \ - BRCMF_FEAT_DEF(SAE_EXT) + BRCMF_FEAT_DEF(SAE_EXT) \ + BRCMF_FEAT_DEF(FBT) \ + BRCMF_FEAT_DEF(OKC) /* * Quirks: From f84e486e12cfe9de68c250d028acb1a893900167 Mon Sep 17 00:00:00 2001 From: Darren Li Date: Fri, 11 Sep 2026 14:56:54 +0800 Subject: [PATCH 0504/2126] wifi: brcmfmac: add PMK programming for firmware roaming offload FT and OKC roaming offload need PMK material in firmware even when the initial 802.1X exchange is handled by userspace. Add a roaming firmware-supplicant profile state for those connections and allow PMK configuration while firmware FT or OKC state is active. Program the OKC PMK through the okc_info_pmk iovar before setting the regular PMK when firmware reports OKC state. Only select the roaming firmware-supplicant state when firmware advertises FBT or OKC support; devices without those capabilities keep the profile in the userspace supplicant state and do not issue roaming-offload specific iovars on every connect. For FT-PSK with firmware supplicant support, keep the profile in the PSK firmware-supplicant state. Assisted-by: GitHub-Copilot-CLI:gpt-5.5 Signed-off-by: Darren Li Signed-off-by: Chung-Hsien Hsu Signed-off-by: Chi-hsien Lin Co-developed-by: Carella Chen Signed-off-by: Carella Chen Co-developed-by: Shelley Yang Signed-off-by: Shelley Yang Signed-off-by: Jason Huang Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260911065656.1269623-4-Jason.Huang2@infineon.com Signed-off-by: Johannes Berg --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 56 +++++++++++++++++-- .../broadcom/brcm80211/brcmfmac/cfg80211.h | 5 +- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 872c48806d09..f2916cc9e5fc 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -2112,9 +2112,11 @@ brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) struct brcmf_pub *drvr = ifp->drvr; s32 val; s32 err; + s32 okc_enable; const struct brcmf_tlv *rsn_ie; const u8 *ie; u32 ie_len; + bool fwsup_roam; u32 offset; u16 rsn_cap; u32 mfp; @@ -2122,6 +2124,9 @@ brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) profile->use_fwsup = BRCMF_PROFILE_FWSUP_NONE; profile->is_ft = false; + profile->is_okc = false; + fwsup_roam = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FBT) || + brcmf_feat_is_enabled(ifp, BRCMF_FEAT_OKC); if (!sme->crypto.n_akm_suites) return 0; @@ -2138,6 +2143,8 @@ brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) val = WPA_AUTH_UNSPECIFIED; if (sme->want_1x) profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X; + else if (fwsup_roam) + profile->use_fwsup = BRCMF_PROFILE_FWSUP_ROAM; break; case WLAN_AKM_SUITE_PSK: val = WPA_AUTH_PSK; @@ -2153,11 +2160,15 @@ brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) val = WPA2_AUTH_UNSPECIFIED; if (sme->want_1x) profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X; + else if (fwsup_roam) + profile->use_fwsup = BRCMF_PROFILE_FWSUP_ROAM; break; case WLAN_AKM_SUITE_8021X_SHA256: val = WPA2_AUTH_1X_SHA256; if (sme->want_1x) profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X; + else if (fwsup_roam) + profile->use_fwsup = BRCMF_PROFILE_FWSUP_ROAM; break; case WLAN_AKM_SUITE_PSK_SHA256: val = WPA2_AUTH_PSK_SHA256; @@ -2170,10 +2181,16 @@ brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) profile->is_ft = true; if (sme->want_1x) profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X; + else if (fwsup_roam) + profile->use_fwsup = BRCMF_PROFILE_FWSUP_ROAM; break; case WLAN_AKM_SUITE_FT_PSK: val = WPA2_AUTH_PSK | WPA2_AUTH_FT; profile->is_ft = true; + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FWSUP)) + profile->use_fwsup = BRCMF_PROFILE_FWSUP_PSK; + else if (fwsup_roam) + profile->use_fwsup = BRCMF_PROFILE_FWSUP_ROAM; break; case WLAN_AKM_SUITE_WFA_DPP: val = WFA_AUTH_DPP; @@ -2204,8 +2221,22 @@ brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X) brcmf_dbg(INFO, "using 1X offload\n"); + + if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X || + profile->use_fwsup == BRCMF_PROFILE_FWSUP_ROAM) { + err = brcmf_fil_bsscfg_int_get(ifp, "okc_enable", + &okc_enable); + if (err) { + bphy_err(drvr, "get okc_enable failed (%d)\n", err); + } else { + brcmf_dbg(INFO, "okc_enable (%d)\n", okc_enable); + profile->is_okc = okc_enable; + } + } if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_SAE) brcmf_dbg(INFO, "using SAE offload\n"); + if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_ROAM) + brcmf_dbg(INFO, "using roaming offload\n"); if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) goto skip_mfp_config; @@ -2494,13 +2525,14 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, if (sme->crypto.psk && !is_sae_akm && profile->use_fwsup != BRCMF_PROFILE_FWSUP_SAE) { - if (WARN_ON(profile->use_fwsup != - BRCMF_PROFILE_FWSUP_NONE)) { + if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_NONE) { + brcmf_dbg(INFO, "using PSK offload\n"); + profile->use_fwsup = BRCMF_PROFILE_FWSUP_PSK; + } else if (WARN_ON(profile->use_fwsup != + BRCMF_PROFILE_FWSUP_PSK)) { err = -EINVAL; goto done; } - brcmf_dbg(INFO, "using PSK offload\n"); - profile->use_fwsup = BRCMF_PROFILE_FWSUP_PSK; } if (profile->use_fwsup != BRCMF_PROFILE_FWSUP_NONE) { /* enable firmware supplicant for this interface */ @@ -5953,17 +5985,29 @@ static int brcmf_cfg80211_set_pmk(struct wiphy *wiphy, struct net_device *dev, const struct cfg80211_pmk_conf *conf) { struct brcmf_if *ifp; + struct brcmf_pub *drvr; + int ret; brcmf_dbg(TRACE, "enter\n"); - /* expect using firmware supplicant for 1X */ ifp = netdev_priv(dev); - if (WARN_ON(ifp->vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_1X)) + drvr = ifp->drvr; + if (WARN_ON(ifp->vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_1X && + !ifp->vif->profile.is_ft && + !ifp->vif->profile.is_okc)) return -EINVAL; if (conf->pmk_len > BRCMF_WSEC_MAX_PSK_LEN) return -ERANGE; + if (ifp->vif->profile.is_okc) { + ret = brcmf_fil_iovar_data_set(ifp, "okc_info_pmk", + conf->pmk, conf->pmk_len); + if (ret < 0) + bphy_err(drvr, "okc_info_pmk iovar failed: ret=%d\n", + ret); + } + return brcmf_set_pmk(ifp, conf->pmk, conf->pmk_len); } diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h index 63e534523f51..1aa99390a951 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h @@ -127,7 +127,8 @@ enum brcmf_profile_fwsup { BRCMF_PROFILE_FWSUP_NONE, BRCMF_PROFILE_FWSUP_PSK, BRCMF_PROFILE_FWSUP_1X, - BRCMF_PROFILE_FWSUP_SAE + BRCMF_PROFILE_FWSUP_SAE, + BRCMF_PROFILE_FWSUP_ROAM }; /** @@ -164,6 +165,7 @@ enum brcmf_mgmt_tx_status { * @bssid: bssid of joined/joining ibss. * @sec: security information. * @key: key information + * @is_okc: OKC is used for current connection. */ struct brcmf_cfg80211_profile { u8 bssid[ETH_ALEN]; @@ -172,6 +174,7 @@ struct brcmf_cfg80211_profile { enum brcmf_profile_fwsup use_fwsup; u16 use_fwauth; bool is_ft; + bool is_okc; }; /** From a2c7d6fb835477cd188f8c324c63990928b6c744 Mon Sep 17 00:00:00 2001 From: Darren Li Date: Fri, 11 Sep 2026 14:56:55 +0800 Subject: [PATCH 0505/2126] wifi: brcmfmac: report port authorization after offloaded roaming Firmware can complete FT or OKC roaming before the driver reports the connect or roam event to cfg80211. Detect those successful offloaded cases when the profile uses firmware 1X or roaming offload and the association request carries PMK cache state, FT is in use, or OKC is enabled. After reporting the connect or roam event, call cfg80211_port_authorized() so nl80211 emits the dedicated NL80211_CMD_PORT_AUTHORIZED event instead of reusing the reserved NL80211_ATTR_PORT_AUTHORIZED flag in CONNECT/ROAM notifications. Assisted-by: GitHub-Copilot-CLI:gpt-5.5 Signed-off-by: Darren Li Signed-off-by: Chung-Hsien Hsu Signed-off-by: Chi-hsien Lin Signed-off-by: Carella Chen Signed-off-by: Jason Huang Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260911065656.1269623-5-Jason.Huang2@infineon.com Signed-off-by: Johannes Berg --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index f2916cc9e5fc..c11b3eac9d47 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -6466,6 +6466,47 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, return err; } +static bool brcmf_has_pmkid(const u8 *parse, u32 len) +{ + const struct brcmf_tlv *rsn_ie; + const u8 *ie; + u32 ie_len; + u32 offset; + u16 count; + + if (!parse) + return false; + + rsn_ie = brcmf_parse_tlvs(parse, len, WLAN_EID_RSN); + if (!rsn_ie) + return false; + + ie = (const u8 *)rsn_ie; + ie_len = rsn_ie->len + TLV_HDR_LEN; + + offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN; + if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) + return false; + + count = ie[offset] + (ie[offset + 1] << 8); + offset += WPA_IE_SUITE_COUNT_LEN + count * WPA_IE_MIN_OUI_LEN; + if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) + return false; + + count = ie[offset] + (ie[offset + 1] << 8); + offset += WPA_IE_SUITE_COUNT_LEN + count * WPA_IE_MIN_OUI_LEN; + if (offset + RSN_CAP_LEN >= ie_len) + return false; + + offset += RSN_CAP_LEN; + if (offset + RSN_PMKID_COUNT_LEN > ie_len) + return false; + + count = ie[offset] + (ie[offset + 1] << 8); + + return count > 0; +} + static s32 brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, struct net_device *ndev, @@ -6480,6 +6521,7 @@ brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, struct brcmf_bss_info_le *bi; struct brcmu_chan ch; struct cfg80211_roam_info roam_info = {}; + bool authorized = false; u32 freq; s32 err = 0; u8 *buf; @@ -6526,13 +6568,17 @@ done: roam_info.resp_ie = conn_info->resp_ie; roam_info.resp_ie_len = conn_info->resp_ie_len; - cfg80211_roamed(ndev, &roam_info, GFP_KERNEL); - brcmf_dbg(CONN, "Report roaming result\n"); + if ((profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X || + profile->use_fwsup == BRCMF_PROFILE_FWSUP_ROAM) && + (brcmf_has_pmkid(roam_info.req_ie, roam_info.req_ie_len) || + profile->is_ft || profile->is_okc)) + authorized = true; - if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X && profile->is_ft) { - cfg80211_port_authorized(ndev, profile->bssid, NULL, 0, GFP_KERNEL); - brcmf_dbg(CONN, "Report port authorized\n"); - } + cfg80211_roamed(ndev, &roam_info, GFP_KERNEL); + if (authorized) + cfg80211_port_authorized(ndev, profile->bssid, NULL, 0, + GFP_KERNEL); + brcmf_dbg(CONN, "Report roaming result\n"); set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); brcmf_dbg(TRACE, "Exit\n"); @@ -6548,6 +6594,7 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); struct cfg80211_connect_resp_params conn_params; + bool authorized; brcmf_dbg(TRACE, "Enter\n"); @@ -6572,7 +6619,15 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, conn_params.req_ie_len = conn_info->req_ie_len; conn_params.resp_ie = conn_info->resp_ie; conn_params.resp_ie_len = conn_info->resp_ie_len; + authorized = completed && + (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X || + profile->use_fwsup == BRCMF_PROFILE_FWSUP_ROAM) && + brcmf_has_pmkid(conn_params.req_ie, + conn_params.req_ie_len); cfg80211_connect_done(ndev, &conn_params, GFP_KERNEL); + if (authorized) + cfg80211_port_authorized(ndev, profile->bssid, NULL, 0, + GFP_KERNEL); brcmf_dbg(CONN, "Report connect result - connection %s\n", completed ? "succeeded" : "failed"); } From f2e344a8d8008970cbb45dee3de8f220fe6755bb Mon Sep 17 00:00:00 2001 From: Carella Chen Date: Fri, 11 Sep 2026 14:56:56 +0800 Subject: [PATCH 0506/2126] wifi: brcmfmac: advertise firmware fast roam offload support Advertise NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD only when firmware reports FBT or OKC support. That lets userspace provide PMK material for firmware fast roaming without enabling the path on devices that cannot complete the offloaded roam. Assisted-by: GitHub-Copilot-CLI:gpt-5.5 Signed-off-by: Carella Chen Signed-off-by: Jason Huang Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260911065656.1269623-6-Jason.Huang2@infineon.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index c11b3eac9d47..519de96b042e 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -7830,6 +7830,10 @@ static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) } if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SAE_EXT)) wiphy->features |= NL80211_FEATURE_SAE; + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FBT) || + brcmf_feat_is_enabled(ifp, BRCMF_FEAT_OKC)) + wiphy_ext_feature_set(wiphy, + NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD); wiphy->mgmt_stypes = brcmf_txrx_stypes; wiphy->max_remain_on_channel_duration = 5000; if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) { From 42aa76b3fd9278a8504dbfaf0a449993104d2a48 Mon Sep 17 00:00:00 2001 From: Ryohei Hashimoto Date: Mon, 14 Sep 2026 01:55:26 +0900 Subject: [PATCH 0507/2126] wifi: brcmfmac: log the firmware status when a connect fails brcmf_bss_connect_done() receives the firmware event in @e but discards it on the failure path. Every failed connect is reported to cfg80211 as WLAN_STATUS_AUTH_TIMEOUT (16), whatever the firmware actually said, so userspace only ever sees: wlan0: CTRL-EVENT-ASSOC-REJECT bssid=00:00:00:00:00:00 status_code=16 The all-zero BSSID comes from the same place: conn_params is memset to zero and profile->bssid has not been filled in when the station never associated. status_code=16 therefore carries no information about the cause. It is not an AP response and it does not mean "authentication timed out" - it is the only failure value this driver can produce. This is a recurring source of confusion: [1] has been open since 2023 with more than twenty follow-ups and no explanation of the code, and covers BCM4345/6, BCM43430 and CYW43455 across several kernel versions. It supersedes [2], filed against the firmware repository a day earlier and closed in favour of it. The firmware's own status (BRCMF_E_STATUS_*) is more specific - FAIL, TIMEOUT, NO_NETWORKS, ABORT and so on - and it is already in hand. Log it so the cause can be narrowed down without rebuilding the kernel. bphy_err() is used rather than brcmf_dbg() or brcmf_info(): it is the form the rest of this file uses, and of the three it is the only one that is both visible in a distribution kernel and bounded. brcmf_dbg(CONN) expands to no_printk() unless CONFIG_BRCMDBG is set, which is what makes the reports in [1] and [2] impossible to act on - the people hitting this run stock kernels. brcmf_info() expands to a plain pr_info() in a non-debug build and is not rate limited, and wpa_supplicant retries the association every few seconds, so it would flood the log. bphy_err() is guarded by net_ratelimit() there, so a station retrying against an unreachable AP prints at most a few lines per second. All three fields are printed because only some of them are meaningful on each path into the failure branch. brcmf_is_nonetwork() keys off @status, so that is the useful field for a join that never associated - the case in [1]. brcmf_is_linkdown() keys off @event_code and @flags and does not look at @status at all, so @status can read 0 there; on those events it is @reason which carries the 802.11 reason code, as the mapping in brcmf_map_fw_linkdown_reason() shows. Printing the three together lets the reader tell which path was taken instead of guessing from one number. The status reported to cfg80211 is left alone; changing it would alter what userspace sees. [1] https://github.com/RPi-Distro/firmware-nonfree/issues/38 [2] https://github.com/raspberrypi/firmware/issues/1829 Assisted-by: Claude:claude-opus-5 Signed-off-by: Ryohei Hashimoto Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260913165526.4426-1-laurel.medalist12@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 519de96b042e..9d8ce7bb046e 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -6613,6 +6613,8 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &ifp->vif->sme_state); conn_params.status = WLAN_STATUS_AUTH_TIMEOUT; + bphy_err(ifp->drvr, "connect failed: event %u status %u reason %u\n", + e->event_code, e->status, e->reason); } conn_params.links[0].bssid = profile->bssid; conn_params.req_ie = conn_info->req_ie; From b8e9e7d82e7eefd5d2d528469d94ec20e96b38c3 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:31:01 -0700 Subject: [PATCH 0508/2126] selftests: drv-net: devmem: set reuseaddr on the sender's source port devmem.py fails on the HW runners with: CMD[remote]: dd if=/dev/zero bs=512 count=1 2>/dev/null | socat -b 512 \ -u - TCP6:[fd00:2::1]:50051,bind=[fd00:2::2]:50051,nodelay STDERR: socat[41018] W bind(5, {AF=10 [fd00:2::2]:50051}, 28): \ Address already in use ncdevmem installs a 5-tuple flow rule which matches the source port, so socat has to bind it explicitly. The port comes from rand_port(), which checks availability on the DUT - but we bind on the remote... That said the failure rate seems to high to be random collisions (~2% per sub-test). It's probably TIME_WAIT sockets on the remote, run_rx_hds() alone creates 12 of them. Set reuseaddr so a TIME_WAIT socket does not fail the bind. Collisions with a live socket are still possible, we'll see if they are frequent enough to care. Reviewed-by: Breno Leitao Reviewed-by: Bobby Eshleman Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260912203101.153688-1-kuba@kernel.org Signed-off-by: Paolo Abeni --- tools/testing/selftests/drivers/net/hw/devmem_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/devmem_lib.py b/tools/testing/selftests/drivers/net/hw/devmem_lib.py index 3554954a6691..71b916c16196 100644 --- a/tools/testing/selftests/drivers/net/hw/devmem_lib.py +++ b/tools/testing/selftests/drivers/net/hw/devmem_lib.py @@ -201,7 +201,7 @@ def socat_send(cfg, port, buf_size=0): else: addr = cfg.baddr - suffix = f",bind={cfg.remote_baddr}:{port}" + suffix = f",bind={cfg.remote_baddr}:{port},reuseaddr" buf = "" if buf_size: @@ -213,7 +213,7 @@ def socat_send(cfg, port, buf_size=0): def socat_listen(cfg, port): """Socat listen command for TX tests.""" - return f"socat -U - TCP{cfg.addr_ipver}-LISTEN:{port}" + return f"socat -U - TCP{cfg.addr_ipver}-LISTEN:{port},reuseaddr" def setup_test(cfg, bin_local): From 24c21f0e97a4cae0f42a420e0e286e2eea051004 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Tue, 15 Sep 2026 09:36:48 -0700 Subject: [PATCH 0509/2126] MAINTAINERS: Replace wireless.wiki.kernel.org links wireless.wiki.kernel.org has not existed for a while. Update all links to point to the current rendered pages at wireless.docs.kernel.org. Signed-off-by: Jeff Johnson Link: https://patch.msgid.link/20260915-wireless-wiki-v1-1-21dc76684b44@oss.qualcomm.com Signed-off-by: Johannes Berg --- MAINTAINERS | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index b23fb6f2f4ef..f6ead73ab92d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -113,7 +113,7 @@ F: net/6lowpan/ M: Johannes Berg L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/ +W: https://wireless.docs.kernel.org/en/latest/ Q: https://patchwork.kernel.org/project/linux-wireless/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git @@ -4260,13 +4260,13 @@ M: Nick Kossifidis M: Luis Chamberlain L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/en/users/Drivers/ath5k +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath5k.html F: drivers/net/wireless/ath/ath5k/ ATHEROS ATH6KL WIRELESS DRIVER L: linux-wireless@vger.kernel.org S: Orphan -W: https://wireless.wiki.kernel.org/en/users/Drivers/ath6kl +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath6kl.html F: drivers/net/wireless/ath/ath6kl/ ATI_REMOTE2 DRIVER @@ -4535,14 +4535,14 @@ B43 WIRELESS DRIVER L: linux-wireless@vger.kernel.org L: b43-dev@lists.infradead.org S: Orphan -W: https://wireless.wiki.kernel.org/en/users/Drivers/b43 +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/b43.html F: drivers/net/wireless/broadcom/b43/ B43LEGACY WIRELESS DRIVER L: linux-wireless@vger.kernel.org L: b43-dev@lists.infradead.org S: Orphan -W: https://wireless.wiki.kernel.org/en/users/Drivers/b43 +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/b43.html F: drivers/net/wireless/broadcom/b43legacy/ BACKLIGHT CLASS/SUBSYSTEM @@ -5919,7 +5919,7 @@ CARL9170 LINUX COMMUNITY WIRELESS DRIVER M: Christian Lamparter L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/en/users/Drivers/carl9170 +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/carl9170.html F: drivers/net/wireless/ath/carl9170/ CAVIUM I2C DRIVER @@ -13560,7 +13560,7 @@ INTEL WIRELESS WIFI LINK (iwlwifi) M: Miri Korenblit L: linux-wireless@vger.kernel.org S: Supported -W: https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/iwlwifi.html T: git https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-next.git/ F: drivers/net/wireless/intel/iwlwifi/ @@ -15661,7 +15661,7 @@ MAC80211 M: Johannes Berg L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/ +W: https://wireless.docs.kernel.org/en/latest/ Q: https://patchwork.kernel.org/project/linux-wireless/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git @@ -18920,7 +18920,7 @@ NETWORKING DRIVERS (WIRELESS) M: Johannes Berg L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/ +W: https://wireless.docs.kernel.org/en/latest/ Q: https://patchwork.kernel.org/project/linux-wireless/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git @@ -20592,7 +20592,7 @@ P54 WIRELESS DRIVER M: Christian Lamparter L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/en/users/Drivers/p54 +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/p54.html F: Documentation/devicetree/bindings/net/wireless/st,stlc4560.yaml F: drivers/net/wireless/intersil/ @@ -22282,7 +22282,7 @@ M: Jeff Johnson L: linux-wireless@vger.kernel.org L: ath12k@lists.infradead.org S: Supported -W: https://wireless.wiki.kernel.org/en/users/Drivers/ath12k +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath12k.html T: git git://git.kernel.org/pub/scm/linux/kernel/git/ath/ath.git F: drivers/net/wireless/ath/ath12k/ N: ath12k @@ -22292,7 +22292,7 @@ M: Jeff Johnson L: linux-wireless@vger.kernel.org L: ath10k@lists.infradead.org S: Supported -W: https://wireless.wiki.kernel.org/en/users/Drivers/ath10k +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath10k.html T: git git://git.kernel.org/pub/scm/linux/kernel/git/ath/ath.git F: drivers/net/wireless/ath/ath10k/ N: ath10k @@ -22302,8 +22302,8 @@ M: Jeff Johnson L: linux-wireless@vger.kernel.org L: ath11k@lists.infradead.org S: Supported -W: https://wireless.wiki.kernel.org/en/users/Drivers/ath11k -B: https://wireless.wiki.kernel.org/en/users/Drivers/ath11k/bugreport +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath11k.html +B: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath11k/bugreport.html T: git git://git.kernel.org/pub/scm/linux/kernel/git/ath/ath.git F: drivers/net/wireless/ath/ath11k/ N: ath11k @@ -22312,7 +22312,7 @@ QUALCOMM ATHEROS ATH9K WIRELESS DRIVER M: Toke Høiland-Jørgensen L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/en/users/Drivers/ath9k +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/ath9k.html T: git git://git.kernel.org/pub/scm/linux/kernel/git/ath/ath.git F: Documentation/devicetree/bindings/net/wireless/qca,ath9k.yaml F: drivers/net/wireless/ath/ath9k/ @@ -22654,7 +22654,7 @@ M: Loic Poulain L: wcn36xx@lists.infradead.org L: linux-wireless@vger.kernel.org S: Supported -W: https://wireless.wiki.kernel.org/en/users/Drivers/wcn36xx +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/wcn36xx.html F: drivers/net/wireless/ath/wcn36xx/ QUANTENNA QTNFMAC WIRELESS DRIVER @@ -23413,7 +23413,7 @@ RFKILL M: Johannes Berg L: linux-wireless@vger.kernel.org S: Maintained -W: https://wireless.wiki.kernel.org/ +W: https://wireless.docs.kernel.org/en/latest/ Q: https://patchwork.kernel.org/project/linux-wireless/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git @@ -27508,8 +27508,8 @@ F: drivers/media/platform/ti/vpe/ TI WILINK WIRELESS DRIVERS L: linux-wireless@vger.kernel.org S: Orphan -W: https://wireless.wiki.kernel.org/en/users/Drivers/wl12xx -W: https://wireless.wiki.kernel.org/en/users/Drivers/wl1251 +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/wl12xx.html +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/wl1251.html F: drivers/net/wireless/ti/ TIMEKEEPING, CLOCKSOURCE CORE, NTP, ALARMTIMER @@ -29386,7 +29386,7 @@ F: drivers/hid/hid-wiimote* WILOCITY WIL6210 WIRELESS DRIVER L: linux-wireless@vger.kernel.org S: Orphan -W: https://wireless.wiki.kernel.org/en/users/Drivers/wil6210 +W: https://wireless.docs.kernel.org/en/latest/en/users/drivers/wil6210.html F: drivers/net/wireless/ath/wil6210/ WINBOND CIR DRIVER From 47dbcfdf942a35dbf842ea05bb2248fcda411da7 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 12 Sep 2026 08:00:19 +0200 Subject: [PATCH 0510/2126] page_pool: Fix page_pool_alloc_va() reference in kernel-doc The kernel-doc comment of page_pool_free_va() refers to page_pool_allo_va, which does not exist. The name is page_pool_alloc_va. Say page_pool_alloc_va. The wrong name came in with commit 8ab32fa1c794 ("page_pool: update document about fragment API"). Signed-off-by: Karl Mehltretter Link: https://patch.msgid.link/20260912060019.39902-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- include/net/page_pool/helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index e2730dd273b2..87a4e13886e1 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -417,7 +417,7 @@ static inline void page_pool_recycle_direct_netmem(struct page_pool *pool, * @va: va to be freed * @allow_direct: freed by the consumer, allow lockless caching * - * Free a va allocated from page_pool_allo_va(). + * Free a va allocated from page_pool_alloc_va(). */ static inline void page_pool_free_va(struct page_pool *pool, void *va, bool allow_direct) From 3661253d2253b92d30e3734aa46e5ad41df7043d Mon Sep 17 00:00:00 2001 From: Dimitri Daskalakis Date: Fri, 11 Sep 2026 15:42:55 -0700 Subject: [PATCH 0511/2126] selftests: drv-net: remove duplicate functions in hds.py There were duplicate definitions of the enabled_set_xdp and set_xdp test methods. The two enabled_set_xdp copies were identical apart from a comment and whitespace. The set_xdp copies differed by a reset of the hds configuration. commit ee3ae27721fb ("selftests: drv-net: hds: restore hds settings") introduced the config reset, but this was shadowed by the copy. Signed-off-by: Dimitri Daskalakis Link: https://patch.msgid.link/20260911224255.3675903-1-dimitri.daskalakis1@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hds.py | 29 ---------------------- 1 file changed, 29 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hds.py b/tools/testing/selftests/drivers/net/hds.py index c4fe049e9baa..606e26d75951 100755 --- a/tools/testing/selftests/drivers/net/hds.py +++ b/tools/testing/selftests/drivers/net/hds.py @@ -240,35 +240,6 @@ def enabled_set_xdp(cfg, netnl) -> None: _xdp_onoff(cfg) -def set_xdp(cfg, netnl) -> None: - """ - Enable single-buffer XDP on the device. - When HDS is in "auto" / UNKNOWN mode, XDP installation should work. - """ - mode = _get_hds_mode(cfg, netnl) - if mode == 'enabled': - netnl.rings_set({'header': {'dev-index': cfg.ifindex}, - 'tcp-data-split': 'unknown'}) - - _xdp_onoff(cfg) - - -def enabled_set_xdp(cfg, netnl) -> None: - """ - Enable single-buffer XDP on the device. - When HDS is in "enabled" mode, XDP installation should not work. - """ - _get_hds_mode(cfg, netnl) # Trigger skip if not supported - - netnl.rings_set({'header': {'dev-index': cfg.ifindex}, - 'tcp-data-split': 'enabled'}) - defer(netnl.rings_set, {'header': {'dev-index': cfg.ifindex}, - 'tcp-data-split': 'unknown'}) - - with ksft_raises(CmdExitFailure) as e: - _xdp_onoff(cfg) - - def ioctl(cfg, netnl) -> None: mode1 = _get_hds_mode(cfg, netnl) _ioctl_ringparam_modify(cfg, netnl) From 032ef43b9dab22f1e2fe9923b4d8b23d3ea9943d Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 14 Sep 2026 17:56:46 +0200 Subject: [PATCH 0512/2126] dt-bindings: net: Use consistent indentation in the example Correct indentation in the examples to consistent 2- or 4-spaces indentation to fix dt-check-style warnings ("example 0 [indent-consistent] indent mismatch ..."). Preferred is 4-spaces, but re-indenting entire example just for that is too much churn. In cortina,gemini-ethernet.yaml also drop the wrongly indented mdio bus, because it is not necessary for the example. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Linus Walleij Reviewed-by: AngeloGioacchino Del Regno Acked-by: Alex Elder Link: https://patch.msgid.link/20260914155645.112508-2-krzysztof.kozlowski@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../bindings/net/brcm,asp-v2.0.yaml | 2 +- .../bindings/net/cortina,gemini-ethernet.yaml | 52 ++++++-------- .../bindings/net/dsa/renesas,rzn1-a5psw.yaml | 4 +- .../bindings/net/intel,dwmac-plat.yaml | 6 +- .../devicetree/bindings/net/mdio-gpio.yaml | 16 ++--- .../bindings/net/mscc,vsc7514-switch.yaml | 8 +-- .../devicetree/bindings/net/qcom,ipa.yaml | 10 +-- .../bindings/net/realtek,rtl82xx.yaml | 6 +- .../bindings/net/socionext,uniphier-ave4.yaml | 32 ++++----- .../bindings/net/ti,cpsw-switch.yaml | 70 +++++++++---------- .../bindings/net/wireless/mediatek,mt76.yaml | 32 ++++----- .../bindings/net/wireless/qcom,ath10k.yaml | 2 +- 12 files changed, 114 insertions(+), 126 deletions(-) diff --git a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml index a3db6d594c8c..7fcc564e820c 100644 --- a/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml +++ b/Documentation/devicetree/bindings/net/brcm,asp-v2.0.yaml @@ -123,7 +123,7 @@ examples: phy0: ethernet-phy@1 { reg = <1>; }; - }; + }; mdio@ce14 { compatible = "brcm,asp-v2.1-mdio"; diff --git a/Documentation/devicetree/bindings/net/cortina,gemini-ethernet.yaml b/Documentation/devicetree/bindings/net/cortina,gemini-ethernet.yaml index f0b5bea2458d..da9bc170cd54 100644 --- a/Documentation/devicetree/bindings/net/cortina,gemini-ethernet.yaml +++ b/Documentation/devicetree/bindings/net/cortina,gemini-ethernet.yaml @@ -87,18 +87,6 @@ examples: #include #include #include - mdio0: mdio { - #address-cells = <1>; - #size-cells = <0>; - phy0: ethernet-phy@1 { - reg = <1>; - device_type = "ethernet-phy"; - }; - phy1: ethernet-phy@3 { - reg = <3>; - device_type = "ethernet-phy"; - }; - }; ethernet@60000000 { compatible = "cortina,gemini-ethernet"; @@ -110,28 +98,28 @@ examples: ranges; gmac0: ethernet-port@0 { - compatible = "cortina,gemini-ethernet-port"; - reg = <0x60008000 0x2000>, /* Port 0 DMA/TOE */ - <0x6000a000 0x2000>; /* Port 0 GMAC */ - interrupt-parent = <&intcon>; - interrupts = <1 IRQ_TYPE_LEVEL_HIGH>; - resets = <&syscon GEMINI_RESET_GMAC0>; - clocks = <&syscon GEMINI_CLK_GATE_GMAC0>; - clock-names = "PCLK"; - phy-mode = "rgmii"; - phy-handle = <&phy0>; + compatible = "cortina,gemini-ethernet-port"; + reg = <0x60008000 0x2000>, /* Port 0 DMA/TOE */ + <0x6000a000 0x2000>; /* Port 0 GMAC */ + interrupt-parent = <&intcon>; + interrupts = <1 IRQ_TYPE_LEVEL_HIGH>; + resets = <&syscon GEMINI_RESET_GMAC0>; + clocks = <&syscon GEMINI_CLK_GATE_GMAC0>; + clock-names = "PCLK"; + phy-mode = "rgmii"; + phy-handle = <&phy0>; }; gmac1: ethernet-port@1 { - compatible = "cortina,gemini-ethernet-port"; - reg = <0x6000c000 0x2000>, /* Port 1 DMA/TOE */ - <0x6000e000 0x2000>; /* Port 1 GMAC */ - interrupt-parent = <&intcon>; - interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; - resets = <&syscon GEMINI_RESET_GMAC1>; - clocks = <&syscon GEMINI_CLK_GATE_GMAC1>; - clock-names = "PCLK"; - phy-mode = "rgmii"; - phy-handle = <&phy1>; + compatible = "cortina,gemini-ethernet-port"; + reg = <0x6000c000 0x2000>, /* Port 1 DMA/TOE */ + <0x6000e000 0x2000>; /* Port 1 GMAC */ + interrupt-parent = <&intcon>; + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; + resets = <&syscon GEMINI_RESET_GMAC1>; + clocks = <&syscon GEMINI_CLK_GATE_GMAC1>; + clock-names = "PCLK"; + phy-mode = "rgmii"; + phy-handle = <&phy1>; }; }; diff --git a/Documentation/devicetree/bindings/net/dsa/renesas,rzn1-a5psw.yaml b/Documentation/devicetree/bindings/net/dsa/renesas,rzn1-a5psw.yaml index ea285ef3e64f..fab6aa6237e9 100644 --- a/Documentation/devicetree/bindings/net/dsa/renesas,rzn1-a5psw.yaml +++ b/Documentation/devicetree/bindings/net/dsa/renesas,rzn1-a5psw.yaml @@ -127,8 +127,8 @@ examples: phy-mode = "internal"; fixed-link { - speed = <1000>; - full-duplex; + speed = <1000>; + full-duplex; }; }; }; diff --git a/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml b/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml index 62c1da36a2b5..d1522216d32b 100644 --- a/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml +++ b/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml @@ -91,9 +91,9 @@ examples: snps,tx-queues-to-use = <2>; snps,tx-sched-wrr; queue0 { - snps,weight = <0x10>; - snps,dcb-algorithm; - snps,priority = <0x0>; + snps,weight = <0x10>; + snps,dcb-algorithm; + snps,priority = <0x0>; }; queue1 { diff --git a/Documentation/devicetree/bindings/net/mdio-gpio.yaml b/Documentation/devicetree/bindings/net/mdio-gpio.yaml index eb4171a1940e..36e51aaae9c0 100644 --- a/Documentation/devicetree/bindings/net/mdio-gpio.yaml +++ b/Documentation/devicetree/bindings/net/mdio-gpio.yaml @@ -45,13 +45,13 @@ examples: }; mdio0: mdio { - compatible = "virtual,mdio-gpio"; - #address-cells = <1>; - #size-cells = <0>; - gpios = <&qe_pio_a 11>, - <&qe_pio_c 6>; - ethphy0: ethernet-phy@0 { - reg = <0>; - }; + compatible = "virtual,mdio-gpio"; + #address-cells = <1>; + #size-cells = <0>; + gpios = <&qe_pio_a 11>, + <&qe_pio_c 6>; + ethphy0: ethernet-phy@0 { + reg = <0>; + }; }; ... diff --git a/Documentation/devicetree/bindings/net/mscc,vsc7514-switch.yaml b/Documentation/devicetree/bindings/net/mscc,vsc7514-switch.yaml index 86a9c3fc76c8..d825130b54b4 100644 --- a/Documentation/devicetree/bindings/net/mscc,vsc7514-switch.yaml +++ b/Documentation/devicetree/bindings/net/mscc,vsc7514-switch.yaml @@ -197,10 +197,10 @@ examples: <0x71040000 0x10000>, <0x71050000 0x10000>, <0x71060000 0x10000>; - reg-names = "sys", "rew", "qs", "ptp", "port0", "port1", - "port2", "port3", "port4", "port5", "port6", - "port7", "port8", "port9", "port10", "qsys", - "ana", "s0", "s1", "s2"; + reg-names = "sys", "rew", "qs", "ptp", "port0", "port1", + "port2", "port3", "port4", "port5", "port6", + "port7", "port8", "port9", "port10", "qsys", + "ana", "s0", "s1", "s2"; ethernet-ports { #address-cells = <1>; diff --git a/Documentation/devicetree/bindings/net/qcom,ipa.yaml b/Documentation/devicetree/bindings/net/qcom,ipa.yaml index 68ec76fe4473..38e3830512fe 100644 --- a/Documentation/devicetree/bindings/net/qcom,ipa.yaml +++ b/Documentation/devicetree/bindings/net/qcom,ipa.yaml @@ -246,14 +246,14 @@ examples: qcom,remote-pid = <5>; ipa_smp2p_out: ipa-ap-to-modem { - qcom,entry-name = "ipa"; - #qcom,smem-state-cells = <1>; + qcom,entry-name = "ipa"; + #qcom,smem-state-cells = <1>; }; ipa_smp2p_in: ipa-modem-to-ap { - qcom,entry-name = "ipa"; - interrupt-controller; - #interrupt-cells = <2>; + qcom,entry-name = "ipa"; + interrupt-controller; + #interrupt-cells = <2>; }; }; diff --git a/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml b/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml index 45033c31a2d5..07b39ef1fc62 100644 --- a/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +++ b/Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml @@ -91,8 +91,8 @@ examples: #size-cells = <0>; ethphy1: ethernet-phy@1 { - reg = <1>; - realtek,clkout-disable; - realtek,aldps-enable; + reg = <1>; + realtek,clkout-disable; + realtek,aldps-enable; }; }; diff --git a/Documentation/devicetree/bindings/net/socionext,uniphier-ave4.yaml b/Documentation/devicetree/bindings/net/socionext,uniphier-ave4.yaml index 4eb63b303cff..8c8622160abb 100644 --- a/Documentation/devicetree/bindings/net/socionext,uniphier-ave4.yaml +++ b/Documentation/devicetree/bindings/net/socionext,uniphier-ave4.yaml @@ -121,22 +121,22 @@ examples: - | ether: ethernet@65000000 { compatible = "socionext,uniphier-ld20-ave4"; - reg = <0x65000000 0x8500>; - interrupts = <0 66 4>; - phy-mode = "rgmii"; - phy-handle = <ðphy>; - clock-names = "ether"; - clocks = <&sys_clk 6>; - reset-names = "ether"; - resets = <&sys_rst 6>; - socionext,syscon-phy-mode = <&soc_glue 0>; + reg = <0x65000000 0x8500>; + interrupts = <0 66 4>; + phy-mode = "rgmii"; + phy-handle = <ðphy>; + clock-names = "ether"; + clocks = <&sys_clk 6>; + reset-names = "ether"; + resets = <&sys_rst 6>; + socionext,syscon-phy-mode = <&soc_glue 0>; - mdio { - #address-cells = <1>; - #size-cells = <0>; + mdio { + #address-cells = <1>; + #size-cells = <0>; - ethphy: ethernet-phy@1 { - reg = <1>; - }; - }; + ethphy: ethernet-phy@1 { + reg = <1>; + }; }; + }; diff --git a/Documentation/devicetree/bindings/net/ti,cpsw-switch.yaml b/Documentation/devicetree/bindings/net/ti,cpsw-switch.yaml index 8b5da602a2e8..4d24dadfaa5d 100644 --- a/Documentation/devicetree/bindings/net/ti,cpsw-switch.yaml +++ b/Documentation/devicetree/bindings/net/ti,cpsw-switch.yaml @@ -192,50 +192,50 @@ examples: interrupt-names = "rx_thresh", "rx", "tx", "misc"; ethernet-ports { - #address-cells = <1>; - #size-cells = <0>; + #address-cells = <1>; + #size-cells = <0>; - cpsw_port1: port@1 { - reg = <1>; - label = "port1"; - mac-address = [ 00 00 00 00 00 00 ]; - phys = <&phy_gmii_sel 1>; - phy-handle = <ðphy0_sw>; - phy-mode = "rgmii"; - ti,dual-emac-pvid = <1>; - }; + cpsw_port1: port@1 { + reg = <1>; + label = "port1"; + mac-address = [ 00 00 00 00 00 00 ]; + phys = <&phy_gmii_sel 1>; + phy-handle = <ðphy0_sw>; + phy-mode = "rgmii"; + ti,dual-emac-pvid = <1>; + }; - cpsw_port2: port@2 { - reg = <2>; - label = "wan"; - mac-address = [ 00 00 00 00 00 00 ]; - phys = <&phy_gmii_sel 2>; - phy-handle = <ðphy1_sw>; - phy-mode = "rgmii"; - ti,dual-emac-pvid = <2>; - }; + cpsw_port2: port@2 { + reg = <2>; + label = "wan"; + mac-address = [ 00 00 00 00 00 00 ]; + phys = <&phy_gmii_sel 2>; + phy-handle = <ðphy1_sw>; + phy-mode = "rgmii"; + ti,dual-emac-pvid = <2>; + }; }; davinci_mdio_sw: mdio@1000 { - compatible = "ti,cpsw-mdio","ti,davinci_mdio"; - reg = <0x1000 0x100>; - clocks = <&gmac_clkctrl DRA7_GMAC_GMAC_CLKCTRL 0>; - clock-names = "fck"; - #address-cells = <1>; - #size-cells = <0>; - bus_freq = <1000000>; + compatible = "ti,cpsw-mdio","ti,davinci_mdio"; + reg = <0x1000 0x100>; + clocks = <&gmac_clkctrl DRA7_GMAC_GMAC_CLKCTRL 0>; + clock-names = "fck"; + #address-cells = <1>; + #size-cells = <0>; + bus_freq = <1000000>; - ethphy0_sw: ethernet-phy@0 { - reg = <0>; - }; + ethphy0_sw: ethernet-phy@0 { + reg = <0>; + }; - ethphy1_sw: ethernet-phy@1 { - reg = <1>; - }; + ethphy1_sw: ethernet-phy@1 { + reg = <1>; + }; }; cpts { - clocks = <&gmac_clkctrl DRA7_GMAC_GMAC_CLKCTRL 25>; - clock-names = "cpts"; + clocks = <&gmac_clkctrl DRA7_GMAC_GMAC_CLKCTRL 25>; + clock-names = "cpts"; }; }; diff --git a/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml b/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml index ae6b97cdc44b..bf4116b057d2 100644 --- a/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml +++ b/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml @@ -325,22 +325,22 @@ examples: r0 { regdomain = "FCC"; txpower-5g { - b0 { - channels = <36 48>; - rates-ofdm = /bits/ 8 <23 23 23 23 23 23 23 23>; - rates-mcs = /bits/ 8 <1 23 23 23 23 23 23 23 23 23 23>, - /bits/ 8 <3 22 22 22 22 22 22 22 22 22 22>; - rates-ru = /bits/ 8 <3 22 22 22 22 22 22 22 22 22 22 22 22>, - /bits/ 8 <4 20 20 20 20 20 20 20 20 20 20 20 20>; - }; - b1 { - channels = <100 181>; - rates-ofdm = /bits/ 8 <14 14 14 14 14 14 14 14>; - rates-mcs = /bits/ 8 <4 14 14 14 14 14 14 14 14 14 14>; - txs-delta = <12 9 6>; - rates-ru = /bits/ 8 <7 14 14 14 14 14 14 14 14 14 14 14 14>; - }; - }; + b0 { + channels = <36 48>; + rates-ofdm = /bits/ 8 <23 23 23 23 23 23 23 23>; + rates-mcs = /bits/ 8 <1 23 23 23 23 23 23 23 23 23 23>, + /bits/ 8 <3 22 22 22 22 22 22 22 22 22 22>; + rates-ru = /bits/ 8 <3 22 22 22 22 22 22 22 22 22 22 22 22>, + /bits/ 8 <4 20 20 20 20 20 20 20 20 20 20 20 20>; + }; + b1 { + channels = <100 181>; + rates-ofdm = /bits/ 8 <14 14 14 14 14 14 14 14>; + rates-mcs = /bits/ 8 <4 14 14 14 14 14 14 14 14 14 14>; + txs-delta = <12 9 6>; + rates-ru = /bits/ 8 <7 14 14 14 14 14 14 14 14 14 14 14 14>; + }; + }; }; }; }; diff --git a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml index e667d78b3ab3..a52cb8a0d409 100644 --- a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml +++ b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml @@ -408,4 +408,4 @@ examples: "msi15", "legacy"; ieee80211-freq-limit = <5470000 5875000>; - }; + }; From b785f5c56fb3dbe70635592b11547a2c828e95b3 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:24:01 -0700 Subject: [PATCH 0513/2126] netlink: policy: report the big endian attributes Paolo pointed out an issue flagged at low priority by Sashiko - we're currently not handling BE{16,32} attributes in policy dumps. Commit 3f4285d741b4 ("netlink: specs: fou: local-v4 and peer-v4 are big endian") flipped two fou attributes from NLA_U32 to NLA_BE32. This made them vanish from the policy dump. Follow the YAML spec format and treat byte order as a property of a u16 / u32 rather than a type of its own. I don't have a strong preference either way. The YNL format "feels cleaner" but the kernel's separate type is easier when handling decoding. I don't think that the policy type is actually usable for decoding (since it only contains input types) so I went with YNL and added the separate attr. A missing byte order means host order, again like in the YAML specs. Link: https://lore.kernel.org/ab90f970-0ebb-4c07-b7b1-db3f91395116@redhat.com Link: https://patch.msgid.link/20260912202401.141336-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/nlctrl.yaml | 15 +++++++++++++++ include/uapi/linux/netlink.h | 14 ++++++++++++++ net/netlink/policy.c | 16 ++++++++++++++-- tools/net/ynl/Makefile.deps | 3 ++- tools/net/ynl/pyynl/lib/ynl.py | 8 +++++++- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/nlctrl.yaml b/Documentation/netlink/specs/nlctrl.yaml index 8b4472a6aa36..7e7c158e3e73 100644 --- a/Documentation/netlink/specs/nlctrl.yaml +++ b/Documentation/netlink/specs/nlctrl.yaml @@ -42,6 +42,16 @@ definitions: - bitfield32 - sint - uint + - + name: policy-byte-order + doc: | + Byte order of an integer attribute. Zero is left unused so that it + can be taken to mean host byte order. + enum-name: netlink-policy-byte-order + type: enum + value-start: 1 + entries: + - big-endian attribute-sets: - @@ -152,6 +162,11 @@ attribute-sets: - name: pad type: pad + - + name: byte-order + doc: Byte order of the attribute, absent means host byte order. + type: u32 + enum: policy-byte-order - name: op-policy-attrs name-prefix: ctrl-attr-policy- diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h index f87aaf28a649..82c41aeb4357 100644 --- a/include/uapi/linux/netlink.h +++ b/include/uapi/linux/netlink.h @@ -329,6 +329,17 @@ enum netlink_attribute_type { NL_ATTR_TYPE_UINT, }; +/** + * enum netlink_policy_byte_order - byte order of an integer attribute + * @NL_POLICY_BYTE_ORDER_BIG_ENDIAN: big endian (network byte order) + * + * Zero is left unassigned so that it keeps meaning host byte order, + * which is also what a missing byte order means. + */ +enum netlink_policy_byte_order { + NL_POLICY_BYTE_ORDER_BIG_ENDIAN = 1, +}; + /** * enum netlink_policy_type_attr - policy type attributes * @NL_POLICY_TYPE_ATTR_UNSPEC: unused @@ -356,6 +367,8 @@ enum netlink_attribute_type { * bitfield32 type (U32) * @NL_POLICY_TYPE_ATTR_MASK: mask of valid bits for unsigned integers (U64) * @NL_POLICY_TYPE_ATTR_PAD: pad attribute for 64-bit alignment + * @NL_POLICY_TYPE_ATTR_BYTE_ORDER: byte order of an integer attribute, + * &enum netlink_policy_byte_order, absent if host byte order (U32) * * @__NL_POLICY_TYPE_ATTR_MAX: number of attributes * @NL_POLICY_TYPE_ATTR_MAX: highest attribute number @@ -374,6 +387,7 @@ enum netlink_policy_type_attr { NL_POLICY_TYPE_ATTR_BITFIELD32_MASK, NL_POLICY_TYPE_ATTR_PAD, NL_POLICY_TYPE_ATTR_MASK, + NL_POLICY_TYPE_ATTR_BYTE_ORDER, /* keep last */ __NL_POLICY_TYPE_ATTR_MAX, diff --git a/net/netlink/policy.c b/net/netlink/policy.c index 08b006c48f06..574d44b7d518 100644 --- a/net/netlink/policy.c +++ b/net/netlink/policy.c @@ -234,6 +234,11 @@ int netlink_policy_dump_attr_size_estimate(const struct nla_policy *pt) /* maximum is common, u64 min/max with padding */ return common + 2 * (nla_attr_size(0) + nla_attr_size(sizeof(u64))); + case NLA_BE16: + case NLA_BE32: + /* same as the unsigned types, plus the byte order */ + return common + nla_attr_size(sizeof(u32)) + + 2 * (nla_attr_size(0) + nla_attr_size(sizeof(u64))); case NLA_BITFIELD32: return common + nla_attr_size(sizeof(u32)); case NLA_STRING: @@ -289,21 +294,28 @@ __netlink_policy_dump_write_attr(struct netlink_policy_dump_state *state, case NLA_U16: case NLA_U32: case NLA_U64: + case NLA_BE16: + case NLA_BE32: case NLA_UINT: case NLA_MSECS: { struct netlink_range_validation range; if (pt->type == NLA_U8) type = NL_ATTR_TYPE_U8; - else if (pt->type == NLA_U16) + else if (pt->type == NLA_U16 || pt->type == NLA_BE16) type = NL_ATTR_TYPE_U16; - else if (pt->type == NLA_U32) + else if (pt->type == NLA_U32 || pt->type == NLA_BE32) type = NL_ATTR_TYPE_U32; else if (pt->type == NLA_U64) type = NL_ATTR_TYPE_U64; else type = NL_ATTR_TYPE_UINT; + if ((pt->type == NLA_BE16 || pt->type == NLA_BE32) && + nla_put_u32(skb, NL_POLICY_TYPE_ATTR_BYTE_ORDER, + NL_POLICY_BYTE_ORDER_BIG_ENDIAN)) + goto nla_put_failure; + if (pt->validation_type == NLA_VALIDATE_MASK) { if (nla_put_u64_64bit(skb, NL_POLICY_TYPE_ATTR_MASK, pt->mask, diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps index 2771375339d9..1e746e25e2bc 100644 --- a/tools/net/ynl/Makefile.deps +++ b/tools/net/ynl/Makefile.deps @@ -30,7 +30,8 @@ CFLAGS_mptcp_pm:=$(call get_hdr_inc,_LINUX_MPTCP_PM_H,mptcp_pm.h) CFLAGS_net_shaper:=$(call get_hdr_inc,_LINUX_NET_SHAPER_H,net_shaper.h) CFLAGS_netdev:=$(call get_hdr_inc,_LINUX_NETDEV_H,netdev.h) CFLAGS_nl80211:=$(call get_hdr_inc,__LINUX_NL802121_H,nl80211.h) -CFLAGS_nlctrl:=$(call get_hdr_inc,__LINUX_GENERIC_NETLINK_H,genetlink.h) +CFLAGS_nlctrl:=$(call get_hdr_inc,__LINUX_GENERIC_NETLINK_H,genetlink.h) \ + $(call get_hdr_inc,__LINUX_NETLINK_H,netlink.h) CFLAGS_nfsd:=$(call get_hdr_inc,_LINUX_NFSD_NETLINK_H,nfsd_netlink.h) CFLAGS_ovpn:=$(call get_hdr_inc,_LINUX_OVPN_H,ovpn.h) CFLAGS_ovs_datapath:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h) diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py index 8682bf588e1f..fb5acb8acded 100644 --- a/tools/net/ynl/pyynl/lib/ynl.py +++ b/tools/net/ynl/pyynl/lib/ynl.py @@ -115,6 +115,7 @@ class Netlink: NL_POLICY_TYPE_ATTR_BITFIELD32_MASK = 10 NL_POLICY_TYPE_ATTR_PAD = 11 NL_POLICY_TYPE_ATTR_MASK = 12 + NL_POLICY_TYPE_ATTR_BYTE_ORDER = 13 AttrType = Enum('AttrType', ['flag', 'u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', @@ -122,6 +123,8 @@ class Netlink: 'nested', 'nested-array', 'bitfield32', 'sint', 'uint']) + ByteOrder = Enum('ByteOrder', ['big-endian'], start=1) + class NlError(Exception): def __init__(self, nl_msg): self.nl_msg = nl_msg @@ -158,7 +161,7 @@ class NlPolicy: Each policy entry always has a 'type' attribute (e.g. u32, string, nested). Optional attributes depending on the 'type': min-value, - max-value, min-length, max-length, mask. + max-value, min-length, max-length, mask, byte-order. Policies can form infinite nesting loops. These loops are trimmed when policy is converted to a dict with pol.to_dict(). @@ -454,6 +457,9 @@ def _genl_decode_policy(raw): policy['bitfield32-mask'] = attr.as_scalar('u32') elif attr.type == Netlink.NL_POLICY_TYPE_ATTR_MASK: policy['mask'] = attr.as_scalar('u64') + elif attr.type == Netlink.NL_POLICY_TYPE_ATTR_BYTE_ORDER: + byte_order = attr.as_scalar('u32') + policy['byte-order'] = Netlink.ByteOrder(byte_order).name return policy From 3d989d1f40a0b286342fab34ed791854c918d06b Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Fri, 11 Sep 2026 17:45:27 +0800 Subject: [PATCH 0514/2126] net: phy: realtek: improve firmware write speed Firmware execution routine unconditionally uses phy_modify_mmd() for all OP_WRITE entries which introduces an unnecessary read transaction when updating an entire 16-bit register. So we optimize this by checking bitmask boundaries. Use phy_write_mmd() directly to speed up firmware loading process. Benchmark number from tracing MDC/MDIO hardware transactions during firmware loading process: - Unpatched: about 28,000 MDIO transactions - Patched: about 9,600 MDIO transactions This results in an approx 65% reduction in MDIO traffic. Signed-off-by: Javen Xu Reviewed-by: Nicolai Buchwitz Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260911094527.1928-1-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/phy/realtek/realtek_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 27e31a799e2c..97b0b67b9900 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -548,8 +548,12 @@ static int rtl8261x_fw_execute_entry(struct phy_device *phydev, switch (entry->type) { case OP_WRITE: - ret = phy_modify_mmd(phydev, dev, addr, - GENMASK(msb, lsb), (value << lsb) & GENMASK(msb, lsb)); + if (msb != 15 || lsb != 0) + ret = phy_modify_mmd(phydev, dev, addr, GENMASK(msb, lsb), + (value << lsb) & GENMASK(msb, lsb)); + else + ret = phy_write_mmd(phydev, dev, addr, value); + if (ret) return ret; break; From 30da1c2a41507ec9265440c1f223d1d6c1bc5244 Mon Sep 17 00:00:00 2001 From: Myeonghun Pak Date: Sun, 13 Sep 2026 16:41:04 -0400 Subject: [PATCH 0515/2126] net: 8390: pcnet_cs: release PCMCIA window on setup_shmem_window() error setup_shmem_window() acquires a PCMCIA memory window using pcmcia_request_window(). If pcmcia_map_mem_page() or the subsequent ioremap() fails, the function returns without releasing the requested window. pcnet_config() treats shared-memory setup failure as non-fatal and falls back to setup_dma_config(). Probe can therefore continue while socket window 3 and its reserved iomem range remain unnecessarily held for the rest of the bound lifetime of the device. pcmcia_disable_device() eventually releases the window during teardown. Route error paths after a successful request through a new release label that calls pcmcia_release_window(). Fold the existing buffer-verification cleanup into the same path, keeping iounmap() before the window release when a mapping exists. Leave the request failure path unchanged. This issue was identified during our ongoing static-analysis research while reviewing kernel code. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Co-developed-by: Ijae Kim Signed-off-by: Ijae Kim Signed-off-by: Myeonghun Pak Reviewed-by: Simon Horman Reviewed-by: Jacob Keller Link: https://patch.msgid.link/20260913204104.53408-1-mhun512@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/8390/pcnet_cs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/8390/pcnet_cs.c b/drivers/net/ethernet/8390/pcnet_cs.c index 19f9c5db3f3b..0cf3c0f3ced7 100644 --- a/drivers/net/ethernet/8390/pcnet_cs.c +++ b/drivers/net/ethernet/8390/pcnet_cs.c @@ -1434,14 +1434,14 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg, offset -= offset % window_size; ret = pcmcia_map_mem_page(link, link->resource[3], offset); if (ret) - goto failed; + goto release; /* Try scribbling on the buffer */ info->base = ioremap(link->resource[3]->start, resource_size(link->resource[3])); if (unlikely(!info->base)) { ret = -ENOMEM; - goto failed; + goto release; } for (i = 0; i < (TX_PAGES<<8); i += 2) @@ -1452,9 +1452,8 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg, pcnet_reset_8390(dev); if (i != (TX_PAGES<<8)) { iounmap(info->base); - pcmcia_release_window(link, link->resource[3]); info->base = NULL; - goto failed; + goto release; } ei_status.mem = info->base + offset; @@ -1475,6 +1474,8 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg, info->flags |= USE_SHMEM; return 0; +release: + pcmcia_release_window(link, link->resource[3]); failed: return 1; } From d328b5ad4a521807edee1920a3c0ca04020d6230 Mon Sep 17 00:00:00 2001 From: Myeonghun Pak Date: Sun, 13 Sep 2026 16:45:34 -0400 Subject: [PATCH 0516/2126] net/qla3xxx: disable the PCI device on remove ql3xxx_probe() enables the PCI device and balances that reference on probe failure. However, ql3xxx_remove() releases the mappings and PCI regions without disabling the device, leaving the enable reference held after unbind. Add pci_disable_device() at the end of ql3xxx_remove() to balance the successful probe's pci_enable_device() call. Keep the existing manual cleanup and probe error handling unchanged. This issue was identified during our ongoing static-analysis research while reviewing kernel code. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Co-developed-by: Ijae Kim Signed-off-by: Ijae Kim Signed-off-by: Myeonghun Pak Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260913204534.53825-1-mhun512@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qlogic/qla3xxx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c b/drivers/net/ethernet/qlogic/qla3xxx.c index 861a13ad7e1a..776840f60d01 100644 --- a/drivers/net/ethernet/qlogic/qla3xxx.c +++ b/drivers/net/ethernet/qlogic/qla3xxx.c @@ -3916,6 +3916,7 @@ static void ql3xxx_remove(struct pci_dev *pdev) iounmap(qdev->mem_map_registers); pci_release_regions(pdev); free_netdev(ndev); + pci_disable_device(pdev); } static struct pci_driver ql3xxx_driver = { From 4e8b65ecb64ca94963057df764c12c4aeddb6bca Mon Sep 17 00:00:00 2001 From: Manish Awasthi Date: Thu, 10 Sep 2026 01:44:27 +0000 Subject: [PATCH 0517/2126] net: mana: Use the HWC destination queues reported by the hardware The hardware provides valid HWC destination vRQ and vRCQ IDs for all PFs and VFs. Use these IDs unconditionally in mana_hwc_send_request(), as the PF-specific gate is not required. Signed-off-by: Manish Awasthi Reviewed-by: Long Li Reviewed-by: Haiyang Zhang Link: https://patch.msgid.link/20260910014427.54272-1-mawasthi@linux.microsoft.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/microsoft/mana/hw_channel.c | 24 ++++++++++--------- include/net/mana/hw_channel.h | 8 +++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c index 263e7c4e2934..3bca4b683134 100644 --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c @@ -170,12 +170,12 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self, hwc->txq->msg_buf->gpa_mkey = val; break; - case HWC_INIT_DATA_PF_DEST_RQ_ID: - hwc->pf_dest_vrq_id = val; + case HWC_INIT_DATA_DEST_RQ_ID: + hwc->dest_vrq_id = val; break; - case HWC_INIT_DATA_PF_DEST_CQ_ID: - hwc->pf_dest_vrcq_id = val; + case HWC_INIT_DATA_DEST_CQ_ID: + hwc->dest_vrcq_id = val; break; } @@ -855,13 +855,12 @@ void mana_hwc_destroy_channel(struct gdma_context *gc) int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, const void *req, u32 resp_len, void *resp) { - struct gdma_context *gc = hwc->gdma_dev->gdma_context; struct hwc_work_request *tx_wr; struct hwc_wq *txq = hwc->txq; struct gdma_req_hdr *req_msg; struct hwc_caller_ctx *ctx; - u32 dest_vrcq = 0; - u32 dest_vrq = 0; + u32 dest_vrcq; + u32 dest_vrq; u32 command; u16 msg_id; int err; @@ -890,10 +889,13 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, tx_wr->msg_size = req_len; command = req_msg->req.msg_type; - if (gc->is_pf) { - dest_vrq = hwc->pf_dest_vrq_id; - dest_vrcq = hwc->pf_dest_vrcq_id; - } + /* The hardware reports the HWC destination queues through + * HWC_INIT_DATA_DEST_RQ_ID and HWC_INIT_DATA_DEST_CQ_ID, and + * always supplies values that are valid for this function, so no + * PF-specific handling is needed here. + */ + dest_vrq = hwc->dest_vrq_id; + dest_vrcq = hwc->dest_vrcq_id; err = mana_hwc_post_tx_wqe(txq, tx_wr, dest_vrq, dest_vrcq, false); if (err) { diff --git a/include/net/mana/hw_channel.h b/include/net/mana/hw_channel.h index 16feb39616c1..1ab2d66c891e 100644 --- a/include/net/mana/hw_channel.h +++ b/include/net/mana/hw_channel.h @@ -20,8 +20,8 @@ #define HWC_INIT_DATA_MAX_NUM_CQS 7 #define HWC_INIT_DATA_PDID 8 #define HWC_INIT_DATA_GPA_MKEY 9 -#define HWC_INIT_DATA_PF_DEST_RQ_ID 10 -#define HWC_INIT_DATA_PF_DEST_CQ_ID 11 +#define HWC_INIT_DATA_DEST_RQ_ID 10 +#define HWC_INIT_DATA_DEST_CQ_ID 11 #define HWC_DATA_CFG_HWC_TIMEOUT 1 #define HWC_DATA_HW_LINK_CONNECT 2 @@ -195,8 +195,8 @@ struct hw_channel_context { struct semaphore sema; struct gdma_resource inflight_msg_res; - u32 pf_dest_vrq_id; - u32 pf_dest_vrcq_id; + u32 dest_vrq_id; + u32 dest_vrcq_id; u32 hwc_timeout; struct hwc_caller_ctx *caller_ctx; From fbcd35eb1871fb7df3a5dbb0ffa05f15b83207a0 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:04:21 -0700 Subject: [PATCH 0518/2126] selftests: drv-net: psp: fix linter issues Fix ruff 0.16 warnings: C403 Unnecessary list comprehension (rewrite as a set comprehension) Reviewed-by: Daniel Zahka Link: https://patch.msgid.link/20260912200426.121025-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/psp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index 315648a770d0..5e87fb50c348 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -525,11 +525,11 @@ def data_stale_key(cfg): def __nsim_psp_rereg(cfg): # The PSP dev ID will change, remember what was there before - before = set([x['id'] for x in cfg.pspnl.dev_get({}, dump=True)]) + before = {x['id'] for x in cfg.pspnl.dev_get({}, dump=True)} cfg._ns.nsims[0].dfs_write('psp_rereg', '1') - after = set([x['id'] for x in cfg.pspnl.dev_get({}, dump=True)]) + after = {x['id'] for x in cfg.pspnl.dev_get({}, dump=True)} new_devs = list(after - before) ksft_eq(len(new_devs), 1) From cf3302111b1a5c2b56127579ca51bdd20c70c0fe Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:04:22 -0700 Subject: [PATCH 0519/2126] psp: don't report the main netdevice's ifindex to associated namespaces PSP device is visible in a netns if any of the devices (eg. netkit) are associated with that PSP device. In the main netns we show all the associated netdevs + their netns id. In the "container" netns we show only the local devices. But we were listing the main netdev in all cases, even though it's meaningless outside of the main netns. Report ifindex only in the main netdevice's namespace. Absence is already unambiguous, the by-association flag is set exactly in the messages which no longer carry the ifindex. Reviewed-by: Daniel Zahka Link: https://patch.msgid.link/20260912200426.121025-3-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/psp.yaml | 2 ++ net/psp/psp_nl.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml index e9c2ee7e28e0..f3266763c325 100644 --- a/Documentation/netlink/specs/psp.yaml +++ b/Documentation/netlink/specs/psp.yaml @@ -38,6 +38,8 @@ attribute-sets: doc: | ifindex of the main netdevice linked to the PSP device, or the ifindex to associate with the PSP device. + Only reported to the network namespace the main netdevice + lives in, an ifindex has no meaning outside of it. type: u32 - name: psp-versions-cap diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c index f91665748dde..b57366b5e032 100644 --- a/net/psp/psp_nl.c +++ b/net/psp/psp_nl.c @@ -294,13 +294,16 @@ psp_nl_dev_fill(struct psp_dev *psd, struct sk_buff *rsp, return -EMSGSIZE; if (nla_put_u32(rsp, PSP_A_DEV_ID, psd->id) || - nla_put_u32(rsp, PSP_A_DEV_IFINDEX, psd->main_netdev->ifindex) || nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_CAP, psd->caps->versions) || nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_ENA, psd->config.versions)) goto err_cancel_msg; if (cur_net == dev_net(psd->main_netdev)) { - /* Primary device - dump assoc list */ + /* Primary device - report the netdev, dump assoc list. */ + if (nla_put_u32(rsp, PSP_A_DEV_IFINDEX, + psd->main_netdev->ifindex)) + goto err_cancel_msg; + err = psp_nl_fill_assoc_dev_list(psd, rsp, cur_net, NULL); if (err) goto err_cancel_msg; From 4d5d9f3a19682450858ff93ba3beaae65784ee3d Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:04:23 -0700 Subject: [PATCH 0520/2126] selftests: drv-net: psp: check the ifindex an associated netns sees dev-get must not report the ifindex outside of the main netns. The dev-get checks for an associated namespace are already there, add the "no main ifindex" assertion. Reviewed-by: Daniel Zahka Link: https://patch.msgid.link/20260912200426.121025-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/psp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index 5e87fb50c348..43780efb84ed 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -749,6 +749,10 @@ def _psp_dev_get_check_netkit_psp_assoc(cfg): ksft_not_none(peer_dev, "No PSP device found with by-association flag in guest netns") + # ifindex of the main netdevice means nothing in this namespace + ksft_true('ifindex' not in peer_dev, + "ifindex reported to an associated namespace") + # Verify assoc-list contains the nk_guest device ksft_true('assoc-list' in peer_dev and len(peer_dev['assoc-list']) > 0, "Guest device should have assoc-list with local devices") From fb3ddbe2b5774f97a428bfb26711d68b966fcd0a Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:04:24 -0700 Subject: [PATCH 0521/2126] psp: notify about a disassociation once it has happened The dev-change-ntf generated by dev-disassoc was built before the association was unlinked, so the assoc-list it carried still contained the device which was going away, and nothing corrected it afterwards. We don't really expect associations to change during a lifetime of a netns but this is still wrong. Netlink listeners need to be able to tell the current "state of the world" based on notifications. The notification had to be sent early because psp_nl_multicast_per_ns() derives the set of namespaces to notify from the association list, so a namespace losing its last associated device becomes unreachable once the entry is gone. In that case - get the netns from the netdev itself, and send that namespace a dev-del-ntf. If the netns had multiple associated netdevs and only one disassoc'd we'll still send a change notification, just with a correct list. Reviewed-by: Daniel Zahka Link: https://patch.msgid.link/20260912200426.121025-5-kuba@kernel.org Signed-off-by: Jakub Kicinski --- net/psp/psp.h | 1 + net/psp/psp_main.c | 16 +++++++++++----- net/psp/psp_nl.c | 44 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/net/psp/psp.h b/net/psp/psp.h index bbb39e2f5b0a..b123c2427905 100644 --- a/net/psp/psp.h +++ b/net/psp/psp.h @@ -19,6 +19,7 @@ bool psp_has_assoc_dev_in_ns(struct psp_dev *psd, struct net *net); int psp_attach_netdev_notifier(void); void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd); +void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net); struct psp_assoc *psp_assoc_create(struct psp_dev *psd); struct psp_dev *psp_dev_get_for_sock(struct sock *sk); diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c index 91473f96ad21..273b010d2355 100644 --- a/net/psp/psp_main.c +++ b/net/psp/psp_main.c @@ -408,7 +408,7 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv) } EXPORT_SYMBOL(psp_dev_rcv); -static void psp_dev_disassoc_one(struct psp_dev *psd, struct net_device *dev) +static bool psp_dev_disassoc_one(struct psp_dev *psd, struct net_device *dev) { struct psp_assoc_dev *entry; @@ -419,9 +419,11 @@ static void psp_dev_disassoc_one(struct psp_dev *psd, struct net_device *dev) rcu_assign_pointer(entry->assoc_dev->psp_dev, NULL); netdev_put(entry->assoc_dev, &entry->dev_tracker); kfree(entry); - return; + return true; } } + + return false; } static int psp_netdev_event(struct notifier_block *nb, unsigned long event, @@ -438,9 +440,13 @@ static int psp_netdev_event(struct notifier_block *nb, unsigned long event, if (psd && psp_dev_tryget(psd)) { rcu_read_unlock(); mutex_lock(&psd->lock); - if (psp_dev_is_registered(psd)) - psp_nl_notify_dev(psd, PSP_CMD_DEV_CHANGE_NTF); - psp_dev_disassoc_one(psd, dev); + /* Nothing to report if the device was never on the list, + * dev-assoc may have failed after publishing dev->psp_dev, + * and this is also the main netdevice's path. + */ + if (psp_dev_disassoc_one(psd, dev) && + psp_dev_is_registered(psd)) + psp_nl_notify_disassoc(psd, dev_net(dev)); mutex_unlock(&psd->lock); psp_dev_put(psd); } else { diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c index b57366b5e032..cdfc2d72fb39 100644 --- a/net/psp/psp_nl.c +++ b/net/psp/psp_nl.c @@ -356,6 +356,40 @@ void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd) psp_nl_build_dev_ntf, &cmd); } +/** + * psp_nl_notify_disassoc() - notify about a device losing an association + * @psd: PSP device (must be locked) + * @net: netns of the netdevice which got disassociated + * + * Must be called once @psd no longer has the association, so that the + * notifications carry the state after the change. + */ +void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net) +{ + struct sk_buff *ntf; + bool still_visible; + u32 cmd; + + lockdep_assert_held(&psd->lock); + + psp_nl_notify_dev(psd, PSP_CMD_DEV_CHANGE_NTF); + + /* psp_nl_notify_dev() reaches the main netdevice's netns and every + * netns which still has an associated device. If @net is neither, + * the device is gone from @net and we should send a delete ntf. + */ + still_visible = !psp_dev_check_access(psd, net, false); + if (still_visible || !maybe_get_net(net)) + return; + + cmd = PSP_CMD_DEV_DEL_NTF; + ntf = psp_nl_build_dev_ntf(psd, net, &cmd); + if (ntf) + genlmsg_multicast_netns(&psp_nl_family, net, ntf, 0, + PSP_NLGRP_MGMT, GFP_KERNEL); + put_net(net); +} + int psp_nl_dev_get_doit(struct sk_buff *req, struct genl_info *info) { struct psp_dev *psd = info->user_ptr[0]; @@ -620,13 +654,6 @@ int psp_nl_dev_disassoc_doit(struct sk_buff *skb, struct genl_info *info) return -ENOMEM; } - put_net(net); - - /* Notify before removal so listeners in the disassociated namespace - * still receive the notification. - */ - psp_nl_notify_dev(psd, PSP_CMD_DEV_CHANGE_NTF); - /* Remove from the association list */ list_del(&found->dev_list); psd->assoc_dev_cnt--; @@ -634,6 +661,9 @@ int psp_nl_dev_disassoc_doit(struct sk_buff *skb, struct genl_info *info) netdev_put(found->assoc_dev, &found->dev_tracker); kfree(found); + psp_nl_notify_disassoc(psd, net); + put_net(net); + return psp_nl_reply_send(rsp, info); } From b711865f68ce1cd5e832f7859260e9db73d2ed7c Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:04:25 -0700 Subject: [PATCH 0522/2126] selftests: drv-net: psp: factor out creating a netkit in the test netns The netkit removal test builds a disposable netkit pair and moves its peer into the test namespace. The next commit needs a second associated device there, so move that to a helper. No functional change, other than looking the new peer up among all netkit devices rather than the two the environment created, which is what makes it reusable. Reviewed-by: Daniel Zahka Link: https://patch.msgid.link/20260912200426.121025-6-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/psp.py | 60 ++++++++++++---------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index 43780efb84ed..d44d2c83473e 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -798,25 +798,18 @@ def _dev_assoc_no_nsid(cfg): ksft_true(not found, "Device should not be in assoc-list after disassociation") -def _psp_dev_assoc_cleanup_on_netkit_del(cfg): - """Test that assoc-list is cleared when associated netkit is deleted. +def _add_netkit_guest(cfg, host_name, guest_name): + """Create a netkit pair and move its peer into the test namespace. - Creates a disposable netkit pair for this test to avoid destroying - the shared environment. + Returns the peer's ifindex there and the defer() deleting the pair. """ - _init_psp_dev(cfg, True) - defer(delattr, cfg, 'psp_dev_id') - defer(delattr, cfg, 'psp_info') + existing = {link['ifindex'] for link in ip("-d link show", json=True) + if link.get('linkinfo', {}).get('info_kind') == 'netkit'} - existing = {cfg.nk_host_ifindex, cfg.nk_guest_ifindex} - - # Create a temporary netkit pair - tmp_host_name = "tmp_nk_host" - tmp_guest_name = "tmp_nk_guest" rtnl = RtnlFamily() rtnl.newlink( { - "ifname": tmp_host_name, + "ifname": host_name, "linkinfo": { "kind": "netkit", "data": { @@ -828,25 +821,38 @@ def _psp_dev_assoc_cleanup_on_netkit_del(cfg): }, flags=[Netlink.NLM_F_CREATE, Netlink.NLM_F_EXCL], ) - cleanup_netkit = defer(ip, f"link del {tmp_host_name}") + cleanup = defer(ip, f"link del {host_name}") # Find the peer by diffing against existing netkit ifindexes all_links = ip("-d link show", json=True) - tmp_peer = [link for link in all_links - if link.get('linkinfo', {}).get('info_kind') == 'netkit' - and link['ifindex'] not in existing - and link['ifname'] != tmp_host_name] - ksft_eq(len(tmp_peer), 1, - "Failed to find temporary netkit peer") - guest_name = tmp_peer[0]['ifname'] + peer = [link for link in all_links + if link.get('linkinfo', {}).get('info_kind') == 'netkit' + and link['ifindex'] not in existing + and link['ifname'] != host_name] + ksft_eq(len(peer), 1, "Failed to find the new netkit peer") # Rename and move guest end into the test namespace - ip(f"link set dev {guest_name} name {tmp_guest_name}") - ip(f"link set dev {tmp_guest_name} netns {cfg.netns.name}") - tmp_guest_dev = ip(f"link show dev {tmp_guest_name}", - json=True, ns=cfg.netns)[0] - tmp_guest_ifindex = tmp_guest_dev['ifindex'] - ip(f"link set dev {tmp_guest_name} up", ns=cfg.netns) + ip(f"link set dev {peer[0]['ifname']} name {guest_name}") + ip(f"link set dev {guest_name} netns {cfg.netns.name}") + guest_dev = ip(f"link show dev {guest_name}", json=True, ns=cfg.netns)[0] + ip(f"link set dev {guest_name} up", ns=cfg.netns) + + return guest_dev['ifindex'], cleanup + + +def _psp_dev_assoc_cleanup_on_netkit_del(cfg): + """Test that assoc-list is cleared when associated netkit is deleted. + + Creates a disposable netkit pair for this test to avoid destroying + the shared environment. + """ + _init_psp_dev(cfg, True) + defer(delattr, cfg, 'psp_dev_id') + defer(delattr, cfg, 'psp_info') + + tmp_host_name = "tmp_nk_host" + tmp_guest_ifindex, cleanup_netkit = _add_netkit_guest(cfg, tmp_host_name, + "tmp_nk_guest") # Associate PSP device with the temporary guest interface cfg.pspnl.dev_assoc({'id': cfg.psp_dev_id, From 4d3c1d963c6fd104bf408ea66c52a939d93697bd Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Sat, 12 Sep 2026 13:04:26 -0700 Subject: [PATCH 0523/2126] selftests: drv-net: psp: check the PSP disassociation notifications The main namespace must see a change which no longer lists the device, and the namespace which lost its last association must see the device go away. Check that on both paths which generate the notifications, dev-disassoc and netdevice removal, and check that a namespace which still has another association is only told about the change. Reviewed-by: Daniel Zahka Link: https://patch.msgid.link/20260912200426.121025-7-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/psp.py | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index d44d2c83473e..13ff5188cca3 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -723,6 +723,111 @@ def _dev_change_notify_multi_ns_netkit(cfg): f" in {label} namespace") +def _subscribe_mgmt(cfg): + """Listen on the mgmt group in the guest and in the main namespace.""" + # Listener in the guest namespace; socket stays bound to that ns + with NetNSEnter(cfg.netns.name): + peer_pspnl = PSPFamily() + peer_pspnl.ntf_subscribe('mgmt') + + main_pspnl = PSPFamily() + main_pspnl.ntf_subscribe('mgmt') + + return main_pspnl, peer_pspnl + + +def _get_dev_ntf(cfg, pspnl, label): + """Wait for the next notification about the PSP device under test.""" + for ntf in pspnl.poll_ntf(duration=10): + if ntf['msg'].get('id') == cfg.psp_dev_id: + return ntf + raise KsftFailEx(f"No notification received in the {label} namespace") + + +def _check_disassoc_ntf(cfg, main_pspnl, peer_pspnl, ifindex): + """Check the notifications for a netns losing its last association.""" + ntf = _get_dev_ntf(cfg, main_pspnl, "main") + ksft_eq(ntf['name'], 'dev-change-ntf') + for assoc in ntf['msg'].get('assoc-list', []): + if assoc['nsid'] != cfg.psp_dev_peer_nsid: + continue + ksft_ne(assoc['ifindex'], ifindex, + "Disassociated device still listed in the notification") + + # The device is gone as far as the disassociated namespace is concerned + ntf = _get_dev_ntf(cfg, peer_pspnl, "guest") + ksft_eq(ntf['name'], 'dev-del-ntf') + ksft_true('ifindex' not in ntf['msg'], + "ifindex reported to an associated namespace") + + +def _dev_disassoc_notify_multi_ns_netkit(cfg): + """ Test the notifications dev-disassoc generates in both namespaces """ + _init_psp_dev(cfg, True) + defer(delattr, cfg, 'psp_dev_id') + defer(delattr, cfg, 'psp_info') + + cfg.pspnl.dev_assoc({'id': cfg.psp_dev_id, + 'ifindex': cfg.nk_guest_ifindex, + 'nsid': cfg.psp_dev_peer_nsid}) + defer(_try_disassoc, cfg, cfg.psp_dev_id, cfg.nk_guest_ifindex, + cfg.psp_dev_peer_nsid) + + main_pspnl, peer_pspnl = _subscribe_mgmt(cfg) + + cfg.pspnl.dev_disassoc({'id': cfg.psp_dev_id, + 'ifindex': cfg.nk_guest_ifindex, + 'nsid': cfg.psp_dev_peer_nsid}) + + _check_disassoc_ntf(cfg, main_pspnl, peer_pspnl, cfg.nk_guest_ifindex) + + +def _dev_disassoc_notify_one_of_two_netkit(cfg): + """Test the notifications with two netkits associated in one netns. + + Disassociating the first netkit leaves the PSP device visible in the + guest namespace, generates a dev-change-ntf. + Disassociating the second one takes the device out of its view, + generates 'dev-del-ntf'. + """ + _init_psp_dev(cfg, True) + defer(delattr, cfg, 'psp_dev_id') + defer(delattr, cfg, 'psp_info') + + tmp_ifindex, _ = _add_netkit_guest(cfg, "tmp_nk_host", "tmp_nk_guest") + + for ifindex in [cfg.nk_guest_ifindex, tmp_ifindex]: + cfg.pspnl.dev_assoc({'id': cfg.psp_dev_id, 'ifindex': ifindex, + 'nsid': cfg.psp_dev_peer_nsid}) + defer(_try_disassoc, cfg, cfg.psp_dev_id, ifindex, + cfg.psp_dev_peer_nsid) + + main_pspnl, peer_pspnl = _subscribe_mgmt(cfg) + + # One of the two goes away, the device stays visible in the guest netns + cfg.pspnl.dev_disassoc({'id': cfg.psp_dev_id, 'ifindex': tmp_ifindex, + 'nsid': cfg.psp_dev_peer_nsid}) + + ntf = _get_dev_ntf(cfg, main_pspnl, "main") + ksft_eq(ntf['name'], 'dev-change-ntf') + + ntf = _get_dev_ntf(cfg, peer_pspnl, "guest") + ksft_eq(ntf['name'], 'dev-change-ntf') + found = False + for assoc in ntf['msg'].get('assoc-list', []): + ksft_ne(assoc['ifindex'], tmp_ifindex, + "Disassociated device still listed in the notification") + found |= assoc['ifindex'] == cfg.nk_guest_ifindex + ksft_true(found, "Remaining association missing from the notification") + + # And now the last one, the device disappears from the guest netns + cfg.pspnl.dev_disassoc({'id': cfg.psp_dev_id, + 'ifindex': cfg.nk_guest_ifindex, + 'nsid': cfg.psp_dev_peer_nsid}) + + _check_disassoc_ntf(cfg, main_pspnl, peer_pspnl, cfg.nk_guest_ifindex) + + def _psp_dev_get_check_netkit_psp_assoc(cfg): """ Check psp dev-get output with netkit interface associated with PSP dev """ _assoc_nk_guest(cfg) @@ -863,6 +968,9 @@ def _psp_dev_assoc_cleanup_on_netkit_del(cfg): _check_assoc_list(cfg, cfg.psp_dev_id, tmp_guest_ifindex, cfg.psp_dev_peer_nsid) + # Removing the netdevice is notified like a disassociation + main_pspnl, peer_pspnl = _subscribe_mgmt(cfg) + # Delete the temporary netkit pair (deleting one end removes both) ip(f"link del {tmp_host_name}") cleanup_netkit.cancel() @@ -873,6 +981,8 @@ def _psp_dev_assoc_cleanup_on_netkit_del(cfg): or len(dev_info['assoc-list']) == 0, "assoc-list should be empty after netkit deletion") + _check_disassoc_ntf(cfg, main_pspnl, peer_pspnl, tmp_guest_ifindex) + def _try_disassoc(cfg, psp_dev_id, ifindex, nsid=None): """Best-effort disassociate, ignoring errors if already removed.""" @@ -991,6 +1101,8 @@ def main() -> None: data_basic_send_netkit_psp_assoc, _key_rotation_notify_multi_ns_netkit, _dev_change_notify_multi_ns_netkit, + _dev_disassoc_notify_multi_ns_netkit, + _dev_disassoc_notify_one_of_two_netkit, _psp_dev_get_check_netkit_psp_assoc, _dev_assoc_no_nsid, _psp_dev_assoc_cleanup_on_netkit_del, From 87b80c2f6b05cad9f0ff9136709c62a0f59923e3 Mon Sep 17 00:00:00 2001 From: Myeonghun Pak Date: Fri, 11 Sep 2026 11:53:18 -0400 Subject: [PATCH 0524/2126] net: txgbe: free the fixed-rate clock on cleanup The fixed-rate clock is registered with clk_register_fixed_rate(), but its error and removal paths use clk_unregister(). That unregisters the clock without freeing the fixed-rate provider allocation. Use clk_unregister_fixed_rate() on lookup creation failure, later PHY initialization failure and removal to release the provider allocation as well. Keep the existing clock registration and lookup cleanup ordering. This issue was identified during our ongoing static-analysis research while reviewing kernel code. Cc: stable+noautosel@kernel.org # untested fix to a driver init path Co-developed-by: Ijae Kim Signed-off-by: Ijae Kim Signed-off-by: Myeonghun Pak Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260911155318.88857-1-mhun512@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c index dc9f24314658..c81d485221d5 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c @@ -434,7 +434,7 @@ static int txgbe_clock_register(struct txgbe *txgbe) clock = clkdev_create(clk, NULL, "%s", clk_name); if (!clock) { - clk_unregister(clk); + clk_unregister_fixed_rate(clk); return -ENOMEM; } @@ -637,7 +637,7 @@ err_unregister_i2c: platform_device_unregister(txgbe->i2c_dev); err_unregister_clk: clkdev_drop(txgbe->clock); - clk_unregister(txgbe->clk); + clk_unregister_fixed_rate(txgbe->clk); err_destroy_phylink: phylink_destroy(wx->phylink); err_destroy_xpcs: @@ -671,7 +671,7 @@ void txgbe_remove_phy(struct txgbe *txgbe) platform_device_unregister(txgbe->sfp_dev); platform_device_unregister(txgbe->i2c_dev); clkdev_drop(txgbe->clock); - clk_unregister(txgbe->clk); + clk_unregister_fixed_rate(txgbe->clk); phylink_destroy(txgbe->wx->phylink); xpcs_destroy_pcs(txgbe->pcs); software_node_unregister_node_group(txgbe->nodes.group); From 8a44d8813de3a546fe0af6a5c5cc44b867f798e3 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 10:18:50 +0530 Subject: [PATCH 0525/2126] wifi: rtl8xxxu: fix typo "Tranceiver" in comment Correct "Tranceiver" to "Transceiver", reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches a comment, no code changes. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260907044851.9884-2-hemanth.selam@gmail.com --- drivers/net/wireless/realtek/rtl8xxxu/regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/regs.h b/drivers/net/wireless/realtek/rtl8xxxu/regs.h index eafaef1438b9..2131d07c5801 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/regs.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/regs.h @@ -982,7 +982,7 @@ #define REG_NHM_TH3_TO_TH0_8723B 0x0898 #define REG_NHM_TH7_TO_TH4_8723B 0x089c -#define REG_FPGA0_XA_LSSI_READBACK 0x08a0 /* Tranceiver LSSI Readback */ +#define REG_FPGA0_XA_LSSI_READBACK 0x08a0 /* Transceiver LSSI Readback */ #define REG_FPGA0_XB_LSSI_READBACK 0x08a4 #define REG_FPGA0_PSD_REPORT 0x08b4 #define REG_HSPI_XA_READBACK 0x08b8 /* Transceiver A HSPI read */ From 834fc28d78809135b4114f3f6920f2f101406428 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Mon, 7 Sep 2026 10:18:51 +0530 Subject: [PATCH 0526/2126] wifi: rtlwifi: fix typos in comments Fix typos in comments, reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260907044851.9884-3-hemanth.selam@gmail.com --- drivers/net/wireless/realtek/rtlwifi/base.c | 2 +- .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c | 2 +- .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c | 2 +- .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c | 2 +- drivers/net/wireless/realtek/rtlwifi/core.c | 4 ++-- drivers/net/wireless/realtek/rtlwifi/debug.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8188ee/dm.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8188ee/hw.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8188ee/phy.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8188ee/phy.h | 2 +- .../wireless/realtek/rtlwifi/rtl8188ee/pwrseq.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8188ee/reg.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192ce/hw.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192ce/trx.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192d/reg.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192de/hw.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192du/phy.c | 4 ++-- .../net/wireless/realtek/rtlwifi/rtl8192ee/fw.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192ee/phy.c | 2 +- .../wireless/realtek/rtlwifi/rtl8192ee/pwrseq.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192se/hw.c | 8 +++++--- .../net/wireless/realtek/rtlwifi/rtl8192se/phy.c | 10 +++++----- .../net/wireless/realtek/rtlwifi/rtl8192se/reg.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8192se/trx.c | 4 ++-- .../wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c | 2 +- .../wireless/realtek/rtlwifi/rtl8723ae/pwrseq.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8723ae/trx.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8723be/dm.c | 2 +- .../wireless/realtek/rtlwifi/rtl8723be/pwrseq.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8723be/reg.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8723be/trx.c | 4 ++-- .../net/wireless/realtek/rtlwifi/rtl8821ae/dm.c | 12 ++++++------ .../net/wireless/realtek/rtlwifi/rtl8821ae/fw.c | 2 +- .../net/wireless/realtek/rtlwifi/rtl8821ae/hw.c | 2 +- .../wireless/realtek/rtlwifi/rtl8821ae/pwrseq.h | 2 +- .../net/wireless/realtek/rtlwifi/rtl8821ae/reg.h | 14 +++++++------- .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.c | 2 +- drivers/net/wireless/realtek/rtlwifi/usb.c | 2 +- drivers/net/wireless/realtek/rtlwifi/wifi.h | 6 +++--- 41 files changed, 66 insertions(+), 64 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c b/drivers/net/wireless/realtek/rtlwifi/base.c index 9e98c01bb90e..b6dcdd03535a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/base.c +++ b/drivers/net/wireless/realtek/rtlwifi/base.c @@ -1271,7 +1271,7 @@ void rtl_get_tcb_desc(struct ieee80211_hw *hw, tcb_desc->disable_ratefallback = 1; } else { /* - *because hw will nerver use hw_rate + *because hw will never use hw_rate *when tcb_desc->use_driver_rate = false *so we never set highest N rate here, *and N rate will all be controlled by FW diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c index edcd3c879f7f..7bece8765c7f 100644 --- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c +++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c @@ -1667,7 +1667,7 @@ static void btc8192e2ant_tdma_duration_adjust(struct btc_coexist *btcoexist, n = 3; wait_cnt = 0; } else { - /* accquire the BT TRx retry count from BT_Info byte2 */ + /* acquire the BT TRx retry count from BT_Info byte2 */ retry_cnt = coex_sta->bt_retry_cnt; rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], retry_cnt = %d\n", retry_cnt); diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c index 7a71f063015a..dac0568f6fd8 100644 --- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c +++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c @@ -1894,7 +1894,7 @@ static void btc8723b2ant_tdma_duration_adjust(struct btc_coexist *btcoexist, result = 0; wait_count = 0; } else { - /*accquire the BT TRx retry count from BT_Info byte2*/ + /* acquire the BT TRx retry count from BT_Info byte2 */ retry_count = coex_sta->bt_retry_cnt; if ((coex_sta->low_priority_tx) > 1050 || diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c index c5b8df58d4a2..e9045551e89f 100644 --- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c +++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c @@ -1780,7 +1780,7 @@ static void btc8821a2ant_tdma_duration_adjust(struct btc_coexist *btcoexist, result = 0; wait_count = 0; } else { - /* accquire the BT TRx retry count from BT_Info byte2 */ + /* acquire the BT TRx retry count from BT_Info byte2 */ retry_count = coex_sta->bt_retry_cnt; rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], retry_count = %d\n", retry_count); diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c b/drivers/net/wireless/realtek/rtlwifi/core.c index 22633c301564..e971132fee14 100644 --- a/drivers/net/wireless/realtek/rtlwifi/core.c +++ b/drivers/net/wireless/realtek/rtlwifi/core.c @@ -608,7 +608,7 @@ static int rtl_op_config(struct ieee80211_hw *hw, int radio_idx, u32 changed) /* sleep here is must, or we may recv the beacon and * cause mac80211 into wrong ps state, this will cause * power save nullfunc send fail, and further cause - * pkt loss, So sleep must quickly but not immediatly + * pkt loss, So sleep must quickly but not immediately * because that will cause nullfunc send by mac80211 * fail, and cause pkt loss, we have tested that 5mA * is worked very well */ @@ -1711,7 +1711,7 @@ static void rtl_op_rfkill_poll(struct ieee80211_hw *hw) } /* this function is called by mac80211 to flush tx buffer - * before switch channle or power save, or tx buffer packet + * before switch channel or power save, or tx buffer packet * maybe send after offchannel or rf sleep, this may cause * dis-association by AP */ static void rtl_op_flush(struct ieee80211_hw *hw, diff --git a/drivers/net/wireless/realtek/rtlwifi/debug.h b/drivers/net/wireless/realtek/rtlwifi/debug.h index 1c0bcf8ec1a9..afed6ac36afc 100644 --- a/drivers/net/wireless/realtek/rtlwifi/debug.h +++ b/drivers/net/wireless/realtek/rtlwifi/debug.h @@ -18,7 +18,7 @@ /*#define DBG_EMERG 0 */ /* - *Abnormal, rare, or unexpeted cases. + *Abnormal, rare, or unexpected cases. *For example, Packet/IO Ctl canceled, *device suprisely unremoved and so on. */ diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/dm.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/dm.c index f749d19ec5f5..d9132d90feb1 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/dm.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/dm.c @@ -879,7 +879,7 @@ static void dm_txpower_track_cb_therm(struct ieee80211_hw *hw) {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 25, 25} }; - /*Initilization (7 steps in total) */ + /* Initialization (7 steps in total) */ rtlpriv->dm.txpower_trackinginit = true; rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "%s\n", __func__); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c index 910f8372d83d..0dbe92188bb1 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c @@ -1090,7 +1090,7 @@ int rtl88ee_hw_init(struct ieee80211_hw *hw) rtl88e_phy_mac_config(hw); /* because last function modify RCR, so we update * rcr var here, or TP will unstable for receive_config - * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx + * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252 */ rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.c index 0fab3a0c7d49..754ca8549c76 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.c @@ -1891,7 +1891,7 @@ static void _rtl88e_phy_set_rfpath_switch(struct ieee80211_hw *hw, rtl_set_bbreg(hw, 0x914, MASKLWORD, 0x0201); /* We use the RF definition of MAIN and AUX, - * left antenna and right antenna repectively. + * left antenna and right antenna respectively. * Default output at AUX. */ if (bmain) { diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.h b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.h index 8157ef419eeb..3fef46e67501 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/phy.h @@ -5,7 +5,7 @@ #define __RTL92C_PHY_H__ /* MAX_TX_COUNT must always set to 4, otherwise read efuse - * table secquence will be wrong. + * table sequence will be wrong. */ #define MAX_TX_COUNT 4 diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/pwrseq.h b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/pwrseq.h index 42e222c1795f..d34c50a4285e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/pwrseq.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/pwrseq.h @@ -14,7 +14,7 @@ * 4: LPS--Low Power State * 5: SUS--Suspend * - * The transision from different states are defined below + * The transition from different states are defined below * TRANS_CARDEMU_TO_ACT * TRANS_ACT_TO_CARDEMU * TRANS_CARDEMU_TO_SUS diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/reg.h b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/reg.h index 0fc8db8916fa..d23da11c2f8e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/reg.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/reg.h @@ -609,7 +609,7 @@ #define HWSET_MAX_SIZE 512 #define EFUSE_MAX_SECTION 64 #define EFUSE_REAL_CONTENT_LEN 256 -/* PG data exclude header, dummy 7 bytes frome CP test and reserved 1byte.*/ +/* PG data exclude header, dummy 7 bytes from CP test and reserved 1byte. */ #define EFUSE_OOB_PROTECT_BYTES 18 #define EEPROM_DEFAULT_TSSI 0x0 diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c index d094163a9a71..ce19b09e36be 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c @@ -432,7 +432,7 @@ bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw, /* hw will set status->decrypted true, if it finds the * frame is open data frame or mgmt frame. - * So hw will not decryption robust managment frame + * So hw will not decryption robust management frame * for IEEE80211w but still set status->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c index 4354ae67a379..942ffea27547 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c @@ -952,7 +952,7 @@ int rtl92ce_hw_init(struct ieee80211_hw *hw) rtl92c_phy_mac_config(hw); /* because last function modify RCR, so we update * rcr var here, or TP will unstable for receive_config - * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx + * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252*/ rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR); rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c index ed151754fc6e..99472053ccff 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c @@ -302,7 +302,7 @@ bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw, /* hw will set stats->decrypted true, if it finds the * frame is open data frame or mgmt frame. - * So hw will not decryption robust managment frame + * So hw will not decryption robust management frame * for IEEE80211w but still set status->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192d/reg.h b/drivers/net/wireless/realtek/rtlwifi/rtl8192d/reg.h index b5b906b799cb..639aa0d92e05 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192d/reg.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192d/reg.h @@ -1051,7 +1051,7 @@ /* 2. 0x800/0x900/0xA00/0xC00/0xD00/0xE00 */ /* 3. RF register 0x00-2E */ /* 4. Bit Mask for BB/RF register */ -/* 5. Other defintion for BB/RF R/W */ +/* 5. Other definition for BB/RF R/W */ /* 3. Page8(0x800) */ #define RFPGA0_RFMOD 0x800 diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.c index 03f4314bdb2e..d7f48f2bde7a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.c @@ -644,7 +644,7 @@ int rtl92de_hw_init(struct ieee80211_hw *hw) rtl92d_phy_mac_config(hw); /* because last function modify RCR, so we update * rcr var here, or TP will unstable for receive_config - * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx + * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252*/ rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR); rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/phy.c index 8c2167cc1f13..fe3af3e8e345 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/phy.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/phy.c @@ -764,7 +764,7 @@ static void _rtl92du_phy_switch_rf_setting(struct ieee80211_hw *hw, u8 channel) rtlhal->interfaceindex == 1) { need_pwr_down = rtl92du_phy_enable_anotherphy(hw, false); rtlhal->during_mac1init_radioa = true; - /* asume no this case */ + /* assume no this case */ if (need_pwr_down) rtl92d_phy_enable_rf_env(hw, path, &u4regvalue); @@ -2248,7 +2248,7 @@ static void _rtl92du_phy_reload_lck_setting(struct ieee80211_hw *hw, u8 channel) bneed_powerdown_radio = rtl92du_phy_enable_anotherphy(hw, false); rtlpriv->rtlhal.during_mac1init_radioa = true; - /* asume no this case */ + /* assume no this case */ if (bneed_powerdown_radio) rtl92d_phy_enable_rf_env(hw, erfpath, &u4regvalue); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c index 88b7a715f4c5..3728e3ec2c25 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c @@ -762,7 +762,7 @@ void rtl92ee_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished) } } -/*Shoud check FW support p2p or not.*/ +/* Should check FW support p2p or not. */ static void rtl92ee_set_p2p_ctw_period_cmd(struct ieee80211_hw *hw, u8 ctwindow) { u8 u1_ctwindow_period[1] = {ctwindow}; diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/phy.c index 1e7f0cd1c86e..2435d457e520 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/phy.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/phy.c @@ -2733,7 +2733,7 @@ static void _rtl92ee_phy_set_rfpath_switch(struct ieee80211_hw *hw, rtl_set_bbreg(hw, 0x914, MASKLWORD, 0x0201); /* We use the RF definition of MAIN and AUX, - * left antenna and right antenna repectively. + * left antenna and right antenna respectively. * Default output at AUX. */ if (bmain) { diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/pwrseq.h b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/pwrseq.h index 2ae8347f7ebb..09f12b5a41ba 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/pwrseq.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/pwrseq.h @@ -15,7 +15,7 @@ * 4: LPS--Low Power State * 5: SUS--Suspend * - * The transision from different states are defined below + * The transition from different states are defined below * TRANS_CARDEMU_TO_ACT * TRANS_ACT_TO_CARDEMU * TRANS_CARDEMU_TO_SUS diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c index 16589e18494b..658591badd8e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c @@ -385,7 +385,7 @@ bool rtl92ee_rx_query_desc(struct ieee80211_hw *hw, /* hw will set status->decrypted true, if it finds the * frame is open data frame or mgmt frame. - * So hw will not decryption robust managment frame + * So hw will not decryption robust management frame * for IEEE80211w but still set status->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c index 6b9f247d11e0..709fe0945795 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c @@ -982,7 +982,7 @@ int rtl92se_hw_init(struct ieee80211_hw *hw) /* because last function modify RCR, so we update * rcr var here, or TP will unstable for receive_config - * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx + * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252 */ rtlpci->receive_config = rtl_read_dword(rtlpriv, RCR); @@ -2350,8 +2350,10 @@ bool rtl92se_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid) } -/* Is_wepkey just used for WEP used as group & pairwise key - * if pairwise is AES ang group is WEP Is_wepkey == false.*/ +/* + * Is_wepkey just used for WEP used as group & pairwise key + * if pairwise is AES and group is WEP Is_wepkey == false. + */ void rtl92se_set_key(struct ieee80211_hw *hw, u32 key_index, u8 *p_macaddr, bool is_group, u8 enc_algo, bool is_wepkey, bool clear_all) { diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/phy.c index d9ef7e1da1db..11e783f9b4c2 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/phy.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/phy.c @@ -689,7 +689,7 @@ static void _rtl92s_phy_init_register_definition(struct ieee80211_hw *hw) rtlphy->phyreg_def[RF90_PATH_C].rfintfe = RFPGA0_XC_RFINTERFACEOE; rtlphy->phyreg_def[RF90_PATH_D].rfintfe = RFPGA0_XD_RFINTERFACEOE; - /* Addr of LSSI. Wirte RF register by driver */ + /* Addr of LSSI. Write RF register by driver */ rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset = RFPGA0_XA_LSSIPARAMETER; rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset = @@ -711,13 +711,13 @@ static void _rtl92s_phy_init_register_definition(struct ieee80211_hw *hw) rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE; rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE; - /* Tranceiver A~D HSSI Parameter-1 */ + /* Transceiver A~D HSSI Parameter-1 */ rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1; rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1; rtlphy->phyreg_def[RF90_PATH_C].rfhssi_para1 = RFPGA0_XC_HSSIPARAMETER1; rtlphy->phyreg_def[RF90_PATH_D].rfhssi_para1 = RFPGA0_XD_HSSIPARAMETER1; - /* Tranceiver A~D HSSI Parameter-2 */ + /* Transceiver A~D HSSI Parameter-2 */ rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2; rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2; rtlphy->phyreg_def[RF90_PATH_C].rfhssi_para2 = RFPGA0_XC_HSSIPARAMETER2; @@ -765,13 +765,13 @@ static void _rtl92s_phy_init_register_definition(struct ieee80211_hw *hw) rtlphy->phyreg_def[RF90_PATH_C].rftx_afe = ROFDM0_XCTXAFE; rtlphy->phyreg_def[RF90_PATH_D].rftx_afe = ROFDM0_XDTXAFE; - /* Tranceiver LSSI Readback */ + /* Transceiver LSSI Readback */ rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK; rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK; rtlphy->phyreg_def[RF90_PATH_C].rf_rb = RFPGA0_XC_LSSIREADBACK; rtlphy->phyreg_def[RF90_PATH_D].rf_rb = RFPGA0_XD_LSSIREADBACK; - /* Tranceiver LSSI Readback PI mode */ + /* Transceiver LSSI Readback PI mode */ rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVERA_HSPI_READBACK; rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVERB_HSPI_READBACK; } diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/reg.h b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/reg.h index 45f968e0e57c..bd43d91bc146 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/reg.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/reg.h @@ -303,7 +303,7 @@ #define RPWM PCI_RPWM -/* Regsiter Bit and Content definition */ +/* Register Bit and Content definition */ #define ISO_MD2PP BIT(0) #define ISO_PA2PCIE BIT(3) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/trx.c index f104cdb649f8..b057d035a3a8 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/trx.c @@ -276,7 +276,7 @@ bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats, /* hw will set stats->decrypted true, if it finds the * frame is open data frame or mgmt frame, - * hw will not decrypt robust managment frame + * hw will not decrypt robust management frame * for IEEE80211w but still set stats->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help @@ -466,7 +466,7 @@ void rtl92se_tx_fill_desc(struct ieee80211_hw *hw, /* Alwasy enable all rate fallback range */ set_tx_desc_data_rate_fb_limit(pdesc, 0x1F); - /* Fix: I don't kown why hw use 6.5M to tx when set it */ + /* Fix: I don't known why hw use 6.5M to tx when set it */ set_tx_desc_user_rate(pdesc, ptcb_desc->use_driver_rate ? 1 : 0); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c index b34dffc6a30c..b36f958a7363 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c @@ -889,7 +889,7 @@ void rtl8723e_dm_bt_set_bt_dm(struct ieee80211_hw *hw, /* Note: * We should add delay for making sure - * sw DacSwing can be set sucessfully. + * sw DacSwing can be set successfully. * because of that rtl8723e_dm_bt_set_fw_2_ant_hid() * and rtl8723e_dm_bt_set_fw_tdma_ctrl() * will overwrite the reg 0x880. diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/pwrseq.h b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/pwrseq.h index d9247a8f3039..4835fb17c5e1 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/pwrseq.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/pwrseq.h @@ -15,7 +15,7 @@ * 4: LPS--Low Power State * 5: SUS--Suspend * - * The transision from different states are defined below + * The transition from different states are defined below * TRANS_CARDEMU_TO_ACT * TRANS_ACT_TO_CARDEMU * TRANS_CARDEMU_TO_SUS diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c index 65bfc14702f4..f40b0efebe3a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c @@ -305,7 +305,7 @@ bool rtl8723e_rx_query_desc(struct ieee80211_hw *hw, /* hw will set status->decrypted true, if it finds the * frame is open data frame or mgmt frame. - * So hw will not decryption robust managment frame + * So hw will not decryption robust management frame * for IEEE80211w but still set status->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/dm.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/dm.c index c65d14fb914f..82e6202fca38 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/dm.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/dm.c @@ -742,7 +742,7 @@ static void rtl8723be_dm_txpower_tracking_callback_thermalmeter( 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15}; - /*Initilization ( 7 steps in total )*/ + /* Initialization ( 7 steps in total ) */ rtlpriv->dm.txpower_trackinginit = true; rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "%s\n", __func__); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/pwrseq.h b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/pwrseq.h index 57eac4864184..94f7ab48cab2 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/pwrseq.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/pwrseq.h @@ -15,7 +15,7 @@ * 4: LPS--Low Power State * 5: SUS--Suspend * - * The transision from different states are defined below + * The transition from different states are defined below * TRANS_CARDEMU_TO_ACT * TRANS_ACT_TO_CARDEMU * TRANS_CARDEMU_TO_SUS diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/reg.h b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/reg.h index 28fd22b2a792..35c96d33e8e0 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/reg.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/reg.h @@ -603,7 +603,7 @@ #define EFUSE_MAX_SECTION 64 #define EFUSE_REAL_CONTENT_LEN 256 #define EFUSE_OOB_PROTECT_BYTES 18 /* PG data exclude header, - * dummy 7 bytes frome CP test + * dummy 7 bytes from CP test * and reserved 1byte. */ diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/trx.c index 8b6352f7f93b..b6029bfaedac 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/trx.c @@ -220,7 +220,7 @@ static void _rtl8723be_translate_rx_signal_stuff(struct ieee80211_hw *hw, (ether_addr_equal(praddr, rtlefuse->dev_addr)); /* YP: packet_beacon is not initialized, - * this assignment is neccesary, + * this assignment is necessary, * otherwise it counld be true in this case * the situation is much worse in Kernel 3.10 */ @@ -360,7 +360,7 @@ bool rtl8723be_rx_query_desc(struct ieee80211_hw *hw, /* hw will set status->decrypted true, if it finds the * frame is open data frame or mgmt frame. - * So hw will not decryption robust managment frame + * So hw will not decryption robust management frame * for IEEE80211w but still set status->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/dm.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/dm.c index f8b159c74658..0e8547a29f0a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/dm.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/dm.c @@ -1150,7 +1150,7 @@ u8 rtl8821ae_hw_rate_to_mrate(struct ieee80211_hw *hw, u8 rate) /*----------------------------------------------------------------------------- * Function: odm_TxPwrTrackSetPwr88E() * - * Overview: 88E change all channel tx power accordign to flag. + * Overview: 88E change all channel tx power according to flag. * OFDM & CCK are all different. * * Input: NONE @@ -1459,7 +1459,7 @@ void rtl8812ae_dm_txpower_tracking_callback_thermalmeter( const u8 *delta_swing_table_idx_tup_b; const u8 *delta_swing_table_idx_tdown_b; - /*2. Initialization ( 7 steps in total )*/ + /* 2. Initialization ( 7 steps in total ) */ rtl8812ae_get_delta_swing_table(hw, &delta_swing_table_idx_tup_a, &delta_swing_table_idx_tdown_a, @@ -1546,7 +1546,7 @@ void rtl8812ae_dm_txpower_tracking_callback_thermalmeter( if (delta > 0 && rtldm->txpower_track_control) { /* "delta" here is used to record the - * absolute value of differrence. + * absolute value of difference. */ delta = thermal_value > rtlefuse->eeprom_thermalmeter ? (thermal_value - rtlefuse->eeprom_thermalmeter) : @@ -1829,7 +1829,7 @@ static void rtl8821ae_get_delta_swing_table(struct ieee80211_hw *hw, /*----------------------------------------------------------------------------- * Function: odm_TxPwrTrackSetPwr88E() * - * Overview: 88E change all channel tx power accordign to flag. + * Overview: 88E change all channel tx power according to flag. * OFDM & CCK are all different. * * Input: NONE @@ -2029,7 +2029,7 @@ void rtl8821ae_dm_txpower_tracking_callback_thermalmeter( const u8 *delta_swing_table_idx_tup_a; const u8 *delta_swing_table_idx_tdown_a; - /*2. Initilization ( 7 steps in total )*/ + /* 2. Initialization ( 7 steps in total ) */ rtl8821ae_get_delta_swing_table(hw, &delta_swing_table_idx_tup_a, &delta_swing_table_idx_tdown_a); @@ -2111,7 +2111,7 @@ void rtl8821ae_dm_txpower_tracking_callback_thermalmeter( if (delta > 0 && rtldm->txpower_track_control) { /*"delta" here is used to record the - * absolute value of differrence. + * absolute value of difference. */ delta = thermal_value > rtlefuse->eeprom_thermalmeter ? (thermal_value - rtlefuse->eeprom_thermalmeter) : diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c index 1ae56e15ca7f..4facbc0bff4e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c @@ -654,7 +654,7 @@ void rtl8821ae_set_fw_keep_alive_cmd(struct ieee80211_hw *hw, rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, "Enable(%d)\n", func_en); SET_8812_H2CCMD_KEEP_ALIVE_ENABLE(keep_alive_info, func_en); - /* 1: the period is controled by driver, 0: by Fw default */ + /* 1: the period is controlled by driver, 0: by Fw default */ SET_8812_H2CCMD_KEEP_ALIVE_ACCPEPT_USER_DEFINED(keep_alive_info, 1); SET_8812_H2CCMD_KEEP_ALIVE_PERIOD(keep_alive_info, 10); /* 10 sec */ diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c index 31f499be99a3..fb893ed8b802 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c @@ -1019,7 +1019,7 @@ static void _rtl8821ae_hw_configure(struct ieee80211_hw *hw) /* ARFB table 12 for 11ac 24G 1SS */ rtl_write_dword(rtlpriv, REG_ARFR3, 0x00000015); rtl_write_dword(rtlpriv, REG_ARFR3 + 4, 0xffcff000); - /* 0x420[7] = 0 , enable retry AMPDU in new AMPD not singal MPDU. */ + /* 0x420[7] = 0 , enable retry AMPDU in new AMPD not signal MPDU. */ rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F00); rtl_write_byte(rtlpriv, REG_AMPDU_MAX_TIME, 0x70); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/pwrseq.h b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/pwrseq.h index d6f3cbab4abc..7297733c7710 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/pwrseq.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/pwrseq.h @@ -343,7 +343,7 @@ extern struct wlan_pwr_cfg rtl8812_leave_lps_flow * 4: LPS--Low Power State * 5: SUS--Suspend * - * The transision from different states are defined below + * The transition from different states are defined below * TRANS_CARDEMU_TO_ACT * TRANS_ACT_TO_CARDEMU * TRANS_CARDEMU_TO_SUS diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/reg.h b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/reg.h index 7d833b72c7ed..ceddd72e2581 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/reg.h +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/reg.h @@ -631,7 +631,7 @@ #define HWSET_MAX_SIZE 512 #define EFUSE_MAX_SECTION 64 #define EFUSE_REAL_CONTENT_LEN 256 -/* PG data exclude header, dummy 7 bytes frome CP test and reserved 1byte.*/ +/* PG data exclude header, dummy 7 bytes from CP test and reserved 1byte. */ #define EFUSE_OOB_PROTECT_BYTES 18 #define EEPROM_DEFAULT_TSSI 0x0 @@ -1523,7 +1523,7 @@ #define ROFDM0_TXCOEFF5 0xcb4 #define ROFDM0_TXCOEFF6 0xcb8 -/*Path_A RFE cotrol */ +/* Path_A RFE control */ #define RA_RFE_CTRL_8812 0xcb8 /*Path_B RFE control*/ #define RB_RFE_CTRL_8812 0xeb8 @@ -2336,7 +2336,7 @@ #define REG_UN_used_register 0x01bf -/* Path_A RFE cotrol pinmux*/ +/* Path_A RFE control pinmux */ #define RA_RFE_PINMUX 0xcb0 /* Path_B RFE control pinmux*/ #define RB_RFE_PINMUX 0xeb0 @@ -2345,17 +2345,17 @@ #define RB_RFE_INV 0xeb4 /* RXIQC */ -/*RxIQ imblance matrix coeff. A & B*/ +/* RxIQ imbalance matrix coeff. A & B */ #define RA_RXIQC_AB 0xc10 -/*RxIQ imblance matrix coeff. C & D*/ +/* RxIQ imbalance matrix coeff. C & D */ #define RA_RXIQC_CD 0xc14 /* Pah_A TX scaling factor*/ #define RA_TXSCALE 0xc1c /* Path_B TX scaling factor*/ #define RB_TXSCALE 0xe1c -/*RxIQ imblance matrix coeff. A & B*/ +/* RxIQ imbalance matrix coeff. A & B */ #define RB_RXIQC_AB 0xe10 -/*RxIQ imblance matrix coeff. C & D*/ +/* RxIQ imbalance matrix coeff. C & D */ #define RB_RXIQC_CD 0xe14 /*bit mask for IQC matrix element A & C*/ #define RXIQC_AC 0x02ff diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/trx.c index bd71592fe26a..12a8341d2f1c 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/trx.c @@ -512,7 +512,7 @@ bool rtl8821ae_rx_query_desc(struct ieee80211_hw *hw, /* hw will set status->decrypted true, if it finds the * frame is open data frame or mgmt frame. - * So hw will not decryption robust managment frame + * So hw will not decryption robust management frame * for IEEE80211w but still set status->decrypted * true, so here we should set it back to undecrypted * for IEEE80211w frame, and mac80211 sw will help diff --git a/drivers/net/wireless/realtek/rtlwifi/usb.c b/drivers/net/wireless/realtek/rtlwifi/usb.c index 9a64df9eed39..d013e5986948 100644 --- a/drivers/net/wireless/realtek/rtlwifi/usb.c +++ b/drivers/net/wireless/realtek/rtlwifi/usb.c @@ -43,7 +43,7 @@ static void _usbctrl_vendorreq_sync(struct usb_device *udev, u8 reqtype, reqtype, value, REALTEK_USB_VENQT_CMD_IDX, pdata, len, 1000); if (status < 0) { - /* firmware download is checksumed, don't retry */ + /* firmware download is checksummed, don't retry */ if ((value >= FW_8192C_START_ADDRESS && value <= FW_8192C_END_ADDRESS)) break; diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h b/drivers/net/wireless/realtek/rtlwifi/wifi.h index f1830ddcdd8c..23697704ffee 100644 --- a/drivers/net/wireless/realtek/rtlwifi/wifi.h +++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h @@ -744,7 +744,7 @@ enum rtl_var_map { RTL_IMR_BDOK, /*Beacon Queue DMA OK Interrup */ RTL_IMR_HIGHDOK, /*High Queue DMA OK Interrupt */ RTL_IMR_COMDOK, /*Command Queue DMA OK Interrupt*/ - RTL_IMR_TBDOK, /*Transmit Beacon OK interrup */ + RTL_IMR_TBDOK, /* Transmit Beacon OK interrupt */ RTL_IMR_MGNTDOK, /*Management Queue DMA OK Interrupt */ RTL_IMR_TBDER, /*For 92C,Transmit Beacon Error Interrupt */ RTL_IMR_BKDOK, /*AC_BK DMA OK Interrupt */ @@ -2693,7 +2693,7 @@ struct rtl_priv { int max_fw_size; /* hal_cfg : for diff cards - * intf_ops : for diff interrface usb/pcie + * intf_ops : for diff interface usb/pcie */ const struct rtl_hal_cfg *cfg; const struct rtl_intf_ops *intf_ops; @@ -2841,7 +2841,7 @@ enum bt_radio_shared { #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6) /* no matter RFOFF or SLEEP we set PS_ASPM_LEVL*/ #define RT_PS_LEVEL_ASPM BIT(7) -/*When LPS is on, disable 2R if no packet is received or transmittd.*/ +/* When LPS is on, disable 2R if no packet is received or transmitted. */ #define RT_RF_LPS_DISALBE_2R BIT(30) #define RT_RF_LPS_LEVEL_ASPM BIT(31) /*LPS with ASPM */ #define RT_IN_PS_LEVEL(ppsc, _ps_flg) \ From 5bfbd61717c6ad9440d47063ecc9fee16b66eb88 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 8 Sep 2026 19:29:48 +0200 Subject: [PATCH 0527/2126] wifi: rtw89: avoid iter_keys_rcu() where not needed All of this code already holds the wiphy mutex, so none needs the _rcu() variant. Simplify the code. Signed-off-by: Johannes Berg Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260908192948.8a5318efb4df.I56408c1ff0b5c3bcb19a1054858076443fcae3b3@changeid --- drivers/net/wireless/realtek/rtw89/cam.c | 4 +--- drivers/net/wireless/realtek/rtw89/wow.c | 12 ++++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/cam.c b/drivers/net/wireless/realtek/rtw89/cam.c index 7c62ece137d0..22f21a04a96d 100644 --- a/drivers/net/wireless/realtek/rtw89/cam.c +++ b/drivers/net/wireless/realtek/rtw89/cam.c @@ -605,9 +605,7 @@ void rtw89_cam_deinit(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_li void rtw89_cam_reset_keys(struct rtw89_dev *rtwdev) { - rcu_read_lock(); - ieee80211_iter_keys_rcu(rtwdev->hw, NULL, rtw89_cam_reset_key_iter, rtwdev); - rcu_read_unlock(); + ieee80211_iter_keys(rtwdev->hw, NULL, rtw89_cam_reset_key_iter, rtwdev); } static int rtw89_cam_get_avail_addr_cam(struct rtw89_dev *rtwdev, diff --git a/drivers/net/wireless/realtek/rtw89/wow.c b/drivers/net/wireless/realtek/rtw89/wow.c index 2dfa24c54e7d..0bf34692c7ce 100644 --- a/drivers/net/wireless/realtek/rtw89/wow.c +++ b/drivers/net/wireless/realtek/rtw89/wow.c @@ -473,10 +473,8 @@ static void rtw89_wow_construct_key_info(struct rtw89_dev *rtwdev) struct ieee80211_vif *wow_vif = rtwvif_link_to_vif(rtwvif_link); bool err = false; - rcu_read_lock(); - ieee80211_iter_keys_rcu(rtwdev->hw, wow_vif, - rtw89_wow_get_key_info_iter, &err); - rcu_read_unlock(); + ieee80211_iter_keys(rtwdev->hw, wow_vif, + rtw89_wow_get_key_info_iter, &err); if (err) { rtw89_wow_key_clear(rtwdev); @@ -695,10 +693,8 @@ static void rtw89_wow_update_key_info(struct rtw89_dev *rtwdev, bool rx_ready) struct ieee80211_bss_conf *bss_conf; struct ieee80211_key_conf *key; - rcu_read_lock(); - ieee80211_iter_keys_rcu(rtwdev->hw, wow_vif, - rtw89_wow_set_key_info_iter, &data); - rcu_read_unlock(); + ieee80211_iter_keys(rtwdev->hw, wow_vif, + rtw89_wow_set_key_info_iter, &data); if (data.error) { rtw89_debug(rtwdev, RTW89_DBG_WOW, "%s error\n", __func__); From eed90f3e4e10ed10448bed60fe88304cb01e4c4c Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 9 Sep 2026 14:59:50 +0800 Subject: [PATCH 0528/2126] wifi: rtw89: consider sta maximum AMSDU subframes number to decide TX work waiting Consider the sta maximum AMSDU subframes as a factor to set agg_wait to 0 to avoid TX work waiting to yield better latency if real-time application lets AMSDU off by iw dev wlan0 set tidconf tids 0xff amsdu off Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/phy.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index 501923d97971..c33b888bc0e3 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -3221,6 +3221,17 @@ static void rtw89_phy_set_txpwr_limit_ru_ax(struct rtw89_dev *rtwdev, } } +static int get_max_agg_wait(struct ieee80211_link_sta *link_sta, u16 amsdu_len) +{ + struct ieee80211_sta *sta = link_sta->sta; + int max_agg_wait = amsdu_len / 1500 - 1; + + if (sta->max_amsdu_subframes) + max_agg_wait = min(max_agg_wait, sta->max_amsdu_subframes - 1); + + return max_agg_wait; +} + struct rtw89_phy_iter_ra_data { struct rtw89_dev *rtwdev; struct sk_buff *c2h; @@ -3345,7 +3356,7 @@ static void __rtw89_phy_c2h_ra_rpt_iter(struct rtw89_sta_link *rtwsta_link, *changed = true; } - rtwsta_link->max_agg_wait = link_sta->agg.max_rc_amsdu_len / 1500 - 1; + rtwsta_link->max_agg_wait = get_max_agg_wait(link_sta, amsdu_len); } static void rtw89_phy_c2h_ra_rpt_iter(void *data, struct ieee80211_sta *sta) From 134e606449955f175de8209c6a2373be9e1fca6c Mon Sep 17 00:00:00 2001 From: Po-Hao Huang Date: Wed, 9 Sep 2026 14:59:51 +0800 Subject: [PATCH 0529/2126] wifi: rtw89: mlo: update link id to FW upon connection Update link id to firmware so correct information can be referenced. This is required for the new power save firmware feature. Without this FW could try to maintain power state of a not existing link and leads to unexpected errors. Signed-off-by: Po-Hao Huang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/fw.c | 6 +++--- drivers/net/wireless/realtek/rtw89/fw.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 6760e0053665..86db025afd7f 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -5193,10 +5193,10 @@ int rtw89_fw_h2c_join_info(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwv RTW89_H2C_JOININFO_W1_EMLSR_PADDING) | le32_encode_bits(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_256US, RTW89_H2C_JOININFO_W1_EMLSR_TRANS_DELAY) | - le32_encode_bits(0, RTW89_H2C_JOININFO_W2_MACID_EXT) | - le32_encode_bits(0, RTW89_H2C_JOININFO_W2_MAIN_MACID_EXT); + le32_encode_bits(rtwvif_link->link_id, RTW89_H2C_JOININFO_W1_LINK_ID); - h2c_v1->w2 = 0; + h2c_v1->w2 = le32_encode_bits(0, RTW89_H2C_JOININFO_W2_MACID_EXT) | + le32_encode_bits(0, RTW89_H2C_JOININFO_W2_MAIN_MACID_EXT); done: rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index f7d017d3ced0..6cb1f6dfb650 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -1858,6 +1858,11 @@ struct rtw89_h2c_join_v1 { #define RTW89_H2C_JOININFO_W1_INIT_PWR_STATE BIT(15) #define RTW89_H2C_JOININFO_W1_EMLSR_PADDING GENMASK(18, 16) #define RTW89_H2C_JOININFO_W1_EMLSR_TRANS_DELAY GENMASK(21, 19) +#define RTW89_H2C_JOININFO_W1_IS_MLD_EXT BIT(22) +#define RTW89_H2C_JOININFO_W1_SUPPORT_3LINKS BIT(23) +#define RTW89_H2C_JOININFO_W1_IS_3RD_LINK BIT(24) +#define RTW89_H2C_JOININFO_W1_LINK_ID GENMASK(28, 25) +#define RTW89_H2C_JOININFO_W1_UPDATE_MODE GENMASK(31, 29) #define RTW89_H2C_JOININFO_W2_MACID_EXT GENMASK(7, 0) #define RTW89_H2C_JOININFO_W2_MAIN_MACID_EXT GENMASK(15, 8) From de9da54622bab66c73a012554467aa089adca4ad Mon Sep 17 00:00:00 2001 From: Po-Hao Huang Date: Wed, 9 Sep 2026 14:59:52 +0800 Subject: [PATCH 0530/2126] Revert "wifi: rtw89: fix unable to receive probe responses under MLO connection" This reverts commit 6f6d7a325fbde4f025ee1b1277f6f44727e21223. We no longer require this change after commit 0b0ff976af94 ("wifi: mac80211: accept probe response on link address as well") Previously, the encryption and decryption of MLD connections are not working properly during scan, this could lead to timeout on some applications. Signed-off-by: Po-Hao Huang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/fw.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 86db025afd7f..a16127b2c317 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -10445,7 +10445,6 @@ int rtw89_hw_scan_start(struct rtw89_dev *rtwdev, struct cfg80211_scan_request *req = &scan_req->req; const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, rtwvif_link->chanctx_idx); - struct ieee80211_vif *vif = rtwvif_link_to_vif(rtwvif_link); struct rtw89_vif *rtwvif = rtwvif_link->rtwvif; struct rtw89_chanctx_pause_parm pause_parm = { .rsn = RTW89_CHANCTX_PAUSE_REASON_HW_SCAN, @@ -10478,8 +10477,6 @@ int rtw89_hw_scan_start(struct rtw89_dev *rtwdev, if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) get_random_mask_addr(mac_addr, req->mac_addr, req->mac_addr_mask); - else if (ieee80211_vif_is_mld(vif)) - ether_addr_copy(mac_addr, vif->addr); else ether_addr_copy(mac_addr, rtwvif_link->mac_addr); From 0788bad5d012b164e5eabf5da206dea4fa67db1c Mon Sep 17 00:00:00 2001 From: Po-Hao Huang Date: Wed, 9 Sep 2026 14:59:53 +0800 Subject: [PATCH 0531/2126] wifi: rtw89: modify active scan rule for 6GHz band Remove the cancellation of active scan with specific SSID when receiving beacons/probe responses of that SSID. Per IEEE Std 802.11ax 26.17.2.3.3, only active scan of direct BSSID should be cancelled. Previously the cancellation causes hidden AP under same ESS couldn't be found. Signed-off-by: Po-Hao Huang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-5-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 572d9c65a2dd..8ab15ee1b155 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -2579,7 +2579,6 @@ static void rtw89_core_cancel_6ghz_probe_tx(struct rtw89_dev *rtwdev, struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; struct list_head *pkt_list = rtwdev->scan_info.pkt_list; struct rtw89_pktofld_info *info; - const u8 *ies = mgmt->u.beacon.variable, *ssid_ie; bool queue_work = false; if (rx_status->band != NL80211_BAND_6GHZ) @@ -2590,21 +2589,10 @@ static void rtw89_core_cancel_6ghz_probe_tx(struct rtw89_dev *rtwdev, return; } - ssid_ie = cfg80211_find_ie(WLAN_EID_SSID, ies, skb->len); - list_for_each_entry(info, &pkt_list[NL80211_BAND_6GHZ], list) { if (ether_addr_equal(info->bssid, mgmt->bssid)) { info->cancel = true; queue_work = true; - continue; - } - - if (!ssid_ie || ssid_ie[1] != info->ssid_len || info->ssid_len == 0) - continue; - - if (memcmp(&ssid_ie[2], info->ssid, info->ssid_len) == 0) { - info->cancel = true; - queue_work = true; } } From 6c6130c4d53f260c7ccf324eb5c90454c319d5a3 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 9 Sep 2026 14:59:54 +0800 Subject: [PATCH 0532/2126] wifi: rtw89: fix ctrl_sco_cck for Wi-Fi 7 Wi-Fi 7 chips have function to control SCO (Symbol Carrier Offset) for CCK. The corresponding valid primary channels are from 1 to 14, i.e. array index is from 0 to 13. So, fix the condition. Resolve INTEGER_OVERFLOW (Overflowed array index read) reported by Coverity. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-6-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8922a.c | 2 +- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922a.c b/drivers/net/wireless/realtek/rtw89/rtw8922a.c index 2d225e009b28..6402bd4f06aa 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922a.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922a.c @@ -1152,7 +1152,7 @@ static int rtw8922a_ctrl_sco_cck(struct rtw89_dev *rtwdev, { u8 ch_element; - if (primary_ch >= 14) + if (primary_ch > 14 || unlikely(primary_ch == 0)) return -EINVAL; ch_element = primary_ch - 1; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 75297b39c4d7..89c1f58d0dc0 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -1320,7 +1320,7 @@ static int rtw8922d_ctrl_sco_cck(struct rtw89_dev *rtwdev, { u8 ch_element; - if (primary_ch >= 14) + if (primary_ch > 14 || unlikely(primary_ch == 0)) return -EINVAL; ch_element = primary_ch - 1; From cfa33d16a4187d073401423bfada0713df09c840 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 9 Sep 2026 14:59:55 +0800 Subject: [PATCH 0533/2126] wifi: rtw89: 8852a: prevent potential OOB in ctrl_sco_cck The array size is 14. Add a check to avoid out-of-bound access. Although it doesn't seem to happen if everything follows spec., it might have potential problem in pure logic. Resolve OVERRUN (Out-of-bounds access) reported by Coverity. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-7-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8852a.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852a.c b/drivers/net/wireless/realtek/rtw89/rtw8852a.c index 5d7b5d1a24b1..4b364f039464 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852a.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852a.c @@ -945,6 +945,14 @@ static int rtw8852a_ctrl_sco_cck(struct rtw89_dev *rtwdev, u8 central_ch, rtw89_warn(rtwdev, "Invalid BW:%d for CCK\n", bw); return -EINVAL; } + + if (unlikely(ch_element >= 14)) { + rtw89_warn(rtwdev, + "Invalid ch_element:%u where central_ch %u primary_ch %u\n", + ch_element, central_ch, primary_ch); + return -EINVAL; + } + rtw89_phy_write32_mask(rtwdev, R_RXSCOBC, B_RXSCOBC_TH, rtw8852a_sco_barker_threshold[ch_element]); rtw89_phy_write32_mask(rtwdev, R_RXSCOCCK, B_RXSCOCCK_TH, From a6e919d1473f4bdab0da5f67c7169e8f05871adb Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 9 Sep 2026 14:59:56 +0800 Subject: [PATCH 0534/2126] wifi: rtw89: fw: cmd_ofld_flush always reset counter Callers expect cmd offload counter is reset after flushing, and then use counter++ with array index. Previously, it might cause OOB since cmd_ofld_flush gets an error, e.g out of memory, and does not reset the cmd offload counter. Fix cmd_ofld_flush to always reset it. Resolve OVERRUN (Out-of-bounds write) reported by Coverity. Pass info to cmd_ofld_flush to make Coverity aware the changes on cmd offload counter. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-8-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/fw.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index a16127b2c317..dcbdf4b5e4b2 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -12643,9 +12643,9 @@ static int rtw89_fw_cmd_ofld_pack(struct rtw89_dev *rtwdev) return 0; } -static void rtw89_fw_cmd_ofld_flush(struct rtw89_dev *rtwdev) +static void rtw89_fw_cmd_ofld_flush(struct rtw89_dev *rtwdev, + struct rtw89_fw_cmd_ofld_info *info) { - struct rtw89_fw_cmd_ofld_info *info = rtwdev->fw_cmd_ofld_info; struct sk_buff *skb; int ret; u32 len; @@ -12654,7 +12654,7 @@ static void rtw89_fw_cmd_ofld_flush(struct rtw89_dev *rtwdev) skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); if (!skb) { rtw89_err(rtwdev, "alloc skb fail\n"); - return; + goto out; } skb_put_data(skb, info->cmds, len); @@ -12669,12 +12669,13 @@ static void rtw89_fw_cmd_ofld_flush(struct rtw89_dev *rtwdev) if (ret) { rtw89_err(rtwdev, "failed to send cmd ofld\n"); dev_kfree_skb_any(skb); - return; + goto out; } if (info->accu_delay) fsleep(info->accu_delay); +out: info->cnt = 0; info->accu_delay = 0; } @@ -12694,7 +12695,7 @@ static int rtw89_fw_cmd_ofld_unpack(struct rtw89_dev *rtwdev) if (info->cnt == 0) return 0; - rtw89_fw_cmd_ofld_flush(rtwdev); + rtw89_fw_cmd_ofld_flush(rtwdev, info); return 0; } @@ -12721,7 +12722,7 @@ static int rtw89_fw_cmd_ofld_enqueue(struct rtw89_dev *rtwdev, return -EFAULT; if (info->cnt >= ARRAY_SIZE(info->cmds)) - rtw89_fw_cmd_ofld_flush(rtwdev); + rtw89_fw_cmd_ofld_flush(rtwdev, info); h2c = &info->cmds[info->cnt++]; From 3ed30788192dafd8a91ef4b93b665342d399dbb5 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 9 Sep 2026 14:59:57 +0800 Subject: [PATCH 0535/2126] wifi: rtw89: explicitly declare TX queue flags by DECLARE_BITMAP() Originally, TX queue flags was declared by pure unsigned long but was used with bitops, e.g. test_bit. Although for now, there are not much cases in enum rtw89_txq_flags to be over than bits that one long can deal with, it indeed missed logical boundary check. Refine it to be declared by DECLARE_BITMAP(). Resolve ARRAY_VS_SINGLETON (Out-of-bounds access) reported by Coverity. (doesn't change logic) Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-9-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 24 +++++++++---------- drivers/net/wireless/realtek/rtw89/core.h | 5 +++- drivers/net/wireless/realtek/rtw89/mac80211.c | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 8ab15ee1b155..b074b3677c43 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -4625,7 +4625,7 @@ static void rtw89_core_ba_work(struct work_struct *work) "failed to setup BA session for %pM:%2d: %d\n", sta->addr, tid, ret); if (ret == -EINVAL) - set_bit(RTW89_TXQ_F_BLOCK_BA, &rtwtxq->flags); + set_bit(RTW89_TXQ_F_BLOCK_BA, rtwtxq->flags); } skip_ba_work: list_del_init(&rtwtxq->list); @@ -4658,7 +4658,7 @@ void rtw89_core_free_sta_pending_forbid_ba(struct rtw89_dev *rtwdev, struct ieee80211_txq *txq = rtw89_txq_to_txq(rtwtxq); if (sta == txq->sta) { - clear_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags); + clear_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags); list_del_init(&rtwtxq->list); } } @@ -4685,12 +4685,12 @@ static void rtw89_core_stop_tx_ba_session(struct rtw89_dev *rtwdev, if (unlikely(!rtwsta) || unlikely(rtwsta->disassoc)) return; - if (!test_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags) || - test_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags)) + if (!test_bit(RTW89_TXQ_F_AMPDU, rtwtxq->flags) || + test_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags)) return; spin_lock_bh(&rtwdev->ba_lock); - if (!test_and_set_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags)) + if (!test_and_set_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags)) list_add_tail(&rtwtxq->list, &rtwdev->forbid_ba_list); spin_unlock_bh(&rtwdev->ba_lock); @@ -4709,7 +4709,7 @@ static void rtw89_core_txq_check_agg(struct rtw89_dev *rtwdev, struct ieee80211_sta *sta = txq->sta; struct rtw89_sta *rtwsta = sta_to_rtwsta_safe(sta); - if (test_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags)) + if (test_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags)) return; if (unlikely(skb->protocol == cpu_to_be16(ETH_P_PAE))) { @@ -4720,10 +4720,10 @@ static void rtw89_core_txq_check_agg(struct rtw89_dev *rtwdev, if (unlikely(!sta)) return; - if (unlikely(test_bit(RTW89_TXQ_F_BLOCK_BA, &rtwtxq->flags))) + if (unlikely(test_bit(RTW89_TXQ_F_BLOCK_BA, rtwtxq->flags))) return; - if (test_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags)) { + if (test_bit(RTW89_TXQ_F_AMPDU, rtwtxq->flags)) { IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_AMPDU; return; } @@ -4901,7 +4901,7 @@ static void rtw89_forbid_ba_work(struct work_struct *w) spin_lock_bh(&rtwdev->ba_lock); list_for_each_entry_safe(rtwtxq, tmp, &rtwdev->forbid_ba_list, list) { - clear_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags); + clear_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags); list_del_init(&rtwtxq->list); } spin_unlock_bh(&rtwdev->ba_lock); @@ -6036,13 +6036,13 @@ static void _rtw89_core_set_tid_config(struct rtw89_dev *rtwdev, if (mask & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) { if (tid_conf->ampdu == NL80211_TID_CONFIG_ENABLE) { - clear_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags); + clear_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags); } else { - if (test_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags)) + if (test_bit(RTW89_TXQ_F_AMPDU, rtwtxq->flags)) ieee80211_stop_tx_ba_session(sta, txq->tid); spin_lock_bh(&rtwdev->ba_lock); list_del_init(&rtwtxq->list); - set_bit(RTW89_TXQ_F_FORBID_BA, &rtwtxq->flags); + set_bit(RTW89_TXQ_F_FORBID_BA, rtwtxq->flags); spin_unlock_bh(&rtwdev->ba_lock); } } diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index c300d15581fc..d725124b39bf 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -244,6 +244,8 @@ enum rtw89_txq_flags { RTW89_TXQ_F_AMPDU = 0, RTW89_TXQ_F_BLOCK_BA = 1, RTW89_TXQ_F_FORBID_BA = 2, + + NUM_OF_RTW89_TXQ_FLAGS, }; enum rtw89_net_type { @@ -1313,8 +1315,9 @@ struct rtw89_core_tx_request { struct rtw89_txq { struct list_head list; - unsigned long flags; int wait_cnt; + + DECLARE_BITMAP(flags, NUM_OF_RTW89_TXQ_FLAGS); }; struct rtw89_mac_ax_gnt { diff --git a/drivers/net/wireless/realtek/rtw89/mac80211.c b/drivers/net/wireless/realtek/rtw89/mac80211.c index c1be69a3c192..cf356a54d91c 100644 --- a/drivers/net/wireless/realtek/rtw89/mac80211.c +++ b/drivers/net/wireless/realtek/rtw89/mac80211.c @@ -1043,7 +1043,7 @@ static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw, case IEEE80211_AMPDU_TX_STOP_CONT: case IEEE80211_AMPDU_TX_STOP_FLUSH: case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: - clear_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags); + clear_bit(RTW89_TXQ_F_AMPDU, rtwtxq->flags); clear_bit(tid, rtwsta->ampdu_map); rtw89_chip_h2c_ampdu_cmac_tbl(rtwdev, rtwvif, rtwsta); ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); @@ -1051,7 +1051,7 @@ static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw, rtw89_phy_ra_recalc_agg_limit(rtwdev); break; case IEEE80211_AMPDU_TX_OPERATIONAL: - set_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags); + set_bit(RTW89_TXQ_F_AMPDU, rtwtxq->flags); rtwsta->ampdu_params[tid].agg_num = params->buf_size; rtwsta->ampdu_params[tid].amsdu = params->amsdu; set_bit(tid, rtwsta->ampdu_map); From 95f4fee98572a9489c12f447eaa924d00ac5a8f5 Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Wed, 9 Sep 2026 14:59:58 +0800 Subject: [PATCH 0536/2126] wifi: rtw89: 8922d: add extra data to PS H2C Append 2GHz regulatory mode and per-link BSS color to LPS multi-link H2C to assist firmware backup and restore the settings. Signed-off-by: Eric Huang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-10-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/fw.c | 44 +++++++++++++++++++++-- drivers/net/wireless/realtek/rtw89/fw.h | 17 +++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index d725124b39bf..e88942c469e4 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6023,6 +6023,7 @@ enum rtw89_fw_feature { RTW89_FW_FEATURE_SER_L1_BY_EVENT, RTW89_FW_FEATURE_SIM_SER_L0L1_BY_HALT_H2C, RTW89_FW_FEATURE_LPS_ML_INFO_V1, + RTW89_FW_FEATURE_LPS_ML_INFO_V1_EXTRA, RTW89_FW_FEATURE_SER_POST_RECOVER_DMAC, RTW89_FW_FEATURE_TX_HISTORY_V1, diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index dcbdf4b5e4b2..300686ed0f6e 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -983,6 +983,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = { __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 109, 1, SCAN_OFFLOAD_BE_V1), __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 113, 0, RFK_TXIQK_V0), __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 113, 2, SCAN_OFFLOAD_BE_V2), + __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 119, 0, LPS_ML_INFO_V1_EXTRA), }; static void rtw89_fw_iterate_feature_cfg(struct rtw89_fw_info *fw, @@ -3486,26 +3487,59 @@ void rtw89_bb_lps_cmn_info_rx_gain_fill(struct rtw89_dev *rtwdev, } } +static void +rtw89_fw_h2c_lps_ml_cmn_info_v1_extra_fill(struct rtw89_dev *rtwdev, + struct rtw89_vif *rtwvif, + struct rtw89_h2c_lps_ml_cmn_info_v1_extra *h2c) +{ + u8 regd = rtw89_regd_get(rtwdev, RTW89_BAND_2G); + struct ieee80211_bss_conf *bss_conf; + struct rtw89_vif_link *rtwvif_link; + unsigned int link_id; + + static_assert(sizeof(*h2c) % 4 == 0); + + h2c->regu_mode_on_24g = regd == RTW89_FCC ? RTW89_BB_REGULATION_FCC : + RTW89_BB_REGULATION_CE; + + rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id) { + u8 phy_idx = rtwvif_link->phy_idx; + + rcu_read_lock(); + bss_conf = rtw89_vif_rcu_dereference_link(rtwvif_link, true); + h2c->bss_color[phy_idx] = bss_conf->he_bss_color.color; + rcu_read_unlock(); + } +} + int rtw89_fw_h2c_lps_ml_cmn_info_v1(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) { static const u8 bcn_bw_ofst[] = {0, 0, 0, 3, 6, 9, 0, 12}; + struct rtw89_h2c_lps_ml_cmn_info_v1_extra *h2c_extra; const struct rtw89_chip_info *chip = rtwdev->chip; struct rtw89_efuse *efuse = &rtwdev->efuse; struct rtw89_h2c_lps_ml_cmn_info_v1 *h2c; struct rtw89_vif_link *rtwvif_link; const struct rtw89_chan *chan; struct rtw89_bb_ctx *bb; - u32 len = sizeof(*h2c); unsigned int link_id; struct sk_buff *skb; u8 beacon_bw_ofst; + bool has_extra; u32 done; + u32 len; int ret; if (chip->chip_gen != RTW89_CHIP_BE) return 0; + has_extra = RTW89_CHK_FW_FEATURE(LPS_ML_INFO_V1_EXTRA, &rtwdev->fw); + if (has_extra) + len = sizeof(*h2c_extra); + else + len = sizeof(*h2c); + skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); if (!skb) { rtw89_err(rtwdev, "failed to alloc skb for h2c lps_ml_cmn_info_v1\n"); @@ -3514,7 +3548,13 @@ int rtw89_fw_h2c_lps_ml_cmn_info_v1(struct rtw89_dev *rtwdev, skb_put(skb, len); h2c = (struct rtw89_h2c_lps_ml_cmn_info_v1 *)skb->data; - h2c->fmt_id = 0x20; + if (has_extra) { + h2c_extra = container_of(h2c, typeof(*h2c_extra), v1); + h2c->fmt_id = RTW89_H2C_LPS_ML_CMN_INFO_FMT_ID_V1_EXTRA; + rtw89_fw_h2c_lps_ml_cmn_info_v1_extra_fill(rtwdev, rtwvif, h2c_extra); + } else { + h2c->fmt_id = RTW89_H2C_LPS_ML_CMN_INFO_FMT_ID_V1; + } h2c->mlo_dbcc_mode = cpu_to_le32(rtwdev->mlo_dbcc_mode); h2c->rfe_type = efuse->rfe_type; diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 6cb1f6dfb650..d1bd82788376 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -2091,6 +2091,16 @@ struct rtw89_bb_link_info_rx_gain { u8 wb_g_elna[RTW89_BB_PS_LINK_RX_GAIN_TAB_MAX][BB_GT2_G_ELNA_NUM]; } __packed; +enum rtw89_bb_regulation_mode { + RTW89_BB_REGULATION_FCC = 0, + RTW89_BB_REGULATION_CE = 1, +}; + +enum rtw89_h2c_lps_ml_cmn_info_fmt_id { + RTW89_H2C_LPS_ML_CMN_INFO_FMT_ID_V1 = 0x20, + RTW89_H2C_LPS_ML_CMN_INFO_FMT_ID_V1_EXTRA = 0x21, +}; + struct rtw89_h2c_lps_ml_cmn_info_v1 { u8 fmt_id; u8 rfe_type; @@ -2106,6 +2116,13 @@ struct rtw89_h2c_lps_ml_cmn_info_v1 { struct rtw89_bb_link_info_rx_gain rx_gain[RTW89_BB_PS_LINK_BUF_MAX]; } __packed; +struct rtw89_h2c_lps_ml_cmn_info_v1_extra { + struct rtw89_h2c_lps_ml_cmn_info_v1 v1; + u8 regu_mode_on_24g; + u8 bss_color[RTW89_BB_PS_LINK_BUF_MAX]; + u8 rsvd[2]; +} __packed; + struct rtw89_h2c_phy_rfe_type { u8 rfe_type; u8 rsvd[3]; From 9db72f4caa21044499156c804bf1e8ad47271c82 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 9 Sep 2026 14:59:59 +0800 Subject: [PATCH 0537/2126] wifi: rtw89: mac: change beamformee CSI direct forward to CMAC_TXDMA Set R_BE_RESP_MODE register when initializing beamformee to makes CSI RX state machine enter initial state, and enables received beamformee CSI to be directly forwarded to CMAC_TXDMA via hardware shortcut path. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-11-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/mac_be.c | 3 +++ drivers/net/wireless/realtek/rtw89/reg.h | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/mac_be.c b/drivers/net/wireless/realtek/rtw89/mac_be.c index c8f343c8d545..fa35cafd7074 100644 --- a/drivers/net/wireless/realtek/rtw89/mac_be.c +++ b/drivers/net/wireless/realtek/rtw89/mac_be.c @@ -2786,6 +2786,9 @@ static int rtw89_mac_init_bfee_be(struct rtw89_dev *rtwdev, u8 mac_idx) B_BE_CSIPRT_HESU_AID_EN | B_BE_CSIPRT_EHTSU_AID_EN); + reg = rtw89_mac_reg_by_idx(rtwdev, R_BE_RESP_MODE, mac_idx); + rtw89_write32_set(rtwdev, reg, B_BE_INIT_CLEAR_RX_STATE | B_BE_SHORT_CUT_MODE); + reg = rtw89_mac_reg_by_idx(rtwdev, R_BE_TRXPTCL_RESP_CSI_RRSC, mac_idx); rtw89_write32(rtwdev, reg, CSI_RRSC_BMAP_BE); diff --git a/drivers/net/wireless/realtek/rtw89/reg.h b/drivers/net/wireless/realtek/rtw89/reg.h index 4291e8115f10..e85af8713777 100644 --- a/drivers/net/wireless/realtek/rtw89/reg.h +++ b/drivers/net/wireless/realtek/rtw89/reg.h @@ -8373,6 +8373,26 @@ #define B_BE_CSI_RESERVED_PAGE_NUM_MASK GENMASK(27, 16) #define B_BE_CSI_RESERVED_START_PAGE_MASK GENMASK(11, 0) +#define R_BE_RESP_MODE 0x11814 +#define R_BE_RESP_MODE_C1 0x15814 +#define B_BE_LMR_MASK_PRE_ENQ BIT(27) +#define B_BE_LMR_INIT_CLEAR_RX_STATE BIT(26) +#define B_BE_LMR_SHORT_CUT_MODE BIT(25) +#define B_BE_LMR_IMMED_ENQ_MODE BIT(24) +#define B_BE_CLEAR_SMR_SEG_TBL BIT(19) +#define B_BE_CLEAR_FTM_SEG_TBL BIT(18) +#define B_BE_CLEAR_CSI_SEG_TBL BIT(17) +#define B_BE_CLEAR_CSI_RESP_TBL BIT(16) +#define B_BE_SMR_MASK_PRE_ENQ BIT(12) +#define B_BE_SMR_DELAY_IMMED_ENQ_MODE BIT(11) +#define B_BE_SMR_INIT_CLEAR_RX_STATE BIT(10) +#define B_BE_SMR_SHORT_CUT_MODE BIT(9) +#define B_BE_SMR_IMMED_ENQ_MODE BIT(8) +#define B_BE_CSI_MASK_PRE_ENQ BIT(3) +#define B_BE_INIT_CLEAR_RX_STATE BIT(2) +#define B_BE_SHORT_CUT_MODE BIT(1) +#define B_BE_IMMED_ENQ_MODE BIT(0) + #define R_BE_RESP_IMR1 0x11878 #define R_BE_RESP_IMR1_C1 0x15878 #define B_BE_RESP_IMR_1_MASK GENMASK(31, 9) From 74f50393f3f3f142c4a0ecd4d1278d887b1c9960 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 9 Sep 2026 15:00:00 +0800 Subject: [PATCH 0538/2126] wifi: rtw89: fw: extend ch_info format of hw_scan to v2 The new format of ch_info is extended from 8 words to 9 words to have additional control probe delay on 6GHz band, but not implement these fields for now. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-12-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/fw.c | 27 +++++++++++++++++++---- drivers/net/wireless/realtek/rtw89/fw.h | 6 ++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index e88942c469e4..3caef61b21d3 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6011,6 +6011,7 @@ enum rtw89_fw_feature { RTW89_FW_FEATURE_NO_WOW_CPU_IO_RX, RTW89_FW_FEATURE_NOTIFY_AP_INFO, RTW89_FW_FEATURE_CH_INFO_BE_V0, + RTW89_FW_FEATURE_CH_INFO_BE_V1, RTW89_FW_FEATURE_LPS_CH_INFO, RTW89_FW_FEATURE_NO_PHYCAP_P1, RTW89_FW_FEATURE_NO_POWER_DIFFERENCE, diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 300686ed0f6e..9eaace2d57c4 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -967,6 +967,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = { __CFG_FW_FEAT(RTL8922A, ge, 0, 35, 108, 0, SIM_SER_L0L1_BY_HALT_H2C), __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 109, 1, SCAN_OFFLOAD_BE_V1), __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 113, 2, SCAN_OFFLOAD_BE_V2), + __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 119, 0, CH_INFO_BE_V1), __CFG_FW_FEAT(RTL8922D, ge, 0, 0, 0, 0, MACID_PAUSE_SLEEP), __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 75, 2, SCAN_OFFLOAD), __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 75, 2, BEACON_FILTER), @@ -984,6 +985,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = { __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 113, 0, RFK_TXIQK_V0), __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 113, 2, SCAN_OFFLOAD_BE_V2), __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 119, 0, LPS_ML_INFO_V1_EXTRA), + __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 119, 0, CH_INFO_BE_V1), }; static void rtw89_fw_iterate_feature_cfg(struct rtw89_fw_info *fw, @@ -7615,24 +7617,34 @@ int rtw89_fw_h2c_scan_list_offload_be(struct rtw89_dev *rtwdev, int ch_num, struct rtw89_h2c_chinfo_elem_be *elem; struct rtw89_mac_chinfo_be *ch_info; struct rtw89_h2c_chinfo_be *h2c; + u8 elem_size = sizeof(*elem); bool wildcard_by_drv; struct sk_buff *skb; unsigned int cond; u8 ver = U8_MAX; + int used_len; int skb_len; int ret; static_assert(sizeof(*elem) == RTW89_MAC_CHINFO_SIZE_BE); skb_len = struct_size(h2c, elem, ch_num); + used_len = skb_len; skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, skb_len); if (!skb) { rtw89_err(rtwdev, "failed to alloc skb for h2c scan list\n"); return -ENOMEM; } - if (RTW89_CHK_FW_FEATURE(CH_INFO_BE_V0, &rtwdev->fw)) + if (RTW89_CHK_FW_FEATURE(CH_INFO_BE_V0, &rtwdev->fw)) { ver = 0; + elem_size = offsetofend(typeof(*elem), w7); + used_len = sizeof(*h2c) + elem_size * ch_num; + } else if (RTW89_CHK_FW_FEATURE(CH_INFO_BE_V1, &rtwdev->fw)) { + ver = 1; + elem_size = offsetofend(typeof(*elem), w7); + used_len = sizeof(*h2c) + elem_size * ch_num; + } wildcard_by_drv = !(RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD_BE_V0, &rtwdev->fw) || RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD_BE_V1, &rtwdev->fw) || @@ -7642,14 +7654,14 @@ int rtw89_fw_h2c_scan_list_offload_be(struct rtw89_dev *rtwdev, int ch_num, h2c = (struct rtw89_h2c_chinfo_be *)skb->data; h2c->ch_num = ch_num; - h2c->elem_size = sizeof(*elem) / 4; /* in unit of 4 bytes */ + h2c->elem_size = elem_size / 4; /* in unit of 4 bytes */ h2c->arg = u8_encode_bits(rtwvif_link->mac_idx, RTW89_H2C_CHINFO_ARG_MAC_IDX_MASK); list_for_each_entry(ch_info, chan_list, list) { bool with_probe_id = ch_info->probe_id != RTW89_SCANOFLD_PKT_NONE; - elem = (struct rtw89_h2c_chinfo_elem_be *)skb_put(skb, sizeof(*elem)); + elem = (struct rtw89_h2c_chinfo_elem_be *)skb_put(skb, elem_size); elem->w0 = le32_encode_bits(ch_info->dwell_time, RTW89_H2C_CHINFO_BE_W0_DWELL) | le32_encode_bits(ch_info->central_ch, @@ -7704,11 +7716,16 @@ int rtw89_fw_h2c_scan_list_offload_be(struct rtw89_dev *rtwdev, int ch_num, else elem->w7 = le32_encode_bits(ch_info->period, RTW89_H2C_CHINFO_BE_W7_PERIOD_V1); + + if (ver < 2) + continue; + + elem->w8 = 0; } rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, H2C_CAT_MAC, H2C_CL_MAC_FW_OFLD, - H2C_FUNC_ADD_SCANOFLD_CH, 1, 1, skb_len); + H2C_FUNC_ADD_SCANOFLD_CH, 1, 1, used_len); cond = RTW89_SCANOFLD_WAIT_COND_ADD_CH; @@ -7929,6 +7946,8 @@ int rtw89_fw_h2c_scan_offload_be(struct rtw89_dev *rtwdev, if (RTW89_CHK_FW_FEATURE(CH_INFO_BE_V0, &rtwdev->fw)) ver = 0; + else if (RTW89_CHK_FW_FEATURE(CH_INFO_BE_V1, &rtwdev->fw)) + ver = 1; h2c->w0 = le32_encode_bits(option->operation, RTW89_H2C_SCANOFLD_BE_W0_OP) | le32_encode_bits(option->scan_mode, diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index d1bd82788376..d64435ffbf78 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -342,7 +342,7 @@ struct rtw89_fw_macid_pause_sleep_grp { #define RTW89_SCANOFLD_DEBUG_MASK 0x1F #define RTW89_CHAN_INVALID 0xFF #define RTW89_MAC_CHINFO_SIZE 28 -#define RTW89_MAC_CHINFO_SIZE_BE 32 +#define RTW89_MAC_CHINFO_SIZE_BE 36 #define RTW89_SCAN_LIST_GUARD 4 #define RTW89_SCAN_LIST_LIMIT(size) \ ((RTW89_H2C_MAX_SIZE / (size)) - RTW89_SCAN_LIST_GUARD) @@ -3009,6 +3009,7 @@ struct rtw89_h2c_chinfo_elem_be { __le32 w5; __le32 w6; __le32 w7; + __le32 w8; /* after CH_INFO_BE_V1 */ } __packed; #define RTW89_H2C_CHINFO_BE_W0_PERIOD GENMASK(7, 0) @@ -3041,6 +3042,9 @@ struct rtw89_h2c_chinfo_elem_be { #define RTW89_H2C_CHINFO_BE_W6_FW_PROBE0_SHORTSSIDS GENMASK(15, 0) #define RTW89_H2C_CHINFO_BE_W6_FW_PROBE0_BSSIDS GENMASK(31, 16) #define RTW89_H2C_CHINFO_BE_W7_PERIOD_V1 GENMASK(15, 0) +#define RTW89_H2C_CHINFO_BE_W7_SSIDS_IGN_DELAY_V2 GENMASK(31, 16) +#define RTW89_H2C_CHINFO_BE_W8_SHORTSSIDS_IGN_DELAY_V2 GENMASK(15, 0) +#define RTW89_H2C_CHINFO_BE_W8_BSSIDS_IGN_DELAY_V2 GENMASK(31, 16) struct rtw89_h2c_chinfo { u8 ch_num; From 31f222ebee23f0aa8f9a89edb07f1f6201de4b45 Mon Sep 17 00:00:00 2001 From: Dian-Syuan Yang Date: Wed, 9 Sep 2026 15:00:01 +0800 Subject: [PATCH 0539/2126] wifi: rtw89: 8922d: update BA cam format to G7 Initially, Wi-Fi 7 chips utilized the V1 format, but the 8922DE is expected to use the G7 format. This format differs from V1 into that STD_ENTRY_EN, BAND_SEL, and MLD_EN are moved into W0, and MACID is widened to 10-bit and relocated to W1. Signed-off-by: Dian-Syuan Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-13-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/fw.c | 80 +++++++++++++++++++ drivers/net/wireless/realtek/rtw89/fw.h | 21 +++++ drivers/net/wireless/realtek/rtw89/mac.c | 3 +- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 4 +- 5 files changed, 106 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 3caef61b21d3..2e6d1be3a751 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -212,6 +212,7 @@ enum rtw89_cv { enum rtw89_bacam_ver { RTW89_BACAM_V0, RTW89_BACAM_V1, + RTW89_BACAM_G7, RTW89_BACAM_V0_EXT = 99, }; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 9eaace2d57c4..63dd918b0989 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -2820,6 +2820,86 @@ fail: } EXPORT_SYMBOL(rtw89_fw_h2c_ba_cam_v1); +int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, + struct rtw89_vif_link *rtwvif_link, + struct rtw89_sta_link *rtwsta_link, + bool valid, struct ieee80211_ampdu_params *params) +{ + const struct rtw89_chip_info *chip = rtwdev->chip; + struct rtw89_h2c_ba_cam_g7 *h2c; + u16 macid = rtwsta_link->mac_id; + u32 len = sizeof(*h2c); + struct sk_buff *skb; + u8 entry_idx; + u8 bmap_size; + int ret; + + ret = valid ? + rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + &entry_idx) : + rtw89_core_release_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + &entry_idx); + if (ret) { + /* + * it still works even if we don't have static BA CAM, because + * hardware can create dynamic BA CAM automatically. + */ + rtw89_debug(rtwdev, RTW89_DBG_TXRX, + "failed to %s entry tid=%d for h2c ba cam\n", + valid ? "alloc" : "free", params->tid); + return 0; + } + + skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); + if (!skb) { + rtw89_err(rtwdev, "failed to alloc skb for h2c ba cam\n"); + return -ENOMEM; + } + skb_put(skb, len); + h2c = (struct rtw89_h2c_ba_cam_g7 *)skb->data; + + if (params->buf_size > 512) + bmap_size = 10; + else if (params->buf_size > 256) + bmap_size = 8; + else if (params->buf_size > 64) + bmap_size = 4; + else + bmap_size = 0; + + h2c->w0 = le32_encode_bits(valid, RTW89_H2C_BA_CAM_G7_W0_VALID) | + le32_encode_bits(1, RTW89_H2C_BA_CAM_G7_W0_INIT_REQ) | + le32_encode_bits(params->tid, RTW89_H2C_BA_CAM_G7_W0_TID_MASK) | + le32_encode_bits(1, RTW89_H2C_BA_CAM_G7_W0_STD_ENTRY_EN) | + le32_encode_bits(!!rtwvif_link->mac_idx, + RTW89_H2C_BA_CAM_G7_W0_BAND_SEL) | + le32_encode_bits(bmap_size, RTW89_H2C_BA_CAM_G7_W0_BMAP_SIZE_MASK) | + le32_encode_bits(params->ssn, RTW89_H2C_BA_CAM_G7_W0_SSN_MASK); + + entry_idx += chip->bacam_dynamic_num; /* std entry right after dynamic ones */ + h2c->w1 = le32_encode_bits(macid, RTW89_H2C_BA_CAM_G7_W1_MACID_MASK) | + le32_encode_bits(entry_idx, RTW89_H2C_BA_CAM_G7_W1_ENTRY_IDX_MASK); + + rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, + H2C_CAT_MAC, + H2C_CL_BA_CAM, + H2C_FUNC_MAC_BA_CAM_V1, 0, 1, + len); + + ret = rtw89_h2c_tx(rtwdev, skb, false); + if (ret) { + rtw89_err(rtwdev, "failed to send h2c\n"); + goto fail; + } + + return 0; +fail: + dev_kfree_skb_any(skb); + + return ret; +} +EXPORT_SYMBOL(rtw89_fw_h2c_ba_cam_g7); + int rtw89_fw_h2c_init_ba_cam_users(struct rtw89_dev *rtwdev, u8 users, u8 offset, u8 mac_idx) { diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index d64435ffbf78..a15a5967cabc 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -1956,6 +1956,23 @@ struct rtw89_h2c_ba_cam_v1 { #define RTW89_H2C_BA_CAM_V1_W1_MLD_EN BIT(10) #define RTW89_H2C_BA_CAM_V1_W1_ENTRY_IDX_MASK GENMASK(31, 24) +struct rtw89_h2c_ba_cam_g7 { + __le32 w0; + __le32 w1; +} __packed; + +#define RTW89_H2C_BA_CAM_G7_W0_VALID BIT(0) +#define RTW89_H2C_BA_CAM_G7_W0_INIT_REQ BIT(1) +#define RTW89_H2C_BA_CAM_G7_W0_TID_MASK GENMASK(7, 4) +#define RTW89_H2C_BA_CAM_G7_W0_STD_ENTRY_EN BIT(8) +#define RTW89_H2C_BA_CAM_G7_W0_BAND_SEL BIT(9) +#define RTW89_H2C_BA_CAM_G7_W0_MLD_EN BIT(10) +#define RTW89_H2C_BA_CAM_G7_W0_BMAP_SIZE_MASK GENMASK(19, 16) +#define RTW89_H2C_BA_CAM_G7_W0_SSN_MASK GENMASK(31, 20) +#define RTW89_H2C_BA_CAM_G7_W1_UID_VALUE_MASK GENMASK(7, 0) +#define RTW89_H2C_BA_CAM_G7_W1_MACID_MASK GENMASK(17, 8) +#define RTW89_H2C_BA_CAM_G7_W1_ENTRY_IDX_MASK GENMASK(31, 24) + struct rtw89_h2c_ba_cam_init { __le32 w0; } __packed; @@ -5584,6 +5601,10 @@ int rtw89_fw_h2c_ba_cam_v1(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_link, struct rtw89_sta_link *rtwsta_link, bool valid, struct ieee80211_ampdu_params *params); +int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, + struct rtw89_vif_link *rtwvif_link, + struct rtw89_sta_link *rtwsta_link, + bool valid, struct ieee80211_ampdu_params *params); void rtw89_fw_h2c_init_dynamic_ba_cam_v0_ext(struct rtw89_dev *rtwdev); int rtw89_fw_h2c_init_ba_cam_users(struct rtw89_dev *rtwdev, u8 users, u8 offset, u8 mac_idx); diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c index df396fbfca26..093291e8854d 100644 --- a/drivers/net/wireless/realtek/rtw89/mac.c +++ b/drivers/net/wireless/realtek/rtw89/mac.c @@ -4087,7 +4087,8 @@ static int rtw89_mac_feat_init(struct rtw89_dev *rtwdev) const struct rtw89_chip_info *chip = rtwdev->chip; u8 users, offset; - if (chip->bacam_ver != RTW89_BACAM_V1) + if (!(chip->bacam_ver == RTW89_BACAM_V1 || + chip->bacam_ver == RTW89_BACAM_G7)) return 0; offset = 0; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 89c1f58d0dc0..2325e646c487 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -3712,7 +3712,7 @@ static const struct rtw89_chip_ops rtw8922d_chip_ops = { .h2c_punctured_cmac_tbl = rtw89_fw_h2c_punctured_cmac_tbl_be, .h2c_default_dmac_tbl = rtw89_fw_h2c_default_dmac_tbl_v3, .h2c_update_beacon = rtw89_fw_h2c_update_beacon_be, - .h2c_ba_cam = rtw89_fw_h2c_ba_cam_v1, + .h2c_ba_cam = rtw89_fw_h2c_ba_cam_g7, .h2c_wow_cam_update = rtw89_fw_h2c_wow_cam_update_v1, .btc_set_rfe = rtw8922d_btc_set_rfe, @@ -3807,7 +3807,7 @@ const struct rtw89_chip_info rtw8922d_chip_info = { .scam_num = 32, .bacam_num = 24, .bacam_dynamic_num = 8, - .bacam_ver = RTW89_BACAM_V1, + .bacam_ver = RTW89_BACAM_G7, .addrcam_ver = 1, .ppdu_max_usr = 16, .sec_ctrl_efuse_size = 4, From 5a2a6b9e092d67d3d93a409299e03a7026ec6965 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 9 Sep 2026 15:00:02 +0800 Subject: [PATCH 0540/2126] wifi: rtw89: 8851b: rfk: set DCK start and delay time Modify the DCK delay time and add the TSSI TX start time to bring more accurate TSSI detection, which helps thermal tracking to compensate output power correctly. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-14-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8851b_rfk_table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk_table.c b/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk_table.c index c5f70c045692..beae5749d07d 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk_table.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8851b_rfk_table.c @@ -272,7 +272,8 @@ static const struct rtw89_reg5_def rtw8851b_tssi_dck_defs_a[] = { RTW89_DECL_RFK_WM(0x5814, 0x00002000, 0x1), RTW89_DECL_RFK_WM(0x5814, 0x00004000, 0x1), RTW89_DECL_RFK_WM(0x5814, 0x00038000, 0x3), - RTW89_DECL_RFK_WM(0x5814, 0x003c0000, 0x5), + RTW89_DECL_RFK_WM(0x0620, 0x00003f00, 0x17), + RTW89_DECL_RFK_WM(0x5814, 0x003c0000, 0x7), RTW89_DECL_RFK_WM(0x5814, 0x18000000, 0x0), }; From 0bd0557aefe635e5ffaeca86631362818aa86098 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 9 Sep 2026 15:00:03 +0800 Subject: [PATCH 0541/2126] wifi: rtw89: 8852b: update default value for ANA SWR The RTL8852BE randomly card drops on certain platforms. Adjust ANA_SWR behavior by compensation parameters to stabilize the switching regulator output to prevent unwanted drop. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-15-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/reg.h | 2 +- drivers/net/wireless/realtek/rtw89/rtw8852b.c | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/reg.h b/drivers/net/wireless/realtek/rtw89/reg.h index e85af8713777..11b30be8f880 100644 --- a/drivers/net/wireless/realtek/rtw89/reg.h +++ b/drivers/net/wireless/realtek/rtw89/reg.h @@ -265,7 +265,7 @@ #define R_AX_SPSANA_ON_CTRL1 0x0224 #define R_AX_SPS_ANA_ON_CTRL2 0x0228 -#define RTL8852B_RFE_05_SPS_ANA 0x4A82 +#define RTL8852B_DEFAULT_SPS_ANA 0x4F42 #define R_AX_WLAN_XTAL_SI_CTRL 0x0270 #define B_AX_WL_XTAL_SI_CMD_POLL BIT(31) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852b.c b/drivers/net/wireless/realtek/rtw89/rtw8852b.c index 356623341f65..c3c53a6b8119 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852b.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852b.c @@ -355,10 +355,7 @@ static const u8 rtw89_btc_8852b_bt_rssi_thres[BTC_BT_RSSI_THMAX] = {50, 40, 30, static void rtw8852b_pwr_sps_ana(struct rtw89_dev *rtwdev) { - struct rtw89_efuse *efuse = &rtwdev->efuse; - - if (efuse->rfe_type == 0x5) - rtw89_write16(rtwdev, R_AX_SPS_ANA_ON_CTRL2, RTL8852B_RFE_05_SPS_ANA); + rtw89_write16(rtwdev, R_AX_SPS_ANA_ON_CTRL2, RTL8852B_DEFAULT_SPS_ANA); } static void rtw8852b_pwr_sps_dig_off(struct rtw89_dev *rtwdev) From 6894826d9a5129d184db6ee53347fb4151a74346 Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Wed, 9 Sep 2026 15:00:04 +0800 Subject: [PATCH 0542/2126] wifi: rtw89: phy: correct PHY-1 EDCCA report register access RTL8922D fills the PHY-1 rpt_b entry with the address of rpt_a. The report select of RTL8922A and RTL8922D has a per-PHY instance, but it was written without the PHY index, so PHY-1 read its report registers through the select of PHY-0. Write it with rtw89_phy_write32_idx() instead. Signed-off-by: Eric Huang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909070004.35353-16-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/phy.c | 12 ++++++------ drivers/net/wireless/realtek/rtw89/rtw8922d.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index c33b888bc0e3..074865665b16 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -8712,8 +8712,8 @@ static void rtw89_phy_edcca_log(struct rtw89_dev *rtwdev, struct rtw89_bb_ctx *b rtw89_phy_write32_mask(rtwdev, edcca_p_regs->rpt_sel, edcca_p_regs->rpt_sel_mask, 0); if (rtwdev->chip->chip_id == RTL8922A || rtwdev->chip->chip_id == RTL8922D) { - rtw89_phy_write32_mask(rtwdev, edcca_regs->rpt_sel_be, - edcca_regs->rpt_sel_be_mask, 0); + rtw89_phy_write32_idx(rtwdev, edcca_regs->rpt_sel_be, + edcca_regs->rpt_sel_be_mask, 0, bb->phy_idx); per20_bitmap = rtw89_phy_read32_mask(rtwdev, edcca_p_regs->rpt_a, MASKBYTE0); } @@ -8738,16 +8738,16 @@ static void rtw89_phy_edcca_log(struct rtw89_dev *rtwdev, struct rtw89_bb_ctx *b pwdb_s40 = u32_get_bits(tmp, MASKBYTE2); if (rtwdev->chip->chip_id == RTL8922A || rtwdev->chip->chip_id == RTL8922D) { - rtw89_phy_write32_mask(rtwdev, edcca_regs->rpt_sel_be, - edcca_regs->rpt_sel_be_mask, 4); + rtw89_phy_write32_idx(rtwdev, edcca_regs->rpt_sel_be, + edcca_regs->rpt_sel_be_mask, 4, bb->phy_idx); tmp = rtw89_phy_read32(rtwdev, edcca_p_regs->rpt_b); pwdb[0] = u32_get_bits(tmp, MASKBYTE3); pwdb[1] = u32_get_bits(tmp, MASKBYTE2); pwdb[2] = u32_get_bits(tmp, MASKBYTE1); pwdb[3] = u32_get_bits(tmp, MASKBYTE0); - rtw89_phy_write32_mask(rtwdev, edcca_regs->rpt_sel_be, - edcca_regs->rpt_sel_be_mask, 5); + rtw89_phy_write32_idx(rtwdev, edcca_regs->rpt_sel_be, + edcca_regs->rpt_sel_be_mask, 5, bb->phy_idx); tmp = rtw89_phy_read32(rtwdev, edcca_p_regs->rpt_b); pwdb[4] = u32_get_bits(tmp, MASKBYTE3); pwdb[5] = u32_get_bits(tmp, MASKBYTE2); diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 2325e646c487..41e2aa1c8f78 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -271,7 +271,7 @@ static const struct rtw89_edcca_regs rtw8922d_edcca_regs = { .rpt_sel_mask = B_EDCCA_RPT_SEL_BE4_MSK, }, { .rpt_a = R_EDCCA_RPT_A_BE4_C1, - .rpt_b = R_EDCCA_RPT_A_BE4_C1, + .rpt_b = R_EDCCA_RPT_B_BE4_C1, .rpt_sel = R_EDCCA_RPT_SEL_BE4_C1, .rpt_sel_mask = B_EDCCA_RPT_SEL_BE4_MSK, }}, From 673662a0411e091ae3152b5b54ba5f7c069548eb Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:50 +0200 Subject: [PATCH 0543/2126] wifi: rtw88: add the RTL8723B chip type and SDIO helper The RTL8723B is a 802.11n combo chip whose SDIO variant, RTL8723BS, runs a Realtek vendor firmware that differs from the firmware used by the other rtw88 8723 family devices. Supporting it needs a number of small adjustments spread across the shared core, all of which have to be restricted to this one chip and bus combination. Add the chip type and a helper that tests for it, so the changes that follow can be gated without repeating the chip and bus comparison. Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-2-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/main.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h index 6883fbd9f768..d59f6e323adf 100644 --- a/drivers/net/wireless/realtek/rtw88/main.h +++ b/drivers/net/wireless/realtek/rtw88/main.h @@ -194,6 +194,7 @@ enum rtw_chip_type { RTW_CHIP_TYPE_8723D, RTW_CHIP_TYPE_8821C, RTW_CHIP_TYPE_8703B, + RTW_CHIP_TYPE_8723B, RTW_CHIP_TYPE_8821A, RTW_CHIP_TYPE_8812A, RTW_CHIP_TYPE_8814A, @@ -2195,6 +2196,12 @@ static inline bool rtw_chip_has_tx_stbc(struct rtw_dev *rtwdev) return rtwdev->chip->tx_stbc; } +static inline bool rtw_is_8723bs(struct rtw_dev *rtwdev) +{ + return rtwdev->chip->id == RTW_CHIP_TYPE_8723B && + rtwdev->hci.type == RTW_HCI_TYPE_SDIO; +} + static inline u8 rtw_acquire_macid(struct rtw_dev *rtwdev) { unsigned long mac_id; From 5f92fb99345664ece26a68c1ea0863645b927197 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:51 +0200 Subject: [PATCH 0544/2126] wifi: rtw88: rx: mark zero length packets on RTL8723BS Like the RTL8703B, the RTL8723BS reports receive descriptors with a zero packet length, which the vendor driver drops outright. rtw88 already flags these as having no PSDU for the RTL8703B, so extend the same handling rather than passing an empty frame up. This is gated on the SDIO interface rather than the chip id, because it has only been observed there; the USB variant is not known to do it. Co-developed-by: Michael Straube Signed-off-by: Michael Straube Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-3-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/rx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/rx.c b/drivers/net/wireless/realtek/rtw88/rx.c index 01fd299abb7f..fde21c840ac0 100644 --- a/drivers/net/wireless/realtek/rtw88/rx.c +++ b/drivers/net/wireless/realtek/rtw88/rx.c @@ -253,10 +253,12 @@ static void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev, rtw_rx_addr_match(rtwdev, pkt_stat, hdr); - /* Rtl8723cs driver checks for size < 14 or size > 8192 and - * simply drops the packet. + /* + * Rtl8723cs and rtl8723bs drivers check for size < 14 or size > 8192 + * and simply drop the packet. */ - if (rtwdev->chip->id == RTW_CHIP_TYPE_8703B && pkt_stat->pkt_len == 0) { + if (pkt_stat->pkt_len == 0 && + (rtwdev->chip->id == RTW_CHIP_TYPE_8703B || rtw_is_8723bs(rtwdev))) { rx_status->flag |= RX_FLAG_NO_PSDU; rtw_dbg(rtwdev, RTW_DBG_RX, "zero length packet"); } From 4d688f22ebbf15b585bb748a87891295e6f57720 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:52 +0200 Subject: [PATCH 0545/2126] wifi: rtw88: tx: extend the TX report purge timeout to RTL8723BS Commit c80788f7c5ae ("wifi: rtw88: increase TX report timeout to fix race condition") raised the purge timeout to 2500 ms for the RTL8723DU, because the firmware can stay off channel during background scans for longer than the 500 ms default, which delays the TX reports and lets the purge timer drop the tracking skbs. The host stack then reads the missing status as loss and collapses TCP throughput. The RTL8723BS runs the same vendor firmware over a slower SDIO host and hits the same race. Testers on ARM SDIO boards see "failed to get tx report from firmware" under load, with the same throughput collapse. Extend the 2500 ms timeout to the RTL8723BS. Reported-by: Peter Robinson Closes: https://lore.kernel.org/all/CALeDE9PgQmpMfDt1DgfLD4tBFGH0MZ7GncV6RUEOHhHbKF+TdQ@mail.gmail.com/ Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-4-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/tx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c index 8786bbb421c2..4e110a457e71 100644 --- a/drivers/net/wireless/realtek/rtw88/tx.c +++ b/drivers/net/wireless/realtek/rtw88/tx.c @@ -208,8 +208,9 @@ void rtw_tx_report_enqueue(struct rtw_dev *rtwdev, struct sk_buff *skb, u8 sn) __skb_queue_tail(&tx_report->queue, skb); spin_unlock_irqrestore(&tx_report->q_lock, flags); - if (rtwdev->chip->id == RTW_CHIP_TYPE_8723D && - rtwdev->hci.type == RTW_HCI_TYPE_USB) + if ((rtwdev->chip->id == RTW_CHIP_TYPE_8723D && + rtwdev->hci.type == RTW_HCI_TYPE_USB) || + rtw_is_8723bs(rtwdev)) timeout = msecs_to_jiffies(2500); mod_timer(&tx_report->purge_timer, jiffies + timeout); From b81ead28aeb1fd9bc3b0de4e20342b6b538ac658 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:53 +0200 Subject: [PATCH 0546/2126] wifi: rtw88: sdio: zero the padding added to a TX transfer rtw_sdio_write_port() rounds the transfer up with sdio_align_size() and then hands that length to sdio_memcpy_toio() while the skb still only holds skb->len bytes. The difference, between one and 511 bytes, is read from beyond the end of the frame and transmitted. Whether it stays inside the skb's allocation depends on how much tailroom the skb happens to have, so this is at best sending uninitialised memory over the air. Pad the skb up to the transfer size first. __skb_pad() zeroes the added bytes, reallocates a cloned skb rather than writing into a buffer a clone still shares, and leaves skb->len alone, so nothing else in the transmit path has to change. It must not free the skb on failure: rtw_sdio_write_data() frees the skb itself and rtw_sdio_process_tx_queue() requeues it, so both callers still own it and would double free. Found while reworking this path for the RTL8723BS. Measured on RTL8723BS hardware, padding the transfer costs about 2% observable over transfer: uplink is 19.5 to 19.8 Mbit/s padded against 20.9 to 21.1 Mbit/s unpadded in an interleaved A/B, with scans, reconnection and a UDP flood clean in both. The other SDIO parts sharing this path are untested; I have only the RTL8723BS. Fixes: 65371a3f14e7 ("wifi: rtw88: sdio: Add HCI implementation for SDIO based chipsets") Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-5-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/sdio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index 5b40d74b16ee..8466abad972a 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -636,6 +636,7 @@ static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb, enum rtw_tx_queue_type queue) { struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + size_t pad_size; bool bus_claim; size_t txsize; u32 txaddr; @@ -646,6 +647,17 @@ static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb, return -EINVAL; txsize = sdio_align_size(rtwsdio->sdio_func, skb->len); + pad_size = txsize - skb->len; + + if (pad_size > 0) { + /* + * __skb_pad() must not free the skb on failure: both callers + * still own it, one requeues it and the other frees it. + */ + ret = __skb_pad(skb, pad_size, false); + if (ret) + return ret; + } ret = rtw_sdio_check_free_txpg(rtwdev, queue, txsize); if (ret) From 5a95bd4601759496dde9c63d420765759d94b103 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:54 +0200 Subject: [PATCH 0547/2126] wifi: rtw88: sdio: track free TX pages and OQT credits for RTL8723BS The RTL8723BS reports free TX page counts that the generic 8051 path reads back from the chip on every transfer, which is both slow over SDIO and unreliable on this part: the register frequently reads back zero while pages are in fact available. It also gates transmission on a free count in the SDIO output queue, REG_SDIO_OQT_FREE_PG, which rtw88 does not track at all. The vendor driver calls this the OQT free space and never expands the acronym; the register holds the number of further transfers the SDIO output queue can accept, and the chip discards writes that arrive when it has run out. Mirror the vendor driver and keep the per-queue and public page counts in software, seeded at start and resynchronised from the chip only when the cached counts say there is not enough room. Wait for a free output queue entry before writing, and account for the pages consumed after a successful transfer. rtw_sdio_write_port() becomes a dispatcher. It works out the transfer address and the aligned transfer size, which both paths need, and hands them to rtw_sdio_write_port_8723bs() or rtw_sdio_write_port_generic(). The transfer itself moves into rtw_sdio_write_to_port(), which both call, so the generic path is step for step what it was. The padding added by the previous patch stays in rtw_sdio_write_port(), so it still runs once for both paths and stays outside the credit mutex. The RTL8723BS path keeps a separate length for the accounting. The chip charges pages by the frame length rather than by the padded transfer, as the vendor driver does, and the two differ just above a block boundary: a 1025 byte frame is nine pages by length and twelve by the padded size. The check, the output queue wait and the accounting are serialised by a mutex. The TX worker and the H2C path reach this function concurrently, and two writers that both pass the checks can otherwise claim the same pages and output queue entry, after which the chip silently discards whichever transfer arrives second. The vendor driver avoids the same race by funnelling all transmission through one thread. Measured on RTL8723BS hardware against an iperf3 server one hop behind the AP, with the wlan0 byte counters as ground truth. On the generic path the association completes but no data passes at all: TCP and UDP both measure 0 bit/s in either direction. With this patch TCP is 25.3 Mbit/s up and 37.3 Mbit/s down, and UDP is 25.0 Mbit/s up at 0% loss. Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-6-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/sdio.c | 351 ++++++++++++++++++++-- drivers/net/wireless/realtek/rtw88/sdio.h | 12 + 2 files changed, 335 insertions(+), 28 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index 8466abad972a..0dc1277619f6 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -20,6 +20,7 @@ #include "tx.h" #define RTW_SDIO_INDIRECT_RW_RETRIES 50 +#define RTW_SDIO_OQT_TIMEOUT_MS 1000 static bool rtw_sdio_is_bus_addr(u32 addr) { @@ -548,12 +549,149 @@ static int rtw_sdio_read_port(struct rtw_dev *rtwdev, u8 *buf, size_t count) return ret; } +/* + * The counters are atomic_t because rtw_sdio_start() seeds them outside + * tx_credit_lock, which the transmit paths hold while using them. + */ +static void rtw_sdio_8723bs_store_free_txpg(struct rtw_dev *rtwdev, + u32 free_txpg) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + + atomic_set(&rtwsdio->free_pg_high, + u32_get_bits(free_txpg, BIT_FREE_TXPG_HIGH)); + atomic_set(&rtwsdio->free_pg_normal, + u32_get_bits(free_txpg, BIT_FREE_TXPG_NORMAL)); + atomic_set(&rtwsdio->free_pg_low, + u32_get_bits(free_txpg, BIT_FREE_TXPG_LOW)); + atomic_set(&rtwsdio->free_pg_pub, + u32_get_bits(free_txpg, BIT_FREE_TXPG_PUB)); +} + +static bool rtw_sdio_8723bs_sync_free_txpg(struct rtw_dev *rtwdev) +{ + u32 free_txpg = rtw_read32(rtwdev, REG_SDIO_FREE_TXPG); + + if (!free_txpg) + return false; + + rtw_sdio_8723bs_store_free_txpg(rtwdev, free_txpg); + + return true; +} + +static int rtw_sdio_8723bs_pubq_num(struct rtw_dev *rtwdev, u16 *pubq_num) +{ + const struct rtw_page_table *pg_tbl = &rtwdev->chip->page_table[0]; + u16 acq_pg_num = rtwdev->fifo.acq_pg_num; + u16 reserved_num; + + reserved_num = pg_tbl->hq_num + pg_tbl->lq_num + pg_tbl->nq_num + + pg_tbl->exq_num + pg_tbl->gapq_num; + if (acq_pg_num <= reserved_num) { + rtw_err(rtwdev, + "no transmit pages left for the public queue: %u of %u reserved\n", + reserved_num, acq_pg_num); + return -EINVAL; + } + + *pubq_num = acq_pg_num - reserved_num; + + return 0; +} + +static int rtw_sdio_8723bs_init_free_txpg(struct rtw_dev *rtwdev) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + const struct rtw_page_table *pg_tbl; + u16 pubq_num; + int ret; + + /* Seed from the page table when the chip has nothing to report yet. */ + if (!rtw_sdio_8723bs_sync_free_txpg(rtwdev)) { + ret = rtw_sdio_8723bs_pubq_num(rtwdev, &pubq_num); + if (ret) + return ret; + + pg_tbl = &rtwdev->chip->page_table[0]; + atomic_set(&rtwsdio->free_pg_high, pg_tbl->hq_num); + atomic_set(&rtwsdio->free_pg_normal, pg_tbl->nq_num); + atomic_set(&rtwsdio->free_pg_low, pg_tbl->lq_num); + atomic_set(&rtwsdio->free_pg_pub, pubq_num); + } + + atomic_set(&rtwsdio->tx_oqt_free, + rtw_read8(rtwdev, REG_SDIO_OQT_FREE_PG)); + + return 0; +} + +/* + * Clamped at zero: a lost update against rtw_sdio_8723bs_consume_txpg() can + * briefly drive a counter negative, and wrapping would hide the shortage + * instead of triggering a resync from the chip. + */ +static unsigned int rtw_sdio_8723bs_pages_free(struct rtw_dev *rtwdev, + atomic_t *dedicated) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + int free; + + free = atomic_read(dedicated) + atomic_read(&rtwsdio->free_pg_pub); + + return free > 0 ? free : 0; +} + +/* + * The pool a queue draws from follows the transmit FIFO that + * rtw_sdio_get_tx_addr() writes into, since that is the one the chip charges. + * RTW_TX_QUEUE_MGMT is the exception: it goes to the extra FIFO, which + * REG_SDIO_FREE_TXPG has no counter for and this chip allocates no pages to, + * so it is accounted against the high pool and served from the public one. + */ +static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + + switch (queue) { + case RTW_TX_QUEUE_VI: + case RTW_TX_QUEUE_VO: + return &rtwsdio->free_pg_normal; + case RTW_TX_QUEUE_BE: + case RTW_TX_QUEUE_BK: + return &rtwsdio->free_pg_low; + case RTW_TX_QUEUE_BCN: + case RTW_TX_QUEUE_H2C: + case RTW_TX_QUEUE_HI0: + case RTW_TX_QUEUE_MGMT: + return &rtwsdio->free_pg_high; + default: + return NULL; + } +} + static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue, size_t count) { unsigned int pages_free, pages_needed; - if (rtw_chip_wcpu_8051(rtwdev)) { + if (rtw_is_8723bs(rtwdev)) { + atomic_t *dedicated; + + dedicated = rtw_sdio_8723bs_free_txpg(rtwdev, queue); + if (!dedicated) { + rtw_warn(rtwdev, "Unknown mapping for queue %u\n", queue); + return -EINVAL; + } + + pages_free = rtw_sdio_8723bs_pages_free(rtwdev, dedicated); + pages_needed = DIV_ROUND_UP(count, rtwdev->chip->page_size); + if (pages_needed <= pages_free) + return 0; + + rtw_sdio_8723bs_sync_free_txpg(rtwdev); + pages_free = rtw_sdio_8723bs_pages_free(rtwdev, dedicated); + } else if (rtw_chip_wcpu_8051(rtwdev)) { u32 free_txpg; free_txpg = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG); @@ -632,13 +770,140 @@ static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue, return 0; } +static int rtw_sdio_8723bs_wait_tx_oqt(struct rtw_dev *rtwdev) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + unsigned long deadline; + u8 free; + + lockdep_assert_held(&rtwsdio->tx_credit_lock); + + if (atomic_add_unless(&rtwsdio->tx_oqt_free, -1, 0)) + return 0; + + deadline = jiffies + msecs_to_jiffies(RTW_SDIO_OQT_TIMEOUT_MS); + do { + free = rtw_read8(rtwdev, REG_SDIO_OQT_FREE_PG); + if (free) { + atomic_set(&rtwsdio->tx_oqt_free, free - 1); + return 0; + } + usleep_range(1000, 2000); + } while (time_before(jiffies, deadline)); + + return -EBUSY; +} + +static void rtw_sdio_8723bs_consume_txpg(struct rtw_dev *rtwdev, u8 queue, + unsigned int pages) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + atomic_t *dedicated; + unsigned int taken; + int free; + + lockdep_assert_held(&rtwsdio->tx_credit_lock); + + dedicated = rtw_sdio_8723bs_free_txpg(rtwdev, queue); + if (!dedicated) + return; + + free = atomic_read(dedicated); + taken = min_t(unsigned int, pages, free > 0 ? free : 0); + atomic_sub(taken, dedicated); + + pages -= taken; + if (pages && atomic_sub_return(pages, &rtwsdio->free_pg_pub) < 0) + atomic_set(&rtwsdio->free_pg_pub, 0); +} + +static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb, + enum rtw_tx_queue_type queue, u32 txaddr, + size_t write_size) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + bool bus_claim; + int ret; + + if (!IS_ALIGNED((unsigned long)skb->data, RTW_SDIO_DATA_PTR_ALIGN)) + rtw_warn(rtwdev, "Got unaligned SKB in %s() for queue %u\n", + __func__, queue); + + bus_claim = rtw_sdio_bus_claim_needed(rtwsdio); + + if (bus_claim) + sdio_claim_host(rtwsdio->sdio_func); + + ret = sdio_memcpy_toio(rtwsdio->sdio_func, txaddr, skb->data, + write_size); + + if (bus_claim) + sdio_release_host(rtwsdio->sdio_func); + + if (ret) + rtw_warn(rtwdev, + "Failed to write %zu byte(s) to SDIO port 0x%08x", + write_size, txaddr); + + return ret; +} + +static int rtw_sdio_write_port_8723bs(struct rtw_dev *rtwdev, + struct sk_buff *skb, + enum rtw_tx_queue_type queue, u32 txaddr, + size_t write_size) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + unsigned int pages; + size_t txsize; + int ret; + + /* the chip charges pages by frame length, not by the padded transfer */ + txsize = round_up(skb->len, 4); + + guard(mutex)(&rtwsdio->tx_credit_lock); + + ret = rtw_sdio_check_free_txpg(rtwdev, queue, txsize); + if (ret) + return ret; + + ret = rtw_sdio_8723bs_wait_tx_oqt(rtwdev); + if (ret) + return ret; + + ret = rtw_sdio_write_to_port(rtwdev, skb, queue, txaddr, write_size); + if (ret) { + /* nothing was queued, so hand the output queue entry back */ + atomic_inc(&rtwsdio->tx_oqt_free); + return ret; + } + + pages = DIV_ROUND_UP(txsize, rtwdev->chip->page_size); + rtw_sdio_8723bs_consume_txpg(rtwdev, queue, pages); + + return 0; +} + +static int rtw_sdio_write_port_generic(struct rtw_dev *rtwdev, + struct sk_buff *skb, + enum rtw_tx_queue_type queue, u32 txaddr, + size_t write_size) +{ + int ret; + + ret = rtw_sdio_check_free_txpg(rtwdev, queue, write_size); + if (ret) + return ret; + + return rtw_sdio_write_to_port(rtwdev, skb, queue, txaddr, write_size); +} + static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb, enum rtw_tx_queue_type queue) { struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + size_t write_size; size_t pad_size; - bool bus_claim; - size_t txsize; u32 txaddr; int ret; @@ -646,8 +911,8 @@ static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb, if (!txaddr) return -EINVAL; - txsize = sdio_align_size(rtwsdio->sdio_func, skb->len); - pad_size = txsize - skb->len; + write_size = sdio_align_size(rtwsdio->sdio_func, skb->len); + pad_size = write_size - skb->len; if (pad_size > 0) { /* @@ -659,30 +924,12 @@ static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb, return ret; } - ret = rtw_sdio_check_free_txpg(rtwdev, queue, txsize); - if (ret) - return ret; + if (rtw_is_8723bs(rtwdev)) + return rtw_sdio_write_port_8723bs(rtwdev, skb, queue, txaddr, + write_size); - if (!IS_ALIGNED((unsigned long)skb->data, RTW_SDIO_DATA_PTR_ALIGN)) - rtw_warn(rtwdev, "Got unaligned SKB in %s() for queue %u\n", - __func__, queue); - - bus_claim = rtw_sdio_bus_claim_needed(rtwsdio); - - if (bus_claim) - sdio_claim_host(rtwsdio->sdio_func); - - ret = sdio_memcpy_toio(rtwsdio->sdio_func, txaddr, skb->data, txsize); - - if (bus_claim) - sdio_release_host(rtwsdio->sdio_func); - - if (ret) - rtw_warn(rtwdev, - "Failed to write %zu byte(s) to SDIO port 0x%08x", - txsize, txaddr); - - return ret; + return rtw_sdio_write_port_generic(rtwdev, skb, queue, txaddr, + write_size); } static void rtw_sdio_init(struct rtw_dev *rtwdev) @@ -761,8 +1008,51 @@ static int rtw_sdio_setup(struct rtw_dev *rtwdev) return 0; } +/* + * Reprogram the queue page allocation if the chip came up with none. This is + * a repair path, not part of the normal start sequence: a non-zero free page + * count means the allocation latched during power on and must be left alone, + * and without a transmit page pool there is nothing to divide up either. + */ +static int rtw_sdio_8723bs_check_rqpn(struct rtw_dev *rtwdev) +{ + const struct rtw_chip_info *chip = rtwdev->chip; + struct rtw_fifo_conf *fifo = &rtwdev->fifo; + const struct rtw_page_table *pg_tbl; + u32 free_txpg; + u16 pubq_num; + int ret; + + free_txpg = rtw_read32(rtwdev, REG_SDIO_FREE_TXPG); + if (free_txpg || !fifo->acq_pg_num) + return 0; + + ret = rtw_sdio_8723bs_pubq_num(rtwdev, &pubq_num); + if (ret) + return ret; + + pg_tbl = &chip->page_table[0]; + rtw_write32(rtwdev, REG_RQPN_NPQ, + BIT_RQPN_NE(pg_tbl->nq_num, pg_tbl->exq_num)); + rtw_write32(rtwdev, REG_RQPN, + BIT_RQPN_HLP(pg_tbl->hq_num, pg_tbl->lq_num, pubq_num)); + + return 0; +} + static int rtw_sdio_start(struct rtw_dev *rtwdev) { + if (rtw_is_8723bs(rtwdev)) { + int ret = rtw_sdio_8723bs_check_rqpn(rtwdev); + + if (ret) + return ret; + + ret = rtw_sdio_8723bs_init_free_txpg(rtwdev); + if (ret) + return ret; + } + rtw_sdio_enable_rx_aggregation(rtwdev); rtw_sdio_enable_interrupt(rtwdev); @@ -1306,6 +1596,8 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev) return -ENOMEM; } + mutex_init(&rtwsdio->tx_credit_lock); + for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) skb_queue_head_init(&rtwsdio->tx_queue[i]); rtwsdio->tx_handler_data = kmalloc_obj(*rtwsdio->tx_handler_data); @@ -1318,6 +1610,7 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev) return 0; err_destroy_wq: + mutex_destroy(&rtwsdio->tx_credit_lock); destroy_workqueue(rtwsdio->txwq); return -ENOMEM; } @@ -1332,6 +1625,8 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev) for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) ieee80211_purge_tx_queue(rtwdev->hw, &rtwsdio->tx_queue[i]); + + mutex_destroy(&rtwsdio->tx_credit_lock); } int rtw_sdio_probe(struct sdio_func *sdio_func, diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h index 457e8b02380e..f43f1c6309b7 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.h +++ b/drivers/net/wireless/realtek/rtw88/sdio.h @@ -86,6 +86,10 @@ #define REG_SDIO_OQT_FREE_PG (SDIO_LOCAL_OFFSET + 0x001E) /* Free Tx Buffer Page */ #define REG_SDIO_FREE_TXPG (SDIO_LOCAL_OFFSET + 0x0020) +#define BIT_FREE_TXPG_HIGH GENMASK(7, 0) +#define BIT_FREE_TXPG_NORMAL GENMASK(15, 8) +#define BIT_FREE_TXPG_LOW GENMASK(23, 16) +#define BIT_FREE_TXPG_PUB GENMASK(31, 24) /* HCI Current Power Mode 1 */ #define REG_SDIO_HCPWM1 (SDIO_LOCAL_OFFSET + 0x0024) /* HCI Current Power Mode 2 */ @@ -159,6 +163,14 @@ struct rtw_sdio { struct workqueue_struct *txwq; struct rtw_sdio_work_data *tx_handler_data; struct sk_buff_head tx_queue[RTK_MAX_TX_QUEUE_NUM]; + + atomic_t free_pg_high; + atomic_t free_pg_normal; + atomic_t free_pg_low; + atomic_t free_pg_pub; + atomic_t tx_oqt_free; + /* one writer at a time between the credit check and the accounting */ + struct mutex tx_credit_lock; }; extern const struct dev_pm_ops rtw_sdio_pm_ops; From 8c17eb82a0fbf21b2c2adb1413c46797eded31b4 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:55 +0200 Subject: [PATCH 0548/2126] wifi: rtw88: sdio: set up RX aggregation and interrupts for RTL8723BS Enable the existing RX aggregation setup for this chip and select the larger DMA burst count it needs. The RTL8723BS does not raise CPWM1, so leave that source out of its interrupt mask, and set the SDIO TX control bit the vendor driver uses to have transfers always recognised. The chip was also seen to keep raising the interrupt after resume when undefined status bits were written back on acknowledgment, so acknowledge only the bits this driver defines. That observation dates from bring up and I cannot re-measure it: the test machine only offers s2idle and does not reliably return from it, so the resume path is not exercised here. The change is scoped to this chip; the other SDIO parts keep writing the status word back unchanged. Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-7-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/sdio.c | 28 ++++++++++++++++++++++- drivers/net/wireless/realtek/rtw88/sdio.h | 9 ++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index 0dc1277619f6..696cd203919e 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -936,7 +936,11 @@ static void rtw_sdio_init(struct rtw_dev *rtwdev) { struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; - rtwsdio->irq_mask = REG_SDIO_HIMR_RX_REQUEST | REG_SDIO_HIMR_CPWM1; + if (rtw_is_8723bs(rtwdev)) + rtwsdio->irq_mask = REG_SDIO_HIMR_RX_REQUEST; + else + rtwsdio->irq_mask = REG_SDIO_HIMR_RX_REQUEST | + REG_SDIO_HIMR_CPWM1; } static void rtw_sdio_enable_rx_aggregation(struct rtw_dev *rtwdev) @@ -944,6 +948,7 @@ static void rtw_sdio_enable_rx_aggregation(struct rtw_dev *rtwdev) u8 size, timeout; switch (rtwdev->chip->id) { + case RTW_CHIP_TYPE_8723B: case RTW_CHIP_TYPE_8703B: case RTW_CHIP_TYPE_8821A: case RTW_CHIP_TYPE_8812A: @@ -971,6 +976,8 @@ static void rtw_sdio_enable_rx_aggregation(struct rtw_dev *rtwdev) FIELD_PREP(BIT_DMA_AGG_TO_V1, timeout)); rtw_write8_set(rtwdev, REG_RXDMA_MODE, BIT_DMA_MODE); + if (rtw_is_8723bs(rtwdev)) + rtw_write8_mask(rtwdev, REG_RXDMA_MODE, BIT_DMA_BURST_CNT, 0x3); } static void rtw_sdio_enable_interrupt(struct rtw_dev *rtwdev) @@ -1042,6 +1049,8 @@ static int rtw_sdio_8723bs_check_rqpn(struct rtw_dev *rtwdev) static int rtw_sdio_start(struct rtw_dev *rtwdev) { + u32 clear; + if (rtw_is_8723bs(rtwdev)) { int ret = rtw_sdio_8723bs_check_rqpn(rtwdev); @@ -1054,6 +1063,13 @@ static int rtw_sdio_start(struct rtw_dev *rtwdev) } rtw_sdio_enable_rx_aggregation(rtwdev); + + if (rtw_is_8723bs(rtwdev)) { + clear = rtw_read32(rtwdev, REG_SDIO_HISR) & RTW_SDIO_HISR_CLEAR_MASK; + if (clear) + rtw_write32(rtwdev, REG_SDIO_HISR, clear); + } + rtw_sdio_enable_interrupt(rtwdev); return 0; @@ -1133,6 +1149,8 @@ static void rtw_sdio_interface_cfg(struct rtw_dev *rtwdev) val = rtw_read32(rtwdev, REG_SDIO_TX_CTRL); val &= 0xfff8; + if (rtw_is_8723bs(rtwdev)) + val |= BIT_SDIO_TX_CTRL_ALWAYS_RECOGNIZE; rtw_write32(rtwdev, REG_SDIO_TX_CTRL, val); } @@ -1397,6 +1415,14 @@ static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func) rtw_sdio_rx_isr(rtwdev); } + /* + * RTL8723BS keeps raising the interrupt after resume if undefined + * status bits are written back, so acknowledge only the bits this + * driver defines. Other chips keep the existing behaviour. + */ + if (rtw_is_8723bs(rtwdev)) + hisr &= RTW_SDIO_HISR_CLEAR_MASK; + rtw_write32(rtwdev, REG_SDIO_HISR, hisr); rtwsdio->irq_thread = NULL; diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h index f43f1c6309b7..634c0b1339bb 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.h +++ b/drivers/net/wireless/realtek/rtw88/sdio.h @@ -22,6 +22,7 @@ /* SDIO Tx Control */ #define REG_SDIO_TX_CTRL (SDIO_LOCAL_OFFSET + 0x0000) +#define BIT_SDIO_TX_CTRL_ALWAYS_RECOGNIZE BIT(4) /*SDIO status timeout*/ #define REG_SDIO_TIMEOUT (SDIO_LOCAL_OFFSET + 0x0002) @@ -77,6 +78,14 @@ /* the following two are RTL8188 SDIO Specific */ #define REG_SDIO_HISR_MCU_ERR BIT(28) #define REG_SDIO_HISR_TSF_BIT32_TOGGLE BIT(29) +#define RTW_SDIO_HISR_CLEAR_MASK \ + (REG_SDIO_HISR_TXERR | REG_SDIO_HISR_RXERR | \ + REG_SDIO_HISR_TXFOVW | REG_SDIO_HISR_RXFOVW | \ + REG_SDIO_HISR_TXBCNOK | REG_SDIO_HISR_TXBCNERR | \ + REG_SDIO_HISR_C2HCMD | REG_SDIO_HISR_CPWM1 | \ + REG_SDIO_HISR_CPWM2 | REG_SDIO_HISR_HSISR_IND | \ + REG_SDIO_HISR_GTINT3_IND | REG_SDIO_HISR_GTINT4_IND | \ + REG_SDIO_HISR_PSTIMEOUT | REG_SDIO_HISR_OCPINT) /* HCI Current Power Mode */ #define REG_SDIO_HCPWM (SDIO_LOCAL_OFFSET + 0x0019) From 28eaf7971a20164eaf53287947be71f1cd98d2dc Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 9 Sep 2026 09:45:56 +0200 Subject: [PATCH 0549/2126] wifi: rtw88: sdio: add TX back-pressure and retry on page starvation Two problems show up on RTL8723BS uplink. The per-AC software FIFO is unbounded, so mac80211 keeps handing frames down until latency collapses under load. And when a transfer cannot be completed the queue is simply abandoned for that pass, which stalls the AC until something else kicks the worker. Stop the mac80211 queue once a data AC fills past a high watermark and wake it from the drain path when it falls back to a low one. Both sides take the TX queue lock across the length check and the flag update, the way rtw_pci_tx_write() and rtw_pci_tx_isr() use irq_lock. Without it the producer could stop a queue on a length the drain path had already emptied, having seen the flag still clear and so skipped the wake, and the AC would have stayed stopped with nothing left to wake it. Convert the TX work item to a delayed work and re-arm it when a transfer fails for a reason that can clear on its own, so it is retried rather than the AC abandoned, and cancel the work on teardown. Retrying matters once the queue can be stopped. A stopped queue is handed no further frames, so nothing else would kick the worker, and the AC would stay stopped for good with the link still up and receive unaffected. The two retried cases, a transmit page or output queue shortage and a failed skb expansion, are also the two that fail silently; the rest are logged where they happen, so they are visible rather than an unexplained hang, and they keep the existing behaviour rather than being retried indefinitely. Measured on RTL8723BS hardware, uplink goes from 11.9 Mbit/s with 204 TCP retransmits to 20.1 Mbit/s with 2. Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260909074556.55709-8-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/sdio.c | 137 ++++++++++++++++++++-- drivers/net/wireless/realtek/rtw88/sdio.h | 3 +- 2 files changed, 129 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index 696cd203919e..dc2fd0f8f9ff 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -22,6 +22,11 @@ #define RTW_SDIO_INDIRECT_RW_RETRIES 50 #define RTW_SDIO_OQT_TIMEOUT_MS 1000 +/* Bounds the queueing latency of the unbounded per-AC software FIFO. */ +#define RTW_SDIO_TX_FIFO_HIWATER 16 +#define RTW_SDIO_TX_FIFO_LOWATER 8 +#define RTW_SDIO_TX_RETRY_DELAY msecs_to_jiffies(1) + static bool rtw_sdio_is_bus_addr(u32 addr) { return !!(addr & RTW_SDIO_BUS_MSK); @@ -1133,7 +1138,11 @@ static void rtw_sdio_tx_kick_off(struct rtw_dev *rtwdev) { struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; - queue_work(rtwsdio->txwq, &rtwsdio->tx_handler_data->work); + /* + * A retry may already be pending with a delay; re-arm it so a newly + * queued frame is not held back by it. + */ + mod_delayed_work(rtwsdio->txwq, &rtwsdio->tx_handler_data->work, 0); } static void rtw_sdio_link_ps(struct rtw_dev *rtwdev, bool enter) @@ -1242,12 +1251,61 @@ static int rtw_sdio_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size) return rtw_sdio_write_data(rtwdev, &pkt_info, skb, RTW_TX_QUEUE_H2C); } +/* + * Both this and the wake below hold the TX queue lock across the length check + * and the flag update, so a queue is only ever stopped while it really is + * above the watermark, and the drain path always sees the flag the producer + * set. + */ +static void rtw_sdio_8723bs_stop_tx_queue(struct rtw_dev *rtwdev, + enum rtw_tx_queue_type queue, + u16 q_map) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + + if (!rtw_is_8723bs(rtwdev) || queue >= RTW_TX_QUEUE_BCN) + return; + + guard(spinlock_irqsave)(&rtwsdio->tx_queue[queue].lock); + + if (rtwsdio->tx_queue_stopped[queue]) + return; + + if (skb_queue_len(&rtwsdio->tx_queue[queue]) < RTW_SDIO_TX_FIFO_HIWATER) + return; + + rtwsdio->tx_queue_stopped[queue] = true; + ieee80211_stop_queue(rtwdev->hw, q_map); +} + +static void rtw_sdio_8723bs_wake_tx_queue(struct rtw_dev *rtwdev, + enum rtw_tx_queue_type queue, + u16 q_map) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + + if (!rtw_is_8723bs(rtwdev) || queue >= RTW_TX_QUEUE_BCN) + return; + + guard(spinlock_irqsave)(&rtwsdio->tx_queue[queue].lock); + + if (!rtwsdio->tx_queue_stopped[queue]) + return; + + if (skb_queue_len(&rtwsdio->tx_queue[queue]) > RTW_SDIO_TX_FIFO_LOWATER) + return; + + rtwsdio->tx_queue_stopped[queue] = false; + ieee80211_wake_queue(rtwdev->hw, q_map); +} + static int rtw_sdio_tx_write(struct rtw_dev *rtwdev, struct rtw_tx_pkt_info *pkt_info, struct sk_buff *skb) { struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; enum rtw_tx_queue_type queue = rtw_tx_queue_mapping(skb); + u16 q_map = skb_get_queue_mapping(skb); struct rtw_sdio_tx_data *tx_data; rtw_sdio_tx_skb_prepare(rtwdev, pkt_info, skb, queue); @@ -1255,8 +1313,11 @@ static int rtw_sdio_tx_write(struct rtw_dev *rtwdev, tx_data = rtw_sdio_get_tx_data(skb); tx_data->sn = pkt_info->sn; + /* The TX worker may already have freed the skb, so do not touch it. */ skb_queue_tail(&rtwsdio->tx_queue[queue], skb); + rtw_sdio_8723bs_stop_tx_queue(rtwdev, queue, q_map); + return 0; } @@ -1559,33 +1620,80 @@ static void rtw_sdio_indicate_tx_status(struct rtw_dev *rtwdev, ieee80211_tx_status_irqsafe(hw, skb); } -static void rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev, - enum rtw_tx_queue_type queue) +/* + * Send one frame from @queue. Returns 0 when a frame was written, 1 when the + * queue was empty and a negative errno when the write failed, in which case + * the frame is put back at the head of the queue. + */ +static int rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev, + enum rtw_tx_queue_type queue) { struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; struct sk_buff *skb; + u16 q_map; int ret; skb = skb_dequeue(&rtwsdio->tx_queue[queue]); if (!skb) - return; + return 1; ret = rtw_sdio_write_port(rtwdev, skb, queue); if (ret) { skb_queue_head(&rtwsdio->tx_queue[queue], skb); - return; + return ret; } + /* rtw_sdio_indicate_tx_status() consumes the skb, so read this first */ + q_map = skb_get_queue_mapping(skb); + rtw_sdio_indicate_tx_status(rtwdev, skb); + + rtw_sdio_8723bs_wake_tx_queue(rtwdev, queue, q_map); + + return 0; +} + +/* + * A page or output queue shortage, and a failed skb expansion, are transient + * and leave the frame queued, so come back for it shortly. That matters once + * the mac80211 queue can be stopped: a stopped queue is handed no further + * frames, so nothing else would kick this work item and the access category + * would stay stopped for good. The remaining errors are logged where they + * happen and are not retried. + * + * After a management frame, restart from the highest priority queue so the + * join sequence is not held up behind a data backlog. + */ +static bool rtw_sdio_8723bs_reschedule_tx(struct rtw_dev *rtwdev, + struct rtw_sdio_work_data *work_data, + enum rtw_tx_queue_type queue, int ret) +{ + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + unsigned long delay; + + if (!rtw_is_8723bs(rtwdev)) + return false; + + if (ret == -EBUSY || ret == -ENOMEM) + delay = RTW_SDIO_TX_RETRY_DELAY; + else if (ret == 0 && queue == RTW_TX_QUEUE_MGMT) + delay = 0; + else + return false; + + queue_delayed_work(rtwsdio->txwq, &work_data->work, delay); + + return true; } static void rtw_sdio_tx_handler(struct work_struct *work) { struct rtw_sdio_work_data *work_data = - container_of(work, struct rtw_sdio_work_data, work); + container_of(to_delayed_work(work), struct rtw_sdio_work_data, + work); struct rtw_sdio *rtwsdio; struct rtw_dev *rtwdev; - int limit, queue; + int limit, queue, ret; rtwdev = work_data->rtwdev; rtwsdio = (struct rtw_sdio *)rtwdev->priv; @@ -1595,7 +1703,13 @@ static void rtw_sdio_tx_handler(struct work_struct *work) for (queue = RTK_MAX_TX_QUEUE_NUM - 1; queue >= 0; queue--) { for (limit = 0; limit < 1000; limit++) { - rtw_sdio_process_tx_queue(rtwdev, queue); + ret = rtw_sdio_process_tx_queue(rtwdev, queue); + if (ret > 0) + break; + + if (rtw_sdio_8723bs_reschedule_tx(rtwdev, work_data, + queue, ret)) + return; if (skb_queue_empty(&rtwsdio->tx_queue[queue])) break; @@ -1624,14 +1738,16 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev) mutex_init(&rtwsdio->tx_credit_lock); - for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) + for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) { skb_queue_head_init(&rtwsdio->tx_queue[i]); + rtwsdio->tx_queue_stopped[i] = false; + } rtwsdio->tx_handler_data = kmalloc_obj(*rtwsdio->tx_handler_data); if (!rtwsdio->tx_handler_data) goto err_destroy_wq; rtwsdio->tx_handler_data->rtwdev = rtwdev; - INIT_WORK(&rtwsdio->tx_handler_data->work, rtw_sdio_tx_handler); + INIT_DELAYED_WORK(&rtwsdio->tx_handler_data->work, rtw_sdio_tx_handler); return 0; @@ -1646,6 +1762,7 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev) struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; int i; + cancel_delayed_work_sync(&rtwsdio->tx_handler_data->work); destroy_workqueue(rtwsdio->txwq); kfree(rtwsdio->tx_handler_data); diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h index 634c0b1339bb..6e7e6009744b 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.h +++ b/drivers/net/wireless/realtek/rtw88/sdio.h @@ -156,7 +156,7 @@ struct rtw_sdio_tx_data { }; struct rtw_sdio_work_data { - struct work_struct work; + struct delayed_work work; struct rtw_dev *rtwdev; }; @@ -172,6 +172,7 @@ struct rtw_sdio { struct workqueue_struct *txwq; struct rtw_sdio_work_data *tx_handler_data; struct sk_buff_head tx_queue[RTK_MAX_TX_QUEUE_NUM]; + bool tx_queue_stopped[RTK_MAX_TX_QUEUE_NUM]; atomic_t free_pg_high; atomic_t free_pg_normal; From 04cc8c59a3d79ef7ec2341f1c7aef1d40a0ce7df Mon Sep 17 00:00:00 2001 From: Mehmet Fide Date: Thu, 10 Sep 2026 10:17:14 +0200 Subject: [PATCH 0550/2126] wifi: rtw88: usb: bound what the driver feeds the after-DTIM queue Frames routed to the high queue are transmitted right after DTIM beacons only, inside the ATIM window, while they wait in the shared TX page pool. The driver puts no limit on how many it hands over, so as long as one station dozes, any sustained broadcast or multicast traffic outruns the drain and empties the pool: measured on an RTL8822BU AP with a single client in power save and ~40 frames/s of mDNS chatter, the free page count at 0x240 goes from 1803 to 16 in about 100 seconds and stays there for as long as the traffic lasts. From that point every other transmit queues behind the backlog, authentication responses arrive too late for anyone to join, and the reserved page download fails ("error beacon valid"). The AP keeps beaconing and only a reboot recovers. Feed the high queue through a small budget that refills below the measured drain rate (about 3 frames per DTIM, ~15/s at dtim_period 2 on the default 2 TU ATIM window); whatever exceeds the budget leaves on its access category queue right away. The high queue backlog is now bounded by the burst size under any load, so the page pool cannot run dry, at the price that a dozing station may miss part of a broadcast storm. Signed-off-by: Mehmet Fide Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260910081716.769081-2-mehmet.fide@gmail.com --- drivers/net/wireless/realtek/rtw88/usb.c | 41 ++++++++++++++++++++++-- drivers/net/wireless/realtek/rtw88/usb.h | 5 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index c90802919473..a03896260f1a 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -562,7 +562,37 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size) return rtw_usb_write_data(rtwdev, &pkt_info, buf); } -static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) +#define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10) /* one unit of budget per 100 ms */ +#define RTW_USB_HIQ_BUDGET_MAX 16 + +static bool rtw_usb_hiq_take_budget(struct rtw_usb *rtwusb) +{ + unsigned long flags, elapsed, add; + bool ok; + + spin_lock_irqsave(&rtwusb->hiq_lock, flags); + + elapsed = jiffies - rtwusb->hiq_refill; + add = elapsed / RTW_USB_HIQ_REFILL_INTERVAL; + if (add) { + rtwusb->hiq_budget = min_t(unsigned long, rtwusb->hiq_budget + add, + RTW_USB_HIQ_BUDGET_MAX); + + /* keep the unfinished part of the interval for the next unit */ + rtwusb->hiq_refill = jiffies - elapsed % RTW_USB_HIQ_REFILL_INTERVAL; + } + + ok = rtwusb->hiq_budget > 0; + if (ok) + rtwusb->hiq_budget--; + + spin_unlock_irqrestore(&rtwusb->hiq_lock, flags); + + return ok; +} + +static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_usb *rtwusb, + struct sk_buff *skb) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); @@ -573,7 +603,8 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) qsel = TX_DESC_QSEL_MGMT; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel = (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ? + qsel = (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) && + rtw_usb_hiq_take_budget(rtwusb) ? TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority; @@ -593,7 +624,7 @@ static int rtw_usb_tx_write(struct rtw_dev *rtwdev, u8 *pkt_desc; int ep; - pkt_info->qsel = rtw_usb_tx_queue_mapping_to_qsel(skb); + pkt_info->qsel = rtw_usb_tx_queue_mapping_to_qsel(rtwusb, skb); pkt_desc = skb_push(skb, chip->tx_pkt_desc_sz); memset(pkt_desc, 0, chip->tx_pkt_desc_sz); ep = qsel_to_ep(rtwusb, pkt_info->qsel); @@ -1034,6 +1065,10 @@ static int rtw_usb_init_tx(struct rtw_dev *rtwdev) struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev); int i; + spin_lock_init(&rtwusb->hiq_lock); + rtwusb->hiq_budget = RTW_USB_HIQ_BUDGET_MAX; + rtwusb->hiq_refill = jiffies; + rtwusb->txwq = create_singlethread_workqueue("rtw88_usb: tx wq"); if (!rtwusb->txwq) { rtw_err(rtwdev, "failed to create TX work queue\n"); diff --git a/drivers/net/wireless/realtek/rtw88/usb.h b/drivers/net/wireless/realtek/rtw88/usb.h index 9b695b688b24..94ff21dd0846 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.h +++ b/drivers/net/wireless/realtek/rtw88/usb.h @@ -75,6 +75,11 @@ struct rtw_usb { u8 out_ep[RTW_USB_EP_MAX]; int qsel_to_ep[TX_DESC_QSEL_MAX]; + /* protects hiq_budget and hiq_refill */ + spinlock_t hiq_lock; + u32 hiq_budget; + unsigned long hiq_refill; + struct workqueue_struct *txwq, *rxwq; struct sk_buff_head tx_queue[RTW_USB_EP_MAX]; From 185971f1b4eb4ea9059d76cf1a18f992eef998c1 Mon Sep 17 00:00:00 2001 From: Mehmet Fide Date: Thu, 10 Sep 2026 10:17:15 +0200 Subject: [PATCH 0551/2126] wifi: rtw88: usb: only let the frames a dozing station needs use the after-DTIM queue With the budget in place the high queue can no longer take the chip down, but ordinary chatter still competes with the frames a sleeping station actually needs. mac80211 marks every broadcast and multicast frame with IEEE80211_TX_CTL_SEND_AFTER_DTIM while a station dozes, mDNS and SSDP included, so under normal traffic the budget is spent on frames nobody waits for. Do what the vendor driver does with its default "allow special" high queue filter: admit only ARP, EAPOL and DHCP to the after-DTIM path, the frames a station coming out of power save has to see; everything else goes out on its access category queue at line rate. The frames are classified the way rtw89_core_tx_btc_spec_pkt_notify() does it, from skb->protocol and the network and transport header offsets that mac80211 keeps from the netdev path; EAPOL is the control port flag. Frames the AP relays between its own stations arrive as ETH_P_802_3 and are not inspected, they leave on the access category queue. With the filter in place the page pool stays at 1803 through the same 180 second storm, a DHCP flood still takes the after-DTIM path (and is then held by the budget), and join/ping cycling without power save is unchanged (10/10). Signed-off-by: Mehmet Fide Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260910081716.769081-3-mehmet.fide@gmail.com --- drivers/net/wireless/realtek/rtw88/usb.c | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index a03896260f1a..715a2ce342d9 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -2,9 +2,11 @@ /* Copyright(c) 2018-2019 Realtek Corporation */ +#include #include -#include #include +#include +#include #include "main.h" #include "debug.h" #include "mac.h" @@ -562,6 +564,27 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size) return rtw_usb_write_data(rtwdev, &pkt_info, buf); } +static bool rtw_usb_bmc_needs_dtim(struct sk_buff *skb) +{ + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); + struct udphdr *udphdr; + + if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) + return true; + + if (skb->protocol == htons(ETH_P_ARP)) + return true; + + if (skb->protocol == htons(ETH_P_IP) && + ip_hdr(skb)->protocol == IPPROTO_UDP) { + udphdr = udp_hdr(skb); + + return udphdr->dest == htons(67) || udphdr->dest == htons(68); + } + + return false; +} + #define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10) /* one unit of budget per 100 ms */ #define RTW_USB_HIQ_BUDGET_MAX 16 @@ -604,7 +627,7 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_usb *rtwusb, else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) qsel = (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) && - rtw_usb_hiq_take_budget(rtwusb) ? + rtw_usb_bmc_needs_dtim(skb) && rtw_usb_hiq_take_budget(rtwusb) ? TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority; From cf8b516f67652f550e040951b88a2040b375afcf Mon Sep 17 00:00:00 2001 From: Mehmet Fide Date: Thu, 10 Sep 2026 10:17:16 +0200 Subject: [PATCH 0552/2126] wifi: rtw88: widen the ATIM window while an AP interface is up The frames held for dozing stations go out right after the DTIM beacon and only for the duration of the ATIM window. The chips come up with a 2 TU window (the two that program it set 0x2 at init), which drains about three frames per DTIM; the vendor driver sets 0xa or 0xc in AP mode instead. With the 2 TU window the measured page pool exhaustion takes ~100 s of ordinary multicast chatter; at 0x4 the same storm already drains, so 0xa leaves comfortable headroom. Program 0xa when an AP interface starts and put the default back when it stops, since most chips never initialize the register themselves. The bound and the filter of the previous patches still apply: the window adds drain capacity, the budget protects the pool when that is not enough, the filter keeps chatter off the beacon-paced path. Suggested-by: Ping-Ke Shih Signed-off-by: Mehmet Fide Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260910081716.769081-4-mehmet.fide@gmail.com --- drivers/net/wireless/realtek/rtw88/mac80211.c | 2 ++ drivers/net/wireless/realtek/rtw88/reg.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/mac80211.c b/drivers/net/wireless/realtek/rtw88/mac80211.c index 0b622d7663b6..2a9b09fa76e7 100644 --- a/drivers/net/wireless/realtek/rtw88/mac80211.c +++ b/drivers/net/wireless/realtek/rtw88/mac80211.c @@ -474,6 +474,7 @@ static int rtw_ops_start_ap(struct ieee80211_hw *hw, mutex_lock(&rtwdev->mutex); rtw_write32_set(rtwdev, REG_TCR, BIT_TCR_UPDATE_HGQMD); + rtw_write16(rtwdev, REG_ATIMWND, ATIMWND_AP); rtwdev->ap_active = true; rtw_store_op_chan(rtwdev, true); chip->ops->phy_calibration(rtwdev); @@ -490,6 +491,7 @@ static void rtw_ops_stop_ap(struct ieee80211_hw *hw, mutex_lock(&rtwdev->mutex); rtw_write32_clr(rtwdev, REG_TCR, BIT_TCR_UPDATE_HGQMD); + rtw_write16(rtwdev, REG_ATIMWND, ATIMWND_DEFAULT); rtwdev->ap_active = false; if (!rtw_core_check_sta_active(rtwdev)) rtw_clear_op_chan(rtwdev); diff --git a/drivers/net/wireless/realtek/rtw88/reg.h b/drivers/net/wireless/realtek/rtw88/reg.h index 08e9494977e0..0b9ba6f37680 100644 --- a/drivers/net/wireless/realtek/rtw88/reg.h +++ b/drivers/net/wireless/realtek/rtw88/reg.h @@ -483,6 +483,8 @@ #define REG_DRVERLYINT 0x0558 #define REG_BCNDMATIM 0x0559 #define REG_ATIMWND 0x055A +#define ATIMWND_DEFAULT 0x2 +#define ATIMWND_AP 0xa #define REG_USTIME_TSF 0x055C #define REG_BCN_MAX_ERR 0x055D #define REG_RXTSF_OFFSET_CCK 0x055E From 8cf894e2c6935bf29d5fbaa4d8e22eeb6640c1f3 Mon Sep 17 00:00:00 2001 From: Chin-Yen Lee Date: Fri, 11 Sep 2026 14:53:58 +0800 Subject: [PATCH 0553/2126] wifi: rtw89: pci: disable D3cold on ASUS ExpertBook B3/P3 series ASUS ExpertBook models (B3406CMA, B3606CMA, P3406CMA, and P3606CMA) may encounter PCIe link loss or recovery issues after entering the L2 low-power state associated with D3cold. Prevent these affected platforms from entering D3cold to avoid the problematic PCIe L2 state transition. Add a DMI quirk match table so that other non-affected platforms can continue utilizing D3cold power saving. Signed-off-by: Chin-Yen Lee Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260911065358.34375-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/pci.c | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c index 8c3f4eb52cc5..941fb5ca15b6 100644 --- a/drivers/net/wireless/realtek/rtw89/pci.c +++ b/drivers/net/wireless/realtek/rtw89/pci.c @@ -4766,6 +4766,49 @@ static const struct rtw89_hci_ops rtw89_pci_ops = { .rst_bdram = rtw89_pci_reset_bdram, }; +static void rtw89_pci_d3cold_quirks(struct rtw89_dev *rtwdev, struct pci_dev *pdev) +{ + static const struct dmi_system_id d3cold_quirks[] = { + { + .ident = "ASUS EXPERTBOOK B3406CMA", + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ASUS"), + DMI_MATCH(DMI_BOARD_NAME, "B3406CMA"), + }, + }, + { + .ident = "ASUS EXPERTBOOK B3606CMA", + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ASUS"), + DMI_MATCH(DMI_BOARD_NAME, "B3606CMA"), + }, + }, + { + .ident = "ASUS EXPERTBOOK P3406CMA", + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ASUS"), + DMI_MATCH(DMI_BOARD_NAME, "P3406CMA"), + }, + }, + { + .ident = "ASUS EXPERTBOOK P3606CMA", + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ASUS"), + DMI_MATCH(DMI_BOARD_NAME, "P3606CMA"), + }, + }, + {}, + }; + const struct dmi_system_id *match; + + match = dmi_first_match(d3cold_quirks); + if (!match) + return; + + rtw89_debug(rtwdev, RTW89_DBG_STATE, "Disable D3Cold on %s\n", match->ident); + pci_d3cold_disable(pdev); +} + int rtw89_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct rtw89_dev *rtwdev; @@ -4791,6 +4834,7 @@ int rtw89_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) rtwdev->hci.rpwm_addr = pci_info->rpwm_addr; rtwdev->hci.cpwm_addr = pci_info->cpwm_addr; + rtw89_pci_d3cold_quirks(rtwdev, pdev); rtw89_check_quirks(rtwdev, info->quirks); rtw89_check_pci_ssid_quirks(rtwdev, pdev, pci_info->ssid_quirks); From 2db269480b861517b34d6bec10daa8903784700a Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Fri, 11 Sep 2026 15:04:07 +0800 Subject: [PATCH 0554/2126] wifi: rtw89: coex: cancel RF band return condition at _set_bt_tx_power() Because RF band value 0 means 2 GHz and, if the condition set !rf_band return, the 2 GHz BT TX power will never been set. Correct the logic. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-wireless/aoXrgwyFu851qVNV@stanley.mountain/ Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260911070407.35803-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index e49d75cc55a1..b16af1291b93 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -3859,7 +3859,7 @@ static void _set_bt_tx_power(struct rtw89_dev *rtwdev, bool force_exec, u8 bid, u8 buf[2] = {}; u8 len = sizeof(*buf); - if (bt->bcnt[BTC_BCNT_INFOUPDATE] == 0 || !rf_band) + if (bt->bcnt[BTC_BCNT_INFOUPDATE] == 0) return; if (bt->rf_para.tx_pwr_freerun == level) From 43f6347e8bbe947d664f2ec3667c6cb6fb5e447e Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Fri, 11 Sep 2026 17:38:11 +0200 Subject: [PATCH 0555/2126] wifi: rtw88: 8703b: complete the card-disable to card-emulation transition On an RTL8723CS the driver cannot power the MAC on after a warm reboot: the power-on sequence waits forever for power ready and probe fails. rtw88_8723cs mmc2:0001:1: failed to poll offset=0x6 mask=0x2 value=0x2 rtw88_8723cs mmc2:0001:1: mac power on failed trans_carddis_to_cardemu_8703b has a single entry, clearing the hardware power-down bit. Its sibling trans_carddis_to_cardemu_8723d has six more, and 8822b and 8822c carry the same SDIO pair: withdraw the SDIO suspend request on local register 0x86 and wait for the interface to leave the suspended state, clear the WL suspend bit alongside the power-down bit, and take the 12H LDO out of sleep mode. The transition is the reverse of trans_cardemu_to_carddis_8703b, which sets 0x23[4] and asks the interface to suspend, so with those operations missing neither is ever undone. The chip then comes back with the WLAN MAC unpowered while the SDIO function still enumerates and CMD52 still works, and nothing in the sequence wakes it. rtw_mac_pre_system_cfg() does not cover it either: it returns early for 8051 wcpu chips, of which this is one. It survives a reboot on any board where WL_REG_ON is the only reset the host has and the chip's rail is not switchable. On the Denver TAQ-102 the pwrseq reset line, the BT enable line, the 32.768 kHz clock and every switchable PMIC rail were each toggled against a wedged chip and none of them cleared it, while the vendor driver recovered it every time. Take the operations 8723d has and this table lacks. That table's USB-only and PCI-only entries are left out: this chip has no such variant. Tested on an RTL8723CS over SDIO: recovers a chip left wedged by a previous boot, and survives repeated warm reboots and loader-mode flash cycles. Signed-off-by: Cristian Deluxe Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/178914109042.64584.1377616159988360897@cristiandeluxe.dev --- drivers/net/wireless/realtek/rtw88/rtw8703b.c | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw88/rtw8703b.c b/drivers/net/wireless/realtek/rtw88/rtw8703b.c index b5e7ae7ebd95..956b5093b9af 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8703b.c +++ b/drivers/net/wireless/realtek/rtw88/rtw8703b.c @@ -187,11 +187,39 @@ static const struct rtw_pwr_seq_cmd trans_pre_enable_8703b[] = { }; static const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8703b[] = { + /* clear WL suspend enable and HW power down enable */ {0x0005, RTW_PWR_CUT_ALL_MSK, RTW_PWR_INTF_ALL_MSK, RTW_PWR_ADDR_MAC, - RTW_PWR_CMD_WRITE, BIT(7), 0}, + RTW_PWR_CMD_WRITE, BIT(3) | BIT(7), 0}, + /* withdraw the SDIO suspend request */ + {0x0086, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_SDIO, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + /* and wait for the interface to leave the suspended state */ + {0x0086, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_SDIO, + RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, + /* disable WL suspend */ + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), 0}, + /* + * take the 12H LDO back out of sleep mode, which the card-disable + * transition put it into + */ + {0x0023, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(4), 0}, {TRANS_SEQ_END}, }; From 73e3b1c94c7d5b4a113e7cbb42665dc2fe3b9d78 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Fri, 11 Sep 2026 17:38:12 +0200 Subject: [PATCH 0556/2126] wifi: rtw88: 8703b: stop the PCIe DMA write reaching SDIO The first entry of trans_act_to_lps_8703b writes 0xff to MAC register 0x301 on every interface. That register is the PCIe DMA control, and both trans_act_to_lps_8723d and Realtek's own 8703b sequence header restrict the same entry to PCI, where it is commented "PCIe DMA stop". So on an RTL8723CS, which is SDIO only, every transition into low power poked a PCIe register for no reason. Restrict it the way the sibling chip and the vendor both do. Tested on an RTL8723CS over SDIO: the interface goes down and back up, reassociates and takes an address, and a warm reboot brings Wi-Fi back with no change in behaviour. Signed-off-by: Cristian Deluxe Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/178914109042.64584.11316164845616306056@cristiandeluxe.dev --- drivers/net/wireless/realtek/rtw88/rtw8703b.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw88/rtw8703b.c b/drivers/net/wireless/realtek/rtw88/rtw8703b.c index 956b5093b9af..42cfc8e62db8 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8703b.c +++ b/drivers/net/wireless/realtek/rtw88/rtw8703b.c @@ -440,7 +440,7 @@ static const struct rtw_pwr_seq_cmd trans_act_to_reset_mcu_8703b[] = { static const struct rtw_pwr_seq_cmd trans_act_to_lps_8703b[] = { {0x0301, RTW_PWR_CUT_ALL_MSK, - RTW_PWR_INTF_ALL_MSK, + RTW_PWR_INTF_PCI_MSK, RTW_PWR_ADDR_MAC, RTW_PWR_CMD_WRITE, 0xff, 0xff}, {0x0522, From 4e1b57b6895945e7f8282dafcc4db93e57a47134 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:27 +0200 Subject: [PATCH 0557/2126] wifi: iwlwifi: use link_sta internally to the driver Using the link_sta is a natural way to pass both the STA and the link ID information at the same time. Use that internally to the driver in preparation to mac80211 changing its API and adopting the same method. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.0b1269375e9e.I41df561f8129fac1327a07729cf4734b8752bcd6@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/intel/iwlwifi/mld/agg.c | 17 +++---- drivers/net/wireless/intel/iwlwifi/mld/agg.h | 4 +- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 45 ++++++++++--------- drivers/net/wireless/intel/iwlwifi/mld/rx.h | 2 +- .../wireless/intel/iwlwifi/mld/tests/agg.c | 7 +-- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/agg.c b/drivers/net/wireless/intel/iwlwifi/mld/agg.c index 96102d2af2cf..c45c47337509 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/agg.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/agg.c @@ -7,7 +7,8 @@ #include "hcmd.h" static void -iwl_mld_reorder_release_frames(struct iwl_mld *mld, struct ieee80211_sta *sta, +iwl_mld_reorder_release_frames(struct iwl_mld *mld, + struct ieee80211_link_sta *link_sta, struct napi_struct *napi, struct iwl_mld_baid_data *baid_data, struct iwl_mld_reorder_buffer *reorder_buf, @@ -32,7 +33,7 @@ iwl_mld_reorder_release_frames(struct iwl_mld *mld, struct ieee80211_sta *sta, while ((skb = __skb_dequeue(skb_list))) { iwl_mld_pass_packet_to_mac80211(mld, napi, skb, reorder_buf->queue, - sta); + link_sta); reorder_buf->num_stored--; } } @@ -74,7 +75,7 @@ static void iwl_mld_release_frames_from_notif(struct iwl_mld *mld, reorder_buf = &ba_data->reorder_buf[queue]; - iwl_mld_reorder_release_frames(mld, link_sta->sta, napi, ba_data, + iwl_mld_reorder_release_frames(mld, link_sta, napi, ba_data, reorder_buf, nssn); out_unlock: rcu_read_unlock(); @@ -180,7 +181,7 @@ void iwl_mld_del_ba(struct iwl_mld *mld, int queue, reorder_buf = &ba_data->reorder_buf[queue]; /* release all frames that are in the reorder buffer to the stack */ - iwl_mld_reorder_release_frames(mld, link_sta->sta, NULL, + iwl_mld_reorder_release_frames(mld, link_sta, NULL, ba_data, reorder_buf, ieee80211_sn_add(reorder_buf->head_sn, ba_data->buf_size)); @@ -193,7 +194,7 @@ out_unlock: */ enum iwl_mld_reorder_result iwl_mld_reorder(struct iwl_mld *mld, struct napi_struct *napi, - int queue, struct ieee80211_sta *sta, + int queue, struct ieee80211_link_sta *link_sta, struct sk_buff *skb, struct iwl_rx_mpdu_desc *desc) { struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb); @@ -228,12 +229,12 @@ iwl_mld_reorder(struct iwl_mld *mld, struct napi_struct *napi, return IWL_MLD_PASS_SKB; /* no sta yet */ - if (IWL_FW_CHECK(mld, !sta, + if (IWL_FW_CHECK(mld, !link_sta, "Got valid BAID without a valid station assigned - %d\n", baid)) return IWL_MLD_PASS_SKB; - mld_sta = iwl_mld_sta_from_mac80211(sta); + mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta); /* not a data packet */ if (!ieee80211_is_data_qos(hdr->frame_control) || @@ -324,7 +325,7 @@ iwl_mld_reorder(struct iwl_mld *mld, struct napi_struct *napi, * will be released when the frame release notification arrives. */ if (!amsdu || last_subframe) - iwl_mld_reorder_release_frames(mld, sta, napi, baid_data, + iwl_mld_reorder_release_frames(mld, link_sta, napi, baid_data, buffer, nssn); else if (buffer->num_stored == 1) buffer->head_sn = nssn; diff --git a/drivers/net/wireless/intel/iwlwifi/mld/agg.h b/drivers/net/wireless/intel/iwlwifi/mld/agg.h index 651c80d1c7cd..c6cd5fa219be 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/agg.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/agg.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024, 2026 Intel Corporation */ #ifndef __iwl_agg_h__ #define __iwl_agg_h__ @@ -106,7 +106,7 @@ int iwl_mld_ampdu_rx_stop(struct iwl_mld *mld, struct ieee80211_sta *sta, enum iwl_mld_reorder_result iwl_mld_reorder(struct iwl_mld *mld, struct napi_struct *napi, - int queue, struct ieee80211_sta *sta, + int queue, struct ieee80211_link_sta *link_sta, struct sk_buff *skb, struct iwl_rx_mpdu_desc *desc); void iwl_mld_handle_frame_release_notif(struct iwl_mld *mld, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 269439d789f4..5696a247922b 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -47,7 +47,8 @@ iwl_mld_fill_phy_data_from_mpdu(struct iwl_mld *mld, } static inline int iwl_mld_check_pn(struct iwl_mld *mld, struct sk_buff *skb, - int queue, struct ieee80211_sta *sta) + int queue, + struct ieee80211_link_sta *link_sta) { struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb); struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb); @@ -71,13 +72,13 @@ static inline int iwl_mld_check_pn(struct iwl_mld *mld, struct sk_buff *skb, return 0; /* if we are here - this for sure is either CCMP or GCMP */ - if (!sta) { + if (!link_sta) { IWL_DEBUG_DROP(mld, "expected hw-decrypted unicast frame for station\n"); return -1; } - mld_sta = iwl_mld_sta_from_mac80211(sta); + mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta); extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control); keyidx = extiv[3] >> 6; @@ -119,17 +120,17 @@ static inline int iwl_mld_check_pn(struct iwl_mld *mld, struct sk_buff *skb, void iwl_mld_pass_packet_to_mac80211(struct iwl_mld *mld, struct napi_struct *napi, struct sk_buff *skb, int queue, - struct ieee80211_sta *sta) + struct ieee80211_link_sta *link_sta) { KUNIT_STATIC_STUB_REDIRECT(iwl_mld_pass_packet_to_mac80211, - mld, napi, skb, queue, sta); + mld, napi, skb, queue, link_sta); - if (unlikely(iwl_mld_check_pn(mld, skb, queue, sta))) { + if (unlikely(iwl_mld_check_pn(mld, skb, queue, link_sta))) { kfree_skb(skb); return; } - ieee80211_rx_napi(mld->hw, sta, skb, napi); + ieee80211_rx_napi(mld->hw, link_sta->sta, skb, napi); } EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_pass_packet_to_mac80211); @@ -1728,7 +1729,7 @@ static void iwl_mld_update_last_rx_timestamp(struct iwl_mld *mld, u8 baid) * Sets *drop to true if the packet should be dropped. * Returns the station if found, or NULL otherwise. */ -static struct ieee80211_sta * +static struct ieee80211_link_sta * iwl_mld_rx_with_sta(struct iwl_mld *mld, struct ieee80211_hdr *hdr, struct sk_buff *skb, const struct iwl_rx_mpdu_desc *mpdu_desc, @@ -1803,10 +1804,10 @@ iwl_mld_rx_with_sta(struct iwl_mld *mld, struct ieee80211_hdr *hdr, queue); } - return sta; + return link_sta; } -static int iwl_mld_rx_mgmt_prot(struct ieee80211_sta *sta, +static int iwl_mld_rx_mgmt_prot(struct ieee80211_link_sta *link_sta, struct ieee80211_hdr *hdr, struct ieee80211_rx_status *rx_status, u32 mpdu_status, @@ -1820,7 +1821,6 @@ static int iwl_mld_rx_mgmt_prot(struct ieee80211_sta *sta, struct ieee80211_key_conf *key; const u8 *frame = (void *)hdr; const u8 *mmie; - u8 link_id; if ((mpdu_status & IWL_RX_MPDU_STATUS_SEC_MASK) == IWL_RX_MPDU_STATUS_SEC_NONE) @@ -1836,10 +1836,10 @@ static int iwl_mld_rx_mgmt_prot(struct ieee80211_sta *sta, if (!ieee80211_is_beacon(hdr->frame_control)) return 0; - if (!sta) + if (!link_sta) return -1; - mld_sta = iwl_mld_sta_from_mac80211(sta); + mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta); mld_vif = iwl_mld_vif_from_mac80211(mld_sta->vif); /* key mismatch - will also report !MIC_OK but we shouldn't count it */ @@ -1853,8 +1853,7 @@ static int iwl_mld_rx_mgmt_prot(struct ieee80211_sta *sta, return 0; } - link_id = rx_status->link_valid ? rx_status->link_id : 0; - link = rcu_dereference(mld_vif->link[link_id]); + link = rcu_dereference(mld_vif->link[link_sta->link_id]); if (WARN_ON_ONCE(!link)) return -1; @@ -1905,7 +1904,7 @@ report: } static int iwl_mld_rx_crypto(struct iwl_mld *mld, - struct ieee80211_sta *sta, + struct ieee80211_link_sta *link_sta, struct ieee80211_hdr *hdr, struct ieee80211_rx_status *rx_status, struct iwl_rx_mpdu_desc *desc, int queue, @@ -1915,7 +1914,7 @@ static int iwl_mld_rx_crypto(struct iwl_mld *mld, if (unlikely(ieee80211_is_mgmt(hdr->frame_control) && !ieee80211_has_protected(hdr->frame_control))) - return iwl_mld_rx_mgmt_prot(sta, hdr, rx_status, status, + return iwl_mld_rx_mgmt_prot(link_sta, hdr, rx_status, status, le16_to_cpu(desc->mpdu_len)); if (!ieee80211_has_protected(hdr->frame_control) || @@ -2023,7 +2022,7 @@ void iwl_mld_rx_mpdu(struct iwl_mld *mld, struct napi_struct *napi, struct iwl_rx_packet *pkt = rxb_addr(rxb); struct iwl_mld_rx_phy_data phy_data = {}; struct iwl_rx_mpdu_desc *mpdu_desc = (void *)pkt->data; - struct ieee80211_sta *sta; + struct ieee80211_link_sta *link_sta; struct ieee80211_hdr *hdr; struct sk_buff *skb; size_t mpdu_desc_size = sizeof(*mpdu_desc); @@ -2086,7 +2085,8 @@ void iwl_mld_rx_mpdu(struct iwl_mld *mld, struct napi_struct *napi, rcu_read_lock(); - sta = iwl_mld_rx_with_sta(mld, hdr, skb, mpdu_desc, pkt, queue, &drop); + link_sta = iwl_mld_rx_with_sta(mld, hdr, skb, mpdu_desc, pkt, queue, + &drop); if (drop) goto drop; @@ -2127,7 +2127,7 @@ void iwl_mld_rx_mpdu(struct iwl_mld *mld, struct napi_struct *napi, iwl_mld_rx_fill_status(mld, link_id, hdr, skb, &phy_data); - if (iwl_mld_rx_crypto(mld, sta, hdr, rx_status, mpdu_desc, queue, + if (iwl_mld_rx_crypto(mld, link_sta, hdr, rx_status, mpdu_desc, queue, le32_to_cpu(pkt->len_n_flags), &crypto_len)) goto drop; @@ -2140,7 +2140,8 @@ void iwl_mld_rx_mpdu(struct iwl_mld *mld, struct napi_struct *napi, if (iwl_mld_time_sync_frame(mld, skb, hdr->addr2)) goto out; - reorder_res = iwl_mld_reorder(mld, napi, queue, sta, skb, mpdu_desc); + reorder_res = iwl_mld_reorder(mld, napi, queue, link_sta, skb, + mpdu_desc); switch (reorder_res) { case IWL_MLD_PASS_SKB: break; @@ -2153,7 +2154,7 @@ void iwl_mld_rx_mpdu(struct iwl_mld *mld, struct napi_struct *napi, goto drop; } - iwl_mld_pass_packet_to_mac80211(mld, napi, skb, queue, sta); + iwl_mld_pass_packet_to_mac80211(mld, napi, skb, queue, link_sta); goto out; diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.h b/drivers/net/wireless/intel/iwlwifi/mld/rx.h index 573b89c3c9c6..b08c5ade3db8 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.h @@ -69,7 +69,7 @@ void iwl_mld_handle_rsc_notif(struct iwl_mld *mld, void iwl_mld_pass_packet_to_mac80211(struct iwl_mld *mld, struct napi_struct *napi, struct sk_buff *skb, int queue, - struct ieee80211_sta *sta); + struct ieee80211_link_sta *link_sta); void iwl_mld_handle_phy_air_sniffer_notif(struct iwl_mld *mld, struct napi_struct *napi, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tests/agg.c b/drivers/net/wireless/intel/iwlwifi/mld/tests/agg.c index 29b0248cec3d..e9efe2996f07 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tests/agg.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tests/agg.c @@ -2,7 +2,7 @@ /* * KUnit tests for channel helper functions * - * Copyright (C) 2024-2025 Intel Corporation + * Copyright (C) 2024-2026 Intel Corporation */ #include #include @@ -441,7 +441,7 @@ static void fake_iwl_mld_pass_packet_to_mac80211(struct iwl_mld *mld, struct napi_struct *napi, struct sk_buff *skb, int queue, - struct ieee80211_sta *sta) + struct ieee80211_link_sta *link_sta) { __skb_queue_tail(&g_released_skbs, skb); g_num_released_skbs++; @@ -630,7 +630,8 @@ static void test_reorder_buffer(struct kunit *test) mpdu_desc = setup_mpdu_desc(); rcu_read_lock(); - reorder_res = iwl_mld_reorder(mld, NULL, QUEUE, sta, skb, mpdu_desc); + reorder_res = iwl_mld_reorder(mld, NULL, QUEUE, &sta->deflink, skb, + mpdu_desc); rcu_read_unlock(); KUNIT_ASSERT_EQ(test, reorder_res, param->expected.reorder_res); From a8188bb7644f6416c7c16f4964b45ea1b40afcfc Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:28 +0200 Subject: [PATCH 0558/2126] wifi: mac80211: change public RX API to use link stations If a station is passed then the link ID also needs to be known. As such, it is a more natural API to simply pass the link station directly rather than pushing the link information into the RX status. Furthermore, having the link ID in the RX status is not actually correct because the link IDs are VIF specific and there may be multiple VIFs. In the case of a station this relationship is clear, but then one may as well use the link station. This patch only changes the API and emulates the old (incorrect) behaviour for now. The mac80211 RX code will be updated in later patches. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.06f41565116a.I4a2d45609e94b52654b10ec572e59a45d09c41f4@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/ath11k/dp_rx.c | 2 +- drivers/net/wireless/ath/ath12k/dp_mon.c | 2 -- drivers/net/wireless/ath/ath12k/dp_rx.c | 20 ++++++++++++--- drivers/net/wireless/ath/ath12k/hw.h | 20 ++++++++------- drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 20 +++++++-------- drivers/net/wireless/ath/ath12k/wifi7/dp_rx.h | 12 ++++----- drivers/net/wireless/ath/ath12k/wifi7/hw.c | 6 ++--- drivers/net/wireless/ath/ath12k/wmi.c | 6 ----- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 7 +----- drivers/net/wireless/intel/iwlwifi/mvm/rx.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 6 ++--- drivers/net/wireless/mediatek/mt76/mac80211.c | 25 +++++++++++-------- drivers/net/wireless/realtek/rtw89/core.c | 7 ------ .../wireless/virtual/mac80211_hwsim_main.c | 3 --- include/net/mac80211.h | 16 +++++++++--- net/mac80211/rx.c | 20 +++++++++++---- 16 files changed, 92 insertions(+), 82 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index 33425707c084..fbb3d18f55dd 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -2500,7 +2500,7 @@ static void ath11k_dp_rx_deliver_msdu(struct ath11k *ar, struct napi_struct *nap !(is_mcbc && rx_status->flag & RX_FLAG_DECRYPTED)) rx_status->flag |= RX_FLAG_8023; - ieee80211_rx_napi(ar->hw, pubsta, msdu, napi); + ieee80211_rx_napi(ar->hw, pubsta ? &pubsta->deflink : NULL, msdu, napi); } static bool ath11k_dp_rx_check_nwifi_hdr_len_valid(struct ath11k_base *ab, diff --git a/drivers/net/wireless/ath/ath12k/dp_mon.c b/drivers/net/wireless/ath/ath12k/dp_mon.c index 7d5be77b081f..1faf1896d0ab 100644 --- a/drivers/net/wireless/ath/ath12k/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/dp_mon.c @@ -503,8 +503,6 @@ void ath12k_dp_mon_rx_deliver_msdu(struct ath12k_pdev_dp *dp_pdev, struct ieee80211_rx_status *rx_status; struct ieee80211_radiotap_he *he = NULL; - status->link_valid = 0; - if ((status->encoding == RX_ENC_HE) && !(status->flag & RX_FLAG_RADIOTAP_HE) && !(status->flag & RX_FLAG_SKIP_MONITOR)) { he = skb_push(msdu, sizeof(known)); diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c index 8fa0e90b4531..41ac0a4072ae 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/dp_rx.c @@ -1375,6 +1375,7 @@ void ath12k_dp_rx_deliver_msdu(struct ath12k_pdev_dp *dp_pdev, struct napi_struc struct ath12k_dp *dp = dp_pdev->dp; struct ieee80211_rx_status *rx_status; struct ieee80211_sta *pubsta; + struct ieee80211_link_sta *link_pubsta = NULL; struct ath12k_dp_peer *peer; struct ath12k_skb_rxcb *rxcb = ATH12K_SKB_RXCB(msdu); struct ieee80211_rx_status *status = rx_info->rx_status; @@ -1384,9 +1385,19 @@ void ath12k_dp_rx_deliver_msdu(struct ath12k_pdev_dp *dp_pdev, struct napi_struc pubsta = peer ? peer->sta : NULL; - status->link_valid = 0; - if (pubsta && pubsta->valid_links) - ath12k_hw_set_rx_link_id(dp->hw_params, peer, rxcb, status); + if (pubsta) { + if (pubsta->valid_links) { + int link_id = + ath12k_hw_get_rx_link_id(dp->hw_params, peer, + rxcb, status); + + if (link_id >= 0) + link_pubsta = + rcu_dereference(pubsta->link[link_id]); + } else { + link_pubsta = &pubsta->deflink; + } + } ath12k_dbg(dp->ab, ATH12K_DBG_DATA, "rx skb %p len %u peer %pM %d %s sn %u %s%s%s%s%s%s%s%s%s%s rate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n", @@ -1422,7 +1433,8 @@ void ath12k_dp_rx_deliver_msdu(struct ath12k_pdev_dp *dp_pdev, struct napi_struc /* TODO: trace rx packet */ - ieee80211_rx_napi(ath12k_pdev_dp_to_hw(dp_pdev), pubsta, msdu, napi); + ieee80211_rx_napi(ath12k_pdev_dp_to_hw(dp_pdev), link_pubsta, msdu, + napi); } EXPORT_SYMBOL(ath12k_dp_rx_deliver_msdu); diff --git a/drivers/net/wireless/ath/ath12k/hw.h b/drivers/net/wireless/ath/ath12k/hw.h index 011bb22e21c7..e790de5737db 100644 --- a/drivers/net/wireless/ath/ath12k/hw.h +++ b/drivers/net/wireless/ath/ath12k/hw.h @@ -249,9 +249,9 @@ struct ath12k_hw_ops { bool (*dp_srng_is_tx_comp_ring)(int ring_num); bool (*is_frame_link_agnostic)(struct ath12k_link_vif *arvif, struct ieee80211_mgmt *mgmt); - void (*set_rx_link_id)(struct ath12k_dp_peer *dp_peer, - struct ath12k_skb_rxcb *rxcb, - struct ieee80211_rx_status *status); + int (*get_rx_link_id)(struct ath12k_dp_peer *dp_peer, + struct ath12k_skb_rxcb *rxcb, + struct ieee80211_rx_status *status); }; static inline @@ -282,13 +282,15 @@ static inline int ath12k_hw_mac_id_to_srng_id(const struct ath12k_hw_params *hw, return 0; } -static inline void ath12k_hw_set_rx_link_id(const struct ath12k_hw_params *hw, - struct ath12k_dp_peer *dp_peer, - struct ath12k_skb_rxcb *rxcb, - struct ieee80211_rx_status *status) +static inline int ath12k_hw_get_rx_link_id(const struct ath12k_hw_params *hw, + struct ath12k_dp_peer *dp_peer, + struct ath12k_skb_rxcb *rxcb, + struct ieee80211_rx_status *status) { - if (hw->hw_ops->set_rx_link_id) - hw->hw_ops->set_rx_link_id(dp_peer, rxcb, status); + if (hw->hw_ops->get_rx_link_id) + return hw->hw_ops->get_rx_link_id(dp_peer, rxcb, status); + + return -1; } struct ath12k_fw_ie { diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index 95d87dd67872..8b722ee0ad8f 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -2317,17 +2317,16 @@ ath12k_wifi7_dp_rxdesc_mpdu_valid(struct ath12k_base *ab, return tlv_tag == HAL_RX_MPDU_START; } -void -ath12k_wifi7_dp_rx_set_link_id_qcn9274(struct ath12k_dp_peer *dp_peer, +int +ath12k_wifi7_dp_rx_get_link_id_qcn9274(struct ath12k_dp_peer *dp_peer, struct ath12k_skb_rxcb *rxcb, struct ieee80211_rx_status *status) { - status->link_valid = 1; - status->link_id = dp_peer->hw_links[rxcb->hw_link_id]; + return dp_peer->hw_links[rxcb->hw_link_id]; } -void -ath12k_wifi7_dp_rx_set_link_id_wcn7850(struct ath12k_dp_peer *dp_peer, +int +ath12k_wifi7_dp_rx_get_link_id_wcn7850(struct ath12k_dp_peer *dp_peer, struct ath12k_skb_rxcb *rxcb, struct ieee80211_rx_status *status) { @@ -2341,10 +2340,9 @@ ath12k_wifi7_dp_rx_set_link_id_wcn7850(struct ath12k_dp_peer *dp_peer, links_map = READ_ONCE(dp_peer->link_peers_map); for_each_set_bit(i, &links_map, ATH12K_NUM_MAX_LINKS) { link_peer = rcu_dereference(dp_peer->link_peers[i]); - if (link_peer && link_peer->peer_id == rxcb->peer_id) { - status->link_valid = 1; - status->link_id = link_peer->link_id; - return; - } + if (link_peer && link_peer->peer_id == rxcb->peer_id) + return link_peer->link_id; } + + return -1; } diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.h b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.h index 1d3a4788a2dd..d68489ff7b03 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.h +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.h @@ -57,10 +57,10 @@ ath12k_wifi7_dp_rxdesc_mpdu_valid(struct ath12k_base *ab, struct hal_rx_desc *rx_desc); int ath12k_wifi7_dp_rx_tid_delete_handler(struct ath12k_base *ab, struct ath12k_dp_rx_tid_rxq *rx_tid); -void ath12k_wifi7_dp_rx_set_link_id_qcn9274(struct ath12k_dp_peer *dp_peer, - struct ath12k_skb_rxcb *rxcb, - struct ieee80211_rx_status *status); -void ath12k_wifi7_dp_rx_set_link_id_wcn7850(struct ath12k_dp_peer *dp_peer, - struct ath12k_skb_rxcb *rxcb, - struct ieee80211_rx_status *status); +int ath12k_wifi7_dp_rx_get_link_id_qcn9274(struct ath12k_dp_peer *dp_peer, + struct ath12k_skb_rxcb *rxcb, + struct ieee80211_rx_status *status); +int ath12k_wifi7_dp_rx_get_link_id_wcn7850(struct ath12k_dp_peer *dp_peer, + struct ath12k_skb_rxcb *rxcb, + struct ieee80211_rx_status *status); #endif diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index 7b86f324b2e6..4ded807763b6 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -158,7 +158,7 @@ static const struct ath12k_hw_ops qcn9274_ops = { .get_ring_selector = ath12k_wifi7_hw_get_ring_selector_qcn9274, .dp_srng_is_tx_comp_ring = ath12k_wifi7_dp_srng_is_comp_ring_qcn9274, .is_frame_link_agnostic = ath12k_wifi7_is_frame_link_agnostic_qcn9274, - .set_rx_link_id = ath12k_wifi7_dp_rx_set_link_id_qcn9274, + .get_rx_link_id = ath12k_wifi7_dp_rx_get_link_id_qcn9274, }; static const struct ath12k_hw_ops wcn7850_ops = { @@ -169,7 +169,7 @@ static const struct ath12k_hw_ops wcn7850_ops = { .get_ring_selector = ath12k_wifi7_hw_get_ring_selector_wcn7850, .dp_srng_is_tx_comp_ring = ath12k_wifi7_dp_srng_is_comp_ring_wcn7850, .is_frame_link_agnostic = ath12k_wifi7_is_frame_link_agnostic_wcn7850, - .set_rx_link_id = ath12k_wifi7_dp_rx_set_link_id_wcn7850, + .get_rx_link_id = ath12k_wifi7_dp_rx_get_link_id_wcn7850, }; static const struct ath12k_hw_ops qcc2072_ops = { @@ -180,7 +180,7 @@ static const struct ath12k_hw_ops qcc2072_ops = { .get_ring_selector = ath12k_wifi7_hw_get_ring_selector_wcn7850, .dp_srng_is_tx_comp_ring = ath12k_wifi7_dp_srng_is_comp_ring_wcn7850, .is_frame_link_agnostic = ath12k_wifi7_is_frame_link_agnostic_wcn7850, - .set_rx_link_id = ath12k_wifi7_dp_rx_set_link_id_wcn7850, + .get_rx_link_id = ath12k_wifi7_dp_rx_get_link_id_wcn7850, }; #define ATH12K_TX_RING_MASK_0 0x1 diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c index d5160af60e00..7e3655966f02 100644 --- a/drivers/net/wireless/ath/ath12k/wmi.c +++ b/drivers/net/wireless/ath/ath12k/wmi.c @@ -7271,7 +7271,6 @@ static void ath12k_mgmt_rx_event(struct ath12k_base *ab, struct sk_buff *skb) struct ath12k_wmi_mgmt_rx_arg rx_ev = {}; struct ath12k *ar; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); - struct ieee80211_sta *pubsta = NULL; struct ath12k_dp_link_peer *peer; struct ieee80211_hdr *hdr; bool is_4addr_null_pkt; @@ -7373,11 +7372,6 @@ static void ath12k_mgmt_rx_event(struct ath12k_base *ab, struct sk_buff *skb) dev_kfree_skb(skb); goto exit; } - pubsta = peer->sta; - if (pubsta && pubsta->valid_links) { - status->link_valid = 1; - status->link_id = peer->link_id; - } spin_unlock_bh(&dp->dp_lock); goto send_rx; } diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 5696a247922b..02bdf6ccbcdc 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -130,7 +130,7 @@ void iwl_mld_pass_packet_to_mac80211(struct iwl_mld *mld, return; } - ieee80211_rx_napi(mld->hw, link_sta->sta, skb, napi); + ieee80211_rx_napi(mld->hw, link_sta, skb, napi); } EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_pass_packet_to_mac80211); @@ -1765,11 +1765,6 @@ iwl_mld_rx_with_sta(struct iwl_mld *mld, struct ieee80211_hdr *hdr, rx_status = IEEE80211_SKB_RXCB(skb); - if (link_sta && sta->valid_links) { - rx_status->link_valid = true; - rx_status->link_id = link_sta->link_id; - } - /* fill checksum */ if (ieee80211_is_data(hdr->frame_control) && pkt->len_n_flags & cpu_to_le32(FH_RSCSR_RPA_EN)) { diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rx.c b/drivers/net/wireless/intel/iwlwifi/mvm/rx.c index ab1eb2eb0c3c..8c197a090c2b 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rx.c @@ -90,7 +90,7 @@ static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, fraglen, rxb->truesize); } - ieee80211_rx_napi(mvm->hw, sta, skb, napi); + ieee80211_rx_napi(mvm->hw, sta ? &sta->deflink : NULL, skb, napi); } /* diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c index 7f0b4f5daa21..8c4009d3a00c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2012-2014, 2018-2025 Intel Corporation + * Copyright (C) 2012-2014, 2018-2026 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2015-2017 Intel Deutschland GmbH */ @@ -243,7 +243,7 @@ static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, return; } - ieee80211_rx_napi(mvm->hw, sta, skb, napi); + ieee80211_rx_napi(mvm->hw, sta ? &sta->deflink : NULL, skb, napi); } static bool iwl_mvm_used_average_energy(struct iwl_mvm *mvm, @@ -2528,7 +2528,7 @@ void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi, } rcu_read_lock(); - ieee80211_rx_napi(mvm->hw, sta, skb, napi); + ieee80211_rx_napi(mvm->hw, sta ? &sta->deflink : NULL, skb, napi); rcu_read_unlock(); } diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index abbe65cbcd89..cda5c5d51aab 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1255,11 +1255,12 @@ EXPORT_SYMBOL(mt76_rx_signal); static void mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb, struct ieee80211_hw **hw, - struct ieee80211_sta **sta) + struct ieee80211_link_sta **link_sta) { struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb); struct mt76_rx_status mstat; + struct ieee80211_sta *sta; mstat = *((struct mt76_rx_status *)skb->cb); memset(status, 0, sizeof(*status)); @@ -1301,12 +1302,14 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb, memcpy(status->chain_signal, mstat.chain_signal, sizeof(mstat.chain_signal)); - if (mstat.wcid) { - status->link_valid = mstat.wcid->link_valid; - status->link_id = mstat.wcid->link_id; - } + sta = wcid_to_sta(mstat.wcid); + if (!sta) + *link_sta = NULL; + else if (mstat.wcid->link_valid) + *link_sta = rcu_dereference(sta->link[mstat.wcid->link_id]); + else + *link_sta = &sta->deflink; - *sta = wcid_to_sta(mstat.wcid); *hw = mt76_phy_hw(dev, mstat.phy_idx); } @@ -1530,7 +1533,7 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb) void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, struct napi_struct *napi) { - struct ieee80211_sta *sta; + struct ieee80211_link_sta *link_sta; struct ieee80211_hw *hw; struct sk_buff *skb, *tmp; LIST_HEAD(list); @@ -1541,8 +1544,8 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, mt76_check_ccmp_pn(skb); skb_shinfo(skb)->frag_list = NULL; - mt76_rx_convert(dev, skb, &hw, &sta); - ieee80211_rx_list(hw, sta, skb, &list); + mt76_rx_convert(dev, skb, &hw, &link_sta); + ieee80211_rx_list(hw, link_sta, skb, &list); /* subsequent amsdu frames */ while (nskb) { @@ -1550,8 +1553,8 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, nskb = nskb->next; skb->next = NULL; - mt76_rx_convert(dev, skb, &hw, &sta); - ieee80211_rx_list(hw, sta, skb, &list); + mt76_rx_convert(dev, skb, &hw, &link_sta); + ieee80211_rx_list(hw, link_sta, skb, &list); } } spin_unlock(&dev->rx_lock); diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 397ebbfcac09..454d876aeb88 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -3073,10 +3073,8 @@ static void rtw89_vif_rx_stats_iter(void *data, u8 *mac, struct rtw89_vif *rtwvif = vif_to_rtwvif(vif); struct rtw89_rx_desc_info *desc_info = iter_data->desc_info; struct sk_buff *skb = iter_data->skb; - struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct rtw89_rx_phy_ppdu *phy_ppdu = iter_data->phy_ppdu; - bool is_mld = ieee80211_vif_is_mld(vif); struct ieee80211_bss_conf *bss_conf; struct rtw89_vif_link *rtwvif_link; const u8 *bssid = iter_data->bssid; @@ -3110,11 +3108,6 @@ static void rtw89_vif_rx_stats_iter(void *data, u8 *mac, if (!ether_addr_equal(target_bssid, bssid)) goto out; - if (is_mld) { - rx_status->link_valid = true; - rx_status->link_id = rtwvif_link->link_id; - } - bb = rtw89_get_bb_ctx(rtwdev, rtwvif_link->phy_idx); pkt_stat = &bb->cur_pkt_stat; diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 9f895ad718e9..1a12261f3e8e 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -1883,9 +1883,6 @@ static void mac80211_hwsim_rx(struct mac80211_hwsim_data *data, sp->active_links_rx &= ~BIT(link_id); else sp->active_links_rx |= BIT(link_id); - - rx_status->link_valid = true; - rx_status->link_id = link_id; } rcu_read_unlock(); } diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 7bb4618065b6..cba7cdf61ce8 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -5389,14 +5389,18 @@ void ieee80211_restart_hw(struct ieee80211_hw *hw); * mixed for a single hardware. Must not run concurrently with * ieee80211_tx_status_skb() or ieee80211_tx_status_ni(). * + * For data frames, when hardware has done address translation, a link station + * has to be provided and the frequency information may be skipped. + * * This function must be called with BHs disabled and RCU read lock * * @hw: the hardware this frame came in on - * @sta: the station the frame was received from, or %NULL + * @link_sta: the link station the data frame was received from, or %NULL * @skb: the buffer to receive, owned by mac80211 after this call * @list: the destination list */ -void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *sta, +void ieee80211_rx_list(struct ieee80211_hw *hw, + struct ieee80211_link_sta *link_sta, struct sk_buff *skb, struct list_head *list); /** @@ -5414,14 +5418,18 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *sta, * mixed for a single hardware. Must not run concurrently with * ieee80211_tx_status_skb() or ieee80211_tx_status_ni(). * + * For data frames, when hardware has done address translation, a link station + * has to be provided and the frequency information may be skipped. + * * This function must be called with BHs disabled. * * @hw: the hardware this frame came in on - * @sta: the station the frame was received from, or %NULL + * @link_sta: the link station the data frame was received from, or %NULL * @skb: the buffer to receive, owned by mac80211 after this call * @napi: the NAPI context */ -void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *sta, +void ieee80211_rx_napi(struct ieee80211_hw *hw, + struct ieee80211_link_sta *link_sta, struct sk_buff *skb, struct napi_struct *napi); /** diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 31dc6f83781b..0ddd0b8ea12a 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -5556,7 +5556,8 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, * This is the receive path handler. It is called by a low level driver when an * 802.11 MPDU is received from the hardware. */ -void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, +void ieee80211_rx_list(struct ieee80211_hw *hw, + struct ieee80211_link_sta *link_pubsta, struct sk_buff *skb, struct list_head *list) { struct ieee80211_local *local = hw_to_local(hw); @@ -5564,6 +5565,7 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, struct ieee80211_supported_band *sband; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + struct ieee80211_sta *pubsta; WARN_ON_ONCE(softirq_count() == 0); @@ -5694,8 +5696,15 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, } } - if (WARN_ON_ONCE(status->link_id >= IEEE80211_LINK_UNSPECIFIED)) - goto drop; + /* FIXME: Emulate the old driver behaviour for now */ + if (link_pubsta) { + status->link_valid = 1; + status->link_id = link_pubsta->link_id; + pubsta = link_pubsta->sta; + } else { + status->link_valid = 0; + pubsta = NULL; + } status->rx_flags = 0; @@ -5727,7 +5736,8 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, } EXPORT_SYMBOL(ieee80211_rx_list); -void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, +void ieee80211_rx_napi(struct ieee80211_hw *hw, + struct ieee80211_link_sta *link_pubsta, struct sk_buff *skb, struct napi_struct *napi) { struct sk_buff *tmp; @@ -5740,7 +5750,7 @@ void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, * receive processing */ rcu_read_lock(); - ieee80211_rx_list(hw, pubsta, skb, &list); + ieee80211_rx_list(hw, link_pubsta, skb, &list); rcu_read_unlock(); if (!napi) { From 4db13371e217c360cda76578f9eb5e1bcd10a17a Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:29 +0200 Subject: [PATCH 0559/2126] wifi: mac80211: refactor RX link_id and station handling The link ID for one frequency may be different between VIFs. As such, the sensible thing is to set the link ID later in the flow once the SKB is duplicated for each VIF. As the link ID is not passed in from outside mac80211 it is always valid and the corresponding bit can be dropped. Also switch a few more places to pass the link STA as that is a natural way to pass the link information around. This fixes the per-link statistics when frames are reordered. Note that this patch deliberately leaves some places unchanged and even incorrect as this will be addressed by further refactorings. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.467593bc1105.I8abe3601d0335dca22d48bcee864817cfccf0de0@changeid Signed-off-by: Johannes Berg --- include/net/mac80211.h | 9 +- net/mac80211/ap.c | 3 - net/mac80211/iface.c | 7 +- net/mac80211/mlme.c | 10 +- net/mac80211/rx.c | 211 ++++++++++++++++++----------------------- net/mac80211/scan.c | 10 +- 6 files changed, 106 insertions(+), 144 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index cba7cdf61ce8..1172d7b83ed1 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1770,10 +1770,9 @@ enum mac80211_rx_encoding { * @ampdu_reference: A-MPDU reference number, must be a different value for * each A-MPDU but the same for each subframe within one A-MPDU * @zero_length_psdu_type: radiotap type of the 0-length PSDU - * @link_valid: if the link which is identified by @link_id is valid. This flag - * is set only when connection is MLO. - * @link_id: id of the link used to receive the packet. This is used along with - * @link_valid. + * @link_id: id of the link used to receive the packet. Set and used by + * mac80211 internally, it uses @freq set by the driver to identify the + * correct link per vif. */ struct ieee80211_rx_status { u64 mactime; @@ -1813,7 +1812,7 @@ struct ieee80211_rx_status { u8 chains; s8 chain_signal[IEEE80211_MAX_CHAINS]; u8 zero_length_psdu_type; - u8 link_valid:1, link_id:4; + u8 link_id:4; }; static_assert(sizeof(struct ieee80211_rx_status) <= sizeof_field(struct sk_buff, cb)); diff --git a/net/mac80211/ap.c b/net/mac80211/ap.c index e7ac99c5a22e..fe255891c35f 100644 --- a/net/mac80211/ap.c +++ b/net/mac80211/ap.c @@ -82,9 +82,6 @@ ieee80211_rx_eml_op_mode_notif(struct ieee80211_sub_if_data *sdata, if (!ift_ext_capa) return; - if (!status->link_valid) - return; - sta = sta_info_get_bss(sdata, mgmt->sa); if (!sta) return; diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 18e62c5ff0fd..29d532183814 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -1674,11 +1674,8 @@ static void ieee80211_iface_process_skb(struct ieee80211_local *local, break; status = IEEE80211_SKB_RXCB(skb); - if (!status->link_valid) - link_sta = &sta->deflink; - else - link_sta = rcu_dereference_protected(sta->link[status->link_id], - lockdep_is_held(&local->hw.wiphy->mtx)); + link_sta = wiphy_dereference(local->hw.wiphy, + sta->link[status->link_id]); if (link_sta) ieee80211_ht_handle_chanwidth_notif(local, sdata, sta, link_sta, chanwidth, diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 47ec703f1094..189dd3467f76 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -11827,12 +11827,10 @@ void ieee80211_sta_rx_queued_frame(struct ieee80211_sub_if_data *sdata, rx_status = (struct ieee80211_rx_status *) skb->cb; fc = le16_to_cpu(mgmt->frame_control); - if (rx_status->link_valid) { - link = sdata_dereference(sdata->link[rx_status->link_id], - sdata); - if (!link) - return; - } + link = sdata_dereference(sdata->link[rx_status->link_id], + sdata); + if (!link) + return; switch (fc & IEEE80211_FCTL_STYPE) { case IEEE80211_STYPE_BEACON: diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 0ddd0b8ea12a..753d639d1955 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -222,43 +222,21 @@ ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local, } static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata, - int link_id, - struct sta_info *sta, + struct link_sta_info *link_sta, struct sk_buff *skb) { - struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); - - if (link_id >= 0) { - status->link_valid = 1; - status->link_id = link_id; - } else { - status->link_valid = 0; - } - skb_queue_tail(&sdata->skb_queue, skb); wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); - if (sta) { - struct link_sta_info *link_sta_info; - - if (link_id >= 0) { - link_sta_info = rcu_dereference(sta->link[link_id]); - if (!link_sta_info) - return; - } else { - link_sta_info = &sta->deflink; - } - - link_sta_info->rx_stats.packets++; - } + if (link_sta) + link_sta->rx_stats.packets++; } static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata, - int link_id, - struct sta_info *sta, + struct link_sta_info *link_sta, struct sk_buff *skb) { skb->protocol = 0; - __ieee80211_queue_skb_to_iface(sdata, link_id, sta, skb); + __ieee80211_queue_skb_to_iface(sdata, link_sta, skb); } static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata, @@ -301,7 +279,7 @@ static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata, if (!skb) return; - ieee80211_queue_skb_to_iface(sdata, -1, NULL, skb); + ieee80211_queue_skb_to_iface(sdata, NULL, skb); } /* @@ -1500,7 +1478,7 @@ static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx, /* if this mpdu is fragmented - terminate rx aggregation session */ sc = le16_to_cpu(hdr->seq_ctrl); if (sc & IEEE80211_SCTL_FRAG) { - ieee80211_queue_skb_to_iface(rx->sdata, rx->link_id, NULL, skb); + ieee80211_queue_skb_to_iface(rx->sdata, NULL, skb); return; } @@ -2524,7 +2502,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx) out: ieee80211_led_rx(rx->local); - if (rx->sta) + if (rx->link_sta) rx->link_sta->rx_stats.packets++; return RX_CONTINUE; } @@ -3335,8 +3313,8 @@ ieee80211_rx_h_data(struct ieee80211_rx_data *rx) (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST || tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) { rx->skb->protocol = cpu_to_be16(ETH_P_TDLS); - __ieee80211_queue_skb_to_iface(sdata, rx->link_id, - rx->sta, rx->skb); + __ieee80211_queue_skb_to_iface(sdata, rx->link_sta, + rx->skb); return RX_QUEUED; } } @@ -3991,7 +3969,7 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx) return RX_QUEUED; queue: - ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb); + ieee80211_queue_skb_to_iface(sdata, rx->link_sta, rx->skb); return RX_QUEUED; } @@ -4147,7 +4125,7 @@ ieee80211_rx_h_ext(struct ieee80211_rx_data *rx) return RX_DROP_U_UNEXPECTED_EXT_FRAME; /* for now only beacons are ext, so queue them */ - ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb); + ieee80211_queue_skb_to_iface(sdata, rx->link_sta, rx->skb); return RX_QUEUED; } @@ -4204,7 +4182,7 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) return RX_DROP_U_UNHANDLED_MGMT_STYPE; } - ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb); + ieee80211_queue_skb_to_iface(sdata, rx->link_sta, rx->skb); return RX_QUEUED; } @@ -4248,12 +4226,28 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, spin_lock_bh(&rx->local->rx_path_lock); while ((skb = __skb_dequeue(frames))) { + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); + /* - * all the other fields are valid across frames - * that belong to an aMPDU since they are on the - * same TID from the same station + * Most fields are valid across frames. However, + * in the case of reordering frames may have arrived + * on different links, so adjust the link_id, link + * and link_sta accordingly. */ rx->skb = skb; + if (ieee80211_vif_is_mld(&rx->sdata->vif) && + unlikely(rx->link_id != status->link_id)) { + if (rx->sta) { + rx->link_sta = + rcu_dereference(rx->sta->link[rx->link_id]); + + /* Link got disabled, just use deflink */ + if (!rx->link_sta) + rx->link_sta = &rx->sta->deflink; + } + rx->link_id = status->link_id; + rx->link = rcu_dereference(rx->sdata->link[status->link_id]); + } if (WARN_ON_ONCE(!rx->link)) { res = RX_DROP_U_NO_LINK; @@ -4323,7 +4317,10 @@ static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx) static bool ieee80211_rx_is_valid_sta_link_id(struct ieee80211_sta *sta, u8 link_id) { - return !!(sta->valid_links & BIT(link_id)); + if (sta->mlo) + return !!(sta->valid_links & BIT(link_id)); + else + return sta->deflink.link_id == link_id; } static bool ieee80211_rx_data_set_link(struct ieee80211_rx_data *rx, @@ -4360,11 +4357,13 @@ static bool ieee80211_rx_data_set_sta(struct ieee80211_rx_data *rx, if (link_id < 0) { if (ieee80211_vif_is_mld(&rx->sdata->vif) && - sta && !sta->sta.valid_links) + sta && !sta->sta.valid_links) { rx->link = rcu_dereference(rx->sdata->link[sta->deflink.link_id]); - else + rx->link_sta = &sta->deflink; + } else { rx->link = &rx->sdata->deflink; + } } else if (!ieee80211_rx_data_set_link(rx, link_id)) { return false; } @@ -4387,7 +4386,7 @@ void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid) struct tid_ampdu_rx *tid_agg_rx; int link_id = -1; - /* FIXME: statistics won't be right with this */ + /* NOTE: the correct link STA for the frame is set later */ if (sta->sta.valid_links) link_id = ffs(sta->sta.valid_links) - 1; @@ -4914,20 +4913,14 @@ static void ieee80211_rx_8023(struct ieee80211_rx_data *rx, { struct ieee80211_sta_rx_stats *stats; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); - struct sta_info *sta = rx->sta; - struct link_sta_info *link_sta; + struct link_sta_info *link_sta = rx->link_sta; struct sk_buff *skb = rx->skb; void *sa = skb->data + ETH_ALEN; void *da = skb->data; - if (rx->link_id >= 0) { - link_sta = rcu_dereference(sta->link[rx->link_id]); - if (WARN_ON_ONCE(!link_sta)) { - dev_kfree_skb(rx->skb); - return; - } - } else { - link_sta = &sta->deflink; + if (WARN_ON_ONCE(!link_sta)) { + dev_kfree_skb(rx->skb); + return; } stats = &link_sta->rx_stats; @@ -5154,6 +5147,9 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, goto drop; } + status = IEEE80211_SKB_RXCB(skb); + status->link_id = rx->link_id < 0 ? 0 : rx->link_id; + ieee80211_rx_8023(rx, fast_rx, orig_len); return true; @@ -5178,6 +5174,7 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, struct ieee80211_hdr *hdr = (void *)skb->data; struct link_sta_info *link_sta = rx->link_sta; struct ieee80211_link_data *link = rx->link; + struct ieee80211_rx_status *status; rx->skb = skb; @@ -5221,6 +5218,9 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, hdr = (struct ieee80211_hdr *)rx->skb->data; } + status = IEEE80211_SKB_RXCB(rx->skb); + status->link_id = rx->link_id < 0 ? 0 : rx->link_id; + if (ieee80211_is_s1g_beacon(hdr->frame_control)) { ieee80211_invoke_rx_handlers(rx); return true; @@ -5256,22 +5256,19 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, } static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, - struct ieee80211_sta *pubsta, + struct ieee80211_link_sta *link_pubsta, struct sk_buff *skb, struct list_head *list) { struct ieee80211_local *local = hw_to_local(hw); - struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_fast_rx *fast_rx; struct ieee80211_rx_data rx; struct sta_info *sta; - int link_id = -1; memset(&rx, 0, sizeof(rx)); rx.skb = skb; rx.local = local; rx.list = list; - rx.link_id = -1; I802_DEBUG_INC(local->dot11ReceivedFragmentCount); @@ -5279,23 +5276,15 @@ static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, if (skb->len < sizeof(struct ethhdr)) goto drop; - if (!pubsta) + if (!link_pubsta) goto drop; - if (status->link_valid) - link_id = status->link_id; - - /* - * TODO: Should the frame be dropped if the right link_id is not - * available? Or may be it is fine in the current form to proceed with - * the frame processing because with frame being in 802.3 format, - * link_id is used only for stats purpose and updating the stats on - * the deflink is fine? - */ - sta = container_of(pubsta, struct sta_info, sta); - if (!ieee80211_rx_data_set_sta(&rx, sta, link_id)) + sta = container_of(link_pubsta->sta, struct sta_info, sta); + if (!ieee80211_rx_data_set_sta(&rx, sta, link_pubsta->link_id)) goto drop; + rx.link_id = link_pubsta->link_id; + fast_rx = rcu_dereference(rx.sta->fast_rx); if (!fast_rx) goto drop; @@ -5323,6 +5312,9 @@ static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx, } /* + * FIXME: Here we can assume that link addresses have not + * been translated. + * * Look up link station first, in case there's a * chance that they might have a link address that * is identical to the MLD address, that way we'll @@ -5336,10 +5328,8 @@ static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx, struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); sta = sta_info_get_bss(rx->sdata, hdr->addr2); - if (status->link_valid) { - link_id = status->link_id; - } else if (ieee80211_vif_is_mld(&rx->sdata->vif) && - status->freq) { + if (ieee80211_vif_is_mld(&rx->sdata->vif) && + status->freq) { struct ieee80211_link_data *link; struct ieee80211_chanctx_conf *conf; @@ -5367,12 +5357,11 @@ static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx, * be called with rcu_read_lock protection. */ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, - struct ieee80211_sta *pubsta, + struct ieee80211_link_sta *link_pubsta, struct sk_buff *skb, struct list_head *list) { struct ieee80211_local *local = hw_to_local(hw); - struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_sub_if_data *sdata; struct ieee80211_hdr *hdr; __le16 fc; @@ -5386,7 +5375,6 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, rx.skb = skb; rx.local = local; rx.list = list; - rx.link_id = -1; if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) I802_DEBUG_INC(local->dot11ReceivedFragmentCount); @@ -5428,37 +5416,14 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, if (ieee80211_is_data(fc)) { struct sta_info *sta, *prev_sta; - int link_id = -1; - if (status->link_valid) - link_id = status->link_id; - - if (pubsta) { - sta = container_of(pubsta, struct sta_info, sta); - if (!ieee80211_rx_data_set_sta(&rx, sta, link_id)) + if (link_pubsta) { + sta = container_of(link_pubsta->sta, + struct sta_info, sta); + if (!ieee80211_rx_data_set_sta(&rx, sta, + link_pubsta->link_id)) goto out; - /* - * In MLO connection, fetch the link_id using addr2 - * when the driver does not pass link_id in status. - * When the address translation is already performed by - * driver/hw, the valid link_id must be passed in - * status. - */ - - if (!status->link_valid && pubsta->mlo) { - struct link_sta_info *link_sta; - - link_sta = link_sta_info_get_bss(rx.sdata, - hdr->addr2); - if (!link_sta) - goto out; - - if (!ieee80211_rx_data_set_link(&rx, - link_sta->link_id)) - goto out; - } - if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) return; goto out; @@ -5467,13 +5432,20 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, prev_sta = NULL; for_each_sta_info(local, hdr->addr2, sta, tmp) { + int link_id; + if (!prev_sta) { prev_sta = sta; continue; } rx.sdata = prev_sta->sdata; - if (!status->link_valid && prev_sta->sta.mlo) { + + /* + * FIXME: This is not correct as the addr2 cannot be a + * link address if the loop itself is iterated. + */ + if (prev_sta->sta.mlo) { struct link_sta_info *link_sta; link_sta = link_sta_info_get_bss(rx.sdata, @@ -5482,6 +5454,8 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, continue; link_id = link_sta->link_id; + } else { + link_id = sta->deflink.link_id; } if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id)) @@ -5493,8 +5467,15 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, } if (prev_sta) { + int link_id; + rx.sdata = prev_sta->sdata; - if (!status->link_valid && prev_sta->sta.mlo) { + + /* + * FIXME: This is not correct as the addr2 cannot be a + * link address if the loop itself is iterated. + */ + if (prev_sta->sta.mlo) { struct link_sta_info *link_sta; link_sta = link_sta_info_get_bss(rx.sdata, @@ -5503,6 +5484,8 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, goto out; link_id = link_sta->link_id; + } else { + link_id = sta->deflink.link_id; } if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id)) @@ -5565,7 +5548,6 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_supported_band *sband; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct ieee80211_sta *pubsta; WARN_ON_ONCE(softirq_count() == 0); @@ -5696,16 +5678,6 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, } } - /* FIXME: Emulate the old driver behaviour for now */ - if (link_pubsta) { - status->link_valid = 1; - status->link_id = link_pubsta->link_id; - pubsta = link_pubsta->sta; - } else { - status->link_valid = 0; - pubsta = NULL; - } - status->rx_flags = 0; kcov_remote_start_common(skb_get_kcov_handle(skb)); @@ -5724,9 +5696,10 @@ void ieee80211_rx_list(struct ieee80211_hw *hw, ieee80211_tpt_led_trig_rx(local, skb->len); if (status->flag & RX_FLAG_8023) - __ieee80211_rx_handle_8023(hw, pubsta, skb, list); + __ieee80211_rx_handle_8023(hw, link_pubsta, skb, list); else - __ieee80211_rx_handle_packet(hw, pubsta, skb, list); + __ieee80211_rx_handle_packet(hw, link_pubsta, skb, + list); } kcov_remote_stop(); diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index eeff230bd909..324c2b6d7ce1 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -9,7 +9,7 @@ * Copyright 2007, Michael Wu * Copyright 2013-2015 Intel Mobile Communications GmbH * Copyright 2016-2017 Intel Deutschland GmbH - * Copyright (C) 2018-2025 Intel Corporation + * Copyright (C) 2018-2026 Intel Corporation */ #include @@ -204,12 +204,10 @@ ieee80211_bss_info_update(struct ieee80211_local *local, * an indication on which of the links the frame was received */ if (ieee80211_vif_is_mld(&scan_sdata->vif)) { - if (rx_status->link_valid) { - s8 link_id = rx_status->link_id; + s8 link_id = rx_status->link_id; - link_conf = - rcu_dereference(scan_sdata->vif.link_conf[link_id]); - } + link_conf = + rcu_dereference(scan_sdata->vif.link_conf[link_id]); } else { link_conf = &scan_sdata->vif.bss_conf; } From 6d531b9af16ea84aab72db573384fa94bfa0f2f7 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:30 +0200 Subject: [PATCH 0560/2126] wifi: mac80211: rework RX packet handling The code has grown over time and it was not correctly handling all cases. Examples of issues are that for management frames we would match the received address against the MLD address even though we should not resolve the station in that case. Another issue was that for data frames we would not correctly fall back to use link addresses when the driver does not provide the pubsta already. The new code still uses the same approach as before. For data frames, assume that a valid station exists and interfaces do not need to be iterated. On the other hand, for non-data frames (or if a data frame without a station is received) all interfaces must be iterated. Note that this rework makes mac80211 slightly more strict. For example, previously mac80211 would have incorrectly accepted a data frame that was transmitted on the wrong link. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.de2fc9a47273.Ie12ec077142c6a7fdbb58cdfc5660497cc75150e@changeid Signed-off-by: Johannes Berg --- net/mac80211/rx.c | 297 +++++++++++++++++++++++++++------------------- 1 file changed, 174 insertions(+), 123 deletions(-) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 753d639d1955..1273c9067aed 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4318,9 +4318,33 @@ static bool ieee80211_rx_is_valid_sta_link_id(struct ieee80211_sta *sta, u8 link_id) { if (sta->mlo) - return !!(sta->valid_links & BIT(link_id)); - else - return sta->deflink.link_id == link_id; + return sta->valid_links & BIT(link_id); + + return sta->deflink.link_id == link_id; +} + +static bool ieee80211_rx_data_set_link_sta(struct ieee80211_rx_data *rx, + struct link_sta_info *link_sta) +{ + struct sta_info *sta; + + if (WARN_ON_ONCE(!link_sta) || + !ieee80211_rx_is_valid_sta_link_id(&link_sta->sta->sta, + link_sta->link_id)) + return false; + + sta = link_sta->sta; + + rx->sta = sta; + rx->local = sta->sdata->local; + rx->link = rcu_dereference(sta->sdata->link[link_sta->link_id]); + if (!rx->link) + return false; + + rx->link_id = rx->link->link_id; + rx->link_sta = link_sta; + + return true; } static bool ieee80211_rx_data_set_link(struct ieee80211_rx_data *rx, @@ -5296,60 +5320,19 @@ drop: dev_kfree_skb(skb); } -static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx, - struct sk_buff *skb, bool consume) +static bool ieee80211_rx_valid_freq(int freq, struct ieee80211_link_data *link) { - struct link_sta_info *link_sta; - struct ieee80211_hdr *hdr = (void *)skb->data; - struct sta_info *sta; - int link_id = -1; + struct ieee80211_chanctx_conf *conf; - if (ieee80211_is_s1g_beacon(hdr->frame_control)) { - if (!ieee80211_rx_data_set_sta(rx, NULL, -1)) - return false; + if (!freq || link->sdata->vif.type == NL80211_IFTYPE_NAN || + link->sdata->vif.type == NL80211_IFTYPE_NAN_DATA) + return true; - return ieee80211_prepare_and_rx_handle(rx, skb, consume); - } - - /* - * FIXME: Here we can assume that link addresses have not - * been translated. - * - * Look up link station first, in case there's a - * chance that they might have a link address that - * is identical to the MLD address, that way we'll - * have the link information if needed. - */ - link_sta = link_sta_info_get_bss(rx->sdata, hdr->addr2); - if (link_sta) { - sta = link_sta->sta; - link_id = link_sta->link_id; - } else { - struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); - - sta = sta_info_get_bss(rx->sdata, hdr->addr2); - if (ieee80211_vif_is_mld(&rx->sdata->vif) && - status->freq) { - struct ieee80211_link_data *link; - struct ieee80211_chanctx_conf *conf; - - for_each_link_data_rcu(rx->sdata, link) { - conf = rcu_dereference(link->conf->chanctx_conf); - if (!conf || !conf->def.chan) - continue; - - if (status->freq == conf->def.chan->center_freq) { - link_id = link->link_id; - break; - } - } - } - } - - if (!ieee80211_rx_data_set_sta(rx, sta, link_id)) + conf = rcu_dereference(link->conf->chanctx_conf); + if (!conf || !conf->def.chan) return false; - return ieee80211_prepare_and_rx_handle(rx, skb, consume); + return freq == conf->def.chan->center_freq; } /* @@ -5363,11 +5346,14 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, { struct ieee80211_local *local = hw_to_local(hw); struct ieee80211_sub_if_data *sdata; + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_hdr *hdr; + struct link_sta_info *link_sta; + struct sta_info *sta; __le16 fc; struct ieee80211_rx_data rx; - struct ieee80211_sub_if_data *prev; struct rhlist_head *tmp; + bool rx_data_pending; int err = 0; fc = ((struct ieee80211_hdr *)skb->data)->frame_control; @@ -5414,92 +5400,102 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, ieee80211_is_s1g_beacon(hdr->frame_control))) ieee80211_scan_rx(local, skb); + /* + * RX of a data frame should only happen to existing stations. + * It is therefore more efficient to use the one provided by the driver + * or search based on the station's address. + * + * Note we will fall through and handle a spurious data frame in the + * same way as a management frame. + */ if (ieee80211_is_data(fc)) { - struct sta_info *sta, *prev_sta; - if (link_pubsta) { - sta = container_of(link_pubsta->sta, - struct sta_info, sta); - if (!ieee80211_rx_data_set_sta(&rx, sta, - link_pubsta->link_id)) - goto out; + sta = container_of(link_pubsta->sta, struct sta_info, + sta); + link_sta = rcu_dereference(sta->link[link_pubsta->link_id]); - if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) + rx.sdata = sta->sdata; + if (ieee80211_rx_data_set_link_sta(&rx, link_sta) && + ieee80211_prepare_and_rx_handle(&rx, skb, true)) return; + goto out; } - prev_sta = NULL; + rx_data_pending = false; + /* Search for stations on non-MLD interfaces */ for_each_sta_info(local, hdr->addr2, sta, tmp) { - int link_id; + struct ieee80211_link_data *link; - if (!prev_sta) { - prev_sta = sta; + if (ieee80211_vif_is_mld(&sta->sdata->vif)) continue; + + link = &sta->sdata->deflink; + if (!ieee80211_rx_valid_freq(status->freq, link)) + continue; + + if (rx_data_pending) { + ieee80211_prepare_and_rx_handle(&rx, skb, + false); + rx_data_pending = false; } - rx.sdata = prev_sta->sdata; + rx.sdata = sta->sdata; + if (!ieee80211_rx_data_set_link_sta(&rx, &sta->deflink)) + continue; - /* - * FIXME: This is not correct as the addr2 cannot be a - * link address if the loop itself is iterated. - */ - if (prev_sta->sta.mlo) { - struct link_sta_info *link_sta; - - link_sta = link_sta_info_get_bss(rx.sdata, - hdr->addr2); - if (!link_sta) - continue; - - link_id = link_sta->link_id; - } else { - link_id = sta->deflink.link_id; - } - - if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id)) - goto out; - - ieee80211_prepare_and_rx_handle(&rx, skb, false); - - prev_sta = sta; + rx_data_pending = true; } - if (prev_sta) { - int link_id; + /* And search stations on MLD interfaces */ + for_each_link_sta_info(local, hdr->addr2, link_sta, tmp) { + struct ieee80211_link_data *link; - rx.sdata = prev_sta->sdata; + sta = link_sta->sta; + sdata = sta->sdata; + link = rcu_dereference(sdata->link[link_sta->link_id]); - /* - * FIXME: This is not correct as the addr2 cannot be a - * link address if the loop itself is iterated. - */ - if (prev_sta->sta.mlo) { - struct link_sta_info *link_sta; + if (!ieee80211_rx_valid_freq(status->freq, link)) + continue; - link_sta = link_sta_info_get_bss(rx.sdata, - hdr->addr2); - if (!link_sta) - goto out; - - link_id = link_sta->link_id; - } else { - link_id = sta->deflink.link_id; + if (rx_data_pending) { + ieee80211_prepare_and_rx_handle(&rx, skb, + false); + rx_data_pending = false; } - if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id)) - goto out; + rx.sdata = sta->sdata; + if (!ieee80211_rx_data_set_link_sta(&rx, link_sta)) + continue; + rx_data_pending = true; + } + + if (rx_data_pending) { if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) return; + goto out; } + + /* fall through, e.g. for spurious frame notification */ } - prev = NULL; + /* + * This is a management frame (or a data frame without a station) and + * it will be delivered independent of whether a station exists, + * so iterate the interfaces. + */ + rx_data_pending = false; + + /* We expect the driver to provide frequency information */ + if (WARN_ON_ONCE(!local->emulate_chanctx && !status->freq)) + goto out; list_for_each_entry_rcu(sdata, &local->interfaces, list) { + struct ieee80211_link_data *link = NULL; + if (!ieee80211_sdata_running(sdata)) continue; @@ -5507,29 +5503,84 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, sdata->vif.type == NL80211_IFTYPE_AP_VLAN) continue; + link_sta = NULL; + link = NULL; + + /* Try to resolve the station */ + if (!ieee80211_vif_is_mld(&sdata->vif)) { + sta = sta_info_get_bss(sdata, hdr->addr2); + + if (sta) { + link_sta = &sta->deflink; + link = &sdata->deflink; + } + } else { + link_sta = link_sta_info_get_bss(sdata, hdr->addr2); + + if (link_sta) + link = rcu_dereference(sdata->link[link_sta->link_id]); + } + /* - * frame is destined for this interface, but if it's - * not also for the previous one we handle that after - * the loop to avoid copying the SKB once too much + * If we found a STA and it has a valid link information, then + * RX using the station. */ + if (link_sta && link && + ieee80211_rx_valid_freq(status->freq, link)) { + if (rx_data_pending) { + ieee80211_prepare_and_rx_handle(&rx, skb, false); + rx_data_pending = false; + } + + /* No valid_links check as we need to RX beacons */ + + rx.sdata = sdata; + if (ieee80211_rx_data_set_link_sta(&rx, link_sta)) + rx_data_pending = true; - if (!prev) { - prev = sdata; continue; } - rx.sdata = prev; - ieee80211_rx_for_interface(&rx, skb, false); + /* No station, try to resolve the link and RX */ + if (ieee80211_vif_is_mld(&sdata->vif)) { + struct ieee80211_chanctx_conf *conf; + bool found = false; - prev = sdata; + for_each_link_data_rcu(sdata, link) { + conf = rcu_dereference(link->conf->chanctx_conf); + if (!conf || !conf->def.chan) + continue; + + if (status->freq == conf->def.chan->center_freq) { + found = true; + break; + } + } + + if (!found) + link = &sdata->deflink; + } else { + link = &sdata->deflink; + } + + if (rx_data_pending) { + ieee80211_prepare_and_rx_handle(&rx, skb, false); + rx_data_pending = false; + } + + rx.sdata = sdata; + rx.local = sdata->local; + rx.link = link; + rx.link_id = link->link_id; + rx.sta = NULL; + rx.link_sta = NULL; + + rx_data_pending = true; } - if (prev) { - rx.sdata = prev; - - if (ieee80211_rx_for_interface(&rx, skb, true)) - return; - } + if (rx_data_pending && + ieee80211_prepare_and_rx_handle(&rx, skb, true)) + return; out: dev_kfree_skb(skb); From de5f5ca3d3bfcdcc38c10eb9246eca3687cd2261 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:31 +0200 Subject: [PATCH 0561/2126] wifi: cfg80211: add attribute for TX/RX denoting there is no station For MLD stations, userspace may need to explicitly transmit a frame to a specific link address. In that case, it needs to ensure that no address translation happens. In the reverse case of an RX, userspace may need to know the link address for a frame. By passing the information whether a STA is known for the frame, userspace knows whether link translation happened and can do the reverse lookup when needed. This is important for flows where a STA is still registered but the connection has been lost and it is returning again. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.f12af80b1972.I4cfd3db83ba3dc0267575f919ba613ea5d10abd5@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 4 ++++ include/uapi/linux/nl80211.h | 7 +++++++ net/wireless/nl80211.c | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 6461a7bd0169..9aa7d2d4a184 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4009,6 +4009,7 @@ struct cfg80211_update_ft_ies_params { * @link_id: for MLO, the link ID to transmit on, -1 if not given; note * that the link ID isn't validated (much), it's in range but the * link might not exist (or be used by the receiver STA) + * @no_sta: set if the frame should not be transmitted using an existing STA */ struct cfg80211_mgmt_tx_params { struct ieee80211_channel *chan; @@ -4021,6 +4022,7 @@ struct cfg80211_mgmt_tx_params { int n_csa_offsets; const u16 *csa_offsets; int link_id; + bool no_sta; }; /** @@ -9501,6 +9503,7 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, * @flags: flags, as defined in &enum nl80211_rxmgmt_flags * @rx_tstamp: Hardware timestamp of frame RX in nanoseconds * @ack_tstamp: Hardware timestamp of ack TX in nanoseconds + * @no_sta: set if no station is known for the frame (relevant for MLD) */ struct cfg80211_rx_info { int freq; @@ -9512,6 +9515,7 @@ struct cfg80211_rx_info { u32 flags; u64 rx_tstamp; u64 ack_tstamp; + bool no_sta; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 32553cacf988..510102febc26 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -3185,6 +3185,11 @@ enum nl80211_commands { * The aggregated message always precedes the per-link messages for the * same station within a dump sequence. * + * @NL80211_ATTR_FRAME_NO_STA: Valid for @NL80211_CMD_FRAME to denote that + * the kernel had no station for a received frame or should not use a + * known station to transmit a frame. This is relevant to know whether + * MLD address translation happened or to disable it when sending a frame. + * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -3785,6 +3790,8 @@ enum nl80211_attrs { NL80211_ATTR_STA_DUMP_LINK_STATS, + NL80211_ATTR_FRAME_NO_STA, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index b081eeaf7016..e77a4c81d031 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1097,6 +1097,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_NPCA_PUNCT_BITMAP] = NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range), [NL80211_ATTR_STA_DUMP_LINK_STATS] = { .type = NLA_FLAG }, + [NL80211_ATTR_FRAME_NO_STA] = { .type = NLA_FLAG }, }; /* policy for the key attributes */ @@ -14873,6 +14874,9 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) !(wdev->valid_links & BIT(params.link_id))) return -EINVAL; + params.no_sta = + nla_get_flag(info->attrs[NL80211_ATTR_FRAME_NO_STA]); + params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); @@ -22042,7 +22046,9 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, (info->ack_tstamp && nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP, info->ack_tstamp, - NL80211_ATTR_PAD))) + NL80211_ATTR_PAD)) || + (info->no_sta && + nla_put_flag(msg, NL80211_ATTR_FRAME_NO_STA))) goto nla_put_failure; genlmsg_end(msg, hdr); From fc60152ad26d085e12d3dfd33e3d5640e8cbbb72 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:32 +0200 Subject: [PATCH 0562/2126] wifi: mac80211: report to cfg80211 when no STA is known for a frame This is relevant for hostapd to know whether address translation was done on a received management frame. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.273a1c7a1ab2.I28d8146b9189c5961411ecb26b44588895de1b56@changeid Signed-off-by: Johannes Berg --- net/mac80211/rx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 1273c9067aed..6c823678d099 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -3983,6 +3983,7 @@ ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) .len = rx->skb->len, .link_id = rx->link_id, .have_link_id = rx->link_id >= 0, + .no_sta = !rx->sta, }; /* skip known-bad action frames and return them in the next handler */ From ec27695b0e5ca5360c7ed6d677fbc8e3cb13057b Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:33 +0200 Subject: [PATCH 0563/2126] wifi: mac80211: pass station to ieee80211_tx_skb_tid The station may be relevant for queuing and will also generally be resolved in some cases. However, we want to be able to prevent looking up the station based on the address. Add a station parameter, which can be set to the correct station, to an error value to prevent station lookup or to NULL to get the old behaviour where the address is used to find the appropriate station. Also disable the station lookup for ieee80211_tx_skb_tid_band already as it does not make any sense to find a station when doing an off-channel transmit. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.759b6144ddf9.Ib7be90db0d3712d14e7a292023ff3d922baef860@changeid Signed-off-by: Johannes Berg --- net/mac80211/agg-tx.c | 4 ++-- net/mac80211/ht.c | 2 +- net/mac80211/ieee80211_i.h | 11 +++++++---- net/mac80211/offchannel.c | 2 +- net/mac80211/rx.c | 2 +- net/mac80211/tdls.c | 2 +- net/mac80211/tx.c | 10 ++++++---- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c index 0832213430f4..ce9fb19d8c18 100644 --- a/net/mac80211/agg-tx.c +++ b/net/mac80211/agg-tx.c @@ -98,7 +98,7 @@ static void ieee80211_send_addba_request(struct sta_info *sta, u16 tid, if (sta->sta.deflink.he_cap.has_he) ieee80211_add_addbaext(skb, 0, agg_size); - ieee80211_tx_skb_tid(sdata, skb, tid, -1); + ieee80211_tx_skb_tid(sdata, skb, NULL, tid, -1); } void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn) @@ -127,7 +127,7 @@ void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn) IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | IEEE80211_TX_CTL_REQ_TX_STATUS; - ieee80211_tx_skb_tid(sdata, skb, tid, -1); + ieee80211_tx_skb_tid(sdata, skb, NULL, tid, -1); } EXPORT_SYMBOL(ieee80211_send_bar); diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c index e1e1b7f82f3f..c5c2113fa4f7 100644 --- a/net/mac80211/ht.c +++ b/net/mac80211/ht.c @@ -545,7 +545,7 @@ int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata, info->status_data = IEEE80211_STATUS_TYPE_SMPS | u16_encode_bits(status_link_id << 2 | smps, IEEE80211_STATUS_SUBDATA_MASK); - ieee80211_tx_skb_tid(sdata, skb, 7, link_id); + ieee80211_tx_skb_tid(sdata, skb, NULL, 7, link_id); return 0; } diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 65311340db40..9514f01778be 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2471,7 +2471,8 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sta_info *sta, struct sk_buff *skb); void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, int tid, int link_id, + struct sk_buff *skb, struct sta_info *sta, + int tid, int link_id, enum nl80211_band band); static inline bool ieee80211_require_encrypted_assoc(__le16 fc, @@ -2486,18 +2487,20 @@ ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, enum nl80211_band band) { rcu_read_lock(); - __ieee80211_tx_skb_tid_band(sdata, skb, tid, -1, band); + __ieee80211_tx_skb_tid_band(sdata, skb, ERR_PTR(-ENOENT), + tid, -1, band); rcu_read_unlock(); } void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, int tid, int link_id); + struct sk_buff *skb, struct sta_info *sta, + int tid, int link_id); static inline void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) { /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */ - ieee80211_tx_skb_tid(sdata, skb, 7, -1); + ieee80211_tx_skb_tid(sdata, skb, NULL, 7, -1); } /** diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c index 7acef80d5f1f..5cec8747b193 100644 --- a/net/mac80211/offchannel.c +++ b/net/mac80211/offchannel.c @@ -1022,7 +1022,7 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, } if (!need_offchan) { - ieee80211_tx_skb_tid(sdata, skb, 7, link_id); + ieee80211_tx_skb_tid(sdata, skb, NULL, 7, link_id); ret = 0; goto out_unlock; } diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 6c823678d099..d6755a4c7d3c 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4106,7 +4106,7 @@ ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx) local->hw.offchannel_tx_hw_queue; } - __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, -1, + __ieee80211_tx_skb_tid_band(rx->sdata, nskb, rx->sta, 7, -1, status->band); } diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c index 4f4cae9fd274..7ec33885a3e1 100644 --- a/net/mac80211/tdls.c +++ b/net/mac80211/tdls.c @@ -1066,7 +1066,7 @@ ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev, } if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) { - ieee80211_tx_skb_tid(sdata, skb, 7, link_id); + ieee80211_tx_skb_tid(sdata, skb, sta, 7, link_id); return 0; } diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 06c50183f064..73affc540f0c 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -6448,7 +6448,8 @@ void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid) EXPORT_SYMBOL(ieee80211_unreserve_tid); void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, int tid, int link_id, + struct sk_buff *skb, struct sta_info *sta, + int tid, int link_id, enum nl80211_band band) { const struct ieee80211_hdr *hdr = (void *)skb->data; @@ -6500,12 +6501,13 @@ void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, */ local_bh_disable(); IEEE80211_SKB_CB(skb)->band = band; - ieee80211_xmit(sdata, NULL, skb); + ieee80211_xmit(sdata, sta, skb); local_bh_enable(); } void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, - struct sk_buff *skb, int tid, int link_id) + struct sk_buff *skb, struct sta_info *sta, + int tid, int link_id) { struct ieee80211_chanctx_conf *chanctx_conf; enum nl80211_band band; @@ -6531,7 +6533,7 @@ void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, band = 0; } - __ieee80211_tx_skb_tid_band(sdata, skb, tid, link_id, band); + __ieee80211_tx_skb_tid_band(sdata, skb, sta, tid, link_id, band); rcu_read_unlock(); } From 3b35f726c20d138fafa154182ee926a419306269 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 15 Sep 2026 15:19:34 +0200 Subject: [PATCH 0564/2126] wifi: mac80211: pass error station if non-STA transmit was requested When cfg80211 requested a transmit without a station, pass an error station to ieee80211_tx_skb_tid instead of the correct one. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260915151925.92499fb21e4a.I5ffe7bc0d4ccefca5c1e506d5d3d482e13989cda@changeid Signed-off-by: Johannes Berg --- net/mac80211/offchannel.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c index 5cec8747b193..ddd7a96a2f81 100644 --- a/net/mac80211/offchannel.c +++ b/net/mac80211/offchannel.c @@ -854,8 +854,10 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, need_offchan = true; rcu_read_lock(); - sta = sta_info_get_bss(sdata, mgmt->da); - mlo_sta = sta && sta->sta.mlo; + if (!params->no_sta) { + sta = sta_info_get_bss(sdata, mgmt->da); + mlo_sta = sta && sta->sta.mlo; + } if (!ieee80211_is_action(mgmt->frame_control) || mgmt->u.action.category == WLAN_CATEGORY_PUBLIC || @@ -884,7 +886,8 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, local->ops->remain_on_channel && memcmp(sdata->vif.cfg.ap_addr, mgmt->bssid, ETH_ALEN))) { need_offchan = true; - } else if (sdata->u.mgd.associated && + } else if (!params->no_sta && + sdata->u.mgd.associated && ether_addr_equal(sdata->vif.cfg.ap_addr, mgmt->da)) { sta = sta_info_get_bss(sdata, mgmt->da); mlo_sta = sta && sta->sta.mlo; @@ -1022,7 +1025,9 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, } if (!need_offchan) { - ieee80211_tx_skb_tid(sdata, skb, NULL, 7, link_id); + ieee80211_tx_skb_tid(sdata, skb, + params->no_sta ? ERR_PTR(-ENOENT) : sta, + 7, link_id); ret = 0; goto out_unlock; } From 3c8abdbe345be37aedadddf931df214d706bb973 Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Mon, 14 Sep 2026 11:47:02 +0200 Subject: [PATCH 0565/2126] net: phy: broadcom: enable jumbo frames on BCM54xx Jumbo packets need two bits that default to off, extended packet length in the auxiliary control register and PCS transmit FIFO elasticity in the extended control register. The latter raises the transmit limit from 4.5 KB to 9 KB at the cost of 16 ns of 1000BASE-T transmit latency, and the two together take copper mode to 10 KB. Without them such frames are lost on a 100M link while the same frames pass at 1G. On a Raspberry Pi CM5, which uses a BCM54210PE, 9142 byte frames at 100M are lost 20 out of 20 with the MAC counting every one as transmitted. The same frames over the same path at 1G arrive intact. Set both, which bcm_phy_enable_jumbo() already does for bcm7xxx. The frames then arrive and the payloads check out byte for byte. Signed-off-by: Nicolai Buchwitz Reviewed-by: Florian Fainelli Link: https://patch.msgid.link/20260914094703.1093504-1-nb@tipi-net.de Signed-off-by: Jakub Kicinski --- drivers/net/phy/broadcom.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index d1a4edb34ad2..b515e3875504 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -537,6 +537,13 @@ static int bcm54xx_config_init(struct phy_device *phydev) bcm54xx_ptp_config_init(phydev); + /* Transmit is limited to 4.5 KB without it, see the BCM54210PE + * datasheet section 5.4.12.14. + */ + err = bcm_phy_enable_jumbo(phydev); + if (err < 0) + return err; + /* Acknowledge any left over interrupt and charge the device for * wake-up. */ From ed502e4856856358b304d0c04f8e33364547d1d2 Mon Sep 17 00:00:00 2001 From: Aamir Ahmed Date: Fri, 11 Sep 2026 22:33:10 +0100 Subject: [PATCH 0566/2126] macsec: require CAP_NET_ADMIN in the device netns for changelink macsec_changelink() operates on two netns: dev_net(dev) and the netns of macsec->real_dev. They differ once the macsec device is created in or moved to a netns other than the one holding the real device. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in dev_net(real_dev) can reach real_dev's driver: - IFLA_MACSEC_OFFLOAD -> macsec_update_offload(), which calls ops->mdo_add_secy() / mdo_del_secy() on real_dev. - the tail "propagate to the device" block, which calls ops->mdo_upd_secy() on real_dev for any request against an already offloaded device that does not change the offload mode. This one needs no IFLA_MACSEC_OFFLOAD attribute at all. Gate both with rtnl_dev_link_net_capable(), as the tunnel, geneve, vxlan and macvlan handlers already do. It fires only when the request would reach real_dev: when IFLA_MACSEC_OFFLOAD asks for a mode other than the current one, or when the device is already offloaded. The local attributes of a non-offloaded device stay configurable from its own netns. The check is in the changelink handler rather than in macsec_update_offload(), because the mdo_upd_secy() propagation does not go through that function. Its other caller, macsec_upd_offload() for MACSEC_CMD_UPD_OFFLOAD, is GENL_ADMIN_PERM. The ndo and dellink paths that reach real_dev's driver as a side effect of operating the macsec device itself (open/stop, set_mac_address, dellink) are unchanged here. rtnl_dev_link_net_capable() was added by commit 8165f7ff57d9 ("net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink"); a stable tree without it needs that first. Cc: stable+noautosel@kernel.org # high regression risk; local DoS by userns are a dime a dozen Fixes: 3cf3227a21d1 ("net: macsec: hardware offloading infrastructure") Cc: Antoine Tenart Signed-off-by: Aamir Ahmed Link: https://patch.msgid.link/AS8P251MB000176E827636EA185226908C8BE2@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM Signed-off-by: Jakub Kicinski --- drivers/net/macsec.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 6f9f3aceffaa..e019e7a25cc9 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -3945,6 +3946,33 @@ static int macsec_changelink_common(struct net_device *dev, return 0; } +/* Both a change of the offload state (mdo_add_secy()/mdo_del_secy()) and + * any request against an already offloaded device (mdo_upd_secy()) reach + * the driver of real_dev, which may live in a different network namespace + * from the macsec device. Require CAP_NET_ADMIN over real_dev's namespace + * for those; local attributes of a non-offloaded device are unaffected. + */ +static int macsec_changelink_check_netns(struct net_device *dev, + struct nlattr *data[], + struct netlink_ext_ack *extack) +{ + struct macsec_dev *macsec = macsec_priv(dev); + bool reaches_real_dev; + + reaches_real_dev = macsec_is_offloaded(macsec); + if (data[IFLA_MACSEC_OFFLOAD] && + nla_get_u8(data[IFLA_MACSEC_OFFLOAD]) != macsec->offload) + reaches_real_dev = true; + + if (!reaches_real_dev || + rtnl_dev_link_net_capable(dev, dev_net(macsec->real_dev))) + return 0; + + NL_SET_ERR_MSG(extack, + "Changing a MACsec device whose real device is in another network namespace requires CAP_NET_ADMIN in that namespace"); + return -EPERM; +} + static int macsec_changelink(struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) @@ -3959,6 +3987,10 @@ static int macsec_changelink(struct net_device *dev, struct nlattr *tb[], if (!data) return 0; + ret = macsec_changelink_check_netns(dev, data, extack); + if (ret) + return ret; + if (data[IFLA_MACSEC_CIPHER_SUITE] || data[IFLA_MACSEC_ICV_LEN] || data[IFLA_MACSEC_SCI] || From c5faf1d4df8f5be608267dfa87cc819dde0bef97 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 14 Sep 2026 23:26:42 +0200 Subject: [PATCH 0567/2126] net: ethernet: cortina: Bound RX descriptor processing NAPI budgets received packets, so gmac_rx() only consumes budget when an EOF descriptor completes a frame. A malformed descriptor stream without EOF can consequently make one poll consume the entire snapshotted RX ring, which may contain up to 32768 descriptors. The error paths can also flood the kernel log while doing so. Keep the packet budget EOF-based, but impose a separate descriptor limit which allows MAX_SKB_FRAGS descriptors for every packet in the budget. If the limit is reached with descriptors still pending, return the full NAPI budget to retain ownership and continue in another poll. Ratelimit errors reported from malformed descriptor paths. Signed-off-by: Linus Walleij Link: https://patch.msgid.link/20260914-b4-gemini-ethernet-fixes-2-v2-2-5ab39a047b90@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cortina/gemini.c | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index f08de623e6f7..663d2ce8414f 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -736,7 +737,8 @@ gmac_get_queue_page(struct gemini_ethernet *geth, mapping = addr & PAGE_MASK; if (!geth->freeq_pages) { - dev_err(geth->dev, "try to get page with no page list\n"); + dev_err_ratelimited(geth->dev, + "try to get page with no page list\n"); return NULL; } @@ -1441,7 +1443,7 @@ update_exit: } static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget, - unsigned int *freeq_consumed) + unsigned int *freeq_consumed, bool *reschedule) { struct gemini_ethernet_port *port = netdev_priv(netdev); unsigned short m = (1 << port->rxq_order) - 1; @@ -1449,6 +1451,8 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget, void __iomem *ptr_reg = port->rxq_rwptr; unsigned int frag_nr = port->rx_frag_nr; struct sk_buff *skb = port->rx_skb; + /* Bound malformed chains while allowing maximum fragments per frame. */ + unsigned int desc_limit = budget * MAX_SKB_FRAGS; unsigned int consumed = 0; unsigned int frame_len, frag_len; struct gmac_rxdesc *rx = NULL; @@ -1475,7 +1479,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget, r = rw.bits.rptr; w = rw.bits.wptr; - while (budget && w != r) { + while (budget && consumed < desc_limit && w != r) { page = NULL; rx = port->rxq_ring + r; word0 = rx->word0; @@ -1502,15 +1506,18 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget, } if (!mapping) { - netdev_err(netdev, - "rxq[%u]: HW BUG: zero DMA desc\n", r); + if (net_ratelimit()) + netdev_err(netdev, + "rxq[%u]: HW BUG: zero DMA desc\n", + r); goto err_drop; } /* Freeq pointers are one page off */ gpage = gmac_get_queue_page(geth, port, mapping + PAGE_SIZE); if (!gpage) { - dev_err(geth->dev, "could not find mapping\n"); + dev_err_ratelimited(geth->dev, + "could not find mapping\n"); goto err_drop; } page = gpage->page; @@ -1535,7 +1542,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget, if (frag_nr == MAX_SKB_FRAGS) goto err_drop; - if (frag_len == 0) + if (frag_len == 0 && net_ratelimit()) netdev_err(netdev, "Received fragment with len = 0\n"); skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len); @@ -1579,6 +1586,7 @@ next_desc: port->rx_frag_nr = frag_nr; port->rx_dropping = dropping; *freeq_consumed = consumed; + *reschedule = budget && w != r; writew(r, ptr_reg); return received; } @@ -1590,12 +1598,13 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget) unsigned int freeq_threshold; unsigned int freeq_consumed; unsigned int received; + bool reschedule; freeq_threshold = 1 << (geth->freeq_order - 1); u64_stats_update_begin(&port->rx_stats_syncp); - received = gmac_rx(napi->dev, budget, &freeq_consumed); - if (received < budget) + received = gmac_rx(napi->dev, budget, &freeq_consumed, &reschedule); + if (!reschedule && received < budget) ++port->rx_napi_exits; u64_stats_update_end(&port->rx_stats_syncp); @@ -1606,10 +1615,11 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget) geth_fill_freeq(geth, true); } - if (received < budget && napi_complete_done(napi, received)) + if (!reschedule && received < budget && + napi_complete_done(napi, received)) gmac_enable_rx_irq(napi->dev, 1); - return received; + return reschedule ? budget : received; } static void gmac_dump_dma_state(struct net_device *netdev) From 65734bbe4a9fb78fca55b27c969656bfad1c7dc3 Mon Sep 17 00:00:00 2001 From: Steve Grubb Date: Thu, 10 Sep 2026 13:53:15 -0400 Subject: [PATCH 0568/2126] net: preserve socketpair output on setup failure socketpair() writes the reserved descriptor numbers to userspace before creating the sockets and their file objects. A later failure therefore leaves a modified caller's array despite returning an error, contrary to POSIX. For example, socketpair(AF_UNIX, SOCK_STREAM, -1, fd) returns EPROTONOSUPPORT but replaces the array's sentinel values with unused fd numbers. Defer the output stores until both file objects have been created, before installing either descriptor. If a store faults, drop both file references before releasing the reserved descriptor slots. Keep the early descriptor reservation and the existing setup-failure cleanup paths. In practice, I doubt anyone notices. But this aligns with the expected behavior Signed-off-by: Steve Grubb Link: https://patch.msgid.link/JyK226D0S5CWGUpAC4MO4A@redhat.com Signed-off-by: Jakub Kicinski --- net/socket.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/net/socket.c b/net/socket.c index c05d86e63abf..4cb8662869f0 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1851,10 +1851,7 @@ int __sys_socketpair(int family, int type, int protocol, int __user *usockvec) if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; - /* - * reserve descriptors and make sure we won't fail - * to return them to userland. - */ + /* Reserve both descriptors before creating the sockets. */ fd1 = get_unused_fd_flags(flags); if (unlikely(fd1 < 0)) return fd1; @@ -1865,14 +1862,6 @@ int __sys_socketpair(int family, int type, int protocol, int __user *usockvec) return fd2; } - err = put_user(fd1, &usockvec[0]); - if (err) - goto out; - - err = put_user(fd2, &usockvec[1]); - if (err) - goto out; - /* * Obtain the first socket and check if the underlying protocol * supports the socketpair call. @@ -1916,6 +1905,16 @@ int __sys_socketpair(int family, int type, int protocol, int __user *usockvec) goto out; } + /* Publish the descriptors now that it shouldn't fail. */ + err = put_user(fd1, &usockvec[0]); + if (!err) + err = put_user(fd2, &usockvec[1]); + if (err) { + fput(newfile2); + fput(newfile1); + goto out; + } + audit_fd_pair(fd1, fd2); fd_install(fd1, newfile1); From 9a483b60a0ad67fbd55c23a0ebb96754e984f585 Mon Sep 17 00:00:00 2001 From: Narcisa Vasile Date: Sat, 12 Sep 2026 22:24:19 -0700 Subject: [PATCH 0569/2126] selftests: drv-net: add BIG TCP test cases Add four new test cases that validate coalescing under increased size limits (BIG TCP): big_tcp_data_same - validates that equal-sized segments coalesce past the legacy IP_MAXPACKET limit. big_tcp_data_lrg_sml - validates that a smaller final segment coalesces into the previous chain of large-sized segments while crossing the IP_MAXPACKET limit. big_tcp_tcp_seq - validates that a packet with a wrong sequence number doesn't coalesce. The test uses a sequence number for which the low 16 bits correspond to the correct sequence number to validate against truncation bugs, since total aggregate length crosses over the legacy size limit for BIG TCP. big_tcp_large_max - validates that coalescing stops at the configured BIG TCP limit. Use a gro_flush_timeout value 2x higher for the BIG TCP test cases to prevent under-coalescing. Signed-off-by: Narcisa Vasile Link: https://patch.msgid.link/20260913052419.77910-1-narcisav.kernel@gmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/gro_lib.py | 59 +++++++- tools/testing/selftests/net/lib/gro.c | 133 +++++++++++++++++- 2 files changed, 187 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/drivers/net/gro_lib.py b/tools/testing/selftests/drivers/net/gro_lib.py index b7ac0660adc0..abecf60baa53 100644 --- a/tools/testing/selftests/drivers/net/gro_lib.py +++ b/tools/testing/selftests/drivers/net/gro_lib.py @@ -40,13 +40,17 @@ Test cases: - ip_v6ext_diff: (IPv6) IPv6 ext header with different payload doesn't coalesce - large_max: Packets exceeding GRO_MAX_SIZE don't coalesce - large_rem: Large packet remainder handling + - big_tcp_data_same: Same size packets coalesce past IP_MAXPACKET + - big_tcp_data_lrg_sml: Smaller last packet coalesces past IP_MAXPACKET + - big_tcp_tcp_seq: Packets with 16-bit truncated seqno don't coalesce + - big_tcp_large_max: Packets exceeding the BIG TCP limit don't coalesce """ import glob import os import re -from lib.py import ksft_run, ksft_exit, ksft_pr -from lib.py import NetDrvEpEnv, KsftFailEx, KsftXfailEx +from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_eq +from lib.py import NetDrvEpEnv, KsftFailEx, KsftSkipEx, KsftXfailEx from lib.py import NetdevFamily, EthtoolFamily from lib.py import bkg, cmd, ctl_file_write, defer, ethtool, ip from lib.py import ksft_variants, KsftNamedVariant @@ -55,6 +59,8 @@ from lib.py import ksft_variants, KsftNamedVariant # gro.c uses hardcoded DPORT=8000 GRO_DPORT = 8000 +BIG_TCP_GRO_MAX_SIZE = 128000 + def _resolve_dmac(cfg, ipver): """ @@ -91,6 +97,34 @@ def _set_mtu_restore(dev, mtu, host): defer(ip, f"link set dev {dev['ifname']} mtu {dev['mtu']}", host=host) +def _set_gro_size_restore(cfg, size): + """ + Set the local device's GRO size limits, then confirm they stuck. + """ + + _set_mtu_restore(cfg.dev, 4096, None) + _set_mtu_restore(cfg.remote_dev, 4096, cfg.remote) + + if "gro_max_size" not in cfg.dev or "gro_ipv4_max_size" not in cfg.dev: + raise KsftSkipEx("iproute2 does not report the GRO size limits") + + if (cfg.dev["gro_max_size"] == size and + cfg.dev["gro_ipv4_max_size"] == size): + return + + old = (f"gro_max_size {cfg.dev['gro_max_size']} " + f"gro_ipv4_max_size {cfg.dev['gro_ipv4_max_size']}") + new = f"gro_max_size {size} gro_ipv4_max_size {size}" + + ip(f"link set dev {cfg.ifname} {new}") + defer(ip, f"link set dev {cfg.ifname} {old}") + + dev = ip("-d link show dev " + cfg.ifname, json=True)[0] + ksft_eq(dev["gro_max_size"], size, comment="gro_max_size not applied") + ksft_eq(dev["gro_ipv4_max_size"], size, + comment="gro_ipv4_max_size not applied") + + def _set_ethtool_feat(dev, current, feats, host=None): s2n = {True: "on", False: "off"} @@ -239,7 +273,11 @@ def _setup(cfg, mode, test_name): flush_path = f"/sys/class/net/{cfg.ifname}/gro_flush_timeout" irq_path = f"/sys/class/net/{cfg.ifname}/napi_defer_hard_irqs" - ctl_file_write(flush_path, "200000") + # "big_tcp_*" tests need a longer timeout, use 2x the regular timeout + if test_name.startswith("big_tcp_"): + ctl_file_write(flush_path, "400000") + else: + ctl_file_write(flush_path, "200000") ctl_file_write(irq_path, "10") _set_ethtool_feat(cfg.ifname, cfg.feat, @@ -289,6 +327,9 @@ def _setup(cfg, mode, test_name): except KsftXfailEx: pass + if test_name.startswith("big_tcp_"): + _set_gro_size_restore(cfg, BIG_TCP_GRO_MAX_SIZE) + def _gro_variants(): """Generator that yields all combinations of protocol and test types.""" @@ -304,6 +345,11 @@ def _gro_variants(): "large_max", "large_rem", ] + big_tcp_tests = [ + "big_tcp_data_same", "big_tcp_data_lrg_sml", + "big_tcp_tcp_seq", "big_tcp_large_max", + ] + # Tests specific to IPv4 ipv4_tests = [ "ip_csum", @@ -322,6 +368,10 @@ def _gro_variants(): for test_name in common_tests: yield protocol, test_name + if protocol in ["ipv4", "ipv6"]: + for test_name in big_tcp_tests: + yield protocol, test_name + if protocol in ["ipv4", "ipip"]: for test_name in ipv4_tests: yield protocol, test_name @@ -358,7 +408,8 @@ def run_test(cfg, mode, protocol, test_name): if rx_proc.ret == 42: raise KsftFailEx(f"GRO over-coalesced in {protocol}/{test_name}") - if test_name.startswith("large_") and os.environ.get("KSFT_MACHINE_SLOW"): + if (test_name.startswith(("large_", "big_tcp_")) and + os.environ.get("KSFT_MACHINE_SLOW")): ksft_pr(f"Ignoring {protocol}/{test_name} failure due to slow environment") return diff --git a/tools/testing/selftests/net/lib/gro.c b/tools/testing/selftests/net/lib/gro.c index 7a333155de1a..70b0deb3c11f 100644 --- a/tools/testing/selftests/net/lib/gro.c +++ b/tools/testing/selftests/net/lib/gro.c @@ -46,6 +46,12 @@ * - large_max: exceeding max size * - large_rem: remainder handling * + * big_tcp_*: + * - big_tcp_data_same: equal segments coalescing past IP_MAXPACKET + * - big_tcp_data_lrg_sml: a smaller final segment carrying it over + * - big_tcp_tcp_seq: 16-bit truncated sequence number must not coalesce + * - big_tcp_large_max: coalescing stops at the configured limit + * * single, capacity: * Boring cases used to test coalescing machinery itself and stats * more than protocol behavior. @@ -110,6 +116,16 @@ #define EXIT_OVER_COALESCE 42 +/* Must match BIG_TCP_GRO_MAX_SIZE in gro_lib.py. */ +#define BIG_TCP_GRO_MAX_SIZE 128000 + +#define BIG_TCP_RECV_BUF_LEN \ + (BIG_TCP_GRO_MAX_SIZE + MAX_MSS + L2_HLEN_MAX) +#define BIG_TCP_MIN_MSS (ASSUMED_MTU - (MAX_HDR_LEN - ETH_HLEN)) +#define BIG_TCP_MAX_FILL_CNT \ + ((int)((BIG_TCP_GRO_MAX_SIZE - 1 - (MAX_HDR_LEN - ETH_HLEN)) / \ + BIG_TCP_MIN_MSS)) + #define ipv6_optlen(p) (((p)->hdrlen+1) << 3) /* calculate IPv6 extension header len */ #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) @@ -166,6 +182,27 @@ static int num_large_pkt(void) return max_payload() / calc_mss(); } +/* How many maximum sized segments fit under the configured limit. */ +static int big_tcp_large_cnt(void) +{ + return (BIG_TCP_GRO_MAX_SIZE - 1 - (total_hdr_len - ETH_HLEN)) / + calc_mss(); +} + +/* How many calc_mss() sized segments are needed to satisfy the + * following condition: + * pkt_count * calc_mss() < IP_MAXPACKET < (pkt_count + 1) * calc_mss() + */ +static int big_tcp_fill_cnt(void) +{ + return IP_MAXPACKET / calc_mss(); +} + +static int big_tcp_fill_len(void) +{ + return big_tcp_fill_cnt() * calc_mss(); +} + static void vlog(const char *fmt, ...) { va_list args; @@ -560,6 +597,61 @@ static void send_data_pkts(int fd, struct sockaddr_ll *daddr, write_packet(fd, buf, total_hdr_len + payload_len2, daddr); } +/* Send num_pkt segments of pkt_len bytes, then one of remainder len. */ +static void send_big_tcp(int fd, struct sockaddr_ll *daddr, int pkt_len, + int num_pkt, int remainder) +{ + static char pkts[BIG_TCP_MAX_FILL_CNT][MAX_HDR_LEN + MAX_MSS]; + static char last[MAX_HDR_LEN + MAX_MSS]; + const int filled = num_pkt * pkt_len; + int i; + + if (num_pkt > BIG_TCP_MAX_FILL_CNT) + error(1, 0, "need %d packets, array holds %d", + num_pkt, BIG_TCP_MAX_FILL_CNT); + + for (i = 0; i < num_pkt; i++) + create_packet(pkts[i], i * pkt_len, 0, pkt_len, 0); + create_packet(last, filled, 0, remainder, 0); + + for (i = 0; i < num_pkt; i++) + write_packet(fd, pkts[i], total_hdr_len + pkt_len, daddr); + write_packet(fd, last, total_hdr_len + remainder, daddr); +} + +/* In BIG TCP configuration, the total aggregate length can + * be greater than the legacy IP_MAXPACKET. Since the aggregate + * length is used in calculating the sequence numbers, + * send a packet with a sequence number that differs by IP_MAXPACKET + 1, + * to test against truncation bugs. + */ +static void send_big_tcp_bad_seq(int fd, struct sockaddr_ll *daddr) +{ + static char pkts[BIG_TCP_MAX_FILL_CNT][MAX_HDR_LEN + MAX_MSS]; + const int num_pkt = big_tcp_fill_cnt() + 1; + static char last[MAX_HDR_LEN + MAX_MSS]; + const int pkt_len = calc_mss(); + int bad_seq; + int filled; + int i; + + filled = num_pkt * pkt_len; + /* Low 16 bits match with the correct incoming sequence number. */ + bad_seq = filled - (IP_MAXPACKET + 1); + + if (num_pkt > BIG_TCP_MAX_FILL_CNT) + error(1, 0, "need %d packets, array holds %d", + num_pkt, BIG_TCP_MAX_FILL_CNT); + + for (i = 0; i < num_pkt; i++) + create_packet(pkts[i], i * pkt_len, 0, pkt_len, 0); + create_packet(last, bad_seq, 0, pkt_len, 0); + + for (i = 0; i < num_pkt; i++) + write_packet(fd, pkts[i], total_hdr_len + pkt_len, daddr); + write_packet(fd, last, total_hdr_len + pkt_len, daddr); +} + /* If incoming segments make tracked segment length exceed * legal IP datagram length, do not coalesce */ @@ -1161,7 +1253,7 @@ static void recv_error(int fd, int rcv_errno) static void check_recv_pkts(int fd, int *correct_payload, int correct_num_pkts) { - static char buffer[IP_MAXPACKET + L2_HLEN_MAX + 1]; + static char buffer[BIG_TCP_RECV_BUF_LEN]; int nhoff = ETH_HLEN + (pppoe ? PPPOE_SES_HLEN : 0); struct iphdr *iph = (struct iphdr *)(buffer + nhoff); struct ipv6hdr *ip6h = (struct ipv6hdr *)(buffer + nhoff); @@ -1541,6 +1633,25 @@ static void gro_sender(void) send_large(txfd, &daddr, remainder + 1); write_packet(txfd, fin_pkt, total_hdr_len, &daddr); + /* big tcp sub-tests */ + } else if (strcmp(testname, "big_tcp_data_same") == 0) { + send_big_tcp(txfd, &daddr, calc_mss(), big_tcp_fill_cnt(), + calc_mss()); + write_packet(txfd, fin_pkt, total_hdr_len, &daddr); + } else if (strcmp(testname, "big_tcp_data_lrg_sml") == 0) { + int remainder = calc_mss() / 2; + + send_big_tcp(txfd, &daddr, calc_mss(), big_tcp_fill_cnt(), + remainder); + write_packet(txfd, fin_pkt, total_hdr_len, &daddr); + } else if (strcmp(testname, "big_tcp_tcp_seq") == 0) { + send_big_tcp_bad_seq(txfd, &daddr); + write_packet(txfd, fin_pkt, total_hdr_len, &daddr); + } else if (strcmp(testname, "big_tcp_large_max") == 0) { + send_big_tcp(txfd, &daddr, calc_mss(), big_tcp_large_cnt(), + calc_mss()); + write_packet(txfd, fin_pkt, total_hdr_len, &daddr); + /* machinery sub-tests */ } else if (strcmp(testname, "single") == 0) { static char buf[MAX_HDR_LEN + PAYLOAD_LEN]; @@ -1768,6 +1879,26 @@ static void gro_receiver(void) printf("last segment sent individually: "); check_recv_pkts(rxfd, correct_payload, 3); + /* big tcp sub-tests */ + } else if (strcmp(testname, "big_tcp_data_same") == 0) { + correct_payload[0] = big_tcp_fill_len() + calc_mss(); + printf("data packets of same size past IP_MAXPACKET: "); + check_recv_pkts(rxfd, correct_payload, 1); + } else if (strcmp(testname, "big_tcp_data_lrg_sml") == 0) { + correct_payload[0] = big_tcp_fill_len() + calc_mss() / 2; + printf("smaller last packet past IP_MAXPACKET: "); + check_recv_pkts(rxfd, correct_payload, 1); + } else if (strcmp(testname, "big_tcp_tcp_seq") == 0) { + correct_payload[0] = (big_tcp_fill_cnt() + 1) * calc_mss(); + correct_payload[1] = calc_mss(); + printf("aliased seq past IP_MAXPACKET doesn't coalesce: "); + check_recv_pkts(rxfd, correct_payload, 2); + } else if (strcmp(testname, "big_tcp_large_max") == 0) { + correct_payload[0] = big_tcp_large_cnt() * calc_mss(); + correct_payload[1] = calc_mss(); + printf("shouldn't coalesce past gro_max_size: "); + check_recv_pkts(rxfd, correct_payload, 2); + /* machinery sub-tests */ } else if (strcmp(testname, "single") == 0) { printf("single data packet: "); From 7bc21b740291c06b6437fd7ed7fab2d707b35cff Mon Sep 17 00:00:00 2001 From: Narcisa Vasile Date: Tue, 15 Sep 2026 18:00:29 -0700 Subject: [PATCH 0570/2126] selftests: net: gro: fix OOB access when under-coalescing When more packets than expected are received, num_pkt could index beyond the end of the array. Add a check to prevent OOB access. Continue receiving until the FIN is received to obtain the total packet count. This helps diagnose issues by distinguishing the cases where no coalescing happened from the partial-coalescing cases that didn't meet the test check. Signed-off-by: Narcisa Vasile Link: https://patch.msgid.link/20260916010029.50911-1-narcisav.kernel@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/gro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/gro.c b/tools/testing/selftests/net/lib/gro.c index 70b0deb3c11f..fb6a72275636 100644 --- a/tools/testing/selftests/net/lib/gro.c +++ b/tools/testing/selftests/net/lib/gro.c @@ -1303,7 +1303,8 @@ static void check_recv_pkts(int fd, int *correct_payload, - sizeof(struct tcphdr) - sizeof(struct iphdr); } vlog("%d ", data_len); - if (data_len != correct_payload[num_pkt]) { + if (num_pkt < correct_num_pkts && + data_len != correct_payload[num_pkt]) { vlog("[!=%d]", correct_payload[num_pkt]); bad_packet = true; } From 063510768490d85454a99b27be303aad5efdf624 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Tue, 15 Sep 2026 10:48:11 +0200 Subject: [PATCH 0571/2126] ppp_synctty: Use common error handling code in ppp_sync_txmunge() Use an additional label so that a bit of exception handling can be better reused at the end of this function implementation. Signed-off-by: Markus Elfring Reviewed-by: Simon Horman Link: https://patch.msgid.link/15f151c7-58c8-4116-8a03-e985fd132b0f@web.de Signed-off-by: Paolo Abeni --- drivers/net/ppp/ppp_synctty.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c index ebd62a7ab54b..9e440e110e9f 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -436,10 +436,9 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) int islcp; /* Ensure we can safely access protocol field and LCP code */ - if (!pskb_may_pull(skb, 3)) { - kfree_skb(skb); - return NULL; - } + if (!pskb_may_pull(skb, 3)) + goto free_skb; + data = skb->data; proto = get_unaligned_be16(data); @@ -455,10 +454,9 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) /* prepend address/control fields if necessary */ if ((ap->flags & SC_COMP_AC) == 0 || islcp) { - if (skb_cow_head(skb, 2)) { - kfree_skb(skb); - return NULL; - } + if (skb_cow_head(skb, 2)) + goto free_skb; + skb_push(skb,2); skb->data[0] = PPP_ALLSTATIONS; skb->data[1] = PPP_UI; @@ -470,6 +468,10 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) ppp_print_buffer ("send buffer", skb->data, skb->len); return skb; + +free_skb: + kfree_skb(skb); + return NULL; } /* From 859e40055c19ceb8b8215f3269e57075023b72b4 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Wed, 16 Sep 2026 14:58:44 +0800 Subject: [PATCH 0572/2126] openvswitch: raise internal port TSO limit Set the internal port TSO limit to GSO_MAX_SIZE (512 KB), as for loopback and veth. This allows the admin/user to set a GSO limit up to this value, to use BIG TCP for traffic routed through the internal port. Only the capability limit changes: the IPv4 and IPv6 GSO and GRO limits remain at 64 KiB until changed by the administrator. Validation used a same-host test with a temporary OVS bridge, a veth pair, and a network namespace: TCP client -> OVS internal -> OVS bridge -> veth -> TCP server The veth endpoints were BIG TCP capable throughout the test, and only the OVS internal port limits changed between 64 KiB and 524280 bytes. A single iperf3 3.19 TCP flow, run separately over IPv4 and IPv6 with six alternating runs per state (`-t 15 -O 5`, fixed CPU affinity and port tuple), increased throughput by 18.1% for IPv4 and 34.7% for IPv6: protocol BIG TCP off BIG TCP on CV off / on TCP/IPv4 65.567 Gbps 77.420 Gbps 1.12% / 0.37% TCP/IPv6 55.355 Gbps 74.568 Gbps 1.20% / 0.68% Assisted-by: LLM Signed-off-by: Wang Zhan Reviewed-by: Ilya Maximets Reviewed-by: Eelco Chaudron Link: https://patch.msgid.link/20260916065844.1380155-1-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- net/openvswitch/vport-internal_dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c index 125d310871e9..77a16d5ebd54 100644 --- a/net/openvswitch/vport-internal_dev.c +++ b/net/openvswitch/vport-internal_dev.c @@ -117,6 +117,8 @@ static void do_setup(struct net_device *netdev) netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX; netdev->hw_features = netdev->features; + netif_set_tso_max_size(netdev, GSO_MAX_SIZE); + eth_hw_addr_random(netdev); } From 546f109fdbbca75684f1041a1193cb910004a289 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Sat, 12 Sep 2026 21:40:40 +0800 Subject: [PATCH 0573/2126] ipv6: make IPV6_FREEBIND and IPV6_TRANSPARENT setsockopt lockless IPV6_FREEBIND and IPV6_TRANSPARENT still take the socket lock despite using inet_assign_bit() to update the flags shared with IP_FREEBIND and IP_TRANSPARENT. IPv6 TCP and UDP sockets can already update these flags without the lock through the corresponding SOL_IP options. Move both options to the lockless setsockopt path. Signed-off-by: Xuanqiang Luo Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260912134040.215664-1-xuanqiang.luo@linux.dev Signed-off-by: Paolo Abeni --- net/ipv6/ipv6_sockglue.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 1f68fb64a43e..4b3536571c98 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -398,6 +398,21 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, /* Handle options that can be set without locking the socket. */ switch (optname) { + case IPV6_FREEBIND: + if (optlen < sizeof(int)) + return -EINVAL; + /* Shared with IP_FREEBIND. */ + inet_assign_bit(FREEBIND, sk, valbool); + return 0; + case IPV6_TRANSPARENT: + if (valbool && !sockopt_ns_capable(net->user_ns, CAP_NET_RAW) && + !sockopt_ns_capable(net->user_ns, CAP_NET_ADMIN)) + return -EPERM; + if (optlen < sizeof(int)) + return -EINVAL; + /* Shared with IP_TRANSPARENT. */ + inet_assign_bit(TRANSPARENT, sk, valbool); + return 0; case IPV6_UNICAST_HOPS: if (optlen < sizeof(int)) return -EINVAL; @@ -666,27 +681,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv = 0; break; - case IPV6_TRANSPARENT: - if (valbool && !sockopt_ns_capable(net->user_ns, CAP_NET_RAW) && - !sockopt_ns_capable(net->user_ns, CAP_NET_ADMIN)) { - retv = -EPERM; - break; - } - if (optlen < sizeof(int)) - goto e_inval; - /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ - inet_assign_bit(TRANSPARENT, sk, valbool); - retv = 0; - break; - - case IPV6_FREEBIND: - if (optlen < sizeof(int)) - goto e_inval; - /* we also don't have a separate freebind bit for IPV6 */ - inet_assign_bit(FREEBIND, sk, valbool); - retv = 0; - break; - case IPV6_RECVORIGDSTADDR: if (optlen < sizeof(int)) goto e_inval; From b8a6f2340999bedd3b83ded2e909d855b6db1f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Jab=C5=AFrek?= Date: Mon, 14 Sep 2026 08:58:48 +0200 Subject: [PATCH 0574/2126] selftests: net: add IPv4 and IPv6 address order check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce the following new tests: `ipv4_verify_same_scope_addr_order`, `ipv4_verify_inter_scope_addr_order`, `ipv6_verify_same_scope_addr_order`, `ipv6_verify_inter_scope_addr_order` to check the ordering of a set of IP addresses after being inserted. The implementations of these protocols are inconsistent in regard to address ordering. IPv4 addresses stay in the same order as inserted while IPv6 addresses appear in reverse order. This inconsistency has prompted attempts to unify the ordering, so both protocols act the same (as IPv4). This however caused user-space regressions in certain applications, which relied on the order as it was prior to the change (particularly NetworkManager). A similar inconsistency occurs when inserting different scope addresses, where IPv4 puts link local ones before global and IPv6 does the opposite. Attempts were already made to unify this also, risking further regressions. The addition of these tests aims to consolidate current behaviour to prevent regressions in the future. The expected behaviour is the initial one, where each protocol acts differently. The same goes for inter scope addresses. Conversations detailing the decision processes for creating these tests are linked below. Link: https://lore.kernel.org/netdev/20260521135310.GC977@cmadams.net/ Link: https://lore.kernel.org/netdev/20260529112357.5079-1-fmancera@suse.de/ Link: https://lore.kernel.org/netdev/20260721090114.GA2510713@shredder/ Suggested-by: Fernando Fernandez Mancera Signed-off-by: Martin Jabůrek Reviewed-by: Fernando Fernandez Mancera Link: https://patch.msgid.link/20260914065848.10518-1-martin.jaburek@suse.com Signed-off-by: Paolo Abeni --- tools/testing/selftests/net/rtnetlink.py | 113 ++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/rtnetlink.py b/tools/testing/selftests/net/rtnetlink.py index 5cc3ebdcf08d..dc8c77db4897 100755 --- a/tools/testing/selftests/net/rtnetlink.py +++ b/tools/testing/selftests/net/rtnetlink.py @@ -314,11 +314,122 @@ def ipv6_route_del_reason_absent() -> None: "user deletion must not carry del-reason") +def _insert_and_get_addrs_ipv4(test_addrs: list[str], scopes: list[str]) -> list[str]: + with NetNS() as ns, NetNSEnter(str(ns)): + dev_name = "dummy_dev" + + ip(f"link add name {dev_name} type dummy", ns=str(ns)) + for test_addr, scope in zip(test_addrs, scopes): + ip(f"address add {test_addr}/24 dev {dev_name} scope {scope}", ns=str(ns)) + + rtnl = RtnlAddrFamily() + addrs = rtnl.getaddr({"ifa-family": socket.AF_INET}, dump=True) + return [addr["address"] for addr in addrs] + + +def ipv4_verify_same_scope_addr_order() -> None: + """ + After inserting multiple same scope IPv4 addresses, their order + must be the same as the insertion order. The only aspect affecting + this are primary addresses, which precede secondary ones. + """ + + primary_first = ["192.0.2.1", "203.0.113.1", "192.0.2.2", "203.0.113.2"] + scopes = ["global"] * 4 + expected_result = primary_first + resulting_list = _insert_and_get_addrs_ipv4(primary_first, scopes) + ksft_eq(resulting_list, expected_result, "Unexpected IPv4 address order") + + subnet_first = ["192.0.2.1", "192.0.2.2", "203.0.113.1", "203.0.113.2"] + # Scope and expected result stay the same. + resulting_list = _insert_and_get_addrs_ipv4(subnet_first, scopes) + ksft_eq(resulting_list, expected_result, "Unexpected IPv4 address order") + + +def ipv4_verify_inter_scope_addr_order() -> None: + """ + When IPv4 addresses from different scopes are inserted, + primary link local addresses must precede global ones. + + Address ordering across different scopes has also + been attempted to be patched, bringing in a new risk of a user-space + regression, similar to the same scope equivalent. This will further + consolidate the implementation differences of both protocols. + """ + + test_addrs = ["192.0.2.1", "203.0.113.1", "192.0.2.2", "203.0.113.2"] + + link_first = ["link", "global", "link", "global"] + expected_result = test_addrs + resulting_list = _insert_and_get_addrs_ipv4(test_addrs, link_first) + ksft_eq(resulting_list, expected_result, "Unexpected IPv4 address order across scopes") + + global_first = ["global", "link", "global", "link"] + expected_result = ["203.0.113.1", "192.0.2.1", "192.0.2.2", "203.0.113.2"] + resulting_list = _insert_and_get_addrs_ipv4(test_addrs, global_first) + ksft_eq(resulting_list, expected_result, "Unexpected IPv4 address order across scopes") + + +def _insert_and_get_addrs_ipv6(test_addrs: list[str]) -> list[str]: + with NetNS() as ns, NetNSEnter(str(ns)): + dev_name = "dummy_dev" + + ip(f"link add name {dev_name} type dummy", ns=str(ns)) + for test_addr in test_addrs: + ip(f"address add {test_addr}/64 dev {dev_name}", ns=str(ns)) + + rtnl = RtnlAddrFamily() + addrs = rtnl.getaddr({"ifa-family": socket.AF_INET6}, dump=True) + return [addr["address"] for addr in addrs] + + +def ipv6_verify_same_scope_addr_order() -> None: + """ + After inserting multiple same scope IPv6 addresses, their order + must be the _reverse_ of the insertion order. + + While this behaviour is different from how IPv4 acts, + updating the IPv6 implementation to act the same way + has proved to cause user-space application regressions + (particularly in NetworkManager). This behaviour is being + tested to consolidate it as being expected and correct. + """ + + addr_list = ["2001:db8::1", "2001:db8::2", "2001:db8::3"] + expected_result = addr_list[::-1] + resulting_list = _insert_and_get_addrs_ipv6(addr_list) + ksft_eq(resulting_list, expected_result, "Unexpected IPv6 address order") + + +def ipv6_verify_inter_scope_addr_order() -> None: + """ + Inserted IPv6 addresses from different scopes must have + global primary address precede link local ones. This again + is the _reverse_ of how IPv4 addresses are ordered. + + To prevent potential user-space regressions with IPv6 + addresses, the inter-scope insertion order is also being tested. + """ + + global_first = ["2001:db8::1", "fe80::1", "2001:db8::2", "fe80::2"] + # Not only must the global addresses be first, but their insertion order must be reversed. + expected_result = ["2001:db8::2", "2001:db8::1", "fe80::2", "fe80::1"] + resulting_list = _insert_and_get_addrs_ipv6(global_first) + ksft_eq(resulting_list, expected_result, "Unexpected IPv6 address order across scopes") + + link_first = ["fe80::1", "2001:db8::1", "fe80::2", "2001:db8::2"] + # Expected result stays the same. + resulting_list = _insert_and_get_addrs_ipv6(link_first) + ksft_eq(resulting_list, expected_result, "Unexpected IPv6 address order across scopes") + + def main() -> None: ksft_run([dump_mcaddr_check, dump_mcaddr6_check, ipv4_devconf_notify, ipv6_route_del_reason_expired, ipv6_route_del_reason_ra_withdrawn, - ipv6_route_del_reason_absent]) + ipv6_route_del_reason_absent, + ipv4_verify_same_scope_addr_order, ipv4_verify_inter_scope_addr_order, + ipv6_verify_same_scope_addr_order, ipv6_verify_inter_scope_addr_order]) ksft_exit() if __name__ == "__main__": From 5ccdfb2c3203207deb17e7c5b0db8c7f475639a7 Mon Sep 17 00:00:00 2001 From: Taylor Bates Date: Mon, 14 Sep 2026 21:53:15 -0400 Subject: [PATCH 0575/2126] netlink: specs: fix duplicate if/then keys in netlink-raw schema Currently netlink-raw.yaml contains two if keys and two then keys in a single mapping that enforces a "len" for "pad" members and a "len" or "struct" for binary members. During validation PyYAML resolves duplicate keys last-wins, so only the binary rule survives. Pad has not been validated since commit bf08f32c8ced ("tools/net/ynl: Add support for nested structs") added the second if/then pair in January 2024. None of the current specs violate this rule, but this validation should not be parser dependent and unspecified. Strict YAML validators such as Red Hat's VS Code YAML extension and Adrien Verge's yamllint will reject the netlink-raw.yaml schema: Command: $ yamllint Documentation/netlink/netlink-raw.yaml Output: 185:13 error duplication of key "if" in mapping (key-duplicates) 189:13 error duplication of key "then" in mapping (key-duplicates) The following invalid netlink family spec will pass validation in the current ynl tooling: # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) --- name: minimal-raw doc: Minimal netlink-raw family for schema validation testing. protocol: netlink-raw protonum: 0 definitions: - name: test-struct type: struct members: - name: reserved type: pad # len intentionally omitted attribute-sets: [] operations: list: [] Signed-off-by: Taylor Bates Reviewed-by: Hangbin Liu Reviewed-by: Donald Hunter Link: https://patch.msgid.link/20260914-ynl-robustness-v2-1-c6125003b21e@gmail.com Signed-off-by: Paolo Abeni --- Documentation/netlink/netlink-raw.yaml | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Documentation/netlink/netlink-raw.yaml b/Documentation/netlink/netlink-raw.yaml index 4c436b59a34b..18ccfe05048a 100644 --- a/Documentation/netlink/netlink-raw.yaml +++ b/Documentation/netlink/netlink-raw.yaml @@ -176,20 +176,23 @@ properties: struct: description: Name of the nested struct type. type: string - if: - properties: - type: - const: pad - then: - required: [ len ] - if: - properties: - type: - const: binary - then: - oneOf: - - required: [ len ] - - required: [ struct ] + allOf: + - + if: + properties: + type: + const: pad + then: + required: [ len ] + - + if: + properties: + type: + const: binary + then: + oneOf: + - required: [ len ] + - required: [ struct ] # End genetlink-legacy attribute-sets: From 26ee8cd69d46a14b37ba5e512084fe80d730127a Mon Sep 17 00:00:00 2001 From: Abdifatah Suruur Date: Tue, 15 Sep 2026 22:56:42 +0300 Subject: [PATCH 0576/2126] net: qualcomm: rmnet: require CAP_NET_ADMIN in the real device netns for config ops An rmnet device may be created with its real device in a different netns than the rmnet device itself (rmnet_newlink() resolves it in link_net), and the config paths below only check CAP_NET_ADMIN against dev_net(dev), while mutating rmnet port state attached to the real device: - rmnet_changelink() rewrites the endpoint mux table and port->data_format and, via rmnet_vnd_update_dev_mtu(), can shrink the MTU of the rmnet endpoint netdevs. - rmnet_add_bridge() and rmnet_del_bridge(), reachable via ndo_add_slave/ndo_del_slave through RTM_SETLINK IFLA_MASTER, flip port->rmnet_mode and port->bridge_ep on the real device's port; with bridge_ep pointing at a caller-owned device, rmnet_rx_handler() then forwards real-device ingress frames to it. - rmnet_set_coalesce() rewrites the port aggregation parameters via ETHTOOL_SCOALESCE (ioctl) or ETHTOOL_MSG_COALESCE_SET (netlink), whose capability checks likewise only cover dev's netns. A caller privileged only in the rmnet device's netns can therefore rewrite the shared cellular data-path state owned by another netns, and steer its ingress traffic. Gate the rtnl paths with rtnl_dev_link_net_capable(), matching the "require CAP_NET_ADMIN in the device netns for changelink" series (vxlan/geneve, CVE-2026-68432), and gate the ethtool setter with ns_capable() in the real device netns, mirroring the check dev_ethtool() already applies to dev's netns. Report the new rejections through extack where one is available. The gates cover the configuration paths only. Teardown (RTM_DELLINK reaching rmnet_dellink(), and rmnet_config_notify_cb() unregistering the bridge when the slave device is deleted) is intentionally left ungated: link deletion is normal netdev lifecycle behaviour, and the changelink series this matches (vxlan/geneve, CVE-2026-68432) gated only the configuration paths. Reviewed-by: Simon Horman Signed-off-by: Abdifatah Suruur Reviewed-by: Subash Abhinov Kasiviswanathan Link: https://patch.msgid.link/20260915195642.1912-1-suruurism@gmail.com Signed-off-by: Paolo Abeni --- .../ethernet/qualcomm/rmnet/rmnet_config.c | 21 ++++++++++++++++++- .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 11 +++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c index bed6f63facf2..8bf385ab44a9 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -312,6 +312,12 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[], if (!rmnet_is_real_dev_registered(real_dev)) return -ENODEV; + if (!rtnl_dev_link_net_capable(dev, dev_net(real_dev))) { + NL_SET_ERR_MSG_MOD(extack, + "request modifies device in another netns"); + return -EPERM; + } + port = rmnet_get_port_rtnl(real_dev); if (data[IFLA_RMNET_MUX_ID]) { @@ -441,6 +447,12 @@ int rmnet_add_bridge(struct net_device *rmnet_dev, struct rmnet_port *port, *slave_port; int err; + if (!rtnl_dev_link_net_capable(slave_dev, dev_net(real_dev))) { + NL_SET_ERR_MSG_MOD(extack, + "request modifies device in another netns"); + return -EPERM; + } + port = rmnet_get_port_rtnl(real_dev); /* If there is more than one rmnet dev attached, its probably being @@ -489,7 +501,14 @@ int rmnet_add_bridge(struct net_device *rmnet_dev, int rmnet_del_bridge(struct net_device *rmnet_dev, struct net_device *slave_dev) { - struct rmnet_port *port = rmnet_get_port_rtnl(slave_dev); + struct rmnet_priv *priv = netdev_priv(rmnet_dev); + struct net_device *real_dev = priv->real_dev; + struct rmnet_port *port; + + if (!rtnl_dev_link_net_capable(slave_dev, dev_net(real_dev))) + return -EPERM; + + port = rmnet_get_port_rtnl(slave_dev); rmnet_unregister_bridge(port); diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c index 4f0ddcedfa97..53802b485a81 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c @@ -4,9 +4,11 @@ * RMNET Data virtual network driver */ +#include #include #include #include +#include #include #include "rmnet_config.h" #include "rmnet_handlers.h" @@ -240,9 +242,16 @@ static int rmnet_set_coalesce(struct net_device *dev, struct netlink_ext_ack *extack) { struct rmnet_priv *priv = netdev_priv(dev); + struct net_device *real_dev = priv->real_dev; struct rmnet_port *port; - port = rmnet_get_port_rtnl(priv->real_dev); + if (!ns_capable(dev_net(real_dev)->user_ns, CAP_NET_ADMIN)) { + NL_SET_ERR_MSG_MOD(extack, + "request modifies device in another netns"); + return -EPERM; + } + + port = rmnet_get_port_rtnl(real_dev); if (kernel_coal->tx_aggr_max_frames < 1 || kernel_coal->tx_aggr_max_frames > 64) return -EINVAL; From e3a93c886d9ae941593e0b867fe93fc7726a64bf Mon Sep 17 00:00:00 2001 From: Tony Nguyen Date: Thu, 2 Jul 2026 12:29:55 +0200 Subject: [PATCH 0577/2126] ice: rename shared Flow Director functions and structs Rename shared Flow Director functions and structs. These entities are currently used to add Flow Director filters, however, they will be expanded to also add ACL filters. Rename the functions and struct, replacing 'fdir' to 'ntuple', to reflect that they are being used for ntuple filters and are not solely used for Flow Director. Rename the file to also reflect this change. Co-developed-by: Paul M Stillwell Jr Signed-off-by: Paul M Stillwell Jr Reviewed-by: Aleksandr Loktionov Co-developed-by: Marcin Szycik Signed-off-by: Marcin Szycik Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/Makefile | 2 +- drivers/net/ethernet/intel/ice/ice.h | 6 +- drivers/net/ethernet/intel/ice/ice_arfs.c | 8 +- drivers/net/ethernet/intel/ice/ice_arfs.h | 2 +- drivers/net/ethernet/intel/ice/ice_ethtool.c | 9 +- ...ce_ethtool_fdir.c => ice_ethtool_ntuple.c} | 85 ++++++++++++------- drivers/net/ethernet/intel/ice/ice_fdir.c | 38 ++------- drivers/net/ethernet/intel/ice/ice_fdir.h | 14 ++- drivers/net/ethernet/intel/ice/ice_type.h | 4 +- drivers/net/ethernet/intel/ice/virt/fdir.c | 28 +++--- 10 files changed, 98 insertions(+), 98 deletions(-) rename drivers/net/ethernet/intel/ice/{ice_ethtool_fdir.c => ice_ethtool_ntuple.c} (96%) diff --git a/drivers/net/ethernet/intel/ice/Makefile b/drivers/net/ethernet/intel/ice/Makefile index 95fd0c49800f..a952bacb7ec7 100644 --- a/drivers/net/ethernet/intel/ice/Makefile +++ b/drivers/net/ethernet/intel/ice/Makefile @@ -24,7 +24,7 @@ ice-y := ice_main.o \ ice_vsi_vlan_ops.o \ ice_vsi_vlan_lib.o \ ice_fdir.o \ - ice_ethtool_fdir.o \ + ice_ethtool_ntuple.o \ ice_vlan_mode.o \ ice_flex_pipe.o \ ice_flow.o \ diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index e5f940d324dc..cb7a73bbcd71 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -1018,11 +1018,11 @@ void ice_deinit_rdma(struct ice_pf *pf); bool ice_is_wol_supported(struct ice_hw *hw); void ice_fdir_del_all_fltrs(struct ice_vsi *vsi); int -ice_fdir_write_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, bool add, +ice_fdir_write_fltr(struct ice_pf *pf, struct ice_ntuple_fltr *input, bool add, bool is_tun); void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena); -int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd); -int ice_del_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd); +int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd); +int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd); int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd); int ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd, diff --git a/drivers/net/ethernet/intel/ice/ice_arfs.c b/drivers/net/ethernet/intel/ice/ice_arfs.c index 53b6e2b09eb9..e0335f5e18fe 100644 --- a/drivers/net/ethernet/intel/ice/ice_arfs.c +++ b/drivers/net/ethernet/intel/ice/ice_arfs.c @@ -302,7 +302,7 @@ ice_arfs_build_entry(struct ice_vsi *vsi, const struct flow_keys *fk, u16 rxq_idx, u32 flow_id) { struct ice_arfs_entry *arfs_entry; - struct ice_fdir_fltr *fltr_info; + struct ice_ntuple_fltr *fltr_info; u8 ip_proto; arfs_entry = devm_kzalloc(ice_pf_to_dev(vsi->back), @@ -392,8 +392,8 @@ ice_arfs_is_perfect_flow_set(struct ice_hw *hw, __be16 l3_proto, u8 l4_proto) * * false - fltr_info and fk refer to different flows. */ static bool -ice_arfs_cmp(const struct ice_fdir_fltr *fltr_info, const struct flow_keys *fk, - __be16 n_proto, u8 ip_proto) +ice_arfs_cmp(const struct ice_ntuple_fltr *fltr_info, + const struct flow_keys *fk, __be16 n_proto, u8 ip_proto) { /* Determine if the filter is for IPv4 or IPv6 based on flow_type, * which is one of ICE_FLTR_PTYPE_NONF_IPV{4,6}_{TCP,UDP}. @@ -485,7 +485,7 @@ ice_rx_flow_steer(struct net_device *netdev, const struct sk_buff *skb, spin_lock_bh(&vsi->arfs_lock); hlist_for_each_entry(arfs_entry, &vsi->arfs_fltr_list[idx], list_entry) { - struct ice_fdir_fltr *fltr_info; + struct ice_ntuple_fltr *fltr_info; /* keep searching for the already existing arfs_entry flow */ if (arfs_entry->flow_id != flow_id) diff --git a/drivers/net/ethernet/intel/ice/ice_arfs.h b/drivers/net/ethernet/intel/ice/ice_arfs.h index 9706293128c3..7393254b7e0a 100644 --- a/drivers/net/ethernet/intel/ice/ice_arfs.h +++ b/drivers/net/ethernet/intel/ice/ice_arfs.h @@ -13,7 +13,7 @@ enum ice_arfs_fltr_state { }; struct ice_arfs_entry { - struct ice_fdir_fltr fltr_info; + struct ice_ntuple_fltr fltr_info; struct hlist_node list_entry; u64 time_activated; /* only valid for UDP flows */ u32 flow_id; diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c index bf9a821c543b..ef1c66855723 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -3088,9 +3088,9 @@ static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) switch (cmd->cmd) { case ETHTOOL_SRXCLSRLINS: - return ice_add_fdir_ethtool(vsi, cmd); + return ice_add_ntuple_ethtool(vsi, cmd); case ETHTOOL_SRXCLSRLDEL: - return ice_del_fdir_ethtool(vsi, cmd); + return ice_del_ntuple_ethtool(vsi, cmd); default: break; } @@ -3132,7 +3132,7 @@ ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, switch (cmd->cmd) { case ETHTOOL_GRXCLSRLCNT: - cmd->rule_cnt = hw->fdir_active_fltr; + cmd->rule_cnt = hw->ntuple_active_fltr_cnt; /* report total rule count */ cmd->data = ice_get_fdir_cnt_all(hw); ret = 0; @@ -3908,7 +3908,8 @@ static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch) return -EOPNOTSUPP; } - if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) { + if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && + pf->hw.ntuple_active_fltr_cnt) { netdev_err(dev, "Cannot set channels when Flow Director filters are active\n"); return -EOPNOTSUPP; } diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c similarity index 96% rename from drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c rename to drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c index aceec184e89b..744cd0b82470 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c @@ -120,7 +120,7 @@ static bool ice_is_mask_valid(u64 mask, u64 field) int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd) { struct ethtool_rx_flow_spec *fsp; - struct ice_fdir_fltr *rule; + struct ice_ntuple_fltr *rule; int ret = 0; u16 idx; @@ -240,7 +240,7 @@ int ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd, u32 *rule_locs) { - struct ice_fdir_fltr *f_rule; + struct ice_ntuple_fltr *f_rule; unsigned int cnt = 0; int val = 0; @@ -1487,10 +1487,10 @@ static void ice_update_per_q_fltr(struct ice_vsi *vsi, u32 q_index, bool inc) * @add: true adds filter and false removed filter * @is_tun: true adds inner filter on tunnel and false outer headers * - * returns 0 on success and negative value on error + * Return: 0 on success and negative value on error */ int -ice_fdir_write_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, bool add, +ice_fdir_write_fltr(struct ice_pf *pf, struct ice_ntuple_fltr *input, bool add, bool is_tun) { struct device *dev = ice_pf_to_dev(pf); @@ -1557,10 +1557,10 @@ err_frag: * @input: filter structure * @add: true adds filter and false removed filter * - * returns 0 on success and negative value on error + * Return: 0 on success and negative value on error */ static int -ice_fdir_write_all_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, +ice_fdir_write_all_fltr(struct ice_pf *pf, struct ice_ntuple_fltr *input, bool add) { u16 port_num; @@ -1585,7 +1585,7 @@ ice_fdir_write_all_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, */ void ice_fdir_replay_fltrs(struct ice_pf *pf) { - struct ice_fdir_fltr *f_rule; + struct ice_ntuple_fltr *f_rule; struct ice_hw *hw = &pf->hw; list_for_each_entry(f_rule, &hw->fdir_list_head, fltr_node) { @@ -1622,6 +1622,25 @@ int ice_fdir_create_dflt_rules(struct ice_pf *pf) return err; } +/** + * ice_ntuple_update_cntrs - increment or decrement filter counter + * @hw: pointer to hardware structure + * @flow: filter flow type + * @add: true to increment, false to decrement + */ +static void ice_ntuple_update_cntrs(struct ice_hw *hw, + enum ice_fltr_ptype flow, bool add) +{ + int incr = add ? 1 : -1; + + hw->ntuple_active_fltr_cnt += incr; + + if (flow == ICE_FLTR_PTYPE_NONF_NONE || flow >= ICE_FLTR_PTYPE_MAX) + ice_debug(hw, ICE_DBG_SW, "Unknown filter type %d\n", flow); + else + hw->fdir_fltr_cnt[flow] += incr; +} + /** * ice_fdir_del_all_fltrs - Delete all flow director filters * @vsi: the VSI being changed @@ -1630,13 +1649,13 @@ int ice_fdir_create_dflt_rules(struct ice_pf *pf) */ void ice_fdir_del_all_fltrs(struct ice_vsi *vsi) { - struct ice_fdir_fltr *f_rule, *tmp; + struct ice_ntuple_fltr *f_rule, *tmp; struct ice_pf *pf = vsi->back; struct ice_hw *hw = &pf->hw; list_for_each_entry_safe(f_rule, tmp, &hw->fdir_list_head, fltr_node) { ice_fdir_write_all_fltr(pf, f_rule, false); - ice_fdir_update_cntrs(hw, f_rule->flow_type, false); + ice_ntuple_update_cntrs(hw, f_rule->flow_type, false); list_del(&f_rule->fltr_node); devm_kfree(ice_pf_to_dev(pf), f_rule); } @@ -1701,18 +1720,18 @@ ice_fdir_do_rem_flow(struct ice_pf *pf, enum ice_fltr_ptype flow_type) } /** - * ice_fdir_update_list_entry - add or delete a filter from the filter list + * ice_ntuple_update_list_entry - add or delete a filter from the filter list * @pf: PF structure * @input: filter structure * @fltr_idx: ethtool index of filter to modify * - * returns 0 on success and negative on errors + * Return: 0 on success and negative on errors */ static int -ice_fdir_update_list_entry(struct ice_pf *pf, struct ice_fdir_fltr *input, - int fltr_idx) +ice_ntuple_update_list_entry(struct ice_pf *pf, struct ice_ntuple_fltr *input, + int fltr_idx) { - struct ice_fdir_fltr *old_fltr; + struct ice_ntuple_fltr *old_fltr; struct ice_hw *hw = &pf->hw; struct ice_vsi *vsi; int err = -ENOENT; @@ -1730,7 +1749,7 @@ ice_fdir_update_list_entry(struct ice_pf *pf, struct ice_fdir_fltr *input, err = ice_fdir_write_all_fltr(pf, old_fltr, false); if (err) return err; - ice_fdir_update_cntrs(hw, old_fltr->flow_type, false); + ice_ntuple_update_cntrs(hw, old_fltr->flow_type, false); /* update sb-filters count, specific to ring->channel */ ice_update_per_q_fltr(vsi, old_fltr->orig_q_index, false); if (!input && !hw->fdir_fltr_cnt[old_fltr->flow_type]) @@ -1746,18 +1765,18 @@ ice_fdir_update_list_entry(struct ice_pf *pf, struct ice_fdir_fltr *input, ice_fdir_list_add_fltr(hw, input); /* update sb-filters count, specific to ring->channel */ ice_update_per_q_fltr(vsi, input->orig_q_index, true); - ice_fdir_update_cntrs(hw, input->flow_type, true); + ice_ntuple_update_cntrs(hw, input->flow_type, true); return 0; } /** - * ice_del_fdir_ethtool - delete Flow Director filter + * ice_del_ntuple_ethtool - delete Flow Director or ACL filter * @vsi: pointer to target VSI - * @cmd: command to add or delete Flow Director filter + * @cmd: command to add or delete the filter * - * Returns 0 on success and negative values for failure + * Return: 0 on success and negative values for failure */ -int ice_del_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) +int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) { struct ethtool_rx_flow_spec *fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; @@ -1778,7 +1797,7 @@ int ice_del_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) return -EBUSY; mutex_lock(&hw->fdir_fltr_lock); - val = ice_fdir_update_list_entry(pf, NULL, fsp->location); + val = ice_ntuple_update_list_entry(pf, NULL, fsp->location); mutex_unlock(&hw->fdir_fltr_lock); return val; @@ -1818,14 +1837,16 @@ ice_update_ring_dest_vsi(struct ice_vsi *vsi, u16 *dest_vsi, u32 *ring) } /** - * ice_set_fdir_input_set - Set the input set for Flow Director + * ice_ntuple_set_input_set - Set the input set for Flow Director * @vsi: pointer to target VSI * @fsp: pointer to ethtool Rx flow specification * @input: filter structure + * + * Return: 0 on success, negative on failure */ static int -ice_set_fdir_input_set(struct ice_vsi *vsi, struct ethtool_rx_flow_spec *fsp, - struct ice_fdir_fltr *input) +ice_ntuple_set_input_set(struct ice_vsi *vsi, struct ethtool_rx_flow_spec *fsp, + struct ice_ntuple_fltr *input) { s16 q_index = ICE_FDIR_NO_QUEUE_IDX; u16 orig_q_index = 0; @@ -1968,17 +1989,17 @@ ice_set_fdir_input_set(struct ice_vsi *vsi, struct ethtool_rx_flow_spec *fsp, } /** - * ice_add_fdir_ethtool - Add/Remove Flow Director filter + * ice_add_ntuple_ethtool - Add/Remove Flow Director or ACL filter * @vsi: pointer to target VSI - * @cmd: command to add or delete Flow Director filter + * @cmd: command to add or delete the filter * - * Returns 0 on success and negative values for failure + * Return: 0 on success and negative values for failure */ -int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) +int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) { struct ice_rx_flow_userdef userdata; struct ethtool_rx_flow_spec *fsp; - struct ice_fdir_fltr *input; + struct ice_ntuple_fltr *input; struct device *dev; struct ice_pf *pf; struct ice_hw *hw; @@ -2034,7 +2055,7 @@ int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) if (!input) return -ENOMEM; - ret = ice_set_fdir_input_set(vsi, fsp, input); + ret = ice_ntuple_set_input_set(vsi, fsp, input); if (ret) goto free_input; @@ -2055,7 +2076,7 @@ int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) input->comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW_FAIL; /* input struct is added to the HW filter list */ - ret = ice_fdir_update_list_entry(pf, input, fsp->location); + ret = ice_ntuple_update_list_entry(pf, input, fsp->location); if (ret) goto release_lock; @@ -2066,7 +2087,7 @@ int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) goto release_lock; remove_sw_rule: - ice_fdir_update_cntrs(hw, input->flow_type, false); + ice_ntuple_update_cntrs(hw, input->flow_type, false); /* update sb-filters count, specific to ring->channel */ ice_update_per_q_fltr(vsi, input->orig_q_index, false); list_del(&input->fltr_node); diff --git a/drivers/net/ethernet/intel/ice/ice_fdir.c b/drivers/net/ethernet/intel/ice/ice_fdir.c index b29fbdec9442..1bc91cb41769 100644 --- a/drivers/net/ethernet/intel/ice/ice_fdir.c +++ b/drivers/net/ethernet/intel/ice/ice_fdir.c @@ -648,7 +648,7 @@ ice_set_fd_desc_val(struct ice_fd_fltr_desc_ctx *ctx, * @add: if add is true, this is an add operation, false implies delete */ void -ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input, +ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_ntuple_fltr *input, struct ice_fltr_desc *fdesc, bool add) { struct ice_fd_fltr_desc_ctx fdir_fltr_ctx = { 0 }; @@ -855,7 +855,7 @@ static void ice_pkt_insert_mac_addr(u8 *pkt, u8 *addr) * @tun: true implies generate a tunnel packet */ int -ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input, +ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_ntuple_fltr *input, u8 *pkt, bool frag, bool tun) { enum ice_fltr_ptype flow; @@ -1138,10 +1138,10 @@ bool ice_fdir_has_frag(enum ice_fltr_ptype flow) * * Returns pointer to filter if found or null */ -struct ice_fdir_fltr * +struct ice_ntuple_fltr * ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx) { - struct ice_fdir_fltr *rule; + struct ice_ntuple_fltr *rule; list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) { /* rule ID found in the list */ @@ -1158,9 +1158,9 @@ ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx) * @hw: hardware structure * @fltr: filter node to add to structure */ -void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *fltr) +void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_ntuple_fltr *fltr) { - struct ice_fdir_fltr *rule, *parent = NULL; + struct ice_ntuple_fltr *rule, *parent = NULL; list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) { /* rule ID found or pass its spot in the list */ @@ -1175,26 +1175,6 @@ void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *fltr) list_add(&fltr->fltr_node, &hw->fdir_list_head); } -/** - * ice_fdir_update_cntrs - increment / decrement filter counter - * @hw: pointer to hardware structure - * @flow: filter flow type - * @add: true implies filters added - */ -void -ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add) -{ - int incr; - - incr = add ? 1 : -1; - hw->fdir_active_fltr += incr; - - if (flow == ICE_FLTR_PTYPE_NONF_NONE || flow >= ICE_FLTR_PTYPE_MAX) - ice_debug(hw, ICE_DBG_SW, "Unknown filter type %d\n", flow); - else - hw->fdir_fltr_cnt[flow] += incr; -} - /** * ice_cmp_ipv6_addr - compare 2 IP v6 addresses * @a: IP v6 address @@ -1215,7 +1195,7 @@ static int ice_cmp_ipv6_addr(__be32 *a, __be32 *b) * Returns true if the filters match */ static bool -ice_fdir_comp_rules(struct ice_fdir_fltr *a, struct ice_fdir_fltr *b) +ice_fdir_comp_rules(struct ice_ntuple_fltr *a, struct ice_ntuple_fltr *b) { enum ice_fltr_ptype flow_type = a->flow_type; @@ -1275,9 +1255,9 @@ ice_fdir_comp_rules(struct ice_fdir_fltr *a, struct ice_fdir_fltr *b) * * Returns true if the filter is found in the list */ -bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input) +bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_ntuple_fltr *input) { - struct ice_fdir_fltr *rule; + struct ice_ntuple_fltr *rule; bool ret = false; list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) { diff --git a/drivers/net/ethernet/intel/ice/ice_fdir.h b/drivers/net/ethernet/intel/ice/ice_fdir.h index 820023c0271f..54f51ae31b40 100644 --- a/drivers/net/ethernet/intel/ice/ice_fdir.h +++ b/drivers/net/ethernet/intel/ice/ice_fdir.h @@ -160,7 +160,7 @@ struct ice_fdir_extra { __be16 vlan_tag; /* VLAN tag info */ }; -struct ice_fdir_fltr { +struct ice_ntuple_fltr { struct list_head fltr_node; enum ice_fltr_ptype flow_type; @@ -216,18 +216,16 @@ int ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id); int ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); int ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); void -ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input, +ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_ntuple_fltr *input, struct ice_fltr_desc *fdesc, bool add); int -ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input, +ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_ntuple_fltr *input, u8 *pkt, bool frag, bool tun); int ice_get_fdir_cnt_all(struct ice_hw *hw); int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi); -bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); +bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_ntuple_fltr *input); bool ice_fdir_has_frag(enum ice_fltr_ptype flow); -struct ice_fdir_fltr * +struct ice_ntuple_fltr * ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx); -void -ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add); -void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); +void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_ntuple_fltr *input); #endif /* _ICE_FDIR_H_ */ diff --git a/drivers/net/ethernet/intel/ice/ice_type.h b/drivers/net/ethernet/intel/ice/ice_type.h index cf147a212707..f1a80da6239e 100644 --- a/drivers/net/ethernet/intel/ice/ice_type.h +++ b/drivers/net/ethernet/intel/ice/ice_type.h @@ -1019,8 +1019,8 @@ struct ice_hw { struct mutex fl_profs_locks[ICE_BLK_COUNT]; /* lock fltr profiles */ struct list_head fl_profs[ICE_BLK_COUNT]; - /* Flow Director filter info */ - int fdir_active_fltr; + /* ntuple filter info */ + int ntuple_active_fltr_cnt; struct mutex fdir_fltr_lock; /* protect Flow Director */ struct list_head fdir_list_head; diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c index 4f1f3442e52c..eca9eda04f31 100644 --- a/drivers/net/ethernet/intel/ice/virt/fdir.c +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c @@ -38,7 +38,7 @@ enum ice_fdir_tunnel_type { }; struct virtchnl_fdir_fltr_conf { - struct ice_fdir_fltr input; + struct ice_ntuple_fltr input; enum ice_fdir_tunnel_type ttype; u64 inset_flag; u32 flow_id; @@ -567,12 +567,12 @@ static bool ice_vc_fdir_has_prof_conflict(struct ice_vf *vf, struct virtchnl_fdir_fltr_conf *conf) { - struct ice_fdir_fltr *desc; + struct ice_ntuple_fltr *desc; list_for_each_entry(desc, &vf->fdir.fdir_rule_list, fltr_node) { struct virtchnl_fdir_fltr_conf *existing_conf; enum ice_fltr_ptype flow_type_a, flow_type_b; - struct ice_fdir_fltr *a, *b; + struct ice_ntuple_fltr *a, *b; existing_conf = to_fltr_conf_from_desc(desc); a = &existing_conf->input; @@ -748,7 +748,7 @@ static int ice_vc_fdir_config_input_set(struct ice_vf *vf, struct virtchnl_fdir_add *fltr, struct virtchnl_fdir_fltr_conf *conf, int tun) { - struct ice_fdir_fltr *input = &conf->input; + struct ice_ntuple_fltr *input = &conf->input; struct device *dev = ice_pf_to_dev(vf->pf); struct ice_flow_seg_info *seg; enum ice_fltr_ptype flow; @@ -924,8 +924,8 @@ ice_vc_fdir_parse_pattern(struct ice_vf *vf, struct virtchnl_fdir_add *fltr, struct virtchnl_proto_hdrs *proto = &fltr->rule_cfg.proto_hdrs; enum virtchnl_proto_hdr_type l3 = VIRTCHNL_PROTO_HDR_NONE; enum virtchnl_proto_hdr_type l4 = VIRTCHNL_PROTO_HDR_NONE; + struct ice_ntuple_fltr *input = &conf->input; struct device *dev = ice_pf_to_dev(vf->pf); - struct ice_fdir_fltr *input = &conf->input; int i; if (proto->count > VIRTCHNL_MAX_NUM_PROTO_HDRS) { @@ -1150,8 +1150,8 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr, struct virtchnl_fdir_fltr_conf *conf) { struct virtchnl_filter_action_set *as = &fltr->rule_cfg.action_set; + struct ice_ntuple_fltr *input = &conf->input; struct device *dev = ice_pf_to_dev(vf->pf); - struct ice_fdir_fltr *input = &conf->input; u32 dest_num = 0; u32 mark_num = 0; int i; @@ -1249,8 +1249,8 @@ static bool ice_vc_fdir_comp_rules(struct virtchnl_fdir_fltr_conf *conf_a, struct virtchnl_fdir_fltr_conf *conf_b) { - struct ice_fdir_fltr *a = &conf_a->input; - struct ice_fdir_fltr *b = &conf_b->input; + struct ice_ntuple_fltr *a = &conf_a->input; + struct ice_ntuple_fltr *b = &conf_b->input; if (conf_a->ttype != conf_b->ttype) return false; @@ -1288,7 +1288,7 @@ ice_vc_fdir_comp_rules(struct virtchnl_fdir_fltr_conf *conf_a, static bool ice_vc_fdir_is_dup_fltr(struct ice_vf *vf, struct virtchnl_fdir_fltr_conf *conf) { - struct ice_fdir_fltr *desc; + struct ice_ntuple_fltr *desc; bool ret; list_for_each_entry(desc, &vf->fdir.fdir_rule_list, fltr_node) { @@ -1317,7 +1317,7 @@ static int ice_vc_fdir_insert_entry(struct ice_vf *vf, struct virtchnl_fdir_fltr_conf *conf, u32 *id) { - struct ice_fdir_fltr *input = &conf->input; + struct ice_ntuple_fltr *input = &conf->input; int i; /* alloc ID corresponding with conf */ @@ -1341,7 +1341,7 @@ static void ice_vc_fdir_remove_entry(struct ice_vf *vf, struct virtchnl_fdir_fltr_conf *conf, u32 id) { - struct ice_fdir_fltr *input = &conf->input; + struct ice_ntuple_fltr *input = &conf->input; idr_remove(&vf->fdir.fdir_rule_idr, id); list_del(&input->fltr_node); @@ -1367,7 +1367,7 @@ ice_vc_fdir_lookup_entry(struct ice_vf *vf, u32 id) static void ice_vc_fdir_flush_entry(struct ice_vf *vf) { struct virtchnl_fdir_fltr_conf *conf; - struct ice_fdir_fltr *desc, *temp; + struct ice_ntuple_fltr *desc, *temp; list_for_each_entry_safe(desc, temp, &vf->fdir.fdir_rule_list, fltr_node) { @@ -1390,7 +1390,7 @@ static int ice_vc_fdir_write_fltr(struct ice_vf *vf, struct virtchnl_fdir_fltr_conf *conf, bool add, bool is_tun) { - struct ice_fdir_fltr *input = &conf->input; + struct ice_ntuple_fltr *input = &conf->input; struct ice_vsi *vsi, *ctrl_vsi; struct ice_fltr_desc desc; struct device *dev; @@ -2315,7 +2315,7 @@ int ice_vc_del_fdir_fltr(struct ice_vf *vf, u8 *msg) struct virtchnl_fdir_fltr_conf *conf; struct ice_vf_fdir *fdir = &vf->fdir; enum virtchnl_status_code v_ret; - struct ice_fdir_fltr *input; + struct ice_ntuple_fltr *input; enum ice_fltr_ptype flow; struct device *dev; struct ice_pf *pf; From 9782619d054b2029b5b3d36a3ee14a316e4cd97a Mon Sep 17 00:00:00 2001 From: Marcin Szycik Date: Thu, 2 Jul 2026 12:29:56 +0200 Subject: [PATCH 0578/2126] ice: remove unused ICE_FD_FLUSH_REQ from PF state It's hard to tell what this flag was intended to represent. The commit adding it only added a check that was always false, because the flag is never set. There is no relevant comment and commit message doesn't mention it. Therefore, it looks like it has always been unused. Remove it. Signed-off-by: Marcin Szycik Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice.h | 1 - drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c | 3 --- 2 files changed, 4 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index cb7a73bbcd71..a56e9b7c4dad 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -302,7 +302,6 @@ enum ice_pf_state { ICE_CFG_BUSY, ICE_SERVICE_SCHED, ICE_SERVICE_DIS, - ICE_FD_FLUSH_REQ, ICE_OICR_INTR_DIS, /* Global OICR interrupt disabled */ ICE_MDD_VF_PRINT_PENDING, /* set when MDD event handle */ ICE_VF_RESETS_DISABLED, /* disable resets during ice_remove */ diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c index 744cd0b82470..516b57ff3b1c 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c @@ -1793,9 +1793,6 @@ int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) return -EBUSY; } - if (test_bit(ICE_FD_FLUSH_REQ, pf->state)) - return -EBUSY; - mutex_lock(&hw->fdir_fltr_lock); val = ice_ntuple_update_list_entry(pf, NULL, fsp->location); mutex_unlock(&hw->fdir_fltr_lock); From 8050e0efd4cf6276605bc3cfa60ebd543896fecf Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 19:16:08 -0700 Subject: [PATCH 0579/2126] netlink: specs: netdev: update doc for xsk tx-checksum and zc-max-segs Minor touch ups to the XSK-related doc strings in the netdev spec. Tx checksum is (obviously?) Layer 4 (TCP/UDP), not Layer 3 (IP). The xdp_zc_max_segs change is more subtle, I guess, but to kernel devs saying "frags" may sound like the number of skb frags. The value includes the head in this case. The default of 1 means single buffer, XDP_USE_SG sockets are refused when it is 1. Let's use the word "buffer" instead of "frag". Link: https://patch.msgid.link/20260916021608.1702731-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/netdev.yaml | 5 +++-- include/uapi/linux/netdev.h | 2 +- tools/include/uapi/linux/netdev.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 3e3f03bd5c29..e13461cf3fc3 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -80,7 +80,7 @@ definitions: - name: tx-checksum doc: >- - L3 checksum HW offload is supported by the driver. + L4 checksum HW offload is supported by the driver. - name: tx-launch-time-fifo doc: >- @@ -118,7 +118,8 @@ attribute-sets: enum: xdp-act - name: xdp-zc-max-segs - doc: max fragment count supported by ZC driver + doc: max buffer count per packet supported by ZC driver, + including the head buffer type: u32 checks: min: 1 diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 35ff083221c7..9026e0414fbe 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -58,7 +58,7 @@ enum netdev_xdp_rx_metadata { * enum netdev_xsk_flags * @NETDEV_XSK_FLAGS_TX_TIMESTAMP: HW timestamping egress packets is supported * by the driver. - * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the + * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L4 checksum HW offload is supported by the * driver. * @NETDEV_XSK_FLAGS_TX_LAUNCH_TIME_FIFO: Launch time HW offload is supported * by the driver. diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 35ff083221c7..9026e0414fbe 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -58,7 +58,7 @@ enum netdev_xdp_rx_metadata { * enum netdev_xsk_flags * @NETDEV_XSK_FLAGS_TX_TIMESTAMP: HW timestamping egress packets is supported * by the driver. - * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the + * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L4 checksum HW offload is supported by the * driver. * @NETDEV_XSK_FLAGS_TX_LAUNCH_TIME_FIFO: Launch time HW offload is supported * by the driver. From aea70e81be7fed87892a499ad27fecf99a712d50 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 11:19:53 +0000 Subject: [PATCH 0580/2126] netkit: no longer rely on RTNL in netkit_fill_info() netkit_fill_info() used rtnl_dereference() to fetch nk->peer, and thus required RTNL. nk->peer is already an RCU protected pointer, updated with rcu_assign_pointer() and read from the fast path with rcu_dereference(). Simply use rcu_dereference() under rcu_read_lock() instead. While at it, use READ_ONCE() when reading nk->policy, because netkit_change_link() can change it at any time (it already uses WRITE_ONCE()). Other fields (primary, mode, pair, scrub) are only set from netkit_new_link(), before the device is visible to dumps. Also add missing const qualifiers. Signed-off-by: Eric Dumazet Acked-by: Daniel Borkmann Acked-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260916111953.1611574-1-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/netkit.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index a3931cd82132..82e608e733d9 100644 --- a/drivers/net/netkit.c +++ b/drivers/net/netkit.c @@ -1209,12 +1209,12 @@ static size_t netkit_get_size(const struct net_device *dev) static int netkit_fill_info(struct sk_buff *skb, const struct net_device *dev) { - struct netkit *nk = netkit_priv(dev); - struct net_device *peer = rtnl_dereference(nk->peer); + const struct netkit *nk = netkit_priv(dev); + const struct net_device *peer; if (nla_put_u8(skb, IFLA_NETKIT_PRIMARY, nk->primary)) return -EMSGSIZE; - if (nla_put_u32(skb, IFLA_NETKIT_POLICY, nk->policy)) + if (nla_put_u32(skb, IFLA_NETKIT_POLICY, READ_ONCE(nk->policy))) return -EMSGSIZE; if (nla_put_u32(skb, IFLA_NETKIT_MODE, nk->mode)) return -EMSGSIZE; @@ -1228,13 +1228,18 @@ static int netkit_fill_info(struct sk_buff *skb, const struct net_device *dev) if (nla_put_u32(skb, IFLA_NETKIT_PAIRING, nk->pair)) return -EMSGSIZE; + rcu_read_lock(); + peer = rcu_dereference(nk->peer); if (peer) { nk = netkit_priv(peer); - if (nla_put_u32(skb, IFLA_NETKIT_PEER_POLICY, nk->policy)) - return -EMSGSIZE; - if (nla_put_u32(skb, IFLA_NETKIT_PEER_SCRUB, nk->scrub)) + if (nla_put_u32(skb, IFLA_NETKIT_PEER_POLICY, + READ_ONCE(nk->policy)) || + nla_put_u32(skb, IFLA_NETKIT_PEER_SCRUB, nk->scrub)) { + rcu_read_unlock(); return -EMSGSIZE; + } } + rcu_read_unlock(); return 0; } From 5117ce8c35d1645e9839bc892b5944556faddb1c Mon Sep 17 00:00:00 2001 From: Donggeun Yoo Date: Wed, 16 Sep 2026 07:31:37 +0900 Subject: [PATCH 0581/2126] net: phy: qca808x: accept the active-high LED polarity mode commit a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs") added PHY_LED_ACTIVE_HIGH, but qca808x_led_polarity_set() still rejects everything except PHY_LED_ACTIVE_LOW. An LED node carrying 'active-high' therefore falls into the default case and returns -EINVAL, which phy_probe() propagates: the mdio device is left unbound and phy_attach_direct() falls back to the genphy driver, so the PHY loses every qca808x-specific feature, not just the LED. Accept the mode. The register write below already handles both polarities. Cc: stable+noautosel@kernel.org # never worked Signed-off-by: Donggeun Yoo Reviewed-by: Christian Marangi Link: https://patch.msgid.link/20260915223138.321307-2-donggeunyoo.kernel@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/qcom/qca808x.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/phy/qcom/qca808x.c b/drivers/net/phy/qcom/qca808x.c index 8eb51b1a006c..3ba58f14e248 100644 --- a/drivers/net/phy/qcom/qca808x.c +++ b/drivers/net/phy/qcom/qca808x.c @@ -603,6 +603,9 @@ static int qca808x_led_polarity_set(struct phy_device *phydev, int index, case PHY_LED_ACTIVE_LOW: active_low = true; break; + case PHY_LED_ACTIVE_HIGH: + active_low = false; + break; default: return -EINVAL; } From f1b4766d67bb2d496eb74b0ecfe0dc55a9ab03e0 Mon Sep 17 00:00:00 2001 From: Donggeun Yoo Date: Wed, 16 Sep 2026 07:31:38 +0900 Subject: [PATCH 0582/2126] net: phy: qca808x: keep an explicit active-high LED across the reset With the previous patch an 'active-high' LED node is accepted, so led_polarity_mode can now hold 0. qca808x_config_init() only re-asserts QCA808X_LED_ACTIVE_HIGH when the mode is -1, the value that means device tree asked for nothing, so an explicit active-high does not reach the register. That matters because the bit does not survive a reset. phy_init_hw() runs .soft_reset before .config_init on every attach and resume, and commit f203c8c77c76 ("net: phy: qcom: qca808x: default to LED active High if not set") records why: "on PHY reset, the Active High bit is not set resulting in the LED driven as active-low". The polarity written from device tree during phy_probe() is therefore gone by the time the link comes up, and the LED runs inverted. Re-assert the bit for anything other than an explicit active-low, which is the one case that wants it clear and gets that from the reset for free. Name the unset value while here: led_polarity_mode otherwise holds a PHY_LED_ACTIVE_* value, so spelling the comparison PHY_LED_ACTIVE_LOW says what it means where -1, 0 and 1 did not. Cc: stable+noautosel@kernel.org # never worked Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260908105959.70453-1-donggeunyoo.kernel%40gmail.com Signed-off-by: Donggeun Yoo Reviewed-by: Christian Marangi Link: https://patch.msgid.link/20260915223138.321307-3-donggeunyoo.kernel@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/qcom/qca808x.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/qcom/qca808x.c b/drivers/net/phy/qcom/qca808x.c index 3ba58f14e248..bab26e4c6140 100644 --- a/drivers/net/phy/qcom/qca808x.c +++ b/drivers/net/phy/qcom/qca808x.c @@ -87,6 +87,9 @@ #define QCA8081_PHY_ID 0x004dd101 +/* led_polarity_mode otherwise holds a PHY_LED_ACTIVE_* value */ +#define QCA808X_PHY_LED_UNSET -1 + MODULE_DESCRIPTION("Qualcomm Atheros QCA808X PHY driver"); MODULE_AUTHOR("Matus Ujhelyi"); MODULE_LICENSE("GPL"); @@ -187,8 +190,7 @@ static int qca808x_probe(struct phy_device *phydev) if (!priv) return -ENOMEM; - /* Init LED polarity mode to -1 */ - priv->led_polarity_mode = -1; + priv->led_polarity_mode = QCA808X_PHY_LED_UNSET; phydev->priv = priv; @@ -200,8 +202,8 @@ static int qca808x_config_init(struct phy_device *phydev) struct qca808x_priv *priv = phydev->priv; int ret; - /* Default to LED Active High if active-low not in DT */ - if (priv->led_polarity_mode == -1) { + /* Set LED Active High unless active-low was requested in DT */ + if (priv->led_polarity_mode != PHY_LED_ACTIVE_LOW) { ret = phy_set_bits_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_LED_POLARITY_CTRL, QCA808X_LED_ACTIVE_HIGH); @@ -615,7 +617,7 @@ static int qca808x_led_polarity_set(struct phy_device *phydev, int index, * To detect this, check if last requested polarity mode * match the new one. */ - if (priv->led_polarity_mode >= 0 && + if (priv->led_polarity_mode != QCA808X_PHY_LED_UNSET && priv->led_polarity_mode != active_low) { phydev_err(phydev, "PHY polarity is global. Mismatched polarity on different LED\n"); return -EINVAL; From 0fa13b71c3303cc5fbb75ae215ccf2dec7efe19a Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 19:15:15 -0700 Subject: [PATCH 0583/2126] netlink: specs: nlctrl: fix the policy attribute numbering mask and pad are declared the wrong way round, giving mask 11 and pad 12, while enum netlink_policy_type_attr has NL_POLICY_TYPE_ATTR_PAD at 11 and NL_POLICY_TYPE_ATTR_MASK at 12. The kernel emits the mask for every NLA_POLICY_MASK() attribute, so a Python YNL client parsing a policy dump maps it onto pad and throws it away - 30 of them in ethtool's policy alone. In the other direction the 64-bit alignment padding, which the kernel does emit on architectures without efficient unaligned access, is decoded as a u64 mask and blows up the whole dump. But those architectures are rare. The generated C parser is not affected, it keys the attributes off the uAPI symbol names rather than off the values the spec derives. Reviewed-by: Donald Hunter Link: https://patch.msgid.link/20260916021516.1701760-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/nlctrl.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/specs/nlctrl.yaml b/Documentation/netlink/specs/nlctrl.yaml index 7e7c158e3e73..6acac4aeab03 100644 --- a/Documentation/netlink/specs/nlctrl.yaml +++ b/Documentation/netlink/specs/nlctrl.yaml @@ -156,12 +156,12 @@ attribute-sets: - name: bitfield32-mask type: u32 - - - name: mask - type: u64 - name: pad type: pad + - + name: mask + type: u64 - name: byte-order doc: Byte order of the attribute, absent means host byte order. From 7c6a3f0a8433c850200bc2b706a581b4d0e2c540 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 19:15:16 -0700 Subject: [PATCH 0584/2126] netlink: specs: nlctrl: let getfamily take a family id ctrl_policy_family[] accepts CTRL_ATTR_FAMILY_ID and ctrl_getfamily() looks the family up by it, but the spec lists only family-name in the request. C YNL generates struct members and setters from that list, so struct nlctrl_getfamily_req has no way to carry an id and resolving a family id - the one a client gets handed in nlmsg_type - back to a name needs a full dump. Python YNL happens to encode any attribute of the op's attribute set, which is why this went unnoticed. Reviewed-by: Donald Hunter Link: https://patch.msgid.link/20260916021516.1701760-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/nlctrl.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/netlink/specs/nlctrl.yaml b/Documentation/netlink/specs/nlctrl.yaml index 6acac4aeab03..a400365cdbeb 100644 --- a/Documentation/netlink/specs/nlctrl.yaml +++ b/Documentation/netlink/specs/nlctrl.yaml @@ -191,6 +191,7 @@ operations: request: value: 3 attributes: + - family-id - family-name reply: &all-attrs value: 1 From 5e591692375918ecc3fde9832760ef0a1003275e Mon Sep 17 00:00:00 2001 From: Sagar Taunk Date: Tue, 15 Sep 2026 14:42:44 +0000 Subject: [PATCH 0585/2126] rust: net: netlink: Migrate to zerocopy's IntoBytes Replace the kernel's own `transmute::FromBytes` and `AsBytes` traits with their zerocopy equivalents. Specifically, this updates `GenlMsg::put` to rely on `IntoBytes` for converting attributes into byte slices. Also, add `Immutable` trait bound on `GenlMsg::put` as zerocopy splits the `no interior mutability` guarantee that `AsBytes` bundled together. Link: https://github.com/Rust-for-Linux/linux/issues/1241 Signed-off-by: Sagar Taunk Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl Link: https://patch.msgid.link/20260915144231.31932-1-sagartaunk@proton.me Signed-off-by: Jakub Kicinski --- rust/kernel/net/netlink.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs index 22ef3dde36fa..a2f4bd171dcf 100644 --- a/rust/kernel/net/netlink.rs +++ b/rust/kernel/net/netlink.rs @@ -12,7 +12,6 @@ use kernel::{ alloc::{self, AllocError}, error::to_result, prelude::*, - transmute::AsBytes, types::Opaque, ThisModule, }; @@ -22,6 +21,11 @@ use core::{ ptr::NonNull, // }; +use zerocopy::{ + Immutable, + IntoBytes, // +}; + /// The default netlink message size. pub const GENLMSG_DEFAULT_SIZE: usize = bindings::GENLMSG_DEFAULT_SIZE; @@ -84,7 +88,7 @@ impl GenlMsg { #[inline] fn put(&mut self, attrtype: c_int, value: &T) -> Result where - T: ?Sized + AsBytes, + T: ?Sized + IntoBytes + Immutable, { let skb = self.skb.skb.as_ptr(); let len = size_of_val(value); From 49969c37035bb6c22cd9d0b32a4e2bfa4b2c86fc Mon Sep 17 00:00:00 2001 From: Manuel Ebner Date: Wed, 16 Sep 2026 14:34:58 +0200 Subject: [PATCH 0586/2126] docs: networking: radiotap: Fix bracket Remove needless ')' from code. Signed-off-by: Manuel Ebner Acked-by: Randy Dunlap Link: https://patch.msgid.link/20260916123458.314458-8-manuelebnerli@mailbox.org Signed-off-by: Jakub Kicinski --- Documentation/networking/radiotap-headers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/radiotap-headers.rst b/Documentation/networking/radiotap-headers.rst index 1a1bd1ec0650..aadc7bc6b43b 100644 --- a/Documentation/networking/radiotap-headers.rst +++ b/Documentation/networking/radiotap-headers.rst @@ -133,7 +133,7 @@ its prototypes available in include/net/cfg80211.h. You use it like this:: case IEEE80211_RADIOTAP_ANTENNA: /* radiotap uses 0 for 1st ant */ - antenna = *iterator.this_arg); + antenna = *iterator.this_arg; break; case IEEE80211_RADIOTAP_DBM_TX_POWER: From 35a4b983c5112ab4ab1941b61104d789419a6b0d Mon Sep 17 00:00:00 2001 From: Manuel Ebner Date: Wed, 16 Sep 2026 14:34:55 +0200 Subject: [PATCH 0587/2126] docs: ethtool: Fix bracket Add missing ')' to sentence. Signed-off-by: Manuel Ebner Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260916123458.314458-5-manuelebnerli@mailbox.org Signed-off-by: Jakub Kicinski --- Documentation/networking/ethtool-netlink.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index e92abf45faf5..393f2b6d3863 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -131,7 +131,7 @@ For compact form, ``ETHTOOL_A_BITSET_SIZE`` and ``ETHTOOL_A_BITSET_VALUE`` are mandatory. ``ETHTOOL_A_BITSET_MASK`` attribute is mandatory if ``ETHTOOL_A_BITSET_NOMASK`` is not set (bitset represents a value/mask pair); if ``ETHTOOL_A_BITSET_NOMASK`` is not set, ``ETHTOOL_A_BITSET_MASK`` is not -allowed (bitset represents a single bitmap. +allowed (bitset represents a single bitmap). Kernel bit set length may differ from userspace length if older application is used on newer kernel or vice versa. If userspace bitmap is longer, an error is From a0afc297a048cc5c59fcb412bba38bd9a809eacd Mon Sep 17 00:00:00 2001 From: Manuel Ebner Date: Wed, 16 Sep 2026 14:34:52 +0200 Subject: [PATCH 0588/2126] Documentation: net: dsa: Fix bracket Add missing ')'. Signed-off-by: Manuel Ebner Acked-by: Randy Dunlap Link: https://patch.msgid.link/20260916123458.314458-2-manuelebnerli@mailbox.org Signed-off-by: Jakub Kicinski --- Documentation/networking/dsa/dsa.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/dsa/dsa.rst b/Documentation/networking/dsa/dsa.rst index 42a99f5dfa2e..7edfdd555f05 100644 --- a/Documentation/networking/dsa/dsa.rst +++ b/Documentation/networking/dsa/dsa.rst @@ -864,7 +864,7 @@ The drivers which act upon the ``dsa_db`` argument in ``port_fdb_add``, DSA associates each offloaded bridge and each offloaded LAG with a one-based ID (``struct dsa_bridge :: num``, ``struct dsa_lag :: id``) for the purposes of refcounting addresses on shared ports. Drivers may piggyback on DSA's numbering -scheme (the ID is readable through ``db->bridge.num`` and ``db->lag.id`` or may +scheme (the ID is readable through ``db->bridge.num`` and ``db->lag.id``) or may implement their own. Only the drivers which declare support for FDB isolation are notified of FDB From 8181678a92f0143ad3dafcc2e811afa44ecb4fd6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Mon, 14 Sep 2026 17:26:44 +0200 Subject: [PATCH 0589/2126] net: stmmac: propagate PTP init failures in __stmmac_open() and stmmac_resume() stmmac_setup_ptp() returns void and swallows both PTP setup errors: the PTP reference clock enable and stmmac_init_timestamping() failures are logged but never propagated. When they fail, the MAC system time counter is left in its post-reset, non-running state, while the driver keeps operating as if timestamping were up. This matters for TAPRIO/EST qdisc offloading, which derives the EST base time from the hardware timestamp counter: arming the gate list against a non-advancing time base would leave the schedule permanently stuck. Make stmmac_setup_ptp() return an error code and propagate the failure in __stmmac_open(), stopping the DMA engines when PTP setup fails. In stmmac_resume(), re-initialise timestamping only when the PTP clock was registered before suspend, re-apply the platform clock rate configuration, and stop the DMA engines if re-initialisation fails. While at it, factor the hardware timestamping capability check into a stmmac_check_timestamp_cap() helper and apply it to the hwtstamp get path and the ethtool ts_info path. stmmac_setup_ptp() now enables the PTP reference clock and runs the platform ptp_clk_freq_config() callback before validating the resulting clock rate; if no valid rate is available, it disables the clock and returns success without registering the PTP clock. This keeps the interface operational on platforms with PTP-capable silicon but an unconfigured PTP clock, where timestamping cannot be enabled: instead of failing, the driver proceeds without setting up timestamping. Extend the timestamping gate on the set path (which keeps testing the core's basic/advanced timestamping capability) and the devlink registration with the PTP reference clock rate requirement. Gate the PTP reference clock enable/disable in the platform noirq suspend/resume callbacks on priv->ptp_enabled, keeping the clock reference balanced against the new early return in stmmac_release_ptp(). Reviewed-by: Maxime Chevallier Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260914-stmmac-ptp-error-propagate-v5-1-81149897e65d@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 7 ++ .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 3 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 114 +++++++++++++----- .../ethernet/stmicro/stmmac/stmmac_platform.c | 6 +- 4 files changed, 95 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 7582fca63741..4fc96b317d79 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -329,6 +329,8 @@ struct stmmac_priv { struct kernel_hwtstamp_config tstamp_config; struct ptp_clock *ptp_clock; struct ptp_clock_info ptp_clock_ops; + bool ptp_enabled; + unsigned int default_addend; u32 sub_second_inc; u32 systime_flags; @@ -419,6 +421,11 @@ int stmmac_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i, struct plat_stmmacenet_data *stmmac_plat_dat_alloc(struct device *dev); +static inline bool stmmac_check_timestamp_cap(struct stmmac_priv *priv) +{ + return priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp; +} + static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv) { return !!priv->xdp_prog; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 1be5310ca766..1cf0f8820b33 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -1007,8 +1007,7 @@ static int stmmac_get_ts_info(struct net_device *dev, { struct stmmac_priv *priv = netdev_priv(dev); - if ((priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) { - + if (stmmac_check_timestamp_cap(priv)) { info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE | diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index bc2b1cbe7792..bf9e7e4cb1c3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -653,7 +653,8 @@ static int stmmac_hwtstamp_set(struct net_device *dev, u32 ts_master_en = 0; u32 ts_event_en = 0; - if (!(priv->dma_cap.time_stamp || priv->adv_ts)) { + if (!priv->plat->clk_ptp_rate || + !(priv->dma_cap.time_stamp || priv->adv_ts)) { NL_SET_ERR_MSG_MOD(extack, "No support for HW time stamping"); priv->hwts_tx_en = 0; priv->hwts_rx_en = 0; @@ -843,7 +844,7 @@ static int stmmac_hwtstamp_get(struct net_device *dev, { struct stmmac_priv *priv = netdev_priv(dev); - if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) + if (!stmmac_check_timestamp_cap(priv)) return -EOPNOTSUPP; *config = priv->tstamp_config; @@ -866,11 +867,6 @@ static int stmmac_init_tstamp_counter(struct stmmac_priv *priv, { struct timespec64 now; - if (!priv->plat->clk_ptp_rate) { - netdev_err(priv->dev, "Invalid PTP clock rate"); - return -EINVAL; - } - stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); priv->systime_flags = systime_flags; @@ -885,26 +881,37 @@ static int stmmac_init_tstamp_counter(struct stmmac_priv *priv, return 0; } +static int stmmac_init_ptp_clk_freq(struct stmmac_priv *priv) +{ + if (priv->plat->ptp_clk_freq_config) + priv->plat->ptp_clk_freq_config(priv); + + if (!priv->plat->clk_ptp_rate) { + netdev_info(priv->dev, "PTP clock rate not configured\n"); + return -EINVAL; + } + + return 0; +} + /** * stmmac_init_timestamping - initialise timestamping * @priv: driver private structure - * Description: this is to verify if the HW supports the PTPv1 or PTPv2. - * This is done by looking at the HW cap. register. - * This function also registers the ptp driver. + * + * Description: initialise the hardware timestamping counter, reset the + * timestamping configuration and derive the advanced timestamping flags from + * the HW capabilities. The caller must have ensured a valid PTP reference + * clock rate (see stmmac_init_ptp_clk_freq()); the configured state is valid + * as long as the interface is open and not suspended, and this function is + * re-run on resume. + * + * Return: 0 on success, a negative errno otherwise. */ static int stmmac_init_timestamping(struct stmmac_priv *priv) { bool xmac = dwmac_is_xmac(priv->plat->core_type); int ret; - if (priv->plat->ptp_clk_freq_config) - priv->plat->ptp_clk_freq_config(priv); - - if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) { - netdev_info(priv->dev, "PTP not supported by HW\n"); - return -EOPNOTSUPP; - } - ret = stmmac_init_tstamp_counter(priv, STMMAC_HWTS_ACTIVE | PTP_TCR_TSCFUPDT); if (ret) { @@ -937,24 +944,48 @@ static int stmmac_init_timestamping(struct stmmac_priv *priv) return 0; } -static void stmmac_setup_ptp(struct stmmac_priv *priv) +static int stmmac_setup_ptp(struct stmmac_priv *priv) { int ret; + if (!stmmac_check_timestamp_cap(priv)) { + netdev_info(priv->dev, "PTP not supported\n"); + return 0; + } + ret = clk_prepare_enable(priv->plat->clk_ptp_ref); - if (ret < 0) + if (ret < 0) { netdev_warn(priv->dev, "failed to enable PTP reference clock: %pe\n", ERR_PTR(ret)); + return ret; + } - if (stmmac_init_timestamping(priv) == 0) - stmmac_ptp_register(priv); + if (stmmac_init_ptp_clk_freq(priv)) { + clk_disable_unprepare(priv->plat->clk_ptp_ref); + return 0; + } + + ret = stmmac_init_timestamping(priv); + if (ret) { + clk_disable_unprepare(priv->plat->clk_ptp_ref); + return ret; + } + + stmmac_ptp_register(priv); + priv->ptp_enabled = true; + + return 0; } static void stmmac_release_ptp(struct stmmac_priv *priv) { + if (!priv->ptp_enabled) + return; + stmmac_ptp_unregister(priv); clk_disable_unprepare(priv->plat->clk_ptp_ref); + priv->ptp_enabled = false; } static void stmmac_legacy_serdes_power_down(struct stmmac_priv *priv) @@ -4161,10 +4192,12 @@ static int __stmmac_open(struct net_device *dev, ret = stmmac_hw_setup(dev); if (ret < 0) { netdev_err(priv->dev, "%s: Hw setup failed\n", __func__); - goto init_error; + return ret; } - stmmac_setup_ptp(priv); + ret = stmmac_setup_ptp(priv); + if (ret) + goto ptp_error; stmmac_init_coalesce(priv); @@ -4191,7 +4224,10 @@ irq_error: hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer); stmmac_release_ptp(priv); -init_error: +ptp_error: + stmmac_stop_all_dma(priv); + stmmac_mac_set(priv, priv->ioaddr, false); + return ret; } @@ -7764,8 +7800,7 @@ static int stmmac_register_devlink(struct stmmac_priv *priv) /* For now, what is exposed over devlink is only relevant when * timestamping is available and we have a valid ptp clock rate */ - if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp) || - !priv->plat->clk_ptp_rate) + if (!stmmac_check_timestamp_cap(priv) || !priv->plat->clk_ptp_rate) return 0; priv->devlink = devlink_alloc(&stmmac_devlink_ops, sizeof(*dl_priv), @@ -8370,14 +8405,19 @@ int stmmac_resume(struct device *dev) ret = stmmac_hw_setup(ndev); if (ret < 0) { netdev_err(priv->dev, "%s: Hw setup failed\n", __func__); - stmmac_legacy_serdes_power_down(priv); - mutex_unlock(&priv->lock); - rtnl_unlock(); - return ret; + goto error_unlock; } - stmmac_init_timestamping(priv); + if (priv->ptp_enabled) { + if (stmmac_init_ptp_clk_freq(priv)) + goto init_coalesce; + ret = stmmac_init_timestamping(priv); + if (ret) + goto error_stop_dma; + } + +init_coalesce: stmmac_init_coalesce(priv); phylink_rx_clk_stop_block(priv->phylink); stmmac_set_rx_mode(ndev); @@ -8400,6 +8440,16 @@ int stmmac_resume(struct device *dev) netif_device_attach(ndev); return 0; + +error_stop_dma: + stmmac_stop_all_dma(priv); + stmmac_mac_set(priv, priv->ioaddr, false); +error_unlock: + stmmac_legacy_serdes_power_down(priv); + mutex_unlock(&priv->lock); + rtnl_unlock(); + + return ret; } EXPORT_SYMBOL_GPL(stmmac_resume); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 93b9af203a18..3ea16d618215 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -970,7 +970,8 @@ static int __maybe_unused stmmac_pltfr_noirq_suspend(struct device *dev) if (!priv->wolopts) { /* Disable clock in case of PWM is off */ - clk_disable_unprepare(priv->plat->clk_ptp_ref); + if (priv->ptp_enabled) + clk_disable_unprepare(priv->plat->clk_ptp_ref); ret = pm_runtime_force_suspend(dev); if (ret) @@ -995,6 +996,9 @@ static int __maybe_unused stmmac_pltfr_noirq_resume(struct device *dev) if (ret) return ret; + if (!priv->ptp_enabled) + return 0; + ret = clk_prepare_enable(priv->plat->clk_ptp_ref); if (ret < 0) { netdev_warn(priv->dev, From 6c53effab88df871c5196b4f026cdac6943283e2 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:33 -0700 Subject: [PATCH 0590/2126] devlink: fix the enum behind DEVLINK_ATTR_RELOAD_LIMITS DEVLINK_ATTR_RELOAD_LIMITS carries enum devlink_reload_limit, the spec says enum devlink_reload_action. The two are unrelated, and have a different set of values (bits 1, 2 vs bits 0, 1). AFAICT this is a cosmetic change - both DEVLINK_RELOAD_LIMIT_UNSPEC and the out of bounds bit 2 will be rejected either way because drivers don't declare them as supported. User will see either a policy validation failure or "Requested limit is not supported by the driver". While at it annotate the right enum for reload-stats-limit Link: https://patch.msgid.link/20260915161341.1053476-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 15 ++++++++++++++- net/devlink/netlink_gen.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 38b1190f3d26..d933b205ee86 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -174,6 +174,18 @@ definitions: value: 1 - name: fw-activate + - + type: enum + name: reload-limit + entries: + - + name: unspec + doc: no constraints + - + name: no-reset + doc: >- + No reset allowed, no down time allowed, no link flap and no + configuration is lost. - type: enum name: param-cmode @@ -775,7 +787,7 @@ attribute-sets: - name: reload-limits type: bitfield32 - enum: reload-action + enum: reload-limit enum-as-flags: true - name: dev-stats @@ -793,6 +805,7 @@ attribute-sets: - name: reload-stats-limit type: u8 + enum: reload-limit - name: reload-stats-value type: u32 diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c index dec00133178d..30f01901b587 100644 --- a/net/devlink/netlink_gen.c +++ b/net/devlink/netlink_gen.c @@ -334,7 +334,7 @@ static const struct nla_policy devlink_reload_nl_policy[DEVLINK_ATTR_INDEX + 1] [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), [DEVLINK_ATTR_RELOAD_ACTION] = NLA_POLICY_RANGE(NLA_U8, 1, 2), - [DEVLINK_ATTR_RELOAD_LIMITS] = NLA_POLICY_BITFIELD32(6), + [DEVLINK_ATTR_RELOAD_LIMITS] = NLA_POLICY_BITFIELD32(3), [DEVLINK_ATTR_NETNS_PID] = { .type = NLA_U32, }, [DEVLINK_ATTR_NETNS_FD] = { .type = NLA_U32, }, [DEVLINK_ATTR_NETNS_ID] = { .type = NLA_U32, }, From b8ffb7e5b9a1b1ff27b2529b41573d0960df2968 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:34 -0700 Subject: [PATCH 0591/2126] netlink: specs: devlink: drop the stale port dump reply value The bug the comment describes was fixed by commit 61c43780e944 ("devlink: fix port dump cmd type") two years ago. devlink_nl_port_get_dump_one() fills DEVLINK_CMD_PORT_NEW (7), not DEVLINK_CMD_NEW (3) now. Note that this change is likely a noop. _dictify_ops_directional() picks the "do" section's value when an op has both "do" and "dump". Link: https://patch.msgid.link/20260915161341.1053476-3-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index d933b205ee86..0e0791d4e2c7 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -1401,7 +1401,6 @@ operations: request: attributes: *dev-id-attrs reply: - value: 3 # due to a bug, port dump returns DEVLINK_CMD_NEW attributes: *port-id-attrs - From 6338e31e68551268fa65b5fb1f67eecb3b7a8e3c Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:35 -0700 Subject: [PATCH 0592/2126] netlink: specs: devlink: describe DEVLINK_ATTR_NESTED_DEVLINK The "# TODO: fill in the attributes in between" gap before selftests (176) hides exactly one attribute, DEVLINK_ATTR_NESTED_DEVLINK (175). devlink_nl_fill() calls devlink_nl_nested_fill() unconditionally, which emits one of these per entry in devlink->nested_rels (mlx5, ice). Unlike the other TODO gaps this is a single attribute of an already modelled type, so just fill it in. Link: https://patch.msgid.link/20260915161341.1053476-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 0e0791d4e2c7..7ec52f81c323 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -858,13 +858,14 @@ attribute-sets: name: linecard-supported-types type: nest nested-attributes: dl-linecard-supported-types - - # TODO: fill in the attributes in between - + - + name: nested-devlink + type: nest + multi-attr: true + nested-attributes: dl-nested-devlink - name: selftests type: nest - value: 176 nested-attributes: dl-selftest-id - name: rate-tx-priority @@ -1351,6 +1352,19 @@ attribute-sets: - name: index + - + name: dl-nested-devlink + subset-of: devlink + attributes: + - + name: bus-name + - + name: dev-name + - + name: index + - + name: netns-id + operations: enum-model: directional list: @@ -1376,6 +1390,7 @@ operations: - index - reload-failed - dev-stats + - nested-devlink dump: reply: *get-reply From 4ced66fc97bf7f979f76256ee04a180f65261b7e Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:36 -0700 Subject: [PATCH 0593/2126] netlink: specs: devlink: complete the port function nest dl-port-function stops at caps, but the nest also carries DEVLINK_PORT_FN_ATTR_DEVLINK (5) and DEVLINK_PORT_FN_ATTR_MAX_IO_EQS (6) both put by devlink_nl_port_function_attrs_put() on every port-get do and dump. YNL raises Space 'dl-port-function' has no attribute with value '6' for any port reporting max_io_eqs or a nested devlink handle, i.e. for mlx5 SFs and VFs. Commit 5af3e3876d56 ("devlink: Support setting max_io_eqs") added the uAPI value and the hand written policy but never touched the spec. Add the missing attributes, subsequent commit reworks the code to use the YNL-generated policy. Link: https://patch.msgid.link/20260915161341.1053476-5-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 8 ++++++++ net/devlink/netlink_gen.c | 11 ++++++++++- net/devlink/netlink_gen.h | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 7ec52f81c323..962789dfbfac 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -992,6 +992,14 @@ attribute-sets: type: bitfield32 enum: port-fn-attr-cap enum-as-flags: true + - + name: devlink + type: nest + nested-attributes: dl-nested-devlink + doc: Handle of the peer devlink instance instantiated for this function. + - + name: max-io-eqs + type: u32 - name: dl-dpipe-tables diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c index 30f01901b587..17d1edcdb935 100644 --- a/net/devlink/netlink_gen.c +++ b/net/devlink/netlink_gen.c @@ -46,17 +46,26 @@ devlink_attr_param_type_validate(const struct nlattr *attr, } /* Common nested types */ +const struct nla_policy devlink_dl_nested_devlink_nl_policy[DEVLINK_ATTR_INDEX + 1] = { + [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), + [DEVLINK_ATTR_NETNS_ID] = { .type = NLA_U32, }, +}; + const struct nla_policy devlink_dl_parent_dev_nl_policy[DEVLINK_ATTR_INDEX + 1] = { [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), }; -const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_CAPS + 1] = { +const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS + 1] = { [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] = { .type = NLA_BINARY, }, [DEVLINK_PORT_FN_ATTR_STATE] = NLA_POLICY_MAX(NLA_U8, 1), [DEVLINK_PORT_FN_ATTR_OPSTATE] = NLA_POLICY_MAX(NLA_U8, 1), [DEVLINK_PORT_FN_ATTR_CAPS] = NLA_POLICY_BITFIELD32(15), + [DEVLINK_PORT_FN_ATTR_DEVLINK] = NLA_POLICY_NESTED(devlink_dl_nested_devlink_nl_policy), + [DEVLINK_PORT_FN_ATTR_MAX_IO_EQS] = { .type = NLA_U32, }, }; const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_ATTR_BW + 1] = { diff --git a/net/devlink/netlink_gen.h b/net/devlink/netlink_gen.h index a70e0e4769aa..75572a9a23f6 100644 --- a/net/devlink/netlink_gen.h +++ b/net/devlink/netlink_gen.h @@ -13,8 +13,9 @@ #include /* Common nested types */ +extern const struct nla_policy devlink_dl_nested_devlink_nl_policy[DEVLINK_ATTR_INDEX + 1]; extern const struct nla_policy devlink_dl_parent_dev_nl_policy[DEVLINK_ATTR_INDEX + 1]; -extern const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_CAPS + 1]; +extern const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS + 1]; extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_ATTR_BW + 1]; extern const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_ATTR_SELFTEST_ID_FLASH + 1]; From 3ec610a6bb12bcd6f93e8c3eaf14ccbe68558bd4 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:37 -0700 Subject: [PATCH 0594/2126] devlink: generate the port function policy from the spec devlink has a one huge root attribute set for the whole family, we haven't taken the time to properly define the sub-sets for each command. Do it for port-set so that we can drop the hand written policy used by devlink_port_function_set(). We need this subsetting because within the DEVLINK_ATTR_PORT_FUNCTION nest DEVLINK_PORT_FN_ATTR_OPSTATE and DEVLINK_PORT_FN_ATTR_DEVLINK are output-only so we have to filter them out of the input set. Link: https://patch.msgid.link/20260915161341.1053476-6-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 37 +++++++++++++++++++++++- net/devlink/netlink_gen.c | 13 ++------- net/devlink/netlink_gen.h | 3 +- net/devlink/port.c | 19 ++---------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 962789dfbfac..f23466fb27f9 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -1001,6 +1001,41 @@ attribute-sets: name: max-io-eqs type: u32 + - + name: dl-port-function-set + subset-of: dl-port-function + doc: | + Port function attributes that can be configured; opstate and the + devlink handle are read-only. + attributes: + - + name: hw-addr + - + name: state + - + name: caps + - + name: max-io-eqs + + - + name: dl-port-set + subset-of: devlink + doc: Attributes accepted by the port-set request. + attributes: + - + name: bus-name + - + name: dev-name + - + name: index + - + name: port-index + - + name: port-type + - + name: port-function + nested-attributes: dl-port-function-set + - name: dl-dpipe-tables subset-of: devlink @@ -1429,7 +1464,7 @@ operations: - name: port-set doc: Set devlink port instances. - attribute-set: devlink + attribute-set: dl-port-set dont-validate: [strict] flags: [admin-perm] do: diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c index 17d1edcdb935..43ef6864d462 100644 --- a/net/devlink/netlink_gen.c +++ b/net/devlink/netlink_gen.c @@ -46,25 +46,16 @@ devlink_attr_param_type_validate(const struct nlattr *attr, } /* Common nested types */ -const struct nla_policy devlink_dl_nested_devlink_nl_policy[DEVLINK_ATTR_INDEX + 1] = { - [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, }, - [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, - [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), - [DEVLINK_ATTR_NETNS_ID] = { .type = NLA_U32, }, -}; - const struct nla_policy devlink_dl_parent_dev_nl_policy[DEVLINK_ATTR_INDEX + 1] = { [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), }; -const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS + 1] = { +const struct nla_policy devlink_dl_port_function_set_nl_policy[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS + 1] = { [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] = { .type = NLA_BINARY, }, [DEVLINK_PORT_FN_ATTR_STATE] = NLA_POLICY_MAX(NLA_U8, 1), - [DEVLINK_PORT_FN_ATTR_OPSTATE] = NLA_POLICY_MAX(NLA_U8, 1), [DEVLINK_PORT_FN_ATTR_CAPS] = NLA_POLICY_BITFIELD32(15), - [DEVLINK_PORT_FN_ATTR_DEVLINK] = NLA_POLICY_NESTED(devlink_dl_nested_devlink_nl_policy), [DEVLINK_PORT_FN_ATTR_MAX_IO_EQS] = { .type = NLA_U32, }, }; @@ -106,7 +97,7 @@ static const struct nla_policy devlink_port_set_nl_policy[DEVLINK_ATTR_INDEX + 1 [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), [DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, }, [DEVLINK_ATTR_PORT_TYPE] = NLA_POLICY_MAX(NLA_U16, 3), - [DEVLINK_ATTR_PORT_FUNCTION] = NLA_POLICY_NESTED(devlink_dl_port_function_nl_policy), + [DEVLINK_ATTR_PORT_FUNCTION] = NLA_POLICY_NESTED(devlink_dl_port_function_set_nl_policy), }; /* DEVLINK_CMD_PORT_NEW - do */ diff --git a/net/devlink/netlink_gen.h b/net/devlink/netlink_gen.h index 75572a9a23f6..99ccacc693b7 100644 --- a/net/devlink/netlink_gen.h +++ b/net/devlink/netlink_gen.h @@ -13,9 +13,8 @@ #include /* Common nested types */ -extern const struct nla_policy devlink_dl_nested_devlink_nl_policy[DEVLINK_ATTR_INDEX + 1]; extern const struct nla_policy devlink_dl_parent_dev_nl_policy[DEVLINK_ATTR_INDEX + 1]; -extern const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS + 1]; +extern const struct nla_policy devlink_dl_port_function_set_nl_policy[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS + 1]; extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_ATTR_BW + 1]; extern const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_ATTR_SELFTEST_ID_FLASH + 1]; diff --git a/net/devlink/port.c b/net/devlink/port.c index 1528f2d148df..803429d9a008 100644 --- a/net/devlink/port.c +++ b/net/devlink/port.c @@ -6,19 +6,6 @@ #include "devl_internal.h" -#define DEVLINK_PORT_FN_CAPS_VALID_MASK \ - (_BITUL(__DEVLINK_PORT_FN_ATTR_CAPS_MAX) - 1) - -static const struct nla_policy devlink_function_nl_policy[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = { - [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] = { .type = NLA_BINARY }, - [DEVLINK_PORT_FN_ATTR_STATE] = - NLA_POLICY_RANGE(NLA_U8, DEVLINK_PORT_FN_STATE_INACTIVE, - DEVLINK_PORT_FN_STATE_ACTIVE), - [DEVLINK_PORT_FN_ATTR_CAPS] = - NLA_POLICY_BITFIELD32(DEVLINK_PORT_FN_CAPS_VALID_MASK), - [DEVLINK_PORT_FN_ATTR_MAX_IO_EQS] = { .type = NLA_U32 }, -}; - #define ASSERT_DEVLINK_PORT_REGISTERED(devlink_port) \ WARN_ON_ONCE(!(devlink_port)->registered) #define ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port) \ @@ -782,11 +769,11 @@ static int devlink_port_function_set(struct devlink_port *port, const struct nlattr *attr, struct netlink_ext_ack *extack) { - struct nlattr *tb[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1]; + struct nlattr *tb[ARRAY_SIZE(devlink_dl_port_function_set_nl_policy)]; int err; - err = nla_parse_nested(tb, DEVLINK_PORT_FUNCTION_ATTR_MAX, attr, - devlink_function_nl_policy, extack); + err = nla_parse_nested(tb, ARRAY_SIZE(tb) - 1, attr, + devlink_dl_port_function_set_nl_policy, extack); if (err < 0) { NL_SET_ERR_MSG(extack, "Fail to parse port function attributes"); return err; From b1380f907cb0e02f12114a2d94a7e20a59fda723 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:38 -0700 Subject: [PATCH 0595/2126] netlink: specs: devlink: populate multi-attr attrs for region read and line card Three attributes are emitted repeatedly inside their nest: - devlink_nl_region_read_fill() calls devlink_nl_cmd_region_read_chunk_fill() once per 256 byte unit - devlink_nl_region_snapshots_id_put() emits one DEVLINK_ATTR_REGION_SNAPSHOT sub-nest per entry on the region's snapshot list - devlink_nl_linecard_fill() emits one DEVLINK_ATTR_LINECARD_TYPE per linecard->types_count entry In all three cases we're missing the multi-attr properties, and the attributes themselves are missing from the attr list used by C code gen. Link: https://patch.msgid.link/20260915161341.1053476-7-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index f23466fb27f9..5c9c672497d4 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -1264,6 +1264,7 @@ attribute-sets: attributes: - name: region-snapshot + multi-attr: true - name: dl-region-snapshot @@ -1278,6 +1279,7 @@ attribute-sets: attributes: - name: region-chunk + multi-attr: true - name: dl-region-chunk @@ -1360,6 +1362,7 @@ attribute-sets: attributes: - name: linecard-type + multi-attr: true - name: dl-selftest-id @@ -1971,7 +1974,7 @@ operations: post: devlink-nl-post-doit request: value: 42 - attributes: ®ion-id-attrs + attributes: - bus-name - dev-name - index @@ -1979,7 +1982,15 @@ operations: - region-name reply: ®ion-get-reply value: 42 - attributes: *region-id-attrs + attributes: + - bus-name + - dev-name + - index + - port-index + - region-name + - region-size + - region-max-snapshots + - region-snapshots dump: request: attributes: *dev-id-attrs @@ -2045,6 +2056,7 @@ operations: - index - port-index - region-name + - region-chunks - name: port-param-get @@ -2444,14 +2456,22 @@ operations: post: devlink-nl-post-doit request: value: 78 - attributes: &linecard-id-attrs + attributes: - bus-name - dev-name - index - linecard-index reply: &linecard-get-reply value: 80 - attributes: *linecard-id-attrs + attributes: + - bus-name + - dev-name + - index + - linecard-index + - linecard-state + - linecard-type + - linecard-supported-types + - nested-devlink dump: request: attributes: *dev-id-attrs From 150079380e4b13c7ed0e738913937e375259172c Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:39 -0700 Subject: [PATCH 0596/2126] netlink: specs: devlink: describe the netns id in the parent-dev nest devlink_nl_rate_parent_fill() emits DEVLINK_ATTR_PARENT_DEV via devlink_nl_put_nested_handle(), which adds DEVLINK_ATTR_NETNS_ID whenever the parent rate node lives on a devlink instance in another netns. Now that we defined dl-nested-devlink subset, which unlike dl-parent-dev includes netns-id, let's switch to it. The rate APIs input genuinely does not accept the netns-id, so we need to subset them to stick with dl-parent-dev. Fixes: b5f90fd4580ce7 ("devlink: Add parent dev to devlink API") Link: https://patch.msgid.link/20260915161341.1053476-8-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 41 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 5c9c672497d4..5535247faf14 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -912,7 +912,7 @@ attribute-sets: - name: parent-dev type: nest - nested-attributes: dl-parent-dev + nested-attributes: dl-nested-devlink doc: | Identifies the devlink instance which owns the parent rate node. Used with rate-set and rate-new to parent a rate object to a node on @@ -1390,6 +1390,10 @@ attribute-sets: - name: dl-parent-dev subset-of: devlink + doc: | + Devlink handle accepted as the parent-dev input; the netns id the + kernel reports back is not accepted, the parent is always resolved + in the caller's netns. attributes: - name: bus-name @@ -1398,6 +1402,37 @@ attribute-sets: - name: index + - + name: dl-rate-set + subset-of: devlink + doc: Attributes accepted by the rate-set and rate-new requests. + attributes: + - + name: bus-name + - + name: dev-name + - + name: index + - + name: port-index + - + name: rate-node-name + - + name: rate-tx-share + - + name: rate-tx-max + - + name: rate-tx-priority + - + name: rate-tx-weight + - + name: rate-parent-node-name + - + name: rate-tc-bws + - + name: parent-dev + nested-attributes: dl-parent-dev + - name: dl-nested-devlink subset-of: devlink @@ -2387,7 +2422,7 @@ operations: - name: rate-set doc: Set rate instances. - attribute-set: devlink + attribute-set: dl-rate-set dont-validate: [strict] flags: [admin-perm] do: @@ -2410,7 +2445,7 @@ operations: - name: rate-new doc: Create rate instances. - attribute-set: devlink + attribute-set: dl-rate-set dont-validate: [strict] flags: [admin-perm] do: From 826e2a736e333cb5a13461fa5098d692e84ccea8 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:40 -0700 Subject: [PATCH 0597/2126] netlink: specs: devlink: add pad to the subsets carrying padded u64s We are missing the pad attribute in a number of subsets. Worse, dl-attr-stats which is a separate attr space doesn't define pad, but reuses the value from the root attr set (DEVLINK_ATTR_PAD). This would break parsing stats on an arch without CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. Link: https://patch.msgid.link/20260915161341.1053476-9-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 5535247faf14..4fb64e71063d 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -1065,6 +1065,8 @@ attribute-sets: name: dpipe-table-resource-id - name: dpipe-table-resource-units + - + name: pad - name: dl-dpipe-table-matches @@ -1099,6 +1101,8 @@ attribute-sets: name: dpipe-entry-action-values - name: dpipe-entry-counter + - + name: pad - name: dl-dpipe-entry-match-values @@ -1237,6 +1241,8 @@ attribute-sets: name: resource-unit - name: resource-occ + - + name: pad - name: dl-resource-list @@ -1289,6 +1295,8 @@ attribute-sets: name: region-chunk-data - name: region-chunk-addr + - + name: pad - name: dl-fmsg @@ -1329,6 +1337,8 @@ attribute-sets: name: health-reporter-auto-dump - name: health-reporter-burst-period + - + name: pad - name: dl-attr-stats @@ -1343,6 +1353,10 @@ attribute-sets: - name: stats-rx-dropped type: u64 + - + name: pad + type: pad + value: 61 - name: dl-trap-metadata From 2a22788ba265881eb048f224534b7556815026de Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 15 Sep 2026 09:13:41 -0700 Subject: [PATCH 0598/2126] devlink: validate the port index in the rate set request port-index is the only way rate-set can address a leaf (port) rate object, but it was never listed in the request, so the generated policy has no entry for it. The op declares .maxattr = DEVLINK_ATTR_PARENT_DEV, so the attribute still reaches info->attrs[], validated against a zeroed slot - NLA_UNSPEC, length 0 - which GENL_DONT_VALIDATE_STRICT accepts at any length. devlink_port_get_from_attrs() then runs nla_get_u32() on it. Handed a zero-length port-index the kernel reads the four bytes past the payload, which are the next attribute's header, and acts on the port index those spell out. Since we're reading a linear skb the OOB read is still within the same memory allocation, it's just garbage. We also do not echo the garbage back to the user so it's not an info leak either. Hence not treating this is a real bug fix. rate-new is left alone on purpose. It creates rate nodes, resolved by name through devlink_rate_node_get_from_attrs(), and never looks at port-index. Link: https://patch.msgid.link/20260915161341.1053476-10-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/devlink.yaml | 1 + net/devlink/netlink_gen.c | 1 + 2 files changed, 2 insertions(+) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 4fb64e71063d..1de0daa0f921 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -2447,6 +2447,7 @@ operations: - bus-name - dev-name - index + - port-index - rate-node-name - rate-tx-share - rate-tx-max diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c index 43ef6864d462..9e1b4c081a7b 100644 --- a/net/devlink/netlink_gen.c +++ b/net/devlink/netlink_gen.c @@ -618,6 +618,7 @@ static const struct nla_policy devlink_rate_set_nl_policy[DEVLINK_ATTR_PARENT_DE [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), + [DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, }, [DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_RATE_TX_SHARE] = { .type = NLA_U64, }, [DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64, }, From 4bb9710c6a68d35207f123aef55dcd50e7195ec5 Mon Sep 17 00:00:00 2001 From: Ajith Parappalliyalil Venugopal Date: Tue, 15 Sep 2026 14:56:41 +0000 Subject: [PATCH 0599/2126] tipc: replace deprecated strcpy with strscpy in tipc_bearer_get_name() The `strcpy()` function is deprecated and moving towards code-tree elimination. Replacing it with `strscpy()` fixes potential buffer overflow vectors by ensuring safe NULL-termination based on the destination buffer size limit [1][2]. To make the interface safer and more robust for future callers, refactor `tipc_bearer_get_name()` to accept a destination buffer length parameter. Replace `strcpy()` with `strscpy()` and pass through any potential `-E2BIG` truncation error code up to the caller. Update the existing caller in `net/tipc/monitor.c` to pass its array size. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1] Link: https://github.com/KSPP/linux/issues/88 [2] Signed-off-by: Ajith Parappalliyalil Venugopal Reviewed-by: Tung Nguyen Link: https://patch.msgid.link/20260915145641.2434403-1-ajithpv.linux@gmail.com Signed-off-by: Jakub Kicinski --- net/tipc/bearer.c | 6 ++++-- net/tipc/bearer.h | 3 ++- net/tipc/monitor.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 05dcd2f9e887..65fa18928fe3 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -195,9 +195,10 @@ struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name) /* tipc_bearer_get_name - get the bearer name from its id. * @net: network namespace * @name: a pointer to the buffer where the name will be stored. + * @len: size of the destination buffer * @bearer_id: the id to get the name from. */ -int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id) +int tipc_bearer_get_name(struct net *net, char *name, size_t len, u32 bearer_id) { struct tipc_net *tn = tipc_net(net); struct tipc_bearer *b; @@ -209,7 +210,8 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id) if (!b) return -EINVAL; - strcpy(name, b->name); + if (strscpy(name, b->name, len) < 0) + return -E2BIG; return 0; } diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 41eac1ee0c09..9ccc9ffa925a 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -226,7 +226,8 @@ int tipc_l2_send_msg(struct net *net, struct sk_buff *buf, void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest); void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest); struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name); -int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id); +int tipc_bearer_get_name(struct net *net, char *name, + size_t len, u32 bearer_id); struct tipc_media *tipc_media_find(const char *name); int tipc_bearer_setup(void); void tipc_bearer_cleanup(void); diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c index a94b9b36a700..f3e965c48472 100644 --- a/net/tipc/monitor.c +++ b/net/tipc/monitor.c @@ -833,7 +833,8 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg, void *hdr; int ret; - ret = tipc_bearer_get_name(net, bearer_name, bearer_id); + ret = tipc_bearer_get_name(net, bearer_name, sizeof(bearer_name), + bearer_id); if (ret || !mon) return 0; From 0a9b6e9385dc1e2f56f8ec58e64a8dfc36771e74 Mon Sep 17 00:00:00 2001 From: Nazim Amirul Date: Wed, 9 Sep 2026 01:05:59 -0700 Subject: [PATCH 0600/2126] dt-bindings: net: snps,dwmac: allow stmmaceth-ocp reset name Arria10 SoCFPGA DWMAC nodes use reset-names = "stmmaceth", "stmmaceth-ocp", which matches what dwmac-socfpga looks up for the OCP reset. The generic snps,dwmac binding only allowed "ahb" as the second reset name, so Arria10 DTS failed schema validation. Allow "stmmaceth-ocp" as an alternative second reset name and drop the related TODO from the Altera SoCFPGA DWMAC binding. Signed-off-by: Nazim Amirul Reviewed-by: Rob Herring (Arm) Link: https://patch.msgid.link/20260909080559.2028-1-muhammad.nazim.amirul.nazle.asmade@altera.com Signed-off-by: Jakub Kicinski --- .../devicetree/bindings/net/altr,socfpga-stmmac.yaml | 2 -- Documentation/devicetree/bindings/net/snps,dwmac.yaml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml b/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml index db93436c96fa..d8f90d36d246 100644 --- a/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml +++ b/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml @@ -13,8 +13,6 @@ description: This binding describes the Altera SOCFPGA SoC implementation of the Synopsys DWMAC for the Cyclone5, Arria5, Stratix10, Agilex5 and Agilex7 families of chips. - # TODO: Determine how to handle the Arria10 reset-name, stmmaceth-ocp, that - # does not validate against net/snps,dwmac.yaml. select: properties: diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml index 2ed4564ae99d..0ff9e3284a06 100644 --- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml +++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml @@ -175,7 +175,7 @@ properties: minItems: 1 items: - description: GMAC stmmaceth reset - - description: AHB reset + - description: AHB or OCP reset reset-names: oneOf: @@ -183,7 +183,7 @@ properties: - enum: [stmmaceth, ahb] - items: - const: stmmaceth - - const: ahb + - enum: [ahb, stmmaceth-ocp] power-domains: maxItems: 1 From 4a6764900678c92dc5fa17d59082698ef44260f8 Mon Sep 17 00:00:00 2001 From: Guangshuo Li Date: Wed, 16 Sep 2026 11:14:14 +0800 Subject: [PATCH 0601/2126] net: fs_enet: fix platform info memory leak on remove fs_enet_probe() allocates the platform information structure with kzalloc_obj() and stores it in fep->fpi. The probe failure paths release this allocation with kfree(). However, after a successful probe, fs_enet_remove() tears down the network device without freeing fep->fpi, leaving the platform information structure allocated after driver removal. Free fep->fpi before releasing the network device. This issue was found by manual code inspection. Cc: stable+noautosel@kernel.org # untested fix to a driver init path Signed-off-by: Guangshuo Li Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260916031414.2875022-1-lgs201920130244@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c index d3c772ed5fc9..071e3f3de78c 100644 --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c @@ -1007,6 +1007,7 @@ static void fs_enet_remove(struct platform_device *ofdev) fep->ops->cleanup_data(ndev); dev_set_drvdata(fep->dev, NULL); phylink_destroy(fep->phylink); + kfree(fep->fpi); free_netdev(ndev); } From c863bf6a7d7dab8cd9e36b1842c7e58b63bccfdb Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:22:29 +0000 Subject: [PATCH 0602/2126] net: rmnet: annotate data-races around port->data_format port->data_format is written under RTNL from rmnet_newlink() and rmnet_changelink(), but it is read from the data path without any lock, both from RX (rmnet_rx_handler() context) and TX (rmnet_egress_handler() context). Note that rmnet_newlink() can be called for a real_dev which is already hooked to rmnet: the rx_handler is live and traffic can already be flowing when port->data_format is overwritten. Add the missing READ_ONCE()/WRITE_ONCE() annotations. While at it, sample port->data_format only once per packet and pass the value down, so that all the decisions taken for a given packet are based on a single consistent value. Otherwise the two ends of a packet transformation could disagree. On TX, rmnet_map_egress_handler() sized the headroom from one read while rmnet_map_add_map_header() decided on MAP_NEXT_HEADER_FLAG from another one, so a concurrent rmnet_changelink() could produce a MAP header announcing a v5 csum header that was neither reserved nor written. On RX, rmnet_map_validate_packet_len() and __rmnet_map_ingress_handler() could likewise disagree on the expected layout, and rmnet_map_send_ack() could trim a dl csum trailer that the ingress path never accounted for. rmnet_map_add_map_header(), rmnet_map_command(), rmnet_map_deaggregate(), rmnet_map_send_ack(), rmnet_map_validate_packet_len() and __rmnet_map_ingress_handler() therefore get the value from their caller instead of re-reading it. rmnet_changelink() now computes the new value in a local variable and publishes it with a single store, instead of letting the data path observe the intermediate (old_data_format & ~flags->mask) value. rmnet_vnd_headroom() is left alone, all its callers hold RTNL. Signed-off-by: Eric Dumazet Cc: Sean Tranchetti Reviewed-by: Subash Abhinov Kasiviswanathan Link: https://patch.msgid.link/20260916132231.1780091-2-edumazet@google.com Signed-off-by: Jakub Kicinski --- .../ethernet/qualcomm/rmnet/rmnet_config.c | 10 +++--- .../ethernet/qualcomm/rmnet/rmnet_handlers.c | 32 +++++++++++-------- .../net/ethernet/qualcomm/rmnet/rmnet_map.h | 9 +++--- .../qualcomm/rmnet/rmnet_map_command.c | 9 +++--- .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 14 ++++---- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c index 8bf385ab44a9..0316888d964f 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -176,7 +176,7 @@ static int rmnet_newlink(struct net_device *dev, } netdev_dbg(dev, "data format [0x%08X]\n", data_format); - port->data_format = data_format; + WRITE_ONCE(port->data_format, data_format); return 0; @@ -348,14 +348,16 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[], if (data[IFLA_RMNET_FLAGS]) { struct ifla_rmnet_flags *flags; u32 old_data_format; + u32 data_format; old_data_format = port->data_format; flags = nla_data(data[IFLA_RMNET_FLAGS]); - port->data_format &= ~flags->mask; - port->data_format |= flags->flags & flags->mask; + data_format = old_data_format & ~flags->mask; + data_format |= flags->flags & flags->mask; + WRITE_ONCE(port->data_format, data_format); if (rmnet_vnd_update_dev_mtu(port, real_dev)) { - port->data_format = old_data_format; + WRITE_ONCE(port->data_format, old_data_format); NL_SET_ERR_MSG_MOD(extack, "Invalid MTU on real dev"); return -EINVAL; } diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index d055a2628d8c..d4fec2fff227 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -54,7 +54,8 @@ rmnet_deliver_skb(struct sk_buff *skb) static void __rmnet_map_ingress_handler(struct sk_buff *skb, - struct rmnet_port *port) + struct rmnet_port *port, + u32 data_format) { struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; @@ -63,8 +64,8 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, if (map_header->flags & MAP_CMD_FLAG) { /* Packet contains a MAP command (not data) */ - if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) - return rmnet_map_command(skb, port); + if (data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) + return rmnet_map_command(skb, port, data_format); goto free_skb; } @@ -82,7 +83,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, skb->dev = ep->egress_dev; - if ((port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV5) && + if ((data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV5) && (map_header->flags & MAP_NEXT_HEADER_FLAG)) { if (rmnet_map_process_next_hdr_packet(skb, len)) goto free_skb; @@ -92,7 +93,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, /* Subtract MAP header */ skb_pull(skb, sizeof(*map_header)); rmnet_set_skb_proto(skb); - if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4 && + if (data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4 && !rmnet_map_checksum_downlink_packet(skb, len + pad)) skb->ip_summed = CHECKSUM_UNNECESSARY; } @@ -110,6 +111,7 @@ rmnet_map_ingress_handler(struct sk_buff *skb, struct rmnet_port *port) { struct sk_buff *skbn; + u32 data_format; if (skb->dev->type == ARPHRD_ETHER) { if (pskb_expand_head(skb, ETH_HLEN, 0, GFP_ATOMIC)) { @@ -120,14 +122,16 @@ rmnet_map_ingress_handler(struct sk_buff *skb, skb_push(skb, ETH_HLEN); } - if (port->data_format & RMNET_FLAGS_INGRESS_DEAGGREGATION) { - while ((skbn = rmnet_map_deaggregate(skb, port)) != NULL) - __rmnet_map_ingress_handler(skbn, port); + data_format = READ_ONCE(port->data_format); + + if (data_format & RMNET_FLAGS_INGRESS_DEAGGREGATION) { + while ((skbn = rmnet_map_deaggregate(skb, data_format)) != NULL) + __rmnet_map_ingress_handler(skbn, port, data_format); consume_skb(skb); } else { - if (rmnet_map_validate_packet_len(skb, port)) - __rmnet_map_ingress_handler(skb, port); + if (rmnet_map_validate_packet_len(skb, data_format)) + __rmnet_map_ingress_handler(skb, port, data_format); else kfree_skb(skb); } @@ -139,14 +143,16 @@ static int rmnet_map_egress_handler(struct sk_buff *skb, { int required_headroom, additional_header_len, csum_type = 0; struct rmnet_map_header *map_header; + u32 data_format; additional_header_len = 0; required_headroom = sizeof(struct rmnet_map_header); - if (port->data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV4) { + data_format = READ_ONCE(port->data_format); + if (data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV4) { additional_header_len = sizeof(struct rmnet_map_ul_csum_header); csum_type = RMNET_FLAGS_EGRESS_MAP_CKSUMV4; - } else if (port->data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV5) { + } else if (data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV5) { additional_header_len = sizeof(struct rmnet_map_v5_csum_header); csum_type = RMNET_FLAGS_EGRESS_MAP_CKSUMV5; } @@ -161,7 +167,7 @@ static int rmnet_map_egress_handler(struct sk_buff *skb, csum_type); map_header = rmnet_map_add_map_header(skb, additional_header_len, - port, 0); + data_format, 0); if (!map_header) return -ENOMEM; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h index 60ca8b780c88..0977e495f591 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h @@ -41,12 +41,13 @@ enum rmnet_map_commands { #define RMNET_MAP_ADD_PAD_BYTES 1 struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, - struct rmnet_port *port); + u32 data_format); struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, int hdrlen, - struct rmnet_port *port, + u32 data_format, int pad); -void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port); +void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port, + u32 data_format); int rmnet_map_checksum_downlink_packet(struct sk_buff *skb, u16 len); void rmnet_map_checksum_uplink_packet(struct sk_buff *skb, struct rmnet_port *port, @@ -59,6 +60,6 @@ void rmnet_map_tx_aggregate_init(struct rmnet_port *port); void rmnet_map_tx_aggregate_exit(struct rmnet_port *port); void rmnet_map_update_ul_agg_config(struct rmnet_port *port, u32 size, u32 count, u32 time); -u32 rmnet_map_validate_packet_len(struct sk_buff *skb, struct rmnet_port *port); +u32 rmnet_map_validate_packet_len(struct sk_buff *skb, u32 data_format); #endif /* _RMNET_MAP_H_ */ diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c index add0f5ade2e6..d334727e1f52 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c @@ -48,13 +48,13 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb, static void rmnet_map_send_ack(struct sk_buff *skb, unsigned char type, - struct rmnet_port *port) + u32 data_format) { struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; struct net_device *dev = skb->dev; - if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) + if (data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) skb_trim(skb, skb->len - sizeof(struct rmnet_map_dl_csum_trailer)); @@ -72,7 +72,8 @@ static void rmnet_map_send_ack(struct sk_buff *skb, /* Process MAP command frame and send N/ACK message as appropriate. Message cmd * name is decoded here and appropriate handler is called. */ -void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) +void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port, + u32 data_format) { struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; @@ -98,5 +99,5 @@ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) break; } if (rc == RMNET_MAP_COMMAND_ACK) - rmnet_map_send_ack(skb, rc, port); + rmnet_map_send_ack(skb, rc, data_format); } diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index e6f48dc9fe64..39d6d084e73f 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -294,7 +294,7 @@ sw_csum: */ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, int hdrlen, - struct rmnet_port *port, + u32 data_format, int pad) { struct rmnet_map_header *map_header; @@ -306,7 +306,7 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, memset(map_header, 0, sizeof(struct rmnet_map_header)); /* Set next_hdr bit for csum offload packets */ - if (port->data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV5) + if (data_format & RMNET_FLAGS_EGRESS_MAP_CKSUMV5) map_header->flags |= MAP_NEXT_HEADER_FLAG; if (pad == RMNET_MAP_NO_PAD_BYTES) { @@ -333,7 +333,7 @@ done: return map_header; } -u32 rmnet_map_validate_packet_len(struct sk_buff *skb, struct rmnet_port *port) +u32 rmnet_map_validate_packet_len(struct sk_buff *skb, u32 data_format) { struct rmnet_map_v5_csum_header *next_hdr = NULL; struct rmnet_map_header *maph; @@ -351,9 +351,9 @@ u32 rmnet_map_validate_packet_len(struct sk_buff *skb, struct rmnet_port *port) packet_len = ntohs(maph->pkt_len) + sizeof(*maph); - if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) { + if (data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) { packet_len += sizeof(struct rmnet_map_dl_csum_trailer); - } else if ((port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV5) && + } else if ((data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV5) && !(maph->flags & MAP_CMD_FLAG)) { /* Mapv5 data pkt without csum hdr is invalid */ if (!(maph->flags & MAP_NEXT_HEADER_FLAG)) @@ -381,12 +381,12 @@ u32 rmnet_map_validate_packet_len(struct sk_buff *skb, struct rmnet_port *port) * is responsible for freeing the original skb. */ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, - struct rmnet_port *port) + u32 data_format) { struct sk_buff *skbn; u32 packet_len; - packet_len = rmnet_map_validate_packet_len(skb, port); + packet_len = rmnet_map_validate_packet_len(skb, data_format); if (!packet_len) return NULL; From 0067187dbe15ca963f671fc009801a80939d6c41 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:22:30 +0000 Subject: [PATCH 0603/2126] net: rmnet: annotate data-races around mux_id priv->mux_id is written under RTNL from rmnet_vnd_newlink() and rmnet_changelink(), but rmnet_egress_handler() reads it from the transmit path without any lock. Likewise ep->mux_id is written under RTNL from rmnet_changelink(), while rmnet_get_endpoint() reads it from the receive path under RCU only. Add the missing READ_ONCE()/WRITE_ONCE() annotations. While at it, publish ep->mux_id before inserting the endpoint in its new bucket in rmnet_changelink(). Otherwise a concurrent rmnet_get_endpoint() walking the new bucket could find the endpoint still carrying its old mux_id, and drop the packet. Signed-off-by: Eric Dumazet Cc: Sean Tranchetti Reviewed-by: Subash Abhinov Kasiviswanathan Link: https://patch.msgid.link/20260916132231.1780091-3-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 6 +++--- drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 2 +- drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c index 0316888d964f..e7b3e4f92731 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -337,11 +337,11 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[], } hlist_del_init_rcu(&ep->hlnode); + WRITE_ONCE(ep->mux_id, mux_id); hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]); - ep->mux_id = mux_id; - priv->mux_id = mux_id; + WRITE_ONCE(priv->mux_id, mux_id); } } @@ -433,7 +433,7 @@ struct rmnet_endpoint *rmnet_get_endpoint(struct rmnet_port *port, u8 mux_id) hlist_for_each_entry_rcu(ep, &port->muxed_ep[mux_id], hlnode, lockdep_rtnl_is_held()) { - if (ep->mux_id == mux_id) + if (READ_ONCE(ep->mux_id) == mux_id) return ep; } diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index d4fec2fff227..aa5523f4618e 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -261,7 +261,7 @@ void rmnet_egress_handler(struct sk_buff *skb) orig_dev = skb->dev; priv = netdev_priv(orig_dev); skb->dev = priv->real_dev; - mux_id = priv->mux_id; + mux_id = READ_ONCE(priv->mux_id); port = rmnet_get_port_rcu(skb->dev); if (!port) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c index 53802b485a81..5f921cddf82b 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c @@ -341,7 +341,7 @@ int rmnet_vnd_newlink(u8 id, struct net_device *rmnet_dev, rmnet_dev->rtnl_link_ops = &rmnet_link_ops; - priv->mux_id = id; + WRITE_ONCE(priv->mux_id, id); netdev_dbg(rmnet_dev, "rmnet dev created\n"); } From d7c9ba103b06eee4a65a686c1d947e68addab390 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:22:31 +0000 Subject: [PATCH 0604/2126] net: rmnet: no longer rely on RTNL in rmnet_fill_info() rmnet_fill_info() used rmnet_get_port_rtnl(), and thus required RTNL. Now that priv->mux_id and port->data_format are properly annotated, rmnet_fill_info() can simply fetch the port under rcu_read_lock(). rmnet_get_port_rcu() was only used from the data path and thus used rcu_dereference_bh(). Relax its lockdep condition so that it can also be called from process context under a plain rcu_read_lock(), and use it from rmnet_fill_info(). Note that rmnet_get_port_rcu() checks real_dev->rx_handler before returning rx_handler_data: this is what makes the lockless lookup safe against rmnet_unregister_real_device(), which clears rx_handler, waits for a grace period in netdev_rx_handler_unregister(), and only then frees the port. While at it, add missing const qualifiers. Signed-off-by: Eric Dumazet Cc: Sean Tranchetti Reviewed-by: Subash Abhinov Kasiviswanathan Link: https://patch.msgid.link/20260916132231.1780091-4-edumazet@google.com Signed-off-by: Jakub Kicinski --- .../ethernet/qualcomm/rmnet/rmnet_config.c | 38 +++++++++---------- .../ethernet/qualcomm/rmnet/rmnet_config.h | 2 +- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c index e7b3e4f92731..61b04c6c0390 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -377,32 +377,24 @@ static size_t rmnet_get_size(const struct net_device *dev) static int rmnet_fill_info(struct sk_buff *skb, const struct net_device *dev) { - struct rmnet_priv *priv = netdev_priv(dev); - struct net_device *real_dev; + const struct rmnet_priv *priv = netdev_priv(dev); + const struct rmnet_port *port; struct ifla_rmnet_flags f; - struct rmnet_port *port; - real_dev = priv->real_dev; + if (nla_put_u16(skb, IFLA_RMNET_MUX_ID, READ_ONCE(priv->mux_id))) + return -EMSGSIZE; - if (nla_put_u16(skb, IFLA_RMNET_MUX_ID, priv->mux_id)) - goto nla_put_failure; - - if (rmnet_is_real_dev_registered(real_dev)) { - port = rmnet_get_port_rtnl(real_dev); - f.flags = port->data_format; - } else { - f.flags = 0; - } + rcu_read_lock(); + port = rmnet_get_port_rcu(priv->real_dev); + f.flags = port ? READ_ONCE(port->data_format) : 0; + rcu_read_unlock(); f.mask = ~0; if (nla_put(skb, IFLA_RMNET_FLAGS, sizeof(f), &f)) - goto nla_put_failure; + return -EMSGSIZE; return 0; - -nla_put_failure: - return -EMSGSIZE; } struct rtnl_link_ops rmnet_link_ops __read_mostly = { @@ -419,12 +411,16 @@ struct rtnl_link_ops rmnet_link_ops __read_mostly = { .fill_info = rmnet_fill_info, }; -struct rmnet_port *rmnet_get_port_rcu(struct net_device *real_dev) +/* Can be called from a RCU read-side critical section, with or + * without BH disabled. + */ +struct rmnet_port *rmnet_get_port_rcu(const struct net_device *real_dev) { - if (rmnet_is_real_dev_registered(real_dev)) - return rcu_dereference_bh(real_dev->rx_handler_data); - else + if (!rmnet_is_real_dev_registered(real_dev)) return NULL; + + return rcu_dereference_check(real_dev->rx_handler_data, + rcu_read_lock_bh_held()); } struct rmnet_endpoint *rmnet_get_endpoint(struct rmnet_port *port, u8 mux_id) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h index f50fae1c6bdd..5adda0323dda 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h @@ -90,7 +90,7 @@ struct rmnet_priv { struct rmnet_priv_stats stats; }; -struct rmnet_port *rmnet_get_port_rcu(struct net_device *real_dev); +struct rmnet_port *rmnet_get_port_rcu(const struct net_device *real_dev); struct rmnet_endpoint *rmnet_get_endpoint(struct rmnet_port *port, u8 mux_id); int rmnet_add_bridge(struct net_device *rmnet_dev, struct net_device *slave_dev, From 0093f7db9c47177fd5a269858002c89c6a3fa340 Mon Sep 17 00:00:00 2001 From: Breno Leitao Date: Mon, 14 Sep 2026 05:20:07 -0700 Subject: [PATCH 0605/2126] net: add sockopt_expand_out() Some getsockopt options size their reply from a count the caller left in optval rather than from optlen, and so write past the optlen the caller declared. Userspace relies on that, so the sockopt_t conversion has to keep doing it. IP_MSFILTER is the first one to convert: its reply covers the imsf_numsrc sources the caller asked for, while optlen only has to cover the fixed header. Add sockopt_expand_out() to grow opt->iter_out mid-air, so the quirk sits in one place instead of each protocol assuming it implicitly. It is a no-op unless the reply outruns optlen. Growing re-anchors the iterator at the head of optval, so it has to be called before anything is written through iter_out. Only a user buffer can be longer than optlen says. A kernel-backed optval keeps the bounded iterator, and a callback that asks to grow one gets a WARN_ON_ONCE() and -EINVAL. Nothing in tree can trip that WARN: the only kernel-backed path into do_ip_getsockopt() is sol_ip_sockopt(), which takes IP_TOS and IP_TRANSPARENT only. It is an assert for the in-kernel callers BPF and io_uring gain once the conversion is done, so they declare an optlen covering the whole buffer instead of repeating the userspace mistake. The conversion in the next patch calls sockptr_to_sockopt() from net/ipv4/, so drop its static and declare it in net.h. Signed-off-by: Breno Leitao Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20260914-getsockopt_phase6-v2-1-e48befc9602e@debian.org Signed-off-by: Jakub Kicinski --- include/linux/net.h | 32 ++++++++++++++++++++++++++++++++ net/socket.c | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/linux/net.h b/include/linux/net.h index 470100ae7107..e2a866fbcfa5 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -47,6 +47,9 @@ typedef struct sockopt { int optlen; } sockopt_t; +int sockptr_to_sockopt(sockopt_t *opt, sockptr_t optval, sockptr_t optlen, + struct kvec *kvec); + /* * Initialize a user-backed sockopt_t from the (optval, optlen) __user pair of * a getsockopt() callback. Used by transitional __user getsockopt wrappers @@ -70,6 +73,35 @@ static inline int sockopt_init_user(sockopt_t *opt, char __user *optval, return 0; } +/* + * Grow optval to @size, for the options whose reply is sized by a count the + * caller left in optval rather than by optlen. Those write past optlen today + * and userspace relies on it. + * + * Call it before writing through opt->iter_out: it re-anchors the iterator at + * the head of optval. Only a user buffer can be longer than the optlen the + * caller declared, so a kernel-backed optval is refused with -EINVAL. + */ +static inline int sockopt_expand_out(sockopt_t *opt, size_t size) +{ + if (size <= (size_t)opt->optlen) + return 0; + + if (size > INT_MAX) + return -EINVAL; + + /* Re-anchoring reads iter_out.ubuf, so the iterator has to be a user + * buffer that nothing has written through yet. + */ + if (WARN_ON_ONCE(!iter_is_ubuf(&opt->iter_out) || + iov_iter_count(&opt->iter_out) != (size_t)opt->optlen)) + return -EINVAL; + + iov_iter_ubuf(&opt->iter_out, ITER_DEST, opt->iter_out.ubuf, size); + + return 0; +} + struct poll_table_struct; struct pipe_inode_info; struct inode; diff --git a/net/socket.c b/net/socket.c index 4cb8662869f0..bb0e1e118ef6 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2436,8 +2436,8 @@ INDIRECT_CALLABLE_DECLARE(bool tcp_bpf_bypass_getsockopt(int level, * It is important to remember that both iov points to the same data, but, * .iter_in is read-only and .iter_out is write-only by the protocol callbacks */ -static int sockptr_to_sockopt(sockopt_t *opt, sockptr_t optval, - sockptr_t optlen, struct kvec *kvec) +int sockptr_to_sockopt(sockopt_t *opt, sockptr_t optval, + sockptr_t optlen, struct kvec *kvec) { int koptlen; From e12e04f5ab54cd6b4c1819b2a8e870245406022a Mon Sep 17 00:00:00 2001 From: Breno Leitao Date: Mon, 14 Sep 2026 05:20:08 -0700 Subject: [PATCH 0606/2126] ipv4: igmp: convert ip_mc_msfget() to sockopt_t IP_MSFILTER reads its reply through ip_mc_msfget(), reached from do_ip_getsockopt() and from nowhere else. Convert it, and build the sockopt_t at the call site for as long as the caller still carries a sockptr_t pair. optlen here only has to cover the header, and the real reply size comes from the imsf_numsrc field inside it. This is nasty, but userspace relies on it, so sockopt_expand_out() preserves the same mechanism: it grows optval only for a user address, and assumes the caller left room for the size its own header asked for. The *optlen store moves out of ip_mc_msfget() and into the call site, guarded by !err so the -EINVAL, -ENODEV and -EADDRNOTAVAIL returns still leave the caller's optlen word untouched. The source list also moves from copy_to_sockptr_offset() to a sequential copy_to_iter(). IP_MSFILTER_SIZE(0) and offsetof(struct ip_msfilter, imsf_slist_flex) are both 16, so the bytes land where they did. Signed-off-by: Breno Leitao Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20260914-getsockopt_phase6-v2-2-e48befc9602e@debian.org Signed-off-by: Jakub Kicinski --- include/linux/igmp.h | 3 ++- net/ipv4/igmp.c | 23 ++++++++++++++--------- net/ipv4/ip_sockglue.c | 10 +++++++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/linux/igmp.h b/include/linux/igmp.h index a0cf0398519f..e075611344ef 100644 --- a/include/linux/igmp.h +++ b/include/linux/igmp.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -273,7 +274,7 @@ extern int ip_mc_source(int add, int omode, struct sock *sk, struct ip_mreq_source *mreqs, int ifindex); extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex); extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, - sockptr_t optval, sockptr_t optlen); + sockopt_t *opt); extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf, sockptr_t optval, size_t offset); extern int ip_mc_sf_allow(const struct sock *sk, __be32 local, __be32 rmt, diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index d56355aca797..144fca158adc 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -2709,8 +2709,8 @@ done: err = ip_mc_leave_group(sk, &imr); return err; } -int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, - sockptr_t optval, sockptr_t optlen) + +int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, sockopt_t *opt) { int err, len, count, copycount, msf_size; struct ip_mreqn imr; @@ -2755,14 +2755,19 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, len = flex_array_size(psl, sl_addr, copycount); msf->imsf_numsrc = count; msf_size = IP_MSFILTER_SIZE(copycount); - if (copy_to_sockptr(optlen, &msf_size, sizeof(int)) || - copy_to_sockptr(optval, msf, IP_MSFILTER_SIZE(0))) { + + /* The source list is sized by the imsf_numsrc the caller left in + * optval, not by optlen, which only has to cover the fixed part. + */ + err = sockopt_expand_out(opt, msf_size); + if (err) + return err; + + opt->optlen = msf_size; + if (copy_to_iter(msf, IP_MSFILTER_SIZE(0), &opt->iter_out) != + IP_MSFILTER_SIZE(0)) return -EFAULT; - } - if (len && - copy_to_sockptr_offset(optval, - offsetof(struct ip_msfilter, imsf_slist_flex), - psl->sl_addr, len)) + if (len && copy_to_iter(psl->sl_addr, len, &opt->iter_out) != len) return -EFAULT; return 0; done: diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index a55ef327ec93..e06c1f48ecad 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -1706,6 +1706,8 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname, case IP_MSFILTER: { struct ip_msfilter msf; + struct kvec kvec; + sockopt_t opt; if (len < IP_MSFILTER_SIZE(0)) { err = -EINVAL; @@ -1715,7 +1717,13 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname, err = -EFAULT; goto out; } - err = ip_mc_msfget(sk, &msf, optval, optlen); + err = sockptr_to_sockopt(&opt, optval, optlen, &kvec); + if (err) + goto out; + + err = ip_mc_msfget(sk, &msf, &opt); + if (!err && copy_to_sockptr(optlen, &opt.optlen, sizeof(int))) + err = -EFAULT; goto out; } case MCAST_MSFILTER: From 9211c455dee8bbe13699ccd1a5dcdd731909ac9b Mon Sep 17 00:00:00 2001 From: Guangshuo Li Date: Wed, 16 Sep 2026 11:00:15 +0800 Subject: [PATCH 0607/2126] net: dpaa2: ptp: fix device node reference leak on remove dpaa2_ptp_probe() gets a referenced device node with of_find_compatible_node() and stores it in dev->of_node. The probe failure paths release this reference with of_node_put(). However, after a successful probe, dpaa2_ptp_remove() tears down the PTP and MC resources without dropping the device node reference. Release dev->of_node during driver removal and clear the pointer after dropping the reference. This issue was found by manual code inspection. Cc: stable+noautosel@kernel.org # untested fix to a driver init path Signed-off-by: Guangshuo Li Link: https://patch.msgid.link/20260916030015.2818545-1-lgs201920130244@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c index 4497e3c0456d..440319a1e775 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c @@ -232,6 +232,8 @@ static void dpaa2_ptp_remove(struct fsl_mc_device *mc_dev) fsl_mc_free_irqs(mc_dev); dprtc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); fsl_mc_portal_free(mc_dev->mc_io); + of_node_put(dev->of_node); + dev->of_node = NULL; } static const struct fsl_mc_device_id dpaa2_ptp_match_id_table[] = { From ca6ff8dd70ebd16b2c0ebe93ec174d2a7079bbe9 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:25:31 +0000 Subject: [PATCH 0608/2126] vlan: annotate data-races in vlan_dev_priv fields vlan->flags, vlan->ingress_priority_map[] and vlan->nr_*_mappings are written under RTNL, but read from lockless contexts: - the RX path reads vlan->flags (VLAN_FLAG_REORDER_HDR) and the ingress priority map, - the TX path reads vlan->flags, - /proc/net/vlan/ reads vlan->flags and the ingress priority map, - vlan_get_size() reads vlan->nr_*_mappings, - vlan_fill_info() will soon run without RTNL. Add the missing READ_ONCE()/WRITE_ONCE() annotations. vlan_dev_change_flags() is also made a bit more readable by using a local new_flags variable, avoiding the repeated re-reads of vlan->flags after it has been published. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260916132532.1785657-2-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/8021q/vlan.h | 2 +- net/8021q/vlan_core.c | 2 +- net/8021q/vlan_dev.c | 37 ++++++++++++++++++++++--------------- net/8021q/vlan_netlink.c | 4 ++-- net/8021q/vlanproc.c | 18 +++++++++--------- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index d874ab323d32..4930e6e86109 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -158,7 +158,7 @@ static inline u32 vlan_get_ingress_priority(struct net_device *dev, { struct vlan_dev_priv *vip = vlan_dev_priv(dev); - return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7]; + return READ_ONCE(vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7]); } #ifdef CONFIG_VLAN_8021Q_GVRP diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c index d23965e76c16..1fc6ebd33132 100644 --- a/net/8021q/vlan_core.c +++ b/net/8021q/vlan_core.c @@ -38,7 +38,7 @@ bool vlan_do_receive(struct sk_buff **skbp) skb->pkt_type = PACKET_HOST; } - if (!(vlan_dev_priv(vlan_dev)->flags & VLAN_FLAG_REORDER_HDR) && + if (!(READ_ONCE(vlan_dev_priv(vlan_dev)->flags) & VLAN_FLAG_REORDER_HDR) && !netif_is_macvlan_port(vlan_dev) && !netif_is_bridge_port(vlan_dev)) { unsigned int offset = skb->data - skb_mac_header(skb); diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 2859cbac3f26..16e917e9c230 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -54,7 +54,7 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev, u16 vlan_tci = 0; int rc; - if (!(vlan->flags & VLAN_FLAG_REORDER_HDR)) { + if (!(READ_ONCE(vlan->flags) & VLAN_FLAG_REORDER_HDR)) { vhdr = skb_push(skb, VLAN_HLEN); vlan_tci = vlan->vlan_id; @@ -110,7 +110,7 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb, * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs... */ - if (vlan->flags & VLAN_FLAG_REORDER_HDR || + if (READ_ONCE(vlan->flags) & VLAN_FLAG_REORDER_HDR || veth->h_vlan_proto != vlan->vlan_proto) { u16 vlan_tci; vlan_tci = vlan->vlan_id; @@ -159,13 +159,16 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev, u32 skb_prio, u16 vlan_prio) { struct vlan_dev_priv *vlan = vlan_dev_priv(dev); + u32 *map = &vlan->ingress_priority_map[vlan_prio & 0x7]; - if (vlan->ingress_priority_map[vlan_prio & 0x7] && !skb_prio) - vlan->nr_ingress_mappings--; - else if (!vlan->ingress_priority_map[vlan_prio & 0x7] && skb_prio) - vlan->nr_ingress_mappings++; + if (*map && !skb_prio) + WRITE_ONCE(vlan->nr_ingress_mappings, + vlan->nr_ingress_mappings - 1); + else if (!*map && skb_prio) + WRITE_ONCE(vlan->nr_ingress_mappings, + vlan->nr_ingress_mappings + 1); - vlan->ingress_priority_map[vlan_prio & 0x7] = skb_prio; + WRITE_ONCE(*map, skb_prio); } int vlan_dev_set_egress_priority(const struct net_device *dev, @@ -185,7 +188,8 @@ int vlan_dev_set_egress_priority(const struct net_device *dev, if (mp->priority == skb_prio) { if (!vlan_qos) { rcu_assign_pointer(*mpp, rtnl_dereference(mp->next)); - vlan->nr_egress_mappings--; + WRITE_ONCE(vlan->nr_egress_mappings, + vlan->nr_egress_mappings - 1); kfree_rcu(mp, rcu); } else { WRITE_ONCE(mp->vlan_qos, vlan_qos); @@ -209,7 +213,8 @@ int vlan_dev_set_egress_priority(const struct net_device *dev, RCU_INIT_POINTER(np->next, rtnl_dereference(vlan->egress_priority_map[bucket])); rcu_assign_pointer(vlan->egress_priority_map[bucket], np); if (vlan_qos) - vlan->nr_egress_mappings++; + WRITE_ONCE(vlan->nr_egress_mappings, + vlan->nr_egress_mappings + 1); return 0; } @@ -220,23 +225,25 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask) { struct vlan_dev_priv *vlan = vlan_dev_priv(dev); u32 old_flags = vlan->flags; + u32 new_flags; if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP | VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP | VLAN_FLAG_BRIDGE_BINDING)) return -EINVAL; - vlan->flags = (old_flags & ~mask) | (flags & mask); + new_flags = (old_flags & ~mask) | (flags & mask); + WRITE_ONCE(vlan->flags, new_flags); - if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) { - if (vlan->flags & VLAN_FLAG_GVRP) + if (netif_running(dev) && (new_flags ^ old_flags) & VLAN_FLAG_GVRP) { + if (new_flags & VLAN_FLAG_GVRP) vlan_gvrp_request_join(dev); else vlan_gvrp_request_leave(dev); } - if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_MVRP) { - if (vlan->flags & VLAN_FLAG_MVRP) + if (netif_running(dev) && (new_flags ^ old_flags) & VLAN_FLAG_MVRP) { + if (new_flags & VLAN_FLAG_MVRP) vlan_mvrp_request_join(dev); else vlan_mvrp_request_leave(dev); @@ -599,7 +606,7 @@ void vlan_dev_free_egress_priority(const struct net_device *dev) pm = next; } } - vlan->nr_egress_mappings = 0; + WRITE_ONCE(vlan->nr_egress_mappings, 0); } static void vlan_dev_uninit(struct net_device *dev) diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 368d53ca7d87..71cb98950511 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -214,8 +214,8 @@ static size_t vlan_get_size(const struct net_device *dev) return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */ nla_total_size(2) + /* IFLA_VLAN_ID */ nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */ - vlan_qos_map_size(vlan->nr_ingress_mappings) + - vlan_qos_map_size(vlan->nr_egress_mappings); + vlan_qos_map_size(READ_ONCE(vlan->nr_ingress_mappings)) + + vlan_qos_map_size(READ_ONCE(vlan->nr_egress_mappings)); } static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev) diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c index 0e424e0895b7..5dd27438db9b 100644 --- a/net/8021q/vlanproc.c +++ b/net/8021q/vlanproc.c @@ -240,7 +240,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset) seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %x\n", vlandev->name, vlan->vlan_id, - (int)(vlan->flags & 1), (u32)vlandev->priv_flags); + (int)(READ_ONCE(vlan->flags) & 1), (u32)vlandev->priv_flags); seq_printf(seq, fmt64, "total frames received", stats->rx_packets); seq_printf(seq, fmt64, "total bytes received", stats->rx_bytes); @@ -252,14 +252,14 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset) /* now show all PRIORITY mappings relating to this VLAN */ seq_printf(seq, "\nINGRESS priority mappings: " "0:%u 1:%u 2:%u 3:%u 4:%u 5:%u 6:%u 7:%u\n", - vlan->ingress_priority_map[0], - vlan->ingress_priority_map[1], - vlan->ingress_priority_map[2], - vlan->ingress_priority_map[3], - vlan->ingress_priority_map[4], - vlan->ingress_priority_map[5], - vlan->ingress_priority_map[6], - vlan->ingress_priority_map[7]); + READ_ONCE(vlan->ingress_priority_map[0]), + READ_ONCE(vlan->ingress_priority_map[1]), + READ_ONCE(vlan->ingress_priority_map[2]), + READ_ONCE(vlan->ingress_priority_map[3]), + READ_ONCE(vlan->ingress_priority_map[4]), + READ_ONCE(vlan->ingress_priority_map[5]), + READ_ONCE(vlan->ingress_priority_map[6]), + READ_ONCE(vlan->ingress_priority_map[7])); seq_printf(seq, " EGRESS priority mappings: "); rcu_read_lock(); From ea5bd52c8bdd363823d0d104ebb922d9559a8b11 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:25:32 +0000 Subject: [PATCH 0609/2126] vlan: no longer rely on RTNL in vlan_fill_info() vlan_fill_info() used rcu_dereference_rtnl() to walk the egress priority map, forcing "ip link show" dumps to hold RTNL. The egress priority map is already fully RCU compliant: entries are published with rcu_assign_pointer() and freed with kfree_rcu() from vlan_dev_set_egress_priority() and vlan_dev_free_egress_priority(). Wrap the QoS mapping serialization in rcu_read_lock() / rcu_read_unlock() and use rcu_dereference(). Now that all the involved fields are annotated, use READ_ONCE() for vlan->flags, vlan->nr_ingress_mappings, vlan->nr_egress_mappings and vlan->ingress_priority_map[]. Also add missing const qualifiers in vlan_get_size() and vlan_fill_info(). Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260916132532.1785657-3-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/8021q/vlan_netlink.c | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 71cb98950511..8c0c33cff453 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -209,7 +209,7 @@ static inline size_t vlan_qos_map_size(unsigned int n) static size_t vlan_get_size(const struct net_device *dev) { - struct vlan_dev_priv *vlan = vlan_dev_priv(dev); + const struct vlan_dev_priv *vlan = vlan_dev_priv(dev); return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */ nla_total_size(2) + /* IFLA_VLAN_ID */ @@ -220,60 +220,72 @@ static size_t vlan_get_size(const struct net_device *dev) static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev) { - struct vlan_dev_priv *vlan = vlan_dev_priv(dev); - struct vlan_priority_tci_mapping *pm; - struct ifla_vlan_flags f; + const struct vlan_dev_priv *vlan = vlan_dev_priv(dev); + const struct vlan_priority_tci_mapping *pm; struct ifla_vlan_qos_mapping m; + struct ifla_vlan_flags f; struct nlattr *nest; unsigned int i; + u32 flags; if (nla_put_be16(skb, IFLA_VLAN_PROTOCOL, vlan->vlan_proto) || nla_put_u16(skb, IFLA_VLAN_ID, vlan->vlan_id)) goto nla_put_failure; - if (vlan->flags) { - f.flags = vlan->flags; + + flags = READ_ONCE(vlan->flags); + if (flags) { + f.flags = flags; f.mask = ~0; if (nla_put(skb, IFLA_VLAN_FLAGS, sizeof(f), &f)) goto nla_put_failure; } - if (vlan->nr_ingress_mappings) { + + rcu_read_lock(); + + if (READ_ONCE(vlan->nr_ingress_mappings)) { nest = nla_nest_start_noflag(skb, IFLA_VLAN_INGRESS_QOS); - if (nest == NULL) - goto nla_put_failure; + if (!nest) + goto nla_put_failure_unlock; for (i = 0; i < ARRAY_SIZE(vlan->ingress_priority_map); i++) { - if (!vlan->ingress_priority_map[i]) + u32 skb_prio = READ_ONCE(vlan->ingress_priority_map[i]); + + if (!skb_prio) continue; m.from = i; - m.to = vlan->ingress_priority_map[i]; + m.to = skb_prio; if (nla_put(skb, IFLA_VLAN_QOS_MAPPING, sizeof(m), &m)) - goto nla_put_failure; + goto nla_put_failure_unlock; } nla_nest_end(skb, nest); } - if (vlan->nr_egress_mappings) { + if (READ_ONCE(vlan->nr_egress_mappings)) { nest = nla_nest_start_noflag(skb, IFLA_VLAN_EGRESS_QOS); - if (nest == NULL) - goto nla_put_failure; + if (!nest) + goto nla_put_failure_unlock; for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) { - for (pm = rcu_dereference_rtnl(vlan->egress_priority_map[i]); pm; - pm = rcu_dereference_rtnl(pm->next)) { + for (pm = rcu_dereference(vlan->egress_priority_map[i]); pm; + pm = rcu_dereference(pm->next)) { u16 vlan_qos = READ_ONCE(pm->vlan_qos); + m.from = pm->priority; m.to = (vlan_qos >> 13) & 0x7; if (nla_put(skb, IFLA_VLAN_QOS_MAPPING, sizeof(m), &m)) - goto nla_put_failure; + goto nla_put_failure_unlock; } } nla_nest_end(skb, nest); } + rcu_read_unlock(); return 0; +nla_put_failure_unlock: + rcu_read_unlock(); nla_put_failure: return -EMSGSIZE; } From 41c57cf05068c420553288642443e12b18872ee6 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:28:21 +0000 Subject: [PATCH 0610/2126] hsr: annotate data-race around hsr->sequence_nr hsr->sequence_nr is incremented from the transmit paths under hsr->seqnr_lock, but hsr_fill_info() reads it without holding this lock. Use WRITE_ONCE() in the two writers, so that a matching READ_ONCE() can be used in hsr_fill_info(). Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260916132822.1791040-2-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/hsr/hsr_device.c | 2 +- net/hsr/hsr_forward.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c index d14de44e14b7..fc512204600c 100644 --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -333,7 +333,7 @@ static void send_hsr_supervision_frame(struct hsr_port *port, hsr->sup_sequence_nr++; } else { hsr_stag->sequence_nr = htons(hsr->sequence_nr); - hsr->sequence_nr++; + WRITE_ONCE(hsr->sequence_nr, hsr->sequence_nr + 1); } hsr_stag->tlv.HSR_TLV_type = type; diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c index 7734a521a96c..44f6d9c83180 100644 --- a/net/hsr/hsr_forward.c +++ b/net/hsr/hsr_forward.c @@ -645,7 +645,7 @@ static void handle_std_frame(struct sk_buff *skb, /* Sequence nr for the master/interlink node */ lockdep_assert_held(&hsr->seqnr_lock); frame->sequence_nr = hsr->sequence_nr; - hsr->sequence_nr++; + WRITE_ONCE(hsr->sequence_nr, hsr->sequence_nr + 1); } } From 9f8b888ced9dce2f401c1c4ad8c01b15b7c7dcf5 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 16 Sep 2026 13:28:22 +0000 Subject: [PATCH 0611/2126] hsr: no longer rely on RTNL in hsr_fill_info() hsr_fill_info() used hsr_port_get_hsr(), which walks hsr->ports with hsr_for_each_port_rtnl(), forcing "ip link show" dumps to hold RTNL. hsr->ports is an RCU protected list: ports are added with list_add_tail_rcu(), removed with list_del_rcu() and freed with kfree_rcu(), and the data path already iterates over it with hsr_for_each_port(). Add a local RCU variant of hsr_port_get_hsr() and use it from hsr_fill_info() under rcu_read_lock(). The remaining fields (sup_multicast_addr, prot_version) are set once at device creation. hsr->sequence_nr is now read with READ_ONCE(), since the transmit paths increment it under hsr->seqnr_lock only. Also add missing const qualifiers. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260916132822.1791040-3-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/hsr/hsr_netlink.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c index 88940e8014b2..fc7820eae884 100644 --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -147,44 +147,61 @@ static void hsr_dellink(struct net_device *dev, struct list_head *head) unregister_netdevice_queue(dev, head); } -static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) +/* RCU variant of hsr_port_get_hsr() */ +static struct hsr_port *hsr_port_get_hsr_rcu(const struct hsr_priv *hsr, + enum hsr_port_type pt) { - struct hsr_priv *hsr = netdev_priv(dev); - u8 proto = HSR_PROTOCOL_HSR; struct hsr_port *port; - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); + hsr_for_each_port(hsr, port) + if (port->type == pt) + return port; + return NULL; +} + +static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) +{ + const struct hsr_priv *hsr = netdev_priv(dev); + const struct hsr_port *port; + u8 proto = HSR_PROTOCOL_HSR; + + rcu_read_lock(); + + port = hsr_port_get_hsr_rcu(hsr, HSR_PT_SLAVE_A); if (port) { if (nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex)) goto nla_put_failure; } - port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); + port = hsr_port_get_hsr_rcu(hsr, HSR_PT_SLAVE_B); if (port) { if (nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex)) goto nla_put_failure; } - port = hsr_port_get_hsr(hsr, HSR_PT_INTERLINK); + port = hsr_port_get_hsr_rcu(hsr, HSR_PT_INTERLINK); if (port) { if (nla_put_u32(skb, IFLA_HSR_INTERLINK, port->dev->ifindex)) goto nla_put_failure; } + rcu_read_unlock(); + if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN, hsr->sup_multicast_addr) || - nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr)) - goto nla_put_failure; + nla_put_u16(skb, IFLA_HSR_SEQ_NR, READ_ONCE(hsr->sequence_nr))) + return -EMSGSIZE; if (hsr->prot_version == PRP_V1) proto = HSR_PROTOCOL_PRP; else if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version)) - goto nla_put_failure; + return -EMSGSIZE; if (nla_put_u8(skb, IFLA_HSR_PROTOCOL, proto)) - goto nla_put_failure; + return -EMSGSIZE; return 0; nla_put_failure: + rcu_read_unlock(); return -EMSGSIZE; } From 9f1c440f928307f6e410f9219d67ce04843ccf01 Mon Sep 17 00:00:00 2001 From: Guangshuo Li Date: Wed, 16 Sep 2026 13:31:17 +0800 Subject: [PATCH 0612/2126] net: ionic: free VF resources on remove ionic_probe() allocates VF tracking data and maps a statistics buffer for each already enabled VF with ionic_vf_alloc(). The probe failure path releases these resources with ionic_vf_dealloc(). However, after a successful probe, ionic_remove() tears down the LIF and device without releasing the VF resources. This leaves the VF tracking allocation and statistics DMA mappings behind when the PF driver is removed. Call ionic_vf_dealloc() before deinitializing the LIF so the VF statistics addresses can be cleared and the associated DMA mappings and tracking data released. This issue was found by manual code inspection. Cc: stable+noautosel@kernel.org # untested fix to a driver init path Signed-off-by: Guangshuo Li Link: https://patch.msgid.link/20260916053117.2906446-1-lgs201920130244@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c index 05f19489ec5c..666efe972de7 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c @@ -424,6 +424,7 @@ static void ionic_remove(struct pci_dev *pdev) ionic_auxbus_unregister(ionic->lif); ionic_lif_unregister(ionic->lif); ionic_devlink_unregister(ionic); + ionic_vf_dealloc(ionic); ionic_lif_deinit(ionic->lif); ionic_lif_free(ionic->lif); ionic->lif = NULL; From c2437bf72a371a6b4d4442c3e946187eafae09fc Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 17 Sep 2026 10:17:01 +0800 Subject: [PATCH 0613/2126] selftests: net: update netfilter netlink config Since commit d4349ba9872d ("netfilter: allow nfnetlink built-in only"), NETFILTER_NETLINK was changed to a bool. Use 'y' instead of 'm'. Otherwise the build emits: .config:5688:warning: symbol value 'm' invalid for NETFILTER_NETLINK Signed-off-by: Hangbin Liu Reviewed-by: Fernando Fernandez Mancera Acked-by: Pablo Neira Ayuso Acked-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260917-selftest_config-v1-1-bf25ccbfb18e@kylinos.cn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/mptcp/config | 2 +- tools/testing/selftests/net/netfilter/config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selftests/net/mptcp/config index 59051ee2a986..bb9c4c97c620 100644 --- a/tools/testing/selftests/net/mptcp/config +++ b/tools/testing/selftests/net/mptcp/config @@ -18,7 +18,7 @@ CONFIG_NET_CLS_ACT=y CONFIG_NET_CLS_FW=m CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y -CONFIG_NETFILTER_NETLINK=m +CONFIG_NETFILTER_NETLINK=y CONFIG_NETFILTER_XTABLES=m CONFIG_NETFILTER_XTABLES_LEGACY=y CONFIG_NETFILTER_XT_MATCH_BPF=m diff --git a/tools/testing/selftests/net/netfilter/config b/tools/testing/selftests/net/netfilter/config index c3c121b6f300..629b2b29ed1a 100644 --- a/tools/testing/selftests/net/netfilter/config +++ b/tools/testing/selftests/net/netfilter/config @@ -44,7 +44,7 @@ CONFIG_NET_CLS_U32=m CONFIG_NETDEVSIM=m CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y -CONFIG_NETFILTER_NETLINK=m +CONFIG_NETFILTER_NETLINK=y CONFIG_NETFILTER_NETLINK_QUEUE=m CONFIG_NETFILTER_SYNPROXY=m CONFIG_NETFILTER_XTABLES=m From f619d5003ff4e6e2c1ec456ab3aca5622587b5d7 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Wed, 16 Sep 2026 08:05:22 +0200 Subject: [PATCH 0614/2126] net: phy: factor out legacy PHY fixup support and make it always built-in PHY fixup registration is used from platform code in init phase only. Let's move the PHY fixup code from the modular part of phylib to the always built-in part of phylib. This allows to annotate the fixup registration as __init. No caller uses the return code of PHY fixup registration, therefore change related functions to return void. phy_needs_fixup() and phy_scan_fixups() wouldn't have to be moved to the built-in part of phylib. But doing so allows to fully factor out legacy fixup support into its own source code file, and make struct phy_fixup and phy_fixup_list strictly private to phy_fixup.c. phy_scan_fixups() is used after init phase only, then phy_fixup_list is read-only. So we don't need the mutex when accessing the list. Also when registering PHY fixups the mutex isn't needed, because fixup registration is done sequentially from platform init code. Actually there is only one platform with more than one fixup. In addition this change lays the foundation for enabling modular phylib on platforms where the fixup just sets a flag. Last but not least reflect the change in the documentation, and add a hint that fixup's are legacy functionality. Reviewed-by: Andrew Lunn Signed-off-by: Heiner Kallweit Link: https://patch.msgid.link/2d722b84-a263-400b-ac91-bf37125eb85b@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/phy.rst | 17 +++--- drivers/net/phy/Makefile | 2 +- drivers/net/phy/phy_device.c | 90 ---------------------------- drivers/net/phy/phy_fixup.c | 98 +++++++++++++++++++++++++++++++ drivers/net/phy/phylib-internal.h | 1 + include/linux/phy.h | 8 +-- 6 files changed, 114 insertions(+), 102 deletions(-) create mode 100644 drivers/net/phy/phy_fixup.c diff --git a/Documentation/networking/phy.rst b/Documentation/networking/phy.rst index 0170c9d4dc5e..d53067ab1a61 100644 --- a/Documentation/networking/phy.rst +++ b/Documentation/networking/phy.rst @@ -511,24 +511,27 @@ Board Fixups Sometimes the specific interaction between the platform and the PHY requires special handling. For instance, to change where the PHY's clock input is, or to add a delay to account for latency issues in the data path. In order -to support such contingencies, the PHY Layer allows platform code to register -fixups to be run when the PHY is brought up (or subsequently reset). +to support such contingencies, the PHY Layer allows platform init code to +register fixups to be run when the PHY is brought up (or subsequently reset). + +Note: This is legacy functionality and not supposed to be used in new code. + Fixup's should be handled in the PHY driver. When the PHY Layer brings up a PHY it checks to see if there are any fixups registered for it, matching based on UID (contained in the PHY device's phy_id field) and the bus identifier (contained in phydev->dev.bus_id). Both must -match, however two constants, PHY_ANY_ID and PHY_ANY_UID, are provided as -wildcards for the bus ID and UID, respectively. +match, however NULL for the bus identifier and 0 for phy_uid_mask can be +used to disable the respective type of matching. When a match is found, the PHY layer will invoke the run function associated with the fixup. This function is passed a pointer to the phy_device of -interest. It should therefore only operate on that PHY. +interest. It should therefore only operate on that PHY. The platform code can register the fixup using one of:: - int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, + void __init phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, int (*run)(struct phy_device *)); - int phy_register_fixup_for_id(const char *phy_id, + void __init phy_register_fixup_for_id(const char *phy_id, int (*run)(struct phy_device *)); Standards diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 49575fa18522..579066a638f0 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -8,7 +8,7 @@ libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \ ifdef CONFIG_PHYLIB # built-in whenever PHYLIB is built-in or module -obj-y += stubs.o +obj-y += stubs.o phy_fixup.o endif libphy-$(CONFIG_SWPHY) += swphy.o diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 41d1b20cde2c..5b13a74e2fa9 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -49,14 +49,6 @@ MODULE_DESCRIPTION("PHY library"); MODULE_AUTHOR("Andy Fleming"); MODULE_LICENSE("GPL"); -struct phy_fixup { - struct list_head list; - char bus_id[MII_BUS_ID_SIZE + 3]; - u32 phy_uid; - u32 phy_uid_mask; - int (*run)(struct phy_device *phydev); -}; - static struct phy_driver genphy_c45_driver = { .phy_id = 0xffffffff, .phy_id_mask = 0xffffffff, @@ -237,9 +229,6 @@ static void phy_mdio_device_remove(struct mdio_device *mdiodev) static struct phy_driver genphy_driver; -static LIST_HEAD(phy_fixup_list); -static DEFINE_MUTEX(phy_fixup_lock); - static bool phy_drv_wol_enabled(struct phy_device *phydev) { struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; @@ -427,85 +416,6 @@ no_resume: static SIMPLE_DEV_PM_OPS(mdio_bus_phy_pm_ops, mdio_bus_phy_suspend, mdio_bus_phy_resume); -/** - * phy_register_fixup - creates a new phy_fixup and adds it to the list - * @bus_id: A string which matches phydev->mdio.dev.bus_id (or NULL) - * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) - * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before - * comparison (or 0 to disable id-based matching) - * @run: The actual code to be run when a matching PHY is found - */ -static int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, - int (*run)(struct phy_device *)) -{ - struct phy_fixup *fixup = kzalloc_obj(*fixup); - - if (!fixup) - return -ENOMEM; - - if (bus_id) - strscpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); - fixup->phy_uid = phy_uid; - fixup->phy_uid_mask = phy_uid_mask; - fixup->run = run; - - mutex_lock(&phy_fixup_lock); - list_add_tail(&fixup->list, &phy_fixup_list); - mutex_unlock(&phy_fixup_lock); - - return 0; -} - -/* Registers a fixup to be run on any PHY with the UID in phy_uid */ -int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, - int (*run)(struct phy_device *)) -{ - return phy_register_fixup(NULL, phy_uid, phy_uid_mask, run); -} -EXPORT_SYMBOL(phy_register_fixup_for_uid); - -/* Registers a fixup to be run on the PHY with id string bus_id */ -int phy_register_fixup_for_id(const char *bus_id, - int (*run)(struct phy_device *)) -{ - return phy_register_fixup(bus_id, 0, 0, run); -} -EXPORT_SYMBOL(phy_register_fixup_for_id); - -static bool phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) -{ - if (!strcmp(fixup->bus_id, phydev_name(phydev))) - return true; - - if (fixup->phy_uid_mask && - phy_id_compare(phydev->phy_id, fixup->phy_uid, fixup->phy_uid_mask)) - return true; - - return false; -} - -/* Runs any matching fixups for this phydev */ -static int phy_scan_fixups(struct phy_device *phydev) -{ - struct phy_fixup *fixup; - - mutex_lock(&phy_fixup_lock); - list_for_each_entry(fixup, &phy_fixup_list, list) { - if (phy_needs_fixup(phydev, fixup)) { - int err = fixup->run(phydev); - - if (err < 0) { - mutex_unlock(&phy_fixup_lock); - return err; - } - phydev->has_fixups = true; - } - } - mutex_unlock(&phy_fixup_lock); - - return 0; -} - /** * genphy_match_phy_device - match a PHY device with a PHY driver * @phydev: target phy_device struct diff --git a/drivers/net/phy/phy_fixup.c b/drivers/net/phy/phy_fixup.c new file mode 100644 index 000000000000..75ed9b142ccc --- /dev/null +++ b/drivers/net/phy/phy_fixup.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * PHY fixup support + */ + +#include +#include +#include +#include + +#include "phylib-internal.h" + +static struct list_head phy_fixup_list __ro_after_init = + LIST_HEAD_INIT(phy_fixup_list); + +struct phy_fixup { + struct list_head list; + char bus_id[MII_BUS_ID_SIZE + 3]; + u32 phy_uid; + u32 phy_uid_mask; + int (*run)(struct phy_device *phydev); +}; + +/** + * phy_register_fixup - creates a new phy_fixup and adds it to the list + * @bus_id: A string which matches phydev->mdio.dev.bus_id (or NULL) + * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) + * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before + * comparison (or 0 to disable id-based matching) + * @run: The actual code to be run when a matching PHY is found + */ +static void __init phy_register_fixup(const char *bus_id, u32 phy_uid, + u32 phy_uid_mask, + int (*run)(struct phy_device *)) +{ + struct phy_fixup *fixup = kzalloc_obj(*fixup); + + if (!fixup) + return; + + if (bus_id) + strscpy(fixup->bus_id, bus_id); + fixup->phy_uid = phy_uid; + fixup->phy_uid_mask = phy_uid_mask; + fixup->run = run; + + list_add_tail(&fixup->list, &phy_fixup_list); +} + +/* Registers a fixup to be run on any PHY with the UID in phy_uid */ +void __init phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, + int (*run)(struct phy_device *)) +{ + phy_register_fixup(NULL, phy_uid, phy_uid_mask, run); +} + +/* Registers a fixup to be run on the PHY with id string bus_id */ +void __init phy_register_fixup_for_id(const char *bus_id, + int (*run)(struct phy_device *)) +{ + phy_register_fixup(bus_id, 0, 0, run); +} + +static bool phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) +{ + if (!strcmp(fixup->bus_id, phydev_name(phydev))) + return true; + + if (fixup->phy_uid_mask && + phy_id_compare(phydev->phy_id, fixup->phy_uid, fixup->phy_uid_mask)) + return true; + + return false; +} + +/** + * phy_scan_fixups - runs any matching fixups for this phydev + * @phydev: the phydev to search and run fixups for + * Returns: 0 or an errno + */ +int phy_scan_fixups(struct phy_device *phydev) +{ + struct phy_fixup *fixup; + + list_for_each_entry(fixup, &phy_fixup_list, list) { + if (phy_needs_fixup(phydev, fixup)) { + int err = fixup->run(phydev); + + if (err < 0) + return err; + + phydev->has_fixups = true; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(phy_scan_fixups); diff --git a/drivers/net/phy/phylib-internal.h b/drivers/net/phy/phylib-internal.h index 664ed7faa518..38ee294f3c96 100644 --- a/drivers/net/phy/phylib-internal.h +++ b/drivers/net/phy/phylib-internal.h @@ -23,6 +23,7 @@ void of_set_phy_eee_broken(struct phy_device *phydev); void of_set_phy_timing_role(struct phy_device *phydev); int phy_speed_down_core(struct phy_device *phydev); void phy_check_downshift(struct phy_device *phydev); +int phy_scan_fixups(struct phy_device *phydev); int mdiobus_register_device(struct mdio_device *mdiodev); int mdiobus_unregister_device(struct mdio_device *mdiodev); diff --git a/include/linux/phy.h b/include/linux/phy.h index 3d8afe6b7f1c..257634a543a1 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2440,10 +2440,10 @@ int phy_get_mac_termination(struct phy_device *phydev, struct device *dev, void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv, bool *tx_pause, bool *rx_pause); -int phy_register_fixup_for_id(const char *bus_id, - int (*run)(struct phy_device *)); -int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, - int (*run)(struct phy_device *)); +void __init phy_register_fixup_for_id(const char *bus_id, + int (*run)(struct phy_device *)); +void __init phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, + int (*run)(struct phy_device *)); int phy_eee_tx_clock_stop_capable(struct phy_device *phydev); int phy_eee_rx_clock_stop(struct phy_device *phydev, bool clk_stop_enable); From d4f90143b9ffdac1fae765354b72366ad6c5ce65 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Thu, 17 Sep 2026 08:30:51 +0200 Subject: [PATCH 0615/2126] net: phy: Fix device_set_wakeup_enable() reference in kernel-doc The phy_may_wakeup() documentation refers to device_set_wakeup_enabled(), but the function is named device_set_wakeup_enable(). Correct the reference. Signed-off-by: Karl Mehltretter Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Link: https://patch.msgid.link/20260917063051.52727-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- include/linux/phy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/phy.h b/include/linux/phy.h index 257634a543a1..7c5098a0dd6c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1715,7 +1715,7 @@ static inline bool phy_can_wakeup(struct phy_device *phydev) * phy_may_wakeup() - indicate whether PHY has wakeup enabled * @phydev: The phy_device struct * - * Returns: true/false depending on the PHY driver's device_set_wakeup_enabled() + * Returns: true/false depending on the PHY driver's device_set_wakeup_enable() * setting if using the driver model, otherwise the legacy determination. */ bool phy_may_wakeup(struct phy_device *phydev); From 404381b4f1053a271a85679cc76a543b10ae043e Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 17 Sep 2026 19:15:52 +0000 Subject: [PATCH 0616/2126] tcp: Set unhashed_state in inet_twsk_hashdance_schedule(). inet_unhash() sets inet_csk(sk)->unhashed_state only when the socket is hashed because tcp_set_state(sk, TCP_CLOSE) could be called multiple times, e.g. tcp_abort() calls it directly and tcp_done_with_error(). However, inet_twsk_hashdance_schedule() also unhashes a socket when replacing it with twsk, allowing the socket to bypass checks for inet_csk(sk)->unhashed_state. Let's update inet_csk(sk)->unhashed_state there as well. Fixes: 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between ehash and lhash2.") Reported-by: Daniel Zahka Closes: https://lore.kernel.org/netdev/DLHLRA8GVI5B.2Q1IRQG5BVJNZ@gmail.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Daniel Zahka Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260917191554.1600494-1-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv4/inet_timewait_sock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index d4c781a0667f..a1d86026aefb 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -105,10 +105,12 @@ void inet_twsk_hashdance_schedule(struct inet_timewait_sock *tw, struct inet_hashinfo *hashinfo, int timeo) { - const struct inet_sock *inet = inet_sk(sk); - const struct inet_connection_sock *icsk = inet_csk(sk); spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash); + struct inet_connection_sock *icsk = inet_csk(sk); struct inet_bind_hashbucket *bhead, *bhead2; + const struct inet_sock *inet = inet_sk(sk); + + icsk->unhashed_state = sk->sk_state; /* Put TW into bind hash. Original socket stays there too. * Note, that any socket with inet->num != 0 MUST be bound in From 7a5e75f649165296b72c151ad0629246806378be Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 16 Sep 2026 12:20:58 +0200 Subject: [PATCH 0617/2126] dt-bindings: net: dsa: microchip: Add KSZ8995XA The KSZ8995XA is just like the KSZ8795 and KSZ8864 a Micrel product. It was renamed from KS8995XA to KSZ8995XA at some point, but it has the same properties as the KS8995XA. Be careful to use the full product name in this new compatible: there is also KSZ8995MA and KSZ8995E which are not compatible with the KS8995XA. Acked-by: Krzysztof Kozlowski Reviewed-by: Nicolai Buchwitz Signed-off-by: Linus Walleij Link: https://patch.msgid.link/20260916-ks8995-to-ksz8-v15-1-8825ff5fd4be@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml b/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml index 8d4a3a9a33fc..4ed13870ed3a 100644 --- a/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +++ b/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml @@ -23,6 +23,7 @@ properties: - microchip,ksz8864 # 4-port version of KSZ8895 family switch - microchip,ksz8873 - microchip,ksz8895 # 5-port version of KSZ8895 family switch + - microchip,ksz8995xa - microchip,ksz9477 - microchip,ksz9897 - microchip,ksz9896 From ca30cd47fe7fd1a7eabf6ec120b8d142cfd7eeef Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 16 Sep 2026 12:20:59 +0200 Subject: [PATCH 0618/2126] net: dsa: tag_ks8995: Add the KS8995 tag handling The KS8995 100Mbit switch can do proper DSA per-port tagging with the proper set-up. This adds the code to handle ingress and egress KS8995 tags. The tagger is used by the KSZ8995XA support added later in this series. The tag is a modified 0x8100 ethertype tag where a bit in the last nibble is set for each target port. Always insert a distinct outer switch tag. User ports remove this field on egress, so reusing an existing 802.1Q header would consume the sender VLAN tag instead of preserving it. Push any hardware-accelerated VLAN tag into the packet first. This keeps the switch tag at offset 12 while retaining 802.1Q, 802.1ad and stacked VLAN headers as inner payload, and avoids relying on a valid SKB MAC header in direct transmit paths. Rate-limit receive untagging errors so repeated failures cannot flood the kernel log. Reviewed-by: Nicolai Buchwitz Signed-off-by: Linus Walleij Link: https://patch.msgid.link/20260916-ks8995-to-ksz8-v15-2-8825ff5fd4be@kernel.org Signed-off-by: Jakub Kicinski --- MAINTAINERS | 1 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 ++ net/dsa/Makefile | 1 + net/dsa/tag_ks8995.c | 180 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 net/dsa/tag_ks8995.c diff --git a/MAINTAINERS b/MAINTAINERS index cae5962045dd..d1a3ec390096 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17772,6 +17772,7 @@ F: Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml F: drivers/net/dsa/microchip/* F: include/linux/dsa/ksz_common.h F: include/linux/platform_data/microchip-ksz.h +F: net/dsa/tag_ks8995.c F: net/dsa/tag_ksz.c MICROCHIP LAN743X ETHERNET DRIVER diff --git a/include/net/dsa.h b/include/net/dsa.h index 7507d632e7c6..5d12191b6f6f 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -61,6 +61,7 @@ struct tc_action; #define DSA_TAG_PROTO_NETC_VALUE 33 #define DSA_TAG_PROTO_KSZ8463_VALUE 34 #define DSA_TAG_PROTO_MT7628_VALUE 35 +#define DSA_TAG_PROTO_KS8995_VALUE 36 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -99,6 +100,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_NETC = DSA_TAG_PROTO_NETC_VALUE, DSA_TAG_PROTO_KSZ8463 = DSA_TAG_PROTO_KSZ8463_VALUE, DSA_TAG_PROTO_MT7628 = DSA_TAG_PROTO_MT7628_VALUE, + DSA_TAG_PROTO_KS8995 = DSA_TAG_PROTO_KS8995_VALUE, }; struct dsa_switch; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index 23b4b74004ed..4f44bf3ede23 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -125,6 +125,12 @@ config NET_DSA_TAG_MXL_GSW1XX Say Y or M if you want to enable support for tagging frames for MaxLinear GSW1xx switches. +config NET_DSA_TAG_KS8995 + tristate "Tag driver for Micrel KS8995 switch" + help + Say Y if you want to enable support for tagging frames for the + Micrel KS8995 switch. + config NET_DSA_TAG_KSZ tristate "Tag driver for Microchip 8795/937x/9477/9893 families of switches" help diff --git a/net/dsa/Makefile b/net/dsa/Makefile index d15bcf5c68f0..1f9cc30e9988 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_NET_DSA_TAG_BRCM_COMMON) += tag_brcm.o obj-$(CONFIG_NET_DSA_TAG_DSA_COMMON) += tag_dsa.o obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o +obj-$(CONFIG_NET_DSA_TAG_KS8995) += tag_ks8995.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o obj-$(CONFIG_NET_DSA_TAG_MT7628) += tag_mt7628.o diff --git a/net/dsa/tag_ks8995.c b/net/dsa/tag_ks8995.c new file mode 100644 index 000000000000..f011bf01845e --- /dev/null +++ b/net/dsa/tag_ks8995.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026 Linus Walleij + */ +#include +#include +#include +#include +#include +#include + +#include "tag.h" + +/* The Micrel KS8995XA / Microchip KSZ8995XA Special Tag Packet ID (STPID) + * pushes its tag in a modified VLAN (802.1Q) tag. + * ----------------------------------------------------------- + * | MAC DA | MAC SA | 2 bytes tag | 2 bytes TCI | EtherType | + * ----------------------------------------------------------- + * The tag is: 0x8100 |= BIT(port), ports 0,1,2,3 + */ + +#define KS8995_NAME "ks8995" + +#define KS8995_TAG_LEN VLAN_HLEN +/* Reserve room for the switch tag and a hardware-accelerated VLAN tag. */ +#define KS8995_NEEDED_HEADROOM (KS8995_TAG_LEN + VLAN_HLEN) + +#define KS8995M_STPID_STD GENMASK(15, 4) +#define KS8995M_STPID_PORTMASK GENMASK(3, 0) +#define KS8995M_STPID(portmask) htons(ETH_P_8021Q | FIELD_PREP(KS8995M_STPID_PORTMASK, portmask)) + +static struct sk_buff *ks8995_xmit(struct sk_buff *skb, struct net_device *dev) +{ + struct vlan_ethhdr *hdr; + u16 portmask; + + /* VLAN insertion requires a complete, linear Ethernet header. */ + if (unlikely(!pskb_may_pull(skb, ETH_HLEN))) { + kfree_skb(skb); + return NULL; + } + + /* Prepare the special KS8995 tags */ + portmask = dsa_xmit_port_mask(skb, dev); + + /* The switch expects the special tag at offset 12. Move any hardware + * accelerated VLAN tag into the payload so the conduit cannot insert + * it outside the special tag. + */ + if (unlikely(skb_vlan_tag_present(skb))) { + skb = __vlan_hwaccel_push_inside(skb); + if (!skb) + return NULL; + } + + /* Always add a distinct outer tag. The user port removes this field on + * egress, so reusing an existing 802.1Q tag would consume that VLAN tag. + */ + skb = vlan_insert_tag(skb, KS8995M_STPID(portmask), 0); + /* vlan_insert_tag() drops the skb on failure */ + if (!skb) + return NULL; + hdr = skb_vlan_eth_hdr(skb); + netdev_dbg(dev, "%s: inserted VLAN TAG %04x TCI %04x\n", + __func__, ntohs(hdr->h_vlan_proto), + ntohs(hdr->h_vlan_TCI)); + + return skb; +} + +static struct sk_buff *ks8995_rcv(struct sk_buff *skb, struct net_device *dev) +{ + int portmask; + int port; + u16 etype; + + /* The special tag may be in the packet or VLAN metadata. In either + * case, its TPID must retain the source-port bits. + * + * Read the in-band TPID directly because skb->protocol contains + * ETH_P_XDSA. + */ + if (skb_vlan_tag_present(skb)) + etype = ntohs(skb->vlan_proto); + else + etype = ntohs(*(__be16 *)dsa_etype_header_pos_rx(skb)); + if ((etype & KS8995M_STPID_STD) != ETH_P_8021Q) { + netdev_dbg(dev, "%s: dropped ethertype 0x%04x\n", + __func__, etype); + kfree_skb(skb); + return NULL; + } + + portmask = FIELD_GET(KS8995M_STPID_PORTMASK, etype); + if (unlikely(!is_power_of_2(portmask))) { + netdev_dbg(dev, "%s: dropped invalid port mask 0x%04x\n", + __func__, portmask); + kfree_skb(skb); + return NULL; + } + port = ilog2(portmask); + + netdev_dbg(dev, "%s: received ethertype %04x\n", + __func__, etype); + + /* Move an in-band special tag into VLAN metadata. If already + * offloaded, its TPID was validated above. + */ + if (!skb_vlan_tag_present(skb)) { + skb = skb_vlan_untag(skb); + if (!skb) { + /* skb_vlan_untag drops the skb on failure */ + if (net_ratelimit()) + netdev_err(dev, "%s: unable to untag skb\n", __func__); + return NULL; + } + } + + netdev_dbg(dev, "%s: etype %04x portmask %04x (%d)\n", + __func__, etype, portmask, port); + skb->dev = dsa_conduit_find_user(dev, 0, port); + if (!skb->dev) { + kfree_skb(skb); + return NULL; + } + + /* The special tag's TCI is now in the hardware-accelerated VLAN + * metadata. The switch preserves the TCI of tagged + * frames, but inserts the ingress port's default tag for untagged frames. + * Since the driver programs the default tag to 0, a zero TCI identifies + * an originally untagged frame. Preserve every non-zero TCI as an + * 802.1Q tag, including VID 0 frames with PCP or DEI set. + */ + if (!skb->vlan_tci) { + netdev_dbg(dev, "%s: clear VLAN tag from frame\n", __func__); + __vlan_hwaccel_clear_tag(skb); + } else { + skb->vlan_proto = htons(ETH_P_8021Q); + netdev_dbg(dev, "%s: vlan_tci = 0x%04x VLAN frame\n", + __func__, skb->vlan_tci); + } + + dsa_default_offload_fwd_mark(skb); + + return skb; +} + +static void ks8995_flow_dissect(const struct sk_buff *skb, __be16 *proto, + int *offset) +{ + const __be16 *encap_proto; + __be16 buffer; + + *proto = 0; + *offset = 0; + + /* Extra TX headroom does not increase the in-band RX tag length. */ + encap_proto = skb_header_pointer(skb, KS8995_TAG_LEN - sizeof(buffer), + sizeof(buffer), &buffer); + if (!encap_proto) + return; + + *proto = *encap_proto; + *offset = KS8995_TAG_LEN; +} + +static const struct dsa_device_ops ks8995_netdev_ops = { + .name = KS8995_NAME, + .proto = DSA_TAG_PROTO_KS8995, + .xmit = ks8995_xmit, + .rcv = ks8995_rcv, + .flow_dissect = ks8995_flow_dissect, + .needed_headroom = KS8995_NEEDED_HEADROOM, +}; + +MODULE_DESCRIPTION("DSA tag driver for Micrel KS8995 family of switches"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KS8995, KS8995_NAME); + +module_dsa_tag_driver(ks8995_netdev_ops); From a926dc2352a9bac233baa2aaf7cd6031bbb74842 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 16 Sep 2026 12:21:00 +0200 Subject: [PATCH 0619/2126] net: dsa: microchip: Support Microchip KSZ8995XA / KS8995XA This adds support for the Microchip KSZ8995XA also known as the Micrel KS8995XA switch to the KSZ driver. The KSZ8995XA shares family ID 0x95 and chip-ID nibble 0x0 with the KS8995MA, so hardware detection cannot distinguish them. The legacy "micrel,ks8995" compatible is therefore treated as KSZ8995XA. No KS8995MA users are known, and KS8995E has no documented SPI management interface. Neither MA nor E has been verified with this driver. The helper macros are named ksz_is_ksz8995xa() to make it possible to add E and MA support in the future. Wait for the self-clearing per-port PHY reset bits before continuing with switch setup. Poll each port for up to 600 ms and allow an additional millisecond for the PHYs to settle. The KSZ8995XA has eight global TOS priority registers with one bit per DSCP code point, providing two internal priority levels. The registers are ordered in the opposite direction from the other KSZ8 switches. Describe the two priorities in the chip data, then augment the DCB helpers for this. Practical testing also shows that its packet-size control bits use the same semantics as the other KSZ8 switches. The polarity in the manual appears to be wrong and makes the switch hang on big packets. The legacy KS8995 driver also matches the Micrel compatibles for KSZ8864 and KSZ8795. Add these to the KSZ SPI driver here and use an exact tristate dependency to make the drivers mutually exclusive. This transfers ownership atomically, avoiding module probe races and gaps in driver coverage between patches. Reviewed-by: Nicolai Buchwitz Signed-off-by: Linus Walleij Link: https://patch.msgid.link/20260916-ks8995-to-ksz8-v15-3-8825ff5fd4be@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/Kconfig | 1 + drivers/net/dsa/microchip/Kconfig | 1 + drivers/net/dsa/microchip/ksz8.c | 252 ++++++++++++++++---- drivers/net/dsa/microchip/ksz8.h | 2 + drivers/net/dsa/microchip/ksz8_reg.h | 2 + drivers/net/dsa/microchip/ksz_common.c | 53 +++- drivers/net/dsa/microchip/ksz_common.h | 11 +- drivers/net/dsa/microchip/ksz_dcb.c | 68 ++++-- drivers/net/dsa/microchip/ksz_spi.c | 33 ++- include/linux/platform_data/microchip-ksz.h | 1 + 10 files changed, 353 insertions(+), 71 deletions(-) diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 8d8edcf89f10..e3d88f41fecf 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -112,6 +112,7 @@ config NET_DSA_RZN1_A5PSW config NET_DSA_KS8995 tristate "Micrel KS8995 family 5-ports 10/100 Ethernet switches" depends on SPI + depends on NET_DSA_MICROCHIP_KSZ_SPI = n select NET_DSA_TAG_NONE help This driver supports the Micrel KS8995 family of 10/100 Mbit ethernet diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig index c71d3fd5dfeb..75c9b2114afd 100644 --- a/drivers/net/dsa/microchip/Kconfig +++ b/drivers/net/dsa/microchip/Kconfig @@ -2,6 +2,7 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON tristate "Microchip KSZ8XXX/KSZ9XXX/LAN937X series switch support" depends on NET_DSA + select NET_DSA_TAG_KS8995 select NET_DSA_TAG_KSZ select NET_DSA_TAG_NONE select NET_IEEE8021Q_HELPERS diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 941ae9f66f70..d7498132064e 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -3,6 +3,7 @@ * Microchip KSZ8XXX series switch driver * * It supports the following switches: + * - KSZ8995XA (the oldest ancestor) * - KSZ8463 * - KSZ8863, KSZ8873 aka KSZ88X3 * - KSZ8895, KSZ8864 aka KSZ8895 family @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -253,7 +255,35 @@ static int ksz8463_reset_switch(struct ksz_device *dev) static int ksz8_reset_switch(struct ksz_device *dev) { - if (ksz_is_ksz88x3(dev)) { + if (ksz_is_ksz8995xa(dev)) { + unsigned int port, reg, val; + int ret; + + /* The KSZ8995XA switch itself cannot be reset by software, but + * often boot loaders have fun with ports, so reset them. This + * reset bit is self-clearing. + */ + for (port = 0; port < dev->info->port_cnt; port++) { + ret = ksz_prmw8(dev, port, REG_PORT_STATUS_3, + PORT_PHY_SOFT_RESET, + PORT_PHY_SOFT_RESET); + if (ret) + return ret; + } + + /* IEEE 802.3 allows up to 500 ms for a PHY reset. */ + for (port = 0; port < dev->info->port_cnt; port++) { + reg = dev->dev_ops->get_port_addr(port, REG_PORT_STATUS_3); + ret = regmap_read_poll_timeout(ksz_regmap_8(dev), reg, val, + !(val & PORT_PHY_SOFT_RESET), + 1000, 600000); + if (ret) + return ret; + } + + /* Some PHYs need additional settling time after reset. */ + usleep_range(1000, 2000); + } else if (ksz_is_ksz88x3(dev)) { /* reset switch */ ksz_cfg(dev, KSZ8863_REG_SW_RESET, KSZ8863_GLOBAL_SOFTWARE_RESET | KSZ8863_PCS_RESET, true); @@ -269,6 +299,31 @@ static int ksz8_reset_switch(struct ksz_device *dev) return 0; } +static int ksz8995xa_change_mtu(struct dsa_switch *ds, int port, int mtu) +{ + struct ksz_device *dev = ds->priv; + int frame_size; + u8 ctrl2 = 0; + + if (!dsa_is_cpu_port(dev->ds, port)) + return 0; + + frame_size = mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; + + /* The legal packet size bit polarity documented in the KSZ8995XA + * manual appears to be wrong. Practical tests show that the same + * semantics as the other switches are correct; using the documented + * polarity makes the switch hang on big packets. + */ + if (frame_size <= KSZ8995XA_LEGAL_PACKET_SIZE) + ctrl2 |= KSZ8863_LEGAL_PACKET_ENABLE; + else if (frame_size > KSZ8863_NORMAL_PACKET_SIZE) + ctrl2 |= KSZ8863_HUGE_PACKET_ENABLE; + + return ksz_rmw8(dev, REG_SW_CTRL_2, KSZ8863_LEGAL_PACKET_ENABLE | + KSZ8863_HUGE_PACKET_ENABLE, ctrl2); +} + static int ksz88xx_change_mtu(struct dsa_switch *ds, int port, int mtu) { struct ksz_device *dev = ds->priv; @@ -325,8 +380,8 @@ static int ksz88xx_max_mtu(struct dsa_switch *ds, int port) static int ksz8_port_queue_split(struct ksz_device *dev, int port, int queues) { - u8 mask_4q, mask_2q; - u8 reg_4q, reg_2q; + u8 mask_4q = 0, mask_2q; + u8 reg_4q = 0, reg_2q; u8 data_4q = 0; u8 data_2q = 0; int ret; @@ -352,6 +407,10 @@ static int ksz8_port_queue_split(struct ksz_device *dev, int port, int queues) mask_2q = KSZ8873_PORT_2QUEUE_SPLIT_EN; reg_4q = P1CR1; reg_2q = P1CR1 + 1; + } else if (ksz_is_ksz8995xa(dev)) { + /* This switch has no 4way split support */ + mask_2q = KSZ8795_PORT_2QUEUE_SPLIT_EN; + reg_2q = REG_PORT_CTRL_0; } else { mask_4q = KSZ8795_PORT_4QUEUE_SPLIT_EN; mask_2q = KSZ8795_PORT_2QUEUE_SPLIT_EN; @@ -373,9 +432,11 @@ static int ksz8_port_queue_split(struct ksz_device *dev, int port, int queues) else if (queues == 2) data_2q = mask_2q; - ret = ksz_prmw8(dev, port, reg_4q, mask_4q, data_4q); - if (ret) - return ret; + if (mask_4q) { + ret = ksz_prmw8(dev, port, reg_4q, mask_4q, data_4q); + if (ret) + return ret; + } return ksz_prmw8(dev, port, reg_2q, mask_2q, data_2q); } @@ -970,6 +1031,10 @@ static int ksz8_r_phy_ctrl(struct ksz_device *dev, int port, u16 *val) if (reg_val & PORT_MDIX_STATUS) *val |= KSZ886X_CTRL_MDIX_STAT; + /* KSZ8995XA has no fancy features in register 0xA */ + if (ksz_is_ksz8995xa(dev)) + return 0; + ret = ksz_pread8(dev, port, REG_PORT_LINK_MD_CTRL, ®_val); if (ret < 0) return ret; @@ -1068,8 +1133,10 @@ static int ksz8_r_phy_bmcr(struct ksz_device *dev, u16 port, u16 *val) if (ctrl & PORT_FORCE_FULL_DUPLEX) *val |= BMCR_FULLDPLX; - if (speed & PORT_HP_MDIX) - *val |= KSZ886X_BMCR_HP_MDIX; + if (!ksz_is_ksz8995xa(dev)) { + if (speed & PORT_HP_MDIX) + *val |= KSZ886X_BMCR_HP_MDIX; + } if (restart & PORT_FORCE_MDIX) *val |= KSZ886X_BMCR_FORCE_MDI; @@ -1164,6 +1231,9 @@ static int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) data |= LPA_LPACK; break; case PHY_REG_LINK_MD: + if (ksz_is_ksz8995xa(dev)) + return -EOPNOTSUPP; + ret = ksz_pread8(dev, p, REG_PORT_LINK_MD_CTRL, &val1); if (ret) return ret; @@ -1307,13 +1377,15 @@ static int ksz8_w_phy_bmcr(struct ksz_device *dev, u16 port, u16 val) if (val & BMCR_RESET) return 0; - speed = 0; - if (val & KSZ886X_BMCR_HP_MDIX) - speed |= PORT_HP_MDIX; + if (!ksz_is_ksz8995xa(dev)) { + speed = 0; + if (val & KSZ886X_BMCR_HP_MDIX) + speed |= PORT_HP_MDIX; - ret = ksz_prmw8(dev, port, regs[P_SPEED_STATUS], PORT_HP_MDIX, speed); - if (ret) - return ret; + ret = ksz_prmw8(dev, port, regs[P_SPEED_STATUS], PORT_HP_MDIX, speed); + if (ret) + return ret; + } ctrl = 0; if (ksz_is_ksz88x3(dev)) { @@ -1423,11 +1495,17 @@ static int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) } break; case PHY_REG_LINK_MD: + if (ksz_is_ksz8995xa(dev)) + return -EOPNOTSUPP; + if (val & PHY_START_CABLE_DIAG) ksz_port_cfg(dev, p, REG_PORT_LINK_MD_CTRL, PORT_START_CABLE_DIAG, true); break; case PHY_REG_PHY_CTRL: + if (ksz_is_ksz8995xa(dev)) + return -EOPNOTSUPP; + ret = ksz8_w_phy_ctrl(dev, p, val); if (ret) return ret; @@ -1527,8 +1605,18 @@ static void ksz8_flush_dyn_mac_table(struct dsa_switch *ds, int port) if (ksz_is_ksz8463(dev)) { reg = KSZ8463_FLUSH_TABLE_CTRL; mask = KSZ8463_FLUSH_DYN_MAC_TABLE; + } else if (ksz_is_ksz8995xa(dev)) { + reg = REG_SW_CTRL_1; + mask = SW_FAST_AGING; } ksz_cfg(dev, reg, mask, true); + if (ksz_is_ksz8995xa(dev)) { + /* Allow the 800 us fast-age cycle to finish before restoring + * normal ageing and port learning. + */ + usleep_range(1000, 2000); + ksz_cfg(dev, reg, mask, false); + } for (index = first; index < cnt; index++) { if (!(learn[index] & PORT_LEARN_DISABLE)) ksz_pwrite8(dev, index, regs[P_STP_CTRL], learn[index]); @@ -2043,12 +2131,14 @@ static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) ksz8_port_queue_split(dev, port, dev->info->num_tx_queues); - /* replace priority */ - offset = P_802_1P_CTRL; - if (ksz_is_ksz8463(dev)) - offset = P1CR2; - ksz_port_cfg(dev, port, offset, - masks[PORT_802_1P_REMAPPING], false); + if (!ksz_is_ksz8995xa(dev)) { + /* replace priority */ + offset = P_802_1P_CTRL; + if (ksz_is_ksz8463(dev)) + offset = P1CR2; + ksz_port_cfg(dev, port, offset, + masks[PORT_802_1P_REMAPPING], false); + } if (cpu_port) member = dsa_user_ports(ds); @@ -2057,6 +2147,20 @@ static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) ksz8_cfg_port_member(dev, port, member); + if (ksz_is_ksz8995xa(dev)) { + /* Use VID 0 to identify untagged frames in the special tag */ + ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, 0); + + /* The KSZ8995XA has a special tag format in the front of the frame + * that need to be inserted by the CPU and then removed by each + * port. PORT_REMOVE_TAG simply means "remove tags coming from the + * CPU port" it does not affect ingress packets. + */ + ksz_prmw8(dev, port, REG_PORT_CTRL_0, + PORT_INSERT_TAG | PORT_REMOVE_TAG, + cpu_port ? PORT_INSERT_TAG : PORT_REMOVE_TAG); + } + /* Disable all WoL options by default. Otherwise * ksz_switch_macaddr_get/put logic will not work properly. * CPU port 4 has no WoL functionality. @@ -2073,6 +2177,7 @@ static int ksz8_dsa_port_setup(struct dsa_switch *ds, int port) return 0; ksz8_port_setup(dev, port, false); + return ksz_dcb_init_port(dev, port); } @@ -2147,7 +2252,9 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds) masks = dev->info->masks; regs = dev->info->regs; - ksz_cfg(dev, regs[S_TAIL_TAG_CTRL], masks[SW_TAIL_TAG_ENABLE], true); + /* KSZ8995XA uses a tag in the header instead of the tail */ + if (!ksz_is_ksz8995xa(dev)) + ksz_cfg(dev, regs[S_TAIL_TAG_CTRL], masks[SW_TAIL_TAG_ENABLE], true); ksz8_port_setup(dev, dev->cpu_port, true); @@ -2323,6 +2430,10 @@ static int ksz8_enable_stp_addr(struct ksz_device *dev) { struct alu_struct alu; + /* KSZ8995XA lacks STP */ + if (ksz_is_ksz8995xa(dev)) + return 0; + /* Setup STP address for STP operation. */ memset(&alu, 0, sizeof(alu)); ether_addr_copy(alu.mac, eth_stp_addr); @@ -2650,13 +2761,17 @@ static int ksz8_setup(struct dsa_switch *ds) struct ksz_port *p; const u16 *regs; int i, ret; + u8 val; regs = dev->info->regs; - dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), - dev->info->num_vlans, GFP_KERNEL); - if (!dev->vlan_cache) - return -ENOMEM; + /* KSZ8995XA has no SW controlled VLAN handling */ + if (!ksz_is_ksz8995xa(dev)) { + dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), + dev->info->num_vlans, GFP_KERNEL); + if (!dev->vlan_cache) + return -ENOMEM; + } ret = ksz8_reset_switch(dev); if (ret) { @@ -2685,19 +2800,22 @@ static int ksz8_setup(struct dsa_switch *ds) ksz_init_mib_timer(dev); - ds->configure_vlan_while_not_filtering = false; ds->dscp_prio_mapping_is_global = true; ds->mtu_enforcement_ingress = true; - /* We rely on software untagging on the CPU port, so that we - * can support both tagged and untagged VLANs - */ - ds->untag_bridge_pvid = true; + if (!ksz_is_ksz8995xa(dev)) { + ds->configure_vlan_while_not_filtering = false; - /* VLAN filtering is partly controlled by the global VLAN - * Enable flag - */ - ds->vlan_filtering_is_global = true; + /* We rely on software untagging on the CPU port, so that we + * can support both tagged and untagged VLANs + */ + ds->untag_bridge_pvid = true; + + /* VLAN filtering is partly controlled by the global VLAN + * Enable flag + */ + ds->vlan_filtering_is_global = true; + } /* Enable automatic fast aging when link changed detected. */ ksz_cfg(dev, S_LINK_AGING_CTRL, SW_LINK_AUTO_AGING, true); @@ -2711,9 +2829,10 @@ static int ksz8_setup(struct dsa_switch *ds) * Make sure unicast VLAN boundary is set as default and * enable no excessive collision drop. */ - ret = ksz_rmw8(dev, REG_SW_CTRL_2, - UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP, - UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP); + val = NO_EXC_COLLISION_DROP; + if (!ksz_is_ksz8995xa(dev)) + val |= UNICAST_VLAN_BOUNDARY; + ret = ksz_rmw8(dev, REG_SW_CTRL_2, val, val); if (ret) return ret; @@ -2721,11 +2840,15 @@ static int ksz8_setup(struct dsa_switch *ds) ksz_cfg(dev, S_MIRROR_CTRL, SW_MIRROR_RX_TX, false); - if (!ksz_is_ksz88x3(dev)) + if (ksz_is_ksz8995xa(dev)) + ksz_cfg(dev, REG_SW_CTRL_9, SW_SPECIAL_TAG, true); + else if (!ksz_is_ksz88x3(dev)) ksz_cfg(dev, REG_SW_CTRL_19, SW_INS_TAG_ENABLE, true); - for (i = 0; i < (dev->info->num_vlans / 4); i++) - ksz8_r_vlan_entries(dev, i); + if (!ksz_is_ksz8995xa(dev)) { + for (i = 0; i < (dev->info->num_vlans / 4); i++) + ksz8_r_vlan_entries(dev, i); + } /* Make sure PME (WoL) is not enabled. If requested, it will * be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs @@ -2976,6 +3099,13 @@ static int ksz8_switch_init(struct ksz_device *dev) return 0; } +static enum dsa_tag_protocol ksz8995xa_get_tag_protocol(struct dsa_switch *ds, + int port, + enum dsa_tag_protocol mp) +{ + return DSA_TAG_PROTO_KS8995; +} + static enum dsa_tag_protocol ksz8463_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -3072,6 +3202,16 @@ const struct phylink_mac_ops ksz8_phylink_mac_ops = { .mac_enable_tx_lpi = ksz_phylink_mac_enable_tx_lpi, }; +/* + * The KS(Z)8995XA has no indirect access, meaning no MIB counters, + * no FDB access, and no VLAN handling. + */ +const struct ksz_dev_ops ksz8995xa_dev_ops = { + .get_port_addr = ksz8_get_port_addr, + .cfg_port_member = ksz8_cfg_port_member, + .init = ksz8_switch_init, +}; + const struct ksz_dev_ops ksz8463_dev_ops = { .get_port_addr = ksz8463_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, @@ -3111,6 +3251,38 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .pme_pwrite8 = ksz8_pme_pwrite8, }; +/* + * Restricted operations for KSZ8995XA, so many things are not supported + * by this old switch that we need diet DSA operations. + */ +const struct dsa_switch_ops ksz8995xa_switch_ops = { + .get_tag_protocol = ksz8995xa_get_tag_protocol, + .setup = ksz8_setup, + .teardown = ksz_teardown, + .phy_read = ksz8_phy_read16, + .phy_write = ksz8_phy_write16, + .phylink_get_caps = ksz8_phylink_get_caps, + .port_setup = ksz8_dsa_port_setup, + .port_bridge_join = ksz_port_bridge_join, + .port_bridge_leave = ksz_port_bridge_leave, + .port_set_mac_address = ksz_port_set_mac_address, + .port_stp_state_set = ksz_port_stp_state_set, + .port_pre_bridge_flags = ksz_port_pre_bridge_flags, + .port_bridge_flags = ksz_port_bridge_flags, + .port_fast_age = ksz8_flush_dyn_mac_table, + .port_mirror_add = ksz8_port_mirror_add, + .port_mirror_del = ksz8_port_mirror_del, + .port_change_mtu = ksz8995xa_change_mtu, + .port_max_mtu = ksz88xx_max_mtu, + .port_get_default_prio = ksz_port_get_default_prio, + .port_set_default_prio = ksz_port_set_default_prio, + .port_get_dscp_prio = ksz_port_get_dscp_prio, + .port_add_dscp_prio = ksz_port_add_dscp_prio, + .port_del_dscp_prio = ksz_port_del_dscp_prio, + .port_get_apptrust = ksz_port_get_apptrust, + .port_set_apptrust = ksz_port_set_apptrust, +}; + const struct dsa_switch_ops ksz8463_switch_ops = { .get_tag_protocol = ksz8463_get_tag_protocol, .connect_tag_protocol = ksz8463_connect_tag_protocol, diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h index bc371cc26c6f..9b37c56c9617 100644 --- a/drivers/net/dsa/microchip/ksz8.h +++ b/drivers/net/dsa/microchip/ksz8.h @@ -12,11 +12,13 @@ #include #include "ksz_common.h" +extern const struct ksz_dev_ops ksz8995xa_dev_ops; extern const struct ksz_dev_ops ksz8463_dev_ops; extern const struct ksz_dev_ops ksz87xx_dev_ops; extern const struct ksz_dev_ops ksz88xx_dev_ops; extern const struct phylink_mac_ops ksz88x3_phylink_mac_ops; extern const struct phylink_mac_ops ksz8_phylink_mac_ops; +extern const struct dsa_switch_ops ksz8995xa_switch_ops; extern const struct dsa_switch_ops ksz8463_switch_ops; extern const struct dsa_switch_ops ksz87xx_switch_ops; extern const struct dsa_switch_ops ksz88xx_switch_ops; diff --git a/drivers/net/dsa/microchip/ksz8_reg.h b/drivers/net/dsa/microchip/ksz8_reg.h index 6bc511da1f7d..f858bce84bfd 100644 --- a/drivers/net/dsa/microchip/ksz8_reg.h +++ b/drivers/net/dsa/microchip/ksz8_reg.h @@ -95,6 +95,8 @@ #define SW_LED_LINK_ACT_DUPLEX 2 #define SW_LED_LINK_DUPLEX 3 +#define SW_SPECIAL_TAG BIT(0) /* KSZ8995XA only */ + #define REG_SW_CTRL_10 0x0C #define SW_PASS_PAUSE BIT(0) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 81798a9fa671..f1b53439ff58 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -446,6 +446,20 @@ static const u8 ksz8895_shifts[] = { [DYNAMIC_MAC_SRC_PORT] = 24, }; +static const u16 ksz8995xa_regs[] = { + [REG_SW_MAC_ADDR] = 0x68, + [P_FORCE_CTRL] = 0x0C, + [P_LINK_STATUS] = 0x0E, + [P_LOCAL_CTRL] = 0x0C, + [P_NEG_RESTART_CTRL] = 0x0D, + [P_REMOTE_STATUS] = 0x0E, + [P_SPEED_STATUS] = 0x09, + [P_STP_CTRL] = 0x02, + [S_START_CTRL] = 0x01, + [S_BROADCAST_CTRL] = 0x06, + [S_MULTICAST_CTRL] = 0x04, +}; + static const u16 ksz9477_regs[] = { [REG_SW_MAC_ADDR] = 0x0302, [P_STP_CTRL] = 0x0B04, @@ -1377,6 +1391,21 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, false}, }, + [KSZ8995XA] = { + .chip_id = KSZ8995XA_CHIP_ID, /* Also known as KS8995XA */ + .dev_name = "KSZ8995XA", + .cpu_ports = 0x10, /* can be configured as cpu port */ + .port_cnt = 5, /* total cpu and user ports */ + .num_tx_queues = 2, /* low/hi priority queues, no more */ + .num_ipms = 2, + .ops = &ksz8995xa_dev_ops, + .switch_ops = &ksz8995xa_switch_ops, + .phylink_mac_ops = &ksz88x3_phylink_mac_ops, + .regs = ksz8995xa_regs, + .supports_mii = {true, true, true, true, true}, + .internal_phy = {true, true, true, true, false}, + }, + [KSZ9477] = { .chip_id = KSZ9477_CHIP_ID, .dev_name = "KSZ9477", @@ -2684,6 +2713,10 @@ void ksz_init_mib_timer(struct ksz_device *dev) { int i; + /* KSZ8995XA lacks MiB features */ + if (ksz_is_ksz8995xa(dev)) + return; + INIT_DELAYED_WORK(&dev->mib_read, ksz_mib_read_work); for (i = 0; i < dev->info->port_cnt; i++) { @@ -2979,11 +3012,15 @@ static int ksz_switch_detect(struct ksz_device *dev) return -ENODEV; break; case KSZ8895_FAMILY_ID: - if (id2 == KSZ8895_CHIP_ID_95 || - id2 == KSZ8895_CHIP_ID_95R) + if (id2 == KSZ8895_CHIP_ID_95XA) { + dev->chip_id = KSZ8995XA_CHIP_ID; + break; + } else if (id2 == KSZ8895_CHIP_ID_95 || + id2 == KSZ8895_CHIP_ID_95R) { dev->chip_id = KSZ8895_CHIP_ID; - else + } else { return -ENODEV; + } ret = ksz_read8(dev, REG_KSZ8864_CHIP_ID, &id4); if (ret) return ret; @@ -4088,11 +4125,13 @@ int ksz_switch_register(struct ksz_device *dev) if (ret) return ret; - /* Read MIB counters every 30 seconds to avoid overflow. */ - dev->mib_read_interval = msecs_to_jiffies(5000); + if (!ksz_is_ksz8995xa(dev)) { + /* Read MIB counters every 30 seconds to avoid overflow. */ + dev->mib_read_interval = msecs_to_jiffies(5000); - /* Start the MIB timer. */ - schedule_delayed_work(&dev->mib_read, 0); + /* Start the MIB timer. */ + schedule_delayed_work(&dev->mib_read, 0); + } return ret; } diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 0cff33df06a4..091cfbdc486f 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -281,6 +281,7 @@ enum ksz_model { KSZ88X3, KSZ8864, KSZ8895, + KSZ8995XA, KSZ9477, KSZ9896, KSZ9897, @@ -790,7 +791,13 @@ static inline bool ksz_is_ksz88x3(struct ksz_device *dev) static inline bool ksz_is_8895_family(struct ksz_device *dev) { return dev->chip_id == KSZ8895_CHIP_ID || - dev->chip_id == KSZ8864_CHIP_ID; + dev->chip_id == KSZ8864_CHIP_ID || + dev->chip_id == KSZ8995XA_CHIP_ID; +} + +static inline bool ksz_is_ksz8995xa(struct ksz_device *dev) +{ + return dev->chip_id == KSZ8995XA_CHIP_ID; } static inline bool is_ksz8(struct ksz_device *dev) @@ -861,6 +868,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port) #define KSZ87_CHIP_ID_94 0x6 #define KSZ87_CHIP_ID_95 0x9 #define KSZ88_CHIP_ID_63 0x3 +#define KSZ8895_CHIP_ID_95XA 0x0 #define KSZ8895_CHIP_ID_95 0x4 #define KSZ8895_CHIP_ID_95R 0x6 @@ -928,6 +936,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port) #define KSZ8863_HUGE_PACKET_SIZE 1916 #define KSZ8863_NORMAL_PACKET_SIZE 1536 #define KSZ8_LEGAL_PACKET_SIZE 1518 +#define KSZ8995XA_LEGAL_PACKET_SIZE 1522 #define KSZ9477_MAX_FRAME_SIZE 9000 #define KSZ8873_REG_GLOBAL_CTRL_12 0x0e diff --git a/drivers/net/dsa/microchip/ksz_dcb.c b/drivers/net/dsa/microchip/ksz_dcb.c index 7131c5caac54..aa0260f07252 100644 --- a/drivers/net/dsa/microchip/ksz_dcb.c +++ b/drivers/net/dsa/microchip/ksz_dcb.c @@ -20,10 +20,12 @@ #define KSZ8_PORT_DIFFSERV_ENABLE BIT(6) #define KSZ8_PORT_802_1P_ENABLE BIT(5) #define KSZ8_PORT_BASED_PRIO_M GENMASK(4, 3) +#define KSZ8995XA_PORT_BASED_PRIO BIT(4) #define KSZ8463_REG_TOS_DSCP_CTRL 0x16 #define KSZ88X3_REG_TOS_DSCP_CTRL 0x60 #define KSZ8765_REG_TOS_DSCP_CTRL 0x90 +#define KSZ8995XA_REG_TOS_DSCP_CTRL_7 0x67 #define KSZ9477_REG_SW_MAC_TOS_CTRL 0x033e #define KSZ9477_SW_TOS_DSCP_REMAP BIT(0) @@ -98,8 +100,11 @@ static void ksz_get_default_port_prio_reg(struct ksz_device *dev, int *reg, { if (is_ksz8(dev)) { *reg = KSZ8_REG_PORT_1_CTRL_0; - *mask = KSZ8_PORT_BASED_PRIO_M; - *shift = __bf_shf(KSZ8_PORT_BASED_PRIO_M); + if (ksz_is_ksz8995xa(dev)) + *mask = KSZ8995XA_PORT_BASED_PRIO; + else + *mask = KSZ8_PORT_BASED_PRIO_M; + *shift = __bf_shf(*mask); if (ksz_is_ksz8463(dev)) *reg = KSZ8463_REG_PORT_1_CTRL_0; } else { @@ -112,31 +117,45 @@ static void ksz_get_default_port_prio_reg(struct ksz_device *dev, int *reg, /** * ksz_get_dscp_prio_reg - Retrieves the DSCP-to-priority-mapping register * @dev: Pointer to the KSZ switch device structure + * @dscp: DSCP value for which to retrieve the register * @reg: Pointer to the register address to be set - * @per_reg: Pointer to the number of DSCP values per register * @mask: Pointer to the mask to be set + * @shift: Pointer to the bit shift to be set * - * This function retrieves the DSCP to priority mapping register, the number of - * DSCP values per register, and the mask to be set. + * This function retrieves the register, mask and shift for a DSCP to priority + * mapping entry. */ -static void ksz_get_dscp_prio_reg(struct ksz_device *dev, int *reg, - int *per_reg, u8 *mask) +static void ksz_get_dscp_prio_reg(struct ksz_device *dev, u8 dscp, int *reg, + u8 *mask, int *shift) { + int per_reg; + + if (ksz_is_ksz8995xa(dev)) { + /* KSZ8995XA stores DSCP groups in descending register order. */ + *reg = KSZ8995XA_REG_TOS_DSCP_CTRL_7 - dscp / 8; + *mask = BIT(0); + *shift = dscp % 8; + return; + } + if (ksz_is_ksz87xx(dev) || ksz_is_8895_family(dev)) { *reg = KSZ8765_REG_TOS_DSCP_CTRL; - *per_reg = 4; + per_reg = 4; *mask = GENMASK(1, 0); } else if (ksz_is_ksz88x3(dev) || ksz_is_ksz8463(dev)) { *reg = KSZ88X3_REG_TOS_DSCP_CTRL; - *per_reg = 4; + per_reg = 4; *mask = GENMASK(1, 0); if (ksz_is_ksz8463(dev)) *reg = KSZ8463_REG_TOS_DSCP_CTRL; } else { *reg = KSZ9477_REG_DIFFSERV_PRIO_MAP; - *per_reg = 2; + per_reg = 2; *mask = GENMASK(2, 0); } + + *reg += dscp / per_reg; + *shift = (dscp % per_reg) * (8 / per_reg); } /** @@ -236,10 +255,10 @@ int ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio) int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) { struct ksz_device *dev = ds->priv; - int reg, per_reg, ret, shift; + int reg, ret, shift; u8 data, mask; - ksz_get_dscp_prio_reg(dev, ®, &per_reg, &mask); + ksz_get_dscp_prio_reg(dev, dscp, ®, &mask, &shift); /* If DSCP remapping is disabled, DSCP bits 3-5 are used as Internal * Priority Map (IPM) @@ -260,13 +279,10 @@ int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) /* In case DSCP remapping is enabled, we need to write the DSCP to * priority mapping table. */ - reg += dscp / per_reg; ret = ksz_read8(dev, reg, &data); if (ret) return ret; - shift = (dscp % per_reg) * (8 / per_reg); - return (data >> shift) & mask; } @@ -283,15 +299,12 @@ int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) */ static int ksz_set_global_dscp_entry(struct ksz_device *dev, u8 dscp, u8 ipm) { - int reg, per_reg, shift; + int reg, shift; u8 mask; - ksz_get_dscp_prio_reg(dev, ®, &per_reg, &mask); + ksz_get_dscp_prio_reg(dev, dscp, ®, &mask, &shift); - shift = (dscp % per_reg) * (8 / per_reg); - - return ksz_rmw8(dev, reg + (dscp / per_reg), mask << shift, - ipm << shift); + return ksz_rmw8(dev, reg, mask << shift, ipm << shift); } /** @@ -441,6 +454,9 @@ static void ksz_apptrust_error(struct ksz_device *dev) * 2. IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point selector * (lowest priority) * + * KSZ8995XA instead ORs the classification results, so it supports only + * one trusted selector at a time. + * * Return: 0 on success, or a negative error code on failure */ static int ksz_port_set_apptrust_validate(struct ksz_device *dev, int port, @@ -449,6 +465,12 @@ static int ksz_port_set_apptrust_validate(struct ksz_device *dev, int port, int i, j, found; int j_prev = 0; + if (ksz_is_ksz8995xa(dev) && nsel > 1) { + dev_err(dev->dev, + "KSZ8995XA supports only one apptrust selector at a time\n"); + return -EOPNOTSUPP; + } + /* Iterate through the requested selectors */ for (i = 0; i < nsel; i++) { found = 0; @@ -552,6 +574,10 @@ int ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nsel) if (ret) return ret; + /* XA's combined classification cannot be reported as a trust order. */ + if (ksz_is_ksz8995xa(dev) && (data & mask) == mask) + return -EOPNOTSUPP; + *nsel = 0; for (i = 0; i < ARRAY_SIZE(ksz_supported_apptrust); i++) { if (data & map[i].bit) diff --git a/drivers/net/dsa/microchip/ksz_spi.c b/drivers/net/dsa/microchip/ksz_spi.c index 373e9054947c..e3bb9e604186 100644 --- a/drivers/net/dsa/microchip/ksz_spi.c +++ b/drivers/net/dsa/microchip/ksz_spi.c @@ -161,7 +161,8 @@ static int ksz_spi_probe(struct spi_device *spi) chip->chip_id == KSZ8794_CHIP_ID || chip->chip_id == KSZ8765_CHIP_ID) regmap_config = ksz8795_regmap_config; - else if (chip->chip_id == KSZ8895_CHIP_ID || + else if (chip->chip_id == KSZ8995XA_CHIP_ID || + chip->chip_id == KSZ8895_CHIP_ID || chip->chip_id == KSZ8864_CHIP_ID) regmap_config = ksz8863_regmap_config; else @@ -185,7 +186,10 @@ static int ksz_spi_probe(struct spi_device *spi) dev->pdata = spi->dev.platform_data; /* setup spi */ - spi->mode = SPI_MODE_3; + if (chip->chip_id == KSZ8995XA_CHIP_ID) + spi->mode = SPI_MODE_0; + else + spi->mode = SPI_MODE_3; ret = spi_setup(spi); if (ret) return ret; @@ -224,6 +228,25 @@ static void ksz_spi_shutdown(struct spi_device *spi) } static const struct of_device_id ksz_dt_ids[] = { + /* + * Legacy Micrel bindings. In 2015 Microchip acquired + * Micrel which is the originator of the KSZ series, and + * devices branded for Micrel already existed, as well as + * some device tree bindings. These two products are identical + * to the same Microchip products. + */ + { + .compatible = "micrel,ksz8864", + .data = &ksz_switch_chips[KSZ8864] + }, + { + .compatible = "micrel,ksz8795", + .data = &ksz_switch_chips[KSZ8795] + }, + { + .compatible = "micrel,ks8995", + .data = &ksz_switch_chips[KSZ8995XA] + }, { .compatible = "microchip,ksz8463", .data = &ksz_switch_chips[KSZ8463] @@ -256,6 +279,10 @@ static const struct of_device_id ksz_dt_ids[] = { .compatible = "microchip,ksz8895", .data = &ksz_switch_chips[KSZ8895] }, + { + .compatible = "microchip,ksz8995xa", + .data = &ksz_switch_chips[KSZ8995XA] + }, { .compatible = "microchip,ksz9477", .data = &ksz_switch_chips[KSZ9477] @@ -317,6 +344,7 @@ static const struct of_device_id ksz_dt_ids[] = { MODULE_DEVICE_TABLE(of, ksz_dt_ids); static const struct spi_device_id ksz_spi_ids[] = { + { "ks8995" }, { "ksz8463" }, { "ksz8765" }, { "ksz8794" }, @@ -325,6 +353,7 @@ static const struct spi_device_id ksz_spi_ids[] = { { "ksz8864" }, { "ksz8873" }, { "ksz8895" }, + { "ksz8995xa" }, { "ksz9477" }, { "ksz9896" }, { "ksz9897" }, diff --git a/include/linux/platform_data/microchip-ksz.h b/include/linux/platform_data/microchip-ksz.h index fe8df1774289..411d5e164383 100644 --- a/include/linux/platform_data/microchip-ksz.h +++ b/include/linux/platform_data/microchip-ksz.h @@ -31,6 +31,7 @@ enum ksz_chip_id { KSZ88X3_CHIP_ID = 0x8830, KSZ8864_CHIP_ID = 0x8864, KSZ8895_CHIP_ID = 0x8895, + KSZ8995XA_CHIP_ID = 0x8995, KSZ9477_CHIP_ID = 0x00947700, KSZ9896_CHIP_ID = 0x00989600, KSZ9897_CHIP_ID = 0x00989700, From 744e0256c4a10694f899f22cbb43566f5c9a770d Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 16 Sep 2026 12:21:01 +0200 Subject: [PATCH 0620/2126] net: dsa: ks8995: Delete surplus driver The Microchip KSZ driver now handles the KS(Z)8995XA. The old driver identified the shared 0x95/0x0 ID as KS8995MA, but this ID cannot distinguish MA from XA. No KS8995MA users are known, and KS8995E has no documented SPI management interface. Neither variant has been verified with the replacement driver. The two in-tree device trees using the "micrel,ks8995" compatible: arch/arm/boot/dts/intel/ixp/intel-ixp42x-linksys-wrv54g.dts arch/arm/boot/dts/intel/ixp/intel-ixp42x-actiontec-mi424wr.dtsi both use KS8995XA hardware and continue to be supported by the replacement driver without regressions. Delete the old driver, but leave a stub behind in Kconfig so new users will be automatically phased over to the new symbol when migrating their configs. The old driver supports platform data (board file) instantiation, but nothing in the kernel tree makes use of this legacy mechanism so it is fine to delete. Reviewed-by: Nicolai Buchwitz Signed-off-by: Linus Walleij Link: https://patch.msgid.link/20260916-ks8995-to-ksz8-v15-4-8825ff5fd4be@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/Kconfig | 10 +- drivers/net/dsa/Makefile | 1 - drivers/net/dsa/ks8995.c | 857 --------------------------------------- 3 files changed, 6 insertions(+), 862 deletions(-) delete mode 100644 drivers/net/dsa/ks8995.c diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index e3d88f41fecf..fe8cd5338fda 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -112,11 +112,13 @@ config NET_DSA_RZN1_A5PSW config NET_DSA_KS8995 tristate "Micrel KS8995 family 5-ports 10/100 Ethernet switches" depends on SPI - depends on NET_DSA_MICROCHIP_KSZ_SPI = n - select NET_DSA_TAG_NONE + select NET_DSA_MICROCHIP_KSZ_COMMON + select NET_DSA_MICROCHIP_KSZ_SPI help - This driver supports the Micrel KS8995 family of 10/100 Mbit ethernet - switches, managed over SPI. + This is a transitional option for users who had NET_DSA_KS8995 + enabled. It automatically enables the new NET_DSA_MICROCHIP_KSZ_SPI + driver which supersedes it. This option will be removed in a future + kernel release. config NET_DSA_SMSC_LAN9303 tristate diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile index df849cd0e640..7e637d56b35c 100644 --- a/drivers/net/dsa/Makefile +++ b/drivers/net/dsa/Makefile @@ -2,7 +2,6 @@ obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o -obj-$(CONFIG_NET_DSA_KS8995) += ks8995.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o diff --git a/drivers/net/dsa/ks8995.c b/drivers/net/dsa/ks8995.c deleted file mode 100644 index 77d8b842693c..000000000000 --- a/drivers/net/dsa/ks8995.c +++ /dev/null @@ -1,857 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * SPI driver for Micrel/Kendin KS8995M and KSZ8864RMN ethernet switches - * - * Copyright (C) 2008 Gabor Juhos - * Copyright (C) 2025 Linus Walleij - * - * This file was based on: drivers/spi/at25.c - * Copyright (C) 2006 David Brownell - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRV_VERSION "0.1.1" -#define DRV_DESC "Micrel KS8995 Ethernet switch SPI driver" - -/* ------------------------------------------------------------------------ */ - -#define KS8995_REG_ID0 0x00 /* Chip ID0 */ -#define KS8995_REG_ID1 0x01 /* Chip ID1 */ - -#define KS8995_REG_GC0 0x02 /* Global Control 0 */ - -#define KS8995_GC0_P5_PHY BIT(3) /* Port 5 PHY enabled */ - -#define KS8995_REG_GC1 0x03 /* Global Control 1 */ -#define KS8995_REG_GC2 0x04 /* Global Control 2 */ - -#define KS8995_GC2_HUGE BIT(2) /* Huge packet support */ -#define KS8995_GC2_LEGAL BIT(1) /* Legal size override */ - -#define KS8995_REG_GC3 0x05 /* Global Control 3 */ -#define KS8995_REG_GC4 0x06 /* Global Control 4 */ - -#define KS8995_GC4_10BT BIT(4) /* Force switch to 10Mbit */ -#define KS8995_GC4_MII_FLOW BIT(5) /* MII full-duplex flow control enable */ -#define KS8995_GC4_MII_HD BIT(6) /* MII half-duplex mode enable */ - -#define KS8995_REG_GC5 0x07 /* Global Control 5 */ -#define KS8995_REG_GC6 0x08 /* Global Control 6 */ -#define KS8995_REG_GC7 0x09 /* Global Control 7 */ -#define KS8995_REG_GC8 0x0a /* Global Control 8 */ -#define KS8995_REG_GC9 0x0b /* Global Control 9 */ - -#define KS8995_GC9_SPECIAL BIT(0) /* Special tagging mode (DSA) */ - -/* In DSA the ports 1-4 are numbered 0-3 and the CPU port is port 4 */ -#define KS8995_REG_PC(p, r) (0x10 + (0x10 * (p)) + (r)) /* Port Control */ -#define KS8995_REG_PS(p, r) (0x1e + (0x10 * (p)) + (r)) /* Port Status */ - -#define KS8995_REG_PC0 0x00 /* Port Control 0 */ -#define KS8995_REG_PC1 0x01 /* Port Control 1 */ -#define KS8995_REG_PC2 0x02 /* Port Control 2 */ -#define KS8995_REG_PC3 0x03 /* Port Control 3 */ -#define KS8995_REG_PC4 0x04 /* Port Control 4 */ -#define KS8995_REG_PC5 0x05 /* Port Control 5 */ -#define KS8995_REG_PC6 0x06 /* Port Control 6 */ -#define KS8995_REG_PC7 0x07 /* Port Control 7 */ -#define KS8995_REG_PC8 0x08 /* Port Control 8 */ -#define KS8995_REG_PC9 0x09 /* Port Control 9 */ -#define KS8995_REG_PC10 0x0a /* Port Control 10 */ -#define KS8995_REG_PC11 0x0b /* Port Control 11 */ -#define KS8995_REG_PC12 0x0c /* Port Control 12 */ -#define KS8995_REG_PC13 0x0d /* Port Control 13 */ - -#define KS8995_PC0_TAG_INS BIT(2) /* Enable tag insertion on port */ -#define KS8995_PC0_TAG_REM BIT(1) /* Enable tag removal on port */ -#define KS8995_PC0_PRIO_EN BIT(0) /* Enable priority handling */ - -#define KS8995_PC2_TXEN BIT(2) /* Enable TX on port */ -#define KS8995_PC2_RXEN BIT(1) /* Enable RX on port */ -#define KS8995_PC2_LEARN_DIS BIT(0) /* Disable learning on port */ - -#define KS8995_PC13_TXDIS BIT(6) /* Disable transmitter */ -#define KS8995_PC13_PWDN BIT(3) /* Power down */ - -#define KS8995_REG_TPC0 0x60 /* TOS Priority Control 0 */ -#define KS8995_REG_TPC1 0x61 /* TOS Priority Control 1 */ -#define KS8995_REG_TPC2 0x62 /* TOS Priority Control 2 */ -#define KS8995_REG_TPC3 0x63 /* TOS Priority Control 3 */ -#define KS8995_REG_TPC4 0x64 /* TOS Priority Control 4 */ -#define KS8995_REG_TPC5 0x65 /* TOS Priority Control 5 */ -#define KS8995_REG_TPC6 0x66 /* TOS Priority Control 6 */ -#define KS8995_REG_TPC7 0x67 /* TOS Priority Control 7 */ - -#define KS8995_REG_MAC0 0x68 /* MAC address 0 */ -#define KS8995_REG_MAC1 0x69 /* MAC address 1 */ -#define KS8995_REG_MAC2 0x6a /* MAC address 2 */ -#define KS8995_REG_MAC3 0x6b /* MAC address 3 */ -#define KS8995_REG_MAC4 0x6c /* MAC address 4 */ -#define KS8995_REG_MAC5 0x6d /* MAC address 5 */ - -#define KS8995_REG_IAC0 0x6e /* Indirect Access Control 0 */ -#define KS8995_REG_IAC1 0x6f /* Indirect Access Control 0 */ -#define KS8995_REG_IAD7 0x70 /* Indirect Access Data 7 */ -#define KS8995_REG_IAD6 0x71 /* Indirect Access Data 6 */ -#define KS8995_REG_IAD5 0x72 /* Indirect Access Data 5 */ -#define KS8995_REG_IAD4 0x73 /* Indirect Access Data 4 */ -#define KS8995_REG_IAD3 0x74 /* Indirect Access Data 3 */ -#define KS8995_REG_IAD2 0x75 /* Indirect Access Data 2 */ -#define KS8995_REG_IAD1 0x76 /* Indirect Access Data 1 */ -#define KS8995_REG_IAD0 0x77 /* Indirect Access Data 0 */ - -#define KSZ8864_REG_ID1 0xfe /* Chip ID in bit 7 */ - -#define KS8995_REGS_SIZE 0x80 -#define KSZ8864_REGS_SIZE 0x100 -#define KSZ8795_REGS_SIZE 0x100 - -#define ID1_CHIPID_M 0xf -#define ID1_CHIPID_S 4 -#define ID1_REVISION_M 0x7 -#define ID1_REVISION_S 1 -#define ID1_START_SW 1 /* start the switch */ - -#define FAMILY_KS8995 0x95 -#define FAMILY_KSZ8795 0x87 -#define CHIPID_M 0 -#define KS8995_CHIP_ID 0x00 -#define KSZ8864_CHIP_ID 0x01 -#define KSZ8795_CHIP_ID 0x09 - -#define KS8995_CMD_WRITE 0x02U -#define KS8995_CMD_READ 0x03U - -#define KS8995_CPU_PORT 4 -#define KS8995_NUM_PORTS 5 /* 5 ports including the CPU port */ -#define KS8995_RESET_DELAY 10 /* usec */ - -enum ks8995_chip_variant { - ks8995, - ksz8864, - ksz8795, - max_variant -}; - -struct ks8995_chip_params { - char *name; - int family_id; - int chip_id; - int regs_size; - int addr_width; - int addr_shift; -}; - -static const struct ks8995_chip_params ks8995_chip[] = { - [ks8995] = { - .name = "KS8995MA", - .family_id = FAMILY_KS8995, - .chip_id = KS8995_CHIP_ID, - .regs_size = KS8995_REGS_SIZE, - .addr_width = 8, - .addr_shift = 0, - }, - [ksz8864] = { - .name = "KSZ8864RMN", - .family_id = FAMILY_KS8995, - .chip_id = KSZ8864_CHIP_ID, - .regs_size = KSZ8864_REGS_SIZE, - .addr_width = 8, - .addr_shift = 0, - }, - [ksz8795] = { - .name = "KSZ8795CLX", - .family_id = FAMILY_KSZ8795, - .chip_id = KSZ8795_CHIP_ID, - .regs_size = KSZ8795_REGS_SIZE, - .addr_width = 12, - .addr_shift = 1, - }, -}; - -struct ks8995_switch { - struct spi_device *spi; - struct device *dev; - struct dsa_switch *ds; - struct mutex lock; - struct gpio_desc *reset_gpio; - struct bin_attribute regs_attr; - const struct ks8995_chip_params *chip; - int revision_id; - unsigned int max_mtu[KS8995_NUM_PORTS]; -}; - -static const struct spi_device_id ks8995_id[] = { - {"ks8995", ks8995}, - {"ksz8864", ksz8864}, - {"ksz8795", ksz8795}, - { } -}; -MODULE_DEVICE_TABLE(spi, ks8995_id); - -static const struct of_device_id ks8995_spi_of_match[] = { - { .compatible = "micrel,ks8995" }, - { .compatible = "micrel,ksz8864" }, - { .compatible = "micrel,ksz8795" }, - { }, -}; -MODULE_DEVICE_TABLE(of, ks8995_spi_of_match); - -static inline u8 get_chip_id(u8 val) -{ - return (val >> ID1_CHIPID_S) & ID1_CHIPID_M; -} - -static inline u8 get_chip_rev(u8 val) -{ - return (val >> ID1_REVISION_S) & ID1_REVISION_M; -} - -/* create_spi_cmd - create a chip specific SPI command header - * @ks: pointer to switch instance - * @cmd: SPI command for switch - * @address: register address for command - * - * Different chip families use different bit pattern to address the switches - * registers: - * - * KS8995: 8bit command + 8bit address - * KSZ8795: 3bit command + 12bit address + 1bit TR (?) - */ -static inline __be16 create_spi_cmd(struct ks8995_switch *ks, int cmd, - unsigned address) -{ - u16 result = cmd; - - /* make room for address (incl. address shift) */ - result <<= ks->chip->addr_width + ks->chip->addr_shift; - /* add address */ - result |= address << ks->chip->addr_shift; - /* SPI protocol needs big endian */ - return cpu_to_be16(result); -} -/* ------------------------------------------------------------------------ */ -static int ks8995_read(struct ks8995_switch *ks, char *buf, - unsigned offset, size_t count) -{ - __be16 cmd; - struct spi_transfer t[2]; - struct spi_message m; - int err; - - cmd = create_spi_cmd(ks, KS8995_CMD_READ, offset); - spi_message_init(&m); - - memset(&t, 0, sizeof(t)); - - t[0].tx_buf = &cmd; - t[0].len = sizeof(cmd); - spi_message_add_tail(&t[0], &m); - - t[1].rx_buf = buf; - t[1].len = count; - spi_message_add_tail(&t[1], &m); - - mutex_lock(&ks->lock); - err = spi_sync(ks->spi, &m); - mutex_unlock(&ks->lock); - - return err ? err : count; -} - -static int ks8995_write(struct ks8995_switch *ks, char *buf, - unsigned offset, size_t count) -{ - __be16 cmd; - struct spi_transfer t[2]; - struct spi_message m; - int err; - - cmd = create_spi_cmd(ks, KS8995_CMD_WRITE, offset); - spi_message_init(&m); - - memset(&t, 0, sizeof(t)); - - t[0].tx_buf = &cmd; - t[0].len = sizeof(cmd); - spi_message_add_tail(&t[0], &m); - - t[1].tx_buf = buf; - t[1].len = count; - spi_message_add_tail(&t[1], &m); - - mutex_lock(&ks->lock); - err = spi_sync(ks->spi, &m); - mutex_unlock(&ks->lock); - - return err ? err : count; -} - -static inline int ks8995_read_reg(struct ks8995_switch *ks, u8 addr, u8 *buf) -{ - return ks8995_read(ks, buf, addr, 1) != 1; -} - -static inline int ks8995_write_reg(struct ks8995_switch *ks, u8 addr, u8 val) -{ - char buf = val; - - return ks8995_write(ks, &buf, addr, 1) != 1; -} - -/* ------------------------------------------------------------------------ */ - -static int ks8995_stop(struct ks8995_switch *ks) -{ - return ks8995_write_reg(ks, KS8995_REG_ID1, 0); -} - -static int ks8995_start(struct ks8995_switch *ks) -{ - return ks8995_write_reg(ks, KS8995_REG_ID1, 1); -} - -static int ks8995_reset(struct ks8995_switch *ks) -{ - int err; - - err = ks8995_stop(ks); - if (err) - return err; - - udelay(KS8995_RESET_DELAY); - - return ks8995_start(ks); -} - -/* ks8995_get_revision - get chip revision - * @ks: pointer to switch instance - * - * Verify chip family and id and get chip revision. - */ -static int ks8995_get_revision(struct ks8995_switch *ks) -{ - int err; - u8 id0, id1, ksz8864_id; - - /* read family id */ - err = ks8995_read_reg(ks, KS8995_REG_ID0, &id0); - if (err) { - err = -EIO; - goto err_out; - } - - /* verify family id */ - if (id0 != ks->chip->family_id) { - dev_err(&ks->spi->dev, "chip family id mismatch: expected 0x%02x but 0x%02x read\n", - ks->chip->family_id, id0); - err = -ENODEV; - goto err_out; - } - - switch (ks->chip->family_id) { - case FAMILY_KS8995: - /* try reading chip id at CHIP ID1 */ - err = ks8995_read_reg(ks, KS8995_REG_ID1, &id1); - if (err) { - err = -EIO; - goto err_out; - } - - /* verify chip id */ - if ((get_chip_id(id1) == CHIPID_M) && - (get_chip_id(id1) == ks->chip->chip_id)) { - /* KS8995MA */ - ks->revision_id = get_chip_rev(id1); - } else if (get_chip_id(id1) != CHIPID_M) { - /* KSZ8864RMN */ - err = ks8995_read_reg(ks, KS8995_REG_ID1, &ksz8864_id); - if (err) { - err = -EIO; - goto err_out; - } - - if ((ksz8864_id & 0x80) && - (ks->chip->chip_id == KSZ8864_CHIP_ID)) { - ks->revision_id = get_chip_rev(id1); - } - - } else { - dev_err(&ks->spi->dev, "unsupported chip id for KS8995 family: 0x%02x\n", - id1); - err = -ENODEV; - } - break; - case FAMILY_KSZ8795: - /* try reading chip id at CHIP ID1 */ - err = ks8995_read_reg(ks, KS8995_REG_ID1, &id1); - if (err) { - err = -EIO; - goto err_out; - } - - if (get_chip_id(id1) == ks->chip->chip_id) { - ks->revision_id = get_chip_rev(id1); - } else { - dev_err(&ks->spi->dev, "unsupported chip id for KSZ8795 family: 0x%02x\n", - id1); - err = -ENODEV; - } - break; - default: - dev_err(&ks->spi->dev, "unsupported family id: 0x%02x\n", id0); - err = -ENODEV; - break; - } -err_out: - return err; -} - -static int ks8995_check_config(struct ks8995_switch *ks) -{ - int ret; - u8 val; - - ret = ks8995_read_reg(ks, KS8995_REG_GC0, &val); - if (ret) { - dev_err(ks->dev, "failed to read KS8995_REG_GC0\n"); - return ret; - } - - dev_dbg(ks->dev, "port 5 PHY %senabled\n", - (val & KS8995_GC0_P5_PHY) ? "" : "not "); - - val |= KS8995_GC0_P5_PHY; - ret = ks8995_write_reg(ks, KS8995_REG_GC0, val); - if (ret) - dev_err(ks->dev, "failed to set KS8995_REG_GC0\n"); - - dev_dbg(ks->dev, "set KS8995_REG_GC0 to 0x%02x\n", val); - - return 0; -} - -static void -ks8995_mac_config(struct phylink_config *config, unsigned int mode, - const struct phylink_link_state *state) -{ -} - -static void -ks8995_mac_link_up(struct phylink_config *config, struct phy_device *phydev, - unsigned int mode, phy_interface_t interface, - int speed, int duplex, bool tx_pause, bool rx_pause) -{ - struct dsa_port *dp = dsa_phylink_to_port(config); - struct ks8995_switch *ks = dp->ds->priv; - int port = dp->index; - int ret; - u8 val; - - /* Allow forcing the mode on the fixed CPU port, no autonegotiation. - * We assume autonegotiation works on the PHY-facing ports. - */ - if (port != KS8995_CPU_PORT) - return; - - dev_dbg(ks->dev, "MAC link up on CPU port (%d)\n", port); - - ret = ks8995_read_reg(ks, KS8995_REG_GC4, &val); - if (ret) { - dev_err(ks->dev, "failed to read KS8995_REG_GC4\n"); - return; - } - - /* Conjure port config */ - switch (speed) { - case SPEED_10: - dev_dbg(ks->dev, "set switch MII to 100Mbit mode\n"); - val |= KS8995_GC4_10BT; - break; - case SPEED_100: - default: - dev_dbg(ks->dev, "set switch MII to 100Mbit mode\n"); - val &= ~KS8995_GC4_10BT; - break; - } - - if (duplex == DUPLEX_HALF) { - dev_dbg(ks->dev, "set switch MII to half duplex\n"); - val |= KS8995_GC4_MII_HD; - } else { - dev_dbg(ks->dev, "set switch MII to full duplex\n"); - val &= ~KS8995_GC4_MII_HD; - } - - dev_dbg(ks->dev, "set KS8995_REG_GC4 to %02x\n", val); - - /* Enable the CPU port */ - ret = ks8995_write_reg(ks, KS8995_REG_GC4, val); - if (ret) - dev_err(ks->dev, "failed to set KS8995_REG_GC4\n"); -} - -static void -ks8995_mac_link_down(struct phylink_config *config, unsigned int mode, - phy_interface_t interface) -{ - struct dsa_port *dp = dsa_phylink_to_port(config); - struct ks8995_switch *ks = dp->ds->priv; - int port = dp->index; - - if (port != KS8995_CPU_PORT) - return; - - dev_dbg(ks->dev, "MAC link down on CPU port (%d)\n", port); - - /* Disable the CPU port */ -} - -static const struct phylink_mac_ops ks8995_phylink_mac_ops = { - .mac_config = ks8995_mac_config, - .mac_link_up = ks8995_mac_link_up, - .mac_link_down = ks8995_mac_link_down, -}; - -static enum -dsa_tag_protocol ks8995_get_tag_protocol(struct dsa_switch *ds, - int port, - enum dsa_tag_protocol mp) -{ - /* This switch actually uses the 6 byte KS8995 protocol */ - return DSA_TAG_PROTO_NONE; -} - -static int ks8995_setup(struct dsa_switch *ds) -{ - return 0; -} - -static int ks8995_port_enable(struct dsa_switch *ds, int port, - struct phy_device *phy) -{ - struct ks8995_switch *ks = ds->priv; - - dev_dbg(ks->dev, "enable port %d\n", port); - - return 0; -} - -static void ks8995_port_disable(struct dsa_switch *ds, int port) -{ - struct ks8995_switch *ks = ds->priv; - - dev_dbg(ks->dev, "disable port %d\n", port); -} - -static int ks8995_port_pre_bridge_flags(struct dsa_switch *ds, int port, - struct switchdev_brport_flags flags, - struct netlink_ext_ack *extack) -{ - /* We support enabling/disabling learning */ - if (flags.mask & ~(BR_LEARNING)) - return -EINVAL; - - return 0; -} - -static int ks8995_port_bridge_flags(struct dsa_switch *ds, int port, - struct switchdev_brport_flags flags, - struct netlink_ext_ack *extack) -{ - struct ks8995_switch *ks = ds->priv; - int ret; - u8 val; - - if (flags.mask & BR_LEARNING) { - ret = ks8995_read_reg(ks, KS8995_REG_PC(port, KS8995_REG_PC2), &val); - if (ret) { - dev_err(ks->dev, "failed to read KS8995_REG_PC2 on port %d\n", port); - return ret; - } - - if (flags.val & BR_LEARNING) - val &= ~KS8995_PC2_LEARN_DIS; - else - val |= KS8995_PC2_LEARN_DIS; - - ret = ks8995_write_reg(ks, KS8995_REG_PC(port, KS8995_REG_PC2), val); - if (ret) { - dev_err(ks->dev, "failed to write KS8995_REG_PC2 on port %d\n", port); - return ret; - } - } - - return 0; -} - -static void ks8995_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) -{ - struct ks8995_switch *ks = ds->priv; - int ret; - u8 val; - - ret = ks8995_read_reg(ks, KS8995_REG_PC(port, KS8995_REG_PC2), &val); - if (ret) { - dev_err(ks->dev, "failed to read KS8995_REG_PC2 on port %d\n", port); - return; - } - - /* Set the bits for the different STP states in accordance with - * the datasheet, pages 36-37 "Spanning tree support". - */ - switch (state) { - case BR_STATE_DISABLED: - case BR_STATE_BLOCKING: - case BR_STATE_LISTENING: - val &= ~KS8995_PC2_TXEN; - val &= ~KS8995_PC2_RXEN; - val |= KS8995_PC2_LEARN_DIS; - break; - case BR_STATE_LEARNING: - val &= ~KS8995_PC2_TXEN; - val &= ~KS8995_PC2_RXEN; - val &= ~KS8995_PC2_LEARN_DIS; - break; - case BR_STATE_FORWARDING: - val |= KS8995_PC2_TXEN; - val |= KS8995_PC2_RXEN; - val &= ~KS8995_PC2_LEARN_DIS; - break; - default: - dev_err(ks->dev, "unknown bridge state requested\n"); - return; - } - - ret = ks8995_write_reg(ks, KS8995_REG_PC(port, KS8995_REG_PC2), val); - if (ret) { - dev_err(ks->dev, "failed to write KS8995_REG_PC2 on port %d\n", port); - return; - } - - dev_dbg(ks->dev, "set KS8995_REG_PC2 for port %d to %02x\n", port, val); -} - -static void ks8995_phylink_get_caps(struct dsa_switch *dsa, int port, - struct phylink_config *config) -{ - unsigned long *interfaces = config->supported_interfaces; - - if (port == KS8995_CPU_PORT) - __set_bit(PHY_INTERFACE_MODE_MII, interfaces); - - if (port <= 3) { - /* Internal PHYs */ - __set_bit(PHY_INTERFACE_MODE_INTERNAL, interfaces); - /* phylib default */ - __set_bit(PHY_INTERFACE_MODE_MII, interfaces); - } - - config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100; -} - -/* Huge packet support up to 1916 byte packages "inclusive" - * which means that tags are included. If the bit is not set - * it is 1536 bytes "inclusive". We present the length without - * tags or ethernet headers. The setting affects all ports. - */ -static int ks8995_change_mtu(struct dsa_switch *ds, int port, int new_mtu) -{ - struct ks8995_switch *ks = ds->priv; - unsigned int max_mtu; - int ret; - u8 val; - int i; - - ks->max_mtu[port] = new_mtu; - - /* Roof out the MTU for the entire switch to the greatest - * common denominator: the biggest set for any one port will - * be the biggest MTU for the switch. - */ - max_mtu = ETH_DATA_LEN; - for (i = 0; i < KS8995_NUM_PORTS; i++) { - if (ks->max_mtu[i] > max_mtu) - max_mtu = ks->max_mtu[i]; - } - - /* Translate to layer 2 size. - * Add ethernet and (possible) VLAN headers, and checksum to the size. - * For ETH_DATA_LEN (1500 bytes) this will add up to 1522 bytes. - */ - max_mtu += VLAN_ETH_HLEN; - max_mtu += ETH_FCS_LEN; - - ret = ks8995_read_reg(ks, KS8995_REG_GC2, &val); - if (ret) { - dev_err(ks->dev, "failed to read KS8995_REG_GC2\n"); - return ret; - } - - if (max_mtu <= 1522) { - val &= ~KS8995_GC2_HUGE; - val &= ~KS8995_GC2_LEGAL; - } else if (max_mtu > 1522 && max_mtu <= 1536) { - /* This accepts packets up to 1536 bytes */ - val &= ~KS8995_GC2_HUGE; - val |= KS8995_GC2_LEGAL; - } else { - /* This accepts packets up to 1916 bytes */ - val |= KS8995_GC2_HUGE; - val |= KS8995_GC2_LEGAL; - } - - dev_dbg(ks->dev, "new max MTU %d bytes (inclusive)\n", max_mtu); - - ret = ks8995_write_reg(ks, KS8995_REG_GC2, val); - if (ret) - dev_err(ks->dev, "failed to set KS8995_REG_GC2\n"); - - return ret; -} - -static int ks8995_get_max_mtu(struct dsa_switch *ds, int port) -{ - return 1916 - ETH_HLEN - ETH_FCS_LEN; -} - -static const struct dsa_switch_ops ks8995_ds_ops = { - .get_tag_protocol = ks8995_get_tag_protocol, - .setup = ks8995_setup, - .port_pre_bridge_flags = ks8995_port_pre_bridge_flags, - .port_bridge_flags = ks8995_port_bridge_flags, - .port_enable = ks8995_port_enable, - .port_disable = ks8995_port_disable, - .port_stp_state_set = ks8995_port_stp_state_set, - .port_change_mtu = ks8995_change_mtu, - .port_max_mtu = ks8995_get_max_mtu, - .phylink_get_caps = ks8995_phylink_get_caps, -}; - -/* ------------------------------------------------------------------------ */ -static int ks8995_probe(struct spi_device *spi) -{ - struct ks8995_switch *ks; - int err; - int variant = spi_get_device_id(spi)->driver_data; - - if (variant >= max_variant) { - dev_err(&spi->dev, "bad chip variant %d\n", variant); - return -ENODEV; - } - - ks = devm_kzalloc(&spi->dev, sizeof(*ks), GFP_KERNEL); - if (!ks) - return -ENOMEM; - - mutex_init(&ks->lock); - ks->spi = spi; - ks->dev = &spi->dev; - ks->chip = &ks8995_chip[variant]; - - ks->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", - GPIOD_OUT_HIGH); - err = PTR_ERR_OR_ZERO(ks->reset_gpio); - if (err) { - dev_err(&spi->dev, - "failed to get reset gpio: %d\n", err); - return err; - } - - err = gpiod_set_consumer_name(ks->reset_gpio, "switch-reset"); - if (err) - return err; - - if (ks->reset_gpio) { - /* - * If a reset line was obtained, wait for 100us after - * de-asserting RESET before accessing any registers, see - * the KS8995MA datasheet, page 44. - */ - gpiod_set_value_cansleep(ks->reset_gpio, 0); - udelay(100); - } - - spi_set_drvdata(spi, ks); - - spi->mode = SPI_MODE_0; - spi->bits_per_word = 8; - err = spi_setup(spi); - if (err) { - dev_err(&spi->dev, "spi_setup failed, err=%d\n", err); - return err; - } - - err = ks8995_get_revision(ks); - if (err) - return err; - - err = ks8995_reset(ks); - if (err) - return err; - - dev_info(&spi->dev, "%s device found, Chip ID:%x, Revision:%x\n", - ks->chip->name, ks->chip->chip_id, ks->revision_id); - - err = ks8995_check_config(ks); - if (err) - return err; - - ks->ds = devm_kzalloc(&spi->dev, sizeof(*ks->ds), GFP_KERNEL); - if (!ks->ds) - return -ENOMEM; - - ks->ds->dev = &spi->dev; - ks->ds->num_ports = KS8995_NUM_PORTS; - ks->ds->ops = &ks8995_ds_ops; - ks->ds->phylink_mac_ops = &ks8995_phylink_mac_ops; - ks->ds->priv = ks; - - err = dsa_register_switch(ks->ds); - if (err) - return dev_err_probe(&spi->dev, err, - "unable to register DSA switch\n"); - - return 0; -} - -static void ks8995_remove(struct spi_device *spi) -{ - struct ks8995_switch *ks = spi_get_drvdata(spi); - - dsa_unregister_switch(ks->ds); - /* assert reset */ - gpiod_set_value_cansleep(ks->reset_gpio, 1); -} - -/* ------------------------------------------------------------------------ */ -static struct spi_driver ks8995_driver = { - .driver = { - .name = "spi-ks8995", - .of_match_table = ks8995_spi_of_match, - }, - .probe = ks8995_probe, - .remove = ks8995_remove, - .id_table = ks8995_id, -}; - -module_spi_driver(ks8995_driver); - -MODULE_DESCRIPTION(DRV_DESC); -MODULE_VERSION(DRV_VERSION); -MODULE_AUTHOR("Gabor Juhos "); -MODULE_LICENSE("GPL v2"); From 0ca19b9fdcb0087c79d8b21c5a224d6b5cd6fe73 Mon Sep 17 00:00:00 2001 From: Yevgeny Kliteynik Date: Tue, 15 Sep 2026 14:19:07 +0300 Subject: [PATCH 0621/2126] net/mlx5: HWS, Return meaningful error code in hws_send_wqe_fw Returning '-1' is non-idiomatic in kernel code. Use a meaningful error code instead. Signed-off-by: Yevgeny Kliteynik Reviewed-by: Erez Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260915111912.3926585-2-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c index df3b93499eeb..ae3ff232c63b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c @@ -1305,7 +1305,7 @@ send_wqe: goto send_wqe; } - return -1; + return -EIO; } void mlx5hws_send_stes_fw(struct mlx5hws_context *ctx, From 59da9e5163e93b0fb573ff5d64c9bdb74de26ef4 Mon Sep 17 00:00:00 2001 From: Yevgeny Kliteynik Date: Tue, 15 Sep 2026 14:19:08 +0300 Subject: [PATCH 0622/2126] net/mlx5: HWS, Fix error message in mlx5hws_cmd_generate_wqe Kernel log messages should end with '\n' for proper formatting. Signed-off-by: Yevgeny Kliteynik Reviewed-by: Erez Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260915111912.3926585-3-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c index ae3ff232c63b..80cfd0ddba08 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c @@ -1287,7 +1287,7 @@ hws_send_wqe_fw(struct mlx5_core_dev *mdev, send_wqe: ret = mlx5hws_cmd_generate_wqe(mdev, &attr, &cqe); if (ret) { - mlx5_core_err(mdev, "Failed to write WQE using command"); + mlx5_core_err(mdev, "Failed to write WQE using command\n"); return ret; } From 23aacde37804d18c7f6e5d88f40b0e5f6cf46249 Mon Sep 17 00:00:00 2001 From: Yevgeny Kliteynik Date: Tue, 15 Sep 2026 14:19:09 +0300 Subject: [PATCH 0623/2126] net/mlx5: HWS, Replace kzalloc with kzalloc_obj Replace kzalloc with the newer kzalloc_obj allocation function. Signed-off-by: Yevgeny Kliteynik Reviewed-by: Erez Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260915111912.3926585-4-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c index 80cfd0ddba08..49dee44d0bef 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c @@ -732,7 +732,7 @@ static int hws_send_ring_alloc_sq(struct mlx5_core_dev *mdev, goto destroy_wq_cyc; } - sq->wr_priv = kzalloc(sizeof(*sq->wr_priv) * buf_sz, GFP_KERNEL); + sq->wr_priv = kzalloc_objs(*sq->wr_priv, buf_sz); if (!sq->wr_priv) { err = -ENOMEM; goto free_dep_wqe; From 7bf7c4367db690087a144c0e54efed8d2df5b11b Mon Sep 17 00:00:00 2001 From: Yevgeny Kliteynik Date: Tue, 15 Sep 2026 14:19:10 +0300 Subject: [PATCH 0624/2126] net/mlx5: HWS, Add timeout mechanism to draining send queues HWS has a timeout mechanism for usual polling for completion, but it was missing such a mechanism for draining the send queues. Signed-off-by: Yevgeny Kliteynik Reviewed-by: Erez Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260915111912.3926585-5-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlx5/core/steering/hws/bwc.c | 4 +++- .../ethernet/mellanox/mlx5/core/steering/hws/send.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c index 3bcf412a08c4..14a2bb9167a4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c @@ -460,7 +460,9 @@ int mlx5hws_bwc_queue_poll(struct mlx5hws_context *ctx, got_comp = !!ret; if (unlikely(!got_comp && time_after(jiffies, timeout))) { - mlx5hws_err(ctx, "BWC poll error: polling queue %d - TIMEOUT\n", queue_id); + mlx5hws_err(ctx, + "BWC poll error: polling queue %d - TIMEOUT (%d sec)\n", + queue_id, MLX5HWS_BWC_POLLING_TIMEOUT); return -ETIMEDOUT; } } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c index 49dee44d0bef..9ff109fc8230 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c @@ -1192,6 +1192,8 @@ int mlx5hws_send_queue_action(struct mlx5hws_context *ctx, u16 queue_id, u32 actions) { + unsigned long timeout = jiffies + + secs_to_jiffies(MLX5HWS_BWC_POLLING_TIMEOUT); struct mlx5hws_send_ring_sq *send_sq; struct mlx5hws_send_engine *queue; bool wait_comp = false; @@ -1213,9 +1215,18 @@ int mlx5hws_send_queue_action(struct mlx5hws_context *ctx, mlx5hws_send_engine_flush_queue(queue); /* Poll queue until empty */ - while (wait_comp && !mlx5hws_send_engine_empty(queue)) + while (wait_comp && !mlx5hws_send_engine_empty(queue)) { hws_send_engine_poll_cq(queue, NULL, &polled, 0); + if (unlikely(time_after(jiffies, timeout))) { + mlx5hws_err(ctx, + "Error draining send queue %d - TIMEOUT (%d sec)\n", + queue_id, + MLX5HWS_BWC_POLLING_TIMEOUT); + return -ETIMEDOUT; + } + } + break; default: return -EINVAL; From 03d41926d03a4a4000a5e002c570545c12cd78a8 Mon Sep 17 00:00:00 2001 From: Yevgeny Kliteynik Date: Tue, 15 Sep 2026 14:19:11 +0300 Subject: [PATCH 0625/2126] net/mlx5: HWS, Handle timeout draining the send queue for FW STEs Handle a case in mlx5hws_send_stes_fw where draining a queue fails with timeout. Signed-off-by: Yevgeny Kliteynik Reviewed-by: Erez Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260915111912.3926585-6-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlx5/core/steering/hws/send.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c index 9ff109fc8230..bddac018b44b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c @@ -1335,10 +1335,14 @@ void mlx5hws_send_stes_fw(struct mlx5hws_context *ctx, pdn = ctx->pd_num; /* Writing through FW can't HW fence, therefore we drain the queue */ - if (send_attr->fence) - mlx5hws_send_queue_action(ctx, - queue_id, - MLX5HWS_SEND_QUEUE_ACTION_DRAIN_SYNC); + if (send_attr->fence) { + enum mlx5hws_send_queue_actions drain = + MLX5HWS_SEND_QUEUE_ACTION_DRAIN_SYNC; + + ret = mlx5hws_send_queue_action(ctx, queue_id, drain); + if (ret) + goto fail_rule; + } if (ste_attr->rtc_1) { send_attr->id = ste_attr->rtc_1; From 889f1d8c0eb2f47c1b34f53e838693fd42bb783a Mon Sep 17 00:00:00 2001 From: Yevgeny Kliteynik Date: Tue, 15 Sep 2026 14:19:12 +0300 Subject: [PATCH 0626/2126] net/mlx5: HWS, Remove unneeded WRITE_ONCE in post send Remove the unneeded WRITE_ONCE, for two reasons: a) This write is erroneous - it just writes to a local variable and doesn't have any effect. b) This code originated from another place (copy-paste bug), where there was actually a CQ polling right after this line, and the WRITE_ONCE was writing to another place. Signed-off-by: Yevgeny Kliteynik Reviewed-by: Erez Shitrit Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260915111912.3926585-7-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c index bddac018b44b..8b70040eaca0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/send.c @@ -111,9 +111,6 @@ static void hws_send_engine_post_ring(struct mlx5hws_send_ring_sq *sq, wmb(); mlx5_write64((__be32 *)doorbell_cseg, sq->uar_map); - - /* Ensure doorbell is written on uar_page before poll_cq */ - WRITE_ONCE(doorbell_cseg, NULL); } static void From 3e6af2e485e4cb8bcef0690bdc9a60902b77f905 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 16 Sep 2026 23:02:20 +0000 Subject: [PATCH 0627/2126] ip6_gre: Initialise ign->tunnels_wc[0] before register_netdev(). ip6gre_init_net() links the fallback device ip6gre0 to ign->tunnels_wc[0] after publishing it by register_netdev(). While ip6_gre module is being loaded, there is a small race window. If ioctl(SIOCADDTUNNEL) is called before ip6gre0 is linked to the hash table, a new device could be linked to ign->tunnels_wc[0]. Then, the fallback device overwrites ign->tunnels_wc[0], and the new device will be no longer found by ip6gre_tunnel_lookup(), resulting in no RX. Let's link the fallback device before register_netdev(). Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260916230353.367014-2-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_gre.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 8ebda0b6a78b..183218100d69 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -1607,12 +1607,13 @@ static int __net_init ip6gre_init_net(struct net *net) ip6gre_fb_tunnel_init(ign->fb_tunnel_dev); ign->fb_tunnel_dev->rtnl_link_ops = &ip6gre_link_ops; + rcu_assign_pointer(ign->tunnels_wc[0], + netdev_priv(ign->fb_tunnel_dev)); + err = register_netdev(ign->fb_tunnel_dev); if (err) goto err_reg_dev; - rcu_assign_pointer(ign->tunnels_wc[0], - netdev_priv(ign->fb_tunnel_dev)); return 0; err_reg_dev: From 3b2813cc6b1f89de3c694ad3c3a6cd9c924d580b Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 16 Sep 2026 23:02:21 +0000 Subject: [PATCH 0628/2126] ip6_gre: Convert ip6gre_net.tunnels[][] to hlist. struct ip6_tnl has a pointer to the next one. Single linked list requires O(n) iteration for device removal and IPv4 tunnel already uses hlist for its hash table. Let's convert ip6gre_net.tunnels[][] to hlist. Once we convert other users (ip6_tunnel.c, sit.c), we can remove the *next pointer from struct ip6_tnl. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260916230353.367014-3-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/ip6_tunnel.h | 1 + net/ipv6/ip6_gre.c | 91 +++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h index b99805ee2fd1..d1f0a427e9c8 100644 --- a/include/net/ip6_tunnel.h +++ b/include/net/ip6_tunnel.h @@ -45,6 +45,7 @@ struct __ip6_tnl_parm { /* IPv6 tunnel */ struct ip6_tnl { struct ip6_tnl __rcu *next; /* next tunnel in list */ + struct hlist_node hash_node; struct net_device *dev; /* virtual device associated with tunnel */ netdevice_tracker dev_tracker; struct net *net; /* netns for packet i/o */ diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 183218100d69..d3a879fa296e 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -64,7 +64,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); static unsigned int ip6gre_net_id __read_mostly; struct ip6gre_net { - struct ip6_tnl __rcu *tunnels[4][IP6_GRE_HASH_SIZE]; + struct hlist_head tunnels[4][IP6_GRE_HASH_SIZE]; struct ip6_tnl __rcu *collect_md_tun; struct ip6_tnl __rcu *collect_md_tun_erspan; @@ -141,20 +141,24 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev, const struct in6_addr *remote, const struct in6_addr *local, __be32 key, __be16 gre_proto) { - struct net *net = dev_net(dev); - int link = dev->ifindex; - unsigned int h0 = HASH_ADDR(remote); - unsigned int h1 = HASH_KEY(key); - struct ip6_tnl *t, *cand = NULL; - struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); int dev_type = (gre_proto == htons(ETH_P_TEB) || gre_proto == htons(ETH_P_ERSPAN) || gre_proto == htons(ETH_P_ERSPAN2)) ? ARPHRD_ETHER : ARPHRD_IP6GRE; + unsigned int h0 = HASH_ADDR(remote); + unsigned int h1 = HASH_KEY(key); + struct ip6_tnl *t, *cand = NULL; + struct net *net = dev_net(dev); struct net_device *ndev; + struct hlist_head *head; + int link = dev->ifindex; + struct ip6gre_net *ign; int cand_score = 4; - for_each_ip_tunnel_rcu(t, ign->tunnels_r_l[h0 ^ h1]) { + ign = net_generic(net, ip6gre_net_id); + + head = &ign->tunnels_r_l[h0 ^ h1]; + hlist_for_each_entry_rcu(t, head, hash_node) { if (!ipv6_addr_equal(local, &t->parms.laddr) || !ipv6_addr_equal(remote, &t->parms.raddr) || key != t->parms.i_key || @@ -165,7 +169,8 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev, return cand; } - for_each_ip_tunnel_rcu(t, ign->tunnels_r[h0 ^ h1]) { + head = &ign->tunnels_r[h0 ^ h1]; + hlist_for_each_entry_rcu(t, head, hash_node) { if (!ipv6_addr_equal(remote, &t->parms.raddr) || key != t->parms.i_key || !(t->dev->flags & IFF_UP)) @@ -175,7 +180,8 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev, return cand; } - for_each_ip_tunnel_rcu(t, ign->tunnels_l[h1]) { + head = &ign->tunnels_l[h1]; + hlist_for_each_entry_rcu(t, head, hash_node) { if ((!ipv6_addr_equal(local, &t->parms.laddr) && (!ipv6_addr_equal(local, &t->parms.raddr) || !ipv6_addr_is_multicast(local))) || @@ -187,7 +193,8 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev, return cand; } - for_each_ip_tunnel_rcu(t, ign->tunnels_wc[h1]) { + head = &ign->tunnels_wc[h1]; + hlist_for_each_entry_rcu(t, head, hash_node) { if (t->parms.i_key != key || !(t->dev->flags & IFF_UP)) continue; @@ -215,8 +222,8 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev, return NULL; } -static struct ip6_tnl __rcu **__ip6gre_bucket(struct ip6gre_net *ign, - const struct __ip6_tnl_parm *p) +static struct hlist_head *__ip6gre_bucket(struct ip6gre_net *ign, + const struct __ip6_tnl_parm *p) { const struct in6_addr *remote = &p->raddr; const struct in6_addr *local = &p->laddr; @@ -258,56 +265,46 @@ static void ip6erspan_tunnel_unlink_md(struct ip6gre_net *ign, rcu_assign_pointer(ign->collect_md_tun_erspan, NULL); } -static inline struct ip6_tnl __rcu **ip6gre_bucket(struct ip6gre_net *ign, - const struct ip6_tnl *t) +static inline struct hlist_head *ip6gre_bucket(struct ip6gre_net *ign, + const struct ip6_tnl *t) { return __ip6gre_bucket(ign, &t->parms); } static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t) { - struct ip6_tnl __rcu **tp = ip6gre_bucket(ign, t); + struct hlist_head *head = ip6gre_bucket(ign, t); - rcu_assign_pointer(t->next, rtnl_dereference(*tp)); - rcu_assign_pointer(*tp, t); + hlist_add_head_rcu(&t->hash_node, head); } static void ip6gre_tunnel_unlink(struct ip6gre_net *ign, struct ip6_tnl *t) { - struct ip6_tnl __rcu **tp; - struct ip6_tnl *iter; - - for (tp = ip6gre_bucket(ign, t); - (iter = rtnl_dereference(*tp)) != NULL; - tp = &iter->next) { - if (t == iter) { - rcu_assign_pointer(*tp, t->next); - break; - } - } + hlist_del_init_rcu(&t->hash_node); } static struct ip6_tnl *ip6gre_tunnel_find(struct net *net, const struct __ip6_tnl_parm *parms, int type) { + struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); const struct in6_addr *remote = &parms->raddr; const struct in6_addr *local = &parms->laddr; __be32 key = parms->i_key; + struct hlist_head *head; int link = parms->link; struct ip6_tnl *t; - struct ip6_tnl __rcu **tp; - struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); - for (tp = __ip6gre_bucket(ign, parms); - (t = rtnl_dereference(*tp)) != NULL; - tp = &t->next) + head = __ip6gre_bucket(ign, parms); + + hlist_for_each_entry(t, head, hash_node) { if (ipv6_addr_equal(local, &t->parms.laddr) && ipv6_addr_equal(remote, &t->parms.raddr) && key == t->parms.i_key && link == t->parms.link && type == t->dev->type) break; + } return t; } @@ -1551,7 +1548,8 @@ static struct inet6_protocol ip6gre_protocol __read_mostly = { .flags = INET6_PROTO_FINAL, }; -static void __net_exit ip6gre_exit_rtnl_net(struct net *net, struct list_head *head) +static void __net_exit ip6gre_exit_rtnl_net(struct net *net, + struct list_head *dev_kill_list) { struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); struct net_device *dev, *aux; @@ -1561,23 +1559,21 @@ static void __net_exit ip6gre_exit_rtnl_net(struct net *net, struct list_head *h if (dev->rtnl_link_ops == &ip6gre_link_ops || dev->rtnl_link_ops == &ip6gre_tap_ops || dev->rtnl_link_ops == &ip6erspan_tap_ops) - unregister_netdevice_queue(dev, head); + unregister_netdevice_queue(dev, dev_kill_list); for (prio = 0; prio < 4; prio++) { int h; + for (h = 0; h < IP6_GRE_HASH_SIZE; h++) { + struct hlist_head *head = &ign->tunnels[prio][h]; struct ip6_tnl *t; - t = rtnl_net_dereference(net, ign->tunnels[prio][h]); - - while (t) { + hlist_for_each_entry(t, head, hash_node) { /* If dev is in the same netns, it has already * been added to the list by the previous loop. */ if (!net_eq(dev_net(t->dev), net)) - unregister_netdevice_queue(t->dev, head); - - t = rtnl_net_dereference(net, t->next); + unregister_netdevice_queue(t->dev, dev_kill_list); } } } @@ -1587,8 +1583,15 @@ static int __net_init ip6gre_init_net(struct net *net) { struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); struct net_device *ndev; + struct ip6_tnl *t; + int prio, h; int err; + for (prio = 0; prio < 4; prio++) { + for (h = 0; h < IP6_GRE_HASH_SIZE; h++) + INIT_HLIST_HEAD(&ign->tunnels[prio][h]); + } + if (!net_has_fallback_tunnels(net)) return 0; ndev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0", @@ -1607,8 +1610,8 @@ static int __net_init ip6gre_init_net(struct net *net) ip6gre_fb_tunnel_init(ign->fb_tunnel_dev); ign->fb_tunnel_dev->rtnl_link_ops = &ip6gre_link_ops; - rcu_assign_pointer(ign->tunnels_wc[0], - netdev_priv(ign->fb_tunnel_dev)); + t = netdev_priv(ign->fb_tunnel_dev); + hlist_add_head_rcu(&t->hash_node, &ign->tunnels_wc[0]); err = register_netdev(ign->fb_tunnel_dev); if (err) From 28328796e0b4ce5dc8f5fc6078823dc42fcf32dd Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 16 Sep 2026 23:02:22 +0000 Subject: [PATCH 0629/2126] ip6_gre: Clear ign->fb_tunnel_dev in ip6gre_exit_rtnl_net(). ip6gre_dellink() ignores itn->fb_tunnel_dev, so the per-netns fallback tunnel device cannot be removed by userspace. This also makes default_device_exit_batch() impossible to remove the device since it calls ->dellink(). So, ip6gre_exit_rtnl_net() has to iterate devices in the dying netns and call unregister_netdevice_queue() directly, and ip6gre_tunnel_unlink() must be called at ->ndo_uninit(). For per-netns device unregistration, we want to check if the device is being removed in ->dellink(), for which we must call ip6gre_tunnel_unlink() before unregister_netdevice_queue(). As a prep, let's set itn->fb_tunnel_dev to NULL and remove remove for_each_netdev_safe() in ip6gre_exit_rtnl_net(). Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260916230353.367014-4-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_gre.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index d3a879fa296e..d5d98474aeb5 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -374,8 +374,6 @@ static void ip6gre_tunnel_uninit(struct net_device *dev) ip6gre_tunnel_unlink_md(ign, t); ip6gre_tunnel_unlink(ign, t); - if (ign->fb_tunnel_dev == dev) - WRITE_ONCE(ign->fb_tunnel_dev, NULL); dst_cache_reset(&t->dst_cache); netdev_put(dev, &t->dev_tracker); } @@ -1552,29 +1550,20 @@ static void __net_exit ip6gre_exit_rtnl_net(struct net *net, struct list_head *dev_kill_list) { struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); - struct net_device *dev, *aux; int prio; - for_each_netdev_safe(net, dev, aux) - if (dev->rtnl_link_ops == &ip6gre_link_ops || - dev->rtnl_link_ops == &ip6gre_tap_ops || - dev->rtnl_link_ops == &ip6erspan_tap_ops) - unregister_netdevice_queue(dev, dev_kill_list); + WRITE_ONCE(ign->fb_tunnel_dev, NULL); for (prio = 0; prio < 4; prio++) { int h; for (h = 0; h < IP6_GRE_HASH_SIZE; h++) { struct hlist_head *head = &ign->tunnels[prio][h]; + struct hlist_node *tmp; struct ip6_tnl *t; - hlist_for_each_entry(t, head, hash_node) { - /* If dev is in the same netns, it has already - * been added to the list by the previous loop. - */ - if (!net_eq(dev_net(t->dev), net)) - unregister_netdevice_queue(t->dev, dev_kill_list); - } + hlist_for_each_entry_safe(t, tmp, head, hash_node) + unregister_netdevice_queue(t->dev, dev_kill_list); } } } From b7c0d393e108a2f6f56dc36d6c1e03591b0e689e Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 16 Sep 2026 23:02:23 +0000 Subject: [PATCH 0630/2126] ip6_gre: Unlink ip6gre_tunnel_unlink() from ->dellink(). With the previous patch, itn->fb_tunnel_dev can be removed via ->dellink(). However, ioctl(SIOCDELTUNNEL) still uses unregister_netdevice(), which requires ip6gre_tunnel_unlink() in ip6gre_tunnel_uninit(). Let's use __ip6gre_dellink() everywhere to remove ip6gre (and variant) devices and remove ip6gre_tunnel_unlink() and ip6gre_tunnel_unlink_md() in ip6gre_tunnel_uninit(). ip6erspan_tunnel_uninit() is also changed accordingly. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260916230353.367014-5-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_gre.c | 50 +++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index d5d98474aeb5..a9059f3841ac 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -79,6 +79,7 @@ static void ip6gre_tunnel_setup(struct net_device *dev); static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t); static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu); static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu); +static void __ip6gre_dellink(struct net_device *dev, struct list_head *head); /* Tunnel hash table */ @@ -359,10 +360,7 @@ failed_free: static void ip6erspan_tunnel_uninit(struct net_device *dev) { struct ip6_tnl *t = netdev_priv(dev); - struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id); - ip6erspan_tunnel_unlink_md(ign, t); - ip6gre_tunnel_unlink(ign, t); dst_cache_reset(&t->dst_cache); netdev_put(dev, &t->dev_tracker); } @@ -370,10 +368,7 @@ static void ip6erspan_tunnel_uninit(struct net_device *dev) static void ip6gre_tunnel_uninit(struct net_device *dev) { struct ip6_tnl *t = netdev_priv(dev); - struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id); - ip6gre_tunnel_unlink_md(ign, t); - ip6gre_tunnel_unlink(ign, t); dst_cache_reset(&t->dst_cache); netdev_put(dev, &t->dev_tracker); } @@ -1251,14 +1246,15 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data, int cmd) { - int err = 0; - struct ip6_tnl_parm2 p; - struct __ip6_tnl_parm p1; struct ip6_tnl *t = netdev_priv(dev); + struct __ip6_tnl_parm p1 = {}; + LIST_HEAD(dev_kill_list); struct net *net = t->net; - struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); + struct ip6_tnl_parm2 p; + struct ip6gre_net *ign; + int err = 0; - memset(&p1, 0, sizeof(p1)); + ign = net_generic(net, ip6gre_net_id); switch (cmd) { case SIOCGETTUNNEL: @@ -1347,7 +1343,8 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, goto done; dev = t->dev; } - unregister_netdevice(dev); + + __ip6gre_dellink(dev, &dev_kill_list); err = 0; break; @@ -1356,6 +1353,7 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, } done: + unregister_netdevice_many(&dev_kill_list); return err; } @@ -1563,7 +1561,7 @@ static void __net_exit ip6gre_exit_rtnl_net(struct net *net, struct ip6_tnl *t; hlist_for_each_entry_safe(t, tmp, head, hash_node) - unregister_netdevice_queue(t->dev, dev_kill_list); + __ip6gre_dellink(t->dev, dev_kill_list); } } } @@ -2056,13 +2054,31 @@ static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[], return 0; } +static void __ip6gre_dellink(struct net_device *dev, struct list_head *head) +{ + struct ip6_tnl *t = netdev_priv(dev); + struct ip6gre_net *ign; + + ign = net_generic(t->net, ip6gre_net_id); + + if (dev->rtnl_link_ops == &ip6erspan_tap_ops) + ip6erspan_tunnel_unlink_md(ign, t); + else + ip6gre_tunnel_unlink_md(ign, t); + + ip6gre_tunnel_unlink(ign, t); + unregister_netdevice_queue(dev, head); +} + static void ip6gre_dellink(struct net_device *dev, struct list_head *head) { - struct net *net = dev_net(dev); - struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); + struct ip6_tnl *t = netdev_priv(dev); + struct ip6gre_net *ign; + + ign = net_generic(t->net, ip6gre_net_id); if (dev != ign->fb_tunnel_dev) - unregister_netdevice_queue(dev, head); + __ip6gre_dellink(dev, head); } static size_t ip6gre_get_size(const struct net_device *dev) @@ -2304,6 +2320,7 @@ static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = { .validate = ip6gre_tap_validate, .newlink = ip6gre_newlink, .changelink = ip6gre_changelink, + .dellink = ip6gre_dellink, .get_size = ip6gre_get_size, .fill_info = ip6gre_fill_info, .get_link_net = ip6_tnl_get_link_net, @@ -2318,6 +2335,7 @@ static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly = { .validate = ip6erspan_tap_validate, .newlink = ip6erspan_newlink, .changelink = ip6erspan_changelink, + .dellink = ip6gre_dellink, .get_size = ip6gre_get_size, .fill_info = ip6gre_fill_info, .get_link_net = ip6_tnl_get_link_net, From cce829e2aa1d1cbf2f04ab33c3a964220ad19793 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 16 Sep 2026 23:02:24 +0000 Subject: [PATCH 0631/2126] ip6_gre: Protect ip6gre_net.tunnels[][] with mutex. struct ip6_tnl.net is the netns where encapsulated packets flow into. struct ip6_tnl is linked to ip6gre_net.tunnels[][] of netns. During netns dismantle or module unload, ip6gre_exit_rtnl_net() iterates the list and queues devices for destruction regardless of the devices' netns. Thus, once RTNL is removed, the list can be modified concurrently from different netns due to device removal. Let's protect it with per-netns mutex. Note that dev_siocdevprivate() calls netdev_lock_ops() but it must be NOP for tunnel devices to avoid AB-BA deadlock. DEBUG_NET_WARN_ON_ONCE() is added to annotate the locking explicitly. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260916230353.367014-6-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_gre.c | 78 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index a9059f3841ac..ac1087330465 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -65,6 +65,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); static unsigned int ip6gre_net_id __read_mostly; struct ip6gre_net { struct hlist_head tunnels[4][IP6_GRE_HASH_SIZE]; + struct mutex tunnels_lock; struct ip6_tnl __rcu *collect_md_tun; struct ip6_tnl __rcu *collect_md_tun_erspan; @@ -1254,8 +1255,12 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, struct ip6gre_net *ign; int err = 0; + DEBUG_NET_WARN_ON_ONCE(netdev_need_ops_lock(dev)); + ign = net_generic(net, ip6gre_net_id); + mutex_lock(&ign->tunnels_lock); + switch (cmd) { case SIOCGETTUNNEL: if (dev == ign->fb_tunnel_dev) { @@ -1353,6 +1358,8 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, } done: + mutex_unlock(&ign->tunnels_lock); + unregister_netdevice_many(&dev_kill_list); return err; } @@ -1552,6 +1559,8 @@ static void __net_exit ip6gre_exit_rtnl_net(struct net *net, WRITE_ONCE(ign->fb_tunnel_dev, NULL); + mutex_lock(&ign->tunnels_lock); + for (prio = 0; prio < 4; prio++) { int h; @@ -1564,6 +1573,8 @@ static void __net_exit ip6gre_exit_rtnl_net(struct net *net, __ip6gre_dellink(t->dev, dev_kill_list); } } + + mutex_unlock(&ign->tunnels_lock); } static int __net_init ip6gre_init_net(struct net *net) @@ -1579,6 +1590,8 @@ static int __net_init ip6gre_init_net(struct net *net) INIT_HLIST_HEAD(&ign->tunnels[prio][h]); } + mutex_init(&ign->tunnels_lock); + if (!net_has_fallback_tunnels(net)) return 0; ndev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0", @@ -1975,18 +1988,22 @@ static int ip6gre_newlink(struct net_device *dev, struct nlattr **data = params->data; struct nlattr **tb = params->tb; struct ip6gre_net *ign; - int err; + int err = 0; ip6gre_netlink_parms(data, &nt->parms); ign = net_generic(net, ip6gre_net_id); + mutex_lock(&ign->tunnels_lock); + if (nt->parms.collect_md) { if (rtnl_dereference(ign->collect_md_tun)) - return -EEXIST; + err = -EEXIST; } else { if (ip6gre_tunnel_find(net, &nt->parms, dev->type)) - return -EEXIST; + err = -EEXIST; } + if (err) + goto unlock; err = ip6gre_newlink_common(net, dev, tb, data, extack); if (!err) { @@ -1994,6 +2011,10 @@ static int ip6gre_newlink(struct net_device *dev, ip6gre_tunnel_link_md(ign, nt); ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt); } + +unlock: + mutex_unlock(&ign->tunnels_lock); + return err; } @@ -2036,22 +2057,32 @@ static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) { struct ip6_tnl *t = netdev_priv(dev); - struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id); struct __ip6_tnl_parm p; + struct ip6gre_net *ign; + int err = 0; + + ign = net_generic(t->net, ip6gre_net_id); if (!rtnl_dev_link_net_capable(dev, t->net)) return -EPERM; + mutex_lock(&ign->tunnels_lock); + t = ip6gre_changelink_common(dev, tb, data, &p, extack); - if (IS_ERR(t)) - return PTR_ERR(t); + if (IS_ERR(t)) { + err = PTR_ERR(t); + goto unlock; + } ip6gre_tunnel_unlink_md(ign, t); ip6gre_tunnel_unlink(ign, t); ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]); ip6gre_tunnel_link_md(ign, t); ip6gre_tunnel_link(ign, t); - return 0; +unlock: + mutex_unlock(&ign->tunnels_lock); + + return err; } static void __ip6gre_dellink(struct net_device *dev, struct list_head *head) @@ -2077,8 +2108,12 @@ static void ip6gre_dellink(struct net_device *dev, struct list_head *head) ign = net_generic(t->net, ip6gre_net_id); + mutex_lock(&ign->tunnels_lock); + if (dev != ign->fb_tunnel_dev) __ip6gre_dellink(dev, head); + + mutex_unlock(&ign->tunnels_lock); } static size_t ip6gre_get_size(const struct net_device *dev) @@ -2234,19 +2269,23 @@ static int ip6erspan_newlink(struct net_device *dev, struct nlattr **data = params->data; struct nlattr **tb = params->tb; struct ip6gre_net *ign; - int err; + int err = 0; ip6gre_netlink_parms(data, &nt->parms); ip6erspan_set_version(data, &nt->parms); ign = net_generic(net, ip6gre_net_id); + mutex_lock(&ign->tunnels_lock); + if (nt->parms.collect_md) { if (rtnl_dereference(ign->collect_md_tun_erspan)) - return -EEXIST; + err = -EEXIST; } else { if (ip6gre_tunnel_find(net, &nt->parms, dev->type)) - return -EEXIST; + err = -EEXIST; } + if (err) + goto unlock; err = ip6gre_newlink_common(net, dev, tb, data, extack); if (!err) { @@ -2254,6 +2293,10 @@ static int ip6erspan_newlink(struct net_device *dev, ip6erspan_tunnel_link_md(ign, nt); ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt); } + +unlock: + mutex_unlock(&ign->tunnels_lock); + return err; } @@ -2278,14 +2321,20 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[], struct ip6_tnl *t = netdev_priv(dev); struct __ip6_tnl_parm p; struct ip6gre_net *ign; + int err = 0; if (!rtnl_dev_link_net_capable(dev, t->net)) return -EPERM; ign = net_generic(t->net, ip6gre_net_id); + + mutex_lock(&ign->tunnels_lock); + t = ip6gre_changelink_common(dev, tb, data, &p, extack); - if (IS_ERR(t)) - return PTR_ERR(t); + if (IS_ERR(t)) { + err = PTR_ERR(t); + goto unlock; + } ip6erspan_set_version(data, &p); ip6gre_tunnel_unlink_md(ign, t); @@ -2293,7 +2342,10 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[], ip6erspan_tnl_change(t, &p, !tb[IFLA_MTU]); ip6erspan_tunnel_link_md(ign, t); ip6gre_tunnel_link(ign, t); - return 0; +unlock: + mutex_unlock(&ign->tunnels_lock); + + return err; } static struct rtnl_link_ops ip6gre_link_ops __read_mostly = { From b27a8c62875ea917d0010109e96147d48169116f Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 16 Sep 2026 23:02:25 +0000 Subject: [PATCH 0632/2126] ip6_gre: Support per-netns device unregistration. ip6gre_exit_rtnl_net() iterates ip6gre devices and variants whose link_net is dying and queues them for destruction. The devices may reside in different netns. Let's use unregister_netdevice_queue_net() to support per-netns device unregistration. Even after ip6gre_exit_rtnl_net() queues a cross-netns ip6gre device, ip6gre_changelink_common(), ip6gre_dellink(), and ip6gre_tunnel_siocdevprivate() could be called concurrently for it (once RTNL is removed). In such a case, __rtnl_net_unlock() will perform the unregistration. Also, ip6gre_tunnel_siocdevprivate() needs to check check_net(t->net), otherwise it could create a new dev in dying netns after ip6gre_exit_rtnl_net(). In the example below, we can see the fallback tunnel device (ip6gre0) and the cross-netns device (ip6gre1) are unregistered by different processes: # bpftrace -e '#include kprobe:ip6gre_tunnel_uninit { $dev = (struct net_device *)arg0; printf("PID: %d | DEV: %s%s\n", pid, $dev->name, kstack()); } kprobe:ip6gre_exit_rtnl_net { printf("PID: %d%s\n", pid, kstack()); }' & # ip netns add ns1 # ip netns add ns2 # ip -n ns1 link add name ip6gre1 link-netns ns2 \ type ip6gre local 2001:9292::1 remote 2001:9292::2 # ip netns del ns2 PID: 12 ip6gre_exit_rtnl_net+5 ops_undo_list+702 cleanup_net+1122 ... PID: 12 | DEV: ip6gre0 <------ fallback device (itn->fb_tunnel_dev). ip6gre_tunnel_uninit+5 unregister_netdevice_many_notify+7137 unregister_netdevice_many_net+1050 __rtnl_net_unlock+37 ops_undo_list+754 cleanup_net+1122 ... PID: 10 | DEV: ip6gre1 ip6gre_tunnel_uninit+5 unregister_netdevice_many_notify+7137 unregister_netdevice_many_net+1050 rtnl_net_work_func+136 Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260916230353.367014-7-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_gre.c | 51 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index ac1087330465..c851af22b9fe 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -80,7 +80,8 @@ static void ip6gre_tunnel_setup(struct net_device *dev); static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t); static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu); static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu); -static void __ip6gre_dellink(struct net_device *dev, struct list_head *head); +static void __ip6gre_dellink(struct net *net, struct net_device *dev, + struct list_head *head); /* Tunnel hash table */ @@ -285,6 +286,11 @@ static void ip6gre_tunnel_unlink(struct ip6gre_net *ign, struct ip6_tnl *t) hlist_del_init_rcu(&t->hash_node); } +static bool ip6gre_tunnel_unregistering(struct ip6_tnl *t) +{ + return hlist_unhashed(&t->hash_node); +} + static struct ip6_tnl *ip6gre_tunnel_find(struct net *net, const struct __ip6_tnl_parm *parms, int type) @@ -1248,6 +1254,7 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, int cmd) { struct ip6_tnl *t = netdev_priv(dev); + struct net *orig_net = dev_net(dev); struct __ip6_tnl_parm p1 = {}; LIST_HEAD(dev_kill_list); struct net *net = t->net; @@ -1261,6 +1268,11 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, mutex_lock(&ign->tunnels_lock); + if (!check_net(net)) { + err = -EBUSY; + goto done; + } + switch (cmd) { case SIOCGETTUNNEL: if (dev == ign->fb_tunnel_dev) { @@ -1302,7 +1314,7 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, t = ip6gre_tunnel_locate(net, &p1, cmd == SIOCADDTUNNEL); if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) { - if (t) { + if (t && !ip6gre_tunnel_unregistering(t)) { if (t->dev != dev) { err = -EEXIST; break; @@ -1310,23 +1322,26 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, } else { t = netdev_priv(dev); - ip6gre_tunnel_unlink(ign, t); - synchronize_net(); - ip6gre_tnl_change(t, &p1, 1); - ip6gre_tunnel_link(ign, t); - netdev_state_change(dev); + if (!ip6gre_tunnel_unregistering(t)) { + ip6gre_tunnel_unlink(ign, t); + synchronize_net(); + ip6gre_tnl_change(t, &p1, 1); + ip6gre_tunnel_link(ign, t); + netdev_state_change(dev); + } } } - if (t) { + if (t && !ip6gre_tunnel_unregistering(t)) { err = 0; memset(&p, 0, sizeof(p)); ip6gre_tnl_parm_to_user(&p, &t->parms); if (copy_to_user(data, &p, sizeof(p))) err = -EFAULT; - } else + } else { err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT); + } break; case SIOCDELTUNNEL: @@ -1349,7 +1364,8 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev, dev = t->dev; } - __ip6gre_dellink(dev, &dev_kill_list); + if (!ip6gre_tunnel_unregistering(t)) + __ip6gre_dellink(orig_net, dev, &dev_kill_list); err = 0; break; @@ -1570,7 +1586,7 @@ static void __net_exit ip6gre_exit_rtnl_net(struct net *net, struct ip6_tnl *t; hlist_for_each_entry_safe(t, tmp, head, hash_node) - __ip6gre_dellink(t->dev, dev_kill_list); + __ip6gre_dellink(net, t->dev, dev_kill_list); } } @@ -2049,6 +2065,9 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[], t = nt; } + if (ip6gre_tunnel_unregistering(t)) + return ERR_PTR(-ENODEV); + return t; } @@ -2085,7 +2104,8 @@ unlock: return err; } -static void __ip6gre_dellink(struct net_device *dev, struct list_head *head) +static void __ip6gre_dellink(struct net *net, struct net_device *dev, + struct list_head *head) { struct ip6_tnl *t = netdev_priv(dev); struct ip6gre_net *ign; @@ -2098,7 +2118,7 @@ static void __ip6gre_dellink(struct net_device *dev, struct list_head *head) ip6gre_tunnel_unlink_md(ign, t); ip6gre_tunnel_unlink(ign, t); - unregister_netdevice_queue(dev, head); + unregister_netdevice_queue_net(net, dev, head); } static void ip6gre_dellink(struct net_device *dev, struct list_head *head) @@ -2110,8 +2130,9 @@ static void ip6gre_dellink(struct net_device *dev, struct list_head *head) mutex_lock(&ign->tunnels_lock); - if (dev != ign->fb_tunnel_dev) - __ip6gre_dellink(dev, head); + if (dev != ign->fb_tunnel_dev && + !ip6gre_tunnel_unregistering(t)) + __ip6gre_dellink(dev_net(dev), dev, head); mutex_unlock(&ign->tunnels_lock); } From e3bfd25626b44b6fa61a13c17178922171d519ce Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Tue, 15 Sep 2026 22:01:30 +0200 Subject: [PATCH 0633/2126] net: dsa: motorcomm: avoid unused variable warning The 'priv' variable is defined before an #ifdef block but used inside of it: drivers/net/dsa/motorcomm/chip.c: In function 'yt921x_dsa_teardown': drivers/net/dsa/motorcomm/chip.c:4229:29: error: unused variable 'priv' [-Werror=unused-variable] Move it one line down. Fixes: 9af9a8168213 ("net: dsa: motorcomm: Add LED support") Signed-off-by: Arnd Bergmann Link: https://patch.msgid.link/20260915200148.3523045-1-arnd@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index d663af010f43..8b0ac5fc8c8b 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -4226,9 +4226,9 @@ static int yt921x_edata_read(struct yt921x_priv *priv, u8 addr, u8 *valp) static void yt921x_dsa_teardown(struct dsa_switch *ds) { +#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) struct yt921x_priv *priv = to_yt921x_priv(ds); -#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) yt921x_leds_remove(priv); #endif } From a4e22e9253e7ed017bc4da89f88c711737b72784 Mon Sep 17 00:00:00 2001 From: Birger Koblitz Date: Wed, 16 Sep 2026 05:24:02 +0200 Subject: [PATCH 0634/2126] ax88179_178a: Fix endianness of pause watermark register The 16-bit pause watermark register is little endian as described in the ASIX 4.1.0 out-of-tree driver. Correct the register byte sequence but also swap the configuration values used in the code in order to keep the current behaviour. The endianness is relevant for 16-bit writes to the register. Signed-off-by: Birger Koblitz Reviewed-by: Andrew Lunn Tested-by: Jianhui Xu Link: https://patch.msgid.link/20260916-ax88179a-v12-3-60c04c9924a2@birger-koblitz.de Signed-off-by: Jakub Kicinski --- drivers/net/usb/ax88179_178a.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 81d8412ce8e2..2ed46ab62c00 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -32,8 +32,8 @@ #define AX_ACCESS_EEPROM 0x04 #define AX_ACCESS_EFUS 0x05 #define AX_RELOAD_EEPROM_EFUSE 0x06 -#define AX_PAUSE_WATERLVL_HIGH 0x54 -#define AX_PAUSE_WATERLVL_LOW 0x55 +#define AX_PAUSE_WATERLVL_LOW 0x54 +#define AX_PAUSE_WATERLVL_HIGH 0x55 #define PHYSICAL_LINK_STATUS 0x02 #define AX_USB_SS 0x04 @@ -1619,11 +1619,10 @@ static int ax88179_reset(struct usbnet *dev) dev->rx_urb_size = 1024 * 20; *tmp = 0x34; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1, 1, tmp); *tmp = 0x52; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, - 1, 1, tmp); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); /* Enable checksum offload */ *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | From cffde9e49e8626cd5a9182e63da9cb6b68276098 Mon Sep 17 00:00:00 2001 From: illusion wang Date: Mon, 14 Sep 2026 20:34:15 +0800 Subject: [PATCH 0635/2126] net/nebula-matrix: add minimum nbl build framework This patch adds the minimum build infrastructure: 1. Add Kconfig, Makefile and MAINTAINERS entries; 2. Add corresponding driver documentation; 3. Add PCI driver skeleton with empty stubs for nbl driver. Note: the documentation describes the final full driver features; implementation will be added in subsequent patches of this series. Signed-off-by: illusion wang Link: https://patch.msgid.link/20260914123429.56596-2-illusion.wang@nebula-matrix.com Signed-off-by: Jakub Kicinski --- .../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/nbl.rst | 28 +++++ MAINTAINERS | 10 ++ drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 32 ++++++ drivers/net/ethernet/nebula-matrix/Makefile | 6 ++ .../net/ethernet/nebula-matrix/nbl/Makefile | 6 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 13 +++ .../nbl/nbl_include/nbl_include.h | 14 +++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 100 ++++++++++++++++++ 11 files changed, 212 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst create mode 100644 drivers/net/ethernet/nebula-matrix/Kconfig create mode 100644 drivers/net/ethernet/nebula-matrix/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c diff --git a/Documentation/networking/device_drivers/ethernet/index.rst b/Documentation/networking/device_drivers/ethernet/index.rst index d9980c84487a..403ae9c2b06a 100644 --- a/Documentation/networking/device_drivers/ethernet/index.rst +++ b/Documentation/networking/device_drivers/ethernet/index.rst @@ -48,6 +48,7 @@ Contents: meta/fbnic microsoft/netvsc mucse/rnpgbe + nebula-matrix/nbl netronome/nfp pensando/ionic pensando/ionic_rdma diff --git a/Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst b/Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file mode 100644 index 000000000000..5540291cf376 --- /dev/null +++ b/Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst @@ -0,0 +1,28 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================================================ +Linux Base Driver for Nebula-matrix m18110-NIC/m18000-NIC family +================================================================ + +Overview: +========= +The m18110-NIC/m18000-NIC (marketed as SNIC s1000) is a series +of network interface cards for the Data Center Area. + +This driver provides the core infrastructure for m18110/m18000-NIC +devices, including: + +- PCI device enumeration and resource (BAR) management +- Firmware command interface via PF mailbox +- Channel-based communication between driver and firmware +- Device initialization and teardown + +Support +======= + +For more information about m18110-NIC/m18000-NIC, please visit the following URL: +https://www.nebula-matrix.com/snic_s1000_en + +If an issue is identified with the released source code on the supported kernel +with a supported adapter, email the specific information related to the issue to +open@nebula-matrix.com. diff --git a/MAINTAINERS b/MAINTAINERS index d1a3ec390096..df8ab9b82402 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18801,6 +18801,16 @@ F: Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml F: Documentation/hwmon/nct7363.rst F: drivers/hwmon/nct7363.c +NEBULA-MATRIX ETHERNET DRIVER (nebula-matrix) +M: Illusion Wang +M: Dimon Zhao +M: Alvin Wang +M: Sam Chen +L: netdev@vger.kernel.org +S: Maintained +F: Documentation/networking/device_drivers/ethernet/nebula-matrix/ +F: drivers/net/ethernet/nebula-matrix/ + NETCONSOLE M: Breno Leitao S: Maintained diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig index 8581ccba1505..c2b0161d0bec 100644 --- a/drivers/net/ethernet/Kconfig +++ b/drivers/net/ethernet/Kconfig @@ -130,6 +130,7 @@ config FEALNX source "drivers/net/ethernet/ni/Kconfig" source "drivers/net/ethernet/natsemi/Kconfig" +source "drivers/net/ethernet/nebula-matrix/Kconfig" source "drivers/net/ethernet/netronome/Kconfig" source "drivers/net/ethernet/8390/Kconfig" source "drivers/net/ethernet/nvidia/Kconfig" diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile index 2b1153d35b52..a306dae23bcb 100644 --- a/drivers/net/ethernet/Makefile +++ b/drivers/net/ethernet/Makefile @@ -67,6 +67,7 @@ obj-$(CONFIG_NET_VENDOR_MUCSE) += mucse/ obj-$(CONFIG_NET_VENDOR_MYRI) += myricom/ obj-$(CONFIG_FEALNX) += fealnx.o obj-$(CONFIG_NET_VENDOR_NATSEMI) += natsemi/ +obj-$(CONFIG_NET_VENDOR_NEBULA_MATRIX) += nebula-matrix/ obj-$(CONFIG_NET_VENDOR_NETRONOME) += netronome/ obj-$(CONFIG_NET_VENDOR_NI) += ni/ obj-$(CONFIG_NET_VENDOR_NVIDIA) += nvidia/ diff --git a/drivers/net/ethernet/nebula-matrix/Kconfig b/drivers/net/ethernet/nebula-matrix/Kconfig new file mode 100644 index 000000000000..dd0e91d14131 --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/Kconfig @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Nebula-matrix network device configuration +# + +config NET_VENDOR_NEBULA_MATRIX + bool "Nebula-matrix devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Nebula-matrix cards. If you say Y, you will be asked + for your specific card in the following questions. + +if NET_VENDOR_NEBULA_MATRIX + +config NBL + tristate "Nebula-matrix Ethernet Controller m18110/m18000 support" + depends on PCI && (64BIT || COMPILE_TEST) && !CPU_BIG_ENDIAN + help + This driver provides the core infrastructure for Nebula-matrix + Ethernet Controller m18110/m18000 Family of devices, including + PCI enumeration, firmware mailbox and channel communication. + + More specific information on configuring the driver is in + . + + To compile this driver as a module, choose M here. The module + will be called nbl. + +endif # NET_VENDOR_NEBULA_MATRIX diff --git a/drivers/net/ethernet/nebula-matrix/Makefile b/drivers/net/ethernet/nebula-matrix/Makefile new file mode 100644 index 000000000000..42cdf2db8f0c --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the Nebula-matrix network device drivers. +# + +obj-$(CONFIG_NBL) += nbl/ diff --git a/drivers/net/ethernet/nebula-matrix/nbl/Makefile b/drivers/net/ethernet/nebula-matrix/nbl/Makefile new file mode 100644 index 000000000000..6c14d1071c0c --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 Nebula Matrix Limited. + +obj-$(CONFIG_NBL) := nbl.o + +nbl-objs += nbl_main.o diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file mode 100644 index 000000000000..a3d63c698aea --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_CORE_H_ +#define _NBL_CORE_H_ + +enum { + NBL_CAP_HAS_NET_BIT, +}; + +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h new file mode 100644 index 000000000000..16b10bcf1d36 --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_INCLUDE_H_ +#define _NBL_INCLUDE_H_ + +#include + +/* ------ Basic definitions ------- */ +#define NBL_DRIVER_NAME "nbl" + +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file mode 100644 index 000000000000..199626159a4c --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#include +#include +#include +#include +#include "nbl_include/nbl_include.h" +#include "nbl_core.h" + +static int nbl_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + return -ENODEV; +} + +static void nbl_remove(struct pci_dev *pdev) +{ +} + +/* + * PCI Device IDs for Leonis/NBL Network Controllers + * + * Vendor ID: 0x1F0F + * SNIC v3r1 product Device IDs range: 0x3403-0x3412 + */ +#define NBL_VENDOR_ID 0x1F0F + +#define NBL_DEVICE_ID_M18110 0x3403 +#define NBL_DEVICE_ID_M18110_LX 0x3404 +#define NBL_DEVICE_ID_M18110_BASE_T 0x3405 +#define NBL_DEVICE_ID_M18110_LX_BASE_T 0x3406 +#define NBL_DEVICE_ID_M18110_OCP 0x3407 +#define NBL_DEVICE_ID_M18110_LX_OCP 0x3408 +#define NBL_DEVICE_ID_M18110_BASE_T_OCP 0x3409 +#define NBL_DEVICE_ID_M18110_LX_BASE_T_OCP 0x340a +#define NBL_DEVICE_ID_M18000 0x340b +#define NBL_DEVICE_ID_M18000_LX 0x340c +#define NBL_DEVICE_ID_M18000_BASE_T 0x340d +#define NBL_DEVICE_ID_M18000_LX_BASE_T 0x340e +#define NBL_DEVICE_ID_M18000_OCP 0x340f +#define NBL_DEVICE_ID_M18000_LX_OCP 0x3410 +#define NBL_DEVICE_ID_M18000_BASE_T_OCP 0x3411 +#define NBL_DEVICE_ID_M18000_LX_BASE_T_OCP 0x3412 + +/* All below IDs belong to Leonis ASIC family, different form-factor variants, + * share the same hardware initialization flow without differentiated ops. + */ +static const struct pci_device_id nbl_id_table[] = { + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_LX), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_BASE_T), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_LX_BASE_T), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_LX_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_BASE_T_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110_LX_BASE_T_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_LX), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_BASE_T), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_LX_BASE_T), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_LX_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_BASE_T_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_LX_BASE_T_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, + /* required as sentinel */ + { } +}; +MODULE_DEVICE_TABLE(pci, nbl_id_table); + +static struct pci_driver nbl_driver = { + .name = NBL_DRIVER_NAME, + .id_table = nbl_id_table, + .probe = nbl_probe, + .remove = nbl_remove, +}; + +module_pci_driver(nbl_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Nebula Matrix Network Driver"); +MODULE_AUTHOR("Illusion Wang "); From 825e6d230163b34f37d1202cf5b86c1ae5822efc Mon Sep 17 00:00:00 2001 From: illusion wang Date: Mon, 14 Sep 2026 20:34:16 +0800 Subject: [PATCH 0636/2126] net/nebula-matrix: add core driver architecture and HW layer initialization Add the fundamental driver architecture framework and Leonis hardware layer initialization for NBL NIC family. - nbl_adapter/nbl_core/nbl_common_info core device context - PCI probe/remove entry and basic device capability parsing - Leonis hardware BAR resource request and ioremap logic This patch establishes the lowest HW layer and core infrastructure, preparing for subsequent device implementations. Note: This commit binds the PCI device during probe, but does not create or register netdev. Netdev support will be added in later patches of this series. This intermediate state is safe: hardware BARs are mapped. Chip configuration and the mailbox control path are brought up by this series, and Ethernet data path RX/TX queues plus data-plane interrupts remain unconfigured and disabled at this stage. Signed-off-by: illusion wang Link: https://patch.msgid.link/20260914123429.56596-3-illusion.wang@nebula-matrix.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/nebula-matrix/nbl/Makefile | 3 +- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 18 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 153 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 15 ++ .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 31 ++++ .../nbl/nbl_include/nbl_def_common.h | 31 ++++ .../nbl/nbl_include/nbl_def_hw.h | 17 ++ .../nbl/nbl_include/nbl_include.h | 9 ++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 94 ++++++++++- 9 files changed, 369 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h diff --git a/drivers/net/ethernet/nebula-matrix/nbl/Makefile b/drivers/net/ethernet/nebula-matrix/nbl/Makefile index 6c14d1071c0c..cc060cf8bf75 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/Makefile +++ b/drivers/net/ethernet/nebula-matrix/nbl/Makefile @@ -3,4 +3,5 @@ obj-$(CONFIG_NBL) := nbl.o -nbl-objs += nbl_main.o +nbl-objs += nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \ + nbl_main.o diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h index a3d63c698aea..1cd6587a8fcb 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h @@ -6,8 +6,26 @@ #ifndef _NBL_CORE_H_ #define _NBL_CORE_H_ +#include +#include "nbl_include/nbl_include.h" +#include "nbl_include/nbl_def_common.h" + enum { NBL_CAP_HAS_NET_BIT, }; +struct nbl_core { + struct nbl_hw_mgt *hw_mgt; +}; + +struct nbl_adapter { + struct pci_dev *pdev; + struct nbl_core core; + struct nbl_common_info common; +}; + +struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, + struct nbl_init_param *param); +void nbl_core_remove(struct nbl_adapter *adapter); + #endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file mode 100644 index 000000000000..cf40ddc45192 --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ +#include +#include +#include +#include +#include "nbl_hw_leonis.h" + +/* Structure starts here, adding an op should not modify anything below */ +static struct nbl_hw_mgt *nbl_hw_setup_hw_mgt(struct nbl_common_info *common) +{ + struct device *dev = common->dev; + struct nbl_hw_mgt *hw_mgt; + + hw_mgt = devm_kzalloc(dev, sizeof(*hw_mgt), GFP_KERNEL); + if (!hw_mgt) + return ERR_PTR(-ENOMEM); + + hw_mgt->common = common; + + return hw_mgt; +} + +static int nbl_pcim_request_selected_bars(struct pci_dev *pdev, u32 mask, + const char *name) +{ + int bar; + int ret; + + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + if (!(mask & BIT(bar))) + continue; + ret = pcim_request_region(pdev, bar, name); + if (ret) + return ret; + } + return 0; +} + +int nbl_hw_init_leonis(struct nbl_adapter *adapter) +{ + resource_size_t expect_sz = NBL_MEM_BAR_TOTAL_SIZE; + struct nbl_common_info *common = &adapter->common; + struct pci_dev *pdev = common->pdev; + struct nbl_hw_mgt *hw_mgt = NULL; + resource_size_t bar_len; + resource_size_t hw_size; + u32 bar_mask; + int ret; + + hw_mgt = nbl_hw_setup_hw_mgt(common); + if (IS_ERR(hw_mgt)) { + ret = PTR_ERR(hw_mgt); + goto setup_mgt_fail; + } + bar_mask = BIT(NBL_MEMORY_BAR) | BIT(NBL_MAILBOX_BAR); + ret = nbl_pcim_request_selected_bars(pdev, bar_mask, NBL_DRIVER_NAME); + if (ret) { + dev_err(&pdev->dev, + "Request memory bar failed, err = %d\n", + ret); + goto setup_mgt_fail; + } + + bar_len = pci_resource_len(pdev, NBL_MEMORY_BAR); + if (!(pci_resource_flags(pdev, NBL_MEMORY_BAR) & IORESOURCE_MEM)) { + dev_err(&pdev->dev, "MEMORY BAR is not memory resource\n"); + ret = -EINVAL; + goto setup_mgt_fail; + } + if (common->has_ctrl) { + /* + * Hardware layout: MEMORY BAR total size is 64M. + * The tail NBL_RDMA_NOTIFY_LEN bytes of the 64M BAR are + * reserved exclusively for RDMA notify hardware. + * Ethernet driver must avoid mapping this reserved tail + * to prevent x86 PAT aliasing conflict between eth net + * mapping and RDMA driver WC mapping. Mapping starts + * at BAR offset 0. + * + * Skip trailing NBL_RDMA_NOTIFY_LEN bytes at BAR tail. + * Round size down to page boundary to avoid ioremap + * rounding up and accidentally including RDMA reserved + * region when PAGE_SIZE > 8KiB. + */ + if (bar_len < NBL_MEM_BAR_TOTAL_SIZE) { + dev_err(&pdev->dev, + "MEMORY BAR len %pa smaller than expected %pa\n", + &bar_len, &expect_sz); + ret = -EINVAL; + goto setup_mgt_fail; + } + hw_size = PAGE_ALIGN_DOWN(NBL_MEM_BAR_TOTAL_SIZE - + NBL_RDMA_NOTIFY_LEN); + hw_mgt->hw_addr = + pcim_iomap(pdev, NBL_MEMORY_BAR, + hw_size); + } else { + if (bar_len < NBL_REG_NET_ONLY_LEN) { + dev_err(&pdev->dev, + "MEMORY BAR len %pa too small for net only reg space\n", + &bar_len); + ret = -EINVAL; + goto setup_mgt_fail; + } + hw_size = NBL_REG_NET_ONLY_LEN; + hw_mgt->hw_addr = pcim_iomap(pdev, NBL_MEMORY_BAR, + hw_size); + } + if (!hw_mgt->hw_addr) { + dev_err(&pdev->dev, "MEMORY BAR pcim_iomap failed\n"); + ret = -EIO; + goto setup_mgt_fail; + } + + bar_len = pci_resource_len(pdev, NBL_MAILBOX_BAR); + if (!(pci_resource_flags(pdev, NBL_MAILBOX_BAR) & IORESOURCE_MEM)) { + dev_err(&pdev->dev, "MAILBOX BAR is not memory resource\n"); + ret = -EINVAL; + goto setup_mgt_fail; + } + if (bar_len < NBL_BAR2_MAX_LEN) { + dev_err(&pdev->dev, "MAILBOX BAR length %pa too small\n", + &bar_len); + ret = -EINVAL; + goto setup_mgt_fail; + } + hw_mgt->mailbox_bar_hw_addr = pcim_iomap(pdev, NBL_MAILBOX_BAR, + bar_len); + if (!hw_mgt->mailbox_bar_hw_addr) { + dev_err(&pdev->dev, "MAILBOX BAR pcim_iomap failed\n"); + ret = -EIO; + goto setup_mgt_fail; + } + + hw_mgt->mailbox_bar_size = bar_len; + + adapter->core.hw_mgt = hw_mgt; + + return 0; + +setup_mgt_fail: + return ret; +} + +void nbl_hw_remove_leonis(struct nbl_adapter *adapter) +{ + /* All BAR mappings & PCI regions are managed by pcim/devres, + * no manual iounmap / release required + */ +} diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h new file mode 100644 index 000000000000..1f9e509dc631 --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_HW_LEONIS_H_ +#define _NBL_HW_LEONIS_H_ + +#include + +#include "../../nbl_include/nbl_include.h" +#include "../nbl_hw_reg.h" + +#define NBL_BAR2_MAX_LEN 0x300 +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file mode 100644 index 000000000000..e281109f502e --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_HW_REG_H_ +#define _NBL_HW_REG_H_ + +#include + +#include "../nbl_include/nbl_def_hw.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +#define NBL_MEMORY_BAR 0 +#define NBL_MAILBOX_BAR 2 +#define NBL_RDMA_NOTIFY_LEN (8ULL << 10) +#define NBL_REG_NET_ONLY_LEN (8ULL << 10) +/* + * PCI MEMORY BAR total size: 64MiB. + */ +#define NBL_MEM_BAR_TOTAL_SIZE (64ULL << 20) + +struct nbl_hw_mgt { + struct nbl_common_info *common; + u8 __iomem *hw_addr; + u8 __iomem *mailbox_bar_hw_addr; + resource_size_t mailbox_bar_size; +}; + +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file mode 100644 index 000000000000..ea646d1efc2d --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_DEF_COMMON_H_ +#define _NBL_DEF_COMMON_H_ + +#include +#include +#include +#include "nbl_include.h" + +struct nbl_common_info { + struct pci_dev *pdev; + struct device *dev; + u16 vsi_id; + u8 eth_id; + u8 logic_eth_id; + u8 eth_num; + + u8 function; + u8 devid; + u8 bus; + u8 hw_bus; + + u8 has_ctrl; + u8 has_net; +}; + +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h new file mode 100644 index 000000000000..ecbf440e4366 --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_DEF_HW_H_ +#define _NBL_DEF_HW_H_ + +#include + +struct nbl_hw_mgt; +struct nbl_adapter; + +int nbl_hw_init_leonis(struct nbl_adapter *adapter); +void nbl_hw_remove_leonis(struct nbl_adapter *adapter); + +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h index 16b10bcf1d36..14e7b19f9a4c 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h @@ -10,5 +10,14 @@ /* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl" +struct nbl_func_caps { + u32 has_ctrl:1; + u32 has_net:1; + u32 rsv:30; +}; + +struct nbl_init_param { + struct nbl_func_caps caps; +}; #endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c index 199626159a4c..f2552bc73293 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c @@ -8,16 +8,108 @@ #include #include #include "nbl_include/nbl_include.h" +#include "nbl_include/nbl_def_hw.h" +#include "nbl_include/nbl_def_common.h" #include "nbl_core.h" +struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, + struct nbl_init_param *param) +{ + struct nbl_common_info *common; + struct nbl_adapter *adapter; + int ret; + + adapter = devm_kzalloc(&pdev->dev, sizeof(*adapter), GFP_KERNEL); + if (!adapter) + return ERR_PTR(-ENOMEM); + + adapter->pdev = pdev; + common = &adapter->common; + + common->pdev = pdev; + common->dev = &pdev->dev; + common->has_ctrl = param->caps.has_ctrl; + common->has_net = param->caps.has_net; + common->function = PCI_FUNC(pdev->devfn); + common->devid = PCI_SLOT(pdev->devfn); + common->bus = pdev->bus->number; + + ret = nbl_hw_init_leonis(adapter); + if (ret) + goto hw_init_fail; + + return adapter; +hw_init_fail: + return ERR_PTR(ret); +} + +void nbl_core_remove(struct nbl_adapter *adapter) +{ + nbl_hw_remove_leonis(adapter); +} + +static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, + struct nbl_init_param *param) +{ + param->caps.has_net = !!(driver_data & BIT(NBL_CAP_HAS_NET_BIT)); + + /* + * Hardware fixed rule: physical PF0 is the only management PF with + * global ctrl capability. All PFs share identical PCI device ID, so + * distinguish control PF via physical function ID. + * + * Hardware & firmware design FORBID passing any PF through to virtual + * machines, there is no scenario where a non-management PF appears + * as Func 0 inside guest. Thus using PCI_FUNC(pdev->devfn) to identify + * control PF is safe on our platform. + */ + if ((PCI_FUNC(pdev->devfn) == 0) && !pdev->is_virtfn) + param->caps.has_ctrl = 1; +} + static int nbl_probe(struct pci_dev *pdev, const struct pci_device_id *id) { - return -ENODEV; + struct nbl_init_param param = { { 0 } }; + struct device *dev = &pdev->dev; + struct nbl_adapter *adapter; + int err; + + err = pcim_enable_device(pdev); + if (err) { + dev_err(&pdev->dev, "Failed to enable PCI dev, err=%d\n", err); + return err; + } + + nbl_get_func_param(pdev, id->driver_data, ¶m); + /* never return fail when DMA_BIT_MASK(64) */ + dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + + pci_set_master(pdev); + + adapter = nbl_core_init(pdev, ¶m); + if (IS_ERR(adapter)) { + dev_err(dev, "Nbl adapter init fail: %pe\n", adapter); + err = PTR_ERR(adapter); + goto adapter_init_err; + } + pci_set_drvdata(pdev, adapter); + return 0; +adapter_init_err: + pci_clear_master(pdev); + return err; } static void nbl_remove(struct pci_dev *pdev) { + struct nbl_adapter *adapter = pci_get_drvdata(pdev); + + if (!adapter) + return; + pci_set_drvdata(pdev, NULL); + nbl_core_remove(adapter); + + pci_clear_master(pdev); } /* From 52fb7cca01e11b7df9c7c4988d619dddd46cc170 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Tue, 15 Sep 2026 23:14:03 +0200 Subject: [PATCH 0637/2126] ieee802154: avoid deprecated .ndo_do_ioctl callback The ieee802154 socket implementation is the last remaining caller of the netdevice ioctl callback. In order to completely remove this, add a custom pointer to the existing wpan_dev specific operations structure. Since that structure is currently only used to wrap the 'create' header operation, adjust the naming slightly to make this more generic. It would be a good idea to adjust the calling conventions and split the get/set operations into separate functions, but that can be a follow-up cleanup. For the moment, I kept the actual changes to a minimum to avoid regressions. Link: https://lore.kernel.org/all/20231011140225.253106-2-arnd@kernel.org/ Signed-off-by: Arnd Bergmann Link: https://patch.msgid.link/20260915211538.1519815-1-arnd@kernel.org Signed-off-by: Jakub Kicinski --- include/net/cfg802154.h | 9 +++++---- net/ieee802154/socket.c | 5 +++-- net/mac802154/iface.c | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h index 2e960441ea49..2c5dcf6a106f 100644 --- a/include/net/cfg802154.h +++ b/include/net/cfg802154.h @@ -458,15 +458,16 @@ struct ieee802154_llsec_device_key { u32 frame_counter; }; -struct wpan_dev_header_ops { +struct wpan_dev_ops { /* TODO create callback currently assumes ieee802154_mac_cb inside * skb->cb. This should be changed to give these information as * parameter. */ - int (*create)(struct sk_buff *skb, struct net_device *dev, + int (*header_create)(struct sk_buff *skb, struct net_device *dev, const struct ieee802154_addr *daddr, const struct ieee802154_addr *saddr, unsigned int len); + int (*ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); }; struct wpan_dev { @@ -477,7 +478,7 @@ struct wpan_dev { struct list_head list; struct net_device *netdev; - const struct wpan_dev_header_ops *header_ops; + const struct wpan_dev_ops *ops; /* lowpan interface, set when the wpan_dev belongs to one lowpan_dev */ struct net_device *lowpan_dev; @@ -523,7 +524,7 @@ wpan_dev_hard_header(struct sk_buff *skb, struct net_device *dev, { struct wpan_dev *wpan_dev = dev->ieee802154_ptr; - return wpan_dev->header_ops->create(skb, dev, daddr, saddr, len); + return wpan_dev->ops->header_create(skb, dev, daddr, saddr, len); } #endif diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c index 5a36e87893f6..be8ca1f053a2 100644 --- a/net/ieee802154/socket.c +++ b/net/ieee802154/socket.c @@ -139,8 +139,9 @@ static int ieee802154_dev_ioctl(struct sock *sk, struct ifreq __user *arg, if (!dev) return -ENODEV; - if (dev->type == ARPHRD_IEEE802154 && dev->netdev_ops->ndo_do_ioctl) - ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, cmd); + if (dev->type == ARPHRD_IEEE802154 && dev->ieee802154_ptr && + dev->ieee802154_ptr->ops) + ret = dev->ieee802154_ptr->ops->ioctl(dev, &ifr, cmd); if (!ret && put_user_ifreq(&ifr, arg)) ret = -EFAULT; diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c index 799f94347667..f437b8daa00d 100644 --- a/net/mac802154/iface.c +++ b/net/mac802154/iface.c @@ -406,8 +406,9 @@ static int ieee802154_header_create(struct sk_buff *skb, return hlen; } -static const struct wpan_dev_header_ops ieee802154_header_ops = { - .create = ieee802154_header_create, +static const struct wpan_dev_ops ieee802154_ops = { + .header_create = ieee802154_header_create, + .ioctl = mac802154_wpan_ioctl, }; /* This header create functionality assumes a 8 byte array for @@ -497,7 +498,6 @@ static const struct net_device_ops mac802154_wpan_ops = { .ndo_open = mac802154_wpan_open, .ndo_stop = mac802154_slave_close, .ndo_start_xmit = ieee802154_subif_start_xmit, - .ndo_do_ioctl = mac802154_wpan_ioctl, .ndo_set_mac_address = mac802154_wpan_mac_addr, }; @@ -583,7 +583,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, sdata->dev->netdev_ops = &mac802154_wpan_ops; sdata->dev->ml_priv = &mac802154_mlme_wpan; sdata->iface_default_filtering = IEEE802154_FILTERING_4_FRAME_FIELDS; - wpan_dev->header_ops = &ieee802154_header_ops; + wpan_dev->ops = &ieee802154_ops; mutex_init(&sdata->sec_mtx); From d98a52ae914e9fef700047f1eca486087abb13db Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Tue, 15 Sep 2026 23:14:04 +0200 Subject: [PATCH 0638/2126] net: remove ndo_do_ioctl handler All of the references to the callback pointer are gone, so remove the pointer itself before we grow new references to it. Signed-off-by: Arnd Bergmann Link: https://patch.msgid.link/20260915211538.1519815-2-arnd@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/networking/netdevices.rst | 7 ------- include/linux/netdevice.h | 7 ------- 2 files changed, 14 deletions(-) diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index aac33497813f..6a87f09e7015 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -222,13 +222,6 @@ ndo_stop: Context: process Note: netif_running() is guaranteed false -ndo_do_ioctl: - Synchronization: rtnl_lock() semaphore. - - This is only called by network subsystems internally, - not by user space calling ioctl as it was in before - linux-5.14. - ndo_siocbond: Synchronization: rtnl_lock() semaphore. In addition, netdev instance lock if the driver implements queue management or shaper API. diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 1f0710eef185..5d16737167ee 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1154,11 +1154,6 @@ struct netdev_net_notifier { * int (*ndo_validate_addr)(struct net_device *dev); * Test if Media Access Control address is valid for the device. * - * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); - * Old-style ioctl entry point. This is used internally by the - * ieee802154 subsystem but is no longer called by the device - * ioctl handler. - * * int (*ndo_siocbond)(struct net_device *dev, struct ifreq *ifr, int cmd); * Used by the bonding driver for its device specific ioctls: * SIOCBONDENSLAVE, SIOCBONDRELEASE, SIOCBONDSETHWADDR, SIOCBONDCHANGEACTIVE, @@ -1480,8 +1475,6 @@ struct net_device_ops { int (*ndo_set_mac_address)(struct net_device *dev, void *addr); int (*ndo_validate_addr)(struct net_device *dev); - int (*ndo_do_ioctl)(struct net_device *dev, - struct ifreq *ifr, int cmd); int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); int (*ndo_siocbond)(struct net_device *dev, From 5ac134441dc8c70d1a70b0503c1157e6b0463a27 Mon Sep 17 00:00:00 2001 From: Jijie Shao Date: Tue, 15 Sep 2026 21:23:41 +0800 Subject: [PATCH 0639/2126] net: hibmcge: fix spelling mistakes in comments and identifiers Fix several typos found in the driver: - hbg_irq.c: macro parameter "ndde_reset" -> "need_reset" - hbg_txrx.c: macro "hbg_queue_next_prt" -> "hbg_queue_next_ptr" (and its call sites) - hbg_txrx.c: function "hbg_ring_page_pool_destory" -> "hbg_ring_page_pool_destroy" - hbg_common.h: comment "after rest" -> "after reset" - hbg_reg.h: register macro "HBG_REG_BRUST_LENGTH_*" -> "HBG_REG_BURST_LENGTH_*" (and references in hbg_hw.c) No functional changes. Signed-off-by: Jijie Shao Link: https://patch.msgid.link/20260915132341.1138610-1-shaojijie@huawei.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h | 2 +- drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c | 4 ++-- drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c | 4 ++-- drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h | 4 ++-- drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h index 8e134da3e217..9ca04909774d 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_common.h @@ -152,7 +152,7 @@ struct hbg_mac_filter { bool enabled; }; -/* saved for restore after rest */ +/* saved for restore after reset */ struct hbg_user_def { struct ethtool_pauseparam pause_param; }; diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c index d6e8ce8e351a..54ed1c17bc2d 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -190,8 +190,8 @@ void hbg_hw_set_mtu(struct hbg_priv *priv, u16 mtu) hbg_hw_set_pcu_max_frame_len(priv, frame_len); hbg_hw_set_mac_max_frame_len(priv, frame_len); - hbg_reg_write_field(priv, HBG_REG_BRUST_LENGTH_ADDR, - HBG_REG_BRUST_LENGTH_B, burst_len_bit); + hbg_reg_write_field(priv, HBG_REG_BURST_LENGTH_ADDR, + HBG_REG_BURST_LENGTH_B, burst_len_bit); } void hbg_hw_mac_enable(struct hbg_priv *priv, u32 enable) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c index ae4cb35186d8..2d67c7557b72 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_irq.c @@ -37,9 +37,9 @@ static void hbg_irq_handle_rx_buf_val(struct hbg_priv *priv, #define HBG_IRQ_I(name, handle) \ {#name, HBG_INT_MSK_##name##_B, false, false, false, handle} -#define HBG_ERR_IRQ_I(name, need_print, ndde_reset) \ +#define HBG_ERR_IRQ_I(name, need_print, need_reset) \ {#name, HBG_INT_MSK_##name##_B, true, need_print, \ - ndde_reset, hbg_irq_handle_err} + need_reset, hbg_irq_handle_err} static const struct hbg_irq_info hbg_irqs[] = { HBG_IRQ_I(RX, hbg_irq_handle_rx), diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h index 30b3903c8f2d..0d2554ca3b5f 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_reg.h @@ -191,8 +191,8 @@ #define HBG_REG_TX_CFF_ADDR_2_ADDR (HBG_REG_SGMII_BASE + 0x0490) #define HBG_REG_TX_CFF_ADDR_3_ADDR (HBG_REG_SGMII_BASE + 0x0494) #define HBG_REG_RX_CFF_ADDR_ADDR (HBG_REG_SGMII_BASE + 0x04A0) -#define HBG_REG_BRUST_LENGTH_ADDR (HBG_REG_SGMII_BASE + 0x04C4) -#define HBG_REG_BRUST_LENGTH_B BIT(29) +#define HBG_REG_BURST_LENGTH_ADDR (HBG_REG_SGMII_BASE + 0x04C4) +#define HBG_REG_BURST_LENGTH_B BIT(29) #define HBG_REG_RX_BUF_SIZE_ADDR (HBG_REG_SGMII_BASE + 0x04E4) #define HBG_REG_RX_BUF_SIZE_M GENMASK(15, 0) #define HBG_REG_BUS_CTRL_ADDR (HBG_REG_SGMII_BASE + 0x04E8) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c index 207ada721dd9..2ea025fd964f 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c @@ -26,10 +26,10 @@ (hbg_queue_used_num((head), (tail), (ring)) == 0) #define hbg_queue_is_full(head, tail, ring) \ (hbg_queue_left_num((head), (tail), (ring)) == 0) -#define hbg_queue_next_prt(p, ring) (((p) + 1) % (ring)->len) +#define hbg_queue_next_ptr(p, ring) (((p) + 1) % (ring)->len) #define hbg_queue_move_next(p, ring) ({ \ typeof(ring) _ring = (ring); \ - _ring->p = hbg_queue_next_prt(_ring->p, _ring); }) + _ring->p = hbg_queue_next_ptr(_ring->p, _ring); }) #define hbg_get_page_order(ring) ({ \ typeof(ring) _ring = (ring); \ @@ -167,7 +167,7 @@ netdev_tx_t hbg_net_start_xmit(struct sk_buff *skb, struct net_device *netdev) /* This smp_store_release() pairs with smp_load_acquire() in * hbg_napi_tx_recycle() called in tx interrupt handle process. */ - smp_store_release(&ring->ntu, hbg_queue_next_prt(ntu, ring)); + smp_store_release(&ring->ntu, hbg_queue_next_ptr(ntu, ring)); dev_sw_netstats_tx_add(netdev, 1, skb->len); return NETDEV_TX_OK; } @@ -220,7 +220,7 @@ static int hbg_napi_tx_recycle(struct napi_struct *napi, int budget) break; hbg_buffer_free(buffer); - ntc = hbg_queue_next_prt(ntc, ring); + ntc = hbg_queue_next_ptr(ntc, ring); packet_done++; } @@ -535,7 +535,7 @@ next_buffer: return packet_done; } -static void hbg_ring_page_pool_destory(struct hbg_ring *ring) +static void hbg_ring_page_pool_destroy(struct hbg_ring *ring) { if (!ring->page_pool) return; @@ -589,7 +589,7 @@ static void hbg_ring_uninit(struct hbg_ring *ring) buffer->priv = NULL; } - hbg_ring_page_pool_destory(ring); + hbg_ring_page_pool_destroy(ring); dma_free_coherent(&ring->priv->pdev->dev, ring->len * sizeof(*ring->queue), ring->queue, ring->queue_dma); From 5f22f5fb90516ed98886c4ae22d27edef92b8d1e Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Wed, 16 Sep 2026 16:13:06 +0800 Subject: [PATCH 0640/2126] r8169: set eee_enable_default base on LPI cap When initializing phylink configuration, if LPI capabilities is non-zero, it indicates the hardware supports EEE, thus we enable it by default. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20260916081306.184-1-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 5415ff62a286..1d06ddff9832 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -5945,6 +5945,7 @@ static int rtl_init_phylink(struct rtl8169_private *tp) tp->phylink_config.type = PHYLINK_NETDEV; tp->phylink_config.mac_managed_pm = true; tp->phylink_config.lpi_capabilities = rtl8169_get_lpi_caps(tp); + tp->phylink_config.eee_enabled_default = !!tp->phylink_config.lpi_capabilities; tp->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE; switch (tp->sfp_mode) { From ca44c21fc117215fdd65c087a19c048ccd52a26e Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Wed, 16 Sep 2026 16:14:42 +0800 Subject: [PATCH 0641/2126] net: phy: realtek: add support for RTL8261CE_CG Add support for RTL8261CE_CG, its phy id is 0x001cc899. RTL8261CE_CG share the same sub_phy_id and firmware with RTL8261C_CG. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260916081444.497-2-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/phy/realtek/realtek_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 97b0b67b9900..d0d09e8e8f5c 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -257,6 +257,7 @@ #define RTL_8251B 0x001cc862 #define RTL_8261C 0x001cc890 #define RTL_8261C_CG 0x001cc898 +#define RTL_8261CE_CG 0x001cc899 #define RTL8261C_CE_MODEL 0x00 #define RTL8261D_MODEL 0x81 @@ -3363,6 +3364,19 @@ static struct phy_driver realtek_drvs[] = { .soft_reset = genphy_c45_pma_soft_reset, .suspend = genphy_c45_pma_suspend, .resume = genphy_c45_pma_resume, + }, { + PHY_ID_MATCH_EXACT(RTL_8261CE_CG), + .name = "Realtek RTL8261CE 10Gbps PHY", + .probe = rtl8261x_probe, + .config_init = rtl8261x_config_init, + .get_features = rtl8261x_get_features, + .config_aneg = rtl8261x_config_aneg, + .read_status = rtl8261x_read_status, + .config_intr = rtl8261x_config_intr, + .handle_interrupt = rtl8261x_handle_interrupt, + .soft_reset = genphy_c45_pma_soft_reset, + .suspend = genphy_c45_pma_suspend, + .resume = genphy_c45_pma_resume, }, }; From c1edd457d21691550ac225e3315aea33d28f246c Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Wed, 16 Sep 2026 16:14:43 +0800 Subject: [PATCH 0642/2126] net: phy: realtek: add firmware for RTL8261D Add support for RTL8261D to load firmware. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260916081444.497-3-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/phy/realtek/realtek_main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index d0d09e8e8f5c..61e602948931 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -286,11 +286,15 @@ #define FW_MAIN_MAGIC 0x52544C38 #define FW_SUB_MAGIC_8261C 0x32363143 +#define FW_SUB_MAGIC_8261D 0x32363144 #define RTL8261X_POLL_TIMEOUT_MS 100 #define RTL8261X_MAX_MMD_DEV 31 #define RTL8261C_CE_FW_NAME "rtl_nic/rtl8261c.bin" +#define RTL8261D_FW_NAME "rtl_nic/rtl8261d.bin" + MODULE_FIRMWARE(RTL8261C_CE_FW_NAME); +MODULE_FIRMWARE(RTL8261D_FW_NAME); enum rtl8261x_fw_op { OP_WRITE = 0x00, /* Write */ @@ -342,6 +346,7 @@ struct rtl821x_priv { struct rtl8261x_priv { const char *fw_name; + u32 fw_sub_magic; bool fw_loaded; }; @@ -411,10 +416,13 @@ static int rtl8261x_probe(struct phy_device *phydev) switch (sub_phy_id) { case RTL8261C_CE_MODEL: priv->fw_name = RTL8261C_CE_FW_NAME; + priv->fw_sub_magic = FW_SUB_MAGIC_8261C; phydev_info(phydev, "RTL8261C detected (sub_id 0x%02x)\n", sub_phy_id); break; case RTL8261D_MODEL: + priv->fw_name = RTL8261D_FW_NAME; + priv->fw_sub_magic = FW_SUB_MAGIC_8261D; phydev_info(phydev, "RTL8261D detected (sub_id 0x%02x)\n", sub_phy_id); break; @@ -473,6 +481,7 @@ static int rtl8261x_read_status(struct phy_device *phydev) static int rtl8261x_verify_firmware(struct phy_device *phydev, const struct firmware *fw) { + struct rtl8261x_priv *priv = phydev->priv; const struct rtl8261x_fw_header *hdr; u32 main_magic, sub_magic; u32 calc_crc, file_crc; @@ -493,7 +502,7 @@ static int rtl8261x_verify_firmware(struct phy_device *phydev, const struct firm } sub_magic = le32_to_cpu(hdr->sub_magic); - if (sub_magic != FW_SUB_MAGIC_8261C) { + if (sub_magic != priv->fw_sub_magic) { phydev_err(phydev, "Invalid sub magic: 0x%08x\n", sub_magic); return -EINVAL; } From 5a13a6152fd0ef309712c2083bae6bffce3638a5 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Wed, 16 Sep 2026 16:14:44 +0800 Subject: [PATCH 0643/2126] net: phy: realtek: add support for RTL8261D_VM Add support for RTL8261D_VM, its phy id is 0x001cc89a. Signed-off-by: Javen Xu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260916081444.497-4-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/phy/realtek/realtek_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 61e602948931..1e670638dd1c 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -258,6 +258,7 @@ #define RTL_8261C 0x001cc890 #define RTL_8261C_CG 0x001cc898 #define RTL_8261CE_CG 0x001cc899 +#define RTL_8261D_VM 0x001cc89a #define RTL8261C_CE_MODEL 0x00 #define RTL8261D_MODEL 0x81 @@ -3386,6 +3387,19 @@ static struct phy_driver realtek_drvs[] = { .soft_reset = genphy_c45_pma_soft_reset, .suspend = genphy_c45_pma_suspend, .resume = genphy_c45_pma_resume, + }, { + PHY_ID_MATCH_EXACT(RTL_8261D_VM), + .name = "Realtek RTL8261D_VM 10Gbps PHY", + .probe = rtl8261x_probe, + .config_init = rtl8261x_config_init, + .get_features = rtl8261x_get_features, + .config_aneg = rtl8261x_config_aneg, + .read_status = rtl8261x_read_status, + .config_intr = rtl8261x_config_intr, + .handle_interrupt = rtl8261x_handle_interrupt, + .soft_reset = genphy_c45_pma_soft_reset, + .suspend = genphy_c45_pma_suspend, + .resume = genphy_c45_pma_resume, }, }; From a907a89ff105272aaab6b184c08f91d4a5b67b91 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Wed, 16 Sep 2026 17:14:20 +0800 Subject: [PATCH 0644/2126] net: gro_cells: add drop reasons to gro_cells_receive() gro_cells_receive() reports SKB_DROP_REASON_NOT_SPECIFIED when the device is down or the GRO cell queue length exceeds max_backlog. Pass SKB_DROP_REASON_DEV_READY and SKB_DROP_REASON_CPU_BACKLOG to kfree_skb_reason() for these two cases, respectively. Suggested-by: Eric Dumazet Signed-off-by: Xuanqiang Luo Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260916091420.138170-1-xuanqiang.luo@linux.dev Signed-off-by: Jakub Kicinski --- net/core/gro_cells.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/core/gro_cells.c b/net/core/gro_cells.c index d8c0a2867120..1d64207bf960 100644 --- a/net/core/gro_cells.c +++ b/net/core/gro_cells.c @@ -14,11 +14,13 @@ struct gro_cell { int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb) { struct net_device *dev = skb->dev; + enum skb_drop_reason reason; bool have_bh_lock = false; struct gro_cell *cell; int res; rcu_read_lock(); + reason = SKB_DROP_REASON_DEV_READY; if (unlikely(!(dev->flags & IFF_UP))) goto drop; @@ -34,9 +36,10 @@ int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb) cell = this_cpu_ptr(gcells->cells); if (skb_queue_len(&cell->napi_skbs) > READ_ONCE(net_hotdata.max_backlog)) { + reason = SKB_DROP_REASON_CPU_BACKLOG; drop: dev_core_stats_rx_dropped_inc(dev); - kfree_skb(skb); + kfree_skb_reason(skb, reason); res = NET_RX_DROP; goto unlock; } From 8830e65ed46de41f849eefb8ba227d4852c460f6 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 17 Sep 2026 20:39:52 +0800 Subject: [PATCH 0645/2126] net: use assign_bit() where applicable Convert open-coded if/else with set_bit/clear_bit and their non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit API. Done with Coccinelle semantic patch: // set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); // clear_bit -> set_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond); // __set_bit -> __clear_bit => __assign_bit @@ expression cond, bit, addr; @@ -if (cond) - __set_bit(bit, addr); -else - __clear_bit(bit, addr); +__assign_bit(bit, addr, cond); // __clear_bit -> __set_bit => __assign_bit @@ expression cond, bit, addr; @@ -if (cond) - __clear_bit(bit, addr); -else - __set_bit(bit, addr); +__assign_bit(bit, addr, !cond); Signed-off-by: Peng Fan Reviewed-by: Ratheesh Kannoth Link: https://patch.msgid.link/20260917-net-assign-bit-v1-1-e9c97965e080@nxp.com Signed-off-by: Jakub Kicinski --- drivers/net/can/slcan/slcan-core.c | 5 +--- drivers/net/ethernet/amd/xgbe/xgbe-mdio.c | 5 +--- .../net/ethernet/aquantia/atlantic/aq_nic.c | 5 +--- .../net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 18 +++---------- drivers/net/ethernet/freescale/enetc/enetc.c | 5 +--- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 10 ++----- .../hisilicon/hns3/hns3pf/hclge_mbx.c | 7 ++--- .../net/ethernet/intel/i40e/i40e_ethtool.c | 10 ++----- .../ethernet/intel/i40e/i40e_virtchnl_pf.c | 5 +--- drivers/net/ethernet/intel/ice/ice_ethtool.c | 5 +--- drivers/net/ethernet/intel/ice/ice_txclk.c | 20 +++++--------- .../net/ethernet/marvell/octeontx2/af/cgx.c | 10 ++----- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 5 +--- .../ethernet/marvell/octeontx2/af/rvu_nix.c | 15 +++-------- .../ethernet/marvell/octeontx2/af/rvu_npa.c | 10 ++----- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 6 ++--- .../ethernet/mellanox/mlx5/core/fw_reset.c | 6 ++--- drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 8 ++---- .../ethernet/pensando/ionic/ionic_ethtool.c | 10 ++----- .../net/ethernet/qlogic/qede/qede_ethtool.c | 6 ++--- drivers/net/ethernet/qlogic/qla3xxx.c | 18 +++++-------- .../net/ethernet/qlogic/qlcnic/qlcnic_dcb.c | 5 +--- .../qlogic/qlcnic/qlcnic_sriov_common.c | 6 ++--- .../ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c | 6 ++--- drivers/net/ethernet/wangxun/libwx/wx_ptp.c | 5 +--- drivers/net/phy/mediatek/mtk-phy-lib.c | 26 ++++++------------- drivers/net/wireless/ath/ath10k/debug.c | 10 ++----- drivers/net/wireless/ath/ath10k/snoc.c | 6 ++--- drivers/net/wireless/ath/ath11k/htc.c | 5 +--- drivers/net/wireless/ath/ath12k/htc.c | 5 +--- drivers/net/wireless/ath/ath9k/ar9003_calib.c | 5 +--- drivers/net/wireless/ath/ath9k/mci.c | 5 +--- .../wireless/mediatek/mt76/mt76_connac_mcu.c | 5 +--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 5 +--- drivers/net/wireless/realtek/rtw88/debug.c | 5 +--- drivers/net/wireless/realtek/rtw89/core.c | 5 +--- drivers/net/wireless/realtek/rtw89/mac.c | 10 ++----- drivers/net/wireless/realtek/rtw89/regd.c | 5 +--- drivers/net/wireless/ti/wlcore/rx.c | 5 +--- 39 files changed, 77 insertions(+), 236 deletions(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 7439849d5c84..c9414faafe66 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -131,10 +131,7 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) if (netif_running(ndev)) return -EBUSY; - if (on) - set_bit(CF_ERR_RST, &sl->cmd_flags); - else - clear_bit(CF_ERR_RST, &sl->cmd_flags); + assign_bit(CF_ERR_RST, &sl->cmd_flags, on); return 0; } diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c index 12770af031eb..c56587384d57 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c @@ -1202,10 +1202,7 @@ static int __xgbe_phy_config_aneg(struct xgbe_prv_data *pdata, bool set_mode) xgbe_an_restart(pdata); out: - if (ret) - set_bit(XGBE_LINK_ERR, &pdata->dev_state); - else - clear_bit(XGBE_LINK_ERR, &pdata->dev_state); + assign_bit(XGBE_LINK_ERR, &pdata->dev_state, ret); mutex_unlock(&pdata->an_mutex); diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c index 01792f7abf96..42e0fe9248f2 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c @@ -1717,10 +1717,7 @@ int aq_nic_setup_tc_min_rate(struct aq_nic_s *self, const unsigned int tc, if (tc >= AQ_CFG_TCS_MAX) return -EINVAL; - if (min_rate) - set_bit(tc, &cfg->tc_min_rate_msk); - else - clear_bit(tc, &cfg->tc_min_rate_msk); + assign_bit(tc, &cfg->tc_min_rate_msk, min_rate); if (min_rate && min_rate < 20) { netdev_warn(self->ndev, diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c index b8af508f9c98..b337e61f9c81 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c @@ -207,10 +207,7 @@ void bnx2x_vfop_qctor_prep(struct bnx2x *bp, */ __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags); __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags); - if (vf->spoofchk) - __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags); - else - __clear_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags); + __assign_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags, vf->spoofchk); /* Setup-op rx parameters */ if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) { @@ -2370,12 +2367,8 @@ static int bnx2x_set_pf_tx_switching(struct bnx2x *bp, bool enable) q_params.cmd = BNX2X_Q_CMD_UPDATE; __set_bit(BNX2X_Q_UPDATE_TX_SWITCHING_CHNG, &q_params.params.update.update_flags); - if (enable) - __set_bit(BNX2X_Q_UPDATE_TX_SWITCHING, - &q_params.params.update.update_flags); - else - __clear_bit(BNX2X_Q_UPDATE_TX_SWITCHING, - &q_params.params.update.update_flags); + __assign_bit(BNX2X_Q_UPDATE_TX_SWITCHING, + &q_params.params.update.update_flags, enable); /* send the ramrod on all the queues of the PF */ for_each_eth_queue(bp, i) { @@ -2764,10 +2757,7 @@ static void bnx2x_set_vf_vlan_acceptance(struct bnx2x *bp, /* need to remove/add the VF's accept_any_vlan bit */ accept_flags = bnx2x_leading_vfq(vf, accept_flags); - if (accept) - set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); - else - clear_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); + assign_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags, accept); bnx2x_vf_prep_rx_mode(bp, LEADING_IDX, &rx_ramrod, vf, accept_flags); diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 04c49b680709..c6571b5cc842 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -88,10 +88,7 @@ void enetc_set_congestion_mode(struct enetc_ndev_priv *priv, bool enable) spin_lock(&si->gen_lock); - if (enable) - set_bit(ENETC_RXBDR_CM, &priv->flags); - else - clear_bit(ENETC_RXBDR_CM, &priv->flags); + assign_bit(ENETC_RXBDR_CM, &priv->flags, enable); for (int i = 0; i < priv->num_rx_rings; i++) { u32 old_rbmr = enetc_rxbdr_rd(hw, i, ENETC_RBMR); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c index e7318f236315..7b92a3c73ef6 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -474,10 +474,7 @@ static void hns3_update_limit_promisc_mode(struct net_device *netdev, { struct hnae3_handle *handle = hns3_get_handle(netdev); - if (enable) - set_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags); - else - clear_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags); + assign_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags, enable); hns3_request_update_promisc_mode(handle); } @@ -1210,10 +1207,7 @@ static int hns3_set_tx_push(struct net_device *netdev, u32 tx_push) netdev_dbg(netdev, "Changing tx push from %s to %s\n", str_on_off(old_state), str_on_off(tx_push)); - if (tx_push) - set_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state); - else - clear_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state); + assign_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state, tx_push); return 0; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c index 30e38cb4843a..08040a492985 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c @@ -341,11 +341,8 @@ static void hclge_set_vf_promisc_mode(struct hclge_vport *vport, vport->vf_info.request_mc_en = req->msg.en_mc; vport->vf_info.request_bc_en = req->msg.en_bc; - if (req->msg.en_limit_promisc) - set_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags); - else - clear_bit(HNAE3_PFLAG_LIMIT_PROMISC, - &handle->priv_flags); + assign_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags, + req->msg.en_limit_promisc); set_bit(HCLGE_VPORT_STATE_PROMISC_CHANGE, &vport->state); hclge_task_schedule(hdev, 0); diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index ef9d1e78c16a..6a992df06fa1 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -5263,10 +5263,7 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags) test_bit(priv_flag->bitno, orig_flags) != new_val) return -EOPNOTSUPP; - if (new_val) - set_bit(priv_flag->bitno, new_flags); - else - clear_bit(priv_flag->bitno, new_flags); + assign_bit(priv_flag->bitno, new_flags, new_val); } if (pf->hw.pf_id != 0) @@ -5284,10 +5281,7 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags) test_bit(priv_flag->bitno, orig_flags) != new_val) return -EOPNOTSUPP; - if (new_val) - set_bit(priv_flag->bitno, new_flags); - else - clear_bit(priv_flag->bitno, new_flags); + assign_bit(priv_flag->bitno, new_flags, new_val); } flags_complete: diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index a26c3d47ec15..0087f7ae0c4c 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -1158,10 +1158,7 @@ static int i40e_alloc_vf_res(struct i40e_vf *vf) pf->queues_left -= total_queue_pairs - I40E_DEFAULT_QUEUES_PER_VF; - if (vf->trusted) - set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps); - else - clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps); + assign_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps, vf->trusted); /* store the total qps number for the runtime * VF req validation diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c index bf9a821c543b..51388ec05a90 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -1751,10 +1751,7 @@ static int ice_set_priv_flags(struct net_device *netdev, u32 flags) priv_flag = &ice_gstrings_priv_flags[i]; - if (flags & BIT(i)) - set_bit(priv_flag->bitno, pf->flags); - else - clear_bit(priv_flag->bitno, pf->flags); + assign_bit(priv_flag->bitno, pf->flags, flags & BIT(i)); } bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS); diff --git a/drivers/net/ethernet/intel/ice/ice_txclk.c b/drivers/net/ethernet/intel/ice/ice_txclk.c index 48459f971cbf..3bca4443f03a 100644 --- a/drivers/net/ethernet/intel/ice/ice_txclk.c +++ b/drivers/net/ethernet/intel/ice/ice_txclk.c @@ -286,12 +286,9 @@ void ice_txclk_update_and_notify(struct ice_pf *pf) if (ctrl_pf != pf) mutex_lock(&ctrl_pf->dplls.lock); for (int i = 0; i < ICE_REF_CLK_MAX; i++) { - if (clk == i) - set_bit(ptp_port->port_num, - &ctrl_pf->ptp.tx_refclks[phy][i]); - else - clear_bit(ptp_port->port_num, - &ctrl_pf->ptp.tx_refclks[phy][i]); + assign_bit(ptp_port->port_num, + &ctrl_pf->ptp.tx_refclks[phy][i], + clk == i); } if (ctrl_pf != pf) mutex_unlock(&ctrl_pf->dplls.lock); @@ -315,13 +312,10 @@ void ice_txclk_update_and_notify(struct ice_pf *pf) */ if (ctrl_pf != pf) mutex_lock(&ctrl_pf->dplls.lock); - for (int i = 0; i < ICE_REF_CLK_MAX; i++) - if (clk == i) - set_bit(ptp_port->port_num, - &ctrl_pf->ptp.tx_refclks[phy][i]); - else - clear_bit(ptp_port->port_num, - &ctrl_pf->ptp.tx_refclks[phy][i]); + for (int i = 0; i < ICE_REF_CLK_MAX; i++) { + assign_bit(ptp_port->port_num, + &ctrl_pf->ptp.tx_refclks[phy][i], clk == i); + } if (ctrl_pf != pf) mutex_unlock(&ctrl_pf->dplls.lock); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c index 8ced44a4495e..ade394c2beba 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -981,15 +981,9 @@ int verify_lmac_fc_cfg(void *cgxd, int lmac_id, u8 tx_pause, u8 rx_pause, if (!lmac) return -ENODEV; - if (!rx_pause) - clear_bit(pfvf_idx, lmac->rx_fc_pfvf_bmap.bmap); - else - set_bit(pfvf_idx, lmac->rx_fc_pfvf_bmap.bmap); + assign_bit(pfvf_idx, lmac->rx_fc_pfvf_bmap.bmap, rx_pause); - if (!tx_pause) - clear_bit(pfvf_idx, lmac->tx_fc_pfvf_bmap.bmap); - else - set_bit(pfvf_idx, lmac->tx_fc_pfvf_bmap.bmap); + assign_bit(pfvf_idx, lmac->tx_fc_pfvf_bmap.bmap, tx_pause); /* check if other pfvfs are using flow control */ if (!rx_pause && bitmap_weight(lmac->rx_fc_pfvf_bmap.bmap, lmac->rx_fc_pfvf_bmap.max)) { diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 2b67671a2bd8..7c829b1da3e5 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -857,10 +857,7 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr, } update_en_map: - if (enable) - set_bit(index, npc_priv->en_map); - else - clear_bit(index, npc_priv->en_map); + assign_bit(index, npc_priv->en_map, enable); return 0; } diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c index d80d2c00bd84..93c5c4b298bf 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -1233,28 +1233,19 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw, ena = (req->rq.ena & req->rq_mask.ena) | (test_bit(req->qidx, pfvf->rq_bmap) & ~req->rq_mask.ena); - if (ena) - __set_bit(req->qidx, pfvf->rq_bmap); - else - __clear_bit(req->qidx, pfvf->rq_bmap); + __assign_bit(req->qidx, pfvf->rq_bmap, ena); } if (req->ctype == NIX_AQ_CTYPE_SQ) { ena = (req->rq.ena & req->sq_mask.ena) | (test_bit(req->qidx, pfvf->sq_bmap) & ~req->sq_mask.ena); - if (ena) - __set_bit(req->qidx, pfvf->sq_bmap); - else - __clear_bit(req->qidx, pfvf->sq_bmap); + __assign_bit(req->qidx, pfvf->sq_bmap, ena); } if (req->ctype == NIX_AQ_CTYPE_CQ) { ena = (req->rq.ena & req->cq_mask.ena) | (test_bit(req->qidx, pfvf->cq_bmap) & ~req->cq_mask.ena); - if (ena) - __set_bit(req->qidx, pfvf->cq_bmap); - else - __clear_bit(req->qidx, pfvf->cq_bmap); + __assign_bit(req->qidx, pfvf->cq_bmap, ena); } } diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npa.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npa.c index e2a33e46b48a..334dc3e888f4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npa.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npa.c @@ -169,10 +169,7 @@ int rvu_npa_aq_enq_inst(struct rvu *rvu, struct npa_aq_enq_req *req, ena = (req->aura.ena & req->aura_mask.ena) | (test_bit(req->aura_id, pfvf->aura_bmap) & ~req->aura_mask.ena); - if (ena) - __set_bit(req->aura_id, pfvf->aura_bmap); - else - __clear_bit(req->aura_id, pfvf->aura_bmap); + __assign_bit(req->aura_id, pfvf->aura_bmap, ena); } } @@ -184,10 +181,7 @@ int rvu_npa_aq_enq_inst(struct rvu *rvu, struct npa_aq_enq_req *req, ena = (req->pool.ena & req->pool_mask.ena) | (test_bit(req->aura_id, pfvf->pool_bmap) & ~req->pool_mask.ena); - if (ena) - __set_bit(req->aura_id, pfvf->pool_bmap); - else - __clear_bit(req->aura_id, pfvf->pool_bmap); + __assign_bit(req->aura_id, pfvf->pool_bmap, ena); } } spin_unlock(&aq->lock); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index 3ed59ced0407..261c466a4d36 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -2320,10 +2320,8 @@ static int set_pflag_rx_no_csum_complete(struct net_device *netdev, bool enable) for (i = 0; i < channels->num; i++) { c = channels->c[i]; - if (enable) - __set_bit(MLX5E_RQ_STATE_NO_CSUM_COMPLETE, &c->rq.state); - else - __clear_bit(MLX5E_RQ_STATE_NO_CSUM_COMPLETE, &c->rq.state); + __assign_bit(MLX5E_RQ_STATE_NO_CSUM_COMPLETE, &c->rq.state, + enable); } return 0; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c b/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c index 07440c58713a..7c0585fe1ee7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c @@ -66,10 +66,8 @@ static int mlx5_fw_reset_enable_remote_dev_reset_set(struct devlink *devlink, u3 fw_reset = dev->priv.fw_reset; - if (ctx->val.vbool) - clear_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, &fw_reset->reset_flags); - else - set_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, &fw_reset->reset_flags); + assign_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, + &fw_reset->reset_flags, !ctx->val.vbool); return 0; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c b/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c index bc0f38b6a2b2..ab6e342ec3fa 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c @@ -126,12 +126,8 @@ void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd, set_bit(FBNIC_MAC_ADDR_T_BMC, mac_addr->act_tcam); mac_addr->state = FBNIC_TCAM_S_ADD; } - if (enable_host) - set_bit(FBNIC_MAC_ADDR_T_ALLMULTI, - mac_addr->act_tcam); - else - clear_bit(FBNIC_MAC_ADDR_T_ALLMULTI, - mac_addr->act_tcam); + assign_bit(FBNIC_MAC_ADDR_T_ALLMULTI, mac_addr->act_tcam, + enable_host); } else { __fbnic_xc_unsync(mac_addr, FBNIC_MAC_ADDR_T_BMC); __fbnic_xc_unsync(mac_addr, FBNIC_MAC_ADDR_T_ALLMULTI); diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c index fc8c50e8f365..119ac720c078 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c @@ -655,15 +655,9 @@ static int ionic_cmb_rings_toggle(struct ionic_lif *lif, bool cmb_tx, bool cmb_r if (pages_used < 0) return pages_used; - if (cmb_tx) - set_bit(IONIC_LIF_F_CMB_TX_RINGS, lif->state); - else - clear_bit(IONIC_LIF_F_CMB_TX_RINGS, lif->state); + assign_bit(IONIC_LIF_F_CMB_TX_RINGS, lif->state, cmb_tx); - if (cmb_rx) - set_bit(IONIC_LIF_F_CMB_RX_RINGS, lif->state); - else - clear_bit(IONIC_LIF_F_CMB_RX_RINGS, lif->state); + assign_bit(IONIC_LIF_F_CMB_RX_RINGS, lif->state, cmb_rx); if (cmb_tx || cmb_rx) netdev_info(lif->netdev, "Enabling CMB %s %s rings - %d pages\n", diff --git a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c index 647f30a16a94..037882a34203 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c +++ b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c @@ -492,10 +492,8 @@ static int qede_set_priv_flags(struct net_device *dev, u32 flags) if (dflags & ~BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR)) return -EINVAL; - if (flags & BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR)) - set_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags); - else - clear_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags); + assign_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags, + flags & BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR)); return 0; } diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c b/drivers/net/ethernet/qlogic/qla3xxx.c index 776840f60d01..1466ec85de24 100644 --- a/drivers/net/ethernet/qlogic/qla3xxx.c +++ b/drivers/net/ethernet/qlogic/qla3xxx.c @@ -1581,10 +1581,8 @@ static void ql_link_state_machine_work(struct work_struct *work) */ static void ql_get_phy_owner(struct ql3_adapter *qdev) { - if (ql_this_adapter_controls_port(qdev)) - set_bit(QL_LINK_MASTER, &qdev->flags); - else - clear_bit(QL_LINK_MASTER, &qdev->flags); + assign_bit(QL_LINK_MASTER, &qdev->flags, + ql_this_adapter_controls_port(qdev)); } /* @@ -3343,10 +3341,8 @@ static void ql_set_mac_info(struct ql3_adapter *qdev) qdev->mac_ob_opcode = OUTBOUND_MAC_IOCB | func_number; qdev->mb_bit_mask = FN0_MA_BITS_MASK; qdev->PHYAddr = PORT0_PHY_ADDRESS; - if (port_status & PORT_STATUS_SM0) - set_bit(QL_LINK_OPTICAL, &qdev->flags); - else - clear_bit(QL_LINK_OPTICAL, &qdev->flags); + assign_bit(QL_LINK_OPTICAL, &qdev->flags, + port_status & PORT_STATUS_SM0); break; case ISP_CONTROL_FN1_NET: @@ -3354,10 +3350,8 @@ static void ql_set_mac_info(struct ql3_adapter *qdev) qdev->mac_ob_opcode = OUTBOUND_MAC_IOCB | func_number; qdev->mb_bit_mask = FN1_MA_BITS_MASK; qdev->PHYAddr = PORT1_PHY_ADDRESS; - if (port_status & PORT_STATUS_SM1) - set_bit(QL_LINK_OPTICAL, &qdev->flags); - else - clear_bit(QL_LINK_OPTICAL, &qdev->flags); + assign_bit(QL_LINK_OPTICAL, &qdev->flags, + port_status & PORT_STATUS_SM1); break; case ISP_CONTROL_FN0_SCSI: diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c index 576340315e0d..ef4a0376baff 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c @@ -644,10 +644,7 @@ static void qlcnic_83xx_dcb_aen_handler(struct qlcnic_dcb *dcb, void *data) if (test_and_set_bit(QLCNIC_DCB_AEN_MODE, &dcb->state)) return; - if (*val & BIT_8) - set_bit(QLCNIC_DCB_STATE, &dcb->state); - else - clear_bit(QLCNIC_DCB_STATE, &dcb->state); + assign_bit(QLCNIC_DCB_STATE, &dcb->state, *val & BIT_8); queue_delayed_work(dcb->wq, &dcb->aen_work, 0); } diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c index 0704dbc52d82..a106f961e177 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c @@ -1488,10 +1488,8 @@ static int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter *adapter, u8 cmd_o goto out; } - if (cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) - set_bit(QLC_BC_VF_STATE, &vf->state); - else - clear_bit(QLC_BC_VF_STATE, &vf->state); + assign_bit(QLC_BC_VF_STATE, &vf->state, + cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT); out: qlcnic_free_mbx_args(&cmd); diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c index 7052d34aad45..c69b41e317d2 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c @@ -773,10 +773,8 @@ static int qlcnic_sriov_pf_channel_cfg_cmd(struct qlcnic_bc_trans *trans, cmd->rsp.arg[0] |= (1 << 25); - if (trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) - set_bit(QLC_BC_VF_STATE, &vf->state); - else - clear_bit(QLC_BC_VF_STATE, &vf->state); + assign_bit(QLC_BC_VF_STATE, &vf->state, + trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT); return err; diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ptp.c b/drivers/net/ethernet/wangxun/libwx/wx_ptp.c index 4708e7f3958f..ea6865b23f5f 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_ptp.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_ptp.c @@ -450,10 +450,7 @@ static int wx_ptp_feature_enable(struct ptp_clock_info *ptp, wx->pps_width = 120000000; } - if (on) - set_bit(WX_FLAG_PTP_PPS_ENABLED, wx->flags); - else - clear_bit(WX_FLAG_PTP_PPS_ENABLED, wx->flags); + assign_bit(WX_FLAG_PTP_PPS_ENABLED, wx->flags, on); return wx->ptp_setup_sdp(wx); } diff --git a/drivers/net/phy/mediatek/mtk-phy-lib.c b/drivers/net/phy/mediatek/mtk-phy-lib.c index 608072fbfde9..4c4eca870bde 100644 --- a/drivers/net/phy/mediatek/mtk-phy-lib.c +++ b/drivers/net/phy/mediatek/mtk-phy-lib.c @@ -136,22 +136,15 @@ int mtk_phy_led_hw_ctrl_get(struct phy_device *phydev, u8 index, if (blink < 0) return -EIO; - if ((on & (on_set | MTK_PHY_LED_ON_FDX | - MTK_PHY_LED_ON_HDX | MTK_PHY_LED_ON_LINKDOWN)) || - (blink & (rx_blink_set | tx_blink_set))) - set_bit(bit_netdev, &priv->led_state); - else - clear_bit(bit_netdev, &priv->led_state); + assign_bit(bit_netdev, &priv->led_state, + (on & (on_set | MTK_PHY_LED_ON_FDX | MTK_PHY_LED_ON_HDX | + MTK_PHY_LED_ON_LINKDOWN)) || + (blink & (rx_blink_set | tx_blink_set))); - if (on & MTK_PHY_LED_ON_FORCE_ON) - set_bit(bit_on, &priv->led_state); - else - clear_bit(bit_on, &priv->led_state); + assign_bit(bit_on, &priv->led_state, on & MTK_PHY_LED_ON_FORCE_ON); - if (blink & MTK_PHY_LED_BLINK_FORCE_BLINK) - set_bit(bit_blink, &priv->led_state); - else - clear_bit(bit_blink, &priv->led_state); + assign_bit(bit_blink, &priv->led_state, + blink & MTK_PHY_LED_BLINK_FORCE_BLINK); if (!rules) return 0; @@ -254,10 +247,7 @@ int mtk_phy_led_hw_ctrl_set(struct phy_device *phydev, u8 index, } } - if (blink || on) - set_bit(bit_netdev, &priv->led_state); - else - clear_bit(bit_netdev, &priv->led_state); + assign_bit(bit_netdev, &priv->led_state, blink || on); ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, index ? MTK_PHY_LED1_ON_CTRL : MTK_PHY_LED0_ON_CTRL, diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c index fb61e53ff4c3..e11eb7a6cdf2 100644 --- a/drivers/net/wireless/ath/ath10k/debug.c +++ b/drivers/net/wireless/ath/ath10k/debug.c @@ -2004,10 +2004,7 @@ static ssize_t ath10k_write_btcoex(struct file *file, ath10k_core_start_recovery(ar); } - if (val) - set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); - else - clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); + assign_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags, val); ret = count; @@ -2118,10 +2115,7 @@ static ssize_t ath10k_write_peer_stats(struct file *file, goto exit; } - if (val) - set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags); - else - clear_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags); + assign_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags, val); ath10k_info(ar, "restarting firmware due to Peer stats change"); diff --git a/drivers/net/wireless/ath/ath10k/snoc.c b/drivers/net/wireless/ath/ath10k/snoc.c index 8de133fe2a72..8f171ab6f4de 100644 --- a/drivers/net/wireless/ath/ath10k/snoc.c +++ b/drivers/net/wireless/ath/ath10k/snoc.c @@ -1532,10 +1532,8 @@ static int ath10k_snoc_modem_notify(struct notifier_block *nb, unsigned long act case QCOM_SSR_BEFORE_SHUTDOWN: ath10k_dbg(ar, ATH10K_DBG_SNOC, "received modem %s event\n", notify_data->crashed ? "crashed" : "stopping"); - if (!notify_data->crashed) - set_bit(ATH10K_SNOC_FLAG_MODEM_STOPPED, &ar_snoc->flags); - else - clear_bit(ATH10K_SNOC_FLAG_MODEM_STOPPED, &ar_snoc->flags); + assign_bit(ATH10K_SNOC_FLAG_MODEM_STOPPED, &ar_snoc->flags, + !notify_data->crashed); break; case QCOM_SSR_AFTER_SHUTDOWN: diff --git a/drivers/net/wireless/ath/ath11k/htc.c b/drivers/net/wireless/ath/ath11k/htc.c index 5f9ee5e633da..07fc959ed74c 100644 --- a/drivers/net/wireless/ath/ath11k/htc.c +++ b/drivers/net/wireless/ath/ath11k/htc.c @@ -244,10 +244,7 @@ static void ath11k_htc_suspend_complete(struct ath11k_base *ab, bool ack) { ath11k_dbg(ab, ATH11K_DBG_BOOT, "suspend complete %d\n", ack); - if (ack) - set_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags); - else - clear_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags); + assign_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags, ack); complete(&ab->htc_suspend); } diff --git a/drivers/net/wireless/ath/ath12k/htc.c b/drivers/net/wireless/ath/ath12k/htc.c index 92138caa2a82..7227bed91ade 100644 --- a/drivers/net/wireless/ath/ath12k/htc.c +++ b/drivers/net/wireless/ath/ath12k/htc.c @@ -236,10 +236,7 @@ static void ath12k_htc_suspend_complete(struct ath12k_base *ab, bool ack) { ath12k_dbg(ab, ATH12K_DBG_BOOT, "boot suspend complete %d\n", ack); - if (ack) - set_bit(ATH12K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags); - else - clear_bit(ATH12K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags); + assign_bit(ATH12K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags, ack); complete(&ab->htc_suspend); } diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c index 2224cb74b1d4..5ea18c87e12e 100644 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c @@ -968,10 +968,7 @@ static void ar9003_hw_tx_iq_cal_outlier_detection(struct ath_hw *ah, AR_PHY_RX_IQCAL_CORR_B0_LOOPBACK_IQCORR_EN, 0x1); if (caldata) { - if (is_reusable) - set_bit(TXIQCAL_DONE, &caldata->cal_flags); - else - clear_bit(TXIQCAL_DONE, &caldata->cal_flags); + assign_bit(TXIQCAL_DONE, &caldata->cal_flags, is_reusable); } return; diff --git a/drivers/net/wireless/ath/ath9k/mci.c b/drivers/net/wireless/ath/ath9k/mci.c index f82bb2349928..62ad761d6a76 100644 --- a/drivers/net/wireless/ath/ath9k/mci.c +++ b/drivers/net/wireless/ath/ath9k/mci.c @@ -348,10 +348,7 @@ static u8 ath_mci_process_status(struct ath_softc *sc, if (status->conn_handle >= ATH_MCI_MAX_PROFILE) return 0; - if (status->is_critical) - __set_bit(status->conn_handle, mci->status); - else - __clear_bit(status->conn_handle, mci->status); + __assign_bit(status->conn_handle, mci->status, status->is_critical); mci->num_mgmt = 0; do { diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index 2f925d22b9aa..2c49f3b493bd 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -2034,10 +2034,7 @@ int mt76_connac_mcu_sched_scan_enable(struct mt76_phy *phy, .active = !enable, }; - if (enable) - set_bit(MT76_HW_SCHED_SCANNING, &phy->state); - else - clear_bit(MT76_HW_SCHED_SCANNING, &phy->state); + assign_bit(MT76_HW_SCHED_SCANNING, &phy->state, enable); return mt76_mcu_send_msg(phy->dev, MCU_CE_CMD(SCHED_SCAN_ENABLE), &req, sizeof(req), false); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index fa29c486a455..aeb017516186 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -3467,10 +3467,7 @@ mt7925_mcu_sched_scan_enable(struct mt76_phy *phy, req = (struct scan_sched_enable *)tlv; req->active = !enable; - if (enable) - set_bit(MT76_HW_SCHED_SCANNING, &phy->state); - else - clear_bit(MT76_HW_SCHED_SCANNING, &phy->state); + assign_bit(MT76_HW_SCHED_SCANNING, &phy->state, enable); return mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(SCAN_REQ), true); diff --git a/drivers/net/wireless/realtek/rtw88/debug.c b/drivers/net/wireless/realtek/rtw88/debug.c index b67d69b01f87..3a10f1bbe0e0 100644 --- a/drivers/net/wireless/realtek/rtw88/debug.c +++ b/drivers/net/wireless/realtek/rtw88/debug.c @@ -1051,10 +1051,7 @@ static ssize_t rtw_debugfs_set_force_lowest_basic_rate(struct file *filp, if (err) return err; - if (input) - set_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags); - else - clear_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags); + assign_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags, input); return count; } diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 397ebbfcac09..95e14df2f137 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -7372,10 +7372,7 @@ void rtw89_core_rfkill_poll(struct rtw89_dev *rtwdev, bool force) rtw89_info(rtwdev, "rfkill hardware state changed to %s\n", str_enable_disable(!blocked)); - if (blocked) - set_bit(RTW89_FLAG_HW_RFKILL_STATE, rtwdev->flags); - else - clear_bit(RTW89_FLAG_HW_RFKILL_STATE, rtwdev->flags); + assign_bit(RTW89_FLAG_HW_RFKILL_STATE, rtwdev->flags, blocked); wiphy_rfkill_set_hw_state(rtwdev->hw->wiphy, blocked); } diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c index df396fbfca26..68da8908f14c 100644 --- a/drivers/net/wireless/realtek/rtw89/mac.c +++ b/drivers/net/wireless/realtek/rtw89/mac.c @@ -6046,10 +6046,7 @@ rtw89_mac_c2h_pwr_int_notify(struct rtw89_dev *rtwdev, struct sk_buff *skb, u32 goto out; rtwsta = rtwsta_link->rtwsta; - if (ps) - set_bit(RTW89_REMOTE_STA_IN_PS, rtwsta->flags); - else - clear_bit(RTW89_REMOTE_STA_IN_PS, rtwsta->flags); + assign_bit(RTW89_REMOTE_STA_IN_PS, rtwsta->flags, ps); sta = rtwsta_to_sta(rtwsta); ieee80211_sta_ps_transition(sta, ps); @@ -7004,10 +7001,7 @@ void rtw89_mac_bf_monitor_calc(struct rtw89_dev *rtwdev, &data); rtw89_debug(rtwdev, RTW89_DBG_BF, "bfee STA count=%d\n", data.count); - if (data.count) - set_bit(RTW89_FLAG_BFEE_MON, rtwdev->flags); - else - clear_bit(RTW89_FLAG_BFEE_MON, rtwdev->flags); + assign_bit(RTW89_FLAG_BFEE_MON, rtwdev->flags, data.count); } void _rtw89_mac_bf_monitor_track(struct rtw89_dev *rtwdev) diff --git a/drivers/net/wireless/realtek/rtw89/regd.c b/drivers/net/wireless/realtek/rtw89/regd.c index 14fab6b1a74a..b9a5ce218b1d 100644 --- a/drivers/net/wireless/realtek/rtw89/regd.c +++ b/drivers/net/wireless/realtek/rtw89/regd.c @@ -421,10 +421,7 @@ static void __rtw89_regd_setup_policy_6ghz(struct rtw89_dev *rtwdev, bool block, return; } - if (block) - set_bit(index, regulatory->block_6ghz); - else - clear_bit(index, regulatory->block_6ghz); + assign_bit(index, regulatory->block_6ghz, block); } static void rtw89_regd_setup_policy_6ghz(struct rtw89_dev *rtwdev) diff --git a/drivers/net/wireless/ti/wlcore/rx.c b/drivers/net/wireless/ti/wlcore/rx.c index 307fab21050b..4d6f5a047782 100644 --- a/drivers/net/wireless/ti/wlcore/rx.c +++ b/drivers/net/wireless/ti/wlcore/rx.c @@ -316,10 +316,7 @@ int wl1271_rx_filter_enable(struct wl1271 *wl, return ret; } - if (enable) - __set_bit(index, wl->rx_filter_enabled); - else - __clear_bit(index, wl->rx_filter_enabled); + __assign_bit(index, wl->rx_filter_enabled, enable); return 0; } From 8a673c89441d71776579d2ca307c7a6f0bcd86f1 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sun, 20 Sep 2026 10:28:18 +0800 Subject: [PATCH 0646/2126] wifi: mac80211: use assign_bit() where applicable Convert open-coded if/else with set_bit/clear_bit the assign_bit API. Done with Coccinelle semantic patch: // set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond); Signed-off-by: Peng Fan Link: https://patch.msgid.link/20260920022822.3145944-1-peng.fan@oss.nxp.com Signed-off-by: Johannes Berg --- net/mac80211/agg-tx.c | 5 +---- net/mac80211/rx.c | 5 +---- net/mac80211/tests/chan-mode.c | 6 ++---- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c index ce9fb19d8c18..f3ecdd8601a0 100644 --- a/net/mac80211/agg-tx.c +++ b/net/mac80211/agg-tx.c @@ -212,10 +212,7 @@ ieee80211_agg_start_txq(struct sta_info *sta, int tid, bool enable) txqi = to_txq_info(txq); - if (enable) - set_bit(IEEE80211_TXQ_AMPDU, &txqi->flags); - else - clear_bit(IEEE80211_TXQ_AMPDU, &txqi->flags); + assign_bit(IEEE80211_TXQ_AMPDU, &txqi->flags, enable); clear_bit(IEEE80211_TXQ_STOP, &txqi->flags); local_bh_disable(); diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index d6755a4c7d3c..b3990b7a7299 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -1692,10 +1692,7 @@ static void sta_ps_start(struct sta_info *sta) list_del_init(&txqi->schedule_order); spin_unlock(&local->active_txq_lock[txq->ac]); - if (txq_has_queue(txq)) - set_bit(tid, &sta->txq_buffered_tids); - else - clear_bit(tid, &sta->txq_buffered_tids); + assign_bit(tid, &sta->txq_buffered_tids, txq_has_queue(txq)); } sta_info_recalc_tim(sta); diff --git a/net/mac80211/tests/chan-mode.c b/net/mac80211/tests/chan-mode.c index ab7d38ef6a3a..85dc87215d23 100644 --- a/net/mac80211/tests/chan-mode.c +++ b/net/mac80211/tests/chan-mode.c @@ -219,10 +219,8 @@ static void test_determine_chan_mode(struct kunit *test) /* To force EHT downgrade to HE on punctured 80 MHz downgraded to 40 MHz */ set_bit(IEEE80211_HW_DISALLOW_PUNCTURING, t_sdata->local.hw.flags); - if (params->strict) - set_bit(IEEE80211_HW_STRICT, t_sdata->local.hw.flags); - else - clear_bit(IEEE80211_HW_STRICT, t_sdata->local.hw.flags); + assign_bit(IEEE80211_HW_STRICT, t_sdata->local.hw.flags, + params->strict); t_sdata->sdata->u.mgd.ht_capa_mask = params->ht_capa_mask; t_sdata->sdata->u.mgd.vht_capa = params->vht_capa; From 5c299357ec1d5c21fa1141310a5f10e0ed47cf03 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 11:57:59 +0200 Subject: [PATCH 0647/2126] wifi: mac80211: tests: fix memory leak The code allocates the bitrates twice, but really only should do that once. Remove the unconditional allocation even though it's the same in both branches of the switch, since the cleanup only handles those two branches explicitly. Link: https://patch.msgid.link/20260916115759.2cd8a91ed99d.I89c5068a3472e6296baf5a2d6832b733282d2b24@changeid Signed-off-by: Johannes Berg --- net/mac80211/tests/util.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/net/mac80211/tests/util.c b/net/mac80211/tests/util.c index 0b01264af577..89ff4f389de3 100644 --- a/net/mac80211/tests/util.c +++ b/net/mac80211/tests/util.c @@ -2,7 +2,7 @@ /* * Utilities for mac80211 unit testing * - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024, 2026 Intel Corporation */ #include #include @@ -226,10 +226,6 @@ int t_sdata_init(struct kunit_resource *resource, void *ctx) sband = t_sdata->wiphy->bands[band]; sband->band = band; - sband->bitrates = - kmemdup(bitrates, sizeof(bitrates), GFP_KERNEL); - sband->n_bitrates = ARRAY_SIZE(bitrates); - /* Initialize channels, feel free to add more channels/bands */ switch (band) { case NL80211_BAND_2GHZ: From c5c853aa6dcb40a2a352982cdd8937c4aa6f2e26 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 12:01:26 +0200 Subject: [PATCH 0648/2126] wifi: mac80211: WARN on 40 MHz HT/HE mismatch This happened to me and was tricky to debug, of course it shouldn't happen with correct drivers, WARN in this case. Link: https://patch.msgid.link/20260916120127.efa58d51d11f.Ie29dc83578893945231db3badfcb7b4a2e2775ba@changeid Signed-off-by: Johannes Berg --- net/mac80211/main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index a59837b9f480..ecd16374e4a1 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1322,12 +1322,13 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G; /* currently no support for HE client where HT has 40 MHz but not HT */ - if (iftd->he_cap.has_he && - iftd->types_mask & (BIT(NL80211_IFTYPE_STATION) | - BIT(NL80211_IFTYPE_P2P_CLIENT)) && - sband->ht_cap.ht_supported && - sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && - !(iftd->he_cap.he_cap_elem.phy_cap_info[0] & he_40_mhz_cap)) + if (WARN_ON(iftd->he_cap.has_he && + iftd->types_mask & (BIT(NL80211_IFTYPE_STATION) | + BIT(NL80211_IFTYPE_P2P_CLIENT)) && + sband->ht_cap.ht_supported && + sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && + !(iftd->he_cap.he_cap_elem.phy_cap_info[0] & + he_40_mhz_cap))) return -EINVAL; /* no support for per-band vendor elems with MLO */ From 8f076d9407f313ae641ef8e9ad241dade9006a91 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 12:01:27 +0200 Subject: [PATCH 0649/2126] wifi: mac80211: allow advertising 20 MHz-only non-AP STA 802.11 Clause 27 (HE) already defined a 20 MHz-only non-AP HE STA in the 5 GHz band, where VHT is required, although VHT in Clause 21 requires 20, 40 and 80 MHz support. The VHT requirement is implemented in mac80211, but the later allowance for 20 MHz-only since HE wasn't. Allow a device to be a 20 MHz-only non-AP STA and require that it support VHT, but not that it has 80 MHz support, if it's HE as well. Link: https://patch.msgid.link/20260916120127.6e74579d46db.I628aed79ec7f9bf2f8e770b4866ed98cf1ddbe60@changeid Signed-off-by: Johannes Berg --- net/mac80211/mlme.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 189dd3467f76..cf3873d8855b 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -6513,7 +6513,7 @@ ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata, struct ieee80211_sta_ht_cap sta_ht_cap = sband->ht_cap; bool is_5ghz = sband->band == NL80211_BAND_5GHZ; bool is_6ghz = sband->band == NL80211_BAND_6GHZ; - const struct ieee80211_sta_he_cap *he_cap; + const struct ieee80211_sta_he_cap *he_cap = NULL; const struct ieee80211_sta_eht_cap *eht_cap; const struct ieee80211_sta_uhr_cap *uhr_cap; struct ieee80211_sta_vht_cap vht_cap; @@ -6577,7 +6577,15 @@ ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata, goto out; } - if (vht_cap.vht_supported && is_5ghz) { + if (req && req->flags & ASSOC_REQ_DISABLE_HE && !is_6ghz) + mlme_link_id_dbg(sdata, link_id, + "HE disabled by flag, limiting to HT/VHT\n"); + else + he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); + + if (vht_cap.vht_supported && is_5ghz && he_cap) { + /* nothing - since HE we can be 20 MHz-only non-AP STA */ + } else if (vht_cap.vht_supported && is_5ghz) { bool have_80mhz = false; unsigned int i; @@ -6623,17 +6631,11 @@ ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata, "no VHT 160 MHz capability on 5 GHz, limiting to 80 MHz"); } - if (req && req->flags & ASSOC_REQ_DISABLE_HE) { - mlme_link_id_dbg(sdata, link_id, - "HE disabled by flag, limiting to HT/VHT\n"); - goto out; - } - - he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); if (!he_cap) { WARN_ON(is_6ghz); - mlme_link_id_dbg(sdata, link_id, - "no HE support, limiting to HT/VHT\n"); + if (!req || !(req->flags & ASSOC_REQ_DISABLE_HE)) + mlme_link_id_dbg(sdata, link_id, + "no HE support, limiting to HT/VHT\n"); goto out; } From 94fe252cd763c3e09399dea3fd28e555090599f5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 12:02:32 +0200 Subject: [PATCH 0650/2126] wifi: ieee80211: fix FTM bufferable check The FTM action frames don't have a protected dual, in fact their numbers are assigned otherwise. Remove the wrong check. Link: https://patch.msgid.link/20260916120232.d3c05305173e.I3855653e49311b0752b9fcdf9d5c6373408a14da@changeid Signed-off-by: Johannes Berg --- include/linux/ieee80211.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h index 26e674038865..7fbc51f873ff 100644 --- a/include/linux/ieee80211.h +++ b/include/linux/ieee80211.h @@ -2421,8 +2421,7 @@ static inline bool ieee80211_is_bufferable_mmpdu(struct sk_buff *skb) /* action frame - additionally check for non-bufferable FTM */ - if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC && - mgmt->u.action.category != WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION) + if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) return true; if (mgmt->u.action.action_code == WLAN_PUB_ACTION_FTM_REQUEST || From ea35828287b5988dac9c9e1e33a4f692e794758c Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 12:04:06 +0200 Subject: [PATCH 0651/2126] wifi: radiotap: correct EHT TB U-SIG 1 B20:25 The mask here needs to cover six bits, not just five, fix that. Link: https://patch.msgid.link/20260916120406.e4c89f440edb.I8d80bba29ff7e7d642ec603098fb7d30f2db5968@changeid Signed-off-by: Johannes Berg --- include/net/ieee80211_radiotap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/ieee80211_radiotap.h b/include/net/ieee80211_radiotap.h index 27ee67b38ea8..ffdfbade25b8 100644 --- a/include/net/ieee80211_radiotap.h +++ b/include/net/ieee80211_radiotap.h @@ -596,7 +596,7 @@ enum ieee80211_radiotap_eht_usig_mu { enum ieee80211_radiotap_eht_usig_tb { /* TB-USIG-1 */ - IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD = 0x0000001f, + IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD = 0x0000003f, /* TB-USIG-2 */ IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE = 0x000000c0, From 73cdc6018f4947c1c29fc274d78edff6223336d1 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 12:06:20 +0200 Subject: [PATCH 0652/2126] wifi: nl80211: rename no-ACK bitmap to TID bitmap Rename the NL80211_ATTR_NOACK_MAP attribute to be called NL80211_ATTR_TID_BITMAP, allowing it to be reused in more contexts. The interpretation stays for the only command using it now (NL80211_CMD_SET_NOACK_MAP.) Signed-off-by: Johannes Berg Reviewed-by: Jeff Johnson Link: https://patch.msgid.link/20260916120620.823bfa05f5f5.Ibb334016129512921b0aa5236ee4c670d83d0f95@changeid Signed-off-by: Johannes Berg --- include/uapi/linux/nl80211.h | 11 ++++++----- net/wireless/nl80211.c | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 510102febc26..9a2ccb8d66b8 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -937,8 +937,8 @@ * OLBC handling in hostapd. Beacons are reported in %NL80211_CMD_FRAME * messages. Note that per PHY only one application may register. * - * @NL80211_CMD_SET_NOACK_MAP: sets a bitmap for the individual TIDs whether - * No Acknowledgement Policy should be applied. + * @NL80211_CMD_SET_NOACK_MAP: sets a bitmap (%NL80211_ATTR_TID_BITMAP) + * indicating for which TIDs No Acknowledgment Policy should be applied. * * @NL80211_CMD_CH_SWITCH_NOTIFY: An AP or GO may decide to switch channels * independently of the userspace SME, send this event indicating @@ -2288,8 +2288,8 @@ enum nl80211_commands { * abides to when initiating radiation on DFS channels. A country maps * to one DFS region. * - * @NL80211_ATTR_NOACK_MAP: This u16 bitmap contains the No Ack Policy of - * up to 16 TIDs. + * @NL80211_ATTR_TID_BITMAP: A TID bitmap (u16) whose meaning depends + * on the command. * * @NL80211_ATTR_INACTIVITY_TIMEOUT: timeout value in seconds, this can be * used by the drivers which has MLME in firmware and does not have support @@ -3434,7 +3434,7 @@ enum nl80211_attrs { NL80211_ATTR_DISABLE_HT, NL80211_ATTR_HT_CAPABILITY_MASK, - NL80211_ATTR_NOACK_MAP, + NL80211_ATTR_TID_BITMAP, NL80211_ATTR_INACTIVITY_TIMEOUT, @@ -3807,6 +3807,7 @@ enum nl80211_attrs { #define NL80211_ATTR_CSA_C_OFF_BEACON NL80211_ATTR_CNTDWN_OFFS_BEACON #define NL80211_ATTR_CSA_C_OFF_PRESP NL80211_ATTR_CNTDWN_OFFS_PRESP #define NL80211_ATTR_ASSOC_MLD_EXT_CAPA_OPS NL80211_ATTR_EXT_MLD_CAPA_AND_OPS +#define NL80211_ATTR_NOACK_MAP NL80211_ATTR_TID_BITMAP /* * Allow user space programs to use #ifdef on new attributes by defining them diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index e77a4c81d031..ab5a14f5fe28 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -877,7 +877,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_HT_CAPABILITY_MASK] = { .len = NL80211_HT_CAPABILITY_LEN }, - [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, + [NL80211_ATTR_TID_BITMAP] = { .type = NLA_U16 }, [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, @@ -5282,13 +5282,13 @@ static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) struct net_device *dev = info->user_ptr[1]; u16 noack_map; - if (!info->attrs[NL80211_ATTR_NOACK_MAP]) + if (!info->attrs[NL80211_ATTR_TID_BITMAP]) return -EINVAL; if (!rdev->ops->set_noack_map) return -EOPNOTSUPP; - noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); + noack_map = nla_get_u16(info->attrs[NL80211_ATTR_TID_BITMAP]); return rdev_set_noack_map(rdev, dev, noack_map); } From 0bfef14586c1d2fa4aff5a4e75a669e0f2bccfcb Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 16 Sep 2026 12:07:08 +0200 Subject: [PATCH 0653/2126] wifi: mac80211: fix multi-link UHR association The maximum connection mode is still set to EHT, and in particular in multi-link this matters, the second link and further links are otherwise limited to EHT. Fix that. Link: https://patch.msgid.link/20260916120708.8ddea0cea883.I72e7fc58d65aca620a05a07b759755e5896f068f@changeid Signed-off-by: Johannes Berg --- net/mac80211/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/util.c b/net/mac80211/util.c index a96078a6bfa2..e2b5b2b21c34 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -47,7 +47,7 @@ struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) EXPORT_SYMBOL(wiphy_to_ieee80211_hw); const struct ieee80211_conn_settings ieee80211_conn_settings_unlimited = { - .mode = IEEE80211_CONN_MODE_EHT, + .mode = IEEE80211_CONN_MODE_HIGHEST, .bw_limit = IEEE80211_CONN_BW_LIMIT_320, }; From e83a9223c97fecc75e6d019abf191eda96bbc0bc Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Wed, 16 Sep 2026 21:31:07 +0200 Subject: [PATCH 0654/2126] libertas: mesh: remove unused and undocumented sysfs attribute groups 7e79b38fe9a4 ("libertas: register sysfs groups properly") changed the code to use struct net_device member sysfs_groups array indices 1 and 2. However only one device-specific group is supported by net core, see netdev_register_kobject(). As a result groups boot_opts_group and mesh_ie_group are overwritten with net core internal groups. Referenced change was done 5 yrs ago, and apparently nobody has missed the sysfs attributes in the meantime. So I dare to remove them, especially as they aren't documented under Documentation/ABI. Signed-off-by: Heiner Kallweit Link: https://patch.msgid.link/6810ccfb-0453-4bdc-bb03-d51c3f3c6e18@kernel.org Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/libertas/mesh.c | 506 ------------------- 1 file changed, 506 deletions(-) diff --git a/drivers/net/wireless/marvell/libertas/mesh.c b/drivers/net/wireless/marvell/libertas/mesh.c index fced7485d015..686b2e18a0e9 100644 --- a/drivers/net/wireless/marvell/libertas/mesh.c +++ b/drivers/net/wireless/marvell/libertas/mesh.c @@ -65,19 +65,6 @@ static int __lbs_mesh_config_send(struct lbs_private *priv, return ret; } -static int lbs_mesh_config_send(struct lbs_private *priv, - struct cmd_ds_mesh_config *cmd, - uint16_t action, uint16_t type) -{ - int ret; - - if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG)) - return -EOPNOTSUPP; - - ret = __lbs_mesh_config_send(priv, cmd, action, type); - return ret; -} - /* This function is the CMD_MESH_CONFIG legacy function. It only handles the * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG * are all handled by preparing a struct cmd_ds_mesh_config and passing it to @@ -333,497 +320,6 @@ static const struct attribute_group lbs_mesh_attr_group = { .attrs = lbs_mesh_sysfs_entries, }; - -/*************************************************************************** - * Persistent configuration support - */ - -static int mesh_get_default_parameters(struct device *dev, - struct mrvl_mesh_defaults *defs) -{ - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - struct cmd_ds_mesh_config cmd; - int ret; - - memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config)); - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET, - CMD_TYPE_MESH_GET_DEFAULTS); - - if (ret) - return -EOPNOTSUPP; - - memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults)); - - return 0; -} - -/** - * bootflag_show - Get function for sysfs attribute bootflag - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t bootflag_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", le32_to_cpu(defs.bootflag)); -} - -/** - * bootflag_store - Set function for sysfs attribute bootflag - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t bootflag_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - struct cmd_ds_mesh_config cmd; - uint32_t datum; - int ret; - - ret = kstrtouint(buf, 10, &datum); - if (ret) - return ret; - if (datum > 1) - return -EINVAL; - - memset(&cmd, 0, sizeof(cmd)); - *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum); - cmd.length = cpu_to_le16(sizeof(uint32_t)); - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_BOOTFLAG); - if (ret) - return ret; - - return strlen(buf); -} - -/** - * boottime_show - Get function for sysfs attribute boottime - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t boottime_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", defs.boottime); -} - -/** - * boottime_store - Set function for sysfs attribute boottime - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t boottime_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - struct cmd_ds_mesh_config cmd; - uint32_t datum; - int ret; - - ret = kstrtouint(buf, 10, &datum); - if (ret) - return ret; - if (datum > 255) - return -EINVAL; - - memset(&cmd, 0, sizeof(cmd)); - - /* A too small boot time will result in the device booting into - * standalone (no-host) mode before the host can take control of it, - * so the change will be hard to revert. This may be a desired - * feature (e.g to configure a very fast boot time for devices that - * will not be attached to a host), but dangerous. So I'm enforcing a - * lower limit of 20 seconds: remove and recompile the driver if this - * does not work for you. - */ - datum = (datum < 20) ? 20 : datum; - cmd.data[0] = datum; - cmd.length = cpu_to_le16(sizeof(uint8_t)); - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_BOOTTIME); - if (ret) - return ret; - - return strlen(buf); -} - -/** - * channel_show - Get function for sysfs attribute channel - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t channel_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", le16_to_cpu(defs.channel)); -} - -/** - * channel_store - Set function for sysfs attribute channel - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t channel_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - struct cmd_ds_mesh_config cmd; - uint32_t datum; - int ret; - - ret = kstrtouint(buf, 10, &datum); - if (ret) - return ret; - if (datum < 1 || datum > 11) - return -EINVAL; - - memset(&cmd, 0, sizeof(cmd)); - *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum); - cmd.length = cpu_to_le16(sizeof(uint16_t)); - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_DEF_CHANNEL); - if (ret) - return ret; - - return strlen(buf); -} - -/** - * mesh_id_show - Get function for sysfs attribute mesh_id - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t mesh_id_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) { - dev_err(dev, "inconsistent mesh ID length\n"); - defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN; - } - - memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len); - buf[defs.meshie.val.mesh_id_len] = '\n'; - buf[defs.meshie.val.mesh_id_len + 1] = '\0'; - - return defs.meshie.val.mesh_id_len + 1; -} - -/** - * mesh_id_store - Set function for sysfs attribute mesh_id - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t mesh_id_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cmd_ds_mesh_config cmd; - struct mrvl_mesh_defaults defs; - struct mrvl_meshie *ie; - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - int len; - int ret; - - if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1) - return -EINVAL; - - memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config)); - ie = (struct mrvl_meshie *) &cmd.data[0]; - - /* fetch all other Information Element parameters */ - ret = mesh_get_default_parameters(dev, &defs); - - cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); - - /* transfer IE elements */ - memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); - - len = count - 1; - memcpy(ie->val.mesh_id, buf, len); - /* SSID len */ - ie->val.mesh_id_len = len; - /* IE len */ - ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len; - - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_MESH_IE); - if (ret) - return ret; - - return strlen(buf); -} - -/** - * protocol_id_show - Get function for sysfs attribute protocol_id - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t protocol_id_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", defs.meshie.val.active_protocol_id); -} - -/** - * protocol_id_store - Set function for sysfs attribute protocol_id - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t protocol_id_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cmd_ds_mesh_config cmd; - struct mrvl_mesh_defaults defs; - struct mrvl_meshie *ie; - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - uint32_t datum; - int ret; - - ret = kstrtouint(buf, 10, &datum); - if (ret) - return ret; - if (datum > 255) - return -EINVAL; - - memset(&cmd, 0, sizeof(cmd)); - - /* fetch all other Information Element parameters */ - ret = mesh_get_default_parameters(dev, &defs); - - cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); - - /* transfer IE elements */ - ie = (struct mrvl_meshie *) &cmd.data[0]; - memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); - /* update protocol id */ - ie->val.active_protocol_id = datum; - - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_MESH_IE); - if (ret) - return ret; - - return strlen(buf); -} - -/** - * metric_id_show - Get function for sysfs attribute metric_id - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t metric_id_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", defs.meshie.val.active_metric_id); -} - -/** - * metric_id_store - Set function for sysfs attribute metric_id - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t metric_id_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cmd_ds_mesh_config cmd; - struct mrvl_mesh_defaults defs; - struct mrvl_meshie *ie; - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - uint32_t datum; - int ret; - - memset(&cmd, 0, sizeof(cmd)); - ret = sscanf(buf, "%d", &datum); - if ((ret != 1) || (datum > 255)) - return -EINVAL; - - /* fetch all other Information Element parameters */ - ret = mesh_get_default_parameters(dev, &defs); - - cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); - - /* transfer IE elements */ - ie = (struct mrvl_meshie *) &cmd.data[0]; - memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); - /* update metric id */ - ie->val.active_metric_id = datum; - - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_MESH_IE); - if (ret) - return ret; - - return strlen(buf); -} - -/** - * capability_show - Get function for sysfs attribute capability - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer where data will be returned - */ -static ssize_t capability_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct mrvl_mesh_defaults defs; - int ret; - - ret = mesh_get_default_parameters(dev, &defs); - - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", defs.meshie.val.mesh_capability); -} - -/** - * capability_store - Set function for sysfs attribute capability - * @dev: the &struct device - * @attr: device attributes - * @buf: buffer that contains new attribute value - * @count: size of buffer - */ -static ssize_t capability_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cmd_ds_mesh_config cmd; - struct mrvl_mesh_defaults defs; - struct mrvl_meshie *ie; - struct lbs_private *priv = to_net_dev(dev)->ml_priv; - uint32_t datum; - int ret; - - memset(&cmd, 0, sizeof(cmd)); - ret = sscanf(buf, "%d", &datum); - if ((ret != 1) || (datum > 255)) - return -EINVAL; - - /* fetch all other Information Element parameters */ - ret = mesh_get_default_parameters(dev, &defs); - - cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); - - /* transfer IE elements */ - ie = (struct mrvl_meshie *) &cmd.data[0]; - memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); - /* update value */ - ie->val.mesh_capability = datum; - - ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, - CMD_TYPE_MESH_SET_MESH_IE); - if (ret) - return ret; - - return strlen(buf); -} - - -static DEVICE_ATTR_RW(bootflag); -static DEVICE_ATTR_RW(boottime); -static DEVICE_ATTR_RW(channel); -static DEVICE_ATTR_RW(mesh_id); -static DEVICE_ATTR_RW(protocol_id); -static DEVICE_ATTR_RW(metric_id); -static DEVICE_ATTR_RW(capability); - -static struct attribute *boot_opts_attrs[] = { - &dev_attr_bootflag.attr, - &dev_attr_boottime.attr, - &dev_attr_channel.attr, - NULL -}; - -static const struct attribute_group boot_opts_group = { - .name = "boot_options", - .attrs = boot_opts_attrs, -}; - -static struct attribute *mesh_ie_attrs[] = { - &dev_attr_mesh_id.attr, - &dev_attr_protocol_id.attr, - &dev_attr_metric_id.attr, - &dev_attr_capability.attr, - NULL -}; - -static const struct attribute_group mesh_ie_group = { - .name = "mesh_ie", - .attrs = mesh_ie_attrs, -}; - - /*************************************************************************** * Initializing and starting, stopping mesh */ @@ -1019,8 +515,6 @@ static int lbs_add_mesh(struct lbs_private *priv) mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST; mesh_dev->sysfs_groups[0] = &lbs_mesh_attr_group; - mesh_dev->sysfs_groups[1] = &boot_opts_group; - mesh_dev->sysfs_groups[2] = &mesh_ie_group; /* Register virtual mesh interface */ ret = register_netdev(mesh_dev); From 6c0b7357e3c7f365ec51dd8d2b626130ee983ce1 Mon Sep 17 00:00:00 2001 From: Eduard Bostina Date: Thu, 17 Sep 2026 20:43:54 +0000 Subject: [PATCH 0655/2126] dt-bindings: net: wireless: Convert WL1251 to DT schema Convert the Texas Instruments WL1251 Wireless LAN Controller bindings to DT schema. During the conversion, the following updates were made: - Added the 'clocks' property. It was missing from the txt binding but is used in device trees (omap3-n900.dts). - Added 'spi-cpol' and 'spi-cpha'. These were present in the original txt binding's example but missing from its property list. - 'vio-supply' and 'spi-max-frequency' are no longer required. The txt binding listed them as required, but they are only applicable when the chip is connected via SPI. Signed-off-by: Eduard Bostina Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260917204354.3017427-1-egbostina@gmail.com Signed-off-by: Johannes Berg --- .../bindings/net/wireless/ti,wl1251.txt | 64 -------------- .../bindings/net/wireless/ti,wl1251.yaml | 85 +++++++++++++++++++ 2 files changed, 85 insertions(+), 64 deletions(-) delete mode 100644 Documentation/devicetree/bindings/net/wireless/ti,wl1251.txt create mode 100644 Documentation/devicetree/bindings/net/wireless/ti,wl1251.yaml diff --git a/Documentation/devicetree/bindings/net/wireless/ti,wl1251.txt b/Documentation/devicetree/bindings/net/wireless/ti,wl1251.txt deleted file mode 100644 index 88fd28d15eac..000000000000 --- a/Documentation/devicetree/bindings/net/wireless/ti,wl1251.txt +++ /dev/null @@ -1,64 +0,0 @@ -* Texas Instruments wl1251 wireless lan controller - -The wl1251 chip can be connected via SPI or via SDIO. This -document describes the binding for the SPI connected chip. - -Required properties: -- compatible : Should be "ti,wl1251" -- reg : Chip select address of device -- spi-max-frequency : Maximum SPI clocking speed of device in Hz -- interrupts : Should contain interrupt line -- vio-supply : phandle to regulator providing VIO - -Optional properties: -- ti,wl1251-has-eeprom : boolean, the wl1251 has an eeprom connected, which - provides configuration data (calibration, MAC, ...) -- ti,power-gpio : GPIO connected to chip's PMEN pin if operated in - SPI mode -- Please consult Documentation/devicetree/bindings/spi/spi-bus.txt - for optional SPI connection related properties, - -Examples: - -&spi1 { - wl1251@0 { - compatible = "ti,wl1251"; - - reg = <0>; - spi-max-frequency = <48000000>; - spi-cpol; - spi-cpha; - - interrupt-parent = <&gpio2>; - interrupts = <10 IRQ_TYPE_NONE>; /* gpio line 42 */ - - vio-supply = <&vio>; - ti,power-gpio = <&gpio3 23 GPIO_ACTIVE_HIGH>; /* 87 */ - }; -}; - -&mmc3 { - vmmc-supply = <&wlan_en>; - - bus-width = <4>; - non-removable; - ti,non-removable; - cap-power-off-card; - - pinctrl-names = "default"; - pinctrl-0 = <&mmc3_pins>; - - #address-cells = <1>; - #size-cells = <0>; - - wlan: wifi@1 { - compatible = "ti,wl1251"; - - reg = <1>; - - interrupt-parent = <&gpio1>; - interrupts = <21 IRQ_TYPE_LEVEL_HIGH>; /* GPIO_21 */ - - ti,wl1251-has-eeprom; - }; -}; diff --git a/Documentation/devicetree/bindings/net/wireless/ti,wl1251.yaml b/Documentation/devicetree/bindings/net/wireless/ti,wl1251.yaml new file mode 100644 index 000000000000..6ce82c4a2c0b --- /dev/null +++ b/Documentation/devicetree/bindings/net/wireless/ti,wl1251.yaml @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/wireless/ti,wl1251.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments WL1251 Wireless LAN Controller + +maintainers: + - Eduard Bostina + +properties: + compatible: + const: ti,wl1251 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vio-supply: + description: + Phandle to the regulator providing VIO. Required when connected via SPI. + + ti,power-gpio: + maxItems: 1 + description: + GPIO connected to chip's PMEN pin if operated in SPI mode. + + ti,wl1251-has-eeprom: + type: boolean + description: + The wl1251 has an EEPROM connected, which provides configuration + data (calibration, MAC, ...). + + clocks: + maxItems: 1 + + spi-max-frequency: true + spi-cpol: true + spi-cpha: true + +required: + - compatible + - reg + - interrupts + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include + #include + spi { + #address-cells = <1>; + #size-cells = <0>; + wifi@0 { + compatible = "ti,wl1251"; + reg = <0>; + spi-max-frequency = <48000000>; + spi-cpol; + spi-cpha; + interrupt-parent = <&gpio2>; + interrupts = <10 IRQ_TYPE_NONE>; + vio-supply = <&vio>; + ti,power-gpio = <&gpio3 23 GPIO_ACTIVE_HIGH>; + }; + }; + - | + #include + mmc { + #address-cells = <1>; + #size-cells = <0>; + wifi@1 { + compatible = "ti,wl1251"; + reg = <1>; + interrupt-parent = <&gpio1>; + interrupts = <21 IRQ_TYPE_LEVEL_HIGH>; + ti,wl1251-has-eeprom; + }; + }; From cc2d273893dbab3b2c89f5396b7ff1a302bc0825 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Wed, 16 Sep 2026 10:26:54 +0200 Subject: [PATCH 0656/2126] net: dsa: motorcomm: fix unused-function warning gcc warns about an unused function here because the __maybe_unused attribute is in the wrong part of the prototype: drivers/net/dsa/motorcomm/leds.c:352:1: error: 'yt921x_cled_hw_control_get_device' defined but not used [-Werror=unused-function] 352 | yt921x_cled_hw_control_get_device(struct led_classdev *led_cdev) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Move the __maybe_unused attribute to refer to the function rather than the returned object. Fixes: 9af9a8168213 ("net: dsa: motorcomm: Add LED support") Signed-off-by: Arnd Bergmann Link: https://patch.msgid.link/20260916082707.3973287-1-arnd@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/leds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c index 87a6b9cf6068..0e8761f37995 100644 --- a/drivers/net/dsa/motorcomm/leds.c +++ b/drivers/net/dsa/motorcomm/leds.c @@ -348,7 +348,7 @@ yt921x_cled_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on, return res; } -static struct device * __maybe_unused +static struct device __maybe_unused * yt921x_cled_hw_control_get_device(struct led_classdev *led_cdev) { struct yt921x_led *led = to_yt921x_led(led_cdev); From 2fba9318087216665e7b7e3a0f66fa6b2a312e94 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Thu, 17 Sep 2026 08:47:36 +0200 Subject: [PATCH 0657/2126] net: microchip: vcap: Stop selecting DEBUG_FS for KUnit tests VCAP_KUNIT_TEST enables DEBUG_FS even when the kernel configuration leaves it disabled. Remove the selection, following the dependency rule in Documentation/dev-tools/kunit/style.rst. The debugfs implementation and its tests are already built only with DEBUG_FS. The other VCAP tests can run without it. Signed-off-by: Karl Mehltretter Reviewed-by: Daniel Machon Acked-by: David Gow Link: https://patch.msgid.link/20260917064736.77354-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/vcap/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/vcap/Kconfig b/drivers/net/ethernet/microchip/vcap/Kconfig index 97f43fd4473f..1af30a358a15 100644 --- a/drivers/net/ethernet/microchip/vcap/Kconfig +++ b/drivers/net/ethernet/microchip/vcap/Kconfig @@ -40,7 +40,6 @@ config VCAP_KUNIT_TEST bool "KUnit test for VCAP library" if !KUNIT_ALL_TESTS depends on KUNIT depends on KUNIT=y && VCAP=y && y - select DEBUG_FS default KUNIT_ALL_TESTS help This builds unit tests for the VCAP library. From c6219deaee41bf35f7f04073f9ef99609d58bba4 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 17 Sep 2026 17:55:11 +0200 Subject: [PATCH 0658/2126] sfc: fix CONFIG_CXL_MEM dependency A recent patch introduced a call to devm_cxl_probe_mem(), which is only available when CXL_MEM is enabled. If CXL_MEM is in a loadable module, this causes a link failure for a builtin driver: s390-linux-ld: drivers/net/ethernet/sfc/efx_cxl.o: in function `efx_cxl_init': efx_cxl.c:(.text+0x156): undefined reference to `devm_cxl_probe_mem' Adapt the dependency to require CXL_MEM instead of CXL_BUS, which we know is available when CXL_MEM is. Fixes: 0418860ef2ca ("sfc: obtain and map cxl range using devm_cxl_probe_mem") Signed-off-by: Arnd Bergmann Reviewed-by: Alejandro Lucero Link: https://patch.msgid.link/20260917155519.2121486-1-arnd@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/sfc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/sfc/Kconfig b/drivers/net/ethernet/sfc/Kconfig index 979f2801e2a8..e2898ec2e6e9 100644 --- a/drivers/net/ethernet/sfc/Kconfig +++ b/drivers/net/ethernet/sfc/Kconfig @@ -68,7 +68,7 @@ config SFC_MCDI_LOGGING a sysfs file 'mcdi_logging' under the PCI device. config SFC_CXL bool "Solarflare SFC9100-family CXL support" - depends on SFC && CXL_BUS >= SFC + depends on SFC && CXL_MEM >= SFC default SFC help This enables SFC CXL support if the kernel is configuring CXL for From a2bd6c17665f95b7a9ef2d1107d2c0bfa6abf3a1 Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Wed, 16 Sep 2026 18:32:39 +0300 Subject: [PATCH 0659/2126] ptp: ocp: unregister devlink before detach on probe error devlink_register() runs before the dpll setup in ptp_ocp_probe(), but the failure paths after it went straight to ptp_ocp_detach() and then devlink_free(), which opens with ASSERT_DEVLINK_NOT_REGISTERED(devlink). Any dpll failure during probe therefore freed a devlink instance that was still registered. Route those paths through a new out_devlink label that unregisters first, matching the order ptp_ocp_remove() already uses. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: Sagi Maimon Link: https://patch.msgid.link/20260916153242.157171-2-sagi.maimon@adtran.com Signed-off-by: Jakub Kicinski --- drivers/ptp/ptp_ocp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 3d26ec1f7b9e..401b04f12d2b 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -5119,12 +5119,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (IS_ERR(bp->dpll)) { err = PTR_ERR(bp->dpll); dev_err(&pdev->dev, "dpll_device_alloc failed\n"); - goto out; + goto out_devlink; } err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp); if (err) - goto out; + goto out_devlink; for (i = 0; i < OCP_SMA_NUM; i++) { bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, @@ -5151,6 +5151,8 @@ out_dpll: dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker); } dpll_device_put(bp->dpll, &bp->tracker); +out_devlink: + devlink_unregister(devlink); out: ptp_ocp_detach(bp); out_disable: From 65ca1f70c4df31a77214625b1938f177f1d8184c Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Wed, 16 Sep 2026 18:32:40 +0300 Subject: [PATCH 0660/2126] ptp: ocp: fix dpll cleanup on probe error Two problems on the dpll error paths in ptp_ocp_probe(). dpll_device_register() takes a second reference and stores bp as the registration private data, and only dpll_device_unregister() drops it. out_dpll dropped bp->tracker but never unregistered, so a dpll_pin_get() or dpll_pin_register() failure left the device registered and visible to userspace with a priv pointer into the storage devlink_free() releases a few lines later, as well as leaking the registration object. A failing dpll_device_register() jumped to the same label as the failing dpll_device_get(), so the reference taken by dpll_device_get() was never dropped either. Give that case its own label. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: Sagi Maimon Link: https://patch.msgid.link/20260916153242.157171-3-sagi.maimon@adtran.com Signed-off-by: Jakub Kicinski --- drivers/ptp/ptp_ocp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 401b04f12d2b..f4299878c27c 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -5124,7 +5124,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp); if (err) - goto out_devlink; + goto out_dpll_put; for (i = 0; i < OCP_SMA_NUM; i++) { bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, @@ -5150,6 +5150,12 @@ out_dpll: dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker); } + /* dpll_device_register() takes a second reference and stores bp; only + * dpll_device_unregister() drops it. Without this the device stays + * visible with a priv pointer into storage devlink_free() will release. + */ + dpll_device_unregister(bp->dpll, &dpll_ops, bp); +out_dpll_put: dpll_device_put(bp->dpll, &bp->tracker); out_devlink: devlink_unregister(devlink); From 3b815e29966fc8a940255fed219f3d061a3c2a7e Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Wed, 16 Sep 2026 18:32:41 +0300 Subject: [PATCH 0661/2126] ptp: ocp: add TAP CPLD access for ADVA TimeCard X1 The ADVA TimeCard X1 carries a Lattice MachXO3 CPLD on its TMC I2C bus. Reaching it means taking that bus from the on-card MicroBlaze first. The card has two I2C controllers. Linux registers only the one at 0x00150000, normally routed to the config EEPROMs; the one at 0x00120000 belongs to the MicroBlaze and is routed to the TMC or M.2 bus as its firmware selects. A request/grant handshake re-routes the host controller onto the TMC bus, where the PCA9548 and the CPLD behind its channel 0 live. An operation takes the i2c core adapter lock for the whole grant window and uses __i2c_transfer() internally; without that, a concurrent transfer from ptp_ocp_read_eeprom(), from the nvmem attributes or from the at24 sysfs files would be issued onto the TMC bus instead of to the EEPROM. The hand-back waits for the firmware to drop the grant before the adapter lock is released, for the same reason. On top of the arbitration this adds two read-only interfaces: a root-only cpld_status attribute reporting the flags in the CPLD status register, and the Lattice device ID as the fixed devlink version cpld.id. Reading the ID claims the bus, so it must not sit on DEVLINK_CMD_INFO_GET, which carries no GENL_ADMIN_PERM; the driver reads it once from its own worker, as soon as the i2c adapter has registered, and info_get() reports the cached value. Signed-off-by: Sagi Maimon Link: https://patch.msgid.link/20260916153242.157171-4-sagi.maimon@adtran.com Signed-off-by: Jakub Kicinski --- Documentation/ABI/testing/sysfs-timecard | 24 + Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/ptp_ocp.rst | 35 ++ MAINTAINERS | 1 + drivers/ptp/ptp_ocp.c | 514 ++++++++++++++++++- 5 files changed, 571 insertions(+), 4 deletions(-) create mode 100644 Documentation/networking/devlink/ptp_ocp.rst diff --git a/Documentation/ABI/testing/sysfs-timecard b/Documentation/ABI/testing/sysfs-timecard index 3ae41b7634ac..e58824e0cdcd 100644 --- a/Documentation/ABI/testing/sysfs-timecard +++ b/Documentation/ABI/testing/sysfs-timecard @@ -11,6 +11,30 @@ Contact: Jonathan Lemon Description: This directory contains the attributes of the Nth timecard registered. +What: /sys/class/timecard/ocpN/cpld_status +Date: July 2026 +Contact: Sagi Maimon +Description: (RO, root only) The flags set in the status register of the + TAP CPLD, space separated, or an empty line when none is + set. Only present on ADVA x1 TAP boards (PCI ID + 0xad5a:0x0410). + + ========== ================================================ + done the configuration flash holds a valid image and + it is active + busy an internal operation is in progress + failed the last ISC operation failed + ========== ================================================ + + For example "busy" while an operation runs, or "busy failed" + if a failure is latched while another one is in progress. + + A read arbitrates for the shared I2C bus and reprograms the + on-card mux, so it is restricted to root. The Lattice device + ID of the CPLD is read once by the driver, shortly after + probe, and reported from that cached value as the fixed + "cpld.id" version by devlink dev info. + What: /sys/class/timecard/ocpN/available_clock_sources Date: September 2021 Contact: Jonathan Lemon diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst index d4a83fdcff7f..1af780c811ee 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -99,6 +99,7 @@ parameters, info versions, and other features it supports. nfp octeontx2 prestera + ptp_ocp qed sfc stmmac diff --git a/Documentation/networking/devlink/ptp_ocp.rst b/Documentation/networking/devlink/ptp_ocp.rst new file mode 100644 index 000000000000..3f997cd9f3a3 --- /dev/null +++ b/Documentation/networking/devlink/ptp_ocp.rst @@ -0,0 +1,35 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================== +ptp_ocp devlink support +======================== + +This document describes the devlink features implemented by the ``ptp_ocp`` +device driver. + +Info versions +============= + +The ``ptp_ocp`` driver reports the following versions + +.. list-table:: devlink info versions implemented + :widths: 5 5 90 + + * - Name + - Type + - Description + * - ``fw`` + - running + - Version of the firmware running on the card. Reported as ``loader`` + instead when the card is running the firmware loader. + * - ``board.id`` + - fixed + - Board identifier, read from the on-card EEPROM. + * - ``cpld.id`` + - fixed + - Lattice device ID (IDCODE) of the TAP CPLD, formatted as ``0x%08x``. + Only present on ADVA TimeCard X1 boards, which are the only ones + carrying that CPLD. Reading it claims the shared I2C bus and + reprograms the on-card mux, so the driver does that once from its + own worker and reports the cached value here; the version is + omitted until that read has succeeded. diff --git a/MAINTAINERS b/MAINTAINERS index df8ab9b82402..645c85e3a212 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20490,6 +20490,7 @@ OPENCOMPUTE PTP CLOCK DRIVER M: Vadim Fedorenko L: netdev@vger.kernel.org S: Maintained +F: Documentation/networking/devlink/ptp_ocp.rst F: drivers/ptp/ptp_ocp.c OPENCORES I2C BUS DRIVER diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index f4299878c27c..998ea9c6b381 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #define PCI_DEVICE_ID_META_TIMECARD 0x0400 @@ -85,6 +87,8 @@ struct ptp_ocp_adva_info { u8 signals_nr; u8 freq_in_nr; const struct ocp_attr_group *attr_groups; + /* x1: TAP CPLD present */ + bool has_cpld; }; #define OCP_CTRL_ENABLE BIT(0) @@ -163,7 +167,8 @@ struct gpio_reg { u32 gpio1; u32 __pad0; u32 gpio2; - u32 __pad1; + /* adva_x1: I2C bus ownership register; reserved on other variants */ + u32 i2c_bus_ctrl; }; struct irig_master_reg { @@ -416,6 +421,25 @@ struct ptp_ocp { dpll_tracker tracker; int signals_nr; int freq_in_nr; + /* adva_x1 CPLD I2C (internal use only) */ + /* serialises CPLD operations */ + struct mutex cpld_lock; + /* guards cpld_i2c_adap_nr against the bus notifier */ + spinlock_t cpld_adap_lock; + /* I2C adapter nr; -1 if absent. Under cpld_adap_lock */ + int cpld_i2c_adap_nr; + /* claimed adapter; valid under cpld_lock */ + struct i2c_adapter *cpld_adap; + /* scratch, write half then read half; valid under cpld_lock */ + u8 *cpld_buf; + /* Lattice device ID; 0 if unread */ + u32 cpld_id; + /* one-shot ID read finished, successfully or not; under cpld_lock */ + bool cpld_id_tried; + /* failed ID read attempts so far; under cpld_lock */ + unsigned int cpld_id_attempts; + /* x1 TAP CPLD present */ + bool has_cpld; }; #define OCP_REQ_TIMESTAMP BIT(0) @@ -1273,6 +1297,7 @@ static struct ocp_resource ocp_adva_x1_resource[] = { .signals_nr = 4, .freq_in_nr = 4, .attr_groups = adva_timecard_x1_groups, + .has_cpld = true, }, }, { } @@ -2159,6 +2184,7 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, const char *fw_image; char buf[32]; int err; + u32 id; fw_image = bp->fw_loader ? "loader" : "fw"; sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version); @@ -2166,6 +2192,18 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, if (err) return err; + /* Read by the worker, not here: this command is unprivileged and + * reading the ID claims the I2C bus. 0 means unread - skip it + * rather than fail, devlink discards the whole reply on error. + */ + id = READ_ONCE(bp->cpld_id); + if (bp->has_cpld && id) { + sprintf(buf, "0x%08x", id); + err = devlink_info_version_fixed_put(req, "cpld.id", buf); + if (err) + return err; + } + if (!bp->has_eeprom_data) { ptp_ocp_read_eeprom(bp); if (!bp->has_eeprom_data) @@ -3199,6 +3237,8 @@ ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r) return err; ptp_ocp_sma_init(bp); + bp->has_cpld = info->has_cpld; + return ptp_ocp_init_clock(bp, &info->servo); } @@ -4226,6 +4266,434 @@ static const struct ocp_attr_group art_timecard_groups[] = { { }, }; +/* + * adva_x1 TAP CPLD (Lattice LCMXO3LF-2100) helpers. + * + * The card has two I2C controllers; Linux registers only 0x00150000. + * The i2c_bus_ctrl handshake re-routes what each is wired to: + * + * grant 0: 0x150000 -> EEPROMs 0x120000 -> TMC or M.2, MB's choice + * grant 1: 0x150000 -> TMC bus 0x120000 -> M.2 + * + * The PCA9548 at 0x74 and the CPLD at 0x40 behind its channel 0 are on the + * TMC bus, reachable only while the grant is held. The EEPROMs are not + * behind the adapter for that window, so a CPLD operation holds cpld_lock + * and the adapter lock to keep the EEPROM and nvmem paths off it. + */ + +#define ADVA_MUX_ADDR 0x74 +#define ADVA_CPLD_ADDR 0x40 +#define ADVA_MUX_CHANNEL 0 + +/* Longest command or reply; bounds each half of the per-claim scratch. */ +#define ADVA_CPLD_XFER_MAX 32 + +/* i2c_bus_ctrl carries a host-written request half and a firmware-written + * grant half. MBLAZE_GRANTED is what a granted register reads while our + * request still stands; the release write clears the request half, so from + * then on only the grant field can be tested. Measured on an ADVA + * TimeCard X1: the register reads 0x00000012 once the firmware has handed + * the segment back, about 670 ms after the release write, so the low half + * is not zero then and only the grant field is a valid test. + */ +#define MBLAZE_REQUEST 0x0000aaaaU +#define MBLAZE_GRANTED 0x5555aaaaU +#define MBLAZE_RELEASE 0x55550000U +#define MBLAZE_GRANT_MASK 0xffff0000U +#define MBLAZE_GRANT 0x55550000U +#define MBLAZE_RETRIES 200 +#define MBLAZE_RETRY_US 10000 + +/* Lattice LCMXO3LF ISC command codes */ +#define CPLD_CMD_READ_ID 0xE0000000UL +#define CPLD_CMD_READ_STATUS 0x3C000000UL +#define CPLD_ID_MAX_ATTEMPTS 10 /* one per sync_work tick */ + +/* Status register bit positions (Lattice LCMXO3LF datasheet) */ +#define CPLD_STATUS_DONE BIT(8) +#define CPLD_STATUS_BUSY BIT(12) +#define CPLD_STATUS_FAILED BIT(13) + +/* + * Issue one I2C transaction on the TMC bus: @cmd if not negative, then + * @wlen bytes of @wdata (NULL sends zeros), then @rlen bytes read back. + * The message is built in the scratch buffer from adva_x1_bus_claim(), so + * a run of transfers costs one allocation, not one each. I2C_M_DMA_SAFE + * is not set: the two halves are not separately aligned, so let the core + * bounce. Caller holds the claim, hence __i2c_transfer(). + */ +static int adva_x1_i2c_xfer(struct ptp_ocp *bp, u8 addr, int cmd, + const void *wdata, u8 wlen, + void *rdata, u8 rlen) +{ + u8 *wbuf, *rbuf; + struct i2c_adapter *adap; + struct i2c_msg msgs[2]; + int nmsgs = 0, ret; + u16 hdr = cmd >= 0; + + lockdep_assert_held(&bp->cpld_lock); + + adap = bp->cpld_adap; + if (!adap || !bp->cpld_buf) + return -ENODEV; + + if (hdr + wlen > ADVA_CPLD_XFER_MAX || rlen > ADVA_CPLD_XFER_MAX) + return -EINVAL; + + wbuf = bp->cpld_buf; + rbuf = bp->cpld_buf + ADVA_CPLD_XFER_MAX; + + if (hdr + wlen) { + if (hdr) + wbuf[0] = cmd; + if (wdata) + memcpy(wbuf + hdr, wdata, wlen); + else + memset(wbuf + hdr, 0, wlen); + msgs[nmsgs++] = (struct i2c_msg){ + .addr = addr, + .flags = 0, + .len = hdr + wlen, + .buf = wbuf, + }; + } + if (rlen) { + msgs[nmsgs++] = (struct i2c_msg){ + .addr = addr, + .flags = I2C_M_RD, + .len = rlen, + .buf = rbuf, + }; + } + + ret = __i2c_transfer(adap, msgs, nmsgs); + if (ret != nmsgs) + return (ret < 0) ? ret : -EIO; + + if (rdata && rlen) + memcpy(rdata, rbuf, rlen); + + return 0; +} + +/* Hand the segment back, and wait for the firmware to drop the grant before + * the caller unlocks the adapter: a transfer queued behind us would + * otherwise be clocked out while the controller is still on the TMC bus, + * which is what holding the adapter lock across the grant exists to stop. + */ +static int adva_x1_mblaze_release(struct ptp_ocp *bp) +{ + u32 val = 0; + int i; + + if (!bp->pps_select) + return 0; + + iowrite32(MBLAZE_RELEASE, &bp->pps_select->i2c_bus_ctrl); + /* Flush the posted write, as the acquire path does. */ + ioread32(&bp->pps_select->i2c_bus_ctrl); + + for (i = 0; i < MBLAZE_RETRIES; i++) { + val = ioread32(&bp->pps_select->i2c_bus_ctrl); + if ((val & MBLAZE_GRANT_MASK) != MBLAZE_GRANT) + return 0; + usleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000); + } + + dev_err(&bp->pdev->dev, + "TMC bus still granted after release, i2c_bus_ctrl 0x%08x\n", + val); + + return -ETIMEDOUT; +} + +/* Acquire the shared I2C bus from the MicroBlaze firmware. Returns with no + * request outstanding on failure, so the firmware is never left granting a + * segment to a host that has given up waiting for it. + */ +static int adva_x1_mblaze_acquire(struct ptp_ocp *bp) +{ + u32 val; + int i; + + if (!bp->pps_select) + return -ENODEV; + + /* Drop a request left by a caller that died mid-sequence; cpld_lock + * keeps live ones out. The read back only flushes the posted write. + */ + iowrite32(0, &bp->pps_select->i2c_bus_ctrl); + ioread32(&bp->pps_select->i2c_bus_ctrl); + + iowrite32(MBLAZE_REQUEST, &bp->pps_select->i2c_bus_ctrl); + for (i = 0; i < MBLAZE_RETRIES; i++) { + usleep_range(MBLAZE_RETRY_US, MBLAZE_RETRY_US + 1000); + val = ioread32(&bp->pps_select->i2c_bus_ctrl); + if (val == MBLAZE_GRANTED) + return 0; + } + + /* Drop the request we gave up on. Any error from the hand-back is + * subsumed by the -ETIMEDOUT we are already returning. + */ + adva_x1_mblaze_release(bp); + return -ETIMEDOUT; +} + +/* Route the host controller back to the EEPROMs and release the adapter. + * Safe after a failed claim: it also clears a request that was never granted. + * + * The adapter is unlocked even when the hand-back timed out: keeping the + * root lock would stall every other user of the controller for good, with + * no way to recover it. The error is returned instead, so the operation + * that held the claim fails rather than reporting success over a bus that + * may still be routed to the TMC segment. + */ +static int adva_x1_bus_release(struct ptp_ocp *bp) +{ + struct i2c_adapter *adap = bp->cpld_adap; + int err; + + if (!adap) + return 0; + + err = adva_x1_mblaze_release(bp); + bp->cpld_adap = NULL; + kfree(bp->cpld_buf); + bp->cpld_buf = NULL; + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); + i2c_put_adapter(adap); + + return err; +} + +static int adva_x1_i2c_adap_match(struct device *dev, const void *data) +{ + return !!i2c_verify_adapter(dev); +} + +/* + * Cache the adapter the CPLD hangs off. ptp_ocp_i2c_notifier_call() misses + * it when the i2c controller driver is already loaded: the adapter is then + * added from inside platform_device_register(), before bp->i2c_ctrl is set. + * Only direct children are searched, so a mux adapter cannot match. + * + * Called from the worker rather than once from probe: device_add() notifies + * before it links the device to its parent, so with asynchronous probing + * both the notifier and a single lookup here can miss the same adapter. + * Retrying costs a short klist walk per tick until one of them succeeds. + */ +static void adva_x1_cache_i2c_adap(struct ptp_ocp *bp) +{ + struct device *child; + + if (!bp->has_cpld || !bp->i2c_ctrl || + READ_ONCE(bp->cpld_i2c_adap_nr) >= 0) + return; + + child = device_find_child(&bp->i2c_ctrl->dev, NULL, + adva_x1_i2c_adap_match); + if (!child) + return; + + /* Re-test under the lock so this does not overwrite a number the + * notifier published meanwhile. It cannot tell that apart from a + * number the notifier has just invalidated, so an adapter removed in + * this window can still be cached; adva_x1_bus_claim() rejects it on + * the parent check and forgets it, and the next tick looks again. + */ + scoped_guard(spinlock, &bp->cpld_adap_lock) { + if (bp->cpld_i2c_adap_nr < 0) + bp->cpld_i2c_adap_nr = i2c_verify_adapter(child)->nr; + } + + put_device(child); +} + +/* + * Claim the TMC bus. The adapter lock is held across the handshake to keep + * the EEPROM, nvmem and at24 paths off the controller while it is routed + * away from the EEPROMs; an EEPROM read blocks until the claim is dropped. + */ +static int adva_x1_bus_claim(struct ptp_ocp *bp) +{ + struct i2c_adapter *adap; + int ret; + + lockdep_assert_held(&bp->cpld_lock); + + adap = i2c_get_adapter(READ_ONCE(bp->cpld_i2c_adap_nr)); + if (!adap) + return -ENODEV; + + /* The number is freed before the notifier clears it, so it can + * already be another adapter's. Check this is still ours, and drop + * a number that is not: otherwise every later claim fails the same + * way, where forgetting it lets the worker look the adapter up again. + */ + if (!bp->i2c_ctrl || adap->dev.parent != &bp->i2c_ctrl->dev) { + scoped_guard(spinlock, &bp->cpld_adap_lock) { + if (bp->cpld_i2c_adap_nr == adap->nr) + bp->cpld_i2c_adap_nr = -1; + } + i2c_put_adapter(adap); + return -ENODEV; + } + + /* One scratch buffer per claim rather than per transfer: a claim can + * cover many transfers. + */ + bp->cpld_buf = kzalloc(2 * ADVA_CPLD_XFER_MAX, GFP_KERNEL); + if (!bp->cpld_buf) { + i2c_put_adapter(adap); + return -ENOMEM; + } + + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); + bp->cpld_adap = adap; + + ret = adva_x1_mblaze_acquire(bp); + if (ret) + adva_x1_bus_release(bp); /* keeps the acquire error */ + + return ret; +} + +/* Select a mux channel, or deselect all with ch < 0 - the power-on state. + * The mux is on the TMC bus, so what it is left set to never affects the + * EEPROM paths. + */ +static int adva_x1_mux_select(struct ptp_ocp *bp, int ch) +{ + u8 val = (ch >= 0) ? BIT(ch) : 0; + + return adva_x1_i2c_xfer(bp, ADVA_MUX_ADDR, val, NULL, 0, NULL, 0); +} + +/* + * Send a 4-byte command and read back without an intermediate STOP: two + * messages in one transfer is the Lattice write -> repeated START -> read, + * so no protocol-mangling flag is needed. + */ +static int adva_x1_cpld_cmd_read(struct ptp_ocp *bp, + u32 cmd_be, u8 *out, u8 out_len) +{ + __be32 cmd = cpu_to_be32(cmd_be); + + return adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, -1, &cmd, 4, out, out_len); +} + +static int adva_x1_cpld_read_status(struct ptp_ocp *bp, u32 *status) +{ + u8 buf[4]; + int ret; + + ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_STATUS, buf, 4); + if (ret) + return ret; + *status = get_unaligned_be32(buf); + return 0; +} + +/* + * Read the Lattice device ID into bp->cpld_id. Done once, off the + * unprivileged devlink path, which reports the cached value. -EBUSY means + * cpld_lock is held, so the caller can retry rather than wait behind a long + * CPLD operation. + */ +static int adva_x1_cpld_read_id(struct ptp_ocp *bp) +{ + u8 data[4]; + int err, ret; + + if (!mutex_trylock(&bp->cpld_lock)) + return -EBUSY; + + ret = adva_x1_bus_claim(bp); + if (ret) + goto out; + /* A select reported as failed may still have been ACKed, so the + * deselect runs either way rather than handing the mux back with a + * channel possibly left open. + */ + ret = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL); + if (ret) + goto deselect; + ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_ID, data, 4); + if (!ret) + WRITE_ONCE(bp->cpld_id, get_unaligned_be32(data)); +deselect: + err = adva_x1_mux_select(bp, -1); + if (!ret) + ret = err; + err = adva_x1_bus_release(bp); + if (!ret) + ret = err; +out: + /* Under cpld_lock, so an operation that resets this bookkeeping + * while holding the lock cannot have it overwritten afterwards by a + * worker that had already finished reading. + */ + if (!ret || ++bp->cpld_id_attempts >= CPLD_ID_MAX_ATTEMPTS) + bp->cpld_id_tried = true; + mutex_unlock(&bp->cpld_lock); + if (ret) + dev_dbg(&bp->pdev->dev, + "CPLD device ID unavailable: %d\n", ret); + + return ret; +} + +/* cpld_status - show the flags set in the TAP CPLD status register. */ +static ssize_t +cpld_status_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct ptp_ocp *bp = dev_get_drvdata(dev); + int count = 0; + u32 st = 0; + int err, ret; + + /* A CPLD operation can hold cpld_lock a long time; stay killable. */ + ret = mutex_lock_interruptible(&bp->cpld_lock); + if (ret) + return ret; + + ret = adva_x1_bus_claim(bp); + if (ret) + goto out; + ret = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL); + if (ret) + goto deselect; + ret = adva_x1_cpld_read_status(bp, &st); +deselect: + err = adva_x1_mux_select(bp, -1); + if (!ret) + ret = err; + err = adva_x1_bus_release(bp); + if (!ret) + ret = err; +out: + mutex_unlock(&bp->cpld_lock); + if (ret) + return ret; + + /* Flags: the names of the bits that are set, nothing when none is, + * rather than a value per bit in one file. + */ + if (st & CPLD_STATUS_DONE) + count += sysfs_emit_at(buf, count, "done"); + if (st & CPLD_STATUS_BUSY) + count += sysfs_emit_at(buf, count, "%sbusy", count ? " " : ""); + if (st & CPLD_STATUS_FAILED) + count += sysfs_emit_at(buf, count, "%sfailed", + count ? " " : ""); + + return count + sysfs_emit_at(buf, count, "\n"); +} +static DEVICE_ATTR_ADMIN_RO(cpld_status); + static struct attribute *adva_timecard_attrs[] = { &dev_attr_serialnum.attr, &dev_attr_gnss_sync.attr, @@ -4274,6 +4742,7 @@ static struct attribute *adva_timecard_x1_attrs[] = { &dev_attr_ts_window_adjust.attr, &dev_attr_utc_tai_offset.attr, &dev_attr_tod_correction.attr, + &dev_attr_cpld_status.attr, NULL, }; @@ -4904,6 +5373,7 @@ ptp_ocp_detach(struct ptp_ocp *bp) clk_hw_unregister_fixed_rate(bp->i2c_clk); if (bp->n_irqs) pci_free_irq_vectors(bp->pdev); + mutex_destroy(&bp->cpld_lock); device_unregister(&bp->dev); } @@ -5052,6 +5522,17 @@ ptp_ocp_sync_work(struct work_struct *work) bp->sync = sync; + /* Resolve the adapter here rather than once in probe, where it can + * race the adapter's own registration, and read the ID as soon as it + * turns up. A claim can fail transiently - the firmware may not + * grant the segment straight after power-up - so adva_x1_cpld_read_id() + * retries a bounded number of times before giving up. + */ + adva_x1_cache_i2c_adap(bp); + if (bp->has_cpld && !READ_ONCE(bp->cpld_id_tried) && + READ_ONCE(bp->cpld_i2c_adap_nr) >= 0) + adva_x1_cpld_read_id(bp); + queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ); } @@ -5080,6 +5561,15 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (err) goto out_disable; + /* Before the first error path that calls ptp_ocp_detach(), so + * mutex_destroy() runs on an initialised mutex, and before + * ptp_ocp_register_resources(), so this sentinel cannot overwrite an + * adapter number the i2c notifier stores during registration. + */ + mutex_init(&bp->cpld_lock); + spin_lock_init(&bp->cpld_adap_lock); + bp->cpld_i2c_adap_nr = -1; + INIT_DELAYED_WORK(&bp->sync_work, ptp_ocp_sync_work); /* compat mode. @@ -5158,6 +5648,7 @@ out_dpll: out_dpll_put: dpll_device_put(bp->dpll, &bp->tracker); out_devlink: + /* detach() destroys cpld_lock; no devlink op may still reach it */ devlink_unregister(devlink); out: ptp_ocp_detach(bp); @@ -5204,6 +5695,7 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb, unsigned long action, void *data) { struct device *dev, *child = data; + struct i2c_adapter *adap; struct ptp_ocp *bp; bool add; @@ -5227,11 +5719,25 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb, found: bp = dev_get_drvdata(dev); - if (add) + adap = i2c_verify_adapter(child); + if (add) { ptp_ocp_symlink(bp, child, "i2c"); - else + /* Only the card's own controller: a mux child added on it + * reaches ptp_ocp through the same walk. Numbers are + * recycled, so the claim re-checks the parent itself. + */ + if (bp->i2c_ctrl && adap->dev.parent == &bp->i2c_ctrl->dev) { + scoped_guard(spinlock, &bp->cpld_adap_lock) + bp->cpld_i2c_adap_nr = adap->nr; + } + } else { + /* invalidate before free, but only for the cached adapter */ + scoped_guard(spinlock, &bp->cpld_adap_lock) { + if (bp->cpld_i2c_adap_nr == adap->nr) + bp->cpld_i2c_adap_nr = -1; + } sysfs_remove_link(&bp->dev.kobj, "i2c"); - + } return 0; } From a4b7c15aa78f1064a4f9a89b8ea43905daf5ab27 Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Wed, 16 Sep 2026 18:32:42 +0300 Subject: [PATCH 0662/2126] ptp: ocp: add TAP CPLD flashing via devlink The Lattice MachXO3 CPLD on the ADVA TimeCard X1 is programmed over I2C using in-system programming (ISP). Build on the TMC bus arbitration added previously and expose the update path as a devlink flash component, next to the card flash the driver already writes through devlink. The component is named fw.cpld and reported as a running version, so ->info_get() both publishes the USERCODE of the image currently in the part and lets the core accept the name: devlink dev flash pci/0000:02:00.0 file adva-cpld.bin component fw.cpld Flashing acquires the bus, erases the configuration flash, programs the image page by page and activates it with the MachXO3 REFRESH command, reporting progress with the standard devlink notifications. The CPLD is required to come back with DONE set, not busy and no error code before the update is called successful, as drivers/fpga/machxo2-spi.c does. The whole sequence runs under cpld_lock and the i2c adapter lock, so an EEPROM read blocks for as long as programming takes; the alternative is reading the TMC bus instead. Flashing is privileged: DEVLINK_CMD_FLASH_UPDATE carries GENL_ADMIN_PERM. Signed-off-by: Sagi Maimon Link: https://patch.msgid.link/20260916153242.157171-5-sagi.maimon@adtran.com Signed-off-by: Jakub Kicinski --- Documentation/ABI/testing/sysfs-timecard | 11 +- Documentation/networking/devlink/ptp_ocp.rst | 48 +- drivers/ptp/ptp_ocp.c | 441 ++++++++++++++++++- 3 files changed, 479 insertions(+), 21 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-timecard b/Documentation/ABI/testing/sysfs-timecard index e58824e0cdcd..4ba45c6ee4a3 100644 --- a/Documentation/ABI/testing/sysfs-timecard +++ b/Documentation/ABI/testing/sysfs-timecard @@ -31,9 +31,14 @@ Description: (RO, root only) The flags set in the status register of the A read arbitrates for the shared I2C bus and reprograms the on-card mux, so it is restricted to root. The Lattice device - ID of the CPLD is read once by the driver, shortly after - probe, and reported from that cached value as the fixed - "cpld.id" version by devlink dev info. + ID of the CPLD is read by the driver shortly after probe, + and again after a successful CPLD update, and reported from + that cached value as the fixed "cpld.id" version by + devlink dev info. + + New CPLD firmware is programmed with devlink dev flash, + selecting the "fw.cpld" component; see + Documentation/networking/devlink/ptp_ocp.rst. What: /sys/class/timecard/ocpN/available_clock_sources Date: September 2021 diff --git a/Documentation/networking/devlink/ptp_ocp.rst b/Documentation/networking/devlink/ptp_ocp.rst index 3f997cd9f3a3..f94b759d9cd6 100644 --- a/Documentation/networking/devlink/ptp_ocp.rst +++ b/Documentation/networking/devlink/ptp_ocp.rst @@ -5,7 +5,7 @@ ptp_ocp devlink support ======================== This document describes the devlink features implemented by the ``ptp_ocp`` -device driver. +device driver: the info versions it reports and its flash update support. Info versions ============= @@ -30,6 +30,46 @@ The ``ptp_ocp`` driver reports the following versions - Lattice device ID (IDCODE) of the TAP CPLD, formatted as ``0x%08x``. Only present on ADVA TimeCard X1 boards, which are the only ones carrying that CPLD. Reading it claims the shared I2C bus and - reprograms the on-card mux, so the driver does that once from its - own worker and reports the cached value here; the version is - omitted until that read has succeeded. + reprograms the on-card mux, so the driver does that from its own + worker and reports the cached value here; the version is omitted + until that read has succeeded. The read is made once per binding + and again after a successful CPLD update. + * - ``fw.cpld`` + - running + - USERCODE of the image programmed into the TAP CPLD, formatted as + ``0x%08x``. Read together with ``cpld.id`` and reported the same + way. This is the component name to pass to ``devlink dev flash`` + to update the CPLD. + +Flash update +============ + +The driver implements ``devlink dev flash`` for two separate targets, +selected with the component name. + +.. list-table:: Flash components + :widths: 20 80 + + * - Component + - Description + * - (none) + - The card's own flash, written through the SPI controller the driver + exposes. The card runs the new image after its next reset. + * - ``fw.cpld`` + - The configuration flash of the TAP CPLD on ADVA TimeCard X1 boards, + programmed over I2C with the MachXO3 in-system programming commands + and activated with a REFRESH, so the new image runs immediately. + The image is the raw configuration bitstream. The only check the + driver makes is that its length is a non-zero multiple of the + 16-byte page size, so a container such as ``.jed`` has to be + converted first rather than passed through - one whose length + happens to be a multiple of 16 would be programmed as if it were + a bitstream. + +Programming the CPLD claims the shared I2C bus for the whole cycle, so +reads of the card's EEPROM block until it completes. Progress is reported +with the standard devlink status notifications. + +Example:: + + $ devlink dev flash pci/0000:02:00.0 file adva-cpld.bin component fw.cpld diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 998ea9c6b381..2802989e8494 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -20,12 +20,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #define PCI_DEVICE_ID_META_TIMECARD 0x0400 @@ -434,12 +436,18 @@ struct ptp_ocp { u8 *cpld_buf; /* Lattice device ID; 0 if unread */ u32 cpld_id; + /* USERCODE of the image in the part; valid once cpld_usercode_ok */ + u32 cpld_usercode; + /* cpld_usercode has been read since the last flash */ + bool cpld_usercode_ok; /* one-shot ID read finished, successfully or not; under cpld_lock */ bool cpld_id_tried; /* failed ID read attempts so far; under cpld_lock */ unsigned int cpld_id_attempts; /* x1 TAP CPLD present */ bool has_cpld; + /* EN_CFG_TP issued but not yet REFRESH'd */ + bool cpld_in_config_mode; }; #define OCP_REQ_TIMESTAMP BIT(0) @@ -476,6 +484,13 @@ static int ptp_ocp_adva_board_init(struct ptp_ocp *bp, struct ocp_resource *r); static const struct ocp_sma_op ocp_adva_sma_op; static const struct ocp_sma_op ocp_adva_x1_sma_op; +/* Flash component naming the CPLD image, as reported by ->info_get(). */ +#define ADVA_CPLD_COMPONENT "fw.cpld" + +static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink, + const struct firmware *fw, + struct netlink_ext_ack *extack); + static const struct ocp_attr_group fb_timecard_groups[]; static const struct ocp_attr_group art_timecard_groups[]; @@ -2158,6 +2173,21 @@ ptp_ocp_devlink_flash_update(struct devlink *devlink, const char *msg; int err; + if (params->component) { + if (!bp->has_cpld || + strcmp(params->component, ADVA_CPLD_COMPONENT)) { + NL_SET_ERR_MSG_MOD(extack, + "unsupported flash component"); + return -EOPNOTSUPP; + } + + err = adva_x1_cpld_flash(bp, devlink, params->fw, extack); + msg = err ? "Flash error" : "Flash complete"; + devlink_flash_update_status_notify(devlink, msg, + ADVA_CPLD_COMPONENT, 0, 0); + return err; + } + dev = ptp_ocp_find_flash(bp); if (!dev) { dev_err(&bp->pdev->dev, "Can't find Flash SPI adapter\n"); @@ -2180,6 +2210,8 @@ static int ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, struct netlink_ext_ack *extack) { + enum devlink_info_version_type ver_type = + DEVLINK_INFO_VERSION_TYPE_COMPONENT; struct ptp_ocp *bp = devlink_priv(devlink); const char *fw_image; char buf[32]; @@ -2192,14 +2224,35 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, if (err) return err; - /* Read by the worker, not here: this command is unprivileged and - * reading the ID claims the I2C bus. 0 means unread - skip it - * rather than fail, devlink discards the whole reply on error. - */ - id = READ_ONCE(bp->cpld_id); - if (bp->has_cpld && id) { - sprintf(buf, "0x%08x", id); - err = devlink_info_version_fixed_put(req, "cpld.id", buf); + if (bp->has_cpld) { + /* Read by the worker, not here: this command is unprivileged + * and reading the ID claims the I2C bus. 0 means unread - + * skip it rather than fail, devlink discards the whole reply + * on error. + */ + id = READ_ONCE(bp->cpld_id); + if (id) { + sprintf(buf, "0x%08x", id); + err = devlink_info_version_fixed_put(req, "cpld.id", + buf); + if (err) + return err; + } + + /* The flashable component. Naming it here is what lets + * "devlink dev flash ... component fw.cpld" through, as the + * core matches the name against the versions reported here, + * so it is reported for every board that has the part and not + * only once its USERCODE has been read: a part left holding a + * bad image answers neither, and gating the component on the + * read would make that state unrecoverable. + */ + if (smp_load_acquire(&bp->cpld_usercode_ok)) + sprintf(buf, "0x%08x", READ_ONCE(bp->cpld_usercode)); + else + strscpy(buf, "unknown", sizeof(buf)); + err = devlink_info_version_running_put_ext(req, "fw.cpld", buf, + ver_type); if (err) return err; } @@ -4306,13 +4359,36 @@ static const struct ocp_attr_group art_timecard_groups[] = { /* Lattice LCMXO3LF ISC command codes */ #define CPLD_CMD_READ_ID 0xE0000000UL +/* The USERCODE lives in the configuration flash that ERASE wipes, and the + * page writes carry it: after programming an image whose JEDEC UH field is + * 0x00000004 the part reads back 0x00000004, not an erased value. So there + * is no separate ISC_PROGRAM_USERCODE step here. + */ +#define CPLD_CMD_READ_USERCODE 0xC0000000UL #define CPLD_CMD_READ_STATUS 0x3C000000UL +#define CPLD_CMD_EN_CFG_TP 0x74 /* enable config, transparent mode */ +#define CPLD_CMD_DIS_CFG 0x26 +#define CPLD_CMD_ERASE 0x0E +#define CPLD_CMD_RESET_ADDR 0x46 +#define CPLD_CMD_WRITE_PAGE 0x70 +#define CPLD_CMD_SET_DONE 0x5E +#define CPLD_CMD_REFRESH 0x79 +#define CPLD_PAGE_SIZE 16 +#define CPLD_POLL_US 10000 /* status poll interval while busy */ +/* Bounds how long a claim can hold the i2c root lock, not image validity: + * far above any bitstream this part takes. + */ +#define CPLD_MAX_IMAGE_SZ (256 * 1024) +#define CPLD_EXIT_CFG_TRIES 3 +#define CPLD_ERASE_MS 15000 /* config sector erase, datasheet max */ #define CPLD_ID_MAX_ATTEMPTS 10 /* one per sync_work tick */ /* Status register bit positions (Lattice LCMXO3LF datasheet) */ #define CPLD_STATUS_DONE BIT(8) +#define CPLD_STATUS_ENAB BIT(9) #define CPLD_STATUS_BUSY BIT(12) #define CPLD_STATUS_FAILED BIT(13) +#define CPLD_STATUS_ERR GENMASK(25, 23) /* * Issue one I2C transaction on the TMC bus: @cmd if not negative, then @@ -4571,6 +4647,54 @@ static int adva_x1_mux_select(struct ptp_ocp *bp, int ch) return adva_x1_i2c_xfer(bp, ADVA_MUX_ADDR, val, NULL, 0, NULL, 0); } +/* + * Argument bytes that follow an ISC opcode. Returns NULL with @nargs set + * when the arguments are all zero: adva_x1_i2c_xfer() zeroes the buffer. + * + * EN_CFG_TP, DIS_CFG and REFRESH take two operand bytes here where the SPI + * drivers in drivers/fpga send three. These are the frames the part on this + * board answers: the sequence below has programmed and refreshed it + * successfully over I2C, so the counts are kept as validated rather than + * aligned with the SPI framing. + */ +static const u8 *adva_x1_cpld_args(u8 cmd, u8 *nargs) +{ + static const u8 en_cfg_tp[] = { 0x08, 0x00 }; + /* cfg sector only */ + static const u8 erase_cfg[] = { 0x04, 0x00, 0x00 }; + + switch (cmd) { + case CPLD_CMD_EN_CFG_TP: + *nargs = sizeof(en_cfg_tp); + return en_cfg_tp; + case CPLD_CMD_ERASE: + *nargs = sizeof(erase_cfg); + return erase_cfg; + case CPLD_CMD_RESET_ADDR: + case CPLD_CMD_SET_DONE: + *nargs = 3; + return NULL; + case CPLD_CMD_DIS_CFG: + case CPLD_CMD_REFRESH: + *nargs = 2; + return NULL; + default: + *nargs = 0; + return NULL; + } +} + +/* Send an ISC command with the fixed arguments that belong to it. */ +static int adva_x1_cpld_write(struct ptp_ocp *bp, u8 cmd) +{ + const u8 *args; + u8 nargs; + + args = adva_x1_cpld_args(cmd, &nargs); + + return adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, cmd, args, nargs, NULL, 0); +} + /* * Send a 4-byte command and read back without an intermediate STOP: two * messages in one transfer is the Lattice write -> repeated START -> read, @@ -4596,11 +4720,86 @@ static int adva_x1_cpld_read_status(struct ptp_ocp *bp, u32 *status) return 0; } +/* Poll the status register until the CPLD goes idle, or @max_ms elapses. + * The deadline is on wall time, so the I2C transactions count against it, + * and the status is read once more after it expires before giving up. + */ +static int adva_x1_cpld_wait_ready(struct ptp_ocp *bp, unsigned int max_ms) +{ + u32 status = 0; + int err = 0, ret; + + ret = read_poll_timeout(adva_x1_cpld_read_status, err, + err || (status & CPLD_STATUS_FAILED) || + !(status & CPLD_STATUS_BUSY), + CPLD_POLL_US, max_ms * USEC_PER_MSEC, false, + bp, &status); + if (ret) + return ret; + /* Keep the transport errno so it reaches userspace as-is; -EIO is + * reserved for the CPLD itself reporting FAILED. + */ + if (err) + return err; + if (status & CPLD_STATUS_FAILED) + return -EIO; + + return 0; +} + +/* Wait for BUSY to clear. Unlike adva_x1_cpld_wait_ready() a latched FAILED + * status is not an error here: this is used on the exit path, where an ISC + * command issued while the part is still erasing or programming may not + * latch, so the operation has to be waited out whatever its outcome. + */ +static int adva_x1_cpld_wait_idle(struct ptp_ocp *bp, unsigned int max_ms) +{ + u32 status = 0; + int err = 0, ret; + + ret = read_poll_timeout(adva_x1_cpld_read_status, err, + err || !(status & CPLD_STATUS_BUSY), + CPLD_POLL_US, max_ms * USEC_PER_MSEC, false, + bp, &status); + if (ret) + return ret; + + return err; +} + +/* Leave transparent configuration mode. + * + * A DIS_CFG issued while the part is still busy may not latch, so the wait + * has to succeed before the write is believed - an ACKed write after a + * timed-out wait says nothing about whether the part left the mode. Retry + * a few times rather than leaving it latched on one bad attempt; there is + * no other caller that would try again. + */ +static void adva_x1_cpld_exit_config(struct ptp_ocp *bp) +{ + int err, i; + + if (!bp->cpld_in_config_mode) + return; + + for (i = 0; i < CPLD_EXIT_CFG_TRIES; i++) { + err = adva_x1_cpld_wait_idle(bp, CPLD_ERASE_MS); + if (!err) + err = adva_x1_cpld_write(bp, CPLD_CMD_DIS_CFG); + if (!err) { + bp->cpld_in_config_mode = false; + return; + } + } + + dev_err(&bp->pdev->dev, "CPLD left in configuration mode: %d\n", err); +} + /* - * Read the Lattice device ID into bp->cpld_id. Done once, off the - * unprivileged devlink path, which reports the cached value. -EBUSY means - * cpld_lock is held, so the caller can retry rather than wait behind a long - * CPLD operation. + * Read the Lattice device ID and the image USERCODE under one bus claim. + * Done once, off the unprivileged devlink path, which reports the cached + * values. -EBUSY means cpld_lock is held, so the caller can retry rather + * than wait behind a long CPLD operation. */ static int adva_x1_cpld_read_id(struct ptp_ocp *bp) { @@ -4621,8 +4820,21 @@ static int adva_x1_cpld_read_id(struct ptp_ocp *bp) if (ret) goto deselect; ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_ID, data, 4); - if (!ret) - WRITE_ONCE(bp->cpld_id, get_unaligned_be32(data)); + if (ret) + goto deselect; + /* Publish the ID before the USERCODE is attempted: a part that does + * not answer 0xC0 must not cost us the device ID as well. + */ + WRITE_ONCE(bp->cpld_id, get_unaligned_be32(data)); + + ret = adva_x1_cpld_cmd_read(bp, CPLD_CMD_READ_USERCODE, data, 4); + if (ret) + goto deselect; + WRITE_ONCE(bp->cpld_usercode, get_unaligned_be32(data)); + /* Pairs with the acquire in ptp_ocp_devlink_info_get(): the value has + * to be visible before the flag that declares it valid. + */ + smp_store_release(&bp->cpld_usercode_ok, true); deselect: err = adva_x1_mux_select(bp, -1); if (!ret) @@ -4694,6 +4906,207 @@ out: } static DEVICE_ATTR_ADMIN_RO(cpld_status); +/* + * Program the CPLD configuration flash from @fw and activate it. Selected + * by the "fw.cpld" flash component; the SPI flash keeps the default path. + * Runs under cpld_lock with the i2c adapter lock held, so an EEPROM read + * blocks for as long as programming takes. + */ +static int adva_x1_cpld_flash(struct ptp_ocp *bp, struct devlink *devlink, + const struct firmware *fw, + struct netlink_ext_ack *extack) +{ + size_t offset; + int err, ret; + u32 st; + + if (!fw->size || fw->size % CPLD_PAGE_SIZE) { + NL_SET_ERR_MSG_MOD(extack, + "image must be a whole number of 16-byte pages"); + return -EINVAL; + } + if (fw->size > CPLD_MAX_IMAGE_SZ) { + NL_SET_ERR_MSG_MOD(extack, "image too large for this part"); + return -EINVAL; + } + + mutex_lock(&bp->cpld_lock); + + err = adva_x1_bus_claim(bp); + if (err) + goto unlock; + /* A select reported as failed may still have been ACKed, so hand the + * mux back deselected either way. + */ + err = adva_x1_mux_select(bp, ADVA_MUX_CHANNEL); + if (err) + goto deselect; + + /* A previous flash may have failed to leave configuration mode. Now + * that the bus is claimed again, retry the exit before re-entering; + * a no-op when the flag is already clear. + */ + adva_x1_cpld_exit_config(bp); + + /* Set before EN_CFG_TP, not after: the CPLD may have entered config + * mode even if the write errors or the wait times out, and only this + * makes the exit path send DIS_CFG. A stray DIS_CFG is harmless; + * leaving config mode enabled is not. + */ + bp->cpld_in_config_mode = true; + + err = adva_x1_cpld_write(bp, CPLD_CMD_EN_CFG_TP); + if (!err) + err = adva_x1_cpld_wait_ready(bp, 5000); + if (err) + goto exit_config; + + /* Confirm the part really entered configuration mode. An enable + * frame that did not latch leaves an idle part reporting neither + * BUSY nor FAILED, the erase and page writes are ignored, and DONE + * is still set from the old image - so every later check passes and + * the update would be reported successful with the flash untouched. + */ + err = adva_x1_cpld_read_status(bp, &st); + if (err) + goto exit_config; + if (!(st & CPLD_STATUS_ENAB)) { + dev_err(&bp->pdev->dev, + "CPLD did not enter configuration mode, status 0x%08x\n", + st); + NL_SET_ERR_MSG_MOD(extack, + "CPLD did not enter configuration mode"); + err = -EIO; + goto exit_config; + } + + devlink_flash_update_status_notify(devlink, "Erasing", + ADVA_CPLD_COMPONENT, 0, 0); + err = adva_x1_cpld_write(bp, CPLD_CMD_ERASE); + if (!err) + err = adva_x1_cpld_wait_ready(bp, CPLD_ERASE_MS); + if (err) + goto exit_config; + + /* The old image is gone from here on, so stop reporting its + * identity even if the rest of the sequence fails. Written under + * cpld_lock, which adva_x1_cpld_read_id() also holds across its own + * bookkeeping, so the worker cannot resurrect any of it. + */ + WRITE_ONCE(bp->cpld_id, 0); + WRITE_ONCE(bp->cpld_usercode_ok, false); + bp->cpld_id_tried = false; + bp->cpld_id_attempts = 0; + + err = adva_x1_cpld_write(bp, CPLD_CMD_RESET_ADDR); + if (err) + goto exit_config; + + for (offset = 0; offset < fw->size; offset += CPLD_PAGE_SIZE) { + u8 args[3 + CPLD_PAGE_SIZE] = { 0x00, 0x00, 0x01 }; + + /* The loop holds cpld_lock and the i2c root lock for the + * whole image, so give a dying task a way out. The part is + * left unconfigured, which is recoverable: fw.cpld stays + * advertised so the image can be written again. + */ + if (fatal_signal_pending(current)) { + err = -EINTR; + goto exit_config; + } + + memcpy(&args[3], fw->data + offset, CPLD_PAGE_SIZE); + err = adva_x1_i2c_xfer(bp, ADVA_CPLD_ADDR, CPLD_CMD_WRITE_PAGE, + args, sizeof(args), NULL, 0); + if (!err) + err = adva_x1_cpld_wait_ready(bp, 100); + if (err) + goto exit_config; + + if (!(offset % (CPLD_PAGE_SIZE * 64))) + devlink_flash_update_status_notify(devlink, + "Programming", + ADVA_CPLD_COMPONENT, + offset, fw->size); + } + devlink_flash_update_status_notify(devlink, "Programming", + ADVA_CPLD_COMPONENT, + fw->size, fw->size); + + err = adva_x1_cpld_write(bp, CPLD_CMD_SET_DONE); + if (!err) + err = adva_x1_cpld_wait_ready(bp, 1000); + if (err) + goto exit_config; + + err = adva_x1_cpld_read_status(bp, &st); + if (err) + goto exit_config; + if (!(st & CPLD_STATUS_DONE)) { + dev_err(&bp->pdev->dev, + "CPLD SET_DONE left status 0x%08x\n", st); + NL_SET_ERR_MSG_MOD(extack, "CPLD did not accept the image"); + err = -EIO; + goto exit_config; + } + + devlink_flash_update_status_notify(devlink, "Activating", + ADVA_CPLD_COMPONENT, 0, 0); + err = adva_x1_cpld_write(bp, CPLD_CMD_REFRESH); + if (err) + goto exit_config; + + /* REFRESH reboots the CPLD out of configuration mode, so the exit + * path must not send DIS_CFG afterwards even if a check below fails. + */ + bp->cpld_in_config_mode = false; + + /* The new image is already running, so a segment that is not back + * yet must not be reported as a failed update: retry the reselect + * rather than sampling the mux once at a fixed delay. + */ + msleep(1500); + err = read_poll_timeout(adva_x1_mux_select, err, !err, CPLD_POLL_US, + 3000 * USEC_PER_MSEC, false, + bp, ADVA_MUX_CHANNEL); + if (err) + goto deselect; + + err = adva_x1_cpld_wait_ready(bp, 3000); + if (err) + goto deselect; + + /* Require DONE set, not busy and no error code, as machxo2-spi.c does + * after a refresh: without it a CRC or preamble error reads back as a + * successful update. + */ + err = adva_x1_cpld_read_status(bp, &st); + if (err) + goto deselect; + if (!(st & CPLD_STATUS_DONE) || (st & CPLD_STATUS_BUSY) || + (st & CPLD_STATUS_ERR)) { + dev_err(&bp->pdev->dev, + "CPLD refresh left status 0x%08x\n", st); + NL_SET_ERR_MSG_MOD(extack, "CPLD did not come back configured"); + err = -EIO; + goto deselect; + } + +exit_config: + adva_x1_cpld_exit_config(bp); +deselect: + ret = adva_x1_mux_select(bp, -1); + if (!err) + err = ret; + ret = adva_x1_bus_release(bp); + if (!err) + err = ret; +unlock: + mutex_unlock(&bp->cpld_lock); + + return err; +} + static struct attribute *adva_timecard_attrs[] = { &dev_attr_serialnum.attr, &dev_attr_gnss_sync.attr, From cd7e4b1e479622ffc117bc7215c0796d7acb8dd1 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Thu, 17 Sep 2026 16:42:06 +0800 Subject: [PATCH 0663/2126] tls: drop duplicate check_app_limited in tls_push_sg Before commit c5c37af6ecad9 ("tcp: Convert do_tcp_sendpages() to use MSG_SPLICE_PAGES"), do_tcp_sendpages() did not call tcp_rate_check_app_limited() internally, so callers needed an explicit tcp_rate_check_app_limited() to cover it. That commit replaced do_tcp_sendpages() with direct tcp_sendmsg_locked() calls, which perform the check on every path that queues data. The outer call became redundant but was left in place. The site changed here, tls_push_sg(), holds the socket lock and invokes tcp_sendmsg_locked() on every iteration. The early-return paths in tcp_sendmsg_locked() that skip tcp_rate_check_app_limited() -- the MSG_ZEROCOPY allocation failure and MSG_FASTOPEN branches -- return without queueing any MSG_SPLICE_PAGES data, so there is no functional consequence from omitting the outer check. A potential benefit of this change is that it facilitates future reuse of tls_push_sg() for KTLS support in protocols beyond TCP, such as MPTCP. Since tcp_rate_check_app_limited() is TCP-specific while sendmsg_locked() is a generic interface in struct proto_ops, this change allows us to switch to different protocols via sk->sk_socket->ops->sendmsg_locked() without carrying protocol-specific assumptions. Signed-off-by: Geliang Tang Link: https://patch.msgid.link/5bc803abb4e27054eaffc8b26db7812e6347b0dd.1789634247.git.tanggeliang@kylinos.cn Signed-off-by: Jakub Kicinski --- net/tls/tls_main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index fbb274287aa5..8bdb78718a8d 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -185,8 +185,6 @@ int tls_push_sg(struct sock *sk, ctx->splicing_pages = true; while (1) { - /* is sending application-limited? */ - tcp_rate_check_app_limited(sk); p = sg_page(sg); retry: bvec_set_page(&bvec, p, size, offset); From 083e64a3af7717363d1918baede5757235f94a87 Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Thu, 17 Sep 2026 11:11:14 -0700 Subject: [PATCH 0664/2126] net: devmem: replace gen_pool with freelist devmem only needs fixed-size net_iov allocations for each dma-buf binding. The gen_pool tracks the same free set indirectly through DMA addresses, which makes devmem depend on the generic allocator even though the users are fixed-size net_iov chunks. Mirror the io_uring zcrx model more closely by keeping a binding-level freelist protected by spin_lock_bh(). Use a single net_iov_area owner for the binding, populate each net_iov's DMA address while walking the SG table, and check at teardown that all net_iovs have returned to the freelist. Validate the DMA-BUF size against the net_iov size up front and derive the RX and TX entry count from it, avoiding a separate SG-table pass. Drop the NET_DEVMEM select of GENERIC_ALLOCATOR now that devmem no longer calls gen_pool APIs. Signed-off-by: Stanislav Fomichev Link: https://patch.msgid.link/20260917181116.3319017-2-sdf@fomichev.me Signed-off-by: Jakub Kicinski --- net/Kconfig | 1 - net/core/devmem.c | 186 +++++++++++++++++++++------------------------- net/core/devmem.h | 15 ++-- 3 files changed, 90 insertions(+), 112 deletions(-) diff --git a/net/Kconfig b/net/Kconfig index e38477393551..76ab44aa439a 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -68,7 +68,6 @@ config SKB_EXTENSIONS config NET_DEVMEM def_bool y - select GENERIC_ALLOCATOR depends on DMA_SHARED_BUFFER depends on PAGE_POOL diff --git a/net/core/devmem.c b/net/core/devmem.c index f4d60654ce7f..2ac9d74010a9 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -8,7 +8,6 @@ */ #include -#include #include #include #include @@ -30,23 +29,13 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); static const struct memory_provider_ops dmabuf_devmem_ops; -static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool, - struct gen_pool_chunk *chunk, - void *not_used) +static void +net_devmem_dmabuf_free_chunk_owner(struct dmabuf_genpool_chunk_owner *owner) { - struct dmabuf_genpool_chunk_owner *owner = chunk->owner; - - kvfree(owner->area.niovs); - kfree(owner); -} - -static dma_addr_t net_devmem_get_dma_addr(const struct net_iov *niov) -{ - struct dmabuf_genpool_chunk_owner *owner; - - owner = net_devmem_iov_to_chunk_owner(niov); - return owner->base_dma_addr + - ((dma_addr_t)net_iov_idx(niov) << owner->binding->niov_shift); + if (owner) { + kvfree(owner->area.niovs); + kfree(owner); + } } static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref) @@ -62,24 +51,20 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) { struct net_devmem_dmabuf_binding *binding = container_of(wq, typeof(*binding), unbind_w); - size_t size, avail; - - gen_pool_for_each_chunk(binding->chunk_pool, - net_devmem_dmabuf_free_chunk_owner, NULL); - - size = gen_pool_size(binding->chunk_pool); - avail = gen_pool_avail(binding->chunk_pool); - - if (!WARN(size != avail, "can't destroy genpool. size=%zu, avail=%zu", - size, avail)) - gen_pool_destroy(binding->chunk_pool); + if (binding->freelist) + WARN(binding->free_count != binding->chunk_owner->area.num_niovs, + "destroying dmabuf binding with outstanding net_iovs: total=%zu, free=%zu", + binding->chunk_owner->area.num_niovs, + binding->free_count); + net_devmem_dmabuf_free_chunk_owner(binding->chunk_owner); dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt, binding->direction); dma_buf_detach(binding->dmabuf, binding->attachment); dma_buf_put(binding->dmabuf); xa_destroy(&binding->bound_rxqs); percpu_ref_exit(&binding->ref); + kvfree(binding->freelist); kvfree(binding->tx_vec); kfree(binding); } @@ -87,21 +72,15 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) struct net_iov * net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) { - struct dmabuf_genpool_chunk_owner *owner; - unsigned long dma_addr; struct net_iov *niov; - ssize_t offset; - ssize_t index; - - dma_addr = gen_pool_alloc_owner(binding->chunk_pool, - 1UL << binding->niov_shift, - (void **)&owner); - if (!dma_addr) + spin_lock_bh(&binding->freelist_lock); + if (unlikely(!binding->free_count)) { + spin_unlock_bh(&binding->freelist_lock); return NULL; + } - offset = dma_addr - owner->base_dma_addr; - index = offset >> binding->niov_shift; - niov = &owner->area.niovs[index]; + niov = binding->freelist[--binding->free_count]; + spin_unlock_bh(&binding->freelist_lock); niov->desc.pp_magic = 0; niov->desc.pp = NULL; @@ -113,14 +92,16 @@ net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) void net_devmem_free_dmabuf(struct net_iov *niov) { struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov); - unsigned long dma_addr = net_devmem_get_dma_addr(niov); - size_t niov_size = 1UL << binding->niov_shift; - if (WARN_ON(!gen_pool_has_addr(binding->chunk_pool, dma_addr, - niov_size))) + spin_lock_bh(&binding->freelist_lock); + if (WARN_ON_ONCE(binding->free_count >= + binding->chunk_owner->area.num_niovs)) { + spin_unlock_bh(&binding->freelist_lock); return; + } - gen_pool_free(binding->chunk_pool, dma_addr, niov_size); + binding->freelist[binding->free_count++] = niov; + spin_unlock_bh(&binding->freelist_lock); } void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) @@ -194,12 +175,15 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, struct netlink_ext_ack *extack) { struct net_devmem_dmabuf_binding *binding; + struct dmabuf_genpool_chunk_owner *owner; size_t niov_size = 1UL << niov_shift; static u32 id_alloc_next; struct scatterlist *sg; struct dma_buf *dmabuf; - unsigned int sg_idx, i; - unsigned long virtual; + unsigned int sg_idx; + size_t total_niovs; + size_t niov_idx; + size_t i; int err; if (!dma_dev) { @@ -249,33 +233,55 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_detach; } + if (!IS_ALIGNED(dmabuf->size, niov_size)) { + err = -EINVAL; + NL_SET_ERR_MSG_FMT(extack, + "dmabuf size %zu not aligned to niov size %zu", + dmabuf->size, niov_size); + goto err_unmap; + } + + total_niovs = dmabuf->size >> niov_shift; if (direction == DMA_TO_DEVICE) { - if (!IS_ALIGNED(dmabuf->size, PAGE_SIZE)) { - err = -EINVAL; - NL_SET_ERR_MSG(extack, "TX dma-buf size must be a multiple of PAGE_SIZE"); - goto err_unmap; - } - binding->tx_vec = kvmalloc_objs(struct net_iov *, - dmabuf->size / PAGE_SIZE); + binding->tx_vec = kvmalloc_objs(struct net_iov *, total_niovs); if (!binding->tx_vec) { err = -ENOMEM; goto err_unmap; } + } else { + spin_lock_init(&binding->freelist_lock); + binding->freelist = kvmalloc_array(total_niovs, + sizeof(binding->freelist[0]), + GFP_KERNEL); + if (!binding->freelist) { + err = -ENOMEM; + goto err_unmap; + } } - - binding->chunk_pool = gen_pool_create(niov_shift, - dev_to_node(&dev->dev)); - if (!binding->chunk_pool) { + owner = kzalloc_node(sizeof(*owner), GFP_KERNEL, + dev_to_node(&dev->dev)); + if (!owner) { err = -ENOMEM; - goto err_tx_vec; + goto err_free_freelist; } - virtual = 0; + owner->area.base_virtual = 0; + owner->area.num_niovs = total_niovs; + owner->binding = binding; + owner->area.niovs = kvmalloc_objs(*owner->area.niovs, + owner->area.num_niovs); + if (!owner->area.niovs) { + err = -ENOMEM; + goto err_free_owner; + } + binding->chunk_owner = owner; + + niov_idx = 0; for_each_sgtable_dma_sg(binding->sgt, sg, sg_idx) { dma_addr_t dma_addr = sg_dma_address(sg); - struct dmabuf_genpool_chunk_owner *owner; size_t len = sg_dma_len(sg); struct net_iov *niov; + size_t nr_niovs; if (!IS_ALIGNED(dma_addr, niov_size) || !IS_ALIGNED(len, niov_size)) { @@ -283,64 +289,40 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, NL_SET_ERR_MSG_FMT(extack, "dmabuf sg entry (addr=%pad, len=%zu) not aligned to niov size %zu", &dma_addr, len, niov_size); - goto err_free_chunks; + goto err_free_chunk_owner; } - owner = kzalloc_node(sizeof(*owner), GFP_KERNEL, - dev_to_node(&dev->dev)); - if (!owner) { - err = -ENOMEM; - goto err_free_chunks; - } - - owner->area.base_virtual = virtual; - owner->base_dma_addr = dma_addr; - owner->area.num_niovs = len >> niov_shift; - owner->binding = binding; - - err = gen_pool_add_owner(binding->chunk_pool, dma_addr, - dma_addr, len, dev_to_node(&dev->dev), - owner); - if (err) { - kfree(owner); - err = -EINVAL; - goto err_free_chunks; - } - - owner->area.niovs = kvmalloc_objs(*owner->area.niovs, - owner->area.num_niovs); - if (!owner->area.niovs) { - err = -ENOMEM; - goto err_free_chunks; - } - - for (i = 0; i < owner->area.num_niovs; i++) { - niov = &owner->area.niovs[i]; + nr_niovs = len >> niov_shift; + for (i = 0; i < nr_niovs; i++, niov_idx++) { + niov = &owner->area.niovs[niov_idx]; net_iov_init(niov, &owner->area, NET_IOV_DMABUF); page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), - net_devmem_get_dma_addr(niov)); + dma_addr); if (direction == DMA_TO_DEVICE) - binding->tx_vec[owner->area.base_virtual / PAGE_SIZE + i] = niov; + binding->tx_vec[niov_idx] = niov; + else + binding->freelist[binding->free_count++] = niov; + dma_addr += niov_size; } - - virtual += len; } err = xa_alloc_cyclic(&net_devmem_dmabuf_bindings, &binding->id, binding, xa_limit_32b, &id_alloc_next, GFP_KERNEL); if (err < 0) - goto err_free_chunks; + goto err_free_chunk_owner; list_add(&binding->list, &priv->bindings); return binding; -err_free_chunks: - gen_pool_for_each_chunk(binding->chunk_pool, - net_devmem_dmabuf_free_chunk_owner, NULL); - gen_pool_destroy(binding->chunk_pool); -err_tx_vec: +err_free_chunk_owner: + net_devmem_dmabuf_free_chunk_owner(binding->chunk_owner); + goto err_free_freelist; +err_free_owner: + kfree(owner); +err_free_freelist: + kvfree(binding->freelist); kvfree(binding->tx_vec); err_unmap: dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt, diff --git a/net/core/devmem.h b/net/core/devmem.h index 4a293a7d1149..db2eb6372aee 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -14,6 +14,7 @@ #include struct netlink_ext_ack; +struct dmabuf_genpool_chunk_owner; struct net_devmem_dmabuf_binding { struct dma_buf *dmabuf; @@ -26,7 +27,7 @@ struct net_devmem_dmabuf_binding { * dereferenced. */ void *vdev; - struct gen_pool *chunk_pool; + struct dmabuf_genpool_chunk_owner *chunk_owner; /* Protect dev */ struct mutex lock; @@ -57,6 +58,10 @@ struct net_devmem_dmabuf_binding { /* rxq's this binding is active on. */ struct xarray bound_rxqs; + spinlock_t freelist_lock ____cacheline_aligned_in_smp; + size_t free_count; + struct net_iov **freelist; + /* ID of this binding. Globally unique to all bindings currently * active. */ @@ -77,17 +82,9 @@ struct net_devmem_dmabuf_binding { }; #if defined(CONFIG_NET_DEVMEM) -/* Owner of the dma-buf chunks inserted into the gen pool. Each scatterlist - * entry from the dmabuf is inserted into the genpool as a chunk, and needs - * this owner struct to keep track of some metadata necessary to create - * allocations from this chunk. - */ struct dmabuf_genpool_chunk_owner { struct net_iov_area area; struct net_devmem_dmabuf_binding *binding; - - /* dma_addr of the start of the chunk. */ - dma_addr_t base_dma_addr; }; void __net_devmem_dmabuf_binding_free(struct work_struct *wq); From 13648ba787223c88086b383beead242427e5747a Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Thu, 17 Sep 2026 11:11:15 -0700 Subject: [PATCH 0665/2126] net: devmem: embed net_iov_area in binding After replacing the gen_pool with a binding-level freelist, devmem no longer needs a separate chunk owner object. There is only one net_iov_area for the binding, so store it directly in struct net_devmem_dmabuf_binding. Derive the binding from net_iov_owner() with container_of(), matching the pattern used by io_uring zcrx. This removes the leftover dmabuf_genpool_chunk_owner wrapper and its allocation/free path. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev Link: https://patch.msgid.link/20260917181116.3319017-3-sdf@fomichev.me Signed-off-by: Jakub Kicinski --- net/core/devmem.c | 61 ++++++++++++++--------------------------------- net/core/devmem.h | 25 +++++-------------- 2 files changed, 24 insertions(+), 62 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 2ac9d74010a9..7cac0dab8ea8 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -29,15 +29,6 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); static const struct memory_provider_ops dmabuf_devmem_ops; -static void -net_devmem_dmabuf_free_chunk_owner(struct dmabuf_genpool_chunk_owner *owner) -{ - if (owner) { - kvfree(owner->area.niovs); - kfree(owner); - } -} - static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref) { struct net_devmem_dmabuf_binding *binding = @@ -52,12 +43,11 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) struct net_devmem_dmabuf_binding *binding = container_of(wq, typeof(*binding), unbind_w); if (binding->freelist) - WARN(binding->free_count != binding->chunk_owner->area.num_niovs, + WARN(binding->free_count != binding->area.num_niovs, "destroying dmabuf binding with outstanding net_iovs: total=%zu, free=%zu", - binding->chunk_owner->area.num_niovs, - binding->free_count); + binding->area.num_niovs, binding->free_count); - net_devmem_dmabuf_free_chunk_owner(binding->chunk_owner); + kvfree(binding->area.niovs); dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt, binding->direction); dma_buf_detach(binding->dmabuf, binding->attachment); @@ -94,8 +84,7 @@ void net_devmem_free_dmabuf(struct net_iov *niov) struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov); spin_lock_bh(&binding->freelist_lock); - if (WARN_ON_ONCE(binding->free_count >= - binding->chunk_owner->area.num_niovs)) { + if (WARN_ON_ONCE(binding->free_count >= binding->area.num_niovs)) { spin_unlock_bh(&binding->freelist_lock); return; } @@ -175,13 +164,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, struct netlink_ext_ack *extack) { struct net_devmem_dmabuf_binding *binding; - struct dmabuf_genpool_chunk_owner *owner; size_t niov_size = 1UL << niov_shift; static u32 id_alloc_next; struct scatterlist *sg; struct dma_buf *dmabuf; unsigned int sg_idx; - size_t total_niovs; size_t niov_idx; size_t i; int err; @@ -241,16 +228,18 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } - total_niovs = dmabuf->size >> niov_shift; + binding->area.base_virtual = 0; + binding->area.num_niovs = dmabuf->size >> niov_shift; if (direction == DMA_TO_DEVICE) { - binding->tx_vec = kvmalloc_objs(struct net_iov *, total_niovs); + binding->tx_vec = kvmalloc_objs(struct net_iov *, + binding->area.num_niovs); if (!binding->tx_vec) { err = -ENOMEM; goto err_unmap; } } else { spin_lock_init(&binding->freelist_lock); - binding->freelist = kvmalloc_array(total_niovs, + binding->freelist = kvmalloc_array(binding->area.num_niovs, sizeof(binding->freelist[0]), GFP_KERNEL); if (!binding->freelist) { @@ -258,24 +247,13 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } } - owner = kzalloc_node(sizeof(*owner), GFP_KERNEL, - dev_to_node(&dev->dev)); - if (!owner) { + binding->area.niovs = kvmalloc_objs(*binding->area.niovs, + binding->area.num_niovs); + if (!binding->area.niovs) { err = -ENOMEM; goto err_free_freelist; } - owner->area.base_virtual = 0; - owner->area.num_niovs = total_niovs; - owner->binding = binding; - owner->area.niovs = kvmalloc_objs(*owner->area.niovs, - owner->area.num_niovs); - if (!owner->area.niovs) { - err = -ENOMEM; - goto err_free_owner; - } - binding->chunk_owner = owner; - niov_idx = 0; for_each_sgtable_dma_sg(binding->sgt, sg, sg_idx) { dma_addr_t dma_addr = sg_dma_address(sg); @@ -289,13 +267,13 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, NL_SET_ERR_MSG_FMT(extack, "dmabuf sg entry (addr=%pad, len=%zu) not aligned to niov size %zu", &dma_addr, len, niov_size); - goto err_free_chunk_owner; + goto err_free_niovs; } nr_niovs = len >> niov_shift; for (i = 0; i < nr_niovs; i++, niov_idx++) { - niov = &owner->area.niovs[niov_idx]; - net_iov_init(niov, &owner->area, NET_IOV_DMABUF); + niov = &binding->area.niovs[niov_idx]; + net_iov_init(niov, &binding->area, NET_IOV_DMABUF); page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), dma_addr); if (direction == DMA_TO_DEVICE) @@ -310,17 +288,14 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, binding, xa_limit_32b, &id_alloc_next, GFP_KERNEL); if (err < 0) - goto err_free_chunk_owner; + goto err_free_niovs; list_add(&binding->list, &priv->bindings); return binding; -err_free_chunk_owner: - net_devmem_dmabuf_free_chunk_owner(binding->chunk_owner); - goto err_free_freelist; -err_free_owner: - kfree(owner); +err_free_niovs: + kvfree(binding->area.niovs); err_free_freelist: kvfree(binding->freelist); kvfree(binding->tx_vec); diff --git a/net/core/devmem.h b/net/core/devmem.h index db2eb6372aee..6ed16b4b4687 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -14,9 +14,9 @@ #include struct netlink_ext_ack; -struct dmabuf_genpool_chunk_owner; struct net_devmem_dmabuf_binding { + struct net_iov_area area; struct dma_buf *dmabuf; struct dma_buf_attachment *attachment; struct sg_table *sgt; @@ -27,7 +27,6 @@ struct net_devmem_dmabuf_binding { * dereferenced. */ void *vdev; - struct dmabuf_genpool_chunk_owner *chunk_owner; /* Protect dev */ struct mutex lock; @@ -82,11 +81,6 @@ struct net_devmem_dmabuf_binding { }; #if defined(CONFIG_NET_DEVMEM) -struct dmabuf_genpool_chunk_owner { - struct net_iov_area area; - struct net_devmem_dmabuf_binding *binding; -}; - void __net_devmem_dmabuf_binding_free(struct work_struct *wq); struct net_devmem_dmabuf_binding * net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, @@ -101,18 +95,11 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, struct net_devmem_dmabuf_binding *binding, struct netlink_ext_ack *extack); -static inline struct dmabuf_genpool_chunk_owner * -net_devmem_iov_to_chunk_owner(const struct net_iov *niov) -{ - struct net_iov_area *owner = net_iov_owner(niov); - - return container_of(owner, struct dmabuf_genpool_chunk_owner, area); -} - static inline struct net_devmem_dmabuf_binding * net_devmem_iov_binding(const struct net_iov *niov) { - return net_devmem_iov_to_chunk_owner(niov)->binding; + return container_of(net_iov_owner(niov), + struct net_devmem_dmabuf_binding, area); } static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) @@ -122,11 +109,11 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) { - struct dmabuf_genpool_chunk_owner *co = - net_devmem_iov_to_chunk_owner(niov); + struct net_devmem_dmabuf_binding *binding = + net_devmem_iov_binding(niov); return net_iov_owner(niov)->base_virtual + - ((unsigned long)net_iov_idx(niov) << co->binding->niov_shift); + ((unsigned long)net_iov_idx(niov) << binding->niov_shift); } static inline bool From 050bacb138f18a5666b7c6bb7e3b4c33f4517ea9 Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Thu, 17 Sep 2026 11:11:16 -0700 Subject: [PATCH 0666/2126] net: devmem: batch net_iov allocations into the page_pool cache Rename net_devmem_alloc_dmabuf() into net_devmem_alloc_dmabuf_bulk() and make it refill page pool with up to PP_ALLOC_CACHE_REFILL NIOVs, similar to io_pp_zc_alloc_netmems(). That should amortize recently introduced freelist_lock. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev Link: https://patch.msgid.link/20260917181116.3319017-4-sdf@fomichev.me Signed-off-by: Jakub Kicinski --- net/core/devmem.c | 57 ++++++++++++++++++++++++++++++----------------- net/core/devmem.h | 8 ------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 7cac0dab8ea8..a9d86b5a5588 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -59,24 +59,24 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) kfree(binding); } -struct net_iov * -net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) +static unsigned int +net_devmem_alloc_dmabuf_bulk(struct net_devmem_dmabuf_binding *binding, + netmem_ref *netmems, unsigned int count) { - struct net_iov *niov; + unsigned int i; + spin_lock_bh(&binding->freelist_lock); - if (unlikely(!binding->free_count)) { - spin_unlock_bh(&binding->freelist_lock); - return NULL; + + count = min_t(size_t, count, binding->free_count); + for (i = 0; i < count; i++) { + struct net_iov *niov = binding->freelist[--binding->free_count]; + + netmems[i] = net_iov_to_netmem(niov); } - niov = binding->freelist[--binding->free_count]; spin_unlock_bh(&binding->freelist_lock); - niov->desc.pp_magic = 0; - niov->desc.pp = NULL; - atomic_long_set(&niov->desc.pp_ref_count, 0); - - return niov; + return count; } void net_devmem_free_dmabuf(struct net_iov *niov) @@ -428,20 +428,35 @@ int mp_dmabuf_devmem_init(struct page_pool *pool) netmem_ref mp_dmabuf_devmem_alloc_netmems(struct page_pool *pool, gfp_t gfp) { struct net_devmem_dmabuf_binding *binding = pool->mp_priv; - struct net_iov *niov; - netmem_ref netmem; + netmem_ref *netmems = pool->alloc.cache; + unsigned int allocated, i; - niov = net_devmem_alloc_dmabuf(binding); - if (!niov) + if (WARN_ON_ONCE(pool->alloc.count)) return 0; - netmem = net_iov_to_netmem(niov); + allocated = net_devmem_alloc_dmabuf_bulk(binding, netmems, + PP_ALLOC_CACHE_REFILL); + if (unlikely(!allocated)) + return 0; - page_pool_set_pp_info(pool, netmem); + for (i = 0; i < allocated; i++) { + struct net_iov *niov = netmem_to_net_iov(netmems[i]); - pool->pages_state_hold_cnt++; - trace_page_pool_state_hold(pool, netmem, pool->pages_state_hold_cnt); - return netmem; + niov->desc.pp_magic = 0; + niov->desc.pp = NULL; + atomic_long_set(&niov->desc.pp_ref_count, 0); + + page_pool_set_pp_info(pool, netmems[i]); + + pool->pages_state_hold_cnt++; + trace_page_pool_state_hold(pool, netmems[i], + pool->pages_state_hold_cnt); + } + + /* Return the last one, the rest stay in the page_pool cache. */ + allocated--; + pool->alloc.count = allocated; + return netmems[allocated]; } void mp_dmabuf_devmem_destroy(struct page_pool *pool) diff --git a/net/core/devmem.h b/net/core/devmem.h index 6ed16b4b4687..f71d9a2bcb3d 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -131,8 +131,6 @@ net_devmem_dmabuf_binding_put(struct net_devmem_dmabuf_binding *binding) void net_devmem_get_net_iov(struct net_iov *niov); void net_devmem_put_net_iov(struct net_iov *niov); -struct net_iov * -net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding); void net_devmem_free_dmabuf(struct net_iov *ppiov); @@ -189,12 +187,6 @@ net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, return -EOPNOTSUPP; } -static inline struct net_iov * -net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) -{ - return NULL; -} - static inline void net_devmem_free_dmabuf(struct net_iov *ppiov) { } From 4c1b44ac2221bfecabf3b772c4c04c1a90048328 Mon Sep 17 00:00:00 2001 From: Vikas Gupta Date: Thu, 17 Sep 2026 12:15:38 +0530 Subject: [PATCH 0667/2126] bnge: update HSI Update HSI to support future patches implementing multi-RSS and NTUPLE-related features. Signed-off-by: Vikas Gupta Reviewed-by: Dharmender Garg Link: https://patch.msgid.link/20260917064548.773334-2-vikas.gupta@broadcom.com Signed-off-by: Jakub Kicinski --- include/linux/bnge/hsi.h | 136 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/include/linux/bnge/hsi.h b/include/linux/bnge/hsi.h index 1f7bd96415a5..d4fe662d60b1 100644 --- a/include/linux/bnge/hsi.h +++ b/include/linux/bnge/hsi.h @@ -8607,6 +8607,7 @@ struct hwrm_cfa_l2_filter_alloc_input { #define CFA_L2_FILTER_ALLOC_REQ_ENABLES_MIRROR_VNIC_ID 0x10000UL #define CFA_L2_FILTER_ALLOC_REQ_ENABLES_NUM_VLANS 0x20000UL #define CFA_L2_FILTER_ALLOC_REQ_ENABLES_T_NUM_VLANS 0x40000UL + #define CFA_L2_FILTER_ALLOC_REQ_ENABLES_RFS_RING_TBL_IDX 0x80000UL u8 l2_addr[6]; u8 num_vlans; u8 t_num_vlans; @@ -8663,7 +8664,8 @@ struct hwrm_cfa_l2_filter_alloc_input { #define CFA_L2_FILTER_ALLOC_REQ_PRI_HINT_MIN 0x4UL #define CFA_L2_FILTER_ALLOC_REQ_PRI_HINT_LAST CFA_L2_FILTER_ALLOC_REQ_PRI_HINT_MIN u8 unused_5; - __le32 unused_6; + __le16 rfs_ring_tbl_idx; + __le16 unused_6; __le64 l2_filter_id_hint; }; @@ -8900,6 +8902,95 @@ struct hwrm_cfa_tunnel_filter_free_output { u8 valid; }; +/* hwrm_cfa_ntuple_filter_alloc_input (size:1024b/128B) */ +struct hwrm_cfa_ntuple_filter_alloc_input { + __le16 req_type; + __le16 cmpl_ring; + __le16 seq_id; + __le16 target_id; + __le64 resp_addr; + __le32 flags; + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_LOOPBACK 0x1UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_DROP 0x2UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_METER 0x4UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_DEST_FID 0x8UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_ARP_REPLY 0x10UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_DEST_RFS_RING_IDX 0x20UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_NO_L2_CONTEXT 0x40UL + __le32 enables; + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID 0x1UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE 0x2UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE 0x4UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR 0x8UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE 0x10UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR 0x20UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK 0x40UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR 0x80UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK 0x100UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL 0x200UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT 0x400UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK 0x800UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT 0x1000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK 0x2000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_PRI_HINT 0x4000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_NTUPLE_FILTER_ID 0x8000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID 0x10000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_MIRROR_VNIC_ID 0x20000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_MACADDR 0x40000UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_RFS_RING_TBL_IDX 0x80000UL + __le64 l2_filter_id; + u8 src_macaddr[6]; + __be16 ethertype; + u8 ip_addr_type; + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_UNKNOWN 0x0UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4 0x4UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6 0x6UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_LAST CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6 + u8 ip_protocol; + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_UNKNOWN 0x0UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_TCP 0x6UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_UDP 0x11UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_ICMP 0x1UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_ICMPV6 0x3aUL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_RSVD 0xffUL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_LAST CFA_NTUPLE_FILTER_ALLOC_REQ_IP_PROTOCOL_RSVD + __le16 dst_id; + __le16 rfs_ring_tbl_idx; + u8 tunnel_type; + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_NONTUNNEL 0x0UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN 0x1UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_NVGRE 0x2UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_L2GRE 0x3UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_IPIP 0x4UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_GENEVE 0x5UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_MPLS 0x6UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_STT 0x7UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_IPGRE 0x8UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN_V4 0x9UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_IPGRE_V1 0xaUL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_L2_ETYPE 0xbUL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN_GPE_V6 0xcUL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN_GPE 0x10UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL 0xffUL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_LAST CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL + u8 pri_hint; + #define CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_NO_PREFER 0x0UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_ABOVE 0x1UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_BELOW 0x2UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_HIGHEST 0x3UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_LOWEST 0x4UL + #define CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_LAST CFA_NTUPLE_FILTER_ALLOC_REQ_PRI_HINT_LOWEST + __be32 src_ipaddr[4]; + __be32 src_ipaddr_mask[4]; + __be32 dst_ipaddr[4]; + __be32 dst_ipaddr_mask[4]; + __be16 src_port; + __be16 src_port_mask; + __be16 dst_port; + __be16 dst_port_mask; + __le64 ntuple_filter_id_hint; +}; + /* hwrm_cfa_ntuple_filter_alloc_output (size:192b/24B) */ struct hwrm_cfa_ntuple_filter_alloc_output { __le16 error_code; @@ -9014,6 +9105,49 @@ struct hwrm_cfa_ntuple_filter_cfg_output { u8 valid; }; +/* hwrm_cfa_adv_flow_mgnt_qcaps_input (size:256b/32B) */ +struct hwrm_cfa_adv_flow_mgnt_qcaps_input { + __le16 req_type; + __le16 cmpl_ring; + __le16 seq_id; + __le16 target_id; + __le64 resp_addr; + __le32 unused_0[4]; +}; + +/* hwrm_cfa_adv_flow_mgnt_qcaps_output (size:128b/16B) */ +struct hwrm_cfa_adv_flow_mgnt_qcaps_output { + __le16 error_code; + __le16 req_type; + __le16 seq_id; + __le16 resp_len; + __le32 flags; + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_FLOW_HND_16BIT_SUPPORTED 0x1UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_FLOW_HND_64BIT_SUPPORTED 0x2UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_FLOW_BATCH_DELETE_SUPPORTED 0x4UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_FLOW_RESET_ALL_SUPPORTED 0x8UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_NTUPLE_FLOW_DEST_FUNC_SUPPORTED 0x10UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_TX_EEM_FLOW_SUPPORTED 0x20UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RX_EEM_FLOW_SUPPORTED 0x40UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_FLOW_COUNTER_ALLOC_SUPPORTED 0x80UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_SUPPORTED 0x100UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_UNTAGGED_VLAN_SUPPORTED 0x200UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_XDP_SUPPORTED 0x400UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_L2_HEADER_SOURCE_FIELDS_SUPPORTED 0x800UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_NTUPLE_FLOW_RX_ARP_SUPPORTED 0x1000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_V2_SUPPORTED 0x2000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_NTUPLE_FLOW_RX_ETHERTYPE_IP_SUPPORTED 0x4000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_TRUFLOW_CAPABLE 0x8000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_L2_FILTER_TRAFFIC_TYPE_L2_ROCE_SUPPORTED 0x10000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_LAG_SUPPORTED 0x20000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_NTUPLE_FLOW_NO_L2CTX_SUPPORTED 0x40000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_NIC_FLOW_STATS_SUPPORTED 0x80000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_NTUPLE_FLOW_RX_EXT_IP_PROTO_SUPPORTED 0x100000UL + #define CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_V3_SUPPORTED 0x200000UL + u8 unused_0[3]; + u8 valid; +}; + /* hwrm_tunnel_dst_port_alloc_input (size:192b/24B) */ struct hwrm_tunnel_dst_port_alloc_input { __le16 req_type; From 6e0ee63cd2c9f0b0d3892306d4d40bd7ef07b285 Mon Sep 17 00:00:00 2001 From: Qingshuang Fu Date: Thu, 17 Sep 2026 11:30:49 +0800 Subject: [PATCH 0668/2126] selftests: net: fou_mcast_encap: load the fou module setup_ipv4() creates a GRETAP tunnel with FOU encap and configures a FOU port via "ip fou add". Both require the fou module, which cannot be auto-loaded. The test assumes CONFIG_NET_FOU=y, which matches the default selftests config, but fails on kernels built with CONFIG_NET_FOU=m. Without the fou module, tunnel creation fails and the test reports a false failure with 0/100 received packets: RTNETLINK answers: Invalid argument TEST: FOU/GRETAP IPv4 multicast encap resubmit (received 0/100) [FAIL] Load the fou module and skip the subtest cleanly when unavailable. This matches the existing fou6 handling in this script and the pattern used in pmtu.sh. modprobe is a no-op when CONFIG_NET_FOU=y, so default selftest builds remain unchanged. Signed-off-by: Qingshuang Fu Link: https://patch.msgid.link/20260917033049.792209-1-fuqingshuang@kylinos.cn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/fou_mcast_encap.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/net/fou_mcast_encap.sh b/tools/testing/selftests/net/fou_mcast_encap.sh index 70210d39fba3..5f84d58d3075 100755 --- a/tools/testing/selftests/net/fou_mcast_encap.sh +++ b/tools/testing/selftests/net/fou_mcast_encap.sh @@ -51,8 +51,6 @@ setup_common() { } setup_ipv4() { - # IPv4 FOU (CONFIG_NET_FOU) is built in on kernels configured for - # these tests, so no module load is needed here. ip -n "$NSENDER" addr add 10.0.0.1/24 dev veth_s ip -n "$NRECV" addr add 10.0.0.2/24 dev veth_r @@ -160,8 +158,13 @@ run_ping_test() { } setup_common -setup_ipv4 -run_ping_test -4 eoudp4 "$TUN4_R" "FOU/GRETAP IPv4 multicast encap resubmit" + +if modprobe -q fou; then + setup_ipv4 + run_ping_test -4 eoudp4 "$TUN4_R" "FOU/GRETAP IPv4 multicast encap resubmit" +else + log_test_skip "FOU/GRETAP IPv4 multicast encap resubmit" +fi if setup_ipv6; then run_ping_test -6 eoudp6 "$TUN6_R" "FOU/ip6gretap IPv6 multicast encap resubmit" From 4d68b3483721b18be2f2fec0c709eaf665658bb5 Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 20 Sep 2026 11:46:51 +0800 Subject: [PATCH 0669/2126] net: alacritech: publish the PCI module aliases The SLIC driver has a PCI ID table connected to its pci_driver, but does not export it. Its module therefore lacks the PCI aliases used to automatically load it for the supported Alacritech adapters. Export the existing PCI table without changing device matching. The issue was found by our static-analysis tool. Cc: stable+noautosel@kernel.org # never worked Reviewed-by: Simon Horman Reviewed-by: Lino Sanfilippo Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260920034651.18109-1-hppiscas@163.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/alacritech/slicoss.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/alacritech/slicoss.c b/drivers/net/ethernet/alacritech/slicoss.c index c1949ca060ca..14b74c09233e 100644 --- a/drivers/net/ethernet/alacritech/slicoss.c +++ b/drivers/net/ethernet/alacritech/slicoss.c @@ -34,6 +34,7 @@ static const struct pci_device_id slic_id_tbl[] = { PCI_DEVICE_ID_ALACRITECH_OASIS) }, { 0 } }; +MODULE_DEVICE_TABLE(pci, slic_id_tbl); static const char slic_stats_strings[][ETH_GSTRING_LEN] = { "rx_packets", From ab86dbf4a6ad584f9f5749e8b8f0bbb351151d3a Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sun, 20 Sep 2026 10:27:44 +0800 Subject: [PATCH 0670/2126] net: protocol: use assign_bit() where applicable Convert open-coded if/else with set_bit/clear_bit and their non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit API. Where a bit is toggled based on its own value, use change_bit() instead. Done with Coccinelle semantic patch: // set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); // clear_bit -> set_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond); // __set_bit -> __clear_bit => __assign_bit @@ expression cond, bit, addr; @@ -if (cond) - __set_bit(bit, addr); -else - __clear_bit(bit, addr); +__assign_bit(bit, addr, cond); // __clear_bit -> __set_bit => __assign_bit @@ expression cond, bit, addr; @@ -if (cond) - __clear_bit(bit, addr); -else - __set_bit(bit, addr); +__assign_bit(bit, addr, !cond); Signed-off-by: Peng Fan Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260920022745.3145847-1-peng.fan@oss.nxp.com Signed-off-by: Jakub Kicinski --- net/6lowpan/debugfs.c | 10 ++-------- net/bridge/br.c | 5 +---- net/bridge/br_sysfs_if.c | 10 ++-------- net/dsa/tag_ksz.c | 5 +---- net/ncsi/ncsi-rsp.c | 10 ++-------- net/x25/af_x25.c | 5 +---- 6 files changed, 9 insertions(+), 36 deletions(-) diff --git a/net/6lowpan/debugfs.c b/net/6lowpan/debugfs.c index 600b9563bfc5..d959b132c067 100644 --- a/net/6lowpan/debugfs.c +++ b/net/6lowpan/debugfs.c @@ -21,10 +21,7 @@ static int lowpan_ctx_flag_active_set(void *data, u64 val) if (val != 0 && val != 1) return -EINVAL; - if (val) - set_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, &ctx->flags); - else - clear_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, &ctx->flags); + assign_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, &ctx->flags, val); return 0; } @@ -46,10 +43,7 @@ static int lowpan_ctx_flag_c_set(void *data, u64 val) if (val != 0 && val != 1) return -EINVAL; - if (val) - set_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags); - else - clear_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags); + assign_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags, val); return 0; } diff --git a/net/bridge/br.c b/net/bridge/br.c index a5e5b2db110e..09a120b3b76c 100644 --- a/net/bridge/br.c +++ b/net/bridge/br.c @@ -396,10 +396,7 @@ void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on) if (cur == on) return; - if (on) - set_bit(opt, &br->options); - else - clear_bit(opt, &br->options); + assign_bit(opt, &br->options, on); } static void __net_exit br_net_exit_rtnl(struct net *net, diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c index bde731c01e10..b9bcafa7f034 100644 --- a/net/bridge/br_sysfs_if.c +++ b/net/bridge/br_sysfs_if.c @@ -64,10 +64,7 @@ static int store_flag(struct net_bridge_port *p, unsigned long v, int err; oflags = flags; - if (v) - __set_bit(bitnr, &flags); - else - __clear_bit(bitnr, &flags); + __assign_bit(bitnr, &flags, v); if (flags == oflags) return 0; @@ -77,10 +74,7 @@ static int store_flag(struct net_bridge_port *p, unsigned long v, netdev_err(p->dev, "%s\n", extack._msg); return err; } - if (v) - set_bit(bitnr, &p->flags); - else - clear_bit(bitnr, &p->flags); + assign_bit(bitnr, &p->flags, v); br_port_flags_change(p, BIT(bitnr)); return 0; } diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index b4d70ba930dc..b0340a7be8c9 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -41,10 +41,7 @@ static void ksz_hwtstamp_set_state(struct dsa_switch *ds, bool on) { struct ksz_tagger_private *priv = ksz_tagger_private(ds); - if (on) - set_bit(KSZ_HWTS_EN, &priv->state); - else - clear_bit(KSZ_HWTS_EN, &priv->state); + assign_bit(KSZ_HWTS_EN, &priv->state, on); } static void ksz_disconnect(struct dsa_switch *ds) diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c index fbd84bc8026a..9c91872a2921 100644 --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -884,10 +884,7 @@ static int ncsi_rsp_handler_gp(struct ncsi_request *nr) spin_lock_irqsave(&nc->lock, flags); bitmap = &ncmf->bitmap; for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) { - if (!(enable & (0x1 << i))) - clear_bit(i, bitmap); - else - set_bit(i, bitmap); + assign_bit(i, bitmap, enable & (0x1 << i)); memcpy(&ncmf->addrs[i * ETH_ALEN], pdata, ETH_ALEN); } @@ -899,10 +896,7 @@ static int ncsi_rsp_handler_gp(struct ncsi_request *nr) bitmap = &ncvf->bitmap; spin_lock_irqsave(&nc->lock, flags); for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) { - if (!(enable & (0x1 << i))) - clear_bit(i, bitmap); - else - set_bit(i, bitmap); + assign_bit(i, bitmap, enable & (0x1 << i)); ncvf->vids[i] = ntohs(*(__be16 *)pdata); } diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index 033e7d059f58..f45c9ec7d2c6 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -439,10 +439,7 @@ static int x25_setsockopt(struct socket *sock, int level, int optname, if (copy_from_sockptr(&opt, optval, sizeof(int))) goto out; - if (opt) - set_bit(X25_Q_BIT_FLAG, &x25_sk(sk)->flags); - else - clear_bit(X25_Q_BIT_FLAG, &x25_sk(sk)->flags); + assign_bit(X25_Q_BIT_FLAG, &x25_sk(sk)->flags, opt); rc = 0; out: return rc; From 51cb6a6424f38801807041435f64b9d5d4a349d0 Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 20 Sep 2026 11:45:57 +0800 Subject: [PATCH 0671/2126] net: xscale: publish the IXP46x PTP OF module alias The IXP46x PTP driver matches intel,ixp46x-ptp-timer via its OF table, but does not export that table. A module build therefore lacks the OF alias used to automatically load the timer driver. Export the existing table without changing the matching or probe logic. The issue was found by our static-analysis tool. Cc: stable+noautosel@kernel.org # never worked Reviewed-by: Simon Horman Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260920034557.17734-1-hppiscas@163.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xscale/ptp_ixp46x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/xscale/ptp_ixp46x.c b/drivers/net/ethernet/xscale/ptp_ixp46x.c index 558c4f8d23f7..c805d1df5d4e 100644 --- a/drivers/net/ethernet/xscale/ptp_ixp46x.c +++ b/drivers/net/ethernet/xscale/ptp_ixp46x.c @@ -307,6 +307,7 @@ static const struct of_device_id ptp_ixp_match[] = { }, { }, }; +MODULE_DEVICE_TABLE(of, ptp_ixp_match); static struct platform_driver ptp_ixp_driver = { .driver = { From 1643b81c38c92674ebceb66dd61211e4ef86b8fe Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Thu, 17 Sep 2026 15:22:29 +0200 Subject: [PATCH 0672/2126] net: mvneta: rely on napi_build_skb() in mvneta_swbm_build_skb() mvneta_swbm_build_skb() is only invoked from mvneta_poll(), the NAPI poll routine, so it always runs in NAPI context. Use napi_build_skb() instead of build_skb() to source the skb head from the per-CPU NAPI cache, avoiding a per-packet kmem_cache_alloc() of the skb head. Signed-off-by: Lorenzo Bianconi Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260917-mvneta-napi-poll-v1-1-fb57604932d3@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/mvneta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index 543e566425c1..c2b1098d8d1d 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -2403,7 +2403,7 @@ mvneta_swbm_build_skb(struct mvneta_port *pp, struct page_pool *pool, if (unlikely(xdp_buff_has_frags(xdp))) num_frags = sinfo->nr_frags; - skb = build_skb(xdp->data_hard_start, PAGE_SIZE); + skb = napi_build_skb(xdp->data_hard_start, PAGE_SIZE); if (!skb) return ERR_PTR(-ENOMEM); From fcc1a92b7a901473ce052d34c2d1d33da15739e4 Mon Sep 17 00:00:00 2001 From: Edoardo Canepa Date: Thu, 17 Sep 2026 13:15:20 +0200 Subject: [PATCH 0673/2126] selftests/net: run tun tests in a dedicated network namespace The tun_vnet_udptnl fixture creates a fresh tap device, assigns it a fixed MAC address and installs the outer neighbor entry as NUD_PERMANENT. On systems where systemd-udevd is running and a systemd .link file sets MACAddressPolicy=persistent (the default shipped by systemd in 99-default.link, so this is what most systemd-based hosts inherit), systemd-udevd's net_setup_link builtin asynchronously sends an RTM_SETLINK to reassign the freshly created tap device's MAC to a machine-persistent value. When that lands after the fixture has configured the device, both directions break: - recv_gso_packet transmits through the tap, and the address change flushes the neighbor entry the fixture installed: do_setlink -> netif_set_mac_address -> call_netdevice_notifiers(NETDEV_CHANGEADDR) -> ndisc_netdev_event (arp_netdev_event for an IPv4 outer) -> neigh_changeaddr -> neigh_flush_dev(tbl, dev, /* skip_perm = */ false) so the packet hits __neigh_create() and waits on neighbor resolution that never completes. - send_gso_packet writes frames addressed to the MAC the fixture assigned. Once the tap has a different address, eth_type_trans() marks them PACKET_OTHERHOST and the IP receive path drops them. Either way nothing arrives before the receive timeout, and the test fails with, for example: tun.c:947:send_gso_packet:Expected ret (0) == variant->data_size (1) tun.c:948:send_gso_packet:Expected r_num_mss (0) == variant->r_num_mss (1) tun.c:962:recv_gso_packet:Expected ret (0) == variant->data_size (1) The failure is non-deterministic and reproduces on a plain systemd-based VM with no containers. Fix by calling unshare(CLONE_NEWNET) from both fixture setups. The harness runs each test in its own forked process, so every test gets a private network namespace that is torn down with it, and all tap and geneve devices are created in a namespace that systemd-udevd (running in the init netns) does not watch, so its RTM_SETLINK never fires against them. Creating a network namespace needs CAP_SYS_ADMIN in the current user namespace and CONFIG_NET_NS=y, neither of which the tests required before. Where they are unavailable the unshare() is reported with SKIP() rather than aborting, so the binary still emits a full TAP stream and a runner can tell "network namespaces unavailable" apart from a real tun/tap regression. Verified on a plain systemd-based VM running the affected kernel. Without the fix, 1000 sequential invocations of tun -r tun_vnet_udptnl.4in6_nogsosz_1byte.recv_gso_packet fail 10 times, and 2 out of 20 full runs of the test binary fail. With the fix there are no failures in either case. Reported-by: Po-Hsu Lin Closes: https://bugs.launchpad.net/bugs/2158217 Signed-off-by: Edoardo Canepa Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260917111520.2614448-1-edoardo.canepa@canonical.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/tun.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c index abe488bac50b..6db21dad0efe 100644 --- a/tools/testing/selftests/net/tun.c +++ b/tools/testing/selftests/net/tun.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -488,6 +489,10 @@ FIXTURE(tun) FIXTURE_SETUP(tun) { + if (unshare(CLONE_NEWNET)) + SKIP(return, "Cannot create network namespace: %s", + strerror(errno)); + memset(self->ifname, 0, sizeof(self->ifname)); self->fd = tun_alloc(self->ifname); @@ -732,6 +737,10 @@ FIXTURE_SETUP(tun_vnet_udptnl) struct sockaddr_storage ssa, dsa; void *sip, *dip, *smac, *dmac; + if (unshare(CLONE_NEWNET)) + SKIP(return, "Cannot create network namespace: %s", + strerror(errno)); + flags = (variant->is_tap ? IFF_TAP : IFF_TUN) | IFF_VNET_HDR | IFF_MULTI_QUEUE | IFF_NO_PI; features = TUN_F_CSUM | TUN_F_UDP_TUNNEL_GSO | From 114bd09838ac6954baaf110aebc4d5503057f88a Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 20 Sep 2026 11:36:41 +0800 Subject: [PATCH 0674/2126] net: hip04: use 16-bit byte order for HI13X1 TX fields The HI13X1 TX descriptor stores send_size and data_offset in 16-bit fields, unlike the 32-bit send_size field in the other descriptor layout. The transmit path nevertheless converts both HI13X1 fields with cpu_to_be32() before assigning them to u16 members. On a little-endian CPU, the conversion moves these small values into the upper half of the 32-bit result and the assignment discards that half. The descriptor consequently loses the packet size and cache-line offset. Use cpu_to_be16() for the two HI13X1 fields. Leave the other layout's 32-bit size conversion unchanged. The issue was found by our static-analysis tool. Cc: stable+noautosel@kernel.org # untested fix for ancient HW Reviewed-by: Simon Horman Reviewed-by: Jijie Shao Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260920033641.13590-1-hppiscas@163.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/hisilicon/hip04_eth.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hip04_eth.c b/drivers/net/ethernet/hisilicon/hip04_eth.c index fc2c47dcfaab..2920985144bf 100644 --- a/drivers/net/ethernet/hisilicon/hip04_eth.c +++ b/drivers/net/ethernet/hisilicon/hip04_eth.c @@ -527,13 +527,14 @@ hip04_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) priv->tx_skb[tx_head] = skb; priv->tx_phys[tx_head] = phys; - desc->send_size = (__force u32)cpu_to_be32(skb->len); #if defined(CONFIG_HI13X1_GMAC) + desc->send_size = (__force u16)cpu_to_be16(skb->len); desc->cfg = (__force u32)cpu_to_be32(TX_CLEAR_WB | TX_FINISH_CACHE_INV | TX_RELEASE_TO_PPE | priv->port << TX_POOL_SHIFT); - desc->data_offset = (__force u32)cpu_to_be32(phys & SOC_CACHE_LINE_MASK); + desc->data_offset = (__force u16)cpu_to_be16(phys & SOC_CACHE_LINE_MASK); desc->send_addr = (__force u32)cpu_to_be32(phys & ~SOC_CACHE_LINE_MASK); #else + desc->send_size = (__force u32)cpu_to_be32(skb->len); desc->cfg = (__force u32)cpu_to_be32(TX_CLEAR_WB | TX_FINISH_CACHE_INV); desc->send_addr = (__force u32)cpu_to_be32(phys); #endif From 1b4efa0399f549d9b9bf82b3e2450e10a06d65b8 Mon Sep 17 00:00:00 2001 From: Victor Nogueira Date: Fri, 18 Sep 2026 10:51:57 -0300 Subject: [PATCH 0675/2126] net/sched: Avoid quadratic handle scan in qdisc_alloc_handle qdisc_alloc_handle scans for a free auto-handle by probing the per-device qdisc hash one handle at a time. With the 16-bucket hash populated by tens of thousands of qdiscs, the failing scan is O(N^2) under rtnl_lock. A single failing add then holds rtnl_lock for most of a second, and rtnl_lock is global, so all other netlink configuration is blocked for that time. First try the handle after the rotating cursor with one qdisc_lookup, as the first iteration of the current loop does; that handle is normally free. Only when it is taken, build a bitmap of the occupied auto-handle majors in one pass over the hash and pick the first free major from the cursor. The scan is cyclic over all 0x7FFF majors starting from the same autohandle + 1 position as the current loop, so it returns the same handle for the same device state and fails only when all 0x7FFF majors are taken. The root qdisc is seeded separately because qdisc_hash_add skips parent == TC_H_ROOT. When the next handle is free, only the single qdisc_lookup of the current loop's first iteration runs; when it is taken, one O(N) walk follows. Measured as tc wall time on a defconfig kernel in a 2-vCPU guest, with an HTB root holding 32768 classes and all 32767 auto-handles in use (a no-op tc command takes 5-6.5 ms): unpatched patched failing add, space exhausted 613-749 ms 8-10 ms add after a mid-range delete 572-573 ms 9 ms The failure path returns -ENOMEM (bitmap allocation) or -ENOSPC (space exhausted) through a handle out-parameter instead of the overloaded 0 return. Since either error is now possible, the extack message changes from "Maximum number of qdisc handles was exceeded" to "Failed to allocate a qdisc handle". Reported-by: Vega Co-developed-by: Jamal Hadi Salim Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260918135157.163015-1-victor@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/sch_api.c | 92 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 463ededcdcfe..f36c41224bcc 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -770,22 +771,75 @@ void qdisc_class_hash_remove(struct Qdisc_class_hash *clhash, } EXPORT_SYMBOL(qdisc_class_hash_remove); -/* Allocate an unique handle from space managed by kernel - * Possible range is [8000-FFFF]:0000 (0x8000 values) - */ -static u32 qdisc_alloc_handle(struct net_device *dev) -{ - int i = 0x8000; - static u32 autohandle = TC_H_MAKE(0x80000000U, 0); +#define QDISC_AUTO_HANDLE_BASE 0x8000 /* first auto-handle major */ +#define QDISC_AUTO_HANDLE_END 0xFFFE /* last auto-handle major */ +#define QDISC_AUTO_HANDLE_COUNT (QDISC_AUTO_HANDLE_END - \ + QDISC_AUTO_HANDLE_BASE + 1) - do { - autohandle += TC_H_MAKE(0x10000U, 0); - if (autohandle == TC_H_MAKE(TC_H_ROOT, 0)) - autohandle = TC_H_MAKE(0x80000000U, 0); - if (!qdisc_lookup(dev, autohandle)) - return autohandle; - cond_resched(); - } while (--i > 0); +/* Allocate a unique handle from space managed by kernel + * Possible range is [8000-FFFE]:0000 (0x7FFF values); 0xFFFF is the + * TC_H_ROOT/ingress major. + */ +static int qdisc_alloc_handle(struct net_device *dev, u32 *handlep) +{ + static u32 autohandle = TC_H_MAKE(0x80000000U, 0); + unsigned long start, bit; + unsigned long *bitmap; + struct Qdisc *q; + u32 handle, maj; + int b; + + start = ((autohandle >> 16) - QDISC_AUTO_HANDLE_BASE + 1) % + QDISC_AUTO_HANDLE_COUNT; + + /* The cursor moves past every handle it hands out, so the next + * handle is normally free: try it with one hashed lookup before + * walking the whole hash. + */ + handle = (start + QDISC_AUTO_HANDLE_BASE) << 16; + if (!qdisc_lookup(dev, handle)) { + autohandle = handle; + *handlep = handle; + return 0; + } + + bitmap = bitmap_zalloc(QDISC_AUTO_HANDLE_COUNT, GFP_KERNEL); + if (!bitmap) + return -ENOMEM; + + /* Mark the occupied auto-handle majors: the hash holds all + * qdiscs except root and ingress ones, and the root can carry + * an auto-range handle. + */ + q = rtnl_dereference(dev->qdisc); + maj = TC_H_MAJ(q->handle) >> 16; + if (!(q->flags & TCQ_F_BUILTIN) && !TC_H_MIN(q->handle) && + maj >= QDISC_AUTO_HANDLE_BASE && maj <= QDISC_AUTO_HANDLE_END) + set_bit(maj - QDISC_AUTO_HANDLE_BASE, bitmap); + + hash_for_each(dev->qdisc_hash, b, q, hash) { + maj = TC_H_MAJ(q->handle) >> 16; + if (maj >= QDISC_AUTO_HANDLE_BASE && + maj <= QDISC_AUTO_HANDLE_END && !TC_H_MIN(q->handle)) + set_bit(maj - QDISC_AUTO_HANDLE_BASE, bitmap); + } + + bit = find_next_zero_bit(bitmap, QDISC_AUTO_HANDLE_COUNT, start); + if (bit >= QDISC_AUTO_HANDLE_COUNT) { + bit = find_first_zero_bit(bitmap, start); + if (bit >= start) + bit = QDISC_AUTO_HANDLE_COUNT; + } + + if (bit >= QDISC_AUTO_HANDLE_COUNT) { + bitmap_free(bitmap); + return -ENOSPC; + } + + handle = (bit + QDISC_AUTO_HANDLE_BASE) << 16; + autohandle = handle; + bitmap_free(bitmap); + *handlep = handle; return 0; } @@ -1308,10 +1362,10 @@ static struct Qdisc *qdisc_create(struct net_device *dev, handle = TC_H_MAKE(TC_H_INGRESS, 0); } else { if (handle == 0) { - handle = qdisc_alloc_handle(dev); - if (handle == 0) { - NL_SET_ERR_MSG(extack, "Maximum number of qdisc handles was exceeded"); - err = -ENOSPC; + err = qdisc_alloc_handle(dev, &handle); + if (err) { + NL_SET_ERR_MSG(extack, + "Failed to allocate a qdisc handle"); goto err_out3; } } From bfc9df9e40c9a8562dabd5f2339787e63b75a325 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Thu, 17 Sep 2026 14:14:10 -0700 Subject: [PATCH 0676/2126] octeontx2-af: Allocate ikpu2 with ARRAY_SIZE() In preparation for making the devm_kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.) This is allocating room for a copy of ikpu_action_entries, which is an array of struct npc_kpu_profile_action, but it asked for a single object the size of the whole array, which would make the allocation type a pointer to the array rather than the "struct npc_kpu_profile_action *" being assigned. Allocate ARRAY_SIZE-many entries instead. The resulting allocation size is the same. Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0: drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.o Signed-off-by: Kees Cook Reviewed-by: Ratheesh Kannoth Link: https://patch.msgid.link/20260917211409.i.425-kees@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c index c34f8d86cc8a..42a601976db3 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -1959,8 +1959,9 @@ static int npc_apply_custom_kpu_from_fs(struct rvu *rvu, fw = rvu->kpu_fwdata; /* Binary blob contains ikpu actions entries at start of data[0] */ - profile->ikpu2 = devm_kcalloc(rvu->dev, 1, - sizeof(ikpu_action_entries), + profile->ikpu2 = devm_kcalloc(rvu->dev, + ARRAY_SIZE(ikpu_action_entries), + sizeof(*profile->ikpu2), GFP_KERNEL); if (!profile->ikpu2) return -ENOMEM; From d7fddeed325df4414704822e5ee656f3e79cefbc Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:42 +0300 Subject: [PATCH 0677/2126] net: bridge: factor out common flood completion handling Factor out the common flood completion handling shared by br_flood and br_multicast_flood into a new helper - br_flood_finish. No functional changes intended. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-2-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_forward.c | 65 ++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 46c762ca5177..31d54125b441 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -197,12 +197,33 @@ out: return p; } +static void br_flood_finish(struct net_bridge_port *prev, struct sk_buff *skb, + bool local_rcv, bool local_orig) +{ + enum skb_drop_reason reason = SKB_DROP_REASON_NO_TX_TARGET; + + if (IS_ERR_OR_NULL(prev)) { + if (IS_ERR(prev)) { + reason = PTR_ERR(prev) == -ENOMEM ? SKB_DROP_REASON_NOMEM : + SKB_DROP_REASON_NOT_SPECIFIED; + } + + if (!local_rcv) + kfree_skb_reason(skb, reason); + return; + } + + if (local_rcv) + deliver_clone(prev, skb, local_orig); + else + __br_forward(prev, skb, local_orig); +} + /* called under rcu_read_lock */ void br_flood(struct net_bridge *br, struct sk_buff *skb, enum br_pkt_type pkt_type, bool local_rcv, bool local_orig, u16 vid) { - enum skb_drop_reason reason = SKB_DROP_REASON_NO_TX_TARGET; struct net_bridge_port *prev = NULL; struct net_bridge_port *p; @@ -243,25 +264,11 @@ void br_flood(struct net_bridge *br, struct sk_buff *skb, } prev = maybe_deliver(prev, p, skb, local_orig); - if (IS_ERR(prev)) { - reason = PTR_ERR(prev) == -ENOMEM ? SKB_DROP_REASON_NOMEM : - SKB_DROP_REASON_NOT_SPECIFIED; - goto out; - } + if (IS_ERR(prev)) + break; } - if (!prev) - goto out; - - if (local_rcv) - deliver_clone(prev, skb, local_orig); - else - __br_forward(prev, skb, local_orig); - return; - -out: - if (!local_rcv) - kfree_skb_reason(skb, reason); + br_flood_finish(prev, skb, local_rcv, local_orig); } #ifdef CONFIG_BRIDGE_IGMP_SNOOPING @@ -301,7 +308,6 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct net_bridge_mcast *brmctx, bool local_rcv, bool local_orig) { - enum skb_drop_reason reason = SKB_DROP_REASON_NO_TX_TARGET; struct net_bridge_port *prev = NULL; struct net_bridge_port_group *p; bool allow_mode_include = true; @@ -343,11 +349,9 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, } prev = maybe_deliver(prev, port, skb, local_orig); - if (IS_ERR(prev)) { - reason = PTR_ERR(prev) == -ENOMEM ? SKB_DROP_REASON_NOMEM : - SKB_DROP_REASON_NOT_SPECIFIED; - goto out; - } + if (IS_ERR(prev)) + break; + delivered: if ((unsigned long)lport >= (unsigned long)port) p = rcu_dereference(p->next); @@ -355,17 +359,6 @@ delivered: rp = rcu_dereference(hlist_next_rcu(rp)); } - if (!prev) - goto out; - - if (local_rcv) - deliver_clone(prev, skb, local_orig); - else - __br_forward(prev, skb, local_orig); - return; - -out: - if (!local_rcv) - kfree_skb_reason(skb, reason); + br_flood_finish(prev, skb, local_rcv, local_orig); } #endif From 25622bef888590390fb53e2e668781bd90bb29fd Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:43 +0300 Subject: [PATCH 0678/2126] net: bridge: factor out port flooding Factor out port flooding code into its own helper, it will be used by later changes to flood to specific port VLANs. No functional changes intended. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-3-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_forward.c | 77 +++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 31d54125b441..a696c6c128e3 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -219,6 +219,48 @@ static void br_flood_finish(struct net_bridge_port *prev, struct sk_buff *skb, __br_forward(prev, skb, local_orig); } +static void br_flood_port(struct net_bridge_port **prev, + struct net_bridge_port *p, struct sk_buff *skb, + enum br_pkt_type pkt_type, bool local_orig, u16 vid) +{ + /* Do not flood unicast traffic to ports that turn it off, nor + * other traffic if flood off, except for traffic we originate + */ + switch (pkt_type) { + case BR_PKT_UNICAST: + if (!test_bit(BR_FLOOD_BIT, &p->flags)) + return; + break; + case BR_PKT_MULTICAST: + if (!test_bit(BR_MCAST_FLOOD_BIT, &p->flags) && + skb->dev != p->br->dev) + return; + break; + case BR_PKT_BROADCAST: + if (!test_bit(BR_BCAST_FLOOD_BIT, &p->flags) && + skb->dev != p->br->dev) + return; + break; + } + + /* Do not flood to ports that enable proxy ARP */ + if (test_bit(BR_PROXYARP_BIT, &p->flags)) + return; + if (BR_INPUT_SKB_CB(skb)->proxyarp_replied) { + if (test_bit(BR_PROXYARP_WIFI_BIT, &p->flags)) + return; + /* For gratuitous ARPs/NAs, check neigh_forward_grat. + * For regular ARPs/NDs, check only neigh_suppress. + */ + if (br_is_neigh_suppress_enabled(p, vid) && + (!BR_INPUT_SKB_CB(skb)->grat_arp || + !br_is_neigh_forward_grat_enabled(p, vid))) + return; + } + + *prev = maybe_deliver(*prev, p, skb, local_orig); +} + /* called under rcu_read_lock */ void br_flood(struct net_bridge *br, struct sk_buff *skb, enum br_pkt_type pkt_type, bool local_rcv, bool local_orig, @@ -230,40 +272,7 @@ void br_flood(struct net_bridge *br, struct sk_buff *skb, br_tc_skb_miss_set(skb, pkt_type != BR_PKT_BROADCAST); list_for_each_entry_rcu(p, &br->port_list, list) { - /* Do not flood unicast traffic to ports that turn it off, nor - * other traffic if flood off, except for traffic we originate - */ - switch (pkt_type) { - case BR_PKT_UNICAST: - if (!test_bit(BR_FLOOD_BIT, &p->flags)) - continue; - break; - case BR_PKT_MULTICAST: - if (!test_bit(BR_MCAST_FLOOD_BIT, &p->flags) && skb->dev != br->dev) - continue; - break; - case BR_PKT_BROADCAST: - if (!test_bit(BR_BCAST_FLOOD_BIT, &p->flags) && skb->dev != br->dev) - continue; - break; - } - - /* Do not flood to ports that enable proxy ARP */ - if (test_bit(BR_PROXYARP_BIT, &p->flags)) - continue; - if (BR_INPUT_SKB_CB(skb)->proxyarp_replied) { - if (test_bit(BR_PROXYARP_WIFI_BIT, &p->flags)) - continue; - /* For gratuitous ARPs/NAs, check neigh_forward_grat. - * For regular ARPs/NDs, check only neigh_suppress. - */ - if (br_is_neigh_suppress_enabled(p, vid) && - (!BR_INPUT_SKB_CB(skb)->grat_arp || - !br_is_neigh_forward_grat_enabled(p, vid))) - continue; - } - - prev = maybe_deliver(prev, p, skb, local_orig); + br_flood_port(&prev, p, skb, pkt_type, local_orig, vid); if (IS_ERR(prev)) break; } From b82e41db0085da71444245f24eb9b7b602a56362 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:44 +0300 Subject: [PATCH 0679/2126] net: bridge: vlan: cache the pvid vlan entry directly VLAN groups cache the pvid and its state separately requiring state updates to keep both copies synchronized. Lockless readers can also observe the pvid and state from different updates. Cache an rcu protected pointer to the pvid vlan entry instead. This makes the vlan entry the single source of truth and lets the ingress path reuse it without another lookup. It also makes the vlan entry always available at the ingress path for subsequent forwarding-path optimizations. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-4-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_mst.c | 13 ++---- net/bridge/br_private.h | 25 +++++------- net/bridge/br_vlan.c | 76 ++++++++++++++---------------------- net/bridge/br_vlan_options.c | 12 ++---- 4 files changed, 46 insertions(+), 80 deletions(-) diff --git a/net/bridge/br_mst.c b/net/bridge/br_mst.c index 63fc1dd0e9bc..252d5c927f71 100644 --- a/net/bridge/br_mst.c +++ b/net/bridge/br_mst.c @@ -79,16 +79,11 @@ int br_mst_get_state(const struct net_device *dev, u16 msti, u8 *state) } EXPORT_SYMBOL_GPL(br_mst_get_state); -static void br_mst_vlan_set_state(struct net_bridge_vlan_group *vg, - struct net_bridge_vlan *v, - u8 state) +static void br_mst_vlan_set_state(struct net_bridge_vlan *v, u8 state) { if (br_vlan_get_state(v) == state) return; - if (v->vid == br_get_pvid(vg)) - br_vlan_set_pvid_state(vg, state); - br_vlan_set_state(v, state); } @@ -129,7 +124,7 @@ int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, if (READ_ONCE(v->brvlan->msti) != msti) continue; - br_mst_vlan_set_state(vg, v, state); + br_mst_vlan_set_state(v, state); } out_rcu_unlock: @@ -149,13 +144,13 @@ static void br_mst_vlan_sync_state(struct net_bridge_vlan *pv, u16 msti) * it. */ if (v != pv && v->brvlan->msti == msti) { - br_mst_vlan_set_state(vg, pv, br_vlan_get_state(v)); + br_mst_vlan_set_state(pv, br_vlan_get_state(v)); return; } } /* Otherwise, start out in a new MSTI with all ports disabled. */ - return br_mst_vlan_set_state(vg, pv, BR_STATE_DISABLED); + return br_mst_vlan_set_state(pv, BR_STATE_DISABLED); } int br_mst_vlan_set_msti(struct net_bridge_vlan *mv, u16 msti) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 09c397e30330..bda25f851342 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -256,8 +256,7 @@ struct net_bridge_vlan { * @tunnel_hash: Hash table to map from tunnel key ID (e.g. VXLAN VNI) to VLAN * @vlan_list: sorted VLAN entry list * @num_vlans: number of total VLAN entries - * @pvid: PVID VLAN id - * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking) + * @pvid: RCU-protected PVID VLAN entry * * IMPORTANT: Be careful when checking if there're VLAN entries using list * primitives because the bridge can have entries in its list which @@ -269,9 +268,8 @@ struct net_bridge_vlan_group { struct rhashtable vlan_hash; struct rhashtable tunnel_hash; struct list_head vlan_list; + struct net_bridge_vlan __rcu *pvid; u16 num_vlans; - u16 pvid; - u8 pvid_state; }; /* bridge fdb flags */ @@ -1687,10 +1685,16 @@ static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) { + struct net_bridge_vlan *pvid; + if (!vg) return 0; - return READ_ONCE(vg->pvid); + pvid = rcu_dereference_rtnl(vg->pvid); + if (!pvid) + return 0; + + return pvid->vid; } static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) @@ -1922,17 +1926,6 @@ static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) br_multicast_update_vlan_mcast_ctx(v, state); } -static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) -{ - return READ_ONCE(vg->pvid_state); -} - -static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, - u8 state) -{ - WRITE_ONCE(vg->pvid_state, state); -} - /* learn_allow is true at ingress and false at egress */ static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) { diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 34ede0f3e452..bfedd13e3fd4 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -35,21 +35,21 @@ static struct net_bridge_vlan *br_vlan_lookup(struct rhashtable *tbl, u16 vid) } static void __vlan_add_pvid(struct net_bridge_vlan_group *vg, - const struct net_bridge_vlan *v) + struct net_bridge_vlan *v) { - if (vg->pvid == v->vid) + if (rcu_access_pointer(vg->pvid) == v) return; - br_vlan_set_pvid_state(vg, br_vlan_get_state(v)); - WRITE_ONCE(vg->pvid, v->vid); + RCU_INIT_POINTER(vg->pvid, v); } -static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid) +static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, + struct net_bridge_vlan *v) { - if (vg->pvid != vid) + if (rcu_access_pointer(vg->pvid) != v) return; - WRITE_ONCE(vg->pvid, 0); + RCU_INIT_POINTER(vg->pvid, NULL); } /* Update the BRIDGE_VLAN_INFO_PVID and BRIDGE_VLAN_INFO_UNTAGGED flags of @v. @@ -60,6 +60,7 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, bool commit) { struct net_bridge_vlan_group *vg; + struct net_bridge_vlan *pvid; u16 vlan_flags; bool change; @@ -70,7 +71,8 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, /* check if anything would be changed on commit */ vlan_flags = v->flags; - change = !!(flags & BRIDGE_VLAN_INFO_PVID) == !!(vg->pvid != v->vid) || + pvid = rtnl_dereference(vg->pvid); + change = !!(flags & BRIDGE_VLAN_INFO_PVID) == !!(pvid != v) || ((flags ^ vlan_flags) & BRIDGE_VLAN_INFO_UNTAGGED); if (!commit) @@ -79,7 +81,7 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, if (flags & BRIDGE_VLAN_INFO_PVID) __vlan_add_pvid(vg, v); else - __vlan_delete_pvid(vg, v->vid); + __vlan_delete_pvid(vg, v); if (flags & BRIDGE_VLAN_INFO_UNTAGGED) vlan_flags |= BRIDGE_VLAN_INFO_UNTAGGED; @@ -403,7 +405,7 @@ static void __vlan_del(struct net_bridge_vlan *v) masterv = v->brvlan; } - __vlan_delete_pvid(vg, v->vid); + __vlan_delete_pvid(vg, v); if (p) { err = __vlan_vid_del(p->dev, p->br, v); if (err) @@ -453,7 +455,7 @@ static void __vlan_flush(const struct net_bridge *br, struct net_bridge_vlan *vlan, *tmp; u16 v_start = 0, v_end = 0; - __vlan_delete_pvid(vg, vg->pvid); + __vlan_delete_pvid(vg, rtnl_dereference(vg->pvid)); list_for_each_entry_safe(vlan, tmp, &vg->vlan_list, vlist) { /* take care of disjoint ranges */ if (!v_start) { @@ -579,42 +581,32 @@ static bool __allowed_ingress(const struct net_bridge *br, } if (!*vid) { - u16 pvid = br_get_pvid(vg); - + v = vg ? rcu_dereference(vg->pvid) : NULL; /* Frame had a tag with VID 0 or did not have a tag. * See if pvid is set on this port. That tells us which * vlan untagged or priority-tagged traffic belongs to. */ - if (!pvid) + if (!v) goto drop; /* PVID is set on this port. Any untagged or priority-tagged * ingress frame is considered to belong to this vlan. */ - *vid = pvid; + *vid = v->vid; if (likely(!tagged)) /* Untagged Frame. */ - __vlan_hwaccel_put_tag(skb, br->vlan_proto, pvid); + __vlan_hwaccel_put_tag(skb, br->vlan_proto, v->vid); else /* Priority-tagged Frame. * At this point, we know that skb->vlan_tci VID * field was 0. * We update only VID field and preserve PCP field. */ - skb->vlan_tci |= pvid; - - /* if snooping and stats are disabled we can avoid the lookup */ - if (!br_opt_get(br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) && - !br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) { - if (*state == BR_STATE_FORWARDING) { - *state = br_vlan_get_pvid_state(vg); - if (!br_vlan_state_allowed(*state, true)) - goto drop; - } - return true; - } + skb->vlan_tci |= v->vid; + } else { + v = br_vlan_find(vg, *vid); } - v = br_vlan_find(vg, *vid); + if (!v || !br_vlan_should_use(v)) goto drop; @@ -697,11 +689,10 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) *vid = 0; if (!*vid) { - *vid = br_get_pvid(vg); - if (!*vid || - !br_vlan_state_allowed(br_vlan_get_pvid_state(vg), true)) + v = rcu_dereference(vg->pvid); + if (!v || !br_vlan_state_allowed(br_vlan_get_state(v), true)) return false; - + *vid = v->vid; return true; } @@ -1061,17 +1052,10 @@ int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val) static bool vlan_default_pvid(struct net_bridge_vlan_group *vg, u16 vid) { - struct net_bridge_vlan *v; + struct net_bridge_vlan *pvid = rtnl_dereference(vg->pvid); - if (vid != vg->pvid) - return false; - - v = br_vlan_lookup(&vg->vlan_hash, vid); - if (v && br_vlan_should_use(v) && - (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)) - return true; - - return false; + return pvid && pvid->vid == vid && br_vlan_should_use(pvid) && + (pvid->flags & BRIDGE_VLAN_INFO_UNTAGGED); } static void br_vlan_disable_default_pvid(struct net_bridge *br) @@ -1524,7 +1508,7 @@ int br_vlan_get_info(const struct net_device *dev, u16 vid, p_vinfo->vid = vid; p_vinfo->flags = v->flags; - if (vid == br_get_pvid(vg)) + if (v == rcu_access_pointer(vg->pvid)) p_vinfo->flags |= BRIDGE_VLAN_INFO_PVID; return 0; } @@ -1551,7 +1535,7 @@ int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid, p_vinfo->vid = vid; p_vinfo->flags = READ_ONCE(v->flags); - if (vid == br_get_pvid(vg)) + if (v == rcu_access_pointer(vg->pvid)) p_vinfo->flags |= BRIDGE_VLAN_INFO_PVID; return 0; } @@ -1956,7 +1940,7 @@ void br_vlan_notify(const struct net_bridge *br, goto out_kfree; flags = v->flags; - if (br_get_pvid(vg) == v->vid) + if (v == rcu_access_pointer(vg->pvid)) flags |= BRIDGE_VLAN_INFO_PVID; break; case RTM_DELVLAN: diff --git a/net/bridge/br_vlan_options.c b/net/bridge/br_vlan_options.c index 506668fc31d9..e4b7a147e42b 100644 --- a/net/bridge/br_vlan_options.c +++ b/net/bridge/br_vlan_options.c @@ -110,8 +110,7 @@ size_t br_vlan_opts_nl_size(void) + 0; } -static int br_vlan_modify_state(struct net_bridge_vlan_group *vg, - struct net_bridge_vlan *v, +static int br_vlan_modify_state(struct net_bridge_vlan *v, u8 state, bool *changed, struct netlink_ext_ack *extack) @@ -143,9 +142,6 @@ static int br_vlan_modify_state(struct net_bridge_vlan_group *vg, if (v->state == state) return 0; - if (v->vid == br_get_pvid(vg)) - br_vlan_set_pvid_state(vg, state); - br_vlan_set_state(v, state); *changed = true; @@ -216,7 +212,6 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p, static int br_vlan_process_one_opts(const struct net_bridge *br, const struct net_bridge_port *p, - struct net_bridge_vlan_group *vg, struct net_bridge_vlan *v, struct nlattr **tb, bool *changed, @@ -228,7 +223,7 @@ static int br_vlan_process_one_opts(const struct net_bridge *br, if (tb[BRIDGE_VLANDB_ENTRY_STATE]) { u8 state = nla_get_u8(tb[BRIDGE_VLANDB_ENTRY_STATE]); - err = br_vlan_modify_state(vg, v, state, changed, extack); + err = br_vlan_modify_state(v, state, changed, extack); if (err) return err; } @@ -339,8 +334,7 @@ int br_vlan_process_options(const struct net_bridge *br, break; } - err = br_vlan_process_one_opts(br, p, vg, v, tb, &changed, - extack); + err = br_vlan_process_one_opts(br, p, v, tb, &changed, extack); if (err) break; From f69acdd819b01aaa7d32b4bf27cd29fdd780a06f Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:45 +0300 Subject: [PATCH 0680/2126] net: bridge: vlan: introduce a list of port-VLANs in the master VLAN Keep a list of all port-VLANs that have been created within their master VLAN. The list is rcu-safe and will be used for optimizing the flood path. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-5-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_private.h | 2 ++ net/bridge/br_vlan.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index bda25f851342..b2a12b6298cb 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -210,6 +210,7 @@ enum { * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast * context * @msti: if MASTER flag set, this holds the VLANs MST instance + * @port_vlist: if MASTER flag set, this is the port-VLAN list * @vlist: sorted list of VLAN entries * @rcu: used for entry destruction * @@ -244,6 +245,7 @@ struct net_bridge_vlan { u16 msti; + struct list_head port_vlist; struct list_head vlist; struct rcu_head rcu; diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index bfedd13e3fd4..34d1df59d190 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -130,10 +130,12 @@ static void __vlan_add_list(struct net_bridge_vlan *v) struct list_head *headp, *hpos; struct net_bridge_vlan *vent; - if (br_vlan_is_master(v)) + if (br_vlan_is_master(v)) { vg = br_vlan_group(v->br); - else + } else { vg = nbp_vlan_group(v->port); + list_add_rcu(&v->port_vlist, &v->brvlan->port_vlist); + } headp = &vg->vlan_list; list_for_each_prev(hpos, headp) { @@ -147,6 +149,10 @@ static void __vlan_add_list(struct net_bridge_vlan *v) static void __vlan_del_list(struct net_bridge_vlan *v) { list_del_rcu(&v->vlist); + if (br_vlan_is_master(v)) + WARN_ON(!list_empty(&v->port_vlist)); + else + list_del_rcu(&v->port_vlist); } static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, @@ -335,6 +341,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, } br_multicast_ctx_init(br, v, &v->br_mcast_ctx); v->priv_flags |= BR_VLFLAG_GLOBAL_MCAST_ENABLED; + INIT_LIST_HEAD(&v->port_vlist); } /* Add the dev mac and count the vlan only if it's usable */ From d5219589e4cfb9954d97b1e9b928e5a72dbb82ea Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:46 +0300 Subject: [PATCH 0681/2126] net: bridge: consider only port-VLAN members when flooding Use the port-VLAN list that is in every master VLAN and consider only participating port-VLANs when flooding packets. This is the first optimization that greatly improves performance for sparse port VLANs e.g. 2 out of 32 ports participating in a single VLAN: before the bridge would consider all 32 ports and forward the packet only through the 2, now it will only consider the participating 2 ports. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-6-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_device.c | 8 ++++---- net/bridge/br_forward.c | 29 +++++++++++++++++++++-------- net/bridge/br_input.c | 2 +- net/bridge/br_private.h | 6 +++--- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index e01c44a90d84..ce9ea9ac3d0a 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -89,10 +89,10 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) dest = eth_hdr(skb)->h_dest; if (is_broadcast_ether_addr(dest)) { - br_flood(br, skb, BR_PKT_BROADCAST, false, true, vid); + br_flood(br, vlan, skb, BR_PKT_BROADCAST, false, true); } else if (is_multicast_ether_addr(dest)) { if (unlikely(netpoll_tx_running(dev))) { - br_flood(br, skb, BR_PKT_MULTICAST, false, true, vid); + br_flood(br, vlan, skb, BR_PKT_MULTICAST, false, true); goto out; } if (br_multicast_rcv(&brmctx, &pmctx_null, vlan, skb, vid)) { @@ -105,11 +105,11 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) br_multicast_querier_exists(brmctx, eth_hdr(skb), mdst)) br_multicast_flood(mdst, skb, brmctx, false, true); else - br_flood(br, skb, BR_PKT_MULTICAST, false, true, vid); + br_flood(br, vlan, skb, BR_PKT_MULTICAST, false, true); } else if ((dst = br_fdb_find_rcu(br, dest, vid)) != NULL) { br_forward(READ_ONCE(dst->dst), skb, false, true); } else { - br_flood(br, skb, BR_PKT_UNICAST, false, true, vid); + br_flood(br, vlan, skb, BR_PKT_UNICAST, false, true); } out: rcu_read_unlock(); diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index a696c6c128e3..251d61e7c312 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -262,19 +262,32 @@ static void br_flood_port(struct net_bridge_port **prev, } /* called under rcu_read_lock */ -void br_flood(struct net_bridge *br, struct sk_buff *skb, - enum br_pkt_type pkt_type, bool local_rcv, bool local_orig, - u16 vid) +void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, + struct sk_buff *skb, enum br_pkt_type pkt_type, + bool local_rcv, bool local_orig) { struct net_bridge_port *prev = NULL; - struct net_bridge_port *p; br_tc_skb_miss_set(skb, pkt_type != BR_PKT_BROADCAST); - list_for_each_entry_rcu(p, &br->port_list, list) { - br_flood_port(&prev, p, skb, pkt_type, local_orig, vid); - if (IS_ERR(prev)) - break; + if (v) { + struct net_bridge_vlan *masterv, *pv; + + masterv = br_vlan_is_master(v) ? v : v->brvlan; + list_for_each_entry_rcu(pv, &masterv->port_vlist, port_vlist) { + br_flood_port(&prev, pv->port, skb, pkt_type, + local_orig, v->vid); + if (IS_ERR(prev)) + break; + } + } else { + struct net_bridge_port *p; + + list_for_each_entry_rcu(p, &br->port_list, list) { + br_flood_port(&prev, p, skb, pkt_type, local_orig, 0); + if (IS_ERR(prev)) + break; + } } br_flood_finish(prev, skb, local_rcv, local_orig); diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 8bed72baf161..b20c7c182a80 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -226,7 +226,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb br_forward(READ_ONCE(dst->dst), skb, local_rcv, false); } else { if (!mcast_hit) - br_flood(br, skb, pkt_type, local_rcv, false, vid); + br_flood(br, vlan, skb, pkt_type, local_rcv, false); else br_multicast_flood(mdst, skb, brmctx, local_rcv, false); } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index b2a12b6298cb..239cf58d2268 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -912,9 +912,9 @@ int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, bool local_rcv, bool local_orig); int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); -void br_flood(struct net_bridge *br, struct sk_buff *skb, - enum br_pkt_type pkt_type, bool local_rcv, bool local_orig, - u16 vid); +void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, + struct sk_buff *skb, enum br_pkt_type pkt_type, + bool local_rcv, bool local_orig); /* return true if both source port and dest port are isolated */ static inline bool br_skb_isolated(const struct net_bridge_port *to, From 9c30ccaa7327f865128bc7977705003c0bf2f643 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:47 +0300 Subject: [PATCH 0682/2126] net: bridge: vlan: use an RCU array for large flood sets Walking the master VLAN's port-VLAN list avoids considering ports outside the VLAN but its pointer chasing becomes more expensive than array when many ports participate. Add an rcu array of port-VLAN pointers for larger flood sets. Rebuild and publish the array under RTNL when VLAN membership changes. Continue using the list for small flood sets and as a fallback if the array allocation fails. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-7-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_forward.c | 39 ++++++++++++++++++++++++++++++--------- net/bridge/br_private.h | 13 +++++++++++++ net/bridge/br_vlan.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 251d61e7c312..e8f30f2df1ed 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -261,6 +261,35 @@ static void br_flood_port(struct net_bridge_port **prev, *prev = maybe_deliver(*prev, p, skb, local_orig); } +static void br_flood_vlan(struct net_bridge_port **prev, + struct net_bridge_vlan *v, struct sk_buff *skb, + enum br_pkt_type pkt_type, bool local_orig) +{ + struct net_bridge_vlan_port_array *array; + struct net_bridge_vlan *masterv, *pv; + + masterv = br_vlan_is_master(v) ? v : v->brvlan; + array = rcu_dereference(masterv->port_array); + if (array) { + unsigned int i; + + for (i = 0; i < array->count; i++) { + pv = array->vlans[i]; + br_flood_port(prev, pv->port, skb, pkt_type, + local_orig, v->vid); + if (IS_ERR(*prev)) + break; + } + } else { + list_for_each_entry_rcu(pv, &masterv->port_vlist, port_vlist) { + br_flood_port(prev, pv->port, skb, pkt_type, + local_orig, v->vid); + if (IS_ERR(*prev)) + break; + } + } +} + /* called under rcu_read_lock */ void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, struct sk_buff *skb, enum br_pkt_type pkt_type, @@ -271,15 +300,7 @@ void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, br_tc_skb_miss_set(skb, pkt_type != BR_PKT_BROADCAST); if (v) { - struct net_bridge_vlan *masterv, *pv; - - masterv = br_vlan_is_master(v) ? v : v->brvlan; - list_for_each_entry_rcu(pv, &masterv->port_vlist, port_vlist) { - br_flood_port(&prev, pv->port, skb, pkt_type, - local_orig, v->vid); - if (IS_ERR(prev)) - break; - } + br_flood_vlan(&prev, v, skb, pkt_type, local_orig); } else { struct net_bridge_port *p; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 239cf58d2268..a33da6e9765f 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -190,6 +190,17 @@ enum { BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED = BIT(6), }; +/* start publishing arrays when there're > BR_VLAN_PORT_ARRAY_THRESHOLD + * port-VLANs + */ +#define BR_VLAN_PORT_ARRAY_THRESHOLD 8 + +struct net_bridge_vlan_port_array { + struct rcu_head rcu; + unsigned int count; + struct net_bridge_vlan *vlans[]; +}; + /** * struct net_bridge_vlan - per-vlan entry * @@ -210,6 +221,7 @@ enum { * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast * context * @msti: if MASTER flag set, this holds the VLANs MST instance + * @port_array: if MASTER flag set, this is the port-VLAN array * @port_vlist: if MASTER flag set, this is the port-VLAN list * @vlist: sorted list of VLAN entries * @rcu: used for entry destruction @@ -245,6 +257,7 @@ struct net_bridge_vlan { u16 msti; + struct net_bridge_vlan_port_array __rcu *port_array; struct list_head port_vlist; struct list_head vlist; diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 34d1df59d190..d750581df64d 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -258,6 +258,36 @@ static void br_vlan_init_state(struct net_bridge_vlan *v) v->msti = 0; } +static unsigned int br_vlan_num_ports(const struct net_bridge_vlan *masterv) +{ + return refcount_read(&masterv->refcnt) - br_vlan_is_brentry(masterv); +} + +static void br_vlan_rebuild_port_array(struct net_bridge_vlan *masterv, + unsigned int count) +{ + struct net_bridge_vlan_port_array *array = NULL, *old; + unsigned int i = 0; + + WARN_ON(!br_vlan_is_master(masterv)); + + if (count > BR_VLAN_PORT_ARRAY_THRESHOLD) + array = kvmalloc(struct_size(array, vlans, count), GFP_KERNEL); + + if (array) { + struct net_bridge_vlan *pv; + + array->count = count; + list_for_each_entry(pv, &masterv->port_vlist, port_vlist) + array->vlans[i++] = pv; + } + + old = rtnl_dereference(masterv->port_array); + rcu_assign_pointer(masterv->port_array, array); + if (old) + kvfree_rcu(old, rcu); +} + /* This is the shared VLAN add function which works for both ports and bridge * devices. There are four possible calls to this function in terms of the * vlan entry type: @@ -368,8 +398,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, __vlan_flags_commit(v, flags); br_multicast_toggle_one_vlan(v, true); - if (p) + if (p) { + br_vlan_rebuild_port_array(masterv, br_vlan_num_ports(masterv)); nbp_vlan_set_vlan_dev_state(p, v->vid); + } out: return err; @@ -438,6 +470,9 @@ static void __vlan_del(struct net_bridge_vlan *v) rhashtable_remove_fast(&vg->vlan_hash, &v->vnode, br_vlan_rht_params); __vlan_del_list(v); + /* -1 because br_vlan_put_master() is called later */ + br_vlan_rebuild_port_array(masterv, + br_vlan_num_ports(masterv) - 1); nbp_vlan_set_vlan_dev_state(p, v->vid); br_multicast_toggle_one_vlan(v, false); br_multicast_port_ctx_deinit(&v->port_mcast_ctx); From 911afcbaa7cd6353e9e434a8167f2ff57cfba7c5 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:48 +0300 Subject: [PATCH 0683/2126] net: bridge: introduce a forwarding destination structure Introduce struct br_fwd_dst to keep an egress port together with its corresponding VLAN while passing it through the forwarding helpers. This allows paths which already resolved the port VLAN to preserve that information for later egress processing. maybe_deliver() now returns the clone error directly and we pass it separately to br_flood_finish() avoiding the error-pointer encoding and decoding which overloaded the previous port pointer. No functional changes intended. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-8-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_forward.c | 146 +++++++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 56 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index e8f30f2df1ed..845193baf992 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -7,7 +7,6 @@ * Lennert Buytenhek */ -#include #include #include #include @@ -17,10 +16,16 @@ #include #include "br_private.h" +struct br_fwd_dst { + const struct net_bridge_port *port; + struct net_bridge_vlan *vlan; +}; + /* Don't forward packets to originating port or forwarding disabled */ -static inline int should_deliver(const struct net_bridge_port *p, +static inline int should_deliver(const struct br_fwd_dst *fwd, const struct sk_buff *skb) { + const struct net_bridge_port *p = fwd->port; struct net_bridge_vlan_group *vg; vg = nbp_vlan_group_rcu(p); @@ -70,9 +75,10 @@ int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb) } EXPORT_SYMBOL_GPL(br_forward_finish); -static void __br_forward(const struct net_bridge_port *to, +static void __br_forward(const struct br_fwd_dst *fwd, struct sk_buff *skb, bool local_orig) { + const struct net_bridge_port *to = fwd->port; struct net_bridge_vlan_group *vg; struct net_device *indev; struct net *net; @@ -117,7 +123,7 @@ static void __br_forward(const struct net_bridge_port *to, br_forward_finish); } -static int deliver_clone(const struct net_bridge_port *prev, +static int deliver_clone(const struct br_fwd_dst *fwd, struct sk_buff *skb, bool local_orig) { struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev; @@ -128,7 +134,7 @@ static int deliver_clone(const struct net_bridge_port *prev, return -ENOMEM; } - __br_forward(prev, skb, local_orig); + __br_forward(fwd, skb, local_orig); return 0; } @@ -144,6 +150,8 @@ static int deliver_clone(const struct net_bridge_port *prev, void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, bool local_rcv, bool local_orig) { + struct br_fwd_dst fwd; + if (unlikely(!to)) goto out; @@ -159,11 +167,13 @@ void br_forward(const struct net_bridge_port *to, to = backup_port; } - if (should_deliver(to, skb)) { + fwd.port = to; + fwd.vlan = NULL; + if (should_deliver(&fwd, skb)) { if (local_rcv) - deliver_clone(to, skb, local_orig); + deliver_clone(&fwd, skb, local_orig); else - __br_forward(to, skb, local_orig); + __br_forward(&fwd, skb, local_orig); return; } @@ -173,40 +183,41 @@ out: } EXPORT_SYMBOL_GPL(br_forward); -static struct net_bridge_port *maybe_deliver( - struct net_bridge_port *prev, struct net_bridge_port *p, - struct sk_buff *skb, bool local_orig) +static int maybe_deliver(struct br_fwd_dst *prev, const struct br_fwd_dst *fwd, + struct sk_buff *skb, bool local_orig) { + const struct net_bridge_port *p = fwd->port; u8 igmp_type = br_multicast_igmp_type(skb); int err; - if (!should_deliver(p, skb)) - return prev; + if (!should_deliver(fwd, skb)) + return 0; nbp_switchdev_frame_mark_tx_fwd_to_hwdom(p, skb); - if (!prev) + if (!prev->port) goto out; err = deliver_clone(prev, skb, local_orig); if (err) - return ERR_PTR(err); + return err; out: br_multicast_count(p->br, p, skb, igmp_type, BR_MCAST_DIR_TX); + *prev = *fwd; - return p; + return 0; } -static void br_flood_finish(struct net_bridge_port *prev, struct sk_buff *skb, +static void br_flood_finish(const struct br_fwd_dst *fwd, int err, + struct sk_buff *skb, bool local_rcv, bool local_orig) { enum skb_drop_reason reason = SKB_DROP_REASON_NO_TX_TARGET; - if (IS_ERR_OR_NULL(prev)) { - if (IS_ERR(prev)) { - reason = PTR_ERR(prev) == -ENOMEM ? SKB_DROP_REASON_NOMEM : - SKB_DROP_REASON_NOT_SPECIFIED; - } + if (err || !fwd->port) { + if (err) + reason = err == -ENOMEM ? SKB_DROP_REASON_NOMEM : + SKB_DROP_REASON_NOT_SPECIFIED; if (!local_rcv) kfree_skb_reason(skb, reason); @@ -214,59 +225,64 @@ static void br_flood_finish(struct net_bridge_port *prev, struct sk_buff *skb, } if (local_rcv) - deliver_clone(prev, skb, local_orig); + deliver_clone(fwd, skb, local_orig); else - __br_forward(prev, skb, local_orig); + __br_forward(fwd, skb, local_orig); } -static void br_flood_port(struct net_bridge_port **prev, - struct net_bridge_port *p, struct sk_buff *skb, - enum br_pkt_type pkt_type, bool local_orig, u16 vid) +static int br_flood_port(struct br_fwd_dst *prev, + const struct br_fwd_dst *fwd, struct sk_buff *skb, + enum br_pkt_type pkt_type, bool local_orig) { + const struct net_bridge_port *p = fwd->port; + u16 vid = fwd->vlan ? fwd->vlan->vid : 0; + /* Do not flood unicast traffic to ports that turn it off, nor * other traffic if flood off, except for traffic we originate */ switch (pkt_type) { case BR_PKT_UNICAST: if (!test_bit(BR_FLOOD_BIT, &p->flags)) - return; + return 0; break; case BR_PKT_MULTICAST: if (!test_bit(BR_MCAST_FLOOD_BIT, &p->flags) && skb->dev != p->br->dev) - return; + return 0; break; case BR_PKT_BROADCAST: if (!test_bit(BR_BCAST_FLOOD_BIT, &p->flags) && skb->dev != p->br->dev) - return; + return 0; break; } /* Do not flood to ports that enable proxy ARP */ if (test_bit(BR_PROXYARP_BIT, &p->flags)) - return; + return 0; if (BR_INPUT_SKB_CB(skb)->proxyarp_replied) { if (test_bit(BR_PROXYARP_WIFI_BIT, &p->flags)) - return; + return 0; /* For gratuitous ARPs/NAs, check neigh_forward_grat. * For regular ARPs/NDs, check only neigh_suppress. */ if (br_is_neigh_suppress_enabled(p, vid) && (!BR_INPUT_SKB_CB(skb)->grat_arp || !br_is_neigh_forward_grat_enabled(p, vid))) - return; + return 0; } - *prev = maybe_deliver(*prev, p, skb, local_orig); + return maybe_deliver(prev, fwd, skb, local_orig); } -static void br_flood_vlan(struct net_bridge_port **prev, - struct net_bridge_vlan *v, struct sk_buff *skb, - enum br_pkt_type pkt_type, bool local_orig) +static int br_flood_vlan(struct br_fwd_dst *prev, + struct net_bridge_vlan *v, struct sk_buff *skb, + enum br_pkt_type pkt_type, bool local_orig) { struct net_bridge_vlan_port_array *array; struct net_bridge_vlan *masterv, *pv; + struct br_fwd_dst dst; + int err; masterv = br_vlan_is_master(v) ? v : v->brvlan; array = rcu_dereference(masterv->port_array); @@ -275,19 +291,25 @@ static void br_flood_vlan(struct net_bridge_port **prev, for (i = 0; i < array->count; i++) { pv = array->vlans[i]; - br_flood_port(prev, pv->port, skb, pkt_type, - local_orig, v->vid); - if (IS_ERR(*prev)) - break; + dst.port = pv->port; + dst.vlan = pv; + err = br_flood_port(prev, &dst, skb, pkt_type, + local_orig); + if (err) + return err; } } else { list_for_each_entry_rcu(pv, &masterv->port_vlist, port_vlist) { - br_flood_port(prev, pv->port, skb, pkt_type, - local_orig, v->vid); - if (IS_ERR(*prev)) - break; + dst.port = pv->port; + dst.vlan = pv; + err = br_flood_port(prev, &dst, skb, pkt_type, + local_orig); + if (err) + return err; } } + + return 0; } /* called under rcu_read_lock */ @@ -295,23 +317,29 @@ void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, struct sk_buff *skb, enum br_pkt_type pkt_type, bool local_rcv, bool local_orig) { - struct net_bridge_port *prev = NULL; + struct br_fwd_dst prev = {}; + int err = 0; br_tc_skb_miss_set(skb, pkt_type != BR_PKT_BROADCAST); if (v) { - br_flood_vlan(&prev, v, skb, pkt_type, local_orig); + err = br_flood_vlan(&prev, v, skb, pkt_type, local_orig); } else { struct net_bridge_port *p; list_for_each_entry_rcu(p, &br->port_list, list) { - br_flood_port(&prev, p, skb, pkt_type, local_orig, 0); - if (IS_ERR(prev)) + struct br_fwd_dst fwd = { + .port = p, + }; + + err = br_flood_port(&prev, &fwd, skb, pkt_type, + local_orig); + if (err) break; } } - br_flood_finish(prev, skb, local_rcv, local_orig); + br_flood_finish(&prev, err, skb, local_rcv, local_orig); } #ifdef CONFIG_BRIDGE_IGMP_SNOOPING @@ -320,9 +348,12 @@ static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb, { struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev; const unsigned char *src = eth_hdr(skb)->h_source; + struct br_fwd_dst fwd = { + .port = p, + }; struct sk_buff *nskb; - if (!should_deliver(p, skb)) + if (!should_deliver(&fwd, skb)) return; /* Even with hairpin, no soliloquies - prevent breaking IPv6 DAD */ @@ -342,7 +373,7 @@ static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb, if (!is_broadcast_ether_addr(addr)) memcpy(eth_hdr(skb)->h_dest, addr, ETH_ALEN); - __br_forward(p, skb, local_orig); + __br_forward(&fwd, skb, local_orig); } /* called with rcu_read_lock */ @@ -351,10 +382,11 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct net_bridge_mcast *brmctx, bool local_rcv, bool local_orig) { - struct net_bridge_port *prev = NULL; struct net_bridge_port_group *p; bool allow_mode_include = true; + struct br_fwd_dst prev = {}; struct hlist_node *rp; + int err = 0; rp = br_multicast_get_first_rport_node(brmctx, skb); @@ -370,6 +402,7 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, while (p || rp) { struct net_bridge_port *port, *lport, *rport; + struct br_fwd_dst fwd = {}; lport = p ? p->key.port : NULL; rport = br_multicast_rport_from_node_skb(rp, skb); @@ -391,8 +424,9 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, port = rport; } - prev = maybe_deliver(prev, port, skb, local_orig); - if (IS_ERR(prev)) + fwd.port = port; + err = maybe_deliver(&prev, &fwd, skb, local_orig); + if (err) break; delivered: @@ -402,6 +436,6 @@ delivered: rp = rcu_dereference(hlist_next_rcu(rp)); } - br_flood_finish(prev, skb, local_rcv, local_orig); + br_flood_finish(&prev, err, skb, local_rcv, local_orig); } #endif From 4e0c8f54f605f68af7ff470c23c834e4f45d737d Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:49 +0300 Subject: [PATCH 0684/2126] net: bridge: avoid egress VLAN lookups when flooding VLAN flooding already provides the exact port-VLAN entry associated with each destination port. Use that entry directly for the egress state check and VLAN handling instead of resolving it again from the packet VLAN ID. Keep the existing lookup path for forwarding destinations which do not provide a port-VLAN entry. This removes two VLAN hash lookups for every flooded egress port. Use __always_inline for should_deliver as it provides a measurable 3% additional gain, should_deliver wasn't inlined even though it had the inline specifier, the bridge module size increases by 173 bytes. The series were tested in a two CPU VM with packet generation and bridge forwarding on separate pinned CPUs. The results are medians of seven runs with 300000 64b tagged broadcast packets. Mpps br_flood TSC cycles/input VIDs Ports before after gain before after reduction 1 8/2 1.209298 1.636580 35.3% 1444 845 41.5% 1 8/4 0.843175 0.986541 17.0% 3036 2527 16.8% 1 8/8 0.508857 0.559844 10.0% 5999 5465 8.9% 1 32/2 0.893896 1.586532 77.5% 3013 841 72.1% 1 32/16 0.250567 0.282339 12.7% 13670 11137 18.5% 1 32/32 0.135351 0.148461 9.7% 25429 22320 12.2% 1 64/2 0.555010 1.603776 189.0% 5001 837 83.3% 1 64/32 0.123831 0.149639 20.8% 27674 22602 18.3% 1 64/64 0.069122 0.076047 10.0% 51508 45138 12.4% 64 8/2 1.044185 1.500468 43.7% 1528 851 44.3% 64 8/4 0.802680 0.977700 21.8% 3178 2546 19.9% 64 8/8 0.479748 0.555419 15.8% 6283 5635 10.3% 64 32/2 0.861074 1.561266 81.3% 3063 849 72.3% 64 32/16 0.234011 0.280027 19.7% 14332 11165 22.1% 64 32/32 0.126145 0.148085 17.4% 27225 22613 16.9% 64 64/2 0.530587 1.496179 182.0% 4377 826 81.1% 64 64/32 0.121105 0.147943 22.2% 29286 22541 23.0% 64 64/64 0.063626 0.077051 21.1% 56147 45520 18.9% 1024 8/2 1.008693 1.358408 34.7% 1538 879 42.8% 1024 8/4 0.785636 0.943545 20.1% 3280 2704 17.6% 1024 8/8 0.448194 0.521765 16.4% 6678 6011 10.0% 1024 32/2 0.840864 1.417311 68.6% 2756 859 68.8% 1024 32/16 0.195786 0.247129 26.2% 16269 12639 22.3% 1024 32/32 0.097978 0.122742 25.3% 35249 29273 17.0% 1024 64/2 0.536947 1.400985 160.9% 4421 849 80.8% 1024 64/32 0.093962 0.123383 31.3% 37425 29197 22.0% 1024 64/64 0.045147 0.057867 28.2% 72626 59198 18.5% Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-9-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_forward.c | 23 ++++++++++++++++------- net/bridge/br_input.c | 2 +- net/bridge/br_private.h | 7 +++++++ net/bridge/br_vlan.c | 31 +++++++++++++++++-------------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 845193baf992..d89f1b7d6def 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -21,17 +21,26 @@ struct br_fwd_dst { struct net_bridge_vlan *vlan; }; +static bool should_deliver_vlan(const struct br_fwd_dst *fwd, + const struct sk_buff *skb) +{ + if (fwd->vlan) + return br_vlan_state_allowed(br_vlan_get_state(fwd->vlan), + false); + + return br_allowed_egress(nbp_vlan_group_rcu(fwd->port), skb); +} + /* Don't forward packets to originating port or forwarding disabled */ -static inline int should_deliver(const struct br_fwd_dst *fwd, - const struct sk_buff *skb) +static __always_inline bool should_deliver(const struct br_fwd_dst *fwd, + const struct sk_buff *skb) { const struct net_bridge_port *p = fwd->port; - struct net_bridge_vlan_group *vg; - vg = nbp_vlan_group_rcu(p); return (test_bit(BR_HAIRPIN_MODE_BIT, &p->flags) || skb->dev != p->dev) && (br_mst_is_enabled(p) || p->state == BR_STATE_FORWARDING) && - br_allowed_egress(vg, skb) && nbp_switchdev_allowed_egress(p, skb) && + should_deliver_vlan(fwd, skb) && + nbp_switchdev_allowed_egress(p, skb) && !br_skb_isolated(p, skb); } @@ -89,8 +98,8 @@ static void __br_forward(const struct br_fwd_dst *fwd, */ nbp_switchdev_frame_mark_tx_fwd_offload(to, skb); - vg = nbp_vlan_group_rcu(to); - skb = br_handle_vlan(to->br, to, vg, skb); + vg = fwd->vlan ? NULL : nbp_vlan_group_rcu(to); + skb = br_handle_vlan(to->br, to, vg, fwd->vlan, skb); if (!skb) return; diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index b20c7c182a80..4357d78524a6 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -58,7 +58,7 @@ static int br_pass_frame_up(struct sk_buff *skb, bool promisc) indev = skb->dev; skb->dev = brdev; - skb = br_handle_vlan(br, NULL, vg, skb); + skb = br_handle_vlan(br, NULL, vg, NULL, skb); if (!skb) return NET_RX_DROP; /* update the multicast stats if the packet is IGMP/MLD */ diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index a33da6e9765f..7c0b1d3e7931 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1606,6 +1606,7 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); struct sk_buff *br_handle_vlan(struct net_bridge *br, const struct net_bridge_port *port, struct net_bridge_vlan_group *vg, + struct net_bridge_vlan *vlan, struct sk_buff *skb); int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, bool *changed, struct netlink_ext_ack *extack); @@ -1743,6 +1744,7 @@ static inline bool br_should_learn(struct net_bridge_port *p, static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, const struct net_bridge_port *port, struct net_bridge_vlan_group *vg, + struct net_bridge_vlan *vlan, struct sk_buff *skb) { return skb; @@ -1953,6 +1955,11 @@ static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) return false; } } +#else +static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) +{ + return false; +} #endif /* br_mst.c */ diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index d750581df64d..ce5aa15c4540 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -520,10 +520,10 @@ static void __vlan_flush(const struct net_bridge *br, struct sk_buff *br_handle_vlan(struct net_bridge *br, const struct net_bridge_port *p, struct net_bridge_vlan_group *vg, + struct net_bridge_vlan *v, struct sk_buff *skb) { struct pcpu_sw_netstats *stats; - struct net_bridge_vlan *v; u16 vid; /* If this packet was not filtered at input, let it pass */ @@ -534,19 +534,22 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br, * a valid vlan id. If the vlan id has untagged flag set, * send untagged; otherwise, send tagged. */ - br_vlan_get_tag(skb, &vid); - v = br_vlan_find(vg, vid); - /* Vlan entry must be configured at this point. The - * only exception is the bridge is set in promisc mode and the - * packet is destined for the bridge device. In this case - * pass the packet as is. - */ - if (!v || !br_vlan_should_use(v)) { - if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) { - goto out; - } else { - kfree_skb(skb); - return NULL; + if (!v) { + br_vlan_get_tag(skb, &vid); + v = br_vlan_find(vg, vid); + /* Vlan entry must be configured at this point. The + * only exception is the bridge is set in promisc mode and the + * packet is destined for the bridge device. In this case + * pass the packet as is. + */ + if (!v || !br_vlan_should_use(v)) { + if ((br->dev->flags & IFF_PROMISC) && + skb->dev == br->dev) { + goto out; + } else { + kfree_skb(skb); + return NULL; + } } } if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) { From fee4e7663e5cdc19bfe1d26f0651f2f9e04922d7 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 18 Sep 2026 18:29:50 +0300 Subject: [PATCH 0685/2126] net: bridge: avoid VLAN lookups for flood neighbour suppression We can remove more unnecessary VLAN lookups if we pass the port-VLAN entry to the neighbour suppression helpers so they can use it directly instead of resolving it again. Use a vid wrapper for callers which don't have the port-VLAN entry. This removes up to two additional VLAN hash lookups per flooded egress port for packets marked as proxy replied. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260918152950.1938259-10-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_arp_nd_proxy.c | 51 ++++++++++++++++++++---------------- net/bridge/br_forward.c | 5 ++-- net/bridge/br_private.h | 6 +++-- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index 9ce8f440e38f..da15f4d7c1ae 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -40,6 +40,23 @@ void br_recalculate_neigh_suppress_enabled(struct net_bridge *br) } #if IS_ENABLED(CONFIG_INET) +static bool +br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid) +{ + const struct net_bridge_vlan *v = NULL; + + if (p && vid && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) { + struct net_bridge_vlan_group *vg; + + vg = nbp_vlan_group_rcu(p); + v = br_vlan_find(vg, vid); + if (!v) + return false; + } + + return br_is_neigh_suppress_enabled(p, v); +} + static void br_arp_send(struct net_bridge *br, struct net_bridge_port *p, struct net_device *dev, __be32 dest_ip, __be32 src_ip, const unsigned char *dest_hw, @@ -159,7 +176,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, return; if (br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) { - if (br_is_neigh_suppress_enabled(p, vid)) + if (br_is_neigh_suppress_enabled_vid(p, vid)) return; if (is_unicast_ether_addr(eth_hdr(skb)->h_dest) && parp->ar_op == htons(ARPOP_REQUEST)) @@ -211,7 +228,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, if ((p && test_bit(BR_PROXYARP_BIT, &p->flags)) || (dst && test_bit(BR_PROXYARP_WIFI_BIT, &dst->flags)) || - br_is_neigh_suppress_enabled(dst, vid)) { + br_is_neigh_suppress_enabled_vid(dst, vid)) { if (!vid) br_arp_send(br, p, skb->dev, sip, tip, sha, ha, sha, 0, 0); @@ -424,7 +441,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, BR_INPUT_SKB_CB(skb)->proxyarp_replied = 0; BR_INPUT_SKB_CB(skb)->grat_arp = 0; - if (br_is_neigh_suppress_enabled(p, vid)) + if (br_is_neigh_suppress_enabled_vid(p, vid)) return; if (is_unicast_ether_addr(eth_hdr(skb)->h_dest) && @@ -486,7 +503,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, const struct net_bridge_port *dst = READ_ONCE(f->dst); bool replied = false; - if (br_is_neigh_suppress_enabled(dst, vid)) { + if (br_is_neigh_suppress_enabled_vid(dst, vid)) { if (vid != 0) br_nd_send(br, p, skb, n, ha, skb->vlan_proto, @@ -509,35 +526,25 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, } #endif -bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, u16 vid) +bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v) { if (!p) return false; - if (vid && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) { - struct net_bridge_vlan_group *vg = nbp_vlan_group_rcu(p); - struct net_bridge_vlan *v; - - v = br_vlan_find(vg, vid); - if (!v) - return false; + if (v && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) return !!(READ_ONCE(v->priv_flags) & BR_VLFLAG_NEIGH_SUPPRESS_ENABLED); - } + return test_bit(BR_NEIGH_SUPPRESS_BIT, &p->flags); } -bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, u16 vid) +bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v) { - if (vid && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) { - struct net_bridge_vlan_group *vg = nbp_vlan_group_rcu(p); - struct net_bridge_vlan *v; - - v = br_vlan_find(vg, vid); - if (!v) - return false; + if (v && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) return !!(READ_ONCE(v->priv_flags) & BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED); - } + return test_bit(BR_NEIGH_FORWARD_GRAT_BIT, &p->flags); } diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index d89f1b7d6def..b5eece1ff9e8 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -244,7 +244,6 @@ static int br_flood_port(struct br_fwd_dst *prev, enum br_pkt_type pkt_type, bool local_orig) { const struct net_bridge_port *p = fwd->port; - u16 vid = fwd->vlan ? fwd->vlan->vid : 0; /* Do not flood unicast traffic to ports that turn it off, nor * other traffic if flood off, except for traffic we originate @@ -275,9 +274,9 @@ static int br_flood_port(struct br_fwd_dst *prev, /* For gratuitous ARPs/NAs, check neigh_forward_grat. * For regular ARPs/NDs, check only neigh_suppress. */ - if (br_is_neigh_suppress_enabled(p, vid) && + if (br_is_neigh_suppress_enabled(p, fwd->vlan) && (!BR_INPUT_SKB_CB(skb)->grat_arp || - !br_is_neigh_forward_grat_enabled(p, vid))) + !br_is_neigh_forward_grat_enabled(p, fwd->vlan))) return 0; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 7c0b1d3e7931..67117fb3dc88 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -2390,6 +2390,8 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, u16 vid, struct net_bridge_port *p, struct nd_msg *msg); struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb); -bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, u16 vid); -bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, u16 vid); +bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v); +bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v); #endif From c7a2a8c0c9ef480849d655273101dcd0c5067e6a Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 21 Sep 2026 09:39:47 +0000 Subject: [PATCH 0686/2126] netlink: remove dev_hold() and dev_put() in __netlink_deliver_tap_skb() __netlink_deliver_tap_skb() is called from netlink_deliver_tap() under rcu_read_lock(). dev_queue_xmit() does not require the caller to hold a device reference count, and the device lifetime is already protected by RCU (the netlink tap is unlinked and waited for via grace periods prior to device destruction). Remove the redundant dev_hold(dev) and dev_put(dev) calls. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260921093947.477658-1-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/netlink/af_netlink.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 1e594baf7adf..6d2530e33540 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -293,8 +293,6 @@ static int __netlink_deliver_tap_skb(struct sk_buff *skb, if (!net_eq(dev_net(dev), sock_net(sk))) return 0; - dev_hold(dev); - if (is_vmalloc_addr(skb->head)) nskb = netlink_to_full_skb(skb, GFP_ATOMIC); else @@ -310,7 +308,6 @@ static int __netlink_deliver_tap_skb(struct sk_buff *skb, ret = net_xmit_errno(ret); } - dev_put(dev); return ret; } From f09db8b83e836f9554ec8e0f985c70699b3cb83f Mon Sep 17 00:00:00 2001 From: Victor Nogueira Date: Sat, 19 Sep 2026 20:04:27 -0300 Subject: [PATCH 0687/2126] net/sched: act_mirred: account for TCA_MIRRED_BLOCKID in get_fill_size tcf_mirred_get_fill_size budgets only TCA_MIRRED_PARMS, but tcf_mirred_dump also emits TCA_MIRRED_BLOCKID whenever the action was created with a block instead of a device, so the budget falls 8 bytes short of what the dump may produce for such actions. Account for TCA_MIRRED_BLOCKID unconditionally: reading tcfm_blockid to size it conditionally would race a concurrent replace, which can flip the action between device and block between sizing and dumping. Reported-by: Sashiko Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824153903.4143642-1-victor@mojatatu.com Co-developed-by: Jamal Hadi Salim Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Link: https://patch.msgid.link/QDISC-RYTB.v1.20260918093205@mojatatu.com.1 Reviewed-by: Simon Horman Signed-off-by: Paolo Abeni --- net/sched/act_mirred.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c index 553342c55cf7..1c98e4d81ebe 100644 --- a/net/sched/act_mirred.c +++ b/net/sched/act_mirred.c @@ -607,7 +607,8 @@ tcf_mirred_get_dev(const struct tc_action *a, static size_t tcf_mirred_get_fill_size(const struct tc_action *act) { - return nla_total_size(sizeof(struct tc_mirred)); + return nla_total_size(sizeof(struct tc_mirred)) /* TCA_MIRRED_PARMS */ + + nla_total_size(sizeof(u32)); /* TCA_MIRRED_BLOCKID */ } static void tcf_offload_mirred_get_dev(struct flow_action_entry *entry, From 4ba61bfd4998074322cf2f34e6338151a1456ef6 Mon Sep 17 00:00:00 2001 From: Victor Nogueira Date: Sat, 19 Sep 2026 20:04:28 -0300 Subject: [PATCH 0688/2126] net/sched: add get_fill_size() to the five actions that lack one act_simple, act_mpls, act_nat, act_skbmod and act_connmark each have a tcf_*_dump but no .get_fill_size callback, so tcf_action_fill_size budgets only the shared attributes and omits the per-action TCA_*_PARMS and option bytes the dump emits. Add a callback to each, sized from the attributes its dump emits. Size every optional attribute unconditionally: reading the current flags to size it conditionally would race a concurrent replace, which can flip the attributes between sizing and dumping. Reported-by: Sashiko Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824153903.4143642-1-victor@mojatatu.com Co-developed-by: Jamal Hadi Salim Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Link: https://patch.msgid.link/QDISC-RYTB.v1.20260918093205@mojatatu.com.2 Reviewed-by: Simon Horman Signed-off-by: Paolo Abeni --- net/sched/act_connmark.c | 6 ++++++ net/sched/act_mpls.c | 11 +++++++++++ net/sched/act_nat.c | 6 ++++++ net/sched/act_simple.c | 7 +++++++ net/sched/act_skbmod.c | 9 +++++++++ 5 files changed, 39 insertions(+) diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c index c634af5edfcd..0b6ac6be60d2 100644 --- a/net/sched/act_connmark.c +++ b/net/sched/act_connmark.c @@ -236,12 +236,18 @@ static void tcf_connmark_cleanup(struct tc_action *a) kfree_rcu(parms, rcu); } +static size_t tcf_connmark_get_fill_size(const struct tc_action *act) +{ + return nla_total_size(sizeof(struct tc_connmark)); /* TCA_CONNMARK_PARMS */ +} + static struct tc_action_ops act_connmark_ops = { .kind = "connmark", .id = TCA_ID_CONNMARK, .owner = THIS_MODULE, .act = tcf_connmark_act, .dump = tcf_connmark_dump, + .get_fill_size = tcf_connmark_get_fill_size, .init = tcf_connmark_init, .cleanup = tcf_connmark_cleanup, .size = sizeof(struct tcf_connmark_info), diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c index 4ea8b2e08c3a..aa56521b7179 100644 --- a/net/sched/act_mpls.c +++ b/net/sched/act_mpls.c @@ -438,12 +438,23 @@ static int tcf_mpls_offload_act_setup(struct tc_action *act, void *entry_data, return 0; } +static size_t tcf_mpls_get_fill_size(const struct tc_action *act) +{ + return nla_total_size(sizeof(struct tc_mpls)) /* TCA_MPLS_PARMS */ + + nla_total_size(sizeof(u32)) /* TCA_MPLS_LABEL */ + + nla_total_size(sizeof(u8)) /* TCA_MPLS_TC */ + + nla_total_size(sizeof(u8)) /* TCA_MPLS_TTL */ + + nla_total_size(sizeof(u8)) /* TCA_MPLS_BOS */ + + nla_total_size(sizeof(u16)); /* TCA_MPLS_PROTO */ +} + static struct tc_action_ops act_mpls_ops = { .kind = "mpls", .id = TCA_ID_MPLS, .owner = THIS_MODULE, .act = tcf_mpls_act, .dump = tcf_mpls_dump, + .get_fill_size = tcf_mpls_get_fill_size, .init = tcf_mpls_init, .cleanup = tcf_mpls_cleanup, .offload_act_setup = tcf_mpls_offload_act_setup, diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c index abb332dee836..a201979ac7cf 100644 --- a/net/sched/act_nat.c +++ b/net/sched/act_nat.c @@ -313,12 +313,18 @@ static void tcf_nat_cleanup(struct tc_action *a) kfree_rcu(parms, rcu); } +static size_t tcf_nat_get_fill_size(const struct tc_action *act) +{ + return nla_total_size(sizeof(struct tc_nat)); /* TCA_NAT_PARMS */ +} + static struct tc_action_ops act_nat_ops = { .kind = "nat", .id = TCA_ID_NAT, .owner = THIS_MODULE, .act = tcf_nat_act, .dump = tcf_nat_dump, + .get_fill_size = tcf_nat_get_fill_size, .init = tcf_nat_init, .cleanup = tcf_nat_cleanup, .size = sizeof(struct tcf_nat), diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c index 8e69a919b4fe..80e5084b4dbd 100644 --- a/net/sched/act_simple.c +++ b/net/sched/act_simple.c @@ -79,6 +79,12 @@ static int reset_policy(struct tc_action *a, const struct nlattr *defdata, return 0; } +static size_t tcf_simp_get_fill_size(const struct tc_action *act) +{ + return nla_total_size(sizeof(struct tc_defact)) /* TCA_DEF_PARMS */ + + nla_total_size(SIMP_MAX_DATA); /* TCA_DEF_DATA */ +} + static const struct nla_policy simple_policy[TCA_DEF_MAX + 1] = { [TCA_DEF_PARMS] = { .len = sizeof(struct tc_defact) }, [TCA_DEF_DATA] = { .type = NLA_STRING, .len = SIMP_MAX_DATA }, @@ -204,6 +210,7 @@ static struct tc_action_ops act_simp_ops = { .owner = THIS_MODULE, .act = tcf_simp_act, .dump = tcf_simp_dump, + .get_fill_size = tcf_simp_get_fill_size, .cleanup = tcf_simp_release, .init = tcf_simp_init, .size = sizeof(struct tcf_defact), diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c index 7579cf1e0ff3..09e9dcf58253 100644 --- a/net/sched/act_skbmod.c +++ b/net/sched/act_skbmod.c @@ -279,12 +279,21 @@ nla_put_failure: return -1; } +static size_t tcf_skbmod_get_fill_size(const struct tc_action *act) +{ + return nla_total_size(sizeof(struct tc_skbmod)) /* TCA_SKBMOD_PARMS */ + + nla_total_size(ETH_ALEN) /* TCA_SKBMOD_DMAC */ + + nla_total_size(ETH_ALEN) /* TCA_SKBMOD_SMAC */ + + nla_total_size(sizeof(u16)); /* TCA_SKBMOD_ETYPE */ +} + static struct tc_action_ops act_skbmod_ops = { .kind = "skbmod", .id = TCA_ACT_SKBMOD, .owner = THIS_MODULE, .act = tcf_skbmod_act, .dump = tcf_skbmod_dump, + .get_fill_size = tcf_skbmod_get_fill_size, .init = tcf_skbmod_init, .cleanup = tcf_skbmod_cleanup, .size = sizeof(struct tcf_skbmod), From 54f5a4edf60966a7f7c13cf6ef8a036e95b25007 Mon Sep 17 00:00:00 2001 From: Victor Nogueira Date: Sat, 19 Sep 2026 20:04:29 -0300 Subject: [PATCH 0689/2126] net/sched: act_api: budget TCA_ROOT_EXT_WARN_MSG in notify skbs tca_get_fill may emit TCA_ROOT_EXT_WARN_MSG from extack->_msg. The string is whatever NL_SET_ERR_MSG and friends stored, so its length is bounded only by the caller, and nothing in the budget that tcf_add_notify_msg and tcf_del_notify_msg hand to alloc_skb accounts for it. The notify skb can therefore be sized smaller than what tca_get_fill goes on to write into it. The attribute reaches a successful add because tcf_action_init keeps going when an action that is not skip_sw fails to offload: err = tcf_action_offload_add(act, extack); if (tc_act_skip_sw(act->tcfa_flags) && err) goto err; The action is created while extack->_msg still holds the offload diagnostic, and tcf_add_notify echoes it back. A pedit action with mixed key commands (one SET and one ADD) takes that path: the non-bind tcf_pedit_offload_act_setup sets "Unsupported pedit command offload" and returns -EOPNOTSUPP. In practice, no underbudgeting has been observed because of this, and the gap is not easy to reach given some other spots account for more than necessary. However, for correctness, budget the attribute so the size handed to alloc_skb covers what tca_get_fill can write. Reported-by: Sashiko Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824153903.4143642-1-victor@mojatatu.com Co-developed-by: Jamal Hadi Salim Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Link: https://patch.msgid.link/QDISC-RYTB.v1.20260918093205@mojatatu.com.3 Reviewed-by: Simon Horman Signed-off-by: Paolo Abeni --- net/sched/act_api.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 3f653721c45f..db06ddcf6ae6 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -475,6 +475,15 @@ static size_t tcf_action_full_attrs_size(size_t sz) + sz; } +/* tca_get_fill() may append TCA_ROOT_EXT_WARN_MSG from extack->_msg */ +static size_t tcf_action_warn_attr_size(const struct netlink_ext_ack *extack) +{ + if (unlikely(extack && extack->_msg)) + return nla_total_size(strlen(extack->_msg) + 1); + + return 0; +} + static size_t tcf_action_fill_size(const struct tc_action *act) { size_t sz = tcf_action_shared_attrs_size(act); @@ -1980,7 +1989,8 @@ static struct sk_buff *tcf_del_notify_msg(struct net *net, struct nlmsghdr *n, { struct sk_buff *skb; - skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL); + skb = alloc_skb(max(attr_size + tcf_action_warn_attr_size(extack), + NLMSG_GOODSIZE), GFP_KERNEL); if (!skb) return ERR_PTR(-ENOBUFS); @@ -2078,7 +2088,8 @@ static struct sk_buff *tcf_add_notify_msg(struct net *net, struct nlmsghdr *n, { struct sk_buff *skb; - skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL); + skb = alloc_skb(max(attr_size + tcf_action_warn_attr_size(extack), + NLMSG_GOODSIZE), GFP_KERNEL); if (!skb) return ERR_PTR(-ENOBUFS); From 4ef25721f7c89392b58e53c84e09b508e8d8c0aa Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Fri, 18 Sep 2026 11:17:20 +0200 Subject: [PATCH 0690/2126] net: phy: realtek: use C45 for RTL8365MB-VC internal PHY MMD access The RTL8365MB-VC PHYs are integrated into the switch and have no MMD registers of their own. What phylib would access as MMD registers (the EEE ability/advertisement) lives in the switch's OCP registers instead. For a C22 PHY, phy_read_mmd()/phy_write_mmd() use C22 indirect-MMD, which this hardware does not implement. Point .read_mmd/.write_mmd at genphy_{read,write}_mmd_c45() so phylib issues those MMD accesses over C45, where the DSA user MDIO bus can carry them to the switch's OCP registers. This patch only redirects the MMD access path; it does not enable EEE. The OCP mapping (the DSA bus .read_c45/.write_c45 handlers) and EEE support are added by the following patch. Until then an MMD access returns -EOPNOTSUPP; the only one that runs is the EEE-ability read in phy_probe(), which phylib ignores, so probe, link and traffic are unaffected and ethtool --show-eee reports EEE unsupported -- the same as before this series, not a regression (verified on an RTL8365MB-VC). Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Reviewed-by: Luiz Angelo Daros de Luca Link: https://patch.msgid.link/20260918091722.3270534-2-o.rempel@pengutronix.de Signed-off-by: Paolo Abeni --- drivers/net/phy/realtek/realtek_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 1e670638dd1c..3b3352e2cdc6 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -3349,6 +3349,8 @@ static struct phy_driver realtek_drvs[] = { }, { PHY_ID_MATCH_EXACT(0x001cc942), .name = "RTL8365MB-VC Gigabit Ethernet", + .read_mmd = genphy_read_mmd_c45, + .write_mmd = genphy_write_mmd_c45, /* Interrupt handling analogous to RTL8366RB */ .config_intr = genphy_no_config_intr, .handle_interrupt = genphy_handle_interrupt_no_ack, From e9ba480ec8209550c597ecdc4f22b9c015001d56 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Fri, 18 Sep 2026 11:17:21 +0200 Subject: [PATCH 0691/2126] net: dsa: realtek: rtl8365mb: extract PHY OCP address halves with FIELD_GET Extract the two OCP address halves with FIELD_GET() before handing them to FIELD_PREP() to build the ADDRESS register value. rtl8365mb_phy_ocp_prepare() previously fed FIELD_PREP() the raw ocp_addr >> 1 and >> 6. FIELD_PREP() masks the value to the field at run time, so that was correct for the current callers, which all pass a run-time register address. FIELD_PREP()'s compile-time width check only fires for a compile-time constant value. None reached it here: the address is computed as PHYREG_BASE + regnum * 2 from a run-time regnum. The EEE support that follows adds callers with constant OCP addresses (0xa5c4 etc.); clang folds those into the inlined ocp_prepare(), so the shifted constant now reaches the check, overflows the 5-/4-bit field and breaks the build (gcc does not fold it here). FIELD_GET() narrows each half to the field width first, so the value already fits. No functional change. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260918091722.3270534-3-o.rempel@pengutronix.de Signed-off-by: Paolo Abeni --- drivers/net/dsa/realtek/rtl8365mb_main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index f8220d832e46..efde1f3b604e 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -199,6 +199,14 @@ #define RTL8365MB_GPHY_OCP_MSB_0_CFG_CPU_OCPADR_MASK 0x0FC0 #define RTL8365MB_PHY_OCP_ADDR_PREFIX_MASK 0xFC00 +/* The full 16-bit OCP address is split across two registers: bits [15:10] are + * the prefix (RTL8365MB_PHY_OCP_ADDR_PREFIX_MASK above), and bits [9:1] go into + * the ADDRESS register as two fields, [5:1] and [9:6]. Bit 0 is always 0 - PHY + * OCP registers are 2-byte aligned. + */ +#define RTL8365MB_PHY_OCP_ADDR_5_1_MASK GENMASK(5, 1) +#define RTL8365MB_PHY_OCP_ADDR_9_6_MASK GENMASK(9, 6) + /* The PHY OCP addresses of PHY registers 0~31 start here */ #define RTL8365MB_PHY_OCP_ADDR_PHYREG_BASE 0xA400 @@ -871,6 +879,8 @@ static int rtl8365mb_phy_poll_busy(struct realtek_priv *priv) static int rtl8365mb_phy_ocp_prepare(struct realtek_priv *priv, int phy, u32 ocp_addr) { + u16 ocp_addr_lo = FIELD_GET(RTL8365MB_PHY_OCP_ADDR_5_1_MASK, ocp_addr); + u16 ocp_addr_hi = FIELD_GET(RTL8365MB_PHY_OCP_ADDR_9_6_MASK, ocp_addr); u32 val; int ret; @@ -887,9 +897,9 @@ static int rtl8365mb_phy_ocp_prepare(struct realtek_priv *priv, int phy, val = RTL8365MB_PHY_BASE; val |= FIELD_PREP(RTL8365MB_INDIRECT_ACCESS_ADDRESS_PHYNUM_MASK, phy); val |= FIELD_PREP(RTL8365MB_INDIRECT_ACCESS_ADDRESS_OCPADR_5_1_MASK, - ocp_addr >> 1); + ocp_addr_lo); val |= FIELD_PREP(RTL8365MB_INDIRECT_ACCESS_ADDRESS_OCPADR_9_6_MASK, - ocp_addr >> 6); + ocp_addr_hi); ret = regmap_write(priv->map_nolock, RTL8365MB_INDIRECT_ACCESS_ADDRESS_REG, val); if (ret) From 61c59309b6f8a8ccdec2058ac4d7e1d09ce230a7 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Fri, 18 Sep 2026 11:17:22 +0200 Subject: [PATCH 0692/2126] net: dsa: realtek: rtl8365mb: add EEE support Add EEE support on the integrated-PHY ports, controllable per port via ethtool. The integrated PHYs have no MMD registers; their EEE registers live in the switch's OCP space. phylib accesses EEE as MMD registers, so add phy_{read,write}_c45 realtek_ops that map those MMD accesses onto their OCP addresses, wired as the user MII bus C45 handlers when the chip provides them (rtl8366rb etc. unaffected). The hardware manages LPI on its own, so advertise EEE to phylink with no-op mac_{en,dis}able_tx_lpi callbacks. The integrated PHYs advertise EEE by default -- advertised, not necessarily active, since LPI is entered only once both link partners advertise it and the link idles. No strap pin selects EEE in the vendor register map, so on the hardware tested this default is uniform and not board-specific, and marking EEE enabled by default in phylink matches the PHY's power-on advertisement. Only the integrated-PHY ports support EEE; the external RGMII ports do not. The LPI timer is a single global per-speed register, so .set_mac_eee rejects the per-port TX LPI knobs rather than silently ignoring them. This assumes the integrated PHYs advertise EEE out of reset regardless of board configuration; should a strap or other non-kernel mechanism disable EEE advertisement on some board or chip in the family, enabling it by default here would change that default behaviour. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Reviewed-by: Luiz Angelo Daros de Luca Link: https://patch.msgid.link/20260918091722.3270534-4-o.rempel@pengutronix.de Signed-off-by: Paolo Abeni --- drivers/net/dsa/realtek/realtek.h | 4 + drivers/net/dsa/realtek/rtl8365mb_main.c | 123 +++++++++++++++++++++++ drivers/net/dsa/realtek/rtl83xx.c | 20 ++++ 3 files changed, 147 insertions(+) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 75a127545e5d..1c0ca6daf545 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -156,6 +156,10 @@ struct realtek_ops { int (*phy_read)(struct realtek_priv *priv, int phy, int regnum); int (*phy_write)(struct realtek_priv *priv, int phy, int regnum, u16 val); + int (*phy_read_c45)(struct realtek_priv *priv, int phy, int devad, + int regnum); + int (*phy_write_c45)(struct realtek_priv *priv, int phy, int devad, + int regnum, u16 val); }; struct realtek_variant { diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index efde1f3b604e..87ec924a0611 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -101,6 +101,7 @@ #include #include #include +#include #include #include "realtek.h" @@ -210,6 +211,10 @@ /* The PHY OCP addresses of PHY registers 0~31 start here */ #define RTL8365MB_PHY_OCP_ADDR_PHYREG_BASE 0xA400 +#define RTL8365MB_PHY_OCP_ADDR_EEE_ABLE 0xA5C4 +#define RTL8365MB_PHY_OCP_ADDR_EEE_ADV 0xA5D0 +#define RTL8365MB_PHY_OCP_ADDR_EEE_LPABLE 0xA5D2 + /* External interface port mode values - used in DIGITAL_INTERFACE_SELECT */ #define RTL8365MB_EXT_PORT_MODE_DISABLE 0 #define RTL8365MB_EXT_PORT_MODE_RGMII 1 @@ -1050,6 +1055,66 @@ static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum, return 0; } +static int rtl8365mb_phy_read_c45(struct realtek_priv *priv, int phy, int devad, + int regnum) +{ + u32 ocp_addr; + u16 val; + int ret; + + if (phy > RTL8365MB_PHYADDRMAX) + return -EINVAL; + + if (devad == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE) + ocp_addr = RTL8365MB_PHY_OCP_ADDR_EEE_ABLE; + else if (devad == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) + ocp_addr = RTL8365MB_PHY_OCP_ADDR_EEE_ADV; + else if (devad == MDIO_MMD_AN && regnum == MDIO_AN_EEE_LPABLE) + ocp_addr = RTL8365MB_PHY_OCP_ADDR_EEE_LPABLE; + else + /* Only the EEE registers are mapped; others read as 0, as the + * hardware does, so the generic MMD code is not tripped up by + * an error. + */ + return 0; + + ret = rtl8365mb_phy_ocp_read(priv, phy, ocp_addr, &val); + if (ret) { + dev_err(priv->dev, + "failed to read PHY%d OCP %04x, ret %d\n", phy, ocp_addr, + ret); + return ret; + } + + return val; +} + +static int rtl8365mb_phy_write_c45(struct realtek_priv *priv, int phy, + int devad, int regnum, u16 val) +{ + int ret; + + if (phy > RTL8365MB_PHYADDRMAX) + return -EINVAL; + + /* Only the EEE advertisement register is writable; writes to other + * registers are ignored, as the hardware does. + */ + if (devad != MDIO_MMD_AN || regnum != MDIO_AN_EEE_ADV) + return 0; + + ret = rtl8365mb_phy_ocp_write(priv, phy, RTL8365MB_PHY_OCP_ADDR_EEE_ADV, + val); + if (ret) { + dev_err(priv->dev, + "failed to write PHY%d OCP %04x, ret %d\n", phy, + RTL8365MB_PHY_OCP_ADDR_EEE_ADV, ret); + return ret; + } + + return 0; +} + static const struct rtl8365mb_extint * rtl8365mb_get_port_extint(struct realtek_priv *priv, int port) { @@ -1649,6 +1714,14 @@ static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port, */ __set_bit(PHY_INTERFACE_MODE_GMII, config->supported_interfaces); + + /* Integrated PHYs support EEE at 100M/1G; the hardware manages + * LPI on its own, so just advertise LPI awareness to phylink. + */ + memcpy(config->lpi_interfaces, config->supported_interfaces, + sizeof(config->lpi_interfaces)); + config->lpi_capabilities = MAC_100FD | MAC_1000FD; + config->eee_enabled_default = true; return; } @@ -3285,18 +3358,66 @@ static int rtl8365mb_detect(struct realtek_priv *priv) return 0; } +static int rtl8365mb_phylink_mac_enable_tx_lpi(struct phylink_config *config, + u32 timer, bool tx_clock_stop) +{ + /* The hardware manages LPI itself; there is no MAC-level LPI control. + * This callback only signals LPI awareness to phylink. + */ + return 0; +} + +static void rtl8365mb_phylink_mac_disable_tx_lpi(struct phylink_config *config) +{ +} + static const struct phylink_mac_ops rtl8365mb_phylink_mac_ops = { .mac_select_pcs = rtl8365mb_phylink_mac_select_pcs, .mac_config = rtl8365mb_phylink_mac_config, .mac_link_down = rtl8365mb_phylink_mac_link_down, .mac_link_up = rtl8365mb_phylink_mac_link_up, + .mac_enable_tx_lpi = rtl8365mb_phylink_mac_enable_tx_lpi, + .mac_disable_tx_lpi = rtl8365mb_phylink_mac_disable_tx_lpi, }; +static bool rtl8365mb_support_eee(struct dsa_switch *ds, int port) +{ + /* Only integrated-PHY ports support EEE, not the external RGMII ports. */ + return !rtl8365mb_get_port_extint(ds->priv, port); +} + +static int rtl8365mb_set_mac_eee(struct dsa_switch *ds, int port, + struct ethtool_keee *e) +{ + struct realtek_priv *priv = ds->priv; + + /* The only LPI timing control (tx_lpi_timer) is a single global + * per-speed register shared by all ports, so it cannot be set from this + * per-port callback; leave it at its reset default. Per-port EEE is + * driven through the PHY advertisement. Reject the per-port TX LPI knobs + * rather than silently ignoring them. + */ + if (!e->tx_lpi_enabled) { + dev_err(priv->dev, "disabling EEE TX LPI is not supported\n"); + return -EOPNOTSUPP; + } + + if (e->tx_lpi_timer) { + dev_err(priv->dev, + "setting the EEE TX LPI timer is not supported\n"); + return -EOPNOTSUPP; + } + + return 0; +} + static const struct dsa_switch_ops rtl8365mb_switch_ops = { .get_tag_protocol = rtl8365mb_get_tag_protocol, .change_tag_protocol = rtl8365mb_change_tag_protocol, .setup = rtl8365mb_setup, .teardown = rtl8365mb_teardown, + .support_eee = rtl8365mb_support_eee, + .set_mac_eee = rtl8365mb_set_mac_eee, .phylink_get_caps = rtl8365mb_phylink_get_caps, .port_bridge_join = rtl83xx_port_bridge_join, .port_bridge_leave = rtl83xx_port_bridge_leave, @@ -3342,6 +3463,8 @@ static const struct realtek_ops rtl8365mb_ops = { .l2_flush = rtl8365mb_l2_flush, .phy_read = rtl8365mb_phy_read, .phy_write = rtl8365mb_phy_write, + .phy_read_c45 = rtl8365mb_phy_read_c45, + .phy_write_c45 = rtl8365mb_phy_write_c45, }; static const char *const rtl8365mb_supplies[] = { diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index 8121ec12fd8b..ad42c05d0a88 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -62,6 +62,22 @@ static int rtl83xx_user_mdio_write(struct mii_bus *bus, int addr, int regnum, return priv->ops->phy_write(priv, addr, regnum, val); } +static int rtl83xx_user_mdio_read_c45(struct mii_bus *bus, int addr, int devad, + int regnum) +{ + struct realtek_priv *priv = bus->priv; + + return priv->ops->phy_read_c45(priv, addr, devad, regnum); +} + +static int rtl83xx_user_mdio_write_c45(struct mii_bus *bus, int addr, int devad, + int regnum, u16 val) +{ + struct realtek_priv *priv = bus->priv; + + return priv->ops->phy_write_c45(priv, addr, devad, regnum, val); +} + /** * rtl83xx_setup_user_mdio() - register the user mii bus driver * @ds: DSA switch associated with this user_mii_bus @@ -95,6 +111,10 @@ int rtl83xx_setup_user_mdio(struct dsa_switch *ds) bus->name = "Realtek user MII"; bus->read = rtl83xx_user_mdio_read; bus->write = rtl83xx_user_mdio_write; + if (priv->ops->phy_read_c45) + bus->read_c45 = rtl83xx_user_mdio_read_c45; + if (priv->ops->phy_write_c45) + bus->write_c45 = rtl83xx_user_mdio_write_c45; snprintf(bus->id, MII_BUS_ID_SIZE, "%s:user_mii", dev_name(priv->dev)); bus->parent = priv->dev; From e3624f5eeac40e2f95e54e5ed684222438d56e23 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 18 Sep 2026 11:53:25 -0700 Subject: [PATCH 0693/2126] net: dsa: mv88e6xxx: check the port when reading back a policy rule chip->policies is one IDR for the whole switch, so the location an ETHTOOL_GRXCLSRULE caller supplies can name a rule belonging to any port. mv88e6xxx_get_rxnfc() copies it out without looking at policy->port, which lets a user on one user port read the MAC address and VID of a policy an admin installed on another. ETHTOOL_GRXCLSRULE needs no CAP_NET_ADMIN. The GRXCLSRLCNT and GRXCLSRLALL arms of the same switch statement already filter on policy->port, which makes the GRXCLSRULE omission look unintentional. Nonetheless, changing this does carry some regression risk. Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260918185326.3940857-2-kuba@kernel.org Signed-off-by: Paolo Abeni --- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 8cf5681f5806..461167199a71 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2457,7 +2457,7 @@ static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port, case ETHTOOL_GRXCLSRULE: err = -ENOENT; policy = idr_find(&chip->policies, fs->location); - if (policy) { + if (policy && policy->port == port) { memcpy(fs, &policy->fs, sizeof(*fs)); err = 0; } From 242ebf4c51148d5202b9c57841082c44c4284082 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 18 Sep 2026 11:53:26 -0700 Subject: [PATCH 0694/2126] net: dsa: mv88e6xxx: check the port when deleting a policy rule ETHTOOL_SRXCLSRLDEL removes the policy the location names out of the switch-wide IDR without checking which port owns it, then hands it to mv88e6xxx_policy_apply() along with the port the request arrived on. Deleting another port's rule therefore purges an ATU entry on and clears the policy register of the requesting port, while the owning port keeps its hardware policy - and, with the software object freed, no longer has a location that can be used to remove it. Initially I thought that we're just able to delete a rule from one port using another port as a handle. But if the reading of the code outlined above is correct, this is just broken, not a "feature" someone could depend on. Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260918185326.3940857-3-kuba@kernel.org Signed-off-by: Paolo Abeni --- drivers/net/dsa/mv88e6xxx/chip.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 461167199a71..70411d147677 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2503,8 +2503,9 @@ static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port, break; case ETHTOOL_SRXCLSRLDEL: err = -ENOENT; - policy = idr_remove(&chip->policies, fs->location); - if (policy) { + policy = idr_find(&chip->policies, fs->location); + if (policy && policy->port == port) { + idr_remove(&chip->policies, fs->location); policy->action = MV88E6XXX_POLICY_ACTION_NORMAL; err = mv88e6xxx_policy_apply(chip, port, policy); devm_kfree(chip->dev, policy); From 6598456d72e48d779445bfec8f72114747f8b8d7 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 21 Sep 2026 09:42:18 +0000 Subject: [PATCH 0695/2126] vsock: remove dev_hold() and dev_put() in __vsock_deliver_tap_skb() __vsock_deliver_tap_skb() is called from vsock_deliver_tap() under rcu_read_lock(). dev_queue_xmit() does not require the caller to hold a device reference count, and the device lifetime is already protected by RCU. Remove the redundant dev_hold(dev) and dev_put(dev) calls. Signed-off-by: Eric Dumazet Cc: Stefano Garzarella Reviewed-by: Bobby Eshleman Reviewed-by: Stefano Garzarella Link: https://patch.msgid.link/20260921094218.483234-1-edumazet@google.com Signed-off-by: Paolo Abeni --- net/vmw_vsock/af_vsock_tap.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/net/vmw_vsock/af_vsock_tap.c b/net/vmw_vsock/af_vsock_tap.c index 30ee7e4fe251..7c5cdceabb2a 100644 --- a/net/vmw_vsock/af_vsock_tap.c +++ b/net/vmw_vsock/af_vsock_tap.c @@ -64,14 +64,10 @@ static int __vsock_deliver_tap_skb(struct sk_buff *skb, struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC); if (nskb) { - dev_hold(dev); - nskb->dev = dev; ret = dev_queue_xmit(nskb); if (unlikely(ret > 0)) ret = net_xmit_errno(ret); - - dev_put(dev); } return ret; From d9750b3c4c277b061df694f563a58c6df7b84912 Mon Sep 17 00:00:00 2001 From: Wentao Liang Date: Thu, 17 Sep 2026 11:36:54 +0000 Subject: [PATCH 0696/2126] net: stmmac: dwmac-sun8i: Fix EPHY clock leak in get_ephy_nodes() get_ephy_nodes() stores the clock returned by of_clk_get() directly in gmac->ephy_clk before the reset control is obtained. When the reset lookup fails, the loop continues or returns without releasing that clock, and sun8i_dwmac_probe() then jumps to dwmac_remove, which does not call clk_put(). Keep the clock in a local variable and release it on the error paths. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: Wentao Liang Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260917113654.2149268-1-vulab@iscas.ac.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 48c52eb96233..38d7e71de925 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -783,18 +783,22 @@ static int get_ephy_nodes(struct stmmac_priv *priv) /* Seek for internal PHY */ for_each_child_of_node_scoped(mdio_internal, iphynode) { - gmac->ephy_clk = of_clk_get(iphynode, 0); - if (IS_ERR(gmac->ephy_clk)) + struct clk *ephy_clk; + + ephy_clk = of_clk_get(iphynode, 0); + if (IS_ERR(ephy_clk)) continue; gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL); if (IS_ERR(gmac->rst_ephy)) { ret = PTR_ERR(gmac->rst_ephy); + clk_put(ephy_clk); if (ret == -EPROBE_DEFER) { of_node_put(mdio_internal); return ret; } continue; } + gmac->ephy_clk = ephy_clk; dev_info(priv->device, "Found internal PHY node\n"); of_node_put(mdio_internal); return 0; From 08dfb3106c0de3a2bf0adb0191264bfff03ed821 Mon Sep 17 00:00:00 2001 From: Wentao Liang Date: Thu, 17 Sep 2026 10:49:20 +0000 Subject: [PATCH 0697/2126] net: dsa: vitesse-vsc73xx: Fix SPI device reference leak in vsc73xx_spi_probe() spi_dev_get() takes a reference on the SPI device, but neither the probe error paths nor vsc73xx_spi_remove() ever release it, so the spi_device can never be freed after the driver has been unbound. Release the reference on both probe error paths and in remove(). Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: Wentao Liang Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260917104920.2147568-1-vulab@iscas.ac.cn Signed-off-by: Jakub Kicinski --- drivers/net/dsa/vitesse-vsc73xx-spi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-spi.c b/drivers/net/dsa/vitesse-vsc73xx-spi.c index 85b9a0f51dd8..7b784320c41e 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-spi.c +++ b/drivers/net/dsa/vitesse-vsc73xx-spi.c @@ -153,10 +153,15 @@ static int vsc73xx_spi_probe(struct spi_device *spi) ret = spi_setup(spi); if (ret < 0) { dev_err(dev, "spi setup failed.\n"); + spi_dev_put(vsc_spi->spi); return ret; } - return vsc73xx_probe(&vsc_spi->vsc); + ret = vsc73xx_probe(&vsc_spi->vsc); + if (ret) + spi_dev_put(vsc_spi->spi); + + return ret; } static void vsc73xx_spi_remove(struct spi_device *spi) @@ -167,6 +172,8 @@ static void vsc73xx_spi_remove(struct spi_device *spi) return; vsc73xx_remove(&vsc_spi->vsc); + + spi_dev_put(vsc_spi->spi); } static void vsc73xx_spi_shutdown(struct spi_device *spi) From a4eb406f1705b21cd689f482ba49a185e61ae187 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:24 +0800 Subject: [PATCH 0698/2126] wifi: rtw89: coex: fix SET_H2C_MACRO not sent for BTC_FEAT_H2C_MACRO chips For chips with BTC_FEAT_H2C_MACRO (e.g. RTL8922D), _send_fw_cmd buffers each BTC H2C command as a TLV entry into hbuf, then falls through to the shared rtw89_fw_h2c_raw_with_hdr call. The else- branch was missing the reassignment of h2c_func, buf, and len to SET_H2C_MACRO and hbuf before that shared send, causing each command to be delivered directly rather than through the MAC FW macro mechanism 8922D requires. Add the three assignments and reset hbuf after the macro is sent. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index b16af1291b93..3ef30bd962d9 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1102,6 +1102,10 @@ static int _send_fw_cmd(struct rtw89_dev *rtwdev, u8 h2c_class, u8 h2c_func, "[BTC], %s():Buffer H2C-MACRO cnt=%d/bt%d-func=%s/len=%d\n", __func__, btc->hbuf_cnt, bid, id_to_h2c(h2c_func_mask), len); + + h2c_func = SET_H2C_MACRO; + buf = btc->hbuf; + len = btc->hbuf_len; } ret = rtw89_fw_h2c_raw_with_hdr(rtwdev, h2c_class, h2c_func, buf, len, @@ -1111,6 +1115,9 @@ static int _send_fw_cmd(struct rtw89_dev *rtwdev, u8 h2c_class, u8 h2c_func, else pfwinfo->cnt_h2c++; + if (h2c_func == SET_H2C_MACRO) + _reset_h2c_macro(btc); + return ret; } From 0a53612e780cd4f8b2d5196805c50168629562a5 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:25 +0800 Subject: [PATCH 0699/2126] wifi: rtw89: coex: fix out-of-bounds read of report gnt_val The firmware report control structures store gnt_val as either struct rtw89_mac_ax_gnt or a u8[4] array, so each element is four bytes wide. The destination dm->gnt_val[] uses struct rtw89_btc_gnt_ctrl, which is eight bytes. Copying sizeof(dm->gnt_val[i]) therefore read four bytes past the end of every source element on each loop iteration, across all affected report versions. Bound the copy by the size of the source element instead, so the memcpy never reads beyond the report field. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 3ef30bd962d9..f86311191171 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -2050,7 +2050,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) memcpy(&dm->gnt_val[i], &prpt->v4.gnt_val[i], - sizeof(dm->gnt_val[i])); + sizeof(prpt->v4.gnt_val[i])); bt->bcnt[BTC_BCNT_HIPRI_TX] = le32_to_cpu(prpt->v4.bt_cnt[BTC_BCNT_HI_TX]); @@ -2082,7 +2082,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) memcpy(&dm->gnt_val[i], &prpt->v5.gnt_val[i], - sizeof(dm->gnt_val[i])); + sizeof(prpt->v5.gnt_val[i])); bt->bcnt[BTC_BCNT_HIPRI_TX] = le16_to_cpu(prpt->v5.bt_cnt[BTC_BCNT_HI_TX]); @@ -2109,7 +2109,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) memcpy(&dm->gnt_val[i], &prpt->v105.gnt_val[i], - sizeof(dm->gnt_val[i])); + sizeof(prpt->v105.gnt_val[i])); bt->bcnt[BTC_BCNT_HIPRI_TX] = le16_to_cpu(prpt->v105.bt_cnt[BTC_BCNT_HI_TX_V105]); @@ -2135,7 +2135,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) memcpy(&dm->gnt_val[i], &prpt->v7.gnt_val[i], - sizeof(dm->gnt_val[i])); + sizeof(prpt->v7.gnt_val[i])); bt->bcnt[BTC_BCNT_HIPRI_TX] = le16_to_cpu(prpt->v7.bt_cnt[BTC_BCNT_HI_TX_V105]); @@ -2167,7 +2167,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) memcpy(&dm->gnt_val[i], &prpt->v8.gnt_val[i], - sizeof(dm->gnt_val[i])); + sizeof(prpt->v8.gnt_val[i])); bt->bcnt[BTC_BCNT_HIPRI_TX] = le16_to_cpu(prpt->v8.bt_cnt[BTC_BCNT_HI_TX_V105]); @@ -2212,7 +2212,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) memcpy(&dm->gnt_val[i], &prpt->v9.gnt_val[i], - sizeof(dm->gnt_val[i])); + sizeof(prpt->v9.gnt_val[i])); bt->bcnt[BTC_BCNT_HIPRI_TX] = le16_to_cpu(prpt->v9.bt_cnt[BTC_BCNT_HI_TX_V105]); From 4b639de3bd853e3fde5acd8ce1535548a5bb5951 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:26 +0800 Subject: [PATCH 0700/2126] wifi: rtw89: coex: fix rlink index bound check in _update_wl_info The rlink array is dimensioned [RTW89_BE_BTC_WL_MAX_ROLE_NUMBER] [RTW89_MAC_NUM], where rlink_id is the HW-band index selecting the second dimension. The guard rejected rlink_id only when it reached RTW89_BAND_NUM (3), but the array holds RTW89_MAC_NUM (2) entries, so rlink_id == 2 passed the check and led to out-of-bounds access when writing rlink[role_id][rlink_id], when scanning rlink[i][rlink_id] in the per-role loop, and inside _update_wl_mlo_info() where the same index reaches arrays sized by HW band. Reject rlink_id at RTW89_MAC_NUM so it matches the actual array size. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index f86311191171..279b75461fe2 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -7605,7 +7605,7 @@ static void _update_wl_info(struct rtw89_dev *rtwdev, struct rtw89_btc_wl_link_i u8 i, link_mode_ori; u32 role_map = 0; - if (role_id >= RTW89_BE_BTC_WL_MAX_ROLE_NUMBER || rlink_id >= RTW89_BAND_NUM) + if (role_id >= RTW89_BE_BTC_WL_MAX_ROLE_NUMBER || rlink_id >= RTW89_MAC_NUM) return; /* From f9ce5e528df736931b452fc2f9b76068156d8620 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:27 +0800 Subject: [PATCH 0701/2126] wifi: rtw89: coex: support version 8 for gpio_dbg FCX report RTL8852C (FW >= 0.27.130) and RTL8922A/D (FW >= 0.35.94/0.35.111) set fcxgpiodbg to 8, but _chk_btc_report only handled version 7, causing it to fall through to goto err. The gpio_dbg v8 struct is layout-compatible with v7, so extend the guard to accept version 8 using the existing v7 parsing path. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-5-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 279b75461fe2..62b86dc40e87 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1908,7 +1908,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, break; case BTC_RPT_TYPE_GPIO_DBG: pcinfo = &pfwinfo->rpt_fbtc_gpio_dbg.cinfo; - if (ver->fcxgpiodbg == 7) { + if (ver->fcxgpiodbg == 7 || ver->fcxgpiodbg == 8) { pfinfo = &pfwinfo->rpt_fbtc_gpio_dbg.finfo.v7; pcinfo->req_len = sizeof(pfwinfo->rpt_fbtc_gpio_dbg.finfo.v7); fwsubver->fcxgpiodbg = pfwinfo->rpt_fbtc_gpio_dbg.finfo.v7.fver; From 78aec73b9b9dabf2a866c6ea1e535f89bc4f3b87 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:28 +0800 Subject: [PATCH 0702/2126] wifi: rtw89: coex: support fcxtdma version 8 in TDMA policy RTL8922A and RTL8922D firmware sets fcxtdma to 8, which shares the same TLV encoding as version 7. Extend the _append_tdma condition to accept version 8 so the TDMA policy is sent correctly for these chips. Also enable the TDMA and CYCLE report types unconditionally in _set_fw_report_map so the firmware sends cycle statistics the driver relies on for coexistence decision-making. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-6-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 62b86dc40e87..3a5219fcc7b9 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -2719,7 +2719,7 @@ static void _append_tdma(struct rtw89_dev *rtwdev) tlv->len = sizeof(*v); *v = dm->tdma; btc->policy_len += BTC_TLV_HDR_LEN + sizeof(*v); - } else if (ver->fcxtdma == 7 || ver->fcxtdma == 4) { + } else if (ver->fcxtdma == 4 || ver->fcxtdma == 7 || ver->fcxtdma == 8) { tlv_v7 = (struct rtw89_btc_btf_tlv_v7 *)&btc->policy[len]; tlv_v7->len = sizeof(dm->tdma); tlv_v7->ver = ver->fcxtdma; @@ -6639,6 +6639,8 @@ static void _set_fw_report_map(struct rtw89_dev *rtwdev) return; } + rpt_map |= rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_TDMA); + rpt_map |= rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_CYCLE); rpt_map |= rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_MREG); bitmap = rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_BT_SCAN_INFO); From 62edaf91541e10f1ee9468cdac3d116df6a85e87 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:29 +0800 Subject: [PATCH 0703/2126] wifi: rtw89: coex: add fcxcysta v8 report support The firmware introduces coexistence cycle statistics report version 8 (fcxcysta v8). The v8 struct layout diverges from v7: it adds a per-slot WL RX error ratio array, a new CXBCN_BT_PROTECT_OK beacon counter, and extended slot step time tracking. Because of these layout differences, the v7 and v8 parsing paths in _chk_btc_report are now separate branches rather than sharing one handler. The v8 error-checking path adds hang detection for E2G, W1, and B1 slot counts in addition to the BT_SLOT_FLOOD and CYCLE_HANG checks carried over from v7. A dedicated _show_fbtc_cysta_v8 display function is added to expose the new fields through the debugfs coex dump. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-7-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 199 ++++++++++++++++++++++ drivers/net/wireless/realtek/rtw89/core.h | 26 +++ 2 files changed, 225 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 3a5219fcc7b9..785060acf508 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1841,6 +1841,11 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, pcysta->v7 = pfwinfo->rpt_fbtc_cysta.finfo.v7; pcinfo->req_len = sizeof(pfwinfo->rpt_fbtc_cysta.finfo.v7); fwsubver->fcxcysta = pfwinfo->rpt_fbtc_cysta.finfo.v7.fver; + } else if (ver->fcxcysta == 8) { + pfinfo = &pfwinfo->rpt_fbtc_cysta.finfo.v8; + pcysta->v8 = pfwinfo->rpt_fbtc_cysta.finfo.v8; + pcinfo->req_len = sizeof(pfwinfo->rpt_fbtc_cysta.finfo.v8); + fwsubver->fcxcysta = pfwinfo->rpt_fbtc_cysta.finfo.v8.fver; } else { goto err; } @@ -2628,6 +2633,49 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, le16_to_cpu(pcysta->v7.cycles)); _chk_btc_err(rtwdev, BTC_DCNT_CYCLE_HANG, le16_to_cpu(pcysta->v7.cycles)); + } else if (ver->fcxcysta == 8) { + if (dm->fddt_train == BTC_FDDT_ENABLE) + break; + + pcysta = &pfwinfo->rpt_fbtc_cysta.finfo; + + if (dm->tdma_now.type != CXTDMA_OFF) { + val16 = le16_to_cpu(pcysta->v8.cycle_time.tavg[CXT_WL]); + _chk_btc_err(rtwdev, BTC_DCNT_WL_SLOT_DRIFT, val16); + + val1 = le32_to_cpu(pcysta->v8.leak_slot.cnt_rximr) * + BTC_LEAK_AP_TH; + val2 = le16_to_cpu(pcysta->v8.slot_cnt[CXST_LK]); + + val16 = le16_to_cpu(pcysta->v8.cycles); + if (dm->tdma_now.rxflctrl && + val16 >= BTC_CYSTA_CHK_PERIOD && val1 > val2) + dm->leak_ap = 1; + } else if (dm->tdma_now.ext_ctrl == CXECTL_EXT) { + val16 = le16_to_cpu(pcysta->v8.cycle_time.tavg[CXT_BT]); + _chk_btc_err(rtwdev, BTC_DCNT_BT_SLOT_DRIFT, val16); + + val1 = le16_to_cpu(pcysta->v8.a2dp_ept.cnt_timeout) * + BTC_SLOT_REQ_TH; + val2 = le16_to_cpu(pcysta->v8.a2dp_ept.cnt); + + val16 = le16_to_cpu(pcysta->v8.cycles); + if (val16 >= BTC_CYSTA_CHK_PERIOD && val1 > val2) + dm->slot_req_more = 1; + else if (bt->link_info.status.map.connect == 0) + dm->slot_req_more = 0; + } + + _chk_btc_err(rtwdev, BTC_DCNT_E2G_HANG, + le16_to_cpu(pcysta->v8.slot_cnt[CXST_E2G])); + _chk_btc_err(rtwdev, BTC_DCNT_W1_HANG, + le16_to_cpu(pcysta->v8.slot_cnt[CXST_W1])); + _chk_btc_err(rtwdev, BTC_DCNT_B1_HANG, + le16_to_cpu(pcysta->v8.slot_cnt[CXST_B1])); + _chk_btc_err(rtwdev, BTC_DCNT_BT_SLOT_FLOOD, + le16_to_cpu(pcysta->v8.cycles)); + _chk_btc_err(rtwdev, BTC_DCNT_CYCLE_HANG, + le16_to_cpu(pcysta->v8.cycles)); } else { goto err; } @@ -10710,6 +10758,10 @@ static int _show_error(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) pcysta->v7 = pfwinfo->rpt_fbtc_cysta.finfo.v7; except_cnt = pcysta->v7.except_cnt; exception_map = le32_to_cpu(pcysta->v7.except_map); + } else if (ver->fcxcysta == 8) { + pcysta->v8 = pfwinfo->rpt_fbtc_cysta.finfo.v8; + except_cnt = pcysta->v8.except_cnt; + exception_map = le32_to_cpu(pcysta->v8.except_map); } else { return 0; } @@ -11652,6 +11704,151 @@ out: return p - buf; } +static int _show_fbtc_cysta_v8(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) +{ + struct rtw89_btc_bt_info *bt = &rtwdev->btc.cx.bt0; + struct rtw89_btc_bt_a2dp_desc *a2dp = &bt->link_info.a2dp_desc; + struct rtw89_btc_btf_fwinfo *pfwinfo = &rtwdev->btc.fwinfo; + struct rtw89_btc_fbtc_cysta_v8 *pcysta = NULL; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; + struct rtw89_btc_rpt_cmn_info *pcinfo; + char *p = buf, *end = buf + bufsz; + u16 cycle, c_begin, c_end, s_id; + u8 i, cnt = 0, divide_cnt; + u8 slot_pair; + + pcinfo = &pfwinfo->rpt_fbtc_cysta.cinfo; + if (!pcinfo->valid) + return 0; + + pcysta = &pfwinfo->rpt_fbtc_cysta.finfo.v8; + p += scnprintf(p, end - p, "\n %-15s : cycle:%d", "[slot_stat]", + le16_to_cpu(pcysta->cycles)); + + for (i = 0; i < CXST_MAX; i++) { + if (!le16_to_cpu(pcysta->slot_cnt[i])) + continue; + p += scnprintf(p, end - p, ", %s:%d", + id_to_slot(i), + le16_to_cpu(pcysta->slot_cnt[i])); + } + + if (dm->tdma_now.rxflctrl) + p += scnprintf(p, end - p, ", leak_rx:%d", + le32_to_cpu(pcysta->leak_slot.cnt_rximr)); + + if (pcysta->collision_cnt) + p += scnprintf(p, end - p, ", collision:%d", + pcysta->collision_cnt); + + if (pcysta->skip_cnt) + p += scnprintf(p, end - p, ", skip:%d", + le16_to_cpu(pcysta->skip_cnt)); + + p += scnprintf(p, end - p, + "\n %-15s : avg_t[wl:%d/bt:%d/lk:%d.%03d]", + "[cycle_stat]", + le16_to_cpu(pcysta->cycle_time.tavg[CXT_WL]), + le16_to_cpu(pcysta->cycle_time.tavg[CXT_BT]), + le16_to_cpu(pcysta->leak_slot.tavg) / 1000, + le16_to_cpu(pcysta->leak_slot.tavg) % 1000); + p += scnprintf(p, end - p, + ", max_t[wl:%d/bt:%d(>%dms:%d)/lk:%d.%03d]", + le16_to_cpu(pcysta->cycle_time.tmax[CXT_WL]), + le16_to_cpu(pcysta->cycle_time.tmax[CXT_BT]), + dm->bt_slot_flood, dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD], + le16_to_cpu(pcysta->leak_slot.tamx) / 1000, + le16_to_cpu(pcysta->leak_slot.tamx) % 1000); + p += scnprintf(p, end - p, ", bcn[all:%d/ok:%d/in_bt:%d/in_bt_ok:%d]", + le16_to_cpu(pcysta->bcn_cnt[CXBCN_ALL]), + le16_to_cpu(pcysta->bcn_cnt[CXBCN_ALL_OK]), + le16_to_cpu(pcysta->bcn_cnt[CXBCN_BT_SLOT]), + le16_to_cpu(pcysta->bcn_cnt[CXBCN_BT_OK])); + + if (a2dp->exist) { + p += scnprintf(p, end - p, + "\n %-15s : a2dp_ept:%d, a2dp_late:%d(streak 2S:%d/max:%d)", + "[a2dp_stat]", + le16_to_cpu(pcysta->a2dp_ept.cnt), + le16_to_cpu(pcysta->a2dp_ept.cnt_timeout), + a2dp->no_empty_streak_2s, + a2dp->no_empty_streak_max); + + p += scnprintf(p, end - p, ", avg_t:%d, max_t:%d", + le16_to_cpu(pcysta->a2dp_ept.tavg), + le16_to_cpu(pcysta->a2dp_ept.tmax)); + } + + if (le16_to_cpu(pcysta->cycles) <= 1) + goto out; + + slot_pair = BTC_CYCLE_SLOT_MAX / 2; + + if (le16_to_cpu(pcysta->cycles) <= slot_pair) + c_begin = 1; + else + c_begin = le16_to_cpu(pcysta->cycles) - slot_pair + 1; + + c_end = le16_to_cpu(pcysta->cycles); + + if (a2dp->exist) + divide_cnt = 2; + else + divide_cnt = 6; + + if (c_begin > c_end) + goto out; + + for (cycle = c_begin; cycle <= c_end; cycle++) { + cnt++; + s_id = ((cycle - 1) % slot_pair) * 2; + + if (cnt % divide_cnt == 1) { + if (a2dp->exist) + p += scnprintf(p, end - p, "\n %-15s : ", + "[slotT_wermtan]"); + else + p += scnprintf(p, end - p, "\n %-15s : ", + "[slotT_rxerr]"); + } + + p += scnprintf(p, end - p, "->b%d", + le16_to_cpu(pcysta->slot_step_time[s_id])); + + if (a2dp->exist) + p += scnprintf(p, end - p, "(%d/%d/%d/%dM/%d/%d/%d)", + pcysta->wl_rx_err_ratio[s_id], + pcysta->a2dp_trx[s_id].empty_cnt, + pcysta->a2dp_trx[s_id].retry_cnt, + (pcysta->a2dp_trx[s_id].tx_rate ? 3 : 2), + pcysta->a2dp_trx[s_id].tx_cnt, + pcysta->a2dp_trx[s_id].ack_cnt, + pcysta->a2dp_trx[s_id].nack_cnt); + else + p += scnprintf(p, end - p, "(%d)", + pcysta->wl_rx_err_ratio[s_id]); + + p += scnprintf(p, end - p, "->w%d", + le16_to_cpu(pcysta->slot_step_time[s_id + 1])); + + if (a2dp->exist) + p += scnprintf(p, end - p, "(%d/%d/%d/%dM/%d/%d/%d)", + pcysta->wl_rx_err_ratio[s_id + 1], + pcysta->a2dp_trx[s_id + 1].empty_cnt, + pcysta->a2dp_trx[s_id + 1].retry_cnt, + (pcysta->a2dp_trx[s_id + 1].tx_rate ? 3 : 2), + pcysta->a2dp_trx[s_id + 1].tx_cnt, + pcysta->a2dp_trx[s_id + 1].ack_cnt, + pcysta->a2dp_trx[s_id + 1].nack_cnt); + else + p += scnprintf(p, end - p, "(%d)", + pcysta->wl_rx_err_ratio[s_id + 1]); + } + +out: + return p - buf; +} + static int _show_fbtc_nullsta(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) { struct rtw89_btc *btc = &rtwdev->btc; @@ -11901,6 +12098,8 @@ static int _show_fw_dm_msg(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) p += _show_fbtc_cysta_v105(rtwdev, p, end - p); else if (ver->fcxcysta == 7) p += _show_fbtc_cysta_v7(rtwdev, p, end - p); + else if (ver->fcxcysta == 8) + p += _show_fbtc_cysta_v8(rtwdev, p, end - p); p += _show_fbtc_nullsta(rtwdev, p, end - p); diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 2e6d1be3a751..d1678a8b5872 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -3665,6 +3665,31 @@ struct rtw89_btc_fbtc_cysta_v7 { /* statistics for cycles */ __le32 except_map; } __packed; +struct rtw89_btc_fbtc_cysta_v8 { /* statistics for cycles */ + u8 fver; + u8 rsvd; + u8 collision_cnt; /* counter for event/timer at the same time */ + u8 except_cnt; + + u8 wl_rx_err_ratio[BTC_CYCLE_SLOT_MAX]; + + struct rtw89_btc_fbtc_a2dp_trx_stat_v4 a2dp_trx[BTC_CYCLE_SLOT_MAX]; + + __le16 skip_cnt; + __le16 cycles; /* total cycle number */ + __le16 rsvd1; + + __le16 slot_step_time[BTC_CYCLE_SLOT_MAX]; /* record the wl/bt slot time */ + __le16 slot_cnt[CXST_MAX]; /* slot count */ + __le16 bcn_cnt[5]; /* CXBCN_BT_PROTECT_OK added in v8 */ + + struct rtw89_btc_fbtc_cycle_time_info_v5 cycle_time; + struct rtw89_btc_fbtc_cycle_a2dp_empty_info a2dp_ept; + struct rtw89_btc_fbtc_cycle_leak_info_v7 leak_slot; + + __le32 except_map; +} __packed; + union rtw89_btc_fbtc_cysta_info { struct rtw89_btc_fbtc_cysta_v2 v2; struct rtw89_btc_fbtc_cysta_v3 v3; @@ -3672,6 +3697,7 @@ union rtw89_btc_fbtc_cysta_info { struct rtw89_btc_fbtc_cysta_v5 v5; struct rtw89_btc_fbtc_cysta_v105 v105; struct rtw89_btc_fbtc_cysta_v7 v7; + struct rtw89_btc_fbtc_cysta_v8 v8; }; struct rtw89_btc_fbtc_cynullsta_v1 { /* cycle null statistics */ From d5a10f34689c3d1439d02b70f7254249b126850c Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:30 +0800 Subject: [PATCH 0704/2126] wifi: rtw89: coex: route BT sub-reports by bt_id for dual-BT support RTL8922D supports dual BT (BT0 + BT1). The C2H report structs for fcxbtscan_v8 and fcxbtdevinfo carry a bt_id field that indicates which BT device sent the report; without routing the data always landed in bt0, silently dropping BT1 information. fcxbtscan_v8: the existing code used a local 'tbt' for the scan array copy but then wrote scan_info_update to the outer 'bt' (always bt0). Reassign 'bt' from bt_id so the update flag reaches the correct device. fcxbtdevinfo_v8: no bt_id routing existed at all. In v8 the rsvd byte carries bt_id; add a version check and redirect 'a2dp' to the selected device's a2dp descriptor. btver_v8 and btafh_v8 already route correctly and are untouched. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-8-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 785060acf508..2513af4d727c 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1591,11 +1591,10 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo) } else if (ver->fcxbtscan == 8) { struct rtw89_btc_fbtc_btscan_v8 *pscan_v8 = (struct rtw89_btc_fbtc_btscan_v8 *)pfinfo; - struct rtw89_btc_bt_info *tbt = - pscan_v8->bt_id ? &btc->cx.bt1 : &btc->cx.bt0; + bt = pscan_v8->bt_id ? &btc->cx.bt1 : &btc->cx.bt0; for (i = 0; i < CXSCAN_MAX; i++) { - tbt->scan_info_v2[i] = pscan_v8->para[i]; + bt->scan_info_v2[i] = pscan_v8->para[i]; if ((pscan_v8->type & BIT(i)) && pscan_v8->para[i].win == 0 && pscan_v8->para[i].intvl == 0) @@ -1653,6 +1652,10 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo) break; case BTC_RPT_TYPE_BT_DEVICE: pdev = (struct rtw89_btc_fbtc_btdevinfo *)pfinfo; + if (ver->fcxbtdevinfo == 8) { + bt = pdev->rsvd ? &btc->cx.bt1 : &btc->cx.bt0; + a2dp = &bt->link_info.a2dp_desc; + } a2dp->device_name = le32_to_cpu(pdev->dev_name); a2dp->vendor_id = le16_to_cpu(pdev->vendor_id); a2dp->flush_time = le32_to_cpu(pdev->flush_time); From d5f8a5e443a1ac7020d1099597c911375f49ab3d Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:31 +0800 Subject: [PATCH 0705/2126] wifi: rtw89: coex: split bt_profile into per-device fields in trx H2C Rename bt_profile/rsvd2 to bt0_profile/bt1_profile in the DM trx_info struct and all three trx H2C structs (v7/v9/v107) to match the firmware interface for dual-BT devices. Previously _update_bt_info() wrote all BT devices' profile maps into a single bt_profile field, so the last device to report overwrote the first. The firmware received bt1_profile as zero at all times because rsvd2 was never updated. Fix _update_bt_info() to assign bt0_profile when bid==BTC_BT_1ST and bt1_profile otherwise, so the firmware H2C correctly reflects each BT device's active profiles independently. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-9-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 7 ++++++- drivers/net/wireless/realtek/rtw89/core.h | 4 ++-- drivers/net/wireless/realtek/rtw89/fw.c | 12 ++++++------ drivers/net/wireless/realtek/rtw89/fw.h | 12 ++++++------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 2513af4d727c..b7b06b28009e 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -9129,7 +9129,12 @@ static void _update_bt_info(struct rtw89_dev *rtwdev, u8 bid, u8 *buf, u32 len) a2dp->exist = btinfo.lb2.a2dp; pan->exist = btinfo.lb2.pan; _update_bt_link_cnt(rtwdev, bt, is_bt_56g); - btc->dm.trx_info.bt_profile = u32_get_bits(btinfo.val, BT_PROFILE_PROTOCOL_MASK); + if (bid == BTC_BT_1ST) + btc->dm.trx_info.bt0_profile = + u32_get_bits(btinfo.val, BT_PROFILE_PROTOCOL_MASK); + else + btc->dm.trx_info.bt1_profile = + u32_get_bits(btinfo.val, BT_PROFILE_PROTOCOL_MASK); /* parse raw info low-Byte3 */ btinfo.val = raw_info[BTC_BTINFO_L3]; diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index d1678a8b5872..7fee587a8162 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -3840,8 +3840,8 @@ struct rtw89_btc_trx_info { u8 cn; /* condition_num */ s8 nhm; - u8 bt_profile; - u8 rsvd2; + u8 bt0_profile; + u8 bt1_profile; u16 tx_rate; u16 rx_rate; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 63dd918b0989..33eb09e56f95 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -7223,8 +7223,8 @@ int rtw89_fw_h2c_cxdrv_trx_v7(struct rtw89_dev *rtwdev, u8 type) h2c->v7_u8.zb_rx_gain = trx->zb_rx_gain[BTC_BT_1ST]; h2c->v7_u8.cn = trx->cn; h2c->v7_u8.nhm = trx->nhm; - h2c->v7_u8.bt_profile = trx->bt_profile; - h2c->v7_u8.rsvd2 = trx->rsvd2; + h2c->v7_u8.bt0_profile = trx->bt0_profile; + h2c->v7_u8.bt1_profile = trx->bt1_profile; h2c->v7_le.tx_rate = cpu_to_le16(trx->tx_rate); h2c->v7_le.rx_rate = cpu_to_le16(trx->rx_rate); h2c->v7_le.tx_tp = cpu_to_le32(trx->tx_tp); @@ -7290,8 +7290,8 @@ int rtw89_fw_h2c_cxdrv_trx_v9(struct rtw89_dev *rtwdev, u8 type) } h2c->v9_u8.cn = trx->cn; h2c->v9_u8.nhm = trx->nhm; - h2c->v9_u8.bt_profile = trx->bt_profile; - h2c->v9_u8.rsvd2 = trx->rsvd2; + h2c->v9_u8.bt0_profile = trx->bt0_profile; + h2c->v9_u8.bt1_profile = trx->bt1_profile; h2c->v9_le.tx_rate = cpu_to_le16(trx->tx_rate); h2c->v9_le.rx_rate = cpu_to_le16(trx->rx_rate); h2c->v9_le.tx_tp = cpu_to_le32(trx->tx_tp); @@ -7348,8 +7348,8 @@ int rtw89_fw_h2c_cxdrv_trx_v107(struct rtw89_dev *rtwdev, u8 type) h2c->v107_u8.bt_rx_gain = trx->bt_rx_gain[BTC_BT_1ST]; h2c->v107_u8.cn = trx->cn; h2c->v107_u8.nhm = trx->nhm; - h2c->v107_u8.bt_profile = trx->bt_profile; - h2c->v107_u8.rsvd2 = trx->rsvd2; + h2c->v107_u8.bt0_profile = trx->bt0_profile; + h2c->v107_u8.bt1_profile = trx->bt1_profile; h2c->v7_le.tx_rate = cpu_to_le16(trx->tx_rate); h2c->v7_le.rx_rate = cpu_to_le16(trx->rx_rate); h2c->v7_le.tx_tp = cpu_to_le32(trx->tx_tp); diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index a15a5967cabc..294399bf57b1 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -2553,8 +2553,8 @@ struct rtw89_btc_trx_info_u8 { u8 cn; /* condition_num */ s8 nhm; - u8 bt_profile; - u8 rsvd2; + u8 bt0_profile; + u8 bt1_profile; } __packed; struct rtw89_btc_trx_info_v7_u8 { @@ -2572,8 +2572,8 @@ struct rtw89_btc_trx_info_v7_u8 { u8 cn; s8 nhm; - u8 bt_profile; - u8 rsvd2; + u8 bt0_profile; + u8 bt1_profile; } __packed; struct rtw89_btc_trx_info_v107_u8 { @@ -2589,8 +2589,8 @@ struct rtw89_btc_trx_info_v107_u8 { u8 cn; s8 nhm; - u8 bt_profile; - u8 rsvd2; + u8 bt0_profile; + u8 bt1_profile; } __packed; struct rtw89_btc_trx_info_le { From a8cdddb20b2754bbe000df4c9e20c73ccd3a475b Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:32 +0800 Subject: [PATCH 0706/2126] wifi: rtw89: coex: add fcxtxpwr version dispatch for CXDRVINFO_TXPWR Some firmware sends the TXPWR H2C with a version that differs from the one implied by fcxtrx. Add a dedicated fcxtxpwr field to rtw89_btc_ver so the TXPWR H2C version can be chosen independently. It defaults to 0, keeping every existing chip on the fcxtrx-based selection, and is set to 1 for the firmware that expects the versioned H2C: RTL8922A 0.35.111.0 and RTL8922D 0.35.94.0 and later. The ver=1 TXPWR H2C shares the rtw89_h2c_cxtxpwr_v9 layout and only differs in the header version, so let rtw89_fw_h2c_cxtxpwr_v9() take the version as an argument instead of adding a near-identical function. Update the CXDRVINFO_TXPWR dispatch to send ver=1 when fcxtxpwr is set before falling through to the fcxtrx-based selection. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-10-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 52 ++++++++++++----------- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/fw.c | 6 +-- drivers/net/wireless/realtek/rtw89/fw.h | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index b7b06b28009e..1fb4a7176179 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -140,7 +140,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 10, .frptmap = 5, .fcxctrl = 9, .fcxinit = 11, .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800, .max_role_num = 6, .fcxosi = 6, .fcxmlo = 2, .bt_desired = 8, - .fcxtrx = 9, + .fcxtrx = 9, .fcxtxpwr = 1, }, {RTL8922D, RTW89_FW_VER_CODE(0, 35, 94, 0), .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, @@ -149,7 +149,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 10, .frptmap = 5, .fcxctrl = 9, .fcxinit = 10, .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800, .max_role_num = 6, .fcxosi = 6, .fcxmlo = 2, .bt_desired = 8, - .fcxtrx = 9, + .fcxtrx = 9, .fcxtxpwr = 1, }, {RTL8852BT, RTW89_FW_VER_CODE(0, 29, 133, 0), .fcxbtcrpt = 9, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -158,7 +158,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 7, .frptmap = 5, .fcxctrl = 7, .fcxinit = 107, .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 103, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, - .fcxtrx = 107, + .fcxtrx = 107, .fcxtxpwr = 0, }, {RTL8852BT, RTW89_FW_VER_CODE(0, 29, 122, 0), .fcxbtcrpt = 8, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -167,7 +167,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 7, .frptmap = 3, .fcxctrl = 7, .fcxinit = 7, .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 1, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852BT, RTW89_FW_VER_CODE(0, 29, 90, 0), .fcxbtcrpt = 7, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -176,7 +176,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 7, .frptmap = 3, .fcxctrl = 7, .fcxinit = 7, .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 1, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8922A, RTW89_FW_VER_CODE(0, 35, 111, 0), .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, @@ -185,7 +185,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 10, .frptmap = 5, .fcxctrl = 9, .fcxinit = 11, .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800, .max_role_num = 6, .fcxosi = 6, .fcxmlo = 2, .bt_desired = 8, - .fcxtrx = 9, + .fcxtrx = 9, .fcxtxpwr = 1, }, {RTL8922A, RTW89_FW_VER_CODE(0, 35, 71, 0), .fcxbtcrpt = 8, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -194,7 +194,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 8, .frptmap = 4, .fcxctrl = 7, .fcxinit = 7, .fwevntrptl = 1, .fwc2hfunc = 3, .drvinfo_ver = 3, .info_buf = 1800, .max_role_num = 6, .fcxosi = 1, .fcxmlo = 1, .bt_desired = 9, - .fcxtrx = 7, + .fcxtrx = 7, .fcxtxpwr = 0, }, {RTL8922A, RTW89_FW_VER_CODE(0, 35, 63, 0), .fcxbtcrpt = 8, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -203,7 +203,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 8, .frptmap = 4, .fcxctrl = 7, .fcxinit = 7, .fwevntrptl = 1, .fwc2hfunc = 3, .drvinfo_ver = 2, .info_buf = 1800, .max_role_num = 6, .fcxosi = 1, .fcxmlo = 1, .bt_desired = 9, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8922A, RTW89_FW_VER_CODE(0, 35, 8, 0), .fcxbtcrpt = 8, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -212,7 +212,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 8, .frptmap = 3, .fcxctrl = 7, .fcxinit = 7, .fwevntrptl = 1, .fwc2hfunc = 1, .drvinfo_ver = 1, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8851B, RTW89_FW_VER_CODE(0, 29, 133, 0), .fcxbtcrpt = 9, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -221,7 +221,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 7, .frptmap = 5, .fcxctrl = 7, .fcxinit = 107, .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 103, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, - .fcxtrx = 107, + .fcxtrx = 107, .fcxtxpwr = 0, }, {RTL8851B, RTW89_FW_VER_CODE(0, 29, 29, 0), .fcxbtcrpt = 105, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 5, @@ -230,7 +230,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 2, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852C, RTW89_FW_VER_CODE(0, 27, 97, 0), .fcxbtcrpt = 4, .fcxtdma = 4, .fcxslots = 2, .fcxcysta = 105, @@ -239,7 +239,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 101, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 107, + .fcxtrx = 107, .fcxtxpwr = 0, }, {RTL8852C, RTW89_FW_VER_CODE(0, 27, 57, 0), .fcxbtcrpt = 4, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 3, @@ -248,7 +248,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 1, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852C, RTW89_FW_VER_CODE(0, 27, 42, 0), .fcxbtcrpt = 4, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 3, @@ -257,7 +257,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 1, .frptmap = 2, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852C, RTW89_FW_VER_CODE(0, 27, 0, 0), .fcxbtcrpt = 4, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 3, @@ -266,7 +266,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 1, .frptmap = 2, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852B, RTW89_FW_VER_CODE(0, 29, 133, 0), .fcxbtcrpt = 9, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -275,7 +275,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 7, .frptmap = 105, .fcxctrl = 7, .fcxinit = 107, .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 103, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, - .fcxtrx = 107, + .fcxtrx = 107, .fcxtxpwr = 0, }, {RTL8852B, RTW89_FW_VER_CODE(0, 29, 122, 0), .fcxbtcrpt = 8, .fcxtdma = 7, .fcxslots = 7, .fcxcysta = 7, @@ -284,7 +284,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 7, .frptmap = 3, .fcxctrl = 7, .fcxinit = 7, .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 1, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852B, RTW89_FW_VER_CODE(0, 29, 29, 0), .fcxbtcrpt = 105, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 5, @@ -293,7 +293,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 2, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852B, RTW89_FW_VER_CODE(0, 29, 14, 0), .fcxbtcrpt = 5, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 4, @@ -302,7 +302,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 1, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1800, .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852B, RTW89_FW_VER_CODE(0, 27, 0, 0), .fcxbtcrpt = 4, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 3, @@ -311,7 +311,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 1, .frptmap = 1, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852A, RTW89_FW_VER_CODE(0, 13, 37, 0), .fcxbtcrpt = 4, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 3, @@ -320,7 +320,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 1, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 0, .drvinfo_ver = 0, .info_buf = 1280, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, {RTL8852A, RTW89_FW_VER_CODE(0, 13, 0, 0), .fcxbtcrpt = 1, .fcxtdma = 1, .fcxslots = 1, .fcxcysta = 2, @@ -329,7 +329,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 0, .frptmap = 0, .fcxctrl = 0, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 0, .drvinfo_ver = 0, .info_buf = 1024, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, /* keep it to be the last as default entry */ @@ -340,7 +340,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fwlrole = 0, .frptmap = 0, .fcxctrl = 0, .fcxinit = 0, .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1024, .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, - .fcxtrx = 0, + .fcxtrx = 0, .fcxtxpwr = 0, }, }; @@ -3589,10 +3589,12 @@ static void _fw_set_drv_info(struct rtw89_dev *rtwdev, u8 index) if (ver->drvinfo_ver == 3 || ver->drvinfo_ver == 103) index = 4; - if (ver->fcxtrx == 7 || ver->fcxtrx == 107) + if (ver->fcxtxpwr == 1) + rtw89_fw_h2c_cxtxpwr_v9(rtwdev, index, 1); + else if (ver->fcxtrx == 7 || ver->fcxtrx == 107) rtw89_fw_h2c_cxtxpwr_v7(rtwdev, index); else if (ver->fcxtrx == 9) - rtw89_fw_h2c_cxtxpwr_v9(rtwdev, index); + rtw89_fw_h2c_cxtxpwr_v9(rtwdev, index, 9); break; case CXDRVINFO_FDDT: if (ver->drvinfo_ver == 3 || ver->drvinfo_ver == 103) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 7fee587a8162..57fa1ce080dd 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -4390,6 +4390,7 @@ struct rtw89_btc_ver { u8 fcxmlo; u8 bt_desired; u8 fcxtrx; + u8 fcxtxpwr; }; struct rtw89_btc_btf_fwinfo { diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 33eb09e56f95..5b33bdb5a3e8 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -7458,7 +7458,7 @@ fail: return ret; } -int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type) +int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type, u8 ver) { struct rtw89_btc *btc = &rtwdev->btc; struct rtw89_btc_dm *dm = &btc->dm; @@ -7470,14 +7470,14 @@ int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type) skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); if (!skb) { - rtw89_err(rtwdev, "failed to alloc skb for h2c cxdrv_ctrl\n"); + rtw89_err(rtwdev, "failed to alloc skb for h2c cxtxpwr\n"); return -ENOMEM; } skb_put(skb, len); h2c = (struct rtw89_h2c_cxtxpwr_v9 *)skb->data; h2c->hdr.type = type; - h2c->hdr.ver = 9; + h2c->hdr.ver = ver; h2c->hdr.len = sizeof(*h2c) - H2C_LEN_CXDRVHDR_V7; if (dm->wl_tx_pwr_phy_map == BIT(RTW89_PHY_1)) h2c->pwr = rp.wl_tx_power[RTW89_PHY_1] & 0xff; diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 294399bf57b1..5df3bb97249a 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -5538,7 +5538,7 @@ int rtw89_fw_h2c_cxdrv_trx_v9(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_trx_v107(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_rfk(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxtxpwr_v7(struct rtw89_dev *rtwdev, u8 type); -int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type); +int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type, u8 ver); int rtw89_fw_h2c_del_pkt_offload(struct rtw89_dev *rtwdev, u8 id); int rtw89_fw_h2c_add_pkt_offload(struct rtw89_dev *rtwdev, u8 *id, struct sk_buff *skb_ofld); From 6e8e123df1d83c2129adc40412925eba5b78fef7 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:33 +0800 Subject: [PATCH 0707/2126] wifi: rtw89: coex: set dbcc_en for dual-band-active MLO modes The 1+1, 2+2 and legacy DBCC link modes are inherently active on both hardware bands, but the multi-link update path left dbcc_en untouched for these modes, so it retained a stale value from a previous update and the coexistence logic could act on the wrong DBCC state. Set dbcc_en directly in that branch, matching the single-band-active modes that already clear it explicitly. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-11-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 1fb4a7176179..7ee0bd441f7a 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -7454,6 +7454,8 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) wl_rinfo->pta_req_band = RTW89_MAC_0; wl_rinfo->dbcc_2g_phy = RTW89_PHY_0; } + + wl_rinfo->dbcc_en = 1; /* two HW-band both active */ break; } From b53e6acb7048ed337b643fe5233b33952da2d11e Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:34 +0800 Subject: [PATCH 0708/2126] wifi: rtw89: coex: evaluate CO-RX Hi-LNA request per band The CO-RX Hi-LNA request for the 2.4 GHz and 5/6 GHz bands was merged into a single scoreboard write gated by a combined condition. Once a co-rx band went away, for example after a 2.4 GHz disconnect, the write for the remaining band no longer covered the vanished band, so its Hi-LNA request stayed latched and could never be cleared to zero. Evaluate and write each band's Hi-LNA request independently against the BT-mirrored state, so the request for a band is cleared as soon as that band stops being co-rx. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-12-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 27 ++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 7ee0bd441f7a..f2cf5bdf65c7 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -4051,8 +4051,8 @@ static void _set_bt_corx_table(struct rtw89_dev *rtwdev, bool en) struct rtw89_btc_cx *cx = &btc->cx; struct rtw89_btc_bt_info *bt = &cx->bt0; struct rtw89_btc_dm *dm = &btc->dm; - u8 is_24g, is_56g, i; - u32 scbd_bit; + bool is_24g, is_56g, en_24g, en_56g; + u8 i; /* * true: bt use Hi-LNA rx gain table (f/e/3/2) in -3x~-9xdBm for co-rx @@ -4063,7 +4063,6 @@ static void _set_bt_corx_table(struct rtw89_dev *rtwdev, bool en) return; for (i = BTC_BT_1ST; i <= BTC_BT_2ND; i++) { - scbd_bit = 0; if (i == BTC_BT_2ND) { if (!(rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT)) continue; @@ -4074,14 +4073,22 @@ static void _set_bt_corx_table(struct rtw89_dev *rtwdev, bool en) dm->corx_map[BTC_RF_S1][i]) & BIT(RTW89_BAND_2G); is_56g = (dm->corx_map[BTC_RF_S0][i] || dm->corx_map[BTC_RF_S1][i]) & BIT(RTW89_BAND_5G); - if (is_24g) - scbd_bit |= BTC_WSCB_BT_HILNA; - if (is_56g) - scbd_bit |= BTC_WSCB_BT_HILNA_56G; - if ((is_24g && (en != (!!bt->hi_lna_rx))) || - (is_56g && (en != (!!bt->hi_lna_rx_6g)))) - _write_scbd(rtwdev, i, scbd_bit, en); + /* + * Request Hi-LNA only when that band is co-rx and enabled. + * Evaluate each band bit independently against the BT-mirrored + * state so the request can still be cleared once a CO-RX band + * disappears (e.g. 2.4 GHz disconnect), avoiding a latched + * Hi-LNA request. + */ + en_24g = is_24g && en; + en_56g = is_56g && en; + + if (en_24g != (!!bt->hi_lna_rx)) + _write_scbd(rtwdev, i, BTC_WSCB_BT_HILNA, en_24g); + + if (en_56g != (!!bt->hi_lna_rx_6g)) + _write_scbd(rtwdev, i, BTC_WSCB_BT_HILNA_56G, en_56g); } } From 98ded88f18c0012d213351e01c4fc83aebb59be6 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:35 +0800 Subject: [PATCH 0709/2126] wifi: rtw89: coex: detect BT HID activity from scoreboard The BT scoreboard reports HID activity on a dedicated bit, but the driver only mirrored the A2DP, PAN and HFP activity bits into the BT link info. HID was therefore never marked present, so coexistence decisions that depend on an active HID device treated it as absent. Read the HID activity bit alongside the other profile bits so that an active HID link is reflected in the BT link state. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-13-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index f2cf5bdf65c7..2392883df528 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -517,6 +517,7 @@ enum btc_b2w_scoreboard { BTC_BSCB_BT_CONNECT_56G = BIT(17), BTC_BSCB_BT_LNAB0_56G = BIT(18), BTC_BSCB_BT_LNAB1_56G = BIT(19), + BTC_BSCB_HID_ACT = BIT(23), BTC_BSCB_BT_15DOT4 = BIT(24), BTC_BSCB_BT_PROTECT = BIT(27), BTC_BSCB_PAN_ACT = BIT(28), @@ -7955,6 +7956,7 @@ static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid) bt_2g->a2dp_desc.exist = !!(val & BTC_BSCB_A2DP_ACT); bt_2g->pan_desc.exist = !!(val & BTC_BSCB_PAN_ACT); bt_2g->hfp_desc.exist = !!(val & BTC_BSCB_HFP_ACT); + bt_2g->hid_desc.exist = !!(val & BTC_BSCB_HID_ACT); bt->lna_constrain = 4 + !!(val & BTC_BSCB_BT_LNAB0) + !!(val & BTC_BSCB_BT_LNAB1) * 2; From 87abb9b102a4f4f22e5fdcf21cf4d23c87b4d845 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:36 +0800 Subject: [PATCH 0710/2126] wifi: rtw89: coex: check null-tx fail ratio in nullsta report Add a BTC_DCNT_NULL_TX_FAIL error check driven from the nullsta (fcxnullsta) report. When such a report is handled, _chk_btc_report() now invokes _chk_btc_err() for BTC_RPT_TYPE_NULLSTA. The check reads the null-1 slot TX count, late count and ok count from the report, handling both fcxnullsta v7 and v2 layouts, and only evaluates once at least BTC_NULLTX_CHK_PERIOD (100) null-tx attempts have accumulated. A late-to-ok ratio worse than BTC_NULLTX_FAIL_TH (8) increments the fail counter while a healthy ratio resets it, and the null1_tx_late error flag is raised once the counter reaches BTC_CHK_HANG_MAX consecutive periods. The check is skipped while FDDT training is active. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-14-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 2392883df528..f88431a0db87 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1317,14 +1317,19 @@ static void _get_reg_status(struct rtw89_dev *rtwdev, u8 type, u8 *val) #define BTC_CHK_WLSLOT_DRIFT_MAX 15 #define BTC_CHK_BTSLOT_DRIFT_MAX 15 #define BTC_CHK_HANG_MAX 3 +#define BTC_NULLTX_CHK_PERIOD 100 +#define BTC_NULLTX_FAIL_TH 8 static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt) { struct rtw89_btc *btc = &rtwdev->btc; + union rtw89_btc_fbtc_cynullsta_info *ns = &btc->fwinfo.rpt_fbtc_nullsta.finfo; struct rtw89_btc_cx *cx = &btc->cx; struct rtw89_btc_bt_info *bt = &cx->bt0; struct rtw89_btc_wl_info *wl = &cx->wl; struct rtw89_btc_dm *dm = &btc->dm; + const struct rtw89_btc_ver *ver = btc->ver; + u32 tx_cnt, late, ok; rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s(): type:%d cnt:%d\n", @@ -1514,6 +1519,37 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt) else dm->error.map.w2b_scbd_no_sync = false; break; + case BTC_DCNT_NULL_TX_FAIL: + if (dm->fddt_train) + break; + + if (ver->fcxnullsta == 7) { + ok = le32_to_cpu(ns->v7.result[1][1]); + late = le32_to_cpu(ns->v7.result[1][2]); + tx_cnt = le32_to_cpu(ns->v7.result[1][4]); + } else if (ver->fcxnullsta == 2) { + ok = le32_to_cpu(ns->v2.result[1][1]); + late = le32_to_cpu(ns->v2.result[1][2]); + tx_cnt = le32_to_cpu(ns->v2.result[1][4]); + } else if (ver->fcxnullsta == 1) { + ok = le32_to_cpu(ns->v1.result[1][1]); + late = le32_to_cpu(ns->v1.result[1][2]); + tx_cnt = 0; + } else { + break; + } + + if (tx_cnt < BTC_NULLTX_CHK_PERIOD) + break; + + if (late * BTC_NULLTX_FAIL_TH > ok) + dm->cnt_dm[BTC_DCNT_NULL_TX_FAIL]++; + else + dm->cnt_dm[BTC_DCNT_NULL_TX_FAIL] = 0; + + dm->error.map.null1_tx_late = + dm->cnt_dm[BTC_DCNT_NULL_TX_FAIL] >= BTC_CHK_HANG_MAX; + break; } } @@ -2684,6 +2720,9 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, goto err; } break; + case BTC_RPT_TYPE_NULLSTA: + _chk_btc_err(rtwdev, BTC_DCNT_NULL_TX_FAIL, 0); + break; case BTC_RPT_TYPE_MREG: if (ver->fcxmreg == 7) break; From c84836d628ed775dbca019dbbd46687aa6adb151 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:37 +0800 Subject: [PATCH 0711/2126] wifi: rtw89: coex: detect BT slot flood via A2DP empty-streak in cysta Add a BTC_DCNT_BT_SLOT_FLOOD error check driven from the cysta (fcxcysta v7) report. It walks the most recent TDMA cycles, bounded to one BTC_CYCLE_SLOT_MAX window of wl/bt slot pairs, and is only evaluated in AUTO/AUTO2 or ext-control TDMA modes once enough cycles have accumulated; otherwise the counters and error flag are cleared. For each cycle the BT slot step time is compared against the dm->bt_slot_flood threshold, increasing BTC_DCNT_BT_SLOT_FLOOD and raising the bt_slot_flood error flag when BT monopolises the medium. In the same pass the run of consecutive slots with no A2DP empty count is measured and stored in the a2dp descriptor as no_empty_streak_2s, with the running maximum kept in no_empty_streak_max. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-15-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index f88431a0db87..7cced933688b 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1324,11 +1324,15 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt) { struct rtw89_btc *btc = &rtwdev->btc; union rtw89_btc_fbtc_cynullsta_info *ns = &btc->fwinfo.rpt_fbtc_nullsta.finfo; + union rtw89_btc_fbtc_cysta_info *pcysta = &btc->fwinfo.rpt_fbtc_cysta.finfo; struct rtw89_btc_cx *cx = &btc->cx; struct rtw89_btc_bt_info *bt = &cx->bt0; + struct rtw89_btc_bt_a2dp_desc *a2dp = &bt->link_info.a2dp_desc; struct rtw89_btc_wl_info *wl = &cx->wl; struct rtw89_btc_dm *dm = &btc->dm; const struct rtw89_btc_ver *ver = btc->ver; + u32 empty_streak = 0, empty_streak_max = 0; + u32 slot_pair, c_begin, c_end, cycle, s_id; u32 tx_cnt, late, ok; rtw89_debug(rtwdev, RTW89_DBG_BTC, @@ -1485,6 +1489,53 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt) dm->error.map.bt_slot_drift = false; break; + case BTC_DCNT_BT_SLOT_FLOOD: + if (!btc->fwinfo.rpt_fbtc_cysta.cinfo.valid || + dm->cnt_dm[BTC_DCNT_CYCLE] == cnt) + break; + + if (cnt < BTC_CYCLE_SLOT_MAX || + (dm->tdma_now.type != CXTDMA_AUTO && + dm->tdma_now.type != CXTDMA_AUTO2 && + dm->tdma_now.ext_ctrl != CXECTL_EXT)) { + dm->error.map.bt_slot_flood = false; + dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD] = 0; + a2dp->no_empty_streak_2s = 0; + a2dp->no_empty_streak_max = 0; + break; + } + + /* 1 cycle = 1 wl-slot + 1 bt-slot */ + slot_pair = BTC_CYCLE_SLOT_MAX / 2; + if (cnt - dm->cnt_dm[BTC_DCNT_CYCLE] > slot_pair) + c_begin = cnt - slot_pair + 1; + else + c_begin = dm->cnt_dm[BTC_DCNT_CYCLE] + 1; + + c_end = cnt; + for (cycle = c_begin; cycle <= c_end; cycle++) { + s_id = ((cycle - 1) % slot_pair) * 2; + if (le16_to_cpu(pcysta->v7.slot_step_time[s_id]) >= + dm->bt_slot_flood) + dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD]++; + /* calculate no-A2DP-empty streak count */ + if (pcysta->v7.a2dp_trx[s_id].empty_cnt == 0 && + pcysta->v7.a2dp_trx[s_id + 1].empty_cnt == 0) { + empty_streak++; + if (empty_streak > empty_streak_max) + empty_streak_max = empty_streak; + } else { + empty_streak = 0; + } + } + + a2dp->no_empty_streak_2s = empty_streak_max; + if (a2dp->no_empty_streak_2s > a2dp->no_empty_streak_max) + a2dp->no_empty_streak_max = a2dp->no_empty_streak_2s; + + dm->error.map.bt_slot_flood = + !!dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD]; + break; case BTC_DCNT_WL_STA_NTFY: cnt = dm->cnt_notify[BTC_NCNT_WL_STA] - dm->cnt_notify[BTC_NCNT_WL_STA_LAST]; From b55b58d9178b35da4d9eaabff7c45211c14180c8 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 16 Sep 2026 15:22:38 +0800 Subject: [PATCH 0712/2126] wifi: rtw89: coex: add AFH conflict detection on BT AFH report Extend the BTC_RPT_TYPE_BT_AFH handler to detect overlap between the BT AFH channel map and the WL 2.4 GHz channels in use. On each legacy AFH map update the legacy conflict counter and error flag are reset and the AFH update counter is advanced, then the 12-byte legacy AFH map is scanned against wl->ch_map[] to count conflicting and total channels and set the bt_afh_conflict error flag. The LE path mirrors this: on each LE map update the LE conflict counter and error flag are reset and the LE update counter advanced, then the 5-byte LE AFH map is scanned against wl->ch_map_le[] to set the bt_leafh_conflict error flag. Both checks are gated by afh_en (WL 2.4 GHz AFH active) and by BT connection state (legacy: connect, LE: ble_connect or leaudio BIS/CIS). They are applied in all versioned branches (fcxbtafh 2/7/8) via a shared helper; fcxbtafh==1 has no map_type field, so conflict detection is skipped there. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916072238.62574-16-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 7cced933688b..305d8edb0d4d 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1604,6 +1604,69 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt) } } +static void _update_bt_afh_conflict(struct rtw89_dev *rtwdev, + struct rtw89_btc_bt_info *bt, + u8 map_type) +{ + struct rtw89_btc *btc = &rtwdev->btc; + struct rtw89_btc_wl_info *wl = &btc->cx.wl; + struct rtw89_btc_dm *dm = &btc->dm; + struct rtw89_btc_bt_link_info *b = &bt->link_info; + struct rtw89_btc_bt_leaudio_desc *leaudio = &b->leaudio_desc; + u8 hw_band = wl->role_info.pta_req_band; + u32 cnt, cnt_ch, cnt_le, cnt_ch_le; + u8 i, omap, xmap, afh_en; + + if (map_type & RPT_BT_AFH_SEQ_LEGACY) { + bt->bcnt[BTC_BCNT_AFH_UPDATE]++; + bt->bcnt[BTC_BCNT_AFH_CONFLICT] = 0; + dm->error.map.bt_afh_conflict = 0; + } + + afh_en = wl->afh_info[hw_band][RTW89_BAND_2G].en; + + for (i = 0; i < 12; i++) { + if (!(map_type & RPT_BT_AFH_SEQ_LEGACY) || + !b->status.map.connect) + break; + + omap = b->afh_map[i]; + xmap = omap & wl->ch_map[i]; + cnt_ch = hweight8(omap); + cnt = afh_en ? hweight8(xmap) : 0; + + if (i == 11) { + bt->bcnt[BTC_BCNT_AFH_CHN] = cnt_ch; + bt->bcnt[BTC_BCNT_AFH_CONFLICT] = cnt; + dm->error.map.bt_afh_conflict = !!cnt; + } + } + + if (map_type & RPT_BT_AFH_SEQ_LE) { + bt->bcnt[BTC_BCNT_AFH_LE_UPDATE]++; + bt->bcnt[BTC_BCNT_AFH_LE_CONFLICT] = 0; + dm->error.map.bt_leafh_conflict = 0; + } + + for (i = 0; i < 5; i++) { + if (!(map_type & RPT_BT_AFH_SEQ_LE) || + (!b->status.map.ble_connect && + !leaudio->bis_exist && !leaudio->cis_exist)) + break; + + omap = b->afh_map_le[i]; + xmap = omap & wl->ch_map_le[i]; + cnt_ch_le = hweight8(omap); + cnt_le = afh_en ? hweight8(xmap) : 0; + + if (i == 4) { + bt->bcnt[BTC_BCNT_AFH_LE_CHN] = cnt_ch_le; + bt->bcnt[BTC_BCNT_AFH_LE_CONFLICT] = cnt_le; + dm->error.map.bt_leafh_conflict = !!cnt_le; + } + } +} + static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo) { struct rtw89_btc *btc = &rtwdev->btc; @@ -1704,6 +1767,7 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo) memcpy(&bt_linfo->afh_map_le[0], pafh_v2->afh_le_a, 4); memcpy(&bt_linfo->afh_map_le[4], pafh_v2->afh_le_b, 1); } + _update_bt_afh_conflict(rtwdev, bt, pafh_v2->map_type); } else if (ver->fcxbtafh == 7) { pafh_v7 = (struct rtw89_btc_fbtc_btafh_v7 *)pfinfo; if (pafh_v7->map_type & RPT_BT_AFH_SEQ_LEGACY) { @@ -1715,6 +1779,7 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo) memcpy(&bt_linfo->afh_map_le[0], pafh_v7->afh_le_a, 4); memcpy(&bt_linfo->afh_map_le[4], pafh_v7->afh_le_b, 1); } + _update_bt_afh_conflict(rtwdev, bt, pafh_v7->map_type); } else if (ver->fcxbtafh == 8) { struct rtw89_btc_fbtc_btafh_v8 *pafh_v8 = (struct rtw89_btc_fbtc_btafh_v8 *)pfinfo; @@ -1731,6 +1796,7 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo) memcpy(&tbt_linfo->afh_map_le[0], pafh_v8->afh_le_a, 4); memcpy(&tbt_linfo->afh_map_le[4], pafh_v8->afh_le_b, 1); } + _update_bt_afh_conflict(rtwdev, tbt, pafh_v8->map_type); } else if (ver->fcxbtafh == 1) { pafh_v1 = (struct rtw89_btc_fbtc_btafh *)pfinfo; memcpy(&bt_linfo->afh_map[0], pafh_v1->afh_l, 4); From 776b5abf3fa3b0052daa6d3f01b8e964a03a898c Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Tue, 22 Sep 2026 08:50:49 +0800 Subject: [PATCH 0713/2126] net: dsa: mv88e6060: publish the OF module alias The MDIO driver matches marvell,mv88e6060 through its OF table, but the table is not exported. The existing platform alias does not supply the OF modalias used for this MDIO-enumerated device. Export the existing table so modular OF-based configurations can load the switch driver automatically. The issue was found by our static-analysis tool. Cc: stable+noautosel@kernel.org # never worked Reviewed-by: Linus Walleij Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260922005049.7647-1-hppiscas@163.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/mv88e6060.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c index 64bf3d759d17..3bb485a90429 100644 --- a/drivers/net/dsa/mv88e6060.c +++ b/drivers/net/dsa/mv88e6060.c @@ -364,6 +364,7 @@ static const struct of_device_id mv88e6060_of_match[] = { }, { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, mv88e6060_of_match); static struct mdio_driver mv88e6060_driver = { .probe = mv88e6060_probe, From 3b68565ba7674be06a21a7384d5f00e1174712fc Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 16 Sep 2026 15:38:31 +0800 Subject: [PATCH 0714/2126] wifi: rtw89: use one single BA CAM entry per MLD instead of per link Previously each link took one BA CAM entry, and then when a MLD (MLSR) switches the target link, the relation between old link and old BA CAM entry got missing and could not correctly release the old BA CAM entry. Besides, it would cause list_del corruption problems once BA CAM entry replacing process was activated after all BA CAM entries were leaked. Since HW supports to use single BA CAM entry per MLD, no need to maintain multiple BA CAM entries across different links. So, set MLD_EN bit when a MLD acquire a BA CAM entry and tweak the flow correspondingly. Reported-by: Aiden Calloway Closes: https://lore.kernel.org/linux-wireless/CAH-fA9oS2N-D05BSd0DDp_hGtBEH==cLuxr1XCUiL_UC3CN+bg@mail.gmail.com/ Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260916073831.65809-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 9 ++- drivers/net/wireless/realtek/rtw89/core.h | 11 ++-- drivers/net/wireless/realtek/rtw89/debug.c | 7 ++- drivers/net/wireless/realtek/rtw89/fw.c | 61 +++++++++++++------ drivers/net/wireless/realtek/rtw89/fw.h | 26 ++------ drivers/net/wireless/realtek/rtw89/mac80211.c | 2 + drivers/net/wireless/realtek/rtw89/ser.c | 4 +- 7 files changed, 64 insertions(+), 56 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index b074b3677c43..0c1c5c8ae8ce 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -5601,7 +5601,7 @@ void rtw89_core_release_all_bits_map(unsigned long *addr, unsigned int nbits) } int rtw89_core_acquire_sta_ba_entry(struct rtw89_dev *rtwdev, - struct rtw89_sta_link *rtwsta_link, u8 tid, + struct rtw89_sta *rtwsta, u8 tid, u8 *cam_idx) { const struct rtw89_chip_info *chip = rtwdev->chip; @@ -5639,7 +5639,7 @@ int rtw89_core_acquire_sta_ba_entry(struct rtw89_dev *rtwdev, } entry->tid = tid; - list_add_tail(&entry->list, &rtwsta_link->ba_cam_list); + list_add_tail(&entry->list, &rtwsta->ba_cam_list); *cam_idx = idx; @@ -5647,7 +5647,7 @@ int rtw89_core_acquire_sta_ba_entry(struct rtw89_dev *rtwdev, } int rtw89_core_release_sta_ba_entry(struct rtw89_dev *rtwdev, - struct rtw89_sta_link *rtwsta_link, u8 tid, + struct rtw89_sta *rtwsta, u8 tid, u8 *cam_idx) { struct rtw89_cam_info *cam_info = &rtwdev->cam_info; @@ -5656,7 +5656,7 @@ int rtw89_core_release_sta_ba_entry(struct rtw89_dev *rtwdev, lockdep_assert_wiphy(rtwdev->hw->wiphy); - list_for_each_entry_safe(entry, tmp, &rtwsta_link->ba_cam_list, list) { + list_for_each_entry_safe(entry, tmp, &rtwsta->ba_cam_list, list) { if (entry->tid != tid) continue; @@ -5751,7 +5751,6 @@ int rtw89_core_sta_link_add(struct rtw89_dev *rtwdev, int ret; rtwsta_link->prev_rssi = 0; - INIT_LIST_HEAD(&rtwsta_link->ba_cam_list); ewma_rssi_init(&rtwsta_link->avg_rssi); ewma_snr_init(&rtwsta_link->avg_snr); ewma_evm_init(&rtwsta_link->evm_1ss); diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 57fa1ce080dd..3a6099386b09 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -4665,7 +4665,6 @@ struct rtw89_sta_link { __le32 htc_template; struct rtw89_addr_cam_entry addr_cam; /* AP mode or TDLS peer only */ struct rtw89_bssid_cam_entry bssid_cam; /* TDLS peer only */ - struct list_head ba_cam_list; bool use_cfg_mask; struct cfg80211_bitrate_mask mask; @@ -5016,9 +5015,7 @@ struct rtw89_chip_ops { struct rtw89_sta_link *rtwsta_link); int (*h2c_update_beacon)(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_link); - int (*h2c_ba_cam)(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, + int (*h2c_ba_cam)(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params); int (*h2c_wow_cam_update)(struct rtw89_dev *rtwdev, struct rtw89_wow_cam_info *cam_info); @@ -7805,6 +7802,8 @@ struct rtw89_sta { struct rtw89_tid_stats tid_rx_stats[IEEE80211_NUM_TIDS]; DECLARE_BITMAP(ampdu_map, IEEE80211_NUM_TIDS); + struct list_head ba_cam_list; + DECLARE_BITMAP(pairwise_sec_cam_map, RTW89_MAX_SEC_CAM_NUM); struct list_head dlink_pool; @@ -9366,10 +9365,10 @@ u8 rtw89_core_acquire_bit_map(unsigned long *addr, unsigned long size); void rtw89_core_release_bit_map(unsigned long *addr, u8 bit); void rtw89_core_release_all_bits_map(unsigned long *addr, unsigned int nbits); int rtw89_core_acquire_sta_ba_entry(struct rtw89_dev *rtwdev, - struct rtw89_sta_link *rtwsta_link, u8 tid, + struct rtw89_sta *rtwsta, u8 tid, u8 *cam_idx); int rtw89_core_release_sta_ba_entry(struct rtw89_dev *rtwdev, - struct rtw89_sta_link *rtwsta_link, u8 tid, + struct rtw89_sta *rtwsta, u8 tid, u8 *cam_idx); void rtw89_core_free_sta_pending_ba(struct rtw89_dev *rtwdev, struct ieee80211_sta *sta); diff --git a/drivers/net/wireless/realtek/rtw89/debug.c b/drivers/net/wireless/realtek/rtw89/debug.c index 2417381bca1c..3a430bd082c3 100644 --- a/drivers/net/wireless/realtek/rtw89/debug.c +++ b/drivers/net/wireless/realtek/rtw89/debug.c @@ -4642,13 +4642,13 @@ void rtw89_vif_ids_get_iter(void *data, u8 *mac, struct ieee80211_vif *vif) static int rtw89_dump_ba_cam(struct rtw89_dev *rtwdev, char *buf, size_t bufsz, - struct rtw89_sta_link *rtwsta_link) + struct rtw89_sta *rtwsta) { struct rtw89_ba_cam_entry *entry; char *p = buf, *end = buf + bufsz; bool first = true; - list_for_each_entry(entry, &rtwsta_link->ba_cam_list, list) { + list_for_each_entry(entry, &rtwsta->ba_cam_list, list) { if (first) { p += scnprintf(p, end - p, "\tba_cam "); first = false; @@ -4683,7 +4683,6 @@ static int rtw89_sta_link_ids_get(struct rtw89_dev *rtwdev, p += scnprintf(p, end - p, "\tlink_id=%u%s\n", rtwsta_link->link_id, designated ? " (*)" : ""); p += rtw89_dump_addr_cam(rtwdev, p, end - p, &rtwsta_link->addr_cam); - p += rtw89_dump_ba_cam(rtwdev, p, end - p, rtwsta_link); return p - buf; } @@ -4705,6 +4704,8 @@ static void rtw89_sta_ids_get_iter(void *data, struct ieee80211_sta *sta) p += scnprintf(p, end - p, "STA %pM %s\n", sta->addr, sta->tdls ? "(TDLS)" : ""); + p += rtw89_dump_ba_cam(rtwdev, p, end - p, rtwsta); + rtw89_sta_for_each_link(rtwsta, rtwsta_link, link_id) p += rtw89_sta_link_ids_get(rtwdev, p, end - p, rtwsta_link, rtwsta_link == designated_link); diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 5b33bdb5a3e8..3d699e398333 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -2606,23 +2606,28 @@ fail: } EXPORT_SYMBOL(rtw89_fw_h2c_default_dmac_tbl_v3); -int rtw89_fw_h2c_ba_cam(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, +int rtw89_fw_h2c_ba_cam(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params) { const struct rtw89_chip_info *chip = rtwdev->chip; + struct rtw89_vif_link *rtwvif_link; + struct rtw89_sta_link *rtwsta_link; struct rtw89_h2c_ba_cam *h2c; - u8 macid = rtwsta_link->mac_id; u32 len = sizeof(*h2c); struct sk_buff *skb; u8 entry_idx; + u8 macid; int ret; + rtwsta_link = rtw89_get_designated_link(rtwsta); + rtwvif_link = rtwsta_link->rtwvif_link; + + macid = rtwsta_link->mac_id; + ret = valid ? - rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta, params->tid, &entry_idx) : - rtw89_core_release_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + rtw89_core_release_sta_ba_entry(rtwdev, rtwsta, params->tid, &entry_idx); if (ret) { /* it still works even if we don't have static BA CAM, because @@ -2741,24 +2746,33 @@ void rtw89_fw_h2c_init_dynamic_ba_cam_v0_ext(struct rtw89_dev *rtwdev) } } -int rtw89_fw_h2c_ba_cam_v1(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, +int rtw89_fw_h2c_ba_cam_v1(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params) { const struct rtw89_chip_info *chip = rtwdev->chip; + struct rtw89_vif_link *rtwvif_link; + struct rtw89_sta_link *rtwsta_link; struct rtw89_h2c_ba_cam_v1 *h2c; - u8 macid = rtwsta_link->mac_id; + struct ieee80211_vif *vif; u32 len = sizeof(*h2c); struct sk_buff *skb; u8 entry_idx; u8 bmap_size; + bool is_mld; + u8 macid; int ret; + rtwsta_link = rtw89_get_designated_link(rtwsta); + rtwvif_link = rtwsta_link->rtwvif_link; + vif = rtwvif_link_to_vif(rtwvif_link); + + macid = rtwsta_link->mac_id; + is_mld = ieee80211_vif_is_mld(vif); + ret = valid ? - rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta, params->tid, &entry_idx) : - rtw89_core_release_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + rtw89_core_release_sta_ba_entry(rtwdev, rtwsta, params->tid, &entry_idx); if (ret) { /* it still works even if we don't have static BA CAM, because @@ -2797,6 +2811,7 @@ int rtw89_fw_h2c_ba_cam_v1(struct rtw89_dev *rtwdev, entry_idx += chip->bacam_dynamic_num; /* std entry right after dynamic ones */ h2c->w1 = le32_encode_bits(entry_idx, RTW89_H2C_BA_CAM_V1_W1_ENTRY_IDX_MASK) | le32_encode_bits(1, RTW89_H2C_BA_CAM_V1_W1_STD_ENTRY_EN) | + le32_encode_bits(is_mld, RTW89_H2C_BA_CAM_V1_W1_MLD_EN) | le32_encode_bits(!!rtwvif_link->mac_idx, RTW89_H2C_BA_CAM_V1_W1_BAND_SEL); @@ -2820,24 +2835,33 @@ fail: } EXPORT_SYMBOL(rtw89_fw_h2c_ba_cam_v1); -int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, +int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params) { const struct rtw89_chip_info *chip = rtwdev->chip; + struct rtw89_vif_link *rtwvif_link; + struct rtw89_sta_link *rtwsta_link; struct rtw89_h2c_ba_cam_g7 *h2c; - u16 macid = rtwsta_link->mac_id; + struct ieee80211_vif *vif; u32 len = sizeof(*h2c); struct sk_buff *skb; u8 entry_idx; u8 bmap_size; + bool is_mld; + u16 macid; int ret; + rtwsta_link = rtw89_get_designated_link(rtwsta); + rtwvif_link = rtwsta_link->rtwvif_link; + vif = rtwvif_link_to_vif(rtwvif_link); + + macid = rtwsta_link->mac_id; + is_mld = ieee80211_vif_is_mld(vif); + ret = valid ? - rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + rtw89_core_acquire_sta_ba_entry(rtwdev, rtwsta, params->tid, &entry_idx) : - rtw89_core_release_sta_ba_entry(rtwdev, rtwsta_link, params->tid, + rtw89_core_release_sta_ba_entry(rtwdev, rtwsta, params->tid, &entry_idx); if (ret) { /* @@ -2871,6 +2895,7 @@ int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, le32_encode_bits(1, RTW89_H2C_BA_CAM_G7_W0_INIT_REQ) | le32_encode_bits(params->tid, RTW89_H2C_BA_CAM_G7_W0_TID_MASK) | le32_encode_bits(1, RTW89_H2C_BA_CAM_G7_W0_STD_ENTRY_EN) | + le32_encode_bits(is_mld, RTW89_H2C_BA_CAM_G7_W0_MLD_EN) | le32_encode_bits(!!rtwvif_link->mac_idx, RTW89_H2C_BA_CAM_G7_W0_BAND_SEL) | le32_encode_bits(bmap_size, RTW89_H2C_BA_CAM_G7_W0_BMAP_SIZE_MASK) | diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 5df3bb97249a..473278f6bbea 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -5593,17 +5593,11 @@ void rtw89_fw_release_general_pkt_list_vif(struct rtw89_dev *rtwdev, struct rtw89_vif_link *rtwvif_link, bool notify_fw); void rtw89_fw_release_general_pkt_list(struct rtw89_dev *rtwdev, bool notify_fw); -int rtw89_fw_h2c_ba_cam(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, +int rtw89_fw_h2c_ba_cam(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params); -int rtw89_fw_h2c_ba_cam_v1(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, +int rtw89_fw_h2c_ba_cam_v1(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params); -int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, - struct rtw89_vif_link *rtwvif_link, - struct rtw89_sta_link *rtwsta_link, +int rtw89_fw_h2c_ba_cam_g7(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params); void rtw89_fw_h2c_init_dynamic_ba_cam_v0_ext(struct rtw89_dev *rtwdev); int rtw89_fw_h2c_init_ba_cam_users(struct rtw89_dev *rtwdev, u8 users, @@ -5845,20 +5839,8 @@ int rtw89_chip_h2c_ba_cam(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, bool valid, struct ieee80211_ampdu_params *params) { const struct rtw89_chip_info *chip = rtwdev->chip; - struct rtw89_vif_link *rtwvif_link; - struct rtw89_sta_link *rtwsta_link; - unsigned int link_id; - int ret; - rtw89_sta_for_each_link(rtwsta, rtwsta_link, link_id) { - rtwvif_link = rtwsta_link->rtwvif_link; - ret = chip->ops->h2c_ba_cam(rtwdev, rtwvif_link, rtwsta_link, - valid, params); - if (ret) - return ret; - } - - return 0; + return chip->ops->h2c_ba_cam(rtwdev, rtwsta, valid, params); } static inline diff --git a/drivers/net/wireless/realtek/rtw89/mac80211.c b/drivers/net/wireless/realtek/rtw89/mac80211.c index cf356a54d91c..9e6cafc492c4 100644 --- a/drivers/net/wireless/realtek/rtw89/mac80211.c +++ b/drivers/net/wireless/realtek/rtw89/mac80211.c @@ -519,6 +519,8 @@ static int __rtw89_ops_sta_add(struct rtw89_dev *rtwdev, INIT_LIST_HEAD(&rtwsta->dlink_pool); skb_queue_head_init(&rtwsta->roc_queue); + + INIT_LIST_HEAD(&rtwsta->ba_cam_list); bitmap_zero(rtwsta->pairwise_sec_cam_map, RTW89_MAX_SEC_CAM_NUM); rtwsta_link = rtw89_sta_set_link(rtwsta, sta->deflink.link_id); diff --git a/drivers/net/wireless/realtek/rtw89/ser.c b/drivers/net/wireless/realtek/rtw89/ser.c index a507ce1fcd63..701440bd7be1 100644 --- a/drivers/net/wireless/realtek/rtw89/ser.c +++ b/drivers/net/wireless/realtek/rtw89/ser.c @@ -327,6 +327,8 @@ static void ser_sta_deinit_cam_iter(void *data, struct ieee80211_sta *sta) if (rtwvif != target_rtwvif) return; + INIT_LIST_HEAD(&rtwsta->ba_cam_list); + rtw89_sta_for_each_link(rtwsta, rtwsta_link, link_id) { rtwvif_link = rtwsta_link->rtwvif_link; @@ -334,8 +336,6 @@ static void ser_sta_deinit_cam_iter(void *data, struct ieee80211_sta *sta) rtw89_cam_deinit_addr_cam(rtwdev, &rtwsta_link->addr_cam); if (sta->tdls) rtw89_cam_deinit_bssid_cam(rtwdev, &rtwsta_link->bssid_cam); - - INIT_LIST_HEAD(&rtwsta_link->ba_cam_list); } } From 944ae66642b726bd6b25ae71b1e9ff88a0e0bdb0 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 01:06:27 +0000 Subject: [PATCH 0715/2126] tcp: remove dead code in tcp_rcv_state_process() Since commit 3d501dd326fb ("tcp: do not accept ACK of bytes we never sent"), tcp_ack() bounds the acceptable old ACK window by min(tp->max_window, tp->bytes_acked). When sk->sk_state == TCP_SYN_RECV, tp->bytes_acked is always 0, so any segment with before(ack, prior_snd_una) immediately returns -SKB_DROP_REASON_TCP_TOO_OLD_ACK and never reaches the old_ack label (which returns 0). Therefore, tcp_ack() can only return 0 in closing states (where old ACKs are accepted), and can never return 0 in TCP_SYN_RECV. Simplify the tcp_ack() return value check in tcp_rcv_state_process() to only check for negative return values and remove the unreachable !reason branch. Signed-off-by: Eric Dumazet Reviewed-by: Xuanqiang Luo Link: https://patch.msgid.link/20260922010627.2291980-1-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/ipv4/tcp_input.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 92bc60716f33..892ff256e235 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -7233,19 +7233,14 @@ tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) FLAG_UPDATE_TS_RECENT | FLAG_NO_CHALLENGE_ACK); - if ((int)reason <= 0) { - if (sk->sk_state == TCP_SYN_RECV) { + /* accept old ack (reason == 0) during closing */ + if ((int)reason < 0) { + reason = -reason; + if (sk->sk_state == TCP_SYN_RECV) /* send one RST */ - if (!reason) - return SKB_DROP_REASON_TCP_OLD_ACK; - return -reason; - } - /* accept old ack during closing */ - if ((int)reason < 0) { - tcp_send_challenge_ack(sk, false); - reason = -reason; - goto discard; - } + return reason; + tcp_send_challenge_ack(sk, false); + goto discard; } SKB_DR_SET(reason, NOT_SPECIFIED); switch (sk->sk_state) { From cb43c5421fb37c520b6a8bdb9dbf51a74e92ef46 Mon Sep 17 00:00:00 2001 From: Chih-Kang Chang Date: Wed, 16 Sep 2026 15:40:00 +0800 Subject: [PATCH 0716/2126] wifi: rtw89: 8851b: avoid using CPUIO feature with old firmware The old firmware for RTL8851B doesn't support CPUIO feature. Add firmware feature check to avoid C2H register polling timeout. Reported-by: Maxim Skokov Closes: https://lore.kernel.org/linux-wireless/20260912193939.5565-1-skokovmaksimevg@gmail.com/ Signed-off-by: Chih-Kang Chang Signed-off-by: Ping-Ke Shih Tested-by: Maxim Skokov Link: https://patch.msgid.link/20260916074000.65960-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/fw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 3d699e398333..535cc2ad8611 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -892,6 +892,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = { __CFG_FW_FEAT(RTL8851B, ge, 0, 29, 37, 1, TX_WAKE), __CFG_FW_FEAT(RTL8851B, ge, 0, 29, 37, 1, SCAN_OFFLOAD), __CFG_FW_FEAT(RTL8851B, ge, 0, 29, 41, 0, CRASH_TRIGGER_TYPE_0), + __CFG_FW_FEAT(RTL8851B, lt, 0, 29, 57, 0, NO_WOW_CPU_IO_RX), __CFG_FW_FEAT(RTL8851B, ge, 0, 29, 127, 0, SER_L1_BY_EVENT), __CFG_FW_FEAT(RTL8851B, ge, 0, 29, 130, 0, SIM_SER_L0L1_BY_HALT_H2C), __CFG_FW_FEAT(RTL8852A, le, 0, 13, 29, 0, OLD_HT_RA_FORMAT), From 398660e43ed9f85e008f967df401ed70f3c41665 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Fri, 18 Sep 2026 10:11:13 +0800 Subject: [PATCH 0717/2126] wifi: rtw89: correct dependency of the multicolor LED The rtw89 depends on multicolor LED module, but for the case multicolor LED is module and rtw89 is built-in driver, like CONFIG_LEDS_CLASS_MULTICOLOR=m CONFIG_RTW89=y CONFIG_RTW89_LEDS_MC=y The linker reports error: ld.lld: error: undefined symbol: led_classdev_multicolor_register_ext Avoid this case, and summerize the supported combination as below CONFIG_LEDS_CLASS_MULTICOLOR y m m CONFIG_RTW89 y/m m y support O O X Fixes: 721d90c8509a ("wifi: rtw89: add multicolor LED support for RTL8852CU valve board") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202609172315.ZYoKvKBS-lkp@intel.com/ Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260918021113.25481-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/Kconfig b/drivers/net/wireless/realtek/rtw89/Kconfig index 7c678dd1f6b3..9c6c16af7f35 100644 --- a/drivers/net/wireless/realtek/rtw89/Kconfig +++ b/drivers/net/wireless/realtek/rtw89/Kconfig @@ -215,7 +215,7 @@ config RTW89_LEDS config RTW89_LEDS_MC bool depends on RTW89_LEDS - depends on LEDS_CLASS_MULTICOLOR + depends on LEDS_CLASS_MULTICOLOR=y || LEDS_CLASS_MULTICOLOR=RTW89_CORE imply LEDS_TRIGGER_TIMER default y From 9f7edf4e8584c87e3c478c6dd87c08d51b5157c2 Mon Sep 17 00:00:00 2001 From: Kim Wooseok <5mghybrid@khu.ac.kr> Date: Mon, 21 Sep 2026 16:59:49 +0900 Subject: [PATCH 0718/2126] wifi: rtl8xxxu: free RX skb when URB submission fails When usb_submit_urb() fails, rtl8xxxu_submit_rx_urb() unanchors the URB but leaves the newly allocated skb in urb.context. For ENOMEM/EAGAIN, the RX worker puts the request back on the pending list. The next submission allocates another skb and overwrites that pointer, leaking the previous buffer. Stopping before the retry also leaks it, because pending-list cleanup frees only the URB. Free the skb and clear urb.context in rtl8xxxu_submit_rx_urb() when submission fails. This keeps buffer allocation and failure cleanup in the same function, so a request returned for retry or teardown no longer owns an skb. Remove the corresponding cleanup from start and the RX worker; they only need to decide whether to retry or free the URB. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Reviewed-by: Ping-Ke Shih Assisted-by: GPT-6 Astra Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260921-codex-rtl-rx-v3-submit-v4-1-eeb09fe8f791@khu.ac.kr --- drivers/net/wireless/realtek/rtl8xxxu/core.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c index bddbd0990de7..795a5ec2f8cd 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c @@ -5864,7 +5864,6 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *work) struct rtl8xxxu_priv *priv; struct rtl8xxxu_rx_urb *rx_urb, *tmp; struct list_head local; - struct sk_buff *skb; unsigned long flags; int ret; @@ -5896,8 +5895,6 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *work) default: dev_warn(&priv->udev->dev, "failed to requeue urb with error %i\n", ret); - skb = (struct sk_buff *)rx_urb->urb.context; - dev_kfree_skb(skb); usb_free_urb(&rx_urb->urb); } } @@ -6596,8 +6593,11 @@ static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv, skb_size, rtl8xxxu_rx_complete, skb); usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor); ret = usb_submit_urb(&rx_urb->urb, GFP_ATOMIC); - if (ret) + if (ret) { usb_unanchor_urb(&rx_urb->urb); + dev_kfree_skb(skb); + rx_urb->urb.context = NULL; + } return ret; } @@ -7410,7 +7410,6 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) struct rtl8xxxu_priv *priv = hw->priv; struct rtl8xxxu_rx_urb *rx_urb; struct rtl8xxxu_tx_urb *tx_urb; - struct sk_buff *skb; unsigned long flags; int ret, i; @@ -7461,13 +7460,8 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) rx_urb->hw = hw; ret = rtl8xxxu_submit_rx_urb(priv, rx_urb); - if (ret) { - if (ret != -ENOMEM) { - skb = (struct sk_buff *)rx_urb->urb.context; - dev_kfree_skb(skb); - } + if (ret) rtl8xxxu_queue_rx_urb(priv, rx_urb); - } } schedule_delayed_work(&priv->ra_watchdog, 2 * HZ); From 4c58fb8944a2cfbe5506534de0cf58646408d31a Mon Sep 17 00:00:00 2001 From: Kim Wooseok <5mghybrid@khu.ac.kr> Date: Mon, 21 Sep 2026 16:59:50 +0900 Subject: [PATCH 0719/2126] wifi: rtl8xxxu: unwind incomplete receive startup rtl8xxxu_start() allocates and submits RX URBs one at a time. If a later allocation fails, the error path frees the TX pool but leaves earlier RX requests active. A partial TX or RX allocation failure can also leave ret at zero, so start reports success despite the incomplete setup. Allocate the RX pool before submitting any of it, and return ENOMEM whenever a pool allocation fails. Pass start errors through rtl8xxxu_stop(), including interrupt URB submission failures, so the existing stop path cancels work and releases both active requests and partially allocated pools. Share the submission loop with the RX worker. Both callers keep requests that fail with ENOMEM/EAGAIN. For a fatal error during startup, free the rest of the unsubmitted batch and return the error so start can unwind. In the worker, free only the failed request and continue with the rest of the batch. Keep the allocation loop in a small helper so the setup and error paths in start remain easy to follow. On an RTL8192EU, I exercised every error exit in rtl8xxxu_start() except interrupt-URB allocation and submission failures, which this adapter does not use. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Assisted-by: GPT-6 Astra Reviewed-by: Ping-Ke Shih Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260921-codex-rtl-rx-v3-submit-v4-2-eeb09fe8f791@khu.ac.kr --- drivers/net/wireless/realtek/rtl8xxxu/core.c | 96 +++++++++++--------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c index 795a5ec2f8cd..5cd6498cc47f 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c @@ -58,6 +58,7 @@ MODULE_PARM_DESC(dma_agg_pages, "Set DMA aggregation pages (range 1-127, 0 to di #define RTL8XXXU_TX_URB_LOW_WATER 25 #define RTL8XXXU_TX_URB_HIGH_WATER 32 +static void rtl8xxxu_stop(struct ieee80211_hw *hw, bool suspend); static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv, struct rtl8xxxu_rx_urb *rx_urb); @@ -5832,6 +5833,28 @@ static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv) spin_unlock_irqrestore(&priv->rx_urb_lock, flags); } +static int rtl8xxxu_alloc_rx_urbs(struct rtl8xxxu_priv *priv) +{ + struct rtl8xxxu_rx_urb *rx_urb; + int i; + + /* No RX work is active until the complete pool has been allocated. */ + for (i = 0; i < RTL8XXXU_RX_URBS; i++) { + rx_urb = kmalloc_obj(struct rtl8xxxu_rx_urb); + if (!rx_urb) + return -ENOMEM; + + usb_init_urb(&rx_urb->urb); + INIT_LIST_HEAD(&rx_urb->list); + rx_urb->hw = priv->hw; + + list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list); + priv->rx_urb_pending_count++; + } + + return 0; +} + static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, struct rtl8xxxu_rx_urb *rx_urb) { @@ -5859,32 +5882,21 @@ static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, spin_unlock_irqrestore(&priv->rx_urb_lock, flags); } -static void rtl8xxxu_rx_urb_work(struct work_struct *work) +static int rtl8xxxu_submit_rx_urbs(struct rtl8xxxu_priv *priv, bool startup) { - struct rtl8xxxu_priv *priv; struct rtl8xxxu_rx_urb *rx_urb, *tmp; - struct list_head local; unsigned long flags; + LIST_HEAD(local); int ret; - priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); - INIT_LIST_HEAD(&local); - spin_lock_irqsave(&priv->rx_urb_lock, flags); - list_splice_init(&priv->rx_urb_pending_list, &local); priv->rx_urb_pending_count = 0; - spin_unlock_irqrestore(&priv->rx_urb_lock, flags); list_for_each_entry_safe(rx_urb, tmp, &local, list) { list_del_init(&rx_urb->list); ret = rtl8xxxu_submit_rx_urb(priv, rx_urb); - /* - * If out of memory or temporary error, put it back on the - * queue and try again. Otherwise the device is dead/gone - * and we should drop it. - */ switch (ret) { case 0: break; @@ -5893,11 +5905,29 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *work) rtl8xxxu_queue_rx_urb(priv, rx_urb); break; default: + usb_free_urb(&rx_urb->urb); + if (startup) + goto free_remaining; dev_warn(&priv->udev->dev, "failed to requeue urb with error %i\n", ret); - usb_free_urb(&rx_urb->urb); } } + + return 0; + +free_remaining: + list_for_each_entry_safe(rx_urb, tmp, &local, list) { + list_del(&rx_urb->list); + usb_free_urb(&rx_urb->urb); + } + return ret; +} + +static void rtl8xxxu_rx_urb_work(struct work_struct *work) +{ + struct rtl8xxxu_priv *priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); + + rtl8xxxu_submit_rx_urbs(priv, false); } /* @@ -7408,7 +7438,6 @@ static void rtl8xxxu_watchdog_callback(struct work_struct *work) static int rtl8xxxu_start(struct ieee80211_hw *hw) { struct rtl8xxxu_priv *priv = hw->priv; - struct rtl8xxxu_rx_urb *rx_urb; struct rtl8xxxu_tx_urb *tx_urb; unsigned long flags; int ret, i; @@ -7423,14 +7452,13 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) if (priv->usb_interrupts) { ret = rtl8xxxu_submit_int_urb(hw); if (ret) - goto exit; + goto error_out; } for (i = 0; i < RTL8XXXU_TX_URBS; i++) { tx_urb = kmalloc_obj(struct rtl8xxxu_tx_urb); if (!tx_urb) { - if (!i) - ret = -ENOMEM; + ret = -ENOMEM; goto error_out; } @@ -7441,31 +7469,21 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) priv->tx_urb_free_count++; } + ret = rtl8xxxu_alloc_rx_urbs(priv); + if (ret) + goto error_out; + priv->tx_stopped = false; spin_lock_irqsave(&priv->rx_urb_lock, flags); priv->shutdown = false; spin_unlock_irqrestore(&priv->rx_urb_lock, flags); - for (i = 0; i < RTL8XXXU_RX_URBS; i++) { - rx_urb = kmalloc_obj(struct rtl8xxxu_rx_urb); - if (!rx_urb) { - if (!i) - ret = -ENOMEM; - - goto error_out; - } - usb_init_urb(&rx_urb->urb); - INIT_LIST_HEAD(&rx_urb->list); - rx_urb->hw = hw; - - ret = rtl8xxxu_submit_rx_urb(priv, rx_urb); - if (ret) - rtl8xxxu_queue_rx_urb(priv, rx_urb); - } + ret = rtl8xxxu_submit_rx_urbs(priv, true); + if (ret) + goto error_out; schedule_delayed_work(&priv->ra_watchdog, 2 * HZ); -exit: /* * Accept all data and mgmt frames */ @@ -7478,13 +7496,7 @@ exit: return ret; error_out: - rtl8xxxu_free_tx_resources(priv); - /* - * Disable all data and mgmt frames - */ - rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000); - rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000); - + rtl8xxxu_stop(hw, false); return ret; } From 2f77c66694108785a1f6ae6c5de06453e7f7a91f Mon Sep 17 00:00:00 2001 From: Kim Wooseok <5mghybrid@khu.ac.kr> Date: Mon, 21 Sep 2026 16:59:51 +0900 Subject: [PATCH 0720/2126] wifi: rtl8xxxu: preserve RX requests across recoverable transfer errors rtl8xxxu resubmits completed RX requests when more than eight URBs are waiting on the pending list. It starts with 32 URBs, but frees them on completion errors. After enough errors, the remaining pool can no longer reach the submission threshold. Reception then stays stopped even after the errors end. Temporary submission failures can leave a small batch waiting with no further work scheduled, too. Keep the URB when a completion reports EPROTO, EILSEQ, ETIME, EOVERFLOW, ECOMM or ENOSR. Free its receive buffer and return the request to the same pending list used by normal completions. ENOMEM/EAGAIN from startup or worker submission uses this path as well, so a submission failure cannot strand a request during recovery. Use one delayed work item to submit the pending requests. An error queues a retry after 100 ms without moving an existing reservation back. If a normal completion takes the pending count above eight, mod_delayed_work(..., 0) brings the work forward. This limits repeated retries when reception is not progressing, while allowing normal traffic to replenish the pool promptly. The 100 ms delay is therefore not a minimum wait for each failed URB. Keep the shutdown check, queue insertion and scheduling under the RX lock. Stop sets shutdown under that lock, cancels the delayed work synchronously, then drains active and pending requests. Cancellation and device removal continue to free their URBs. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Assisted-by: GPT-6 Astra Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Reviewed-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260921-codex-rtl-rx-v3-submit-v4-3-eeb09fe8f791@khu.ac.kr --- drivers/net/wireless/realtek/rtl8xxxu/core.c | 46 ++++++++++++------- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c index 5cd6498cc47f..3d0c22db30a8 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c @@ -54,6 +54,7 @@ MODULE_PARM_DESC(dma_agg_pages, "Set DMA aggregation pages (range 1-127, 0 to di #define USB_VENDOR_ID_REALTEK 0x0bda #define RTL8XXXU_RX_URBS 32 #define RTL8XXXU_RX_URB_PENDING_WATER 8 +#define RTL8XXXU_RX_URB_RETRY_DELAY_MS 100 #define RTL8XXXU_TX_URBS 64 #define RTL8XXXU_TX_URB_LOW_WATER 25 #define RTL8XXXU_TX_URB_HIGH_WATER 32 @@ -5856,9 +5857,8 @@ static int rtl8xxxu_alloc_rx_urbs(struct rtl8xxxu_priv *priv) } static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, - struct rtl8xxxu_rx_urb *rx_urb) + struct rtl8xxxu_rx_urb *rx_urb, bool defer_schedule) { - struct sk_buff *skb; unsigned long flags; spin_lock_irqsave(&priv->rx_urb_lock, flags); @@ -5866,16 +5866,13 @@ static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, if (!priv->shutdown) { list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list); priv->rx_urb_pending_count++; - /* - * Arm the worker under rx_urb_lock so this is atomic with the - * shutdown check: moving it out of the lock would let a - * completion arm the work after rtl8xxxu_stop() canceled it. - */ - if (priv->rx_urb_pending_count > RTL8XXXU_RX_URB_PENDING_WATER) - schedule_work(&priv->rx_urb_wq); + /* Serialize scheduling with the shutdown check and cancellation. */ + if (defer_schedule) + schedule_delayed_work(&priv->rx_urb_wq, + msecs_to_jiffies(RTL8XXXU_RX_URB_RETRY_DELAY_MS)); + else if (priv->rx_urb_pending_count > RTL8XXXU_RX_URB_PENDING_WATER) + mod_delayed_work(system_percpu_wq, &priv->rx_urb_wq, 0); } else { - skb = (struct sk_buff *)rx_urb->urb.context; - dev_kfree_skb_irq(skb); usb_free_urb(&rx_urb->urb); } @@ -5902,7 +5899,7 @@ static int rtl8xxxu_submit_rx_urbs(struct rtl8xxxu_priv *priv, bool startup) break; case -ENOMEM: case -EAGAIN: - rtl8xxxu_queue_rx_urb(priv, rx_urb); + rtl8xxxu_queue_rx_urb(priv, rx_urb, true); break; default: usb_free_urb(&rx_urb->urb); @@ -5925,7 +5922,8 @@ free_remaining: static void rtl8xxxu_rx_urb_work(struct work_struct *work) { - struct rtl8xxxu_priv *priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); + struct rtl8xxxu_priv *priv = container_of(to_delayed_work(work), + struct rtl8xxxu_priv, rx_urb_wq); rtl8xxxu_submit_rx_urbs(priv, false); } @@ -6585,10 +6583,24 @@ static void rtl8xxxu_rx_complete(struct urb *urb) skb = NULL; rx_urb->urb.context = NULL; - rtl8xxxu_queue_rx_urb(priv, rx_urb); + rtl8xxxu_queue_rx_urb(priv, rx_urb, false); } else { dev_dbg(dev, "%s: status %i\n", __func__, urb->status); - goto cleanup; + + switch (urb->status) { + case -EPROTO: + case -EILSEQ: + case -ETIME: + case -EOVERFLOW: + case -ECOMM: + case -ENOSR: + dev_kfree_skb(skb); + urb->context = NULL; + rtl8xxxu_queue_rx_urb(priv, rx_urb, true); + return; + default: + goto cleanup; + } } return; @@ -7519,7 +7531,7 @@ static void rtl8xxxu_stop(struct ieee80211_hw *hw, bool suspend) * it drained via rtl8xxxu_submit_rx_urb(), so a worker still running * after the kill could submit a URB that escapes it. */ - cancel_work_sync(&priv->rx_urb_wq); + cancel_delayed_work_sync(&priv->rx_urb_wq); usb_kill_anchored_urbs(&priv->rx_anchor); usb_kill_anchored_urbs(&priv->tx_anchor); @@ -7832,7 +7844,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface, spin_lock_init(&priv->tx_urb_lock); INIT_LIST_HEAD(&priv->rx_urb_pending_list); spin_lock_init(&priv->rx_urb_lock); - INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work); + INIT_DELAYED_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work); INIT_DELAYED_WORK(&priv->ra_watchdog, rtl8xxxu_watchdog_callback); INIT_DELAYED_WORK(&priv->update_beacon_work, rtl8xxxu_update_beacon_work_callback); skb_queue_head_init(&priv->c2hcmd_queue); diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h index eeb18eb0e4c0..c6953051d9c4 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h @@ -1809,7 +1809,7 @@ struct rtl8xxxu_priv { struct list_head rx_urb_pending_list; int rx_urb_pending_count; bool shutdown; - struct work_struct rx_urb_wq; + struct delayed_work rx_urb_wq; u8 mac_addr[ETH_ALEN]; char chip_name[8]; From 1196e46f6d42ac490e245f3917af330530a176f0 Mon Sep 17 00:00:00 2001 From: Qingfang Deng Date: Sun, 20 Sep 2026 19:49:43 +0800 Subject: [PATCH 0721/2126] ppp_synctty: remove redundant skb null check in ppp_sync_txmunge() The skb is already dereferenced before the check. In addition, a TX skb passed from the generic layer can never be null. Remove the redundant null check. Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202609132245.txZXoUxc-lkp@intel.com/ Signed-off-by: Qingfang Deng Link: https://patch.msgid.link/20260920114945.2517-1-qingfang.deng@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/ppp/ppp_synctty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c index 9e440e110e9f..b90ae0583c84 100644 --- a/drivers/net/ppp/ppp_synctty.c +++ b/drivers/net/ppp/ppp_synctty.c @@ -464,7 +464,7 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) ap->last_xmit = jiffies; - if (skb && ap->flags & SC_LOG_OUTPKT) + if (ap->flags & SC_LOG_OUTPKT) ppp_print_buffer ("send buffer", skb->data, skb->len); return skb; From a9e94a7faa5691ca4fc48e27eebb5d42fde00e2a Mon Sep 17 00:00:00 2001 From: Jan Hoffmann Date: Sun, 20 Sep 2026 21:26:10 +0200 Subject: [PATCH 0722/2126] net: sfp: add quirk for XikeStor SKT-2.5G-100M This 2.5G copper SFP module contains a RTL8221B-VB-CG PHY which can be accessed using Rollball protocol. Add a SFP quirk to enable Rollball protocol. It includes a small delay to avoid unnecessary attempts at reading PHY registers before the module is ready. Note: The RTL8221B PHY in this module becomes stuck in a broken state after attempting to read some registers on MMD 30 while it has already established a link (this is a general issue with this PHY which happens when it is configured for rate adaptation mode). This includes the registers 2/3/8 which are read by "get_phy_c45_ids" during PHY probing. However, the PHY takes about 4 seconds to establish a link after reset, so in practice any host that supports TX_DISABLE should be unaffected, as that puts the PHY into reset. Signed-off-by: Jan Hoffmann Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260920192632.72729-2-jan@3e8.eu Signed-off-by: Jakub Kicinski --- drivers/net/phy/sfp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 2ec91466acdf..6bbb02117217 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -432,6 +432,19 @@ static void sfp_fixup_rollball_wait4s(struct sfp *sfp) sfp->module_t_wait = msecs_to_jiffies(4000); } +static void sfp_fixup_xikestor_2_5g(struct sfp *sfp) +{ + sfp_fixup_rollball(sfp); + + /* This module does not immediately respond to Rollball commands. Add + * a small delay to avoid unnecessary PHY access attempts. Note that + * the delay should not be too long, as the RTL8221B-VB-CG PHY inside + * breaks when reading some registers from MMD 30 if it has already + * established a link (which takes about 4 seconds after reset). + */ + sfp->module_t_wait = msecs_to_jiffies(1000); +} + static void sfp_fixup_fs_10gt(struct sfp *sfp) { sfp_fixup_10gbaset_30m(sfp); @@ -636,6 +649,8 @@ static const struct sfp_quirk sfp_quirks[] = { SFP_QUIRK_F("Turris", "RTSFP-10", sfp_fixup_rollball), SFP_QUIRK_F("Turris", "RTSFP-10G", sfp_fixup_rollball), + SFP_QUIRK_F("XikeStor", "SKT-2.5G-100M", sfp_fixup_xikestor_2_5g), + SFP_QUIRK_S("ZOERAX", "SFP-2.5G-T", sfp_quirk_oem_2_5g), }; From 0a2de6c7cdedcf9fb7622888a2715cd94aca7773 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Mon, 21 Sep 2026 13:04:22 +0200 Subject: [PATCH 0723/2126] dt-bindings: net: nvidia,tegra234-mgbe: Add missing properties Being a DWMAC derivative, the Tegra234 MGBE supports AXI configuration nodes named stmmac-axi-config and phandle references to them using the snps,axi-config property. While at it, add the 10gbase-r PHY mode. Reviewed-by: Rob Herring (Arm) Signed-off-by: Thierry Reding Link: https://patch.msgid.link/20260921110422.220832-1-thierry.reding@kernel.org Signed-off-by: Jakub Kicinski --- .../bindings/net/nvidia,tegra234-mgbe.yaml | 8 ++- .../bindings/net/snps,dwmac-common.yaml | 66 +++++++++++++++++++ .../devicetree/bindings/net/snps,dwmac.yaml | 52 +-------------- 3 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/snps,dwmac-common.yaml diff --git a/Documentation/devicetree/bindings/net/nvidia,tegra234-mgbe.yaml b/Documentation/devicetree/bindings/net/nvidia,tegra234-mgbe.yaml index 215f14d1897d..48e4798a039b 100644 --- a/Documentation/devicetree/bindings/net/nvidia,tegra234-mgbe.yaml +++ b/Documentation/devicetree/bindings/net/nvidia,tegra234-mgbe.yaml @@ -81,8 +81,9 @@ properties: phy-mode: contains: enum: - - usxgmii - 10gbase-kr + - 10gbase-r + - usxgmii mdio: $ref: mdio.yaml# @@ -90,6 +91,9 @@ properties: description: Optional node for embedded MDIO controller. +allOf: + - $ref: snps,dwmac-common.yaml# + required: - compatible - reg @@ -103,7 +107,7 @@ required: - phy-handle - phy-mode -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/net/snps,dwmac-common.yaml b/Documentation/devicetree/bindings/net/snps,dwmac-common.yaml new file mode 100644 index 000000000000..a38ff314b3cd --- /dev/null +++ b/Documentation/devicetree/bindings/net/snps,dwmac-common.yaml @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/snps,dwmac-common.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Synopsys DesignWare MAC common properties + +maintainers: + - Alexandre Torgue + - Giuseppe Cavallaro + - Jose Abreu + +properties: + stmmac-axi-config: + type: object + unevaluatedProperties: false + description: + AXI BUS Mode parameters. + + properties: + snps,lpi_en: + $ref: /schemas/types.yaml#/definitions/flag + description: + enable Low Power Interface + + snps,xit_frm: + $ref: /schemas/types.yaml#/definitions/flag + description: + unlock on WoL + + snps,wr_osr_lmt: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + max write outstanding req. limit + + snps,rd_osr_lmt: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + max read outstanding req. limit + + snps,blen: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + this is a vector of supported burst length. + minItems: 7 + maxItems: 7 + + snps,fb: + $ref: /schemas/types.yaml#/definitions/flag + description: + fixed-burst + + snps,axi-config: + $ref: /schemas/types.yaml#/definitions/phandle + description: + AXI BUS Mode parameters. Phandle to a node that can contain the + following properties + * snps,lpi_en, enable Low Power Interface + * snps,xit_frm, unlock on WoL + * snps,wr_osr_lmt, max write outstanding req. limit + * snps,rd_osr_lmt, max read outstanding req. limit + * snps,blen, this is a vector of supported burst length. + * snps,fb, fixed-burst + +additionalProperties: true diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml index 0ff9e3284a06..d3e591157faf 100644 --- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml +++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml @@ -196,18 +196,6 @@ properties: can be passive (no SW requirement), and requires that the MAC operate in a different mode than the PHY in order to function. - snps,axi-config: - $ref: /schemas/types.yaml#/definitions/phandle - description: - AXI BUS Mode parameters. Phandle to a node that can contain the - following properties - * snps,lpi_en, enable Low Power Interface - * snps,xit_frm, unlock on WoL - * snps,wr_osr_lmt, max write outstanding req. limit - * snps,rd_osr_lmt, max read outstanding req. limit - * snps,blen, this is a vector of supported burst length. - * snps,fb, fixed-burst - snps,mtl-rx-config: $ref: /schemas/types.yaml#/definitions/phandle description: @@ -559,45 +547,6 @@ properties: required: - compatible - stmmac-axi-config: - type: object - unevaluatedProperties: false - description: - AXI BUS Mode parameters. - - properties: - snps,lpi_en: - $ref: /schemas/types.yaml#/definitions/flag - description: - enable Low Power Interface - - snps,xit_frm: - $ref: /schemas/types.yaml#/definitions/flag - description: - unlock on WoL - - snps,wr_osr_lmt: - $ref: /schemas/types.yaml#/definitions/uint32 - description: - max write outstanding req. limit - - snps,rd_osr_lmt: - $ref: /schemas/types.yaml#/definitions/uint32 - description: - max read outstanding req. limit - - snps,blen: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: - this is a vector of supported burst length. - minItems: 7 - maxItems: 7 - - snps,fb: - $ref: /schemas/types.yaml#/definitions/flag - description: - fixed-burst - required: - compatible - reg @@ -611,6 +560,7 @@ dependencies: allOf: - $ref: ethernet-controller.yaml# + - $ref: snps,dwmac-common.yaml# - if: properties: compatible: From 6f5021d32914a99c0a7df8f0fc9c4605f43ae3f4 Mon Sep 17 00:00:00 2001 From: Aryan Sinha Date: Sun, 20 Sep 2026 17:58:02 +0530 Subject: [PATCH 0724/2126] octeontx2-af: remove duplicate SCTP port flags proto_flags ORs BIT_ULL(NPC_SPORT_SCTP) and BIT_ULL(NPC_DPORT_SCTP) twice. The second pair is redundant and does not change the mask. Drop it. Signed-off-by: Aryan Sinha Reviewed-by: Geetha sowjanya Link: https://patch.msgid.link/20260920122803.6277-1-sinha.aryan03@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c index d422bdd5e8f8..ec004ea5154c 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c @@ -698,7 +698,6 @@ static void npc_set_features(struct rvu *rvu, int blkaddr, u8 intf) proto_flags = BIT_ULL(NPC_SPORT_TCP) | BIT_ULL(NPC_SPORT_UDP) | BIT_ULL(NPC_DPORT_TCP) | BIT_ULL(NPC_DPORT_UDP) | BIT_ULL(NPC_SPORT_SCTP) | BIT_ULL(NPC_DPORT_SCTP) | - BIT_ULL(NPC_SPORT_SCTP) | BIT_ULL(NPC_DPORT_SCTP) | BIT_ULL(NPC_TYPE_ICMP) | BIT_ULL(NPC_CODE_ICMP) | BIT_ULL(NPC_TCP_FLAGS); From dbb8d2dc0d2f3b7b64a8384db124e0fdc01fea10 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sun, 20 Sep 2026 21:48:30 -0700 Subject: [PATCH 0725/2126] docs: ABI: OCP TimeCard: use literal blocks for commands Use literal blocks for 'echo' commands to separate them from the surrounding text. Otherwise the lines run together, without any clear break before or after the commands. Signed-off-by: Randy Dunlap Link: https://patch.msgid.link/20260921044830.95981-1-rdunlap@infradead.org Signed-off-by: Jakub Kicinski --- Documentation/ABI/testing/sysfs-timecard | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-timecard b/Documentation/ABI/testing/sysfs-timecard index 4ba45c6ee4a3..a0b7172851d4 100644 --- a/Documentation/ABI/testing/sysfs-timecard +++ b/Documentation/ABI/testing/sysfs-timecard @@ -185,9 +185,11 @@ Description: (RW) Used to start the signal generator, and summarize period [duty [phase [polarity]]] - echo 500000000 > signal # 1/2 second period - echo 1000000 40 100 > signal - echo 0 > signal # turn off generator + :: + + echo 500000000 > signal # 1/2 second period + echo 1000000 40 100 > signal + echo 0 > signal # turn off generator Period and phase are specified in nanoseconds. Duty cycle is a percentage from 1-99. Polarity is 1 or 0. From 63182028f38b703d3c28e18aacf262dc7e4de866 Mon Sep 17 00:00:00 2001 From: Narcisa Vasile Date: Mon, 21 Sep 2026 13:11:45 -0700 Subject: [PATCH 0726/2126] selftests: drv-net: add BIG TCP coverage to TSO test Add IPv4 and IPv6 test cases that exercise GSO packets under BIG TCP size limits. 1..2 ok 1 tso.big_tcp_ipv4 ok 2 tso.big_tcp_ipv6 Both of them run the existing tx-tcp-segmentation and tx-tcp6-segmentation tests at the increased TSO maximum. Additionally, reserve a hugepage and transmit its content using MSG_ZEROCOPY to produce skb fragments larger than 65536. Check that the number of retransmissions represents a small percentage of the total packets sent. Record the number of drops before and after the send to catch issues with large frag handling during segmentation. Signed-off-by: Narcisa Vasile Acked-by: Petr Vorel Link: https://patch.msgid.link/20260921201145.49875-1-narcisav.kernel@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hw/tso.py | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/tools/testing/selftests/drivers/net/hw/tso.py b/tools/testing/selftests/drivers/net/hw/tso.py index 67f6c9ca9a64..176ddf97fabb 100755 --- a/tools/testing/selftests/drivers/net/hw/tso.py +++ b/tools/testing/selftests/drivers/net/hw/tso.py @@ -4,6 +4,7 @@ """A simple test for TSO.""" import fcntl +import mmap import socket import struct import termios @@ -15,6 +16,87 @@ from lib.py import EthtoolFamily, NetdevFamily, NetDrvEpEnv from lib.py import bkg, cmd, defer, ethtool, ip, rand_port, wait_port_listen +MAP_HUGETLB = getattr(mmap, "MAP_HUGETLB", 0x40000) +MSG_ZEROCOPY = getattr(socket, "MSG_ZEROCOPY", 0x4000000) +SO_ZEROCOPY = getattr(socket, "SO_ZEROCOPY", 60) + +GSO_LEGACY_MAX_SIZE = 65536 + +# Pool of the default hugepage size, the one /proc/meminfo reports on. +NR_HUGEPAGES = "/proc/sys/vm/nr_hugepages" + + +def default_huge_page_size(): + """Return the hugepage size in bytes""" + try: + with open("/proc/meminfo", encoding="utf-8") as meminfo: + for line in meminfo: + if line.startswith("Hugepagesize:"): + return int(line.split()[1]) * 1024 + except OSError: + pass + + return 2 * 1024 * 1024 + + +def hugepages_free(): + """Return the number of unused hugepages of the default size.""" + try: + with open("/proc/meminfo", encoding="utf-8") as meminfo: + for line in meminfo: + if line.startswith("HugePages_Free:"): + return int(line.split()[1]) + except OSError: + pass + return 0 + + +def set_nr_hugepages(count): + with open(NR_HUGEPAGES, "w", encoding="utf-8") as sysctl: + sysctl.write(f"{count}\n") + + +def tx_dropped(ifname): + with open(f"/sys/class/net/{ifname}/statistics/tx_dropped", + encoding="utf-8") as counter: + return int(counter.read()) + + +def setup_hugepage(): + """Reserve one hugepage, and put the pool back afterwards.""" + if hugepages_free() >= 1: + return + + try: + with open(NR_HUGEPAGES, encoding="utf-8") as sysctl: + old_count = int(sysctl.read()) + set_nr_hugepages(old_count + 1) + except OSError as error: + raise KsftSkipEx(f"Unable to reserve a hugepage: {error}") from error + + defer(set_nr_hugepages, old_count) + + if hugepages_free() < 1: + raise KsftSkipEx("Unable to reserve a hugepage") + + +def mmap_large_buffer(): + """Allocate a buffer backed by one huge page.""" + size = default_huge_page_size() + + setup_hugepage() + + try: + return mmap.mmap(-1, size, + flags=mmap.MAP_PRIVATE | + mmap.MAP_ANONYMOUS | + MAP_HUGETLB, + prot=mmap.PROT_READ) + except OSError as e: + raise KsftSkipEx(f"Unable to allocate a {size >> 20}MB hugepage " + f"buffer: {e}") from e + + def sock_wait_drain(sock, max_wait=1000): """Wait for all pending write data on the socket to get ACKed.""" for _ in range(max_wait): @@ -33,6 +115,32 @@ def tcp_sock_get_retrans(sock): return struct.unpack("I", info[100:104])[0] +def setup_big_tcp(cfg): + """Lift the GSO ceiling to what the device advertises for TSO.""" + if cfg.dev["tso_max_size"] <= GSO_LEGACY_MAX_SIZE: + raise KsftSkipEx("Device does not support BIG TCP") + + ip(f"link set dev {cfg.ifname} " + f"gso_max_size {cfg.dev['tso_max_size']} " + f"gso_ipv4_max_size {cfg.dev['tso_max_size']}") + + defer(ip, f"link set dev {cfg.ifname} " + f"gso_max_size {cfg.dev['gso_max_size']} " + f"gso_ipv4_max_size {cfg.dev['gso_ipv4_max_size']}") + + +def sock_send_zerocopy(sock): + """Send with MSG_ZEROCOPY, return the bytes queued.""" + try: + sock.setsockopt(socket.SOL_SOCKET, SO_ZEROCOPY, 1) + except OSError as e: + raise KsftSkipEx(f"SO_ZEROCOPY not supported: {e}") from e + + with mmap_large_buffer() as tx_buf: + sock.sendall(tx_buf, MSG_ZEROCOPY) + return len(tx_buf) + + def run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso): cfg.require_cmd("socat", local=False, remote=True) @@ -96,6 +204,46 @@ def run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso): 500, comment="Number of LSO wire-packets with LSO disabled") +def run_big_tcp_stream(cfg, ipver, remote_v4, remote_v6): + """Send with MSG_ZEROCOPY out of a huge page, so the frags exceed 64kB.""" + cfg.require_cmd("socat", local=False, remote=True) + + # No clamping, as it would keep the frags under 64kB + port = rand_port() + listen_opts = f"{port},reuseport" + listen_cmd = f"socat -{ipver} -t 2 -u TCP-LISTEN:{listen_opts} /dev/null,ignoreeof" + + with bkg(listen_cmd, host=cfg.remote, exit_wait=True): + wait_port_listen(port, host=cfg.remote) + + if ipver == "4": + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((remote_v4, port)) + else: + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + sock.connect((remote_v6, port)) + + # Small send to make sure the connection is working. + sock.send("ping".encode()) + sock_wait_drain(sock) + + retrans_old = tcp_sock_get_retrans(sock) + drops_old = tx_dropped(cfg.ifname) + + sent = sock_send_zerocopy(sock) + sock_wait_drain(sock) + + drops = tx_dropped(cfg.ifname) - drops_old + retrans = tcp_sock_get_retrans(sock) - retrans_old + sock.close() + + ksft_eq(drops, 0, comment="Driver TX drops during BIG TCP send") + + # Same best effort bound as the plain stream. + total_lso_wire = sent * 0.90 // cfg.dev["mtu"] + ksft_lt(retrans, total_lso_wire / 16) + + def build_tunnel(cfg, outer_ipver, tun_info): local_v4 = NetDrvEpEnv.nsim_v4_pfx + "1" local_v6 = NetDrvEpEnv.nsim_v6_pfx + "1" @@ -147,6 +295,11 @@ def test_builder(name, cfg, outer_ipver, feature, tun=None, inner_ipver=None): if feature not in cfg.hw_features: raise KsftSkipEx(f"Device does not support {feature}") + # Run non-tunnel test cases under the BIG TCP limits too. + big_tcp = "big_tcp" in name + if big_tcp: + setup_big_tcp(cfg) + ipver = outer_ipver if tun: remote_v4, remote_v6 = build_tunnel(cfg, ipver, tun) @@ -159,6 +312,9 @@ def test_builder(name, cfg, outer_ipver, feature, tun=None, inner_ipver=None): ethtool(f"-K {cfg.ifname} {feature} off") run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso=False) + if big_tcp: + run_big_tcp_stream(cfg, ipver, remote_v4, remote_v6) + ethtool(f"-K {cfg.ifname} tx-gso-partial off") ethtool(f"-K {cfg.ifname} tx-tcp-mangleid-segmentation off") if feature in cfg.partial_features: @@ -171,6 +327,9 @@ def test_builder(name, cfg, outer_ipver, feature, tun=None, inner_ipver=None): ethtool(f"-K {cfg.ifname} {feature} on") run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso=True) + if big_tcp: + run_big_tcp_stream(cfg, ipver, remote_v4, remote_v6) + f.__name__ = name + ((outer_ipver + "_") if tun else "") + "ipv" + inner_ipver return f @@ -230,6 +389,8 @@ def main() -> None: # name, v4/v6 ethtool_feature tun:(type, args, inner ip versions) ("", "4", "tx-tcp-segmentation", None), ("", "6", "tx-tcp6-segmentation", None), + ("big_tcp_", "4", "tx-tcp-segmentation", None), + ("big_tcp_", "6", "tx-tcp6-segmentation", None), ("vxlan", "4", "tx-udp_tnl-segmentation", ("vxlan", "id 100 dstport 4789 noudpcsum", ("4", "6"))), ("vxlan", "6", "tx-udp_tnl-segmentation", ("vxlan", "id 100 dstport 4789 udp6zerocsumtx udp6zerocsumrx", ("4", "6"))), ("vxlan_csum", "", "tx-udp_tnl-csum-segmentation", ("vxlan", "id 100 dstport 4789 udpcsum", ("4", "6"))), From 528de6832b2194ae0b1d62b0925e0ac6cad1087c Mon Sep 17 00:00:00 2001 From: Hui Peng Date: Sat, 19 Sep 2026 21:06:24 +0000 Subject: [PATCH 0727/2126] net/sched: ematch: check nla_put_nohdr() return value in tcf_em_tree_dump() When tcf_em_tree_dump() was converted from the legacy rtnetlink `RTA_PUT_NOHDR` macro (which contained an implicit `goto rtattr_failure;`) to `nla_put_nohdr()`, the return value check on `nla_put_nohdr()` was omitted for container/simple matches and raw match payloads. If the netlink dump skb runs out of tailroom at `nla_put_nohdr()`, the error is silently ignored and `match_start->nla_len` is finalized without the match payload, emitting a malformed/truncated TCA_EMATCH_TREE_LIST attribute to userspace instead of returning `-1` via `nla_put_failure` so rtnetlink can reallocate and retry the dump. Check the return value of `nla_put_nohdr()` in both branches and jump to `nla_put_failure` on error. Cc: stable+noautosel@kernel.org # never worked Signed-off-by: Hui Peng Link: https://patch.msgid.link/20260919210624.3030344-1-benquike@gmail.com Signed-off-by: Jakub Kicinski --- net/sched/ematch.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/sched/ematch.c b/net/sched/ematch.c index 5c1235e6076a..a8e06cf053c9 100644 --- a/net/sched/ematch.c +++ b/net/sched/ematch.c @@ -470,9 +470,12 @@ int tcf_em_tree_dump(struct sk_buff *skb, struct tcf_ematch_tree *tree, int tlv) goto nla_put_failure; } else if (tcf_em_is_container(em) || tcf_em_is_simple(em)) { u32 u = em->data; - nla_put_nohdr(skb, sizeof(u), &u); - } else if (em->datalen > 0) - nla_put_nohdr(skb, em->datalen, (void *) em->data); + if (nla_put_nohdr(skb, sizeof(u), &u)) + goto nla_put_failure; + } else if (em->datalen > 0) { + if (nla_put_nohdr(skb, em->datalen, (void *)em->data)) + goto nla_put_failure; + } tail = skb_tail_pointer(skb); match_start->nla_len = tail - (u8 *)match_start; From 6516ac5e6b164bf78fb34d36b4d84d495a07c844 Mon Sep 17 00:00:00 2001 From: Nathan Gao Date: Thu, 17 Sep 2026 21:50:21 -0700 Subject: [PATCH 0728/2126] selftests/net: packetdrill: check rcv_ssthresh vs scaling_ratio changes tcp_measure_rcv_mss() recomputes tp->scaling_ratio from skb->len/skb->truesize and updates tp->window_clamp accordingly. Commit f5da7c45188e ("tcp: adjust rcvq_space after updating scaling ratio") made that update go through tcp_set_window_clamp(), which also shrinks tp->rcv_ssthresh, so every scaling_ratio dip cut the advertised window as well. Commit 0e125ecfe20c ("tcp: do not change rcv_ssthresh in tcp_measure_rcv_mss()") restored the plain window_clamp update. Add a packetdrill test for it, as suggested during the review of that fix. A fixed SO_RCVBUF pins sk_rcvbuf, so window_clamp can only move when scaling_ratio does, and the peer announces TCP_MIN_MSS so that icsk_ack.rcv_mss sits at its 88 byte floor. A single 89 byte segment is then measured, and 89 bytes of payload in a ~900 byte skb is far below the 50% that TCP_DEFAULT_SCALING_RATIO assumes, so scaling_ratio and window_clamp drop sharply. Nothing puts the socket under memory pressure, so rcv_ssthresh must not move at all. The test checks the state it depends on instead of assuming it. tcp_measure_rcv_mss() only measures segments of at least rcv_mss bytes, so rcv_mss is checked to be 88 before the segment is sent. It is checked to be 89 afterwards, because rcv_mss is only updated by the same code that recomputes scaling_ratio, so this proves the segment was measured. rcv_ssthresh is compared against the value it had right after the handshake, not against a fixed number, so the test does not depend on the receive buffer size or on how the architecture accounts skb memory. Verified on net-next, where it passes for ipv4, ipv6 and ipv4-mapped-ipv6, and on the same tree with the fix reverted, where it fails in all three modes with rcv_ssthresh cut from 260684 to 51200. Signed-off-by: Nathan Gao Link: https://patch.msgid.link/20260918045021.42138-1-zcgao@amazon.com Signed-off-by: Paolo Abeni --- .../tcp_rcv_ssthresh_scaling_ratio.pkt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_ssthresh_scaling_ratio.pkt diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_ssthresh_scaling_ratio.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_ssthresh_scaling_ratio.pkt new file mode 100644 index 000000000000..f99ecb8a224f --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_ssthresh_scaling_ratio.pkt @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 +// tcp_measure_rcv_mss() lowers tp->window_clamp when a segment carries less +// payload per byte of memory than the ratio it had assumed. Test that it does +// not lower tp->rcv_ssthresh as well: rcv_ssthresh is cut back under +// memory pressure, and it only grows back slowly, through tcp_grow_window(). + +--mss=1000 + +`./defaults.sh` + +// A fixed SO_RCVBUF keeps sk_rcvbuf from moving, so window_clamp can only +// change when the ratio does. The MSS of 88 (TCP_MIN_MSS) is the smallest +// segment size TCP will measure, and window scaling lets rcv_ssthresh start +// well above 64 KB. The window the peer announces does not matter here, this +// side never sends data. + +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 + +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [262144], 4) = 0 + +0 bind(3, ..., ...) = 0 + +0 listen(3, 1) = 0 + + +0 < S 0:0(0) win 65535 + +0 > S. 0:0(0) ack 1 <...> + +.1 < . 1:1(0) ack 1 win 65535 + + +0 accept(3, ..., ...) = 4 + +// Only segments of at least rcv_mss bytes are measured. Note it down, along +// with the rcv_ssthresh the connection starts with. + +0 %{ +assert tcpi_rcv_mss == 88, tcpi_rcv_mss +ssthresh_0 = tcpi_rcv_ssthresh +}% + +// One segment, one byte above that threshold. 89 bytes of payload sit in an +// skb of about 900 bytes, far below the 50% ratio TCP assumes by default, so +// window_clamp drops sharply. + +0 < P. 1:90(89) ack 1 win 65535 + +0 > . 1:1(0) ack 90 + +// rcv_mss is only updated by the code that recomputes the ratio, so 89 here +// means the segment was measured. rcv_ssthresh must have been left alone. + +0 %{ +assert tcpi_rcv_mss == 89, tcpi_rcv_mss +assert tcpi_rcv_ssthresh >= ssthresh_0, (tcpi_rcv_ssthresh, ssthresh_0) +}% From 1c85ea5df86bed136589a2866c22f394020d3fdf Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Tue, 22 Sep 2026 12:53:28 -0700 Subject: [PATCH 0729/2126] eth: fbnic: put back netmem reference when xdp_buff_add_frag() fails fbnic_add_rx_frag() takes a page_pool reference out of the buffer's pagecnt_bias before handing the fragment to xdp_buff_add_frag(). If that call fails it has not taken ownership of the netmem: the fragment is not recorded in the shared info, and fbnic_put_pkt_buff() will not put the reference back. Put the netmem reference back on the failure path. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260922-fbnic-refcount-fix-v1-1-31e5862c9893@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index 447ec5522499..bbc3c9e89a38 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -1045,6 +1045,7 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, pkt->add_frag_failed = true; netdev_err_once(nv->napi.dev, "Failed to add fragment to xdp_buff\n"); + page_pool_put_full_netmem(qt->sub1.page_pool, netmem, true); } } From d3630df401a8ee91117db26b14a64520aa44fbdb Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Fri, 18 Sep 2026 11:25:27 +0000 Subject: [PATCH 0730/2126] selftests: drv-net: Move _set_ethtool_feat() into lib Move the _set_ethtool_feat() helper from gro_lib.py into lib, so that it can be reused by the VLAN test added in the next commit. Drop the leading underscore, now that the helper is exported. Signed-off-by: Ovidiu Panait Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260918112529.96039-2-ovidiu.panait.rb@renesas.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/gro_lib.py | 65 ++++++------------- .../drivers/net/hw/lib/py/__init__.py | 3 +- .../selftests/drivers/net/lib/py/__init__.py | 3 +- .../selftests/drivers/net/lib/py/feat.py | 35 ++++++++++ 4 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/lib/py/feat.py diff --git a/tools/testing/selftests/drivers/net/gro_lib.py b/tools/testing/selftests/drivers/net/gro_lib.py index abecf60baa53..7856ebdd49d3 100644 --- a/tools/testing/selftests/drivers/net/gro_lib.py +++ b/tools/testing/selftests/drivers/net/gro_lib.py @@ -52,7 +52,7 @@ import re from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_eq from lib.py import NetDrvEpEnv, KsftFailEx, KsftSkipEx, KsftXfailEx from lib.py import NetdevFamily, EthtoolFamily -from lib.py import bkg, cmd, ctl_file_write, defer, ethtool, ip +from lib.py import bkg, cmd, ctl_file_write, defer, ethtool, ip, set_ethtool_feat from lib.py import ksft_variants, KsftNamedVariant @@ -125,31 +125,6 @@ def _set_gro_size_restore(cfg, size): comment="gro_ipv4_max_size not applied") -def _set_ethtool_feat(dev, current, feats, host=None): - s2n = {True: "on", False: "off"} - - new = ["-K", dev] - old = ["-K", dev] - no_change = True - for name, state in feats.items(): - new += [name, s2n[state]] - old += [name, s2n[current[name]["active"]]] - - if current[name]["active"] != state: - no_change = False - if current[name]["fixed"]: - raise KsftXfailEx(f"Device does not support {name}") - if no_change: - return - - eth_cmd = ethtool(" ".join(new), host=host) - defer(ethtool, " ".join(old), host=host) - - # If ethtool printed something kernel must have modified some features - if eth_cmd.stdout: - ksft_pr(eth_cmd) - - def _get_queue_stats(cfg, queue_id): """Get stats for a specific Rx queue.""" cfg.wait_hw_stats_settle() @@ -280,15 +255,15 @@ def _setup(cfg, mode, test_name): ctl_file_write(flush_path, "200000") ctl_file_write(irq_path, "10") - _set_ethtool_feat(cfg.ifname, cfg.feat, - {"generic-receive-offload": True, - "rx-gro-hw": False, - "large-receive-offload": False}) + set_ethtool_feat(cfg.ifname, cfg.feat, + {"generic-receive-offload": True, + "rx-gro-hw": False, + "large-receive-offload": False}) elif mode == "hw": - _set_ethtool_feat(cfg.ifname, cfg.feat, - {"generic-receive-offload": False, - "rx-gro-hw": True, - "large-receive-offload": False}) + set_ethtool_feat(cfg.ifname, cfg.feat, + {"generic-receive-offload": False, + "rx-gro-hw": True, + "large-receive-offload": False}) # Some NICs treat HW GRO as a GRO sub-feature so disabling GRO # will also clear HW GRO. Use a hack of installing XDP generic @@ -303,27 +278,27 @@ def _setup(cfg, mode, test_name): # Attaching XDP may change features, fetch the latest state feat = ethtool(f"-k {cfg.ifname}", json=True)[0] - _set_ethtool_feat(cfg.ifname, feat, - {"generic-receive-offload": True, - "rx-gro-hw": True, - "large-receive-offload": False}) + set_ethtool_feat(cfg.ifname, feat, + {"generic-receive-offload": True, + "rx-gro-hw": True, + "large-receive-offload": False}) elif mode == "lro": # netdevsim advertises LRO for feature inheritance testing with # bonding/team tests but it doesn't actually perform the offload cfg.require_nsim(nsim_test=False) - _set_ethtool_feat(cfg.ifname, cfg.feat, - {"generic-receive-offload": False, - "rx-gro-hw": False, - "large-receive-offload": True}) + set_ethtool_feat(cfg.ifname, cfg.feat, + {"generic-receive-offload": False, + "rx-gro-hw": False, + "large-receive-offload": True}) try: # Disable TSO for local tests cfg.require_nsim() # will raise KsftXfailEx if not running on nsim - _set_ethtool_feat(cfg.remote_ifname, cfg.remote_feat, - {"tcp-segmentation-offload": False}, - host=cfg.remote) + set_ethtool_feat(cfg.remote_ifname, cfg.remote_feat, + {"tcp-segmentation-offload": False}, + host=cfg.remote) except KsftXfailEx: pass diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py index 81e1d1865cd5..4077f5f1a1be 100644 --- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py @@ -31,6 +31,7 @@ try: ksft_setup, ksft_variants, KsftNamedVariant from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \ ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none + from drivers.net.lib.py import set_ethtool_feat from drivers.net.lib.py import GenerateTraffic, Remote, Iperf3Runner from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv @@ -49,7 +50,7 @@ try: "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt", "ksft_not_none", "ksft_not_none", "NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic", - "Remote", "Iperf3Runner"] + "Remote", "Iperf3Runner", "set_ethtool_feat"] except ModuleNotFoundError as e: print("Failed importing `net` library from kernel sources") print(str(e)) diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools/testing/selftests/drivers/net/lib/py/__init__.py index 591b1e6c7eea..40ccdcf0c378 100644 --- a/tools/testing/selftests/drivers/net/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py @@ -48,11 +48,12 @@ try: "ksft_not_none", "ksft_not_none"] from .env import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv + from .feat import set_ethtool_feat from .load import GenerateTraffic, Iperf3Runner from .remote import Remote __all__ += ["NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic", - "Remote", "Iperf3Runner"] + "Remote", "Iperf3Runner", "set_ethtool_feat"] except ModuleNotFoundError as e: print("Failed importing `net` library from kernel sources") print(str(e)) diff --git a/tools/testing/selftests/drivers/net/lib/py/feat.py b/tools/testing/selftests/drivers/net/lib/py/feat.py new file mode 100644 index 000000000000..b94a24214e59 --- /dev/null +++ b/tools/testing/selftests/drivers/net/lib/py/feat.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 + +""" +Netdev feature helper utilities for kernel selftests. + +Provides common operations for changing device features via ethtool. +""" + +from . import KsftXfailEx, defer, ethtool, ksft_pr + + +def set_ethtool_feat(dev, current, feats, host=None): + """Set ethtool features with defer to restore original state.""" + s2n = {True: "on", False: "off"} + + new = ["-K", dev] + old = ["-K", dev] + no_change = True + for name, state in feats.items(): + new += [name, s2n[state]] + old += [name, s2n[current[name]["active"]]] + + if current[name]["active"] != state: + no_change = False + if current[name]["fixed"]: + raise KsftXfailEx(f"Device does not support {name}") + if no_change: + return + + eth_cmd = ethtool(" ".join(new), host=host) + defer(ethtool, " ".join(old), host=host) + + # If ethtool printed something kernel must have modified some features + if eth_cmd.stdout: + ksft_pr(eth_cmd) From a57ddd89900480dc90fd9f553f7f71a8e875bf67 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Fri, 18 Sep 2026 11:25:28 +0000 Subject: [PATCH 0731/2126] selftests: drv-net: Check the features set by set_ethtool_feat() Read back the features after running ethtool -K to check if they were actually applied. The drivers might refuse to set a feature silently and the test could run with a different configuration than the requested one. Add a 'check' parameter to skip this, as the GRO "hw" mode handles the case where HW GRO is cleared by the driver. Signed-off-by: Ovidiu Panait Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260918112529.96039-3-ovidiu.panait.rb@renesas.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/gro_lib.py | 3 ++- tools/testing/selftests/drivers/net/lib/py/feat.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/gro_lib.py b/tools/testing/selftests/drivers/net/gro_lib.py index 7856ebdd49d3..875a715b2ae1 100644 --- a/tools/testing/selftests/drivers/net/gro_lib.py +++ b/tools/testing/selftests/drivers/net/gro_lib.py @@ -263,7 +263,8 @@ def _setup(cfg, mode, test_name): set_ethtool_feat(cfg.ifname, cfg.feat, {"generic-receive-offload": False, "rx-gro-hw": True, - "large-receive-offload": False}) + "large-receive-offload": False}, + check=False) # Some NICs treat HW GRO as a GRO sub-feature so disabling GRO # will also clear HW GRO. Use a hack of installing XDP generic diff --git a/tools/testing/selftests/drivers/net/lib/py/feat.py b/tools/testing/selftests/drivers/net/lib/py/feat.py index b94a24214e59..f0630844f023 100644 --- a/tools/testing/selftests/drivers/net/lib/py/feat.py +++ b/tools/testing/selftests/drivers/net/lib/py/feat.py @@ -9,7 +9,7 @@ Provides common operations for changing device features via ethtool. from . import KsftXfailEx, defer, ethtool, ksft_pr -def set_ethtool_feat(dev, current, feats, host=None): +def set_ethtool_feat(dev, current, feats, host=None, check=True): """Set ethtool features with defer to restore original state.""" s2n = {True: "on", False: "off"} @@ -33,3 +33,11 @@ def set_ethtool_feat(dev, current, feats, host=None): # If ethtool printed something kernel must have modified some features if eth_cmd.stdout: ksft_pr(eth_cmd) + + if not check: + return + + current = ethtool(f"-k {dev}", json=True, host=host)[0] + for name, state in feats.items(): + if current[name]["active"] != state: + raise KsftXfailEx(f"{name} was not set to {s2n[state]}") From efc7f4646c1d4d45dd4cdab6a94275484e3287d0 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Fri, 18 Sep 2026 11:25:29 +0000 Subject: [PATCH 0732/2126] selftests: drv-net: Add VLAN test Add a test that validates ping traffic over VLAN interfaces. It aims to catch drivers which mishandle hardware VLAN tag stripping, in particular QinQ. Three VLAN configurations are covered, each with hardware RX VLAN stripping enabled and disabled (via the rx-vlan-offload and rx-vlan-stag-hw-parse features): - a single 802.1q VLAN interface - a single 802.1ad VLAN interface - an 802.1q VLAN stacked on top of an 802.1ad interface The "hw" test variants enable the RX VLAN stripping features supported by the device (rx-vlan-offload and rx-vlan-stag-hw-parse), the "sw" test variants disable all of them. A test is xfailed if the requested configuration is not possible. VLAN insertion offloads are not tested for now. NETIF=end0 LOCAL_V4=172.16.0.2 REMOTE_V4=172.16.0.3 \ REMOTE_TYPE=ssh REMOTE_ARGS=root@172.16.0.3 \ run_kselftest.sh -t drivers/net/hw:vlan.py TAP version 13 1..1 # timeout set to 0 # selftests: drivers/net/hw: vlan.py # # Interface: end0, driver: st_gmac # TAP version 13 # 1..6 # ok 1 vlan.test.8021q_hw # ok 2 vlan.test.8021q_sw # ok 3 vlan.test.8021ad_hw # ok 4 vlan.test.8021ad_sw # ok 5 vlan.test.qinq_hw # ok 6 vlan.test.qinq_sw # # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0 ok 1 selftests: drivers/net/hw: vlan.py # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Ovidiu Panait Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260918112529.96039-4-ovidiu.panait.rb@renesas.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/Makefile | 1 + tools/testing/selftests/drivers/net/hw/config | 1 + .../testing/selftests/drivers/net/hw/vlan.py | 127 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/vlan.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 8aebdc6feb17..18ce235a77f8 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -50,6 +50,7 @@ TEST_PROGS = \ tso.py \ userns_devmem.py \ uso.py \ + vlan.py \ xdp_metadata.py \ xsk_reconfig.py \ # diff --git a/tools/testing/selftests/drivers/net/hw/config b/tools/testing/selftests/drivers/net/hw/config index d89a9ba17655..c6c2b64bb712 100644 --- a/tools/testing/selftests/drivers/net/hw/config +++ b/tools/testing/selftests/drivers/net/hw/config @@ -24,5 +24,6 @@ CONFIG_NET_SCH_INGRESS=y CONFIG_SYNC_FILE=y CONFIG_UDMABUF=y CONFIG_USER_NS=y +CONFIG_VLAN_8021Q=m CONFIG_VXLAN=y CONFIG_XFRM_USER=y diff --git a/tools/testing/selftests/drivers/net/hw/vlan.py b/tools/testing/selftests/drivers/net/hw/vlan.py new file mode 100755 index 000000000000..00c90b930f67 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/vlan.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +VLAN tests. + +Validates that ping traffic is sent and received correctly over 802.1q +and 802.1ad VLAN interfaces, with hardware RX VLAN stripping enabled and +disabled on the local interface. + +The "hw" test variants enable the RX VLAN stripping features supported by +the device, the "sw" test variants disable all of them. A test is xfailed +if the requested configuration is not possible. + +Test cases: + - 8021q_hw: Traffic over a single 802.1q VLAN, HW stripping on + - 8021q_sw: Traffic over a single 802.1q VLAN, HW stripping off + - 8021ad_hw: Traffic over a single 802.1ad VLAN, HW stripping on + - 8021ad_sw: Traffic over a single 802.1ad VLAN, HW stripping off + - qinq_hw: Traffic over an 802.1q VLAN stacked on an 802.1ad VLAN, + HW stripping on + - qinq_sw: Traffic over an 802.1q VLAN stacked on an 802.1ad VLAN, + HW stripping off +""" + +import os + +from lib.py import ( + KsftNamedVariant, + KsftXfailEx, + NetDrvEpEnv, + cmd, + defer, + ethtool, + ip, + ksft_exit, + ksft_run, + ksft_variants, + set_ethtool_feat, +) + +OUTER_DEV = f"vlout{os.getpid()}" +INNER_DEV = f"vlin{os.getpid()}" + +OUTER_VID = 100 +INNER_VID = 200 + +LOCAL_IP = os.environ.get("VLAN_LOCAL_V4", "198.51.100.1") +REMOTE_IP = os.environ.get("VLAN_REMOTE_V4", "198.51.100.2") + + +def _vlan_add(base, name, proto, vid, host=None): + """Create a VLAN device on top of base and bring it up.""" + + ip(f"link add link {base} name {name} type vlan proto {proto} id {vid}", + host=host) + defer(ip, f"link del {name}", host=host) + ip(f"link set {name} up", host=host) + + +def _vlan_setup(base, addr, outer_proto, inner_proto, host=None): + """Create VLAN interfaces on base and set an IP on the innermost one.""" + + _vlan_add(base, OUTER_DEV, outer_proto, OUTER_VID, host=host) + if inner_proto: + _vlan_add(OUTER_DEV, INNER_DEV, inner_proto, INNER_VID, host=host) + + dev = INNER_DEV if inner_proto else OUTER_DEV + ip(f"addr add {addr}/24 dev {dev}", host=host) + + +def _setup(cfg, outer_proto, inner_proto, hw_strip): + """Configure VLAN stripping and create the VLAN interfaces.""" + + names = ["rx-vlan-offload"] + if outer_proto == "802.1ad": + names.append("rx-vlan-stag-hw-parse") + + feat = ethtool(f"-k {cfg.ifname}", json=True)[0] + feats = {} + for name in names: + # hw: skip the features the device does not support + # sw: request all of them off + if hw_strip and feat[name]["fixed"] and not feat[name]["active"]: + continue + feats[name] = hw_strip + + if hw_strip and not feats: + raise KsftXfailEx("Device does not support RX VLAN stripping") + + set_ethtool_feat(cfg.ifname, feat, feats) + + _vlan_setup(cfg.ifname, LOCAL_IP, outer_proto, inner_proto) + _vlan_setup(cfg.remote_ifname, REMOTE_IP, outer_proto, inner_proto, + host=cfg.remote) + + +def _vlan_variants(): + """Generator that yields the VLAN protocols and the stripping mode.""" + + yield KsftNamedVariant("8021q_hw", "802.1q", None, True) + yield KsftNamedVariant("8021q_sw", "802.1q", None, False) + yield KsftNamedVariant("8021ad_hw", "802.1ad", None, True) + yield KsftNamedVariant("8021ad_sw", "802.1ad", None, False) + yield KsftNamedVariant("qinq_hw", "802.1ad", "802.1q", True) + yield KsftNamedVariant("qinq_sw", "802.1ad", "802.1q", False) + + +@ksft_variants(_vlan_variants()) +def test(cfg, outer_proto, inner_proto, hw_strip): + """Run a single VLAN test""" + + _setup(cfg, outer_proto, inner_proto, hw_strip) + + cmd(f"ping -c 1 -W 5 {REMOTE_IP}") + + +def main() -> None: + """ Ksft boiler plate main """ + + with NetDrvEpEnv(__file__) as cfg: + ksft_run(cases=[test], args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main() From 7afc23c9884d0cc0e01ecae9638b6c566e09a947 Mon Sep 17 00:00:00 2001 From: Alessandro Zini Date: Sat, 19 Sep 2026 01:14:48 +0200 Subject: [PATCH 0733/2126] dt-bindings: net: microchip,lan8650: add reset-gpios property Add optional reset-gpios property to describe the connection to the hardware RESET_N pin of the LAN8650/1 MAC-PHY. Acked-by: Krzysztof Kozlowski Signed-off-by: Alessandro Zini Link: https://patch.msgid.link/20260918231450.55966-2-alessandro.zini@siemens.com Signed-off-by: Jakub Kicinski --- Documentation/devicetree/bindings/net/microchip,lan8650.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/net/microchip,lan8650.yaml b/Documentation/devicetree/bindings/net/microchip,lan8650.yaml index 766ff58147ae..1b543ce30763 100644 --- a/Documentation/devicetree/bindings/net/microchip,lan8650.yaml +++ b/Documentation/devicetree/bindings/net/microchip,lan8650.yaml @@ -40,6 +40,11 @@ properties: Event. maxItems: 1 + reset-gpios: + description: + GPIO connected to the active-low RESET_N pin of the MAC-PHY. + maxItems: 1 + spi-max-frequency: minimum: 15000000 maximum: 25000000 From 15358c2c3dca39d83fb372679daf9c79ac6fe9bb Mon Sep 17 00:00:00 2001 From: Alessandro Zini Date: Sat, 19 Sep 2026 01:14:49 +0200 Subject: [PATCH 0734/2126] net: ethernet: oa_tc6: return ERR_PTR from oa_tc6_init() oa_tc6_init() returns NULL on failure, so the reason for the failure is lost and both callers turn it into a plain -ENODEV. In preparation for acquiring an optional reset GPIO, which can return -EPROBE_DEFER when the GPIO provider is not available yet, the error code has to reach the driver core, otherwise the SPI device would never be probed again. Convert oa_tc6_init() to return an ERR_PTR on failure instead of NULL, and update the lan865x and adin1140 callers to check with IS_ERR() and propagate the error with PTR_ERR(). Signed-off-by: Alessandro Zini Link: https://patch.msgid.link/20260918231450.55966-3-alessandro.zini@siemens.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/adi/adin1140.c | 4 +-- .../net/ethernet/microchip/lan865x/lan865x.c | 4 +-- drivers/net/ethernet/oa_tc6.c | 27 ++++++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/adi/adin1140.c b/drivers/net/ethernet/adi/adin1140.c index 93710baca151..adc6e2ef44f8 100644 --- a/drivers/net/ethernet/adi/adin1140.c +++ b/drivers/net/ethernet/adi/adin1140.c @@ -725,8 +725,8 @@ static int adin1140_probe(struct spi_device *spi) tc6_quirks.quirk_flags = OA_TC6_BROKEN_PHY; priv->tc6 = oa_tc6_init(spi, netdev, &tc6_quirks); - if (!priv->tc6) - return -ENODEV; + if (IS_ERR(priv->tc6)) + return PTR_ERR(priv->tc6); ret = devm_add_action_or_reset(&spi->dev, adin1140_oa_tc6_remove, priv->tc6); diff --git a/drivers/net/ethernet/microchip/lan865x/lan865x.c b/drivers/net/ethernet/microchip/lan865x/lan865x.c index 26a2761332a5..127afb9e9f14 100644 --- a/drivers/net/ethernet/microchip/lan865x/lan865x.c +++ b/drivers/net/ethernet/microchip/lan865x/lan865x.c @@ -347,8 +347,8 @@ static int lan865x_probe(struct spi_device *spi) INIT_WORK(&priv->multicast_work, lan865x_multicast_work_handler); priv->tc6 = oa_tc6_init(spi, netdev, NULL); - if (!priv->tc6) { - ret = -ENODEV; + if (IS_ERR(priv->tc6)) { + ret = PTR_ERR(priv->tc6); goto free_netdev; } diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c index 6fcc5f561d56..8c82bc8354ed 100644 --- a/drivers/net/ethernet/oa_tc6.c +++ b/drivers/net/ethernet/oa_tc6.c @@ -1453,7 +1453,7 @@ static int oa_tc6_check_ctrl_protection(struct oa_tc6 *tc6) * @quirks: device specific modifiers for the OA TC6 protocol. * * Return: pointer reference to the oa_tc6 structure if the MAC-PHY - * initialization is successful otherwise NULL. + * initialization is successful otherwise an ERR_PTR. */ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev, struct oa_tc6_quirks *quirks) @@ -1463,7 +1463,7 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev, tc6 = devm_kzalloc(&spi->dev, sizeof(*tc6), GFP_KERNEL); if (!tc6) - return NULL; + return ERR_PTR(-ENOMEM); tc6->spi = spi; tc6->netdev = netdev; @@ -1476,60 +1476,61 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev, /* Set the SPI controller to pump at realtime priority */ tc6->spi->rt = true; - if (spi_setup(tc6->spi) < 0) - return NULL; + ret = spi_setup(tc6->spi); + if (ret < 0) + return ERR_PTR(ret); tc6->spi_ctrl_tx_buf = devm_kzalloc(&tc6->spi->dev, OA_TC6_CTRL_SPI_BUF_SIZE, GFP_KERNEL); if (!tc6->spi_ctrl_tx_buf) - return NULL; + return ERR_PTR(-ENOMEM); tc6->spi_ctrl_rx_buf = devm_kzalloc(&tc6->spi->dev, OA_TC6_CTRL_SPI_BUF_SIZE, GFP_KERNEL); if (!tc6->spi_ctrl_rx_buf) - return NULL; + return ERR_PTR(-ENOMEM); tc6->spi_data_tx_buf = devm_kzalloc(&tc6->spi->dev, OA_TC6_SPI_DATA_BUF_SIZE, GFP_KERNEL); if (!tc6->spi_data_tx_buf) - return NULL; + return ERR_PTR(-ENOMEM); tc6->spi_data_rx_buf = devm_kzalloc(&tc6->spi->dev, OA_TC6_SPI_DATA_BUF_SIZE, GFP_KERNEL); if (!tc6->spi_data_rx_buf) - return NULL; + return ERR_PTR(-ENOMEM); /* Check the PROTE bit status so that we can reset the device */ ret = oa_tc6_check_ctrl_protection(tc6); if (ret) { dev_err(&tc6->spi->dev, "Failed to check the protection mode: %d\n", ret); - return NULL; + return ERR_PTR(ret); } ret = oa_tc6_sw_reset_macphy(tc6); if (ret) { dev_err(&tc6->spi->dev, "MAC-PHY software reset failed: %d\n", ret); - return NULL; + return ERR_PTR(ret); } ret = oa_tc6_unmask_macphy_error_interrupts(tc6); if (ret) { dev_err(&tc6->spi->dev, "MAC-PHY error interrupts unmask failed: %d\n", ret); - return NULL; + return ERR_PTR(ret); } ret = oa_tc6_phy_init(tc6); if (ret) { dev_err(&tc6->spi->dev, "MAC internal PHY initialization failed: %d\n", ret); - return NULL; + return ERR_PTR(ret); } ret = oa_tc6_enable_data_transfer(tc6); @@ -1570,7 +1571,7 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev, phy_exit: oa_tc6_phy_exit(tc6); - return NULL; + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(oa_tc6_init); From 8d5dab574a9585817906bc214087ef29879a76b8 Mon Sep 17 00:00:00 2001 From: Alessandro Zini Date: Sat, 19 Sep 2026 01:14:50 +0200 Subject: [PATCH 0735/2126] net: ethernet: oa_tc6: add reset-gpios support OPEN Alliance 10BASE-T1x MAC-PHY Serial Interface specification (v1.1, section 8.2) defines an external RESET pin as an optional reset source for the MAC-PHY. Add support for an optional reset GPIO in oa_tc6_init(). The GPIO is requested asserted, kept asserted for 10 us and, once deasserted, 1 ms of settle time is allowed for the crystal oscillator startup before the initial TC6 control protection check and software reset are performed. As the reset handling lives in the common library, it is available to all MAC-PHY devices using oa_tc6_init() that provide an external reset pin. Suggested-by: Parthiban Veerasooran Signed-off-by: Alessandro Zini Link: https://patch.msgid.link/20260918231450.55966-4-alessandro.zini@siemens.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/oa_tc6.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c index 8c82bc8354ed..364027c39fa4 100644 --- a/drivers/net/ethernet/oa_tc6.c +++ b/drivers/net/ethernet/oa_tc6.c @@ -6,6 +6,8 @@ */ #include +#include +#include #include #include #include @@ -88,6 +90,7 @@ struct oa_tc6 { bool disable_traffic; bool prot_ctrl; enum oa_tc6_quirk_flag quirk_flags; + struct gpio_desc *reset_gpio; }; enum oa_tc6_header_type { @@ -1504,6 +1507,22 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev, if (!tc6->spi_data_rx_buf) return ERR_PTR(-ENOMEM); + tc6->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(tc6->reset_gpio)) + return ERR_PTR(dev_err_probe(&spi->dev, + PTR_ERR(tc6->reset_gpio), + "failed to get reset gpio\n")); + + if (tc6->reset_gpio) { + /* Keep the reset asserted for 10 us and then allow 1 ms of + * settle time for the crystal oscillator startup. + */ + fsleep(10); + gpiod_set_value_cansleep(tc6->reset_gpio, 0); + fsleep(1000); + } + /* Check the PROTE bit status so that we can reset the device */ ret = oa_tc6_check_ctrl_protection(tc6); if (ret) { From bf7c19e231e2f48cafddbe3f4c2a2f5b6184b55f Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:17:58 +0530 Subject: [PATCH 0736/2126] wifi: ath12k: move dp_profile_params to dp.h Move struct ath12k_dp_profile_params from core.h to dp.h as it is specifically used for Data Path operations. This improves code organization by keeping DP-related structures in the DP header. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-2-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/core.h | 9 --------- drivers/net/wireless/ath/ath12k/dp.h | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/core.h b/drivers/net/wireless/ath/ath12k/core.h index a98fc6e0699d..4718da494aab 100644 --- a/drivers/net/wireless/ath/ath12k/core.h +++ b/drivers/net/wireless/ath/ath12k/core.h @@ -928,15 +928,6 @@ struct ath12k_wsi_info { u32 hw_link_id_base; }; -struct ath12k_dp_profile_params { - u32 tx_comp_ring_size; - u32 rxdma_monitor_buf_ring_size; - u32 rxdma_monitor_dst_ring_size; - u32 num_pool_tx_desc; - u32 rx_desc_count; - u32 rx_release_ring_size; -}; - struct ath12k_mem_profile_based_param { u32 num_vdevs; u32 max_client_single; diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index bef0f2ba0560..72d3de2db5d8 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -23,6 +23,15 @@ struct ath12k_ext_irq_grp; struct ath12k_dp_rx_tid; struct ath12k_dp_rx_tid_rxq; +struct ath12k_dp_profile_params { + u32 tx_comp_ring_size; + u32 rxdma_monitor_buf_ring_size; + u32 rxdma_monitor_dst_ring_size; + u32 num_pool_tx_desc; + u32 rx_desc_count; + u32 rx_release_ring_size; +}; + #define DP_MON_PURGE_TIMEOUT_MS 100 #define DP_MON_SERVICE_BUDGET 128 From eaff19e86c2dbde320ccc8812cafb0a366dc65f4 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:17:59 +0530 Subject: [PATCH 0737/2126] wifi: ath12k: convert DP_TX_COMP_RING_SIZE to inline helper Replace DP_TX_COMP_RING_SIZE macro with ath12k_dp_tx_comp_ring_size() static inline helper. Pass the DP profile parameters explicitly to improve type safety and make the interface explicit. Update code using ATH12K_TX_COMPL_NEXT to pass ring size directly rather than deriving it from the ath12k_base structure. Also remove the unused DP_TX_IDR_SIZE macro. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-3-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.c | 10 +++++++--- drivers/net/wireless/ath/ath12k/dp.h | 11 +++++++---- drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 12 +++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index ef9601152f81..6d5db403b731 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -439,6 +439,7 @@ static void ath12k_dp_srng_common_cleanup(struct ath12k_base *ab) static int ath12k_dp_srng_common_setup(struct ath12k_base *ab) { + const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; struct ath12k_dp *dp = ath12k_ab_to_dp(ab); const struct ath12k_hal_tcl_to_wbm_rbm_map *map; struct hal_srng *srng; @@ -469,7 +470,7 @@ static int ath12k_dp_srng_common_setup(struct ath12k_base *ab) ret = ath12k_dp_srng_setup(ab, &dp->tx_ring[i].tcl_comp_ring, HAL_WBM2SW_RELEASE, tx_comp_ring_num, 0, - DP_TX_COMP_RING_SIZE(ab)); + ath12k_dp_tx_comp_ring_size(dp_params)); if (ret) { ath12k_warn(ab, "failed to set up tcl_comp ring (%d) :%d\n", tx_comp_ring_num, ret); @@ -1465,6 +1466,7 @@ static int ath12k_dp_reoq_lut_setup(struct ath12k_base *ab) static int ath12k_dp_setup(struct ath12k_base *ab) { + const struct ath12k_dp_profile_params *dp_params; struct ath12k_dp *dp; struct hal_srng *srng = NULL; size_t size = 0; @@ -1474,6 +1476,7 @@ static int ath12k_dp_setup(struct ath12k_base *ab) dp = ath12k_ab_to_dp(ab); dp->ab = ab; + dp_params = &ab->profile_param->dp_params; INIT_LIST_HEAD(&dp->reo_cmd_list); INIT_LIST_HEAD(&dp->reo_cmd_cache_flush_list); @@ -1528,7 +1531,7 @@ static int ath12k_dp_setup(struct ath12k_base *ab) goto fail_dp_bank_profiles_cleanup; size = ab->hal.hal_wbm_release_ring_tx_size * - DP_TX_COMP_RING_SIZE(ab); + ath12k_dp_tx_comp_ring_size(dp_params); ret = ath12k_dp_reoq_lut_setup(ab); if (ret) { @@ -1540,7 +1543,8 @@ static int ath12k_dp_setup(struct ath12k_base *ab) dp->tx_ring[i].tcl_data_ring_id = i; dp->tx_ring[i].tx_status_head = 0; - dp->tx_ring[i].tx_status_tail = DP_TX_COMP_RING_SIZE(ab) - 1; + dp->tx_ring[i].tx_status_tail = + ath12k_dp_tx_comp_ring_size(dp_params) - 1; dp->tx_ring[i].tx_status = kmalloc(size, GFP_KERNEL); if (!dp->tx_ring[i].tx_status) { ret = -ENOMEM; diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 72d3de2db5d8..6540b3453cc6 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -61,7 +61,7 @@ struct dp_rxdma_ring { int bufs_max; }; -#define ATH12K_TX_COMPL_NEXT(ab, x) (((x) + 1) % DP_TX_COMP_RING_SIZE(ab)) +#define ATH12K_TX_COMPL_NEXT(ring_size, x) (((x) + 1) % (ring_size)) struct dp_tx_ring { u8 tcl_data_ring_id; @@ -201,9 +201,6 @@ struct ath12k_pdev_dp { #define DP_WBM_RELEASE_RING_SIZE 64 #define DP_TCL_DATA_RING_SIZE 512 -#define DP_TX_COMP_RING_SIZE(ab) \ - ((ab)->profile_param->dp_params.tx_comp_ring_size) -#define DP_TX_IDR_SIZE(ab) DP_TX_COMP_RING_SIZE(ab) #define DP_TCL_CMD_RING_SIZE 32 #define DP_TCL_STATUS_RING_SIZE 32 #define DP_REO_DST_RING_MAX 8 @@ -689,6 +686,12 @@ ath12k_dp_to_pdev_dp(struct ath12k_dp *dp, u8 pdev_idx) return rcu_dereference(dp->dp_pdevs[pdev_idx]); } +static inline u32 +ath12k_dp_tx_comp_ring_size(const struct ath12k_dp_profile_params *p) +{ + return p->tx_comp_ring_size; +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 7c12dba4cc51..3f6df96de160 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -929,12 +929,14 @@ void ath12k_wifi7_dp_tx_completion_handler(struct ath12k_dp *dp, int ring_id) u64 desc_va; enum hal_wbm_rel_src_module buf_rel_source; enum hal_wbm_tqm_rel_reason rel_status; + u32 ring_size; spin_lock_bh(&status_ring->lock); + ring_size = ath12k_dp_tx_comp_ring_size(&ab->profile_param->dp_params); ath12k_hal_srng_access_begin(ab, status_ring); - while (ATH12K_TX_COMPL_NEXT(ab, tx_ring->tx_status_head) != + while (ATH12K_TX_COMPL_NEXT(ring_size, tx_ring->tx_status_head) != tx_ring->tx_status_tail) { desc = ath12k_hal_srng_dst_get_next_entry(ab, status_ring); if (!desc) @@ -943,11 +945,11 @@ void ath12k_wifi7_dp_tx_completion_handler(struct ath12k_dp *dp, int ring_id) memcpy(&tx_ring->tx_status[tx_ring->tx_status_head], desc, sizeof(*desc)); tx_ring->tx_status_head = - ATH12K_TX_COMPL_NEXT(ab, tx_ring->tx_status_head); + ATH12K_TX_COMPL_NEXT(ring_size, tx_ring->tx_status_head); } if (ath12k_hal_srng_dst_peek(ab, status_ring) && - (ATH12K_TX_COMPL_NEXT(ab, tx_ring->tx_status_head) == + (ATH12K_TX_COMPL_NEXT(ring_size, tx_ring->tx_status_head) == tx_ring->tx_status_tail)) { /* TODO: Process pending tx_status messages when kfifo_is_full() */ ath12k_warn(ab, "Unable to process some of the tx_status ring desc because status_fifo is full\n"); @@ -957,13 +959,13 @@ void ath12k_wifi7_dp_tx_completion_handler(struct ath12k_dp *dp, int ring_id) spin_unlock_bh(&status_ring->lock); - while (ATH12K_TX_COMPL_NEXT(ab, tx_ring->tx_status_tail) != + while (ATH12K_TX_COMPL_NEXT(ring_size, tx_ring->tx_status_tail) != tx_ring->tx_status_head) { struct hal_wbm_completion_ring_tx *tx_status; u32 desc_id; tx_ring->tx_status_tail = - ATH12K_TX_COMPL_NEXT(ab, tx_ring->tx_status_tail); + ATH12K_TX_COMPL_NEXT(ring_size, tx_ring->tx_status_tail); tx_status = &tx_ring->tx_status[tx_ring->tx_status_tail]; ath12k_wifi7_dp_tx_status_parse(dp, tx_status, &ts); From d57f90669269fad2dd9ca98cd32b7412ceccb0b0 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:18:00 +0530 Subject: [PATCH 0738/2126] wifi: ath12k: convert DP_RXDMA_MONITOR_BUF_RING_SIZE to inline helper Replace DP_RXDMA_MONITOR_BUF_RING_SIZE macro with ath12k_dp_rxdma_monitor_buf_ring_size() static inline helper. Pass the DP profile parameters explicitly to improve type safety and make the interface explicit. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-4-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.h | 8 ++++++-- drivers/net/wireless/ath/ath12k/dp_rx.c | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 6540b3453cc6..9081655eae77 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -216,8 +216,6 @@ struct ath12k_pdev_dp { #define DP_RXDMA_REFILL_RING_SIZE 2048 #define DP_RXDMA_ERR_DST_RING_SIZE 1024 #define DP_RXDMA_MON_STATUS_RING_SIZE 1024 -#define DP_RXDMA_MONITOR_BUF_RING_SIZE(ab) \ - ((ab)->profile_param->dp_params.rxdma_monitor_buf_ring_size) #define DP_RXDMA_MONITOR_DST_RING_SIZE(ab) \ ((ab)->profile_param->dp_params.rxdma_monitor_dst_ring_size) #define DP_RXDMA_MONITOR_DESC_RING_SIZE 4096 @@ -692,6 +690,12 @@ ath12k_dp_tx_comp_ring_size(const struct ath12k_dp_profile_params *p) return p->tx_comp_ring_size; } +static inline u32 +ath12k_dp_rxdma_monitor_buf_ring_size(const struct ath12k_dp_profile_params *p) +{ + return p->rxdma_monitor_buf_ring_size; +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c index 41ac0a4072ae..75ada41aa2ba 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/dp_rx.c @@ -1704,6 +1704,8 @@ int ath12k_dp_rx_htt_setup(struct ath12k_base *ab) int ath12k_dp_rx_alloc(struct ath12k_base *ab) { + const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; + u32 monitor_buf_ring_size = ath12k_dp_rxdma_monitor_buf_ring_size(dp_params); struct ath12k_dp *dp = ath12k_ab_to_dp(ab); struct dp_srng *srng; int i, ret; @@ -1748,7 +1750,7 @@ int ath12k_dp_rx_alloc(struct ath12k_base *ab) ret = ath12k_dp_srng_setup(ab, &dp->rxdma_mon_buf_ring.refill_buf_ring, HAL_RXDMA_MONITOR_BUF, 0, 0, - DP_RXDMA_MONITOR_BUF_RING_SIZE(ab)); + monitor_buf_ring_size); if (ret) { ath12k_warn(ab, "failed to setup HAL_RXDMA_MONITOR_BUF\n"); return ret; From 62e2758d17d307753457bd51af074be5f8265c03 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:18:01 +0530 Subject: [PATCH 0739/2126] wifi: ath12k: convert DP_RXDMA_MONITOR_DST_RING_SIZE to inline helper Replace DP_RXDMA_MONITOR_DST_RING_SIZE macro with ath12k_dp_rxdma_monitor_dst_ring_size() static inline helper. Pass the DP profile parameters explicitly to improve type safety and make the interface explicit. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-5-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.h | 8 ++++++-- drivers/net/wireless/ath/ath12k/dp_rx.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 9081655eae77..a7cd2535866b 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -216,8 +216,6 @@ struct ath12k_pdev_dp { #define DP_RXDMA_REFILL_RING_SIZE 2048 #define DP_RXDMA_ERR_DST_RING_SIZE 1024 #define DP_RXDMA_MON_STATUS_RING_SIZE 1024 -#define DP_RXDMA_MONITOR_DST_RING_SIZE(ab) \ - ((ab)->profile_param->dp_params.rxdma_monitor_dst_ring_size) #define DP_RXDMA_MONITOR_DESC_RING_SIZE 4096 #define DP_TX_MONITOR_BUF_RING_SIZE 4096 #define DP_TX_MONITOR_DEST_RING_SIZE 2048 @@ -696,6 +694,12 @@ ath12k_dp_rxdma_monitor_buf_ring_size(const struct ath12k_dp_profile_params *p) return p->rxdma_monitor_buf_ring_size; } +static inline u32 +ath12k_dp_rxdma_monitor_dst_ring_size(const struct ath12k_dp_profile_params *p) +{ + return p->rxdma_monitor_dst_ring_size; +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c index 75ada41aa2ba..8bb2b57aed15 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/dp_rx.c @@ -330,16 +330,20 @@ static int ath12k_dp_rx_pdev_srng_alloc(struct ath12k *ar) { struct ath12k_pdev_dp *dp = &ar->dp; struct ath12k_base *ab = ar->ab; + u32 monitor_dst_ring_size; + u32 mac_id = dp->mac_id; int i; int ret; - u32 mac_id = dp->mac_id; + + monitor_dst_ring_size = + ath12k_dp_rxdma_monitor_dst_ring_size(&ab->profile_param->dp_params); for (i = 0; i < ab->hw_params->num_rxdma_per_pdev; i++) { ret = ath12k_dp_srng_setup(ar->ab, &dp->rxdma_mon_dst_ring[i], HAL_RXDMA_MONITOR_DST, 0, mac_id + i, - DP_RXDMA_MONITOR_DST_RING_SIZE(ab)); + monitor_dst_ring_size); if (ret) { ath12k_warn(ar->ab, "failed to setup HAL_RXDMA_MONITOR_DST\n"); From 99b85a24189a518938eb0f1c4f8e15fbab4373ec Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:18:02 +0530 Subject: [PATCH 0740/2126] wifi: ath12k: convert ATH12K_NUM_POOL_TX_DESC to inline helper Replace ATH12K_NUM_POOL_TX_DESC with the ath12k_dp_num_pool_tx_desc() static inline helper. Also replace ATH12K_TX_SPT_PAGES_PER_POOL, ATH12K_NUM_TX_SPT_PAGES, and ATH12K_RX_SPT_PAGE_OFFSET, which are derived from ATH12K_NUM_POOL_TX_DESC, with static inline helper functions. Pass the DP profile parameters explicitly to improve type safety and make the interface more explicit. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-6-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.c | 55 ++++++++++++++++----------- drivers/net/wireless/ath/ath12k/dp.h | 32 ++++++++++++---- drivers/net/wireless/ath/ath12k/mac.c | 5 ++- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index 6d5db403b731..e8a82a86bd9b 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -967,14 +967,15 @@ void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif) static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) { - struct ath12k_rx_desc_info *desc_info; + const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; + u32 pool_id, tx_spt_page, tx_spt_pages_per_pool; struct ath12k_tx_desc_info *tx_desc_info, *tmp1; struct ath12k_dp *dp = ath12k_ab_to_dp(ab); + struct ath12k_rx_desc_info *desc_info; struct ath12k_skb_cb *skb_cb; struct sk_buff *skb; struct ath12k *ar; int i, j; - u32 pool_id, tx_spt_page; if (!dp->spt_info) return; @@ -1056,12 +1057,13 @@ static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) } if (dp->txbaddr) { + tx_spt_pages_per_pool = ath12k_dp_tx_spt_pages_per_pool(dp_params); + for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) { spin_lock_bh(&dp->tx_desc_lock[pool_id]); - for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL(ab); i++) { - tx_spt_page = i + pool_id * - ATH12K_TX_SPT_PAGES_PER_POOL(ab); + for (i = 0; i < tx_spt_pages_per_pool; i++) { + tx_spt_page = i + pool_id * tx_spt_pages_per_pool; if (!dp->txbaddr[tx_spt_page]) continue; @@ -1155,13 +1157,15 @@ static void *ath12k_dp_cc_get_desc_addr_ptr(struct ath12k_dp *dp, struct ath12k_rx_desc_info *ath12k_dp_get_rx_desc(struct ath12k_dp *dp, u32 cookie) { + const struct ath12k_dp_profile_params *dp_params; struct ath12k_rx_desc_info **desc_addr_ptr; u16 start_ppt_idx, end_ppt_idx, ppt_idx, spt_idx; ppt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_PPT); spt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_SPT); + dp_params = &dp->ab->profile_param->dp_params; - start_ppt_idx = dp->rx_ppt_base + ATH12K_RX_SPT_PAGE_OFFSET(dp->ab); + start_ppt_idx = dp->rx_ppt_base + ath12k_dp_rx_spt_page_offset(dp_params); end_ppt_idx = start_ppt_idx + ATH12K_NUM_RX_SPT_PAGES(dp->ab); if (ppt_idx < start_ppt_idx || @@ -1179,15 +1183,16 @@ EXPORT_SYMBOL(ath12k_dp_get_rx_desc); struct ath12k_tx_desc_info *ath12k_dp_get_tx_desc(struct ath12k_dp *dp, u32 cookie) { + const struct ath12k_dp_profile_params *dp_params; struct ath12k_tx_desc_info **desc_addr_ptr; u16 start_ppt_idx, end_ppt_idx, ppt_idx, spt_idx; ppt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_PPT); spt_idx = u32_get_bits(cookie, ATH12K_DP_CC_COOKIE_SPT); + dp_params = &dp->ab->profile_param->dp_params; start_ppt_idx = ATH12K_TX_SPT_PAGE_OFFSET; - end_ppt_idx = start_ppt_idx + - (ATH12K_TX_SPT_PAGES_PER_POOL(dp->ab) * ATH12K_HW_MAX_QUEUES); + end_ppt_idx = start_ppt_idx + ath12k_dp_num_tx_spt_pages(dp_params); if (ppt_idx < start_ppt_idx || ppt_idx >= end_ppt_idx || @@ -1202,12 +1207,13 @@ EXPORT_SYMBOL(ath12k_dp_get_tx_desc); static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) { - struct ath12k_dp *dp = ath12k_ab_to_dp(ab); + const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; struct ath12k_rx_desc_info *rx_descs, **rx_desc_addr; struct ath12k_tx_desc_info *tx_descs, **tx_desc_addr; + u32 i, j, pool_id, tx_spt_page, tx_spt_pages_per_pool; u32 num_rx_spt_pages = ATH12K_NUM_RX_SPT_PAGES(ab); - u32 i, j, pool_id, tx_spt_page; - u32 ppt_idx, cookie_ppt_idx; + u32 ppt_idx, cookie_ppt_idx, rx_spt_page_offset; + struct ath12k_dp *dp = ath12k_ab_to_dp(ab); spin_lock_bh(&dp->rx_desc_lock); @@ -1219,9 +1225,9 @@ static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) return -ENOMEM; } - /* First ATH12K_NUM_RX_SPT_PAGES(ab) of allocated SPT pages are used for - * RX - */ + rx_spt_page_offset = ath12k_dp_rx_spt_page_offset(dp_params); + + /* First num_rx_spt_pages of allocated SPT pages are used for RX */ for (i = 0; i < num_rx_spt_pages; i++) { rx_descs = kzalloc_objs(*rx_descs, ATH12K_MAX_SPT_ENTRIES, GFP_ATOMIC); @@ -1231,7 +1237,7 @@ static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) return -ENOMEM; } - ppt_idx = ATH12K_RX_SPT_PAGE_OFFSET(ab) + i; + ppt_idx = rx_spt_page_offset + i; cookie_ppt_idx = dp->rx_ppt_base + ppt_idx; dp->rxbaddr[i] = &rx_descs[0]; @@ -1250,14 +1256,17 @@ static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) spin_unlock_bh(&dp->rx_desc_lock); dp->txbaddr = kzalloc_objs(struct ath12k_tx_desc_info *, - ATH12K_NUM_TX_SPT_PAGES(ab), GFP_ATOMIC); + ath12k_dp_num_tx_spt_pages(dp_params), + GFP_ATOMIC); if (!dp->txbaddr) return -ENOMEM; + tx_spt_pages_per_pool = ath12k_dp_tx_spt_pages_per_pool(dp_params); + for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) { spin_lock_bh(&dp->tx_desc_lock[pool_id]); - for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL(ab); i++) { + for (i = 0; i < tx_spt_pages_per_pool; i++) { tx_descs = kzalloc_objs(*tx_descs, ATH12K_MAX_SPT_ENTRIES, GFP_ATOMIC); @@ -1268,8 +1277,7 @@ static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) return -ENOMEM; } - tx_spt_page = i + pool_id * - ATH12K_TX_SPT_PAGES_PER_POOL(ab); + tx_spt_page = i + pool_id * tx_spt_pages_per_pool; ppt_idx = ATH12K_TX_SPT_PAGE_OFFSET + tx_spt_page; dp->txbaddr[tx_spt_page] = &tx_descs[0]; @@ -1295,6 +1303,7 @@ static int ath12k_dp_cmem_init(struct ath12k_base *ab, struct ath12k_dp *dp, enum ath12k_dp_desc_type type) { + const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; u32 cmem_base; int i, start, end; @@ -1303,11 +1312,11 @@ static int ath12k_dp_cmem_init(struct ath12k_base *ab, switch (type) { case ATH12K_DP_TX_DESC: start = ATH12K_TX_SPT_PAGE_OFFSET; - end = start + ATH12K_NUM_TX_SPT_PAGES(ab); + end = start + ath12k_dp_num_tx_spt_pages(dp_params); break; case ATH12K_DP_RX_DESC: cmem_base += ATH12K_PPT_ADDR_OFFSET(dp->rx_ppt_base); - start = ATH12K_RX_SPT_PAGE_OFFSET(ab); + start = ath12k_dp_rx_spt_page_offset(dp_params); end = start + ATH12K_NUM_RX_SPT_PAGES(ab); break; default: @@ -1338,7 +1347,9 @@ void ath12k_dp_partner_cc_init(struct ath12k_base *ab) static u32 ath12k_dp_get_num_spt_pages(struct ath12k_base *ab) { - return ATH12K_NUM_RX_SPT_PAGES(ab) + ATH12K_NUM_TX_SPT_PAGES(ab); + const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; + + return ATH12K_NUM_RX_SPT_PAGES(ab) + ath12k_dp_num_tx_spt_pages(dp_params); } static int ath12k_dp_cc_init(struct ath12k_base *ab) diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index a7cd2535866b..7e48379d18a0 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -249,8 +249,6 @@ struct ath12k_pdev_dp { #define ATH12K_SHADOW_DP_TIMER_INTERVAL 20 #define ATH12K_SHADOW_CTRL_TIMER_INTERVAL 10 -#define ATH12K_NUM_POOL_TX_DESC(ab) \ - ((ab)->profile_param->dp_params.num_pool_tx_desc) /* TODO: revisit this count during testing */ #define ATH12K_RX_DESC_COUNT(ab) \ ((ab)->profile_param->dp_params.rx_desc_count) @@ -268,13 +266,7 @@ struct ath12k_pdev_dp { #define ATH12K_NUM_RX_SPT_PAGES(ab) ((ATH12K_RX_DESC_COUNT(ab)) / \ ATH12K_MAX_SPT_ENTRIES) -#define ATH12K_TX_SPT_PAGES_PER_POOL(ab) (ATH12K_NUM_POOL_TX_DESC(ab) / \ - ATH12K_MAX_SPT_ENTRIES) -#define ATH12K_NUM_TX_SPT_PAGES(ab) (ATH12K_TX_SPT_PAGES_PER_POOL(ab) * \ - ATH12K_HW_MAX_QUEUES) - #define ATH12K_TX_SPT_PAGE_OFFSET 0 -#define ATH12K_RX_SPT_PAGE_OFFSET(ab) ATH12K_NUM_TX_SPT_PAGES(ab) /* The SPT pages are divided for RX and TX, first block for RX * and remaining for TX @@ -700,6 +692,30 @@ ath12k_dp_rxdma_monitor_dst_ring_size(const struct ath12k_dp_profile_params *p) return p->rxdma_monitor_dst_ring_size; } +static inline u32 +ath12k_dp_num_pool_tx_desc(const struct ath12k_dp_profile_params *p) +{ + return p->num_pool_tx_desc; +} + +static inline u32 +ath12k_dp_tx_spt_pages_per_pool(const struct ath12k_dp_profile_params *p) +{ + return ath12k_dp_num_pool_tx_desc(p) / ATH12K_MAX_SPT_ENTRIES; +} + +static inline u32 +ath12k_dp_num_tx_spt_pages(const struct ath12k_dp_profile_params *p) +{ + return ath12k_dp_tx_spt_pages_per_pool(p) * ATH12K_HW_MAX_QUEUES; +} + +static inline u32 +ath12k_dp_rx_spt_page_offset(const struct ath12k_dp_profile_params *p) +{ + return ath12k_dp_num_tx_spt_pages(p); +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index d4116ba0da08..196b807210de 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -9739,6 +9739,7 @@ static int ath12k_mac_config_mon_status_default(struct ath12k *ar, bool enable) static int ath12k_mac_start(struct ath12k *ar) { + const struct ath12k_dp_profile_params *dp_params; struct ath12k_hw *ah = ar->ah; struct ath12k_base *ab = ar->ab; struct ath12k_pdev *pdev = ar->pdev; @@ -9747,6 +9748,8 @@ static int ath12k_mac_start(struct ath12k *ar) lockdep_assert_held(&ah->hw_mutex); lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); + dp_params = &ab->profile_param->dp_params; + ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1, pdev->pdev_id); @@ -9795,7 +9798,7 @@ static int ath12k_mac_start(struct ath12k *ar) if (ab->hw_params->supports_cong_ctrl_max_msdus) { ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_SET_CONG_CTRL_MAX_MSDUS, - ATH12K_NUM_POOL_TX_DESC(ab), + ath12k_dp_num_pool_tx_desc(dp_params), pdev->pdev_id); if (ret) { ath12k_err(ab, From fafb9b0450fd6fd3618daf347717a6d6320bea38 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:18:03 +0530 Subject: [PATCH 0741/2126] wifi: ath12k: convert ATH12K_RX_DESC_COUNT to inline helper Replace ATH12K_RX_DESC_COUNT with ath12k_dp_rx_desc_count() static inline helper, also replace ATH12K_NUM_RX_SPT_PAGES which is calculated from ATH12K_RX_DESC_COUNT into static inline helper functions and pass the DP profile parameters explicitly to improve type safety and make the interface explicit. Also remove the unused ATH12K_NUM_TX_SPT_PAGE_START macro. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-7-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.c | 18 +++++++++++------- drivers/net/wireless/ath/ath12k/dp.h | 24 ++++++++++++------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index e8a82a86bd9b..c08bd780d59d 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -968,7 +968,7 @@ void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif) static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) { const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; - u32 pool_id, tx_spt_page, tx_spt_pages_per_pool; + u32 pool_id, tx_spt_page, tx_spt_pages_per_pool, num_rx_spt_pages; struct ath12k_tx_desc_info *tx_desc_info, *tmp1; struct ath12k_dp *dp = ath12k_ab_to_dp(ab); struct ath12k_rx_desc_info *desc_info; @@ -983,8 +983,10 @@ static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) /* RX Descriptor cleanup */ spin_lock_bh(&dp->rx_desc_lock); + num_rx_spt_pages = ath12k_dp_num_rx_spt_pages(dp_params); + if (dp->rxbaddr) { - for (i = 0; i < ATH12K_NUM_RX_SPT_PAGES(ab); i++) { + for (i = 0; i < num_rx_spt_pages; i++) { if (!dp->rxbaddr[i]) continue; @@ -1166,7 +1168,7 @@ struct ath12k_rx_desc_info *ath12k_dp_get_rx_desc(struct ath12k_dp *dp, dp_params = &dp->ab->profile_param->dp_params; start_ppt_idx = dp->rx_ppt_base + ath12k_dp_rx_spt_page_offset(dp_params); - end_ppt_idx = start_ppt_idx + ATH12K_NUM_RX_SPT_PAGES(dp->ab); + end_ppt_idx = start_ppt_idx + ath12k_dp_num_rx_spt_pages(dp_params); if (ppt_idx < start_ppt_idx || ppt_idx >= end_ppt_idx || @@ -1208,10 +1210,10 @@ EXPORT_SYMBOL(ath12k_dp_get_tx_desc); static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) { const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; + u32 num_rx_spt_pages = ath12k_dp_num_rx_spt_pages(dp_params); struct ath12k_rx_desc_info *rx_descs, **rx_desc_addr; struct ath12k_tx_desc_info *tx_descs, **tx_desc_addr; u32 i, j, pool_id, tx_spt_page, tx_spt_pages_per_pool; - u32 num_rx_spt_pages = ATH12K_NUM_RX_SPT_PAGES(ab); u32 ppt_idx, cookie_ppt_idx, rx_spt_page_offset; struct ath12k_dp *dp = ath12k_ab_to_dp(ab); @@ -1317,7 +1319,7 @@ static int ath12k_dp_cmem_init(struct ath12k_base *ab, case ATH12K_DP_RX_DESC: cmem_base += ATH12K_PPT_ADDR_OFFSET(dp->rx_ppt_base); start = ath12k_dp_rx_spt_page_offset(dp_params); - end = start + ATH12K_NUM_RX_SPT_PAGES(ab); + end = start + ath12k_dp_num_rx_spt_pages(dp_params); break; default: ath12k_err(ab, "invalid descriptor type %d in cmem init\n", type); @@ -1349,7 +1351,8 @@ static u32 ath12k_dp_get_num_spt_pages(struct ath12k_base *ab) { const struct ath12k_dp_profile_params *dp_params = &ab->profile_param->dp_params; - return ATH12K_NUM_RX_SPT_PAGES(ab) + ath12k_dp_num_tx_spt_pages(dp_params); + return ath12k_dp_num_rx_spt_pages(dp_params) + + ath12k_dp_num_tx_spt_pages(dp_params); } static int ath12k_dp_cc_init(struct ath12k_base *ab) @@ -1377,7 +1380,8 @@ static int ath12k_dp_cc_init(struct ath12k_base *ab) return -ENOMEM; } - dp->rx_ppt_base = ab->device_id * ATH12K_NUM_RX_SPT_PAGES(ab); + dp->rx_ppt_base = ab->device_id * + ath12k_dp_num_rx_spt_pages(&ab->profile_param->dp_params); for (i = 0; i < dp->num_spt_pages; i++) { dp->spt_info[i].vaddr = dma_alloc_coherent(ab->dev, diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 7e48379d18a0..c8ca3ab4d5e1 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -249,10 +249,6 @@ struct ath12k_pdev_dp { #define ATH12K_SHADOW_DP_TIMER_INTERVAL 20 #define ATH12K_SHADOW_CTRL_TIMER_INTERVAL 10 -/* TODO: revisit this count during testing */ -#define ATH12K_RX_DESC_COUNT(ab) \ - ((ab)->profile_param->dp_params.rx_desc_count) - #define ATH12K_PAGE_SIZE PAGE_SIZE /* Total 1024 entries in PPT, i.e 4K/4 considering 4K aligned @@ -263,16 +259,8 @@ struct ath12k_pdev_dp { /* Total 512 entries in a SPT, i.e 4K Page/8 */ #define ATH12K_MAX_SPT_ENTRIES 512 -#define ATH12K_NUM_RX_SPT_PAGES(ab) ((ATH12K_RX_DESC_COUNT(ab)) / \ - ATH12K_MAX_SPT_ENTRIES) - #define ATH12K_TX_SPT_PAGE_OFFSET 0 -/* The SPT pages are divided for RX and TX, first block for RX - * and remaining for TX - */ -#define ATH12K_NUM_TX_SPT_PAGE_START(ab) ATH12K_NUM_RX_SPT_PAGES(ab) - #define ATH12K_DP_RX_DESC_MAGIC 0xBABABABA /* 4K aligned address have last 12 bits set to 0, this check is done @@ -716,6 +704,18 @@ ath12k_dp_rx_spt_page_offset(const struct ath12k_dp_profile_params *p) return ath12k_dp_num_tx_spt_pages(p); } +static inline u32 +ath12k_dp_rx_desc_count(const struct ath12k_dp_profile_params *p) +{ + return p->rx_desc_count; +} + +static inline u32 +ath12k_dp_num_rx_spt_pages(const struct ath12k_dp_profile_params *p) +{ + return ath12k_dp_rx_desc_count(p) / ATH12K_MAX_SPT_ENTRIES; +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); From 897d2e0046f941d8956f655f5ffc5d75c788558d Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 20 Aug 2026 11:18:04 +0530 Subject: [PATCH 0742/2126] wifi: ath12k: convert DP_RX_RELEASE_RING_SIZE to inline helper Replace DP_RX_RELEASE_RING_SIZE macro with ath12k_dp_rx_release_ring_size() static inline helper. Pass the DP profile parameters explicitly to improve type safety and make the interface explicit. No functional change intended. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260820054804.3222296-8-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.c | 2 +- drivers/net/wireless/ath/ath12k/dp.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index c08bd780d59d..cce5386c5bd5 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -488,7 +488,7 @@ static int ath12k_dp_srng_common_setup(struct ath12k_base *ab) ret = ath12k_dp_srng_setup(ab, &dp->rx_rel_ring, HAL_WBM2SW_RELEASE, HAL_WBM2SW_REL_ERR_RING_NUM, 0, - DP_RX_RELEASE_RING_SIZE(ab)); + ath12k_dp_rx_release_ring_size(dp_params)); if (ret) { ath12k_warn(ab, "failed to set up rx_rel ring :%d\n", ret); goto err; diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index c8ca3ab4d5e1..ff62773cfa9a 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -206,8 +206,6 @@ struct ath12k_pdev_dp { #define DP_REO_DST_RING_MAX 8 #define DP_REO_DST_RING_SIZE 2048 #define DP_REO_REINJECT_RING_SIZE 32 -#define DP_RX_RELEASE_RING_SIZE(ab) \ - ((ab)->profile_param->dp_params.rx_release_ring_size) #define DP_REO_EXCEPTION_RING_SIZE 128 #define DP_REO_CMD_RING_SIZE 256 #define DP_REO_STATUS_RING_SIZE 2048 @@ -716,6 +714,12 @@ ath12k_dp_num_rx_spt_pages(const struct ath12k_dp_profile_params *p) return ath12k_dp_rx_desc_count(p) / ATH12K_MAX_SPT_ENTRIES; } +static inline u32 +ath12k_dp_rx_release_ring_size(const struct ath12k_dp_profile_params *p) +{ + return p->rx_release_ring_size; +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); From 4dfe8e3ac731c3372b5c1f1f73b0676c301c3916 Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Wed, 16 Sep 2026 14:03:20 +0800 Subject: [PATCH 0743/2126] wifi: ath12k: fix skb leak on paddr mismatch in wifi7 mon RX pop When rxcb->paddr does not match the MSDU-list paddr reported by the link descriptor, ath12k_wifi7_dp_rx_mon_mpdu_pop() sets drop_mpdu = true and continues to the next MSDU. At that point the skb is still attached to the descriptor via desc_info->skb; the local msdu variable only holds a copy of that pointer. The continue skips the rest of the loop body, which would normally DMA-unmap the buffer, free the skb, clear desc_info->skb, and append the descriptor to used_list in the next_msdu block. The descriptor therefore stays in_use with the skb attached forever. The skb is never DMA-unmapped, delivered, freed or replaced, and HW does not write into it either because the descriptor is no longer posted to any SRNG. The descriptor is also never returned to used_list, so ath12k_dp_rx_bufs_replenish() cannot allocate a fresh buffer for it and the RX refill ring gradually drains. The skb is still reachable via dp->rxbaddr[][].skb and is reclaimed at teardown by ath12k_dp_cc_cleanup(), so this is not a kmemleak-style unreachable leak. Nevertheless, both the descriptor slot and the skb memory are wasted for the module lifetime, and under sustained mismatches monitor RX stalls. Remove the continue so drop_mpdu remains true, execution reaches the DMA unmap and dev_kfree_skb_any() below, and the descriptor is returned to used_list via the next_msdu block for replenish. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 72bfbf19b7da ("wifi: ath12k: add support to reap and process mon dest ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260916060325.854-2-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c index ded7d56cd79b..ed6686746605 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c @@ -2718,7 +2718,6 @@ ath12k_wifi7_dp_rx_mon_mpdu_pop(struct ath12k *ar, int mac_id, i, (unsigned long)rxcb->paddr, (unsigned long)msdu_list.paddr[i]); drop_mpdu = true; - continue; } if (!rxcb->unmapped) { dma_unmap_single(ar->ab->dev, rxcb->paddr, From d8e8eac3fcffc114a79f7d07d7cb73cc16645381 Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Wed, 16 Sep 2026 14:03:21 +0800 Subject: [PATCH 0744/2126] wifi: ath12k: free pending MSDUs on duplicate mon link descriptor ath12k_wifi7_dp_rx_mon_mpdu_pop() aborts processing when a duplicate monitor link descriptor is detected. Previous iterations may already have linked MSDUs onto *head_msdu and detached the corresponding RX buffers from their descriptors. Returning without completing or freeing the chain leaves those skbs orphaned, resulting in a memory leak. kmemleak reports these skbs in field testing: kmemleak_alloc() __netdev_alloc_skb() ath12k_dp_rx_bufs_replenish() ath12k_wifi7_dp_rx_mon_dest_process() Free the accumulated MSDU chain before returning and clear *head_msdu so callers observe a consistent state. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 72bfbf19b7da ("wifi: ath12k: add support to reap and process mon dest ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260916060325.854-3-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c index ed6686746605..08f2fba3e680 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c @@ -2675,6 +2675,8 @@ ath12k_wifi7_dp_rx_mon_mpdu_pop(struct ath12k *ar, int mac_id, if (pmon->mon_last_linkdesc_paddr == paddr) { pmon->rx_mon_stats.dup_mon_linkdesc_cnt++; spin_unlock_bh(&pmon->mon_lock); + kfree_skb_list(*head_msdu); + *head_msdu = NULL; return rx_bufs_used; } From 1a10a558555072dba8510ded23a9174b2a00d079 Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Wed, 16 Sep 2026 14:03:22 +0800 Subject: [PATCH 0745/2126] wifi: ath12k: fix stale tail_msdu pointer returned from mpdu_pop ath12k_wifi7_dp_rx_mon_mpdu_pop() assigns *tail_msdu from the loop cursor msdu at function exit. That cursor reflects the state of the last msdu_list entry processed, not the end of the accumulated MSDU chain: on next_msdu paths (invalid skb, drop_mpdu, first-MSDU rx_desc invalid) it is set to NULL, and on the set_pktlen failure path it becomes a dangling pointer to a freed skb. When these occur on the final iteration, callers see head_msdu populated with a valid chain while tail_msdu is NULL or points to freed memory. The chain end is already tracked by the local variable last, which is updated only after each MSDU has been validated and linked. Use it as the source for tail_msdu so head_msdu and tail_msdu are either both NULL or both point into the same live chain. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 72bfbf19b7da ("wifi: ath12k: add support to reap and process mon dest ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260916060325.854-4-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c index 08f2fba3e680..8fca777041d1 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c @@ -2802,7 +2802,7 @@ next_msdu: if (last) last->next = NULL; - *tail_msdu = msdu; + *tail_msdu = last; if (msdu_cnt == 0) *npackets = 1; From 8b1d2f4c3805b9f1bddd5dc3bd241edd1f9ab2d9 Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Wed, 16 Sep 2026 14:03:23 +0800 Subject: [PATCH 0746/2126] wifi: ath12k: place dp_mon_mpdu on stack in mon dst reap loop ath12k_wifi7_dp_rx_mon_dest_process() allocates a dp_mon_mpdu with kzalloc(GFP_ATOMIC) for each delivered MPDU. On allocation failure it breaks out of the reap loop without calling ath12k_hal_srng_dst_get_next_entry(), leaving the destination ring tail pointer parked on the current entry -- the same entry will be peek()ed on every subsequent NAPI schedule, stalling monitor RX until the mon_dest_ring_stuck_cnt recovery path resyncs the PPDU ID. The head_msdu chain accumulated for this iteration is also orphaned since the break bypasses both the delivery and the cleanup paths. kmemleak reports these skbs in field testing: kmemleak_alloc() __netdev_alloc_skb() ath12k_dp_rx_bufs_replenish() ath12k_wifi7_dp_rx_mon_dest_process() dp_mon_mpdu is used only within a single reap loop iteration and is passed synchronously to ath12k_wifi7_dp_mon_rx_deliver(); the callee does not retain the pointer. Place it on the stack instead of using kzalloc(GFP_ATOMIC). This eliminates the allocation failure path (and the ring stall it caused) and saves a kzalloc/kfree pair per delivered MPDU. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 72bfbf19b7da ("wifi: ath12k: add support to reap and process mon dest ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260916060325.854-5-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c index 8fca777041d1..1e29c13ad66d 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_mon.c @@ -2827,7 +2827,6 @@ ath12k_wifi7_dp_rx_mon_dest_process(struct ath12k *ar, int mac_id, struct ath12k_base *ab = ar->ab; struct ath12k_dp *dp = ath12k_ab_to_dp(ab); void *ring_entry, *mon_dst_srng; - struct dp_mon_mpdu *tmp_mpdu; LIST_HEAD(rx_desc_used_list); struct hal_srng *srng; @@ -2893,18 +2892,16 @@ ath12k_wifi7_dp_rx_mon_dest_process(struct ath12k *ar, int mac_id, } if (head_msdu && tail_msdu) { - tmp_mpdu = kzalloc_obj(*tmp_mpdu, GFP_ATOMIC); - if (!tmp_mpdu) - break; + struct dp_mon_mpdu tmp_mpdu = { + .head = head_msdu, + .tail = tail_msdu, + .err_bitmap = pmon->err_bitmap, + .decap_format = pmon->decap_format, + }; - tmp_mpdu->head = head_msdu; - tmp_mpdu->tail = tail_msdu; - tmp_mpdu->err_bitmap = pmon->err_bitmap; - tmp_mpdu->decap_format = pmon->decap_format; - ath12k_wifi7_dp_mon_rx_deliver(&ar->dp, tmp_mpdu, + ath12k_wifi7_dp_mon_rx_deliver(&ar->dp, &tmp_mpdu, &pmon->mon_ppdu_info, napi); rx_mon_stats->dest_mpdu_done++; - kfree(tmp_mpdu); } ring_entry = ath12k_hal_srng_dst_get_next_entry(ar->ab, From 97b144b82e2388efef1f78269626d61de0480feb Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Wed, 16 Sep 2026 14:03:24 +0800 Subject: [PATCH 0747/2126] wifi: ath12k: fix skb leak on monitor PPDU ID wraparound ath12k_dp_mon_comp_ppduid() updates *ppdu_id and returns msdu_ppdu_id to indicate that a PPDU transition was detected. When PPDU IDs wrap around, msdu_ppdu_id can be 0. In that case the function updates *ppdu_id but returns 0, causing ath12k_wifi7_dp_rx_mon_mpdu_pop() to interpret the result as "no PPDU update" and continue processing the MPDU. The MSDUs are then linked into head_msdu while their RX descriptors have already been detached. Later, ath12k_wifi7_dp_rx_mon_dest_process() detects the PPDU mismatch and exits with the partially built MSDU chain, leaking the SKBs. kmemleak reports the leak through: kmemleak_alloc() __netdev_alloc_skb() ath12k_dp_rx_bufs_replenish() ath12k_wifi7_dp_rx_mon_dest_process() Fix this by returning a boolean value from ath12k_dp_mon_comp_ppduid() so the update notification is independent of the actual PPDU ID value. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 72bfbf19b7da ("wifi: ath12k: add support to reap and process mon dest ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260916060325.854-6-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp_mon.c | 15 +++++++-------- drivers/net/wireless/ath/ath12k/dp_mon.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp_mon.c b/drivers/net/wireless/ath/ath12k/dp_mon.c index 1faf1896d0ab..709507d44d8e 100644 --- a/drivers/net/wireless/ath/ath12k/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/dp_mon.c @@ -81,24 +81,23 @@ fail_alloc_skb: } EXPORT_SYMBOL(ath12k_dp_rx_alloc_mon_status_buf); -u32 ath12k_dp_mon_comp_ppduid(u32 msdu_ppdu_id, u32 *ppdu_id) +bool ath12k_dp_mon_comp_ppduid(u32 msdu_ppdu_id, u32 *ppdu_id) { - u32 ret = 0; - if ((*ppdu_id < msdu_ppdu_id) && ((msdu_ppdu_id - *ppdu_id) < DP_NOT_PPDU_ID_WRAP_AROUND)) { /* Hold on mon dest ring, and reap mon status ring. */ *ppdu_id = msdu_ppdu_id; - ret = msdu_ppdu_id; - } else if ((*ppdu_id > msdu_ppdu_id) && - ((*ppdu_id - msdu_ppdu_id) > DP_NOT_PPDU_ID_WRAP_AROUND)) { + return true; + } + if ((*ppdu_id > msdu_ppdu_id) && + ((*ppdu_id - msdu_ppdu_id) > DP_NOT_PPDU_ID_WRAP_AROUND)) { /* PPDU ID has exceeded the maximum value and will * restart from 0. */ *ppdu_id = msdu_ppdu_id; - ret = msdu_ppdu_id; + return true; } - return ret; + return false; } EXPORT_SYMBOL(ath12k_dp_mon_comp_ppduid); diff --git a/drivers/net/wireless/ath/ath12k/dp_mon.h b/drivers/net/wireless/ath/ath12k/dp_mon.h index 162cdcaa57a7..f352655eae9d 100644 --- a/drivers/net/wireless/ath/ath12k/dp_mon.h +++ b/drivers/net/wireless/ath/ath12k/dp_mon.h @@ -100,7 +100,7 @@ struct sk_buff *ath12k_dp_rx_alloc_mon_status_buf(struct ath12k_base *ab, struct dp_rxdma_mon_ring *rx_ring, int *buf_id); -u32 ath12k_dp_mon_comp_ppduid(u32 msdu_ppdu_id, u32 *ppdu_id); +bool ath12k_dp_mon_comp_ppduid(u32 msdu_ppdu_id, u32 *ppdu_id); int ath12k_dp_mon_parse_status_buf(struct ath12k_pdev_dp *dp_pdev, struct ath12k_mon_data *pmon, From febe1f8cbccc3434790bfc4d94d40c9dbd803065 Mon Sep 17 00:00:00 2001 From: Kang Yang Date: Wed, 16 Sep 2026 14:03:25 +0800 Subject: [PATCH 0748/2126] wifi: ath12k: avoid double DMA unmap of held monitor RX buffers ath12k_dp_cc_cleanup() assumes that every rx_desc_info entry with a non-NULL skb still has an active DMA mapping and therefore always calls dma_unmap_single() before freeing the skb. This assumption is not true for the monitor RX path. ath12k_wifi7_dp_rx_mon_mpdu_pop() may DMA-unmap a buffer and mark rxcb->unmapped before returning early to hold the MSDU for later reprocessing. In that state desc_info->skb remains populated, so module removal can trigger a second dma_unmap_single() from ath12k_dp_cc_cleanup(). IOMMU reports the issue as: dma_unmap_phys() dma_unmap_page_attrs() ath12k_dp_cc_cleanup() ath12k_dp_cmn_device_deinit() ath12k_core_stop() Skip dma_unmap_single() when rxcb->unmapped is already set and free the skb directly. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Fixes: 72bfbf19b7da ("wifi: ath12k: add support to reap and process mon dest ring") Signed-off-by: Kang Yang Reviewed-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20260916060325.854-7-kang.yang@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index cce5386c5bd5..83f9edfabf69 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -1002,10 +1002,11 @@ static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) if (!skb) continue; - dma_unmap_single(ab->dev, - ATH12K_SKB_RXCB(skb)->paddr, - skb->len + skb_tailroom(skb), - DMA_FROM_DEVICE); + if (!ATH12K_SKB_RXCB(skb)->unmapped) + dma_unmap_single(ab->dev, + ATH12K_SKB_RXCB(skb)->paddr, + skb->len + skb_tailroom(skb), + DMA_FROM_DEVICE); dev_kfree_skb_any(skb); } From 4e286c780d75831a169b0489afd015214838affd Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Thu, 30 Jul 2026 14:17:40 +0800 Subject: [PATCH 0749/2126] wifi: ath12k: use per-device max QMI chunk size When a target memory chunk fails to allocate, ath12k_qmi_alloc_chunk() compares the requested chunk size against ATH12K_QMI_MAX_CHUNK_SIZE to decide whether to ask the firmware to retry with smaller chunks (-EAGAIN) or to give up (-ENOMEM). This threshold is the boundary that tells a first (big) request apart from a retry (small) request, so it has to match the size the firmware actually falls back to on retry. That fallback size is not the same across all firmware, though. On WCN7850 and QCC2072 the firmware splits the request into 512 KB chunks on retry, whereas on QCN9274, IPQ5332 and IPQ5424 the firmware retries with larger 2 MB segments instead of 512 KB. A single hardcoded 2 MB threshold is therefore wrong for the former, and a hardcoded 512 KB threshold would be wrong for the latter. Replace the hardcoded ATH12K_QMI_MAX_CHUNK_SIZE with a per-device qmi_max_chunk_size parameter: SZ_512K for WCN7850 and QCC2072, SZ_2M for QCN9274, IPQ5332 and IPQ5424. No functional change for the latter (the value stays 2 MB); the former now use the correct 512 KB boundary. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00302-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.115823.3 Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00074-QCACOLSWPL_V1_TO_SILICONZ-1 Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260730-ath12k-align-qmi-memory-v1-1-0fef98dda614@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/hw.h | 1 + drivers/net/wireless/ath/ath12k/qmi.c | 3 +-- drivers/net/wireless/ath/ath12k/wifi7/hw.c | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/hw.h b/drivers/net/wireless/ath/ath12k/hw.h index e790de5737db..1e652dc0d247 100644 --- a/drivers/net/wireless/ath/ath12k/hw.h +++ b/drivers/net/wireless/ath/ath12k/hw.h @@ -166,6 +166,7 @@ struct ath12k_hw_params { u8 max_radios; bool single_pdev_only:1; u32 qmi_service_ins_id; + u32 qmi_max_chunk_size; bool internal_sleep_clock:1; const struct ath12k_hw_ops *hw_ops; diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c index 50082505c882..96c82aa46fc4 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.c +++ b/drivers/net/wireless/ath/ath12k/qmi.c @@ -18,7 +18,6 @@ #define SLEEP_CLOCK_SELECT_INTERNAL_BIT 0x02 #define HOST_CSTATE_BIT 0x04 #define PLATFORM_CAP_PCIE_GLOBAL_RESET 0x08 -#define ATH12K_QMI_MAX_CHUNK_SIZE 2097152 static const struct qmi_elem_info wlfw_host_mlo_chip_info_s_v01_ei[] = { { @@ -2655,7 +2654,7 @@ static int ath12k_qmi_alloc_chunk(struct ath12k_base *ab, &chunk->paddr, GFP_KERNEL | __GFP_NOWARN); if (!chunk->v.addr) { - if (chunk->size > ATH12K_QMI_MAX_CHUNK_SIZE) { + if (chunk->size > ab->hw_params->qmi_max_chunk_size) { ab->qmi.target_mem_delayed = true; ath12k_warn(ab, "qmi dma allocation failed (%u B type %u), will try later with small size\n", diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index ae8df80928b0..aec7c652808c 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../debug.h" #include "../core.h" @@ -369,6 +370,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_radios = 1, .single_pdev_only = false, .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9274, + .qmi_max_chunk_size = SZ_2M, .internal_sleep_clock = false, .hw_ops = &qcn9274_ops, @@ -461,6 +463,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_radios = 1, .single_pdev_only = true, .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_WCN7850, + .qmi_max_chunk_size = SZ_512K, .internal_sleep_clock = true, .hw_ops = &wcn7850_ops, @@ -553,6 +556,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_radios = 2, .single_pdev_only = false, .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9274, + .qmi_max_chunk_size = SZ_2M, .internal_sleep_clock = false, .hw_ops = &qcn9274_ops, @@ -643,6 +647,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_radios = 1, .single_pdev_only = false, .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ5332, + .qmi_max_chunk_size = SZ_2M, .internal_sleep_clock = false, .hw_ops = &qcn9274_ops, @@ -729,6 +734,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_radios = 1, .single_pdev_only = true, .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_WCN7850, + .qmi_max_chunk_size = SZ_512K, .internal_sleep_clock = true, .hw_ops = &qcc2072_ops, @@ -822,6 +828,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_radios = 1, .single_pdev_only = false, .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ5332, + .qmi_max_chunk_size = SZ_2M, .internal_sleep_clock = false, .hw_ops = &qcn9274_ops, From a1af8645cf2dcdac5c6b3929e1dcb2274ca9f27e Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Thu, 30 Jul 2026 14:17:41 +0800 Subject: [PATCH 0750/2126] wifi: ath12k: clear chunk paddr and size in ath12k_qmi_free_target_mem_chunk() paddr and size of a chunk are not cleared after the chunk is freed, which is safe now since the code checks vaddr only and it is properly cleared on free. However, leaving stale values can mislead diagnostics and future maintenance. Clear both to reduce such risk, this also aligns with ath12k_qmi_free_mlo_mem_chunk(). Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00302-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.115823.3 Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00074-QCACOLSWPL_V1_TO_SILICONZ-1 Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260730-ath12k-align-qmi-memory-v1-2-0fef98dda614@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/qmi.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c index 96c82aa46fc4..201e58de0860 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.c +++ b/drivers/net/wireless/ath/ath12k/qmi.c @@ -2602,27 +2602,33 @@ static void ath12k_qmi_free_mlo_mem_chunk(struct ath12k_base *ab, static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab) { struct ath12k_hw_group *ag = ab->ag; + struct target_mem_chunk *chunk; int i, mlo_idx; for (i = 0, mlo_idx = 0; i < ab->qmi.mem_seg_count; i++) { - if (ab->qmi.target_mem[i].type == MLO_GLOBAL_MEM_REGION_TYPE) { + chunk = &ab->qmi.target_mem[i]; + + if (chunk->type == MLO_GLOBAL_MEM_REGION_TYPE) { ath12k_qmi_free_mlo_mem_chunk(ab, - &ab->qmi.target_mem[i], + chunk, mlo_idx++); } else { if (test_bit(ATH12K_FLAG_FIXED_MEM_REGION, &ab->dev_flags) && - ab->qmi.target_mem[i].v.ioaddr) { - iounmap(ab->qmi.target_mem[i].v.ioaddr); - ab->qmi.target_mem[i].v.ioaddr = NULL; + chunk->v.ioaddr) { + iounmap(chunk->v.ioaddr); + chunk->v.ioaddr = NULL; } else { - if (!ab->qmi.target_mem[i].v.addr) + if (!chunk->v.addr) continue; dma_free_coherent(ab->dev, - ab->qmi.target_mem[i].prev_size, - ab->qmi.target_mem[i].v.addr, - ab->qmi.target_mem[i].paddr); - ab->qmi.target_mem[i].v.addr = NULL; + chunk->prev_size, + chunk->v.addr, + chunk->paddr); + chunk->v.addr = NULL; } + + chunk->paddr = 0; + chunk->size = 0; } } From f7f05c443361ebaa503e054e882633913273b3fa Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Thu, 30 Jul 2026 14:17:42 +0800 Subject: [PATCH 0751/2126] wifi: ath12k: align QMI target memory to 64 KB ath12k_qmi_alloc_chunk() allocates the target memory chunks the firmware requests via dma_alloc_coherent() and hands the resulting physical addresses to the firmware. The firmware does not require every chunk to be aligned, but each unaligned chunk consumes extra TLB entries when the firmware maps it, and too many unaligned chunks exhaust the TLB and make the firmware crash. The firmware team recommends aligning the chunks to 64 KB so that the TLB stays within budget. dma_alloc_coherent() only guarantees page alignment, so a chunk can end up unaligned. Align the physical address handed to the firmware to 64 KB. A natural allocation is often already 64 KB aligned, so try the exact size first and keep it when it happens to be aligned; only when it is not, free it and over-allocate by SZ_64K - PAGE_SIZE and round the base up. Since the DMA allocator already guarantees page alignment, that padding is enough to reach the next 64 KB boundary. Record the raw allocation in paddr_unaligned/vaddr_unaligned/total_size so the chunk can still be freed correctly. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00302-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.115823.3 Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00074-QCACOLSWPL_V1_TO_SILICONZ-1 Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260730-ath12k-align-qmi-memory-v1-3-0fef98dda614@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/qmi.c | 79 +++++++++++++++++++++------ drivers/net/wireless/ath/ath12k/qmi.h | 4 ++ 2 files changed, 65 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c index 201e58de0860..817bd820623d 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.c +++ b/drivers/net/wireless/ath/ath12k/qmi.c @@ -14,6 +14,7 @@ #include #include #include +#include #define SLEEP_CLOCK_SELECT_INTERNAL_BIT 0x02 #define HOST_CSTATE_BIT 0x04 @@ -2583,20 +2584,28 @@ static void ath12k_qmi_free_mlo_mem_chunk(struct ath12k_base *ab, mlo_chunk->v.ioaddr = NULL; } else if (mlo_chunk->v.addr) { dma_free_coherent(ab->dev, - mlo_chunk->size, - mlo_chunk->v.addr, - mlo_chunk->paddr); + mlo_chunk->total_size, + mlo_chunk->vaddr_unaligned, + mlo_chunk->paddr_unaligned); + mlo_chunk->vaddr_unaligned = NULL; mlo_chunk->v.addr = NULL; } mlo_chunk->paddr = 0; + mlo_chunk->paddr_unaligned = 0; mlo_chunk->size = 0; - if (fixed_mem) + mlo_chunk->total_size = 0; + + if (fixed_mem) { chunk->v.ioaddr = NULL; - else + } else { chunk->v.addr = NULL; + chunk->vaddr_unaligned = NULL; + } chunk->paddr = 0; + chunk->paddr_unaligned = 0; chunk->size = 0; + chunk->total_size = 0; } static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab) @@ -2621,14 +2630,17 @@ static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab) if (!chunk->v.addr) continue; dma_free_coherent(ab->dev, - chunk->prev_size, - chunk->v.addr, - chunk->paddr); + chunk->total_size, + chunk->vaddr_unaligned, + chunk->paddr_unaligned); + chunk->vaddr_unaligned = NULL; chunk->v.addr = NULL; } chunk->paddr = 0; + chunk->paddr_unaligned = 0; chunk->size = 0; + chunk->total_size = 0; } } @@ -2641,6 +2653,10 @@ static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab) static int ath12k_qmi_alloc_chunk(struct ath12k_base *ab, struct target_mem_chunk *chunk) { + dma_addr_t paddr; + size_t size; + void *vaddr; + /* Firmware reloads in recovery/resume. * In such cases, no need to allocate memory for FW again. */ @@ -2650,29 +2666,56 @@ static int ath12k_qmi_alloc_chunk(struct ath12k_base *ab, goto this_chunk_done; /* cannot reuse the existing chunk */ - dma_free_coherent(ab->dev, chunk->prev_size, - chunk->v.addr, chunk->paddr); + dma_free_coherent(ab->dev, chunk->total_size, + chunk->vaddr_unaligned, chunk->paddr_unaligned); chunk->v.addr = NULL; + chunk->vaddr_unaligned = NULL; + chunk->paddr_unaligned = 0; + chunk->total_size = 0; } - chunk->v.addr = dma_alloc_coherent(ab->dev, - chunk->size, - &chunk->paddr, + /* + * Each unaligned chunk costs the firmware extra TLB entries when + * mapping it, and too many unaligned chunks exhaust the TLB and + * crash the firmware, so align the base to 64 KB. The DMA + * allocator only guarantees page alignment, but a natural + * allocation is often already 64 KB aligned. Try the exact size + * first and keep it when it happens to be aligned; only fall back + * to over-allocating and rounding up when it is not. + */ + size = chunk->size; + vaddr = dma_alloc_coherent(ab->dev, size, &paddr, + GFP_KERNEL | __GFP_NOWARN); + if (vaddr && !IS_ALIGNED(paddr, SZ_64K)) { + dma_free_coherent(ab->dev, size, vaddr, paddr); + + size = chunk->size + SZ_64K - PAGE_SIZE; + vaddr = dma_alloc_coherent(ab->dev, size, &paddr, GFP_KERNEL | __GFP_NOWARN); - if (!chunk->v.addr) { + } + + if (!vaddr) { if (chunk->size > ab->hw_params->qmi_max_chunk_size) { ab->qmi.target_mem_delayed = true; ath12k_warn(ab, - "qmi dma allocation failed (%u B type %u), will try later with small size\n", - chunk->size, + "qmi dma allocation failed (%zu B type %u), will try later with small size\n", + size, chunk->type); ath12k_qmi_free_target_mem_chunk(ab); return -EAGAIN; } - ath12k_warn(ab, "memory allocation failure for %u size: %u\n", - chunk->type, chunk->size); + ath12k_warn(ab, "memory allocation failure for %u size: %zu\n", + chunk->type, size); return -ENOMEM; } + + chunk->vaddr_unaligned = vaddr; + chunk->paddr_unaligned = paddr; + chunk->total_size = size; + + chunk->paddr = ALIGN(paddr, SZ_64K); + chunk->v.addr = (u8 *)vaddr + (chunk->paddr - paddr); + chunk->prev_type = chunk->type; chunk->prev_size = chunk->size; this_chunk_done: diff --git a/drivers/net/wireless/ath/ath12k/qmi.h b/drivers/net/wireless/ath/ath12k/qmi.h index 6da10f3cb597..1b1c88906f1e 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.h +++ b/drivers/net/wireless/ath/ath12k/qmi.h @@ -100,6 +100,10 @@ struct target_mem_chunk { void __iomem *ioaddr; void *addr; } v; + + dma_addr_t paddr_unaligned; + void *vaddr_unaligned; + u32 total_size; }; struct target_info { From 64828f091c7de5c1324427b140fb545f93ef073f Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Mon, 17 Aug 2026 16:46:34 -0700 Subject: [PATCH 0752/2126] wifi: ath11k: fix reg_info_store leak in ath11k_service_ready_ext_event() Currently, while processing the WMI Service Ready Ext event, the iterator in ath11k_service_ready_ext_event() can dispatch the HAL Regulatory Capabilities handler ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse() which can allocate ab->reg_info_store. If a subsequent failure occurs during iteration, the ab->reg_info_store allocation is leaked. Directly free and clear the pointer on the error path. Note that the normal cleanup function ath11k_reg_free() cannot be used since other regulatory-related fields are not yet populated at this point. Compile tested only. Fixes: 7004bdceef60 ("wifi: ath11k: store cur_regulatory_info for each radio") Assisted-by: Claude:claude-sonnet-4-6 Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260817-reg_info_store-leak-v1-1-77025a99b074@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/wmi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wireless/ath/ath11k/wmi.c b/drivers/net/wireless/ath/ath11k/wmi.c index bbca275a8289..08fd6795ed9e 100644 --- a/drivers/net/wireless/ath/ath11k/wmi.c +++ b/drivers/net/wireless/ath/ath11k/wmi.c @@ -5136,6 +5136,15 @@ static int ath11k_service_ready_ext_event(struct ath11k_base *ab, err: kfree(svc_rdy_ext.mac_phy_caps); + + /* + * During TLV iteration the WMI_TAG_SOC_HAL_REG_CAPABILITIES + * handler may have allocated ab->reg_info_store, so free it + * on error to avoid a memory leak + */ + kfree(ab->reg_info_store); + ab->reg_info_store = NULL; + ath11k_wmi_free_dbring_caps(ab); return ret; } From e1ef274a49873a9545b51e36f1f1d25707372872 Mon Sep 17 00:00:00 2001 From: Miaoqing Pan Date: Mon, 3 Aug 2026 09:05:32 +0800 Subject: [PATCH 0753/2126] wifi: ath12k: remove unused ath12k_dp_rx_h_find_link_peer() ath12k_dp_rx_h_find_link_peer() is no longer referenced anywhere, remove the unused helper and its declaration to avoid dead code. Tested-on: QCC2072 hw1.0 PCI CI_WLAN.COL.1.0.c2-00229.1-QCACOLSWPL_V1_TO_SILICON-1 Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Signed-off-by: Miaoqing Pan Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260803010532.302038-1-miaoqing.pan@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/dp_rx.c | 21 --------------------- drivers/net/wireless/ath/ath12k/dp_rx.h | 3 --- 2 files changed, 24 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c index 8bb2b57aed15..cfaf26ae2720 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/dp_rx.c @@ -1204,27 +1204,6 @@ void ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu } EXPORT_SYMBOL(ath12k_dp_rx_h_undecap); -struct ath12k_dp_link_peer * -ath12k_dp_rx_h_find_link_peer(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu, - struct hal_rx_desc_data *rx_info) -{ - struct ath12k_skb_rxcb *rxcb = ATH12K_SKB_RXCB(msdu); - struct ath12k_dp_link_peer *peer = NULL; - struct ath12k_dp *dp = dp_pdev->dp; - - lockdep_assert_held(&dp->dp_lock); - - peer = ath12k_dp_link_peer_find_by_peerid(dp_pdev, rxcb->peer_id); - - if (peer) - return peer; - - if (rx_info->addr2_present) - peer = ath12k_dp_link_peer_find_by_addr(dp, rx_info->addr2); - - return peer; -} - static void ath12k_dp_rx_h_rate(struct ath12k_pdev_dp *dp_pdev, struct hal_rx_desc_data *rx_info) { diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.h b/drivers/net/wireless/ath/ath12k/dp_rx.h index 0660db070e92..82700474548a 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.h +++ b/drivers/net/wireless/ath/ath12k/dp_rx.h @@ -237,9 +237,6 @@ int ath12k_dp_rx_peer_frag_setup(struct ath12k *ar, const u8 *peer_mac, int vdev u8 ath12k_dp_rx_h_l3pad(struct ath12k_base *ab, struct hal_rx_desc *desc); -struct ath12k_dp_link_peer * -ath12k_dp_rx_h_find_link_peer(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu, - struct hal_rx_desc_data *rx_info); u8 ath12k_dp_rx_h_decap_type(struct ath12k_base *ab, struct hal_rx_desc *desc); u32 ath12k_dp_rx_h_mpdu_err(struct ath12k_base *ab, From c8f83d3389d1d1b318ac3bd2ae3d60c2862c90b4 Mon Sep 17 00:00:00 2001 From: Pardeep Kaur Date: Wed, 19 Aug 2026 11:02:40 +0530 Subject: [PATCH 0754/2126] wifi: ath12k: fix out-of-bounds access on TX stats arrays The fw_tx_status[], tx_wbm_rel_source[], and tqm_rel_reason[] arrays are indexed directly by values read from hardware without bounds checks. Values at or beyond MAX_FW_TX_STATUS, HAL_WBM_REL_SRC_MODULE_MAX, or MAX_TQM_RELEASE_REASON respectively would write past the end of the arrays causing memory corruption. Add likely() bounds checks before incrementing each counter. For tx_wbm_rel_source[] and tqm_rel_reason[], add WARN_ON_ONCE() on the out-of-bounds else branch. For fw_tx_status[], no WARN_ON_ONCE is added since the switch statement that follows already calls ath12k_warn() in its default: branch for unknown values, avoiding a double-warn. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Fixes: c5c62287e690 ("wifi: ath12k: Add device dp stats support") Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-2-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 3f6df96de160..4ce0948d429f 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -589,7 +589,8 @@ ath12k_dp_tx_process_htt_tx_complete(struct ath12k_dp *dp, void *desc, wbm_status = le32_get_bits(status_desc->info0, HTT_TX_WBM_COMP_INFO0_STATUS); - dp->device_stats.fw_tx_status[wbm_status]++; + if (likely(wbm_status < MAX_FW_TX_STATUS)) + dp->device_stats.fw_tx_status[wbm_status]++; switch (wbm_status) { case HAL_WBM_REL_HTT_TX_COMP_STATUS_OK: @@ -993,11 +994,17 @@ void ath12k_wifi7_dp_tx_completion_handler(struct ath12k_dp *dp, int ring_id) /* Find the HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE value */ buf_rel_source = le32_get_bits(tx_status->info0, HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE); - dp->device_stats.tx_wbm_rel_source[buf_rel_source]++; + if (likely(buf_rel_source < HAL_WBM_REL_SRC_MODULE_MAX)) + dp->device_stats.tx_wbm_rel_source[buf_rel_source]++; + else + WARN_ON_ONCE(1); rel_status = le32_get_bits(tx_status->info0, HAL_WBM_COMPL_TX_INFO0_TQM_RELEASE_REASON); - dp->device_stats.tqm_rel_reason[rel_status]++; + if (likely(rel_status < MAX_TQM_RELEASE_REASON)) + dp->device_stats.tqm_rel_reason[rel_status]++; + else + WARN_ON_ONCE(1); /* Release descriptor as soon as extracting necessary info * to reduce contention From 90396f4a01fe2e14c2a31540a73fde4c7c1cc8d5 Mon Sep 17 00:00:00 2001 From: Hariharan Ramanathan Date: Wed, 19 Aug 2026 11:02:41 +0530 Subject: [PATCH 0755/2126] wifi: ath12k: rename wbm_status to htt_status in HTT TX completion The variable wbm_status in ath12k_dp_tx_process_htt_tx_complete() holds a value from the HTT TX WBM completion status field, not a generic WBM status. Rename it to htt_status to accurately reflect the field origin and improve code clarity. Also fix ts.acked assignment inside the HAL_WBM_REL_HTT_TX_COMP_STATUS_OK case to use true directly since the condition is always true within that case branch. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Hariharan Ramanathan Co-developed-by: Pardeep Kaur Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-3-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 4ce0948d429f..962abe7f3089 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -582,19 +582,19 @@ ath12k_dp_tx_process_htt_tx_complete(struct ath12k_dp *dp, void *desc, { struct htt_tx_wbm_completion *status_desc; struct ath12k_dp_htt_wbm_tx_status ts = {}; - enum hal_wbm_htt_tx_comp_status wbm_status; + enum hal_wbm_htt_tx_comp_status htt_status; u16 peer_id; status_desc = desc; - wbm_status = le32_get_bits(status_desc->info0, + htt_status = le32_get_bits(status_desc->info0, HTT_TX_WBM_COMP_INFO0_STATUS); - if (likely(wbm_status < MAX_FW_TX_STATUS)) - dp->device_stats.fw_tx_status[wbm_status]++; + if (likely(htt_status < MAX_FW_TX_STATUS)) + dp->device_stats.fw_tx_status[htt_status]++; - switch (wbm_status) { + switch (htt_status) { case HAL_WBM_REL_HTT_TX_COMP_STATUS_OK: - ts.acked = (wbm_status == HAL_WBM_REL_HTT_TX_COMP_STATUS_OK); + ts.acked = true; ts.ack_rssi = le32_get_bits(status_desc->info2, HTT_TX_WBM_COMP_INFO2_ACK_RSSI); @@ -616,7 +616,7 @@ ath12k_dp_tx_process_htt_tx_complete(struct ath12k_dp *dp, void *desc, */ break; default: - ath12k_warn(dp->ab, "Unknown htt wbm tx status %d\n", wbm_status); + ath12k_warn(dp->ab, "Unknown htt tx status %d\n", htt_status); break; } } From 6fec999446d926e1f5d2c0efc306134f64f29686 Mon Sep 17 00:00:00 2001 From: Hariharan Ramanathan Date: Wed, 19 Aug 2026 11:02:42 +0530 Subject: [PATCH 0756/2126] wifi: ath12k: add TCL ring TX buffer allocation failure counter When ath12k_dp_tx_assign_buffer() fails, the TX path returns -ENOMEM silently with no visibility into which traffic class is affected. Without a counter, TX descriptor pool exhaustion is invisible during debugging. Add txbuf_na[] indexed by pool_id to ath12k_device_dp_tx_err_stats to track TX descriptor pool allocation failures per traffic class and increment it on assign failure in the TX path. Expose the per-pool counts in debugfs under a new 'TX Descriptor Pool Alloc Failures' section. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Hariharan Ramanathan Co-developed-by: Pardeep Kaur Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-4-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs.c | 5 +++++ drivers/net/wireless/ath/ath12k/dp.h | 2 ++ drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c index d54995b7adb2..ec49692107a8 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -1117,6 +1117,11 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, len += scnprintf(buf + len, size - len, "ring%d: %u\n", i, device_stats->tx_err.desc_na[i]); + len += scnprintf(buf + len, size - len, "\nTX Descriptor Pool Alloc Failures:\n"); + for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) + len += scnprintf(buf + len, size - len, "pool%d: %u\n", + i, device_stats->tx_err.txbuf_na[i]); + len += scnprintf(buf + len, size - len, "\nMisc Transmit Failures: %d\n", atomic_read(&device_stats->tx_err.misc_fail)); diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index ff62773cfa9a..230a74d48c8b 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -409,6 +409,8 @@ struct ath12k_dp_arch_ops { struct ath12k_device_dp_tx_err_stats { /* TCL Ring Descriptor unavailable */ u32 desc_na[DP_TCL_NUM_RING_MAX]; + /* TX descriptor pool exhausted (per pool_id / traffic class) */ + u32 txbuf_na[ATH12K_HW_MAX_QUEUES]; /* Other failures during dp_tx due to mem allocation failure * idr unavailable etc. */ diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c index 962abe7f3089..41abf1865702 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c @@ -167,8 +167,10 @@ tcl_ring_sel: tx_ring = &dp->tx_ring[ti.ring_id]; tx_desc = ath12k_dp_tx_assign_buffer(dp, pool_id); - if (!tx_desc) + if (!tx_desc) { + dp->device_stats.tx_err.txbuf_na[pool_id]++; return -ENOMEM; + } dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, arvif->link_id); From 26e095b0801ab6d24cf20b37eb377bae3ff39715 Mon Sep 17 00:00:00 2001 From: Hariharan Ramanathan Date: Wed, 19 Aug 2026 11:02:43 +0530 Subject: [PATCH 0757/2126] wifi: ath12k: add device DP stats reset support via debugfs There is no way to reset device DP stats counters without reloading the driver, making it difficult to isolate issues to a specific time window during debugging. Add a write handler to the device_dp_stats debugfs file so that writing 'reset' clears all device DP stats counters. Change the file mode from 0400 to 0600 to allow write access. Use simple_write_to_buffer() to correctly handle partial writes and non-zero ppos, consistent with ath12k_write_simulate_fw_crash(). No lock is taken around the memset since the counters are updated locklessly in the datapath; taking dp_lock would be misleading as it does not protect device_stats updates. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Hariharan Ramanathan Co-developed-by: Pardeep Kaur Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-5-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs.c | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c index ec49692107a8..68acb4cb9c4f 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -1220,8 +1220,40 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, return ret; } +static ssize_t +ath12k_debugfs_write_device_dp_stats(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct ath12k_base *ab = file->private_data; + struct ath12k_dp *dp = ath12k_ab_to_dp(ab); + struct ath12k_device_dp_stats *device_stats = &dp->device_stats; + char buf[20] = {}; + int ret; + + /* filter partial writes and invalid commands */ + if (*ppos != 0 || count >= sizeof(buf) || count == 0) + return -EINVAL; + + ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); + if (ret < 0) + return ret; + + /* drop the possible '\n' from the end */ + if (buf[*ppos - 1] == '\n') + buf[*ppos - 1] = '\0'; + + if (!strcmp(buf, "reset")) { + memset(device_stats, 0, sizeof(*device_stats)); + return count; + } + + return -EINVAL; +} + static const struct file_operations fops_device_dp_stats = { .read = ath12k_debugfs_dump_device_dp_stats, + .write = ath12k_debugfs_write_device_dp_stats, .open = simple_open, .owner = THIS_MODULE, .llseek = default_llseek, @@ -1232,7 +1264,7 @@ void ath12k_debugfs_pdev_create(struct ath12k_base *ab) debugfs_create_file("simulate_fw_crash", 0600, ab->debugfs_soc, ab, &fops_simulate_fw_crash); - debugfs_create_file("device_dp_stats", 0400, ab->debugfs_soc, ab, + debugfs_create_file("device_dp_stats", 0600, ab->debugfs_soc, ab, &fops_device_dp_stats); } From 0f4f1fe45e4b49311e9cd0fffdd3290f57b5afe1 Mon Sep 17 00:00:00 2001 From: Aniruddha Mishra Date: Wed, 19 Aug 2026 11:02:44 +0530 Subject: [PATCH 0758/2126] wifi: ath12k: add WBM RX error drop statistics Without fine-grained drop counters, diagnosing RX failures in the WBM error path requires intrusive debugging. Introduce per-drop-reason counters to track exactly where and why packets are dropped during WBM RX error handling. Introduce a new dp_stats.h header and define ath12k_wbm_err_drop_reason enum there covering all drop points in the WBM RX error path: descriptor parse failures, SW descriptor retrieval errors, null partner DP, invalid HW link ID, null pdev/ar, CAC running, scatter-gather drops, and invalid NWifi header length. The new header is included by dp.h which is already included by all consumers. Add ath12k_device_dp_rx_wbm_err_stats struct grouping rxdma_error[], reo_error[], and the new drop[] counters, replacing the flat arrays previously in ath12k_device_dp_stats. Add bounds checks before indexing rxdma_error[] and reo_error[] with hardware-supplied err_code values to prevent out-of-bounds writes, using the same likely/WARN_ON_ONCE pattern as the TX stats bounds fixes. Add ath12k_wifi7_dp_rx_wbm_err_free_skb() helper to combine drop stat increment and skb free at each drop site, reducing repetition. Define the helper at the top of dp_rx.c before its first use. Increment WBM_ERR_DROP_RXDMA_GENERIC only inside rxdma_err()'s default: branch so it counts only unhandled RXDMA errors, not every RXDMA drop - consistent with how WBM_ERR_DROP_REO_GENERIC is counted. Expose WBM RX drop counts in the device_dp_stats debugfs file under a new 'WBM Rx Drop Count' section. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aniruddha Mishra Co-developed-by: Pardeep Kaur Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-6-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs.c | 23 ++++++++- drivers/net/wireless/ath/ath12k/dp.h | 10 +++- drivers/net/wireless/ath/ath12k/dp_stats.h | 25 ++++++++++ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 47 +++++++++++++++---- .../net/wireless/ath/ath12k/wifi7/hal_rx.c | 5 +- 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 drivers/net/wireless/ath/ath12k/dp_stats.h diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c index 68acb4cb9c4f..935da8d06450 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -1071,6 +1071,20 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, [HAL_REO_DEST_RING_ERROR_CODE_PN_ERR_FLAG_SET] = "PN err", [HAL_REO_DEST_RING_ERROR_CODE_DESC_BLOCKED] = "Desc blocked"}; + static const char *wbm_rx_drop[WBM_ERR_DROP_MAX] = { + [WBM_ERR_DROP_GET_SW_DESC] = "SW desc error", + [WBM_ERR_DROP_DESC_PARSE] = "Desc parse error", + [WBM_ERR_DROP_INV_HW_ID] = "Invalid hw id", + [WBM_ERR_DROP_NULL_PRTNR_DP] = "Null Partner dp", + [WBM_ERR_DROP_NULL_PROC_DP] = "Process Null Partner dp", + [WBM_ERR_DROP_NULL_PDEV] = "Null Pdev", + [WBM_ERR_DROP_NULL_AR] = "Null ar", + [WBM_ERR_DROP_CAC_RUNNING] = "CAC Running", + [WBM_ERR_DROP_SG] = "Scatter Gather", + [WBM_ERR_DROP_INV_NWIFI_HDR] = "Invalid NWifi Hdr len", + [WBM_ERR_DROP_REO_GENERIC] = "REO Generic", + [WBM_ERR_DROP_RXDMA_GENERIC] = "RXDMA Generic"}; + static const char *wbm_rel_src[HAL_WBM_REL_SRC_MODULE_MAX] = { [HAL_WBM_REL_SRC_MODULE_TQM] = "TQM", [HAL_WBM_REL_SRC_MODULE_RXDMA] = "Rxdma", @@ -1095,13 +1109,18 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, for (i = 0; i < HAL_REO_ENTR_RING_RXDMA_ECODE_MAX; i++) len += scnprintf(buf + len, size - len, "%s: %u\n", - rxdma_err[i], device_stats->rxdma_error[i]); + rxdma_err[i], device_stats->wbm_err.rxdma_error[i]); len += scnprintf(buf + len, size - len, "\nREO errors:\n"); for (i = 0; i < HAL_REO_DEST_RING_ERROR_CODE_MAX; i++) len += scnprintf(buf + len, size - len, "%s: %u\n", - reo_err[i], device_stats->reo_error[i]); + reo_err[i], device_stats->wbm_err.reo_error[i]); + + len += scnprintf(buf + len, size - len, "\nWBM Rx Drop Count:\n"); + for (i = 0; i < WBM_ERR_DROP_MAX; i++) + len += scnprintf(buf + len, size - len, "%s: %u\n", + wbm_rx_drop[i], device_stats->wbm_err.drop[i]); len += scnprintf(buf + len, size - len, "\nHAL REO errors:\n"); diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 230a74d48c8b..3765bcd09c51 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -7,6 +7,7 @@ #ifndef ATH12K_DP_H #define ATH12K_DP_H +#include "dp_stats.h" #include "hw.h" #include "dp_htt.h" #include "dp_cmn.h" @@ -417,13 +418,18 @@ struct ath12k_device_dp_tx_err_stats { atomic_t misc_fail; }; +struct ath12k_device_dp_rx_wbm_err_stats { + u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX]; + u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX]; + u32 drop[WBM_ERR_DROP_MAX]; +}; + struct ath12k_device_dp_stats { u32 err_ring_pkts; u32 invalid_rbm; - u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX]; - u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX]; u32 hal_reo_error[DP_REO_DST_RING_MAX]; struct ath12k_device_dp_tx_err_stats tx_err; + struct ath12k_device_dp_rx_wbm_err_stats wbm_err; u32 reo_rx[DP_REO_DST_RING_MAX][ATH12K_MAX_DEVICES]; u32 rx_wbm_rel_source[HAL_WBM_REL_SRC_MODULE_MAX][ATH12K_MAX_DEVICES]; u32 tqm_rel_reason[MAX_TQM_RELEASE_REASON]; diff --git a/drivers/net/wireless/ath/ath12k/dp_stats.h b/drivers/net/wireless/ath/ath12k/dp_stats.h new file mode 100644 index 000000000000..1a05256dbf74 --- /dev/null +++ b/drivers/net/wireless/ath/ath12k/dp_stats.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#ifndef ATH12K_DP_STATS_H +#define ATH12K_DP_STATS_H + +enum ath12k_wbm_err_drop_reason { + WBM_ERR_DROP_GET_SW_DESC, + WBM_ERR_DROP_DESC_PARSE, + WBM_ERR_DROP_INV_HW_ID, + WBM_ERR_DROP_NULL_PRTNR_DP, + WBM_ERR_DROP_NULL_PROC_DP, + WBM_ERR_DROP_NULL_PDEV, + WBM_ERR_DROP_NULL_AR, + WBM_ERR_DROP_CAC_RUNNING, + WBM_ERR_DROP_SG, + WBM_ERR_DROP_INV_NWIFI_HDR, + WBM_ERR_DROP_REO_GENERIC, + WBM_ERR_DROP_RXDMA_GENERIC, + WBM_ERR_DROP_MAX, +}; + +#endif /* ATH12K_DP_STATS_H */ diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index 8b722ee0ad8f..721eb25be1a9 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -12,6 +12,15 @@ #include "hal_wcn7850.h" #include "hal_qcc2072.h" +static void +ath12k_wifi7_dp_rx_wbm_err_free_skb(struct ath12k_dp *dp, + struct sk_buff *msdu, + enum ath12k_wbm_err_drop_reason drop_reason) +{ + dp->device_stats.wbm_err.drop[drop_reason]++; + dev_kfree_skb_any(msdu); +} + static u16 ath12k_wifi7_dp_rx_get_peer_id(struct ath12k_dp *dp, enum ath12k_peer_metadata_version ver, __le32 peer_metadata) @@ -642,7 +651,6 @@ ath12k_wifi7_dp_rx_process_received_packets(struct ath12k_dp *dp, dev_kfree_skb_any(msdu); continue; } - ath12k_dp_rx_deliver_msdu(dp_pdev, napi, msdu, &rx_info); } @@ -1614,6 +1622,7 @@ static int ath12k_wifi7_dp_rx_h_null_q_desc(struct ath12k_pdev_dp *dp_pdev, /* First buffer will be freed by the caller, so deduct it's length */ msdu_len = msdu_len - (DP_RX_BUFFER_SIZE - hal_rx_desc_sz); ath12k_wifi7_dp_rx_null_q_desc_sg_drop(dp, msdu_len, msdu_list); + dp->device_stats.wbm_err.drop[WBM_ERR_DROP_SG]++; return -EINVAL; } @@ -1649,8 +1658,10 @@ static int ath12k_wifi7_dp_rx_h_null_q_desc(struct ath12k_pdev_dp *dp_pdev, skb_put(msdu, hal_rx_desc_sz + l3pad_bytes + msdu_len); skb_pull(msdu, hal_rx_desc_sz + l3pad_bytes); } - if (unlikely(!ath12k_dp_rx_check_nwifi_hdr_len_valid(dp, msdu, rx_info))) + if (unlikely(!ath12k_dp_rx_check_nwifi_hdr_len_valid(dp, msdu, rx_info))) { + dp->device_stats.wbm_err.drop[WBM_ERR_DROP_INV_NWIFI_HDR]++; return -EINVAL; + } ath12k_dp_rx_h_ppdu(dp_pdev, rx_info); ret = ath12k_wifi7_dp_rx_h_mpdu(dp_pdev, msdu, rx_info); @@ -1763,7 +1774,10 @@ static bool ath12k_wifi7_dp_rx_h_rxdma_err(struct ath12k_pdev_dp *dp_pdev, struct ath12k_skb_rxcb *rxcb = ATH12K_SKB_RXCB(msdu); bool drop = false; - dp->device_stats.rxdma_error[rxcb->err_code]++; + if (likely(rxcb->err_code < HAL_REO_ENTR_RING_RXDMA_ECODE_MAX)) + dp->device_stats.wbm_err.rxdma_error[rxcb->err_code]++; + else + WARN_ON_ONCE(1); switch (rxcb->err_code) { case HAL_REO_ENTR_RING_RXDMA_ECODE_UNAUTH_WDS_ERR: @@ -1780,6 +1794,7 @@ static bool ath12k_wifi7_dp_rx_h_rxdma_err(struct ath12k_pdev_dp *dp_pdev, /* TODO: Review other rxdma error code to check if anything is * worth reporting to mac80211 */ + dp->device_stats.wbm_err.drop[WBM_ERR_DROP_RXDMA_GENERIC]++; drop = true; break; } @@ -1796,7 +1811,10 @@ static bool ath12k_wifi7_dp_rx_h_reo_err(struct ath12k_pdev_dp *dp_pdev, struct ath12k_skb_rxcb *rxcb = ATH12K_SKB_RXCB(msdu); bool drop = false; - dp->device_stats.reo_error[rxcb->err_code]++; + if (likely(rxcb->err_code < HAL_REO_DEST_RING_ERROR_CODE_MAX)) + dp->device_stats.wbm_err.reo_error[rxcb->err_code]++; + else + WARN_ON_ONCE(1); switch (rxcb->err_code) { case HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO: @@ -1813,6 +1831,7 @@ static bool ath12k_wifi7_dp_rx_h_reo_err(struct ath12k_pdev_dp *dp_pdev, /* TODO: Review other errors and process them to mac80211 * as appropriate. */ + dp->device_stats.wbm_err.drop[WBM_ERR_DROP_REO_GENERIC]++; drop = true; break; } @@ -1935,6 +1954,7 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, ret = ath12k_wifi7_hal_wbm_desc_parse_err(dp, rx_desc, &err_info); if (ret) { + dp->device_stats.wbm_err.drop[WBM_ERR_DROP_DESC_PARSE]++; ath12k_warn(ab, "failed to parse rx error in wbm_rel ring desc %d\n", ret); continue; @@ -1946,6 +1966,7 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, if (!desc_info) { desc_info = ath12k_dp_get_rx_desc(dp, err_info.cookie); if (!desc_info) { + dp->device_stats.wbm_err.drop[WBM_ERR_DROP_GET_SW_DESC]++; ath12k_warn(ab, "Invalid cookie in DP WBM rx error descriptor retrieval: 0x%x\n", err_info.cookie); continue; @@ -1961,7 +1982,8 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, device_id = desc_info->device_id; partner_dp = ath12k_dp_hw_grp_to_dp(dp_hw_grp, device_id); if (unlikely(!partner_dp)) { - dev_kfree_skb_any(msdu); + ath12k_wifi7_dp_rx_wbm_err_free_skb(dp, msdu, + WBM_ERR_DROP_NULL_PRTNR_DP); /* In any case continuation bit is set * in the previous record, cleanup scatter_msdu_list @@ -2007,7 +2029,8 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, hw_link_id = ath12k_dp_rx_get_msdu_src_link(partner_dp->hal, msdu_data); if (hw_link_id >= ATH12K_GROUP_MAX_RADIO) { - dev_kfree_skb_any(msdu); + ath12k_wifi7_dp_rx_wbm_err_free_skb(dp, msdu, + WBM_ERR_DROP_INV_HW_ID); /* In any case continuation bit is set * in the previous record, cleanup scatter_msdu_list @@ -2068,7 +2091,8 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, ath12k_dbg(ab, ATH12K_DBG_DATA, "Unable to process WBM error msdu due to invalid hw link id %d device id %d\n", hw_link_id, device_id); - dev_kfree_skb_any(msdu); + ath12k_wifi7_dp_rx_wbm_err_free_skb(dp, msdu, + WBM_ERR_DROP_NULL_PROC_DP); continue; } @@ -2077,18 +2101,21 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, dp_pdev = ath12k_dp_to_pdev_dp(partner_dp, pdev_idx); if (!dp_pdev) { - dev_kfree_skb_any(msdu); + ath12k_wifi7_dp_rx_wbm_err_free_skb(dp, msdu, + WBM_ERR_DROP_NULL_PDEV); continue; } ar = ath12k_pdev_dp_to_ar(dp_pdev); if (!ar || !rcu_dereference(ar->ab->pdevs_active[pdev_idx])) { - dev_kfree_skb_any(msdu); + ath12k_wifi7_dp_rx_wbm_err_free_skb(dp, msdu, + WBM_ERR_DROP_NULL_AR); continue; } if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) { - dev_kfree_skb_any(msdu); + ath12k_wifi7_dp_rx_wbm_err_free_skb(dp, msdu, + WBM_ERR_DROP_CAC_RUNNING); continue; } diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_rx.c index 49c693289709..60e7a36097f1 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_rx.c @@ -329,7 +329,10 @@ int ath12k_wifi7_hal_desc_reo_parse_err(struct ath12k_dp *dp, HAL_REO_DEST_RING_INFO0_PUSH_REASON); err_code = le32_get_bits(desc->info0, HAL_REO_DEST_RING_INFO0_ERROR_CODE); - dp->device_stats.reo_error[err_code]++; + if (likely(err_code < HAL_REO_DEST_RING_ERROR_CODE_MAX)) + dp->device_stats.wbm_err.reo_error[err_code]++; + else + WARN_ON_ONCE(1); if (push_reason != HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED && push_reason != HAL_REO_DEST_RING_PUSH_REASON_ROUTING_INSTRUCTION) { From 7acba3c0a67cbe65d9bca8437e01065e778ebf8c Mon Sep 17 00:00:00 2001 From: Hariharan Ramanathan Date: Wed, 19 Aug 2026 11:02:45 +0530 Subject: [PATCH 0759/2126] wifi: ath12k: track per-ring RX sent-to-stack count The device DP stats provide visibility into RX errors and drops but lack a counter for successfully delivered packets. Without this, it is difficult to correlate REO ring activity with actual stack delivery during debugging or performance analysis. Add sent_to_stack[DP_REO_DST_RING_MAX][ATH12K_MAX_DEVICES] to ath12k_device_dp_stats to track successful deliveries per REO ring per device. The counter is attributed to the ring owner's dp and indexed by partner_dp->device_id, keeping it in the same debugfs file as reo_rx[] for direct comparison in MLO configurations. Increment the counter just before each MSDU is handed off to the stack via ath12k_dp_rx_deliver_msdu(). Add a likely()/WARN_ON_ONCE() bounds check on ring_id before indexing sent_to_stack[], consistent with all other new stat arrays in this series. Expose the per-ring per-device counts in the device_dp_stats debugfs file under a new 'REO sent to stack:' section. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Hariharan Ramanathan Co-developed-by: Pardeep Kaur Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-7-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs.c | 10 ++++++++++ drivers/net/wireless/ath/ath12k/dp.h | 1 + drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c index 935da8d06450..5d5597d80417 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -1122,6 +1122,16 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, len += scnprintf(buf + len, size - len, "%s: %u\n", wbm_rx_drop[i], device_stats->wbm_err.drop[i]); + len += scnprintf(buf + len, size - len, "\nREO sent to stack:\n"); + for (i = 0; i < DP_REO_DST_RING_MAX; i++) { + len += scnprintf(buf + len, size - len, "ring%d:", i); + for (j = 0; j < ab->ag->num_devices; j++) + len += scnprintf(buf + len, size - len, + "\t%d:%u", j, + device_stats->sent_to_stack[i][j]); + len += scnprintf(buf + len, size - len, "\n"); + } + len += scnprintf(buf + len, size - len, "\nHAL REO errors:\n"); for (i = 0; i < DP_REO_DST_RING_MAX; i++) diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 3765bcd09c51..d10157cda4fd 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -438,6 +438,7 @@ struct ath12k_device_dp_stats { u32 tx_enqueued[DP_TCL_NUM_RING_MAX]; u32 tx_completed[DP_TCL_NUM_RING_MAX]; u32 reo_excep_msdu_buf_type; + u32 sent_to_stack[DP_REO_DST_RING_MAX][ATH12K_MAX_DEVICES]; }; struct ath12k_dp { diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index 721eb25be1a9..b9b8f15dc4e4 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -651,6 +651,10 @@ ath12k_wifi7_dp_rx_process_received_packets(struct ath12k_dp *dp, dev_kfree_skb_any(msdu); continue; } + if (likely(ring_id < DP_REO_DST_RING_MAX)) + dp->device_stats.sent_to_stack[ring_id][partner_dp->device_id]++; + else + WARN_ON_ONCE(1); ath12k_dp_rx_deliver_msdu(dp_pdev, napi, msdu, &rx_info); } From 640240adbde5ecbbbc5afab5d72d89d7dd68347f Mon Sep 17 00:00:00 2001 From: Pardeep Kaur Date: Wed, 19 Aug 2026 11:02:46 +0530 Subject: [PATCH 0760/2126] wifi: ath12k: fix 1-based ring index in REO Rx Received debugfs output The REO Rx Received section in device_dp_stats debugfs uses a 1-based ring index ("Ring1:", "Ring2:", ...) which is inconsistent with the rest of ath12k where rings are indexed from 0. Fix it to use 0-based indexing and lowercase "ring%d:" to match the style used by all other ring counters in the same function. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-8-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c index 5d5597d80417..5d6710f1160c 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -1215,7 +1215,7 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, len += scnprintf(buf + len, size - len, "\nREO Rx Received:\n"); for (i = 0; i < DP_REO_DST_RING_MAX; i++) { - len += scnprintf(buf + len, size - len, "Ring%d:", i + 1); + len += scnprintf(buf + len, size - len, "ring%d:", i); for (j = 0; j < ab->ag->num_devices; j++) { len += scnprintf(buf + len, size - len, From 8637c54300cf71fb7e0f8f402b4393e0b73d0a11 Mon Sep 17 00:00:00 2001 From: Aniruddha Mishra Date: Wed, 19 Aug 2026 11:02:47 +0530 Subject: [PATCH 0761/2126] wifi: ath12k: add WBM SW desc fallback counter When HW CC is not done, the WBM RX error path falls back to cookie-based descriptor retrieval via ath12k_dp_get_rx_desc(). This fallback path is taken before knowing whether the retrieval will succeed, so it is not a drop event and should not be counted in the drop[] array. Add a dedicated sw_desc_fallback counter in ath12k_device_dp_rx_wbm_err_stats to track how often the HW CC fallback path is taken, distinct from actual packet drops. Expose the counter in the device_dp_stats debugfs file as a separate line. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6.r1-00402-QCAHKSWPL_SILICONZ-1 Signed-off-by: Aniruddha Mishra Co-developed-by: Pardeep Kaur Signed-off-by: Pardeep Kaur Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260819053247.1420393-9-pardeep.kaur@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs.c | 4 ++++ drivers/net/wireless/ath/ath12k/dp.h | 1 + drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 1 + 3 files changed, 6 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c index 5d6710f1160c..12791e267d1a 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs.c +++ b/drivers/net/wireless/ath/ath12k/debugfs.c @@ -1132,6 +1132,10 @@ static ssize_t ath12k_debugfs_dump_device_dp_stats(struct file *file, len += scnprintf(buf + len, size - len, "\n"); } + len += scnprintf(buf + len, size - len, + "\nWBM SW desc fallback (HW CC not done): %u\n", + device_stats->wbm_err.sw_desc_fallback); + len += scnprintf(buf + len, size - len, "\nHAL REO errors:\n"); for (i = 0; i < DP_REO_DST_RING_MAX; i++) diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index d10157cda4fd..c53eac20b989 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -422,6 +422,7 @@ struct ath12k_device_dp_rx_wbm_err_stats { u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX]; u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX]; u32 drop[WBM_ERR_DROP_MAX]; + u32 sw_desc_fallback; }; struct ath12k_device_dp_stats { diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index b9b8f15dc4e4..a32c804403e8 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -1968,6 +1968,7 @@ int ath12k_wifi7_dp_rx_process_wbm_err(struct ath12k_dp *dp, /* retry manual desc retrieval if hw cc is not done */ if (!desc_info) { + dp->device_stats.wbm_err.sw_desc_fallback++; desc_info = ath12k_dp_get_rx_desc(dp, err_info.cookie); if (!desc_info) { dp->device_stats.wbm_err.drop[WBM_ERR_DROP_GET_SW_DESC]++; From 753baa59527f8e606c49eac25692b8b08918a3a9 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Thu, 6 Aug 2026 16:38:35 +0200 Subject: [PATCH 0762/2126] dt-bindings: net: wireless: qcom,ath10k: Document NVMEM cells Document the NVMEM cells supported by the ath10k driver, the mac-address, pre-calibration data, and calibration data. Since such data may also originate from chipset OTP or be supplied via other device tree structures. All of these cells are optional and can be provided independently, in any combination. Reviewed-by: Bartosz Golaszewski Reviewed-by: Krzysztof Kozlowski Signed-off-by: Loic Poulain Link: https://patch.msgid.link/20260806-block-as-nvmem-v10-2-be598b2a5606@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .../bindings/net/wireless/qcom,ath10k.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml index a52cb8a0d409..0cb065265df4 100644 --- a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml +++ b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.yaml @@ -92,6 +92,22 @@ properties: ieee80211-freq-limit: true + nvmem-cells: + minItems: 1 + maxItems: 3 + description: + References to nvmem cells for MAC address and/or calibration data. + Supported cell names are mac-address, calibration, and pre-calibration. + + nvmem-cell-names: + minItems: 1 + maxItems: 3 + items: + enum: + - mac-address + - calibration + - pre-calibration + qcom,calibration-data: $ref: /schemas/types.yaml#/definitions/uint8-array description: From 9396e37c4860822fbc354fa438bb18e1437e0c9c Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 16:34:55 +0000 Subject: [PATCH 0763/2126] net: synchronize proc_do_rss_key() with netdev_rss_key_fill() proc_do_rss_key() reads netdev_rss_key[] without synchronization, so a concurrent reader of /proc/sys/net/core/netdev_rss_key can observe a partially populated key while netdev_rss_key_fill() is initializing it. Publish a boolean flag after an smp_wmb() once netdev_rss_key_fill() has populated netdev_rss_key[], and pair it with an smp_rmb() in proc_do_rss_key(), printing zero bytes until the flag is set. Fixes: 960fb622f851 ("net: provide a per host RSS key generic infrastructure") Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260922163458.3900996-2-edumazet@google.com Signed-off-by: Jakub Kicinski --- net/core/dev.h | 1 + net/core/sysctl_net_core.c | 7 ++++++- net/ethtool/ioctl.c | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/net/core/dev.h b/net/core/dev.h index 04fb0e9a571e..f159a7c7beaa 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -95,6 +95,7 @@ extern int netdev_unregister_timeout_secs; extern int weight_p; extern int dev_weight_rx_bias; extern int dev_weight_tx_bias; +extern bool netdev_rss_key_initialized; extern struct rw_semaphore dev_addr_sem; diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 23310581f494..473c162736d6 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -337,10 +337,15 @@ static int proc_do_rss_key(const struct ctl_table *table, int write, { char buf[NETDEV_RSS_KEY_LEN * 3]; struct ctl_table fake_table; + bool initialized; char *pos = buf; + initialized = READ_ONCE(netdev_rss_key_initialized); + /* Pair with smp_wmb() in netdev_rss_key_fill(). */ + smp_rmb(); + for (int i = 0; i < NETDEV_RSS_KEY_LEN; i++) { - pos = hex_byte_pack(pos, netdev_rss_key[i]); + pos = hex_byte_pack(pos, initialized ? netdev_rss_key[i] : 0); *pos++ = ':'; } *(--pos) = 0; diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 4b0bc503f930..b2820f02ca27 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -34,6 +34,7 @@ #include #include +#include "../core/dev.h" #include "common.h" /* State held across locks and calls for commands which have devlink fallback */ @@ -1302,11 +1303,17 @@ static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr, } u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; +bool netdev_rss_key_initialized __read_mostly; void netdev_rss_key_fill(void *buffer, size_t len) { BUG_ON(len > sizeof(netdev_rss_key)); net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key)); + if (unlikely(!READ_ONCE(netdev_rss_key_initialized))) { + /* Pair with smp_rmb() in proc_do_rss_key(). */ + smp_wmb(); + WRITE_ONCE(netdev_rss_key_initialized, true); + } memcpy(buffer, netdev_rss_key, len); } EXPORT_SYMBOL(netdev_rss_key_fill); From 898d431abd2578281bd3bb7db0970bc2de7a24c5 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 16:34:56 +0000 Subject: [PATCH 0764/2126] net: ethtool: generate RSS keys that spread flows over all queues netdev_rss_key_fill() returns a key made of uniformly random bytes. That is not enough, because the Toeplitz hash is linear over GF(2). Walking the hash input MSB first, each set bit contributes a 32-bit sliding window of the key, and hardware indexes the indirection table with the low order bits of the result. Only the tail of each window therefore reaches the queue index: v(i) = key bits [i + 32 - q .. i + 31] with q = log2(number of RX queues). Consecutive input bits give windows overlapping in q - 1 positions, so the q vectors belonging to the q lowest bits of a header field form a Toeplitz matrix built from 2 * q - 1 key bits, rather than q * q independent ones. Over GF(2) a random Toeplitz matrix is singular with probability exactly 1/2, whatever its size. When it is singular, flows differing only in the low order bits of that field cannot reach all the queues. This is not theoretical: a burst of connections draws ephemeral ports from a narrow range, and on one affected host only 4 of the 16 RX queues received any traffic at all, until its key was replaced. Keep drawing the key at random, since it is a secret that stops a remote attacker from steering flows onto a single queue, but force the handful of bits that decide this. Writing d[t] for key bit (lsb + 31 - t), where lsb is the position of the least significant bit of a field in the hash input, the matrices of all the q values up to 8 are non singular if and only if d[2 * i] = 1 ^ d[i] ^ d[i + 1] ^ ... ^ d[2 * i - 1] The odd positions stay free, so this is a one pass fixup rather than a search. It is in fact a bijection from those free positions onto the set of the values having the property, so the key stays uniformly distributed over that set and the whole cost is 8 bits of entropy per position. Searching for such a key by rejection would not have been an option: a freshly drawn one has the property everywhere with probability 2^-1008. Apply this at every 16-bit aligned position of the key, rather than at the offsets of the 2-tuple and 4-tuple layouts only. The core does not get to know what a given NIC hashes. Hardware may select the bytes it feeds to Toeplitz out of a header window with a bitmap, and hash an encapsulated header: for PSP over UDP over IPv6 it can pick the outer addresses and the inner TCP ports, which sit 78 bytes into the frame and read key bits well past the 40 bytes an IPv6 4-tuple needs. Hashed fields are 16 bits wide at the smallest and are not expected to straddle that grid, so covering the grid covers the layouts that were never written down, at no cost in code. This spends 8 bits of entropy per position, 1008 bits out of the 2048 bits of netdev_rss_key, leaving 1040 bits. 8 is also the largest usable bound, as each q constrains 2 * q - 1 bits and anything larger would make the ranges of two adjacent positions overlap. What the fixup leaves behind is visible structure: 8 of every 16 bits are derived from the 8 others, so a 16-bit aligned word of the key takes only 2^8 values and about 27 of the 128 words of netdev_rss_key duplicate another one. That much is forced rather than an artefact of this implementation, 1040 bits spread over 128 words being a little over 8 bits each, but it has one consequence worth removing. Two 32-bit windows a whole number of words apart now collide with probability 2^-16 instead of 2^-32, and two input bits reading the same window are indistinguishable to the hash, since flipping both of them leaves it unchanged. Over 500 keys, 23% of them had such a pair, where a uniformly random key has one with probability 2^-11. So draw another key when that happens. Four out of five pass. Which distances to look at follows from where the structure is: covering the multiples of 16 leaves 1.2e-3 expected colliding pairs per key, still 2.6 times the 4.6e-4 of a plain random key, and almost all of that excess sits at a distance of 8 modulo 16. Covering every multiple of 8 brings the total down to 4.2e-4, below what a plain random key gives over all distances, and within a few percent of the 4.0e-4 it gives over the distances that are left. Two windows a multiple of 8 bits apart are two windows at the same offset modulo 8, so this is a handful of pairwise sweeps rather than one pass over the key per distance. DO_ONCE() runs the generator under a spinlock with hard IRQs disabled, so keep the windows of a class in an array rather than recomputing both sides of every pair: 116 us instead of 254 us for the worst case, a 2048-bit key with no collision anywhere, at a cost of 512 bytes of stack. The shared key is fixed up once and every driver prefix inherits both properties. Move netdev_rss_key and netdev_rss_key_fill() from net/ethtool/ioctl.c to net/ethtool/common.c, and move the netdev_rss_key declaration out of include/linux/netdevice.h into net/core/dev.h. Checked against an independent Toeplitz implementation: for every 16-bit aligned position and every q in 1..8, an aligned block of 2^q consecutive values of a field ending there lands on the 2^q queues exactly once each. Over 20 random keys that is 20160 checks, which 50.1% of plain random keys fail and none of the generated keys do, for an average of 502 rewritten bits out of 2048. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260922163458.3900996-3-edumazet@google.com Signed-off-by: Jakub Kicinski --- Documentation/networking/scaling.rst | 9 ++ include/linux/netdevice.h | 1 - net/core/dev.h | 1 + net/ethtool/common.c | 174 +++++++++++++++++++++++++++ net/ethtool/ioctl.c | 16 --- 5 files changed, 184 insertions(+), 17 deletions(-) diff --git a/Documentation/networking/scaling.rst b/Documentation/networking/scaling.rst index 6c261eb48845..6c9836000a8d 100644 --- a/Documentation/networking/scaling.rst +++ b/Documentation/networking/scaling.rst @@ -48,6 +48,15 @@ count is not a power of two. NICs should provide an indirection table at least 4 times larger than the queue count. 4x table results in ~16% imbalance between the queues, which is acceptable for most applications. +The Toeplitz hash is linear over GF(2), so the quality of the hash key +matters as much as its randomness. For a key made of uniformly random +bytes, the q lowest order bits of a given header field fail to spread +flows over all 2^q queues with probability 1/2, and a burst of connections +picking nearly consecutive ephemeral ports then lands on a fraction of the +queues while the others stay idle. The netdev_rss_key_fill() helper draws +a random key that is free of this defect; drivers should use it rather +than seeding a key of their own. + Some NICs support symmetric RSS hashing where, if the IP (source address, destination address) and TCP/UDP (source port, destination port) tuples are swapped, the computed hash is the same. This is beneficial in some diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 5d16737167ee..d037faff7c44 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5323,7 +5323,6 @@ void netdev_lower_state_changed(struct net_device *lower_dev, void *lower_state_info); #define NETDEV_RSS_KEY_LEN 256 -extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; void netdev_rss_key_fill(void *buffer, size_t len); int skb_checksum_help(struct sk_buff *skb); diff --git a/net/core/dev.h b/net/core/dev.h index f159a7c7beaa..51921623fc0a 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -95,6 +95,7 @@ extern int netdev_unregister_timeout_secs; extern int weight_p; extern int dev_weight_rx_bias; extern int dev_weight_tx_bias; +extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; extern bool netdev_rss_key_initialized; extern struct rw_semaphore dev_addr_sem; diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 23db40618fed..b4e766e60d38 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -2,6 +2,9 @@ #include #include +#include +#include +#include #include #include #include @@ -1400,3 +1403,174 @@ enum ethtool_link_medium ethtool_str_to_medium(const char *str) return ETHTOOL_LINK_MEDIUM_NONE; } EXPORT_SYMBOL_GPL(ethtool_str_to_medium); + +u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; +bool netdev_rss_key_initialized __read_mostly; + +/* Toeplitz is linear over GF(2): the hash is the XOR of the 32-bit key + * windows selected by the set bits of the input, and hardware indexes the + * indirection table with the low order bits of the hash. Only the tail of + * each window therefore matters for queue selection: + * + * v(i) = key bits [i + 32 - q .. i + 31] + * + * for input bit @i, with q = log2(number of RX queues). Consecutive input + * bits give windows overlapping in q - 1 positions, so the matrix formed by + * the windows of the q lowest bits of a header field is a Toeplitz matrix + * built from 2 * q - 1 key bits, not from q * q independent ones. A random + * Toeplitz matrix over GF(2) is singular with probability 1/2, whatever its + * size, and when it is singular the flows of a burst differing only in the + * low order bits of that field (consecutive ephemeral ports, typically) + * cannot reach all the RX queues no matter how many of them are configured. + * + * Keep the key random, but constrain the few bits that decide this. The + * fixup is applied at every 16-bit aligned position of the key, rather than + * at the offsets of the one hash input layout the software happens to know + * about: hardware is free to hash whatever it wants, but the fields it picks + * are 16 bits wide at the smallest and are not expected to straddle that + * grid, so an encapsulated or offloaded layout is covered like the usual + * 2-tuple and 4-tuple ones. Each position constrains 2 * q - 1 bits, so + * NETDEV_RSS_KEY_QMAX is both enough for 256 queues and the largest value + * keeping the ranges of two adjacent positions disjoint. + */ +#define NETDEV_RSS_KEY_QMAX 8 +#define NETDEV_RSS_KEY_SPAN (2 * NETDEV_RSS_KEY_QMAX - 1) + +static bool netdev_rss_key_bit(const u8 *key, unsigned int bit) +{ + return key[bit / BITS_PER_BYTE] & (0x80 >> (bit % BITS_PER_BYTE)); +} + +static void netdev_rss_key_assign_bit(u8 *key, unsigned int bit, bool value) +{ + u8 mask = 0x80 >> (bit % BITS_PER_BYTE); + + if (value) + key[bit / BITS_PER_BYTE] |= mask; + else + key[bit / BITS_PER_BYTE] &= ~mask; +} + +/* Writing d[t] for key bit (@lsb + 31 - t), the matrices of all the q values + * up to NETDEV_RSS_KEY_QMAX are non singular if and only if + * + * d[2 * i] = 1 ^ d[i] ^ d[i + 1] ^ ... ^ d[2 * i - 1] + * + * The odd positions stay free, so this is a one pass fixup rather than a + * search. It is also a bijection onto the set of the values having the + * property, so the key stays uniformly distributed over that set. It costs + * NETDEV_RSS_KEY_QMAX bits of entropy per position. + */ +static void netdev_rss_key_fixup_field(u8 *key, unsigned int lsb) +{ + bool d[NETDEV_RSS_KEY_SPAN]; + unsigned int i, t; + + for (t = 0; t < NETDEV_RSS_KEY_SPAN; t++) + d[t] = netdev_rss_key_bit(key, lsb + 31 - t); + + for (i = 0; 2 * i < NETDEV_RSS_KEY_SPAN; i++) { + bool value = true; + + for (t = i; t < 2 * i; t++) + value ^= d[t]; + + d[2 * i] = value; + } + + for (t = 0; t < NETDEV_RSS_KEY_SPAN; t++) + netdev_rss_key_assign_bit(key, lsb + 31 - t, d[t]); +} + +/* The 32 key bits starting at @bit, which is what input bit @bit contributes + * to the hash. @bit + 32 must fit in the key. + */ +static u32 netdev_rss_key_window(const u8 *key, unsigned int bit) +{ + unsigned int byte = bit / BITS_PER_BYTE; + unsigned int shift = bit % BITS_PER_BYTE; + u32 window = get_unaligned_be32(key + byte); + + if (shift) + window = (window << shift) | + (key[byte + 4] >> (BITS_PER_BYTE - shift)); + + return window; +} + +/* Two input bits contributing the same window are indistinguishable to the + * hash, since flipping both of them leaves it unchanged. For a uniformly + * random key that is a 2 ** -32 event per pair of positions, but the fixup + * makes it likelier: it derives 8 of every 16 bits from the 8 others, so a + * 16-bit aligned word only takes 2 ** 8 values and two windows a whole + * number of words apart collide with probability 2 ** -16 instead. Half a + * word apart is less affected but still well clear of the random odds, so + * cover every distance that is a multiple of 8. What is left after that is + * below what a plain random key gives. + * + * Two windows at a distance that is a multiple of 8 are two windows at the + * same offset modulo 8. Caching a whole class would put 253 u32 on the + * stack, so cache one class modulo 16 and stream the class 8 bits above it + * against it. + */ +static bool netdev_rss_key_aliases(const u8 *key, unsigned int bits) +{ + u32 windows[NETDEV_RSS_KEY_LEN * BITS_PER_BYTE / 16]; + unsigned int i, j, n, r; + + for (r = 0; r < 16; r++) { + n = 0; + for (i = r; i + 32 <= bits; i += 16) + windows[n++] = netdev_rss_key_window(key, i); + + for (i = 0; i < n; i++) + for (j = i + 1; j < n; j++) + if (windows[i] == windows[j]) + return true; + + if (r >= 8) + continue; + + for (i = r + 8; i + 32 <= bits; i += 16) { + u32 window = netdev_rss_key_window(key, i); + + for (j = 0; j < n; j++) + if (windows[j] == window) + return true; + } + } + + return false; +} + +static void netdev_rss_key_init(u8 *key, size_t len) +{ + unsigned int lsb, bits = len * BITS_PER_BYTE; + + /* Four keys out of five come out of the fixup free of aliases, so + * drawing another one is both simpler and cheaper than repairing. + */ + do { + get_random_bytes(key, len); + + /* A field ending at bit @lsb uses key bits [.. , @lsb + 31], + * so stop as soon as a 32-bit window no longer fits in the + * key. + */ + for (lsb = 15; lsb + 32 <= bits; lsb += 16) + netdev_rss_key_fixup_field(key, lsb); + } while (netdev_rss_key_aliases(key, bits)); + + /* Pair with smp_rmb() in proc_do_rss_key(). */ + smp_wmb(); + WRITE_ONCE(netdev_rss_key_initialized, true); +} + +void netdev_rss_key_fill(void *buffer, size_t len) +{ + if (WARN_ON_ONCE(len > sizeof(netdev_rss_key))) + len = sizeof(netdev_rss_key); + DO_ONCE(netdev_rss_key_init, netdev_rss_key, sizeof(netdev_rss_key)); + memcpy(buffer, netdev_rss_key, len); +} +EXPORT_SYMBOL(netdev_rss_key_fill); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index b2820f02ca27..2b449d08ddcf 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -34,7 +34,6 @@ #include #include -#include "../core/dev.h" #include "common.h" /* State held across locks and calls for commands which have devlink fallback */ @@ -1302,21 +1301,6 @@ static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr, return 0; } -u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; -bool netdev_rss_key_initialized __read_mostly; - -void netdev_rss_key_fill(void *buffer, size_t len) -{ - BUG_ON(len > sizeof(netdev_rss_key)); - net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key)); - if (unlikely(!READ_ONCE(netdev_rss_key_initialized))) { - /* Pair with smp_rmb() in proc_do_rss_key(). */ - smp_wmb(); - WRITE_ONCE(netdev_rss_key_initialized, true); - } - memcpy(buffer, netdev_rss_key, len); -} -EXPORT_SYMBOL(netdev_rss_key_fill); static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, void __user *useraddr) From 5fd4208098be11251c062e41fef9d81b78277264 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 16:34:57 +0000 Subject: [PATCH 0765/2126] netdevsim: support reporting RSS key, indirection table, and flow hash fields Initialize a per-device RSS key in nsim_ethtool_init() using netdev_rss_key_fill() and wire up get_rxfh_key_size, get_rxfh_indir_size, get_rxfh, and get_rxfh_fields on nsim_ethtool_ops. This allows RSS selftests under tools/testing/selftests/drivers/net/ to exercise both /proc/sys/net/core/netdev_rss_key and ethtool netlink RSS reporting against netdevsim without requiring physical hardware. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260922163458.3900996-4-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/ethtool.c | 53 +++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 3 ++ 2 files changed, 56 insertions(+) diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c index 025ea79879f3..c3d2bc783d55 100644 --- a/drivers/net/netdevsim/ethtool.c +++ b/drivers/net/netdevsim/ethtool.c @@ -205,7 +205,59 @@ static int nsim_get_ts_info(struct net_device *dev, return 0; } +static u32 nsim_get_rxfh_key_size(struct net_device *dev) +{ + return NETDEV_RSS_KEY_LEN; +} + +static u32 nsim_get_rxfh_indir_size(struct net_device *dev) +{ + return NSIM_RSS_INDIR_SIZE; +} + +static int nsim_get_rxfh(struct net_device *dev, + struct ethtool_rxfh_param *rxfh) +{ + struct netdevsim *ns = netdev_priv(dev); + u32 i; + + rxfh->hfunc = ETH_RSS_HASH_TOP; + if (rxfh->indir) { + for (i = 0; i < NSIM_RSS_INDIR_SIZE; i++) + rxfh->indir[i] = ethtool_rxfh_indir_default(i, ns->ethtool.channels); + } + if (rxfh->key) + memcpy(rxfh->key, ns->ethtool.rss_key, + sizeof(ns->ethtool.rss_key)); + + return 0; +} + +static int nsim_get_rxfh_fields(struct net_device *dev, + struct ethtool_rxfh_fields *info) +{ + switch (info->flow_type) { + case TCP_V4_FLOW: + case UDP_V4_FLOW: + case TCP_V6_FLOW: + case UDP_V6_FLOW: + info->data = RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + return 0; + case IPV4_FLOW: + case IPV6_FLOW: + info->data = RXH_IP_SRC | RXH_IP_DST; + return 0; + default: + return -EOPNOTSUPP; + } +} + static const struct ethtool_ops nsim_ethtool_ops = { + .get_rxfh_key_size = nsim_get_rxfh_key_size, + .get_rxfh_indir_size = nsim_get_rxfh_indir_size, + .get_rxfh = nsim_get_rxfh, + .get_rxfh_fields = nsim_get_rxfh_fields, .supported_coalesce_params = ETHTOOL_COALESCE_ALL_PARAMS, .supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT | ETHTOOL_RING_USE_HDS_THRS, @@ -250,6 +302,7 @@ void nsim_ethtool_init(struct netdevsim *ns) ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE; ns->ethtool.channels = ns->nsim_bus_dev->num_queues; + netdev_rss_key_fill(ns->ethtool.rss_key, sizeof(ns->ethtool.rss_key)); ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir); ns->ethtool_ddir = ethtool; diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index eb9d684e3bcc..fd5599cd3bb9 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -87,10 +87,13 @@ struct nsim_ethtool_pauseparam { bool report_stats_tx; }; +#define NSIM_RSS_INDIR_SIZE 128 + struct nsim_ethtool { u32 get_err; u32 set_err; u32 channels; + u8 rss_key[NETDEV_RSS_KEY_LEN]; struct nsim_ethtool_pauseparam pauseparam; struct ethtool_coalesce coalesce; struct ethtool_ringparam ring; From c8103dd8b9b4e0aa599d4ccdfeffb57eb88b5590 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 16:34:58 +0000 Subject: [PATCH 0766/2126] selftests: drivers: net: check the host and device RSS keys Add a selftest under tools/testing/selftests/drivers/net/rss_key.py checking both the host RSS key (/proc/sys/net/core/netdev_rss_key) and the RSS key, indirection table, and flow-hash layouts reported by a device over ethtool netlink. When invoked without NETIF, NetDrvEnv creates a 4-queue netdevsim device, which calls netdev_rss_key_fill() and allows exercising both the host key and the netlink RSS reporting path in a virtual machine without special hardware. When invoked with NETIF, it checks the key and indirection table of that interface. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260922163458.3900996-5-edumazet@google.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/Makefile | 1 + .../testing/selftests/drivers/net/rss_key.py | 343 ++++++++++++++++++ 2 files changed, 344 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/rss_key.py diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index b98c0e240b7d..79c6f998e704 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -25,6 +25,7 @@ TEST_PROGS := \ psp.py \ queues.py \ ring_reconfig.py \ + rss_key.py \ shaper.py \ so_txtime.py \ stats.py \ diff --git a/tools/testing/selftests/drivers/net/rss_key.py b/tools/testing/selftests/drivers/net/rss_key.py new file mode 100755 index 000000000000..4f694a99e9a0 --- /dev/null +++ b/tools/testing/selftests/drivers/net/rss_key.py @@ -0,0 +1,343 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +Check the quality of the host RSS key (/proc/sys/net/core/netdev_rss_key) +and that the RSS key a device actually uses spreads flows over all of the +entries of its indirection table. + +The Toeplitz hash is linear over GF(2): the hash is the XOR of the 32 bit key +windows selected by the set bits of the input, and hardware indexes the +indirection table with the low order bits of the hash. The windows belonging +to the q lowest bits of a header field therefore form a Toeplitz matrix, and +when that matrix is singular the flows of a burst differing only in those +bits, consecutive ephemeral ports typically, can not reach all of the 2 ** q +entries of the table. A key drawn uniformly at random is singular for a given +field and a given q with probability 1/2. + +netdev_rss_key_fill() generates keys that are non singular for every field of +the hash input and every q up to RSS_KEY_QMAX. +""" + +import errno +import random + +from lib.py import ksft_run, ksft_exit, ksft_pr +from lib.py import ksft_eq, ksft_ge +from lib.py import KsftSkipEx +from lib.py import NetDrvEnv, EthtoolFamily, NlError + +KEY_PATH = "/proc/sys/net/core/netdev_rss_key" + +# Shortest key able to hash an IPv6 4-tuple. +MIN_KEY_LEN = 40 + +# Matches NETDEV_RSS_KEY_QMAX, that is up to 256 entries of the table. +RSS_KEY_QMAX = 8 + +# "define" for the ID of the Toeplitz hash function +ETH_RSS_HASH_TOP = 1 + +FLOW_TYPES = ("tcp4", "udp4", "tcp6", "udp6") + +# Map ethtool netlink rxfh-fields flag names to rss_key_layout() codes. +FIELD_NAMES = { + "ip-src": "s", + "ip-dst": "d", + "l3-proto": "t", + "l4-b-0-1": "f", + "l4-b-2-3": "n", + "ip6-fl": "l", +} + + +def rss_key_bit(buf, bit): + """Bit @bit of @buf, counting from the most significant bit of byte 0.""" + return (buf[bit // 8] >> (7 - bit % 8)) & 1 + + +def rss_key_assign_bit(buf, bit, value): + mask = 0x80 >> (bit % 8) + + if value: + buf[bit // 8] |= mask + else: + buf[bit // 8] &= ~mask + + +def rss_key_window(key, bit): + """The 32 key bits starting at @bit, what input bit @bit contributes.""" + value = 0 + + for i in range(32): + value = (value << 1) | rss_key_bit(key, bit + i) + + return value + + +def rss_key_toeplitz(key, inp, nbits): + """The Toeplitz hash of the @nbits long input @inp under @key.""" + value = 0 + + for i in range(nbits): + if rss_key_bit(inp, i): + value ^= rss_key_window(key, i) + + return value + + +def rss_key_full_rank(key, lsb, q): + """Do the q low order bits of the field at @lsb reach all 2 ** q entries? + + Gaussian elimination over GF(2) on the q windows involved, reduced to + their q low order bits, which are the ones indexing the table. + """ + basis = {} + + for j in range(q): + vector = rss_key_window(key, lsb - j) & ((1 << q) - 1) + + while vector: + low = vector & -vector + if low not in basis: + basis[low] = vector + break + vector ^= basis[low] + + if not vector: + return False + + return True + + +def rss_key_layout(fields, ipv6): + """Describe the hash input built from @fields. + + @fields is the flow hash configuration, "sdfn" for a 4-tuple or "sd" for + a 2-tuple. Returns the list of (name, position of the least significant + bit) and the length of the input in bits, or None if the layout involves + something this does not know how to place. + """ + addr_bits = 128 if ipv6 else 32 + known = (("s", "saddr", addr_bits), + ("d", "daddr", addr_bits), + ("f", "sport", 16), + ("n", "dport", 16)) + + if set(fields) - {flag for flag, _, _ in known}: + return None, 0 + + layout = [] + nbits = 0 + + for flag, name, width in known: + if flag not in fields: + continue + nbits += width + layout.append((name, nbits - 1)) + + return layout, nbits + + +def _read_host_key(): + """Return the host RSS key, skipping if it has not been generated.""" + try: + with open(KEY_PATH, "r", encoding="ascii") as fp: + text = fp.read().strip() + except FileNotFoundError as exc: + raise KsftSkipEx(f"{KEY_PATH} is not available") from exc + + key = bytes(int(byte, 16) for byte in text.split(":")) if text else b"" + + if not any(key): + raise KsftSkipEx("the host RSS key has not been generated yet, " + "no driver has called netdev_rss_key_fill()") + + return key + + +def _get_rss(cfg): + """The key, indirection table, and flow-hash config of @cfg's device.""" + try: + rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) + except NlError as exc: + if exc.error == errno.EOPNOTSUPP: + raise KsftSkipEx(f"{cfg.ifname} does not support RSS") from exc + raise + + hkey = rss.get("hkey") + if not hkey or not any(hkey): + raise KsftSkipEx(f"{cfg.ifname} does not report an RSS key") + + if rss.get("hfunc") != ETH_RSS_HASH_TOP: + raise KsftSkipEx(f"{cfg.ifname} does not use the Toeplitz hash") + + if rss.get("input-xfrm"): + raise KsftSkipEx(f"{cfg.ifname} transforms the hash input") + + indir = rss.get("indir") + if not indir: + raise KsftSkipEx(f"{cfg.ifname} does not report an indirection table") + + if len(indir) & (len(indir) - 1): + raise KsftSkipEx(f"{cfg.ifname} has {len(indir)} indirection table " + "entries, which is not a power of two") + + return bytes(hkey), indir, rss.get("flow-hash", {}) + + +def _get_layouts(flow_hash): + """The hash input layouts in use, mapped to the flow types sharing them.""" + layouts = {} + + for fl_type in FLOW_TYPES: + nl_fields = flow_hash.get(fl_type) + if not nl_fields: + continue + + fields = "".join(FIELD_NAMES.get(name, "?") for name in nl_fields) + layout, nbits = rss_key_layout(fields, fl_type.endswith("6")) + if layout is None: + ksft_pr(f"{fl_type}: not checked, hashes fields we can not place " + f"({nl_fields})") + continue + + layouts.setdefault((tuple(layout), nbits), []).append(fl_type) + + if not layouts: + raise KsftSkipEx("no flow type with a hash input we can describe") + + return layouts + + +def test_host_rss_key_length(cfg) -> None: + key = _read_host_key() + + ksft_pr(f"host RSS key is {len(key)} bytes") + ksft_ge(len(key), MIN_KEY_LEN, "key too short to hash an IPv6 4-tuple") + + +def test_host_rss_key_spread(cfg) -> None: + key = _read_host_key() + degenerate = [] + + for ipv6 in (False, True): + layout, _ = rss_key_layout("sdfn", ipv6) + family = "IPv6" if ipv6 else "IPv4" + + for name, lsb in layout: + if lsb + 32 > len(key) * 8: + continue + + for q in range(1, RSS_KEY_QMAX + 1): + if not rss_key_full_rank(key, lsb, q): + degenerate.append(f"{family} {name} over {1 << q} queues") + + for bad in degenerate: + ksft_pr(f"degenerate: {bad}") + + ksft_eq(len(degenerate), 0, + "the host RSS key does not spread flows over all the queues") + + +def test_host_rss_key_grid(cfg) -> None: + """Sweep the whole key, not only the fields of the usual layouts.""" + key = _read_host_key() + bits = len(key) * 8 + positions = 0 + degenerate = [] + + for lsb in range(15, bits - 31, 16): + positions += 1 + + for q in range(1, RSS_KEY_QMAX + 1): + if not rss_key_full_rank(key, lsb, q): + degenerate.append(f"field ending at bit {lsb} " + f"over {1 << q} queues") + + ksft_pr(f"checked {positions} positions of the {len(key)} byte key") + + for bad in degenerate[:8]: + ksft_pr(f"degenerate: {bad}") + + ksft_eq(len(degenerate), 0, + "the host RSS key does not spread flows over all the queues " + "at every 16-bit aligned position") + + +def test_dev_rss_key_rank(cfg) -> None: + """The key has to be non singular for the size of the table.""" + hkey, indir, flow_hash = _get_rss(cfg) + q = min((len(indir) - 1).bit_length(), RSS_KEY_QMAX) + degenerate = [] + + if not q: + raise KsftSkipEx("the indirection table has a single entry") + + for (layout, _), fl_types in _get_layouts(flow_hash).items(): + for name, lsb in layout: + if lsb + 32 > len(hkey) * 8: + ksft_pr(f"{name}: not checked, the key is {len(hkey)} bytes") + continue + + if not rss_key_full_rank(hkey, lsb, q): + degenerate.append(f"{'/'.join(fl_types)} {name}") + + for bad in degenerate: + ksft_pr(f"degenerate: {bad}") + + ksft_eq(len(degenerate), 0, + f"the key of {cfg.ifname} does not spread flows over the " + f"{1 << q} entries of its indirection table") + + +def test_dev_rss_key_spread(cfg) -> None: + """Hash bursts differing in one field only, and place them in the table.""" + hkey, indir, flow_hash = _get_rss(cfg) + q = (len(indir) - 1).bit_length() + collisions = [] + + if q > RSS_KEY_QMAX: + raise KsftSkipEx(f"{len(indir)} indirection table entries is more " + "than the kernel guarantees") + if not q: + raise KsftSkipEx("the indirection table has a single entry") + + for (layout, nbits), fl_types in _get_layouts(flow_hash).items(): + if nbits + 31 > len(hkey) * 8: + ksft_pr(f"{'/'.join(fl_types)}: not checked, the key is " + f"{len(hkey)} bytes, input needs {(nbits + 31 + 7) // 8}") + continue + + for name, lsb in layout: + inp = bytearray(random.randbytes(nbits // 8)) + entries = set() + for value in range(1 << q): + for bit in range(q): + rss_key_assign_bit(inp, lsb - bit, value & (1 << bit)) + hash_ = rss_key_toeplitz(hkey, inp, nbits) + entries.add(hash_ & (len(indir) - 1)) + + if len(entries) != 1 << q: + collisions.append(f"{'/'.join(fl_types)} {name} reaches " + f"{len(entries)} of the {1 << q} entries") + + for bad in collisions: + ksft_pr(bad) + + ksft_eq(len(collisions), 0, + f"flows differing in one field only do not fill the " + f"indirection table of {cfg.ifname}") + + +def main() -> None: + """ Ksft boiler plate main """ + + with NetDrvEnv(__file__, queue_count=4) as cfg: + cfg.ethnl = EthtoolFamily() + ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main() From e8bfdd91469c9668d11427a30f8ba0396f9aa92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:28 +0200 Subject: [PATCH 0767/2126] net: ethernet: ravb: Remove gPTP control from WoL setup and restore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit a6a85ba36fd0 ("net: ravb: Move PTP initialization in the driver's ndo_open API for ccc_gac platorms") the gPTP clock (if supported) is stopped and started by opening and closing the ndev. This makes the special case to stop and start it when resuming from WoL redundant. As the ndev will always be closed and re-opened when resuming the system. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-2-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb_main.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index ea1c7e536791..36173a09e2fd 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -3182,9 +3182,6 @@ static int ravb_wol_setup(struct net_device *ndev) /* Enable MagicPacket */ ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); - if (priv->info->ccc_gac) - ravb_ptp_stop(ndev); - return enable_irq_wake(priv->emac_irq); } @@ -3204,9 +3201,6 @@ static int ravb_wol_restore(struct net_device *ndev) if (error) return error; - if (priv->info->ccc_gac) - ravb_ptp_init(ndev, priv->pdev); - if (info->nc_queues) napi_enable(&priv->napi[RAVB_NC]); napi_enable(&priv->napi[RAVB_BE]); From d9519789d0989ab47355b30fe1bc35f2c327e6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:29 +0200 Subject: [PATCH 0768/2126] net: ethernet: ravb: Move programming of gPTP timer interval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit f384ab481cab ("net: ravb: Split GTI computation and set operations") broke apart the operations of computing the timer interval and programming of it. However it kept the programming of the interval in the RAVB main logic. Having split the two apart this can be improved further by moving the programming to the gPTP initialization function, as the first action of the gPTP init function is to wait for the timer interval programming to be acknowledge by the hardware. As an added bonus the interaction with the gPTP registers for the programming can then also be done while holding the gPTP registers lock. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-3-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb_main.c | 16 ---------------- drivers/net/ethernet/renesas/ravb_ptp.c | 11 ++++++++++- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 36173a09e2fd..a89f6fe7866f 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1846,20 +1846,6 @@ static int ravb_set_config_mode(struct net_device *ndev) return error; } -static void ravb_set_gti(struct net_device *ndev) -{ - struct ravb_private *priv = netdev_priv(ndev); - const struct ravb_hw_info *info = priv->info; - - if (!(info->gptp || info->ccc_gac)) - return; - - ravb_write(ndev, priv->gti_tiv, GTI); - - /* Request GTI loading */ - ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI); -} - static int ravb_compute_gti(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); @@ -1974,8 +1960,6 @@ static int ravb_open(struct net_device *ndev) ravb_emac_init(ndev); - ravb_set_gti(ndev); - /* Initialise PTP Clock driver */ if (info->gptp || info->ccc_gac) ravb_ptp_init(ndev, priv->pdev); diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c index 43218bc15b15..ac91a6813368 100644 --- a/drivers/net/ethernet/renesas/ravb_ptp.c +++ b/drivers/net/ethernet/renesas/ravb_ptp.c @@ -321,11 +321,20 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev) priv->ptp.info = ravb_ptp_info; - priv->ptp.default_addend = ravb_read(ndev, GTI); + priv->ptp.default_addend = priv->gti_tiv; priv->ptp.current_addend = priv->ptp.default_addend; spin_lock_irqsave(&priv->lock, flags); + + /* Set gPTP Timer Increment Value. */ + ravb_write(ndev, priv->ptp.default_addend, GTI); + + /* Request GTI loading. */ + ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI); + + /* Wait for GIT loading to complete by checking there are no requests. */ ravb_wait(ndev, GCCR, GCCR_TCR, GCCR_TCR_NOREQ); + ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP); spin_unlock_irqrestore(&priv->lock, flags); From b9c1216c01560c2603af4c3ca42755ead3cdb4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:30 +0200 Subject: [PATCH 0769/2126] net: ethernet: ravb: Simplify gPTP start and stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For devices that do not support the gPTP clock in config mode the somewhat oddly named flag gptp is set, compared to devices that do support the gPTP clock in config and operation mode where the flag ccc_gac is set instead. The two flags are mutually exclusive. For the gptp-flag devices (Gen2) the clock is tied to the AVB-DMAC, when it is stopped so is the gPTP clock. For ccc_gac-flag devices (Gen3) the gPTP clock is available whenever the ndev is open. Prepare to add Gen4 support which will add a third way by cleaning the Gen2 and Gen3 cases up a bit. Fold the gptp-flag start and stop calls into ravb_dmac_init() and ravb_stop_dma(), which start and stop the AVB-DMAC. There are no functional change as all call sites to the construct: if (info->gptp) ravb_ptp_init(ndev, priv->pdev); are always just after a call to into ravb_dmac_init() and all call sites to the construct: if (info->gptp) ravb_ptp_stop(ndev); are always directly followed by a call to ravb_stop_dma(). There are two special cases where the calling construct covers both the gptp-flag and info->ccc_gac devices, one for start and one for stop. The condition that it is preceded by a call to ravb_dmac_init(), or followed by a call to ravb_stop_dma() are however true for them too. Reworked the two special cases to drop the check of info->gptp. The end result is that the gPTP clock will be started or stopped for the gptp-flag devices in tandem with the AVB-DMAC, while the info->ccc_gac devices will be controlled, as before, when the ndev is opened or closed. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-4-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb_main.c | 36 +++++++++++------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index a89f6fe7866f..42d208e6b8ec 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -707,7 +707,15 @@ static int ravb_dmac_init(struct net_device *ndev) return error; /* Setting the control will start the AVB-DMAC process. */ - return ravb_set_opmode(ndev, CCC_OPC_OPERATION); + error = ravb_set_opmode(ndev, CCC_OPC_OPERATION); + if (error) + return error; + + /* Initialise PTP Clock driver */ + if (info->gptp) + ravb_ptp_init(ndev, priv->pdev); + + return 0; } static void ravb_get_tx_tstamp(struct net_device *ndev) @@ -1115,6 +1123,10 @@ static int ravb_stop_dma(struct net_device *ndev) netdev_err(ndev, "failed to stop AXI BUS\n"); } + /* Stop PTP Clock driver */ + if (info->gptp) + ravb_ptp_stop(ndev); + /* Stop AVB-DMAC process */ return ravb_set_opmode(ndev, CCC_OPC_CONFIG); } @@ -1719,9 +1731,7 @@ static int ravb_set_ringparam(struct net_device *ndev, if (netif_running(ndev)) { netif_device_detach(ndev); - /* Stop PTP Clock driver */ - if (info->gptp) - ravb_ptp_stop(ndev); + /* Wait for DMA stopping */ error = ravb_stop_dma(ndev); if (error) { @@ -1752,10 +1762,6 @@ static int ravb_set_ringparam(struct net_device *ndev, ravb_emac_init(ndev); - /* Initialise PTP Clock driver */ - if (info->gptp) - ravb_ptp_init(ndev, priv->pdev); - netif_device_attach(ndev); } @@ -1961,7 +1967,7 @@ static int ravb_open(struct net_device *ndev) ravb_emac_init(ndev); /* Initialise PTP Clock driver */ - if (info->gptp || info->ccc_gac) + if (info->ccc_gac) ravb_ptp_init(ndev, priv->pdev); /* PHY control start */ @@ -1975,7 +1981,7 @@ static int ravb_open(struct net_device *ndev) out_ptp_stop: /* Stop PTP Clock driver */ - if (info->gptp || info->ccc_gac) + if (info->ccc_gac) ravb_ptp_stop(ndev); ravb_stop_dma(ndev); out_set_reset: @@ -2020,10 +2026,6 @@ static void ravb_tx_timeout_work(struct work_struct *work) netif_tx_stop_all_queues(ndev); - /* Stop PTP Clock driver */ - if (info->gptp) - ravb_ptp_stop(ndev); - /* Wait for DMA stopping */ if (ravb_stop_dma(ndev)) { /* If ravb_stop_dma() fails, the hardware is still operating @@ -2056,10 +2058,6 @@ static void ravb_tx_timeout_work(struct work_struct *work) ravb_emac_init(ndev); out: - /* Initialise PTP Clock driver */ - if (info->gptp) - ravb_ptp_init(ndev, priv->pdev); - netif_tx_start_all_queues(ndev); out_unlock: @@ -2374,7 +2372,7 @@ static int ravb_close(struct net_device *ndev) } /* Stop PTP Clock driver */ - if (info->gptp || info->ccc_gac) + if (info->ccc_gac) ravb_ptp_stop(ndev); /* Set the config mode to stop the AVB-DMAC's processes */ From b784f9ed2e3bcc1f632401307057e47f71d4d7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:31 +0200 Subject: [PATCH 0770/2126] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need to explicitly pass the struct platform_device pointer to ravb_ptp_init(), it can retrieve it directly from the private data structure. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-5-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 2 +- drivers/net/ethernet/renesas/ravb_main.c | 4 ++-- drivers/net/ethernet/renesas/ravb_ptp.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index 3ee4c6108189..aa45f5466001 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -1163,7 +1163,7 @@ void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear, int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value); void ravb_ptp_interrupt(struct net_device *ndev); -void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev); +void ravb_ptp_init(struct net_device *ndev); void ravb_ptp_stop(struct net_device *ndev); #endif /* #ifndef __RAVB_H__ */ diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 42d208e6b8ec..1dfe905832a0 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -713,7 +713,7 @@ static int ravb_dmac_init(struct net_device *ndev) /* Initialise PTP Clock driver */ if (info->gptp) - ravb_ptp_init(ndev, priv->pdev); + ravb_ptp_init(ndev); return 0; } @@ -1968,7 +1968,7 @@ static int ravb_open(struct net_device *ndev) /* Initialise PTP Clock driver */ if (info->ccc_gac) - ravb_ptp_init(ndev, priv->pdev); + ravb_ptp_init(ndev); /* PHY control start */ error = ravb_phy_start(ndev); diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c index ac91a6813368..6817e94721b5 100644 --- a/drivers/net/ethernet/renesas/ravb_ptp.c +++ b/drivers/net/ethernet/renesas/ravb_ptp.c @@ -313,7 +313,7 @@ void ravb_ptp_interrupt(struct net_device *ndev) ravb_write(ndev, ~(gis | GIS_RESERVED), GIS); } -void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev) +void ravb_ptp_init(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); struct ptp_clock *clock; @@ -338,7 +338,7 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev) ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP); spin_unlock_irqrestore(&priv->lock, flags); - clock = ptp_clock_register(&priv->ptp.info, &pdev->dev); + clock = ptp_clock_register(&priv->ptp.info, &priv->pdev->dev); if (IS_ERR(clock)) { netdev_err(ndev, "failed to register PTP clock: %pe\n", clock); clock = NULL; From 121cc8a3acf8d8e31daec4e564eff32e39c00446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:32 +0200 Subject: [PATCH 0771/2126] net: ethernet: ravb: Propagate error from ptp_clock_register() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the PTP clock registration failed the error is silently ignored. Before reworking all callers of ravb_ptp_init() handle and propagate the error so it can be used. Link: https://sashiko.dev/#/patchset/20260610102432.3538432-2-niklas.soderlund+renesas@ragnatech.se?part=1 Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-6-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 3 +-- drivers/net/ethernet/renesas/ravb_main.c | 5 ++--- drivers/net/ethernet/renesas/ravb_ptp.c | 27 +++++++++++------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index aa45f5466001..0c122a815840 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -1028,7 +1028,6 @@ struct ravb_ptp_perout { struct ravb_ptp { struct ptp_clock *clock; struct ptp_clock_info info; - int phc_index; u32 default_addend; u32 current_addend; int extts[N_EXT_TS]; @@ -1163,7 +1162,7 @@ void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear, int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value); void ravb_ptp_interrupt(struct net_device *ndev); -void ravb_ptp_init(struct net_device *ndev); +int ravb_ptp_init(struct net_device *ndev); void ravb_ptp_stop(struct net_device *ndev); #endif /* #ifndef __RAVB_H__ */ diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 1dfe905832a0..db3ef87f0991 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1774,7 +1774,7 @@ static int ravb_get_ts_info(struct net_device *ndev, struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *hw_info = priv->info; - if (hw_info->gptp || hw_info->ccc_gac) { + if (priv->ptp.clock && (hw_info->gptp || hw_info->ccc_gac)) { info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | @@ -1785,7 +1785,7 @@ static int ravb_get_ts_info(struct net_device *ndev, (1 << HWTSTAMP_FILTER_NONE) | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | (1 << HWTSTAMP_FILTER_ALL); - info->phc_index = READ_ONCE(priv->ptp.phc_index); + info->phc_index = ptp_clock_index(priv->ptp.clock); } return 0; @@ -2937,7 +2937,6 @@ static int ravb_probe(struct platform_device *pdev) priv->rstc = rstc; priv->ndev = ndev; priv->pdev = pdev; - priv->ptp.phc_index = -1; priv->num_tx_ring[RAVB_BE] = BE_TX_RING_SIZE; priv->num_rx_ring[RAVB_BE] = BE_RX_RING_SIZE; if (info->nc_queues) { diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c index 6817e94721b5..407ae97b76bb 100644 --- a/drivers/net/ethernet/renesas/ravb_ptp.c +++ b/drivers/net/ethernet/renesas/ravb_ptp.c @@ -313,11 +313,11 @@ void ravb_ptp_interrupt(struct net_device *ndev) ravb_write(ndev, ~(gis | GIS_RESERVED), GIS); } -void ravb_ptp_init(struct net_device *ndev) +int ravb_ptp_init(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); - struct ptp_clock *clock; unsigned long flags; + int ret = 0; priv->ptp.info = ravb_ptp_info; @@ -338,15 +338,14 @@ void ravb_ptp_init(struct net_device *ndev) ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP); spin_unlock_irqrestore(&priv->lock, flags); - clock = ptp_clock_register(&priv->ptp.info, &priv->pdev->dev); - if (IS_ERR(clock)) { - netdev_err(ndev, "failed to register PTP clock: %pe\n", clock); - clock = NULL; + priv->ptp.clock = ptp_clock_register(&priv->ptp.info, &priv->pdev->dev); + if (IS_ERR(priv->ptp.clock)) { + ret = PTR_ERR(priv->ptp.clock); + priv->ptp.clock = NULL; + ravb_ptp_stop(ndev); } - WRITE_ONCE(priv->ptp.clock, clock); - if (clock) - WRITE_ONCE(priv->ptp.phc_index, ptp_clock_index(clock)); + return ret; } static void ravb_ptp_disable(struct net_device *ndev) @@ -369,14 +368,12 @@ static void ravb_ptp_sync_irqs(struct net_device *ndev) void ravb_ptp_stop(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); - struct ptp_clock *clock; - - WRITE_ONCE(priv->ptp.phc_index, -1); - clock = xchg(&priv->ptp.clock, NULL); ravb_ptp_disable(ndev); ravb_ptp_sync_irqs(ndev); - if (clock) - ptp_clock_unregister(clock); + if (priv->ptp.clock) { + ptp_clock_unregister(priv->ptp.clock); + priv->ptp.clock = NULL; + } } From 14bf0091dd0d47204f761125d65b102bebcb6001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:33 +0200 Subject: [PATCH 0772/2126] net: ethernet: ravb: Replace gPTP flags with callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare for adding Gen4 support which will add a third and new way to interact with the gPTP clock by replacing the flags for Gen2 behavior (info->gptp) and Gen3 behavior (info->ccc_gac) with callbacks. This will make adding Gen4 support cleaner as the code will not have "if else if else" sprinkled all over to handle each generations special cases. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-7-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 24 ++++++- drivers/net/ethernet/renesas/ravb_main.c | 87 +++++++++++++++--------- 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index 0c122a815840..6603f90b19e1 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -1034,6 +1034,27 @@ struct ravb_ptp { struct ravb_ptp_perout perout[N_PER_OUT]; }; +/** + * struct ravb_gptp_info - Platform specific gPTP behavior + * + * Each generation of RAVB have slightly different behaviors when interacting + * with the gPTP clock. This struct provides the callbacks to be called at + * critical points in the RAVB driver. + * + * @set_config_mode: Enter config mode + * @dmac_start: Called when the DMAC starts + * @dmac_stop: Called when the DMAC stops + * @ndev_open: Called when the ndev is opened + * @ndev_close: Called when the ndev is closed + */ +struct ravb_gptp_info { + int (*set_config_mode)(struct net_device *ndev); + int (*dmac_start)(struct net_device *ndev); + void (*dmac_stop)(struct net_device *ndev); + int (*ndev_open)(struct net_device *ndev); + void (*ndev_close)(struct net_device *ndev); +}; + struct ravb_hw_info { int (*receive)(struct net_device *ndev, int budget, int q); void (*set_rate)(struct net_device *ndev); @@ -1052,6 +1073,7 @@ struct ravb_hw_info { u32 rx_buffer_size; u32 rx_desc_size; u32 dbat_entry_num; + const struct ravb_gptp_info *ptp; /* Callbacks to handle gPTP interactions. */ unsigned aligned_tx: 1; unsigned coalesce_irqs:1; /* Needs software IRQ coalescing */ @@ -1062,8 +1084,6 @@ struct ravb_hw_info { unsigned multi_irqs:1; /* AVB-DMAC and E-MAC has multiple irqs */ unsigned irq_en_dis:1; /* Has separate irq enable and disable regs */ unsigned err_mgmt_irqs:1; /* Line1 (Err) and Line2 (Mgmt) irqs are separate */ - unsigned gptp:1; /* AVB-DMAC has gPTP support */ - unsigned ccc_gac:1; /* AVB-DMAC has gPTP support active in config mode */ unsigned gptp_ref_clk:1; /* gPTP has separate reference clock */ unsigned nc_queues:1; /* AVB-DMAC has RX and TX NC queues */ unsigned magic_pkt:1; /* E-MAC supports magic packet detection */ diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index db3ef87f0991..b558e9f5611e 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -712,8 +712,8 @@ static int ravb_dmac_init(struct net_device *ndev) return error; /* Initialise PTP Clock driver */ - if (info->gptp) - ravb_ptp_init(ndev); + if (info->ptp && info->ptp->dmac_start) + return info->ptp->dmac_start(ndev); return 0; } @@ -1124,8 +1124,8 @@ static int ravb_stop_dma(struct net_device *ndev) } /* Stop PTP Clock driver */ - if (info->gptp) - ravb_ptp_stop(ndev); + if (info->ptp && info->ptp->dmac_stop) + info->ptp->dmac_stop(ndev); /* Stop AVB-DMAC process */ return ravb_set_opmode(ndev, CCC_OPC_CONFIG); @@ -1774,7 +1774,7 @@ static int ravb_get_ts_info(struct net_device *ndev, struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *hw_info = priv->info; - if (priv->ptp.clock && (hw_info->gptp || hw_info->ccc_gac)) { + if (priv->ptp.clock && hw_info->ptp) { info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | @@ -1835,21 +1835,11 @@ static int ravb_set_config_mode(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; - int error; - if (info->gptp) { - error = ravb_set_opmode(ndev, CCC_OPC_CONFIG); - if (error) - return error; - /* Set CSEL value */ - ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB); - } else if (info->ccc_gac) { - error = ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB); - } else { - error = ravb_set_opmode(ndev, CCC_OPC_CONFIG); - } + if (info->ptp && info->ptp->set_config_mode) + return info->ptp->set_config_mode(ndev); - return error; + return ravb_set_opmode(ndev, CCC_OPC_CONFIG); } static int ravb_compute_gti(struct net_device *ndev) @@ -1860,7 +1850,7 @@ static int ravb_compute_gti(struct net_device *ndev) unsigned long rate; u64 inc; - if (!(info->gptp || info->ccc_gac)) + if (!info->ptp) return 0; if (info->gptp_ref_clk) @@ -1967,8 +1957,11 @@ static int ravb_open(struct net_device *ndev) ravb_emac_init(ndev); /* Initialise PTP Clock driver */ - if (info->ccc_gac) - ravb_ptp_init(ndev); + if (info->ptp && info->ptp->ndev_open) { + error = info->ptp->ndev_open(ndev); + if (error) + goto out_ptp_stop; + } /* PHY control start */ error = ravb_phy_start(ndev); @@ -1981,8 +1974,8 @@ static int ravb_open(struct net_device *ndev) out_ptp_stop: /* Stop PTP Clock driver */ - if (info->ccc_gac) - ravb_ptp_stop(ndev); + if (info->ptp && info->ptp->ndev_close) + info->ptp->ndev_close(ndev); ravb_stop_dma(ndev); out_set_reset: ravb_set_opmode(ndev, CCC_OPC_RESET); @@ -2190,7 +2183,7 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev) desc->dptr = cpu_to_le32(dma_addr); /* TX timestamp required */ - if (info->gptp || info->ccc_gac) { + if (info->ptp) { if (q == RAVB_NC) { ts_skb = kmalloc_obj(*ts_skb, GFP_ATOMIC); if (!ts_skb) { @@ -2372,8 +2365,8 @@ static int ravb_close(struct net_device *ndev) } /* Stop PTP Clock driver */ - if (info->ccc_gac) - ravb_ptp_stop(ndev); + if (info->ptp && info->ptp->ndev_close) + info->ptp->ndev_close(ndev); /* Set the config mode to stop the AVB-DMAC's processes */ if (ravb_stop_dma(ndev) < 0) @@ -2381,7 +2374,7 @@ static int ravb_close(struct net_device *ndev) "device will be stopped after h/w processes are done.\n"); /* Clear the timestamp list */ - if (info->gptp || info->ccc_gac) { + if (info->ptp) { list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) { list_del(&ts_skb->list); kfree_skb(ts_skb->skb); @@ -2663,6 +2656,26 @@ static int ravb_mdio_release(struct ravb_private *priv) return 0; } +static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev) +{ + int ret; + + ret = ravb_set_opmode(ndev, CCC_OPC_CONFIG); + if (ret) + return ret; + + /* gPTP Clock Select High-speed peripheral bus clock. */ + ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB); + + return 0; +} + +static const struct ravb_gptp_info ravb_gen2_ptp_info = { + .set_config_mode = ravb_gen2_ptp_set_config_mode, + .dmac_start = ravb_ptp_init, + .dmac_stop = ravb_ptp_stop, +}; + static const struct ravb_hw_info ravb_gen2_hw_info = { .receive = ravb_rx_rcar, .set_rate = ravb_set_rate_rcar, @@ -2681,12 +2694,24 @@ static const struct ravb_hw_info ravb_gen2_hw_info = { SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), .rx_desc_size = sizeof(struct ravb_ex_rx_desc), .dbat_entry_num = 22, + .ptp = &ravb_gen2_ptp_info, .aligned_tx = 1, - .gptp = 1, .nc_queues = 1, .magic_pkt = 1, }; +static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev) +{ + /* Enable gPTP Clock and Select High-speed peripheral bus clock. */ + return ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB); +} + +static const struct ravb_gptp_info ravb_gen3_ptp_info = { + .set_config_mode = ravb_gen3_ptp_set_config_mode, + .ndev_open = ravb_ptp_init, + .ndev_close = ravb_ptp_stop, +}; + static const struct ravb_hw_info ravb_gen3_hw_info = { .receive = ravb_rx_rcar, .set_rate = ravb_set_rate_rcar, @@ -2705,11 +2730,11 @@ static const struct ravb_hw_info ravb_gen3_hw_info = { SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), .rx_desc_size = sizeof(struct ravb_ex_rx_desc), .dbat_entry_num = 22, + .ptp = &ravb_gen3_ptp_info, .internal_delay = 1, .tx_counters = 1, .multi_irqs = 1, .irq_en_dis = 1, - .ccc_gac = 1, .nc_queues = 1, .magic_pkt = 1, }; @@ -2736,7 +2761,7 @@ static const struct ravb_hw_info ravb_gen4_hw_info = { .tx_counters = 1, .multi_irqs = 1, .irq_en_dis = 1, - .ccc_gac = 1, + .ptp = &ravb_gen3_ptp_info, .nc_queues = 1, .magic_pkt = 1, }; @@ -2761,7 +2786,7 @@ static const struct ravb_hw_info ravb_rzv2m_hw_info = { .dbat_entry_num = 22, .multi_irqs = 1, .err_mgmt_irqs = 1, - .gptp = 1, + .ptp = &ravb_gen2_ptp_info, .gptp_ref_clk = 1, .nc_queues = 1, .magic_pkt = 1, From 9a85f9dfbc3f6fea346044fecf0a0c637a4ad213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:34 +0200 Subject: [PATCH 0773/2126] net: ethernet: ravb: Add callback for gPTP probe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Different generations of the RAVB IP have different needs when it probes the gPTP timer clock. Add a callback in the PTP information to allow each generation to probe its own way. With this the last gPTP specific flag (gptp_ref_clk) can be removed. However the primary motivation for the change is to prepare for Gen4 support, which compared to other generations with gPTP support does not have the clock as part of the IP itself. Gen4 will not need to compute GTI value as it have nowhere to write it, as the gPTP clock is external. For this reason move the computation of it into the newly gPTP probe specific callbacks for the RAVB IP's that support it. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-8-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 3 +- drivers/net/ethernet/renesas/ravb_main.c | 53 +++++++++++++++--------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index 6603f90b19e1..b788e8f5260d 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -1041,6 +1041,7 @@ struct ravb_ptp { * with the gPTP clock. This struct provides the callbacks to be called at * critical points in the RAVB driver. * + * @probe: Probe the gPTP clock * @set_config_mode: Enter config mode * @dmac_start: Called when the DMAC starts * @dmac_stop: Called when the DMAC stops @@ -1048,6 +1049,7 @@ struct ravb_ptp { * @ndev_close: Called when the ndev is closed */ struct ravb_gptp_info { + int (*probe)(struct net_device *ndev); int (*set_config_mode)(struct net_device *ndev); int (*dmac_start)(struct net_device *ndev); void (*dmac_stop)(struct net_device *ndev); @@ -1084,7 +1086,6 @@ struct ravb_hw_info { unsigned multi_irqs:1; /* AVB-DMAC and E-MAC has multiple irqs */ unsigned irq_en_dis:1; /* Has separate irq enable and disable regs */ unsigned err_mgmt_irqs:1; /* Line1 (Err) and Line2 (Mgmt) irqs are separate */ - unsigned gptp_ref_clk:1; /* gPTP has separate reference clock */ unsigned nc_queues:1; /* AVB-DMAC has RX and TX NC queues */ unsigned magic_pkt:1; /* E-MAC supports magic packet detection */ unsigned half_duplex:1; /* E-MAC supports half duplex mode */ diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index b558e9f5611e..77e66a9870ab 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1842,21 +1842,14 @@ static int ravb_set_config_mode(struct net_device *ndev) return ravb_set_opmode(ndev, CCC_OPC_CONFIG); } -static int ravb_compute_gti(struct net_device *ndev) +static int ravb_compute_gti(struct net_device *ndev, struct clk *clk) { struct ravb_private *priv = netdev_priv(ndev); - const struct ravb_hw_info *info = priv->info; struct device *dev = ndev->dev.parent; unsigned long rate; u64 inc; - if (!info->ptp) - return 0; - - if (info->gptp_ref_clk) - rate = clk_get_rate(priv->gptp_clk); - else - rate = clk_get_rate(priv->clk); + rate = clk_get_rate(clk); if (!rate) return -EINVAL; @@ -2656,6 +2649,13 @@ static int ravb_mdio_release(struct ravb_private *priv) return 0; } +static int ravb_gen2_ptp_probe(struct net_device *ndev) +{ + struct ravb_private *priv = netdev_priv(ndev); + + return ravb_compute_gti(ndev, priv->clk); +} + static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev) { int ret; @@ -2671,6 +2671,7 @@ static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev) } static const struct ravb_gptp_info ravb_gen2_ptp_info = { + .probe = ravb_gen2_ptp_probe, .set_config_mode = ravb_gen2_ptp_set_config_mode, .dmac_start = ravb_ptp_init, .dmac_stop = ravb_ptp_stop, @@ -2707,6 +2708,7 @@ static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev) } static const struct ravb_gptp_info ravb_gen3_ptp_info = { + .probe = ravb_gen2_ptp_probe, .set_config_mode = ravb_gen3_ptp_set_config_mode, .ndev_open = ravb_ptp_init, .ndev_close = ravb_ptp_stop, @@ -2766,6 +2768,24 @@ static const struct ravb_hw_info ravb_gen4_hw_info = { .magic_pkt = 1, }; +static int ravb_rzv2m_ptp_probe(struct net_device *ndev) +{ + struct ravb_private *priv = netdev_priv(ndev); + + priv->gptp_clk = devm_clk_get(&priv->pdev->dev, "gptp"); + if (IS_ERR(priv->gptp_clk)) + return PTR_ERR(priv->gptp_clk); + + return ravb_compute_gti(ndev, priv->gptp_clk); +} + +static const struct ravb_gptp_info ravb_rzv2m_ptp_info = { + .probe = ravb_rzv2m_ptp_probe, + .set_config_mode = ravb_gen2_ptp_set_config_mode, + .dmac_start = ravb_ptp_init, + .dmac_stop = ravb_ptp_stop, +}; + static const struct ravb_hw_info ravb_rzv2m_hw_info = { .receive = ravb_rx_rcar, .set_rate = ravb_set_rate_rcar, @@ -2786,8 +2806,7 @@ static const struct ravb_hw_info ravb_rzv2m_hw_info = { .dbat_entry_num = 22, .multi_irqs = 1, .err_mgmt_irqs = 1, - .ptp = &ravb_gen2_ptp_info, - .gptp_ref_clk = 1, + .ptp = &ravb_rzv2m_ptp_info, .nc_queues = 1, .magic_pkt = 1, }; @@ -2979,12 +2998,10 @@ static int ravb_probe(struct platform_device *pdev) goto out_reset_assert; } - if (info->gptp_ref_clk) { - priv->gptp_clk = devm_clk_get(&pdev->dev, "gptp"); - if (IS_ERR(priv->gptp_clk)) { - error = PTR_ERR(priv->gptp_clk); + if (info->ptp && info->ptp->probe) { + error = info->ptp->probe(ndev); + if (error) goto out_reset_assert; - } } priv->refclk = devm_clk_get_optional(&pdev->dev, "refclk"); @@ -3037,10 +3054,6 @@ static int ravb_probe(struct platform_device *pdev) ndev->netdev_ops = &ravb_netdev_ops; ndev->ethtool_ops = &ravb_ethtool_ops; - error = ravb_compute_gti(ndev); - if (error) - goto out_rpm_put; - ravb_parse_delay_mode(np, ndev); /* Allocate descriptor base address table */ From 931770c1995f6fa188f488700c22ad99fff1abfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:35 +0200 Subject: [PATCH 0774/2126] net: ethernet: ravb: Add callback for gPTP clock index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare for adding Gen4 support which have an optional external gPTP clock. Add a callback to get the clock index and use it to determine if the device shall report gPTP support. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-9-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 2 ++ drivers/net/ethernet/renesas/ravb_main.c | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index b788e8f5260d..27e2b31955ba 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -1042,6 +1042,7 @@ struct ravb_ptp { * critical points in the RAVB driver. * * @probe: Probe the gPTP clock + * @clock_index: Get the PTP clock index, if any * @set_config_mode: Enter config mode * @dmac_start: Called when the DMAC starts * @dmac_stop: Called when the DMAC stops @@ -1050,6 +1051,7 @@ struct ravb_ptp { */ struct ravb_gptp_info { int (*probe)(struct net_device *ndev); + int (*clock_index)(struct net_device *ndev); int (*set_config_mode)(struct net_device *ndev); int (*dmac_start)(struct net_device *ndev); void (*dmac_stop)(struct net_device *ndev); diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 77e66a9870ab..2dff47c2a125 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1773,8 +1773,13 @@ static int ravb_get_ts_info(struct net_device *ndev, { struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *hw_info = priv->info; + int index = -1; - if (priv->ptp.clock && hw_info->ptp) { + if (hw_info->ptp && hw_info->ptp->clock_index) + index = hw_info->ptp->clock_index(ndev); + + /* Only advertise ptp clock if present. */ + if (index >= 0) { info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | @@ -1785,7 +1790,7 @@ static int ravb_get_ts_info(struct net_device *ndev, (1 << HWTSTAMP_FILTER_NONE) | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | (1 << HWTSTAMP_FILTER_ALL); - info->phc_index = ptp_clock_index(priv->ptp.clock); + info->phc_index = index; } return 0; @@ -2656,6 +2661,16 @@ static int ravb_gen2_ptp_probe(struct net_device *ndev) return ravb_compute_gti(ndev, priv->clk); } +static int ravb_gen2_ptp_clock_index(struct net_device *ndev) +{ + struct ravb_private *priv = netdev_priv(ndev); + + if (!priv->ptp.clock) + return -ENODEV; + + return ptp_clock_index(priv->ptp.clock); +} + static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev) { int ret; @@ -2672,6 +2687,7 @@ static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev) static const struct ravb_gptp_info ravb_gen2_ptp_info = { .probe = ravb_gen2_ptp_probe, + .clock_index = ravb_gen2_ptp_clock_index, .set_config_mode = ravb_gen2_ptp_set_config_mode, .dmac_start = ravb_ptp_init, .dmac_stop = ravb_ptp_stop, @@ -2709,6 +2725,7 @@ static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev) static const struct ravb_gptp_info ravb_gen3_ptp_info = { .probe = ravb_gen2_ptp_probe, + .clock_index = ravb_gen2_ptp_clock_index, .set_config_mode = ravb_gen3_ptp_set_config_mode, .ndev_open = ravb_ptp_init, .ndev_close = ravb_ptp_stop, @@ -2781,6 +2798,7 @@ static int ravb_rzv2m_ptp_probe(struct net_device *ndev) static const struct ravb_gptp_info ravb_rzv2m_ptp_info = { .probe = ravb_rzv2m_ptp_probe, + .clock_index = ravb_gen2_ptp_clock_index, .set_config_mode = ravb_gen2_ptp_set_config_mode, .dmac_start = ravb_ptp_init, .dmac_stop = ravb_ptp_stop, From ef488a9da66d0f9fb296ffdbaa2bbb1602e65496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:36 +0200 Subject: [PATCH 0775/2126] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The RAVB module on Gen4 have no gPTP clock as part of the RAVB module itself, instead it relies on an external system wide gPTP clock. The gPTP clock is shared with RTSN on V4H and RSWITCH on S4. Add an optional phandle so that the RAVB driver can find and use the gPTP clock. Ideally this should have been a mandatory property but for backward compatible it is optional. The RAVB module is capable of functioning without it, but can in such cases not provided PTP functionality. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260921175037.4084310-10-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- .../devicetree/bindings/net/renesas,etheravb.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/net/renesas,etheravb.yaml b/Documentation/devicetree/bindings/net/renesas,etheravb.yaml index 1e00ef5b3acd..fad002492421 100644 --- a/Documentation/devicetree/bindings/net/renesas,etheravb.yaml +++ b/Documentation/devicetree/bindings/net/renesas,etheravb.yaml @@ -97,6 +97,8 @@ properties: phy-handle: true + ptp-timer: true + '#address-cells': description: Number of address cells for the MDIO bus. const: 1 @@ -305,6 +307,15 @@ allOf: items: - const: fck - const: refclk + - if: + not: + properties: + compatible: + contains: + const: renesas,etheravb-rcar-gen4 + then: + properties: + ptp-timer: false additionalProperties: false From 2b240cfc6de4a6ca7779323e0f1ffdf0d7f99add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:37 +0200 Subject: [PATCH 0776/2126] net: ethernet: ravb: Add gPTP support for Gen4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While driver advertises gPTP support on Gen4 platforms it is in fact completely broken. On R-Car Gen4 devices the RAVB module have no internal gPTP clock as generations before it. Instead it utilizes a system-wide gPTP clock. This change utilizes the refactoring of the RAVB gPTP code to add support for a system-wide clock and stops the Gen4 devices trying to use the non-existing internal gPTP clock. To remain backward compatible the ptp-timer property is optional.If not present, or not enabled, the RAVB driver will no longer advertise gPTP support to user-space. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-11-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 3 ++ drivers/net/ethernet/renesas/ravb_main.c | 54 +++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h index 27e2b31955ba..5d35b40d7c58 100644 --- a/drivers/net/ethernet/renesas/ravb.h +++ b/drivers/net/ethernet/renesas/ravb.h @@ -249,6 +249,8 @@ enum APSR_BIT { APSR_RDM = 0x00002000, APSR_TDM = 0x00004000, APSR_MIISELECT = 0x01000000, /* R-Car V4M only */ + APSR_GPTPTIMER_SOURCE = BIT(25), /* Gen4 */ + APSR_GPTPCLOCK = BIT(29), /* Gen4 */ }; /* RCR */ @@ -1132,6 +1134,7 @@ struct ravb_private { struct list_head ts_skb_list; u32 ts_skb_tag; struct ravb_ptp ptp; + struct device_node *of_gptp; /* Reference to external gPTP clock, if any. */ spinlock_t lock; /* Register access lock */ u32 cur_rx[NUM_RX_QUEUE]; /* Consumer ring indices */ u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */ diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 2dff47c2a125..5a07cc0180d8 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -2758,6 +2758,57 @@ static const struct ravb_hw_info ravb_gen3_hw_info = { .magic_pkt = 1, }; +static int ravb_gen4_ptp_probe(struct net_device *ndev) +{ + struct ravb_private *priv = netdev_priv(ndev); + + priv->of_gptp = of_parse_phandle(priv->pdev->dev.of_node, "ptp-timer", 0); + if (!priv->of_gptp) + return 0; + + if (!of_device_is_available(priv->of_gptp)) { + of_node_put(priv->of_gptp); + priv->of_gptp = NULL; + } + + return 0; +} + +static int ravb_gen4_ptp_clock_index(struct net_device *ndev) +{ + struct ravb_private *priv = netdev_priv(ndev); + + /* If no clock, mimic ptp_clock_index_by_of_node() fail and return -1 */ + if (!priv->of_gptp) + return -1; + + return ptp_clock_index_by_of_node(priv->of_gptp); +} + +static int ravb_gen4_ptp_set_config_mode(struct net_device *ndev) +{ + struct ravb_private *priv = netdev_priv(ndev); + int ret; + + /* Enable gPTP Clock and Select High-speed peripheral bus clock. */ + ret = ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB); + if (ret) + return ret; + + /* Set PTP source to GPTP module, only option on Gen4. */ + if (priv->of_gptp) + ravb_modify(ndev, APSR, APSR_GPTPTIMER_SOURCE | APSR_GPTPCLOCK, + APSR_GPTPTIMER_SOURCE | APSR_GPTPCLOCK); + + return 0; +} + +static const struct ravb_gptp_info ravb_gen4_ptp_info = { + .probe = ravb_gen4_ptp_probe, + .clock_index = ravb_gen4_ptp_clock_index, + .set_config_mode = ravb_gen4_ptp_set_config_mode, +}; + static const struct ravb_hw_info ravb_gen4_hw_info = { .receive = ravb_rx_rcar, .set_rate = ravb_set_rate_rcar, @@ -2780,7 +2831,7 @@ static const struct ravb_hw_info ravb_gen4_hw_info = { .tx_counters = 1, .multi_irqs = 1, .irq_en_dis = 1, - .ptp = &ravb_gen3_ptp_info, + .ptp = &ravb_gen4_ptp_info, .nc_queues = 1, .magic_pkt = 1, }; @@ -3194,6 +3245,7 @@ static void ravb_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); pm_runtime_dont_use_autosuspend(dev); clk_unprepare(priv->refclk); + of_node_put(priv->of_gptp); reset_control_assert(priv->rstc); free_netdev(ndev); platform_set_drvdata(pdev, NULL); From a529f9258da5cbfe6d313651ceabda23892e5027 Mon Sep 17 00:00:00 2001 From: Yibo Tan Date: Tue, 22 Sep 2026 19:36:01 +0800 Subject: [PATCH 0777/2126] ptp: idt82p33: Stop PTP work producers before teardown idt82p33_ptp_clock_unregister_all() cancels each channel's adjtime work before unregistering its PTP clock. An adjustment callback already in progress can schedule that work after cancellation returns. Device removal then frees the channel while its delayed work remains queued, causing a use-after-free. Mark the device as stopping under its lock before draining work. Reject new adjustment and EXTS requests, clear the EXTS polling mask, and synchronously drain the EXTS and channel adjustment work before the device storage is released. With an i2c-stub device and kprobe-controlled callback timing, three runs of the unmodified driver reported KASAN use-after-free after unbind. Three runs with this change completed without a kernel diagnostic. No physical IDT82P33 device was tested. Cc: stable+noautosel@kernel.org # untested fix to a driver init path race Signed-off-by: Yibo Tan Link: https://patch.msgid.link/20260922113601.855416-1-lhfff@tju.edu.cn Signed-off-by: Jakub Kicinski --- drivers/ptp/ptp_idt82p33.c | 25 +++++++++++++++++++++---- drivers/ptp/ptp_idt82p33.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/ptp/ptp_idt82p33.c b/drivers/ptp/ptp_idt82p33.c index f01c50dfa44e..ffc2ec1fc4be 100644 --- a/drivers/ptp/ptp_idt82p33.c +++ b/drivers/ptp/ptp_idt82p33.c @@ -918,6 +918,13 @@ static void idt82p33_ptp_clock_unregister_all(struct idt82p33 *idt82p33) struct idt82p33_channel *channel; u8 i; + mutex_lock(idt82p33->lock); + idt82p33->stopping = true; + idt82p33->extts_mask = 0; + mutex_unlock(idt82p33->lock); + + cancel_delayed_work_sync(&idt82p33->extts_work); + for (i = 0; i < MAX_PHC_PLL; i++) { channel = &idt82p33->channel[i]; cancel_delayed_work_sync(&channel->adjtime_work); @@ -937,6 +944,10 @@ static int idt82p33_enable(struct ptp_clock_info *ptp, int err = -EOPNOTSUPP; mutex_lock(idt82p33->lock); + if (idt82p33->stopping) { + err = -ENODEV; + goto out; + } switch (rq->type) { case PTP_CLK_REQ_PEROUT: @@ -958,6 +969,7 @@ static int idt82p33_enable(struct ptp_clock_info *ptp, break; } +out: mutex_unlock(idt82p33->lock); if (err) @@ -1044,11 +1056,14 @@ static int idt82p33_adjtime(struct ptp_clock_info *ptp, s64 delta_ns) return -EBUSY; mutex_lock(idt82p33->lock); + if (idt82p33->stopping) { + err = -ENODEV; + goto out; + } if (abs(delta_ns) < phase_snap_threshold) { err = idt82p33_start_ddco(channel, delta_ns); - mutex_unlock(idt82p33->lock); - return err; + goto out; } /* Use more accurate internal 1pps triggered write first */ @@ -1056,6 +1071,7 @@ static int idt82p33_adjtime(struct ptp_clock_info *ptp, s64 delta_ns) if (err && delta_ns > IMMEDIATE_SNAP_THRESHOLD_NS) err = _idt82p33_adjtime_immediate(channel, delta_ns); +out: mutex_unlock(idt82p33->lock); if (err) @@ -1342,6 +1358,8 @@ static void idt82p33_extts_check(struct work_struct *work) return; mutex_lock(idt82p33->lock); + if (idt82p33->stopping) + goto out; for (i = 0; i < MAX_PHC_PLL; i++) { mask = 1 << i; @@ -1367,6 +1385,7 @@ static void idt82p33_extts_check(struct work_struct *work) schedule_delayed_work(&idt82p33->extts_work, msecs_to_jiffies(EXTTS_PERIOD_MS)); +out: mutex_unlock(idt82p33->lock); } @@ -1442,8 +1461,6 @@ static void idt82p33_remove(struct platform_device *pdev) { struct idt82p33 *idt82p33 = platform_get_drvdata(pdev); - cancel_delayed_work_sync(&idt82p33->extts_work); - idt82p33_ptp_clock_unregister_all(idt82p33); } diff --git a/drivers/ptp/ptp_idt82p33.h b/drivers/ptp/ptp_idt82p33.h index 6a63c14b6966..b88c921adaa9 100644 --- a/drivers/ptp/ptp_idt82p33.h +++ b/drivers/ptp/ptp_idt82p33.h @@ -91,6 +91,7 @@ struct idt82p33 { u8 extts_mask; bool extts_single_shot; struct delayed_work extts_work; + bool stopping; /* Remember the ptp channel to report extts */ struct idt82p33_channel *event_channel[MAX_PHC_PLL]; /* Mutex to protect operations from being interrupted */ From 456a389f594a1a46a2913cf082579a9ceec481eb Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Tue, 22 Sep 2026 11:09:24 -0400 Subject: [PATCH 0778/2126] net: macb: Poll for link state changes when using the internal PCS. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When used with an offboard transceiver (e.g. an SFP), link state needs to be measured at the PCS rather than an onboard PHY. Poll the link state when the PCS is active to allow the kernel to detect link state changes in this case. Signed-off-by: Nathan Whitehorn Reviewed-by: Théo Lebrun Link: https://patch.msgid.link/20260922151429.23272-2-nwhitehorn@pa.msu.edu Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index e3ee7d1d1263..1b8f6a752b05 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1025,6 +1025,7 @@ static int macb_mii_probe(struct net_device *netdev) struct macb *bp = netdev_priv(netdev); bp->phylink_sgmii_pcs.ops = &macb_phylink_pcs_ops; + bp->phylink_sgmii_pcs.poll = true; bp->phylink_usx_pcs.ops = &macb_phylink_usx_pcs_ops; bp->phylink_config.dev = &netdev->dev; From f342b1208f8df6c6b4c45d0702e6f150357d0143 Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Tue, 22 Sep 2026 11:09:25 -0400 Subject: [PATCH 0779/2126] net: macb: add support for 1000BASE-X autonegotiation to PCS The current PCS code unconditionally uses SGMII autonegotiation, though the hardware supports both SGMII and 1000BASE-X modes. Decouple the choice of PCS enablement from use of the SGMII mode when running at gigabit rates and announce to phylink that 1000BASE-X is a supported operating mode. This enables direct attachment of the PCS to e.g. an SFP. The 1000BASE-X code in phylink also sometimes calls the autonegotiation restart method, so add an implementation of autonegotiation restart and make sure that pcs_config() signals to phylink when the AN advertisement has changed. Signed-off-by: Nathan Whitehorn Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260922151429.23272-3-nwhitehorn@pa.msu.edu Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_main.c | 36 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 1b8f6a752b05..c26ffcf73562 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -583,7 +583,12 @@ static void macb_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, static void macb_pcs_an_restart(struct phylink_pcs *pcs) { - /* Not supported */ + struct macb *bp = container_of(pcs, struct macb, phylink_sgmii_pcs); + u32 old, new; + + old = gem_readl(bp, PCSCNTRL); + new = old | BMCR_ANRESTART; + gem_writel(bp, PCSCNTRL, new); } static int macb_pcs_config(struct phylink_pcs *pcs, @@ -594,11 +599,17 @@ static int macb_pcs_config(struct phylink_pcs *pcs, { struct macb *bp = container_of(pcs, struct macb, phylink_sgmii_pcs); u32 old, new; + int ret = 0; old = gem_readl(bp, PCSANADV); new = phylink_mii_c22_pcs_encode_advertisement(interface, advertising); - if (new != -EINVAL && old != new) + if (new != -EINVAL && old != new) { + /* pcs_config() is supposed to return 1 if AN advertisement + * has changed + */ + ret = 1; gem_writel(bp, PCSANADV, new); + } /* Disable AN if it's not to be used, enable otherwise. * Must be written after PCSSEL is set in NCFGR which is done in @@ -612,7 +623,7 @@ static int macb_pcs_config(struct phylink_pcs *pcs, if (old != new) gem_writel(bp, PCSCNTRL, new); - return 0; + return ret; } static const struct phylink_pcs_ops macb_phylink_usx_pcs_ops = { @@ -750,7 +761,9 @@ static void macb_mac_config(struct phylink_config *config, unsigned int mode, ctrl &= ~(GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL)); ncr &= ~GEM_BIT(ENABLE_HS_MAC); - if (state->interface == PHY_INTERFACE_MODE_SGMII) { + if (state->interface == PHY_INTERFACE_MODE_1000BASEX) { + ctrl |= GEM_BIT(PCSSEL); + } else if (state->interface == PHY_INTERFACE_MODE_SGMII) { ctrl |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL); } else if (state->interface == PHY_INTERFACE_MODE_10GBASER) { ctrl |= GEM_BIT(PCSSEL); @@ -957,7 +970,8 @@ static struct phylink_pcs *macb_mac_select_pcs(struct phylink_config *config, if (interface == PHY_INTERFACE_MODE_10GBASER) return &bp->phylink_usx_pcs; - else if (interface == PHY_INTERFACE_MODE_SGMII) + else if (interface == PHY_INTERFACE_MODE_1000BASEX || + interface == PHY_INTERFACE_MODE_SGMII) return &bp->phylink_sgmii_pcs; else return NULL; @@ -1032,7 +1046,8 @@ static int macb_mii_probe(struct net_device *netdev) bp->phylink_config.type = PHYLINK_NETDEV; bp->phylink_config.mac_managed_pm = true; - if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII) { + if (bp->phy_interface == PHY_INTERFACE_MODE_1000BASEX || + bp->phy_interface == PHY_INTERFACE_MODE_SGMII) { bp->phylink_config.poll_fixed_state = true; bp->phylink_config.get_fixed_state = macb_get_pcs_fixed_state; /* The PCSAUTONEG bit in PCSCNTRL is on out of reset. Setting @@ -1061,9 +1076,12 @@ static int macb_mii_probe(struct net_device *netdev) bp->phylink_config.supported_interfaces); phy_interface_set_rgmii(bp->phylink_config.supported_interfaces); - if (bp->caps & MACB_CAPS_PCS) + if (bp->caps & MACB_CAPS_PCS) { + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + bp->phylink_config.supported_interfaces); __set_bit(PHY_INTERFACE_MODE_SGMII, bp->phylink_config.supported_interfaces); + } if (bp->caps & MACB_CAPS_HIGH_SPEED) { __set_bit(PHY_INTERFACE_MODE_10GBASER, @@ -4921,7 +4939,9 @@ static int macb_init_dflt(struct platform_device *pdev) /* Set MII management clock divider */ val = macb_mdc_clk_div(bp); val |= macb_dbw(bp); - if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII) + if (bp->phy_interface == PHY_INTERFACE_MODE_1000BASEX) + val |= GEM_BIT(PCSSEL); + else if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII) val |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL); macb_writel(bp, NCFGR, val); From b6d2762919bc803542e4ce4bfb42d0205475b9d5 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:33 +0800 Subject: [PATCH 0780/2126] net: dsa: motorcomm: Remove YT921X_PORT_MASK_* macros Remove YT921X_PORT_MASK_* macros since they are only thin wrappers around BIT() and GENMASK() and are not used in other places (plain BIT() and GENMASK() are used there). No functional change. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-2-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 8b0ac5fc8c8b..825e0bfcff86 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -108,46 +108,41 @@ struct yt921x_info { u16 external_mask; }; -#define YT921X_PORT_MASK_INTn(port) BIT(port) -#define YT921X_PORT_MASK_INT0_n(n) GENMASK((n) - 1, 0) -#define YT921X_PORT_MASK_EXT0 BIT(8) -#define YT921X_PORT_MASK_EXT1 BIT(9) - static const struct yt921x_info yt921x_infos[] = { { "YT9215SC", YT9215_MAJOR, 1, 0, - YT921X_PORT_MASK_INT0_n(5), - YT921X_PORT_MASK_EXT0 | YT921X_PORT_MASK_EXT1, + GENMASK(4, 0), + BIT(8) | BIT(9), }, { "YT9215S", YT9215_MAJOR, 2, 0, - YT921X_PORT_MASK_INT0_n(5), - YT921X_PORT_MASK_EXT0 | YT921X_PORT_MASK_EXT1, + GENMASK(4, 0), + BIT(8) | BIT(9), }, { "YT9215RB", YT9215_MAJOR, 3, 0, - YT921X_PORT_MASK_INT0_n(5), - YT921X_PORT_MASK_EXT0 | YT921X_PORT_MASK_EXT1, + GENMASK(4, 0), + BIT(8) | BIT(9), }, { "YT9214NB", YT9215_MAJOR, 3, 2, - YT921X_PORT_MASK_INTn(1) | YT921X_PORT_MASK_INTn(3), - YT921X_PORT_MASK_EXT0 | YT921X_PORT_MASK_EXT1, + BIT(1) | BIT(3), + BIT(8) | BIT(9), }, { "YT9213NB", YT9215_MAJOR, 3, 3, - YT921X_PORT_MASK_INTn(1) | YT921X_PORT_MASK_INTn(3), - YT921X_PORT_MASK_EXT1, + BIT(1) | BIT(3), + BIT(9), }, { "YT9218N", YT9218_MAJOR, 0, 0, - YT921X_PORT_MASK_INT0_n(8), + GENMASK(7, 0), 0, }, { "YT9218MB", YT9218_MAJOR, 1, 0, - YT921X_PORT_MASK_INT0_n(8), - YT921X_PORT_MASK_EXT0 | YT921X_PORT_MASK_EXT1, + GENMASK(7, 0), + BIT(8) | BIT(9), }, {} }; From 605597aff80348308e8145817b840a4bc50db85f Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:34 +0800 Subject: [PATCH 0781/2126] net: dsa: motorcomm: Split xMII and SERDES port masks Replace external_mask with xmii_mask and serdes_mask, and advertise the interface modes it actually supports. Also move struct yt921x_info into chip.h for future use. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-3-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 39 ++++++++++++-------------------- drivers/net/dsa/motorcomm/chip.h | 13 +++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 825e0bfcff86..54881856b796 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -96,53 +96,48 @@ static const struct yt921x_mib_desc yt921x_mib_descs[] = { MIB_DESC(1, YT921X_MIB_DATA_TX_OAM, "TxOAM"), }; -struct yt921x_info { - const char *name; - u16 major; - /* Unknown, seems to be plain enumeration */ - u8 mode; - u8 extmode; - /* Ports with integral GbE PHYs, not including MCU Port 10 */ - u16 internal_mask; - /* TODO: see comments in yt921x_dsa_phylink_get_caps() */ - u16 external_mask; -}; - static const struct yt921x_info yt921x_infos[] = { { "YT9215SC", YT9215_MAJOR, 1, 0, GENMASK(4, 0), + BIT(9), BIT(8) | BIT(9), }, { "YT9215S", YT9215_MAJOR, 2, 0, GENMASK(4, 0), - BIT(8) | BIT(9), + BIT(9), + BIT(8), }, { "YT9215RB", YT9215_MAJOR, 3, 0, GENMASK(4, 0), BIT(8) | BIT(9), + 0, }, { "YT9214NB", YT9215_MAJOR, 3, 2, BIT(1) | BIT(3), - BIT(8) | BIT(9), + BIT(9), + BIT(8), }, { "YT9213NB", YT9215_MAJOR, 3, 3, BIT(1) | BIT(3), BIT(9), + BIT(9), }, { "YT9218N", YT9218_MAJOR, 0, 0, GENMASK(7, 0), 0, + 0, }, { "YT9218MB", YT9218_MAJOR, 1, 0, GENMASK(7, 0), BIT(8) | BIT(9), + BIT(8) | BIT(9), }, {} }; @@ -4021,15 +4016,10 @@ yt921x_dsa_phylink_get_caps(struct dsa_switch *ds, int port, */ __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces); - } else if (info->external_mask & BIT(port)) { - /* TODO: external ports may support SERDES only, XMII only, or - * SERDES + XMII depending on the chip. However, we can't get - * the accurate config table due to lack of document, thus - * we simply declare SERDES + XMII and rely on the correctness - * of devicetree for now. - */ + return; + } - /* SERDES */ + if (BIT(port) & info->serdes_mask) { __set_bit(PHY_INTERFACE_MODE_SGMII, config->supported_interfaces); /* REVSGMII (SGMII in PHY role) should go here, once @@ -4042,9 +4032,8 @@ yt921x_dsa_phylink_get_caps(struct dsa_switch *ds, int port, __set_bit(PHY_INTERFACE_MODE_2500BASEX, config->supported_interfaces); config->mac_capabilities |= MAC_2500FD; - - /* XMII */ - + } + if (BIT(port) & info->xmii_mask) { /* Not tested. To add support for XMII: * - Add proper interface modes below * - Handle them in yt921x_port_config() diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 83cd454955dd..83e76cefbccd 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -960,6 +960,19 @@ struct yt921x_reg_ops { int (*write)(void *context, u32 reg, u32 val); }; +struct yt921x_info { + const char *name; + u16 major; + /* Unknown, seems to be plain enumeration */ + u8 mode; + u8 extmode; + /* Ports with integral GbE PHYs, not including MCU Port 10 */ + u16 internal_mask; + /* Note: xmii_mask and serdes_mask may overlap */ + u16 xmii_mask; + u16 serdes_mask; +}; + struct yt921x_priv { struct dsa_switch ds; From 07b60e1bf4a1e41b4def32882f9ad6fa002682fb Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:35 +0800 Subject: [PATCH 0782/2126] net: dsa: motorcomm: Identify port type at runtime The yt921x_port_is_internal/external() macros hardcoded the port layout: they treat ports 8 and 9 as external on every chip and count the dummy ports as internal. Identify the actual port capabilities using chip info and track configuration of external ports (although only SerDes is supported now). This is a hardening and cleanup step ahead of the SerDes PCS support, no behavior changes intended. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-4-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 40 +++++++++++++++++++++++--------- drivers/net/dsa/motorcomm/chip.h | 11 +++++---- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 54881856b796..ea4b29882b5c 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -3738,6 +3738,7 @@ yt921x_dsa_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel, static int yt921x_port_down(struct yt921x_priv *priv, int port) { + const struct yt921x_info *info = priv->info; u32 mask; int res; @@ -3746,12 +3747,13 @@ static int yt921x_port_down(struct yt921x_priv *priv, int port) if (res) return res; - if (yt921x_port_is_external(port)) { + if (BIT(port) & info->serdes_mask) { mask = YT921X_SERDES_LINK; res = yt921x_reg_clear_bits(priv, YT921X_SERDESn(port), mask); if (res) return res; - + } + if (BIT(port) & info->xmii_mask) { mask = YT921X_XMII_LINK; res = yt921x_reg_clear_bits(priv, YT921X_XMIIn(port), mask); if (res) @@ -3766,6 +3768,8 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, phy_interface_t interface, int speed, int duplex, bool tx_pause, bool rx_pause) { + const struct yt921x_info *info = priv->info; + struct yt921x_port *pp = &priv->ports[port]; u32 mask; u32 ctrl; int res; @@ -3800,7 +3804,10 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, if (res) return res; - if (yt921x_port_is_external(port)) { + if (!(BIT(port) & (info->serdes_mask | info->xmii_mask))) + return 0; + + if (pp->serdes) { mask = YT921X_SERDES_SPEED_M; switch (speed) { case SPEED_10: @@ -3836,7 +3843,7 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, mask, ctrl); if (res) return res; - + } else { mask = YT921X_XMII_LINK; res = yt921x_reg_set_bits(priv, YT921X_XMIIn(port), mask); if (res) @@ -3876,17 +3883,16 @@ static int yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, phy_interface_t interface) { + const struct yt921x_info *info = priv->info; + struct yt921x_port *pp = &priv->ports[port]; struct device *dev = to_device(priv); u32 mask; u32 ctrl; int res; - if (!yt921x_port_is_external(port)) { - if (interface != PHY_INTERFACE_MODE_INTERNAL) { - dev_err(dev, "Wrong mode %d on port %d\n", - interface, port); - return -EINVAL; - } + if (BIT(port) & info->internal_mask) { + if (interface != PHY_INTERFACE_MODE_INTERNAL) + goto err; return 0; } @@ -3896,6 +3902,9 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, case PHY_INTERFACE_MODE_100BASEX: case PHY_INTERFACE_MODE_1000BASEX: case PHY_INTERFACE_MODE_2500BASEX: + if (!(BIT(port) & info->serdes_mask)) + goto err; + mask = YT921X_SERDES_CTRL_PORTn(port); res = yt921x_reg_set_bits(priv, YT921X_SERDES_CTRL, mask); if (res) @@ -3906,6 +3915,11 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, if (res) return res; + /* The order is quite arbitrary - we can't return to a safe + * state on IO errors. + */ + pp->serdes = true; + mask = YT921X_SERDES_MODE_M; switch (interface) { case PHY_INTERFACE_MODE_SGMII: @@ -3931,10 +3945,14 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, break; /* add XMII support here */ default: - return -EINVAL; + goto err; } return 0; + +err: + dev_err(dev, "Wrong mode %d on port %d\n", interface, port); + return -EINVAL; } static void diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 83e76cefbccd..fd552f7dced4 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -858,9 +858,6 @@ enum yt921x_fdb_entry_status { #define YT921X_NAME "yt921x" -#define yt921x_port_is_internal(port) ((port) < 8) -#define yt921x_port_is_external(port) ((port) == 8 || (port) == 9) - struct yt921x_mib { u64 rx_broadcast; u64 rx_pause; @@ -936,8 +933,12 @@ struct yt921x_acl_blk { struct yt921x_port { unsigned char index; - bool hairpin; - bool isolated; + /* SerDes in use */ + bool serdes:1; + /* BR_HAIRPIN_MODE */ + bool hairpin:1; + /* BR_ISOLATED */ + bool isolated:1; struct delayed_work mib_read; struct yt921x_mib mib; From be5cdff08903f64eb95b386db17258f5c9251601 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:36 +0800 Subject: [PATCH 0783/2126] net: dsa: motorcomm: Fix register bit field names Review and fix the incorrectness in the bit field names. No functional change. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-5-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 3 ++- drivers/net/dsa/motorcomm/chip.h | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index ea4b29882b5c..f22c37e0b5bc 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -3742,7 +3742,8 @@ static int yt921x_port_down(struct yt921x_priv *priv, int port) u32 mask; int res; - mask = YT921X_PORT_LINK | YT921X_PORT_RX_MAC_EN | YT921X_PORT_TX_MAC_EN; + mask = YT921X_PORT_CTRL_LINK_AN | YT921X_PORT_RX_MAC_EN | + YT921X_PORT_TX_MAC_EN; res = yt921x_reg_clear_bits(priv, YT921X_PORTn_CTRL(port), mask); if (res) return res; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index fd552f7dced4..3fb0c6a69dd8 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -42,7 +42,7 @@ #define YT921X_PVID_SEL 0x80014 #define YT921X_PVID_SEL_SVID_PORTn(port) BIT(port) #define YT921X_SERDES_CTRL 0x80028 -#define YT921X_SERDES_CTRL_PORTn_TEST(port) BIT((port) - 3) +#define YT921X_SERDES_CTRL_TEST BIT(6) #define YT921X_SERDES_CTRL_PORTn(port) BIT((port) - 8) #define YT921X_IO_LEVEL 0x80030 #define YT9215_IO_LEVEL_NORMAL_M GENMASK(5, 4) @@ -94,11 +94,12 @@ #define YT921X_SERDES_SPEED_1000 YT921X_SERDES_SPEED(2) #define YT921X_SERDES_SPEED_10000 YT921X_SERDES_SPEED(3) #define YT921X_SERDES_SPEED_2500 YT921X_SERDES_SPEED(4) -#define YT921X_PORTn_CTRL(port) (0x80100 + 4 * (port)) +#define YT921X_PORTn_CTRL(port) (0x80100 + 4 * (port)) /* Bit 7-0 shared with PORT_STATUS */ #define YT921X_PORT_CTRL_PAUSE_AN BIT(10) +#define YT921X_PORT_CTRL_LINK_AN BIT(9) +#define YT921X_PORT_CTRL_HALF_PAUSE BIT(8) /* Half-duplex back pressure mode */ #define YT921X_PORTn_STATUS(port) (0x80200 + 4 * (port)) -#define YT921X_PORT_LINK BIT(9) /* CTRL: auto negotiation */ -#define YT921X_PORT_HALF_PAUSE BIT(8) /* Half-duplex back pressure mode */ +#define YT921X_PORT_LINK BIT(8) #define YT921X_PORT_DUPLEX_FULL BIT(7) #define YT921X_PORT_RX_PAUSE BIT(6) #define YT921X_PORT_TX_PAUSE BIT(5) From 5423f892f1294a61a6406a625338f4698c352d26 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:37 +0800 Subject: [PATCH 0784/2126] net: dsa: motorcomm: Introduce yt921x_speed FIELD_PREP values cannot be used as case labels. Introduce enum for future use. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-6-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 62 ++++---------------------------- drivers/net/dsa/motorcomm/chip.h | 43 ++++++++++++++-------- 2 files changed, 34 insertions(+), 71 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index f22c37e0b5bc..06e2c60b415f 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -3771,29 +3771,15 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, { const struct yt921x_info *info = priv->info; struct yt921x_port *pp = &priv->ports[port]; + int ps = ethtool_speed_to_yt921x(speed); u32 mask; u32 ctrl; int res; - switch (speed) { - case SPEED_10: - ctrl = YT921X_PORT_SPEED_10; - break; - case SPEED_100: - ctrl = YT921X_PORT_SPEED_100; - break; - case SPEED_1000: - ctrl = YT921X_PORT_SPEED_1000; - break; - case SPEED_2500: - ctrl = YT921X_PORT_SPEED_2500; - break; - case SPEED_10000: - ctrl = YT921X_PORT_SPEED_10000; - break; - default: + if (ps == YT921X_SPEED_INVALID) return -EINVAL; - } + + ctrl = YT921X_PORT_SPEED(ps); if (duplex == DUPLEX_FULL) ctrl |= YT921X_PORT_DUPLEX_FULL; if (tx_pause) @@ -3810,25 +3796,7 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, if (pp->serdes) { mask = YT921X_SERDES_SPEED_M; - switch (speed) { - case SPEED_10: - ctrl = YT921X_SERDES_SPEED_10; - break; - case SPEED_100: - ctrl = YT921X_SERDES_SPEED_100; - break; - case SPEED_1000: - ctrl = YT921X_SERDES_SPEED_1000; - break; - case SPEED_2500: - ctrl = YT921X_SERDES_SPEED_2500; - break; - case SPEED_10000: - ctrl = YT921X_SERDES_SPEED_10000; - break; - default: - return -EINVAL; - } + ctrl = YT921X_SERDES_SPEED(ps); mask |= YT921X_SERDES_DUPLEX_FULL; if (duplex == DUPLEX_FULL) ctrl |= YT921X_SERDES_DUPLEX_FULL; @@ -3850,25 +3818,7 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, if (res) return res; - switch (speed) { - case SPEED_10: - ctrl = YT921X_MDIO_POLLING_SPEED_10; - break; - case SPEED_100: - ctrl = YT921X_MDIO_POLLING_SPEED_100; - break; - case SPEED_1000: - ctrl = YT921X_MDIO_POLLING_SPEED_1000; - break; - case SPEED_2500: - ctrl = YT921X_MDIO_POLLING_SPEED_2500; - break; - case SPEED_10000: - ctrl = YT921X_MDIO_POLLING_SPEED_10000; - break; - default: - return -EINVAL; - } + ctrl = YT921X_MDIO_POLLING_SPEED(ps); if (duplex == DUPLEX_FULL) ctrl |= YT921X_MDIO_POLLING_DUPLEX_FULL; ctrl |= YT921X_MDIO_POLLING_LINK; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 3fb0c6a69dd8..30d131eb9844 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -89,11 +89,6 @@ #define YT921X_SERDES_DUPLEX_FULL BIT(3) #define YT921X_SERDES_SPEED_M GENMASK(2, 0) #define YT921X_SERDES_SPEED(x) FIELD_PREP(YT921X_SERDES_SPEED_M, (x)) -#define YT921X_SERDES_SPEED_10 YT921X_SERDES_SPEED(0) -#define YT921X_SERDES_SPEED_100 YT921X_SERDES_SPEED(1) -#define YT921X_SERDES_SPEED_1000 YT921X_SERDES_SPEED(2) -#define YT921X_SERDES_SPEED_10000 YT921X_SERDES_SPEED(3) -#define YT921X_SERDES_SPEED_2500 YT921X_SERDES_SPEED(4) #define YT921X_PORTn_CTRL(port) (0x80100 + 4 * (port)) /* Bit 7-0 shared with PORT_STATUS */ #define YT921X_PORT_CTRL_PAUSE_AN BIT(10) #define YT921X_PORT_CTRL_LINK_AN BIT(9) @@ -107,11 +102,6 @@ #define YT921X_PORT_TX_MAC_EN BIT(3) #define YT921X_PORT_SPEED_M GENMASK(2, 0) #define YT921X_PORT_SPEED(x) FIELD_PREP(YT921X_PORT_SPEED_M, (x)) -#define YT921X_PORT_SPEED_10 YT921X_PORT_SPEED(0) -#define YT921X_PORT_SPEED_100 YT921X_PORT_SPEED(1) -#define YT921X_PORT_SPEED_1000 YT921X_PORT_SPEED(2) -#define YT921X_PORT_SPEED_10000 YT921X_PORT_SPEED(3) -#define YT921X_PORT_SPEED_2500 YT921X_PORT_SPEED(4) #define YT921X_PON_STRAP_FUNC 0x80320 #define YT921X_PON_STRAP_VAL 0x80324 #define YT921X_PON_STRAP_CAP 0x80328 @@ -122,11 +112,16 @@ #define YT921X_MDIO_POLLING_LINK BIT(3) #define YT921X_MDIO_POLLING_SPEED_M GENMASK(2, 0) #define YT921X_MDIO_POLLING_SPEED(x) FIELD_PREP(YT921X_MDIO_POLLING_SPEED_M, (x)) -#define YT921X_MDIO_POLLING_SPEED_10 YT921X_MDIO_POLLING_SPEED(0) -#define YT921X_MDIO_POLLING_SPEED_100 YT921X_MDIO_POLLING_SPEED(1) -#define YT921X_MDIO_POLLING_SPEED_1000 YT921X_MDIO_POLLING_SPEED(2) -#define YT921X_MDIO_POLLING_SPEED_10000 YT921X_MDIO_POLLING_SPEED(3) -#define YT921X_MDIO_POLLING_SPEED_2500 YT921X_MDIO_POLLING_SPEED(4) + +enum yt921x_speed { + YT921X_SPEED_10, + YT921X_SPEED_100, + YT921X_SPEED_1000, + YT921X_SPEED_10000, + YT921X_SPEED_2500, + YT921X_SPEED_INVALID +}; + #define YT921X_SENSOR 0x8036c #define YT921X_SENSOR_TEMP BIT(18) #define YT921X_TEMP 0x80374 @@ -1004,4 +999,22 @@ struct yt921x_priv { struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM]; }; +static inline int ethtool_speed_to_yt921x(int speed) +{ + switch (speed) { + case SPEED_10: + return YT921X_SPEED_10; + case SPEED_100: + return YT921X_SPEED_100; + case SPEED_1000: + return YT921X_SPEED_1000; + case SPEED_2500: + return YT921X_SPEED_2500; + case SPEED_10000: + return YT921X_SPEED_10000; + default: + return YT921X_SPEED_INVALID; + } +} + #endif From c9996cf718ec3f880ccb32cda0510cb0d822219a Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:38 +0800 Subject: [PATCH 0785/2126] net: dsa: motorcomm: Hoist port_to_priv helper into chip.h yt921x_poll_mib() open-codes the same container_of_const() expression that leds.c defines as to_yt921x_priv(). Move the macro to chip.h as yt921x_port_to_priv() so both files use one definition. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-7-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 3 +-- drivers/net/dsa/motorcomm/chip.h | 3 +++ drivers/net/dsa/motorcomm/leds.c | 14 ++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 06e2c60b415f..ee433f1e1b58 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -598,9 +598,8 @@ static void yt921x_poll_mib(struct work_struct *work) { struct yt921x_port *pp = container_of_const(work, struct yt921x_port, mib_read.work); - struct yt921x_priv *priv = (void *)(pp - pp->index) - - offsetof(struct yt921x_priv, ports); unsigned long delay = YT921X_STATS_INTERVAL_JIFFIES; + struct yt921x_priv *priv = yt921x_port_to_priv(pp); int port = pp->index; int res; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 30d131eb9844..6a9fb27ddfb7 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -999,6 +999,9 @@ struct yt921x_priv { struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM]; }; +#define yt921x_port_to_priv(pp) \ + container_of_const((pp), struct yt921x_priv, ports[(pp)->index]) + static inline int ethtool_speed_to_yt921x(int speed) { switch (speed) { diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c index 0e8761f37995..6613fe3b0471 100644 --- a/drivers/net/dsa/motorcomm/leds.c +++ b/drivers/net/dsa/motorcomm/leds.c @@ -12,8 +12,6 @@ #define to_yt921x_led(led_cdev) \ container_of_const((led_cdev), struct yt921x_led, cdev) #define to_yt921x_port(led) ((led)->port) -#define to_yt921x_priv(pp) \ - container_of_const((pp), struct yt921x_priv, ports[(pp)->index]) #define to_device(priv) ((priv)->ds.dev) static u32 yt921x_led_regaddr(struct yt921x_priv *priv, int port, int group) @@ -321,7 +319,7 @@ yt921x_cled_brightness_set_blocking(struct led_classdev *led_cdev, { struct yt921x_led *led = to_yt921x_led(led_cdev); struct yt921x_port *pp = to_yt921x_port(led); - struct yt921x_priv *priv = to_yt921x_priv(pp); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); int res; mutex_lock(&priv->reg_lock); @@ -337,7 +335,7 @@ yt921x_cled_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on, { struct yt921x_led *led = to_yt921x_led(led_cdev); struct yt921x_port *pp = to_yt921x_port(led); - struct yt921x_priv *priv = to_yt921x_priv(pp); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); int res; mutex_lock(&priv->reg_lock); @@ -353,7 +351,7 @@ yt921x_cled_hw_control_get_device(struct led_classdev *led_cdev) { struct yt921x_led *led = to_yt921x_led(led_cdev); struct yt921x_port *pp = to_yt921x_port(led); - struct yt921x_priv *priv = to_yt921x_priv(pp); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); struct dsa_port *dp; dp = dsa_to_port(&priv->ds, pp->index); @@ -374,7 +372,7 @@ yt921x_cled_hw_control_is_supported(struct led_classdev *led_cdev, { struct yt921x_led *led = to_yt921x_led(led_cdev); struct yt921x_port *pp = to_yt921x_port(led); - struct yt921x_priv *priv = to_yt921x_priv(pp); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); if (yt921x_led_trigger_is_supported(priv, pp->index, led->group, flags)) return 0; @@ -386,7 +384,7 @@ yt921x_cled_hw_control_get(struct led_classdev *led_cdev, unsigned long *flagsp) { struct yt921x_led *led = to_yt921x_led(led_cdev); struct yt921x_port *pp = to_yt921x_port(led); - struct yt921x_priv *priv = to_yt921x_priv(pp); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); int res; mutex_lock(&priv->reg_lock); @@ -401,7 +399,7 @@ yt921x_cled_hw_control_set(struct led_classdev *led_cdev, unsigned long flags) { struct yt921x_led *led = to_yt921x_led(led_cdev); struct yt921x_port *pp = to_yt921x_port(led); - struct yt921x_priv *priv = to_yt921x_priv(pp); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); int res; mutex_lock(&priv->reg_lock); From b9eca1c2be7fe50f677d69fd8239859c13b50996 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:39 +0800 Subject: [PATCH 0786/2126] net: dsa: motorcomm: Split MDIO bus module Split it in order to be used in other modules. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-8-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 269 +------------------------- drivers/net/dsa/motorcomm/chip.h | 21 -- drivers/net/dsa/motorcomm/mdio_bus.c | 278 +++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/mdio_bus.h | 39 ++++ 5 files changed, 319 insertions(+), 289 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/mdio_bus.c create mode 100644 drivers/net/dsa/motorcomm/mdio_bus.h diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index aeb12cb91f93..f7cce7eabbb8 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -2,4 +2,5 @@ obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o +yt921x-objs += mdio_bus.o yt921x-objs += smi.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index ee433f1e1b58..6e1219ef05d7 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -27,6 +27,7 @@ #include "chip.h" #include "leds.h" +#include "mdio_bus.h" #include "smi.h" struct yt921x_mib_desc { @@ -266,274 +267,6 @@ static const struct yt921x_reg_ops yt921x_reg_ops_mdio = { /* TODO: SPI/I2C */ -static int yt921x_intif_wait(struct yt921x_priv *priv) -{ - u32 val = 0; - - return yt921x_reg_wait(priv, YT921X_INT_MBUS_OP, YT921X_MBUS_OP_START, - &val); -} - -static int -yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) -{ - struct device *dev = to_device(priv); - u32 mask; - u32 ctrl; - u32 val; - int res; - - res = yt921x_intif_wait(priv); - if (res) - return res; - - mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | - YT921X_MBUS_CTRL_OP_M; - ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | - YT921X_MBUS_CTRL_READ; - res = yt921x_reg_update_bits(priv, YT921X_INT_MBUS_CTRL, mask, ctrl); - if (res) - return res; - res = yt921x_reg_write(priv, YT921X_INT_MBUS_OP, YT921X_MBUS_OP_START); - if (res) - return res; - - res = yt921x_intif_wait(priv); - if (res) - return res; - res = yt921x_reg_read(priv, YT921X_INT_MBUS_DIN, &val); - if (res) - return res; - - if ((u16)val != val) - dev_info(dev, - "%s: port %d, reg 0x%x: Expected u16, got 0x%08x\n", - __func__, port, reg, val); - *valp = (u16)val; - return 0; -} - -static int -yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) -{ - u32 mask; - u32 ctrl; - int res; - - res = yt921x_intif_wait(priv); - if (res) - return res; - - mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | - YT921X_MBUS_CTRL_OP_M; - ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | - YT921X_MBUS_CTRL_WRITE; - res = yt921x_reg_update_bits(priv, YT921X_INT_MBUS_CTRL, mask, ctrl); - if (res) - return res; - res = yt921x_reg_write(priv, YT921X_INT_MBUS_DOUT, val); - if (res) - return res; - res = yt921x_reg_write(priv, YT921X_INT_MBUS_OP, YT921X_MBUS_OP_START); - if (res) - return res; - - return yt921x_intif_wait(priv); -} - -static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg) -{ - struct yt921x_priv *priv = mbus->priv; - u16 val; - int res; - - if (port >= YT921X_PORT_NUM) - return U16_MAX; - - mutex_lock(&priv->reg_lock); - res = yt921x_intif_read(priv, port, reg, &val); - mutex_unlock(&priv->reg_lock); - - if (res) - return res; - return val; -} - -static int -yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data) -{ - struct yt921x_priv *priv = mbus->priv; - int res; - - if (port >= YT921X_PORT_NUM) - return -ENODEV; - - mutex_lock(&priv->reg_lock); - res = yt921x_intif_write(priv, port, reg, data); - mutex_unlock(&priv->reg_lock); - - return res; -} - -static int -yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) -{ - struct device *dev = to_device(priv); - struct mii_bus *mbus; - int res; - - mbus = devm_mdiobus_alloc(dev); - if (!mbus) - return -ENOMEM; - - mbus->name = "YT921x internal MDIO bus"; - snprintf(mbus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); - mbus->priv = priv; - mbus->read = yt921x_mbus_int_read; - mbus->write = yt921x_mbus_int_write; - mbus->parent = dev; - mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0); - - res = devm_of_mdiobus_register(dev, mbus, mnp); - if (res) - return res; - - priv->mbus_int = mbus; - - return 0; -} - -static int yt921x_extif_wait(struct yt921x_priv *priv) -{ - u32 val = 0; - - return yt921x_reg_wait(priv, YT921X_EXT_MBUS_OP, YT921X_MBUS_OP_START, - &val); -} - -static int -yt921x_extif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) -{ - struct device *dev = to_device(priv); - u32 mask; - u32 ctrl; - u32 val; - int res; - - res = yt921x_extif_wait(priv); - if (res) - return res; - - mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | - YT921X_MBUS_CTRL_TYPE_M | YT921X_MBUS_CTRL_OP_M; - ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | - YT921X_MBUS_CTRL_TYPE_C22 | YT921X_MBUS_CTRL_READ; - res = yt921x_reg_update_bits(priv, YT921X_EXT_MBUS_CTRL, mask, ctrl); - if (res) - return res; - res = yt921x_reg_write(priv, YT921X_EXT_MBUS_OP, YT921X_MBUS_OP_START); - if (res) - return res; - - res = yt921x_extif_wait(priv); - if (res) - return res; - res = yt921x_reg_read(priv, YT921X_EXT_MBUS_DIN, &val); - if (res) - return res; - - if ((u16)val != val) - dev_info(dev, - "%s: port %d, reg 0x%x: Expected u16, got 0x%08x\n", - __func__, port, reg, val); - *valp = (u16)val; - return 0; -} - -static int -yt921x_extif_write(struct yt921x_priv *priv, int port, int reg, u16 val) -{ - u32 mask; - u32 ctrl; - int res; - - res = yt921x_extif_wait(priv); - if (res) - return res; - - mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | - YT921X_MBUS_CTRL_TYPE_M | YT921X_MBUS_CTRL_OP_M; - ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | - YT921X_MBUS_CTRL_TYPE_C22 | YT921X_MBUS_CTRL_WRITE; - res = yt921x_reg_update_bits(priv, YT921X_EXT_MBUS_CTRL, mask, ctrl); - if (res) - return res; - res = yt921x_reg_write(priv, YT921X_EXT_MBUS_DOUT, val); - if (res) - return res; - res = yt921x_reg_write(priv, YT921X_EXT_MBUS_OP, YT921X_MBUS_OP_START); - if (res) - return res; - - return yt921x_extif_wait(priv); -} - -static int yt921x_mbus_ext_read(struct mii_bus *mbus, int port, int reg) -{ - struct yt921x_priv *priv = mbus->priv; - u16 val; - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_extif_read(priv, port, reg, &val); - mutex_unlock(&priv->reg_lock); - - if (res) - return res; - return val; -} - -static int -yt921x_mbus_ext_write(struct mii_bus *mbus, int port, int reg, u16 data) -{ - struct yt921x_priv *priv = mbus->priv; - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_extif_write(priv, port, reg, data); - mutex_unlock(&priv->reg_lock); - - return res; -} - -static int -yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp) -{ - struct device *dev = to_device(priv); - struct mii_bus *mbus; - int res; - - mbus = devm_mdiobus_alloc(dev); - if (!mbus) - return -ENOMEM; - - mbus->name = "YT921x external MDIO bus"; - snprintf(mbus->id, MII_BUS_ID_SIZE, "%s@ext", dev_name(dev)); - mbus->priv = priv; - /* TODO: c45? */ - mbus->read = yt921x_mbus_ext_read; - mbus->write = yt921x_mbus_ext_write; - mbus->parent = dev; - - res = devm_of_mdiobus_register(dev, mbus, mnp); - if (res) - return res; - - priv->mbus_ext = mbus; - - return 0; -} - /* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */ static int yt921x_read_mib(struct yt921x_priv *priv, int port) { diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 6a9fb27ddfb7..f68b77f815b1 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -243,27 +243,6 @@ enum yt921x_speed { #define YT9218_SYS_CLK_167M 0 #define YT921X_SYS_CLK_143M 1 -#define YT921X_EXT_MBUS_OP 0x6a000 -#define YT921X_INT_MBUS_OP 0xf0000 -#define YT921X_MBUS_OP_START BIT(0) -#define YT921X_EXT_MBUS_CTRL 0x6a004 -#define YT921X_INT_MBUS_CTRL 0xf0004 -#define YT921X_MBUS_CTRL_PORT_M GENMASK(25, 21) -#define YT921X_MBUS_CTRL_PORT(x) FIELD_PREP(YT921X_MBUS_CTRL_PORT_M, (x)) -#define YT921X_MBUS_CTRL_REG_M GENMASK(20, 16) -#define YT921X_MBUS_CTRL_REG(x) FIELD_PREP(YT921X_MBUS_CTRL_REG_M, (x)) -#define YT921X_MBUS_CTRL_TYPE_M GENMASK(11, 8) /* wild guess */ -#define YT921X_MBUS_CTRL_TYPE(x) FIELD_PREP(YT921X_MBUS_CTRL_TYPE_M, (x)) -#define YT921X_MBUS_CTRL_TYPE_C22 YT921X_MBUS_CTRL_TYPE(4) -#define YT921X_MBUS_CTRL_OP_M GENMASK(3, 2) /* wild guess */ -#define YT921X_MBUS_CTRL_OP(x) FIELD_PREP(YT921X_MBUS_CTRL_OP_M, (x)) -#define YT921X_MBUS_CTRL_WRITE YT921X_MBUS_CTRL_OP(1) -#define YT921X_MBUS_CTRL_READ YT921X_MBUS_CTRL_OP(2) -#define YT921X_EXT_MBUS_DOUT 0x6a008 -#define YT921X_INT_MBUS_DOUT 0xf0008 -#define YT921X_EXT_MBUS_DIN 0x6a00c -#define YT921X_INT_MBUS_DIN 0xf000c - #define YT921X_PORTn_EGR(port) (0x100000 + 4 * (port)) #define YT921X_PORT_EGR_TPID_CTAG_M GENMASK(5, 4) #define YT921X_PORT_EGR_TPID_CTAG(x) FIELD_PREP(YT921X_PORT_EGR_TPID_CTAG_M, (x)) diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c new file mode 100644 index 000000000000..ba70343f3f33 --- /dev/null +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -0,0 +1,278 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 David Yang + */ + +#include + +#include "chip.h" +#include "mdio_bus.h" +#include "smi.h" + +#define to_device(priv) ((priv)->ds.dev) + +static int yt921x_intif_wait(struct yt921x_priv *priv) +{ + u32 val = 0; + + return yt921x_reg_wait(priv, YT921X_INT_MBUS_OP, YT921X_MBUS_OP_START, + &val); +} + +static int +yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) +{ + struct device *dev = to_device(priv); + u32 mask; + u32 ctrl; + u32 val; + int res; + + res = yt921x_intif_wait(priv); + if (res) + return res; + + mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | + YT921X_MBUS_CTRL_OP_M; + ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | + YT921X_MBUS_CTRL_READ; + res = yt921x_reg_update_bits(priv, YT921X_INT_MBUS_CTRL, mask, ctrl); + if (res) + return res; + res = yt921x_reg_write(priv, YT921X_INT_MBUS_OP, YT921X_MBUS_OP_START); + if (res) + return res; + + res = yt921x_intif_wait(priv); + if (res) + return res; + res = yt921x_reg_read(priv, YT921X_INT_MBUS_DIN, &val); + if (res) + return res; + + if ((u16)val != val) + dev_info(dev, + "%s: port %d, reg 0x%x: Expected u16, got 0x%08x\n", + __func__, port, reg, val); + *valp = (u16)val; + return 0; +} + +static int +yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) +{ + u32 mask; + u32 ctrl; + int res; + + res = yt921x_intif_wait(priv); + if (res) + return res; + + mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | + YT921X_MBUS_CTRL_OP_M; + ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | + YT921X_MBUS_CTRL_WRITE; + res = yt921x_reg_update_bits(priv, YT921X_INT_MBUS_CTRL, mask, ctrl); + if (res) + return res; + res = yt921x_reg_write(priv, YT921X_INT_MBUS_DOUT, val); + if (res) + return res; + res = yt921x_reg_write(priv, YT921X_INT_MBUS_OP, YT921X_MBUS_OP_START); + if (res) + return res; + + return yt921x_intif_wait(priv); +} + +static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg) +{ + struct yt921x_priv *priv = mbus->priv; + u16 val; + int res; + + if (port >= YT921X_PORT_NUM) + return U16_MAX; + + mutex_lock(&priv->reg_lock); + res = yt921x_intif_read(priv, port, reg, &val); + mutex_unlock(&priv->reg_lock); + + if (res) + return res; + return val; +} + +static int +yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data) +{ + struct yt921x_priv *priv = mbus->priv; + int res; + + if (port >= YT921X_PORT_NUM) + return -ENODEV; + + mutex_lock(&priv->reg_lock); + res = yt921x_intif_write(priv, port, reg, data); + mutex_unlock(&priv->reg_lock); + + return res; +} + +int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) +{ + struct device *dev = to_device(priv); + struct mii_bus *mbus; + int res; + + mbus = devm_mdiobus_alloc(dev); + if (!mbus) + return -ENOMEM; + + mbus->name = "YT921x internal MDIO bus"; + snprintf(mbus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); + mbus->priv = priv; + mbus->read = yt921x_mbus_int_read; + mbus->write = yt921x_mbus_int_write; + mbus->parent = dev; + mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0); + + res = devm_of_mdiobus_register(dev, mbus, mnp); + if (res) + return res; + + priv->mbus_int = mbus; + + return 0; +} + +static int yt921x_extif_wait(struct yt921x_priv *priv) +{ + u32 val = 0; + + return yt921x_reg_wait(priv, YT921X_EXT_MBUS_OP, YT921X_MBUS_OP_START, + &val); +} + +static int +yt921x_extif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) +{ + struct device *dev = to_device(priv); + u32 mask; + u32 ctrl; + u32 val; + int res; + + res = yt921x_extif_wait(priv); + if (res) + return res; + + mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | + YT921X_MBUS_CTRL_TYPE_M | YT921X_MBUS_CTRL_OP_M; + ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | + YT921X_MBUS_CTRL_TYPE_C22 | YT921X_MBUS_CTRL_READ; + res = yt921x_reg_update_bits(priv, YT921X_EXT_MBUS_CTRL, mask, ctrl); + if (res) + return res; + res = yt921x_reg_write(priv, YT921X_EXT_MBUS_OP, YT921X_MBUS_OP_START); + if (res) + return res; + + res = yt921x_extif_wait(priv); + if (res) + return res; + res = yt921x_reg_read(priv, YT921X_EXT_MBUS_DIN, &val); + if (res) + return res; + + if ((u16)val != val) + dev_info(dev, + "%s: port %d, reg 0x%x: Expected u16, got 0x%08x\n", + __func__, port, reg, val); + *valp = (u16)val; + return 0; +} + +static int +yt921x_extif_write(struct yt921x_priv *priv, int port, int reg, u16 val) +{ + u32 mask; + u32 ctrl; + int res; + + res = yt921x_extif_wait(priv); + if (res) + return res; + + mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M | + YT921X_MBUS_CTRL_TYPE_M | YT921X_MBUS_CTRL_OP_M; + ctrl = YT921X_MBUS_CTRL_PORT(port) | YT921X_MBUS_CTRL_REG(reg) | + YT921X_MBUS_CTRL_TYPE_C22 | YT921X_MBUS_CTRL_WRITE; + res = yt921x_reg_update_bits(priv, YT921X_EXT_MBUS_CTRL, mask, ctrl); + if (res) + return res; + res = yt921x_reg_write(priv, YT921X_EXT_MBUS_DOUT, val); + if (res) + return res; + res = yt921x_reg_write(priv, YT921X_EXT_MBUS_OP, YT921X_MBUS_OP_START); + if (res) + return res; + + return yt921x_extif_wait(priv); +} + +static int yt921x_mbus_ext_read(struct mii_bus *mbus, int port, int reg) +{ + struct yt921x_priv *priv = mbus->priv; + u16 val; + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_extif_read(priv, port, reg, &val); + mutex_unlock(&priv->reg_lock); + + if (res) + return res; + return val; +} + +static int +yt921x_mbus_ext_write(struct mii_bus *mbus, int port, int reg, u16 data) +{ + struct yt921x_priv *priv = mbus->priv; + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_extif_write(priv, port, reg, data); + mutex_unlock(&priv->reg_lock); + + return res; +} + +int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp) +{ + struct device *dev = to_device(priv); + struct mii_bus *mbus; + int res; + + mbus = devm_mdiobus_alloc(dev); + if (!mbus) + return -ENOMEM; + + mbus->name = "YT921x external MDIO bus"; + snprintf(mbus->id, MII_BUS_ID_SIZE, "%s@ext", dev_name(dev)); + mbus->priv = priv; + /* TODO: c45? */ + mbus->read = yt921x_mbus_ext_read; + mbus->write = yt921x_mbus_ext_write; + mbus->parent = dev; + + res = devm_of_mdiobus_register(dev, mbus, mnp); + if (res) + return res; + + priv->mbus_ext = mbus; + + return 0; +} diff --git a/drivers/net/dsa/motorcomm/mdio_bus.h b/drivers/net/dsa/motorcomm/mdio_bus.h new file mode 100644 index 000000000000..ae5792b8da24 --- /dev/null +++ b/drivers/net/dsa/motorcomm/mdio_bus.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2026 David Yang + */ + +#ifndef _YT_MDIO_BUS_H +#define _YT_MDIO_BUS_H + +#include +#include +#include + +#define YT921X_EXT_MBUS_OP 0x6a000 +#define YT921X_INT_MBUS_OP 0xf0000 +#define YT921X_MBUS_OP_START BIT(0) +#define YT921X_EXT_MBUS_CTRL 0x6a004 +#define YT921X_INT_MBUS_CTRL 0xf0004 +#define YT921X_MBUS_CTRL_PORT_M GENMASK(25, 21) +#define YT921X_MBUS_CTRL_PORT(x) FIELD_PREP(YT921X_MBUS_CTRL_PORT_M, (x)) +#define YT921X_MBUS_CTRL_REG_M GENMASK(20, 16) +#define YT921X_MBUS_CTRL_REG(x) FIELD_PREP(YT921X_MBUS_CTRL_REG_M, (x)) +#define YT921X_MBUS_CTRL_TYPE_M GENMASK(11, 8) /* wild guess */ +#define YT921X_MBUS_CTRL_TYPE(x) FIELD_PREP(YT921X_MBUS_CTRL_TYPE_M, (x)) +#define YT921X_MBUS_CTRL_TYPE_C22 YT921X_MBUS_CTRL_TYPE(4) +#define YT921X_MBUS_CTRL_OP_M GENMASK(3, 2) /* wild guess */ +#define YT921X_MBUS_CTRL_OP(x) FIELD_PREP(YT921X_MBUS_CTRL_OP_M, (x)) +#define YT921X_MBUS_CTRL_WRITE YT921X_MBUS_CTRL_OP(1) +#define YT921X_MBUS_CTRL_READ YT921X_MBUS_CTRL_OP(2) +#define YT921X_EXT_MBUS_DOUT 0x6a008 +#define YT921X_INT_MBUS_DOUT 0xf0008 +#define YT921X_EXT_MBUS_DIN 0x6a00c +#define YT921X_INT_MBUS_DIN 0xf000c + +struct yt921x_priv; + +int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp); +int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp); + +#endif From 4b8fbb875a5411ff81a937245af8d4361b8a7ce4 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 23 Sep 2026 10:19:40 +0800 Subject: [PATCH 0787/2126] net: dsa: motorcomm: Add SerDes PCS Support in-band negotiation of the SerDes ports. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260923021945.2203368-9-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 83 ++++++--- drivers/net/dsa/motorcomm/chip.h | 6 + drivers/net/dsa/motorcomm/mdio_bus.c | 31 +++- drivers/net/dsa/motorcomm/mdio_bus.h | 15 ++ drivers/net/dsa/motorcomm/pcs-921x.c | 247 +++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/pcs.h | 13 ++ 7 files changed, 367 insertions(+), 29 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/pcs-921x.c create mode 100644 drivers/net/dsa/motorcomm/pcs.h diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index f7cce7eabbb8..1d2c1b3064c4 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -3,4 +3,5 @@ obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += mdio_bus.o +yt921x-objs += pcs-921x.o yt921x-objs += smi.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 6e1219ef05d7..3ff2de383157 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -28,6 +28,7 @@ #include "chip.h" #include "leds.h" #include "mdio_bus.h" +#include "pcs.h" #include "smi.h" struct yt921x_mib_desc { @@ -3511,6 +3512,10 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, if (ps == YT921X_SPEED_INVALID) return -EINVAL; + mask = YT921X_PORT_SPEED_M | YT921X_PORT_TX_MAC_EN | + YT921X_PORT_RX_MAC_EN | YT921X_PORT_TX_PAUSE | + YT921X_PORT_RX_PAUSE | YT921X_PORT_DUPLEX_FULL | + YT921X_PORT_CTRL_LINK_AN; ctrl = YT921X_PORT_SPEED(ps); if (duplex == DUPLEX_FULL) ctrl |= YT921X_PORT_DUPLEX_FULL; @@ -3519,7 +3524,9 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, if (rx_pause) ctrl |= YT921X_PORT_RX_PAUSE; ctrl |= YT921X_PORT_RX_MAC_EN | YT921X_PORT_TX_MAC_EN; - res = yt921x_reg_write(priv, YT921X_PORTn_CTRL(port), ctrl); + if (pp->serdes && pp->inband) + ctrl |= YT921X_PORT_CTRL_LINK_AN; + res = yt921x_reg_update_bits(priv, YT921X_PORTn_CTRL(port), mask, ctrl); if (res) return res; @@ -3539,7 +3546,8 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode, if (rx_pause) ctrl |= YT921X_SERDES_RX_PAUSE; mask |= YT921X_SERDES_LINK; - ctrl |= YT921X_SERDES_LINK; + if (!pp->inband) + ctrl |= YT921X_SERDES_LINK; res = yt921x_reg_update_bits(priv, YT921X_SERDESn(port), mask, ctrl); if (res) @@ -3570,7 +3578,6 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, struct yt921x_port *pp = &priv->ports[port]; struct device *dev = to_device(priv); u32 mask; - u32 ctrl; int res; if (BIT(port) & info->internal_mask) { @@ -3603,28 +3610,6 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, */ pp->serdes = true; - mask = YT921X_SERDES_MODE_M; - switch (interface) { - case PHY_INTERFACE_MODE_SGMII: - ctrl = YT921X_SERDES_MODE_SGMII; - break; - case PHY_INTERFACE_MODE_100BASEX: - ctrl = YT921X_SERDES_MODE_100BASEX; - break; - case PHY_INTERFACE_MODE_1000BASEX: - ctrl = YT921X_SERDES_MODE_1000BASEX; - break; - case PHY_INTERFACE_MODE_2500BASEX: - ctrl = YT921X_SERDES_MODE_2500BASEX; - break; - default: - return -EINVAL; - } - res = yt921x_reg_update_bits(priv, YT921X_SERDESn(port), - mask, ctrl); - if (res) - return res; - break; /* add XMII support here */ default: @@ -3638,6 +3623,29 @@ err: return -EINVAL; } +static struct phylink_pcs * +yt921x_phylink_mac_select_pcs(struct phylink_config *config, + phy_interface_t interface) +{ + struct dsa_port *dp = dsa_phylink_to_port(config); + struct yt921x_priv *priv = to_yt921x_priv(dp->ds); + const struct yt921x_info *info = priv->info; + int port = dp->index; + + if (!(BIT(port) & info->serdes_mask)) + return NULL; + + switch (interface) { + case PHY_INTERFACE_MODE_SGMII: + case PHY_INTERFACE_MODE_100BASEX: + case PHY_INTERFACE_MODE_1000BASEX: + case PHY_INTERFACE_MODE_2500BASEX: + return &priv->ports[port].pcs; + default: + return NULL; + } +} + static void yt921x_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, phy_interface_t interface) @@ -4225,6 +4233,11 @@ static int yt921x_chip_setup(struct yt921x_priv *priv) if (res) return res; + res = yt921x_reg_clear_bits(priv, YT921X_SERDES_CTRL, + YT921X_SERDES_CTRL_TEST); + if (res) + return res; + return 0; } @@ -4234,6 +4247,8 @@ static int yt921x_dsa_setup(struct dsa_switch *ds) struct device *dev = to_device(priv); struct device_node *np = dev->of_node; struct device_node *child; + unsigned long mask; + int port; int res; mutex_lock(&priv->reg_lock); @@ -4267,6 +4282,23 @@ static int yt921x_dsa_setup(struct dsa_switch *ds) return -ENODEV; } + mask = priv->info->serdes_mask; + for_each_set_bit(port, &mask, YT921X_PORT_NUM) { + struct yt921x_port *pp = &priv->ports[port]; + + pp->pcs.ops = &yt921x_phylink_pcs_ops; + pp->pcs.poll = true; + + __set_bit(PHY_INTERFACE_MODE_SGMII, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_100BASEX, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, + pp->pcs.supported_interfaces); + } + mutex_lock(&priv->reg_lock); res = yt921x_chip_setup(priv); mutex_unlock(&priv->reg_lock); @@ -4284,6 +4316,7 @@ static int yt921x_dsa_setup(struct dsa_switch *ds) } static const struct phylink_mac_ops yt921x_phylink_mac_ops = { + .mac_select_pcs = yt921x_phylink_mac_select_pcs, .mac_link_down = yt921x_phylink_mac_link_down, .mac_link_up = yt921x_phylink_mac_link_up, .mac_config = yt921x_phylink_mac_config, diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index f68b77f815b1..28e4f26f9cc4 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -910,6 +910,8 @@ struct yt921x_port { /* SerDes in use */ bool serdes:1; + /* Link from in-band status (PHYLINK_PCS_NEG_INBAND) */ + bool inband:1; /* BR_HAIRPIN_MODE */ bool hairpin:1; /* BR_ISOLATED */ @@ -929,8 +931,12 @@ struct yt921x_port { struct yt921x_led *leds[YT921X_LED_GROUP_NUM]; #endif + + struct phylink_pcs pcs; }; +#define pcs_to_yt921x_port(_pcs) container_of((_pcs), struct yt921x_port, pcs) + struct yt921x_reg_ops { int (*read)(void *context, u32 reg, u32 *valp); int (*write)(void *context, u32 reg, u32 val); diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c index ba70343f3f33..1a3f3cc68275 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.c +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -19,8 +19,7 @@ static int yt921x_intif_wait(struct yt921x_priv *priv) &val); } -static int -yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) +int yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) { struct device *dev = to_device(priv); u32 mask; @@ -58,8 +57,7 @@ yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) return 0; } -static int -yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) +int yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) { u32 mask; u32 ctrl; @@ -86,6 +84,31 @@ yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val) return yt921x_intif_wait(priv); } +int +yt921x_intif_modify_changed(struct yt921x_priv *priv, int port, int reg, + u16 mask, u16 val) +{ + int res; + u16 v; + u16 u; + + res = yt921x_intif_read(priv, port, reg, &v); + if (res) + return res; + + u = v; + u &= ~mask; + u |= val; + if (u == v) + return 0; + + res = yt921x_intif_write(priv, port, reg, u); + if (res) + return res; + + return 1; +} + static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg) { struct yt921x_priv *priv = mbus->priv; diff --git a/drivers/net/dsa/motorcomm/mdio_bus.h b/drivers/net/dsa/motorcomm/mdio_bus.h index ae5792b8da24..e79b725d435b 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.h +++ b/drivers/net/dsa/motorcomm/mdio_bus.h @@ -33,6 +33,21 @@ struct yt921x_priv; +int yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp); +int yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val); +int yt921x_intif_modify_changed(struct yt921x_priv *priv, int port, int reg, + u16 mask, u16 val); + +static inline int +yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask, + u16 val) +{ + int res; + + res = yt921x_intif_modify_changed(priv, port, reg, mask, val); + return res >= 0 ? 0 : res; +} + int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp); int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp); diff --git a/drivers/net/dsa/motorcomm/pcs-921x.c b/drivers/net/dsa/motorcomm/pcs-921x.c new file mode 100644 index 000000000000..47467d803e13 --- /dev/null +++ b/drivers/net/dsa/motorcomm/pcs-921x.c @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 David Yang + */ + +#include "chip.h" +#include "mdio_bus.h" +#include "pcs.h" +#include "smi.h" + +#define to_device(priv) ((priv)->ds.dev) + +static int +yt921x_serdes_config(struct yt921x_priv *priv, int port, unsigned int neg_mode, + phy_interface_t interface, + const unsigned long *advertising, bool permit_pause_to_mac) +{ + bool inband = neg_mode & PHYLINK_PCS_NEG_INBAND; + struct yt921x_port *pp = &priv->ports[port]; + bool changed = false; + u16 bmcr; + u32 mask; + u32 ctrl; + u16 val; + int adv; + int res; + + switch (interface) { + case PHY_INTERFACE_MODE_SGMII: + ctrl = YT921X_SERDES_MODE_SGMII; + break; + case PHY_INTERFACE_MODE_100BASEX: + ctrl = YT921X_SERDES_MODE_100BASEX; + break; + case PHY_INTERFACE_MODE_1000BASEX: + ctrl = YT921X_SERDES_MODE_1000BASEX; + break; + case PHY_INTERFACE_MODE_2500BASEX: + ctrl = YT921X_SERDES_MODE_2500BASEX; + break; + default: + return -EOPNOTSUPP; + } + + res = yt921x_reg_update_bits(priv, YT921X_SERDESn(port), + YT921X_SERDES_MODE_M, ctrl); + if (res) + return res; + + mask = YT921X_PORT_CTRL_LINK_AN | YT921X_PORT_CTRL_PAUSE_AN; + ctrl = 0; + if (inband) + ctrl |= YT921X_PORT_CTRL_LINK_AN; + if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED && permit_pause_to_mac && + interface != PHY_INTERFACE_MODE_SGMII) + ctrl |= YT921X_PORT_CTRL_PAUSE_AN; + res = yt921x_reg_update_bits(priv, YT921X_PORTn_CTRL(port), mask, ctrl); + if (res) + return res; + + if (inband) { + res = yt921x_reg_clear_bits(priv, YT921X_SERDESn(port), + YT921X_SERDES_LINK); + if (res) + return res; + } + + adv = phylink_mii_c22_pcs_encode_advertisement(interface, advertising); + if (adv >= 0) { + res = yt921x_intif_modify_changed(priv, port, MII_ADVERTISE, + U16_MAX, adv); + if (res < 0) + return res; + + changed = !!res; + } + + res = yt921x_intif_read(priv, port, MII_BMCR, &val); + if (res) + return res; + + bmcr = val; + if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) + bmcr |= BMCR_ANENABLE; + else + bmcr &= ~BMCR_ANENABLE; + + /* If the ANENABLE bit was changed, the PHY will restart negotiation, + * so we don't need to flag a change to trigger its own restart. + */ + if (bmcr != val) + changed = false; + + bmcr &= ~BMCR_ISOLATE; + res = yt921x_intif_write(priv, port, MII_BMCR, bmcr); + if (res) + return res; + + pp->inband = inband; + return changed; +} + +static unsigned int +yt921x_phylink_pcs_inband_caps(struct phylink_pcs *pcs, + phy_interface_t interface) +{ + if (interface == PHY_INTERFACE_MODE_100BASEX) + return LINK_INBAND_DISABLE; + + return LINK_INBAND_DISABLE | LINK_INBAND_ENABLE; +} + +static void +yt921x_phylink_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, + struct phylink_link_state *state) +{ + struct yt921x_port *pp = pcs_to_yt921x_port(pcs); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + struct device *dev = to_device(priv); + int port = pp->index; + u16 bmsr; + u16 lpa; + int res; + + mutex_lock(&priv->reg_lock); + + res = yt921x_intif_read(priv, port, MII_BMSR, &bmsr); + if (res) + goto end; + + res = yt921x_intif_read(priv, port, MII_LPA, &lpa); + +end: + mutex_unlock(&priv->reg_lock); + + if (res) { + dev_err_ratelimited(dev, "Failed to %s PCS port %d: %i\n", + "get state of", port, res); + state->link = false; + return; + } + + if (state->interface == PHY_INTERFACE_MODE_100BASEX) { + state->speed = SPEED_100; + state->duplex = DUPLEX_FULL; + state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX; + state->link = !!(bmsr & BMSR_LSTATUS); + return; + } + + phylink_mii_c22_pcs_decode_state(state, neg_mode, bmsr, lpa); +} + +static void yt921x_phylink_pcs_an_restart(struct phylink_pcs *pcs) +{ + struct yt921x_port *pp = pcs_to_yt921x_port(pcs); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + struct device *dev = to_device(priv); + int port = pp->index; + u16 val; + int res; + + mutex_lock(&priv->reg_lock); + + res = yt921x_intif_read(priv, port, MII_BMCR, &val); + if (res) + goto end; + + val |= BMCR_ANRESTART; + res = yt921x_intif_write(priv, port, MII_BMCR, val); + +end: + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dev, "Failed to %s PCS port %d: %i\n", "restart", + port, res); +} + +static void yt921x_phylink_pcs_disable(struct phylink_pcs *pcs) +{ + struct yt921x_port *pp = pcs_to_yt921x_port(pcs); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + struct device *dev = to_device(priv); + int port = pp->index; + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_intif_modify(priv, port, MII_BMCR, BMCR_PDOWN, BMCR_PDOWN); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dev, "Failed to %s PCS port %d: %i\n", "power down", + port, res); +} + +static int yt921x_phylink_pcs_enable(struct phylink_pcs *pcs) +{ + struct yt921x_port *pp = pcs_to_yt921x_port(pcs); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + int port = pp->index; + u16 val; + int res; + + mutex_lock(&priv->reg_lock); + + res = yt921x_intif_read(priv, port, MII_BMCR, &val); + if (res) + goto end; + + val &= ~BMCR_PDOWN; + val |= BMCR_ANRESTART; + res = yt921x_intif_write(priv, port, MII_BMCR, val); + +end: + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int +yt921x_phylink_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, + phy_interface_t interface, + const unsigned long *advertising, + bool permit_pause_to_mac) +{ + struct yt921x_port *pp = pcs_to_yt921x_port(pcs); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + int port = pp->index; + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_serdes_config(priv, port, neg_mode, interface, + advertising, permit_pause_to_mac); + mutex_unlock(&priv->reg_lock); + + return res; +} + +const struct phylink_pcs_ops yt921x_phylink_pcs_ops = { + .pcs_inband_caps = yt921x_phylink_pcs_inband_caps, + .pcs_get_state = yt921x_phylink_pcs_get_state, + .pcs_an_restart = yt921x_phylink_pcs_an_restart, + .pcs_disable = yt921x_phylink_pcs_disable, + .pcs_enable = yt921x_phylink_pcs_enable, + .pcs_config = yt921x_phylink_pcs_config, +}; diff --git a/drivers/net/dsa/motorcomm/pcs.h b/drivers/net/dsa/motorcomm/pcs.h new file mode 100644 index 000000000000..42426558086a --- /dev/null +++ b/drivers/net/dsa/motorcomm/pcs.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2026 David Yang + */ + +#ifndef _YT_PCS_H +#define _YT_PCS_H + +#include + +extern const struct phylink_pcs_ops yt921x_phylink_pcs_ops; + +#endif From e0edf25f141a7acc03748902bcb43974bd885353 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Thu, 24 Sep 2026 08:18:41 -0400 Subject: [PATCH 0788/2126] net/sched: cls_flower: exact-match ERSPAN key when no mask supplied Commit 292207809486 ("net: sched: fix erspan_opt settings in cls_flower") removed the unconditional memset of the erspan_metadata mask in fl_set_erspan_opt(). On the mask-parse pass, when userspace supplies the encap option key but no mask (TCA_FLOWER_KEY_ENC_OPTS without TCA_FLOWER_KEY_ENC_OPTS_MASK), the !depth early return leaves the mask zeroed -- a wildcard. A filter keyed on an ERSPAN index (v1), or dir/hwid (v2), then matches every ERSPAN packet's values instead of exact-matching. Default the match fields on the no-mask path the same way the with-mask branches default them: v1 index to 0xff, v2 dir and hwid to their exact-match masks. The union cannot just be memset to 0xff -- that would re-mask the overlapping timestamp/sgt bytes of the v2 header that the commit deliberately left to 0. A mask and a key that declare different ERSPAN versions describe different union layouts, so the mask would silently wildcard the key's matched fields. Reject that combination. Have fl_set_erspan_opt() report the parsed key's version back through a u8 pointer so the mask pass uses it without re-reading the union. This is a follow-up to commit fee10655709c ("net/sched: cls_flower: validate mask pointer after nla_next()"). Conditions to recreate the bug: add an ERSPAN encap-opts flower filter with a key but no mask (raw netlink, TCA_FLOWER_KEY_ENC_OPTS present, TCA_FLOWER_KEY_ENC_OPTS_MASK absent); dump the filter and observe the match mask is zero (wildcard) instead of exact for the supplied fields. For the mismatch case, pair a v1 key with a v2 mask (or vice versa) and observe the request is accepted with a mask of the other version. Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260826025123.62758-1-ljp1205831794@gmail.com Link: https://lore.kernel.org/netdev/20260826025123.62758-1-ljp1205831794@gmail.com/ Reported-by: Sashiko (nipa) Link: https://lore.kernel.org/netdev/179003833955.2160803.1077681716391858800@kernel.org/ Suggested-by: Xin Long Signed-off-by: Jamal Hadi Salim Reviewed-by: Simon Horman Reviewed-by: Xin Long Link: https://patch.msgid.link/QDISC-4CSL.v2.20260924114800@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/cls_flower.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 1cefea571efd..0c4beff18d68 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1358,17 +1358,29 @@ static int fl_set_vxlan_opt(const struct nlattr *nla, struct fl_flow_key *key, static int fl_set_erspan_opt(const struct nlattr *nla, struct fl_flow_key *key, int depth, int option_len, - struct netlink_ext_ack *extack) + struct netlink_ext_ack *extack, u8 *key_ver) { struct nlattr *tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX + 1]; struct erspan_metadata *md; int err; md = (struct erspan_metadata *)&key->enc_opts.data[key->enc_opts.len]; - md->version = 1; - if (!depth) + if (!depth) { + /* No mask attribute supplied: exact-match every field the + * key set, keyed off the key's own version so the v2 dir/hwid + * bytes are masked without touching the overlapping + * timestamp/sgt bytes of the union (see 292207809486). + */ + md->version = *key_ver; + if (md->version == 1) { + memset(&md->u.index, 0xff, sizeof(md->u.index)); + } else if (md->version == 2) { + md->u.md2.dir = 1; + set_hwid(&md->u.md2, 0xff); + } return sizeof(*md); + } if (nla_type(nla) != TCA_FLOWER_KEY_ENC_OPTS_ERSPAN) { NL_SET_ERR_MSG(extack, "Non-erspan option type for mask"); @@ -1387,6 +1399,22 @@ static int fl_set_erspan_opt(const struct nlattr *nla, struct fl_flow_key *key, if (tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER]) md->version = nla_get_u8(tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER]); + else + md->version = 1; + + /* The key and mask must describe the same union layout: the + * per-version default below only exact-matches the fields of its own + * version, so a mask version that differs from the key's would + * silently wildcard the key's matched fields. A mask without a + * version keeps the historical v1 default. + */ + if (option_len && md->version != *key_ver) { + NL_SET_ERR_MSG(extack, "Tunnel key erspan option ver mismatch"); + return -EINVAL; + } + + if (!option_len) + *key_ver = md->version; if (md->version == 1) { if (!option_len && !tb[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX]) { @@ -1509,6 +1537,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key, { const struct nlattr *nla_enc_key, *nla_opt_key, *nla_opt_msk = NULL; int err, option_len, key_depth, msk_depth = 0; + u8 key_ver = 1; err = nla_validate_nested_deprecated(tb[TCA_FLOWER_KEY_ENC_OPTS], TCA_FLOWER_KEY_ENC_OPTS_MAX, @@ -1607,7 +1636,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key, key->enc_opts.dst_opt_type = IP_TUNNEL_ERSPAN_OPT_BIT; option_len = fl_set_erspan_opt(nla_opt_key, key, key_depth, option_len, - extack); + extack, &key_ver); if (option_len < 0) return option_len; @@ -1618,7 +1647,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key, mask->enc_opts.dst_opt_type = IP_TUNNEL_ERSPAN_OPT_BIT; option_len = fl_set_erspan_opt(nla_opt_msk, mask, msk_depth, option_len, - extack); + extack, &key_ver); if (option_len < 0) return option_len; From 0fd5dfa99cfc7555fe7eb034136e0bad12c5e2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 24 Sep 2026 13:50:55 +0200 Subject: [PATCH 0789/2126] net: sfp: ignore LOS also on Hisense GPON modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to commit 87d126852158467a ("net: sfp: improve Huawei MA5671a fixup"), in order to be able to communicate with the module for configuration even if the fiber is not connected, apply also the sfp_fixup_ignore_los() fixup to the following SFP modules: Hisense-Leox LXT-010S-H Hisense ZNID-GPON-2311NA HSGQ HSGQ-XPON-Stick Note: tested only on the Hisense-Leox LXT-010S-H module, but applying to all three modules, since they were all added in the same commit 95aca8602ef70ffd ("net: sfp: add quirks for Hisense and HSGQ GPON ONT SFP modules"), which says they are all based on the same chipset Realtek RTL960x. Signed-off-by: Marek Behún Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260924115055.196631-1-kabel@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/phy/sfp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 6bbb02117217..96361584791b 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -594,17 +594,17 @@ static const struct sfp_quirk sfp_quirks[] = { // can operate at 2500base-X, but reports 1000BASE-LX / 1300MBd in its // EEPROM SFP_QUIRK("Hisense-Leox", "LXT-010S-H", sfp_quirk_2500basex, - sfp_fixup_ignore_tx_fault), + sfp_fixup_ignore_tx_fault_and_los), // Hisense ZNID-GPON-2311NA can operate at 2500base-X, but reports // 1000BASE-LX / 1300MBd in its EEPROM SFP_QUIRK("Hisense", "ZNID-GPON-2311NA", sfp_quirk_2500basex, - sfp_fixup_ignore_tx_fault), + sfp_fixup_ignore_tx_fault_and_los), // HSGQ HSGQ-XPON-Stick can operate at 2500base-X, but reports // 1000BASE-LX / 1300MBd in its EEPROM SFP_QUIRK("HSGQ", "HSGQ-XPON-Stick", sfp_quirk_2500basex, - sfp_fixup_ignore_tx_fault), + sfp_fixup_ignore_tx_fault_and_los), // Lantech 8330-262D-E and 8330-265D can operate at 2500base-X, but // incorrectly report 2500MBd NRZ in their EEPROM. From a0dfaa3ecdce8119514806ead63f2eedc778421a Mon Sep 17 00:00:00 2001 From: Patryk Biel Date: Wed, 23 Sep 2026 18:14:12 +0200 Subject: [PATCH 0790/2126] net: pcs: lynx: enable autonegotiation for 10g-qxgmii and usxgmii The Lynx PCS setup for 10g-qxgmii and usxgmii programs the USXGMII replicator advertisement, but does not explicitly enable and restart in-band autonegotiation or program the replicator link timers. This leaves the PCS dependent on firmware or bootloader state. Systems which do not get the USXGMII replicator preconfigured before Linux may therefore fail to negotiate the link correctly. After programming the USXGMII device ability, configure the replicator BMCR with reset, autonegotiation enable and autonegotiation restart. Also program the replicator link timer registers using the value returned by phylink_get_link_timer_ns(). Co-developed-by: Vladimir Oltean Signed-off-by: Vladimir Oltean Signed-off-by: Patryk Biel Reviewed-by: Vladimir Oltean Link: https://patch.msgid.link/20260923-b4-fix-pcs-lynx-an-v4-1-3f7927606d12@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/pcs/pcs-lynx.c | 53 +++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/drivers/net/pcs/pcs-lynx.c b/drivers/net/pcs/pcs-lynx.c index da4f99059eef..6d94f92a3332 100644 --- a/drivers/net/pcs/pcs-lynx.c +++ b/drivers/net/pcs/pcs-lynx.c @@ -20,6 +20,12 @@ #define IF_MODE_SPEED_MSK GENMASK(3, 2) #define IF_MODE_HALF_DUPLEX BIT(4) +/* USXGMII replicator link timer step is 3.2 ns (312.5M XGMII columns per sec) + * for single port mode. For quad port mode, it is 1/4 of that. + */ +#define LINK_TIMER_VAL_USXGMII(ns) ((u32)((ns) * 10 / 32)) +#define LINK_TIMER_VAL_10G_QXGMII(ns) ((u32)((ns) * 10 / 128)) + struct lynx_pcs { struct phylink_pcs pcs; struct mdio_device *mdio; @@ -158,6 +164,9 @@ static int lynx_pcs_config_usxgmii(struct mdio_device *pcs, { struct mii_bus *bus = pcs->bus; int addr = pcs->addr; + int link_timer_ns; + u32 link_timer; + int ret; if (neg_mode != PHYLINK_PCS_NEG_INBAND_ENABLED) { dev_err(&pcs->dev, "%s only supports in-band AN for now\n", @@ -166,10 +175,46 @@ static int lynx_pcs_config_usxgmii(struct mdio_device *pcs, } /* Configure device ability for the USXGMII Replicator */ - return mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, MII_ADVERTISE, - MDIO_USXGMII_10G | MDIO_USXGMII_LINK | - MDIO_USXGMII_FULL_DUPLEX | - ADVERTISE_SGMII | ADVERTISE_LPACK); + ret = mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, MII_ADVERTISE, + MDIO_USXGMII_10G | MDIO_USXGMII_LINK | + MDIO_USXGMII_FULL_DUPLEX | + ADVERTISE_SGMII | ADVERTISE_LPACK); + if (ret < 0) { + dev_err(&pcs->dev, "could not set USXGMII replicator config\n"); + return ret; + } + + link_timer_ns = phylink_get_link_timer_ns(interface); + if (link_timer_ns > 0) { + if (interface == PHY_INTERFACE_MODE_10G_QXGMII) + link_timer = LINK_TIMER_VAL_10G_QXGMII(link_timer_ns); + else + link_timer = LINK_TIMER_VAL_USXGMII(link_timer_ns); + + ret = mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, + LINK_TIMER_LO, link_timer & 0xffff); + if (ret < 0) { + dev_err(&pcs->dev, "could not set USXGMII Link Timer 1\n"); + return ret; + } + + ret = mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, + LINK_TIMER_HI, (link_timer >> 16) & 0x1f); + if (ret < 0) { + dev_err(&pcs->dev, "could not set USXGMII Link Timer 2\n"); + return ret; + } + } + + /* Configure autonegotiation */ + ret = mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, MII_BMCR, + BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART); + if (ret < 0) { + dev_err(&pcs->dev, "could not set USXGMII replicator control config\n"); + return ret; + } + + return ret; } static int lynx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, From 52c895f638fedaa91cce71224a7810ce889517f0 Mon Sep 17 00:00:00 2001 From: Sergey Shtylyov Date: Wed, 23 Sep 2026 23:14:38 +0300 Subject: [PATCH 0791/2126] ch9200: return error on failed register writes in ch9200_bind() The successful register writes, done via the USB control requests in control_write(), seem vital for the normal functioning of the device, however the driver's bind() method ignores error codes returned from control_write(). Do bail out of ch9200_bind() on failed writes... Signed-off-by: Sergey Shtylyov Link: https://patch.msgid.link/20260923201440.36966-2-s.shtylyov@auroraos.dev Signed-off-by: Jakub Kicinski --- drivers/net/usb/ch9200.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c index a206ffa76f1b..ab3cd3902ed7 100644 --- a/drivers/net/usb/ch9200.c +++ b/drivers/net/usb/ch9200.c @@ -360,32 +360,44 @@ static int ch9200_bind(struct usbnet *dev, struct usb_interface *intf) data[1] = 0x0F; retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_THRESHOLD, data, 0x02, CONTROL_TIMEOUT_MS); + if (retval < 0) + return retval; data[0] = 0xA0; data[1] = 0x90; retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_FIFO_DEPTH, data, 0x02, CONTROL_TIMEOUT_MS); + if (retval < 0) + return retval; data[0] = 0x30; data[1] = 0x00; retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_PAUSE, data, 0x02, CONTROL_TIMEOUT_MS); + if (retval < 0) + return retval; data[0] = 0x17; data[1] = 0xD8; retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_FLOW_CONTROL, data, 0x02, CONTROL_TIMEOUT_MS); + if (retval < 0) + return retval; /* Undocumented register */ data[0] = 0x01; data[1] = 0x00; retval = control_write(dev, REQUEST_WRITE, 0, 254, data, 0x02, CONTROL_TIMEOUT_MS); + if (retval < 0) + return retval; data[0] = 0x5F; data[1] = 0x0D; retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_CTRL, data, 0x02, CONTROL_TIMEOUT_MS); + if (retval < 0) + return retval; retval = get_mac_address(dev, addr); eth_hw_addr_set(dev->net, addr); From 7bfc50171800304c6e68968ff252889cde791f26 Mon Sep 17 00:00:00 2001 From: Sergey Shtylyov Date: Wed, 23 Sep 2026 23:14:39 +0300 Subject: [PATCH 0792/2126] ch9200: do return USB errors from control_write() Compared with control_read(), control_write() looks really strange: it ignores any errors returned by usb_control_msg(), always returning 0 instead, despite overriding a positive result of usb_control_msg() (indicating short transfer) to -EINVAL before doing that. Drop that dubious *return* and propagate USB errors to the callers... Signed-off-by: Sergey Shtylyov Link: https://patch.msgid.link/20260923201440.36966-3-s.shtylyov@auroraos.dev Signed-off-by: Jakub Kicinski --- drivers/net/usb/ch9200.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c index ab3cd3902ed7..5cd825f26420 100644 --- a/drivers/net/usb/ch9200.c +++ b/drivers/net/usb/ch9200.c @@ -168,8 +168,6 @@ static int control_write(struct usbnet *dev, unsigned char request, err = -EINVAL; kfree(buf); - return 0; - err_out: return err; } From 381cb968fa89bccbb20c324f0793eeced9fdbad4 Mon Sep 17 00:00:00 2001 From: Kim Wooseok <5mghybrid@khu.ac.kr> Date: Wed, 23 Sep 2026 18:13:25 +0900 Subject: [PATCH 0793/2126] net: macb: Preserve timestamp settings on rejected requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gem_set_hwtst() can reject a request after changing the TX one-step setting, because it programs the TX mode before checking the RX filter. The call returns -ERANGE, but the hardware may no longer match the cached configuration. Validate both settings first and keep the adjusted RX filter local until validation succeeds. Then apply the register settings and update the configuration. A rejected request now leaves the hardware, the caller's settings and the cached configuration unchanged. Protect the NCR read-modify-write with bp->lock, keeping the descriptor writes and cache update in the same section. With the register writes now in the setter, remove gem_ptp_set_one_step_sync() and gem_ptp_set_ts_mode(). Reviewed-by: Nicolai Buchwitz Reviewed-by: Théo Lebrun Tested-by: Nicolai Buchwitz Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Link: https://patch.msgid.link/20260923-macb-hwtstamp-rework-v2-1-75c909b2676d@khu.ac.kr Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_ptp.c | 59 +++++++++++-------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index 14ae57fa00cb..02face93a53a 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -374,16 +374,6 @@ void gem_ptp_remove(struct net_device *netdev) GEM_PTP_TIMER_NAME); } -static int gem_ptp_set_ts_mode(struct macb *bp, - enum macb_bd_control tx_bd_control, - enum macb_bd_control rx_bd_control) -{ - gem_writel(bp, TXBDCTRL, GEM_BF(TXTSMODE, tx_bd_control)); - gem_writel(bp, RXBDCTRL, GEM_BF(RXTSMODE, rx_bd_control)); - - return 0; -} - int gem_get_hwtst(struct net_device *netdev, struct kernel_hwtstamp_config *tstamp_config) { @@ -396,25 +386,17 @@ int gem_get_hwtst(struct net_device *netdev, return 0; } -static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable) -{ - u32 reg_val; - - reg_val = macb_readl(bp, NCR); - - if (enable) - macb_writel(bp, NCR, reg_val | MACB_BIT(OSSMODE)); - else - macb_writel(bp, NCR, reg_val & ~MACB_BIT(OSSMODE)); -} - int gem_set_hwtst(struct net_device *netdev, struct kernel_hwtstamp_config *tstamp_config, struct netlink_ext_ack *extack) { enum macb_bd_control tx_bd_control = TSTAMP_DISABLED; enum macb_bd_control rx_bd_control = TSTAMP_DISABLED; + int rx_filter = tstamp_config->rx_filter; struct macb *bp = netdev_priv(netdev); + unsigned long flags; + u32 ncr_mask = 0; + u32 ncr_bits = 0; u32 regval; if (!macb_dma_ptp(bp)) @@ -424,18 +406,19 @@ int gem_set_hwtst(struct net_device *netdev, case HWTSTAMP_TX_OFF: break; case HWTSTAMP_TX_ONESTEP_SYNC: - gem_ptp_set_one_step_sync(bp, 1); + ncr_bits |= MACB_BIT(OSSMODE); + ncr_mask |= MACB_BIT(OSSMODE); tx_bd_control = TSTAMP_ALL_FRAMES; break; case HWTSTAMP_TX_ON: - gem_ptp_set_one_step_sync(bp, 0); + ncr_mask |= MACB_BIT(OSSMODE); tx_bd_control = TSTAMP_ALL_FRAMES; break; default: return -ERANGE; } - switch (tstamp_config->rx_filter) { + switch (rx_filter) { case HWTSTAMP_FILTER_NONE: break; case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: @@ -451,25 +434,33 @@ int gem_set_hwtst(struct net_device *netdev, case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: - rx_bd_control = TSTAMP_ALL_PTP_FRAMES; - tstamp_config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; - regval = macb_readl(bp, NCR); - macb_writel(bp, NCR, (regval | MACB_BIT(SRTSM))); + rx_bd_control = TSTAMP_ALL_PTP_FRAMES; + rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; + ncr_mask |= MACB_BIT(SRTSM); + ncr_bits |= MACB_BIT(SRTSM); break; case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: case HWTSTAMP_FILTER_ALL: rx_bd_control = TSTAMP_ALL_FRAMES; - tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; + rx_filter = HWTSTAMP_FILTER_ALL; break; default: - tstamp_config->rx_filter = HWTSTAMP_FILTER_NONE; return -ERANGE; } - bp->tstamp_config = *tstamp_config; + spin_lock_irqsave(&bp->lock, flags); + if (ncr_mask) { + regval = macb_readl(bp, NCR); + regval = (regval & ~ncr_mask) | ncr_bits; + macb_writel(bp, NCR, regval); + } - if (gem_ptp_set_ts_mode(bp, tx_bd_control, rx_bd_control) != 0) - return -ERANGE; + gem_writel(bp, TXBDCTRL, GEM_BF(TXTSMODE, tx_bd_control)); + gem_writel(bp, RXBDCTRL, GEM_BF(RXTSMODE, rx_bd_control)); + + tstamp_config->rx_filter = rx_filter; + bp->tstamp_config = *tstamp_config; + spin_unlock_irqrestore(&bp->lock, flags); return 0; } From 059a5a238c22c11e29e55fe6908e4b73cb763ad5 Mon Sep 17 00:00:00 2001 From: Kim Wooseok <5mghybrid@khu.ac.kr> Date: Wed, 23 Sep 2026 18:13:26 +0900 Subject: [PATCH 0794/2126] net: macb: Enable RX timestamping for specific PTPv1 filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selecting a PTPv1 Sync or Delay_Req filter in gem_set_hwtst() returns success, but leaves rx_bd_control at its initial value of TSTAMP_DISABLED. The requested filter therefore appears to have been applied, even though received packets have no hardware timestamps. The PTPv1 event case already enables timestamping for all frames, so use that path for Sync and Delay_Req as well. This enables timestamping for both requests and returns HWTSTAMP_FILTER_ALL to tell the caller which filter was actually applied. Reviewed-by: Nicolai Buchwitz Reviewed-by: Théo Lebrun Tested-by: Nicolai Buchwitz Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Link: https://patch.msgid.link/20260923-macb-hwtstamp-rework-v2-2-75c909b2676d@khu.ac.kr Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_ptp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index 02face93a53a..af2e36f81096 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -421,10 +421,6 @@ int gem_set_hwtst(struct net_device *netdev, switch (rx_filter) { case HWTSTAMP_FILTER_NONE: break; - case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: - break; - case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: - break; case HWTSTAMP_FILTER_PTP_V2_EVENT: case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: @@ -439,6 +435,8 @@ int gem_set_hwtst(struct net_device *netdev, ncr_mask |= MACB_BIT(SRTSM); ncr_bits |= MACB_BIT(SRTSM); break; + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: case HWTSTAMP_FILTER_ALL: rx_bd_control = TSTAMP_ALL_FRAMES; From 7ca3702d40d9ba2de7876abc03b116ca0e9f5264 Mon Sep 17 00:00:00 2001 From: Kim Wooseok <5mghybrid@khu.ac.kr> Date: Wed, 23 Sep 2026 18:13:27 +0900 Subject: [PATCH 0795/2126] net: macb: Clear SRTSM outside PTPv2 receive filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A PTPv2 receive filter sets NCR.SRTSM, but switching to NONE, ALL or a PTPv1 filter leaves it set. As a result, selecting the same filter can produce a different register setting depending on whether PTPv2 was used before. Update SRTSM whenever the RX filter changes, setting it only for PTPv2. Switching away from PTPv2 then clears the old setting, so the bit follows the currently selected filter. Reviewed-by: Nicolai Buchwitz Reviewed-by: Théo Lebrun Tested-by: Nicolai Buchwitz Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Link: https://patch.msgid.link/20260923-macb-hwtstamp-rework-v2-3-75c909b2676d@khu.ac.kr Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_ptp.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index af2e36f81096..2fd063394698 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -394,8 +394,8 @@ int gem_set_hwtst(struct net_device *netdev, enum macb_bd_control rx_bd_control = TSTAMP_DISABLED; int rx_filter = tstamp_config->rx_filter; struct macb *bp = netdev_priv(netdev); + u32 ncr_mask = MACB_BIT(SRTSM); unsigned long flags; - u32 ncr_mask = 0; u32 ncr_bits = 0; u32 regval; @@ -432,7 +432,6 @@ int gem_set_hwtst(struct net_device *netdev, case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: rx_bd_control = TSTAMP_ALL_PTP_FRAMES; rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; - ncr_mask |= MACB_BIT(SRTSM); ncr_bits |= MACB_BIT(SRTSM); break; case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: @@ -447,11 +446,9 @@ int gem_set_hwtst(struct net_device *netdev, } spin_lock_irqsave(&bp->lock, flags); - if (ncr_mask) { - regval = macb_readl(bp, NCR); - regval = (regval & ~ncr_mask) | ncr_bits; - macb_writel(bp, NCR, regval); - } + regval = macb_readl(bp, NCR); + regval = (regval & ~ncr_mask) | ncr_bits; + macb_writel(bp, NCR, regval); gem_writel(bp, TXBDCTRL, GEM_BF(TXTSMODE, tx_bd_control)); gem_writel(bp, RXBDCTRL, GEM_BF(RXTSMODE, rx_bd_control)); From 5ccac2330debbd96bf6b886cae93bbb8207e4735 Mon Sep 17 00:00:00 2001 From: Sunny Tiwari Date: Thu, 24 Sep 2026 06:26:11 +0000 Subject: [PATCH 0796/2126] net/rds: replace tasklets with workqueue Convert the deprecated send and receive completion tasklets in net/rds/ib to BH work items queued on system_bh_wq. In rds_ib_conn_path_shutdown(), replace tasklet_kill() with disable_work_sync(), and call enable_work() after destroying the CQs so the work items can be used again when the connection reconnects. Signed-off-by: Sunny Tiwari Reviewed-by: Allison Henderson Link: https://patch.msgid.link/20cbfc32678019daadd3c67fd75262b8264aa180.1790178801.git.sunnytiwari@google.com Signed-off-by: Jakub Kicinski --- net/rds/ib.h | 4 ++-- net/rds/ib_cm.c | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/net/rds/ib.h b/net/rds/ib.h index 5ff346a1e8ba..1901226368c9 100644 --- a/net/rds/ib.h +++ b/net/rds/ib.h @@ -159,8 +159,8 @@ struct rds_ib_connection { atomic_t i_fastreg_inuse_count; /* interrupt handling */ - struct tasklet_struct i_send_tasklet; - struct tasklet_struct i_recv_tasklet; + struct work_struct i_send_work; + struct work_struct i_recv_work; /* tx */ struct rds_ib_work_ring i_send_ring; diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c index 6e3110a04ae6..3ebe13d00953 100644 --- a/net/rds/ib_cm.c +++ b/net/rds/ib_cm.c @@ -253,7 +253,7 @@ static void rds_ib_cq_comp_handler_recv(struct ib_cq *cq, void *context) rds_ib_stats_inc(s_ib_evt_handler_call); - tasklet_schedule(&ic->i_recv_tasklet); + queue_work(system_bh_wq, &ic->i_recv_work); } static void poll_scq(struct rds_ib_connection *ic, struct ib_cq *cq, @@ -279,9 +279,9 @@ static void poll_scq(struct rds_ib_connection *ic, struct ib_cq *cq, } } -static void rds_ib_tasklet_fn_send(unsigned long data) +static void rds_ib_send_worker(struct work_struct *work) { - struct rds_ib_connection *ic = (struct rds_ib_connection *)data; + struct rds_ib_connection *ic = from_work(ic, work, i_send_work); struct rds_connection *conn = ic->conn; rds_ib_stats_inc(s_ib_tasklet_call); @@ -319,9 +319,9 @@ static void poll_rcq(struct rds_ib_connection *ic, struct ib_cq *cq, } } -static void rds_ib_tasklet_fn_recv(unsigned long data) +static void rds_ib_recv_worker(struct work_struct *work) { - struct rds_ib_connection *ic = (struct rds_ib_connection *)data; + struct rds_ib_connection *ic = from_work(ic, work, i_recv_work); struct rds_connection *conn = ic->conn; struct rds_ib_device *rds_ibdev = ic->rds_ibdev; struct rds_ib_ack_state state; @@ -381,7 +381,7 @@ static void rds_ib_cq_comp_handler_send(struct ib_cq *cq, void *context) rds_ib_stats_inc(s_ib_evt_handler_call); - tasklet_schedule(&ic->i_send_tasklet); + queue_work(system_bh_wq, &ic->i_send_work); } static inline int ibdev_get_unused_vector(struct rds_ib_device *rds_ibdev) @@ -1099,12 +1099,12 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path *cp) while (!wait_event_timeout(rds_ib_ring_empty_wait, rds_ib_conn_path_shutdown_check_wait(cp) == 0, msecs_to_jiffies(1000))) { - tasklet_schedule(&ic->i_send_tasklet); - tasklet_schedule(&ic->i_recv_tasklet); + queue_work(system_bh_wq, &ic->i_send_work); + queue_work(system_bh_wq, &ic->i_recv_work); } - tasklet_kill(&ic->i_send_tasklet); - tasklet_kill(&ic->i_recv_tasklet); + disable_work_sync(&ic->i_send_work); + disable_work_sync(&ic->i_recv_work); atomic_set(&ic->i_cq_quiesce, 1); @@ -1123,6 +1123,9 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path *cp) ib_destroy_cq(ic->i_recv_cq); } + enable_work(&ic->i_send_work); + enable_work(&ic->i_recv_work); + if (ic->rds_ibdev) { /* then free the resources that ib callbacks use */ if (ic->i_send_hdrs) { @@ -1234,10 +1237,8 @@ int rds_ib_conn_alloc(struct rds_connection *conn, gfp_t gfp) } INIT_LIST_HEAD(&ic->ib_node); - tasklet_init(&ic->i_send_tasklet, rds_ib_tasklet_fn_send, - (unsigned long)ic); - tasklet_init(&ic->i_recv_tasklet, rds_ib_tasklet_fn_recv, - (unsigned long)ic); + INIT_WORK(&ic->i_send_work, rds_ib_send_worker); + INIT_WORK(&ic->i_recv_work, rds_ib_recv_worker); mutex_init(&ic->i_recv_mutex); #ifndef KERNEL_HAS_ATOMIC64 spin_lock_init(&ic->i_ack_lock); From 3c21842f999a27962b34d685b7153d936c21a339 Mon Sep 17 00:00:00 2001 From: Subbaraya Sundeep Date: Wed, 23 Sep 2026 09:05:00 +0530 Subject: [PATCH 0797/2126] octeontx2-af: nix: Log TX scheduler queue validation failures Emit logs when is_valid_txschq() rejects a scheduler queue mapping so misconfigured TX scheduler allocations are easier to diagnose. Signed-off-by: Subbaraya Sundeep Signed-off-by: Ratheesh Kannoth Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260923033500.1752732-1-rkannoth@marvell.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c index 93c5c4b298bf..d04540420bca 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -324,15 +324,23 @@ static bool is_valid_txschq(struct rvu *rvu, int blkaddr, if (lvl >= hw->cap.nix_tx_aggr_lvl) { if ((nix_get_tx_link(rvu, map_func) != nix_get_tx_link(rvu, pcifunc)) && - (rvu_get_pf(rvu->pdev, map_func) != - rvu_get_pf(rvu->pdev, pcifunc))) + (rvu_get_pf(rvu->pdev, map_func) != + rvu_get_pf(rvu->pdev, pcifunc))) { + dev_err_ratelimited(rvu->dev, + "NIX TX schq %u lvl %d: pcifunc %x PF/link mismatch\n", + schq, lvl, pcifunc); return false; - else + } else { return true; + } } - if (map_func != pcifunc) + if (map_func != pcifunc) { + dev_err_ratelimited(rvu->dev, + "NIX TX schq %u lvl %d: not owned by pcifunc %x\n", + schq, lvl, pcifunc); return false; + } return true; } From 83cfac9d70cbc502c763f6ef259fb18f9d27081f Mon Sep 17 00:00:00 2001 From: Rouven Czerwinski Date: Thu, 24 Sep 2026 12:48:18 +0200 Subject: [PATCH 0798/2126] net: phy: mxl-gpy: add 2.5G for MXL86211C The MXL86211C also supports 2.5G via 2500BASEX, switch the config init to indicate support for that mode. Datasheet checks indicate that the 2.5G speed indication is the same between GPY211 & MXL86211C. The same should be true for MXL86252 & MXL86282, those are not modified for a lack of testing hardware. With this change 2.5G negotiates correctly with a Mikrotik CRS310-8G+2S+IN. Reviewed-by: Andrew Lunn Signed-off-by: Rouven Czerwinski Link: https://patch.msgid.link/20260924-mainline-rouven-mxl2g5-v2-1-fc8367a4c3ad@linaro.org Signed-off-by: Jakub Kicinski --- drivers/net/phy/mxl-gpy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c index 0da2d4e9d854..089a1a9e5bc6 100644 --- a/drivers/net/phy/mxl-gpy.c +++ b/drivers/net/phy/mxl-gpy.c @@ -1405,7 +1405,7 @@ static struct phy_driver gpy_drivers[] = { PHY_ID_MATCH_MODEL(PHY_ID_MXL86211C), .name = "Maxlinear Ethernet MxL86211C", .get_features = genphy_c45_pma_read_abilities, - .config_init = gpy_config_init, + .config_init = gpy21x_config_init, .probe = gpy_probe, .inband_caps = gpy_inband_caps, .config_inband = gpy_config_inband, From 7f92b7f381ffa83800bba6d535ac36a764f3abeb Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Thu, 24 Sep 2026 16:12:09 -0700 Subject: [PATCH 0799/2126] dpll: do not truncate the requested pin frequency before checking it DPLL_A_PIN_FREQUENCY is a u64 on the wire and dpll_pin_freq_set() keeps it as one, but dpll_pin_is_freq_supported() takes a u32 while the ranges it compares against are u64. The supported-frequency check therefore only looks at the low 32 bits, and the full value is what reaches the driver. Nothing is hitting this today. Reaching it at all needs a pin-set above U32_MAX, which no sane caller sends, and the outcome is mild: a pin advertising 10 kHz accepts 0x1_0000_2710, ice narrows it straight back to 10 kHz in ice_dpll_pin_freq_set(), so the hardware still ends up on an advertised frequency and only the "frequency is not supported by the device" rejection goes missing. The other direction - a legitimate request above U32_MAX wrapping out of the pin's range - needs a driver advertising such a range, and none does; zl3073x_pin_check_freq() refuses one outright. So this is types rather than a live bug. Widen the check to match the attribute, the ranges and the driver callback instead of adding a U32_MAX rejection, so that the second case stays right if such a driver appears. dpll_pin_esync_set() already keeps u64 throughout its equivalent loop. Reviewed-by: Ivan Vecera Link: https://patch.msgid.link/20260924231211.568213-2-kuba@kernel.org Signed-off-by: Jakub Kicinski --- drivers/dpll/dpll_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index fb24fd53f2e1..e5380d95f238 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -608,7 +608,7 @@ nest_cancel: return -EMSGSIZE; } -static bool dpll_pin_is_freq_supported(struct dpll_pin *pin, u32 freq) +static bool dpll_pin_is_freq_supported(struct dpll_pin *pin, u64 freq) { int fs; From 398f802dba0108e37c4070096a7a223f11d0babb Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Thu, 24 Sep 2026 16:12:10 -0700 Subject: [PATCH 0800/2126] netlink: specs: dpll: declare pad in the nests which carry 64-bit values Pads need to be propagated to subsets if they are used. Otherwise Python YNL can fail with: YnlException: Space 'frequency-range' has no attribute with value '4' This affects only platforms which care about alignment so not much real impact. Reviewed-by: Ivan Vecera Link: https://patch.msgid.link/20260924231211.568213-3-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/dpll.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/netlink/specs/dpll.yaml b/Documentation/netlink/specs/dpll.yaml index e2ca4df5699a..7009a64473b1 100644 --- a/Documentation/netlink/specs/dpll.yaml +++ b/Documentation/netlink/specs/dpll.yaml @@ -550,6 +550,8 @@ attribute-sets: attributes: - name: parent-id + - + name: pad - name: direction - @@ -576,6 +578,8 @@ attribute-sets: name: frequency-range subset-of: pin attributes: + - + name: pad - name: frequency-min - From 863da457b407f84beb8d60f8d13384e2b13e2b13 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Thu, 24 Sep 2026 16:12:11 -0700 Subject: [PATCH 0801/2126] netlink: specs: dpll: drop the reference to DPLL_MODE_DETACHED The lock-status doc tells userspace that DPLL_LOCK_STATUS_UNLOCKED can be forced by setting DPLL_A_MODE to DPLL_MODE_DETACHED. But no such value has been defined so far. enum dpll_mode has only MANUAL and AUTOMATIC. Let's make sure the doc reflects current reality. Reviewed-by: Ivan Vecera Link: https://patch.msgid.link/20260924231211.568213-4-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/dpll.yaml | 3 +-- include/uapi/linux/dpll.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/dpll.yaml b/Documentation/netlink/specs/dpll.yaml index 7009a64473b1..8fa789a50273 100644 --- a/Documentation/netlink/specs/dpll.yaml +++ b/Documentation/netlink/specs/dpll.yaml @@ -31,8 +31,7 @@ definitions: - name: unlocked doc: | - dpll was not yet locked to any valid input (or forced by setting - DPLL_A_MODE to DPLL_MODE_DETACHED) + dpll was not yet locked to any valid input value: 1 - name: locked diff --git a/include/uapi/linux/dpll.h b/include/uapi/linux/dpll.h index 85b898b1db5e..8c71fc3f9863 100644 --- a/include/uapi/linux/dpll.h +++ b/include/uapi/linux/dpll.h @@ -29,8 +29,7 @@ enum dpll_mode { /** * enum dpll_lock_status - provides information of dpll device lock status, * valid values for DPLL_A_LOCK_STATUS attribute - * @DPLL_LOCK_STATUS_UNLOCKED: dpll was not yet locked to any valid input (or - * forced by setting DPLL_A_MODE to DPLL_MODE_DETACHED) + * @DPLL_LOCK_STATUS_UNLOCKED: dpll was not yet locked to any valid input * @DPLL_LOCK_STATUS_LOCKED: dpll is locked to a valid signal, but no holdover * available * @DPLL_LOCK_STATUS_LOCKED_HO_ACQ: dpll is locked and holdover acquired From a72690652227ef7a5031268568f178bd3eee5585 Mon Sep 17 00:00:00 2001 From: Ayush Yaduvanshi Date: Fri, 25 Sep 2026 04:51:38 +0530 Subject: [PATCH 0802/2126] ice: dpll: fix kernel-doc parameter descriptions Remove stale @count and @cgu parameter descriptions from ice_dpll_init_fwnode_pins() and ice_dpll_init_pins_e825(). Signed-off-by: Ayush Yaduvanshi Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260924232138.69492-1-ayush37735@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice_dpll.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index 0109fc34307c..ade1fb3dd067 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -4221,7 +4221,6 @@ ice_dpll_init_fwnode_pin(struct ice_dpll_pin *pin, const char *name) * @pf: board private structure * @pins: pointer to pins array * @start_idx: starting index for pins - * @count: number of pins to initialize * * Initialize input pins for E825 RCLK support. The parent pins (rclk0, rclk1) * are expected to be defined by the system firmware (ACPI). This function @@ -4372,7 +4371,6 @@ static int ice_dpll_init_tspll_pins(struct ice_pf *pf) /** * ice_dpll_init_pins_e825 - init pins and register pins with a dplls * @pf: board private structure - * @cgu: if cgu is present and controlled by this NIC * * Initialize directly connected pf's pins within pf's dplls in a Linux dpll * subsystem. From 014d795c73837ea2339a4ea8e8f82c6e959b845d Mon Sep 17 00:00:00 2001 From: Ayush Yaduvanshi Date: Fri, 25 Sep 2026 05:32:44 +0530 Subject: [PATCH 0803/2126] idpf: fix kernel-doc parameter descriptions Remove stale @vport parameter descriptions from idpf_rx_desc_rel_all() and idpf_vport_queue_grp_rel_all(). Signed-off-by: Ayush Yaduvanshi Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925000244.72480-1-ayush37735@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index 215a62161a04..885df6294ad9 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -487,7 +487,6 @@ static void idpf_rx_desc_rel_bufq(struct idpf_buf_queue *bufq, /** * idpf_rx_desc_rel_all - Free Rx Resources for All Queues - * @vport: virtual port structure * @rsrc: pointer to queue and vector resources * * Free all rx queues resources @@ -1394,7 +1393,6 @@ static void idpf_rxq_group_rel(struct idpf_q_vec_rsrc *rsrc) /** * idpf_vport_queue_grp_rel_all - Release all queue groups - * @vport: vport to release queue groups for * @rsrc: pointer to queue and vector resources */ static void idpf_vport_queue_grp_rel_all(struct idpf_q_vec_rsrc *rsrc) From f95b9f28a9df609be434c645d9de632041285262 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Tue, 1 Sep 2026 21:07:56 +0200 Subject: [PATCH 0804/2126] batman-adv: tt: queue local DEL event under bucket lock batadv_tt_local_remove() sets BATADV_TT_CLIENT_PENDING on an already announced local entry and only afterwards queues the DEL change event. It holds neither the hash bucket list_lock nor bat_priv->tt.commit_lock. It can therefore be potentially interrupted in the middle: CPU0 CPU1 batadv_tt_local_remove() flags |= ..._PENDING; batadv_tt_local_commit_changes() ..._purge_pending_clients() hlist_del_rcu(&...->hash_entry); batadv_tt_local_update_crc() atomic_inc(&bat_priv->tt.vn); batadv_tt_local_event() /* DEL queued only now */ The client then disappears from the local table and from the CRC of the new TTVN after batadv_tt_local_commit_changes() without a DEL change being announced for it. Neighbours receiving the new CRC without previously seeing the DEL will try to recover via a full table request. Move the event into batadv_tt_local_mark_removed() and hold the bucket list_lock of the entry around both the flag change and the DEL event to avoid this scenario. Fixes: 976b159b3c12 ("batman-adv: tt: use protected flag modifications") Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=12 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 64 ++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index c904d67791f8..c229c51cafa7 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -1427,13 +1427,20 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb) * @message: debug message describing the reason for the change * * Schedule the TT change announcement for the entry. The caller must already - * have added BATADV_TT_CLIENT_PENDING to the @tt_local_entry + * have added BATADV_TT_CLIENT_PENDING to the @tt_local_entry and must hold the + * hash bucket list_lock of @tt_local_entry since setting the flag. */ static void batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, struct batadv_tt_local_entry *tt_local_entry, u16 flags, const char *message) { + struct batadv_hashtable *hash = bat_priv->tt.local_hash; + u32 i; + + i = batadv_choose_tt(&tt_local_entry->common, hash->size); + lockdep_assert_held(&hash->list_locks[i]); + batadv_tt_local_event(bat_priv, tt_local_entry, flags); batadv_dbg(BATADV_DBG_TT, bat_priv, @@ -1443,20 +1450,37 @@ batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, } /** - * batadv_tt_local_mark_removed() - mark a local entry as removed + * batadv_tt_local_mark_removed() - mark a local entry as removed and queue DEL + * @bat_priv: the bat priv with all the mesh interface information * @tt_local_entry: local TT entry to mark + * @message: message to append to the log on deletion * @roaming: true if the deletion is due to a roaming event * @curr_flags: pointer to store the flags of the entry before it was marked * + * An already announced entry is marked as BATADV_TT_CLIENT_PENDING and the + * (roamed) DEL change is queued. Both happen under the hash bucket list_lock + * of the entry to prevent concurrent batadv_tt_local_purge_pending_clients() + * from removing the entry. + * * Return: true if the entry has to be kept in the local table until the next * ttvn increment, false if it can be purged immediately. */ static bool -batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry, - bool roaming, u16 *curr_flags) +batadv_tt_local_mark_removed(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local_entry, + const char *message, bool roaming, u16 *curr_flags) { + spinlock_t *list_lock; /* protects write access to the hash lists */ struct batadv_tt_common_entry *common = &tt_local_entry->common; + struct batadv_hashtable *hash = bat_priv->tt.local_hash; bool pending = false; + u16 flags; + u32 i; + + i = batadv_choose_tt(common, hash->size); + list_lock = &hash->list_locks[i]; + + spin_lock_bh(list_lock); scoped_guard(spinlock_bh, &common->flags_lock) { *curr_flags = common->flags; @@ -1474,6 +1498,17 @@ batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry, } } + if (pending) { + flags = BATADV_TT_CLIENT_DEL; + if (roaming) + flags |= BATADV_TT_CLIENT_ROAM; + + batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, + flags, message); + } + + spin_unlock_bh(list_lock); + return pending; } @@ -1532,28 +1567,17 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, { struct batadv_tt_local_entry *tt_local_entry; u16 curr_flags; - u16 flags; tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); if (!tt_local_entry) return BATADV_NO_FLAGS; - if (batadv_tt_local_mark_removed(tt_local_entry, roaming, &curr_flags)) { - /* queue (roamed) del event which was prepared by - * batadv_tt_local_mark_removed() - */ - flags = BATADV_TT_CLIENT_DEL; - if (roaming) - flags |= BATADV_TT_CLIENT_ROAM; - - batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, - flags, message); - } else { - /* if this client has been added right now, it is possible to - * immediately purge it - */ + /* if this client has been added right now, it is possible to + * immediately purge it + */ + if (!batadv_tt_local_mark_removed(bat_priv, tt_local_entry, message, + roaming, &curr_flags)) batadv_tt_local_remove_now(bat_priv, tt_local_entry); - } batadv_tt_local_entry_put(tt_local_entry); From a6746cb1907615a37acf26f7e529a022e99876a0 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sun, 27 Sep 2026 13:18:17 +0200 Subject: [PATCH 0805/2126] batman-adv: tt: queue local DEL event before marking entry as pending batadv_tt_local_set_pending() originally queued the DEL change event and only afterwards set BATADV_TT_CLIENT_PENDING on the local entry. Commit 976b159b3c12 ("batman-adv: tt: use protected flag modifications") inverted this order for batadv_tt_local_remove() and batadv_tt_local_purge_list(). The hash bucket list_lock held around both steps does not help against batadv_tt_local_add_existing() because it is not holding it. CPU0 CPU1 flags |= ..._PENDING; batadv_tt_local_add_existing() flags &= ~..._PENDING; batadv_tt_local_event(ADD) batadv_tt_local_event(DEL) If the ADD was already announced by a commit in between, the DEL is sent in the next TTVN although the entry is no longer pending (after batadv_tt_local_add_existing()) and the local entry was never purged. The incorrect DEL will corrupt the CRC on neighbor nodes. A full table sync request is therefore issued to resolve this problem. When the DEL event is queued before the flag is set, a batadv_tt_local_add_existing() which clears the flag afterwards queues its ADD behind the DEL, and both cancel each other out. But the check whether an entry has to be removed must not be separated (by using two different critial flags_lock sections) from setting the flag (in batadv_tt_local_event) either. Otherwise batadv_tt_local_add_existing() could refresh the entry between both steps without queuing an ADD, and an active client would be announced as removed and purged. Fixes: 976b159b3c12 ("batman-adv: tt: use protected flag modifications") Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831135117.574836-1-sw%40simonwunderlich.de?part=12 Signed-off-by: Sven Eckelmann --- net/batman-adv/translation-table.c | 102 ++++++++++++++++------------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index c229c51cafa7..481dc6afaaba 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -461,23 +461,21 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common) } /** - * batadv_tt_local_event() - store a local TT event (ADD/DEL) + * __batadv_tt_local_event() - store a local TT event (ADD/DEL) with given flags * @bat_priv: the bat priv with all the mesh interface information - * @tt_local_entry: the TT entry involved in the event - * @event_flags: flags to store in the event structure + * @common: the TT entry involved in the event + * @flags: flags of the TT entry combined with the event flags */ -static void batadv_tt_local_event(struct batadv_priv *bat_priv, - struct batadv_tt_local_entry *tt_local_entry, - u8 event_flags) +static void __batadv_tt_local_event(struct batadv_priv *bat_priv, + const struct batadv_tt_common_entry *common, + u8 flags) { - struct batadv_tt_common_entry *common = &tt_local_entry->common; struct batadv_tt_change_node *tt_change_node; struct batadv_tt_change_node *entry; struct batadv_tt_change_node *safe; bool del_op_requested; bool del_op_entry; size_t changes; - u8 flags; tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); if (!tt_change_node) @@ -488,8 +486,6 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, ether_addr_copy(tt_change_node->change.addr, common->addr); tt_change_node->change.vid = htons(common->vid); - flags = batadv_tt_flags_get(common) | event_flags; - tt_change_node->change.flags = flags; del_op_requested = flags & BATADV_TT_CLIENT_DEL; @@ -537,6 +533,23 @@ update_changes: spin_unlock_bh(&bat_priv->tt.changes_list_lock); } +/** + * batadv_tt_local_event() - store a local TT event (ADD/DEL) + * @bat_priv: the bat priv with all the mesh interface information + * @tt_local_entry: the TT entry involved in the event + * @event_flags: flags to store in the event structure + */ +static void batadv_tt_local_event(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local_entry, + u8 event_flags) +{ + struct batadv_tt_common_entry *common = &tt_local_entry->common; + u8 flags; + + flags = batadv_tt_flags_get(common) | event_flags; + __batadv_tt_local_event(bat_priv, common, flags); +} + /** * batadv_tt_len() - compute length in bytes of given number of tt changes * @changes_num: number of tt changes @@ -1420,28 +1433,37 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb) } /** - * batadv_tt_local_set_pending_event() - trigger events for TT pending removal + * batadv_tt_local_set_pending() - mark local TT entry as pending removal * @bat_priv: the bat priv with all the mesh interface information - * @tt_local_entry: local TT entry which was marked as BATADV_TT_CLIENT_PENDING + * @tt_local_entry: local TT entry to mark as BATADV_TT_CLIENT_PENDING * @flags: TT change flags to announce together with the pending removal * @message: debug message describing the reason for the change * - * Schedule the TT change announcement for the entry. The caller must already - * have added BATADV_TT_CLIENT_PENDING to the @tt_local_entry and must hold the - * hash bucket list_lock of @tt_local_entry since setting the flag. + * Schedule the TT change announcement and set BATADV_TT_CLIENT_PENDING on the + * entry. The entry is kept in the local table until the next TTVN increment + * so that a consistency-check response can still be answered. + * + * Next to the flags_lock of the entry, the caller must hold the hash bucket + * list_lock of @tt_local_entry. Otherwise + * batadv_tt_local_purge_pending_clients() could remove the entry before its + * change was queued. */ static void -batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, - struct batadv_tt_local_entry *tt_local_entry, - u16 flags, const char *message) +batadv_tt_local_set_pending(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local_entry, + u16 flags, const char *message) + __must_hold(&tt_local_entry->common.flags_lock) { + struct batadv_tt_common_entry *common = &tt_local_entry->common; struct batadv_hashtable *hash = bat_priv->tt.local_hash; u32 i; - i = batadv_choose_tt(&tt_local_entry->common, hash->size); + i = batadv_choose_tt(common, hash->size); lockdep_assert_held(&hash->list_locks[i]); + lockdep_assert_held(&common->flags_lock); - batadv_tt_local_event(bat_priv, tt_local_entry, flags); + __batadv_tt_local_event(bat_priv, common, common->flags | flags); + common->flags |= BATADV_TT_CLIENT_PENDING; batadv_dbg(BATADV_DBG_TT, bat_priv, "Local tt entry (%pM, vid: %d) pending to be removed: %s\n", @@ -1460,7 +1482,8 @@ batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, * An already announced entry is marked as BATADV_TT_CLIENT_PENDING and the * (roamed) DEL change is queued. Both happen under the hash bucket list_lock * of the entry to prevent concurrent batadv_tt_local_purge_pending_clients() - * from removing the entry. + * from removing the entry and batadv_tt_local_transition_new() from clearing + * BATADV_TT_CLIENT_NEW after it was checked. * * Return: true if the entry has to be kept in the local table until the next * ttvn increment, false if it can be purged immediately. @@ -1492,19 +1515,16 @@ batadv_tt_local_mark_removed(struct batadv_priv *bat_priv, if (roaming) common->flags |= BATADV_TT_CLIENT_ROAM; - if (!(common->flags & BATADV_TT_CLIENT_NEW)) { - common->flags |= BATADV_TT_CLIENT_PENDING; - pending = true; - } - } + if (common->flags & BATADV_TT_CLIENT_NEW) + break; - if (pending) { flags = BATADV_TT_CLIENT_DEL; if (roaming) flags |= BATADV_TT_CLIENT_ROAM; - batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, - flags, message); + batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags, + message); + pending = true; } spin_unlock_bh(list_lock); @@ -1601,37 +1621,25 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv, hlist_for_each_entry_safe(tt_common_entry, node_tmp, head, hash_entry) { - bool cont = false; - tt_local_entry = container_of(tt_common_entry, struct batadv_tt_local_entry, common); scoped_guard(spinlock_bh, &tt_local_entry->common.flags_lock) { - if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE) { - cont = true; + if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE) break; - } /* entry already marked for deletion */ - if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) { - cont = true; + if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) break; - } - if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout)) { - cont = true; + if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout)) break; - } - tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING; + batadv_tt_local_set_pending(bat_priv, tt_local_entry, + BATADV_TT_CLIENT_DEL, + "timed out"); } - - if (cont) - continue; - - batadv_tt_local_set_pending_event(bat_priv, tt_local_entry, - BATADV_TT_CLIENT_DEL, "timed out"); } } From 85fb027f611b200c75b456404def8665216bc2db Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 6 Aug 2026 14:35:19 +0200 Subject: [PATCH 0806/2126] batman-adv: tt: reject VLAN/TT entries before reaching size limit The translation table is announcing its current state via the TT TVLV in each OGM(2). If another originator detects a desync with its own copy of this state information, it will request a full table sync. Each originator must therefore be able to send a reply with its full table without hitting the size limit of this response. The translation table code already tries to limit the amount of local TT entries. But the code itself fails to achieve this task because: * the size check uses shared, unlocked information * the size check isn't done for VLANs When enough VLANs + TT entries are created in parallel, then the TT will need more room then allowed for a full translation table reply. Other originators will then send regularly requests for a table sync but never get a reply. To avoid this problem for new VLAN and local TT entries, each new entry must reserve "room" before it is actually allocated. Only when enough "room" is available, this reservation is granted. This makes it possible to keep the reservation handling locked and therefore safe for multiple parallel contexts. For now, over-reservation caused by a reduction of the MTU is not taken into account. Signed-off-by: Sven Eckelmann --- net/batman-adv/main.c | 1 + net/batman-adv/mesh-interface.c | 8 ++ net/batman-adv/translation-table.c | 194 ++++++++++++++++++++++++----- net/batman-adv/translation-table.h | 3 + net/batman-adv/types.h | 19 +++ 5 files changed, 194 insertions(+), 31 deletions(-) diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index d89d44706269..6c54a8d4be3e 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -198,6 +198,7 @@ int batadv_mesh_init(struct net_device *mesh_iface) spin_lock_init(&bat_priv->tt.roam_list_lock); spin_lock_init(&bat_priv->tt.last_changeset_lock); spin_lock_init(&bat_priv->tt.commit_lock); + spin_lock_init(&bat_priv->tt.reserve_lock); spin_lock_init(&bat_priv->gw.list_lock); #ifdef CONFIG_BATMAN_ADV_MCAST spin_lock_init(&bat_priv->mcast.mla_lock); diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c index 63af21954cf9..1ce707aaf48a 100644 --- a/net/batman-adv/mesh-interface.c +++ b/net/batman-adv/mesh-interface.c @@ -561,6 +561,8 @@ void batadv_meshif_vlan_release(struct kref *ref) hlist_del_rcu(&vlan->list); spin_unlock_bh(&vlan->bat_priv->meshif_vlan_list_lock); + batadv_tt_local_unreserve_vlan(vlan->bat_priv); + kfree_rcu(vlan, rcu); } @@ -614,9 +616,15 @@ int batadv_meshif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid) return -EEXIST; } + if (!batadv_tt_local_reserve_vlan(bat_priv, vid)) { + spin_unlock_bh(&bat_priv->meshif_vlan_list_lock); + return -EMSGSIZE; + } + vlan = kzalloc_obj(*vlan, GFP_ATOMIC); if (!vlan) { spin_unlock_bh(&bat_priv->meshif_vlan_list_lock); + batadv_tt_local_unreserve_vlan(bat_priv); return -ENOMEM; } diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 481dc6afaaba..3349376a9087 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -234,6 +234,162 @@ batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr, return tt_global_entry; } +/** + * batadv_tt_len() - compute length in bytes of given number of tt changes + * @changes_num: number of tt changes + * + * Return: computed length in bytes. + */ +static int batadv_tt_len(int changes_num) +{ + return changes_num * sizeof(struct batadv_tvlv_tt_change); +} + +/** + * batadv_tt_local_transmit_size() - calculate the size of a full table response + * for a given number of VLANs and local TT entries + * @num_vlan: number of announced VLANs + * @num_entries: number of announced local TT entries + * + * Return: local translation table size in bytes. + */ +static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries) +{ + int hdr_size; + + /* header size of tvlv encapsulated tt response payload */ + hdr_size = sizeof(struct batadv_unicast_tvlv_packet); + hdr_size += sizeof(struct batadv_tvlv_hdr); + hdr_size += sizeof(struct batadv_tvlv_tt_data); + hdr_size += num_vlan * sizeof(struct batadv_tvlv_tt_vlan_data); + + return hdr_size + batadv_tt_len(num_entries); +} + +/** + * batadv_tt_local_reserve() - reserve room in the transmittable local table + * @bat_priv: the bat priv with all the mesh interface information + * @num_vlan: number of VLANs to reserve + * @num_entries: number of local TT entries to reserve + * @table_size: stores the resulting worst case table size in bytes + * + * Add the requested number of VLANs and local TT entries to the reservation + * counters and check whether the local translation table would then still fit + * in a single full table response. The reservation is dropped again when it + * would not. + * + * The reservation has to happen before the related object is allocated. This + * way two parallel allocations cannot both observe enough room for themselves + * and end up with a local table which can no longer be transmitted. + * + * A granted reservation must be returned via batadv_tt_local_unreserve() when + * the related object is released or was never created. + * + * Return: true when the reservation was granted, false otherwise. + */ +static bool batadv_tt_local_reserve(struct batadv_priv *bat_priv, u16 num_vlan, + u16 num_entries, int *table_size) +{ + int packet_size_max = READ_ONCE(bat_priv->packet_size_max); + + scoped_guard(spinlock_bh, &bat_priv->tt.reserve_lock) { + bat_priv->tt.reserved_vlans += num_vlan; + bat_priv->tt.reserved_entries += num_entries; + + *table_size = batadv_tt_local_transmit_size(bat_priv->tt.reserved_vlans, + bat_priv->tt.reserved_entries); + if (*table_size <= packet_size_max) + return true; + + bat_priv->tt.reserved_vlans -= num_vlan; + bat_priv->tt.reserved_entries -= num_entries; + } + + return false; +} + +/** + * batadv_tt_local_unreserve() - return room in the transmittable local table + * @bat_priv: the bat priv with all the mesh interface information + * @num_vlan: number of VLANs to return + * @num_entries: number of local TT entries to return + */ +static void batadv_tt_local_unreserve(struct batadv_priv *bat_priv, + u16 num_vlan, u16 num_entries) +{ + scoped_guard(spinlock_bh, &bat_priv->tt.reserve_lock) { + bat_priv->tt.reserved_vlans -= num_vlan; + bat_priv->tt.reserved_entries -= num_entries; + } +} + +/** + * batadv_tt_local_reserve_entry() - reserve room for a new local TT entry + * @bat_priv: the bat priv with all the mesh interface information + * @addr: the mac address of the client to add + * + * Return: true when the reservation was granted, false otherwise. + */ +static bool batadv_tt_local_reserve_entry(struct batadv_priv *bat_priv, + const u8 *addr) +{ + int table_size; + + if (batadv_tt_local_reserve(bat_priv, 0, 1, &table_size)) + return true; + + net_ratelimited_function(batadv_info, bat_priv->mesh_iface, + "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", + table_size, + READ_ONCE(bat_priv->packet_size_max), addr); + + return false; +} + +/** + * batadv_tt_local_unreserve_entry() - return the room of a local TT entry + * @bat_priv: the bat priv with all the mesh interface information + */ +static void batadv_tt_local_unreserve_entry(struct batadv_priv *bat_priv) +{ + batadv_tt_local_unreserve(bat_priv, 0, 1); +} + +/** + * batadv_tt_local_reserve_vlan() - reserve room for a new VLAN + * @bat_priv: the bat priv with all the mesh interface information + * @vid: the VLAN identifier + * + * Each VLAN adds a per VLAN header to the full table response and therefore + * has to be reserved before batadv_meshif_create_vlan() allocates it. + * + * Return: true when the reservation was granted, false otherwise. + */ +bool batadv_tt_local_reserve_vlan(struct batadv_priv *bat_priv, + unsigned short vid) +{ + int table_size; + + if (batadv_tt_local_reserve(bat_priv, 1, 0, &table_size)) + return true; + + net_ratelimited_function(batadv_info, bat_priv->mesh_iface, + "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new VLAN: %d\n", + table_size, READ_ONCE(bat_priv->packet_size_max), + batadv_print_vid(vid)); + + return false; +} + +/** + * batadv_tt_local_unreserve_vlan() - return the room of a VLAN + * @bat_priv: the bat priv with all the mesh interface information + */ +void batadv_tt_local_unreserve_vlan(struct batadv_priv *bat_priv) +{ + batadv_tt_local_unreserve(bat_priv, 1, 0); +} + /** * batadv_tt_local_entry_release() - release tt_local_entry from lists and queue * for free after rcu grace period @@ -246,6 +402,7 @@ static void batadv_tt_local_entry_release(struct kref *ref) tt_local_entry = container_of(ref, struct batadv_tt_local_entry, common.refcount); + batadv_tt_local_unreserve_entry(tt_local_entry->vlan->bat_priv); batadv_meshif_vlan_put(tt_local_entry->vlan); kfree_rcu(tt_local_entry, common.rcu); @@ -550,17 +707,6 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, __batadv_tt_local_event(bat_priv, common, flags); } -/** - * batadv_tt_len() - compute length in bytes of given number of tt changes - * @changes_num: number of tt changes - * - * Return: computed length in bytes. - */ -static int batadv_tt_len(int changes_num) -{ - return changes_num * sizeof(struct batadv_tvlv_tt_change); -} - /** * batadv_tt_entries() - compute the number of entries fitting in tt_len bytes * @tt_len: available space @@ -584,7 +730,6 @@ static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv) struct batadv_meshif_vlan *vlan; u16 tt_local_entries = 0; u16 num_vlan = 0; - int hdr_size; rcu_read_lock(); hlist_for_each_entry_rcu(vlan, &bat_priv->meshif_vlan_list, list) { @@ -593,13 +738,7 @@ static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv) } rcu_read_unlock(); - /* header size of tvlv encapsulated tt response payload */ - hdr_size = sizeof(struct batadv_unicast_tvlv_packet); - hdr_size += sizeof(struct batadv_tvlv_hdr); - hdr_size += sizeof(struct batadv_tvlv_tt_data); - hdr_size += num_vlan * sizeof(struct batadv_tvlv_tt_vlan_data); - - return hdr_size + batadv_tt_len(tt_local_entries); + return batadv_tt_local_transmit_size(num_vlan, tt_local_entries); } /** @@ -803,23 +942,15 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr, struct batadv_priv *bat_priv = netdev_priv(mesh_iface); struct batadv_tt_local_entry *tt_local; struct batadv_meshif_vlan *vlan; - int packet_size_max; - int table_size; - /* Ignore the client if we cannot send it in a full table response. */ - table_size = batadv_tt_local_table_transmit_size(bat_priv); - table_size += batadv_tt_len(1); - packet_size_max = READ_ONCE(bat_priv->packet_size_max); - if (table_size > packet_size_max) { - net_ratelimited_function(batadv_info, mesh_iface, - "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", - table_size, packet_size_max, addr); + if (!batadv_tt_local_reserve_entry(bat_priv, addr)) return NULL; - } tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC); - if (!tt_local) + if (!tt_local) { + batadv_tt_local_unreserve_entry(bat_priv); return NULL; + } /* increase the refcounter of the related vlan */ vlan = batadv_meshif_vlan_get(bat_priv, vid); @@ -828,6 +959,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr, "adding TT local entry %pM to non-existent VLAN %d\n", addr, batadv_print_vid(vid)); kmem_cache_free(batadv_tl_cache, tt_local); + batadv_tt_local_unreserve_entry(bat_priv); return NULL; } diff --git a/net/batman-adv/translation-table.h b/net/batman-adv/translation-table.h index 618d9dbca5ea..ca01d20ee2d7 100644 --- a/net/batman-adv/translation-table.h +++ b/net/batman-adv/translation-table.h @@ -16,6 +16,9 @@ #include int batadv_tt_init(struct batadv_priv *bat_priv); +bool batadv_tt_local_reserve_vlan(struct batadv_priv *bat_priv, + unsigned short vid); +void batadv_tt_local_unreserve_vlan(struct batadv_priv *bat_priv); bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, unsigned short vid, int ifindex, u32 mark); u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 67872927cfb5..c19caa84e692 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -1055,6 +1055,25 @@ struct batadv_priv_tt { */ spinlock_t commit_lock; + /** + * @reserved_entries: number of local TT entries which are currently + * allocated or about to be allocated. Together with @reserved_vlans it + * describes the worst case size of a full table response. + */ + u16 reserved_entries; + + /** + * @reserved_vlans: number of mesh interface VLANs which are currently + * allocated or about to be allocated. Together with @reserved_entries + * it describes the worst case size of a full table response. + */ + u16 reserved_vlans; + + /** + * @reserve_lock: lock protecting @reserved_entries & @reserved_vlans + */ + spinlock_t reserve_lock; + /** @work: work queue callback item for translation table purging */ struct delayed_work work; }; From d1807b20d548171d40c5d21a7cf22830ea8f348e Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sun, 20 Sep 2026 10:27:21 +0800 Subject: [PATCH 0807/2126] batman-adv: use assign_bit() where applicable Convert open-coded if/else with set_bit/clear_bit the assign_bit API. Signed-off-by: Peng Fan Signed-off-by: Sven Eckelmann --- net/batman-adv/distributed-arp-table.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index a4be5b2a87d7..74050bffedbc 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -863,10 +863,8 @@ static void batadv_dat_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv, u8 flags, void *tvlv_value, u16 tvlv_value_len) { - if (flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) - clear_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities); - else - set_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities); + assign_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities, + !(flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND)); } /** From a8708aa9fe1095ca7859cb3f102b6a3fa0fb98bd Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Wed, 19 Aug 2026 12:24:08 +0200 Subject: [PATCH 0808/2126] netfilter: synproxy: fix reset of ct seqadj when reopening a connection SYNPROXY is resetting conntrack seqadj when a closed connection is re-opened, but it was using nf_ct_seqadj_init() which is a no-op for a zero offset. This patch introduces nf_ct_seqadj_reset() which sets the offset values directly to zero and avoid setting IPS_SEQ_ADJUST_BIT flag, it changes SYNPROXY code to use it when needed. Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target") Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Pablo Neira Ayuso --- include/net/netfilter/nf_conntrack_seqadj.h | 1 + net/netfilter/nf_conntrack_seqadj.c | 17 +++++++++++++++++ net/netfilter/nf_synproxy_core.c | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/net/netfilter/nf_conntrack_seqadj.h b/include/net/netfilter/nf_conntrack_seqadj.h index 883c414b768e..0f5bbb14a25a 100644 --- a/include/net/netfilter/nf_conntrack_seqadj.h +++ b/include/net/netfilter/nf_conntrack_seqadj.h @@ -33,6 +33,7 @@ static inline struct nf_conn_seqadj *nfct_seqadj_ext_add(struct nf_conn *ct) int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo, s32 off); +void nf_ct_seqadj_reset(struct nf_conn *ct, enum ip_conntrack_info ctinfo); int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo, __be32 seq, s32 off); void nf_ct_tcp_seqadj_set(struct sk_buff *skb, struct nf_conn *ct, diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c index d75e8dafb189..b7b166a8ad58 100644 --- a/net/netfilter/nf_conntrack_seqadj.c +++ b/net/netfilter/nf_conntrack_seqadj.c @@ -31,6 +31,23 @@ int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo, } EXPORT_SYMBOL_GPL(nf_ct_seqadj_init); +void nf_ct_seqadj_reset(struct nf_conn *ct, enum ip_conntrack_info ctinfo) +{ + struct nf_conn_seqadj *seqadj = nfct_seqadj(ct); + enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); + struct nf_ct_seqadj *this_way; + + if (unlikely(!seqadj)) + return; + + spin_lock_bh(&ct->lock); + this_way = &seqadj->seq[dir]; + this_way->offset_before = 0; + this_way->offset_after = 0; + spin_unlock_bh(&ct->lock); +} +EXPORT_SYMBOL_GPL(nf_ct_seqadj_reset); + int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo, __be32 seq, s32 off) { diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index 9fc959ba2030..401ce5a13f3f 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -686,7 +686,7 @@ ipv4_synproxy_hook(void *priv, struct sk_buff *skb, * adjustments, they will get initialized once the connection is * reestablished. */ - nf_ct_seqadj_init(ct, ctinfo, 0); + nf_ct_seqadj_reset(ct, ctinfo); synproxy->tsoff = 0; this_cpu_inc(snet->stats->conn_reopened); fallthrough; @@ -1116,7 +1116,7 @@ ipv6_synproxy_hook(void *priv, struct sk_buff *skb, * adjustments, they will get initialized once the connection is * reestablished. */ - nf_ct_seqadj_init(ct, ctinfo, 0); + nf_ct_seqadj_reset(ct, ctinfo); synproxy->tsoff = 0; this_cpu_inc(snet->stats->conn_reopened); fallthrough; From 409df11c5674e1e6c8a79e8d008f007ad6f9b448 Mon Sep 17 00:00:00 2001 From: Shaojie Sun Date: Thu, 20 Aug 2026 20:57:18 +0800 Subject: [PATCH 0809/2126] netfilter: conntrack: fix nf_conntrack_expect_max default value in documentation The documentation for nf_conntrack_expect_max incorrectly states that the default value is nf_conntrack_buckets / 256. However, the code in nf_conntrack_expect_init() shows: nf_ct_expect_hsize = nf_conntrack_htable_size / 256; nf_ct_expect_max = nf_ct_expect_hsize * 4; This means the default value is actually nf_conntrack_buckets / 64 (i.e. 4 times the hash table size, which defaults to nf_conntrack_buckets / 256). Fix the documentation to reflect the correct default value and add explanation of the calculation. Signed-off-by: Shaojie Sun Signed-off-by: Pablo Neira Ayuso --- Documentation/networking/nf_conntrack-sysctl.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/nf_conntrack-sysctl.rst b/Documentation/networking/nf_conntrack-sysctl.rst index 35f889259fcd..4426cce2a73f 100644 --- a/Documentation/networking/nf_conntrack-sysctl.rst +++ b/Documentation/networking/nf_conntrack-sysctl.rst @@ -44,7 +44,7 @@ nf_conntrack_events - BOOLEAN nf_conntrack_expect_max - INTEGER Maximum size of expectation table. Default value is - nf_conntrack_buckets / 256. Minimum is 1. + nf_conntrack_buckets / 64. Minimum is 1. nf_conntrack_frag6_high_thresh - INTEGER default 262144 From 32cbf7a8e5560b42a8eac04ac66cc4dafff63e95 Mon Sep 17 00:00:00 2001 From: Linkui Xiao Date: Fri, 21 Aug 2026 17:50:14 +0800 Subject: [PATCH 0810/2126] netfilter: osf: remove unreachable break in nf_osf_ttl() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In nf_osf_ttl(), the break statement after return in NF_OSF_TTL_TRUE case is unreachable dead‑code. The return statement exits the function immediately, so break will never execute. Remove the useless break, no functional change. Signed-off-by: Linkui Xiao Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nfnetlink_osf.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/netfilter/nfnetlink_osf.c b/net/netfilter/nfnetlink_osf.c index e4835b0f4bb1..c8cd6af95db4 100644 --- a/net/netfilter/nfnetlink_osf.c +++ b/net/netfilter/nfnetlink_osf.c @@ -36,7 +36,6 @@ static inline int nf_osf_ttl(const struct sk_buff *skb, switch (ttl_check) { case NF_OSF_TTL_TRUE: return ip->ttl == f_ttl; - break; case NF_OSF_TTL_NOCHECK: return 1; case NF_OSF_TTL_LESS: From d8cefdc18124d2cedeb6419028648b681b7dfd1a Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 17:15:36 +0530 Subject: [PATCH 0811/2126] netfilter: fix several typos in comments Fix typos reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam Signed-off-by: Pablo Neira Ayuso --- net/ipv4/netfilter/arp_tables.c | 2 +- net/netfilter/ipset/ip_set_core.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 2 +- tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index db307fa49f3f..cf747e1e17a3 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -58,7 +58,7 @@ static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap, /* * Unfortunately, _b and _mask are not aligned to an int (or long int) * Some arches dont care, unrolling the loop is a win on them. - * For other arches, we only have a 16bit alignement. + * For other arches, we only have a 16bit alignment. */ static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask) { diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c index 0a86a170ba90..4aeb767088cf 100644 --- a/net/netfilter/ipset/ip_set_core.c +++ b/net/netfilter/ipset/ip_set_core.c @@ -1426,7 +1426,7 @@ static int ip_set_swap(struct sk_buff *skb, const struct nfnl_info *info, return -IPSET_ERR_EXIST_SETNAME2; /* Features must not change. - * Not an artifical restriction anymore, as we must prevent + * Not an artificial restriction anymore, as we must prevent * possible loops created by swapping in setlist type of sets. */ if (!(from->type->features == to->type->features && diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 5383aeafb0ae..4dacd5af65db 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -1344,7 +1344,7 @@ static void set_mcast_pmtudisc(struct sock *sk, int val) } /* - * Specifiy default interface for outgoing multicasts + * Specify default interface for outgoing multicasts */ static int set_mcast_if(struct sock *sk, struct net_device *dev) { diff --git a/tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh b/tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh index c63d840ead61..f63b7f12b36a 100755 --- a/tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh +++ b/tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh @@ -171,7 +171,7 @@ table inet filter { } EOF -# make sure NAT core rewrites adress of icmp error if nat is used according to +# make sure NAT core rewrites address of icmp error if nat is used according to # conntrack nat information (icmp error will be directed at nsrouter1 address, # but it needs to be routed to nsclient1 address). ip netns exec "$nsrouter1" nft -f - < Date: Tue, 8 Sep 2026 12:02:53 +0200 Subject: [PATCH 0812/2126] netfilter: conntrack: Untangle insert_failed counter from others There is not much sense in incrementing multiple conntrack counters for the same situation. Defining insert_failed as a situation where a valid packet's conntrack can't be confirmed due to unresolvable clash sets it apart from 'drop' (ENOMEM situation) and 'chaintoolong'. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index d0d9e5ea84a0..53401e21ad99 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1169,7 +1169,6 @@ nf_ct_resolve_clash(struct sk_buff *skb, struct nf_conntrack_tuple_hash *h, return ret; drop: - NF_CT_STAT_INC(net, drop); NF_CT_STAT_INC(net, insert_failed); return NF_DROP; } @@ -1259,7 +1258,6 @@ __nf_conntrack_confirm(struct sk_buff *skb) if (chainlen++ > max_chainlen) { chaintoolong: NF_CT_STAT_INC(net, chaintoolong); - NF_CT_STAT_INC(net, insert_failed); ret = NF_DROP; goto dying; } From 2ac41d7009c7c60e0b876760d98bd84a1f91020d Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 8 Sep 2026 12:02:54 +0200 Subject: [PATCH 0813/2126] netfilter: conntrack: Untangle drop and invalid counters In nf_conntrack_in, 'drop' counter increments if nf_conntrack_handle_packet returns NF_DROP. This is a special case with TCP packets (added by commit 6b69fe0c73c0 ("netfilter: nf_conntrack_tcp: fix endless loop") and not related to invalid packets which are responsible for all the other <=0 returns. So don't increment 'invalid' ounter in this case. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 53401e21ad99..f9b8927327ba 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -2065,9 +2065,10 @@ repeat: if (ret == -NF_REPEAT) goto repeat; - NF_CT_STAT_INC_ATOMIC(state->net, invalid); if (ret == NF_DROP) NF_CT_STAT_INC_ATOMIC(state->net, drop); + else + NF_CT_STAT_INC_ATOMIC(state->net, invalid); ret = -ret; goto out; From d4548625f38b7958540451f9afed9e4155b4fa22 Mon Sep 17 00:00:00 2001 From: Qingfang Deng Date: Wed, 9 Sep 2026 15:56:05 +0800 Subject: [PATCH 0814/2126] net/sched: act_ct: set net pointer before publishing flowtable nf_flow_table_init() adds the flowtable to the global flowtables list. However, tcf_ct_flow_table_get() sets the table's network namespace only after that call, leaving a window where the published table has a NULL namespace pointer. Set the namespace before calling nf_flow_table_init() so that flowtable list walkers can rely on it being initialized. This is required by: "netfilter: flowtable: check namespace before iterating flows" Signed-off-by: Qingfang Deng Reviewed-by: Xuanqiang Luo Signed-off-by: Pablo Neira Ayuso --- net/sched/act_ct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 411e3dd92d07..e26c0d5b2176 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -349,10 +349,10 @@ static int tcf_ct_flow_table_get(struct net *net, struct tcf_ct_params *params) ct_ft->nf_ft.type = &flowtable_ct; ct_ft->nf_ft.flags |= NF_FLOWTABLE_HW_OFFLOAD | NF_FLOWTABLE_COUNTER; + write_pnet(&ct_ft->nf_ft.net, net); err = nf_flow_table_init(&ct_ft->nf_ft); if (err) goto err_init; - write_pnet(&ct_ft->nf_ft.net, net); __module_get(THIS_MODULE); out_unlock: From c48fdf027a7265b86ea6332c4e1f56d86268541b Mon Sep 17 00:00:00 2001 From: Qingfang Deng Date: Wed, 9 Sep 2026 16:17:04 +0800 Subject: [PATCH 0815/2126] netfilter: flowtable: check namespace before iterating flows nf_flow_table_cleanup() walks every registered flow table, checking the network namespace for each flow in nf_flow_table_do_cleanup(). As a result, tables in other namespaces are still iterated and their cleanup work is flushed. Compare the flow table's namespace with the device's namespace in nf_flow_table_cleanup() and skip nonmatching tables. This avoids unnecessary iteration and work flushing, and leaves the per-flow cleanup callback to check only the interface index. Signed-off-by: Qingfang Deng Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_flow_table_core.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index 934c6151f558..bd8f9cf394ff 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -737,14 +737,9 @@ static void nf_flow_table_do_cleanup(struct nf_flowtable *flow_table, { struct net_device *dev = data; - if (!dev) { - flow_offload_teardown(flow); - return; - } - - if (net_eq(nf_ct_net(flow->ct), dev_net(dev)) && - (flow->tuplehash[0].tuple.iifidx == dev->ifindex || - flow->tuplehash[1].tuple.iifidx == dev->ifindex)) + if (!dev || + flow->tuplehash[0].tuple.iifidx == dev->ifindex || + flow->tuplehash[1].tuple.iifidx == dev->ifindex) flow_offload_teardown(flow); } @@ -761,8 +756,10 @@ void nf_flow_table_cleanup(struct net_device *dev) struct nf_flowtable *flowtable; mutex_lock(&flowtable_lock); - list_for_each_entry(flowtable, &flowtables, list) - nf_flow_table_gc_cleanup(flowtable, dev); + list_for_each_entry(flowtable, &flowtables, list) { + if (net_eq(read_pnet(&flowtable->net), dev_net(dev))) + nf_flow_table_gc_cleanup(flowtable, dev); + } mutex_unlock(&flowtable_lock); } EXPORT_SYMBOL_GPL(nf_flow_table_cleanup); From d3950004ba90350bcdf414c5f804da277178564a Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 9 Sep 2026 11:34:55 +0200 Subject: [PATCH 0816/2126] netfilter: nfnetlink: Fix for interrupted hook dumps Handling of concurrent hook changes with a dump in progress was problematic in nfnl_hook_dump and entirely broken in nfnl_hook_dump_nat. Address all issues in a single patch to please the review LLM. Introduce sequence numbers in struct netns_nf to replace pointer value-based modification detection which may fail due to memory buffer reuse. This also eliminates the need for most manual cb->seq updates and excessive array index value checks. Since nat hook updates are protected by a different mutex than others, they have to bump their own sequence number. nfnl_hook_dump_nat therefore open-codes what nl_dump_check_consistent does but bumps cb->seq instead of setting NLM_F_DUMP_INTR flag. Dumps of many nat hooks was entirely broken since the array index was not (re)stored. Use cb->args[1] for that and make sure it is reset upon completion as the same dump may loop over multiple arrays of nat hooks. In nfnl_hook_dump, don't signal NLM_F_DUMP_INTR if nfnl_hook_entries_head returns error: This is a permanent condition which does not change during a dump. It is already caught by nfnl_hook_dump_start though, so should not happen anyway. In general, access ops array pointer values using READ_ONCE since they are assigned to using WRITE_ONCE. Avoid setting NLM_F_DUMP_INTR flag in garbage memory by calling nl_dump_check_consistent only for non-empty skbs. If not a single netlink message was created, nfnetlink code will take care of setting the flag. Fixes: e2cf17d3774c ("netfilter: add new hook nfnl subsystem") Fixes: b010e2a4a9ac ("netfilter: nfnetlink_hook: Dump nat type chains") Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- include/net/netns/netfilter.h | 2 + net/netfilter/core.c | 18 ++++++++- net/netfilter/nf_nat_core.c | 11 +++++ net/netfilter/nfnetlink_hook.c | 74 ++++++++++++++++++++-------------- 4 files changed, 73 insertions(+), 32 deletions(-) diff --git a/include/net/netns/netfilter.h b/include/net/netns/netfilter.h index a6a0bf4a247e..7fd78394d1e7 100644 --- a/include/net/netns/netfilter.h +++ b/include/net/netns/netfilter.h @@ -33,5 +33,7 @@ struct netns_nf { #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) unsigned int defrag_ipv6_users; #endif + unsigned int hook_base_seq; + unsigned int nat_hook_base_seq; }; #endif diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 675a1034b340..940dea2663e9 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -386,6 +386,15 @@ static void nf_static_key_dec(const struct nf_hook_ops *reg, int pf) #endif } +static void bump_hook_base_seq(struct net *net) +{ + unsigned int base_seq = READ_ONCE(net->nf.hook_base_seq); + + while (++base_seq == 0) + ; + smp_store_release(&net->nf.hook_base_seq, base_seq); +} + static int __nf_register_net_hook(struct net *net, int pf, const struct nf_hook_ops *reg) { @@ -430,6 +439,7 @@ static int __nf_register_net_hook(struct net *net, int pf, if (!IS_ERR(new_hooks)) { hooks_validate(new_hooks); rcu_assign_pointer(*pp, new_hooks); + bump_hook_base_seq(net); } mutex_unlock(&nf_hook_mutex); @@ -483,6 +493,7 @@ static void __nf_unregister_net_hook(struct net *net, int pf, { struct nf_hook_entries __rcu **pp; struct nf_hook_entries *p; + bool found; pp = nf_hook_entry_head(net, pf, reg->hooknum, reg->dev); if (!pp) @@ -496,7 +507,8 @@ static void __nf_unregister_net_hook(struct net *net, int pf, return; } - if (nf_remove_net_hook(p, reg)) { + found = nf_remove_net_hook(p, reg); + if (found) { #ifdef CONFIG_NETFILTER_INGRESS if (nf_ingress_hook(reg, pf)) net_dec_ingress_queue(); @@ -511,6 +523,8 @@ static void __nf_unregister_net_hook(struct net *net, int pf, } p = __nf_hook_entries_try_shrink(p, pp); + if (found) + bump_hook_base_seq(net); mutex_unlock(&nf_hook_mutex); if (!p) return; @@ -784,6 +798,8 @@ static int __net_init netfilter_net_init(struct net *net) return -ENOMEM; } #endif + net->nf.hook_base_seq = 1; + net->nf.nat_hook_base_seq = 1; return 0; } diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c index 84f82957e66b..5ddd5fc95b24 100644 --- a/net/netfilter/nf_nat_core.c +++ b/net/netfilter/nf_nat_core.c @@ -1160,6 +1160,15 @@ nfnetlink_parse_nat_setup(struct nf_conn *ct, } #endif +static void bump_nat_hook_base_seq(struct net *net) +{ + unsigned int base_seq = READ_ONCE(net->nf.nat_hook_base_seq); + + while (++base_seq == 0) + ; + smp_store_release(&net->nf.nat_hook_base_seq, base_seq); +} + static struct nf_ct_helper_expectfn follow_master_nat = { .name = "nat-follow-master", .expectfn = nf_nat_follow_master, @@ -1245,6 +1254,7 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, nat_proto_net->nat_hook_ops = nat_ops; nat_proto_net->users++; + bump_nat_hook_base_seq(net); mutex_unlock(&nf_nat_proto_mutex); @@ -1299,6 +1309,7 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, goto unlock; priv = nat_ops[hooknum].priv; nf_hook_entries_delete_raw(&priv->entries, ops); + bump_nat_hook_base_seq(net); if (nat_proto_net->users == 0) { nf_unregister_net_hooks(net, nat_ops, ops_count); diff --git a/net/netfilter/nfnetlink_hook.c b/net/netfilter/nfnetlink_hook.c index 95005e9a6066..b05fd79397c5 100644 --- a/net/netfilter/nfnetlink_hook.c +++ b/net/netfilter/nfnetlink_hook.c @@ -54,7 +54,6 @@ static int nf_netlink_dump_start_rcu(struct sock *nlsk, struct sk_buff *skb, struct nfnl_dump_hook_data { char devname[IFNAMSIZ]; - unsigned long headv; u8 hook; }; @@ -338,27 +337,47 @@ nfnl_hook_entries_head(u8 pf, unsigned int hook, struct net *net, const char *de } static int nfnl_hook_dump_nat(struct sk_buff *nlskb, - const struct nfnl_dump_hook_data *ctx, - const struct nf_hook_ops *ops, - int family, unsigned int seq) + struct netlink_callback *cb, + const struct nf_hook_ops *ops, int family) { struct nf_nat_lookup_hook_priv *priv = ops->priv; - struct nf_hook_entries *e = rcu_dereference(priv->entries); + struct nfnl_dump_hook_data *ctx = cb->data; + struct net *net = sock_net(nlskb->sk); struct nf_hook_ops **nat_ops; - int i, err; + unsigned int i = cb->args[1]; + struct nf_hook_entries *e; + unsigned int base_seq; + int err = 0; + base_seq = smp_load_acquire(&net->nf.nat_hook_base_seq); + + e = rcu_dereference(priv->entries); if (!e) - return 0; + goto out; nat_ops = nf_hook_entries_get_hook_ops(e); - for (i = 0; i < e->num_hook_entries; i++) { - err = nfnl_hook_dump_one(nlskb, ctx, nat_ops[i], - ops->priority, family, seq); + for (; i < e->num_hook_entries; i++) { + err = nfnl_hook_dump_one(nlskb, ctx, + READ_ONCE(nat_ops[i]), + ops->priority, family, + cb->nlh->nlmsg_seq); if (err) - return err; + break; + } - return 0; +out: + if (!err) + i = 0; + cb->args[1] = i; + + if (cb->args[2] && base_seq != cb->args[2]) { + cb->seq++; + err = -EINTR; + } + cb->args[2] = base_seq; + + return err; } static int nfnl_hook_dump(struct sk_buff *nlskb, @@ -373,35 +392,31 @@ static int nfnl_hook_dump(struct sk_buff *nlskb, unsigned int i = cb->args[0]; rcu_read_lock(); + cb->seq = smp_load_acquire(&net->nf.hook_base_seq); e = nfnl_hook_entries_head(family, ctx->hook, net, ctx->devname); - if (!e) + if (!e || IS_ERR(e)) goto done; - if (IS_ERR(e)) { - cb->seq++; - goto done; - } - - if ((unsigned long)e != ctx->headv || i >= e->num_hook_entries) - cb->seq++; - ops = nf_hook_entries_get_hook_ops(e); for (; i < e->num_hook_entries; i++) { - if (ops[i]->hook_ops_type == NF_HOOK_OP_NAT) - err = nfnl_hook_dump_nat(nlskb, ctx, ops[i], family, - cb->nlh->nlmsg_seq); - else - err = nfnl_hook_dump_one(nlskb, ctx, ops[i], - ops[i]->priority, family, + const struct nf_hook_ops *cur = READ_ONCE(ops[i]); + + if (cur->hook_ops_type == NF_HOOK_OP_NAT) { + err = nfnl_hook_dump_nat(nlskb, cb, cur, family); + } else { + err = nfnl_hook_dump_one(nlskb, ctx, cur, + cur->priority, family, cb->nlh->nlmsg_seq); + } if (err) break; } done: - nl_dump_check_consistent(cb, nlmsg_hdr(nlskb)); + if (nlskb->len > 0) + nl_dump_check_consistent(cb, nlmsg_hdr(nlskb)); rcu_read_unlock(); cb->args[0] = i; return nlskb->len; @@ -442,10 +457,7 @@ static int nfnl_hook_dump_start(struct netlink_callback *cb) return -ENOMEM; strscpy(ctx->devname, name, sizeof(ctx->devname)); - ctx->headv = (unsigned long)head; ctx->hook = hooknum; - - cb->seq = 1; cb->data = ctx; return 0; From 1ae2d094b0200f687923298c0e42579273558988 Mon Sep 17 00:00:00 2001 From: Piotr Kubik Date: Wed, 9 Sep 2026 16:49:29 +0200 Subject: [PATCH 0817/2126] netfilter: ctnetlink: fix inverted IPv6 address match in dump filter ctnetlink_filter_match_tuple() rejects an entry when !ipv6_addr_cmp(filter, entry) is true. ipv6_addr_cmp() is a memcmp() and returns 0 for equal addresses, so the condition is true exactly when the addresses match: a CTA_FILTER dump with an IPv6 CTA_IP_SRC or CTA_IP_DST skips every entry that matches the requested address and returns all the others. The IPv4 branch compares with != and behaves correctly. Observed with libnetfilter_conntrack NFCT_FILTER_DUMP_TUPLE: a dump filtered on src 2001:db8::10 returned only the unrelated entries, and a dump filtered on ::1 returned every entry except the ::1 ones. conntrack-tools does not use the tuple filter for -L, which is why this went unnoticed. Use ipv6_addr_equal() so the IPv6 branch mirrors the IPv4 one. Fixes: cb8aa9a3affb ("netfilter: ctnetlink: add kernel side filtering for dump") Cc: stable@vger.kernel.org Signed-off-by: Piotr Kubik Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_netlink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 4e5d7c701436..e8477f792c95 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -1098,13 +1098,13 @@ static int ctnetlink_filter_match_tuple(struct nf_conntrack_tuple *filter_tuple, break; case NFPROTO_IPV6: if ((flags & CTA_FILTER_FLAG(CTA_IP_SRC)) && - !ipv6_addr_cmp(&filter_tuple->src.u3.in6, - &ct_tuple->src.u3.in6)) + !ipv6_addr_equal(&filter_tuple->src.u3.in6, + &ct_tuple->src.u3.in6)) return 0; if ((flags & CTA_FILTER_FLAG(CTA_IP_DST)) && - !ipv6_addr_cmp(&filter_tuple->dst.u3.in6, - &ct_tuple->dst.u3.in6)) + !ipv6_addr_equal(&filter_tuple->dst.u3.in6, + &ct_tuple->dst.u3.in6)) return 0; break; } From 46da6029bf468ce3c426cb8b4abf96976ed9d4c8 Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Thu, 10 Sep 2026 12:54:13 +0200 Subject: [PATCH 0818/2126] netfilter: conntrack: make filtering by zone discoverable Conntrack flush supports filtering by zone using CTA_ZONE, but this attribute is really hard to use from user space applications. The reason is that it is not possible to tell if it's supported or not. Older kernels silently ignore CTA_ZONE. And in that case they just happily flush all the entries from all zones breaking all the existing connections. So, applications have to infer support from the kernel version. While it works in most cases, it's not a particularly reliable or desired way to check kernel capabilities from applications that aim to be portable. There should be a better way to probe or discover features in the kernel. The CTA_FILTER interface on the other hand is simple enough to probe. We can check for NLM_F_DUMP_FILTERED in the dump to see if filtering is supported. And unknown sub-attributes in CTA_FILTER are rejected explicitly since strict validation is in use there. Let's add new CTA_FILTER_ZONE that signals that CTA_ZONE should be filtered on. It is a flag, since everything in the CTA_FILTER is a bit mask, i.e., a form of a flag. If set, it means that CTA_ZONE must be present and be used for filtering. If the flag is not set however, the filtering on CTA_ZONE will still take place to ensure backwards compatibility. So, the flag doesn't really change the filtering behavior, but it allows user space applications to properly discover support for CTA_ZONE filtering without need to rely on kernel version parsing or risk accidental flushes of the entire conntrack table, and also without modifying the kernel state. A new test variant is added to test with and without the new flag. Since the setup code is moved into a shared function, expectations replaced with assertions to bail early if the base setup fails to avoid the cascade of secondary failures that can be misleading. Error return is only for the SKIP cases. Signed-off-by: Ilya Maximets Signed-off-by: Pablo Neira Ayuso --- Documentation/netlink/specs/conntrack.yaml | 6 + .../linux/netfilter/nfnetlink_conntrack.h | 1 + net/netfilter/nf_conntrack_netlink.c | 11 ++ .../net/netfilter/conntrack_dump_flush.c | 145 ++++++++++++------ 4 files changed, 117 insertions(+), 46 deletions(-) diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index 1d163130241a..56c13705243b 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -393,6 +393,12 @@ attribute-sets: name: reply-flags type: u32 doc: bitmask of tuple fields to filter on, reply direction + - + name: zone + type: flag + doc: >- + Filter on conntrack zone id; requires the top-level zone + (``CTA_ZONE``) attribute. - name: conntrack-attrs attributes: diff --git a/include/uapi/linux/netfilter/nfnetlink_conntrack.h b/include/uapi/linux/netfilter/nfnetlink_conntrack.h index 43233af75b9d..985f9c08d3e9 100644 --- a/include/uapi/linux/netfilter/nfnetlink_conntrack.h +++ b/include/uapi/linux/netfilter/nfnetlink_conntrack.h @@ -285,6 +285,7 @@ enum ctattr_filter { CTA_FILTER_UNSPEC, CTA_FILTER_ORIG_FLAGS, CTA_FILTER_REPLY_FLAGS, + CTA_FILTER_ZONE, __CTA_FILTER_MAX }; #define CTA_FILTER_MAX (__CTA_FILTER_MAX - 1) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index e8477f792c95..4b6abe36028e 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -911,6 +911,7 @@ struct ctnetlink_filter { static const struct nla_policy cta_filter_nla_policy[CTA_FILTER_MAX + 1] = { [CTA_FILTER_ORIG_FLAGS] = NLA_POLICY_MASK(NLA_U32, CTA_FILTER_F_ALL), [CTA_FILTER_REPLY_FLAGS] = NLA_POLICY_MASK(NLA_U32, CTA_FILTER_F_ALL), + [CTA_FILTER_ZONE] = { .type = NLA_FLAG }, }; static int ctnetlink_parse_filter(const struct nlattr *attr, @@ -930,6 +931,9 @@ static int ctnetlink_parse_filter(const struct nlattr *attr, if (tb[CTA_FILTER_REPLY_FLAGS]) filter->reply_flags = nla_get_u32(tb[CTA_FILTER_REPLY_FLAGS]); + if (tb[CTA_FILTER_ZONE]) + filter->zone_filter = true; + return 0; } @@ -1006,6 +1010,7 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family) if (err) goto err_filter; + /* CTA_ZONE is allowed without CTA_FILTER_ZONE. */ if (cda[CTA_ZONE]) { err = ctnetlink_parse_zone(cda[CTA_ZONE], &filter->zone); if (err < 0) @@ -1020,6 +1025,12 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family) if (err < 0) goto err_filter; + /* CTA_FILTER_ZONE cannot be set without CTA_ZONE. */ + if (filter->zone_filter && !cda[CTA_ZONE]) { + err = -EINVAL; + goto err_filter; + } + if (filter->orig_flags) { if (!cda[CTA_TUPLE_ORIG]) { err = -EINVAL; diff --git a/tools/testing/selftests/net/netfilter/conntrack_dump_flush.c b/tools/testing/selftests/net/netfilter/conntrack_dump_flush.c index 31b8250ddc53..0c777323f4ba 100644 --- a/tools/testing/selftests/net/netfilter/conntrack_dump_flush.c +++ b/tools/testing/selftests/net/netfilter/conntrack_dump_flush.c @@ -215,7 +215,22 @@ static int count_entries(const struct nlmsghdr *nlh, void *data) return MNL_CB_OK; } -static int conntrack_count_zone(struct mnl_socket *sock, uint16_t zone) +static void put_zone_attr(struct nlmsghdr *nlh, uint16_t zone, + bool use_cta_filter) +{ + struct nlattr *nest; + + mnl_attr_put_u16(nlh, CTA_ZONE, htons(zone)); + + if (use_cta_filter) { + nest = mnl_attr_nest_start(nlh, CTA_FILTER); + mnl_attr_put(nlh, CTA_FILTER_ZONE, 0, NULL); + mnl_attr_nest_end(nlh, nest); + } +} + +static int conntrack_count_zone(struct mnl_socket *sock, uint16_t zone, + bool use_cta_filter) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; @@ -235,7 +250,7 @@ static int conntrack_count_zone(struct mnl_socket *sock, uint16_t zone) nfh->version = NFNETLINK_V0; nfh->res_id = 0; - mnl_attr_put_u16(nlh, CTA_ZONE, htons(zone)); + put_zone_attr(nlh, zone, use_cta_filter); ret = mnl_socket_sendto(sock, nlh, nlh->nlmsg_len); if (ret < 0) { @@ -261,7 +276,8 @@ static int conntrack_count_zone(struct mnl_socket *sock, uint16_t zone) return reply_counter; } -static int conntrack_flush_zone(struct mnl_socket *sock, uint16_t zone) +static int conntrack_flush_zone(struct mnl_socket *sock, uint16_t zone, + bool use_cta_filter) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; @@ -281,7 +297,7 @@ static int conntrack_flush_zone(struct mnl_socket *sock, uint16_t zone) nfh->version = NFNETLINK_V0; nfh->res_id = 0; - mnl_attr_put_u16(nlh, CTA_ZONE, htons(zone)); + put_zone_attr(nlh, zone, use_cta_filter); ret = mnl_socket_sendto(sock, nlh, nlh->nlmsg_len); if (ret < 0) { @@ -304,43 +320,40 @@ static int conntrack_flush_zone(struct mnl_socket *sock, uint16_t zone) return 0; } -FIXTURE(conntrack_dump_flush) -{ - struct mnl_socket *sock; -}; - -FIXTURE_SETUP(conntrack_dump_flush) +static int conntrack_zone_setup(struct __test_metadata *_metadata, + struct mnl_socket **sock) { struct in6_addr src, dst; int ret; - self->sock = mnl_socket_open(NETLINK_NETFILTER); - if (!self->sock) { + *sock = mnl_socket_open(NETLINK_NETFILTER); + if (!*sock) { perror("mnl_socket_open"); - SKIP(return, "cannot open netlink_netfilter socket"); + SKIP(return -1, "cannot open netlink_netfilter socket"); } - ret = mnl_socket_bind(self->sock, 0, MNL_SOCKET_AUTOPID); - EXPECT_EQ(ret, 0); + ret = mnl_socket_bind(*sock, 0, MNL_SOCKET_AUTOPID); + ASSERT_EQ(ret, 0); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID); + ret = conntrack_count_zone(*sock, TEST_ZONE_ID, false); if (ret < 0 && errno == EPERM) - SKIP(return, "Needs to be run as root"); + SKIP(return -1, "Needs to be run as root"); else if (ret < 0 && errno == EOPNOTSUPP) - SKIP(return, "Kernel does not seem to support conntrack zones"); + SKIP(return -1, + "Kernel does not seem to support conntrack zones"); - ret = conntrack_data_generate_v4(self->sock, 0xf0f0f0f0, 0xf1f1f1f1, + ret = conntrack_data_generate_v4(*sock, 0xf0f0f0f0, 0xf1f1f1f1, TEST_ZONE_ID); - EXPECT_EQ(ret, 0); - ret = conntrack_data_generate_v4(self->sock, 0xf2f2f2f2, 0xf3f3f3f3, + ASSERT_EQ(ret, 0); + ret = conntrack_data_generate_v4(*sock, 0xf2f2f2f2, 0xf3f3f3f3, TEST_ZONE_ID + 1); - EXPECT_EQ(ret, 0); - ret = conntrack_data_generate_v4(self->sock, 0xf4f4f4f4, 0xf5f5f5f5, + ASSERT_EQ(ret, 0); + ret = conntrack_data_generate_v4(*sock, 0xf4f4f4f4, 0xf5f5f5f5, TEST_ZONE_ID + 2); - EXPECT_EQ(ret, 0); - ret = conntrack_data_generate_v4(self->sock, 0xf6f6f6f6, 0xf7f7f7f7, + ASSERT_EQ(ret, 0); + ret = conntrack_data_generate_v4(*sock, 0xf6f6f6f6, 0xf7f7f7f7, NF_CT_DEFAULT_ZONE_ID); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); src = (struct in6_addr) {{ .__u6_addr32 = { @@ -358,9 +371,9 @@ FIXTURE_SETUP(conntrack_dump_flush) 0x02000000 } }}; - ret = conntrack_data_generate_v6(self->sock, src, dst, + ret = conntrack_data_generate_v6(*sock, src, dst, TEST_ZONE_ID); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); src = (struct in6_addr) {{ .__u6_addr32 = { 0xb80d0120, @@ -377,9 +390,9 @@ FIXTURE_SETUP(conntrack_dump_flush) 0x04000000 } }}; - ret = conntrack_data_generate_v6(self->sock, src, dst, + ret = conntrack_data_generate_v6(*sock, src, dst, TEST_ZONE_ID + 1); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); src = (struct in6_addr) {{ .__u6_addr32 = { 0xb80d0120, @@ -396,9 +409,9 @@ FIXTURE_SETUP(conntrack_dump_flush) 0x06000000 } }}; - ret = conntrack_data_generate_v6(self->sock, src, dst, + ret = conntrack_data_generate_v6(*sock, src, dst, TEST_ZONE_ID + 2); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); src = (struct in6_addr) {{ .__u6_addr32 = { @@ -416,14 +429,51 @@ FIXTURE_SETUP(conntrack_dump_flush) 0x08000000 } }}; - ret = conntrack_data_generate_v6(self->sock, src, dst, + ret = conntrack_data_generate_v6(*sock, src, dst, NF_CT_DEFAULT_ZONE_ID); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID); + return 0; +} + +FIXTURE(conntrack_dump_flush) +{ + struct mnl_socket *sock; +}; + +FIXTURE_VARIANT(conntrack_dump_flush) +{ + bool use_cta_filter; +}; + +FIXTURE_VARIANT_ADD(conntrack_dump_flush, cta_zone) +{ + .use_cta_filter = false, +}; + +FIXTURE_VARIANT_ADD(conntrack_dump_flush, cta_filter) +{ + .use_cta_filter = true, +}; + +FIXTURE_SETUP(conntrack_dump_flush) +{ + int ret; + + if (conntrack_zone_setup(_metadata, &self->sock)) + return; + + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID, false); EXPECT_GE(ret, 2); if (ret > 2) SKIP(return, "kernel does not support filtering by zone"); + + if (variant->use_cta_filter) { + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID, true); + if (ret < 0 && errno == EINVAL) + SKIP(return, "kernel does not support CTA_FILTER_ZONE"); + ASSERT_GE(ret, 0); + } } FIXTURE_TEARDOWN(conntrack_dump_flush) @@ -434,39 +484,42 @@ TEST_F(conntrack_dump_flush, test_dump_by_zone) { int ret; - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID, + variant->use_cta_filter); EXPECT_EQ(ret, 2); } TEST_F(conntrack_dump_flush, test_flush_by_zone) { + bool filter = variant->use_cta_filter; int ret; - ret = conntrack_flush_zone(self->sock, TEST_ZONE_ID); + ret = conntrack_flush_zone(self->sock, TEST_ZONE_ID, filter); EXPECT_EQ(ret, 0); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID, filter); EXPECT_EQ(ret, 0); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 1); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 1, filter); EXPECT_EQ(ret, 2); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 2); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 2, filter); EXPECT_EQ(ret, 2); - ret = conntrack_count_zone(self->sock, NF_CT_DEFAULT_ZONE_ID); + ret = conntrack_count_zone(self->sock, NF_CT_DEFAULT_ZONE_ID, filter); EXPECT_EQ(ret, 2); } TEST_F(conntrack_dump_flush, test_flush_by_zone_default) { + bool filter = variant->use_cta_filter; int ret; - ret = conntrack_flush_zone(self->sock, NF_CT_DEFAULT_ZONE_ID); + ret = conntrack_flush_zone(self->sock, NF_CT_DEFAULT_ZONE_ID, filter); EXPECT_EQ(ret, 0); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID, filter); EXPECT_EQ(ret, 2); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 1); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 1, filter); EXPECT_EQ(ret, 2); - ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 2); + ret = conntrack_count_zone(self->sock, TEST_ZONE_ID + 2, filter); EXPECT_EQ(ret, 2); - ret = conntrack_count_zone(self->sock, NF_CT_DEFAULT_ZONE_ID); + ret = conntrack_count_zone(self->sock, NF_CT_DEFAULT_ZONE_ID, filter); EXPECT_EQ(ret, 0); } From 53e0b15a0ee1a4ce6fda4225c3cc2b844a984149 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 21 Sep 2026 14:40:50 +0200 Subject: [PATCH 0819/2126] wifi: mac80211: add key flags to debugfs Since there are two sets of key flags, one for the driver and one internal to mac80211, add the first set in debugfs as well. This will be used by hwsim tests to determine if a key is pairwise or not, since the next changes will make mac80211 use only per-STA GTKs. Link: https://patch.msgid.link/20260921144048.641cb1492f2e.I3a7d6912def9ba2623b41cc672704cbe3beb0bf3@changeid Signed-off-by: Johannes Berg --- net/mac80211/debugfs_key.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c index 117f58af5ff9..79ae3552c55b 100644 --- a/net/mac80211/debugfs_key.c +++ b/net/mac80211/debugfs_key.c @@ -4,7 +4,7 @@ * Copyright (c) 2006 Jiri Benc * Copyright 2007 Johannes Berg * Copyright (C) 2015 Intel Deutschland GmbH - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2023, 2026 Intel Corporation */ #include @@ -42,9 +42,10 @@ static const struct debugfs_short_fops key_ ##name## _ops = { \ KEY_READ_##format(name) \ KEY_OPS(name) -#define KEY_CONF_READ(name, format_string) \ - KEY_READ(conf_##name, conf.name, format_string) -#define KEY_CONF_READ_D(name) KEY_CONF_READ(name, "%d\n") +#define KEY_CONF_READ(name, val, format_string) \ + KEY_READ(conf_##name, conf.val, format_string) +#define KEY_CONF_READ_D(name, val) KEY_CONF_READ(name, val, "%d\n") +#define KEY_CONF_READ_X(name, val) KEY_CONF_READ(name, val, "0x%x\n") #define KEY_CONF_OPS(name) \ static const struct debugfs_short_fops key_ ##name## _ops = { \ @@ -53,12 +54,16 @@ static const struct debugfs_short_fops key_ ##name## _ops = { \ } #define KEY_CONF_FILE(name, format) \ - KEY_CONF_READ_##format(name) \ + KEY_CONF_READ_##format(name, name) \ + KEY_CONF_OPS(name) +#define KEY_CONF_FILE_NAMED(name, val, format) \ + KEY_CONF_READ_##format(name, val) \ KEY_CONF_OPS(name) KEY_CONF_FILE(keylen, D); KEY_CONF_FILE(keyidx, D); KEY_CONF_FILE(hw_key_idx, D); +KEY_CONF_FILE_NAMED(conf_flags, flags, X); KEY_FILE(flags, X); KEY_READ(ifindex, sdata->name, "%s\n"); KEY_OPS(ifindex); @@ -356,6 +361,7 @@ void ieee80211_debugfs_key_add(struct ieee80211_key *key) DEBUGFS_ADD(mic_failures); DEBUGFS_ADD(key); DEBUGFS_ADD(ifindex); + DEBUGFS_ADD(conf_flags); }; void ieee80211_debugfs_key_remove(struct ieee80211_key *key) From 325bb57ca9606858821102ffd99af4838bf3e846 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 14:40:51 +0200 Subject: [PATCH 0820/2126] wifi: mac80211: add key link_id to debugfs Add the link_id to the debugfs. This is useful for hwsim tests to validate the per-link keys in multi-link tests. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921144048.fee6216d4a22.I262f6ee5af944970707e1d4e6607020fcfe6ba89@changeid Signed-off-by: Johannes Berg --- net/mac80211/debugfs_key.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c index 79ae3552c55b..3a4f8e9e54dc 100644 --- a/net/mac80211/debugfs_key.c +++ b/net/mac80211/debugfs_key.c @@ -65,6 +65,7 @@ KEY_CONF_FILE(keyidx, D); KEY_CONF_FILE(hw_key_idx, D); KEY_CONF_FILE_NAMED(conf_flags, flags, X); KEY_FILE(flags, X); +KEY_CONF_FILE(link_id, D); KEY_READ(ifindex, sdata->name, "%s\n"); KEY_OPS(ifindex); @@ -362,6 +363,7 @@ void ieee80211_debugfs_key_add(struct ieee80211_key *key) DEBUGFS_ADD(key); DEBUGFS_ADD(ifindex); DEBUGFS_ADD(conf_flags); + DEBUGFS_ADD(link_id); }; void ieee80211_debugfs_key_remove(struct ieee80211_key *key) From 3191dfbf0779337292526bacb53ac442650099da Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 14:40:52 +0200 Subject: [PATCH 0821/2126] wifi: cfg80211: add Control Integrity Protocol (CIP) APIs The Control Integrity Protocol consists of a set of capabilities for the MIC padding as well as a new CIGTK that can be installed. The CIGTK uses a fixed GMAC-256 cipher for which no RSN extension is defined as it is bound to the pairwise cipher being GCMP-256. The CIGTK uses the key index 0 and 1, making it necessary to add a new key type for it. Add a new CIP feature flag and attributes for CIP Capabilities and enabling the feature for stations and the association. Also extend the cfg80211 API to pass the key type rather than a single pairwise boolean. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921144048.aa7939493375.I49c0be0a1b05d625cc307e9bdd13c32a6c18667f@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/ath6kl/cfg80211.c | 10 +- drivers/net/wireless/ath/wil6210/cfg80211.c | 13 +- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 11 +- drivers/net/wireless/marvell/libertas/cfg.c | 6 +- .../net/wireless/marvell/mwifiex/cfg80211.c | 12 +- .../wireless/microchip/wilc1000/cfg80211.c | 13 +- drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 11 +- .../net/wireless/quantenna/qtnfmac/cfg80211.c | 8 +- .../staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 9 +- include/net/cfg80211.h | 19 ++- include/uapi/linux/nl80211.h | 14 ++ net/mac80211/cfg.c | 19 ++- net/wireless/core.h | 7 +- net/wireless/ibss.c | 3 +- net/wireless/nl80211.c | 124 ++++++++++++++---- net/wireless/rdev-ops.h | 23 ++-- net/wireless/sme.c | 10 +- net/wireless/trace.h | 37 +++--- net/wireless/util.c | 40 +++++- net/wireless/wext-compat.c | 8 +- 20 files changed, 295 insertions(+), 102 deletions(-) diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c index 8bbe554a9b36..a9a35476fecd 100644 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c @@ -1130,13 +1130,15 @@ void ath6kl_cfg80211_ch_switch_notify(struct ath6kl_vif *vif, int freq, } static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct ath6kl *ar = ath6kl_priv(wdev->netdev); struct ath6kl_vif *vif = netdev_priv(wdev->netdev); struct ath6kl_key *key = NULL; + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; int seq_len; u8 key_usage; u8 key_type; @@ -1255,7 +1257,8 @@ static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wde } static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { struct ath6kl *ar = ath6kl_priv(wdev->netdev); @@ -1285,7 +1288,8 @@ static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wde } static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, void *cookie, void (*callback) (void *cookie, struct key_params *)) diff --git a/drivers/net/wireless/ath/wil6210/cfg80211.c b/drivers/net/wireless/ath/wil6210/cfg80211.c index 9ac33d827f80..bf060281c9a2 100644 --- a/drivers/net/wireless/ath/wil6210/cfg80211.c +++ b/drivers/net/wireless/ath/wil6210/cfg80211.c @@ -1620,11 +1620,13 @@ static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage, static int wil_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, + u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { int rc; + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; struct wil6210_priv *wil = wiphy_to_wil(wiphy); struct wil6210_vif *vif = wdev_to_vif(wil, wdev); enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise); @@ -1695,12 +1697,14 @@ static int wil_cfg80211_add_key(struct wiphy *wiphy, static int wil_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, + u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { struct wil6210_priv *wil = wiphy_to_wil(wiphy); struct wil6210_vif *vif = wdev_to_vif(wil, wdev); - enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise); + enum wmi_key_usage key_usage = + wil_detect_key_usage(wdev, type == NL80211_KEYTYPE_PAIRWISE); struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid, key_usage, mac_addr); @@ -2071,7 +2075,8 @@ void wil_cfg80211_ap_recovery(struct wil6210_priv *wil) key_params.seq_len = IEEE80211_GCMP_PN_LEN; rc = wil_cfg80211_add_key(wiphy, vif_to_wdev(vif), -1, vif->gtk_index, - false, NULL, &key_params); + NL80211_KEYTYPE_PAIRWISE, + NULL, &key_params); if (rc) wil_err(wil, "vif %d recovery add key failed (%d)\n", i, rc); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 9d8ce7bb046e..ede76a9e12c8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -2802,7 +2802,8 @@ done: static s32 brcmf_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_idx, bool pairwise, + int link_id, u8 key_idx, + enum nl80211_key_type type, const u8 *mac_addr) { struct brcmf_if *ifp = netdev_priv(wdev->netdev); @@ -2840,7 +2841,8 @@ brcmf_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, static s32 brcmf_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_idx, bool pairwise, + int link_id, u8 key_idx, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); @@ -2866,7 +2868,7 @@ brcmf_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, if (params->key_len == 0) return brcmf_cfg80211_del_key(wiphy, wdev, -1, key_idx, - pairwise, mac_addr); + type, mac_addr); if (params->key_len > sizeof(key->data)) { bphy_err(drvr, "Too long key length (%u)\n", params->key_len); @@ -2962,7 +2964,8 @@ done: static s32 brcmf_cfg80211_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_idx, bool pairwise, + int link_id, u8 key_idx, + enum nl80211_key_type type, const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *params)) diff --git a/drivers/net/wireless/marvell/libertas/cfg.c b/drivers/net/wireless/marvell/libertas/cfg.c index 72c92f72469d..e015cfa1950c 100644 --- a/drivers/net/wireless/marvell/libertas/cfg.c +++ b/drivers/net/wireless/marvell/libertas/cfg.c @@ -1508,7 +1508,8 @@ static int lbs_cfg_set_default_key(struct wiphy *wiphy, static int lbs_cfg_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 idx, bool pairwise, + int link_id, u8 idx, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct lbs_private *priv = wiphy_priv(wiphy); @@ -1569,7 +1570,8 @@ static int lbs_cfg_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, static int lbs_cfg_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c index d7f20ec0bb3e..e6e7739c4a3b 100644 --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c @@ -142,12 +142,14 @@ static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy) */ static int mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - const u8 *peer_mac = pairwise ? mac_addr : bc_mac; + const u8 *peer_mac = + (type == NL80211_KEYTYPE_PAIRWISE) ? mac_addr : bc_mac; if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) { mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n"); @@ -480,13 +482,15 @@ mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev, */ static int mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); struct mwifiex_wep_key *wep_key; static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - const u8 *peer_mac = pairwise ? mac_addr : bc_mac; + const u8 *peer_mac = + (type == NL80211_KEYTYPE_PAIRWISE) ? mac_addr : bc_mac; if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP && (params->cipher == WLAN_CIPHER_SUITE_WEP40 || diff --git a/drivers/net/wireless/microchip/wilc1000/cfg80211.c b/drivers/net/wireless/microchip/wilc1000/cfg80211.c index 9ad21d41e999..3db290875ff4 100644 --- a/drivers/net/wireless/microchip/wilc1000/cfg80211.c +++ b/drivers/net/wireless/microchip/wilc1000/cfg80211.c @@ -535,10 +535,13 @@ static int wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key *key_info, } static int add_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr, + u8 key_index, + enum nl80211_key_type type, + const u8 *mac_addr, struct key_params *params) { + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; int ret = 0, keylen = params->key_len; const u8 *rx_mic = NULL; const u8 *tx_mic = NULL; @@ -641,9 +644,10 @@ static int add_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, static int del_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, u8 key_index, - bool pairwise, + enum nl80211_key_type type, const u8 *mac_addr) { + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; struct wilc_vif *vif = netdev_priv(wdev->netdev); struct wilc_priv *priv = &vif->priv; @@ -681,10 +685,11 @@ static int del_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, } static int get_key(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr, - void *cookie, + u8 key_index, enum nl80211_key_type type, + const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *)) { + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; struct wilc_vif *vif = netdev_priv(wdev->netdev); struct wilc_priv *priv = &vif->priv; struct key_params key_params; diff --git a/drivers/net/wireless/nxp/nxpwifi/cfg80211.c b/drivers/net/wireless/nxp/nxpwifi/cfg80211.c index 86304ea3331c..8805439c0b4b 100644 --- a/drivers/net/wireless/nxp/nxpwifi/cfg80211.c +++ b/drivers/net/wireless/nxp/nxpwifi/cfg80211.c @@ -99,12 +99,14 @@ static void *nxpwifi_cfg80211_get_adapter(struct wiphy *wiphy) /* cfg80211 operation handler to delete a network key. */ static int nxpwifi_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev); static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - const u8 *peer_mac = pairwise ? mac_addr : bc_mac; + const u8 *peer_mac = + (type == NL80211_KEYTYPE_PAIRWISE) ? mac_addr : bc_mac; int ret; ret = nxpwifi_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1); @@ -426,7 +428,8 @@ nxpwifi_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev, /* cfg80211 handler for adding an 802.11 encryption key. */ static int nxpwifi_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev); @@ -436,7 +439,7 @@ nxpwifi_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, int ret; eth_broadcast_addr(bc_mac); - peer_mac = pairwise ? mac_addr : bc_mac; + peer_mac = (type == NL80211_KEYTYPE_PAIRWISE) ? mac_addr : bc_mac; if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP && (params->cipher == WLAN_CIPHER_SUITE_WEP40 || diff --git a/drivers/net/wireless/quantenna/qtnfmac/cfg80211.c b/drivers/net/wireless/quantenna/qtnfmac/cfg80211.c index 45e2b7ae9633..d9c84d5ce254 100644 --- a/drivers/net/wireless/quantenna/qtnfmac/cfg80211.c +++ b/drivers/net/wireless/quantenna/qtnfmac/cfg80211.c @@ -531,10 +531,12 @@ qtnf_dump_station(struct wiphy *wiphy, struct wireless_dev *wdev, } static int qtnf_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev); + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; int ret; ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params); @@ -547,10 +549,12 @@ static int qtnf_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, } static int qtnf_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev); + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; int ret; ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr); diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c index 3468d4114f60..be233a471b43 100644 --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c @@ -825,7 +825,8 @@ exit: } static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { char *alg_name; @@ -904,7 +905,8 @@ addkey_end: } static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params*)) @@ -913,7 +915,8 @@ static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, } static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr) { struct adapter *padapter = rtw_netdev_priv(wdev->netdev); diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 9aa7d2d4a184..1ef5f85a9376 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -1821,6 +1821,8 @@ struct sta_txpwr { * @s1g_capa: S1G capabilities of station * @uhr_capa: UHR capabilities of the station * @uhr_capa_len: the length of the UHR capabilities + * @cip_cap_set: If CIP capabilities are present, required for CIP stations + * @cip_cap: CIP capabilities of station */ struct link_station_parameters { const u8 *mld_mac; @@ -1842,6 +1844,8 @@ struct link_station_parameters { const struct ieee80211_s1g_cap *s1g_capa; const struct ieee80211_uhr_cap *uhr_capa; u8 uhr_capa_len; + bool cip_cap_set; + u8 cip_cap; }; /** @@ -3402,6 +3406,7 @@ struct cfg80211_ml_reconf_req { * flag is not set. * @ASSOC_REQ_SPP_AMSDU: SPP A-MSDUs will be used on this connection (if any) * @ASSOC_REQ_DISABLE_UHR: Disable UHR + * @ASSOC_REQ_CIP: Enable Control Integrity Protocol */ enum cfg80211_assoc_req_flags { ASSOC_REQ_DISABLE_HT = BIT(0), @@ -3413,6 +3418,7 @@ enum cfg80211_assoc_req_flags { CONNECT_REQ_MLO_SUPPORT = BIT(6), ASSOC_REQ_SPP_AMSDU = BIT(7), ASSOC_REQ_DISABLE_UHR = BIT(8), + ASSOC_REQ_CIP = BIT(9), }; /** @@ -5304,14 +5310,17 @@ struct cfg80211_ops { unsigned int link_id); int (*add_key)(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params); int (*get_key)(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params*)); int (*del_key)(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, + int link_id, u8 key_index, + enum nl80211_key_type type, const u8 *mac_addr); int (*set_default_key)(struct wiphy *wiphy, struct net_device *netdev, int link_id, @@ -6045,6 +6054,8 @@ struct wiphy_vendor_command { * @eml_capabilities: EML capabilities (for MLO) * @mld_capa_and_ops: MLD capabilities and operations (for MLO) * @ext_mld_capa_and_ops: Extended MLD capabilities and operations (for MLO) + * @cip_supported: CIP is supported and the capabilities are valid + * @cip_capabilities: CIP Capabilities element containing the MIC padding delay */ struct wiphy_iftype_ext_capab { enum nl80211_iftype iftype; @@ -6054,6 +6065,8 @@ struct wiphy_iftype_ext_capab { u16 eml_capabilities; u16 mld_capa_and_ops; u16 ext_mld_capa_and_ops; + bool cip_supported; + u8 cip_capabilities; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 9a2ccb8d66b8..843d1dbb725d 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -3190,6 +3190,11 @@ enum nl80211_commands { * known station to transmit a frame. This is relevant to know whether * MLD address translation happened or to disable it when sending a frame. * + * @NL80211_ATTR_ASSOC_CIP: Enable Control Integrity Protocol for the + * association + * @NL80211_ATTR_CIP_CAPABILITIES: The Control Integrity Protocol for the + * station. + * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -3792,6 +3797,9 @@ enum nl80211_attrs { NL80211_ATTR_FRAME_NO_STA, + NL80211_ATTR_ASSOC_CIP, + NL80211_ATTR_CIP_CAPABILITIES, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, @@ -3942,6 +3950,7 @@ enum nl80211_iftype { * that support %NL80211_FEATURE_FULL_AP_CLIENT_STATE to transition a * previously added station into associated state * @NL80211_STA_FLAG_SPP_AMSDU: station supports SPP A-MSDUs + * @NL80211_STA_FLAG_CIP: station has Control Integrity Protocol (CIP) enabled * @NL80211_STA_FLAG_MAX: highest station flag number currently defined * @__NL80211_STA_FLAG_AFTER_LAST: internal use */ @@ -3955,6 +3964,7 @@ enum nl80211_sta_flags { NL80211_STA_FLAG_TDLS_PEER, NL80211_STA_FLAG_ASSOCIATED, NL80211_STA_FLAG_SPP_AMSDU, + NL80211_STA_FLAG_CIP, /* keep last */ __NL80211_STA_FLAG_AFTER_LAST, @@ -5786,12 +5796,16 @@ enum nl80211_auth_type { * @NL80211_KEYTYPE_GROUP: Group (broadcast/multicast) key * @NL80211_KEYTYPE_PAIRWISE: Pairwise (unicast/individual) key * @NL80211_KEYTYPE_PEERKEY: PeerKey (DLS) + * @NL80211_KEYTYPE_CIGTK: Control Integrity Group Temporal Key + * The cipher is GMAC-256 but passed as GCMP-256, + * same as the pairwise key when used for CIP. * @NUM_NL80211_KEYTYPES: number of defined key types */ enum nl80211_key_type { NL80211_KEYTYPE_GROUP, NL80211_KEYTYPE_PAIRWISE, NL80211_KEYTYPE_PEERKEY, + NL80211_KEYTYPE_CIGTK, NUM_NL80211_KEYTYPES }; diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index a1753335eb9d..4c3a432b44ce 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -615,12 +615,14 @@ static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata, } static int ieee80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_idx, bool pairwise, + int link_id, u8 key_idx, + enum nl80211_key_type type, const u8 *mac_addr, struct key_params *params) { struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); struct ieee80211_link_data *link = ieee80211_link_or_deflink(sdata, link_id, false); + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; struct ieee80211_local *local = sdata->local; struct sta_info *sta = NULL; struct ieee80211_key *key; @@ -741,10 +743,12 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, static struct ieee80211_key * ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, - u8 key_idx, bool pairwise, const u8 *mac_addr) + u8 key_idx, enum nl80211_key_type type, + const u8 *mac_addr) { struct ieee80211_local *local __maybe_unused = sdata->local; struct ieee80211_link_data *link = &sdata->deflink; + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; struct ieee80211_key *key; if (link_id >= 0) { @@ -799,8 +803,8 @@ ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, } static int ieee80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_idx, bool pairwise, - const u8 *mac_addr) + int link_id, u8 key_idx, + enum nl80211_key_type type, const u8 *mac_addr) { struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); struct ieee80211_local *local = sdata->local; @@ -808,7 +812,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, lockdep_assert_wiphy(local->hw.wiphy); - key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr); + key = ieee80211_lookup_key(sdata, link_id, key_idx, type, mac_addr); if (!key) return -ENOENT; @@ -818,7 +822,8 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, } static int ieee80211_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_idx, bool pairwise, + int link_id, u8 key_idx, + enum nl80211_key_type type, const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *params)) @@ -837,7 +842,7 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, rcu_read_lock(); - key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr); + key = ieee80211_lookup_key(sdata, link_id, key_idx, type, mac_addr); if (!key) goto out; diff --git a/net/wireless/core.h b/net/wireless/core.h index 6138d207caf4..de23518451ca 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -453,13 +453,16 @@ void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev); /* internal helpers */ bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher); +bool cfg80211_cigtk_supported(struct wireless_dev *wdev, + struct genl_info *info); bool cfg80211_valid_key_idx(struct wireless_dev *wdev, - int key_idx, bool pairwise, + int key_idx, enum nl80211_key_type type, const u8 *mac_addr); int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, struct key_params *params, int key_idx, - bool pairwise, const u8 *mac_addr); + enum nl80211_key_type type, + const u8 *mac_addr); void __cfg80211_scan_done(struct wiphy *wiphy, struct wiphy_work *wk); void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool send_message); diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c index 7f6779d326b8..81dff0bace28 100644 --- a/net/wireless/ibss.c +++ b/net/wireless/ibss.c @@ -176,7 +176,8 @@ void cfg80211_clear_ibss(struct net_device *dev, bool nowext) */ if (rdev->ops->del_key) for (i = 0; i < 6; i++) - rdev_del_key(rdev, wdev, -1, i, false, NULL); + rdev_del_key(rdev, wdev, -1, i, NL80211_KEYTYPE_GROUP, + NULL); if (wdev->u.ibss.current_bss) { cfg80211_unhold_bss(wdev->u.ibss.current_bss); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 85c010793c53..ef241b6da245 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1098,6 +1098,8 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range), [NL80211_ATTR_STA_DUMP_LINK_STATS] = { .type = NLA_FLAG }, [NL80211_ATTR_FRAME_NO_STA] = { .type = NLA_FLAG }, + [NL80211_ATTR_ASSOC_CIP] = { .type = NLA_FLAG }, + [NL80211_ATTR_CIP_CAPABILITIES] = { .type = NLA_U8 }, }; /* policy for the key attributes */ @@ -1763,6 +1765,11 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) GENL_SET_ERR_MSG(info, "def key idx not 0-3"); return -EINVAL; } + } else if (k->type == NL80211_KEYTYPE_CIGTK) { + if (k->idx < 0 || k->idx > 1) { + GENL_SET_ERR_MSG(info, "CIGTK idx not 0-1"); + return -EINVAL; + } } else { if (k->idx < 0 || k->idx > 7) { GENL_SET_ERR_MSG(info, "key idx not 0-7"); @@ -1827,7 +1834,9 @@ nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, } else if (parse.defmgmt) goto error; err = cfg80211_validate_key_settings(rdev, wdev, &parse.p, - parse.idx, false, NULL); + parse.idx, + NL80211_KEYTYPE_GROUP, + NULL); if (err) goto error; if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && @@ -3617,6 +3626,11 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, NL80211_ATTR_EXT_MLD_CAPA_AND_OPS, capab->ext_mld_capa_and_ops)) goto nla_put_failure; + if (capab->cip_supported && + nla_put_u8(msg, + NL80211_ATTR_CIP_CAPABILITIES, + capab->cip_capabilities)) + goto nla_put_failure; nla_nest_end(msg, nested_ext_capab); if (state->split) @@ -5373,6 +5387,7 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) struct wireless_dev *wdev = info->user_ptr[1]; u8 key_idx = 0; const u8 *mac_addr = NULL; + enum nl80211_key_type type; bool pairwise; struct get_key_cookie cookie = { .error = 0, @@ -5405,19 +5420,24 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); pairwise = !!mac_addr; + type = pairwise ? NL80211_KEYTYPE_PAIRWISE : NL80211_KEYTYPE_GROUP; if (info->attrs[NL80211_ATTR_KEY_TYPE]) { - u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); + type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); - if (kt != NL80211_KEYTYPE_GROUP && - kt != NL80211_KEYTYPE_PAIRWISE) + if (type != NL80211_KEYTYPE_GROUP && + type != NL80211_KEYTYPE_PAIRWISE && + type != NL80211_KEYTYPE_CIGTK) { + GENL_SET_ERR_MSG(info, "key type not pairwise, group or CIGTK"); return -EINVAL; - pairwise = kt == NL80211_KEYTYPE_PAIRWISE; + } + + pairwise = type == NL80211_KEYTYPE_PAIRWISE; } if (!rdev->ops->get_key) return -EOPNOTSUPP; - if (!cfg80211_valid_key_idx(wdev, key_idx, pairwise, mac_addr)) + if (!cfg80211_valid_key_idx(wdev, key_idx, type, mac_addr)) return -ENOENT; msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); @@ -5446,7 +5466,7 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) if (err) goto free_msg; - err = rdev_get_key(rdev, wdev, link_id, key_idx, pairwise, mac_addr, + err = rdev_get_key(rdev, wdev, link_id, key_idx, type, mac_addr, &cookie, get_key_callback); if (err) @@ -5605,8 +5625,9 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) /* for now */ if (key.type != NL80211_KEYTYPE_PAIRWISE && - key.type != NL80211_KEYTYPE_GROUP) { - GENL_SET_ERR_MSG(info, "key type not pairwise or group"); + key.type != NL80211_KEYTYPE_GROUP && + key.type != NL80211_KEYTYPE_CIGTK) { + GENL_SET_ERR_MSG(info, "key type not pairwise, group or CIGTK"); return -EINVAL; } @@ -5618,8 +5639,7 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) return -EOPNOTSUPP; if (cfg80211_validate_key_settings(rdev, wdev, &key.p, key.idx, - key.type == NL80211_KEYTYPE_PAIRWISE, - mac_addr)) { + key.type, mac_addr)) { GENL_SET_ERR_MSG(info, "key setting validation failed"); return -EINVAL; } @@ -5633,8 +5653,7 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) key.type == NL80211_KEYTYPE_PAIRWISE); if (!err) { - err = rdev_add_key(rdev, wdev, link_id, key.idx, - key.type == NL80211_KEYTYPE_PAIRWISE, + err = rdev_add_key(rdev, wdev, link_id, key.idx, key.type, mac_addr, &key.p); if (err) GENL_SET_ERR_MSG(info, "key addition failed"); @@ -5668,12 +5687,13 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) /* for now */ if (key.type != NL80211_KEYTYPE_PAIRWISE && - key.type != NL80211_KEYTYPE_GROUP) + key.type != NL80211_KEYTYPE_GROUP && + key.type != NL80211_KEYTYPE_CIGTK) { + GENL_SET_ERR_MSG(info, "key type not pairwise, group or CIGTK"); return -EINVAL; + } - if (!cfg80211_valid_key_idx(wdev, key.idx, - key.type == NL80211_KEYTYPE_PAIRWISE, - mac_addr)) + if (!cfg80211_valid_key_idx(wdev, key.idx, key.type, mac_addr)) return -EINVAL; if (!rdev->ops->del_key) @@ -5687,8 +5707,7 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) if (!err) err = rdev_del_key(rdev, wdev, link_id, key.idx, - key.type == NL80211_KEYTYPE_PAIRWISE, - mac_addr); + key.type, mac_addr); #ifdef CONFIG_CFG80211_WEXT if (!err) { @@ -8819,7 +8838,7 @@ int cfg80211_check_station_change(struct wiphy *wiphy, return -EINVAL; /* When you run into this, adjust the code below for the new flag */ - BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 8); + BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 9); switch (statype) { case CFG80211_STA_MESH_PEER_KERNEL: @@ -8913,7 +8932,8 @@ int cfg80211_check_station_change(struct wiphy *wiphy, BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | BIT(NL80211_STA_FLAG_WME) | BIT(NL80211_STA_FLAG_MFP) | - BIT(NL80211_STA_FLAG_SPP_AMSDU))) + BIT(NL80211_STA_FLAG_SPP_AMSDU) | + BIT(NL80211_STA_FLAG_CIP))) return -EINVAL; /* but authenticated/associated only if driver handles it */ @@ -9298,6 +9318,22 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) nla_get_u16(info->attrs[NL80211_ATTR_EML_CAPABILITY]); } + if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_CIP) && + params.sta_flags_set & BIT(NL80211_STA_FLAG_CIP)) { + if (!cfg80211_cigtk_supported(wdev, info)) + return -EINVAL; + + /* CIP capabilities are required if CIP is being enabled */ + if (info->attrs[NL80211_ATTR_CIP_CAPABILITIES]) { + params.link_sta_params.cip_cap_set = true; + params.link_sta_params.cip_cap = + nla_get_u8(info->attrs[NL80211_ATTR_CIP_CAPABILITIES]); + } else { + GENL_SET_ERR_MSG(info, "No CIP capabilities provided"); + return -EINVAL; + } + } + if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) params.airtime_weight = nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); @@ -9507,6 +9543,22 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) nla_get_u16(info->attrs[NL80211_ATTR_EML_CAPABILITY]); } + if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_CIP) && + params.sta_flags_set & BIT(NL80211_STA_FLAG_CIP)) { + if (!cfg80211_cigtk_supported(wdev, info)) + return -EINVAL; + + /* CIP capabilities are required if CIP is enabled */ + if (info->attrs[NL80211_ATTR_CIP_CAPABILITIES]) { + params.link_sta_params.cip_cap_set = true; + params.link_sta_params.cip_cap = + nla_get_u8(info->attrs[NL80211_ATTR_CIP_CAPABILITIES]); + } else { + GENL_SET_ERR_MSG(info, "No CIP capabilities provided"); + return -EINVAL; + } + } + if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) params.link_sta_params.he_6ghz_capa = nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); @@ -9584,7 +9636,7 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) return -EINVAL; /* When you run into this, adjust the code below for the new flag */ - BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 8); + BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 9); switch (wdev->iftype) { case NL80211_IFTYPE_AP: @@ -9617,6 +9669,10 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) params.sta_flags_mask & BIT(NL80211_STA_FLAG_SPP_AMSDU)) return -EINVAL; + if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_CIP) && + !cfg80211_cigtk_supported(wdev, info)) + return -EINVAL; + /* Older userspace, or userspace wanting to be compatible with * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth * and assoc flags in the mask, but assumes the station will be @@ -13339,6 +13395,13 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) req.flags |= ASSOC_REQ_SPP_AMSDU; } + if (nla_get_flag(info->attrs[NL80211_ATTR_ASSOC_CIP])) { + if (!cfg80211_cigtk_supported(dev->ieee80211_ptr, info)) + return -EINVAL; + + req.flags |= ASSOC_REQ_CIP; + } + req.link_id = nl80211_link_id_or_invalid(info->attrs); if (info->attrs[NL80211_ATTR_MLO_LINKS]) { @@ -19216,6 +19279,23 @@ nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info, params.he_6ghz_capa = nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); + if (info->attrs[NL80211_ATTR_CIP_CAPABILITIES]) { + struct wireless_dev *wdev = dev->ieee80211_ptr; + + if (!cfg80211_cigtk_supported(wdev, info)) + return -EINVAL; + + params.cip_cap_set = true; + params.cip_cap = + nla_get_u8(info->attrs[NL80211_ATTR_CIP_CAPABILITIES]); + + /* Only permit CIP capabilities when adding link stations */ + if (!add) { + GENL_SET_ERR_MSG(info, "Cannot modify CIP capabilities"); + return -EINVAL; + } + } + if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { params.opmode_notif_used = true; params.opmode_notif = diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index adcfd0278da3..0d4bbe0e5c5d 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -78,42 +78,43 @@ rdev_change_virtual_intf(struct cfg80211_registered_device *rdev, static inline int rdev_add_key(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr, - struct key_params *params) + u8 key_index, enum nl80211_key_type type, + const u8 *mac_addr, struct key_params *params) { int ret; - trace_rdev_add_key(&rdev->wiphy, wdev, link_id, key_index, pairwise, + trace_rdev_add_key(&rdev->wiphy, wdev, link_id, key_index, type, mac_addr, params->mode); ret = rdev->ops->add_key(&rdev->wiphy, wdev, link_id, key_index, - pairwise, mac_addr, params); + type, mac_addr, params); trace_rdev_return_int(&rdev->wiphy, ret); return ret; } static inline int rdev_get_key(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, const u8 *mac_addr, - void *cookie, + int link_id, u8 key_index, enum nl80211_key_type type, + const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params*)) { int ret; - trace_rdev_get_key(&rdev->wiphy, wdev, link_id, key_index, pairwise, + trace_rdev_get_key(&rdev->wiphy, wdev, link_id, key_index, type, mac_addr); ret = rdev->ops->get_key(&rdev->wiphy, wdev, link_id, key_index, - pairwise, mac_addr, cookie, callback); + type, mac_addr, cookie, callback); trace_rdev_return_int(&rdev->wiphy, ret); return ret; } static inline int rdev_del_key(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr) + u8 key_index, enum nl80211_key_type type, + const u8 *mac_addr) { int ret; - trace_rdev_del_key(&rdev->wiphy, wdev, link_id, key_index, pairwise, + trace_rdev_del_key(&rdev->wiphy, wdev, link_id, key_index, type, mac_addr); ret = rdev->ops->del_key(&rdev->wiphy, wdev, link_id, key_index, - pairwise, mac_addr); + type, mac_addr); trace_rdev_return_int(&rdev->wiphy, ret); return ret; } diff --git a/net/wireless/sme.c b/net/wireless/sme.c index 2a719b5c487e..458f72d8351a 100644 --- a/net/wireless/sme.c +++ b/net/wireless/sme.c @@ -1387,7 +1387,15 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) max_key_idx = 7; for (i = 0; i <= max_key_idx; i++) - rdev_del_key(rdev, wdev, -1, i, false, NULL); + rdev_del_key(rdev, wdev, -1, i, NL80211_KEYTYPE_GROUP, + NULL); + + if (cfg80211_cigtk_supported(wdev, NULL)) { + rdev_del_key(rdev, wdev, -1, 0, NL80211_KEYTYPE_CIGTK, + NULL); + rdev_del_key(rdev, wdev, -1, 1, NL80211_KEYTYPE_CIGTK, + NULL); + } } rdev_set_qos_map(rdev, dev, NULL); diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 8c2a91b85c39..c210ca1e44e2 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -557,15 +557,15 @@ TRACE_EVENT(rdev_change_virtual_intf, DECLARE_EVENT_CLASS(key_handle, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr), - TP_ARGS(wiphy, wdev, link_id, key_index, pairwise, mac_addr), + u8 key_index, enum nl80211_key_type type, const u8 *mac_addr), + TP_ARGS(wiphy, wdev, link_id, key_index, type, mac_addr), TP_STRUCT__entry( WIPHY_ENTRY WDEV_ENTRY MAC_ENTRY(mac_addr) __field(int, link_id) __field(u8, key_index) - __field(bool, pairwise) + __field(u8, type) ), TP_fast_assign( WIPHY_ASSIGN; @@ -573,38 +573,40 @@ DECLARE_EVENT_CLASS(key_handle, MAC_ASSIGN(mac_addr, mac_addr); __entry->link_id = link_id; __entry->key_index = key_index; - __entry->pairwise = pairwise; + __entry->type = type; ), TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", link_id: %d, " - "key_index: %u, pairwise: %s, mac addr: %pM", + "key_index: %u, pairwise: %s, type: %d, mac addr: %pM", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->link_id, - __entry->key_index, BOOL_TO_STR(__entry->pairwise), - __entry->mac_addr) + __entry->key_index, + BOOL_TO_STR(__entry->type == NL80211_KEYTYPE_PAIRWISE), + __entry->type, __entry->mac_addr) ); DEFINE_EVENT(key_handle, rdev_get_key, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr), - TP_ARGS(wiphy, wdev, link_id, key_index, pairwise, mac_addr) + u8 key_index, enum nl80211_key_type type, const u8 *mac_addr), + TP_ARGS(wiphy, wdev, link_id, key_index, type, mac_addr) ); DEFINE_EVENT(key_handle, rdev_del_key, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr), - TP_ARGS(wiphy, wdev, link_id, key_index, pairwise, mac_addr) + u8 key_index, enum nl80211_key_type type, const u8 *mac_addr), + TP_ARGS(wiphy, wdev, link_id, key_index, type, mac_addr) ); TRACE_EVENT(rdev_add_key, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int link_id, - u8 key_index, bool pairwise, const u8 *mac_addr, u8 mode), - TP_ARGS(wiphy, wdev, link_id, key_index, pairwise, mac_addr, mode), + u8 key_index, enum nl80211_key_type type, const u8 *mac_addr, + u8 mode), + TP_ARGS(wiphy, wdev, link_id, key_index, type, mac_addr, mode), TP_STRUCT__entry( WIPHY_ENTRY WDEV_ENTRY MAC_ENTRY(mac_addr) __field(int, link_id) __field(u8, key_index) - __field(bool, pairwise) + __field(u8, type) __field(u8, mode) ), TP_fast_assign( @@ -613,15 +615,16 @@ TRACE_EVENT(rdev_add_key, MAC_ASSIGN(mac_addr, mac_addr); __entry->link_id = link_id; __entry->key_index = key_index; - __entry->pairwise = pairwise; + __entry->type = type; __entry->mode = mode; ), TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", link_id: %d, " - "key_index: %u, mode: %u, pairwise: %s, " + "key_index: %u, mode: %u, pairwise: %s, type: %d, " "mac addr: %pM", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->link_id, __entry->key_index, __entry->mode, - BOOL_TO_STR(__entry->pairwise), __entry->mac_addr) + BOOL_TO_STR(__entry->type == NL80211_KEYTYPE_PAIRWISE), + __entry->type, __entry->mac_addr) ); TRACE_EVENT(rdev_set_default_key, diff --git a/net/wireless/util.c b/net/wireless/util.c index f2464d2ce0d5..9d5456defc90 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -258,8 +258,24 @@ static bool cfg80211_igtk_cipher_supported(struct wiphy *wiphy) return false; } +bool cfg80211_cigtk_supported(struct wireless_dev *wdev, + struct genl_info *info) +{ + const struct wiphy_iftype_ext_capab *ext_capab = + cfg80211_get_iftype_ext_capa(wdev->wiphy, wdev->iftype); + + if (ext_capab && ext_capab->cip_supported) + return true; + + if (info) + GENL_SET_ERR_MSG(info, + "Control Integrity Protocol not supported"); + + return false; +} + bool cfg80211_valid_key_idx(struct wireless_dev *wdev, - int key_idx, bool pairwise, + int key_idx, enum nl80211_key_type type, const u8 *mac_addr) { if (WARN_ON(!wdev)) @@ -272,13 +288,24 @@ bool cfg80211_valid_key_idx(struct wireless_dev *wdev, * Can't differentiate ciphers here so allow 0..3. * Pairwise keys must be for a station (MAC address given). */ - if (pairwise) { + if (type == NL80211_KEYTYPE_PAIRWISE) { if (!mac_addr) return false; return key_idx < 4; } + /* Check the wdev/iftype supports CIGTK */ + if (type == NL80211_KEYTYPE_CIGTK) { + if (!cfg80211_cigtk_supported(wdev, NULL)) + return false; + + if (key_idx >= 2) + return false; + + /* fallthrough for mac_addr checks */ + } + /* * For group keys, mac_addr==NULL means setting a group key * for TX, which is only supported on some interface types, @@ -343,9 +370,12 @@ bool cfg80211_valid_key_idx(struct wireless_dev *wdev, int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, struct key_params *params, int key_idx, - bool pairwise, const u8 *mac_addr) + enum nl80211_key_type type, + const u8 *mac_addr) { - if (!cfg80211_valid_key_idx(wdev, key_idx, pairwise, mac_addr)) + bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; + + if (!cfg80211_valid_key_idx(wdev, key_idx, type, mac_addr)) return -EINVAL; switch (params->cipher) { @@ -1190,7 +1220,7 @@ void cfg80211_upload_connect_keys(struct wireless_dev *wdev) for (i = 0; i < 4; i++) { if (!wdev->connect_keys->params[i].cipher) continue; - if (rdev_add_key(rdev, wdev, -1, i, false, NULL, + if (rdev_add_key(rdev, wdev, -1, i, NL80211_KEYTYPE_GROUP, NULL, &wdev->connect_keys->params[i])) { netdev_err(dev, "failed to set key %d\n", i); continue; diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c index d45bc08c0de4..ec2389f6b8b1 100644 --- a/net/wireless/wext-compat.c +++ b/net/wireless/wext-compat.c @@ -401,6 +401,8 @@ static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, int idx, struct key_params *params) { struct wireless_dev *wdev = dev->ieee80211_ptr; + enum nl80211_key_type key_type = + pairwise ? NL80211_KEYTYPE_PAIRWISE : NL80211_KEYTYPE_GROUP; int err, i; bool rejoin = false; @@ -454,11 +456,11 @@ static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, rejoin = true; } - if (!cfg80211_valid_key_idx(wdev, idx, pairwise, addr)) + if (!cfg80211_valid_key_idx(wdev, idx, key_type, addr)) err = -ENOENT; else - err = rdev_del_key(rdev, wdev, -1, idx, pairwise, - addr); + err = rdev_del_key(rdev, wdev, -1, idx, + key_type, addr); } wdev->wext.connect.privacy = false; /* From 89665aeecd0f0c6b4ae620dfd4c67b99751f4cd1 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 14:40:53 +0200 Subject: [PATCH 0822/2126] wifi: mac80211: add cigtk parameter to ieee80211_gtk_rekey_add The CIGTK keys use a key index of 0 or 1, which is not unique. As such, a new parameter is needed to differentiate the key type. Add the parameter to prepare for handling the CIGTK in the future. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921144048.8bfea7df6b06.I3d046fbe7dfb3883471773f84e7a791b5b97000e@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/intel/iwlwifi/mld/d3.c | 6 ++++-- drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 6 ++++-- drivers/net/wireless/realtek/rtw89/wow.c | 6 ++++-- include/net/mac80211.h | 3 ++- net/mac80211/key.c | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/d3.c b/drivers/net/wireless/intel/iwlwifi/mld/d3.c index 55f9b809e764..6d8ede336d59 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/d3.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/d3.c @@ -1138,7 +1138,8 @@ iwl_mld_add_mcast_rekey(struct ieee80211_vif *vif, return; key_config = ieee80211_gtk_rekey_add(vif, key_data->id, key_data->key, - sizeof(key_data->key), link_id); + sizeof(key_data->key), link_id, + false); if (IS_ERR(key_config)) return; @@ -1220,7 +1221,8 @@ static void iwl_mld_mlo_rekey(struct iwl_mld *mld, mlo_key->idx, link_id); key = ieee80211_gtk_rekey_add(vif, mlo_key->idx, mlo_key->key, - sizeof(mlo_key->key), link_id); + sizeof(mlo_key->key), link_id, + false); if (IS_ERR(key)) continue; diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c index 6b11fa32ea5c..bd52f2ebd3ba 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c @@ -1887,7 +1887,8 @@ static bool iwl_mvm_gtk_rekey(struct iwl_wowlan_status_data *status, key = ieee80211_gtk_rekey_add(vif, status->gtk[i].id, status->gtk[i].key, - sizeof(status->gtk[i].key), -1); + sizeof(status->gtk[i].key), -1, + false); if (IS_ERR(key)) { /* FW may send also the old keys */ if (PTR_ERR(key) == -EALREADY) @@ -1922,7 +1923,8 @@ iwl_mvm_d3_igtk_bigtk_rekey_add(struct iwl_wowlan_status_data *status, return true; key_config = ieee80211_gtk_rekey_add(vif, keyidx, key_data->key, - sizeof(key_data->key), -1); + sizeof(key_data->key), -1, + false); if (IS_ERR(key_config)) { /* FW may send also the old keys */ return PTR_ERR(key_config) == -EALREADY; diff --git a/drivers/net/wireless/realtek/rtw89/wow.c b/drivers/net/wireless/realtek/rtw89/wow.c index 2dfa24c54e7d..2e37e1fafbef 100644 --- a/drivers/net/wireless/realtek/rtw89/wow.c +++ b/drivers/net/wireless/realtek/rtw89/wow.c @@ -669,10 +669,12 @@ static struct ieee80211_key_conf *rtw89_wow_gtk_rekey(struct rtw89_dev *rtwdev, if (ieee80211_vif_is_mld(wow_vif)) key = ieee80211_gtk_rekey_add(wow_vif, keyidx, gtk, cipher_info->len, - rtwvif_link->link_id); + rtwvif_link->link_id, + false); else key = ieee80211_gtk_rekey_add(wow_vif, keyidx, gtk, - cipher_info->len, -1); + cipher_info->len, -1, + false); kfree(rekey_conf); if (IS_ERR(key)) { diff --git a/include/net/mac80211.h b/include/net/mac80211.h index d6f3c5855910..c4894bd37903 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -6278,6 +6278,7 @@ void ieee80211_set_key_rx_seq(struct ieee80211_key_conf *keyconf, * @key_len: the key data. Might be bigger than the actual key length, * but not smaller (for the driver convinence) * @link_id: the link id of the key or -1 for non-MLO + * @cigtk: whether this is a CIGTK * * When GTK rekeying was done while the system was suspended, (a) new * key(s) will be available. These will be needed by mac80211 for proper @@ -6304,7 +6305,7 @@ void ieee80211_set_key_rx_seq(struct ieee80211_key_conf *keyconf, struct ieee80211_key_conf * ieee80211_gtk_rekey_add(struct ieee80211_vif *vif, u8 idx, u8 *key_data, u8 key_len, - int link_id); + int link_id, bool cigtk); /** * ieee80211_gtk_rekey_notify - notify userspace supplicant of rekeying diff --git a/net/mac80211/key.c b/net/mac80211/key.c index f45e792abede..9ac7a5c4b861 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -1366,7 +1366,7 @@ EXPORT_SYMBOL_GPL(ieee80211_set_key_rx_seq); struct ieee80211_key_conf * ieee80211_gtk_rekey_add(struct ieee80211_vif *vif, u8 idx, u8 *key_data, u8 key_len, - int link_id) + int link_id, bool cigtk) { struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); struct ieee80211_local *local = sdata->local; From fc14cfab631994c872e2ebb65de8c50c49bda38e Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 14:40:54 +0200 Subject: [PATCH 0823/2126] wifi: mac80211: add helpers to parse/generate CIP Capabilities The Control Integrity Protocol (CIP) Capabilities need to be added to and parsed from the association request and response. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921144048.a3249c0b78ad.Ia3ea929dd6381cf8b04e3dd0c38e709e335113c2@changeid Signed-off-by: Johannes Berg --- include/linux/ieee80211.h | 22 ++++++++++++++++++++++ net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/parse.c | 4 ++++ net/mac80211/util.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h index 7fbc51f873ff..73ac5336a17a 100644 --- a/include/linux/ieee80211.h +++ b/include/linux/ieee80211.h @@ -1828,6 +1828,7 @@ enum ieee80211_eid_ext { WLAN_EID_EXT_BANDWIDTH_INDICATION = 135, WLAN_EID_EXT_KNOWN_STA_IDENTIFCATION = 136, WLAN_EID_EXT_NON_AP_STA_REG_CON = 137, + WLAN_EID_EXT_CIP_CAPA = 150, WLAN_EID_EXT_UHR_OPER = 151, WLAN_EID_EXT_UHR_CAPA = 152, WLAN_EID_EXT_MACP = 153, @@ -2899,4 +2900,25 @@ static inline bool ieee80211_check_tim(const struct ieee80211_tim_ie *tim, __ieee80211_check_tim(tim, tim_len, aid); } +/** + * enum ieee80211_cip_cap_fields - CIP Capabilities element fields + * @IEEE80211_CIP_CAP_MIC_PADDING: The MIC padding subfield in the CIP + * capabilities + * @IEEE80211_CIP_CAP_PROTECTED_CTRL_FRAME_ONLY: The MIC Padding For Protected + * Control Frames Only bit in CIP capabilities + */ +enum ieee80211_cip_cap_fields { + IEEE80211_CIP_CAP_MIC_PADDING = 0x0F, + IEEE80211_CIP_CAP_PROTECTED_CTRL_FRAME_ONLY = 0x10, +}; + +/** + * struct ieee80211_cip_cap - CIP Capabilities element + * + * @v: The value of the Control Integrity Protocol Capability element + */ +struct ieee80211_cip_cap { + u8 v; +} __packed; + #endif /* LINUX_IEEE80211_H */ diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 10767666c45c..658550faf64a 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1878,6 +1878,7 @@ struct ieee802_11_elems { const struct ieee80211_ttlm_elem *ttlm[IEEE80211_TTLM_MAX_CNT]; const struct ieee80211_uhr_cap *uhr_cap; const struct ieee80211_uhr_operation *uhr_operation; + const struct ieee80211_cip_cap *cip_cap; /* not the order in the psd values is per element, not per chandef */ struct ieee80211_parsed_tpe tpe; @@ -2778,6 +2779,8 @@ int ieee80211_put_uhr_cap(struct sk_buff *skb, const struct ieee80211_supported_band *sband); void ieee80211_put_reg_conn(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb); +int ieee80211_put_cip_cap(struct sk_buff *skb, + struct ieee80211_sub_if_data *sdata); /* channel management */ bool ieee80211_chandef_ht_oper(const struct ieee80211_ht_operation *ht_oper, diff --git a/net/mac80211/parse.c b/net/mac80211/parse.c index cb2be167cde7..3b66ca7d7a5c 100644 --- a/net/mac80211/parse.c +++ b/net/mac80211/parse.c @@ -205,6 +205,10 @@ ieee80211_parse_extension_element(u32 *crc, elems->ttlm_num++; } break; + case WLAN_EID_EXT_CIP_CAPA: + if (len >= sizeof(*elems->cip_cap)) + elems->cip_cap = data; + break; case WLAN_EID_EXT_UHR_OPER: if (params->mode < IEEE80211_CONN_MODE_UHR) break; diff --git a/net/mac80211/util.c b/net/mac80211/util.c index e2b5b2b21c34..c193a75ef06e 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -4680,6 +4680,25 @@ int ieee80211_put_uhr_cap(struct sk_buff *skb, return 0; } +int ieee80211_put_cip_cap(struct sk_buff *skb, + struct ieee80211_sub_if_data *sdata) +{ + const struct wiphy_iftype_ext_capab *ift_ext_capa = + cfg80211_get_iftype_ext_capa(sdata->local->hw.wiphy, + ieee80211_vif_type_p2p(&sdata->vif)); + u8 cip_capabilities = ift_ext_capa ? ift_ext_capa->cip_capabilities : 0; + + if (skb_tailroom(skb) < 4) + return -ENOBUFS; + + skb_put_u8(skb, WLAN_EID_EXTENSION); + skb_put_u8(skb, 2); + skb_put_u8(skb, WLAN_EID_EXT_CIP_CAPA); + skb_put_u8(skb, cip_capabilities); + + return 0; +} + const char *ieee80211_conn_mode_str(enum ieee80211_conn_mode mode) { static const char * const modes[] = { From 57be6fdf3c8c9c4ab038971a897e9b7df1a136e4 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 14:40:55 +0200 Subject: [PATCH 0824/2126] wifi: mac80211: add Control Integrity Protocol handling Add the handling of CIP during association, when adding a station in AP mode and also add some checks whether the keys are being installed correctly. For internal use, add a new key flag CIP that is used for both the pairwise key and CIGTK. The CIGTK will then have the MCAST_KEY and CIP flags set. As the CIGTK uses key indices 0 and 1, add a new variable to track it separately from the other GTKs. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921144048.f032c70e0bc2.I30cf9ae29629188b8674e2268a6b592c1a63128b@changeid Signed-off-by: Johannes Berg --- include/net/mac80211.h | 8 ++++ net/mac80211/cfg.c | 22 ++++++++- net/mac80211/ieee80211_i.h | 2 + net/mac80211/key.c | 94 +++++++++++++++++++++++++++++--------- net/mac80211/key.h | 3 +- net/mac80211/mlme.c | 20 +++++++- net/mac80211/sta_info.h | 2 + 7 files changed, 126 insertions(+), 25 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index c4894bd37903..94bfa2485160 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -2395,6 +2395,8 @@ static inline bool lockdep_vif_wiphy_mutex_held(struct ieee80211_vif *vif) * number generation only * @IEEE80211_KEY_FLAG_SPP_AMSDU: SPP A-MSDUs can be used with this key * (set by mac80211 from the sta->spp_amsdu flag) + * @IEEE80211_KEY_FLAG_CIP: This key is used for the Control Integrity + * Protocol, and is either a pairwise key or a CIGTK. */ enum ieee80211_key_flags { IEEE80211_KEY_FLAG_GENERATE_IV_MGMT = BIT(0), @@ -2409,6 +2411,7 @@ enum ieee80211_key_flags { IEEE80211_KEY_FLAG_NO_AUTO_TX = BIT(9), IEEE80211_KEY_FLAG_GENERATE_MMIE = BIT(10), IEEE80211_KEY_FLAG_SPP_AMSDU = BIT(11), + IEEE80211_KEY_FLAG_CIP = BIT(12), }; /** @@ -2629,6 +2632,7 @@ struct ieee80211_sta_aggregates { * @eht_cap: EHT capabilities of this STA * @uhr_cap: UHR capabilities of this STA * @s1g_cap: S1G capabilities of this STA + * @cip_cap: the CIP capabilities of this STA (or zero) * @agg: per-link data for multi-link aggregation * @bandwidth: current bandwidth the station can receive with. * This is the minimum between the peer's capabilities and our own @@ -2657,6 +2661,7 @@ struct ieee80211_link_sta { struct ieee80211_sta_eht_cap eht_cap; struct ieee80211_sta_uhr_cap uhr_cap; struct ieee80211_sta_s1g_cap s1g_cap; + u8 cip_cap; struct ieee80211_sta_aggregates agg; @@ -2720,6 +2725,7 @@ struct ieee80211_link_sta { * @valid_links: bitmap of valid links, or 0 for non-MLO * @spp_amsdu: indicates whether the STA uses SPP A-MSDU or not. * @epp_peer: indicates that the peer is an EPP peer. + * @cip: indicates whether the STA uses control frame protection or not. * @nmi: For NDI stations, pointer to the NMI station of the peer. * @nan_sched: NAN peer schedule for this station. Valid only for NMI stations. * @ext_mld_capa_ops: the MLD's extended MLD capabilities and operations @@ -2741,6 +2747,8 @@ struct ieee80211_sta { u8 max_amsdu_subframes; u16 eml_cap; + bool cip; + struct ieee80211_sta_aggregates *cur; bool support_p2p_ps; diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 4c3a432b44ce..c85fb3e618fd 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -623,6 +623,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, struct ieee80211_link_data *link = ieee80211_link_or_deflink(sdata, link_id, false); bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; + bool cigtk = type == NL80211_KEYTYPE_CIGTK; struct ieee80211_local *local = sdata->local; struct sta_info *sta = NULL; struct ieee80211_key *key; @@ -666,6 +667,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, key->conf.link_id = -1; } else { key->conf.link_id = link->link_id; + + if (cigtk) + key->conf.flags |= IEEE80211_KEY_FLAG_CIP; } if (params->mode == NL80211_KEY_NO_TX) @@ -749,6 +753,7 @@ ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, struct ieee80211_local *local __maybe_unused = sdata->local; struct ieee80211_link_data *link = &sdata->deflink; bool pairwise = type == NL80211_KEYTYPE_PAIRWISE; + bool cigtk = type == NL80211_KEYTYPE_CIGTK; struct ieee80211_key *key; if (link_id >= 0) { @@ -778,7 +783,11 @@ ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, return wiphy_dereference(local->hw.wiphy, sta->ptk[key_idx]); - if (!pairwise && + if (cigtk && key_idx < NUM_CTRL_KEYS) + return wiphy_dereference(local->hw.wiphy, + link_sta->cigtk[key_idx]); + + if (!pairwise && !cigtk && key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS + NUM_DEFAULT_BEACON_KEYS) @@ -791,6 +800,9 @@ ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, if (pairwise && key_idx < NUM_DEFAULT_KEYS) return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]); + if (cigtk) + return wiphy_dereference(local->hw.wiphy, link->cigtk[key_idx]); + key = wiphy_dereference(local->hw.wiphy, link->gtk[key_idx]); if (key) return key; @@ -2301,6 +2313,8 @@ static int sta_link_apply_parameters(struct ieee80211_local *local, case STA_LINK_MODE_NEW: if (!params->link_mac) return -EINVAL; + if (sta->sta.cip && !params->cip_cap_set) + return -EINVAL; break; case STA_LINK_MODE_LINK_MODIFY: break; @@ -2423,6 +2437,9 @@ static int sta_link_apply_parameters(struct ieee80211_local *local, ieee80211_s1g_cap_to_sta_s1g_cap(sdata, params->s1g_capa, link_sta); + if (params->cip_cap_set) + link_sta->pub->cip_cap = params->cip_cap; + switch (sdata->vif.type) { case NL80211_IFTYPE_NAN: case NL80211_IFTYPE_NAN_DATA: @@ -2585,6 +2602,9 @@ static int sta_apply_parameters(struct ieee80211_local *local, if (params->eml_cap_present) sta->sta.eml_cap = params->eml_cap; + if (params->sta_flags_set & BIT(NL80211_STA_FLAG_CIP)) + sta->sta.cip = true; + ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_STA_MODIFY, ¶ms->link_sta_params); if (ret) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 658550faf64a..e7972c08e5f3 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -486,6 +486,7 @@ struct ieee80211_mgd_assoc_data { bool comeback; /* whether the AP has requested association comeback */ bool s1g; bool spp_amsdu; + bool cip; s8 assoc_link_id; @@ -1113,6 +1114,7 @@ struct ieee80211_link_data { struct ieee80211_key __rcu *gtk[NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS + NUM_DEFAULT_BEACON_KEYS]; + struct ieee80211_key __rcu *cigtk[NUM_CTRL_KEYS]; struct ieee80211_key __rcu *default_multicast_key; struct ieee80211_key __rcu *default_mgmt_key; struct ieee80211_key __rcu *default_beacon_key; diff --git a/net/mac80211/key.c b/net/mac80211/key.c index 9ac7a5c4b861..4c9788ec0b74 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -205,6 +205,10 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key) sta ? sta->sta.addr : bcast_addr, ret); out_unsupported: + /* Control Integrity Protocol can only be done in hardware */ + if (key->conf.flags & IEEE80211_KEY_FLAG_CIP) + return -EINVAL; + switch (key->conf.cipher) { case WLAN_CIPHER_SUITE_WEP40: case WLAN_CIPHER_SUITE_WEP104: @@ -440,11 +444,13 @@ void ieee80211_set_default_beacon_key(struct ieee80211_link_data *link, static int ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, struct ieee80211_link_data *link, struct sta_info *sta, - bool pairwise, + enum ieee80211_key_flags flags, struct ieee80211_key *old, struct ieee80211_key *new) { struct link_sta_info *link_sta = sta ? &sta->deflink : NULL; + bool pairwise = flags & IEEE80211_KEY_FLAG_PAIRWISE; + bool cip = flags & IEEE80211_KEY_FLAG_CIP; int link_id; int idx; int ret = 0; @@ -535,6 +541,8 @@ static int ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, if (new && !(new->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)) _ieee80211_set_tx_key(new, true); + } else if (cip) { + rcu_assign_pointer(link_sta->cigtk[idx], new); } else { rcu_assign_pointer(link_sta->gtk[idx], new); } @@ -569,6 +577,8 @@ static int ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, if (is_wep || pairwise) rcu_assign_pointer(sdata->keys[idx], new); + else if (cip) + rcu_assign_pointer(link->cigtk[idx], new); else rcu_assign_pointer(link->gtk[idx], new); @@ -883,6 +893,10 @@ int ieee80211_key_link(struct ieee80211_key *key, ret = -EOPNOTSUPP; goto out; } + + /* Set CIP flag if enabled for the station */ + if (sta->sta.cip) + key->conf.flags |= IEEE80211_KEY_FLAG_CIP; } else if (sta) { struct link_sta_info *link_sta = &sta->deflink; int link_id = key->conf.link_id; @@ -896,15 +910,25 @@ int ieee80211_key_link(struct ieee80211_key *key, } } - old_key = wiphy_dereference(sdata->local->hw.wiphy, - link_sta->gtk[idx]); + if (key->conf.flags & IEEE80211_KEY_FLAG_CIP) + old_key = wiphy_dereference(sdata->local->hw.wiphy, + link_sta->cigtk[idx]); + else + old_key = wiphy_dereference(sdata->local->hw.wiphy, + link_sta->gtk[idx]); } else { - if (idx < NUM_DEFAULT_KEYS) + if (key->conf.flags & IEEE80211_KEY_FLAG_CIP) { old_key = wiphy_dereference(sdata->local->hw.wiphy, - sdata->keys[idx]); - if (!old_key) - old_key = wiphy_dereference(sdata->local->hw.wiphy, - link->gtk[idx]); + link->cigtk[idx]); + } else { + if (idx < NUM_DEFAULT_KEYS) + old_key = wiphy_dereference(sdata->local->hw.wiphy, + sdata->keys[idx]); + + if (!old_key) + old_key = wiphy_dereference(sdata->local->hw.wiphy, + link->gtk[idx]); + } } /* Non-pairwise keys must also not switch the cipher on rekey */ @@ -938,9 +962,17 @@ int ieee80211_key_link(struct ieee80211_key *key, if (sta && sta->sta.spp_amsdu) key->conf.flags |= IEEE80211_KEY_FLAG_SPP_AMSDU; + /* A CIP related key must be GCMP-256 (really GMAC-256) */ + if ((key->conf.flags & IEEE80211_KEY_FLAG_CIP) && + key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256) { + ret = -EINVAL; + goto out; + } + increment_tailroom_need_count(sdata); - ret = ieee80211_key_replace(sdata, link, sta, pairwise, old_key, key); + ret = ieee80211_key_replace(sdata, link, sta, key->conf.flags, + old_key, key); if (!ret) { ieee80211_debugfs_key_add(key); @@ -966,8 +998,7 @@ void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom) */ if (key->sdata) ieee80211_key_replace(key->sdata, NULL, key->sta, - key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, - key, NULL); + key->conf.flags, key, NULL); ieee80211_key_destroy(key, delay_tailroom); } @@ -1098,8 +1129,7 @@ static void ieee80211_free_keys_iface(struct ieee80211_sub_if_data *sdata, list_for_each_entry_safe(key, tmp, &sdata->key_list, list) { ieee80211_key_replace(key->sdata, NULL, key->sta, - key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, - key, NULL); + key->conf.flags, key, NULL); list_add_tail(&key->list, keys); } @@ -1119,8 +1149,7 @@ void ieee80211_remove_link_keys(struct ieee80211_link_data *link, if (key->conf.link_id != link->link_id) continue; ieee80211_key_replace(key->sdata, link, key->sta, - key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, - key, NULL); + key->conf.flags, key, NULL); list_add_tail(&key->list, keys); } } @@ -1196,8 +1225,17 @@ void ieee80211_free_sta_keys(struct ieee80211_local *local, if (!key) continue; ieee80211_key_replace(key->sdata, NULL, key->sta, - key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, - key, NULL); + key->conf.flags, key, NULL); + __ieee80211_key_destroy(key, key->sdata->vif.type == + NL80211_IFTYPE_STATION); + } + + for (i = 0; i < ARRAY_SIZE(sta->deflink.cigtk); i++) { + key = wiphy_dereference(local->hw.wiphy, sta->deflink.cigtk[i]); + if (!key) + continue; + ieee80211_key_replace(key->sdata, NULL, key->sta, + key->conf.flags, key, NULL); __ieee80211_key_destroy(key, key->sdata->vif.type == NL80211_IFTYPE_STATION); } @@ -1207,8 +1245,7 @@ void ieee80211_free_sta_keys(struct ieee80211_local *local, if (!key) continue; ieee80211_key_replace(key->sdata, NULL, key->sta, - key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE, - key, NULL); + key->conf.flags, key, NULL); __ieee80211_key_destroy(key, key->sdata->vif.type == NL80211_IFTYPE_STATION); } @@ -1390,10 +1427,20 @@ ieee80211_gtk_rekey_add(struct ieee80211_vif *vif, NUM_DEFAULT_BEACON_KEYS)) return ERR_PTR(-EINVAL); - prev_key = wiphy_dereference(local->hw.wiphy, - link_data->gtk[idx]); + if (WARN_ON(cigtk && idx >= NUM_CTRL_KEYS)) + return ERR_PTR(-EINVAL); + + if (cigtk) + prev_key = wiphy_dereference(local->hw.wiphy, + link_data->cigtk[idx]); + else + prev_key = wiphy_dereference(local->hw.wiphy, + link_data->gtk[idx]); if (!prev_key) { - if (idx < NUM_DEFAULT_KEYS) { + if (cigtk) { + prev_key = wiphy_dereference(local->hw.wiphy, + link_data->cigtk[idx ^ 1]); + } else if (idx < NUM_DEFAULT_KEYS) { for (int i = 0; i < NUM_DEFAULT_KEYS; i++) { if (i == idx) continue; @@ -1424,6 +1471,9 @@ ieee80211_gtk_rekey_add(struct ieee80211_vif *vif, if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED) key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; + if (prev_key->conf.flags & IEEE80211_KEY_FLAG_CIP) + key->conf.flags |= IEEE80211_KEY_FLAG_CIP; + key->conf.link_id = link_data->link_id; err = ieee80211_key_link(key, link_data, NULL); diff --git a/net/mac80211/key.h b/net/mac80211/key.h index 826e4e9387c5..c85992493afd 100644 --- a/net/mac80211/key.h +++ b/net/mac80211/key.h @@ -2,7 +2,7 @@ /* * Copyright 2002-2004, Instant802 Networks, Inc. * Copyright 2005, Devicescape Software, Inc. - * Copyright (C) 2019, 2022-2023 Intel Corporation + * Copyright (C) 2019, 2022-2023, 2026 Intel Corporation */ #ifndef IEEE80211_KEY_H @@ -19,6 +19,7 @@ #define NUM_DEFAULT_KEYS 4 #define NUM_DEFAULT_MGMT_KEYS 2 #define NUM_DEFAULT_BEACON_KEYS 2 +#define NUM_CTRL_KEYS 2 #define INVALID_PTK_KEYIDX 2 /* Keyidx always pointing to a NULL key for PTK */ struct ieee80211_local; diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index cf3873d8855b..76c45a0eea62 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -2337,6 +2337,10 @@ ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata, ieee80211_put_eht_cap(skb, sdata, sband, &assoc_data->link[link_id].conn); + /* Insert CIP only on the assoc link (it will be inherited) */ + if (link_id == assoc_data->assoc_link_id && assoc_data->cip) + ieee80211_put_cip_cap(skb, sdata); + if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_UHR) ieee80211_put_uhr_cap(skb, sdata, sband); @@ -2613,7 +2617,8 @@ static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) assoc_data->ie_len + /* extra IEs */ (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + 9 /* WMM */ + - 4 /* regulatory connectivity, if 6 GHz is supported */; + 4 /* regulatory connectivity, if 6 GHz is supported */ + + (assoc_data->cip ? 4 /* CIP capabilities */ : 0); for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; @@ -6274,6 +6279,17 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link, /* TODO: OPEN: what happens if BSS color disable is set? */ } + if (assoc_data->cip) { + if (elems->cip_cap) { + link_sta->pub->cip_cap = elems->cip_cap->v; + } else { + sdata_info(sdata, + "CIP Capabilities not included in association response\n"); + ret = false; + goto out; + } + } + if (cbss->transmitted_bss) { bss_conf->nontransmitted = true; ether_addr_copy(bss_conf->transmitter_bssid, @@ -6999,6 +7015,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, goto out_err; sta->sta.spp_amsdu = assoc_data->spp_amsdu; + sta->sta.cip = assoc_data->cip; if (ieee80211_vif_is_mld(&sdata->vif)) { if (!elems->ml_basic) @@ -10536,6 +10553,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, } assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU; + assoc_data->cip = req->flags & ASSOC_REQ_CIP; if (ifmgd->auth_data && !ifmgd->auth_data->done) { err = -EBUSY; diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index ee0d32877c5b..f409f6a3afa1 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -485,6 +485,7 @@ struct ieee80211_fragment_cache { * @link_hash_node: hash node for rhashtable * @sta: Points to the STA info * @gtk: group keys negotiated with this station, if any + * @cigtk: control integrity group keys negotiated with this station, if any * @tx_stats: TX statistics * @tx_stats.packets: # of packets transmitted * @tx_stats.bytes: # of bytes in all packets transmitted @@ -535,6 +536,7 @@ struct link_sta_info { struct ieee80211_key __rcu *gtk[NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS + NUM_DEFAULT_BEACON_KEYS]; + struct ieee80211_key __rcu *cigtk[NUM_CTRL_KEYS]; struct ieee80211_sta_rx_stats __percpu *pcpu_rx_stats; /* Updated from RX path only, no locking requirements */ From 96040137f2b74a113c15791adc56f6788b2492a3 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 14:40:56 +0200 Subject: [PATCH 0825/2126] wifi: mac80211_hwsim: claim support for Control Integrity Protocol The mac80211_hwsim driver never actually generates control frames. As such, it can simply claim the Control Integrity protocol (CIP). Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921144048.6a4047ca21a1.If483ea588361a90b58a52493936cc0bbbc74c075@changeid Signed-off-by: Johannes Berg --- .../wireless/virtual/mac80211_hwsim_main.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index d567ed8d45a4..762f99eb15e4 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -5650,6 +5650,14 @@ static void mac80211_hwsim_sband_capab(struct ieee80211_supported_band *sband) BIT(NL80211_IFTYPE_MESH_POINT) | \ BIT(NL80211_IFTYPE_OCB)) +static const u8 iftypes_ext_capa[] = { + [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, + [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, + [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF | + WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB, + [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB, +}; + static const u8 iftypes_ext_capa_ap[] = { [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, @@ -5674,6 +5682,33 @@ static const struct wiphy_iftype_ext_capab mac80211_hwsim_iftypes_ext_capa[] = { .eml_capabilities = IEEE80211_EML_CAP_EMLSR_SUPP | IEEE80211_EML_CAP_EMLMR_SUPPORT, .mld_capa_and_ops = MAC80211_HWSIM_MLD_CAPA_OPS, + /* CIP works as hwsim does not have control frames */ + .cip_supported = true, + .cip_capabilities = 0, + }, + { + .iftype = NL80211_IFTYPE_STATION, + .extended_capabilities = iftypes_ext_capa, + .extended_capabilities_mask = iftypes_ext_capa, + .extended_capabilities_len = sizeof(iftypes_ext_capa), + .cip_supported = true, + .cip_capabilities = 0, + }, + { + .iftype = NL80211_IFTYPE_P2P_CLIENT, + .extended_capabilities = iftypes_ext_capa, + .extended_capabilities_mask = iftypes_ext_capa, + .extended_capabilities_len = sizeof(iftypes_ext_capa), + .cip_supported = true, + .cip_capabilities = 0, + }, + { + .iftype = NL80211_IFTYPE_P2P_GO, + .extended_capabilities = iftypes_ext_capa, + .extended_capabilities_mask = iftypes_ext_capa, + .extended_capabilities_len = sizeof(iftypes_ext_capa), + .cip_supported = true, + .cip_capabilities = 0, }, }; From 025ef5f4f63b5ecf38bb8f4eb80941c0d55c943f Mon Sep 17 00:00:00 2001 From: Andrei Otcheretianski Date: Mon, 21 Sep 2026 22:00:22 +0300 Subject: [PATCH 0826/2126] wifi: cfg80211: add NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS Add a new NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS command that lets user space mark a set of NAN channels as non-evacuable. The command carries the channels as nested NL80211_ATTR_NAN_CHANNEL attributes (chandef only) and replaces the entire set of non-evacuable channels; channels not included in the list become evacuable again. All provided channels must already exist in the current local schedule, otherwise -ENOENT is returned. The command is rejected with -EBUSY while a schedule update is pending. This prevents the kernel from evacuating channels that carry NDC or immutable schedules, so evacuating these channels would break existing NDP connections. Fixes: 154b0296c0ec ("wifi: nl80211: Add a notification to notify NAN channel evacuation") Signed-off-by: Andrei Otcheretianski Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260921215936.2efc32011e73.Ice8839058e114f6f9783079807df446388187dda@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 24 +++++++++++++ include/uapi/linux/nl80211.h | 31 ++++++++++++++++ net/wireless/core.c | 35 ++++++++++++++++++ net/wireless/core.h | 4 +++ net/wireless/nl80211.c | 69 ++++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 17 +++++++++ net/wireless/trace.h | 25 +++++++++++++ 7 files changed, 205 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 1ef5f85a9376..0b3fcb2a9576 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4264,6 +4264,21 @@ struct cfg80211_nan_local_sched { struct cfg80211_nan_channel nan_channels[] __counted_by(n_channels); }; +/** + * struct cfg80211_nan_non_evac_channels - NAN non-evacuable channels + * + * This struct defines the set of NAN local schedule channels that must not + * be evacuated for concurrent operations. + * + * @n_channels: number of channel definitions in %chandefs. + * @chandefs: array of channel definitions that must not be evacuated. Each + * must match a channel of the current local schedule. + */ +struct cfg80211_nan_non_evac_channels { + u8 n_channels; + struct cfg80211_chan_def chandefs[] __counted_by(n_channels); +}; + /** * struct cfg80211_nan_peer_map - NAN peer schedule map * @@ -5212,6 +5227,12 @@ struct mgmt_frame_regs { * schedule, the full new schedule is provided - partial updates are not * supported, and the new schedule completely replaces the previous one. * + * @nan_set_non_evac_channels: set the list of local schedule channels that + * must not be evacuated for concurrent operations. The provided list + * replaces the previous set; channels of the current schedule that are + * not included become evacuable again. All provided channels are + * guaranteed by cfg80211 to belong to the current local schedule. + * * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS * * @get_txq_stats: Get TXQ stats for interface or phy. If wdev is %NULL, this @@ -5601,6 +5622,9 @@ struct cfg80211_ops { int (*nan_set_peer_sched)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_nan_peer_sched *sched); + int (*nan_set_non_evac_channels)(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_nan_non_evac_channels *channels); int (*set_multicast_to_unicast)(struct wiphy *wiphy, struct net_device *dev, const bool enabled); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 843d1dbb725d..be9e2842a736 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1383,6 +1383,13 @@ * from the device to perform an announced schedule update. See * %NL80211_ATTR_NAN_SCHED_DEFERRED for more details. * If not set, the schedule should be applied immediately. + * Setting a new schedule is always allowed and is never treated as an + * evacuation, even if it removes channels that were previously marked as + * non-evacuable with %NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS. The + * non-evacuable marking is a per-channel property of the schedule: + * channels that remain in the new schedule keep their marking, channels + * that are removed simply lose it, and newly added channels are + * evacuable by default. * @NL80211_CMD_NAN_SCHED_UPDATE_DONE: Event sent to user space to notify that * a deferred local NAN schedule update (requested with * %NL80211_CMD_NAN_SET_LOCAL_SCHED and %NL80211_ATTR_NAN_SCHED_DEFERRED) @@ -1427,6 +1434,28 @@ * @NL80211_CMD_STOP_PD: Stop the PD operation, identified by * its %NL80211_ATTR_WDEV interface. * + * @NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS: Set the list of NAN local schedule + * channels that must not be evacuated. NAN must be operational + * (%NL80211_CMD_START_NAN was executed) and a local schedule must have + * been set (%NL80211_CMD_NAN_SET_LOCAL_SCHED). The command carries zero + * or more nested %NL80211_ATTR_NAN_CHANNEL attributes, each identifying a + * channel (by its channel definition) of the current local schedule that + * must not be evacuated for concurrent operations. The provided list + * replaces the previous set of non-evacuable channels; channels of the + * current schedule that are not included become evacuable again. All + * provided channels must exist in the current local schedule, otherwise + * the command fails. This is used to protect channels carrying NDC or + * immutable schedules, whose evacuation would break existing NDP + * connections. + * The non-evacuable marking is a per-channel property of the current + * local schedule and only affects evacuation for concurrent operations; + * it does not prevent the schedule itself from being changed. Removing a + * channel from the schedule with %NL80211_CMD_NAN_SET_LOCAL_SCHED is a + * user-initiated change, not an evacuation, and is allowed even for a + * non-evacuable channel. Across a schedule update, channels that remain + * keep their non-evacuable marking, removed channels lose it, and newly + * added channels are evacuable by default; issue this command again to + * change the non-evacuable set. * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */ @@ -1705,6 +1734,8 @@ enum nl80211_commands { NL80211_CMD_START_PD, NL80211_CMD_STOP_PD, + NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ diff --git a/net/wireless/core.c b/net/wireless/core.c index cde3ca85494d..3ac3b2a67a9c 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -348,6 +348,41 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev, return 0; } +int cfg80211_nan_set_non_evac_channels(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_non_evac_channels *channels) +{ + lockdep_assert_held(&rdev->wiphy.mtx); + + if (wdev->iftype != NL80211_IFTYPE_NAN || !wdev_running(wdev)) + return -EINVAL; + + /* + * Don't allow updating the non-evacuable channels while a deferred + * schedule update is pending, as the set of channels may still change. + */ + if (wdev->u.nan.sched_update_pending) + return -EBUSY; + + /* All provided channels must belong to the current local schedule. */ + for (int i = 0; i < channels->n_channels; i++) { + bool found = false; + + for (int j = 0; j < wdev->u.nan.n_channels; j++) { + if (cfg80211_chandef_identical(&wdev->u.nan.chandefs[j], + &channels->chandefs[i])) { + found = true; + break; + } + } + + if (!found) + return -ENOENT; + } + + return rdev_nan_set_non_evac_channels(rdev, wdev, channels); +} + void cfg80211_stop_pd(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev) { diff --git a/net/wireless/core.h b/net/wireless/core.h index de23518451ca..58445c09026a 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -578,6 +578,10 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, struct cfg80211_nan_local_sched *sched); +int cfg80211_nan_set_non_evac_channels(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_non_evac_channels *channels); + struct cfg80211_internal_bss * cfg80211_bss_update(struct cfg80211_registered_device *rdev, struct cfg80211_internal_bss *tmp, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index ef241b6da245..91e26b93a523 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -17845,6 +17845,69 @@ static int nl80211_nan_set_local_sched(struct sk_buff *skb, return cfg80211_nan_set_local_schedule(rdev, wdev, sched); } +static int +nl80211_parse_non_evac_channel(struct cfg80211_registered_device *rdev, + struct nlattr *channel, struct genl_info *info, + struct cfg80211_chan_def *chandef) +{ + struct nlattr **channel_parsed __free(kfree) = + kcalloc(NL80211_ATTR_MAX + 1, sizeof(*channel_parsed), + GFP_KERNEL); + int ret; + + if (!channel_parsed) + return -ENOMEM; + + ret = nla_parse_nested(channel_parsed, NL80211_ATTR_MAX, channel, NULL, + info->extack); + if (ret) + return ret; + + return nl80211_parse_chandef(rdev, info->extack, channel_parsed, + chandef, false); +} + +static int nl80211_nan_set_non_evac_channels(struct sk_buff *skb, + struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wireless_dev *wdev = info->user_ptr[1]; + int rem, i = 0, n_channels = 0; + struct nlattr *channel; + + if (wdev->iftype != NL80211_IFTYPE_NAN) + return -EOPNOTSUPP; + + if (!wdev_running(wdev)) + return -ENOTCONN; + + /* Count how many channel attributes we got */ + nlmsg_for_each_attr_type(channel, NL80211_ATTR_NAN_CHANNEL, + info->nlhdr, GENL_HDRLEN, rem) + n_channels++; + + struct cfg80211_nan_non_evac_channels *channels __free(kfree) = + kzalloc(struct_size(channels, chandefs, n_channels), + GFP_KERNEL); + if (!channels) + return -ENOMEM; + + channels->n_channels = n_channels; + + nlmsg_for_each_attr_type(channel, NL80211_ATTR_NAN_CHANNEL, + info->nlhdr, GENL_HDRLEN, rem) { + int ret; + + ret = nl80211_parse_non_evac_channel(rdev, channel, info, + &channels->chandefs[i]); + if (ret) + return ret; + i++; + } + + return cfg80211_nan_set_non_evac_channels(rdev, wdev, channels); +} + static int nl80211_get_protocol_features(struct sk_buff *skb, struct genl_info *info) { @@ -20724,6 +20787,12 @@ static const struct genl_small_ops nl80211_small_ops[] = { .flags = GENL_ADMIN_PERM, .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), }, + { + .cmd = NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS, + .doit = nl80211_nan_set_non_evac_channels, + .flags = GENL_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 0d4bbe0e5c5d..1f1311c20e94 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1097,6 +1097,23 @@ rdev_nan_set_peer_sched(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_nan_set_non_evac_channels(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_non_evac_channels *channels) +{ + int ret; + + trace_rdev_nan_set_non_evac_channels(&rdev->wiphy, wdev, channels); + if (rdev->ops->nan_set_non_evac_channels) + ret = rdev->ops->nan_set_non_evac_channels(&rdev->wiphy, wdev, + channels); + else + ret = -EOPNOTSUPP; + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline int rdev_start_pd(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev) { diff --git a/net/wireless/trace.h b/net/wireless/trace.h index c210ca1e44e2..83007a824010 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2486,6 +2486,31 @@ TRACE_EVENT(rdev_nan_set_peer_sched, ) ); +TRACE_EVENT(rdev_nan_set_non_evac_channels, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_nan_non_evac_channels *channels), + TP_ARGS(wiphy, wdev, channels), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __field(u8, n_channels) + __dynamic_array(u32, freqs, channels->n_channels) + ), + TP_fast_assign( + u32 *freqs = __get_dynamic_array(freqs); + + WIPHY_ASSIGN; + WDEV_ASSIGN; + __entry->n_channels = channels->n_channels; + for (int i = 0; i < channels->n_channels; i++) + freqs[i] = channels->chandefs[i].chan->center_freq; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", n_channels: %u, freqs: %s", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->n_channels, + __print_array(__get_dynamic_array(freqs), + __entry->n_channels, sizeof(u32))) +); + TRACE_EVENT(rdev_set_mac_acl, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_acl_data *params), From e9e25a957842ba2667b75df40f5a73bfda934d7b Mon Sep 17 00:00:00 2001 From: Andrei Otcheretianski Date: Mon, 21 Sep 2026 22:00:23 +0300 Subject: [PATCH 0827/2126] wifi: mac80211: implement NAN non-evacuable channels Implement the nan_set_non_evac_channels operation in mac80211. It marks the provided channels as non-evacuable in the current local schedule and clears the flag on all other channels. All provided channels must exist in the current schedule, otherwise -ENOENT is returned. ieee80211_nan_find_evac_chan() skips channels marked as non-evacuable when selecting a channel to evacuate for concurrent operations. Fixes: 42c9de58d990 ("wifi: mac80211: add NAN channel evacuation support") Signed-off-by: Andrei Otcheretianski Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260921215936.ef5884349253.I38b685378c3557679ed6387922a94a7da821555c@changeid Signed-off-by: Johannes Berg --- include/net/mac80211.h | 2 ++ net/mac80211/cfg.c | 13 +++++++++++++ net/mac80211/ieee80211_i.h | 2 ++ net/mac80211/nan.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 94bfa2485160..cb9f8e14b3b6 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -923,12 +923,14 @@ struct ieee80211_bss_conf { * @channel_entry: the Channel Entry blob as defined in Wi-Fi Aware * (TM) 4.0 specification Table 100 (Channel Entry format for the NAN * Availability attribute). + * @no_evacuate: if set, this channel must not be evacuated */ struct ieee80211_nan_channel { struct ieee80211_chan_req chanreq; u8 needed_rx_chains; struct ieee80211_chanctx_conf *chanctx_conf; u8 channel_entry[6]; + bool no_evacuate; }; /** diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index c85fb3e618fd..bd1a857c812d 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -6012,6 +6012,18 @@ ieee80211_set_peer_nan_sched(struct wiphy *wiphy, return ieee80211_nan_set_peer_sched(sdata, sched); } +static int +ieee80211_set_nan_non_evac_channels(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_nan_non_evac_channels *channels) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); + + lockdep_assert_wiphy(wiphy); + + return ieee80211_nan_set_non_evac_channels(sdata, channels); +} + const struct cfg80211_ops mac80211_config_ops = { .add_virtual_intf = ieee80211_add_iface, .del_virtual_intf = ieee80211_del_iface, @@ -6130,4 +6142,5 @@ const struct cfg80211_ops mac80211_config_ops = { .set_epcs = ieee80211_set_epcs, .nan_set_local_sched = ieee80211_set_local_nan_sched, .nan_set_peer_sched = ieee80211_set_peer_nan_sched, + .nan_set_non_evac_channels = ieee80211_set_nan_non_evac_channels, }; diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index e7972c08e5f3..1430527d216c 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2091,6 +2091,8 @@ int ieee80211_nan_set_local_sched(struct ieee80211_sub_if_data *sdata, struct cfg80211_nan_local_sched *sched); int ieee80211_nan_set_peer_sched(struct ieee80211_sub_if_data *sdata, struct cfg80211_nan_peer_sched *sched); +int ieee80211_nan_set_non_evac_channels(struct ieee80211_sub_if_data *sdata, + struct cfg80211_nan_non_evac_channels *channels); void ieee80211_nan_free_peer_sched(struct ieee80211_nan_peer_sched *sched); void ieee80211_nan_update_ndi_carrier(struct ieee80211_sub_if_data *ndi_sdata); struct ieee80211_nan_channel * diff --git a/net/mac80211/nan.c b/net/mac80211/nan.c index c7769da9617b..dc14b5d676fc 100644 --- a/net/mac80211/nan.c +++ b/net/mac80211/nan.c @@ -248,6 +248,35 @@ ieee80211_nan_find_free_channel(struct ieee80211_nan_sched_cfg *sched_cfg) return NULL; } +int +ieee80211_nan_set_non_evac_channels(struct ieee80211_sub_if_data *sdata, + struct cfg80211_nan_non_evac_channels *channels) +{ + struct ieee80211_nan_sched_cfg *sched_cfg = &sdata->vif.cfg.nan_sched; + + /* + * cfg80211 already validated that all provided channels belong to the + * current schedule, so just clear all non-evacuable flags and set the + * ones in the list. + */ + for (int j = 0; j < ARRAY_SIZE(sched_cfg->channels); j++) + sched_cfg->channels[j].no_evacuate = false; + + for (int i = 0; i < channels->n_channels; i++) { + for (int j = 0; j < ARRAY_SIZE(sched_cfg->channels); j++) { + if (!sched_cfg->channels[j].chanreq.oper.chan) + continue; + if (cfg80211_chandef_identical(&sched_cfg->channels[j].chanreq.oper, + &channels->chandefs[i])) { + sched_cfg->channels[j].no_evacuate = true; + break; + } + } + } + + return 0; +} + int ieee80211_nan_set_local_sched(struct ieee80211_sub_if_data *sdata, struct cfg80211_nan_local_sched *sched) { @@ -785,6 +814,10 @@ ieee80211_nan_find_evac_chan(struct ieee80211_local *local, usable_channels++; + /* No-evacuate channel is usable but cannot be evacuated */ + if (chan->no_evacuate) + continue; + chan_ctx = container_of(chan->chanctx_conf, struct ieee80211_chanctx, conf); From e5fefa3da5bf7c45bef90a3cca6a49e6c2d80877 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 21 Sep 2026 22:30:38 +0300 Subject: [PATCH 0828/2126] wifi: radiotap: add definitions for UHR U-SIG There are three different formats for MU, TB and ELR, add the necessary definitions for them. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260921223016.8f871c68a709.I1cdbb85ac81e33fb84548e8679b78ee1cd1db6c4@changeid Signed-off-by: Johannes Berg --- include/net/ieee80211_radiotap.h | 45 +++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/include/net/ieee80211_radiotap.h b/include/net/ieee80211_radiotap.h index ffdfbade25b8..782c3dcd8b52 100644 --- a/include/net/ieee80211_radiotap.h +++ b/include/net/ieee80211_radiotap.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2017 Intel Deutschland GmbH - * Copyright (c) 2018-2019, 2021-2022, 2025 Intel Corporation + * Copyright (c) 2018-2019, 2021-2022, 2025-2026 Intel Corporation * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -608,6 +608,49 @@ enum ieee80211_radiotap_eht_usig_tb { IEEE80211_RADIOTAP_EHT_USIG2_TB_B20_B25_TAIL = 0xfc000000, }; +enum ieee80211_radiotap_uhr_usig_mu { + /* USIG-1 */ + IEEE80211_RADIOTAP_UHR_USIG1_MU_BSS_COLOR_2 = 0x0000003f, + IEEE80211_RADIOTAP_UHR_USIG1_MU_B20_B24_DISREGARD = 0x0000001f, + IEEE80211_RADIOTAP_UHR_USIG1_MU_B25_VALIDATE = 0x00000020, + /* USIG-2 */ + IEEE80211_RADIOTAP_UHR_USIG2_MU_B0_B1_PPDU_TYPE = 0x000000c0, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B2_COBF_COSR = 0x00000100, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B3_B7_PUNCTURED_INFO = 0x00003e00, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B8_VALIDATE = 0x00004000, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B9_B10_SIG_MCS = 0x00018000, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B11_B15_UHR_SIG_SYMBOLS = 0x003e0000, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B16_B19_CRC = 0x03c00000, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B20_B25_TAIL = 0xfc000000, +}; + +enum ieee80211_radiotap_uhr_usig_tb { + /* USIG-1 */ + IEEE80211_RADIOTAP_UHR_USIG1_TB_B20_B25_DISREGARD = 0x0000003f, + + /* USIG-2 */ + IEEE80211_RADIOTAP_UHR_USIG2_TB_B0_B1_PPDU_TYPE = 0x000000c0, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B2_VALIDATE = 0x00000100, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B3_B6_SPATIAL_REUSE_1 = 0x00001e00, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B7_B10_SPATIAL_REUSE_2 = 0x0001e000, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B11_B15_DISREGARD = 0x003e0000, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B16_B19_CRC = 0x03c00000, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B20_B25_TAIL = 0xfc000000, +}; + +enum ieee80211_radiotap_uhr_usig_elr { + /* USIG-1 */ + IEEE80211_RADIOTAP_UHR_USIG1_ELR_B20_B24_DISREGARD = 0x0000001f, + IEEE80211_RADIOTAP_UHR_USIG1_ELR_B25_VALIDATE = 0x00000020, + + /* USIG-2 */ + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B0_B1_PPDU_TYPE = 0x000000c0, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B2_B12_STA_ID = 0x0007ff00, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B13_B15_VALIDATE = 0x00380000, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B16_B19_CRC = 0x03c00000, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B20_B25_TAIL = 0xfc000000, +}; + /* * ieee80211_radiotap_uhr_elr - content of UHR-ELR TLV (type 37) * see https://www.radiotap.org/fields/UHR-ELR for details From 4b7ad021a981c2e1c6b7b65ab8f03d24a7173042 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Mon, 21 Sep 2026 22:54:54 +0300 Subject: [PATCH 0829/2126] wifi: nl80211: defer AP beacon regulatory check to start_ap Defer the cfg80211_reg_can_beacon_relax() check from __nl80211_set_channel() for AP and P2P-GO. At __nl80211_set_channel() stage AP type is not fully known before start_ap, so this early check incorrectly rejects valid VLP AP bring-up. start_ap has the required AP context and already performs the regulatory validation, so start checking after start_ap. This way, VLP APs can be brought up. Also handle the CSA scenario by running regulatory beaconing validation during channel switch and preserving/updating AP reg_power across CSA completion. Signed-off-by: Pagadala Yesu Anjaneyulu Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260921224731.67fbc8a28a2c.I5633284cb4c82ffb4e4e32e6f2dcc9a71fd5b06a@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 2 ++ net/wireless/ap.c | 7 +++---- net/wireless/nl80211.c | 31 ++++++++++++++++++++++++++----- net/wireless/reg.c | 9 +++++++-- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 0b3fcb2a9576..b603f1804cc2 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -7371,6 +7371,8 @@ struct wireless_dev { union { struct { unsigned int beacon_interval; + enum ieee80211_ap_reg_power reg_power; + enum ieee80211_ap_reg_power csa_reg_power; struct cfg80211_chan_def chandef; } ap; struct { diff --git a/net/wireless/ap.c b/net/wireless/ap.c index 9a9a870806f5..fa5441987a90 100644 --- a/net/wireless/ap.c +++ b/net/wireless/ap.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Parts of this file are - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2023, 2026 Intel Corporation */ #include #include @@ -33,9 +33,8 @@ static int ___cfg80211_stop_ap(struct cfg80211_registered_device *rdev, err = rdev_stop_ap(rdev, dev, link_id); if (!err) { wdev->conn_owner_nlportid = 0; - wdev->links[link_id].ap.beacon_interval = 0; - memset(&wdev->links[link_id].ap.chandef, 0, - sizeof(wdev->links[link_id].ap.chandef)); + memset(&wdev->links[link_id].ap, 0, + sizeof(wdev->links[link_id].ap)); wdev->u.ap.ssid_len = 0; rdev_set_qos_map(rdev, dev, NULL); if (notify) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 91e26b93a523..ae994568c86e 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -4156,12 +4156,17 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, switch (iftype) { case NL80211_IFTYPE_AP: case NL80211_IFTYPE_P2P_GO: - if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, - iftype)) - return -EINVAL; if (wdev->links[link_id].ap.beacon_interval) { struct ieee80211_channel *cur_chan; + struct cfg80211_beaconing_check_config config = { + .iftype = iftype, + .reg_power = wdev->links[link_id].ap.reg_power, + .relax = true, + }; + if (!cfg80211_reg_check_beaconing(&rdev->wiphy, + &chandef, &config)) + return -EINVAL; if (!dev || !rdev->ops->set_ap_chanwidth || !(rdev->wiphy.features & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) @@ -7397,6 +7402,7 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) params->beacon.tail_len, 0); if (!cfg80211_reg_check_beaconing(&rdev->wiphy, ¶ms->chandef, &beacon_check)) { + GENL_SET_ERR_MSG(info, "Channel rejected by regulatory"); err = -EINVAL; goto out; } @@ -7511,6 +7517,7 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) err = rdev_start_ap(rdev, dev, params); if (!err) { wdev->links[link_id].ap.beacon_interval = params->beacon_interval; + wdev->links[link_id].ap.reg_power = beacon_check.reg_power; wdev->links[link_id].ap.chandef = params->chandef; wdev->u.ap.ssid_len = params->ssid_len; memcpy(wdev->u.ap.ssid, params->ssid, @@ -7603,6 +7610,8 @@ static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) } err = rdev_change_beacon(rdev, dev, params); + if (!err) + wdev->links[link_id].ap.reg_power = beacon_check.reg_power; out: kfree(params->beacon.mbssid_ies); @@ -12314,6 +12323,7 @@ static int nl80211_parse_counter_offsets(struct cfg80211_registered_device *rdev static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct cfg80211_beaconing_check_config beacon_check = {}; unsigned int link_id = nl80211_link_id(info->attrs); struct net_device *dev = info->user_ptr[1]; struct wireless_dev *wdev = dev->ieee80211_ptr; @@ -12438,8 +12448,13 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) goto free; skip_beacons: - if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, - wdev->iftype)) { + beacon_check.iftype = wdev->iftype; + beacon_check.relax = true; + beacon_check.reg_power = + cfg80211_get_6ghz_power_type(params.beacon_after.tail, + params.beacon_after.tail_len, 0); + if (!cfg80211_reg_check_beaconing(&rdev->wiphy, ¶ms.chandef, + &beacon_check)) { err = -EINVAL; goto free; } @@ -12475,6 +12490,10 @@ skip_beacons: params.link_id = link_id; err = rdev_channel_switch(rdev, dev, ¶ms); + if (!err && (wdev->iftype == NL80211_IFTYPE_AP || + wdev->iftype == NL80211_IFTYPE_P2P_GO)) + wdev->links[link_id].ap.csa_reg_power = beacon_check.reg_power; + free: kfree(params.beacon_after.mbssid_ies); kfree(params.beacon_csa.mbssid_ies); @@ -22747,6 +22766,8 @@ void cfg80211_ch_switch_notify(struct net_device *dev, case NL80211_IFTYPE_AP: case NL80211_IFTYPE_P2P_GO: wdev->links[link_id].ap.chandef = *chandef; + wdev->links[link_id].ap.reg_power = + wdev->links[link_id].ap.csa_reg_power; break; case NL80211_IFTYPE_ADHOC: wdev->u.ibss.chandef = *chandef; diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 11665e0a7efc..035b95508565 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -2361,6 +2361,10 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev) } for (link = 0; link < ARRAY_SIZE(wdev->links); link++) { + struct cfg80211_beaconing_check_config config = { + .iftype = iftype, + .relax = true, + }; struct ieee80211_channel *chan; if (!wdev->valid_links && link > 0) @@ -2373,6 +2377,7 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev) if (!wdev->links[link].ap.beacon_interval) continue; chandef = wdev->links[link].ap.chandef; + config.reg_power = wdev->links[link].ap.reg_power; break; case NL80211_IFTYPE_MESH_POINT: if (!wdev->u.mesh.beacon_interval) @@ -2426,8 +2431,8 @@ static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev) case NL80211_IFTYPE_P2P_GO: case NL80211_IFTYPE_ADHOC: case NL80211_IFTYPE_MESH_POINT: - ret = cfg80211_reg_can_beacon_relax(wiphy, &chandef, - iftype); + ret = cfg80211_reg_check_beaconing(wiphy, &chandef, + &config); if (!ret) return ret; break; From e01f1c70e47ec76e8d77d3413eff86bab6c84b4c Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Mon, 21 Sep 2026 22:54:55 +0300 Subject: [PATCH 0830/2126] wifi: nl80211: reject color-change requests that change 6 GHz power type AP power type is regulatory operating state, so changing it requires full AP reconfiguration and validation. Allowing it through color-change could bypass stricter checks done in AP setup. Keep color-change behavior limited to color updates only. Signed-off-by: Pagadala Yesu Anjaneyulu Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260921224731.1d8727ce4fbf.I1049058ae5e60b7ebcb450d03f6b13cee573eeea@changeid Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index ae994568c86e..58d336498125 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -19085,6 +19085,7 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) struct cfg80211_color_change_settings params = {}; struct net_device *dev = info->user_ptr[1]; struct wireless_dev *wdev = dev->ieee80211_ptr; + enum ieee80211_ap_reg_power reg_power; struct nlattr **tb; u16 offset; int err; @@ -19186,6 +19187,15 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) goto out; } + reg_power = + cfg80211_get_6ghz_power_type(params.beacon_color_change.tail, + params.beacon_color_change.tail_len, 0); + if (wdev->links[params.link_id].ap.reg_power != reg_power) { + GENL_SET_ERR_MSG(info, "6 GHz power type change not allowed"); + err = -EINVAL; + goto out; + } + err = rdev_color_change(rdev, dev, ¶ms); out: From 12bc27e79a8ddab8ee6d900dae712d7c10231faf Mon Sep 17 00:00:00 2001 From: Rory Little Date: Mon, 21 Sep 2026 14:04:41 -0700 Subject: [PATCH 0831/2126] wifi: cfg80211: validate monitor channel set against radio usage Current logic only looks globally at interface counts to validate that a monitor can have its channel configured. This works to ensure that the wiphy is not pulled off the channel currently being used by another active interface, but fails to allow for the case where the channels in use on the other active interface and the desired channel for the monitor fall on disjoint sets of radios. Instead, search for any interface which would cause conflict, otherwise allowing for the configuration. Suggested-by: Dylan Eskew Signed-off-by: Rory Little Link: https://patch.msgid.link/20260921210441.3137-1-roryl@candelatech.com Signed-off-by: Johannes Berg --- net/wireless/chan.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/net/wireless/chan.c b/net/wireless/chan.c index 1071e823108b..c743b6fb7e30 100644 --- a/net/wireless/chan.c +++ b/net/wireless/chan.c @@ -1810,13 +1810,44 @@ bool cfg80211_reg_check_beaconing(struct wiphy *wiphy, } EXPORT_SYMBOL(cfg80211_reg_check_beaconing); +static bool cfg80211_can_set_monitor_channel(struct cfg80211_registered_device *rdev, + struct cfg80211_chan_def *chandef) +{ + struct wireless_dev *wdev; + int radio_idx; + + lockdep_assert_held(&rdev->wiphy.mtx); + + if (rdev->num_running_monitor_ifaces < 1) + return false; + + if (cfg80211_has_monitors_only(rdev)) + return true; + + radio_idx = cfg80211_get_radio_idx_by_chan(&rdev->wiphy, chandef->chan); + /* No defined radio covers this channel. Fall back on global behavior */ + if (radio_idx < 0) + return false; + + list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->iftype == NL80211_IFTYPE_MONITOR) + continue; + if (!wdev->netdev) + continue; + if (rdev_get_radio_mask(rdev, wdev->netdev) & BIT(radio_idx)) + return false; + } + + return true; +} + int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev, struct net_device *dev, struct cfg80211_chan_def *chandef) { if (!rdev->ops->set_monitor_channel) return -EOPNOTSUPP; - if (!cfg80211_has_monitors_only(rdev)) + if (!cfg80211_can_set_monitor_channel(rdev, chandef)) return -EBUSY; return rdev_set_monitor_channel(rdev, dev, chandef); From 6571b6a24cc37c650a1815b1c320e30db5de466f Mon Sep 17 00:00:00 2001 From: Ginger Li Date: Tue, 22 Sep 2026 13:42:53 +0800 Subject: [PATCH 0832/2126] wifi: mac80211: Fix a race when expiring a mesh path My static analyzer identified a potential issue in 'net/mac80211/mesh_pathtbl.c': mpath_expired() reads mpath->flags and mpath->exp_time without holding mpath->state_lock, while mesh_path_fix_nexthop() and the other writers update both fields under that lock. In mpath_lookup() and __mesh_path_lookup_by_idx() the unlocked check is followed by taking the lock and clearing MESH_PATH_ACTIVE, so the check and the update are not atomic: CPU0 (mpath_lookup) CPU1 (mesh_path_fix_nexthop) mpath_expired() reads the stale flags/exp_time and returns true spin_lock_bh(&mpath->state_lock) mpath->exp_time = 0; mpath->flags = FIXED|SN_VALID; mesh_path_activate(mpath); spin_unlock_bh(&mpath->state_lock) spin_lock_bh(&mpath->state_lock) mpath->flags &= ~MESH_PATH_ACTIVE; spin_unlock_bh(&mpath->state_lock) A path which mesh_path_fix_nexthop() has just set up as MESH_PATH_FIXED and MESH_PATH_ACTIVE then has MESH_PATH_ACTIVE cleared again, and forwarding to that destination silently stops. Take mpath->state_lock before evaluating mpath_expired() so that the check and the clearing of MESH_PATH_ACTIVE are atomic with respect to the writers. Fixes: 60854fd94573 ("mac80211: mesh: convert path table to rhashtable") Signed-off-by: Ginger Li Link: https://patch.msgid.link/20260922054253.11976-1-ginger.jzllee@gmail.com Signed-off-by: Johannes Berg --- net/mac80211/mesh_pathtbl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c index a9c5a3250edb..0c3c24a2f0cc 100644 --- a/net/mac80211/mesh_pathtbl.c +++ b/net/mac80211/mesh_pathtbl.c @@ -247,9 +247,10 @@ static struct mesh_path *mpath_lookup(struct mesh_table *tbl, const u8 *dst, mpath = rhashtable_lookup(&tbl->rhead, dst, mesh_rht_params); - if (mpath && mpath_expired(mpath)) { + if (mpath) { spin_lock_bh(&mpath->state_lock); - mpath->flags &= ~MESH_PATH_ACTIVE; + if (mpath_expired(mpath)) + mpath->flags &= ~MESH_PATH_ACTIVE; spin_unlock_bh(&mpath->state_lock); } return mpath; @@ -290,11 +291,11 @@ __mesh_path_lookup_by_idx(struct mesh_table *tbl, int idx) if (!mpath) return NULL; - if (mpath_expired(mpath)) { - spin_lock_bh(&mpath->state_lock); + spin_lock_bh(&mpath->state_lock); + if (mpath_expired(mpath)) mpath->flags &= ~MESH_PATH_ACTIVE; - spin_unlock_bh(&mpath->state_lock); - } + spin_unlock_bh(&mpath->state_lock); + return mpath; } From e6c32e485f8296596b6a9741cb00f31e13dbc5de Mon Sep 17 00:00:00 2001 From: Andrei Otcheretianski Date: Tue, 22 Sep 2026 13:23:16 +0300 Subject: [PATCH 0833/2126] wifi: cfg80211: fix NAN local schedule update ordering and allocation In cfg80211_nan_set_local_schedule(), after calling the driver, the old channel definitions were freed and only then the new ones were allocated and stored. This had two problems: - On allocation failure the previous channel definitions had already been freed while the driver had already applied the new schedule, leaving the wdev with no channel definitions. - If the driver completes a deferred schedule update synchronously, the completion notification to user space fired before the new channel definitions were stored, exposing an inconsistent state. Allocate and fill the new channel definitions before calling the driver, swap them in, and roll back on failure. Also set the pending flag before the driver call so that a synchronous deferred completion can clear it. Signed-off-by: Andrei Otcheretianski Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260922132247.d0665fa8a5c1.I0b45103342d4a911142a2325b9259258758a0670@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 52 +++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index 3ac3b2a67a9c..dc1e0522340a 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -312,6 +312,8 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, struct cfg80211_nan_local_sched *sched) { + struct cfg80211_chan_def *chandefs = NULL, *old_chandefs; + u8 old_n_channels; int ret; lockdep_assert_held(&rdev->wiphy.mtx); @@ -322,28 +324,42 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev, if (wdev->u.nan.sched_update_pending) return -EBUSY; - ret = rdev_nan_set_local_sched(rdev, wdev, sched); - if (ret) - return ret; + /* + * Pre-allocate chandefs, so we don't ruin the current + * schedule on allocation failure. + */ + if (sched->n_channels) { + chandefs = kcalloc(sched->n_channels, sizeof(*chandefs), + GFP_KERNEL); + if (!chandefs) + return -ENOMEM; + for (int i = 0; i < sched->n_channels; i++) + chandefs[i] = sched->nan_channels[i].chandef; + } + + /* + * Swap in the new chandefs before calling the driver and set the + * deferred flag, so if the driver completes the update synchronously + * the new schedule will be already in place. + */ + old_chandefs = wdev->u.nan.chandefs; + old_n_channels = wdev->u.nan.n_channels; + wdev->u.nan.chandefs = chandefs; + wdev->u.nan.n_channels = sched->n_channels; wdev->u.nan.sched_update_pending = sched->deferred; - kfree(wdev->u.nan.chandefs); - wdev->u.nan.chandefs = NULL; - wdev->u.nan.n_channels = 0; + ret = rdev_nan_set_local_sched(rdev, wdev, sched); + if (ret) { + /* Restore the previous schedule on failure */ + wdev->u.nan.sched_update_pending = false; + wdev->u.nan.chandefs = old_chandefs; + wdev->u.nan.n_channels = old_n_channels; + kfree(chandefs); + return ret; + } - if (!sched->n_channels) - return 0; - - wdev->u.nan.chandefs = kzalloc_objs(*wdev->u.nan.chandefs, - sched->n_channels); - if (!wdev->u.nan.chandefs) - return -ENOMEM; - - for (int i = 0; i < sched->n_channels; i++) - wdev->u.nan.chandefs[i] = sched->nan_channels[i].chandef; - - wdev->u.nan.n_channels = sched->n_channels; + kfree(old_chandefs); return 0; } From 6c05e2aac50fc009e0c6fa16fcace0411411c640 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 13:37:17 +0300 Subject: [PATCH 0834/2126] wifi: cfg80211: require zero terminator in valid_regdb country table valid_regdb() walks the regulatory.db country table and returns true as soon as either: - a zero coll_ptr entry (the required terminator) is found, or - the next country entry would no longer fit in the buffer. The second case silently accepts a database image whose country table reaches the end of the buffer without a zero-terminator. The callers of valid_regdb() assume that every country is zero terminated. Exit immediately upon zero terminator, don't accept a database without a zero terminator. Assisted-by: GitHubCopilot:GPT-5.3-Codex Signed-off-by: Emmanuel Grumbach Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260922133709.3d75b1440a1b.Ib92fa3a47e4cd5109c6139e9a4aac85c50f9be22@changeid Signed-off-by: Johannes Berg --- net/wireless/reg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 035b95508565..b7ef479a74f0 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -820,13 +820,13 @@ static bool valid_regdb(const u8 *data, unsigned int size) country = &hdr->country[0]; while ((u8 *)(country + 1) <= data + size) { if (!country->coll_ptr) - break; + return true; if (!valid_country(data, size, country)) return false; country++; } - return true; + return false; } static void set_wmm_rule(const struct fwdb_header *db, From cb578a044de27445c993d690bcdc9259be58d056 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 13:56:19 +0300 Subject: [PATCH 0835/2126] wifi: cfg80211: use sysfs_emit_at() in addresses_show This is now the standard way to print data for sysfs read callbacks. Assisted-by: GitHubCopilot:GPT-5.3-Codex Signed-off-by: Emmanuel Grumbach Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260922135556.49646df6da77.If5066fce4d8f42221009e77d76c68132e18c6a0d@changeid Signed-off-by: Johannes Berg --- net/wireless/sysfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c index 3ec25d3f004e..89ca3f080b7c 100644 --- a/net/wireless/sysfs.c +++ b/net/wireless/sysfs.c @@ -5,7 +5,7 @@ * * Copyright 2005-2006 Jiri Benc * Copyright 2006 Johannes Berg - * Copyright (C) 2020-2021, 2023-2024 Intel Corporation + * Copyright (C) 2020-2021, 2023-2024, 2026 Intel Corporation */ #include @@ -52,16 +52,16 @@ static ssize_t addresses_show(struct device *dev, char *buf) { struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy; - char *start = buf; - int i; + int i, len = 0; if (!wiphy->addresses) - return sprintf(buf, "%pM\n", wiphy->perm_addr); + return sysfs_emit(buf, "%pM\n", wiphy->perm_addr); for (i = 0; i < wiphy->n_addresses; i++) - buf += sprintf(buf, "%pM\n", wiphy->addresses[i].addr); + len += sysfs_emit_at(buf, len, "%pM\n", + wiphy->addresses[i].addr); - return buf - start; + return len; } static DEVICE_ATTR_RO(addresses); From 55ab5eccd1a5ec98416b611c5aa6fdb4c9b51062 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Tue, 22 Sep 2026 14:01:51 +0300 Subject: [PATCH 0836/2126] wifi: nl80211: allow a NAN peer schedule with 2 channels in the same slot A NAN peer that has dual radio can schedule a slot to 2 different channels. Until now, for single radio devices, we disallowed such a peer schedule. This was done so because the assumption was that the user space needs to pick one of the channels for us, according to its logic. But for devices that have their ULW logic offloaded, it can be useful if we program it with the full information and let it decide what to do. For example: - peer has slot S scheduled to C1 and C2 - local schedule has S scheduled to C1 - in practice, the device is on C2 at S, for example due to non-NAN activity In that case, this extra information can actually be useful to the device, and bring to more efficient usage of the time. Allow a peer schedule that has a single slot scheduled to two different channels. Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260922140131.6c3e3f552bda.I056644aaeea3f96605272651c4108e9ff224caf1@changeid Signed-off-by: Johannes Berg --- include/uapi/linux/nl80211.h | 10 ++++++---- net/wireless/nl80211.c | 23 ++--------------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index be9e2842a736..75d4c5d6a7a3 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1406,10 +1406,12 @@ * be provided. * Each peer channel must be compatible with at least one local channel * set by %NL80211_CMD_SET_LOCAL_NAN_SCHED. Different maps must not - * contain compatible channels. - * For single-radio devices (n_radio <= 1), different maps must not - * schedule the same time slot, as the device cannot operate on multiple - * channels simultaneously. + * contain compatible channels. Two maps may schedule the same time slot. + * The device decides at runtime which of the channels to follow. + * For example, the local schedule may place slot S on channel c1 while + * the peer advertises slot S on both c1 and c2. If the device is anyway + * on c2 during slot S (e.g. via the ULW mechanism for non-NAN activity), + * it may use slot S on c2 to communicate with the peer. * When updating an existing peer schedule, the full new schedule must be * provided - partial updates are not supported. The new schedule will * completely replace the previous one. diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 58d336498125..16c63383923b 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -17566,8 +17566,7 @@ nl80211_parse_nan_peer_map(struct genl_info *info, struct nlattr *map_attr, map->schedule, n_channels); } -static int nl80211_nan_validate_map_pair(struct wiphy *wiphy, - struct genl_info *info, +static int nl80211_nan_validate_map_pair(struct genl_info *info, const struct cfg80211_nan_peer_map *map1, const struct cfg80211_nan_peer_map *map2, struct cfg80211_nan_channel *nan_channels) @@ -17602,24 +17601,6 @@ static int nl80211_nan_validate_map_pair(struct wiphy *wiphy, } } - /* - * Check for conflicting time slots between maps. - * Only check for single-radio devices (n_radio <= 1) which cannot - * operate on multiple channels simultaneously. - */ - if (wiphy->n_radio > 1) - return 0; - - for (int i = 0; i < ARRAY_SIZE(map1->schedule); i++) { - if (map1->schedule[i] != NL80211_NAN_SCHED_NOT_AVAIL_SLOT && - map2->schedule[i] != NL80211_NAN_SCHED_NOT_AVAIL_SLOT) { - NL_SET_ERR_MSG_FMT(info->extack, - "Maps %u and %u both schedule slot %d", - map1->map_id, map2->map_id, i); - return -EINVAL; - } - } - return 0; } @@ -17736,7 +17717,7 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb, /* Validate against previous maps */ for (int j = 0; j < n_maps; j++) { - ret = nl80211_nan_validate_map_pair(&rdev->wiphy, info, + ret = nl80211_nan_validate_map_pair(info, &sched.maps[j], &sched.maps[n_maps], nan_channels); From dc16bea6fee807b8c176e519a0eb27c77279062e Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Tue, 22 Sep 2026 14:41:29 +0300 Subject: [PATCH 0837/2126] wifi: mac80211: Restrict probe request rates for minimal content When IEEE80211_PROBE_FLAG_MIN_CONTENT is set, restrict the probe request supported rates per Draft P802.11bi D5.0 specification: - 2 GHz: only include 1, 2, 5.5, 6, 11, 12, 24 Mb/s - 5/6 GHz: only include 6, 12, 24 Mb/s Also skip the Extended Supported Rates element for minimal content probes. Signed-off-by: Ilan Peer Assisted-by: GitHub-Copilot:claude-opus-4-6 Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260922143146.13a6fab60516.I3ebb1fa5d41622b1a0ddf9d008328fc19ad980a1@changeid [drop strange comment about extended element] Signed-off-by: Johannes Berg --- net/mac80211/util.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/net/mac80211/util.c b/net/mac80211/util.c index c193a75ef06e..9e1749d2e427 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -1283,6 +1283,28 @@ static int ieee80211_put_preq_ies_band(struct sk_buff *skb, if (band == NL80211_BAND_S1GHZ) return ieee80211_put_s1g_cap(skb, &sband->s1g_cap); + /* + * For EPP minimal content probes, restrict supported rates: + * - 2 GHz: only 1, 2, 5.5, 6, 11, 12, 24 Mb/s + * - 5/6 GHz: only 6, 12, 24 Mb/s + */ + if (flags & IEEE80211_PROBE_FLAG_MIN_CONTENT) { + for (i = 0; i < sband->n_bitrates; i++) { + u16 rate = sband->bitrates[i].bitrate; + + if (band == NL80211_BAND_2GHZ) { + if (rate != 10 && rate != 20 && + rate != 55 && rate != 60 && + rate != 110 && rate != 120 && + rate != 240) + rate_mask &= ~BIT(i); + } else { + if (rate != 60 && rate != 120 && rate != 240) + rate_mask &= ~BIT(i); + } + } + } + err = ieee80211_put_srates_elem(skb, sband, 0, ~rate_mask, WLAN_EID_SUPP_RATES); if (err) From b4f12aa3163d96ae08f58b9c17028f3bcc431a7d Mon Sep 17 00:00:00 2001 From: Andrei Otcheretianski Date: Tue, 22 Sep 2026 14:44:03 +0300 Subject: [PATCH 0838/2126] wifi: mac80211_hwsim: Support NAN deferred schedule completion Simulate firmware completing a deferred NAN schedule update in mac80211_hwsim by calling ieee80211_nan_sched_update_done() from a delayed work, so that the completion notification reaches user space after the update request returns, as it would with real hardware. This doesn't really implement the schedule update flow and doesn't announce anything to the peers. However, it should be good enough meanwhile for some minimal testing. Signed-off-by: Andrei Otcheretianski Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260922144356.81f62b390ef6.I21654fe82a0065a055a1b958297b2beb4337a1f0@changeid Signed-off-by: Johannes Berg --- .../net/wireless/virtual/mac80211_hwsim_nan.c | 22 +++++++++++++++++++ .../net/wireless/virtual/mac80211_hwsim_nan.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c index 7be64c45babf..2d9f6d7b9251 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c @@ -906,6 +906,18 @@ mac80211_hwsim_nan_discovery_beacon_timer(struct hrtimer *timer) return HRTIMER_RESTART; } +static void +mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy, + struct wiphy_work *work) +{ + struct mac80211_hwsim_data *data = + container_of(work, struct mac80211_hwsim_data, + nan.sched_update_work.work); + + if (data->nan.device_vif) + ieee80211_nan_sched_update_done(data->nan.device_vif); +} + int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct cfg80211_nan_conf *conf) @@ -922,6 +934,9 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, data->nan.device_vif = vif; data->nan.bands = conf->bands; + wiphy_delayed_work_init(&data->nan.sched_update_work, + mac80211_hwsim_nan_sched_update_work); + scoped_guard(spinlock_bh, &data->nan.state_lock) { /* Start in the "scan" phase and stay there for a little bit */ data->nan.phase = MAC80211_HWSIM_NAN_PHASE_SCAN; @@ -960,6 +975,7 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw, hrtimer_cancel(&data->nan.slot_timer); hrtimer_cancel(&data->nan.resume_txqs_timer); hrtimer_cancel(&data->nan.discovery_beacon_timer); + wiphy_delayed_work_cancel(hw->wiphy, &data->nan.sched_update_work); data->nan.device_vif = NULL; return 0; @@ -1296,6 +1312,12 @@ void mac80211_hwsim_nan_local_sched_changed(struct ieee80211_hw *hw, } spin_unlock_bh(&data->nan.state_lock); + + /* Simulate firmware completing a deferred schedule update */ + if (vif->cfg.nan_sched.deferred) + wiphy_delayed_work_queue(hw->wiphy, + &data->nan.sched_update_work, + msecs_to_jiffies(10)); } int mac80211_hwsim_nan_peer_sched_changed(struct ieee80211_hw *hw, diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h index 81e105ac7b8e..2801a1d8dcf0 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h @@ -59,6 +59,9 @@ struct mac80211_hwsim_nan_data { * available in that slot (except DW which is implicit). */ struct cfg80211_chan_def local_sched[CFG80211_NAN_SCHED_NUM_TIME_SLOTS]; + + /* Simulates the firmware completing a deferred schedule update */ + struct wiphy_delayed_work sched_update_work; }; enum hrtimer_restart From 930336208fe2c7fd1ef283f9899ae3674224d40b Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 22 Sep 2026 14:48:37 +0200 Subject: [PATCH 0839/2126] wifi: mac80211: mesh: don't send peering close in listen In listen state, nothing has been sent, so there's no need to send a WLAN_SP_MESH_PEERING_CLOSE frame. Also, in case the station just failed to insert, e.g. due to a missing channel context, it might not be possible to transmit the frame at all, leading to a warning. Reported-by: syzbot+8bd4574e8c52c48c2595@syzkaller.appspotmail.com Link: https://patch.msgid.link/20260922144838.b1b35f44b069.I80ab9ad25eb48d291807ca968fcba6b64d8fb6ab@changeid Signed-off-by: Johannes Berg --- net/mac80211/mesh_plink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c index 268857467f29..6ce3ae3fb39b 100644 --- a/net/mac80211/mesh_plink.c +++ b/net/mac80211/mesh_plink.c @@ -399,11 +399,13 @@ u64 mesh_plink_deactivate(struct sta_info *sta) { struct ieee80211_sub_if_data *sdata = sta->sdata; u64 changed; + bool send_close; spin_lock_bh(&sta->mesh->plink_lock); + send_close = sta->mesh->plink_state != NL80211_PLINK_LISTEN; changed = __mesh_plink_deactivate(sta); - if (!sdata->u.mesh.user_mpm) { + if (!sdata->u.mesh.user_mpm && send_close) { sta->mesh->reason = WLAN_REASON_MESH_PEER_CANCELED; mesh_plink_frame_tx(sdata, sta, WLAN_SP_MESH_PEERING_CLOSE, sta->sta.addr, sta->mesh->llid, From 5cb31978dddd15e51112500000d48f02279118bb Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 22 Sep 2026 14:48:45 +0200 Subject: [PATCH 0840/2126] wifi: mac80211: fix potential ack-skb leak on error path In case this warning hits, which shouldn't but could at least due to an unrelated mesh bug, an ack SKB will not be freed correctly if present. Fix that. Reported-by: syzbot+ac648b0525be1feba506@syzkaller.appspotmail.com Link: https://patch.msgid.link/20260922144845.729cf61a017b.Iabf0248920a1e70c9f6f321fbf163fc10e5f0884@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 83b758724edf..e897116f8b7e 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -6552,7 +6552,7 @@ void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, rcu_dereference(sdata->vif.bss_conf.chanctx_conf); if (WARN_ON(!chanctx_conf)) { rcu_read_unlock(); - kfree_skb(skb); + ieee80211_free_txskb(&sdata->local->hw, skb); return; } band = chanctx_conf->def.chan->band; From 1359b631c7c8455de947b2cc44b335b0ebc84d9e Mon Sep 17 00:00:00 2001 From: Ruide Cao Date: Tue, 22 Sep 2026 23:38:54 +0800 Subject: [PATCH 0841/2126] wifi: mac80211: start next ROC after purging an interface When an interface owning the active hardware ROC is purged, a ROC queued for another interface can become the head of roc_list without being started. Subsequent requests only append to the non-empty list, so no driver work is scheduled and the entries are never freed. Flush pending ROC start work and cancel pending completion work before handing the remaining queue to the normal next-ROC path. This preserves the existing software ROC handling and avoids stale workers operating on the newly started ROC. Reported-by: Vega Assisted-by: LLM Signed-off-by: Ruide Cao Signed-off-by: Ren Wei Link: https://patch.msgid.link/6975ce9d8e9a153e8319d10e6e7c7be004d6df88.1787220252.git.vega.cover-letter@nebusec.ai Signed-off-by: Johannes Berg --- net/mac80211/offchannel.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c index 4b40b461ca78..c46cb81fab22 100644 --- a/net/mac80211/offchannel.c +++ b/net/mac80211/offchannel.c @@ -1075,10 +1075,14 @@ void ieee80211_roc_purge(struct ieee80211_local *local, struct ieee80211_sub_if_data *sdata) { struct ieee80211_roc_work *roc, *tmp; + bool start_next_roc = false; bool work_to_do = false; lockdep_assert_wiphy(local->hw.wiphy); + if (local->ops->remain_on_channel) + wiphy_work_flush(local->hw.wiphy, &local->hw_roc_start); + list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { if (sdata && roc->sdata != sdata) continue; @@ -1088,6 +1092,7 @@ void ieee80211_roc_purge(struct ieee80211_local *local, /* can race, so ignore return value */ drv_cancel_remain_on_channel(local, roc->sdata); ieee80211_roc_notify_destroy(roc); + start_next_roc = true; } else { roc->abort = true; work_to_do = true; @@ -1098,4 +1103,9 @@ void ieee80211_roc_purge(struct ieee80211_local *local, } if (work_to_do) __ieee80211_roc_work(local); + else if (start_next_roc) { + wiphy_work_cancel(local->hw.wiphy, &local->hw_roc_done); + if (!list_empty(&local->roc_list)) + ieee80211_start_next_roc(local); + } } From dbca9dfd3bfc6fd3592a0fee997bf418f805c321 Mon Sep 17 00:00:00 2001 From: Tianchu Chen Date: Wed, 23 Sep 2026 14:43:51 +0000 Subject: [PATCH 0842/2126] wifi: mwifiex: bound SDIO fw dump count by memory table size mwifiex_sdio_fw_dump() reads the number of memory regions (dump_num) from a device register and uses it to index the static 15-entry mem_type_mapping_tbl[] without any bounds check. A bogus device can report a dump_num larger than the table; each out-of-table loop iteration then reads entry->mem_name and entry->done_flag and stores a vmalloc pointer and a device-controlled size past the end of the table, into adjacent .data (up to ~5.6KiB when dump_num is 255). The dump path runs after command timeouts or firmware crashes, so a bogus device can first force an error to trigger the dump and then report a bogus dump_num. Limit dump_num to the table size instead of aborting the dump. This is not expected to change the behavior on normal devices. Discovered by Atuin - Automated Vulnerability Discovery Engine. Assisted-by: LLM Signed-off-by: Tianchu Chen Acked-by: Brian Norris Link: https://patch.msgid.link/33a45fd59b5569cbce79142d2e012e191989ec26@linux.dev Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/mwifiex/sdio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c index f039d6f19183..c15d6e1dd8f6 100644 --- a/drivers/net/wireless/marvell/mwifiex/sdio.c +++ b/drivers/net/wireless/marvell/mwifiex/sdio.c @@ -2795,6 +2795,9 @@ static void mwifiex_sdio_fw_dump(struct mwifiex_adapter *adapter) mwifiex_dbg(adapter, ERROR, "SDIO read memory length err\n"); goto done; } + /* Limit the dump count to the memory table size */ + if (dump_num > ARRAY_SIZE(mem_type_mapping_tbl)) + dump_num = ARRAY_SIZE(mem_type_mapping_tbl); /* Read the length of every memory which will dump */ for (idx = 0; idx < dump_num; idx++) { From d4b21975f47b13b41c2f2b29f0a2823ce40ea97a Mon Sep 17 00:00:00 2001 From: Tianchu Chen Date: Thu, 24 Sep 2026 09:03:28 +0000 Subject: [PATCH 0843/2126] wifi: cw1200: fix link_id_db OOB access via device-controlled link ID cw1200_rx_cb() stores the link ID from the device-supplied WSM header (a 4-bit field, range 0-15) into priv->action_linkid for P2P public action frames without an upper bound check. The work handler cw1200_link_id_reset() then uses it to index link_id_db[], which has only CW1200_MAX_STA_IN_AP_MODE (5) entries, so a device reporting a link ID of 6-15 makes the driver read and write cw1200_common fields past the array (a status copy and a constant store onto adjacent work/lock/timer fields), corrupting driver state. The first link ID check in the same function (used for timestamp tracking) already validates against CW1200_MAX_STA_IN_AP_MODE and degrades out-of-range IDs to untracked handling, so out-of-range link IDs on the RX path are anticipated; the P2P remap branch was missed. Add the same bound to the remap branch. This is expected to keep driver behavior unchanged in most cases: the driver itself only assigns link IDs 1..5, and a P2P public action frame carrying any other ID now degrades to the same untracked handling the first branch already applies, instead of corrupting memory. Discovered by Atuin - Automated Vulnerability Discovery Engine. Assisted-by: LLM Signed-off-by: Tianchu Chen Link: https://patch.msgid.link/969ee752d023e7431481605c320fa0636cc6f20c@linux.dev Signed-off-by: Johannes Berg --- drivers/net/wireless/st/cw1200/txrx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/st/cw1200/txrx.c b/drivers/net/wireless/st/cw1200/txrx.c index 084d52b11f5b..0e041be88bba 100644 --- a/drivers/net/wireless/st/cw1200/txrx.c +++ b/drivers/net/wireless/st/cw1200/txrx.c @@ -1036,7 +1036,7 @@ void cw1200_rx_cb(struct cw1200_common *priv, schedule_work(&priv->linkid_reset_work); } - if (link_id && p2p && + if (link_id && link_id <= CW1200_MAX_STA_IN_AP_MODE && p2p && ieee80211_is_action(frame->frame_control) && (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)) { /* Link ID already exists for the ACTION frame. From f07554557ff2dacb36e05343e54a3323d0e010e6 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 25 Sep 2026 15:07:36 +0200 Subject: [PATCH 0844/2126] wifi: b43legacy: work around stack frame size warning I came across a rare warning in the b43legacy driver while building randconfig kernels using clang-21.1.8, with KASAN enabled: drivers/net/wireless/broadcom/b43legacy/main.c:3250:12: error: stack frame size (1392) exceeds limit (1280) in 'b43legacy_wireless_core_init' [-Werror,-Wframe-larger-than] 3250 | static int b43legacy_wireless_core_init(struct b43legacy_wldev *dev) | ^ There are no actual large variables on the stack here, just excessive spills, and the code looks fine otherwise, so this is really an optimization quirk in the compiler. Marking the prepare_phy_data_for_init() function as noinline completely avoids the issue, with no function in this file using more than 200 bytes of stack space, same as without KASAN. Link: https://pastebin.com/raw/KpV124Ep # .config Link: https://pastebin.com/CxWfsBN0 # assembler output, truncated Signed-off-by: Arnd Bergmann Link: https://patch.msgid.link/20260925130749.4191347-1-arnd@kernel.org Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/b43legacy/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/b43legacy/main.c b/drivers/net/wireless/broadcom/b43legacy/main.c index 6b3e0b2bbca7..dfff3710dea3 100644 --- a/drivers/net/wireless/broadcom/b43legacy/main.c +++ b/drivers/net/wireless/broadcom/b43legacy/main.c @@ -3207,7 +3207,8 @@ static void b43legacy_wireless_core_exit(struct b43legacy_wldev *dev) ssb_bus_may_powerdown(dev->dev->bus); } -static void prepare_phy_data_for_init(struct b43legacy_wldev *dev) +static noinline_for_stack void +prepare_phy_data_for_init(struct b43legacy_wldev *dev) { struct b43legacy_phy *phy = &dev->phy; int i; From 2cee035644d18a58816c0920b9ade98ea0ec69e2 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 25 Sep 2026 17:22:18 -0700 Subject: [PATCH 0845/2126] wifi: mwifiex: Reattach interfaces on suspend failure If our .suspend() fails, we forget to unwind the early steps -- namely, re-attaching our network interfaces. This commonly occurs if, for example, we fail to program WoWLAN patterns to the device. Without this, the interface won't work again. Tested on a Rockchip RK3399 Gru/Kevin Chromebook, with Marvell 8997 PCIe WLAN. Signed-off-by: Brian Norris Link: https://patch.msgid.link/20260925172218.1.Ie4146d413a6be79caa11cf34e19b23f514ad3f5e@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/mwifiex/cfg80211.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c index e6e7739c4a3b..a30fd0c936e1 100644 --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c @@ -3566,6 +3566,14 @@ static int mwifiex_cfg80211_suspend(struct wiphy *wiphy, mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n"); done: + if (ret) { + for (i = 0; i < adapter->priv_num; i++) { + priv = adapter->priv[i]; + if (priv->netdev) + netif_device_attach(priv->netdev); + } + } + sta_priv->scan_aborting = false; return ret; } From 076e00b142a25c689862a2443bad0d1229268eca Mon Sep 17 00:00:00 2001 From: Tianchu Chen Date: Thu, 24 Sep 2026 10:19:43 +0000 Subject: [PATCH 0846/2126] wifi: libertas: fix RX OOB access from device-controlled pkt_ptr lbs_process_rxed_packet() computes the packet header pointer as skb->data + rxpd->pkt_ptr, where pkt_ptr is a 32-bit value supplied by the device, and never checks it against the packet length. The only validation (skb->len < ETH_HLEN + 8 + sizeof(struct rxpd)) bounds the total length, not pkt_ptr. A bogus device can report an arbitrary pkt_ptr: - the memcmp() against the RFC1042 header reads 6 bytes at pkt_ptr + 14, potentially past the skb buffer - if the compared bytes happen to match, the EthernetII header reconstruction writes 12 bytes at pkt_ptr + 8; - hdrchop derived from pkt_ptr is later passed to skb_pull(). Validate pkt_ptr before using it: it must leave room for a full struct rxpackethdr within the received frame. It is not expected to affect the driver behavior in most cases, only invalid pkt_ptr packets being dropped. Discovered by Atuin - Automated Vulnerability Discovery Engine. Assisted-by: LLM Signed-off-by: Tianchu Chen Link: https://patch.msgid.link/f22d4f23e5e54b1debd6038b3b75119f97920a73@linux.dev Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/libertas/rx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wireless/marvell/libertas/rx.c b/drivers/net/wireless/marvell/libertas/rx.c index c34d30f7cbe0..a9d1320d90b1 100644 --- a/drivers/net/wireless/marvell/libertas/rx.c +++ b/drivers/net/wireless/marvell/libertas/rx.c @@ -89,6 +89,15 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb) goto done; } + if (le32_to_cpu(p_rx_pd->pkt_ptr) > + skb->len - sizeof(struct rxpackethdr)) { + lbs_deb_rx("rx err: pkt_ptr beyond packet\n"); + dev->stats.rx_length_errors++; + ret = -EINVAL; + dev_kfree_skb(skb); + goto done; + } + lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n", skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr), skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr)); From e2578c2f2bc4d0d45b1a1d46bae923c2e2e2967c Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Sat, 26 Sep 2026 21:22:56 +0300 Subject: [PATCH 0847/2126] wifi: mac80211: Gracefully deauthenticate on association timeout When an association with AP times out, and the connection is an Enhanced Privacy Protection (EPP) connection where the TK is already installed, send an explicit deauthentication frame to the AP so it would clear its local state. Not doing so might impact (fail) future connection attempts with this AP (that might think that the station is still connected). This cannot be done by user space, since as part of the association timeout flow, the station and corresponding keys are removed. Assisted-by: GithubCopilot:claude-opus-5.0 Signed-off-by: Ilan Peer Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260926212249.736b01b4a76d.Ie528ea57d4d8dc8abfca406f8bae55a3902ff740@changeid Signed-off-by: Johannes Berg --- net/mac80211/mlme.c | 64 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 76c45a0eea62..3a17d1ccd32a 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -9110,6 +9110,57 @@ void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, wiphy_work_queue(local->hw.wiphy, &sdata->work); } +static void +ieee80211_assoc_timeout_teardown(struct ieee80211_sub_if_data *sdata) +{ + struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; + struct ieee80211_local *local = sdata->local; + struct ieee80211_event event = { + .type = MLME_EVENT, + .u.mlme.data = ASSOC_EVENT, + .u.mlme.status = MLME_TIMEOUT, + }; + struct sta_info *sta; + + lockdep_assert_wiphy(local->hw.wiphy); + + /* + * With an EPP station, the AP is already maintaining a state for the + * station. Send a deauthentication frame, so that the AP clears its + * state for this station (to allow additional connection attempts). + * Note that this needs to be done before the station is removed + * locally as the deauthentication frame needs to be sent encrypted. + */ + sta = sta_info_get_bss(sdata, assoc_data->ap_addr); + if (sta && sta->sta.epp_peer && + wiphy_dereference(local->hw.wiphy, sta->ptk[sta->ptk_idx])) { + u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; + struct ieee80211_prep_tx_info info = { + .subtype = IEEE80211_STYPE_DEAUTH, + .link_id = assoc_data->assoc_link_id, + }; + + drv_mgd_prepare_tx(local, sdata, &info); + + ieee80211_send_deauth_disassoc(sdata, assoc_data->ap_addr, + assoc_data->ap_addr, + IEEE80211_STYPE_DEAUTH, + WLAN_REASON_DEAUTH_LEAVING, + true, frame_buf); + + /* make sure the deauth is out before the station is removed */ + ieee80211_flush_queues(local, sdata, false); + + drv_mgd_complete_tx(local, sdata, &info); + + cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, sizeof(frame_buf), + false); + } + + ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT, NULL); + drv_event_callback(local, sdata, &event); +} + void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) { struct ieee80211_local *local = sdata->local; @@ -9192,17 +9243,8 @@ void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) time_after(jiffies, ifmgd->assoc_data->timeout)) { if ((ifmgd->assoc_data->need_beacon && !sdata->deflink.u.mgd.have_beacon) || - ieee80211_do_assoc(sdata)) { - struct ieee80211_event event = { - .type = MLME_EVENT, - .u.mlme.data = ASSOC_EVENT, - .u.mlme.status = MLME_TIMEOUT, - }; - - ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT, - NULL); - drv_event_callback(sdata->local, sdata, &event); - } + ieee80211_do_assoc(sdata)) + ieee80211_assoc_timeout_teardown(sdata); } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) run_again(sdata, ifmgd->assoc_data->timeout); From 392551884f44038a921c55ebf39acc71629c2fcd Mon Sep 17 00:00:00 2001 From: Minxi Hou Date: Fri, 18 Sep 2026 10:46:46 -0400 Subject: [PATCH 0848/2126] selftests/net/openvswitch: add SCTP flow key test over IPv6 The merged SCTP test covers only IPv4. The SCTP branch of the IPv6 extractor (the proto=132 walk after parse_ipv6hdr) and the v6 side of the SCTP netlink validation (match_validate() requires the sctp() key whenever ipv6(proto=132) is matched) have no selftest coverage. Add test_sctp_connect_v6 mirroring the v4 test: bare icmpv6() flows forward NS/NA, and ipv6(proto=132),sctp(dst=4443)/sctp(src=4443) flows gate the association in the same three phases (flows installed, removed, reinstalled). A keyless ipv6(proto=132) install must be refused with EINVAL, pinning the reject side of the match_validate() rule; without it a regression dropping the requirement would pass unnoticed. The refusal is asserted to be EINVAL specifically, not a parse error of the flow string. After the association succeeds the test also pushes a known payload across and waits for the listener to log it, proving the datapath carries the association's traffic end to end, not only its handshake. Skips when the sctp module is missing, socat lacks SCTP or IPv6 support, or IPv6 is unavailable; an association or payload failure with the flows installed fails the test. Signed-off-by: Minxi Hou Reviewed-by: Narcisa Vasile Reviewed-by: Aaron Conole Link: https://patch.msgid.link/20260918144647.2024095-2-houminxi@gmail.com Signed-off-by: Jakub Kicinski --- .../selftests/net/openvswitch/openvswitch.sh | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh index a31f7fb6882d..aa84fafc3201 100755 --- a/tools/testing/selftests/net/openvswitch/openvswitch.sh +++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh @@ -34,6 +34,7 @@ tests=" trunc trunc: output truncation icmpv6 icmpv6: ICMPv6 echo type match sctp_connect_v4 sctp: SCTP flow key matching + sctp_connect_v6 sctp6: SCTP flow keys over IPv6 psample psample: Sampling packets with psample" info() { @@ -700,6 +701,114 @@ test_sctp_connect_v4() { return 0 } +# sctp_connect_v6 test +# - sctp(dst=4443) matches client-to-server INIT +# - sctp(src=4443) matches server-to-client INIT-ACK +# - icmpv6 NS/NA flows forward neighbour discovery +# - remove flows and verify connection fails, reinstall and recover +test_sctp_connect_v6() { + local t="test_sctp_connect_v6" + local v6="eth_type(0x86dd),ipv6(proto=132)" + local payload="SCTP6_DATA_OK" + local rxfile="${ovs_base}/${t}/sctp-rx.txt" + + modprobe -q sctp 2>/dev/null || return "$ksft_skip" + socat -V 2>&1 | grep -q "define WITH_SCTP" || return "$ksft_skip" + socat -V 2>&1 | grep -q "define WITH_IP6" || return "$ksft_skip" + [ -e /proc/sys/net/ipv6 ] || return "$ksft_skip" + + sbx_add "$t" || return $? + ovs_add_dp "$t" sctp6 || return 1 + + info "create namespaces" + for ns in client server; do + ovs_add_netns_and_veths "$t" "sctp6" "$ns" \ + "${ns:0:1}0" "${ns:0:1}1" || return 1 + done + + ip netns exec client ip addr add fd00::1/64 dev c1 nodad + ip netns exec client ip link set c1 up + ip netns exec server ip addr add fd00::2/64 dev s1 nodad + ip netns exec server ip link set s1 up + + # NS/NA forwarding + ovs_add_flow "$t" sctp6 \ + 'in_port(1),eth(),eth_type(0x86dd),ipv6(proto=58),icmpv6()' \ + '2' || return 1 + ovs_add_flow "$t" sctp6 \ + 'in_port(2),eth(),eth_type(0x86dd),ipv6(proto=58),icmpv6()' \ + '1' || return 1 + + # SCTP port matching: dst for request, src for reply + ovs_add_flow "$t" sctp6 \ + "in_port(1),eth(),$v6,sctp(dst=4443)" \ + '2' || return 1 + ovs_add_flow "$t" sctp6 \ + "in_port(2),eth(),$v6,sctp(src=4443)" \ + '1' || return 1 + + # A keyless ipv6(proto=132) install must be refused (EINVAL): + # match_validate() requires the sctp() key. Pin the reject side + # of that rule; the keyed installs above cover the accept side. + # Verify the refusal is EINVAL (missing key), not a parse error. + err=$(ovs_sbx "$t" python3 $ovs_base/ovs-dpctl.py add-flow sctp6 \ + "in_port(1),eth(),$v6" '2' 2>&1 >/dev/null) \ + && { info "keyless SCTP flow should be refused" + return 1; } + echo "$err" | grep -q "(22," || { + info "keyless SCTP flow refused for wrong reason: $err" + return 1 + } + + ovs_netns_spawn_daemon "$t" "server" \ + socat -u -t 1 SCTP6-LISTEN:4443,fork \ + OPEN:"$rxfile",creat,append + ovs_wait sctp_eps_has server 4443 || return 1 + + info "verify SCTP association with port-keyed flows" + ovs_sbx "$t" ip netns exec client \ + timeout 3 socat -u STDIN "SCTP6-CONNECT:[fd00::2]:4443" /dev/null 2>&1 \ + && { info "connection should fail without flows" + return 1; } + + info "reinstall flows and verify recovery" + ovs_add_flow "$t" sctp6 \ + "in_port(1),eth(),$v6,sctp(dst=4443)" \ + '2' || return 1 + ovs_add_flow "$t" sctp6 \ + "in_port(2),eth(),$v6,sctp(src=4443)" \ + '1' || return 1 + + ovs_sbx "$t" ip netns exec client \ + timeout 3 socat -u STDIN "SCTP6-CONNECT:[fd00::2]:4443" Date: Fri, 18 Sep 2026 10:46:47 -0400 Subject: [PATCH 0849/2126] selftests/net/openvswitch: add SCTP flow key test across conntrack NAT After conntrack NAT rewrites a packet, OVS refreshes the cached flow key in ovs_nat_update_key(), which has a per-protocol branch for the L4 ports (UDP/TCP/SCTP, conntrack.c). Address-only NAT cannot tell a working SCTP branch from a missing one: the ports survive unchanged either way, so a post-recirc match on the original port stays green even with the branch deleted. The suite's NAT coverage drives TCP over nc, and the merged SCTP test has no conntrack in the path, so the SCTP branch goes unexercised. Add test_sctp_nat_connect_v4: untracked client traffic to 192.168.0.20:4443 hits ct(commit,nat(dst=172.31.110.20:5555)),recirc, and the post-recirc flows match the translated tuple, ipv4(dst=172.31.110.20),sctp(dst=5555). Reply traffic is matched on the restored original tuple, sctp(src=4443). With the SCTP branch broken the translated port never reaches the key, no post-recirc flow matches, and the association fails. The probe flow uses the same ct+nat action as the real flows, so a kernel without CONFIG_NF_NAT rejects it at flow-add time and the test skips instead of failing. The config fragment sets CONFIG_NETFILTER_ADVANCED=y so CONFIG_NF_CT_PROTO_SCTP is visible, CONFIG_NF_CT_PROTO_SCTP=y, and CONFIG_NF_NAT=m so the reference build actually has those pieces. After the association succeeds the test pushes a known payload across and waits for the listener to log it. Signed-off-by: Minxi Hou Reviewed-by: Narcisa Vasile Reviewed-by: Aaron Conole Link: https://patch.msgid.link/20260918144647.2024095-3-houminxi@gmail.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/net/openvswitch/config | 3 + .../selftests/net/openvswitch/openvswitch.sh | 93 +++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/tools/testing/selftests/net/openvswitch/config b/tools/testing/selftests/net/openvswitch/config index a825e0b5c88e..15685d242813 100644 --- a/tools/testing/selftests/net/openvswitch/config +++ b/tools/testing/selftests/net/openvswitch/config @@ -3,10 +3,13 @@ CONFIG_INET_DIAG=y CONFIG_IP_SCTP=y CONFIG_IPV6=y CONFIG_NETFILTER=y +CONFIG_NETFILTER_ADVANCED=y CONFIG_NET_IPGRE=m CONFIG_NET_IPGRE_DEMUX=m CONFIG_NF_CONNTRACK=m CONFIG_NF_CONNTRACK_OVS=y +CONFIG_NF_CT_PROTO_SCTP=y +CONFIG_NF_NAT=m CONFIG_OPENVSWITCH=m CONFIG_PSAMPLE=m CONFIG_VETH=y diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh index aa84fafc3201..21444657a040 100755 --- a/tools/testing/selftests/net/openvswitch/openvswitch.sh +++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh @@ -35,6 +35,7 @@ tests=" icmpv6 icmpv6: ICMPv6 echo type match sctp_connect_v4 sctp: SCTP flow key matching sctp_connect_v6 sctp6: SCTP flow keys over IPv6 + sctp_nat_connect_v4 sctpnat4: SCTP NAT translation psample psample: Sampling packets with psample" info() { @@ -1200,6 +1201,98 @@ test_nat_connect_v4 () { return 0 } +# sctp_nat_connect_v4 test +# - SCTP association crosses a ct(commit,nat(dst=ip:port)) DNAT +# - post-recirc flows match the translated address and port, so the +# SCTP branch of the post-NAT flow key update is load-bearing +test_sctp_nat_connect_v4 () { + local t="test_sctp_nat_connect_v4" + local payload="SCTP_NAT_DATA_OK" + local rxfile="${ovs_base}/${t}/sctp-rx.txt" + + modprobe -q sctp 2>/dev/null || return "$ksft_skip" + socat -V 2>&1 | grep -q "define WITH_SCTP" || return "$ksft_skip" + # SCTP conntrack is compiled into nf_conntrack.ko, so check that + # loading it actually exposed the SCTP conntrack sysctls. + modprobe -q nf_conntrack 2>/dev/null || return "$ksft_skip" + [ -e /proc/sys/net/netfilter/nf_conntrack_sctp_timeout_established ] \ + || { info "no SCTP conntrack support - skipping" + return "$ksft_skip"; } + + sbx_add "test_sctp_nat_connect_v4" || return $? + + ovs_add_dp "test_sctp_nat_connect_v4" sctpnat4 || return 1 + info "create namespaces" + for ns in client server; do + ovs_add_netns_and_veths "test_sctp_nat_connect_v4" "sctpnat4" \ + "$ns" "${ns:0:1}0" "${ns:0:1}1" || return 1 + done + + ip netns exec client ip addr add 172.31.110.10/24 dev c1 + ip netns exec client ip link set c1 up + ip netns exec server ip addr add 172.31.110.20/24 dev s1 + ip netns exec server ip link set s1 up + + ip netns exec client ip route add default via 172.31.110.20 + + # Check if the ct and nat actions can be configured. + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + 'in_port(1),eth(),eth_type(0x0800),ipv4()' \ + 'ct(commit,nat(dst=172.31.110.20:5555)),recirc(0x1)' \ + &> /dev/null + if [ $? == 1 ]; then + info "no support for ct/nat actions - skipping" + ovs_exit_sig + return $ksft_skip + fi + + ovs_del_flows "test_sctp_nat_connect_v4" sctpnat4 + + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1 + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1 + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + "ct_state(-trk),in_port(1),eth(),eth_type(0x0800),"\ +"ipv4(dst=192.168.0.20)" \ + "ct(commit,nat(dst=172.31.110.20:5555)),recirc(0x1)" || return 1 + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + "ct_state(-trk),in_port(2),eth(),eth_type(0x0800),ipv4()" \ + "ct(commit,nat),recirc(0x2)" || return 1 + + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + "recirc_id(0x1),ct_state(+trk-inv),in_port(1),eth(),"\ +"eth_type(0x0800),ipv4(dst=172.31.110.20,proto=132),"\ +"sctp(dst=5555)" \ + "2" || return 1 + ovs_add_flow "test_sctp_nat_connect_v4" sctpnat4 \ + "recirc_id(0x2),ct_state(+trk-inv),in_port(2),eth(),"\ +"eth_type(0x0800),ipv4(src=192.168.0.20,proto=132),"\ +"sctp(src=4443)" \ + "1" || return 1 + + ovs_netns_spawn_daemon "test_sctp_nat_connect_v4" "server" \ + socat -u -t 1 SCTP4-LISTEN:5555,fork \ + OPEN:"$rxfile",creat,append + ovs_wait sctp_eps_has server 5555 || return 1 + + info "verify SCTP association across NAT" + ovs_sbx "test_sctp_nat_connect_v4" ip netns exec client \ + timeout 3 socat -u STDIN "SCTP4-CONNECT:192.168.0.20:4443" \ + server ip packets go via SNAT # - client solicits ICMP destination unreachable packet from server From 087827628ad3d9cab31365114e8b4d6d153dfa36 Mon Sep 17 00:00:00 2001 From: Sang-Hoon Choi Date: Tue, 22 Sep 2026 03:49:28 +0900 Subject: [PATCH 0850/2126] hinic3: handle auxiliary device ID allocation failure hinic3_init_hwdev() stores the result of hinic3_adev_idx_alloc() in hwdev->dev_id without checking for an error. If ID allocation fails but the remaining initialization succeeds, hinic3_add_one_adev() uses the negative error code as the auxiliary device ID instead of a reserved ID. Return the allocation error before initializing the hardware. Add an unwind label that clears pci_adapter->hwdev and frees the allocation without attempting to release an ID that was never allocated. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Reported-by: Changyul Lee Signed-off-by: Sang-Hoon Choi Link: https://patch.msgid.link/179001656835.91284.3719235813225229273.idr-bug-81@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c b/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c index f44b3064ab2e..830bf9aadbf5 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c @@ -545,6 +545,10 @@ int hinic3_init_hwdev(struct pci_dev *pdev) hwdev->dev = &pci_adapter->pdev->dev; hwdev->func_state = 0; hwdev->dev_id = hinic3_adev_idx_alloc(); + if (hwdev->dev_id < 0) { + err = hwdev->dev_id; + goto err_free_hwdev_no_id; + } spin_lock_init(&hwdev->channel_lock); err = hinic3_init_hwif(hwdev); @@ -602,8 +606,9 @@ err_destroy_workqueue: err_free_hwif: hinic3_free_hwif(hwdev); err_free_hwdev: - pci_adapter->hwdev = NULL; hinic3_adev_idx_free(hwdev->dev_id); +err_free_hwdev_no_id: + pci_adapter->hwdev = NULL; kfree(hwdev); return err; From b0e75977c6883283b55fbbdcd64d1c7111b134f2 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:10:55 +0000 Subject: [PATCH 0851/2126] vxlan: update default fdb entries when the lower device changes vxlan_changelink() only refreshed the default fdb entries when the remote IP changed, but vxlan_config_apply() also updates default_dst.remote_ifindex when the lower device changes. A changelink that only swaps the lower device therefore left the all zeros mac rdst pointing at the old ifindex: ip link add vxlan0 type vxlan id 10 group 239.1.1.1 dev eth0 ip link set dev vxlan0 type vxlan group 239.1.1.1 dev eth1 vxlan_xmit_one() uses rdst->remote_ifindex as the route oif, so traffic kept leaving eth0. VNI filter entries have the same problem, and are worse: their fdb entries are keyed on the device remote_ifindex even when the vni carries its own group, but vxlan_vnilist_update_group() only visited the vnis without one. vxlan_vni_delete_group() later looks an entry up with the current remote_ifindex, and vxlan_fdb_find_rdst() requires an exact match, so the lookup failed and the entry survived the delete. Re-adding the same vni then appended a second rdst, duplicating transmitted BUM traffic. Likewise, in vxlan_vni_update_group(), oldrip was only set when newrip was NULL, so changing an existing VNI's group appended the new rdst without deleting the old one. Set oldrip to the previous effective remote IP whenever updating an existing VNI (!create). Pass the old and new ifindex down to vxlan_update_default_fdb_entry() so the append targets the new lower device and the delete still matches the entry created for the old one, and refresh every vni rather than only those inheriting the device group. If updating the vni list fails partway through, unwind the already updated fdb entries (still deleting the new rdst even if re-adding the old one fails) so default_dst and the fdb entries do not diverge. Also run vxlan_multicast_leave() and vxlan_multicast_join() when VXLAN_F_VNIFILTER is set so per-VNI multicast memberships are migrated even when the device default remote_ip is not multicast, and make vxlan_multicast_leave_vnigrp() skip the default group and ignore -EADDRNOTAVAIL when multiple VNIs share a multicast group. The new ifindex is the one vxlan_config_apply() will commit, which is the current one when lowerdev is NULL, so that default_dst and the fdb entries can not diverge. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260922181102.3989489-2-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 39 ++++++++++---- drivers/net/vxlan/vxlan_multicast.c | 13 ++++- drivers/net/vxlan/vxlan_private.h | 6 +++ drivers/net/vxlan/vxlan_vnifilter.c | 79 ++++++++++++++++++++++------- 4 files changed, 106 insertions(+), 31 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 7f552c98dcc5..7af38cdfb98e 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4454,6 +4454,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], struct net_device *lowerdev; struct vxlan_config conf; struct vxlan_rdst *dst; + u32 new_ifindex; int err; if (!rtnl_dev_link_net_capable(dev, vxlan->net)) @@ -4477,13 +4478,16 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], if (err) return err; + /* vxlan_config_apply() only commits remote_ifindex if lowerdev is set */ + new_ifindex = lowerdev ? conf.remote_ifindex : dst->remote_ifindex; + rem_ip_changed = !vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip); change_igmp = vxlan->dev->flags & IFF_UP && (rem_ip_changed || - dst->remote_ifindex != conf.remote_ifindex); + dst->remote_ifindex != new_ifindex); /* handle default dst entry */ - if (rem_ip_changed) { + if (rem_ip_changed || dst->remote_ifindex != new_ifindex) { spin_lock_bh(&vxlan->hash_lock); if (!vxlan_addr_any(&conf.remote_ip)) { err = vxlan_fdb_update(vxlan, all_zeros_mac, @@ -4492,7 +4496,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], NLM_F_APPEND | NLM_F_CREATE, vxlan->cfg.dst_port, conf.vni, conf.vni, - conf.remote_ifindex, + new_ifindex, NTF_SELF, 0, true, extack); if (err) { spin_unlock_bh(&vxlan->hash_lock); @@ -4511,13 +4515,21 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], true); spin_unlock_bh(&vxlan->hash_lock); - /* If vni filtering device, also update fdb entries of - * all vnis that were using default remote ip + /* If vni filtering device, also update default fdb entries of + * all vnis */ if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) { err = vxlan_vnilist_update_group(vxlan, &dst->remote_ip, - &conf.remote_ip, extack); + &conf.remote_ip, + dst->remote_ifindex, + new_ifindex, extack); if (err) { + vxlan_update_default_fdb_entry(vxlan, conf.vni, + &conf.remote_ip, + &dst->remote_ip, + new_ifindex, + dst->remote_ifindex, + NULL); netdev_adjacent_change_abort(dst->remote_dev, lowerdev, dev); return err; @@ -4525,7 +4537,9 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], } } - if (change_igmp && vxlan_addr_multicast(&dst->remote_ip)) + if (change_igmp && + (vxlan_addr_multicast(&dst->remote_ip) || + (vxlan->cfg.flags & VXLAN_F_VNIFILTER))) err = vxlan_multicast_leave(vxlan); if (netif_running(dev) && conf.age_interval != vxlan->cfg.age_interval) @@ -4536,9 +4550,14 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], dst->remote_dev = lowerdev; vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true); - if (!err && change_igmp && - vxlan_addr_multicast(&dst->remote_ip)) - err = vxlan_multicast_join(vxlan); + if (change_igmp && + (vxlan_addr_multicast(&dst->remote_ip) || + (vxlan->cfg.flags & VXLAN_F_VNIFILTER))) { + int join_err = vxlan_multicast_join(vxlan); + + if (join_err) + err = join_err; + } return err; } diff --git a/drivers/net/vxlan/vxlan_multicast.c b/drivers/net/vxlan/vxlan_multicast.c index 3b75b48dc726..b85283605aaf 100644 --- a/drivers/net/vxlan/vxlan_multicast.c +++ b/drivers/net/vxlan/vxlan_multicast.c @@ -219,10 +219,17 @@ static int vxlan_multicast_leave_vnigrp(struct vxlan_dev *vxlan) int last_err = 0, ret; list_for_each_entry_safe(v, tmp, &vg->vni_list, vlist) { - if (vxlan_addr_multicast(&v->remote_ip) && - !vxlan_group_used(vn, vxlan, v->vni, &v->remote_ip, + if (!vxlan_addr_multicast(&v->remote_ip)) + continue; + /* skip if address is same as default address */ + if (vxlan_addr_equal(&v->remote_ip, + &vxlan->default_dst.remote_ip)) + continue; + if (!vxlan_group_used(vn, vxlan, v->vni, &v->remote_ip, 0)) { ret = vxlan_igmp_leave(vxlan, &v->remote_ip, 0); + if (ret == -EADDRNOTAVAIL) + ret = 0; if (ret) last_err = ret; } @@ -259,6 +266,8 @@ int vxlan_multicast_leave(struct vxlan_dev *vxlan) !vxlan_group_used(vn, vxlan, 0, NULL, 0)) { ret = vxlan_igmp_leave(vxlan, &vxlan->default_dst.remote_ip, vxlan->default_dst.remote_ifindex); + if (ret == -EADDRNOTAVAIL) + ret = 0; if (ret) return ret; } diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index b1eec2216360..e4ceca925bde 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -213,9 +213,15 @@ void vxlan_vs_add_vnigrp(struct vxlan_dev *vxlan, struct vxlan_sock *vs, bool ipv6); void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan); +int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, + union vxlan_addr *old_remote_ip, + union vxlan_addr *remote_ip, + u32 old_ifindex, u32 new_ifindex, + struct netlink_ext_ack *extack); int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, union vxlan_addr *old_remote_ip, union vxlan_addr *new_remote_ip, + u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack); diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index dd94085e0886..336e8128be48 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -470,14 +470,19 @@ static const struct nla_policy vni_filter_policy[VXLAN_VNIFILTER_MAX + 1] = { [VXLAN_VNIFILTER_ENTRY] = { .type = NLA_NESTED }, }; -static int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, - union vxlan_addr *old_remote_ip, - union vxlan_addr *remote_ip, - struct netlink_ext_ack *extack) +int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, + union vxlan_addr *old_remote_ip, + union vxlan_addr *remote_ip, + u32 old_ifindex, u32 new_ifindex, + struct netlink_ext_ack *extack) { - struct vxlan_rdst *dst = &vxlan->default_dst; int err = 0; + if (old_remote_ip && remote_ip && + vxlan_addr_equal(old_remote_ip, remote_ip) && + old_ifindex == new_ifindex) + return 0; + spin_lock_bh(&vxlan->hash_lock); if (remote_ip && !vxlan_addr_any(remote_ip)) { err = vxlan_fdb_update(vxlan, all_zeros_mac, @@ -487,9 +492,9 @@ static int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, vxlan->cfg.dst_port, vni, vni, - dst->remote_ifindex, + new_ifindex, NTF_SELF, 0, true, extack); - if (err) { + if (err && extack) { spin_unlock_bh(&vxlan->hash_lock); return err; } @@ -500,7 +505,7 @@ static int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, *old_remote_ip, vxlan->cfg.dst_port, vni, vni, - dst->remote_ifindex, + old_ifindex, true); } spin_unlock_bh(&vxlan->hash_lock); @@ -532,11 +537,12 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, newrip = &dst->remote_ip; } - /* if old rip exists, and no newrip, - * explicitly delete old rip - */ - if (!newrip && !vxlan_addr_any(&old_remote_ip)) - oldrip = &old_remote_ip; + if (!create) { + if (!vxlan_addr_any(&old_remote_ip)) + oldrip = &old_remote_ip; + else if (!vxlan_addr_any(&dst->remote_ip)) + oldrip = &dst->remote_ip; + } if (!newrip && !oldrip) return 0; @@ -546,6 +552,8 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, ret = vxlan_update_default_fdb_entry(vxlan, vninode->vni, oldrip, newrip, + dst->remote_ifindex, + dst->remote_ifindex, extack); if (ret) goto out; @@ -560,6 +568,8 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, vxlan->default_dst.remote_ifindex)) { ret = vxlan_igmp_leave(vxlan, &old_remote_ip, 0); + if (ret == -EADDRNOTAVAIL) + ret = 0; if (ret) goto out; } @@ -583,8 +593,10 @@ out: int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, union vxlan_addr *old_remote_ip, union vxlan_addr *new_remote_ip, + u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack) { + union vxlan_addr *oldrip, *newrip; struct list_head *headp, *hpos; struct vxlan_vni_group *vg; struct vxlan_vni_node *vent; @@ -595,17 +607,46 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, headp = &vg->vni_list; list_for_each_prev(hpos, headp) { vent = list_entry(hpos, struct vxlan_vni_node, vlist); + if (vxlan_addr_any(&vent->remote_ip)) { - ret = vxlan_update_default_fdb_entry(vxlan, vent->vni, - old_remote_ip, - new_remote_ip, - extack); - if (ret) - return ret; + oldrip = old_remote_ip; + newrip = new_remote_ip; + } else { + /* A vni with its own group keeps it, but its fdb entry + * is still keyed on the device remote_ifindex. + */ + oldrip = &vent->remote_ip; + newrip = &vent->remote_ip; } + + ret = vxlan_update_default_fdb_entry(vxlan, vent->vni, + oldrip, newrip, + old_ifindex, new_ifindex, + extack); + if (ret) + goto err_unwind; } return 0; + +err_unwind: + list_for_each_continue(hpos, headp) { + vent = list_entry(hpos, struct vxlan_vni_node, vlist); + + if (vxlan_addr_any(&vent->remote_ip)) { + oldrip = old_remote_ip; + newrip = new_remote_ip; + } else { + oldrip = &vent->remote_ip; + newrip = &vent->remote_ip; + } + + vxlan_update_default_fdb_entry(vxlan, vent->vni, + newrip, oldrip, + new_ifindex, old_ifindex, + NULL); + } + return ret; } static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, From d10b7b93c5e781e1fdf159d072a787583229387b Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:10:56 +0000 Subject: [PATCH 0852/2126] vxlan: vnifilter: use list_for_each_entry_rcu() in vxlan_vnifilter_dump_dev() RTM_GETTUNNEL dumps currently run under RTNL lock, but vxlan_vnifilter_dump() also acquires rcu_read_lock(). 1) Currently vxlan_vnifilter_dump_dev() traverses vg->vni_list using list_for_each_entry_safe(). Even though RTNL is held today, writers modify vg->vni_list with list_add_rcu() and list_del_rcu(). Switch to list_for_each_entry_rcu() for proper RCU traversal and as preparation for future lockless dump support. 2) During a paginated dump, RTNL is released between dump skbs. If vxlan_vnifilter_dump_dev() returns early because VXLAN_F_VNIFILTER is not set or vg has no VNIs, cb->args[1] was not cleared. This leaked a non-zero VNI offset to subsequent devices, silently skipping their first N VNIs. Furthermore, if devices are added or removed between dump calls, ordinal device indexes can shift. Track the current device ifindex in cb->args[2] and reset cb->args[1] if the device changes. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260922181102.3989489-3-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_vnifilter.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index 336e8128be48..0a04e8875f7d 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -333,22 +333,34 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, struct sk_buff *skb, struct netlink_callback *cb) { - struct vxlan_vni_node *tmp, *v, *vbegin = NULL, *vend = NULL; + struct vxlan_vni_node *v, *vbegin = NULL, *vend = NULL; struct vxlan_dev *vxlan = netdev_priv(dev); struct tunnel_msg *new_tmsg, *tmsg; - int idx = 0, s_idx = cb->args[1]; struct vxlan_vni_group *vg; struct nlmsghdr *nlh; + int idx = 0, s_idx; bool dump_stats; int err = 0; - if (!(vxlan->cfg.flags & VXLAN_F_VNIFILTER)) + if (cb->args[2] != dev->ifindex) { + cb->args[1] = 0; + cb->args[2] = dev->ifindex; + } + s_idx = cb->args[1]; + + if (!(vxlan->cfg.flags & VXLAN_F_VNIFILTER)) { + cb->args[1] = 0; + cb->args[2] = 0; return -EINVAL; + } /* RCU needed because of the vni locking rules (rcu || rtnl) */ vg = rcu_dereference(vxlan->vnigrp); - if (!vg || !vg->num_vnis) + if (!vg || !vg->num_vnis) { + cb->args[1] = 0; + cb->args[2] = 0; return 0; + } tmsg = nlmsg_data(cb->nlh); dump_stats = !!(tmsg->flags & TUNNEL_MSG_FLAG_STATS); @@ -362,7 +374,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, new_tmsg->family = PF_BRIDGE; new_tmsg->ifindex = dev->ifindex; - list_for_each_entry_safe(v, tmp, &vg->vni_list, vlist) { + list_for_each_entry_rcu(v, &vg->vni_list, vlist) { if (idx < s_idx) { idx++; continue; @@ -394,6 +406,7 @@ update_end: } cb->args[1] = err ? idx : 0; + cb->args[2] = err ? dev->ifindex : 0; nlmsg_end(skb, nlh); From 0e75889596aa6edcf884b0079299213213fc9611 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:10:57 +0000 Subject: [PATCH 0853/2126] vxlan: vnifilter: signal interrupted RTM_GETTUNNEL dumps vxlan_vnifilter_dump() walks all vxlan devices of a netns, and for each one walks vg->vni_list. Both cursors are plain ordinals stored in cb->args[0] and cb->args[1], and RTNL is released between dump skbs. A concurrent __vxlan_vni_add_list(), which inserts sorted by VNI, __vxlan_vni_del_list(), or an in-place group update in vxlan_vni_update() (which splits or merges coalesced VNI ranges) shifts the second cursor, duplicating or skipping entries. Unregistering a vxlan device shifts the first one, and the partially dumped device is then skipped altogether by the "if (idx < s_idx)" test, silently losing the rest of its VNIs. Add a per-netns generation counter, bumped whenever the set of vxlan devices in the netns or any vni_list changes, and feed it to nl_dump_check_consistent() so that user space gets NLM_F_DUMP_INTR and can retry, as vxlan_mdb_dump() already does. The counter is keyed on dev_net(vxlan->dev) rather than vxlan->net, because the dump enumerates devices with for_each_netdev_rcu() in the netns the netdevice lives in, which differs from the packet i/o netns when the device was created with a separate link netns. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260922181102.3989489-4-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 4 ++++ drivers/net/vxlan/vxlan_private.h | 9 ++++++++ drivers/net/vxlan/vxlan_vnifilter.c | 35 ++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 7af38cdfb98e..1e5e960fce69 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4773,6 +4773,10 @@ static int vxlan_netdevice_event(struct notifier_block *unused, struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id); + if ((event == NETDEV_REGISTER || event == NETDEV_UNREGISTER) && + netif_is_vxlan(dev)) + vxlan_vnifilter_seq_inc(dev_net(dev)); + if (event == NETDEV_UNREGISTER) vxlan_handle_lowerdev_unregister(vn, dev); else if (event == NETDEV_UDP_TUNNEL_PUSH_INFO) diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index e4ceca925bde..74d713717cd5 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -22,6 +22,8 @@ struct vxlan_net { /* sock_list is protected by rtnl lock */ struct hlist_head sock_list[PORT_HASH_SIZE]; struct notifier_block nexthop_notifier_block; + /* Generation counter for RTM_GETTUNNEL dumps */ + atomic_t vnifilter_seq; }; struct vxlan_fdb_key { @@ -177,6 +179,13 @@ vxlan_vnifilter_lookup(struct vxlan_dev *vxlan, __be32 vni) vxlan_vni_rht_params); } +static inline void vxlan_vnifilter_seq_inc(const struct net *net) +{ + struct vxlan_net *vn = net_generic(net, vxlan_net_id); + + atomic_inc(&vn->vnifilter_seq); +} + /* vxlan_core.c */ int vxlan_fdb_create(struct vxlan_dev *vxlan, const u8 *mac, union vxlan_addr *ip, diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index 0a04e8875f7d..181a7614be5c 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -410,9 +410,22 @@ update_end: nlmsg_end(skb, nlh); + nl_dump_check_consistent(cb, nlh); + return err; } +static u32 vxlan_vnifilter_base_seq(const struct net *net) +{ + const struct vxlan_net *vn = net_generic(net, vxlan_net_id); + u32 res = atomic_read(&vn->vnifilter_seq); + + /* Must not return 0 (see nl_dump_check_consistent()) */ + if (!res) + res = 0x80000000; + return res; +} + static int vxlan_vnifilter_dump(struct sk_buff *skb, struct netlink_callback *cb) { int idx = 0, err = 0, s_idx = cb->args[0]; @@ -432,6 +445,9 @@ static int vxlan_vnifilter_dump(struct sk_buff *skb, struct netlink_callback *cb } rcu_read_lock(); + + cb->seq = vxlan_vnifilter_base_seq(net); + if (tmsg->ifindex) { dev = dev_get_by_index_rcu(net, tmsg->ifindex); if (!dev) { @@ -571,8 +587,11 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, if (ret) goto out; - if (group) + if (group) { memcpy(&vninode->remote_ip, group, sizeof(vninode->remote_ip)); + if (!create) + vxlan_vnifilter_seq_inc(dev_net(vxlan->dev)); + } if (vxlan->dev->flags & IFF_UP) { if (vxlan_addr_multicast(&old_remote_ip) && @@ -719,7 +738,8 @@ static int vxlan_vni_update(struct vxlan_dev *vxlan, return 0; } -static void __vxlan_vni_add_list(struct vxlan_vni_group *vg, +static void __vxlan_vni_add_list(struct vxlan_dev *vxlan, + struct vxlan_vni_group *vg, struct vxlan_vni_node *v) { struct list_head *headp, *hpos; @@ -735,13 +755,16 @@ static void __vxlan_vni_add_list(struct vxlan_vni_group *vg, } list_add_rcu(&v->vlist, hpos); vg->num_vnis++; + vxlan_vnifilter_seq_inc(dev_net(vxlan->dev)); } -static void __vxlan_vni_del_list(struct vxlan_vni_group *vg, +static void __vxlan_vni_del_list(struct vxlan_dev *vxlan, + struct vxlan_vni_group *vg, struct vxlan_vni_node *v) { list_del_rcu(&v->vlist); vg->num_vnis--; + vxlan_vnifilter_seq_inc(dev_net(vxlan->dev)); } static struct vxlan_vni_node *vxlan_vni_alloc(struct vxlan_dev *vxlan, @@ -803,7 +826,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, return err; } - __vxlan_vni_add_list(vg, vninode); + __vxlan_vni_add_list(vxlan, vg, vninode); if (vxlan->dev->flags & IFF_UP) vxlan_vs_add_del_vninode(vxlan, vninode, false); @@ -849,7 +872,7 @@ static int vxlan_vni_del(struct vxlan_dev *vxlan, if (err) goto out; - __vxlan_vni_del_list(vg, vninode); + __vxlan_vni_del_list(vxlan, vg, vninode); vxlan_vnifilter_notify(vxlan, vninode, RTM_DELTUNNEL); @@ -963,7 +986,7 @@ void vxlan_vnigroup_uninit(struct vxlan_dev *vxlan) #if IS_ENABLED(CONFIG_IPV6) hlist_del_init_rcu(&v->hlist6.hlist); #endif - __vxlan_vni_del_list(vg, v); + __vxlan_vni_del_list(vxlan, vg, v); vxlan_vnifilter_notify(vxlan, v, RTM_DELTUNNEL); call_rcu(&v->rcu, vxlan_vni_node_rcu_free); } From 3ea463294b1b0fd14c1837019d920f69683aca74 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:10:58 +0000 Subject: [PATCH 0854/2126] vxlan: pass vxlan_config pointer to helper functions In preparation for converting vxlan->cfg to an RCU-protected pointer, refactor internal helper functions in the RX, TX, MDB, and VNIFILTER paths to accept a pointer to struct vxlan_config (or pass flags/ saddr_family where appropriate) rather than directly accessing vxlan->cfg. No functional changes. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260922181102.3989489-5-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 345 +++++++++++++++------------- drivers/net/vxlan/vxlan_mdb.c | 21 +- drivers/net/vxlan/vxlan_private.h | 8 +- drivers/net/vxlan/vxlan_vnifilter.c | 5 +- 4 files changed, 207 insertions(+), 172 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 1e5e960fce69..95d26d9a22ad 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -377,14 +377,15 @@ static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN]) /* Look up Ethernet address in forwarding table */ static struct vxlan_fdb *vxlan_find_mac_rcu(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, const u8 *mac, __be32 vni) { struct vxlan_fdb_key key; memset(&key, 0, sizeof(key)); memcpy(key.eth_addr, mac, sizeof(key.eth_addr)); - if (!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA)) - key.vni = vxlan->default_dst.remote_vni; + if (!(cfg->flags & VXLAN_F_COLLECT_METADATA)) + key.vni = cfg->vni; else key.vni = vni; @@ -393,11 +394,12 @@ static struct vxlan_fdb *vxlan_find_mac_rcu(struct vxlan_dev *vxlan, } static struct vxlan_fdb *vxlan_find_mac_tx(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, const u8 *mac, __be32 vni) { struct vxlan_fdb *f; - f = vxlan_find_mac_rcu(vxlan, mac, vni); + f = vxlan_find_mac_rcu(vxlan, cfg, mac, vni); if (f) { unsigned long now = jiffies; @@ -416,7 +418,7 @@ static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan, lockdep_assert_held_once(&vxlan->hash_lock); rcu_read_lock(); - f = vxlan_find_mac_rcu(vxlan, mac, vni); + f = vxlan_find_mac_rcu(vxlan, &vxlan->cfg, mac, vni); rcu_read_unlock(); return f; @@ -457,7 +459,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, rcu_read_lock(); - f = vxlan_find_mac_rcu(vxlan, eth_addr, vni); + f = vxlan_find_mac_rcu(vxlan, &vxlan->cfg, eth_addr, vni); if (f) rdst = first_remote_rcu(f); if (!rdst) { @@ -1416,7 +1418,7 @@ static int vxlan_fdb_get(struct sk_buff *skb, rcu_read_lock(); - f = vxlan_find_mac_rcu(vxlan, addr, vni); + f = vxlan_find_mac_rcu(vxlan, &vxlan->cfg, addr, vni); if (!f) { NL_SET_ERR_MSG(extack, "Fdb entry not found"); err = -ENOENT; @@ -1434,6 +1436,7 @@ errout: * and Tunnel endpoint. */ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, + const struct vxlan_config *cfg, union vxlan_addr *src_ip, const u8 *src_mac, u32 src_ifindex, __be32 vni) @@ -1452,7 +1455,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, ifindex = src_ifindex; #endif - f = vxlan_find_mac_rcu(vxlan, src_mac, vni); + f = vxlan_find_mac_rcu(vxlan, cfg, src_mac, vni); if (likely(f)) { struct vxlan_rdst *rdst = first_remote_rcu(f); unsigned long now = jiffies; @@ -1488,9 +1491,9 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, vxlan_fdb_update(vxlan, src_mac, src_ip, NUD_REACHABLE, NLM_F_EXCL|NLM_F_CREATE, - vxlan->cfg.dst_port, + cfg->dst_port, vni, - vxlan->default_dst.remote_vni, + cfg->vni, ifindex, NTF_SELF, 0, true, NULL); spin_unlock(&vxlan->hash_lock); } @@ -1598,6 +1601,7 @@ static void vxlan_parse_gbp_hdr(struct sk_buff *skb, u32 vxflags, } static enum skb_drop_reason vxlan_set_mac(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, struct vxlan_sock *vs, struct sk_buff *skb, __be32 vni) { @@ -1623,10 +1627,10 @@ static enum skb_drop_reason vxlan_set_mac(struct vxlan_dev *vxlan, #endif } - if (!(vxlan->cfg.flags & VXLAN_F_LEARN)) + if (!(cfg->flags & VXLAN_F_LEARN)) return SKB_NOT_DROPPED_YET; - return vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source, + return vxlan_snoop(skb->dev, cfg, &saddr, eth_hdr(skb)->h_source, ifindex, vni); } @@ -1657,18 +1661,21 @@ static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph, static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) { struct vxlan_vni_node *vninode = NULL; - const struct vxlanhdr *vh; - struct vxlan_dev *vxlan; - struct vxlan_sock *vs; - struct vxlan_metadata _md; - struct vxlan_metadata *md = &_md; __be16 protocol = htons(ETH_P_TEB); + const struct vxlan_config *cfg; enum skb_drop_reason reason; + const struct vxlanhdr *vh; + struct vxlan_metadata *md; + struct vxlan_metadata _md; + struct vxlan_dev *vxlan; bool raw_proto = false; - void *oiph; + struct vxlan_sock *vs; __be32 vni = 0; + void *oiph; int nh; + md = &_md; + /* Need UDP and VXLAN header to be present */ reason = pskb_may_pull_reason(skb, VXLAN_HLEN); if (reason) @@ -1696,8 +1703,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop; } - if (vh->vx_flags & vxlan->cfg.reserved_bits.vx_flags || - vh->vx_vni & vxlan->cfg.reserved_bits.vx_vni) { + cfg = &vxlan->cfg; + if (vh->vx_flags & cfg->reserved_bits.vx_flags || + vh->vx_vni & cfg->reserved_bits.vx_vni) { /* If the header uses bits besides those enabled by the * netdevice configuration, treat this as a malformed packet. * This behavior diverges from VXLAN RFC (RFC7348) which @@ -1709,12 +1717,12 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) reason = SKB_DROP_REASON_VXLAN_INVALID_HDR; DEV_STATS_INC(vxlan->dev, rx_frame_errors); DEV_STATS_INC(vxlan->dev, rx_errors); - vxlan_vnifilter_count(vxlan, vni, vninode, + vxlan_vnifilter_count(vxlan, cfg, vni, vninode, VXLAN_VNI_STATS_RX_ERRORS, 0); goto drop; } - if (vxlan->cfg.flags & VXLAN_F_GPE) { + if (cfg->flags & VXLAN_F_GPE) { if (!vxlan_parse_gpe_proto(vh, &protocol)) goto drop; raw_proto = true; @@ -1726,8 +1734,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop; } - if (vxlan->cfg.flags & VXLAN_F_REMCSUM_RX) { - reason = vxlan_remcsum(skb, vxlan->cfg.flags); + if (cfg->flags & VXLAN_F_REMCSUM_RX) { + reason = vxlan_remcsum(skb, cfg->flags); if (unlikely(reason)) goto drop; } @@ -1752,14 +1760,14 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) memset(md, 0, sizeof(*md)); } - if (vxlan->cfg.flags & VXLAN_F_GBP) - vxlan_parse_gbp_hdr(skb, vxlan->cfg.flags, md); + if (cfg->flags & VXLAN_F_GBP) + vxlan_parse_gbp_hdr(skb, cfg->flags, md); /* Note that GBP and GPE can never be active together. This is * ensured in vxlan_dev_configure. */ if (!raw_proto) { - reason = vxlan_set_mac(vxlan, vs, skb, vni); + reason = vxlan_set_mac(vxlan, cfg, vs, skb, vni); if (reason) goto drop; } else { @@ -1780,7 +1788,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) if (reason) { DEV_STATS_INC(vxlan->dev, rx_length_errors); DEV_STATS_INC(vxlan->dev, rx_errors); - vxlan_vnifilter_count(vxlan, vni, vninode, + vxlan_vnifilter_count(vxlan, cfg, vni, vninode, VXLAN_VNI_STATS_RX_ERRORS, 0); goto drop; } @@ -1792,7 +1800,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) reason = SKB_DROP_REASON_IP_TUNNEL_ECN; DEV_STATS_INC(vxlan->dev, rx_frame_errors); DEV_STATS_INC(vxlan->dev, rx_errors); - vxlan_vnifilter_count(vxlan, vni, vninode, + vxlan_vnifilter_count(vxlan, cfg, vni, vninode, VXLAN_VNI_STATS_RX_ERRORS, 0); goto drop; } @@ -1802,14 +1810,15 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) if (unlikely(!(vxlan->dev->flags & IFF_UP))) { rcu_read_unlock(); dev_dstats_rx_dropped(vxlan->dev); - vxlan_vnifilter_count(vxlan, vni, vninode, + vxlan_vnifilter_count(vxlan, cfg, vni, vninode, VXLAN_VNI_STATS_RX_DROPS, 0); reason = SKB_DROP_REASON_DEV_READY; goto drop; } dev_dstats_rx_add(vxlan->dev, skb->len); - vxlan_vnifilter_count(vxlan, vni, vninode, VXLAN_VNI_STATS_RX, skb->len); + vxlan_vnifilter_count(vxlan, cfg, vni, vninode, VXLAN_VNI_STATS_RX, + skb->len); gro_cells_receive(&vxlan->gro_cells, skb); rcu_read_unlock(); @@ -1850,7 +1859,7 @@ static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb) return 0; } -static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) +static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u32 flags) { struct neigh_table *tbl = arp_table(dev_net(dev)); struct vxlan_dev *vxlan = netdev_priv(dev); @@ -1864,7 +1873,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) if (!pskb_network_may_pull(skb, arp_hdr_len(dev))) { dev_dstats_tx_dropped(dev); - vxlan_vnifilter_count(vxlan, vni, NULL, + vxlan_vnifilter_count(vxlan, &vxlan->cfg, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); goto out; } @@ -1905,7 +1914,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) neigh_ha_snapshot(ha, n, n->dev); rcu_read_lock(); - f = vxlan_find_mac_tx(vxlan, ha, vni); + f = vxlan_find_mac_tx(vxlan, &vxlan->cfg, ha, vni); if (f) rdst = first_remote_rcu(f); if (rdst && vxlan_addr_any(&rdst->remote_ip)) { @@ -1931,11 +1940,11 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) if (netif_rx(reply) == NET_RX_DROP) { dev_dstats_rx_dropped(dev); - vxlan_vnifilter_count(vxlan, vni, NULL, + vxlan_vnifilter_count(vxlan, &vxlan->cfg, vni, NULL, VXLAN_VNI_STATS_RX_DROPS, 0); } - } else if (vxlan->cfg.flags & VXLAN_F_L3MISS) { + } else if (flags & VXLAN_F_L3MISS) { union vxlan_addr ipa = { .sin.sin_addr.s_addr = tip, .sin.sin_family = AF_INET, @@ -2045,7 +2054,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, return reply; } -static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) +static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u32 flags) { struct vxlan_dev *vxlan = netdev_priv(dev); const struct in6_addr *daddr; @@ -2079,7 +2088,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) } neigh_ha_snapshot(ha, n, n->dev); - f = vxlan_find_mac_tx(vxlan, ha, vni); + f = vxlan_find_mac_tx(vxlan, &vxlan->cfg, ha, vni); if (f) rdst = first_remote_rcu(f); if (rdst && vxlan_addr_any(&rdst->remote_ip)) { @@ -2098,10 +2107,10 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) if (netif_rx(reply) == NET_RX_DROP) { dev_dstats_rx_dropped(dev); - vxlan_vnifilter_count(vxlan, vni, NULL, + vxlan_vnifilter_count(vxlan, &vxlan->cfg, vni, NULL, VXLAN_VNI_STATS_RX_DROPS, 0); } - } else if (vxlan->cfg.flags & VXLAN_F_L3MISS) { + } else if (flags & VXLAN_F_L3MISS) { union vxlan_addr ipa = { .sin6.sin6_addr = msg->target, .sin6.sin6_family = AF_INET6, @@ -2117,9 +2126,9 @@ out: } #endif -static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) +static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb, + const struct vxlan_config *cfg) { - struct vxlan_dev *vxlan = netdev_priv(dev); struct neigh_table *tbl; struct neighbour *n; @@ -2138,7 +2147,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) tbl = arp_table(dev_net(dev)); pip = ip_hdr(skb); n = neigh_lookup(tbl, &pip->daddr, dev); - if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { + if (!n && (cfg->flags & VXLAN_F_L3MISS)) { union vxlan_addr ipa = { .sin.sin_addr.s_addr = pip->daddr, .sin.sin_family = AF_INET, @@ -2166,7 +2175,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) tbl = nd_table(dev_net(dev)); pip6 = ipv6_hdr(skb); n = neigh_lookup(tbl, &pip6->daddr, dev); - if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { + if (!n && (cfg->flags & VXLAN_F_L3MISS)) { union vxlan_addr ipa = { .sin6.sin6_addr = pip6->daddr, .sin6.sin6_family = AF_INET6, @@ -2284,20 +2293,21 @@ static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst, /* Bypass encapsulation if the destination is local */ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, - struct vxlan_dev *dst_vxlan, __be32 vni, - bool snoop) + struct vxlan_dev *dst_vxlan, + const struct vxlan_config *src_cfg, + __be32 vni, bool snoop) { + const struct vxlan_config *dst_cfg = &dst_vxlan->cfg; union vxlan_addr loopback; - union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip; unsigned int len = skb->len; - struct net_device *dev; + struct net_device *dev = dst_vxlan->dev; skb->pkt_type = PACKET_HOST; skb->encapsulation = 0; - skb->dev = dst_vxlan->dev; + skb->dev = dev; __skb_pull(skb, skb_network_offset(skb)); - if (remote_ip->sa.sa_family == AF_INET) { + if (dst_vxlan->default_dst.remote_ip.sa.sa_family == AF_INET) { loopback.sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); loopback.sa.sa_family = AF_INET; #if IS_ENABLED(CONFIG_IPV6) @@ -2308,26 +2318,25 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, } rcu_read_lock(); - dev = skb->dev; if (unlikely(!(dev->flags & IFF_UP))) { kfree_skb_reason(skb, SKB_DROP_REASON_DEV_READY); goto drop; } - if ((dst_vxlan->cfg.flags & VXLAN_F_LEARN) && snoop) - vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source, 0, vni); + if ((dst_cfg->flags & VXLAN_F_LEARN) && snoop) + vxlan_snoop(dev, dst_cfg, &loopback, eth_hdr(skb)->h_source, 0, vni); dev_dstats_tx_add(src_vxlan->dev, len); - vxlan_vnifilter_count(src_vxlan, vni, NULL, VXLAN_VNI_STATS_TX, len); + vxlan_vnifilter_count(src_vxlan, src_cfg, vni, NULL, VXLAN_VNI_STATS_TX, len); if (__netif_rx(skb) == NET_RX_SUCCESS) { dev_dstats_rx_add(dst_vxlan->dev, len); - vxlan_vnifilter_count(dst_vxlan, vni, NULL, VXLAN_VNI_STATS_RX, + vxlan_vnifilter_count(dst_vxlan, dst_cfg, vni, NULL, VXLAN_VNI_STATS_RX, len); } else { drop: dev_dstats_rx_dropped(dev); - vxlan_vnifilter_count(dst_vxlan, vni, NULL, + vxlan_vnifilter_count(dst_vxlan, dst_cfg, vni, NULL, VXLAN_VNI_STATS_RX_DROPS, 0); } rcu_read_unlock(); @@ -2335,6 +2344,7 @@ drop: static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, int addr_family, __be16 dst_port, int dst_ifindex, __be32 vni, struct dst_entry *dst, @@ -2350,22 +2360,22 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, /* Bypass encapsulation if the destination is local */ if (rt_flags & RTCF_LOCAL && !(rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) && - vxlan->cfg.flags & VXLAN_F_LOCALBYPASS) { + cfg->flags & VXLAN_F_LOCALBYPASS) { struct vxlan_dev *dst_vxlan; dst_release(dst); dst_vxlan = vxlan_find_vni(vxlan->net, dst_ifindex, vni, addr_family, dst_port, - vxlan->cfg.flags); + cfg->flags); if (!dst_vxlan) { DEV_STATS_INC(dev, tx_errors); - vxlan_vnifilter_count(vxlan, vni, NULL, + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0); kfree_skb_reason(skb, SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND); return -ENOENT; } - vxlan_encap_bypass(skb, vxlan, dst_vxlan, vni, true); + vxlan_encap_bypass(skb, vxlan, dst_vxlan, cfg, vni, true); return 1; } @@ -2373,30 +2383,35 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, } void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, + const struct vxlan_config *cfg, __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc) { - struct dst_cache *dst_cache; - struct ip_tunnel_info *info; - struct ip_tunnel_key *pkey; - struct ip_tunnel_key key; - struct vxlan_dev *vxlan = netdev_priv(dev); - const struct iphdr *old_iph; - struct vxlan_metadata _md = {}; - struct vxlan_metadata *md = &_md; unsigned int pkt_len = skb->len; + struct vxlan_metadata _md = {}; __be16 src_port = 0, dst_port; struct dst_entry *ndst = NULL; + enum skb_drop_reason reason; + struct dst_cache *dst_cache; + const struct iphdr *old_iph; + struct ip_tunnel_info *info; + struct ip_tunnel_key *pkey; + struct vxlan_metadata *md; + struct ip_tunnel_key key; + struct vxlan_dev *vxlan; + u32 flags = cfg->flags; + bool udp_sum = false; + bool no_eth_encap; int addr_family; + bool use_cache; + __be32 vni = 0; __u8 tos, ttl; int ifindex; int err = 0; - u32 flags = vxlan->cfg.flags; - bool use_cache; - bool udp_sum = false; - bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev)); - enum skb_drop_reason reason; - bool no_eth_encap; - __be32 vni = 0; + bool xnet; + + vxlan = netdev_priv(dev); + xnet = !net_eq(vxlan->net, dev_net(vxlan->dev)); + md = &_md; no_eth_encap = flags & VXLAN_F_GPE && skb->protocol != htons(ETH_P_TEB); reason = skb_vlan_inet_prepare(skb, no_eth_encap); @@ -2416,23 +2431,23 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, if (vxlan_addr_any(&rdst->remote_ip)) { if (did_rsc) { /* short-circuited back to local bridge */ - vxlan_encap_bypass(skb, vxlan, vxlan, + vxlan_encap_bypass(skb, vxlan, vxlan, cfg, default_vni, true); return; } goto drop; } - addr_family = vxlan->cfg.saddr.sa.sa_family; - dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; + addr_family = cfg->saddr.sa.sa_family; + dst_port = rdst->remote_port ? rdst->remote_port : cfg->dst_port; vni = (rdst->remote_vni) ? : default_vni; ifindex = rdst->remote_ifindex; if (addr_family == AF_INET) { - key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr; + key.u.ipv4.src = cfg->saddr.sin.sin_addr.s_addr; key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr; } else { - key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr; + key.u.ipv6.src = cfg->saddr.sin6.sin6_addr; key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr; } @@ -2441,11 +2456,11 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, if (flags & VXLAN_F_TTL_INHERIT) { ttl = ip_tunnel_get_ttl(old_iph, skb); } else { - ttl = vxlan->cfg.ttl; + ttl = cfg->ttl; if (!ttl && vxlan_addr_multicast(&rdst->remote_ip)) ttl = 1; } - tos = vxlan->cfg.tos; + tos = cfg->tos; if (tos == 1) tos = ip_tunnel_get_dsfield(old_iph, skb); if (tos && !info) @@ -2456,9 +2471,9 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, else udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX); #if IS_ENABLED(CONFIG_IPV6) - switch (vxlan->cfg.label_policy) { + switch (cfg->label_policy) { case VXLAN_LABEL_FIXED: - key.label = vxlan->cfg.label; + key.label = cfg->label; break; case VXLAN_LABEL_INHERIT: key.label = ip_tunnel_get_flowlabel(old_iph, skb); @@ -2476,7 +2491,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, } pkey = &info->key; addr_family = ip_tunnel_info_af(info); - dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; + dst_port = info->key.tp_dst ? : cfg->dst_port; vni = tunnel_id_to_key32(info->key.tun_id); ifindex = 0; dst_cache = &info->dst_cache; @@ -2489,8 +2504,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos = info->key.tos; udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags); } - src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, - vxlan->cfg.port_max, true); + src_port = udp_flow_src_port(dev_net(dev), skb, cfg->port_min, + cfg->port_max, true); rcu_read_lock(); if (addr_family == AF_INET) { @@ -2523,15 +2538,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, if (!info) { /* Bypass encapsulation if the destination is local */ - err = encap_bypass_if_local(skb, dev, vxlan, AF_INET, + err = encap_bypass_if_local(skb, dev, vxlan, cfg, AF_INET, dst_port, ifindex, vni, &rt->dst, rt->rt_flags); if (err) goto out_unlock; - if (vxlan->cfg.df == VXLAN_DF_SET) { + if (cfg->df == VXLAN_DF_SET) { df = htons(IP_DF); - } else if (vxlan->cfg.df == VXLAN_DF_INHERIT) { + } else if (cfg->df == VXLAN_DF_INHERIT) { struct ethhdr *eth = eth_hdr(skb); if (ntohs(eth->h_proto) == ETH_P_IPV6 || @@ -2560,7 +2575,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, unclone->key.u.ipv4.src = pkey->u.ipv4.dst; unclone->key.u.ipv4.dst = saddr; } - vxlan_encap_bypass(skb, vxlan, vxlan, vni, false); + vxlan_encap_bypass(skb, vxlan, vxlan, cfg, vni, false); dst_release(ndst); goto out_unlock; } @@ -2610,7 +2625,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, if (!info) { u32 rt6i_flags = dst_rt6_info(ndst)->rt6i_flags; - err = encap_bypass_if_local(skb, dev, vxlan, AF_INET6, + err = encap_bypass_if_local(skb, dev, vxlan, cfg, AF_INET6, dst_port, ifindex, vni, ndst, rt6i_flags); if (err) @@ -2634,7 +2649,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, unclone->key.u.ipv6.dst = saddr; } - vxlan_encap_bypass(skb, vxlan, vxlan, vni, false); + vxlan_encap_bypass(skb, vxlan, vxlan, cfg, vni, false); dst_release(ndst); goto out_unlock; } @@ -2655,14 +2670,14 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, ip6cb_flags); #endif } - vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX, pkt_len); + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX, pkt_len); out_unlock: rcu_read_unlock(); return; drop: dev_dstats_tx_dropped(dev); - vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); kfree_skb_reason(skb, reason); return; @@ -2674,11 +2689,12 @@ tx_error: DEV_STATS_INC(dev, tx_carrier_errors); dst_release(ndst); DEV_STATS_INC(dev, tx_errors); - vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0); + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0); kfree_skb_reason(skb, reason); } static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev, + const struct vxlan_config *cfg, struct vxlan_fdb *f, __be32 vni, bool did_rsc) { struct vxlan_rdst nh_rdst; @@ -2695,7 +2711,7 @@ static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev, do_xmit = vxlan_fdb_nh_path_select(nh, hash, &nh_rdst); if (likely(do_xmit)) - vxlan_xmit_one(skb, dev, vni, &nh_rdst, did_rsc); + vxlan_xmit_one(skb, dev, cfg, vni, &nh_rdst, did_rsc); else goto drop; @@ -2703,15 +2719,15 @@ static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev, drop: dev_dstats_tx_dropped(dev); - vxlan_vnifilter_count(netdev_priv(dev), vni, NULL, + vxlan_vnifilter_count(netdev_priv(dev), cfg, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); dev_kfree_skb(skb); } static netdev_tx_t vxlan_xmit_nhid(struct sk_buff *skb, struct net_device *dev, - u32 nhid, __be32 vni) + u32 nhid, __be32 vni, + const struct vxlan_config *cfg) { - struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_rdst nh_rdst; struct nexthop *nh; bool do_xmit; @@ -2729,11 +2745,11 @@ static netdev_tx_t vxlan_xmit_nhid(struct sk_buff *skb, struct net_device *dev, do_xmit = vxlan_fdb_nh_path_select(nh, hash, &nh_rdst); rcu_read_unlock(); - if (vxlan->cfg.saddr.sa.sa_family != nh_rdst.remote_ip.sa.sa_family) + if (cfg->saddr.sa.sa_family != nh_rdst.remote_ip.sa.sa_family) goto drop; if (likely(do_xmit)) - vxlan_xmit_one(skb, dev, vni, &nh_rdst, false); + vxlan_xmit_one(skb, dev, cfg, vni, &nh_rdst, false); else goto drop; @@ -2741,7 +2757,7 @@ static netdev_tx_t vxlan_xmit_nhid(struct sk_buff *skb, struct net_device *dev, drop: dev_dstats_tx_dropped(dev); - vxlan_vnifilter_count(netdev_priv(dev), vni, NULL, + vxlan_vnifilter_count(netdev_priv(dev), cfg, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); dev_kfree_skb(skb); return NETDEV_TX_OK; @@ -2758,34 +2774,41 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_rdst *rdst, *fdst = NULL; const struct ip_tunnel_info *info; + const struct vxlan_config *cfg; + __be32 default_vni; struct vxlan_fdb *f; struct ethhdr *eth; __be32 vni = 0; - u32 nhid = 0; bool did_rsc; + u32 nhid = 0; + u32 flags; + + cfg = &vxlan->cfg; + flags = cfg->flags; + default_vni = cfg->vni; info = skb_tunnel_info(skb); skb_reset_mac_header(skb); - if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) { + if (flags & VXLAN_F_COLLECT_METADATA) { if (info && info->mode & IP_TUNNEL_INFO_BRIDGE && info->mode & IP_TUNNEL_INFO_TX) { vni = tunnel_id_to_key32(info->key.tun_id); nhid = info->key.nhid; } else { if (info && info->mode & IP_TUNNEL_INFO_TX) - vxlan_xmit_one(skb, dev, vni, NULL, false); + vxlan_xmit_one(skb, dev, cfg, vni, NULL, false); else kfree_skb_reason(skb, SKB_DROP_REASON_TUNNEL_TXINFO); return NETDEV_TX_OK; } } - if (vxlan->cfg.flags & VXLAN_F_PROXY) { + if (flags & VXLAN_F_PROXY) { eth = eth_hdr(skb); if (ntohs(eth->h_proto) == ETH_P_ARP) - return arp_reduce(dev, skb, vni); + return arp_reduce(dev, skb, vni, flags); #if IS_ENABLED(CONFIG_IPV6) else if (ntohs(eth->h_proto) == ETH_P_IPV6 && pskb_network_may_pull(skb, sizeof(struct ipv6hdr) + @@ -2795,23 +2818,23 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) if (m->icmph.icmp6_code == 0 && m->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) - return neigh_reduce(dev, skb, vni); + return neigh_reduce(dev, skb, vni, flags); } #endif } if (nhid) - return vxlan_xmit_nhid(skb, dev, nhid, vni); + return vxlan_xmit_nhid(skb, dev, nhid, vni, cfg); - if (vxlan->cfg.flags & VXLAN_F_MDB) { + if (flags & VXLAN_F_MDB) { struct vxlan_mdb_entry *mdb_entry; rcu_read_lock(); - mdb_entry = vxlan_mdb_entry_skb_get(vxlan, skb, vni); + mdb_entry = vxlan_mdb_entry_skb_get(vxlan, cfg, skb, vni); if (mdb_entry) { netdev_tx_t ret; - ret = vxlan_mdb_xmit(vxlan, mdb_entry, skb); + ret = vxlan_mdb_xmit(vxlan, cfg, mdb_entry, skb); rcu_read_unlock(); return ret; } @@ -2820,27 +2843,27 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) eth = eth_hdr(skb); rcu_read_lock(); - f = vxlan_find_mac_tx(vxlan, eth->h_dest, vni); + f = vxlan_find_mac_tx(vxlan, cfg, eth->h_dest, vni); did_rsc = false; - if (f && (f->flags & NTF_ROUTER) && (vxlan->cfg.flags & VXLAN_F_RSC) && + if (f && (f->flags & NTF_ROUTER) && (flags & VXLAN_F_RSC) && (ntohs(eth->h_proto) == ETH_P_IP || ntohs(eth->h_proto) == ETH_P_IPV6)) { - did_rsc = route_shortcircuit(dev, skb); + did_rsc = route_shortcircuit(dev, skb, cfg); eth = eth_hdr(skb); if (did_rsc) - f = vxlan_find_mac_tx(vxlan, eth->h_dest, vni); + f = vxlan_find_mac_tx(vxlan, cfg, eth->h_dest, vni); } if (f == NULL) { - f = vxlan_find_mac_tx(vxlan, all_zeros_mac, vni); + f = vxlan_find_mac_tx(vxlan, cfg, all_zeros_mac, vni); if (f == NULL) { - if ((vxlan->cfg.flags & VXLAN_F_L2MISS) && + if ((flags & VXLAN_F_L2MISS) && !is_multicast_ether_addr(eth->h_dest)) vxlan_fdb_miss(vxlan, eth->h_dest); dev_dstats_tx_dropped(dev); - vxlan_vnifilter_count(vxlan, vni, NULL, + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); kfree_skb_reason(skb, SKB_DROP_REASON_NO_TX_TARGET); goto out; @@ -2848,8 +2871,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) } if (rcu_access_pointer(f->nh)) { - vxlan_xmit_nh(skb, dev, f, - (vni ? : vxlan->default_dst.remote_vni), did_rsc); + vxlan_xmit_nh(skb, dev, cfg, f, + (vni ? : default_vni), did_rsc); } else { list_for_each_entry_rcu(rdst, &f->remotes, list) { struct sk_buff *skb1; @@ -2860,10 +2883,10 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) } skb1 = skb_clone(skb, GFP_ATOMIC); if (skb1) - vxlan_xmit_one(skb1, dev, vni, rdst, did_rsc); + vxlan_xmit_one(skb1, dev, cfg, vni, rdst, did_rsc); } if (fdst) - vxlan_xmit_one(skb, dev, vni, fdst, did_rsc); + vxlan_xmit_one(skb, dev, cfg, vni, fdst, did_rsc); else kfree_skb_reason(skb, SKB_DROP_REASON_NO_TX_TARGET); } @@ -3736,7 +3759,7 @@ static int vxlan_sock_add(struct vxlan_dev *vxlan) } int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan, - struct vxlan_config *conf, __be32 vni) + const struct vxlan_config *conf, __be32 vni) { struct vxlan_net *vn = net_generic(src_net, vxlan_net_id); struct vxlan_dev *tmp; @@ -4617,10 +4640,10 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) { const struct vxlan_dev *vxlan = netdev_priv(dev); const struct vxlan_rdst *dst = &vxlan->default_dst; - struct ifla_vxlan_port_range ports = { - .low = htons(vxlan->cfg.port_min), - .high = htons(vxlan->cfg.port_max), - }; + struct ifla_vxlan_port_range ports; + const struct vxlan_config *cfg; + + cfg = &vxlan->cfg; if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(dst->remote_vni))) goto nla_put_failure; @@ -4642,79 +4665,81 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) goto nla_put_failure; - if (!vxlan_addr_any(&vxlan->cfg.saddr)) { - if (vxlan->cfg.saddr.sa.sa_family == AF_INET) { + if (!vxlan_addr_any(&cfg->saddr)) { + if (cfg->saddr.sa.sa_family == AF_INET) { if (nla_put_in_addr(skb, IFLA_VXLAN_LOCAL, - vxlan->cfg.saddr.sin.sin_addr.s_addr)) + cfg->saddr.sin.sin_addr.s_addr)) goto nla_put_failure; #if IS_ENABLED(CONFIG_IPV6) } else { if (nla_put_in6_addr(skb, IFLA_VXLAN_LOCAL6, - &vxlan->cfg.saddr.sin6.sin6_addr)) + &cfg->saddr.sin6.sin6_addr)) goto nla_put_failure; #endif } } - if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->cfg.ttl) || + if (nla_put_u8(skb, IFLA_VXLAN_TTL, cfg->ttl) || nla_put_u8(skb, IFLA_VXLAN_TTL_INHERIT, - !!(vxlan->cfg.flags & VXLAN_F_TTL_INHERIT)) || - nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->cfg.tos) || - nla_put_u8(skb, IFLA_VXLAN_DF, vxlan->cfg.df) || - nla_put_be32(skb, IFLA_VXLAN_LABEL, vxlan->cfg.label) || - nla_put_u32(skb, IFLA_VXLAN_LABEL_POLICY, vxlan->cfg.label_policy) || + !!(cfg->flags & VXLAN_F_TTL_INHERIT)) || + nla_put_u8(skb, IFLA_VXLAN_TOS, cfg->tos) || + nla_put_u8(skb, IFLA_VXLAN_DF, cfg->df) || + nla_put_be32(skb, IFLA_VXLAN_LABEL, cfg->label) || + nla_put_u32(skb, IFLA_VXLAN_LABEL_POLICY, cfg->label_policy) || nla_put_u8(skb, IFLA_VXLAN_LEARNING, - !!(vxlan->cfg.flags & VXLAN_F_LEARN)) || + !!(cfg->flags & VXLAN_F_LEARN)) || nla_put_u8(skb, IFLA_VXLAN_PROXY, - !!(vxlan->cfg.flags & VXLAN_F_PROXY)) || + !!(cfg->flags & VXLAN_F_PROXY)) || nla_put_u8(skb, IFLA_VXLAN_RSC, - !!(vxlan->cfg.flags & VXLAN_F_RSC)) || + !!(cfg->flags & VXLAN_F_RSC)) || nla_put_u8(skb, IFLA_VXLAN_L2MISS, - !!(vxlan->cfg.flags & VXLAN_F_L2MISS)) || + !!(cfg->flags & VXLAN_F_L2MISS)) || nla_put_u8(skb, IFLA_VXLAN_L3MISS, - !!(vxlan->cfg.flags & VXLAN_F_L3MISS)) || + !!(cfg->flags & VXLAN_F_L3MISS)) || nla_put_u8(skb, IFLA_VXLAN_COLLECT_METADATA, - !!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA)) || - nla_put_u32(skb, IFLA_VXLAN_AGEING, vxlan->cfg.age_interval) || - nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->cfg.addrmax) || - nla_put_be16(skb, IFLA_VXLAN_PORT, vxlan->cfg.dst_port) || + !!(cfg->flags & VXLAN_F_COLLECT_METADATA)) || + nla_put_u32(skb, IFLA_VXLAN_AGEING, cfg->age_interval) || + nla_put_u32(skb, IFLA_VXLAN_LIMIT, cfg->addrmax) || + nla_put_be16(skb, IFLA_VXLAN_PORT, cfg->dst_port) || nla_put_u8(skb, IFLA_VXLAN_UDP_CSUM, - !(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM_TX)) || + !(cfg->flags & VXLAN_F_UDP_ZERO_CSUM_TX)) || nla_put_u8(skb, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, - !!(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM6_TX)) || + !!(cfg->flags & VXLAN_F_UDP_ZERO_CSUM6_TX)) || nla_put_u8(skb, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, - !!(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM6_RX)) || + !!(cfg->flags & VXLAN_F_UDP_ZERO_CSUM6_RX)) || nla_put_u8(skb, IFLA_VXLAN_REMCSUM_TX, - !!(vxlan->cfg.flags & VXLAN_F_REMCSUM_TX)) || + !!(cfg->flags & VXLAN_F_REMCSUM_TX)) || nla_put_u8(skb, IFLA_VXLAN_REMCSUM_RX, - !!(vxlan->cfg.flags & VXLAN_F_REMCSUM_RX)) || + !!(cfg->flags & VXLAN_F_REMCSUM_RX)) || nla_put_u8(skb, IFLA_VXLAN_LOCALBYPASS, - !!(vxlan->cfg.flags & VXLAN_F_LOCALBYPASS))) + !!(cfg->flags & VXLAN_F_LOCALBYPASS))) goto nla_put_failure; + ports.low = htons(cfg->port_min); + ports.high = htons(cfg->port_max); if (nla_put(skb, IFLA_VXLAN_PORT_RANGE, sizeof(ports), &ports)) goto nla_put_failure; - if (vxlan->cfg.flags & VXLAN_F_GBP && + if (cfg->flags & VXLAN_F_GBP && nla_put_flag(skb, IFLA_VXLAN_GBP)) goto nla_put_failure; - if (vxlan->cfg.flags & VXLAN_F_GPE && + if (cfg->flags & VXLAN_F_GPE && nla_put_flag(skb, IFLA_VXLAN_GPE)) goto nla_put_failure; - if (vxlan->cfg.flags & VXLAN_F_REMCSUM_NOPARTIAL && + if (cfg->flags & VXLAN_F_REMCSUM_NOPARTIAL && nla_put_flag(skb, IFLA_VXLAN_REMCSUM_NOPARTIAL)) goto nla_put_failure; - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER && + if (cfg->flags & VXLAN_F_VNIFILTER && nla_put_u8(skb, IFLA_VXLAN_VNIFILTER, - !!(vxlan->cfg.flags & VXLAN_F_VNIFILTER))) + !!(cfg->flags & VXLAN_F_VNIFILTER))) goto nla_put_failure; if (nla_put(skb, IFLA_VXLAN_RESERVED_BITS, - sizeof(vxlan->cfg.reserved_bits), - &vxlan->cfg.reserved_bits)) + sizeof(cfg->reserved_bits), + &cfg->reserved_bits)) goto nla_put_failure; return 0; diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c index 841f42ffecb9..56ca92832833 100644 --- a/drivers/net/vxlan/vxlan_mdb.c +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -165,6 +165,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { + const struct vxlan_config *cfg = &vxlan->cfg; struct vxlan_rdst *rd = rtnl_dereference(remote->rd); struct br_mdb_entry e; struct nlattr *nest; @@ -189,7 +190,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, vxlan_nla_put_addr(skb, MDBA_MDB_EATTR_DST, &rd->remote_ip)) goto nest_err; - if (rd->remote_port && rd->remote_port != vxlan->cfg.dst_port && + if (rd->remote_port && rd->remote_port != cfg->dst_port && nla_put_u16(skb, MDBA_MDB_EATTR_DST_PORT, be16_to_cpu(rd->remote_port))) goto nest_err; @@ -202,7 +203,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, nla_put_u32(skb, MDBA_MDB_EATTR_IFINDEX, rd->remote_ifindex)) goto nest_err; - if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && + if ((cfg->flags & VXLAN_F_COLLECT_METADATA) && mdb_entry->key.vni && nla_put_u32(skb, MDBA_MDB_EATTR_SRC_VNI, be32_to_cpu(mdb_entry->key.vni))) goto nest_err; @@ -613,6 +614,7 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, { struct br_mdb_entry *entry = nla_data(tb[MDBA_SET_ENTRY]); struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *vcfg = &vxlan->cfg; memset(cfg, 0, sizeof(*cfg)); cfg->vxlan = vxlan; @@ -622,7 +624,7 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, cfg->filter_mode = MCAST_EXCLUDE; cfg->rt_protocol = RTPROT_STATIC; cfg->remote_vni = vxlan->default_dst.remote_vni; - cfg->remote_port = vxlan->cfg.dst_port; + cfg->remote_port = vcfg->dst_port; if (entry->ifindex != dev->ifindex) { NL_SET_ERR_MSG_MOD(extack, "Port net device must be the VXLAN net device"); @@ -957,6 +959,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan, const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { + const struct vxlan_config *cfg = &vxlan->cfg; const struct vxlan_mdb_entry_key *group = &mdb_entry->key; struct vxlan_rdst *rd = rtnl_dereference(remote->rd); size_t nlmsg_size; @@ -978,7 +981,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan, /* MDBA_MDB_EATTR_DST */ nlmsg_size += nla_total_size(vxlan_addr_size(&rd->remote_ip)); /* MDBA_MDB_EATTR_DST_PORT */ - if (rd->remote_port && rd->remote_port != vxlan->cfg.dst_port) + if (rd->remote_port && rd->remote_port != cfg->dst_port) nlmsg_size += nla_total_size(sizeof(u16)); /* MDBA_MDB_EATTR_VNI */ if (rd->remote_vni != vxlan->default_dst.remote_vni) @@ -987,7 +990,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan, if (rd->remote_ifindex) nlmsg_size += nla_total_size(sizeof(u32)); /* MDBA_MDB_EATTR_SRC_VNI */ - if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && group->vni) + if ((cfg->flags & VXLAN_F_COLLECT_METADATA) && group->vni) nlmsg_size += nla_total_size(sizeof(u32)); return nlmsg_size; @@ -1621,6 +1624,7 @@ free: } struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, struct sk_buff *skb, __be32 src_vni) { @@ -1634,7 +1638,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, /* When not in collect metadata mode, 'src_vni' is zero, but MDB * entries are stored with the VNI of the VXLAN device. */ - if (!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA)) + if (!(cfg->flags & VXLAN_F_COLLECT_METADATA)) src_vni = vxlan->default_dst.remote_vni; memset(&group, 0, sizeof(group)); @@ -1700,6 +1704,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, } netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, const struct vxlan_mdb_entry *mdb_entry, struct sk_buff *skb) { @@ -1721,12 +1726,12 @@ netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan, skb1 = skb_clone(skb, GFP_ATOMIC); if (skb1) - vxlan_xmit_one(skb1, vxlan->dev, src_vni, + vxlan_xmit_one(skb1, vxlan->dev, cfg, src_vni, rcu_dereference(remote->rd), false); } if (fremote) - vxlan_xmit_one(skb, vxlan->dev, src_vni, + vxlan_xmit_one(skb, vxlan->dev, cfg, src_vni, rcu_dereference(fremote->rd), false); else kfree_skb_reason(skb, SKB_DROP_REASON_NO_TX_TARGET); diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index 74d713717cd5..a2034ad418f7 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -204,9 +204,10 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, __u32 ifindex, __u16 ndm_flags, u32 nhid, bool swdev_notify, struct netlink_ext_ack *extack); void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, + const struct vxlan_config *cfg, __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc); int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan, - struct vxlan_config *conf, __be32 vni); + const struct vxlan_config *conf, __be32 vni); /* vxlan_vnifilter.c */ int vxlan_vnigroup_init(struct vxlan_dev *vxlan); @@ -214,7 +215,8 @@ void vxlan_vnigroup_uninit(struct vxlan_dev *vxlan); int vxlan_vnifilter_init(void); void vxlan_vnifilter_uninit(void); -void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni, +void vxlan_vnifilter_count(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, __be32 vni, struct vxlan_vni_node *vninode, int type, unsigned int len); @@ -256,9 +258,11 @@ int vxlan_mdb_del_bulk(struct net_device *dev, struct nlattr *tb[], int vxlan_mdb_get(struct net_device *dev, struct nlattr *tb[], u32 portid, u32 seq, struct netlink_ext_ack *extack); struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, struct sk_buff *skb, __be32 src_vni); netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, const struct vxlan_mdb_entry *mdb_entry, struct sk_buff *skb); int vxlan_mdb_init(struct vxlan_dev *vxlan); diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index 181a7614be5c..cdda7688f3af 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -171,13 +171,14 @@ static void vxlan_vnifilter_stats_add(struct vxlan_vni_node *vninode, u64_stats_update_end(&pstats->syncp); } -void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni, +void vxlan_vnifilter_count(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, __be32 vni, struct vxlan_vni_node *vninode, int type, unsigned int len) { struct vxlan_vni_node *vnode; - if (!(vxlan->cfg.flags & VXLAN_F_VNIFILTER)) + if (!cfg || !(cfg->flags & VXLAN_F_VNIFILTER)) return; if (vninode) { From 0259a5f1279f7aa39d1325bc7cc1c897d65521e5 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:10:59 +0000 Subject: [PATCH 0855/2126] vxlan: move VXLAN_F_MDB to struct vxlan_dev flags VXLAN_F_MDB is an internal runtime state flag indicating whether any MDB entries are configured on the device, rather than a netlink configuration attribute. In preparation for converting vxlan->cfg to an RCU-protected pointer, move VXLAN_F_MDB from struct vxlan_config to a dedicated 'flags' field in struct vxlan_dev as VXLAN_DEV_F_MDB, using atomic bitops (set_bit(), clear_bit(), test_bit()) to avoid KCSAN data races between the TX path and RTNL operations. This avoids having to dynamically reallocate and publish a new vxlan_config structure via RCU whenever the first MDB entry is added or the last one is removed, and prevents potential memory allocation failures during MDB teardown under memory pressure. mlxsw validates cfg->flags against a deny-by-default mask, so VXLAN_F_MDB used to make mlxsw_sp_nve_vxlan_can_offload() reject a device with MDB entries as carrying an unsupported flag. Add an explicit VXLAN_DEV_F_MDB test there to keep that rejection, with a message naming the actual reason. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260922181102.3989489-6-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c | 5 +++++ drivers/net/vxlan/vxlan_core.c | 2 +- drivers/net/vxlan/vxlan_mdb.c | 6 +++--- include/net/vxlan.h | 6 +++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c index 52c2fe3644d4..b78aff31c98f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c @@ -92,6 +92,11 @@ static bool mlxsw_sp_nve_vxlan_can_offload(const struct mlxsw_sp_nve *nve, return false; } + if (test_bit(VXLAN_DEV_F_MDB, &vxlan->flags)) { + NL_SET_ERR_MSG_MOD(extack, "VxLAN: MDB entries are not supported"); + return false; + } + switch (cfg->saddr.sa.sa_family) { case AF_INET: if (!mlxsw_sp_nve_vxlan_ipv4_flags_check(cfg, extack)) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 95d26d9a22ad..6503571b9431 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2826,7 +2826,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) if (nhid) return vxlan_xmit_nhid(skb, dev, nhid, vni, cfg); - if (flags & VXLAN_F_MDB) { + if (test_bit(VXLAN_DEV_F_MDB, &vxlan->flags)) { struct vxlan_mdb_entry *mdb_entry; rcu_read_lock(); diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c index 56ca92832833..cf606256d092 100644 --- a/drivers/net/vxlan/vxlan_mdb.c +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -1219,7 +1219,7 @@ vxlan_mdb_entry_get(struct vxlan_dev *vxlan, goto err_free_entry; if (hlist_is_singular_node(&mdb_entry->mdb_node, &vxlan->mdb_list)) - vxlan->cfg.flags |= VXLAN_F_MDB; + set_bit(VXLAN_DEV_F_MDB, &vxlan->flags); return mdb_entry; @@ -1236,7 +1236,7 @@ static void vxlan_mdb_entry_put(struct vxlan_dev *vxlan, return; if (hlist_is_singular_node(&mdb_entry->mdb_node, &vxlan->mdb_list)) - vxlan->cfg.flags &= ~VXLAN_F_MDB; + clear_bit(VXLAN_DEV_F_MDB, &vxlan->flags); rhashtable_remove_fast(&vxlan->mdb_tbl, &mdb_entry->rhnode, vxlan_mdb_rht_params); @@ -1762,7 +1762,7 @@ void vxlan_mdb_fini(struct vxlan_dev *vxlan) struct vxlan_mdb_flush_desc desc = {}; vxlan_mdb_flush(vxlan, &desc); - WARN_ON_ONCE(vxlan->cfg.flags & VXLAN_F_MDB); + WARN_ON_ONCE(test_bit(VXLAN_DEV_F_MDB, &vxlan->flags)); rhashtable_free_and_destroy(&vxlan->mdb_tbl, vxlan_mdb_check_empty, NULL); } diff --git a/include/net/vxlan.h b/include/net/vxlan.h index 7b8207505523..d323f91af236 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -300,6 +300,7 @@ struct vxlan_dev { spinlock_t hash_lock; unsigned int addrcnt; struct gro_cells gro_cells; + unsigned long flags; struct vxlan_config cfg; @@ -313,6 +314,10 @@ struct vxlan_dev { unsigned int mdb_seq; }; +enum vxlan_dev_flags { + VXLAN_DEV_F_MDB, +}; + #define VXLAN_F_LEARN 0x01 #define VXLAN_F_PROXY 0x02 #define VXLAN_F_RSC 0x04 @@ -331,7 +336,6 @@ struct vxlan_dev { #define VXLAN_F_IPV6_LINKLOCAL 0x8000 #define VXLAN_F_TTL_INHERIT 0x10000 #define VXLAN_F_VNIFILTER 0x20000 -#define VXLAN_F_MDB 0x40000 #define VXLAN_F_LOCALBYPASS 0x80000 #define VXLAN_F_MC_ROUTE 0x100000 From 0db0197ef9e1da4eb4718dff5e9568739394ff65 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:11:00 +0000 Subject: [PATCH 0856/2126] vxlan: convert configuration to RCU protection Move 'struct vxlan_config' from an embedded structure inside 'struct vxlan_dev' to a dynamically allocated RCU-protected pointer 'vxlan->cfg'. Updating configuration via vxlan_changelink() or vxlan_dev_configure() allocates a new struct vxlan_config and publishes it with rcu_assign_pointer(), freeing the previous config with kfree_rcu(). Readers are converted to use rcu_dereference() or rtnl_dereference(). In vxlan_xmit(), acquire rcu_read_lock() to protect config access. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260922181102.3989489-7-edumazet@google.com Signed-off-by: Jakub Kicinski --- .../mellanox/mlxsw/spectrum_nve_vxlan.c | 14 +- .../mellanox/mlxsw/spectrum_switchdev.c | 57 ++-- drivers/net/vxlan/vxlan_core.c | 274 ++++++++++++------ drivers/net/vxlan/vxlan_mdb.c | 10 +- drivers/net/vxlan/vxlan_multicast.c | 12 +- drivers/net/vxlan/vxlan_vnifilter.c | 21 +- include/net/vxlan.h | 3 +- 7 files changed, 263 insertions(+), 128 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c index b78aff31c98f..21e7b499f387 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c @@ -59,8 +59,11 @@ static bool mlxsw_sp_nve_vxlan_can_offload(const struct mlxsw_sp_nve *nve, const struct mlxsw_sp_nve_params *params, struct netlink_ext_ack *extack) { - struct vxlan_dev *vxlan = netdev_priv(params->dev); - struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg; + struct vxlan_dev *vxlan; + + vxlan = netdev_priv(params->dev); + cfg = rtnl_dereference(vxlan->cfg); if (vxlan_addr_multicast(&cfg->remote_ip)) { NL_SET_ERR_MSG_MOD(extack, "VxLAN: Multicast destination IP is not supported"); @@ -153,8 +156,11 @@ static void mlxsw_sp_nve_vxlan_config(const struct mlxsw_sp_nve *nve, const struct mlxsw_sp_nve_params *params, struct mlxsw_sp_nve_config *config) { - struct vxlan_dev *vxlan = netdev_priv(params->dev); - struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg; + struct vxlan_dev *vxlan; + + vxlan = netdev_priv(params->dev); + cfg = rtnl_dereference(vxlan->cfg); config->type = MLXSW_SP_NVE_TYPE_VXLAN; config->ttl = cfg->ttl; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c index fe45e533a4b2..de60b698bea9 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c @@ -2513,15 +2513,17 @@ mlxsw_sp_bridge_vlan_aware_vxlan_join(struct mlxsw_sp_bridge_device *bridge_devi { struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev); struct vxlan_dev *vxlan = netdev_priv(vxlan_dev); - struct mlxsw_sp_nve_params params = { - .type = MLXSW_SP_NVE_TYPE_VXLAN, - .vni = vxlan->cfg.vni, - .dev = vxlan_dev, - .ethertype = ethertype, - }; + struct mlxsw_sp_nve_params params; + const struct vxlan_config *cfg; struct mlxsw_sp_fid *fid; int err; + cfg = rtnl_dereference(vxlan->cfg); + params.type = MLXSW_SP_NVE_TYPE_VXLAN; + params.vni = cfg->vni; + params.dev = vxlan_dev; + params.ethertype = ethertype; + /* If the VLAN is 0, we need to find the VLAN that is configured as * PVID and egress untagged on the bridge port of the VxLAN device. * It is possible no such VLAN exists @@ -2704,15 +2706,17 @@ mlxsw_sp_bridge_8021d_vxlan_join(struct mlxsw_sp_bridge_device *bridge_device, { struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(bridge_device->dev); struct vxlan_dev *vxlan = netdev_priv(vxlan_dev); - struct mlxsw_sp_nve_params params = { - .type = MLXSW_SP_NVE_TYPE_VXLAN, - .vni = vxlan->cfg.vni, - .dev = vxlan_dev, - .ethertype = ETH_P_8021Q, - }; + struct mlxsw_sp_nve_params params; + const struct vxlan_config *cfg; struct mlxsw_sp_fid *fid; int err; + cfg = rtnl_dereference(vxlan->cfg); + params.type = MLXSW_SP_NVE_TYPE_VXLAN; + params.vni = cfg->vni; + params.dev = vxlan_dev; + params.ethertype = ETH_P_8021Q; + fid = mlxsw_sp_fid_8021d_get(mlxsw_sp, bridge_device->dev->ifindex); if (IS_ERR(fid)) { NL_SET_ERR_MSG_MOD(extack, "Failed to create 802.1D FID"); @@ -2933,10 +2937,13 @@ static void __mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp, const struct net_device *vxlan_dev) { struct vxlan_dev *vxlan = netdev_priv(vxlan_dev); + const struct vxlan_config *cfg; struct mlxsw_sp_fid *fid; + cfg = rtnl_dereference(vxlan->cfg); + /* If the VxLAN device is down, then the FID does not have a VNI */ - fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vxlan->cfg.vni); + fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, cfg->vni); if (!fid) return; @@ -3029,11 +3036,13 @@ static void mlxsw_sp_fdb_vxlan_call_notifiers(struct net_device *dev, struct switchdev_notifier_vxlan_fdb_info info; struct vxlan_dev *vxlan = netdev_priv(dev); enum switchdev_notifier_type type; + const struct vxlan_config *cfg; + cfg = rtnl_dereference(vxlan->cfg); type = adding ? SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE : SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE; mlxsw_sp_switchdev_addr_vxlan_convert(proto, addr, &info.remote_ip); - info.remote_port = vxlan->cfg.dst_port; + info.remote_port = cfg->dst_port; info.remote_vni = vni; info.remote_ifindex = 0; ether_addr_copy(info.eth_addr, mac); @@ -3236,8 +3245,10 @@ __mlxsw_sp_fdb_notify_mac_uc_tunnel_process(struct mlxsw_sp *mlxsw_sp, if (adding && netif_is_vxlan(dev)) { struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *cfg; - if (!(vxlan->cfg.flags & VXLAN_F_LEARN)) + cfg = rtnl_dereference(vxlan->cfg); + if (!(cfg->flags & VXLAN_F_LEARN)) return -EINVAL; } @@ -3722,9 +3733,11 @@ mlxsw_sp_switchdev_vxlan_work_prepare(struct mlxsw_sp_switchdev_event_work * { struct vxlan_dev *vxlan = netdev_priv(switchdev_work->dev); struct switchdev_notifier_vxlan_fdb_info *vxlan_fdb_info; - struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg; struct netlink_ext_ack *extack; + cfg = rcu_dereference_rtnl(vxlan->cfg); + extack = switchdev_notifier_info_to_extack(info); vxlan_fdb_info = container_of(info, struct switchdev_notifier_vxlan_fdb_info, @@ -3851,11 +3864,15 @@ mlxsw_sp_switchdev_vxlan_vlan_add(struct mlxsw_sp *mlxsw_sp, struct netlink_ext_ack *extack) { struct vxlan_dev *vxlan = netdev_priv(vxlan_dev); - __be32 vni = vxlan->cfg.vni; + const struct vxlan_config *cfg; struct mlxsw_sp_fid *fid; u16 old_vid; + __be32 vni; int err; + cfg = rtnl_dereference(vxlan->cfg); + vni = cfg->vni; + /* We cannot have the same VLAN as PVID and egress untagged on multiple * VxLAN devices. Note that we get this notification before the VLAN is * actually added to the bridge's database, so it is not possible for @@ -3935,12 +3952,16 @@ mlxsw_sp_switchdev_vxlan_vlan_del(struct mlxsw_sp *mlxsw_sp, const struct net_device *vxlan_dev, u16 vid) { struct vxlan_dev *vxlan = netdev_priv(vxlan_dev); - __be32 vni = vxlan->cfg.vni; + const struct vxlan_config *cfg; struct mlxsw_sp_fid *fid; + __be32 vni; if (!netif_running(vxlan_dev)) return; + cfg = rtnl_dereference(vxlan->cfg); + vni = cfg->vni; + fid = mlxsw_sp_fid_lookup_by_vni(mlxsw_sp, vni); if (!fid) return; diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 6503571b9431..783337fc4483 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -110,20 +110,23 @@ static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, vni = 0; hlist_for_each_entry_rcu(node, vni_head(vs, vni), hlist) { + const struct vxlan_config *cfg; + if (!node->vxlan) continue; + + cfg = rcu_dereference(node->vxlan->cfg); + vnode = NULL; - if (node->vxlan->cfg.flags & VXLAN_F_VNIFILTER) { + if (cfg->flags & VXLAN_F_VNIFILTER) { vnode = vxlan_vnifilter_lookup(node->vxlan, vni); if (!vnode) continue; - } else if (node->vxlan->default_dst.remote_vni != vni) { + } else if (cfg->vni != vni) { continue; } if (IS_ENABLED(CONFIG_IPV6)) { - const struct vxlan_config *cfg = &node->vxlan->cfg; - if ((cfg->flags & VXLAN_F_IPV6_LINKLOCAL) && cfg->remote_ifindex != ifindex) continue; @@ -157,6 +160,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, u32 portid, u32 seq, int type, unsigned int flags, const struct vxlan_rdst *rdst) { + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg); unsigned long now = jiffies; struct nda_cacheinfo ci; bool send_ip, send_eth; @@ -216,10 +220,10 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, goto nla_put_failure; if (rdst->remote_port && - rdst->remote_port != vxlan->cfg.dst_port && + rdst->remote_port != cfg->dst_port && nla_put_be16(skb, NDA_PORT, rdst->remote_port)) goto nla_put_failure; - if (rdst->remote_vni != vxlan->default_dst.remote_vni && + if (rdst->remote_vni != cfg->vni && nla_put_u32(skb, NDA_VNI, be32_to_cpu(rdst->remote_vni))) goto nla_put_failure; if (rdst->remote_ifindex && @@ -227,7 +231,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, goto nla_put_failure; } - if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && fdb->key.vni && + if ((cfg->flags & VXLAN_F_COLLECT_METADATA) && fdb->key.vni && nla_put_u32(skb, NDA_SRC_VNI, be32_to_cpu(fdb->key.vni))) goto nla_put_failure; @@ -418,7 +422,7 @@ static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan, lockdep_assert_held_once(&vxlan->hash_lock); rcu_read_lock(); - f = vxlan_find_mac_rcu(vxlan, &vxlan->cfg, mac, vni); + f = vxlan_find_mac_rcu(vxlan, rcu_dereference(vxlan->cfg), mac, vni); rcu_read_unlock(); return f; @@ -459,7 +463,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, rcu_read_lock(); - f = vxlan_find_mac_rcu(vxlan, &vxlan->cfg, eth_addr, vni); + f = vxlan_find_mac_rcu(vxlan, rcu_dereference(vxlan->cfg), eth_addr, vni); if (f) rdst = first_remote_rcu(f); if (!rdst) { @@ -865,12 +869,13 @@ int vxlan_fdb_create(struct vxlan_dev *vxlan, u32 nhid, struct vxlan_fdb **fdb, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg); struct vxlan_rdst *rd = NULL; struct vxlan_fdb *f; int rc; - if (vxlan->cfg.addrmax && - vxlan->addrcnt >= vxlan->cfg.addrmax) + if (cfg->addrmax && + vxlan->addrcnt >= cfg->addrmax) return -ENOSPC; netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip); @@ -1156,6 +1161,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, __be32 *vni, u32 *ifindex, u32 *nhid, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); struct net *net = dev_net(vxlan->dev); int err; @@ -1172,7 +1178,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, return err; } } else { - union vxlan_addr *remote = &vxlan->default_dst.remote_ip; + const union vxlan_addr *remote = &cfg->remote_ip; if (remote->sa.sa_family == AF_INET) { ip->sin.sin_addr.s_addr = htonl(INADDR_ANY); @@ -1192,7 +1198,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, } *port = nla_get_be16(tb[NDA_PORT]); } else { - *port = vxlan->cfg.dst_port; + *port = cfg->dst_port; } if (tb[NDA_VNI]) { @@ -1202,7 +1208,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, } *vni = cpu_to_be32(nla_get_u32(tb[NDA_VNI])); } else { - *vni = vxlan->default_dst.remote_vni; + *vni = cfg->vni; } if (tb[NDA_SRC_VNI]) { @@ -1212,7 +1218,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, } *src_vni = cpu_to_be32(nla_get_u32(tb[NDA_SRC_VNI])); } else { - *src_vni = vxlan->default_dst.remote_vni; + *src_vni = cfg->vni; } if (tb[NDA_IFINDEX]) { @@ -1407,18 +1413,21 @@ static int vxlan_fdb_get(struct sk_buff *skb, struct netlink_ext_ack *extack) { struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *cfg; struct vxlan_fdb *f; __be32 vni; int err; + cfg = rcu_dereference_rtnl(vxlan->cfg); + if (tb[NDA_VNI]) vni = cpu_to_be32(nla_get_u32(tb[NDA_VNI])); else - vni = vxlan->default_dst.remote_vni; + vni = cfg->vni; rcu_read_lock(); - f = vxlan_find_mac_rcu(vxlan, &vxlan->cfg, addr, vni); + f = vxlan_find_mac_rcu(vxlan, cfg, addr, vni); if (!f) { NL_SET_ERR_MSG(extack, "Fdb entry not found"); err = -ENOENT; @@ -1521,6 +1530,7 @@ static bool __vxlan_sock_release_prep(struct vxlan_sock *vs) static void vxlan_sock_release(struct vxlan_dev *vxlan) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); #if IS_ENABLED(CONFIG_IPV6) struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); @@ -1530,7 +1540,7 @@ static void vxlan_sock_release(struct vxlan_dev *vxlan) RCU_INIT_POINTER(vxlan->vn4_sock, NULL); - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) + if (cfg->flags & VXLAN_F_VNIFILTER) vxlan_vs_del_vnigrp(vxlan); else vxlan_vs_del_dev(vxlan); @@ -1703,7 +1713,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop; } - cfg = &vxlan->cfg; + cfg = rcu_dereference(vxlan->cfg); + if (vh->vx_flags & cfg->reserved_bits.vx_flags || vh->vx_vni & cfg->reserved_bits.vx_vni) { /* If the header uses bits besides those enabled by the @@ -1859,7 +1870,8 @@ static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb) return 0; } -static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u32 flags) +static int arp_reduce(struct net_device *dev, struct sk_buff *skb, + const struct vxlan_config *cfg, __be32 vni) { struct neigh_table *tbl = arp_table(dev_net(dev)); struct vxlan_dev *vxlan = netdev_priv(dev); @@ -1873,7 +1885,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u if (!pskb_network_may_pull(skb, arp_hdr_len(dev))) { dev_dstats_tx_dropped(dev); - vxlan_vnifilter_count(vxlan, &vxlan->cfg, vni, NULL, + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0); goto out; } @@ -1914,7 +1926,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u neigh_ha_snapshot(ha, n, n->dev); rcu_read_lock(); - f = vxlan_find_mac_tx(vxlan, &vxlan->cfg, ha, vni); + f = vxlan_find_mac_tx(vxlan, cfg, ha, vni); if (f) rdst = first_remote_rcu(f); if (rdst && vxlan_addr_any(&rdst->remote_ip)) { @@ -1940,11 +1952,11 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u if (netif_rx(reply) == NET_RX_DROP) { dev_dstats_rx_dropped(dev); - vxlan_vnifilter_count(vxlan, &vxlan->cfg, vni, NULL, + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_RX_DROPS, 0); } - } else if (flags & VXLAN_F_L3MISS) { + } else if (cfg->flags & VXLAN_F_L3MISS) { union vxlan_addr ipa = { .sin.sin_addr.s_addr = tip, .sin.sin_family = AF_INET, @@ -2054,7 +2066,8 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, return reply; } -static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, u32 flags) +static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, + const struct vxlan_config *cfg, __be32 vni) { struct vxlan_dev *vxlan = netdev_priv(dev); const struct in6_addr *daddr; @@ -2088,7 +2101,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, } neigh_ha_snapshot(ha, n, n->dev); - f = vxlan_find_mac_tx(vxlan, &vxlan->cfg, ha, vni); + f = vxlan_find_mac_tx(vxlan, cfg, ha, vni); if (f) rdst = first_remote_rcu(f); if (rdst && vxlan_addr_any(&rdst->remote_ip)) { @@ -2107,10 +2120,10 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni, if (netif_rx(reply) == NET_RX_DROP) { dev_dstats_rx_dropped(dev); - vxlan_vnifilter_count(vxlan, &vxlan->cfg, vni, NULL, + vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_RX_DROPS, 0); } - } else if (flags & VXLAN_F_L3MISS) { + } else if (cfg->flags & VXLAN_F_L3MISS) { union vxlan_addr ipa = { .sin6.sin6_addr = msg->target, .sin6.sin6_family = AF_INET6, @@ -2297,7 +2310,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, const struct vxlan_config *src_cfg, __be32 vni, bool snoop) { - const struct vxlan_config *dst_cfg = &dst_vxlan->cfg; + const struct vxlan_config *dst_cfg; union vxlan_addr loopback; unsigned int len = skb->len; struct net_device *dev = dst_vxlan->dev; @@ -2318,6 +2331,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, } rcu_read_lock(); + dst_cfg = rcu_dereference(dst_vxlan->cfg); if (unlikely(!(dev->flags & IFF_UP))) { kfree_skb_reason(skb, SKB_DROP_REASON_DEV_READY); goto drop; @@ -2783,7 +2797,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) u32 nhid = 0; u32 flags; - cfg = &vxlan->cfg; + rcu_read_lock(); + cfg = rcu_dereference(vxlan->cfg); flags = cfg->flags; default_vni = cfg->vni; @@ -2801,14 +2816,19 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) vxlan_xmit_one(skb, dev, cfg, vni, NULL, false); else kfree_skb_reason(skb, SKB_DROP_REASON_TUNNEL_TXINFO); + rcu_read_unlock(); return NETDEV_TX_OK; } } if (flags & VXLAN_F_PROXY) { eth = eth_hdr(skb); - if (ntohs(eth->h_proto) == ETH_P_ARP) - return arp_reduce(dev, skb, vni, flags); + if (ntohs(eth->h_proto) == ETH_P_ARP) { + netdev_tx_t res = arp_reduce(dev, skb, cfg, vni); + + rcu_read_unlock(); + return res; + } #if IS_ENABLED(CONFIG_IPV6) else if (ntohs(eth->h_proto) == ETH_P_IPV6 && pskb_network_may_pull(skb, sizeof(struct ipv6hdr) + @@ -2817,32 +2837,36 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) struct nd_msg *m = (struct nd_msg *)(ipv6_hdr(skb) + 1); if (m->icmph.icmp6_code == 0 && - m->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) - return neigh_reduce(dev, skb, vni, flags); + m->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) { + netdev_tx_t res = neigh_reduce(dev, skb, cfg, vni); + + rcu_read_unlock(); + return res; + } } #endif } - if (nhid) - return vxlan_xmit_nhid(skb, dev, nhid, vni, cfg); + if (nhid) { + netdev_tx_t res = vxlan_xmit_nhid(skb, dev, nhid, vni, cfg); + + rcu_read_unlock(); + return res; + } if (test_bit(VXLAN_DEV_F_MDB, &vxlan->flags)) { struct vxlan_mdb_entry *mdb_entry; - rcu_read_lock(); mdb_entry = vxlan_mdb_entry_skb_get(vxlan, cfg, skb, vni); if (mdb_entry) { - netdev_tx_t ret; + netdev_tx_t ret = vxlan_mdb_xmit(vxlan, cfg, mdb_entry, skb); - ret = vxlan_mdb_xmit(vxlan, cfg, mdb_entry, skb); rcu_read_unlock(); return ret; } - rcu_read_unlock(); } eth = eth_hdr(skb); - rcu_read_lock(); f = vxlan_find_mac_tx(vxlan, cfg, eth->h_dest, vni); did_rsc = false; @@ -2901,12 +2925,15 @@ static void vxlan_cleanup(struct timer_list *t) { struct vxlan_dev *vxlan = timer_container_of(vxlan, t, age_timer); unsigned long next_timer = jiffies + FDB_AGE_INTERVAL; + const struct vxlan_config *cfg; struct vxlan_fdb *f; if (!netif_running(vxlan->dev)) return; rcu_read_lock(); + cfg = rcu_dereference(vxlan->cfg); + hlist_for_each_entry_rcu(f, &vxlan->fdb_list, fdb_node) { unsigned long timeout; @@ -2916,7 +2943,7 @@ static void vxlan_cleanup(struct timer_list *t) if (f->flags & NTF_EXT_LEARNED) continue; - timeout = READ_ONCE(f->updated) + vxlan->cfg.age_interval * HZ; + timeout = READ_ONCE(f->updated) + cfg->age_interval * HZ; if (time_before_eq(timeout, jiffies)) { spin_lock(&vxlan->hash_lock); if (!hlist_unhashed(&f->fdb_node)) { @@ -2960,13 +2987,16 @@ static void vxlan_vs_add_dev(struct vxlan_sock *vs, struct vxlan_dev *vxlan, static int vxlan_init(struct net_device *dev) { struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *cfg; int err; + cfg = rtnl_dereference(vxlan->cfg); + err = rhashtable_init(&vxlan->fdb_hash_tbl, &vxlan_fdb_rht_params); if (err) return err; - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) { + if (cfg->flags & VXLAN_F_VNIFILTER) { err = vxlan_vnigroup_init(vxlan); if (err) goto err_rhashtable_destroy; @@ -2986,7 +3016,7 @@ static int vxlan_init(struct net_device *dev) err_gro_cells_destroy: gro_cells_destroy(&vxlan->gro_cells); err_vnigroup_uninit: - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) + if (cfg->flags & VXLAN_F_VNIFILTER) vxlan_vnigroup_uninit(vxlan); err_rhashtable_destroy: rhashtable_destroy(&vxlan->fdb_hash_tbl); @@ -2996,10 +3026,13 @@ err_rhashtable_destroy: static void vxlan_uninit(struct net_device *dev) { struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *cfg; + + cfg = rtnl_dereference(vxlan->cfg); vxlan_mdb_fini(vxlan); - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) + if (cfg->flags & VXLAN_F_VNIFILTER) vxlan_vnigroup_uninit(vxlan); gro_cells_destroy(&vxlan->gro_cells); @@ -3011,6 +3044,7 @@ static void vxlan_uninit(struct net_device *dev) static int vxlan_open(struct net_device *dev) { struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *cfg; int ret; ret = vxlan_sock_add(vxlan); @@ -3023,7 +3057,8 @@ static int vxlan_open(struct net_device *dev) return ret; } - if (vxlan->cfg.age_interval) + cfg = rtnl_dereference(vxlan->cfg); + if (cfg->age_interval) mod_timer(&vxlan->age_timer, jiffies + FDB_AGE_INTERVAL); return ret; @@ -3045,8 +3080,10 @@ struct vxlan_fdb_flush_desc { static bool vxlan_fdb_is_default_entry(const struct vxlan_fdb *f, const struct vxlan_dev *vxlan) { + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg); + return is_zero_ether_addr(f->key.eth_addr) && - f->key.vni == vxlan->cfg.vni; + f->key.vni == cfg->vni; } static bool vxlan_fdb_nhid_matches(const struct vxlan_fdb *f, u32 nhid) @@ -3264,14 +3301,18 @@ static int vxlan_change_mtu(struct net_device *dev, int new_mtu) { struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_rdst *dst = &vxlan->default_dst; - struct net_device *lowerdev = __dev_get_by_index(vxlan->net, - dst->remote_ifindex); + const struct vxlan_config *cfg; + struct net_device *lowerdev; + + cfg = rtnl_dereference(vxlan->cfg); + + lowerdev = __dev_get_by_index(vxlan->net, dst->remote_ifindex); /* This check is different than dev->max_mtu, because it looks at * the lowerdev->mtu, rather than the static dev->max_mtu */ if (lowerdev) { - int max_mtu = lowerdev->mtu - vxlan_headroom(vxlan->cfg.flags); + int max_mtu = lowerdev->mtu - vxlan_headroom(cfg->flags); if (new_mtu > max_mtu) return -EINVAL; } @@ -3284,11 +3325,14 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) { struct vxlan_dev *vxlan = netdev_priv(dev); struct ip_tunnel_info *info = skb_tunnel_info(skb); + const struct vxlan_config *cfg; __be16 sport, dport; - sport = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, - vxlan->cfg.port_max, true); - dport = info->key.tp_dst ? : vxlan->cfg.dst_port; + cfg = rcu_dereference(vxlan->cfg); + + sport = udp_flow_src_port(dev_net(dev), skb, cfg->port_min, + cfg->port_max, true); + dport = info->key.tp_dst ? : cfg->dst_port; if (ip_tunnel_info_af(info) == AF_INET) { struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); @@ -3398,6 +3442,15 @@ static void vxlan_offload_rx_ports(struct net_device *dev, bool push) } } +static void vxlan_free_dev(struct net_device *dev) +{ + struct vxlan_dev *vxlan = netdev_priv(dev); + struct vxlan_config *cfg = rcu_dereference_protected(vxlan->cfg, 1); + + RCU_INIT_POINTER(vxlan->cfg, NULL); + kfree(cfg); +} + /* Initialize the device structure. */ static void vxlan_setup(struct net_device *dev) { @@ -3406,6 +3459,8 @@ static void vxlan_setup(struct net_device *dev) eth_hw_addr_random(dev); ether_setup(dev); + dev->priv_destructor = vxlan_free_dev; + dev->needs_free_netdev = true; SET_NETDEV_DEVTYPE(dev, &vxlan_type); @@ -3688,21 +3743,22 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6, static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6) { - bool metadata = vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA; + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); + bool metadata = cfg->flags & VXLAN_F_COLLECT_METADATA; struct vxlan_sock *vs = NULL; struct vxlan_dev_node *node; int l3mdev_index = 0; ASSERT_RTNL(); - if (vxlan->cfg.remote_ifindex) + if (cfg->remote_ifindex) l3mdev_index = l3mdev_master_upper_ifindex_by_index( - vxlan->net, vxlan->cfg.remote_ifindex); + vxlan->net, cfg->remote_ifindex); - if (!vxlan->cfg.no_share) { + if (!cfg->no_share) { rcu_read_lock(); vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET, - vxlan->cfg.dst_port, vxlan->cfg.flags, + cfg->dst_port, cfg->flags, l3mdev_index); if (vs && !refcount_inc_not_zero(&vs->refcnt)) { rcu_read_unlock(); @@ -3712,7 +3768,7 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6) } if (!vs) vs = vxlan_socket_create(vxlan->net, ipv6, - vxlan->cfg.dst_port, vxlan->cfg.flags, + cfg->dst_port, cfg->flags, l3mdev_index); if (IS_ERR(vs)) return PTR_ERR(vs); @@ -3727,7 +3783,7 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6) node = &vxlan->hlist4; } - if (metadata && (vxlan->cfg.flags & VXLAN_F_VNIFILTER)) + if (metadata && (cfg->flags & VXLAN_F_VNIFILTER)) vxlan_vs_add_vnigrp(vxlan, vs, ipv6); else vxlan_vs_add_dev(vs, vxlan, node); @@ -3737,11 +3793,14 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6) static int vxlan_sock_add(struct vxlan_dev *vxlan) { - bool metadata = vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA; - bool ipv6 = vxlan->cfg.flags & VXLAN_F_IPV6 || metadata; - bool ipv4 = !ipv6 || metadata; + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); + bool metadata, ipv6, ipv4; int ret = 0; + metadata = cfg->flags & VXLAN_F_COLLECT_METADATA; + ipv6 = (cfg->flags & VXLAN_F_IPV6) || metadata; + ipv4 = !ipv6 || metadata; + RCU_INIT_POINTER(vxlan->vn4_sock, NULL); #if IS_ENABLED(CONFIG_IPV6) RCU_INIT_POINTER(vxlan->vn6_sock, NULL); @@ -3765,22 +3824,27 @@ int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan, struct vxlan_dev *tmp; list_for_each_entry(tmp, &vn->vxlan_list, next) { + const struct vxlan_config *tmp_cfg; + if (tmp == vxlan) continue; - if (tmp->cfg.flags & VXLAN_F_VNIFILTER) { + + tmp_cfg = rtnl_dereference(tmp->cfg); + + if (tmp_cfg->flags & VXLAN_F_VNIFILTER) { if (!vxlan_vnifilter_lookup(tmp, vni)) continue; - } else if (tmp->cfg.vni != vni) { + } else if (tmp_cfg->vni != vni) { continue; } - if (tmp->cfg.dst_port != conf->dst_port) + if (tmp_cfg->dst_port != conf->dst_port) continue; - if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) != + if ((tmp_cfg->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) != (conf->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6))) continue; if ((conf->flags & VXLAN_F_IPV6_LINKLOCAL) && - tmp->cfg.remote_ifindex != conf->remote_ifindex) + tmp_cfg->remote_ifindex != conf->remote_ifindex) continue; return -EEXIST; @@ -3942,7 +4006,7 @@ static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf, } static void vxlan_config_apply(struct net_device *dev, - struct vxlan_config *conf, + struct vxlan_config *new_cfg, struct net_device *lowerdev, struct net *src_net, bool changelink) @@ -3950,8 +4014,9 @@ static void vxlan_config_apply(struct net_device *dev, struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_rdst *dst = &vxlan->default_dst; unsigned short needed_headroom = ETH_HLEN; + struct vxlan_config *old_cfg; int max_mtu = ETH_MAX_MTU; - u32 flags = conf->flags; + u32 flags = new_cfg->flags; if (!changelink) { if (flags & VXLAN_F_GPE) @@ -3959,18 +4024,18 @@ static void vxlan_config_apply(struct net_device *dev, else vxlan_ether_setup(dev); - if (conf->mtu) - dev->mtu = conf->mtu; + if (new_cfg->mtu) + dev->mtu = new_cfg->mtu; vxlan->net = src_net; } - dst->remote_vni = conf->vni; + dst->remote_vni = new_cfg->vni; - memcpy(&dst->remote_ip, &conf->remote_ip, sizeof(conf->remote_ip)); + memcpy(&dst->remote_ip, &new_cfg->remote_ip, sizeof(new_cfg->remote_ip)); if (lowerdev) { - dst->remote_ifindex = conf->remote_ifindex; + dst->remote_ifindex = new_cfg->remote_ifindex; netif_inherit_tso_max(dev, lowerdev); @@ -3983,7 +4048,7 @@ static void vxlan_config_apply(struct net_device *dev, if (max_mtu < ETH_MIN_MTU) max_mtu = ETH_MIN_MTU; - if (!changelink && !conf->mtu) + if (!changelink && !new_cfg->mtu) dev->mtu = max_mtu; } @@ -3995,7 +4060,10 @@ static void vxlan_config_apply(struct net_device *dev, needed_headroom += vxlan_headroom(flags); dev->needed_headroom = needed_headroom; - memcpy(&vxlan->cfg, conf, sizeof(*conf)); + old_cfg = rtnl_dereference(vxlan->cfg); + rcu_assign_pointer(vxlan->cfg, new_cfg); + if (old_cfg) + kfree_rcu(old_cfg, rcu); } static int vxlan_dev_configure(struct net *src_net, struct net_device *dev, @@ -4004,13 +4072,18 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev, { struct vxlan_dev *vxlan = netdev_priv(dev); struct net_device *lowerdev; + struct vxlan_config *new_cfg; int ret; ret = vxlan_config_validate(src_net, conf, &lowerdev, vxlan, extack); if (ret) return ret; - vxlan_config_apply(dev, conf, lowerdev, src_net, false); + new_cfg = kmemdup(conf, sizeof(*conf), GFP_KERNEL); + if (!new_cfg) + return -ENOMEM; + + vxlan_config_apply(dev, new_cfg, lowerdev, src_net, false); return 0; } @@ -4022,6 +4095,7 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, struct vxlan_net *vn = net_generic(net, vxlan_net_id); struct vxlan_dev *vxlan = netdev_priv(dev); struct net_device *remote_dev = NULL; + const struct vxlan_config *cfg; struct vxlan_rdst *dst; int err; @@ -4030,11 +4104,15 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, if (err) return err; + cfg = rtnl_dereference(vxlan->cfg); + dev->ethtool_ops = &vxlan_ethtool_ops; err = register_netdevice(dev); - if (err) + if (err) { + vxlan_free_dev(dev); return err; + } if (dst->remote_ifindex) { remote_dev = __dev_get_by_index(net, dst->remote_ifindex); @@ -4061,7 +4139,7 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, &dst->remote_ip, NUD_REACHABLE | NUD_PERMANENT, NLM_F_EXCL | NLM_F_CREATE, - vxlan->cfg.dst_port, + cfg->dst_port, dst->remote_vni, dst->remote_vni, dst->remote_ifindex, @@ -4125,8 +4203,12 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], memset(conf, 0, sizeof(*conf)); /* if changelink operation, start with old existing cfg */ - if (changelink) - memcpy(conf, &vxlan->cfg, sizeof(*conf)); + if (changelink) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); + + if (cfg) + memcpy(conf, cfg, sizeof(*conf)); + } if (data[IFLA_VXLAN_ID]) { __be32 vni = cpu_to_be32(nla_get_u32(data[IFLA_VXLAN_ID])); @@ -4473,9 +4555,11 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) { struct vxlan_dev *vxlan = netdev_priv(dev); + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); bool rem_ip_changed, change_igmp; struct net_device *lowerdev; struct vxlan_config conf; + struct vxlan_config *new_cfg; struct vxlan_rdst *dst; u32 new_ifindex; int err; @@ -4493,13 +4577,19 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], if (err) return err; + new_cfg = kmemdup(&conf, sizeof(conf), GFP_KERNEL); + if (!new_cfg) + return -ENOMEM; + if (dst->remote_dev == lowerdev) lowerdev = NULL; err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev, extack); - if (err) + if (err) { + kfree(new_cfg); return err; + } /* vxlan_config_apply() only commits remote_ifindex if lowerdev is set */ new_ifindex = lowerdev ? conf.remote_ifindex : dst->remote_ifindex; @@ -4517,7 +4607,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], &conf.remote_ip, NUD_REACHABLE | NUD_PERMANENT, NLM_F_APPEND | NLM_F_CREATE, - vxlan->cfg.dst_port, + cfg->dst_port, conf.vni, conf.vni, new_ifindex, NTF_SELF, 0, true, extack); @@ -4525,13 +4615,14 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], spin_unlock_bh(&vxlan->hash_lock); netdev_adjacent_change_abort(dst->remote_dev, lowerdev, dev); + kfree(new_cfg); return err; } } if (!vxlan_addr_any(&dst->remote_ip)) __vxlan_fdb_delete(vxlan, all_zeros_mac, dst->remote_ip, - vxlan->cfg.dst_port, + cfg->dst_port, dst->remote_vni, dst->remote_vni, dst->remote_ifindex, @@ -4541,7 +4632,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], /* If vni filtering device, also update default fdb entries of * all vnis */ - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) { + if (cfg->flags & VXLAN_F_VNIFILTER) { err = vxlan_vnilist_update_group(vxlan, &dst->remote_ip, &conf.remote_ip, dst->remote_ifindex, @@ -4555,6 +4646,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], NULL); netdev_adjacent_change_abort(dst->remote_dev, lowerdev, dev); + kfree(new_cfg); return err; } } @@ -4562,20 +4654,20 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], if (change_igmp && (vxlan_addr_multicast(&dst->remote_ip) || - (vxlan->cfg.flags & VXLAN_F_VNIFILTER))) + (cfg->flags & VXLAN_F_VNIFILTER))) err = vxlan_multicast_leave(vxlan); - if (netif_running(dev) && conf.age_interval != vxlan->cfg.age_interval) + if (netif_running(dev) && conf.age_interval != cfg->age_interval) mod_timer(&vxlan->age_timer, jiffies); netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev); if (lowerdev && lowerdev != dst->remote_dev) dst->remote_dev = lowerdev; - vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true); + vxlan_config_apply(dev, new_cfg, lowerdev, vxlan->net, true); if (change_igmp && (vxlan_addr_multicast(&dst->remote_ip) || - (vxlan->cfg.flags & VXLAN_F_VNIFILTER))) { + (new_cfg->flags & VXLAN_F_VNIFILTER))) { int join_err = vxlan_multicast_join(vxlan); if (join_err) @@ -4643,7 +4735,7 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) struct ifla_vxlan_port_range ports; const struct vxlan_config *cfg; - cfg = &vxlan->cfg; + cfg = rtnl_dereference(vxlan->cfg); if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(dst->remote_vni))) goto nla_put_failure; diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c index cf606256d092..4ae6369ed4e3 100644 --- a/drivers/net/vxlan/vxlan_mdb.c +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -165,7 +165,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { - const struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg); struct vxlan_rdst *rd = rtnl_dereference(remote->rd); struct br_mdb_entry e; struct nlattr *nest; @@ -614,7 +614,9 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, { struct br_mdb_entry *entry = nla_data(tb[MDBA_SET_ENTRY]); struct vxlan_dev *vxlan = netdev_priv(dev); - const struct vxlan_config *vcfg = &vxlan->cfg; + const struct vxlan_config *vcfg; + + vcfg = rtnl_dereference(vxlan->cfg); memset(cfg, 0, sizeof(*cfg)); cfg->vxlan = vxlan; @@ -959,12 +961,12 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan, const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { - const struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg); const struct vxlan_mdb_entry_key *group = &mdb_entry->key; struct vxlan_rdst *rd = rtnl_dereference(remote->rd); size_t nlmsg_size; - /* MDBA_MDB_ENTRY_INFO */ + /* MDBA_MDB_ENTRY_INFO */ nlmsg_size = nla_total_size(sizeof(struct br_mdb_entry)) + /* MDBA_MDB_EATTR_TIMER */ nla_total_size(sizeof(u32)); diff --git a/drivers/net/vxlan/vxlan_multicast.c b/drivers/net/vxlan/vxlan_multicast.c index b85283605aaf..c717540e95ab 100644 --- a/drivers/net/vxlan/vxlan_multicast.c +++ b/drivers/net/vxlan/vxlan_multicast.c @@ -147,6 +147,8 @@ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, #endif list_for_each_entry(vxlan, &vn->vxlan_list, next) { + const struct vxlan_config *cfg; + if (!netif_running(vxlan->dev) || vxlan == dev) continue; @@ -158,7 +160,9 @@ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, rtnl_dereference(vxlan->vn6_sock) != sock6) continue; #endif - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) { + cfg = rtnl_dereference(vxlan->cfg); + + if (cfg->flags & VXLAN_F_VNIFILTER) { if (!vxlan_group_used_by_vnifilter(vxlan, ip, ifindex)) continue; } else { @@ -240,6 +244,7 @@ static int vxlan_multicast_leave_vnigrp(struct vxlan_dev *vxlan) int vxlan_multicast_join(struct vxlan_dev *vxlan) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); int ret = 0; if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip)) { @@ -251,7 +256,7 @@ int vxlan_multicast_join(struct vxlan_dev *vxlan) return ret; } - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) + if (cfg->flags & VXLAN_F_VNIFILTER) return vxlan_multicast_join_vnigrp(vxlan); return 0; @@ -259,6 +264,7 @@ int vxlan_multicast_join(struct vxlan_dev *vxlan) int vxlan_multicast_leave(struct vxlan_dev *vxlan) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); int ret = 0; @@ -272,7 +278,7 @@ int vxlan_multicast_leave(struct vxlan_dev *vxlan) return ret; } - if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) + if (cfg->flags & VXLAN_F_VNIFILTER) return vxlan_multicast_leave_vnigrp(vxlan); return 0; diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index cdda7688f3af..d16d5a6c7dad 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -178,7 +178,7 @@ void vxlan_vnifilter_count(struct vxlan_dev *vxlan, { struct vxlan_vni_node *vnode; - if (!cfg || !(cfg->flags & VXLAN_F_VNIFILTER)) + if (!(cfg->flags & VXLAN_F_VNIFILTER)) return; if (vninode) { @@ -337,6 +337,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, struct vxlan_vni_node *v, *vbegin = NULL, *vend = NULL; struct vxlan_dev *vxlan = netdev_priv(dev); struct tunnel_msg *new_tmsg, *tmsg; + const struct vxlan_config *cfg; struct vxlan_vni_group *vg; struct nlmsghdr *nlh; int idx = 0, s_idx; @@ -349,7 +350,8 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, } s_idx = cb->args[1]; - if (!(vxlan->cfg.flags & VXLAN_F_VNIFILTER)) { + cfg = rcu_dereference(vxlan->cfg); + if (!(cfg->flags & VXLAN_F_VNIFILTER)) { cb->args[1] = 0; cb->args[2] = 0; return -EINVAL; @@ -506,6 +508,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); int err = 0; if (old_remote_ip && remote_ip && @@ -519,7 +522,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, remote_ip, NUD_REACHABLE | NUD_PERMANENT, NLM_F_APPEND | NLM_F_CREATE, - vxlan->cfg.dst_port, + cfg->dst_port, vni, vni, new_ifindex, @@ -533,7 +536,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, if (old_remote_ip && !vxlan_addr_any(old_remote_ip)) { __vxlan_fdb_delete(vxlan, all_zeros_mac, *old_remote_ip, - vxlan->cfg.dst_port, + cfg->dst_port, vni, vni, old_ifindex, true); @@ -686,6 +689,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, struct vxlan_vni_node *vninode) { struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); struct vxlan_rdst *dst = &vxlan->default_dst; /* if per vni remote_ip not present, delete the @@ -697,7 +701,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, __vxlan_fdb_delete(vxlan, all_zeros_mac, (vxlan_addr_any(&vninode->remote_ip) ? dst->remote_ip : vninode->remote_ip), - vxlan->cfg.dst_port, + cfg->dst_port, vninode->vni, vninode->vni, dst->remote_ifindex, true); @@ -801,6 +805,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, u32 vni, union vxlan_addr *group, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); struct vxlan_vni_node *vninode; __be32 v = cpu_to_be32(vni); bool changed = false; @@ -809,7 +814,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, if (vxlan_vnifilter_lookup(vxlan, v)) return vxlan_vni_update(vxlan, vg, v, group, &changed, extack); - err = vxlan_vni_in_use(vxlan->net, vxlan, &vxlan->cfg, v); + err = vxlan_vni_in_use(vxlan->net, vxlan, cfg, v); if (err) { NL_SET_ERR_MSG(extack, "VNI in use"); return err; @@ -1018,6 +1023,7 @@ static int vxlan_vnifilter_process(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct net *net = sock_net(skb->sk); + const struct vxlan_config *cfg; struct tunnel_msg *tmsg; struct vxlan_dev *vxlan; struct net_device *dev; @@ -1042,8 +1048,9 @@ static int vxlan_vnifilter_process(struct sk_buff *skb, struct nlmsghdr *nlh, } vxlan = netdev_priv(dev); + cfg = rtnl_dereference(vxlan->cfg); - if (!(vxlan->cfg.flags & VXLAN_F_VNIFILTER)) + if (!(cfg->flags & VXLAN_F_VNIFILTER)) return -EOPNOTSUPP; nlmsg_for_each_attr_type(attr, VXLAN_VNIFILTER_ENTRY, nlh, diff --git a/include/net/vxlan.h b/include/net/vxlan.h index d323f91af236..7ced743ec881 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -229,6 +229,7 @@ struct vxlan_config { bool no_share; enum ifla_vxlan_df df; struct vxlanhdr reserved_bits; + struct rcu_head rcu; }; enum { @@ -302,7 +303,7 @@ struct vxlan_dev { struct gro_cells gro_cells; unsigned long flags; - struct vxlan_config cfg; + struct vxlan_config __rcu *cfg; struct vxlan_vni_group __rcu *vnigrp; From 7e9e6844befcbbed3b576c16e75d5348639774ff Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:11:01 +0000 Subject: [PATCH 0857/2126] vxlan: remove default_dst and use vxlan_config and lowerdev Now that vxlan->cfg is an RCU-protected pointer, storing default destination attributes (remote_ip, remote_vni, remote_ifindex) in vxlan->default_dst is redundant and creates potential data races for lockless readers. Furthermore, several fields of struct vxlan_rdst (remote_port, offloaded, list, rcu, dst_cache) in default_dst were completely unused. The remaining one, remote_dev, only tracked the lower device, a role now taken by vxlan->lowerdev, so drop it from struct vxlan_rdst. Replace vxlan->default_dst with a 'struct net_device *lowerdev' pointer in struct vxlan_dev to track adjacent upper/lower netdev topology under RTNL, and switch all remaining users over to reading configuration attributes from vxlan->cfg. Also update mlx5e_tc_tun_get_remote_ifindex() to read remote_ifindex from vxlan->cfg under rcu_read_lock(). In vxlan_changelink(), pass lowerdev to vxlan_config_apply() to preserve needed_headroom and needed_tailroom. The mtu is still only reconsidered when the lower device changes, so that an unrelated changelink can not shrink it. cfg->remote_ifindex is now committed unconditionally, where default_dst.remote_ifindex was left untouched when IFLA_VXLAN_LINK was cleared, so a changelink dropping the lower device no longer leaves a stale ifindex behind. For the same reason vxlan_changelink() no longer needs to compute the ifindex that will actually be committed. Setting IFLA_VXLAN_LINK to 0 now also tears down the upper/lower adjacency, which netdev_adjacent_change_commit() used to skip for a NULL new device, resets needed_tailroom, and is rejected if per-VNI multicast groups are configured. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260922181102.3989489-8-edumazet@google.com Signed-off-by: Jakub Kicinski --- .../mellanox/mlx5/core/en/tc_tun_vxlan.c | 11 +- drivers/net/vxlan/vxlan_core.c | 201 ++++++++++-------- drivers/net/vxlan/vxlan_mdb.c | 14 +- drivers/net/vxlan/vxlan_multicast.c | 71 ++++--- drivers/net/vxlan/vxlan_private.h | 15 +- drivers/net/vxlan/vxlan_vnifilter.c | 61 ++++-- include/net/vxlan.h | 3 +- 7 files changed, 213 insertions(+), 163 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c index 7a18a469961d..467fbe43b89e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c @@ -241,9 +241,16 @@ static bool mlx5e_tc_tun_encap_info_equal_vxlan(struct mlx5e_encap_key *a, static int mlx5e_tc_tun_get_remote_ifindex(struct net_device *mirred_dev) { const struct vxlan_dev *vxlan = netdev_priv(mirred_dev); - const struct vxlan_rdst *dst = &vxlan->default_dst; + const struct vxlan_config *cfg; + int ifindex = 0; - return dst->remote_ifindex; + rcu_read_lock(); + cfg = rcu_dereference(vxlan->cfg); + if (cfg) + ifindex = cfg->remote_ifindex; + rcu_read_unlock(); + + return ifindex; } struct mlx5e_tc_tunnel vxlan_tunnel = { diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 783337fc4483..e8027b794e8c 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -804,6 +804,7 @@ static int vxlan_fdb_nh_update(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, u32 nhid, struct netlink_ext_ack *extack) { struct nexthop *old_nh = rtnl_dereference(fdb->nh); + const struct vxlan_config *cfg; struct nexthop *nh; int err = -EINVAL; @@ -832,7 +833,8 @@ static int vxlan_fdb_nh_update(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, } /* check nexthop group family */ - switch (vxlan->default_dst.remote_ip.sa.sa_family) { + cfg = rtnl_dereference(vxlan->cfg); + switch (cfg->remote_ip.sa.sa_family) { case AF_INET: if (!nexthop_has_v4(nh)) { err = -EAFNOSUPPORT; @@ -1249,6 +1251,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], const unsigned char *addr, u16 vid, u16 flags, bool *notified, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg; struct vxlan_dev *vxlan = netdev_priv(dev); /* struct net *net = dev_net(vxlan->dev); */ union vxlan_addr ip; @@ -1276,7 +1279,8 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], return -EINVAL; } - if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family) + cfg = rtnl_dereference(vxlan->cfg); + if (cfg->remote_ip.sa.sa_family != ip.sa.sa_family) return -EAFNOSUPPORT; spin_lock_bh(&vxlan->hash_lock); @@ -2320,7 +2324,14 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, skb->dev = dev; __skb_pull(skb, skb_network_offset(skb)); - if (dst_vxlan->default_dst.remote_ip.sa.sa_family == AF_INET) { + rcu_read_lock(); + dst_cfg = rcu_dereference(dst_vxlan->cfg); + if (unlikely(!(dev->flags & IFF_UP))) { + kfree_skb_reason(skb, SKB_DROP_REASON_DEV_READY); + goto drop; + } + + if (dst_cfg->remote_ip.sa.sa_family == AF_INET) { loopback.sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); loopback.sa.sa_family = AF_INET; #if IS_ENABLED(CONFIG_IPV6) @@ -2330,13 +2341,6 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, #endif } - rcu_read_lock(); - dst_cfg = rcu_dereference(dst_vxlan->cfg); - if (unlikely(!(dev->flags & IFF_UP))) { - kfree_skb_reason(skb, SKB_DROP_REASON_DEV_READY); - goto drop; - } - if ((dst_cfg->flags & VXLAN_F_LEARN) && snoop) vxlan_snoop(dev, dst_cfg, &loopback, eth_hdr(skb)->h_source, 0, vni); @@ -2975,10 +2979,14 @@ static void vxlan_vs_del_dev(struct vxlan_dev *vxlan) static void vxlan_vs_add_dev(struct vxlan_sock *vs, struct vxlan_dev *vxlan, struct vxlan_dev_node *node) { - __be32 vni = vxlan->default_dst.remote_vni; + const struct vxlan_config *cfg; + __be32 vni; ASSERT_RTNL(); + cfg = rtnl_dereference(vxlan->cfg); + vni = cfg->vni; + node->vxlan = vxlan; hlist_add_head_rcu(&node->hlist, vni_head(vs, vni)); } @@ -3300,13 +3308,12 @@ static void vxlan_set_multicast_list(struct net_device *dev) static int vxlan_change_mtu(struct net_device *dev, int new_mtu) { struct vxlan_dev *vxlan = netdev_priv(dev); - struct vxlan_rdst *dst = &vxlan->default_dst; const struct vxlan_config *cfg; struct net_device *lowerdev; cfg = rtnl_dereference(vxlan->cfg); - lowerdev = __dev_get_by_index(vxlan->net, dst->remote_ifindex); + lowerdev = __dev_get_by_index(vxlan->net, cfg->remote_ifindex); /* This check is different than dev->max_mtu, because it looks at * the lowerdev->mtu, rather than the static dev->max_mtu @@ -3635,9 +3642,11 @@ static int vxlan_get_link_ksettings(struct net_device *dev, struct ethtool_link_ksettings *cmd) { struct vxlan_dev *vxlan = netdev_priv(dev); - struct vxlan_rdst *dst = &vxlan->default_dst; - struct net_device *lowerdev = __dev_get_by_index(vxlan->net, - dst->remote_ifindex); + const struct vxlan_config *cfg; + struct net_device *lowerdev; + + cfg = rtnl_dereference(vxlan->cfg); + lowerdev = __dev_get_by_index(vxlan->net, cfg->remote_ifindex); if (!lowerdev) { cmd->base.duplex = DUPLEX_UNKNOWN; @@ -3975,6 +3984,13 @@ static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf, return -EINVAL; } + if ((conf->flags & VXLAN_F_VNIFILTER) && old && + vxlan_vnifilter_has_multicast(old)) { + NL_SET_ERR_MSG(extack, + "Local interface required for multicast remote group"); + return -EINVAL; + } + #if IS_ENABLED(CONFIG_IPV6) if (conf->flags & VXLAN_F_IPV6_LINKLOCAL) { NL_SET_ERR_MSG(extack, @@ -4009,10 +4025,9 @@ static void vxlan_config_apply(struct net_device *dev, struct vxlan_config *new_cfg, struct net_device *lowerdev, struct net *src_net, - bool changelink) + bool changelink, bool lowerdev_changed) { struct vxlan_dev *vxlan = netdev_priv(dev); - struct vxlan_rdst *dst = &vxlan->default_dst; unsigned short needed_headroom = ETH_HLEN; struct vxlan_config *old_cfg; int max_mtu = ETH_MAX_MTU; @@ -4025,18 +4040,13 @@ static void vxlan_config_apply(struct net_device *dev, vxlan_ether_setup(dev); if (new_cfg->mtu) - dev->mtu = new_cfg->mtu; + WRITE_ONCE(dev->mtu, new_cfg->mtu); vxlan->net = src_net; } - dst->remote_vni = new_cfg->vni; - - memcpy(&dst->remote_ip, &new_cfg->remote_ip, sizeof(new_cfg->remote_ip)); - + dev->needed_tailroom = 0; if (lowerdev) { - dst->remote_ifindex = new_cfg->remote_ifindex; - netif_inherit_tso_max(dev, lowerdev); needed_headroom = lowerdev->hard_header_len; @@ -4044,16 +4054,17 @@ static void vxlan_config_apply(struct net_device *dev, dev->needed_tailroom = lowerdev->needed_tailroom; - max_mtu = lowerdev->mtu - vxlan_headroom(flags); + max_mtu = READ_ONCE(lowerdev->mtu) - vxlan_headroom(flags); if (max_mtu < ETH_MIN_MTU) max_mtu = ETH_MIN_MTU; if (!changelink && !new_cfg->mtu) - dev->mtu = max_mtu; + WRITE_ONCE(dev->mtu, max_mtu); } - if (dev->mtu > max_mtu) - dev->mtu = max_mtu; + /* A changelink leaving the lower device alone must not shrink the mtu */ + if (lowerdev_changed && READ_ONCE(dev->mtu) > max_mtu) + WRITE_ONCE(dev->mtu, max_mtu); if (flags & VXLAN_F_COLLECT_METADATA) flags |= VXLAN_F_IPV6; @@ -4083,7 +4094,7 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev, if (!new_cfg) return -ENOMEM; - vxlan_config_apply(dev, new_cfg, lowerdev, src_net, false); + vxlan_config_apply(dev, new_cfg, lowerdev, src_net, false, true); return 0; } @@ -4096,10 +4107,8 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, struct vxlan_dev *vxlan = netdev_priv(dev); struct net_device *remote_dev = NULL; const struct vxlan_config *cfg; - struct vxlan_rdst *dst; int err; - dst = &vxlan->default_dst; err = vxlan_dev_configure(net, dev, conf, extack); if (err) return err; @@ -4114,8 +4123,8 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, return err; } - if (dst->remote_ifindex) { - remote_dev = __dev_get_by_index(net, dst->remote_ifindex); + if (cfg->remote_ifindex) { + remote_dev = __dev_get_by_index(net, cfg->remote_ifindex); if (!remote_dev) { err = -ENODEV; goto unregister; @@ -4125,7 +4134,7 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, if (err) goto unregister; - dst->remote_dev = remote_dev; + vxlan->lowerdev = remote_dev; } err = rtnl_configure_link(dev, NULL, 0, NULL); @@ -4133,16 +4142,18 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, goto unlink; /* create an fdb entry for a valid default destination */ - if (!vxlan_addr_any(&dst->remote_ip)) { + if (!vxlan_addr_any(&cfg->remote_ip)) { + union vxlan_addr rip = cfg->remote_ip; + spin_lock_bh(&vxlan->hash_lock); err = vxlan_fdb_update(vxlan, all_zeros_mac, - &dst->remote_ip, + &rip, NUD_REACHABLE | NUD_PERMANENT, NLM_F_EXCL | NLM_F_CREATE, cfg->dst_port, - dst->remote_vni, - dst->remote_vni, - dst->remote_ifindex, + cfg->vni, + cfg->vni, + cfg->remote_ifindex, NTF_SELF, 0, true, extack); spin_unlock_bh(&vxlan->hash_lock); if (err) @@ -4554,20 +4565,19 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { + bool lowerdev_changed, rem_ip_changed, change_igmp; struct vxlan_dev *vxlan = netdev_priv(dev); - const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); - bool rem_ip_changed, change_igmp; + const struct vxlan_config *cfg; + struct vxlan_config *new_cfg; struct net_device *lowerdev; struct vxlan_config conf; - struct vxlan_config *new_cfg; - struct vxlan_rdst *dst; - u32 new_ifindex; int err; + cfg = rtnl_dereference(vxlan->cfg); + if (!rtnl_dev_link_net_capable(dev, vxlan->net)) return -EPERM; - dst = &vxlan->default_dst; err = vxlan_nl2conf(tb, data, dev, &conf, true, extack); if (err) return err; @@ -4581,26 +4591,23 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], if (!new_cfg) return -ENOMEM; - if (dst->remote_dev == lowerdev) - lowerdev = NULL; - - err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev, - extack); - if (err) { - kfree(new_cfg); - return err; + lowerdev_changed = vxlan->lowerdev != lowerdev; + if (lowerdev_changed) { + err = netdev_adjacent_change_prepare(vxlan->lowerdev, lowerdev, + dev, extack); + if (err) { + kfree(new_cfg); + return err; + } } - /* vxlan_config_apply() only commits remote_ifindex if lowerdev is set */ - new_ifindex = lowerdev ? conf.remote_ifindex : dst->remote_ifindex; - - rem_ip_changed = !vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip); + rem_ip_changed = !vxlan_addr_equal(&conf.remote_ip, &cfg->remote_ip); change_igmp = vxlan->dev->flags & IFF_UP && (rem_ip_changed || - dst->remote_ifindex != new_ifindex); + cfg->remote_ifindex != conf.remote_ifindex); /* handle default dst entry */ - if (rem_ip_changed || dst->remote_ifindex != new_ifindex) { + if (rem_ip_changed || cfg->remote_ifindex != conf.remote_ifindex) { spin_lock_bh(&vxlan->hash_lock); if (!vxlan_addr_any(&conf.remote_ip)) { err = vxlan_fdb_update(vxlan, all_zeros_mac, @@ -4609,23 +4616,24 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], NLM_F_APPEND | NLM_F_CREATE, cfg->dst_port, conf.vni, conf.vni, - new_ifindex, + conf.remote_ifindex, NTF_SELF, 0, true, extack); if (err) { spin_unlock_bh(&vxlan->hash_lock); - netdev_adjacent_change_abort(dst->remote_dev, - lowerdev, dev); + if (lowerdev_changed) + netdev_adjacent_change_abort(vxlan->lowerdev, + lowerdev, dev); kfree(new_cfg); return err; } } - if (!vxlan_addr_any(&dst->remote_ip)) + if (!vxlan_addr_any(&cfg->remote_ip)) __vxlan_fdb_delete(vxlan, all_zeros_mac, - dst->remote_ip, + cfg->remote_ip, cfg->dst_port, - dst->remote_vni, - dst->remote_vni, - dst->remote_ifindex, + cfg->vni, + cfg->vni, + cfg->remote_ifindex, true); spin_unlock_bh(&vxlan->hash_lock); @@ -4633,19 +4641,21 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], * all vnis */ if (cfg->flags & VXLAN_F_VNIFILTER) { - err = vxlan_vnilist_update_group(vxlan, &dst->remote_ip, + err = vxlan_vnilist_update_group(vxlan, &cfg->remote_ip, &conf.remote_ip, - dst->remote_ifindex, - new_ifindex, extack); + cfg->remote_ifindex, + conf.remote_ifindex, + extack); if (err) { vxlan_update_default_fdb_entry(vxlan, conf.vni, &conf.remote_ip, - &dst->remote_ip, - new_ifindex, - dst->remote_ifindex, + &cfg->remote_ip, + conf.remote_ifindex, + cfg->remote_ifindex, NULL); - netdev_adjacent_change_abort(dst->remote_dev, - lowerdev, dev); + if (lowerdev_changed) + netdev_adjacent_change_abort(vxlan->lowerdev, + lowerdev, dev); kfree(new_cfg); return err; } @@ -4653,20 +4663,26 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], } if (change_igmp && - (vxlan_addr_multicast(&dst->remote_ip) || + (vxlan_addr_multicast(&cfg->remote_ip) || (cfg->flags & VXLAN_F_VNIFILTER))) err = vxlan_multicast_leave(vxlan); if (netif_running(dev) && conf.age_interval != cfg->age_interval) mod_timer(&vxlan->age_timer, jiffies); - netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev); - if (lowerdev && lowerdev != dst->remote_dev) - dst->remote_dev = lowerdev; - vxlan_config_apply(dev, new_cfg, lowerdev, vxlan->net, true); + if (lowerdev_changed) { + if (lowerdev) + netdev_adjacent_change_commit(vxlan->lowerdev, lowerdev, + dev); + else + netdev_upper_dev_unlink(vxlan->lowerdev, dev); + vxlan->lowerdev = lowerdev; + } + vxlan_config_apply(dev, new_cfg, lowerdev, vxlan->net, true, + lowerdev_changed); if (change_igmp && - (vxlan_addr_multicast(&dst->remote_ip) || + (vxlan_addr_multicast(&new_cfg->remote_ip) || (new_cfg->flags & VXLAN_F_VNIFILTER))) { int join_err = vxlan_multicast_join(vxlan); @@ -4686,8 +4702,8 @@ static void vxlan_dellink(struct net_device *dev, struct list_head *head) list_del(&vxlan->next); unregister_netdevice_queue(dev, head); - if (vxlan->default_dst.remote_dev) - netdev_upper_dev_unlink(vxlan->default_dst.remote_dev, dev); + if (vxlan->lowerdev) + netdev_upper_dev_unlink(vxlan->lowerdev, dev); } static size_t vxlan_get_size(const struct net_device *dev) @@ -4731,30 +4747,29 @@ static size_t vxlan_get_size(const struct net_device *dev) static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) { const struct vxlan_dev *vxlan = netdev_priv(dev); - const struct vxlan_rdst *dst = &vxlan->default_dst; struct ifla_vxlan_port_range ports; const struct vxlan_config *cfg; cfg = rtnl_dereference(vxlan->cfg); - if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(dst->remote_vni))) + if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(cfg->vni))) goto nla_put_failure; - if (!vxlan_addr_any(&dst->remote_ip)) { - if (dst->remote_ip.sa.sa_family == AF_INET) { + if (!vxlan_addr_any(&cfg->remote_ip)) { + if (cfg->remote_ip.sa.sa_family == AF_INET) { if (nla_put_in_addr(skb, IFLA_VXLAN_GROUP, - dst->remote_ip.sin.sin_addr.s_addr)) + cfg->remote_ip.sin.sin_addr.s_addr)) goto nla_put_failure; #if IS_ENABLED(CONFIG_IPV6) } else { if (nla_put_in6_addr(skb, IFLA_VXLAN_GROUP6, - &dst->remote_ip.sin6.sin6_addr)) + &cfg->remote_ip.sin6.sin6_addr)) goto nla_put_failure; #endif } } - if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) + if (cfg->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, cfg->remote_ifindex)) goto nla_put_failure; if (!vxlan_addr_any(&cfg->saddr)) { @@ -4869,7 +4884,7 @@ static void vxlan_handle_lowerdev_unregister(struct vxlan_net *vn, LIST_HEAD(list_kill); list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) { - struct vxlan_rdst *dst = &vxlan->default_dst; + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); /* In case we created vxlan device with carrier * and we loose the carrier due to module unload @@ -4877,7 +4892,7 @@ static void vxlan_handle_lowerdev_unregister(struct vxlan_net *vn, * cases, it's not necessary and remote_ifindex * is 0 here, so no matches. */ - if (dst->remote_ifindex == dev->ifindex) + if (cfg->remote_ifindex == dev->ifindex) vxlan_dellink(vxlan->dev, &list_kill); } diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c index 4ae6369ed4e3..c1a055199055 100644 --- a/drivers/net/vxlan/vxlan_mdb.c +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -195,7 +195,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, be16_to_cpu(rd->remote_port))) goto nest_err; - if (rd->remote_vni != vxlan->default_dst.remote_vni && + if (rd->remote_vni != cfg->vni && nla_put_u32(skb, MDBA_MDB_EATTR_VNI, be32_to_cpu(rd->remote_vni))) goto nest_err; @@ -620,12 +620,12 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, memset(cfg, 0, sizeof(*cfg)); cfg->vxlan = vxlan; - cfg->group.vni = vxlan->default_dst.remote_vni; + cfg->group.vni = vcfg->vni; INIT_LIST_HEAD(&cfg->src_list); cfg->nlflags = nlmsg_flags; cfg->filter_mode = MCAST_EXCLUDE; cfg->rt_protocol = RTPROT_STATIC; - cfg->remote_vni = vxlan->default_dst.remote_vni; + cfg->remote_vni = vcfg->vni; cfg->remote_port = vcfg->dst_port; if (entry->ifindex != dev->ifindex) { @@ -986,7 +986,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan, if (rd->remote_port && rd->remote_port != cfg->dst_port) nlmsg_size += nla_total_size(sizeof(u16)); /* MDBA_MDB_EATTR_VNI */ - if (rd->remote_vni != vxlan->default_dst.remote_vni) + if (rd->remote_vni != cfg->vni) nlmsg_size += nla_total_size(sizeof(u32)); /* MDBA_MDB_EATTR_IFINDEX */ if (rd->remote_ifindex) @@ -1488,11 +1488,13 @@ static int vxlan_mdb_get_parse(struct net_device *dev, struct nlattr *tb[], { struct br_mdb_entry *entry = nla_data(tb[MDBA_GET_ENTRY]); struct nlattr *mdbe_attrs[MDBE_ATTR_MAX + 1]; + const struct vxlan_config *cfg; struct vxlan_dev *vxlan = netdev_priv(dev); int err; + cfg = rtnl_dereference(vxlan->cfg); memset(group, 0, sizeof(*group)); - group->vni = vxlan->default_dst.remote_vni; + group->vni = cfg->vni; if (!tb[MDBA_GET_ENTRY_ATTRS]) { vxlan_mdb_group_set(group, entry, NULL); @@ -1641,7 +1643,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, * entries are stored with the VNI of the VXLAN device. */ if (!(cfg->flags & VXLAN_F_COLLECT_METADATA)) - src_vni = vxlan->default_dst.remote_vni; + src_vni = cfg->vni; memset(&group, 0, sizeof(group)); group.vni = src_vni; diff --git a/drivers/net/vxlan/vxlan_multicast.c b/drivers/net/vxlan/vxlan_multicast.c index c717540e95ab..a5ef6f66f00d 100644 --- a/drivers/net/vxlan/vxlan_multicast.c +++ b/drivers/net/vxlan/vxlan_multicast.c @@ -14,11 +14,12 @@ /* Update multicast group membership when first VNI on * multicast address is brought up */ -int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, +int vxlan_igmp_join(struct vxlan_dev *vxlan, const union vxlan_addr *rip, int rifindex) { - union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); - int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex); + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); + const union vxlan_addr *ip = (rip ? : &cfg->remote_ip); + int ifindex = (rifindex ? : cfg->remote_ifindex); int ret = -EINVAL; struct sock *sk; @@ -47,11 +48,12 @@ int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, return ret; } -int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, +int vxlan_igmp_leave(struct vxlan_dev *vxlan, const union vxlan_addr *rip, int rifindex) { - union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); - int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex); + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); + const union vxlan_addr *ip = (rip ? : &cfg->remote_ip); + int ifindex = (rifindex ? : cfg->remote_ifindex); int ret = -EINVAL; struct sock *sk; @@ -80,8 +82,8 @@ int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, return ret; } -static bool vxlan_group_used_match(union vxlan_addr *ip, int ifindex, - union vxlan_addr *rip, int rifindex) +static bool vxlan_group_used_match(const union vxlan_addr *ip, int ifindex, + const union vxlan_addr *rip, int rifindex) { if (!vxlan_addr_multicast(rip)) return false; @@ -96,14 +98,16 @@ static bool vxlan_group_used_match(union vxlan_addr *ip, int ifindex, } static bool vxlan_group_used_by_vnifilter(struct vxlan_dev *vxlan, - union vxlan_addr *ip, int ifindex) + const struct vxlan_config *cfg, + const union vxlan_addr *ip, + int ifindex) { struct vxlan_vni_group *vg = rtnl_dereference(vxlan->vnigrp); struct vxlan_vni_node *v, *tmp; if (vxlan_group_used_match(ip, ifindex, - &vxlan->default_dst.remote_ip, - vxlan->default_dst.remote_ifindex)) + &cfg->remote_ip, + cfg->remote_ifindex)) return true; list_for_each_entry_safe(v, tmp, &vg->vni_list, vlist) { @@ -112,7 +116,7 @@ static bool vxlan_group_used_by_vnifilter(struct vxlan_dev *vxlan, if (vxlan_group_used_match(ip, ifindex, &v->remote_ip, - vxlan->default_dst.remote_ifindex)) + cfg->remote_ifindex)) return true; } @@ -121,16 +125,17 @@ static bool vxlan_group_used_by_vnifilter(struct vxlan_dev *vxlan, /* See if multicast group is already in use by other ID */ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, - __be32 vni, union vxlan_addr *rip, int rifindex) + __be32 vni, const union vxlan_addr *rip, int rifindex) { - union vxlan_addr *ip = (rip ? : &dev->default_dst.remote_ip); - int ifindex = (rifindex ? : dev->default_dst.remote_ifindex); + const struct vxlan_config *dev_cfg = rtnl_dereference(dev->cfg); + const union vxlan_addr *ip = (rip ? : &dev_cfg->remote_ip); + int ifindex = (rifindex ? : dev_cfg->remote_ifindex); struct vxlan_dev *vxlan; struct vxlan_sock *sock4; #if IS_ENABLED(CONFIG_IPV6) struct vxlan_sock *sock6; #endif - unsigned short family = dev->default_dst.remote_ip.sa.sa_family; + unsigned short family = dev_cfg->remote_ip.sa.sa_family; sock4 = rtnl_dereference(dev->vn4_sock); @@ -163,12 +168,12 @@ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, cfg = rtnl_dereference(vxlan->cfg); if (cfg->flags & VXLAN_F_VNIFILTER) { - if (!vxlan_group_used_by_vnifilter(vxlan, ip, ifindex)) + if (!vxlan_group_used_by_vnifilter(vxlan, cfg, ip, ifindex)) continue; } else { if (!vxlan_group_used_match(ip, ifindex, - &vxlan->default_dst.remote_ip, - vxlan->default_dst.remote_ifindex)) + &cfg->remote_ip, + cfg->remote_ifindex)) continue; } @@ -178,7 +183,8 @@ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, return false; } -static int vxlan_multicast_join_vnigrp(struct vxlan_dev *vxlan) +static int vxlan_multicast_join_vnigrp(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg) { struct vxlan_vni_group *vg = rtnl_dereference(vxlan->vnigrp); struct vxlan_vni_node *v, *tmp, *vgood = NULL; @@ -189,7 +195,7 @@ static int vxlan_multicast_join_vnigrp(struct vxlan_dev *vxlan) continue; /* skip if address is same as default address */ if (vxlan_addr_equal(&v->remote_ip, - &vxlan->default_dst.remote_ip)) + &cfg->remote_ip)) continue; ret = vxlan_igmp_join(vxlan, &v->remote_ip, 0); if (ret == -EADDRINUSE) @@ -204,7 +210,7 @@ out: if (!vxlan_addr_multicast(&v->remote_ip)) continue; if (vxlan_addr_equal(&v->remote_ip, - &vxlan->default_dst.remote_ip)) + &cfg->remote_ip)) continue; vxlan_igmp_leave(vxlan, &v->remote_ip, 0); if (v == vgood) @@ -215,7 +221,8 @@ out: return ret; } -static int vxlan_multicast_leave_vnigrp(struct vxlan_dev *vxlan) +static int vxlan_multicast_leave_vnigrp(struct vxlan_dev *vxlan, + const struct vxlan_config *cfg) { struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); struct vxlan_vni_group *vg = rtnl_dereference(vxlan->vnigrp); @@ -227,7 +234,7 @@ static int vxlan_multicast_leave_vnigrp(struct vxlan_dev *vxlan) continue; /* skip if address is same as default address */ if (vxlan_addr_equal(&v->remote_ip, - &vxlan->default_dst.remote_ip)) + &cfg->remote_ip)) continue; if (!vxlan_group_used(vn, vxlan, v->vni, &v->remote_ip, 0)) { @@ -247,9 +254,9 @@ int vxlan_multicast_join(struct vxlan_dev *vxlan) const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); int ret = 0; - if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip)) { - ret = vxlan_igmp_join(vxlan, &vxlan->default_dst.remote_ip, - vxlan->default_dst.remote_ifindex); + if (vxlan_addr_multicast(&cfg->remote_ip)) { + ret = vxlan_igmp_join(vxlan, &cfg->remote_ip, + cfg->remote_ifindex); if (ret == -EADDRINUSE) ret = 0; if (ret) @@ -257,7 +264,7 @@ int vxlan_multicast_join(struct vxlan_dev *vxlan) } if (cfg->flags & VXLAN_F_VNIFILTER) - return vxlan_multicast_join_vnigrp(vxlan); + return vxlan_multicast_join_vnigrp(vxlan, cfg); return 0; } @@ -268,10 +275,10 @@ int vxlan_multicast_leave(struct vxlan_dev *vxlan) struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); int ret = 0; - if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip) && + if (vxlan_addr_multicast(&cfg->remote_ip) && !vxlan_group_used(vn, vxlan, 0, NULL, 0)) { - ret = vxlan_igmp_leave(vxlan, &vxlan->default_dst.remote_ip, - vxlan->default_dst.remote_ifindex); + ret = vxlan_igmp_leave(vxlan, &cfg->remote_ip, + cfg->remote_ifindex); if (ret == -EADDRNOTAVAIL) ret = 0; if (ret) @@ -279,7 +286,7 @@ int vxlan_multicast_leave(struct vxlan_dev *vxlan) } if (cfg->flags & VXLAN_F_VNIFILTER) - return vxlan_multicast_leave_vnigrp(vxlan); + return vxlan_multicast_leave_vnigrp(vxlan, cfg); return 0; } diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index a2034ad418f7..f0ee85f83732 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -224,14 +224,15 @@ void vxlan_vs_add_vnigrp(struct vxlan_dev *vxlan, struct vxlan_sock *vs, bool ipv6); void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan); +bool vxlan_vnifilter_has_multicast(const struct vxlan_dev *vxlan); int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, - union vxlan_addr *old_remote_ip, - union vxlan_addr *remote_ip, + const union vxlan_addr *old_remote_ip, + const union vxlan_addr *remote_ip, u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack); int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, - union vxlan_addr *old_remote_ip, - union vxlan_addr *new_remote_ip, + const union vxlan_addr *old_remote_ip, + const union vxlan_addr *new_remote_ip, u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack); @@ -240,10 +241,10 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, int vxlan_multicast_join(struct vxlan_dev *vxlan); int vxlan_multicast_leave(struct vxlan_dev *vxlan); bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, - __be32 vni, union vxlan_addr *rip, int rifindex); -int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, + __be32 vni, const union vxlan_addr *rip, int rifindex); +int vxlan_igmp_join(struct vxlan_dev *vxlan, const union vxlan_addr *rip, int rifindex); -int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, +int vxlan_igmp_leave(struct vxlan_dev *vxlan, const union vxlan_addr *rip, int rifindex); /* vxlan_mdb.c */ diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index d16d5a6c7dad..41095096b698 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -502,9 +502,25 @@ static const struct nla_policy vni_filter_policy[VXLAN_VNIFILTER_MAX + 1] = { [VXLAN_VNIFILTER_ENTRY] = { .type = NLA_NESTED }, }; +bool vxlan_vnifilter_has_multicast(const struct vxlan_dev *vxlan) +{ + struct vxlan_vni_group *vg = rtnl_dereference(vxlan->vnigrp); + struct vxlan_vni_node *v; + + if (!vg) + return false; + + list_for_each_entry(v, &vg->vni_list, vlist) { + if (vxlan_addr_multicast(&v->remote_ip)) + return true; + } + + return false; +} + int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, - union vxlan_addr *old_remote_ip, - union vxlan_addr *remote_ip, + const union vxlan_addr *old_remote_ip, + const union vxlan_addr *remote_ip, u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack) { @@ -518,8 +534,10 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, spin_lock_bh(&vxlan->hash_lock); if (remote_ip && !vxlan_addr_any(remote_ip)) { + union vxlan_addr rip = *remote_ip; + err = vxlan_fdb_update(vxlan, all_zeros_mac, - remote_ip, + &rip, NUD_REACHABLE | NUD_PERMANENT, NLM_F_APPEND | NLM_F_CREATE, cfg->dst_port, @@ -553,8 +571,8 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, struct netlink_ext_ack *extack) { struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); - struct vxlan_rdst *dst = &vxlan->default_dst; - union vxlan_addr *newrip = NULL, *oldrip = NULL; + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); + const union vxlan_addr *newrip = NULL, *oldrip = NULL; union vxlan_addr old_remote_ip; int ret = 0; @@ -566,15 +584,15 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, if (group && !vxlan_addr_any(group)) { newrip = group; } else { - if (!vxlan_addr_any(&dst->remote_ip)) - newrip = &dst->remote_ip; + if (!vxlan_addr_any(&cfg->remote_ip)) + newrip = &cfg->remote_ip; } if (!create) { if (!vxlan_addr_any(&old_remote_ip)) oldrip = &old_remote_ip; - else if (!vxlan_addr_any(&dst->remote_ip)) - oldrip = &dst->remote_ip; + else if (!vxlan_addr_any(&cfg->remote_ip)) + oldrip = &cfg->remote_ip; } if (!newrip && !oldrip) @@ -585,8 +603,8 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, ret = vxlan_update_default_fdb_entry(vxlan, vninode->vni, oldrip, newrip, - dst->remote_ifindex, - dst->remote_ifindex, + cfg->remote_ifindex, + cfg->remote_ifindex, extack); if (ret) goto out; @@ -601,7 +619,7 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, if (vxlan_addr_multicast(&old_remote_ip) && !vxlan_group_used(vn, vxlan, vninode->vni, &old_remote_ip, - vxlan->default_dst.remote_ifindex)) { + cfg->remote_ifindex)) { ret = vxlan_igmp_leave(vxlan, &old_remote_ip, 0); if (ret == -EADDRNOTAVAIL) @@ -627,12 +645,12 @@ out: } int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, - union vxlan_addr *old_remote_ip, - union vxlan_addr *new_remote_ip, + const union vxlan_addr *old_remote_ip, + const union vxlan_addr *new_remote_ip, u32 old_ifindex, u32 new_ifindex, struct netlink_ext_ack *extack) { - union vxlan_addr *oldrip, *newrip; + const union vxlan_addr *oldrip, *newrip; struct list_head *headp, *hpos; struct vxlan_vni_group *vg; struct vxlan_vni_node *vent; @@ -690,20 +708,19 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, { struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg); - struct vxlan_rdst *dst = &vxlan->default_dst; /* if per vni remote_ip not present, delete the * default dst remote_ip previously added for this vni */ if (!vxlan_addr_any(&vninode->remote_ip) || - !vxlan_addr_any(&dst->remote_ip)) { + !vxlan_addr_any(&cfg->remote_ip)) { spin_lock_bh(&vxlan->hash_lock); __vxlan_fdb_delete(vxlan, all_zeros_mac, (vxlan_addr_any(&vninode->remote_ip) ? - dst->remote_ip : vninode->remote_ip), + cfg->remote_ip : vninode->remote_ip), cfg->dst_port, vninode->vni, vninode->vni, - dst->remote_ifindex, + cfg->remote_ifindex, true); spin_unlock_bh(&vxlan->hash_lock); } @@ -712,7 +729,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, if (vxlan_addr_multicast(&vninode->remote_ip) && !vxlan_group_used(vn, vxlan, vninode->vni, &vninode->remote_ip, - dst->remote_ifindex)) { + cfg->remote_ifindex)) { vxlan_igmp_leave(vxlan, &vninode->remote_ip, 0); } } @@ -927,6 +944,7 @@ static int vxlan_process_vni_filter(struct vxlan_dev *vxlan, int cmd, struct netlink_ext_ack *extack) { struct nlattr *vattrs[VXLAN_VNIFILTER_ENTRY_MAX + 1]; + const struct vxlan_config *cfg; u32 vni_start = 0, vni_end = 0; union vxlan_addr group; int err; @@ -964,7 +982,8 @@ static int vxlan_process_vni_filter(struct vxlan_dev *vxlan, memset(&group, 0, sizeof(group)); } - if (vxlan_addr_multicast(&group) && !vxlan->default_dst.remote_ifindex) { + cfg = rtnl_dereference(vxlan->cfg); + if (vxlan_addr_multicast(&group) && !cfg->remote_ifindex) { NL_SET_ERR_MSG(extack, "Local interface required for multicast remote group"); diff --git a/include/net/vxlan.h b/include/net/vxlan.h index 7ced743ec881..c3c9f2ccc3d1 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -204,7 +204,6 @@ struct vxlan_rdst { u8 offloaded:1; __be32 remote_vni; u32 remote_ifindex; - struct net_device *remote_dev; struct list_head list; struct rcu_head rcu; struct dst_cache dst_cache; @@ -295,7 +294,7 @@ struct vxlan_dev { #endif struct net_device *dev; struct net *net; /* netns for packet i/o */ - struct vxlan_rdst default_dst; /* default destination */ + struct net_device *lowerdev; struct timer_list age_timer; spinlock_t hash_lock; From 4b74deb12948aa4057da966e34fe23db3c9877af Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 22 Sep 2026 18:11:02 +0000 Subject: [PATCH 0858/2126] vxlan: no longer rely on RTNL in vxlan_fill_info() Now that vxlan->cfg is RCU-protected, we can update vxlan_fill_info() to run under RCU read lock instead of relying on RTNL. This completes the transition to RTNL-less link info dumping for VXLAN. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260922181102.3989489-9-edumazet@google.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index e8027b794e8c..27b0b6567d52 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4750,7 +4750,8 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) struct ifla_vxlan_port_range ports; const struct vxlan_config *cfg; - cfg = rtnl_dereference(vxlan->cfg); + rcu_read_lock(); + cfg = rcu_dereference(vxlan->cfg); if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(cfg->vni))) goto nla_put_failure; @@ -4849,9 +4850,11 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) &cfg->reserved_bits)) goto nla_put_failure; + rcu_read_unlock(); return 0; nla_put_failure: + rcu_read_unlock(); return -EMSGSIZE; } From 5277d2c55286c2677bdc15d7f0577f0e772b5866 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 22 Sep 2026 15:25:24 -0700 Subject: [PATCH 0859/2126] net: systemport: Fix missing phy-handle parsing for non-fixed PHYs In bcm_sysport_probe(), priv->phy_dn is only initialized if the device tree node has a fixed-link configuration (of_phy_is_fixed_link). When connecting to a discrete MDIO-attached PHY referenced via 'phy-handle', priv->phy_dn remains NULL. This causes of_phy_connect() during bcm_sysport_open() to fail with -ENODEV since of_phy_find_device(NULL) returns NULL. Fix this by parsing 'phy-handle' via of_parse_phandle() and falling back to of_phy_is_fixed_link(). Ensure proper of_node_get() and of_node_put() refcounting lifecycle on both error unwinding and module remove paths. Signed-off-by: Florian Fainelli Reviewed-by: Simon Horman Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260922222525.3992167-2-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bcmsysport.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 4f0ec136b606..8a566b98f486 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2522,17 +2522,19 @@ static int bcm_sysport_probe(struct platform_device *pdev) if (ret) priv->phy_interface = PHY_INTERFACE_MODE_GMII; + priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0); + /* In the case of a fixed PHY, the DT node associated * to the PHY is the Ethernet MAC DT node. */ - if (of_phy_is_fixed_link(dn)) { + if (!priv->phy_dn && of_phy_is_fixed_link(dn)) { ret = of_phy_register_fixed_link(dn); if (ret) { dev_err(&pdev->dev, "failed to register fixed PHY\n"); goto err_free_netdev; } - priv->phy_dn = dn; + priv->phy_dn = of_node_get(dn); } /* Initialize netdevice members */ @@ -2617,6 +2619,7 @@ err_deregister_notifier: err_deregister_fixed_link: if (of_phy_is_fixed_link(dn)) of_phy_deregister_fixed_link(dn); + of_node_put(priv->phy_dn); err_free_netdev: free_netdev(dev); return ret; @@ -2635,6 +2638,7 @@ static void bcm_sysport_remove(struct platform_device *pdev) unregister_netdev(dev); if (of_phy_is_fixed_link(dn)) of_phy_deregister_fixed_link(dn); + of_node_put(priv->phy_dn); free_netdev(dev); dev_set_drvdata(&pdev->dev, NULL); } From 78cccb00ec16bdd9922efddbb0e4c63017b05503 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 22 Sep 2026 15:25:25 -0700 Subject: [PATCH 0860/2126] net: bcmasp: remove duplicate MDA filter register definitions Remove the redundant duplicate definitions of ASP_RX_FILTER_MDA_CFG, ASP_RX_FILTER_MDA_PAT_H, ASP_RX_FILTER_MDA_PAT_L, ASP_RX_FILTER_MDA_MSK_H, and ASP_RX_FILTER_MDA_MSK_L in bcmasp.h. Signed-off-by: Florian Fainelli Reviewed-by: Simon Horman Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260922222525.3992167-3-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h b/drivers/net/ethernet/broadcom/asp2/bcmasp.h index 8c8ffaeadc79..b08a7ddc4c64 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h @@ -80,11 +80,6 @@ #define ASP_RX_FILTER_MDA_PAT_L(sel) (((sel) * 0x14) + 0x108) #define ASP_RX_FILTER_MDA_MSK_H(sel) (((sel) * 0x14) + 0x10c) #define ASP_RX_FILTER_MDA_MSK_L(sel) (((sel) * 0x14) + 0x110) -#define ASP_RX_FILTER_MDA_CFG(sel) (((sel) * 0x14) + 0x100) -#define ASP_RX_FILTER_MDA_PAT_H(sel) (((sel) * 0x14) + 0x104) -#define ASP_RX_FILTER_MDA_PAT_L(sel) (((sel) * 0x14) + 0x108) -#define ASP_RX_FILTER_MDA_MSK_H(sel) (((sel) * 0x14) + 0x10c) -#define ASP_RX_FILTER_MDA_MSK_L(sel) (((sel) * 0x14) + 0x110) #define ASP_RX_FILTER_NET_CFG(sel) (((sel) * 0xa04) + 0x400) #define ASP_RX_FILTER_NET_CFG_CH(sel) ((sel) << 0) #define ASP_RX_FILTER_NET_CFG_EN BIT(9) From 96c201a2f43ea49a65f32929494ac68f2b08b9a3 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 22 Sep 2026 16:24:33 -0700 Subject: [PATCH 0861/2126] net: systemport: Fix NULL pointer dereference in bcm_sysport_fini_rx_ring() If allocation of priv->rx_cbs fails during bcm_sysport_init_rx_ring(), error unwinding in bcm_sysport_open() calls bcm_sysport_fini_rx_ring(). Without checking if priv->rx_cbs is non-NULL, bcm_sysport_fini_rx_ring() dereferences priv->rx_cbs, resulting in a NULL pointer dereference. Add a check for !priv->rx_cbs at the beginning of bcm_sysport_fini_rx_ring(), matching bcm_sysport_fini_tx_ring(). Cc: stable+noautosel@kernel.org # unlikely driver error path Reviewed-by: Nicolai Buchwitz Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20260922232440.598918-4-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bcmsysport.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 8a566b98f486..4d8c7d2f24a4 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -1717,6 +1717,9 @@ static void bcm_sysport_fini_rx_ring(struct bcm_sysport_priv *priv) if (!(reg & RDMA_DISABLED)) netdev_warn(priv->netdev, "RDMA not stopped!\n"); + if (!priv->rx_cbs) + return; + for (i = 0; i < priv->num_rx_bds; i++) { cb = &priv->rx_cbs[i]; if (dma_unmap_addr(cb, dma_addr)) From 1b94a9b462d869bbb466767caa28b197953f2a37 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 22 Sep 2026 16:24:34 -0700 Subject: [PATCH 0862/2126] net: systemport: Fix Wake-on-LAN RXCHK filter enable loop In bcm_sysport_suspend_to_wol(), the loop enabling programmed RXCHK filters in RXCHK_CONTROL used an auxiliary counter 'i' instead of the actual set filter index 'index'. When non-contiguous filters were configured (for example, if filter 0 was deleted and filter 1 remained), the code would enable bit (RXCHK_BRCM_TAG_MATCH_SHIFT + 0) corresponding to filter 0 rather than filter 1, causing Wake-on-LAN filter matching to fail. Fix this by using the filter 'index' to set the appropriate match bit in RXCHK_CONTROL. Cc: stable+noautosel@kernel.org # never worked Reviewed-by: Nicolai Buchwitz Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20260922232440.598918-5-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bcmsysport.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 4d8c7d2f24a4..03d381d4e9a8 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2650,7 +2650,7 @@ static int bcm_sysport_suspend_to_wol(struct bcm_sysport_priv *priv) { struct net_device *ndev = priv->netdev; unsigned int timeout = 1000; - unsigned int index, i = 0; + unsigned int index; u32 reg; reg = umac_readl(priv, UMAC_MPD_CTRL); @@ -2680,10 +2680,8 @@ static int bcm_sysport_suspend_to_wol(struct bcm_sysport_priv *priv) reg = rxchk_readl(priv, RXCHK_CONTROL); reg &= ~(RXCHK_BRCM_TAG_MATCH_MASK << RXCHK_BRCM_TAG_MATCH_SHIFT); - for_each_set_bit(index, priv->filters, RXCHK_BRCM_TAG_MAX) { - reg |= BIT(RXCHK_BRCM_TAG_MATCH_SHIFT + i); - i++; - } + for_each_set_bit(index, priv->filters, RXCHK_BRCM_TAG_MAX) + reg |= BIT(RXCHK_BRCM_TAG_MATCH_SHIFT + index); reg |= RXCHK_EN | RXCHK_BRCM_TAG_EN; rxchk_writel(priv, reg, RXCHK_CONTROL); } From 1c6214e6daf604b16f9bf1fd9d48124ef702313c Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 22 Sep 2026 16:24:38 -0700 Subject: [PATCH 0863/2126] net: systemport: Fix inverted error messages in bcm_sysport_stop() In bcm_sysport_stop(), the error messages printed when tdma_enable_set() and rdma_enable_set() time out were inverted: the failure of tdma_enable_set() logged 'timeout disabling RDMA' and the failure of rdma_enable_set() logged 'timeout disabling TDMA'. Swap the error messages so they correctly describe the failing engine. Reviewed-by: Nicolai Buchwitz Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20260922232440.598918-9-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bcmsysport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 03d381d4e9a8..8313da5f8a63 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2086,7 +2086,7 @@ static int bcm_sysport_stop(struct net_device *dev) ret = tdma_enable_set(priv, 0); if (ret) { - netdev_err(dev, "timeout disabling RDMA\n"); + netdev_err(dev, "timeout disabling TDMA\n"); return ret; } @@ -2095,7 +2095,7 @@ static int bcm_sysport_stop(struct net_device *dev) ret = rdma_enable_set(priv, 0); if (ret) { - netdev_err(dev, "timeout disabling TDMA\n"); + netdev_err(dev, "timeout disabling RDMA\n"); return ret; } From cfda5de640534855cc0a602f0eeb91a7e0c75764 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:18 +0300 Subject: [PATCH 0864/2126] net/mlx5e: Assign a random MAC to any netdev with a zero MAC address mlx5e_set_netdev_dev_addr() falls back to a random MAC only when the queried address is all-zeros AND the device is not a vport group manager. A vport group manager that comes up with a zero MAC is therefore left with an invalid all-zero address. The vport_group_manager exception is unnecessary: a zero MAC is always invalid, regardless of device type. Drop the condition and assign a random MAC whenever the queried address is zero, so every netdev comes up with a valid address. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-2-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 4c6060d54fbe..f90b5a34e097 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -5430,8 +5430,7 @@ static void mlx5e_set_netdev_dev_addr(struct net_device *netdev) u8 addr[ETH_ALEN]; mlx5_query_mac_address(priv->mdev, addr); - if (is_zero_ether_addr(addr) && - !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) { + if (is_zero_ether_addr(addr)) { eth_hw_addr_random(netdev); mlx5_core_info(priv->mdev, "Assigned random MAC address %pM\n", netdev->dev_addr); return; From 11dac22ca06323148a387f71aef2a9885d5efa10 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:19 +0300 Subject: [PATCH 0865/2126] net/mlx5: E-switch, do not leave an unpaired devcom registered If the initial PAIR event fails, the eswitch offloads devcom component stays registered until eswitch teardown even though no peer was ever paired. devcom is optional, so this is not a functional bug - but a registered component that reflects no actual pairing is incorrect state to keep around. Release it when the initial pairing fails. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-3-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index eb74b6260168..e7d92d9bde16 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -3548,6 +3548,7 @@ err_out: void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw, const struct mlx5_devcom_match_attr *attr) { + int err; int i; for (i = 0; i < MLX5_MAX_PORTS; i++) @@ -3572,10 +3573,12 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw, if (!esw->devcom) return; - mlx5_devcom_send_event(esw->devcom, - ESW_OFFLOADS_DEVCOM_PAIR, - ESW_OFFLOADS_DEVCOM_UNPAIR, - esw); + err = mlx5_devcom_send_event(esw->devcom, + ESW_OFFLOADS_DEVCOM_PAIR, + ESW_OFFLOADS_DEVCOM_UNPAIR, + esw); + if (err) + mlx5_esw_offloads_devcom_cleanup(esw); } void mlx5_esw_offloads_devcom_cleanup(struct mlx5_eswitch *esw) From d9f3227f673b7d5aa0bdb822a2cc6be17e10f3e0 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:20 +0300 Subject: [PATCH 0866/2126] net/mlx5: LAG, allocate v2p_map dynamically v2p_map was a fixed array sized MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS embedded in struct mlx5_lag. Turn it into a pointer allocated in mlx5_lag_dev_alloc() once ldev->ports is known, sized by the actual port count, and free it in mlx5_ldev_free(). The ldev->ports / ldev->buckets initialization is moved up so the allocation can use it. The matching scratch buffer in mlx5_modify_lag() is converted from a MLX5_MAX_PORTS-sized stack array to a kcalloc() of the same extent, with the trailing teardown reworked through a goto so the buffer is freed on every path. The memcpy() that previously relied on sizeof() of the stack array now uses the explicit ldev->ports * MLX5_LAG_MAX_HASH_BUCKETS span. No functional change; this removes v2p_map's dependency on MLX5_MAX_PORTS. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-4-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 38 ++++++++++++++----- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index dd14cdc378de..6321f985c071 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -308,6 +308,7 @@ static void mlx5_ldev_free(struct kref *ref) cancel_work_sync(&ldev->speed_update_work); destroy_workqueue(ldev->wq); mutex_destroy(&ldev->lock); + kfree(ldev->v2p_map); kfree(ldev); } @@ -330,11 +331,16 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev) if (!ldev) return NULL; + ldev->ports = MLX5_CAP_GEN(dev, num_lag_ports); + ldev->buckets = 1; + ldev->v2p_map = kcalloc(ldev->ports * MLX5_LAG_MAX_HASH_BUCKETS, + sizeof(*ldev->v2p_map), GFP_KERNEL); + if (!ldev->v2p_map) + goto err_v2p_map; + ldev->wq = create_singlethread_workqueue("mlx5_lag"); - if (!ldev->wq) { - kfree(ldev); - return NULL; - } + if (!ldev->wq) + goto err_wq; kref_init(&ldev->ref); mutex_init(&ldev->lock); @@ -358,10 +364,13 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev) mlx5_core_err(dev, "Failed to init multipath lag err=%d\n", err); - ldev->ports = MLX5_CAP_GEN(dev, num_lag_ports); - ldev->buckets = 1; - return ldev; + +err_wq: + kfree(ldev->v2p_map); +err_v2p_map: + kfree(ldev); + return NULL; } int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev, @@ -853,8 +862,8 @@ void mlx5_modify_lag(struct mlx5_lag *ldev, struct lag_tracker *tracker) { int first_idx = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P1); - u8 ports[MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS] = {}; struct mlx5_core_dev *dev0; + u8 *ports; int idx; int err; int i; @@ -864,6 +873,12 @@ void mlx5_modify_lag(struct mlx5_lag *ldev, return; dev0 = mlx5_lag_pf(ldev, first_idx)->dev; + + ports = kcalloc(ldev->ports * MLX5_LAG_MAX_HASH_BUCKETS, + sizeof(*ports), GFP_KERNEL); + if (!ports) + return; + mlx5_infer_tx_affinity_mapping(tracker, ldev, ldev->buckets, ports); mlx5_ldev_for_each(i, 0, ldev) { @@ -876,9 +891,10 @@ void mlx5_modify_lag(struct mlx5_lag *ldev, mlx5_core_err(dev0, "Failed to modify LAG (%d)\n", err); - return; + goto out; } - memcpy(ldev->v2p_map, ports, sizeof(ports)); + memcpy(ldev->v2p_map, ports, + ldev->ports * MLX5_LAG_MAX_HASH_BUCKETS); mlx5_lag_print_mapping(dev0, ldev, tracker, ldev->mode_flags); @@ -899,6 +915,8 @@ void mlx5_modify_lag(struct mlx5_lag *ldev, ndev); dev_put(ndev); } +out: + kfree(ports); } static int mlx5_lag_set_port_sel_mode(struct mlx5_lag *ldev, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h index e9f0ef83ce1d..8552792b9035 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h @@ -85,7 +85,7 @@ struct mlx5_lag { u8 ports; u8 buckets; int mode_changes_in_progress; - u8 v2p_map[MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS]; + u8 *v2p_map; struct kref ref; struct xarray pfs; struct lag_tracker tracker; From 4138820bdddaf61c260952c49da692c9456f3d37 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:21 +0300 Subject: [PATCH 0867/2126] net/mlx5: LAG, allocate port-indexed scratch buffers dynamically mlx5_lag_print_mapping(), mlx5_infer_tx_affinity_mapping() and lag_active_port_bits() each used a MLX5_MAX_PORTS-sized stack buffer to hold per-port working state. Allocate these buffers with kcalloc(ldev->ports, ...) instead so they track the actual port count and no longer depend on MLX5_MAX_PORTS. lag_active_port_bits() can now fail on allocation, so it returns int and propagates -ENOMEM; a non-negative return is the active-port bitmask as before. Its two callers, mlx5_cmd_create_lag() and _mlx5_modify_lag(), check for a negative return and bail out, then narrow the value back into the u8 they hand to the device. This removes these buffers' dependency on MLX5_MAX_PORTS. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-5-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 100 ++++++++++++++---- 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index 6321f985c071..a7c316121c26 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -63,19 +63,25 @@ static int get_port_sel_mode(enum mlx5_lag_mode mode, unsigned long flags) return MLX5_LAG_PORT_SELECT_MODE_QUEUE_AFFINITY; } -static u8 lag_active_port_bits(struct mlx5_lag *ldev, - struct lag_tracker *tracker) +static int lag_active_port_bits(struct mlx5_lag *ldev, + struct lag_tracker *tracker) { - u8 enabled_ports[MLX5_MAX_PORTS] = {}; u8 active_port = 0; + u8 *enabled_ports; int num_enabled; int idx; + enabled_ports = kcalloc(ldev->ports, sizeof(*enabled_ports), + GFP_KERNEL); + if (!enabled_ports) + return -ENOMEM; + mlx5_infer_tx_enabled(tracker, ldev, enabled_ports, &num_enabled); for (idx = 0; idx < num_enabled; idx++) active_port |= BIT_MASK(enabled_ports[idx]); + kfree(enabled_ports); return active_port; } @@ -105,13 +111,21 @@ static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, struct mlx5_lag *ldev, MLX5_SET(lagc, lag_ctx, tx_remap_affinity_1, ports[idx0]); MLX5_SET(lagc, lag_ctx, tx_remap_affinity_2, ports[idx1]); break; - case MLX5_LAG_PORT_SELECT_MODE_PORT_SELECT_FT: + case MLX5_LAG_PORT_SELECT_MODE_PORT_SELECT_FT: { + u8 active_port; + int ret; + if (!MLX5_CAP_PORT_SELECTION(dev, port_select_flow_table_bypass)) break; - MLX5_SET(lagc, lag_ctx, active_port, - lag_active_port_bits(ldev, tracker)); + ret = lag_active_port_bits(ldev, tracker); + if (ret < 0) + return ret; + + active_port = ret; + MLX5_SET(lagc, lag_ctx, active_port, active_port); break; + } default: break; } @@ -240,22 +254,31 @@ static void mlx5_lag_print_mapping(struct mlx5_core_dev *dev, struct lag_tracker *tracker, unsigned long flags) { - char buf[MLX5_MAX_PORTS * 10 + 1] = {}; - u8 enabled_ports[MLX5_MAX_PORTS] = {}; + u8 *enabled_ports = NULL; int written = 0; int num_enabled; + char *buf; int idx; int err; int i; int j; + buf = kcalloc(ldev->ports * 10 + 1, sizeof(*buf), GFP_KERNEL); + if (!buf) + return; + if (test_bit(MLX5_LAG_MODE_FLAG_HASH_BASED, &flags)) { + enabled_ports = kcalloc(ldev->ports, sizeof(*enabled_ports), + GFP_KERNEL); + if (!enabled_ports) + goto free_buf; + mlx5_infer_tx_enabled(tracker, ldev, enabled_ports, &num_enabled); for (i = 0; i < num_enabled; i++) { err = scnprintf(buf + written, 4, "%d, ", enabled_ports[i] + 1); if (err != 3) - return; + goto free_enabled; written += err; } buf[written - 2] = 0; @@ -267,12 +290,17 @@ static void mlx5_lag_print_mapping(struct mlx5_core_dev *dev, err = scnprintf(buf + written, 10, " port %d:%d", i + 1, ldev->v2p_map[idx]); if (err != 9) - return; + goto free_enabled; written += err; } } mlx5_core_info(dev, "lag map:%s\n", buf); } + +free_enabled: + kfree(enabled_ports); +free_buf: + kfree(buf); } static int mlx5_lag_netdev_event(struct notifier_block *this, @@ -668,20 +696,28 @@ static bool __mlx5_lag_is_sd_active(struct mlx5_lag *ldev, * If there are ports that are disabled fill the relevant slots * with mapping that points to active ports. */ -static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker, - struct mlx5_lag *ldev, - u8 buckets, - u8 *ports) +static int mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker, + struct mlx5_lag *ldev, + u8 buckets, + u8 *ports) { - int disabled[MLX5_MAX_PORTS] = {}; - int enabled[MLX5_MAX_PORTS] = {}; int disabled_ports_num = 0; int enabled_ports_num = 0; + int *disabled; + int *enabled; + int err = 0; int idx; u32 rand; int i; int j; + enabled = kcalloc(ldev->ports, sizeof(*enabled), GFP_KERNEL); + disabled = kcalloc(ldev->ports, sizeof(*disabled), GFP_KERNEL); + if (!enabled || !disabled) { + err = -ENOMEM; + goto out; + } + mlx5_ldev_for_each(i, 0, ldev) { if (tracker->netdev_state[i].tx_enabled && tracker->netdev_state[i].link_up) @@ -704,7 +740,7 @@ static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker, /* If all ports are disabled/enabled keep native mapping */ if (enabled_ports_num == ldev->ports || disabled_ports_num == ldev->ports) - return; + goto out; /* Go over the disabled ports and for each assign a random active port */ for (i = 0; i < disabled_ports_num; i++) { @@ -717,6 +753,11 @@ static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker, mlx5_lag_xa_to_dev_idx(ldev, rand_xa_idx) + 1; } } + +out: + kfree(enabled); + kfree(disabled); + return err; } static bool mlx5_lag_has_drop_rule(struct mlx5_lag *ldev) @@ -816,7 +857,10 @@ static int _mlx5_modify_lag(struct mlx5_lag *ldev, !MLX5_CAP_PORT_SELECTION(dev0, port_select_flow_table_bypass)) return ret; - active_ports = lag_active_port_bits(ldev, tracker); + ret = lag_active_port_bits(ldev, tracker); + if (ret < 0) + return ret; + active_ports = ret; return mlx5_cmd_modify_active_port(dev0, active_ports); } @@ -879,7 +923,14 @@ void mlx5_modify_lag(struct mlx5_lag *ldev, if (!ports) return; - mlx5_infer_tx_affinity_mapping(tracker, ldev, ldev->buckets, ports); + err = mlx5_infer_tx_affinity_mapping(tracker, ldev, ldev->buckets, + ports); + if (err) { + mlx5_core_err(dev0, + "mlx5_infer_tx_affinity_mapping failed, err = %d\n", + err); + goto out; + } mlx5_ldev_for_each(i, 0, ldev) { for (j = 0; j < ldev->buckets; j++) { @@ -1045,7 +1096,16 @@ int mlx5_activate_lag(struct mlx5_lag *ldev, return err; if (mode != MLX5_LAG_MODE_MPESW) { - mlx5_infer_tx_affinity_mapping(tracker, ldev, ldev->buckets, ldev->v2p_map); + err = mlx5_infer_tx_affinity_mapping(tracker, ldev, + ldev->buckets, + ldev->v2p_map); + if (err) { + mlx5_core_err(dev0, + "mlx5_infer_tx_affinity_mapping failed, err = %d\n", + err); + return err; + } + if (test_bit(MLX5_LAG_MODE_FLAG_HASH_BASED, &flags)) { err = mlx5_lag_port_sel_create(ldev, tracker->hash_type, ldev->v2p_map); From fbc4f422c5b86cffed759890f31b335adae9a27e Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:22 +0300 Subject: [PATCH 0868/2126] net/mlx5: LAG, drop per-port scratch array in drop-rule setup mlx5_lag_drop_rule_setup() walks the per-port tracker state, but does so through a per-port scratch array, mlx5_lag_drop_rule_setup() collects the disabled ports to create a per-port drop rule. Walk the tracker state inline removing its MLX5_MAX_PORTS dependency. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-6-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index a7c316121c26..78505e59bf9d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -792,11 +792,8 @@ static void mlx5_lag_drop_rule_cleanup(struct mlx5_lag *ldev) static void mlx5_lag_drop_rule_setup(struct mlx5_lag *ldev, struct lag_tracker *tracker) { - u8 disabled_ports[MLX5_MAX_PORTS] = {}; struct mlx5_core_dev *dev; struct lag_func *pf; - int disabled_index; - int num_disabled; int err; int i; @@ -808,11 +805,11 @@ static void mlx5_lag_drop_rule_setup(struct mlx5_lag *ldev, if (!ldev->tracker.has_inactive) return; - mlx5_infer_tx_disabled(tracker, ldev, disabled_ports, &num_disabled); - - for (i = 0; i < num_disabled; i++) { - disabled_index = disabled_ports[i]; - pf = mlx5_lag_pf(ldev, disabled_index); + mlx5_ldev_for_each(i, 0, ldev) { + if (tracker->netdev_state[i].tx_enabled && + tracker->netdev_state[i].link_up) + continue; + pf = mlx5_lag_pf(ldev, i); dev = pf->dev; err = mlx5_esw_acl_ingress_vport_drop_rule_create(dev->priv.eswitch, MLX5_VPORT_UPLINK); @@ -820,7 +817,8 @@ static void mlx5_lag_drop_rule_setup(struct mlx5_lag *ldev, pf->has_drop = true; else mlx5_core_err(dev, - "Failed to create lag drop rule, error: %d", err); + "Failed to create lag drop rule, error: %d", + err); } } From 6c244dd5ba6b3d7ee55a4e85d81ad27083de3d6b Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:23 +0300 Subject: [PATCH 0869/2126] net/mlx5: LAG, size debugfs buffers by port count debugfs mapping_show() uses constant MLX5_MAX_PORTS to size ports array. Instead, allocate dynamically using actual number of ports. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-7-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c index e9b8d79d2d21..44296789d656 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c @@ -101,14 +101,18 @@ unlock: static int mapping_show(struct seq_file *file, void *priv) { struct mlx5_core_dev *dev = file->private; - u8 ports[MLX5_MAX_PORTS] = {}; struct mlx5_lag *ldev; bool hash = false; bool lag_active; int i, idx = 0; int num_ports; + u8 *ports; ldev = mlx5_lag_dev(dev); + ports = kcalloc(ldev->ports, sizeof(*ports), GFP_KERNEL); + if (!ports) + return -ENOMEM; + mutex_lock(&ldev->lock); lag_active = __mlx5_lag_is_active(ldev); if (lag_active) { @@ -123,8 +127,10 @@ static int mapping_show(struct seq_file *file, void *priv) } } mutex_unlock(&ldev->lock); - if (!lag_active) + if (!lag_active) { + kfree(ports); return -EINVAL; + } for (i = 0; i < num_ports; i++) { if (hash) @@ -133,6 +139,7 @@ static int mapping_show(struct seq_file *file, void *priv) seq_printf(file, "%d:%d\n", i + 1, ports[i]); } + kfree(ports); return 0; } From 675956237b3818c3a9deeabf7be678cf31699e72 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:24 +0300 Subject: [PATCH 0870/2126] net/mlx5e: TC, anchor peer-flow reverse index on the duplicated flow A TC eswitch flow offloaded to a shared FDB is duplicated onto every peer eswitch. Besides the forward list of duplicates on the origin flow (mlx5e_tc_flow.peer_flows), the eswitch keeps a reverse index, esw->offloads.peer_flows[], an array of per-peer list heads keyed by the peer's LAG sequence number, used to tear down a peer's duplicates when it is removed. That reverse index was anchored on the origin: since one origin can have a duplicate on every peer, the origin carried per-peer storage sized to the max port count - a peer[MLX5_MAX_PORTS] array of list nodes plus a peer_used bitmap - and each duplicate stored its peer_index. Anchor it on the duplicate instead, which belongs to a single peer. Give each flow one list node, mlx5e_tc_flow.peer, and place the duplicate - not the origin - on its peer's list through it; add a peer_orig back-ref so del can reach the origin from the duplicate. One node then replaces the origin's per-peer array, and del unlinks the duplicate directly, so peer[], peer_used and peer_index are dropped. The per-peer list heads remain the fixed esw->offloads.peer_flows[] array keyed by the LAG sequence number - that array is replaced in the next patch. No functional change. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-8-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlx5/core/en/tc_priv.h | 14 ++--- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 59 ++++++++----------- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h index 7bfe7cdc5770..1ceebab4ce08 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h @@ -97,18 +97,14 @@ struct mlx5e_tc_flow { struct encap_flow_item encaps[MLX5_MAX_FLOW_FWD_VPORTS]; struct mlx5e_hairpin_entry *hpe; /* attached hairpin instance */ struct list_head hairpin; /* flows sharing the same hairpin */ - struct list_head peer[MLX5_MAX_PORTS]; /* flows with peer flow */ - DECLARE_BITMAP(peer_used, MLX5_MAX_PORTS); /* tracks populated peer - * slots - */ + struct list_head peer; /* dup: node in origin esw's peer_flows */ struct list_head unready; /* flows not ready to be offloaded (e.g * due to missing route) */ - struct list_head peer_flows; /* flows on peer */ - int peer_index; /* peer-flow index pinned at add time, used at del - * time so removal is independent of LAG state - * changes between add and del. - */ + + /* origin: its dups; dup: node on that list */ + struct list_head peer_flows; + struct mlx5e_tc_flow *peer_orig; /* dup: back-ref to origin flow */ struct net_device *orig_dev; /* netdev adding flow first */ int tmp_entry_index; struct list_head tmp_list; /* temporary flow list used by neigh update */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index b290beb4369a..fae4f8625da4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -2116,43 +2116,35 @@ void mlx5e_put_flow_list(struct mlx5e_priv *priv, struct list_head *flow_list) mlx5e_flow_put(priv, flow); } -static void mlx5e_tc_del_fdb_peer_flow(struct mlx5e_tc_flow *flow, - int peer_index) +static void mlx5e_tc_del_fdb_peer_flow(struct mlx5e_tc_flow *peer_flow) { - struct mlx5_eswitch *esw = flow->priv->mdev->priv.eswitch; - struct mlx5e_tc_flow *peer_flow; - struct mlx5e_tc_flow *tmp; - - if (!flow_flag_test(flow, ESWITCH) || - !flow_flag_test(flow, DUP)) - return; + struct mlx5e_tc_flow *flow = peer_flow->peer_orig; + struct mlx5_eswitch *esw; + esw = flow->priv->mdev->priv.eswitch; mutex_lock(&esw->offloads.peer_mutex); - list_del(&flow->peer[peer_index]); - clear_bit(peer_index, flow->peer_used); + list_del(&peer_flow->peer); mutex_unlock(&esw->offloads.peer_mutex); - list_for_each_entry_safe(peer_flow, tmp, &flow->peer_flows, peer_flows) { - if (peer_index != peer_flow->peer_index) - continue; - - list_del(&peer_flow->peer_flows); - if (refcount_dec_and_test(&peer_flow->refcnt)) { - mlx5e_tc_del_fdb_flow(peer_flow->priv, peer_flow); - kfree(peer_flow); - } - } - + list_del(&peer_flow->peer_flows); if (list_empty(&flow->peer_flows)) flow_flag_clear(flow, DUP); + + if (refcount_dec_and_test(&peer_flow->refcnt)) { + mlx5e_tc_del_fdb_flow(peer_flow->priv, peer_flow); + kfree(peer_flow); + } } static void mlx5e_tc_del_fdb_peers_flow(struct mlx5e_tc_flow *flow) { - int i; + struct mlx5e_tc_flow *peer_flow, *tmp; - for_each_set_bit(i, flow->peer_used, MLX5_MAX_PORTS) - mlx5e_tc_del_fdb_peer_flow(flow, i); + if (!flow_flag_test(flow, ESWITCH) || !flow_flag_test(flow, DUP)) + return; + + list_for_each_entry_safe(peer_flow, tmp, &flow->peer_flows, peer_flows) + mlx5e_tc_del_fdb_peer_flow(peer_flow); } static void mlx5e_tc_del_flow(struct mlx5e_priv *priv, @@ -4639,12 +4631,11 @@ static int mlx5e_tc_add_fdb_peer_flow(struct flow_cls_offload *f, goto out; } - peer_flow->peer_index = i; + peer_flow->peer_orig = flow; list_add_tail(&peer_flow->peer_flows, &flow->peer_flows); flow_flag_set(flow, DUP); mutex_lock(&esw->offloads.peer_mutex); - list_add_tail(&flow->peer[i], &esw->offloads.peer_flows[i]); - set_bit(i, flow->peer_used); + list_add_tail(&peer_flow->peer, &esw->offloads.peer_flows[i]); mutex_unlock(&esw->offloads.peer_mutex); out: @@ -5539,21 +5530,19 @@ int mlx5e_tc_num_filters(struct mlx5e_priv *priv, unsigned long flags) void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw) { - struct mlx5_devcom_comp_dev *devcom; - struct mlx5_devcom_comp_dev *pos; - struct mlx5e_tc_flow *flow, *tmp; + struct mlx5_devcom_comp_dev *devcom = esw->devcom, *pos; + struct mlx5e_tc_flow *peer_flow, *tmp_peer_flow; struct mlx5_eswitch *peer_esw; int i; - devcom = esw->devcom; - mlx5_devcom_for_each_peer_entry(devcom, peer_esw, pos) { i = mlx5_lag_get_dev_seq(peer_esw->dev); if (i < 0) continue; - list_for_each_entry_safe(flow, tmp, &esw->offloads.peer_flows[i], peer[i]) - mlx5e_tc_del_fdb_peers_flow(flow); + list_for_each_entry_safe(peer_flow, tmp_peer_flow, + &esw->offloads.peer_flows[i], peer) + mlx5e_tc_del_fdb_peer_flow(peer_flow); } } From 9d608a40c2d400ef7529e13c165278053ea0d51c Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:25 +0300 Subject: [PATCH 0871/2126] net/mlx5e: TC, track peer flows in a vhca_id xarray The per-peer reverse index lived in a fixed esw->offloads.peer_flows[] array of list heads indexed by the peer's LAG sequence number, capping a shared FDB at MLX5_MAX_PORTS members. Replace the array with an xarray keyed by the peer vhca_id. Each entry is a heap-allocated list head that chains the flows duplicated to that peer via their peer node. This lifts the MLX5_MAX_PORTS cap: the number of peers is bounded only by the number of distinct vhca_ids. The lifetime of the duplicated peer flows list_head follows the devcom pairing of the two eswitches: - pair (mlx5_esw_offloads_pair): kzalloc_obj + INIT_LIST_HEAD + xa_store the dup_peer_flows under the peer's vhca_id. - add (mlx5e_tc_add_fdb_peer_flow): xa_load the dup_peer_flows and list_add the duplicated flow's peer node. - del (mlx5e_tc_del_fdb_peer_flow): list_del that node. - flush (mlx5e_tc_clean_fdb_peer_flows): xa_for_each dup_peer_flows, drop every duplicated flow on it; called from unpair. - unpair (mlx5_esw_offloads_unpair): xa_erase + kfree the dup_peer_flows. So a dup_peer_flows is created when the local eswitch pairs with a peer over devcom and freed when they unpair. No functional change. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-9-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 22 +++++++--------- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 2 +- .../mellanox/mlx5/core/eswitch_offloads.c | 26 ++++++++++++++++--- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index fae4f8625da4..c99e824b4c6d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -4596,12 +4596,13 @@ static int mlx5e_tc_add_fdb_peer_flow(struct flow_cls_offload *f, unsigned long flow_flags, struct mlx5_eswitch *peer_esw) { + u16 peer_vhca_id = MLX5_CAP_GEN(peer_esw->dev, vhca_id); struct mlx5e_priv *priv = flow->priv, *peer_priv; struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; struct mlx5_esw_flow_attr *attr = flow->attr->esw_attr; struct mlx5e_tc_flow_parse_attr *parse_attr; - int i = mlx5_lag_get_dev_seq(peer_esw->dev); struct mlx5e_rep_priv *peer_urpriv; + struct list_head *dup_peer_flows; struct mlx5e_tc_flow *peer_flow; struct mlx5_core_dev *in_mdev; int err = 0; @@ -4634,8 +4635,11 @@ static int mlx5e_tc_add_fdb_peer_flow(struct flow_cls_offload *f, peer_flow->peer_orig = flow; list_add_tail(&peer_flow->peer_flows, &flow->peer_flows); flow_flag_set(flow, DUP); + dup_peer_flows = xa_load(&esw->offloads.peer_flows, peer_vhca_id); + if (!dup_peer_flows) + return -ENODEV; mutex_lock(&esw->offloads.peer_mutex); - list_add_tail(&peer_flow->peer, &esw->offloads.peer_flows[i]); + list_add_tail(&peer_flow->peer, dup_peer_flows); mutex_unlock(&esw->offloads.peer_mutex); out: @@ -5530,20 +5534,14 @@ int mlx5e_tc_num_filters(struct mlx5e_priv *priv, unsigned long flags) void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw) { - struct mlx5_devcom_comp_dev *devcom = esw->devcom, *pos; struct mlx5e_tc_flow *peer_flow, *tmp_peer_flow; - struct mlx5_eswitch *peer_esw; - int i; - - mlx5_devcom_for_each_peer_entry(devcom, peer_esw, pos) { - i = mlx5_lag_get_dev_seq(peer_esw->dev); - if (i < 0) - continue; + struct list_head *dup_peer_flows; + unsigned long index; + xa_for_each(&esw->offloads.peer_flows, index, dup_peer_flows) list_for_each_entry_safe(peer_flow, tmp_peer_flow, - &esw->offloads.peer_flows[i], peer) + dup_peer_flows, peer) mlx5e_tc_del_fdb_peer_flow(peer_flow); - } } void mlx5e_tc_reoffload_flows_work(struct work_struct *work) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h index 8b1f93b13ea9..e9cbcd73b23f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -319,7 +319,7 @@ struct mlx5_esw_offload { struct mlx5_flow_handle *vport_rx_drop_rule; struct mlx5_flow_table *ft_ipsec_tx_pol; struct xarray vport_reps; - struct list_head peer_flows[MLX5_MAX_PORTS]; + struct xarray peer_flows; struct mutex peer_mutex; struct mutex encap_tbl_lock; /* protects encap_tbl */ DECLARE_HASHTABLE(encap_tbl, 8); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index e7d92d9bde16..c712848b202d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -3383,10 +3383,15 @@ static void mlx5_esw_offloads_rep_event_unpair(struct mlx5_eswitch *esw, static void mlx5_esw_offloads_unpair(struct mlx5_eswitch *esw, struct mlx5_eswitch *peer_esw) { + struct list_head *dup_peer_flows; + #if IS_ENABLED(CONFIG_MLX5_CLS_ACT) mlx5e_tc_clean_fdb_peer_flows(esw); #endif mlx5_esw_offloads_rep_event_unpair(esw, peer_esw); + dup_peer_flows = xa_erase(&esw->offloads.peer_flows, + MLX5_CAP_GEN(peer_esw->dev, vhca_id)); + kfree(dup_peer_flows); esw_del_fdb_peer_miss_rules(esw, peer_esw->dev); } @@ -3394,6 +3399,7 @@ static int mlx5_esw_offloads_pair(struct mlx5_eswitch *esw, struct mlx5_eswitch *peer_esw) { const struct mlx5_eswitch_rep_ops *ops; + struct list_head *dup_peer_flows; struct mlx5_eswitch_rep *rep; unsigned long i; u8 rep_type; @@ -3403,6 +3409,20 @@ static int mlx5_esw_offloads_pair(struct mlx5_eswitch *esw, if (err) return err; + dup_peer_flows = kzalloc_obj(*dup_peer_flows); + if (!dup_peer_flows) { + err = -ENOMEM; + goto err_out; + } + INIT_LIST_HEAD(dup_peer_flows); + err = xa_err(xa_store(&esw->offloads.peer_flows, + MLX5_CAP_GEN(peer_esw->dev, vhca_id), + dup_peer_flows, GFP_KERNEL)); + if (err) { + kfree(dup_peer_flows); + goto err_out; + } + mlx5_esw_for_each_rep(esw, i, rep) { for (rep_type = 0; rep_type < NUM_REP_TYPES; rep_type++) { ops = esw->offloads.rep_ops[rep_type]; @@ -3549,10 +3569,8 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw, const struct mlx5_devcom_match_attr *attr) { int err; - int i; - for (i = 0; i < MLX5_MAX_PORTS; i++) - INIT_LIST_HEAD(&esw->offloads.peer_flows[i]); + xa_init(&esw->offloads.peer_flows); mutex_init(&esw->offloads.peer_mutex); if (!MLX5_CAP_ESW(esw->dev, merged_eswitch)) @@ -3595,6 +3613,8 @@ void mlx5_esw_offloads_devcom_cleanup(struct mlx5_eswitch *esw) xa_destroy(&esw->paired); xa_destroy(&esw->fdb_table.offloads.peer_miss_rules); esw->devcom = NULL; + WARN_ON_ONCE(!xa_empty(&esw->offloads.peer_flows)); + xa_destroy(&esw->offloads.peer_flows); } bool mlx5_esw_offloads_devcom_is_ready(struct mlx5_eswitch *esw) From d451adde0203fa62519eb224be87046b27c76b99 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:26 +0300 Subject: [PATCH 0872/2126] net/mlx5: E-switch, derive manager vport from device capability mlx5_eswitch_manager_vport() hardcoded the e-switch manager vport as either the ECPF or the host PF. Read esw_manager_vport_number from the e-switch capability when esw_manager_vport_number_valid is set, so the manager vport can be a VF - a prerequisite for VFs acting as e-switch managers. Keep the previous mapping as fallback when the capability does not report a number. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-10-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 11 +++++++++-- include/linux/mlx5/eswitch.h | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index fc197d1dc9df..e7561f0f89b0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -2460,13 +2460,20 @@ static int mlx5_esw_vports_init(struct mlx5_eswitch *esw) } } - if (mlx5_ecpf_vport_exists(dev) || - mlx5_core_is_ecpf_esw_manager(dev)) { + if (mlx5_ecpf_vport_exists(dev)) { err = mlx5_esw_vport_alloc(esw, idx, MLX5_VPORT_ECPF); if (err) goto err; idx++; } + + if (!xa_load(&esw->vports, esw->manager_vport)) { + err = mlx5_esw_vport_alloc(esw, idx, esw->manager_vport); + if (err) + goto err; + idx++; + } + err = mlx5_esw_vport_alloc(esw, idx, MLX5_VPORT_UPLINK); if (err) goto err; diff --git a/include/linux/mlx5/eswitch.h b/include/linux/mlx5/eswitch.h index a0dd162baa78..03d3620141c8 100644 --- a/include/linux/mlx5/eswitch.h +++ b/include/linux/mlx5/eswitch.h @@ -222,6 +222,9 @@ static inline bool is_mdev_switchdev_mode(struct mlx5_core_dev *dev) /* The returned number is valid only when the dev is eswitch manager. */ static inline u16 mlx5_eswitch_manager_vport(struct mlx5_core_dev *dev) { + if (MLX5_CAP_ESW(dev, esw_manager_vport_number_valid)) + return MLX5_CAP_ESW(dev, esw_manager_vport_number); + return mlx5_core_is_ecpf_esw_manager(dev) ? MLX5_VPORT_ECPF : MLX5_VPORT_HOST_PF; } From c51ea6db00e6b872143a10aecf8449f23865965c Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:27 +0300 Subject: [PATCH 0873/2126] net/mlx5: LAG, don't print port mapping to debugfs in MPESW mode The mapping debugfs file dumps the LAG virtual-to-physical port mapping. In MPESW mode the LAG does not own that mapping - port selection is driven by user steering rules, not by the LAG - so the dumped values are meaningless. Treat MPESW as if LAG is inactive and don't print anything to the user. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-11-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c index 44296789d656..b6125c7bd91b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c @@ -114,7 +114,8 @@ static int mapping_show(struct seq_file *file, void *priv) return -ENOMEM; mutex_lock(&ldev->lock); - lag_active = __mlx5_lag_is_active(ldev); + lag_active = __mlx5_lag_is_active(ldev) && + ldev->mode != MLX5_LAG_MODE_MPESW; if (lag_active) { if (test_bit(MLX5_LAG_MODE_FLAG_HASH_BASED, &ldev->mode_flags)) { mlx5_infer_tx_enabled(&ldev->tracker, ldev, ports, From 66b25da0cfed831be0ec1536dc7499e232030236 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:28 +0300 Subject: [PATCH 0874/2126] net/mlx5: LAG, drop stale esw_shared_ingress_acl gate from shared FDB The shared-FDB support check still requires the esw_shared_ingress_acl capability. That capability backed the merged uplink ingress ACL, where the slave uplink's ingress-ACL root was pointed at the master's (esw_set_uplink_slave_ingress_root()). That handling was removed in commit 82e86a6c7109 ("net/mlx5: E-switch, remove special uplink ingress ACL handling") once both uplinks were tagged with the same reserved metadata (MLX5_ESW_METADATA_RSVD_UPLINK) - a single FDB rule then matches traffic from either uplink, with no shared ingress ACL involved. The capability check was left behind and has been dead since: the driver programs no shared ingress ACL, yet the check still keeps otherwise shared-FDB-capable devices out of shared FDB. Drop it. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-12-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c index 424040918fa3..7c7e6c832a93 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c @@ -35,8 +35,7 @@ bool mlx5_lag_shared_fdb_supported_filter(struct mlx5_lag *ldev, u32 filter) if (is_mdev_switchdev_mode(dev0) && mlx5_eswitch_vport_match_metadata_enabled(dev0->priv.eswitch) && - mlx5_esw_offloads_devcom_is_ready(dev0->priv.eswitch) && - MLX5_CAP_ESW(dev0, esw_shared_ingress_acl)) + mlx5_esw_offloads_devcom_is_ready(dev0->priv.eswitch)) ret = true; return ret; From dd655b1e93c149bc0a42c1432870898475f8c4cf Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:29 +0300 Subject: [PATCH 0875/2126] net/mlx5: E-switch, correct stale VF/PF wording in esw-allowed comments mlx5_esw_hold() and mlx5_eswitch_unblock_ipsec() bail out on !mlx5_esw_allowed(), and their comments explained that as "a VF has no eswitch" / "core dev is not a PF". New FW will let a VF act as a nested e-switch manager - such a VF has an eswitch and passes mlx5_esw_allowed() - so that equivalence no longer holds. Reword the comments to describe the actual condition, the device is not an e-switch manager, with no functional change. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-13-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index e7561f0f89b0..6f3676c86d3d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -2958,7 +2958,7 @@ bool mlx5_esw_hold(struct mlx5_core_dev *mdev) { struct mlx5_eswitch *esw = mdev->priv.eswitch; - /* e.g. VF doesn't have eswitch so nothing to do */ + /* Not an eswitch manager, so there is no mode lock to take */ if (!mlx5_esw_allowed(esw)) return true; @@ -3106,7 +3106,7 @@ void mlx5_eswitch_unblock_ipsec(struct mlx5_core_dev *dev) struct mlx5_eswitch *esw = dev->priv.eswitch; if (!mlx5_esw_allowed(esw)) - /* Failure means no eswitch => core dev is not a PF */ + /* Not an eswitch manager, so nothing was blocked */ return; mutex_lock(&esw->state_lock); From a5bfbdfebd5353a4113539342e800610606a8153 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Wed, 23 Sep 2026 13:38:30 +0300 Subject: [PATCH 0876/2126] net/mlx5: E-switch, disable host functions for a non PF e-switch manager mlx5_esw_host_functions_enabled() only treated host functions as disabled for an ECPF manager. To support a non PF acting as an e-switch manager, add a check for a non PF e-switch manager that treats host functions as disabled. This will avoid allocating a host-PF vport in mlx5_esw_vports_init(). With host functions disabled for non PF, its e-switch is the expected manager + uplink only. Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260923103830.1183-14-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index 6f3676c86d3d..2d289fb1353b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -1241,6 +1241,11 @@ static int mlx5_esw_host_functions_enabled_query(struct mlx5_eswitch *esw) struct mlx5_esw_pf_info host_pf_info; const u32 *query_host_out; + if (!mlx5_core_is_pf(esw->dev)) { + esw->esw_funcs.host_funcs_disabled = true; + return 0; + } + if (!mlx5_core_is_ecpf_esw_manager(esw->dev)) return 0; From 608e7f84960bad22d933ff877ba41b1f75b43770 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 23 Sep 2026 19:40:07 +0100 Subject: [PATCH 0877/2126] vsock: report pending receive data to io_uring AF_VSOCK stream receives never fill msghdr.msg_inq, so io_uring cannot set IORING_CQE_F_SOCK_NONEMPTY and retries a multishot receive even after the queue has been drained. Fill the hint at the common receive exit using the transport callback that SIOCINQ already uses, and report 1 once the connection is finished so the caller performs the receive which observes EOF, as TCP does after a FIN. A vsock loopback ping-pong with io_uring multishot receive drops entries into __vsock_connectible_recvmsg from 1.97 to 1.00 per delivered message, and receiver CPU time by about 3% (25 runs of 50000 messages, p=0.006). Signed-off-by: David Carlier Reviewed-by: Stefano Garzarella Link: https://patch.msgid.link/20260923184008.153541-2-devnexen@gmail.com Signed-off-by: Jakub Kicinski --- net/vmw_vsock/af_vsock.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 9b71479a2b29..44cee7451955 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -2543,6 +2543,35 @@ out: return err; } +/* Bytes a following receive can consume, 1 if it would only see EOF, or -1 + * if the transport cannot tell. + * + * Called under the socket lock after a nonnegative stream receive, so a NULL + * transport implies SOCK_DONE. + */ +static int vsock_stream_inq_hint(struct sock *sk) +{ + struct vsock_sock *vsk = vsock_sk(sk); + s64 data; + + if ((sk->sk_shutdown & RCV_SHUTDOWN) || !vsk->transport || + (sock_flag(sk, SOCK_DONE) && sk->sk_state != TCP_ESTABLISHED)) + return 1; + + data = vsock_stream_has_data(vsk); + if (data < 0) + return -1; + if (data > 0) + return min_t(s64, data, INT_MAX); + + /* Empty but finished: keep the caller reading so it sees EOF. */ + if (sock_flag(sk, SOCK_DONE) || + (READ_ONCE(vsk->peer_shutdown) & SEND_SHUTDOWN)) + return 1; + + return 0; +} + int __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int flags) @@ -2606,6 +2635,12 @@ __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, err = __vsock_seqpacket_recvmsg(sk, msg, len, flags); out: + /* Seqpacket has_data counts messages, while io_uring treats msg_inq as + * a byte length when sizing retries, so only streams report a hint. + */ + if (msg->msg_get_inq && err >= 0 && sk->sk_type == SOCK_STREAM) + msg->msg_inq = vsock_stream_inq_hint(sk); + release_sock(sk); return err; } From c116f78f94a4f51b30a967f6f33c509dae8942bd Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 23 Sep 2026 19:40:08 +0100 Subject: [PATCH 0878/2126] vsock/test: cover receive queue hints Add io_uring receive tests checking IORING_CQE_F_SOCK_NONEMPTY across a partial receive, draining while the peer stays connected, EOF, a nonblocking receive on an empty queue, a zero-length request, and a multishot receive with provided buffers. Signed-off-by: David Carlier Reviewed-by: Bobby Eshleman Reviewed-by: Stefano Garzarella Link: https://patch.msgid.link/20260923184008.153541-3-devnexen@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/vsock/util.c | 9 + tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_uring_test.c | 391 +++++++++++++++++++++++++ 3 files changed, 401 insertions(+) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index fe316b02a590..299a4e8ecb63 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -483,6 +483,15 @@ void recv_byte(int fd, int expected_ret, int flags) } } +void expect_res(int res, int expected, const char *what) +{ + if (res != expected) { + fprintf(stderr, "%s: expected %d, got %d\n", what, expected, + res); + exit(EXIT_FAILURE); + } +} + /* Run test cases. The program terminates if a failure occurs. */ void run_tests(const struct test_case *test_cases, const struct test_opts *opts) diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index bf633cde82b0..9dabb547021e 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -94,6 +94,7 @@ void send_buf(int fd, const void *buf, size_t len, int flags, void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_ret); void send_byte(int fd, int expected_ret, int flags); void recv_byte(int fd, int expected_ret, int flags); +void expect_res(int res, int expected, const char *what); void run_tests(const struct test_case *test_cases, const struct test_opts *opts); void list_tests(const struct test_case *test_cases); diff --git a/tools/testing/vsock/vsock_uring_test.c b/tools/testing/vsock/vsock_uring_test.c index 5c3078969659..c6cc51db7adc 100644 --- a/tools/testing/vsock/vsock_uring_test.c +++ b/tools/testing/vsock/vsock_uring_test.c @@ -13,7 +13,10 @@ #include #include #include +#include #include +#include +#include #include #include "util.h" @@ -28,6 +31,10 @@ #define VSOCK_TEST_DATA_MAX_IOV 3 +#define HINT_CHUNK_SIZE 4096 +#define HINT_BUF_GROUP 1 +#define HINT_BUF_ENTRIES 4 + struct vsock_io_uring_test { /* Number of valid elements in 'vecs'. */ int vecs_cnt; @@ -211,6 +218,365 @@ void test_stream_uring_msg_zc_client(const struct test_opts *opts) vsock_io_uring_client(opts, &test_data_array[i], true); } +struct uring_inq_ctx { + struct io_uring ring; + int fd; +}; + +static void inq_server_init(struct uring_inq_ctx *ctx, + const struct test_opts *opts) +{ + ctx->fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); + if (ctx->fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + if (io_uring_queue_init(RING_ENTRIES_NUM, &ctx->ring, 0)) + error(1, errno, "io_uring_queue_init"); +} + +static void inq_server_exit(struct uring_inq_ctx *ctx) +{ + io_uring_queue_exit(&ctx->ring); + close(ctx->fd); +} + +/* Submit a single receive and report both its result and its CQE flags. */ +static int inq_recv(struct uring_inq_ctx *ctx, void *buf, size_t len, + int flags, unsigned int *cflags) +{ + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + int res; + + sqe = io_uring_get_sqe(&ctx->ring); + io_uring_prep_recv(sqe, ctx->fd, buf, len, flags); + + if (io_uring_submit(&ctx->ring) != 1) + error(1, errno, "io_uring_submit"); + + if (io_uring_wait_cqe(&ctx->ring, &cqe)) + error(1, errno, "io_uring_wait_cqe"); + + res = cqe->res; + *cflags = cqe->flags; + io_uring_cqe_seen(&ctx->ring, cqe); + + return res; +} + +static void expect_uring_nonempty(unsigned int cflags, bool expected, + const char *what) +{ + bool nonempty = !!(cflags & IORING_CQE_F_SOCK_NONEMPTY); + + if (nonempty != expected) { + fprintf(stderr, "%s: expected SOCK_NONEMPTY %d, got %d\n", + what, expected, nonempty); + exit(EXIT_FAILURE); + } +} + +static void expect_uring_more(unsigned int cflags, bool expected, + const char *what) +{ + bool more = !!(cflags & IORING_CQE_F_MORE); + + if (more != expected) { + fprintf(stderr, "%s: expected F_MORE %d, got %d\n", + what, expected, more); + exit(EXIT_FAILURE); + } +} + +/* Wait until the whole payload is queued, so the hint is deterministic. + * Return false if the test has to be skipped. + */ +static bool inq_wait_queued(int fd, int len) +{ + if (!vsock_ioctl_int(fd, SIOCINQ, len)) { + fprintf(stderr, "Test skipped, SIOCINQ not supported.\n"); + return false; + } + + return true; +} + +static void inq_send_chunks(const struct test_opts *opts, int chunks) +{ + char buf[HINT_CHUNK_SIZE]; + int fd, i; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + memset(buf, 0xa5, sizeof(buf)); + for (i = 0; i < chunks; i++) + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + + control_writeln("SENT"); + control_expectln("DONE"); + close(fd); +} + +static void test_stream_uring_inq_client(const struct test_opts *opts) +{ + inq_send_chunks(opts, 2); +} + +static void test_stream_uring_inq_server(const struct test_opts *opts) +{ + char buf[HINT_CHUNK_SIZE]; + struct uring_inq_ctx ctx; + unsigned int cflags; + int res; + + inq_server_init(&ctx, opts); + + control_expectln("SENT"); + if (!inq_wait_queued(ctx.fd, 2 * HINT_CHUNK_SIZE)) + goto out; + + /* Data remains after this receive, so the flag must be set. */ + res = inq_recv(&ctx, buf, sizeof(buf), 0, &cflags); + expect_res(res, HINT_CHUNK_SIZE, "partial receive"); + expect_uring_nonempty(cflags, true, "partial receive"); + + /* This receive drains the queue while the peer stays connected. */ + res = inq_recv(&ctx, buf, sizeof(buf), 0, &cflags); + expect_res(res, HINT_CHUNK_SIZE, "draining receive"); + expect_uring_nonempty(cflags, false, "draining receive"); + +out: + control_writeln("DONE"); + inq_server_exit(&ctx); +} + +static void test_stream_uring_inq_eof_client(const struct test_opts *opts) +{ + char buf[HINT_CHUNK_SIZE]; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + memset(buf, 0x5a, sizeof(buf)); + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + control_writeln("SENT"); + + control_expectln("DRAINED"); + close(fd); + control_writeln("CLOSED"); +} + +static void test_stream_uring_inq_eof_server(const struct test_opts *opts) +{ + char buf[HINT_CHUNK_SIZE]; + struct uring_inq_ctx ctx; + unsigned int cflags; + int res; + + inq_server_init(&ctx, opts); + + control_expectln("SENT"); + if (!inq_wait_queued(ctx.fd, HINT_CHUNK_SIZE)) { + control_writeln("DRAINED"); + control_expectln("CLOSED"); + goto out; + } + + res = inq_recv(&ctx, buf, sizeof(buf), 0, &cflags); + expect_res(res, HINT_CHUNK_SIZE, "drain before EOF"); + expect_uring_nonempty(cflags, false, "drain before EOF"); + + control_writeln("DRAINED"); + control_expectln("CLOSED"); + + /* The queue is empty and the peer is gone. The hint stays non-zero + * so that this receive happens and reports EOF, as TCP does after a + * FIN. + */ + res = inq_recv(&ctx, buf, sizeof(buf), 0, &cflags); + expect_res(res, 0, "receive at EOF"); + expect_uring_nonempty(cflags, true, "receive at EOF"); + +out: + inq_server_exit(&ctx); +} + +static void test_stream_uring_inq_empty_client(const struct test_opts *opts) +{ + int fd; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + control_writeln("READY"); + control_expectln("DONE"); + close(fd); +} + +static void test_stream_uring_inq_empty_server(const struct test_opts *opts) +{ + char buf[HINT_CHUNK_SIZE]; + struct uring_inq_ctx ctx; + unsigned int cflags; + int res; + + inq_server_init(&ctx, opts); + + control_expectln("READY"); + + /* A failed receive must not leave a stale positive hint. */ + res = inq_recv(&ctx, buf, sizeof(buf), MSG_DONTWAIT, &cflags); + expect_res(res, -EAGAIN, "empty nonblocking receive"); + expect_uring_nonempty(cflags, false, "empty nonblocking receive"); + + control_writeln("DONE"); + inq_server_exit(&ctx); +} + +static void test_stream_uring_inq_zerolen_client(const struct test_opts *opts) +{ + inq_send_chunks(opts, 1); +} + +static void test_stream_uring_inq_zerolen_server(const struct test_opts *opts) +{ + char buf[HINT_CHUNK_SIZE]; + struct uring_inq_ctx ctx; + unsigned int cflags; + int res; + + inq_server_init(&ctx, opts); + + control_expectln("SENT"); + if (!inq_wait_queued(ctx.fd, HINT_CHUNK_SIZE)) + goto out; + + /* A zero-length request is not an error and still describes the + * queue behind it. + */ + res = inq_recv(&ctx, buf, 0, 0, &cflags); + expect_res(res, 0, "zero-length receive"); + expect_uring_nonempty(cflags, true, "zero-length receive"); + +out: + control_writeln("DONE"); + inq_server_exit(&ctx); +} + +static void test_stream_uring_inq_mshot_client(const struct test_opts *opts) +{ + char buf[HINT_CHUNK_SIZE]; + int fd, i; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + memset(buf, 0x3c, sizeof(buf)); + for (i = 0; i < 2; i++) + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + control_writeln("SENT"); + + control_expectln("DRAINED"); + close(fd); + control_writeln("CLOSED"); + + control_expectln("DONE"); +} + +static void test_stream_uring_inq_mshot_server(const struct test_opts *opts) +{ + static char bufs[HINT_BUF_ENTRIES][HINT_CHUNK_SIZE]; + struct io_uring_buf_ring *br; + struct uring_inq_ctx ctx; + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + int i, ret; + + inq_server_init(&ctx, opts); + + br = io_uring_setup_buf_ring(&ctx.ring, HINT_BUF_ENTRIES, + HINT_BUF_GROUP, 0, &ret); + if (!br) { + fprintf(stderr, "io_uring_setup_buf_ring: %d\n", ret); + exit(EXIT_FAILURE); + } + + for (i = 0; i < HINT_BUF_ENTRIES; i++) + io_uring_buf_ring_add(br, bufs[i], HINT_CHUNK_SIZE, i, + io_uring_buf_ring_mask(HINT_BUF_ENTRIES), + i); + io_uring_buf_ring_advance(br, HINT_BUF_ENTRIES); + + control_expectln("SENT"); + if (!inq_wait_queued(ctx.fd, 2 * HINT_CHUNK_SIZE)) { + control_writeln("DRAINED"); + control_expectln("CLOSED"); + goto out; + } + + /* Arm only once both chunks are queued, so every completion knows + * what is left behind it. + */ + sqe = io_uring_get_sqe(&ctx.ring); + io_uring_prep_recv_multishot(sqe, ctx.fd, NULL, 0, 0); + sqe->flags |= IOSQE_BUFFER_SELECT; + sqe->buf_group = HINT_BUF_GROUP; + + if (io_uring_submit(&ctx.ring) != 1) + error(1, errno, "io_uring_submit"); + + /* A buffer holds one chunk, so the other one is still queued. */ + if (io_uring_wait_cqe(&ctx.ring, &cqe)) + error(1, errno, "io_uring_wait_cqe"); + + expect_res(cqe->res, HINT_CHUNK_SIZE, "multishot first chunk"); + expect_uring_nonempty(cqe->flags, true, "multishot first chunk"); + expect_uring_more(cqe->flags, true, "multishot first chunk"); + io_uring_cqe_seen(&ctx.ring, cqe); + + /* This completion drains the queue and keeps the request armed. */ + if (io_uring_wait_cqe(&ctx.ring, &cqe)) + error(1, errno, "io_uring_wait_cqe"); + + expect_res(cqe->res, HINT_CHUNK_SIZE, "multishot second chunk"); + expect_uring_nonempty(cqe->flags, false, "multishot second chunk"); + expect_uring_more(cqe->flags, true, "multishot second chunk"); + io_uring_cqe_seen(&ctx.ring, cqe); + + control_writeln("DRAINED"); + control_expectln("CLOSED"); + + /* EOF ends multishot regardless of the hint. */ + if (io_uring_wait_cqe(&ctx.ring, &cqe)) + error(1, errno, "io_uring_wait_cqe"); + + expect_res(cqe->res, 0, "multishot EOF"); + expect_uring_more(cqe->flags, false, "multishot EOF"); + io_uring_cqe_seen(&ctx.ring, cqe); + +out: + control_writeln("DONE"); + io_uring_free_buf_ring(&ctx.ring, br, HINT_BUF_ENTRIES, + HINT_BUF_GROUP); + inq_server_exit(&ctx); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM io_uring test", @@ -222,6 +588,31 @@ static struct test_case test_cases[] = { .run_server = test_stream_uring_msg_zc_server, .run_client = test_stream_uring_msg_zc_client, }, + { + .name = "SOCK_STREAM io_uring receive queue hint", + .run_server = test_stream_uring_inq_server, + .run_client = test_stream_uring_inq_client, + }, + { + .name = "SOCK_STREAM io_uring receive hint at EOF", + .run_server = test_stream_uring_inq_eof_server, + .run_client = test_stream_uring_inq_eof_client, + }, + { + .name = "SOCK_STREAM io_uring receive hint on empty queue", + .run_server = test_stream_uring_inq_empty_server, + .run_client = test_stream_uring_inq_empty_client, + }, + { + .name = "SOCK_STREAM io_uring receive hint zero-length", + .run_server = test_stream_uring_inq_zerolen_server, + .run_client = test_stream_uring_inq_zerolen_client, + }, + { + .name = "SOCK_STREAM io_uring multishot receive hint", + .run_server = test_stream_uring_inq_mshot_server, + .run_client = test_stream_uring_inq_mshot_client, + }, {}, }; From c20d84c6dec8236afecf6493b5b89d955dc83fc3 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Thu, 24 Sep 2026 15:32:45 -0700 Subject: [PATCH 0879/2126] tools: ynl-gen-c: keep the type values of a nest in spec order Family._load_nested_set_nest() collects the type-value names of a nest-type-value attribute into a set and Struct.set_inherited() renders them sorted, while TypeNestTypeValue._attr_get() passes them to the parse helper in the order the spec lists them. For nlctrl's type-value: [policy-id, attr-id] that makes the generated helper take (attr_id, policy_id) and the caller pass (policy_id, attr_id). Both are __u32 so nothing complains, and every C YNL user of the nlctrl policy dump gets the two swapped. Two attributes nesting the same attribute set with the type values in a different order now fail set_inherited() instead of comparing equal. No spec does that today, but better safe than sorry. Nesting an attribute set which is also used as a sub-message gets its own check: it used to be caught by the list-versus-set type mismatch, which the ordering fix removes, and without it the generator emits a call to the sub-message parser with the selector argument missing. Again, no spec does this today. nlctrl is the only spec affected, discovered by an LLM scan of the spec. Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260924223245.530132-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- tools/net/ynl/pyynl/ynl_gen_c.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py index 2b3483db1b60..15c79849c609 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -986,7 +986,8 @@ class Struct: self.family = family self.space_name = space_name self.attr_set = family.attr_sets[space_name] - # Use list to catch comparisons with empty sets + # Stored by reference, _load_nested_set_nest() fills the list in + # after constructing us. self._inherited = inherited if inherited is not None else [] self.inherited = [] self.fixed_header = None @@ -1038,9 +1039,11 @@ class Struct: return self.attr_list def set_inherited(self, new_inherited): + if self.submsg: + raise Exception("Nesting a sub-message as an attribute set not supported") if self._inherited != new_inherited: - raise Exception("Inheriting different members not supported") - self.inherited = [c_lower(x) for x in sorted(self._inherited)] + raise Exception("Inheriting different members, or a different order, not supported") + self.inherited = [c_lower(x) for x in self._inherited] def external_selectors(self): sels = [] @@ -1394,7 +1397,7 @@ class Family(SpecFamily): pns_key_list.append(name) def _load_nested_set_nest(self, spec): - inherit = set() + inherit = [] nested = spec['nested-attributes'] if nested not in self.root_sets: if nested not in self.pure_nested_structs: @@ -1407,9 +1410,9 @@ class Family(SpecFamily): if 'type-value' in spec: if nested in self.root_sets: raise Exception("Inheriting members to a space used as root not supported") - inherit.update(set(spec['type-value'])) + inherit.extend(spec['type-value']) elif spec['type'] == 'indexed-array': - inherit.add('idx') + inherit.append('idx') self.pure_nested_structs[nested].set_inherited(inherit) return nested From 67da3009384f80c93f5e90e9bc88c1afe77464be Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Fri, 25 Sep 2026 15:52:35 +0200 Subject: [PATCH 0880/2126] net: ethtool: reject an out of range hwtstamp provider index A provider index of 0xFFFFFFFF picks a provider on hardware that has none. phc_index is an int where -1 means no PHC, and the u32 from user space ends up as -1, so the two match. TSINFO_GET uses -1 for "no provider requested" and answers with the default provider instead of an error. Reject the value in the netlink policy, which covers every comparison site. Signed-off-by: Nicolai Buchwitz Reviewed-by: Kory Maincent Link: https://patch.msgid.link/20260925135237.3432266-2-nb@tipi-net.de Signed-off-by: Jakub Kicinski --- net/ethtool/ts.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/ethtool/ts.h b/net/ethtool/ts.h index d901a879a671..ab9805308353 100644 --- a/net/ethtool/ts.h +++ b/net/ethtool/ts.h @@ -5,9 +5,15 @@ #include "netlink.h" +/* phc_index is an int and -1 means no PHC, so keep the request non-negative */ +static const struct netlink_range_validation ethnl_ts_prov_index_range = { + .max = INT_MAX, +}; + static const struct nla_policy ethnl_ts_hwtst_prov_policy[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_MAX + 1] = { - [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] = { .type = NLA_U32 }, + [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] = + NLA_POLICY_FULL_RANGE(NLA_U32, ðnl_ts_prov_index_range), [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER] = NLA_POLICY_MAX(NLA_U32, HWTSTAMP_PROVIDER_QUALIFIER_CNT - 1) }; From c66d93e68728cfb5f40b40d0f24129d7768faf43 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 26 Sep 2026 03:33:52 +0000 Subject: [PATCH 0881/2126] ipv6: Remove FIB6_EXCEPTION_BUCKET_FLUSHED. The FIB6_EXCEPTION_BUCKET_FLUSHED logic has been dead since added. Commit 0346ec2f080b ("ipv6: Prevent rt6_insert_exception() for dying fib6_info.") restored the original race protection in rt6_insert_exception() by reusing fib6_info.fib6_destroying. The flag now prevents two races for per-cpu and exception routes. Let's remove FIB6_EXCEPTION_BUCKET_FLUSHED and set fib6_destroying in fib6_purge_rt(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260926033355.3295550-1-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_fib.c | 14 +++++++------- net/ipv6/route.c | 45 --------------------------------------------- 2 files changed, 7 insertions(+), 52 deletions(-) diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 9ff761962b45..0dc6ebee6e56 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -1019,12 +1019,6 @@ static int fib6_nh_drop_pcpu_from(struct fib6_nh *nh, void *_arg) static void fib6_drop_pcpu_from(struct fib6_info *f6i) { - /* Make sure rt6_make_pcpu_route() wont add other percpu routes - * while we are cleaning them here. - */ - f6i->fib6_destroying = 1; - mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */ - if (f6i->nh) { rcu_read_lock(); nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_drop_pcpu_from, f6i); @@ -1042,7 +1036,13 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn, { struct fib6_table *table = rt->fib6_table; - /* Flush all cached dst in exception table */ + /* Make sure rt6_make_pcpu_route() / rt6_insert_exception() + * will not add other percpu / exception routes after cleaning + * them up in __fib6_drop_pcpu_from() / rt6_flush_exceptions(). + */ + rt->fib6_destroying = 1; + mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */ + fib6_drop_pcpu_from(rt); rt6_flush_exceptions(rt); diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 475ced827ec5..a76869ff87cd 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1663,13 +1663,6 @@ static unsigned int fib6_mtu(const struct fib6_result *res) return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); } -#define FIB6_EXCEPTION_BUCKET_FLUSHED 0x1UL - -/* used when the flushed bit is not relevant, only access to the bucket - * (ie., all bucket users except rt6_insert_exception); - * - * called under rcu lock; sometimes called with rt6_exception_lock held - */ static struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh, spinlock_t *lock) @@ -1682,40 +1675,9 @@ struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh, else bucket = rcu_dereference(nh->rt6i_exception_bucket); - /* remove bucket flushed bit if set */ - if (bucket) { - unsigned long p = (unsigned long)bucket; - - p &= ~FIB6_EXCEPTION_BUCKET_FLUSHED; - bucket = (struct rt6_exception_bucket *)p; - } - return bucket; } -static bool fib6_nh_excptn_bucket_flushed(struct rt6_exception_bucket *bucket) -{ - unsigned long p = (unsigned long)bucket; - - return !!(p & FIB6_EXCEPTION_BUCKET_FLUSHED); -} - -/* called with rt6_exception_lock held */ -static void fib6_nh_excptn_bucket_set_flushed(struct fib6_nh *nh, - spinlock_t *lock) -{ - struct rt6_exception_bucket *bucket; - unsigned long p; - - bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, - lockdep_is_held(lock)); - - p = (unsigned long)bucket; - p |= FIB6_EXCEPTION_BUCKET_FLUSHED; - bucket = (struct rt6_exception_bucket *)p; - rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); -} - static int rt6_insert_exception(struct rt6_info *nrt, const struct fib6_result *res) { @@ -1745,9 +1707,6 @@ static int rt6_insert_exception(struct rt6_info *nrt, goto out; } rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); - } else if (fib6_nh_excptn_bucket_flushed(bucket)) { - err = -EINVAL; - goto out; } #ifdef CONFIG_IPV6_SUBTREES @@ -1818,10 +1777,6 @@ static void fib6_nh_flush_exceptions(struct fib6_nh *nh, struct fib6_info *from) if (!bucket) goto out; - /* Prevent rt6_insert_exception() to recreate the bucket list */ - if (!from) - fib6_nh_excptn_bucket_set_flushed(nh, &rt6_exception_lock); - for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) { hlist_for_each_entry_safe(rt6_ex, tmp, &bucket->chain, hlist) { if (!from || From f817c1894dc12af86d11110df4ab3d70271b627c Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Tue, 8 Sep 2026 17:37:55 +0800 Subject: [PATCH 0882/2126] mmc: sdio: add NXP IW610 device ID Add SDIO device ID (0x0215) for NXP IW610 to sdio_ids.h. It is used by the nxpwifi driver to probe the IW610 chip over SDIO. Signed-off-by: Jeff Chen Acked-by: Ulf Hansson --- include/linux/mmc/sdio_ids.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/mmc/sdio_ids.h b/include/linux/mmc/sdio_ids.h index afae93f6f245..5eff5e348eb0 100644 --- a/include/linux/mmc/sdio_ids.h +++ b/include/linux/mmc/sdio_ids.h @@ -123,6 +123,7 @@ #define SDIO_VENDOR_ID_NXP 0x0471 #define SDIO_DEVICE_ID_NXP_IW61X_BASE 0x0204 #define SDIO_DEVICE_ID_NXP_IW61X 0x0205 +#define SDIO_DEVICE_ID_NXP_IW610 0x0215 #define SDIO_VENDOR_ID_REALTEK 0x024c #define SDIO_DEVICE_ID_REALTEK_RTW8723BS 0xb723 From e477a2aa1ad5a8a911d4b5488adf5943be369216 Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Tue, 8 Sep 2026 17:37:56 +0800 Subject: [PATCH 0883/2126] mmc: core: add NXP IW610 base ID and block size quirk The NXP IW610 SDIO chipset identifies itself with a base card ID (0x0214) during the initial MMC bus scan, whereas the WLAN function reports a different ID (0x0215). Like the IW61x, the IW610 requires MMC_QUIRK_BLKSZ_FOR_BYTE_MODE for correct byte-mode block size handling. Since SDIO fixups are applied before function devices are enumerated, the quirk must be associated with the base card ID rather than the WLAN function ID. Add the SDIO_DEVICE_ID_NXP_IW610_BASE definition and apply the required fixup in the SDIO quirk table. Signed-off-by: Jeff Chen Acked-by: Ulf Hansson --- drivers/mmc/core/quirks.h | 3 +++ include/linux/mmc/sdio_ids.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h index ae3ece89d0aa..98cb680e3ace 100644 --- a/drivers/mmc/core/quirks.h +++ b/drivers/mmc/core/quirks.h @@ -211,6 +211,9 @@ static const struct mmc_fixup __maybe_unused sdio_fixup_methods[] = { SDIO_FIXUP(SDIO_VENDOR_ID_NXP, SDIO_DEVICE_ID_NXP_IW61X_BASE, add_quirk, MMC_QUIRK_BLKSZ_FOR_BYTE_MODE), + SDIO_FIXUP(SDIO_VENDOR_ID_NXP, SDIO_DEVICE_ID_NXP_IW610_BASE, + add_quirk, MMC_QUIRK_BLKSZ_FOR_BYTE_MODE), + END_FIXUP }; diff --git a/include/linux/mmc/sdio_ids.h b/include/linux/mmc/sdio_ids.h index 5eff5e348eb0..dfffda3d8002 100644 --- a/include/linux/mmc/sdio_ids.h +++ b/include/linux/mmc/sdio_ids.h @@ -123,6 +123,7 @@ #define SDIO_VENDOR_ID_NXP 0x0471 #define SDIO_DEVICE_ID_NXP_IW61X_BASE 0x0204 #define SDIO_DEVICE_ID_NXP_IW61X 0x0205 +#define SDIO_DEVICE_ID_NXP_IW610_BASE 0x0214 #define SDIO_DEVICE_ID_NXP_IW610 0x0215 #define SDIO_VENDOR_ID_REALTEK 0x024c From de488b65b9120dad3a363858a0ab5beacc88752d Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Tue, 8 Sep 2026 17:37:57 +0800 Subject: [PATCH 0884/2126] wifi: nxpwifi: Add support for SDIO-based IW610 Add the IW610 SDIO device ID to the supported device table. This enables driver probing, interface initialization, and firmware download for the NXP IW610 wireless chipset. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/sdio.c | 16 ++++++++++++++++ drivers/net/wireless/nxp/nxpwifi/sdio.h | 1 + 2 files changed, 17 insertions(+) diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.c b/drivers/net/wireless/nxp/nxpwifi/sdio.c index 8ef0f6eb49e2..f4de494bf2f2 100644 --- a/drivers/net/wireless/nxp/nxpwifi/sdio.c +++ b/drivers/net/wireless/nxp/nxpwifi/sdio.c @@ -96,6 +96,19 @@ static const struct nxpwifi_sdio_device nxpwifi_sdio_iw61x = { .can_ext_scan = true, }; +static const struct nxpwifi_sdio_device nxpwifi_sdio_iw610 = { + .firmware = IW610_SDIO_FW_NAME, + .reg = &nxpwifi_reg_iw61x, + .max_ports = 32, + .mp_agg_pkt_limit = 16, + .tx_buf_size = NXPWIFI_TX_DATA_BUF_SIZE_4K, + .mp_tx_agg_buf_size = NXPWIFI_MP_AGGR_BSIZE_MAX, + .mp_rx_agg_buf_size = NXPWIFI_MP_AGGR_BSIZE_MAX, + .can_dump_fw = true, + .fw_dump_enh = true, + .can_ext_scan = true, +}; + static struct memory_type_mapping generic_mem_type_map[] = { {"DUMP", NULL, 0, 0xDD}, }; @@ -458,6 +471,8 @@ static void nxpwifi_sdio_coredump(struct device *dev) static const struct sdio_device_id nxpwifi_ids[] = { {SDIO_DEVICE(SDIO_VENDOR_ID_NXP, SDIO_DEVICE_ID_NXP_IW61X), .driver_data = (unsigned long)&nxpwifi_sdio_iw61x}, + {SDIO_DEVICE(SDIO_VENDOR_ID_NXP, SDIO_DEVICE_ID_NXP_IW610), + .driver_data = (unsigned long)&nxpwifi_sdio_iw610}, {}, }; @@ -2326,3 +2341,4 @@ MODULE_DESCRIPTION("NXP WiFi SDIO Driver version " SDIO_VERSION); MODULE_VERSION(SDIO_VERSION); MODULE_LICENSE("GPL"); MODULE_FIRMWARE(IW61X_SDIO_FW_NAME); +MODULE_FIRMWARE(IW610_SDIO_FW_NAME); diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.h b/drivers/net/wireless/nxp/nxpwifi/sdio.h index de5c884a5b14..e9881448fe2f 100644 --- a/drivers/net/wireless/nxp/nxpwifi/sdio.h +++ b/drivers/net/wireless/nxp/nxpwifi/sdio.h @@ -11,6 +11,7 @@ #include "main.h" #define IW61X_SDIO_FW_NAME "nxp/sd_w61x_v1.bin.se" +#define IW610_SDIO_FW_NAME "nxp/sd_iw610.bin.se" #define BLOCK_MODE 1 #define BYTE_MODE 0 From 952a5d152fe2ecb994b9acc22f984cc23d6aed14 Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Tue, 8 Sep 2026 17:37:58 +0800 Subject: [PATCH 0885/2126] wifi: nxpwifi: Limit channel width based on firmware capability nxpwifi_cmd_append_11n_tlv() derived the channel width solely from the AP's advertised operating bandwidth and could request 40/80 MHz operation even when the firmware did not support it. On 20 MHz-only devices such as IW610, this may cause the firmware to be configured with an unsupported channel width. Check firmware bandwidth capabilities before selecting the channel width: - Allow 80 MHz only when ISSUPP_NO_80MHZ() is false. - Allow 40 MHz only when ISSUPP_40MHZ_ENABLED() is true. - Otherwise fall back to 20 MHz operation. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/11n.c | 4 +++- drivers/net/wireless/nxp/nxpwifi/fw.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/11n.c b/drivers/net/wireless/nxp/nxpwifi/11n.c index c2a54d781b42..a83e29ecc466 100644 --- a/drivers/net/wireless/nxp/nxpwifi/11n.c +++ b/drivers/net/wireless/nxp/nxpwifi/11n.c @@ -349,6 +349,7 @@ nxpwifi_cmd_append_11n_tlv(struct nxpwifi_private *priv, nxpwifi_band_to_radio_type((u8)bss_desc->bss_band); if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) && + !ISSUPP_NO_80MHZ(priv->adapter->fw_cap_ext) && bss_desc->bcn_vht_oper && bss_desc->bcn_vht_oper->chan_width == IEEE80211_VHT_CHANWIDTH_80MHZ) { @@ -359,7 +360,8 @@ nxpwifi_cmd_append_11n_tlv(struct nxpwifi_private *priv, ((CHAN_BW_80MHZ << BAND_CFG_CHAN_WIDTH_SHIFT_BIT) & BAND_CFG_CHAN_WIDTH_MASK); - } else if (sband->ht_cap.cap & + } else if (ISSUPP_40MHZ_ENABLED(priv->adapter->fw_cap_ext) && + sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && bss_desc->bcn_ht_oper->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) { diff --git a/drivers/net/wireless/nxp/nxpwifi/fw.h b/drivers/net/wireless/nxp/nxpwifi/fw.h index 188110b020cf..124728a72442 100644 --- a/drivers/net/wireless/nxp/nxpwifi/fw.h +++ b/drivers/net/wireless/nxp/nxpwifi/fw.h @@ -334,6 +334,8 @@ enum NXPWIFI_802_11_PRIVACY_FILTER { #define DFS_CHAN_MOVE_TIME 10000 #define ISSUPP_11AXENABLED(fw_cap_ext) ((fw_cap_ext) & BIT(7)) +#define ISSUPP_NO_80MHZ(fw_cap_ext) ((fw_cap_ext) & BIT(8)) +#define ISSUPP_40MHZ_ENABLED(fw_cap_ext) ((fw_cap_ext) & BIT(15)) #define HOST_CMD_GET_HW_SPEC 0x0003 #define HOST_CMD_802_11_SCAN 0x0006 From f833415e49981bee131841e805da3f24b90a7524 Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Mon, 31 Aug 2026 15:52:26 +0800 Subject: [PATCH 0886/2126] wifi: nxpwifi: fix return value check in change_vif_to_sta/ap nxpwifi_change_vif_to_sta() and nxpwifi_change_vif_to_ap() both call nxpwifi_set_bss_mode() without storing the return value, then check 'if (ret)' which tests the stale value from the previous call. The 'if (ret) goto done' is therefore dead code, and errors from nxpwifi_set_bss_mode() are silently ignored. Fix this by assigning the return value to ret, so the existing error path works correctly. Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-wireless/anwqp-LuExbRshYu@stanley.mountain/ Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/cfg80211.c b/drivers/net/wireless/nxp/nxpwifi/cfg80211.c index 8805439c0b4b..eb394c4e05ab 100644 --- a/drivers/net/wireless/nxp/nxpwifi/cfg80211.c +++ b/drivers/net/wireless/nxp/nxpwifi/cfg80211.c @@ -847,8 +847,7 @@ nxpwifi_change_vif_to_sta(struct net_device *dev, update_vif_type_counter(adapter, type, 1); dev->ieee80211_ptr->iftype = type; - if (nxpwifi_set_bss_mode(priv)) - return -1; + ret = nxpwifi_set_bss_mode(priv); if (ret) goto done; @@ -891,8 +890,7 @@ nxpwifi_change_vif_to_ap(struct net_device *dev, update_vif_type_counter(adapter, type, 1); dev->ieee80211_ptr->iftype = type; - if (nxpwifi_set_bss_mode(priv)) - return -1; + ret = nxpwifi_set_bss_mode(priv); if (ret) goto done; From 3251a68930f83359f9a4c8b5bf45b5f1c983adb3 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:14 -0700 Subject: [PATCH 0887/2126] eth: mpnic: add scaffolding for Meta Platforms NIC MPNIC is the next network interface controller designed by Meta. Create a bare PCI driver for it. Subsequent changes will flesh it out. Registers live in BAR0 and are addressed as an array of 32 bit words, which is why the CSR indices are a quarter of the byte offset. Most of the register file is only accessible as 64 bit, so that is the only accessor added here. If a read returns all ones, a second read to an unused register with reset value 0 is performed to determine if the device is gone. If the device is gone, the mapped BAR0 pointer is cleared, so no further accesses reach the bus. For now, if mpnic_mmio_err() clears mpd->uc_addr0, nothing will reassign it. The user will have to unbind and rebind the driver. Future series will reset uc_addr0 from pci error handlers. In addition to being used as a 0 value reference CSR, MPNIC_BDQ_SPARE is also used to perform write flushes, because it can be read without producing side effects. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-1-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/Kconfig | 12 ++ drivers/net/ethernet/meta/Makefile | 1 + drivers/net/ethernet/meta/mpnic/Makefile | 12 ++ drivers/net/ethernet/meta/mpnic/mpnic.h | 40 ++++++ drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 24 ++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 147 ++++++++++++++++++++ 6 files changed, 236 insertions(+) create mode 100644 drivers/net/ethernet/meta/mpnic/Makefile create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic.h create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_csr.h create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_pci.c diff --git a/drivers/net/ethernet/meta/Kconfig b/drivers/net/ethernet/meta/Kconfig index ca5c7ac2a5bc..f940048a5e37 100644 --- a/drivers/net/ethernet/meta/Kconfig +++ b/drivers/net/ethernet/meta/Kconfig @@ -35,4 +35,16 @@ config FBNIC To compile this driver as a module, choose M here. The module will be called fbnic. MSI-X interrupt support is required. +config MPNIC + tristate "Meta Platforms Network Interface Controller" + depends on 64BIT || COMPILE_TEST + depends on !S390 + depends on PCI_MSI + help + This driver supports the Meta Platforms Network Interface + Controller. + + To compile this driver as a module, choose M here. The module + will be called mpnic. + endif # NET_VENDOR_META diff --git a/drivers/net/ethernet/meta/Makefile b/drivers/net/ethernet/meta/Makefile index 88804f3de963..633973419c21 100644 --- a/drivers/net/ethernet/meta/Makefile +++ b/drivers/net/ethernet/meta/Makefile @@ -4,3 +4,4 @@ # obj-$(CONFIG_FBNIC) += fbnic/ +obj-$(CONFIG_MPNIC) += mpnic/ diff --git a/drivers/net/ethernet/meta/mpnic/Makefile b/drivers/net/ethernet/meta/mpnic/Makefile new file mode 100644 index 000000000000..2588f1f1f1d5 --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) Meta Platforms, Inc. and affiliates. + +# +# Makefile for the Meta(R) Platforms Network Interface Controller +# + +obj-$(CONFIG_MPNIC) += mpnic.o + +mpnic-y := \ + mpnic_pci.o \ +# End of mpnic-y diff --git a/drivers/net/ethernet/meta/mpnic/mpnic.h b/drivers/net/ethernet/meta/mpnic/mpnic.h new file mode 100644 index 000000000000..6b8bee93033a --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_H_ +#define _MPNIC_H_ + +#include +#include + +#include "mpnic_csr.h" + +#define MPNIC_DRV_NAME "mpnic" + +struct mpnic_dev { + struct device *dev; + + u32 __iomem *uc_addr0; +}; + +u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg); + +static inline void mpnic_wr64(struct mpnic_dev *mpd, u32 reg, u64 val) +{ + u32 __iomem *csr = READ_ONCE(mpd->uc_addr0); + + if (csr) + writeq(val, csr + reg); +} + +static inline void mpnic_wrfl(struct mpnic_dev *mpd) +{ + mpnic_rd64(mpd, MPNIC_BDQ_SPARE); +} + +static inline bool mpnic_present(struct mpnic_dev *mpd) +{ + return !!READ_ONCE(mpd->uc_addr0); +} + +#endif /* _MPNIC_H_ */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h new file mode 100644 index 000000000000..473a2e9f5a09 --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_CSR_H_ +#define _MPNIC_CSR_H_ + +#include + +#define CSR_BIT(nr) BIT_ULL(nr) +#define CSR_GENMASK(h, l) GENMASK_ULL(h, l) + +/* Register Definitions + * + * The register file is addressed as an array of le32, so the byte address of + * a register is 4 times the index below. Each register is listed with its + * name, index and byte address. + * + * Name Index Address + *****************************************************************************/ + +/* NIC_CORE_RBP_HP_GLBL */ +#define MPNIC_BDQ_SPARE 0x42013e /* 0x10804f8 */ + +#endif /* _MPNIC_CSR_H_ */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file mode 100644 index 000000000000..96393e781241 --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include +#include +#include + +#include "mpnic.h" + +#define PCI_DEVICE_ID_META_MPNIC 0x0014 + +static void mpnic_mmio_err(struct mpnic_dev *mpd, u32 reg) +{ + /* Hardware is giving us all 1's reads, assume it is gone */ + WRITE_ONCE(mpd->uc_addr0, NULL); + + dev_err(mpd->dev, + "Failed read (idx 0x%x AKA addr 0x%x), disabled CSR access, awaiting reset\n", + reg, reg << 2); +} + +u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg) +{ + u32 __iomem *csr = READ_ONCE(mpd->uc_addr0); + u64 value; + + if (!csr) + return ~0ULL; + + value = readq(csr + reg); + + /* If any bits are 0 value should be valid */ + if (~value) + return value; + + /* All ones can be a valid value, so confirm against a register + * which never reads that way on a live device. + */ + if (reg != MPNIC_BDQ_SPARE && ~readq(csr + MPNIC_BDQ_SPARE)) + return value; + + mpnic_mmio_err(mpd, reg); + + return ~0ULL; +} + +static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev) +{ + struct mpnic_dev *mpd; + + mpd = kzalloc_obj(*mpd); + if (!mpd) + return NULL; + + pci_set_drvdata(pdev, mpd); + mpd->dev = &pdev->dev; + + return mpd; +} + +/** + * mpnic_probe - Device initialization routine + * @pdev: PCI device information struct + * @ent: entry in mpnic_pci_tbl + * + * Return: 0 on success, negative on failure + **/ +static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +{ + void __iomem *uc_addr0; + struct mpnic_dev *mpd; + int err; + + if (pdev->error_state != pci_channel_io_normal) { + dev_err(&pdev->dev, + "PCI device still in an error state. Unable to load...\n"); + return -EIO; + } + + err = pcim_enable_device(pdev); + if (err) { + dev_err(&pdev->dev, "PCI enable device failed: %d\n", err); + return err; + } + + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(46)); + if (err) { + dev_err(&pdev->dev, "DMA configuration failed: %d\n", err); + return err; + } + + mpd = mpnic_alloc(pdev); + if (!mpd) + return -ENOMEM; + + uc_addr0 = pcim_iomap_region(pdev, 0, MPNIC_DRV_NAME); + if (IS_ERR(uc_addr0)) { + err = PTR_ERR(uc_addr0); + dev_err(&pdev->dev, "Mapping the register file failed: %d\n", + err); + goto err_free_mpd; + } + mpd->uc_addr0 = uc_addr0; + + pci_set_master(pdev); + pci_save_state(pdev); + + return 0; + +err_free_mpd: + kfree(mpd); + + return err; +} + +/** + * mpnic_remove - Device removal routine + * @pdev: PCI device information struct + **/ +static void mpnic_remove(struct pci_dev *pdev) +{ + struct mpnic_dev *mpd = pci_get_drvdata(pdev); + + kfree(mpd); +} + +static const struct pci_device_id mpnic_pci_tbl[] = { + { PCI_VDEVICE(META, PCI_DEVICE_ID_META_MPNIC) }, + /* required last entry */ + {} +}; +MODULE_DEVICE_TABLE(pci, mpnic_pci_tbl); + +static struct pci_driver mpnic_driver = { + .name = MPNIC_DRV_NAME, + .id_table = mpnic_pci_tbl, + .probe = mpnic_probe, + .remove = mpnic_remove, +}; + +module_pci_driver(mpnic_driver); + +MODULE_DESCRIPTION("Meta Platforms Network Interface Controller"); +MODULE_LICENSE("GPL"); From cda700bcb2367da673fad182b00427ac9ae158a3 Mon Sep 17 00:00:00 2001 From: Mohsin Bashir Date: Thu, 24 Sep 2026 17:35:15 -0700 Subject: [PATCH 0888/2126] eth: mpnic: add register init for the device Perform one time register initialization during mpnic_probe(). These CSR settings are either static configs that only need to be set once, or pulses for zeroizing on chip SRAMs, which also only need to be done once. This initialization is idempotent and does not require any matching deinitialization in the remove path. We can unbind and re-bind the driver and perform the same initialization without problems. Signed-off-by: Mohsin Bashir Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-2-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 9 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 163 ++++++ drivers/net/ethernet/meta/mpnic/mpnic_init.c | 556 +++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 8 + 5 files changed, 737 insertions(+) create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_init.c diff --git a/drivers/net/ethernet/meta/mpnic/Makefile b/drivers/net/ethernet/meta/mpnic/Makefile index 2588f1f1f1d5..9dcaa1c72605 100644 --- a/drivers/net/ethernet/meta/mpnic/Makefile +++ b/drivers/net/ethernet/meta/mpnic/Makefile @@ -8,5 +8,6 @@ obj-$(CONFIG_MPNIC) += mpnic.o mpnic-y := \ + mpnic_init.o \ mpnic_pci.o \ # End of mpnic-y diff --git a/drivers/net/ethernet/meta/mpnic/mpnic.h b/drivers/net/ethernet/meta/mpnic/mpnic.h index 6b8bee93033a..67d48b7ce315 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic.h @@ -11,14 +11,23 @@ #define MPNIC_DRV_NAME "mpnic" +#define MPNIC_MAX_TXQS 1024u +#define MPNIC_MAX_RXQS 1024u + struct mpnic_dev { struct device *dev; u32 __iomem *uc_addr0; + + u32 mps; + u32 readrq; + u8 relaxed_ord; }; u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg); +int mpnic_dev_init(struct mpnic_dev *mpd); + static inline void mpnic_wr64(struct mpnic_dev *mpd, u32 reg, u64 val) { u32 __iomem *csr = READ_ONCE(mpd->uc_addr0); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h index 473a2e9f5a09..3ddd6acea085 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -9,6 +9,16 @@ #define CSR_BIT(nr) BIT_ULL(nr) #define CSR_GENMASK(h, l) GENMASK_ULL(h, l) +#define DESC_BIT(nr) BIT_ULL(nr) +#define DESC_GENMASK(h, l) GENMASK_ULL(h, l) + +/* Transmit Work Descriptor Format */ +#define MPNIC_TWD_FLAG_REQ_COMPLETION DESC_BIT(37) + +/* Common fields for all DESC_CFG CSRs */ +#define MPNIC_DESC_CFG_NUM_DESCS CSR_GENMASK(2, 0) +#define MPNIC_DESC_CFG_START_ADDR CSR_GENMASK(19, 8) + /* Register Definitions * * The register file is addressed as an array of le32, so the byte address of @@ -19,6 +29,159 @@ *****************************************************************************/ /* NIC_CORE_RBP_HP_GLBL */ +#define MPNIC_BDQ_GLBL_CTL0 0x420080 /* 0x1080200 */ +#define MPNIC_BDQ_GLBL_CTL0_MAX_REQ_SIZE CSR_GENMASK(26, 18) +#define MPNIC_BDQ_GLBL_CTL0_PREFETCH_SPACE_THRESH \ + CSR_GENMASK(42, 32) +#define MPNIC_RDE_CTL 0x420082 /* 0x1080208 */ +#define MPNIC_RDE_CTL_HPQ_DROP_THRESHOLD CSR_GENMASK(10, 0) +#define MPNIC_RDE_CTL_PPQ_DROP_THRESHOLD CSR_GENMASK(21, 11) +#define MPNIC_RDE_CTL_HPQ_LOCAL_DROP_THRESHOLD CSR_GENMASK(42, 32) +#define MPNIC_RDE_CTL_PPQ_LOCAL_DROP_THRESHOLD CSR_GENMASK(53, 43) +#define MPNIC_BDQ_MEM_INIT_REQ 0x42013a /* 0x10804e8 */ +#define MPNIC_BDQ_MEM_INIT_DONE 0x42013c /* 0x10804f0 */ #define MPNIC_BDQ_SPARE 0x42013e /* 0x10804f8 */ +#define MPNIC_HPQ_DESC_CFG(i) (0x420140 + 2 * (i)) /* 0x1080500 */ +#define MPNIC_PPQ_DESC_CFG(i) (0x420940 + 2 * (i)) /* 0x1082500 */ + +/* NIC_CORE_RDE_GLBL */ +#define MPNIC_RDE_MEM_INIT_REQ 0x4240e6 /* 0x1090398 */ +#define MPNIC_RDE_MEM_INIT_DONE 0x4240e8 /* 0x10903a0 */ + +/* NIC_CORE_RCM_GLBL */ +#define MPNIC_RCM_MEM_INIT_REQ 0x42507e /* 0x10941f8 */ +#define MPNIC_RCM_MEM_INIT_DONE 0x425080 /* 0x1094200 */ + +/* NIC_CORE_RNI_GLBL */ +#define MPNIC_RNI_RBP_CTL 0x427000 /* 0x109c000 */ +#define MPNIC_RNI_RDE_CTL 0x427002 /* 0x109c008 */ +#define MPNIC_RNI_RDE_CTL_MPS CSR_GENMASK(1, 0) +#define MPNIC_RNI_RDE_CTL_CLS CSR_GENMASK(3, 2) +#define MPNIC_RNI_RCM_CTL 0x427004 /* 0x109c010 */ + +/* NIC_CORE_TDF_GLBL */ +#define MPNIC_TWQ_DEF_PRI_TWD 0x428082 /* 0x10a0208 */ +#define MPNIC_TDF_MEM_INIT_REQ 0x42813a /* 0x10a04e8 */ +#define MPNIC_TDF_MEM_INIT_DONE 0x42813c /* 0x10a04f0 */ +#define MPNIC_TDF_DESC_CFG(i) (0x428140 + 2 * (i)) /* 0x10a0500 */ + +/* NIC_CORE_TQS_GLBL */ +#define MPNIC_TQS_GLBL_CTL0 0x42a000 /* 0x10a8000 */ +#define MPNIC_TQS_GLBL_CTL0_TWD_ERROR_CHECK_EN CSR_BIT(2) +#define MPNIC_TQS_GLBL_P0_0 0x42a002 /* 0x10a8008 */ +#define MPNIC_TQS_GLBL_P0_0_TXB_MAX_CRDTS_0 CSR_GENMASK(63, 48) +#define MPNIC_TQS_GLBL_P0_1 0x42a004 /* 0x10a8010 */ +#define MPNIC_TQS_GLBL_BMC 0x42a012 /* 0x10a8048 */ +#define MPNIC_TQS_GLBL_BMC_TXB_MAX_CRDTS CSR_GENMASK(15, 0) +#define MPNIC_TQS_SLOWDOWN_CTL 0x42a026 /* 0x10a8098 */ +#define MPNIC_TQS_SLOWDOWN_CTL_ENABLE CSR_BIT(6) +#define MPNIC_TQS_MTU_CTL0 0x42a030 /* 0x10a80c0 */ +#define MPNIC_TQS_MTU_CTL1 0x42a032 /* 0x10a80c8 */ +#define MPNIC_TQS_SET_P0_MAP0(i) (0x42a082 + 2 * (i)) /* 0x10a8208 */ +#define MPNIC_TQS_SET_P0_MAP1(i) (0x42a092 + 2 * (i)) /* 0x10a8248 */ +#define MPNIC_TQS_GLBL_SHAPING 0x42a108 /* 0x10a8420 */ +#define MPNIC_TQS_GLBL_SHAPING_DISABLE CSR_BIT(0) +#define MPNIC_TQS_ARB_CTL 0x42a122 /* 0x10a8488 */ +#define MPNIC_TQS_ARB_CTL_SET_CRDT_BUCKET_EN CSR_BIT(9) +#define MPNIC_TQS_ARB_CTL_SET_IMM_DECR_EN CSR_BIT(8) +#define MPNIC_TQS_ARB_CTL_GROUP_CRDT_BUCKET_EN CSR_BIT(5) +#define MPNIC_TQS_ARB_CTL_GROUP_IMM_DECR_EN CSR_BIT(4) +#define MPNIC_TQS_ARB_CTL_QUEUE_CRDT_BUCKET_EN CSR_BIT(1) +#define MPNIC_TQS_ARB_CTL_QUEUE_IMM_DECR_EN CSR_BIT(0) +#define MPNIC_TQS_CEV_MIN_SCHED_THRESH_0 \ + 0x42a124 /* 0x10a8490 */ +#define MPNIC_TQS_CEV_MIN_SCHED_THRESH_0_QUEUE CSR_GENMASK(19, 0) +#define MPNIC_TQS_CEV_MIN_SCHED_THRESH_0_GROUP CSR_GENMASK(59, 32) +#define MPNIC_TQS_CEV_MIN_SCHED_THRESH_1 \ + 0x42a126 /* 0x10a8498 */ +#define MPNIC_TQS_CEV_MIN_SCHED_THRESH_1_SET CSR_GENMASK(27, 0) +#define MPNIC_TQS_CEV_MIN_SCHED_THRESH_1_PORT CSR_GENMASK(63, 32) +#define MPNIC_TQS_SRAM_INIT_CTL 0x42a128 /* 0x10a84a0 */ +#define MPNIC_TQS_SRAM_INIT_CTL_QUANTUM CSR_GENMASK(31, 20) +#define MPNIC_TQS_SRAM_INIT_CTL_INIT CSR_BIT(32) +#define MPNIC_TQS_GROUP_INIT_CTL 0x42a12a /* 0x10a84a8 */ +#define MPNIC_TQS_GROUP_INIT_CTL_QUANTUM CSR_GENMASK(51, 32) +#define MPNIC_TQS_GROUP_INIT_CTL_INIT CSR_BIT(52) +#define MPNIC_TQS_SET_INIT_CTL 0x42a12c /* 0x10a84b0 */ +#define MPNIC_TQS_SET_INIT_CTL_QUANTUM CSR_GENMASK(51, 32) +#define MPNIC_TQS_SET_INIT_CTL_INIT CSR_BIT(52) +#define MPNIC_TQS_PORT_INIT_CTL 0x42a12e /* 0x10a84b8 */ +#define MPNIC_TQS_PORT_INIT_CTL_QUANTUM CSR_GENMASK(55, 32) +#define MPNIC_TQS_PORT_INIT_CTL_INIT CSR_BIT(56) +#define MPNIC_TQS_SRAM_STS 0x42a130 /* 0x10a84c0 */ +#define MPNIC_TQS_PORT_CTL(i) (0x42a1e4 + 2 * (i)) /* 0x10a8790 */ + +/* NIC_CORE_TDE_GLBL */ +#define MPNIC_TDE_MEM_INIT_REQ 0x42b1ee /* 0x10ac7b8 */ +#define MPNIC_TDE_MEM_INIT_DONE 0x42b1f0 /* 0x10ac7c0 */ + +/* NIC_CORE_TCM_GLBL */ +#define MPNIC_TCM_MEM_INIT_REQ 0x42c0be /* 0x10b02f8 */ +#define MPNIC_TCM_MEM_INIT_DONE 0x42c0c0 /* 0x10b0300 */ + +/* NIC_CORE_TNI_GLBL */ +#define MPNIC_TNI_GLBL_TDF_CTL 0x42e000 /* 0x10b8000 */ +#define MPNIC_TNI_GLBL_TDF_CTL_MRRS CSR_GENMASK(2, 0) +#define MPNIC_TNI_GLBL_TDF_CTL_CLS CSR_GENMASK(5, 3) +#define MPNIC_TNI_GLBL_TDE_CTL 0x42e002 /* 0x10b8008 */ +#define MPNIC_TNI_GLBL_TCM_CTL 0x42e004 /* 0x10b8010 */ + +/* NIC_CORE_TXB */ +#define MPNIC_TXB_PORT_CONFIG 0x600000 /* 0x1800000 */ +#define MPNIC_TXB_PORT_CONFIG_PORT_MODE CSR_GENMASK(15, 13) +#define MPNIC_TXB_BMC 0x600122 /* 0x1800488 */ +#define MPNIC_TXB_P0(i) (0x600124 + 2 * (i)) /* 0x1800490 */ +#define MPNIC_TXB_P0_CNT 17 +#define MPNIC_TXB_P0_THRESH(i) (0x60025e + 2 * (i)) /* 0x1800978 */ +#define MPNIC_TXB_P0_ARB_WEIGHTS(i) (0x600378 + 2 * (i)) /* 0x1800de0 */ + +/* NIC_CORE_RXB */ +#define MPNIC_RXB_MEM_INIT_REQ 0x620002 /* 0x1880008 */ +#define MPNIC_RXB_MEM_INIT_DONE 0x620004 /* 0x1880010 */ +#define MPNIC_RXB_PORT_CFG(i) (0x620006 + 2 * (i)) /* 0x1880018 */ +#define MPNIC_RXB_PORT_CFG_FCS_STRIP_MODE CSR_GENMASK(22, 22) +enum { + MPNIC_FCS_MODE_KEEP = 0, + MPNIC_FCS_MODE_STRIP = 1, +}; + +#define MPNIC_RXB_PORT_CLASS_CFG(i) (0x620020 + 2 * (i)) /* 0x1880080 */ +#define MPNIC_RXB_PORT_CLASS_CFG_DEFAULT_L2_ACTION \ + CSR_GENMASK(0, 0) +enum { + MPNIC_L2_ACTION_DROP = 0, + MPNIC_L2_ACTION_PASS = 1, +}; + +#define MPNIC_RXB_TC_CRDTS(i) (0x620418 + 2 * (i)) /* 0x1881060 */ +#define MPNIC_RXB_POOL_COMMON_CRDTS(i) (0x620458 + 2 * (i)) /* 0x1881160 */ +#define MPNIC_RXB_COMMON_CRDT_CTRL_TC(i) \ + (0x620472 + 2 * (i)) /* 0x18811c8 */ +#define MPNIC_RXB_COMMON_CRDT_CTRL_TC_THRESH CSR_GENMASK(15, 0) +#define MPNIC_RXB_COMMON_CRDT_CTRL_TC_TC_EN CSR_BIT(29) +#define MPNIC_RXB_COMMON_CRDT_CTRL_TC_MAX_CRDTS CSR_GENMASK(47, 32) +#define MPNIC_RXB_HOST_DROP_THRESH(i) (0x6205b0 + 2 * (i)) /* 0x18816c0 */ +#define MPNIC_RXB_BMC_CRDTS(i) (0x6205d0 + 2 * (i)) /* 0x1881740 */ + +/* NIC_CORE_RPC */ +#define MPNIC_RPC_MEM_INIT_REQ 0x780440 /* 0x1e01100 */ +#define MPNIC_RPC_MEM_INIT_DONE 0x780442 /* 0x1e01108 */ + +/* NIC_CORE_ROF */ +#define MPNIC_RSC_GLOBAL_CONF 0x7e2002 /* 0x1f88008 */ +#define MPNIC_RSC_GLOBAL_CONF_RSC_DISABLE CSR_BIT(0) + +/* NIC_CORE_TOF */ +#define MPNIC_TOF_TCAM_DEST_REMAP 0x7e3022 /* 0x1f8c088 */ + +/* PEMO_WRAPPER */ +#define MPNIC_OB_ATTR_RO CSR_BIT(1) +#define MPNIC_OB_ATTR_TDE_H 0x9a000e /* 0x2680038 */ +#define MPNIC_OB_ATTR_TDE_P 0x9a0010 /* 0x2680040 */ +#define MPNIC_OB_ATTR_TDF 0x9a0012 /* 0x2680048 */ +#define MPNIC_OB_ATTR_RBP_HPQ 0x9a0014 /* 0x2680050 */ +#define MPNIC_OB_ATTR_RBP_PPQ 0x9a0016 /* 0x2680058 */ +#define MPNIC_OB_ATTR_RDE_H 0x9a0018 /* 0x2680060 */ +#define MPNIC_OB_ATTR_RDE_P 0x9a001a /* 0x2680068 */ #endif /* _MPNIC_CSR_H_ */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_init.c b/drivers/net/ethernet/meta/mpnic/mpnic_init.c new file mode 100644 index 000000000000..2daed458f5fc --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_init.c @@ -0,0 +1,556 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include +#include +#include +#include + +#include "mpnic.h" + +#define MPNIC_MEM_INIT_POLL_US 500 +#define MPNIC_MEM_INIT_TO_US 5000 + +/* BDQ mem init: + * bit 1: fifo_wrptr_mem + * bit 0: fifo_rdptr_mem + */ +#define MPNIC_MEM_INIT_BDQ_VAL 0x3 + +/* RCM mem init: + * bit 3: cq_base_addr + * bit 2: cd_fifo_rptr_stats + * bit 1: cd_fifo_wptr_stats + * bit 0: cq_head_ptr_stats + */ +#define MPNIC_MEM_INIT_RCM_VAL 0xf + +/* RDE mem init, bits 0-18. Bits 0-12 are the per-queue packet, error and + * drop counters, bits 13-18 the two context memories of each of the HPQ, + * PPQ and SPQ descriptor prefetchers. + */ +#define MPNIC_MEM_INIT_RDE_VAL 0x7ffff + +/* RPC mem init, bit 0 covers the whole classifier. */ +#define MPNIC_MEM_INIT_RPC_VAL 0x1 + +/* TCM mem init: + * bit 3: cq_head_ptr_stats + * bit 2: cd_fifo_wptr_stats + * bit 1: cd_fifo_rptr_stats + * bit 0: cq_base_addr + */ +#define MPNIC_MEM_INIT_TCM_VAL 0xf + +/* TDE mem init: + * bit 1: stats mem + * bit 0: dma_head_ptr SRAM + */ +#define MPNIC_MEM_INIT_TDE_VAL 0x3 + +/* TDF mem init, bit 0 covers the descriptor fetch SRAM. */ +#define MPNIC_MEM_INIT_TDF_VAL 0x1 + +/* RXB mem init, bit 0 covers the DMAC TCAM statistics RAM. */ +#define MPNIC_MEM_INIT_RXB_VAL 0x1 + +/* TQS arbiter SRAM init done, one bit per DWRR level. */ +#define MPNIC_TQS_ARB_INIT_VAL 0xf + +/* On-chip SRAM allocated to each queue for descriptor fetch, in units of + * descriptors. Valid values are 64, 128, 256, 512 and 1024. + * + * The partition sizes are chosen for the maximum number of queues the + * device supports, so they do not have to be adjusted when the active + * queue count changes: + * + * BDQ: 1 MiB / (8 B/DESC) / (1024 HPQ + 1024 PPQ) = 64 DESC/QUEUE + * TWQ: 2 MiB / (8 B/DESC) / (1024 TXQ * 2 TWQ) = 128 DESC/QUEUE + */ +#define MPNIC_BDQ_SRAM_DESCS 64u +#define MPNIC_TDF_SRAM_DESCS 128u + +/* A total of 1 MiB worth of Tx credits is available, in units of 128 B. + * The BMC to MAC and host to BMC paths each get a guaranteed share of them + * whether or not anything is routed their way, everything else goes to + * MAC TC0. + */ +#define MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL 800 +#define MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL \ + (SZ_1M / 128 - 2 * MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL) + +/* The recommended lower bound for the TXB threshold is 80, based on a 10K + * MTU. Round up by 25% to stay on the defensive side. The same reasoning + * applies to the arbitration weight, which has to exceed the full packet + * size. + */ +#define MPNIC_TXB_INIT_BMC_THRESH 100 +#define MPNIC_TXB_INIT_P0_THRESH 100 +#define MPNIC_TXB_INIT_P0_ARB_WEIGHTS 0x64 + +/* RXB host drop threshold in units of 128 B beats. Packets targeting a + * queue are dropped when the available credits fall below it. 80 beats is + * 10 KB, which is also the largest frame the device is configured for. + */ +#define MPNIC_RXB_INIT_HOST_DROP_THRESH 0x50 + +/* A total of 8 MiB of Rx buffer is available. The recommended per-TC pool + * for a 800G configuration is 420 KB with all 8 TCs enabled. Only one TC + * is in use, so give it 8 * 420 KB (in units of 128 B) and push the rest + * to the common pool. Start drawing from the common pool as soon as the + * TC0 credits fall below one max sized frame. The BMC keeps a small + * reserve of its own whether or not the host talks to it. + */ +#define MPNIC_RXB_INIT_POOL_TC_CRDTS_P0 (0xd20 * 8) +#define MPNIC_RXB_INIT_BMC_CRDTS 0x20 +#define MPNIC_RXB_INIT_COMMON_CRDT_MAX_THRSH \ + (SZ_8M / 128 - MPNIC_RXB_INIT_POOL_TC_CRDTS_P0 - \ + MPNIC_RXB_INIT_BMC_CRDTS) +#define MPNIC_RXB_INIT_COMMON_CRDT_THRSH 0x50 + +/* TXB port mode selects the number of active MAC ports for Tx buffer + * credit distribution and arbitration. The hardware only supports single, + * dual and quad port, encoded as b'001, b'010 and b'100. + */ +#define MPNIC_TXB_PORT_MODE_SINGLE 1 + +/* The MAC traffic classes start at index 8 in the TXB arrays, the BMC + * sits above them. + */ +#define MPNIC_TXB_TC_IDX_MAC_0 8 +#define MPNIC_TXB_TC_IDX_BMC 16 + +/* Largest frame the Tx queue scheduler will pass through. Anything above + * it gets truncated. + */ +#define MPNIC_TQS_MTU_CTL0_MAX 0x2800 + +/* The unit of the DWRR quantum is 256 B. It has to be large enough for at + * least 11 MTUs to be transmitted in one quantum; use 15 for headroom. + */ +#define MPNIC_TQS_DWRR_INIT_QUANTUM (15 * MPNIC_TQS_MTU_CTL0_MAX / 256) + +/* Lower bound on the credit available to a queue, group, set or port + * before the scheduler stops issuing requests for it. 15 MTUs, matching + * the DWRR quantum above. + */ +#define MPNIC_TQS_DWRR_CEV_MIN_SCHED_THRESH (15 * MPNIC_TQS_MTU_CTL0_MAX) + +/* The TQS view of the TXB partitioning between the MAC and the BMC, in + * units of 1 KiB. It has to match the TXB private credits above. + */ +#define MPNIC_TQS_GLBL_TXB_CRDT_UNIT SZ_1K +#define MPNIC_TQS_GLBL_TXB_CRDT_BMC \ + (MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL * 128 / MPNIC_TQS_GLBL_TXB_CRDT_UNIT) +#define MPNIC_TQS_GLBL_TXB_CRDT_MAC \ + (MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL * 128 / \ + MPNIC_TQS_GLBL_TXB_CRDT_UNIT) + +struct mpnic_init_poll { + u64 exp_val; + u32 addr; +}; + +struct mpnic_poll_state { + int poll_idx; + u64 val; +}; + +static void mpnic_tdf_glbl_init(struct mpnic_dev *mpd) +{ + /* Default metadata descriptor, used for frames the driver did not + * prepend one to. + */ + mpnic_wr64(mpd, MPNIC_TWQ_DEF_PRI_TWD, MPNIC_TWD_FLAG_REQ_COMPLETION); +} + +static void mpnic_txb_init(struct mpnic_dev *mpd) +{ + int i; + + mpnic_wr64(mpd, MPNIC_TXB_BMC, MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL); + + /* Zero the private credits of every traffic class, then hand the + * unreserved ones to MAC TC0. + */ + for (i = 0; i < MPNIC_TXB_P0_CNT; i++) + mpnic_wr64(mpd, MPNIC_TXB_P0(i), 0); + mpnic_wr64(mpd, MPNIC_TXB_P0(MPNIC_TXB_TC_IDX_MAC_0), + MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL); + mpnic_wr64(mpd, MPNIC_TXB_P0(MPNIC_TXB_TC_IDX_BMC), + MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL); + + mpnic_wr64(mpd, MPNIC_TXB_P0_THRESH(MPNIC_TXB_TC_IDX_BMC), + MPNIC_TXB_INIT_BMC_THRESH); + + mpnic_wr64(mpd, MPNIC_TXB_P0_THRESH(MPNIC_TXB_TC_IDX_MAC_0), + MPNIC_TXB_INIT_P0_THRESH); + mpnic_wr64(mpd, MPNIC_TXB_P0_ARB_WEIGHTS(MPNIC_TXB_TC_IDX_MAC_0), + MPNIC_TXB_INIT_P0_ARB_WEIGHTS); + mpnic_wr64(mpd, MPNIC_TXB_PORT_CONFIG, + FIELD_PREP(MPNIC_TXB_PORT_CONFIG_PORT_MODE, + MPNIC_TXB_PORT_MODE_SINGLE)); +} + +static void mpnic_rxb_init(struct mpnic_dev *mpd) +{ + /* Accept all packets that miss dmac tcam, until l2 filtering is + * implemented. + */ + mpnic_wr64(mpd, MPNIC_RXB_PORT_CLASS_CFG(0), + FIELD_PREP(MPNIC_RXB_PORT_CLASS_CFG_DEFAULT_L2_ACTION, + MPNIC_L2_ACTION_PASS)); + mpnic_wr64(mpd, MPNIC_RXB_PORT_CFG(0), + FIELD_PREP(MPNIC_RXB_PORT_CFG_FCS_STRIP_MODE, + MPNIC_FCS_MODE_STRIP)); + + mpnic_wr64(mpd, MPNIC_RXB_HOST_DROP_THRESH(0), + MPNIC_RXB_INIT_HOST_DROP_THRESH); + + mpnic_wr64(mpd, MPNIC_RXB_TC_CRDTS(0), + MPNIC_RXB_INIT_POOL_TC_CRDTS_P0); + mpnic_wr64(mpd, MPNIC_RXB_COMMON_CRDT_CTRL_TC(0), + FIELD_PREP(MPNIC_RXB_COMMON_CRDT_CTRL_TC_THRESH, + MPNIC_RXB_INIT_COMMON_CRDT_THRSH) | + FIELD_PREP(MPNIC_RXB_COMMON_CRDT_CTRL_TC_MAX_CRDTS, + MPNIC_RXB_INIT_COMMON_CRDT_MAX_THRSH) | + MPNIC_RXB_COMMON_CRDT_CTRL_TC_TC_EN); + + /* Only pool 0 is used, it gets all of the common credits */ + mpnic_wr64(mpd, MPNIC_RXB_POOL_COMMON_CRDTS(0), + MPNIC_RXB_INIT_COMMON_CRDT_MAX_THRSH); + + mpnic_wr64(mpd, MPNIC_RXB_BMC_CRDTS(0), MPNIC_RXB_INIT_BMC_CRDTS); + + mpnic_wr64(mpd, MPNIC_RXB_MEM_INIT_REQ, MPNIC_MEM_INIT_RXB_VAL); +} + +static u64 mpnic_desc_cfg(unsigned int sram_descs, unsigned int q_idx) +{ + /* The hardware encodes the partition size as 64 * 2^n descriptors, + * and its start address in units of 64 descriptors. + */ + return FIELD_PREP(MPNIC_DESC_CFG_NUM_DESCS, __ffs(sram_descs) - 6) | + FIELD_PREP(MPNIC_DESC_CFG_START_ADDR, + q_idx * (sram_descs >> 6)); +} + +static void mpnic_desc_sram_init(struct mpnic_dev *mpd) +{ + int i; + + for (i = 0; i < MPNIC_MAX_TXQS * 2; i++) + mpnic_wr64(mpd, MPNIC_TDF_DESC_CFG(i), + mpnic_desc_cfg(MPNIC_TDF_SRAM_DESCS, i)); + + for (i = 0; i < MPNIC_MAX_RXQS; i++) { + mpnic_wr64(mpd, MPNIC_HPQ_DESC_CFG(i), + mpnic_desc_cfg(MPNIC_BDQ_SRAM_DESCS, i)); + mpnic_wr64(mpd, MPNIC_PPQ_DESC_CFG(i), + mpnic_desc_cfg(MPNIC_BDQ_SRAM_DESCS, + MPNIC_MAX_RXQS + i)); + } +} + +static void mpnic_rxglb_init(struct mpnic_dev *mpd) +{ + /* Descriptor prefetch reads are only issued once 32 descriptors + * worth of FIFO space is available, and no more than 64 descriptors + * are fetched for one queue at a time so that a single queue cannot + * monopolize the bus. Both have to be multiples of 16 to keep the + * reads 128 B aligned. + */ + mpnic_wr64(mpd, MPNIC_BDQ_GLBL_CTL0, + FIELD_PREP(MPNIC_BDQ_GLBL_CTL0_PREFETCH_SPACE_THRESH, 32) | + FIELD_PREP(MPNIC_BDQ_GLBL_CTL0_MAX_REQ_SIZE, 64)); + + /* Minimum number of descriptors which has to be available before + * the descriptor engine considers a queue usable, globally and in + * the per-queue prefetch FIFO. + */ + mpnic_wr64(mpd, MPNIC_RDE_CTL, + FIELD_PREP(MPNIC_RDE_CTL_HPQ_DROP_THRESHOLD, 16) | + FIELD_PREP(MPNIC_RDE_CTL_PPQ_DROP_THRESHOLD, 16) | + FIELD_PREP(MPNIC_RDE_CTL_HPQ_LOCAL_DROP_THRESHOLD, 16) | + FIELD_PREP(MPNIC_RDE_CTL_PPQ_LOCAL_DROP_THRESHOLD, 16)); + + /* Receive side coalescing is not supported yet */ + mpnic_wr64(mpd, MPNIC_RSC_GLOBAL_CONF, + MPNIC_RSC_GLOBAL_CONF_RSC_DISABLE); + + mpnic_wr64(mpd, MPNIC_BDQ_MEM_INIT_REQ, MPNIC_MEM_INIT_BDQ_VAL); + mpnic_wr64(mpd, MPNIC_RCM_MEM_INIT_REQ, MPNIC_MEM_INIT_RCM_VAL); + mpnic_wr64(mpd, MPNIC_RDE_MEM_INIT_REQ, MPNIC_MEM_INIT_RDE_VAL); + mpnic_wr64(mpd, MPNIC_RPC_MEM_INIT_REQ, MPNIC_MEM_INIT_RPC_VAL); +} + +static void mpnic_txglb_init(struct mpnic_dev *mpd) +{ + /* Nothing is redirected to the BMC until the Tx offload TCAM gets + * programmed with its addresses. + */ + mpnic_wr64(mpd, MPNIC_TOF_TCAM_DEST_REMAP, 0); + + mpnic_wr64(mpd, MPNIC_TCM_MEM_INIT_REQ, MPNIC_MEM_INIT_TCM_VAL); + mpnic_wr64(mpd, MPNIC_TDE_MEM_INIT_REQ, MPNIC_MEM_INIT_TDE_VAL); + mpnic_wr64(mpd, MPNIC_TDF_MEM_INIT_REQ, MPNIC_MEM_INIT_TDF_VAL); +} + +/* Fill the DWRR arbiter memories. Setting the INIT bit makes the hardware + * write the given credit and quantum into every entry at the queue, group, + * set and port level, so nothing has to be programmed per queue. + */ +static void mpnic_tqs_sram_init(struct mpnic_dev *mpd) +{ + mpnic_wr64(mpd, MPNIC_TQS_GROUP_INIT_CTL, + FIELD_PREP(MPNIC_TQS_GROUP_INIT_CTL_QUANTUM, + MPNIC_TQS_DWRR_INIT_QUANTUM) | + MPNIC_TQS_GROUP_INIT_CTL_INIT); + mpnic_wr64(mpd, MPNIC_TQS_SET_INIT_CTL, + FIELD_PREP(MPNIC_TQS_SET_INIT_CTL_QUANTUM, + MPNIC_TQS_DWRR_INIT_QUANTUM) | + MPNIC_TQS_SET_INIT_CTL_INIT); + mpnic_wr64(mpd, MPNIC_TQS_PORT_INIT_CTL, + FIELD_PREP(MPNIC_TQS_PORT_INIT_CTL_QUANTUM, + MPNIC_TQS_DWRR_INIT_QUANTUM) | + MPNIC_TQS_PORT_INIT_CTL_INIT); + mpnic_wr64(mpd, MPNIC_TQS_SRAM_INIT_CTL, + FIELD_PREP(MPNIC_TQS_SRAM_INIT_CTL_QUANTUM, + MPNIC_TQS_DWRR_INIT_QUANTUM) | + MPNIC_TQS_SRAM_INIT_CTL_INIT); +} + +static void mpnic_tqs_init(struct mpnic_dev *mpd) +{ + u64 val; + + /* Initialize to the largest frame we support, the scheduler + * truncates anything above it. The BMC gets the same limit. + */ + mpnic_wr64(mpd, MPNIC_TQS_MTU_CTL0, MPNIC_TQS_MTU_CTL0_MAX); + mpnic_wr64(mpd, MPNIC_TQS_MTU_CTL1, MPNIC_TQS_MTU_CTL0_MAX); + + mpnic_wr64(mpd, MPNIC_TQS_GLBL_CTL0, + MPNIC_TQS_GLBL_CTL0_TWD_ERROR_CHECK_EN); + + mpnic_tqs_sram_init(mpd); + + /* Only port 0 is used. A single traffic class is in use as well, so + * TC0 gets all of the Tx buffer credits not reserved for the BMC. + */ + mpnic_wr64(mpd, MPNIC_TQS_GLBL_P0_0, + FIELD_PREP(MPNIC_TQS_GLBL_P0_0_TXB_MAX_CRDTS_0, + MPNIC_TQS_GLBL_TXB_CRDT_MAC)); + mpnic_wr64(mpd, MPNIC_TQS_GLBL_P0_1, 0); + mpnic_wr64(mpd, MPNIC_TQS_GLBL_BMC, + FIELD_PREP(MPNIC_TQS_GLBL_BMC_TXB_MAX_CRDTS, + MPNIC_TQS_GLBL_TXB_CRDT_BMC)); + + mpnic_wr64(mpd, MPNIC_TQS_PORT_CTL(0), 0); + + /* Map all sets to port 0 */ + mpnic_wr64(mpd, MPNIC_TQS_SET_P0_MAP0(0), ~0ULL); + mpnic_wr64(mpd, MPNIC_TQS_SET_P0_MAP1(0), ~0ULL); + + mpnic_wr64(mpd, MPNIC_TQS_CEV_MIN_SCHED_THRESH_0, + FIELD_PREP(MPNIC_TQS_CEV_MIN_SCHED_THRESH_0_QUEUE, + MPNIC_TQS_DWRR_CEV_MIN_SCHED_THRESH) | + FIELD_PREP(MPNIC_TQS_CEV_MIN_SCHED_THRESH_0_GROUP, + MPNIC_TQS_DWRR_CEV_MIN_SCHED_THRESH)); + mpnic_wr64(mpd, MPNIC_TQS_CEV_MIN_SCHED_THRESH_1, + FIELD_PREP(MPNIC_TQS_CEV_MIN_SCHED_THRESH_1_SET, + MPNIC_TQS_DWRR_CEV_MIN_SCHED_THRESH) | + FIELD_PREP(MPNIC_TQS_CEV_MIN_SCHED_THRESH_1_PORT, + MPNIC_TQS_DWRR_CEV_MIN_SCHED_THRESH)); + + /* The rate limiters are left uninitialized, so shaping has to stay + * off or nothing would ever get scheduled. + */ + mpnic_wr64(mpd, MPNIC_TQS_GLBL_SHAPING, MPNIC_TQS_GLBL_SHAPING_DISABLE); + + /* Enable fairness protection (phantom eligibility). Read modify + * write so that the reset default slowdown cycle is preserved. + */ + val = mpnic_rd64(mpd, MPNIC_TQS_SLOWDOWN_CTL); + val |= MPNIC_TQS_SLOWDOWN_CTL_ENABLE; + mpnic_wr64(mpd, MPNIC_TQS_SLOWDOWN_CTL, val); + + /* Use immediate credit decrement at every DWRR level so that the + * credit reflects a grant in the same cycle. + */ + val = mpnic_rd64(mpd, MPNIC_TQS_ARB_CTL); + val |= MPNIC_TQS_ARB_CTL_SET_CRDT_BUCKET_EN | + MPNIC_TQS_ARB_CTL_SET_IMM_DECR_EN | + MPNIC_TQS_ARB_CTL_GROUP_CRDT_BUCKET_EN | + MPNIC_TQS_ARB_CTL_GROUP_IMM_DECR_EN | + MPNIC_TQS_ARB_CTL_QUEUE_CRDT_BUCKET_EN | + MPNIC_TQS_ARB_CTL_QUEUE_IMM_DECR_EN; + mpnic_wr64(mpd, MPNIC_TQS_ARB_CTL, val); +} + +/* The MPS and CLS fields sit at the same bit positions in every block, so + * one set of masks covers both the RNI and the TNI registers. + */ +static void mpnic_mps_init(struct mpnic_dev *mpd, u32 reg, unsigned int mps, + unsigned int cls) +{ + u64 val = mpnic_rd64(mpd, reg); + + val &= ~(MPNIC_RNI_RDE_CTL_MPS | MPNIC_RNI_RDE_CTL_CLS); + val |= FIELD_PREP(MPNIC_RNI_RDE_CTL_MPS, mps) | + FIELD_PREP(MPNIC_RNI_RDE_CTL_CLS, cls); + + mpnic_wr64(mpd, reg, val); +} + +/* Likewise for the MRRS and CLS fields, which have their own common + * layout. + */ +static void mpnic_mrrs_init(struct mpnic_dev *mpd, u32 reg, unsigned int mrrs, + unsigned int cls) +{ + u64 val = mpnic_rd64(mpd, reg); + + val &= ~(MPNIC_TNI_GLBL_TDF_CTL_MRRS | MPNIC_TNI_GLBL_TDF_CTL_CLS); + val |= FIELD_PREP(MPNIC_TNI_GLBL_TDF_CTL_MRRS, mrrs) | + FIELD_PREP(MPNIC_TNI_GLBL_TDF_CTL_CLS, cls); + + mpnic_wr64(mpd, reg, val); +} + +/** + * mpnic_axi_init - Configure AXI bus parameters from host PCIe capabilities + * @mpd: Device to configure + * + * Programs the max read request size, max payload size and cache line size + * of the DMA engines. The hardware encodes all three as a power of 2 index, + * MRRS and MPS relative to 128 B and CLS relative to 64 B. + * + * MAX_OT and MAX_OB are left at their hardware defaults. + */ +static void mpnic_axi_init(struct mpnic_dev *mpd) +{ + int mps, cls, mrrs; + + mps = clamp(ilog2(mpd->mps) - 7, 0, 3); + cls = clamp(ilog2(L1_CACHE_BYTES) - 6, 0, 3); + + mpnic_mps_init(mpd, MPNIC_RNI_RDE_CTL, mps, cls); + mpnic_mps_init(mpd, MPNIC_RNI_RCM_CTL, mps, cls); + mpnic_mps_init(mpd, MPNIC_TNI_GLBL_TCM_CTL, mps, cls); + + mrrs = clamp(ilog2(mpd->readrq) - 7, 0, 3); + mpnic_mrrs_init(mpd, MPNIC_RNI_RBP_CTL, mrrs, cls); + mpnic_mrrs_init(mpd, MPNIC_TNI_GLBL_TDF_CTL, mrrs, cls); + + /* TDE supports a wider range of MRRS encodings. */ + mrrs = clamp(ilog2(mpd->readrq) - 7, 0, 5); + mpnic_mrrs_init(mpd, MPNIC_TNI_GLBL_TDE_CTL, mrrs, cls); +} + +/** + * mpnic_ro_init - Set relaxed ordering on the outbound TLP attributes + * @mpd: Device to configure + * + * Completions must stay ordered so that they are not observed before the + * payload DMA they describe has landed, so RCM and TCM are left alone. + */ +static void mpnic_ro_init(struct mpnic_dev *mpd) +{ + u64 attr = mpd->relaxed_ord ? MPNIC_OB_ATTR_RO : 0; + + mpnic_wr64(mpd, MPNIC_OB_ATTR_TDE_H, attr); + mpnic_wr64(mpd, MPNIC_OB_ATTR_TDE_P, attr); + mpnic_wr64(mpd, MPNIC_OB_ATTR_TDF, attr); + mpnic_wr64(mpd, MPNIC_OB_ATTR_RBP_HPQ, attr); + mpnic_wr64(mpd, MPNIC_OB_ATTR_RBP_PPQ, attr); + mpnic_wr64(mpd, MPNIC_OB_ATTR_RDE_H, attr); + mpnic_wr64(mpd, MPNIC_OB_ATTR_RDE_P, attr); +} + +static bool mpnic_init_status_ready(struct mpnic_dev *mpd, + const struct mpnic_init_poll *polls, + struct mpnic_poll_state *state) +{ + u64 val; + int i; + + for (i = state->poll_idx; polls[i].addr; i++) { + val = mpnic_rd64(mpd, polls[i].addr); + + if ((val & polls[i].exp_val) != polls[i].exp_val) { + state->poll_idx = i; + state->val = val; + return false; + } + } + + return true; +} + +/** + * mpnic_mem_init_poll - Wait for the memory initializations to complete + * @mpd: Device to poll + * + * The blocks initialize their memories in parallel, so walk the status + * registers in order and only go back to sleep on the first one which is + * not done yet. + * + * Return: 0 on success, -ETIMEDOUT if not everything completed in time + */ +static int mpnic_mem_init_poll(struct mpnic_dev *mpd) +{ + static const struct mpnic_init_poll polls[] = { + { MPNIC_TQS_ARB_INIT_VAL, MPNIC_TQS_SRAM_STS }, + { MPNIC_MEM_INIT_BDQ_VAL, MPNIC_BDQ_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_RCM_VAL, MPNIC_RCM_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_RDE_VAL, MPNIC_RDE_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_RPC_VAL, MPNIC_RPC_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_TCM_VAL, MPNIC_TCM_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_TDE_VAL, MPNIC_TDE_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_TDF_VAL, MPNIC_TDF_MEM_INIT_DONE }, + { MPNIC_MEM_INIT_RXB_VAL, MPNIC_RXB_MEM_INIT_DONE }, + { 0 }, + }; + struct mpnic_poll_state state = {}; + bool done; + int err; + + err = read_poll_timeout(mpnic_init_status_ready, done, done, + MPNIC_MEM_INIT_POLL_US, MPNIC_MEM_INIT_TO_US, + false, mpd, polls, &state); + if (err) + dev_err(mpd->dev, "Poll timeout for reg 0x%x: 0x%llx\n", + polls[state.poll_idx].addr, state.val); + + return err; +} + +int mpnic_dev_init(struct mpnic_dev *mpd) +{ + int err; + + mpnic_tdf_glbl_init(mpd); + mpnic_txb_init(mpd); + mpnic_rxb_init(mpd); + mpnic_desc_sram_init(mpd); + mpnic_axi_init(mpd); + mpnic_ro_init(mpd); + mpnic_rxglb_init(mpd); + mpnic_txglb_init(mpd); + mpnic_tqs_init(mpd); + + err = mpnic_mem_init_poll(mpd); + if (err) { + dev_err(mpd->dev, "Device initialization failed: %d\n", err); + return err; + } + + if (!mpnic_present(mpd)) + return -EIO; + + return 0; +} diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c index 96393e781241..68a64377e6c5 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c @@ -58,6 +58,10 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev) pci_set_drvdata(pdev, mpd); mpd->dev = &pdev->dev; + mpd->mps = pcie_get_mps(pdev); + mpd->readrq = pcie_get_readrq(pdev); + mpd->relaxed_ord = pcie_relaxed_ordering_enabled(pdev); + return mpd; } @@ -108,6 +112,10 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); pci_save_state(pdev); + err = mpnic_dev_init(mpd); + if (err) + goto err_free_mpd; + return 0; err_free_mpd: From 2cf67a26922471bdd21aa1576a414f11a34992df Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:16 -0700 Subject: [PATCH 0889/2126] eth: mpnic: allocate MSI-X vectors Request one vector for FW generated interrupts and then one vector per CPU to use for the completion queues. Nothing requests a handler yet, that comes with the NAPI vectors. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-3-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 15 +++++ drivers/net/ethernet/meta/mpnic/mpnic_irq.c | 64 +++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 9 ++- 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_irq.c diff --git a/drivers/net/ethernet/meta/mpnic/Makefile b/drivers/net/ethernet/meta/mpnic/Makefile index 9dcaa1c72605..3aa7c6a5ab5e 100644 --- a/drivers/net/ethernet/meta/mpnic/Makefile +++ b/drivers/net/ethernet/meta/mpnic/Makefile @@ -9,5 +9,6 @@ obj-$(CONFIG_MPNIC) += mpnic.o mpnic-y := \ mpnic_init.o \ + mpnic_irq.o \ mpnic_pci.o \ # End of mpnic-y diff --git a/drivers/net/ethernet/meta/mpnic/mpnic.h b/drivers/net/ethernet/meta/mpnic/mpnic.h index 67d48b7ce315..628fd48c997d 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic.h @@ -4,6 +4,7 @@ #ifndef _MPNIC_H_ #define _MPNIC_H_ +#include #include #include @@ -14,11 +15,19 @@ #define MPNIC_MAX_TXQS 1024u #define MPNIC_MAX_RXQS 1024u +/* misc IRQ entries are allocated before the completion queue IRQs */ +enum { + MPNIC_FW_MSIX_ENTRY, + MPNIC_NON_NAPI_VECTORS +}; + struct mpnic_dev { struct device *dev; u32 __iomem *uc_addr0; + u16 num_irqs; + u32 mps; u32 readrq; u8 relaxed_ord; @@ -28,6 +37,12 @@ u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg); int mpnic_dev_init(struct mpnic_dev *mpd); +int mpnic_request_irq(struct mpnic_dev *mpd, int nr, irq_handler_t handler, + unsigned long flags, const char *name, void *data); +void mpnic_free_irq(struct mpnic_dev *mpd, int nr, void *data); +void mpnic_free_irqs(struct mpnic_dev *mpd); +int mpnic_alloc_irqs(struct mpnic_dev *mpd); + static inline void mpnic_wr64(struct mpnic_dev *mpd, u32 reg, u64 val) { u32 __iomem *csr = READ_ONCE(mpd->uc_addr0); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_irq.c b/drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file mode 100644 index 000000000000..bcc33655cbbe --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_irq.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include + +#include "mpnic.h" + +int mpnic_request_irq(struct mpnic_dev *mpd, int nr, irq_handler_t handler, + unsigned long flags, const char *name, void *data) +{ + struct pci_dev *pdev = to_pci_dev(mpd->dev); + int irq = pci_irq_vector(pdev, nr); + + if (irq < 0) + return irq; + + return request_irq(irq, handler, flags, name, data); +} + +void mpnic_free_irq(struct mpnic_dev *mpd, int nr, void *data) +{ + struct pci_dev *pdev = to_pci_dev(mpd->dev); + int irq = pci_irq_vector(pdev, nr); + + if (irq < 0) + return; + + free_irq(irq, data); +} + +void mpnic_free_irqs(struct mpnic_dev *mpd) +{ + struct pci_dev *pdev = to_pci_dev(mpd->dev); + + mpd->num_irqs = 0; + pci_free_irq_vectors(pdev); +} + +int mpnic_alloc_irqs(struct mpnic_dev *mpd) +{ + unsigned int wanted_irqs = MPNIC_NON_NAPI_VECTORS; + struct pci_dev *pdev = to_pci_dev(mpd->dev); + int num_irqs; + + wanted_irqs += min_t(unsigned int, num_online_cpus(), MPNIC_MAX_RXQS); + num_irqs = pci_alloc_irq_vectors(pdev, MPNIC_NON_NAPI_VECTORS + 1, + wanted_irqs, PCI_IRQ_MSIX); + if (num_irqs < 0) { + dev_err(mpd->dev, "Failed to allocate MSI-X entries: %d\n", + num_irqs); + return num_irqs; + } + + if (num_irqs < wanted_irqs) + dev_warn(mpd->dev, "Allocated %d IRQs, expected %u\n", + num_irqs, wanted_irqs); + + mpd->num_irqs = num_irqs; + + return 0; +} diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c index 68a64377e6c5..127b71b44b0f 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c @@ -112,12 +112,18 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); pci_save_state(pdev); - err = mpnic_dev_init(mpd); + err = mpnic_alloc_irqs(mpd); if (err) goto err_free_mpd; + err = mpnic_dev_init(mpd); + if (err) + goto err_free_irqs; + return 0; +err_free_irqs: + mpnic_free_irqs(mpd); err_free_mpd: kfree(mpd); @@ -132,6 +138,7 @@ static void mpnic_remove(struct pci_dev *pdev) { struct mpnic_dev *mpd = pci_get_drvdata(pdev); + mpnic_free_irqs(mpd); kfree(mpd); } From 3d4e4ad43aa455353067cf004d0618009ac39205 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:17 -0700 Subject: [PATCH 0890/2126] eth: mpnic: implement Tx queue allocation and cleanup Queues come in triads of two work queues and one completion queue. The Tx triad only uses the first work queue for now, the second one will be used for the XDP ring later. Add the ring structures, the per NAPI vector allocation of triads, descriptor memory and interrupts, and the completion processing. The completion queue does not report one entry per packet, it reports a work queue head, so a single completion can release many packets. Nothing enables the queues in hardware or submits anything to them yet, that comes with the next two changes. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-4-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 23 + .../net/ethernet/meta/mpnic/mpnic_netdev.h | 26 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 495 ++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 80 +++ 5 files changed, 625 insertions(+) create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_netdev.h create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_txrx.c create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_txrx.h diff --git a/drivers/net/ethernet/meta/mpnic/Makefile b/drivers/net/ethernet/meta/mpnic/Makefile index 3aa7c6a5ab5e..67d617f49a8a 100644 --- a/drivers/net/ethernet/meta/mpnic/Makefile +++ b/drivers/net/ethernet/meta/mpnic/Makefile @@ -11,4 +11,5 @@ mpnic-y := \ mpnic_init.o \ mpnic_irq.o \ mpnic_pci.o \ + mpnic_txrx.o \ # End of mpnic-y diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h index 3ddd6acea085..adf81b5ef49c 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -15,6 +15,13 @@ /* Transmit Work Descriptor Format */ #define MPNIC_TWD_FLAG_REQ_COMPLETION DESC_BIT(37) +#define MPNIC_TWD_ADDR DESC_GENMASK(45, 0) +#define MPNIC_TWD_LEN DESC_GENMASK(63, 48) + +/* Tx Completion Descriptor Format */ +#define MPNIC_TCD_TYPE0_HEAD0 DESC_GENMASK(15, 0) +#define MPNIC_TCD_DONE DESC_BIT(63) + /* Common fields for all DESC_CFG CSRs */ #define MPNIC_DESC_CFG_NUM_DESCS CSR_GENMASK(2, 0) #define MPNIC_DESC_CFG_START_ADDR CSR_GENMASK(19, 8) @@ -28,6 +35,22 @@ * Name Index Address *****************************************************************************/ +/* NIC_CORE_TDF */ +#define MPNIC_TWQ_TAIL(i, j) (0x4 + 1024 * (i) + 2 * (j)) + /* 0x10 */ + +/* NIC_CORE_TCM */ +#define MPNIC_TCQ_HEAD(i) (0x8e + 1024 * (i)) /* 0x238 */ + +/* NIC_CORE_TIM */ +#define MPNIC_TIM_CTL1(i) (0xc0 + 1024 * (i)) /* 0x300 */ +#define MPNIC_TIM_CTL1_UPD_IGN_LONG_EVENT_CNT CSR_BIT(48) +#define MPNIC_TIM_CTL1_UPD_IGN_LONG_TIME_CNT CSR_BIT(49) +#define MPNIC_TIM_CTL1_UPD_IGN_SHORT_TIME_CNT CSR_BIT(50) +#define MPNIC_TIM_CTL1_MASK CSR_BIT(51) +#define MPNIC_TIM_CTL1_MASK_EN CSR_BIT(52) +#define MPNIC_TIM_CTL1_TRIGGER CSR_BIT(53) + /* NIC_CORE_RBP_HP_GLBL */ #define MPNIC_BDQ_GLBL_CTL0 0x420080 /* 0x1080200 */ #define MPNIC_BDQ_GLBL_CTL0_MAX_REQ_SIZE CSR_GENMASK(26, 18) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h new file mode 100644 index 000000000000..f98adf209b45 --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_NETDEV_H_ +#define _MPNIC_NETDEV_H_ + +#include + +#include "mpnic.h" +#include "mpnic_txrx.h" + +struct mpnic_net { + struct mpnic_ring *tx[MPNIC_MAX_TXQS]; + + struct mpnic_napi_vector *napi[MPNIC_MAX_NAPI_VECTORS]; + + struct net_device *netdev; + struct mpnic_dev *mpd; + + u32 txq_size; + + u16 num_napi; + u16 num_tx_queues; +}; + +#endif /* _MPNIC_NETDEV_H_ */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file mode 100644 index 000000000000..853976e11b03 --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -0,0 +1,495 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include + +#include "mpnic.h" +#include "mpnic_netdev.h" +#include "mpnic_txrx.h" + +struct mpnic_xmit_cb { + u32 bytecount; + u8 desc_count; +}; + +#define MPNIC_XMIT_CB(__skb) ((struct mpnic_xmit_cb *)((__skb)->cb)) + +/* Leave the interrupt moderation counters alone when arming or masking */ +#define MPNIC_TIM_PARAM_CFG_PRESERVE_MASK \ + (MPNIC_TIM_CTL1_UPD_IGN_LONG_EVENT_CNT | \ + MPNIC_TIM_CTL1_UPD_IGN_LONG_TIME_CNT | \ + MPNIC_TIM_CTL1_UPD_IGN_SHORT_TIME_CNT) + +static void mpnic_nv_irq_disable(struct mpnic_napi_vector *nv) +{ + mpnic_wr64(nv->mpd, MPNIC_TIM_CTL1(nv->qt[0].cmpl.q_idx), + MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | + MPNIC_TIM_CTL1_MASK_EN | MPNIC_TIM_CTL1_MASK); +} + +static void mpnic_nv_irq_rearm(struct mpnic_napi_vector *nv) +{ + /* Rearming a single queue on a given IRQ rearms all the other + * queues mapped to the same IRQ. + */ + mpnic_wr64(nv->mpd, MPNIC_TIM_CTL1(nv->qt[0].cmpl.q_idx), + MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | MPNIC_TIM_CTL1_MASK_EN); +} + +static void mpnic_nv_irq_trigger(struct mpnic_napi_vector *nv) +{ + mpnic_wr64(nv->mpd, MPNIC_TIM_CTL1(nv->qt[0].cmpl.q_idx), + MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | + MPNIC_TIM_CTL1_MASK_EN | MPNIC_TIM_CTL1_TRIGGER); +} + +static unsigned int mpnic_desc_unused(struct mpnic_ring *ring) +{ + return (ring->head - ring->tail - 1) & ring->size_mask; +} + +static struct netdev_queue *mpnic_txring_txq(const struct net_device *dev, + const struct mpnic_ring *ring) +{ + return netdev_get_tx_queue(dev, ring->q_idx); +} + +static void mpnic_unmap_single_twd(struct device *dev, __le64 *twd) +{ + u64 raw_twd = le64_to_cpu(*twd); + + dma_unmap_single(dev, FIELD_GET(MPNIC_TWD_ADDR, raw_twd), + FIELD_GET(MPNIC_TWD_LEN, raw_twd), DMA_TO_DEVICE); +} + +static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd) +{ + u64 raw_twd = le64_to_cpu(*twd); + + dma_unmap_page(dev, FIELD_GET(MPNIC_TWD_ADDR, raw_twd), + FIELD_GET(MPNIC_TWD_LEN, raw_twd), DMA_TO_DEVICE); +} + +static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget, + struct mpnic_ring *ring, bool discard, + unsigned int hw_head) +{ + u64 total_bytes = 0, total_packets = 0; + unsigned int head = ring->head; + struct netdev_queue *txq; + unsigned int clean_desc; + + clean_desc = (hw_head - head) & ring->size_mask; + + while (clean_desc) { + struct sk_buff *skb = ring->tx_buf[head]; + unsigned int desc_cnt; + + desc_cnt = MPNIC_XMIT_CB(skb)->desc_count; + if (desc_cnt > clean_desc) + break; + + ring->tx_buf[head] = NULL; + + clean_desc -= desc_cnt; + + /* Step over the metadata descriptor */ + head++; + head &= ring->size_mask; + desc_cnt--; + + mpnic_unmap_single_twd(nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + desc_cnt--; + + while (desc_cnt--) { + mpnic_unmap_page_twd(nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + } + + total_bytes += MPNIC_XMIT_CB(skb)->bytecount; + total_packets++; + + napi_consume_skb(skb, napi_budget); + } + + if (!total_bytes) + return; + + ring->head = head; + + if (discard) + return; + + txq = mpnic_txring_txq(nv->napi.dev, ring); + netif_txq_completed_wake(txq, total_packets, total_bytes, + mpnic_desc_unused(ring), + MPNIC_TX_DESC_WAKEUP); +} + +static void mpnic_commit_cq_head(struct mpnic_ring *cmpl) +{ + u32 head = cmpl->head; + + /* The tail shadows the last value written to the doorbell, so a + * completion queue which has not moved costs no MMIO write. + */ + if (cmpl->tail != head) { + cmpl->tail = head; + writeq(head & cmpl->size_mask, cmpl->doorbell); + } +} + +static void mpnic_clean_tcq(struct mpnic_napi_vector *nv, + struct mpnic_q_triad *qt, int napi_budget) +{ + struct mpnic_ring *cmpl = &qt->cmpl; + __le64 *raw_tcd, done; + u32 head = cmpl->head; + s32 head0 = -1; + + done = (head & (cmpl->size_mask + 1)) ? 0 : cpu_to_le64(MPNIC_TCD_DONE); + raw_tcd = &cmpl->desc[head & cmpl->size_mask]; + + /* Walk the completion queue collecting the heads reported by NIC. + * Only the first work queue is enabled and no packet asks for a + * timestamp, so every completion is a plain head update and the + * descriptor type does not have to be decoded. + */ + while ((*raw_tcd & cpu_to_le64(MPNIC_TCD_DONE)) == done) { + u64 tcd; + + dma_rmb(); + + tcd = le64_to_cpu(*raw_tcd); + head0 = FIELD_GET(MPNIC_TCD_TYPE0_HEAD0, tcd); + + raw_tcd++; + head++; + + if (unlikely(!(head & cmpl->size_mask))) { + done ^= cpu_to_le64(MPNIC_TCD_DONE); + raw_tcd = &cmpl->desc[0]; + } + } + + cmpl->head = head; + + if (head0 >= 0) + mpnic_clean_twq0(nv, napi_budget, &qt->sub0, false, head0); +} + +static int mpnic_poll(struct napi_struct *napi, int budget) +{ + struct mpnic_napi_vector *nv = container_of(napi, + struct mpnic_napi_vector, + napi); + int i; + + for (i = 0; i < nv->txt_count; i++) + mpnic_clean_tcq(nv, &nv->qt[i], budget); + + for (i = 0; i < nv->txt_count; i++) + mpnic_commit_cq_head(&nv->qt[i].cmpl); + + if (likely(napi_complete_done(napi, 0))) + mpnic_nv_irq_rearm(nv); + + return 0; +} + +static irqreturn_t mpnic_msix_clean_rings(int __always_unused irq, void *data) +{ + struct mpnic_napi_vector *nv = data; + + napi_schedule_irqoff(&nv->napi); + + return IRQ_HANDLED; +} + +static void mpnic_free_napi_vector(struct mpnic_net *mpn, + struct mpnic_napi_vector *nv) +{ + int i; + + for (i = 0; i < nv->txt_count; i++) + mpn->tx[nv->qt[i].sub0.q_idx] = NULL; + + mpnic_free_irq(nv->mpd, nv->v_idx, nv); + netif_napi_del_locked(&nv->napi); + mpn->napi[nv->v_idx - MPNIC_NON_NAPI_VECTORS] = NULL; + kfree(nv); +} + +void mpnic_free_napi_vectors(struct mpnic_net *mpn) +{ + int i; + + for (i = 0; i < mpn->num_napi; i++) + if (mpn->napi[i]) + mpnic_free_napi_vector(mpn, mpn->napi[i]); +} + +static void mpnic_ring_init(struct mpnic_ring *ring, u32 __iomem *doorbell, + int q_idx) +{ + ring->doorbell = doorbell; + ring->q_idx = q_idx; +} + +static int mpnic_alloc_napi_vector(struct mpnic_dev *mpd, + struct mpnic_net *mpn, unsigned int idx) +{ + u32 __iomem *uc_addr = READ_ONCE(mpd->uc_addr0); + struct mpnic_napi_vector *nv; + int err; + + /* Doorbells are plain pointers into the register window, they have + * no way of noticing that it went away. + */ + if (!uc_addr) + return -EIO; + + nv = kzalloc_flex(*nv, qt, 1); + if (!nv) + return -ENOMEM; + + nv->txt_count = 1; + nv->mpd = mpd; + nv->dev = mpd->dev; + nv->v_idx = idx + MPNIC_NON_NAPI_VECTORS; + + mpn->napi[idx] = nv; + netif_napi_add_config_locked(mpn->netdev, &nv->napi, mpnic_poll, idx); + netif_napi_set_irq_locked(&nv->napi, + pci_irq_vector(to_pci_dev(mpd->dev), + nv->v_idx)); + + snprintf(nv->name, sizeof(nv->name), "%s-TxRx-%u", + mpn->netdev->name, idx); + + err = mpnic_request_irq(mpd, nv->v_idx, mpnic_msix_clean_rings, 0, + nv->name, nv); + if (err) + goto err_napi_del; + + mpnic_ring_init(&nv->qt[0].sub0, &uc_addr[MPNIC_TWQ_TAIL(idx, 0)], idx); + mpnic_ring_init(&nv->qt[0].cmpl, &uc_addr[MPNIC_TCQ_HEAD(idx)], idx); + mpn->tx[idx] = &nv->qt[0].sub0; + + return 0; + +err_napi_del: + netif_napi_del_locked(&nv->napi); + mpn->napi[idx] = NULL; + kfree(nv); + return err; +} + +int mpnic_alloc_napi_vectors(struct mpnic_net *mpn) +{ + unsigned int i; + int err; + + for (i = 0; i < mpn->num_napi; i++) { + err = mpnic_alloc_napi_vector(mpn->mpd, mpn, i); + if (err) + goto err_free_vectors; + } + + return 0; + +err_free_vectors: + mpnic_free_napi_vectors(mpn); + + return err; +} + +static void mpnic_free_ring_resources(struct device *dev, + struct mpnic_ring *ring) +{ + kvfree(ring->tx_buf); + ring->tx_buf = NULL; + + /* If size is not set there are no descriptors present */ + if (!ring->size) + return; + + dma_free_coherent(dev, ring->size, ring->desc, ring->dma); + ring->size_mask = 0; + ring->size = 0; +} + +static int mpnic_alloc_ring_desc(struct mpnic_net *mpn, + struct mpnic_ring *ring, u32 count) +{ + struct device *dev = mpn->netdev->dev.parent; + size_t size; + + size = ALIGN(array_size(sizeof(*ring->desc), count), 4096); + + ring->desc = dma_alloc_coherent(dev, size, &ring->dma, + GFP_KERNEL | __GFP_NOWARN); + if (!ring->desc) + return -ENOMEM; + + ring->size_mask = count - 1; + ring->size = size; + + return 0; +} + +static void mpnic_free_tx_qt_resources(struct mpnic_net *mpn, + struct mpnic_q_triad *qt) +{ + struct device *dev = mpn->netdev->dev.parent; + + mpnic_free_ring_resources(dev, &qt->cmpl); + mpnic_free_ring_resources(dev, &qt->sub0); +} + +static int mpnic_alloc_tx_qt_resources(struct mpnic_net *mpn, + struct mpnic_q_triad *qt) +{ + int err; + + err = mpnic_alloc_ring_desc(mpn, &qt->sub0, mpn->txq_size); + if (err) + return err; + + qt->sub0.tx_buf = kvzalloc_objs(*qt->sub0.tx_buf, mpn->txq_size, + GFP_KERNEL | __GFP_NOWARN); + if (!qt->sub0.tx_buf) { + err = -ENOMEM; + goto err_free_qt; + } + + err = mpnic_alloc_ring_desc(mpn, &qt->cmpl, mpn->txq_size); + if (err) + goto err_free_qt; + + return 0; + +err_free_qt: + mpnic_free_tx_qt_resources(mpn, qt); + return err; +} + +static void mpnic_free_nv_resources(struct mpnic_net *mpn, + struct mpnic_napi_vector *nv) +{ + int i; + + for (i = 0; i < nv->txt_count; i++) + mpnic_free_tx_qt_resources(mpn, &nv->qt[i]); +} + +static int mpnic_alloc_nv_resources(struct mpnic_net *mpn, + struct mpnic_napi_vector *nv) +{ + int i, err; + + for (i = 0; i < nv->txt_count; i++) { + err = mpnic_alloc_tx_qt_resources(mpn, &nv->qt[i]); + if (err) + goto err_free_qt_resources; + } + + return 0; + +err_free_qt_resources: + while (i--) + mpnic_free_tx_qt_resources(mpn, &nv->qt[i]); + return err; +} + +void mpnic_free_resources(struct mpnic_net *mpn) +{ + int i; + + for (i = 0; i < mpn->num_napi; i++) + mpnic_free_nv_resources(mpn, mpn->napi[i]); +} + +int mpnic_alloc_resources(struct mpnic_net *mpn) +{ + int i, err; + + for (i = 0; i < mpn->num_napi; i++) { + err = mpnic_alloc_nv_resources(mpn, mpn->napi[i]); + if (err) + goto err_free_resources; + } + + return 0; + +err_free_resources: + while (i--) + mpnic_free_nv_resources(mpn, mpn->napi[i]); + + return err; +} + +int mpnic_set_netif_queues(struct mpnic_net *mpn) +{ + int i, j, err; + + err = netif_set_real_num_tx_queues(mpn->netdev, mpn->num_tx_queues); + if (err) + return err; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (j = 0; j < nv->txt_count; j++) + netif_queue_set_napi(mpn->netdev, nv->qt[j].sub0.q_idx, + NETDEV_QUEUE_TYPE_TX, &nv->napi); + } + + return 0; +} + +void mpnic_reset_netif_queues(struct mpnic_net *mpn) +{ + int i, j; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (j = 0; j < nv->txt_count; j++) + netif_queue_set_napi(mpn->netdev, nv->qt[j].sub0.q_idx, + NETDEV_QUEUE_TYPE_TX, NULL); + } +} + +void mpnic_napi_disable(struct mpnic_net *mpn) +{ + int i; + + for (i = 0; i < mpn->num_napi; i++) { + napi_disable_locked(&mpn->napi[i]->napi); + + mpnic_nv_irq_disable(mpn->napi[i]); + } +} + +void mpnic_napi_enable(struct mpnic_net *mpn) +{ + int i; + + for (i = 0; i < mpn->num_napi; i++) + napi_enable_locked(&mpn->napi[i]->napi); + + /* Force the first interrupt on each vector to guarantee that any + * completions posted during bringup are processed. + */ + for (i = 0; i < mpn->num_napi; i++) + mpnic_nv_irq_trigger(mpn->napi[i]); + + mpnic_wrfl(mpn->mpd); +} diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h new file mode 100644 index 000000000000..0d4667666b5b --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_TXRX_H_ +#define _MPNIC_TXRX_H_ + +#include +#include +#include +#include +#include + +#include "mpnic.h" + +struct mpnic_net; + +/* Space we have to have available in a work queue to take a packet: + * 1 descriptor per page + * + 1 descriptor for the skb head + * + 1 descriptor for the metadata + * + 7 descriptors to keep the tail out of the head's cacheline + * If we cannot guarantee that we return NETDEV_TX_BUSY. + */ +#define MPNIC_MAX_SKB_DESC (MAX_SKB_FRAGS + 9) +#define MPNIC_TX_DESC_WAKEUP (MPNIC_MAX_SKB_DESC * 2) + +#define MPNIC_MAX_NAPI_VECTORS 1024u + +struct mpnic_ring { + void **tx_buf; /* Packets outstanding in a TWQ */ + + u32 __iomem *doorbell; /* Pointer to CSR space for ring */ + __le64 *desc; /* Descriptor ring memory */ + u16 size_mask; /* Size of ring in descriptors - 1 */ + u16 q_idx; /* Hardware queue index */ + + u32 head, tail; /* Head/Tail of ring */ + + /* TWQ only, index of the metadata descriptor of the last packet + * placed in the ring without ringing the doorbell, -1 if the + * doorbell is in sync with the tail. + */ + s32 deferred_meta; + + /* Slow path fields follow */ + dma_addr_t dma; /* Phys addr of descriptor memory */ + size_t size; /* Size of descriptor ring in memory */ +}; + +/* The device pairs two work queues with one completion queue. On the Tx + * side only the first work queue is used for now, the second one becomes + * the XDP ring. + */ +struct mpnic_q_triad { + struct mpnic_ring sub0, sub1, cmpl; +}; + +struct mpnic_napi_vector { + struct napi_struct napi; + struct device *dev; /* Device for DMA unmapping */ + struct mpnic_dev *mpd; + + u16 v_idx; + u16 txt_count; + + char name[IFNAMSIZ + 11]; + + struct mpnic_q_triad qt[]; +}; + +int mpnic_alloc_napi_vectors(struct mpnic_net *mpn); +void mpnic_free_napi_vectors(struct mpnic_net *mpn); +int mpnic_alloc_resources(struct mpnic_net *mpn); +void mpnic_free_resources(struct mpnic_net *mpn); +int mpnic_set_netif_queues(struct mpnic_net *mpn); +void mpnic_reset_netif_queues(struct mpnic_net *mpn); +void mpnic_napi_enable(struct mpnic_net *mpn); +void mpnic_napi_disable(struct mpnic_net *mpn); + +#endif /* _MPNIC_TXRX_H_ */ From bd7ce2b2afeae7a9fa8fa28602ba515c8656ce3a Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:18 -0700 Subject: [PATCH 0891/2126] eth: mpnic: start and stop the Tx HW queues Point the hardware at the descriptor rings and provide functions for turning the Tx queues on and off. Teardown has to wait for the DMA engines to go idle before the ring memory can be freed: disabling a queue only stops the device picking up new work, it does not tell us that the work already fetched has been retired. Each block exposes an idle bitmap per queue, and every one of the four blocks a packet passes through on its way out has to report idle before the descriptors are safe to free. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-5-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 28 +++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 175 +++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 4 + 3 files changed, 207 insertions(+) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h index adf81b5ef49c..44ff664e3f3b 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -36,11 +36,26 @@ *****************************************************************************/ /* NIC_CORE_TDF */ +#define MPNIC_TWQ_CTL(i, j) (0x0 + 1024 * (i) + 2 * (j)) + /* 0x0 */ +#define MPNIC_TWQ_CTL_RESET CSR_BIT(0) +#define MPNIC_TWQ_CTL_ENABLE CSR_BIT(1) #define MPNIC_TWQ_TAIL(i, j) (0x4 + 1024 * (i) + 2 * (j)) /* 0x10 */ +#define MPNIC_TWQ_SIZE(i, j) (0x10 + 1024 * (i) + 2 * (j)) + /* 0x40 */ +#define MPNIC_TWQ_SIZE_SIZE CSR_GENMASK(3, 0) +#define MPNIC_TWQ_BASE_ADDR(i, j) (0x1c + 1024 * (i) + 2 * (j)) + /* 0x70 */ /* NIC_CORE_TCM */ +#define MPNIC_TCQ_CTL(i) (0x80 + 1024 * (i)) /* 0x200 */ +#define MPNIC_TCQ_CTL_RESET CSR_BIT(0) +#define MPNIC_TCQ_CTL_ENABLE CSR_BIT(1) +#define MPNIC_TCQ_BASE_ADDR(i) (0x86 + 1024 * (i)) /* 0x218 */ #define MPNIC_TCQ_HEAD(i) (0x8e + 1024 * (i)) /* 0x238 */ +#define MPNIC_TCQ_SIZE(i) (0x94 + 1024 * (i)) /* 0x250 */ +#define MPNIC_TCQ_SIZE_SIZE CSR_GENMASK(4, 0) /* NIC_CORE_TIM */ #define MPNIC_TIM_CTL1(i) (0xc0 + 1024 * (i)) /* 0x300 */ @@ -50,6 +65,11 @@ #define MPNIC_TIM_CTL1_MASK CSR_BIT(51) #define MPNIC_TIM_CTL1_MASK_EN CSR_BIT(52) #define MPNIC_TIM_CTL1_TRIGGER CSR_BIT(53) +#define MPNIC_TIM_INTR_MASK(i) (0xc8 + 1024 * (i)) /* 0x320 */ +#define MPNIC_TIM_INTR_MASK_MASK CSR_BIT(0) + +/* NIC_CORE_TIM_PRV */ +#define MPNIC_TIM_CTL(i) (0x100100 + 1024 * (i)) /* 0x400400 */ /* NIC_CORE_RBP_HP_GLBL */ #define MPNIC_BDQ_GLBL_CTL0 0x420080 /* 0x1080200 */ @@ -83,6 +103,8 @@ #define MPNIC_RNI_RCM_CTL 0x427004 /* 0x109c010 */ /* NIC_CORE_TDF_GLBL */ +#define MPNIC_TWQ_IDLE(i) (0x428042 + 2 * (i)) /* 0x10a0108 */ +#define MPNIC_TWQ_IDLE_CNT 32 #define MPNIC_TWQ_DEF_PRI_TWD 0x428082 /* 0x10a0208 */ #define MPNIC_TDF_MEM_INIT_REQ 0x42813a /* 0x10a04e8 */ #define MPNIC_TDF_MEM_INIT_DONE 0x42813c /* 0x10a04f0 */ @@ -100,6 +122,8 @@ #define MPNIC_TQS_SLOWDOWN_CTL_ENABLE CSR_BIT(6) #define MPNIC_TQS_MTU_CTL0 0x42a030 /* 0x10a80c0 */ #define MPNIC_TQS_MTU_CTL1 0x42a032 /* 0x10a80c8 */ +#define MPNIC_TQS_IDLE(i) (0x42a040 + 2 * (i)) /* 0x10a8100 */ +#define MPNIC_TQS_IDLE_CNT 32 #define MPNIC_TQS_SET_P0_MAP0(i) (0x42a082 + 2 * (i)) /* 0x10a8208 */ #define MPNIC_TQS_SET_P0_MAP1(i) (0x42a092 + 2 * (i)) /* 0x10a8248 */ #define MPNIC_TQS_GLBL_SHAPING 0x42a108 /* 0x10a8420 */ @@ -135,10 +159,14 @@ #define MPNIC_TQS_PORT_CTL(i) (0x42a1e4 + 2 * (i)) /* 0x10a8790 */ /* NIC_CORE_TDE_GLBL */ +#define MPNIC_TDE_IDLE(i) (0x42b000 + 2 * (i)) /* 0x10ac000 */ +#define MPNIC_TDE_IDLE_CNT 32 #define MPNIC_TDE_MEM_INIT_REQ 0x42b1ee /* 0x10ac7b8 */ #define MPNIC_TDE_MEM_INIT_DONE 0x42b1f0 /* 0x10ac7c0 */ /* NIC_CORE_TCM_GLBL */ +#define MPNIC_TCQ_IDLE(i) (0x42c09e + 2 * (i)) /* 0x10b0278 */ +#define MPNIC_TCQ_IDLE_CNT 16 #define MPNIC_TCM_MEM_INIT_REQ 0x42c0be /* 0x10b02f8 */ #define MPNIC_TCM_MEM_INIT_DONE 0x42c0c0 /* 0x10b0300 */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index 853976e11b03..aaa3a3e99a13 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -467,6 +468,180 @@ void mpnic_reset_netif_queues(struct mpnic_net *mpn) } } +static void mpnic_enable_twq(struct mpnic_dev *mpd, struct mpnic_ring *twq) +{ + u32 log_size = fls(twq->size_mask); + u32 i = twq->q_idx; + + /* Reset head/tail */ + mpnic_wr64(mpd, MPNIC_TWQ_CTL(i, 0), MPNIC_TWQ_CTL_RESET); + twq->tail = 0; + twq->head = 0; + twq->deferred_meta = -1; + + /* Store descriptor ring address and size */ + mpnic_wr64(mpd, MPNIC_TWQ_BASE_ADDR(i, 0), twq->dma); + mpnic_wr64(mpd, MPNIC_TWQ_SIZE(i, 0), log_size & MPNIC_TWQ_SIZE_SIZE); + + mpnic_wr64(mpd, MPNIC_TWQ_CTL(i, 0), MPNIC_TWQ_CTL_ENABLE); +} + +static void mpnic_enable_tcq(struct mpnic_dev *mpd, + struct mpnic_napi_vector *nv, + struct mpnic_ring *tcq) +{ + u32 log_size = fls(tcq->size_mask); + u32 i = tcq->q_idx; + + /* Reset head/tail */ + mpnic_wr64(mpd, MPNIC_TCQ_CTL(i), MPNIC_TCQ_CTL_RESET); + tcq->tail = 0; + tcq->head = 0; + + /* Store descriptor ring address and size */ + mpnic_wr64(mpd, MPNIC_TCQ_BASE_ADDR(i), tcq->dma); + mpnic_wr64(mpd, MPNIC_TCQ_SIZE(i), log_size & MPNIC_TCQ_SIZE_SIZE); + + /* Store interrupt information for the completion queue */ + mpnic_wr64(mpd, MPNIC_TIM_CTL(i), nv->v_idx); + mpnic_wr64(mpd, MPNIC_TIM_INTR_MASK(i), 0); + + mpnic_wr64(mpd, MPNIC_TCQ_CTL(i), MPNIC_TCQ_CTL_ENABLE); +} + +void mpnic_enable(struct mpnic_net *mpn) +{ + struct mpnic_dev *mpd = mpn->mpd; + int i, j; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (j = 0; j < nv->txt_count; j++) { + mpnic_enable_twq(mpd, &nv->qt[j].sub0); + mpnic_enable_tcq(mpd, nv, &nv->qt[j].cmpl); + } + } + + mpnic_wrfl(mpd); +} + +static void mpnic_disable_twq(struct mpnic_dev *mpd, struct mpnic_ring *txr) +{ + u64 twq_ctl = mpnic_rd64(mpd, MPNIC_TWQ_CTL(txr->q_idx, 0)); + + twq_ctl &= ~MPNIC_TWQ_CTL_ENABLE; + mpnic_wr64(mpd, MPNIC_TWQ_CTL(txr->q_idx, 0), twq_ctl); +} + +static void mpnic_disable_tcq(struct mpnic_dev *mpd, struct mpnic_ring *txr) +{ + mpnic_wr64(mpd, MPNIC_TCQ_CTL(txr->q_idx), 0); + mpnic_wr64(mpd, MPNIC_TIM_INTR_MASK(txr->q_idx), + MPNIC_TIM_INTR_MASK_MASK); +} + +void mpnic_disable(struct mpnic_net *mpn) +{ + struct mpnic_dev *mpd = mpn->mpd; + int i, j; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (j = 0; j < nv->txt_count; j++) { + mpnic_disable_twq(mpd, &nv->qt[j].sub0); + mpnic_disable_tcq(mpd, &nv->qt[j].cmpl); + } + } + + mpnic_wrfl(mpd); +} + +struct mpnic_idle_regs { + u32 reg_base; + u8 reg_cnt; + char name[4]; +}; + +static u32 mpnic_non_idle_queues(struct mpnic_dev *mpd, + const struct mpnic_idle_regs *regs, + unsigned int nregs) +{ + u32 non_idle_bitmap = 0; + unsigned int i, j; + + for (i = 0; i < nregs; i++) { + for (j = 0; j < regs[i].reg_cnt; j++) { + if (mpnic_rd64(mpd, regs[i].reg_base + 2 * j) != + ~0ULL) { + non_idle_bitmap |= BIT(i); + break; + } + } + } + + return non_idle_bitmap; +} + +static void mpnic_idle_dump(struct mpnic_dev *mpd, + const struct mpnic_idle_regs *regs, + unsigned int nregs, u32 non_idle_bitmap, int err) +{ + unsigned int i, j; + + dev_err(mpd->dev, "error waiting for queues idle %d\n", err); + for (i = 0; i < nregs; i++) { + if (!(non_idle_bitmap & BIT(i))) + continue; + + dev_err(mpd->dev, "%s block not idle:\n", regs[i].name); + for (j = 0; j < regs[i].reg_cnt; j++) + dev_err(mpd->dev, " 0x%04x: %016llx\n", + regs[i].reg_base + 2 * j, + mpnic_rd64(mpd, regs[i].reg_base + 2 * j)); + } +} + +void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) +{ + static const struct mpnic_idle_regs queues[] = { + { MPNIC_TWQ_IDLE(0), MPNIC_TWQ_IDLE_CNT, "TWQ" }, + { MPNIC_TQS_IDLE(0), MPNIC_TQS_IDLE_CNT, "TQS" }, + { MPNIC_TDE_IDLE(0), MPNIC_TDE_IDLE_CNT, "TDE" }, + { MPNIC_TCQ_IDLE(0), MPNIC_TCQ_IDLE_CNT, "TCQ" }, + }; + u32 non_idle_bitmap; + int err; + + err = read_poll_timeout(mpnic_non_idle_queues, non_idle_bitmap, + !non_idle_bitmap, 20, 500000, false, mpd, + queues, ARRAY_SIZE(queues)); + if (err) + mpnic_idle_dump(mpd, queues, ARRAY_SIZE(queues), + non_idle_bitmap, err); +} + +void mpnic_flush(struct mpnic_net *mpn) +{ + int i, j; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (j = 0; j < nv->txt_count; j++) { + struct mpnic_q_triad *qt = &nv->qt[j]; + struct netdev_queue *txq; + + /* Clean the work queue of unprocessed work */ + mpnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail); + + txq = netdev_get_tx_queue(mpn->netdev, qt->sub0.q_idx); + netdev_tx_reset_queue(txq); + } + } +} + void mpnic_napi_disable(struct mpnic_net *mpn) { int i; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 0d4667666b5b..68a773133fa2 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -76,5 +76,9 @@ int mpnic_set_netif_queues(struct mpnic_net *mpn); void mpnic_reset_netif_queues(struct mpnic_net *mpn); void mpnic_napi_enable(struct mpnic_net *mpn); void mpnic_napi_disable(struct mpnic_net *mpn); +void mpnic_enable(struct mpnic_net *mpn); +void mpnic_disable(struct mpnic_net *mpn); +void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd); +void mpnic_flush(struct mpnic_net *mpn); #endif /* _MPNIC_TXRX_H_ */ From 1b8d005bd3340ae249271c779672c7355a39f144 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:19 -0700 Subject: [PATCH 0892/2126] eth: mpnic: add a netdevice and basic Tx handling Register the network interface and let it transmit skbs. The typical TWQ descriptor sequence for an skb is: 1 primary metadata, followed by 0 or more non-last address + length (A/L) descriptors, terminated by an always present last A/L descriptor. The device does not write a Tx completion unless it is requested in the primary metadata desc. The xmit path sets this bit when the stack does not report netdev_xmit_more(). This can create a problem if the last packet in a burst is dropped by the driver. To deal with that case, the driver latches the last metadata for which a completion was not requested, and uses this to request a completion and flush queued packets when one is dropped. There is no link state yet, so carrier follows the administrative state. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-6-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 2 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 7 + .../net/ethernet/meta/mpnic/mpnic_netdev.c | 180 ++++++++++++++++++ .../net/ethernet/meta/mpnic/mpnic_netdev.h | 4 + drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 25 +++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 157 +++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 5 + 8 files changed, 381 insertions(+) create mode 100644 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c diff --git a/drivers/net/ethernet/meta/mpnic/Makefile b/drivers/net/ethernet/meta/mpnic/Makefile index 67d617f49a8a..d5bdbd5bd1c7 100644 --- a/drivers/net/ethernet/meta/mpnic/Makefile +++ b/drivers/net/ethernet/meta/mpnic/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MPNIC) += mpnic.o mpnic-y := \ mpnic_init.o \ mpnic_irq.o \ + mpnic_netdev.o \ mpnic_pci.o \ mpnic_txrx.o \ # End of mpnic-y diff --git a/drivers/net/ethernet/meta/mpnic/mpnic.h b/drivers/net/ethernet/meta/mpnic/mpnic.h index 628fd48c997d..78359ab6abb1 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic.h @@ -23,11 +23,13 @@ enum { struct mpnic_dev { struct device *dev; + struct net_device *netdev; u32 __iomem *uc_addr0; u16 num_irqs; + u64 dsn; u32 mps; u32 readrq; u8 relaxed_ord; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h index 44ff664e3f3b..978622bf40c9 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -14,6 +14,13 @@ /* Transmit Work Descriptor Format */ #define MPNIC_TWD_FLAG_REQ_COMPLETION DESC_BIT(37) +#define MPNIC_TWD_FLAG_DEST_MAC DESC_BIT(43) +#define MPNIC_TWD_TYPE DESC_GENMASK(47, 46) +enum { + MPNIC_TWD_TYPE_META = 0, + MPNIC_TWD_TYPE_AL = 2, + MPNIC_TWD_TYPE_LAST_AL = 3, +}; #define MPNIC_TWD_ADDR DESC_GENMASK(45, 0) #define MPNIC_TWD_LEN DESC_GENMASK(63, 48) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file mode 100644 index 000000000000..6d5007be6cad --- /dev/null +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include +#include + +#include "mpnic.h" +#include "mpnic_netdev.h" +#include "mpnic_txrx.h" + +static int mpnic_open(struct net_device *netdev) +{ + struct mpnic_net *mpn = netdev_priv(netdev); + int err; + + err = mpnic_alloc_napi_vectors(mpn); + if (err) + return err; + + err = mpnic_alloc_resources(mpn); + if (err) + goto err_free_napi_vectors; + + err = mpnic_set_netif_queues(mpn); + if (err) + goto err_free_resources; + + mpnic_enable(mpn); + mpnic_napi_enable(mpn); + + netif_tx_wake_all_queues(netdev); + netif_carrier_on(netdev); + + return 0; + +err_free_resources: + mpnic_free_resources(mpn); +err_free_napi_vectors: + mpnic_free_napi_vectors(mpn); + return err; +} + +static int mpnic_stop(struct net_device *netdev) +{ + struct mpnic_net *mpn = netdev_priv(netdev); + + netif_carrier_off(netdev); + + mpnic_napi_disable(mpn); + netif_tx_disable(netdev); + + mpnic_disable(mpn); + mpnic_wait_all_queues_idle(mpn->mpd); + mpnic_flush(mpn); + + mpnic_reset_netif_queues(mpn); + mpnic_free_resources(mpn); + mpnic_free_napi_vectors(mpn); + + return 0; +} + +static const struct net_device_ops mpnic_netdev_ops = { + .ndo_open = mpnic_open, + .ndo_stop = mpnic_stop, + .ndo_validate_addr = eth_validate_addr, + .ndo_start_xmit = mpnic_xmit_frame, +}; + +/** + * mpnic_netdev_free - Free the netdev associated with mpnic + * @mpd: Driver specific structure to free netdev from + **/ +void mpnic_netdev_free(struct mpnic_dev *mpd) +{ + free_netdev(mpd->netdev); + mpd->netdev = NULL; +} + +/** + * mpnic_netdev_alloc - Allocate a netdev and associate it with mpnic + * @mpd: Driver specific structure to associate the netdev with + * + * Return: NULL on failure. + **/ +struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd) +{ + struct net_device *netdev; + struct mpnic_net *mpn; + unsigned int queues; + + netdev = alloc_etherdev_mq(sizeof(*mpn), MPNIC_MAX_RXQS); + if (!netdev) + return NULL; + + SET_NETDEV_DEV(netdev, mpd->dev); + mpd->netdev = netdev; + + netdev->netdev_ops = &mpnic_netdev_ops; + netdev->request_ops_lock = true; + + mpn = netdev_priv(netdev); + mpn->netdev = netdev; + mpn->mpd = mpd; + + mpn->txq_size = MPNIC_TXQ_SIZE_DEFAULT; + + queues = min(netif_get_num_default_rss_queues(), + mpd->num_irqs - MPNIC_NON_NAPI_VECTORS); + mpn->num_tx_queues = queues; + mpn->num_napi = queues; + + netdev->features |= NETIF_F_SG; + netdev->hw_features |= netdev->features; + netdev->vlan_features |= netdev->features; + + netdev->min_mtu = IPV6_MIN_MTU; + netdev->max_mtu = MPNIC_MAX_JUMBO_FRAME_SIZE - ETH_HLEN; + + netif_carrier_off(netdev); + netif_tx_stop_all_queues(netdev); + + return netdev; +} + +static int mpnic_dsn_to_mac_addr(u64 dsn, u8 *addr) +{ + addr[0] = (dsn >> 56) & 0xFF; + addr[1] = (dsn >> 48) & 0xFF; + addr[2] = (dsn >> 40) & 0xFF; + addr[3] = (dsn >> 16) & 0xFF; + addr[4] = (dsn >> 8) & 0xFF; + addr[5] = dsn & 0xFF; + + return is_valid_ether_addr(addr) ? 0 : -EINVAL; +} + +/** + * mpnic_netdev_register - Assign the MAC address and register the netdev + * @netdev: Netdev to register + * + * The permanent address is derived from the PCIe device serial number, the + * same way the firmware and the BMC derive it. A random address would break + * provisioning, so refuse to spawn the interface if the serial number does + * not yield a valid one. + * + * Return: non-zero on failure. + **/ +int mpnic_netdev_register(struct net_device *netdev) +{ + struct mpnic_net *mpn = netdev_priv(netdev); + struct mpnic_dev *mpd = mpn->mpd; + u8 addr[ETH_ALEN]; + int err; + + err = mpnic_dsn_to_mac_addr(mpd->dsn, addr); + if (err) { + dev_err(mpd->dev, "MAC addr %pM invalid\n", addr); + return err; + } + + ether_addr_copy(netdev->perm_addr, addr); + eth_hw_addr_set(netdev, addr); + + err = netif_set_real_num_tx_queues(netdev, mpn->num_tx_queues); + if (err) + return err; + + /* Abort if MMIO has failed. This has to be the last check before + * registration, the register accessors can only detach the device + * once it has been registered. + */ + if (!mpnic_present(mpd)) + return -EIO; + + return register_netdev(netdev); +} diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h index f98adf209b45..df682d194826 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h @@ -23,4 +23,8 @@ struct mpnic_net { u16 num_tx_queues; }; +struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd); +void mpnic_netdev_free(struct mpnic_dev *mpd); +int mpnic_netdev_register(struct net_device *netdev); + #endif /* _MPNIC_NETDEV_H_ */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c index 127b71b44b0f..968cd611b8ea 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c @@ -4,11 +4,13 @@ #include #include #include +#include #include #include #include #include "mpnic.h" +#include "mpnic_netdev.h" #define PCI_DEVICE_ID_META_MPNIC 0x0014 @@ -20,6 +22,10 @@ static void mpnic_mmio_err(struct mpnic_dev *mpd, u32 reg) dev_err(mpd->dev, "Failed read (idx 0x%x AKA addr 0x%x), disabled CSR access, awaiting reset\n", reg, reg << 2); + + /* Tell the stack the device has lost its PCIe link */ + if (mpd->netdev) + netif_device_detach(mpd->netdev); } u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg) @@ -58,6 +64,7 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev) pci_set_drvdata(pdev, mpd); mpd->dev = &pdev->dev; + mpd->dsn = pci_get_dsn(pdev); mpd->mps = pcie_get_mps(pdev); mpd->readrq = pcie_get_readrq(pdev); mpd->relaxed_ord = pcie_relaxed_ordering_enabled(pdev); @@ -74,6 +81,7 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev) **/ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { + struct net_device *netdev; void __iomem *uc_addr0; struct mpnic_dev *mpd; int err; @@ -120,8 +128,23 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) goto err_free_irqs; + netdev = mpnic_netdev_alloc(mpd); + if (!netdev) { + dev_err(&pdev->dev, "Netdev allocation failed\n"); + err = -ENOMEM; + goto err_free_irqs; + } + + err = mpnic_netdev_register(netdev); + if (err) { + dev_err(&pdev->dev, "Netdev registration failed: %d\n", err); + goto err_free_netdev; + } + return 0; +err_free_netdev: + mpnic_netdev_free(mpd); err_free_irqs: mpnic_free_irqs(mpd); err_free_mpd: @@ -138,6 +161,8 @@ static void mpnic_remove(struct pci_dev *pdev) { struct mpnic_dev *mpd = pci_get_drvdata(pdev); + unregister_netdev(mpd->netdev); + mpnic_netdev_free(mpd); mpnic_free_irqs(mpd); kfree(mpd); } diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index aaa3a3e99a13..b1fb0d3902a7 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -17,6 +17,8 @@ struct mpnic_xmit_cb { }; #define MPNIC_XMIT_CB(__skb) ((struct mpnic_xmit_cb *)((__skb)->cb)) +#define MPNIC_TWD_TYPE_MASK(_type) \ + cpu_to_le64(FIELD_PREP(MPNIC_TWD_TYPE, MPNIC_TWD_TYPE_##_type)) /* Leave the interrupt moderation counters alone when arming or masking */ #define MPNIC_TIM_PARAM_CFG_PRESERVE_MASK \ @@ -58,6 +60,29 @@ static struct netdev_queue *mpnic_txring_txq(const struct net_device *dev, return netdev_get_tx_queue(dev, ring->q_idx); } +static void mpnic_tx_doorbell(struct mpnic_ring *ring, __le64 *meta) +{ + *meta |= cpu_to_le64(MPNIC_TWD_FLAG_REQ_COMPLETION); + ring->deferred_meta = -1; + + /* Force DMA writes to flush before writing to tail */ + dma_wmb(); + + writeq(ring->tail, ring->doorbell); +} + +/* Packets handed to us with xmit_more set are left in the ring without a + * doorbell, and without a completion request, in the expectation that the + * packet ending the burst will ring for all of them. If that packet gets + * dropped instead we have to ring here, otherwise the descriptors sit in + * the ring until the next transmit, which may never come. + */ +static void mpnic_tx_flush_doorbell(struct mpnic_ring *ring) +{ + if (ring->deferred_meta >= 0) + mpnic_tx_doorbell(ring, &ring->desc[ring->deferred_meta]); +} + static void mpnic_unmap_single_twd(struct device *dev, __le64 *twd) { u64 raw_twd = le64_to_cpu(*twd); @@ -74,6 +99,138 @@ static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd) FIELD_GET(MPNIC_TWD_LEN, raw_twd), DMA_TO_DEVICE); } +static bool +mpnic_tx_map(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta) +{ + struct device *dev = skb->dev->dev.parent; + unsigned int tail = ring->tail, first; + unsigned int size, data_len; + skb_frag_t *frag; + dma_addr_t dma; + __le64 *twd; + + tail++; + tail &= ring->size_mask; + first = tail; + + size = skb_headlen(skb); + data_len = skb->data_len; + + if (size > FIELD_MAX(MPNIC_TWD_LEN)) + goto err_dma; + + dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); + + for (frag = &skb_shinfo(skb)->frags[0];; frag++) { + twd = &ring->desc[tail]; + + if (dma_mapping_error(dev, dma)) + goto err_dma; + + *twd = cpu_to_le64(FIELD_PREP(MPNIC_TWD_ADDR, dma) | + FIELD_PREP(MPNIC_TWD_LEN, size) | + FIELD_PREP(MPNIC_TWD_TYPE, + MPNIC_TWD_TYPE_AL)); + + tail++; + tail &= ring->size_mask; + + if (!data_len) + break; + + size = skb_frag_size(frag); + data_len -= size; + + if (size > FIELD_MAX(MPNIC_TWD_LEN)) + goto err_dma; + + dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE); + } + + *twd |= MPNIC_TWD_TYPE_MASK(LAST_AL); + + MPNIC_XMIT_CB(skb)->desc_count = ((twd - meta) + 1) & ring->size_mask; + + skb_tx_timestamp(skb); + + ring->tail = tail; + + /* Verify there is room for another packet */ + netif_txq_maybe_stop(mpnic_txring_txq(skb->dev, ring), + mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC, + MPNIC_TX_DESC_WAKEUP); + + if (__netdev_tx_sent_queue(mpnic_txring_txq(skb->dev, ring), + MPNIC_XMIT_CB(skb)->bytecount, + netdev_xmit_more())) + mpnic_tx_doorbell(ring, meta); + else + ring->deferred_meta = meta - ring->desc; + + return false; +err_dma: + if (net_ratelimit()) + netdev_err(skb->dev, "TX DMA map failed\n"); + + while (tail != first) { + tail--; + tail &= ring->size_mask; + twd = &ring->desc[tail]; + if (tail == first) + mpnic_unmap_single_twd(dev, twd); + else + mpnic_unmap_page_twd(dev, twd); + } + + return true; +} + +#define MPNIC_MIN_FRAME_LEN 60 + +static netdev_tx_t mpnic_xmit_frame_ring(struct sk_buff *skb, + struct mpnic_ring *ring) +{ + __le64 *meta = &ring->desc[ring->tail]; + u32 tail = ring->tail; + + if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN)) + goto err_drop; + + if (!netif_txq_maybe_stop(mpnic_txring_txq(skb->dev, ring), + mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC, + MPNIC_TX_DESC_WAKEUP)) { + mpnic_tx_flush_doorbell(ring); + return NETDEV_TX_BUSY; + } + + ring->tx_buf[tail] = skb; + *meta = cpu_to_le64(MPNIC_TWD_FLAG_DEST_MAC); + + MPNIC_XMIT_CB(skb)->bytecount = skb->len; + MPNIC_XMIT_CB(skb)->desc_count = 0; + + if (mpnic_tx_map(ring, skb, meta)) + goto err_free; + + return NETDEV_TX_OK; + +err_free: + dev_kfree_skb_any(skb); + ring->tx_buf[tail] = NULL; + ring->tail = tail; +err_drop: + mpnic_tx_flush_doorbell(ring); + + return NETDEV_TX_OK; +} + +netdev_tx_t mpnic_xmit_frame(struct sk_buff *skb, struct net_device *dev) +{ + struct mpnic_net *mpn = netdev_priv(dev); + + return mpnic_xmit_frame_ring(skb, mpn->tx[skb_get_queue_mapping(skb)]); +} + static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget, struct mpnic_ring *ring, bool discard, unsigned int hw_head) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 68a773133fa2..2add4ad0d39a 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -26,6 +26,10 @@ struct mpnic_net; #define MPNIC_MAX_NAPI_VECTORS 1024u +#define MPNIC_TXQ_SIZE_DEFAULT 1024 + +#define MPNIC_MAX_JUMBO_FRAME_SIZE 9742 + struct mpnic_ring { void **tx_buf; /* Packets outstanding in a TWQ */ @@ -68,6 +72,7 @@ struct mpnic_napi_vector { struct mpnic_q_triad qt[]; }; +netdev_tx_t mpnic_xmit_frame(struct sk_buff *skb, struct net_device *dev); int mpnic_alloc_napi_vectors(struct mpnic_net *mpn); void mpnic_free_napi_vectors(struct mpnic_net *mpn); int mpnic_alloc_resources(struct mpnic_net *mpn); From 4b26e9cdad78bfa4e1ff80690589f0244ba07e4d Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:20 -0700 Subject: [PATCH 0893/2126] eth: mpnic: implement Rx queue allocation and cleanup The Rx side of a queue triad is a header queue, a payload queue and a completion queue. With HDS not active yet, frames are split between the two buffer queues at a fixed header boundary: everything up to 1536 bytes lands in the header page, the rest goes to the payload page. Small frames therefore never touch the payload queue, and several of them share one header page. The device is set to leave headroom and tailroom for XDP and skb_shared_info respectively. Both queues draw from one page pool per triad and post buffer descriptors to the device in batches. Even though we do not support XDP yet, use the XDP APIs for tracking pre-skb buffers. The XDP buffer handling helpers save us from reimplementing the same logic in the driver. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20260924-linux-mpnic-v2-7-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/Kconfig | 1 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 67 +++ .../net/ethernet/meta/mpnic/mpnic_netdev.c | 8 +- .../net/ethernet/meta/mpnic/mpnic_netdev.h | 5 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 447 ++++++++++++++++-- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 71 ++- 6 files changed, 554 insertions(+), 45 deletions(-) diff --git a/drivers/net/ethernet/meta/Kconfig b/drivers/net/ethernet/meta/Kconfig index f940048a5e37..f8b5fe7e31b7 100644 --- a/drivers/net/ethernet/meta/Kconfig +++ b/drivers/net/ethernet/meta/Kconfig @@ -40,6 +40,7 @@ config MPNIC depends on 64BIT || COMPILE_TEST depends on !S390 depends on PCI_MSI + select PAGE_POOL help This driver supports the Meta Platforms Network Interface Controller. diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h index 978622bf40c9..6455ec23b6c7 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -29,6 +29,38 @@ enum { #define MPNIC_TCD_TYPE0_HEAD0 DESC_GENMASK(15, 0) #define MPNIC_TCD_DONE DESC_BIT(63) +/* Rx Buffer Descriptor Format */ +#define MPNIC_BD_DESC_ADDR DESC_GENMASK(39, 2) +#define MPNIC_BD_DESC_ID DESC_GENMASK(57, 40) +#define MPNIC_BD_DESC_BUF_SZ_LOG2 DESC_GENMASK(62, 58) + +/* Rx Completion Queue Descriptors */ +#define MPNIC_RCD_TYPE DESC_GENMASK(62, 61) +enum { + MPNIC_RCD_TYPE_HDR_AL = 0, + MPNIC_RCD_TYPE_PAY_AL = 1, + MPNIC_RCD_TYPE_META = 3, +}; + +#define MPNIC_RCD_DONE DESC_BIT(63) + +#define MPNIC_RCD_HDR_SUBTYPE DESC_GENMASK(60, 59) +enum { + MPNIC_RCD_HDR_SUBTYPE_HDR = 2, +}; + +/* Address/Length Completion Descriptors */ +#define MPNIC_RCD_AL_BUFF_OFF DESC_GENMASK(15, 0) +#define MPNIC_RCD_AL_BUFF_ID DESC_GENMASK(33, 16) +#define MPNIC_RCD_AL_BUFF_LEN DESC_GENMASK(47, 34) +#define MPNIC_RCD_AL_PAGE_FIN DESC_BIT(53) + +/* Metadata Completion Descriptors */ +#define MPNIC_RCD_META_ERR_MAC_EOP DESC_BIT(53) +#define MPNIC_RCD_META_ERR_TRUNCATED_FRAME DESC_BIT(54) +#define MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK \ + (MPNIC_RCD_META_ERR_MAC_EOP | MPNIC_RCD_META_ERR_TRUNCATED_FRAME) + /* Common fields for all DESC_CFG CSRs */ #define MPNIC_DESC_CFG_NUM_DESCS CSR_GENMASK(2, 0) #define MPNIC_DESC_CFG_START_ADDR CSR_GENMASK(19, 8) @@ -75,10 +107,43 @@ enum { #define MPNIC_TIM_INTR_MASK(i) (0xc8 + 1024 * (i)) /* 0x320 */ #define MPNIC_TIM_INTR_MASK_MASK CSR_BIT(0) +/* NIC_CORE_RBP */ +#define MPNIC_BDQ_CTL(i) (0x200 + 1024 * (i)) /* 0x800 */ +#define MPNIC_BDQ_CTL_RESET CSR_BIT(0) +#define MPNIC_BDQ_CTL_ENABLE CSR_BIT(1) +#define MPNIC_BDQ_CTL_ENABLE_PPQ CSR_BIT(3) +#define MPNIC_HPQ_TAIL(i) (0x202 + 1024 * (i)) /* 0x808 */ +#define MPNIC_PPQ_TAIL(i) (0x204 + 1024 * (i)) /* 0x810 */ +#define MPNIC_HPQ_SIZE(i) (0x20a + 1024 * (i)) /* 0x828 */ +#define MPNIC_HPQ_SIZE_SIZE CSR_GENMASK(4, 0) +#define MPNIC_PPQ_SIZE(i) (0x20c + 1024 * (i)) /* 0x830 */ +#define MPNIC_PPQ_SIZE_SIZE CSR_GENMASK(4, 0) +#define MPNIC_HPQ_BASE_ADDR(i) (0x216 + 1024 * (i)) /* 0x858 */ +#define MPNIC_PPQ_BASE_ADDR(i) (0x218 + 1024 * (i)) /* 0x860 */ + +/* NIC_CORE_RCM */ +#define MPNIC_RCQ_CTL(i) (0x280 + 1024 * (i)) /* 0xa00 */ +#define MPNIC_RCQ_CTL_RESET CSR_BIT(0) +#define MPNIC_RCQ_CTL_ENABLE CSR_BIT(1) +#define MPNIC_RCQ_BASE_ADDR(i) (0x286 + 1024 * (i)) /* 0xa18 */ +#define MPNIC_RCQ_HEAD(i) (0x28e + 1024 * (i)) /* 0xa38 */ +#define MPNIC_RCQ_SIZE(i) (0x294 + 1024 * (i)) /* 0xa50 */ +#define MPNIC_RCQ_SIZE_SIZE CSR_GENMASK(4, 0) + /* NIC_CORE_TIM_PRV */ #define MPNIC_TIM_CTL(i) (0x100100 + 1024 * (i)) /* 0x400400 */ +/* NIC_CORE_RDE */ +#define MPNIC_RDE_CFG(i) (0x10021c + 1024 * (i)) /* 0x400870 */ +#define MPNIC_RDE_CFG_MIN_TAIL_ROOM CSR_GENMASK(9, 0) +#define MPNIC_RDE_CFG_MIN_HEAD_ROOM CSR_GENMASK(18, 10) +#define MPNIC_RDE_CFG_MAX_HEADER_BYTES CSR_GENMASK(45, 32) + /* NIC_CORE_RBP_HP_GLBL */ +#define MPNIC_HPQ_IDLE(i) (0x420000 + 2 * (i)) /* 0x1080000 */ +#define MPNIC_HPQ_IDLE_CNT 16 +#define MPNIC_PPQ_IDLE(i) (0x420060 + 2 * (i)) /* 0x1080180 */ +#define MPNIC_PPQ_IDLE_CNT 16 #define MPNIC_BDQ_GLBL_CTL0 0x420080 /* 0x1080200 */ #define MPNIC_BDQ_GLBL_CTL0_MAX_REQ_SIZE CSR_GENMASK(26, 18) #define MPNIC_BDQ_GLBL_CTL0_PREFETCH_SPACE_THRESH \ @@ -99,6 +164,8 @@ enum { #define MPNIC_RDE_MEM_INIT_DONE 0x4240e8 /* 0x10903a0 */ /* NIC_CORE_RCM_GLBL */ +#define MPNIC_RCQ_IDLE(i) (0x42505e + 2 * (i)) /* 0x1094178 */ +#define MPNIC_RCQ_IDLE_CNT 16 #define MPNIC_RCM_MEM_INIT_REQ 0x42507e /* 0x10941f8 */ #define MPNIC_RCM_MEM_INIT_DONE 0x425080 /* 0x1094200 */ diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c index 6d5007be6cad..2c0309d0c221 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -29,6 +29,7 @@ static int mpnic_open(struct net_device *netdev) goto err_free_resources; mpnic_enable(mpn); + mpnic_fill(mpn); mpnic_napi_enable(mpn); netif_tx_wake_all_queues(netdev); @@ -107,10 +108,14 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd) mpn->mpd = mpd; mpn->txq_size = MPNIC_TXQ_SIZE_DEFAULT; + mpn->hpq_size = MPNIC_HPQ_SIZE_DEFAULT; + mpn->ppq_size = MPNIC_PPQ_SIZE_DEFAULT; + mpn->rcq_size = MPNIC_RCQ_SIZE_DEFAULT; queues = min(netif_get_num_default_rss_queues(), mpd->num_irqs - MPNIC_NON_NAPI_VECTORS); mpn->num_tx_queues = queues; + mpn->num_rx_queues = queues; mpn->num_napi = queues; netdev->features |= NETIF_F_SG; @@ -165,7 +170,8 @@ int mpnic_netdev_register(struct net_device *netdev) ether_addr_copy(netdev->perm_addr, addr); eth_hw_addr_set(netdev, addr); - err = netif_set_real_num_tx_queues(netdev, mpn->num_tx_queues); + err = netif_set_real_num_queues(netdev, mpn->num_tx_queues, + mpn->num_rx_queues); if (err) return err; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h index df682d194826..ccb0929f9180 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h @@ -11,6 +11,7 @@ struct mpnic_net { struct mpnic_ring *tx[MPNIC_MAX_TXQS]; + struct mpnic_ring *rx[MPNIC_MAX_RXQS]; struct mpnic_napi_vector *napi[MPNIC_MAX_NAPI_VECTORS]; @@ -18,9 +19,13 @@ struct mpnic_net { struct mpnic_dev *mpd; u32 txq_size; + u32 hpq_size; + u32 ppq_size; + u32 rcq_size; u16 num_napi; u16 num_tx_queues; + u16 num_rx_queues; }; struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index b1fb0d3902a7..389a9e5476c6 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "mpnic.h" #include "mpnic_netdev.h" @@ -342,6 +343,105 @@ static void mpnic_clean_tcq(struct mpnic_napi_vector *nv, mpnic_clean_twq0(nv, napi_budget, &qt->sub0, false, head0); } +static void mpnic_bd_prep(struct mpnic_ring *bdq, u32 idx, struct page *page) +{ + dma_addr_t dma = page_pool_get_dma_addr(page); + + bdq->desc[idx] = cpu_to_le64(FIELD_PREP(MPNIC_BD_DESC_ADDR, dma >> 10) | + FIELD_PREP(MPNIC_BD_DESC_ID, idx) | + FIELD_PREP(MPNIC_BD_DESC_BUF_SZ_LOG2, + page_shift(page) - 10)); +} + +static unsigned int mpnic_bdq_desc_unused(struct mpnic_ring *bdq) +{ + return (ALIGN_DOWN(bdq->head - 1, MPNIC_BDQ_BATCH_SIZE) - bdq->tail) & + bdq->size_mask; +} + +static unsigned int __mpnic_fill_bdq(struct mpnic_ring *bdq) +{ + unsigned int i = bdq->tail; + unsigned int count; + + for (count = mpnic_bdq_desc_unused(bdq); count; count--) { + struct page *page; + + page = page_pool_dev_alloc_pages(bdq->page_pool); + if (!page) + break; + + bdq->rx_buf[i] = page; + mpnic_bd_prep(bdq, i, page); + + i++; + i &= bdq->size_mask; + } + + return i; +} + +static void __mpnic_bdq_commit_tail(struct mpnic_ring *bdq, unsigned int tail) +{ + if (bdq->tail != tail) { + bdq->tail = tail; + + writeq(tail, bdq->doorbell); + } +} + +static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt) +{ + unsigned int ppq_i = __mpnic_fill_bdq(&qt->sub1); + unsigned int hpq_i = __mpnic_fill_bdq(&qt->sub0); + + /* Force DMA writes to flush before writing to tail(s) */ + dma_wmb(); + + /* Flush out the completions we are done with */ + mpnic_commit_cq_head(&qt->cmpl); + + __mpnic_bdq_commit_tail(&qt->sub0, hpq_i); + __mpnic_bdq_commit_tail(&qt->sub1, ppq_i); +} + +static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) +{ + long pagecnt_bias = ctxt->pagecnt_bias; + + if (pagecnt_bias) { + struct page *page = ctxt->page; + + if (!page_pool_unref_page(page, pagecnt_bias)) + page_pool_put_unrefed_page(page->pp, page, -1, napi); + } +} + +static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) +{ + struct xdp_buff *buff = &ctxt->buff; + struct page *page; + + if (!buff->data_hard_start) + return; + + if (unlikely(xdp_buff_has_frags(buff))) { + struct skb_shared_info *shinfo; + int nr_frags; + + shinfo = xdp_get_shared_info_from_buff(buff); + nr_frags = shinfo->nr_frags; + + while (nr_frags--) { + page = skb_frag_page(&shinfo->frags[nr_frags]); + page_pool_put_full_page(page->pp, page, napi); + } + } + + page = virt_to_head_page(buff->data_hard_start); + page_pool_put_full_page(page->pp, page, napi); +} + static int mpnic_poll(struct napi_struct *napi, int budget) { struct mpnic_napi_vector *nv = container_of(napi, @@ -373,11 +473,14 @@ static irqreturn_t mpnic_msix_clean_rings(int __always_unused irq, void *data) static void mpnic_free_napi_vector(struct mpnic_net *mpn, struct mpnic_napi_vector *nv) { - int i; + int i, j; for (i = 0; i < nv->txt_count; i++) mpn->tx[nv->qt[i].sub0.q_idx] = NULL; + for (j = 0; j < nv->rxt_count; j++, i++) + mpn->rx[nv->qt[i].cmpl.q_idx] = NULL; + mpnic_free_irq(nv->mpd, nv->v_idx, nv); netif_napi_del_locked(&nv->napi); mpn->napi[nv->v_idx - MPNIC_NON_NAPI_VECTORS] = NULL; @@ -413,11 +516,12 @@ static int mpnic_alloc_napi_vector(struct mpnic_dev *mpd, if (!uc_addr) return -EIO; - nv = kzalloc_flex(*nv, qt, 1); + nv = kzalloc_flex(*nv, qt, 2); if (!nv) return -ENOMEM; nv->txt_count = 1; + nv->rxt_count = 1; nv->mpd = mpd; nv->dev = mpd->dev; nv->v_idx = idx + MPNIC_NON_NAPI_VECTORS; @@ -440,6 +544,11 @@ static int mpnic_alloc_napi_vector(struct mpnic_dev *mpd, mpnic_ring_init(&nv->qt[0].cmpl, &uc_addr[MPNIC_TCQ_HEAD(idx)], idx); mpn->tx[idx] = &nv->qt[0].sub0; + mpnic_ring_init(&nv->qt[1].sub0, &uc_addr[MPNIC_HPQ_TAIL(idx)], idx); + mpnic_ring_init(&nv->qt[1].sub1, &uc_addr[MPNIC_PPQ_TAIL(idx)], idx); + mpnic_ring_init(&nv->qt[1].cmpl, &uc_addr[MPNIC_RCQ_HEAD(idx)], idx); + mpn->rx[idx] = &nv->qt[1].cmpl; + return 0; err_napi_del: @@ -471,8 +580,8 @@ err_free_vectors: static void mpnic_free_ring_resources(struct device *dev, struct mpnic_ring *ring) { - kvfree(ring->tx_buf); - ring->tx_buf = NULL; + kvfree(ring->buffer); + ring->buffer = NULL; /* If size is not set there are no descriptors present */ if (!ring->size) @@ -538,19 +647,134 @@ err_free_qt: return err; } +static int +mpnic_alloc_qt_page_pool(struct mpnic_net *mpn, struct mpnic_napi_vector *nv, + struct mpnic_q_triad *qt) +{ + struct page_pool_params pp_params = { + .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size = min(mpn->hpq_size + mpn->ppq_size, 32768u), + .nid = NUMA_NO_NODE, + .dev = nv->dev, + .dma_dir = DMA_FROM_DEVICE, + .max_len = PAGE_SIZE, + .napi = &nv->napi, + .netdev = mpn->netdev, + .queue_idx = qt->cmpl.q_idx, + }; + struct page_pool *pp; + + pp = page_pool_create(&pp_params); + if (IS_ERR(pp)) + return PTR_ERR(pp); + + qt->sub0.page_pool = pp; + page_pool_get(pp); + qt->sub1.page_pool = pp; + + return 0; +} + +static void mpnic_free_rx_qt_resources(struct mpnic_net *mpn, + struct mpnic_q_triad *qt) +{ + struct device *dev = mpn->netdev->dev.parent; + + mpnic_free_ring_resources(dev, &qt->cmpl); + mpnic_free_ring_resources(dev, &qt->sub1); + mpnic_free_ring_resources(dev, &qt->sub0); + + if (xdp_rxq_info_is_reg(&qt->xdp_rxq)) { + xdp_rxq_info_unreg(&qt->xdp_rxq); + page_pool_destroy(qt->sub1.page_pool); + page_pool_destroy(qt->sub0.page_pool); + } +} + +static int mpnic_alloc_rx_qt_resources(struct mpnic_net *mpn, + struct mpnic_napi_vector *nv, + struct mpnic_q_triad *qt) +{ + int err; + + err = mpnic_alloc_qt_page_pool(mpn, nv, qt); + if (err) + return err; + + err = xdp_rxq_info_reg(&qt->xdp_rxq, mpn->netdev, qt->cmpl.q_idx, + nv->napi.napi_id); + if (err) + goto err_free_page_pool; + + err = xdp_rxq_info_reg_mem_model(&qt->xdp_rxq, MEM_TYPE_PAGE_POOL, + qt->sub0.page_pool); + if (err) + goto err_unreg_rxq; + + err = mpnic_alloc_ring_desc(mpn, &qt->sub0, mpn->hpq_size); + if (err) + goto err_unreg_mm; + + qt->sub0.rx_buf = kvzalloc_objs(*qt->sub0.rx_buf, mpn->hpq_size, + GFP_KERNEL | __GFP_NOWARN); + if (!qt->sub0.rx_buf) { + err = -ENOMEM; + goto err_free_qt; + } + + err = mpnic_alloc_ring_desc(mpn, &qt->sub1, mpn->ppq_size); + if (err) + goto err_free_qt; + + qt->sub1.rx_buf = kvzalloc_objs(*qt->sub1.rx_buf, mpn->ppq_size, + GFP_KERNEL | __GFP_NOWARN); + if (!qt->sub1.rx_buf) { + err = -ENOMEM; + goto err_free_qt; + } + + err = mpnic_alloc_ring_desc(mpn, &qt->cmpl, mpn->rcq_size); + if (err) + goto err_free_qt; + + qt->cmpl.state = kvzalloc_obj(*qt->cmpl.state, + GFP_KERNEL | __GFP_NOWARN); + if (!qt->cmpl.state) { + err = -ENOMEM; + goto err_free_qt; + } + + return 0; + +err_free_qt: + mpnic_free_rx_qt_resources(mpn, qt); + return err; +err_unreg_mm: + xdp_rxq_info_unreg_mem_model(&qt->xdp_rxq); +err_unreg_rxq: + xdp_rxq_info_unreg(&qt->xdp_rxq); +err_free_page_pool: + page_pool_destroy(qt->sub1.page_pool); + page_pool_destroy(qt->sub0.page_pool); + return err; +} + static void mpnic_free_nv_resources(struct mpnic_net *mpn, struct mpnic_napi_vector *nv) { - int i; + int i, j; for (i = 0; i < nv->txt_count; i++) mpnic_free_tx_qt_resources(mpn, &nv->qt[i]); + + for (j = 0; j < nv->rxt_count; j++, i++) + mpnic_free_rx_qt_resources(mpn, &nv->qt[i]); } static int mpnic_alloc_nv_resources(struct mpnic_net *mpn, struct mpnic_napi_vector *nv) { - int i, err; + int i, j, err; for (i = 0; i < nv->txt_count; i++) { err = mpnic_alloc_tx_qt_resources(mpn, &nv->qt[i]); @@ -558,11 +782,21 @@ static int mpnic_alloc_nv_resources(struct mpnic_net *mpn, goto err_free_qt_resources; } + for (j = 0; j < nv->rxt_count; j++, i++) { + err = mpnic_alloc_rx_qt_resources(mpn, nv, &nv->qt[i]); + if (err) + goto err_free_qt_resources; + } + return 0; err_free_qt_resources: - while (i--) - mpnic_free_tx_qt_resources(mpn, &nv->qt[i]); + while (i--) { + if (i < nv->txt_count) + mpnic_free_tx_qt_resources(mpn, &nv->qt[i]); + else + mpnic_free_rx_qt_resources(mpn, &nv->qt[i]); + } return err; } @@ -593,36 +827,41 @@ err_free_resources: return err; } +static void mpnic_set_netif_napi(struct mpnic_napi_vector *nv, + struct napi_struct *napi) +{ + int i, j; + + for (i = 0; i < nv->txt_count; i++) + netif_queue_set_napi(nv->napi.dev, nv->qt[i].sub0.q_idx, + NETDEV_QUEUE_TYPE_TX, napi); + + for (j = 0; j < nv->rxt_count; j++, i++) + netif_queue_set_napi(nv->napi.dev, nv->qt[i].cmpl.q_idx, + NETDEV_QUEUE_TYPE_RX, napi); +} + int mpnic_set_netif_queues(struct mpnic_net *mpn) { - int i, j, err; + int i, err; - err = netif_set_real_num_tx_queues(mpn->netdev, mpn->num_tx_queues); + err = netif_set_real_num_queues(mpn->netdev, mpn->num_tx_queues, + mpn->num_rx_queues); if (err) return err; - for (i = 0; i < mpn->num_napi; i++) { - struct mpnic_napi_vector *nv = mpn->napi[i]; - - for (j = 0; j < nv->txt_count; j++) - netif_queue_set_napi(mpn->netdev, nv->qt[j].sub0.q_idx, - NETDEV_QUEUE_TYPE_TX, &nv->napi); - } + for (i = 0; i < mpn->num_napi; i++) + mpnic_set_netif_napi(mpn->napi[i], &mpn->napi[i]->napi); return 0; } void mpnic_reset_netif_queues(struct mpnic_net *mpn) { - int i, j; + int i; - for (i = 0; i < mpn->num_napi; i++) { - struct mpnic_napi_vector *nv = mpn->napi[i]; - - for (j = 0; j < nv->txt_count; j++) - netif_queue_set_napi(mpn->netdev, nv->qt[j].sub0.q_idx, - NETDEV_QUEUE_TYPE_TX, NULL); - } + for (i = 0; i < mpn->num_napi; i++) + mpnic_set_netif_napi(mpn->napi[i], NULL); } static void mpnic_enable_twq(struct mpnic_dev *mpd, struct mpnic_ring *twq) @@ -666,17 +905,77 @@ static void mpnic_enable_tcq(struct mpnic_dev *mpd, mpnic_wr64(mpd, MPNIC_TCQ_CTL(i), MPNIC_TCQ_CTL_ENABLE); } +static void mpnic_enable_bdq(struct mpnic_dev *mpd, struct mpnic_ring *hpq, + struct mpnic_ring *ppq) +{ + u32 hpq_log_size = fls(hpq->size_mask); + u32 ppq_log_size = fls(ppq->size_mask); + u32 i = hpq->q_idx; + + /* Reset head/tail */ + mpnic_wr64(mpd, MPNIC_BDQ_CTL(i), MPNIC_BDQ_CTL_RESET); + hpq->tail = 0; + hpq->head = 0; + ppq->tail = 0; + ppq->head = 0; + + /* Store descriptor ring addresses and sizes */ + mpnic_wr64(mpd, MPNIC_HPQ_BASE_ADDR(i), hpq->dma); + mpnic_wr64(mpd, MPNIC_HPQ_SIZE(i), hpq_log_size & MPNIC_HPQ_SIZE_SIZE); + mpnic_wr64(mpd, MPNIC_PPQ_BASE_ADDR(i), ppq->dma); + mpnic_wr64(mpd, MPNIC_PPQ_SIZE(i), ppq_log_size & MPNIC_PPQ_SIZE_SIZE); + + mpnic_wr64(mpd, MPNIC_BDQ_CTL(i), + MPNIC_BDQ_CTL_ENABLE | MPNIC_BDQ_CTL_ENABLE_PPQ); +} + +static void mpnic_set_rde_cfg(struct mpnic_dev *mpd, struct mpnic_ring *rcq) +{ + BUILD_BUG_ON(FIELD_MAX(MPNIC_RDE_CFG_MIN_HEAD_ROOM) < MPNIC_RX_HROOM); + BUILD_BUG_ON(FIELD_MAX(MPNIC_RDE_CFG_MIN_TAIL_ROOM) < MPNIC_RX_TROOM); + + mpnic_wr64(mpd, MPNIC_RDE_CFG(rcq->q_idx), + FIELD_PREP(MPNIC_RDE_CFG_MIN_HEAD_ROOM, MPNIC_RX_HROOM) | + FIELD_PREP(MPNIC_RDE_CFG_MIN_TAIL_ROOM, MPNIC_RX_TROOM) | + FIELD_PREP(MPNIC_RDE_CFG_MAX_HEADER_BYTES, + MPNIC_RX_MAX_HDR)); +} + +static void mpnic_enable_rcq(struct mpnic_dev *mpd, struct mpnic_ring *rcq) +{ + u32 log_size = fls(rcq->size_mask); + u32 i = rcq->q_idx; + + mpnic_set_rde_cfg(mpd, rcq); + + /* Reset head/tail */ + mpnic_wr64(mpd, MPNIC_RCQ_CTL(i), MPNIC_RCQ_CTL_RESET); + rcq->head = 0; + rcq->tail = 0; + + /* Store descriptor ring address and size */ + mpnic_wr64(mpd, MPNIC_RCQ_BASE_ADDR(i), rcq->dma); + mpnic_wr64(mpd, MPNIC_RCQ_SIZE(i), log_size & MPNIC_RCQ_SIZE_SIZE); + + mpnic_wr64(mpd, MPNIC_RCQ_CTL(i), MPNIC_RCQ_CTL_ENABLE); +} + void mpnic_enable(struct mpnic_net *mpn) { struct mpnic_dev *mpd = mpn->mpd; - int i, j; + int i, j, t; for (i = 0; i < mpn->num_napi; i++) { struct mpnic_napi_vector *nv = mpn->napi[i]; - for (j = 0; j < nv->txt_count; j++) { - mpnic_enable_twq(mpd, &nv->qt[j].sub0); - mpnic_enable_tcq(mpd, nv, &nv->qt[j].cmpl); + for (t = 0; t < nv->txt_count; t++) { + mpnic_enable_twq(mpd, &nv->qt[t].sub0); + mpnic_enable_tcq(mpd, nv, &nv->qt[t].cmpl); + } + + for (j = 0; j < nv->rxt_count; j++, t++) { + mpnic_enable_bdq(mpd, &nv->qt[t].sub0, &nv->qt[t].sub1); + mpnic_enable_rcq(mpd, &nv->qt[t].cmpl); } } @@ -698,17 +997,35 @@ static void mpnic_disable_tcq(struct mpnic_dev *mpd, struct mpnic_ring *txr) MPNIC_TIM_INTR_MASK_MASK); } +static void mpnic_disable_bdq(struct mpnic_dev *mpd, struct mpnic_ring *hpq) +{ + u64 bdq_ctl = mpnic_rd64(mpd, MPNIC_BDQ_CTL(hpq->q_idx)); + + bdq_ctl &= ~(MPNIC_BDQ_CTL_ENABLE | MPNIC_BDQ_CTL_ENABLE_PPQ); + mpnic_wr64(mpd, MPNIC_BDQ_CTL(hpq->q_idx), bdq_ctl); +} + +static void mpnic_disable_rcq(struct mpnic_dev *mpd, struct mpnic_ring *rcq) +{ + mpnic_wr64(mpd, MPNIC_RCQ_CTL(rcq->q_idx), 0); +} + void mpnic_disable(struct mpnic_net *mpn) { struct mpnic_dev *mpd = mpn->mpd; - int i, j; + int i, j, t; for (i = 0; i < mpn->num_napi; i++) { struct mpnic_napi_vector *nv = mpn->napi[i]; - for (j = 0; j < nv->txt_count; j++) { - mpnic_disable_twq(mpd, &nv->qt[j].sub0); - mpnic_disable_tcq(mpd, &nv->qt[j].cmpl); + for (t = 0; t < nv->txt_count; t++) { + mpnic_disable_twq(mpd, &nv->qt[t].sub0); + mpnic_disable_tcq(mpd, &nv->qt[t].cmpl); + } + + for (j = 0; j < nv->rxt_count; j++, t++) { + mpnic_disable_bdq(mpd, &nv->qt[t].sub0); + mpnic_disable_rcq(mpd, &nv->qt[t].cmpl); } } @@ -767,6 +1084,9 @@ void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) { MPNIC_TQS_IDLE(0), MPNIC_TQS_IDLE_CNT, "TQS" }, { MPNIC_TDE_IDLE(0), MPNIC_TDE_IDLE_CNT, "TDE" }, { MPNIC_TCQ_IDLE(0), MPNIC_TCQ_IDLE_CNT, "TCQ" }, + { MPNIC_HPQ_IDLE(0), MPNIC_HPQ_IDLE_CNT, "HPQ" }, + { MPNIC_PPQ_IDLE(0), MPNIC_PPQ_IDLE_CNT, "PPQ" }, + { MPNIC_RCQ_IDLE(0), MPNIC_RCQ_IDLE_CNT, "RCQ" }, }; u32 non_idle_bitmap; int err; @@ -779,15 +1099,31 @@ void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) non_idle_bitmap, err); } +static void mpnic_clean_bdq(struct mpnic_ring *bdq) +{ + unsigned int head = bdq->head; + + while (head != bdq->tail) { + struct page *page = bdq->rx_buf[head]; + + page_pool_put_full_page(page->pp, page, false); + + head++; + head &= bdq->size_mask; + } + + bdq->head = head; +} + void mpnic_flush(struct mpnic_net *mpn) { - int i, j; + int i, j, t; for (i = 0; i < mpn->num_napi; i++) { struct mpnic_napi_vector *nv = mpn->napi[i]; - for (j = 0; j < nv->txt_count; j++) { - struct mpnic_q_triad *qt = &nv->qt[j]; + for (t = 0; t < nv->txt_count; t++) { + struct mpnic_q_triad *qt = &nv->qt[t]; struct netdev_queue *txq; /* Clean the work queue of unprocessed work */ @@ -796,6 +1132,45 @@ void mpnic_flush(struct mpnic_net *mpn) txq = netdev_get_tx_queue(mpn->netdev, qt->sub0.q_idx); netdev_tx_reset_queue(txq); } + + for (j = 0; j < nv->rxt_count; j++, t++) { + struct mpnic_q_triad *qt = &nv->qt[t]; + struct mpnic_rcq_state *state = qt->cmpl.state; + + /* Release the partially assembled frame and the + * pages the queues are still handing out. + */ + mpnic_put_pkt_buff(&state->pkt, false); + mpnic_flush_pg_ctxt(&state->hdr, false); + mpnic_flush_pg_ctxt(&state->payld, false); + memset(state, 0, sizeof(*state)); + + mpnic_clean_bdq(&qt->sub0); + mpnic_clean_bdq(&qt->sub1); + } + } +} + +void mpnic_fill(struct mpnic_net *mpn) +{ + int i, j, t; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (j = 0, t = nv->txt_count; j < nv->rxt_count; j++, t++) { + struct mpnic_q_triad *qt = &nv->qt[t]; + struct mpnic_rcq_state *state = qt->cmpl.state; + + /* Point the page contexts at an index the device + * cannot report, so the first buffer coming out of + * either queue is not taken for a page we hold. + */ + state->hdr.idx = UINT_MAX; + state->payld.idx = UINT_MAX; + + mpnic_fill_qt_bdqs(qt); + } } } diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 2add4ad0d39a..5e592dfd9f81 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "mpnic.h" @@ -26,12 +27,57 @@ struct mpnic_net; #define MPNIC_MAX_NAPI_VECTORS 1024u +/* Number of buffer descriptors the driver posts before ringing the + * doorbell. The device consumes whatever the doorbell points at, this is + * purely to keep the driver from writing the CSR for every descriptor. + */ +#define MPNIC_BDQ_BATCH_SIZE 64u + #define MPNIC_TXQ_SIZE_DEFAULT 1024 +#define MPNIC_HPQ_SIZE_DEFAULT 256 +#define MPNIC_PPQ_SIZE_DEFAULT 256 +#define MPNIC_RCQ_SIZE_DEFAULT 1024 + +/* Room the device has to leave in front of and behind every header so the + * driver can build an skb around it in place. The headroom is padded out + * so that consecutive headers in one page start 128 B aligned. + */ +#define MPNIC_RX_TROOM \ + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +#define MPNIC_RX_HROOM \ + (ALIGN(MPNIC_RX_TROOM + XDP_PACKET_HEADROOM, 128) - MPNIC_RX_TROOM) + +/* Headers longer than this are split off into the payload queue */ +#define MPNIC_RX_MAX_HDR 1536 #define MPNIC_MAX_JUMBO_FRAME_SIZE 9742 +/* The page a buffer descriptor queue is currently handing out. Records + * how many of the references taken on it are still unused. + */ +struct mpnic_pg_ctxt { + struct page *page; + long pagecnt_bias; + u32 idx; +}; + +struct mpnic_pkt_ctxt { + struct xdp_buff buff; +}; + +struct mpnic_rcq_state { + struct mpnic_pkt_ctxt pkt; + struct mpnic_pg_ctxt hdr; + struct mpnic_pg_ctxt payld; +}; + struct mpnic_ring { - void **tx_buf; /* Packets outstanding in a TWQ */ + union { + struct mpnic_rcq_state *state; /* RCQ */ + struct page **rx_buf; /* BDQ */ + void **tx_buf; /* TWQ */ + void *buffer; /* Generic pointer */ + }; u32 __iomem *doorbell; /* Pointer to CSR space for ring */ __le64 *desc; /* Descriptor ring memory */ @@ -40,22 +86,29 @@ struct mpnic_ring { u32 head, tail; /* Head/Tail of ring */ - /* TWQ only, index of the metadata descriptor of the last packet - * placed in the ring without ringing the doorbell, -1 if the - * doorbell is in sync with the tail. - */ - s32 deferred_meta; + union { + /* BDQ only */ + struct page_pool *page_pool; + + /* TWQ only, index of the metadata descriptor of the last + * packet placed in the ring without ringing the doorbell, + * -1 if the doorbell is in sync with the tail. + */ + s32 deferred_meta; + }; /* Slow path fields follow */ dma_addr_t dma; /* Phys addr of descriptor memory */ size_t size; /* Size of descriptor ring in memory */ }; -/* The device pairs two work queues with one completion queue. On the Tx - * side only the first work queue is used for now, the second one becomes +/* The device pairs two work queues with one completion queue. On the Rx + * side they are the header and the payload buffer descriptor queues; on + * the Tx side only the first one is used for now, the second one becomes * the XDP ring. */ struct mpnic_q_triad { + struct xdp_rxq_info xdp_rxq; struct mpnic_ring sub0, sub1, cmpl; }; @@ -66,6 +119,7 @@ struct mpnic_napi_vector { u16 v_idx; u16 txt_count; + u16 rxt_count; char name[IFNAMSIZ + 11]; @@ -85,5 +139,6 @@ void mpnic_enable(struct mpnic_net *mpn); void mpnic_disable(struct mpnic_net *mpn); void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd); void mpnic_flush(struct mpnic_net *mpn); +void mpnic_fill(struct mpnic_net *mpn); #endif /* _MPNIC_TXRX_H_ */ From a9a9bb5416148f415a8c847048feb017d4f1b089 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 24 Sep 2026 17:35:21 -0700 Subject: [PATCH 0894/2126] eth: mpnic: add basic Rx handling A frame arrives as a run of completion descriptors: one header address/length descriptor, one address/length descriptor per payload page, and a metadata descriptor that closes the frame. The frame is assembled in an xdp_buff as the descriptors come in and handed to the stack when the metadata descriptor arrives. A page holds several frames, so rather than taking a reference per frame the driver takes a batch of references when it starts handing the page out and returns whatever is left over once the device moves on to the next one. Payload fragments that turn out to be contiguous within one page are merged so that a frame spread over a page does not eat one skb fragment slot per descriptor. Signed-off-by: Daniel Zahka Acked-by: Jakub Kicinski Link: https://patch.msgid.link/20260924-linux-mpnic-v2-8-4badc9b58b9e@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 7 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 203 ++++++++++++++++++- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 7 + 3 files changed, 212 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h index 6455ec23b6c7..d6ab9df58168 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h @@ -130,6 +130,10 @@ enum { #define MPNIC_RCQ_SIZE(i) (0x294 + 1024 * (i)) /* 0xa50 */ #define MPNIC_RCQ_SIZE_SIZE CSR_GENMASK(4, 0) +/* NIC_CORE_RIM */ +#define MPNIC_RIM_INTR_MASK(i) (0x2c8 + 1024 * (i)) /* 0xb20 */ +#define MPNIC_RIM_INTR_MASK_MASK CSR_BIT(0) + /* NIC_CORE_TIM_PRV */ #define MPNIC_TIM_CTL(i) (0x100100 + 1024 * (i)) /* 0x400400 */ @@ -139,6 +143,9 @@ enum { #define MPNIC_RDE_CFG_MIN_HEAD_ROOM CSR_GENMASK(18, 10) #define MPNIC_RDE_CFG_MAX_HEADER_BYTES CSR_GENMASK(45, 32) +/* NIC_CORE_RIM_PRV */ +#define MPNIC_RIM_CTL(i) (0x100280 + 1024 * (i)) /* 0x400a00 */ + /* NIC_CORE_RBP_HP_GLBL */ #define MPNIC_HPQ_IDLE(i) (0x420000 + 2 * (i)) /* 0x1080000 */ #define MPNIC_HPQ_IDLE_CNT 16 diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index 389a9e5476c6..edb07b7f334b 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -405,6 +405,34 @@ static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt) __mpnic_bdq_commit_tail(&qt->sub1, ppq_i); } +/* Take one of the references batched on the page at @idx. If the device + * has moved on to a new page, first drop the unused references left on + * the previous one. + */ +static struct page * +mpnic_page_pool_get(struct mpnic_pg_ctxt *pg_ctxt, struct mpnic_ring *ring, + u32 idx) +{ + struct page *page = pg_ctxt->page; + + if (unlikely(pg_ctxt->idx != idx)) { + if (pg_ctxt->pagecnt_bias && + !page_pool_unref_page(page, pg_ctxt->pagecnt_bias)) + page_pool_put_unrefed_page(page->pp, page, -1, true); + + page = ring->rx_buf[idx]; + page_pool_fragment_page(page, MPNIC_PAGECNT_BIAS_MAX); + + pg_ctxt->page = page; + pg_ctxt->pagecnt_bias = MPNIC_PAGECNT_BIAS_MAX; + pg_ctxt->idx = idx; + } + + pg_ctxt->pagecnt_bias--; + + return page; +} + static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) { long pagecnt_bias = ctxt->pagecnt_bias; @@ -417,6 +445,87 @@ static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) } } +static unsigned int mpnic_hdr_pg_start(unsigned int pg_off) +{ + /* The headroom of the first header may be larger than + * MPNIC_RX_HROOM due to alignment. So account for that by just + * making the page offset 0 if we are starting at the first header. + */ + if (ALIGN(MPNIC_RX_HROOM, 128) > MPNIC_RX_HROOM && + pg_off == ALIGN(MPNIC_RX_HROOM, 128)) + return 0; + + return pg_off - MPNIC_RX_HROOM; +} + +static unsigned int mpnic_hdr_pg_end(unsigned int pg_off, unsigned int len) +{ + /* Determine the end of the buffer by finding the start of the next + * and then subtracting the headroom from that frame. + */ + pg_off += len + MPNIC_RX_TROOM + MPNIC_RX_HROOM; + + return ALIGN(pg_off, 128) - MPNIC_RX_HROOM; +} + +static void +mpnic_pkt_prepare(u64 rcd, struct mpnic_rcq_state *state, + struct mpnic_q_triad *qt) +{ + unsigned int pg_off = FIELD_GET(MPNIC_RCD_AL_BUFF_OFF, rcd); + unsigned int pg_idx = FIELD_GET(MPNIC_RCD_AL_BUFF_ID, rcd); + unsigned int len = FIELD_GET(MPNIC_RCD_AL_BUFF_LEN, rcd); + bool fin = FIELD_GET(MPNIC_RCD_AL_PAGE_FIN, rcd); + unsigned int frame_sz, pg_start, pg_end; + struct xdp_buff *buff = &state->pkt.buff; + struct page *page; + + pg_start = mpnic_hdr_pg_start(pg_off); + + page = mpnic_page_pool_get(&state->hdr, &qt->sub0, pg_idx); + qt->sub0.head = (pg_idx + 1) & qt->sub0.size_mask; + + /* Short-cut the end calculation if the page is fully consumed */ + pg_end = fin ? page_size(page) : mpnic_hdr_pg_end(pg_off, len); + frame_sz = pg_end - pg_start; + + page_pool_dma_sync_for_cpu(qt->sub0.page_pool, page, pg_start, + frame_sz); + + xdp_init_buff(buff, frame_sz, &qt->xdp_rxq); + xdp_prepare_buff(buff, page_address(page) + pg_start, + pg_off - pg_start, len, true); + net_prefetch(buff->data); + + state->pkt.add_frag_failed = false; +} + +static void +mpnic_add_rx_frag(u64 rcd, struct mpnic_rcq_state *state, + struct mpnic_q_triad *qt) +{ + unsigned int pg_off = FIELD_GET(MPNIC_RCD_AL_BUFF_OFF, rcd); + unsigned int pg_idx = FIELD_GET(MPNIC_RCD_AL_BUFF_ID, rcd); + unsigned int len = FIELD_GET(MPNIC_RCD_AL_BUFF_LEN, rcd); + bool fin = FIELD_GET(MPNIC_RCD_AL_PAGE_FIN, rcd); + struct xdp_buff *buff = &state->pkt.buff; + unsigned int truesz; + struct page *page; + + page = mpnic_page_pool_get(&state->payld, &qt->sub1, pg_idx); + qt->sub1.head = (pg_idx + 1) & qt->sub1.size_mask; + + truesz = (fin ? page_size(page) : ALIGN(pg_off + len, 128)) - pg_off; + + page_pool_dma_sync_for_cpu(qt->sub1.page_pool, page, pg_off, truesz); + + if (!xdp_buff_add_frag(buff, page_to_netmem(page), pg_off, len, + truesz)) { + state->payld.pagecnt_bias++; + state->pkt.add_frag_failed = true; + } +} + static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) { struct xdp_buff *buff = &ctxt->buff; @@ -442,23 +551,99 @@ static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) page_pool_put_full_page(page->pp, page, napi); } +static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, + struct mpnic_q_triad *qt, int budget) +{ + struct mpnic_ring *rcq = &qt->cmpl; + struct mpnic_rcq_state *state; + unsigned int packets = 0; + __le64 *raw_rcd, done; + u32 head = rcq->head; + + done = (head & (rcq->size_mask + 1)) ? 0 : cpu_to_le64(MPNIC_RCD_DONE); + raw_rcd = &rcq->desc[head & rcq->size_mask]; + state = rcq->state; + + while (packets < budget) { + u64 rcd; + + if ((*raw_rcd & cpu_to_le64(MPNIC_RCD_DONE)) != done) + break; + + dma_rmb(); + + rcd = le64_to_cpu(*raw_rcd); + + switch (FIELD_GET(MPNIC_RCD_TYPE, rcd)) { + case MPNIC_RCD_TYPE_HDR_AL: + if (FIELD_GET(MPNIC_RCD_HDR_SUBTYPE, rcd) == + MPNIC_RCD_HDR_SUBTYPE_HDR) + mpnic_pkt_prepare(rcd, state, qt); + break; + case MPNIC_RCD_TYPE_PAY_AL: + mpnic_add_rx_frag(rcd, state, qt); + break; + case MPNIC_RCD_TYPE_META: { + struct sk_buff *skb = NULL; + + if (likely(!(rcd & + MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) && + !state->pkt.add_frag_failed)) + skb = xdp_build_skb_from_buff(&state->pkt.buff); + + if (likely(skb)) + napi_gro_receive(&nv->napi, skb); + else + mpnic_put_pkt_buff(&state->pkt, true); + + state->pkt.buff.data_hard_start = NULL; + packets++; + break; + } + } + + raw_rcd++; + head++; + + if (unlikely(!(head & rcq->size_mask))) { + done ^= cpu_to_le64(MPNIC_RCD_DONE); + raw_rcd = &rcq->desc[0]; + } + } + + rcq->head = head; + + /* Allocate buffers, force dma_wmb(), and then start writing tails */ + mpnic_fill_qt_bdqs(qt); + + return packets; +} + static int mpnic_poll(struct napi_struct *napi, int budget) { struct mpnic_napi_vector *nv = container_of(napi, struct mpnic_napi_vector, napi); - int i; + int i, j, work_done = 0; for (i = 0; i < nv->txt_count; i++) mpnic_clean_tcq(nv, &nv->qt[i], budget); + if (likely(budget)) + for (j = 0; j < nv->rxt_count; j++, i++) + work_done += mpnic_clean_rcq(nv, &nv->qt[i], + budget - work_done); + for (i = 0; i < nv->txt_count; i++) mpnic_commit_cq_head(&nv->qt[i].cmpl); - if (likely(napi_complete_done(napi, 0))) + if (work_done >= budget) + return budget; + + if (likely(napi_complete_done(napi, work_done))) mpnic_nv_irq_rearm(nv); - return 0; + return work_done; } static irqreturn_t mpnic_msix_clean_rings(int __always_unused irq, void *data) @@ -941,7 +1126,9 @@ static void mpnic_set_rde_cfg(struct mpnic_dev *mpd, struct mpnic_ring *rcq) MPNIC_RX_MAX_HDR)); } -static void mpnic_enable_rcq(struct mpnic_dev *mpd, struct mpnic_ring *rcq) +static void mpnic_enable_rcq(struct mpnic_dev *mpd, + struct mpnic_napi_vector *nv, + struct mpnic_ring *rcq) { u32 log_size = fls(rcq->size_mask); u32 i = rcq->q_idx; @@ -957,6 +1144,10 @@ static void mpnic_enable_rcq(struct mpnic_dev *mpd, struct mpnic_ring *rcq) mpnic_wr64(mpd, MPNIC_RCQ_BASE_ADDR(i), rcq->dma); mpnic_wr64(mpd, MPNIC_RCQ_SIZE(i), log_size & MPNIC_RCQ_SIZE_SIZE); + /* Store interrupt information for the completion queue */ + mpnic_wr64(mpd, MPNIC_RIM_CTL(i), nv->v_idx); + mpnic_wr64(mpd, MPNIC_RIM_INTR_MASK(i), 0); + mpnic_wr64(mpd, MPNIC_RCQ_CTL(i), MPNIC_RCQ_CTL_ENABLE); } @@ -975,7 +1166,7 @@ void mpnic_enable(struct mpnic_net *mpn) for (j = 0; j < nv->rxt_count; j++, t++) { mpnic_enable_bdq(mpd, &nv->qt[t].sub0, &nv->qt[t].sub1); - mpnic_enable_rcq(mpd, &nv->qt[t].cmpl); + mpnic_enable_rcq(mpd, nv, &nv->qt[t].cmpl); } } @@ -1008,6 +1199,8 @@ static void mpnic_disable_bdq(struct mpnic_dev *mpd, struct mpnic_ring *hpq) static void mpnic_disable_rcq(struct mpnic_dev *mpd, struct mpnic_ring *rcq) { mpnic_wr64(mpd, MPNIC_RCQ_CTL(rcq->q_idx), 0); + mpnic_wr64(mpd, MPNIC_RIM_INTR_MASK(rcq->q_idx), + MPNIC_RIM_INTR_MASK_MASK); } void mpnic_disable(struct mpnic_net *mpn) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 5e592dfd9f81..834eb9bfffd1 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -50,6 +50,12 @@ struct mpnic_net; /* Headers longer than this are split off into the payload queue */ #define MPNIC_RX_MAX_HDR 1536 +/* A page is handed out to many packets, each of which takes one reference. + * Rather than a locked increment per packet the driver takes a batch of + * references up front and returns whatever is left when the page is done. + */ +#define MPNIC_PAGECNT_BIAS_MAX (PAGE_SIZE + 1) + #define MPNIC_MAX_JUMBO_FRAME_SIZE 9742 /* The page a buffer descriptor queue is currently handing out. Records @@ -63,6 +69,7 @@ struct mpnic_pg_ctxt { struct mpnic_pkt_ctxt { struct xdp_buff buff; + bool add_frag_failed; }; struct mpnic_rcq_state { From b6f74dff6d26c4727d679f69da980836f092fb56 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 25 Sep 2026 21:18:31 -0700 Subject: [PATCH 0895/2126] net: use two lockdep classes for the netdev instance lock netdev_lockdep_set_classes() puts dev->lock in a separate lockdep class, by type (netkit vs dummy etc), with the intent of keeping the instance locks of individual devices as independent from each other as possible. In practice it does the opposite. lockdep only calls the cmp_fn for locks of the same class, so netdev_lock_cmp_fn() never gets a say when devices from different classes are nested. Instead lockdep records a dependency between the classes, and reports a circular locking problem as soon as the nesting happens the other way round, e.g. when devices are unregistered in a batch. ====================================================== WARNING: possible circular locking dependency detected 7.3.0-rc3+ #26 Not tainted ------------------------------------------------------ kworker/u256:1/326 is trying to acquire lock: ff110000104fce28 (&dev_instance_lock_key#6){+.+.}-{4:4}, at: unregister_netdevice_many_notify+0x1141/0x1c30 but task is already holding lock: ff110000127f2e28 (&dev_instance_lock_key#7){+.+.}-{4:4}, at: unregister_netdevice_many_notify+0x1141/0x1c30 -> #1 (&dev_instance_lock_key#7){+.+.}-{4:4}: __lock_acquire+0x767/0xd60 lock_acquire.part.0+0xd0/0x260 __mutex_lock+0x17d/0x1f20 unregister_netdevice_many_notify+0x1141/0x1c30 default_device_exit_batch+0x3ee/0x520 ops_undo_list+0x2cc/0x8a0 cleanup_net+0x442/0x9c0 process_one_work+0x951/0x1ab0 worker_thread+0x5a6/0xd10 kthread+0x339/0x430 ret_from_fork+0x4a4/0x6f0 ret_from_fork_asm+0x1a/0x30 -> #0 (&dev_instance_lock_key#6){+.+.}-{4:4}: check_prev_add+0xeb/0xe60 validate_chain+0x598/0x900 __lock_acquire+0x767/0xd60 lock_acquire.part.0+0xd0/0x260 __mutex_lock+0x17d/0x1f20 unregister_netdevice_many_notify+0x1141/0x1c30 default_device_exit_batch+0x3ee/0x520 ops_undo_list+0x2cc/0x8a0 cleanup_net+0x442/0x9c0 process_one_work+0x951/0x1ab0 worker_thread+0x5a6/0xd10 kthread+0x339/0x430 ret_from_fork+0x4a4/0x6f0 ret_from_fork_asm+0x1a/0x30 Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&dev_instance_lock_key#7); lock(&dev_instance_lock_key#6); lock(&dev_instance_lock_key#7); lock(&dev_instance_lock_key#6); *** DEADLOCK *** locks held by kworker/u256:1/326: 6, last CPU#6: #0: ff11000001c2b540 ((wq_completion)netns){+.+.}-{0:0}, at: process_one_work+0x117c/0x1ab0 #1: ffa0000001a3fd18 (net_cleanup_work){+.+.}-{0:0}, at: process_one_work+0x8ce/0x1ab0 #2: ffffffff98f53288 (pernet_ops_rwsem){++++}-{4:4}, at: cleanup_net+0xc1/0x9c0 #3: ffffffff98f6ede0 (rtnl_mutex){+.+.}-{4:4}, at: default_device_exit_batch+0x92/0x520 #4: ff1100001321ae28 (&dev_instance_lock_key#7){+.+.}-{4:4}, at: unregister_netdevice_many_notify+0x1141/0x1c30 We can't put all devices in the same class, that'd be too permissive. netdev_nl_queue_create_doit() and netdev_nl_bind_tx_doit() lock a virtual device (netkit) before a physical device, without rtnl_lock. We can never allow locking in the opposite order even under rtnl_lock. cmp_fn cannot enforce this sort of rule: lockdep keys its chain cache on the sequence of lock classes, so with a single class both orders hash to the same chain and only whichever happens first is validated. netdev_lock_cmp_fn() itself has another source of false-negatives. lockdep calls it from within __lock_acquire(), with the recursion counter already raised, so lock_is_held_type() always returns LOCK_STATE_UNKNOWN, which means lockdep_rtnl_is_held() always returns true / held. Use rtnl_is_locked(), which looks at the mutex directly and does work from that context. We may still miss a bad case if some other process is holding the lock, not us, but that's better than the 100% false negative rate of lockdep_rtnl_is_held(). One last thing, lockdep compares the address of the cmp function, so it can't be a static inline - that would work similarly to having separate classes, again. Move it to a source file. Tested by nesting two instance locks from a module, one scenario per boot since the first splat turns debug_locks off: first second rtnl reported ----------------------------------------------------------- virt->virt no recursive locking virt->virt yes - virt->phys no - virt->phys yes - phys->virt no - (records the edge) phys->virt yes - (records the edge) phys->phys no recursive locking phys->phys yes - virt->phys phys->virt no, no circular dependency virt->phys phys->virt no, yes circular dependency virt->phys phys->virt yes, no circular dependency virt->phys phys->virt yes, yes circular dependency phys->virt virt->phys no, no circular dependency phys->virt virt->phys yes, yes circular dependency virt->virt virt->virt yes, no recursive locking phys->phys phys->phys yes, no recursive locking (netkit and dummy stood in for the virtual devices, virtio_net and netdevsim for the physical ones.) Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20260926041832.1649675-1-kuba@kernel.org Signed-off-by: Paolo Abeni --- include/net/netdev_lock.h | 20 +++----------------- net/core/dev.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h index 9fb3e93857c3..edd8cc2e2b36 100644 --- a/include/net/netdev_lock.h +++ b/include/net/netdev_lock.h @@ -110,34 +110,20 @@ static inline int netdev_is_locked_ops_compat(const struct net_device *dev) return lockdep_rtnl_is_held(); } -static inline int netdev_lock_cmp_fn(const struct lockdep_map *a, - const struct lockdep_map *b) -{ - if (a == b) - return 0; - - /* Allow locking multiple devices only under rtnl_lock, - * the exact order doesn't matter. - * Note that upper devices don't lock their ops, so nesting - * mostly happens in batched device removal for now. - */ - return lockdep_rtnl_is_held() ? -1 : 1; -} +void netdev_set_instance_lock_class(struct net_device *dev); #define netdev_lockdep_set_classes(dev) \ { \ static struct lock_class_key qdisc_tx_busylock_key; \ static struct lock_class_key qdisc_xmit_lock_key; \ static struct lock_class_key dev_addr_list_lock_key; \ - static struct lock_class_key dev_instance_lock_key; \ unsigned int i; \ \ (dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \ lockdep_set_class(&(dev)->addr_list_lock, \ &dev_addr_list_lock_key); \ - lockdep_set_class(&(dev)->lock, \ - &dev_instance_lock_key); \ - lock_set_cmp_fn(&dev->lock, netdev_lock_cmp_fn, NULL); \ + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) \ + netdev_set_instance_lock_class(dev); \ for (i = 0; i < (dev)->num_tx_queues; i++) \ lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \ &qdisc_xmit_lock_key); \ diff --git a/net/core/dev.c b/net/core/dev.c index f660fccfc0db..a8eb382f40ca 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -568,6 +568,41 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev) } #endif +#ifdef CONFIG_PROVE_LOCKING +static int netdev_lock_cmp_fn(const struct lockdep_map *a, + const struct lockdep_map *b) +{ + if (a == b) + return 0; + + /* @a and @b must be of same class - both virtual or physical. + * cmp_fn won't be called for devices of different classes. + * + * For the same class only allow nesting under the protection + * of rtnl_lock. Note that we can't use lockdep_rtnl_is_held() + * here, it always answers UNKNOWN from within lockdep. + */ + return rtnl_is_locked() ? -1 : 1; +} + +/* A virtual device can be locked before the physical device it leases + * queues from, see netdev_nl_queue_create_doit(). Keep the two kinds + * in separate classes so the dependency graph enforces the order; + * netdev_lock_cmp_fn() then only has to rule on same-class nesting. + */ +void netdev_set_instance_lock_class(struct net_device *dev) +{ + static struct lock_class_key netdev_virt_instance_lock_key; + + if (dev->dev.parent) + return; + + lockdep_set_class(&dev->lock, &netdev_virt_instance_lock_key); + lock_set_cmp_fn(&dev->lock, netdev_lock_cmp_fn, NULL); +} +EXPORT_SYMBOL_GPL(netdev_set_instance_lock_class); +#endif + /******************************************************************************* * * Protocol management and registration routines @@ -12183,6 +12218,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, #endif mutex_init(&dev->lock); + /* see also netdev_set_instance_lock_class() */ + lock_set_cmp_fn(&dev->lock, netdev_lock_cmp_fn, NULL); netif_rx_mode_init(dev); dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM; From e542bad8d52e0a7f0d47647c2d20612fcdc80c09 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 25 Sep 2026 21:18:32 -0700 Subject: [PATCH 0896/2126] selftests: net: add test for netdev instance lock ordering on unregister Dismantle two netns holding a dummy and a netkit pair registered in opposite order. unregister_netdevice_many_notify() takes the instance locks of all the devices at once, nesting the two kinds of devices one way for the first netns and the other way for the second. With lockdep enabled this used to trigger a circular locking report. Acked-by: Stanislav Fomichev Reviewed-by: Eric Dumazet Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260926041832.1649675-2-kuba@kernel.org Signed-off-by: Paolo Abeni --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/netdev_lock.py | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 tools/testing/selftests/net/netdev_lock.py diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 3ee3378f8b26..d4ca82fec0b4 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -67,6 +67,7 @@ TEST_PROGS := \ nat6to4.sh \ ndisc_unsolicited_na_test.sh \ netdev-l2addr.sh \ + netdev_lock.py \ netdevice.sh \ netns-name.sh \ netns-sysctl.sh \ diff --git a/tools/testing/selftests/net/netdev_lock.py b/tools/testing/selftests/net/netdev_lock.py new file mode 100755 index 000000000000..0015b987eb9d --- /dev/null +++ b/tools/testing/selftests/net/netdev_lock.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +"""Tests for the netdev instance lock.""" + +from lib.py import ksft_run, ksft_exit +from lib.py import ip +from lib.py import NetNS + + +def test_unreg_order() -> None: + """Dismantle two netns holding the same two kinds of ops locked device, + registered in opposite order. + + unregister_netdevice_many_notify() takes the instance lock of every + device in the batch and holds them all at once, so the two kinds end up + nested one way round for the first netns and the other way round for + the second. + """ + with NetNS() as ns1, NetNS() as ns2: + net1, net2 = str(ns1), str(ns2) + + ip("link add du0 type dummy", ns=net1) + ip("link add nk0 type netkit peer name nk1", ns=net1) + + ip("link add nk0 type netkit peer name nk1", ns=net2) + ip("link add du0 type dummy", ns=net2) + + # only devices which are up get locked during unregister + for net in (net1, net2): + for dev in ("du0", "nk0", "nk1"): + ip(f"link set {dev} up", ns=net) + + +def main() -> None: + """Ksft boilerplate main.""" + ksft_run([test_unreg_order]) + ksft_exit() + + +if __name__ == "__main__": + main() From e769837e4e5ccec70c45de04da526a5c071b1fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:04 +0000 Subject: [PATCH 0897/2126] netlink: specs: rt-link: re-align IPv4 devconf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The YNL "ipv4-devconf" enum is misaligned with the IPV4_DEVCONF_* enum. IPV4_DEVCONF_* starts at 1, ipv4-devconf starts at 0. $ git grep -B3 -A1 IPV4_DEVCONF_FORWARDING include/ inc../uapi/linux/ip.h-/* index values for the variables in ipv4_devconf */ inc../uapi/linux/ip.h-enum inc../uapi/linux/ip.h-{ inc../uapi/linux/ip.h: IPV4_DEVCONF_FORWARDING=1, inc../uapi/linux/ip.h- IPV4_DEVCONF_MC_FORWARDING, Re-align the YNL spec by explicitly setting the first value to 1. This misalignment has been present since the spec was added in commit b2f63d904e72 ("doc/netlink: Add spec for rt link messages"). Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-2-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-link.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index 7a72cd1b7e1e..8d63933f9910 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -309,6 +309,7 @@ definitions: entries: - name: forwarding + value: 1 - name: mc-forwarding - From 621524a737f195ab6fc3eae2a1099533301c87df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:05 +0000 Subject: [PATCH 0898/2126] netlink: specs: rt-link: re-align ifla-inet6-stats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit YNL enum ifla-inet6-stats got misaligned with C, as two commits reordered the enum. In commit b4a11b2033b7 ("net: fix IPSTATS_MIB_OUTPKGS increment in OutForwDatagrams."), IPSTATS_MIB_OUTPKTS was renamed to _OUTREQUESTS and a new _OUTPKTS was as the last entry. In commit 652e2c777862 ("net: reorganize IP MIB values (II)"), the IPSTATS_MIB_* enum was reorganized for data locality. Neither of these commits updated the YNL spec. This changed uAPI, as IPSTATS_MIB_* is used as indicies in an u64 array, exported as IFLA_INET6_STATS by inet6_fill_ifla6_stats_attrs(). This patch updates ifla-inet6-stats to reflect both of these commits. Next time we want to reorganize these counters we should properly apply mapping as to maintain the current order on the netlink side. While touching these entries, also remove the dash from ect{0,1}-pkts, so that they align with the C naming. This pre-existing issue was identified by Sashiko during review of commit 2b0aecb7b2b1 ("netlink: specs: rt-link: add accept-ra-min-lft"). Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260831093458.472180-1-ast%40fiberby.net CC: Heng Guo Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-3-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-link.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index 8d63933f9910..3560053cea7a 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -532,11 +532,21 @@ definitions: - name: indelivers - - name: outforwdatagrams + name: noectpkts + - + name: ect1pkts + - + name: ect0pkts + - + name: cepkts + - + name: outrequests - name: outpkts - name: outoctets + - + name: outforwdatagrams - name: inhdrerrors - @@ -587,14 +597,6 @@ definitions: name: outbcastoctets - name: csumerrors - - - name: noectpkts - - - name: ect1-pkts - - - name: ect0-pkts - - - name: cepkts - name: reasm-overlaps - name: br-boolopt-multi From 306df818cc64d61d8c74aa3233173d2b544ffa53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:06 +0000 Subject: [PATCH 0899/2126] netlink: specs: rt-link: fix ifinfo-flags names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correct the names of `enum net_device_flags` constants: - IFF_POINTOPOINT should be "pointopoint", not "point-to-point". - IFF_NOTRAILERS should be "notrailers", not "no-trailers". - IFF_NOARP should be "noarp", not "no-arp". - IFF_ALLMULTI should be "allmulti", not "all-multi". - IFF_AUTOMEDIA should be "automedia", not "auto-media". Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-4-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-link.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index 3560053cea7a..e3a4b4e7e5ef 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -25,17 +25,17 @@ definitions: - name: loopback - - name: point-to-point + name: pointopoint - - name: no-trailers + name: notrailers - name: running - - name: no-arp + name: noarp - name: promisc - - name: all-multi + name: allmulti - name: master - @@ -45,7 +45,7 @@ definitions: - name: portsel - - name: auto-media + name: automedia - name: dynamic - From bef8442f5ffab8b6b846199850247fe5e2d383f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:07 +0000 Subject: [PATCH 0900/2126] netlink: specs: devlink: fix resource-scope type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The correct type for resource-scope is flags, not enum: - DEVLINK_RESOURCE_SCOPE_DEV is _BITUL(0) aka. 1, not 0. - DEVLINK_RESOURCE_SCOPE_PORT is _BITUL(1) aka. 2, not 1. This patch also removes "enum-as-flags", as it is now redundant, these changes does not change the generated policy. Before this patch, this generated devlink-user.c function call: devlink_resource_scope_str(DEVLINK_RESOURCE_SCOPE_DEV) returned "port", not "dev", as it didn't use ffs() to convert the value. CC: Jiri Pirko CC: Tariq Toukan Reviewed-by: Moshe Shemesh Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-5-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/devlink.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index 1de0daa0f921..4706de628392 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -158,7 +158,7 @@ definitions: - name: entry - - type: enum + type: flags name: resource-scope entries: - @@ -903,7 +903,6 @@ attribute-sets: name: resource-scope-mask type: u32 enum: resource-scope - enum-as-flags: true doc: | Bitmask selecting which resource classes to include in a resource-dump response. Bit 0 (dev) selects device-level From fe6a71dc0fbe2c7fea1757b187851737a6a3d118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:08 +0000 Subject: [PATCH 0901/2126] netlink: specs: ethtool: re-align c33-pse-ext-state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit enum ethtool_c33_pse_ext_state is misaligned with YNL: - ETHTOOL_C33_PSE_EXT_STATE_OVLD_DETECTED is 6. - ETHTOOL_C33_PSE_EXT_STATE_PD_DLL_POWER_TYPE is 7 (not in YNL). - ETHTOOL_C33_PSE_EXT_STATE_POWER_NOT_AVAILABLE is 8, not 7. - ETHTOOL_C33_PSE_EXT_STATE_SHORT_DETECTED is 9, not 8. In commit c8149739af86 ("netlink: specs: Expand the PSE netlink command with C33 new features") the PD_DLL_POWER_TYPE enum member was skipped, leading incorrect values for power-not-available and short-detected. As PD_DLL_POWER_TYPE is not used, then skip it, but set the value for power-not-available to 8. CC: Andrew Lunn CC: Oleksij Rempel Reviewed-by: Kory Maincent Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-6-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/ethtool.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 5dd4d1b5d94b..439bf24e7c33 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -89,6 +89,7 @@ definitions: - name: power-not-available doc: Group of power_not_available states + value: 8 - name: short-detected doc: Group of short_detected states From a9a98457342a8a353671bf09dee4bc226d84f209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:09 +0000 Subject: [PATCH 0902/2126] netlink: specs: ethtool: re-align module-fw-flash-status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correct the values for enum ethtool_module_fw_flash_status: - ETHTOOL_MODULE_FW_FLASH_STATUS_STARTED is 1, not 0. - ETHTOOL_MODULE_FW_FLASH_STATUS_IN_PROGRESS is 2, not 1. - ETHTOOL_MODULE_FW_FLASH_STATUS_COMPLETED is 3, not 2. - ETHTOOL_MODULE_FW_FLASH_STATUS_ERROR is 4, not 3. Re-align the YNL spec by explicitly setting the first value to 1. CC: Andrew Lunn CC: Oleksij Rempel Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-7-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/ethtool.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 439bf24e7c33..6868eb473478 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -47,6 +47,7 @@ definitions: - name: started doc: The firmware flashing process has started. + value: 1 - name: in-progress doc: The firmware flashing process is in progress. From 479ecf856c2163ac24c331825419143a1af6d237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:10 +0000 Subject: [PATCH 0903/2126] netlink: specs: nl80211: fix naming of enum members MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the correct naming for enum members: - In feature-flags, it's NL80211_FEATURE_ND_RANDOM_MAC_ADDR, so "nd-random-mac-addr", not "no-random-mac-addr". - In commands, it's NL80211_CMD_UNEXPECTED_4ADDR_FRAME, so "unexpected-4addr-frame", not "unexpected-4-addr-frame". CC: Joe Damato CC: Shaikh Kamaluddin Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-8-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/nl80211.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/nl80211.yaml b/Documentation/netlink/specs/nl80211.yaml index d9fdd66b497e..efc783fb8fdf 100644 --- a/Documentation/netlink/specs/nl80211.yaml +++ b/Documentation/netlink/specs/nl80211.yaml @@ -97,7 +97,7 @@ definitions: - unexpected-frame - probe-client - register-beacons - - unexpected-4-addr-frame + - unexpected-4addr-frame - set-noack-map - ch-switch-notify - start-p2p-device @@ -202,7 +202,7 @@ definitions: - tdls-channel-switch - scan-random-mac-addr - sched-scan-random-mac-addr - - no-random-mac-addr + - nd-random-mac-addr - name: channel-type type: enum From 5fd016f357f7f01b108f87c2ef9756468f579f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:11 +0000 Subject: [PATCH 0904/2126] netlink: specs: tc: fix typo in cls-flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a typo in the naming of a cls-flags constant. The correct name for TCA_CLS_FLAGS_NOT_IN_HW is "not-in-hw", not "not-in-nw". CC: Jamal Hadi Salim CC: "Jonas Köppeler" Reviewed-by: Toke Høiland-Jørgensen Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-9-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/tc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/tc.yaml b/Documentation/netlink/specs/tc.yaml index 2e663333a279..b6ccc645b0e3 100644 --- a/Documentation/netlink/specs/tc.yaml +++ b/Documentation/netlink/specs/tc.yaml @@ -42,7 +42,7 @@ definitions: - skip-hw - skip-sw - in-hw - - not-in-nw + - not-in-hw - verbose - name: flower-key-ctrl-flags From 8450becb88f8452d02086283b828f61fa6a4b359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 25 Sep 2026 21:39:12 +0000 Subject: [PATCH 0905/2126] netlink: specs: fix incorrect name-prefixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix two invalid name-prefixes in the specs: - It's PHY_UPSTREAM_MAC, not PHY_UPSTREAMMAC. - It's PHY_UPSTREAM_PHY, not PHY_UPSTREAMPHY. - It's OVPN_MODE_P2P, not OVPN_MODEP2P. - It's OVPN_MODE_MP, not OVPN_MODEMP. CC: Andrew Lunn CC: Oleksij Rempel Reviewed-by: Jakub Kicinski Signed-off-by: Asbjørn Sloth Tønnesen Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925213918.204767-10-ast@fiberby.net Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/ethtool.yaml | 2 +- Documentation/netlink/specs/rt-link.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 6868eb473478..a66594ad9e73 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -99,7 +99,7 @@ definitions: enum-name: phy-upstream header: linux/ethtool.h type: enum - name-prefix: phy-upstream + name-prefix: phy-upstream- entries: [mac, phy] - name: tcp-data-split diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml index e3a4b4e7e5ef..81b58633911d 100644 --- a/Documentation/netlink/specs/rt-link.yaml +++ b/Documentation/netlink/specs/rt-link.yaml @@ -842,7 +842,7 @@ definitions: - name: ovpn-mode enum-name: ovpn-mode - name-prefix: ovpn-mode + name-prefix: ovpn-mode- type: enum entries: - p2p From 2a5043c8b7d09f2fc76c19270fd687b774c5a68b Mon Sep 17 00:00:00 2001 From: Chengfeng Ye Date: Sun, 27 Sep 2026 21:54:05 +0800 Subject: [PATCH 0906/2126] net: pktgen: return bool from __pktgen_NN_threads() Callers of __pktgen_NN_threads() only check whether a pktgen_dev was found. Returning the pointer exposes it outside the helper even though neither caller uses the object itself. Return bool instead and keep the pktgen_dev pointer internal to the helper. Suggested-by: Paolo Abeni Signed-off-by: Chengfeng Ye Reviewed-by: Ivy Lopez Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260927135406.3969970-1-nicoyip.dev@gmail.com Signed-off-by: Paolo Abeni --- net/core/pktgen.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 7f81aed46672..a89cb0760821 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -2024,11 +2024,11 @@ static const struct proc_ops pktgen_thread_proc_ops = { }; /* Think find or remove for NN */ -static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn, - const char *ifname, int remove) +static bool __pktgen_NN_threads(const struct pktgen_net *pn, + const char *ifname, int remove) { struct pktgen_thread *t; - struct pktgen_dev *pkt_dev = NULL; + struct pktgen_dev *pkt_dev; bool exact = (remove == FIND); list_for_each_entry(t, &pn->pktgen_threads, th_list) { @@ -2038,10 +2038,10 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn, pkt_dev->removal_mark = 1; t->control |= T_REMDEV; } - break; + return true; } } - return pkt_dev; + return false; } /* @@ -2049,7 +2049,6 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn, */ static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname) { - struct pktgen_dev *pkt_dev = NULL; const int max_tries = 10, msec_per_try = 125; int i = 0; @@ -2058,8 +2057,7 @@ static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname) while (1) { - pkt_dev = __pktgen_NN_threads(pn, ifname, REMOVE); - if (pkt_dev == NULL) + if (!__pktgen_NN_threads(pn, ifname, REMOVE)) break; /* success */ mutex_unlock(&pktgen_thread_lock); @@ -3835,8 +3833,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname) /* We don't allow a device to be on several threads */ - pkt_dev = __pktgen_NN_threads(t->net, ifname, FIND); - if (pkt_dev) { + if (__pktgen_NN_threads(t->net, ifname, FIND)) { pr_err("ERROR: interface already used\n"); return -EBUSY; } From ee1972def665f4ea965bd654925711261a9ad241 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Sun, 27 Sep 2026 22:03:29 -0400 Subject: [PATCH 0907/2126] net: downgrade BUG_ON EIOCBQUEUED in sock_sendmsg_nosec sock_sendmsg_nosec() runs in syscall context but calls BUG_ON() if proto_ops->sendmsg() returns -EIOCBQUEUED. Crashing the kernel on an unexpected return value is dangerous for production workloads. This risk is real: any signed integer overflow in a sendmsg handler that returns 0xfffffdef (-529, -EIOCBQUEUED) triggers this BUG_ON. In one month, two such bugs were reported in PF_PACKET, reachable by a local user with CAP_NET_RAW in a user namespace: - Commit 73e594c19b4f ("af_packet: Don't cast tpacket_hdr.tp_len to int in tpacket_parse_header().") - In review ("net/packet: prevent TX_RING byte count overflow") https://lore.kernel.org/netdev/20260925124829.6595-1-ilkka.lappetelainen@gmail.com/ Replace the BUG_ON with DEBUG_NET_WARN_ON_ONCE() to retain debug and syzbot coverage, and return -EIO so that -EIOCBQUEUED does not leak to userspace or trigger the BUG_ON(ret == -EIOCBQUEUED) in VFS callers of sock_write_iter() such as new_sync_write(). Failing gracefully is safe because the original reason for the BUG_ON is gone. It was added in commit 599bd19bdc4c ("fs: don't allow to complete sync iocbs through aio_complete") and commit d8725c86aeba ("get rid of the size argument of sock_sendmsg()") to prevent an async completion from corrupting a caller's on-stack kiocb. Commit 1b784140474e ("net: Remove iocb argument from sendmsg and recvmsg") removed that on-stack kiocb. More recently commit fcc77d33a34c ("net: Remove support for AIO on sockets") removed socket AIO support entirely. Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20260928020420.3097018-1-willemdebruijn.kernel@gmail.com Signed-off-by: Paolo Abeni --- net/socket.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/socket.c b/net/socket.c index bb0e1e118ef6..d7a2d2195a07 100644 --- a/net/socket.c +++ b/net/socket.c @@ -800,7 +800,10 @@ static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg) int ret = INDIRECT_CALL_INET(READ_ONCE(sock->ops)->sendmsg, inet6_sendmsg, inet_sendmsg, sock, msg, msg_data_left(msg)); - BUG_ON(ret == -EIOCBQUEUED); + if (unlikely(ret == -EIOCBQUEUED)) { + DEBUG_NET_WARN_ON_ONCE(1); + ret = -EIO; + } if (trace_sock_send_length_enabled()) call_trace_sock_send_length(sock->sk, ret, 0); From 63f028c4dd73720b313b390558920e303205670e Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Fri, 25 Sep 2026 09:04:10 -0500 Subject: [PATCH 0908/2126] dt-bindings: net: Document Marvell PHY "marvell,reg-init" The Marvell PHY driver consumes marvell,reg-init as one or more tuples. Define the property so dtbs_check validates the existing board descriptions. Existing users have no compatible or just "ethernet-phy-ieee802.3-c22" so this has to go into the generic ethernet-phy.yaml schema. Marking it deprecated both for that reason and because opaque register initialization values are discouraged in DT. Assisted-by: LLM Signed-off-by: Rob Herring (Arm) Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260925140410.1157036-2-robh@kernel.org Signed-off-by: Paolo Abeni --- .../devicetree/bindings/net/ethernet-phy.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml index c3ebb3af8b52..df50c4c33d76 100644 --- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml @@ -269,6 +269,22 @@ properties: have to be placed on board. When omitted, the PHYs default will be left as is. + marvell,reg-init: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + deprecated: true + description: + Register initialization tuples for Marvell PHYs. + items: + items: + - description: register page + maximum: 0xffff + - description: register number + maximum: 31 + - description: mask of bits to preserve + maximum: 0xffff + - description: value to apply + maximum: 0xffff + leds: type: object From 1cf2f913b3dd934b339e0d50d3447a9b1c07b83f Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Fri, 25 Sep 2026 13:15:20 -0700 Subject: [PATCH 0909/2126] net: netmem: move to index based freelist Move devmem's freelist to an index-based approach similar to io_uring. This halves the memory requirements for the freelist. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev Link: https://patch.msgid.link/20260925201522.254717-2-sdf@fomichev.me Signed-off-by: Paolo Abeni --- net/core/devmem.c | 50 ++++++++++++++++++++++++++++++++++++----------- net/core/devmem.h | 4 ++-- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index a9d86b5a5588..704d02bd8bc8 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -29,6 +29,29 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); static const struct memory_provider_ops dmabuf_devmem_ops; +static struct net_iov *net_iov_free_pop(struct net_iov_area *area, + u32 *freelist, u32 *free_count) +{ + u32 idx; + + if (unlikely(!*free_count)) + return NULL; + + idx = freelist[--(*free_count)]; + return &area->niovs[idx]; +} + +static void net_iov_free_push(struct net_iov_area *area, + u32 *freelist, u32 *free_count, + struct net_iov *niov) +{ + if (WARN_ON_ONCE(net_iov_owner(niov) != area || + *free_count >= area->num_niovs)) + return; + + freelist[(*free_count)++] = net_iov_idx(niov); +} + static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref) { struct net_devmem_dmabuf_binding *binding = @@ -44,7 +67,7 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) if (binding->freelist) WARN(binding->free_count != binding->area.num_niovs, - "destroying dmabuf binding with outstanding net_iovs: total=%zu, free=%zu", + "destroying dmabuf binding with outstanding net_iovs: total=%zu, free=%u", binding->area.num_niovs, binding->free_count); kvfree(binding->area.niovs); @@ -63,14 +86,15 @@ static unsigned int net_devmem_alloc_dmabuf_bulk(struct net_devmem_dmabuf_binding *binding, netmem_ref *netmems, unsigned int count) { + struct net_iov *niov; unsigned int i; spin_lock_bh(&binding->freelist_lock); - count = min_t(size_t, count, binding->free_count); + count = min(count, binding->free_count); for (i = 0; i < count; i++) { - struct net_iov *niov = binding->freelist[--binding->free_count]; - + niov = net_iov_free_pop(&binding->area, binding->freelist, + &binding->free_count); netmems[i] = net_iov_to_netmem(niov); } @@ -84,12 +108,8 @@ void net_devmem_free_dmabuf(struct net_iov *niov) struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov); spin_lock_bh(&binding->freelist_lock); - if (WARN_ON_ONCE(binding->free_count >= binding->area.num_niovs)) { - spin_unlock_bh(&binding->freelist_lock); - return; - } - - binding->freelist[binding->free_count++] = niov; + net_iov_free_push(&binding->area, binding->freelist, + &binding->free_count, niov); spin_unlock_bh(&binding->freelist_lock); } @@ -228,6 +248,12 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } + if ((dmabuf->size >> niov_shift) > U32_MAX) { + err = -E2BIG; + NL_SET_ERR_MSG(extack, "dmabuf contains too many net_iovs"); + goto err_unmap; + } + binding->area.base_virtual = 0; binding->area.num_niovs = dmabuf->size >> niov_shift; if (direction == DMA_TO_DEVICE) { @@ -279,7 +305,9 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, if (direction == DMA_TO_DEVICE) binding->tx_vec[niov_idx] = niov; else - binding->freelist[binding->free_count++] = niov; + net_iov_free_push(&binding->area, + binding->freelist, + &binding->free_count, niov); dma_addr += niov_size; } } diff --git a/net/core/devmem.h b/net/core/devmem.h index f71d9a2bcb3d..28d6fa7bcb57 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -58,8 +58,8 @@ struct net_devmem_dmabuf_binding { struct xarray bound_rxqs; spinlock_t freelist_lock ____cacheline_aligned_in_smp; - size_t free_count; - struct net_iov **freelist; + u32 free_count; + u32 *freelist; /* ID of this binding. Globally unique to all bindings currently * active. From 5bdeb89ec5b07c751c490af7cac9b1e20a1426ac Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Fri, 25 Sep 2026 13:15:21 -0700 Subject: [PATCH 0910/2126] net: devmem: use memory provider helpers for net_iovs Use public memory-provider helpers for DMA address storage and page-pool association instead of open-coding page_pool state and accounting. Zero the net_iov array because net_mp_niov_set_page_pool() ORs PP_SIGNATURE into pp_magic. Reject DMA addresses that cannot be represented in net_iov metadata. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev Link: https://patch.msgid.link/20260925201522.254717-3-sdf@fomichev.me Signed-off-by: Paolo Abeni --- net/core/devmem.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 704d02bd8bc8..71c83730d73d 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -17,11 +17,9 @@ #include #include #include -#include #include "devmem.h" #include "mp_dmabuf_devmem.h" -#include "page_pool_priv.h" /* Device memory support */ @@ -273,7 +271,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } } - binding->area.niovs = kvmalloc_objs(*binding->area.niovs, + binding->area.niovs = kvzalloc_objs(*binding->area.niovs, binding->area.num_niovs); if (!binding->area.niovs) { err = -ENOMEM; @@ -300,8 +298,12 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, for (i = 0; i < nr_niovs; i++, niov_idx++) { niov = &binding->area.niovs[niov_idx]; net_iov_init(niov, &binding->area, NET_IOV_DMABUF); - page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), - dma_addr); + if (net_mp_niov_set_dma_addr(niov, dma_addr)) { + err = -EFAULT; + NL_SET_ERR_MSG(extack, + "dmabuf DMA address cannot be represented"); + goto err_free_niovs; + } if (direction == DMA_TO_DEVICE) binding->tx_vec[niov_idx] = niov; else @@ -467,19 +469,9 @@ netmem_ref mp_dmabuf_devmem_alloc_netmems(struct page_pool *pool, gfp_t gfp) if (unlikely(!allocated)) return 0; - for (i = 0; i < allocated; i++) { - struct net_iov *niov = netmem_to_net_iov(netmems[i]); - - niov->desc.pp_magic = 0; - niov->desc.pp = NULL; - atomic_long_set(&niov->desc.pp_ref_count, 0); - - page_pool_set_pp_info(pool, netmems[i]); - - pool->pages_state_hold_cnt++; - trace_page_pool_state_hold(pool, netmems[i], - pool->pages_state_hold_cnt); - } + for (i = 0; i < allocated; i++) + net_mp_niov_set_page_pool(pool, + netmem_to_net_iov(netmems[i])); /* Return the last one, the rest stay in the page_pool cache. */ allocated--; @@ -504,8 +496,7 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem) if (WARN_ON_ONCE(refcount != 1)) return false; - page_pool_clear_pp_info(netmem); - + net_mp_niov_clear_page_pool(netmem_to_net_iov(netmem)); net_devmem_free_dmabuf(netmem_to_net_iov(netmem)); /* We don't want the page pool put_page()ing our net_iovs. */ From 5c729e6c71f1be48b5afb99326a6b687e3600c67 Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Fri, 25 Sep 2026 13:15:22 -0700 Subject: [PATCH 0911/2126] net: devmem: decode DMA addresses for TX On 32-bit architectures where dma_addr_t is wider than unsigned long, page_pool_set_dma_addr_netmem() stores page-aligned DMA addresses shifted by PAGE_SHIFT. The net_iov branch of __skb_frag_dma_map() adds byte offsets to the encoded value, so the NIC is programmed with an invalid DMA address. This can trigger an IOMMU fault or DMA from unintended memory. Consolidate DMA address encoding, decoding, and representability checks in netmem helpers. Use the common decoder from the page pool and net_iov TX paths so both interpret stored addresses consistently. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev Link: https://patch.msgid.link/20260925201522.254717-4-sdf@fomichev.me Signed-off-by: Paolo Abeni --- include/linux/skbuff.h | 7 +++++-- include/net/netmem.h | 27 +++++++++++++++++++++++++++ include/net/page_pool/helpers.h | 10 +--------- net/core/page_pool_priv.h | 14 ++------------ 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 84308498a3a8..38b7d7389452 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3816,9 +3816,12 @@ static inline dma_addr_t __skb_frag_dma_map(struct device *dev, size_t offset, size_t size, enum dma_data_direction dir) { + dma_addr_t addr; + if (skb_frag_is_net_iov(frag)) { - return netmem_to_net_iov(frag->netmem)->desc.dma_addr + - offset + frag->offset; + addr = netmem_dma_addr_decode( + netmem_get_dma_addr(frag->netmem)); + return addr + offset + frag->offset; } return dma_map_page(dev, skb_frag_page(frag), skb_frag_off(frag) + offset, size, dir); diff --git a/include/net/netmem.h b/include/net/netmem.h index bccacd21b6c3..cc97611632dc 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -358,6 +358,33 @@ static inline bool netmem_is_pfmemalloc(netmem_ref netmem) return page_is_pfmemalloc(netmem_to_page(netmem)); } +#define NETMEM_32BIT_ARCH_WITH_64BIT_DMA \ + (sizeof(dma_addr_t) > sizeof(unsigned long)) + +static inline unsigned long netmem_dma_addr_encode(dma_addr_t addr) +{ + if (NETMEM_32BIT_ARCH_WITH_64BIT_DMA) + addr >>= PAGE_SHIFT; + + return addr; +} + +static inline dma_addr_t netmem_dma_addr_decode(unsigned long addr) +{ + if (NETMEM_32BIT_ARCH_WITH_64BIT_DMA) + return (dma_addr_t)addr << PAGE_SHIFT; + + return addr; +} + +static inline bool netmem_dma_addr_fits(dma_addr_t addr) +{ + /* We assume page alignment to shave off bottom bits, + * if this "compression" doesn't work we need to drop. + */ + return addr == netmem_dma_addr_decode(netmem_dma_addr_encode(addr)); +} + static inline unsigned long netmem_get_dma_addr(netmem_ref netmem) { return netmem_to_nmdesc(netmem)->dma_addr; diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 87a4e13886e1..cd021832c3fa 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -408,9 +408,6 @@ static inline void page_pool_recycle_direct_netmem(struct page_pool *pool, page_pool_put_full_netmem(pool, netmem, true); } -#define PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA \ - (sizeof(dma_addr_t) > sizeof(unsigned long)) - /** * page_pool_free_va() - free a va into the page_pool * @pool: pool from which va was allocated @@ -427,12 +424,7 @@ static inline void page_pool_free_va(struct page_pool *pool, void *va, static inline dma_addr_t page_pool_get_dma_addr_netmem(netmem_ref netmem) { - dma_addr_t ret = netmem_get_dma_addr(netmem); - - if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) - ret <<= PAGE_SHIFT; - - return ret; + return netmem_dma_addr_decode(netmem_get_dma_addr(netmem)); } /** diff --git a/net/core/page_pool_priv.h b/net/core/page_pool_priv.h index 2fb06d5f6d55..430b97cd88da 100644 --- a/net/core/page_pool_priv.h +++ b/net/core/page_pool_priv.h @@ -18,18 +18,8 @@ void page_pool_unlist(struct page_pool *pool); static inline bool page_pool_set_dma_addr_netmem(netmem_ref netmem, dma_addr_t addr) { - if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) { - netmem_set_dma_addr(netmem, addr >> PAGE_SHIFT); - - /* We assume page alignment to shave off bottom bits, - * if this "compression" doesn't work we need to drop. - */ - return addr != (dma_addr_t)netmem_get_dma_addr(netmem) - << PAGE_SHIFT; - } - - netmem_set_dma_addr(netmem, addr); - return false; + netmem_set_dma_addr(netmem, netmem_dma_addr_encode(addr)); + return !netmem_dma_addr_fits(addr); } static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr) From ecf7e8b5c39d161c76461b89de358bd2e23b3f34 Mon Sep 17 00:00:00 2001 From: Grzegorz Nitka Date: Fri, 20 Mar 2026 06:05:48 +0100 Subject: [PATCH 0912/2126] ice: reduce loglevel to debug for 'Can't delete DSCP' message Reduce netdev message "Can't delete DSCP netlink app ..." from error to debug level when in FW (firmware) DCB mode. This is not a real error and a kind of expected behavior. The device is fully operational and error message might be wrongly interpreted by the user. Signed-off-by: Grzegorz Nitka Signed-off-by: Aleksandr Loktionov Reviewed-by: Simon Horman Tested-by: Arpana Arland (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_dcb_nl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dcb_nl.c b/drivers/net/ethernet/intel/ice/ice_dcb_nl.c index a10c1c8d8697..bb5cc0a2ba69 100644 --- a/drivers/net/ethernet/intel/ice/ice_dcb_nl.c +++ b/drivers/net/ethernet/intel/ice/ice_dcb_nl.c @@ -872,7 +872,7 @@ static int ice_dcbnl_delapp(struct net_device *netdev, struct dcb_app *app) int ret = 0; if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED) { - netdev_err(netdev, "can't delete DSCP netlink app when FW DCB agent is active\n"); + netdev_dbg(netdev, "can't delete DSCP netlink app when FW DCB agent is active\n"); return -EINVAL; } From c160960c7f7ecb6317b73f8d93780847f3f63a87 Mon Sep 17 00:00:00 2001 From: Marcin Szycik Date: Fri, 20 Mar 2026 06:05:56 +0100 Subject: [PATCH 0913/2126] ice: use ice_fill_eth_hdr() in ice_fill_sw_rule() Use the already existing helper function to fill Ethernet header. Also replace sizeof with a (also existing) macro to reduce the number of variables. Suggested-by: Martyna Szapar-Mudlaw Signed-off-by: Marcin Szycik Signed-off-by: Aleksandr Loktionov Reviewed-by: Simon Horman Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_switch.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c index 6a5875bd9c6b..4daee252e2a6 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -2612,7 +2612,6 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info, u16 vlan_id = ICE_MAX_VLAN_ID + 1; u16 vlan_tpid = ETH_P_8021Q; void *daddr = NULL; - u16 eth_hdr_sz; u8 *eth_hdr; u32 act = 0; __be16 *off; @@ -2625,11 +2624,10 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info, return; } - eth_hdr_sz = sizeof(dummy_eth_header); eth_hdr = s_rule->hdr_data; /* initialize the ether header with a dummy header */ - memcpy(eth_hdr, dummy_eth_header, eth_hdr_sz); + ice_fill_eth_hdr(eth_hdr); ice_fill_sw_info(hw, f_info); switch (f_info->fltr_act) { @@ -2730,7 +2728,7 @@ ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info, /* Create the switch rule with the final dummy Ethernet header */ if (opc != ice_aqc_opc_update_sw_rules) - s_rule->hdr_len = cpu_to_le16(eth_hdr_sz); + s_rule->hdr_len = cpu_to_le16(DUMMY_ETH_HDR_LEN); } /** From 74a4378ee5b9e9f5fdbd321db23cf4f83fca0834 Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Fri, 10 Apr 2026 09:49:15 +0200 Subject: [PATCH 0914/2126] ice: reorder ice_flash_info fields to eliminate padding The ice_flash_info structure has a u16 sr_words field before a u32 flash_size value. This creates a 2-byte hole as well as 3 bytes of padding at the end of the structure due to the blank_nvm_mode bitfield. Re-order the structure to place flash_size first, which gives a better layout and reduces padding. Signed-off-by: Jacob Keller Signed-off-by: Aleksandr Loktionov Reviewed-by: Simon Horman Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_type.h b/drivers/net/ethernet/intel/ice/ice_type.h index f1a80da6239e..b8bdd7e8c768 100644 --- a/drivers/net/ethernet/intel/ice/ice_type.h +++ b/drivers/net/ethernet/intel/ice/ice_type.h @@ -529,8 +529,8 @@ struct ice_flash_info { struct ice_nvm_info nvm; /* NVM version information */ struct ice_netlist_info netlist;/* Netlist version info */ struct ice_bank_info banks; /* Flash Bank information */ - u16 sr_words; /* Shadow RAM size in words */ u32 flash_size; /* Size of available flash in bytes */ + u16 sr_words; /* Shadow RAM size in words */ u8 blank_nvm_mode; /* is NVM empty (no FW present) */ }; From 0b1419908406111c45bb5c4c1f3d499dd560cf8c Mon Sep 17 00:00:00 2001 From: Aleksandr Loktionov Date: Fri, 10 Apr 2026 09:49:17 +0200 Subject: [PATCH 0915/2126] ice: increase OICR interrupt moderation rate to 20K interrupts/sec The miscellaneous interrupt cause (OICR) is throttled to 8K interrupts per second (124 us minimum spacing). This interrupt handles VF mailbox messages and Tx timestamps, so the low rate imposes a minimum latency floor on both use-cases. Raise the rate to 20K interrupts per second (50 us minimum spacing) to allow lower latency handling for Tx timestamp bursts and high VF message rates. Signed-off-by: Jacob Keller Signed-off-by: Aleksandr Loktionov Reviewed-by: Simon Horman Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 707c7431b91a..73f69d453542 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3428,7 +3428,7 @@ skip_req_irq: ((pf->ll_ts_irq.index + pf_intr_start_offset) & PFINT_SB_CTL_MSIX_INDX_M) | PFINT_SB_CTL_CAUSE_ENA_M); wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_irq.index), - ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S); + ITR_REG_ALIGN(ICE_ITR_20K) >> ICE_ITR_GRAN_S); ice_flush(hw); ice_irq_dynamic_ena(hw, NULL, NULL); From 49a4ae7adead916596195803176f96e998625fa3 Mon Sep 17 00:00:00 2001 From: Aleksandr Loktionov Date: Fri, 10 Apr 2026 09:49:20 +0200 Subject: [PATCH 0916/2126] ice: use inline helpers instead of memcmp() for IPv6 mask checks in ice_ethtool_fdir Replace static full_ipv6_addr_mask / zero_ipv6_addr_mask structs and the associated memcmp() calls in ice_ethtool_fdir.c with the kernel-provided ipv6_addr_any() helper and a new ice_ipv6_mask_full() inline, reducing boilerplate and making intent clearer. Suggested-by: Larysa Zaremba Signed-off-by: Aleksandr Loktionov Reviewed-by: Simon Horman Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- .../ethernet/intel/ice/ice_ethtool_ntuple.c | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c index 516b57ff3b1c..ad519a8513db 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c @@ -8,23 +8,10 @@ #include "ice_fdir.h" #include "ice_flow.h" -static struct in6_addr full_ipv6_addr_mask = { - .in6_u = { - .u6_addr8 = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - } - } -}; - -static struct in6_addr zero_ipv6_addr_mask = { - .in6_u = { - .u6_addr8 = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - } - } -}; +static bool ice_ipv6_mask_full(const __be32 *a) +{ + return (a[0] & a[1] & a[2] & a[3]) == cpu_to_be32(0xffffffff); +} /* calls to ice_flow_add_prof require the number of segments in the array * for segs_cnt. In this code that is one more than the index. @@ -1070,10 +1057,8 @@ ice_set_fdir_ip6_seg(struct ice_flow_seg_info *seg, enum ice_flow_field src_port, dst_port; /* make sure we don't have any empty rule */ - if (!memcmp(tcp_ip6_spec->ip6src, &zero_ipv6_addr_mask, - sizeof(struct in6_addr)) && - !memcmp(tcp_ip6_spec->ip6dst, &zero_ipv6_addr_mask, - sizeof(struct in6_addr)) && + if (ipv6_addr_any((struct in6_addr *)tcp_ip6_spec->ip6src) && + ipv6_addr_any((struct in6_addr *)tcp_ip6_spec->ip6dst) && !tcp_ip6_spec->psrc && !tcp_ip6_spec->pdst) return -EINVAL; @@ -1097,24 +1082,20 @@ ice_set_fdir_ip6_seg(struct ice_flow_seg_info *seg, *perfect_fltr = true; ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 | l4_proto); - if (!memcmp(tcp_ip6_spec->ip6src, &full_ipv6_addr_mask, - sizeof(struct in6_addr))) + if (ice_ipv6_mask_full(tcp_ip6_spec->ip6src)) ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_SA, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false); - else if (!memcmp(tcp_ip6_spec->ip6src, &zero_ipv6_addr_mask, - sizeof(struct in6_addr))) + else if (ipv6_addr_any((struct in6_addr *)tcp_ip6_spec->ip6src)) *perfect_fltr = false; else return -EOPNOTSUPP; - if (!memcmp(tcp_ip6_spec->ip6dst, &full_ipv6_addr_mask, - sizeof(struct in6_addr))) + if (ice_ipv6_mask_full(tcp_ip6_spec->ip6dst)) ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_DA, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false); - else if (!memcmp(tcp_ip6_spec->ip6dst, &zero_ipv6_addr_mask, - sizeof(struct in6_addr))) + else if (ipv6_addr_any((struct in6_addr *)tcp_ip6_spec->ip6dst)) *perfect_fltr = false; else return -EOPNOTSUPP; @@ -1167,33 +1148,27 @@ ice_set_fdir_ip6_usr_seg(struct ice_flow_seg_info *seg, if (usr_ip6_spec->l4_proto) return -EOPNOTSUPP; /* empty rules are not valid */ - if (!memcmp(usr_ip6_spec->ip6src, &zero_ipv6_addr_mask, - sizeof(struct in6_addr)) && - !memcmp(usr_ip6_spec->ip6dst, &zero_ipv6_addr_mask, - sizeof(struct in6_addr))) + if (ipv6_addr_any((struct in6_addr *)usr_ip6_spec->ip6src) && + ipv6_addr_any((struct in6_addr *)usr_ip6_spec->ip6dst)) return -EINVAL; *perfect_fltr = true; ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6); - if (!memcmp(usr_ip6_spec->ip6src, &full_ipv6_addr_mask, - sizeof(struct in6_addr))) + if (ice_ipv6_mask_full(usr_ip6_spec->ip6src)) ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_SA, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false); - else if (!memcmp(usr_ip6_spec->ip6src, &zero_ipv6_addr_mask, - sizeof(struct in6_addr))) + else if (ipv6_addr_any((struct in6_addr *)usr_ip6_spec->ip6src)) *perfect_fltr = false; else return -EOPNOTSUPP; - if (!memcmp(usr_ip6_spec->ip6dst, &full_ipv6_addr_mask, - sizeof(struct in6_addr))) + if (ice_ipv6_mask_full(usr_ip6_spec->ip6dst)) ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_IPV6_DA, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL, false); - else if (!memcmp(usr_ip6_spec->ip6dst, &zero_ipv6_addr_mask, - sizeof(struct in6_addr))) + else if (ipv6_addr_any((struct in6_addr *)usr_ip6_spec->ip6dst)) *perfect_fltr = false; else return -EOPNOTSUPP; From 5443362bae71a77a7bf37467cef3be608ce32783 Mon Sep 17 00:00:00 2001 From: Przemyslaw Korba Date: Mon, 11 May 2026 09:36:34 +0200 Subject: [PATCH 0917/2126] ice: add rx timestamp tracepoint for debugging Add ice_rx_hwtstamp trace event to help debug PTP rx timestamp issues. The trace captures cached_time, ts_high, and the extended ts_ns value in ice_ptp_get_rx_hwts(). Enable with: echo 1 > /sys/kernel/debug/tracing/events/ice/ice_rx_hwtstamp/enable cat /sys/kernel/debug/tracing/trace_pipe Signed-off-by: Przemyslaw Korba Reviewed-by: Aleksandr Loktionov Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_ptp.c | 2 ++ drivers/net/ethernet/intel/ice/ice_trace.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index e54a98a0bdd0..b781004f856d 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -2330,6 +2330,8 @@ u64 ice_ptp_get_rx_hwts(const union ice_32b_rx_flex_desc *rx_desc, ts_high = le32_to_cpu(rx_desc->wb.flex_ts.ts_high); ts_ns = ice_ptp_extend_32b_ts(cached_time, ts_high); + ice_trace(rx_hwtstamp, cached_time, ts_high, ts_ns); + return ts_ns; } diff --git a/drivers/net/ethernet/intel/ice/ice_trace.h b/drivers/net/ethernet/intel/ice/ice_trace.h index 7568c917cdbe..7c43683a77d4 100644 --- a/drivers/net/ethernet/intel/ice/ice_trace.h +++ b/drivers/net/ethernet/intel/ice/ice_trace.h @@ -261,6 +261,24 @@ DEFINE_TX_TSTAMP_OP_EVENT(ice_tx_tstamp_fw_req); DEFINE_TX_TSTAMP_OP_EVENT(ice_tx_tstamp_fw_done); DEFINE_TX_TSTAMP_OP_EVENT(ice_tx_tstamp_complete); +/* Trace event for Rx timestamp */ +TRACE_EVENT(ice_rx_hwtstamp, + TP_PROTO(u64 cached_time, u32 ts_high, u64 ts_ns), + + TP_ARGS(cached_time, ts_high, ts_ns), + + TP_STRUCT__entry(__field(u64, cached_time) + __field(u32, ts_high) + __field(u64, ts_ns)), + + TP_fast_assign(__entry->cached_time = cached_time; + __entry->ts_high = ts_high; + __entry->ts_ns = ts_ns;), + + TP_printk("cached_time=%llu ts_high=%u ts_ns=%llu", + __entry->cached_time, __entry->ts_high, __entry->ts_ns) +); + DECLARE_EVENT_CLASS(ice_esw_br_fdb_template, TP_PROTO(struct ice_esw_br_fdb_entry *fdb), TP_ARGS(fdb), From ef1c1106e17828a78996f15784b4fdaba88e3831 Mon Sep 17 00:00:00 2001 From: Weimin Xiong Date: Tue, 21 Jul 2026 09:57:47 +0800 Subject: [PATCH 0918/2126] ice: parser: use kcalloc for table allocation Use kcalloc() when calculating the parser table allocation size so an overflow in the firmware-provided item dimensions is detected before allocation. Signed-off-by: Weimin Xiong Reviewed-by: Aleksandr Loktionov Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_parser.c b/drivers/net/ethernet/intel/ice/ice_parser.c index 3ede4c1a5a8a..d239102c52ff 100644 --- a/drivers/net/ethernet/intel/ice/ice_parser.c +++ b/drivers/net/ethernet/intel/ice/ice_parser.c @@ -102,7 +102,7 @@ ice_parser_create_table(struct ice_hw *hw, u32 sect_type, if (!seg) return ERR_PTR(-EINVAL); - table = kzalloc(item_size * length, GFP_KERNEL); + table = kcalloc(length, item_size, GFP_KERNEL); if (!table) return ERR_PTR(-ENOMEM); From f93a165c9bc3cca4338aa9367862c6097163546f Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Thu, 3 Sep 2026 09:20:35 -0400 Subject: [PATCH 0919/2126] ice: simplify ice_pf_state_is_nominal() The function creates a temporary mask on stack just to check that first ICE_STATE_NOMINAL_CHECK_BITS is empty. Simplify it by using the ice_pf_state_is_nominal(). Signed-off-by: Yury Norov Reviewed-by: Sergey Temerkhanov Reviewed-by: Simon Horman Reviewed-by: Aleksandr Loktionov Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_lib.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 9e08db376d3d..73996e3022ef 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi) */ bool ice_pf_state_is_nominal(struct ice_pf *pf) { - DECLARE_BITMAP(check_bits, ICE_STATE_NBITS) = { 0 }; - if (!pf) return false; - bitmap_set(check_bits, 0, ICE_STATE_NOMINAL_CHECK_BITS); - if (bitmap_intersects(pf->state, check_bits, ICE_STATE_NBITS)) - return false; - - return true; + return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS); } #define ICE_FW_MODE_REC_M BIT(1) From 2270d2bf1606fb622737efd4a9ab18551a19034b Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Thu, 3 Sep 2026 09:20:36 -0400 Subject: [PATCH 0920/2126] ice: drop pf == NULL check in ice_pf_state_is_nominal() The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makes the fun function a one-liner. Signed-off-by: Yury Norov Reviewed-by: Sergey Temerkhanov Reviewed-by: Simon Horman Reviewed-by: Aleksandr Loktionov Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_lib.c | 3 --- drivers/net/ethernet/intel/ice/ice_main.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 73996e3022ef..6d5b8acc4764 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi) */ bool ice_pf_state_is_nominal(struct ice_pf *pf) { - if (!pf) - return false; - return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS); } diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 73f69d453542..454fba07d4ec 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -5530,7 +5530,7 @@ static int ice_suspend(struct device *dev) pf = pci_get_drvdata(pdev); - if (!ice_pf_state_is_nominal(pf)) { + if (!pf || !ice_pf_state_is_nominal(pf)) { dev_err(dev, "Device is not ready, no need to suspend it\n"); return -EBUSY; } From ce0e3e4b98c2f80221965ba16c583bd886828823 Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Tue, 17 Feb 2026 11:29:11 +0100 Subject: [PATCH 0921/2126] ice: simplify ice_vc_dis_qs_msg() a little Remove special case logic for disabling all queues in ice_vc_dis_qs_msg(). There were no actual speedup from it, the only difference was in saved bitmap checks, but the HW operations take the majority of time anyway. ice_vsi_stop_all_rx_rings() used (in the removed code) loops over rings anyway. With a message added just before removed code, in the "remove VF" scenario there were no noticeable difference with the "speedup" and without, and it takes ~0.06s on my machine from this point to the whole iavf removed, so really no big deal anyway. Reviewed-by: Aleksandr Loktionov Signed-off-by: Przemek Kitszel Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/virt/queues.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/virt/queues.c b/drivers/net/ethernet/intel/ice/virt/queues.c index 431c9c546b04..ac7f98479b13 100644 --- a/drivers/net/ethernet/intel/ice/virt/queues.c +++ b/drivers/net/ethernet/intel/ice/virt/queues.c @@ -375,6 +375,8 @@ int ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id) * @msg: pointer to the msg buffer * * called from the VF to disable all or specific queue(s) + * + * Return: exit code of sending the virtchnl response. */ int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg) { @@ -424,20 +426,7 @@ int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg) } q_map = vqs->rx_queues; - /* speed up Rx queue disable by batching them if possible */ - if (q_map && - bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) { - if (ice_vsi_stop_all_rx_rings(vsi)) { - dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n", - vsi->vsi_num); - v_ret = VIRTCHNL_STATUS_ERR_PARAM; - goto error_param; - } - - for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) - ice_vf_dis_rxq_interrupt(vsi, vf_q_id); - bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF); - } else if (q_map) { + if (q_map) { for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) { if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) { v_ret = VIRTCHNL_STATUS_ERR_PARAM; From f10883b37d9cb567147d110f3d554ce767a02138 Mon Sep 17 00:00:00 2001 From: Matvey Valigura Date: Thu, 24 Sep 2026 08:06:54 +0300 Subject: [PATCH 0922/2126] usb: atm: use request_firmware_direct() for firmware probing When disconnecting a device while firmware is not present on the system, usbatm_usb_disconnect() waits for the heavy_init thread to finish: wait_for_completion(&instance->thread_exited); If CONFIG_FW_LOADER_USER_HELPER_FALLBACK is enabled, missing firmware causes request_firmware() to fall back to sysfs/udevd. This creates a circular dependency during disconnect: 1. usb_disconnect() holds device_lock(&udev->dev). 2. usbatm_usb_disconnect() waits for instance->thread to exit. 3. instance->thread waits for request_firmware() sysfs fallback. 4. udevd receives the firmware uevent and attempts to read sysfs attributes (e.g. serial), blocking on device_lock(&udev->dev). Furthermore, the fallback wait uses wait_for_completion_killable_timeout(), which ignores the non-fatal SIGTERM signal sent by usbatm_usb_disconnect(). Because speedtch and cxacru probe multiple candidate firmware files sequentially, each file stalls for the 60-second fallback timeout, triggering hung task timeouts (>120s) reported by syzbot. Switch to request_firmware_direct() to probe firmware files directly from the filesystem without falling back to user-mode helper. Cc: stable+noautosel@kernel.org # untested fix to a driver init path race Reported-by: syzbot+9ca2c9f85bd8b5e46516@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=9ca2c9f85bd8b5e46516 Signed-off-by: Matvey Valigura Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260924050654.15347-1-valigurasm@gmail.com Signed-off-by: Jakub Kicinski --- drivers/usb/atm/cxacru.c | 2 +- drivers/usb/atm/speedtch.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 75d87c31e81f..464510a44c9e 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c @@ -993,7 +993,7 @@ static int cxacru_find_firmware(struct cxacru_data *instance, sprintf(buf, "cxacru-%s.bin", phase); usb_dbg(usbatm, "cxacru_find_firmware: looking for %s\n", buf); - if (request_firmware(fw_p, buf, dev)) { + if (request_firmware_direct(fw_p, buf, dev)) { usb_dbg(usbatm, "no stage %s firmware found\n", phase); return -ENOENT; } diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index e5e021aafbd3..000f8eb24ead 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c @@ -357,15 +357,15 @@ static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interfa sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); - if (request_firmware(fw_p, buf, dev)) { + if (request_firmware_direct(fw_p, buf, dev)) { sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); - if (request_firmware(fw_p, buf, dev)) { + if (request_firmware_direct(fw_p, buf, dev)) { sprintf(buf, "speedtch-%d.bin", phase); usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); - if (request_firmware(fw_p, buf, dev)) { + if (request_firmware_direct(fw_p, buf, dev)) { usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase); return -ENOENT; } From 20d020a075366d201fc95001dc5b6cb92cb04195 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Mon, 28 Sep 2026 10:31:41 +0800 Subject: [PATCH 0923/2126] udp: fix auto-selected port colliding with an existing SO_REUSEPORT socket Observed with two independent servers in the same process: fd1 = socket(AF_INET, SOCK_DGRAM, 0); setsockopt(fd1, SOL_SOCKET, SO_REUSEPORT, ...); bind(fd1, port 0); /* got 40000 */ fd2 = socket(AF_INET, SOCK_DGRAM, 0); setsockopt(fd2, SOL_SOCKET, SO_REUSEPORT, ...); bind(fd2, port 0); /* got 40000 as well */ Both sockets end up on the same port and join the same reuseport group, so each of them takes part of the other's datagrams. The same port sharing happens with SO_REUSEADDR, without the reuseport group. udp_lib_lport_inuse() keeps the reuse rules when it scans for a free port: a socket with SO_REUSEADDR set, or one with SO_REUSEPORT and the same uid, is not a conflict, so its port is never marked in the bitmap and the scan can hand it out again. Those rules only make sense when the user asks for a specific port. bind(0) wants a free port and has no way to know whose port it lands on. TCP already does this: inet_csk_find_open_port() passes relax=false and reuseport_ok=false, so the scan treats every port in use as a conflict whatever options the sockets have. Commit aacd9289af8b ("tcp: bind() use stronger condition for bind_conflict") did it for SO_REUSEADDR and commit 0643ee4fd1b7 ("inet: Fix get port to handle zero port number with soreuseport set") for SO_REUSEPORT. Do the same for UDP: ignore both options during a scan, keep them for an explicit port. This changes bind(0) for SO_REUSEADDR sockets once the port range is full: it used to share a port and now fails with EADDRINUSE, like TCP. Sharing a port on purpose when the range is full is a feature, TCP has net.ipv4.ip_autobind_reuse for it, off by default. UDP can get the same knob later, this patch only fixes the scan. Fixes: ba418fa357a7 ("soreuseport: UDP/IPv4 implementation") Cc: stable+noautosel@kernel.org # bind() behaviour change Signed-off-by: Jiayuan Chen Link: https://patch.msgid.link/20260928023145.301855-1-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski --- net/ipv4/udp.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index b534b85bc623..303d0102519a 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -139,25 +139,26 @@ static int udp_lib_lport_inuse(struct net *net, __u16 num, kuid_t uid = sk_uid(sk); struct sock *sk2; + /* With @bitmap we are scanning for a free port: every port in use + * is marked, whatever reuse options the sockets have. Without it + * we are checking a specific port and honour the reuse options. + */ sk_for_each(sk2, &hslot->head) { if (net_eq(sock_net(sk2), net) && sk2 != sk && (bitmap || udp_sk(sk2)->udp_port_hash == num) && - (!sk2->sk_reuse || !sk->sk_reuse) && + (bitmap || !sk2->sk_reuse || !sk->sk_reuse) && (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if || sk2->sk_bound_dev_if == sk->sk_bound_dev_if) && inet_rcv_saddr_equal(sk, sk2, true)) { - if (sk2->sk_reuseport && sk->sk_reuseport && - !rcu_access_pointer(sk->sk_reuseport_cb) && - uid_eq(uid, sk_uid(sk2))) { - if (!bitmap) + if (!bitmap) { + if (sk2->sk_reuseport && sk->sk_reuseport && + !rcu_access_pointer(sk->sk_reuseport_cb) && + uid_eq(uid, sk_uid(sk2))) return 0; - } else { - if (!bitmap) - return 1; - __set_bit(udp_sk(sk2)->udp_port_hash >> log, - bitmap); + return 1; } + __set_bit(udp_sk(sk2)->udp_port_hash >> log, bitmap); } } return 0; From 883c308be4250b39403b83f85611d9e9c04b9d54 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Mon, 28 Sep 2026 10:31:42 +0800 Subject: [PATCH 0924/2126] selftests/net: check auto-selected port with reuse options Use IP_LOCAL_PORT_RANGE to limit a socket to 8 ports, bind 8 sockets to port 0 and check they get 8 distinct ports and the 9th bind fails with EADDRINUSE. Run it for the four combinations of reuse options on the sockets: none (existing test) SO_REUSEPORT SO_REUSEADDR SO_REUSEADDR + SO_REUSEPORT TCP passes all four. Before the udp fix UDP only passes the first one: the scan hands out a port already taken by a socket with the same reuse options, so fewer than 8 distinct ports come back and the 9th bind succeeds. # ./ip_local_port_range.sh Before: ok 13 ip_local_port_range.ip4_udp.exhaust_8_port_range not ok 14 ip_local_port_range.ip4_udp.exhaust_8_port_range_reuseport not ok 15 ip_local_port_range.ip4_udp.exhaust_8_port_range_reuseaddr not ok 16 ip_local_port_range.ip4_udp.exhaust_8_port_range_reuseaddr_reuseport ok 49 ip_local_port_range.ip6_udp.exhaust_8_port_range not ok 50 ip_local_port_range.ip6_udp.exhaust_8_port_range_reuseport not ok 51 ip_local_port_range.ip6_udp.exhaust_8_port_range_reuseaddr not ok 52 ip_local_port_range.ip6_udp.exhaust_8_port_range_reuseaddr_reuseport After: ok 13 ip_local_port_range.ip4_udp.exhaust_8_port_range ok 14 ip_local_port_range.ip4_udp.exhaust_8_port_range_reuseport ok 15 ip_local_port_range.ip4_udp.exhaust_8_port_range_reuseaddr ok 16 ip_local_port_range.ip4_udp.exhaust_8_port_range_reuseaddr_reuseport ok 49 ip_local_port_range.ip6_udp.exhaust_8_port_range ok 50 ip_local_port_range.ip6_udp.exhaust_8_port_range_reuseport ok 51 ip_local_port_range.ip6_udp.exhaust_8_port_range_reuseaddr ok 52 ip_local_port_range.ip6_udp.exhaust_8_port_range_reuseaddr_reuseport Signed-off-by: Jiayuan Chen Link: https://patch.msgid.link/20260928023145.301855-2-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski --- .../selftests/net/ip_local_port_range.c | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/ip_local_port_range.c b/tools/testing/selftests/net/ip_local_port_range.c index e6834a6cfc8f..3d32b33cba46 100644 --- a/tools/testing/selftests/net/ip_local_port_range.c +++ b/tools/testing/selftests/net/ip_local_port_range.c @@ -301,7 +301,27 @@ TEST_F(ip_local_port_range, single_port_range) } } -TEST_F(ip_local_port_range, exhaust_8_port_range) +#define REUSEADDR 0x1 +#define REUSEPORT 0x2 + +static int set_reuse_opts(int fd, unsigned int flags) +{ + int one = 1; + + if ((flags & REUSEADDR) && + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) + return -1; + + if ((flags & REUSEPORT) && + setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) + return -1; + + return 0; +} + +static void exhaust_8_port_range(struct __test_metadata *_metadata, + const FIXTURE_VARIANT(ip_local_port_range) *variant, + unsigned int flags) { __u8 port_set = 0; int i, fd, err; @@ -313,6 +333,9 @@ TEST_F(ip_local_port_range, exhaust_8_port_range) fd = socket(variant->so_domain, variant->so_type, variant->so_protocol); ASSERT_GE(fd, 0) TH_LOG("socket failed"); + err = set_reuse_opts(fd, flags); + ASSERT_TRUE(!err) TH_LOG("setsockopt(SO_REUSE*) failed"); + range = pack_port_range(40000, 40007); err = setsockopt(fd, SOL_IP, IP_LOCAL_PORT_RANGE, &range, sizeof(range)); ASSERT_TRUE(!err) TH_LOG("setsockopt(IP_LOCAL_PORT_RANGE) failed"); @@ -335,6 +358,9 @@ TEST_F(ip_local_port_range, exhaust_8_port_range) fd = socket(variant->so_domain, variant->so_type, variant->so_protocol); ASSERT_GE(fd, 0) TH_LOG("socket failed"); + err = set_reuse_opts(fd, flags); + ASSERT_TRUE(!err) TH_LOG("setsockopt(SO_REUSE*) failed"); + range = pack_port_range(40000, 40007); err = setsockopt(fd, SOL_IP, IP_LOCAL_PORT_RANGE, &range, sizeof(range)); ASSERT_TRUE(!err) TH_LOG("setsockopt(IP_LOCAL_PORT_RANGE) failed"); @@ -352,6 +378,30 @@ TEST_F(ip_local_port_range, exhaust_8_port_range) } } +TEST_F(ip_local_port_range, exhaust_8_port_range) +{ + exhaust_8_port_range(_metadata, variant, 0); +} + +/* Auto-selected port must not land on a port already taken by another + * socket, whatever reuse options both of them have, so all 8 sockets + * must get distinct ports. + */ +TEST_F(ip_local_port_range, exhaust_8_port_range_reuseport) +{ + exhaust_8_port_range(_metadata, variant, REUSEPORT); +} + +TEST_F(ip_local_port_range, exhaust_8_port_range_reuseaddr) +{ + exhaust_8_port_range(_metadata, variant, REUSEADDR); +} + +TEST_F(ip_local_port_range, exhaust_8_port_range_reuseaddr_reuseport) +{ + exhaust_8_port_range(_metadata, variant, REUSEADDR | REUSEPORT); +} + TEST_F(ip_local_port_range, late_bind) { union { From 679950fedec7a6ce5887c5e9f03de40a7cf7e56b Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 24 Sep 2026 16:35:37 +0800 Subject: [PATCH 0925/2126] net: dsa: use regmap_assign_bits() for conditional set/clear Replace if/else blocks using regmap_set_bits()/regmap_clear_bits() with the simpler regmap_assign_bits() calls in the lantiq gswip, mt7530 and qca8k drivers. Signed-off-by: Peng Fan Link: https://patch.msgid.link/20260924083538.461887-1-peng.fan@oss.nxp.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lantiq/lantiq_gswip_common.c | 8 ++------ drivers/net/dsa/mt7530.c | 10 ++-------- drivers/net/dsa/qca/qca8k-common.c | 15 +++------------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c index 6150dc3ffb64..20ed487f37ca 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c @@ -1279,12 +1279,8 @@ static int gswip_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) /* Enable MLEN for ports with non-standard MTUs, including the special * header on the CPU port added above. */ - if (new_mtu != ETH_DATA_LEN) - regmap_set_bits(priv->gswip, GSWIP_MAC_CTRL_2p(port), - GSWIP_MAC_CTRL_2_MLEN); - else - regmap_clear_bits(priv->gswip, GSWIP_MAC_CTRL_2p(port), - GSWIP_MAC_CTRL_2_MLEN); + regmap_assign_bits(priv->gswip, GSWIP_MAC_CTRL_2p(port), + GSWIP_MAC_CTRL_2_MLEN, new_mtu != ETH_DATA_LEN); return 0; } diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 50e80585d558..7781a63b4e6f 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2150,10 +2150,7 @@ mt7530_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) struct mt7530_priv *priv = gpiochip_get_data(gc); u32 bit = mt7530_gpio_to_bit(offset); - if (value) - regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); - else - regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); + regmap_assign_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit, value); return 0; } @@ -2191,10 +2188,7 @@ mt7530_gpio_direction_output(struct gpio_chip *gc, unsigned int offset, int valu regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DIR, bit); - if (value) - regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); - else - regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); + regmap_assign_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit, value); regmap_set_bits(priv->regmap, MT7530_LED_GPIO_OE, bit); diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c index 13005f10edb7..ab978cc8367f 100644 --- a/drivers/net/dsa/qca/qca8k-common.c +++ b/drivers/net/dsa/qca/qca8k-common.c @@ -471,10 +471,7 @@ void qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable) if (port > 0 && port < 6) mask |= QCA8K_PORT_STATUS_LINK_AUTO; - if (enable) - regmap_set_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask); - else - regmap_clear_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask); + regmap_assign_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask, enable); } void qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, @@ -562,14 +559,8 @@ static int qca8k_port_configure_learning(struct dsa_switch *ds, int port, { struct qca8k_priv *priv = ds->priv; - if (learning) - return regmap_set_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_LEARN); - else - return regmap_clear_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_LEARN); + return regmap_assign_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(port), + QCA8K_PORT_LOOKUP_LEARN, learning); } void qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) From a58cdf56b6eb6c9639c6cd9fae2f6819f6312f67 Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Mon, 28 Sep 2026 14:14:50 +0200 Subject: [PATCH 0926/2126] net: bcmgenet: complete Tx NAPI after one reclaim pass After reclaiming, the Tx poll asks to be polled again. That extra poll finds nothing to do and does not reduce the interrupt rate. Complete the NAPI and unmask the ring interrupt right after the reclaim. On a CM4 this raises 60 byte pktgen Tx from about 187k to 224k pps and saves about 5% of one core at TCP line rate. Signed-off-by: Nicolai Buchwitz Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260928121454.901306-1-nb@tipi-net.de Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index 21668e41b696..f17ad20b4b9c 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -2020,25 +2020,20 @@ static int bcmgenet_tx_poll(struct napi_struct *napi, int budget) { struct bcmgenet_tx_ring *ring = container_of(napi, struct bcmgenet_tx_ring, napi); - unsigned int work_done = 0; struct netdev_queue *txq; spin_lock(&ring->lock); - work_done = __bcmgenet_tx_reclaim(ring->priv->dev, ring); + __bcmgenet_tx_reclaim(ring->priv->dev, ring); if (ring->free_bds > (MAX_SKB_FRAGS + 1)) { txq = netdev_get_tx_queue(ring->priv->dev, ring->index); netif_tx_wake_queue(txq); } spin_unlock(&ring->lock); - if (work_done == 0) { - napi_complete(napi); + if (budget && napi_complete_done(napi, 0)) bcmgenet_tx_ring_int_enable(ring); - return 0; - } - - return budget; + return 0; } static void bcmgenet_tx_reclaim_all(struct net_device *dev) From be15d99d8ebc44b676c85737a1c09f5f7df317bd Mon Sep 17 00:00:00 2001 From: Arthur Crepin Leblond Date: Thu, 24 Sep 2026 11:48:11 +0200 Subject: [PATCH 0927/2126] dt-bindings: net: wiznet,w5100: convert to DT schema Convert the Wiznet w5x00 SPI Ethernet controller binding from plain text to DT schema. Change the trigger type from edge-falling to low to match the driver implementation. Add wiznet,w5100.yaml entry in MAINTAINERS. Signed-off-by: Arthur Crepin Leblond Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260924-wiznet-link-gpio-v11-1-42a332517b30@marmottus.net Signed-off-by: Jakub Kicinski --- .../devicetree/bindings/net/wiznet,w5100.yaml | 68 +++++++++++++++++++ .../devicetree/bindings/net/wiznet,w5x00.txt | 50 -------------- MAINTAINERS | 6 ++ 3 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/wiznet,w5100.yaml delete mode 100644 Documentation/devicetree/bindings/net/wiznet,w5x00.txt diff --git a/Documentation/devicetree/bindings/net/wiznet,w5100.yaml b/Documentation/devicetree/bindings/net/wiznet,w5100.yaml new file mode 100644 index 000000000000..df83f90b3919 --- /dev/null +++ b/Documentation/devicetree/bindings/net/wiznet,w5100.yaml @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/wiznet,w5100.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Wiznet w5100/w5200/w5500 SPI Ethernet Controller + +maintainers: + - Arthur Crepin Leblond + +description: | + This is a standalone 10/100 MBit Ethernet controller with SPI interface. + +allOf: + - $ref: /schemas/net/ethernet-controller.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + enum: + - wiznet,w5100 + - wiznet,w5200 + - wiznet,w5500 + + interrupts: + maxItems: 1 + description: Main interrupt (INT pin on the device). + + reg: + maxItems: 1 + + spi-max-frequency: + description: + According to the datasheets, w5500 and w5200 allow a maximum of 80 MHz + while w5100 is reported by users to allow a maximum of 14 MHz. However, + board designs may need to limit this value. + maximum: 80000000 + +required: + - compatible + - reg + - interrupts + +unevaluatedProperties: false + +examples: + - | + /* Example (for Raspberry Pi with pin control stuff for GPIO irq) */ + + #include + + spi { + #address-cells = <1>; + #size-cells = <0>; + + ethernet@0 { + compatible = "wiznet,w5500"; + reg = <0>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_LEVEL_LOW>; + local-mac-address = [ a0 b0 c0 d0 e0 f0 ]; + pinctrl-0 = <ð1_pins>; + pinctrl-names = "default"; + spi-max-frequency = <30000000>; + }; + }; +... diff --git a/Documentation/devicetree/bindings/net/wiznet,w5x00.txt b/Documentation/devicetree/bindings/net/wiznet,w5x00.txt deleted file mode 100644 index e9665798c4be..000000000000 --- a/Documentation/devicetree/bindings/net/wiznet,w5x00.txt +++ /dev/null @@ -1,50 +0,0 @@ -* Wiznet w5x00 - -This is a standalone 10/100 MBit Ethernet controller with SPI interface. - -For each device connected to a SPI bus, define a child node within -the SPI master node. - -Required properties: -- compatible: Should be one of the following strings: - "wiznet,w5100" - "wiznet,w5200" - "wiznet,w5500" -- reg: Specify the SPI chip select the chip is wired to. -- interrupts: Specify the interrupt index within the interrupt controller (referred - to above in interrupt-parent) and interrupt type. w5x00 natively - generates falling edge interrupts, however, additional board logic - might invert the signal. -- pinctrl-names: List of assigned state names, see pinctrl binding documentation. -- pinctrl-0: List of phandles to configure the GPIO pin used as interrupt line, - see also generic and your platform specific pinctrl binding - documentation. - -Optional properties: -- spi-max-frequency: Maximum frequency of the SPI bus when accessing the w5500. - According to the w5500 datasheet, the chip allows a maximum of 80 MHz, however, - board designs may need to limit this value. -- local-mac-address: See ethernet.txt in the same directory. - - -Example (for Raspberry Pi with pin control stuff for GPIO irq): - -&spi { - ethernet@0: w5500@0 { - compatible = "wiznet,w5500"; - reg = <0>; - pinctrl-names = "default"; - pinctrl-0 = <ð1_pins>; - interrupt-parent = <&gpio>; - interrupts = <25 IRQ_TYPE_EDGE_FALLING>; - spi-max-frequency = <30000000>; - }; -}; - -&gpio { - eth1_pins: eth1_pins { - brcm,pins = <25>; - brcm,function = <0>; /* in */ - brcm,pull = <0>; /* none */ - }; -}; diff --git a/MAINTAINERS b/MAINTAINERS index 6de1ff058db6..737f076f31c7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -29455,6 +29455,12 @@ M: Miloslav Trmac S: Maintained F: drivers/input/misc/wistron_btns.c +WIZNET W5100 ETHERNET BINDINGS +M: Arthur Crepin Leblond +L: netdev@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/net/wiznet,w5100.yaml + WMI BINARY MOF DRIVER M: Armin Wolf R: Thomas Weißschuh From 50c4bbaa0d36fb924649943159b6f4b73586e256 Mon Sep 17 00:00:00 2001 From: Arthur Crepin Leblond Date: Thu, 24 Sep 2026 11:48:12 +0200 Subject: [PATCH 0928/2126] dt-bindings: net: wiznet,w5100: add link status interrupt Add an optional link status interrupt which can be connected to the LINKLED pin on the device to detect link status changes. This second interrupt is only supported on wiznet,w5500. Signed-off-by: Arthur Crepin Leblond Acked-by: Conor Dooley Link: https://patch.msgid.link/20260924-wiznet-link-gpio-v11-2-42a332517b30@marmottus.net Signed-off-by: Jakub Kicinski --- .../devicetree/bindings/net/wiznet,w5100.yaml | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/net/wiznet,w5100.yaml b/Documentation/devicetree/bindings/net/wiznet,w5100.yaml index df83f90b3919..b0d1e1d699dc 100644 --- a/Documentation/devicetree/bindings/net/wiznet,w5100.yaml +++ b/Documentation/devicetree/bindings/net/wiznet,w5100.yaml @@ -12,10 +12,6 @@ maintainers: description: | This is a standalone 10/100 MBit Ethernet controller with SPI interface. -allOf: - - $ref: /schemas/net/ethernet-controller.yaml# - - $ref: /schemas/spi/spi-peripheral-props.yaml# - properties: compatible: enum: @@ -24,8 +20,16 @@ properties: - wiznet,w5500 interrupts: - maxItems: 1 - description: Main interrupt (INT pin on the device). + minItems: 1 + description: + The main interrupt (INT pin) is mandatory on all devices. The w5500 + additionally supports an optional second interrupt for link status changes + (LINKLED pin). If it is not specified, link state changes will not be + reported. + items: + - description: Main interrupt (INT pin on the device). + - description: + Optional interrupt for link status changes (LINKLED pin on w5500). reg: maxItems: 1 @@ -42,6 +46,21 @@ required: - reg - interrupts +allOf: + - $ref: /schemas/net/ethernet-controller.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + - if: + not: + properties: + compatible: + contains: + enum: + - wiznet,w5500 + then: + properties: + interrupts: + maxItems: 1 + unevaluatedProperties: false examples: @@ -58,7 +77,8 @@ examples: compatible = "wiznet,w5500"; reg = <0>; interrupt-parent = <&gpio>; - interrupts = <25 IRQ_TYPE_LEVEL_LOW>; + interrupts = <25 IRQ_TYPE_LEVEL_LOW>, + <24 IRQ_TYPE_EDGE_BOTH>; local-mac-address = [ a0 b0 c0 d0 e0 f0 ]; pinctrl-0 = <ð1_pins>; pinctrl-names = "default"; From 323767fa31a284b37703b59a1aaabb88162bfa37 Mon Sep 17 00:00:00 2001 From: Arthur Crepin Leblond Date: Thu, 24 Sep 2026 11:48:13 +0200 Subject: [PATCH 0929/2126] w5100: detect carrier state using link status bit and optional interrupt Detect the carrier state on the w5500 Ethernet controller using the Link Status bit from the PHY Configuration register (PHYCFGR). On w5100/w5200, which lack this register, get_link() is not implemented and the carrier state is not reported (netif_carrier_(on|off) is not called). For the w5500, add an optional interrupt, wired to the LINKLED pin of the device, to detect link status changes with a read of the PHYCFGR register and update of the carrier state with netif_carrier_(on|off). If this interrupt is not set in the DT binding, get_link() is not implemented and the carrier state is not reported (netif_carrier_(on|off) is not called). The interrupt handler and the PHYCFGR register readings are synchronized using a mutex. A few changes are also brought for the bring-up/teardown synchronization: - The net device is registered last in the probe() function so no operation can be performed before the probing is finished - The net device is unregistered first in remove() - dev_name is now used instead of netdev_name - w5100_stop() calls cancel_work_sync() and flush_work() to make sure there is no race condition or unfinished work - w5100_suspend() calls w5100_stop() - w5100_resume() calls w5100_open() - The main irq is not automatically enabled in w5100_probe() but in w5100_open() and disabled in w5100_stop() Commit dacf281771a9 ("w5100: remove unused gpio link detection") dropped the link_gpio/link_irq handling on the grounds that no devicetree user passed a "link" gpio at the time and that it used the old gpio interface. This isn't a plain revert of that removal: link detection is now done using a second interrupt rather than a gpio with a documented DT binding. Set the WIZNET entry as DRIVER and add drivers/net/ethernet/wiznet in MAINTAINERS file. Signed-off-by: Arthur Crepin Leblond Fixes: dacf281771a9 ("w5100: remove unused gpio link detection") Link: https://patch.msgid.link/20260924-wiznet-link-gpio-v11-3-42a332517b30@marmottus.net Signed-off-by: Jakub Kicinski --- MAINTAINERS | 3 +- drivers/net/ethernet/wiznet/w5100.c | 234 ++++++++++++++++++++++++---- 2 files changed, 206 insertions(+), 31 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 737f076f31c7..51873349ba91 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -29455,11 +29455,12 @@ M: Miloslav Trmac S: Maintained F: drivers/input/misc/wistron_btns.c -WIZNET W5100 ETHERNET BINDINGS +WIZNET W5100 ETHERNET DRIVER M: Arthur Crepin Leblond L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/wiznet,w5100.yaml +F: drivers/net/ethernet/wiznet/ WMI BINARY MOF DRIVER M: Armin Wolf diff --git a/drivers/net/ethernet/wiznet/w5100.c b/drivers/net/ethernet/wiznet/w5100.c index 53d8dc642fbd..dff39ba8103c 100644 --- a/drivers/net/ethernet/wiznet/w5100.c +++ b/drivers/net/ethernet/wiznet/w5100.c @@ -18,9 +18,11 @@ #include #include #include +#include #include #include #include +#include #include #include "w5100.h" @@ -124,6 +126,8 @@ MODULE_LICENSE("GPL"); */ #define W5500_SIMR 0x0018 /* Socket Interrupt Mask Register */ #define W5500_RTR 0x0019 /* Retry Time-value Register */ +#define W5500_PHYCFGR 0x002e /* PHY Configuration Register */ +#define PHYCFGR_LNK 0x01 /* Link status */ #define W5500_S0_REGS 0x10000 @@ -154,6 +158,9 @@ struct w5100_priv { u16 s0_rx_buf_size; int irq; + int link_irq; + /* Protects link state and carrier updates */ + struct mutex link_lock; struct napi_struct napi; struct net_device *ndev; @@ -345,6 +352,82 @@ static void w5500_memory_configure(struct w5100_priv *priv) } } +static int w5500_get_phycfgr_lnk(struct net_device *ndev) +{ + struct w5100_priv *priv = netdev_priv(ndev); + int retries = 3; + int ret; + + do { + ret = w5100_read(priv, W5500_PHYCFGR); + if (ret < 0) + netif_err(priv, link, ndev, + "failed to read link status: %d\n", ret); + } while (ret < 0 && --retries); + + if (ret < 0) + return ret; + + return ret & PHYCFGR_LNK; +} + +static void w5500_report_carrier_state(struct net_device *ndev) +{ + struct w5100_priv *priv = netdev_priv(ndev); + int state; + + mutex_lock(&priv->link_lock); + + state = w5500_get_phycfgr_lnk(ndev); + if (state > 0) { + netif_info(priv, link, ndev, "link is up\n"); + netif_carrier_on(ndev); + } else if (state == 0) { + netif_info(priv, link, ndev, "link is down\n"); + netif_carrier_off(ndev); + } + + mutex_unlock(&priv->link_lock); +} + +static irqreturn_t w5500_detect_link_interrupt(int irq, void *ndev_instance) +{ + struct net_device *ndev = ndev_instance; + + if (netif_running(ndev)) + w5500_report_carrier_state(ndev); + + return IRQ_HANDLED; +} + +static u32 w5500_get_link(struct net_device *ndev) +{ + struct w5100_priv *priv = netdev_priv(ndev); + int state; + bool link; + + mutex_lock(&priv->link_lock); + + if (!netif_device_present(ndev)) { + link = netif_carrier_ok(ndev); + goto out; + } + + state = w5500_get_phycfgr_lnk(ndev); + + if (state < 0) { + link = netif_carrier_ok(ndev); + goto out; + } + + link = state > 0; + +out: + mutex_unlock(&priv->link_lock); + + return link; +} + static int w5100_hw_reset(struct w5100_priv *priv) { u32 rtr; @@ -448,12 +531,28 @@ static void w5100_restart(struct net_device *ndev) { struct w5100_priv *priv = netdev_priv(ndev); + if (!netif_running(ndev) || !netif_device_present(ndev)) + return; + + disable_irq(priv->irq); + if (priv->link_irq > 0) + disable_irq(priv->link_irq); + netif_stop_queue(ndev); + w5100_hw_close(priv); + flush_work(&priv->rx_work); + flush_work(&priv->tx_work); w5100_hw_reset(priv); + enable_irq(priv->irq); w5100_hw_start(priv); ndev->stats.tx_errors++; netif_trans_update(ndev); netif_wake_queue(ndev); + + if (priv->link_irq > 0) { + enable_irq(priv->link_irq); + w5500_report_carrier_state(ndev); + } } static void w5100_restart_work(struct work_struct *work) @@ -468,10 +567,7 @@ static void w5100_tx_timeout(struct net_device *ndev, unsigned int txqueue) { struct w5100_priv *priv = netdev_priv(ndev); - if (priv->ops->may_sleep) - schedule_work(&priv->restart_work); - else - w5100_restart(ndev); + schedule_work(&priv->restart_work); } static void w5100_tx_skb(struct net_device *ndev, struct sk_buff *skb) @@ -564,7 +660,8 @@ static void w5100_rx_work(struct work_struct *work) while ((skb = w5100_rx_skb(priv->ndev))) netif_rx(skb); - w5100_enable_intr(priv); + if (netif_running(priv->ndev)) + w5100_enable_intr(priv); } static int w5100_napi_poll(struct napi_struct *napi, int budget) @@ -656,9 +753,17 @@ static int w5100_open(struct net_device *ndev) struct w5100_priv *priv = netdev_priv(ndev); netif_info(priv, ifup, ndev, "enabling\n"); + w5100_hw_reset(priv); + enable_irq(priv->irq); w5100_hw_start(priv); napi_enable(&priv->napi); netif_start_queue(ndev); + + if (priv->link_irq > 0) { + enable_irq(priv->link_irq); + w5500_report_carrier_state(ndev); + } + return 0; } @@ -667,13 +772,40 @@ static int w5100_stop(struct net_device *ndev) struct w5100_priv *priv = netdev_priv(ndev); netif_info(priv, ifdown, ndev, "shutting down\n"); - w5100_hw_close(priv); - netif_carrier_off(ndev); + + disable_irq(priv->irq); + if (priv->link_irq > 0) + disable_irq(priv->link_irq); + netif_stop_queue(ndev); napi_disable(&priv->napi); + + cancel_work_sync(&priv->restart_work); + cancel_work_sync(&priv->setrx_work); + + w5100_hw_close(priv); + + flush_work(&priv->rx_work); + flush_work(&priv->tx_work); + + if (priv->link_irq > 0) { + mutex_lock(&priv->link_lock); + netif_carrier_off(ndev); + mutex_unlock(&priv->link_lock); + } + return 0; } +static const struct ethtool_ops w5500_ethtool_ops = { + .get_drvinfo = w5100_get_drvinfo, + .get_msglevel = w5100_get_msglevel, + .set_msglevel = w5100_set_msglevel, + .get_link = w5500_get_link, + .get_regs_len = w5100_get_regs_len, + .get_regs = w5100_get_regs, +}; + static const struct ethtool_ops w5100_ethtool_ops = { .get_drvinfo = w5100_get_drvinfo, .get_msglevel = w5100_get_msglevel, @@ -721,6 +853,8 @@ int w5100_probe(struct device *dev, const struct w5100_ops *ops, dev_set_drvdata(dev, ndev); priv = netdev_priv(ndev); + mutex_init(&priv->link_lock); + switch (ops->chip_id) { case W5100: priv->s0_regs = W5100_S0_REGS; @@ -745,15 +879,27 @@ int w5100_probe(struct device *dev, const struct w5100_ops *ops, break; default: err = -EINVAL; - goto err_register; + goto err_mutex; } priv->ndev = ndev; priv->ops = ops; priv->irq = irq; + priv->link_irq = -EINVAL; + if (ops->chip_id == W5500) { + priv->link_irq = fwnode_irq_get(dev_fwnode(dev), 1); + if (priv->link_irq == -EPROBE_DEFER) { + err = dev_err_probe(dev, priv->link_irq, + "failed to get link irq\n"); + goto err_mutex; + } + } + ndev->netdev_ops = &w5100_netdev_ops; - ndev->ethtool_ops = &w5100_ethtool_ops; + ndev->ethtool_ops = priv->link_irq > 0 ? &w5500_ethtool_ops : + &w5100_ethtool_ops; + netif_napi_add_weight(ndev, &priv->napi, w5100_napi_poll, 16); /* This chip doesn't support VLAN packets with normal MTU, @@ -761,15 +907,11 @@ int w5100_probe(struct device *dev, const struct w5100_ops *ops, */ ndev->features |= NETIF_F_VLAN_CHALLENGED; - err = register_netdev(ndev); - if (err < 0) - goto err_register; - priv->xfer_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_PERCPU, 0, - netdev_name(ndev)); + dev_name(dev)); if (!priv->xfer_wq) { err = -ENOMEM; - goto err_wq; + goto err_mutex; } INIT_WORK(&priv->rx_work, w5100_rx_work); @@ -794,22 +936,45 @@ int w5100_probe(struct device *dev, const struct w5100_ops *ops, if (ops->may_sleep) { err = request_threaded_irq(priv->irq, NULL, w5100_interrupt, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, - netdev_name(ndev), ndev); + IRQF_TRIGGER_LOW | IRQF_ONESHOT | + IRQF_NO_AUTOEN, + dev_name(dev), ndev); } else { err = request_irq(priv->irq, w5100_interrupt, - IRQF_TRIGGER_LOW, netdev_name(ndev), ndev); + IRQF_TRIGGER_LOW | IRQF_NO_AUTOEN, + dev_name(dev), ndev); } if (err) goto err_hw; + if (priv->link_irq > 0) { + err = request_threaded_irq(priv->link_irq, NULL, + w5500_detect_link_interrupt, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT | IRQF_NO_AUTOEN, + "w5100-link", ndev); + if (err < 0) + goto err_irq; + + netif_carrier_off(ndev); + } + + err = register_netdev(ndev); + if (err < 0) + goto err_link_irq; + return 0; +err_link_irq: + if (priv->link_irq > 0) + free_irq(priv->link_irq, ndev); +err_irq: + free_irq(priv->irq, ndev); err_hw: destroy_workqueue(priv->xfer_wq); -err_wq: - unregister_netdev(ndev); -err_register: +err_mutex: + mutex_destroy(&priv->link_lock); free_netdev(ndev); return err; } @@ -820,14 +985,21 @@ void w5100_remove(struct device *dev) struct net_device *ndev = dev_get_drvdata(dev); struct w5100_priv *priv = netdev_priv(ndev); - w5100_hw_reset(priv); + unregister_netdev(ndev); + + if (priv->link_irq > 0) + free_irq(priv->link_irq, ndev); free_irq(priv->irq, ndev); - flush_work(&priv->setrx_work); - flush_work(&priv->restart_work); - destroy_workqueue(priv->xfer_wq); + cancel_work_sync(&priv->setrx_work); + cancel_work_sync(&priv->restart_work); + flush_work(&priv->rx_work); + flush_work(&priv->tx_work); - unregister_netdev(ndev); + w5100_hw_reset(priv); + + destroy_workqueue(priv->xfer_wq); + mutex_destroy(&priv->link_lock); free_netdev(ndev); } EXPORT_SYMBOL_GPL(w5100_remove); @@ -839,10 +1011,11 @@ static int w5100_suspend(struct device *dev) struct w5100_priv *priv = netdev_priv(ndev); if (netif_running(ndev)) { - netif_carrier_off(ndev); + mutex_lock(&priv->link_lock); netif_device_detach(ndev); + mutex_unlock(&priv->link_lock); - w5100_hw_close(priv); + w5100_stop(ndev); } return 0; } @@ -853,10 +1026,11 @@ static int w5100_resume(struct device *dev) struct w5100_priv *priv = netdev_priv(ndev); if (netif_running(ndev)) { - w5100_hw_reset(priv); - w5100_hw_start(priv); + w5100_open(ndev); + mutex_lock(&priv->link_lock); netif_device_attach(ndev); + mutex_unlock(&priv->link_lock); } return 0; } From 24717a02aee4c169f237b7216d0caa498f3513e7 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 23 Sep 2026 01:34:18 +0000 Subject: [PATCH 0930/2126] ipv6: update NUD_FAILED neighbors from NA messages Transition a FAILED neighbor entry to STALE upon receipt of an NA message on routers when accept_untracked_na is enabled. This extends the RFC 9131 accept_untracked_na behavior so that FAILED entries are treated the same as non-existent entries. RFC 4861 section 7.3.3 says that an entry should be deleted when address resolution fails. Linux instead retains the entry in NUD_FAILED, so treating it as untracked is consistent with the protocol model. Trying to resolve FAILED neighbors via periodic probing (e.g. using NTF_EXT_MANAGED) is more work compared to this approach which uses information in NAs that the kernel may already be receiving. Note that because this behavior in IPv6 is dependent on the accept_untracked_na sysctl setting, this approach is more conservative than IPv4 which transitions FAILED neighbors to STALE by default upon receiving GARPs. Link: https://lore.kernel.org/r/20260813233344.445265-1-lfqlee314@gmail.com Signed-off-by: Lawrence Lee Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/6be400e601f4ffa59e47ddb5daa33ecdd85dd88b.1790127207.git.lfqlee314@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/ip-sysctl.rst | 28 ++++++++------- net/ipv6/ndisc.c | 47 ++++++++++++++------------ 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index f7af0286341c..685c84cf543d 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -3225,18 +3225,19 @@ drop_unsolicited_na - BOOLEAN Default: 0 (disabled). accept_untracked_na - INTEGER - Define behavior for accepting neighbor advertisements from devices that - are absent in the neighbor cache: + Define behavior for accepting neighbor advertisements for IPv6 addresses + that are absent from the neighbor cache or whose entries are in FAILED + state: - - 0 - (default) Do not accept unsolicited and untracked neighbor - advertisements. + - 0 - (default) Do not create new neighbor cache entries or update + FAILED entries from neighbor advertisements. - - 1 - Add a new neighbor cache entry in STALE state for routers on - receiving a neighbor advertisement (either solicited or unsolicited) - with target link-layer address option specified if no neighbor entry - is already present for the advertised IPv6 address. Without this knob, - NAs received for untracked addresses (absent in neighbor cache) are - silently ignored. + - 1 - For routers, add a new neighbor cache entry or update an existing + FAILED entry to STALE upon receiving a neighbor advertisement (either + solicited or unsolicited) with the target link-layer address option + specified. Without this knob, NAs received for untracked addresses + (absent from the neighbor cache or in FAILED state) are silently + ignored. This is as per router-side behavior documented in RFC9131. @@ -3251,9 +3252,10 @@ accept_untracked_na - INTEGER used in conjunction with the ndisc_notify setting on the host to satisfy this prerequisite. - - 2 - Extend option (1) to add a new neighbor cache entry only if the - source IP address is in the same subnet as an address configured on - the interface that received the neighbor advertisement. + - 2 - Extend option (1) to add a new neighbor cache entry or update a + FAILED entry only if the source IP address is in the same subnet as + an address configured on the interface that received the neighbor + advertisement. enhanced_dad - BOOLEAN Include a nonce option in the IPv6 neighbor solicitation messages used for diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 90cd5d852569..12d85d7f8234 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -973,13 +973,13 @@ out: static int accept_untracked_na(struct inet6_dev *idev, struct in6_addr *saddr) { switch (READ_ONCE(idev->cnf.accept_untracked_na)) { - case 0: /* Don't accept untracked na (absent in neighbor cache) */ + case 0: /* Don't accept untracked NA (absent or FAILED) */ return 0; - case 1: /* Create new entries from na if currently untracked */ + case 1: /* Create new or update FAILED entries from NA */ return 1; - case 2: /* Create new entries from untracked na only if saddr is in the + case 2: /* Create new or update FAILED entries only if saddr is in the * same subnet as an address configured on the interface that - * received the na + * received the NA */ return !!ipv6_chk_prefix(saddr, idev->dev); default: @@ -1067,34 +1067,39 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) neigh = neigh_lookup(tbl, &msg->target, dev); /* RFC 9131 updates original Neighbour Discovery RFC 4861. - * NAs with Target LL Address option without a corresponding - * entry in the neighbour cache can now create a STALE neighbour - * cache entry on routers. + * NAs with Target LL Address option can now create a STALE neighbor + * cache entry on routers if the NA does not have a corresponding entry + * in the neighbour cache or has a corresponding FAILED entry. * - * entry accept fwding solicited behaviour - * ------- ------ ------ --------- ---------------------- - * present X X 0 Set state to STALE - * present X X 1 Set state to REACHABLE - * absent 0 X X Do nothing - * absent 1 0 X Do nothing - * absent 1 1 X Add a new STALE entry + * entry accept fwding solicited behaviour + * ----------- ------ ------ --------- ---------------------- + * non-FAILED X X 0 Set state to STALE + * non-FAILED X X 1 Set state to REACHABLE + * FAILED 0 X X Do nothing + * FAILED 1 0 X Do nothing + * FAILED 1 1 X Set state to STALE + * absent 0 X X Do nothing + * absent 1 0 X Do nothing + * absent 1 1 X Add a new STALE entry * * Note that we don't do a (daddr == all-routers-mcast) check. */ new_state = msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE; - if (!neigh && lladdr && idev && READ_ONCE(idev->cnf.forwarding)) { - if (accept_untracked_na(idev, saddr)) { - neigh = neigh_create(tbl, &msg->target, dev); - new_state = NUD_STALE; + if (!neigh || (READ_ONCE(neigh->nud_state) & NUD_FAILED)) { + if (!lladdr || !idev || !READ_ONCE(idev->cnf.forwarding) || + !accept_untracked_na(idev, saddr)) { + if (neigh) + neigh_release(neigh); + return reason; } + if (!neigh) + neigh = neigh_create(tbl, &msg->target, dev); + new_state = NUD_STALE; } if (neigh && !IS_ERR(neigh)) { u8 old_flags = neigh->flags; - if (READ_ONCE(neigh->nud_state) & NUD_FAILED) - goto out; - /* * Don't update the neighbor cache entry on a proxy NA from * ourselves because either the proxied node is off link or it From 022e48e207760a7297eb41df138481df682e9f14 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 23 Sep 2026 01:34:19 +0000 Subject: [PATCH 0931/2126] selftests: net: test untracked NA recovery of FAILED neighbors Seed a FAILED neighbor before triggering an unsolicited NA. Verify that the entry transitions to STALE and learns the advertised link-layer address only when drop_unsolicited_na is disabled, accept_untracked_na mode 1 or in-prefix mode 2 is enabled, and IPv6 forwarding is enabled. Verify that disabling each gate keeps the entry in FAILED without a link-layer address. Mark the seed externally learned and disable carrier-based eviction so the entry cannot be garbage-collected before the NA arrives. Require the marker after processing to prove that a recovered entry was updated in place instead of deleted and recreated. Keep the NA source, target, and neighbor key fixed for the mode 2 cases. Vary the prefix configured on the router to exercise the source-prefix check without changing the entry under test. Arm packet capture before bringing up the host interface and starting DAD. Wait for the capture to become ready and for tcpdump to exit so the NA cannot be missed and receive processing is complete before checking the neighbor entry. Preserve the return code from test_unsolicited_na_common() before constructing the test description. The array assignment previously reset the return code to zero and caused existing cases to report false success. Link: https://lore.kernel.org/r/20260813233344.445265-1-lfqlee314@gmail.com Signed-off-by: Lawrence Lee Link: https://patch.msgid.link/ce40008682ed26ab039168a5fcb515eff8d30c3a.1790127207.git.lfqlee314@gmail.com Signed-off-by: Jakub Kicinski --- .../net/ndisc_unsolicited_na_test.sh | 197 ++++++++++++++---- 1 file changed, 161 insertions(+), 36 deletions(-) diff --git a/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh b/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh index 5db69dad0cfc..ba9e670b5149 100755 --- a/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh +++ b/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh @@ -3,12 +3,18 @@ # This test is for the accept_untracked_na feature to # enable RFC9131 behaviour. The following is the test-matrix. -# drop accept fwding behaviour -# ---- ------ ------ ---------------------------------------------- -# 1 X X Don't update NC -# 0 0 X Don't update NC -# 0 1 0 Don't update NC -# 0 1 1 Add a STALE NC entry +# state drop accept fwding behaviour +# ------ ---- ------ ------ ---------------------------------------------- +# absent 1 X X Don't update NC +# absent 0 0 X Don't update NC +# absent 0 1 0 Don't update NC +# absent 0 1 1 Add a STALE NC entry +# failed 1 X X Keep the NC entry in FAILED state +# failed 0 0 X Keep the NC entry in FAILED state +# failed 0 1 0 Keep the NC entry in FAILED state +# failed 0 1 1 Update the NC entry to STALE +# failed 0 2 1 Update the NC entry to STALE if in-network +# failed 0 2 1 Keep the NC entry FAILED if out-of-network source lib.sh ret=0 @@ -19,14 +25,18 @@ PAUSE=no HOST_INTF="veth-host" ROUTER_INTF="veth-router" -ROUTER_ADDR="2000:20::1" +ROUTER_ADDR_IN_NETWORK="2000:20::1" +ROUTER_ADDR_OUT_OF_NETWORK="2000:21::1" +ROUTER_ADDR="${ROUTER_ADDR_IN_NETWORK}" HOST_ADDR="2000:20::2" +HOST_LLADDR="02:00:00:00:00:02" SUBNET_WIDTH=64 ROUTER_ADDR_WITH_MASK="${ROUTER_ADDR}/${SUBNET_WIDTH}" HOST_ADDR_WITH_MASK="${HOST_ADDR}/${SUBNET_WIDTH}" tcpdump_stdout= tcpdump_stderr= +tcpdump_pid= log_test() { @@ -75,6 +85,7 @@ setup() ${IP_ROUTER} link add ${ROUTER_INTF} type veth \ peer name ${HOST_INTF} netns ${HOST_NS} + ${IP_HOST} link set dev "${HOST_INTF}" address "${HOST_LLADDR}" # Enable IPv6 on both router and host, and configure static addresses. # The router here is the DUT @@ -88,6 +99,8 @@ setup() ${ROUTER_CONF}.drop_unsolicited_na=${drop_unsolicited_na} ${IP_ROUTER_EXEC} sysctl -qw \ ${ROUTER_CONF}.accept_untracked_na=${accept_untracked_na} + ${IP_ROUTER_EXEC} sysctl -qw \ + ${ROUTER_CONF}.ndisc_evict_nocarrier=0 ${IP_ROUTER_EXEC} sysctl -qw ${ROUTER_CONF}.disable_ipv6=0 ${IP_ROUTER} addr add ${ROUTER_ADDR_WITH_MASK} dev ${ROUTER_INTF} @@ -102,24 +115,39 @@ setup() } start_tcpdump() { - set -e - tcpdump_stdout=`mktemp` - tcpdump_stderr=`mktemp` + tcpdump_stdout=$(mktemp) || return 1 + tcpdump_stderr=$(mktemp) || return 1 ${IP_ROUTER_EXEC} timeout 15s \ tcpdump --immediate-mode -tpni ${ROUTER_INTF} -c 1 \ "icmp6 && icmp6[0] == 136 && src ${HOST_ADDR}" \ - > ${tcpdump_stdout} 2> /dev/null - set +e + > "${tcpdump_stdout}" 2> "${tcpdump_stderr}" & + tcpdump_pid=$! + + slowwait 5 grep -q "listening on ${ROUTER_INTF}" "${tcpdump_stderr}" +} + +wait_tcpdump() +{ + local rc + + wait "${tcpdump_pid}" + rc=$? + tcpdump_pid= + + return "${rc}" } cleanup_tcpdump() { - set -e - [[ ! -z ${tcpdump_stdout} ]] && rm -f ${tcpdump_stdout} - [[ ! -z ${tcpdump_stderr} ]] && rm -f ${tcpdump_stderr} + if [ -n "${tcpdump_pid}" ]; then + kill "${tcpdump_pid}" 2> /dev/null + wait "${tcpdump_pid}" 2> /dev/null + fi + [ -n "${tcpdump_stdout}" ] && rm -f "${tcpdump_stdout}" + [ -n "${tcpdump_stderr}" ] && rm -f "${tcpdump_stderr}" tcpdump_stdout= tcpdump_stderr= - set +e + tcpdump_pid= } cleanup() @@ -129,58 +157,145 @@ cleanup() ip netns del ${ROUTER_NS} } -link_up() { - set -e +router_link_up() +{ ${IP_ROUTER} link set dev ${ROUTER_INTF} up +} + +host_link_up() +{ ${IP_HOST} link set dev ${HOST_INTF} up - set +e } verify_ndisc() { local drop_unsolicited_na=$1 local accept_untracked_na=$2 local forwarding=$3 + local initial_state=${4:-absent} + local same_subnet=${5:-1} + local expected_lladdr + local neigh_show_output + local expected_state - neigh_show_output=$(${IP_ROUTER} neigh show \ - to ${HOST_ADDR} dev ${ROUTER_INTF} nud stale) - if [ ${drop_unsolicited_na} -eq 0 ] && \ - [ ${accept_untracked_na} -eq 1 ] && \ - [ ${forwarding} -eq 1 ]; then - # Neighbour entry expected to be present for 011 case - [[ ${neigh_show_output} ]] + if [ "${drop_unsolicited_na}" -eq 0 ] && + [ "${forwarding}" -eq 1 ]; then + case "${accept_untracked_na}" in + 1) + expected_state=STALE + expected_lladdr="${HOST_LLADDR}" + ;; + 2) + if [ "${same_subnet}" -eq 1 ]; then + expected_state=STALE + expected_lladdr="${HOST_LLADDR}" + fi + ;; + esac + fi + if [ -z "${expected_state}" ] && + [ "${initial_state}" = "failed" ]; then + expected_state=FAILED + fi + + if [ -n "${expected_state}" ]; then + neigh_show_output=$(${IP_ROUTER} neigh show \ + to "${HOST_ADDR}" dev "${ROUTER_INTF}") + if [[ " ${neigh_show_output} " != \ + *" ${expected_state} "* ]]; then + return 1 + fi + if [ -n "${expected_lladdr}" ] && + [[ " ${neigh_show_output} " != \ + *" lladdr ${expected_lladdr} "* ]]; then + return 1 + fi + if [[ "${expected_state}" == "FAILED" && + "${neigh_show_output}" == *"lladdr"* ]]; then + return 1 + fi + if [ "${initial_state}" = "failed" ]; then + [[ "${neigh_show_output}" == *"extern_learn"* ]] + fi else - # Neighbour entry expected to be absent for all other cases + neigh_show_output=$(${IP_ROUTER} neigh show \ + to "${HOST_ADDR}" dev "${ROUTER_INTF}") [[ -z ${neigh_show_output} ]] fi } test_unsolicited_na_common() { - # Setup the test bed, but keep links down - setup $1 $2 $3 + local same_subnet=${5:-1} + local neigh_show_output - # Bring the link up, wait for the NA, - # and add a delay to ensure neighbour processing is done. - link_up - start_tcpdump + if [ "${same_subnet}" -eq 1 ]; then + ROUTER_ADDR="${ROUTER_ADDR_IN_NETWORK}" + else + ROUTER_ADDR="${ROUTER_ADDR_OUT_OF_NETWORK}" + fi + ROUTER_ADDR_WITH_MASK="${ROUTER_ADDR}/${SUBNET_WIDTH}" + + # Setup the test bed, but keep links down + setup "$1" "$2" "$3" + + if [ "${4:-absent}" = "failed" ]; then + if ! ${IP_ROUTER} neigh replace "${HOST_ADDR}" \ + dev "${ROUTER_INTF}" \ + nud failed extern_learn; then + echo "Unable to create NUD_FAILED neighbor entry" + return 1 + fi + neigh_show_output=$(${IP_ROUTER} neigh show \ + to "${HOST_ADDR}" dev "${ROUTER_INTF}") + if [[ " ${neigh_show_output} " != *" FAILED "* ]]; then + echo "Unable to verify NUD_FAILED neighbor entry" + return 1 + fi + if [[ "${neigh_show_output}" != *"extern_learn"* ]]; then + echo "Neighbor entry is not externally learned" + return 1 + fi + fi + + # Arm the capture before bringing up the host and starting DAD. + router_link_up || return 1 + start_tcpdump || return 1 + host_link_up || return 1 + + # Closing tcpdump's packet socket calls synchronize_net(), so waiting + # for it also waits for receive processing of the captured NA. + wait_tcpdump || return 1 # Verify the neighbour table - verify_ndisc $1 $2 $3 + verify_ndisc "$1" "$2" "$3" "$4" "${same_subnet}" } test_unsolicited_na_combination() { - test_unsolicited_na_common $1 $2 $3 + local initial_state=${4:-absent} + local same_subnet=${5:-1} + local rc + + test_unsolicited_na_common "$1" "$2" "$3" "${initial_state}" \ + "${same_subnet}" + rc=$? test_msg=("test_unsolicited_na: " "drop_unsolicited_na=$1 " "accept_untracked_na=$2 " "forwarding=$3") - log_test $? 0 "${test_msg[*]}" + if [ "${initial_state}" = "failed" ]; then + test_msg+=("initial_state=failed") + fi + if [ "$2" -eq 2 ]; then + test_msg+=("same_subnet=${same_subnet}") + fi + log_test "${rc}" 0 "${test_msg[*]}" cleanup } test_unsolicited_na_combinations() { # Args: drop_unsolicited_na accept_untracked_na forwarding + # [initial_state] [same_subnet] # Expect entry test_unsolicited_na_combination 0 1 1 @@ -193,6 +308,16 @@ test_unsolicited_na_combinations() { test_unsolicited_na_combination 1 0 1 test_unsolicited_na_combination 1 1 0 test_unsolicited_na_combination 1 1 1 + + # Expect FAILED entry to become STALE + test_unsolicited_na_combination 0 1 1 failed + test_unsolicited_na_combination 0 2 1 failed 1 + + # Expect FAILED entry to remain FAILED + test_unsolicited_na_combination 0 0 1 failed + test_unsolicited_na_combination 0 1 0 failed + test_unsolicited_na_combination 1 1 1 failed + test_unsolicited_na_combination 0 2 1 failed 0 } ############################################################################### From 549f5f48f10ef5affc48aebed52c686338fdb899 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 26 Sep 2026 14:56:13 +0300 Subject: [PATCH 0932/2126] net: enetc: document enetc_msg_vsi_send() return values Smatch combines the return values together and wants all the callers to handle the positive values so it leads to static checker warnings. Add a comment explaining the return values. Generally functions which return non-standard values should have a comment. Signed-off-by: Dan Carpenter Link: https://patch.msgid.link/09f24cefc214455305543a0528ceae6349c77419.1790357822.git.error27@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/enetc/enetc_vf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c index ee9567998c7c..f70b6d4290f2 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c @@ -48,6 +48,10 @@ static void enetc_msg_dma_free(struct device *dev, struct enetc_msg_swbd *msg) } } +/* + * Returns: 0 on success, a negative errno on failure, or the positive IP + * minor revision for an ENETC_MSG_GET_IP_MN request. + */ static int enetc_msg_vsi_send(struct enetc_si *si, struct enetc_msg_swbd *msg) { struct device *dev = &si->pdev->dev; From fee9c17671b6fc008398ad389434eeb134e028fe Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Sun, 27 Sep 2026 12:52:19 -0600 Subject: [PATCH 0933/2126] net: stmmac: sun8i: reset the MAC after PHY initialization The MAC software reset needs a running receive clock from the PHY. Resetting the MAC at the end of probe therefore fails when the PHY driver has not been loaded or its probe has deferred on a missing supplier. The failure removes the MAC and its MDIO bus, so loading the missing driver later cannot recover the interface without reprobing the MAC. Perform the software reset in the DMA reset callback instead. The stmmac core calls it during hardware setup after attaching and initializing the PHY, and resumes a suspended PHY before reopening or resuming the MAC. Mask interrupts before requesting the reset and retain the existing DMA and interrupt-register clearing even if the reset times out. Return reset errors through the normal hardware-setup error path. Remove the unconditional reset from probe. Keep the separate H3 MDIO-mux reset after switching the mux and powering the selected PHY, since it is needed to latch the selected interface before MDIO accesses. Tested-by: Maxime Chevallier Reviewed-by: Maxime Chevallier Signed-off-by: James Hilliard Link: https://patch.msgid.link/20260927-submit-h616-emac1-v1-v6-1-e64971f4e414@gmail.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 38d7e71de925..5691da796454 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -269,11 +269,33 @@ static const struct emac_variant emac_variant_h6 = { #define SYSCON_ETCS_EXT_GMII 0x1 #define SYSCON_ETCS_INT_GMII 0x2 +static int sun8i_dwmac_reset(void __iomem *ioaddr) +{ + u32 v; + + v = readl(ioaddr + EMAC_BASIC_CTL1); + writel(v | 0x01, ioaddr + EMAC_BASIC_CTL1); + + /* The timeout was previously set to 10ms, but some board (OrangePI0) + * need more if no cable plugged. 100ms seems OK + */ + return readl_poll_timeout(ioaddr + EMAC_BASIC_CTL1, v, + !(v & 0x01), 100, 100000); +} + /* sun8i_dwmac_dma_reset() - reset the EMAC * Called from stmmac via stmmac_dma_ops->reset */ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr) { + int ret; + + writel(0, ioaddr + EMAC_INT_EN); + + /* The PHY receive clock must be running for the reset to complete. */ + ret = sun8i_dwmac_reset(ioaddr); + + /* Leave DMA and interrupts disabled even if the reset timed out. */ writel(0, ioaddr + EMAC_RX_CTL1); writel(0, ioaddr + EMAC_TX_CTL1); writel(0, ioaddr + EMAC_RX_FRM_FLT); @@ -281,7 +303,7 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr) writel(0, ioaddr + EMAC_TX_DESC_LIST); writel(0, ioaddr + EMAC_INT_EN); writel(0x1FFFFFF, ioaddr + EMAC_INT_STA); - return 0; + return ret; } /* sun8i_dwmac_dma_init() - initialize the EMAC @@ -738,27 +760,6 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw, writel(v, ioaddr + EMAC_TX_FLOW_CTL); } -static int sun8i_dwmac_reset(struct stmmac_priv *priv) -{ - u32 v; - int err; - - v = readl(priv->ioaddr + EMAC_BASIC_CTL1); - writel(v | 0x01, priv->ioaddr + EMAC_BASIC_CTL1); - - /* The timeout was previously set to 10ms, but some board (OrangePI0) - * need more if no cable plugged. 100ms seems OK - */ - err = readl_poll_timeout(priv->ioaddr + EMAC_BASIC_CTL1, v, - !(v & 0x01), 100, 100000); - - if (err) { - dev_err(priv->device, "EMAC reset timeout\n"); - return err; - } - return 0; -} - /* Search in mdio-mux node for internal PHY node and get its clk/reset */ static int get_ephy_nodes(struct stmmac_priv *priv) { @@ -899,7 +900,9 @@ static int mdio_mux_syscon_switch_fn(int current_child, int desired_child, /* After changing syscon value, the MAC need reset or it will * use the last value (and so the last PHY set). */ - ret = sun8i_dwmac_reset(priv); + ret = sun8i_dwmac_reset(priv->ioaddr); + if (ret) + dev_err(priv->device, "EMAC reset timeout\n"); } return ret; } @@ -1221,10 +1224,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to register mux\n"); goto dwmac_mux; } - } else { - ret = sun8i_dwmac_reset(priv); - if (ret) - goto dwmac_remove; } pm_runtime_put(&pdev->dev); From 1cf9c2ac57fdb89f93976bd698c93a8fa2129e03 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Sun, 27 Sep 2026 12:52:20 -0600 Subject: [PATCH 0934/2126] dt-bindings: net: allwinner: add H616 EMAC1 The H616 secondary EMAC uses a separate system-control clock register and supports only RMII at 10/100 Mbps. Add its distinct compatible without an older fallback, since using the primary EMAC clock register would not work. Constrain the PHY interface mode to RMII, matching the hardware. Reviewed-by: Andre Przywara Reviewed-by: Krzysztof Kozlowski Signed-off-by: James Hilliard Link: https://patch.msgid.link/20260927-submit-h616-emac1-v1-v6-2-e64971f4e414@gmail.com Signed-off-by: Jakub Kicinski --- .../bindings/net/allwinner,sun8i-a83t-emac.yaml | 13 +++++++++++++ .../devicetree/bindings/net/snps,dwmac.yaml | 2 ++ 2 files changed, 15 insertions(+) diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml index 323a669fa982..2cae0133b3cd 100644 --- a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml +++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml @@ -21,6 +21,7 @@ select: - allwinner,sun8i-r40-gmac - allwinner,sun8i-v3s-emac - allwinner,sun50i-a64-emac + - allwinner,sun50i-h616-emac1 - allwinner,sun55i-a523-gmac200 required: - compatible @@ -33,6 +34,7 @@ properties: - const: allwinner,sun8i-r40-gmac - const: allwinner,sun8i-v3s-emac - const: allwinner,sun50i-a64-emac + - const: allwinner,sun50i-h616-emac1 - items: - enum: - allwinner,sun20i-d1-emac @@ -91,6 +93,17 @@ required: allOf: - $ref: snps,dwmac.yaml# + - if: + properties: + compatible: + contains: + const: allwinner,sun50i-h616-emac1 + + then: + properties: + phy-mode: + const: rmii + - if: properties: compatible: diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml index d3e591157faf..2218a492817f 100644 --- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml +++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml @@ -57,6 +57,7 @@ properties: - allwinner,sun8i-r40-gmac - allwinner,sun8i-v3s-emac - allwinner,sun50i-a64-emac + - allwinner,sun50i-h616-emac1 - amlogic,meson6-dwmac - amlogic,meson8b-dwmac - amlogic,meson8m2-dwmac @@ -573,6 +574,7 @@ allOf: - allwinner,sun8i-r40-gmac - allwinner,sun8i-v3s-emac - allwinner,sun50i-a64-emac + - allwinner,sun50i-h616-emac1 - loongson,ls2k-dwmac - loongson,ls7a-dwmac - ingenic,jz4775-mac From 61240e48a67de166ddf29a93e0bdf603be04e0c8 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Sun, 27 Sep 2026 12:52:21 -0600 Subject: [PATCH 0935/2126] net: stmmac: sun8i: add support for Allwinner H616 EMAC1 The H616 secondary EMAC uses a separate system-control clock register and supports only RMII at 10/100 Mbps. It connects internally to the co-packaged AC200 or AC300 EPHY and has no external PHY pins. Add an EMAC1 variant using the dedicated register and enable only RMII. Leave PHY initialization to the PHY driver instead of using the H3 internal-PHY controls. No RX or TX clock delays are configured for this RMII-only variant. Co-developed-by: Richard Genoud Signed-off-by: Richard Genoud Reviewed-by: Maxime Chevallier Reviewed-by: Andre Przywara Reviewed-by: Alastair D'Silva Tested-by: Alastair D'Silva Signed-off-by: James Hilliard Link: https://patch.msgid.link/20260927-submit-h616-emac1-v1-v6-3-e64971f4e414@gmail.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 5691da796454..47954537b29e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -81,6 +81,13 @@ static const struct reg_field sun8i_syscon_reg_field = { .msb = 31, }; +/* EMAC1 clock register @ 0x34 in the "system control" address range */ +static const struct reg_field sun8i_syscon_reg_field_emac1 = { + .reg = 0x34, + .lsb = 0, + .msb = 31, +}; + /* EMAC clock register @ 0x164 in the CCU address range */ static const struct reg_field sun8i_ccu_reg_field = { .reg = 0x164, @@ -143,6 +150,13 @@ static const struct emac_variant emac_variant_h6 = { .tx_delay_max = 7, }; +static const struct emac_variant emac_variant_h616_emac1 = { + .syscon_field = &sun8i_syscon_reg_field_emac1, + /* The co-packaged AC200/AC300 PHY does not use the H3 PHY controls. */ + .soc_has_internal_phy = false, + .support_rmii = true, +}; + #define EMAC_BASIC_CTL0 0x00 #define EMAC_BASIC_CTL1 0x04 #define EMAC_INT_STA 0x08 @@ -1281,6 +1295,8 @@ static const struct of_device_id sun8i_dwmac_match[] = { .data = &emac_variant_a64 }, { .compatible = "allwinner,sun50i-h6-emac", .data = &emac_variant_h6 }, + { .compatible = "allwinner,sun50i-h616-emac1", + .data = &emac_variant_h616_emac1 }, { } }; MODULE_DEVICE_TABLE(of, sun8i_dwmac_match); From 504bbf01735f695f29dddb8b83378464a6b29e2a Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 23 Sep 2026 13:45:00 +0800 Subject: [PATCH 0936/2126] wifi: rtw89: fw: duplicate recognized firmware elements The firmware file contains variant elements for variant hardware, and currently whole firmware content is persistent. However, RTL8922DE has many variants and firmware file become grown to over 4MB, but actually size of necessary duplicate elements are about 1.0MB. To reduce memory usage, duplicate recognized firmware elements as persistent memory, and will release firmware by next coming patch. However, firmware for early chips doesn't have many variant elements, and no need to duplicate memory for the purpose, so do it only if firmware size is over 2MB. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923054505.43329-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/fw.c | 72 ++++++++++++++++++----- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 3a6099386b09..4b4500a7a068 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6094,6 +6094,7 @@ struct rtw89_fw_suit { struct rtw89_fw_req_info { const struct firmware *firmware; struct completion completion; + bool free_after_probe; }; struct rtw89_fw_log { diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 535cc2ad8611..3cdfb141f075 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -137,6 +137,33 @@ int rtw89_fw_check_rdy(struct rtw89_dev *rtwdev, enum rtw89_fwdl_check_type type return 0; } +static const void *__rtw89_fw_elem_dup_if_needed(struct rtw89_dev *rtwdev, + const void *src, size_t len) +{ + struct rtw89_fw_req_info *fw_req = &rtwdev->fw.req; + const void *dup; + + if (!fw_req->free_after_probe) + return src; + + dup = devm_kmemdup(rtwdev->dev, src, len, GFP_KERNEL); + if (!dup) { + /* If failed to memdup, fallback to point to firmware->data. */ + fw_req->free_after_probe = false; + return src; + } + + return dup; +} + +static const void *rtw89_fw_elem_dup_if_needed(struct rtw89_dev *rtwdev, + const struct rtw89_fw_element_hdr *elm) +{ + size_t len = sizeof(*elm) + le32_to_cpu(elm->size); + + return __rtw89_fw_elem_dup_if_needed(rtwdev, elm, len); +} + static int rtw89_fw_hdr_parser_v0(struct rtw89_dev *rtwdev, const u8 *fw, u32 len, struct rtw89_fw_bin_info *info) { @@ -641,6 +668,8 @@ int rtw89_mfw_recognize(struct rtw89_dev *rtwdev, enum rtw89_fw_type type, const struct rtw89_mfw_hdr *mfw_hdr; const u8 *mfw = firmware->data; u32 mfw_len = firmware->size; + const u8 *mfw_info_ptr; + u32 mfw_info_size; int ret; int i; @@ -650,8 +679,9 @@ int rtw89_mfw_recognize(struct rtw89_dev *rtwdev, enum rtw89_fw_type type, /* legacy firmware support normal type only */ if (type != RTW89_FW_NORMAL) return -EINVAL; - fw_suit->data = mfw; fw_suit->size = mfw_len; + fw_suit->data = __rtw89_fw_elem_dup_if_needed(rtwdev, mfw, + fw_suit->size); return 0; } @@ -686,14 +716,18 @@ int rtw89_mfw_recognize(struct rtw89_dev *rtwdev, enum rtw89_fw_type type, return -ENOENT; found: - fw_suit->data = mfw + le32_to_cpu(mfw_info->shift); - fw_suit->size = le32_to_cpu(mfw_info->size); + mfw_info_ptr = mfw + le32_to_cpu(mfw_info->shift); + mfw_info_size = le32_to_cpu(mfw_info->size); - if (fw_suit->data + fw_suit->size > mfw + mfw_len) { + if (mfw_info_ptr + mfw_info_size > mfw + mfw_len) { rtw89_err(rtwdev, "fw_suit %d out of address\n", type); return -EFAULT; } + fw_suit->size = mfw_info_size; + fw_suit->data = __rtw89_fw_elem_dup_if_needed(rtwdev, mfw_info_ptr, + fw_suit->size); + return 0; } @@ -831,8 +865,9 @@ int __rtw89_fw_recognize_from_elm(struct rtw89_dev *rtwdev, if (fw_suit->data) return 1; /* ignore this element (a firmware is taken already) */ - fw_suit->data = elm->u.bbmcu.contents; fw_suit->size = le32_to_cpu(elm->size); + fw_suit->data = __rtw89_fw_elem_dup_if_needed(rtwdev, elm->u.bbmcu.contents, + fw_suit->size); return rtw89_fw_update_ver(rtwdev, type, fw_suit); } @@ -1252,7 +1287,12 @@ setup: conf->rfe_type = txpwr_elm->rfe_type; conf->ent_sz = txpwr_elm->ent_sz; conf->num_ents = le32_to_cpu(txpwr_elm->num_ents); + /* + * The conf->data is used by rtw89_core_setup_rfe_parms() to do format + * conversion before releasing firmware. No need to duplicate. + */ conf->data = txpwr_elm->content; + return 0; } @@ -1263,6 +1303,7 @@ int rtw89_build_txpwr_trk_tbl_from_elm(struct rtw89_dev *rtwdev, { struct rtw89_fw_elm_info *elm_info = &rtwdev->fw.elm_info; const struct rtw89_chip_info *chip = rtwdev->chip; + const struct rtw89_fw_element_hdr *elm_dup; struct rtw89_hal *hal = &rtwdev->hal; u16 aid = le16_to_cpu(elm->aid); u32 needed_bitmap = 0; @@ -1293,6 +1334,8 @@ int rtw89_build_txpwr_trk_tbl_from_elm(struct rtw89_dev *rtwdev, if (!elm_info->txpwr_trk) return -ENOMEM; + elm_dup = rtw89_fw_elem_dup_if_needed(rtwdev, elm); + for (type = 0; bitmap; type++, bitmap >>= 1) { if (!(bitmap & BIT(0))) continue; @@ -1309,10 +1352,10 @@ int rtw89_build_txpwr_trk_tbl_from_elm(struct rtw89_dev *rtwdev, else break; - elm_info->txpwr_trk->delta[type] = &elm->u.txpwr_trk.contents[offset]; + elm_info->txpwr_trk->delta[type] = &elm_dup->u.txpwr_trk.contents[offset]; offset += subband; - if (offset * DELTA_SWINGIDX_SIZE > le32_to_cpu(elm->size)) + if (offset * DELTA_SWINGIDX_SIZE > le32_to_cpu(elm_dup->size)) goto err; } @@ -1347,7 +1390,7 @@ allocated: if (rfk_id >= RTW89_PHY_C2H_RFK_LOG_FUNC_NUM) return 1; - elm_info->rfk_log_fmt->elm[rfk_id] = elm; + elm_info->rfk_log_fmt->elm[rfk_id] = rtw89_fw_elem_dup_if_needed(rtwdev, elm); return 0; } @@ -1454,7 +1497,7 @@ int rtw89_build_afe_pwr_seq_from_elm(struct rtw89_dev *rtwdev, { struct rtw89_fw_elm_info *elm_info = &rtwdev->fw.elm_info; - elm_info->afe = elm; + elm_info->afe = rtw89_fw_elem_dup_if_needed(rtwdev, elm); return 0; } @@ -1466,7 +1509,7 @@ int rtw89_recognize_diag_mac_from_elm(struct rtw89_dev *rtwdev, { struct rtw89_fw_elm_info *elm_info = &rtwdev->fw.elm_info; - elm_info->diag_mac = elm; + elm_info->diag_mac = rtw89_fw_elem_dup_if_needed(rtwdev, elm); return 0; } @@ -1492,7 +1535,7 @@ int rtw89_build_tx_comp_from_elm(struct rtw89_dev *rtwdev, else if (elm_info->tx_comp) return 1; /* ignore if an element is existing */ - elm_info->tx_comp = elm; + elm_info->tx_comp = rtw89_fw_elem_dup_if_needed(rtwdev, elm); return 0; } @@ -2106,13 +2149,12 @@ static int rtw89_load_firmware_req(struct rtw89_dev *rtwdev, struct rtw89_fw_req_info *req, const char *fw_name, bool nowarn) { - int ret; + int ret = 0; if (req->firmware) { rtw89_debug(rtwdev, RTW89_DBG_FW, "full firmware has been early requested\n"); - complete_all(&req->completion); - return 0; + goto out; } if (nowarn) @@ -2120,6 +2162,8 @@ static int rtw89_load_firmware_req(struct rtw89_dev *rtwdev, else ret = request_firmware(&req->firmware, fw_name, rtwdev->dev); +out: + req->free_after_probe = req->firmware && req->firmware->size > 0x200000; complete_all(&req->completion); return ret; From f31a3a3afab1a55d91212196185c99ed7a68018d Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 23 Sep 2026 13:45:01 +0800 Subject: [PATCH 0937/2126] wifi: rtw89: fw: release firmware after recognizing firmware elements The firmware elements are recognized according to hardware variants in rtw89_chip_info_setup(), and the last function uses firmware content is rtw89_core_setup_rfe_parms(). Release firmware at the end of the function if we have duplicated the elements. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923054505.43329-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 4 ++++ drivers/net/wireless/realtek/rtw89/fw.c | 24 ++++++++++++++--------- drivers/net/wireless/realtek/rtw89/fw.h | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 0c1c5c8ae8ce..5ca0c401c43a 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -7388,6 +7388,7 @@ void rtw89_core_rfkill_poll(struct rtw89_dev *rtwdev, bool force) int rtw89_chip_info_setup(struct rtw89_dev *rtwdev) { + struct rtw89_fw_req_info *fw_req = &rtwdev->fw.req; struct rtw89_efuse *efuse = &rtwdev->efuse; struct rtw89_hal *hal = &rtwdev->hal; int ret; @@ -7437,6 +7438,9 @@ int rtw89_chip_info_setup(struct rtw89_dev *rtwdev) hal->cid, hal->cv, hal->aid, hal->acv, efuse->rfe_type); out: + if (fw_req->free_after_probe) + __rtw89_unload_firmware(rtwdev); + rtw89_mac_pwr_off(rtwdev); return ret; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 3cdfb141f075..e4b59690622d 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -2206,20 +2206,26 @@ static void rtw89_unload_firmware_elements(struct rtw89_dev *rtwdev) kfree(elm_info->rfk_log_fmt); } +void __rtw89_unload_firmware(struct rtw89_dev *rtwdev) +{ + struct rtw89_fw_info *fw = &rtwdev->fw; + + release_firmware(fw->req.firmware); + + /* + * Directly call this to free firmware early in normal flow. Assign + * NULL back in case rtw89_free_ieee80211_hw() or tw89_core_deinit() + * try to release the same one again in error handling paths. + */ + fw->req.firmware = NULL; +} + void rtw89_unload_firmware(struct rtw89_dev *rtwdev) { struct rtw89_fw_info *fw = &rtwdev->fw; cancel_work_sync(&rtwdev->load_firmware_work); - - if (fw->req.firmware) { - release_firmware(fw->req.firmware); - - /* assign NULL back in case rtw89_free_ieee80211_hw() - * try to release the same one again. - */ - fw->req.firmware = NULL; - } + __rtw89_unload_firmware(rtwdev); kfree(fw->log.fmts); rtw89_unload_firmware_elements(rtwdev); diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 473278f6bbea..cb4209df5843 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -5419,6 +5419,7 @@ rtw89_early_fw_feature_recognize(struct device *device, int rtw89_fw_download(struct rtw89_dev *rtwdev, enum rtw89_fw_type type, bool include_bb); void rtw89_load_firmware_work(struct work_struct *work); +void __rtw89_unload_firmware(struct rtw89_dev *rtwdev); void rtw89_unload_firmware(struct rtw89_dev *rtwdev); int rtw89_wait_firmware_completion(struct rtw89_dev *rtwdev); int rtw89_fw_log_prepare(struct rtw89_dev *rtwdev); From 0ba6a2d26fef118edd0fa157ea737a053031c95e Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 23 Sep 2026 13:45:02 +0800 Subject: [PATCH 0938/2126] wifi: rtw89: fw: duplicate firmware suit data by vmalloc to reduce memory fragment The firmware suit data might be just over 512kB (e.g. 540kB) and actual allocation size of devm_kmemdup() can be 1MB, which is a big internal fragment. Use vmalooc() instead to reduce fragment. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923054505.43329-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 1 + drivers/net/wireless/realtek/rtw89/core.h | 3 ++ drivers/net/wireless/realtek/rtw89/fw.c | 52 ++++++++++++++++++----- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 5ca0c401c43a..e61d7e89882f 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -6986,6 +6986,7 @@ int rtw89_core_init(struct rtw89_dev *rtwdev) } INIT_LIST_HEAD(&rtwdev->scan_info.chan_list); INIT_LIST_HEAD(&rtwdev->tx_waits); + INIT_LIST_HEAD(&rtwdev->fw.dup_data_list); INIT_WORK(&rtwdev->ba_work, rtw89_core_ba_work); INIT_WORK(&rtwdev->txq_work, rtw89_core_txq_work); INIT_DELAYED_WORK(&rtwdev->txq_reinvoke_work, rtw89_core_txq_reinvoke_work); diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 4b4500a7a068..d8adf7425a3a 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6059,6 +6059,7 @@ enum rtw89_fw_feature { struct rtw89_fw_suit { enum rtw89_fw_type type; const u8 *data; + struct list_head list; u32 size; u8 major_ver; u8 minor_ver; @@ -6150,6 +6151,8 @@ struct rtw89_fw_info { struct rtw89_fw_elm_info elm_info; struct rtw89_fw_secure sec; + struct list_head dup_data_list; + DECLARE_BITMAP(feature_map, NUM_OF_RTW89_FW_FEATURES); }; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index e4b59690622d..7c7c0a4f703e 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -3,6 +3,7 @@ */ #include +#include #include "cam.h" #include "chan.h" #include "coex.h" @@ -138,15 +139,23 @@ int rtw89_fw_check_rdy(struct rtw89_dev *rtwdev, enum rtw89_fwdl_check_type type } static const void *__rtw89_fw_elem_dup_if_needed(struct rtw89_dev *rtwdev, - const void *src, size_t len) + const void *src, size_t len, + bool is_fw_suit) { struct rtw89_fw_req_info *fw_req = &rtwdev->fw.req; - const void *dup; + void *dup; if (!fw_req->free_after_probe) return src; - dup = devm_kmemdup(rtwdev->dev, src, len, GFP_KERNEL); + if (is_fw_suit) { + dup = vmalloc(len); + if (dup) + memcpy(dup, src, len); + } else { + dup = devm_kmemdup(rtwdev->dev, src, len, GFP_KERNEL); + } + if (!dup) { /* If failed to memdup, fallback to point to firmware->data. */ fw_req->free_after_probe = false; @@ -161,7 +170,22 @@ static const void *rtw89_fw_elem_dup_if_needed(struct rtw89_dev *rtwdev, { size_t len = sizeof(*elm) + le32_to_cpu(elm->size); - return __rtw89_fw_elem_dup_if_needed(rtwdev, elm, len); + return __rtw89_fw_elem_dup_if_needed(rtwdev, elm, len, false); +} + +static const void *rtw89_fw_suit_data_dup_if_needed(struct rtw89_dev *rtwdev, + struct rtw89_fw_suit *fw_suit, + const void *src) +{ + struct rtw89_fw_info *fw = &rtwdev->fw; + const void *dup; + + dup = __rtw89_fw_elem_dup_if_needed(rtwdev, src, fw_suit->size, true); + + if (dup != src) + list_add_tail(&fw_suit->list, &fw->dup_data_list); + + return dup; } static int rtw89_fw_hdr_parser_v0(struct rtw89_dev *rtwdev, const u8 *fw, u32 len, @@ -680,8 +704,7 @@ int rtw89_mfw_recognize(struct rtw89_dev *rtwdev, enum rtw89_fw_type type, if (type != RTW89_FW_NORMAL) return -EINVAL; fw_suit->size = mfw_len; - fw_suit->data = __rtw89_fw_elem_dup_if_needed(rtwdev, mfw, - fw_suit->size); + fw_suit->data = rtw89_fw_suit_data_dup_if_needed(rtwdev, fw_suit, mfw); return 0; } @@ -725,8 +748,7 @@ found: } fw_suit->size = mfw_info_size; - fw_suit->data = __rtw89_fw_elem_dup_if_needed(rtwdev, mfw_info_ptr, - fw_suit->size); + fw_suit->data = rtw89_fw_suit_data_dup_if_needed(rtwdev, fw_suit, mfw_info_ptr); return 0; } @@ -866,8 +888,8 @@ int __rtw89_fw_recognize_from_elm(struct rtw89_dev *rtwdev, return 1; /* ignore this element (a firmware is taken already) */ fw_suit->size = le32_to_cpu(elm->size); - fw_suit->data = __rtw89_fw_elem_dup_if_needed(rtwdev, elm->u.bbmcu.contents, - fw_suit->size); + fw_suit->data = + rtw89_fw_suit_data_dup_if_needed(rtwdev, fw_suit, elm->u.bbmcu.contents); return rtw89_fw_update_ver(rtwdev, type, fw_suit); } @@ -2206,6 +2228,15 @@ static void rtw89_unload_firmware_elements(struct rtw89_dev *rtwdev) kfree(elm_info->rfk_log_fmt); } +static void rtw89_unload_firmware_dup_data(struct rtw89_dev *rtwdev) +{ + struct rtw89_fw_info *fw = &rtwdev->fw; + struct rtw89_fw_suit *fw_suit; + + list_for_each_entry(fw_suit, &fw->dup_data_list, list) + vfree(fw_suit->data); +} + void __rtw89_unload_firmware(struct rtw89_dev *rtwdev) { struct rtw89_fw_info *fw = &rtwdev->fw; @@ -2229,6 +2260,7 @@ void rtw89_unload_firmware(struct rtw89_dev *rtwdev) kfree(fw->log.fmts); rtw89_unload_firmware_elements(rtwdev); + rtw89_unload_firmware_dup_data(rtwdev); } static u32 rtw89_fw_log_get_fmt_idx(struct rtw89_dev *rtwdev, u32 fmt_id) From 86e0056aaaf32f88f0cf5f27a8d89b775142dbf4 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 23 Sep 2026 13:45:03 +0800 Subject: [PATCH 0939/2126] wifi: rtw89: led: check if board variant assigns led desc Refine the check logic. The led initializer assumed a board variant must have led desc, but board variant is going to add a new field, board_id, for custom FW elements and not all board variants which require custom FW elements have led desc. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923054505.43329-5-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/led.c b/drivers/net/wireless/realtek/rtw89/led.c index ae74b7075d7c..18bfe626ef50 100644 --- a/drivers/net/wireless/realtek/rtw89/led.c +++ b/drivers/net/wireless/realtek/rtw89/led.c @@ -104,7 +104,7 @@ void rtw89_led_init(struct rtw89_dev *rtwdev) /* single-GPIO monochrome LED is the only supported layout */ BUILD_BUG_ON(ARRAY_SIZE(rtw89_common_led_gpios) != 1); - if (board) + if (board && board->led_desc) desc = board->led_desc; if (!desc->n_gpio || desc->n_gpio > RTW89_LED_MAX_NUM) return; From af5905e22a435f18227ba533536deaecce028e08 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 23 Sep 2026 13:45:04 +0800 Subject: [PATCH 0940/2126] wifi: rtw89: support variants of FW elements Although there is a set of general FW elements parameters for each chip, some chipsets depending on products may need variants of FW elements for some specific adjustments. Each of these chipsets will be defined with a specific VID/PID that mapping to a specific board ID for FW elements. When probing these chipsets, try to load rtw89/board_elm.bin and seek the given variant ID. If found, apply the variant of FW elements. Otherwise, fallback to the general FW elements. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923054505.43329-6-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 1 + drivers/net/wireless/realtek/rtw89/core.h | 14 +++ drivers/net/wireless/realtek/rtw89/fw.c | 124 ++++++++++++++++++---- drivers/net/wireless/realtek/rtw89/fw.h | 14 +++ 4 files changed, 135 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index e61d7e89882f..2a1f54e9664a 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -7745,6 +7745,7 @@ void rtw89_free_ieee80211_hw(struct rtw89_dev *rtwdev) } EXPORT_SYMBOL(rtw89_free_ieee80211_hw); +MODULE_FIRMWARE(RTW89_FWNAME_BOARD_ELM); MODULE_AUTHOR("Realtek Corporation"); MODULE_DESCRIPTION("Realtek 802.11ax wireless core module"); MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index d8adf7425a3a..bcb58a9392cc 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -5302,6 +5302,8 @@ struct rtw89_reg_imr { #define RTW89_GEN_MODULE_FWNAME(basename, maxformat) \ basename RTW89_GEN_MODULE_FWNAME_FMT(maxformat) ".bin" +#define RTW89_FWNAME_BOARD_ELM "rtw89/board_elm.bin" + struct rtw89_fw_def { const char *fw_basename; u8 fw_format_max; @@ -5893,7 +5895,18 @@ struct rtw89_chip_variant { const struct rtw89_qta_def *qta_def_override; }; +/* @pid can have extra suffix to describe the variant if necessary */ +#define RTW89_BOARD_ID(vid, pid) \ + RTW89_BOARD_ID_##vid##_##pid + +enum rtw89_board_id { + RTW89_BOARD_ID(0000, 0000) = 0, /* reserve 0 for non-variant */ + + NUM_OF_RTW89_BOARD_IDS, +}; + struct rtw89_board_variant { + enum rtw89_board_id id; const struct rtw89_led_desc *led_desc; }; @@ -6094,6 +6107,7 @@ struct rtw89_fw_suit { struct rtw89_fw_req_info { const struct firmware *firmware; + const struct firmware *board_elm; struct completion completion; bool free_after_probe; }; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 7c7c0a4f703e..d53e670a29cf 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -1658,30 +1658,17 @@ static const struct rtw89_fw_element_handler __fw_element_handlers[] = { }, }; -int rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev) +static int __rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev, + const struct firmware *firmware, + u32 offset, u32 skipped_elements, + u32 *unrecognized_elements) { - struct rtw89_fw_info *fw_info = &rtwdev->fw; - const struct firmware *firmware = fw_info->req.firmware; - const struct rtw89_chip_info *chip = rtwdev->chip; - u32 unrecognized_elements = chip->needed_fw_elms; const struct rtw89_fw_element_handler *handler; const struct rtw89_fw_element_hdr *hdr; - bool transition; u32 elm_size; u32 elem_id; - u32 offset; int ret; - BUILD_BUG_ON(sizeof(chip->needed_fw_elms) * 8 < RTW89_FW_ELEMENT_ID_NUM); - - transition = !!((chip->needed_fw_elms & BIT(__RTW89_FW_ELEMENT_ID_INTL_TRANSITION))); - unrecognized_elements &= ~BIT(__RTW89_FW_ELEMENT_ID_INTL_TRANSITION); - - offset = rtw89_mfw_get_size(rtwdev); - offset = ALIGN(offset, RTW89_FW_ELEMENT_ALIGN); - if (offset == 0) - return -EINVAL; - while (offset + sizeof(*hdr) < firmware->size) { hdr = (const struct rtw89_fw_element_hdr *)(firmware->data + offset); @@ -1694,6 +1681,8 @@ int rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev) elem_id = le32_to_cpu(hdr->id); if (elem_id >= ARRAY_SIZE(__fw_element_handlers)) goto next; + if (skipped_elements & BIT(elem_id)) + goto next; handler = &__fw_element_handlers[elem_id]; if (!handler->fn) @@ -1709,12 +1698,105 @@ int rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev) rtw89_info(rtwdev, "Firmware element %s version: %4ph\n", handler->name, hdr->ver); - unrecognized_elements &= ~BIT(elem_id); + *unrecognized_elements &= ~BIT(elem_id); next: offset += sizeof(*hdr) + elm_size; offset = ALIGN(offset, RTW89_FW_ELEMENT_ALIGN); } + return 0; +} + +static int rtw89_board_elm_seek(const struct firmware *board_elm, + enum rtw89_board_id board_id, + struct firmware *pseudo_fw) +{ + const struct rtw89_board_elm_hdr *hdr; + const struct rtw89_board_elm_ent *ent; + u32 ofst; + u32 size; + u16 num; + + if (board_elm->size < sizeof(*hdr)) + return -EINVAL; + + hdr = (const struct rtw89_board_elm_hdr *)board_elm->data; + if (hdr->sig != RTW89_BOARD_ELM_SIG) + return -EINVAL; + + BUILD_BUG_ON(U16_MAX < NUM_OF_RTW89_BOARD_IDS); + + num = le16_to_cpu(hdr->num); + if (unlikely(board_elm->size < struct_size(hdr, ents, num))) + return -EFAULT; + if (num <= board_id) + return -ENOENT; + + ent = &hdr->ents[board_id]; + + ofst = le32_to_cpu(ent->ofst); + size = le32_to_cpu(ent->size); + + if (unlikely(board_elm->size < ofst + size)) + return -EFAULT; + + memset(pseudo_fw, 0, sizeof(*pseudo_fw)); + + pseudo_fw->data = (const void *)board_elm->data + ofst; + pseudo_fw->size = size; + + return 0; +} + +int rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev) +{ + const struct rtw89_board_variant *board = rtwdev->board; + struct rtw89_fw_req_info *fw_req = &rtwdev->fw.req; + const struct firmware *firmware = fw_req->firmware; + const struct rtw89_chip_info *chip = rtwdev->chip; + u32 unrecognized_elements = chip->needed_fw_elms; + u32 skipped_elements = 0; + bool transition; + u32 offset; + int ret; + + BUILD_BUG_ON(sizeof(chip->needed_fw_elms) * 8 < RTW89_FW_ELEMENT_ID_NUM); + BUILD_BUG_ON(!__same_type(unrecognized_elements, chip->needed_fw_elms)); + BUILD_BUG_ON(!__same_type(skipped_elements, chip->needed_fw_elms)); + + transition = !!((chip->needed_fw_elms & BIT(__RTW89_FW_ELEMENT_ID_INTL_TRANSITION))); + unrecognized_elements &= ~BIT(__RTW89_FW_ELEMENT_ID_INTL_TRANSITION); + + if (fw_req->board_elm) { + struct firmware pseudo_fw; + + ret = rtw89_board_elm_seek(fw_req->board_elm, board->id, &pseudo_fw); + if (ret) + goto mfw; + + ret = __rtw89_fw_recognize_elements(rtwdev, &pseudo_fw, 0, 0, + &unrecognized_elements); + if (ret) + goto mfw; + + skipped_elements = chip->needed_fw_elms & ~unrecognized_elements; + + rtw89_debug(rtwdev, RTW89_DBG_FW, "apply elements 0x08%x from %s\n", + skipped_elements, RTW89_FWNAME_BOARD_ELM); + } + +mfw: + offset = rtw89_mfw_get_size(rtwdev); + offset = ALIGN(offset, RTW89_FW_ELEMENT_ALIGN); + if (offset == 0) + return -EINVAL; + + ret = __rtw89_fw_recognize_elements(rtwdev, firmware, offset, + skipped_elements, + &unrecognized_elements); + if (ret) + return ret; + if (unrecognized_elements) { if (transition) { rtw89_info(rtwdev, "NOTE: This firmware is going to be obsolete!\n" @@ -2171,6 +2253,7 @@ static int rtw89_load_firmware_req(struct rtw89_dev *rtwdev, struct rtw89_fw_req_info *req, const char *fw_name, bool nowarn) { + const struct rtw89_board_variant *board = rtwdev->board; int ret = 0; if (req->firmware) { @@ -2185,6 +2268,9 @@ static int rtw89_load_firmware_req(struct rtw89_dev *rtwdev, ret = request_firmware(&req->firmware, fw_name, rtwdev->dev); out: + if (board && board->id) + firmware_request_nowarn(&req->board_elm, RTW89_FWNAME_BOARD_ELM, rtwdev->dev); + req->free_after_probe = req->firmware && req->firmware->size > 0x200000; complete_all(&req->completion); @@ -2242,6 +2328,7 @@ void __rtw89_unload_firmware(struct rtw89_dev *rtwdev) struct rtw89_fw_info *fw = &rtwdev->fw; release_firmware(fw->req.firmware); + release_firmware(fw->req.board_elm); /* * Directly call this to free firmware early in normal flow. Assign @@ -2249,6 +2336,7 @@ void __rtw89_unload_firmware(struct rtw89_dev *rtwdev) * try to release the same one again in error handling paths. */ fw->req.firmware = NULL; + fw->req.board_elm = NULL; } void rtw89_unload_firmware(struct rtw89_dev *rtwdev) diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index cb4209df5843..23adf12f132e 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -4394,6 +4394,7 @@ struct rtw89_h2c_ofld { #define RTW89_H2C_OFLD_W0_RX_TP GENMASK(27, 18) #define RTW89_MFW_SIG 0xFF +#define RTW89_BOARD_ELM_SIG 0xFE struct rtw89_mfw_info { u8 cv; @@ -4419,6 +4420,19 @@ struct rtw89_mfw_hdr { struct rtw89_mfw_info info[]; } __packed; +struct rtw89_board_elm_ent { + u8 rsvd[8]; + __le32 ofst; /* offset from beginning of rtw89_board_elm_hdr */ + __le32 size; +} __packed; + +struct rtw89_board_elm_hdr { + u8 sig; /* RTW89_BOARD_ELM_SIG */ + u8 rsvd[13]; + __le16 num; + struct rtw89_board_elm_ent ents[] __counted_by_le(num); +} __packed; + struct rtw89_fw_logsuit_hdr { __le32 rsvd; __le32 count; From efd90b64ce25697da8131708bd30b90b5758d22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Fri, 25 Sep 2026 15:59:34 +0200 Subject: [PATCH 0941/2126] net: macb: never give hardware a NULL RX buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The refill logic is simple: iterate over all pending rx slots, allocate SKB (& DMA map) if needed and hand it off to the hardware by clearing the RX_USED flag. If the refill operation fails mid-way, it early returns leaving the remaining slots untouched. In an initialised ring that is safe: a slot is either owned by the hardware holding a valid buffer, or software-owned (RX_USED set) waiting for refill to hand it a new one. When slots have never been initialised however, we are in trouble. After dma_alloc_coherent() of the rx ring buffer, all slots have NULL pointers and RX_USED cleared meaning HW will try using them. Ensure this does not happen by setting the RX_USED flag on all slots before calling refill at buffer alloc, in gem_init_rx_ring(). That way even if refill fails on an alloc/dma_map, the HW won't try using NULL pointers as buffers. Note we tweak gem_rx() and macb_rx_pending(): their previous stop condition was only if desc was RX_USED. Now it must be either RX_USED or we got out of the range of successfully allocated descriptors (detected using the rx_tail and rx_prepared_head cursors). Otherwise gem_rx() could consume unallocated buffers. Theoretical bugfix, never encountered in practice. To reproduce, introduce memory pressure (less than 512 SKBs of free memory) and open the interface. Note that this codepath also hits at resume, on HRESP errors and on set_ringparam (while interface is running). Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20260925-macb-close-v2-1-360efa565914@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index c26ffcf73562..ab19221d5bea 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1615,6 +1615,13 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, dma_addr_t addr; bool rxused; + /* Only descriptors in [rx_tail, rx_prepared_head) were armed + * for hardware. Outside, we might have RX_USED descriptors for + * alloc failures. + */ + if (queue->rx_tail == queue->rx_prepared_head) + break; + entry = macb_rx_ring_wrap(bp, queue->rx_tail); desc = macb_rx_desc(queue, entry); @@ -1878,6 +1885,10 @@ static bool macb_rx_pending(struct macb_queue *queue) struct macb_dma_desc *desc; unsigned int entry; + /* No armed descriptor left: nothing can be pending. */ + if (macb_is_gem(bp) && queue->rx_tail == queue->rx_prepared_head) + return false; + entry = macb_rx_ring_wrap(bp, queue->rx_tail); desc = macb_rx_desc(queue, entry); @@ -2814,9 +2825,14 @@ out_err: static void gem_init_rx_ring(struct macb_queue *queue) { + unsigned int i; + queue->rx_tail = 0; queue->rx_prepared_head = 0; + for (i = 0; i < queue->bp->rx_ring_size; i++) + macb_rx_desc(queue, i)->addr |= MACB_BIT(RX_USED); + gem_rx_refill(queue); } From 9ea465c4fbaf4c77bd86a0e91e610a713592a1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Fri, 25 Sep 2026 15:59:35 +0200 Subject: [PATCH 0942/2126] net: macb: propagate RX ring refill errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gem_rx_refill() is responsible for Rx SKB allocation, including at open, but its prototype indicates a void return value. Therefore we change the code to propagate allocation and DMA mapping errors back up the stack, making sure the open fails if no descriptors were allocated. Change all those to return errno-style ints: - gem_rx_refill() - its parent gem_init_rx_ring() - its grand-parent gem_init_rings() - the macbgem_ops.mog_init_rings function pointer - its grand-uncle macb_init_rings() We tolerate some allocation failures: we accept running with the rx ring only partially filled with successful descriptors. It is important we refuse the zero-valid-descriptor case: nothing would ever trigger a refill, which only happens once a frame has been received. Theoretical bugfix, never encountered in practice. To reproduce, introduce memory pressure (less than 512 SKBs of free memory) and open the interface. I expect the last queue to be unusable because it has zero usable rx buffers. Note that other callers of refill (resume, HRESP error task, NAPI) cannot do anything useful with that error and keep their best-effort refill, hoping it will improve. Signed-off-by: Théo Lebrun Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260925-macb-close-v2-2-360efa565914@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb.h | 2 +- drivers/net/ethernet/cadence/macb_main.c | 33 +++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index d6931c41f39d..cfaa0ca49f1a 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1197,7 +1197,7 @@ struct macb_queue; struct macb_or_gem_ops { int (*mog_alloc_rx_buffers)(struct macb *bp); void (*mog_free_rx_buffers)(struct macb *bp); - void (*mog_init_rings)(struct macb *bp); + int (*mog_init_rings)(struct macb *bp); int (*mog_rx)(struct macb_queue *queue, struct napi_struct *napi, int budget); }; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index ab19221d5bea..db86f5370a05 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1505,7 +1505,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) return packets; } -static void gem_rx_refill(struct macb_queue *queue) +static int gem_rx_refill(struct macb_queue *queue) { struct macb *bp = queue->bp; struct macb_dma_desc *desc; @@ -1577,6 +1577,14 @@ static void gem_rx_refill(struct macb_queue *queue) netdev_vdbg(bp->netdev, "rx ring: queue: %p, prepared head %d, tail %d\n", queue, queue->rx_prepared_head, queue->rx_tail); + + /* Fail if queue has zero prepared descriptors. This is critical because + * nothing will ever trigger a refill again. + */ + if (queue->rx_prepared_head == queue->rx_tail) + return -ENOMEM; + + return 0; } /* Mark DMA descriptors from begin up to and not including end as unused */ @@ -2823,7 +2831,7 @@ out_err: return -ENOMEM; } -static void gem_init_rx_ring(struct macb_queue *queue) +static int gem_init_rx_ring(struct macb_queue *queue) { unsigned int i; @@ -2833,14 +2841,16 @@ static void gem_init_rx_ring(struct macb_queue *queue) for (i = 0; i < queue->bp->rx_ring_size; i++) macb_rx_desc(queue, i)->addr |= MACB_BIT(RX_USED); - gem_rx_refill(queue); + return gem_rx_refill(queue); } -static void gem_init_rings(struct macb *bp) +static int gem_init_rings(struct macb *bp) { struct macb_queue *queue; struct macb_dma_desc *desc = NULL; + int last_err = 0; unsigned int q; + int err; int i; for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { @@ -2853,11 +2863,15 @@ static void gem_init_rings(struct macb *bp) queue->tx_head = 0; queue->tx_tail = 0; - gem_init_rx_ring(queue); + err = gem_init_rx_ring(queue); + if (err) + last_err = err; } + + return last_err; } -static void macb_init_rings(struct macb *bp) +static int macb_init_rings(struct macb *bp) { int i; struct macb_dma_desc *desc = NULL; @@ -2872,6 +2886,8 @@ static void macb_init_rings(struct macb *bp) bp->queues[0].tx_head = 0; bp->queues[0].tx_tail = 0; desc->ctrl |= MACB_BIT(TX_WRAP); + + return 0; } static void macb_reset_hw(struct macb *bp) @@ -3202,7 +3218,9 @@ static int macb_open(struct net_device *netdev) goto pm_exit; } - bp->macbgem_ops.mog_init_rings(bp); + err = bp->macbgem_ops.mog_init_rings(bp); + if (err) + goto free_rings; macb_init_buffers(bp); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { @@ -3240,6 +3258,7 @@ reset_hw: napi_disable(&queue->napi_rx); napi_disable(&queue->napi_tx); } +free_rings: macb_free(bp); pm_exit: pm_runtime_put_sync(&bp->pdev->dev); From 4fcaed2cb1d8fc66b93920cef25da242d5051867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Fri, 25 Sep 2026 15:59:36 +0200 Subject: [PATCH 0943/2126] net: macb: quiesce IRQs and drain BH on interface close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macb_close() operation is facing races as it disables IRQs late in its sequence and keeps BH primitives alive while shutdown. Non exhaustive list of races that could occur: - macb_tx_error_task() could be scheduled and access the buffers freed by macb_close(). - macb_tx_error_task() or macb_hresp_error_task() might re-enable interrupts after the IDR write in macb_close(). - macb_close() calls napi_disable() meaning that if macb_tx_error_task() occurs later, it will deadlock on napi_disable() that shouldn't be called if NAPI is already disabled. - macb_hresp_error_task() might reinit every RX/TX ring under macb_close()'s foot. - macb_interrupt() might re-enable NAPI just after it has been disabled by macb_close(). Instead, disable all our primitives one by one: - (1) mask and sync on IRQ handlers, - (2) drain any scheduled bp->hresp_err_bh_work, - (3) drain any scheduled queue->tx_error_task, - (4) drain queue->napi_rx/napi_tx, - (5) drain bp->tx_lpi_work. Careful! Ordering is important because our scheduling primitives can wake each other up. Recap table: | | enable/disable | schedule | | |----|-------|-------|------|----|----|--------|-----| | |IRQs|napi_tx|napi_rx|tx_lpi|napi|napi|tx_error|hresp| | Context | | | | task | rx | tx | task |task | |===============|====|=======|=======|======|====|====|========|=====| | open | X | X | X | | | | | | | link_up | X | | | | | | | | | link_down | X | | | | | | | | | close | X | X | X | | | | | | | enable_tx_lpi | | | | X | | | | | | swap | X | X | X | X | | | | | | suspend | X | X | X | | | | | | | resume | X | X | X | | | | | | |---------------|----|-------|-------|------|----|----|--------|-----| | irq & netpoll | X | | | | X | X | X | X | |---------------|----|-------|-------|------|----|----|--------|-----| | napi_rx | X | | | | X | | | | | napi_tx | X | | | X | | X | | | |---------------|----|-------|-------|------|----|----|--------|-----| | tx_error_task | X | X | | | | | | | | hresp task | X | | | | | | | | As example, one ordering constraint that can be deduced from the table: napi_tx can schedule tx_lpi_task meaning napi_tx must be disabled before tx_lpi_task, else we risk napi_tx re-enabling tx_lpi_task after it has been disabled by macb_close(). We do *not* use IDR masking to shutdown IRQs because that risks conflicting with BH primitives we have not disabled yet. For example if we writel(IDR) in macb_close() and napi_rx is pending then IRQs might be unmasked by the NAPI poll. As for why we do not use disable_irq(): we will have situations where we are quiesced but want to listen to some IRQs and (minor reason) we register shared IRQ handlers so we shouldn't disable the full IRQ line. Instead we introduce a bool that tells macb_interrupt() to self-disarm. Its default value is true as we start closed. It gets set to false while interface is active. Reading into my crystal ball, we'll reuse that flag in suspend/WOL, set_ringparam and change_mtu (context swap). Note that old IRQ handler tried preventing a race with close by self-disarming based on netif_running(). This might work, but it does not prevent a race with the error codepath of macb_open() which needs to run with IRQs dis-armed but netif_running() returns true during that time. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20260925-macb-close-v2-3-360efa565914@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb.h | 5 ++ drivers/net/ethernet/cadence/macb_main.c | 84 ++++++++++++++++++------ 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index cfaa0ca49f1a..1cb2778fe49e 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1382,6 +1382,11 @@ struct macb { struct delayed_work tx_lpi_work; u32 tx_lpi_timer; + /* ISR must not drive NAPI & BH mechanisms. True when the interface + * is closed. Protected by bp->lock. + */ + bool irq_quiesced; + int rx_bd_rd_prefetch; int tx_bd_rd_prefetch; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index db86f5370a05..20fe30789834 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2028,6 +2028,53 @@ static int macb_tx_poll(struct napi_struct *napi, int budget) return work_done; } +static void macb_quiesce_start(struct macb *bp) +{ + struct macb_queue *queue; + unsigned long flags; + unsigned int q; + + spin_lock_irqsave(&bp->lock, flags); + bp->irq_quiesced = true; + spin_unlock_irqrestore(&bp->lock, flags); + + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) + synchronize_irq(queue->irq); + + cancel_work_sync(&bp->hresp_err_bh_work); + + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { + /* Must be done before NAPI is disabled: the task ends with a + * napi_enable() call. + */ + cancel_work_sync(&queue->tx_error_task); + + napi_disable(&queue->napi_rx); + napi_disable(&queue->napi_tx); + } + + /* Must be done after napi_tx is disabled: its completion re-arms + * the LPI timer. + */ + cancel_delayed_work_sync(&bp->tx_lpi_work); +} + +static void macb_quiesce_end(struct macb *bp) +{ + struct macb_queue *queue; + unsigned long flags; + unsigned int q; + + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { + napi_enable(&queue->napi_rx); + napi_enable(&queue->napi_tx); + } + + spin_lock_irqsave(&bp->lock, flags); + bp->irq_quiesced = false; + spin_unlock_irqrestore(&bp->lock, flags); +} + static void macb_hresp_error_task(struct work_struct *work) { struct macb *bp = from_work(bp, work, hresp_err_bh_work); @@ -2170,8 +2217,8 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) spin_lock(&bp->lock); while (status) { - /* close possible race with dev_close */ - if (unlikely(!netif_running(netdev))) { + /* self-disarm while the netdev is closed */ + if (unlikely(bp->irq_quiesced)) { queue_writel(queue, IDR, -1); macb_queue_isr_clear(bp, queue, -1); break; @@ -3198,8 +3245,6 @@ static int macb_open(struct net_device *netdev) { size_t bufsz = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; struct macb *bp = netdev_priv(netdev); - struct macb_queue *queue; - unsigned int q; int err; netdev_dbg(bp->netdev, "open\n"); @@ -3223,10 +3268,7 @@ static int macb_open(struct net_device *netdev) goto free_rings; macb_init_buffers(bp); - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - napi_enable(&queue->napi_rx); - napi_enable(&queue->napi_tx); - } + macb_quiesce_end(bp); macb_init_hw(bp); @@ -3253,11 +3295,10 @@ phy_off: phy_power_off(bp->phy); reset_hw: + /* The netdev stays down: quiesce and drain, as macb_close() does. */ + macb_quiesce_start(bp); + macb_reset_hw(bp); - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - napi_disable(&queue->napi_rx); - napi_disable(&queue->napi_tx); - } free_rings: macb_free(bp); pm_exit: @@ -3268,19 +3309,17 @@ pm_exit: static int macb_close(struct net_device *netdev) { struct macb *bp = netdev_priv(netdev); - struct macb_queue *queue; unsigned long flags; unsigned int q; + macb_quiesce_start(bp); + + /* Drain the BH contexts before stopping the queues: NAPI completion + * and tx_error_task wake them up. + */ netif_tx_stop_all_queues(netdev); - - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - napi_disable(&queue->napi_rx); - napi_disable(&queue->napi_tx); + for (q = 0; q < bp->num_queues; ++q) netdev_tx_reset_queue(netdev_get_tx_queue(netdev, q)); - } - - cancel_delayed_work_sync(&bp->tx_lpi_work); phylink_stop(bp->phylink); phylink_disconnect_phy(bp->phylink); @@ -4802,6 +4841,11 @@ static int macb_init_dflt(struct platform_device *pdev) bp->tx_ring_size = DEFAULT_TX_RING_SIZE; bp->rx_ring_size = DEFAULT_RX_RING_SIZE; + /* No locking needed because the IRQs are not requested yet. The + * flag is cleared by macb_open() and re-armed by macb_close(). + */ + bp->irq_quiesced = true; + /* set the queue register mapping once for all: queue0 has a special * register mapping but we don't want to test the queue index then * compute the corresponding register offset at run time. From e55ca4e813e58ab4c44af3d57c558423bc5462cf Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 23 Sep 2026 13:45:05 +0800 Subject: [PATCH 0944/2126] wifi: rtw89: 8852cu: take board ID 1 for FW elements 28de/2432 RTL8852CU with 28de/2432 prefers to use variant of some FW elements. Use board ID 1 for these FW elements. And, configure board ID to it correspondingly to try to load the variant. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923054505.43329-7-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/rtw8852cu.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index bcb58a9392cc..5b26ea33f329 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -5901,6 +5901,7 @@ struct rtw89_chip_variant { enum rtw89_board_id { RTW89_BOARD_ID(0000, 0000) = 0, /* reserve 0 for non-variant */ + RTW89_BOARD_ID(28de, 2432) = 1, NUM_OF_RTW89_BOARD_IDS, }; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c index 6f852f4a713e..2e46b05b05ee 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c @@ -89,6 +89,7 @@ static const struct rtw89_led_desc rtw8852cu_valve_led_desc = { }; static const struct rtw89_board_variant rtw89_8852cu_valve_board = { + .id = RTW89_BOARD_ID(28de, 2432), .led_desc = &rtw8852cu_valve_led_desc, }; From 0266773d404bb832811ec5b050fc6358e03e5f44 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 23 Sep 2026 15:13:48 +0800 Subject: [PATCH 0945/2126] wifi: rtw89: coex: log FCX report version mismatch without dropping _chk_btc_report() validated the reported firmware struct version only for the control report, so a version mismatch on any other report type was copied in silently and left no trace, making a ver_defs or firmware version error hard to diagnose. Read the reported fver, which is the leading field of every report struct, and when it differs from the driver-selected version set the per-type bit in fver_mismch and emit a debug line. The length-valid report is still processed, because the driver must stay compatible with every released firmware and a mismatch usually points at a ver_defs entry that needs fixing rather than a report that should be discarded. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 305d8edb0d4d..d3f9ef02e982 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1866,6 +1866,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, u32 cnt_leak_slot, bt_slot_real, bt_slot_set, cnt_rx_imr; u8 i, j, val = 0, val1, val2; u32 *bt_cnt, start_idx; + const u8 *rpt_fver; rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s(): index:%d\n", @@ -2181,6 +2182,21 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, memcpy(pfinfo, rpt_content, pcinfo->req_len); pcinfo->valid = 1; + /* + * fver is the leading field of every report struct. A mismatch + * vs the driver-selected version means ver_defs needs a fix, so + * flag it for debug but keep processing the length-valid report. + */ + rpt_fver = pfinfo; + pcinfo->rsp_fver = rpt_fver[0]; + if (pcinfo->rsp_fver != pcinfo->req_fver) { + pfwinfo->fver_mismch |= BIT(rpt_type); + rtw89_debug(rtwdev, RTW89_DBG_BTC, + "[BTC], %s(): %d rsp_fver:%d!=req_fver:%d\n", + __func__, rpt_type, pcinfo->rsp_fver, + pcinfo->req_fver); + } + switch (rpt_type) { case BTC_RPT_TYPE_CTRL: if (ver->fcxbtcrpt == 1) { From 0104c69ba22597c0052cb2393e72d06fcbb6dfd5 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 23 Sep 2026 15:13:49 +0800 Subject: [PATCH 0946/2126] wifi: rtw89: coex: add fbtc_rpt_ctrl v205 report struct and handling Define struct rtw89_btc_fbtc_rpt_ctrl_v205 and add it to the rtw89_btc_fbtc_rpt_ctrl_ver_info union. Wire up the v205 dispatch path in _chk_btc_report() including req_len, fver extraction, and rsp_fver assignment (H2C fver=5). Decode the v205 report block for rpt_en_map, fw_coex/fw version, cx_offload, build timestamps, gnt_val, and BT counters. Add fw_ver_match checking for fcxbtcrpt=205, and add BTTX_HANG detection in the v205 error-check block. Also add _show_summary_v205() and wire it into the coex info dump so the fcxbtcrpt=205 statistics block is printed instead of skipped. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 179 +++++++++++++++++++++- drivers/net/wireless/realtek/rtw89/core.h | 14 ++ 2 files changed, 191 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index d3f9ef02e982..0f3347fdbb01 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1910,6 +1910,14 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, fwsubver->fcxbtcrpt = pfwinfo->rpt_ctrl.finfo.v105.fver; pcinfo->req_fver = 5; break; + } else if (ver->fcxbtcrpt == 205) { + pfinfo = &pfwinfo->rpt_ctrl.finfo.v205; + pcinfo->req_len = + sizeof(pfwinfo->rpt_ctrl.finfo.v205); + fwsubver->fcxbtcrpt = + pfwinfo->rpt_ctrl.finfo.v205.fver; + pcinfo->req_fver = 5; + break; } else if (ver->fcxbtcrpt == 8) { pfinfo = &pfwinfo->rpt_ctrl.finfo.v8; pcinfo->req_len = sizeof(pfwinfo->rpt_ctrl.finfo.v8); @@ -2304,6 +2312,52 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev, _chk_btc_err(rtwdev, BTC_DCNT_RPT_HANG, pfwinfo->event[BTF_EVNT_RPT]); + dm->error.map.bt_rfk_timeout = bt->rfk_info.map.timeout; + } else if (ver->fcxbtcrpt == 205) { + prpt->v205 = pfwinfo->rpt_ctrl.finfo.v205; + pfwinfo->rpt_en_map = + le32_to_cpu(prpt->v205.rpt_info.en); + wl->ver_info.fw_coex = + le32_to_cpu(prpt->v205.wl_fw_info.cx_ver); + wl->ver_info.fw = + le32_to_cpu(prpt->v205.wl_fw_info.fw_ver); + dm->wl_fw_cx_offload = + !!le32_to_cpu(prpt->v205.wl_fw_info.cx_offload); + + memcpy(wl->ver_info.build_time, + prpt->v205.build_time, + sizeof(wl->ver_info.build_time)); + memcpy(wl->ver_info.build_date, + prpt->v205.build_date, + sizeof(wl->ver_info.build_date)); + + for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++) + memcpy(&dm->gnt_val[i], + &prpt->v205.gnt_val[i], + sizeof(prpt->v205.gnt_val[i])); + + bt->bcnt[BTC_BCNT_HIPRI_TX] = + le32_to_cpu(prpt->v205.bt_cnt[BTC_BCNT_HI_TX]); + bt->bcnt[BTC_BCNT_HIPRI_RX] = + le32_to_cpu(prpt->v205.bt_cnt[BTC_BCNT_HI_RX]); + bt->bcnt[BTC_BCNT_LOPRI_TX] = + le32_to_cpu(prpt->v205.bt_cnt[BTC_BCNT_LO_TX]); + bt->bcnt[BTC_BCNT_LOPRI_RX] = + le32_to_cpu(prpt->v205.bt_cnt[BTC_BCNT_LO_RX]); + bt->bcnt[BTC_BCNT_POLLUTED] = + le32_to_cpu(prpt->v205.bt_cnt[BTC_BCNT_POLLUTED]); + + _chk_btc_err(rtwdev, BTC_DCNT_BTCNT_HANG, 0); + _chk_btc_err(rtwdev, BTC_DCNT_RPT_HANG, + pfwinfo->event[BTF_EVNT_RPT]); + _chk_btc_err(rtwdev, BTC_DCNT_WL_FW_VER_MATCH, 0); + _chk_btc_err(rtwdev, BTC_DCNT_BTTX_HANG, 0); + + if (le32_to_cpu(prpt->v205.bt_cnt[BTC_BCNT_RFK_TIMEOUT]) > 0) + bt->rfk_info.map.timeout = 1; + else + bt->rfk_info.map.timeout = 0; + dm->error.map.bt_rfk_timeout = bt->rfk_info.map.timeout; } else if (ver->fcxbtcrpt == 7) { prpt->v7 = pfwinfo->rpt_ctrl.finfo.v7; @@ -3332,9 +3386,13 @@ static void rtw89_btc_fw_en_rpt(struct rtw89_dev *rtwdev, if (btc->ver->fcxbtcrpt == 7 || btc->ver->fcxbtcrpt == 8 || btc->ver->fcxbtcrpt == 9 || - btc->ver->fcxbtcrpt == 11) { + btc->ver->fcxbtcrpt == 11 || + btc->ver->fcxbtcrpt == 205) { r.v8.type = SET_REPORT_EN; - r.v8.fver = btc->ver->fcxbtcrpt; + if (btc->ver->fcxbtcrpt == 205) + r.v8.fver = 5; + else + r.v8.fver = btc->ver->fcxbtcrpt; r.v8.len = sizeof(r.v8.map); r.v8.map = cpu_to_le32(rpt_map); ret = _send_fw_cmd(rtwdev, BTFC_SET, SET_REPORT_EN, &r.v8, @@ -13644,6 +13702,121 @@ static int _show_summary_v11(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) return p - buf; } +static int _show_summary_v205(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) +{ + struct rtw89_btc *btc = &rtwdev->btc; + struct rtw89_btc_btf_fwinfo *pfwinfo = &btc->fwinfo; + struct rtw89_btc_fbtc_rpt_ctrl_v205 *prptctrl; + struct rtw89_btc_rpt_cmn_info *pcinfo; + struct rtw89_btc_cx *cx = &btc->cx; + struct rtw89_btc_dm *dm = &btc->dm; + struct rtw89_btc_wl_info *wl = &cx->wl; + struct rtw89_btc_bt_info *bt = &cx->bt0; + u32 cnt_sum = 0, *cnt = btc->dm.cnt_notify; + char *p = buf, *end = buf + bufsz; + u8 i; + + if (!(dm->coex_info_map & BTC_COEX_INFO_SUMMARY)) + return 0; + + p += scnprintf(p, end - p, "========== [Statistics] ==========\n"); + + pcinfo = &pfwinfo->rpt_ctrl.cinfo; + if (pcinfo->valid && !wl->status.map.lps && !wl->status.map.rf_off) { + prptctrl = &pfwinfo->rpt_ctrl.finfo.v205; + + p += scnprintf(p, end - p, + " %-15s : h2c_cnt=%d(fail:%d, fw_recv:%d), c2h_cnt=%d(fw_send:%d), ", + "[summary]", pfwinfo->cnt_h2c, + pfwinfo->cnt_h2c_fail, + le32_to_cpu(prptctrl->rpt_info.cnt_h2c), + pfwinfo->cnt_c2h, + le32_to_cpu(prptctrl->rpt_info.cnt_c2h)); + + p += scnprintf(p, end - p, + "rpt_cnt=%d(fw_send:%d), rpt_map=0x%x, dm_error_map:0x%x", + pfwinfo->event[BTF_EVNT_RPT], + le32_to_cpu(prptctrl->rpt_info.cnt), + le32_to_cpu(prptctrl->rpt_info.en), + dm->error.val); + + if (dm->error.map.wl_fw_hang) + p += scnprintf(p, end - p, " (WL FW Hang!!)"); + p += scnprintf(p, end - p, "\n"); + p += scnprintf(p, end - p, + " %-15s : send_ok:%d, send_fail:%d, recv:%d, ", + "[mailbox]", + le32_to_cpu(prptctrl->bt_mbx_info.cnt_send_ok), + le32_to_cpu(prptctrl->bt_mbx_info.cnt_send_fail), + le32_to_cpu(prptctrl->bt_mbx_info.cnt_recv)); + + p += scnprintf(p, end - p, + "A2DP_empty:%d(stop:%d, tx:%d, ack:%d, nack:%d)\n", + le32_to_cpu(prptctrl->bt_mbx_info.a2dp.cnt_empty), + le32_to_cpu(prptctrl->bt_mbx_info.a2dp.cnt_flowctrl), + le32_to_cpu(prptctrl->bt_mbx_info.a2dp.cnt_tx), + le32_to_cpu(prptctrl->bt_mbx_info.a2dp.cnt_ack), + le32_to_cpu(prptctrl->bt_mbx_info.a2dp.cnt_nack)); + + p += scnprintf(p, end - p, + " %-15s : wl_rfk[req:%d/go:%d/reject:%d/timeout:%d]", + "[RFK]", wl->wcnt[BTC_WCNT_RFK_REQ], + wl->wcnt[BTC_WCNT_RFK_GO], + wl->wcnt[BTC_WCNT_RFK_REJECT], + wl->wcnt[BTC_WCNT_RFK_TIMEOUT]); + + p += scnprintf(p, end - p, + ", bt_rfk[req:%d/go:%d/reject:%d/timeout:%d/fail:%d]\n", + le32_to_cpu(prptctrl->bt_cnt[BTC_BCNT_RFK_REQ]), + le32_to_cpu(prptctrl->bt_cnt[BTC_BCNT_RFK_GO]), + le32_to_cpu(prptctrl->bt_cnt[BTC_BCNT_RFK_REJECT]), + le32_to_cpu(prptctrl->bt_cnt[BTC_BCNT_RFK_TIMEOUT]), + le32_to_cpu(prptctrl->bt_cnt[BTC_BCNT_RFK_FAIL])); + + if (le32_to_cpu(prptctrl->bt_cnt[BTC_BCNT_RFK_TIMEOUT]) > 0) + bt->rfk_info.map.timeout = 1; + else + bt->rfk_info.map.timeout = 0; + + dm->error.map.wl_rfk_timeout = bt->rfk_info.map.timeout; + } else { + p += scnprintf(p, end - p, + " %-15s : h2c_cnt=%d(fail:%d), c2h_cnt=%d, rpt_cnt=%d, rpt_map=0x%x", + "[summary]", pfwinfo->cnt_h2c, + pfwinfo->cnt_h2c_fail, pfwinfo->cnt_c2h, + pfwinfo->event[BTF_EVNT_RPT], + btc->fwinfo.rpt_en_map); + p += scnprintf(p, end - p, " (WL FW report invalid!!)\n"); + } + + for (i = 0; i < BTC_NCNT_NUM; i++) + cnt_sum += dm->cnt_notify[i]; + + p += scnprintf(p, end - p, + " %-15s : total=%d, show_coex_info=%d, power_on=%d, init_coex=%d, ", + "[notify_cnt]", cnt_sum, cnt[BTC_NCNT_SHOW_COEX_INFO], + cnt[BTC_NCNT_POWER_ON], cnt[BTC_NCNT_INIT_COEX]); + + p += scnprintf(p, end - p, + "power_off=%d, radio_state=%d, role_info=%d, wl_rfk=%d, wl_sta=%d\n", + cnt[BTC_NCNT_POWER_OFF], cnt[BTC_NCNT_RADIO_STATE], + cnt[BTC_NCNT_ROLE_INFO], cnt[BTC_NCNT_WL_RFK], + cnt[BTC_NCNT_WL_STA]); + + p += scnprintf(p, end - p, + " %-15s : scan_start=%d, scan_finish=%d, switch_band=%d, special_pkt=%d, ", + "[notify_cnt]", cnt[BTC_NCNT_SCAN_START], + cnt[BTC_NCNT_SCAN_FINISH], cnt[BTC_NCNT_SWITCH_BAND], + cnt[BTC_NCNT_SPECIAL_PACKET]); + + p += scnprintf(p, end - p, + "timer=%d, control=%d, customerize=%d\n", + cnt[BTC_NCNT_TIMER], cnt[BTC_NCNT_CONTROL], + cnt[BTC_NCNT_CUSTOMERIZE]); + + return p - buf; +} + ssize_t rtw89_btc_dump_info(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) { struct rtw89_btc *btc = &rtwdev->btc; @@ -13704,6 +13877,8 @@ ssize_t rtw89_btc_dump_info(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) p += _show_summary_v5(rtwdev, p, end - p); else if (ver->fcxbtcrpt == 105) p += _show_summary_v105(rtwdev, p, end - p); + else if (ver->fcxbtcrpt == 205) + p += _show_summary_v205(rtwdev, p, end - p); else if (ver->fcxbtcrpt == 7) p += _show_summary_v7(rtwdev, p, end - p); else if (ver->fcxbtcrpt == 8) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 5b26ea33f329..d428f527835e 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -3006,6 +3006,19 @@ struct rtw89_btc_fbtc_rpt_ctrl_v11 { __le32 scbd_b2w[2]; } __packed; +struct rtw89_btc_fbtc_rpt_ctrl_v205 { + u8 fver; + u8 rsvd; + u8 build_time[RTW89_BTC_TIME_DATE_FMT]; + u8 build_date[RTW89_BTC_TIME_DATE_FMT]; + __le16 rsvd1; + struct rtw89_btc_fbtc_rpt_ctrl_info rpt_info; + struct rtw89_btc_fbtc_rpt_ctrl_wl_fw_info wl_fw_info; + struct rtw89_btc_fbtc_rpt_ctrl_bt_mailbox bt_mbx_info; + __le32 bt_cnt[BTC_BCNT_STA_MAX]; + u8 gnt_val[RTW89_PHY_NUM][4]; +} __packed; + union rtw89_btc_fbtc_rpt_ctrl_ver_info { struct rtw89_btc_fbtc_rpt_ctrl_v1 v1; struct rtw89_btc_fbtc_rpt_ctrl_v4 v4; @@ -3015,6 +3028,7 @@ union rtw89_btc_fbtc_rpt_ctrl_ver_info { struct rtw89_btc_fbtc_rpt_ctrl_v8 v8; struct rtw89_btc_fbtc_rpt_ctrl_v9 v9; struct rtw89_btc_fbtc_rpt_ctrl_v11 v11; + struct rtw89_btc_fbtc_rpt_ctrl_v205 v205; }; enum rtw89_fbtc_ext_ctrl_type { From 6047d2f7efd0c14a80eb56c6d83314f90ea5f89d Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 23 Sep 2026 15:13:50 +0800 Subject: [PATCH 0947/2126] wifi: rtw89: coex: Add firmware 0.27.130.1 support for RTL8852C Add a new entry in rtw89_btc_ver_defs for RTL8852C firmware version 0.27.130.1, which introduces fcxbtcrpt=205. The new entry activates the v205 coexistence report path added in the preceding commit. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 0f3347fdbb01..b80e7979a1ae 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -146,7 +146,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, .fcxstep = 7, .fcxnullsta = 7, .fcxmreg = 7, .fcxgpiodbg = 8, .fcxbtver = 8, .fcxbtscan = 8, .fcxbtafh = 8, .fcxbtdevinfo = 8, - .fwlrole = 10, .frptmap = 5, .fcxctrl = 9, .fcxinit = 10, + .fwlrole = 10, .frptmap = 5, .fcxctrl = 9, .fcxinit = 10, .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800, .max_role_num = 6, .fcxosi = 6, .fcxmlo = 2, .bt_desired = 8, .fcxtrx = 9, .fcxtxpwr = 1, @@ -224,7 +224,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .fcxtrx = 107, .fcxtxpwr = 0, }, {RTL8851B, RTW89_FW_VER_CODE(0, 29, 29, 0), - .fcxbtcrpt = 105, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 5, + .fcxbtcrpt = 105, .fcxtdma = 3, .fcxslots = 1, .fcxcysta = 5, .fcxstep = 3, .fcxnullsta = 2, .fcxmreg = 2, .fcxgpiodbg = 1, .fcxbtver = 1, .fcxbtscan = 2, .fcxbtafh = 2, .fcxbtdevinfo = 1, .fwlrole = 2, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, @@ -232,6 +232,15 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, .fcxtrx = 0, .fcxtxpwr = 0, }, + {RTL8852C, RTW89_FW_VER_CODE(0, 27, 130, 1), + .fcxbtcrpt = 205, .fcxtdma = 4, .fcxslots = 2, .fcxcysta = 105, + .fcxstep = 3, .fcxnullsta = 2, .fcxmreg = 2, .fcxgpiodbg = 1, + .fcxbtver = 1, .fcxbtscan = 2, .fcxbtafh = 2, .fcxbtdevinfo = 1, + .fwlrole = 101, .frptmap = 3, .fcxctrl = 1, .fcxinit = 0, + .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280, + .max_role_num = 5, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 7, + .fcxtrx = 107, .fcxtxpwr = 0, + }, {RTL8852C, RTW89_FW_VER_CODE(0, 27, 97, 0), .fcxbtcrpt = 4, .fcxtdma = 4, .fcxslots = 2, .fcxcysta = 105, .fcxstep = 3, .fcxnullsta = 2, .fcxmreg = 2, .fcxgpiodbg = 1, From d6c34b67ad5c16159037ee0a7cbde814af7e0275 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 23 Sep 2026 15:13:51 +0800 Subject: [PATCH 0948/2126] wifi: rtw89: coex: fix BT scoreboard update for non-C2H paths The scoreboard update function was changed to always read from scbd_c2h, which is populated only by BTF_EVNT_BT_SCBD C2H events from the BT firmware. This caused two problems. First, calling _update_bt_scbd at the NTFY_INIT notification with scbd_c2h still zero would set bt->enable.now to 0, overwriting the bt-on assumption that _ntfy_init_coex establishes for all chips. Remove the NTFY_INIT call to preserve that default. Second, chips whose BT firmware does not send BTF_EVNT_BT_SCBD events have scbd_c2h stuck at zero indefinitely, making scoreboard updates non-functional. Restore a hardware register read path by adding _read_scbd() and an is_c2h flag to _update_bt_scbd. The NTFY_RADIO_STATE path passes is_c2h=false to read the hardware scoreboard register directly, ensuring correct BT state even without C2H support. Pass BTC_ALL_BT so both BT devices are refreshed on dual-BT chips. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-5-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 28 +++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index b80e7979a1ae..6b72e2c80d14 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1010,7 +1010,7 @@ static void _run_coex(struct rtw89_dev *rtwdev, enum btc_reason_and_action reason); static void _write_scbd(struct rtw89_dev *rtwdev, u8 bid, u32 val, bool state); static u8 _sned_h2c_w2bscbd(struct rtw89_dev *rtwdev, bool force_exec, u8 bid); -static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid); +static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid, bool is_c2h); static const char *id_to_h2c(u32 id); static void _reset_h2c_macro(struct rtw89_btc *btc) @@ -3902,7 +3902,7 @@ void btc_fw_event(struct rtw89_dev *rtwdev, u8 evt_id, void *data, u32 len) "[BTC], %s() bt%d:c2h->0x%08x, rb->0x%08x\n", __func__, i, bt->scbd_c2h, bt->scbd_rb); bt->scbd_c2h = bt->scbd_rb; - _update_bt_scbd(rtwdev, i); + _update_bt_scbd(rtwdev, i, true); btc->dm.scbd_b2w_update = false; } } @@ -8116,7 +8116,21 @@ static void _update_bt_ctrl_lps(struct rtw89_dev *rtwdev) } } -static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid) +static u32 _read_scbd(struct rtw89_dev *rtwdev, u8 id) +{ + const struct rtw89_chip_info *chip = rtwdev->chip; + u32 val; + + if (!chip->scbd) + return 0; + + val = rtw89_read32(rtwdev, chip->btc_sb.n[id].get); + rtw89_debug(rtwdev, RTW89_DBG_BTC, + "[BTC], read scbd bt%d: 0x%08x\n", id, val); + return val; +} + +static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid, bool is_c2h) { struct rtw89_btc_bt_link_info *bt_2g, *bt_56g; struct rtw89_btc *btc = &rtwdev->btc; @@ -8149,7 +8163,7 @@ static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid) if (!(rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT) && id == BTC_BT_2ND) break; - val = bt->scbd_c2h; + val = is_c2h ? bt->scbd_c2h : _read_scbd(rtwdev, id); if (val == 0xffffffff) { rtw89_debug(rtwdev, RTW89_DBG_BTC, @@ -8785,8 +8799,8 @@ void _run_coex(struct rtw89_dev *rtwdev, enum btc_reason_and_action reason) _update_run_ctrl_info(rtwdev); - if (reason == BTC_RSN_NTFY_INIT || reason == BTC_RSN_NTFY_RADIO_STATE) - _update_bt_scbd(rtwdev, false); + if (reason == BTC_RSN_NTFY_RADIO_STATE) + _update_bt_scbd(rtwdev, BTC_ALL_BT, false); dm->freerun = false; dm->cnt_dm[BTC_DCNT_RUN]++; @@ -10131,7 +10145,7 @@ void rtw89_btc_c2h_handle(struct rtw89_dev *rtwdev, struct sk_buff *skb, rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], handle C2H BT%d SCBD with data 0x%08x\n", bid, bt->scbd_c2h); - _update_bt_scbd(rtwdev, bid); + _update_bt_scbd(rtwdev, bid, true); _run_coex(rtwdev, BTC_RSN_UPDATE_BT_SCBD); break; case BTF_EVNT_BT_PSD: From 5f57e54539462915cd47d1baf2fd0582023921e5 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 23 Sep 2026 15:13:52 +0800 Subject: [PATCH 0949/2126] wifi: rtw89: add instance of IO ops for (un)pack and [um]delay To make IO wrappers of pack/unpack/udely/mdely can intuitively call the loaded IO ops as others do, add corresponding instances for them. And, expect all rtw89_io_ops initializers should assign all members. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-6-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 40 ++++++++++++++--------- drivers/net/wireless/realtek/rtw89/fw.c | 10 +++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index d428f527835e..99c7e8604888 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -8116,36 +8116,44 @@ struct rtw89_tx_skb_data *RTW89_TX_SKB_CB(struct sk_buff *skb) return (struct rtw89_tx_skb_data *)info->driver_data; } +static inline int rtw89_raw_io_pack(struct rtw89_dev *rtwdev) +{ + return 0; +} + +static inline int rtw89_raw_io_unpack(struct rtw89_dev *rtwdev) +{ + return 0; +} + +static inline void rtw89_raw_io_udelay(struct rtw89_dev *rtwdev, u32 us) +{ + udelay(us); +} + +static inline void rtw89_raw_io_mdelay(struct rtw89_dev *rtwdev, u32 ms) +{ + mdelay(ms); +} + static inline int rtw89_io_pack(struct rtw89_dev *rtwdev) { - if (rtwdev->io->pack) - return rtwdev->io->pack(rtwdev); - - return 0; + return rtwdev->io->pack(rtwdev); } static inline int rtw89_io_unpack(struct rtw89_dev *rtwdev) { - if (rtwdev->io->unpack) - return rtwdev->io->unpack(rtwdev); - - return 0; + return rtwdev->io->unpack(rtwdev); } static inline void rtw89_io_udelay(struct rtw89_dev *rtwdev, u32 us) { - if (rtwdev->io->do_udelay) - rtwdev->io->do_udelay(rtwdev, us); - else - udelay(us); + rtwdev->io->do_udelay(rtwdev, us); } static inline void rtw89_io_mdelay(struct rtw89_dev *rtwdev, u32 ms) { - if (rtwdev->io->do_mdelay) - rtwdev->io->do_mdelay(rtwdev, ms); - else - mdelay(ms); + rtwdev->io->do_mdelay(rtwdev, ms); } static inline u8 rtw89_read8(struct rtw89_dev *rtwdev, u32 addr) diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index d53e670a29cf..a45281eba1ff 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -13086,8 +13086,10 @@ static int rtw89_fw_cmd_ofld_enqueue(struct rtw89_dev *rtwdev, } static const struct rtw89_io_ops rtw89_raw_io = { - .pack = NULL, - .unpack = NULL, + .pack = rtw89_raw_io_pack, + .unpack = rtw89_raw_io_unpack, + .do_udelay = rtw89_raw_io_udelay, + .do_mdelay = rtw89_raw_io_mdelay, .write8 = rtw89_raw_write8, .write16 = rtw89_raw_write16, .write32 = rtw89_raw_write32, @@ -13266,7 +13268,7 @@ static void rtw89_fw_cmd_ofld_udelay(struct rtw89_dev *rtwdev, u32 us) ret = rtw89_fw_cmd_ofld_enqueue(rtwdev, &cmd); if (ret) - udelay(us); + rtw89_raw_io.do_udelay(rtwdev, us); } static void rtw89_fw_cmd_ofld_mdelay(struct rtw89_dev *rtwdev, u32 ms) @@ -13280,7 +13282,7 @@ static void rtw89_fw_cmd_ofld_mdelay(struct rtw89_dev *rtwdev, u32 ms) ret = rtw89_fw_cmd_ofld_enqueue(rtwdev, &cmd); if (ret) - mdelay(ms); + rtw89_raw_io.do_mdelay(rtwdev, ms); } static const struct rtw89_io_ops rtw89_fw_cmd_ofld_io = { From 587acb86d6465efdc03f6d8524461e6e725597b7 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Thu, 24 Sep 2026 20:05:19 +0200 Subject: [PATCH 0950/2126] enetc: Increase eMDIO MDC rate to 2.5 MHz The current eMDIO MDC rate is 558 kHz on i.MX95 B0. This is very low, but also very compatible. However, for example NXP TJA1120 PHY needs at minimum 1 MHz MDC clock and 558 kHz does not work with that PHY. As a minimum change, increase the MDC clock to 2.5 MHz which matches the 802.3 specification. Also, even old PHYs like LAN8210Ai, KSZ8794, DP83822 support up to 2.5 MHz MDC clock frequency, and it covers the NXP TJA1120 as well. There is no known rationale for why the 558 kHz was picked when the eMDIO driver was added. Signed-off-by: Marek Vasut Link: https://patch.msgid.link/20260924180607.60932-1-marex@nabladev.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/enetc/enetc_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_mdio.c b/drivers/net/ethernet/freescale/enetc/enetc_mdio.c index 998aaa394e9c..a90a04a47bef 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_mdio.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_mdio.c @@ -24,7 +24,7 @@ #define ENETC_EMDIO_CFG \ (MDIO_CFG_HOLD(2) | \ - MDIO_CFG_CLKDIV(258) | \ + MDIO_CFG_CLKDIV(66) | \ MDIO_CFG_NEG) #define MDIO_CTL_DEV_ADDR(x) ((x) & 0x1f) From 6d0c77424034bd2b14ec06c648e028b2992c8b9e Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 23 Sep 2026 15:13:53 +0800 Subject: [PATCH 0951/2126] wifi: rtw89: coex: offload 8852C IO writes via firmware CMD pack region On USB, 8852C is the only chip with .support_fw_cmd_ofld set, which routes register writes through the FW command offload path via the transparent io_ops indirection. The coex layer never entered an rtw89_io_pack() region, so its register writes were always issued individually instead of being batched to the firmware. Wrap the RF LUT and GNT write sequences in rtw8852c_btc_init_cfg(), rtw8852c_btc_wl_s1_standby() and rtw8852c_set_wl_lna2() with rtw89_io_pack()/rtw89_io_unpack() so that on USB these writes are enqueued and flushed as a single FW command batch. On PCIe the pack region is a no-op and raw MMIO proceeds unchanged. Only write_rf partial-mask, write-only sequences are offloaded, for which the firmware performs the read-modify-write. Driver-side same-register read-modify-write helpers and BB phy_write32 flows are kept outside the pack region to avoid the offload full-dword overwrite hazard. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-7-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8852c.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852c.c b/drivers/net/wireless/realtek/rtw89/rtw8852c.c index c68959b63a01..7649706b67e6 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852c.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852c.c @@ -2706,6 +2706,8 @@ static void rtw8852c_btc_init_cfg(struct rtw89_dev *rtwdev) chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_TX_RESP, true); chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_BEACON, true); + rtw89_io_pack(rtwdev); + /* set rf gnt debug off */ rtw89_write_rf(rtwdev, RF_PATH_A, RR_WLSEL, RFREG_MASK, 0x0); rtw89_write_rf(rtwdev, RF_PATH_B, RR_WLSEL, RFREG_MASK, 0x0); @@ -2733,6 +2735,8 @@ static void rtw8852c_btc_init_cfg(struct rtw89_dev *rtwdev) rtw89_write32_set(rtwdev, R_AX_BT_CNT_CFG, B_AX_BT_CNT_EN | B_AX_BT_CNT_RST_V1); + + rtw89_io_unpack(rtwdev); } static @@ -2888,6 +2892,8 @@ void rtw8852c_btc_update_bt_cnt(struct rtw89_dev *rtwdev) static void rtw8852c_btc_wl_s1_standby(struct rtw89_dev *rtwdev, bool state) { + rtw89_io_pack(rtwdev); + rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x80000); rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWA, RFREG_MASK, 0x1); rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWD1, RFREG_MASK, 0x620); @@ -2901,6 +2907,8 @@ void rtw8852c_btc_wl_s1_standby(struct rtw89_dev *rtwdev, bool state) RFREG_MASK, 0x208); rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0); + + rtw89_io_unpack(rtwdev); } static void rtw8852c_set_wl_lna2(struct rtw89_dev *rtwdev, u8 level) @@ -2910,6 +2918,8 @@ static void rtw8852c_set_wl_lna2(struct rtw89_dev *rtwdev, u8 level) * To improve BT ACI in co-rx */ + rtw89_io_pack(rtwdev); + switch (level) { case 0: /* default */ rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x1000); @@ -2936,6 +2946,8 @@ static void rtw8852c_set_wl_lna2(struct rtw89_dev *rtwdev, u8 level) rtw89_write_rf(rtwdev, RF_PATH_B, RR_LUTWE, RFREG_MASK, 0x0); break; } + + rtw89_io_unpack(rtwdev); } static void rtw8852c_btc_set_wl_rx_gain(struct rtw89_dev *rtwdev, u32 level) From 3e6a0e83c91389f8efec0805a195008248a97ff8 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 25 Sep 2026 13:10:42 -0700 Subject: [PATCH 0952/2126] octeontx2: remove unneeded symbol exports octeontx2 has a bunch of symbols not used outside the module which defines them. Worse, still the macro which defines otx2_mbox_up_handler_* adds exports for all the functions. Remove all the explicit exports and the auto-export from that macro. otx2_mbox_up_handler_cgx_link_event was exported by the macro and is genuienly called from the VF driver, so add an export. Link: https://lore.kernel.org/arYYTw8l90VNnKal@infradead.org Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20260925201042.1174488-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/octeontx2/af/cn20k/npa.c | 1 - drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 8 +------- drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c | 5 ----- drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c | 3 --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 2 +- drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 1 - 6 files changed, 2 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npa.c b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npa.c index fe8f926c8b75..8ebbf844f155 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npa.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npa.c @@ -18,4 +18,3 @@ int rvu_mbox_handler_npa_cn20k_aq_enq(struct rvu *rvu, return rvu_npa_aq_enq_inst(rvu, (struct npa_aq_enq_req *)req, (struct npa_aq_enq_rsp *)rsp); } -EXPORT_SYMBOL(rvu_mbox_handler_npa_cn20k_aq_enq); diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c index 175992188c18..6e4ad26a663a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -732,7 +732,6 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for return otx2_sync_mbox_msg(&pfvf->mbox); } -EXPORT_SYMBOL(otx2_txschq_config); int otx2_smq_flush(struct otx2_nic *pfvf, int smq) { @@ -756,7 +755,6 @@ int otx2_smq_flush(struct otx2_nic *pfvf, int smq) mutex_unlock(&pfvf->mbox.lock); return rc; } -EXPORT_SYMBOL(otx2_smq_flush); int otx2_txsch_alloc(struct otx2_nic *pfvf) { @@ -828,7 +826,6 @@ void otx2_txschq_free_one(struct otx2_nic *pfvf, u16 lvl, u16 schq) mutex_unlock(&pfvf->mbox.lock); } -EXPORT_SYMBOL(otx2_txschq_free_one); void otx2_txschq_stop(struct otx2_nic *pfvf) { @@ -1838,7 +1835,6 @@ int otx2_nix_config_bp(struct otx2_nic *pfvf, bool enable) return otx2_sync_mbox_msg(&pfvf->mbox); } -EXPORT_SYMBOL(otx2_nix_config_bp); int otx2_nix_cpt_config_bp(struct otx2_nic *pfvf, bool enable) { @@ -1863,7 +1859,6 @@ int otx2_nix_cpt_config_bp(struct otx2_nic *pfvf, bool enable) return otx2_sync_mbox_msg(&pfvf->mbox); } -EXPORT_SYMBOL(otx2_nix_cpt_config_bp); /* Mbox message handlers */ void mbox_handler_cgx_stats(struct otx2_nic *pfvf, @@ -2110,8 +2105,7 @@ otx2_mbox_up_handler_ ## _fn_name(struct otx2_nic *pfvf, \ { \ /* Nothing to do here */ \ return 0; \ -} \ -EXPORT_SYMBOL(otx2_mbox_up_handler_ ## _fn_name); +} MBOX_UP_CGX_MESSAGES MBOX_UP_MCS_MESSAGES #undef M diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c index 91d346d114af..e3d54009180d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c @@ -54,7 +54,6 @@ int otx2_pfc_txschq_config(struct otx2_nic *pfvf) return 0; } -EXPORT_SYMBOL(otx2_pfc_txschq_config); static int otx2_pfc_txschq_alloc_one(struct otx2_nic *pfvf, u8 prio) { @@ -123,7 +122,6 @@ int otx2_pfc_txschq_alloc(struct otx2_nic *pfvf) return 0; } -EXPORT_SYMBOL(otx2_pfc_txschq_alloc); static int otx2_pfc_txschq_stop_one(struct otx2_nic *pfvf, u8 prio) { @@ -262,7 +260,6 @@ update_sq_smq_map: return 0; } -EXPORT_SYMBOL(otx2_pfc_txschq_update); int otx2_pfc_txschq_stop(struct otx2_nic *pfvf) { @@ -285,7 +282,6 @@ int otx2_pfc_txschq_stop(struct otx2_nic *pfvf) return 0; } -EXPORT_SYMBOL(otx2_pfc_txschq_stop); int otx2_config_priority_flow_ctrl(struct otx2_nic *pfvf) { @@ -395,7 +391,6 @@ out: "Updating BPIDs in CQ and Aura contexts of RQ%d failed with err %d\n", qidx, err); } -EXPORT_SYMBOL(otx2_update_bpid_in_rqctx); static int otx2_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc) { diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c index 99d78fc5a2c4..6d095023d17b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c @@ -281,7 +281,6 @@ exit: count, allocated); return allocated; } -EXPORT_SYMBOL(otx2_alloc_mcam_entries); int otx2_mcam_entry_init(struct otx2_nic *pfvf) { @@ -420,7 +419,6 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf) refcount_set(&flow_cfg->mark_flows, 1); return 0; } -EXPORT_SYMBOL(otx2_mcam_entry_init); /* TODO : revisit on size */ #define OTX2_DMAC_FLTR_BITMAP_SZ (4 * 2048 + 32) @@ -654,7 +652,6 @@ int otx2_get_maxflows(struct otx2_flow_config *flow_cfg) else return flow_cfg->max_flows; } -EXPORT_SYMBOL(otx2_get_maxflows); int otx2_get_flow(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc, u32 location) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c index c0e2100de1d9..7dc0ce669d0b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -959,6 +959,7 @@ int otx2_mbox_up_handler_cgx_link_event(struct otx2_nic *pf, otx2_handle_link_event(pf); return 0; } +EXPORT_SYMBOL(otx2_mbox_up_handler_cgx_link_event); static int otx2_process_mbox_msg_up(struct otx2_nic *pf, struct mbox_msghdr *req) @@ -3102,7 +3103,6 @@ int otx2_realloc_msix_vectors(struct otx2_nic *pf) return otx2_register_mbox_intr(pf, false); } -EXPORT_SYMBOL(otx2_realloc_msix_vectors); static int otx2_sriov_vfcfg_init(struct otx2_nic *pf) { diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c index 039fd47ebf52..dee38d5c7f65 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c @@ -1675,4 +1675,3 @@ void otx2_tc_apply_ingress_police_rules(struct otx2_nic *nic) otx2_tc_config_ingress_rule(nic, node); } } -EXPORT_SYMBOL(otx2_tc_apply_ingress_police_rules); From 6c095c657b316c2811d1e901e03300ab73284b8b Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 23 Sep 2026 15:13:54 +0800 Subject: [PATCH 0953/2126] wifi: rtw89: coex: batch PTA init with masked IO offload On USB, the register writes in coex init cannot be fully batched into a single H2C because the write32 IO offload only carries MASKDWORD, i.e. a full-dword overwrite. Read-modify-write helpers derive the new value from a driver-side read that cannot observe other writes still queued in the same pack region, so packing a same-register sequence would drop bits. mac_coex_init_v1() and btc_set_wl_pri() were thus left outside the pack region and issued as separate H2C commands, costing hundreds of ms. Add write8_mask/write16_mask/write32_mask to the IO ops. For the raw IO path, these ops are implemented as direct read-modify-write on the hardware. For the firmware offload path, they forward the field mask to the FW so it can perform the read-modify-write server-side, removing the dependency on a driver-side read of a register whose new value may still be queued. Extract the raw read-modify-write bodies of write8_set, write16_set, write32_set, write8_clr, write16_clr, write32_clr, write8_mask, write16_mask, and write32_mask into rtw89_raw_write*() helpers, grouping raw_* variants before the io-dispatching thin wrappers. Replace the original functions with thin wrappers that dispatch through rtwdev->io, removing the inline capability checks. With that in place, extend the 8852c PTA init pack region to cover mac_coex_init_v1() and btc_set_wl_pri(). Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923071354.50864-8-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 132 +++++++++++++----- drivers/net/wireless/realtek/rtw89/fw.c | 112 +++++++++++++++ drivers/net/wireless/realtek/rtw89/fw.h | 8 +- drivers/net/wireless/realtek/rtw89/rtw8852c.c | 4 +- 4 files changed, 220 insertions(+), 36 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 99c7e8604888..7e74b5c9ed49 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -7610,6 +7610,18 @@ struct rtw89_io_ops { void (*phy_write32)(struct rtw89_dev *rtwdev, u32 addr, u32 data); void (*write_rf)(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path, u32 addr, u32 mask, u32 data); + void (*write8_set)(struct rtw89_dev *rtwdev, u32 addr, u8 bit); + void (*write16_set)(struct rtw89_dev *rtwdev, u32 addr, u16 bit); + void (*write32_set)(struct rtw89_dev *rtwdev, u32 addr, u32 bit); + void (*write8_clr)(struct rtw89_dev *rtwdev, u32 addr, u8 bit); + void (*write16_clr)(struct rtw89_dev *rtwdev, u32 addr, u16 bit); + void (*write32_clr)(struct rtw89_dev *rtwdev, u32 addr, u32 bit); + void (*write8_mask)(struct rtw89_dev *rtwdev, u32 addr, u32 mask, + u8 data); + void (*write16_mask)(struct rtw89_dev *rtwdev, u32 addr, u32 mask, + u16 data); + void (*write32_mask)(struct rtw89_dev *rtwdev, u32 addr, u32 mask, + u32 data); }; struct rtw89_dev { @@ -8202,57 +8214,93 @@ static inline void rtw89_write32(struct rtw89_dev *rtwdev, u32 addr, u32 data) } static inline void -rtw89_write8_set(struct rtw89_dev *rtwdev, u32 addr, u8 bit) +rtw89_raw_write8_set(struct rtw89_dev *rtwdev, u32 addr, u8 bit) { u8 val; val = rtw89_read8(rtwdev, addr); - rtw89_write8(rtwdev, addr, val | bit); + rtw89_raw_write8(rtwdev, addr, val | bit); +} + +static inline void +rtw89_raw_write16_set(struct rtw89_dev *rtwdev, u32 addr, u16 bit) +{ + u16 val; + + val = rtw89_read16(rtwdev, addr); + rtw89_raw_write16(rtwdev, addr, val | bit); +} + +static inline void +rtw89_raw_write32_set(struct rtw89_dev *rtwdev, u32 addr, u32 bit) +{ + u32 val; + + val = rtw89_read32(rtwdev, addr); + rtw89_raw_write32(rtwdev, addr, val | bit); +} + +static inline void +rtw89_write8_set(struct rtw89_dev *rtwdev, u32 addr, u8 bit) +{ + rtwdev->io->write8_set(rtwdev, addr, bit); } static inline void rtw89_write16_set(struct rtw89_dev *rtwdev, u32 addr, u16 bit) { - u16 val; - - val = rtw89_read16(rtwdev, addr); - rtw89_write16(rtwdev, addr, val | bit); + rtwdev->io->write16_set(rtwdev, addr, bit); } static inline void rtw89_write32_set(struct rtw89_dev *rtwdev, u32 addr, u32 bit) +{ + rtwdev->io->write32_set(rtwdev, addr, bit); +} + +static inline void +rtw89_raw_write8_clr(struct rtw89_dev *rtwdev, u32 addr, u8 bit) +{ + u8 val; + + val = rtw89_read8(rtwdev, addr); + rtw89_raw_write8(rtwdev, addr, val & ~bit); +} + +static inline void +rtw89_raw_write16_clr(struct rtw89_dev *rtwdev, u32 addr, u16 bit) +{ + u16 val; + + val = rtw89_read16(rtwdev, addr); + rtw89_raw_write16(rtwdev, addr, val & ~bit); +} + +static inline void +rtw89_raw_write32_clr(struct rtw89_dev *rtwdev, u32 addr, u32 bit) { u32 val; val = rtw89_read32(rtwdev, addr); - rtw89_write32(rtwdev, addr, val | bit); + rtw89_raw_write32(rtwdev, addr, val & ~bit); } static inline void rtw89_write8_clr(struct rtw89_dev *rtwdev, u32 addr, u8 bit) { - u8 val; - - val = rtw89_read8(rtwdev, addr); - rtw89_write8(rtwdev, addr, val & ~bit); + rtwdev->io->write8_clr(rtwdev, addr, bit); } static inline void rtw89_write16_clr(struct rtw89_dev *rtwdev, u32 addr, u16 bit) { - u16 val; - - val = rtw89_read16(rtwdev, addr); - rtw89_write16(rtwdev, addr, val & ~bit); + rtwdev->io->write16_clr(rtwdev, addr, bit); } static inline void rtw89_write32_clr(struct rtw89_dev *rtwdev, u32 addr, u32 bit) { - u32 val; - - val = rtw89_read32(rtwdev, addr); - rtw89_write32(rtwdev, addr, val & ~bit); + rtwdev->io->write32_clr(rtwdev, addr, bit); } static inline u32 @@ -8294,46 +8342,66 @@ rtw89_read8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask) return ret; } +static inline void +rtw89_raw_write8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u8 data) +{ + u8 orig, set; + + orig = rtw89_read8(rtwdev, addr); + set = (orig & ~mask) | (data & mask); + rtw89_raw_write8(rtwdev, addr, set); +} + +static inline void +rtw89_raw_write16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u16 data) +{ + u16 orig, set; + + orig = rtw89_read16(rtwdev, addr); + set = (orig & ~mask) | (data & mask); + rtw89_raw_write16(rtwdev, addr, set); +} + +static inline void +rtw89_raw_write32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u32 data) +{ + u32 orig, set; + + orig = rtw89_read32(rtwdev, addr); + set = (orig & ~mask) | (data & mask); + rtw89_raw_write32(rtwdev, addr, set); +} + static inline void rtw89_write32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u32 data) { u32 shift = __ffs(mask); - u32 orig; - u32 set; WARN(addr & 0x3, "should be 4-byte aligned, addr = 0x%08x\n", addr); - orig = rtw89_read32(rtwdev, addr); - set = (orig & ~mask) | ((data << shift) & mask); - rtw89_write32(rtwdev, addr, set); + rtwdev->io->write32_mask(rtwdev, addr, mask, (data << shift) & mask); } static inline void rtw89_write16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u16 data) { u32 shift; - u16 orig, set; mask &= 0xffff; shift = __ffs(mask); - orig = rtw89_read16(rtwdev, addr); - set = (orig & ~mask) | ((data << shift) & mask); - rtw89_write16(rtwdev, addr, set); + rtwdev->io->write16_mask(rtwdev, addr, mask, (data << shift) & mask); } static inline void rtw89_write8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u8 data) { u32 shift; - u8 orig, set; mask &= 0xff; shift = __ffs(mask); - orig = rtw89_read8(rtwdev, addr); - set = (orig & ~mask) | ((data << shift) & mask); - rtw89_write8(rtwdev, addr, set); + rtwdev->io->write8_mask(rtwdev, addr, mask, (data << shift) & mask); } static inline u32 diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index a45281eba1ff..4ac2fd117b95 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -13093,6 +13093,15 @@ static const struct rtw89_io_ops rtw89_raw_io = { .write8 = rtw89_raw_write8, .write16 = rtw89_raw_write16, .write32 = rtw89_raw_write32, + .write8_set = rtw89_raw_write8_set, + .write16_set = rtw89_raw_write16_set, + .write32_set = rtw89_raw_write32_set, + .write8_clr = rtw89_raw_write8_clr, + .write16_clr = rtw89_raw_write16_clr, + .write32_clr = rtw89_raw_write32_clr, + .write8_mask = rtw89_raw_write8_mask, + .write16_mask = rtw89_raw_write16_mask, + .write32_mask = rtw89_raw_write32_mask, .phy_write8 = rtw89_raw_phy_write8, .phy_write16 = rtw89_raw_phy_write16, .phy_write32 = rtw89_raw_phy_write32, @@ -13201,6 +13210,100 @@ void rtw89_fw_cmd_ofld_write32(struct rtw89_dev *rtwdev, u32 addr, u32 data) rtw89_raw_io.write32(rtwdev, addr, data); } +static void +rtw89_fw_cmd_ofld_write8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, + u8 data) +{ + u32 dword_mask = RTW89_W8_MASK_OF_ALIGNED_ADDR(addr); + u32 shift = RTW89_W8_SHIFT_OF_ALIGNED_ADDR(addr); + struct rtw89_fw_cmd_ofld_arg cmd = { + .src = RTW89_FW_CMD_OFLD_SRC_MAC, + .type = RTW89_FW_CMD_OFLD_WRITE, + .offset = ALIGN_DOWN(addr, 4), + .mask = (mask << shift) & dword_mask, + .value = (data << shift) & dword_mask, + }; + int ret; + + ret = rtw89_fw_cmd_ofld_enqueue(rtwdev, &cmd); + if (ret) + rtw89_raw_io.write8_mask(rtwdev, addr, mask, data); +} + +static void +rtw89_fw_cmd_ofld_write16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, + u16 data) +{ + u32 dword_mask = RTW89_W16_MASK_OF_ALIGNED_ADDR(addr); + u32 shift = RTW89_W16_SHIFT_OF_ALIGNED_ADDR(addr); + struct rtw89_fw_cmd_ofld_arg cmd = { + .src = RTW89_FW_CMD_OFLD_SRC_MAC, + .type = RTW89_FW_CMD_OFLD_WRITE, + .offset = ALIGN_DOWN(addr, 4), + .mask = (mask << shift) & dword_mask, + .value = (data << shift) & dword_mask, + }; + int ret; + + ret = rtw89_fw_cmd_ofld_enqueue(rtwdev, &cmd); + if (ret) + rtw89_raw_io.write16_mask(rtwdev, addr, mask, data); +} + +static void +rtw89_fw_cmd_ofld_write32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, + u32 data) +{ + struct rtw89_fw_cmd_ofld_arg cmd = { + .src = RTW89_FW_CMD_OFLD_SRC_MAC, + .type = RTW89_FW_CMD_OFLD_WRITE, + .offset = addr, + .mask = mask, + .value = data, + }; + int ret; + + ret = rtw89_fw_cmd_ofld_enqueue(rtwdev, &cmd); + if (ret) + rtw89_raw_io.write32_mask(rtwdev, addr, mask, data); +} + +static void +rtw89_fw_cmd_ofld_write8_set(struct rtw89_dev *rtwdev, u32 addr, u8 bit) +{ + rtw89_fw_cmd_ofld_write8_mask(rtwdev, addr, bit, bit); +} + +static void +rtw89_fw_cmd_ofld_write16_set(struct rtw89_dev *rtwdev, u32 addr, u16 bit) +{ + rtw89_fw_cmd_ofld_write16_mask(rtwdev, addr, bit, bit); +} + +static void +rtw89_fw_cmd_ofld_write32_set(struct rtw89_dev *rtwdev, u32 addr, u32 bit) +{ + rtw89_fw_cmd_ofld_write32_mask(rtwdev, addr, bit, bit); +} + +static void +rtw89_fw_cmd_ofld_write8_clr(struct rtw89_dev *rtwdev, u32 addr, u8 bit) +{ + rtw89_fw_cmd_ofld_write8_mask(rtwdev, addr, bit, 0); +} + +static void +rtw89_fw_cmd_ofld_write16_clr(struct rtw89_dev *rtwdev, u32 addr, u16 bit) +{ + rtw89_fw_cmd_ofld_write16_mask(rtwdev, addr, bit, 0); +} + +static void +rtw89_fw_cmd_ofld_write32_clr(struct rtw89_dev *rtwdev, u32 addr, u32 bit) +{ + rtw89_fw_cmd_ofld_write32_mask(rtwdev, addr, bit, 0); +} + static void rtw89_fw_cmd_ofld_write_rf_ddv(struct rtw89_dev *rtwdev, struct rtw89_fw_cmd_ofld_arg *cmd, enum rtw89_rf_path rf_path, u32 addr, u32 mask, @@ -13297,6 +13400,15 @@ static const struct rtw89_io_ops rtw89_fw_cmd_ofld_io = { .phy_write16 = rtw89_fw_cmd_ofld_phy_write16, .phy_write32 = rtw89_fw_cmd_ofld_phy_write32, .write_rf = rtw89_fw_cmd_ofld_write_rf, + .write8_set = rtw89_fw_cmd_ofld_write8_set, + .write16_set = rtw89_fw_cmd_ofld_write16_set, + .write32_set = rtw89_fw_cmd_ofld_write32_set, + .write8_clr = rtw89_fw_cmd_ofld_write8_clr, + .write16_clr = rtw89_fw_cmd_ofld_write16_clr, + .write32_clr = rtw89_fw_cmd_ofld_write32_clr, + .write8_mask = rtw89_fw_cmd_ofld_write8_mask, + .write16_mask = rtw89_fw_cmd_ofld_write16_mask, + .write32_mask = rtw89_fw_cmd_ofld_write32_mask, }; const struct rtw89_io_ops * diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 23adf12f132e..9b616ec9323b 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -3281,8 +3281,12 @@ struct rtw89_h2c_cmd_ofld { #define RTW89_H2C_CMD_OFLD_W1_BASE_OFFSET GENMASK(31, 16) #define RTW89_H2C_CMD_OFLD_W2_VALUE GENMASK(31, 0) #define RTW89_H2C_CMD_OFLD_W3_MASK GENMASK(31, 0) -#define RTW89_W8_MASK_OF_ALIGNED_ADDR(offset) (0xff << (((offset) & 0x3) << 3)) -#define RTW89_W16_MASK_OF_ALIGNED_ADDR(offset) (0xffff << (((offset) & 0x2) * 8)) +#define RTW89_W8_SHIFT_OF_ALIGNED_ADDR(offset) (((offset) & 0x3) << 3) +#define RTW89_W16_SHIFT_OF_ALIGNED_ADDR(offset) (((offset) & 0x2) << 3) +#define RTW89_W8_MASK_OF_ALIGNED_ADDR(offset) \ + (0xff << RTW89_W8_SHIFT_OF_ALIGNED_ADDR(offset)) +#define RTW89_W16_MASK_OF_ALIGNED_ADDR(offset) \ + (0xffff << RTW89_W16_SHIFT_OF_ALIGNED_ADDR(offset)) #define RTW89_FW_CMD_OFLD_NR 125 struct rtw89_fw_cmd_ofld_info { diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852c.c b/drivers/net/wireless/realtek/rtw89/rtw8852c.c index 7649706b67e6..624f23b3f2a1 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852c.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852c.c @@ -2699,6 +2699,8 @@ static void rtw8852c_btc_init_cfg(struct rtw89_dev *rtwdev) .direction = RTW89_MAC_AX_COEX_INNER, }; + rtw89_io_pack(rtwdev); + /* PTA init */ rtw89_mac_coex_init_v1(rtwdev, &coex_params); @@ -2706,8 +2708,6 @@ static void rtw8852c_btc_init_cfg(struct rtw89_dev *rtwdev) chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_TX_RESP, true); chip->ops->btc_set_wl_pri(rtwdev, BTC_PRI_MASK_BEACON, true); - rtw89_io_pack(rtwdev); - /* set rf gnt debug off */ rtw89_write_rf(rtwdev, RF_PATH_A, RR_WLSEL, RFREG_MASK, 0x0); rtw89_write_rf(rtwdev, RF_PATH_B, RR_WLSEL, RFREG_MASK, 0x0); From 0cb6910130a33cc95987503b5b312e5435d1fc77 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Sat, 26 Sep 2026 17:30:34 +0200 Subject: [PATCH 0954/2126] mptcp: remove thmac from subflow ctx This entry is only used in subflow_finish_connect(). Instead, use the original value from mp_opt, and pass it to subflow_thmac_valid() to do the validation with the given truncated hmac. While at it, rename the variables in subflow_thmac_valid() to avoid confusions about the received one vs the expected one. Reviewed-by: Geliang Tang Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260926-net-next-mptcp-misc-feat-7-4-v1-1-67af4ab37406@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/protocol.h | 1 - net/mptcp/subflow.c | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0384d6a023f9..dd9957d334b6 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -593,7 +593,6 @@ struct mptcp_subflow_context { bool fully_established; /* path validated */ u32 lent_mem_frag; u32 remote_nonce; - u64 thmac; u32 local_nonce; u32 remote_token; union { diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index f0a6725d2c37..14aa82647c3d 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -408,20 +408,21 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk, #endif /* validate received truncated hmac and create hmac for third ACK */ -static bool subflow_thmac_valid(struct mptcp_subflow_context *subflow) +static bool subflow_thmac_valid(struct mptcp_subflow_context *subflow, + u64 thmac) { u8 hmac[SHA256_DIGEST_SIZE]; - u64 thmac; + u64 expected_thmac; subflow_generate_hmac(subflow->remote_key, subflow->local_key, subflow->remote_nonce, subflow->local_nonce, hmac); - thmac = get_unaligned_be64(hmac); - pr_debug("subflow=%p, token=%u, thmac=%llu, subflow->thmac=%llu\n", - subflow, subflow->token, thmac, subflow->thmac); + expected_thmac = get_unaligned_be64(hmac); + pr_debug("subflow=%p, token=%u, expected_thmac=%llu, thmac=%llu\n", + subflow, subflow->token, expected_thmac, thmac); - return thmac == subflow->thmac; + return expected_thmac == thmac; } void mptcp_subflow_reset(struct sock *ssk) @@ -575,14 +576,13 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) } subflow->backup = mp_opt.backup; - subflow->thmac = mp_opt.thmac; subflow->remote_nonce = mp_opt.nonce; WRITE_ONCE(subflow->remote_id, mp_opt.join_id); pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u backup=%d\n", - subflow, subflow->thmac, subflow->remote_nonce, + subflow, mp_opt.thmac, subflow->remote_nonce, subflow->backup); - if (!subflow_thmac_valid(subflow)) { + if (!subflow_thmac_valid(subflow, mp_opt.thmac)) { MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKMAC); subflow->reset_reason = MPTCP_RST_EMPTCP; goto do_reset; From 9f778b5678177a6ab3a2f62d2f6f55a2f120d4dc Mon Sep 17 00:00:00 2001 From: Quanye Yang Date: Sat, 26 Sep 2026 17:30:35 +0200 Subject: [PATCH 0955/2126] mptcp: split FASTCLOSE key from rcvr_key MP_CAPABLE and MP_FASTCLOSE both stored their key in rcvr_key. Give FASTCLOSE a dedicated fc_recv_key overlapped with rcvr_key in a union. This helps shrink struct mptcp_options_received. Signed-off-by: Quanye Yang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260926-net-next-mptcp-misc-feat-7-4-v1-2-67af4ab37406@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/options.c | 6 +++--- net/mptcp/protocol.h | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index ce0de02f5a3a..c2f4d7bd080c 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -374,10 +374,10 @@ static void mptcp_parse_option(const struct sk_buff *skb, break; ptr += 2; - mp_opt->rcvr_key = get_unaligned_be64(ptr); + mp_opt->fc_recv_key = get_unaligned_be64(ptr); ptr += 8; mp_opt->suboptions |= OPTION_MPTCP_FASTCLOSE; - pr_debug("MP_FASTCLOSE: recv_key=%llu\n", mp_opt->rcvr_key); + pr_debug("MP_FASTCLOSE: recv_key=%llu\n", mp_opt->fc_recv_key); break; case MPTCPOPT_RST: @@ -1258,7 +1258,7 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) { if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) && - READ_ONCE(msk->local_key) == mp_opt.rcvr_key) { + READ_ONCE(msk->local_key) == mp_opt.fc_recv_key) { WRITE_ONCE(msk->rcv_fastclose, true); mptcp_schedule_work((struct sock *)msk); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index dd9957d334b6..6b9bffc5992b 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -146,7 +146,10 @@ static inline bool before64(__u64 seq1, __u64 seq2) struct mptcp_options_received { u64 sndr_key; - u64 rcvr_key; + union { + u64 rcvr_key; + u64 fc_recv_key; + }; u64 data_ack; u64 data_seq; u32 subflow_seq; From d16d54dac08f47f6d0e8aea13e8709f4733592c0 Mon Sep 17 00:00:00 2001 From: Quanye Yang Date: Sat, 26 Sep 2026 17:30:36 +0200 Subject: [PATCH 0956/2126] mptcp: shrink struct mptcp_options_received struct mptcp_options_received is allocated on the stack while parsing incoming MPTCP options. Several suboptions are mutually exclusive, as enforced by mptcp_parse_option(), so their payloads can overlap. Group fields by suboption and place the mutually exclusive payloads in an anonymous union. Keep DSS and rm_list outside the union: they can be combined with other suboptions. Move join_id into the MP_JOIN group, and overlap token, thmac and hmac inside that group. Further shrinking would require changing the parser so currently coexisting fields (DSS mapping vs ACK, rm_list, status flags) can overlap. That adds complexity for little gain, since the outer union is already dominated by the MP_JOIN / ADD_ADDR members. This reduces the structure size from 136 to 72 bytes on x86_64. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/625 Signed-off-by: Quanye Yang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260926-net-next-mptcp-misc-feat-7-4-v1-3-67af4ab37406@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/protocol.h | 45 +++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 6b9bffc5992b..29b03275a59e 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -145,16 +145,13 @@ static inline bool before64(__u64 seq1, __u64 seq2) #define after64(seq2, seq1) before64(seq1, seq2) struct mptcp_options_received { - u64 sndr_key; - union { - u64 rcvr_key; - u64 fc_recv_key; + struct { /* DSS, also used by MP_CAPABLE with data */ + u64 data_ack; + u64 data_seq; + u32 subflow_seq; + u16 data_len; + __sum16 csum; }; - u64 data_ack; - u64 data_seq; - u32 subflow_seq; - u16 data_len; - __sum16 csum; struct_group(status, u16 suboptions; u16 use_map:1, @@ -170,15 +167,29 @@ struct mptcp_options_received { deny_join_id0:1, __unused:2; ); - u8 join_id; - u32 token; - u32 nonce; - u64 thmac; - u8 hmac[MPTCPOPT_HMAC_LEN]; - struct mptcp_addr_info addr; struct mptcp_rm_list rm_list; - u64 ahmac; - u64 fail_seq; + /* Options below are mutually exclusive, see mptcp_parse_option() */ + union { + struct { /* MP_CAPABLE */ + u64 sndr_key; + u64 rcvr_key; + }; + struct { /* MP_JOIN */ + u32 nonce; + u8 join_id; + union { + u32 token; /* SYN */ + u64 thmac; /* SYN + ACK */ + u8 hmac[MPTCPOPT_HMAC_LEN]; /* ACK */ + }; + }; + struct { /* ADD_ADDR */ + struct mptcp_addr_info addr; + u64 ahmac; + }; + u64 fail_seq; /* MP_FAIL */ + u64 fc_recv_key; /* MP_FASTCLOSE */ + }; }; static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) From 533c404af22c5e9d43007b3158a086cf52349c07 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 23 Sep 2026 15:27:39 +0800 Subject: [PATCH 0957/2126] wifi: rtw89: ser: reset map of associated links when L2 SER There is a map used to record the associated links by MAC ID, but L2 SER (system error recovery) will invoke ieee80211_restart_hw to reset things. After ieee80211_restart_hw, the associated links will re-configure, but each associated link might not use the same MAC ID as the original one. If an associated link doesn't and the old MAC ID is not re-used, the map keeps the old pair of old MAC ID and it. And then, if somehow HW fills a wrong MAC ID, e.g. the old MAC ID above, in RX, SW will still obtain the associated link. Once the one is really disconnected, the memory will be freed and this case will cause problems. So, reset entire map of associated links before ieee80211_restart_hw call. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923072741.54118-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/ser.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/ser.c b/drivers/net/wireless/realtek/rtw89/ser.c index 701440bd7be1..045dac0bd1db 100644 --- a/drivers/net/wireless/realtek/rtw89/ser.c +++ b/drivers/net/wireless/realtek/rtw89/ser.c @@ -354,6 +354,14 @@ static void ser_deinit_cam(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) bitmap_zero(rtwdev->cam_info.ba_cam_map, RTW89_MAX_BA_CAM_NUM); } +static void ser_reset_assoc_links(struct rtw89_dev *rtwdev) +{ + for (int i = 0; i < RTW89_MAX_MAC_ID_NUM; i++) + rcu_assign_pointer(rtwdev->assoc_link_on_macid[i], NULL); + + synchronize_rcu(); +} + static void ser_reset_mac_binding(struct rtw89_dev *rtwdev) { struct rtw89_vif *rtwvif; @@ -362,6 +370,7 @@ static void ser_reset_mac_binding(struct rtw89_dev *rtwdev) rtw89_for_each_rtwvif(rtwdev, rtwvif) ser_deinit_cam(rtwdev, rtwvif); + ser_reset_assoc_links(rtwdev); rtw89_core_release_all_bits_map(rtwdev->mac_id_map, RTW89_MAX_MAC_ID_NUM); rtw89_for_each_rtwvif(rtwdev, rtwvif) ser_reset_vif(rtwdev, rtwvif); From 39884f761fe68b58f1f2b35d2abef855f006a986 Mon Sep 17 00:00:00 2001 From: Chih-Kang Chang Date: Wed, 23 Sep 2026 15:27:40 +0800 Subject: [PATCH 0958/2126] wifi: rtw89: wow: check AOAC report C2H event length The AOAC report C2H event contains fixed-size fields including GTK and IGTK. The received C2H skb may contain less data than the expected AOAC report size. Check the skb length before processing the AOAC report to ensure the complete report is available. Signed-off-by: Chih-Kang Chang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923072741.54118-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/mac.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c index 093291e8854d..ad849e4b4a50 100644 --- a/drivers/net/wireless/realtek/rtw89/mac.c +++ b/drivers/net/wireless/realtek/rtw89/mac.c @@ -5897,6 +5897,13 @@ rtw89_mac_c2h_wow_aoac_rpt(struct rtw89_dev *rtwdev, struct sk_buff *skb, u32 le (const struct rtw89_c2h_wow_aoac_report *)skb->data; struct rtw89_completion_data data = {}; + if (skb->len < sizeof(*c2h)) { + rtw89_warn(rtwdev, "wow: aoac rpt skb len %u is too short\n", + skb->len); + data.err = true; + goto out; + } + aoac_rpt->rpt_ver = c2h->rpt_ver; aoac_rpt->sec_type = c2h->sec_type; aoac_rpt->key_idx = c2h->key_idx; @@ -5913,6 +5920,7 @@ rtw89_mac_c2h_wow_aoac_rpt(struct rtw89_dev *rtwdev, struct sk_buff *skb, u32 le aoac_rpt->igtk_ipn = le64_to_cpu(c2h->igtk_ipn); memcpy(aoac_rpt->igtk, c2h->igtk, sizeof(aoac_rpt->igtk)); +out: rtw89_complete_cond(wait, RTW89_WOW_WAIT_COND_AOAC, &data); } From cab0aec92072f99cb6a529b6fb1ef71542620f3b Mon Sep 17 00:00:00 2001 From: Chih-Kang Chang Date: Wed, 23 Sep 2026 15:27:41 +0800 Subject: [PATCH 0959/2126] wifi: rtw89: wow: check AOAC report key index Check the key index reported by firmware before updating the GTK RX IV information in the AOAC report. The key index is obtained from the firmware C2H register and is used to select the GTK RX IV entry. Make sure the reported index is within the available GTK RX IV entries before processing the report. Signed-off-by: Chih-Kang Chang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260923072741.54118-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/wow.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/wow.c b/drivers/net/wireless/realtek/rtw89/wow.c index 0bf34692c7ce..7a2d6904951f 100644 --- a/drivers/net/wireless/realtek/rtw89/wow.c +++ b/drivers/net/wireless/realtek/rtw89/wow.c @@ -546,6 +546,9 @@ static int rtw89_wow_get_aoac_rpt_reg(struct rtw89_dev *rtwdev) aoac_rpt->key_idx = u32_get_bits(c2h_info.u.c2hreg[0], RTW89_C2HREG_AOAC_RPT_1_W0_KEY_IDX); key_idx = aoac_rpt->key_idx; + if (key_idx >= ARRAY_SIZE(aoac_rpt->gtk_rx_iv)) + return -EINVAL; + aoac_rpt->gtk_rx_iv[key_idx][0] = u32_get_bits(c2h_info.u.c2hreg[1], RTW89_C2HREG_AOAC_RPT_1_W1_IV_0); aoac_rpt->gtk_rx_iv[key_idx][1] = From 7cde94dab0e74434ccc0a387d7ad373fb3becda0 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Thu, 24 Sep 2026 08:46:37 +0800 Subject: [PATCH 0960/2126] wifi: rtw88: TX report with long timeout for non-PCIE devices Many USB and SDIO devices can't report TX status within 500 ms, and extending to 2500 ms as tested USB/SDIO devices can fix the problem [1]. To avoid adding chip ID one by one, and this change looks harmless. Keep PCIE using short timeout, and others use long timeout. [1] https://lore.kernel.org/linux-wireless/20260921165343.8131-1-pepe.schlehofer@gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Ping-Ke Shih Reviewed-by: Luka Gejak Tested-by: Josef Schlehofer Link: https://patch.msgid.link/20260924004637.9958-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw88/tx.c | 10 +++++----- drivers/net/wireless/realtek/rtw88/tx.h | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c index 4e110a457e71..701ed7c4f3f7 100644 --- a/drivers/net/wireless/realtek/rtw88/tx.c +++ b/drivers/net/wireless/realtek/rtw88/tx.c @@ -196,7 +196,7 @@ void rtw_tx_report_purge_timer(struct timer_list *t) void rtw_tx_report_enqueue(struct rtw_dev *rtwdev, struct sk_buff *skb, u8 sn) { struct rtw_tx_report *tx_report = &rtwdev->tx_report; - unsigned long timeout = RTW_TX_PROBE_TIMEOUT; + unsigned long timeout; unsigned long flags; u8 *drv_data; @@ -208,10 +208,10 @@ void rtw_tx_report_enqueue(struct rtw_dev *rtwdev, struct sk_buff *skb, u8 sn) __skb_queue_tail(&tx_report->queue, skb); spin_unlock_irqrestore(&tx_report->q_lock, flags); - if ((rtwdev->chip->id == RTW_CHIP_TYPE_8723D && - rtwdev->hci.type == RTW_HCI_TYPE_USB) || - rtw_is_8723bs(rtwdev)) - timeout = msecs_to_jiffies(2500); + if (rtwdev->hci.type == RTW_HCI_TYPE_PCIE) + timeout = RTW_TX_PROBE_TIMEOUT_SHORT; + else + timeout = RTW_TX_PROBE_TIMEOUT_LONG; mod_timer(&tx_report->purge_timer, jiffies + timeout); } diff --git a/drivers/net/wireless/realtek/rtw88/tx.h b/drivers/net/wireless/realtek/rtw88/tx.h index d34cdeca16f1..168f48e87853 100644 --- a/drivers/net/wireless/realtek/rtw88/tx.h +++ b/drivers/net/wireless/realtek/rtw88/tx.h @@ -7,7 +7,8 @@ #define RTK_TX_MAX_AGG_NUM_MASK 0x1f -#define RTW_TX_PROBE_TIMEOUT msecs_to_jiffies(500) +#define RTW_TX_PROBE_TIMEOUT_SHORT msecs_to_jiffies(500) +#define RTW_TX_PROBE_TIMEOUT_LONG msecs_to_jiffies(2500) struct rtw_tx_desc { __le32 w0; From 1a924ab28fb51c64f3e66dc4cbc2dbafa0011f68 Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 24 Sep 2026 23:25:29 +0800 Subject: [PATCH 0961/2126] tcp: preserve timestamps across receive queue collapse When tcp_collapse() rebuilds skbs under memory pressure, the copy process doesn't include the right tstamp and hwtstamp from the old skb. And memcpy(nskb->cb, skb->cb, ...) copies has_rxtstamp, but nskb->tstamp and hwtstamps are left at zero, so tcp_recv_timestamp() ends up emitting no cmsg at all. In net timestamping case, if such an skb happens to be the last one consumed in a recvmsg() call, the application receives no RX timestamp for that call. Fix this by copying both tstamp and hwtstamp of the last skb to the new skb, matching tcp_try_coalesce()/tcp_add_backlog(). Note that the has_rxtstamp flag can still be inherited through the cb memcpy from an skb that contributes no bytes (fully covered skb left in the ofo tree by the tcp_ooo_try_coalesce() -> coalesce_done path), so set TCP_SKB_CB(nskb)->has_rxtstamp to false which makes the new block the only place setting it. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260924152529.5689-1-kerneljasonxing@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv4/tcp_input.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 892ff256e235..39f1ac73bd5e 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5834,6 +5834,7 @@ skip_this: break; memcpy(nskb->cb, skb->cb, sizeof(skb->cb)); + TCP_SKB_CB(nskb)->has_rxtstamp = false; skb_copy_decrypted(nskb, skb); TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start; if (list) @@ -5854,6 +5855,12 @@ skip_this: if (skb_copy_bits(skb, offset, skb_put(nskb, size), size)) BUG(); TCP_SKB_CB(nskb)->end_seq += size; + if (TCP_SKB_CB(skb)->has_rxtstamp) { + TCP_SKB_CB(nskb)->has_rxtstamp = true; + nskb->tstamp = skb->tstamp; + skb_hwtstamps(nskb)->hwtstamp = + skb_hwtstamps(skb)->hwtstamp; + } copy -= size; start += size; } From 3fca849c965333f387aa02dca02326ce3abd1305 Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Fri, 25 Sep 2026 15:15:43 +0200 Subject: [PATCH 0962/2126] ice: skip stats handling for channel VSIs on rebuild ice_vsi_alloc_stat_arrays() returns early for ICE_VSI_CHNL, so a channel VSI never gets an entry in pf->vsi_stats[]. ice_vsi_realloc_stat_arrays() dereferences that entry unconditionally, and ice_vsi_rebuild() calls it before anything else, so the NULL is not filtered out anywhere. The path is live. ice_prepare_for_reset() removes the queue channels only for resets other than a PFR, so a PFR leaves the channel VSIs in place, and ice_rebuild() then calls ice_rebuild_channels(), which rebuilds every ICE_VSI_CHNL VSI it finds. A PF reset with ADQ (mqprio hardware offload) configured thus dereferences NULL. That combination is reset recovery on top of an active mqprio offload, which is why it went unnoticed. It was found while refactoring this code, not reported by a user. I'm leaning towards removing our limited (compared to OOT ADQ) support, but it's outside of this series. Bug could be triggered by: tc qdisc del dev "$IF" root 2>/dev/null || true tc qdisc add dev "$IF" root mqprio num_tc 2 \ map 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \ queues 2@0 2@2 hw 1 mode channel sleep 3 ethtool --reset "$IF" irq dma filter offload Workqueue: ice ice_service_task [ice] RIP: 0010:ice_vsi_rebuild+0x289/0x380 [ice] ice_rebuild_channels+0xd6/0x320 [ice] ice_rebuild+0x4f6/0x540 [ice] ice_do_reset+0x9f/0x1a0 [ice] ice_service_task+0x4a/0x460 [ice] Fixes: 5995ef88e3a8 ("ice: realloc VSI stats arrays") Signed-off-by: Przemek Kitszel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925132636.123300-2-przemyslaw.kitszel@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice_lib.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 9e08db376d3d..31af378aa0e7 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -3031,6 +3031,10 @@ ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi) u16 prev_rxq = vsi->alloc_rxq; int i; + /* channel VSIs have no entry in pf->vsi_stats[] */ + if (vsi->type == ICE_VSI_CHNL) + return 0; + vsi_stat = pf->vsi_stats[vsi->idx]; if (req_txq < prev_txq) { From db61b199031c614d1a98e844af00e3c426fc9d5f Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Fri, 25 Sep 2026 15:15:44 +0200 Subject: [PATCH 0963/2126] ice: extract __ice_vsi_free_stats() Record the length of each ring stats array in struct ice_vsi_stats, so that freeing the array entries no longer needs the owning VSI. Keep the new fields in sync in both places that size the arrays. With that, the body of ice_vsi_free_stats() becomes independent of the VSI and can be split out as __ice_vsi_free_stats(). The @free_entries parameter is always true here; a later commit adds a caller that frees only the array container, after its entries have been handed over to a freshly allocated stats structure. The free path now stops at the recorded length instead of the VSI queue count, so it follows the real allocation rather than a number that can disagree with it. Sizing still does not: "ice: rebuild ring stats arrays instead of reallocating them in place" starts using the lengths to carry entries over, and only "ice: size ring stats arrays from the final queue count" makes them authoritative for the allocation path. Signed-off-by: Przemek Kitszel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925132636.123300-3-przemyslaw.kitszel@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice.h | 2 + drivers/net/ethernet/intel/ice/ice_lib.c | 52 ++++++++++++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index a56e9b7c4dad..776f4d902f44 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -327,6 +327,8 @@ enum ice_vsi_state { struct ice_vsi_stats { struct ice_ring_stats **tx_ring_stats; /* Tx ring stats array */ struct ice_ring_stats **rx_ring_stats; /* Rx ring stats array */ + u16 tx_ring_stats_len; /* Length of the Tx ring stats array */ + u16 rx_ring_stats_len; /* Length of the Rx ring stats array */ }; /* struct that defines a VSI, associated with a dev */ diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 31af378aa0e7..1414127d32cd 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -330,6 +330,32 @@ static void ice_vsi_free_arrays(struct ice_vsi *vsi) vsi->rxq_map = NULL; } +/* free single stats memory */ +static void __ice_vsi_free_stats(struct ice_vsi_stats *vsi_stat, bool free_entries) +{ + if (!vsi_stat) + return; + + if (free_entries) { + for (int i = 0; i < vsi_stat->tx_ring_stats_len; i++) { + if (vsi_stat->tx_ring_stats[i]) { + kfree_rcu(vsi_stat->tx_ring_stats[i], rcu); + WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL); + } + } + for (int i = 0; i < vsi_stat->rx_ring_stats_len; i++) { + if (vsi_stat->rx_ring_stats[i]) { + kfree_rcu(vsi_stat->rx_ring_stats[i], rcu); + WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL); + } + } + } + + kfree(vsi_stat->tx_ring_stats); + kfree(vsi_stat->rx_ring_stats); + kfree(vsi_stat); +} + /** * ice_vsi_free_stats - Free the ring statistics structures * @vsi: VSI pointer @@ -338,7 +364,6 @@ static void ice_vsi_free_stats(struct ice_vsi *vsi) { struct ice_vsi_stats *vsi_stat; struct ice_pf *pf = vsi->back; - int i; if (vsi->type == ICE_VSI_CHNL) return; @@ -346,26 +371,7 @@ static void ice_vsi_free_stats(struct ice_vsi *vsi) return; vsi_stat = pf->vsi_stats[vsi->idx]; - if (!vsi_stat) - return; - - ice_for_each_alloc_txq(vsi, i) { - if (vsi_stat->tx_ring_stats[i]) { - kfree_rcu(vsi_stat->tx_ring_stats[i], rcu); - WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL); - } - } - - ice_for_each_alloc_rxq(vsi, i) { - if (vsi_stat->rx_ring_stats[i]) { - kfree_rcu(vsi_stat->rx_ring_stats[i], rcu); - WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL); - } - } - - kfree(vsi_stat->tx_ring_stats); - kfree(vsi_stat->rx_ring_stats); - kfree(vsi_stat); + __ice_vsi_free_stats(vsi_stat, true); pf->vsi_stats[vsi->idx] = NULL; } @@ -539,11 +545,13 @@ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi) kzalloc_objs(*vsi_stat->tx_ring_stats, vsi->alloc_txq); if (!vsi_stat->tx_ring_stats) goto err_alloc_tx; + vsi_stat->tx_ring_stats_len = vsi->alloc_txq; vsi_stat->rx_ring_stats = kzalloc_objs(*vsi_stat->rx_ring_stats, vsi->alloc_rxq); if (!vsi_stat->rx_ring_stats) goto err_alloc_rx; + vsi_stat->rx_ring_stats_len = vsi->alloc_rxq; pf->vsi_stats[vsi->idx] = vsi_stat; @@ -3055,6 +3063,7 @@ ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi) vsi_stat->tx_ring_stats = tx_ring_stats; return -ENOMEM; } + vsi_stat->tx_ring_stats_len = req_txq; if (req_rxq < prev_rxq) { for (i = req_rxq; i < prev_rxq; i++) { @@ -3074,6 +3083,7 @@ ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi) vsi_stat->rx_ring_stats = rx_ring_stats; return -ENOMEM; } + vsi_stat->rx_ring_stats_len = req_rxq; return 0; } From ed3cbc4430c2f365281623b8c9fa81e47f4e8d31 Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Fri, 25 Sep 2026 15:15:45 +0200 Subject: [PATCH 0964/2126] ice: extract ice_vsi_new_stat_arrays() Split the allocation of a struct ice_vsi_stats and its two ring stats arrays out of ice_vsi_alloc_stat_arrays(), which is left with just the lookup and the store into pf->vsi_stats[]. The sole caller keeps passing the very same queue counts as before, vsi->alloc_txq and vsi->alloc_rxq. A later commit adds a second caller in the rebuild path, which cannot use vsi->alloc_* because it has to size the arrays before the VSI is reconfigured. Note that the error path no longer clears pf->vsi_stats[vsi->idx]; the early return above guarantees it is already NULL. No functional change intended. Signed-off-by: Przemek Kitszel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925132636.123300-4-przemyslaw.kitszel@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice_lib.c | 47 +++++++++++++----------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 1414127d32cd..ed32ae2667c5 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -519,6 +519,30 @@ static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data) return IRQ_HANDLED; } +static struct ice_vsi_stats *ice_vsi_new_stat_arrays(int txq, int rxq) +{ + struct ice_ring_stats **tx_ring_stats; + struct ice_ring_stats **rx_ring_stats; + struct ice_vsi_stats *vsi_stat; + + vsi_stat = kzalloc_obj(*vsi_stat); + tx_ring_stats = kzalloc_objs(*tx_ring_stats, txq); + rx_ring_stats = kzalloc_objs(*rx_ring_stats, rxq); + if (!vsi_stat || !tx_ring_stats || !rx_ring_stats) { + kfree(vsi_stat); + kfree(tx_ring_stats); + kfree(rx_ring_stats); + return NULL; + } + + vsi_stat->tx_ring_stats = tx_ring_stats; + vsi_stat->rx_ring_stats = rx_ring_stats; + vsi_stat->tx_ring_stats_len = txq; + vsi_stat->rx_ring_stats_len = rxq; + + return vsi_stat; +} + /** * ice_vsi_alloc_stat_arrays - Allocate statistics arrays * @vsi: VSI pointer @@ -537,33 +561,12 @@ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi) /* realloc will happen in rebuild path */ return 0; - vsi_stat = kzalloc_obj(*vsi_stat); + vsi_stat = ice_vsi_new_stat_arrays(vsi->alloc_txq, vsi->alloc_rxq); if (!vsi_stat) return -ENOMEM; - vsi_stat->tx_ring_stats = - kzalloc_objs(*vsi_stat->tx_ring_stats, vsi->alloc_txq); - if (!vsi_stat->tx_ring_stats) - goto err_alloc_tx; - vsi_stat->tx_ring_stats_len = vsi->alloc_txq; - - vsi_stat->rx_ring_stats = - kzalloc_objs(*vsi_stat->rx_ring_stats, vsi->alloc_rxq); - if (!vsi_stat->rx_ring_stats) - goto err_alloc_rx; - vsi_stat->rx_ring_stats_len = vsi->alloc_rxq; - pf->vsi_stats[vsi->idx] = vsi_stat; - return 0; - -err_alloc_rx: - kfree(vsi_stat->rx_ring_stats); -err_alloc_tx: - kfree(vsi_stat->tx_ring_stats); - kfree(vsi_stat); - pf->vsi_stats[vsi->idx] = NULL; - return -ENOMEM; } /** From 4425fa055c0da53c893ff5989b63cd04b9c8353b Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Fri, 25 Sep 2026 15:15:46 +0200 Subject: [PATCH 0965/2126] ice: extract ice_vsi_get_num_qs() ice_vsi_set_num_qs() mixed two things: deciding how many queues a VSI gets, and applying all the side effects of that decision. Split the decision out into ice_vsi_get_num_qs(), returning both counts at once. To make that possible, group alloc_txq and alloc_rxq in struct ice_vsi with struct_group_tagged(), which gives the return type without adding any new storage. Field order changes slightly, num_txq now follows alloc_rxq, but nothing depends on it. ice_vsi_get_num_qs() takes @held_txq and @held_rxq from the start, even though the only caller so far passes zero for both. They let a caller ask what the counts would be once the queues the VSI currently owns are back in the PF pool. A later commit adds the caller that needs this: the rebuild path has to size its ring stats arrays before ice_vsi_decfg() releases the queues, yet the arrays must match what ice_vsi_set_num_qs() computes afterwards. While reshaping the whole body, drop the kernel-doc line promising a return value; ice_vsi_set_num_qs() returns void. No functional change intended. Signed-off-by: Przemek Kitszel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925132636.123300-5-przemyslaw.kitszel@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice.h | 6 +- drivers/net/ethernet/intel/ice/ice_lib.c | 88 ++++++++++++++---------- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index 776f4d902f44..432da05c48c0 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -402,9 +402,11 @@ struct ice_vsi { u8 rx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */ u16 *txq_map; /* index in pf->avail_txqs */ u16 *rxq_map; /* index in pf->avail_rxqs */ - u16 alloc_txq; /* Allocated Tx queues */ + struct_group_tagged(ice_vsi_alloc_queues_params, alloc_txq_rxq, + u16 alloc_txq; /* Allocated Tx queues */ + u16 alloc_rxq; /* Allocated Rx queues */ + ); u16 num_txq; /* Used Tx queues */ - u16 alloc_rxq; /* Allocated Rx queues */ u16 num_rxq; /* Used Rx queues */ u16 req_txq; /* User requested Tx queues */ u16 req_rxq; /* User requested Rx queues */ diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index ed32ae2667c5..134984077d5d 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -153,23 +153,61 @@ static void ice_vsi_set_num_desc(struct ice_vsi *vsi) } } -static u16 ice_get_rxq_count(struct ice_pf *pf) +static u16 ice_get_rxq_count(struct ice_pf *pf, u16 held) { - return min(ice_get_avail_rxq_count(pf), - netif_get_num_default_rss_queues()); + return min_t(u16, ice_get_avail_rxq_count(pf) + held, + netif_get_num_default_rss_queues()); } -static u16 ice_get_txq_count(struct ice_pf *pf) +static u16 ice_get_txq_count(struct ice_pf *pf, u16 held) { - return min(ice_get_avail_txq_count(pf), - netif_get_num_default_rss_queues()); + return min_t(u16, ice_get_avail_txq_count(pf) + held, + netif_get_num_default_rss_queues()); +} + +/* @held_txq, @held_rxq: queues the VSI still owns but is about to return to the + * PF pool, so that the result matches what it will be once they are back there. + */ +static struct ice_vsi_alloc_queues_params +ice_vsi_get_num_qs(struct ice_vsi *vsi, u16 held_txq, u16 held_rxq) +{ + struct ice_vsi_alloc_queues_params qs = {}; + struct ice_pf *pf = vsi->back; + + switch (vsi->type) { + case ICE_VSI_PF: + qs.alloc_txq = vsi->req_txq ?: ice_get_txq_count(pf, held_txq); + + /* only 1 Rx queue unless RSS is enabled */ + if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) + qs.alloc_rxq = 1; + else + qs.alloc_rxq = vsi->req_rxq ?: + ice_get_rxq_count(pf, held_rxq); + break; + case ICE_VSI_SF: + case ICE_VSI_CTRL: + case ICE_VSI_LB: + qs.alloc_txq = 1; + qs.alloc_rxq = 1; + break; + case ICE_VSI_VF: + qs.alloc_txq = vsi->vf->num_req_qs ?: vsi->vf->num_vf_qs; + qs.alloc_rxq = qs.alloc_txq; + break; + case ICE_VSI_CHNL: + break; + default: + dev_warn(ice_pf_to_dev(pf), "Unknown VSI type %d\n", vsi->type); + return vsi->alloc_txq_rxq; + } + + return qs; } /** * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI * @vsi: the VSI being configured - * - * Return 0 on success and a negative value on error */ static void ice_vsi_set_num_qs(struct ice_vsi *vsi) { @@ -180,44 +218,27 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi) if (WARN_ON(vsi_type == ICE_VSI_VF && !vf)) return; + vsi->alloc_txq_rxq = ice_vsi_get_num_qs(vsi, 0, 0); + switch (vsi_type) { case ICE_VSI_PF: - if (vsi->req_txq) { - vsi->alloc_txq = vsi->req_txq; + if (vsi->req_txq) vsi->num_txq = vsi->req_txq; - } else { - vsi->alloc_txq = ice_get_txq_count(pf); - } + if (vsi->req_rxq && test_bit(ICE_FLAG_RSS_ENA, pf->flags)) + vsi->num_rxq = vsi->req_rxq; pf->num_lan_tx = vsi->alloc_txq; - - /* only 1 Rx queue unless RSS is enabled */ - if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) { - vsi->alloc_rxq = 1; - } else { - if (vsi->req_rxq) { - vsi->alloc_rxq = vsi->req_rxq; - vsi->num_rxq = vsi->req_rxq; - } else { - vsi->alloc_rxq = ice_get_rxq_count(pf); - } - } - pf->num_lan_rx = vsi->alloc_rxq; vsi->num_q_vectors = max(vsi->alloc_rxq, vsi->alloc_txq); break; case ICE_VSI_SF: - vsi->alloc_txq = 1; - vsi->alloc_rxq = 1; vsi->num_q_vectors = 1; vsi->irq_dyn_alloc = true; break; case ICE_VSI_VF: if (vf->num_req_qs) vf->num_vf_qs = vf->num_req_qs; - vsi->alloc_txq = vf->num_vf_qs; - vsi->alloc_rxq = vf->num_vf_qs; /* pf->vfs.num_msix_per includes (VF miscellaneous vector + * data queue interrupts). Since vsi->num_q_vectors is number * of queues vectors, subtract 1 (ICE_NONQ_VECS_VF) from the @@ -226,22 +247,15 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi) vsi->num_q_vectors = vf->num_msix - ICE_NONQ_VECS_VF; break; case ICE_VSI_CTRL: - vsi->alloc_txq = 1; - vsi->alloc_rxq = 1; vsi->num_q_vectors = 1; break; case ICE_VSI_CHNL: - vsi->alloc_txq = 0; - vsi->alloc_rxq = 0; break; case ICE_VSI_LB: - vsi->alloc_txq = 1; - vsi->alloc_rxq = 1; /* A dummy q_vector, no actual IRQ. */ vsi->num_q_vectors = 1; break; default: - dev_warn(ice_pf_to_dev(pf), "Unknown VSI type %d\n", vsi_type); break; } From 66444f06a9fe96ac49f5c168d06aaebbfa109c9e Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Fri, 25 Sep 2026 15:15:47 +0200 Subject: [PATCH 0966/2126] ice: rebuild ring stats arrays instead of reallocating them in place ice_vsi_realloc_stat_arrays() resized the ring stats arrays in place with krealloc_array(), sizing them from vsi->req_txq/req_rxq. That is not what ice_vsi_set_num_qs() computes later in ice_vsi_cfg_def(), so after a rebuild the arrays could end up shorter than vsi->alloc_txq / vsi->alloc_rxq, and ice_vsi_alloc_ring_stats() then walked past their end. The VF case shows the divergence. ice_sriov_set_msix_vec_count() writes vsi->req_txq and then calls ice_vsi_rebuild(), so the old resizer sized from req_txq, while ice_vsi_get_num_qs() reads vf->num_req_qs ?: vf->num_vf_qs and ignores req_txq entirely. Once a guest has raised vf->num_req_qs through VIRTCHNL_OP_REQUEST_QUEUES the two disagree and the arrays come out shorter than the alloc_txq/alloc_rxq the rebuild installs. The reset that such a request triggers is a different path, ice_vf_reconfig_vsi(), which does not use this resizer at all; that one is handled by the next patch. Replace it with ice_vsi_resize_stat_arrays(), which allocates a fresh struct ice_vsi_stats instead, sized with ice_vsi_get_num_qs() and the queues ice_vsi_decfg() is about to return to the PF pool, which is exactly what ice_vsi_set_num_qs() will compute once they are back there, barring a concurrent change of the PF pool; the next patch stops relying on that. Copy the surviving entry pointers over and install the new structure, all before ice_vsi_decfg() runs. The entries that did not fit are freed by ice_vsi_free_unused_stat_arrays(); the old container itself then goes through __ice_vsi_free_stats() with @free_entries set to false, since the entries it still points at now belong to the new structure. Allocating up front also means a failure no longer leaves a half-updated ice_vsi_stats behind, with the Tx array already swapped and its surplus Tx entries already freed, but the Rx allocation failed. Put the allocate-install-free-surplus sequence in ice_vsi_install_stat_arrays(), next to ice_vsi_new_stat_arrays(), so that only the sizing decision is left in the resizer. Signed-off-by: Przemek Kitszel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925132636.123300-6-przemyslaw.kitszel@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice_lib.c | 144 ++++++++++++++--------- 1 file changed, 88 insertions(+), 56 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 134984077d5d..448d3c7780ad 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -557,6 +557,80 @@ static struct ice_vsi_stats *ice_vsi_new_stat_arrays(int txq, int rxq) return vsi_stat; } +static void ice_vsi_free_unused_stat_arrays(struct ice_vsi_stats *vsi_stat, + struct ice_vsi_stats *new_vsi_stat) +{ + int new_txq = new_vsi_stat->tx_ring_stats_len; + int new_rxq = new_vsi_stat->rx_ring_stats_len; + int prev_txq = vsi_stat->tx_ring_stats_len; + int prev_rxq = vsi_stat->rx_ring_stats_len; + + for (int i = new_txq; i < prev_txq; i++) { + if (vsi_stat->tx_ring_stats[i]) { + kfree_rcu(vsi_stat->tx_ring_stats[i], rcu); + WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL); + } + } + for (int i = new_rxq; i < prev_rxq; i++) { + if (vsi_stat->rx_ring_stats[i]) { + kfree_rcu(vsi_stat->rx_ring_stats[i], rcu); + WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL); + } + } +} + +static void ice_vsi_set_stat_arrays(struct ice_vsi *vsi, + struct ice_vsi_stats *new_vsi_stat) +{ + u16 new_txq, new_rxq, prev_txq, prev_rxq; + struct ice_vsi_stats *vsi_stat; + struct ice_pf *pf = vsi->back; + + new_txq = new_vsi_stat->tx_ring_stats_len; + new_rxq = new_vsi_stat->rx_ring_stats_len; + vsi_stat = pf->vsi_stats[vsi->idx]; + pf->vsi_stats[vsi->idx] = new_vsi_stat; + if (!vsi_stat) + return; /* don't copy if there is no source */ + + prev_txq = vsi_stat->tx_ring_stats_len; + prev_rxq = vsi_stat->rx_ring_stats_len; + + memcpy(new_vsi_stat->tx_ring_stats, vsi_stat->tx_ring_stats, + sizeof(*vsi_stat->tx_ring_stats) * min(prev_txq, new_txq)); + memcpy(new_vsi_stat->rx_ring_stats, vsi_stat->rx_ring_stats, + sizeof(*vsi_stat->rx_ring_stats) * min(prev_rxq, new_rxq)); +} + +/** + * ice_vsi_install_stat_arrays - swap in freshly sized ring stats arrays + * @vsi: VSI to install the ring stats arrays of + * @txq: number of Tx ring stats entries to make room for + * @rxq: number of Rx ring stats entries to make room for + * + * Surviving entries are carried over, the rest is freed together with the old + * container. + * + * Return: 0 on success and negative value on failure. + */ +static int ice_vsi_install_stat_arrays(struct ice_vsi *vsi, u16 txq, u16 rxq) +{ + struct ice_vsi_stats *old_stat, *new_stat; + + new_stat = ice_vsi_new_stat_arrays(txq, rxq); + if (!new_stat) + return -ENOMEM; + + old_stat = vsi->back->vsi_stats[vsi->idx]; + ice_vsi_set_stat_arrays(vsi, new_stat); + if (old_stat) { + ice_vsi_free_unused_stat_arrays(old_stat, new_stat); + __ice_vsi_free_stats(old_stat, false); + } + + return 0; +} + /** * ice_vsi_alloc_stat_arrays - Allocate statistics arrays * @vsi: VSI pointer @@ -3040,69 +3114,27 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi, } /** - * ice_vsi_realloc_stat_arrays - Frees unused stat structures or alloc new ones - * @vsi: VSI pointer + * ice_vsi_resize_stat_arrays - resize ring stats arrays for new queue count + * @vsi: VSI to swap the ring stats arrays of + * + * Call while @vsi still owns its queues and before ice_vsi_decfg() returns them + * to the PF pool, so that the new size is what ice_vsi_set_num_qs() will compute + * afterwards. Surviving entries are carried over, the rest is freed. + * + * Return: 0 on success and negative value on failure. */ -static int -ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi) +static int ice_vsi_resize_stat_arrays(struct ice_vsi *vsi) { - u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq; - u16 req_rxq = vsi->req_rxq ? vsi->req_rxq : vsi->alloc_rxq; - struct ice_ring_stats **tx_ring_stats; - struct ice_ring_stats **rx_ring_stats; - struct ice_vsi_stats *vsi_stat; - struct ice_pf *pf = vsi->back; - u16 prev_txq = vsi->alloc_txq; - u16 prev_rxq = vsi->alloc_rxq; - int i; + struct ice_vsi_alloc_queues_params qs; /* channel VSIs have no entry in pf->vsi_stats[] */ if (vsi->type == ICE_VSI_CHNL) return 0; - vsi_stat = pf->vsi_stats[vsi->idx]; + qs = ice_vsi_get_num_qs(vsi, vsi->alloc_txq + vsi->num_xdp_txq, + vsi->alloc_rxq); - if (req_txq < prev_txq) { - for (i = req_txq; i < prev_txq; i++) { - if (vsi_stat->tx_ring_stats[i]) { - kfree_rcu(vsi_stat->tx_ring_stats[i], rcu); - WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL); - } - } - } - - tx_ring_stats = vsi_stat->tx_ring_stats; - vsi_stat->tx_ring_stats = - krealloc_array(vsi_stat->tx_ring_stats, req_txq, - sizeof(*vsi_stat->tx_ring_stats), - GFP_KERNEL | __GFP_ZERO); - if (!vsi_stat->tx_ring_stats) { - vsi_stat->tx_ring_stats = tx_ring_stats; - return -ENOMEM; - } - vsi_stat->tx_ring_stats_len = req_txq; - - if (req_rxq < prev_rxq) { - for (i = req_rxq; i < prev_rxq; i++) { - if (vsi_stat->rx_ring_stats[i]) { - kfree_rcu(vsi_stat->rx_ring_stats[i], rcu); - WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL); - } - } - } - - rx_ring_stats = vsi_stat->rx_ring_stats; - vsi_stat->rx_ring_stats = - krealloc_array(vsi_stat->rx_ring_stats, req_rxq, - sizeof(*vsi_stat->rx_ring_stats), - GFP_KERNEL | __GFP_ZERO); - if (!vsi_stat->rx_ring_stats) { - vsi_stat->rx_ring_stats = rx_ring_stats; - return -ENOMEM; - } - vsi_stat->rx_ring_stats_len = req_rxq; - - return 0; + return ice_vsi_install_stat_arrays(vsi, qs.alloc_txq, qs.alloc_rxq); } /** @@ -3132,7 +3164,7 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags) mutex_lock(&vsi->xdp_state_lock); - ret = ice_vsi_realloc_stat_arrays(vsi); + ret = ice_vsi_resize_stat_arrays(vsi); if (ret) goto unlock; From f1c3b87896e656c1940a1dc3e2f286e000c62da8 Mon Sep 17 00:00:00 2001 From: Przemek Kitszel Date: Fri, 25 Sep 2026 15:15:48 +0200 Subject: [PATCH 0967/2126] ice: size ring stats arrays from the final queue count The ring stats arrays were sized in one place and indexed in another, with nothing reconciling the two. ice_vsi_alloc_stat_arrays() gave up as soon as a container existed: if (pf->vsi_stats[vsi->idx]) /* realloc will happen in rebuild path */ return 0; while ice_vsi_alloc_ring_stats() walks the arrays with ice_for_each_alloc_txq() / ice_for_each_alloc_rxq(), that is, up to vsi->alloc_txq / vsi->alloc_rxq. Whenever the arrays are shorter than the count ice_vsi_set_num_qs() ends up computing, that loop reads and stores past the end of the kmalloc'ed pointer arrays. Deferring to "the rebuild path" does not hold. It cannot get the size right, and some paths never call it at all. ice_devlink_reinit_down() is one of the latter. It calls ice_vsi_decfg() directly, which does not free pf->vsi_stats[], and nothing on the way down releases the main VSI's entry either: ice_dealloc_vsis() runs only from ice_init()/ice_deinit(), and the single entry that ice_unload() does drop is the control VSI's, via ice_deinit_fdir(). The main VSI's arrays therefore survive the reload, while ice_devlink_reinit_up() runs ice_vsi_cfg() and recomputes the count from netif_get_num_default_rss_queues(), which follows cpu_online_mask. Sizing the arrays with most CPUs offline and then onlining them is enough, no VF involved: for c in /sys/devices/system/cpu/cpu[0-9]*/online; do echo 0 > $c; done echo 0000:18:00.0 > /sys/bus/pci/drivers/ice/unbind echo 0000:18:00.0 > /sys/bus/pci/drivers/ice/bind for c in /sys/devices/system/cpu/cpu[0-9]*/online; do echo 1 > $c; done devlink dev reload pci/0000:18:00.0 action driver_reinit The unbind/bind is what makes the arrays actually be allocated at the small size; a reload alone only reuses them. The read then runs off the end of tx_ring_stats[] and picks up whatever follows it in kmalloc-32. Here that was a string, 0x74756f5f6c697475 spelling "util_out" in memory order. It is stored into ring->ring_stats and faults on the first dereference, in ice_setup_tx_ring(), call trace: RIP: 0010:ice_setup_tx_ring+0x8d/0xe0 [ice] ice_vsi_setup_tx_rings+0x2a/0x80 [ice] ice_vsi_open+0x28/0x170 [ice] ice_open_internal+0xc9/0x160 [ice] __dev_open+0x138/0x2b0 __dev_change_flags+0x1d5/0x250 netif_change_flags+0x21/0x60 do_setlink.constprop.0+0x336/0xcf0 rtnl_newlink+0x4a4/0x9b0 Even where the rebuild path does run, it sizes the arrays before ice_vsi_decfg() returns the queues to the PF pool, and for an ICE_VSI_PF VSI with no explicit request it derives the count from that shared pool. Nothing serializes it against the recount in ice_vsi_set_num_qs(), so a concurrent release, say "echo 0 > sriov_numvfs", leaves the final count larger than the arrays that were already installed. ice_vsi_alloc_stat_arrays() runs from ice_vsi_cfg_def(), right after ice_vsi_alloc_def() called ice_vsi_set_num_qs(), so it is the first place where the queue count is final. Make it the only authority: keep the existing arrays when they are already long enough, and otherwise grow them with ice_vsi_install_stat_arrays(), which carries the surviving entries over. The check only forces a grow: while both arrays are long enough they are kept, an oversized one being merely wasteful. Once either is too short the whole container is replaced, and then the other one follows the final count too, shrinking if that is what it takes. Michal Schmidt hit the same corruption through the VF path, where a guest raises its queue count with VIRTCHNL_OP_REQUEST_QUEUES and the following VF reset reconfigures the VSI with the larger count while the old, shorter arrays are still installed: BUG: KASAN: slab-out-of-bounds in ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice] Workqueue: ice ice_service_task [ice] Call Trace: kasan_report+0xd7/0x120 ice_vsi_alloc_ring_stats+0x385/0x4a0 [ice] ice_vsi_cfg_def+0x12e2/0x2060 [ice] ice_vsi_cfg+0xb5/0x3c0 [ice] ice_reset_vf+0x858/0xf80 [ice] ice_vc_request_qs_msg+0x1da/0x290 [ice] ice_vc_process_vf_msg+0xb15/0x1430 [ice] __ice_clean_ctrlq+0x70d/0x9d0 [ice] ice_service_task+0x840/0xf20 [ice] process_one_work+0x690/0xff0 worker_thread+0x4d9/0xd20 kthread+0x322/0x410 ret_from_fork+0x332/0x660 ret_from_fork_asm+0x1a/0x30 Allocated by task 2439: kasan_save_stack+0x1c/0x40 kasan_save_track+0x10/0x30 __kasan_kmalloc+0x96/0xb0 __kmalloc_noprof+0x1d8/0x580 ice_vsi_cfg_def+0x115c/0x2060 [ice] ice_vsi_cfg+0xb5/0x3c0 [ice] ice_vsi_setup+0x180/0x320 [ice] ice_start_vfs+0x1f3/0x590 [ice] ice_ena_vfs+0x66d/0x798 [ice] ice_sriov_configure.cold+0xe4/0x121 [ice] sriov_numvfs_store+0x279/0x480 kernfs_fop_write_iter+0x331/0x4f0 vfs_write+0x4c4/0xe40 ksys_write+0x10c/0x240 do_syscall_64+0xd9/0x650 entry_SYSCALL_64_after_hwframe+0x76/0x7e The buggy address belongs to the object at ffff88810affea40 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 0 bytes to the right of allocated 32-byte region [ffff88810affea40, ffff88810affea60) Fixes: 288ecf491b16 ("ice: Accumulate ring statistics over reset") Reported-by: Michal Schmidt Closes: https://redhat.atlassian.net/browse/RHEL-164321 Signed-off-by: Przemek Kitszel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20260925132636.123300-7-przemyslaw.kitszel@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/ice/ice_lib.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 448d3c7780ad..c393d913d037 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -634,10 +634,15 @@ static int ice_vsi_install_stat_arrays(struct ice_vsi *vsi, u16 txq, u16 rxq) /** * ice_vsi_alloc_stat_arrays - Allocate statistics arrays * @vsi: VSI pointer + * + * Runs after ice_vsi_set_num_qs(), so this is the first point where the queue + * count is final. Grow the arrays if an earlier sizing guessed too low. + * + * Return: 0 on success, negative error code otherwise. */ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi) { - struct ice_vsi_stats *vsi_stat; + struct ice_vsi_stats *old_stat; struct ice_pf *pf = vsi->back; if (vsi->type == ICE_VSI_CHNL) @@ -645,16 +650,13 @@ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi) if (!pf->vsi_stats) return -ENOENT; - if (pf->vsi_stats[vsi->idx]) - /* realloc will happen in rebuild path */ + old_stat = pf->vsi_stats[vsi->idx]; + if (old_stat && old_stat->tx_ring_stats_len >= vsi->alloc_txq && + old_stat->rx_ring_stats_len >= vsi->alloc_rxq) return 0; - vsi_stat = ice_vsi_new_stat_arrays(vsi->alloc_txq, vsi->alloc_rxq); - if (!vsi_stat) - return -ENOMEM; - - pf->vsi_stats[vsi->idx] = vsi_stat; - return 0; + return ice_vsi_install_stat_arrays(vsi, vsi->alloc_txq, + vsi->alloc_rxq); } /** From bf515c9fae875c95e033407d963b19e32c8f2820 Mon Sep 17 00:00:00 2001 From: Yuya Kusakabe Date: Fri, 25 Sep 2026 23:49:53 +0900 Subject: [PATCH 0968/2126] seg6: reallocate the skb head on L2 encapsulation only when needed The L2 encapsulation modes of the seg6 lwtunnel reallocate the skb head on every packet, where the IPv6 encapsulation modes reallocate only when they have to. Ask for the whole encapsulation up front instead, so that the reallocation happens at most once and only when the headroom really is too small: skb->mac_len + sizeof(struct ipv6hdr) + ipv6_optlen(tinfo->srh) + dst_dev_overhead(cache_dst, skb) __seg6_do_srh_encap() then finds the room it needs and its own skb_cow_head() becomes a no-op. Drivers reserve more than that on the forwarding path, so the reallocation usually disappears altogether. A single-segment policy on ixgbe needs 14 (mac_len) + 40 (ipv6hdr) + 24 (SRH) + 16 (LL_RESERVED_SPACE) = 94 against the 206 bytes the driver leaves. Where the headroom is smaller, as on a veth pair, pskb_expand_head() is called once per forwarded packet instead of twice. Asking only for skb->mac_len would still take two whenever the skb is header-cloned, because the cow that unclones it does not also make room for the outer header. The cost is amplified by CONFIG_INIT_ON_ALLOC_DEFAULT_ON, which many distributions enable: every new head is zeroed in full, and that memset alone accounts for 16% of the datapath profile. Throughput at 0.5% packet loss, 64-byte frames forwarded through one 2.30 GHz core (Xeon E5-2650 v3, ixgbe 82599ES), offered by TRex and binary-searched over 10 runs of 10 s: Before: 654.6 kpps After: 965.7 kpps Signed-off-by: Yuya Kusakabe Reviewed-by: Eric Dumazet Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20260925-seg6-l2cow-v3-1-fc83821542a7@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/seg6_iptunnel.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 61c6a27bf202..ecd8146089ee 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -400,6 +400,7 @@ static int seg6_do_srh(struct sk_buff *skb, struct dst_entry *cache_dst) struct dst_entry *dst = skb_dst(skb); struct seg6_iptunnel_encap *tinfo; struct seg6_lwt *slwt; + unsigned int headroom; int proto, err = 0; slwt = seg6_lwt_lwtunnel(dst->lwtstate); @@ -446,8 +447,13 @@ static int seg6_do_srh(struct sk_buff *skb, struct dst_entry *cache_dst) if (!skb_mac_header_was_set(skb)) return -EINVAL; - if (pskb_expand_head(skb, skb->mac_len, 0, GFP_ATOMIC) < 0) - return -ENOMEM; + headroom = skb->mac_len + sizeof(struct ipv6hdr) + + ipv6_optlen(tinfo->srh) + + dst_dev_overhead(cache_dst, skb); + + err = skb_cow_head(skb, headroom); + if (unlikely(err)) + return err; skb_mac_header_rebuild(skb); skb_push(skb, skb->mac_len); From b38dd3a0cf1d136b610ff4d59214a8169286eb08 Mon Sep 17 00:00:00 2001 From: Xinsheng Zhu Date: Mon, 28 Sep 2026 00:40:11 -0400 Subject: [PATCH 0969/2126] net: usb: ax88172a: improve MAC address read error handling When retrieving the MAC address, ax88172a_bind() checks the return value of asix_read_cmd() against ETH_ALEN to detect short reads. Commit c28d9a285668 ("ax88172a: fix ax88172a_unbind() failures") added an -EIO assignment to ensure that this failure path returns a negative error code, even when asix_read_cmd() returns a non-negative short-read length. Short-read handling was subsequently added to asix_read_cmd() by commit 920a9fa27e78 ("net: asix: add proper error handling of usb read errors"). The helper now converts short reads to -ENODATA while preserving negative errors from the underlying USB read operation. The MAC address short-read check in ax88172a_bind() is therefore redundant now, and overwriting the return value with -EIO is no longer necessary to ensure that the failure path returns a negative error code. Check only for negative return values and remove the -EIO assignment to preserve the error returned by asix_read_cmd() through the existing cleanup path. Signed-off-by: Xinsheng Zhu Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20260928044011.63926-1-xinsheng.zhu.ny@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/ax88172a.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/usb/ax88172a.c b/drivers/net/usb/ax88172a.c index 6b14bce2a552..f5036451f086 100644 --- a/drivers/net/usb/ax88172a.c +++ b/drivers/net/usb/ax88172a.c @@ -173,9 +173,8 @@ static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf) /* Get the MAC address */ ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf, 0); - if (ret < ETH_ALEN) { + if (ret < 0) { netdev_err(dev->net, "Failed to read MAC address: %d\n", ret); - ret = -EIO; goto free; } eth_hw_addr_set(dev->net, buf); From 9433d2f334ed1b089cfc83cfcdeb28e6a3f3f412 Mon Sep 17 00:00:00 2001 From: Zack Gomez Date: Fri, 25 Sep 2026 16:45:37 -0400 Subject: [PATCH 0970/2126] netpoll: bound the deferred transmit queue __netpoll_send_skb() parks an skb on npinfo->txq whenever the device cannot take it at once, and once the queue is non-empty every later skb goes straight there to keep ordering. queue_process() drains it from a workqueue and, unlike the direct path, never polls the device for completions: when the ring is stopped it backs off HZ/10. Nothing limits the queue length. A producer that outruns that drain therefore grows the queue until the host is out of memory. Observed with netconsole forwarding a GPU driver that logged one line at ~1e5/s after a firmware hang. The NIC was moving ~17k packets/s: completions for each burst surfaced tens of ms later, outside the one-tick window, so queue_process() slept HZ/10 per ring while ~1e5 lines/s kept arriving. The queue grew at ~170 MB/s, unreclaimable slab reached 51 GiB in five minutes and the OOM killer ran from kswapd with 341 MiB of anonymous memory on the whole box. What the queue held was the flood itself; the OOM report never left the host. Reproduced on the same host (netconsole over a 10G ConnectX-4 Lx) under the same slow-completion condition: 200k lines to /dev/kmsg in 0.12 s grew unreclaimable slab by 173 MiB, about 188k skbs, draining at ~8-10k packets/s. With prompt completions the same burst drains at line rate; a stall on the link while lines keep arriving faster than the drain reproduces the growth. Until the 2006 netpoll rework [1] the deferred path drained through dev_queue_xmit(), with the stack's own backpressure, and was capped at 16 skbs (MAX_QUEUE_DEPTH). That series moved it to a direct hard_start_xmit() with the HZ/10 back-off and made the queue per-device, dropping the cap on the way. Cap it at 1024 skbs per device and drop new skbs beyond that. The drop is counted in tx_dropped of the device whose queue is full and freed with SKB_DROP_REASON_FULL_RING. A netconsole target bound directly to that device also gets NET_XMIT_DROP and, with CONFIG_NETCONSOLE_DYNAMIC, counts it in xmit_drop_count. When a stacked device (bond, bridge, team, vlan, macvlan) passes the skb down and the lower device's queue is the one that fills, the return value does not reach netconsole and the lower device's tx_dropped is the record. The bound holds either way. Nothing is logged on the drop path because that would recurse into the console being drained. [1] https://lore.kernel.org/netdev/20061026225645.482978803@osdl.org/ Signed-off-by: Zack Gomez Reviewed-by: Breno Leitao Link: https://patch.msgid.link/20260925204537.2664119-1-zack.gomez@gmail.com Signed-off-by: Jakub Kicinski --- net/core/netpoll.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index fe1e0cda5d6b..aafbb19a2887 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -38,6 +38,15 @@ #define USEC_PER_POLL 50 +/* + * Cap on skbs parked in npinfo->txq while the device is busy. The queue + * exists to ride out a transient stall; a producer that outruns the + * device for longer than that must lose packets, not grow it without + * bound. Checked without the queue lock, so the queue can overshoot + * slightly. + */ +#define NETPOLL_TXQ_MAX 1024 + /* * carrier_timeout is netconsole-specific and only kept here to preserve the * netpoll.carrier_timeout module-parameter ABI. Its value is exposed to @@ -314,6 +323,12 @@ static netdev_tx_t __netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) } if (!dev_xmit_complete(status)) { + if (skb_queue_len_lockless(&npinfo->txq) >= NETPOLL_TXQ_MAX) { + dev_core_stats_tx_dropped_inc(dev); + dev_kfree_skb_irq_reason(skb, + SKB_DROP_REASON_FULL_RING); + goto out; + } skb_queue_tail(&npinfo->txq, skb); schedule_delayed_work(&npinfo->tx_work,0); } From 6cccd4b720e21adc07c94f68685b9b6efce587aa Mon Sep 17 00:00:00 2001 From: Chengfeng Ye Date: Sun, 27 Sep 2026 15:45:47 +0800 Subject: [PATCH 0971/2126] net/smc: Serialize link activation with teardown smc_llc_link_active() marks a link active before scheduling its testlink work. The first-link confirmation paths call it without llc_conf_mutex, allowing link-down processing to clear the link between these operations: Connection setup Link-down worker smc_llc_link_active() link->state = SMC_LNK_ACTIVE smcr_link_clear() link->clearing = 1 smc_llc_link_clear() cancel_delayed_work_sync() schedule_delayed_work() The connection reference keeps the link alive during activation, but the newly queued work outlives that reference. Later cleanup skips clearing an already-clearing link, leaving its timer armed when the link group is freed. KASAN reported: BUG: KASAN: use-after-free in __run_timers+0x723/0x8d0 Write of size 8 at addr ffff88810f108810 by task swapper/1/0 Call Trace: __run_timers+0x723/0x8d0 timer_expire_remote+0xd3/0x120 tmigr_handle_remote_up+0x4f4/0xab0 __walk_groups_from+0x40/0x150 tmigr_handle_remote+0x229/0x2c0 run_timer_softirq+0x1f5/0x250 Hold llc_conf_mutex around first-link activation on both sides so that link-down processing cannot cancel the work before it is queued. Also protect the client's initial optional add-link processing, which can activate a second link without the lock. The other add-link paths already hold llc_conf_mutex. This serializes every activation with link teardown without changing the handshake sequence or error handling. Signed-off-by: Chengfeng Ye Link: https://patch.msgid.link/20260927074547.3694742-1-nicoyip.dev@gmail.com Signed-off-by: Jakub Kicinski --- net/smc/af_smc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index e9f93b3ab435..221643624ace 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -665,8 +665,10 @@ static int smcr_clnt_conf_first_link(struct smc_sock *smc) if (rc < 0) return SMC_CLC_DECL_TIMEOUT_CL; + down_write(&link->lgr->llc_conf_mutex); smc_llc_link_active(link); smcr_lgr_set_type(link->lgr, SMC_LGR_SINGLE); + up_write(&link->lgr->llc_conf_mutex); if (link->lgr->max_links > 1) { /* optional 2nd link, receive ADD LINK request from server */ @@ -682,7 +684,9 @@ static int smcr_clnt_conf_first_link(struct smc_sock *smc) return rc; } smc_llc_flow_qentry_clr(&link->lgr->llc_flow_lcl); + down_write(&link->lgr->llc_conf_mutex); smc_llc_cli_add_link(link, qentry); + up_write(&link->lgr->llc_conf_mutex); } return 0; } @@ -1909,8 +1913,10 @@ static int smcr_serv_conf_first_link(struct smc_sock *smc) /* confirm_rkey is implicit on 1st contact */ smc->conn.rmb_desc->is_conf_rkey = true; + down_write(&link->lgr->llc_conf_mutex); smc_llc_link_active(link); smcr_lgr_set_type(link->lgr, SMC_LGR_SINGLE); + up_write(&link->lgr->llc_conf_mutex); if (link->lgr->max_links > 1) { down_write(&link->lgr->llc_conf_mutex); From 0ac396fbc25cb67bd75f887da5c0a01acebd94c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Fri, 25 Sep 2026 15:15:08 +0200 Subject: [PATCH 0972/2126] net: macb: init workqueues before register_netdev() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit register_netdev() exposes the interface to userspace which might trigger operations like close on it. Those access the HRESP/LPI tasks and might therefore use them uninitialised. Fix this race by initialising both `struct work_struct` before register_netdev(). Theoretical bugfix. The main reason for fix is to avoid future Sashiko reports which triggers if we grow the race condition (by touching those workqueues at open for example). The likeliness of this bug sounds tiny, but I've not spent any time trying to reproduce it. Cc: stable+noautosel@kernel.org # fix for an unproven driver init path race Fixes: c5092ba3155e ("net: macb: Convert tasklet API to new bottom half workqueue mechanism") Reported-by: sashiko Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260918-macb-close-v1-0-05e32ce98813%40bootlin.com Link: https://lore.kernel.org/netdev/179010942347.2160803.5970158668197373074@kernel.org/ Signed-off-by: Théo Lebrun Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260925-macb-netdev-register-race-v1-1-752f90ce1c39@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 20fe30789834..1520a9b4edaf 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -6068,15 +6068,15 @@ static int macb_probe(struct platform_device *pdev) if (err) goto err_out_unregister_mdio; + INIT_WORK(&bp->hresp_err_bh_work, macb_hresp_error_task); + INIT_DELAYED_WORK(&bp->tx_lpi_work, macb_tx_lpi_work_fn); + err = register_netdev(netdev); if (err) { dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); goto err_out_free_tieoff; } - INIT_WORK(&bp->hresp_err_bh_work, macb_hresp_error_task); - INIT_DELAYED_WORK(&bp->tx_lpi_work, macb_tx_lpi_work_fn); - netdev_info(netdev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n", macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID), netdev->base_addr, netdev->irq, netdev->dev_addr); From 6b76e4efe73f00ee053d77962f853e4c6e60cc2c Mon Sep 17 00:00:00 2001 From: Linkui Xiao Date: Mon, 28 Sep 2026 20:34:22 +0800 Subject: [PATCH 0973/2126] net: stmmac: do not keep the new TSO MSS cached on mapping failures stmmac_tso_xmit() fills the MSS context descriptor and stores the new MSS in tx_q->mss right away, but the descriptor only gets its OWN bit much later, right before the frame is handed to the DMA. Every error path in between - the dma_map_single() of the linear part and the skb_frag_dma_map() of each fragment - returns with tx_q->mss already updated while the MAC is still programmed with the previous MSS. The context descriptor is now handled like the data descriptors are: tx_q->cur_tx is not advanced while it is being filled, so the slot stays where the next transmit fills it, and the error paths release it explicitly instead of leaving a descriptor the DMA will stop on in the middle of the ring. With the queue no longer wedged by that descriptor, the stale cached MSS is what remains: the next skb carrying the same gso_size compares equal to the cached value, no context descriptor is emitted, and the hardware segments the TCP stream with the MSS of an earlier frame, generating frames whose payload size does not match what the stack accounted for. Drop the cached value on those paths instead. Zero is what stmmac_reset_tx_queue() leaves behind, so the next TSO frame programs the context descriptor again. The store itself stays ahead of the mappings, as before, rather than moving next to the OWN bit: stmmac_tx_err() reinitialises the channel and clears tx_q->mss from the DMA interrupt handler, which takes no TX queue lock, so it can run in the middle of stmmac_tso_xmit(). Publishing the cache after the descriptor has been handed over would widen the window in which such a reset is overwritten with an MSS that the reinitialised channel was never programmed with. Found by manual code inspection and AI tools. Not triggered or tested on real hardware. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Fixes: f748be531d70 ("stmmac: support new GMAC4") Signed-off-by: Linkui Xiao Link: https://patch.msgid.link/20260928123422.1698785-1-xiaolinkui@126.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 3ad9252bf6ae..d95482b7f6e5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4604,9 +4604,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) stmmac_set_mss(priv, mss_desc, mss); tx_q->mss = mss; - tx_q->cur_tx = STMMAC_NEXT_ENTRY(tx_q->cur_tx, - priv->dma_conf.dma_tx_size); - WARN_ON(tx_q->tx_skbuff[tx_q->cur_tx]); } if (netif_msg_tx_queued(priv)) { @@ -4617,6 +4614,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) } first_entry = tx_q->cur_tx; + if (mss_desc) + first_entry = STMMAC_NEXT_ENTRY(first_entry, + priv->dma_conf.dma_tx_size); entry = first_entry; WARN_ON(tx_q->tx_skbuff[entry]); @@ -4785,6 +4785,16 @@ error_dma_unmap: priv->dma_conf.dma_tx_size); } error: + if (mss_desc) { + /* The context descriptor never reached the DMA, so the MAC is + * still programmed with the previous MSS. Invalidate the cache + * instead of leaving it ahead of the hardware; zero is the + * value stmmac_reset_tx_queue() leaves behind. + */ + stmmac_release_tx_desc(priv, mss_desc, priv->descriptor_mode); + tx_q->mss = 0; + } + dev_err(priv->device, "Tx dma map failed\n"); dev_kfree_skb(skb); priv->xstats.tx_dropped++; From 1fadd469b628e5857ff2e7a42c4c5aa394cd3229 Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:47 +0200 Subject: [PATCH 0974/2126] net: dsa: microchip: fully save the periodic output request When a periodic output is initialized, its period and start time are stored to initialize it back in case of restart. These information aren't enough if the request contains flags or targets a pin that isn't the first output of the switch. At restarts, these two arguments are always set to 0. The 'flag issue' isn't concrete so far because the driver doesn't advertise any .supported_perout_flags so any flag request gets rejected by the upper layer. I don't know if other switches use non-zero indexes but the KSZ8463 has twelve periodic outputs, so this index has to also be saved from now on. Save the full request when a periodic output is successfully started. Use the saved request when the periodic output is restarted. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-1-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 33 ++++++++++++++++------------- drivers/net/dsa/microchip/ksz_ptp.h | 3 +-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 39cc70d65900..47cf397481d5 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -189,6 +189,7 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, { struct ksz_ptp_data *ptp_data = &dev->ptp_data; u64 req_pulse_width_ns; + struct timespec64 tmp; u64 cycle_width_ns; u64 pulse_width_ns; int pin = 0; @@ -222,13 +223,9 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, return 0; } - ptp_data->perout_target_time_first.tv_sec = request->start.sec; - ptp_data->perout_target_time_first.tv_nsec = request->start.nsec; - - ptp_data->perout_period.tv_sec = request->period.sec; - ptp_data->perout_period.tv_nsec = request->period.nsec; - - cycle_width_ns = timespec64_to_ns(&ptp_data->perout_period); + tmp.tv_sec = request->period.sec; + tmp.tv_nsec = request->period.nsec; + cycle_width_ns = timespec64_to_ns(&tmp); if ((cycle_width_ns & TRIG_CYCLE_WIDTH_M) != cycle_width_ns) return -EINVAL; @@ -249,9 +246,10 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, if (ret) return ret; + tmp.tv_sec = request->start.sec; + tmp.tv_nsec = request->start.nsec; ret = ksz_ptp_configure_perout(dev, cycle_width_ns, pulse_width_ns, - &ptp_data->perout_target_time_first, - pin); + &tmp, pin); if (ret) return ret; @@ -263,6 +261,8 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, if (ret) return ret; + memcpy(&ptp_data->perout_request, request, + sizeof(struct ptp_perout_request)); ptp_data->tou_mode = KSZ_PTP_TOU_PEROUT; return 0; @@ -763,6 +763,7 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev) struct ptp_perout_request request; struct timespec64 next; struct timespec64 now; + struct timespec64 tmp; unsigned int count; int ret; @@ -773,10 +774,14 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev) return ret; now_ns = timespec64_to_ns(&now); - first_ns = timespec64_to_ns(&ptp_data->perout_target_time_first); + tmp.tv_sec = ptp_data->perout_request.start.sec; + tmp.tv_nsec = ptp_data->perout_request.start.nsec; + first_ns = timespec64_to_ns(&tmp); /* Calculate next perout event based on start time and period */ - period_ns = timespec64_to_ns(&ptp_data->perout_period); + tmp.tv_sec = ptp_data->perout_request.period.sec; + tmp.tv_nsec = ptp_data->perout_request.period.nsec; + period_ns = timespec64_to_ns(&tmp); if (first_ns < now_ns) { count = div_u64(now_ns - first_ns, period_ns); @@ -791,12 +796,10 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev) /* Restart periodic output signal */ next = ns_to_timespec64(next_ns); + memcpy(&request, &ptp_data->perout_request, + sizeof(struct ptp_perout_request)); request.start.sec = next.tv_sec; request.start.nsec = next.tv_nsec; - request.period.sec = ptp_data->perout_period.tv_sec; - request.period.nsec = ptp_data->perout_period.tv_nsec; - request.index = 0; - request.flags = 0; return ksz_ptp_enable_perout(dev, &request, 1); } diff --git a/drivers/net/dsa/microchip/ksz_ptp.h b/drivers/net/dsa/microchip/ksz_ptp.h index 7067ec9bd1e6..eb3827203b96 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.h +++ b/drivers/net/dsa/microchip/ksz_ptp.h @@ -29,8 +29,7 @@ struct ksz_ptp_data { spinlock_t clock_lock; struct timespec64 clock_time; enum ksz_ptp_tou_mode tou_mode; - struct timespec64 perout_target_time_first; /* start of first pulse */ - struct timespec64 perout_period; + struct ptp_perout_request perout_request; }; int ksz_ptp_clock_register(struct dsa_switch *ds); From 1599393bf3fff9394a360a77f3358df93362f7bb Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:48 +0200 Subject: [PATCH 0975/2126] net: dsa: microchip: add the number of pins to chip infos The number of periodic output pins available is hardcoded to 2 while KSZ8463 has 12 pins that can be used as periodic outputs. Add an n_pin attribute to the struct ksz_chip_data to make this setting configurable. Set it to 2 for all the PTP-capable switches. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-2-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_common.c | 10 ++++++++++ drivers/net/dsa/microchip/ksz_common.h | 1 + drivers/net/dsa/microchip/ksz_ptp.c | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index f1b53439ff58..ac9a10a91d79 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1208,6 +1208,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .ptp_capable = true, .wr_table = &ksz8563_register_set, .rd_table = &ksz8563_register_set, + .n_pins = 2, }, [KSZ8795] = { @@ -1443,6 +1444,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .sgmii_port = 7, .wr_table = &ksz9477_register_set, .rd_table = &ksz9477_register_set, + .n_pins = 2, }, [KSZ9896] = { @@ -1608,6 +1610,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, false}, .gbit_capable = {true, true, true}, .ptp_capable = true, + .n_pins = 2, }, [KSZ8567] = { @@ -1645,6 +1648,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .gbit_capable = {false, false, false, false, false, true, true}, .ptp_capable = true, + .n_pins = 2, }, [KSZ9567] = { @@ -1679,6 +1683,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { true, false, false}, .gbit_capable = {true, true, true, true, true, true, true}, .ptp_capable = true, + .n_pins = 2, }, [LAN9370] = { @@ -1710,6 +1715,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_rgmii = {false, false, false, false, true}, .internal_phy = {true, true, true, true, false}, .ptp_capable = true, + .n_pins = 2, }, [LAN9371] = { @@ -1741,6 +1747,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_rgmii = {false, false, false, false, true, true}, .internal_phy = {true, true, true, true, false, false}, .ptp_capable = true, + .n_pins = 2, }, [LAN9372] = { @@ -1776,6 +1783,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, false, false, true, true}, .ptp_capable = true, + .n_pins = 2, }, [LAN9373] = { @@ -1811,6 +1819,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, false, false, false, true, true}, .ptp_capable = true, + .n_pins = 2, }, [LAN9374] = { @@ -1846,6 +1855,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, false, false, true, true}, .ptp_capable = true, + .n_pins = 2, }, [LAN9646] = { diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 091cfbdc486f..9b911f9aafd9 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -139,6 +139,7 @@ struct ksz_chip_data { u8 sgmii_port; const struct regmap_access_table *wr_table; const struct regmap_access_table *rd_table; + const u8 n_pins; }; struct ksz_irq { diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 47cf397481d5..33416e59edc7 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -1053,14 +1053,14 @@ int ksz_ptp_clock_register(struct dsa_switch *ds) ptp_data->caps.do_aux_work = ksz_ptp_do_aux_work; ptp_data->caps.enable = ksz_ptp_enable; ptp_data->caps.verify = ksz_ptp_verify_pin; - ptp_data->caps.n_pins = KSZ_PTP_N_GPIO; + ptp_data->caps.n_pins = dev->info->n_pins; ptp_data->caps.n_per_out = 3; ret = ksz_ptp_start_clock(dev); if (ret) return ret; - for (i = 0; i < KSZ_PTP_N_GPIO; i++) { + for (i = 0; i < dev->info->n_pins; i++) { struct ptp_pin_desc *ptp_pin = &ptp_data->pin_config[i]; snprintf(ptp_pin->name, From 7242c96652e3d2be2c9fe472f73f39c2c27bc221 Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:49 +0200 Subject: [PATCH 0976/2126] net: dsa: microchip: add the number of periodic signals to chip infos The number of periodic signals available is hardcoded to 3 while KSZ8463 can produce 12 different periodic signals. Add an n_per_out attribute to the struct ksz_chip_data to make this setting configurable. Set it to 3 for all the PTP-capable switches. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-3-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_common.c | 10 ++++++++++ drivers/net/dsa/microchip/ksz_common.h | 1 + drivers/net/dsa/microchip/ksz_ptp.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index ac9a10a91d79..ea6db85e7e2b 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1209,6 +1209,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .wr_table = &ksz8563_register_set, .rd_table = &ksz8563_register_set, .n_pins = 2, + .n_per_out = 3, }, [KSZ8795] = { @@ -1445,6 +1446,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .wr_table = &ksz9477_register_set, .rd_table = &ksz9477_register_set, .n_pins = 2, + .n_per_out = 3, }, [KSZ9896] = { @@ -1611,6 +1613,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .gbit_capable = {true, true, true}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [KSZ8567] = { @@ -1649,6 +1652,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { true, true}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [KSZ9567] = { @@ -1684,6 +1688,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .gbit_capable = {true, true, true, true, true, true, true}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [LAN9370] = { @@ -1716,6 +1721,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, false}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [LAN9371] = { @@ -1748,6 +1754,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, false, false}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [LAN9372] = { @@ -1784,6 +1791,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { false, false, true, true}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [LAN9373] = { @@ -1820,6 +1828,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { false, false, true, true}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [LAN9374] = { @@ -1856,6 +1865,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { false, false, true, true}, .ptp_capable = true, .n_pins = 2, + .n_per_out = 3, }, [LAN9646] = { diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 9b911f9aafd9..f1c0e89e13c1 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -140,6 +140,7 @@ struct ksz_chip_data { const struct regmap_access_table *wr_table; const struct regmap_access_table *rd_table; const u8 n_pins; + const u8 n_per_out; }; struct ksz_irq { diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 33416e59edc7..84c799959aaa 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -1054,7 +1054,7 @@ int ksz_ptp_clock_register(struct dsa_switch *ds) ptp_data->caps.enable = ksz_ptp_enable; ptp_data->caps.verify = ksz_ptp_verify_pin; ptp_data->caps.n_pins = dev->info->n_pins; - ptp_data->caps.n_per_out = 3; + ptp_data->caps.n_per_out = dev->info->n_per_out; ret = ksz_ptp_start_clock(dev); if (ret) From 3336fa2007184dc900fcedabca887137bbebc421 Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:50 +0200 Subject: [PATCH 0977/2126] net: dsa: microchip: use dynamic mask to check pulse width validity The pulse width validity is checked against an hardcoded mask. KSZ8463 uses a smaller register than other switches so this check won't work for it. Move the mask as a ksz_ptp_tou_pulse_verify()'s input to allow changing it for KSZ8463 case. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-4-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 84c799959aaa..1889698691e9 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -86,7 +86,7 @@ static int ksz_ptp_tou_reset(struct ksz_device *dev, u8 unit) 0); } -static int ksz_ptp_tou_pulse_verify(u64 pulse_ns) +static int ksz_ptp_tou_pulse_verify(u64 pulse_ns, u32 mask) { u32 data; @@ -94,7 +94,7 @@ static int ksz_ptp_tou_pulse_verify(u64 pulse_ns) return -EINVAL; data = (pulse_ns / 8); - if (!FIELD_FIT(TRIG_PULSE_WIDTH_M, data)) + if ((mask & data) != data) return -ERANGE; return 0; @@ -242,7 +242,7 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, KSZ_MAX_PULSE_WIDTH); } - ret = ksz_ptp_tou_pulse_verify(pulse_width_ns); + ret = ksz_ptp_tou_pulse_verify(pulse_width_ns, TRIG_PULSE_WIDTH_M); if (ret) return ret; From cfd0011cb5c2140cc06bcc04a477198a28ffa49e Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:51 +0200 Subject: [PATCH 0978/2126] net: dsa: microchip: extract PTP callbacks configuration from PTP registration KSZ8463 also has periodic output capabilities but the way its outputs are driven differs from the other switches. It will need its own set of PTP callbacks to implements this behaviour. Extract the PTP callbacks configuration in a dedicated function to be called before the PTP registration to ease the use of others callbacks when needed. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-5-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz8.c | 2 ++ drivers/net/dsa/microchip/ksz9477.c | 1 + drivers/net/dsa/microchip/ksz_ptp.c | 20 ++++++++++++++------ drivers/net/dsa/microchip/ksz_ptp.h | 2 ++ drivers/net/dsa/microchip/lan937x_main.c | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index d7498132064e..37b681d9e20f 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -2589,6 +2589,7 @@ static int ksz8463_setup(struct dsa_switch *ds) if (ret) goto free_girq; + ksz_ptp_set_caps(ds); ret = ksz_ptp_clock_register(ds); if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", @@ -2898,6 +2899,7 @@ static int ksz8_setup(struct dsa_switch *ds) } if (dev->info->ptp_capable) { + ksz_ptp_set_caps(ds); ret = ksz_ptp_clock_register(ds); if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 3ee995545c57..72528a53b67d 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1781,6 +1781,7 @@ static int ksz9477_setup(struct dsa_switch *ds) } if (dev->info->ptp_capable) { + ksz_ptp_set_caps(ds); ret = ksz_ptp_clock_register(ds); if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 1889698691e9..fd27e5851003 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -1031,17 +1031,12 @@ static int ksz_ptp_start_clock(struct ksz_device *dev) return 0; } -int ksz_ptp_clock_register(struct dsa_switch *ds) +void ksz_ptp_set_caps(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; - const u16 *regs = dev->info->regs; struct ksz_ptp_data *ptp_data; - int ret; - u8 i; ptp_data = &dev->ptp_data; - mutex_init(&ptp_data->lock); - spin_lock_init(&ptp_data->clock_lock); ptp_data->caps.owner = THIS_MODULE; snprintf(ptp_data->caps.name, 16, "Microchip Clock"); @@ -1055,6 +1050,19 @@ int ksz_ptp_clock_register(struct dsa_switch *ds) ptp_data->caps.verify = ksz_ptp_verify_pin; ptp_data->caps.n_pins = dev->info->n_pins; ptp_data->caps.n_per_out = dev->info->n_per_out; +} + +int ksz_ptp_clock_register(struct dsa_switch *ds) +{ + struct ksz_device *dev = ds->priv; + const u16 *regs = dev->info->regs; + struct ksz_ptp_data *ptp_data; + int ret; + u8 i; + + ptp_data = &dev->ptp_data; + mutex_init(&ptp_data->lock); + spin_lock_init(&ptp_data->clock_lock); ret = ksz_ptp_start_clock(dev); if (ret) diff --git a/drivers/net/dsa/microchip/ksz_ptp.h b/drivers/net/dsa/microchip/ksz_ptp.h index eb3827203b96..b23040f47b9c 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.h +++ b/drivers/net/dsa/microchip/ksz_ptp.h @@ -32,6 +32,7 @@ struct ksz_ptp_data { struct ptp_perout_request perout_request; }; +void ksz_ptp_set_caps(struct dsa_switch *ds); int ksz_ptp_clock_register(struct dsa_switch *ds); void ksz_ptp_clock_unregister(struct dsa_switch *ds); @@ -64,6 +65,7 @@ struct ksz_ptp_data { struct mutex lock; }; +static inline void ksz_ptp_set_caps(struct dsa_switch *ds) { } static inline int ksz_ptp_clock_register(struct dsa_switch *ds) { return 0; diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index 86ce3a86705f..3a209122fc7d 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -867,6 +867,7 @@ static int lan937x_setup(struct dsa_switch *ds) } } + ksz_ptp_set_caps(ds); ret = ksz_ptp_clock_register(ds); if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", From 5b2bb536a3418fe29cd2e8e21eca3d83c833ca6b Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:52 +0200 Subject: [PATCH 0979/2126] net: dsa: microchip: extract ptp_get_pin The KSZ8463 supports periodic outputs but doesn't handle them in the same way as the other KSZ switches. To add proper support for the KSZ8463, a dedicated ksz8463_ptp_enable_perout() function needs to be created. This function will use the same algorithm to select the output pin as the common ksz_ptp_enable_perout() function. Extract the pin selection algorithm into a dedicated function so it can be used later by the KSZ8463 support. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-6-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index fd27e5851003..79520d345efc 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -183,6 +183,26 @@ static int ksz_ptp_configure_perout(struct ksz_device *dev, return 0; } +static int ksz_ptp_get_pin(struct ksz_device *dev, + struct ptp_perout_request const *request) +{ + struct ksz_ptp_data *ptp_data = &dev->ptp_data; + int pin; + + if (request->flags & ~PTP_PEROUT_DUTY_CYCLE) + return -EOPNOTSUPP; + + if (ptp_data->tou_mode != KSZ_PTP_TOU_PEROUT && + ptp_data->tou_mode != KSZ_PTP_TOU_IDLE) + return -EBUSY; + + pin = ptp_find_pin(ptp_data->clock, PTP_PF_PEROUT, request->index); + if (pin < 0) + return -EINVAL; + + return pin; +} + static int ksz_ptp_enable_perout(struct ksz_device *dev, struct ptp_perout_request const *request, int on) @@ -196,16 +216,9 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, u32 data32; int ret; - if (request->flags & ~PTP_PEROUT_DUTY_CYCLE) - return -EOPNOTSUPP; - - if (ptp_data->tou_mode != KSZ_PTP_TOU_PEROUT && - ptp_data->tou_mode != KSZ_PTP_TOU_IDLE) - return -EBUSY; - - pin = ptp_find_pin(ptp_data->clock, PTP_PF_PEROUT, request->index); + pin = ksz_ptp_get_pin(dev, request); if (pin < 0) - return -EINVAL; + return pin; data32 = FIELD_PREP(PTP_GPIO_INDEX, pin) | FIELD_PREP(PTP_TOU_INDEX, request->index); From 8885b5406a58ad5e1bb1629a0e1e66aa26f3c818 Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:53 +0200 Subject: [PATCH 0980/2126] net: dsa: microchip: extract compute_width The KSZ8463 supports periodic outputs but doesn't handle them in the same way as the other KSZ switches. To add proper support for the KSZ8463, a dedicated ksz8463_ptp_enable_perout() function needs to be created. This function will use the same algorithm to compute the periodic cycles as the common ksz_ptp_enable_perout() function. Extract these algorithms into a dedicated function so they can be used later by the KSZ8463 support. Add some checks on the period to ensure the request is valid and will not cause divide by zero issues if the periodic output is restarted. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-7-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 62 ++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 79520d345efc..4b57cf076bb4 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -203,12 +203,50 @@ static int ksz_ptp_get_pin(struct ksz_device *dev, return pin; } +static int ksz_ptp_compute_perout_cycle(struct ksz_device *dev, + struct ptp_perout_request const *request, + u64 max_pulse_width, + u64 *cycle_width_ns, + u64 *pulse_width_ns) +{ + struct timespec64 tmp; + + if (request->period.sec < 0) + return -EINVAL; + + if (!request->period.sec && !request->period.nsec) + return -EINVAL; + + tmp.tv_sec = request->period.sec; + tmp.tv_nsec = request->period.nsec; + *cycle_width_ns = timespec64_to_ns(&tmp); + if ((*cycle_width_ns & TRIG_CYCLE_WIDTH_M) != *cycle_width_ns) { + *cycle_width_ns = 0; + *pulse_width_ns = 0; + return -EINVAL; + } + + if (request->flags & PTP_PEROUT_DUTY_CYCLE) { + *pulse_width_ns = request->on.sec * NSEC_PER_SEC + + request->on.nsec; + return 0; + } + + /* Use a duty cycle of 50%. Maximum pulse width supported by the + * hardware is a little bit more than 125 ms. + */ + *pulse_width_ns = (request->period.sec * NSEC_PER_SEC + + request->period.nsec) / 2; + *pulse_width_ns = min_t(u64, *pulse_width_ns, max_pulse_width); + + return 0; +} + static int ksz_ptp_enable_perout(struct ksz_device *dev, struct ptp_perout_request const *request, int on) { struct ksz_ptp_data *ptp_data = &dev->ptp_data; - u64 req_pulse_width_ns; struct timespec64 tmp; u64 cycle_width_ns; u64 pulse_width_ns; @@ -236,24 +274,10 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, return 0; } - tmp.tv_sec = request->period.sec; - tmp.tv_nsec = request->period.nsec; - cycle_width_ns = timespec64_to_ns(&tmp); - if ((cycle_width_ns & TRIG_CYCLE_WIDTH_M) != cycle_width_ns) - return -EINVAL; - - if (request->flags & PTP_PEROUT_DUTY_CYCLE) { - pulse_width_ns = request->on.sec * NSEC_PER_SEC + - request->on.nsec; - } else { - /* Use a duty cycle of 50%. Maximum pulse width supported by the - * hardware is a little bit more than 125 ms. - */ - req_pulse_width_ns = (request->period.sec * NSEC_PER_SEC + - request->period.nsec) / 2; - pulse_width_ns = min_t(u64, req_pulse_width_ns, - KSZ_MAX_PULSE_WIDTH); - } + ret = ksz_ptp_compute_perout_cycle(dev, request, KSZ_MAX_PULSE_WIDTH, + &cycle_width_ns, &pulse_width_ns); + if (ret) + return ret; ret = ksz_ptp_tou_pulse_verify(pulse_width_ns, TRIG_PULSE_WIDTH_M); if (ret) From ff327ef4488df10ba76a8f0e1f3711374baf3292 Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:54 +0200 Subject: [PATCH 0981/2126] net: dsa: microchip: extract prepare reset The KSZ8463 supports periodic outputs but doesn't handle them in the same way as the other KSZ switches. To add proper support for the KSZ8463, a dedicated ksz8463_ptp_restart_perout() function needs to be created. This function will use the same request initialization as the common ksz_ptp_restart_perout() function. Extract the inialization into a dedicated function so it can be used later by the KSZ8463 support. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-8-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 4b57cf076bb4..b627062dbaad 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -793,11 +793,11 @@ static int ksz_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) return ret; } -static int ksz_ptp_restart_perout(struct ksz_device *dev) +static int ksz_ptp_prepare_restart_perout(struct ksz_device *dev, + struct ptp_perout_request *request) { struct ksz_ptp_data *ptp_data = &dev->ptp_data; s64 now_ns, first_ns, period_ns, next_ns; - struct ptp_perout_request request; struct timespec64 next; struct timespec64 now; struct timespec64 tmp; @@ -833,10 +833,22 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev) /* Restart periodic output signal */ next = ns_to_timespec64(next_ns); - memcpy(&request, &ptp_data->perout_request, + memcpy(request, &ptp_data->perout_request, sizeof(struct ptp_perout_request)); - request.start.sec = next.tv_sec; - request.start.nsec = next.tv_nsec; + request->start.sec = next.tv_sec; + request->start.nsec = next.tv_nsec; + + return 0; +} + +static int ksz_ptp_restart_perout(struct ksz_device *dev) +{ + struct ptp_perout_request request; + int ret; + + ret = ksz_ptp_prepare_restart_perout(dev, &request); + if (ret) + return ret; return ksz_ptp_enable_perout(dev, &request, 1); } From 7273205d31db8b66a4500b77afe8999bd104d483 Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:55 +0200 Subject: [PATCH 0982/2126] net: dsa: microchip: extract time update The KSZ8463 supports periodic outputs but doesn't handle them in the same way as the other KSZ switches. To add proper support for the KSZ8463, a dedicated ksz8463_ptp_settime() function needs to be created. This function will access the same registers than the common ksz_ptp_settime(). Extract the register accesses into a dedicated function so it can be used later by the KSZ8463 support. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-9-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 42 ++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index b627062dbaad..1244ef44df34 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -853,30 +853,42 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev) return ksz_ptp_enable_perout(dev, &request, 1); } +static int __ksz_ptp_settime(struct ksz_device *dev, + const struct timespec64 *ts) +{ + const u16 *regs = dev->info->regs; + int ret; + + /* Write to shadow registers and Load PTP clock */ + ret = ksz_write16(dev, regs[PTP_RTC_SUB_NANOSEC], PTP_RTC_0NS); + if (ret) + return ret; + + ret = ksz_write32(dev, regs[PTP_RTC_NANOSEC], ts->tv_nsec); + if (ret) + return ret; + + ret = ksz_write32(dev, regs[PTP_RTC_SEC], ts->tv_sec); + if (ret) + return ret; + + ret = ksz_rmw16(dev, regs[PTP_CLK_CTRL], PTP_LOAD_TIME, PTP_LOAD_TIME); + if (ret) + return ret; + + return 0; +} + static int ksz_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts) { struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data); - const u16 *regs = dev->info->regs; int ret; mutex_lock(&ptp_data->lock); - /* Write to shadow registers and Load PTP clock */ - ret = ksz_write16(dev, regs[PTP_RTC_SUB_NANOSEC], PTP_RTC_0NS); - if (ret) - goto unlock; - - ret = ksz_write32(dev, regs[PTP_RTC_NANOSEC], ts->tv_nsec); - if (ret) - goto unlock; - - ret = ksz_write32(dev, regs[PTP_RTC_SEC], ts->tv_sec); - if (ret) - goto unlock; - - ret = ksz_rmw16(dev, regs[PTP_CLK_CTRL], PTP_LOAD_TIME, PTP_LOAD_TIME); + ret = __ksz_ptp_settime(dev, ts); if (ret) goto unlock; From a7cc3395d17e3ea9de18b9bf95392378d5eac98f Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:56 +0200 Subject: [PATCH 0983/2126] net: dsa: microchip: extract time adjustment The KSZ8463 supports periodic outputs but doesn't handle them in the same way as the other KSZ switches. To add proper support for the KSZ8463, a dedicated ksz8463_ptp_adjtime() function needs to be created. This function will access the same registers as the common ksz_ptp_adjtime() function. Extract the register accesses into a dedicated function so it can be used later by the KSZ8463 support. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-10-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz_ptp.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 1244ef44df34..c1c4c781bca7 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -954,18 +954,13 @@ unlock: return ret; } -static int ksz_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) +static int __ksz_ptp_adjtime(struct ksz_device *dev, s64 delta) { - struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); - struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data); - struct timespec64 delta64 = ns_to_timespec64(delta); const u16 *regs = dev->info->regs; s32 sec, nsec; u16 data16; int ret; - mutex_lock(&ptp_data->lock); - /* do not use ns_to_timespec64(), * both sec and nsec are subtracted by hw */ @@ -973,15 +968,15 @@ static int ksz_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) ret = ksz_write32(dev, regs[PTP_RTC_NANOSEC], abs(nsec)); if (ret) - goto unlock; + return ret; ret = ksz_write32(dev, regs[PTP_RTC_SEC], abs(sec)); if (ret) - goto unlock; + return ret; ret = ksz_read16(dev, regs[PTP_CLK_CTRL], &data16); if (ret) - goto unlock; + return ret; data16 |= PTP_STEP_ADJ; @@ -992,6 +987,22 @@ static int ksz_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) data16 |= PTP_STEP_DIR; ret = ksz_write16(dev, regs[PTP_CLK_CTRL], data16); + if (ret) + return ret; + + return 0; +} + +static int ksz_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) +{ + struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); + struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data); + struct timespec64 delta64 = ns_to_timespec64(delta); + int ret; + + mutex_lock(&ptp_data->lock); + + ret = __ksz_ptp_adjtime(dev, delta); if (ret) goto unlock; From 64854d9aab3a66ba2cffb87713ac157a297924bd Mon Sep 17 00:00:00 2001 From: "Bastien Curutchet (Schneider Electric)" Date: Fri, 25 Sep 2026 13:38:57 +0200 Subject: [PATCH 0984/2126] net: dsa: microchip: add periodic output support for the KSZ8463 KSZ8463 has several periodic outputs. The way it handles them differ from the other KSZ switches: - KSZ8463 has one set of registers for each of its 12 units while others switches share on set of configuration registers for all their units. - Maximum size of the KSZ8463 pulse width is smaller - KSZ8463 has 12 outputs while others only have 2 Add support for the KSZ8463 periodics outputs through a set of KSZ8463 specific functions. Signed-off-by: Bastien Curutchet (Schneider Electric) Link: https://patch.msgid.link/20260925-ksz-perout-v4-11-d675bd21ce49@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/microchip/ksz8.c | 2 +- drivers/net/dsa/microchip/ksz_common.c | 2 + drivers/net/dsa/microchip/ksz_ptp.c | 261 ++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_ptp.h | 4 +- drivers/net/dsa/microchip/ksz_ptp_reg.h | 16 ++ 5 files changed, 283 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 37b681d9e20f..3c96dd4581cf 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -2589,7 +2589,7 @@ static int ksz8463_setup(struct dsa_switch *ds) if (ret) goto free_girq; - ksz_ptp_set_caps(ds); + ksz8463_ptp_set_caps(ds); ret = ksz_ptp_clock_register(ds); if (ret) { dev_err(dev->dev, "Failed to register PTP clock: %d\n", diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index ea6db85e7e2b..767c8fe8e819 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1175,6 +1175,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { .supports_mii = {false, false, true}, .supports_rmii = {false, false, true}, .internal_phy = {true, true, false}, + .n_pins = 12, + .n_per_out = 12, }, [KSZ8563] = { diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index c1c4c781bca7..1c59428b159b 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -26,6 +26,7 @@ */ #define KSZ_MAX_DRIFT_CORR 6249999 #define KSZ_MAX_PULSE_WIDTH 125000000LL +#define KSZ8463_MAX_PULSE_WIDTH 500000LL #define KSZ_PTP_INC_NS 40ULL /* HW clock is incremented every 40 ns (by 40) */ #define KSZ_PTP_SUBNS_BITS 32 @@ -63,6 +64,17 @@ static int ksz_ptp_tou_gpio(struct ksz_device *dev) LED_SRC_PTP_GPIO_1 | LED_SRC_PTP_GPIO_2); } +static int ksz8463_ptp_tou_reset(struct ksz_device *dev, u8 unit) +{ + int ret; + + ret = ksz_rmw16(dev, KSZ8463_TOU_SW_RST, BIT(unit), BIT(unit)); + if (ret) + return ret; + + return ksz_rmw16(dev, KSZ8463_TOU_SW_RST, BIT(unit), 0); +} + static int ksz_ptp_tou_reset(struct ksz_device *dev, u8 unit) { u32 data; @@ -120,6 +132,28 @@ static int ksz_ptp_tou_target_time_set(struct ksz_device *dev, return 0; } +static int ksz8463_ptp_tou_start(struct ksz_device *dev, u8 unit) +{ + u16 data; + int ret; + + ret = ksz_rmw16(dev, KSZ8463_TOU_EN, BIT(unit), BIT(unit)); + if (ret) + return ret; + + ret = ksz_read16(dev, KSZ8463_TOU_ACTIVE, &data); + if (ret) + return ret; + + if (!(data & BIT(unit))) { + dev_err(dev->dev, "%s: Trigger unit%d error!\n", __func__, + unit); + return -EIO; + } + + return 0; +} + static int ksz_ptp_tou_start(struct ksz_device *dev, u8 unit) { u32 data; @@ -147,6 +181,56 @@ static int ksz_ptp_tou_start(struct ksz_device *dev, u8 unit) return 0; } +static int ksz8463_ptp_configure_perout(struct ksz_device *dev, + struct ptp_perout_request const *request, + u32 cycle_width_ns, u32 pulse_width_ns, + u8 index) +{ + struct ptp_pin_desc *pin = &dev->ptp_data.pin_config[index]; + u16 cfg_base = KSZ8463_TRIG1_CFG + KSZ8463_TRIGN_CFG_SIZE * pin->chan; + u16 data; + int ret; + + /* Hardware has only 32 bit for the second field */ + if ((request->start.sec & 0xffffffff) != request->start.sec) + return -EINVAL; + + data = KSZ8463_NOTIFY_BIT | + FIELD_PREP(KSZ8463_PATTERN_M, TRIG_POS_PERIOD) | + pin->index; + ret = ksz_write16(dev, cfg_base + KSZ8463_PATTERN_OFF, data); + if (ret) + return ret; + + ret = ksz_write32(dev, cfg_base + KSZ8463_CYCLE_WIDTH_OFF, + cycle_width_ns); + if (ret) + return ret; + + /* Set cycle count 0 - Infinite */ + ret = ksz_write16(dev, cfg_base + KSZ8463_CYCLE_CNT_OFF, 0); + if (ret) + return ret; + + /* KSZ8463 uses a 8 ns unit value to compute the pulse width */ + data = (pulse_width_ns / 8); + ret = ksz_write16(dev, cfg_base + KSZ8463_PULSE_WIDTH_OFF, data); + if (ret) + return ret; + + ret = ksz_write32(dev, cfg_base + KSZ8463_TARGET_NSEC, + request->start.nsec); + if (ret) + return ret; + + ret = ksz_write32(dev, cfg_base + KSZ8463_TARGET_SEC, + request->start.sec); + if (ret) + return ret; + + return 0; +} + static int ksz_ptp_configure_perout(struct ksz_device *dev, u32 cycle_width_ns, u32 pulse_width_ns, struct timespec64 const *target_time, @@ -242,6 +326,61 @@ static int ksz_ptp_compute_perout_cycle(struct ksz_device *dev, return 0; } +static int ksz8463_ptp_enable_perout(struct ksz_device *dev, + struct ptp_perout_request const *request, + int on) +{ + struct ksz_ptp_data *ptp_data = &dev->ptp_data; + u64 cycle_width_ns; + u64 pulse_width_ns; + int pin; + int ret; + + pin = ksz_ptp_get_pin(dev, request); + if (pin < 0) + return pin; + + ret = ksz8463_ptp_tou_reset(dev, request->index); + if (ret) + return ret; + + if (!on) { + ptp_data->tou_mode = KSZ_PTP_TOU_IDLE; + return 0; + } + + ret = ksz_ptp_compute_perout_cycle(dev, request, + KSZ8463_MAX_PULSE_WIDTH, + &cycle_width_ns, &pulse_width_ns); + if (ret) + return ret; + + ret = ksz_ptp_tou_pulse_verify(pulse_width_ns, + KSZ8463_TRIG_PULSE_WIDTH_M); + if (ret) + return ret; + + ret = ksz8463_ptp_configure_perout(dev, request, + cycle_width_ns, pulse_width_ns, + pin); + if (ret) + return ret; + + ret = ksz_ptp_tou_gpio(dev); + if (ret) + return ret; + + ret = ksz8463_ptp_tou_start(dev, request->index); + if (ret) + return ret; + + memcpy(&ptp_data->perout_request, request, + sizeof(struct ptp_perout_request)); + ptp_data->tou_mode = KSZ_PTP_TOU_PEROUT; + + return 0; +} + static int ksz_ptp_enable_perout(struct ksz_device *dev, struct ptp_perout_request const *request, int on) @@ -853,6 +992,18 @@ static int ksz_ptp_restart_perout(struct ksz_device *dev) return ksz_ptp_enable_perout(dev, &request, 1); } +static int ksz8463_ptp_restart_perout(struct ksz_device *dev) +{ + struct ptp_perout_request request; + int ret; + + ret = ksz_ptp_prepare_restart_perout(dev, &request); + if (ret) + return ret; + + return ksz8463_ptp_enable_perout(dev, &request, 1); +} + static int __ksz_ptp_settime(struct ksz_device *dev, const struct timespec64 *ts) { @@ -879,6 +1030,41 @@ static int __ksz_ptp_settime(struct ksz_device *dev, return 0; } +static int ksz8463_ptp_settime(struct ptp_clock_info *ptp, + const struct timespec64 *ts) +{ + struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); + struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data); + int ret; + + mutex_lock(&ptp_data->lock); + + ret = __ksz_ptp_settime(dev, ts); + if (ret) + goto unlock; + + switch (ptp_data->tou_mode) { + case KSZ_PTP_TOU_IDLE: + break; + + case KSZ_PTP_TOU_PEROUT: + ret = ksz8463_ptp_restart_perout(dev); + if (ret) + goto unlock; + + break; + } + + spin_lock_bh(&ptp_data->clock_lock); + ptp_data->clock_time = *ts; + spin_unlock_bh(&ptp_data->clock_lock); + +unlock: + mutex_unlock(&ptp_data->lock); + + return ret; +} + static int ksz_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts) { @@ -993,6 +1179,40 @@ static int __ksz_ptp_adjtime(struct ksz_device *dev, s64 delta) return 0; } +static int ksz8463_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) +{ + struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); + struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data); + struct timespec64 delta64 = ns_to_timespec64(delta); + int ret; + + mutex_lock(&ptp_data->lock); + + ret = __ksz_ptp_adjtime(dev, delta); + if (ret) + goto unlock; + + switch (ptp_data->tou_mode) { + case KSZ_PTP_TOU_IDLE: + break; + + case KSZ_PTP_TOU_PEROUT: + ret = ksz8463_ptp_restart_perout(dev); + if (ret) + goto unlock; + + break; + } + + spin_lock_bh(&ptp_data->clock_lock); + ptp_data->clock_time = timespec64_add(ptp_data->clock_time, delta64); + spin_unlock_bh(&ptp_data->clock_lock); + +unlock: + mutex_unlock(&ptp_data->lock); + return ret; +} + static int ksz_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) { struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); @@ -1027,6 +1247,26 @@ unlock: return ret; } +static int ksz8463_ptp_enable(struct ptp_clock_info *ptp, + struct ptp_clock_request *req, int on) +{ + struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp); + struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data); + int ret; + + switch (req->type) { + case PTP_CLK_REQ_PEROUT: + mutex_lock(&ptp_data->lock); + ret = ksz8463_ptp_enable_perout(dev, &req->perout, on); + mutex_unlock(&ptp_data->lock); + break; + default: + return -EOPNOTSUPP; + } + + return ret; +} + static int ksz_ptp_enable(struct ptp_clock_info *ptp, struct ptp_clock_request *req, int on) { @@ -1103,6 +1343,27 @@ static int ksz_ptp_start_clock(struct ksz_device *dev) return 0; } +void ksz8463_ptp_set_caps(struct dsa_switch *ds) +{ + struct ksz_device *dev = ds->priv; + struct ksz_ptp_data *ptp_data; + + ptp_data = &dev->ptp_data; + + ptp_data->caps.owner = THIS_MODULE; + snprintf(ptp_data->caps.name, 16, "Microchip Clock"); + ptp_data->caps.max_adj = KSZ_MAX_DRIFT_CORR; + ptp_data->caps.gettime64 = ksz_ptp_gettime; + ptp_data->caps.settime64 = ksz8463_ptp_settime; + ptp_data->caps.adjfine = ksz_ptp_adjfine; + ptp_data->caps.adjtime = ksz8463_ptp_adjtime; + ptp_data->caps.do_aux_work = ksz_ptp_do_aux_work; + ptp_data->caps.enable = ksz8463_ptp_enable; + ptp_data->caps.verify = ksz_ptp_verify_pin; + ptp_data->caps.n_pins = dev->info->n_pins; + ptp_data->caps.n_per_out = dev->info->n_per_out; +} + void ksz_ptp_set_caps(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; diff --git a/drivers/net/dsa/microchip/ksz_ptp.h b/drivers/net/dsa/microchip/ksz_ptp.h index b23040f47b9c..22898a22723c 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.h +++ b/drivers/net/dsa/microchip/ksz_ptp.h @@ -12,7 +12,7 @@ #include -#define KSZ_PTP_N_GPIO 2 +#define KSZ_PTP_N_GPIO 12 enum ksz_ptp_tou_mode { KSZ_PTP_TOU_IDLE, @@ -33,6 +33,7 @@ struct ksz_ptp_data { }; void ksz_ptp_set_caps(struct dsa_switch *ds); +void ksz8463_ptp_set_caps(struct dsa_switch *ds); int ksz_ptp_clock_register(struct dsa_switch *ds); void ksz_ptp_clock_unregister(struct dsa_switch *ds); @@ -66,6 +67,7 @@ struct ksz_ptp_data { }; static inline void ksz_ptp_set_caps(struct dsa_switch *ds) { } +static inline void ksz8463_ptp_set_caps(struct dsa_switch *ds) { } static inline int ksz_ptp_clock_register(struct dsa_switch *ds) { return 0; diff --git a/drivers/net/dsa/microchip/ksz_ptp_reg.h b/drivers/net/dsa/microchip/ksz_ptp_reg.h index 65ea8577af75..16f117fa5d49 100644 --- a/drivers/net/dsa/microchip/ksz_ptp_reg.h +++ b/drivers/net/dsa/microchip/ksz_ptp_reg.h @@ -51,6 +51,22 @@ #define REG_PTP_UNIT_INDEX__4 0x0520 +#define KSZ8463_TOU_ACTIVE 0x202 +#define KSZ8463_TOU_EN 0x206 +#define KSZ8463_TOU_SW_RST 0x208 + +#define KSZ8463_TRIGN_CFG_SIZE 0x20 +#define KSZ8463_TRIG1_CFG 0x220 +#define KSZ8463_TARGET_NSEC 0x000 +#define KSZ8463_TARGET_SEC 0x004 +#define KSZ8463_PATTERN_OFF 0x008 +#define KSZ8463_NOTIFY_BIT BIT(8) +#define KSZ8463_PATTERN_M GENMASK(6, 4) +#define KSZ8463_PULSE_WIDTH_OFF 0x00A +#define KSZ8463_TRIG_PULSE_WIDTH_M GENMASK(15, 0) +#define KSZ8463_CYCLE_WIDTH_OFF 0x00C +#define KSZ8463_CYCLE_CNT_OFF 0x010 + #define PTP_GPIO_INDEX GENMASK(19, 16) #define PTP_TSI_INDEX BIT(8) #define PTP_TOU_INDEX GENMASK(1, 0) From c978ff0f1e854bad07b79998b567942ec5c49ccf Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 25 Sep 2026 12:44:08 +0200 Subject: [PATCH 0985/2126] net: Add netdev_config helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit netdev_config manipulation will become slightly more complicated soon and will be used by both ethtool and the queue API. Encapsulate the logic in helper functions. Signed-off-by: Björn Töpel Reviewed-by: Breno Leitao Reviewed-by: Simon Horman Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260925104417.2325213-2-bjorn@kernel.org Signed-off-by: Jakub Kicinski --- net/core/dev.c | 7 ++----- net/core/dev.h | 5 +++++ net/core/netdev_config.c | 37 +++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.c | 15 +++++++-------- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index a8eb382f40ca..79be99b52f20 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -12243,10 +12243,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, if (!dev->ethtool) goto free_all; - dev->cfg = kzalloc_obj(*dev->cfg, GFP_KERNEL_ACCOUNT); - if (!dev->cfg) + if (netdev_alloc_config(dev)) goto free_all; - dev->cfg_pending = dev->cfg; dev->num_napi_configs = maxqs; napi_config_sz = array_size(maxqs, sizeof(*dev->napi_config)); @@ -12318,8 +12316,7 @@ void free_netdev(struct net_device *dev) return; } - WARN_ON(dev->cfg != dev->cfg_pending); - kfree(dev->cfg); + netdev_free_config(dev); kfree(dev->ethtool); netif_free_tx_queues(dev); netif_free_rx_queues(dev); diff --git a/net/core/dev.h b/net/core/dev.h index 51921623fc0a..73db70b023d8 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -104,6 +104,11 @@ extern struct rw_semaphore dev_addr_sem; extern struct list_head net_todo_list; void netdev_run_todo(void); +int netdev_alloc_config(struct net_device *dev); +void __netdev_free_config(struct netdev_config *cfg); +void netdev_free_config(struct net_device *dev); +int netdev_reconfig_start(struct net_device *dev); + int netdev_queue_config_validate(struct net_device *dev, int rxq_idx, struct netdev_queue_config *qcfg, struct netlink_ext_ack *extack); diff --git a/net/core/netdev_config.c b/net/core/netdev_config.c index f14af365d5cd..b101341e3251 100644 --- a/net/core/netdev_config.c +++ b/net/core/netdev_config.c @@ -6,6 +6,43 @@ #include "dev.h" +int netdev_alloc_config(struct net_device *dev) +{ + struct netdev_config *cfg; + + cfg = kzalloc_obj(*dev->cfg, GFP_KERNEL_ACCOUNT); + if (!cfg) + return -ENOMEM; + + dev->cfg = cfg; + dev->cfg_pending = cfg; + return 0; +} + +void __netdev_free_config(struct netdev_config *cfg) +{ + kfree(cfg); +} + +void netdev_free_config(struct net_device *dev) +{ + WARN_ON(dev->cfg != dev->cfg_pending); + __netdev_free_config(dev->cfg); +} + +int netdev_reconfig_start(struct net_device *dev) +{ + struct netdev_config *cfg; + + WARN_ON(dev->cfg != dev->cfg_pending); + cfg = kmemdup(dev->cfg, sizeof(*dev->cfg), GFP_KERNEL_ACCOUNT); + if (!cfg) + return -ENOMEM; + + dev->cfg_pending = cfg; + return 0; +} + static int netdev_nop_validate_qcfg(struct net_device *dev, struct netdev_queue_config *qcfg, struct netlink_ext_ack *extack) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 1af395b54330..383e911f50f7 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -11,6 +11,8 @@ #include "module_fw.h" #include "netlink.h" +#include "../core/dev.h" + static struct genl_family ethtool_genl_family; static bool ethnl_ok __read_mostly; @@ -934,12 +936,9 @@ static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info) if (need_rtnl) rtnl_lock(); netdev_lock_ops(dev); - dev->cfg_pending = kmemdup(dev->cfg, sizeof(*dev->cfg), - GFP_KERNEL_ACCOUNT); - if (!dev->cfg_pending) { - ret = -ENOMEM; - goto out_tie_cfg; - } + ret = netdev_reconfig_start(dev); + if (ret) + goto out_unlock; ret = ethnl_ops_begin(dev); if (ret < 0) @@ -958,9 +957,9 @@ static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info) out_ops: ethnl_ops_complete(dev); out_free_cfg: - kfree(dev->cfg_pending); -out_tie_cfg: + __netdev_free_config(dev->cfg_pending); dev->cfg_pending = dev->cfg; +out_unlock: netdev_unlock_ops(dev); if (need_rtnl) rtnl_unlock(); From 0d5c23f827d38f119e485619f70866caf5632479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Date: Fri, 25 Sep 2026 12:44:09 +0200 Subject: [PATCH 0986/2126] fbnic: Track BDQ device-page geometry per ring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fbnic derives the BDQ buffer layout from PAGE_SIZE. That decides at build time how a posted page is split into 4 KiB device pages, and uses the same completion decoding for HPQ and PPQ. That is wrong once the queues use different posted-page sizes; completions must be decoded with the geometry of the queue that produced them. Keep PAGE_SIZE as the posted-page size for both queues in this change, so the descriptor format and runtime behavior stay unchanged. Signed-off-by: Björn Töpel Reviewed-by: Breno Leitao Reviewed-by: Simon Horman Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260925104417.2325213-3-bjorn@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 34 ++------ .../net/ethernet/meta/fbnic/fbnic_debugfs.c | 5 +- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 83 ++++++++++++------- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 6 ++ 4 files changed, 72 insertions(+), 56 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h index baba3471bf5a..cbb25d11638c 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h @@ -109,34 +109,19 @@ enum { /* Rx Buffer Descriptor Format * - * The layout of this can vary depending on the page size of the system. + * Buffer descriptors describe 4 KiB device pages. A posted page larger than + * 4 KiB is represented by consecutive device-page descriptors. * - * If the page size is 4K then the layout will simply consist of ID for - * the 16 most significant bits, and the lower 46 are essentially the page - * address with the lowest 12 bits being reserved 0 due to the fact that - * a page will be aligned. - * - * If the page size is larger than 4K then the lower n bits of the ID and - * page address will be reserved for the fragment ID. This fragment will - * be 4K in size and will be used to index both the DMA address and the ID - * by the same amount. + * The address field stores the 4 KiB-aligned DMA address. The ID field stores + * the software page ID, with the low n bits used as the device-page ID when a + * posted page spans multiple device pages. The driver increments both the + * address and ID by one device page for each descriptor belonging to a posted + * page. */ #define FBNIC_BD_DESC_ADDR_MASK DESC_GENMASK(45, 12) #define FBNIC_BD_DESC_ID_MASK DESC_GENMASK(63, 48) -#define FBNIC_BD_FRAG_SIZE \ +#define FBNIC_BD_PAGE_SIZE \ (FBNIC_BD_DESC_ADDR_MASK & ~(FBNIC_BD_DESC_ADDR_MASK - 1)) -#define FBNIC_BD_FRAG_COUNT \ - (PAGE_SIZE / FBNIC_BD_FRAG_SIZE) -#define FBNIC_BD_FRAG_ADDR_MASK \ - (FBNIC_BD_DESC_ADDR_MASK & \ - ~(FBNIC_BD_DESC_ADDR_MASK * FBNIC_BD_FRAG_COUNT)) -#define FBNIC_BD_FRAG_ID_MASK \ - (FBNIC_BD_DESC_ID_MASK & \ - ~(FBNIC_BD_DESC_ID_MASK * FBNIC_BD_FRAG_COUNT)) -#define FBNIC_BD_PAGE_ADDR_MASK \ - (FBNIC_BD_DESC_ADDR_MASK & ~FBNIC_BD_FRAG_ADDR_MASK) -#define FBNIC_BD_PAGE_ID_MASK \ - (FBNIC_BD_DESC_ID_MASK & ~FBNIC_BD_FRAG_ID_MASK) /* Rx Completion Queue Descriptors */ #define FBNIC_RCD_TYPE_MASK DESC_GENMASK(62, 61) @@ -151,9 +136,6 @@ enum { /* Address/Length Completion Descriptors */ #define FBNIC_RCD_AL_BUFF_ID_MASK DESC_GENMASK(15, 0) -#define FBNIC_RCD_AL_BUFF_FRAG_MASK (FBNIC_BD_FRAG_COUNT - 1) -#define FBNIC_RCD_AL_BUFF_PAGE_MASK \ - (FBNIC_RCD_AL_BUFF_ID_MASK & ~FBNIC_RCD_AL_BUFF_FRAG_MASK) #define FBNIC_RCD_AL_BUFF_LEN_MASK DESC_GENMASK(28, 16) #define FBNIC_RCD_AL_BUFF_OFF_MASK DESC_GENMASK(43, 32) #define FBNIC_RCD_AL_PAGE_FIN DESC_BIT(60) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c b/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c index 6edfa0aa69f1..f9e879be254d 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c @@ -181,8 +181,8 @@ static int fbnic_dbg_tcq_desc_seq_show(struct seq_file *s, void *v) static int fbnic_dbg_bdq_desc_seq_show(struct seq_file *s, void *v) { struct fbnic_ring *ring = s->private; + unsigned int i, desc_count; char hdr[80]; - int i; /* Generate header on first entry */ fbnic_dbg_ring_show(s); @@ -197,7 +197,8 @@ static int fbnic_dbg_bdq_desc_seq_show(struct seq_file *s, void *v) return 0; } - for (i = 0; i < (ring->size_mask + 1) * FBNIC_BD_FRAG_COUNT; i++) { + desc_count = (ring->size_mask + 1) * fbnic_bd_page_count(ring); + for (i = 0; i < desc_count; i++) { u64 bd = le64_to_cpu(ring->desc[i]); seq_printf(s, "%04x %#04llx %#014llx\n", i, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index b41ff7c88a0a..6b24733dc606 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -896,19 +896,31 @@ static void fbnic_clean_bdq(struct fbnic_ring *ring, unsigned int hw_head, ring->head = head; } +static u16 fbnic_rcd_bd_idx(const struct fbnic_ring *bdq, u64 rcd) +{ + return FIELD_GET(FBNIC_RCD_AL_BUFF_ID_MASK, rcd) >> bdq->bd_page_shift; +} + +static unsigned int fbnic_rcd_bd_page_offset(const struct fbnic_ring *bdq, + u64 rcd) +{ + u16 id = FIELD_GET(FBNIC_RCD_AL_BUFF_ID_MASK, rcd); + u16 page_id = id & (fbnic_bd_page_count(bdq) - 1); + + return page_id * FBNIC_BD_PAGE_SIZE; +} + static void fbnic_bd_prep(struct fbnic_ring *bdq, u16 id, netmem_ref netmem) { - __le64 *bdq_desc = &bdq->desc[id * FBNIC_BD_FRAG_COUNT]; + __le64 *bdq_desc = &bdq->desc[id * fbnic_bd_page_count(bdq)]; dma_addr_t dma = page_pool_get_dma_addr_netmem(netmem); - u64 bd, i = FBNIC_BD_FRAG_COUNT; + u64 bd, i = fbnic_bd_page_count(bdq); - bd = (FBNIC_BD_PAGE_ADDR_MASK & dma) | - FIELD_PREP(FBNIC_BD_PAGE_ID_MASK, id); + bd = (FBNIC_BD_DESC_ADDR_MASK & dma) | + FIELD_PREP(FBNIC_BD_DESC_ID_MASK, (u64)id << bdq->bd_page_shift); - /* In the case that a page size is larger than 4K we will map a - * single page to multiple fragments. The fragments will be - * FBNIC_BD_FRAG_COUNT in size and the lower n bits will be use - * to indicate the individual fragment IDs. + /* Posted pages larger than 4 KiB use consecutive device-page IDs in + * the low bits of the software page ID. */ do { *bdq_desc = cpu_to_le64(bd); @@ -953,7 +965,7 @@ static void fbnic_fill_bdq(struct fbnic_ring *bdq) /* Force DMA writes to flush before writing to tail */ dma_wmb(); - writel(i * FBNIC_BD_FRAG_COUNT, bdq->doorbell); + writel(i * fbnic_bd_page_count(bdq), bdq->doorbell); } } @@ -984,26 +996,27 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd, struct fbnic_pkt_buff *pkt, struct fbnic_q_triad *qt) { - unsigned int hdr_pg_idx = FIELD_GET(FBNIC_RCD_AL_BUFF_PAGE_MASK, rcd); unsigned int hdr_pg_off = FIELD_GET(FBNIC_RCD_AL_BUFF_OFF_MASK, rcd); - struct page *page = fbnic_page_pool_get_head(qt, hdr_pg_idx); unsigned int len = FIELD_GET(FBNIC_RCD_AL_BUFF_LEN_MASK, rcd); + unsigned int hdr_pg_idx = fbnic_rcd_bd_idx(&qt->sub0, rcd); unsigned int frame_sz, hdr_pg_start, hdr_pg_end, headroom; unsigned char *hdr_start; + struct page *page; /* data_hard_start should always be NULL when this is called */ WARN_ON_ONCE(pkt->buff.data_hard_start); + page = fbnic_page_pool_get_head(qt, hdr_pg_idx); + /* Short-cut the end calculation if we know page is fully consumed */ hdr_pg_end = FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? - FBNIC_BD_FRAG_SIZE : fbnic_hdr_pg_end(hdr_pg_off, len); + FBNIC_BD_PAGE_SIZE : fbnic_hdr_pg_end(hdr_pg_off, len); hdr_pg_start = fbnic_hdr_pg_start(hdr_pg_off); headroom = hdr_pg_off - hdr_pg_start + FBNIC_RX_PAD; frame_sz = hdr_pg_end - hdr_pg_start; xdp_init_buff(&pkt->buff, frame_sz, &qt->xdp_rxq); - hdr_pg_start += (FBNIC_RCD_AL_BUFF_FRAG_MASK & rcd) * - FBNIC_BD_FRAG_SIZE; + hdr_pg_start += fbnic_rcd_bd_page_offset(&qt->sub0, rcd); /* Sync DMA buffer */ dma_sync_single_range_for_cpu(nv->dev, page_pool_get_dma_addr(page), @@ -1024,18 +1037,19 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, struct fbnic_pkt_buff *pkt, struct fbnic_q_triad *qt) { - unsigned int pg_idx = FIELD_GET(FBNIC_RCD_AL_BUFF_PAGE_MASK, rcd); unsigned int pg_off = FIELD_GET(FBNIC_RCD_AL_BUFF_OFF_MASK, rcd); unsigned int len = FIELD_GET(FBNIC_RCD_AL_BUFF_LEN_MASK, rcd); - netmem_ref netmem = fbnic_page_pool_get_data(qt, pg_idx); + unsigned int pg_idx = fbnic_rcd_bd_idx(&qt->sub1, rcd); unsigned int truesize; + netmem_ref netmem; bool added; - truesize = FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? - FBNIC_BD_FRAG_SIZE - pg_off : ALIGN(len, 128); + netmem = fbnic_page_pool_get_data(qt, pg_idx); - pg_off += (FBNIC_RCD_AL_BUFF_FRAG_MASK & rcd) * - FBNIC_BD_FRAG_SIZE; + truesize = FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? + FBNIC_BD_PAGE_SIZE - pg_off : ALIGN(len, 128); + + pg_off += fbnic_rcd_bd_page_offset(&qt->sub1, rcd); /* Sync DMA buffer */ page_pool_dma_sync_netmem_for_cpu(qt->sub1.page_pool, netmem, @@ -1283,12 +1297,12 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv, switch (FIELD_GET(FBNIC_RCD_TYPE_MASK, rcd)) { case FBNIC_RCD_TYPE_HDR_AL: - head0 = FIELD_GET(FBNIC_RCD_AL_BUFF_PAGE_MASK, rcd); + head0 = fbnic_rcd_bd_idx(&qt->sub0, rcd); fbnic_pkt_prepare(nv, rcd, pkt, qt); break; case FBNIC_RCD_TYPE_PAY_AL: - head1 = FIELD_GET(FBNIC_RCD_AL_BUFF_PAGE_MASK, rcd); + head1 = fbnic_rcd_bd_idx(&qt->sub1, rcd); fbnic_add_rx_frag(nv, rcd, pkt, qt); break; @@ -1629,6 +1643,16 @@ err_destroy_sub0: return PTR_ERR(pp); } +static u8 fbnic_bdq_page_shift(u32 page_size) +{ + return ilog2(page_size / FBNIC_BD_PAGE_SIZE); +} + +static void fbnic_bdq_set_page_size(struct fbnic_ring *bdq, u32 page_size) +{ + bdq->bd_page_shift = fbnic_bdq_page_shift(page_size); +} + static void fbnic_ring_init(struct fbnic_ring *ring, u32 __iomem *doorbell, int q_idx, u8 flags) { @@ -1636,6 +1660,7 @@ static void fbnic_ring_init(struct fbnic_ring *ring, u32 __iomem *doorbell, ring->doorbell = doorbell; ring->q_idx = q_idx; ring->flags = flags; + fbnic_bdq_set_page_size(ring, PAGE_SIZE); ring->deferred_head = -1; } @@ -1920,12 +1945,12 @@ static int fbnic_alloc_rx_ring_desc(struct fbnic_net *fbn, switch (rxr->doorbell - fbnic_ring_csr_base(rxr)) { case FBNIC_QUEUE_BDQ_HPQ_TAIL: - rxq_size = fbn->hpq_size / FBNIC_BD_FRAG_COUNT; - desc_size *= FBNIC_BD_FRAG_COUNT; + rxq_size = fbn->hpq_size / fbnic_bd_page_count(rxr); + desc_size *= fbnic_bd_page_count(rxr); break; case FBNIC_QUEUE_BDQ_PPQ_TAIL: - rxq_size = fbn->ppq_size / FBNIC_BD_FRAG_COUNT; - desc_size *= FBNIC_BD_FRAG_COUNT; + rxq_size = fbn->ppq_size / fbnic_bd_page_count(rxr); + desc_size *= fbnic_bd_page_count(rxr); break; case FBNIC_QUEUE_RCQ_HEAD: rxq_size = fbn->rcq_size; @@ -2592,7 +2617,7 @@ static void fbnic_enable_bdq(struct fbnic_ring *hpq, struct fbnic_ring *ppq) hpq->tail = 0; hpq->head = 0; - log_size = fls(hpq->size_mask) + ilog2(FBNIC_BD_FRAG_COUNT); + log_size = fls(hpq->size_mask) + hpq->bd_page_shift; /* Store descriptor ring address and size */ fbnic_ring_wr32(hpq, FBNIC_QUEUE_BDQ_HPQ_BAL, lower_32_bits(hpq->dma)); @@ -2604,7 +2629,7 @@ static void fbnic_enable_bdq(struct fbnic_ring *hpq, struct fbnic_ring *ppq) if (!ppq->size_mask) goto write_ctl; - log_size = fls(ppq->size_mask) + ilog2(FBNIC_BD_FRAG_COUNT); + log_size = fls(ppq->size_mask) + ppq->bd_page_shift; /* Add enabling of PPQ to BDQ control */ bdq_ctl |= FBNIC_QUEUE_BDQ_CTL_PPQ_ENABLE; @@ -2908,8 +2933,10 @@ static int fbnic_queue_mem_alloc(struct net_device *dev, fbnic_ring_init(&qt->sub0, real->sub0.doorbell, real->sub0.q_idx, real->sub0.flags); + qt->sub0.bd_page_shift = real->sub0.bd_page_shift; fbnic_ring_init(&qt->sub1, real->sub1.doorbell, real->sub1.q_idx, real->sub1.flags); + qt->sub1.bd_page_shift = real->sub1.bd_page_shift; fbnic_ring_init(&qt->cmpl, real->cmpl.doorbell, real->cmpl.q_idx, real->cmpl.flags); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h index 66c287a5404a..4e1852f94696 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -131,6 +131,7 @@ struct fbnic_ring { u16 size_mask; /* Size of ring in descriptors - 1 */ u8 q_idx; /* Logical netdev ring index */ u8 flags; /* Ring flags (FBNIC_RING_F_*) */ + u8 bd_page_shift; /* BDQ: ilog2(page_size / 4096) */ u32 head, tail; /* Head/Tail of ring */ @@ -177,6 +178,11 @@ struct fbnic_napi_vector { extern const struct netdev_queue_mgmt_ops fbnic_queue_mgmt_ops; +static inline u16 fbnic_bd_page_count(const struct fbnic_ring *bdq) +{ + return 1U << bdq->bd_page_shift; +} + netdev_tx_t fbnic_xmit_frame(struct sk_buff *skb, struct net_device *dev); netdev_features_t fbnic_features_check(struct sk_buff *skb, struct net_device *dev, From f092b749e11c18b34b8e793bd3a134357257fa1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Date: Fri, 25 Sep 2026 12:44:10 +0200 Subject: [PATCH 0987/2126] net: Revalidate queue config for ringparam changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Memory-provider queue configuration is validated when the provider is bound. A later ethtool ring change may invalidate it because drivers can size queue memory from both ring depth and RX page size. The fbnic consumer is added in the following patch. Keep configured RX ring depths in netdev_config and stage proposed values in cfg_pending. Validate every RX queue before calling the driver. Each check validates the device defaults, then any queue memory-provider override. Commit the values only after the driver accepts them. Drivers which consume stored ring depths through queue configuration must initialize every RX depth before registering the netdev. Stored values override callback defaults, including when zero. The callback receives a rendered configuration rather than a queue ID. Validation should depend on the configuration, not queue identity. Checking defaults also covers the case where every queue has a memory-provider override. Drivers may normalize ring depths when applying them. Require the validation callback to use the same normalization. Drivers must report the applied depths through the ethtool_ringparam argument so the core records the result. Use the same transaction for ioctl and netlink. Drivers without ndo_validate_qcfg skip the new validation. Link: https://lore.kernel.org/all/20250421222827.283737-14-kuba@kernel.org/ Signed-off-by: Björn Töpel Reviewed-by: Simon Horman Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260925104417.2325213-4-bjorn@kernel.org Signed-off-by: Jakub Kicinski --- include/linux/ethtool.h | 4 ++- include/net/netdev_queues.h | 56 ++++++++++++++++++++++++++++++++----- net/core/dev.h | 2 ++ net/core/netdev_config.c | 38 +++++++++++++++++++++++-- net/ethtool/common.c | 8 ++++++ net/ethtool/common.h | 2 ++ net/ethtool/ioctl.c | 24 ++++++++++++++-- net/ethtool/rings.c | 13 ++++++++- 8 files changed, 133 insertions(+), 14 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index c4c9ce038611..c3a41fbd5426 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1025,7 +1025,9 @@ struct kernel_ethtool_ts_info { * types should be set in @supported_coalesce_params. * Returns a negative error code or zero. * @get_ringparam: Report ring sizes - * @set_ringparam: Set ring sizes. Returns a negative error code or zero. + * @set_ringparam: Set ring sizes. The &struct ethtool_ringparam argument is + * also an output; drivers which normalize requested sizes must update it + * with the applied sizes. Returns a negative error code or zero. * @get_pause_stats: Report pause frame statistics. Drivers must not zero * statistics which they don't report. The stats structure is initialized * to ETHTOOL_STAT_NOT_SET indicating driver does not report statistics. diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h index 70c9fe9e83cc..c5335e935b7d 100644 --- a/include/net/netdev_queues.h +++ b/include/net/netdev_queues.h @@ -4,18 +4,56 @@ #include +/** + * struct netdev_ring_config - accepted RX ring depth configuration + * @rx_pending: Size of the regular RX ring. + * @rx_mini_pending: Size of the RX mini ring. + * @rx_jumbo_pending: Size of the RX jumbo ring. + * + * This stores only persistent configuration values. Capability fields, + * such as max ring sizes, are reported by drivers but are not part of the + * accepted configuration. + * + * These values are only used for queue-configuration validation today. + * Drivers which normalize ring sizes must update the struct ethtool_ringparam + * passed to set_ringparam() with the applied sizes. + */ +struct netdev_ring_config { + u32 rx_pending; + u32 rx_mini_pending; + u32 rx_jumbo_pending; +}; + /** * struct netdev_config - queue-related configuration for a netdev * @hds_thresh: HDS Threshold value. * @hds_config: HDS value from userspace. + * @rings: Accepted RX ring depths. + * + * Direct values, such as @hds_thresh and @rings, hold the accepted + * configuration and always override callback-provided defaults, including + * when zero. Drivers which use @rings for queue rendering must initialize + * every RX ring depth before registering the netdev. */ struct netdev_config { u32 hds_thresh; u8 hds_config; + + struct netdev_ring_config rings; }; +/** + * struct netdev_queue_config - rendered configuration for an RX queue + * @rx_page_size: Size of one RX page-pool allocation. + * @rx_ring_size: Configured size of the regular RX ring. + * @rx_mini_ring_size: Configured size of the RX mini ring. + * @rx_jumbo_ring_size: Configured size of the RX jumbo ring. + */ struct netdev_queue_config { u32 rx_page_size; + u32 rx_ring_size; + u32 rx_mini_ring_size; + u32 rx_jumbo_ring_size; }; /* See the netdev.yaml spec for definition of each statistic */ @@ -139,16 +177,20 @@ enum { * @ndo_queue_get_dma_dev: Get dma device for zero-copy operations to be used * for this queue. Return NULL on error. * - * @ndo_default_qcfg: (Optional) Populate queue config struct with defaults. - * Queue config structs are passed to this helper before - * the user-requested settings are applied. + * @ndo_default_qcfg: (Optional) Populate queue config with defaults. Queue + * config structs are passed to this helper before the + * user-requested settings are applied. Ring depths from + * dev->cfg override these defaults. Drivers which consume + * them must initialize dev->cfg->rings before registering + * the netdev. * * @ndo_validate_qcfg: (Optional) Check if queue config is supported. * Called when configuration affecting a queue may be - * changing, either due to NIC-wide config, or config - * scoped to the queue at a specified index. - * When NIC-wide config is changed the callback will - * be invoked for all queues. + * changing. When NIC-wide config is changed the + * callback will be invoked for the defaults and all + * queue overrides. Drivers which normalize device-wide + * values when applying them must use the same + * normalization during validation. * * @ndo_queue_create: Create a new RX queue on a virtual device that will * be paired with a physical device's queue via leasing. diff --git a/net/core/dev.h b/net/core/dev.h index 73db70b023d8..4793a994f7f1 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -112,6 +112,8 @@ int netdev_reconfig_start(struct net_device *dev); int netdev_queue_config_validate(struct net_device *dev, int rxq_idx, struct netdev_queue_config *qcfg, struct netlink_ext_ack *extack); +int netdev_queue_config_revalidate(struct net_device *dev, + struct netlink_ext_ack *extack); bool netif_rxq_has_mp(struct net_device *dev, unsigned int rxq_idx); bool netif_rxq_is_leased(struct net_device *dev, unsigned int rxq_idx); diff --git a/net/core/netdev_config.c b/net/core/netdev_config.c index b101341e3251..1975de42a60d 100644 --- a/net/core/netdev_config.c +++ b/net/core/netdev_config.c @@ -50,6 +50,15 @@ static int netdev_nop_validate_qcfg(struct net_device *dev, return 0; } +static void netdev_qcfg_apply_dev(struct netdev_queue_config *qcfg, + const struct netdev_config *cfg) +{ + /* Device config overrides callback-provided fallbacks. */ + qcfg->rx_ring_size = cfg->rings.rx_pending; + qcfg->rx_mini_ring_size = cfg->rings.rx_mini_pending; + qcfg->rx_jumbo_ring_size = cfg->rings.rx_jumbo_pending; +} + static int __netdev_queue_config(struct net_device *dev, int rxq_idx, struct netdev_queue_config *qcfg, struct netlink_ext_ack *extack, @@ -70,6 +79,7 @@ static int __netdev_queue_config(struct net_device *dev, int rxq_idx, /* Get defaults from the driver, in case user config not set */ if (dev->queue_mgmt_ops->ndo_default_qcfg) dev->queue_mgmt_ops->ndo_default_qcfg(dev, qcfg); + netdev_qcfg_apply_dev(qcfg, dev->cfg_pending); err = validate_cb(dev, qcfg, extack); if (err) return err; @@ -91,9 +101,11 @@ static int __netdev_queue_config(struct net_device *dev, int rxq_idx, * @rxq_idx: index of the queue of interest * @qcfg: queue configuration struct (output) * - * Render the configuration for a given queue. This helper should be used - * by drivers which support queue configuration to retrieve config for - * a particular queue. + * Render the configuration for a given queue. During a configuration + * transaction this includes the proposed device-wide values in + * @dev->cfg_pending; otherwise @dev->cfg_pending points to the accepted + * configuration. This helper should be used by drivers which support queue + * configuration to retrieve config for a particular queue. * * @qcfg is an output parameter and is always fully initialized by this * function. Some values may not be set by the user, drivers may either @@ -113,3 +125,23 @@ int netdev_queue_config_validate(struct net_device *dev, int rxq_idx, { return __netdev_queue_config(dev, rxq_idx, qcfg, extack, true); } + +int netdev_queue_config_revalidate(struct net_device *dev, + struct netlink_ext_ack *extack) +{ + const struct netdev_queue_mgmt_ops *qops = dev->queue_mgmt_ops; + struct netdev_queue_config qcfg; + unsigned int i; + int err; + + if (!qops || !qops->ndo_validate_qcfg) + return 0; + + for (i = 0; i < dev->real_num_rx_queues; i++) { + err = netdev_queue_config_validate(dev, i, &qcfg, extack); + if (err) + return err; + } + + return 0; +} diff --git a/net/ethtool/common.c b/net/ethtool/common.c index b4e766e60d38..ec67fbd6bb86 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -959,6 +959,14 @@ void ethtool_ringparam_get_cfg(struct net_device *dev, kparam->hds_thresh = dev->cfg->hds_thresh; } +void ethtool_ringparam_set_cfg(struct netdev_config *cfg, + const struct ethtool_ringparam *param) +{ + cfg->rings.rx_pending = param->rx_pending; + cfg->rings.rx_mini_pending = param->rx_mini_pending; + cfg->rings.rx_jumbo_pending = param->rx_jumbo_pending; +} + static void ethtool_init_tsinfo(struct kernel_ethtool_ts_info *info) { memset(info, 0, sizeof(*info)); diff --git a/net/ethtool/common.h b/net/ethtool/common.h index ae32e7fdb563..b062e99e89db 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -53,6 +53,8 @@ void ethtool_ringparam_get_cfg(struct net_device *dev, struct ethtool_ringparam *param, struct kernel_ethtool_ringparam *kparam, struct netlink_ext_ack *extack); +void ethtool_ringparam_set_cfg(struct netdev_config *cfg, + const struct ethtool_ringparam *param); int ethtool_get_rx_ring_count(struct net_device *dev); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 2b449d08ddcf..27b0e2e275dc 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -35,6 +35,7 @@ #include #include "common.h" +#include "../core/dev.h" /* State held across locks and calls for commands which have devlink fallback */ struct ethtool_devlink_compat { @@ -2230,10 +2231,29 @@ static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) ringparam.tx_pending > max.tx_max_pending) return -EINVAL; + ret = netdev_reconfig_start(dev); + if (ret) + return ret; + + ethtool_ringparam_set_cfg(dev->cfg_pending, &ringparam); + + ret = netdev_queue_config_revalidate(dev, NULL); + if (ret) + goto out_free_cfg; + ret = dev->ethtool_ops->set_ringparam(dev, &ringparam, &kernel_ringparam, NULL); - if (!ret) - ethtool_notify(dev, ETHTOOL_MSG_RINGS_NTF); + if (ret) + goto out_free_cfg; + + /* Capture ring depth adjustments reported by the driver. */ + ethtool_ringparam_set_cfg(dev->cfg_pending, &ringparam); + swap(dev->cfg, dev->cfg_pending); + ethtool_notify(dev, ETHTOOL_MSG_RINGS_NTF); + +out_free_cfg: + __netdev_free_config(dev->cfg_pending); + dev->cfg_pending = dev->cfg; return ret; } diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index 9054c89c5d7b..e3810c0320e3 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -4,6 +4,7 @@ #include "common.h" #include "netlink.h" +#include "../core/dev.h" struct rings_req_info { struct ethnl_req_info base; @@ -299,10 +300,20 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) dev->cfg_pending->hds_config = kernel_ringparam.tcp_data_split; dev->cfg_pending->hds_thresh = kernel_ringparam.hds_thresh; + ethtool_ringparam_set_cfg(dev->cfg_pending, &ringparam); + + ret = netdev_queue_config_revalidate(dev, info->extack); + if (ret) + return ret; ret = dev->ethtool_ops->set_ringparam(dev, &ringparam, &kernel_ringparam, info->extack); - return ret < 0 ? ret : 1; + if (ret < 0) + return ret; + + /* Capture ring depth adjustments reported by the driver. */ + ethtool_ringparam_set_cfg(dev->cfg_pending, &ringparam); + return 1; } const struct ethnl_request_ops ethnl_rings_request_ops = { From 54491a1dbd689a90a732132145e1417a4ad4b90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Date: Fri, 25 Sep 2026 12:44:11 +0200 Subject: [PATCH 0988/2126] fbnic: Support larger memory-provider RX pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Memory providers can set the receive page size for a queue through QCFG_RX_PAGE_SIZE. fbnic creates PAGE_SIZE PPQ page-pool allocations, so larger rx_buf_len values are not reflected in the PPQ BDQ geometry. Use the rendered rx_page_size for PPQ allocations and completion decoding. The NIC still consumes 4 KiB device pages; a larger PPQ page is represented by consecutive device-page descriptors, and completion IDs decode to offsets within the same netmem allocation. Validate rx_page_size against fbnic's fragment-reference budget, device-page geometry, and rendered PPQ depth. The page size must be a power-of-two of at least one device page, its worst-case payload fragment count must fit the page-pool reference bias, and the PPQ must retain usable software depth after expansion. Signed-off-by: Björn Töpel Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260925104417.2325213-5-bjorn@kernel.org Signed-off-by: Jakub Kicinski --- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 4 + drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 96 +++++++++++++++++-- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 1 + 3 files changed, 92 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c index 10bf99be3f24..8a6703afca38 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c @@ -773,6 +773,10 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd) fbn->ppq_size = FBNIC_PPQ_SIZE_DEFAULT; fbn->rcq_size = FBNIC_RCQ_SIZE_DEFAULT; + netdev->cfg->rings.rx_pending = fbn->rcq_size; + netdev->cfg->rings.rx_mini_pending = fbn->hpq_size; + netdev->cfg->rings.rx_jumbo_pending = fbn->ppq_size; + fbn->tx_usecs = FBNIC_TX_USECS_DEFAULT; fbn->rx_usecs = FBNIC_RX_USECS_DEFAULT; fbn->rx_max_frames = FBNIC_RX_FRAMES_DEFAULT; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index 6b24733dc606..c62d885a678a 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -1047,7 +1047,8 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, netmem = fbnic_page_pool_get_data(qt, pg_idx); truesize = FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? - FBNIC_BD_PAGE_SIZE - pg_off : ALIGN(len, 128); + FBNIC_BD_PAGE_SIZE - pg_off : + ALIGN(len, FBNIC_RX_PAYLD_ALIGN); pg_off += fbnic_rcd_bd_page_offset(&qt->sub1, rcd); @@ -1055,6 +1056,9 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, page_pool_dma_sync_netmem_for_cpu(qt->sub1.page_pool, netmem, pg_off, truesize); + /* Consecutive device-page completions from one PPQ page are adjacent + * ranges in the same netmem. + */ added = xdp_buff_add_frag(&pkt->buff, netmem, pg_off, len, truesize); if (unlikely(!added)) { pkt->add_frag_failed = true; @@ -1590,7 +1594,7 @@ void fbnic_free_napi_vectors(struct fbnic_net *fbn) static int fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt, - unsigned int rxq_idx) + unsigned int rxq_idx, u32 rx_page_size) { struct page_pool_params pp_params = { .order = 0, @@ -1625,6 +1629,8 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt, qt->sub0.page_pool = pp; if (netif_rxq_has_unreadable_mp(fbn->netdev, rxq_idx)) { + pp_params.order = get_order(rx_page_size); + pp_params.max_len = rx_page_size; pp_params.flags |= PP_FLAG_ALLOW_UNREADABLE_NETMEM; pp_params.dma_dir = DMA_FROM_DEVICE; @@ -2054,15 +2060,18 @@ free_sub0: static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn, struct fbnic_napi_vector *nv, - struct fbnic_q_triad *qt) + struct fbnic_q_triad *qt, + u32 rx_page_size) { struct device *dev = fbn->netdev->dev.parent; int err; - err = fbnic_alloc_qt_page_pools(fbn, qt, qt->cmpl.q_idx); + err = fbnic_alloc_qt_page_pools(fbn, qt, qt->cmpl.q_idx, rx_page_size); if (err) return err; + fbnic_bdq_set_page_size(&qt->sub1, rx_page_size); + err = xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, qt->sub0.q_idx, nv->napi.napi_id); if (err) @@ -2123,7 +2132,11 @@ static int fbnic_alloc_nv_resources(struct fbnic_net *fbn, /* Allocate Rx Resources */ for (j = 0; j < nv->rxt_count; j++, i++) { - err = fbnic_alloc_rx_qt_resources(fbn, nv, &nv->qt[i]); + struct netdev_queue_config qcfg; + + netdev_queue_config(fbn->netdev, nv->qt[i].cmpl.q_idx, &qcfg); + err = fbnic_alloc_rx_qt_resources(fbn, nv, &nv->qt[i], + qcfg.rx_page_size); if (err) goto free_qt_resources; } @@ -2918,7 +2931,8 @@ static int fbnic_queue_mem_alloc(struct net_device *dev, struct fbnic_napi_vector *nv; if (!netif_running(dev)) - return fbnic_alloc_qt_page_pools(fbn, qt, idx); + return fbnic_alloc_qt_page_pools(fbn, qt, idx, + qcfg->rx_page_size); /* A failed PCIe recovery or resume can leave the datapath torn down * while netif_running() is still true. This ndo runs before @@ -2933,14 +2947,75 @@ static int fbnic_queue_mem_alloc(struct net_device *dev, fbnic_ring_init(&qt->sub0, real->sub0.doorbell, real->sub0.q_idx, real->sub0.flags); - qt->sub0.bd_page_shift = real->sub0.bd_page_shift; fbnic_ring_init(&qt->sub1, real->sub1.doorbell, real->sub1.q_idx, real->sub1.flags); - qt->sub1.bd_page_shift = real->sub1.bd_page_shift; fbnic_ring_init(&qt->cmpl, real->cmpl.doorbell, real->cmpl.q_idx, real->cmpl.flags); - return fbnic_alloc_rx_qt_resources(fbn, nv, qt); + return fbnic_alloc_rx_qt_resources(fbn, nv, qt, qcfg->rx_page_size); +} + +static void fbnic_default_qcfg(struct net_device *dev, + struct netdev_queue_config *qcfg) +{ + qcfg->rx_page_size = PAGE_SIZE; +} + +static int fbnic_validate_qcfg(struct net_device *dev, + struct netdev_queue_config *qcfg, + struct netlink_ext_ack *extack) +{ + u32 bd_page_count, ppq_entries, frag_count; + u32 rx_page_size = qcfg->rx_page_size; + u32 ppq_size; + + if (!qcfg->rx_jumbo_ring_size) { + NL_SET_ERR_MSG_MOD(extack, + "rx-jumbo ring size must be nonzero"); + return -EINVAL; + } + + ppq_size = roundup_pow_of_two(qcfg->rx_jumbo_ring_size); + + if (!is_power_of_2(rx_page_size)) { + NL_SET_ERR_MSG_MOD(extack, + "rx_page_size must be a power of 2"); + return -EINVAL; + } + + if (rx_page_size < FBNIC_BD_PAGE_SIZE) { + NL_SET_ERR_MSG_MOD(extack, + "rx_page_size must be at least 4K"); + return -EINVAL; + } + + /* Payload fragments occupy multiples of FBNIC_RX_PAYLD_ALIGN bytes. + * Keep at least one reference in the bias until fbnic_clean_bdq() + * observes a completion from a subsequent allocation. + */ + frag_count = rx_page_size / FBNIC_RX_PAYLD_ALIGN; + if (frag_count >= FBNIC_PAGECNT_BIAS_MAX) { + NL_SET_ERR_MSG_MOD(extack, + "rx_page_size can produce too many fragments"); + return -EINVAL; + } + + bd_page_count = rx_page_size / FBNIC_BD_PAGE_SIZE; + ppq_entries = ppq_size / bd_page_count; + /* The PPQ is sized in 4 KiB device pages. One software entry tracks + * each page-pool allocation. In addition to the unused entry for + * empty/full accounting, cleanup retains the current allocation + * until a completion identifies a subsequent allocation. A two-entry + * ring can only post one allocation and cannot make progress. + * Require at least four entries, since ring sizes are powers of two. + */ + if (ppq_entries < 4) { + NL_SET_ERR_MSG_MOD(extack, + "rx-jumbo ring size too small for rx_page_size"); + return -EINVAL; + } + + return 0; } static void fbnic_queue_mem_free(struct net_device *dev, void *qmem) @@ -3042,4 +3117,7 @@ const struct netdev_queue_mgmt_ops fbnic_queue_mgmt_ops = { .ndo_queue_mem_free = fbnic_queue_mem_free, .ndo_queue_start = fbnic_queue_start, .ndo_queue_stop = fbnic_queue_stop, + .ndo_default_qcfg = fbnic_default_qcfg, + .ndo_validate_qcfg = fbnic_validate_qcfg, + .supported_params = QCFG_RX_PAGE_SIZE, }; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h index 4e1852f94696..6ee3cce3d942 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -65,6 +65,7 @@ struct fbnic_net; #define FBNIC_RX_HROOM \ (ALIGN(FBNIC_RX_TROOM + FBNIC_RX_HROOM_PAD, 128) - FBNIC_RX_TROOM) #define FBNIC_RX_PAD 0 +#define FBNIC_RX_PAYLD_ALIGN 128 #define FBNIC_RX_PAYLD_OFFSET 0 #define FBNIC_RX_PAYLD_PG_CL 0 From b7fb14dff027391000b319cf7279c36952f9465e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Date: Fri, 25 Sep 2026 12:44:12 +0200 Subject: [PATCH 0989/2126] selftests: drv-net: Request larger zcrx buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The large-chunk test always requests two base pages. On interfaces with a large MTU, that may not exceed two maximum-sized frames. Request a power-of-two buffer larger than twice the MTU. This makes the existing rx_buf_len check and data-integrity traffic exercise the larger layout. Signed-off-by: Björn Töpel Tested-by: Breno Leitao Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260925104417.2325213-6-bjorn@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/hw/iou-zcrx.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py index c833535d8a03..5047fdb56005 100755 --- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py @@ -221,9 +221,13 @@ def test_zcrx_large_chunks(cfg) -> None: single(cfg) page_size = resource.getpagesize() + mtu = cfg.dev["mtu"] nr_pages = 2 + while nr_pages * page_size <= 2 * mtu: + nr_pages *= 2 rx_buf_len = nr_pages * page_size - rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.target} -x {nr_pages}" + rx_cmd = (f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} " + f"-q {cfg.target} -x {nr_pages}") tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 12840" probe = cmd(rx_cmd + " -d", fail=False) From a0227fa24e8a2a0397cc4eb669731ff8d9161bbd Mon Sep 17 00:00:00 2001 From: Alexandra Winter Date: Mon, 28 Sep 2026 17:14:20 +0200 Subject: [PATCH 0990/2126] s390/ism: Zerorize dmb at allocation Sashiko reported [1] that 'Missing __GFP_ZERO in folio_alloc() causes uninitialized kernel memory to be exposed in the receive message buffer'. An ism dmb is receive-only, so the data is not leaked to a remote peer. In general the smc kernel module (dibs client) will only push newly received data to userspace. We still should not have uninitialized data in a receive buffer. Since commit 750afb08ca71 ("cross-tree: phase out dma_zalloc_coherent()") dma_alloc_coherent no longer required the __GFP_ZERO flag, but when commit 83781384a96b ("s390/ism: Properly fix receive message buffer allocation") switched to folio_alloc(), it should have added back the __GFP_ZERO flag. Add __GFP_ZERO flag and state in dibs.h that register_dbm() provides a zerorized buffer (dibs_lo already does). Link: https://lore.kernel.org/linux-s390/20260903143746.A5CC41F00A3A@smtp.kernel.org/ [1] Fixes: 83781384a96b ("s390/ism: Properly fix receive message buffer allocation") Signed-off-by: Alexandra Winter Reviewed-by: Julian Ruess Link: https://patch.msgid.link/20260928151420.383105-1-wintera@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/s390/net/ism_drv.c | 3 ++- include/linux/dibs.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/s390/net/ism_drv.c b/drivers/s390/net/ism_drv.c index 035b233abb4e..405abd99c820 100644 --- a/drivers/s390/net/ism_drv.c +++ b/drivers/s390/net/ism_drv.c @@ -256,7 +256,8 @@ static int ism_alloc_dmb(struct ism_dev *ism, struct dibs_dmb *dmb) return -EINVAL; folio = folio_alloc(GFP_KERNEL | __GFP_NOWARN | __GFP_NOMEMALLOC | - __GFP_NORETRY, get_order(dmb->dmb_len)); + __GFP_NORETRY | __GFP_ZERO, + get_order(dmb->dmb_len)); if (!folio) { rc = -ENOMEM; diff --git a/include/linux/dibs.h b/include/linux/dibs.h index d3e0777f25ae..0c10c224bcca 100644 --- a/include/linux/dibs.h +++ b/include/linux/dibs.h @@ -261,12 +261,12 @@ struct dibs_dev_ops { * @vlan_id: deprecated, ignored if device does not support vlan * Upon return in addition the following fields will be valid: * @dmb_tok: for usage by remote and local devices and clients - * @cpu_addr: allocated buffer + * @cpu_addr: allocated, zerorized buffer * @idx: dmb index, unique per dibs device * @dma_addr: to be used by device driver,if applicable * - * Allocate a dmb buffer and register it with this device and for this - * client. + * Allocate and zerorize a dmb buffer and register it with this device + * and for this client. * Return: zero on success */ int (*register_dmb)(struct dibs_dev *dev, struct dibs_dmb *dmb, From 1bc449382b3d5f5a2403c4aea244073c9ed72a7c Mon Sep 17 00:00:00 2001 From: Chengfeng Ye Date: Sun, 27 Sep 2026 15:51:20 +0800 Subject: [PATCH 0991/2126] net/smc: Hold a socket reference for transmit work SMC transmit work is queued without holding a socket reference. After an active close has cancelled tx_work, a received CDC message can queue it again while the socket is in SMC_PEERCLOSEWAIT1. Passive close can then reach SMC_CLOSED, call smc_conn_free() and drop the last socket reference before smc_tx_work() acquires the socket lock. The worker then accesses the freed socket. KASAN reported: BUG: KASAN: slab-use-after-free in lock_sock_nested+0x97/0x180 Write of size 8 by task kworker/0:1/11 Workqueue: smc_tx_wq-00000000 smc_tx_work Call Trace: lock_sock_nested+0x97/0x180 smc_tx_work+0x5d/0x170 process_one_work+0x5ce/0xeb0 worker_thread+0x45b/0xd10 Allocated by task 24: sk_prot_alloc+0x56/0x210 sk_alloc+0x2b/0x6f0 smc_tcp_listen_work+0x16d/0xfc0 Freed by task 182: slab_free_after_rcu_debug+0xa6/0x1e0 rcu_core+0x509/0x1850 Hold a socket reference for each successful enqueue and release it when the worker finishes or a pending invocation is cancelled. Cover all three queue sites and all cancellation sites, including the socket options. Check conn->freed in smc_tx_pending() under the socket lock: retaining the socket does not retain connection resources released by smc_conn_free(). This also covers pending transmit processing from smc_release_cb(). Use queue_delayed_work() for the busy-slot retry as well. All tx_work delays are zero, so an already queued invocation needs no timer update. Unlike mod_delayed_work(), its return value distinguishes a successful enqueue from work disabled temporarily by cancel_delayed_work_sync(), allowing the extra reference to be returned when no work was queued. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: e6727f39004b ("smc: send data (through RDMA)") Link: https://lists.openwall.net/netdev/2026/09/09/105 Signed-off-by: Chengfeng Ye Link: https://patch.msgid.link/20260927075120.3695060-1-nicoyip.dev@gmail.com Signed-off-by: Jakub Kicinski --- net/smc/af_smc.c | 6 ++++-- net/smc/smc_close.c | 18 ++++++++++++------ net/smc/smc_core.c | 4 +++- net/smc/smc_tx.c | 18 +++++++++++++----- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 221643624ace..7f762bb31879 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -3147,7 +3147,8 @@ int smc_setsockopt(struct socket *sock, int level, int optname, if (val) { SMC_STAT_INC(smc, ndly_cnt); smc_tx_pending(&smc->conn); - cancel_delayed_work(&smc->conn.tx_work); + if (cancel_delayed_work(&smc->conn.tx_work)) + sock_put(sk); } } break; @@ -3158,7 +3159,8 @@ int smc_setsockopt(struct socket *sock, int level, int optname, if (!val) { SMC_STAT_INC(smc, cork_cnt); smc_tx_pending(&smc->conn); - cancel_delayed_work(&smc->conn.tx_work); + if (cancel_delayed_work(&smc->conn.tx_work)) + sock_put(sk); } } break; diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c index bb0313ef5f7c..a8d4b4b65f24 100644 --- a/net/smc/smc_close.c +++ b/net/smc/smc_close.c @@ -118,7 +118,8 @@ static void smc_close_cancel_work(struct smc_sock *smc) release_sock(sk); if (cancel_work_sync(&smc->conn.close_work)) sock_put(sk); - cancel_delayed_work_sync(&smc->conn.tx_work); + if (cancel_delayed_work_sync(&smc->conn.tx_work)) + sock_put(sk); lock_sock(sk); } @@ -230,7 +231,8 @@ again: case SMC_ACTIVE: smc_close_stream_wait(smc, timeout); release_sock(sk); - cancel_delayed_work_sync(&conn->tx_work); + if (cancel_delayed_work_sync(&conn->tx_work)) + sock_put(sk); lock_sock(sk); if (sk->sk_state == SMC_ACTIVE) { /* send close request */ @@ -264,7 +266,8 @@ again: if (!smc_cdc_rxed_any_close(conn)) smc_close_stream_wait(smc, timeout); release_sock(sk); - cancel_delayed_work_sync(&conn->tx_work); + if (cancel_delayed_work_sync(&conn->tx_work)) + sock_put(sk); lock_sock(sk); if (sk->sk_state != SMC_APPCLOSEWAIT1 && sk->sk_state != SMC_APPCLOSEWAIT2) @@ -372,7 +375,8 @@ static void smc_close_passive_work(struct work_struct *work) /* peer has not received all data */ smc_close_passive_abort_received(smc); release_sock(sk); - cancel_delayed_work_sync(&conn->tx_work); + if (cancel_delayed_work_sync(&conn->tx_work)) + sock_put(sk); lock_sock(sk); goto wakeup; } @@ -462,7 +466,8 @@ again: case SMC_ACTIVE: smc_close_stream_wait(smc, timeout); release_sock(sk); - cancel_delayed_work_sync(&conn->tx_work); + if (cancel_delayed_work_sync(&conn->tx_work)) + sock_put(sk); lock_sock(sk); if (sk->sk_state != SMC_ACTIVE) goto again; @@ -475,7 +480,8 @@ again: if (!smc_cdc_rxed_any_close(conn)) smc_close_stream_wait(smc, timeout); release_sock(sk); - cancel_delayed_work_sync(&conn->tx_work); + if (cancel_delayed_work_sync(&conn->tx_work)) + sock_put(sk); lock_sock(sk); if (sk->sk_state != SMC_APPCLOSEWAIT1) goto again; diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index 9974149659c2..6021322253e9 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -1070,7 +1070,9 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend, smc->sk.sk_state != SMC_CLOSED) { rc = smcr_cdc_msg_send_validation(conn, pend, wr_buf); if (!rc) { - queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, 0); + sock_hold(&smc->sk); + if (!queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, 0)) + sock_put(&smc->sk); smc->sk.sk_data_ready(&smc->sk); } } else { diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c index 3144b4b1fe29..c5c00c63ce4c 100644 --- a/net/smc/smc_tx.c +++ b/net/smc/smc_tx.c @@ -570,8 +570,10 @@ static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn) if (conn->killed) return -EPIPE; rc = 0; - mod_delayed_work(conn->lgr->tx_wq, &conn->tx_work, - SMC_TX_WORK_DELAY); + sock_hold(&smc->sk); + if (!queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, + SMC_TX_WORK_DELAY)) + sock_put(&smc->sk); } return rc; } @@ -667,7 +669,7 @@ void smc_tx_pending(struct smc_connection *conn) struct smc_sock *smc = container_of(conn, struct smc_sock, conn); int rc; - if (smc->sk.sk_err) + if (smc->sk.sk_err || conn->freed) return; rc = smc_tx_sndbuf_nonempty(conn); @@ -690,6 +692,7 @@ void smc_tx_work(struct work_struct *work) lock_sock(&smc->sk); smc_tx_pending(conn); release_sock(&smc->sk); + sock_put(&smc->sk); } void smc_tx_consumer_update(struct smc_connection *conn, bool force) @@ -718,8 +721,13 @@ void smc_tx_consumer_update(struct smc_connection *conn, bool force) return; if ((smc_cdc_get_slot_and_msg_send(conn) < 0) && !conn->killed) { - queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, - SMC_TX_WORK_DELAY); + struct smc_sock *smc = + container_of(conn, struct smc_sock, conn); + + sock_hold(&smc->sk); + if (!queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, + SMC_TX_WORK_DELAY)) + sock_put(&smc->sk); return; } } From c03e69c95a18e957dd461d60bd343e0488a986c4 Mon Sep 17 00:00:00 2001 From: Manish Awasthi Date: Thu, 24 Sep 2026 17:30:51 +0000 Subject: [PATCH 0992/2126] net: mana: Introduce gdma_bus_ops for bus-specific operations Introduce per-device gdma_bus_ops for interrupt allocation, IRQ lookup, reset, servicing, and bus-specific capabilities. Route the shared GDMA code through these callbacks and provide the PCI implementation. Move common device bring-up and teardown into mana_gd_setup() and mana_gd_cleanup(), including hardware-channel initialization, device enumeration, interrupt-pool sizing, and servicing workqueue management. Record the vPort count for transport-specific queue sizing and keep shared IRQ context bookkeeping in the core. This prepares the driver for additional bus transports without duplicating the core or adding configuration checks throughout it. Signed-off-by: Manish Awasthi Reviewed-by: Simon Horman Reviewed-by: Haiyang Zhang Link: https://patch.msgid.link/20260924173054.589291-2-mawasthi@linux.microsoft.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/microsoft/mana/gdma_main.c | 883 ++++++++++-------- drivers/net/ethernet/microsoft/mana/mana_en.c | 10 +- include/net/mana/gdma.h | 102 +- 3 files changed, 618 insertions(+), 377 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index 8e9bfc1d6a2a..b076760b2dc5 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -2,49 +2,42 @@ /* Copyright (c) 2021, Microsoft Corporation. */ #include +#include #include +#include +#include #include -#include #include #include #include #include #include #include +#include +#include +#include #include +#include #include #include struct dentry *mana_debugfs_root; -struct mana_dev_recovery { - struct list_head list; - struct pci_dev *pdev; - enum gdma_eqe_type type; -}; - -static struct mana_dev_recovery_work { - struct list_head dev_list; - struct delayed_work work; - - /* Lock for dev_list above */ - spinlock_t lock; -} mana_dev_recovery_work; - -static u32 mana_gd_r32(struct gdma_context *g, u64 offset) +/* + * True if the underlying bus can allocate MSI-X vectors after probe time. + * Buses that size their vector pool at probe install no callback. + */ +static bool mana_gd_msix_can_alloc_dyn(struct gdma_context *gc) { - return readl(g->bar0_va + offset); + if (!gc->bus_ops || !gc->bus_ops->msix_can_alloc_dyn) + return false; + + return gc->bus_ops->msix_can_alloc_dyn(gc); } -static u64 mana_gd_r64(struct gdma_context *g, u64 offset) +static int mana_gd_init_pf_regs(struct gdma_context *gc) { - return readq(g->bar0_va + offset); -} - -static int mana_gd_init_pf_regs(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); u64 remaining_barsize; u64 sriov_base_off; u64 sriov_shm_off; @@ -102,9 +95,8 @@ static int mana_gd_init_pf_regs(struct pci_dev *pdev) return 0; } -static int mana_gd_init_vf_regs(struct pci_dev *pdev) +static int mana_gd_init_vf_regs(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); u64 shm_off; gc->db_page_size = mana_gd_r32(gc, GDMA_REG_DB_PAGE_SIZE) & 0xFFFF; @@ -148,14 +140,12 @@ static int mana_gd_init_vf_regs(struct pci_dev *pdev) return 0; } -static int mana_gd_init_registers(struct pci_dev *pdev) +int mana_gd_init_registers(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); - if (gc->is_pf && !gc->is_pf2) - return mana_gd_init_pf_regs(pdev); + return mana_gd_init_pf_regs(gc); else - return mana_gd_init_vf_regs(pdev); + return mana_gd_init_vf_regs(gc); } /* Suppress logging when we set timeout to zero */ @@ -176,9 +166,8 @@ bool mana_need_log(struct gdma_context *gc, int err) return true; } -static int mana_gd_query_max_resources(struct pci_dev *pdev) +int mana_gd_query_max_resources(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); struct gdma_query_max_resources_resp resp = {}; struct gdma_general_req req = {}; unsigned int max_num_queues; @@ -194,7 +183,7 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev) * MSI-X allocation; on non-dyn platforms msi_sharing is * unconditionally true (set in mana_gd_setup_hwc_irqs). */ - if (pci_msix_can_alloc_dyn(to_pci_dev(gc->dev))) + if (mana_gd_msix_can_alloc_dyn(gc)) gc->msi_sharing = false; mana_gd_init_req_hdr(&req.hdr, GDMA_QUERY_MAX_RESOURCES, @@ -207,7 +196,11 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev) return err ? err : -EPROTO; } - if (!pci_msix_can_alloc_dyn(pdev)) { + if (!mana_gd_msix_can_alloc_dyn(gc)) { + /* Buses that size their vector pool at probe time cannot grow + * it afterwards, so never raise num_msix_usable above what has + * already been allocated. + */ if (gc->num_msix_usable > resp.max_msix) gc->num_msix_usable = resp.max_msix; } else { @@ -221,20 +214,24 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev) /* MSI-X vectors are allocated by index into the device MSI-X table, so * never ask for more than the table holds. It can be smaller than both - * resp.max_msix and the CPU count. + * resp.max_msix and the CPU count. A bus that cannot report a table + * size installs no callback and skips the clamp. */ - err = pci_msix_vec_count(pdev); - if (err <= 0) { - dev_err(gc->dev, "Failed to query MSI-X table size: %d\n", err); - return err < 0 ? err : -ENOSPC; - } - msix_vec_count = err; + if (gc->bus_ops && gc->bus_ops->msix_vec_count) { + err = gc->bus_ops->msix_vec_count(gc); + if (err <= 0) { + dev_err(gc->dev, + "Failed to query MSI-X table size: %d\n", err); + return err < 0 ? err : -ENOSPC; + } + msix_vec_count = err; - if (gc->num_msix_usable > msix_vec_count) { - dev_info(gc->dev, - "Limiting MSI-X vectors from %u to table size %u\n", - gc->num_msix_usable, msix_vec_count); - gc->num_msix_usable = msix_vec_count; + if (gc->num_msix_usable > msix_vec_count) { + dev_info(gc->dev, + "Limiting MSI-X vectors from %u to table size %u\n", + gc->num_msix_usable, msix_vec_count); + gc->num_msix_usable = msix_vec_count; + } } if (gc->num_msix_usable <= 1) @@ -286,6 +283,8 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev) if (num_ports > MAX_PORTS_IN_MANA_DEV) num_ports = MAX_PORTS_IN_MANA_DEV; + gc->num_ports = num_ports; + /* * Adjust the per-vPort max queue count to allow dedicated * MSIx for each vPort. Prefer at least MANA_DEF_NUM_QUEUES, @@ -317,9 +316,8 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev) return 0; } -static int mana_gd_query_hwc_timeout(struct pci_dev *pdev, u32 *timeout_val) +static int mana_gd_query_hwc_timeout(struct gdma_context *gc, u32 *timeout_val) { - struct gdma_context *gc = pci_get_drvdata(pdev); struct gdma_query_hwc_timeout_resp resp = {}; struct gdma_query_hwc_timeout_req req = {}; int err; @@ -336,9 +334,8 @@ static int mana_gd_query_hwc_timeout(struct pci_dev *pdev, u32 *timeout_val) return 0; } -static int mana_gd_detect_devices(struct pci_dev *pdev) +int mana_gd_detect_devices(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); struct gdma_list_devices_resp resp = {}; struct gdma_general_req req = {}; struct gdma_dev_id dev; @@ -657,187 +654,31 @@ void mana_gd_ring_dim(struct gdma_queue *cq, u32 mod_usec, bool mod_usec_vld, } EXPORT_SYMBOL_NS(mana_gd_ring_dim, "NET_MANA"); -#define MANA_SERVICE_PERIOD 10 - -static void mana_serv_rescan(struct pci_dev *pdev) -{ - struct pci_bus *parent; - - pci_lock_rescan_remove(); - - parent = pdev->bus; - if (!parent) { - dev_err(&pdev->dev, "MANA service: no parent bus\n"); - goto out; - } - - pci_stop_and_remove_bus_device(pdev); - pci_rescan_bus(parent); - -out: - pci_unlock_rescan_remove(); -} - -static void mana_serv_fpga(struct pci_dev *pdev) -{ - struct pci_bus *bus, *parent; - - pci_lock_rescan_remove(); - - bus = pdev->bus; - if (!bus) { - dev_err(&pdev->dev, "MANA service: no bus\n"); - goto out; - } - - parent = bus->parent; - if (!parent) { - dev_err(&pdev->dev, "MANA service: no parent bus\n"); - goto out; - } - - pci_stop_and_remove_bus_device(bus->self); - - msleep(MANA_SERVICE_PERIOD * 1000); - - pci_rescan_bus(parent); - -out: - pci_unlock_rescan_remove(); -} - -static void mana_serv_reset(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - struct hw_channel_context *hwc; - int ret; - - if (!gc) { - /* Perform PCI rescan on device if GC is not set up */ - dev_err(&pdev->dev, "MANA service: GC not setup, rescanning\n"); - mana_serv_rescan(pdev); - return; - } - - hwc = gc->hwc.driver_data; - if (!hwc) { - dev_err(&pdev->dev, "MANA service: no HWC\n"); - goto out; - } - - /* HWC is not responding in this case, so don't wait */ - hwc->hwc_timeout = 0; - - dev_info(&pdev->dev, "MANA reset cycle start\n"); - - mana_gd_suspend(pdev, PMSG_SUSPEND); - - msleep(MANA_SERVICE_PERIOD * 1000); - - ret = mana_gd_resume(pdev); - if (ret == -ETIMEDOUT || ret == -EPROTO) { - /* Perform PCI rescan on device if we failed on HWC */ - dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n"); - mana_serv_rescan(pdev); - return; - } - - if (ret) - dev_info(&pdev->dev, "MANA reset cycle failed err %d\n", ret); - else - dev_info(&pdev->dev, "MANA reset cycle completed\n"); - -out: - clear_bit(GC_IN_SERVICE, &gc->flags); -} - -static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev) -{ - switch (type) { - case GDMA_EQE_HWC_FPGA_RECONFIG: - mana_serv_fpga(pdev); - break; - - case GDMA_EQE_HWC_RESET_REQUEST: - mana_serv_reset(pdev); - break; - - default: - dev_err(&pdev->dev, "MANA service: unknown type %d\n", type); - break; - } -} - -static void mana_recovery_delayed_func(struct work_struct *w) -{ - struct mana_dev_recovery_work *work; - struct mana_dev_recovery *dev; - unsigned long flags; - - work = container_of(w, struct mana_dev_recovery_work, work.work); - - spin_lock_irqsave(&work->lock, flags); - - while (!list_empty(&work->dev_list)) { - dev = list_first_entry(&work->dev_list, - struct mana_dev_recovery, list); - list_del(&dev->list); - spin_unlock_irqrestore(&work->lock, flags); - - mana_do_service(dev->type, dev->pdev); - pci_dev_put(dev->pdev); - kfree(dev); - - spin_lock_irqsave(&work->lock, flags); - } - - spin_unlock_irqrestore(&work->lock, flags); -} - -static void mana_serv_func(struct work_struct *w) -{ - struct mana_serv_work *mns_wk; - struct pci_dev *pdev; - - mns_wk = container_of(w, struct mana_serv_work, serv_work); - pdev = mns_wk->pdev; - - if (pdev) - mana_do_service(mns_wk->type, pdev); - - pci_dev_put(pdev); - kfree(mns_wk); - module_put(THIS_MODULE); -} - +/* + * Queue device servicing or recovery on buses that support it. + * + * Servicing tears the device down and brings it back up, so it depends on + * bus-level facilities the GDMA core does not have. Buses that provide no + * servicing path install no callback and the request is rejected. + */ int mana_schedule_serv_work(struct gdma_context *gc, enum gdma_eqe_type type) { - struct mana_serv_work *mns_wk; + if (!gc->bus_ops || !gc->bus_ops->schedule_serv_work) + return -EOPNOTSUPP; - if (test_and_set_bit(GC_IN_SERVICE, &gc->flags)) { - dev_info(gc->dev, "Already in service\n"); - return -EBUSY; - } + return gc->bus_ops->schedule_serv_work(gc, type); +} - if (!try_module_get(THIS_MODULE)) { - dev_info(gc->dev, "Module is unloading\n"); - clear_bit(GC_IN_SERVICE, &gc->flags); - return -ENODEV; - } - - mns_wk = kzalloc_obj(*mns_wk, GFP_ATOMIC); - if (!mns_wk) { - module_put(THIS_MODULE); - clear_bit(GC_IN_SERVICE, &gc->flags); +/* The servicing workqueue is owned by the GDMA core because the queueing + * sites live here and in mana_en.c, which every transport shares. Each bus + * driver creates it during setup and destroys it during cleanup. + */ +int mana_gd_alloc_service_wq(struct gdma_context *gc) +{ + gc->service_wq = alloc_ordered_workqueue("gdma_service_wq", 0); + if (!gc->service_wq) return -ENOMEM; - } - dev_info(gc->dev, "Start MANA service type:%d\n", type); - mns_wk->pdev = to_pci_dev(gc->dev); - mns_wk->type = type; - pci_dev_get(mns_wk->pdev); - INIT_WORK(&mns_wk->serv_work, mana_serv_func); - schedule_work(&mns_wk->serv_work); return 0; } @@ -904,6 +745,15 @@ ssize_t mana_gd_read_ring(struct gdma_queue *q, char __user *buf, return copied; } +void mana_gd_free_service_wq(struct gdma_context *gc) +{ + if (!gc->service_wq) + return; + + destroy_workqueue(gc->service_wq); + gc->service_wq = NULL; +} + static void mana_gd_process_eqe(struct gdma_queue *eq) { u32 head = eq->head % (eq->queue_size / GDMA_EQE_SIZE); @@ -975,7 +825,7 @@ static void mana_gd_process_eqe(struct gdma_queue *eq) } } -static void mana_gd_process_eq_events(void *arg) +void mana_gd_process_eq_events(void *arg) { u32 owner_bits, new_bits, old_bits; union gdma_eqe_info eqe_info; @@ -1530,9 +1380,8 @@ void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue) } EXPORT_SYMBOL_NS(mana_gd_destroy_queue, "NET_MANA"); -int mana_gd_verify_vf_version(struct pci_dev *pdev) +int mana_gd_verify_vf_version(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); struct gdma_verify_ver_resp resp = {}; struct gdma_verify_ver_req req = {}; struct hw_channel_context *hwc; @@ -1546,6 +1395,8 @@ int mana_gd_verify_vf_version(struct pci_dev *pdev) req.protocol_ver_max = GDMA_PROTOCOL_LAST; req.gd_drv_cap_flags1 = GDMA_DRV_CAP_FLAGS1; + if (gc->bus_ops) + req.gd_drv_cap_flags1 |= gc->bus_ops->drv_cap_flags1; req.gd_drv_cap_flags2 = GDMA_DRV_CAP_FLAGS2; req.gd_drv_cap_flags3 = GDMA_DRV_CAP_FLAGS3; req.gd_drv_cap_flags4 = GDMA_DRV_CAP_FLAGS4; @@ -1574,7 +1425,7 @@ int mana_gd_verify_vf_version(struct pci_dev *pdev) &gc->pf_cap_flags1); if (resp.pf_cap_flags1 & GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG) { - err = mana_gd_query_hwc_timeout(pdev, &hwc->hwc_timeout); + err = mana_gd_query_hwc_timeout(gc, &hwc->hwc_timeout); if (err) { dev_err(gc->dev, "Failed to set the hwc timeout %d\n", err); return err; @@ -1873,7 +1724,7 @@ int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int num_cqe) } EXPORT_SYMBOL_NS(mana_gd_poll_cq, "NET_MANA"); -static irqreturn_t mana_gd_intr(int irq, void *arg) +irqreturn_t mana_gd_intr(int irq, void *arg) { struct gdma_irq_context *gic = arg; struct list_head *eq_list = &gic->eq_list; @@ -1888,11 +1739,25 @@ static irqreturn_t mana_gd_intr(int irq, void *arg) return IRQ_HANDLED; } +/* + * Reset the device using whatever mechanism the bus provides. + */ +int mana_gd_dev_reset(struct gdma_context *gc) +{ + if (!gc->bus_ops || !gc->bus_ops->dev_reset) + return -EOPNOTSUPP; + + return gc->bus_ops->dev_reset(gc); +} + +/* + * Release a reference on the IRQ context backing an MSI vector, freeing + * the vector once the last user is gone. + */ void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi) { - struct pci_dev *dev = to_pci_dev(gc->dev); + const struct gdma_bus_ops *ops = gc->bus_ops; struct gdma_irq_context *gic; - struct msi_map irq_map; int irq; mutex_lock(&gc->gic_mutex); @@ -1917,11 +1782,8 @@ void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi) irq_update_affinity_hint(irq, NULL); free_irq(irq, gic); - if (gic->dyn_msix) { - irq_map.virq = irq; - irq_map.index = msi; - pci_msix_free_irq(dev, irq_map); - } + if (gic->dyn_msix) + ops->msix_free(gc, msi, irq); xa_erase(&gc->irq_contexts, msi); kfree(gic); @@ -1944,12 +1806,10 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, bool use_msi_bitmap, int *msi_requested) { - struct pci_dev *dev = to_pci_dev(gc->dev); + const struct gdma_bus_ops *ops = gc->bus_ops; struct gdma_irq_context *gic; - struct msi_map irq_map = { }; - int irq; - int msi; - int err; + bool dyn_msix = false; + int msi, irq, err; mutex_lock(&gc->gic_mutex); @@ -1975,27 +1835,34 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, goto out; } - irq = pci_irq_vector(dev, msi); + irq = ops->msix_virq(gc, msi); if (irq == -EINVAL) { - irq_map = pci_msix_alloc_irq_at(dev, msi, NULL); - if (!irq_map.virq) { - err = irq_map.index; - dev_err(gc->dev, - "Failed to alloc irq_map msi %d err %d\n", - msi, err); - gic = ERR_PTR(err); + /* A bus that sizes its vector pool up front has nothing left + * to hand out once every vector has been claimed. + */ + if (!ops->msix_alloc_at) { + dev_err(gc->dev, "No IRQ for MSI %d\n", msi); + gic = ERR_PTR(-ENOENT); goto out; } - irq = irq_map.virq; - msi = irq_map.index; + + irq = ops->msix_alloc_at(gc, &msi); + if (irq < 0) { + dev_err(gc->dev, "Failed to alloc irq msi %d err %d\n", + *msi_requested, irq); + gic = ERR_PTR(irq); + goto out; + } + + dyn_msix = true; *msi_requested = msi; } gic = kzalloc_obj(*gic); if (!gic) { gic = ERR_PTR(-ENOMEM); - if (irq_map.virq) - pci_msix_free_irq(dev, irq_map); + if (dyn_msix) + ops->msix_free(gc, msi, irq); goto out; } @@ -2006,11 +1873,11 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, spin_lock_init(&gic->lock); if (!gic->msi) - snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_hwc@pci:%s", - pci_name(dev)); + snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_hwc@%s:%s", + ops->bus_name, dev_name(gc->dev)); else - snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_msi%d@pci:%s", - gic->msi, pci_name(dev)); + snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_msi%d@%s:%s", + gic->msi, ops->bus_name, dev_name(gc->dev)); err = request_irq(irq, mana_gd_intr, 0, gic->name, gic); if (err) { @@ -2018,12 +1885,12 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, irq, gic->name); kfree(gic); gic = ERR_PTR(err); - if (irq_map.virq) - pci_msix_free_irq(dev, irq_map); + if (dyn_msix) + ops->msix_free(gc, msi, irq); goto out; } - gic->dyn_msix = !!irq_map.virq; + gic->dyn_msix = dyn_msix; refcount_set(&gic->refcount, 1); gic->bitmap_refs = use_msi_bitmap ? 1 : 0; @@ -2034,8 +1901,8 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, free_irq(irq, gic); kfree(gic); gic = ERR_PTR(err); - if (irq_map.virq) - pci_msix_free_irq(dev, irq_map); + if (dyn_msix) + ops->msix_free(gc, msi, irq); goto out; } @@ -2067,6 +1934,326 @@ void mana_gd_free_res_map(struct gdma_resource *r) r->size = 0; } +/* Bring up the GDMA context on a probed device: create the debugfs directory, + * map the shared-memory registers, start the hardware channel and size the + * interrupt pool. Every step here is common to all buses; the ones that are + * not are reached through gdma_bus_ops. + */ +int mana_gd_setup(struct gdma_context *gc) +{ + int err; + + gc->mana_pci_debugfs = debugfs_create_dir(dev_name(gc->dev), + mana_debugfs_root); + + err = mana_gd_init_registers(gc); + if (err) + goto remove_debugfs; + + mana_smc_init(&gc->shm_channel, gc->dev, gc->shm_base); + + err = mana_gd_alloc_service_wq(gc); + if (err) + goto remove_debugfs; + + err = gc->bus_ops->setup_hwc_irqs(gc); + if (err) { + dev_err(gc->dev, "Failed to setup IRQs for HWC creation: %d\n", + err); + goto free_workqueue; + } + + err = mana_hwc_create_channel(gc); + if (err) + goto remove_irq; + + err = mana_gd_verify_vf_version(gc); + if (err) + goto destroy_hwc; + + err = mana_gd_detect_devices(gc); + if (err) + goto destroy_hwc; + + err = mana_gd_query_max_resources(gc); + if (err) + goto destroy_hwc; + + err = gc->bus_ops->setup_remaining_irqs(gc); + if (err) + goto destroy_hwc; + + dev_dbg(gc->dev, "mana gdma setup successful\n"); + return 0; + +destroy_hwc: + mana_hwc_destroy_channel(gc); +remove_irq: + gc->bus_ops->remove_irqs(gc); +free_workqueue: + mana_gd_free_service_wq(gc); +remove_debugfs: + debugfs_remove_recursive(gc->mana_pci_debugfs); + gc->mana_pci_debugfs = NULL; + dev_err(gc->dev, "%s failed (error %d)\n", __func__, err); + return err; +} + +void mana_gd_cleanup(struct gdma_context *gc) +{ + mana_hwc_destroy_channel(gc); + + gc->bus_ops->remove_irqs(gc); + + mana_gd_free_service_wq(gc); + + debugfs_remove_recursive(gc->mana_pci_debugfs); + gc->mana_pci_debugfs = NULL; + + dev_dbg(gc->dev, "mana gdma cleanup successful\n"); +} + +struct mana_dev_recovery { + struct list_head list; + struct pci_dev *pdev; + enum gdma_eqe_type type; +}; + +static struct mana_dev_recovery_work { + struct list_head dev_list; + struct delayed_work work; + + /* Lock for dev_list above */ + spinlock_t lock; +} mana_dev_recovery_work; + +static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state); +static int mana_gd_resume(struct pci_dev *pdev); + +#define MANA_SERVICE_PERIOD 10 + +static void mana_serv_rescan(struct pci_dev *pdev) +{ + struct pci_bus *parent; + + pci_lock_rescan_remove(); + + parent = pdev->bus; + if (!parent) { + dev_err(&pdev->dev, "MANA service: no parent bus\n"); + goto out; + } + + pci_stop_and_remove_bus_device(pdev); + pci_rescan_bus(parent); + +out: + pci_unlock_rescan_remove(); +} + +static void mana_serv_fpga(struct pci_dev *pdev) +{ + struct pci_bus *bus, *parent; + + pci_lock_rescan_remove(); + + bus = pdev->bus; + if (!bus) { + dev_err(&pdev->dev, "MANA service: no bus\n"); + goto out; + } + + parent = bus->parent; + if (!parent) { + dev_err(&pdev->dev, "MANA service: no parent bus\n"); + goto out; + } + + pci_stop_and_remove_bus_device(bus->self); + + msleep(MANA_SERVICE_PERIOD * 1000); + + pci_rescan_bus(parent); + +out: + pci_unlock_rescan_remove(); +} + +static void mana_serv_reset(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + struct hw_channel_context *hwc; + int ret; + + if (!gc) { + /* Perform PCI rescan on device if GC is not set up */ + dev_err(&pdev->dev, "MANA service: GC not setup, rescanning\n"); + mana_serv_rescan(pdev); + return; + } + + hwc = gc->hwc.driver_data; + if (!hwc) { + dev_err(&pdev->dev, "MANA service: no HWC\n"); + goto out; + } + + /* HWC is not responding in this case, so don't wait */ + hwc->hwc_timeout = 0; + + dev_info(&pdev->dev, "MANA reset cycle start\n"); + + mana_gd_suspend(pdev, PMSG_SUSPEND); + + msleep(MANA_SERVICE_PERIOD * 1000); + + ret = mana_gd_resume(pdev); + if (ret == -ETIMEDOUT || ret == -EPROTO) { + /* Perform PCI rescan on device if we failed on HWC */ + dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n"); + mana_serv_rescan(pdev); + return; + } + + if (ret) + dev_info(&pdev->dev, "MANA reset cycle failed err %d\n", ret); + else + dev_info(&pdev->dev, "MANA reset cycle completed\n"); + +out: + clear_bit(GC_IN_SERVICE, &gc->flags); +} + +static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev) +{ + switch (type) { + case GDMA_EQE_HWC_FPGA_RECONFIG: + mana_serv_fpga(pdev); + break; + + case GDMA_EQE_HWC_RESET_REQUEST: + mana_serv_reset(pdev); + break; + + default: + dev_err(&pdev->dev, "MANA service: unknown type %d\n", type); + break; + } +} + +static void mana_recovery_delayed_func(struct work_struct *w) +{ + struct mana_dev_recovery_work *work; + struct mana_dev_recovery *dev; + unsigned long flags; + + work = container_of(w, struct mana_dev_recovery_work, work.work); + + spin_lock_irqsave(&work->lock, flags); + + while (!list_empty(&work->dev_list)) { + dev = list_first_entry(&work->dev_list, + struct mana_dev_recovery, list); + list_del(&dev->list); + spin_unlock_irqrestore(&work->lock, flags); + + mana_do_service(dev->type, dev->pdev); + pci_dev_put(dev->pdev); + kfree(dev); + + spin_lock_irqsave(&work->lock, flags); + } + + spin_unlock_irqrestore(&work->lock, flags); +} + +static void mana_serv_func(struct work_struct *w) +{ + struct mana_serv_work *mns_wk; + struct pci_dev *pdev; + + mns_wk = container_of(w, struct mana_serv_work, serv_work); + pdev = mns_wk->pdev; + + if (pdev) + mana_do_service(mns_wk->type, pdev); + + pci_dev_put(pdev); + kfree(mns_wk); + module_put(THIS_MODULE); +} + +static int mana_pci_schedule_serv_work(struct gdma_context *gc, + enum gdma_eqe_type type) +{ + struct mana_serv_work *mns_wk; + + if (test_and_set_bit(GC_IN_SERVICE, &gc->flags)) { + dev_info(gc->dev, "Already in service\n"); + return -EBUSY; + } + + if (!try_module_get(THIS_MODULE)) { + dev_info(gc->dev, "Module is unloading\n"); + clear_bit(GC_IN_SERVICE, &gc->flags); + return -ENODEV; + } + + mns_wk = kzalloc(sizeof(*mns_wk), GFP_ATOMIC); + if (!mns_wk) { + module_put(THIS_MODULE); + clear_bit(GC_IN_SERVICE, &gc->flags); + return -ENOMEM; + } + + dev_info(gc->dev, "Start MANA service type:%d\n", type); + mns_wk->pdev = to_pci_dev(gc->dev); + mns_wk->type = type; + pci_dev_get(mns_wk->pdev); + INIT_WORK(&mns_wk->serv_work, mana_serv_func); + schedule_work(&mns_wk->serv_work); + return 0; +} + +static bool mana_pci_msix_can_alloc_dyn(struct gdma_context *gc) +{ + return pci_msix_can_alloc_dyn(to_pci_dev(gc->dev)); +} + +static int mana_pci_msix_virq(struct gdma_context *gc, int msi) +{ + return pci_irq_vector(to_pci_dev(gc->dev), msi); +} + +static int mana_pci_msix_alloc_at(struct gdma_context *gc, int *msi) +{ + struct msi_map irq_map; + + irq_map = pci_msix_alloc_irq_at(to_pci_dev(gc->dev), *msi, NULL); + if (!irq_map.virq) + return irq_map.index; + + *msi = irq_map.index; + return irq_map.virq; +} + +static void mana_pci_msix_free(struct gdma_context *gc, int msi, int irq) +{ + struct msi_map irq_map = { .virq = irq, .index = msi }; + + pci_msix_free_irq(to_pci_dev(gc->dev), irq_map); +} + +static int mana_pci_msix_vec_count(struct gdma_context *gc) +{ + return pci_msix_vec_count(to_pci_dev(gc->dev)); +} + +static int mana_pci_dev_reset(struct gdma_context *gc) +{ + return pcie_flr(to_pci_dev(gc->dev)); +} + /* * Spread on CPUs with the following heuristics: * @@ -2396,101 +2583,52 @@ static void mana_gd_remove_irqs(struct pci_dev *pdev) gc->num_msix_usable = 0; } -static int mana_gd_setup(struct pci_dev *pdev) +static int mana_pci_setup_hwc_irqs(struct gdma_context *gc) +{ + return mana_gd_setup_hwc_irqs(to_pci_dev(gc->dev)); +} + +static int mana_pci_setup_remaining_irqs(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); int err; - gc->mana_pci_debugfs = debugfs_create_dir(pci_name(pdev), - mana_debugfs_root); - - err = mana_gd_init_registers(pdev); - if (err) - goto remove_debugfs; - - mana_smc_init(&gc->shm_channel, gc->dev, gc->shm_base); - - gc->service_wq = alloc_ordered_workqueue("gdma_service_wq", 0); - if (!gc->service_wq) { - err = -ENOMEM; - goto remove_debugfs; - } - - err = mana_gd_setup_hwc_irqs(pdev); - if (err) { - dev_err(gc->dev, "Failed to setup IRQs for HWC creation: %d\n", - err); - goto free_workqueue; - } - - err = mana_hwc_create_channel(gc); - if (err) - goto remove_irq; - - err = mana_gd_verify_vf_version(pdev); - if (err) - goto destroy_hwc; - - err = mana_gd_detect_devices(pdev); - if (err) - goto destroy_hwc; - - err = mana_gd_query_max_resources(pdev); - if (err) - goto destroy_hwc; - - err = mana_gd_setup_remaining_irqs(pdev); + err = mana_gd_setup_remaining_irqs(to_pci_dev(gc->dev)); if (err) { dev_err(gc->dev, "Failed to setup remaining IRQs: %d", err); - goto destroy_hwc; + return err; } if (!gc->msi_sharing) { gc->msi_bitmap = bitmap_zalloc(gc->num_msix_usable, GFP_KERNEL); - if (!gc->msi_bitmap) { - err = -ENOMEM; - goto destroy_hwc; - } + if (!gc->msi_bitmap) + return -ENOMEM; /* Set bit for HWC */ set_bit(0, gc->msi_bitmap); } - dev_dbg(&pdev->dev, "mana gdma setup successful\n"); return 0; - -destroy_hwc: - mana_hwc_destroy_channel(gc); -remove_irq: - mana_gd_remove_irqs(pdev); -free_workqueue: - destroy_workqueue(gc->service_wq); - gc->service_wq = NULL; -remove_debugfs: - debugfs_remove_recursive(gc->mana_pci_debugfs); - gc->mana_pci_debugfs = NULL; - dev_err(&pdev->dev, "%s failed (error %d)\n", __func__, err); - return err; } -static void mana_gd_cleanup_device(struct pci_dev *pdev) +static void mana_pci_remove_irqs(struct gdma_context *gc) { - struct gdma_context *gc = pci_get_drvdata(pdev); - - mana_hwc_destroy_channel(gc); - - mana_gd_remove_irqs(pdev); - - if (gc->service_wq) { - destroy_workqueue(gc->service_wq); - gc->service_wq = NULL; - } - - debugfs_remove_recursive(gc->mana_pci_debugfs); - gc->mana_pci_debugfs = NULL; - - dev_dbg(&pdev->dev, "mana gdma cleanup successful\n"); + mana_gd_remove_irqs(to_pci_dev(gc->dev)); } +static const struct gdma_bus_ops mana_pci_bus_ops = { + .bus_name = "pci", + .msix_can_alloc_dyn = mana_pci_msix_can_alloc_dyn, + .msix_virq = mana_pci_msix_virq, + .msix_alloc_at = mana_pci_msix_alloc_at, + .msix_free = mana_pci_msix_free, + .msix_vec_count = mana_pci_msix_vec_count, + .setup_hwc_irqs = mana_pci_setup_hwc_irqs, + .setup_remaining_irqs = mana_pci_setup_remaining_irqs, + .remove_irqs = mana_pci_remove_irqs, + .dev_reset = mana_pci_dev_reset, + .schedule_serv_work = mana_pci_schedule_serv_work, + .drv_cap_flags1 = GDMA_DRV_CAP_FLAGS1_PCI, +}; + static bool mana_is_pf(unsigned short dev_id) { return dev_id == MANA_PF_DEVICE_ID || dev_id == MANA_PF2_DEVICE_ID; @@ -2546,9 +2684,10 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) gc->bar0_va = bar0_va; gc->dev = &pdev->dev; + gc->bus_ops = &mana_pci_bus_ops; xa_init(&gc->irq_contexts); - err = mana_gd_setup(pdev); + err = mana_gd_setup(gc); if (err) goto unmap_bar; @@ -2576,7 +2715,7 @@ cleanup_mana_rdma: cleanup_mana: mana_remove(&gc->mana, false); cleanup_gd: - mana_gd_cleanup_device(pdev); + mana_gd_cleanup(gc); unmap_bar: xa_destroy(&gc->irq_contexts); pci_iounmap(pdev, bar0_va); @@ -2629,7 +2768,7 @@ static void mana_gd_remove(struct pci_dev *pdev) mana_rdma_remove(&gc->mana_ib); mana_remove(&gc->mana, false); - mana_gd_cleanup_device(pdev); + mana_gd_cleanup(gc); xa_destroy(&gc->irq_contexts); @@ -2644,24 +2783,24 @@ static void mana_gd_remove(struct pci_dev *pdev) } /* The 'state' parameter is not used. */ -int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state) +static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state) { struct gdma_context *gc = pci_get_drvdata(pdev); mana_rdma_remove(&gc->mana_ib); mana_remove(&gc->mana, true); - mana_gd_cleanup_device(pdev); + mana_gd_cleanup(gc); return 0; } -int mana_gd_resume(struct pci_dev *pdev) +static int mana_gd_resume(struct pci_dev *pdev) { struct gdma_context *gc = pci_get_drvdata(pdev); int err; - err = mana_gd_setup(pdev); + err = mana_gd_setup(gc); if (err) return err; @@ -2676,7 +2815,7 @@ int mana_gd_resume(struct pci_dev *pdev) return err; cleanup_gd: - mana_gd_cleanup_device(pdev); + mana_gd_cleanup(gc); return err; } @@ -2690,7 +2829,7 @@ static void mana_gd_shutdown(struct pci_dev *pdev) mana_rdma_remove(&gc->mana_ib); mana_remove(&gc->mana, true); - mana_gd_cleanup_device(pdev); + mana_gd_cleanup(gc); pci_disable_device(pdev); } @@ -2734,26 +2873,19 @@ static struct pci_driver mana_driver = { .sriov_configure = mana_sriov_configure, }; -static int __init mana_driver_init(void) -{ - int err; +MODULE_DEVICE_TABLE(pci, mana_id_table); +static int mana_pci_driver_register(void) +{ INIT_LIST_HEAD(&mana_dev_recovery_work.dev_list); spin_lock_init(&mana_dev_recovery_work.lock); - INIT_DELAYED_WORK(&mana_dev_recovery_work.work, mana_recovery_delayed_func); + INIT_DELAYED_WORK(&mana_dev_recovery_work.work, + mana_recovery_delayed_func); - mana_debugfs_root = debugfs_create_dir("mana", NULL); - - err = pci_register_driver(&mana_driver); - if (err) { - debugfs_remove(mana_debugfs_root); - mana_debugfs_root = NULL; - } - - return err; + return pci_register_driver(&mana_driver); } -static void __exit mana_driver_exit(void) +static void mana_pci_driver_unregister(void) { struct mana_dev_recovery *dev; unsigned long flags; @@ -2771,6 +2903,29 @@ static void __exit mana_driver_exit(void) spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags); pci_unregister_driver(&mana_driver); +} + +static int __init mana_driver_init(void) +{ + int err; + + mana_debugfs_root = debugfs_create_dir("mana", NULL); + + err = mana_pci_driver_register(); + if (err) + goto err_debugfs; + + return 0; + +err_debugfs: + debugfs_remove(mana_debugfs_root); + mana_debugfs_root = NULL; + return err; +} + +static void __exit mana_driver_exit(void) +{ + mana_pci_driver_unregister(); debugfs_remove(mana_debugfs_root); @@ -2780,7 +2935,5 @@ static void __exit mana_driver_exit(void) module_init(mana_driver_init); module_exit(mana_driver_exit); -MODULE_DEVICE_TABLE(pci, mana_id_table); - MODULE_LICENSE("Dual BSD/GPL"); MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver"); diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 591fb4191d90..62b89b3d6072 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -20,6 +19,7 @@ #include #include + #include #include @@ -3725,10 +3725,9 @@ static int mana_dealloc_queues(struct net_device *ndev) tsleep <<= 1; } if (atomic_read(&txq->pending_sends)) { - err = - pcie_flr(to_pci_dev(gd->gdma_context->dev)); + err = mana_gd_dev_reset(gd->gdma_context); if (err) { - netdev_err(ndev, "flr failed %d with %d pkts pending in txq %u\n", + netdev_err(ndev, "device reset failed %d with %d pkts pending in txq %u\n", err, atomic_read(&txq->pending_sends), txq->gdma_txq_id); @@ -4031,6 +4030,9 @@ int mana_rdma_service_event(struct gdma_context *gc, enum gdma_service_type even return 0; } + if (!gc->service_wq) + return -EOPNOTSUPP; + serv_work = kzalloc_obj(*serv_work, GFP_ATOMIC); if (!serv_work) return -ENOMEM; diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 308950f9b54b..cdec5558304f 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -422,14 +422,72 @@ enum gdma_context_flags { GC_IN_SERVICE = 1, }; +struct gdma_context; + +/** + * struct gdma_bus_ops - transport-specific operations + * + * Lets the bus-agnostic GDMA core drive PCI and CDX devices without + * testing configuration symbols. Each bus driver installs its own + * instance in gdma_context.bus_ops at probe time. + * + * @bus_name: Bus token used to build the per-vector IRQ names. + * @msix_can_alloc_dyn: True if the bus can allocate MSI-X vectors after + * probe time. Buses that size their vector pool at probe and cannot + * grow it later leave this NULL. + * @msix_virq: Return the Linux IRQ number backing an MSI vector, or + * -EINVAL if the vector has not been allocated yet. + * @msix_alloc_at: Allocate an MSI vector on demand and return its IRQ + * number, updating @msi with the index actually assigned. Buses that + * allocate their whole pool up front leave this NULL. + * @msix_free: Release a vector obtained from @msix_alloc_at. Only needed + * by buses that implement @msix_alloc_at. + * @msix_vec_count: Return the number of entries in the device MSI-X table, + * used to clamp the vector count the core asks for. Buses that cannot + * report a table size leave this NULL and the clamp is skipped. + * @setup_hwc_irqs: Set up the interrupts the hardware channel needs before + * it is created. + * @setup_remaining_irqs: Set up the remaining interrupts once the device + * resource limits are known. + * @remove_irqs: Release the interrupts set up by @setup_hwc_irqs and + * @setup_remaining_irqs. + * @dev_reset: Reset the device using the bus-level reset mechanism. + * @schedule_serv_work: Queue device servicing or recovery. Buses without + * a servicing path leave this NULL. + * @drv_cap_flags1: Extra capability bits this transport can honour, OR'ed + * into GDMA_DRV_CAP_FLAGS1 when the driver version is negotiated. + */ +struct gdma_bus_ops { + const char *bus_name; + bool (*msix_can_alloc_dyn)(struct gdma_context *gc); + int (*msix_virq)(struct gdma_context *gc, int msi); + int (*msix_alloc_at)(struct gdma_context *gc, int *msi); + void (*msix_free)(struct gdma_context *gc, int msi, int irq); + int (*msix_vec_count)(struct gdma_context *gc); + int (*setup_hwc_irqs)(struct gdma_context *gc); + int (*setup_remaining_irqs)(struct gdma_context *gc); + void (*remove_irqs)(struct gdma_context *gc); + int (*dev_reset)(struct gdma_context *gc); + int (*schedule_serv_work)(struct gdma_context *gc, + enum gdma_eqe_type type); + u64 drv_cap_flags1; +}; + struct gdma_context { struct device *dev; struct dentry *mana_pci_debugfs; + /* Transport-specific operations, installed by the bus driver */ + const struct gdma_bus_ops *bus_ops; + /* Hardware max number of queues */ unsigned int max_num_queues; /* Per-vPort max number of queues */ unsigned int max_num_queues_vport; + /* Number of vPorts reported by the device, capped at + * MAX_PORTS_IN_MANA_DEV + */ + u16 num_ports; unsigned int max_num_msix; unsigned int num_msix_usable; struct xarray irq_contexts; @@ -529,6 +587,10 @@ ssize_t mana_gd_read_ring(struct gdma_queue *q, char __user *buf, int mana_schedule_serv_work(struct gdma_context *gc, enum gdma_eqe_type type); +int mana_gd_alloc_service_wq(struct gdma_context *gc); + +void mana_gd_free_service_wq(struct gdma_context *gc); + void mana_gd_ring_dim(struct gdma_queue *cq, u32 mod_usec, bool mod_usec_vld, u32 mod_comps, bool mod_comps_vld); @@ -686,21 +748,28 @@ enum { /* Driver supports non-contiguous queue buffers */ #define GDMA_DRV_CAP_FLAG_1_NON_CONTIGUOUS_BUFFERS BIT(30) +/* Capabilities in the PCI-only group below rely on dynamic MSI-X allocation + * and on the servicing and reset paths reached through + * mana_schedule_serv_work(). Transports that provide neither leave + * gdma_bus_ops.drv_cap_flags1 unset so the group is not advertised. + */ +#define GDMA_DRV_CAP_FLAGS1_PCI \ + (GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT | \ + GDMA_DRV_CAP_FLAG_1_SELF_RESET_ON_EQE | \ + GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE | \ + GDMA_DRV_CAP_FLAG_1_PROBE_RECOVERY | \ + GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECOVERY) + #define GDMA_DRV_CAP_FLAGS1 \ (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \ GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG | \ GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT | \ GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP | \ - GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT | \ - GDMA_DRV_CAP_FLAG_1_SELF_RESET_ON_EQE | \ - GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE | \ GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE | \ GDMA_DRV_CAP_FLAG_1_PERIODIC_STATS_QUERY | \ GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE | \ - GDMA_DRV_CAP_FLAG_1_PROBE_RECOVERY | \ GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY | \ - GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECOVERY | \ GDMA_DRV_CAP_FLAG_1_EQ_MSI_UNSHARE_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_DYN_INTERRUPT_MODERATION | \ GDMA_DRV_CAP_FLAG_1_NON_CONTIGUOUS_BUFFERS) @@ -1044,7 +1113,24 @@ struct gdma_destroy_dm_resp { struct gdma_resp_hdr hdr; }; /* HW Data */ -int mana_gd_verify_vf_version(struct pci_dev *pdev); +int mana_gd_verify_vf_version(struct gdma_context *gc); +int mana_gd_query_max_resources(struct gdma_context *gc); +int mana_gd_setup(struct gdma_context *gc); +void mana_gd_cleanup(struct gdma_context *gc); +int mana_gd_detect_devices(struct gdma_context *gc); +int mana_gd_init_registers(struct gdma_context *gc); +irqreturn_t mana_gd_intr(int irq, void *arg); +void mana_gd_process_eq_events(void *arg); + +static inline u32 mana_gd_r32(struct gdma_context *g, u64 offset) +{ + return readl(g->bar0_va + offset); +} + +static inline u64 mana_gd_r64(struct gdma_context *g, u64 offset) +{ + return readq(g->bar0_va + offset); +} int mana_gd_register_device(struct gdma_dev *gd); int mana_gd_deregister_device(struct gdma_dev *gd); @@ -1077,8 +1163,6 @@ void mana_unregister_debugfs(void); int mana_rdma_service_event(struct gdma_context *gc, enum gdma_service_type event); -int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state); -int mana_gd_resume(struct pci_dev *pdev); bool mana_need_log(struct gdma_context *gc, int err); @@ -1089,4 +1173,6 @@ void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi); int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver, u32 proto_minor_ver, u32 proto_micro_ver, u16 *max_num_vports, u8 *bm_hostmode); +int mana_gd_dev_reset(struct gdma_context *gc); + #endif /* _GDMA_H */ From 34520ae5dd5756849849776c097871f4a589c622 Mon Sep 17 00:00:00 2001 From: Manish Awasthi Date: Thu, 24 Sep 2026 17:30:52 +0000 Subject: [PATCH 0993/2126] net: mana: Move PCI transport code into gdma_pci.c Move PCI transport code and driver callbacks from gdma_main.c into gdma_pci.c. Keep shared IRQ bookkeeping in the core and update build wiring. Signed-off-by: Manish Awasthi Reviewed-by: Simon Horman Reviewed-by: Haiyang Zhang Link: https://patch.msgid.link/20260924173054.589291-3-mawasthi@linux.microsoft.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microsoft/mana/Makefile | 3 +- .../net/ethernet/microsoft/mana/gdma_main.c | 899 ----------------- .../net/ethernet/microsoft/mana/gdma_pci.c | 909 ++++++++++++++++++ include/net/mana/gdma.h | 3 + 4 files changed, 914 insertions(+), 900 deletions(-) create mode 100644 drivers/net/ethernet/microsoft/mana/gdma_pci.c diff --git a/drivers/net/ethernet/microsoft/mana/Makefile b/drivers/net/ethernet/microsoft/mana/Makefile index e16a4221f571..6705bf65c92c 100644 --- a/drivers/net/ethernet/microsoft/mana/Makefile +++ b/drivers/net/ethernet/microsoft/mana/Makefile @@ -3,4 +3,5 @@ # Makefile for the Microsoft Azure Network Adapter driver obj-$(CONFIG_MICROSOFT_MANA) += mana.o -mana-objs := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o mana_bpf.o +mana-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o mana_bpf.o \ + gdma_pci.o diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index b076760b2dc5..531170e58a62 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -2,10 +2,7 @@ /* Copyright (c) 2021, Microsoft Corporation. */ #include -#include #include -#include -#include #include #include #include @@ -13,11 +10,7 @@ #include #include #include -#include -#include -#include #include -#include #include #include @@ -2013,898 +2006,6 @@ void mana_gd_cleanup(struct gdma_context *gc) dev_dbg(gc->dev, "mana gdma cleanup successful\n"); } -struct mana_dev_recovery { - struct list_head list; - struct pci_dev *pdev; - enum gdma_eqe_type type; -}; - -static struct mana_dev_recovery_work { - struct list_head dev_list; - struct delayed_work work; - - /* Lock for dev_list above */ - spinlock_t lock; -} mana_dev_recovery_work; - -static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state); -static int mana_gd_resume(struct pci_dev *pdev); - -#define MANA_SERVICE_PERIOD 10 - -static void mana_serv_rescan(struct pci_dev *pdev) -{ - struct pci_bus *parent; - - pci_lock_rescan_remove(); - - parent = pdev->bus; - if (!parent) { - dev_err(&pdev->dev, "MANA service: no parent bus\n"); - goto out; - } - - pci_stop_and_remove_bus_device(pdev); - pci_rescan_bus(parent); - -out: - pci_unlock_rescan_remove(); -} - -static void mana_serv_fpga(struct pci_dev *pdev) -{ - struct pci_bus *bus, *parent; - - pci_lock_rescan_remove(); - - bus = pdev->bus; - if (!bus) { - dev_err(&pdev->dev, "MANA service: no bus\n"); - goto out; - } - - parent = bus->parent; - if (!parent) { - dev_err(&pdev->dev, "MANA service: no parent bus\n"); - goto out; - } - - pci_stop_and_remove_bus_device(bus->self); - - msleep(MANA_SERVICE_PERIOD * 1000); - - pci_rescan_bus(parent); - -out: - pci_unlock_rescan_remove(); -} - -static void mana_serv_reset(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - struct hw_channel_context *hwc; - int ret; - - if (!gc) { - /* Perform PCI rescan on device if GC is not set up */ - dev_err(&pdev->dev, "MANA service: GC not setup, rescanning\n"); - mana_serv_rescan(pdev); - return; - } - - hwc = gc->hwc.driver_data; - if (!hwc) { - dev_err(&pdev->dev, "MANA service: no HWC\n"); - goto out; - } - - /* HWC is not responding in this case, so don't wait */ - hwc->hwc_timeout = 0; - - dev_info(&pdev->dev, "MANA reset cycle start\n"); - - mana_gd_suspend(pdev, PMSG_SUSPEND); - - msleep(MANA_SERVICE_PERIOD * 1000); - - ret = mana_gd_resume(pdev); - if (ret == -ETIMEDOUT || ret == -EPROTO) { - /* Perform PCI rescan on device if we failed on HWC */ - dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n"); - mana_serv_rescan(pdev); - return; - } - - if (ret) - dev_info(&pdev->dev, "MANA reset cycle failed err %d\n", ret); - else - dev_info(&pdev->dev, "MANA reset cycle completed\n"); - -out: - clear_bit(GC_IN_SERVICE, &gc->flags); -} - -static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev) -{ - switch (type) { - case GDMA_EQE_HWC_FPGA_RECONFIG: - mana_serv_fpga(pdev); - break; - - case GDMA_EQE_HWC_RESET_REQUEST: - mana_serv_reset(pdev); - break; - - default: - dev_err(&pdev->dev, "MANA service: unknown type %d\n", type); - break; - } -} - -static void mana_recovery_delayed_func(struct work_struct *w) -{ - struct mana_dev_recovery_work *work; - struct mana_dev_recovery *dev; - unsigned long flags; - - work = container_of(w, struct mana_dev_recovery_work, work.work); - - spin_lock_irqsave(&work->lock, flags); - - while (!list_empty(&work->dev_list)) { - dev = list_first_entry(&work->dev_list, - struct mana_dev_recovery, list); - list_del(&dev->list); - spin_unlock_irqrestore(&work->lock, flags); - - mana_do_service(dev->type, dev->pdev); - pci_dev_put(dev->pdev); - kfree(dev); - - spin_lock_irqsave(&work->lock, flags); - } - - spin_unlock_irqrestore(&work->lock, flags); -} - -static void mana_serv_func(struct work_struct *w) -{ - struct mana_serv_work *mns_wk; - struct pci_dev *pdev; - - mns_wk = container_of(w, struct mana_serv_work, serv_work); - pdev = mns_wk->pdev; - - if (pdev) - mana_do_service(mns_wk->type, pdev); - - pci_dev_put(pdev); - kfree(mns_wk); - module_put(THIS_MODULE); -} - -static int mana_pci_schedule_serv_work(struct gdma_context *gc, - enum gdma_eqe_type type) -{ - struct mana_serv_work *mns_wk; - - if (test_and_set_bit(GC_IN_SERVICE, &gc->flags)) { - dev_info(gc->dev, "Already in service\n"); - return -EBUSY; - } - - if (!try_module_get(THIS_MODULE)) { - dev_info(gc->dev, "Module is unloading\n"); - clear_bit(GC_IN_SERVICE, &gc->flags); - return -ENODEV; - } - - mns_wk = kzalloc(sizeof(*mns_wk), GFP_ATOMIC); - if (!mns_wk) { - module_put(THIS_MODULE); - clear_bit(GC_IN_SERVICE, &gc->flags); - return -ENOMEM; - } - - dev_info(gc->dev, "Start MANA service type:%d\n", type); - mns_wk->pdev = to_pci_dev(gc->dev); - mns_wk->type = type; - pci_dev_get(mns_wk->pdev); - INIT_WORK(&mns_wk->serv_work, mana_serv_func); - schedule_work(&mns_wk->serv_work); - return 0; -} - -static bool mana_pci_msix_can_alloc_dyn(struct gdma_context *gc) -{ - return pci_msix_can_alloc_dyn(to_pci_dev(gc->dev)); -} - -static int mana_pci_msix_virq(struct gdma_context *gc, int msi) -{ - return pci_irq_vector(to_pci_dev(gc->dev), msi); -} - -static int mana_pci_msix_alloc_at(struct gdma_context *gc, int *msi) -{ - struct msi_map irq_map; - - irq_map = pci_msix_alloc_irq_at(to_pci_dev(gc->dev), *msi, NULL); - if (!irq_map.virq) - return irq_map.index; - - *msi = irq_map.index; - return irq_map.virq; -} - -static void mana_pci_msix_free(struct gdma_context *gc, int msi, int irq) -{ - struct msi_map irq_map = { .virq = irq, .index = msi }; - - pci_msix_free_irq(to_pci_dev(gc->dev), irq_map); -} - -static int mana_pci_msix_vec_count(struct gdma_context *gc) -{ - return pci_msix_vec_count(to_pci_dev(gc->dev)); -} - -static int mana_pci_dev_reset(struct gdma_context *gc) -{ - return pcie_flr(to_pci_dev(gc->dev)); -} - -/* - * Spread on CPUs with the following heuristics: - * - * 1. No more than one IRQ per CPU, if possible; - * 2. NUMA locality is the second priority; - * 3. Sibling dislocality is the last priority. - * - * Let's consider this topology: - * - * Node 0 1 - * Core 0 1 2 3 - * CPU 0 1 2 3 4 5 6 7 - * - * The most performant IRQ distribution based on the above topology - * and heuristics may look like this: - * - * IRQ Nodes Cores CPUs - * 0 1 0 0-1 - * 1 1 1 2-3 - * 2 1 0 0-1 - * 3 1 1 2-3 - * 4 2 2 4-5 - * 5 2 3 6-7 - * 6 2 2 4-5 - * 7 2 3 6-7 - * - * The heuristics is implemented as follows. - * - * The outer for_each() loop resets the 'weight' to the actual number - * of CPUs in the hop. Then inner for_each() loop decrements it by the - * number of sibling groups (cores) while assigning first set of IRQs - * to each group. IRQs 0 and 1 above are distributed this way. - * - * Now, because NUMA locality is more important, we should walk the - * same set of siblings and assign 2nd set of IRQs (2 and 3), and it's - * implemented by the medium while() loop. We do like this unless the - * number of IRQs assigned on this hop will not become equal to number - * of CPUs in the hop (weight == 0). Then we switch to the next hop and - * do the same thing. - */ - -static int mana_irq_setup_numa_aware(unsigned int *irqs, unsigned int len, - int node, bool skip_first_cpu) -{ - const struct cpumask *next, *prev = cpu_none_mask; - cpumask_var_t cpus __free(free_cpumask_var); - int cpu, weight; - - if (!alloc_cpumask_var(&cpus, GFP_KERNEL)) - return -ENOMEM; - - rcu_read_lock(); - for_each_numa_hop_mask(next, node) { - weight = cpumask_weight_andnot(next, prev); - while (weight > 0) { - cpumask_andnot(cpus, next, prev); - for_each_cpu(cpu, cpus) { - cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu)); - --weight; - - if (unlikely(skip_first_cpu)) { - skip_first_cpu = false; - continue; - } - - if (len-- == 0) - goto done; - - irq_set_affinity_and_hint(*irqs++, topology_sibling_cpumask(cpu)); - } - } - prev = next; - } -done: - rcu_read_unlock(); - return 0; -} - -/* must be called with cpus_read_lock() held */ -static void mana_irq_setup_linear(unsigned int *irqs, unsigned int len) -{ - int cpu; - - for_each_online_cpu(cpu) { - if (len == 0) - break; - - irq_set_affinity_and_hint(*irqs++, cpumask_of(cpu)); - len--; - } -} - -static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - struct gdma_irq_context *gic; - int *irqs, err, i, msi; - - irqs = kmalloc_objs(int, nvec); - if (!irqs) - return -ENOMEM; - - /* - * In this function, num_msix_usable = HWC IRQ + Queue IRQ. - * nvec is only Queue IRQ (HWC already setup). - * While processing the next pci irq vector, we start with index 1, - * as IRQ vector at index 0 is already processed for HWC. - * However, the population of irqs array starts with index 0, to be - * further used in mana_irq_setup_numa_aware() - */ - for (i = 1; i <= nvec; i++) { - msi = i; - gic = mana_gd_get_gic(gc, false, &msi); - if (IS_ERR(gic)) { - err = PTR_ERR(gic); - goto free_irq; - } - - irqs[i - 1] = gic->irq; - } - - /* - * When calling mana_irq_setup_numa_aware() for dynamically added IRQs, - * if number of CPUs is more than or equal to allocated MSI-X, we need to - * skip the first CPU sibling group since they are already affinitized to - * HWC IRQ - */ - cpus_read_lock(); - if (gc->num_msix_usable <= num_online_cpus()) { - err = mana_irq_setup_numa_aware(irqs, nvec, gc->numa_node, - true); - if (err) { - cpus_read_unlock(); - goto free_irq; - } - } else { - /* - * When num_msix_usable are more than num_online_cpus, our - * queue IRQs should be equal to num of online vCPUs. - * We try to make sure queue IRQs spread across all vCPUs. - * In such a case NUMA or CPU core affinity does not matter. - * Note: in this case the total mana IRQ should always be - * num_online_cpus + 1. The first HWC IRQ is already handled - * in HWC setup calls - * However, if CPUs went offline since num_msix_usable was - * computed, queue IRQs will be more than num_online_cpus(). - * In such cases remaining extra IRQs will retain their default - * affinity. - */ - int first_unassigned = num_online_cpus(); - - if (nvec > first_unassigned) { - char buf[32]; - - if (first_unassigned == nvec - 1) - snprintf(buf, sizeof(buf), "%d", - first_unassigned); - else - snprintf(buf, sizeof(buf), "%d-%d", - first_unassigned, nvec - 1); - - dev_dbg(&pdev->dev, - "MANA IRQ indices #%s will retain the default CPU affinity\n", - buf); - } - - mana_irq_setup_linear(irqs, nvec); - } - - cpus_read_unlock(); - kfree(irqs); - return 0; - -free_irq: - for (i -= 1; i > 0; i--) - mana_gd_put_gic(gc, false, i); - kfree(irqs); - return err; -} - -static int mana_gd_setup_irqs(struct pci_dev *pdev, int nvec) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - struct gdma_irq_context *gic; - int *irqs, *start_irqs; - unsigned int cpu; - int err, i, msi; - - irqs = kmalloc_objs(int, nvec); - if (!irqs) - return -ENOMEM; - - start_irqs = irqs; - - for (i = 0; i < nvec; i++) { - msi = i; - gic = mana_gd_get_gic(gc, false, &msi); - if (IS_ERR(gic)) { - err = PTR_ERR(gic); - goto free_irq; - } - - irqs[i] = gic->irq; - } - - /* If number of IRQ is one extra than number of online CPUs, - * then we need to assign IRQ0 (hwc irq) and IRQ1 to - * same CPU. - * Else we will use different CPUs for IRQ0 and IRQ1. - * Also we are using cpumask_local_spread instead of - * cpumask_first for the node, because the node can be - * mem only. - */ - cpus_read_lock(); - if (nvec > num_online_cpus()) { - cpu = cpumask_local_spread(0, gc->numa_node); - irq_set_affinity_and_hint(irqs[0], cpumask_of(cpu)); - irqs++; - nvec -= 1; - } - - err = mana_irq_setup_numa_aware(irqs, nvec, gc->numa_node, false); - if (err) { - cpus_read_unlock(); - goto free_irq; - } - - cpus_read_unlock(); - kfree(start_irqs); - return 0; - -free_irq: - for (i -= 1; i >= 0; i--) - mana_gd_put_gic(gc, false, i); - - kfree(start_irqs); - return err; -} - -static int mana_gd_setup_hwc_irqs(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - unsigned int max_irqs, min_irqs; - int nvec, err; - - if (pci_msix_can_alloc_dyn(pdev)) { - max_irqs = 1; - min_irqs = 1; - } else { - /* Need 1 interrupt for HWC */ - max_irqs = min(num_online_cpus(), MANA_MAX_NUM_QUEUES) + 1; - min_irqs = 2; - gc->msi_sharing = true; - } - - nvec = pci_alloc_irq_vectors(pdev, min_irqs, max_irqs, PCI_IRQ_MSIX); - if (nvec < 0) - return nvec; - - err = mana_gd_setup_irqs(pdev, nvec); - if (err) { - pci_free_irq_vectors(pdev); - return err; - } - - gc->num_msix_usable = nvec; - gc->max_num_msix = nvec; - - return 0; -} - -static int mana_gd_setup_remaining_irqs(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - struct msi_map irq_map; - int max_irqs, i, err; - - if (!pci_msix_can_alloc_dyn(pdev)) - /* remain irqs are already allocated with HWC IRQ */ - return 0; - - /* allocate only remaining IRQs*/ - max_irqs = gc->num_msix_usable - 1; - - for (i = 1; i <= max_irqs; i++) { - irq_map = pci_msix_alloc_irq_at(pdev, i, NULL); - if (!irq_map.virq) { - err = irq_map.index; - /* caller will handle cleaning up all allocated - * irqs, after HWC is destroyed - */ - return err; - } - } - - err = mana_gd_setup_dyn_irqs(pdev, max_irqs); - if (err) - return err; - - gc->max_num_msix = gc->max_num_msix + max_irqs; - - return 0; -} - -static void mana_gd_remove_irqs(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - int i; - - if (gc->max_num_msix < 1) - return; - - for (i = 0; i < gc->max_num_msix; i++) { - if (!xa_load(&gc->irq_contexts, i)) - continue; - - mana_gd_put_gic(gc, false, i); - } - - WARN_ON(!xa_empty(&gc->irq_contexts)); - - pci_free_irq_vectors(pdev); - - bitmap_free(gc->msi_bitmap); - gc->msi_bitmap = NULL; - gc->max_num_msix = 0; - gc->num_msix_usable = 0; -} - -static int mana_pci_setup_hwc_irqs(struct gdma_context *gc) -{ - return mana_gd_setup_hwc_irqs(to_pci_dev(gc->dev)); -} - -static int mana_pci_setup_remaining_irqs(struct gdma_context *gc) -{ - int err; - - err = mana_gd_setup_remaining_irqs(to_pci_dev(gc->dev)); - if (err) { - dev_err(gc->dev, "Failed to setup remaining IRQs: %d", err); - return err; - } - - if (!gc->msi_sharing) { - gc->msi_bitmap = bitmap_zalloc(gc->num_msix_usable, GFP_KERNEL); - if (!gc->msi_bitmap) - return -ENOMEM; - /* Set bit for HWC */ - set_bit(0, gc->msi_bitmap); - } - - return 0; -} - -static void mana_pci_remove_irqs(struct gdma_context *gc) -{ - mana_gd_remove_irqs(to_pci_dev(gc->dev)); -} - -static const struct gdma_bus_ops mana_pci_bus_ops = { - .bus_name = "pci", - .msix_can_alloc_dyn = mana_pci_msix_can_alloc_dyn, - .msix_virq = mana_pci_msix_virq, - .msix_alloc_at = mana_pci_msix_alloc_at, - .msix_free = mana_pci_msix_free, - .msix_vec_count = mana_pci_msix_vec_count, - .setup_hwc_irqs = mana_pci_setup_hwc_irqs, - .setup_remaining_irqs = mana_pci_setup_remaining_irqs, - .remove_irqs = mana_pci_remove_irqs, - .dev_reset = mana_pci_dev_reset, - .schedule_serv_work = mana_pci_schedule_serv_work, - .drv_cap_flags1 = GDMA_DRV_CAP_FLAGS1_PCI, -}; - -static bool mana_is_pf(unsigned short dev_id) -{ - return dev_id == MANA_PF_DEVICE_ID || dev_id == MANA_PF2_DEVICE_ID; -} - -static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) -{ - struct gdma_context *gc; - void __iomem *bar0_va; - int bar = 0; - int err; - - /* Each port has 2 CQs, each CQ has at most 1 EQE at a time */ - BUILD_BUG_ON(2 * MAX_PORTS_IN_MANA_DEV * GDMA_EQE_SIZE > EQ_SIZE); - - err = pci_enable_device(pdev); - if (err) { - dev_err(&pdev->dev, "Failed to enable pci device (err=%d)\n", err); - return -ENXIO; - } - - pci_set_master(pdev); - - err = pci_request_regions(pdev, "mana"); - if (err) - goto disable_dev; - - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); - if (err) { - dev_err(&pdev->dev, "DMA set mask failed: %d\n", err); - goto release_region; - } - dma_set_max_seg_size(&pdev->dev, UINT_MAX); - - err = -ENOMEM; - gc = vzalloc(sizeof(*gc)); - if (!gc) - goto release_region; - - mutex_init(&gc->eq_test_event_mutex); - mutex_init(&gc->gic_mutex); - pci_set_drvdata(pdev, gc); - gc->bar0_pa = pci_resource_start(pdev, 0); - gc->bar0_size = pci_resource_len(pdev, 0); - - bar0_va = pci_iomap(pdev, bar, 0); - if (!bar0_va) - goto free_gc; - - gc->numa_node = dev_to_node(&pdev->dev); - gc->is_pf = mana_is_pf(pdev->device); - gc->is_pf2 = (pdev->device == MANA_PF2_DEVICE_ID); - - gc->bar0_va = bar0_va; - gc->dev = &pdev->dev; - gc->bus_ops = &mana_pci_bus_ops; - xa_init(&gc->irq_contexts); - - err = mana_gd_setup(gc); - if (err) - goto unmap_bar; - - err = mana_probe(&gc->mana, false); - if (err) - goto cleanup_gd; - - err = mana_rdma_probe(&gc->mana_ib); - if (err) - goto cleanup_mana; - - /* - * If a hardware reset event has occurred over HWC during probe, - * rollback and perform hardware reset procedure. - */ - if (test_and_set_bit(GC_PROBE_SUCCEEDED, &gc->flags)) { - err = -EPROTO; - goto cleanup_mana_rdma; - } - - return 0; - -cleanup_mana_rdma: - mana_rdma_remove(&gc->mana_ib); -cleanup_mana: - mana_remove(&gc->mana, false); -cleanup_gd: - mana_gd_cleanup(gc); -unmap_bar: - xa_destroy(&gc->irq_contexts); - pci_iounmap(pdev, bar0_va); -free_gc: - pci_set_drvdata(pdev, NULL); - vfree(gc); -release_region: - pci_release_regions(pdev); -disable_dev: - pci_disable_device(pdev); - dev_err(&pdev->dev, "gdma probe failed: err = %d\n", err); - - /* - * Hardware could be in recovery mode and the HWC returns TIMEDOUT or - * EPROTO from mana_gd_setup(), mana_probe() or mana_rdma_probe(), or - * we received a hardware reset event over HWC interrupt. In this case, - * perform the device recovery procedure after MANA_SERVICE_PERIOD - * seconds. - */ - if (err == -ETIMEDOUT || err == -EPROTO) { - struct mana_dev_recovery *dev; - unsigned long flags; - - dev_info(&pdev->dev, "Start MANA recovery mode\n"); - - dev = kzalloc_obj(*dev); - if (!dev) - return err; - - dev->pdev = pci_dev_get(pdev); - dev->type = GDMA_EQE_HWC_RESET_REQUEST; - - spin_lock_irqsave(&mana_dev_recovery_work.lock, flags); - list_add_tail(&dev->list, &mana_dev_recovery_work.dev_list); - spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags); - - schedule_delayed_work(&mana_dev_recovery_work.work, - secs_to_jiffies(MANA_SERVICE_PERIOD)); - } - - return err; -} - -static void mana_gd_remove(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - - pci_disable_sriov(pdev); - - mana_rdma_remove(&gc->mana_ib); - mana_remove(&gc->mana, false); - - mana_gd_cleanup(gc); - - xa_destroy(&gc->irq_contexts); - - pci_iounmap(pdev, gc->bar0_va); - - vfree(gc); - - pci_release_regions(pdev); - pci_disable_device(pdev); - - dev_dbg(&pdev->dev, "mana gdma remove successful\n"); -} - -/* The 'state' parameter is not used. */ -static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - - mana_rdma_remove(&gc->mana_ib); - mana_remove(&gc->mana, true); - - mana_gd_cleanup(gc); - - return 0; -} - -static int mana_gd_resume(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - int err; - - err = mana_gd_setup(gc); - if (err) - return err; - - err = mana_probe(&gc->mana, true); - if (err) - goto cleanup_gd; - - err = mana_rdma_probe(&gc->mana_ib); - if (err) - mana_rdma_remove(&gc->mana_ib); - - return err; - -cleanup_gd: - mana_gd_cleanup(gc); - return err; -} - -/* Quiesce the device for kexec. This is also called upon reboot/shutdown. */ -static void mana_gd_shutdown(struct pci_dev *pdev) -{ - struct gdma_context *gc = pci_get_drvdata(pdev); - - dev_info(&pdev->dev, "Shutdown was called\n"); - - mana_rdma_remove(&gc->mana_ib); - mana_remove(&gc->mana, true); - - mana_gd_cleanup(gc); - - pci_disable_device(pdev); -} - -static int mana_sriov_configure(struct pci_dev *pdev, int numvfs) -{ - int err = 0; - - dev_info(&pdev->dev, "Requested num VFs: %d\n", numvfs); - - if (numvfs > 0) { - err = pci_enable_sriov(pdev, numvfs); - } else { - if (pci_vfs_assigned(pdev)) { - dev_warn(&pdev->dev, - "Cannot disable SR-IOV while VFs are assigned\n"); - return -EPERM; - } - - pci_disable_sriov(pdev); - } - - return err ? err : numvfs; -} - -static const struct pci_device_id mana_id_table[] = { - { PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_PF_DEVICE_ID) }, - { PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_PF2_DEVICE_ID) }, - { PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_VF_DEVICE_ID) }, - { } -}; - -static struct pci_driver mana_driver = { - .name = "mana", - .id_table = mana_id_table, - .probe = mana_gd_probe, - .remove = mana_gd_remove, - .suspend = mana_gd_suspend, - .resume = mana_gd_resume, - .shutdown = mana_gd_shutdown, - .sriov_configure = mana_sriov_configure, -}; - -MODULE_DEVICE_TABLE(pci, mana_id_table); - -static int mana_pci_driver_register(void) -{ - INIT_LIST_HEAD(&mana_dev_recovery_work.dev_list); - spin_lock_init(&mana_dev_recovery_work.lock); - INIT_DELAYED_WORK(&mana_dev_recovery_work.work, - mana_recovery_delayed_func); - - return pci_register_driver(&mana_driver); -} - -static void mana_pci_driver_unregister(void) -{ - struct mana_dev_recovery *dev; - unsigned long flags; - - disable_delayed_work_sync(&mana_dev_recovery_work.work); - - spin_lock_irqsave(&mana_dev_recovery_work.lock, flags); - while (!list_empty(&mana_dev_recovery_work.dev_list)) { - dev = list_first_entry(&mana_dev_recovery_work.dev_list, - struct mana_dev_recovery, list); - list_del(&dev->list); - pci_dev_put(dev->pdev); - kfree(dev); - } - spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags); - - pci_unregister_driver(&mana_driver); -} - static int __init mana_driver_init(void) { int err; diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c new file mode 100644 index 000000000000..4f6a77f55e5a --- /dev/null +++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c @@ -0,0 +1,909 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* Copyright (c) 2025, Microsoft Corporation. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +struct mana_dev_recovery { + struct list_head list; + struct pci_dev *pdev; + enum gdma_eqe_type type; +}; + +static struct mana_dev_recovery_work { + struct list_head dev_list; + struct delayed_work work; + + /* Lock for dev_list above */ + spinlock_t lock; +} mana_dev_recovery_work; + +static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state); +static int mana_gd_resume(struct pci_dev *pdev); + +#define MANA_SERVICE_PERIOD 10 + +static void mana_serv_rescan(struct pci_dev *pdev) +{ + struct pci_bus *parent; + + pci_lock_rescan_remove(); + + parent = pdev->bus; + if (!parent) { + dev_err(&pdev->dev, "MANA service: no parent bus\n"); + goto out; + } + + pci_stop_and_remove_bus_device(pdev); + pci_rescan_bus(parent); + +out: + pci_unlock_rescan_remove(); +} + +static void mana_serv_fpga(struct pci_dev *pdev) +{ + struct pci_bus *bus, *parent; + + pci_lock_rescan_remove(); + + bus = pdev->bus; + if (!bus) { + dev_err(&pdev->dev, "MANA service: no bus\n"); + goto out; + } + + parent = bus->parent; + if (!parent) { + dev_err(&pdev->dev, "MANA service: no parent bus\n"); + goto out; + } + + pci_stop_and_remove_bus_device(bus->self); + + msleep(MANA_SERVICE_PERIOD * 1000); + + pci_rescan_bus(parent); + +out: + pci_unlock_rescan_remove(); +} + +static void mana_serv_reset(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + struct hw_channel_context *hwc; + int ret; + + if (!gc) { + /* Perform PCI rescan on device if GC is not set up */ + dev_err(&pdev->dev, "MANA service: GC not setup, rescanning\n"); + mana_serv_rescan(pdev); + return; + } + + hwc = gc->hwc.driver_data; + if (!hwc) { + dev_err(&pdev->dev, "MANA service: no HWC\n"); + goto out; + } + + /* HWC is not responding in this case, so don't wait */ + hwc->hwc_timeout = 0; + + dev_info(&pdev->dev, "MANA reset cycle start\n"); + + mana_gd_suspend(pdev, PMSG_SUSPEND); + + msleep(MANA_SERVICE_PERIOD * 1000); + + ret = mana_gd_resume(pdev); + if (ret == -ETIMEDOUT || ret == -EPROTO) { + /* Perform PCI rescan on device if we failed on HWC */ + dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n"); + mana_serv_rescan(pdev); + return; + } + + if (ret) + dev_info(&pdev->dev, "MANA reset cycle failed err %d\n", ret); + else + dev_info(&pdev->dev, "MANA reset cycle completed\n"); + +out: + clear_bit(GC_IN_SERVICE, &gc->flags); +} + +static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev) +{ + switch (type) { + case GDMA_EQE_HWC_FPGA_RECONFIG: + mana_serv_fpga(pdev); + break; + + case GDMA_EQE_HWC_RESET_REQUEST: + mana_serv_reset(pdev); + break; + + default: + dev_err(&pdev->dev, "MANA service: unknown type %d\n", type); + break; + } +} + +static void mana_recovery_delayed_func(struct work_struct *w) +{ + struct mana_dev_recovery_work *work; + struct mana_dev_recovery *dev; + unsigned long flags; + + work = container_of(w, struct mana_dev_recovery_work, work.work); + + spin_lock_irqsave(&work->lock, flags); + + while (!list_empty(&work->dev_list)) { + dev = list_first_entry(&work->dev_list, + struct mana_dev_recovery, list); + list_del(&dev->list); + spin_unlock_irqrestore(&work->lock, flags); + + mana_do_service(dev->type, dev->pdev); + pci_dev_put(dev->pdev); + kfree(dev); + + spin_lock_irqsave(&work->lock, flags); + } + + spin_unlock_irqrestore(&work->lock, flags); +} + +static void mana_serv_func(struct work_struct *w) +{ + struct mana_serv_work *mns_wk; + struct pci_dev *pdev; + + mns_wk = container_of(w, struct mana_serv_work, serv_work); + pdev = mns_wk->pdev; + + if (pdev) + mana_do_service(mns_wk->type, pdev); + + pci_dev_put(pdev); + kfree(mns_wk); + module_put(THIS_MODULE); +} + +static int mana_pci_schedule_serv_work(struct gdma_context *gc, + enum gdma_eqe_type type) +{ + struct mana_serv_work *mns_wk; + + if (test_and_set_bit(GC_IN_SERVICE, &gc->flags)) { + dev_info(gc->dev, "Already in service\n"); + return -EBUSY; + } + + if (!try_module_get(THIS_MODULE)) { + dev_info(gc->dev, "Module is unloading\n"); + clear_bit(GC_IN_SERVICE, &gc->flags); + return -ENODEV; + } + + mns_wk = kzalloc(sizeof(*mns_wk), GFP_ATOMIC); + if (!mns_wk) { + module_put(THIS_MODULE); + clear_bit(GC_IN_SERVICE, &gc->flags); + return -ENOMEM; + } + + dev_info(gc->dev, "Start MANA service type:%d\n", type); + mns_wk->pdev = to_pci_dev(gc->dev); + mns_wk->type = type; + pci_dev_get(mns_wk->pdev); + INIT_WORK(&mns_wk->serv_work, mana_serv_func); + schedule_work(&mns_wk->serv_work); + return 0; +} + +static bool mana_pci_msix_can_alloc_dyn(struct gdma_context *gc) +{ + return pci_msix_can_alloc_dyn(to_pci_dev(gc->dev)); +} + +static int mana_pci_msix_virq(struct gdma_context *gc, int msi) +{ + return pci_irq_vector(to_pci_dev(gc->dev), msi); +} + +static int mana_pci_msix_alloc_at(struct gdma_context *gc, int *msi) +{ + struct msi_map irq_map; + + irq_map = pci_msix_alloc_irq_at(to_pci_dev(gc->dev), *msi, NULL); + if (!irq_map.virq) + return irq_map.index; + + *msi = irq_map.index; + return irq_map.virq; +} + +static void mana_pci_msix_free(struct gdma_context *gc, int msi, int irq) +{ + struct msi_map irq_map = { .virq = irq, .index = msi }; + + pci_msix_free_irq(to_pci_dev(gc->dev), irq_map); +} + +static int mana_pci_msix_vec_count(struct gdma_context *gc) +{ + return pci_msix_vec_count(to_pci_dev(gc->dev)); +} + +static int mana_pci_dev_reset(struct gdma_context *gc) +{ + return pcie_flr(to_pci_dev(gc->dev)); +} + +/* + * Spread on CPUs with the following heuristics: + * + * 1. No more than one IRQ per CPU, if possible; + * 2. NUMA locality is the second priority; + * 3. Sibling dislocality is the last priority. + * + * Let's consider this topology: + * + * Node 0 1 + * Core 0 1 2 3 + * CPU 0 1 2 3 4 5 6 7 + * + * The most performant IRQ distribution based on the above topology + * and heuristics may look like this: + * + * IRQ Nodes Cores CPUs + * 0 1 0 0-1 + * 1 1 1 2-3 + * 2 1 0 0-1 + * 3 1 1 2-3 + * 4 2 2 4-5 + * 5 2 3 6-7 + * 6 2 2 4-5 + * 7 2 3 6-7 + * + * The heuristics is implemented as follows. + * + * The outer for_each() loop resets the 'weight' to the actual number + * of CPUs in the hop. Then inner for_each() loop decrements it by the + * number of sibling groups (cores) while assigning first set of IRQs + * to each group. IRQs 0 and 1 above are distributed this way. + * + * Now, because NUMA locality is more important, we should walk the + * same set of siblings and assign 2nd set of IRQs (2 and 3), and it's + * implemented by the medium while() loop. We do like this unless the + * number of IRQs assigned on this hop will not become equal to number + * of CPUs in the hop (weight == 0). Then we switch to the next hop and + * do the same thing. + */ + +static int mana_irq_setup_numa_aware(unsigned int *irqs, unsigned int len, + int node, bool skip_first_cpu) +{ + const struct cpumask *next, *prev = cpu_none_mask; + cpumask_var_t cpus __free(free_cpumask_var); + int cpu, weight; + + if (!alloc_cpumask_var(&cpus, GFP_KERNEL)) + return -ENOMEM; + + rcu_read_lock(); + for_each_numa_hop_mask(next, node) { + weight = cpumask_weight_andnot(next, prev); + while (weight > 0) { + cpumask_andnot(cpus, next, prev); + for_each_cpu(cpu, cpus) { + cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu)); + --weight; + + if (unlikely(skip_first_cpu)) { + skip_first_cpu = false; + continue; + } + + if (len-- == 0) + goto done; + + irq_set_affinity_and_hint(*irqs++, topology_sibling_cpumask(cpu)); + } + } + prev = next; + } +done: + rcu_read_unlock(); + return 0; +} + +/* must be called with cpus_read_lock() held */ +static void mana_irq_setup_linear(unsigned int *irqs, unsigned int len) +{ + int cpu; + + for_each_online_cpu(cpu) { + if (len == 0) + break; + + irq_set_affinity_and_hint(*irqs++, cpumask_of(cpu)); + len--; + } +} + +static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + struct gdma_irq_context *gic; + int *irqs, err, i, msi; + + irqs = kmalloc_objs(int, nvec); + if (!irqs) + return -ENOMEM; + + /* + * In this function, num_msix_usable = HWC IRQ + Queue IRQ. + * nvec is only Queue IRQ (HWC already setup). + * While processing the next pci irq vector, we start with index 1, + * as IRQ vector at index 0 is already processed for HWC. + * However, the population of irqs array starts with index 0, to be + * further used in mana_irq_setup_numa_aware() + */ + for (i = 1; i <= nvec; i++) { + msi = i; + gic = mana_gd_get_gic(gc, false, &msi); + if (IS_ERR(gic)) { + err = PTR_ERR(gic); + goto free_irq; + } + + irqs[i - 1] = gic->irq; + } + + /* + * When calling mana_irq_setup_numa_aware() for dynamically added IRQs, + * if number of CPUs is more than or equal to allocated MSI-X, we need to + * skip the first CPU sibling group since they are already affinitized to + * HWC IRQ + */ + cpus_read_lock(); + if (gc->num_msix_usable <= num_online_cpus()) { + err = mana_irq_setup_numa_aware(irqs, nvec, gc->numa_node, + true); + if (err) { + cpus_read_unlock(); + goto free_irq; + } + } else { + /* + * When num_msix_usable are more than num_online_cpus, our + * queue IRQs should be equal to num of online vCPUs. + * We try to make sure queue IRQs spread across all vCPUs. + * In such a case NUMA or CPU core affinity does not matter. + * Note: in this case the total mana IRQ should always be + * num_online_cpus + 1. The first HWC IRQ is already handled + * in HWC setup calls + * However, if CPUs went offline since num_msix_usable was + * computed, queue IRQs will be more than num_online_cpus(). + * In such cases remaining extra IRQs will retain their default + * affinity. + */ + int first_unassigned = num_online_cpus(); + + if (nvec > first_unassigned) { + char buf[32]; + + if (first_unassigned == nvec - 1) + snprintf(buf, sizeof(buf), "%d", + first_unassigned); + else + snprintf(buf, sizeof(buf), "%d-%d", + first_unassigned, nvec - 1); + + dev_dbg(&pdev->dev, + "MANA IRQ indices #%s will retain the default CPU affinity\n", + buf); + } + + mana_irq_setup_linear(irqs, nvec); + } + + cpus_read_unlock(); + kfree(irqs); + return 0; + +free_irq: + for (i -= 1; i > 0; i--) + mana_gd_put_gic(gc, false, i); + kfree(irqs); + return err; +} + +static int mana_gd_setup_irqs(struct pci_dev *pdev, int nvec) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + struct gdma_irq_context *gic; + int *irqs, *start_irqs; + unsigned int cpu; + int err, i, msi; + + irqs = kmalloc_objs(int, nvec); + if (!irqs) + return -ENOMEM; + + start_irqs = irqs; + + for (i = 0; i < nvec; i++) { + msi = i; + gic = mana_gd_get_gic(gc, false, &msi); + if (IS_ERR(gic)) { + err = PTR_ERR(gic); + goto free_irq; + } + + irqs[i] = gic->irq; + } + + /* If number of IRQ is one extra than number of online CPUs, + * then we need to assign IRQ0 (hwc irq) and IRQ1 to + * same CPU. + * Else we will use different CPUs for IRQ0 and IRQ1. + * Also we are using cpumask_local_spread instead of + * cpumask_first for the node, because the node can be + * mem only. + */ + cpus_read_lock(); + if (nvec > num_online_cpus()) { + cpu = cpumask_local_spread(0, gc->numa_node); + irq_set_affinity_and_hint(irqs[0], cpumask_of(cpu)); + irqs++; + nvec -= 1; + } + + err = mana_irq_setup_numa_aware(irqs, nvec, gc->numa_node, false); + if (err) { + cpus_read_unlock(); + goto free_irq; + } + + cpus_read_unlock(); + kfree(start_irqs); + return 0; + +free_irq: + for (i -= 1; i >= 0; i--) + mana_gd_put_gic(gc, false, i); + + kfree(start_irqs); + return err; +} + +static int mana_gd_setup_hwc_irqs(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + unsigned int max_irqs, min_irqs; + int nvec, err; + + if (pci_msix_can_alloc_dyn(pdev)) { + max_irqs = 1; + min_irqs = 1; + } else { + /* Need 1 interrupt for HWC */ + max_irqs = min(num_online_cpus(), MANA_MAX_NUM_QUEUES) + 1; + min_irqs = 2; + gc->msi_sharing = true; + } + + nvec = pci_alloc_irq_vectors(pdev, min_irqs, max_irqs, PCI_IRQ_MSIX); + if (nvec < 0) + return nvec; + + err = mana_gd_setup_irqs(pdev, nvec); + if (err) { + pci_free_irq_vectors(pdev); + return err; + } + + gc->num_msix_usable = nvec; + gc->max_num_msix = nvec; + + return 0; +} + +static int mana_gd_setup_remaining_irqs(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + struct msi_map irq_map; + int max_irqs, i, err; + + if (!pci_msix_can_alloc_dyn(pdev)) + /* remain irqs are already allocated with HWC IRQ */ + return 0; + + /* allocate only remaining IRQs*/ + max_irqs = gc->num_msix_usable - 1; + + for (i = 1; i <= max_irqs; i++) { + irq_map = pci_msix_alloc_irq_at(pdev, i, NULL); + if (!irq_map.virq) { + err = irq_map.index; + /* caller will handle cleaning up all allocated + * irqs, after HWC is destroyed + */ + return err; + } + } + + err = mana_gd_setup_dyn_irqs(pdev, max_irqs); + if (err) + return err; + + gc->max_num_msix = gc->max_num_msix + max_irqs; + + return 0; +} + +static void mana_gd_remove_irqs(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + int i; + + if (gc->max_num_msix < 1) + return; + + for (i = 0; i < gc->max_num_msix; i++) { + if (!xa_load(&gc->irq_contexts, i)) + continue; + + mana_gd_put_gic(gc, false, i); + } + + WARN_ON(!xa_empty(&gc->irq_contexts)); + + pci_free_irq_vectors(pdev); + + bitmap_free(gc->msi_bitmap); + gc->msi_bitmap = NULL; + gc->max_num_msix = 0; + gc->num_msix_usable = 0; +} + +static int mana_pci_setup_hwc_irqs(struct gdma_context *gc) +{ + return mana_gd_setup_hwc_irqs(to_pci_dev(gc->dev)); +} + +static int mana_pci_setup_remaining_irqs(struct gdma_context *gc) +{ + int err; + + err = mana_gd_setup_remaining_irqs(to_pci_dev(gc->dev)); + if (err) { + dev_err(gc->dev, "Failed to setup remaining IRQs: %d", err); + return err; + } + + if (!gc->msi_sharing) { + gc->msi_bitmap = bitmap_zalloc(gc->num_msix_usable, GFP_KERNEL); + if (!gc->msi_bitmap) + return -ENOMEM; + /* Set bit for HWC */ + set_bit(0, gc->msi_bitmap); + } + + return 0; +} + +static void mana_pci_remove_irqs(struct gdma_context *gc) +{ + mana_gd_remove_irqs(to_pci_dev(gc->dev)); +} + +static const struct gdma_bus_ops mana_pci_bus_ops = { + .bus_name = "pci", + .msix_can_alloc_dyn = mana_pci_msix_can_alloc_dyn, + .msix_virq = mana_pci_msix_virq, + .msix_alloc_at = mana_pci_msix_alloc_at, + .msix_free = mana_pci_msix_free, + .msix_vec_count = mana_pci_msix_vec_count, + .setup_hwc_irqs = mana_pci_setup_hwc_irqs, + .setup_remaining_irqs = mana_pci_setup_remaining_irqs, + .remove_irqs = mana_pci_remove_irqs, + .dev_reset = mana_pci_dev_reset, + .schedule_serv_work = mana_pci_schedule_serv_work, + .drv_cap_flags1 = GDMA_DRV_CAP_FLAGS1_PCI, +}; + +static bool mana_is_pf(unsigned short dev_id) +{ + return dev_id == MANA_PF_DEVICE_ID || dev_id == MANA_PF2_DEVICE_ID; +} + +static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +{ + struct gdma_context *gc; + void __iomem *bar0_va; + int bar = 0; + int err; + + /* Each port has 2 CQs, each CQ has at most 1 EQE at a time */ + BUILD_BUG_ON(2 * MAX_PORTS_IN_MANA_DEV * GDMA_EQE_SIZE > EQ_SIZE); + + err = pci_enable_device(pdev); + if (err) { + dev_err(&pdev->dev, "Failed to enable pci device (err=%d)\n", err); + return -ENXIO; + } + + pci_set_master(pdev); + + err = pci_request_regions(pdev, "mana"); + if (err) + goto disable_dev; + + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (err) { + dev_err(&pdev->dev, "DMA set mask failed: %d\n", err); + goto release_region; + } + dma_set_max_seg_size(&pdev->dev, UINT_MAX); + + err = -ENOMEM; + gc = vzalloc(sizeof(*gc)); + if (!gc) + goto release_region; + + mutex_init(&gc->eq_test_event_mutex); + mutex_init(&gc->gic_mutex); + pci_set_drvdata(pdev, gc); + gc->bar0_pa = pci_resource_start(pdev, 0); + gc->bar0_size = pci_resource_len(pdev, 0); + + bar0_va = pci_iomap(pdev, bar, 0); + if (!bar0_va) + goto free_gc; + + gc->numa_node = dev_to_node(&pdev->dev); + gc->is_pf = mana_is_pf(pdev->device); + gc->is_pf2 = (pdev->device == MANA_PF2_DEVICE_ID); + + gc->bar0_va = bar0_va; + gc->dev = &pdev->dev; + gc->bus_ops = &mana_pci_bus_ops; + xa_init(&gc->irq_contexts); + + err = mana_gd_setup(gc); + if (err) + goto unmap_bar; + + err = mana_probe(&gc->mana, false); + if (err) + goto cleanup_gd; + + err = mana_rdma_probe(&gc->mana_ib); + if (err) + goto cleanup_mana; + + /* + * If a hardware reset event has occurred over HWC during probe, + * rollback and perform hardware reset procedure. + */ + if (test_and_set_bit(GC_PROBE_SUCCEEDED, &gc->flags)) { + err = -EPROTO; + goto cleanup_mana_rdma; + } + + return 0; + +cleanup_mana_rdma: + mana_rdma_remove(&gc->mana_ib); +cleanup_mana: + mana_remove(&gc->mana, false); +cleanup_gd: + mana_gd_cleanup(gc); +unmap_bar: + xa_destroy(&gc->irq_contexts); + pci_iounmap(pdev, bar0_va); +free_gc: + pci_set_drvdata(pdev, NULL); + vfree(gc); +release_region: + pci_release_regions(pdev); +disable_dev: + pci_disable_device(pdev); + dev_err(&pdev->dev, "gdma probe failed: err = %d\n", err); + + /* + * Hardware could be in recovery mode and the HWC returns TIMEDOUT or + * EPROTO from mana_gd_setup(), mana_probe() or mana_rdma_probe(), or + * we received a hardware reset event over HWC interrupt. In this case, + * perform the device recovery procedure after MANA_SERVICE_PERIOD + * seconds. + */ + if (err == -ETIMEDOUT || err == -EPROTO) { + struct mana_dev_recovery *dev; + unsigned long flags; + + dev_info(&pdev->dev, "Start MANA recovery mode\n"); + + dev = kzalloc_obj(*dev); + if (!dev) + return err; + + dev->pdev = pci_dev_get(pdev); + dev->type = GDMA_EQE_HWC_RESET_REQUEST; + + spin_lock_irqsave(&mana_dev_recovery_work.lock, flags); + list_add_tail(&dev->list, &mana_dev_recovery_work.dev_list); + spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags); + + schedule_delayed_work(&mana_dev_recovery_work.work, + secs_to_jiffies(MANA_SERVICE_PERIOD)); + } + + return err; +} + +static void mana_gd_remove(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + + pci_disable_sriov(pdev); + + mana_rdma_remove(&gc->mana_ib); + mana_remove(&gc->mana, false); + + mana_gd_cleanup(gc); + + xa_destroy(&gc->irq_contexts); + + pci_iounmap(pdev, gc->bar0_va); + + vfree(gc); + + pci_release_regions(pdev); + pci_disable_device(pdev); + + dev_dbg(&pdev->dev, "mana gdma remove successful\n"); +} + +/* The 'state' parameter is not used. */ +static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + + mana_rdma_remove(&gc->mana_ib); + mana_remove(&gc->mana, true); + + mana_gd_cleanup(gc); + + return 0; +} + +static int mana_gd_resume(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + int err; + + err = mana_gd_setup(gc); + if (err) + return err; + + err = mana_probe(&gc->mana, true); + if (err) + goto cleanup_gd; + + err = mana_rdma_probe(&gc->mana_ib); + if (err) + mana_rdma_remove(&gc->mana_ib); + + return err; + +cleanup_gd: + mana_gd_cleanup(gc); + return err; +} + +/* Quiesce the device for kexec. This is also called upon reboot/shutdown. */ +static void mana_gd_shutdown(struct pci_dev *pdev) +{ + struct gdma_context *gc = pci_get_drvdata(pdev); + + dev_info(&pdev->dev, "Shutdown was called\n"); + + mana_rdma_remove(&gc->mana_ib); + mana_remove(&gc->mana, true); + + mana_gd_cleanup(gc); + + pci_disable_device(pdev); +} + +static int mana_sriov_configure(struct pci_dev *pdev, int numvfs) +{ + int err = 0; + + dev_info(&pdev->dev, "Requested num VFs: %d\n", numvfs); + + if (numvfs > 0) { + err = pci_enable_sriov(pdev, numvfs); + } else { + if (pci_vfs_assigned(pdev)) { + dev_warn(&pdev->dev, + "Cannot disable SR-IOV while VFs are assigned\n"); + return -EPERM; + } + + pci_disable_sriov(pdev); + } + + return err ? err : numvfs; +} + +static const struct pci_device_id mana_id_table[] = { + { PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_PF_DEVICE_ID) }, + { PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_PF2_DEVICE_ID) }, + { PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_VF_DEVICE_ID) }, + { } +}; + +static struct pci_driver mana_driver = { + .name = "mana", + .id_table = mana_id_table, + .probe = mana_gd_probe, + .remove = mana_gd_remove, + .suspend = mana_gd_suspend, + .resume = mana_gd_resume, + .shutdown = mana_gd_shutdown, + .sriov_configure = mana_sriov_configure, +}; + +MODULE_DEVICE_TABLE(pci, mana_id_table); + +int mana_pci_driver_register(void) +{ + INIT_LIST_HEAD(&mana_dev_recovery_work.dev_list); + spin_lock_init(&mana_dev_recovery_work.lock); + INIT_DELAYED_WORK(&mana_dev_recovery_work.work, + mana_recovery_delayed_func); + + return pci_register_driver(&mana_driver); +} + +void mana_pci_driver_unregister(void) +{ + struct mana_dev_recovery *dev; + unsigned long flags; + + disable_delayed_work_sync(&mana_dev_recovery_work.work); + + spin_lock_irqsave(&mana_dev_recovery_work.lock, flags); + while (!list_empty(&mana_dev_recovery_work.dev_list)) { + dev = list_first_entry(&mana_dev_recovery_work.dev_list, + struct mana_dev_recovery, list); + list_del(&dev->list); + pci_dev_put(dev->pdev); + kfree(dev); + } + spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags); + + pci_unregister_driver(&mana_driver); +} diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index cdec5558304f..238ff8b9f067 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -1175,4 +1175,7 @@ int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver, u16 *max_num_vports, u8 *bm_hostmode); int mana_gd_dev_reset(struct gdma_context *gc); +int mana_pci_driver_register(void); +void mana_pci_driver_unregister(void); + #endif /* _GDMA_H */ From 445927de07cdee3ffa58cb00a17e8c2a682f3a1b Mon Sep 17 00:00:00 2001 From: Manish Awasthi Date: Thu, 24 Sep 2026 17:30:53 +0000 Subject: [PATCH 0994/2126] net: mana: Build the PCI transport as a separate module Build the shared GDMA and Ethernet code as gdma_core.ko, selected by MICROSOFT_GDMA_CORE. Build the PCI transport separately as mana.ko and export the required core symbols. Preserve the PCI module name, device table, and mana.eth/mana.rdma auxiliary-device names. Each transport registers its own bus driver. Signed-off-by: Manish Awasthi Reviewed-by: Simon Horman Reviewed-by: Haiyang Zhang Link: https://patch.msgid.link/20260924173054.589291-4-mawasthi@linux.microsoft.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microsoft/Kconfig | 12 ++++++--- drivers/net/ethernet/microsoft/Makefile | 2 +- drivers/net/ethernet/microsoft/mana/Makefile | 7 ++++-- .../net/ethernet/microsoft/mana/gdma_main.c | 25 ++++++------------- .../net/ethernet/microsoft/mana/gdma_pci.c | 11 ++++++-- drivers/net/ethernet/microsoft/mana/mana_en.c | 7 +++++- include/net/mana/gdma.h | 3 --- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/microsoft/Kconfig b/drivers/net/ethernet/microsoft/Kconfig index e9be18c92ca5..ee5bc1c1bf59 100644 --- a/drivers/net/ethernet/microsoft/Kconfig +++ b/drivers/net/ethernet/microsoft/Kconfig @@ -15,15 +15,19 @@ config NET_VENDOR_MICROSOFT if NET_VENDOR_MICROSOFT +config MICROSOFT_GDMA_CORE + tristate + select AUXILIARY_BUS + select DIMLIB + select PAGE_POOL + select NET_SHAPER + config MICROSOFT_MANA tristate "Microsoft Azure Network Adapter (MANA) support" depends on PCI_MSI depends on X86_64 || (ARM64 && !CPU_BIG_ENDIAN) depends on PCI_HYPERV - select AUXILIARY_BUS - select DIMLIB - select PAGE_POOL - select NET_SHAPER + select MICROSOFT_GDMA_CORE help This driver supports Microsoft Azure Network Adapter (MANA). So far, the driver is only supported on X86_64. diff --git a/drivers/net/ethernet/microsoft/Makefile b/drivers/net/ethernet/microsoft/Makefile index d2ddc218135f..c3b6dafdf473 100644 --- a/drivers/net/ethernet/microsoft/Makefile +++ b/drivers/net/ethernet/microsoft/Makefile @@ -2,4 +2,4 @@ # Makefile for the Microsoft Azure network device driver. # -obj-$(CONFIG_MICROSOFT_MANA) += mana/ +obj-$(CONFIG_MICROSOFT_GDMA_CORE) += mana/ diff --git a/drivers/net/ethernet/microsoft/mana/Makefile b/drivers/net/ethernet/microsoft/mana/Makefile index 6705bf65c92c..72c03fb6e441 100644 --- a/drivers/net/ethernet/microsoft/mana/Makefile +++ b/drivers/net/ethernet/microsoft/mana/Makefile @@ -2,6 +2,9 @@ # # Makefile for the Microsoft Azure Network Adapter driver +obj-$(CONFIG_MICROSOFT_GDMA_CORE) += gdma_core.o +gdma_core-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o \ + mana_bpf.o + obj-$(CONFIG_MICROSOFT_MANA) += mana.o -mana-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o mana_bpf.o \ - gdma_pci.o +mana-y := gdma_pci.o diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index 531170e58a62..ae0ed700b3b9 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -1991,6 +1991,7 @@ remove_debugfs: dev_err(gc->dev, "%s failed (error %d)\n", __func__, err); return err; } +EXPORT_SYMBOL_NS(mana_gd_setup, "NET_MANA"); void mana_gd_cleanup(struct gdma_context *gc) { @@ -2005,36 +2006,24 @@ void mana_gd_cleanup(struct gdma_context *gc) dev_dbg(gc->dev, "mana gdma cleanup successful\n"); } +EXPORT_SYMBOL_NS(mana_gd_cleanup, "NET_MANA"); -static int __init mana_driver_init(void) +static int __init gdma_core_init(void) { - int err; - mana_debugfs_root = debugfs_create_dir("mana", NULL); - err = mana_pci_driver_register(); - if (err) - goto err_debugfs; - return 0; - -err_debugfs: - debugfs_remove(mana_debugfs_root); - mana_debugfs_root = NULL; - return err; } -static void __exit mana_driver_exit(void) +static void __exit gdma_core_exit(void) { - mana_pci_driver_unregister(); - debugfs_remove(mana_debugfs_root); mana_debugfs_root = NULL; } -module_init(mana_driver_init); -module_exit(mana_driver_exit); +module_init(gdma_core_init); +module_exit(gdma_core_exit); MODULE_LICENSE("Dual BSD/GPL"); -MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver"); +MODULE_DESCRIPTION("Microsoft Azure Network Adapter GDMA core"); diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c index 4f6a77f55e5a..92a1e66e18b7 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c @@ -878,7 +878,7 @@ static struct pci_driver mana_driver = { MODULE_DEVICE_TABLE(pci, mana_id_table); -int mana_pci_driver_register(void) +static int __init mana_driver_init(void) { INIT_LIST_HEAD(&mana_dev_recovery_work.dev_list); spin_lock_init(&mana_dev_recovery_work.lock); @@ -888,7 +888,7 @@ int mana_pci_driver_register(void) return pci_register_driver(&mana_driver); } -void mana_pci_driver_unregister(void) +static void __exit mana_driver_exit(void) { struct mana_dev_recovery *dev; unsigned long flags; @@ -907,3 +907,10 @@ void mana_pci_driver_unregister(void) pci_unregister_driver(&mana_driver); } + +module_init(mana_driver_init); +module_exit(mana_driver_exit); + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver"); +MODULE_IMPORT_NS("NET_MANA"); diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 62b89b3d6072..16a9d192c099 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -3957,7 +3957,8 @@ static int add_adev(struct gdma_dev *gd, const char *name) /* madev is owned by the auxiliary device */ madev = NULL; - ret = auxiliary_device_add(adev); + /* Keep the established mana.{eth,rdma} auxiliary match names. */ + ret = __auxiliary_device_add(adev, "mana"); if (ret) goto add_fail; @@ -4194,6 +4195,7 @@ out: return err; } +EXPORT_SYMBOL_NS(mana_probe, "NET_MANA"); void mana_remove(struct gdma_dev *gd, bool suspending) { @@ -4272,6 +4274,7 @@ void mana_remove(struct gdma_dev *gd, bool suspending) kfree(ac); dev_dbg(dev, "%s succeeded\n", __func__); } +EXPORT_SYMBOL_NS(mana_remove, "NET_MANA"); int mana_rdma_probe(struct gdma_dev *gd) { @@ -4307,6 +4310,7 @@ int mana_rdma_probe(struct gdma_dev *gd) return err; } +EXPORT_SYMBOL_NS(mana_rdma_probe, "NET_MANA"); void mana_rdma_remove(struct gdma_dev *gd) { @@ -4327,6 +4331,7 @@ void mana_rdma_remove(struct gdma_dev *gd) mana_gd_deregister_device(gd); } +EXPORT_SYMBOL_NS(mana_rdma_remove, "NET_MANA"); struct net_device *mana_get_primary_netdev(struct mana_context *ac, u32 port_index, diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 238ff8b9f067..cdec5558304f 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -1175,7 +1175,4 @@ int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver, u16 *max_num_vports, u8 *bm_hostmode); int mana_gd_dev_reset(struct gdma_context *gc); -int mana_pci_driver_register(void); -void mana_pci_driver_unregister(void); - #endif /* _GDMA_H */ From 3d6792ea46056816196bf72243903b216a2fb06f Mon Sep 17 00:00:00 2001 From: Manish Awasthi Date: Thu, 24 Sep 2026 17:30:54 +0000 Subject: [PATCH 0995/2126] net: mana: Add support for CDX device ID 0x00C2 Add the CDX transport as mana_cdx.ko for device ID 0x00C2, using the shared gdma_core.ko. Allocate interrupts at probe, limit queues to available vectors, use 32-bit DMA, and keep CDX auxiliary devices separate from PCI. Signed-off-by: Manish Awasthi Reviewed-by: Simon Horman Reviewed-by: Haiyang Zhang Link: https://patch.msgid.link/20260924173054.589291-5-mawasthi@linux.microsoft.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microsoft/Kconfig | 14 + drivers/net/ethernet/microsoft/mana/Makefile | 3 + .../net/ethernet/microsoft/mana/gdma_cdx.c | 340 ++++++++++++++++++ .../net/ethernet/microsoft/mana/gdma_pci.c | 1 + drivers/net/ethernet/microsoft/mana/mana_en.c | 5 +- include/net/mana/gdma.h | 4 + 6 files changed, 365 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/microsoft/mana/gdma_cdx.c diff --git a/drivers/net/ethernet/microsoft/Kconfig b/drivers/net/ethernet/microsoft/Kconfig index ee5bc1c1bf59..7e4b77f7f29c 100644 --- a/drivers/net/ethernet/microsoft/Kconfig +++ b/drivers/net/ethernet/microsoft/Kconfig @@ -35,4 +35,18 @@ config MICROSOFT_MANA To compile this driver as a module, choose M here. The module will be called mana. +config MICROSOFT_MANA_CDX + tristate "Microsoft Azure Network Adapter (MANA) support for the CDX bus" + depends on CDX_BUS + depends on GENERIC_MSI_IRQ + depends on 64BIT && !CPU_BIG_ENDIAN + select MICROSOFT_GDMA_CORE + help + This driver supports the Microsoft Azure Network Adapter (MANA) on + systems where it is integrated into the SoC and presented on the CDX + bus rather than discovered over PCI. + + To compile this driver as a module, choose M here. + The module will be called mana_cdx. + endif #NET_VENDOR_MICROSOFT diff --git a/drivers/net/ethernet/microsoft/mana/Makefile b/drivers/net/ethernet/microsoft/mana/Makefile index 72c03fb6e441..64926015f734 100644 --- a/drivers/net/ethernet/microsoft/mana/Makefile +++ b/drivers/net/ethernet/microsoft/mana/Makefile @@ -8,3 +8,6 @@ gdma_core-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o \ obj-$(CONFIG_MICROSOFT_MANA) += mana.o mana-y := gdma_pci.o + +obj-$(CONFIG_MICROSOFT_MANA_CDX) += mana_cdx.o +mana_cdx-y := gdma_cdx.o diff --git a/drivers/net/ethernet/microsoft/mana/gdma_cdx.c b/drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file mode 100644 index 000000000000..0d01e3d2f0d9 --- /dev/null +++ b/drivers/net/ethernet/microsoft/mana/gdma_cdx.c @@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* Copyright (c) 2025, Microsoft Corporation. */ +#include +#include +#include +#include +#include + +#include + +#define MANA_CDX_GDMA_REGS_SIZE (GDMA_REG_SHM_OFFSET + sizeof(u64)) + +static int mana_cdx_msix_virq(struct gdma_context *gc, int msi) +{ + unsigned int virq = msi_get_virq(gc->dev, msi); + + /* CDX allocates its whole vector pool in mana_cdx_setup_hwc_irqs(), + * so a vector with no Linux IRQ was never part of that pool. + */ + return virq ? virq : -EINVAL; +} + +static int mana_cdx_dev_reset(struct gdma_context *gc) +{ + return cdx_dev_reset(gc->dev); +} + +static int mana_cdx_setup_hwc_irqs(struct gdma_context *gc) +{ + struct cdx_device *cdx_dev = to_cdx_device(gc->dev); + struct gdma_irq_context *gic; + unsigned int max_irqs; + int nvec; + int err, i = 0, j; + + max_irqs = cdx_dev->num_msi; + + /* Need 1 IRQ for HWC and at least 1 for the data path queues */ + if (max_irqs < 2) { + dev_err(&cdx_dev->dev, "Not enough MSI vectors: %u\n", + max_irqs); + return -ENOSPC; + } + + /* Constrain the device to 32-bit DMA addresses, for both the MSI + * doorbells and the data path buffers, and never widen it afterwards. + * + * The MSI doorbell address has to land within the low 4GB. The data + * path carries a second constraint: the device does not perform + * writes to the final page of the 48-bit IOVA window, and + * iommu_dma_alloc_iova() allocates downwards from the top of that + * window, so the first queue created lands on the unusable page and + * its event queue stalls permanently. PCI devices are shielded from + * this by the low-4GB first attempt in iommu_dma_alloc_iova(), but + * that attempt is gated on dev_is_pci() and CDX devices do not + * qualify. + */ + err = dma_set_mask_and_coherent(gc->dev, DMA_BIT_MASK(32)); + if (err) { + dev_err(&cdx_dev->dev, "Failed to set 32-bit DMA mask\n"); + return err; + } + + /* The PCI path also calls dma_set_max_seg_size(), but that is + * deliberately omitted here: the CDX core does not attach a + * dma_parms to the device, so the helper would only WARN, and MANA + * never builds scatter-gather lists, so the limit is never read. + */ + + err = cdx_enable_msi(cdx_dev); + if (err) { + dev_err(&cdx_dev->dev, "Failed to enable MSI\n"); + return err; + } + + err = msi_domain_alloc_irqs(gc->dev, MSI_DEFAULT_DOMAIN, max_irqs); + if (err) { + dev_err(&cdx_dev->dev, "Failed to alloc MSI IRQs\n"); + cdx_disable_msi(cdx_dev); + return err; + } + + nvec = max_irqs; + + xa_init(&gc->irq_contexts); + + /* No IRQ affinity hint is applied here. The PCI transport spreads its + * vectors over the NUMA node local to the device; the CDX platforms + * this driver targets are single-node, so there is nothing to spread + * over. Affinity management can be added when a multi-node CDX host + * exists to validate it against. + */ + for (i = 0; i < nvec; i++) { + int msi = i; + + gic = mana_gd_get_gic(gc, false, &msi); + if (IS_ERR(gic)) { + err = PTR_ERR(gic); + goto free_irq; + } + } + + gc->max_num_msix = nvec; + gc->num_msix_usable = nvec; + + /* CDX sizes its MSI pool at probe time and cannot grow it later, so + * never share vectors: vector 0 is reserved for the HWC and each of + * the remaining nvec - 1 vectors backs exactly one EQ. That bounds + * the queue count at nvec - 1 and guarantees the HWC vector is never + * handed out to a data queue. + */ + gc->msi_sharing = false; + + gc->msi_bitmap = bitmap_zalloc(nvec, GFP_KERNEL); + if (!gc->msi_bitmap) { + err = -ENOMEM; + goto free_irq; + } + + /* Reserve the HWC vector */ + set_bit(0, gc->msi_bitmap); + + return 0; + +free_irq: + for (j = i - 1; j >= 0; j--) + mana_gd_put_gic(gc, false, j); + + xa_destroy(&gc->irq_contexts); + msi_domain_free_irqs_all(gc->dev, MSI_DEFAULT_DOMAIN); + cdx_disable_msi(cdx_dev); + return err; +} + +static void mana_cdx_remove_irqs(struct gdma_context *gc) +{ + struct cdx_device *cdx_dev = to_cdx_device(gc->dev); + int i; + + if (gc->max_num_msix < 1) + return; + + for (i = 0; i < gc->max_num_msix; i++) { + if (!xa_load(&gc->irq_contexts, i)) + continue; + + mana_gd_put_gic(gc, false, i); + } + + WARN_ON(!xa_empty(&gc->irq_contexts)); + + xa_destroy(&gc->irq_contexts); + msi_domain_free_irqs_all(gc->dev, MSI_DEFAULT_DOMAIN); + cdx_disable_msi(cdx_dev); + + bitmap_free(gc->msi_bitmap); + gc->msi_bitmap = NULL; + gc->max_num_msix = 0; + gc->num_msix_usable = 0; +} + +static int mana_cdx_setup_remaining_irqs(struct gdma_context *gc) +{ + unsigned int max_queues_vport; + + /* mana_gd_query_max_resources() may turn MSI sharing back on and round + * the per-vPort queue count up to MANA_DEF_NUM_QUEUES. CDX sizes its + * vector pool at probe time and cannot grow it later, and the HWC + * vector must stay private, so give every vPort a private slice of the + * remaining vectors instead. gc->max_num_queues is already capped at + * num_msix_usable - 1 by the core. + */ + gc->msi_sharing = false; + max_queues_vport = (gc->num_msix_usable - 1) / gc->num_ports; + if (!max_queues_vport) { + dev_err(gc->dev, "%u MSI vectors cannot serve %u vPorts\n", + gc->num_msix_usable, gc->num_ports); + return -ENOSPC; + } + + gc->max_num_queues_vport = min(gc->max_num_queues, max_queues_vport); + + dev_dbg(gc->dev, "%u MSI vectors, %u vPorts, %u queues, no MSI sharing\n", + gc->num_msix_usable, gc->num_ports, gc->max_num_queues_vport); + + return 0; +} + +static const struct gdma_bus_ops mana_cdx_bus_ops = { + .bus_name = "cdx", + .adev_prefix = "mana_cdx", + .msix_virq = mana_cdx_msix_virq, + .setup_hwc_irqs = mana_cdx_setup_hwc_irqs, + .setup_remaining_irqs = mana_cdx_setup_remaining_irqs, + .remove_irqs = mana_cdx_remove_irqs, + .dev_reset = mana_cdx_dev_reset, +}; + +static int mana_cdx_gd_probe(struct cdx_device *cdx_dev) +{ + struct gdma_context *gc; + void __iomem *bar0_va; + int err; + + /* Each port has 2 CQs, each CQ has at most 1 EQE at a time */ + BUILD_BUG_ON(2 * MAX_PORTS_IN_MANA_DEV * GDMA_EQE_SIZE > EQ_SIZE); + + err = cdx_dev_reset(&cdx_dev->dev); + if (err) + return err; + + err = cdx_set_master(cdx_dev); + if (err) + return err; + + gc = vzalloc(sizeof(*gc)); + if (!gc) { + err = -ENOMEM; + goto clear_master; + } + + mutex_init(&gc->eq_test_event_mutex); + mutex_init(&gc->gic_mutex); + dev_set_drvdata(&cdx_dev->dev, gc); + gc->bar0_pa = cdx_resource_start(cdx_dev, 0); + gc->bar0_size = cdx_resource_len(cdx_dev, 0); + if (gc->bar0_size < MANA_CDX_GDMA_REGS_SIZE) { + dev_err(&cdx_dev->dev, "BAR0 size %#llx is too small\n", + (u64)gc->bar0_size); + err = -EINVAL; + goto free_gc; + } + + bar0_va = ioremap(gc->bar0_pa, gc->bar0_size); + if (!bar0_va) { + err = -ENOMEM; + goto free_gc; + } + + gc->numa_node = dev_to_node(&cdx_dev->dev); + gc->bar0_va = bar0_va; + gc->dev = &cdx_dev->dev; + gc->bus_ops = &mana_cdx_bus_ops; + + /* gc->is_pf is intentionally left clear: this device uses the VF + * register layout, and the vPort and MAC filter registration that + * is_pf selects is not required on this bus. + */ + + err = mana_gd_setup(gc); + if (err) + goto unmap_bar; + + err = mana_probe(&gc->mana, false); + if (err) + goto cleanup_gd; + + err = mana_rdma_probe(&gc->mana_ib); + if (err) + goto remove_mana; + + /* If a hardware reset event arrived over HWC during probe, roll back: + * the device state the rest of probe observed is no longer valid. + */ + if (test_and_set_bit(GC_PROBE_SUCCEEDED, &gc->flags)) { + err = -EPROTO; + goto remove_rdma; + } + + return 0; + +remove_rdma: + mana_rdma_remove(&gc->mana_ib); +remove_mana: + mana_remove(&gc->mana, false); +cleanup_gd: + mana_gd_cleanup(gc); +unmap_bar: + iounmap(bar0_va); +free_gc: + dev_set_drvdata(&cdx_dev->dev, NULL); + vfree(gc); +clear_master: + cdx_clear_master(cdx_dev); + return err; +} + +static int mana_cdx_gd_remove(struct cdx_device *cdx_dev) +{ + struct gdma_context *gc = dev_get_drvdata(&cdx_dev->dev); + + mana_rdma_remove(&gc->mana_ib); + mana_remove(&gc->mana, false); + + mana_gd_cleanup(gc); + cdx_clear_master(cdx_dev); + + iounmap(gc->bar0_va); + + dev_set_drvdata(&cdx_dev->dev, NULL); + vfree(gc); + return 0; +} + +/* Quiesce the device for kexec. This is also called upon reboot/shutdown. */ +static void mana_cdx_gd_shutdown(struct cdx_device *cdx_dev) +{ + struct gdma_context *gc = dev_get_drvdata(&cdx_dev->dev); + + mana_rdma_remove(&gc->mana_ib); + mana_remove(&gc->mana, true); + + mana_gd_cleanup(gc); + cdx_clear_master(cdx_dev); +} + +#define CDX_VENDOR_ID_MICROSOFT 0x1414 +static const struct cdx_device_id mana_cdx_table[] = { + { CDX_DEVICE(CDX_VENDOR_ID_MICROSOFT, MANA_CDX_DEVICE_ID) }, + {} +}; + +MODULE_DEVICE_TABLE(cdx, mana_cdx_table); + +static struct cdx_driver gdma_cdx_driver = { + .match_id_table = mana_cdx_table, + .probe = mana_cdx_gd_probe, + .remove = mana_cdx_gd_remove, + .shutdown = mana_cdx_gd_shutdown, + .driver = { + .name = "mana_cdx", + }, +}; + +module_driver(gdma_cdx_driver, cdx_driver_register, cdx_driver_unregister); + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver for the CDX bus"); +MODULE_IMPORT_NS("CDX_BUS"); +MODULE_IMPORT_NS("NET_MANA"); diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c index 92a1e66e18b7..ed8925296c8a 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c @@ -619,6 +619,7 @@ static void mana_pci_remove_irqs(struct gdma_context *gc) static const struct gdma_bus_ops mana_pci_bus_ops = { .bus_name = "pci", + .adev_prefix = "mana", .msix_can_alloc_dyn = mana_pci_msix_can_alloc_dyn, .msix_virq = mana_pci_msix_virq, .msix_alloc_at = mana_pci_msix_alloc_at, diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 16a9d192c099..2ba48a1c4b15 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -3957,8 +3957,9 @@ static int add_adev(struct gdma_dev *gd, const char *name) /* madev is owned by the auxiliary device */ madev = NULL; - /* Keep the established mana.{eth,rdma} auxiliary match names. */ - ret = __auxiliary_device_add(adev, "mana"); + /* Keep match names independent of the common module's name. */ + ret = __auxiliary_device_add(adev, + gd->gdma_context->bus_ops->adev_prefix); if (ret) goto add_fail; diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index cdec5558304f..c610fc1067e0 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -432,6 +432,7 @@ struct gdma_context; * instance in gdma_context.bus_ops at probe time. * * @bus_name: Bus token used to build the per-vector IRQ names. + * @adev_prefix: Prefix used for auxiliary-device match names. * @msix_can_alloc_dyn: True if the bus can allocate MSI-X vectors after * probe time. Buses that size their vector pool at probe and cannot * grow it later leave this NULL. @@ -459,6 +460,7 @@ struct gdma_context; */ struct gdma_bus_ops { const char *bus_name; + const char *adev_prefix; bool (*msix_can_alloc_dyn)(struct gdma_context *gc); int (*msix_virq)(struct gdma_context *gc, int msi); int (*msix_alloc_at)(struct gdma_context *gc, int *msi); @@ -684,6 +686,8 @@ struct gdma_eqe { #define MANA_PF2_DEVICE_ID 0x00C1 #define MANA_VF_DEVICE_ID 0x00BA +#define MANA_CDX_DEVICE_ID 0x00C2 + struct gdma_posted_wqe_info { u32 wqe_size_in_bu; }; From 003f21868b2b0b4d09eb6b1f4abe0a8fbc03e859 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 28 Sep 2026 12:07:58 -0700 Subject: [PATCH 0996/2126] llc: move the type 2 sockets out of tree 802.2 LLC is only used in tree by protocols which need the connectionless type 1 subset: STP, which carries the bridge's BPDUs, GARP, which sends its own UI PDUs, and SNAP. The llc2 module on top of the core - the type 2 connection state machine, the type 1 SAP state machine, the station component and the PF_LLC socket family - has no in-kernel users and nobody who can test it; what we get instead is a slow trickle of drive-by fixes. There was a recent patch from Ernestas Kulik indicating potential real life use, but it was new/experimental and that person is not responding to off-list pings. Let LLC2 follow AX.25, hamradio and AppleTalk out of the Linux tree. We will maintain the code at: github.com/linux-netdev/mod-orphan for anyone interested in playing with it. PF_LLC goes in full, both the class two SOCK_STREAM and the class one SOCK_DGRAM half, and so do /proc/net/llc/ and /proc/sys/net/llc/. Note that the kernel also stops answering XID and TEST commands, addressed to a SAP or to the station - those are type 1, but they lived in the module, and they got answered whether or not any socket was open. Nothing in tree asks for them; what the core keeps is SAP registration and the UI path the in-tree users need. Retain the uAPI for now, like we did for AppleTalk. Only the socket ABI half of it is vestigial: STP, GARP, the bridge and openvswitch use the SAP numbers it defines. Cleaning up what the core no longer needs follows in the next patch. Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260928190800.2521749-2-kuba@kernel.org Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paolo Abeni --- arch/loongarch/configs/loongson32_defconfig | 1 - arch/loongarch/configs/loongson64_defconfig | 1 - arch/mips/configs/gpr_defconfig | 1 - arch/mips/configs/mtx1_defconfig | 1 - arch/mips/configs/rb532_defconfig | 1 - arch/parisc/configs/generic-32bit_defconfig | 1 - include/linux/llc.h | 5 - include/net/llc.h | 26 - include/net/llc_c_ac.h | 180 - include/net/llc_c_ev.h | 217 - include/net/llc_c_st.h | 46 - include/net/llc_conn.h | 114 - include/net/llc_if.h | 63 - include/net/llc_s_ac.h | 35 - include/net/llc_s_ev.h | 61 - include/net/llc_s_st.h | 32 - include/net/llc_sap.h | 26 - net/llc/Kconfig | 7 - net/llc/Makefile | 10 +- net/llc/af_llc.c | 1304 ----- net/llc/llc_c_ac.c | 1448 ------ net/llc/llc_c_ev.c | 742 --- net/llc/llc_c_st.c | 4940 ------------------- net/llc/llc_conn.c | 1025 ---- net/llc/llc_if.c | 151 - net/llc/llc_input.c | 1 - net/llc/llc_pdu.c | 366 -- net/llc/llc_proc.c | 245 - net/llc/llc_s_ac.c | 220 - net/llc/llc_s_ev.c | 109 - net/llc/llc_s_st.c | 177 - net/llc/llc_sap.c | 437 -- net/llc/llc_station.c | 120 - net/llc/sysctl_net_llc.c | 71 - 34 files changed, 1 insertion(+), 12183 deletions(-) delete mode 100644 include/net/llc_c_ac.h delete mode 100644 include/net/llc_c_ev.h delete mode 100644 include/net/llc_c_st.h delete mode 100644 include/net/llc_conn.h delete mode 100644 include/net/llc_if.h delete mode 100644 include/net/llc_s_ac.h delete mode 100644 include/net/llc_s_ev.h delete mode 100644 include/net/llc_s_st.h delete mode 100644 include/net/llc_sap.h delete mode 100644 net/llc/af_llc.c delete mode 100644 net/llc/llc_c_ac.c delete mode 100644 net/llc/llc_c_ev.c delete mode 100644 net/llc/llc_c_st.c delete mode 100644 net/llc/llc_conn.c delete mode 100644 net/llc/llc_if.c delete mode 100644 net/llc/llc_pdu.c delete mode 100644 net/llc/llc_proc.c delete mode 100644 net/llc/llc_s_ac.c delete mode 100644 net/llc/llc_s_ev.c delete mode 100644 net/llc/llc_s_st.c delete mode 100644 net/llc/llc_sap.c delete mode 100644 net/llc/llc_station.c delete mode 100644 net/llc/sysctl_net_llc.c diff --git a/arch/loongarch/configs/loongson32_defconfig b/arch/loongarch/configs/loongson32_defconfig index e76ea9b62974..dbef879935f3 100644 --- a/arch/loongarch/configs/loongson32_defconfig +++ b/arch/loongarch/configs/loongson32_defconfig @@ -321,7 +321,6 @@ CONFIG_BRIDGE=m CONFIG_VLAN_8021Q=m CONFIG_VLAN_8021Q_GVRP=y CONFIG_VLAN_8021Q_MVRP=y -CONFIG_LLC2=m CONFIG_NET_SCHED=y CONFIG_NET_SCH_HTB=m CONFIG_NET_SCH_PRIO=m diff --git a/arch/loongarch/configs/loongson64_defconfig b/arch/loongarch/configs/loongson64_defconfig index 976340d4d514..4f8bb77b8a1e 100644 --- a/arch/loongarch/configs/loongson64_defconfig +++ b/arch/loongarch/configs/loongson64_defconfig @@ -337,7 +337,6 @@ CONFIG_BRIDGE=m CONFIG_VLAN_8021Q=m CONFIG_VLAN_8021Q_GVRP=y CONFIG_VLAN_8021Q_MVRP=y -CONFIG_LLC2=m CONFIG_NET_SCHED=y CONFIG_NET_SCH_HTB=m CONFIG_NET_SCH_PRIO=m diff --git a/arch/mips/configs/gpr_defconfig b/arch/mips/configs/gpr_defconfig index 7834569a8314..718a04dbe88d 100644 --- a/arch/mips/configs/gpr_defconfig +++ b/arch/mips/configs/gpr_defconfig @@ -90,7 +90,6 @@ CONFIG_ATM=y CONFIG_ATM_BR2684=m CONFIG_BRIDGE=m CONFIG_VLAN_8021Q=m -CONFIG_LLC2=m CONFIG_DEV_APPLETALK=m CONFIG_IPDDP=m CONFIG_IPDDP_ENCAP=y diff --git a/arch/mips/configs/mtx1_defconfig b/arch/mips/configs/mtx1_defconfig index e28a0b1e6d52..095176c3dbee 100644 --- a/arch/mips/configs/mtx1_defconfig +++ b/arch/mips/configs/mtx1_defconfig @@ -135,7 +135,6 @@ CONFIG_ATM=y CONFIG_ATM_BR2684=m CONFIG_BRIDGE=m CONFIG_VLAN_8021Q=m -CONFIG_LLC2=m CONFIG_DEV_APPLETALK=m CONFIG_IPDDP=m CONFIG_IPDDP_ENCAP=y diff --git a/arch/mips/configs/rb532_defconfig b/arch/mips/configs/rb532_defconfig index a88322fe3935..e2f7d01f4d10 100644 --- a/arch/mips/configs/rb532_defconfig +++ b/arch/mips/configs/rb532_defconfig @@ -70,7 +70,6 @@ CONFIG_IP_NF_MANGLE=y CONFIG_IP_NF_RAW=m CONFIG_BRIDGE=y CONFIG_VLAN_8021Q=y -CONFIG_LLC2=m CONFIG_NET_SCHED=y CONFIG_NET_SCH_CBQ=m CONFIG_NET_SCH_PRIO=m diff --git a/arch/parisc/configs/generic-32bit_defconfig b/arch/parisc/configs/generic-32bit_defconfig index 3572a32f7849..3550250e8b87 100644 --- a/arch/parisc/configs/generic-32bit_defconfig +++ b/arch/parisc/configs/generic-32bit_defconfig @@ -35,7 +35,6 @@ CONFIG_INET=y CONFIG_INET_AH=m CONFIG_INET_ESP=m CONFIG_INET_DIAG=m -CONFIG_LLC2=m # CONFIG_WIRELESS is not set CONFIG_EISA=y CONFIG_PCI=y diff --git a/include/linux/llc.h b/include/linux/llc.h index 944e9e213112..c03bb12bcc9c 100644 --- a/include/linux/llc.h +++ b/include/linux/llc.h @@ -9,9 +9,4 @@ #include -#define LLC_SAP_DYN_START 0xC0 -#define LLC_SAP_DYN_STOP 0xDE -#define LLC_SAP_DYN_TRIES 4 - -#define llc_ui_skb_cb(__skb) ((struct sockaddr_llc *)&((__skb)->cb[0])) #endif /* __LINUX_LLC_H */ diff --git a/include/net/llc.h b/include/net/llc.h index 029ba8a22319..8ea44ed98c4d 100644 --- a/include/net/llc.h +++ b/include/net/llc.h @@ -130,30 +130,4 @@ struct llc_sap *llc_sap_find(unsigned char sap_value); int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, const unsigned char *dmac, unsigned char dsap); - -void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb); -void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb); - -void llc_station_init(void); -void llc_station_exit(void); - -#ifdef CONFIG_PROC_FS -int llc_proc_init(void); -void llc_proc_exit(void); -#else -#define llc_proc_init() (0) -#define llc_proc_exit() do { } while(0) -#endif /* CONFIG_PROC_FS */ -#ifdef CONFIG_SYSCTL -int llc_sysctl_init(void); -void llc_sysctl_exit(void); - -extern int sysctl_llc2_ack_timeout; -extern int sysctl_llc2_busy_timeout; -extern int sysctl_llc2_p_timeout; -extern int sysctl_llc2_rej_timeout; -#else -#define llc_sysctl_init() (0) -#define llc_sysctl_exit() do { } while(0) -#endif /* CONFIG_SYSCTL */ #endif /* LLC_H */ diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h deleted file mode 100644 index af31a49bebb0..000000000000 --- a/include/net/llc_c_ac.h +++ /dev/null @@ -1,180 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_C_AC_H -#define LLC_C_AC_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ -/* Connection component state transition actions */ -/* - * Connection state transition actions - * (Fb = F bit; Pb = P bit; Xb = X bit) - */ - -#include - -struct sk_buff; -struct sock; -struct timer_list; - -#define LLC_CONN_AC_CLR_REMOTE_BUSY 1 -#define LLC_CONN_AC_CONN_IND 2 -#define LLC_CONN_AC_CONN_CONFIRM 3 -#define LLC_CONN_AC_DATA_IND 4 -#define LLC_CONN_AC_DISC_IND 5 -#define LLC_CONN_AC_RESET_IND 6 -#define LLC_CONN_AC_RESET_CONFIRM 7 -#define LLC_CONN_AC_REPORT_STATUS 8 -#define LLC_CONN_AC_CLR_REMOTE_BUSY_IF_Fb_EQ_1 9 -#define LLC_CONN_AC_STOP_REJ_TMR_IF_DATA_FLAG_EQ_2 10 -#define LLC_CONN_AC_SEND_DISC_CMD_Pb_SET_X 11 -#define LLC_CONN_AC_SEND_DM_RSP_Fb_SET_Pb 12 -#define LLC_CONN_AC_SEND_DM_RSP_Fb_SET_1 13 -#define LLC_CONN_AC_SEND_DM_RSP_Fb_SET_F_FLAG 14 -#define LLC_CONN_AC_SEND_FRMR_RSP_Fb_SET_X 15 -#define LLC_CONN_AC_RESEND_FRMR_RSP_Fb_SET_0 16 -#define LLC_CONN_AC_RESEND_FRMR_RSP_Fb_SET_Pb 17 -#define LLC_CONN_AC_SEND_I_CMD_Pb_SET_1 18 -#define LLC_CONN_AC_RESEND_I_CMD_Pb_SET_1 19 -#define LLC_CONN_AC_RESEND_I_CMD_Pb_SET_1_OR_SEND_RR 20 -#define LLC_CONN_AC_SEND_I_XXX_Xb_SET_0 21 -#define LLC_CONN_AC_RESEND_I_XXX_Xb_SET_0 22 -#define LLC_CONN_AC_RESEND_I_XXX_Xb_SET_0_OR_SEND_RR 23 -#define LLC_CONN_AC_RESEND_I_RSP_Fb_SET_1 24 -#define LLC_CONN_AC_SEND_REJ_CMD_Pb_SET_1 25 -#define LLC_CONN_AC_SEND_REJ_RSP_Fb_SET_1 26 -#define LLC_CONN_AC_SEND_REJ_XXX_Xb_SET_0 27 -#define LLC_CONN_AC_SEND_RNR_CMD_Pb_SET_1 28 -#define LLC_CONN_AC_SEND_RNR_RSP_Fb_SET_1 29 -#define LLC_CONN_AC_SEND_RNR_XXX_Xb_SET_0 30 -#define LLC_CONN_AC_SET_REMOTE_BUSY 31 -#define LLC_CONN_AC_OPTIONAL_SEND_RNR_XXX_Xb_SET_0 32 -#define LLC_CONN_AC_SEND_RR_CMD_Pb_SET_1 33 -#define LLC_CONN_AC_SEND_ACK_CMD_Pb_SET_1 34 -#define LLC_CONN_AC_SEND_RR_RSP_Fb_SET_1 35 -#define LLC_CONN_AC_SEND_ACK_RSP_Fb_SET_1 36 -#define LLC_CONN_AC_SEND_RR_XXX_Xb_SET_0 37 -#define LLC_CONN_AC_SEND_ACK_XXX_Xb_SET_0 38 -#define LLC_CONN_AC_SEND_SABME_CMD_Pb_SET_X 39 -#define LLC_CONN_AC_SEND_UA_RSP_Fb_SET_Pb 40 -#define LLC_CONN_AC_SEND_UA_RSP_Fb_SET_F_FLAG 41 -#define LLC_CONN_AC_S_FLAG_SET_0 42 -#define LLC_CONN_AC_S_FLAG_SET_1 43 -#define LLC_CONN_AC_START_P_TMR 44 -#define LLC_CONN_AC_START_ACK_TMR 45 -#define LLC_CONN_AC_START_REJ_TMR 46 -#define LLC_CONN_AC_START_ACK_TMR_IF_NOT_RUNNING 47 -#define LLC_CONN_AC_STOP_ACK_TMR 48 -#define LLC_CONN_AC_STOP_P_TMR 49 -#define LLC_CONN_AC_STOP_REJ_TMR 50 -#define LLC_CONN_AC_STOP_ALL_TMRS 51 -#define LLC_CONN_AC_STOP_OTHER_TMRS 52 -#define LLC_CONN_AC_UPDATE_Nr_RECEIVED 53 -#define LLC_CONN_AC_UPDATE_P_FLAG 54 -#define LLC_CONN_AC_DATA_FLAG_SET_2 55 -#define LLC_CONN_AC_DATA_FLAG_SET_0 56 -#define LLC_CONN_AC_DATA_FLAG_SET_1 57 -#define LLC_CONN_AC_DATA_FLAG_SET_1_IF_DATA_FLAG_EQ_0 58 -#define LLC_CONN_AC_P_FLAG_SET_0 59 -#define LLC_CONN_AC_P_FLAG_SET_P 60 -#define LLC_CONN_AC_REMOTE_BUSY_SET_0 61 -#define LLC_CONN_AC_RETRY_CNT_SET_0 62 -#define LLC_CONN_AC_RETRY_CNT_INC_BY_1 63 -#define LLC_CONN_AC_Vr_SET_0 64 -#define LLC_CONN_AC_Vr_INC_BY_1 65 -#define LLC_CONN_AC_Vs_SET_0 66 -#define LLC_CONN_AC_Vs_SET_Nr 67 -#define LLC_CONN_AC_F_FLAG_SET_P 68 -#define LLC_CONN_AC_STOP_SENDACK_TMR 70 -#define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71 - -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb); - -int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb); -int llc_conn_disc(struct sock *sk, struct sk_buff *skb); -int llc_conn_reset(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb); -u8 llc_circular_between(u8 a, u8 b, u8 c); -int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb); -int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb); - -void llc_conn_busy_tmr_cb(struct timer_list *t); -void llc_conn_pf_cycle_tmr_cb(struct timer_list *t); -void llc_conn_ack_tmr_cb(struct timer_list *t); -void llc_conn_rej_tmr_cb(struct timer_list *t); - -void llc_conn_set_p_flag(struct sock *sk, u8 value); -#endif /* LLC_C_AC_H */ diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h deleted file mode 100644 index d45140d4289a..000000000000 --- a/include/net/llc_c_ev.h +++ /dev/null @@ -1,217 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_C_EV_H -#define LLC_C_EV_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ - -#include - -/* Connection component state transition event qualifiers */ -/* Types of events (possible values in 'ev->type') */ -#define LLC_CONN_EV_TYPE_SIMPLE 1 -#define LLC_CONN_EV_TYPE_CONDITION 2 -#define LLC_CONN_EV_TYPE_PRIM 3 -#define LLC_CONN_EV_TYPE_PDU 4 /* command/response PDU */ -#define LLC_CONN_EV_TYPE_ACK_TMR 5 -#define LLC_CONN_EV_TYPE_P_TMR 6 -#define LLC_CONN_EV_TYPE_REJ_TMR 7 -#define LLC_CONN_EV_TYPE_BUSY_TMR 8 -#define LLC_CONN_EV_TYPE_RPT_STATUS 9 -#define LLC_CONN_EV_TYPE_SENDACK_TMR 10 - -#define NBR_CONN_EV 5 -/* Connection events which cause state transitions when fully qualified */ - -#define LLC_CONN_EV_CONN_REQ 1 -#define LLC_CONN_EV_CONN_RESP 2 -#define LLC_CONN_EV_DATA_REQ 3 -#define LLC_CONN_EV_DISC_REQ 4 -#define LLC_CONN_EV_RESET_REQ 5 -#define LLC_CONN_EV_RESET_RESP 6 -#define LLC_CONN_EV_LOCAL_BUSY_DETECTED 7 -#define LLC_CONN_EV_LOCAL_BUSY_CLEARED 8 -#define LLC_CONN_EV_RX_BAD_PDU 9 -#define LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X 10 -#define LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X 11 -#define LLC_CONN_EV_RX_FRMR_RSP_Fbit_SET_X 12 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_X 13 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_X_UNEXPD_Ns 14 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_X_INVAL_Ns 15 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_X 16 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_X_UNEXPD_Ns 17 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_X_INVAL_Ns 18 -#define LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_X 19 -#define LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_X 20 -#define LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_X 21 -#define LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_X 22 -#define LLC_CONN_EV_RX_RR_CMD_Pbit_SET_X 23 -#define LLC_CONN_EV_RX_RR_RSP_Fbit_SET_X 24 -#define LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X 25 -#define LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X 26 -#define LLC_CONN_EV_RX_XXX_CMD_Pbit_SET_X 27 -#define LLC_CONN_EV_RX_XXX_RSP_Fbit_SET_X 28 -#define LLC_CONN_EV_RX_XXX_YYY 29 -#define LLC_CONN_EV_RX_ZZZ_CMD_Pbit_SET_X_INVAL_Nr 30 -#define LLC_CONN_EV_RX_ZZZ_RSP_Fbit_SET_X_INVAL_Nr 31 -#define LLC_CONN_EV_P_TMR_EXP 32 -#define LLC_CONN_EV_ACK_TMR_EXP 33 -#define LLC_CONN_EV_REJ_TMR_EXP 34 -#define LLC_CONN_EV_BUSY_TMR_EXP 35 -#define LLC_CONN_EV_RX_XXX_CMD_Pbit_SET_1 36 -#define LLC_CONN_EV_RX_XXX_CMD_Pbit_SET_0 37 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns 38 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns 39 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_1_UNEXPD_Ns 40 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns 41 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 42 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 43 -#define LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 44 -#define LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 45 -#define LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 46 -#define LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 47 -#define LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 48 -#define LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 49 -#define LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 50 -#define LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 51 -#define LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 52 -#define LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 53 -#define LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 54 -#define LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 55 -#define LLC_CONN_EV_RX_I_RSP_Fbit_SET_1 56 -#define LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_1 57 -#define LLC_CONN_EV_RX_XXX_RSP_Fbit_SET_1 58 -#define LLC_CONN_EV_TX_BUFF_FULL 59 - -#define LLC_CONN_EV_INIT_P_F_CYCLE 100 -/* - * Connection event qualifiers; for some events a certain combination of - * these qualifiers must be TRUE before event recognized valid for state; - * these constants act as indexes into the Event Qualifier function - * table - */ -#define LLC_CONN_EV_QFY_DATA_FLAG_EQ_1 1 -#define LLC_CONN_EV_QFY_DATA_FLAG_EQ_0 2 -#define LLC_CONN_EV_QFY_DATA_FLAG_EQ_2 3 -#define LLC_CONN_EV_QFY_P_FLAG_EQ_1 4 -#define LLC_CONN_EV_QFY_P_FLAG_EQ_0 5 -#define LLC_CONN_EV_QFY_P_FLAG_EQ_Fbit 6 -#define LLC_CONN_EV_QFY_REMOTE_BUSY_EQ_0 7 -#define LLC_CONN_EV_QFY_RETRY_CNT_LT_N2 8 -#define LLC_CONN_EV_QFY_RETRY_CNT_GTE_N2 9 -#define LLC_CONN_EV_QFY_S_FLAG_EQ_1 10 -#define LLC_CONN_EV_QFY_S_FLAG_EQ_0 11 -#define LLC_CONN_EV_QFY_INIT_P_F_CYCLE 12 - -struct llc_conn_state_ev { - u8 type; - u8 prim; - u8 prim_type; - u8 reason; - u8 status; - u8 ind_prim; - u8 cfm_prim; -}; - -static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb) -{ - return (struct llc_conn_state_ev *)skb->cb; -} - -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb); -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb); - -int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_disc_req(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rst_req(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_local_busy_detected(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_local_busy_cleared(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_bad_pdu(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_disc_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_dm_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_frmr_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_rej_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_sabme_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_ua_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_xxx_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_xxx_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_zzz_cmd_pbit_set_x_inval_nr(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_zzz_rsp_fbit_set_x_inval_nr(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_p_tmr_exp(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_ack_tmr_exp(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rej_tmr_exp(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_busy_tmr_exp(struct sock *sk, struct sk_buff *skb); -/* NOT_USED functions and their variations */ -int llc_conn_ev_rx_xxx_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_xxx_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_i_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_i_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_i_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rnr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rnr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rnr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rnr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rej_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rej_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rej_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_rej_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_rx_any_frame(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_tx_buffer_full(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_init_p_f_cycle(struct sock *sk, struct sk_buff *skb); - -/* Available connection action qualifiers */ -int llc_conn_ev_qlfy_data_flag_eq_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_data_flag_eq_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_data_flag_eq_2(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_p_flag_eq_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_last_frame_eq_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_last_frame_eq_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_p_flag_eq_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_p_flag_eq_f(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_remote_busy_eq_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_remote_busy_eq_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_retry_cnt_lt_n2(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_retry_cnt_gte_n2(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_s_flag_eq_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_s_flag_eq_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_cause_flag_eq_1(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_cause_flag_eq_0(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_conn(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_disc(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_failed(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_remote_busy(struct sock *sk, - struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_refuse(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_conflict(struct sock *sk, struct sk_buff *skb); -int llc_conn_ev_qlfy_set_status_rst_done(struct sock *sk, struct sk_buff *skb); - -static __inline__ int llc_conn_space(struct sock *sk, struct sk_buff *skb) -{ - return atomic_read(&sk->sk_rmem_alloc) + skb->truesize < - (unsigned int)sk->sk_rcvbuf; -} -#endif /* LLC_C_EV_H */ diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h deleted file mode 100644 index f52a4cc4880d..000000000000 --- a/include/net/llc_c_st.h +++ /dev/null @@ -1,46 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_C_ST_H -#define LLC_C_ST_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ - -#include -#include - -/* Connection component state management */ -/* connection states */ -#define LLC_CONN_OUT_OF_SVC 0 /* prior to allocation */ - -#define LLC_CONN_STATE_ADM 1 /* disc, initial state */ -#define LLC_CONN_STATE_SETUP 2 /* disconnected state */ -#define LLC_CONN_STATE_NORMAL 3 /* connected state */ -#define LLC_CONN_STATE_BUSY 4 /* connected state */ -#define LLC_CONN_STATE_REJ 5 /* connected state */ -#define LLC_CONN_STATE_AWAIT 6 /* connected state */ -#define LLC_CONN_STATE_AWAIT_BUSY 7 /* connected state */ -#define LLC_CONN_STATE_AWAIT_REJ 8 /* connected state */ -#define LLC_CONN_STATE_D_CONN 9 /* disconnected state */ -#define LLC_CONN_STATE_RESET 10 /* disconnected state */ -#define LLC_CONN_STATE_ERROR 11 /* disconnected state */ -#define LLC_CONN_STATE_TEMP 12 /* disconnected state */ - -#define NBR_CONN_STATES 12 /* size of state table */ -#define NO_STATE_CHANGE 100 - -/* Connection state table structure */ -struct llc_conn_state_trans { - llc_conn_ev_t ev; - u8 next_state; - const llc_conn_ev_qfyr_t *ev_qualifiers; - const llc_conn_action_t *ev_actions; -}; - -struct llc_conn_state { - u8 current_state; - const struct llc_conn_state_trans **transitions; -}; - -extern struct llc_conn_state llc_conn_state_table[]; -#endif /* LLC_C_ST_H */ diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h deleted file mode 100644 index e1a302696723..000000000000 --- a/include/net/llc_conn.h +++ /dev/null @@ -1,114 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_CONN_H -#define LLC_CONN_H -/* - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001, 2002 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include - -#define LLC_EVENT 1 -#define LLC_PACKET 2 - -#define LLC2_P_TIME 2 -#define LLC2_ACK_TIME 1 -#define LLC2_REJ_TIME 3 -#define LLC2_BUSY_TIME 3 - -struct llc_timer { - struct timer_list timer; - unsigned long expire; /* timer expire time */ -}; - -struct llc_sock { - /* struct sock must be the first member of llc_sock */ - struct sock sk; - struct sockaddr_llc addr; /* address sock is bound to */ - u8 state; /* state of connection */ - struct llc_sap *sap; /* pointer to parent SAP */ - struct llc_addr laddr; /* lsap/mac pair */ - struct llc_addr daddr; /* dsap/mac pair */ - struct net_device *dev; /* device to send to remote */ - netdevice_tracker dev_tracker; - u32 copied_seq; /* head of yet unread data */ - u8 retry_count; /* number of retries */ - u8 ack_must_be_send; - u8 first_pdu_Ns; - u8 npta; - struct llc_timer ack_timer; - struct llc_timer pf_cycle_timer; - struct llc_timer rej_sent_timer; - struct llc_timer busy_state_timer; /* ind busy clr at remote LLC */ - u8 vS; /* seq# next in-seq I-PDU tx'd*/ - u8 vR; /* seq# next in-seq I-PDU rx'd*/ - u32 n2; /* max nbr re-tx's for timeout*/ - u32 n1; /* max nbr octets in I PDU */ - u8 k; /* tx window size; max = 127 */ - u8 rw; /* rx window size; max = 127 */ - u8 p_flag; /* state flags */ - u8 f_flag; - u8 s_flag; - u8 data_flag; - u8 remote_busy_flag; - u8 cause_flag; - struct sk_buff_head pdu_unack_q; /* PUDs sent/waiting ack */ - u16 link; /* network layer link number */ - u8 X; /* a temporary variable */ - u8 ack_pf; /* this flag indicates what is - the P-bit of acknowledge */ - u8 failed_data_req; /* recognize that already exist a - failed llc_data_req_handler - (tx_buffer_full or unacceptable - state */ - u8 dec_step; - u8 inc_cntr; - u8 dec_cntr; - u8 connect_step; - u8 last_nr; /* NR of last pdu received */ - u32 rx_pdu_hdr; /* used for saving header of last pdu - received and caused sending FRMR. - Used for resending FRMR */ - u32 cmsg_flags; - struct hlist_node dev_hash_node; -}; - -static inline struct llc_sock *llc_sk(const struct sock *sk) -{ - return (struct llc_sock *)sk; -} - -static __inline__ void llc_set_backlog_type(struct sk_buff *skb, char type) -{ - skb->cb[sizeof(skb->cb) - 1] = type; -} - -static __inline__ char llc_backlog_type(struct sk_buff *skb) -{ - return skb->cb[sizeof(skb->cb) - 1]; -} - -struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority, - struct proto *prot, int kern); -void llc_sk_stop_all_timers(struct sock *sk, bool sync); -void llc_sk_free(struct sock *sk); - -void llc_sk_reset(struct sock *sk); - -/* Access to a connection */ -int llc_conn_state_process(struct sock *sk, struct sk_buff *skb); -void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb); -void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb); -void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit); -void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit); -int llc_conn_remove_acked_pdus(struct sock *conn, u8 nr, u16 *how_many_unacked); -struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr, - struct llc_addr *laddr, const struct net *net); -void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk); -void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk); - -u8 llc_data_accept_state(u8 state); -void llc_build_offset_table(void); -#endif /* LLC_CONN_H */ diff --git a/include/net/llc_if.h b/include/net/llc_if.h deleted file mode 100644 index a333259613ab..000000000000 --- a/include/net/llc_if.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_IF_H -#define LLC_IF_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ -/* Defines LLC interface to network layer */ -/* Available primitives */ -#include -#include -#include -#include -#include - -#define LLC_DATAUNIT_PRIM 1 -#define LLC_CONN_PRIM 2 -#define LLC_DATA_PRIM 3 -#define LLC_DISC_PRIM 4 -#define LLC_RESET_PRIM 5 -#define LLC_FLOWCONTROL_PRIM 6 /* Not supported at this time */ -#define LLC_DISABLE_PRIM 7 -#define LLC_XID_PRIM 8 -#define LLC_TEST_PRIM 9 -#define LLC_SAP_ACTIVATION 10 -#define LLC_SAP_DEACTIVATION 11 - -#define LLC_NBR_PRIMITIVES 11 - -#define LLC_IND 1 -#define LLC_CONFIRM 2 - -/* Primitive type */ -#define LLC_PRIM_TYPE_REQ 1 -#define LLC_PRIM_TYPE_IND 2 -#define LLC_PRIM_TYPE_RESP 3 -#define LLC_PRIM_TYPE_CONFIRM 4 - -/* Reset reasons, remote entity or local LLC */ -#define LLC_RESET_REASON_REMOTE 1 -#define LLC_RESET_REASON_LOCAL 2 - -/* Disconnect reasons */ -#define LLC_DISC_REASON_RX_DM_RSP_PDU 0 -#define LLC_DISC_REASON_RX_DISC_CMD_PDU 1 -#define LLC_DISC_REASON_ACK_TMR_EXP 2 - -/* Confirm reasons */ -#define LLC_STATUS_CONN 0 /* connect confirm & reset confirm */ -#define LLC_STATUS_DISC 1 /* connect confirm & reset confirm */ -#define LLC_STATUS_FAILED 2 /* connect confirm & reset confirm */ -#define LLC_STATUS_IMPOSSIBLE 3 /* connect confirm */ -#define LLC_STATUS_RECEIVED 4 /* data conn */ -#define LLC_STATUS_REMOTE_BUSY 5 /* data conn */ -#define LLC_STATUS_REFUSE 6 /* data conn */ -#define LLC_STATUS_CONFLICT 7 /* disconnect conn */ -#define LLC_STATUS_RESET_DONE 8 /* */ - -int llc_establish_connection(struct sock *sk, const u8 *lmac, u8 *dmac, - u8 dsap); -int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb); -int llc_send_disc(struct sock *sk); -#endif /* LLC_IF_H */ diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h deleted file mode 100644 index 076adc5217fd..000000000000 --- a/include/net/llc_s_ac.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_S_AC_H -#define LLC_S_AC_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ - -struct llc_sap; -struct sk_buff; - -/* SAP component actions */ -#define SAP_ACT_UNITDATA_IND 1 -#define SAP_ACT_SEND_UI 2 -#define SAP_ACT_SEND_XID_C 3 -#define SAP_ACT_SEND_XID_R 4 -#define SAP_ACT_SEND_TEST_C 5 -#define SAP_ACT_SEND_TEST_R 6 -#define SAP_ACT_REPORT_STATUS 7 -#define SAP_ACT_XID_IND 8 -#define SAP_ACT_TEST_IND 9 - -/* All action functions must look like this */ -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb); - -int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb); -#endif /* LLC_S_AC_H */ diff --git a/include/net/llc_s_ev.h b/include/net/llc_s_ev.h deleted file mode 100644 index 7b9c94093336..000000000000 --- a/include/net/llc_s_ev.h +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_S_EV_H -#define LLC_S_EV_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ - -#include -#include - -/* Defines SAP component events */ -/* Types of events (possible values in 'ev->type') */ -#define LLC_SAP_EV_TYPE_SIMPLE 1 -#define LLC_SAP_EV_TYPE_CONDITION 2 -#define LLC_SAP_EV_TYPE_PRIM 3 -#define LLC_SAP_EV_TYPE_PDU 4 /* command/response PDU */ -#define LLC_SAP_EV_TYPE_ACK_TMR 5 -#define LLC_SAP_EV_TYPE_RPT_STATUS 6 - -#define LLC_SAP_EV_ACTIVATION_REQ 1 -#define LLC_SAP_EV_RX_UI 2 -#define LLC_SAP_EV_UNITDATA_REQ 3 -#define LLC_SAP_EV_XID_REQ 4 -#define LLC_SAP_EV_RX_XID_C 5 -#define LLC_SAP_EV_RX_XID_R 6 -#define LLC_SAP_EV_TEST_REQ 7 -#define LLC_SAP_EV_RX_TEST_C 8 -#define LLC_SAP_EV_RX_TEST_R 9 -#define LLC_SAP_EV_DEACTIVATION_REQ 10 - -struct llc_sap_state_ev { - u8 prim; - u8 prim_type; - u8 type; - u8 reason; - u8 ind_cfm_flag; - struct llc_addr saddr; - struct llc_addr daddr; -}; - -static __inline__ struct llc_sap_state_ev *llc_sap_ev(struct sk_buff *skb) -{ - return (struct llc_sap_state_ev *)skb->cb; -} - -struct llc_sap; - -typedef int (*llc_sap_ev_t)(struct llc_sap *sap, struct sk_buff *skb); - -int llc_sap_ev_activation_req(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_rx_ui(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_unitdata_req(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_xid_req(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_rx_xid_c(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_rx_xid_r(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_test_req(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_rx_test_c(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_rx_test_r(struct llc_sap *sap, struct sk_buff *skb); -int llc_sap_ev_deactivation_req(struct llc_sap *sap, struct sk_buff *skb); -#endif /* LLC_S_EV_H */ diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h deleted file mode 100644 index 85ce230fd946..000000000000 --- a/include/net/llc_s_st.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_S_ST_H -#define LLC_S_ST_H -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001 by Arnaldo Carvalho de Melo - */ - -#include -#include -#include - -struct llc_sap_state_trans; - -#define LLC_NR_SAP_STATES 2 /* size of state table */ - -/* structures and types */ -/* SAP state table structure */ -struct llc_sap_state_trans { - llc_sap_ev_t ev; - u8 next_state; - const llc_sap_action_t *ev_actions; -}; - -struct llc_sap_state { - u8 curr_state; - const struct llc_sap_state_trans **transitions; -}; - -/* only access to SAP state table */ -extern struct llc_sap_state llc_sap_state_table[LLC_NR_SAP_STATES]; -#endif /* LLC_S_ST_H */ diff --git a/include/net/llc_sap.h b/include/net/llc_sap.h deleted file mode 100644 index b259f5993c46..000000000000 --- a/include/net/llc_sap.h +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef LLC_SAP_H -#define LLC_SAP_H - -#include - -/* - * Copyright (c) 1997 by Procom Technology,Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -struct llc_sap; -struct net_device; -struct sk_buff; -struct sock; - -void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb); -void llc_save_primitive(struct sock *sk, struct sk_buff *skb, - unsigned char prim); -struct sk_buff *llc_alloc_frame(struct sock *sk, struct net_device *dev, - u8 type, u32 data_size); - -void llc_build_and_send_test_pkt(struct llc_sap *sap, struct sk_buff *skb, - unsigned char *dmac, unsigned char dsap); -void llc_build_and_send_xid_pkt(struct llc_sap *sap, struct sk_buff *skb, - unsigned char *dmac, unsigned char dsap); -#endif /* LLC_SAP_H */ diff --git a/net/llc/Kconfig b/net/llc/Kconfig index 7f79f5e134f9..81bfeaed6443 100644 --- a/net/llc/Kconfig +++ b/net/llc/Kconfig @@ -1,10 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only config LLC tristate - -config LLC2 - tristate "ANSI/IEEE 802.2 LLC type 2 Support" - select LLC - help - This is a Logical Link Layer type 2, connection oriented support. - Select this if you want to have support for PF_LLC sockets. diff --git a/net/llc/Makefile b/net/llc/Makefile index 46b1cd905ffd..17a8a2610b28 100644 --- a/net/llc/Makefile +++ b/net/llc/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 ########################################################################### -# Makefile for the Linux 802.2 LLC (fully-functional) layer. +# Makefile for the Linux 802.2 LLC layer. # # Copyright (c) 1997 by Procom Technology,Inc. # 2001-2003 by Arnaldo Carvalho de Melo @@ -9,11 +9,3 @@ obj-$(CONFIG_LLC) += llc.o llc-y := llc_core.o llc_input.o llc_output.o - -obj-$(CONFIG_LLC2) += llc2.o - -llc2-y := llc_if.o llc_c_ev.o llc_c_ac.o llc_conn.o llc_c_st.o llc_pdu.o \ - llc_sap.o llc_s_ac.o llc_s_ev.o llc_s_st.o af_llc.o llc_station.o - -llc2-$(CONFIG_PROC_FS) += llc_proc.o -llc2-$(CONFIG_SYSCTL) += sysctl_net_llc.o diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c deleted file mode 100644 index b0447c33dbf0..000000000000 --- a/net/llc/af_llc.c +++ /dev/null @@ -1,1304 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * af_llc.c - LLC User Interface SAPs - * Description: - * Functions in this module are implementation of socket based llc - * communications for the Linux operating system. Support of llc class - * one and class two is provided via SOCK_DGRAM and SOCK_STREAM - * respectively. - * - * An llc2 connection is (mac + sap), only one llc2 sap connection - * is allowed per mac. Though one sap may have multiple mac + sap - * connections. - * - * Copyright (c) 2001 by Jay Schulist - * 2002-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -/* remember: uninitialized global data is zeroed because its in .bss */ -static u16 llc_ui_sap_last_autoport = LLC_SAP_DYN_START; -static u16 llc_ui_sap_link_no_max[256]; -static struct sockaddr_llc llc_ui_addrnull; -static const struct proto_ops llc_ui_ops; - -static bool llc_ui_wait_for_conn(struct sock *sk, long timeout); -static int llc_ui_wait_for_disc(struct sock *sk, long timeout); -static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout); - -#if 0 -#define dprintk(args...) printk(KERN_DEBUG args) -#else -#define dprintk(args...) do {} while (0) -#endif - -/* Maybe we'll add some more in the future. */ -#define LLC_CMSG_PKTINFO 1 - - -/** - * llc_ui_next_link_no - return the next unused link number for a sap - * @sap: Address of sap to get link number from. - * - * Return the next unused link number for a given sap. - */ -static inline u16 llc_ui_next_link_no(int sap) -{ - return llc_ui_sap_link_no_max[sap]++; -} - -/** - * llc_proto_type - return eth protocol for ARP header type - * @arphrd: ARP header type. - * - * Given an ARP header type return the corresponding ethernet protocol. - */ -static inline __be16 llc_proto_type(u16 arphrd) -{ - return htons(ETH_P_802_2); -} - -/** - * llc_ui_addr_null - determines if a address structure is null - * @addr: Address to test if null. - */ -static inline u8 llc_ui_addr_null(struct sockaddr_llc *addr) -{ - return !memcmp(addr, &llc_ui_addrnull, sizeof(*addr)); -} - -/** - * llc_ui_header_len - return length of llc header based on operation - * @sk: Socket which contains a valid llc socket type. - * @addr: Complete sockaddr_llc structure received from the user. - * - * Provide the length of the llc header depending on what kind of - * operation the user would like to perform and the type of socket. - * Returns the correct llc header length. - */ -static inline u8 llc_ui_header_len(struct sock *sk, struct sockaddr_llc *addr) -{ - u8 rc = LLC_PDU_LEN_U; - - if (addr->sllc_test) - rc = LLC_PDU_LEN_U; - else if (addr->sllc_xid) - /* We need to expand header to sizeof(struct llc_xid_info) - * since llc_pdu_init_as_xid_cmd() sets 4,5,6 bytes of LLC header - * as XID PDU. In llc_ui_sendmsg() we reserved header size and then - * filled all other space with user data. If we won't reserve this - * bytes, llc_pdu_init_as_xid_cmd() will overwrite user data - */ - rc = LLC_PDU_LEN_U_XID; - else if (sk->sk_type == SOCK_STREAM) - rc = LLC_PDU_LEN_I; - return rc; -} - -/** - * llc_ui_send_data - send data via reliable llc2 connection - * @sk: Connection the socket is using. - * @skb: Data the user wishes to send. - * @noblock: can we block waiting for data? - * - * Send data via reliable llc2 connection. - * Returns 0 upon success, non-zero if action did not succeed. - * - * This function always consumes a reference to the skb. - */ -static int llc_ui_send_data(struct sock* sk, struct sk_buff *skb, int noblock) -{ - struct llc_sock* llc = llc_sk(sk); - - if (unlikely(llc_data_accept_state(llc->state) || - llc->remote_busy_flag || - llc->p_flag)) { - long timeout = sock_sndtimeo(sk, noblock); - int rc; - - rc = llc_ui_wait_for_busy_core(sk, timeout); - if (rc) { - kfree_skb(skb); - return rc; - } - } - return llc_build_and_send_pkt(sk, skb); -} - -static void llc_ui_sk_init(struct socket *sock, struct sock *sk) -{ - sock_graft(sk, sock); - sk->sk_type = sock->type; - sock->ops = &llc_ui_ops; -} - -static struct proto llc_proto = { - .name = "LLC", - .owner = THIS_MODULE, - .obj_size = sizeof(struct llc_sock), - .slab_flags = SLAB_TYPESAFE_BY_RCU, -}; - -/** - * llc_ui_create - alloc and init a new llc_ui socket - * @net: network namespace (must be default network) - * @sock: Socket to initialize and attach allocated sk to. - * @protocol: Unused. - * @kern: on behalf of kernel or userspace - * - * Allocate and initialize a new llc_ui socket, validate the user wants a - * socket type we have available. - * Returns 0 upon success, negative upon failure. - */ -static int llc_ui_create(struct net *net, struct socket *sock, int protocol, - int kern) -{ - struct sock *sk; - int rc = -ESOCKTNOSUPPORT; - - if (!ns_capable(net->user_ns, CAP_NET_RAW)) - return -EPERM; - - if (!net_eq(net, &init_net)) - return -EAFNOSUPPORT; - - if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) { - rc = -ENOMEM; - sk = llc_sk_alloc(net, PF_LLC, GFP_KERNEL, &llc_proto, kern); - if (sk) { - rc = 0; - llc_ui_sk_init(sock, sk); - } - } - return rc; -} - -/** - * llc_ui_release - shutdown socket - * @sock: Socket to release. - * - * Shutdown and deallocate an existing socket. - */ -static int llc_ui_release(struct socket *sock) -{ - struct sock *sk = sock->sk; - struct llc_sock *llc; - - if (unlikely(sk == NULL)) - goto out; - sock_hold(sk); - lock_sock(sk); - llc = llc_sk(sk); - dprintk("%s: closing local(%02X) remote(%02X)\n", __func__, - llc->laddr.lsap, llc->daddr.lsap); - if (!llc_send_disc(sk)) - llc_ui_wait_for_disc(sk, READ_ONCE(sk->sk_rcvtimeo)); - if (!sock_flag(sk, SOCK_ZAPPED)) { - struct llc_sap *sap = llc->sap; - - /* Hold this for release_sock(), so that llc_backlog_rcv() - * could still use it. - */ - llc_sap_hold(sap); - llc_sap_remove_socket(llc->sap, sk); - release_sock(sk); - llc_sap_put(sap); - } else { - release_sock(sk); - } - netdev_put(llc->dev, &llc->dev_tracker); - sock_put(sk); - sock_orphan(sk); - sock->sk = NULL; - llc_sk_free(sk); -out: - return 0; -} - -/** - * llc_ui_autoport - provide dynamically allocate SAP number - * - * Provide the caller with a dynamically allocated SAP number according - * to the rules that are set in this function. Returns: 0, upon failure, - * SAP number otherwise. - */ -static int llc_ui_autoport(void) -{ - struct llc_sap *sap; - int i, tries = 0; - - while (tries < LLC_SAP_DYN_TRIES) { - for (i = llc_ui_sap_last_autoport; - i < LLC_SAP_DYN_STOP; i += 2) { - sap = llc_sap_find(i); - if (!sap) { - llc_ui_sap_last_autoport = i + 2; - goto out; - } - llc_sap_put(sap); - } - llc_ui_sap_last_autoport = LLC_SAP_DYN_START; - tries++; - } - i = 0; -out: - return i; -} - -/** - * llc_ui_autobind - automatically bind a socket to a sap - * @sock: socket to bind - * @addr: address to connect to - * - * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't - * specifically used llc_ui_bind to bind to an specific address/sap - * - * Returns: 0 upon success, negative otherwise. - */ -static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr) -{ - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - struct net_device *dev = NULL; - struct llc_sap *sap; - int rc = -EINVAL; - - if (!sock_flag(sk, SOCK_ZAPPED)) - goto out; - if (!addr->sllc_arphrd) - addr->sllc_arphrd = ARPHRD_ETHER; - if (addr->sllc_arphrd != ARPHRD_ETHER) - goto out; - rc = -ENODEV; - if (sk->sk_bound_dev_if) { - dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if); - if (dev && addr->sllc_arphrd != dev->type) { - dev_put(dev); - dev = NULL; - } - } else - dev = dev_getfirstbyhwtype(&init_net, addr->sllc_arphrd); - if (!dev) - goto out; - rc = -EUSERS; - llc->laddr.lsap = llc_ui_autoport(); - if (!llc->laddr.lsap) - goto out; - rc = -EBUSY; /* some other network layer is using the sap */ - sap = llc_sap_open(llc->laddr.lsap, NULL); - if (!sap) - goto out; - - /* Note: We do not expect errors from this point. */ - llc->dev = dev; - netdev_tracker_alloc(llc->dev, &llc->dev_tracker, GFP_KERNEL); - dev = NULL; - - memcpy(llc->laddr.mac, llc->dev->dev_addr, IFHWADDRLEN); - memcpy(&llc->addr, addr, sizeof(llc->addr)); - /* assign new connection to its SAP */ - llc_sap_add_socket(sap, sk); - sock_reset_flag(sk, SOCK_ZAPPED); - llc_sap_put(sap); - rc = 0; -out: - dev_put(dev); - return rc; -} - -/** - * llc_ui_bind - bind a socket to a specific address. - * @sock: Socket to bind an address to. - * @uaddr: Address the user wants the socket bound to. - * @addrlen: Length of the uaddr structure. - * - * Bind a socket to a specific address. For llc a user is able to bind to - * a specific sap only or mac + sap. - * If the user desires to bind to a specific mac + sap, it is possible to - * have multiple sap connections via multiple macs. - * Bind and autobind for that matter must enforce the correct sap usage - * otherwise all hell will break loose. - * Returns: 0 upon success, negative otherwise. - */ -static int llc_ui_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int addrlen) -{ - struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr; - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - struct net_device *dev = NULL; - struct llc_sap *sap; - int rc = -EINVAL; - - lock_sock(sk); - if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr))) - goto out; - rc = -EAFNOSUPPORT; - if (!addr->sllc_arphrd) - addr->sllc_arphrd = ARPHRD_ETHER; - if (unlikely(addr->sllc_family != AF_LLC || addr->sllc_arphrd != ARPHRD_ETHER)) - goto out; - dprintk("%s: binding %02X\n", __func__, addr->sllc_sap); - rc = -ENODEV; - rcu_read_lock(); - if (sk->sk_bound_dev_if) { - dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if); - if (dev) { - if (is_zero_ether_addr(addr->sllc_mac)) - memcpy(addr->sllc_mac, dev->dev_addr, - IFHWADDRLEN); - if (addr->sllc_arphrd != dev->type || - !ether_addr_equal(addr->sllc_mac, - dev->dev_addr)) { - rc = -EINVAL; - dev = NULL; - } - } - } else { - dev = dev_getbyhwaddr_rcu(&init_net, addr->sllc_arphrd, - addr->sllc_mac); - } - dev_hold(dev); - rcu_read_unlock(); - if (!dev) - goto out; - - if (!addr->sllc_sap) { - rc = -EUSERS; - addr->sllc_sap = llc_ui_autoport(); - if (!addr->sllc_sap) - goto out; - } - sap = llc_sap_find(addr->sllc_sap); - if (!sap) { - sap = llc_sap_open(addr->sllc_sap, NULL); - rc = -EBUSY; /* some other network layer is using the sap */ - if (!sap) - goto out; - } else { - struct llc_addr laddr, daddr; - struct sock *ask; - - memset(&laddr, 0, sizeof(laddr)); - memset(&daddr, 0, sizeof(daddr)); - /* - * FIXME: check if the address is multicast, - * only SOCK_DGRAM can do this. - */ - memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN); - laddr.lsap = addr->sllc_sap; - rc = -EADDRINUSE; /* mac + sap clash. */ - ask = llc_lookup_established(sap, &daddr, &laddr, &init_net); - if (ask) { - sock_put(ask); - goto out_put; - } - } - - /* Note: We do not expect errors from this point. */ - llc->dev = dev; - netdev_tracker_alloc(llc->dev, &llc->dev_tracker, GFP_KERNEL); - dev = NULL; - - llc->laddr.lsap = addr->sllc_sap; - memcpy(llc->laddr.mac, addr->sllc_mac, IFHWADDRLEN); - memcpy(&llc->addr, addr, sizeof(llc->addr)); - /* assign new connection to its SAP */ - llc_sap_add_socket(sap, sk); - sock_reset_flag(sk, SOCK_ZAPPED); - rc = 0; -out_put: - llc_sap_put(sap); -out: - dev_put(dev); - release_sock(sk); - return rc; -} - -/** - * llc_ui_shutdown - shutdown a connect llc2 socket. - * @sock: Socket to shutdown. - * @how: What part of the socket to shutdown. - * - * Shutdown a connected llc2 socket. Currently this function only supports - * shutting down both sends and receives (2), we could probably make this - * function such that a user can shutdown only half the connection but not - * right now. - * Returns: 0 upon success, negative otherwise. - */ -static int llc_ui_shutdown(struct socket *sock, int how) -{ - struct sock *sk = sock->sk; - int rc = -ENOTCONN; - - lock_sock(sk); - if (unlikely(sk->sk_state != TCP_ESTABLISHED)) - goto out; - rc = -EINVAL; - if (how != 2) - goto out; - rc = llc_send_disc(sk); - if (!rc) - rc = llc_ui_wait_for_disc(sk, READ_ONCE(sk->sk_rcvtimeo)); - /* Wake up anyone sleeping in poll */ - sk->sk_state_change(sk); -out: - release_sock(sk); - return rc; -} - -/** - * llc_ui_connect - Connect to a remote llc2 mac + sap. - * @sock: Socket which will be connected to the remote destination. - * @uaddr: Remote and possibly the local address of the new connection. - * @addrlen: Size of uaddr structure. - * @flags: Operational flags specified by the user. - * - * Connect to a remote llc2 mac + sap. The caller must specify the - * destination mac and address to connect to. If the user hasn't previously - * called bind(2) with a smac the address of the first interface of the - * specified arp type will be used. - * This function will autobind if user did not previously call bind. - * Returns: 0 upon success, negative otherwise. - */ -static int llc_ui_connect(struct socket *sock, struct sockaddr_unsized *uaddr, - int addrlen, int flags) -{ - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr; - int rc = -EINVAL; - - lock_sock(sk); - if (unlikely(addrlen != sizeof(*addr))) - goto out; - rc = -EAFNOSUPPORT; - if (unlikely(addr->sllc_family != AF_LLC)) - goto out; - if (unlikely(sk->sk_type != SOCK_STREAM)) - goto out; - rc = -EALREADY; - if (unlikely(sock->state == SS_CONNECTING)) - goto out; - /* bind connection to sap if user hasn't done it. */ - if (sock_flag(sk, SOCK_ZAPPED)) { - /* bind to sap with null dev, exclusive */ - rc = llc_ui_autobind(sock, addr); - if (rc) - goto out; - } - llc->daddr.lsap = addr->sllc_sap; - memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN); - sock->state = SS_CONNECTING; - sk->sk_state = TCP_SYN_SENT; - llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap); - rc = llc_establish_connection(sk, llc->dev->dev_addr, - addr->sllc_mac, addr->sllc_sap); - if (rc) { - dprintk("%s: llc_ui_send_conn failed :-(\n", __func__); - sock->state = SS_UNCONNECTED; - sk->sk_state = TCP_CLOSE; - goto out; - } - - if (sk->sk_state == TCP_SYN_SENT) { - const long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK); - - if (!timeo || !llc_ui_wait_for_conn(sk, timeo)) { - rc = -EINPROGRESS; - goto out; - } - - rc = sock_intr_errno(timeo); - if (signal_pending(current)) - goto out; - } - - if (sk->sk_state == TCP_CLOSE) - goto sock_error; - - sock->state = SS_CONNECTED; - rc = 0; -out: - release_sock(sk); - return rc; -sock_error: - rc = sock_error(sk) ? : -ECONNABORTED; - sock->state = SS_UNCONNECTED; - goto out; -} - -/** - * llc_ui_listen - allow a normal socket to accept incoming connections - * @sock: Socket to allow incoming connections on. - * @backlog: Number of connections to queue. - * - * Allow a normal socket to accept incoming connections. - * Returns 0 upon success, negative otherwise. - */ -static int llc_ui_listen(struct socket *sock, int backlog) -{ - struct sock *sk = sock->sk; - int rc = -EINVAL; - - lock_sock(sk); - if (unlikely(sock->state != SS_UNCONNECTED)) - goto out; - rc = -EOPNOTSUPP; - if (unlikely(sk->sk_type != SOCK_STREAM)) - goto out; - rc = -EAGAIN; - if (sock_flag(sk, SOCK_ZAPPED)) - goto out; - rc = 0; - if (!(unsigned int)backlog) /* BSDism */ - backlog = 1; - sk->sk_max_ack_backlog = backlog; - if (sk->sk_state != TCP_LISTEN) { - sk->sk_ack_backlog = 0; - sk->sk_state = TCP_LISTEN; - } - sk->sk_socket->flags |= __SO_ACCEPTCON; -out: - release_sock(sk); - return rc; -} - -static int llc_ui_wait_for_disc(struct sock *sk, long timeout) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - int rc = 0; - - add_wait_queue(sk_sleep(sk), &wait); - while (1) { - if (sk_wait_event(sk, &timeout, - READ_ONCE(sk->sk_state) == TCP_CLOSE, &wait)) - break; - rc = -ERESTARTSYS; - if (signal_pending(current)) - break; - rc = -EAGAIN; - if (!timeout) - break; - rc = 0; - } - remove_wait_queue(sk_sleep(sk), &wait); - return rc; -} - -static bool llc_ui_wait_for_conn(struct sock *sk, long timeout) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - - add_wait_queue(sk_sleep(sk), &wait); - while (1) { - if (sk_wait_event(sk, &timeout, - READ_ONCE(sk->sk_state) != TCP_SYN_SENT, &wait)) - break; - if (signal_pending(current) || !timeout) - break; - } - remove_wait_queue(sk_sleep(sk), &wait); - return timeout; -} - -static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - struct llc_sock *llc = llc_sk(sk); - int rc; - - add_wait_queue(sk_sleep(sk), &wait); - while (1) { - rc = 0; - if (sk_wait_event(sk, &timeout, - (READ_ONCE(sk->sk_shutdown) & RCV_SHUTDOWN) || - (!llc_data_accept_state(llc->state) && - !llc->remote_busy_flag && - !llc->p_flag), &wait)) - break; - rc = -ERESTARTSYS; - if (signal_pending(current)) - break; - rc = -EAGAIN; - if (!timeout) - break; - } - remove_wait_queue(sk_sleep(sk), &wait); - return rc; -} - -static int llc_wait_data(struct sock *sk, long timeo) -{ - int rc; - - while (1) { - /* - * POSIX 1003.1g mandates this order. - */ - rc = sock_error(sk); - if (rc) - break; - rc = 0; - if (sk->sk_shutdown & RCV_SHUTDOWN) - break; - rc = -EAGAIN; - if (!timeo) - break; - rc = sock_intr_errno(timeo); - if (signal_pending(current)) - break; - rc = 0; - if (sk_wait_data(sk, &timeo, NULL)) - break; - } - return rc; -} - -static void llc_cmsg_rcv(struct msghdr *msg, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(skb->sk); - - if (llc->cmsg_flags & LLC_CMSG_PKTINFO) { - struct llc_pktinfo info; - - memset(&info, 0, sizeof(info)); - info.lpi_ifindex = llc_sk(skb->sk)->dev->ifindex; - llc_pdu_decode_dsap(skb, &info.lpi_sap); - llc_pdu_decode_da(skb, info.lpi_mac); - put_cmsg(msg, SOL_LLC, LLC_OPT_PKTINFO, sizeof(info), &info); - } -} - -/** - * llc_ui_accept - accept a new incoming connection. - * @sock: Socket which connections arrive on. - * @newsock: Socket to move incoming connection to. - * @arg: User specified arguments - * - * Accept a new incoming connection. - * Returns 0 upon success, negative otherwise. - */ -static int llc_ui_accept(struct socket *sock, struct socket *newsock, - struct proto_accept_arg *arg) -{ - struct sock *sk = sock->sk, *newsk; - struct llc_sock *llc, *newllc; - struct sk_buff *skb; - int rc = -EOPNOTSUPP; - - dprintk("%s: accepting on %02X\n", __func__, - llc_sk(sk)->laddr.lsap); - lock_sock(sk); - if (unlikely(sk->sk_type != SOCK_STREAM)) - goto out; - rc = -EINVAL; - if (unlikely(sock->state != SS_UNCONNECTED || - sk->sk_state != TCP_LISTEN)) - goto out; - /* wait for a connection to arrive. */ - if (skb_queue_empty(&sk->sk_receive_queue)) { - rc = llc_wait_data(sk, READ_ONCE(sk->sk_rcvtimeo)); - if (rc) - goto out; - } - dprintk("%s: got a new connection on %02X\n", __func__, - llc_sk(sk)->laddr.lsap); - skb = skb_dequeue(&sk->sk_receive_queue); - rc = -EINVAL; - if (!skb->sk) - goto frees; - rc = 0; - newsk = skb->sk; - /* attach connection to a new socket. */ - llc_ui_sk_init(newsock, newsk); - sock_reset_flag(newsk, SOCK_ZAPPED); - newsk->sk_state = TCP_ESTABLISHED; - newsock->state = SS_CONNECTED; - llc = llc_sk(sk); - newllc = llc_sk(newsk); - memcpy(&newllc->addr, &llc->addr, sizeof(newllc->addr)); - newllc->link = llc_ui_next_link_no(newllc->laddr.lsap); - - /* put original socket back into a clean listen state. */ - sk->sk_state = TCP_LISTEN; - sk_acceptq_removed(sk); - dprintk("%s: ok success on %02X, client on %02X\n", __func__, - llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap); -frees: - kfree_skb(skb); -out: - release_sock(sk); - return rc; -} - -/** - * llc_ui_recvmsg - copy received data to the socket user. - * @sock: Socket to copy data from. - * @msg: Various user space related information. - * @len: Size of user buffer. - * @flags: User specified flags. - * - * Copy received data to the socket user. - * Returns non-negative upon success, negative otherwise. - */ -static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, - int flags) -{ - DECLARE_SOCKADDR(struct sockaddr_llc *, uaddr, msg->msg_name); - const int nonblock = flags & MSG_DONTWAIT; - struct sk_buff *skb = NULL; - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - size_t copied = 0; - u32 peek_seq = 0; - u32 *seq, skb_len; - unsigned long used; - int target; /* Read at least this many bytes */ - long timeo; - - lock_sock(sk); - copied = -ENOTCONN; - if (unlikely(sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN)) - goto out; - - timeo = sock_rcvtimeo(sk, nonblock); - - seq = &llc->copied_seq; - if (flags & MSG_PEEK) { - peek_seq = llc->copied_seq; - seq = &peek_seq; - } - - target = sock_rcvlowat(sk, flags & MSG_WAITALL, len); - copied = 0; - - do { - u32 offset; - - /* - * We need to check signals first, to get correct SIGURG - * handling. FIXME: Need to check this doesn't impact 1003.1g - * and move it down to the bottom of the loop - */ - if (signal_pending(current)) { - if (copied) - break; - copied = timeo ? sock_intr_errno(timeo) : -EAGAIN; - break; - } - - /* Next get a buffer. */ - - skb = skb_peek(&sk->sk_receive_queue); - if (skb) { - offset = *seq; - goto found_ok_skb; - } - /* Well, if we have backlog, try to process it now yet. */ - - if (copied >= target && !READ_ONCE(sk->sk_backlog.tail)) - break; - - if (copied) { - if (sk->sk_err || - sk->sk_state == TCP_CLOSE || - (sk->sk_shutdown & RCV_SHUTDOWN) || - !timeo || - (flags & MSG_PEEK)) - break; - } else { - if (sock_flag(sk, SOCK_DONE)) - break; - - if (sk->sk_err) { - copied = sock_error(sk); - break; - } - if (sk->sk_shutdown & RCV_SHUTDOWN) - break; - - if (sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_CLOSE) { - if (!sock_flag(sk, SOCK_DONE)) { - /* - * This occurs when user tries to read - * from never connected socket. - */ - copied = -ENOTCONN; - break; - } - break; - } - if (!timeo) { - copied = -EAGAIN; - break; - } - } - - if (copied >= target) { /* Do not sleep, just process backlog. */ - release_sock(sk); - lock_sock(sk); - } else - sk_wait_data(sk, &timeo, NULL); - - if ((flags & MSG_PEEK) && peek_seq != llc->copied_seq) { - net_dbg_ratelimited("LLC(%s:%d): Application bug, race in MSG_PEEK\n", - current->comm, - task_pid_nr(current)); - peek_seq = llc->copied_seq; - } - continue; - found_ok_skb: - skb_len = skb->len; - /* Ok so how much can we use? */ - used = skb->len - offset; - if (len < used) - used = len; - - if (!(flags & MSG_TRUNC)) { - int rc = skb_copy_datagram_msg(skb, offset, msg, used); - if (rc) { - /* Exception. Bailout! */ - if (!copied) - copied = -EFAULT; - break; - } - } - - *seq += used; - copied += used; - len -= used; - - /* For non stream protcols we get one packet per recvmsg call */ - if (sk->sk_type != SOCK_STREAM) - goto copy_uaddr; - - /* Partial read */ - if (used + offset < skb_len) - continue; - - if (!(flags & MSG_PEEK)) { - skb_unlink(skb, &sk->sk_receive_queue); - kfree_skb(skb); - *seq = 0; - } - } while (len > 0); - -out: - release_sock(sk); - return copied; -copy_uaddr: - if (uaddr != NULL && skb != NULL) { - memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr)); - msg->msg_namelen = sizeof(*uaddr); - } - if (llc_sk(sk)->cmsg_flags) - llc_cmsg_rcv(msg, skb); - - if (!(flags & MSG_PEEK)) { - skb_unlink(skb, &sk->sk_receive_queue); - kfree_skb(skb); - *seq = 0; - } - - goto out; -} - -/** - * llc_ui_sendmsg - Transmit data provided by the socket user. - * @sock: Socket to transmit data from. - * @msg: Various user related information. - * @len: Length of data to transmit. - * - * Transmit data provided by the socket user. - * Returns non-negative upon success, negative otherwise. - */ -static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) -{ - DECLARE_SOCKADDR(struct sockaddr_llc *, addr, msg->msg_name); - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - int flags = msg->msg_flags; - int noblock = flags & MSG_DONTWAIT; - int rc = -EINVAL, copied = 0, hdrlen, hh_len; - struct sk_buff *skb = NULL; - struct net_device *dev; - size_t size = 0; - - dprintk("%s: sending from %02X to %02X\n", __func__, - llc->laddr.lsap, llc->daddr.lsap); - lock_sock(sk); - if (addr) { - if (msg->msg_namelen < sizeof(*addr)) - goto out; - } else { - if (llc_ui_addr_null(&llc->addr)) - goto out; - addr = &llc->addr; - } - /* must bind connection to sap if user hasn't done it. */ - if (sock_flag(sk, SOCK_ZAPPED)) { - /* bind to sap with null dev, exclusive. */ - rc = llc_ui_autobind(sock, addr); - if (rc) - goto out; - } - dev = llc->dev; - hh_len = LL_RESERVED_SPACE(dev); - hdrlen = llc_ui_header_len(sk, addr); - size = hdrlen + len; - size = min_t(size_t, size, READ_ONCE(dev->mtu)); - copied = size - hdrlen; - rc = -EINVAL; - if (copied < 0) - goto out; - release_sock(sk); - skb = sock_alloc_send_skb(sk, hh_len + size, noblock, &rc); - lock_sock(sk); - if (!skb) - goto out; - if (sock_flag(sk, SOCK_ZAPPED) || - llc->dev != dev || - hdrlen != llc_ui_header_len(sk, addr) || - hh_len != LL_RESERVED_SPACE(dev) || - size > READ_ONCE(dev->mtu)) - goto out; - skb->dev = dev; - skb->protocol = llc_proto_type(addr->sllc_arphrd); - skb_reserve(skb, hh_len + hdrlen); - rc = memcpy_from_msg(skb_put(skb, copied), msg, copied); - if (rc) - goto out; - if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) { - llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac, - addr->sllc_sap); - skb = NULL; - goto out; - } - if (addr->sllc_test) { - llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac, - addr->sllc_sap); - skb = NULL; - goto out; - } - if (addr->sllc_xid) { - llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac, - addr->sllc_sap); - skb = NULL; - goto out; - } - rc = -ENOPROTOOPT; - if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua)) - goto out; - rc = llc_ui_send_data(sk, skb, noblock); - skb = NULL; -out: - kfree_skb(skb); - if (rc) - dprintk("%s: failed sending from %02X to %02X: %d\n", - __func__, llc->laddr.lsap, llc->daddr.lsap, rc); - release_sock(sk); - return rc ? : copied; -} - -/** - * llc_ui_getname - return the address info of a socket - * @sock: Socket to get address of. - * @uaddr: Address structure to return information. - * @peer: Does user want local or remote address information. - * - * Return the address information of a socket. - */ -static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr, - int peer) -{ - struct sockaddr_llc sllc; - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - int rc = -EBADF; - - memset(&sllc, 0, sizeof(sllc)); - lock_sock(sk); - if (sock_flag(sk, SOCK_ZAPPED)) - goto out; - if (peer) { - rc = -ENOTCONN; - if (sk->sk_state != TCP_ESTABLISHED) - goto out; - if(llc->dev) - sllc.sllc_arphrd = llc->dev->type; - sllc.sllc_sap = llc->daddr.lsap; - memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN); - } else { - rc = -EINVAL; - if (!llc->sap) - goto out; - sllc.sllc_sap = llc->sap->laddr.lsap; - - if (llc->dev) { - sllc.sllc_arphrd = llc->dev->type; - memcpy(&sllc.sllc_mac, llc->dev->dev_addr, - IFHWADDRLEN); - } - } - sllc.sllc_family = AF_LLC; - memcpy(uaddr, &sllc, sizeof(sllc)); - rc = sizeof(sllc); -out: - release_sock(sk); - return rc; -} - -/** - * llc_ui_ioctl - io controls for PF_LLC - * @sock: Socket to get/set info - * @cmd: command - * @arg: optional argument for cmd - * - * get/set info on llc sockets - */ -static int llc_ui_ioctl(struct socket *sock, unsigned int cmd, - unsigned long arg) -{ - return -ENOIOCTLCMD; -} - -/** - * llc_ui_setsockopt - set various connection specific parameters. - * @sock: Socket to set options on. - * @level: Socket level user is requesting operations on. - * @optname: Operation name. - * @optval: User provided operation data. - * @optlen: Length of optval. - * - * Set various connection specific parameters. - */ -static int llc_ui_setsockopt(struct socket *sock, int level, int optname, - sockptr_t optval, unsigned int optlen) -{ - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - unsigned int opt; - int rc = -EINVAL; - - lock_sock(sk); - if (unlikely(level != SOL_LLC || optlen != sizeof(int))) - goto out; - rc = copy_safe_from_sockptr(&opt, sizeof(opt), optval, optlen); - if (rc) - goto out; - rc = -EINVAL; - switch (optname) { - case LLC_OPT_RETRY: - if (opt > LLC_OPT_MAX_RETRY) - goto out; - llc->n2 = opt; - break; - case LLC_OPT_SIZE: - if (opt > LLC_OPT_MAX_SIZE) - goto out; - llc->n1 = opt; - break; - case LLC_OPT_ACK_TMR_EXP: - if (opt > LLC_OPT_MAX_ACK_TMR_EXP) - goto out; - llc->ack_timer.expire = opt * HZ; - break; - case LLC_OPT_P_TMR_EXP: - if (opt > LLC_OPT_MAX_P_TMR_EXP) - goto out; - llc->pf_cycle_timer.expire = opt * HZ; - break; - case LLC_OPT_REJ_TMR_EXP: - if (opt > LLC_OPT_MAX_REJ_TMR_EXP) - goto out; - llc->rej_sent_timer.expire = opt * HZ; - break; - case LLC_OPT_BUSY_TMR_EXP: - if (opt > LLC_OPT_MAX_BUSY_TMR_EXP) - goto out; - llc->busy_state_timer.expire = opt * HZ; - break; - case LLC_OPT_TX_WIN: - if (opt > LLC_OPT_MAX_WIN) - goto out; - llc->k = opt; - break; - case LLC_OPT_RX_WIN: - if (opt > LLC_OPT_MAX_WIN) - goto out; - llc->rw = opt; - break; - case LLC_OPT_PKTINFO: - if (opt) - llc->cmsg_flags |= LLC_CMSG_PKTINFO; - else - llc->cmsg_flags &= ~LLC_CMSG_PKTINFO; - break; - default: - rc = -ENOPROTOOPT; - goto out; - } - rc = 0; -out: - release_sock(sk); - return rc; -} - -/** - * llc_ui_getsockopt - get connection specific socket info - * @sock: Socket to get information from. - * @level: Socket level user is requesting operations on. - * @optname: Operation name. - * @opt: sockopt context with iterator and length for returning data. - * - * Get connection specific socket information. - */ -static int llc_ui_getsockopt(struct socket *sock, int level, int optname, - sockopt_t *opt) -{ - struct sock *sk = sock->sk; - struct llc_sock *llc = llc_sk(sk); - int val = 0, len, rc = -EINVAL; - - lock_sock(sk); - if (unlikely(level != SOL_LLC)) - goto out; - len = opt->optlen; - if (len != sizeof(int)) - goto out; - switch (optname) { - case LLC_OPT_RETRY: - val = llc->n2; break; - case LLC_OPT_SIZE: - val = llc->n1; break; - case LLC_OPT_ACK_TMR_EXP: - val = llc->ack_timer.expire / HZ; break; - case LLC_OPT_P_TMR_EXP: - val = llc->pf_cycle_timer.expire / HZ; break; - case LLC_OPT_REJ_TMR_EXP: - val = llc->rej_sent_timer.expire / HZ; break; - case LLC_OPT_BUSY_TMR_EXP: - val = llc->busy_state_timer.expire / HZ; break; - case LLC_OPT_TX_WIN: - val = llc->k; break; - case LLC_OPT_RX_WIN: - val = llc->rw; break; - case LLC_OPT_PKTINFO: - val = (llc->cmsg_flags & LLC_CMSG_PKTINFO) != 0; - break; - default: - rc = -ENOPROTOOPT; - goto out; - } - rc = 0; - opt->optlen = len; - if (copy_to_iter(&val, len, &opt->iter_out) != len) - rc = -EFAULT; -out: - release_sock(sk); - return rc; -} - -static const struct net_proto_family llc_ui_family_ops = { - .family = PF_LLC, - .create = llc_ui_create, - .owner = THIS_MODULE, -}; - -static const struct proto_ops llc_ui_ops = { - .family = PF_LLC, - .owner = THIS_MODULE, - .release = llc_ui_release, - .bind = llc_ui_bind, - .connect = llc_ui_connect, - .socketpair = sock_no_socketpair, - .accept = llc_ui_accept, - .getname = llc_ui_getname, - .poll = datagram_poll, - .ioctl = llc_ui_ioctl, - .listen = llc_ui_listen, - .shutdown = llc_ui_shutdown, - .setsockopt = llc_ui_setsockopt, - .getsockopt_iter = llc_ui_getsockopt, - .sendmsg = llc_ui_sendmsg, - .recvmsg = llc_ui_recvmsg, - .mmap = sock_no_mmap, -}; - -static const char llc_proc_err_msg[] __initconst = - KERN_CRIT "LLC: Unable to register the proc_fs entries\n"; -static const char llc_sysctl_err_msg[] __initconst = - KERN_CRIT "LLC: Unable to register the sysctl entries\n"; -static const char llc_sock_err_msg[] __initconst = - KERN_CRIT "LLC: Unable to register the network family\n"; - -static int __init llc2_init(void) -{ - int rc = proto_register(&llc_proto, 0); - - if (rc != 0) - goto out; - - llc_build_offset_table(); - llc_station_init(); - llc_ui_sap_last_autoport = LLC_SAP_DYN_START; - rc = llc_proc_init(); - if (rc != 0) { - printk(llc_proc_err_msg); - goto out_station; - } - rc = llc_sysctl_init(); - if (rc) { - printk(llc_sysctl_err_msg); - goto out_proc; - } - rc = sock_register(&llc_ui_family_ops); - if (rc) { - printk(llc_sock_err_msg); - goto out_sysctl; - } - llc_add_pack(LLC_DEST_SAP, llc_sap_handler); - llc_add_pack(LLC_DEST_CONN, llc_conn_handler); -out: - return rc; -out_sysctl: - llc_sysctl_exit(); -out_proc: - llc_proc_exit(); -out_station: - llc_station_exit(); - proto_unregister(&llc_proto); - goto out; -} - -static void __exit llc2_exit(void) -{ - llc_station_exit(); - llc_remove_pack(LLC_DEST_SAP); - llc_remove_pack(LLC_DEST_CONN); - sock_unregister(PF_LLC); - llc_proc_exit(); - llc_sysctl_exit(); - proto_unregister(&llc_proto); -} - -module_init(llc2_init); -module_exit(llc2_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003"); -MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support"); -MODULE_ALIAS_NETPROTO(PF_LLC); diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c deleted file mode 100644 index 1aa7fe28acdd..000000000000 --- a/net/llc/llc_c_ac.c +++ /dev/null @@ -1,1448 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_c_ac.c - actions performed during connection state transition. - * - * Description: - * Functions in this module are implementation of connection component actions - * Details of actions can be found in IEEE-802.2 standard document. - * All functions have one connection and one event as input argument. All of - * them return 0 On success and 1 otherwise. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb); -static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb); -static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev); - -static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb); - -static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, - struct sk_buff *skb); - -static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb); - -#define INCORRECT 0 - -int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (llc->remote_busy_flag) { - u8 nr; - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - llc->remote_busy_flag = 0; - timer_delete(&llc->busy_state_timer.timer); - nr = LLC_I_GET_NR(pdu); - llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); - } - return 0; -} - -int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->ind_prim = LLC_CONN_PRIM; - return 0; -} - -int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->cfm_prim = LLC_CONN_PRIM; - return 0; -} - -static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->cfm_prim = LLC_DATA_PRIM; - return 0; -} - -int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb) -{ - llc_conn_rtn_pdu(sk, skb); - return 0; -} - -int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - u8 reason = 0; - int rc = 0; - - if (ev->type == LLC_CONN_EV_TYPE_PDU) { - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - if (LLC_PDU_IS_RSP(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM) - reason = LLC_DISC_REASON_RX_DM_RSP_PDU; - else if (LLC_PDU_IS_CMD(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC) - reason = LLC_DISC_REASON_RX_DISC_CMD_PDU; - } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR) - reason = LLC_DISC_REASON_ACK_TMR_EXP; - else - rc = -EINVAL; - if (!rc) { - ev->reason = reason; - ev->ind_prim = LLC_DISC_PRIM; - } - return rc; -} - -int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->reason = ev->status; - ev->cfm_prim = LLC_DISC_PRIM; - return 0; -} - -int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb) -{ - u8 reason = 0; - int rc = 1; - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - struct llc_sock *llc = llc_sk(sk); - - switch (ev->type) { - case LLC_CONN_EV_TYPE_PDU: - if (LLC_PDU_IS_RSP(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) { - reason = LLC_RESET_REASON_LOCAL; - rc = 0; - } else if (LLC_PDU_IS_CMD(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) { - reason = LLC_RESET_REASON_REMOTE; - rc = 0; - } - break; - case LLC_CONN_EV_TYPE_ACK_TMR: - case LLC_CONN_EV_TYPE_P_TMR: - case LLC_CONN_EV_TYPE_REJ_TMR: - case LLC_CONN_EV_TYPE_BUSY_TMR: - if (llc->retry_count > llc->n2) { - reason = LLC_RESET_REASON_LOCAL; - rc = 0; - } - break; - } - if (!rc) { - ev->reason = reason; - ev->ind_prim = LLC_RESET_PRIM; - } - return rc; -} - -int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->reason = 0; - ev->cfm_prim = LLC_RESET_PRIM; - return 0; -} - -int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk, - struct sk_buff *skb) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - if (LLC_PDU_IS_RSP(pdu) && - LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf) - llc_conn_ac_clear_remote_busy(sk, skb); - return 0; -} - -int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk, - struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (llc->data_flag == 2) - timer_delete(&llc->rej_sent_timer.timer); - return 0; -} - -int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_disc_cmd(nskb, 1); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - llc_conn_ac_set_p_flag_1(sk, skb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - u8 f_bit; - - llc_pdu_decode_pf_bit(skb, &f_bit); - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_dm_rsp(nskb, f_bit); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_dm_rsp(nskb, 1); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb) -{ - u8 f_bit; - int rc = -ENOBUFS; - struct sk_buff *nskb; - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - struct llc_sock *llc = llc_sk(sk); - - llc->rx_pdu_hdr = *((u32 *)pdu); - if (LLC_PDU_IS_CMD(pdu)) - llc_pdu_decode_pf_bit(skb, &f_bit); - else - f_bit = 0; - nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, - sizeof(struct llc_frmr_info)); - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, - llc->vR, INCORRECT); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, - sizeof(struct llc_frmr_info)); - - if (nskb) { - struct llc_sap *sap = llc->sap; - struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS, - llc->vR, INCORRECT); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) -{ - u8 f_bit; - int rc = -ENOBUFS; - struct sk_buff *nskb; - struct llc_sock *llc = llc_sk(sk); - - llc_pdu_decode_pf_bit(skb, &f_bit); - nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, - sizeof(struct llc_frmr_info)); - if (nskb) { - struct llc_sap *sap = llc->sap; - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, - llc->vR, INCORRECT); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc; - struct llc_sock *llc = llc_sk(sk); - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR); - rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); - if (likely(!rc)) { - skb_get(skb); - llc_conn_send_pdu(sk, skb); - llc_conn_ac_inc_vs_by_1(sk, skb); - } - return rc; -} - -static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc; - struct llc_sock *llc = llc_sk(sk); - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); - rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); - if (likely(!rc)) { - skb_get(skb); - llc_conn_send_pdu(sk, skb); - llc_conn_ac_inc_vs_by_1(sk, skb); - } - return rc; -} - -int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc; - struct llc_sock *llc = llc_sk(sk); - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); - rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); - if (likely(!rc)) { - skb_get(skb); - llc_conn_send_pdu(sk, skb); - llc_conn_ac_inc_vs_by_1(sk, skb); - } - return 0; -} - -int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - u8 nr = LLC_I_GET_NR(pdu); - - llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); - return 0; -} - -int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk, - struct sk_buff *skb) -{ - u8 nr; - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (likely(!rc)) - llc_conn_send_pdu(sk, nskb); - else - kfree_skb(nskb); - } - if (rc) { - nr = LLC_I_GET_NR(pdu); - rc = 0; - llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); - } - return rc; -} - -int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - u8 nr = LLC_I_GET_NR(pdu); - - llc_conn_resend_i_pdu_as_rsp(sk, nr, 1); - return 0; -} - -int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (!llc->remote_busy_flag) { - llc->remote_busy_flag = 1; - mod_timer(&llc->busy_state_timer.timer, - jiffies + llc->busy_state_timer.expire); - } - return 0; -} - -int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - u8 f_bit = 1; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -void llc_conn_set_p_flag(struct sock *sk, u8 value) -{ - int state_changed = llc_sk(sk)->p_flag && !value; - - llc_sk(sk)->p_flag = value; - - if (state_changed) - sk->sk_state_change(sk); -} - -int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - const u8 *dmac = llc->daddr.mac; - - if (llc->dev->flags & IFF_LOOPBACK) - dmac = llc->dev->dev_addr; - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_sabme_cmd(nskb, 1); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - llc_conn_set_p_flag(sk, 1); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) -{ - u8 f_bit; - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); - - llc_pdu_decode_pf_bit(skb, &f_bit); - if (nskb) { - struct llc_sap *sap = llc->sap; - - nskb->dev = llc->dev; - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_ua_rsp(nskb, f_bit); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->s_flag = 0; - return 0; -} - -int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->s_flag = 1; - return 0; -} - -int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - llc_conn_set_p_flag(sk, 1); - mod_timer(&llc->pf_cycle_timer.timer, - jiffies + llc->pf_cycle_timer.expire); - return 0; -} - -/** - * llc_conn_ac_send_ack_if_needed - check if ack is needed - * @sk: current connection structure - * @skb: current event - * - * Checks number of received PDUs which have not been acknowledged, yet, - * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then - * sends an RR response as acknowledgement for them. Returns 0 for - * success, 1 otherwise. - */ -int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb) -{ - u8 pf_bit; - struct llc_sock *llc = llc_sk(sk); - - llc_pdu_decode_pf_bit(skb, &pf_bit); - llc->ack_pf |= pf_bit & 1; - if (!llc->ack_must_be_send) { - llc->first_pdu_Ns = llc->vR; - llc->ack_must_be_send = 1; - llc->ack_pf = pf_bit & 1; - } - if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO) - % LLC_2_SEQ_NBR_MODULO) >= llc->npta) { - llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb); - llc->ack_must_be_send = 0; - llc->ack_pf = 0; - llc_conn_ac_inc_npta_value(sk, skb); - } - return 0; -} - -/** - * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag - * @sk: current connection structure - * @skb: current event - * - * This action resets ack_must_be_send flag of given connection, this flag - * indicates if there is any PDU which has not been acknowledged yet. - * Returns 0 for success, 1 otherwise. - */ -int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0; - return 0; -} - -/** - * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs - * @sk: current connection structure - * @skb: current event - * - * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to - * all received PDUs which have not been acknowledged, yet. ack_pf flag is - * set to one if one PDU with p-bit set to one is received. Returns 0 for - * success, 1 otherwise. - */ -static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk, - struct sk_buff *skb) -{ - int rc; - struct llc_sock *llc = llc_sk(sk); - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR); - rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); - if (likely(!rc)) { - skb_get(skb); - llc_conn_send_pdu(sk, skb); - llc_conn_ac_inc_vs_by_1(sk, skb); - } - return rc; -} - -/** - * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs - * @sk: current connection structure. - * @skb: current event. - * - * This action sends an I-format PDU as acknowledge to received PDUs which - * have not been acknowledged, yet, if there is any. By using of this - * action number of acknowledgements decreases, this technic is called - * piggy backing. Returns 0 for success, 1 otherwise. - */ -int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - int ret; - - if (llc->ack_must_be_send) { - ret = llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb); - llc->ack_must_be_send = 0 ; - llc->ack_pf = 0; - } else { - ret = llc_conn_ac_send_i_cmd_p_set_0(sk, skb); - } - - return ret; -} - -/** - * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked - * @sk: current connection structure. - * @skb: current event. - * - * This action sends an RR response with f-bit set to ack_pf flag as - * acknowledge to all received PDUs which have not been acknowledged, yet, - * if there is any. ack_pf flag indicates if a PDU has been received with - * p-bit set to one. Returns 0 for success, 1 otherwise. - */ -static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, - struct sk_buff *skb) -{ - int rc = -ENOBUFS; - struct llc_sock *llc = llc_sk(sk); - struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); - - if (nskb) { - struct llc_sap *sap = llc->sap; - - llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, - llc->daddr.lsap, LLC_PDU_RSP); - llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR); - rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); - if (unlikely(rc)) - goto free; - llc_conn_send_pdu(sk, nskb); - } -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -/** - * llc_conn_ac_inc_npta_value - tries to make value of npta greater - * @sk: current connection structure. - * @skb: current event. - * - * After "inc_cntr" times calling of this action, "npta" increase by one. - * this action tries to make vale of "npta" greater as possible; number of - * acknowledgements decreases by increasing of "npta". Returns 0 for - * success, 1 otherwise. - */ -static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (!llc->inc_cntr) { - llc->dec_step = 0; - llc->dec_cntr = llc->inc_cntr = 2; - ++llc->npta; - if (llc->npta > LLC_2_SEQ_NBR_MODULO - 1) - llc->npta = LLC_2_SEQ_NBR_MODULO - 1; - } else - --llc->inc_cntr; - return 0; -} - -/** - * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one - * @sk: current connection structure. - * @skb: current event. - * - * After receiving "dec_cntr" times RR command, this action decreases - * "npta" by one. Returns 0 for success, 1 otherwise. - */ -int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (!llc->connect_step && !llc->remote_busy_flag) { - if (!llc->dec_step) { - if (!llc->dec_cntr) { - llc->inc_cntr = llc->dec_cntr = 2; - if (llc->npta > 0) - llc->npta = llc->npta - 1; - } else - llc->dec_cntr -=1; - } - } else - llc->connect_step = 0 ; - return 0; -} - -/** - * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one - * @sk: current connection structure. - * @skb: current event. - * - * After receiving "dec_cntr" times RNR command, this action decreases - * "npta" by one. Returns 0 for success, 1 otherwise. - */ -int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (llc->remote_busy_flag) - if (!llc->dec_step) { - if (!llc->dec_cntr) { - llc->inc_cntr = llc->dec_cntr = 2; - if (llc->npta > 0) - --llc->npta; - } else - --llc->dec_cntr; - } - return 0; -} - -/** - * llc_conn_ac_dec_tx_win_size - decreases tx window size - * @sk: current connection structure. - * @skb: current event. - * - * After receiving of a REJ command or response, transmit window size is - * decreased by number of PDUs which are outstanding yet. Returns 0 for - * success, 1 otherwise. - */ -int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q); - - if (llc->k - unacked_pdu < 1) - llc->k = 1; - else - llc->k -= unacked_pdu; - return 0; -} - -/** - * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1 - * @sk: current connection structure. - * @skb: current event. - * - * After receiving an RR response with f-bit set to one, transmit window - * size is increased by one. Returns 0 for success, 1 otherwise. - */ -int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - llc->k += 1; - if (llc->k > LLC_2_SEQ_NBR_MODULO - 1) - llc->k = LLC_2_SEQ_NBR_MODULO - 1; - return 0; -} - -int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb) -{ - llc_sk_stop_all_timers(sk, false); - return 0; -} - -int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - timer_delete(&llc->rej_sent_timer.timer); - timer_delete(&llc->pf_cycle_timer.timer); - timer_delete(&llc->busy_state_timer.timer); - llc->ack_must_be_send = 0; - llc->ack_pf = 0; - return 0; -} - -int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire); - return 0; -} - -int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - mod_timer(&llc->rej_sent_timer.timer, - jiffies + llc->rej_sent_timer.expire); - return 0; -} - -int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk, - struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - if (!timer_pending(&llc->ack_timer.timer)) - mod_timer(&llc->ack_timer.timer, - jiffies + llc->ack_timer.expire); - return 0; -} - -int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb) -{ - timer_delete(&llc_sk(sk)->ack_timer.timer); - return 0; -} - -int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb) -{ - struct llc_sock *llc = llc_sk(sk); - - timer_delete(&llc->pf_cycle_timer.timer); - llc_conn_set_p_flag(sk, 0); - return 0; -} - -int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb) -{ - timer_delete(&llc_sk(sk)->rej_sent_timer.timer); - return 0; -} - -int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb) -{ - int acked; - u16 unacked = 0; - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - struct llc_sock *llc = llc_sk(sk); - - llc->last_nr = PDU_SUPV_GET_Nr(pdu); - acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked); - /* On loopback we don't queue I frames in unack_pdu_q queue. */ - if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) { - llc->retry_count = 0; - timer_delete(&llc->ack_timer.timer); - if (llc->failed_data_req) { - /* already, we did not accept data from upper layer - * (tx_window full or unacceptable state). Now, we - * can send data and must inform to upper layer. - */ - llc->failed_data_req = 0; - llc_conn_ac_data_confirm(sk, skb); - } - if (unacked) - mod_timer(&llc->ack_timer.timer, - jiffies + llc->ack_timer.expire); - } else if (llc->failed_data_req) { - u8 f_bit; - - llc_pdu_decode_pf_bit(skb, &f_bit); - if (f_bit == 1) { - llc->failed_data_req = 0; - llc_conn_ac_data_confirm(sk, skb); - } - } - return 0; -} - -int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - if (LLC_PDU_IS_RSP(pdu)) { - u8 f_bit; - - llc_pdu_decode_pf_bit(skb, &f_bit); - if (f_bit) { - llc_conn_set_p_flag(sk, 0); - llc_conn_ac_stop_p_timer(sk, skb); - } - } - return 0; -} - -int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->data_flag = 2; - return 0; -} - -int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->data_flag = 0; - return 0; -} - -int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->data_flag = 1; - return 0; -} - -int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk, - struct sk_buff *skb) -{ - if (!llc_sk(sk)->data_flag) - llc_sk(sk)->data_flag = 1; - return 0; -} - -int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb) -{ - llc_conn_set_p_flag(sk, 0); - return 0; -} - -static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb) -{ - llc_conn_set_p_flag(sk, 1); - return 0; -} - -int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->remote_busy_flag = 0; - return 0; -} - -int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->cause_flag = 0; - return 0; -} - -int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->cause_flag = 1; - return 0; -} - -int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->retry_count = 0; - return 0; -} - -int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->retry_count++; - return 0; -} - -int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->vR = 0; - return 0; -} - -int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR); - return 0; -} - -int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->vS = 0; - return 0; -} - -int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->vS = llc_sk(sk)->last_nr; - return 0; -} - -static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO; - return 0; -} - -static void llc_conn_tmr_common_cb(struct sock *sk, u8 type) -{ - struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); - - bh_lock_sock(sk); - if (skb) { - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - skb_set_owner_r(skb, sk); - ev->type = type; - llc_process_tmr_ev(sk, skb); - } - bh_unlock_sock(sk); -} - -void llc_conn_pf_cycle_tmr_cb(struct timer_list *t) -{ - struct llc_sock *llc = timer_container_of(llc, t, - pf_cycle_timer.timer); - - llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_P_TMR); -} - -void llc_conn_busy_tmr_cb(struct timer_list *t) -{ - struct llc_sock *llc = timer_container_of(llc, t, - busy_state_timer.timer); - - llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_BUSY_TMR); -} - -void llc_conn_ack_tmr_cb(struct timer_list *t) -{ - struct llc_sock *llc = timer_container_of(llc, t, ack_timer.timer); - - llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_ACK_TMR); -} - -void llc_conn_rej_tmr_cb(struct timer_list *t) -{ - struct llc_sock *llc = timer_container_of(llc, t, - rej_sent_timer.timer); - - llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_REJ_TMR); -} - -int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb) -{ - llc_sk(sk)->X = llc_sk(sk)->vS; - llc_conn_ac_set_vs_nr(sk, skb); - return 0; -} - -int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - u8 nr = PDU_SUPV_GET_Nr(pdu); - - if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X)) - llc_conn_ac_set_vs_nr(sk, skb); - return 0; -} - -/* - * Non-standard actions; these not contained in IEEE specification; for - * our own usage - */ -/** - * llc_conn_disc - removes connection from SAP list and frees it - * @sk: closed connection - * @skb: occurred event - */ -int llc_conn_disc(struct sock *sk, struct sk_buff *skb) -{ - /* FIXME: this thing seems to want to die */ - return 0; -} - -/** - * llc_conn_reset - resets connection - * @sk : reseting connection. - * @skb: occurred event. - * - * Stop all timers, empty all queues and reset all flags. - */ -int llc_conn_reset(struct sock *sk, struct sk_buff *skb) -{ - llc_sk_reset(sk); - return 0; -} - -/** - * llc_circular_between - designates that b is between a and c or not - * @a: lower bound - * @b: element to see if is between a and b - * @c: upper bound - * - * This function designates that b is between a and c or not (for example, - * 0 is between 127 and 1). Returns 1 if b is between a and c, 0 - * otherwise. - */ -u8 llc_circular_between(u8 a, u8 b, u8 c) -{ - b = b - a; - c = c - a; - return b <= c; -} - -/** - * llc_process_tmr_ev - timer backend - * @sk: active connection - * @skb: occurred event - * - * This function is called from timer callback functions. When connection - * is busy (during sending a data frame) timer expiration event must be - * queued. Otherwise this event can be sent to connection state machine. - * Queued events will process by llc_backlog_rcv function after sending - * data frame. - */ -static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb) -{ - if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) { - printk(KERN_WARNING "%s: timer called on closed connection\n", - __func__); - kfree_skb(skb); - } else { - if (!sock_owned_by_user(sk)) - llc_conn_state_process(sk, skb); - else { - llc_set_backlog_type(skb, LLC_EVENT); - __sk_add_backlog(sk, skb); - } - } -} diff --git a/net/llc/llc_c_ev.c b/net/llc/llc_c_ev.c deleted file mode 100644 index beb2836c7db0..000000000000 --- a/net/llc/llc_c_ev.c +++ /dev/null @@ -1,742 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_c_ev.c - Connection component state transition event qualifiers - * - * A 'state' consists of a number of possible event matching functions, - * the actions associated with each being executed when that event is - * matched; a 'state machine' accepts events in a serial fashion from an - * event queue. Each event is passed to each successive event matching - * function until a match is made (the event matching function returns - * success, or '0') or the list of event matching functions is exhausted. - * If a match is made, the actions associated with the event are executed - * and the state is changed to that event's transition state. Before some - * events are recognized, even after a match has been made, a certain - * number of 'event qualifier' functions must also be executed. If these - * all execute successfully, then the event is finally executed. - * - * These event functions must return 0 for success, to show a matched - * event, of 1 if the event does not match. Event qualifier functions - * must return a 0 for success or a non-zero for failure. Each function - * is simply responsible for verifying one single thing and returning - * either a success or failure. - * - * All of followed event functions are described in 802.2 LLC Protocol - * standard document except two functions that we added that will explain - * in their comments, at below. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include -#include -#include - -#if 1 -#define dprintk(args...) printk(KERN_DEBUG args) -#else -#define dprintk(args...) -#endif - -/** - * llc_util_ns_inside_rx_window - check if sequence number is in rx window - * @ns: sequence number of received pdu. - * @vr: sequence number which receiver expects to receive. - * @rw: receive window size of receiver. - * - * Checks if sequence number of received PDU is in range of receive - * window. Returns 0 for success, 1 otherwise - */ -static u16 llc_util_ns_inside_rx_window(u8 ns, u8 vr, u8 rw) -{ - return !llc_circular_between(vr, ns, - (vr + rw - 1) % LLC_2_SEQ_NBR_MODULO); -} - -/** - * llc_util_nr_inside_tx_window - check if sequence number is in tx window - * @sk: current connection. - * @nr: N(R) of received PDU. - * - * This routine checks if N(R) of received PDU is in range of transmit - * window; on the other hand checks if received PDU acknowledges some - * outstanding PDUs that are in transmit window. Returns 0 for success, 1 - * otherwise. - */ -static u16 llc_util_nr_inside_tx_window(struct sock *sk, u8 nr) -{ - u8 nr1, nr2; - struct sk_buff *skb; - struct llc_pdu_sn *pdu; - struct llc_sock *llc = llc_sk(sk); - int rc = 0; - - if (llc->dev->flags & IFF_LOOPBACK) - goto out; - rc = 1; - if (skb_queue_empty(&llc->pdu_unack_q)) - goto out; - skb = skb_peek(&llc->pdu_unack_q); - pdu = llc_pdu_sn_hdr(skb); - nr1 = LLC_I_GET_NS(pdu); - skb = skb_peek_tail(&llc->pdu_unack_q); - pdu = llc_pdu_sn_hdr(skb); - nr2 = LLC_I_GET_NS(pdu); - rc = !llc_circular_between(nr1, nr, (nr2 + 1) % LLC_2_SEQ_NBR_MODULO); -out: - return rc; -} - -int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->prim == LLC_CONN_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; -} - -int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->prim == LLC_DATA_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; -} - -int llc_conn_ev_disc_req(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->prim == LLC_DISC_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; -} - -int llc_conn_ev_rst_req(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->prim == LLC_RESET_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; -} - -int llc_conn_ev_local_busy_detected(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type == LLC_CONN_EV_TYPE_SIMPLE && - ev->prim_type == LLC_CONN_EV_LOCAL_BUSY_DETECTED ? 0 : 1; -} - -int llc_conn_ev_local_busy_cleared(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type == LLC_CONN_EV_TYPE_SIMPLE && - ev->prim_type == LLC_CONN_EV_LOCAL_BUSY_CLEARED ? 0 : 1; -} - -int llc_conn_ev_rx_bad_pdu(struct sock *sk, struct sk_buff *skb) -{ - return 1; -} - -int llc_conn_ev_rx_disc_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC ? 0 : 1; -} - -int llc_conn_ev_rx_dm_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM ? 0 : 1; -} - -int llc_conn_ev_rx_frmr_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR ? 0 : 1; -} - -int llc_conn_ev_rx_i_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return llc_conn_space(sk, skb) && - LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_0(pdu) && - LLC_I_GET_NS(pdu) == llc_sk(sk)->vR ? 0 : 1; -} - -int llc_conn_ev_rx_i_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return llc_conn_space(sk, skb) && - LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_1(pdu) && - LLC_I_GET_NS(pdu) == llc_sk(sk)->vR ? 0 : 1; -} - -int llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_0(pdu) && ns != vr && - !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; -} - -int llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_1(pdu) && ns != vr && - !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; -} - -int llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn * pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - const u16 rc = LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - ns != vr && - llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; - if (!rc) - dprintk("%s: matched, state=%d, ns=%d, vr=%d\n", - __func__, llc_sk(sk)->state, ns, vr); - return rc; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return llc_conn_space(sk, skb) && - LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_0(pdu) && - LLC_I_GET_NS(pdu) == llc_sk(sk)->vR ? 0 : 1; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_1(pdu) && - LLC_I_GET_NS(pdu) == llc_sk(sk)->vR ? 0 : 1; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return llc_conn_space(sk, skb) && - LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_GET_NS(pdu) == llc_sk(sk)->vR ? 0 : 1; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_0(pdu) && ns != vr && - !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - LLC_I_PF_IS_1(pdu) && ns != vr && - !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && ns != vr && - !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; -} - -int llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vr = llc_sk(sk)->vR; - const u8 ns = LLC_I_GET_NS(pdu); - const u16 rc = LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && - ns != vr && - llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; - if (!rc) - dprintk("%s: matched, state=%d, ns=%d, vr=%d\n", - __func__, llc_sk(sk)->state, ns, vr); - return rc; -} - -int llc_conn_ev_rx_rej_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_0(pdu) && - LLC_S_PDU_CMD(pdu) == LLC_2_PDU_CMD_REJ ? 0 : 1; -} - -int llc_conn_ev_rx_rej_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_1(pdu) && - LLC_S_PDU_CMD(pdu) == LLC_2_PDU_CMD_REJ ? 0 : 1; -} - -int llc_conn_ev_rx_rej_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_0(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_REJ ? 0 : 1; -} - -int llc_conn_ev_rx_rej_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_1(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_REJ ? 0 : 1; -} - -int llc_conn_ev_rx_rej_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_REJ ? 0 : 1; -} - -int llc_conn_ev_rx_rnr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_0(pdu) && - LLC_S_PDU_CMD(pdu) == LLC_2_PDU_CMD_RNR ? 0 : 1; -} - -int llc_conn_ev_rx_rnr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_1(pdu) && - LLC_S_PDU_CMD(pdu) == LLC_2_PDU_CMD_RNR ? 0 : 1; -} - -int llc_conn_ev_rx_rnr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_0(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_RNR ? 0 : 1; -} - -int llc_conn_ev_rx_rnr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_1(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_RNR ? 0 : 1; -} - -int llc_conn_ev_rx_rr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_0(pdu) && - LLC_S_PDU_CMD(pdu) == LLC_2_PDU_CMD_RR ? 0 : 1; -} - -int llc_conn_ev_rx_rr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_1(pdu) && - LLC_S_PDU_CMD(pdu) == LLC_2_PDU_CMD_RR ? 0 : 1; -} - -int llc_conn_ev_rx_rr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return llc_conn_space(sk, skb) && - LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_0(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_RR ? 0 : 1; -} - -int llc_conn_ev_rx_rr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - return llc_conn_space(sk, skb) && - LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && - LLC_S_PF_IS_1(pdu) && - LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_RR ? 0 : 1; -} - -int llc_conn_ev_rx_sabme_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME ? 0 : 1; -} - -int llc_conn_ev_rx_ua_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_UA ? 0 : 1; -} - -int llc_conn_ev_rx_xxx_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) -{ - u16 rc = 1; - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - if (LLC_PDU_IS_CMD(pdu)) { - if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) { - if (LLC_I_PF_IS_1(pdu)) - rc = 0; - } else if (LLC_PDU_TYPE_IS_U(pdu) && LLC_U_PF_IS_1(pdu)) - rc = 0; - } - return rc; -} - -int llc_conn_ev_rx_xxx_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - u16 rc = 1; - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - if (LLC_PDU_IS_CMD(pdu)) { - if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) - rc = 0; - else if (LLC_PDU_TYPE_IS_U(pdu)) - switch (LLC_U_PDU_CMD(pdu)) { - case LLC_2_PDU_CMD_SABME: - case LLC_2_PDU_CMD_DISC: - rc = 0; - break; - } - } - return rc; -} - -int llc_conn_ev_rx_xxx_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) -{ - u16 rc = 1; - const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - if (LLC_PDU_IS_RSP(pdu)) { - if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) - rc = 0; - else if (LLC_PDU_TYPE_IS_U(pdu)) - switch (LLC_U_PDU_RSP(pdu)) { - case LLC_2_PDU_RSP_UA: - case LLC_2_PDU_RSP_DM: - case LLC_2_PDU_RSP_FRMR: - rc = 0; - break; - } - } - - return rc; -} - -int llc_conn_ev_rx_zzz_cmd_pbit_set_x_inval_nr(struct sock *sk, - struct sk_buff *skb) -{ - u16 rc = 1; - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vs = llc_sk(sk)->vS; - const u8 nr = LLC_I_GET_NR(pdu); - - if (LLC_PDU_IS_CMD(pdu) && - (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) && - nr != vs && llc_util_nr_inside_tx_window(sk, nr)) { - dprintk("%s: matched, state=%d, vs=%d, nr=%d\n", - __func__, llc_sk(sk)->state, vs, nr); - rc = 0; - } - return rc; -} - -int llc_conn_ev_rx_zzz_rsp_fbit_set_x_inval_nr(struct sock *sk, - struct sk_buff *skb) -{ - u16 rc = 1; - const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - const u8 vs = llc_sk(sk)->vS; - const u8 nr = LLC_I_GET_NR(pdu); - - if (LLC_PDU_IS_RSP(pdu) && - (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) && - nr != vs && llc_util_nr_inside_tx_window(sk, nr)) { - rc = 0; - dprintk("%s: matched, state=%d, vs=%d, nr=%d\n", - __func__, llc_sk(sk)->state, vs, nr); - } - return rc; -} - -int llc_conn_ev_rx_any_frame(struct sock *sk, struct sk_buff *skb) -{ - return 0; -} - -int llc_conn_ev_p_tmr_exp(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type != LLC_CONN_EV_TYPE_P_TMR; -} - -int llc_conn_ev_ack_tmr_exp(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type != LLC_CONN_EV_TYPE_ACK_TMR; -} - -int llc_conn_ev_rej_tmr_exp(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type != LLC_CONN_EV_TYPE_REJ_TMR; -} - -int llc_conn_ev_busy_tmr_exp(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type != LLC_CONN_EV_TYPE_BUSY_TMR; -} - -int llc_conn_ev_init_p_f_cycle(struct sock *sk, struct sk_buff *skb) -{ - return 1; -} - -int llc_conn_ev_tx_buffer_full(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - return ev->type == LLC_CONN_EV_TYPE_SIMPLE && - ev->prim_type == LLC_CONN_EV_TX_BUFF_FULL ? 0 : 1; -} - -/* Event qualifier functions - * - * these functions simply verify the value of a state flag associated with - * the connection and return either a 0 for success or a non-zero value - * for not-success; verify the event is the type we expect - */ -int llc_conn_ev_qlfy_data_flag_eq_1(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->data_flag != 1; -} - -int llc_conn_ev_qlfy_data_flag_eq_0(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->data_flag; -} - -int llc_conn_ev_qlfy_data_flag_eq_2(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->data_flag != 2; -} - -int llc_conn_ev_qlfy_p_flag_eq_1(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->p_flag != 1; -} - -/** - * llc_conn_ev_qlfy_last_frame_eq_1 - checks if frame is last in tx window - * @sk: current connection structure. - * @skb: current event. - * - * This function determines when frame which is sent, is last frame of - * transmit window, if it is then this function return zero else return - * one. This function is used for sending last frame of transmit window - * as I-format command with p-bit set to one. Returns 0 if frame is last - * frame, 1 otherwise. - */ -int llc_conn_ev_qlfy_last_frame_eq_1(struct sock *sk, struct sk_buff *skb) -{ - return !(skb_queue_len(&llc_sk(sk)->pdu_unack_q) + 1 == llc_sk(sk)->k); -} - -/** - * llc_conn_ev_qlfy_last_frame_eq_0 - checks if frame isn't last in tx window - * @sk: current connection structure. - * @skb: current event. - * - * This function determines when frame which is sent, isn't last frame of - * transmit window, if it isn't then this function return zero else return - * one. Returns 0 if frame isn't last frame, 1 otherwise. - */ -int llc_conn_ev_qlfy_last_frame_eq_0(struct sock *sk, struct sk_buff *skb) -{ - return skb_queue_len(&llc_sk(sk)->pdu_unack_q) + 1 == llc_sk(sk)->k; -} - -int llc_conn_ev_qlfy_p_flag_eq_0(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->p_flag; -} - -int llc_conn_ev_qlfy_p_flag_eq_f(struct sock *sk, struct sk_buff *skb) -{ - u8 f_bit; - - llc_pdu_decode_pf_bit(skb, &f_bit); - return llc_sk(sk)->p_flag == f_bit ? 0 : 1; -} - -int llc_conn_ev_qlfy_remote_busy_eq_0(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->remote_busy_flag; -} - -int llc_conn_ev_qlfy_remote_busy_eq_1(struct sock *sk, struct sk_buff *skb) -{ - return !llc_sk(sk)->remote_busy_flag; -} - -int llc_conn_ev_qlfy_retry_cnt_lt_n2(struct sock *sk, struct sk_buff *skb) -{ - return !(llc_sk(sk)->retry_count < llc_sk(sk)->n2); -} - -int llc_conn_ev_qlfy_retry_cnt_gte_n2(struct sock *sk, struct sk_buff *skb) -{ - return !(llc_sk(sk)->retry_count >= llc_sk(sk)->n2); -} - -int llc_conn_ev_qlfy_s_flag_eq_1(struct sock *sk, struct sk_buff *skb) -{ - return !llc_sk(sk)->s_flag; -} - -int llc_conn_ev_qlfy_s_flag_eq_0(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->s_flag; -} - -int llc_conn_ev_qlfy_cause_flag_eq_1(struct sock *sk, struct sk_buff *skb) -{ - return !llc_sk(sk)->cause_flag; -} - -int llc_conn_ev_qlfy_cause_flag_eq_0(struct sock *sk, struct sk_buff *skb) -{ - return llc_sk(sk)->cause_flag; -} - -int llc_conn_ev_qlfy_set_status_conn(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_CONN; - return 0; -} - -int llc_conn_ev_qlfy_set_status_disc(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_DISC; - return 0; -} - -int llc_conn_ev_qlfy_set_status_failed(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_FAILED; - return 0; -} - -int llc_conn_ev_qlfy_set_status_remote_busy(struct sock *sk, - struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_REMOTE_BUSY; - return 0; -} - -int llc_conn_ev_qlfy_set_status_refuse(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_REFUSE; - return 0; -} - -int llc_conn_ev_qlfy_set_status_conflict(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_CONFLICT; - return 0; -} - -int llc_conn_ev_qlfy_set_status_rst_done(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->status = LLC_STATUS_RESET_DONE; - return 0; -} diff --git a/net/llc/llc_c_st.c b/net/llc/llc_c_st.c deleted file mode 100644 index 5fbd8d19c6c4..000000000000 --- a/net/llc/llc_c_st.c +++ /dev/null @@ -1,4940 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_c_st.c - This module contains state transition of connection component. - * - * Description of event functions and actions there is in 802.2 LLC standard, - * or in "llc_c_ac.c" and "llc_c_ev.c" modules. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include -#include - -#define NONE NULL - -/* COMMON CONNECTION STATE transitions - * Common transitions for - * LLC_CONN_STATE_NORMAL, - * LLC_CONN_STATE_BUSY, - * LLC_CONN_STATE_REJ, - * LLC_CONN_STATE_AWAIT, - * LLC_CONN_STATE_AWAIT_BUSY and - * LLC_CONN_STATE_AWAIT_REJ states - */ -/* State transitions for LLC_CONN_EV_DISC_REQ event */ -static const llc_conn_action_t llc_common_actions_1[] = { - [0] = llc_conn_ac_send_disc_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_1 = { - .ev = llc_conn_ev_disc_req, - .next_state = LLC_CONN_STATE_D_CONN, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RESET_REQ event */ -static const llc_conn_action_t llc_common_actions_2[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_2 = { - .ev = llc_conn_ev_rst_req, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_2, -}; - -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_common_actions_3[] = { - [0] = llc_conn_ac_stop_all_timers, - [1] = llc_conn_ac_set_vs_0, - [2] = llc_conn_ac_set_vr_0, - [3] = llc_conn_ac_send_ua_rsp_f_set_p, - [4] = llc_conn_ac_rst_ind, - [5] = llc_conn_ac_set_p_flag_0, - [6] = llc_conn_ac_set_remote_busy_0, - [7] = llc_conn_reset, - [8] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_3 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_common_actions_4[] = { - [0] = llc_conn_ac_stop_all_timers, - [1] = llc_conn_ac_send_ua_rsp_f_set_p, - [2] = llc_conn_ac_disc_ind, - [3] = llc_conn_disc, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_4 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_FRMR_RSP_Fbit_SET_X event */ -static const llc_conn_action_t llc_common_actions_5[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_rst_ind, - [5] = llc_conn_ac_set_cause_flag_0, - [6] = llc_conn_reset, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_5 = { - .ev = llc_conn_ev_rx_frmr_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_5, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event */ -static const llc_conn_action_t llc_common_actions_6[] = { - [0] = llc_conn_ac_disc_ind, - [1] = llc_conn_ac_stop_all_timers, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_6 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_6, -}; - -/* State transitions for LLC_CONN_EV_RX_ZZZ_CMD_Pbit_SET_X_INVAL_Nr event */ -static const llc_conn_action_t llc_common_actions_7a[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_7a = { - .ev = llc_conn_ev_rx_zzz_cmd_pbit_set_x_inval_nr, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_7a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_X_INVAL_Ns event */ -static const llc_conn_action_t llc_common_actions_7b[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_7b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_7b, -}; - -/* State transitions for LLC_CONN_EV_RX_ZZZ_RSP_Fbit_SET_X_INVAL_Nr event */ -static const llc_conn_action_t llc_common_actions_8a[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_8a = { - .ev = llc_conn_ev_rx_zzz_rsp_fbit_set_x_inval_nr, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_8a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_X_INVAL_Ns event */ -static const llc_conn_action_t llc_common_actions_8b[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_8b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_8b, -}; - -/* State transitions for LLC_CONN_EV_RX_BAD_PDU event */ -static const llc_conn_action_t llc_common_actions_8c[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_8c = { - .ev = llc_conn_ev_rx_bad_pdu, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_8c, -}; - -/* State transitions for LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X event */ -static const llc_conn_action_t llc_common_actions_9[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_9 = { - .ev = llc_conn_ev_rx_ua_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_common_actions_9, -}; - -/* State transitions for LLC_CONN_EV_RX_XXX_RSP_Fbit_SET_1 event */ -#if 0 -static const llc_conn_ev_qfyr_t llc_common_ev_qfyrs_10[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_common_actions_10[] = { - [0] = llc_conn_ac_send_frmr_rsp_f_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_10 = { - .ev = llc_conn_ev_rx_xxx_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = llc_common_ev_qfyrs_10, - .ev_actions = llc_common_actions_10, -}; -#endif - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_common_ev_qfyrs_11a[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_common_actions_11a[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_0, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_11a = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_common_ev_qfyrs_11a, - .ev_actions = llc_common_actions_11a, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_common_ev_qfyrs_11b[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_common_actions_11b[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_0, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_11b = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_common_ev_qfyrs_11b, - .ev_actions = llc_common_actions_11b, -}; - -/* State transitions for LLC_CONN_EV_REJ_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_common_ev_qfyrs_11c[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_common_actions_11c[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_0, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_11c = { - .ev = llc_conn_ev_rej_tmr_exp, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_common_ev_qfyrs_11c, - .ev_actions = llc_common_actions_11c, -}; - -/* State transitions for LLC_CONN_EV_BUSY_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_common_ev_qfyrs_11d[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_common_actions_11d[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_stop_other_timers, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_0, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_common_state_trans_11d = { - .ev = llc_conn_ev_busy_tmr_exp, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_common_ev_qfyrs_11d, - .ev_actions = llc_common_actions_11d, -}; - -/* - * Common dummy state transition; must be last entry for all state - * transition groups - it'll be on .bss, so will be zeroed. - */ -static const struct llc_conn_state_trans llc_common_state_trans_end; - -/* LLC_CONN_STATE_ADM transitions */ -/* State transitions for LLC_CONN_EV_CONN_REQ event */ -static const llc_conn_action_t llc_adm_actions_1[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_set_retry_cnt_0, - [3] = llc_conn_ac_set_s_flag_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_adm_state_trans_1 = { - .ev = llc_conn_ev_conn_req, - .next_state = LLC_CONN_STATE_SETUP, - .ev_qualifiers = NONE, - .ev_actions = llc_adm_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_adm_actions_2[] = { - [0] = llc_conn_ac_send_ua_rsp_f_set_p, - [1] = llc_conn_ac_set_vs_0, - [2] = llc_conn_ac_set_vr_0, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_p_flag_0, - [5] = llc_conn_ac_set_remote_busy_0, - [6] = llc_conn_ac_conn_ind, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_adm_state_trans_2 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_adm_actions_2, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_adm_actions_3[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_p, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_adm_state_trans_3 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_adm_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_XXX_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_adm_actions_4[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_1, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_adm_state_trans_4 = { - .ev = llc_conn_ev_rx_xxx_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_adm_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_XXX_YYY event */ -static const llc_conn_action_t llc_adm_actions_5[] = { - [0] = llc_conn_disc, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_adm_state_trans_5 = { - .ev = llc_conn_ev_rx_any_frame, - .next_state = LLC_CONN_OUT_OF_SVC, - .ev_qualifiers = NONE, - .ev_actions = llc_adm_actions_5, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_adm_state_transitions[] = { - [0] = &llc_adm_state_trans_1, /* Request */ - [1] = &llc_common_state_trans_end, - [2] = &llc_common_state_trans_end, /* local_busy */ - [3] = &llc_common_state_trans_end, /* init_pf_cycle */ - [4] = &llc_common_state_trans_end, /* timer */ - [5] = &llc_adm_state_trans_2, /* Receive frame */ - [6] = &llc_adm_state_trans_3, - [7] = &llc_adm_state_trans_4, - [8] = &llc_adm_state_trans_5, - [9] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_SETUP transitions */ -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_setup_actions_1[] = { - [0] = llc_conn_ac_send_ua_rsp_f_set_p, - [1] = llc_conn_ac_set_vs_0, - [2] = llc_conn_ac_set_vr_0, - [3] = llc_conn_ac_set_s_flag_1, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_1 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_SETUP, - .ev_qualifiers = NONE, - .ev_actions = llc_setup_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_setup_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = llc_conn_ev_qlfy_set_status_conn, - [2] = NULL, -}; - -static const llc_conn_action_t llc_setup_actions_2[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_ac_set_vs_0, - [2] = llc_conn_ac_set_vr_0, - [3] = llc_conn_ac_upd_p_flag, - [4] = llc_conn_ac_set_remote_busy_0, - [5] = llc_conn_ac_conn_confirm, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_2 = { - .ev = llc_conn_ev_rx_ua_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_setup_ev_qfyrs_2, - .ev_actions = llc_setup_actions_2, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_setup_ev_qfyrs_3[] = { - [0] = llc_conn_ev_qlfy_s_flag_eq_1, - [1] = llc_conn_ev_qlfy_set_status_conn, - [2] = NULL, -}; - -static const llc_conn_action_t llc_setup_actions_3[] = { - [0] = llc_conn_ac_set_p_flag_0, - [1] = llc_conn_ac_set_remote_busy_0, - [2] = llc_conn_ac_conn_confirm, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_3 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_setup_ev_qfyrs_3, - .ev_actions = llc_setup_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_setup_ev_qfyrs_4[] = { - [0] = llc_conn_ev_qlfy_set_status_disc, - [1] = NULL, -}; - -static const llc_conn_action_t llc_setup_actions_4[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_p, - [1] = llc_conn_ac_stop_ack_timer, - [2] = llc_conn_ac_conn_confirm, - [3] = llc_conn_disc, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_4 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_setup_ev_qfyrs_4, - .ev_actions = llc_setup_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_setup_ev_qfyrs_5[] = { - [0] = llc_conn_ev_qlfy_set_status_disc, - [1] = NULL, -}; - -static const llc_conn_action_t llc_setup_actions_5[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_ac_conn_confirm, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_5 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_setup_ev_qfyrs_5, - .ev_actions = llc_setup_actions_5, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_setup_ev_qfyrs_7[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = llc_conn_ev_qlfy_s_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_setup_actions_7[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_7 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_SETUP, - .ev_qualifiers = llc_setup_ev_qfyrs_7, - .ev_actions = llc_setup_actions_7, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_setup_ev_qfyrs_8[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = llc_conn_ev_qlfy_s_flag_eq_0, - [2] = llc_conn_ev_qlfy_set_status_failed, - [3] = NULL, -}; - -static const llc_conn_action_t llc_setup_actions_8[] = { - [0] = llc_conn_ac_conn_confirm, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_setup_state_trans_8 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_setup_ev_qfyrs_8, - .ev_actions = llc_setup_actions_8, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_setup_state_transitions[] = { - [0] = &llc_common_state_trans_end, /* Request */ - [1] = &llc_common_state_trans_end, /* local busy */ - [2] = &llc_common_state_trans_end, /* init_pf_cycle */ - [3] = &llc_setup_state_trans_3, /* Timer */ - [4] = &llc_setup_state_trans_7, - [5] = &llc_setup_state_trans_8, - [6] = &llc_common_state_trans_end, - [7] = &llc_setup_state_trans_1, /* Receive frame */ - [8] = &llc_setup_state_trans_2, - [9] = &llc_setup_state_trans_4, - [10] = &llc_setup_state_trans_5, - [11] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_NORMAL transitions */ -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_1[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = llc_conn_ev_qlfy_last_frame_eq_0, - [3] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_1[] = { - [0] = llc_conn_ac_send_i_as_ack, - [1] = llc_conn_ac_start_ack_tmr_if_not_running, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_1 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_1, - .ev_actions = llc_normal_actions_1, -}; - -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = llc_conn_ev_qlfy_last_frame_eq_1, - [3] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_2[] = { - [0] = llc_conn_ac_send_i_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_2 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_2, - .ev_actions = llc_normal_actions_2, -}; - -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_2_1[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_1, - [1] = llc_conn_ev_qlfy_set_status_remote_busy, - [2] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_normal_actions_2_1[1]; - -static const struct llc_conn_state_trans llc_normal_state_trans_2_1 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_2_1, - .ev_actions = llc_normal_actions_2_1, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_DETECTED event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_3[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_3[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rnr_xxx_x_set_0, - [2] = llc_conn_ac_set_data_flag_0, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_3 = { - .ev = llc_conn_ev_local_busy_detected, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_normal_ev_qfyrs_3, - .ev_actions = llc_normal_actions_3, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_DETECTED event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_4[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_4[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rnr_xxx_x_set_0, - [2] = llc_conn_ac_set_data_flag_0, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_4 = { - .ev = llc_conn_ev_local_busy_detected, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_normal_ev_qfyrs_4, - .ev_actions = llc_normal_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_5a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_5a[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rej_xxx_x_set_0, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_upd_p_flag, - [4] = llc_conn_ac_start_rej_timer, - [5] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_5a = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_normal_ev_qfyrs_5a, - .ev_actions = llc_normal_actions_5a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_5b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_5b[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rej_xxx_x_set_0, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_upd_p_flag, - [4] = llc_conn_ac_start_rej_timer, - [5] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_5b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_normal_ev_qfyrs_5b, - .ev_actions = llc_normal_actions_5b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_5c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_5c[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rej_xxx_x_set_0, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_upd_p_flag, - [4] = llc_conn_ac_start_rej_timer, - [5] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_5c = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_normal_ev_qfyrs_5c, - .ev_actions = llc_normal_actions_5c, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_6a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_6a[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rej_xxx_x_set_0, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_start_rej_timer, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_6a = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_normal_ev_qfyrs_6a, - .ev_actions = llc_normal_actions_6a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_6b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_6b[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rej_xxx_x_set_0, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_start_rej_timer, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_6b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_normal_ev_qfyrs_6b, - .ev_actions = llc_normal_actions_6b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_normal_actions_7[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rej_rsp_f_set_1, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_start_rej_timer, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_7 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_7, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_8a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_8[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [5] = llc_conn_ac_send_ack_if_needed, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_8a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_8a, - .ev_actions = llc_normal_actions_8, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_8b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_8b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_8b, - .ev_actions = llc_normal_actions_8, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_9a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_9a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_data_ind, - [3] = llc_conn_ac_send_ack_if_needed, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_9a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_9a, - .ev_actions = llc_normal_actions_9a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_9b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_9b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_data_ind, - [3] = llc_conn_ac_send_ack_if_needed, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_9b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_9b, - .ev_actions = llc_normal_actions_9b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_normal_actions_10[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_send_ack_rsp_f_set_1, - [2] = llc_conn_ac_rst_sendack_flag, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_data_ind, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_10 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_10, -}; - -/* State transitions for * LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_normal_actions_11a[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_11a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_11a, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_normal_actions_11b[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_11b = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_11b, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_11c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_11c[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_inc_tx_win_size, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_11c = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_11c, - .ev_actions = llc_normal_actions_11c, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_normal_actions_12[] = { - [0] = llc_conn_ac_send_ack_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_adjust_npta_by_rr, - [3] = llc_conn_ac_rst_sendack_flag, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_12 = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_12, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_normal_actions_13a[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_13a = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_13a, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_normal_actions_13b[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_13b = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_13b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_13c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_13c[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_13c = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_13c, - .ev_actions = llc_normal_actions_13c, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_normal_actions_14[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_adjust_npta_by_rnr, - [3] = llc_conn_ac_rst_sendack_flag, - [4] = llc_conn_ac_set_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_14 = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_14, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_15a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_15a[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_dec_tx_win_size, - [4] = llc_conn_ac_resend_i_xxx_x_set_0, - [5] = llc_conn_ac_clear_remote_busy, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_15a = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_15a, - .ev_actions = llc_normal_actions_15a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_15b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_15b[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_dec_tx_win_size, - [4] = llc_conn_ac_resend_i_xxx_x_set_0, - [5] = llc_conn_ac_clear_remote_busy, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_15b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_15b, - .ev_actions = llc_normal_actions_15b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_16a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_16a[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_dec_tx_win_size, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_16a = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_16a, - .ev_actions = llc_normal_actions_16a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_16b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_16b[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_dec_tx_win_size, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_16b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_16b, - .ev_actions = llc_normal_actions_16b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_normal_actions_17[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_dec_tx_win_size, - [3] = llc_conn_ac_resend_i_rsp_f_set_1, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_17 = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_normal_actions_17, -}; - -/* State transitions for LLC_CONN_EV_INIT_P_F_CYCLE event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_18[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_18[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_18 = { - .ev = llc_conn_ev_init_p_f_cycle, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_18, - .ev_actions = llc_normal_actions_18, -}; - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_19[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_19[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rr_cmd_p_set_1, - [2] = llc_conn_ac_rst_vs, - [3] = llc_conn_ac_start_p_timer, - [4] = llc_conn_ac_inc_retry_cnt_by_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_19 = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = llc_normal_ev_qfyrs_19, - .ev_actions = llc_normal_actions_19, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_20a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_20a[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rr_cmd_p_set_1, - [2] = llc_conn_ac_rst_vs, - [3] = llc_conn_ac_start_p_timer, - [4] = llc_conn_ac_inc_retry_cnt_by_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_20a = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = llc_normal_ev_qfyrs_20a, - .ev_actions = llc_normal_actions_20a, -}; - -/* State transitions for LLC_CONN_EV_BUSY_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_20b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_20b[] = { - [0] = llc_conn_ac_rst_sendack_flag, - [1] = llc_conn_ac_send_rr_cmd_p_set_1, - [2] = llc_conn_ac_rst_vs, - [3] = llc_conn_ac_start_p_timer, - [4] = llc_conn_ac_inc_retry_cnt_by_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_20b = { - .ev = llc_conn_ev_busy_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = llc_normal_ev_qfyrs_20b, - .ev_actions = llc_normal_actions_20b, -}; - -/* State transitions for LLC_CONN_EV_TX_BUFF_FULL event */ -static const llc_conn_ev_qfyr_t llc_normal_ev_qfyrs_21[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_normal_actions_21[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_normal_state_trans_21 = { - .ev = llc_conn_ev_tx_buffer_full, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_normal_ev_qfyrs_21, - .ev_actions = llc_normal_actions_21, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_normal_state_transitions[] = { - [0] = &llc_normal_state_trans_1, /* Requests */ - [1] = &llc_normal_state_trans_2, - [2] = &llc_normal_state_trans_2_1, - [3] = &llc_common_state_trans_1, - [4] = &llc_common_state_trans_2, - [5] = &llc_common_state_trans_end, - [6] = &llc_normal_state_trans_21, - [7] = &llc_normal_state_trans_3, /* Local busy */ - [8] = &llc_normal_state_trans_4, - [9] = &llc_common_state_trans_end, - [10] = &llc_normal_state_trans_18, /* Init pf cycle */ - [11] = &llc_common_state_trans_end, - [12] = &llc_common_state_trans_11a, /* Timers */ - [13] = &llc_common_state_trans_11b, - [14] = &llc_common_state_trans_11c, - [15] = &llc_common_state_trans_11d, - [16] = &llc_normal_state_trans_19, - [17] = &llc_normal_state_trans_20a, - [18] = &llc_normal_state_trans_20b, - [19] = &llc_common_state_trans_end, - [20] = &llc_normal_state_trans_8b, /* Receive frames */ - [21] = &llc_normal_state_trans_9b, - [22] = &llc_normal_state_trans_10, - [23] = &llc_normal_state_trans_11b, - [24] = &llc_normal_state_trans_11c, - [25] = &llc_normal_state_trans_5a, - [26] = &llc_normal_state_trans_5b, - [27] = &llc_normal_state_trans_5c, - [28] = &llc_normal_state_trans_6a, - [29] = &llc_normal_state_trans_6b, - [30] = &llc_normal_state_trans_7, - [31] = &llc_normal_state_trans_8a, - [32] = &llc_normal_state_trans_9a, - [33] = &llc_normal_state_trans_11a, - [34] = &llc_normal_state_trans_12, - [35] = &llc_normal_state_trans_13a, - [36] = &llc_normal_state_trans_13b, - [37] = &llc_normal_state_trans_13c, - [38] = &llc_normal_state_trans_14, - [39] = &llc_normal_state_trans_15a, - [40] = &llc_normal_state_trans_15b, - [41] = &llc_normal_state_trans_16a, - [42] = &llc_normal_state_trans_16b, - [43] = &llc_normal_state_trans_17, - [44] = &llc_common_state_trans_3, - [45] = &llc_common_state_trans_4, - [46] = &llc_common_state_trans_5, - [47] = &llc_common_state_trans_6, - [48] = &llc_common_state_trans_7a, - [49] = &llc_common_state_trans_7b, - [50] = &llc_common_state_trans_8a, - [51] = &llc_common_state_trans_8b, - [52] = &llc_common_state_trans_8c, - [53] = &llc_common_state_trans_9, - /* [54] = &llc_common_state_trans_10, */ - [54] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_BUSY transitions */ -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_1[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_1[] = { - [0] = llc_conn_ac_send_i_xxx_x_set_0, - [1] = llc_conn_ac_start_ack_tmr_if_not_running, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_1 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_1, - .ev_actions = llc_busy_actions_1, -}; - -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_1, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_2[] = { - [0] = llc_conn_ac_send_i_xxx_x_set_0, - [1] = llc_conn_ac_start_ack_tmr_if_not_running, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_2 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_2, - .ev_actions = llc_busy_actions_2, -}; - -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_2_1[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_1, - [1] = llc_conn_ev_qlfy_set_status_remote_busy, - [2] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_busy_actions_2_1[1]; - -static const struct llc_conn_state_trans llc_busy_state_trans_2_1 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_2_1, - .ev_actions = llc_busy_actions_2_1, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_3[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_1, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_3[] = { - [0] = llc_conn_ac_send_rej_xxx_x_set_0, - [1] = llc_conn_ac_start_rej_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_3 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_busy_ev_qfyrs_3, - .ev_actions = llc_busy_actions_3, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_4[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_1, - [1] = llc_conn_ev_qlfy_p_flag_eq_1, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_4[] = { - [0] = llc_conn_ac_send_rej_xxx_x_set_0, - [1] = llc_conn_ac_start_rej_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_4 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_busy_ev_qfyrs_4, - .ev_actions = llc_busy_actions_4, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_5[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_5[] = { - [0] = llc_conn_ac_send_rr_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_5 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_busy_ev_qfyrs_5, - .ev_actions = llc_busy_actions_5, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_6[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_1, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_6[] = { - [0] = llc_conn_ac_send_rr_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_6 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_busy_ev_qfyrs_6, - .ev_actions = llc_busy_actions_6, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_7[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_2, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_7[] = { - [0] = llc_conn_ac_send_rr_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_7 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_busy_ev_qfyrs_7, - .ev_actions = llc_busy_actions_7, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_8[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_2, - [1] = llc_conn_ev_qlfy_p_flag_eq_1, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_8[] = { - [0] = llc_conn_ac_send_rr_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_8 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_busy_ev_qfyrs_8, - .ev_actions = llc_busy_actions_8, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_X_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_9a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_9a[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_p_flag, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_set_data_flag_1_if_data_flag_eq_0, - [4] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_9a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_9a, - .ev_actions = llc_busy_actions_9a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_9b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_9b[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_p_flag, - [2] = llc_conn_ac_upd_nr_received, - [3] = llc_conn_ac_set_data_flag_1_if_data_flag_eq_0, - [4] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_9b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_9b, - .ev_actions = llc_busy_actions_9b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_10a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_10a[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_data_flag_1_if_data_flag_eq_0, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_10a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_10a, - .ev_actions = llc_busy_actions_10a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_10b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_10b[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_data_flag_1_if_data_flag_eq_0, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_10b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_10b, - .ev_actions = llc_busy_actions_10b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_busy_actions_11[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_data_flag_1_if_data_flag_eq_0, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_11 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_11, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_busy_actions_12[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rnr_rsp_f_set_1, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2, - [5] = llc_conn_ac_set_data_flag_0, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_12 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_12, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_13a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_13a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2, - [6] = llc_conn_ac_set_data_flag_0, - [7] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [8] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_13a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_13a, - .ev_actions = llc_busy_actions_13a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_13b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_13b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2, - [6] = llc_conn_ac_set_data_flag_0, - [7] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [8] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_13b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_13b, - .ev_actions = llc_busy_actions_13b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_14a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_14a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2, - [5] = llc_conn_ac_set_data_flag_0, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_14a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_14a, - .ev_actions = llc_busy_actions_14a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_14b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_14b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2, - [5] = llc_conn_ac_set_data_flag_0, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_14b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_14b, - .ev_actions = llc_busy_actions_14b, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_busy_actions_15a[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_15a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_15a, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_busy_actions_15b[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_15b = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_15b, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_15c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_15c[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_15c = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_15c, - .ev_actions = llc_busy_actions_15c, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_busy_actions_16[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_16 = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_16, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_busy_actions_17a[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_17a = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_17a, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_busy_actions_17b[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_17b = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_17b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_17c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_17c[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_17c = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_17c, - .ev_actions = llc_busy_actions_17c, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_busy_actions_18[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_18 = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_18, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_19a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_19a[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_19a = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_19a, - .ev_actions = llc_busy_actions_19a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_19b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_19b[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_19b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_19b, - .ev_actions = llc_busy_actions_19b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_20a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_20a[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_resend_i_xxx_x_set_0, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_20a = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_20a, - .ev_actions = llc_busy_actions_20a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_20b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_20b[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_resend_i_xxx_x_set_0, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_20b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_20b, - .ev_actions = llc_busy_actions_20b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_busy_actions_21[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_send_rnr_rsp_f_set_1, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_21 = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_busy_actions_21, -}; - -/* State transitions for LLC_CONN_EV_INIT_P_F_CYCLE event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_22[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_22[] = { - [0] = llc_conn_ac_send_rnr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_22 = { - .ev = llc_conn_ev_init_p_f_cycle, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_22, - .ev_actions = llc_busy_actions_22, -}; - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_23[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_23[] = { - [0] = llc_conn_ac_send_rnr_cmd_p_set_1, - [1] = llc_conn_ac_rst_vs, - [2] = llc_conn_ac_start_p_timer, - [3] = llc_conn_ac_inc_retry_cnt_by_1, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_23 = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_23, - .ev_actions = llc_busy_actions_23, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_24a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_24a[] = { - [0] = llc_conn_ac_send_rnr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = llc_conn_ac_rst_vs, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_24a = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_24a, - .ev_actions = llc_busy_actions_24a, -}; - -/* State transitions for LLC_CONN_EV_BUSY_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_24b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_24b[] = { - [0] = llc_conn_ac_send_rnr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = llc_conn_ac_rst_vs, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_24b = { - .ev = llc_conn_ev_busy_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_24b, - .ev_actions = llc_busy_actions_24b, -}; - -/* State transitions for LLC_CONN_EV_REJ_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_25[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_25[] = { - [0] = llc_conn_ac_send_rnr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = llc_conn_ac_rst_vs, - [4] = llc_conn_ac_set_data_flag_1, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_25 = { - .ev = llc_conn_ev_rej_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_25, - .ev_actions = llc_busy_actions_25, -}; - -/* State transitions for LLC_CONN_EV_REJ_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_busy_ev_qfyrs_26[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_busy_actions_26[] = { - [0] = llc_conn_ac_set_data_flag_1, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_busy_state_trans_26 = { - .ev = llc_conn_ev_rej_tmr_exp, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_busy_ev_qfyrs_26, - .ev_actions = llc_busy_actions_26, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_busy_state_transitions[] = { - [0] = &llc_common_state_trans_1, /* Request */ - [1] = &llc_common_state_trans_2, - [2] = &llc_busy_state_trans_1, - [3] = &llc_busy_state_trans_2, - [4] = &llc_busy_state_trans_2_1, - [5] = &llc_common_state_trans_end, - [6] = &llc_busy_state_trans_3, /* Local busy */ - [7] = &llc_busy_state_trans_4, - [8] = &llc_busy_state_trans_5, - [9] = &llc_busy_state_trans_6, - [10] = &llc_busy_state_trans_7, - [11] = &llc_busy_state_trans_8, - [12] = &llc_common_state_trans_end, - [13] = &llc_busy_state_trans_22, /* Initiate PF cycle */ - [14] = &llc_common_state_trans_end, - [15] = &llc_common_state_trans_11a, /* Timer */ - [16] = &llc_common_state_trans_11b, - [17] = &llc_common_state_trans_11c, - [18] = &llc_common_state_trans_11d, - [19] = &llc_busy_state_trans_23, - [20] = &llc_busy_state_trans_24a, - [21] = &llc_busy_state_trans_24b, - [22] = &llc_busy_state_trans_25, - [23] = &llc_busy_state_trans_26, - [24] = &llc_common_state_trans_end, - [25] = &llc_busy_state_trans_9a, /* Receive frame */ - [26] = &llc_busy_state_trans_9b, - [27] = &llc_busy_state_trans_10a, - [28] = &llc_busy_state_trans_10b, - [29] = &llc_busy_state_trans_11, - [30] = &llc_busy_state_trans_12, - [31] = &llc_busy_state_trans_13a, - [32] = &llc_busy_state_trans_13b, - [33] = &llc_busy_state_trans_14a, - [34] = &llc_busy_state_trans_14b, - [35] = &llc_busy_state_trans_15a, - [36] = &llc_busy_state_trans_15b, - [37] = &llc_busy_state_trans_15c, - [38] = &llc_busy_state_trans_16, - [39] = &llc_busy_state_trans_17a, - [40] = &llc_busy_state_trans_17b, - [41] = &llc_busy_state_trans_17c, - [42] = &llc_busy_state_trans_18, - [43] = &llc_busy_state_trans_19a, - [44] = &llc_busy_state_trans_19b, - [45] = &llc_busy_state_trans_20a, - [46] = &llc_busy_state_trans_20b, - [47] = &llc_busy_state_trans_21, - [48] = &llc_common_state_trans_3, - [49] = &llc_common_state_trans_4, - [50] = &llc_common_state_trans_5, - [51] = &llc_common_state_trans_6, - [52] = &llc_common_state_trans_7a, - [53] = &llc_common_state_trans_7b, - [54] = &llc_common_state_trans_8a, - [55] = &llc_common_state_trans_8b, - [56] = &llc_common_state_trans_8c, - [57] = &llc_common_state_trans_9, - /* [58] = &llc_common_state_trans_10, */ - [58] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_REJ transitions */ -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_1[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_1[] = { - [0] = llc_conn_ac_send_i_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_1 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_1, - .ev_actions = llc_reject_actions_1, -}; - -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_0, - [1] = llc_conn_ev_qlfy_p_flag_eq_1, - [2] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_2[] = { - [0] = llc_conn_ac_send_i_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_2 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_2, - .ev_actions = llc_reject_actions_2, -}; - -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_2_1[] = { - [0] = llc_conn_ev_qlfy_remote_busy_eq_1, - [1] = llc_conn_ev_qlfy_set_status_remote_busy, - [2] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_reject_actions_2_1[1]; - -static const struct llc_conn_state_trans llc_reject_state_trans_2_1 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_2_1, - .ev_actions = llc_reject_actions_2_1, -}; - - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_DETECTED event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_3[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_3[] = { - [0] = llc_conn_ac_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_set_data_flag_2, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_3 = { - .ev = llc_conn_ev_local_busy_detected, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_reject_ev_qfyrs_3, - .ev_actions = llc_reject_actions_3, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_DETECTED event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_4[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_4[] = { - [0] = llc_conn_ac_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_set_data_flag_2, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_4 = { - .ev = llc_conn_ev_local_busy_detected, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = llc_reject_ev_qfyrs_4, - .ev_actions = llc_reject_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_reject_actions_5a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_p_flag, - [2] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_5a = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_5a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_reject_actions_5b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_p_flag, - [2] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_5b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_5b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_5c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_5c[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_p_flag, - [2] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_5c = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_5c, - .ev_actions = llc_reject_actions_5c, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_reject_actions_6[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_6 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_6, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_7a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_7a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_send_ack_xxx_x_set_0, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [6] = llc_conn_ac_stop_rej_timer, - [7] = NULL, - -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_7a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_reject_ev_qfyrs_7a, - .ev_actions = llc_reject_actions_7a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_7b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_7b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_send_ack_xxx_x_set_0, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_clear_remote_busy_if_f_eq_1, - [6] = llc_conn_ac_stop_rej_timer, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_7b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_reject_ev_qfyrs_7b, - .ev_actions = llc_reject_actions_7b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_8a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_8a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_ack_xxx_x_set_0, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_stop_rej_timer, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_8a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_reject_ev_qfyrs_8a, - .ev_actions = llc_reject_actions_8a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_8b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_8b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_ack_xxx_x_set_0, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_stop_rej_timer, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_8b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_reject_ev_qfyrs_8b, - .ev_actions = llc_reject_actions_8b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_reject_actions_9[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_ack_rsp_f_set_1, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_stop_rej_timer, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_9 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_9, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_reject_actions_10a[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_10a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_10a, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_reject_actions_10b[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_10b = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_10b, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_10c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_10c[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_10c = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_10c, - .ev_actions = llc_reject_actions_10c, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_reject_actions_11[] = { - [0] = llc_conn_ac_send_ack_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_11 = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_11, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_reject_actions_12a[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_12a = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_12a, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_reject_actions_12b[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_12b = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_12b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_12c[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_12c[] = { - [0] = llc_conn_ac_upd_p_flag, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_12c = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_12c, - .ev_actions = llc_reject_actions_12c, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_reject_actions_13[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_13 = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_13, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_14a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_14a[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_14a = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_14a, - .ev_actions = llc_reject_actions_14a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_X event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_14b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_14b[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_p_flag, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_14b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_14b, - .ev_actions = llc_reject_actions_14b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_15a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_15a[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_resend_i_xxx_x_set_0, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_15a = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_15a, - .ev_actions = llc_reject_actions_15a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_15b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_15b[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_resend_i_xxx_x_set_0, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_15b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_15b, - .ev_actions = llc_reject_actions_15b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_reject_actions_16[] = { - [0] = llc_conn_ac_set_vs_nr, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_resend_i_rsp_f_set_1, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_16 = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_reject_actions_16, -}; - -/* State transitions for LLC_CONN_EV_INIT_P_F_CYCLE event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_17[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_17[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_17 = { - .ev = llc_conn_ev_init_p_f_cycle, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_17, - .ev_actions = llc_reject_actions_17, -}; - -/* State transitions for LLC_CONN_EV_REJ_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_18[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_18[] = { - [0] = llc_conn_ac_send_rej_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_start_rej_timer, - [3] = llc_conn_ac_inc_retry_cnt_by_1, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_18 = { - .ev = llc_conn_ev_rej_tmr_exp, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_18, - .ev_actions = llc_reject_actions_18, -}; - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_19[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_19[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_start_rej_timer, - [3] = llc_conn_ac_inc_retry_cnt_by_1, - [4] = llc_conn_ac_rst_vs, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_19 = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_19, - .ev_actions = llc_reject_actions_19, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_20a[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_20a[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_start_rej_timer, - [3] = llc_conn_ac_inc_retry_cnt_by_1, - [4] = llc_conn_ac_rst_vs, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_20a = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_20a, - .ev_actions = llc_reject_actions_20a, -}; - -/* State transitions for LLC_CONN_EV_BUSY_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_reject_ev_qfyrs_20b[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_0, - [1] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [2] = NULL, -}; - -static const llc_conn_action_t llc_reject_actions_20b[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_start_rej_timer, - [3] = llc_conn_ac_inc_retry_cnt_by_1, - [4] = llc_conn_ac_rst_vs, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_reject_state_trans_20b = { - .ev = llc_conn_ev_busy_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_reject_ev_qfyrs_20b, - .ev_actions = llc_reject_actions_20b, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_reject_state_transitions[] = { - [0] = &llc_common_state_trans_1, /* Request */ - [1] = &llc_common_state_trans_2, - [2] = &llc_common_state_trans_end, - [3] = &llc_reject_state_trans_1, - [4] = &llc_reject_state_trans_2, - [5] = &llc_reject_state_trans_2_1, - [6] = &llc_reject_state_trans_3, /* Local busy */ - [7] = &llc_reject_state_trans_4, - [8] = &llc_common_state_trans_end, - [9] = &llc_reject_state_trans_17, /* Initiate PF cycle */ - [10] = &llc_common_state_trans_end, - [11] = &llc_common_state_trans_11a, /* Timer */ - [12] = &llc_common_state_trans_11b, - [13] = &llc_common_state_trans_11c, - [14] = &llc_common_state_trans_11d, - [15] = &llc_reject_state_trans_18, - [16] = &llc_reject_state_trans_19, - [17] = &llc_reject_state_trans_20a, - [18] = &llc_reject_state_trans_20b, - [19] = &llc_common_state_trans_end, - [20] = &llc_common_state_trans_3, /* Receive frame */ - [21] = &llc_common_state_trans_4, - [22] = &llc_common_state_trans_5, - [23] = &llc_common_state_trans_6, - [24] = &llc_common_state_trans_7a, - [25] = &llc_common_state_trans_7b, - [26] = &llc_common_state_trans_8a, - [27] = &llc_common_state_trans_8b, - [28] = &llc_common_state_trans_8c, - [29] = &llc_common_state_trans_9, - /* [30] = &llc_common_state_trans_10, */ - [30] = &llc_reject_state_trans_5a, - [31] = &llc_reject_state_trans_5b, - [32] = &llc_reject_state_trans_5c, - [33] = &llc_reject_state_trans_6, - [34] = &llc_reject_state_trans_7a, - [35] = &llc_reject_state_trans_7b, - [36] = &llc_reject_state_trans_8a, - [37] = &llc_reject_state_trans_8b, - [38] = &llc_reject_state_trans_9, - [39] = &llc_reject_state_trans_10a, - [40] = &llc_reject_state_trans_10b, - [41] = &llc_reject_state_trans_10c, - [42] = &llc_reject_state_trans_11, - [43] = &llc_reject_state_trans_12a, - [44] = &llc_reject_state_trans_12b, - [45] = &llc_reject_state_trans_12c, - [46] = &llc_reject_state_trans_13, - [47] = &llc_reject_state_trans_14a, - [48] = &llc_reject_state_trans_14b, - [49] = &llc_reject_state_trans_15a, - [50] = &llc_reject_state_trans_15b, - [51] = &llc_reject_state_trans_16, - [52] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_AWAIT transitions */ -/* State transitions for LLC_CONN_EV_DATA_REQ event */ -static const llc_conn_ev_qfyr_t llc_await_ev_qfyrs_1_0[] = { - [0] = llc_conn_ev_qlfy_set_status_refuse, - [1] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_await_actions_1_0[1]; - -static const struct llc_conn_state_trans llc_await_state_trans_1_0 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = llc_await_ev_qfyrs_1_0, - .ev_actions = llc_await_actions_1_0, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_DETECTED event */ -static const llc_conn_action_t llc_await_actions_1[] = { - [0] = llc_conn_ac_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_set_data_flag_0, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_1 = { - .ev = llc_conn_ev_local_busy_detected, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_actions_2[] = { - [0] = llc_conn_ac_send_rej_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_stop_p_timer, - [4] = llc_conn_ac_resend_i_xxx_x_set_0, - [5] = llc_conn_ac_start_rej_timer, - [6] = llc_conn_ac_clear_remote_busy, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_2 = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_2, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_actions_3a[] = { - [0] = llc_conn_ac_send_rej_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_start_rej_timer, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_3a = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_3a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_actions_3b[] = { - [0] = llc_conn_ac_send_rej_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_start_rej_timer, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_3b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_3b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_actions_4[] = { - [0] = llc_conn_ac_send_rej_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_start_rej_timer, - [4] = llc_conn_ac_start_p_timer, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_4 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_5[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr, - [6] = llc_conn_ac_clear_remote_busy, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_5 = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_5, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_6a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rr_xxx_x_set_0, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_6a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_6a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_6b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rr_xxx_x_set_0, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_6b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_6b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_7[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rr_rsp_f_set_1, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_7 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_7, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_8a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_8a = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_8a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_8b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_8b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_8b, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_9a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_9a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_9a, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_9b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_9b = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_9b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_9c[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_9c = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_9c, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_9d[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_9d = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_9d, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_10a[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_10a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_10a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_10b[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_10b = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_10b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_11[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_set_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_11 = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_11, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_12a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_12a = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_12a, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_actions_12b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_12b = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_12b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_actions_13[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_set_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_13 = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_actions_13, -}; - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_await_ev_qfyrs_14[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_await_actions_14[] = { - [0] = llc_conn_ac_send_rr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_state_trans_14 = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = llc_await_ev_qfyrs_14, - .ev_actions = llc_await_actions_14, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_await_state_transitions[] = { - [0] = &llc_common_state_trans_1, /* Request */ - [1] = &llc_common_state_trans_2, - [2] = &llc_await_state_trans_1_0, - [3] = &llc_common_state_trans_end, - [4] = &llc_await_state_trans_1, /* Local busy */ - [5] = &llc_common_state_trans_end, - [6] = &llc_common_state_trans_end, /* Initiate PF Cycle */ - [7] = &llc_common_state_trans_11a, /* Timer */ - [8] = &llc_common_state_trans_11b, - [9] = &llc_common_state_trans_11c, - [10] = &llc_common_state_trans_11d, - [11] = &llc_await_state_trans_14, - [12] = &llc_common_state_trans_end, - [13] = &llc_common_state_trans_3, /* Receive frame */ - [14] = &llc_common_state_trans_4, - [15] = &llc_common_state_trans_5, - [16] = &llc_common_state_trans_6, - [17] = &llc_common_state_trans_7a, - [18] = &llc_common_state_trans_7b, - [19] = &llc_common_state_trans_8a, - [20] = &llc_common_state_trans_8b, - [21] = &llc_common_state_trans_8c, - [22] = &llc_common_state_trans_9, - /* [23] = &llc_common_state_trans_10, */ - [23] = &llc_await_state_trans_2, - [24] = &llc_await_state_trans_3a, - [25] = &llc_await_state_trans_3b, - [26] = &llc_await_state_trans_4, - [27] = &llc_await_state_trans_5, - [28] = &llc_await_state_trans_6a, - [29] = &llc_await_state_trans_6b, - [30] = &llc_await_state_trans_7, - [31] = &llc_await_state_trans_8a, - [32] = &llc_await_state_trans_8b, - [33] = &llc_await_state_trans_9a, - [34] = &llc_await_state_trans_9b, - [35] = &llc_await_state_trans_9c, - [36] = &llc_await_state_trans_9d, - [37] = &llc_await_state_trans_10a, - [38] = &llc_await_state_trans_10b, - [39] = &llc_await_state_trans_11, - [40] = &llc_await_state_trans_12a, - [41] = &llc_await_state_trans_12b, - [42] = &llc_await_state_trans_13, - [43] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_AWAIT_BUSY transitions */ -/* State transitions for LLC_CONN_EV_DATA_CONN_REQ event */ -static const llc_conn_ev_qfyr_t llc_await_busy_ev_qfyrs_1_0[] = { - [0] = llc_conn_ev_qlfy_set_status_refuse, - [1] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_await_busy_actions_1_0[1]; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_1_0 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = llc_await_busy_ev_qfyrs_1_0, - .ev_actions = llc_await_busy_actions_1_0, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_await_busy_ev_qfyrs_1[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_1, - [1] = NULL, -}; - -static const llc_conn_action_t llc_await_busy_actions_1[] = { - [0] = llc_conn_ac_send_rej_xxx_x_set_0, - [1] = llc_conn_ac_start_rej_timer, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_1 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_await_busy_ev_qfyrs_1, - .ev_actions = llc_await_busy_actions_1, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_await_busy_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_0, - [1] = NULL, -}; - -static const llc_conn_action_t llc_await_busy_actions_2[] = { - [0] = llc_conn_ac_send_rr_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_2 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = llc_await_busy_ev_qfyrs_2, - .ev_actions = llc_await_busy_actions_2, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_CLEARED event */ -static const llc_conn_ev_qfyr_t llc_await_busy_ev_qfyrs_3[] = { - [0] = llc_conn_ev_qlfy_data_flag_eq_2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_await_busy_actions_3[] = { - [0] = llc_conn_ac_send_rr_xxx_x_set_0, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_3 = { - .ev = llc_conn_ev_local_busy_cleared, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_await_busy_ev_qfyrs_3, - .ev_actions = llc_await_busy_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_busy_actions_4[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_stop_p_timer, - [4] = llc_conn_ac_set_data_flag_1, - [5] = llc_conn_ac_clear_remote_busy, - [6] = llc_conn_ac_resend_i_xxx_x_set_0, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_4 = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_busy_actions_5a[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_set_data_flag_1, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_5a = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_5a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_busy_actions_5b[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_set_data_flag_1, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_5b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_5b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_busy_actions_6[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_set_data_flag_1, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_6 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_6, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_7[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_inc_vr_by_1, - [2] = llc_conn_ac_data_ind, - [3] = llc_conn_ac_stop_p_timer, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_upd_vs, - [6] = llc_conn_ac_set_data_flag_0, - [7] = llc_conn_ac_clear_remote_busy, - [8] = llc_conn_ac_resend_i_xxx_x_set_0, - [9] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_7 = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_7, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_8a[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_inc_vr_by_1, - [2] = llc_conn_ac_data_ind, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = llc_conn_ac_set_data_flag_0, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_8a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_8a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_8b[] = { - [0] = llc_conn_ac_opt_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_inc_vr_by_1, - [2] = llc_conn_ac_data_ind, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = llc_conn_ac_set_data_flag_0, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_8b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_8b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_9[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_inc_vr_by_1, - [2] = llc_conn_ac_data_ind, - [3] = llc_conn_ac_upd_nr_received, - [4] = llc_conn_ac_upd_vs, - [5] = llc_conn_ac_set_data_flag_0, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_9 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_9, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_10a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_10a = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_10a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_10b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_10b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_10b, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_11a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_11a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_11a, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_11b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_11b = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_11b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_11c[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_11c = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_11c, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_11d[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_11d = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_11d, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_12a[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_12a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_12a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_12b[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_12b = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_12b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_13[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_set_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_13 = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_13, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_14a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_14a = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_14a, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_busy_actions_14b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_14b = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_14b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_busy_actions_15[] = { - [0] = llc_conn_ac_send_rnr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_set_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_15 = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_busy_actions_15, -}; - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_await_busy_ev_qfyrs_16[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_await_busy_actions_16[] = { - [0] = llc_conn_ac_send_rnr_cmd_p_set_1, - [1] = llc_conn_ac_start_p_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_busy_state_trans_16 = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = llc_await_busy_ev_qfyrs_16, - .ev_actions = llc_await_busy_actions_16, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_await_busy_state_transitions[] = { - [0] = &llc_common_state_trans_1, /* Request */ - [1] = &llc_common_state_trans_2, - [2] = &llc_await_busy_state_trans_1_0, - [3] = &llc_common_state_trans_end, - [4] = &llc_await_busy_state_trans_1, /* Local busy */ - [5] = &llc_await_busy_state_trans_2, - [6] = &llc_await_busy_state_trans_3, - [7] = &llc_common_state_trans_end, - [8] = &llc_common_state_trans_end, /* Initiate PF cycle */ - [9] = &llc_common_state_trans_11a, /* Timer */ - [10] = &llc_common_state_trans_11b, - [11] = &llc_common_state_trans_11c, - [12] = &llc_common_state_trans_11d, - [13] = &llc_await_busy_state_trans_16, - [14] = &llc_common_state_trans_end, - [15] = &llc_await_busy_state_trans_4, /* Receive frame */ - [16] = &llc_await_busy_state_trans_5a, - [17] = &llc_await_busy_state_trans_5b, - [18] = &llc_await_busy_state_trans_6, - [19] = &llc_await_busy_state_trans_7, - [20] = &llc_await_busy_state_trans_8a, - [21] = &llc_await_busy_state_trans_8b, - [22] = &llc_await_busy_state_trans_9, - [23] = &llc_await_busy_state_trans_10a, - [24] = &llc_await_busy_state_trans_10b, - [25] = &llc_await_busy_state_trans_11a, - [26] = &llc_await_busy_state_trans_11b, - [27] = &llc_await_busy_state_trans_11c, - [28] = &llc_await_busy_state_trans_11d, - [29] = &llc_await_busy_state_trans_12a, - [30] = &llc_await_busy_state_trans_12b, - [31] = &llc_await_busy_state_trans_13, - [32] = &llc_await_busy_state_trans_14a, - [33] = &llc_await_busy_state_trans_14b, - [34] = &llc_await_busy_state_trans_15, - [35] = &llc_common_state_trans_3, - [36] = &llc_common_state_trans_4, - [37] = &llc_common_state_trans_5, - [38] = &llc_common_state_trans_6, - [39] = &llc_common_state_trans_7a, - [40] = &llc_common_state_trans_7b, - [41] = &llc_common_state_trans_8a, - [42] = &llc_common_state_trans_8b, - [43] = &llc_common_state_trans_8c, - [44] = &llc_common_state_trans_9, - /* [45] = &llc_common_state_trans_10, */ - [45] = &llc_common_state_trans_end, -}; - -/* ----------------- LLC_CONN_STATE_AWAIT_REJ transitions --------------- */ -/* State transitions for LLC_CONN_EV_DATA_CONN_REQ event */ -static const llc_conn_ev_qfyr_t llc_await_reject_ev_qfyrs_1_0[] = { - [0] = llc_conn_ev_qlfy_set_status_refuse, - [1] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_await_reject_actions_1_0[1]; - -static const struct llc_conn_state_trans llc_await_reject_state_trans_1_0 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_await_reject_ev_qfyrs_1_0, - .ev_actions = llc_await_reject_actions_1_0, -}; - -/* State transitions for LLC_CONN_EV_LOCAL_BUSY_DETECTED event */ -static const llc_conn_action_t llc_await_rejct_actions_1[] = { - [0] = llc_conn_ac_send_rnr_xxx_x_set_0, - [1] = llc_conn_ac_set_data_flag_2, - [2] = NULL -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_1 = { - .ev = llc_conn_ev_local_busy_detected, - .next_state = LLC_CONN_STATE_AWAIT_BUSY, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_rejct_actions_2a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = NULL -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_2a = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_2a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_rejct_actions_2b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = NULL -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_2b = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_2b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_rejct_actions_3[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = NULL -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_3 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_4[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_stop_rej_timer, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_upd_vs, - [6] = llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr, - [7] = llc_conn_ac_clear_remote_busy, - [8] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_4 = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_5a[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rr_xxx_x_set_0, - [3] = llc_conn_ac_stop_rej_timer, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_upd_vs, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_5a = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_5a, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_5b[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rr_xxx_x_set_0, - [3] = llc_conn_ac_stop_rej_timer, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_upd_vs, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_5b = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_5b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_6[] = { - [0] = llc_conn_ac_inc_vr_by_1, - [1] = llc_conn_ac_data_ind, - [2] = llc_conn_ac_send_rr_rsp_f_set_1, - [3] = llc_conn_ac_stop_rej_timer, - [4] = llc_conn_ac_upd_nr_received, - [5] = llc_conn_ac_upd_vs, - [6] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_6 = { - .ev = llc_conn_ev_rx_i_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_6, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_7a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_7a = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_7a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_7b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_7b = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_7b, -}; - -/* State transitions for LLC_CONN_EV_RX_I_RSP_Fbit_SET_1_UNEXPD_Ns event */ -static const llc_conn_action_t llc_await_rejct_actions_7c[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_resend_i_xxx_x_set_0, - [4] = llc_conn_ac_clear_remote_busy, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_7c = { - .ev = llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_7c, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_8a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_8a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_8a, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_8b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_8b = { - .ev = llc_conn_ev_rx_rr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_8b, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_8c[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_8c = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_8c, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_8d[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_clear_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_8d = { - .ev = llc_conn_ev_rx_rej_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_8d, -}; - -/* State transitions for LLC_CONN_EV_RX_RR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_9a[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_9a = { - .ev = llc_conn_ev_rx_rr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_9a, -}; - -/* State transitions for LLC_CONN_EV_RX_REJ_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_9b[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_clear_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_9b = { - .ev = llc_conn_ev_rx_rej_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_9b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_10[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_stop_p_timer, - [3] = llc_conn_ac_set_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_10 = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_1, - .next_state = LLC_CONN_STATE_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_10, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_11a[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_11a = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_11a, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_RSP_Fbit_SET_0 event */ -static const llc_conn_action_t llc_await_rejct_actions_11b[] = { - [0] = llc_conn_ac_upd_nr_received, - [1] = llc_conn_ac_upd_vs, - [2] = llc_conn_ac_set_remote_busy, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_11b = { - .ev = llc_conn_ev_rx_rnr_rsp_fbit_set_0, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_11b, -}; - -/* State transitions for LLC_CONN_EV_RX_RNR_CMD_Pbit_SET_1 event */ -static const llc_conn_action_t llc_await_rejct_actions_12[] = { - [0] = llc_conn_ac_send_rr_rsp_f_set_1, - [1] = llc_conn_ac_upd_nr_received, - [2] = llc_conn_ac_upd_vs, - [3] = llc_conn_ac_set_remote_busy, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_12 = { - .ev = llc_conn_ev_rx_rnr_cmd_pbit_set_1, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = NONE, - .ev_actions = llc_await_rejct_actions_12, -}; - -/* State transitions for LLC_CONN_EV_P_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_await_rejct_ev_qfyrs_13[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_await_rejct_actions_13[] = { - [0] = llc_conn_ac_send_rej_cmd_p_set_1, - [1] = llc_conn_ac_stop_p_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_await_rejct_state_trans_13 = { - .ev = llc_conn_ev_p_tmr_exp, - .next_state = LLC_CONN_STATE_AWAIT_REJ, - .ev_qualifiers = llc_await_rejct_ev_qfyrs_13, - .ev_actions = llc_await_rejct_actions_13, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_await_rejct_state_transitions[] = { - [0] = &llc_await_reject_state_trans_1_0, - [1] = &llc_common_state_trans_1, /* requests */ - [2] = &llc_common_state_trans_2, - [3] = &llc_common_state_trans_end, - [4] = &llc_await_rejct_state_trans_1, /* local busy */ - [5] = &llc_common_state_trans_end, - [6] = &llc_common_state_trans_end, /* Initiate PF cycle */ - [7] = &llc_await_rejct_state_trans_13, /* timers */ - [8] = &llc_common_state_trans_11a, - [9] = &llc_common_state_trans_11b, - [10] = &llc_common_state_trans_11c, - [11] = &llc_common_state_trans_11d, - [12] = &llc_common_state_trans_end, - [13] = &llc_await_rejct_state_trans_2a, /* receive frames */ - [14] = &llc_await_rejct_state_trans_2b, - [15] = &llc_await_rejct_state_trans_3, - [16] = &llc_await_rejct_state_trans_4, - [17] = &llc_await_rejct_state_trans_5a, - [18] = &llc_await_rejct_state_trans_5b, - [19] = &llc_await_rejct_state_trans_6, - [20] = &llc_await_rejct_state_trans_7a, - [21] = &llc_await_rejct_state_trans_7b, - [22] = &llc_await_rejct_state_trans_7c, - [23] = &llc_await_rejct_state_trans_8a, - [24] = &llc_await_rejct_state_trans_8b, - [25] = &llc_await_rejct_state_trans_8c, - [26] = &llc_await_rejct_state_trans_8d, - [27] = &llc_await_rejct_state_trans_9a, - [28] = &llc_await_rejct_state_trans_9b, - [29] = &llc_await_rejct_state_trans_10, - [30] = &llc_await_rejct_state_trans_11a, - [31] = &llc_await_rejct_state_trans_11b, - [32] = &llc_await_rejct_state_trans_12, - [33] = &llc_common_state_trans_3, - [34] = &llc_common_state_trans_4, - [35] = &llc_common_state_trans_5, - [36] = &llc_common_state_trans_6, - [37] = &llc_common_state_trans_7a, - [38] = &llc_common_state_trans_7b, - [39] = &llc_common_state_trans_8a, - [40] = &llc_common_state_trans_8b, - [41] = &llc_common_state_trans_8c, - [42] = &llc_common_state_trans_9, - /* [43] = &llc_common_state_trans_10, */ - [43] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_D_CONN transitions */ -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event, - * cause_flag = 1 */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_1[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_1, - [1] = llc_conn_ev_qlfy_set_status_conflict, - [2] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_1[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_p, - [1] = llc_conn_ac_stop_ack_timer, - [2] = llc_conn_ac_disc_confirm, - [3] = llc_conn_disc, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_1 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_1, - .ev_actions = llc_d_conn_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event, - * cause_flag = 0 - */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_1_1[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_0, - [1] = llc_conn_ev_qlfy_set_status_conflict, - [2] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_1_1[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_p, - [1] = llc_conn_ac_stop_ack_timer, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_1_1 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_1_1, - .ev_actions = llc_d_conn_actions_1_1, -}; - -/* State transitions for LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X event, - * cause_flag = 1 - */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = llc_conn_ev_qlfy_cause_flag_eq_1, - [2] = llc_conn_ev_qlfy_set_status_disc, - [3] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_2[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_ac_disc_confirm, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_2 = { - .ev = llc_conn_ev_rx_ua_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_2, - .ev_actions = llc_d_conn_actions_2, -}; - -/* State transitions for LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X event, - * cause_flag = 0 - */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_2_1[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = llc_conn_ev_qlfy_cause_flag_eq_0, - [2] = llc_conn_ev_qlfy_set_status_disc, - [3] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_2_1[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_2_1 = { - .ev = llc_conn_ev_rx_ua_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_2_1, - .ev_actions = llc_d_conn_actions_2_1, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_d_conn_actions_3[] = { - [0] = llc_conn_ac_send_ua_rsp_f_set_p, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_3 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_D_CONN, - .ev_qualifiers = NONE, - .ev_actions = llc_d_conn_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event, - * cause_flag = 1 - */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_4[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_1, - [1] = llc_conn_ev_qlfy_set_status_disc, - [2] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_4[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_ac_disc_confirm, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_4 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_4, - .ev_actions = llc_d_conn_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event, - * cause_flag = 0 - */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_4_1[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_0, - [1] = llc_conn_ev_qlfy_set_status_disc, - [2] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_4_1[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_4_1 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_4_1, - .ev_actions = llc_d_conn_actions_4_1, -}; - -/* - * State transition for - * LLC_CONN_EV_DATA_CONN_REQ event - */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_5[] = { - [0] = llc_conn_ev_qlfy_set_status_refuse, - [1] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_d_conn_actions_5[1]; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_5 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_D_CONN, - .ev_qualifiers = llc_d_conn_ev_qfyrs_5, - .ev_actions = llc_d_conn_actions_5, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_6[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_6[] = { - [0] = llc_conn_ac_send_disc_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_6 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_D_CONN, - .ev_qualifiers = llc_d_conn_ev_qfyrs_6, - .ev_actions = llc_d_conn_actions_6, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event, cause_flag = 1 */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_7[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = llc_conn_ev_qlfy_cause_flag_eq_1, - [2] = llc_conn_ev_qlfy_set_status_failed, - [3] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_7[] = { - [0] = llc_conn_ac_disc_confirm, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_7 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_7, - .ev_actions = llc_d_conn_actions_7, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event, cause_flag = 0 */ -static const llc_conn_ev_qfyr_t llc_d_conn_ev_qfyrs_8[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = llc_conn_ev_qlfy_cause_flag_eq_0, - [2] = llc_conn_ev_qlfy_set_status_failed, - [3] = NULL, -}; - -static const llc_conn_action_t llc_d_conn_actions_8[] = { - [0] = llc_conn_disc, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_d_conn_state_trans_8 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_d_conn_ev_qfyrs_8, - .ev_actions = llc_d_conn_actions_8, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_d_conn_state_transitions[] = { - [0] = &llc_d_conn_state_trans_5, /* Request */ - [1] = &llc_common_state_trans_end, - [2] = &llc_common_state_trans_end, /* Local busy */ - [3] = &llc_common_state_trans_end, /* Initiate PF cycle */ - [4] = &llc_d_conn_state_trans_6, /* Timer */ - [5] = &llc_d_conn_state_trans_7, - [6] = &llc_d_conn_state_trans_8, - [7] = &llc_common_state_trans_end, - [8] = &llc_d_conn_state_trans_1, /* Receive frame */ - [9] = &llc_d_conn_state_trans_1_1, - [10] = &llc_d_conn_state_trans_2, - [11] = &llc_d_conn_state_trans_2_1, - [12] = &llc_d_conn_state_trans_3, - [13] = &llc_d_conn_state_trans_4, - [14] = &llc_d_conn_state_trans_4_1, - [15] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_RESET transitions */ -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_rst_actions_1[] = { - [0] = llc_conn_ac_set_vs_0, - [1] = llc_conn_ac_set_vr_0, - [2] = llc_conn_ac_set_s_flag_1, - [3] = llc_conn_ac_send_ua_rsp_f_set_p, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_1 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = NONE, - .ev_actions = llc_rst_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X event, - * cause_flag = 1 - */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_2[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = llc_conn_ev_qlfy_cause_flag_eq_1, - [2] = llc_conn_ev_qlfy_set_status_conn, - [3] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_2[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_ac_set_vs_0, - [2] = llc_conn_ac_set_vr_0, - [3] = llc_conn_ac_upd_p_flag, - [4] = llc_conn_ac_rst_confirm, - [5] = llc_conn_ac_set_remote_busy_0, - [6] = llc_conn_reset, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_2 = { - .ev = llc_conn_ev_rx_ua_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_rst_ev_qfyrs_2, - .ev_actions = llc_rst_actions_2, -}; - -/* State transitions for LLC_CONN_EV_RX_UA_RSP_Fbit_SET_X event, - * cause_flag = 0 - */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_2_1[] = { - [0] = llc_conn_ev_qlfy_p_flag_eq_f, - [1] = llc_conn_ev_qlfy_cause_flag_eq_0, - [2] = llc_conn_ev_qlfy_set_status_rst_done, - [3] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_2_1[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_ac_set_vs_0, - [2] = llc_conn_ac_set_vr_0, - [3] = llc_conn_ac_upd_p_flag, - [4] = llc_conn_ac_rst_confirm, - [5] = llc_conn_ac_set_remote_busy_0, - [6] = llc_conn_reset, - [7] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_2_1 = { - .ev = llc_conn_ev_rx_ua_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_rst_ev_qfyrs_2_1, - .ev_actions = llc_rst_actions_2_1, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_3[] = { - [0] = llc_conn_ev_qlfy_s_flag_eq_1, - [1] = llc_conn_ev_qlfy_set_status_rst_done, - [2] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_3[] = { - [0] = llc_conn_ac_set_p_flag_0, - [1] = llc_conn_ac_set_remote_busy_0, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_3 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = llc_rst_ev_qfyrs_3, - .ev_actions = llc_rst_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event, - * cause_flag = 1 - */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_4[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_1, - [1] = llc_conn_ev_qlfy_set_status_disc, - [2] = NULL, -}; -static const llc_conn_action_t llc_rst_actions_4[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_p, - [1] = llc_conn_ac_disc_ind, - [2] = llc_conn_ac_stop_ack_timer, - [3] = llc_conn_disc, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_4 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_rst_ev_qfyrs_4, - .ev_actions = llc_rst_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event, - * cause_flag = 0 - */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_4_1[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_0, - [1] = llc_conn_ev_qlfy_set_status_refuse, - [2] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_4_1[] = { - [0] = llc_conn_ac_send_dm_rsp_f_set_p, - [1] = llc_conn_ac_stop_ack_timer, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_4_1 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_rst_ev_qfyrs_4_1, - .ev_actions = llc_rst_actions_4_1, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event, - * cause_flag = 1 - */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_5[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_1, - [1] = llc_conn_ev_qlfy_set_status_disc, - [2] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_5[] = { - [0] = llc_conn_ac_disc_ind, - [1] = llc_conn_ac_stop_ack_timer, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_5 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_rst_ev_qfyrs_5, - .ev_actions = llc_rst_actions_5, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event, - * cause_flag = 0 - */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_5_1[] = { - [0] = llc_conn_ev_qlfy_cause_flag_eq_0, - [1] = llc_conn_ev_qlfy_set_status_refuse, - [2] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_5_1[] = { - [0] = llc_conn_ac_stop_ack_timer, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_5_1 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_rst_ev_qfyrs_5_1, - .ev_actions = llc_rst_actions_5_1, -}; - -/* State transitions for DATA_CONN_REQ event */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_6[] = { - [0] = llc_conn_ev_qlfy_set_status_refuse, - [1] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_rst_actions_6[1]; - -static const struct llc_conn_state_trans llc_rst_state_trans_6 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_rst_ev_qfyrs_6, - .ev_actions = llc_rst_actions_6, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_7[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = llc_conn_ev_qlfy_s_flag_eq_0, - [2] = NULL, -}; - -static const llc_conn_action_t llc_rst_actions_7[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_7 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_rst_ev_qfyrs_7, - .ev_actions = llc_rst_actions_7, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_8[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = llc_conn_ev_qlfy_s_flag_eq_0, - [2] = llc_conn_ev_qlfy_cause_flag_eq_1, - [3] = llc_conn_ev_qlfy_set_status_failed, - [4] = NULL, -}; -static const llc_conn_action_t llc_rst_actions_8[] = { - [0] = llc_conn_ac_disc_ind, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_8 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_rst_ev_qfyrs_8, - .ev_actions = llc_rst_actions_8, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_rst_ev_qfyrs_8_1[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = llc_conn_ev_qlfy_s_flag_eq_0, - [2] = llc_conn_ev_qlfy_cause_flag_eq_0, - [3] = llc_conn_ev_qlfy_set_status_failed, - [4] = NULL, -}; -static const llc_conn_action_t llc_rst_actions_8_1[] = { - [0] = llc_conn_ac_disc_ind, - [1] = llc_conn_disc, - [2] = NULL, -}; - -static const struct llc_conn_state_trans llc_rst_state_trans_8_1 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = llc_rst_ev_qfyrs_8_1, - .ev_actions = llc_rst_actions_8_1, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_rst_state_transitions[] = { - [0] = &llc_rst_state_trans_6, /* Request */ - [1] = &llc_common_state_trans_end, - [2] = &llc_common_state_trans_end, /* Local busy */ - [3] = &llc_common_state_trans_end, /* Initiate PF cycle */ - [4] = &llc_rst_state_trans_3, /* Timer */ - [5] = &llc_rst_state_trans_7, - [6] = &llc_rst_state_trans_8, - [7] = &llc_rst_state_trans_8_1, - [8] = &llc_common_state_trans_end, - [9] = &llc_rst_state_trans_1, /* Receive frame */ - [10] = &llc_rst_state_trans_2, - [11] = &llc_rst_state_trans_2_1, - [12] = &llc_rst_state_trans_4, - [13] = &llc_rst_state_trans_4_1, - [14] = &llc_rst_state_trans_5, - [15] = &llc_rst_state_trans_5_1, - [16] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_ERROR transitions */ -/* State transitions for LLC_CONN_EV_RX_SABME_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_error_actions_1[] = { - [0] = llc_conn_ac_set_vs_0, - [1] = llc_conn_ac_set_vr_0, - [2] = llc_conn_ac_send_ua_rsp_f_set_p, - [3] = llc_conn_ac_rst_ind, - [4] = llc_conn_ac_set_p_flag_0, - [5] = llc_conn_ac_set_remote_busy_0, - [6] = llc_conn_ac_stop_ack_timer, - [7] = llc_conn_reset, - [8] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_1 = { - .ev = llc_conn_ev_rx_sabme_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_NORMAL, - .ev_qualifiers = NONE, - .ev_actions = llc_error_actions_1, -}; - -/* State transitions for LLC_CONN_EV_RX_DISC_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_error_actions_2[] = { - [0] = llc_conn_ac_send_ua_rsp_f_set_p, - [1] = llc_conn_ac_disc_ind, - [2] = llc_conn_ac_stop_ack_timer, - [3] = llc_conn_disc, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_2 = { - .ev = llc_conn_ev_rx_disc_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_error_actions_2, -}; - -/* State transitions for LLC_CONN_EV_RX_DM_RSP_Fbit_SET_X event */ -static const llc_conn_action_t llc_error_actions_3[] = { - [0] = llc_conn_ac_disc_ind, - [1] = llc_conn_ac_stop_ack_timer, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_3 = { - .ev = llc_conn_ev_rx_dm_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_error_actions_3, -}; - -/* State transitions for LLC_CONN_EV_RX_FRMR_RSP_Fbit_SET_X event */ -static const llc_conn_action_t llc_error_actions_4[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_set_retry_cnt_0, - [3] = llc_conn_ac_set_cause_flag_0, - [4] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_4 = { - .ev = llc_conn_ev_rx_frmr_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = NONE, - .ev_actions = llc_error_actions_4, -}; - -/* State transitions for LLC_CONN_EV_RX_XXX_CMD_Pbit_SET_X event */ -static const llc_conn_action_t llc_error_actions_5[] = { - [0] = llc_conn_ac_resend_frmr_rsp_f_set_p, - [1] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_5 = { - .ev = llc_conn_ev_rx_xxx_cmd_pbit_set_x, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = llc_error_actions_5, -}; - -/* State transitions for LLC_CONN_EV_RX_XXX_RSP_Fbit_SET_X event */ -static const struct llc_conn_state_trans llc_error_state_trans_6 = { - .ev = llc_conn_ev_rx_xxx_rsp_fbit_set_x, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = NONE, - .ev_actions = NONE, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_error_ev_qfyrs_7[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_lt_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_error_actions_7[] = { - [0] = llc_conn_ac_resend_frmr_rsp_f_set_0, - [1] = llc_conn_ac_start_ack_timer, - [2] = llc_conn_ac_inc_retry_cnt_by_1, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_7 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = llc_error_ev_qfyrs_7, - .ev_actions = llc_error_actions_7, -}; - -/* State transitions for LLC_CONN_EV_ACK_TMR_EXP event */ -static const llc_conn_ev_qfyr_t llc_error_ev_qfyrs_8[] = { - [0] = llc_conn_ev_qlfy_retry_cnt_gte_n2, - [1] = NULL, -}; - -static const llc_conn_action_t llc_error_actions_8[] = { - [0] = llc_conn_ac_send_sabme_cmd_p_set_x, - [1] = llc_conn_ac_set_s_flag_0, - [2] = llc_conn_ac_start_ack_timer, - [3] = llc_conn_ac_set_retry_cnt_0, - [4] = llc_conn_ac_set_cause_flag_0, - [5] = NULL, -}; - -static const struct llc_conn_state_trans llc_error_state_trans_8 = { - .ev = llc_conn_ev_ack_tmr_exp, - .next_state = LLC_CONN_STATE_RESET, - .ev_qualifiers = llc_error_ev_qfyrs_8, - .ev_actions = llc_error_actions_8, -}; - -/* State transitions for LLC_CONN_EV_DATA_CONN_REQ event */ -static const llc_conn_ev_qfyr_t llc_error_ev_qfyrs_9[] = { - [0] = llc_conn_ev_qlfy_set_status_refuse, - [1] = NULL, -}; - -/* just one member, NULL, .bss zeroes it */ -static const llc_conn_action_t llc_error_actions_9[1]; - -static const struct llc_conn_state_trans llc_error_state_trans_9 = { - .ev = llc_conn_ev_data_req, - .next_state = LLC_CONN_STATE_ERROR, - .ev_qualifiers = llc_error_ev_qfyrs_9, - .ev_actions = llc_error_actions_9, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_error_state_transitions[] = { - [0] = &llc_error_state_trans_9, /* Request */ - [1] = &llc_common_state_trans_end, - [2] = &llc_common_state_trans_end, /* Local busy */ - [3] = &llc_common_state_trans_end, /* Initiate PF cycle */ - [4] = &llc_error_state_trans_7, /* Timer */ - [5] = &llc_error_state_trans_8, - [6] = &llc_common_state_trans_end, - [7] = &llc_error_state_trans_1, /* Receive frame */ - [8] = &llc_error_state_trans_2, - [9] = &llc_error_state_trans_3, - [10] = &llc_error_state_trans_4, - [11] = &llc_error_state_trans_5, - [12] = &llc_error_state_trans_6, - [13] = &llc_common_state_trans_end, -}; - -/* LLC_CONN_STATE_TEMP transitions */ -/* State transitions for LLC_CONN_EV_DISC_REQ event */ -static const llc_conn_action_t llc_temp_actions_1[] = { - [0] = llc_conn_ac_stop_all_timers, - [1] = llc_conn_ac_send_disc_cmd_p_set_x, - [2] = llc_conn_disc, - [3] = NULL, -}; - -static const struct llc_conn_state_trans llc_temp_state_trans_1 = { - .ev = llc_conn_ev_disc_req, - .next_state = LLC_CONN_STATE_ADM, - .ev_qualifiers = NONE, - .ev_actions = llc_temp_actions_1, -}; - -/* - * Array of pointers; - * one to each transition - */ -static const struct llc_conn_state_trans *llc_temp_state_transitions[] = { - [0] = &llc_temp_state_trans_1, /* requests */ - [1] = &llc_common_state_trans_end, - [2] = &llc_common_state_trans_end, /* local busy */ - [3] = &llc_common_state_trans_end, /* init_pf_cycle */ - [4] = &llc_common_state_trans_end, /* timer */ - [5] = &llc_common_state_trans_end, /* receive */ -}; - -/* Connection State Transition Table */ -struct llc_conn_state llc_conn_state_table[NBR_CONN_STATES] = { - [LLC_CONN_STATE_ADM - 1] = { - .current_state = LLC_CONN_STATE_ADM, - .transitions = llc_adm_state_transitions, - }, - [LLC_CONN_STATE_SETUP - 1] = { - .current_state = LLC_CONN_STATE_SETUP, - .transitions = llc_setup_state_transitions, - }, - [LLC_CONN_STATE_NORMAL - 1] = { - .current_state = LLC_CONN_STATE_NORMAL, - .transitions = llc_normal_state_transitions, - }, - [LLC_CONN_STATE_BUSY - 1] = { - .current_state = LLC_CONN_STATE_BUSY, - .transitions = llc_busy_state_transitions, - }, - [LLC_CONN_STATE_REJ - 1] = { - .current_state = LLC_CONN_STATE_REJ, - .transitions = llc_reject_state_transitions, - }, - [LLC_CONN_STATE_AWAIT - 1] = { - .current_state = LLC_CONN_STATE_AWAIT, - .transitions = llc_await_state_transitions, - }, - [LLC_CONN_STATE_AWAIT_BUSY - 1] = { - .current_state = LLC_CONN_STATE_AWAIT_BUSY, - .transitions = llc_await_busy_state_transitions, - }, - [LLC_CONN_STATE_AWAIT_REJ - 1] = { - .current_state = LLC_CONN_STATE_AWAIT_REJ, - .transitions = llc_await_rejct_state_transitions, - }, - [LLC_CONN_STATE_D_CONN - 1] = { - .current_state = LLC_CONN_STATE_D_CONN, - .transitions = llc_d_conn_state_transitions, - }, - [LLC_CONN_STATE_RESET - 1] = { - .current_state = LLC_CONN_STATE_RESET, - .transitions = llc_rst_state_transitions, - }, - [LLC_CONN_STATE_ERROR - 1] = { - .current_state = LLC_CONN_STATE_ERROR, - .transitions = llc_error_state_transitions, - }, - [LLC_CONN_STATE_TEMP - 1] = { - .current_state = LLC_CONN_STATE_TEMP, - .transitions = llc_temp_state_transitions, - }, -}; diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c deleted file mode 100644 index 4b6fe9a473cb..000000000000 --- a/net/llc/llc_conn.c +++ /dev/null @@ -1,1025 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_conn.c - Driver routines for connection component. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if 0 -#define dprintk(args...) printk(KERN_DEBUG args) -#else -#define dprintk(args...) -#endif - -static int llc_find_offset(int state, int ev_type); -static void llc_conn_send_pdus(struct sock *sk); -static int llc_conn_service(struct sock *sk, struct sk_buff *skb); -static int llc_exec_conn_trans_actions(struct sock *sk, - const struct llc_conn_state_trans *trans, - struct sk_buff *ev); -static const struct llc_conn_state_trans *llc_qualify_conn_ev(struct sock *sk, - struct sk_buff *skb); - -/* Offset table on connection states transition diagram */ -static int llc_offset_table[NBR_CONN_STATES][NBR_CONN_EV]; - -int sysctl_llc2_ack_timeout = LLC2_ACK_TIME * HZ; -int sysctl_llc2_p_timeout = LLC2_P_TIME * HZ; -int sysctl_llc2_rej_timeout = LLC2_REJ_TIME * HZ; -int sysctl_llc2_busy_timeout = LLC2_BUSY_TIME * HZ; - -/** - * llc_conn_state_process - sends event to connection state machine - * @sk: connection - * @skb: occurred event - * - * Sends an event to connection state machine. After processing event - * (executing it's actions and changing state), upper layer will be - * indicated or confirmed, if needed. Returns 0 for success, 1 for - * failure. The socket lock has to be held before calling this function. - * - * This function always consumes a reference to the skb. - */ -int llc_conn_state_process(struct sock *sk, struct sk_buff *skb) -{ - int rc; - struct llc_sock *llc = llc_sk(skb->sk); - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->ind_prim = ev->cfm_prim = 0; - /* - * Send event to state machine - */ - rc = llc_conn_service(skb->sk, skb); - if (unlikely(rc != 0)) { - printk(KERN_ERR "%s: llc_conn_service failed\n", __func__); - goto out_skb_put; - } - - switch (ev->ind_prim) { - case LLC_DATA_PRIM: - skb_get(skb); - llc_save_primitive(sk, skb, LLC_DATA_PRIM); - if (unlikely(sock_queue_rcv_skb(sk, skb))) { - /* - * shouldn't happen - */ - printk(KERN_ERR "%s: sock_queue_rcv_skb failed!\n", - __func__); - kfree_skb(skb); - } - break; - case LLC_CONN_PRIM: - /* - * Can't be sock_queue_rcv_skb, because we have to leave the - * skb->sk pointing to the newly created struct sock in - * llc_conn_handler. -acme - */ - skb_get(skb); - skb_queue_tail(&sk->sk_receive_queue, skb); - sk->sk_state_change(sk); - break; - case LLC_DISC_PRIM: - sock_hold(sk); - if (sk->sk_type == SOCK_STREAM && - sk->sk_state == TCP_ESTABLISHED) { - sk->sk_shutdown = SHUTDOWN_MASK; - sk->sk_socket->state = SS_UNCONNECTED; - sk->sk_state = TCP_CLOSE; - if (!sock_flag(sk, SOCK_DEAD)) { - sock_set_flag(sk, SOCK_DEAD); - sk->sk_state_change(sk); - } - } - sock_put(sk); - break; - case LLC_RESET_PRIM: - /* - * FIXME: - * RESET is not being notified to upper layers for now - */ - printk(KERN_INFO "%s: received a reset ind!\n", __func__); - break; - default: - if (ev->ind_prim) - printk(KERN_INFO "%s: received unknown %d prim!\n", - __func__, ev->ind_prim); - /* No indication */ - break; - } - - switch (ev->cfm_prim) { - case LLC_DATA_PRIM: - if (!llc_data_accept_state(llc->state)) - sk->sk_write_space(sk); - else - rc = llc->failed_data_req = 1; - break; - case LLC_CONN_PRIM: - if (sk->sk_type == SOCK_STREAM && - sk->sk_state == TCP_SYN_SENT) { - if (ev->status) { - sk->sk_socket->state = SS_UNCONNECTED; - sk->sk_state = TCP_CLOSE; - } else { - sk->sk_socket->state = SS_CONNECTED; - sk->sk_state = TCP_ESTABLISHED; - } - sk->sk_state_change(sk); - } - break; - case LLC_DISC_PRIM: - sock_hold(sk); - if (sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_CLOSING) { - sk->sk_socket->state = SS_UNCONNECTED; - sk->sk_state = TCP_CLOSE; - sk->sk_state_change(sk); - } - sock_put(sk); - break; - case LLC_RESET_PRIM: - /* - * FIXME: - * RESET is not being notified to upper layers for now - */ - printk(KERN_INFO "%s: received a reset conf!\n", __func__); - break; - default: - if (ev->cfm_prim) - printk(KERN_INFO "%s: received unknown %d prim!\n", - __func__, ev->cfm_prim); - /* No confirmation */ - break; - } -out_skb_put: - kfree_skb(skb); - return rc; -} - -void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb) -{ - /* queue PDU to send to MAC layer */ - skb_queue_tail(&sk->sk_write_queue, skb); - llc_conn_send_pdus(sk); -} - -/** - * llc_conn_rtn_pdu - sends received data pdu to upper layer - * @sk: Active connection - * @skb: Received data frame - * - * Sends received data pdu to upper layer (by using indicate function). - * Prepares service parameters (prim and prim_data). calling indication - * function will be done in llc_conn_state_process. - */ -void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->ind_prim = LLC_DATA_PRIM; -} - -/** - * llc_conn_resend_i_pdu_as_cmd - resend all unacknowledged I PDUs - * @sk: active connection - * @nr: NR - * @first_p_bit: p_bit value of first pdu - * - * Resend all unacknowledged I PDUs, starting with the NR; send first as - * command PDU with P bit equal first_p_bit; if more than one send - * subsequent as command PDUs with P bit equal zero (0). - */ -void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit) -{ - struct sk_buff *skb; - struct llc_pdu_sn *pdu; - u16 nbr_unack_pdus; - struct llc_sock *llc; - u8 howmany_resend = 0; - - llc_conn_remove_acked_pdus(sk, nr, &nbr_unack_pdus); - if (!nbr_unack_pdus) - goto out; - /* - * Process unack PDUs only if unack queue is not empty; remove - * appropriate PDUs, fix them up, and put them on mac_pdu_q. - */ - llc = llc_sk(sk); - - while ((skb = skb_dequeue(&llc->pdu_unack_q)) != NULL) { - pdu = llc_pdu_sn_hdr(skb); - llc_pdu_set_cmd_rsp(skb, LLC_PDU_CMD); - llc_pdu_set_pf_bit(skb, first_p_bit); - skb_queue_tail(&sk->sk_write_queue, skb); - first_p_bit = 0; - llc->vS = LLC_I_GET_NS(pdu); - howmany_resend++; - } - if (howmany_resend > 0) - llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO; - /* any PDUs to re-send are queued up; start sending to MAC */ - llc_conn_send_pdus(sk); -out:; -} - -/** - * llc_conn_resend_i_pdu_as_rsp - Resend all unacknowledged I PDUs - * @sk: active connection. - * @nr: NR - * @first_f_bit: f_bit value of first pdu. - * - * Resend all unacknowledged I PDUs, starting with the NR; send first as - * response PDU with F bit equal first_f_bit; if more than one send - * subsequent as response PDUs with F bit equal zero (0). - */ -void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit) -{ - struct sk_buff *skb; - u16 nbr_unack_pdus; - struct llc_sock *llc = llc_sk(sk); - u8 howmany_resend = 0; - - llc_conn_remove_acked_pdus(sk, nr, &nbr_unack_pdus); - if (!nbr_unack_pdus) - goto out; - /* - * Process unack PDUs only if unack queue is not empty; remove - * appropriate PDUs, fix them up, and put them on mac_pdu_q - */ - while ((skb = skb_dequeue(&llc->pdu_unack_q)) != NULL) { - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - llc_pdu_set_cmd_rsp(skb, LLC_PDU_RSP); - llc_pdu_set_pf_bit(skb, first_f_bit); - skb_queue_tail(&sk->sk_write_queue, skb); - first_f_bit = 0; - llc->vS = LLC_I_GET_NS(pdu); - howmany_resend++; - } - if (howmany_resend > 0) - llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO; - /* any PDUs to re-send are queued up; start sending to MAC */ - llc_conn_send_pdus(sk); -out:; -} - -/** - * llc_conn_remove_acked_pdus - Removes acknowledged pdus from tx queue - * @sk: active connection - * @nr: NR - * @how_many_unacked: size of pdu_unack_q after removing acked pdus - * - * Removes acknowledged pdus from transmit queue (pdu_unack_q). Returns - * the number of pdus that removed from queue. - */ -int llc_conn_remove_acked_pdus(struct sock *sk, u8 nr, u16 *how_many_unacked) -{ - int pdu_pos, i; - struct sk_buff *skb; - struct llc_pdu_sn *pdu; - int nbr_acked = 0; - struct llc_sock *llc = llc_sk(sk); - int q_len = skb_queue_len(&llc->pdu_unack_q); - - if (!q_len) - goto out; - skb = skb_peek(&llc->pdu_unack_q); - pdu = llc_pdu_sn_hdr(skb); - - /* finding position of last acked pdu in queue */ - pdu_pos = ((int)LLC_2_SEQ_NBR_MODULO + (int)nr - - (int)LLC_I_GET_NS(pdu)) % LLC_2_SEQ_NBR_MODULO; - - for (i = 0; i < pdu_pos && i < q_len; i++) { - skb = skb_dequeue(&llc->pdu_unack_q); - kfree_skb(skb); - nbr_acked++; - } -out: - *how_many_unacked = skb_queue_len(&llc->pdu_unack_q); - return nbr_acked; -} - -/** - * llc_conn_send_pdus - Sends queued PDUs - * @sk: active connection - * - * Sends queued pdus to MAC layer for transmission. - */ -static void llc_conn_send_pdus(struct sock *sk) -{ - struct sk_buff *skb; - - while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) { - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - if (LLC_PDU_TYPE_IS_I(pdu) && - !(skb->dev->flags & IFF_LOOPBACK)) { - struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); - - skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb); - if (!skb2) - break; - skb = skb2; - } - dev_queue_xmit(skb); - } -} - -/** - * llc_conn_service - finds transition and changes state of connection - * @sk: connection - * @skb: happened event - * - * This function finds transition that matches with happened event, then - * executes related actions and finally changes state of connection. - * Returns 0 for success, 1 for failure. - */ -static int llc_conn_service(struct sock *sk, struct sk_buff *skb) -{ - const struct llc_conn_state_trans *trans; - struct llc_sock *llc = llc_sk(sk); - int rc = 1; - - if (llc->state > NBR_CONN_STATES) - goto out; - rc = 0; - trans = llc_qualify_conn_ev(sk, skb); - if (trans) { - rc = llc_exec_conn_trans_actions(sk, trans, skb); - if (!rc && trans->next_state != NO_STATE_CHANGE) { - llc->state = trans->next_state; - if (!llc_data_accept_state(llc->state)) - sk->sk_state_change(sk); - } - } -out: - return rc; -} - -/** - * llc_qualify_conn_ev - finds transition for event - * @sk: connection - * @skb: happened event - * - * This function finds transition that matches with happened event. - * Returns pointer to found transition on success, %NULL otherwise. - */ -static const struct llc_conn_state_trans *llc_qualify_conn_ev(struct sock *sk, - struct sk_buff *skb) -{ - const struct llc_conn_state_trans **next_trans; - const llc_conn_ev_qfyr_t *next_qualifier; - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - struct llc_sock *llc = llc_sk(sk); - struct llc_conn_state *curr_state = - &llc_conn_state_table[llc->state - 1]; - - /* search thru events for this state until - * list exhausted or until no more - */ - for (next_trans = curr_state->transitions + - llc_find_offset(llc->state - 1, ev->type); - (*next_trans)->ev; next_trans++) { - if (!((*next_trans)->ev)(sk, skb)) { - /* got POSSIBLE event match; the event may require - * qualification based on the values of a number of - * state flags; if all qualifications are met (i.e., - * if all qualifying functions return success, or 0, - * then this is THE event we're looking for - */ - for (next_qualifier = (*next_trans)->ev_qualifiers; - next_qualifier && *next_qualifier && - !(*next_qualifier)(sk, skb); next_qualifier++) - /* nothing */; - if (!next_qualifier || !*next_qualifier) - /* all qualifiers executed successfully; this is - * our transition; return it so we can perform - * the associated actions & change the state - */ - return *next_trans; - } - } - return NULL; -} - -/** - * llc_exec_conn_trans_actions - executes related actions - * @sk: connection - * @trans: transition that it's actions must be performed - * @skb: event - * - * Executes actions that is related to happened event. Returns 0 for - * success, 1 to indicate failure of at least one action. - */ -static int llc_exec_conn_trans_actions(struct sock *sk, - const struct llc_conn_state_trans *trans, - struct sk_buff *skb) -{ - int rc = 0; - const llc_conn_action_t *next_action; - - for (next_action = trans->ev_actions; - next_action && *next_action; next_action++) { - int rc2 = (*next_action)(sk, skb); - - if (rc2 == 2) { - rc = rc2; - break; - } else if (rc2) - rc = 1; - } - return rc; -} - -static inline bool llc_estab_match(const struct llc_sap *sap, - const struct llc_addr *daddr, - const struct llc_addr *laddr, - const struct sock *sk, - const struct net *net) -{ - struct llc_sock *llc = llc_sk(sk); - - return net_eq(sock_net(sk), net) && - llc->laddr.lsap == laddr->lsap && - llc->daddr.lsap == daddr->lsap && - ether_addr_equal(llc->laddr.mac, laddr->mac) && - ether_addr_equal(llc->daddr.mac, daddr->mac); -} - -/** - * __llc_lookup_established - Finds connection for the remote/local sap/mac - * @sap: SAP - * @daddr: address of remote LLC (MAC + SAP) - * @laddr: address of local LLC (MAC + SAP) - * @net: netns to look up a socket in - * - * Search connection list of the SAP and finds connection using the remote - * mac, remote sap, local mac, and local sap. Returns pointer for - * connection found, %NULL otherwise. - * Caller has to make sure local_bh is disabled. - */ -static struct sock *__llc_lookup_established(struct llc_sap *sap, - struct llc_addr *daddr, - struct llc_addr *laddr, - const struct net *net) -{ - struct sock *rc; - struct hlist_nulls_node *node; - int slot = llc_sk_laddr_hashfn(sap, laddr); - struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot]; - - rcu_read_lock(); -again: - sk_nulls_for_each_rcu(rc, node, laddr_hb) { - if (llc_estab_match(sap, daddr, laddr, rc, net)) { - /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ - if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt))) - goto again; - if (unlikely(llc_sk(rc)->sap != sap || - !llc_estab_match(sap, daddr, laddr, rc, net))) { - sock_put(rc); - continue; - } - goto found; - } - } - rc = NULL; - /* - * if the nulls value we got at the end of this lookup is - * not the expected one, we must restart lookup. - * We probably met an item that was moved to another chain. - */ - if (unlikely(get_nulls_value(node) != slot)) - goto again; -found: - rcu_read_unlock(); - return rc; -} - -struct sock *llc_lookup_established(struct llc_sap *sap, - struct llc_addr *daddr, - struct llc_addr *laddr, - const struct net *net) -{ - struct sock *sk; - - local_bh_disable(); - sk = __llc_lookup_established(sap, daddr, laddr, net); - local_bh_enable(); - return sk; -} - -static inline bool llc_listener_match(const struct llc_sap *sap, - const struct llc_addr *laddr, - const struct sock *sk, - const struct net *net) -{ - struct llc_sock *llc = llc_sk(sk); - - return net_eq(sock_net(sk), net) && - sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN && - llc->laddr.lsap == laddr->lsap && - ether_addr_equal(llc->laddr.mac, laddr->mac); -} - -static struct sock *__llc_lookup_listener(struct llc_sap *sap, - struct llc_addr *laddr, - const struct net *net) -{ - struct sock *rc; - struct hlist_nulls_node *node; - int slot = llc_sk_laddr_hashfn(sap, laddr); - struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot]; - - rcu_read_lock(); -again: - sk_nulls_for_each_rcu(rc, node, laddr_hb) { - if (llc_listener_match(sap, laddr, rc, net)) { - /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ - if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt))) - goto again; - if (unlikely(llc_sk(rc)->sap != sap || - !llc_listener_match(sap, laddr, rc, net))) { - sock_put(rc); - continue; - } - goto found; - } - } - rc = NULL; - /* - * if the nulls value we got at the end of this lookup is - * not the expected one, we must restart lookup. - * We probably met an item that was moved to another chain. - */ - if (unlikely(get_nulls_value(node) != slot)) - goto again; -found: - rcu_read_unlock(); - return rc; -} - -/** - * llc_lookup_listener - Finds listener for local MAC + SAP - * @sap: SAP - * @laddr: address of local LLC (MAC + SAP) - * @net: netns to look up a socket in - * - * Search connection list of the SAP and finds connection listening on - * local mac, and local sap. Returns pointer for parent socket found, - * %NULL otherwise. - * Caller has to make sure local_bh is disabled. - */ -static struct sock *llc_lookup_listener(struct llc_sap *sap, - struct llc_addr *laddr, - const struct net *net) -{ - struct sock *rc = __llc_lookup_listener(sap, laddr, net); - static struct llc_addr null_addr; - - if (!rc) - rc = __llc_lookup_listener(sap, &null_addr, net); - - return rc; -} - -static struct sock *__llc_lookup(struct llc_sap *sap, - struct llc_addr *daddr, - struct llc_addr *laddr, - const struct net *net) -{ - struct sock *sk = __llc_lookup_established(sap, daddr, laddr, net); - - return sk ? : llc_lookup_listener(sap, laddr, net); -} - -/** - * llc_data_accept_state - designates if in this state data can be sent. - * @state: state of connection. - * - * Returns 0 if data can be sent, 1 otherwise. - */ -u8 llc_data_accept_state(u8 state) -{ - return state != LLC_CONN_STATE_NORMAL && state != LLC_CONN_STATE_BUSY && - state != LLC_CONN_STATE_REJ; -} - -/** - * llc_find_next_offset - finds offset for next category of transitions - * @state: state table. - * @offset: start offset. - * - * Finds offset of next category of transitions in transition table. - * Returns the start index of next category. - */ -static u16 __init llc_find_next_offset(struct llc_conn_state *state, u16 offset) -{ - const struct llc_conn_state_trans **next_trans; - u16 cnt = 0; - - for (next_trans = state->transitions + offset; - (*next_trans)->ev; next_trans++) - ++cnt; - return cnt; -} - -/** - * llc_build_offset_table - builds offset table of connection - * - * Fills offset table of connection state transition table - * (llc_offset_table). - */ -void __init llc_build_offset_table(void) -{ - struct llc_conn_state *curr_state; - int state, ev_type, next_offset; - - for (state = 0; state < NBR_CONN_STATES; state++) { - curr_state = &llc_conn_state_table[state]; - next_offset = 0; - for (ev_type = 0; ev_type < NBR_CONN_EV; ev_type++) { - llc_offset_table[state][ev_type] = next_offset; - next_offset += llc_find_next_offset(curr_state, - next_offset) + 1; - } - } -} - -/** - * llc_find_offset - finds start offset of category of transitions - * @state: state of connection - * @ev_type: type of happened event - * - * Finds start offset of desired category of transitions. Returns the - * desired start offset. - */ -static int llc_find_offset(int state, int ev_type) -{ - int rc = 0; - /* at this stage, llc_offset_table[..][2] is not important. it is for - * init_pf_cycle and I don't know what is it. - */ - switch (ev_type) { - case LLC_CONN_EV_TYPE_PRIM: - rc = llc_offset_table[state][0]; break; - case LLC_CONN_EV_TYPE_PDU: - rc = llc_offset_table[state][4]; break; - case LLC_CONN_EV_TYPE_SIMPLE: - rc = llc_offset_table[state][1]; break; - case LLC_CONN_EV_TYPE_P_TMR: - case LLC_CONN_EV_TYPE_ACK_TMR: - case LLC_CONN_EV_TYPE_REJ_TMR: - case LLC_CONN_EV_TYPE_BUSY_TMR: - rc = llc_offset_table[state][3]; break; - } - return rc; -} - -/** - * llc_sap_add_socket - adds a socket to a SAP - * @sap: SAP - * @sk: socket - * - * This function adds a socket to the hash tables of a SAP. - */ -void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk) -{ - struct llc_sock *llc = llc_sk(sk); - struct hlist_head *dev_hb = llc_sk_dev_hash(sap, llc->dev->ifindex); - struct hlist_nulls_head *laddr_hb = llc_sk_laddr_hash(sap, &llc->laddr); - - llc_sap_hold(sap); - llc_sk(sk)->sap = sap; - - spin_lock_bh(&sap->sk_lock); - sock_set_flag(sk, SOCK_RCU_FREE); - sap->sk_count++; - sk_nulls_add_node_rcu(sk, laddr_hb); - hlist_add_head(&llc->dev_hash_node, dev_hb); - spin_unlock_bh(&sap->sk_lock); -} - -/** - * llc_sap_remove_socket - removes a socket from SAP - * @sap: SAP - * @sk: socket - * - * This function removes a connection from the hash tables of a SAP if - * the connection was in this list. - */ -void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk) -{ - struct llc_sock *llc = llc_sk(sk); - - spin_lock_bh(&sap->sk_lock); - sk_nulls_del_node_init_rcu(sk); - hlist_del(&llc->dev_hash_node); - sap->sk_count--; - spin_unlock_bh(&sap->sk_lock); - llc_sap_put(sap); -} - -/** - * llc_conn_rcv - sends received pdus to the connection state machine - * @sk: current connection structure. - * @skb: received frame. - * - * Sends received pdus to the connection state machine. - */ -static int llc_conn_rcv(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->type = LLC_CONN_EV_TYPE_PDU; - ev->reason = 0; - return llc_conn_state_process(sk, skb); -} - -static struct sock *llc_create_incoming_sock(struct sock *sk, - struct net_device *dev, - struct llc_addr *saddr, - struct llc_addr *daddr) -{ - struct sock *newsk = llc_sk_alloc(sock_net(sk), sk->sk_family, GFP_ATOMIC, - sk->sk_prot, 0); - struct llc_sock *newllc, *llc = llc_sk(sk); - - if (!newsk) - goto out; - newllc = llc_sk(newsk); - memcpy(&newllc->laddr, daddr, sizeof(newllc->laddr)); - memcpy(&newllc->daddr, saddr, sizeof(newllc->daddr)); - newllc->dev = dev; - dev_hold(dev); - llc_sap_add_socket(llc->sap, newsk); -out: - return newsk; -} - -void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_addr saddr, daddr; - struct sock *sk; - - llc_pdu_decode_sa(skb, saddr.mac); - llc_pdu_decode_ssap(skb, &saddr.lsap); - llc_pdu_decode_da(skb, daddr.mac); - llc_pdu_decode_dsap(skb, &daddr.lsap); - - sk = __llc_lookup(sap, &saddr, &daddr, dev_net(skb->dev)); - if (!sk) - goto drop; - - bh_lock_sock(sk); - /* - * This has to be done here and not at the upper layer ->accept - * method because of the way the PROCOM state machine works: - * it needs to set several state variables (see, for instance, - * llc_adm_actions_2 in net/llc/llc_c_st.c) and send a packet to - * the originator of the new connection, and this state has to be - * in the newly created struct sock private area. -acme - */ - if (unlikely(sk->sk_state == TCP_LISTEN)) { - struct sock *newsk = llc_create_incoming_sock(sk, skb->dev, - &saddr, &daddr); - if (!newsk) - goto drop_unlock; - skb_set_owner_r(skb, newsk); - } else { - /* - * Can't be skb_set_owner_r, this will be done at the - * llc_conn_state_process function, later on, when we will use - * skb_queue_rcv_skb to send it to upper layers, this is - * another trick required to cope with how the PROCOM state - * machine works. -acme - */ - skb_orphan(skb); - sock_hold(sk); - skb->sk = sk; - skb->destructor = sock_efree; - } - if (!sock_owned_by_user(sk)) - llc_conn_rcv(sk, skb); - else { - dprintk("%s: adding to backlog...\n", __func__); - llc_set_backlog_type(skb, LLC_PACKET); - if (sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf))) - goto drop_unlock; - } -out: - bh_unlock_sock(sk); - sock_put(sk); - return; -drop: - kfree_skb(skb); - return; -drop_unlock: - kfree_skb(skb); - goto out; -} - -#undef LLC_REFCNT_DEBUG -#ifdef LLC_REFCNT_DEBUG -static atomic_t llc_sock_nr; -#endif - -/** - * llc_backlog_rcv - Processes rx frames and expired timers. - * @sk: LLC sock (p8022 connection) - * @skb: queued rx frame or event - * - * This function processes frames that has received and timers that has - * expired during sending an I pdu (refer to data_req_handler). frames - * queue by llc_rcv function (llc_mac.c) and timers queue by timer - * callback functions(llc_c_ac.c). - */ -static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb) -{ - int rc = 0; - struct llc_sock *llc = llc_sk(sk); - - if (likely(llc_backlog_type(skb) == LLC_PACKET)) { - if (likely(llc->state > 1)) /* not closed */ - rc = llc_conn_rcv(sk, skb); - else - goto out_kfree_skb; - } else if (llc_backlog_type(skb) == LLC_EVENT) { - /* timer expiration event */ - if (likely(llc->state > 1)) /* not closed */ - rc = llc_conn_state_process(sk, skb); - else - goto out_kfree_skb; - } else { - printk(KERN_ERR "%s: invalid skb in backlog\n", __func__); - goto out_kfree_skb; - } -out: - return rc; -out_kfree_skb: - kfree_skb(skb); - goto out; -} - -/** - * llc_sk_init - Initializes a socket with default llc values. - * @sk: socket to initialize. - * - * Initializes a socket with default llc values. - */ -static void llc_sk_init(struct sock *sk) -{ - struct llc_sock *llc = llc_sk(sk); - - llc->state = LLC_CONN_STATE_ADM; - llc->inc_cntr = llc->dec_cntr = 2; - llc->dec_step = llc->connect_step = 1; - - timer_setup(&llc->ack_timer.timer, llc_conn_ack_tmr_cb, 0); - llc->ack_timer.expire = sysctl_llc2_ack_timeout; - - timer_setup(&llc->pf_cycle_timer.timer, llc_conn_pf_cycle_tmr_cb, 0); - llc->pf_cycle_timer.expire = sysctl_llc2_p_timeout; - - timer_setup(&llc->rej_sent_timer.timer, llc_conn_rej_tmr_cb, 0); - llc->rej_sent_timer.expire = sysctl_llc2_rej_timeout; - - timer_setup(&llc->busy_state_timer.timer, llc_conn_busy_tmr_cb, 0); - llc->busy_state_timer.expire = sysctl_llc2_busy_timeout; - - llc->n2 = 2; /* max retransmit */ - llc->k = 2; /* tx win size, will adjust dynam */ - llc->rw = 128; /* rx win size (opt and equal to - * tx_win of remote LLC) */ - skb_queue_head_init(&llc->pdu_unack_q); - sk->sk_backlog_rcv = llc_backlog_rcv; -} - -/** - * llc_sk_alloc - Allocates LLC sock - * @net: network namespace - * @family: upper layer protocol family - * @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc) - * @prot: struct proto associated with this new sock instance - * @kern: is this to be a kernel socket? - * - * Allocates a LLC sock and initializes it. Returns the new LLC sock - * or %NULL if there's no memory available for one - */ -struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority, struct proto *prot, int kern) -{ - struct sock *sk = sk_alloc(net, family, priority, prot, kern); - - if (!sk) - goto out; - llc_sk_init(sk); - sock_init_data(NULL, sk); -#ifdef LLC_REFCNT_DEBUG - atomic_inc(&llc_sock_nr); - printk(KERN_DEBUG "LLC socket %p created in %s, now we have %d alive\n", sk, - __func__, atomic_read(&llc_sock_nr)); -#endif -out: - return sk; -} - -void llc_sk_stop_all_timers(struct sock *sk, bool sync) -{ - struct llc_sock *llc = llc_sk(sk); - - if (sync) { - timer_delete_sync(&llc->pf_cycle_timer.timer); - timer_delete_sync(&llc->ack_timer.timer); - timer_delete_sync(&llc->rej_sent_timer.timer); - timer_delete_sync(&llc->busy_state_timer.timer); - } else { - timer_delete(&llc->pf_cycle_timer.timer); - timer_delete(&llc->ack_timer.timer); - timer_delete(&llc->rej_sent_timer.timer); - timer_delete(&llc->busy_state_timer.timer); - } - - llc->ack_must_be_send = 0; - llc->ack_pf = 0; -} - -/** - * llc_sk_free - Frees a LLC socket - * @sk: - socket to free - * - * Frees a LLC socket - */ -void llc_sk_free(struct sock *sk) -{ - struct llc_sock *llc = llc_sk(sk); - - llc->state = LLC_CONN_OUT_OF_SVC; - /* Stop all (possibly) running timers */ - llc_sk_stop_all_timers(sk, true); -#ifdef DEBUG_LLC_CONN_ALLOC - printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __func__, - skb_queue_len(&llc->pdu_unack_q), - skb_queue_len(&sk->sk_write_queue)); -#endif - skb_queue_purge(&sk->sk_receive_queue); - skb_queue_purge(&sk->sk_write_queue); - skb_queue_purge(&llc->pdu_unack_q); -#ifdef LLC_REFCNT_DEBUG - if (refcount_read(&sk->sk_refcnt) != 1) { - printk(KERN_DEBUG "Destruction of LLC sock %p delayed in %s, cnt=%d\n", - sk, __func__, refcount_read(&sk->sk_refcnt)); - printk(KERN_DEBUG "%d LLC sockets are still alive\n", - atomic_read(&llc_sock_nr)); - } else { - atomic_dec(&llc_sock_nr); - printk(KERN_DEBUG "LLC socket %p released in %s, %d are still alive\n", sk, - __func__, atomic_read(&llc_sock_nr)); - } -#endif - sock_put(sk); -} - -/** - * llc_sk_reset - resets a connection - * @sk: LLC socket to reset - * - * Resets a connection to the out of service state. Stops its timers - * and frees any frames in the queues of the connection. - */ -void llc_sk_reset(struct sock *sk) -{ - struct llc_sock *llc = llc_sk(sk); - - llc_conn_ac_stop_all_timers(sk, NULL); - skb_queue_purge(&sk->sk_write_queue); - skb_queue_purge(&llc->pdu_unack_q); - llc->remote_busy_flag = 0; - llc->cause_flag = 0; - llc->retry_count = 0; - llc_conn_set_p_flag(sk, 0); - llc->f_flag = 0; - llc->s_flag = 0; - llc->ack_pf = 0; - llc->first_pdu_Ns = 0; - llc->ack_must_be_send = 0; - llc->dec_step = 1; - llc->inc_cntr = 2; - llc->dec_cntr = 2; - llc->X = 0; - llc->failed_data_req = 0 ; - llc->last_nr = 0; -} diff --git a/net/llc/llc_if.c b/net/llc/llc_if.c deleted file mode 100644 index 1514362e613d..000000000000 --- a/net/llc/llc_if.c +++ /dev/null @@ -1,151 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_if.c - Defines LLC interface to upper layer - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * llc_build_and_send_pkt - Connection data sending for upper layers. - * @sk: connection - * @skb: packet to send - * - * This function is called when upper layer wants to send data using - * connection oriented communication mode. During sending data, connection - * will be locked and received frames and expired timers will be queued. - * Returns 0 for success, -ECONNABORTED when the connection already - * closed and -EBUSY when sending data is not permitted in this state or - * LLC has send an I pdu with p bit set to 1 and is waiting for it's - * response. - * - * This function always consumes a reference to the skb. - */ -int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb) -{ - struct llc_conn_state_ev *ev; - int rc = -ECONNABORTED; - struct llc_sock *llc = llc_sk(sk); - - if (unlikely(llc->state == LLC_CONN_STATE_ADM)) - goto out_free; - rc = -EBUSY; - if (unlikely(llc_data_accept_state(llc->state) || /* data_conn_refuse */ - llc->p_flag)) { - llc->failed_data_req = 1; - goto out_free; - } - ev = llc_conn_ev(skb); - ev->type = LLC_CONN_EV_TYPE_PRIM; - ev->prim = LLC_DATA_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - skb->dev = llc->dev; - return llc_conn_state_process(sk, skb); - -out_free: - kfree_skb(skb); - return rc; -} - -/** - * llc_establish_connection - Called by upper layer to establish a conn - * @sk: connection - * @lmac: local mac address - * @dmac: destination mac address - * @dsap: destination sap - * - * Upper layer calls this to establish an LLC connection with a remote - * machine. This function packages a proper event and sends it connection - * component state machine. Success or failure of connection - * establishment will inform to upper layer via calling it's confirm - * function and passing proper information. - */ -int llc_establish_connection(struct sock *sk, const u8 *lmac, u8 *dmac, u8 dsap) -{ - int rc = -EISCONN; - struct llc_addr laddr, daddr; - struct sk_buff *skb; - struct llc_sock *llc = llc_sk(sk); - struct sock *existing; - - laddr.lsap = llc->sap->laddr.lsap; - daddr.lsap = dsap; - memcpy(daddr.mac, dmac, sizeof(daddr.mac)); - memcpy(laddr.mac, lmac, sizeof(laddr.mac)); - existing = llc_lookup_established(llc->sap, &daddr, &laddr, sock_net(sk)); - if (existing) { - if (existing->sk_state == TCP_ESTABLISHED) { - sk = existing; - goto out_put; - } else - sock_put(existing); - } - sock_hold(sk); - rc = -ENOMEM; - skb = alloc_skb(0, GFP_ATOMIC); - if (skb) { - struct llc_conn_state_ev *ev = llc_conn_ev(skb); - - ev->type = LLC_CONN_EV_TYPE_PRIM; - ev->prim = LLC_CONN_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - skb_set_owner_w(skb, sk); - rc = llc_conn_state_process(sk, skb); - } -out_put: - sock_put(sk); - return rc; -} - -/** - * llc_send_disc - Called by upper layer to close a connection - * @sk: connection to be closed - * - * Upper layer calls this when it wants to close an established LLC - * connection with a remote machine. This function packages a proper event - * and sends it to connection component state machine. Returns 0 for - * success, 1 otherwise. - */ -int llc_send_disc(struct sock *sk) -{ - u16 rc = 1; - struct llc_conn_state_ev *ev; - struct sk_buff *skb; - - sock_hold(sk); - if (sk->sk_type != SOCK_STREAM || sk->sk_state != TCP_ESTABLISHED || - llc_sk(sk)->state == LLC_CONN_STATE_ADM || - llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) - goto out; - /* - * Postpone unassigning the connection from its SAP and returning the - * connection until all ACTIONs have been completely executed - */ - skb = alloc_skb(0, GFP_ATOMIC); - if (!skb) - goto out; - skb_set_owner_w(skb, sk); - sk->sk_state = TCP_CLOSING; - ev = llc_conn_ev(skb); - ev->type = LLC_CONN_EV_TYPE_PRIM; - ev->prim = LLC_DISC_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - rc = llc_conn_state_process(sk, skb); -out: - sock_put(sk); - return rc; -} diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c index 8eb3d73c39d1..78426ae7c73f 100644 --- a/net/llc/llc_input.c +++ b/net/llc/llc_input.c @@ -11,7 +11,6 @@ #include #include #include -#include #if 0 #define dprintk(args...) printk(KERN_DEBUG args) diff --git a/net/llc/llc_pdu.c b/net/llc/llc_pdu.c deleted file mode 100644 index c1938fa24a3f..000000000000 --- a/net/llc/llc_pdu.c +++ /dev/null @@ -1,366 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_pdu.c - access to PDU internals - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ - -#include -#include - -static void llc_pdu_decode_pdu_type(struct sk_buff *skb, u8 *type); -static u8 llc_pdu_get_pf_bit(struct llc_pdu_sn *pdu); - -void llc_pdu_set_cmd_rsp(struct sk_buff *skb, u8 pdu_type) -{ - llc_pdu_un_hdr(skb)->ssap |= pdu_type; -} - -/** - * llc_pdu_set_pf_bit - sets poll/final bit in LLC header - * @skb: Frame to set bit in - * @bit_value: poll/final bit (0 or 1). - * - * This function sets poll/final bit in LLC header (based on type of PDU). - * in I or S pdus, p/f bit is right bit of fourth byte in header. in U - * pdus p/f bit is fifth bit of third byte. - */ -void llc_pdu_set_pf_bit(struct sk_buff *skb, u8 bit_value) -{ - u8 pdu_type; - struct llc_pdu_sn *pdu; - - llc_pdu_decode_pdu_type(skb, &pdu_type); - pdu = llc_pdu_sn_hdr(skb); - - switch (pdu_type) { - case LLC_PDU_TYPE_I: - case LLC_PDU_TYPE_S: - pdu->ctrl_2 = (pdu->ctrl_2 & 0xFE) | bit_value; - break; - case LLC_PDU_TYPE_U: - pdu->ctrl_1 |= (pdu->ctrl_1 & 0xEF) | (bit_value << 4); - break; - } -} - -/** - * llc_pdu_decode_pf_bit - extracs poll/final bit from LLC header - * @skb: input skb that p/f bit must be extracted from it - * @pf_bit: poll/final bit (0 or 1) - * - * This function extracts poll/final bit from LLC header (based on type of - * PDU). In I or S pdus, p/f bit is right bit of fourth byte in header. In - * U pdus p/f bit is fifth bit of third byte. - */ -void llc_pdu_decode_pf_bit(struct sk_buff *skb, u8 *pf_bit) -{ - u8 pdu_type; - struct llc_pdu_sn *pdu; - - llc_pdu_decode_pdu_type(skb, &pdu_type); - pdu = llc_pdu_sn_hdr(skb); - - switch (pdu_type) { - case LLC_PDU_TYPE_I: - case LLC_PDU_TYPE_S: - *pf_bit = pdu->ctrl_2 & LLC_S_PF_BIT_MASK; - break; - case LLC_PDU_TYPE_U: - *pf_bit = (pdu->ctrl_1 & LLC_U_PF_BIT_MASK) >> 4; - break; - } -} - -/** - * llc_pdu_init_as_disc_cmd - Builds DISC PDU - * @skb: Address of the skb to build - * @p_bit: The P bit to set in the PDU - * - * Builds a pdu frame as a DISC command. - */ -void llc_pdu_init_as_disc_cmd(struct sk_buff *skb, u8 p_bit) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_2_PDU_CMD_DISC; - pdu->ctrl_1 |= ((p_bit & 1) << 4) & LLC_U_PF_BIT_MASK; -} - -/** - * llc_pdu_init_as_i_cmd - builds I pdu - * @skb: Address of the skb to build - * @p_bit: The P bit to set in the PDU - * @ns: The sequence number of the data PDU - * @nr: The seq. number of the expected I PDU from the remote - * - * Builds a pdu frame as an I command. - */ -void llc_pdu_init_as_i_cmd(struct sk_buff *skb, u8 p_bit, u8 ns, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_I; - pdu->ctrl_2 = 0; - pdu->ctrl_2 |= (p_bit & LLC_I_PF_BIT_MASK); /* p/f bit */ - pdu->ctrl_1 |= (ns << 1) & 0xFE; /* set N(S) in bits 2..8 */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_rej_cmd - builds REJ PDU - * @skb: Address of the skb to build - * @p_bit: The P bit to set in the PDU - * @nr: The seq. number of the expected I PDU from the remote - * - * Builds a pdu frame as a REJ command. - */ -void llc_pdu_init_as_rej_cmd(struct sk_buff *skb, u8 p_bit, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_S; - pdu->ctrl_1 |= LLC_2_PDU_CMD_REJ; - pdu->ctrl_2 = 0; - pdu->ctrl_2 |= p_bit & LLC_S_PF_BIT_MASK; - pdu->ctrl_1 &= 0x0F; /* setting bits 5..8 to zero(reserved) */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_rnr_cmd - builds RNR pdu - * @skb: Address of the skb to build - * @p_bit: The P bit to set in the PDU - * @nr: The seq. number of the expected I PDU from the remote - * - * Builds a pdu frame as an RNR command. - */ -void llc_pdu_init_as_rnr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_S; - pdu->ctrl_1 |= LLC_2_PDU_CMD_RNR; - pdu->ctrl_2 = 0; - pdu->ctrl_2 |= p_bit & LLC_S_PF_BIT_MASK; - pdu->ctrl_1 &= 0x0F; /* setting bits 5..8 to zero(reserved) */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_rr_cmd - Builds RR pdu - * @skb: Address of the skb to build - * @p_bit: The P bit to set in the PDU - * @nr: The seq. number of the expected I PDU from the remote - * - * Builds a pdu frame as an RR command. - */ -void llc_pdu_init_as_rr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_S; - pdu->ctrl_1 |= LLC_2_PDU_CMD_RR; - pdu->ctrl_2 = p_bit & LLC_S_PF_BIT_MASK; - pdu->ctrl_1 &= 0x0F; /* setting bits 5..8 to zero(reserved) */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_sabme_cmd - builds SABME pdu - * @skb: Address of the skb to build - * @p_bit: The P bit to set in the PDU - * - * Builds a pdu frame as an SABME command. - */ -void llc_pdu_init_as_sabme_cmd(struct sk_buff *skb, u8 p_bit) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_2_PDU_CMD_SABME; - pdu->ctrl_1 |= ((p_bit & 1) << 4) & LLC_U_PF_BIT_MASK; -} - -/** - * llc_pdu_init_as_dm_rsp - builds DM response pdu - * @skb: Address of the skb to build - * @f_bit: The F bit to set in the PDU - * - * Builds a pdu frame as a DM response. - */ -void llc_pdu_init_as_dm_rsp(struct sk_buff *skb, u8 f_bit) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_2_PDU_RSP_DM; - pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK; -} - -/** - * llc_pdu_init_as_frmr_rsp - builds FRMR response PDU - * @skb: Address of the frame to build - * @prev_pdu: The rejected PDU frame - * @f_bit: The F bit to set in the PDU - * @vs: tx state vari value for the data link conn at the rejecting LLC - * @vr: rx state var value for the data link conn at the rejecting LLC - * @vzyxw: completely described in the IEEE Std 802.2 document (Pg 55) - * - * Builds a pdu frame as a FRMR response. - */ -void llc_pdu_init_as_frmr_rsp(struct sk_buff *skb, struct llc_pdu_sn *prev_pdu, - u8 f_bit, u8 vs, u8 vr, u8 vzyxw) -{ - struct llc_frmr_info *frmr_info; - u8 prev_pf = 0; - u8 *ctrl; - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_2_PDU_RSP_FRMR; - pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK; - - frmr_info = (struct llc_frmr_info *)&pdu->ctrl_2; - ctrl = (u8 *)&prev_pdu->ctrl_1; - FRMR_INFO_SET_REJ_CNTRL(frmr_info,ctrl); - FRMR_INFO_SET_Vs(frmr_info, vs); - FRMR_INFO_SET_Vr(frmr_info, vr); - prev_pf = llc_pdu_get_pf_bit(prev_pdu); - FRMR_INFO_SET_C_R_BIT(frmr_info, prev_pf); - FRMR_INFO_SET_INVALID_PDU_CTRL_IND(frmr_info, vzyxw); - FRMR_INFO_SET_INVALID_PDU_INFO_IND(frmr_info, vzyxw); - FRMR_INFO_SET_PDU_INFO_2LONG_IND(frmr_info, vzyxw); - FRMR_INFO_SET_PDU_INVALID_Nr_IND(frmr_info, vzyxw); - FRMR_INFO_SET_PDU_INVALID_Ns_IND(frmr_info, vzyxw); - skb_put(skb, sizeof(struct llc_frmr_info)); -} - -/** - * llc_pdu_init_as_rr_rsp - builds RR response pdu - * @skb: Address of the skb to build - * @f_bit: The F bit to set in the PDU - * @nr: The seq. number of the expected data PDU from the remote - * - * Builds a pdu frame as an RR response. - */ -void llc_pdu_init_as_rr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_S; - pdu->ctrl_1 |= LLC_2_PDU_RSP_RR; - pdu->ctrl_2 = 0; - pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK; - pdu->ctrl_1 &= 0x0F; /* setting bits 5..8 to zero(reserved) */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_rej_rsp - builds REJ response pdu - * @skb: Address of the skb to build - * @f_bit: The F bit to set in the PDU - * @nr: The seq. number of the expected data PDU from the remote - * - * Builds a pdu frame as a REJ response. - */ -void llc_pdu_init_as_rej_rsp(struct sk_buff *skb, u8 f_bit, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_S; - pdu->ctrl_1 |= LLC_2_PDU_RSP_REJ; - pdu->ctrl_2 = 0; - pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK; - pdu->ctrl_1 &= 0x0F; /* setting bits 5..8 to zero(reserved) */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_rnr_rsp - builds RNR response pdu - * @skb: Address of the frame to build - * @f_bit: The F bit to set in the PDU - * @nr: The seq. number of the expected data PDU from the remote - * - * Builds a pdu frame as an RNR response. - */ -void llc_pdu_init_as_rnr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr) -{ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_S; - pdu->ctrl_1 |= LLC_2_PDU_RSP_RNR; - pdu->ctrl_2 = 0; - pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK; - pdu->ctrl_1 &= 0x0F; /* setting bits 5..8 to zero(reserved) */ - pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */ -} - -/** - * llc_pdu_init_as_ua_rsp - builds UA response pdu - * @skb: Address of the frame to build - * @f_bit: The F bit to set in the PDU - * - * Builds a pdu frame as a UA response. - */ -void llc_pdu_init_as_ua_rsp(struct sk_buff *skb, u8 f_bit) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_2_PDU_RSP_UA; - pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK; -} - -/** - * llc_pdu_decode_pdu_type - designates PDU type - * @skb: input skb that type of it must be designated. - * @type: type of PDU (output argument). - * - * This function designates type of PDU (I, S or U). - */ -static void llc_pdu_decode_pdu_type(struct sk_buff *skb, u8 *type) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - if (pdu->ctrl_1 & 1) { - if ((pdu->ctrl_1 & LLC_PDU_TYPE_U) == LLC_PDU_TYPE_U) - *type = LLC_PDU_TYPE_U; - else - *type = LLC_PDU_TYPE_S; - } else - *type = LLC_PDU_TYPE_I; -} - -/** - * llc_pdu_get_pf_bit - extracts p/f bit of input PDU - * @pdu: pointer to LLC header. - * - * This function extracts p/f bit of input PDU. at first examines type of - * PDU and then extracts p/f bit. Returns the p/f bit. - */ -static u8 llc_pdu_get_pf_bit(struct llc_pdu_sn *pdu) -{ - u8 pdu_type; - u8 pf_bit = 0; - - if (pdu->ctrl_1 & 1) { - if ((pdu->ctrl_1 & LLC_PDU_TYPE_U) == LLC_PDU_TYPE_U) - pdu_type = LLC_PDU_TYPE_U; - else - pdu_type = LLC_PDU_TYPE_S; - } else - pdu_type = LLC_PDU_TYPE_I; - switch (pdu_type) { - case LLC_PDU_TYPE_I: - case LLC_PDU_TYPE_S: - pf_bit = pdu->ctrl_2 & LLC_S_PF_BIT_MASK; - break; - case LLC_PDU_TYPE_U: - pf_bit = (pdu->ctrl_1 & LLC_U_PF_BIT_MASK) >> 4; - break; - } - return pf_bit; -} diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c deleted file mode 100644 index 4804a08c2490..000000000000 --- a/net/llc/llc_proc.c +++ /dev/null @@ -1,245 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * proc_llc.c - proc interface for LLC - * - * Copyright (c) 2001 by Jay Schulist - * 2002-2003 by Arnaldo Carvalho de Melo - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void llc_ui_format_mac(struct seq_file *seq, const u8 *addr) -{ - seq_printf(seq, "%pM", addr); -} - -static struct sock *llc_get_sk_idx(loff_t pos) -{ - struct llc_sap *sap; - struct sock *sk = NULL; - int i; - - list_for_each_entry_rcu(sap, &llc_sap_list, node) { - spin_lock_bh(&sap->sk_lock); - for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) { - struct hlist_nulls_head *head = &sap->sk_laddr_hash[i]; - struct hlist_nulls_node *node; - - sk_nulls_for_each(sk, node, head) { - if (!pos) - goto found; /* keep the lock */ - --pos; - } - } - spin_unlock_bh(&sap->sk_lock); - } - sk = NULL; -found: - return sk; -} - -static void *llc_seq_start(struct seq_file *seq, loff_t *pos) __acquires(RCU) -{ - loff_t l = *pos; - - rcu_read_lock_bh(); - return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN; -} - -static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket) -{ - struct hlist_nulls_node *node; - struct sock *sk = NULL; - - while (++bucket < LLC_SK_LADDR_HASH_ENTRIES) - sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket]) - goto out; - -out: - return sk; -} - -static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos) -{ - struct sock* sk, *next; - struct llc_sock *llc; - struct llc_sap *sap; - - ++*pos; - if (v == SEQ_START_TOKEN) { - sk = llc_get_sk_idx(0); - goto out; - } - sk = v; - next = sk_nulls_next(sk); - if (next) { - sk = next; - goto out; - } - llc = llc_sk(sk); - sap = llc->sap; - sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr)); - if (sk) - goto out; - spin_unlock_bh(&sap->sk_lock); - list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) { - spin_lock_bh(&sap->sk_lock); - sk = laddr_hash_next(sap, -1); - if (sk) - break; /* keep the lock */ - spin_unlock_bh(&sap->sk_lock); - } -out: - return sk; -} - -static void llc_seq_stop(struct seq_file *seq, void *v) -{ - if (v && v != SEQ_START_TOKEN) { - struct sock *sk = v; - struct llc_sock *llc = llc_sk(sk); - struct llc_sap *sap = llc->sap; - - spin_unlock_bh(&sap->sk_lock); - } - rcu_read_unlock_bh(); -} - -static int llc_seq_socket_show(struct seq_file *seq, void *v) -{ - struct sock* sk; - struct llc_sock *llc; - - if (v == SEQ_START_TOKEN) { - seq_puts(seq, "SKt Mc local_mac_sap remote_mac_sap " - " tx_queue rx_queue st uid link\n"); - goto out; - } - sk = v; - llc = llc_sk(sk); - - /* FIXME: check if the address is multicast */ - seq_printf(seq, "%2X %2X ", sk->sk_type, 0); - - if (llc->dev) - llc_ui_format_mac(seq, llc->dev->dev_addr); - else { - u8 addr[6] = {0,0,0,0,0,0}; - llc_ui_format_mac(seq, addr); - } - seq_printf(seq, "@%02X ", llc->sap->laddr.lsap); - llc_ui_format_mac(seq, llc->daddr.mac); - seq_printf(seq, "@%02X %8d %8d %2d %3u %4d\n", llc->daddr.lsap, - sk_wmem_alloc_get(sk), - sk_rmem_alloc_get(sk) - llc->copied_seq, - sk->sk_state, - from_kuid_munged(seq_user_ns(seq), sk_uid(sk)), - llc->link); -out: - return 0; -} - -static const char *const llc_conn_state_names[] = { - [LLC_CONN_STATE_ADM] = "adm", - [LLC_CONN_STATE_SETUP] = "setup", - [LLC_CONN_STATE_NORMAL] = "normal", - [LLC_CONN_STATE_BUSY] = "busy", - [LLC_CONN_STATE_REJ] = "rej", - [LLC_CONN_STATE_AWAIT] = "await", - [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy", - [LLC_CONN_STATE_AWAIT_REJ] = "await_rej", - [LLC_CONN_STATE_D_CONN] = "d_conn", - [LLC_CONN_STATE_RESET] = "reset", - [LLC_CONN_STATE_ERROR] = "error", - [LLC_CONN_STATE_TEMP] = "temp", -}; - -static int llc_seq_core_show(struct seq_file *seq, void *v) -{ - struct sock* sk; - struct llc_sock *llc; - - if (v == SEQ_START_TOKEN) { - seq_puts(seq, "Connection list:\n" - "dsap state retr txw rxw pf ff sf df rs cs " - "tack tpfc trs tbs blog busr\n"); - goto out; - } - sk = v; - llc = llc_sk(sk); - - seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d " - "%4d %4d %3d %3d %4d %4d\n", - llc->daddr.lsap, llc_conn_state_names[llc->state], - llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag, - llc->s_flag, llc->data_flag, llc->remote_busy_flag, - llc->cause_flag, timer_pending(&llc->ack_timer.timer), - timer_pending(&llc->pf_cycle_timer.timer), - timer_pending(&llc->rej_sent_timer.timer), - timer_pending(&llc->busy_state_timer.timer), - !!sk->sk_backlog.tail, sock_owned_by_user_nocheck(sk)); -out: - return 0; -} - -static const struct seq_operations llc_seq_socket_ops = { - .start = llc_seq_start, - .next = llc_seq_next, - .stop = llc_seq_stop, - .show = llc_seq_socket_show, -}; - -static const struct seq_operations llc_seq_core_ops = { - .start = llc_seq_start, - .next = llc_seq_next, - .stop = llc_seq_stop, - .show = llc_seq_core_show, -}; - -static struct proc_dir_entry *llc_proc_dir; - -int __init llc_proc_init(void) -{ - int rc = -ENOMEM; - struct proc_dir_entry *p; - - llc_proc_dir = proc_mkdir("llc", init_net.proc_net); - if (!llc_proc_dir) - goto out; - - p = proc_create_seq("socket", 0444, llc_proc_dir, &llc_seq_socket_ops); - if (!p) - goto out_socket; - - p = proc_create_seq("core", 0444, llc_proc_dir, &llc_seq_core_ops); - if (!p) - goto out_core; - - rc = 0; -out: - return rc; -out_core: - remove_proc_entry("socket", llc_proc_dir); -out_socket: - remove_proc_entry("llc", init_net.proc_net); - goto out; -} - -void llc_proc_exit(void) -{ - remove_proc_entry("socket", llc_proc_dir); - remove_proc_entry("core", llc_proc_dir); - remove_proc_entry("llc", init_net.proc_net); -} diff --git a/net/llc/llc_s_ac.c b/net/llc/llc_s_ac.c deleted file mode 100644 index 831998211b52..000000000000 --- a/net/llc/llc_s_ac.c +++ /dev/null @@ -1,220 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_s_ac.c - actions performed during sap state transition. - * - * Description : - * Functions in this module are implementation of sap component actions. - * Details of actions can be found in IEEE-802.2 standard document. - * All functions have one sap and one event as input argument. All of - * them return 0 On success and 1 otherwise. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ - -#include -#include -#include -#include -#include -#include -#include - -/** - * llc_sap_action_unitdata_ind - forward UI PDU to network layer - * @sap: SAP - * @skb: the event to forward - * - * Received a UI PDU from MAC layer; forward to network layer as a - * UNITDATA INDICATION; verify our event is the kind we expect - */ -int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb) -{ - llc_sap_rtn_pdu(sap, skb); - return 0; -} - -static int llc_prepare_and_xmit(struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct sk_buff *nskb; - int rc; - - rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); - if (rc) - return rc; - - nskb = skb_clone(skb, GFP_ATOMIC); - if (!nskb) - return -ENOMEM; - - if (skb->sk) - skb_set_owner_w(nskb, skb->sk); - - return dev_queue_xmit(nskb); -} - -/** - * llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer - * @sap: SAP - * @skb: the event to send - * - * Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST - * primitive from the network layer. Verifies event is a primitive type of - * event. Verify the primitive is a UNITDATA REQUEST. - */ -int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap, - ev->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_ui_cmd(skb); - - return llc_prepare_and_xmit(skb); -} - -/** - * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ - * @sap: SAP - * @skb: the event to send - * - * Send a XID command PDU to MAC layer in response to a XID REQUEST - * primitive from the network layer. Verify event is a primitive type - * event. Verify the primitive is a XID REQUEST. - */ -int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - llc_pdu_header_init(skb, LLC_PDU_TYPE_U_XID, ev->saddr.lsap, - ev->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0); - - return llc_prepare_and_xmit(skb); -} - -/** - * llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID - * @sap: SAP - * @skb: the event to send - * - * Send XID response PDU to MAC in response to an earlier received XID - * command PDU. Verify event is a PDU type event - */ -int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb) -{ - u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap; - int rc = 1; - struct sk_buff *nskb; - - llc_pdu_decode_sa(skb, mac_da); - llc_pdu_decode_da(skb, mac_sa); - llc_pdu_decode_ssap(skb, &dsap); - nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, - sizeof(struct llc_xid_info)); - if (!nskb) - goto out; - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap, - LLC_PDU_RSP); - llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0); - rc = llc_mac_hdr_init(nskb, mac_sa, mac_da); - if (likely(!rc)) - rc = dev_queue_xmit(nskb); - else - kfree_skb(nskb); -out: - return rc; -} - -/** - * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ - * @sap: SAP - * @skb: the event to send - * - * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST - * primitive from the network layer. Verify event is a primitive type - * event; verify the primitive is a TEST REQUEST. - */ -int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap, - ev->daddr.lsap, LLC_PDU_CMD); - llc_pdu_init_as_test_cmd(skb); - - return llc_prepare_and_xmit(skb); -} - -int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb) -{ - u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap; - struct sk_buff *nskb; - int rc = 1; - u32 data_size; - - if (skb->mac_len < ETH_HLEN) - return 1; - - llc_pdu_decode_sa(skb, mac_da); - llc_pdu_decode_da(skb, mac_sa); - llc_pdu_decode_ssap(skb, &dsap); - - /* The test request command is type U (llc_len = 3) */ - data_size = ntohs(eth_hdr(skb)->h_proto) - 3; - nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size); - if (!nskb) - goto out; - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap, - LLC_PDU_RSP); - llc_pdu_init_as_test_rsp(nskb, skb); - rc = llc_mac_hdr_init(nskb, mac_sa, mac_da); - if (likely(!rc)) - rc = dev_queue_xmit(nskb); - else - kfree_skb(nskb); -out: - return rc; -} - -/** - * llc_sap_action_report_status - report data link status to layer mgmt - * @sap: SAP - * @skb: the event to send - * - * Report data link status to layer management. Verify our event is the - * kind we expect. - */ -int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb) -{ - return 0; -} - -/** - * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND - * @sap: SAP - * @skb: the event to send - * - * Send a XID response PDU to the network layer via a XID INDICATION - * primitive. - */ -int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb) -{ - llc_sap_rtn_pdu(sap, skb); - return 0; -} - -/** - * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND - * @sap: SAP - * @skb: the event to send - * - * Send a TEST response PDU to the network layer via a TEST INDICATION - * primitive. Verify our event is a PDU type event. - */ -int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb) -{ - llc_sap_rtn_pdu(sap, skb); - return 0; -} diff --git a/net/llc/llc_s_ev.c b/net/llc/llc_s_ev.c deleted file mode 100644 index cfbecba589e7..000000000000 --- a/net/llc/llc_s_ev.c +++ /dev/null @@ -1,109 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_s_ev.c - Defines SAP component events - * - * The followed event functions are SAP component events which are described - * in 802.2 LLC protocol standard document. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include - -int llc_sap_ev_activation_req(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - return ev->type == LLC_SAP_EV_TYPE_SIMPLE && - ev->prim_type == LLC_SAP_EV_ACTIVATION_REQ ? 0 : 1; -} - -int llc_sap_ev_rx_ui(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_CMD(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_UI ? 0 : 1; -} - -int llc_sap_ev_unitdata_req(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - return ev->type == LLC_SAP_EV_TYPE_PRIM && - ev->prim == LLC_DATAUNIT_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; - -} - -int llc_sap_ev_xid_req(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - return ev->type == LLC_SAP_EV_TYPE_PRIM && - ev->prim == LLC_XID_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; -} - -int llc_sap_ev_rx_xid_c(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_CMD(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID ? 0 : 1; -} - -int llc_sap_ev_rx_xid_r(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_RSP(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_XID ? 0 : 1; -} - -int llc_sap_ev_test_req(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - return ev->type == LLC_SAP_EV_TYPE_PRIM && - ev->prim == LLC_TEST_PRIM && - ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; -} - -int llc_sap_ev_rx_test_c(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_CMD(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST ? 0 : 1; -} - -int llc_sap_ev_rx_test_r(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_RSP(pdu) && - LLC_PDU_TYPE_IS_U(pdu) && - LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_TEST ? 0 : 1; -} - -int llc_sap_ev_deactivation_req(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - return ev->type == LLC_SAP_EV_TYPE_SIMPLE && - ev->prim_type == LLC_SAP_EV_DEACTIVATION_REQ ? 0 : 1; -} diff --git a/net/llc/llc_s_st.c b/net/llc/llc_s_st.c deleted file mode 100644 index e14d4f520327..000000000000 --- a/net/llc/llc_s_st.c +++ /dev/null @@ -1,177 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_s_st.c - Defines SAP component state machine transitions. - * - * The followed transitions are SAP component state machine transitions - * which are described in 802.2 LLC protocol standard document. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include - -/* dummy last-transition indicator; common to all state transition groups - * last entry for this state - * all members are zeros, .bss zeroes it - */ -static const struct llc_sap_state_trans llc_sap_state_trans_end; - -/* state LLC_SAP_STATE_INACTIVE transition for - * LLC_SAP_EV_ACTIVATION_REQ event - */ -static const llc_sap_action_t llc_sap_inactive_state_actions_1[] = { - [0] = llc_sap_action_report_status, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_inactive_state_trans_1 = { - .ev = llc_sap_ev_activation_req, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_inactive_state_actions_1, -}; - -/* array of pointers; one to each transition */ -static const struct llc_sap_state_trans *llc_sap_inactive_state_transitions[] = { - [0] = &llc_sap_inactive_state_trans_1, - [1] = &llc_sap_state_trans_end, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_RX_UI event */ -static const llc_sap_action_t llc_sap_active_state_actions_1[] = { - [0] = llc_sap_action_unitdata_ind, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_1 = { - .ev = llc_sap_ev_rx_ui, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_1, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_UNITDATA_REQ event */ -static const llc_sap_action_t llc_sap_active_state_actions_2[] = { - [0] = llc_sap_action_send_ui, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_2 = { - .ev = llc_sap_ev_unitdata_req, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_2, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_XID_REQ event */ -static const llc_sap_action_t llc_sap_active_state_actions_3[] = { - [0] = llc_sap_action_send_xid_c, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_3 = { - .ev = llc_sap_ev_xid_req, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_3, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_RX_XID_C event */ -static const llc_sap_action_t llc_sap_active_state_actions_4[] = { - [0] = llc_sap_action_send_xid_r, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_4 = { - .ev = llc_sap_ev_rx_xid_c, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_4, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_RX_XID_R event */ -static const llc_sap_action_t llc_sap_active_state_actions_5[] = { - [0] = llc_sap_action_xid_ind, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_5 = { - .ev = llc_sap_ev_rx_xid_r, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_5, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_TEST_REQ event */ -static const llc_sap_action_t llc_sap_active_state_actions_6[] = { - [0] = llc_sap_action_send_test_c, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_6 = { - .ev = llc_sap_ev_test_req, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_6, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_RX_TEST_C event */ -static const llc_sap_action_t llc_sap_active_state_actions_7[] = { - [0] = llc_sap_action_send_test_r, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_7 = { - .ev = llc_sap_ev_rx_test_c, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_7 -}; - -/* state LLC_SAP_STATE_ACTIVE transition for LLC_SAP_EV_RX_TEST_R event */ -static const llc_sap_action_t llc_sap_active_state_actions_8[] = { - [0] = llc_sap_action_test_ind, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_8 = { - .ev = llc_sap_ev_rx_test_r, - .next_state = LLC_SAP_STATE_ACTIVE, - .ev_actions = llc_sap_active_state_actions_8, -}; - -/* state LLC_SAP_STATE_ACTIVE transition for - * LLC_SAP_EV_DEACTIVATION_REQ event - */ -static const llc_sap_action_t llc_sap_active_state_actions_9[] = { - [0] = llc_sap_action_report_status, - [1] = NULL, -}; - -static const struct llc_sap_state_trans llc_sap_active_state_trans_9 = { - .ev = llc_sap_ev_deactivation_req, - .next_state = LLC_SAP_STATE_INACTIVE, - .ev_actions = llc_sap_active_state_actions_9 -}; - -/* array of pointers; one to each transition */ -static const struct llc_sap_state_trans *llc_sap_active_state_transitions[] = { - [0] = &llc_sap_active_state_trans_2, - [1] = &llc_sap_active_state_trans_1, - [2] = &llc_sap_active_state_trans_3, - [3] = &llc_sap_active_state_trans_4, - [4] = &llc_sap_active_state_trans_5, - [5] = &llc_sap_active_state_trans_6, - [6] = &llc_sap_active_state_trans_7, - [7] = &llc_sap_active_state_trans_8, - [8] = &llc_sap_active_state_trans_9, - [9] = &llc_sap_state_trans_end, -}; - -/* SAP state transition table */ -struct llc_sap_state llc_sap_state_table[LLC_NR_SAP_STATES] = { - [LLC_SAP_STATE_INACTIVE - 1] = { - .curr_state = LLC_SAP_STATE_INACTIVE, - .transitions = llc_sap_inactive_state_transitions, - }, - [LLC_SAP_STATE_ACTIVE - 1] = { - .curr_state = LLC_SAP_STATE_ACTIVE, - .transitions = llc_sap_active_state_transitions, - }, -}; diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c deleted file mode 100644 index 3904a1b4ba84..000000000000 --- a/net/llc/llc_sap.c +++ /dev/null @@ -1,437 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_sap.c - driver routines for SAP component. - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int llc_mac_header_len(struct net_device *dev) -{ - switch (dev->type) { - case ARPHRD_ETHER: - case ARPHRD_LOOPBACK: - return LL_RESERVED_SPACE(dev); - } - return 0; -} - -/** - * llc_alloc_frame - allocates sk_buff for frame - * @sk: socket to allocate frame to - * @dev: network device this skb will be sent over - * @type: pdu type to allocate - * @data_size: data size to allocate - * - * Allocates an sk_buff for frame and initializes sk_buff fields. - * Returns allocated skb or %NULL when out of memory. - */ -struct sk_buff *llc_alloc_frame(struct sock *sk, struct net_device *dev, - u8 type, u32 data_size) -{ - int hlen = type == LLC_PDU_TYPE_U ? 3 : 4; - struct sk_buff *skb; - - hlen += llc_mac_header_len(dev); - skb = alloc_skb(hlen + data_size, GFP_ATOMIC); - - if (skb) { - skb_reset_mac_header(skb); - skb_reserve(skb, hlen); - skb_reset_network_header(skb); - skb_reset_transport_header(skb); - skb->protocol = htons(ETH_P_802_2); - skb->dev = dev; - if (sk != NULL) - skb_set_owner_w(skb, sk); - } - return skb; -} - -void llc_save_primitive(struct sock *sk, struct sk_buff *skb, u8 prim) -{ - struct sockaddr_llc *addr; - - /* save primitive for use by the user. */ - addr = llc_ui_skb_cb(skb); - - memset(addr, 0, sizeof(*addr)); - addr->sllc_family = sk->sk_family; - addr->sllc_arphrd = skb->dev->type; - addr->sllc_test = prim == LLC_TEST_PRIM; - addr->sllc_xid = prim == LLC_XID_PRIM; - addr->sllc_ua = prim == LLC_DATAUNIT_PRIM; - llc_pdu_decode_sa(skb, addr->sllc_mac); - llc_pdu_decode_ssap(skb, &addr->sllc_sap); -} - -/** - * llc_sap_rtn_pdu - Informs upper layer on rx of an UI, XID or TEST pdu. - * @sap: pointer to SAP - * @skb: received pdu - */ -void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - switch (LLC_U_PDU_RSP(pdu)) { - case LLC_1_PDU_CMD_TEST: - ev->prim = LLC_TEST_PRIM; break; - case LLC_1_PDU_CMD_XID: - ev->prim = LLC_XID_PRIM; break; - case LLC_1_PDU_CMD_UI: - ev->prim = LLC_DATAUNIT_PRIM; break; - } - ev->ind_cfm_flag = LLC_IND; -} - -/** - * llc_find_sap_trans - finds transition for event - * @sap: pointer to SAP - * @skb: happened event - * - * This function finds transition that matches with happened event. - * Returns the pointer to found transition on success or %NULL for - * failure. - */ -static const struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap, - struct sk_buff *skb) -{ - int i = 0; - const struct llc_sap_state_trans *rc = NULL; - const struct llc_sap_state_trans **next_trans; - struct llc_sap_state *curr_state = &llc_sap_state_table[sap->state - 1]; - /* - * Search thru events for this state until list exhausted or until - * its obvious the event is not valid for the current state - */ - for (next_trans = curr_state->transitions; next_trans[i]->ev; i++) - if (!next_trans[i]->ev(sap, skb)) { - rc = next_trans[i]; /* got event match; return it */ - break; - } - return rc; -} - -/** - * llc_exec_sap_trans_actions - execute actions related to event - * @sap: pointer to SAP - * @trans: pointer to transition that it's actions must be performed - * @skb: happened event. - * - * This function executes actions that is related to happened event. - * Returns 0 for success and 1 for failure of at least one action. - */ -static int llc_exec_sap_trans_actions(struct llc_sap *sap, - const struct llc_sap_state_trans *trans, - struct sk_buff *skb) -{ - int rc = 0; - const llc_sap_action_t *next_action = trans->ev_actions; - - for (; next_action && *next_action; next_action++) - if ((*next_action)(sap, skb)) - rc = 1; - return rc; -} - -/** - * llc_sap_next_state - finds transition, execs actions & change SAP state - * @sap: pointer to SAP - * @skb: happened event - * - * This function finds transition that matches with happened event, then - * executes related actions and finally changes state of SAP. It returns - * 0 on success and 1 for failure. - */ -static int llc_sap_next_state(struct llc_sap *sap, struct sk_buff *skb) -{ - const struct llc_sap_state_trans *trans; - int rc = 1; - - if (sap->state > LLC_NR_SAP_STATES) - goto out; - trans = llc_find_sap_trans(sap, skb); - if (!trans) - goto out; - /* - * Got the state to which we next transition; perform the actions - * associated with this transition before actually transitioning to the - * next state - */ - rc = llc_exec_sap_trans_actions(sap, trans, skb); - if (rc) - goto out; - /* - * Transition SAP to next state if all actions execute successfully - */ - sap->state = trans->next_state; -out: - return rc; -} - -/** - * llc_sap_state_process - sends event to SAP state machine - * @sap: sap to use - * @skb: pointer to occurred event - * - * After executing actions of the event, upper layer will be indicated - * if needed(on receiving an UI frame). sk can be null for the - * datalink_proto case. - * - * This function always consumes a reference to the skb. - */ -static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - ev->ind_cfm_flag = 0; - llc_sap_next_state(sap, skb); - - if (ev->ind_cfm_flag == LLC_IND && skb->sk->sk_state != TCP_LISTEN) { - llc_save_primitive(skb->sk, skb, ev->prim); - - /* queue skb to the user. */ - if (sock_queue_rcv_skb(skb->sk, skb) == 0) - return; - } - kfree_skb(skb); -} - -/** - * llc_build_and_send_test_pkt - TEST interface for upper layers. - * @sap: sap to use - * @skb: packet to send - * @dmac: destination mac address - * @dsap: destination sap - * - * This function is called when upper layer wants to send a TEST pdu. - * Returns 0 for success, 1 otherwise. - */ -void llc_build_and_send_test_pkt(struct llc_sap *sap, - struct sk_buff *skb, u8 *dmac, u8 dsap) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - ev->saddr.lsap = sap->laddr.lsap; - ev->daddr.lsap = dsap; - memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN); - memcpy(ev->daddr.mac, dmac, IFHWADDRLEN); - - ev->type = LLC_SAP_EV_TYPE_PRIM; - ev->prim = LLC_TEST_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - llc_sap_state_process(sap, skb); -} - -/** - * llc_build_and_send_xid_pkt - XID interface for upper layers - * @sap: sap to use - * @skb: packet to send - * @dmac: destination mac address - * @dsap: destination sap - * - * This function is called when upper layer wants to send a XID pdu. - * Returns 0 for success, 1 otherwise. - */ -void llc_build_and_send_xid_pkt(struct llc_sap *sap, struct sk_buff *skb, - u8 *dmac, u8 dsap) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - ev->saddr.lsap = sap->laddr.lsap; - ev->daddr.lsap = dsap; - memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN); - memcpy(ev->daddr.mac, dmac, IFHWADDRLEN); - - ev->type = LLC_SAP_EV_TYPE_PRIM; - ev->prim = LLC_XID_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - llc_sap_state_process(sap, skb); -} - -/** - * llc_sap_rcv - sends received pdus to the sap state machine - * @sap: current sap component structure. - * @skb: received frame. - * @sk: socket to associate to frame - * - * Sends received pdus to the sap state machine. - */ -static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb, - struct sock *sk) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - ev->type = LLC_SAP_EV_TYPE_PDU; - ev->reason = 0; - skb_orphan(skb); - sock_hold(sk); - skb->sk = sk; - skb->destructor = sock_efree; - llc_sap_state_process(sap, skb); -} - -static inline bool llc_dgram_match(const struct llc_sap *sap, - const struct llc_addr *laddr, - const struct sock *sk, - const struct net *net) -{ - struct llc_sock *llc = llc_sk(sk); - - return sk->sk_type == SOCK_DGRAM && - net_eq(sock_net(sk), net) && - llc->laddr.lsap == laddr->lsap && - ether_addr_equal(llc->laddr.mac, laddr->mac); -} - -/** - * llc_lookup_dgram - Finds dgram socket for the local sap/mac - * @sap: SAP - * @laddr: address of local LLC (MAC + SAP) - * @net: netns to look up a socket in - * - * Search socket list of the SAP and finds connection using the local - * mac, and local sap. Returns pointer for socket found, %NULL otherwise. - */ -static struct sock *llc_lookup_dgram(struct llc_sap *sap, - const struct llc_addr *laddr, - const struct net *net) -{ - struct sock *rc; - struct hlist_nulls_node *node; - int slot = llc_sk_laddr_hashfn(sap, laddr); - struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot]; - - rcu_read_lock_bh(); -again: - sk_nulls_for_each_rcu(rc, node, laddr_hb) { - if (llc_dgram_match(sap, laddr, rc, net)) { - /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ - if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt))) - goto again; - if (unlikely(llc_sk(rc)->sap != sap || - !llc_dgram_match(sap, laddr, rc, net))) { - sock_put(rc); - continue; - } - goto found; - } - } - rc = NULL; - /* - * if the nulls value we got at the end of this lookup is - * not the expected one, we must restart lookup. - * We probably met an item that was moved to another chain. - */ - if (unlikely(get_nulls_value(node) != slot)) - goto again; -found: - rcu_read_unlock_bh(); - return rc; -} - -static inline bool llc_mcast_match(const struct llc_sap *sap, - const struct llc_addr *laddr, - const struct sk_buff *skb, - const struct sock *sk) -{ - struct llc_sock *llc = llc_sk(sk); - - return sk->sk_type == SOCK_DGRAM && - llc->laddr.lsap == laddr->lsap && - llc->dev == skb->dev; -} - -static void llc_do_mcast(struct llc_sap *sap, struct sk_buff *skb, - struct sock **stack, int count) -{ - struct sk_buff *skb1; - int i; - - for (i = 0; i < count; i++) { - skb1 = skb_clone(skb, GFP_ATOMIC); - if (!skb1) { - sock_put(stack[i]); - continue; - } - - llc_sap_rcv(sap, skb1, stack[i]); - sock_put(stack[i]); - } -} - -/** - * llc_sap_mcast - Deliver multicast PDU's to all matching datagram sockets. - * @sap: SAP - * @laddr: address of local LLC (MAC + SAP) - * @skb: PDU to deliver - * - * Search socket list of the SAP and finds connections with same sap. - * Deliver clone to each. - */ -static void llc_sap_mcast(struct llc_sap *sap, - const struct llc_addr *laddr, - struct sk_buff *skb) -{ - int i = 0; - struct sock *sk; - struct sock *stack[256 / sizeof(struct sock *)]; - struct llc_sock *llc; - struct hlist_head *dev_hb = llc_sk_dev_hash(sap, skb->dev->ifindex); - - spin_lock_bh(&sap->sk_lock); - hlist_for_each_entry(llc, dev_hb, dev_hash_node) { - - sk = &llc->sk; - - if (!llc_mcast_match(sap, laddr, skb, sk)) - continue; - - sock_hold(sk); - if (i < ARRAY_SIZE(stack)) - stack[i++] = sk; - else { - llc_do_mcast(sap, skb, stack, i); - i = 0; - } - } - spin_unlock_bh(&sap->sk_lock); - - llc_do_mcast(sap, skb, stack, i); -} - - -void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb) -{ - struct llc_addr laddr; - - llc_pdu_decode_da(skb, laddr.mac); - llc_pdu_decode_dsap(skb, &laddr.lsap); - - if (is_multicast_ether_addr(laddr.mac)) { - llc_sap_mcast(sap, &laddr, skb); - kfree_skb(skb); - } else { - struct sock *sk = llc_lookup_dgram(sap, &laddr, dev_net(skb->dev)); - if (sk) { - llc_sap_rcv(sap, skb, sk); - sock_put(sk); - } else - kfree_skb(skb); - } -} diff --git a/net/llc/llc_station.c b/net/llc/llc_station.c deleted file mode 100644 index 77fd0ac75263..000000000000 --- a/net/llc/llc_station.c +++ /dev/null @@ -1,120 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * llc_station.c - station component of LLC - * - * Copyright (c) 1997 by Procom Technology, Inc. - * 2001-2003 by Arnaldo Carvalho de Melo - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && /* command PDU */ - LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */ - LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID && - !pdu->dsap; /* NULL DSAP value */ -} - -static int llc_stat_ev_rx_null_dsap_test_c(struct sk_buff *skb) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - return LLC_PDU_IS_CMD(pdu) && /* command PDU */ - LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */ - LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST && - !pdu->dsap; /* NULL DSAP */ -} - -static int llc_station_ac_send_xid_r(struct sk_buff *skb) -{ - u8 mac_da[ETH_ALEN], dsap; - int rc = 1; - struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, - sizeof(struct llc_xid_info)); - - if (!nskb) - goto out; - llc_pdu_decode_sa(skb, mac_da); - llc_pdu_decode_ssap(skb, &dsap); - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); - llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127); - rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da); - if (unlikely(rc)) - goto free; - dev_queue_xmit(nskb); -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -static int llc_station_ac_send_test_r(struct sk_buff *skb) -{ - u8 mac_da[ETH_ALEN], dsap; - int rc = 1; - u32 data_size; - struct sk_buff *nskb; - - if (skb->mac_len < ETH_HLEN) - goto out; - - /* The test request command is type U (llc_len = 3) */ - data_size = ntohs(eth_hdr(skb)->h_proto) - 3; - nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size); - - if (!nskb) - goto out; - llc_pdu_decode_sa(skb, mac_da); - llc_pdu_decode_ssap(skb, &dsap); - llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); - llc_pdu_init_as_test_rsp(nskb, skb); - rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da); - if (unlikely(rc)) - goto free; - dev_queue_xmit(nskb); -out: - return rc; -free: - kfree_skb(nskb); - goto out; -} - -/** - * llc_station_rcv - send received pdu to the station state machine - * @skb: received frame. - * - * Sends data unit to station state machine. - */ -static void llc_station_rcv(struct sk_buff *skb) -{ - if (llc_stat_ev_rx_null_dsap_xid_c(skb)) - llc_station_ac_send_xid_r(skb); - else if (llc_stat_ev_rx_null_dsap_test_c(skb)) - llc_station_ac_send_test_r(skb); - kfree_skb(skb); -} - -void __init llc_station_init(void) -{ - llc_set_station_handler(llc_station_rcv); -} - -void llc_station_exit(void) -{ - llc_set_station_handler(NULL); -} diff --git a/net/llc/sysctl_net_llc.c b/net/llc/sysctl_net_llc.c deleted file mode 100644 index 15f1e5d88f20..000000000000 --- a/net/llc/sysctl_net_llc.c +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * sysctl_net_llc.c: sysctl interface to LLC net subsystem. - * - * Arnaldo Carvalho de Melo - */ - -#include -#include -#include -#include -#include - -static struct ctl_table llc2_timeout_table[] = { - { - .procname = "ack", - .data = &sysctl_llc2_ack_timeout, - .maxlen = sizeof(sysctl_llc2_ack_timeout), - .mode = 0644, - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname = "busy", - .data = &sysctl_llc2_busy_timeout, - .maxlen = sizeof(sysctl_llc2_busy_timeout), - .mode = 0644, - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname = "p", - .data = &sysctl_llc2_p_timeout, - .maxlen = sizeof(sysctl_llc2_p_timeout), - .mode = 0644, - .proc_handler = proc_dointvec_jiffies, - }, - { - .procname = "rej", - .data = &sysctl_llc2_rej_timeout, - .maxlen = sizeof(sysctl_llc2_rej_timeout), - .mode = 0644, - .proc_handler = proc_dointvec_jiffies, - }, -}; - -static struct ctl_table_header *llc2_timeout_header; -static struct ctl_table_header *llc_station_header; - -int __init llc_sysctl_init(void) -{ - static struct ctl_table empty[1] = {}; - llc2_timeout_header = register_net_sysctl(&init_net, "net/llc/llc2/timeout", llc2_timeout_table); - llc_station_header = register_net_sysctl_sz(&init_net, "net/llc/station", empty, 0); - - if (!llc2_timeout_header || !llc_station_header) { - llc_sysctl_exit(); - return -ENOMEM; - } - return 0; -} - -void llc_sysctl_exit(void) -{ - if (llc2_timeout_header) { - unregister_net_sysctl_table(llc2_timeout_header); - llc2_timeout_header = NULL; - } - if (llc_station_header) { - unregister_net_sysctl_table(llc_station_header); - llc_station_header = NULL; - } -} From 6c1f58d7d5dfdcf6d06bbe9f5cd4adfd22a7268a Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 28 Sep 2026 12:07:59 -0700 Subject: [PATCH 0997/2126] llc: strip the leftovers of the llc2 removal Nothing in tree registers the type 1 / type 2 packet handlers or the station handler any more, and nothing looks at the socket hashes hanging off struct llc_sap. The two SAPs opened in tree - SNAP, and STP for the bridge's BPDUs and GARP's PDUs - receive through the per-SAP rcv_func(), so llc_rcv() boils down to a SAP lookup and a call. llc_sap_list becomes static and five exports go away with all this; the llc2 module out of tree has been reworked to open its own SAPs. Frames with a NULL DSAP used to be handed to the station handler before the SAP lookup. They take the normal path now, meaning they get dropped unless something registers SAP 0. struct llc_sap is down to 48 bytes on 64-bit from over a kilobyte, which also moves its GFP_ATOMIC allocation from kmalloc-2k to kmalloc-64. The two 64-entry socket hashes are the bulk of it, and the address it carried is now just the SAP number - nothing has read the MAC half since the socket layer left. llc_pdu.h keeps only what its remaining users need, plus LLC_PDU_RSP to document the one argument which can take it. That takes out the type 2 (I and S format, FRMR) definitions, the XID and TEST builders with their constants - the kernel neither sends nor answers either any more - the SAP address defines, the field accessors, and the prototypes of the llc_pdu.c helpers which went out of tree with the rest of LLC2. With the I and S formats gone llc_pdu_header_init() has one PDU type left, so drop the argument. Signed-off-by: Jakub Kicinski Link: https://patch.msgid.link/20260928190800.2521749-3-kuba@kernel.org Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paolo Abeni --- include/net/llc.h | 82 +-------- include/net/llc_pdu.h | 379 +-------------------------------------- net/802/garp.c | 4 +- net/802/psnap.c | 2 +- net/bridge/br_stp_bpdu.c | 3 +- net/llc/llc_core.c | 25 +-- net/llc/llc_input.c | 125 +------------ net/llc/llc_output.c | 3 +- 8 files changed, 32 insertions(+), 591 deletions(-) diff --git a/include/net/llc.h b/include/net/llc.h index 8ea44ed98c4d..ce7db08e8355 100644 --- a/include/net/llc.h +++ b/include/net/llc.h @@ -6,112 +6,44 @@ * 2001-2003 by Arnaldo Carvalho de Melo */ -#include -#include #include -#include -#include -#include -#include - -#include +#include struct net_device; struct packet_type; struct sk_buff; -struct llc_addr { - unsigned char lsap; - unsigned char mac[IFHWADDRLEN]; -}; - -#define LLC_SAP_STATE_INACTIVE 1 -#define LLC_SAP_STATE_ACTIVE 2 - -#define LLC_SK_DEV_HASH_BITS 6 -#define LLC_SK_DEV_HASH_ENTRIES (1<sk_dev_hash[bucket]; -} - -static inline -u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr) -{ - return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0), - LLC_SK_LADDR_HASH_BITS); -} - -static inline -struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap, - const struct llc_addr *laddr) -{ - return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)]; -} - -#define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */ -#define LLC_DEST_SAP 1 /* Type 1 goes here */ -#define LLC_DEST_CONN 2 /* Type 2 goes here */ - -extern struct list_head llc_sap_list; - int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev); int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa, const unsigned char *da); -void llc_add_pack(int type, - void (*handler)(struct llc_sap *sap, struct sk_buff *skb)); -void llc_remove_pack(int type); - -void llc_set_station_handler(void (*handler)(struct sk_buff *skb)); - struct llc_sap *llc_sap_open(unsigned char lsap, int (*rcv)(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)); -static inline void llc_sap_hold(struct llc_sap *sap) -{ - refcount_inc(&sap->refcnt); -} static inline bool llc_sap_hold_safe(struct llc_sap *sap) { diff --git a/include/net/llc_pdu.h b/include/net/llc_pdu.h index f165237a3723..14c76b0d9832 100644 --- a/include/net/llc_pdu.h +++ b/include/net/llc_pdu.h @@ -6,201 +6,17 @@ * 2001-2003 by Arnaldo Carvalho de Melo */ -#include - -/* Lengths of frame formats */ -#define LLC_PDU_LEN_I 4 /* header and 2 control bytes */ -#define LLC_PDU_LEN_S 4 -#define LLC_PDU_LEN_U 3 /* header and 1 control byte */ -/* header and 1 control byte and XID info */ -#define LLC_PDU_LEN_U_XID (LLC_PDU_LEN_U + sizeof(struct llc_xid_info)) -/* Known SAP addresses */ -#define LLC_GLOBAL_SAP 0xFF -#define LLC_NULL_SAP 0x00 /* not network-layer visible */ -#define LLC_MGMT_INDIV 0x02 /* station LLC mgmt indiv addr */ -#define LLC_MGMT_GRP 0x03 /* station LLC mgmt group addr */ -#define LLC_RDE_SAP 0xA6 /* route ... */ - -/* SAP field bit masks */ -#define LLC_ISO_RESERVED_SAP 0x02 -#define LLC_SAP_GROUP_DSAP 0x01 -#define LLC_SAP_RESP_SSAP 0x01 - -/* Group/individual DSAP indicator is DSAP field */ -#define LLC_PDU_GROUP_DSAP_MASK 0x01 -#define LLC_PDU_IS_GROUP_DSAP(pdu) \ - ((pdu->dsap & LLC_PDU_GROUP_DSAP_MASK) ? 0 : 1) -#define LLC_PDU_IS_INDIV_DSAP(pdu) \ - (!(pdu->dsap & LLC_PDU_GROUP_DSAP_MASK) ? 0 : 1) +#include /* Command/response PDU indicator in SSAP field */ -#define LLC_PDU_CMD_RSP_MASK 0x01 #define LLC_PDU_CMD 0 #define LLC_PDU_RSP 1 -#define LLC_PDU_IS_CMD(pdu) ((pdu->ssap & LLC_PDU_RSP) ? 0 : 1) -#define LLC_PDU_IS_RSP(pdu) ((pdu->ssap & LLC_PDU_RSP) ? 1 : 0) /* Get PDU type from 2 lowest-order bits of control field first byte */ -#define LLC_PDU_TYPE_I_MASK 0x01 /* 16-bit control field */ -#define LLC_PDU_TYPE_S_MASK 0x03 -#define LLC_PDU_TYPE_U_MASK 0x03 /* 8-bit control field */ #define LLC_PDU_TYPE_MASK 0x03 - -#define LLC_PDU_TYPE_I 0 /* first bit */ -#define LLC_PDU_TYPE_S 1 /* first two bits */ #define LLC_PDU_TYPE_U 3 /* first two bits */ -#define LLC_PDU_TYPE_U_XID 4 /* private type for detecting XID commands */ - -#define LLC_PDU_TYPE_IS_I(pdu) \ - ((!(pdu->ctrl_1 & LLC_PDU_TYPE_I_MASK)) ? 1 : 0) - -#define LLC_PDU_TYPE_IS_U(pdu) \ - (((pdu->ctrl_1 & LLC_PDU_TYPE_U_MASK) == LLC_PDU_TYPE_U) ? 1 : 0) - -#define LLC_PDU_TYPE_IS_S(pdu) \ - (((pdu->ctrl_1 & LLC_PDU_TYPE_S_MASK) == LLC_PDU_TYPE_S) ? 1 : 0) - -/* U-format PDU control field masks */ -#define LLC_U_PF_BIT_MASK 0x10 /* P/F bit mask */ -#define LLC_U_PF_IS_1(pdu) ((pdu->ctrl_1 & LLC_U_PF_BIT_MASK) ? 1 : 0) -#define LLC_U_PF_IS_0(pdu) ((!(pdu->ctrl_1 & LLC_U_PF_BIT_MASK)) ? 1 : 0) - -#define LLC_U_PDU_CMD_MASK 0xEC /* cmd/rsp mask */ -#define LLC_U_PDU_CMD(pdu) (pdu->ctrl_1 & LLC_U_PDU_CMD_MASK) -#define LLC_U_PDU_RSP(pdu) (pdu->ctrl_1 & LLC_U_PDU_CMD_MASK) #define LLC_1_PDU_CMD_UI 0x00 /* Type 1 cmds/rsps */ -#define LLC_1_PDU_CMD_XID 0xAC -#define LLC_1_PDU_CMD_TEST 0xE0 - -#define LLC_2_PDU_CMD_SABME 0x6C /* Type 2 cmds/rsps */ -#define LLC_2_PDU_CMD_DISC 0x40 -#define LLC_2_PDU_RSP_UA 0x60 -#define LLC_2_PDU_RSP_DM 0x0C -#define LLC_2_PDU_RSP_FRMR 0x84 - -/* Type 1 operations */ - -/* XID information field bit masks */ - -/* LLC format identifier (byte 1) */ -#define LLC_XID_FMT_ID 0x81 /* first byte must be this */ - -/* LLC types/classes identifier (byte 2) */ -#define LLC_XID_CLASS_ZEROS_MASK 0xE0 /* these must be zeros */ -#define LLC_XID_CLASS_MASK 0x1F /* AND with byte to get below */ - -#define LLC_XID_NULL_CLASS_1 0x01 /* if NULL LSAP...use these */ -#define LLC_XID_NULL_CLASS_2 0x03 -#define LLC_XID_NULL_CLASS_3 0x05 -#define LLC_XID_NULL_CLASS_4 0x07 - -#define LLC_XID_NNULL_TYPE_1 0x01 /* if non-NULL LSAP...use these */ -#define LLC_XID_NNULL_TYPE_2 0x02 -#define LLC_XID_NNULL_TYPE_3 0x04 -#define LLC_XID_NNULL_TYPE_1_2 0x03 -#define LLC_XID_NNULL_TYPE_1_3 0x05 -#define LLC_XID_NNULL_TYPE_2_3 0x06 -#define LLC_XID_NNULL_ALL 0x07 - -/* Sender Receive Window (byte 3) */ -#define LLC_XID_RW_MASK 0xFE /* AND with value to get below */ - -#define LLC_XID_MIN_RW 0x02 /* lowest-order bit always zero */ - -/* Type 2 operations */ - -#define LLC_2_SEQ_NBR_MODULO ((u8) 128) - -/* I-PDU masks ('ctrl' is I-PDU control word) */ -#define LLC_I_GET_NS(pdu) (u8)((pdu->ctrl_1 & 0xFE) >> 1) -#define LLC_I_GET_NR(pdu) (u8)((pdu->ctrl_2 & 0xFE) >> 1) - -#define LLC_I_PF_BIT_MASK 0x01 - -#define LLC_I_PF_IS_0(pdu) ((!(pdu->ctrl_2 & LLC_I_PF_BIT_MASK)) ? 1 : 0) -#define LLC_I_PF_IS_1(pdu) ((pdu->ctrl_2 & LLC_I_PF_BIT_MASK) ? 1 : 0) - -/* S-PDU supervisory commands and responses */ - -#define LLC_S_PDU_CMD_MASK 0x0C -#define LLC_S_PDU_CMD(pdu) (pdu->ctrl_1 & LLC_S_PDU_CMD_MASK) -#define LLC_S_PDU_RSP(pdu) (pdu->ctrl_1 & LLC_S_PDU_CMD_MASK) - -#define LLC_2_PDU_CMD_RR 0x00 /* rx ready cmd */ -#define LLC_2_PDU_RSP_RR 0x00 /* rx ready rsp */ -#define LLC_2_PDU_CMD_REJ 0x08 /* reject PDU cmd */ -#define LLC_2_PDU_RSP_REJ 0x08 /* reject PDU rsp */ -#define LLC_2_PDU_CMD_RNR 0x04 /* rx not ready cmd */ -#define LLC_2_PDU_RSP_RNR 0x04 /* rx not ready rsp */ - -#define LLC_S_PF_BIT_MASK 0x01 -#define LLC_S_PF_IS_0(pdu) ((!(pdu->ctrl_2 & LLC_S_PF_BIT_MASK)) ? 1 : 0) -#define LLC_S_PF_IS_1(pdu) ((pdu->ctrl_2 & LLC_S_PF_BIT_MASK) ? 1 : 0) - -#define PDU_SUPV_GET_Nr(pdu) ((pdu->ctrl_2 & 0xFE) >> 1) -#define PDU_GET_NEXT_Vr(sn) (((sn) + 1) & ~LLC_2_SEQ_NBR_MODULO) - -/* FRMR information field macros */ - -#define FRMR_INFO_LENGTH 5 /* 5 bytes of information */ - -/* - * info is pointer to FRMR info field structure; 'rej_ctrl' is byte pointer - * (if U-PDU) or word pointer to rejected PDU control field - */ -#define FRMR_INFO_SET_REJ_CNTRL(info,rej_ctrl) \ - info->rej_pdu_ctrl = ((*((u8 *) rej_ctrl) & \ - LLC_PDU_TYPE_U) != LLC_PDU_TYPE_U ? \ - (u16)*((u16 *) rej_ctrl) : \ - (((u16) *((u8 *) rej_ctrl)) & 0x00FF)) - -/* - * Info is pointer to FRMR info field structure; 'vs' is a byte containing - * send state variable value in low-order 7 bits (insure the lowest-order - * bit remains zero (0)) - */ -#define FRMR_INFO_SET_Vs(info,vs) (info->curr_ssv = (((u8) vs) << 1)) -#define FRMR_INFO_SET_Vr(info,vr) (info->curr_rsv = (((u8) vr) << 1)) - -/* - * Info is pointer to FRMR info field structure; 'cr' is a byte containing - * the C/R bit value in the low-order bit - */ -#define FRMR_INFO_SET_C_R_BIT(info, cr) (info->curr_rsv |= (((u8) cr) & 0x01)) - -/* - * In the remaining five macros, 'info' is pointer to FRMR info field - * structure; 'ind' is a byte containing the bit value to set in the - * lowest-order bit) - */ -#define FRMR_INFO_SET_INVALID_PDU_CTRL_IND(info, ind) \ - (info->ind_bits = ((info->ind_bits & 0xFE) | (((u8) ind) & 0x01))) - -#define FRMR_INFO_SET_INVALID_PDU_INFO_IND(info, ind) \ - (info->ind_bits = ( (info->ind_bits & 0xFD) | (((u8) ind) & 0x02))) - -#define FRMR_INFO_SET_PDU_INFO_2LONG_IND(info, ind) \ - (info->ind_bits = ( (info->ind_bits & 0xFB) | (((u8) ind) & 0x04))) - -#define FRMR_INFO_SET_PDU_INVALID_Nr_IND(info, ind) \ - (info->ind_bits = ( (info->ind_bits & 0xF7) | (((u8) ind) & 0x08))) - -#define FRMR_INFO_SET_PDU_INVALID_Ns_IND(info, ind) \ - (info->ind_bits = ( (info->ind_bits & 0xEF) | (((u8) ind) & 0x10))) - -/* Sequence-numbered PDU format (4 bytes in length) */ -struct llc_pdu_sn { - u8 dsap; - u8 ssap; - u8 ctrl_1; - u8 ctrl_2; -} __packed; - -static inline struct llc_pdu_sn *llc_pdu_sn_hdr(struct sk_buff *skb) -{ - return (struct llc_pdu_sn *)skb_network_header(skb); -} /* Un-numbered PDU format (3 bytes in length) */ struct llc_pdu_un { @@ -217,29 +33,18 @@ static inline struct llc_pdu_un *llc_pdu_un_hdr(struct sk_buff *skb) /** * llc_pdu_header_init - initializes pdu header * @skb: input skb that header must be set into it. - * @type: type of PDU (U, I or S). * @ssap: source sap. * @dsap: destination sap. - * @cr: command/response bit (0 or 1). + * @cr: command/response bit (%LLC_PDU_CMD or %LLC_PDU_RSP). * * This function sets DSAP, SSAP and command/Response bit in LLC header. */ -static inline void llc_pdu_header_init(struct sk_buff *skb, u8 type, - u8 ssap, u8 dsap, u8 cr) +static inline void llc_pdu_header_init(struct sk_buff *skb, u8 ssap, u8 dsap, + u8 cr) { - int hlen = 4; /* default value for I and S types */ struct llc_pdu_un *pdu; - switch (type) { - case LLC_PDU_TYPE_U: - hlen = 3; - break; - case LLC_PDU_TYPE_U_XID: - hlen = 6; - break; - } - - skb_push(skb, hlen); + skb_push(skb, sizeof(*pdu)); skb_reset_network_header(skb); pdu = llc_pdu_un_hdr(skb); pdu->dsap = dsap; @@ -247,56 +52,6 @@ static inline void llc_pdu_header_init(struct sk_buff *skb, u8 type, pdu->ssap |= cr; } -/** - * llc_pdu_decode_sa - extracts, source address (MAC) of input frame - * @skb: input skb that source address must be extracted from it. - * @sa: pointer to source address (6 byte array). - * - * This function extracts source address(MAC) of input frame. - */ -static inline void llc_pdu_decode_sa(struct sk_buff *skb, u8 *sa) -{ - memcpy(sa, eth_hdr(skb)->h_source, ETH_ALEN); -} - -/** - * llc_pdu_decode_da - extracts dest address of input frame - * @skb: input skb that destination address must be extracted from it - * @da: pointer to destination address (6 byte array). - * - * This function extracts destination address(MAC) of input frame. - */ -static inline void llc_pdu_decode_da(struct sk_buff *skb, u8 *da) -{ - memcpy(da, eth_hdr(skb)->h_dest, ETH_ALEN); -} - -/** - * llc_pdu_decode_ssap - extracts source SAP of input frame - * @skb: input skb that source SAP must be extracted from it. - * @ssap: source SAP (output argument). - * - * This function extracts source SAP of input frame. Right bit of SSAP is - * command/response bit. - */ -static inline void llc_pdu_decode_ssap(struct sk_buff *skb, u8 *ssap) -{ - *ssap = llc_pdu_un_hdr(skb)->ssap & 0xFE; -} - -/** - * llc_pdu_decode_dsap - extracts dest SAP of input frame - * @skb: input skb that destination SAP must be extracted from it. - * @dsap: destination SAP (output argument). - * - * This function extracts destination SAP of input frame. right bit of - * DSAP designates individual/group SAP. - */ -static inline void llc_pdu_decode_dsap(struct sk_buff *skb, u8 *dsap) -{ - *dsap = llc_pdu_un_hdr(skb)->dsap & 0xFE; -} - /** * llc_pdu_init_as_ui_cmd - sets LLC header as UI PDU * @skb: input skb that header must be set into it. @@ -311,128 +66,4 @@ static inline void llc_pdu_init_as_ui_cmd(struct sk_buff *skb) pdu->ctrl_1 |= LLC_1_PDU_CMD_UI; } -/** - * llc_pdu_init_as_test_cmd - sets PDU as TEST - * @skb: Address of the skb to build - * - * Sets a PDU as TEST - */ -static inline void llc_pdu_init_as_test_cmd(struct sk_buff *skb) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_1_PDU_CMD_TEST; - pdu->ctrl_1 |= LLC_U_PF_BIT_MASK; -} - -/** - * llc_pdu_init_as_test_rsp - build TEST response PDU - * @skb: Address of the skb to build - * @ev_skb: The received TEST command PDU frame - * - * Builds a pdu frame as a TEST response. - */ -static inline void llc_pdu_init_as_test_rsp(struct sk_buff *skb, - struct sk_buff *ev_skb) -{ - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_1_PDU_CMD_TEST; - pdu->ctrl_1 |= LLC_U_PF_BIT_MASK; - if (ev_skb->protocol == htons(ETH_P_802_2)) { - struct llc_pdu_un *ev_pdu = llc_pdu_un_hdr(ev_skb); - int dsize; - - dsize = ntohs(eth_hdr(ev_skb)->h_proto) - 3; - memcpy(((u8 *)pdu) + 3, ((u8 *)ev_pdu) + 3, dsize); - skb_put(skb, dsize); - } -} - -/* LLC Type 1 XID command/response information fields format */ -struct llc_xid_info { - u8 fmt_id; /* always 0x81 for LLC */ - u8 type; /* different if NULL/non-NULL LSAP */ - u8 rw; /* sender receive window */ -} __packed; - -/** - * llc_pdu_init_as_xid_cmd - sets bytes 3, 4 & 5 of LLC header as XID - * @skb: input skb that header must be set into it. - * @svcs_supported: The class of the LLC (I or II) - * @rx_window: The size of the receive window of the LLC - * - * This function sets third,fourth,fifth and sixth bytes of LLC header as - * a XID PDU. - */ -static inline void llc_pdu_init_as_xid_cmd(struct sk_buff *skb, - u8 svcs_supported, u8 rx_window) -{ - struct llc_xid_info *xid_info; - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_1_PDU_CMD_XID; - pdu->ctrl_1 |= LLC_U_PF_BIT_MASK; - xid_info = (struct llc_xid_info *)(((u8 *)&pdu->ctrl_1) + 1); - xid_info->fmt_id = LLC_XID_FMT_ID; /* 0x81 */ - xid_info->type = svcs_supported; - xid_info->rw = rx_window << 1; /* size of receive window */ - - /* no need to push/put since llc_pdu_header_init() has already - * pushed 3 + 3 bytes - */ -} - -/** - * llc_pdu_init_as_xid_rsp - builds XID response PDU - * @skb: Address of the skb to build - * @svcs_supported: The class of the LLC (I or II) - * @rx_window: The size of the receive window of the LLC - * - * Builds a pdu frame as an XID response. - */ -static inline void llc_pdu_init_as_xid_rsp(struct sk_buff *skb, - u8 svcs_supported, u8 rx_window) -{ - struct llc_xid_info *xid_info; - struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); - - pdu->ctrl_1 = LLC_PDU_TYPE_U; - pdu->ctrl_1 |= LLC_1_PDU_CMD_XID; - pdu->ctrl_1 |= LLC_U_PF_BIT_MASK; - - xid_info = (struct llc_xid_info *)(((u8 *)&pdu->ctrl_1) + 1); - xid_info->fmt_id = LLC_XID_FMT_ID; - xid_info->type = svcs_supported; - xid_info->rw = rx_window << 1; - skb_put(skb, sizeof(struct llc_xid_info)); -} - -/* LLC Type 2 FRMR response information field format */ -struct llc_frmr_info { - u16 rej_pdu_ctrl; /* bits 1-8 if U-PDU */ - u8 curr_ssv; /* current send state variable val */ - u8 curr_rsv; /* current receive state variable */ - u8 ind_bits; /* indicator bits set with macro */ -} __packed; - -void llc_pdu_set_cmd_rsp(struct sk_buff *skb, u8 type); -void llc_pdu_set_pf_bit(struct sk_buff *skb, u8 bit_value); -void llc_pdu_decode_pf_bit(struct sk_buff *skb, u8 *pf_bit); -void llc_pdu_init_as_disc_cmd(struct sk_buff *skb, u8 p_bit); -void llc_pdu_init_as_i_cmd(struct sk_buff *skb, u8 p_bit, u8 ns, u8 nr); -void llc_pdu_init_as_rej_cmd(struct sk_buff *skb, u8 p_bit, u8 nr); -void llc_pdu_init_as_rnr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr); -void llc_pdu_init_as_rr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr); -void llc_pdu_init_as_sabme_cmd(struct sk_buff *skb, u8 p_bit); -void llc_pdu_init_as_dm_rsp(struct sk_buff *skb, u8 f_bit); -void llc_pdu_init_as_frmr_rsp(struct sk_buff *skb, struct llc_pdu_sn *prev_pdu, - u8 f_bit, u8 vs, u8 vr, u8 vzyxw); -void llc_pdu_init_as_rr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr); -void llc_pdu_init_as_rej_rsp(struct sk_buff *skb, u8 f_bit, u8 nr); -void llc_pdu_init_as_rnr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr); -void llc_pdu_init_as_ua_rsp(struct sk_buff *skb, u8 f_bit); #endif /* LLC_PDU_H */ diff --git a/net/802/garp.c b/net/802/garp.c index 56b934ec1aae..de6b96bd425a 100644 --- a/net/802/garp.c +++ b/net/802/garp.c @@ -255,8 +255,8 @@ static void garp_pdu_queue(struct garp_applicant *app) garp_pdu_append_end_mark(app); garp_pdu_append_end_mark(app); - llc_pdu_header_init(app->pdu, LLC_PDU_TYPE_U, LLC_SAP_BSPAN, - LLC_SAP_BSPAN, LLC_PDU_CMD); + llc_pdu_header_init(app->pdu, LLC_SAP_BSPAN, LLC_SAP_BSPAN, + LLC_PDU_CMD); llc_pdu_init_as_ui_cmd(app->pdu); llc_mac_hdr_init(app->pdu, app->dev->dev_addr, app->app->proto.group_address); diff --git a/net/802/psnap.c b/net/802/psnap.c index 8ae835e1cbae..c776c5f0041f 100644 --- a/net/802/psnap.c +++ b/net/802/psnap.c @@ -82,7 +82,7 @@ static int snap_request(struct datalink_proto *dl, struct sk_buff *skb, const u8 *dest) { memcpy(skb_push(skb, 5), dl->type, 5); - llc_build_and_send_ui_pkt(snap_sap, skb, dest, snap_sap->laddr.lsap); + llc_build_and_send_ui_pkt(snap_sap, skb, dest, snap_sap->lsap); return 0; } diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c index 21d092f5acbb..6cb2526c38f8 100644 --- a/net/bridge/br_stp_bpdu.c +++ b/net/bridge/br_stp_bpdu.c @@ -48,8 +48,7 @@ static void br_send_bpdu(struct net_bridge_port *p, skb_reserve(skb, LLC_RESERVE); __skb_put_data(skb, data, length); - llc_pdu_header_init(skb, LLC_PDU_TYPE_U, LLC_SAP_BSPAN, - LLC_SAP_BSPAN, LLC_PDU_CMD); + llc_pdu_header_init(skb, LLC_SAP_BSPAN, LLC_SAP_BSPAN, LLC_PDU_CMD); llc_pdu_init_as_ui_cmd(skb); if (llc_mac_hdr_init(skb, p->dev->dev_addr, p->br->group_addr)) { diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c index 5b0f1986bddc..cde6a0b1509e 100644 --- a/net/llc/llc_core.c +++ b/net/llc/llc_core.c @@ -16,7 +16,7 @@ #include #include -LIST_HEAD(llc_sap_list); +static LIST_HEAD(llc_sap_list); static DEFINE_SPINLOCK(llc_sap_list_lock); /** @@ -27,16 +27,9 @@ static DEFINE_SPINLOCK(llc_sap_list_lock); static struct llc_sap *llc_sap_alloc(void) { struct llc_sap *sap = kzalloc_obj(*sap, GFP_ATOMIC); - int i; - if (sap) { - /* sap->laddr.mac - leave as a null, it's filled by bind */ - sap->state = LLC_SAP_STATE_ACTIVE; - spin_lock_init(&sap->sk_lock); - for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) - INIT_HLIST_NULLS_HEAD(&sap->sk_laddr_hash[i], i); + if (sap) refcount_set(&sap->refcnt, 1); - } return sap; } @@ -45,7 +38,7 @@ static struct llc_sap *__llc_sap_find(unsigned char sap_value) struct llc_sap *sap; list_for_each_entry(sap, &llc_sap_list, node) - if (sap->laddr.lsap == sap_value) + if (sap->lsap == sap_value) goto out; sap = NULL; out: @@ -53,10 +46,9 @@ out: } /** - * llc_sap_find - searches a SAP in station + * llc_sap_find - searches for a SAP by its number * @sap_value: sap to be found * - * Searches for a sap in the sap list of the LLC's station upon the sap ID. * If the sap is found it will be refcounted and the user will have to do * a llc_sap_put after use. * Returns the sap or %NULL if not found. @@ -96,7 +88,7 @@ struct llc_sap *llc_sap_open(unsigned char lsap, sap = llc_sap_alloc(); if (!sap) goto out; - sap->laddr.lsap = lsap; + sap->lsap = lsap; sap->rcv_func = func; list_add_tail_rcu(&sap->node, &llc_sap_list); out: @@ -110,13 +102,10 @@ out: * * Close interface function to upper layer. Each one who wants to * close an open SAP (for example NetBEUI) should call this function. - * Removes this sap from the list of saps in the station and then - * frees the memory for this sap. + * Removes this sap from the SAP list and then frees the memory for it. */ void llc_sap_close(struct llc_sap *sap) { - WARN_ON(sap->sk_count); - spin_lock_bh(&llc_sap_list_lock); list_del_rcu(&sap->node); spin_unlock_bh(&llc_sap_list_lock); @@ -143,8 +132,6 @@ static void __exit llc_exit(void) module_init(llc_init); module_exit(llc_exit); -EXPORT_SYMBOL(llc_sap_list); -EXPORT_SYMBOL(llc_sap_find); EXPORT_SYMBOL(llc_sap_open); EXPORT_SYMBOL(llc_sap_close); diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c index 78426ae7c73f..a8730c54b5c2 100644 --- a/net/llc/llc_input.c +++ b/net/llc/llc_input.c @@ -7,7 +7,6 @@ */ #include #include -#include #include #include #include @@ -18,80 +17,6 @@ #define dprintk(args...) #endif -/* - * Packet handler for the station, registerable because in the minimal - * LLC core that is taking shape only the very minimal subset of LLC that - * is needed for things like IPX, Appletalk, etc will stay, with all the - * rest in the llc1 and llc2 modules. - */ -static void (*llc_station_handler)(struct sk_buff *skb); - -/* - * Packet handlers for LLC_DEST_SAP and LLC_DEST_CONN. - */ -static void (*llc_type_handlers[2])(struct llc_sap *sap, - struct sk_buff *skb); - -void llc_add_pack(int type, void (*handler)(struct llc_sap *sap, - struct sk_buff *skb)) -{ - smp_wmb(); /* ensure initialisation is complete before it's called */ - if (type == LLC_DEST_SAP || type == LLC_DEST_CONN) - llc_type_handlers[type - 1] = handler; -} - -void llc_remove_pack(int type) -{ - if (type == LLC_DEST_SAP || type == LLC_DEST_CONN) - llc_type_handlers[type - 1] = NULL; - synchronize_net(); -} - -void llc_set_station_handler(void (*handler)(struct sk_buff *skb)) -{ - /* Ensure initialisation is complete before it's called */ - if (handler) - smp_wmb(); - - llc_station_handler = handler; - - if (!handler) - synchronize_net(); -} - -/** - * llc_pdu_type - returns which LLC component must handle for PDU - * @skb: input skb - * - * This function returns which LLC component must handle this PDU. - */ -static __inline__ int llc_pdu_type(struct sk_buff *skb) -{ - int type = LLC_DEST_CONN; /* I-PDU or S-PDU type */ - struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); - - if ((pdu->ctrl_1 & LLC_PDU_TYPE_MASK) != LLC_PDU_TYPE_U) - goto out; - switch (LLC_U_PDU_CMD(pdu)) { - case LLC_1_PDU_CMD_XID: - case LLC_1_PDU_CMD_UI: - case LLC_1_PDU_CMD_TEST: - type = LLC_DEST_SAP; - break; - case LLC_2_PDU_CMD_SABME: - case LLC_2_PDU_CMD_DISC: - case LLC_2_PDU_RSP_UA: - case LLC_2_PDU_RSP_DM: - case LLC_2_PDU_RSP_FRMR: - break; - default: - type = LLC_DEST_INVALID; - break; - } -out: - return type; -} - /** * llc_fixup_skb - initializes skb pointers * @skb: This argument points to incoming skb @@ -146,21 +71,16 @@ static inline int llc_fixup_skb(struct sk_buff *skb) * @orig_dev: the original receive net device * * When the system receives a 802.2 frame this function is called. It - * checks SAP and connection of received pdu and passes frame to - * llc_{station,sap,conn}_rcv for sending to proper state machine. If - * the frame is related to a busy connection (a connection is sending - * data now), it queues this frame in the connection's backlog. + * looks up the SAP the pdu is addressed to and passes the frame to its + * handler, dropping it if the SAP is unknown or has no handler. */ int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { - struct llc_sap *sap; - struct llc_pdu_sn *pdu; - int dest; int (*rcv)(struct sk_buff *, struct net_device *, struct packet_type *, struct net_device *); - void (*sta_handler)(struct sk_buff *skb); - void (*sap_handler)(struct llc_sap *sap, struct sk_buff *skb); + struct llc_pdu_un *pdu; + struct llc_sap *sap; /* * When the interface is in promisc. mode, drop all the crap that it @@ -175,49 +95,22 @@ int llc_rcv(struct sk_buff *skb, struct net_device *dev, goto out; if (unlikely(!llc_fixup_skb(skb))) goto drop; - pdu = llc_pdu_sn_hdr(skb); - if (unlikely(!pdu->dsap)) /* NULL DSAP, refer to station */ - goto handle_station; + pdu = llc_pdu_un_hdr(skb); sap = llc_sap_find(pdu->dsap); if (unlikely(!sap)) {/* unknown SAP */ dprintk("%s: llc_sap_find(%02X) failed!\n", __func__, pdu->dsap); goto drop; } - /* - * First the upper layer protocols that don't need the full - * LLC functionality - */ rcv = rcu_dereference(sap->rcv_func); - dest = llc_pdu_type(skb); - sap_handler = dest ? READ_ONCE(llc_type_handlers[dest - 1]) : NULL; - if (unlikely(!sap_handler)) { - if (rcv) - rcv(skb, dev, pt, orig_dev); - else - kfree_skb(skb); - } else { - if (rcv) { - struct sk_buff *cskb = skb_clone(skb, GFP_ATOMIC); - if (cskb) - rcv(cskb, dev, pt, orig_dev); - } - sap_handler(sap, skb); - } + if (likely(rcv)) + rcv(skb, dev, pt, orig_dev); + else + kfree_skb(skb); llc_sap_put(sap); out: return 0; drop: kfree_skb(skb); goto out; -handle_station: - sta_handler = READ_ONCE(llc_station_handler); - if (!sta_handler) - goto drop; - sta_handler(skb); - goto out; } - -EXPORT_SYMBOL(llc_add_pack); -EXPORT_SYMBOL(llc_remove_pack); -EXPORT_SYMBOL(llc_set_station_handler); diff --git a/net/llc/llc_output.c b/net/llc/llc_output.c index 5a6466fc626a..8324f1cad4ca 100644 --- a/net/llc/llc_output.c +++ b/net/llc/llc_output.c @@ -59,8 +59,7 @@ int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, const unsigned char *dmac, unsigned char dsap) { int rc; - llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap, - dsap, LLC_PDU_CMD); + llc_pdu_header_init(skb, sap->lsap, dsap, LLC_PDU_CMD); llc_pdu_init_as_ui_cmd(skb); rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac); if (likely(!rc)) From 0b934eb6b14205d04f76b4464cb7dd6b9b3f6e2c Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 28 Sep 2026 12:08:00 -0700 Subject: [PATCH 0998/2126] net: drop unused LLC-related includes The bridge and the openvswitch code include , and without using anything out of them. parse_ethertype() is the one exception: it wants LLC_SAP_SNAP, which comes from the uAPI header pulls in, so flow.c keeps that one. The LLC core has leftovers of its own - slab, string, interrupt and net_namespace - which it has not used in a long time. None of this is new, the type 2 removal has just shrunk the LLC headers enough to make it easy to see. Signed-off-by: Jakub Kicinski Acked-by: Aaron Conole Link: https://patch.msgid.link/20260928190800.2521749-4-kuba@kernel.org Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paolo Abeni --- net/bridge/br.c | 2 -- net/llc/llc_core.c | 3 --- net/llc/llc_input.c | 2 -- net/openvswitch/flow.c | 1 - net/openvswitch/flow_netlink.c | 2 -- net/openvswitch/flow_table.c | 2 -- net/openvswitch/vport-netdev.c | 1 - 7 files changed, 13 deletions(-) diff --git a/net/bridge/br.c b/net/bridge/br.c index 09a120b3b76c..c602d6305997 100644 --- a/net/bridge/br.c +++ b/net/bridge/br.c @@ -12,8 +12,6 @@ #include #include #include -#include -#include #include #include diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c index cde6a0b1509e..eafc57ac903d 100644 --- a/net/llc/llc_core.c +++ b/net/llc/llc_core.c @@ -7,13 +7,10 @@ */ #include -#include #include #include #include -#include #include -#include #include static LIST_HEAD(llc_sap_list); diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c index a8730c54b5c2..6bb4275a8518 100644 --- a/net/llc/llc_input.c +++ b/net/llc/llc_input.c @@ -6,8 +6,6 @@ * 2001-2003 by Arnaldo Carvalho de Melo */ #include -#include -#include #include #include diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c index 868d9fdf3afd..1c4f3a079044 100644 --- a/net/openvswitch/flow.c +++ b/net/openvswitch/flow.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index d8079dee700e..de0053f701b3 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -12,11 +12,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index 1e0f9d193eb0..93d36f66e2ac 100644 --- a/net/openvswitch/flow_table.c +++ b/net/openvswitch/flow_table.c @@ -11,11 +11,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include diff --git a/net/openvswitch/vport-netdev.c b/net/openvswitch/vport-netdev.c index 44808cd0fcff..7daea2e44dfa 100644 --- a/net/openvswitch/vport-netdev.c +++ b/net/openvswitch/vport-netdev.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include From 3b49f11cc92dc10a3587c9c982cbab6fa8ba91c9 Mon Sep 17 00:00:00 2001 From: Quanye Yang Date: Fri, 25 Sep 2026 05:47:56 -0700 Subject: [PATCH 0999/2126] tcp: annotate lockless access to sk->sk_err BUG: KCSAN: data-race in do_recvmmsg / mptcp_recvmsg read-write (marked) to 0xffff8880134d391c of 4 bytes by task 2619 on cpu 1: instrument_atomic_read_write include/linux/instrumented.h:113 [inline] sock_error include/net/sock.h:2565 [inline] do_recvmmsg+0x50c/0x580 net/socket.c:3049 __sys_recvmmsg net/socket.c:3144 [inline] __do_sys_recvmmsg net/socket.c:3167 [inline] __se_sys_recvmmsg net/socket.c:3160 [inline] __x64_sys_recvmmsg+0x161/0x180 net/socket.c:3160 x64_sys_call+0x19c7/0x1ca0 arch/x86/include/generated/asm/syscalls_64.h:300 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0xde/0x3d0 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f read to 0xffff8880134d391c of 4 bytes by task 2620 on cpu 0: tcp_recv_should_stop include/net/tcp.h:3086 [inline] mptcp_recvmsg+0x54d/0xd50 net/mptcp/protocol.c:2466 inet_recvmsg+0x204/0x210 net/ipv4/af_inet.c:894 sock_recvmsg_nosec net/socket.c:1151 [inline] sock_recvmsg+0x11a/0x140 net/socket.c:1173 ____sys_recvmsg+0x14b/0x3c0 net/socket.c:2933 ___sys_recvmsg+0x116/0x160 net/socket.c:2975 __sys_recvmsg net/socket.c:3008 [inline] __do_sys_recvmsg net/socket.c:3014 [inline] __se_sys_recvmsg net/socket.c:3011 [inline] __x64_sys_recvmsg+0xeb/0x160 net/socket.c:3011 x64_sys_call+0x1319/0x1ca0 arch/x86/include/generated/asm/syscalls_64.h:48 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0xde/0x3d0 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f value changed: 0x0000006b -> 0x00000000 Reported by Kernel Concurrency Sanitizer on: CPU: 0 UID: 0 PID: 2620 Comm: syz.2.33 Not tainted 7.2.0-g39d4f32c5d53 #76 PREEMPT(full) Hardware name: QEMU Ubuntu 26.04 PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014 do_recvmmsg() and getsockopt(SO_ERROR) call sock_error() without the socket lock. sock_error() clears sk_err with xchg(), which races with unmarked loads of the same field. KCSAN reported the unmarked peek in tcp_recv_should_stop(). Annotate that helper and the other send-side peeks with READ_ONCE(). On the no-data recv and splice paths, if (sk_err) followed by sock_error() and an unconditional break can return 0 after another thread consumes the error. Call sock_error() once and only stop when it returns a non-zero error. tcp_bpf_sendmsg() read sk_err twice; fold those unmarked loads into one READ_ONCE() and use that value as the returned errno. The field is still not consumed. MPTCP is handled in the next patch. Suggested-by: Jiayuan Chen Link: https://lore.kernel.org/netdev/8bbee583-6f21-4817-bfeb-2d60057380a3@linux.dev/ Reported-by: Matthieu Baerts (NGI0) Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/632 Signed-off-by: Quanye Yang Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260925-mptcp-sk-err-net-v5-1-0cac04d6ea48@proton.me Signed-off-by: Paolo Abeni --- include/net/tcp.h | 2 +- net/core/stream.c | 2 +- net/ipv4/tcp.c | 12 +++++------- net/ipv4/tcp_bpf.c | 10 ++++------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 96a1a23e47fa..74f54bfa51f1 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -3093,7 +3093,7 @@ enum skb_drop_reason tcp_inbound_hash(struct sock *sk, static inline int tcp_recv_should_stop(struct sock *sk) { - return sk->sk_err || + return READ_ONCE(sk->sk_err) || sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN) || signal_pending(current); diff --git a/net/core/stream.c b/net/core/stream.c index 2d748581862d..5c0adc3077f0 100644 --- a/net/core/stream.c +++ b/net/core/stream.c @@ -133,7 +133,7 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p) while (1) { sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); - if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) + if (READ_ONCE(sk->sk_err) || (sk->sk_shutdown & SEND_SHUTDOWN)) goto do_error; if (!*timeo_p) goto do_eagain; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 3ac485685279..7c9d8305094c 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -846,10 +846,9 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos, break; if (sock_flag(sk, SOCK_DONE)) break; - if (sk->sk_err) { - ret = sock_error(sk); + ret = sock_error(sk); + if (ret) break; - } if (sk->sk_shutdown & RCV_SHUTDOWN) break; if (sk->sk_state == TCP_CLOSE) { @@ -1230,7 +1229,7 @@ restart: mss_now = tcp_send_mss(sk, &size_goal, flags); err = -EPIPE; - if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) + if (READ_ONCE(sk->sk_err) || (sk->sk_shutdown & SEND_SHUTDOWN)) goto do_error; while (msg_data_left(msg)) { @@ -2762,10 +2761,9 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len, if (sock_flag(sk, SOCK_DONE)) break; - if (sk->sk_err) { - copied = sock_error(sk); + copied = sock_error(sk); + if (copied) break; - } if (sk->sk_shutdown & RCV_SHUTDOWN) break; diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 2e234d155b5e..338c5d90e550 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -286,10 +286,9 @@ msg_bytes_ready: if (sock_flag(sk, SOCK_DONE)) goto out; - if (sk->sk_err) { - copied = sock_error(sk); + copied = sock_error(sk); + if (copied) goto out; - } if (sk->sk_shutdown & RCV_SHUTDOWN) goto out; @@ -553,10 +552,9 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) bool enospc = false; u32 copy, osize; - if (sk->sk_err) { - err = -sk->sk_err; + err = -READ_ONCE(sk->sk_err); + if (err) goto out_err; - } copy = msg_data_left(msg); if (!sk_stream_memory_free(sk)) From 97870870b7dd7970d4e6090b63627abf2ee3e6a5 Mon Sep 17 00:00:00 2001 From: Quanye Yang Date: Fri, 25 Sep 2026 05:47:57 -0700 Subject: [PATCH 1000/2126] mptcp: annotate lockless access to sk->sk_err sock_error() can clear sk_err with xchg() without the socket lock. On the no-data msk recv and splice paths, call sock_error() once and only stop when it returns a non-zero error. Annotate the remaining msk send and subflow error-report peeks with READ_ONCE(). Signed-off-by: Quanye Yang Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260925-mptcp-sk-err-net-v5-2-0cac04d6ea48@proton.me Signed-off-by: Paolo Abeni --- net/mptcp/protocol.c | 14 ++++++-------- net/mptcp/subflow.c | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e89a69ab927c..b543eb245136 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -970,7 +970,7 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk) moved = __mptcp_move_skbs_from_subflow(msk, ssk, true); __mptcp_ofo_queue(msk); - if (unlikely(ssk->sk_err)) + if (unlikely(READ_ONCE(ssk->sk_err))) __mptcp_subflow_error_report(sk, ssk); /* If the moves have caught up with the DATA_FIN sequence number @@ -2033,7 +2033,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } ret = -EPIPE; - if (unlikely(sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))) + if (unlikely(READ_ONCE(sk->sk_err) || (sk->sk_shutdown & SEND_SHUTDOWN))) goto do_error; pfrag = sk_page_frag(sk); @@ -2434,10 +2434,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, !timeo) break; } else { - if (sk->sk_err) { - copied = sock_error(sk); + copied = sock_error(sk); + if (copied) break; - } if (sk->sk_shutdown & RCV_SHUTDOWN) break; @@ -4671,10 +4670,9 @@ static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos, break; if (sock_flag(sk, SOCK_DONE)) break; - if (sk->sk_err) { - ret = sock_error(sk); + ret = sock_error(sk); + if (ret) break; - } if (sk->sk_shutdown & RCV_SHUTDOWN) break; if (sk->sk_state == TCP_CLOSE) { diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 14aa82647c3d..e9cb19188069 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1545,7 +1545,7 @@ static void subflow_data_ready(struct sock *sk) if (mptcp_data_avail(msk) < parent->sk_rcvlowat && (tcp_sk(sk)->rcv_nxt - tcp_sk(sk)->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss) inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW; - } else if (unlikely(sk->sk_err)) { + } else if (unlikely(READ_ONCE(sk->sk_err))) { subflow_error_report(sk); } } @@ -1900,7 +1900,7 @@ static void subflow_state_change(struct sock *sk) */ if (mptcp_subflow_data_available(sk)) mptcp_data_ready(parent, sk); - else if (unlikely(sk->sk_err)) + else if (unlikely(READ_ONCE(sk->sk_err))) subflow_error_report(sk); subflow_sched_work_if_closed(mptcp_sk(parent), sk); From f5185ec79dac01431c01427c4583147a6d0ce20a Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Mon, 28 Sep 2026 10:42:55 +0300 Subject: [PATCH 1001/2126] net: axienet: use device_property and fwnode APIs for probe-time config axienet_probe() reads its configuration exclusively through the of_* API, so the driver can only be instantiated from a device tree node. The ADVA TimeCard X2 is a PCIe timing card, driven by ptp_ocp, whose FPGA contains an AXI Ethernet MAC with an AXI DMA engine. ptp_ocp is going to register the MAC as a child platform device described by a software node, so that this driver runs it rather than a copy in ptp_ocp. That needs the probe-time configuration to be readable from a software node. Convert only the lookups such a caller needs: "xlnx,rxmem", which probe requires; "phy-mode"; the MAC address; and the PHY connection, which is where phylink finds a "fixed-link" child. On a device tree this is a no-op: device_property_read_u32() dispatches to the of_* implementation when dev->fwnode is an OF node, phylink_of_phy_connect() is a wrapper around phylink_fwnode_phy_connect(), and device_get_phy_mode() and device_get_mac_address() are thin fwnode wrappers around the same lookups. device_get_mac_address() also keeps the "mac-address" nvmem cell fallback that of_get_mac_address() has. Note that device_get_phy_mode() returns the mode as a positive value rather than through an out parameter, so the error test changes from "if (ret)" to "if (ret < 0)". Everything else stays on the OF API. "xlnx,txcsum", "xlnx,rxcsum" and "xlnx,switch-x-sgmii" are optional, and "xlnx,phy-type" is deprecated in favour of "phy-mode". Without an OF node each of those lookups finds nothing, exactly as for a device tree node that leaves them out: no checksum offload, no runtime SGMII/1000BASE-X switching and a fall-through to "phy-mode". The "dmas" test likewise selects the built-in AXI DMA engine. The "axistream-connected", "pcs-handle" and "phy-handle" phandle lookups stay too: a caller without an OF node takes neither branch, getting its DMA registers from its own platform resources, and it cannot use the SGMII and 1000BASE-X modes, which need a PCS. No functional change intended. Tested on the X2 with a local ptp_ocp change, with CONFIG_OF disabled and enabled: the interface probes with its configuration read from the software node and passes traffic. No device tree board was available, so the claim that this is a no-op for device tree users rests on the dispatch described above. Assisted-by: LLM sparse Signed-off-by: Sagi Maimon Reviewed-by: Andrew Lunn Tested-by: Suraj Gupta Reviewed-by: Suraj Gupta Link: https://patch.msgid.link/20260928074256.462345-2-maimon.sagi@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 782f903d318f..0f2170af9b10 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1671,7 +1672,7 @@ static int axienet_open(struct net_device *ndev) ret = axienet_device_reset(ndev); axienet_unlock_mii(lp); - ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0); + ret = phylink_fwnode_phy_connect(lp->phylink, dev_fwnode(lp->dev), 0); if (ret) { dev_err(lp->dev, "phylink_of_phy_connect() failed: %d\n", ret); return ret; @@ -2898,7 +2899,7 @@ static int axienet_probe(struct platform_device *pdev) * Here we check for memory allocated for Rx/Tx in the hardware from * the device-tree and accordingly set flags. */ - ret = of_property_read_u32(pdev->dev.of_node, "xlnx,rxmem", &lp->rxmem); + ret = device_property_read_u32(&pdev->dev, "xlnx,rxmem", &lp->rxmem); if (ret) return dev_err_probe(&pdev->dev, ret, "failed to read xlnx,rxmem property\n"); @@ -2930,9 +2931,10 @@ static int axienet_probe(struct platform_device *pdev) return -EINVAL; } } else { - ret = of_get_phy_mode(pdev->dev.of_node, &lp->phy_mode); - if (ret) + ret = device_get_phy_mode(&pdev->dev); + if (ret < 0) return ret; + lp->phy_mode = ret; } if (lp->switch_x_sgmii && lp->phy_mode != PHY_INTERFACE_MODE_SGMII && lp->phy_mode != PHY_INTERFACE_MODE_1000BASEX) { @@ -3060,7 +3062,7 @@ static int axienet_probe(struct platform_device *pdev) dev_info(&pdev->dev, "Ethernet core IRQ not defined\n"); /* Retrieve the MAC address */ - ret = of_get_mac_address(pdev->dev.of_node, mac_addr); + ret = device_get_mac_address(&pdev->dev, mac_addr); if (!ret) { axienet_set_mac_address(ndev, mac_addr); } else { From 418149559ef3606ea710192e1a12a58d8ff8de4c Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Mon, 28 Sep 2026 10:42:56 +0300 Subject: [PATCH 1002/2126] net: axienet: add a MODULE_ALIAS for platform instantiation The module is built as xilinx_emac.ko while the platform driver it registers is named xilinx_axienet. For a device tree instantiation that mismatch does not matter, because the OF match table supplies the modalias udev uses to load the module. A device registered by name from another driver has no OF node and so no OF modalias. It advertises platform:xilinx_axienet, which matches nothing, and the device is created but never bound. ptp_ocp is going to register the AXI Ethernet MAC of the ADVA TimeCard X2 this way, as a child platform device described by a software node. Add the corresponding MODULE_ALIAS so name-based instantiation can autoload the driver, and give the name a define now that it is used in more than one place. Tested on the X2 with a local ptp_ocp change: with this patch the module is loaded and binds when ptp_ocp registers the device; without it the device stays unbound until xilinx_emac is loaded by hand. Assisted-by: LLM sparse Signed-off-by: Sagi Maimon Link: https://patch.msgid.link/20260928074256.462345-3-maimon.sagi@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 0f2170af9b10..ae8ed4495ea0 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -48,6 +48,7 @@ #include "xilinx_axienet.h" /* Descriptors defines for Tx and Rx DMA */ +#define AXIENET_DRIVER_NAME "xilinx_axienet" #define TX_BD_NUM_DEFAULT 128 #define RX_BD_NUM_DEFAULT 1024 #define TX_BD_NUM_MIN (MAX_SKB_FRAGS + 1) @@ -3223,7 +3224,7 @@ static struct platform_driver axienet_driver = { .remove = axienet_remove, .shutdown = axienet_shutdown, .driver = { - .name = "xilinx_axienet", + .name = AXIENET_DRIVER_NAME, .pm = &axienet_pm_ops, .of_match_table = axienet_of_match, }, @@ -3231,6 +3232,13 @@ static struct platform_driver axienet_driver = { module_platform_driver(axienet_driver); +/* The module is named xilinx_emac, the platform driver xilinx_axienet. A + * device registered by name rather than from firmware advertises a + * platform:xilinx_axienet modalias, which without this matches no module: + * udev cannot autoload the driver and the device stays unbound. + */ +MODULE_ALIAS("platform:" AXIENET_DRIVER_NAME); + MODULE_DESCRIPTION("Xilinx Axi Ethernet driver"); MODULE_AUTHOR("Xilinx"); MODULE_LICENSE("GPL"); From ddef4c2d6d07e54816a073c7b5cad7f337fa1251 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 29 Sep 2026 12:15:43 -0700 Subject: [PATCH 1003/2126] net: only give queue leasing devices a separate instance lock class Commit b6f74dff6d26 ("net: use two lockdep classes for the netdev instance lock") put every device without a parent in the virtual class. It also restricted the locking order for the virtual class, because queue leasing has hard requirements on the exact order. This bites us back on bond, which is "virtual" and needs to be taken before taking the locks of the lowers. NIPA hit the following on the new test I recently posted for XDP+bond: WARNING: possible circular locking dependency detected ------------------------------------------------------ python3/18635 is trying to acquire lock: ff11000120b8ce30 (&dev->lock){+.+.}-{4:4}, at: netdev_put_lock+0x2d/0x1a0 but task is already holding lock: ff110001ef77ae30 (&netdev_virt_instance_lock_key){+.+.}-{4:4}, at: netdev_put_lock+0x2d/0x1a0 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (&netdev_virt_instance_lock_key){+.+.}-{4:4}: __mutex_lock+0x1ae/0x1f10 xdp_set_features_flag+0x2b/0x50 bond_xdp_set_features+0x1eb/0x360 bond_netdev_event+0x13f/0x300 notifier_call_chain+0xae/0x300 call_netdevice_notifiers+0x70/0xa0 bnxt_xdp_set+0x2f6/0x620 netif_xdp_propagate+0x503/0xc60 dev_xdp_propagate+0xa1/0x230 bond_xdp_set+0x234/0x700 dev_xdp_install+0x592/0xd70 dev_xdp_attach+0x355/0xf50 dev_change_xdp_fd+0x176/0x210 do_setlink.isra.0+0x220d/0x2b20 rtnl_newlink+0x9f1/0x11b0 -> #0 (&dev->lock){+.+.}-{4:4}: __mutex_lock+0x1ae/0x1f10 netdev_put_lock+0x2d/0x1a0 netdev_nl_queue_create_doit+0x801/0x1a70 genl_family_rcv_msg_doit+0x206/0x300 Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&netdev_virt_instance_lock_key); lock(&dev->lock); lock(&netdev_virt_instance_lock_key); lock(&dev->lock); Let's narrow down the "virtual" class to only the devices which can actually create a queue. More LoC and complexity, but that is what we actually care about here. The rest needs to nest under rtnl_lock, which bond does (famous last words?) Take the instance locks in two passes, first the netkits then the rest (matching the queue leasing order). An alternative would be to make sure the close list is sorted correctly from the start (queue head/tail appropriately in unregister_netdevice_queue()). I think it works but feels a little more fragile. Happy to change, tho. netdev_can_create_queue() will now be used on paths where we genuinely handle non-netkit, so we can't always set the extack. Unfortunately, the (recently) added tracepoint in extack fires even when extack is NULL. Fixes: b6f74dff6d26 ("net: use two lockdep classes for the netdev instance lock") Signed-off-by: Jakub Kicinski Acked-by: Stanislav Fomichev Reviewed-by: Nikolay Aleksandrov Acked-by: Daniel Borkmann Link: https://patch.msgid.link/20260929191543.3295633-1-kuba@kernel.org Signed-off-by: Paolo Abeni --- net/core/dev.c | 48 ++++++++++++++++++++++------------------ net/core/netdev_queues.c | 31 ++++++++++++++------------ 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 79be99b52f20..133e394ef199 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -575,7 +575,7 @@ static int netdev_lock_cmp_fn(const struct lockdep_map *a, if (a == b) return 0; - /* @a and @b must be of same class - both virtual or physical. + /* @a and @b are of same lock class. * cmp_fn won't be called for devices of different classes. * * For the same class only allow nesting under the protection @@ -589,12 +589,13 @@ static int netdev_lock_cmp_fn(const struct lockdep_map *a, * queues from, see netdev_nl_queue_create_doit(). Keep the two kinds * in separate classes so the dependency graph enforces the order; * netdev_lock_cmp_fn() then only has to rule on same-class nesting. + * Other virtual devices stay in the default class. */ void netdev_set_instance_lock_class(struct net_device *dev) { static struct lock_class_key netdev_virt_instance_lock_key; - if (dev->dev.parent) + if (!netdev_can_create_queue(dev, NULL)) return; lockdep_set_class(&dev->lock, &netdev_virt_instance_lock_key); @@ -12462,19 +12463,31 @@ static void netif_close_many_and_unlock(struct list_head *close_head) } } -static void netif_close_many_and_unlock_cond(struct list_head *close_head) +/* Handle one class of ops-locked devices. Since close requires the lock + * we need to be careful about which classes we allow to nest. + */ +static void netdev_lock_ops_close_many(struct list_head *head, + struct list_head *close_head, + bool leasing) { -#ifdef CONFIG_LOCKDEP - /* We can only track up to MAX_LOCK_DEPTH locks per task. - * - * Reserve half the available slots for additional locks possibly - * taken by notifiers and (soft)irqs. - */ - unsigned int limit = MAX_LOCK_DEPTH / 2; + struct net_device *dev; - if (lockdep_depth(current) > limit) - netif_close_many_and_unlock(close_head); + list_for_each_entry(dev, head, unreg_list) { + if (!(dev->flags & IFF_UP) || !netdev_need_ops_lock(dev) || + netdev_can_create_queue(dev, NULL) != leasing) + continue; + list_add_tail(&dev->close_list, close_head); + netdev_lock(dev); + +#ifdef CONFIG_LOCKDEP + /* We can only track up to MAX_LOCK_DEPTH locks per task. + * Reserve half the available slots for additional locks + * possibly taken by notifiers and (soft)irqs. + */ + if (lockdep_depth(current) > MAX_LOCK_DEPTH / 2) + netif_close_many_and_unlock(close_head); #endif + } } bool unregister_netdevice_queued(const struct net_device *dev) @@ -12514,15 +12527,8 @@ void unregister_netdevice_many_notify(struct list_head *head, } /* If device is running, close it first. Start with ops locked... */ - list_for_each_entry(dev, head, unreg_list) { - if (!(dev->flags & IFF_UP)) - continue; - if (netdev_need_ops_lock(dev)) { - list_add_tail(&dev->close_list, &close_head); - netdev_lock(dev); - } - netif_close_many_and_unlock_cond(&close_head); - } + netdev_lock_ops_close_many(head, &close_head, true); /* queue leasing */ + netdev_lock_ops_close_many(head, &close_head, false); /* the rest */ netif_close_many_and_unlock(&close_head); /* ... now go over the rest. */ list_for_each_entry(dev, head, unreg_list) { diff --git a/net/core/netdev_queues.c b/net/core/netdev_queues.c index f5558b12877c..27cb6397bdd4 100644 --- a/net/core/netdev_queues.c +++ b/net/core/netdev_queues.c @@ -61,21 +61,24 @@ struct device *netdev_queue_get_dma_dev(struct net_device *dev, bool netdev_can_create_queue(const struct net_device *dev, struct netlink_ext_ack *extack) { - if (dev->dev.parent) { - NL_SET_ERR_MSG(extack, "Device is not a virtual device"); - return false; - } - if (!dev->queue_mgmt_ops || - !dev->queue_mgmt_ops->ndo_queue_create) { - NL_SET_ERR_MSG(extack, "Device does not support queue creation"); - return false; - } + const char *msg = NULL; + if (dev->real_num_rx_queues < 1 || - dev->real_num_tx_queues < 1) { - NL_SET_ERR_MSG(extack, "Device must have at least one real queue"); - return false; - } - return true; + dev->real_num_tx_queues < 1) + msg = "Device must have at least one real queue"; + if (!dev->queue_mgmt_ops || + !dev->queue_mgmt_ops->ndo_queue_create) + msg = "Device does not support queue creation"; + if (dev->dev.parent) + msg = "Device is not a virtual device"; + + /* callers with extack=NULL are not from uAPI and don't want to trigger + * the extack tracepoint. + */ + if (msg && extack) + NL_SET_ERR_MSG_FMT(extack, "%s", msg); + + return !msg; } bool netdev_can_lease_queue(const struct net_device *dev, From f9cb4d296d81adb0923546ca5d54fae57a81af52 Mon Sep 17 00:00:00 2001 From: Yuya Kusakabe Date: Sat, 26 Sep 2026 20:19:27 +0900 Subject: [PATCH 1004/2126] seg6: fix HMAC validation when an extension header precedes the SRH seg6_hmac_validate_skb() derived the SRH from skb_transport_header(). That only holds while the two coincide, which is not true on the seg6_local input path. ip6_rcv_core() leaves the transport header just past the IPv6 header. A Hop-by-Hop options header is consumed before the route lookup and advances it, but a Destination Options header is not: the seg6_local lwtunnel is entered through an input redirect from the route lookup, which bypasses the extension header handlers. The transport header then still points at the Destination Options header while seg6_get_srh() has located the real SRH further down the chain. The HMAC is therefore computed over the Destination Options header, and a packet carrying a valid HMAC TLV is dropped when seg6_require_hmac is set. Such a packet is legitimate: RFC 8200 allows Destination Options before a routing header, and get_srh() has walked the header chain since commit 5829d70b0b6c ("ipv6: sr: fix get_srh() to comply with IPv6 standard "RFC 8200""). With a Fragment or an Authentication header in front of the SRH, the same mistake also reads past the data pulled by seg6_get_srh(). This happens before seg6_require_hmac is read, so the default configuration is affected. Reproduce by giving a node a seg6local End SID with net.ipv6.conf..seg6_require_hmac=1 and a key installed with "ip sr hmac set sha1", then sending IPv6 -> Destination Options -> SRH (carrying a valid HMAC TLV) -> payload to that SID: it is dropped, while the same packet without the Destination Options header passes. Fixes: 5829d70b0b6c ("ipv6: sr: fix get_srh() to comply with IPv6 standard "RFC 8200"") Assisted-by: LLM Signed-off-by: Yuya Kusakabe Reviewed-by: Andrea Mayer Link: https://patch.msgid.link/20260926-b4-seg6-hmac-transport-header-v2-1-8087b76f6375@gmail.com Signed-off-by: Paolo Abeni --- include/net/seg6_hmac.h | 3 ++- net/ipv6/exthdrs.c | 2 +- net/ipv6/seg6_hmac.c | 5 +---- net/ipv6/seg6_local.c | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/net/seg6_hmac.h b/include/net/seg6_hmac.h index e9f41725933e..3161a8104b89 100644 --- a/include/net/seg6_hmac.h +++ b/include/net/seg6_hmac.h @@ -48,7 +48,8 @@ extern int seg6_hmac_info_add(struct net *net, u32 key, extern int seg6_hmac_info_del(struct net *net, u32 key); extern int seg6_push_hmac(struct net *net, struct in6_addr *saddr, struct ipv6_sr_hdr *srh); -extern bool seg6_hmac_validate_skb(struct sk_buff *skb); +extern bool seg6_hmac_validate_skb(struct sk_buff *skb, + struct ipv6_sr_hdr *srh); #ifdef CONFIG_IPV6_SEG6_HMAC extern int seg6_hmac_net_init(struct net *net); extern void seg6_hmac_net_exit(struct net *net); diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 55391e2e5612..96c8402a27a5 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -387,7 +387,7 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev) } #ifdef CONFIG_IPV6_SEG6_HMAC - if (!seg6_hmac_validate_skb(skb)) { + if (!seg6_hmac_validate_skb(skb, hdr)) { kfree_skb(skb); return -1; } diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c index e6964c6b0d38..bd2704d4c7a0 100644 --- a/net/ipv6/seg6_hmac.c +++ b/net/ipv6/seg6_hmac.c @@ -173,13 +173,12 @@ EXPORT_SYMBOL(seg6_hmac_compute); * * called with rcu_read_lock() */ -bool seg6_hmac_validate_skb(struct sk_buff *skb) +bool seg6_hmac_validate_skb(struct sk_buff *skb, struct ipv6_sr_hdr *srh) { u8 hmac_output[SEG6_HMAC_FIELD_LEN]; struct net *net = dev_net(skb->dev); struct seg6_hmac_info *hinfo; struct sr6_tlv_hmac *tlv; - struct ipv6_sr_hdr *srh; struct inet6_dev *idev; int require_hmac; @@ -187,8 +186,6 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb) if (!idev) return false; - srh = (struct ipv6_sr_hdr *)skb_transport_header(skb); - tlv = seg6_get_tlv_hmac(srh); require_hmac = READ_ONCE(idev->cnf.seg6_require_hmac); diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index d1070aec7b72..67eeb27ee43a 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -222,7 +222,7 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb) return NULL; #ifdef CONFIG_IPV6_SEG6_HMAC - if (!seg6_hmac_validate_skb(skb)) + if (!seg6_hmac_validate_skb(skb, srh)) return NULL; #endif @@ -239,7 +239,7 @@ static bool decap_and_validate(struct sk_buff *skb, int proto) return false; #ifdef CONFIG_IPV6_SEG6_HMAC - if (srh && !seg6_hmac_validate_skb(skb)) + if (srh && !seg6_hmac_validate_skb(skb, srh)) return false; #endif @@ -771,7 +771,7 @@ static int end_flv8986_core(struct sk_buff *skb, struct seg6_local_lwt *slwt) srhoff = srh ? ((unsigned char *)srh - skb->data) : 0; pinfo = seg6_get_srh_pktinfo(srh); #ifdef CONFIG_IPV6_SEG6_HMAC - if (srh && !seg6_hmac_validate_skb(skb)) + if (srh && !seg6_hmac_validate_skb(skb, srh)) goto drop; #endif flvmask = finfo->flv_ops; From eb0c18404c8943356f4aa164e5db9067b79ea93c Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Mon, 28 Sep 2026 21:15:57 +0300 Subject: [PATCH 1005/2126] amt: pull the AMT header behind the transport header in amt_parse_type() A gateway's encap socket passes ICMP errors to amt_err_lookup(), which calls amt_parse_type() on the quoted datagram to see which AMT message failed. On that path skb->data points at the quoted IP header and the transport header at the quoted UDP header, and icmp_socket_deliver() only guarantees the quoted IP header plus 8 bytes, that is, up to the end of the UDP header. amt_parse_type() pulls sizeof(struct udphdr) + sizeof(struct amt_header) bytes from skb->data, which on this path stays inside the quoted IP header, and then reads the AMT header behind udp_hdr(skb). An ICMP error that quotes only the IP and UDP headers of a Request, the minimum RFC 792 asks for, therefore makes it read past the pulled data, and past the end of the packet when nothing follows. Pull up to the transport header plus the UDP and AMT headers, as vxlan_err_lookup() does. amt_rcv() is called with the transport header at skb->data, so the pull on the receive path does not change. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Omar Ramadan Reviewed-by: Eric Dumazet Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260928181557.85796-1-omar@blockcast.net Signed-off-by: Paolo Abeni --- drivers/net/amt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index bddc24e1856d..0277e4cac39b 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -1310,8 +1310,12 @@ static int amt_parse_type(struct sk_buff *skb) { struct amt_header *amth; - if (!pskb_may_pull(skb, sizeof(struct udphdr) + - sizeof(struct amt_header))) + /* skb->data is the UDP header on receive, but the quoted IP header + * when amt_err_lookup() parses an ICMP error, so pull up to the + * transport header rather than from skb->data. + */ + if (!pskb_may_pull(skb, skb_transport_offset(skb) + + sizeof(struct udphdr) + sizeof(struct amt_header))) return -1; amth = (struct amt_header *)(udp_hdr(skb) + 1); From 526025d552baf36b6dcb348fd8ec1287063e44f5 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Mon, 28 Sep 2026 13:22:45 +0200 Subject: [PATCH 1006/2126] dpaa2-eth: use the DPMAC id as the devlink physical port number dpaa2-eth registers every DPNI as a devlink port of flavour physical without setting a port number. All DPAA2 interfaces report the same phys_port_name, p0 (see devlink port show). The DPNI endpoint can change at runtime while the attributes of a registered devlink port cannot, so log a warning when it happens. Another benefit: udev rules can match ATTR{phys_port_name} to name an interface based on its DPMAC. Signed-off-by: Vincent Jardin Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-for-upstream-dpaa2_ports-v2-1-1cda148530bf@free.fr Signed-off-by: Jakub Kicinski --- .../freescale/dpaa2/dpaa2-eth-devlink.c | 40 ++++++++++++++++++- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 2 + .../net/ethernet/freescale/dpaa2/dpaa2-eth.h | 3 ++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c index 8775c931106b..4c0a04c2d458 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c @@ -213,20 +213,58 @@ void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv) devlink_unregister(priv->devlink); } +static u32 dpaa2_eth_dl_port_number(struct dpaa2_eth_priv *priv) +{ + lockdep_assert_held(&priv->mac_lock); + + return dpaa2_eth_has_mac(priv) ? priv->mac->mc_dev->obj_desc.id : 0; +} + int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv) { struct devlink_port *devlink_port = &priv->devlink_port; struct devlink_port_attrs attrs = {}; + u32 port_number; + int err; + + mutex_lock(&priv->mac_lock); + port_number = dpaa2_eth_dl_port_number(priv); + priv->dl_port_number = port_number; + priv->dl_port_valid = true; + mutex_unlock(&priv->mac_lock); attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; + attrs.phys.port_number = port_number; devlink_port_attrs_set(devlink_port, &attrs); - return devlink_port_register(priv->devlink, devlink_port, 0); + err = devlink_port_register(priv->devlink, devlink_port, 0); + if (err) { + mutex_lock(&priv->mac_lock); + priv->dl_port_valid = false; + mutex_unlock(&priv->mac_lock); + } + + return err; +} + +void dpaa2_eth_dl_port_check(struct dpaa2_eth_priv *priv) +{ + mutex_lock(&priv->mac_lock); + if (priv->dl_port_valid && + priv->dl_port_number != dpaa2_eth_dl_port_number(priv)) + netdev_warn(priv->net_dev, + "devlink port number %u is stale, rebind to update\n", + priv->dl_port_number); + mutex_unlock(&priv->mac_lock); } void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv) { struct devlink_port *devlink_port = &priv->devlink_port; + mutex_lock(&priv->mac_lock); + priv->dl_port_valid = false; + mutex_unlock(&priv->mac_lock); + devlink_port_unregister(devlink_port); } diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 6f1046c9cc51..def2d5c0e7f7 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -4771,6 +4771,8 @@ static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg) dpaa2_eth_disconnect_mac(priv); else dpaa2_eth_connect_mac(priv); + + dpaa2_eth_dl_port_check(priv); } return IRQ_HANDLED; diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h index 834cba8c3a41..3e0acd15549e 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h @@ -632,6 +632,8 @@ struct dpaa2_eth_priv { struct devlink *devlink; struct dpaa2_eth_trap_data *trap_data; struct devlink_port devlink_port; + u32 dl_port_number; + bool dl_port_valid; u32 rx_copybreak; @@ -802,6 +804,7 @@ void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv); int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv); void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv); +void dpaa2_eth_dl_port_check(struct dpaa2_eth_priv *priv); int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv); void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv); From aed5a323ec37af3ff230b7cf16045a44136aded3 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Mon, 28 Sep 2026 13:22:46 +0200 Subject: [PATCH 1007/2126] dpaa2-eth: mark DPNIs without a DPMAC as virtual devlink ports A DPNI whose endpoint is not a DPMAC has no physical connector: it may have no endpoint at all, or be connected to another DPNI or to a DPSW port. Until now, such a DPNI was still registered as a physical devlink port with number 0, so userspace saw a physical port that does not exist. Register these DPNIs as virtual devlink ports instead. A virtual port has no phys_port_name, so only the DPNIs that serve a DPMAC at probe time report one, "p", and those names do not collide. Signed-off-by: Vincent Jardin Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-for-upstream-dpaa2_ports-v2-2-1cda148530bf@free.fr Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c index 4c0a04c2d458..6defc00199bf 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c @@ -233,7 +233,10 @@ int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv) priv->dl_port_valid = true; mutex_unlock(&priv->mac_lock); - attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; + if (port_number) + attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; + else + attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL; attrs.phys.port_number = port_number; devlink_port_attrs_set(devlink_port, &attrs); err = devlink_port_register(priv->devlink, devlink_port, 0); From c7fca8aae6fe944493fd6a8ed3316b0fb673f7a7 Mon Sep 17 00:00:00 2001 From: Allison Henderson Date: Sat, 26 Sep 2026 23:30:57 -0700 Subject: [PATCH 1008/2126] net/rds: restrict the rdma_cm ids to IB devices RDS only has an IB transport, but it never tells the rdma_cm so. The listener created in rds_rdma_listen_init() is therefore installed on every RDMA device in the system, including iWARP RNICs, and the id an outgoing connection resolves through in rds_ib_conn_path_connect() may be bound to whichever device the address resolution picks: rds_ib_laddr_check() only vouched for the local address being served by one of RDS's IB devices, while cma_acquire_dev_by_src_ip() walks every RDMA device for the same address, so a software iWARP device attached to the same netdev can win. The event handler then runs the IB transport's callbacks against a device that is not one. The rdma_cm has an API for exactly this since commit a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()"). Restrict all three ids RDS creates - the listener, the per-connection id and the probe id in rds_ib_laddr_check_cm() - to RDMA_NODE_IB_CA before they are bound, so that the listener is only installed on IB devices, an outgoing connection can only bind one, and the address check's bind fails outright on anything else - which makes its explicit node_type test dead, so it goes; the check that the bind produced a device at all stays. With that, no rdma_cm event reaches RDS's handler from a device it has no transport for. The handler itself still assumes IB: it assigns its transport pointer only for RDMA_NODE_IB_CA and dereferences it regardless, which is the crash that first surfaced this. The fix for that is a separate net patch, Aohan Mei's "net: rds: fix uninitialized trans dereference in CM event handler", and is what stable kernels without rdma_restrict_node_type() - which arrived in commit a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()") - have to take: this patch depends on that API, so stable trees need that separate, minimal fix rather than a backport of this one. The two patches are independent and apply in either order. The listener has been on every RDMA device since the iWARP transport was removed and left the ids unrestricted, hence the Fixes tag. Signed-off-by: Allison Henderson Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260927063058.170273-2-achender@kernel.org Signed-off-by: Jakub Kicinski --- net/rds/ib.c | 14 ++++++-------- net/rds/ib_cm.c | 12 ++++++++++++ net/rds/rdma_transport.c | 8 ++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/net/rds/ib.c b/net/rds/ib.c index 786f39169bc1..4ea9838d090c 100644 --- a/net/rds/ib.c +++ b/net/rds/ib.c @@ -414,13 +414,14 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr, bool isv4; isv4 = ipv6_addr_v4mapped(addr); - /* Create a CMA ID and try to bind it. This catches both - * IB and iWARP capable NICs. - */ + /* Create a CMA ID restricted to IB devices and try to bind it. */ cm_id = rdma_create_id(&init_net, rds_rdma_cm_event_handler, NULL, RDMA_PS_TCP, IB_QPT_RC); if (IS_ERR(cm_id)) return PTR_ERR(cm_id); + ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA); + if (ret) + goto out; if (isv4) { memset(&sin, 0, sizeof(sin)); @@ -473,12 +474,9 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr, #endif } - /* rdma_bind_addr will only succeed for IB & iWARP devices */ + /* the restriction above means this only succeeds for IB devices */ ret = rdma_bind_addr(cm_id, sa); - /* due to this, we will claim to support iWARP devices unless we - check node_type. */ - if (ret || !cm_id->device || - cm_id->device->node_type != RDMA_NODE_IB_CA) + if (ret || !cm_id->device) ret = -EADDRNOTAVAIL; rdsdebug("addr %pI6c%%%u ret %d node type %d\n", diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c index 3ebe13d00953..3ed03ad32812 100644 --- a/net/rds/ib_cm.c +++ b/net/rds/ib_cm.c @@ -999,6 +999,18 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp) goto out; } + /* rds_ib_laddr_check() only vouched for the local address being + * on an IB device; the address resolution below picks the device + * on its own, so restrict it to the same kind. + */ + ret = rdma_restrict_node_type(ic->i_cm_id, RDMA_NODE_IB_CA); + if (ret) { + rdsdebug("rdma_restrict_node_type() failed: %d\n", ret); + rdma_destroy_id(ic->i_cm_id); + ic->i_cm_id = NULL; + goto out; + } + rdsdebug("created cm id %p for conn %p\n", ic->i_cm_id, conn); if (ipv6_addr_v4mapped(&conn->c_faddr)) { diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c index b15cf316b23a..91ff1dde26af 100644 --- a/net/rds/rdma_transport.c +++ b/net/rds/rdma_transport.c @@ -210,6 +210,14 @@ static int rds_rdma_listen_init_common(rdma_cm_event_handler handler, return ret; } + /* Only the IB transport is left, so only listen on IB devices */ + ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA); + if (ret) { + pr_err("RDS/RDMA: failed to setup listener, rdma_restrict_node_type() returned %d\n", + ret); + goto out; + } + /* * XXX I bet this binds the cm_id to a device. If we want to support * fail-over we'll have to take this into consideration. From 00d77b18186637646ac71a0c9e7e74931d3a180d Mon Sep 17 00:00:00 2001 From: Allison Henderson Date: Sat, 26 Sep 2026 23:30:58 -0700 Subject: [PATCH 1009/2126] net/rds: log the port a listener actually bound rds_rdma_listen_init_common() reports every listener as being on RDS_PORT, but only the IPv4 caller binds that port; the IPv6 listener is bound to RDS_CM_PORT, as rds_rdma_listen_init() explains, and its debug line has claimed 18634 instead of 16385 since it was added. Print the port from the address the helper just bound. Signed-off-by: Allison Henderson Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260927063058.170273-3-achender@kernel.org Signed-off-by: Jakub Kicinski --- net/rds/rdma_transport.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c index 91ff1dde26af..3f853004c490 100644 --- a/net/rds/rdma_transport.c +++ b/net/rds/rdma_transport.c @@ -236,7 +236,10 @@ static int rds_rdma_listen_init_common(rdma_cm_event_handler handler, goto out; } - rdsdebug("cm %p listening on port %u\n", cm_id, RDS_PORT); + rdsdebug("cm %p listening on port %u\n", cm_id, + ntohs(sa->sa_family == AF_INET6 ? + ((struct sockaddr_in6 *)sa)->sin6_port : + ((struct sockaddr_in *)sa)->sin_port)); *ret_cm_id = cm_id; cm_id = NULL; From 264f8ac8ec51b4c1adbf29fd333b4eb5abc569b9 Mon Sep 17 00:00:00 2001 From: Xinsheng Zhu Date: Mon, 28 Sep 2026 15:21:19 -0400 Subject: [PATCH 1010/2126] net: usb: asix: remove redundant PHY address short-read check Short-read handling was added to asix_read_cmd() by commit 920a9fa27e78 ("net: asix: add proper error handling of usb read errors"). The helper converts short reads to -ENODATA while preserving negative errors from the underlying USB read operation. Remove the redundant short-read check in asix_read_phy_addr() and its unreachable -EIO assignment. The existing negative-return check handles both short reads and underlying USB read errors. Signed-off-by: Xinsheng Zhu Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928192119.73351-1-xinsheng.zhu.ny@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/asix_common.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c index 4f03f4e57655..51bf887e3520 100644 --- a/drivers/net/usb/asix_common.c +++ b/drivers/net/usb/asix_common.c @@ -327,11 +327,6 @@ int asix_read_phy_addr(struct usbnet *dev, bool internal) if (ret < 0) goto error; - if (ret < 2) { - ret = -EIO; - goto error; - } - offset = (internal ? 1 : 0); ret = buf[offset]; From bbafd2f4b3548afa8c67267f9e8ba8ffef1323b9 Mon Sep 17 00:00:00 2001 From: Ayush Yaduvanshi Date: Tue, 29 Sep 2026 15:36:24 +0530 Subject: [PATCH 1011/2126] sfc: fix kernel-doc description for efx_ptp_timeset Remove excess @valid struct member description from efx_ptp_timeset. Signed-off-by: Ayush Yaduvanshi Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260929094211.48125-1-ayush37735@gmail.com Link: https://patch.msgid.link/20260929100625.50380-1-ayush37735@gmail.com [Jakub: squash with the siena patch] Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/sfc/ptp.c | 1 - drivers/net/ethernet/sfc/siena/ptp.c | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index 6ca9a75af01d..00cfd8d5b46e 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c @@ -193,7 +193,6 @@ struct efx_ptp_event_rx { * @wait: Number of NIC clock ticks between hardware timestamp being read and * host end time being seen * @window: Difference of host_end and host_start - * @valid: Whether this timeset is valid */ struct efx_ptp_timeset { u32 host_start; diff --git a/drivers/net/ethernet/sfc/siena/ptp.c b/drivers/net/ethernet/sfc/siena/ptp.c index 0b723a127364..d643e41ae773 100644 --- a/drivers/net/ethernet/sfc/siena/ptp.c +++ b/drivers/net/ethernet/sfc/siena/ptp.c @@ -196,7 +196,6 @@ struct efx_ptp_event_rx { * @wait: Number of NIC clock ticks between hardware timestamp being read and * host end time being seen * @window: Difference of host_end and host_start - * @valid: Whether this timeset is valid */ struct efx_ptp_timeset { u32 host_start; From 29b635a5bb8aca70d16e9e1f5f7a039198b6dec2 Mon Sep 17 00:00:00 2001 From: Ayush Yaduvanshi Date: Tue, 29 Sep 2026 15:47:13 +0530 Subject: [PATCH 1012/2126] atlx: fix kernel-doc description for atlx_tx_timeout Add missing @txqueue parameter description to atlx_tx_timeout to eliminate kernel-doc warning. Signed-off-by: Ayush Yaduvanshi Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260929101714.51579-1-ayush37735@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/atheros/atlx/atlx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/atheros/atlx/atlx.c b/drivers/net/ethernet/atheros/atlx/atlx.c index e8cfbf4ff1b5..0a6205e5c19d 100644 --- a/drivers/net/ethernet/atheros/atlx/atlx.c +++ b/drivers/net/ethernet/atheros/atlx/atlx.c @@ -182,6 +182,7 @@ static void atlx_clear_phy_int(struct atlx_adapter *adapter) /** * atlx_tx_timeout - Respond to a Tx Hang * @netdev: network interface device structure + * @txqueue: transmit queue index */ static void atlx_tx_timeout(struct net_device *netdev, unsigned int txqueue) { From ffa16b43078a90a43beebdf4fe8d4166665cf6cf Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Tue, 29 Sep 2026 10:06:40 +0800 Subject: [PATCH 1013/2126] selftests: net: move log_test to lib file and remove duplicate code Many test scripts under tools/testing/selftests/net/ each define their own log_test() function with near-identical logic for comparing a return code against an expected value and printing OK/FAIL. Add a shared log_test_expected() to lib.sh so we can replace each local definitions. The function is named log_test_expected() rather than log_test() because lib.sh already exports log_test() with a different signature used by the forwarding tests. Most of the checks in log_test_expected() are the same as log_test() in other tests. The differences are: - The function always returns 0 to avoid influencing later code. - On failure with VERBOSE=1, the actual and expected return codes are printed (echo " rc=$rc, expected $expected"). - A PAUSE_ON_FAIL check is added via pause_on_fail() for scripts that did not have one. - A PAUSE=yes check is added for scripts that did not have one. - A trailing [ "$VERBOSE" = "1" ] && echo is added for scripts that did not have one. Several tests required special handling: - fcnal-test.sh - Print format: it uses %-70s, while log_test_expected() uses %-60s. - The old code always printed "expected rc $expected; actual rc $rc" on failure. The new code only prints when VERBOSE=1. - The old [ "${VERBOSE}" = "1" ] && echo ran before the comparison; now it runs after the PAUSE check. - fdb_flush.sh - It used local ret, nsuccess, and nfail, which are not used outside the function. The log_test_expected() uses global variables as all other tests do. - fib-onlink-tests.sh - Print format: it uses %-50s, while log_test_expected() uses %-60s. - srv6_end_dx*.sh and srv6_end_flavors_test.sh - These three tests previously defined ksft_skip locally instead of sourcing lib.sh. They now source lib.sh, which provides ksft_skip and other framework constants. Note that srv6_end_flavors_test.sh previously declared ksft_skip as readonly; the lib.sh definition does not use readonly. - test_bridge_neigh_suppress.sh - The test use ksft_exit_status_merge "$ret" "$ksft_fail", which always set ret=1 as ksft_fail has the maximum weight. So in the lib we just discarded ksft_exit_status_merge and set ret to 1 directly. In addition to the above, 12 tests that previously used "TEST:" now use " TEST:" (4-space prefix), and srv6 tests plus vrf_strict_mode_test.sh that previously used "\n TEST:" (newline + 4-space prefix) now with no leading newline. The fib_nexthops.sh test is skipped because it has a ksft_skip check that needs special handling. Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20260929-self_log_test-v6-1-41199262e50b@kylinos.cn Signed-off-by: Jakub Kicinski --- .../selftests/net/drop_monitor_tests.sh | 13 +------ tools/testing/selftests/net/fcnal-test.sh | 29 +-------------- tools/testing/selftests/net/fdb_flush.sh | 35 +------------------ .../testing/selftests/net/fib-onlink-tests.sh | 18 +--------- .../selftests/net/fib_nexthop_multiprefix.sh | 21 +---------- .../selftests/net/fib_nexthop_nongw.sh | 21 +---------- tools/testing/selftests/net/fib_rule_tests.sh | 19 +--------- tools/testing/selftests/net/fib_tests.sh | 26 +------------- tools/testing/selftests/net/gre_gso.sh | 26 +------------- tools/testing/selftests/net/icmp_redirect.sh | 19 +--------- tools/testing/selftests/net/l2tp.sh | 19 +--------- tools/testing/selftests/net/lib.sh | 34 ++++++++++++++++++ .../net/ndisc_unsolicited_na_test.sh | 26 +------------- .../net/srv6_encap_lookup_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt46_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt4_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt6_l3vpn_test.sh | 19 +--------- .../net/srv6_end_dx4_netfilter_test.sh | 23 ++---------- .../net/srv6_end_dx6_netfilter_test.sh | 23 ++---------- .../selftests/net/srv6_end_flavors_test.sh | 23 ++---------- .../net/srv6_end_next_csid_l3vpn_test.sh | 19 +--------- .../net/srv6_end_x_next_csid_l3vpn_test.sh | 19 +--------- .../net/srv6_hencap_red_l3vpn_test.sh | 19 +--------- .../net/srv6_hl2encap_red_l2vpn_test.sh | 19 +--------- .../selftests/net/test_bridge_backup_port.sh | 32 +---------------- .../net/test_bridge_neigh_suppress.sh | 34 +----------------- tools/testing/selftests/net/test_vxlan_mdb.sh | 32 +---------------- .../selftests/net/test_vxlan_nolocalbypass.sh | 32 +---------------- .../selftests/net/test_vxlan_vnifiltering.sh | 26 +------------- tools/testing/selftests/net/vrf-xfrm-tests.sh | 19 +--------- .../selftests/net/vrf_route_leaking.sh | 19 +--------- .../selftests/net/vrf_strict_mode_test.sh | 19 +--------- 32 files changed, 71 insertions(+), 669 deletions(-) diff --git a/tools/testing/selftests/net/drop_monitor_tests.sh b/tools/testing/selftests/net/drop_monitor_tests.sh index 507d0a82f5f0..7da85608561b 100755 --- a/tools/testing/selftests/net/drop_monitor_tests.sh +++ b/tools/testing/selftests/net/drop_monitor_tests.sh @@ -18,18 +18,7 @@ DEVLINK_DEV=netdevsim/${DEV} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - fi + log_test_expected "$1" "$2" "$3" } setup() diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh index 890c3f8e51bb..a50609535fed 100755 --- a/tools/testing/selftests/net/fcnal-test.sh +++ b/tools/testing/selftests/net/fcnal-test.sh @@ -97,34 +97,7 @@ fi log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - local ans - - [ "${VERBOSE}" = "1" ] && echo - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "TEST: %-70s [ OK ]\n" "${msg}" - else - nfail=$((nfail+1)) - printf "TEST: %-70s [FAIL]\n" "${msg}" - echo " expected rc $expected; actual rc $rc" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read ans - [ "$ans" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read ans - [ "$ans" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" kill_procs } diff --git a/tools/testing/selftests/net/fdb_flush.sh b/tools/testing/selftests/net/fdb_flush.sh index 9931a1e36e3d..4965e52d5ef5 100755 --- a/tools/testing/selftests/net/fdb_flush.sh +++ b/tools/testing/selftests/net/fdb_flush.sh @@ -67,40 +67,7 @@ run_cmd() log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - local nsuccess - local nfail - local ret - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } MAC_POOL_1=" diff --git a/tools/testing/selftests/net/fib-onlink-tests.sh b/tools/testing/selftests/net/fib-onlink-tests.sh index e0d45292a298..a26075abf7d2 100755 --- a/tools/testing/selftests/net/fib-onlink-tests.sh +++ b/tools/testing/selftests/net/fib-onlink-tests.sh @@ -85,23 +85,7 @@ PBR_TABLE=101 log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf " TEST: %-50s [ OK ]\n" "${msg}" - else - nfail=$((nfail+1)) - printf " TEST: %-50s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } log_section() diff --git a/tools/testing/selftests/net/fib_nexthop_multiprefix.sh b/tools/testing/selftests/net/fib_nexthop_multiprefix.sh index e85248609af4..bd0b8a053ea1 100755 --- a/tools/testing/selftests/net/fib_nexthop_multiprefix.sh +++ b/tools/testing/selftests/net/fib_nexthop_multiprefix.sh @@ -23,26 +23,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/fib_nexthop_nongw.sh b/tools/testing/selftests/net/fib_nexthop_nongw.sh index 1ccf56f10171..4d483cb83593 100755 --- a/tools/testing/selftests/net/fib_nexthop_nongw.sh +++ b/tools/testing/selftests/net/fib_nexthop_nongw.sh @@ -18,26 +18,7 @@ ret=0 log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/fib_rule_tests.sh b/tools/testing/selftests/net/fib_rule_tests.sh index 5fbdd2a0b537..5d66b00e61b2 100755 --- a/tools/testing/selftests/net/fib_rule_tests.sh +++ b/tools/testing/selftests/net/fib_rule_tests.sh @@ -31,24 +31,7 @@ SELFTEST_PATH="" log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf " TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } setup() diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index b338bfb196a2..7df967a2d669 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -24,31 +24,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } setup() diff --git a/tools/testing/selftests/net/gre_gso.sh b/tools/testing/selftests/net/gre_gso.sh index 5100d90f92d2..4ebe1ed6e9c9 100755 --- a/tools/testing/selftests/net/gre_gso.sh +++ b/tools/testing/selftests/net/gre_gso.sh @@ -16,31 +16,7 @@ PID= log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } setup() diff --git a/tools/testing/selftests/net/icmp_redirect.sh b/tools/testing/selftests/net/icmp_redirect.sh index 35357d02e823..e724f895ae2c 100755 --- a/tools/testing/selftests/net/icmp_redirect.sh +++ b/tools/testing/selftests/net/icmp_redirect.sh @@ -61,24 +61,7 @@ log_section() log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } log_debug() diff --git a/tools/testing/selftests/net/l2tp.sh b/tools/testing/selftests/net/l2tp.sh index 88de7166c8ae..41e8b19d1bd3 100755 --- a/tools/testing/selftests/net/l2tp.sh +++ b/tools/testing/selftests/net/l2tp.sh @@ -23,24 +23,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) # log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh index d46d2cec89e4..72a0b870f81f 100644 --- a/tools/testing/selftests/net/lib.sh +++ b/tools/testing/selftests/net/lib.sh @@ -454,6 +454,40 @@ log_test_xfail() RET=$ksft_xfail retmsg= log_test "$@" } +# Log test result with expected return value +log_test_expected() +{ + local rc=$1 + local expected=$2 + local msg="$3" + local a + + if [ "${rc}" -eq "${expected}" ]; then + nsuccess=$((nsuccess+1)) + printf " TEST: %-60s [ OK ]\n" "${msg}" + else + ret="$ksft_fail" + nfail=$((nfail+1)) + printf " TEST: %-60s [FAIL]\n" "${msg}" + if [ "$VERBOSE" = "1" ]; then + echo " rc=$rc, expected $expected" + fi + + pause_on_fail || true + fi + + if [ "${PAUSE}" = "yes" ]; then + echo + echo "hit enter to continue, 'q' to quit" + read -r a + [ "$a" = "q" ] && exit 1 + fi + + [ "$VERBOSE" = "1" ] && echo + + return 0 +} + log_info() { local msg=$1 diff --git a/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh b/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh index ba9e670b5149..6e63a5eb1ebb 100755 --- a/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh +++ b/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh @@ -40,31 +40,7 @@ tcpdump_pid= log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } setup() diff --git a/tools/testing/selftests/net/srv6_encap_lookup_l3vpn_test.sh b/tools/testing/selftests/net/srv6_encap_lookup_l3vpn_test.sh index d6249303b7ea..8241de6827de 100755 --- a/tools/testing/selftests/net/srv6_encap_lookup_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_encap_lookup_l3vpn_test.sh @@ -202,24 +202,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read -r a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh index 50e37d3217ea..900a2ae42335 100755 --- a/tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh @@ -208,24 +208,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh index 037e5fe1da2a..260170dc8443 100755 --- a/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh @@ -177,24 +177,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh index 9a29e0d6c912..6d4d6a23ecc4 100755 --- a/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh @@ -178,24 +178,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh b/tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh index e23210aa547f..aeddbef536d6 100755 --- a/tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh +++ b/tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh @@ -111,8 +111,8 @@ # +---------------------------------------------------+ # -# Kselftest framework requirement - SKIP code is 4. -ksft_skip=4 +# shellcheck source=lib.sh +source lib.sh readonly IPv6_RT_NETWORK=2001:11 readonly IPv4_HS_NETWORK=10.0.0 @@ -126,24 +126,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh b/tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh index 9e69a2ed5bc3..8fbeda1372e1 100755 --- a/tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh +++ b/tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh @@ -111,8 +111,8 @@ # +---------------------------------------------------+ # -# Kselftest framework requirement - SKIP code is 4. -ksft_skip=4 +# shellcheck source=lib.sh +source lib.sh readonly IPv6_RT_NETWORK=2001:11 readonly IPv6_HS_NETWORK=cafe @@ -126,24 +126,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_flavors_test.sh b/tools/testing/selftests/net/srv6_end_flavors_test.sh index 318487eda671..30a939392eea 100755 --- a/tools/testing/selftests/net/srv6_end_flavors_test.sh +++ b/tools/testing/selftests/net/srv6_end_flavors_test.sh @@ -194,8 +194,8 @@ # after the IPv6 header. At this point, the packet with IPv6 DA=cafe::1 is sent # to the destination, i.e. hs-1. -# Kselftest framework requirement - SKIP code is 4. -readonly ksft_skip=4 +# shellcheck source=lib.sh +source lib.sh readonly RDMSUFF="$(mktemp -u XXXXXXXX)" readonly DUMMY_DEVNAME="dum0" @@ -224,24 +224,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_next_csid_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_next_csid_l3vpn_test.sh index 4bc135e5c22c..2e2ae21974ae 100755 --- a/tools/testing/selftests/net/srv6_end_next_csid_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_next_csid_l3vpn_test.sh @@ -323,24 +323,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh b/tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh index 34b781a2ae74..b492a7f0297f 100755 --- a/tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh @@ -368,24 +368,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_hencap_red_l3vpn_test.sh b/tools/testing/selftests/net/srv6_hencap_red_l3vpn_test.sh index cd7d061e21f8..64ea4e2308b6 100755 --- a/tools/testing/selftests/net/srv6_hencap_red_l3vpn_test.sh +++ b/tools/testing/selftests/net/srv6_hencap_red_l3vpn_test.sh @@ -197,24 +197,7 @@ HAS_TUNSRC=false log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/srv6_hl2encap_red_l2vpn_test.sh b/tools/testing/selftests/net/srv6_hl2encap_red_l2vpn_test.sh index 0979b5316fdf..31e41cc4922e 100755 --- a/tools/testing/selftests/net/srv6_hl2encap_red_l2vpn_test.sh +++ b/tools/testing/selftests/net/srv6_hl2encap_red_l2vpn_test.sh @@ -146,24 +146,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() diff --git a/tools/testing/selftests/net/test_bridge_backup_port.sh b/tools/testing/selftests/net/test_bridge_backup_port.sh index 2a7224fe74f2..8bc76be2b2d3 100755 --- a/tools/testing/selftests/net/test_bridge_backup_port.sh +++ b/tools/testing/selftests/net/test_bridge_backup_port.sh @@ -56,37 +56,7 @@ PING_TIMEOUT=5 log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/test_bridge_neigh_suppress.sh b/tools/testing/selftests/net/test_bridge_neigh_suppress.sh index e9ed0d750996..9d2dc0faf741 100755 --- a/tools/testing/selftests/net/test_bridge_neigh_suppress.sh +++ b/tools/testing/selftests/net/test_bridge_neigh_suppress.sh @@ -72,39 +72,7 @@ PAUSE=no log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - # shellcheck disable=SC2154 - ret=$(ksft_exit_status_merge "$ret" "$ksft_fail") - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo - return 0 + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/test_vxlan_mdb.sh b/tools/testing/selftests/net/test_vxlan_mdb.sh index f9600aabd4a2..2ebb4d8a3026 100755 --- a/tools/testing/selftests/net/test_vxlan_mdb.sh +++ b/tools/testing/selftests/net/test_vxlan_mdb.sh @@ -133,37 +133,7 @@ PAUSE=no log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/test_vxlan_nolocalbypass.sh b/tools/testing/selftests/net/test_vxlan_nolocalbypass.sh index b8805983b728..c51ca0b532dd 100755 --- a/tools/testing/selftests/net/test_vxlan_nolocalbypass.sh +++ b/tools/testing/selftests/net/test_vxlan_nolocalbypass.sh @@ -24,37 +24,7 @@ PAUSE=no log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/test_vxlan_vnifiltering.sh b/tools/testing/selftests/net/test_vxlan_vnifiltering.sh index 8deacc565afa..6fb5af013dac 100755 --- a/tools/testing/selftests/net/test_vxlan_vnifiltering.sh +++ b/tools/testing/selftests/net/test_vxlan_vnifiltering.sh @@ -98,31 +98,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/vrf-xfrm-tests.sh b/tools/testing/selftests/net/vrf-xfrm-tests.sh index b64dd891699d..a4617e5dace7 100755 --- a/tools/testing/selftests/net/vrf-xfrm-tests.sh +++ b/tools/testing/selftests/net/vrf-xfrm-tests.sh @@ -35,24 +35,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) # log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } run_cmd_host1() diff --git a/tools/testing/selftests/net/vrf_route_leaking.sh b/tools/testing/selftests/net/vrf_route_leaking.sh index ce34cb2e6e0b..abf106e0f0c0 100755 --- a/tools/testing/selftests/net/vrf_route_leaking.sh +++ b/tools/testing/selftests/net/vrf_route_leaking.sh @@ -99,24 +99,7 @@ log_section() log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read -r a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } run_cmd() diff --git a/tools/testing/selftests/net/vrf_strict_mode_test.sh b/tools/testing/selftests/net/vrf_strict_mode_test.sh index 01552b542544..7de1873362ba 100755 --- a/tools/testing/selftests/net/vrf_strict_mode_test.sh +++ b/tools/testing/selftests/net/vrf_strict_mode_test.sh @@ -16,24 +16,7 @@ TESTS="init testns mix" log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results() From c47befeabc3383e3f08e653cf9c3a6ee340c7917 Mon Sep 17 00:00:00 2001 From: Hongyan Xu Date: Mon, 28 Sep 2026 21:41:25 +0800 Subject: [PATCH 1014/2126] net: octeon_mgmt: kill TX tasklet before freeing rings The interrupt handler schedules tx_clean_tasklet, which dereferences the private state and TX ring. free_irq() prevents new scheduling but does not wait for a tasklet that was already queued. Kill the tasklet after freeing the interrupt and before purging and freeing the DMA rings. Cc: stable+noautosel@kernel.org # untested fix for a driver init path race Signed-off-by: Hongyan Xu Link: https://patch.msgid.link/20260928134125.2003-1-getshell@seu.edu.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cavium/octeon/octeon_mgmt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c b/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c index c190fc6538d4..2cf3365b9636 100644 --- a/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c +++ b/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c @@ -1254,6 +1254,7 @@ static int octeon_mgmt_stop(struct net_device *netdev) octeon_mgmt_reset_hw(p); free_irq(p->irq, netdev); + tasklet_kill(&p->tx_clean_tasklet); /* dma_unmap is a nop on Octeon, so just free everything. */ skb_queue_purge(&p->tx_list); From 1b7bc043cd1ba1d97f890b71c9a706022b06196e Mon Sep 17 00:00:00 2001 From: Hongyan Xu Date: Mon, 28 Sep 2026 21:41:29 +0800 Subject: [PATCH 1015/2126] net: octeontx2-af: quiesce devlink health work on teardown NPA and NIX interrupt handlers queue health-reporting work whose containers are freed by rvu_health_reporters_destroy(). Interrupt unregistration does not drain queued work. In addition, each reporter setup creates a workqueue in the same field, leaking the NPA queue and leaving no teardown handle for work queued on it. Initialize work before later allocations can fail, share one workqueue, unregister each set of interrupts, and cancel its work before freeing the reporters. Destroy the shared workqueue once both reporter sets are gone. Cc: stable+noautosel@kernel.org # untested fix for a driver (de)init path race Signed-off-by: Hongyan Xu Link: https://patch.msgid.link/20260928134129.145-1-getshell@seu.edu.cn Signed-off-by: Jakub Kicinski --- .../marvell/octeontx2/af/rvu_devlink.c | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c index d63c3d33775a..c7c7230dc588 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c @@ -505,6 +505,11 @@ static int rvu_nix_register_reporters(struct rvu_devlink *rvu_dl) return -ENOMEM; rvu_reporters->nix_event_ctx = nix_event_context; + INIT_WORK(&rvu_reporters->intr_work, rvu_nix_intr_work); + INIT_WORK(&rvu_reporters->gen_work, rvu_nix_gen_work); + INIT_WORK(&rvu_reporters->err_work, rvu_nix_err_work); + INIT_WORK(&rvu_reporters->ras_work, rvu_nix_ras_work); + rvu_reporters->rvu_hw_nix_intr_reporter = devlink_health_reporter_create(rvu_dl->dl, &rvu_hw_nix_intr_reporter_ops, @@ -545,15 +550,11 @@ static int rvu_nix_register_reporters(struct rvu_devlink *rvu_dl) return PTR_ERR(rvu_reporters->rvu_hw_nix_ras_reporter); } - rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq"); + if (!rvu_dl->devlink_wq) + rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq"); if (!rvu_dl->devlink_wq) return -ENOMEM; - INIT_WORK(&rvu_reporters->intr_work, rvu_nix_intr_work); - INIT_WORK(&rvu_reporters->gen_work, rvu_nix_gen_work); - INIT_WORK(&rvu_reporters->err_work, rvu_nix_err_work); - INIT_WORK(&rvu_reporters->ras_work, rvu_nix_ras_work); - return 0; } @@ -582,6 +583,13 @@ static void rvu_nix_health_reporters_destroy(struct rvu_devlink *rvu_dl) if (!nix_reporters->rvu_hw_nix_ras_reporter) return; + + rvu_nix_unregister_interrupts(rvu); + cancel_work_sync(&nix_reporters->intr_work); + cancel_work_sync(&nix_reporters->gen_work); + cancel_work_sync(&nix_reporters->err_work); + cancel_work_sync(&nix_reporters->ras_work); + if (!IS_ERR_OR_NULL(nix_reporters->rvu_hw_nix_intr_reporter)) devlink_health_reporter_destroy(nix_reporters->rvu_hw_nix_intr_reporter); @@ -594,7 +602,6 @@ static void rvu_nix_health_reporters_destroy(struct rvu_devlink *rvu_dl) if (!IS_ERR_OR_NULL(nix_reporters->rvu_hw_nix_ras_reporter)) devlink_health_reporter_destroy(nix_reporters->rvu_hw_nix_ras_reporter); - rvu_nix_unregister_interrupts(rvu); kfree(rvu_dl->rvu_nix_health_reporter->nix_event_ctx); kfree(rvu_dl->rvu_nix_health_reporter); } @@ -1059,6 +1066,11 @@ static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl) return -ENOMEM; rvu_reporters->npa_event_ctx = npa_event_context; + INIT_WORK(&rvu_reporters->intr_work, rvu_npa_intr_work); + INIT_WORK(&rvu_reporters->err_work, rvu_npa_err_work); + INIT_WORK(&rvu_reporters->gen_work, rvu_npa_gen_work); + INIT_WORK(&rvu_reporters->ras_work, rvu_npa_ras_work); + rvu_reporters->rvu_hw_npa_intr_reporter = devlink_health_reporter_create(rvu_dl->dl, &rvu_hw_npa_intr_reporter_ops, @@ -1099,15 +1111,11 @@ static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl) return PTR_ERR(rvu_reporters->rvu_hw_npa_ras_reporter); } - rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq"); + if (!rvu_dl->devlink_wq) + rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq"); if (!rvu_dl->devlink_wq) return -ENOMEM; - INIT_WORK(&rvu_reporters->intr_work, rvu_npa_intr_work); - INIT_WORK(&rvu_reporters->err_work, rvu_npa_err_work); - INIT_WORK(&rvu_reporters->gen_work, rvu_npa_gen_work); - INIT_WORK(&rvu_reporters->ras_work, rvu_npa_ras_work); - return 0; } @@ -1136,6 +1144,13 @@ static void rvu_npa_health_reporters_destroy(struct rvu_devlink *rvu_dl) if (!npa_reporters->rvu_hw_npa_ras_reporter) return; + + rvu_npa_unregister_interrupts(rvu); + cancel_work_sync(&npa_reporters->intr_work); + cancel_work_sync(&npa_reporters->gen_work); + cancel_work_sync(&npa_reporters->err_work); + cancel_work_sync(&npa_reporters->ras_work); + if (!IS_ERR_OR_NULL(npa_reporters->rvu_hw_npa_intr_reporter)) devlink_health_reporter_destroy(npa_reporters->rvu_hw_npa_intr_reporter); @@ -1148,7 +1163,6 @@ static void rvu_npa_health_reporters_destroy(struct rvu_devlink *rvu_dl) if (!IS_ERR_OR_NULL(npa_reporters->rvu_hw_npa_ras_reporter)) devlink_health_reporter_destroy(npa_reporters->rvu_hw_npa_ras_reporter); - rvu_npa_unregister_interrupts(rvu); kfree(rvu_dl->rvu_npa_health_reporter->npa_event_ctx); kfree(rvu_dl->rvu_npa_health_reporter); } @@ -1176,6 +1190,10 @@ static void rvu_health_reporters_destroy(struct rvu *rvu) rvu_dl = rvu->rvu_dl; rvu_npa_health_reporters_destroy(rvu_dl); rvu_nix_health_reporters_destroy(rvu_dl); + if (rvu_dl->devlink_wq) { + destroy_workqueue(rvu_dl->devlink_wq); + rvu_dl->devlink_wq = NULL; + } } /* Devlink Params APIs */ From 56fbbb662795b29f4d12a55cb1b456553a6ec3b0 Mon Sep 17 00:00:00 2001 From: Kris Pan Date: Mon, 28 Sep 2026 09:47:08 +0800 Subject: [PATCH 1016/2126] net: iterate online nodes in skb_defer_free_flush() skb_attempt_defer_free() only queues skbs on the current CPU's node (numa_node_id() of a running CPU), which is always online, so the flush loop never needs to visit nodes that are merely possible. for_each_node() walks node_possible_map. On machines where the possible map is much larger than the online map -- e.g. a POWER10 LPAR with 32 possible but 1 online node -- the flush loop touches 31 cold, always-empty per-node lists on every softirq pass. Use for_each_online_node() to iterate only node_online_map. Nodes that go offline are drained by dev_cpu_dead() ("net: flush skb_defer_nodes in dev_cpu_dead()"), so the flush no longer needs to visit offline nodes. Loopback UDP throughput in a QEMU guest with 32 possible / 1 online nodes (bench_udp, 8 senders, interleaved runs) improves by ~5%. Fixes: 5628f3fe3b16 ("net: add NUMA awareness to skb_attempt_defer_free()") Reported-by: kernel test robot Suggested-by: Adrian Tomasov Closes: https://lore.kernel.org/oe-lkp/202512112119.5b9829a-lkp@intel.com Signed-off-by: Kris Pan Link: https://patch.msgid.link/20260928014708.3903028-1-kris.pan@intel.com Signed-off-by: Jakub Kicinski --- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 0f87fd8c6892..5ac08da8b9d7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6995,7 +6995,7 @@ static void skb_defer_free_flush(void) struct skb_defer_node *sdn; int node; - for_each_node(node) { + for_each_online_node(node) { sdn = this_cpu_ptr(net_hotdata.skb_defer_nodes) + node; __skb_defer_free_flush(sdn, 1); } From d261a371e3b74c82c417b1171264dd35f6ddc615 Mon Sep 17 00:00:00 2001 From: Alexander Duyck Date: Mon, 28 Sep 2026 09:12:08 -0700 Subject: [PATCH 1017/2126] fbnic: Rework the BMC state pulled from the capabilities message The BMC side of the RPC configuration is driven entirely out of the capabilities message: it carries the BMC presence, its MAC addresses and the all-multi request, and the reinit flag raised off it is what gets the service task to reprogram the MACDA and action TCAMs. Pull that out of fbnic_fw_parse_cap_resp() into a helper and rework the state it publishes. The firmware reports the BMC present as soon as its NC-SI channel is enabled, before the BMC has been assigned a MAC address. Such a message carries no BMC MAC array and is rejected with -EINVAL, discarding the rest of it. Treat a present BMC with no MAC as absent instead. There is no entry to steer traffic to without one, so the BMC paths stay disabled either way, and the link speed, FEC and anti-rollback version in the same message are no longer thrown out with it. bmc_present, need_bmc_tcam_reinit, need_bmc_macda_sync and all_multi are single bit members of one bitfield, so every write to one is a read-modify-write of all four. The mailbox writes three of them and the service task writes the other two. Move them into an unsigned long state field driven by the atomic bitops. Putting it at the top of the struct keeps the cost to the word itself: 152 bytes grows to 160, still three cachelines, with a 1 byte hole left ahead of anti_rollback_version. Order the reinit handoff while there. The mailbox publishes the BMC state before raising the flag and the service task tests the flag before consuming it, so pair an smp_mb__before_atomic() on the raise with a test_and_clear_bit() on the consume. Claiming the flag atomically also keeps a raise that lands mid-pass instead of dropping it. Commit all_multi unconditionally rather than only when the firmware supplied the attribute. An absent attribute means the BMC is not asking for all-multi, so holding the previous value just kept stale state. It is read out of the message only when a BMC is present, so it is never set on its own and the three callers that paired it with the presence check can test it alone. fbnic_write_macda() tests the reinit flag to force a MACDA sync and now always sees it clear when reached from fbnic_bmc_rpc_check(). That path is unaffected, as fbnic_bmc_rpc_init() unconditionally marks the broadcast entry, so the update count is never zero while a BMC is present. Signed-off-by: Alexander Duyck Fixes: 20d2e88cc746 ("eth: fbnic: Add initial messaging to notify FW of our presence") Fixes: 04a230b27d8f ("fbnic: Add logic to repopulate RPC TCAM if BMC enables channel") Fixes: cee8d21d8091 ("fbnic: Push local unicast MAC addresses to FW to populate TCAMs") Link: https://patch.msgid.link/179061192791.414394.2161969547553719796.stgit@ahduyck-xeon-server.home.arpa Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/fbnic/fbnic.h | 7 +- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 78 +++++++++++++-------- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 15 ++-- drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 24 ++++--- 4 files changed, 80 insertions(+), 44 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h index 0e7ae1def5bf..1f9fbd71447f 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic.h @@ -161,7 +161,12 @@ void fbnic_fw_wr32(struct fbnic_dev *fbd, u32 reg, u32 val); static inline bool fbnic_bmc_present(struct fbnic_dev *fbd) { - return fbd->fw_cap.bmc_present; + return test_bit(FBNIC_FW_CAP_F_BMC_PRESENT, &fbd->fw_cap.state); +} + +static inline bool fbnic_bmc_all_multi(struct fbnic_dev *fbd) +{ + return test_bit(FBNIC_FW_CAP_F_BMC_ALL_MULTI, &fbd->fw_cap.state); } static inline bool fbnic_init_failure(struct fbnic_dev *fbd) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c index 47894b45676b..49b8813a3564 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c @@ -620,11 +620,55 @@ static int fbnic_fw_parse_bmc_addrs(u8 bmc_mac_addr[][ETH_ALEN], return 0; } +static int fbnic_fw_parse_bmc_cap(struct fbnic_dev *fbd, + struct fbnic_tlv_msg **results) +{ + struct fbnic_tlv_msg *attr; + bool bmc_present = false; + u32 all_multi = 0; + int err; + + /* FW reports the BMC present once its NC-SI channel is enabled, before + * it has a MAC. No MAC array means nothing to program, so treat it as + * absent rather than rejecting the message. + */ + attr = results[FBNIC_FW_CAP_RESP_BMC_PRESENT] ? + results[FBNIC_FW_CAP_RESP_BMC_MAC_ARRAY] : NULL; + if (attr) { + err = fbnic_fw_parse_bmc_addrs(fbd->fw_cap.bmc_mac_addr, + attr, 4); + if (err) + return err; + + all_multi = fta_get_uint(results, + FBNIC_FW_CAP_RESP_BMC_ALL_MULTI); + bmc_present = true; + } else { + memset(fbd->fw_cap.bmc_mac_addr, 0, + sizeof(fbd->fw_cap.bmc_mac_addr)); + } + + /* all_multi is only read out of the message when a BMC is present, so + * it is never set on its own and callers can test it without pairing + * it with the presence check. + */ + assign_bit(FBNIC_FW_CAP_F_BMC_PRESENT, &fbd->fw_cap.state, bmc_present); + assign_bit(FBNIC_FW_CAP_F_BMC_ALL_MULTI, &fbd->fw_cap.state, all_multi); + + /* Always assume we need a BMC reinit. The barrier orders the BMC state + * published above ahead of the flag, pairing with the ordering implied + * by the test_and_clear_bit() in fbnic_bmc_rpc_check(). + */ + smp_mb__before_atomic(); + set_bit(FBNIC_FW_CAP_F_BMC_TCAM_REINIT, &fbd->fw_cap.state); + + return 0; +} + static int fbnic_fw_parse_cap_resp(void *opaque, struct fbnic_tlv_msg **results) { - u32 all_multi = 0, version = 0; struct fbnic_dev *fbd = opaque; - bool bmc_present; + u32 version = 0; int err; version = fta_get_uint(results, FBNIC_FW_CAP_RESP_VERSION); @@ -684,37 +728,13 @@ static int fbnic_fw_parse_cap_resp(void *opaque, struct fbnic_tlv_msg **results) fbd->fw_cap.link_fec = fta_get_uint(results, FBNIC_FW_CAP_RESP_FW_LINK_FEC); - bmc_present = !!results[FBNIC_FW_CAP_RESP_BMC_PRESENT]; - if (bmc_present) { - struct fbnic_tlv_msg *attr; - - attr = results[FBNIC_FW_CAP_RESP_BMC_MAC_ARRAY]; - if (!attr) - return -EINVAL; - - err = fbnic_fw_parse_bmc_addrs(fbd->fw_cap.bmc_mac_addr, - attr, 4); - if (err) - return err; - - all_multi = - fta_get_uint(results, FBNIC_FW_CAP_RESP_BMC_ALL_MULTI); - } else { - memset(fbd->fw_cap.bmc_mac_addr, 0, - sizeof(fbd->fw_cap.bmc_mac_addr)); - } - - fbd->fw_cap.bmc_present = bmc_present; - - if (results[FBNIC_FW_CAP_RESP_BMC_ALL_MULTI] || !bmc_present) - fbd->fw_cap.all_multi = all_multi; + err = fbnic_fw_parse_bmc_cap(fbd, results); + if (err) + return err; fbd->fw_cap.anti_rollback_version = fta_get_uint(results, FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION); - /* Always assume we need a BMC reinit */ - fbd->fw_cap.need_bmc_tcam_reinit = true; - return 0; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h index 5f9969247e30..e542b17bdac7 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h @@ -45,7 +45,18 @@ struct fbnic_fw_ver { char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE]; }; +/* Bits in fbnic_fw_cap.state. The firmware mailbox publishes the BMC state + * and the service task consumes it, so they are updated with atomic bitops. + */ +enum { + FBNIC_FW_CAP_F_BMC_PRESENT, + FBNIC_FW_CAP_F_BMC_ALL_MULTI, + FBNIC_FW_CAP_F_BMC_TCAM_REINIT, + FBNIC_FW_CAP_F_BMC_MACDA_SYNC, +}; + struct fbnic_fw_cap { + unsigned long state; struct { struct fbnic_fw_ver mgmt, bootloader; } running; @@ -54,10 +65,6 @@ struct fbnic_fw_cap { } stored; u8 active_slot; u8 bmc_mac_addr[4][ETH_ALEN]; - u8 bmc_present : 1; - u8 need_bmc_tcam_reinit : 1; - u8 need_bmc_macda_sync : 1; - u8 all_multi : 1; u8 link_speed; u8 link_fec; u32 anti_rollback_version; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c b/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c index ab6e342ec3fa..51fd0564d33f 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c @@ -117,7 +117,7 @@ void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd, * BMC. */ mac_addr = &fbd->mac_addr[fbd->mac_addr_boundary - 1]; - if (fbnic_bmc_present(fbd) && fbd->fw_cap.all_multi) { + if (fbnic_bmc_all_multi(fbd)) { if (mac_addr->state != FBNIC_TCAM_S_VALID) { eth_zero_addr(mac_addr->value.addr8); eth_broadcast_addr(mac_addr->mask.addr8); @@ -144,7 +144,7 @@ void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd, /* If we are not enabling the rule just delete it. We will fall * back to the RSS rules that support the multicast addresses. */ - if (!fbnic_bmc_present(fbd) || !fbd->fw_cap.all_multi || enable_host) { + if (!fbnic_bmc_all_multi(fbd) || enable_host) { if (act_tcam->state == FBNIC_TCAM_S_VALID) act_tcam->state = FBNIC_TCAM_S_DELETE; return; @@ -238,20 +238,25 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd) { int err; - if (fbd->fw_cap.need_bmc_tcam_reinit) { + /* Consume the flag before the state it advertises. The ordering + * implied by test_and_clear_bit() pairs with the barrier in + * fbnic_fw_parse_bmc_cap(), and claiming it atomically means a set + * racing with us is kept and retried rather than overwritten. + */ + if (test_and_clear_bit(FBNIC_FW_CAP_F_BMC_TCAM_REINIT, + &fbd->fw_cap.state)) { fbnic_bmc_rpc_init(fbd); netif_addr_lock_bh(fbd->netdev); __fbnic_set_rx_mode(fbd, &fbd->netdev->uc, &fbd->netdev->mc); netif_addr_unlock_bh(fbd->netdev); - fbd->fw_cap.need_bmc_tcam_reinit = false; } - if (fbd->fw_cap.need_bmc_macda_sync) { + if (test_and_clear_bit(FBNIC_FW_CAP_F_BMC_MACDA_SYNC, + &fbd->fw_cap.state)) { err = fbnic_fw_xmit_rpc_macda_sync(fbd); if (err) dev_warn(fbd->dev, "Writing MACDA table to FW failed, err: %d\n", err); - fbd->fw_cap.need_bmc_macda_sync = false; } } @@ -484,8 +489,7 @@ void fbnic_promisc_sync(struct fbnic_dev *fbd, mac_addr->act_tcam); mac_addr->state = FBNIC_TCAM_S_ADD; } - } else if (mc_promisc && - (!fbnic_bmc_present(fbd) || !fbd->fw_cap.all_multi)) { + } else if (mc_promisc && !fbnic_bmc_all_multi(fbd)) { /* We have to add a special handler for multicast as the * BMC may have an all-multi rule already in place. As such * adding a rule ourselves won't do any good so we will have @@ -656,12 +660,12 @@ void fbnic_write_macda(struct fbnic_dev *fbd) } /* If reinitializing the BMC TCAM we are doing an initial update */ - if (fbd->fw_cap.need_bmc_tcam_reinit) + if (test_bit(FBNIC_FW_CAP_F_BMC_TCAM_REINIT, &fbd->fw_cap.state)) updates++; /* If needed notify firmware of changes to MACDA TCAM */ if (updates != 0 && fbnic_bmc_present(fbd)) - fbd->fw_cap.need_bmc_macda_sync = true; + set_bit(FBNIC_FW_CAP_F_BMC_MACDA_SYNC, &fbd->fw_cap.state); } static void fbnic_clear_act_tcam(struct fbnic_dev *fbd, unsigned int idx) From db99b6fae21cfc09d7201b18470acbc01e45d038 Mon Sep 17 00:00:00 2001 From: Alexander Duyck Date: Mon, 28 Sep 2026 09:12:15 -0700 Subject: [PATCH 1018/2126] fbnic: Remove BMC routing rules when the BMC channel is disabled While a BMC is present the driver programs MACDA entries for the BMC addresses, action rules steering matching traffic to it, the DEST_BMC copy bit on the multicast/broadcast RSS actions, and a host-unicast copy of the RSS actions. All of these are only torn down when the host interface goes down. A BMC can disable its NC-SI channel while the host interface stays up. The filters are then left in place, so the host keeps steering traffic to a BMC that is no longer there, and the driver logs "Found BMC MAC address w/ BMC not present" at the next interface down. Detect that bmc_present dropped while BMC tagged rules are still programmed in fbnic_bmc_rpc_check(), and remove the BMC MAC entries, the action rule and the host-unicast RSS entries. That needs three supporting changes: 1. Action rules must be marked for deletion in any live state rather than only VALID, as a missed deletion leaks the rule for good. The same applies to the BMC all-multi rule, which ifdown leaves in UPDATE. 2. The host-unicast entries have to go because fbnic_rss_reinit() only programs them while a BMC is present and would otherwise leave them stale and valid in hardware. 3. Recompute the RSS actions for both directions; without that a disable and re-enable cycle leaves the BMC without its multicast/broadcast copies until the interface bounces. Take the instance lock over the whole of fbnic_bmc_rpc_check() while here. fbnic_fw_xmit_rpc_macda_sync() walks the entire MACDA shadow and the teardown above rewrites it, but the service task they both run from holds only RTNL. RTNL used to cover that, back when ndo_set_rx_mode() was called inline from dev_set_rx_mode(). fbnic is ops-locked, so netif_rx_mode_run() now calls ndo_set_rx_mode_async() under the instance lock alone, having dropped netif_addr_lock and handed over a snapshot of the address lists. The ethtool NFC paths are in the same position. The instance lock is the one lock every writer of the shadow holds. The flags are tested once without it first so the lock stays off the common path, where the service task has nothing to do. Signed-off-by: Alexander Duyck Link: https://patch.msgid.link/179061193535.414394.10077526689774524435.stgit@ahduyck-xeon-server.home.arpa Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 4 + drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 97 ++++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h index e542b17bdac7..f47669129c9d 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h @@ -55,6 +55,10 @@ enum { FBNIC_FW_CAP_F_BMC_MACDA_SYNC, }; +#define FBNIC_FW_CAP_BMC_PENDING \ + (BIT(FBNIC_FW_CAP_F_BMC_TCAM_REINIT) | \ + BIT(FBNIC_FW_CAP_F_BMC_MACDA_SYNC)) + struct fbnic_fw_cap { unsigned long state; struct { diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c b/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c index 51fd0564d33f..939d56585b26 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_rpc.c @@ -143,9 +143,11 @@ void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd, /* If we are not enabling the rule just delete it. We will fall * back to the RSS rules that support the multicast addresses. + * Delete in any live state, not just VALID, as ifdown demotes it to + * UPDATE and a miss there leaves it to be rewritten to hardware. */ if (!fbnic_bmc_all_multi(fbd) || enable_host) { - if (act_tcam->state == FBNIC_TCAM_S_VALID) + if (act_tcam->state != FBNIC_TCAM_S_DISABLED) act_tcam->state = FBNIC_TCAM_S_DELETE; return; } @@ -234,10 +236,91 @@ void fbnic_bmc_rpc_init(struct fbnic_dev *fbd) act_tcam->state = FBNIC_TCAM_S_UPDATE; } +/** + * fbnic_bmc_rules_present - is the BMC currently programmed into the filters? + * @fbd: Pointer to fbnic device struct + * + * The BMC tag is only set while a BMC is present, so it doubles as the state. + * + * Return: true if any MACDA entry carries the BMC tag, false otherwise. + */ +static bool fbnic_bmc_rules_present(struct fbnic_dev *fbd) +{ + int idx; + + for (idx = ARRAY_SIZE(fbd->mac_addr); idx--;) { + struct fbnic_mac_addr *mac_addr = &fbd->mac_addr[idx]; + + if (mac_addr->state == FBNIC_TCAM_S_DISABLED) + continue; + + if (test_bit(FBNIC_MAC_ADDR_T_BMC, mac_addr->act_tcam)) + return true; + } + + return false; +} + +/** + * fbnic_bmc_rpc_disable - remove the BMC MAC and action rules + * @fbd: Pointer to fbnic device struct + * + * Undo fbnic_bmc_rpc_init() when the BMC drops its NC-SI channel while the + * host interface stays up. Only marks shadow state; the caller's + * __fbnic_set_rx_mode() pushes it to hardware, so ordering here is moot. + */ +static void fbnic_bmc_rpc_disable(struct fbnic_dev *fbd) +{ + struct fbnic_act_tcam *act_tcam; + int idx; + + /* Drop the BMC's claim; entries the host also uses survive */ + for (idx = ARRAY_SIZE(fbd->mac_addr); idx--;) { + struct fbnic_mac_addr *mac_addr = &fbd->mac_addr[idx]; + + if (mac_addr->state == FBNIC_TCAM_S_DISABLED) + continue; + + __fbnic_xc_unsync(mac_addr, FBNIC_MAC_ADDR_T_BMC); + } + + /* Delete in any live state, not just VALID: init leaves it UPDATE and + * ifdown demotes VALID to UPDATE. A miss leaks the rule for good, as + * fbnic_bmc_rules_present() keys off the MACDA tag just cleared above. + */ + act_tcam = &fbd->act_tcam[FBNIC_RPC_ACT_TBL_BMC_OFFSET]; + if (act_tcam->state != FBNIC_TCAM_S_DISABLED) + act_tcam->state = FBNIC_TCAM_S_DELETE; + + /* fbnic_rss_reinit() only programs the host-unicast entries while a BMC + * is present, so the reinit after this would leave them stale and valid + * in hardware. Delete them to converge on the no-BMC layout. + */ + for (idx = 0; idx < FBNIC_RSS_EN_NUM_UNICAST; idx++) { + act_tcam = &fbd->act_tcam[FBNIC_RPC_ACT_TBL_RSS_OFFSET + idx]; + if (act_tcam->state != FBNIC_TCAM_S_DISABLED) + act_tcam->state = FBNIC_TCAM_S_DELETE; + } +} + void fbnic_bmc_rpc_check(struct fbnic_dev *fbd) { + struct fbnic_net *fbn = netdev_priv(fbd->netdev); int err; + /* Nothing to do unless the firmware raised one of the flags. Test + * before taking the lock to keep it off the common path; one raised + * after this is picked up on the next pass. + */ + if (!(READ_ONCE(fbd->fw_cap.state) & FBNIC_FW_CAP_BMC_PENDING)) + return; + + /* The rx mode work and the ethtool paths rewrite the MACDA and action + * TCAM shadows under the instance lock, and this runs from the service + * task under RTNL only, so the two do not exclude each other. + */ + netdev_lock(fbd->netdev); + /* Consume the flag before the state it advertises. The ordering * implied by test_and_clear_bit() pairs with the barrier in * fbnic_fw_parse_bmc_cap(), and claiming it atomically means a set @@ -245,7 +328,15 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd) */ if (test_and_clear_bit(FBNIC_FW_CAP_F_BMC_TCAM_REINIT, &fbd->fw_cap.state)) { - fbnic_bmc_rpc_init(fbd); + if (!fbnic_bmc_present(fbd) && fbnic_bmc_rules_present(fbd)) + fbnic_bmc_rpc_disable(fbd); + else + fbnic_bmc_rpc_init(fbd); + + /* Neither path touches the RSS actions, which carry the mc/bc + * copy to the BMC, so recompute them alongside. + */ + fbnic_rss_reinit(fbd, fbn); netif_addr_lock_bh(fbd->netdev); __fbnic_set_rx_mode(fbd, &fbd->netdev->uc, &fbd->netdev->mc); netif_addr_unlock_bh(fbd->netdev); @@ -258,6 +349,8 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd) dev_warn(fbd->dev, "Writing MACDA table to FW failed, err: %d\n", err); } + + netdev_unlock(fbd->netdev); } #define FBNIC_ACT1_INIT(_l4, _udp, _ip, _v6) \ From fe8a42931853be7e78564fa6359f4c0197429d1e Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 30 Sep 2026 09:31:09 -0700 Subject: [PATCH 1019/2126] docs: netdev: additional info requirements for bug fixes Knowing how AI-generated patches were tested would be a great help when reviewing them. Explicitly ask people to describe the discovery and validation process they followed. I posted this as an RFC a while back and there were some concerns from developers that it would gum up the process. With Linus's recent complaints about the size of our PRs, we really need this information. I launched an AI bot which complains if people don't explain how bugs were discovered and tested (look for netdev-bot+sinfo@kernel.org, s=series info). We need to document this requirement. Reviewed-by: Nicolai Buchwitz Acked-by: Daniel Machon Link: https://patch.msgid.link/20260930163109.3910509-1-kuba@kernel.org Signed-off-by: Jakub Kicinski --- Documentation/process/maintainer-netdev.rst | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/process/maintainer-netdev.rst b/Documentation/process/maintainer-netdev.rst index 1739d9f856c3..df220a965438 100644 --- a/Documentation/process/maintainer-netdev.rst +++ b/Documentation/process/maintainer-netdev.rst @@ -283,6 +283,38 @@ as a patch to the list with a commit message explaining the technical problems with the reverted commit. Reverts should be used as a last resort, when original change is completely wrong; incremental fixes are preferred. +Bug fixes +~~~~~~~~~ + +All bug fixes must state how the issue was discovered and validated, +and how the fix was tested. This should be done in plain English, not with +special tags or annotations. That said, the information does not have to be +provided if the existing trailers imply it (e.g. ``Reported-by: syzbot...`` +implies the discovery method and validation). + +Example statements describing discovery: + + - discovered by a non-AI static analysis tool + - discovered by an AI code review agent + - discovered by manual code inspection + - triggered during code development + - triggered in CI testing + - observed on a machine in real use + +If the discovery method does not imply the issue was triggered, the commit +message should describe the validation, i.e. how the bug was confirmed +to be real. The commit message must disclose whether reproducing the issue +required modifying the kernel (e.g. inserting a delay to widen a race, or +writing a loadable module to issue the right sequence of calls) or using error +injection. The reproduction steps should be included in the commit message +if they are short (roughly 10 lines or fewer); longer reproducers can be posted +online with a link included. + +The testing statement should explain whether the fix was tested against the +reproducer and against kernel selftests. If the bug is in a hardware driver, +the testing statement must include information about the HW on which the +fix was tested. + Stable tree ~~~~~~~~~~~ From 071876fd50482a68603a9460d80dd6dd58827ee1 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Wed, 30 Sep 2026 22:01:34 +0000 Subject: [PATCH 1020/2126] ref_tracker: Don't use __GFP_NOFAIL for PF_MEMALLOC thread. syzbot triggered a warning in __alloc_pages_slowpath(). [0] ref_tracker_alloc() uses __GFP_NOFAIL if the passed gfp has __GFP_DIRECT_RECLAIM. However, cifs_demultiplex_thread() calls memalloc_noreclaim_save() and its kthread has PF_MEMALLOC. As commented in __alloc_pages_slowpath(), __GFP_NOFAIL should not be used for PF_MEMALLOC thread. if (unlikely(nofail)) { ... /* * PF_MEMALLOC request from this context is rather bizarre * because we cannot reclaim anything and only can loop waiting * for somebody to do a work for us. */ WARN_ON_ONCE(current->flags & PF_MEMALLOC); Let's avoid using __GFP_NOFAIL for PF_MEMALLOC thread. [0]: current->flags & PF_MEMALLOC WARNING: mm/page_alloc.c:4816 at __alloc_pages_slowpath mm/page_alloc.c:4816 [inline], CPU#0: cifsd/12032 WARNING: mm/page_alloc.c:4816 at __alloc_frozen_pages_noprof+0x1eac/0x3300 mm/page_alloc.c:5449, CPU#0: cifsd/12032 Modules linked in: CPU: 0 UID: 0 PID: 12032 Comm: cifsd Tainted: G L syzkaller #0 PREEMPT(full) Tainted: [L]=SOFTLOCKUP Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:__alloc_pages_slowpath mm/page_alloc.c:4816 [inline] RIP: 0010:__alloc_frozen_pages_noprof+0x1eac/0x3300 mm/page_alloc.c:5449 Code: 38 d0 7c 08 84 d2 0f 85 de 12 00 00 65 48 8b 05 e2 a7 1c 12 c7 84 24 94 00 00 00 00 80 00 00 f6 40 2d 08 0f 84 ba e7 ff ff 90 <0f> 0b 90 e9 b1 e7 ff ff 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 RSP: 0000:ffffc90002e172d0 EFLAGS: 00010202 RAX: ffff888029380000 RBX: 0000000000000000 RCX: 1ffff1100fffad29 RDX: 0000000000000000 RSI: 0000000000000002 RDI: ffff88803fffd938 RBP: ffff88802938002c R08: 0000000000008000 R09: 0000000000000001 R10: 0000000000000002 R11: 0000000000000000 R12: 00000000000cac40 R13: ffff88803fffb900 R14: 0000000000000000 R15: 1ffff920005c2e74 FS: 0000000000000000(0000) GS:ffff888096955000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000008000a000 CR3: 00000000403b5000 CR4: 0000000000352ef0 Call Trace: alloc_slab_page mm/slub.c:3347 [inline] allocate_slab mm/slub.c:3470 [inline] new_slab+0x1f6/0x6e0 mm/slub.c:3513 refill_objects+0xe3/0x410 mm/slub.c:7417 refill_sheaf mm/slub.c:2885 [inline] __pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4774 alloc_from_pcs mm/slub.c:4850 [inline] slab_alloc_node mm/slub.c:4984 [inline] __kmalloc_cache_noprof+0x4f4/0x6d0 mm/slub.c:5559 _kmalloc_noprof include/linux/slab.h:991 [inline] _kzalloc_noprof include/linux/slab.h:1312 [inline] ref_tracker_alloc+0x190/0x590 lib/ref_tracker.c:270 __netns_tracker_alloc include/net/net_namespace.h:370 [inline] sk_alloc+0xcfc/0xe80 net/core/sock.c:2329 inet_create net/ipv4/af_inet.c:333 [inline] inet_create+0x3a0/0x1060 net/ipv4/af_inet.c:259 __sock_create+0x339/0x860 net/socket.c:1676 generic_ip_connect+0x826/0x1810 fs/smb/client/connect.c:3377 __cifs_reconnect+0x348/0xa80 fs/smb/client/connect.c:420 _cifs_reconnect fs/smb/client/connect.c:596 [inline] cifs_reconnect fs/smb/client/connect.c:610 [inline] cifs_readv_from_socket+0x7c1/0xa30 fs/smb/client/connect.c:749 cifs_read_from_socket+0xb8/0x100 fs/smb/client/connect.c:804 cifs_demultiplex_thread+0x2db/0x2ea0 fs/smb/client/connect.c:1295 kthread+0x373/0x450 kernel/kthread.c:436 ret_from_fork+0x730/0xd60 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 Cc: stable+noautosel@kernel.org # ref_tracker is debug instrumentation Fixes: 4e66934eaadc ("lib: add reference counting tracking infrastructure") Reported-by: syzbot+f95c2f0a71a98cef50eb@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/6abd860c.9b478af7.e8d7a.0000.GAE@google.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260930220137.843785-1-kuniyu@google.com Signed-off-by: Jakub Kicinski --- lib/ref_tracker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c index 30c999d57b10..5f63206357b2 100644 --- a/lib/ref_tracker.c +++ b/lib/ref_tracker.c @@ -265,7 +265,7 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir, refcount_inc(&dir->no_tracker); return 0; } - if (gfp & __GFP_DIRECT_RECLAIM) + if ((gfp & __GFP_DIRECT_RECLAIM) && !(current->flags & PF_MEMALLOC)) gfp_mask |= __GFP_NOFAIL; *trackerp = tracker = kzalloc_obj(*tracker, gfp_mask); if (unlikely(!tracker)) { From 13bb47965e021eabeaf6881272b419e076c529b2 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:00 +0300 Subject: [PATCH 1021/2126] net: bridge: introduce a bridge destination type Add an opaque destination type and helpers for representing bridge port destinations. Using a separate structure makes raw pointer assignments and comparisons fail at build time while marking its value member __private makes sparse warn about accesses that bypass the helpers. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-2-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_private.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 67117fb3dc88..1146187aa2ba 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -306,6 +306,10 @@ struct net_bridge_fdb_key { u16 vlan_id; }; +struct net_bridge_dst { + unsigned long __private value; +}; + struct net_bridge_fdb_entry { struct rhash_head rhnode; struct net_bridge_port *dst; @@ -670,6 +674,40 @@ struct br_input_skb_cb { #define br_debug(br, format, args...) \ pr_debug("%s: " format, (br)->dev->name, ##args) +static inline struct net_bridge_dst +br_dst_read(const struct net_bridge_dst *src) +{ + struct net_bridge_dst dst; + + ACCESS_PRIVATE(&dst, value) = + READ_ONCE(ACCESS_PRIVATE(src, value)); + + return dst; +} + +static inline void br_dst_write(struct net_bridge_dst *dst, + struct net_bridge_dst src) +{ + WRITE_ONCE(ACCESS_PRIVATE(dst, value), + ACCESS_PRIVATE(&src, value)); +} + +static inline struct net_bridge_dst +br_port_to_dst(const struct net_bridge_port *p) +{ + struct net_bridge_dst dst; + + ACCESS_PRIVATE(&dst, value) = (unsigned long)p; + + return dst; +} + +static inline struct net_bridge_port * +br_dst_port(struct net_bridge_dst dst) +{ + return (struct net_bridge_port *)ACCESS_PRIVATE(&dst, value); +} + /* called under bridge lock */ static inline int br_is_root_bridge(const struct net_bridge *br) { From fd7a8eb03c32f811eff6f4972c8ff57cab28b66d Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:01 +0300 Subject: [PATCH 1022/2126] net: bridge: use net_bridge_dst for fdb destinations Store fdb destinations in struct net_bridge_dst and access them through the destination helpers. This doesn't change their representation or behavior, fdb destinations still contain only bridge port pointers. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-3-razor@blackwall.org Signed-off-by: Jakub Kicinski --- include/trace/events/bridge.h | 7 +++-- net/bridge/br_arp_nd_proxy.c | 4 +-- net/bridge/br_device.c | 4 +-- net/bridge/br_fdb.c | 53 ++++++++++++++++++----------------- net/bridge/br_input.c | 4 +-- net/bridge/br_private.h | 20 ++++++++++++- net/bridge/br_switchdev.c | 2 +- 7 files changed, 58 insertions(+), 36 deletions(-) diff --git a/include/trace/events/bridge.h b/include/trace/events/bridge.h index 3fe4725c83ff..f676516b33fa 100644 --- a/include/trace/events/bridge.h +++ b/include/trace/events/bridge.h @@ -68,13 +68,14 @@ TRACE_EVENT(br_fdb_external_learn_add, TRACE_EVENT(fdb_delete, - TP_PROTO(struct net_bridge *br, struct net_bridge_fdb_entry *f), + TP_PROTO(struct net_bridge *br, struct net_bridge_fdb_entry *f, + const struct net_bridge_port *dst), - TP_ARGS(br, f), + TP_ARGS(br, f, dst), TP_STRUCT__entry( __string(br_dev, br->dev->name) - __string(dev, f->dst ? f->dst->dev->name : "null") + __string(dev, dst ? dst->dev->name : "null") __array(unsigned char, addr, ETH_ALEN) __field(u16, vid) ), diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index da15f4d7c1ae..ba4a63840b21 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -223,7 +223,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, neigh_ha_snapshot(ha, n, n->dev); f = br_fdb_find_rcu(br, ha, vid); if (f) { - const struct net_bridge_port *dst = READ_ONCE(f->dst); + const struct net_bridge_port *dst = br_fdb_dst_port(f); bool replied = false; if ((p && test_bit(BR_PROXYARP_BIT, &p->flags)) || @@ -500,7 +500,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, neigh_ha_snapshot(ha, n, n->dev); f = br_fdb_find_rcu(br, ha, vid); if (f) { - const struct net_bridge_port *dst = READ_ONCE(f->dst); + const struct net_bridge_port *dst = br_fdb_dst_port(f); bool replied = false; if (br_is_neigh_suppress_enabled_vid(dst, vid)) { diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index ce9ea9ac3d0a..c6804409b60b 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -107,7 +107,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) else br_flood(br, vlan, skb, BR_PKT_MULTICAST, false, true); } else if ((dst = br_fdb_find_rcu(br, dest, vid)) != NULL) { - br_forward(READ_ONCE(dst->dst), skb, false, true); + br_forward(br_fdb_dst_port(dst), skb, false, true); } else { br_flood(br, vlan, skb, BR_PKT_UNICAST, false, true); } @@ -400,7 +400,7 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx, if (!f) return -1; - dst = READ_ONCE(f->dst); + dst = br_fdb_dst_port(f); if (!dst) return -1; diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index e4570bbed854..0f5cf5615b56 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -90,7 +90,7 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br, const struct net_bridge_fdb_entry *fdb, u32 portid, u32 seq, int type, unsigned int flags) { - const struct net_bridge_port *dst = READ_ONCE(fdb->dst); + const struct net_bridge_port *dst = br_fdb_dst_port(fdb); unsigned long now = jiffies; struct nda_cacheinfo ci; struct nlmsghdr *nlh; @@ -250,7 +250,7 @@ struct net_device *br_fdb_find_port(const struct net_device *br_dev, rcu_read_lock(); f = br_fdb_find_rcu(br, addr, vid); if (f) { - dst = READ_ONCE(f->dst); + dst = br_fdb_dst_port(f); if (dst) dev = dst->dev; } @@ -315,7 +315,7 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr) static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f, bool swdev_notify) { - trace_fdb_delete(br, f); + trace_fdb_delete(br, f, br_fdb_dst_port(f)); if (test_bit(BR_FDB_STATIC, &f->flags)) fdb_del_hw_addr(br, f->key.addr.addr); @@ -350,7 +350,7 @@ static void fdb_delete_local(struct net_bridge *br, vg = nbp_vlan_group(op); if (op != p && ether_addr_equal(op->dev->dev_addr, addr) && (!vid || br_vlan_find(vg, vid))) { - WRITE_ONCE(f->dst, op); + br_fdb_dst_write(f, br_port_to_dst(op)); clear_bit(BR_FDB_ADDED_BY_USER, &f->flags); return; } @@ -361,7 +361,7 @@ static void fdb_delete_local(struct net_bridge *br, /* Maybe bridge device has same hw addr? */ if (p && ether_addr_equal(br->dev->dev_addr, addr) && (!vid || (v && br_vlan_should_use(v)))) { - WRITE_ONCE(f->dst, NULL); + br_fdb_dst_write(f, br_port_to_dst(NULL)); clear_bit(BR_FDB_ADDED_BY_USER, &f->flags); return; } @@ -378,7 +378,8 @@ void br_fdb_find_delete_local(struct net_bridge *br, spin_lock_bh(&br->hash_lock); f = br_fdb_find(br, addr, vid); if (f && test_bit(BR_FDB_LOCAL, &f->flags) && - !test_bit(BR_FDB_ADDED_BY_USER, &f->flags) && f->dst == p) + !test_bit(BR_FDB_ADDED_BY_USER, &f->flags) && + br_fdb_dst_port(f) == p) fdb_delete_local(br, p, f); spin_unlock_bh(&br->hash_lock); } @@ -408,7 +409,7 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, return NULL; memcpy(fdb->key.addr.addr, addr, ETH_ALEN); - WRITE_ONCE(fdb->dst, source); + br_fdb_dst_write(fdb, br_port_to_dst(source)); fdb->key.vlan_id = vid; fdb->flags = flags; fdb->updated = fdb->used = jiffies; @@ -470,7 +471,7 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr) spin_lock_bh(&br->hash_lock); vg = nbp_vlan_group(p); hlist_for_each_entry(f, &br->fdb_list, fdb_node) { - if (READ_ONCE(f->dst) == p && + if (br_fdb_dst_port(f) == p && test_bit(BR_FDB_LOCAL, &f->flags) && !test_bit(BR_FDB_ADDED_BY_USER, &f->flags)) { /* delete old one */ @@ -517,7 +518,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr) /* If old entry was unassociated with any port, then delete it. */ f = br_fdb_find(br, br->dev->dev_addr, 0); if (f && test_bit(BR_FDB_LOCAL, &f->flags) && - !f->dst && !test_bit(BR_FDB_ADDED_BY_USER, &f->flags)) + !br_fdb_dst_port(f) && + !test_bit(BR_FDB_ADDED_BY_USER, &f->flags)) fdb_delete_local(br, NULL, f); fdb_add_local(br, NULL, newaddr, 0); @@ -533,7 +535,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr) continue; f = br_fdb_find(br, br->dev->dev_addr, v->vid); if (f && test_bit(BR_FDB_LOCAL, &f->flags) && - !f->dst && !test_bit(BR_FDB_ADDED_BY_USER, &f->flags)) + !br_fdb_dst_port(f) && + !test_bit(BR_FDB_ADDED_BY_USER, &f->flags)) fdb_delete_local(br, NULL, f); fdb_add_local(br, NULL, newaddr, v->vid); } @@ -693,7 +696,7 @@ static bool __fdb_flush_matches(const struct net_bridge *br, const struct net_bridge_fdb_entry *f, const struct net_bridge_fdb_flush_desc *desc) { - const struct net_bridge_port *dst = READ_ONCE(f->dst); + const struct net_bridge_port *dst = br_fdb_dst_port(f); int port_ifidx = dst ? dst->dev->ifindex : br->dev->ifindex; if (desc->vlan_id && desc->vlan_id != f->key.vlan_id) @@ -879,7 +882,7 @@ void br_fdb_delete_by_port(struct net_bridge *br, spin_lock_bh(&br->hash_lock); hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) { - if (READ_ONCE(f->dst) != p) + if (br_fdb_dst_port(f) != p) continue; if (!do_all) @@ -921,7 +924,7 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf, continue; /* ignore pseudo entry for local MAC address */ - dst = READ_ONCE(f->dst); + dst = br_fdb_dst_port(f); if (!dst) continue; @@ -996,10 +999,10 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, } /* fastpath: update of existing entry */ - if (unlikely(source != READ_ONCE(fdb->dst) && + if (unlikely(source != br_fdb_dst_port(fdb) && !test_bit(BR_FDB_STICKY, &fdb->flags))) { br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH); - WRITE_ONCE(fdb->dst, source); + br_fdb_dst_write(fdb, br_port_to_dst(source)); fdb_modified = true; /* Take over HW learned entry */ if (unlikely(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, @@ -1061,17 +1064,17 @@ int br_fdb_dump(struct sk_buff *skb, rcu_read_lock(); hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { - const struct net_bridge_port *dst = READ_ONCE(f->dst); + const struct net_bridge_port *dst = br_fdb_dst_port(f); if (*idx < ctx->fdb_idx) goto skip; if (filter_dev && (!dst || dst->dev != filter_dev)) { if (filter_dev != dev) goto skip; - /* !f->dst is a special case for bridge + /* A NULL destination is a special case for bridge * It means the MAC belongs to the bridge * Therefore need a little more filtering - * we only want to dump the !f->dst case + * we only want to dump the NULL destination case */ if (dst) goto skip; @@ -1193,8 +1196,8 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, if (flags & NLM_F_EXCL) return -EEXIST; - if (READ_ONCE(fdb->dst) != source) { - WRITE_ONCE(fdb->dst, source); + if (br_fdb_dst_port(fdb) != source) { + br_fdb_dst_write(fdb, br_port_to_dst(source)); modified = true; } @@ -1385,7 +1388,7 @@ static int fdb_delete_by_addr_and_port(struct net_bridge *br, struct net_bridge_fdb_entry *fdb; fdb = br_fdb_find(br, addr, vlan); - if (!fdb || READ_ONCE(fdb->dst) != p) + if (!fdb || br_fdb_dst_port(fdb) != p) return -ENOENT; fdb_delete(br, fdb, true); @@ -1541,15 +1544,15 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, } else { if (locked && (!test_bit(BR_FDB_LOCKED, &fdb->flags) || - READ_ONCE(fdb->dst) != p)) { + br_fdb_dst_port(fdb) != p)) { err = -EINVAL; goto err_unlock; } WRITE_ONCE(fdb->updated, jiffies); - if (READ_ONCE(fdb->dst) != p) { - WRITE_ONCE(fdb->dst, p); + if (br_fdb_dst_port(fdb) != p) { + br_fdb_dst_write(fdb, br_port_to_dst(p)); modified = true; } @@ -1632,7 +1635,7 @@ void br_fdb_clear_offload(const struct net_device *dev, u16 vid) spin_lock_bh(&p->br->hash_lock); hlist_for_each_entry(f, &p->br->fdb_list, fdb_node) { - if (READ_ONCE(f->dst) == p && f->key.vlan_id == vid) + if (br_fdb_dst_port(f) == p && f->key.vlan_id == vid) clear_bit(BR_FDB_OFFLOADED, &f->flags); } spin_unlock_bh(&p->br->hash_lock); diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 4357d78524a6..68aa8fa52eba 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -123,7 +123,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb br_fdb_update(br, p, eth_hdr(skb)->h_source, vid, BIT(BR_FDB_LOCKED)); goto drop; - } else if (READ_ONCE(fdb_src->dst) != p || + } else if (br_fdb_dst_port(fdb_src) != p || test_bit(BR_FDB_LOCAL, &fdb_src->flags)) { /* FDB mismatch. Drop the packet without roaming. */ goto drop; @@ -223,7 +223,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb if (now != READ_ONCE(dst->used)) WRITE_ONCE(dst->used, now); - br_forward(READ_ONCE(dst->dst), skb, local_rcv, false); + br_forward(br_fdb_dst_port(dst), skb, local_rcv, false); } else { if (!mcast_hit) br_flood(br, vlan, skb, pkt_type, local_rcv, false); diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 1146187aa2ba..bbb59b53e745 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -312,7 +312,7 @@ struct net_bridge_dst { struct net_bridge_fdb_entry { struct rhash_head rhnode; - struct net_bridge_port *dst; + struct net_bridge_dst dst; struct net_bridge_fdb_key key; struct hlist_node fdb_node; @@ -708,6 +708,24 @@ br_dst_port(struct net_bridge_dst dst) return (struct net_bridge_port *)ACCESS_PRIVATE(&dst, value); } +static inline struct net_bridge_dst +br_fdb_dst_read(const struct net_bridge_fdb_entry *fdb) +{ + return br_dst_read(&fdb->dst); +} + +static inline void br_fdb_dst_write(struct net_bridge_fdb_entry *fdb, + struct net_bridge_dst dst) +{ + br_dst_write(&fdb->dst, dst); +} + +static inline struct net_bridge_port * +br_fdb_dst_port(const struct net_bridge_fdb_entry *fdb) +{ + return br_dst_port(br_fdb_dst_read(fdb)); +} + /* called under bridge lock */ static inline int br_is_root_bridge(const struct net_bridge *br) { diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index 990c6b38fd39..10f3aea6a1f8 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -129,7 +129,7 @@ static void br_switchdev_fdb_populate(struct net_bridge *br, const struct net_bridge_fdb_entry *fdb, const void *ctx) { - const struct net_bridge_port *p = READ_ONCE(fdb->dst); + const struct net_bridge_port *p = br_fdb_dst_port(fdb); item->addr = fdb->key.addr.addr; item->vid = fdb->key.vlan_id; From a39c339fd6c5b333db8050260ac562842d3f7734 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:02 +0300 Subject: [PATCH 1023/2126] net: bridge: add VLAN support to bridge destinations Use bit 0 to distinguish port-VLAN pointers from bridge port pointers in struct net_bridge_dst. Add helpers for constructing and decoding VLAN destinations. No caller creates one yet, so behavior remains unchanged. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-4-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_private.h | 50 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index bbb59b53e745..2bf7f4429a3b 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -306,6 +306,8 @@ struct net_bridge_fdb_key { u16 vlan_id; }; +#define BR_DST_VLAN_TAG BIT(0) + struct net_bridge_dst { unsigned long __private value; }; @@ -702,10 +704,56 @@ br_port_to_dst(const struct net_bridge_port *p) return dst; } +static inline struct net_bridge_dst +br_vlan_to_dst(const struct net_bridge_vlan *v) +{ + struct net_bridge_dst dst; + + ACCESS_PRIVATE(&dst, value) = (unsigned long)v | BR_DST_VLAN_TAG; + + return dst; +} + +static inline void br_dst_decode(struct net_bridge_dst dst, + struct net_bridge_port **port, + struct net_bridge_vlan **vlan) +{ + struct net_bridge_vlan *v; + unsigned long value; + + value = ACCESS_PRIVATE(&dst, value); + if (!(value & BR_DST_VLAN_TAG)) { + *port = (struct net_bridge_port *)value; + *vlan = NULL; + return; + } + + v = (struct net_bridge_vlan *)(value & ~BR_DST_VLAN_TAG); + *port = v->port; + *vlan = v; +} + static inline struct net_bridge_port * br_dst_port(struct net_bridge_dst dst) { - return (struct net_bridge_port *)ACCESS_PRIVATE(&dst, value); + struct net_bridge_port *p; + struct net_bridge_vlan *v; + + br_dst_decode(dst, &p, &v); + + return p; +} + +static inline struct net_bridge_vlan * +br_dst_vlan(struct net_bridge_dst dst) +{ + unsigned long value; + + value = ACCESS_PRIVATE(&dst, value); + if (!(value & BR_DST_VLAN_TAG)) + return NULL; + + return (struct net_bridge_vlan *)(value & ~BR_DST_VLAN_TAG); } static inline struct net_bridge_dst From cebd6130e6c26909aa792f785ecc82939d095767 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:03 +0300 Subject: [PATCH 1024/2126] net: bridge: vlan: return VLAN entries from ingress helpers Have the ingress helpers return the resolved vlan entry directly and let callers derive the vid from it. This keeps the vlan available for later fdb operations without carrying parallel vlan pointer and vid. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-5-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_device.c | 5 +++-- net/bridge/br_input.c | 14 ++++++++------ net/bridge/br_private.h | 12 +++++++----- net/bridge/br_vlan.c | 38 +++++++++++++++++++++----------------- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index c6804409b60b..2423d69f2498 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -65,9 +65,10 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) skb_reset_mac_header(skb); skb_pull(skb, ETH_HLEN); - if (!br_allowed_ingress(br, br_vlan_group_rcu(br), skb, &vid, - &state, &vlan)) + if (!br_allowed_ingress(br, br_vlan_group_rcu(br), skb, &state, + &vlan)) goto out; + vid = vlan ? vlan->vid : 0; if (IS_ENABLED(CONFIG_INET) && (eth_hdr(skb)->h_proto == htons(ETH_P_ARP) || diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 68aa8fa52eba..d9a0e1f65ec9 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -86,8 +86,8 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb struct net_bridge_vlan *vlan; struct net_bridge *br; bool promisc; - u16 vid = 0; u8 state; + u16 vid; if (!p) goto drop; @@ -107,9 +107,10 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb brmctx = &p->br->multicast_ctx; pmctx = &p->multicast_ctx; - if (!br_allowed_ingress(p->br, nbp_vlan_group_rcu(p), skb, &vid, - &state, &vlan)) + if (!br_allowed_ingress(p->br, nbp_vlan_group_rcu(p), skb, &state, + &vlan)) goto out; + vid = vlan ? vlan->vid : 0; if (test_bit(BR_PORT_LOCKED_BIT, &p->flags)) { struct net_bridge_fdb_entry *fdb_src = @@ -245,14 +246,15 @@ EXPORT_SYMBOL_GPL(br_handle_frame_finish); static void __br_handle_local_finish(struct sk_buff *skb) { struct net_bridge_port *p = br_port_get_rcu(skb->dev); - u16 vid = 0; + struct net_bridge_vlan *vlan; /* check if vlan is allowed, to avoid spoofing */ if (test_bit(BR_LEARNING_BIT, &p->flags) && nbp_state_should_learn(p) && !br_opt_get(p->br, BROPT_NO_LL_LEARN) && - br_should_learn(p, skb, &vid)) - br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, 0); + br_should_learn(p, skb, &vlan)) + br_fdb_update(p->br, p, eth_hdr(skb)->h_source, + vlan ? vlan->vid : 0, 0); } /* note: already called with rcu_read_lock */ diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 2bf7f4429a3b..34e95741b940 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1702,11 +1702,11 @@ br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, #ifdef CONFIG_BRIDGE_VLAN_FILTERING bool br_allowed_ingress(const struct net_bridge *br, struct net_bridge_vlan_group *vg, struct sk_buff *skb, - u16 *vid, u8 *state, - struct net_bridge_vlan **vlan); + u8 *state, struct net_bridge_vlan **vlan); bool br_allowed_egress(struct net_bridge_vlan_group *vg, const struct sk_buff *skb); -bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); +bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, + struct net_bridge_vlan **vlan); struct sk_buff *br_handle_vlan(struct net_bridge *br, const struct net_bridge_port *port, struct net_bridge_vlan_group *vg, @@ -1825,7 +1825,7 @@ static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) static inline bool br_allowed_ingress(const struct net_bridge *br, struct net_bridge_vlan_group *vg, struct sk_buff *skb, - u16 *vid, u8 *state, + u8 *state, struct net_bridge_vlan **vlan) { @@ -1840,8 +1840,10 @@ static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, } static inline bool br_should_learn(struct net_bridge_port *p, - struct sk_buff *skb, u16 *vid) + struct sk_buff *skb, + struct net_bridge_vlan **vlan) { + *vlan = NULL; return true; } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index ce5aa15c4540..471b4e7f0571 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -583,13 +583,13 @@ out: /* Called under RCU */ static bool __allowed_ingress(const struct net_bridge *br, struct net_bridge_vlan_group *vg, - struct sk_buff *skb, u16 *vid, - u8 *state, + struct sk_buff *skb, u8 *state, struct net_bridge_vlan **vlan) { struct pcpu_sw_netstats *stats; struct net_bridge_vlan *v; bool tagged; + u16 vid; BR_INPUT_SKB_CB(skb)->vlan_filtered = true; /* If vlan tx offload is disabled on bridge device and frame was @@ -603,7 +603,7 @@ static bool __allowed_ingress(const struct net_bridge *br, return false; } - if (!br_vlan_get_tag(skb, vid)) { + if (!br_vlan_get_tag(skb, &vid)) { /* Tagged frame */ if (skb->vlan_proto != br->vlan_proto) { /* Protocol-mismatch, empty out vlan_tci for new tag */ @@ -615,7 +615,7 @@ static bool __allowed_ingress(const struct net_bridge *br, skb_pull(skb, ETH_HLEN); skb_reset_mac_len(skb); - *vid = 0; + vid = 0; tagged = false; } else { tagged = true; @@ -625,7 +625,7 @@ static bool __allowed_ingress(const struct net_bridge *br, tagged = false; } - if (!*vid) { + if (!vid) { v = vg ? rcu_dereference(vg->pvid) : NULL; /* Frame had a tag with VID 0 or did not have a tag. * See if pvid is set on this port. That tells us which @@ -637,7 +637,6 @@ static bool __allowed_ingress(const struct net_bridge *br, /* PVID is set on this port. Any untagged or priority-tagged * ingress frame is considered to belong to this vlan. */ - *vid = v->vid; if (likely(!tagged)) /* Untagged Frame. */ __vlan_hwaccel_put_tag(skb, br->vlan_proto, v->vid); @@ -649,7 +648,7 @@ static bool __allowed_ingress(const struct net_bridge *br, */ skb->vlan_tci |= v->vid; } else { - v = br_vlan_find(vg, *vid); + v = br_vlan_find(vg, vid); } if (!v || !br_vlan_should_use(v)) @@ -680,8 +679,7 @@ drop: bool br_allowed_ingress(const struct net_bridge *br, struct net_bridge_vlan_group *vg, struct sk_buff *skb, - u16 *vid, u8 *state, - struct net_bridge_vlan **vlan) + u8 *state, struct net_bridge_vlan **vlan) { /* If VLAN filtering is disabled on the bridge, all packets are * permitted. @@ -692,7 +690,7 @@ bool br_allowed_ingress(const struct net_bridge *br, return true; } - return __allowed_ingress(br, vg, skb, vid, state, vlan); + return __allowed_ingress(br, vg, skb, state, vlan); } /* Called under RCU. */ @@ -716,11 +714,15 @@ bool br_allowed_egress(struct net_bridge_vlan_group *vg, } /* Called under RCU */ -bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) +bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, + struct net_bridge_vlan **vlan) { struct net_bridge_vlan_group *vg; struct net_bridge *br = p->br; struct net_bridge_vlan *v; + u16 vid; + + *vlan = NULL; /* If filtering was disabled at input, let it pass. */ if (!br_opt_get(br, BROPT_VLAN_ENABLED)) @@ -730,20 +732,22 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) if (!vg || !READ_ONCE(vg->num_vlans)) return false; - if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto) - *vid = 0; + if (!br_vlan_get_tag(skb, &vid) && skb->vlan_proto != br->vlan_proto) + vid = 0; - if (!*vid) { + if (!vid) { v = rcu_dereference(vg->pvid); if (!v || !br_vlan_state_allowed(br_vlan_get_state(v), true)) return false; - *vid = v->vid; + *vlan = v; return true; } - v = br_vlan_find(vg, *vid); - if (v && br_vlan_state_allowed(br_vlan_get_state(v), true)) + v = br_vlan_find(vg, vid); + if (v && br_vlan_state_allowed(br_vlan_get_state(v), true)) { + *vlan = v; return true; + } return false; } From 8247ef76032ba924c05346930e181d267c2072fb Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:04 +0300 Subject: [PATCH 1025/2126] net: bridge: fdb: pass VLAN entries to learning updates Pass the resolved VLAN entry through fdb learning paths and derive the vid inside br_fdb_update(). The fdb destination remains a port for now, this is a preparation for caching the VLAN. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-6-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 16 ++++++++++------ net/bridge/br_input.c | 12 ++++++------ net/bridge/br_private.h | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 0f5cf5615b56..9cd6deae8635 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -974,9 +974,11 @@ static bool __fdb_mark_active(struct net_bridge_fdb_entry *fdb) } void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, - const unsigned char *addr, u16 vid, unsigned long flags) + struct net_bridge_vlan *vlan, const unsigned char *addr, + unsigned long flags) { struct net_bridge_fdb_entry *fdb; + u16 vid = vlan ? vlan->vid : 0; /* some users want to always flood. */ if (hold_time(br) == 0) @@ -1247,9 +1249,11 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, struct net_bridge_port *p, const unsigned char *addr, - u16 nlh_flags, u16 vid, struct nlattr *nfea_tb[], + u16 nlh_flags, struct net_bridge_vlan *vlan, + struct nlattr *nfea_tb[], bool *notified, struct netlink_ext_ack *extack) { + u16 vid = vlan ? vlan->vid : 0; int err = 0; if (ndm->ndm_flags & NTF_USE) { @@ -1263,7 +1267,7 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, local_bh_disable(); rcu_read_lock(); - br_fdb_update(br, p, addr, vid, BIT(BR_FDB_ADDED_BY_USER)); + br_fdb_update(br, p, vlan, addr, BIT(BR_FDB_ADDED_BY_USER)); rcu_read_unlock(); local_bh_enable(); } else if (ndm->ndm_flags & NTF_EXT_LEARNED) { @@ -1355,10 +1359,10 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], } /* VID was specified, so use it. */ - err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid, nfea_tb, + err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v, nfea_tb, notified, extack); } else { - err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0, nfea_tb, + err = __br_fdb_add(ndm, br, p, addr, nlh_flags, NULL, nfea_tb, notified, extack); if (err || !vg || !vg->num_vlans) goto out; @@ -1370,7 +1374,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], list_for_each_entry(v, &vg->vlan_list, vlist) { if (!br_vlan_should_use(v)) continue; - err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid, + err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v, nfea_tb, notified, extack); if (err) goto out; diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index d9a0e1f65ec9..44a217d65e7f 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -121,8 +121,9 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb * and drop the packet. */ if (test_bit(BR_PORT_MAB_BIT, &p->flags)) - br_fdb_update(br, p, eth_hdr(skb)->h_source, - vid, BIT(BR_FDB_LOCKED)); + br_fdb_update(br, p, vlan, + eth_hdr(skb)->h_source, + BIT(BR_FDB_LOCKED)); goto drop; } else if (br_fdb_dst_port(fdb_src) != p || test_bit(BR_FDB_LOCAL, &fdb_src->flags)) { @@ -132,7 +133,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb /* FDB match, but entry is locked. Refresh it and drop * the packet. */ - br_fdb_update(br, p, eth_hdr(skb)->h_source, vid, + br_fdb_update(br, p, vlan, eth_hdr(skb)->h_source, BIT(BR_FDB_LOCKED)); goto drop; } @@ -142,7 +143,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb /* insert into forwarding database after filtering to avoid spoofing */ if (test_bit(BR_LEARNING_BIT, &p->flags)) - br_fdb_update(br, p, eth_hdr(skb)->h_source, vid, 0); + br_fdb_update(br, p, vlan, eth_hdr(skb)->h_source, 0); promisc = !!(br->dev->flags & IFF_PROMISC); local_rcv = promisc; @@ -253,8 +254,7 @@ static void __br_handle_local_finish(struct sk_buff *skb) nbp_state_should_learn(p) && !br_opt_get(p->br, BROPT_NO_LL_LEARN) && br_should_learn(p, skb, &vlan)) - br_fdb_update(p->br, p, eth_hdr(skb)->h_source, - vlan ? vlan->vid : 0, 0); + br_fdb_update(p->br, p, vlan, eth_hdr(skb)->h_source, 0); } /* note: already called with rcu_read_lock */ diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 34e95741b940..058cc082311a 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -993,7 +993,8 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count, int br_fdb_add_local(struct net_bridge *br, struct net_bridge_port *source, const unsigned char *addr, u16 vid); void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, - const unsigned char *addr, u16 vid, unsigned long flags); + struct net_bridge_vlan *vlan, const unsigned char *addr, + unsigned long flags); int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], struct net_device *dev, const unsigned char *addr, u16 vid, From f0a349b921205e4af450c0d50fcd9f46317019e6 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:05 +0300 Subject: [PATCH 1026/2126] net: bridge: fdb: consolidate port-VLAN cleanup Deleting a port-VLAN currently takes the hash_lock twice and performs two fdb ops. The first removes its automatically generated local entry and the second deletes dynamic entries associated with the port and vid. Rename br_fdb_delete_by_port() to br_fdb_cleanup_by_dst() and pass a bridge dst so it can distinguish a port-VLAN from a raw port. This allows both operations to be done during the same locked fdb walk. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-7-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br.c | 2 +- net/bridge/br_fdb.c | 17 +++++++++++++---- net/bridge/br_if.c | 6 +++--- net/bridge/br_netlink.c | 2 +- net/bridge/br_private.h | 4 ++-- net/bridge/br_stp_if.c | 2 +- net/bridge/br_sysfs_if.c | 3 ++- net/bridge/br_vlan.c | 5 ++--- 8 files changed, 25 insertions(+), 16 deletions(-) diff --git a/net/bridge/br.c b/net/bridge/br.c index c602d6305997..d9a39ff98868 100644 --- a/net/bridge/br.c +++ b/net/bridge/br.c @@ -200,7 +200,7 @@ static int br_switchdev_event(struct notifier_block *unused, case SWITCHDEV_FDB_FLUSH_TO_BRIDGE: fdb_info = ptr; /* Don't delete static entries */ - br_fdb_delete_by_port(br, p, fdb_info->vid, 0); + br_fdb_cleanup_by_dst(br, br_port_to_dst(p), fdb_info->vid, 0); break; } diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 9cd6deae8635..7c68b540b358 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -868,15 +868,16 @@ int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev, return 0; } -/* Flush all entries referring to a specific port. +/* Clean up all entries referring to a specific destination. * if do_all is set also flush static entries * if vid is set delete all entries that match the vlan_id */ -void br_fdb_delete_by_port(struct net_bridge *br, - const struct net_bridge_port *p, - u16 vid, +void br_fdb_cleanup_by_dst(struct net_bridge *br, + struct net_bridge_dst cleanup_dst, u16 vid, int do_all) { + const struct net_bridge_vlan *vlan = br_dst_vlan(cleanup_dst); + const struct net_bridge_port *p = br_dst_port(cleanup_dst); struct net_bridge_fdb_entry *f; struct hlist_node *tmp; @@ -885,6 +886,14 @@ void br_fdb_delete_by_port(struct net_bridge *br, if (br_fdb_dst_port(f) != p) continue; + if (vlan && f->key.vlan_id == vlan->vid && + test_bit(BR_FDB_LOCAL, &f->flags) && + !test_bit(BR_FDB_ADDED_BY_USER, &f->flags) && + ether_addr_equal(f->key.addr.addr, p->dev->dev_addr)) { + fdb_delete_local(br, p, f); + continue; + } + if (!do_all) if (test_bit(BR_FDB_STATIC, &f->flags) || (test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags) && diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index c52613431f88..d94558a5e3e9 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -355,7 +355,7 @@ static void del_nbp(struct net_bridge_port *p) netdev_reset_rx_headroom(dev); nbp_vlan_flush(p); - br_fdb_delete_by_port(br, p, 0, 1); + br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 1); switchdev_deferred_process(); nbp_backup_clear(p); @@ -390,7 +390,7 @@ void br_dev_delete(struct net_device *dev, struct list_head *head) br_mst_uninit(br); br_recalculate_neigh_suppress_enabled(br); - br_fdb_delete_by_port(br, NULL, 0, 1); + br_fdb_cleanup_by_dst(br, br_port_to_dst(NULL), 0, 1); timer_shutdown_sync(&br->hello_timer); timer_shutdown_sync(&br->topology_change_timer); @@ -696,7 +696,7 @@ err6: if (fdb_synced) br_fdb_unsync_static(br, p); list_del_rcu(&p->list); - br_fdb_delete_by_port(br, p, 0, 1); + br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 1); nbp_update_port_count(br); netdev_upper_dev_unlink(dev, br->dev); err5: diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index ae76df0de05a..f65b8b6ca97c 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1044,7 +1044,7 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[], } if (tb[IFLA_BRPORT_FLUSH]) - br_fdb_delete_by_port(p->br, p, 0, 0); + br_fdb_cleanup_by_dst(p->br, br_port_to_dst(p), 0, 0); #ifdef CONFIG_BRIDGE_IGMP_SNOOPING if (tb[IFLA_BRPORT_MULTICAST_ROUTER]) { diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 058cc082311a..a790368b69e9 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -983,8 +983,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); void br_fdb_cleanup(struct work_struct *work); int br_fdb_toggle_local_vlan_0(struct net_bridge *br, bool on, struct netlink_ext_ack *extack); -void br_fdb_delete_by_port(struct net_bridge *br, - const struct net_bridge_port *p, u16 vid, int do_all); +void br_fdb_cleanup_by_dst(struct net_bridge *br, + struct net_bridge_dst dst, u16 vid, int do_all); struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, const unsigned char *addr, __u16 vid); diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c index a7e5422eb5d1..2e5190278c90 100644 --- a/net/bridge/br_stp_if.c +++ b/net/bridge/br_stp_if.c @@ -114,7 +114,7 @@ void br_stp_disable_port(struct net_bridge_port *p) timer_delete(&p->hold_timer); if (!rcu_access_pointer(p->backup_port)) - br_fdb_delete_by_port(br, p, 0, 0); + br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 0); br_multicast_disable_port(p); br_configuration_update(br); diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c index b9bcafa7f034..621d62a063d9 100644 --- a/net/bridge/br_sysfs_if.c +++ b/net/bridge/br_sysfs_if.c @@ -191,7 +191,8 @@ static BRPORT_ATTR(hold_timer, 0444, show_hold_timer, NULL); static int store_flush(struct net_bridge_port *p, unsigned long v) { - br_fdb_delete_by_port(p->br, p, 0, 0); // Don't delete local entry + /* Don't delete local entry */ + br_fdb_cleanup_by_dst(p->br, br_port_to_dst(p), 0, 0); return 0; } static BRPORT_ATTR(flush, 0200, NULL, store_flush); diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 471b4e7f0571..7ba6e57b18fa 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -870,7 +870,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid) return -ENOENT; br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid); - br_fdb_delete_by_port(br, NULL, vid, 0); + br_fdb_cleanup_by_dst(br, br_port_to_dst(NULL), vid, 0); vlan_tunnel_info_del(vg, v); __vlan_del(v); @@ -1396,8 +1396,7 @@ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) v = br_vlan_find(nbp_vlan_group(port), vid); if (!v) return -ENOENT; - br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid); - br_fdb_delete_by_port(port->br, port, vid, 0); + br_fdb_cleanup_by_dst(port->br, br_vlan_to_dst(v), vid, 0); __vlan_del(v); return 0; From e5c71bf91447447241736d44291e67784548585e Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:06 +0300 Subject: [PATCH 1027/2126] net: bridge: vlan: split unpublishing from deletion Split removal of a VLAN from its lookup and flood structures from object destruction. Pass the VLAN group explicitly to __vlan_del() and call both operations consecutively for now. This prepares deletion paths to quiesce readers after making an entry unreachable and before freeing it. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-8-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_vlan.c | 45 +++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 7ba6e57b18fa..8a914e249767 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -429,22 +429,34 @@ out_filt: goto out; } -static void __vlan_del(struct net_bridge_vlan *v) +static void __vlan_unpublish(struct net_bridge_vlan_group *vg, + struct net_bridge_vlan *v) +{ + __vlan_delete_pvid(vg, v); + if (!br_vlan_is_master(v)) { + struct net_bridge_vlan *masterv = v->brvlan; + + rhashtable_remove_fast(&vg->vlan_hash, &v->vnode, + br_vlan_rht_params); + __vlan_del_list(v); + /* -1 because br_vlan_put_master() is called later */ + br_vlan_rebuild_port_array(masterv, + br_vlan_num_ports(masterv) - 1); + } +} + +static void __vlan_del(struct net_bridge_vlan_group *vg, + struct net_bridge_vlan *v) { struct net_bridge_vlan *masterv = v; - struct net_bridge_vlan_group *vg; struct net_bridge_port *p = NULL; int err; - if (br_vlan_is_master(v)) { - vg = br_vlan_group(v->br); - } else { + if (!br_vlan_is_master(v)) { p = v->port; - vg = nbp_vlan_group(v->port); masterv = v->brvlan; } - __vlan_delete_pvid(vg, v); if (p) { err = __vlan_vid_del(p->dev, p->br, v); if (err) @@ -467,12 +479,6 @@ static void __vlan_del(struct net_bridge_vlan *v) if (masterv != v) { vlan_tunnel_info_del(vg, v); - rhashtable_remove_fast(&vg->vlan_hash, &v->vnode, - br_vlan_rht_params); - __vlan_del_list(v); - /* -1 because br_vlan_put_master() is called later */ - br_vlan_rebuild_port_array(masterv, - br_vlan_num_ports(masterv) - 1); nbp_vlan_set_vlan_dev_state(p, v->vid); br_multicast_toggle_one_vlan(v, false); br_multicast_port_ctx_deinit(&v->port_mcast_ctx); @@ -509,7 +515,8 @@ static void __vlan_flush(const struct net_bridge *br, } v_end = vlan->vid; - __vlan_del(vlan); + __vlan_unpublish(vg, vlan); + __vlan_del(vg, vlan); } /* notify about the last/whole vlan range */ @@ -873,7 +880,8 @@ int br_vlan_delete(struct net_bridge *br, u16 vid) br_fdb_cleanup_by_dst(br, br_port_to_dst(NULL), vid, 0); vlan_tunnel_info_del(vg, v); - __vlan_del(v); + __vlan_unpublish(vg, v); + __vlan_del(vg, v); return 0; } @@ -1389,15 +1397,18 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, */ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) { + struct net_bridge_vlan_group *vg; struct net_bridge_vlan *v; ASSERT_RTNL(); - v = br_vlan_find(nbp_vlan_group(port), vid); + vg = nbp_vlan_group(port); + v = br_vlan_find(vg, vid); if (!v) return -ENOENT; br_fdb_cleanup_by_dst(port->br, br_vlan_to_dst(v), vid, 0); - __vlan_del(v); + __vlan_unpublish(vg, v); + __vlan_del(vg, v); return 0; } From 83edc87a91725592ea8cb241e29d9a72e4f61e36 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:07 +0300 Subject: [PATCH 1028/2126] net: bridge: vlan: quiesce readers before freeing port VLANs Later fdb entries will cache port-VLAN pointers so unpublish a VLAN, wait for a grace period (existing readers) and then purge or rewrite fdb references before releasing it. Cached destinations can continue forwarding until they are cleaned, that is acceptable so add a comment to document it. During port teardown unpublish the complete VLAN group first, clean the port fdbs and then release the VLANs. This lets all VLANs share one grace period. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-9-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 20 ++++++++++++++++---- net/bridge/br_if.c | 7 +++++-- net/bridge/br_private.h | 12 ++++++++++-- net/bridge/br_vlan.c | 21 +++++++++++++++------ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 7c68b540b358..307f9c12914e 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -883,7 +883,9 @@ void br_fdb_cleanup_by_dst(struct net_bridge *br, spin_lock_bh(&br->hash_lock); hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) { - if (br_fdb_dst_port(f) != p) + struct net_bridge_dst dst = br_fdb_dst_read(f); + + if (br_dst_port(dst) != p) continue; if (vlan && f->key.vlan_id == vlan->vid && @@ -894,12 +896,22 @@ void br_fdb_cleanup_by_dst(struct net_bridge *br, continue; } - if (!do_all) + if (!do_all) { + if (vid && f->key.vlan_id != vid) + continue; + if (test_bit(BR_FDB_STATIC, &f->flags) || (test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags) && - !test_bit(BR_FDB_OFFLOADED, &f->flags)) || - (vid && f->key.vlan_id != vid)) + !test_bit(BR_FDB_OFFLOADED, &f->flags))) { + /* The entry outlives the VLAN, so it must fall + * back to the raw port destination + */ + if (vlan && br_dst_vlan(dst) == vlan) + br_fdb_dst_write(f, + br_port_to_dst(p)); continue; + } + } if (test_bit(BR_FDB_LOCAL, &f->flags)) fdb_delete_local(br, p, f); diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index d94558a5e3e9..2c05ebc1299d 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -333,8 +333,9 @@ static void update_headroom(struct net_bridge *br, int new_hr) */ static void del_nbp(struct net_bridge_port *p) { - struct net_bridge *br = p->br; + struct net_bridge_vlan_group *vg; struct net_device *dev = p->dev; + struct net_bridge *br = p->br; sysfs_remove_link(br->ifobj, p->dev->name); @@ -354,8 +355,10 @@ static void del_nbp(struct net_bridge_port *p) update_headroom(br, get_max_headroom(br)); netdev_reset_rx_headroom(dev); - nbp_vlan_flush(p); + vg = nbp_vlan_group(p); + nbp_vlan_group_unpublish(p); br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 1); + nbp_vlan_flush(p, vg); switchdev_deferred_process(); nbp_backup_clear(p); diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index a790368b69e9..951b6ac5f484 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1735,7 +1735,9 @@ int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, bool *changed, struct netlink_ext_ack *extack); int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); -void nbp_vlan_flush(struct net_bridge_port *port); +void nbp_vlan_group_unpublish(struct net_bridge_port *port); +void nbp_vlan_flush(struct net_bridge_port *port, + struct net_bridge_vlan_group *vg); int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); void br_vlan_get_stats(const struct net_bridge_vlan *v, @@ -1894,7 +1896,13 @@ static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) return -EOPNOTSUPP; } -static inline void nbp_vlan_flush(struct net_bridge_port *port) +static inline void nbp_vlan_group_unpublish(struct net_bridge_port *port) +{ +} + +static inline void +nbp_vlan_flush(struct net_bridge_port *port, + struct net_bridge_vlan_group *vg) { } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 8a914e249767..0675f74cf1b9 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -1406,23 +1406,32 @@ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) v = br_vlan_find(vg, vid); if (!v) return -ENOENT; - br_fdb_cleanup_by_dst(port->br, br_vlan_to_dst(v), vid, 0); __vlan_unpublish(vg, v); + synchronize_net(); + /* Traffic may still use v through cached fdb dsts until they are + * cleaned below. This is acceptable during vlan deletion. Above we + * drain the readers that could republish the dst before cleaning it + */ + br_fdb_cleanup_by_dst(port->br, br_vlan_to_dst(v), vid, 0); __vlan_del(vg, v); return 0; } -void nbp_vlan_flush(struct net_bridge_port *port) +void nbp_vlan_group_unpublish(struct net_bridge_port *port) { - struct net_bridge_vlan_group *vg; - ASSERT_RTNL(); - vg = nbp_vlan_group(port); - __vlan_flush(port->br, port, vg); RCU_INIT_POINTER(port->vlgrp, NULL); synchronize_net(); +} + +void nbp_vlan_flush(struct net_bridge_port *port, + struct net_bridge_vlan_group *vg) +{ + ASSERT_RTNL(); + + __vlan_flush(port->br, port, vg); __vlan_group_free(vg); } From 941056f91907fd2e281ba94c3203d4b84d9974ca Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:08 +0300 Subject: [PATCH 1029/2126] net: bridge: fdb: factor out existing entry updates Move the existing fdb entry update path out of br_fdb_update() into __fdb_update(). This reduces nesting in br_fdb_update() and keeps the lookup and creation flow separate from updates to an entry that was found. No functional changes intended. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-10-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 96 +++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 307f9c12914e..b87c6f8875da 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -994,6 +994,55 @@ static bool __fdb_mark_active(struct net_bridge_fdb_entry *fdb) test_and_clear_bit(BR_FDB_NOTIFY_INACTIVE, &fdb->flags)); } +static void __fdb_update(struct net_bridge *br, + struct net_bridge_fdb_entry *fdb, + struct net_bridge_port *source, + const unsigned char *addr, u16 vid, + unsigned long flags) +{ + bool fdb_modified = false; + unsigned long now; + + /* attempt to update an entry for a local interface */ + if (unlikely(test_bit(BR_FDB_LOCAL, &fdb->flags))) { + if (net_ratelimit()) + br_warn(br, "received packet on %s with own address as source address (addr:%pM, vlan:%u)\n", + source->dev->name, addr, vid); + return; + } + + now = jiffies; + if (now != READ_ONCE(fdb->updated)) { + WRITE_ONCE(fdb->updated, now); + fdb_modified = __fdb_mark_active(fdb); + } + + /* fastpath: update of existing entry */ + if (unlikely(source != br_fdb_dst_port(fdb) && + !test_bit(BR_FDB_STICKY, &fdb->flags))) { + br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH); + br_fdb_dst_write(fdb, br_port_to_dst(source)); + fdb_modified = true; + /* Take over HW learned entry */ + if (unlikely(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))) + clear_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags); + /* Clear locked flag when roaming to an unlocked port */ + if (unlikely(test_bit(BR_FDB_LOCKED, &fdb->flags))) + clear_bit(BR_FDB_LOCKED, &fdb->flags); + } + + if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) { + set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); + if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags)) + atomic_dec(&br->fdb_n_learned); + } + + if (unlikely(fdb_modified)) { + trace_br_fdb_update(br, source, addr, vid, flags); + fdb_notify(br, fdb, RTM_NEWNEIGH, true); + } +} + void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, struct net_bridge_vlan *vlan, const unsigned char *addr, unsigned long flags) @@ -1007,49 +1056,7 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid); if (likely(fdb)) { - /* attempt to update an entry for a local interface */ - if (unlikely(test_bit(BR_FDB_LOCAL, &fdb->flags))) { - if (net_ratelimit()) - br_warn(br, "received packet on %s with own address as source address (addr:%pM, vlan:%u)\n", - source->dev->name, addr, vid); - } else { - unsigned long now = jiffies; - bool fdb_modified = false; - - if (now != READ_ONCE(fdb->updated)) { - WRITE_ONCE(fdb->updated, now); - fdb_modified = __fdb_mark_active(fdb); - } - - /* fastpath: update of existing entry */ - if (unlikely(source != br_fdb_dst_port(fdb) && - !test_bit(BR_FDB_STICKY, &fdb->flags))) { - br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH); - br_fdb_dst_write(fdb, br_port_to_dst(source)); - fdb_modified = true; - /* Take over HW learned entry */ - if (unlikely(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, - &fdb->flags))) - clear_bit(BR_FDB_ADDED_BY_EXT_LEARN, - &fdb->flags); - /* Clear locked flag when roaming to an - * unlocked port. - */ - if (unlikely(test_bit(BR_FDB_LOCKED, &fdb->flags))) - clear_bit(BR_FDB_LOCKED, &fdb->flags); - } - - if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) { - set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); - if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, - &fdb->flags)) - atomic_dec(&br->fdb_n_learned); - } - if (unlikely(fdb_modified)) { - trace_br_fdb_update(br, source, addr, vid, flags); - fdb_notify(br, fdb, RTM_NEWNEIGH, true); - } - } + __fdb_update(br, fdb, source, addr, vid, flags); } else { spin_lock(&br->hash_lock); fdb = fdb_create(br, source, addr, vid, flags); @@ -1057,9 +1064,6 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, trace_br_fdb_update(br, source, addr, vid, flags); fdb_notify(br, fdb, RTM_NEWNEIGH, true); } - /* else we lose race and someone else inserts - * it first, don't bother updating - */ spin_unlock(&br->hash_lock); } } From 8009eb405fc610d541731fcb95dde0ff6808b857 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:09 +0300 Subject: [PATCH 1030/2126] net: bridge: fdb: cache port VLANs in learned entries Store the resolved port-VLAN as the destination of dynamically learned FDB entries. Roaming updates the destination directly, while an existing raw port destination is conditionally upgraded without generating a spurious notification. Conditional replacements prevent both this upgrade and a VLAN deletion fallback from overwriting a concurrent roam. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-11-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 57 ++++++++++++++++++++++++++--------------- net/bridge/br_private.h | 18 +++++++++++++ 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index b87c6f8875da..5664f3d649fa 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -385,7 +385,7 @@ void br_fdb_find_delete_local(struct net_bridge *br, } static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, - struct net_bridge_port *source, + struct net_bridge_dst dst, const unsigned char *addr, __u16 vid, unsigned long flags) @@ -409,7 +409,7 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, return NULL; memcpy(fdb->key.addr.addr, addr, ETH_ALEN); - br_fdb_dst_write(fdb, br_port_to_dst(source)); + br_fdb_dst_write(fdb, dst); fdb->key.vlan_id = vid; fdb->flags = flags; fdb->updated = fdb->used = jiffies; @@ -448,7 +448,7 @@ static int fdb_add_local(struct net_bridge *br, struct net_bridge_port *source, fdb_delete(br, fdb, true); } - fdb = fdb_create(br, source, addr, vid, + fdb = fdb_create(br, br_port_to_dst(source), addr, vid, BIT(BR_FDB_LOCAL) | BIT(BR_FDB_STATIC)); if (!fdb) return -ENOMEM; @@ -907,8 +907,8 @@ void br_fdb_cleanup_by_dst(struct net_bridge *br, * back to the raw port destination */ if (vlan && br_dst_vlan(dst) == vlan) - br_fdb_dst_write(f, - br_port_to_dst(p)); + br_fdb_dst_replace(f, dst, + br_port_to_dst(p)); continue; } } @@ -997,9 +997,12 @@ static bool __fdb_mark_active(struct net_bridge_fdb_entry *fdb) static void __fdb_update(struct net_bridge *br, struct net_bridge_fdb_entry *fdb, struct net_bridge_port *source, + struct net_bridge_dst dst, const unsigned char *addr, u16 vid, unsigned long flags) { + struct net_bridge_port *old_port; + struct net_bridge_dst old_dst; bool fdb_modified = false; unsigned long now; @@ -1017,18 +1020,30 @@ static void __fdb_update(struct net_bridge *br, fdb_modified = __fdb_mark_active(fdb); } + old_dst = br_fdb_dst_read(fdb); + old_port = br_dst_port(old_dst); /* fastpath: update of existing entry */ - if (unlikely(source != br_fdb_dst_port(fdb) && - !test_bit(BR_FDB_STICKY, &fdb->flags))) { - br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH); - br_fdb_dst_write(fdb, br_port_to_dst(source)); - fdb_modified = true; - /* Take over HW learned entry */ - if (unlikely(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))) - clear_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags); - /* Clear locked flag when roaming to an unlocked port */ - if (unlikely(test_bit(BR_FDB_LOCKED, &fdb->flags))) - clear_bit(BR_FDB_LOCKED, &fdb->flags); + if (unlikely(!br_dst_equal(dst, old_dst) && + (source == old_port || + !test_bit(BR_FDB_STICKY, &fdb->flags)))) { + if (source != old_port) { + br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH); + br_fdb_dst_write(fdb, dst); + fdb_modified = true; + /* take over HW learned entry */ + if (unlikely(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, + &fdb->flags))) + clear_bit(BR_FDB_ADDED_BY_EXT_LEARN, + &fdb->flags); + /* clear locked flag when roaming to an unlocked port */ + if (unlikely(test_bit(BR_FDB_LOCKED, &fdb->flags))) + clear_bit(BR_FDB_LOCKED, &fdb->flags); + } else { + /* raw port-to-VLAN promotion shouldn't overwrite a + * concurrent roam to another port + */ + br_fdb_dst_replace(fdb, old_dst, dst); + } } if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) { @@ -1047,6 +1062,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, struct net_bridge_vlan *vlan, const unsigned char *addr, unsigned long flags) { + struct net_bridge_dst dst = vlan ? br_vlan_to_dst(vlan) : + br_port_to_dst(source); struct net_bridge_fdb_entry *fdb; u16 vid = vlan ? vlan->vid : 0; @@ -1056,10 +1073,10 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid); if (likely(fdb)) { - __fdb_update(br, fdb, source, addr, vid, flags); + __fdb_update(br, fdb, source, dst, addr, vid, flags); } else { spin_lock(&br->hash_lock); - fdb = fdb_create(br, source, addr, vid, flags); + fdb = fdb_create(br, dst, addr, vid, flags); if (fdb) { trace_br_fdb_update(br, source, addr, vid, flags); fdb_notify(br, fdb, RTM_NEWNEIGH, true); @@ -1213,7 +1230,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, if (!(flags & NLM_F_CREATE)) return -ENOENT; - fdb = fdb_create(br, source, addr, vid, + fdb = fdb_create(br, br_port_to_dst(source), addr, vid, BIT(BR_FDB_ADDED_BY_USER)); if (!fdb) return -ENOMEM; @@ -1564,7 +1581,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, if (locked) flags |= BIT(BR_FDB_LOCKED); - fdb = fdb_create(br, p, addr, vid, flags); + fdb = fdb_create(br, br_port_to_dst(p), addr, vid, flags); if (!fdb) { err = -ENOMEM; goto err_unlock; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 951b6ac5f484..a1c5b1abc1ef 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -694,6 +694,13 @@ static inline void br_dst_write(struct net_bridge_dst *dst, ACCESS_PRIVATE(&src, value)); } +static inline bool br_dst_equal(struct net_bridge_dst dst1, + struct net_bridge_dst dst2) +{ + return ACCESS_PRIVATE(&dst1, value) == + ACCESS_PRIVATE(&dst2, value); +} + static inline struct net_bridge_dst br_port_to_dst(const struct net_bridge_port *p) { @@ -768,6 +775,17 @@ static inline void br_fdb_dst_write(struct net_bridge_fdb_entry *fdb, br_dst_write(&fdb->dst, dst); } +static inline bool +br_fdb_dst_replace(struct net_bridge_fdb_entry *fdb, + struct net_bridge_dst old, + struct net_bridge_dst new) +{ + unsigned long old_value = ACCESS_PRIVATE(&old, value); + + return cmpxchg(&ACCESS_PRIVATE(&fdb->dst, value), old_value, + ACCESS_PRIVATE(&new, value)) == old_value; +} + static inline struct net_bridge_port * br_fdb_dst_port(const struct net_bridge_fdb_entry *fdb) { From 8533e9b85bd23e6c8ab0e9c3f2d5574d1a33c1b8 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:10 +0300 Subject: [PATCH 1031/2126] net: bridge: fdb: cache VLAN destinations in configured entries Use the known port-VLAN destination for user-configured fdb entries and resolve switchdev vids with an fdb helper. VLAN 0, bridge entries and unconfigured switchdev vids retain raw port destinations. Keep the vid alongside the destination because it remains part of the fdb key. Use conditional replacement for same port destination upgrades so they don't overwrite a concurrent packet-learned roam. Port changing updates remain direct and report a forwarding change. Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-12-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 61 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 5664f3d649fa..730b178cf6c4 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -1192,10 +1192,11 @@ static bool fdb_handle_notify(struct net_bridge_fdb_entry *fdb, u8 notify) } /* Update (create or replace) forwarding database entry */ -static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, +static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst, const u8 *addr, struct ndmsg *ndm, u16 flags, u16 vid, struct nlattr *nfea_tb[]) { + struct net_bridge_port *source = br_dst_port(dst); bool is_sticky = !!(ndm->ndm_flags & NTF_STICKY); bool refresh = !nfea_tb[NFEA_DONT_REFRESH]; struct net_bridge_fdb_entry *fdb; @@ -1230,19 +1231,26 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, if (!(flags & NLM_F_CREATE)) return -ENOENT; - fdb = fdb_create(br, br_port_to_dst(source), addr, vid, + fdb = fdb_create(br, dst, addr, vid, BIT(BR_FDB_ADDED_BY_USER)); if (!fdb) return -ENOMEM; modified = true; } else { + struct net_bridge_dst old_dst; + if (flags & NLM_F_EXCL) return -EEXIST; - if (br_fdb_dst_port(fdb) != source) { - br_fdb_dst_write(fdb, br_port_to_dst(source)); - modified = true; + old_dst = br_fdb_dst_read(fdb); + if (!br_dst_equal(old_dst, dst)) { + if (br_dst_port(old_dst) != source) { + modified = true; + br_fdb_dst_write(fdb, dst); + } else { + br_fdb_dst_replace(fdb, old_dst, dst); + } } set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); @@ -1296,6 +1304,7 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, bool *notified, struct netlink_ext_ack *extack) { u16 vid = vlan ? vlan->vid : 0; + struct net_bridge_dst dst; int err = 0; if (ndm->ndm_flags & NTF_USE) { @@ -1320,8 +1329,10 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, } err = br_fdb_external_learn_add(br, p, addr, vid, false, true); } else { + dst = p && vlan ? br_vlan_to_dst(vlan) : br_port_to_dst(p); spin_lock_bh(&br->hash_lock); - err = fdb_add_entry(br, p, addr, ndm, nlh_flags, vid, nfea_tb); + err = fdb_add_entry(br, dst, addr, ndm, nlh_flags, vid, + nfea_tb); spin_unlock_bh(&br->hash_lock); } @@ -1553,10 +1564,31 @@ void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p) rcu_read_unlock(); } +static struct net_bridge_dst br_fdb_resolve_dst(const struct net_bridge_port *p, + u16 vid) +{ + struct net_bridge_dst dst = br_port_to_dst(p); + struct net_bridge_vlan *v; + + lockdep_assert(rcu_read_lock_held() || lockdep_rtnl_is_held()); + + if (!p || !vid) + return dst; + + rcu_read_lock(); + v = br_vlan_find(nbp_vlan_group_rcu(p), vid); + if (v) + dst = br_vlan_to_dst(v); + rcu_read_unlock(); + + return dst; +} + int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, const unsigned char *addr, u16 vid, bool locked, bool swdev_notify) { + struct net_bridge_dst dst = br_fdb_resolve_dst(p, vid); struct net_bridge_fdb_entry *fdb; bool modified = false; int err = 0; @@ -1581,25 +1613,32 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, if (locked) flags |= BIT(BR_FDB_LOCKED); - fdb = fdb_create(br, br_port_to_dst(p), addr, vid, flags); + fdb = fdb_create(br, dst, addr, vid, flags); if (!fdb) { err = -ENOMEM; goto err_unlock; } fdb_notify(br, fdb, RTM_NEWNEIGH, swdev_notify); } else { + struct net_bridge_dst old_dst; + + old_dst = br_fdb_dst_read(fdb); if (locked && (!test_bit(BR_FDB_LOCKED, &fdb->flags) || - br_fdb_dst_port(fdb) != p)) { + br_dst_port(old_dst) != p)) { err = -EINVAL; goto err_unlock; } WRITE_ONCE(fdb->updated, jiffies); - if (br_fdb_dst_port(fdb) != p) { - br_fdb_dst_write(fdb, br_port_to_dst(p)); - modified = true; + if (!br_dst_equal(old_dst, dst)) { + if (br_dst_port(old_dst) != p) { + modified = true; + br_fdb_dst_write(fdb, dst); + } else { + br_fdb_dst_replace(fdb, old_dst, dst); + } } if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) { From f1829618e0ad2d5ff974b5d6f295b897e301cda6 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Wed, 30 Sep 2026 10:14:11 +0300 Subject: [PATCH 1032/2126] net: bridge: fdb: avoid VLAN lookups in unicast forwarding Pass the complete fdb destination to br_forward(). The tagged value is decoded once into br_fwd_dst on entry so all subsequent forwarding checks use the decoded port and VLAN. A cached port-VLAN is then used to avoid two VLAN hash lookups in the standard unicast forwarding path. A backup-port redirect also uses a raw destination because the cached VLAN belongs to the original port. [1] 64 byte vlan packets, 4k randomized fdb hits with 4k fdbs, 5 million packets passed 5 times for every case VIDs Ports Mpps Gbps CPU1 cycles/input before after gain before after before after reduction 64 8/2 2.375486 2.635811 11.0% 1.216 1.350 1724.6 1553.7 9.9% 64 8/4 2.376731 2.636459 10.9% 1.217 1.350 1714.8 1554.7 9.3% 64 8/8 2.376621 2.635783 10.9% 1.217 1.350 1722.6 1553.2 9.8% 64 32/2 2.375876 2.637897 11.0% 1.216 1.351 1726.7 1552.3 10.1% 64 32/16 2.376442 2.636426 10.9% 1.217 1.350 1721.3 1554.2 9.7% 64 32/32 2.376763 2.636268 10.9% 1.217 1.350 1726.8 1553.5 10.0% 64 64/2 2.375678 2.638707 11.1% 1.216 1.351 1725.0 1552.1 10.0% 64 64/32 2.376681 2.637359 11.0% 1.217 1.350 1725.1 1555.9 9.8% 64 64/64 2.376787 2.638396 11.0% 1.217 1.351 1722.8 1550.9 10.0% 1024 8/2 2.263768 2.498881 10.4% 1.159 1.279 1808.5 1637.1 9.5% 1024 8/4 2.264519 2.499075 10.4% 1.159 1.280 1807.6 1638.8 9.3% 1024 8/8 2.263551 2.499231 10.4% 1.159 1.280 1812.0 1640.2 9.5% 1024 32/2 2.263841 2.499120 10.4% 1.159 1.280 1806.8 1639.6 9.3% 1024 32/16 2.263990 2.499562 10.4% 1.159 1.280 1806.1 1639.2 9.2% 1024 32/32 2.263719 2.498905 10.4% 1.159 1.279 1807.7 1639.3 9.3% 1024 64/2 2.263635 2.501889 10.5% 1.159 1.281 1809.4 1635.6 9.6% 1024 64/32 2.264467 2.500359 10.4% 1.159 1.280 1806.5 1633.0 9.6% 1024 64/64 2.240494 2.470246 10.3% 1.147 1.265 1810.0 1637.1 9.6% Reviewed-by: Ido Schimmel Signed-off-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20260930071411.2786201-13-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_device.c | 2 +- net/bridge/br_forward.c | 24 +++++++++++++----------- net/bridge/br_input.c | 2 +- net/bridge/br_mrp.c | 6 +++--- net/bridge/br_private.h | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 8 ++++---- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index 2423d69f2498..0a1ce9e59a4d 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -108,7 +108,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) else br_flood(br, vlan, skb, BR_PKT_MULTICAST, false, true); } else if ((dst = br_fdb_find_rcu(br, dest, vid)) != NULL) { - br_forward(br_fdb_dst_port(dst), skb, false, true); + br_forward(br_fdb_dst_read(dst), skb, false, true); } else { br_flood(br, vlan, skb, BR_PKT_UNICAST, false, true); } diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index b5eece1ff9e8..82645db32efb 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -17,7 +17,7 @@ #include "br_private.h" struct br_fwd_dst { - const struct net_bridge_port *port; + struct net_bridge_port *port; struct net_bridge_vlan *vlan; }; @@ -149,35 +149,37 @@ static int deliver_clone(const struct br_fwd_dst *fwd, /** * br_forward - forward a packet to a specific port - * @to: destination port + * @dst: bridge destination * @skb: packet being forwarded * @local_rcv: packet will be received locally after forwarding * @local_orig: packet is locally originated * * Should be called with rcu_read_lock. */ -void br_forward(const struct net_bridge_port *to, +void br_forward(struct net_bridge_dst dst, struct sk_buff *skb, bool local_rcv, bool local_orig) { struct br_fwd_dst fwd; - if (unlikely(!to)) + br_dst_decode(dst, &fwd.port, &fwd.vlan); + + if (unlikely(!fwd.port)) goto out; /* redirect to backup link if the destination port is down */ - if (rcu_access_pointer(to->backup_port) && - (!netif_carrier_ok(to->dev) || !netif_running(to->dev))) { + if (rcu_access_pointer(fwd.port->backup_port) && + (!netif_carrier_ok(fwd.port->dev) || + !netif_running(fwd.port->dev))) { struct net_bridge_port *backup_port; - backup_port = rcu_dereference(to->backup_port); + backup_port = rcu_dereference(fwd.port->backup_port); if (unlikely(!backup_port)) goto out; - BR_INPUT_SKB_CB(skb)->backup_nhid = READ_ONCE(to->backup_nhid); - to = backup_port; + BR_INPUT_SKB_CB(skb)->backup_nhid = READ_ONCE(fwd.port->backup_nhid); + fwd.port = backup_port; + fwd.vlan = NULL; } - fwd.port = to; - fwd.vlan = NULL; if (should_deliver(&fwd, skb)) { if (local_rcv) deliver_clone(&fwd, skb, local_orig); diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 44a217d65e7f..fc2e381c4fe0 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -225,7 +225,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb if (now != READ_ONCE(dst->used)) WRITE_ONCE(dst->used, now); - br_forward(br_fdb_dst_port(dst), skb, local_rcv, false); + br_forward(br_fdb_dst_read(dst), skb, local_rcv, false); } else { if (!mcast_hit) br_flood(br, vlan, skb, pkt_type, local_rcv, false); diff --git a/net/bridge/br_mrp.c b/net/bridge/br_mrp.c index dce6efa96c4c..c8cd5b4f3af8 100644 --- a/net/bridge/br_mrp.c +++ b/net/bridge/br_mrp.c @@ -1219,11 +1219,11 @@ static int br_mrp_rcv(struct net_bridge_port *p, forward: if (p_dst) - br_forward(p_dst, skb, true, false); + br_forward(br_port_to_dst(p_dst), skb, true, false); if (s_dst) - br_forward(s_dst, skb, true, false); + br_forward(br_port_to_dst(s_dst), skb, true, false); if (i_dst) - br_forward(i_dst, skb, true, false); + br_forward(br_port_to_dst(i_dst), skb, true, false); no_forward: return 1; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index a1c5b1abc1ef..05921192ebda 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1045,7 +1045,7 @@ enum br_pkt_type { BR_PKT_BROADCAST }; int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb); -void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, +void br_forward(struct net_bridge_dst dst, struct sk_buff *skb, bool local_rcv, bool local_orig); int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, diff --git a/net/bridge/netfilter/nft_reject_bridge.c b/net/bridge/netfilter/nft_reject_bridge.c index cd2b04236a99..92b488793914 100644 --- a/net/bridge/netfilter/nft_reject_bridge.c +++ b/net/bridge/netfilter/nft_reject_bridge.c @@ -55,7 +55,7 @@ static void nft_reject_br_send_v4_tcp_reset(struct net *net, nft_reject_br_push_etherhdr(oldskb, nskb); - br_forward(br_port_get_rcu(dev), nskb, false, true); + br_forward(br_port_to_dst(br_port_get_rcu(dev)), nskb, false, true); } static void nft_reject_br_send_v4_unreach(struct net *net, @@ -71,7 +71,7 @@ static void nft_reject_br_send_v4_unreach(struct net *net, nft_reject_br_push_etherhdr(oldskb, nskb); - br_forward(br_port_get_rcu(dev), nskb, false, true); + br_forward(br_port_to_dst(br_port_get_rcu(dev)), nskb, false, true); } static void nft_reject_br_send_v6_tcp_reset(struct net *net, @@ -87,7 +87,7 @@ static void nft_reject_br_send_v6_tcp_reset(struct net *net, nft_reject_br_push_etherhdr(oldskb, nskb); - br_forward(br_port_get_rcu(dev), nskb, false, true); + br_forward(br_port_to_dst(br_port_get_rcu(dev)), nskb, false, true); } @@ -104,7 +104,7 @@ static void nft_reject_br_send_v6_unreach(struct net *net, nft_reject_br_push_etherhdr(oldskb, nskb); - br_forward(br_port_get_rcu(dev), nskb, false, true); + br_forward(br_port_to_dst(br_port_get_rcu(dev)), nskb, false, true); } static void nft_reject_bridge_eval(const struct nft_expr *expr, From 4841fb8f557d090b37900f9179d3ff668f678b16 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Wed, 30 Sep 2026 10:06:24 +0800 Subject: [PATCH 1033/2126] selftests: fib_tests: use per-test return value in subtests fib_tests mixes use of $ret for both per-test return value and global exit code. If an earlier subtest fails and a later function sets ret=0, the script will exit with status 0 even though [FAIL] lines were printed. Use RET as the per-test return value, as already defined in lib.sh. The exit code ret will only be set in log_test(). Signed-off-by: Hangbin Liu Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20260930-self_fib_tests-v2-1-3053e649d341@kylinos.cn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/fib_tests.sh | 40 +++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index 7df967a2d669..7c47d7fe250d 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -345,8 +345,6 @@ fib_carrier_local_test() fib_carrier_unicast_test() { - ret=0 - echo echo "Single path route carrier test" @@ -661,12 +659,12 @@ fib6_notify_test() err=`cat errors.txt |grep "Message too long"` if [ -z "$err" ];then - ret=0 + RET=0 else - ret=1 + RET=1 fi - log_test $ret 0 "ipv6 route add notify" + log_test "$RET" 0 "ipv6 route add notify" kill_process %% @@ -708,12 +706,12 @@ fib_notify_test() err=`cat errors.txt |grep "Message too long"` if [ -z "$err" ];then - ret=0 + RET=0 else - ret=1 + RET=1 fi - log_test $ret 0 "ipv4 route add notify" + log_test "$RET" 0 "ipv4 route add notify" kill_process %% @@ -739,9 +737,9 @@ check_rt_num() if [ $num -ne $expected ]; then echo "FAIL: Expected $expected routes, got $num" - ret=1 + RET=1 else - ret=0 + RET=0 fi } @@ -788,7 +786,7 @@ fib6_gc_test() sleep $GC_WAIT_TIME $NS_EXEC sysctl -wq net.ipv6.route.flush=1 check_rt_num 0 $($IP -6 route list |grep expires|wc -l) - log_test $ret 0 "ipv6 route garbage collection" + log_test "$RET" 0 "ipv6 route garbage collection" reset_dummy_10 @@ -806,7 +804,7 @@ fib6_gc_test() # Wait for GC sleep $GC_WAIT_TIME check_rt_num 0 $($IP -6 route list |grep expires|wc -l) - log_test $ret 0 "ipv6 route garbage collection (with permanent routes)" + log_test "$RET" 0 "ipv6 route garbage collection (with permanent routes)" reset_dummy_10 @@ -824,7 +822,7 @@ fib6_gc_test() # Wait for GC sleep $GC_WAIT_TIME check_rt_num 0 $($IP -6 route list |grep expires|wc -l) - log_test $ret 0 "ipv6 route garbage collection (replace with expires)" + log_test "$RET" 0 "ipv6 route garbage collection (replace with expires)" reset_dummy_10 @@ -844,7 +842,7 @@ fib6_gc_test() # Wait for GC sleep $GC_WAIT_TIME check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l) - log_test $ret 0 "ipv6 route garbage collection (replace with permanent)" + log_test "$RET" 0 "ipv6 route garbage collection (replace with permanent)" # Delete dummy_10 and remove all routes $IP link del dev dummy_10 @@ -899,7 +897,7 @@ fib6_gc_test() # rt6_nh_dump_exceptions() just skips expired exceptions. $NS_EXEC sysctl -wq net.ipv6.route.flush=1 check_rt_num 0 $($IP -6 route list cache | grep 2001:10:: | wc -l) - log_test $ret 0 "ipv6 route garbage collection (promote to permanent routes)" + log_test "$RET" 0 "ipv6 route garbage collection (promote to permanent routes)" $IP neigh del fe80:dead::3 lladdr 00:11:22:33:44:55 dev veth1 router $IP link del veth1 @@ -936,7 +934,7 @@ fib6_gc_test() # Wait for GC sleep $GC_WAIT_TIME check_rt_num 0 $($IP -6 route list |grep expires|wc -l) - log_test $ret 0 "ipv6 route garbage collection (RA message)" + log_test "$RET" 0 "ipv6 route garbage collection (RA message)" set +e @@ -1565,7 +1563,7 @@ fib6_ra_to_static() # Expire is back, on-link route is now owned by RA again check_rt_num 2 $($IP -6 route list |grep expires|wc -l) - log_test $ret 0 "ipv6 promote RA route to static" + log_test "$RET" 0 "ipv6 promote RA route to static" # Prepare for RA route with gateway $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra_rt_info_max_plen=64 @@ -1582,7 +1580,7 @@ fib6_ra_to_static() check_rt_num 2 "$($IP -6 route list | grep -c "nexthop via")" - log_test "$ret" 0 "ipv6 RA route with nexthop do not merge into ECMP with static" + log_test "$RET" 0 "ipv6 RA route with nexthop do not merge into ECMP with static" set +e @@ -1627,18 +1625,18 @@ fib6_temp_addr_renewal() { # Restore it $NS_EXEC ra6 -i veth2 -s fe80::1 -d ff02::1 -P 2001:12::/64\#LA\#3600\#3600 -e - ret=1 + RET=1 for i in $(seq 1 25); do sleep 1 num_dep="$($IP -6 addr | grep -c "temporary deprecated" || true)" num_tot="$($IP -6 addr | grep -c "temporary" || true)" if [ "$num_dep" -eq 1 ] && [ "$num_tot" -ge 2 ]; then - ret=0 + RET=0 break fi done - log_test "$ret" 0 "IPv6 temporary address cleanly deprecated and regenerated" + log_test "$RET" 0 "IPv6 temporary address cleanly deprecated and regenerated" set +e From 91ad754f3c14fee3a2752ffee55a08c552a3a8e1 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:49 +0200 Subject: [PATCH 1034/2126] MAINTAINERS: add FDMA library to Sparx5 SoC entry The FDMA library under drivers/net/ethernet/microchip/fdma/ is shared by the lan966x, sparx5 and lan969x drivers, but is not covered by an entry in the MAINTAINERS file. A subsequent patch will add new files to the FDMA library, so let's make sure it's covered. Add drivers/net/ethernet/microchip/fdma/ to the Sparx5 SoC entry, since I am already listed there. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-1-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 3011f995437f..72ca3aab2106 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3214,6 +3214,7 @@ M: UNGLinuxDriver@microchip.com L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) S: Supported F: arch/arm64/boot/dts/microchip/sparx* +F: drivers/net/ethernet/microchip/fdma/ F: drivers/net/ethernet/microchip/vcap/ F: drivers/pinctrl/pinctrl-microchip-sgpio.c N: sparx5 From 27470b22eca3492738374c377cc4aed83b84dc57 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:50 +0200 Subject: [PATCH 1035/2126] net: microchip: fdma: rename contiguous dataptr helpers When the FDMA library was introduced [1], two helpers to get the DMA and virtual address of a data buffer, in contiguous memory, were added. These helpers have had no callers until this series. I found the naming I initially used confusing and inconsistent. Rename fdma_dataptr_get_contiguous() and fdma_dataptr_virt_get_contiguous() to fdma_dataptr_dma_addr_contiguous() and fdma_dataptr_virt_addr_contiguous(). This makes the pair symmetric and clarifies what type of address each returns. [1]: commit 30e48a75df9c ("net: microchip: add FDMA library") Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-2-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/fdma/fdma_api.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microchip/fdma/fdma_api.h b/drivers/net/ethernet/microchip/fdma/fdma_api.h index d91affe8bd98..dea8e3cc155a 100644 --- a/drivers/net/ethernet/microchip/fdma/fdma_api.h +++ b/drivers/net/ethernet/microchip/fdma/fdma_api.h @@ -197,8 +197,8 @@ static inline int fdma_nextptr_cb(struct fdma *fdma, int dcb_idx, u64 *nextptr) * if the dataptr addresses and DCB's are in contiguous memory and the driver * supports XDP. */ -static inline u64 fdma_dataptr_get_contiguous(struct fdma *fdma, int dcb_idx, - int db_idx) +static inline u64 fdma_dataptr_dma_addr_contiguous(struct fdma *fdma, + int dcb_idx, int db_idx) { return fdma->dma + (sizeof(struct fdma_dcb) * fdma->n_dcbs) + (dcb_idx * fdma->n_dbs + db_idx) * fdma->db_size + @@ -209,8 +209,8 @@ static inline u64 fdma_dataptr_get_contiguous(struct fdma *fdma, int dcb_idx, * applicable if the dataptr addresses and DCB's are in contiguous memory and * the driver supports XDP. */ -static inline void *fdma_dataptr_virt_get_contiguous(struct fdma *fdma, - int dcb_idx, int db_idx) +static inline void *fdma_dataptr_virt_addr_contiguous(struct fdma *fdma, + int dcb_idx, int db_idx) { return (u8 *)fdma->dcbs + (sizeof(struct fdma_dcb) * fdma->n_dcbs) + (dcb_idx * fdma->n_dbs + db_idx) * fdma->db_size + From 3318a794bb15e329d09dba3aaddd5ef8e22eace4 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:51 +0200 Subject: [PATCH 1036/2126] net: microchip: fdma: add PCIe ATU support When lan966x or lan969x operates as a PCIe endpoint, the internal FDMA engine cannot directly access host memory. Instead, DMA addresses must be translated through the PCIe Address Translation Unit (ATU). The ATU provides outbound windows that map internal addresses to PCIe bus addresses. The ATU outbound address space (0x10000000-0x1fffffff) is divided into six equally-sized regions (~42MB each). When FDMA buffers are allocated, a free ATU region is claimed and programmed with the DMA target address. The FDMA engine then uses the region's base address in its descriptors, and the ATU translates these to the actual DMA addresses on the PCIe bus. Add the required functions and helpers that combine the DMA allocation with the ATU region mapping. These are used by the lan966x PCIe FDMA path. The ATU cannot express a limit finer than its 64KB region granularity, so pad the mapped allocation to that boundary; otherwise the outbound window would extend past the memory the host allocated for DMA. This implementation will also be used by the lan969x, when PCIe FDMA is added for that platform in the future. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-3-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/fdma/Makefile | 4 + .../net/ethernet/microchip/fdma/fdma_api.c | 44 ++++ .../net/ethernet/microchip/fdma/fdma_api.h | 14 ++ .../net/ethernet/microchip/fdma/fdma_pci.c | 208 ++++++++++++++++++ .../net/ethernet/microchip/fdma/fdma_pci.h | 57 +++++ 5 files changed, 327 insertions(+) create mode 100644 drivers/net/ethernet/microchip/fdma/fdma_pci.c create mode 100644 drivers/net/ethernet/microchip/fdma/fdma_pci.h diff --git a/drivers/net/ethernet/microchip/fdma/Makefile b/drivers/net/ethernet/microchip/fdma/Makefile index cc9a736be357..910a10b33fb9 100644 --- a/drivers/net/ethernet/microchip/fdma/Makefile +++ b/drivers/net/ethernet/microchip/fdma/Makefile @@ -5,3 +5,7 @@ obj-$(CONFIG_FDMA) += fdma.o fdma-y += fdma_api.o + +ifneq ($(CONFIG_MCHP_LAN966X_PCI),) +fdma-y += fdma_pci.o +endif diff --git a/drivers/net/ethernet/microchip/fdma/fdma_api.c b/drivers/net/ethernet/microchip/fdma/fdma_api.c index e78c3590da9e..a3c9e3097c5c 100644 --- a/drivers/net/ethernet/microchip/fdma/fdma_api.c +++ b/drivers/net/ethernet/microchip/fdma/fdma_api.c @@ -127,6 +127,50 @@ void fdma_free_phys(struct fdma *fdma) } EXPORT_SYMBOL_GPL(fdma_free_phys); +#if IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) +/* Allocate coherent DMA memory and map it in the ATU. */ +int fdma_alloc_coherent_and_map(struct device *dev, struct fdma *fdma, + struct fdma_pci_atu *atu) +{ + struct fdma_pci_atu_region *region; + int err; + + if (WARN_ON(fdma->atu_region)) + return -EBUSY; + + /* The ATU cannot express a limit finer than the region granularity, so + * the hardware widens the programmed limit to that boundary. Pad the + * allocation to match, or the outbound window would extend past the + * memory we own. + */ + fdma->size = ALIGN(fdma->size, FDMA_PCI_ATU_REGION_ALIGN); + + err = fdma_alloc_coherent(dev, fdma); + if (err) + return err; + + region = fdma_pci_atu_region_map(atu, fdma->dma, fdma->size); + if (IS_ERR(region)) { + fdma_free_coherent(dev, fdma); + return PTR_ERR(region); + } + + fdma->atu_region = region; + + return 0; +} +EXPORT_SYMBOL_GPL(fdma_alloc_coherent_and_map); + +/* Free coherent DMA memory and unmap the memory in the ATU. */ +void fdma_free_coherent_and_unmap(struct device *dev, struct fdma *fdma) +{ + fdma_pci_atu_region_unmap(fdma->atu_region); + fdma->atu_region = NULL; + fdma_free_coherent(dev, fdma); +} +EXPORT_SYMBOL_GPL(fdma_free_coherent_and_unmap); +#endif + /* Get the size of the FDMA memory */ u32 fdma_get_size(struct fdma *fdma) { diff --git a/drivers/net/ethernet/microchip/fdma/fdma_api.h b/drivers/net/ethernet/microchip/fdma/fdma_api.h index dea8e3cc155a..ccc30d506e89 100644 --- a/drivers/net/ethernet/microchip/fdma/fdma_api.h +++ b/drivers/net/ethernet/microchip/fdma/fdma_api.h @@ -7,6 +7,8 @@ #include #include +#include "fdma_pci.h" + /* This provides a common set of functions and data structures for interacting * with the Frame DMA engine on multiple Microchip switchcores. * @@ -109,6 +111,11 @@ struct fdma { u32 channel_id; struct fdma_ops ops; + +#if IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) + /* PCI ATU region for this FDMA instance. */ + struct fdma_pci_atu_region *atu_region; +#endif }; /* Advance the DCB index and wrap if required. */ @@ -233,9 +240,16 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status, int fdma_alloc_coherent(struct device *dev, struct fdma *fdma); int fdma_alloc_phys(struct fdma *fdma); +#if IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) +int fdma_alloc_coherent_and_map(struct device *dev, struct fdma *fdma, + struct fdma_pci_atu *atu); +#endif void fdma_free_coherent(struct device *dev, struct fdma *fdma); void fdma_free_phys(struct fdma *fdma); +#if IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) +void fdma_free_coherent_and_unmap(struct device *dev, struct fdma *fdma); +#endif u32 fdma_get_size(struct fdma *fdma); u32 fdma_get_size_contiguous(struct fdma *fdma); diff --git a/drivers/net/ethernet/microchip/fdma/fdma_pci.c b/drivers/net/ethernet/microchip/fdma/fdma_pci.c new file mode 100644 index 000000000000..dd1dc46cbc9d --- /dev/null +++ b/drivers/net/ethernet/microchip/fdma/fdma_pci.c @@ -0,0 +1,208 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include + +#include "fdma_pci.h" + +/* When the switch operates as a PCIe endpoint, the FDMA engine needs to + * DMA to/from host memory. The FDMA writes to addresses within the endpoint's + * internal Outbound (OB) address space, and the PCIe ATU translates these to + * DMA addresses on the PCIe bus, targeting host memory. + * + * The ATU supports up to six outbound regions. This implementation divides + * the OB address space into six equally sized chunks. + * + * +-------------+------------+------------+-----+------------+ + * | Index | Region 0 | Region 1 | ... | Region 5 | + * +-------------+------------+------------+-----+------------+ + * | Base addr | 0x10000000 | 0x12aa0000 | ... | 0x1d520000 | + * | Limit addr | 0x12a9ffff | 0x1553ffff | ... | 0x1ffbffff | + * | Target addr | host dma | host dma | ... | host dma | + * +-------------+------------+------------+-----+------------+ + * + * Base addr is the start address of the region within the OB address space. + * Limit addr is each region's own upper bound. The value actually + * programmed is set per-mapping as base_addr + mapped size - 1, and is + * usually smaller than this. + * Target addr is the host DMA address that the base addr translates to. + */ + +#define FDMA_PCI_ATU_OB_START 0x10000000 +#define FDMA_PCI_ATU_OB_END 0x1fffffff + +#define FDMA_PCI_ATU_ADDR 0x300000 +#define FDMA_PCI_ATU_IDX_SIZE 0x200 +#define FDMA_PCI_ATU_ENA_REG 0x4 +#define FDMA_PCI_ATU_ENA_BIT BIT(31) +#define FDMA_PCI_ATU_LWR_BASE_ADDR 0x8 +#define FDMA_PCI_ATU_UPP_BASE_ADDR 0xc +#define FDMA_PCI_ATU_LIMIT_ADDR 0x10 +#define FDMA_PCI_ATU_LWR_TARGET_ADDR 0x14 +#define FDMA_PCI_ATU_UPP_TARGET_ADDR 0x18 + +static u32 fdma_pci_atu_region_size(void) +{ + return round_down((FDMA_PCI_ATU_OB_END - FDMA_PCI_ATU_OB_START) / + FDMA_PCI_ATU_REGION_MAX, FDMA_PCI_ATU_REGION_ALIGN); +} + +static void __iomem *fdma_pci_atu_addr_get(void __iomem *addr, int offset, + int idx) +{ + return addr + FDMA_PCI_ATU_ADDR + FDMA_PCI_ATU_IDX_SIZE * idx + offset; +} + +static void fdma_pci_atu_region_enable(struct fdma_pci_atu_region *region) +{ + writel(FDMA_PCI_ATU_ENA_BIT, + fdma_pci_atu_addr_get(region->atu->addr, FDMA_PCI_ATU_ENA_REG, + region->idx)); +} + +static void fdma_pci_atu_region_disable(struct fdma_pci_atu_region *region) +{ + writel(0, fdma_pci_atu_addr_get(region->atu->addr, FDMA_PCI_ATU_ENA_REG, + region->idx)); +} + +/* Configure the address translation in the ATU. */ +static void +fdma_pci_atu_configure_translation(struct fdma_pci_atu_region *region) +{ + struct fdma_pci_atu *atu = region->atu; + int idx = region->idx; + + writel(lower_32_bits(region->base_addr), + fdma_pci_atu_addr_get(atu->addr, + FDMA_PCI_ATU_LWR_BASE_ADDR, idx)); + + writel(upper_32_bits(region->base_addr), + fdma_pci_atu_addr_get(atu->addr, + FDMA_PCI_ATU_UPP_BASE_ADDR, idx)); + + /* The OB address space lies entirely below 4GB, so the limit always + * fits the lower limit register and the upper one is left alone. + */ + writel(region->limit_addr, + fdma_pci_atu_addr_get(atu->addr, FDMA_PCI_ATU_LIMIT_ADDR, idx)); + + writel(lower_32_bits(region->target_addr), + fdma_pci_atu_addr_get(atu->addr, + FDMA_PCI_ATU_LWR_TARGET_ADDR, idx)); + + writel(upper_32_bits(region->target_addr), + fdma_pci_atu_addr_get(atu->addr, + FDMA_PCI_ATU_UPP_TARGET_ADDR, idx)); +} + +/* Find an unused ATU region. */ +static struct fdma_pci_atu_region * +fdma_pci_atu_region_get_free(struct fdma_pci_atu *atu) +{ + struct fdma_pci_atu_region *regions = atu->regions; + + for (int i = 0; i < FDMA_PCI_ATU_REGION_MAX; i++) { + if (regions[i].in_use) + continue; + + return ®ions[i]; + } + + return ERR_PTR(-ENOSPC); +} + +/* Unmap an ATU region, clearing its translation and disabling it. */ +void fdma_pci_atu_region_unmap(struct fdma_pci_atu_region *region) +{ + if (IS_ERR_OR_NULL(region)) + return; + + mutex_lock(®ion->atu->lock); + + region->target_addr = 0; + region->in_use = false; + + fdma_pci_atu_region_disable(region); + fdma_pci_atu_configure_translation(region); + + mutex_unlock(®ion->atu->lock); +} +EXPORT_SYMBOL_GPL(fdma_pci_atu_region_unmap); + +/* Map a host DMA address into a free outbound region. */ +struct fdma_pci_atu_region * +fdma_pci_atu_region_map(struct fdma_pci_atu *atu, u64 target_addr, int size) +{ + struct fdma_pci_atu_region *region; + + if (!atu) + return ERR_PTR(-EINVAL); + + if (size <= 0) + return ERR_PTR(-EINVAL); + + if (size > fdma_pci_atu_region_size()) + return ERR_PTR(-ERANGE); + + /* The ATU region base is only ever aligned to FDMA_PCI_ATU_REGION_ALIGN; + * require the same alignment of the host target address, since the ATU + * translates addr - target_addr + base_addr and any misalignment here + * would shift every translated address by the same amount. + */ + if (!IS_ALIGNED(target_addr, FDMA_PCI_ATU_REGION_ALIGN)) + return ERR_PTR(-EINVAL); + + mutex_lock(&atu->lock); + + region = fdma_pci_atu_region_get_free(atu); + if (IS_ERR(region)) { + mutex_unlock(&atu->lock); + return region; + } + + region->target_addr = target_addr; + region->limit_addr = region->base_addr + size - 1; + region->in_use = true; + + fdma_pci_atu_configure_translation(region); + fdma_pci_atu_region_enable(region); + + mutex_unlock(&atu->lock); + + return region; +} +EXPORT_SYMBOL_GPL(fdma_pci_atu_region_map); + +/* Translate a host DMA address to the corresponding OB address. */ +u64 fdma_pci_atu_translate_addr(struct fdma_pci_atu_region *region, u64 addr) +{ + return region->base_addr + (addr - region->target_addr); +} +EXPORT_SYMBOL_GPL(fdma_pci_atu_translate_addr); + +/* Initialize ATU, dividing the OB space into equally sized regions. */ +void fdma_pci_atu_init(struct fdma_pci_atu *atu, void __iomem *addr) +{ + struct fdma_pci_atu_region *regions = atu->regions; + u32 region_size = fdma_pci_atu_region_size(); + + atu->addr = addr; + mutex_init(&atu->lock); + + for (int i = 0; i < FDMA_PCI_ATU_REGION_MAX; i++) { + regions[i].base_addr = + FDMA_PCI_ATU_OB_START + (i * region_size); + regions[i].limit_addr = 0; + regions[i].target_addr = 0; + regions[i].idx = i; + regions[i].atu = atu; + regions[i].in_use = false; + + fdma_pci_atu_region_disable(®ions[i]); + } +} +EXPORT_SYMBOL_GPL(fdma_pci_atu_init); diff --git a/drivers/net/ethernet/microchip/fdma/fdma_pci.h b/drivers/net/ethernet/microchip/fdma/fdma_pci.h new file mode 100644 index 000000000000..010bdb4d50b0 --- /dev/null +++ b/drivers/net/ethernet/microchip/fdma/fdma_pci.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _FDMA_PCI_H_ +#define _FDMA_PCI_H_ + +#include +#include +#include +#include + +#define FDMA_PCI_ATU_REGION_MAX 6 + +/* Outbound regions are 64KB granular (datasheet section 3.24.7.4.1), so both + * the region base and the mapped size must be aligned to this. + */ +#define FDMA_PCI_ATU_REGION_ALIGN BIT(16) + +#define FDMA_PCI_DB_ALIGN 128 +#define FDMA_PCI_DB_SIZE(mtu) ALIGN(mtu, FDMA_PCI_DB_ALIGN) + +struct fdma_pci_atu; + +struct fdma_pci_atu_region { + struct fdma_pci_atu *atu; + u64 base_addr; /* Base addr of the OB window */ + u64 limit_addr; /* End addr of the active mapping (base_addr + size - 1) */ + u64 target_addr; /* Host DMA address this region maps to */ + int idx; + bool in_use; +}; + +struct fdma_pci_atu { + void __iomem *addr; + struct mutex lock; /* Protects region alloc/free and ATU register access */ + struct fdma_pci_atu_region regions[FDMA_PCI_ATU_REGION_MAX]; +}; + +/* Initialize ATU, dividing OB space into regions. */ +void fdma_pci_atu_init(struct fdma_pci_atu *atu, void __iomem *addr); + +/* Unmap an ATU region, clearing its translation and disabling it. */ +void fdma_pci_atu_region_unmap(struct fdma_pci_atu_region *region); + +/* Map a host DMA address into a free ATU region. target_addr and size must be + * FDMA_PCI_ATU_REGION_ALIGN aligned; a misaligned target_addr returns -EINVAL. + */ +struct fdma_pci_atu_region *fdma_pci_atu_region_map(struct fdma_pci_atu *atu, + u64 target_addr, + int size); + +/* Translate a host DMA address to the OB address space. Reads the region + * unlocked, so the caller must quiesce DMA and the descriptor paths before + * unmapping the region. + */ +u64 fdma_pci_atu_translate_addr(struct fdma_pci_atu_region *region, u64 addr); + +#endif From 9786c387b299bda5277eed98284a6f6fa7331fb9 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:52 +0200 Subject: [PATCH 1037/2126] net: microchip: fdma: use little-endian types for descriptor fields The FDMA engine reads and writes the DCB and DB descriptors in little-endian byte order. So far the descriptors have only been produced by the little-endian SoC itself, so plain u64 fields were fine. With the PCIe FDMA path, the descriptors live in host memory and are written by the host CPU, which may be big-endian. Change the descriptor fields to __le64 and convert at the library boundary: in __fdma_db_add() and __fdma_dcb_add() on write, and in the fdma_db_*() accessors on read. The dataptr and nextptr callbacks keep their u64 signatures, so their implementations are unchanged. Add fdma_db_dataptr_get(), and convert the lan966x sites that read the descriptor fields directly to use the accessors. No functional change on little-endian hosts. Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-4-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/microchip/fdma/fdma_api.c | 21 ++++++++++++++----- .../net/ethernet/microchip/fdma/fdma_api.h | 20 +++++++++++------- .../ethernet/microchip/lan966x/lan966x_fdma.c | 9 ++++---- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/microchip/fdma/fdma_api.c b/drivers/net/ethernet/microchip/fdma/fdma_api.c index a3c9e3097c5c..f7a42348e932 100644 --- a/drivers/net/ethernet/microchip/fdma/fdma_api.c +++ b/drivers/net/ethernet/microchip/fdma/fdma_api.c @@ -12,10 +12,18 @@ static int __fdma_db_add(struct fdma *fdma, int dcb_idx, int db_idx, u64 status, int db_idx, u64 *dataptr)) { struct fdma_db *db = fdma_db_get(fdma, dcb_idx, db_idx); + u64 dataptr; + int err; - db->status = status; + db->status = cpu_to_le64(status); - return cb(fdma, dcb_idx, db_idx, &db->dataptr); + err = cb(fdma, dcb_idx, db_idx, &dataptr); + if (unlikely(err)) + return err; + + db->dataptr = cpu_to_le64(dataptr); + + return 0; } /* Add a DB to a DCB, using the callback set in the fdma_ops struct. */ @@ -35,6 +43,7 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status, u64 *dataptr)) { struct fdma_dcb *dcb = fdma_dcb_get(fdma, dcb_idx); + u64 nextptr; int i, err; for (i = 0; i < fdma->n_dbs; i++) { @@ -43,14 +52,16 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status, return err; } - err = dcb_cb(fdma, dcb_idx, &fdma->last_dcb->nextptr); + err = dcb_cb(fdma, dcb_idx, &nextptr); if (unlikely(err)) return err; + fdma->last_dcb->nextptr = cpu_to_le64(nextptr); + fdma->last_dcb = dcb; - dcb->nextptr = FDMA_DCB_INVALID_DATA; - dcb->info = info; + dcb->nextptr = cpu_to_le64(FDMA_DCB_INVALID_DATA); + dcb->info = cpu_to_le64(info); return 0; } diff --git a/drivers/net/ethernet/microchip/fdma/fdma_api.h b/drivers/net/ethernet/microchip/fdma/fdma_api.h index ccc30d506e89..4e4f009b77cb 100644 --- a/drivers/net/ethernet/microchip/fdma/fdma_api.h +++ b/drivers/net/ethernet/microchip/fdma/fdma_api.h @@ -66,13 +66,13 @@ struct fdma; struct fdma_db { - u64 dataptr; - u64 status; + __le64 dataptr; + __le64 status; }; struct fdma_dcb { - u64 nextptr; - u64 info; + __le64 nextptr; + __le64 info; struct fdma_db db[FDMA_DB_MAX]; }; @@ -147,19 +147,25 @@ static inline bool fdma_dcb_is_reusable(struct fdma *fdma) /* Check if the FDMA has marked this DB as done. */ static inline bool fdma_db_is_done(struct fdma_db *db) { - return db->status & FDMA_DCB_STATUS_DONE; + return le64_to_cpu(db->status) & FDMA_DCB_STATUS_DONE; } /* Get the length of a DB. */ static inline int fdma_db_len_get(struct fdma_db *db) { - return FDMA_DCB_STATUS_BLOCKL(db->status); + return FDMA_DCB_STATUS_BLOCKL(le64_to_cpu(db->status)); +} + +/* Get the dataptr of a DB. */ +static inline u64 fdma_db_dataptr_get(struct fdma_db *db) +{ + return le64_to_cpu(db->dataptr); } /* Set the length of a DB. */ static inline void fdma_dcb_len_set(struct fdma_dcb *dcb, u32 len) { - dcb->info = FDMA_DCB_INFO_DATAL(len); + dcb->info = cpu_to_le64(FDMA_DCB_INFO_DATAL(len)); } /* Get a DB by index. */ diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 41d4ec7f2f57..68fd454ebc98 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -406,8 +406,9 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) return FDMA_ERROR; dma_sync_single_for_cpu(lan966x->dev, - (dma_addr_t)db->dataptr + XDP_PACKET_HEADROOM, - FDMA_DCB_STATUS_BLOCKL(db->status), + (dma_addr_t)fdma_db_dataptr_get(db) + + XDP_PACKET_HEADROOM, + fdma_db_len_get(db), DMA_FROM_DEVICE); lan966x_ifh_get_src_port(page_address(page) + XDP_PACKET_HEADROOM, @@ -419,7 +420,7 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) if (!lan966x_xdp_port_present(port)) return FDMA_PASS; - return lan966x_xdp_run(port, page, FDMA_DCB_STATUS_BLOCKL(db->status)); + return lan966x_xdp_run(port, page, fdma_db_len_get(db)); } static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, @@ -443,7 +444,7 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx, skb_mark_for_recycle(skb); skb_reserve(skb, XDP_PACKET_HEADROOM); - skb_put(skb, FDMA_DCB_STATUS_BLOCKL(db->status)); + skb_put(skb, fdma_db_len_get(db)); lan966x_ifh_get_timestamp(skb->data, ×tamp); From 2e52284420bd45dcc04813a1d90b04d6003b0a85 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:53 +0200 Subject: [PATCH 1038/2126] net: lan966x: add FDMA LLP register write helper The FDMA Link List Pointer (LLP) register points to the first DCB in the chain and must be written before the channel is activated. This tells the FDMA engine where to begin DMA transfers. Move the LLP register writes from the channel start/activate functions into the allocation functions and introduce a shared lan966x_fdma_llp_configure() helper. This is needed because the upcoming PCIe FDMA path writes ATU-translated addresses to the LLP registers instead of DMA addresses. Keeping the writes in the shared start/activate path would overwrite these translated addresses. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-5-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 68fd454ebc98..1c5484a506ff 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -109,6 +109,13 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) return 0; } +static void lan966x_fdma_llp_configure(struct lan966x *lan966x, u64 addr, + u8 channel_id) +{ + lan_wr(lower_32_bits(addr), lan966x, FDMA_DCB_LLP(channel_id)); + lan_wr(upper_32_bits(addr), lan966x, FDMA_DCB_LLP1(channel_id)); +} + static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) { struct lan966x *lan966x = rx->lan966x; @@ -128,6 +135,8 @@ static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) fdma_dcbs_init(fdma, FDMA_DCB_INFO_DATAL(fdma->db_size), FDMA_DCB_STATUS_INTR); + lan966x_fdma_llp_configure(lan966x, fdma->dma, fdma->channel_id); + return 0; } @@ -137,14 +146,6 @@ static void lan966x_fdma_rx_start(struct lan966x_rx *rx) struct fdma *fdma = &rx->fdma; u32 mask; - /* When activating a channel, first is required to write the first DCB - * address and then to activate it - */ - lan_wr(lower_32_bits((u64)fdma->dma), lan966x, - FDMA_DCB_LLP(fdma->channel_id)); - lan_wr(upper_32_bits((u64)fdma->dma), lan966x, - FDMA_DCB_LLP1(fdma->channel_id)); - lan_wr(FDMA_CH_CFG_CH_DCB_DB_CNT_SET(fdma->n_dbs) | FDMA_CH_CFG_CH_INTR_DB_EOF_ONLY_SET(1) | FDMA_CH_CFG_CH_INJ_PORT_SET(0) | @@ -215,6 +216,8 @@ static int lan966x_fdma_tx_alloc(struct lan966x_tx *tx) fdma_dcbs_init(fdma, 0, 0); + lan966x_fdma_llp_configure(lan966x, fdma->dma, fdma->channel_id); + return 0; out: @@ -236,14 +239,6 @@ static void lan966x_fdma_tx_activate(struct lan966x_tx *tx) struct fdma *fdma = &tx->fdma; u32 mask; - /* When activating a channel, first is required to write the first DCB - * address and then to activate it - */ - lan_wr(lower_32_bits((u64)fdma->dma), lan966x, - FDMA_DCB_LLP(fdma->channel_id)); - lan_wr(upper_32_bits((u64)fdma->dma), lan966x, - FDMA_DCB_LLP1(fdma->channel_id)); - lan_wr(FDMA_CH_CFG_CH_DCB_DB_CNT_SET(fdma->n_dbs) | FDMA_CH_CFG_CH_INTR_DB_EOF_ONLY_SET(1) | FDMA_CH_CFG_CH_INJ_PORT_SET(0) | @@ -877,6 +872,9 @@ restore: MEM_TYPE_PAGE_POOL, page_pool); } + lan966x_fdma_llp_configure(lan966x, lan966x->rx.fdma.dma, + lan966x->rx.fdma.channel_id); + lan966x_fdma_rx_start(&lan966x->rx); lan966x_fdma_wakeup_netdev(lan966x); From eac4b8882a03fada82ae689d28754a553c044304 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:54 +0200 Subject: [PATCH 1039/2126] net: lan966x: export FDMA helpers for reuse Make shared FDMA helpers non-static, so they can be reused by the PCIe FDMA implementation. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-6-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 22 +++++++++---------- .../ethernet/microchip/lan966x/lan966x_main.h | 11 ++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 1c5484a506ff..651ea03eede7 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -109,8 +109,8 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) return 0; } -static void lan966x_fdma_llp_configure(struct lan966x *lan966x, u64 addr, - u8 channel_id) +void lan966x_fdma_llp_configure(struct lan966x *lan966x, u64 addr, + u8 channel_id) { lan_wr(lower_32_bits(addr), lan966x, FDMA_DCB_LLP(channel_id)); lan_wr(upper_32_bits(addr), lan966x, FDMA_DCB_LLP1(channel_id)); @@ -140,7 +140,7 @@ static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) return 0; } -static void lan966x_fdma_rx_start(struct lan966x_rx *rx) +void lan966x_fdma_rx_start(struct lan966x_rx *rx) { struct lan966x *lan966x = rx->lan966x; struct fdma *fdma = &rx->fdma; @@ -171,7 +171,7 @@ static void lan966x_fdma_rx_start(struct lan966x_rx *rx) lan966x, FDMA_CH_ACTIVATE); } -static void lan966x_fdma_rx_disable(struct lan966x_rx *rx) +void lan966x_fdma_rx_disable(struct lan966x_rx *rx) { struct lan966x *lan966x = rx->lan966x; struct fdma *fdma = &rx->fdma; @@ -191,7 +191,7 @@ static void lan966x_fdma_rx_disable(struct lan966x_rx *rx) lan966x, FDMA_CH_DB_DISCARD); } -static void lan966x_fdma_rx_reload(struct lan966x_rx *rx) +void lan966x_fdma_rx_reload(struct lan966x_rx *rx) { struct lan966x *lan966x = rx->lan966x; @@ -264,7 +264,7 @@ static void lan966x_fdma_tx_activate(struct lan966x_tx *tx) lan966x, FDMA_CH_ACTIVATE); } -static void lan966x_fdma_tx_disable(struct lan966x_tx *tx) +void lan966x_fdma_tx_disable(struct lan966x_tx *tx) { struct lan966x *lan966x = tx->lan966x; struct fdma *fdma = &tx->fdma; @@ -296,7 +296,7 @@ static void lan966x_fdma_tx_reload(struct lan966x_tx *tx) lan966x, FDMA_CH_RELOAD); } -static void lan966x_fdma_wakeup_netdev(struct lan966x *lan966x) +void lan966x_fdma_wakeup_netdev(struct lan966x *lan966x) { struct lan966x_port *port; int i; @@ -471,7 +471,7 @@ free_page: return NULL; } -static int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) +int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight) { struct lan966x *lan966x = container_of(napi, struct lan966x, napi); struct lan966x_rx *rx = &lan966x->rx; @@ -584,7 +584,7 @@ static int lan966x_fdma_get_next_dcb(struct lan966x_tx *tx) return -1; } -static void lan966x_fdma_tx_start(struct lan966x_tx *tx) +void lan966x_fdma_tx_start(struct lan966x_tx *tx) { struct lan966x *lan966x = tx->lan966x; @@ -802,7 +802,7 @@ static int lan966x_fdma_get_max_mtu(struct lan966x *lan966x) return max_mtu; } -static int lan966x_qsys_sw_status(struct lan966x *lan966x) +int lan966x_qsys_sw_status(struct lan966x *lan966x) { return lan_rd(lan966x, QSYS_SW_STATUS(CPU_PORT)); } @@ -884,7 +884,7 @@ restore: return err; } -static int lan966x_fdma_get_max_frame(struct lan966x *lan966x) +int lan966x_fdma_get_max_frame(struct lan966x *lan966x) { return lan966x_fdma_get_max_mtu(lan966x) + IFH_LEN_BYTES + diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index eea286c29474..83c361abb789 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -561,6 +561,17 @@ int lan966x_fdma_init(struct lan966x *lan966x); void lan966x_fdma_deinit(struct lan966x *lan966x); irqreturn_t lan966x_fdma_irq_handler(int irq, void *args); int lan966x_fdma_reload_page_pool(struct lan966x *lan966x); +int lan966x_fdma_napi_poll(struct napi_struct *napi, int weight); +void lan966x_fdma_llp_configure(struct lan966x *lan966x, u64 addr, + u8 channel_id); +void lan966x_fdma_rx_start(struct lan966x_rx *rx); +void lan966x_fdma_rx_disable(struct lan966x_rx *rx); +void lan966x_fdma_rx_reload(struct lan966x_rx *rx); +void lan966x_fdma_tx_start(struct lan966x_tx *tx); +void lan966x_fdma_tx_disable(struct lan966x_tx *tx); +void lan966x_fdma_wakeup_netdev(struct lan966x *lan966x); +int lan966x_fdma_get_max_frame(struct lan966x *lan966x); +int lan966x_qsys_sw_status(struct lan966x *lan966x); int lan966x_lag_port_join(struct lan966x_port *port, struct net_device *brport_dev, From f83ac2d94a2a0e36cc45434d7ba8b79306fde04a Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:55 +0200 Subject: [PATCH 1040/2126] net: lan966x: use a dedicated device for DMA operations In preparation for the PCIe FDMA implementation, add lan966x->dma_dev, resolved once at probe time, and use it for every DMA operation the FDMA path performs: coherent allocations, streaming mappings and the RX page pool. Natively, dma_dev is lan966x->dev, so there is no functional change. Since dma_dev differs from dev only on the PCIe path, add lan966x_is_pci() on top of it, for the later PCIe patches to key off. Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-7-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 30 +++++++++---------- .../ethernet/microchip/lan966x/lan966x_main.c | 16 ++++++++++ .../ethernet/microchip/lan966x/lan966x_main.h | 10 +++++++ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 651ea03eede7..ae6e5aec5e13 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -80,7 +80,7 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx) .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, .pool_size = rx->fdma.n_dcbs, .nid = NUMA_NO_NODE, - .dev = lan966x->dev, + .dev = lan966x->dma_dev, .dma_dir = DMA_FROM_DEVICE, .offset = XDP_PACKET_HEADROOM, .max_len = rx->max_mtu - @@ -126,7 +126,7 @@ static int lan966x_fdma_rx_alloc(struct lan966x_rx *rx) if (err) return err; - err = fdma_alloc_coherent(lan966x->dev, fdma); + err = fdma_alloc_coherent(lan966x->dma_dev, fdma); if (err) { page_pool_destroy(rx->page_pool); return err; @@ -210,7 +210,7 @@ static int lan966x_fdma_tx_alloc(struct lan966x_tx *tx) if (!tx->dcbs_buf) return -ENOMEM; - err = fdma_alloc_coherent(lan966x->dev, fdma); + err = fdma_alloc_coherent(lan966x->dma_dev, fdma); if (err) goto out; @@ -230,7 +230,7 @@ static void lan966x_fdma_tx_free(struct lan966x_tx *tx) struct lan966x *lan966x = tx->lan966x; kfree(tx->dcbs_buf); - fdma_free_coherent(lan966x->dev, &tx->fdma); + fdma_free_coherent(lan966x->dma_dev, &tx->fdma); } static void lan966x_fdma_tx_activate(struct lan966x_tx *tx) @@ -355,7 +355,7 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) dcb_buf->used = false; if (dcb_buf->use_skb) { - dma_unmap_single(lan966x->dev, + dma_unmap_single(lan966x->dma_dev, dcb_buf->dma_addr, dcb_buf->len, DMA_TO_DEVICE); @@ -364,7 +364,7 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) napi_consume_skb(dcb_buf->data.skb, weight); } else { if (dcb_buf->xdp_ndo) - dma_unmap_single(lan966x->dev, + dma_unmap_single(lan966x->dma_dev, dcb_buf->dma_addr, dcb_buf->len, DMA_TO_DEVICE); @@ -400,7 +400,7 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) if (unlikely(!page)) return FDMA_ERROR; - dma_sync_single_for_cpu(lan966x->dev, + dma_sync_single_for_cpu(lan966x->dma_dev, (dma_addr_t)fdma_db_dataptr_get(db) + XDP_PACKET_HEADROOM, fdma_db_len_get(db), @@ -636,11 +636,11 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len) lan966x_ifh_set_bypass(ifh, 1); lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); - dma_addr = dma_map_single(lan966x->dev, + dma_addr = dma_map_single(lan966x->dma_dev, xdpf->data - IFH_LEN_BYTES, xdpf->len + IFH_LEN_BYTES, DMA_TO_DEVICE); - if (dma_mapping_error(lan966x->dev, dma_addr)) { + if (dma_mapping_error(lan966x->dma_dev, dma_addr)) { ret = NETDEV_TX_OK; goto out; } @@ -656,7 +656,7 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len) lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); dma_addr = page_pool_get_dma_addr(page); - dma_sync_single_for_device(lan966x->dev, + dma_sync_single_for_device(lan966x->dma_dev, dma_addr + XDP_PACKET_HEADROOM, len + IFH_LEN_BYTES, DMA_TO_DEVICE); @@ -735,9 +735,9 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev) memcpy(skb->data, ifh, IFH_LEN_BYTES); skb_put(skb, 4); - dma_addr = dma_map_single(lan966x->dev, skb->data, skb->len, + dma_addr = dma_map_single(lan966x->dma_dev, skb->data, skb->len, DMA_TO_DEVICE); - if (dma_mapping_error(lan966x->dev, dma_addr)) { + if (dma_mapping_error(lan966x->dma_dev, dma_addr)) { dev->stats.tx_dropped++; err = NETDEV_TX_OK; goto release; @@ -843,7 +843,7 @@ static int lan966x_fdma_reload(struct lan966x *lan966x, int new_mtu) page_pool_put_full_page(page_pool, old_pages[i][j], false); - fdma_free_coherent(lan966x->dev, &fdma_rx_old); + fdma_free_coherent(lan966x->dma_dev, &fdma_rx_old); page_pool_destroy(page_pool); @@ -993,7 +993,7 @@ int lan966x_fdma_init(struct lan966x *lan966x) err = lan966x_fdma_tx_alloc(&lan966x->tx); if (err) { - fdma_free_coherent(lan966x->dev, &lan966x->rx.fdma); + fdma_free_coherent(lan966x->dma_dev, &lan966x->rx.fdma); page_pool_destroy(lan966x->rx.page_pool); return err; } @@ -1015,7 +1015,7 @@ void lan966x_fdma_deinit(struct lan966x *lan966x) napi_disable(&lan966x->napi); lan966x_fdma_rx_free_pages(&lan966x->rx); - fdma_free_coherent(lan966x->dev, &lan966x->rx.fdma); + fdma_free_coherent(lan966x->dma_dev, &lan966x->rx.fdma); page_pool_destroy(lan966x->rx.page_pool); lan966x_fdma_tx_free(&lan966x->tx); } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 1179a6e127c5..2741f7c9fa4c 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1081,6 +1082,20 @@ static int lan966x_reset_switch(struct lan966x *lan966x) return 0; } +/* When enumerated over PCIe, dev is a platform device with no + * iommus/dma-ranges of its own, so DMA must target the PCIe endpoint instead. + * The result differs from dev only in that case; lan966x_is_pci() relies on it. + */ +static struct device *lan966x_get_dma_dev(struct device *dev) +{ + for (struct device *p = dev->parent; p; p = p->parent) { + if (dev_is_pci(p)) + return p; + } + + return dev; +} + static int lan966x_probe(struct platform_device *pdev) { struct fwnode_handle *ports, *portnp; @@ -1094,6 +1109,7 @@ static int lan966x_probe(struct platform_device *pdev) platform_set_drvdata(pdev, lan966x); lan966x->dev = &pdev->dev; + lan966x->dma_dev = lan966x_get_dma_dev(lan966x->dev); if (!device_get_mac_address(&pdev->dev, mac_addr)) { ether_addr_copy(lan966x->base_mac, mac_addr); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 83c361abb789..3f09f8ddf620 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -270,6 +270,9 @@ struct lan966x_skb_cb { struct lan966x { struct device *dev; + /* Device used for DMA; the PCIe endpoint when enumerated over PCIe. */ + struct device *dma_dev; + u8 num_phys_ports; struct lan966x_port **ports; @@ -573,6 +576,13 @@ void lan966x_fdma_wakeup_netdev(struct lan966x *lan966x); int lan966x_fdma_get_max_frame(struct lan966x *lan966x); int lan966x_qsys_sw_status(struct lan966x *lan966x); +/* dma_dev differs from dev only on the PCIe path. */ +static inline bool lan966x_is_pci(struct lan966x *lan966x) +{ + return IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) && + lan966x->dma_dev != lan966x->dev; +} + int lan966x_lag_port_join(struct lan966x_port *port, struct net_device *brport_dev, struct net_device *bond, From 5a97c2c00b8e02aa2b27f5d445c004b1e7af9499 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:56 +0200 Subject: [PATCH 1041/2126] net: lan966x: add FDMA ops dispatch for PCIe support Introduce lan966x_fdma_ops to support different FDMA implementations for platform and PCIe. Plumb fdma_init, fdma_deinit, fdma_xmit, fdma_poll and fdma_resize through the ops table, and select the implementation at probe time. Only the platform implementation exists at this point; the PCIe implementation is added in a later patch. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-8-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 2 +- .../ethernet/microchip/lan966x/lan966x_main.c | 20 ++++++++++++++----- .../ethernet/microchip/lan966x/lan966x_main.h | 13 ++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index ae6e5aec5e13..5f46166cbfe4 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -948,7 +948,7 @@ void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev) return; lan966x->fdma_ndev = dev; - netif_napi_add(dev, &lan966x->napi, lan966x_fdma_napi_poll); + netif_napi_add(dev, &lan966x->napi, lan966x->ops->fdma_poll); napi_enable(&lan966x->napi); } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 2741f7c9fa4c..6e6c08bb8eea 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -27,6 +27,14 @@ #define IO_RANGES 2 +static const struct lan966x_fdma_ops lan966x_fdma_ops = { + .fdma_init = &lan966x_fdma_init, + .fdma_deinit = &lan966x_fdma_deinit, + .fdma_xmit = &lan966x_fdma_xmit, + .fdma_poll = &lan966x_fdma_napi_poll, + .fdma_resize = &lan966x_fdma_change_mtu, +}; + static const struct of_device_id lan966x_match[] = { { .compatible = "microchip,lan966x-switch" }, { } @@ -392,7 +400,7 @@ static netdev_tx_t lan966x_port_xmit(struct sk_buff *skb, spin_lock(&lan966x->tx_lock); if (port->lan966x->fdma) - err = lan966x_fdma_xmit(skb, ifh, dev); + err = lan966x->ops->fdma_xmit(skb, ifh, dev); else err = lan966x_port_ifh_xmit(skb, ifh, dev); spin_unlock(&lan966x->tx_lock); @@ -414,7 +422,7 @@ static int lan966x_port_change_mtu(struct net_device *dev, int new_mtu) if (!lan966x->fdma) return 0; - err = lan966x_fdma_change_mtu(lan966x); + err = lan966x->ops->fdma_resize(lan966x); if (err) { lan_wr(DEV_MAC_MAXLEN_CFG_MAX_LEN_SET(LAN966X_HW_MTU(old_mtu)), lan966x, DEV_MAC_MAXLEN_CFG(port->chip_port)); @@ -1111,6 +1119,8 @@ static int lan966x_probe(struct platform_device *pdev) lan966x->dev = &pdev->dev; lan966x->dma_dev = lan966x_get_dma_dev(lan966x->dev); + lan966x->ops = &lan966x_fdma_ops; + if (!device_get_mac_address(&pdev->dev, mac_addr)) { ether_addr_copy(lan966x->base_mac, mac_addr); } else { @@ -1250,7 +1260,7 @@ static int lan966x_probe(struct platform_device *pdev) if (err) goto cleanup_fdb; - err = lan966x_fdma_init(lan966x); + err = lan966x->ops->fdma_init(lan966x); if (err) goto cleanup_ptp; @@ -1263,7 +1273,7 @@ static int lan966x_probe(struct platform_device *pdev) return 0; cleanup_fdma: - lan966x_fdma_deinit(lan966x); + lan966x->ops->fdma_deinit(lan966x); cleanup_ptp: lan966x_ptp_deinit(lan966x); @@ -1291,7 +1301,7 @@ static void lan966x_remove(struct platform_device *pdev) lan966x_taprio_deinit(lan966x); lan966x_vcap_deinit(lan966x); - lan966x_fdma_deinit(lan966x); + lan966x->ops->fdma_deinit(lan966x); lan966x_cleanup_ports(lan966x); cancel_delayed_work_sync(&lan966x->stats_work); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 3f09f8ddf620..aab5e53ed059 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -193,6 +193,17 @@ enum vcap_is1_port_sel_rt { VCAP_IS1_PS_RT_FOLLOW_OTHER = 7, }; +struct lan966x; + +struct lan966x_fdma_ops { + int (*fdma_init)(struct lan966x *lan966x); + void (*fdma_deinit)(struct lan966x *lan966x); + int (*fdma_xmit)(struct sk_buff *skb, __be32 *ifh, + struct net_device *dev); + int (*fdma_poll)(struct napi_struct *napi, int weight); + int (*fdma_resize)(struct lan966x *lan966x); +}; + struct lan966x_port; struct lan966x_rx { @@ -273,6 +284,8 @@ struct lan966x { /* Device used for DMA; the PCIe endpoint when enumerated over PCIe. */ struct device *dma_dev; + const struct lan966x_fdma_ops *ops; + u8 num_phys_ports; struct lan966x_port **ports; From 58e73ef6a1e50b1516560ea981a18606633add26 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:57 +0200 Subject: [PATCH 1042/2126] net: lan966x: clear FDMA interrupt stickies after switch reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When in PCI mode, the GCB soft reset issued by the reset controller can latch spurious bits in the FDMA error stickies. The latched bits sit in FDMA_INTR_ERR until the FDMA IRQ is requested later in probe, at which point the handler fires immediately and WARNs. Clear FDMA_ERRORS, FDMA_INTR_ERR and FDMA_INTR_DB right after the switch reset so the FDMA comes out clean and the IRQ handler does not see ghost errors on probe. The clear runs on both the PCI and platform paths. On the platform path it has no effect — there are no spurious stickies to clear — but keeping it unconditional avoids a PCI-specific code path here. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-9-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 6e6c08bb8eea..259d81e75907 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -1067,6 +1067,15 @@ static int lan966x_reset_switch(struct lan966x *lan966x) reset_control_reset(switch_reset); + /* When in PCI mode, the GCB soft reset issued by the reset + * controller can latch spurious bits in the FDMA error and + * data-block stickies. Clear them before request_irq hooks up the + * FDMA IRQ line, otherwise the handler fires immediately on probe. + */ + lan_wr(lan_rd(lan966x, FDMA_ERRORS), lan966x, FDMA_ERRORS); + lan_wr(lan_rd(lan966x, FDMA_INTR_ERR), lan966x, FDMA_INTR_ERR); + lan_wr(lan_rd(lan966x, FDMA_INTR_DB), lan966x, FDMA_INTR_DB); + /* Don't reinitialize the switch core, if it is already initialized. In * case it is initialized twice, some pointers inside the queue system * in HW will get corrupted and then after a while the queue system gets From ab6268b958f04b9e6fda69ceb5c95dbc9b8141da Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:58 +0200 Subject: [PATCH 1043/2126] net: lan966x: add shutdown callback to stop the FDMA on reboot As a PCIe endpoint, lan966x is not reset by a host reboot: its FDMA channels and interrupt sources stay armed, and the OIC ORs every source into the shared PCIe INTx, asserted before the driver has re-probed. A still-active channel also keeps write access to host memory the next kernel will reuse. Add a shutdown callback that: - frees the ana, xtr and FDMA irqs, masking and unmapping them at the OIC (disable_irq() would leave both set - the OIC has no irq_disable()) - masks the analyzer source, armed unconditionally by lan966x_init() and re-armed by the MAC table's age timer - stops and detaches the netdevs, draining in-flight xmit and clearing netif_device_present() so ndo_open/ndo_change_mtu cannot re-enter the FDMA against a disabled NAPI - disables both FDMA channels and masks their interrupts - unmaps the outbound ATU windows, leaving none armed (the windows are mapped by the PCIe FDMA backend added later in this series) NAPI is skipped when fdma_ndev is unset (a probed switch with no usable port never adds one), and XDP attach cannot re-enter the FDMA either: on PCIe, lan966x_xdp_setup() returns before the page pool reload, which is the only point where it touches the FDMA. Only the PCIe instantiation needs this - the SoC one resets with the chip - so the callback returns early on a platform device; the check is at runtime since .shutdown belongs to the driver, and a PCIe-enabled kernel binds both. FDMA_INTR_ENA persists across a warm reboot, so also restore the full enable in lan966x_fdma_rx_start(), run after both rings are allocated. The PCIe FDMA backend added later in this series starts RX through the same function, so both backends are re-armed from one site. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-10-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 4 ++ .../ethernet/microchip/lan966x/lan966x_main.c | 56 +++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_regs.h | 15 +++++ 3 files changed, 75 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 5f46166cbfe4..2e8f786d6fee 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -146,6 +146,10 @@ void lan966x_fdma_rx_start(struct lan966x_rx *rx) struct fdma *fdma = &rx->fdma; u32 mask; + lan_wr(FDMA_INTR_ENA_INTR_PORT_ENA_SET(GENMASK(1, 0)) | + FDMA_INTR_ENA_INTR_CH_ENA_SET(GENMASK(7, 0)), + lan966x, FDMA_INTR_ENA); + lan_wr(FDMA_CH_CFG_CH_DCB_DB_CNT_SET(fdma->n_dbs) | FDMA_CH_CFG_CH_INTR_DB_EOF_ONLY_SET(1) | FDMA_CH_CFG_CH_INJ_PORT_SET(0) | diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 259d81e75907..024ce9f9916c 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -1324,9 +1324,65 @@ static void lan966x_remove(struct platform_device *pdev) debugfs_remove_recursive(lan966x->debugfs_root); } +static void lan966x_shutdown(struct platform_device *pdev) +{ + struct lan966x *lan966x = platform_get_drvdata(pdev); + + /* As a PCIe endpoint the switch is not reset by the host reboot, so it + * has to be quiesced here: + * + * Free the irqs and mask the sources: no source can assert INTx. + * Disable NAPI: the teardown must not race a poll. + * Stop and detach the netdevs: drains xmit, closes ndo_open and MTU. + * Stop the FDMA channels: waits for the engine to go idle. + * Unmap the ATU windows: revokes the engine's access to host memory. + */ + if (!lan966x_is_pci(lan966x)) + return; + + if (lan966x->xtr_irq > 0) + devm_free_irq(lan966x->dev, lan966x->xtr_irq, lan966x); + if (lan966x->ana_irq > 0) + devm_free_irq(lan966x->dev, lan966x->ana_irq, lan966x); + if (lan966x->fdma_irq > 0) + devm_free_irq(lan966x->dev, lan966x->fdma_irq, lan966x); + + lan_wr(0, lan966x, ANA_ANAINTR); + + if (!lan966x->fdma) + return; + + rtnl_lock(); + + if (lan966x->fdma_ndev) + napi_disable(&lan966x->napi); + + for (int p = 0; p < lan966x->num_phys_ports; p++) { + if (!lan966x->ports[p] || !lan966x->ports[p]->dev) + continue; + + netif_tx_disable(lan966x->ports[p]->dev); + netif_device_detach(lan966x->ports[p]->dev); + } + + lan966x_fdma_rx_disable(&lan966x->rx); + lan966x_fdma_tx_disable(&lan966x->tx); + + lan_wr(0, lan966x, FDMA_INTR_ENA); + lan_wr(0, lan966x, FDMA_INTR_DB_ENA); + +#if IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) + fdma_pci_atu_region_unmap(lan966x->rx.fdma.atu_region); + fdma_pci_atu_region_unmap(lan966x->tx.fdma.atu_region); +#endif + + rtnl_unlock(); +} + static struct platform_driver lan966x_driver = { .probe = lan966x_probe, .remove = lan966x_remove, + .shutdown = lan966x_shutdown, .driver = { .name = "lan966x-switch", .of_match_table = lan966x_match, diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h b/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h index 4b553927d2e0..aba0d36ae6b5 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h @@ -1039,6 +1039,21 @@ enum lan966x_target { /* FDMA:FDMA:FDMA_INTR_ERR */ #define FDMA_INTR_ERR __REG(TARGET_FDMA, 0, 1, 8, 0, 1, 428, 400, 0, 1, 4) +/* FDMA:FDMA:FDMA_INTR_ENA */ +#define FDMA_INTR_ENA __REG(TARGET_FDMA, 0, 1, 8, 0, 1, 428, 404, 0, 1, 4) + +#define FDMA_INTR_ENA_INTR_PORT_ENA GENMASK(9, 8) +#define FDMA_INTR_ENA_INTR_PORT_ENA_SET(x)\ + FIELD_PREP(FDMA_INTR_ENA_INTR_PORT_ENA, x) +#define FDMA_INTR_ENA_INTR_PORT_ENA_GET(x)\ + FIELD_GET(FDMA_INTR_ENA_INTR_PORT_ENA, x) + +#define FDMA_INTR_ENA_INTR_CH_ENA GENMASK(7, 0) +#define FDMA_INTR_ENA_INTR_CH_ENA_SET(x)\ + FIELD_PREP(FDMA_INTR_ENA_INTR_CH_ENA, x) +#define FDMA_INTR_ENA_INTR_CH_ENA_GET(x)\ + FIELD_GET(FDMA_INTR_ENA_INTR_CH_ENA, x) + /* FDMA:FDMA:FDMA_ERRORS */ #define FDMA_ERRORS __REG(TARGET_FDMA, 0, 1, 8, 0, 1, 428, 412, 0, 1, 4) From e013b82ed3b251e680401b4f4d541acd99cbe572 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:32:59 +0200 Subject: [PATCH 1044/2126] net: lan966x: add PCIe FDMA support Add PCIe FDMA support for lan966x. The PCIe FDMA path uses contiguous DMA buffers mapped through the endpoint's ATU, with memcpy-based frame transfer instead of per-page DMA mappings. With PCIe FDMA, throughput increases from ~33 Mbps (register-based I/O) to ~620 Mbps on an Intel x86 host with a lan966x PCIe card. The RX path uses its own copy of lan966x_hw_offload() that reports back when skb_vlan_untag() frees the skb, so the caller can drop the frame instead of touching it. XDP is not supported on this path yet, so do not advertise xdp_features and reject program attach for PCIe instances. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-11-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/microchip/lan966x/Makefile | 4 + .../microchip/lan966x/lan966x_fdma_pci.c | 458 ++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_main.c | 11 +- .../ethernet/microchip/lan966x/lan966x_main.h | 7 + .../ethernet/microchip/lan966x/lan966x_regs.h | 10 + .../ethernet/microchip/lan966x/lan966x_xdp.c | 6 + 6 files changed, 493 insertions(+), 3 deletions(-) create mode 100644 drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c diff --git a/drivers/net/ethernet/microchip/lan966x/Makefile b/drivers/net/ethernet/microchip/lan966x/Makefile index 4cdbe263502c..02db4d4d9826 100644 --- a/drivers/net/ethernet/microchip/lan966x/Makefile +++ b/drivers/net/ethernet/microchip/lan966x/Makefile @@ -18,6 +18,10 @@ lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \ lan966x-switch-$(CONFIG_LAN966X_DCB) += lan966x_dcb.o lan966x-switch-$(CONFIG_DEBUG_FS) += lan966x_vcap_debugfs.o +ifneq ($(CONFIG_MCHP_LAN966X_PCI),) +lan966x-switch-y += lan966x_fdma_pci.o +endif + # Provide include files ccflags-y += -I$(srctree)/drivers/net/ethernet/microchip/vcap ccflags-y += -I$(srctree)/drivers/net/ethernet/microchip/fdma diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c new file mode 100644 index 000000000000..f511e7061314 --- /dev/null +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c @@ -0,0 +1,458 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include + +#include "fdma_api.h" +#include "lan966x_main.h" + +static int lan966x_fdma_pci_dataptr_cb(struct fdma *fdma, int dcb, int db, + u64 *dataptr) +{ + u64 addr; + + addr = fdma_dataptr_dma_addr_contiguous(fdma, dcb, db); + + *dataptr = fdma_pci_atu_translate_addr(fdma->atu_region, addr); + + return 0; +} + +static int lan966x_fdma_pci_nextptr_cb(struct fdma *fdma, int dcb, u64 *nextptr) +{ + u64 addr; + + fdma_nextptr_cb(fdma, dcb, &addr); + + *nextptr = fdma_pci_atu_translate_addr(fdma->atu_region, addr); + + return 0; +} + +/* Stop the TX queues on every port, so nothing feeds the injection channel + * while it is torn down or resized. + */ +static void lan966x_fdma_tx_disable_netdev(struct lan966x *lan966x) +{ + struct lan966x_port *port; + int i; + + for (i = 0; i < lan966x->num_phys_ports; ++i) { + port = lan966x->ports[i]; + if (!port) + continue; + + netif_tx_disable(port->dev); + } +} + +static int lan966x_fdma_pci_rx_alloc(struct lan966x_rx *rx) +{ + struct lan966x *lan966x = rx->lan966x; + struct fdma *fdma = &rx->fdma; + int err; + + err = fdma_alloc_coherent_and_map(lan966x->dma_dev, fdma, + &lan966x->atu); + if (err) + return err; + + err = fdma_dcbs_init(fdma, + FDMA_DCB_INFO_DATAL(fdma->db_size - XDP_PACKET_HEADROOM), + FDMA_DCB_STATUS_INTR); + if (err) { + fdma_free_coherent_and_unmap(lan966x->dma_dev, fdma); + return err; + } + + lan966x_fdma_llp_configure(lan966x, + fdma->atu_region->base_addr, + fdma->channel_id); + + return 0; +} + +static int lan966x_fdma_pci_tx_alloc(struct lan966x_tx *tx) +{ + struct lan966x *lan966x = tx->lan966x; + struct fdma *fdma = &tx->fdma; + int err; + + err = fdma_alloc_coherent_and_map(lan966x->dma_dev, fdma, + &lan966x->atu); + if (err) + return err; + + err = fdma_dcbs_init(fdma, + FDMA_DCB_INFO_DATAL(fdma->db_size), + FDMA_DCB_STATUS_DONE); + if (err) { + fdma_free_coherent_and_unmap(lan966x->dma_dev, fdma); + return err; + } + + lan966x_fdma_llp_configure(lan966x, + fdma->atu_region->base_addr, + fdma->channel_id); + + return 0; +} + +static int lan966x_fdma_pci_get_next_dcb(struct fdma *fdma) +{ + struct fdma_db *db; + + for (int i = 0; i < fdma->n_dcbs; i++) { + db = fdma_db_get(fdma, i, 0); + + if (!fdma_db_is_done(db)) + continue; + if (fdma_is_last(fdma, &fdma->dcbs[i])) + continue; + + return i; + } + + return -ENOSPC; +} + +/* TX slot layout (sizes in bytes): + * + * +---------------------+-----+---------+-----+ + * | XDP_PACKET_HEADROOM | IFH | payload | FCS | + * | 256 | 28 | len | 4 | + * +---------------------+-----+---------+-----+ + * |<---------------- db_size ----------------->| + * + * Return true if the frame plus required overhead fits. + */ +static bool lan966x_fdma_pci_tx_size_fits(struct fdma *fdma, u32 len) +{ + return XDP_PACKET_HEADROOM + IFH_LEN_BYTES + len + ETH_FCS_LEN <= + fdma->db_size; +} + +/* Return true if blockl is a valid RX frame size. */ +static bool lan966x_fdma_pci_rx_size_fits(struct fdma *fdma, u32 blockl) +{ + return blockl >= IFH_LEN_BYTES + ETH_HLEN + ETH_FCS_LEN && + blockl <= fdma->db_size - XDP_PACKET_HEADROOM; +} + +static int lan966x_fdma_pci_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) +{ + struct lan966x *lan966x = rx->lan966x; + struct fdma *fdma = &rx->fdma; + struct lan966x_port *port; + struct fdma_db *db; + void *virt_addr; + u32 blockl; + + /* virt_addr points to the IFH. */ + virt_addr = fdma_dataptr_virt_addr_contiguous(fdma, + fdma->dcb_index, + fdma->db_index); + + lan966x_ifh_get_src_port(virt_addr, src_port); + + if (*src_port >= lan966x->num_phys_ports) + return FDMA_ERROR; + + port = lan966x->ports[*src_port]; + if (!port) + return FDMA_ERROR; + + db = fdma_db_next_get(fdma); + + /* BLOCKL is a 16-bit HW-populated field; reject obviously-bad + * values before they feed memcpy/XDP sizes. + */ + blockl = fdma_db_len_get(db); + if (!lan966x_fdma_pci_rx_size_fits(fdma, blockl)) + return FDMA_ERROR; + + return FDMA_PASS; +} + +static bool lan966x_fdma_pci_hw_offload(struct lan966x *lan966x, u32 port, + struct sk_buff **pskb) +{ + struct sk_buff *skb = *pskb; + u32 val; + + val = lan_rd(lan966x, ANA_CPU_FWD_CFG(port)); + if (!(val & (ANA_CPU_FWD_CFG_IGMP_REDIR_ENA | + ANA_CPU_FWD_CFG_MLD_REDIR_ENA))) + return true; + + if (eth_type_vlan(skb->protocol)) { + skb = skb_vlan_untag(skb); + *pskb = skb; + if (unlikely(!skb)) + return false; + } + + if (skb->protocol == htons(ETH_P_IP) && + ip_hdr(skb)->protocol == IPPROTO_IGMP) + return false; + + if (IS_ENABLED(CONFIG_IPV6) && + skb->protocol == htons(ETH_P_IPV6) && + ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) && + !ipv6_mc_check_mld(skb)) + return false; + + return true; +} + +static struct sk_buff *lan966x_fdma_pci_rx_get_frame(struct lan966x_rx *rx, + u64 src_port) +{ + struct lan966x *lan966x = rx->lan966x; + struct fdma *fdma = &rx->fdma; + struct sk_buff *skb; + struct fdma_db *db; + u32 data_len; + + /* Get the received frame and create an SKB for it. */ + db = fdma_db_next_get(fdma); + data_len = fdma_db_len_get(db); + + skb = napi_alloc_skb(&lan966x->napi, data_len); + if (unlikely(!skb)) + return NULL; + + memcpy(skb->data, + fdma_dataptr_virt_addr_contiguous(fdma, + fdma->dcb_index, + fdma->db_index), + data_len); + + skb_put(skb, data_len); + + skb->dev = lan966x->ports[src_port]->dev; + skb_pull(skb, IFH_LEN_BYTES); + + skb_trim(skb, skb->len - ETH_FCS_LEN); + + skb->protocol = eth_type_trans(skb, skb->dev); + + if (lan966x->bridge_mask & BIT(src_port)) { + skb->offload_fwd_mark = 1; + + skb_reset_network_header(skb); + if (!lan966x_fdma_pci_hw_offload(lan966x, src_port, &skb)) { + if (unlikely(!skb)) + return NULL; + skb->offload_fwd_mark = 0; + } + } + + skb->dev->stats.rx_bytes += skb->len; + skb->dev->stats.rx_packets++; + + return skb; +} + +static int lan966x_fdma_pci_xmit(struct sk_buff *skb, __be32 *ifh, + struct net_device *dev) +{ + struct lan966x_port *port = netdev_priv(dev); + struct lan966x *lan966x = port->lan966x; + struct lan966x_tx *tx = &lan966x->tx; + struct fdma *fdma = &tx->fdma; + int next_to_use; + void *virt_addr; + + next_to_use = lan966x_fdma_pci_get_next_dcb(fdma); + + if (next_to_use < 0) { + netif_stop_queue(dev); + return NETDEV_TX_BUSY; + } + + if (skb_put_padto(skb, ETH_ZLEN)) { + dev->stats.tx_dropped++; + return NETDEV_TX_OK; + } + + if (!lan966x_fdma_pci_tx_size_fits(fdma, skb->len)) { + dev_kfree_skb_any(skb); + dev->stats.tx_dropped++; + return NETDEV_TX_OK; + } + + skb_tx_timestamp(skb); + + /* virt_addr points to the IFH. */ + virt_addr = fdma_dataptr_virt_addr_contiguous(fdma, next_to_use, 0); + memcpy(virt_addr, ifh, IFH_LEN_BYTES); + memcpy(virt_addr + IFH_LEN_BYTES, skb->data, skb->len); + + /* Order frame write before DCB status write below. */ + dma_wmb(); + + fdma_dcb_add(fdma, + next_to_use, + 0, + FDMA_DCB_STATUS_INTR | + FDMA_DCB_STATUS_SOF | + FDMA_DCB_STATUS_EOF | + FDMA_DCB_STATUS_BLOCKO(0) | + FDMA_DCB_STATUS_BLOCKL(IFH_LEN_BYTES + skb->len + ETH_FCS_LEN)); + + /* Start the transmission. */ + lan966x_fdma_tx_start(tx); + + dev->stats.tx_bytes += skb->len; + dev->stats.tx_packets++; + + /* Safe to free: PTP is not supported on the PCIe path yet, + * so lan966x->ptp is always 0 here. + */ + dev_consume_skb_any(skb); + + return NETDEV_TX_OK; +} + +static int lan966x_fdma_pci_napi_poll(struct napi_struct *napi, int weight) +{ + struct lan966x *lan966x = container_of(napi, struct lan966x, napi); + struct lan966x_rx *rx = &lan966x->rx; + struct fdma *fdma = &rx->fdma; + int dcb_reload, old_dcb; + struct sk_buff *skb; + int counter = 0; + u64 src_port; + + /* Wake any stopped TX queues if a TX DCB is available. */ + spin_lock(&lan966x->tx_lock); + if (lan966x_fdma_pci_get_next_dcb(&lan966x->tx.fdma) >= 0) + lan966x_fdma_wakeup_netdev(lan966x); + spin_unlock(&lan966x->tx_lock); + + dcb_reload = fdma->dcb_index; + + /* Get all received skbs. */ + while (counter < weight) { + if (!fdma_has_frames(fdma)) + break; + /* Order DONE read before DCB/frame reads below. */ + dma_rmb(); + counter++; + switch (lan966x_fdma_pci_rx_check_frame(rx, &src_port)) { + case FDMA_PASS: + break; + case FDMA_ERROR: + /* No rx_dropped increment here because src_port is + * invalid. + */ + fdma_dcb_advance(fdma); + continue; + } + skb = lan966x_fdma_pci_rx_get_frame(rx, src_port); + fdma_dcb_advance(fdma); + if (!skb) { + lan966x->ports[src_port]->dev->stats.rx_dropped++; + continue; + } + + napi_gro_receive(&lan966x->napi, skb); + } + while (dcb_reload != fdma->dcb_index) { + old_dcb = dcb_reload; + dcb_reload++; + dcb_reload &= fdma->n_dcbs - 1; + + fdma_dcb_add(fdma, + old_dcb, + FDMA_DCB_INFO_DATAL(fdma->db_size - XDP_PACKET_HEADROOM), + FDMA_DCB_STATUS_INTR); + + lan966x_fdma_rx_reload(rx); + } + + if (counter < weight && napi_complete_done(napi, counter)) + lan_wr(0xff, lan966x, FDMA_INTR_DB_ENA); + + return counter; +} + +static int lan966x_fdma_pci_init(struct lan966x *lan966x) +{ + struct fdma *rx_fdma = &lan966x->rx.fdma; + struct fdma *tx_fdma = &lan966x->tx.fdma; + int err; + + if (!lan966x->fdma) + return 0; + + lan_wr(FDMA_CTRL_NRESET_SET(0), lan966x, FDMA_CTRL); + lan_wr(FDMA_CTRL_NRESET_SET(1), lan966x, FDMA_CTRL); + + fdma_pci_atu_init(&lan966x->atu, lan966x->regs[TARGET_PCIE_DBI]); + + lan966x->rx.lan966x = lan966x; + lan966x->rx.max_mtu = lan966x_fdma_get_max_frame(lan966x); + rx_fdma->channel_id = FDMA_XTR_CHANNEL; + rx_fdma->n_dcbs = FDMA_DCB_MAX; + rx_fdma->n_dbs = FDMA_RX_DCB_MAX_DBS; + rx_fdma->priv = lan966x; + rx_fdma->db_size = FDMA_PCI_DB_SIZE(lan966x->rx.max_mtu); + rx_fdma->size = fdma_get_size_contiguous(rx_fdma); + rx_fdma->ops.nextptr_cb = &lan966x_fdma_pci_nextptr_cb; + rx_fdma->ops.dataptr_cb = &lan966x_fdma_pci_dataptr_cb; + + lan966x->tx.lan966x = lan966x; + tx_fdma->channel_id = FDMA_INJ_CHANNEL; + tx_fdma->n_dcbs = FDMA_DCB_MAX; + tx_fdma->n_dbs = FDMA_TX_DCB_MAX_DBS; + tx_fdma->priv = lan966x; + tx_fdma->db_size = FDMA_PCI_DB_SIZE(lan966x->rx.max_mtu); + tx_fdma->size = fdma_get_size_contiguous(tx_fdma); + tx_fdma->ops.nextptr_cb = &lan966x_fdma_pci_nextptr_cb; + tx_fdma->ops.dataptr_cb = &lan966x_fdma_pci_dataptr_cb; + + err = lan966x_fdma_pci_rx_alloc(&lan966x->rx); + if (err) + return err; + + err = lan966x_fdma_pci_tx_alloc(&lan966x->tx); + if (err) { + fdma_free_coherent_and_unmap(lan966x->dma_dev, rx_fdma); + return err; + } + + lan966x_fdma_rx_start(&lan966x->rx); + + return 0; +} + +static int lan966x_fdma_pci_resize(struct lan966x *lan966x) +{ + return -EOPNOTSUPP; +} + +static void lan966x_fdma_pci_deinit(struct lan966x *lan966x) +{ + if (!lan966x->fdma) + return; + + if (lan966x->fdma_ndev) + napi_disable(&lan966x->napi); + + lan966x_fdma_tx_disable_netdev(lan966x); + lan966x_fdma_rx_disable(&lan966x->rx); + lan966x_fdma_tx_disable(&lan966x->tx); + + fdma_free_coherent_and_unmap(lan966x->dma_dev, &lan966x->rx.fdma); + fdma_free_coherent_and_unmap(lan966x->dma_dev, &lan966x->tx.fdma); +} + +const struct lan966x_fdma_ops lan966x_fdma_pci_ops = { + .fdma_init = &lan966x_fdma_pci_init, + .fdma_deinit = &lan966x_fdma_pci_deinit, + .fdma_xmit = &lan966x_fdma_pci_xmit, + .fdma_poll = &lan966x_fdma_pci_napi_poll, + .fdma_resize = &lan966x_fdma_pci_resize, +}; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 024ce9f9916c..de2202786826 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -50,6 +50,7 @@ struct lan966x_main_io_resource { static const struct lan966x_main_io_resource lan966x_main_iomap[] = { { TARGET_CPU, 0xc0000, 0 }, /* 0xe00c0000 */ { TARGET_FDMA, 0xc0400, 0 }, /* 0xe00c0400 */ + { TARGET_PCIE_DBI, 0x400000, 0 }, /* 0xe0400000 */ { TARGET_ORG, 0, 1 }, /* 0xe2000000 */ { TARGET_GCB, 0x4000, 1 }, /* 0xe2004000 */ { TARGET_QS, 0x8000, 1 }, /* 0xe2008000 */ @@ -873,7 +874,8 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, port->phylink = phylink; - if (lan966x->fdma) + /* XDP is not supported on the PCIe FDMA path. */ + if (lan966x->fdma && !lan966x_is_pci(lan966x)) dev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_NDO_XMIT; @@ -1128,7 +1130,8 @@ static int lan966x_probe(struct platform_device *pdev) lan966x->dev = &pdev->dev; lan966x->dma_dev = lan966x_get_dma_dev(lan966x->dev); - lan966x->ops = &lan966x_fdma_ops; + lan966x->ops = lan966x_is_pci(lan966x) ? &lan966x_fdma_pci_ops : + &lan966x_fdma_ops; if (!device_get_mac_address(&pdev->dev, mac_addr)) { ether_addr_copy(lan966x->base_mac, mac_addr); @@ -1187,7 +1190,9 @@ static int lan966x_probe(struct platform_device *pdev) if (err) return dev_err_probe(&pdev->dev, err, "Unable to use ptp irq"); - lan966x->ptp = 1; + /* PTP is not supported on the PCIe path yet. */ + if (!lan966x_is_pci(lan966x)) + lan966x->ptp = 1; } lan966x->fdma_irq = platform_get_irq_byname(pdev, "fdma"); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index aab5e53ed059..16bc28c8f11f 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -291,6 +292,10 @@ struct lan966x { void __iomem *regs[NUM_TARGETS]; +#if IS_ENABLED(CONFIG_MCHP_LAN966X_PCI) + struct fdma_pci_atu atu; +#endif + int shared_queue_sz; u8 base_mac[ETH_ALEN]; @@ -589,6 +594,8 @@ void lan966x_fdma_wakeup_netdev(struct lan966x *lan966x); int lan966x_fdma_get_max_frame(struct lan966x *lan966x); int lan966x_qsys_sw_status(struct lan966x *lan966x); +extern const struct lan966x_fdma_ops lan966x_fdma_pci_ops; + /* dma_dev differs from dev only on the PCIe path. */ static inline bool lan966x_is_pci(struct lan966x *lan966x) { diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h b/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h index aba0d36ae6b5..4778ea217673 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h @@ -20,6 +20,7 @@ enum lan966x_target { TARGET_FDMA = 21, TARGET_GCB = 27, TARGET_ORG = 36, + TARGET_PCIE_DBI = 40, TARGET_PTP = 41, TARGET_QS = 42, TARGET_QSYS = 46, @@ -1009,6 +1010,15 @@ enum lan966x_target { #define FDMA_CH_CFG_CH_MEM_GET(x)\ FIELD_GET(FDMA_CH_CFG_CH_MEM, x) +/* FDMA:FDMA:FDMA_CTRL */ +#define FDMA_CTRL __REG(TARGET_FDMA, 0, 1, 8, 0, 1, 428, 424, 0, 1, 4) + +#define FDMA_CTRL_NRESET BIT(0) +#define FDMA_CTRL_NRESET_SET(x)\ + FIELD_PREP(FDMA_CTRL_NRESET, x) +#define FDMA_CTRL_NRESET_GET(x)\ + FIELD_GET(FDMA_CTRL_NRESET, x) + /* FDMA:FDMA:FDMA_PORT_CTRL */ #define FDMA_PORT_CTRL(r) __REG(TARGET_FDMA, 0, 1, 8, 0, 1, 428, 376, r, 2, 4) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c index 9ee61db8690b..e63634887f64 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -20,6 +20,12 @@ static int lan966x_xdp_setup(struct net_device *dev, struct netdev_bpf *xdp) return -EOPNOTSUPP; } + if (lan966x_is_pci(lan966x)) { + NL_SET_ERR_MSG_MOD(xdp->extack, + "XDP is not supported on the PCIe FDMA path"); + return -EOPNOTSUPP; + } + old_xdp = lan966x_xdp_present(lan966x); old_prog = xchg(&port->xdp_prog, xdp->prog); new_xdp = lan966x_xdp_present(lan966x); From 1709aa382db7c1728c0430f1a3d7c6b32ed66402 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:33:00 +0200 Subject: [PATCH 1045/2126] net: lan966x: add PCIe FDMA MTU change support Add MTU change support for the PCIe FDMA path: on an MTU change, the contiguous ATU-mapped RX and TX buffers are reallocated at the new size, falling back to the existing buffers on failure. Cap the PCIe DCB ring at 256 (FDMA_PCI_DCB_MAX): 512 DCBs would overflow MAX_PAGE_ORDER at jumbo MTU. The ring must fit one MAX_PAGE_ORDER block after ATU padding, and db_size is handed to the FDMA in the 16-bit DCB DATAL field. Advertise the resulting limit in dev->max_mtu (FDMA_PCI_MAX_MTU) when the FDMA is in use - a switch with no "fdma" interrupt named uses the unconstrained register-based path instead, so the cap is gated on lan966x->fdma, not lan966x_is_pci() alone. On a 4KB-page, MAX_PAGE_ORDER=10 build this is MTU 15498; the overhead is shared with lan966x_fdma_get_max_frame() via FDMA_OVERHEAD. Skip the resize until lan966x_fdma_pci_init() has built the rings; it runs after the netdevs register and sizes them from DEV_MAC_MAXLEN_CFG, already programmed by the caller. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-12-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/lan966x/lan966x_fdma.c | 6 +- .../microchip/lan966x/lan966x_fdma_pci.c | 153 +++++++++++++++++- .../ethernet/microchip/lan966x/lan966x_main.c | 3 +- .../ethernet/microchip/lan966x/lan966x_main.h | 28 ++++ 4 files changed, 181 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 2e8f786d6fee..a7940eca5df3 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -890,11 +890,7 @@ restore: int lan966x_fdma_get_max_frame(struct lan966x *lan966x) { - return lan966x_fdma_get_max_mtu(lan966x) + - IFH_LEN_BYTES + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + - VLAN_HLEN * 2 + - XDP_PACKET_HEADROOM; + return lan966x_fdma_get_max_mtu(lan966x) + FDMA_OVERHEAD; } static int __lan966x_fdma_reload(struct lan966x *lan966x, int max_mtu) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c index f511e7061314..758554c951c5 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c @@ -395,7 +395,7 @@ static int lan966x_fdma_pci_init(struct lan966x *lan966x) lan966x->rx.lan966x = lan966x; lan966x->rx.max_mtu = lan966x_fdma_get_max_frame(lan966x); rx_fdma->channel_id = FDMA_XTR_CHANNEL; - rx_fdma->n_dcbs = FDMA_DCB_MAX; + rx_fdma->n_dcbs = FDMA_PCI_DCB_MAX; rx_fdma->n_dbs = FDMA_RX_DCB_MAX_DBS; rx_fdma->priv = lan966x; rx_fdma->db_size = FDMA_PCI_DB_SIZE(lan966x->rx.max_mtu); @@ -405,7 +405,7 @@ static int lan966x_fdma_pci_init(struct lan966x *lan966x) lan966x->tx.lan966x = lan966x; tx_fdma->channel_id = FDMA_INJ_CHANNEL; - tx_fdma->n_dcbs = FDMA_DCB_MAX; + tx_fdma->n_dcbs = FDMA_PCI_DCB_MAX; tx_fdma->n_dbs = FDMA_TX_DCB_MAX_DBS; tx_fdma->priv = lan966x; tx_fdma->db_size = FDMA_PCI_DB_SIZE(lan966x->rx.max_mtu); @@ -428,9 +428,156 @@ static int lan966x_fdma_pci_init(struct lan966x *lan966x) return 0; } +/* Reset existing rx and tx buffers. */ +static void lan966x_fdma_pci_reset_mem(struct lan966x *lan966x) +{ + struct lan966x_rx *rx = &lan966x->rx; + struct lan966x_tx *tx = &lan966x->tx; + + memset(rx->fdma.dcbs, 0, rx->fdma.size); + memset(tx->fdma.dcbs, 0, tx->fdma.size); + + fdma_dcbs_init(&rx->fdma, + FDMA_DCB_INFO_DATAL(rx->fdma.db_size - XDP_PACKET_HEADROOM), + FDMA_DCB_STATUS_INTR); + + fdma_dcbs_init(&tx->fdma, + FDMA_DCB_INFO_DATAL(tx->fdma.db_size), + FDMA_DCB_STATUS_DONE); + + lan966x_fdma_llp_configure(lan966x, + tx->fdma.atu_region->base_addr, + tx->fdma.channel_id); + lan966x_fdma_llp_configure(lan966x, + rx->fdma.atu_region->base_addr, + rx->fdma.channel_id); +} + +/* Wake all TX queues on every port (undoes lan966x_fdma_tx_disable_netdev). */ +static void lan966x_fdma_pci_wakeup_netdev(struct lan966x *lan966x) +{ + for (int i = 0; i < lan966x->num_phys_ports; ++i) { + struct lan966x_port *port = lan966x->ports[i]; + + if (port) + netif_tx_wake_all_queues(port->dev); + } +} + +static int lan966x_fdma_pci_reload(struct lan966x *lan966x, int new_mtu) +{ + struct fdma tx_fdma_old = lan966x->tx.fdma; + struct fdma rx_fdma_old = lan966x->rx.fdma; + u32 old_mtu = lan966x->rx.max_mtu; + int err; + + napi_disable(&lan966x->napi); + lan966x_fdma_tx_disable_netdev(lan966x); + lan966x_fdma_rx_disable(&lan966x->rx); + lan966x_fdma_tx_disable(&lan966x->tx); + + lan966x->rx.max_mtu = new_mtu; + + /* Must be NULL'ed in order to realloc them. */ + lan966x->rx.fdma.atu_region = NULL; + lan966x->tx.fdma.atu_region = NULL; + + lan966x->tx.fdma.db_size = FDMA_PCI_DB_SIZE(lan966x->rx.max_mtu); + lan966x->tx.fdma.size = fdma_get_size_contiguous(&lan966x->tx.fdma); + lan966x->rx.fdma.db_size = FDMA_PCI_DB_SIZE(lan966x->rx.max_mtu); + lan966x->rx.fdma.size = fdma_get_size_contiguous(&lan966x->rx.fdma); + + err = lan966x_fdma_pci_rx_alloc(&lan966x->rx); + if (err) + goto restore; + + err = lan966x_fdma_pci_tx_alloc(&lan966x->tx); + if (err) { + fdma_free_coherent_and_unmap(lan966x->dma_dev, + &lan966x->rx.fdma); + goto restore; + } + + /* Free and unmap old memory. */ + fdma_free_coherent_and_unmap(lan966x->dma_dev, &rx_fdma_old); + fdma_free_coherent_and_unmap(lan966x->dma_dev, &tx_fdma_old); + + /* Order matters: napi_enable() must precede the wakes, or a TX that + * completes first clears FDMA_INTR_DB_ENA with nothing scheduled to + * restore it, leaving RX dead until the next reload. + */ + napi_enable(&lan966x->napi); + lan966x_fdma_rx_start(&lan966x->rx); + lan966x_fdma_pci_wakeup_netdev(lan966x); + + return err; +restore: + + /* No new buffers are allocated at this point. Use the old buffers, + * but reset them before starting the FDMA again. + */ + + memcpy(&lan966x->tx.fdma, &tx_fdma_old, sizeof(struct fdma)); + memcpy(&lan966x->rx.fdma, &rx_fdma_old, sizeof(struct fdma)); + + lan966x->rx.max_mtu = old_mtu; + + lan966x_fdma_pci_reset_mem(lan966x); + + napi_enable(&lan966x->napi); + lan966x_fdma_rx_start(&lan966x->rx); + lan966x_fdma_pci_wakeup_netdev(lan966x); + + return err; +} + +static int __lan966x_fdma_pci_reload(struct lan966x *lan966x, int max_mtu) +{ + int err; + u32 val; + + /* Disable the CPU port. */ + lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(0), + QSYS_SW_PORT_MODE_PORT_ENA, + lan966x, QSYS_SW_PORT_MODE(CPU_PORT)); + + /* Flush the CPU queues. */ + readx_poll_timeout(lan966x_qsys_sw_status, + lan966x, + val, + !(QSYS_SW_STATUS_EQ_AVAIL_GET(val)), + READL_SLEEP_US, READL_TIMEOUT_US); + + /* Add a sleep in case there are frames between the queues and the CPU + * port + */ + usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC); + + err = lan966x_fdma_pci_reload(lan966x, max_mtu); + + /* Enable back the CPU port. */ + lan_rmw(QSYS_SW_PORT_MODE_PORT_ENA_SET(1), + QSYS_SW_PORT_MODE_PORT_ENA, + lan966x, QSYS_SW_PORT_MODE(CPU_PORT)); + + return err; +} + static int lan966x_fdma_pci_resize(struct lan966x *lan966x) { - return -EOPNOTSUPP; + int max_mtu; + + /* Nothing to resize until fdma_pci_init() has built the rings; it + * sizes them from DEV_MAC_MAXLEN_CFG, which the caller already set. + */ + if (!lan966x->rx.lan966x) + return 0; + + max_mtu = lan966x_fdma_get_max_frame(lan966x); + if (max_mtu == lan966x->rx.max_mtu) + return 0; + + return __lan966x_fdma_pci_reload(lan966x, max_mtu); } static void lan966x_fdma_pci_deinit(struct lan966x *lan966x) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index de2202786826..c3afc4cc597f 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -823,7 +823,8 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, port->chip_port = p; lan966x->ports[p] = port; - dev->max_mtu = ETH_MAX_MTU; + dev->max_mtu = lan966x_is_pci(lan966x) && lan966x->fdma ? + FDMA_PCI_MAX_MTU : ETH_MAX_MTU; dev->netdev_ops = &lan966x_port_netdev_ops; dev->ethtool_ops = &lan966x_ethtool_ops; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 16bc28c8f11f..1877f1916d71 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,33 @@ #define FDMA_INJ_CHANNEL 0 #define FDMA_DCB_MAX 512 +/* Ring must fit in one MAX_PAGE_ORDER DMA block; 512 DCBs overflows + * at jumbo MTU. + */ +#define FDMA_PCI_DCB_MAX 256 + +#define FDMA_OVERHEAD \ + (IFH_LEN_BYTES + \ + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \ + VLAN_HLEN * 2 + \ + XDP_PACKET_HEADROOM) + +/* Largest db_size keeping the ATU-padded ring inside one MAX_PAGE_ORDER + * block and within the 16-bit DCB DATAL field. Inverts ALIGN(x, R) <= L + * into x <= ALIGN_DOWN(L, R) to bound x directly. + */ +#define FDMA_PCI_DB_SIZE_MAX \ + MIN_T(u32, \ + (ALIGN_DOWN(PAGE_SIZE << MAX_PAGE_ORDER, \ + FDMA_PCI_ATU_REGION_ALIGN) - \ + FDMA_PCI_DCB_MAX * sizeof(struct fdma_dcb)) / \ + (FDMA_PCI_DCB_MAX * FDMA_RX_DCB_MAX_DBS), \ + ALIGN_DOWN(GENMASK(15, 0), FDMA_PCI_DB_ALIGN)) + +#define FDMA_PCI_MAX_MTU \ + (FDMA_PCI_DB_SIZE_MAX - FDMA_OVERHEAD - \ + (ETH_HLEN + ETH_FCS_LEN)) + #define SE_IDX_QUEUE 0 /* 0-79 : Queue scheduler elements */ #define SE_IDX_PORT 80 /* 80-89 : Port schedular elements */ From fbb46fde69651a5d4b3cbbbf9d2d24f5b18fe38f Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:33:01 +0200 Subject: [PATCH 1046/2126] net: lan966x: add PCIe FDMA XDP support Add XDP support for the PCIe FDMA path. The implementation operates on contiguous ATU-mapped buffers with memcpy-based XDP_TX, unlike the platform path which uses page_pool. XDP sees the frame with IFH and FCS stripped. These are removed in lan966x_fdma_pci_rx_check_frame() before the BPF program runs, because after the program returns the driver cannot tell whether the tail region was modified. The skb_pull/skb_trim previously done in lan966x_fdma_pci_rx_get_frame() are removed for the same reason; the frame pointer and length are pre-computed by rx_check_frame() and passed through rx_get_frame() and lan966x_xdp_pci_run() to the caller. lan966x_fdma_pci_xmit_xdpf() handles XDP_TX: it rebuilds a fresh IFH in the TX slot, copies the post-XDP frame after it, and lets HW insert a new FCS. lan966x_xdp_setup() is extended so the PCIe path skips the page_pool reload that the platform path needs. Only XDP_ACT_BASIC is supported. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-13-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- .../microchip/lan966x/lan966x_fdma_pci.c | 166 +++++++++++++++--- .../ethernet/microchip/lan966x/lan966x_main.c | 12 +- .../ethernet/microchip/lan966x/lan966x_xdp.c | 12 +- 3 files changed, 159 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c index 758554c951c5..949994874ed9 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma_pci.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ +#include #include #include @@ -139,7 +140,123 @@ static bool lan966x_fdma_pci_rx_size_fits(struct fdma *fdma, u32 blockl) blockl <= fdma->db_size - XDP_PACKET_HEADROOM; } -static int lan966x_fdma_pci_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) +static int lan966x_fdma_pci_xmit_xdpf(struct lan966x_port *port, + void *ptr, u32 len) +{ + struct lan966x *lan966x = port->lan966x; + struct lan966x_tx *tx = &lan966x->tx; + struct fdma *fdma = &tx->fdma; + int next_to_use, ret = 0; + void *virt_addr; + + spin_lock(&lan966x->tx_lock); + + next_to_use = lan966x_fdma_pci_get_next_dcb(fdma); + + if (next_to_use < 0) { + netif_stop_queue(port->dev); + port->dev->stats.tx_dropped++; + ret = NETDEV_TX_BUSY; + goto out; + } + + /* Only the upper bound is enforced: XDP owns the frame contents and + * length, so a program that shrinks below ETH_ZLEN gets what it asked + * for. + */ + if (!lan966x_fdma_pci_tx_size_fits(fdma, len)) { + port->dev->stats.tx_dropped++; + ret = -EINVAL; + goto out; + } + + /* virt_addr points to the IFH. */ + virt_addr = fdma_dataptr_virt_addr_contiguous(fdma, next_to_use, 0); + + /* Construct a fresh IFH. */ + memset(virt_addr, 0, IFH_LEN_BYTES); + lan966x_ifh_set_bypass(virt_addr, 1); + lan966x_ifh_set_port(virt_addr, BIT_ULL(port->chip_port)); + + /* Copy the (post-XDP) frame after the IFH. */ + memcpy(virt_addr + IFH_LEN_BYTES, ptr, len); + + /* Order frame write before DCB status write below. */ + dma_wmb(); + + /* Reserve ETH_FCS_LEN for the HW-inserted FCS (len is FCS-stripped). */ + fdma_dcb_add(fdma, + next_to_use, + 0, + FDMA_DCB_STATUS_INTR | + FDMA_DCB_STATUS_SOF | + FDMA_DCB_STATUS_EOF | + FDMA_DCB_STATUS_BLOCKO(0) | + FDMA_DCB_STATUS_BLOCKL(IFH_LEN_BYTES + len + ETH_FCS_LEN)); + + /* Start the transmission. */ + lan966x_fdma_tx_start(tx); + + port->dev->stats.tx_bytes += len; + port->dev->stats.tx_packets++; + +out: + spin_unlock(&lan966x->tx_lock); + + return ret; +} + +static int lan966x_xdp_pci_run(struct lan966x_port *port, void *data, + u32 data_len, void **xdp_data, u32 *xdp_len) +{ + /* Read once so the NULL check and bpf_prog_run_xdp() see the same + * pointer. + */ + struct bpf_prog *xdp_prog = READ_ONCE(port->xdp_prog); + struct lan966x *lan966x = port->lan966x; + struct fdma *fdma = &lan966x->rx.fdma; + struct xdp_buff xdp; + u32 act; + + if (!xdp_prog) + return FDMA_PASS; + + xdp_init_buff(&xdp, fdma->db_size, &port->xdp_rxq); + + /* hard_start is set to slot start (virt_addr is XDP_PACKET_HEADROOM + * into the slot). Headroom includes the IFH; BPF may grow into it + * via adjust_head. IFH is rebuilt on XDP_TX and unread on XDP_PASS. + */ + xdp_prepare_buff(&xdp, + data - XDP_PACKET_HEADROOM, + XDP_PACKET_HEADROOM + IFH_LEN_BYTES, + data_len, + false); + + act = bpf_prog_run_xdp(xdp_prog, &xdp); + + *xdp_data = xdp.data; + *xdp_len = xdp.data_end - xdp.data; + + switch (act) { + case XDP_PASS: + return FDMA_PASS; + case XDP_TX: + return lan966x_fdma_pci_xmit_xdpf(port, *xdp_data, *xdp_len) ? + FDMA_DROP : FDMA_TX; + default: + bpf_warn_invalid_xdp_action(port->dev, xdp_prog, act); + fallthrough; + case XDP_ABORTED: + trace_xdp_exception(port->dev, xdp_prog, act); + fallthrough; + case XDP_DROP: + return FDMA_DROP; + } +} + +static int lan966x_fdma_pci_rx_check_frame(struct lan966x_rx *rx, u64 *src_port, + void **data, u32 *data_len) { struct lan966x *lan966x = rx->lan966x; struct fdma *fdma = &rx->fdma; @@ -171,7 +288,15 @@ static int lan966x_fdma_pci_rx_check_frame(struct lan966x_rx *rx, u64 *src_port) if (!lan966x_fdma_pci_rx_size_fits(fdma, blockl)) return FDMA_ERROR; - return FDMA_PASS; + /* Present the Ethernet frame (no IFH, no FCS). HW re-inserts the + * FCS on TX; see lan966x_fdma_pci_xmit_xdpf(). May be overridden + * by XDP. The FCS strip is unconditional because NETIF_F_RXFCS + * is not advertised in hw_features. + */ + *data = virt_addr + IFH_LEN_BYTES; + *data_len = blockl - IFH_LEN_BYTES - ETH_FCS_LEN; + + return lan966x_xdp_pci_run(port, virt_addr, *data_len, data, data_len); } static bool lan966x_fdma_pci_hw_offload(struct lan966x *lan966x, u32 port, @@ -206,34 +331,21 @@ static bool lan966x_fdma_pci_hw_offload(struct lan966x *lan966x, u32 port, } static struct sk_buff *lan966x_fdma_pci_rx_get_frame(struct lan966x_rx *rx, - u64 src_port) + u64 src_port, void *data, + u32 data_len) { struct lan966x *lan966x = rx->lan966x; - struct fdma *fdma = &rx->fdma; struct sk_buff *skb; - struct fdma_db *db; - u32 data_len; - - /* Get the received frame and create an SKB for it. */ - db = fdma_db_next_get(fdma); - data_len = fdma_db_len_get(db); skb = napi_alloc_skb(&lan966x->napi, data_len); if (unlikely(!skb)) return NULL; - memcpy(skb->data, - fdma_dataptr_virt_addr_contiguous(fdma, - fdma->dcb_index, - fdma->db_index), - data_len); + memcpy(skb->data, data, data_len); skb_put(skb, data_len); skb->dev = lan966x->ports[src_port]->dev; - skb_pull(skb, IFH_LEN_BYTES); - - skb_trim(skb, skb->len - ETH_FCS_LEN); skb->protocol = eth_type_trans(skb, skb->dev); @@ -324,6 +436,8 @@ static int lan966x_fdma_pci_napi_poll(struct napi_struct *napi, int weight) struct sk_buff *skb; int counter = 0; u64 src_port; + u32 data_len; + void *data; /* Wake any stopped TX queues if a TX DCB is available. */ spin_lock(&lan966x->tx_lock); @@ -340,7 +454,10 @@ static int lan966x_fdma_pci_napi_poll(struct napi_struct *napi, int weight) /* Order DONE read before DCB/frame reads below. */ dma_rmb(); counter++; - switch (lan966x_fdma_pci_rx_check_frame(rx, &src_port)) { + switch (lan966x_fdma_pci_rx_check_frame(rx, + &src_port, + &data, + &data_len)) { case FDMA_PASS: break; case FDMA_ERROR: @@ -349,8 +466,17 @@ static int lan966x_fdma_pci_napi_poll(struct napi_struct *napi, int weight) */ fdma_dcb_advance(fdma); continue; + case FDMA_TX: + fdma_dcb_advance(fdma); + continue; + case FDMA_DROP: + fdma_dcb_advance(fdma); + continue; } - skb = lan966x_fdma_pci_rx_get_frame(rx, src_port); + skb = lan966x_fdma_pci_rx_get_frame(rx, + src_port, + data, + data_len); fdma_dcb_advance(fdma); if (!skb) { lan966x->ports[src_port]->dev->stats.rx_dropped++; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index c3afc4cc597f..e4c9c5812cca 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -875,11 +875,13 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, port->phylink = phylink; - /* XDP is not supported on the PCIe FDMA path. */ - if (lan966x->fdma && !lan966x_is_pci(lan966x)) - dev->xdp_features = NETDEV_XDP_ACT_BASIC | - NETDEV_XDP_ACT_REDIRECT | - NETDEV_XDP_ACT_NDO_XMIT; + if (lan966x->fdma) { + dev->xdp_features = NETDEV_XDP_ACT_BASIC; + + if (!lan966x_is_pci(lan966x)) + dev->xdp_features |= NETDEV_XDP_ACT_REDIRECT | + NETDEV_XDP_ACT_NDO_XMIT; + } err = register_netdev(dev); if (err) { diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c index e63634887f64..b98426afc785 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_xdp.c @@ -20,16 +20,16 @@ static int lan966x_xdp_setup(struct net_device *dev, struct netdev_bpf *xdp) return -EOPNOTSUPP; } - if (lan966x_is_pci(lan966x)) { - NL_SET_ERR_MSG_MOD(xdp->extack, - "XDP is not supported on the PCIe FDMA path"); - return -EOPNOTSUPP; - } - old_xdp = lan966x_xdp_present(lan966x); old_prog = xchg(&port->xdp_prog, xdp->prog); new_xdp = lan966x_xdp_present(lan966x); + /* PCIe FDMA uses contiguous buffers, so no page_pool reload + * is needed. + */ + if (lan966x_is_pci(lan966x)) + goto out; + if (old_xdp == new_xdp) goto out; From 100eead96ed665e2b0026a3d8beaed79b28ff231 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:33:02 +0200 Subject: [PATCH 1047/2126] misc: lan966x-pci: dts: extend cpu reg to cover PCIE DBI space The ATU outbound windows used by the FDMA engine are programmed through registers at offset 0x400000+, which falls outside the current cpu reg mapping. Extend the cpu reg size from 0x100000 (1MB) to 0x800000 (8MB) to cover the full PCIE DBI and iATU register space. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-14-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- drivers/misc/lan966x_pci.dtso | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/lan966x_pci.dtso b/drivers/misc/lan966x_pci.dtso index 7b196b0a0eb6..7bb726550caf 100644 --- a/drivers/misc/lan966x_pci.dtso +++ b/drivers/misc/lan966x_pci.dtso @@ -135,7 +135,7 @@ switch: switch@e0000000 { compatible = "microchip,lan966x-switch"; - reg = <0xe0000000 0x0100000>, + reg = <0xe0000000 0x0800000>, <0xe2000000 0x0800000>; reg-names = "cpu", "gcb"; From 14b9ac2f189db8809a3c9f750d7700cfc9d21f77 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 28 Sep 2026 21:33:03 +0200 Subject: [PATCH 1048/2126] misc: lan966x-pci: dts: add fdma interrupt to overlay Add the fdma interrupt (OIC interrupt 14) to the lan966x PCI device tree overlay, enabling FDMA-based frame injection/extraction when the switch is connected over PCIe. Tested-by: Herve Codina Signed-off-by: Daniel Machon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260928-lan966x-pci-fdma-v9-15-a17caf60f89a@microchip.com Signed-off-by: Jakub Kicinski --- drivers/misc/lan966x_pci.dtso | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/misc/lan966x_pci.dtso b/drivers/misc/lan966x_pci.dtso index 7bb726550caf..5bb12dbc0843 100644 --- a/drivers/misc/lan966x_pci.dtso +++ b/drivers/misc/lan966x_pci.dtso @@ -141,8 +141,9 @@ interrupt-parent = <&oic>; interrupts = <12 IRQ_TYPE_LEVEL_HIGH>, + <14 IRQ_TYPE_LEVEL_HIGH>, <9 IRQ_TYPE_LEVEL_HIGH>; - interrupt-names = "xtr", "ana"; + interrupt-names = "xtr", "fdma", "ana"; resets = <&reset 0>; reset-names = "switch"; From 8b4e7209c842d8cb9516f1f5ef0a88aa2d8831a6 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Tue, 29 Sep 2026 11:20:07 +0200 Subject: [PATCH 1049/2126] net: phy: realtek: add MDI-X support for RTL8365MB-VC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add MDI-X configuration and status reporting for the RTL8365MB-VC internal PHYs. Without a driver hook genphy cannot reach the chip's crossover control register, so forcing MDI/MDI-X with "ethtool -s mdix on|off" is a no-op and "ethtool " cannot report the resolved MDI-X state on this PHY. Signed-off-by: Oleksij Rempel Reviewed-by: Alvin Šipraga Tested-by: Luiz Angelo Daros de Luca Signed-off-by: David S. Miller --- drivers/net/phy/realtek/realtek_main.c | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 3b3352e2cdc6..e14960192e79 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -239,6 +239,16 @@ #define RTL_PHYSR_MASTER BIT(11) #define RTL_PHYSR_SPEED_MASK (RTL_PHYSR_SPEEDL | RTL_PHYSR_SPEEDH) +/* MDI-X control and status of the RTL8365MB-VC internal PHY. The resolved + * MDI-X state is reported in RTL_PHYSR; the configuration lives in a + * chip-specific control register. Both are only known to apply to this model. + * On this chip a set select/resolved bit means MDI, not MDI-X (measured). + */ +#define RTL8365MB_VC_PHYCR1 0x18 +#define RTL8365MB_VC_PHYCR1_MDIX_FORCE BIT(9) +#define RTL8365MB_VC_PHYCR1_MDI BIT(8) +#define RTL8365MB_VC_PHYSR_MDI BIT(1) + #define RTL_MDIO_PCS_EEE_ABLE 0xa5c4 #define RTL_MDIO_AN_EEE_ADV 0xa5d0 #define RTL_MDIO_AN_EEE_LPABLE 0xa5d2 @@ -3058,6 +3068,74 @@ static irqreturn_t rtl8221b_handle_interrupt(struct phy_device *phydev) return IRQ_HANDLED; } +static int rtl8365mb_config_mdix(struct phy_device *phydev) +{ + u16 val; + + switch (phydev->mdix_ctrl) { + case ETH_TP_MDI: + val = RTL8365MB_VC_PHYCR1_MDIX_FORCE | + RTL8365MB_VC_PHYCR1_MDI; + break; + case ETH_TP_MDI_X: + val = RTL8365MB_VC_PHYCR1_MDIX_FORCE; + break; + case ETH_TP_MDI_AUTO: + val = 0; + break; + default: + /* Leave the hardware configuration alone until user space + * asks for a specific mode. + */ + return 0; + } + + return phy_modify_changed(phydev, RTL8365MB_VC_PHYCR1, + RTL8365MB_VC_PHYCR1_MDIX_FORCE | + RTL8365MB_VC_PHYCR1_MDI, val); +} + +static int rtl8365mb_config_aneg(struct phy_device *phydev) +{ + int ret; + + ret = rtl8365mb_config_mdix(phydev); + if (ret < 0) + return ret; + + /* The pair assignment is only evaluated while the link is brought up, + * so renegotiate if the crossover configuration changed. + */ + return __genphy_config_aneg(phydev, ret); +} + +static int rtl8365mb_read_status(struct phy_device *phydev) +{ + int ret; + + ret = phy_read(phydev, RTL8365MB_VC_PHYCR1); + if (ret < 0) + return ret; + + if (ret & RTL8365MB_VC_PHYCR1_MDIX_FORCE) { + if (ret & RTL8365MB_VC_PHYCR1_MDI) + phydev->mdix_ctrl = ETH_TP_MDI; + else + phydev->mdix_ctrl = ETH_TP_MDI_X; + } else { + phydev->mdix_ctrl = ETH_TP_MDI_AUTO; + } + + ret = phy_read(phydev, RTL_PHYSR); + if (ret < 0) + return ret; + + phydev->mdix = (ret & RTL8365MB_VC_PHYSR_MDI) ? ETH_TP_MDI : + ETH_TP_MDI_X; + + return genphy_read_status(phydev); +} + static struct phy_driver realtek_drvs[] = { { PHY_ID_MATCH_EXACT(0x00008201), @@ -3354,6 +3432,8 @@ static struct phy_driver realtek_drvs[] = { /* Interrupt handling analogous to RTL8366RB */ .config_intr = genphy_no_config_intr, .handle_interrupt = genphy_handle_interrupt_no_ack, + .config_aneg = rtl8365mb_config_aneg, + .read_status = rtl8365mb_read_status, .suspend = genphy_suspend, .resume = genphy_resume, }, { From d9ecaa0a31732014a128e3b03243de54bbbd8394 Mon Sep 17 00:00:00 2001 From: Dominic White Date: Thu, 3 Sep 2026 10:18:04 +0200 Subject: [PATCH 1050/2126] wifi: cfg80211: allow zero HE OBSS PD offsets IEEE Std 802.11 permits the OBSS PD offset fields in the Spatial Reuse Parameter Set element to have a value of zero. (IEEE Std 802.11-2024, 26.10.2.4) The standard specifies the offsets as unsigned values added to -82 dBm, with field presence signalled independently. The valid offset range is therefore 0..20. nl80211 currently rejects zero for all three HE OBSS PD offset attributes during nested netlink policy validation, before the values reach cfg80211 or the driver. Allow zero while retaining the upper bound and the existing minimum/maximum relationship validation. Fixes: 796e90f42b7e ("cfg80211: add support for parsing OBBS_PD attributes") Signed-off-by: Dominic White Link: https://patch.msgid.link/20260903081804.96532-1-github@singe.za.net Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index a182404557e0..572da1d8f3d9 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -529,11 +529,11 @@ nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { static const struct nla_policy he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = - NLA_POLICY_RANGE(NLA_U8, 1, 20), + NLA_POLICY_RANGE(NLA_U8, 0, 20), [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = - NLA_POLICY_RANGE(NLA_U8, 1, 20), + NLA_POLICY_RANGE(NLA_U8, 0, 20), [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = - NLA_POLICY_RANGE(NLA_U8, 1, 20), + NLA_POLICY_RANGE(NLA_U8, 0, 20), [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = NLA_POLICY_EXACT_LEN(8), [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = From 6f88e6ebdc1a37eee93fcae9ae6384a03788bae4 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Tue, 15 Sep 2026 02:50:39 +0200 Subject: [PATCH 1051/2126] wifi: brcmfmac: Improve D3 substate entering timeout handling Some firmwares (e.g. BCM43752) do not service the D3_INFORM mailbox handshake when idle, so the D3 ACK never arrives. If WoWL is not armed the device is going to be powered off during system suspend and re-probed on resume anyway (brcmf_pcie_pm_leave_D3() handles that), so the missing ACK is harmless and must not abort the whole system suspend. When WoWL is active the device has to stay powered with its state preserved, so keep treating the timeout as fatal. Signed-off-by: Sebastian Reichel Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260915-brcmfmac-bcm43752-suspend-fix-v2-1-1bd84914998b@collabora.com Signed-off-by: Johannes Berg --- .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 55f4d7b970f2..17bae04c14b0 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -2652,9 +2652,13 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) wait_event_timeout(devinfo->mbdata_resp_wait, devinfo->mbdata_completed, BRCMF_PCIE_MBDATA_TIMEOUT); if (!devinfo->mbdata_completed) { - brcmf_err(bus, "Timeout on response for entering D3 substate\n"); - brcmf_bus_change_state(bus, BRCMF_BUS_UP); - return -EIO; + if (devinfo->wowl_enabled) { + brcmf_err(bus, "Timeout on response for entering D3 substate\n"); + brcmf_bus_change_state(bus, BRCMF_BUS_UP); + return -EIO; + } + + brcmf_dbg(PCIE, "No D3 ACK, continuing to power the device off\n"); } devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; From c56821fb3eeec2a8fbf30086b85fdb836cf4e781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ramon=20Fontanela?= Date: Tue, 15 Sep 2026 14:43:00 -0300 Subject: [PATCH 1052/2126] wifi: brcmfmac: allow ISO3166 fallback for BCM4350 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BCM4350 devices using brcmfmac on x86/PCIe may have no platform-provided country code map. In that case brcmf_translate_country_code() falls back to ISO3166 codes only for chips accepted by brmcf_use_iso3166_ccode_fallback(). BCM4350 is currently missing from that list, despite the adjacent BCM4345 and BCM4356 being present. Add BCM4350 so these devices can use the ISO3166 country code with revision 0. Signed-off-by: Vinícius Ramon Fontanela Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260915174300.28363-1-vfontanela@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index ede76a9e12c8..fc08c5b2d572 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -8079,6 +8079,7 @@ static bool brmcf_use_iso3166_ccode_fallback(struct brcmf_pub *drvr) switch (drvr->bus_if->chip) { case BRCM_CC_43430_CHIP_ID: case BRCM_CC_4345_CHIP_ID: + case BRCM_CC_4350_CHIP_ID: case BRCM_CC_4356_CHIP_ID: case BRCM_CC_43602_CHIP_ID: return true; From 6fff9de5c5b425817588eeed42bd56d665751c13 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 15 Sep 2026 21:17:38 +0200 Subject: [PATCH 1053/2126] wifi: brcmfmac: cfg80211: Report port_authorized for 4-way HS offload Since commit 416386060 ("Mark authorization completed on driver indication during 4-way HS offload") [0] wpa_supplicant expects NL80211_CMD_PORT_AUTHORIZED to complete the authentication when the driver supports 4-way handshake offload. This was apparently never tested with the upstream brcmfmac driver as it does not report this. This broke authentication on Apple silicon devices (BRCM4378, BRMC4387, BRMC4388) and other devices when wpa_supplicant 2.11 was released [1]. This was initially dealt with by reverting the commit in Fedora [2] and other Linux distributions. Instead of carrying the revert over to wpa_supplicant 2.12 add the expected NL80211_CMD_PORT_AUTHORIZED when the connection is established. The "Fixes:" tag is not fully accurate as this has only became an issue after userspace changes years after the change. Since the change is expected to be required in all active stable branches for wpa_supplicant 2.11 / 2.12 compatibility it is helpful even though BRCMF_PROFILE_FWSUP_SAE did not exists then. Link: https://github.com/zephyrproject-rtos/hostap/commit/41638606054a09867fe3f9a2b5523aa4678cbfa5 [0] Link: https://lists.infradead.org/pipermail/hostap/2024-August/042893.html [1] Link: https://bugzilla.redhat.com/show_bug.cgi?id=2302577 [2] Link: https://lore.kernel.org/linux-wireless/20260911065656.1269623-5-Jason.Huang2@infineon.com/ [3] Cc: stable@vger.kernel.org Fixes: b8a64f0e96c2 ("brcmfmac: support 4-way handshake offloading for WPA/WPA2-PSK") Signed-off-by: Janne Grunau Reviewed-by: Neal Gompa Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260915-brcmfmac-4way-handshake-offload-authenticated-event-v2-1-fbb9cc7ac177@jannau.net Signed-off-by: Johannes Berg --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index fc08c5b2d572..e32b46b7cbe2 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -6588,6 +6588,21 @@ done: return err; } +static bool +brcmf_fwsup_is_authorized(struct brcmf_cfg80211_profile *profile, + struct cfg80211_connect_resp_params *conn_params) +{ + if ((profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X || + profile->use_fwsup == BRCMF_PROFILE_FWSUP_ROAM) && + brcmf_has_pmkid(conn_params->req_ie, conn_params->req_ie_len)) + return true; + if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_SAE || + profile->use_fwsup == BRCMF_PROFILE_FWSUP_PSK) + return true; + + return false; +} + static s32 brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, struct net_device *ndev, const struct brcmf_event_msg *e, @@ -6625,10 +6640,7 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, conn_params.resp_ie = conn_info->resp_ie; conn_params.resp_ie_len = conn_info->resp_ie_len; authorized = completed && - (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X || - profile->use_fwsup == BRCMF_PROFILE_FWSUP_ROAM) && - brcmf_has_pmkid(conn_params.req_ie, - conn_params.req_ie_len); + brcmf_fwsup_is_authorized(profile, &conn_params); cfg80211_connect_done(ndev, &conn_params, GFP_KERNEL); if (authorized) cfg80211_port_authorized(ndev, profile->bssid, NULL, 0, From 3ffb0de666c6dc3831a16ad33f9c9fd8a9310dcb Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 20 Sep 2026 11:44:14 +0800 Subject: [PATCH 1054/2126] wifi: brcmfmac: bound NVRAM comment parsing The NVRAM comment handler searches for a newline with strchr() even though its input is a firmware buffer with an explicit length. A comment at the end of an unterminated buffer can make the search read past that input. Keep the input extent in the parser and use bounded searches for newline and NUL. Preserve the full input length: the capped size used to allocate the output is not a bound on the input, which may contain more than 64KiB of comments. Leave the outer parsing limit unchanged. The issue was found by our static-analysis tool. Assisted-by: gpt 5 Signed-off-by: Pengpeng Hou Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260920034414.16948-1-hppiscas@163.com Signed-off-by: Johannes Berg --- .../wireless/broadcom/brcm80211/brcmfmac/firmware.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c index 22ff326f1924..a2ee7b43aa21 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c @@ -37,6 +37,7 @@ enum nvram_parser_state { * * @state: current parser state. * @data: input buffer being parsed. + * @data_len: size of the input buffer, including comments. * @nvram: output buffer with parse result. * @nvram_len: length of parse result. * @line: current line. @@ -51,6 +52,7 @@ enum nvram_parser_state { struct nvram_parser { enum nvram_parser_state state; const u8 *data; + size_t data_len; u8 *nvram; u32 nvram_len; u32 line; @@ -171,12 +173,14 @@ brcmf_nvram_handle_value(struct nvram_parser *nvp) static enum nvram_parser_state brcmf_nvram_handle_comment(struct nvram_parser *nvp) { - char *eoc, *sol; + const char *eoc, *sol; + size_t remaining; - sol = (char *)&nvp->data[nvp->pos]; - eoc = strchr(sol, '\n'); + sol = (const char *)&nvp->data[nvp->pos]; + remaining = nvp->data_len - nvp->pos; + eoc = strnchr(sol, remaining, '\n'); if (!eoc) { - eoc = strchr(sol, '\0'); + eoc = memchr(sol, '\0', remaining); if (!eoc) return END; } @@ -210,6 +214,7 @@ static int brcmf_init_nvram_parser(struct nvram_parser *nvp, memset(nvp, 0, sizeof(*nvp)); nvp->data = data; + nvp->data_len = data_len; /* Limit size to MAX_NVRAM_SIZE, some files contain lot of comment */ if (data_len > BRCMF_FW_MAX_NVRAM_SIZE) size = BRCMF_FW_MAX_NVRAM_SIZE; From f3d9c56e6eb275a6da1119c131a3510858bf3ab3 Mon Sep 17 00:00:00 2001 From: Girish Rudrappa Date: Tue, 22 Sep 2026 06:24:58 +0000 Subject: [PATCH 1055/2126] wifi: brcmfmac: Set extsae_pwe parameter to Infineon firmware in SAP mode Parse and configure the extsae_pwe according to the information from the supported rate/extended support rate and RSNX IE Parse the beacon IEs on start_ap() and set the extsae_pwe iovar. Set sae_pwe to 2 when the RSNX IE advertises H2E, 1 when an H2E-only membership selector is present, 0 otherwise. The changes are tested with FW Version 7.45.286 Signed-off-by: Girish Rudrappa Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260922062458.3550-1-girishbukkasagara.rudrappa@infineon.com Signed-off-by: Johannes Berg --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 77 +++++++++++++++++++ .../broadcom/brcm80211/brcmfmac/cyw/core.c | 6 ++ .../broadcom/brcm80211/brcmfmac/fwvid.h | 11 +++ 3 files changed, 94 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index e32b46b7cbe2..46714d871260 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -5134,6 +5134,79 @@ brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, return err; } +static s32 +brcmf_parse_configure_sae_pwe(struct brcmf_if *ifp, + struct cfg80211_ap_settings *settings) +{ + const struct brcmf_tlv *rsnx_ie; + const struct brcmf_tlv *ext_rate_ie; + const struct brcmf_tlv *supp_rate_ie; + u8 ie_len, i; + u32 wpa_auth = 0; + u32 sae_pwe = 0; /* 0 = Hunting-and-Pecking only, 1 = H2E only, 2 = both */ + s32 err = 0; + + if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SAE_EXT)) + return 0; + + err = brcmf_fil_bsscfg_int_get(ifp, "wpa_auth", &wpa_auth); + if (err || (wpa_auth & WPA3_AUTH_SAE_PSK) == 0) { + brcmf_dbg(INFO, "wpa_auth is not SAE:0x%x\n", wpa_auth); + return 0; + } + + rsnx_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, + settings->beacon.tail_len, WLAN_EID_RSNX); + + if (rsnx_ie && rsnx_ie->len && + (rsnx_ie->data[0] & WLAN_RSNX_CAPA_SAE_H2E)) + sae_pwe = 2; + + /* Found rsnx_ie with SAE_H2E, check the bss selector to know if it is + * a H2E only. + */ + + if (sae_pwe == 2) { + supp_rate_ie = brcmf_parse_tlvs((u8 *)settings->beacon.head, + settings->beacon.head_len, + WLAN_EID_SUPP_RATES); + ext_rate_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, + settings->beacon.tail_len, + WLAN_EID_EXT_SUPP_RATES); + if (ext_rate_ie) { + ie_len = ext_rate_ie->len; + for (i = 0; i < ie_len; i++) { + if ((ext_rate_ie->data[i] & 0x7f) == + BSS_MEMBERSHIP_SELECTOR_SAE_H2E) { + sae_pwe = 1; + break; + } + } + } + + /* If we cannot found H2E only selector in ext_supp_rate IE, + * traversal supp_rate IE to make sure it really doesn't exist + */ + if (sae_pwe == 2 && supp_rate_ie) { + ie_len = supp_rate_ie->len; + for (i = 0; i < ie_len; i++) { + if ((supp_rate_ie->data[i] & 0x7f) == + BSS_MEMBERSHIP_SELECTOR_SAE_H2E) { + sae_pwe = 1; + break; + } + } + } + } + + err = brcmf_fwvid_configure_sae_pwe(ifp, sae_pwe); + if (err == -EOPNOTSUPP) + return 0; + + brcmf_dbg(TRACE, "extsae_pwe=%u\n", sae_pwe); + return err; +} + static s32 brcmf_parse_configure_security(struct brcmf_if *ifp, struct cfg80211_ap_settings *settings, @@ -5167,6 +5240,10 @@ brcmf_parse_configure_security(struct brcmf_if *ifp, err = brcmf_configure_wpaie(ifp, tmp_ie, true); if (err < 0) return err; + + err = brcmf_parse_configure_sae_pwe(ifp, settings); + if (err < 0) + return err; } } else { brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c index 6d5098f6f00f..e43cbd1fc732 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c @@ -370,10 +370,16 @@ static void brcmf_cyw_register_event_handlers(struct brcmf_pub *drvr) brcmf_notify_mgmt_tx_status); } +static int brcmf_cyw_configure_sae_pwe(struct brcmf_if *ifp, u32 sae_pwe) +{ + return brcmf_fil_iovar_int_set(ifp, "extsae_pwe", sae_pwe); +} + const struct brcmf_fwvid_ops brcmf_cyw_ops = { .set_sae_password = brcmf_cyw_set_sae_pwd, .alloc_fweh_info = brcmf_cyw_alloc_fweh_info, .activate_events = brcmf_cyw_activate_events, .get_cfg80211_ops = brcmf_cyw_get_cfg80211_ops, .register_event_handlers = brcmf_cyw_register_event_handlers, + .configure_sae_pwe = brcmf_cyw_configure_sae_pwe, }; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwvid.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwvid.h index f3e011d090f2..56d341a75a53 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwvid.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwvid.h @@ -18,6 +18,7 @@ struct brcmf_fwvid_ops { int (*activate_events)(struct brcmf_if *ifp); void (*get_cfg80211_ops)(struct brcmf_pub *drvr); void (*register_event_handlers)(struct brcmf_pub *drvr); + int (*configure_sae_pwe)(struct brcmf_if *ifp, u32 sae_pwe); }; /* exported functions */ @@ -40,6 +41,16 @@ static inline void brcmf_fwvid_feat_attach(struct brcmf_if *ifp) vops->feat_attach(ifp); } +static inline int brcmf_fwvid_configure_sae_pwe(struct brcmf_if *ifp, u32 sae_pwe) +{ + const struct brcmf_fwvid_ops *vops = ifp->drvr->vops; + + if (!vops || !vops->configure_sae_pwe) + return -EOPNOTSUPP; + + return vops->configure_sae_pwe(ifp, sae_pwe); +} + static inline int brcmf_fwvid_set_sae_password(struct brcmf_if *ifp, struct cfg80211_crypto_settings *crypto) { From 8a0f175488bdb899b13d4ebd2347223a40ff3276 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Wed, 23 Sep 2026 22:37:38 +0200 Subject: [PATCH 1056/2126] wifi: brcmfmac: Add per-board clm_blob firmware binaries On Ubuntu 26.10 these firmware file are missing inside the initrd when including the brcmfmac kernel module: ``` /usr/lib/firmware/brcm/brcmfmac43430-sdio.raspberrypi,3-model-b.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43430b0-sdio.raspberrypi,model-zero-2-w.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43436-sdio.raspberrypi,model-zero-2-w.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,3-model-a-plus.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,3-model-b-plus.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-compute-module.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-model-b.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,5-compute-module.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,5-model-b.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,500.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43456-sdio.raspberrypi,4-compute-module.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43456-sdio.raspberrypi,400.clm_blob.zst ``` Commit 885f256f61f9 ("brcmfmac: Add clm_blob firmware files to modinfo") added clm_blob firmware binaries, but did not add them for per-board firmware binaries. So add a similar glob for the per-board firmware binaries. Signed-off-by: Benjamin Drung Reviewed-by: Matthias Brugger Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260923203739.2560527-2-benjamin.drung@canonical.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c index 381801af3ac9..3cff0f1fe25f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c @@ -631,6 +631,7 @@ MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.txt"); /* per-board firmware binaries */ MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.bin"); +MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.clm_blob"); static const struct brcmf_firmware_mapping brcmf_sdio_fwnames[] = { BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID, 0xFFFFFFFF, 43143), From 37f9b5f2465dbcee24d86c6a53e504469b787cf1 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Wed, 23 Sep 2026 22:37:39 +0200 Subject: [PATCH 1057/2126] wifi: brcmfmac: Add clm_blob firmware for brcmfmac43456-sdio On Ubuntu 26.10 these firmware file are missing inside the initrd when including the brcmfmac kernel module: ``` /usr/lib/firmware/brcm/brcmfmac43436-sdio.clm_blob.zst /usr/lib/firmware/brcm/brcmfmac43456-sdio.clm_blob.zst ``` So include the clm_blob firmware file for brcmfmac43456-sdio similar to the other firmware files. Signed-off-by: Benjamin Drung Reviewed-by: Matthias Brugger Acked-by: Arend van Spriel Link: https://patch.msgid.link/20260923203739.2560527-3-benjamin.drung@canonical.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c index 3cff0f1fe25f..cea52d408817 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c @@ -618,7 +618,7 @@ BRCMF_FW_CLM_DEF(43430A1, "brcmfmac43430-sdio"); BRCMF_FW_DEF(43430B0, "brcmfmac43430b0-sdio"); BRCMF_FW_CLM_DEF(43439, "brcmfmac43439-sdio"); BRCMF_FW_CLM_DEF(43455, "brcmfmac43455-sdio"); -BRCMF_FW_DEF(43456, "brcmfmac43456-sdio"); +BRCMF_FW_CLM_DEF(43456, "brcmfmac43456-sdio"); BRCMF_FW_CLM_DEF(4354, "brcmfmac4354-sdio"); BRCMF_FW_CLM_DEF(4356, "brcmfmac4356-sdio"); BRCMF_FW_DEF(4359, "brcmfmac4359-sdio"); From 4ff2e13b696fad5ce36881e395e9844fa662b57b Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Mon, 28 Sep 2026 15:45:06 +0530 Subject: [PATCH 1058/2126] wifi: mac80211: Do not report BSS parameters in AP station info Do not report NL80211_STA_INFO_BSS_PARAM for station information generated on AP interfaces, as beacon interval, DTIM period, CTS protection, short preamble and short slot time are AP BSS configuration parameters already managed by userspace. Retain BSS parameter reporting for STA interfaces, where these parameters describe the BSS to which the station is associated. Use the per-link BSS configuration when populating BSS parameters for STA link station information. Signed-off-by: Aaradhana Sahu Link: https://patch.msgid.link/20260928101506.726663-1-aaradhana.sahu@oss.qualcomm.com Signed-off-by: Johannes Berg --- net/mac80211/sta_info.c | 49 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index e81cd155197b..9252aaa39895 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2866,7 +2866,6 @@ static void sta_set_link_sinfo(struct sta_info *sta, link_sinfo); link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | - BIT_ULL(NL80211_STA_INFO_BSS_PARAM) | BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC); if (sdata->vif.type == NL80211_IFTYPE_STATION) { @@ -3039,15 +3038,20 @@ static void sta_set_link_sinfo(struct sta_info *sta, link_id); } - link_sinfo->bss_param.flags = 0; - if (sdata->vif.bss_conf.use_cts_prot) - link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; - if (sdata->vif.bss_conf.use_short_preamble) - link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; - if (sdata->vif.bss_conf.use_short_slot) - link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; - link_sinfo->bss_param.dtim_period = link->conf->dtim_period; - link_sinfo->bss_param.beacon_interval = link->conf->beacon_int; + if (sdata->vif.type == NL80211_IFTYPE_STATION) { + link_sinfo->bss_param.flags = 0; + if (link->conf->use_cts_prot) + link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; + if (link->conf->use_short_preamble) + link_sinfo->bss_param.flags |= + BSS_PARAM_FLAGS_SHORT_PREAMBLE; + if (link->conf->use_short_slot) + link_sinfo->bss_param.flags |= + BSS_PARAM_FLAGS_SHORT_SLOT_TIME; + link_sinfo->bss_param.dtim_period = link->conf->dtim_period; + link_sinfo->bss_param.beacon_interval = link->conf->beacon_int; + link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM); + } thr = sta_get_expected_throughput(sta); if (!thr && (link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))) @@ -3101,7 +3105,6 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, drv_sta_statistics(local, sdata, &sta->sta, sinfo); sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | BIT_ULL(NL80211_STA_INFO_STA_FLAGS) | - BIT_ULL(NL80211_STA_INFO_BSS_PARAM) | BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) | BIT_ULL(NL80211_STA_INFO_ASSOC_AT_BOOTTIME) | BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC); @@ -3269,15 +3272,21 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sta_set_mesh_sinfo(sta, sinfo); #endif - sinfo->bss_param.flags = 0; - if (sdata->vif.bss_conf.use_cts_prot) - sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; - if (sdata->vif.bss_conf.use_short_preamble) - sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; - if (sdata->vif.bss_conf.use_short_slot) - sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; - sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period; - sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int; + if (sdata->vif.type == NL80211_IFTYPE_STATION) { + sinfo->bss_param.flags = 0; + if (sdata->vif.bss_conf.use_cts_prot) + sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; + if (sdata->vif.bss_conf.use_short_preamble) + sinfo->bss_param.flags |= + BSS_PARAM_FLAGS_SHORT_PREAMBLE; + if (sdata->vif.bss_conf.use_short_slot) + sinfo->bss_param.flags |= + BSS_PARAM_FLAGS_SHORT_SLOT_TIME; + sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period; + sinfo->bss_param.beacon_interval = + sdata->vif.bss_conf.beacon_int; + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM); + } sinfo->sta_flags.set = 0; sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | From d160663ca2fadfa0ffbb674f8b3141c064c1d546 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 28 Sep 2026 19:38:31 +0200 Subject: [PATCH 1059/2126] wifi: mac80211: fix TPE in channel switch wrapper parsing WLAN_EID_TX_POWER_ENVELOPE is a regular (non-extended) element, but I accidentally used cfg80211_find_ext_elem for it, and it should be a loop since multiple can be given. Fix both issues. Link: https://patch.msgid.link/20260928193832.a3deb0415eaf.I8b07b323ba83173b570bc07ed61f4130b8aff04f@changeid Signed-off-by: Johannes Berg --- net/mac80211/parse.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/mac80211/parse.c b/net/mac80211/parse.c index 3b66ca7d7a5c..030da4679ca3 100644 --- a/net/mac80211/parse.c +++ b/net/mac80211/parse.c @@ -692,9 +692,8 @@ _ieee802_11_parse_elems_full(struct ieee80211_elems_parse_params *params, IEEE80211_PARSE_ERR_BAD_ELEM_SIZE; } - subelem = cfg80211_find_ext_elem(WLAN_EID_TX_POWER_ENVELOPE, - pos, elen); - if (subelem) + for_each_element_id(subelem, WLAN_EID_TX_POWER_ENVELOPE, + pos, elen) ieee80211_parse_tpe(&elems->csa_tpe, subelem->data + 1, subelem->datalen - 1); From 34f93ba0bc9f2bca0fde881b2267bc18bc9ac052 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 28 Sep 2026 19:38:32 +0200 Subject: [PATCH 1060/2126] wifi: ieee80211: type-check (extended) element functions Type-check element finding functions and element iteration macros, so that when constants are given for the (extended) ID they must be from the appropriate enum, otherwise an enum compare compiler warning will trigger. Two places are using element iteration for subelements, but don't have the outer element as a struct element, so they need casts to avoid the warning now, but overall this will flag issues like the one in the previous commit. Link: https://patch.msgid.link/20260928193832.706fb927f309.I0f8702dc218b56470017d2fcf8fff2980946e818@changeid Signed-off-by: Johannes Berg --- include/linux/ieee80211.h | 17 +++++++++++++---- include/net/cfg80211.h | 17 +++++++++++------ net/mac80211/mlme.c | 2 +- net/wireless/scan.c | 5 +++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h index 73ac5336a17a..66f9ebe79c61 100644 --- a/include/linux/ieee80211.h +++ b/include/linux/ieee80211.h @@ -2730,6 +2730,10 @@ struct element { u8 data[]; } __packed; +/* trigger enum comparison warnings if applicable (constant id) */ +#define element_iteration_typecheck(type, id) \ + (((type)0 == (id)) || true) + /* element iteration helpers */ #define for_each_element(_elem, _data, _datalen) \ for (_elem = (const struct element *)(_data); \ @@ -2741,11 +2745,15 @@ struct element { #define for_each_element_id(element, _id, data, datalen) \ for_each_element(element, data, datalen) \ - if (element->id == (_id)) + if (element_iteration_typecheck(enum ieee80211_eid, \ + _id) && \ + element->id == (_id)) #define for_each_element_extid(element, extid, _data, _datalen) \ for_each_element(element, _data, _datalen) \ - if (element->id == WLAN_EID_EXTENSION && \ + if (element_iteration_typecheck(enum ieee80211_eid_ext, \ + extid) && \ + element->id == WLAN_EID_EXTENSION && \ element->datalen > 0 && \ element->data[0] == (extid)) @@ -2753,10 +2761,11 @@ struct element { for_each_element(sub, (element)->data, (element)->datalen) #define for_each_subelement_id(sub, id, element) \ - for_each_element_id(sub, id, (element)->data, (element)->datalen) + for_each_element_id(sub, (u8)id, (element)->data, (element)->datalen) #define for_each_subelement_extid(sub, extid, element) \ - for_each_element_extid(sub, extid, (element)->data, (element)->datalen) + for_each_element_extid(sub, (u8)extid, (element)->data, \ + (element)->datalen) /** * for_each_element_completed - determine if element parsing consumed all data diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index b603f1804cc2..2e3dfee85019 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -7858,7 +7858,8 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb, * byte array to match. */ const struct element * -cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len, +cfg80211_find_elem_match(enum ieee80211_eid eid, + const u8 *ies, unsigned int len, const u8 *match, unsigned int match_len, unsigned int match_offset); @@ -7887,7 +7888,7 @@ cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len, * byte array to match. */ static inline const u8 * -cfg80211_find_ie_match(u8 eid, const u8 *ies, unsigned int len, +cfg80211_find_ie_match(enum ieee80211_eid eid, const u8 *ies, unsigned int len, const u8 *match, unsigned int match_len, unsigned int match_offset) { @@ -7920,7 +7921,7 @@ cfg80211_find_ie_match(u8 eid, const u8 *ies, unsigned int len, * having to fit into the given data. */ static inline const struct element * -cfg80211_find_elem(u8 eid, const u8 *ies, int len) +cfg80211_find_elem(enum ieee80211_eid eid, const u8 *ies, int len) { return cfg80211_find_elem_match(eid, ies, len, NULL, 0, 0); } @@ -7940,7 +7941,8 @@ cfg80211_find_elem(u8 eid, const u8 *ies, int len) * Note: There are no checks on the element length other than * having to fit into the given data. */ -static inline const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len) +static inline const u8 *cfg80211_find_ie(enum ieee80211_eid eid, + const u8 *ies, int len) { return cfg80211_find_ie_match(eid, ies, len, NULL, 0, 0); } @@ -7961,10 +7963,13 @@ static inline const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len) * having to fit into the given data. */ static inline const struct element * -cfg80211_find_ext_elem(u8 ext_eid, const u8 *ies, int len) +cfg80211_find_ext_elem(enum ieee80211_eid_ext ext_eid, + const u8 *ies, int len) { + u8 _ext_eid = ext_eid; + return cfg80211_find_elem_match(WLAN_EID_EXTENSION, ies, len, - &ext_eid, 1, 0); + &_ext_eid, 1, 0); } /** diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 5fee0e9ca7b4..baeacf0544f6 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -7982,7 +7982,7 @@ ieee80211_mgd_check_cross_link_csa(struct ieee80211_sub_if_data *sdata, subelems = (u8 *)elems->ml_basic + common_size; subelems_len = elems->ml_basic_len - common_size; - for_each_element_id(sub, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE, + for_each_element_id(sub, (u8)IEEE80211_MLE_SUBELEM_PER_STA_PROFILE, subelems, subelems_len) { struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data; struct ieee80211_link_data *link; diff --git a/net/wireless/scan.c b/net/wireless/scan.c index d35c826c4b1a..70607c4625ec 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -1436,7 +1436,8 @@ void cfg80211_bss_flush(struct wiphy *wiphy) EXPORT_SYMBOL(cfg80211_bss_flush); const struct element * -cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len, +cfg80211_find_elem_match(enum ieee80211_eid eid, + const u8 *ies, unsigned int len, const u8 *match, unsigned int match_len, unsigned int match_offset) { @@ -2787,7 +2788,7 @@ cfg80211_defrag_mle(const struct element *mle, const u8 *ie, size_t ielen, ielen = mle_len - common_size; idx = 0; - for_each_element_id(elem, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE, + for_each_element_id(elem, (u8)IEEE80211_MLE_SUBELEM_PER_STA_PROFILE, ie, ielen) { res->sta_prof[idx] = (void *)elem->data; res->sta_prof_len[idx] = elem->datalen; From 145e565664c7979e21f691ee752ad459af6b12fb Mon Sep 17 00:00:00 2001 From: Huang Xiangping Date: Tue, 29 Sep 2026 11:56:49 +0800 Subject: [PATCH 1061/2126] wifi: cfg80211: process pending events before connect/disconnect requests cfg80211 reports connect results and disconnects through wdev->event_list, processed asynchronously by cfg80211_event_work(). The state that cfg80211_connect() and cfg80211_disconnect() reason about can therefore lag behind what the driver has already reported. cfg80211_disconnect() relies on that asynchronous processing on purpose: when the interface is connected it leaves wdev->u.client.ssid_len alone, expecting __cfg80211_disconnected() to clear it later: if (!wdev->connected) wdev->u.client.ssid_len = 0; If userspace reconnects before that deferred clear has run, cfg80211_connect() installs the new SSID and the queued EVENT_DISCONNECTED then wipes it again, together with wdev->connected, wdev->connect_keys and wdev->conn_owner_nlportid. The connection result of the new connection is subsequently processed with ssid_len == 0, so the BSS lookup in __cfg80211_connect_result() cannot match any BSS and WARN_ON(bss_not_found) triggers, dropping the connection result and leaving userspace waiting for a connection that is never reported. The same happens in cfg80211_roamed(). The zero ssid_len additionally defeats the -EALREADY and connection-owner checks of the following request, as both are skipped when ssid_len is zero. Fix this by draining the pending events before the connect and disconnect handlers inspect the interface state. Both run under the wiphy mutex, which cfg80211_process_rdev_events() requires, so no new lock ordering is introduced; this mirrors what cfg80211_change_iface() already does. Signed-off-by: Huang Xiangping Link: https://patch.msgid.link/20260929035649.33538-1-huangxiangping88@163.com Signed-off-by: Johannes Berg --- net/wireless/sme.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/wireless/sme.c b/net/wireless/sme.c index 458f72d8351a..85076f3b3355 100644 --- a/net/wireless/sme.c +++ b/net/wireless/sme.c @@ -1453,6 +1453,13 @@ int cfg80211_connect(struct cfg80211_registered_device *rdev, lockdep_assert_wiphy(wdev->wiphy); + /* + * Pending events may still change the state we're about to reason + * about (e.g. a deferred disconnect clearing ssid_len), so process + * them before looking at it. + */ + cfg80211_process_rdev_events(rdev); + /* * If we have an ssid_len, we're trying to connect or are * already connected, so reject a new SSID unless it's the @@ -1559,6 +1566,13 @@ int cfg80211_disconnect(struct cfg80211_registered_device *rdev, lockdep_assert_wiphy(wdev->wiphy); + /* + * Pending events may still change the state we're about to reason + * about (e.g. a deferred disconnect clearing ssid_len), so process + * them before looking at it. + */ + cfg80211_process_rdev_events(rdev); + kfree_sensitive(wdev->connect_keys); wdev->connect_keys = NULL; From 6832075ed4efdab62f9c7f4889496151624387ec Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 30 Sep 2026 10:47:29 +0200 Subject: [PATCH 1062/2126] wifi: mac80211_hwsim: reserve headroom for software encryption mac80211_hwsim accepts CCMP and GCMP keys in mac80211_hwsim_set_key() and encrypts unicast data frames itself in mac80211_hwsim_tx(), through ieee80211_encrypt_tx_skb(). It asks mac80211 to reserve tailroom for the MIC, but not headroom for the CCMP or GCMP header. Reserve the header as driver headroom. Signed-off-by: Felix Fietkau Link: https://patch.msgid.link/20260930084729.3000295-1-nbd@nbd.name Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 762f99eb15e4..79154332d54e 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -5942,6 +5942,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, hw->queues = 5; hw->offchannel_tx_hw_queue = 4; + hw->extra_tx_headroom = IEEE80211_CCMP_HDR_LEN; ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); ieee80211_hw_set(hw, CHANCTX_STA_CSA); From 743c052c1979560d3ddca312ef084715120e17c8 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 30 Sep 2026 12:02:56 +0300 Subject: [PATCH 1063/2126] wifi: cfg80211: add protected TWT assoc flag Protected TWT support is indicated in RSNX, but RSNX may be used from security profile now, and not be present in the association response frame, so the logic in mac80211 to determine it doesn't/won't really work. Add a flag for wpa_supplicant to indicate if protected TWT is supported in the association, it can easily check this based on the RSNX data that was used. Signed-off-by: Johannes Berg Reviewed-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260930120021.1eb6760356f2.Ie4962eaca97be29c7f08043d615534c7aeb3f370@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 2 ++ include/uapi/linux/nl80211.h | 5 +++++ net/wireless/nl80211.c | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 2e3dfee85019..3154f12fbd89 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -3407,6 +3407,7 @@ struct cfg80211_ml_reconf_req { * @ASSOC_REQ_SPP_AMSDU: SPP A-MSDUs will be used on this connection (if any) * @ASSOC_REQ_DISABLE_UHR: Disable UHR * @ASSOC_REQ_CIP: Enable Control Integrity Protocol + * @ASSOC_REQ_PROTECTED_TWT: Enable protected TWT */ enum cfg80211_assoc_req_flags { ASSOC_REQ_DISABLE_HT = BIT(0), @@ -3419,6 +3420,7 @@ enum cfg80211_assoc_req_flags { ASSOC_REQ_SPP_AMSDU = BIT(7), ASSOC_REQ_DISABLE_UHR = BIT(8), ASSOC_REQ_CIP = BIT(9), + ASSOC_REQ_PROTECTED_TWT = BIT(10), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 75d4c5d6a7a3..7dae0860a1b8 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -3228,6 +3228,9 @@ enum nl80211_commands { * @NL80211_ATTR_CIP_CAPABILITIES: The Control Integrity Protocol for the * station. * + * @NL80211_ATTR_ASSOC_PROTECTED_TWT: Enable protected TWT for the association, + * requires protected TWT support (flag attribute) + * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -3833,6 +3836,8 @@ enum nl80211_attrs { NL80211_ATTR_ASSOC_CIP, NL80211_ATTR_CIP_CAPABILITIES, + NL80211_ATTR_ASSOC_PROTECTED_TWT, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 572da1d8f3d9..cbd51de57b6e 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1100,6 +1100,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_FRAME_NO_STA] = { .type = NLA_FLAG }, [NL80211_ATTR_ASSOC_CIP] = { .type = NLA_FLAG }, [NL80211_ATTR_CIP_CAPABILITIES] = { .type = NLA_U8 }, + [NL80211_ATTR_ASSOC_PROTECTED_TWT] = { .type = NLA_FLAG }, }; /* policy for the key attributes */ @@ -13422,6 +13423,13 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) req.flags |= ASSOC_REQ_CIP; } + if (nla_get_flag(info->attrs[NL80211_ATTR_ASSOC_PROTECTED_TWT])) { + if (!wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_PROTECTED_TWT)) + return -EINVAL; + req.flags |= ASSOC_REQ_PROTECTED_TWT; + } + req.link_id = nl80211_link_id_or_invalid(info->attrs); if (info->attrs[NL80211_ATTR_MLO_LINKS]) { From 1a86b4fac91748073cc031232fcfe19313d11965 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 30 Sep 2026 12:02:57 +0300 Subject: [PATCH 1064/2126] wifi: mac80211: fix and clean up protected TWT support The "twt_protected" flag in the link/bss_conf information really isn't right since this is negotiated via RSNX and therefore cannot differ per link. Move it to be a per-STA indication and also derive it from the new assoc request flag since that gets used with security profile. Signed-off-by: Johannes Berg Reviewed-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260930120021.844fde440b63.I80999965c70e50d756ab62833fc7f53f2481cf3d@changeid Signed-off-by: Johannes Berg --- .../net/wireless/intel/iwlwifi/mld/iface.c | 4 +++- .../net/wireless/intel/iwlwifi/mvm/mac-ctxt.c | 3 ++- include/net/mac80211.h | 4 ++-- net/mac80211/ieee80211_i.h | 1 + net/mac80211/mlme.c | 21 ++++++++++++------- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/iface.c b/drivers/net/wireless/intel/iwlwifi/mld/iface.c index 2b837c6fa5fe..0307abff5644 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/iface.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/iface.c @@ -241,6 +241,8 @@ static void iwl_mld_fill_mac_cmd_sta(struct iwl_mld *mld, struct ieee80211_vif *vif, u32 action, struct iwl_mac_config_cmd *cmd) { + struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); + struct ieee80211_sta *ap_sta = mld_vif->ap_sta; struct ieee80211_bss_conf *link; u32 twt_policy = 0; int link_id; @@ -290,7 +292,7 @@ static void iwl_mld_fill_mac_cmd_sta(struct iwl_mld *mld, if (link->twt_requester) twt_policy |= TWT_SUPPORTED; - if (link->twt_protected) + if (ap_sta && ap_sta->twt_protected) twt_policy |= PROTECTED_TWT_SUPPORTED; if (link->twt_broadcast) twt_policy |= BROADCAST_TWT_SUPPORTED; diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c index b2c5be22c293..b41b4bbf0049 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c @@ -644,11 +644,12 @@ __le32 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm *mvm, u32 iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm *mvm, struct ieee80211_vif *vif) { + struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); u32 twt_policy = 0; if (vif->bss_conf.twt_requester && IWL_MVM_USE_TWT) twt_policy |= TWT_SUPPORTED; - if (vif->bss_conf.twt_protected) + if (mvmvif->ap_sta && mvmvif->ap_sta->twt_protected) twt_policy |= PROTECTED_TWT_SUPPORTED; if (vif->bss_conf.twt_broadcast) twt_policy |= BROADCAST_TWT_SUPPORTED; diff --git a/include/net/mac80211.h b/include/net/mac80211.h index cb9f8e14b3b6..a24d849b8f9c 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -640,7 +640,6 @@ struct ieee80211_bss_npca_params { * mode only, set if the AP advertises TWT responder role) * @twt_responder: does this BSS support TWT requester (relevant for managed * mode only, set if the AP advertises TWT responder role) - * @twt_protected: does this BSS support protected TWT frames * @twt_broadcast: does this BSS support broadcast TWT * @use_cts_prot: use CTS protection * @use_short_preamble: use 802.11b short preamble @@ -812,7 +811,6 @@ struct ieee80211_bss_conf { bool he_support; bool twt_requester; bool twt_responder; - bool twt_protected; bool twt_broadcast; /* erp related data */ bool use_cts_prot; @@ -2728,6 +2726,7 @@ struct ieee80211_link_sta { * @spp_amsdu: indicates whether the STA uses SPP A-MSDU or not. * @epp_peer: indicates that the peer is an EPP peer. * @cip: indicates whether the STA uses control frame protection or not. + * @twt_protected: does this STA support protected TWT frames * @nmi: For NDI stations, pointer to the NMI station of the peer. * @nan_sched: NAN peer schedule for this station. Valid only for NMI stations. * @ext_mld_capa_ops: the MLD's extended MLD capabilities and operations @@ -2750,6 +2749,7 @@ struct ieee80211_sta { u16 eml_cap; bool cip; + bool twt_protected; struct ieee80211_sta_aggregates *cur; diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 1430527d216c..b571019bd05a 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -487,6 +487,7 @@ struct ieee80211_mgd_assoc_data { bool s1g; bool spp_amsdu; bool cip; + bool protected_twt; s8 assoc_link_id; diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index baeacf0544f6..6ec45a9f7221 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -6168,13 +6168,6 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link, link_sta); bss_conf->he_support = link_sta->pub->he_cap.has_he; - if (elems->rsnx && elems->rsnx_len && - (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && - wiphy_ext_feature_isset(local->hw.wiphy, - NL80211_EXT_FEATURE_PROTECTED_TWT)) - bss_conf->twt_protected = true; - else - bss_conf->twt_protected = false; *changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems); @@ -6207,7 +6200,6 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link, } else { bss_conf->he_support = false; bss_conf->twt_requester = false; - bss_conf->twt_protected = false; bss_conf->eht_support = false; bss_conf->epcs_support = false; } @@ -7016,6 +7008,18 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, sta->sta.spp_amsdu = assoc_data->spp_amsdu; sta->sta.cip = assoc_data->cip; + sta->sta.twt_protected = assoc_data->protected_twt; + + /* + * backward compatibility - assumes that RSNX will not + * indicate anything (if present at all) _less_ than + * security profile RSNX content might + */ + if (elems->rsnx && elems->rsnx_len && + (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && + wiphy_ext_feature_isset(local->hw.wiphy, + NL80211_EXT_FEATURE_PROTECTED_TWT)) + sta->sta.twt_protected = true; if (ieee80211_vif_is_mld(&sdata->vif)) { if (!elems->ml_basic) @@ -10596,6 +10600,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU; assoc_data->cip = req->flags & ASSOC_REQ_CIP; + assoc_data->protected_twt = req->flags & ASSOC_REQ_PROTECTED_TWT; if (ifmgd->auth_data && !ifmgd->auth_data->done) { err = -EBUSY; From c8189e0929509c743e104de9cec236d2af5fa5e3 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 30 Sep 2026 12:05:18 +0300 Subject: [PATCH 1065/2126] wifi: mac80211: set SP in reg connectivity with any channel The regulatory connectivity element is informational and for debug, per spec, but that didn't stop some situations/tests from requiring certain bits to be set, notably the SP bit to be set if any channel is available for AFC client behaviour, even if that seems to reduce the utility of the bit. Set the bit accordingly by initialising the flags to NO_AFC and then masking for all enabled channels. Signed-off-by: Johannes Berg Reviewed-by: Emmanuel Grumbach Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260930120507.2ba7e2905019.I6d589cf60434ba9d3e007fe4537c8c8e2aeb7415@changeid Signed-off-by: Johannes Berg --- net/mac80211/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/mac80211/util.c b/net/mac80211/util.c index 9e1749d2e427..44feb80274c6 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -2731,13 +2731,13 @@ end: void ieee80211_put_reg_conn(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) { + u32 flags = IEEE80211_CHAN_NO_6GHZ_AFC_CLIENT; struct ieee80211_local *local = sdata->local; u8 reg_conn = IEEE80211_REG_CONN_LPI_VALID | IEEE80211_REG_CONN_LPI_VALUE | IEEE80211_REG_CONN_SP_VALID; struct ieee80211_supported_band *sband; bool available_channels = false; - u32 flags = 0; int i; sband = local->hw.wiphy->bands[NL80211_BAND_6GHZ]; @@ -2747,7 +2747,7 @@ void ieee80211_put_reg_conn(struct ieee80211_sub_if_data *sdata, for (i = 0; i < sband->n_channels; i++) { if (sband->channels[i].flags & IEEE80211_CHAN_DISABLED) continue; - flags |= sband->channels[i].flags; + flags &= sband->channels[i].flags; available_channels = true; } From 9b6cb072f9249e2cdb7c32be2b8069774c7e01e6 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 1 Oct 2026 10:37:40 +0300 Subject: [PATCH 1066/2126] wifi: b43: don't pass unterminated string to sscanf() The "buf" buffer is a PAGE_SIZE and allocated with kzalloc(). We store a string from the user in it and then pass it to sscanf() in the write functions such as shm32write__write_file(). Only a few numbers are stored in the buffer so it never comes close to filling up the whole PAGE_SIZE. Reserve the last character of the page for a NUL terminator. This is debugfs so it's root only. Fixes: 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices") Signed-off-by: Dan Carpenter Link: https://patch.msgid.link/b396713e697c7411b23a2157e2102c347ac900bc.1790839793.git.error27@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/b43/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/b43/debugfs.c b/drivers/net/wireless/broadcom/b43/debugfs.c index 31a1ff00c1a4..173ef5db90fc 100644 --- a/drivers/net/wireless/broadcom/b43/debugfs.c +++ b/drivers/net/wireless/broadcom/b43/debugfs.c @@ -557,7 +557,7 @@ static ssize_t b43_debugfs_write(struct file *file, if (!count) return 0; - if (count > PAGE_SIZE) + if (count >= PAGE_SIZE) return -E2BIG; dev = file->private_data; if (!dev) From f94595252b318a9ae3c01d78b3bcd33b01b1c082 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 1 Oct 2026 10:37:46 +0300 Subject: [PATCH 1067/2126] wifi: b43legacy: debugfs: NUL terminate string in debugfs The "buf" buffer is PAGE_SIZE and allocated with kzalloc(). We store a string from the user in it and then pass it to sscanf() in the write functions such as tsf_write_file(). The buffer is only used to store a number so we never come close to filling up the whole PAGE_SIZE. Reserve the last character of the page for a NUL terminator. This is debugfs so it's root only. Fixes: 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices") Signed-off-by: Dan Carpenter Link: https://patch.msgid.link/909ea7a88658b5e7c183bf0fda31687a91d73818.1790839793.git.error27@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/b43legacy/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/b43legacy/debugfs.c b/drivers/net/wireless/broadcom/b43legacy/debugfs.c index a04d90d7307c..7ce8bcf12f0a 100644 --- a/drivers/net/wireless/broadcom/b43legacy/debugfs.c +++ b/drivers/net/wireless/broadcom/b43legacy/debugfs.c @@ -259,7 +259,7 @@ static ssize_t b43legacy_debugfs_write(struct file *file, if (!count) return 0; - if (count > PAGE_SIZE) + if (count >= PAGE_SIZE) return -E2BIG; dev = file->private_data; if (!dev) From ece30e1daf6a9c95d6f9d0518534a0b9c8c7fd42 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 1 Oct 2026 10:37:50 +0300 Subject: [PATCH 1068/2126] wifi: carl9170: NUL terminate string in debugfs The "buf" buffer comes from the user. We use it to store a number or two so it doesn't need to be large. It gets passed to sscanf() in the write functions such as carl9170_debugfs_erp_write(). Ensure that buffer is NUL terminated. This is debugfs so it's root only. Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code") Signed-off-by: Dan Carpenter Acked-by: Christian Lamparter Acked-by: Jeff Johnson Link: https://patch.msgid.link/674270ab4aeefa1982362c0ea4132427e14f15eb.1790839793.git.error27@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/carl9170/debug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c index 0498df2a2160..bc6c8e0b1d16 100644 --- a/drivers/net/wireless/ath/carl9170/debug.c +++ b/drivers/net/wireless/ath/carl9170/debug.c @@ -119,7 +119,7 @@ static ssize_t carl9170_debugfs_write(struct file *file, if (!count) return 0; - if (count > PAGE_SIZE) + if (count >= PAGE_SIZE) return -E2BIG; ar = file->private_data; @@ -131,7 +131,7 @@ static ssize_t carl9170_debugfs_write(struct file *file, if (!dfops->write) return -ENOSYS; - buf = vmalloc(count); + buf = vmalloc(count + 1); if (!buf) return -ENOMEM; @@ -139,6 +139,7 @@ static ssize_t carl9170_debugfs_write(struct file *file, err = -EFAULT; goto out_free; } + buf[count] = '\0'; if (mutex_trylock(&ar->mutex) == 0) { err = -EAGAIN; From bded6f5803dcb83b7ba2153bf9f83535c4066f73 Mon Sep 17 00:00:00 2001 From: Manish Dharanenthiran Date: Thu, 1 Oct 2026 14:43:45 +0530 Subject: [PATCH 1069/2126] wifi: mac80211: Guard FILS discovery and unsolicited broadcast probe response According to IEEE Std 802.11-2024, subclause 11.45.2.1 FILS Discovery frame transmission, only a transmitting BSS shall transmit a FILS Discovery frame. Currently, BSS_CHANGED_FILS_DISCOVERY is set unconditionally for all the BSSs. Hence, add a check to allow setting the FILS Discovery flag only for a transmitting BSS. Similarly, IEEE Std 802.11-2024, subclause 26.17.2.3.2 AP behavior for fast passive scanning, mentions that unsolicited broadcast probe response frame shall be transmitted only by a transmitting BSS. Hence, add a check to allow setting the BSS_CHANGED_UNSOL_BCAST_PROBE_RESP only for a transmitting BSS. Currently in user-space there is no restriction on sending this for non-transmitting BSS, thus it may send these for those BSSs as well. While this is not a valid configuration, returning an error here could be fatal because failing 'start_ap' or 'update_ap' operation would result in failure of bringing up those BSSs. Thus, to maintain the compatibility with existing user-space, ignore the config for non-transmitting BSS silently. Signed-off-by: Manish Dharanenthiran Link: https://patch.msgid.link/20261001-fils-v3-1-55c5628f9d1d@oss.qualcomm.com Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index bd1a857c812d..323eab042b32 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1159,7 +1159,15 @@ static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata, struct fils_discovery_data *new, *old = NULL; struct ieee80211_fils_discovery *fd; - if (!params->update) + /* + * This configuration is only applicable to transmitting BSSes. + * + * Current user-space version may also set this for non-transmitting + * BSSes. While this is not a valid configuration, to maintain the + * compatibility with the existing user-space ignore the configuration + * for non-transmitting BSS silently. + */ + if (!params->update || link_conf->nontransmitted) return 0; fd = &link_conf->fils_discovery; @@ -1194,7 +1202,15 @@ ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata, { struct unsol_bcast_probe_resp_data *new, *old = NULL; - if (!params->update) + /* + * This configuration is only applicable to transmitting BSSes. + * + * Current user-space version may also set this for non-transmitting + * BSSes. While this is not a valid configuration, to maintain the + * compatibility with the existing user-space ignore the configuration + * for non-transmitting BSS silently. + */ + if (!params->update || link_conf->nontransmitted) return 0; link_conf->unsol_bcast_probe_resp_interval = params->interval; From 56fb2334c86cef0b6d44099a6b21de4c8d80a7cb Mon Sep 17 00:00:00 2001 From: Aloka Dixit Date: Fri, 2 Oct 2026 12:10:56 -0700 Subject: [PATCH 1070/2126] Revert "wifi: mac80211: do not use old MBSSID elements" Commit a519be2f5d95 ("wifi: mac80211: do not use old MBSSID elements") fixed the incorrect inclusion of stopped/removed non-transmitted profiles from the Beacon frames, but it caused a regression for channel switch (CSA) and BSS color change (CCA) operations initiated from hostapd. Hostapd passes two Beacon templates to kernel for CSA and CCA - (1) beacon_csa/beacon_color_change used during the countdown. (2) beacon_after/beacon_next used after the countdown completes. Hostapd relies on the kernel to include the old MBSSID elements while sending beacon_csa/beacon_color_change templates to the driver. This path is now broken and results in CSA/CCA failure. Including existing MBSSID elements explicitly makes the netlink buffer larger than default 4 KB depending on the number of APs which would need unnecessary complication to pre-calculate the buffer length. Revert the commit to fix the regression. Regarding the original issue fixed by the reverted commit - Hostapd now has a new commit which always includes at least one MBSSID element when the feature is enabled, hence when all non-transmitted profiles are removed, this empty element ensures that stopped profiles are not advertised. Fixes: a519be2f5d95 ("wifi: mac80211: do not use old MBSSID elements") Signed-off-by: Aloka Dixit Link: https://patch.msgid.link/20261002-csa_cca_fix-v1-1-b83a998aeb44@oss.qualcomm.com Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 323eab042b32..4eab9ab49d20 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1534,6 +1534,7 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, size = sizeof(*new) + new_head_len + new_tail_len; + /* new or old multiple BSSID elements? */ if (params->mbssid_ies) { mbssid = params->mbssid_ies; size += struct_size(new->mbssid_ies, elem, mbssid->cnt); @@ -1543,6 +1544,15 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, } size += ieee80211_get_mbssid_beacon_len(mbssid, rnr, mbssid->cnt); + } else if (old && old->mbssid_ies) { + mbssid = old->mbssid_ies; + size += struct_size(new->mbssid_ies, elem, mbssid->cnt); + if (old && old->rnr_ies) { + rnr = old->rnr_ies; + size += struct_size(new->rnr_ies, elem, rnr->cnt); + } + size += ieee80211_get_mbssid_beacon_len(mbssid, rnr, + mbssid->cnt); } new = kzalloc(size, GFP_KERNEL); From 229cf0621950919c38a271ab3c07dfd41dd301d0 Mon Sep 17 00:00:00 2001 From: Aloka Dixit Date: Fri, 2 Oct 2026 12:10:57 -0700 Subject: [PATCH 1071/2126] wifi: mac80211: remove redundant null check in ieee80211_assign_beacon() The else-if branch condition 'old && old->mbssid_ies' already guarantees 'old' is non-NULL. The inner 'old &&' in 'if (old && old->rnr_ies)' is therefore redundant; remove it. Signed-off-by: Aloka Dixit Link: https://patch.msgid.link/20261002-csa_cca_fix-v1-2-b83a998aeb44@oss.qualcomm.com Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 4eab9ab49d20..917594ad6474 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1547,7 +1547,7 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, } else if (old && old->mbssid_ies) { mbssid = old->mbssid_ies; size += struct_size(new->mbssid_ies, elem, mbssid->cnt); - if (old && old->rnr_ies) { + if (old->rnr_ies) { rnr = old->rnr_ies; size += struct_size(new->rnr_ies, elem, rnr->cnt); } From cd9c0566b5b3ccff979b47dbb4abc9e4ad1ada30 Mon Sep 17 00:00:00 2001 From: Andrei-Alexandru Bleortu Date: Sun, 4 Oct 2026 14:14:50 +0300 Subject: [PATCH 1072/2126] wifi: mac80211: keep the BSS color while a color change is pending When a BSS color change starts, mac80211 tells the driver that the BSS color is disabled, as the Beacon frames say during the countdown, but it also sets the color to 0. While the BSS Color Disabled subfield is 1, an HE STA shall keep using its nonzero color, the one it used before, in the BSS_COLOR of the HE PPDUs it transmits (IEEE Std 802.11-2024, 26.11.4), and a driver can only do so if it still knows the color. Keep the current color and only clear enabled. Assisted-by: LLM Signed-off-by: Andrei-Alexandru Bleortu Link: https://patch.msgid.link/e696e399eee2f42c2907c45c85aa894705bee1bf.1791111135.git.me@andrei-z.com Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 917594ad6474..a00566aff8aa 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -5830,7 +5830,9 @@ ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev, cfg80211_color_change_started_notify(sdata->dev, params->count, link_id); if (changed) - ieee80211_color_change_bss_config_notify(link, 0, 0, changed); + ieee80211_color_change_bss_config_notify(link, + link_conf->he_bss_color.color, + 0, changed); else /* if the beacon didn't change, we can finalize immediately */ ieee80211_color_change_finalize(link); From ef650cdd4495df8afce89826a1c3bc3f285ab3ae Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:48 +0300 Subject: [PATCH 1073/2126] wifi: cfg80211: nan: add Instant Communication support Add NL80211_NAN_CONF_INSTANT_COMM flag to let user space request that the NAN synchronization logic starts Instant Communication (IC) as defined in Chapter 13 of the Wi-Fi Aware Specification v4.0. Add NL80211_NAN_CAPA_INSTANT_COMM for drivers to advertise it. The capability requires configurable synchronization support, and IC requests are rejected if it isn't advertised. When IC is enabled, user space must also configure the discovery beacon interval. The IC schedule is expected to be configured by user space. Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-2-ilan.peer@intel.com Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 9 ++++++++- include/uapi/linux/nl80211.h | 12 ++++++++++++ net/wireless/core.c | 5 +++++ net/wireless/nl80211.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 3154f12fbd89..05c625d9e076 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4193,9 +4193,12 @@ struct cfg80211_nan_band_config { * that can take a value from 50-6F-9A-01-00-00 to 50-6F-9A-01-FF-FF. * @scan_period: period (in seconds) between NAN scans. * @scan_dwell_time: dwell time (in milliseconds) for NAN scans. - * @discovery_beacon_interval: interval (in TUs) for discovery beacons. + * @discovery_beacon_interval: interval (in TUs) for discovery beacons. Must be + * greater than 0 when @instant_comm is true. * @enable_dw_notification: flag to enable/disable discovery window * notifications. + * @instant_comm: if true, start Instant Communication (IC) as defined in + * Chapter 13 of the Wi-Fi Aware Specification v4.0. * @band_cfgs: array of band specific configurations, indexed by * &enum nl80211_band values. * @extra_nan_attrs: pointer to additional NAN attributes. @@ -4211,6 +4214,7 @@ struct cfg80211_nan_conf { u16 scan_dwell_time; u8 discovery_beacon_interval; bool enable_dw_notification; + bool instant_comm; struct cfg80211_nan_band_config band_cfgs[NUM_NL80211_BANDS]; const u8 *extra_nan_attrs; u16 extra_nan_attrs_len; @@ -6307,10 +6311,13 @@ struct wiphy_radio { * @WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC: Device supports NAN configurable * synchronization. * @WIPHY_NAN_FLAGS_USERSPACE_DE: Device doesn't support DE offload. + * @WIPHY_NAN_FLAGS_INSTANT_COMM: Device can switch to Instant Communication + * (IC) mode. Can only be set along with %WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC. */ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC = BIT(0), WIPHY_NAN_FLAGS_USERSPACE_DE = BIT(1), + WIPHY_NAN_FLAGS_INSTANT_COMM = BIT(2), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 7dae0860a1b8..341f8395d1af 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7895,6 +7895,11 @@ enum nl80211_nan_band_conf_attributes { * the upcoming discovery window with * %NL80211_CMD_NAN_NEXT_DW_NOTIFICATION. * This is a flag attribute. + * @NL80211_NAN_CONF_INSTANT_COMM: If set, the NAN synchronization logic will + * start Instant Communication (IC) as defined in Chapter 13 of the + * Wi-Fi Aware Specification v4.0. + * %NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL must be set as well. + * This is a flag attribute. * @NUM_NL80211_NAN_CONF_ATTR: Internal. * @NL80211_NAN_CONF_ATTR_MAX: Highest NAN configuration attribute. * @@ -7910,6 +7915,7 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_SCAN_DWELL_TIME, NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL, NL80211_NAN_CONF_NOTIFY_DW, + NL80211_NAN_CONF_INSTANT_COMM, /* keep last */ NUM_NL80211_NAN_CONF_ATTR, @@ -9126,6 +9132,11 @@ enum nl80211_s1g_short_beacon_attrs { * specification Table 79 (Capabilities field). * @NL80211_NAN_CAPA_PHY: nested attribute containing band-agnostic * capabilities for NAN data path. See &enum nl80211_nan_phy_cap_attr. + * @NL80211_NAN_CAPA_INSTANT_COMM: Flag attribute indicating that the device + * can switch to Instant Communication (IC) mode, as defined in Chapter 13 + * of the Wi-Fi Aware Specification v4.0. Can only be set if + * %NL80211_NAN_CAPA_CONFIGURABLE_SYNC is set. When IC is enabled, the IC + * schedule is expected to be configured by user space. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */ @@ -9139,6 +9150,7 @@ enum nl80211_nan_capabilities { NL80211_NAN_CAPA_MAX_CHANNEL_SWITCH_TIME, NL80211_NAN_CAPA_CAPABILITIES, NL80211_NAN_CAPA_PHY, + NL80211_NAN_CAPA_INSTANT_COMM, /* keep last */ __NL80211_NAN_CAPABILITIES_LAST, NL80211_NAN_CAPABILITIES_MAX = __NL80211_NAN_CAPABILITIES_LAST - 1, diff --git a/net/wireless/core.c b/net/wireless/core.c index dc1e0522340a..9176659345f0 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -964,6 +964,11 @@ int wiphy_register(struct wiphy *wiphy) (!wiphy->nan_capa.phy.ht.ht_supported || wiphy->n_radio > 1))) return -EINVAL; + if (WARN_ON((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_INSTANT_COMM) && + !(wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC))) + return -EINVAL; + if (WARN_ON(wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))) return -EINVAL; diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index cbd51de57b6e..7ee69ec10b0f 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -687,6 +687,7 @@ nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL] = NLA_POLICY_RANGE(NLA_U8, 50, 200), [NL80211_NAN_CONF_NOTIFY_DW] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_INSTANT_COMM] = { .type = NLA_FLAG }, }; static const struct netlink_range_validation nl80211_punct_bitmap_range = { @@ -3037,6 +3038,10 @@ static int nl80211_put_nan_capa(struct wiphy *wiphy, struct sk_buff *msg) nla_put_flag(msg, NL80211_NAN_CAPA_USERSPACE_DE)) goto fail; + if ((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_INSTANT_COMM) && + nla_put_flag(msg, NL80211_NAN_CAPA_INSTANT_COMM)) + goto fail; + if (nla_put_u8(msg, NL80211_NAN_CAPA_OP_MODE, wiphy->nan_capa.op_mode) || nla_put_u8(msg, NL80211_NAN_CAPA_NUM_ANTENNAS, @@ -16789,6 +16794,23 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, conf->enable_dw_notification = nla_get_flag(attrs[NL80211_NAN_CONF_NOTIFY_DW]); + conf->instant_comm = nla_get_flag(attrs[NL80211_NAN_CONF_INSTANT_COMM]); + if (conf->instant_comm) { + if (!(wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_INSTANT_COMM)) { + NL_SET_ERR_MSG_ATTR(info->extack, + attrs[NL80211_NAN_CONF_INSTANT_COMM], + "Instant Communication is not supported"); + return -EOPNOTSUPP; + } + + if (!conf->discovery_beacon_interval) { + NL_SET_ERR_MSG_ATTR(info->extack, + attrs[NL80211_NAN_CONF_INSTANT_COMM], + "Instant Communication requires a discovery beacon interval"); + return -EINVAL; + } + } + out: if (!conf->band_cfgs[NL80211_BAND_5GHZ].chan && (!conf->bands || conf->bands & BIT(NL80211_BAND_5GHZ))) { From 05b44bd48fb38218570d792d522b8ea8c5438b17 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:49 +0300 Subject: [PATCH 1074/2126] wifi: mac80211: nan: Update NAN configuration copy Copy the Instant Communication flag when storing the NAN configuration. Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-3-ilan.peer@intel.com Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index a00566aff8aa..69002d740a58 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -368,6 +368,7 @@ static int ieee80211_nan_conf_copy(struct cfg80211_nan_conf *dst, dst->discovery_beacon_interval = src->discovery_beacon_interval; dst->enable_dw_notification = src->enable_dw_notification; + dst->instant_comm = src->instant_comm; memcpy(&dst->band_cfgs, &src->band_cfgs, sizeof(dst->band_cfgs)); From f4134597a0efa48341416fbb76b667d706526c07 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:50 +0300 Subject: [PATCH 1075/2126] wifi: cfg80211: nan: check Rx registration for NAN beacons Instant Communication requires user space to track the NAN beacons, so fail device registration when the device declares NAN Device support for Instant Communication but doesn't support Rx registration for beacon frames. Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-4-ilan.peer@intel.com Signed-off-by: Johannes Berg --- net/wireless/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/wireless/core.c b/net/wireless/core.c index 9176659345f0..45a1709cffe7 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -969,6 +969,13 @@ int wiphy_register(struct wiphy *wiphy) WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC))) return -EINVAL; + /* Instant Communication requires user space to track NAN beacons */ + if (WARN_ON((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_INSTANT_COMM) && + (!wiphy->mgmt_stypes || + !(wiphy->mgmt_stypes[NL80211_IFTYPE_NAN].rx & + BIT(IEEE80211_STYPE_BEACON >> 4))))) + return -EINVAL; + if (WARN_ON(wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))) return -EINVAL; From 41da18108d25fb487c503c9a63b72cc543a9e72a Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:51 +0300 Subject: [PATCH 1076/2126] wifi: cfg80211: do not use NAN beacons to update the BSS table As NAN beacons have a different structure compared to beacons defined in the IEEE802.11 specification, e.g., they do not contain a SSID element etc., they cannot be used to update the BSS table. Add a utility function to check if a frame is a NAN beacon and use it do return early in cfg80211_inform_bss_frame_data(). Signed-off-by: Ilan Peer Link: https://patch.msgid.link/20261005084458.3666739-5-ilan.peer@intel.com Signed-off-by: Johannes Berg --- include/linux/ieee80211-nan.h | 26 ++++++++++++++++++++++++++ net/wireless/scan.c | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/ieee80211-nan.h b/include/linux/ieee80211-nan.h index 455033955e54..b332a94671ba 100644 --- a/include/linux/ieee80211-nan.h +++ b/include/linux/ieee80211-nan.h @@ -74,4 +74,30 @@ struct ieee80211_nan_anchor_master_info { _attr = (const struct ieee80211_nan_attr *) \ (_attr->data + le16_to_cpu(_attr->length))) +static inline bool ieee80211_is_nan_beacon(const struct ieee80211_mgmt *mgmt, + size_t len) +{ + const struct element *elem; + + /* The NAN IE is at least 6 octets */ + if (len < offsetofend(struct ieee80211_mgmt, u.beacon) + 6) + return false; + + if (!ieee80211_is_beacon(mgmt->frame_control)) + return false; + + /* NAN Cluster IDs range from 50-6F-9A-01-00-00 to 50-6F-9A-01-FF-FF */ + if (get_unaligned_be32(mgmt->bssid) != ((WLAN_OUI_WFA << 8) | 0x01)) + return false; + + elem = (const struct element *)mgmt->u.beacon.variable; + if (elem->id != WLAN_EID_VENDOR_SPECIFIC || + elem->datalen < 4 || + get_unaligned_be32(elem->data) != + (WLAN_OUI_WFA << 8 | WLAN_OUI_TYPE_WFA_NAN)) + return false; + + return true; +} + #endif /* LINUX_IEEE80211_NAN_H */ diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 70607c4625ec..ac56338f0f43 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -3339,6 +3339,10 @@ cfg80211_inform_bss_frame_data(struct wiphy *wiphy, if (WARN_ON(!wiphy)) return NULL; + /* NAN beacons are not a BSS, don't add to the BSS table */ + if (ieee80211_is_nan_beacon(mgmt, len)) + return NULL; + BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) != offsetof(struct ieee80211_mgmt, u.beacon.variable)); From b39e4172f4261a923928f89b5c97507b27e72fad Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:52 +0300 Subject: [PATCH 1077/2126] wifi: mac80211: nan: allow Rx registration for NAN beacons Instant Communication requires user space to track the NAN beacons, so let it register for Rx of beacons on a NAN interface. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-6-ilan.peer@intel.com Signed-off-by: Johannes Berg --- net/mac80211/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 7816395681fa..b889d2a7ef75 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -745,8 +745,13 @@ ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { }, [NL80211_IFTYPE_NAN] = { .tx = 0xffff, + /* + * Beacon Rx registration is needed to let user space handle + * service discovery when Instant Communication is enabled. + */ .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4), + BIT(IEEE80211_STYPE_AUTH >> 4) | + BIT(IEEE80211_STYPE_BEACON >> 4), }, [NL80211_IFTYPE_NAN_DATA] = { .tx = 0xffff, From d5f706d3a9b50a87078a3801c0c05b79389029d5 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:53 +0300 Subject: [PATCH 1078/2126] wifi: mac80211: accept NAN beacons only when IC is enabled Accept NAN beacons in the Rx path only when Instant Communication (IC) is enabled in the NAN configuration. Signed-off-by: Ilan Peer Link: https://patch.msgid.link/20261005084458.3666739-7-ilan.peer@intel.com Signed-off-by: Johannes Berg --- net/mac80211/rx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index f5893f9c07c6..1121e650b0dd 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4687,7 +4687,8 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) * Accept only frames that are addressed to the NAN cluster * (based on the Cluster ID). From these frames, accept only * - public action frames, - * - authentication frames to the local address, and + * - authentication frames to the local address, + * - NAN beacons, when Instant Communication is enabled, and * - robust management frames except disassoc. */ if (!ether_addr_equal(sdata->u.nan.conf.cluster_id, hdr->addr3)) @@ -4697,6 +4698,9 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) if (ieee80211_is_auth(hdr->frame_control) && ether_addr_equal(sdata->vif.addr, hdr->addr1)) return true; + if (ieee80211_is_nan_beacon((struct ieee80211_mgmt *)hdr, + skb->len)) + return sdata->u.nan.conf.instant_comm; if (!ieee80211_is_disassoc(hdr->frame_control) && ieee80211_is_robust_mgmt_frame(skb)) return true; From ee0ea8cebd11781c4ae5ea5d050fb15ad12887c9 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:54 +0300 Subject: [PATCH 1079/2126] wifi: ieee80211: add NAN service ID list attribute definitions Add the Service ID List and Subscribe Service ID List NAN attribute IDs. These are needed to filter in NAN beacons during Instant Communication. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-8-ilan.peer@intel.com Signed-off-by: Johannes Berg --- include/linux/ieee80211-nan.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/ieee80211-nan.h b/include/linux/ieee80211-nan.h index b332a94671ba..7815a6cf8160 100644 --- a/include/linux/ieee80211-nan.h +++ b/include/linux/ieee80211-nan.h @@ -40,6 +40,8 @@ /* NAN attributes, as defined in Wi-Fi Aware (TM) specification 4.0 Table 42 */ #define NAN_ATTR_MASTER_INDICATION 0x00 #define NAN_ATTR_CLUSTER_INFO 0x01 +#define NAN_ATTR_SERVICE_ID_LIST 0x02 +#define NAN_ATTR_SUBSCRIBE_SERVICE_ID_LIST 0x28 struct ieee80211_nan_attr { u8 attr; From 37c7e192b3c5529e7852ea906f6c3d56ce475116 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:55 +0300 Subject: [PATCH 1080/2126] wifi: mac80211_hwsim: nan: use ieee80211_is_nan_beacon() helper Use the new ieee80211_is_nan_beacon() helper to identify NAN beacons instead of open-coding the cluster ID and vendor element checks. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-9-ilan.peer@intel.com Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim_nan.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c index 2d9f6d7b9251..fab6bd9e3cfb 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c @@ -230,9 +230,7 @@ void mac80211_hwsim_nan_rx(struct ieee80211_hw *hw, ssize_t data_len; u8 slot; - /* Need a NAN vendor element at the start */ - if (skb->len < (offsetofend(struct ieee80211_mgmt, u.beacon) + 6) || - !ieee80211_is_beacon(mgmt->frame_control)) + if (!ieee80211_is_nan_beacon(mgmt, skb->len)) return; data_len = skb->len - offsetofend(struct ieee80211_mgmt, u.beacon); @@ -279,17 +277,6 @@ void mac80211_hwsim_nan_rx(struct ieee80211_hw *hw, if (rx_status.signal < NAN_RSSI_MIDDLE) return; - /* Needs to be a valid NAN cluster ID in A3 */ - if (get_unaligned_be32(mgmt->bssid) != ((WLAN_OUI_WFA << 8) | 0x01)) - return; - - /* We are only interested in NAN beacons */ - if (nan_elem->id != WLAN_EID_VENDOR_SPECIFIC || - nan_elem->datalen < 4 || - get_unaligned_be32(nan_elem->data) != - (WLAN_OUI_WFA << 8 | WLAN_OUI_TYPE_WFA_NAN)) - return; - u8 *nan_defragmented __free(kfree) = kzalloc(data_len, GFP_ATOMIC); if (!nan_defragmented) return; From 1bcfad2871a578b46549ad0d8ffbc8672dd615c5 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:56 +0300 Subject: [PATCH 1081/2126] wifi: mac80211_hwsim: nan: prepare for more configurable NAN settings In preparation for handling more of the NAN configuration setting, do some refactoring and cleanup: - Extract mac80211_hwsim_nan_set_config() and call it both when NAN is started and when the configuration changes. - Add NAN_BEACON_ELEM_LEN instead of the hardcoded 27. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Link: https://patch.msgid.link/20261005084458.3666739-10-ilan.peer@intel.com Signed-off-by: Johannes Berg --- .../net/wireless/virtual/mac80211_hwsim_nan.c | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c index fab6bd9e3cfb..2b30933ef2f9 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c @@ -33,6 +33,9 @@ static_assert(DW0_TSF_MASK + 1 == 8192 * 1024); #define NAN_RSSI_CLOSE (-60) #define NAN_RSSI_MIDDLE (-75) +/* Size of the NAN vendor element carrying the mandatory attributes */ +#define NAN_BEACON_ELEM_LEN 27 + /* Quiet time at the end of each slot where TX is suppressed */ #define NAN_CHAN_SWITCH_TIME_US 256 @@ -685,7 +688,7 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, { struct ieee80211_vendor_ie nan_ie = { .element_id = WLAN_EID_VENDOR_SPECIFIC, - .len = 27 - 2, + .len = NAN_BEACON_ELEM_LEN - 2, .oui = { u32_get_bits(WLAN_OUI_WFA, 0xff0000), u32_get_bits(WLAN_OUI_WFA, 0xff00), u32_get_bits(WLAN_OUI_WFA, 0xff) }, @@ -694,7 +697,7 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, size_t alloc_size = IEEE80211_TX_STATUS_HEADROOM + offsetofend(struct ieee80211_mgmt, u.beacon) + - 27 /* size of NAN vendor element */; + NAN_BEACON_ELEM_LEN; struct ieee80211_nan_master_indication master_indication; struct ieee80211_nan_attr nan_attr; struct ieee80211_mgmt *mgmt; @@ -905,11 +908,20 @@ mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy, ieee80211_nan_sched_update_done(data->nan.device_vif); } +static int mac80211_hwsim_nan_set_config(struct mac80211_hwsim_data *data, + struct cfg80211_nan_conf *conf) +{ + data->nan.notify_dw = conf->enable_dw_notification; + + return 0; +} + int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct cfg80211_nan_conf *conf) { struct mac80211_hwsim_data *data = hw->priv; + int err; if (vif->type != NL80211_IFTYPE_NAN) return -EINVAL; @@ -917,6 +929,10 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, if (data->nan.device_vif) return -EALREADY; + err = mac80211_hwsim_nan_set_config(data, conf); + if (err) + return err; + /* set this before starting the timer, as preemption might occur */ data->nan.device_vif = vif; data->nan.bands = conf->bands; @@ -945,8 +961,6 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, ether_addr_copy(data->nan.cluster_id, conf->cluster_id); - data->nan.notify_dw = conf->enable_dw_notification; - return 0; } @@ -983,13 +997,17 @@ int mac80211_hwsim_nan_change_config(struct ieee80211_hw *hw, wiphy_debug(hw->wiphy, "nan_config_changed: changes=0x%x\n", changes); + if (changes & CFG80211_NAN_CONF_CHANGED_CONFIG) { + int err = mac80211_hwsim_nan_set_config(data, conf); + + if (err) + return err; + } + /* Handle only the changes we care about for simulation purposes */ if (changes & CFG80211_NAN_CONF_CHANGED_BANDS) data->nan.bands = conf->bands; - if (changes & CFG80211_NAN_CONF_CHANGED_CONFIG) - data->nan.notify_dw = conf->enable_dw_notification; - if (changes & CFG80211_NAN_CONF_CHANGED_PREF) { scoped_guard(spinlock_bh, &data->nan.state_lock) data->nan.master_pref = conf->master_pref; From 24356be4c609155422d11d652880b7a1613a3cb0 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:57 +0300 Subject: [PATCH 1082/2126] wifi: mac80211_hwsim: nan: Handle more of the NAN configuration - Use the discovery beacon interval configured by user space instead of always using hardcoded 100 TUs. - Append the NAN attributes set by user space to the locally generated ones in the discovery beacons. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Link: https://patch.msgid.link/20261005084458.3666739-11-ilan.peer@intel.com Signed-off-by: Johannes Berg --- .../net/wireless/virtual/mac80211_hwsim_nan.c | 69 +++++++++++++++++-- .../net/wireless/virtual/mac80211_hwsim_nan.h | 5 ++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c index 2b30933ef2f9..e7815eb95c55 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c @@ -36,6 +36,9 @@ static_assert(DW0_TSF_MASK + 1 == 8192 * 1024); /* Size of the NAN vendor element carrying the mandatory attributes */ #define NAN_BEACON_ELEM_LEN 27 +/* Space left in the NAN vendor element for the configured attributes */ +#define NAN_BEACON_EXTRA_ATTRS_LEN (255 - (NAN_BEACON_ELEM_LEN - 2)) + /* Quiet time at the end of each slot where TX is suppressed */ #define NAN_CHAN_SWITCH_TIME_US 256 @@ -704,16 +707,27 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, struct sk_buff *skb; /* - * TODO: Should the configured vendor elements or NAN attributes be - * included in some of these beacons? + * TODO: Should the configured vendor elements be included in some of + * these beacons? */ + /* Allocate maximal size for NAN IE */ + if (is_discovery) + alloc_size += NAN_BEACON_EXTRA_ATTRS_LEN; + skb = alloc_skb(alloc_size, GFP_ATOMIC); if (!skb) return; spin_lock(&data->nan.state_lock); + /* + * The attributes configured by user space are appended to the + * mandatory ones. + */ + if (is_discovery) + nan_ie.len += data->nan.extra_nan_attrs_len; + skb_reserve(skb, IEEE80211_TX_STATUS_HEADROOM); mgmt = skb_put(skb, offsetofend(struct ieee80211_mgmt, u.beacon)); @@ -724,7 +738,9 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON); - mgmt->u.beacon.beacon_int = cpu_to_le16(is_discovery ? 100 : DWST_TU); + mgmt->u.beacon.beacon_int = + cpu_to_le16(is_discovery ? data->nan.discovery_beacon_interval : + DWST_TU); mgmt->u.beacon.capab_info = cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME | WLAN_CAPABILITY_SHORT_PREAMBLE); @@ -755,6 +771,10 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, skb_put_data(skb, &data->nan.current_ami, sizeof(data->nan.current_ami)); + if (is_discovery && data->nan.extra_nan_attrs_len) + skb_put_data(skb, data->nan.extra_nan_attrs, + data->nan.extra_nan_attrs_len); + spin_unlock(&data->nan.state_lock); mac80211_hwsim_tx_frame(data->hw, skb, channel); @@ -884,10 +904,11 @@ mac80211_hwsim_nan_discovery_beacon_timer(struct hrtimer *timer) tsf_now = mac80211_hwsim_get_tsf(data->hw, data->nan.device_vif); /* Wrap value to be after the next TBTT */ - tbtt = tsf_now + ieee80211_tu_to_usec(100); + tbtt = tsf_now + ieee80211_tu_to_usec(data->nan.discovery_beacon_interval); /* Round TBTT down to the correct time */ - div_u64_rem(tbtt, ieee80211_tu_to_usec(100), &remainder); + div_u64_rem(tbtt, ieee80211_tu_to_usec(data->nan.discovery_beacon_interval), + &remainder); tbtt = tbtt - remainder; hrtimer_set_expires(&data->nan.discovery_beacon_timer, @@ -911,8 +932,37 @@ mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy, static int mac80211_hwsim_nan_set_config(struct mac80211_hwsim_data *data, struct cfg80211_nan_conf *conf) { + const u8 *extra_nan_attrs = NULL; + const u8 *old; + + if (conf->extra_nan_attrs_len > NAN_BEACON_EXTRA_ATTRS_LEN) + return -EINVAL; + + if (conf->extra_nan_attrs_len) { + extra_nan_attrs = kmemdup(conf->extra_nan_attrs, + conf->extra_nan_attrs_len, + GFP_KERNEL); + if (!extra_nan_attrs) + return -ENOMEM; + } + data->nan.notify_dw = conf->enable_dw_notification; + scoped_guard(spinlock_bh, &data->nan.state_lock) { + /* + * Fall back to the device default if user space did not + * configure it + */ + data->nan.discovery_beacon_interval = + conf->discovery_beacon_interval ? : 100; + + old = data->nan.extra_nan_attrs; + data->nan.extra_nan_attrs = extra_nan_attrs; + data->nan.extra_nan_attrs_len = conf->extra_nan_attrs_len; + } + + kfree(old); + return 0; } @@ -968,6 +1018,7 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { struct mac80211_hwsim_data *data = hw->priv; + const u8 *old; if (vif->type != NL80211_IFTYPE_NAN || !data->nan.device_vif || data->nan.device_vif != vif) @@ -979,6 +1030,14 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw, wiphy_delayed_work_cancel(hw->wiphy, &data->nan.sched_update_work); data->nan.device_vif = NULL; + scoped_guard(spinlock_bh, &data->nan.state_lock) { + old = data->nan.extra_nan_attrs; + data->nan.extra_nan_attrs = NULL; + data->nan.extra_nan_attrs_len = 0; + } + + kfree(old); + return 0; } diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h index 2801a1d8dcf0..e73634e479e8 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h @@ -32,6 +32,9 @@ struct mac80211_hwsim_nan_data { /* Later members are protected by this lock */ spinlock_t state_lock; + const u8 *extra_nan_attrs; + u16 extra_nan_attrs_len; + u8 master_pref; u8 random_factor; @@ -53,6 +56,8 @@ struct mac80211_hwsim_nan_data { bool tsf_adjusted; bool tsf_discontinuity; + u8 discovery_beacon_interval; + /* * Local schedule - stores channel definition for each 16TU slot. * Derived from NMI vif->cfg.nan_schedule. chan == NULL means not From 51741226b2087a261d99ce5af805246f75d14ab8 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 5 Oct 2026 11:44:58 +0300 Subject: [PATCH 1083/2126] wifi: mac80211_hwsim: add NAN Instant Communication support Advertise Instant Communication (IC) support, and when it is enabled: - Transmit the discovery beacons disregarding the role and the state, with the configured beacon interval and the NAN attributes set by user space. - Accept beacons that carry a Service ID List or a Subscribe Service ID List attribute at any time, so that they are forwarded to mac80211. - Process discovery beacons received during non DW slots for anchor master tracking and synchronization. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Reviewed-by: Benjamin Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261005084458.3666739-12-ilan.peer@intel.com Signed-off-by: Johannes Berg --- .../wireless/virtual/mac80211_hwsim_main.c | 7 +- .../net/wireless/virtual/mac80211_hwsim_nan.c | 129 ++++++++++++++++-- .../net/wireless/virtual/mac80211_hwsim_nan.h | 2 + 3 files changed, 122 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 79154332d54e..6cd9542e8b72 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -1775,6 +1775,7 @@ struct tx_iter_data { struct ieee80211_channel *channel; struct ieee80211_rx_status *rx_status; struct ieee80211_hw *hw; + struct sk_buff *skb; bool receive; }; @@ -1787,6 +1788,7 @@ static void mac80211_hwsim_tx_iter(void *_data, u8 *addr, if (vif->type == NL80211_IFTYPE_NAN || vif->type == NL80211_IFTYPE_NAN_DATA) { data->receive = mac80211_hwsim_nan_receive(data->hw, + data->skb, data->channel, data->rx_status); return; @@ -1968,6 +1970,7 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, .hw = data2->hw, .channel = chan, .rx_status = &rx_status, + .skb = skb, }; if (data == data2) @@ -5841,7 +5844,8 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, BIT(NL80211_BAND_5GHZ); hw->wiphy->nan_capa.flags = WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC | - WIPHY_NAN_FLAGS_USERSPACE_DE; + WIPHY_NAN_FLAGS_USERSPACE_DE | + WIPHY_NAN_FLAGS_INSTANT_COMM; hw->wiphy->nan_capa.op_mode = NAN_OP_MODE_PHY_MODE_MASK | NAN_OP_MODE_80P80MHZ | NAN_OP_MODE_160MHZ; @@ -6644,6 +6648,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, struct tx_iter_data iter_data = { .hw = data2->hw, .rx_status = &rx_status, + .skb = skb, }; /* throw away off-channel packets, but allow both the temporary diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c index e7815eb95c55..6f90856099e8 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c @@ -219,6 +219,37 @@ mac80211_hwsim_nan_schedule_slot(struct mac80211_hwsim_data *data, u8 slot, mac80211_hwsim_tsf_to_boottime(data, tsf)); } +static bool hwsim_nan_beacon_has_service_ids(struct sk_buff *skb) +{ + const struct ieee80211_mgmt *mgmt = (void *)skb->data; + const struct ieee80211_nan_attr *nan_attr; + const struct element *elem; + size_t len; + + if (skb->len < offsetofend(struct ieee80211_mgmt, u.beacon) || + !ieee80211_is_beacon(mgmt->frame_control)) + return false; + + len = skb->len - offsetofend(struct ieee80211_mgmt, u.beacon); + + /* TODO: fragmented NAN elements are not supported */ + for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, + mgmt->u.beacon.variable, len) { + if (elem->datalen < 4 || + get_unaligned_be32(elem->data) != + (WLAN_OUI_WFA << 8 | WLAN_OUI_TYPE_WFA_NAN)) + continue; + + for_each_nan_attr(nan_attr, elem->data + 4, elem->datalen - 4) + if (nan_attr->attr == NAN_ATTR_SERVICE_ID_LIST || + nan_attr->attr == + NAN_ATTR_SUBSCRIBE_SERVICE_ID_LIST) + return true; + } + + return false; +} + void mac80211_hwsim_nan_rx(struct ieee80211_hw *hw, struct sk_buff *skb) { @@ -270,15 +301,32 @@ void mac80211_hwsim_nan_rx(struct ieee80211_hw *hw, } /* - * (overly) simplify things, only track 2.4 GHz here. Also, ignore - * frames outside of the 2.4 GHz DW slot, unless in the initial SCAN - * phase. + * Only sync on 2.4 GHz, which all NAN devices attend. The slot number + * is derived from the local TSF, so before being synchronized a 5 GHz + * beacon from a different device may fall into the local 2.4 GHz DW + * slot. Filter by frequency to keep such beacons out of master + * selection and synchronization. */ - if ((slot != SLOT_24GHZ_DW && - data->nan.phase != MAC80211_HWSIM_NAN_PHASE_SCAN) || - rx_status.freq != 2437) + if (rx_status.freq != 2437) return; + /* + * Ignore frames outside of the 2.4 GHz DW slot, unless in the initial + * SCAN phase or in Instant Communication, where discovery beacons are + * received outside the DW. + */ + if (slot != SLOT_24GHZ_DW) { + bool rx_outside_dw; + + scoped_guard(spinlock_bh, &data->nan.state_lock) + rx_outside_dw = data->nan.instant_comm || + data->nan.phase == + MAC80211_HWSIM_NAN_PHASE_SCAN; + + if (!rx_outside_dw) + return; + } + /* Just ignore low RSSI beacons that we cannot sync to */ if (rx_status.signal < NAN_RSSI_MIDDLE) return; @@ -629,10 +677,12 @@ mac80211_hwsim_nan_exec_state_transitions(struct mac80211_hwsim_data *data) /* * The discovery beacon timer will stop automatically. Make sure it is - * running if we are master. Do not bother with a proper alignment it - * will sync itself to the TSF after the first TX. + * running if we are master or if Instant Communication is enabled. Do + * not bother with a proper alignment it will sync itself to the TSF + * after the first TX. */ - if (data->nan.role == MAC80211_HWSIM_NAN_ROLE_MASTER && + if ((data->nan.role == MAC80211_HWSIM_NAN_ROLE_MASTER || + data->nan.instant_comm) && !hrtimer_active(&data->nan.discovery_beacon_timer)) hrtimer_start(&data->nan.discovery_beacon_timer, ns_to_ktime(10 * NSEC_PER_USEC), @@ -887,7 +937,15 @@ mac80211_hwsim_nan_discovery_beacon_timer(struct hrtimer *timer) return HRTIMER_NORESTART; scoped_guard(spinlock, &data->nan.state_lock) { - if (data->nan.phase == MAC80211_HWSIM_NAN_PHASE_SCAN || + if (data->nan.phase == MAC80211_HWSIM_NAN_PHASE_SCAN) + return HRTIMER_NORESTART; + + /* + * With Instant Communication the discovery beacons are + * transmitted disregarding the role and the state, see + * Wi-Fi Aware version 4.0 section 13. + */ + if (!data->nan.instant_comm && data->nan.role != MAC80211_HWSIM_NAN_ROLE_MASTER) return HRTIMER_NORESTART; } @@ -956,6 +1014,8 @@ static int mac80211_hwsim_nan_set_config(struct mac80211_hwsim_data *data, data->nan.discovery_beacon_interval = conf->discovery_beacon_interval ? : 100; + data->nan.instant_comm = conf->instant_comm; + old = data->nan.extra_nan_attrs; data->nan.extra_nan_attrs = extra_nan_attrs; data->nan.extra_nan_attrs_len = conf->extra_nan_attrs_len; @@ -991,9 +1051,13 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, mac80211_hwsim_nan_sched_update_work); scoped_guard(spinlock_bh, &data->nan.state_lock) { - /* Start in the "scan" phase and stay there for a little bit */ + /* + * Start in the "scan" phase and stay there for a little bit, + * unless Instant Communication is configured, in which case an + * own cluster is started immediately. + */ data->nan.phase = MAC80211_HWSIM_NAN_PHASE_SCAN; - data->nan.random_factor_valid_dwst = 1; + data->nan.random_factor_valid_dwst = conf->instant_comm ? 0 : 1; data->nan.random_factor = 0; data->nan.master_pref = conf->master_pref; data->nan.role = MAC80211_HWSIM_NAN_ROLE_MASTER; @@ -1034,6 +1098,7 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw, old = data->nan.extra_nan_attrs; data->nan.extra_nan_attrs = NULL; data->nan.extra_nan_attrs_len = 0; + data->nan.instant_comm = false; } kfree(old); @@ -1061,6 +1126,16 @@ int mac80211_hwsim_nan_change_config(struct ieee80211_hw *hw, if (err) return err; + + /* + * When Instant Communication is enabled discovery beacons are + * transmitted regardless of the role and the state. + */ + if (conf->instant_comm && + !hrtimer_active(&data->nan.discovery_beacon_timer)) + hrtimer_start(&data->nan.discovery_beacon_timer, + ns_to_ktime(10 * NSEC_PER_USEC), + HRTIMER_MODE_REL_SOFT); } /* Handle only the changes we care about for simulation purposes */ @@ -1249,9 +1324,16 @@ bool mac80211_hwsim_nan_txq_transmitting(struct ieee80211_hw *hw, is_dw_slot = mac80211_hwsim_nan_is_dw_slot(data, slot); if (!txq->sta) { - /* Non-STA TXQ: allow management frames during DW */ - if (txq->vif->type == NL80211_IFTYPE_NAN) - return is_dw_slot; + /* Non-STA TXQ: allow management frames during DW or IC */ + if (txq->vif->type == NL80211_IFTYPE_NAN) { + if (is_dw_slot) + return true; + + /* Outside the DW the local schedule must allow it */ + guard(spinlock_bh)(&data->nan.state_lock); + return data->nan.instant_comm && + data->nan.local_sched[slot].chan; + } /* Allow multicast data when all the peers are available * on this slot @@ -1304,15 +1386,32 @@ void mac80211_hwsim_nan_get_tx_chandef(struct ieee80211_hw *hw, } bool mac80211_hwsim_nan_receive(struct ieee80211_hw *hw, + struct sk_buff *skb, struct ieee80211_channel *channel, struct ieee80211_rx_status *rx_status) { struct mac80211_hwsim_data *data = hw->priv; + bool instant_comm; u8 slot; if (WARN_ON_ONCE(!data->nan.device_vif)) return false; + scoped_guard(spinlock_bh, &data->nan.state_lock) + instant_comm = data->nan.instant_comm; + + /* + * During Instant Communication a peer advertises its services in the + * discovery beacons, which are transmitted disregarding the roles and + * the states, see Section 13 in Wi-Fi Aware v4.0. + * Note that while according to the specification Instant communication + * should be enabled only on the NAN discovery channels, do not force + * this here, and allow receiving NAN frames on any channel if Instant + * Communication is enabled. + */ + if (instant_comm && hwsim_nan_beacon_has_service_ids(skb)) + return true; + if (data->nan.phase == MAC80211_HWSIM_NAN_PHASE_SCAN) return channel->center_freq == 2437; diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h index e73634e479e8..0684f9b823ba 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h @@ -56,6 +56,7 @@ struct mac80211_hwsim_nan_data { bool tsf_adjusted; bool tsf_discontinuity; + bool instant_comm; u8 discovery_beacon_interval; /* @@ -98,6 +99,7 @@ void mac80211_hwsim_nan_get_tx_chandef(struct ieee80211_hw *hw, struct cfg80211_chan_def *chandef); bool mac80211_hwsim_nan_receive(struct ieee80211_hw *hw, + struct sk_buff *skb, struct ieee80211_channel *channel, struct ieee80211_rx_status *rx_status); From df40d3645443e884897b5b95873f9871bb44b7e5 Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Mon, 31 Aug 2026 17:43:08 +0800 Subject: [PATCH 1084/2126] wifi: nxpwifi: fix missing error codes in _nxpwifi_fw_dpc() When nxpwifi_register_cfg80211(), nxpwifi_init_channel_scan_gap(), or nxpwifi_add_virtual_intf() fail, the function jumped to an error label but left ret == 0, causing _nxpwifi_fw_dpc() to return success despite the failure. Fix by propagating the return value of nxpwifi_register_cfg80211() and nxpwifi_init_channel_scan_gap() directly into ret, and by extracting the encoded error from the ERR_PTR wdev with PTR_ERR() before each goto err_add_intf. The P2P client interface path had the same IS_ERR/goto pattern and is fixed in the same way. Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-wireless/anwshVbQWXXHTJpa@stanley.mountain/ Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/main.c b/drivers/net/wireless/nxp/nxpwifi/main.c index 55b962430f37..b57c373546ca 100644 --- a/drivers/net/wireless/nxp/nxpwifi/main.c +++ b/drivers/net/wireless/nxp/nxpwifi/main.c @@ -603,14 +603,18 @@ static int _nxpwifi_fw_dpc(const struct firmware *firmware, void *context) maybe_quirk_fw_disable_ds(adapter); if (!adapter->wiphy) { - if (nxpwifi_register_cfg80211(adapter)) { + ret = nxpwifi_register_cfg80211(adapter); + + if (ret) { nxpwifi_dbg(adapter, ERROR, "cannot register with cfg80211\n"); goto err_init_fw; } } - if (nxpwifi_init_channel_scan_gap(adapter)) { + ret = nxpwifi_init_channel_scan_gap(adapter); + + if (ret) { nxpwifi_dbg(adapter, ERROR, "could not init channel stats table\n"); goto err_init_chan_scan; @@ -623,6 +627,7 @@ static int _nxpwifi_fw_dpc(const struct firmware *firmware, void *context) if (IS_ERR(wdev)) { nxpwifi_dbg(adapter, ERROR, "cannot create default STA interface\n"); + ret = PTR_ERR(wdev); rtnl_unlock(); goto err_add_intf; } @@ -632,6 +637,7 @@ static int _nxpwifi_fw_dpc(const struct firmware *firmware, void *context) if (IS_ERR(wdev)) { nxpwifi_dbg(adapter, ERROR, "cannot create AP interface\n"); + ret = PTR_ERR(wdev); rtnl_unlock(); goto err_add_intf; } From 52c9568fa2eda80d02842961e7ba01e07eb01883 Mon Sep 17 00:00:00 2001 From: Aamir Ahmed Date: Sat, 12 Sep 2026 17:20:31 +0100 Subject: [PATCH 1085/2126] wifi: nxpwifi: validate variable IE lengths in beacon parser nxpwifi_update_bss_desc_with_ie() stores pointers to the HT, VHT and HE capability and operation elements, to the operating mode notification and to the 20/40 BSS coexistence element, taken from a beacon or probe response, without checking that each element is long enough for the structure the driver later dereferences it as. bss_desc->beacon_buf is a tight kmemdup() of the on-air elements, so a truncated element leaves the stored pointer short of the structure and the consumers read past the end of that allocation at association time. Some of those bytes are copied into the association request, so a rogue access point in range can both trigger the read and receive the result. Reject the frame with -EINVAL when any of these elements is shorter than the structure read from it, as the FH, DS and CF parameter set cases in the same parser already do. The extended capabilities element has no structure size to check against, so nxpwifi_is_ap_11ax_twt_supported()'s read of bcn_ext_cap->data[9] is bounded at that consumer instead. Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x") Assisted-by: LLM Signed-off-by: Aamir Ahmed Reviewed-by: Jeff Chen Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/11ax.c | 2 ++ drivers/net/wireless/nxp/nxpwifi/scan.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/net/wireless/nxp/nxpwifi/11ax.c b/drivers/net/wireless/nxp/nxpwifi/11ax.c index 96540914f3cf..dc1e747383ec 100644 --- a/drivers/net/wireless/nxp/nxpwifi/11ax.c +++ b/drivers/net/wireless/nxp/nxpwifi/11ax.c @@ -402,6 +402,8 @@ static u8 nxpwifi_is_ap_11ax_twt_supported(struct nxpwifi_bssdescriptor *bss_des return false; ext_cap = (struct element *)bss_desc->bcn_ext_cap; + if (ext_cap->datalen < 10) + return false; if (!(ext_cap->data[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) return false; return true; diff --git a/drivers/net/wireless/nxp/nxpwifi/scan.c b/drivers/net/wireless/nxp/nxpwifi/scan.c index 67d7ff2f10c5..f3becafb9c23 100644 --- a/drivers/net/wireless/nxp/nxpwifi/scan.c +++ b/drivers/net/wireless/nxp/nxpwifi/scan.c @@ -1209,6 +1209,8 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, (u16)(current_ptr - bss_entry->beacon_buf); break; case WLAN_EID_HT_CAPABILITY: + if (element_len < sizeof(*bss_entry->bcn_ht_cap)) + return -EINVAL; bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)(current_ptr + elem_size); @@ -1217,6 +1219,8 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, bss_entry->beacon_buf); break; case WLAN_EID_HT_OPERATION: + if (element_len < sizeof(*bss_entry->bcn_ht_oper)) + return -EINVAL; bss_entry->bcn_ht_oper = (struct ieee80211_ht_operation *)(current_ptr + elem_size); @@ -1225,6 +1229,8 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, bss_entry->beacon_buf); break; case WLAN_EID_VHT_CAPABILITY: + if (element_len < sizeof(*bss_entry->bcn_vht_cap)) + return -EINVAL; bss_entry->disable_11ac = false; bss_entry->bcn_vht_cap = (void *)(current_ptr + elem_size); @@ -1233,6 +1239,8 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, bss_entry->beacon_buf); break; case WLAN_EID_VHT_OPERATION: + if (element_len < sizeof(*bss_entry->bcn_vht_oper)) + return -EINVAL; bss_entry->bcn_vht_oper = (void *)(current_ptr + elem_size); bss_entry->vht_info_offset = @@ -1240,6 +1248,8 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, bss_entry->beacon_buf); break; case WLAN_EID_BSS_COEX_2040: + if (!element_len) + return -EINVAL; bss_entry->bcn_bss_co_2040 = current_ptr; bss_entry->bss_co_2040_offset = (u16)(current_ptr - bss_entry->beacon_buf); @@ -1250,6 +1260,8 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, (u16)(current_ptr - bss_entry->beacon_buf); break; case WLAN_EID_OPMODE_NOTIF: + if (total_ie_len < sizeof(*bss_entry->oper_mode)) + return -EINVAL; bss_entry->oper_mode = (void *)current_ptr; bss_entry->oper_mode_offset = (u16)(current_ptr - bss_entry->beacon_buf); @@ -1262,6 +1274,9 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, switch (elem->data[0]) { case WLAN_EID_EXT_HE_CAPABILITY: + if (element_len < + 1 + sizeof(*bss_entry->bcn_he_cap)) + return -EINVAL; bss_entry->disable_11ax = false; bss_entry->bcn_he_cap = (void *)(current_ptr + elem_size + 1); @@ -1270,6 +1285,9 @@ int nxpwifi_update_bss_desc_with_ie(struct nxpwifi_adapter *adapter, bss_entry->beacon_buf); break; case WLAN_EID_EXT_HE_OPERATION: + if (element_len < + 1 + sizeof(*bss_entry->bcn_he_oper)) + return -EINVAL; bss_entry->bcn_he_oper = (void *)(current_ptr + elem_size + 1); bss_entry->he_info_offset = From 5033daff1534a586536ee6e7f70f6886122464c5 Mon Sep 17 00:00:00 2001 From: Heyang Tan Date: Sat, 19 Sep 2026 12:02:52 +0800 Subject: [PATCH 1086/2126] wifi: nxpwifi: bound histogram debugfs output nxpwifi_histogram_read() writes histogram entries to a PAGE_SIZE buffer. Each entry is formatted with sprintf(), so enough populated buckets can write past the allocation. Use scnprintf() with the remaining buffer space when formatting the histogram. Assisted-by: LLM Signed-off-by: Heyang Tan Reviewed-by: Jeff Chen Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/debugfs.c | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/debugfs.c b/drivers/net/wireless/nxp/nxpwifi/debugfs.c index ccaf0eae37e3..fd738a8110f9 100644 --- a/drivers/net/wireless/nxp/nxpwifi/debugfs.c +++ b/drivers/net/wireless/nxp/nxpwifi/debugfs.c @@ -211,25 +211,26 @@ nxpwifi_histogram_read(struct file *file, char __user *ubuf, phist_data = priv->hist_data; - p += sprintf(p, "\n" + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), "\n" "total samples = %d\n", atomic_read(&phist_data->num_samples)); - p += sprintf(p, + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), "rx rates (in Mbps): 0=1M 1=2M 2=5.5M 3=11M 4=6M 5=9M 6=12M\n" "7=18M 8=24M 9=36M 10=48M 11=54M 12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n"); if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) { - p += sprintf(p, + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), "44-53=MCS0-9(VHT:BW20) 54-63=MCS0-9(VHT:BW40) 64-73=MCS0-9(VHT:BW80)\n\n"); } else { - p += sprintf(p, "\n"); + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), "\n"); } for (i = 0; i < NXPWIFI_MAX_RX_RATES; i++) { value = atomic_read(&phist_data->rx_rate[i]); if (value) - p += sprintf(p, "rx_rate[%02d] = %d\n", i, value); + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), + "rx_rate[%02d] = %d\n", i, value); } if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) { @@ -237,27 +238,31 @@ nxpwifi_histogram_read(struct file *file, char __user *ubuf, i++) { value = atomic_read(&phist_data->rx_rate[i]); if (value) - p += sprintf(p, "rx_rate[%02d] = %d\n", - i, value); + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), + "rx_rate[%02d] = %d\n", + i, value); } } for (i = 0; i < NXPWIFI_MAX_SNR; i++) { value = atomic_read(&phist_data->snr[i]); if (value) - p += sprintf(p, "snr[%02ddB] = %d\n", i, value); + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), + "snr[%02ddB] = %d\n", i, value); } for (i = 0; i < NXPWIFI_MAX_NOISE_FLR; i++) { value = atomic_read(&phist_data->noise_flr[i]); if (value) - p += sprintf(p, "noise_flr[%02ddBm] = %d\n", - (int)(i - 128), value); + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), + "noise_flr[%02ddBm] = %d\n", + (int)(i - 128), value); } for (i = 0; i < NXPWIFI_MAX_SIG_STRENGTH; i++) { value = atomic_read(&phist_data->sig_str[i]); if (value) - p += sprintf(p, "sig_strength[-%02ddBm] = %d\n", - i, value); + p += scnprintf(p, PAGE_SIZE - (p - (char *)page), + "sig_strength[-%02ddBm] = %d\n", + i, value); } ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page, From 93a443bb4e91183101f2a5faf826c41293aedcce Mon Sep 17 00:00:00 2001 From: Heyang Tan Date: Sat, 19 Sep 2026 12:44:39 +0800 Subject: [PATCH 1087/2126] wifi: nxpwifi: bound debug info output nxpwifi_debug_read() provides a PAGE_SIZE buffer to nxpwifi_debug_info_to_buffer(), which formats debug state with unbounded sprintf() calls. The same helper is also used for the firmware dump. Pass the output size to the helper and use scnprintf() while formatting. Clamp the debug table counts and window size to the backing array lengths before accessing them. Assisted-by: LLM Signed-off-by: Heyang Tan Reviewed-by: Jeff Chen Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/debugfs.c | 2 +- drivers/net/wireless/nxp/nxpwifi/main.c | 5 ++- drivers/net/wireless/nxp/nxpwifi/util.c | 43 +++++++++++++--------- drivers/net/wireless/nxp/nxpwifi/util.h | 1 + 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/debugfs.c b/drivers/net/wireless/nxp/nxpwifi/debugfs.c index fd738a8110f9..cd6e73a215f0 100644 --- a/drivers/net/wireless/nxp/nxpwifi/debugfs.c +++ b/drivers/net/wireless/nxp/nxpwifi/debugfs.c @@ -304,7 +304,7 @@ nxpwifi_debug_read(struct file *file, char __user *ubuf, if (ret) goto free_and_exit; - p += nxpwifi_debug_info_to_buffer(priv, p, &info); + p += nxpwifi_debug_info_to_buffer(priv, p, PAGE_SIZE, &info); ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page, (unsigned long)p - page); diff --git a/drivers/net/wireless/nxp/nxpwifi/main.c b/drivers/net/wireless/nxp/nxpwifi/main.c index b57c373546ca..03efafecfcf2 100644 --- a/drivers/net/wireless/nxp/nxpwifi/main.c +++ b/drivers/net/wireless/nxp/nxpwifi/main.c @@ -1119,7 +1119,10 @@ void nxpwifi_drv_info_dump(struct nxpwifi_adapter *adapter) continue; priv = adapter->priv[i]; nxpwifi_get_debug_info(priv, debug_info); - p += nxpwifi_debug_info_to_buffer(priv, p, debug_info); + p += nxpwifi_debug_info_to_buffer(priv, p, + NXPWIFI_FW_DUMP_SIZE - + (p - (char *)adapter->devdump_data), + debug_info); break; } kfree(debug_info); diff --git a/drivers/net/wireless/nxp/nxpwifi/util.c b/drivers/net/wireless/nxp/nxpwifi/util.c index bbfefb81d8d3..27a91e2054fc 100644 --- a/drivers/net/wireless/nxp/nxpwifi/util.c +++ b/drivers/net/wireless/nxp/nxpwifi/util.c @@ -220,19 +220,24 @@ int nxpwifi_get_debug_info(struct nxpwifi_private *priv, } int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf, + size_t buf_size, struct nxpwifi_debug_info *info) { - char *p = buf; + size_t used = 0; struct nxpwifi_debug_data *d = &items[0]; size_t size, addr; long val; + u32 tx_tbl_num, rx_tbl_num, win_size; int i, j; if (!info) return 0; + tx_tbl_num = min_t(u32, info->tx_tbl_num, ARRAY_SIZE(info->tx_tbl)); + rx_tbl_num = min_t(u32, info->rx_tbl_num, ARRAY_SIZE(info->rx_tbl)); + for (i = 0; i < num_of_items; i++) { - p += sprintf(p, "%s=", d[i].name); + used += scnprintf(buf + used, buf_size - used, "%s=", d[i].name); size = d[i].size / d[i].num; @@ -260,41 +265,43 @@ int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf, break; } - p += sprintf(p, "%#lx ", val); + used += scnprintf(buf + used, buf_size - used, "%#lx ", val); addr += size; } - p += sprintf(p, "\n"); + used += scnprintf(buf + used, buf_size - used, "\n"); } - if (info->tx_tbl_num) { - p += sprintf(p, "Tx BA stream table:\n"); - for (i = 0; i < info->tx_tbl_num; i++) - p += sprintf(p, "tid = %d, ra = %pM\n", + if (tx_tbl_num) { + used += scnprintf(buf + used, buf_size - used, "Tx BA stream table:\n"); + for (i = 0; i < tx_tbl_num; i++) + used += scnprintf(buf + used, buf_size - used, "tid = %d, ra = %pM\n", info->tx_tbl[i].tid, info->tx_tbl[i].ra); } - if (info->rx_tbl_num) { - p += sprintf(p, "Rx reorder table:\n"); - for (i = 0; i < info->rx_tbl_num; i++) { - p += sprintf(p, "tid = %d, ta = %pM, ", + if (rx_tbl_num) { + used += scnprintf(buf + used, buf_size - used, "Rx reorder table:\n"); + for (i = 0; i < rx_tbl_num; i++) { + used += scnprintf(buf + used, buf_size - used, "tid = %d, ta = %pM, ", info->rx_tbl[i].tid, info->rx_tbl[i].ta); - p += sprintf(p, "start_win = %d, ", + used += scnprintf(buf + used, buf_size - used, "start_win = %d, ", info->rx_tbl[i].start_win); - p += sprintf(p, "win_size = %d, buffer: ", + used += scnprintf(buf + used, buf_size - used, "win_size = %d, buffer: ", info->rx_tbl[i].win_size); - for (j = 0; j < info->rx_tbl[i].win_size; j++) - p += sprintf(p, "%c ", + win_size = min_t(u32, info->rx_tbl[i].win_size, + ARRAY_SIZE(info->rx_tbl[i].buffer)); + for (j = 0; j < win_size; j++) + used += scnprintf(buf + used, buf_size - used, "%c ", info->rx_tbl[i].buffer[j] ? '1' : '0'); - p += sprintf(p, "\n"); + used += scnprintf(buf + used, buf_size - used, "\n"); } } - return p - buf; + return used; } bool nxpwifi_is_channel_setting_allowable(struct nxpwifi_private *priv, diff --git a/drivers/net/wireless/nxp/nxpwifi/util.h b/drivers/net/wireless/nxp/nxpwifi/util.h index 1a47c8c5b530..a0ec722e6da5 100644 --- a/drivers/net/wireless/nxp/nxpwifi/util.h +++ b/drivers/net/wireless/nxp/nxpwifi/util.h @@ -82,6 +82,7 @@ static inline dma_addr_t NXPWIFI_SKB_DMA_ADDR(struct sk_buff *skb) } int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf, + size_t buf_size, struct nxpwifi_debug_info *info); static inline void le16_unaligned_add_cpu(__le16 *var, u16 val) From e56c9d429ba004d5416b03091fd7656187cdcaf1 Mon Sep 17 00:00:00 2001 From: Baochen Qiang Date: Mon, 28 Sep 2026 18:45:25 +0800 Subject: [PATCH 1088/2126] wifi: ath11k: fix unbalanced IRQ enable/disable during suspend/resume Commit f7a74e131d3f ("wifi: ath11k: disable interrupts during firmware crash recovery") added an unconditional ath11k_hif_irq_disable()/ ath11k_hif_ce_irq_disable() pair inside ath11k_core_reconfigure_on_crash(), guarded by "if (!ab->is_reset)", to stop the DP NAPI from touching rings that have just been torn down. That fixes AHB device recovery, but breaks PCI device suspend/resume. During suspend, IRQs are disabled once in ath11k_core_suspend_late(). Then during resume, ath11k_core_reconfigure_on_crash() sees ab->is_reset clear and disables them a second time. Those IRQs are enabled only once during the following reinitialization, leaving the IRQ lines masked. As a result, HTC control responses never arrive, and resume fails: failed to receive control response completion, polling.. failed to connect to HTT: -110 failed to reconfigure driver on crash recovery failed to resume core: -110 Fix this by disabling the IRQs unconditionally at the top of ath11k_core_reconfigure_on_crash(), and instead drop the disable calls from the two places that already disable IRQs before this function can run: ath11k_core_suspend_late() and ath11k_core_reset(). This keeps a single disable per recovery/suspend cycle regardless of which path (recovery or suspend) triggers it, so the refcount on PCI parts stays balanced while AHB parts keep getting the disable that the original commit needed. Fixes: f7a74e131d3f ("wifi: ath11k: disable interrupts during firmware crash recovery") Reported-by: Marek Szyprowski Closes: https://lore.kernel.org/linux-wireless/a068a857-a549-4cc2-ae0f-3ef119d3a859@samsung.com/ Tested-by: Marek Szyprowski Tested-by: Julius Bairaktaris Signed-off-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260928-ath11k-unbalanced-irq-enable-disable-v1-1-75166f534763@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/core.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index d2ed6a0ea7e3..1ad0a47653de 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -1275,9 +1275,6 @@ int ath11k_core_suspend_late(struct ath11k_base *ab) if (ab->actual_pm_policy == ATH11K_PM_WOW) return 0; - ath11k_hif_irq_disable(ab); - ath11k_hif_ce_irq_disable(ab); - ath11k_hif_power_down(ab, true); return 0; @@ -2333,17 +2330,9 @@ static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab) int ret; mutex_lock(&ab->core_lock); + ath11k_hif_irq_disable(ab); + ath11k_hif_ce_irq_disable(ab); ath11k_thermal_unregister(ab); - - /* - * ath11k_core_reset() already disabled the interrupts on the reset - * path; only the firmware crash path reaches here with them live. - */ - if (!ab->is_reset) { - ath11k_hif_irq_disable(ab); - ath11k_hif_ce_irq_disable(ab); - } - ath11k_dp_pdev_free(ab); ath11k_cfr_deinit(ab); ath11k_spectral_deinit(ab); @@ -2605,9 +2594,6 @@ static void ath11k_core_reset(struct work_struct *work) time_left = wait_for_completion_timeout(&ab->recovery_start, ATH11K_RECOVER_START_TIMEOUT_HZ); - ath11k_hif_irq_disable(ab); - ath11k_hif_ce_irq_disable(ab); - ath11k_hif_power_down(ab, false); ath11k_hif_power_up(ab); From 13b15eabe2c541b80406166964cdc8ccb5e9c32a Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:59:13 +0800 Subject: [PATCH 1089/2126] wifi: ath12k: Reserve space for a string terminator ath12k_write_htt_stats_type() accepts count == size, which fills the zero-initialized buffer without a terminating NUL. sscanf() then reads beyond the buffer. Reject input that leaves no room for the trailing NUL. Fixes: 8c7a5031a6b0 ("wifi: ath12k: Fix buffer overflow in debugfs") Reviewed-by: Dan Carpenter Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Signed-off-by: Jiale Yao Link: https://patch.msgid.link/20261003095913.575108-1-yaojiale02@163.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c b/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c index b772181a496e..f84f1828275a 100644 --- a/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c +++ b/drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c @@ -6190,7 +6190,7 @@ static ssize_t ath12k_write_htt_stats_type(struct file *file, const int size = 32; int num_args; - if (count > size) + if (count >= size) return -EINVAL; char *buf __free(kfree) = kzalloc(size, GFP_KERNEL); From 81394dfb9a7905472957628b560ae894eae3a30f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 11 Sep 2026 14:31:44 -0700 Subject: [PATCH 1090/2126] wifi: ath9k: delete channel-context timers on deinit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ath9k_deinit_channel_context() cancels chanctx_work but does not delete the offchannel and sched timers set up by ath9k_init_channel_context(). If either timer fires after deinit (e.g. during driver unload or suspend), it accesses sc->sc_ah which may already be freed by ath9k_hw_deinit(), causing a use-after-free. Delete both timers with timer_shutdown_sync() before cancelling the work item. Assisted-by: LLM Signed-off-by: Rosen Penev Acked-by: Toke Høiland-Jørgensen Cc: stable@vger.kernel.org # v6.2+ Fixes: 705d0bf83dbe ("ath9k: Add a routine for initializing channel contexts") Link: https://patch.msgid.link/20260911213144.130192-1-rosenp@gmail.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath9k/channel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/channel.c b/drivers/net/wireless/ath/ath9k/channel.c index 8b27d8cc086a..cfb1c90eb4b6 100644 --- a/drivers/net/wireless/ath/ath9k/channel.c +++ b/drivers/net/wireless/ath/ath9k/channel.c @@ -1363,6 +1363,8 @@ void ath9k_init_channel_context(struct ath_softc *sc) void ath9k_deinit_channel_context(struct ath_softc *sc) { + timer_shutdown_sync(&sc->sched.timer); + timer_shutdown_sync(&sc->offchannel.timer); cancel_work_sync(&sc->chanctx_work); } From 59411703660919197234fa0ec80ee1a5bcbe4276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nerijus=20Bend=C5=BEi=C5=ABnas?= Date: Tue, 8 Sep 2026 21:03:08 +0300 Subject: [PATCH 1091/2126] wifi: ath9k: refuse spectral scan control while the hardware is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spectral_scan_ctl debugfs file drives PHY register writes, and nothing checks whether the hardware is up. While the interface is down the chip is asleep, and on the AR9271 those writes go over WMI to a sleeping target and hang the firmware until the device is re-enumerated. Refuse the write with -EBUSY while ATH_OP_INVALID is set. The reset control already refuses on the same flag. Assisted-by: LLM Signed-off-by: Nerijus Bendžiūnas Acked-by: Toke Høiland-Jørgensen Link: https://patch.msgid.link/20260908180308.788642-1-nerijus.bendziunas@gmail.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath9k/common-spectral.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/common-spectral.c b/drivers/net/wireless/ath/ath9k/common-spectral.c index ca01a07f6630..beedabee7d47 100644 --- a/drivers/net/wireless/ath/ath9k/common-spectral.c +++ b/drivers/net/wireless/ath/ath9k/common-spectral.c @@ -805,6 +805,15 @@ static ssize_t write_file_spec_scan_ctl(struct file *file, buf[len] = '\0'; + /* + * Every command below drives PHY register writes. Refuse them while + * the hardware is disabled (the interface is down): on the AR9271 + * that traffic hangs the firmware until the device is re-enumerated. + * The reset control refuses on the same flag. + */ + if (test_bit(ATH_OP_INVALID, &common->op_flags)) + return -EBUSY; + if (strncmp("trigger", buf, 7) == 0) { ath9k_cmn_spectral_scan_trigger(common, spec_priv); } else if (strncmp("background", buf, 10) == 0) { From 129324b60343dec19d45dcf87736f129b18b95bb Mon Sep 17 00:00:00 2001 From: Albert Esteve Date: Mon, 14 Sep 2026 15:05:19 +0200 Subject: [PATCH 1092/2126] wifi: ath10k: clear QMI if failed during init A failed ath10k_qmi_init() leaves a dangling pointer (ar_snoc->qmi) in the cleanup path. Clear the pointer on the way out for hygiene and consistency with deinit(). Signed-off-by: Albert Esteve Reviewed-by: Brian Norris Link: https://patch.msgid.link/20260914-fix-ath10k-dangling-v1-1-15c5089682b1@redhat.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath10k/qmi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/ath/ath10k/qmi.c b/drivers/net/wireless/ath/ath10k/qmi.c index 0d74548a5f34..08a64f737fb4 100644 --- a/drivers/net/wireless/ath/ath10k/qmi.c +++ b/drivers/net/wireless/ath/ath10k/qmi.c @@ -1128,6 +1128,7 @@ err_release_qmi_handle: err: kfree(qmi); + ar_snoc->qmi = NULL; return ret; } From fe7ca0c13f7d477d6f461114815c57fde3f930ca Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 30 Sep 2026 14:40:17 +0000 Subject: [PATCH 1093/2126] ipv4: fix IP ID reuse in ip_select_ident_segs() ip_select_ident_segs() must put the first of the @segs reserved IP IDs in iph->id, as GSO assigns id, id + 1, ..., id + segs - 1 to segments. Commit f866fbc842de ("ipv4: fix data-races around inet->inet_id") used atomic_add_return() for non-TCP sockets, which returns the first ID of the next packet instead. Consecutive GSO packets can then reuse IP IDs. SCTP GSO is affected. Other callers use segs == 1, and only see a harmless off-by-one (UDP GSO has a separate, older issue). Use atomic_fetch_add() instead, like the TCP path. Fixes: f866fbc842de ("ipv4: fix data-races around inet->inet_id") Signed-off-by: Eric Dumazet Reviewed-by: Jiayuan Chen Reviewed-by: David Ahern Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260930144018.1174068-2-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- include/net/ip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/ip.h b/include/net/ip.h index 6f602df72ee6..6a3e8271a73b 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -598,7 +598,7 @@ static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb, val = atomic_read(&inet_sk(sk)->inet_id); atomic_set(&inet_sk(sk)->inet_id, val + segs); } else { - val = atomic_add_return(segs, &inet_sk(sk)->inet_id); + val = atomic_fetch_add(segs, &inet_sk(sk)->inet_id); } iph->id = htons(val); return; From 852c08d6a99149dc71c51cea125b5083f555237e Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 30 Sep 2026 14:40:18 +0000 Subject: [PATCH 1094/2126] ipv4: reserve one IP ID per segment for UDP GSO packets __ip_make_skb() reserves a single IP ID for UDP GSO packets, but GSO assigns one IP ID per segment. Following packets then reuse these IDs, either from inet->inet_id or from the shared generator. Unless IP_PMTUDISC_DO/PROBE is used, DF is not set on UDP GSO packets, so segments can be fragmented on the path and IP ID reuse can lead to incorrect reassembly. Reserve one IP ID per segment, using the same test as udp_send_skb(). Fixes: bec1f6f69736 ("udp: generate gso with UDP_SEGMENT") Signed-off-by: Eric Dumazet Reviewed-by: Jiayuan Chen Cc: Willem de Bruijn Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260930144018.1174068-3-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ipv4/ip_output.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index a24cc8ee11d3..47a78f297a7f 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1410,6 +1410,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk, struct iphdr *iph; u8 pmtudisc, ttl; __be16 df = 0; + int segs; skb = __skb_dequeue(queue); if (!skb) @@ -1464,7 +1465,19 @@ struct sk_buff *__ip_make_skb(struct sock *sk, iph->ttl = ttl; iph->protocol = sk->sk_protocol; ip_copy_addrs(iph, fl4); - ip_select_ident(net, skb, sk); + + /* UDP GSO packets are segmented later (see udp_send_skb()): + * reserve one IP ID per segment. + */ + segs = 1; + if (cork->gso_size && sk_is_udp(sk)) { + int datalen = skb->len - skb_transport_offset(skb) - + sizeof(struct udphdr); + + if (datalen > cork->gso_size) + segs = DIV_ROUND_UP(datalen, cork->gso_size); + } + ip_select_ident_segs(net, skb, sk, segs); if (opt) { iph->ihl += opt->optlen >> 2; From 05e40209cf75cd516b17b6f8e137f3f4ba2d176d Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Wed, 30 Sep 2026 15:18:49 -0500 Subject: [PATCH 1095/2126] dt-bindings: net: Convert hisilicon,hns-nic to DT schema Convert the hisilicon,hns-nic binding to DT schema format. It's a straight forward conversion. Signed-off-by: Rob Herring (Arm) Link: https://patch.msgid.link/20260930201851.71082-1-robh@kernel.org Signed-off-by: Jakub Kicinski --- .../bindings/net/hisilicon,hns-nic.yaml | 108 ++++++++++++++++++ .../bindings/net/hisilicon-hns-nic.txt | 76 ------------ 2 files changed, 108 insertions(+), 76 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/hisilicon,hns-nic.yaml delete mode 100644 Documentation/devicetree/bindings/net/hisilicon-hns-nic.txt diff --git a/Documentation/devicetree/bindings/net/hisilicon,hns-nic.yaml b/Documentation/devicetree/bindings/net/hisilicon,hns-nic.yaml new file mode 100644 index 000000000000..799b3ef1e1eb --- /dev/null +++ b/Documentation/devicetree/bindings/net/hisilicon,hns-nic.yaml @@ -0,0 +1,108 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/hisilicon,hns-nic.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hisilicon Network Subsystem NIC controller + +maintainers: + - Jian Shen + - Jijie Shao + +allOf: + - $ref: ethernet-controller.yaml# + +properties: + compatible: + enum: + - hisilicon,hns-nic-v1 + - hisilicon,hns-nic-v2 + + ae-handle: + description: + accelerator engine handle for hns, specifies a reference to the + associating hardware driver node. + $ref: /schemas/types.yaml#/definitions/phandle + + port-id: + description: | + is the index of port provided by DSAF (the accelerator). DSAF can connect to 8 PHYs. + Port 0 to 1 are both used for administration purpose. + They are called debug ports. + + The remaining 6 PHYs are taken according to the mode of DSAF. + + In NIC mode of DSAF, all 6 PHYs are taken as ethernet ports to the CPU. + The port-id can be 2 to 7. Here is the diagram: + +-----+---------------+ + | CPU | + +-+-+-+---+-+-+-+-+-+-+ + | | | | | | | | + debug service + port port + (0,1) (2-7) + + In Switch mode of DSAF, all 6 PHYs are taken as physical ports connect to a LAN Switch, + while the CPU side assume itself have one single NIC connect to this switch. + In this case, the port-id will be 2 only. + +-----+---------------+ + | CPU | + +-+-+-+---+-+-+-+-+-+-+ + | | service| port(2) + debug +------------+ + port | switch | + (0,1) +-+-+-+-+-+-++ + | | | | | | + external port + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 7 + deprecated: true + + port-idx-in-ae: + description: | + is the index of port provided by AE. + In NIC mode of DSAF, all 6 PHYs of service DSAF are taken as ethernet ports to the CPU. + The port-idx-in-ae can be 0 to 5. Here is the diagram: + +-----+---------------+ + | CPU | + +-+-+-+---+-+-+-+-+-+-+ + | | | | | | | | + debug debug service + port port port + (0) (0) (0-5) + + In Switch mode of DSAF, all 6 PHYs of service DSAF are taken as physical ports connected to + a LAN Switch, + while the CPU side assume itself have one single NIC connected to this switch. + In this case, the port-idx-in-ae will be 0 only. + +-----+-----+------+------+ + | CPU | + +-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | service| port(0) + debug debug +------------+ + port port | switch | + (0) (0) +-+-+-+-+-+-++ + | | | | | | + external port + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 5 + + dma-coherent: true + +required: + - compatible + - ae-handle + - port-idx-in-ae + - local-mac-address + +unevaluatedProperties: false + +examples: + - | + ethernet { + compatible = "hisilicon,hns-nic-v1"; + ae-handle = <&dsaf0>; + port-idx-in-ae = <0>; + local-mac-address = [a2 14 e4 4b 56 76]; + }; diff --git a/Documentation/devicetree/bindings/net/hisilicon-hns-nic.txt b/Documentation/devicetree/bindings/net/hisilicon-hns-nic.txt deleted file mode 100644 index f0421ee3c714..000000000000 --- a/Documentation/devicetree/bindings/net/hisilicon-hns-nic.txt +++ /dev/null @@ -1,76 +0,0 @@ -Hisilicon Network Subsystem NIC controller - -Required properties: -- compatible: "hisilicon,hns-nic-v1" or "hisilicon,hns-nic-v2". - "hisilicon,hns-nic-v1" is for hip05. - "hisilicon,hns-nic-v2" is for Hi1610 and Hi1612. -- ae-handle: accelerator engine handle for hns, - specifies a reference to the associating hardware driver node. - see Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt -- port-id: is the index of port provided by DSAF (the accelerator). DSAF can - connect to 8 PHYs. Port 0 to 1 are both used for administration purpose. They - are called debug ports. - - The remaining 6 PHYs are taken according to the mode of DSAF. - - In NIC mode of DSAF, all 6 PHYs are taken as ethernet ports to the CPU. The - port-id can be 2 to 7. Here is the diagram: - +-----+---------------+ - | CPU | - +-+-+-+---+-+-+-+-+-+-+ - | | | | | | | | - debug service - port port - (0,1) (2-7) - - In Switch mode of DSAF, all 6 PHYs are taken as physical ports connect to a - LAN Switch while the CPU side assume itself have one single NIC connect to - this switch. In this case, the port-id will be 2 only. - +-----+---------------+ - | CPU | - +-+-+-+---+-+-+-+-+-+-+ - | | service| port(2) - debug +------------+ - port | switch | - (0,1) +-+-+-+-+-+-++ - | | | | | | - external port - - This attribute is remained for compatible purpose. It is not recommended to - use it in new code. - -- port-idx-in-ae: is the index of port provided by AE. - In NIC mode of DSAF, all 6 PHYs of service DSAF are taken as ethernet ports - to the CPU. The port-idx-in-ae can be 0 to 5. Here is the diagram: - +-----+---------------+ - | CPU | - +-+-+-+---+-+-+-+-+-+-+ - | | | | | | | | - debug debug service - port port port - (0) (0) (0-5) - - In Switch mode of DSAF, all 6 PHYs of service DSAF are taken as physical - ports connected to a LAN Switch while the CPU side assume itself have one - single NIC connected to this switch. In this case, the port-idx-in-ae - will be 0 only. - +-----+-----+------+------+ - | CPU | - +-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | service| port(0) - debug debug +------------+ - port port | switch | - (0) (0) +-+-+-+-+-+-++ - | | | | | | - external port - -- local-mac-address: mac addr of the ethernet interface - -Example: - - ethernet@0{ - compatible = "hisilicon,hns-nic-v1"; - ae-handle = <&dsaf0>; - port-idx-in-ae = <0>; - local-mac-address = [a2 14 e4 4b 56 76]; - }; From c0402d7640a84a557849f8e42ebc86c8491a87da Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Wed, 30 Sep 2026 15:19:04 -0500 Subject: [PATCH 1096/2126] dt-bindings: net: Convert hisilicon,hns-mdio to DT schema Convert the hisilicon,hns-mdio binding to DT schema format. Add the missing 'subctrl-vbase' property which is already in use. Signed-off-by: Rob Herring (Arm) Link: https://patch.msgid.link/20260930201906.74125-1-robh@kernel.org Signed-off-by: Jakub Kicinski --- .../bindings/net/hisilicon,hns-mdio.yaml | 61 +++++++++++++++++++ .../bindings/net/hisilicon-hns-mdio.txt | 27 -------- 2 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/hisilicon,hns-mdio.yaml delete mode 100644 Documentation/devicetree/bindings/net/hisilicon-hns-mdio.txt diff --git a/Documentation/devicetree/bindings/net/hisilicon,hns-mdio.yaml b/Documentation/devicetree/bindings/net/hisilicon,hns-mdio.yaml new file mode 100644 index 000000000000..6904f9b351f2 --- /dev/null +++ b/Documentation/devicetree/bindings/net/hisilicon,hns-mdio.yaml @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/hisilicon,hns-mdio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hisilicon HNS MDIO bus controller + +maintainers: + - Jian Shen + - Jijie Shao + +allOf: + - $ref: mdio.yaml# + +properties: + compatible: + enum: + - hisilicon,hns-mdio + - hisilicon,mdio + + reg: + maxItems: 1 + + subctrl-vbase: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: syscon phandle + - description: MDIO clock enable register offset + - description: MDIO reset request register offset + - description: MDIO clock state register offset + - description: MDIO reset state register offset + +required: + - compatible + - reg + - '#address-cells' + - '#size-cells' + - subctrl-vbase + +unevaluatedProperties: false + +examples: + - | + bus { + #address-cells = <2>; + #size-cells = <2>; + + mdio@803c0000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "hisilicon,hns-mdio"; + reg = <0x0 0x803c0000 0x0 0x10000>; + subctrl-vbase = <&peri_c_subctrl 0x338 0xa38 0x531c 0x5a1c>; + + ethernet-phy@0 { + reg = <0>; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/net/hisilicon-hns-mdio.txt b/Documentation/devicetree/bindings/net/hisilicon-hns-mdio.txt deleted file mode 100644 index 4a7ede9657b0..000000000000 --- a/Documentation/devicetree/bindings/net/hisilicon-hns-mdio.txt +++ /dev/null @@ -1,27 +0,0 @@ -Hisilicon MDIO bus controller - -Properties: -- compatible: can be one of: - "hisilicon,hns-mdio" - "hisilicon,mdio" - "hisilicon,hns-mdio" is recommended to be used for hip05 and later SOCs, - while "hisilicon,mdio" is optional for backwards compatibility only on - hip04 Soc. -- reg: The base address of the MDIO bus controller register bank. -- #address-cells: Must be <1>. -- #size-cells: Must be <0>. MDIO addresses have no size component. - -Typically an MDIO bus might have several children. - -Example: - mdio@803c0000 { - #address-cells = <1>; - #size-cells = <0>; - compatible = "hisilicon,hns-mdio","hisilicon,mdio"; - reg = <0x0 0x803c0000 0x0 0x10000>; - - ethernet-phy@0 { - ... - reg = <0>; - }; - }; From 3b70edea393de445255da6c706eebb823117a955 Mon Sep 17 00:00:00 2001 From: Andrea Parri Date: Thu, 1 Oct 2026 16:30:39 +0200 Subject: [PATCH 1097/2126] rtnetlink: wait for RCU readers in rtnl_link_unregister() rtnl_link_ops_get() finds ops on link_ops under rcu_read_lock() and only then takes ops->srcu. rtnl_link_unregister() unlinks ops, then calls synchronize_srcu() and cleanup_srcu_struct() without first waiting for RCU readers. A reader that found ops before list_del_rcu() and has not yet taken ops->srcu is not waited for. Such a reader then locks a cleaned-up srcu_struct and keeps using ops after the module that owns it is gone. rtnl_newlink() and rtnl_dump_ifinfo() both look up ops without RTNL, the latter for any user that dumps links filtered by kind. With delays added between the lookup and srcu_read_lock() in rtnl_link_ops_get(), and before rtnl_link_ops_put() in rtnl_dump_ifinfo(), running "ip link show type dummy" alongside "rmmod dummy" on a KASAN kernel gives: BUG: KASAN: vmalloc-out-of-bounds in __srcu_read_unlock+0x57/0x70 Read of size 8 at addr ffffffffc02ff318 by task ip/147 Call Trace: __srcu_read_unlock+0x57/0x70 rtnl_dump_ifinfo.cold+0x30/0x3b rtnl_dumpit+0x7a/0x1b0 netlink_dump+0x486/0x11b0 __netlink_dump_start+0x661/0x910 rtnetlink_rcv_msg+0x611/0x9e0 netlink_rcv_skb+0x126/0x380 netlink_unicast+0x605/0x830 netlink_sendmsg+0x6d0/0xbb0 __sys_sendto+0x335/0x3a0 Call synchronize_rcu() before synchronize_srcu(), as rtnl_af_unregister() already does. This should be enough because rtnl_link_ops_get() is the only RCU walker of link_ops, and it takes ops->srcu before rcu_read_unlock(), so every reader that found ops is covered by synchronize_srcu() once the RCU grace period ends. The extra grace period only costs time at module unload. Readers and the writer were serialized by RTNL until link_ops got its own mutex, which is why the missing RCU wait did not matter before. Cc: stable+noautosel@kernel.org # needs real net-admin (non-ns) Fixes: 6b57ff21a310 ("rtnetlink: Protect link_ops by mutex.") Reviewed-by: Eric Dumazet Signed-off-by: Andrea Parri Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261001143040.28467-1-parri.andrea@gmail.com Signed-off-by: Jakub Kicinski --- net/core/rtnetlink.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index e3444fd24061..5bbebce0c2f5 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -707,6 +707,10 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops) list_del_rcu(&ops->list); mutex_unlock(&link_ops_mutex); + /* Wait for rtnl_link_ops_get() readers that found ops but have + * not yet taken ops->srcu. + */ + synchronize_rcu(); synchronize_srcu(&ops->srcu); cleanup_srcu_struct(&ops->srcu); From ecf5985006dd0505b2f700ef22fb9beac0ad3457 Mon Sep 17 00:00:00 2001 From: Jisheng Zhang Date: Tue, 29 Sep 2026 20:10:32 +0800 Subject: [PATCH 1098/2126] net: stmmac: Disable unsolicited checksum insertion for AF_XDP TX stmmac enables TX checksum insertion for every AF_XDP packet on queues that support it. The driver does not implement tmo_request_checksum(), so it enables the offload regardless of whether the application requested it and ignores the requested checksum offsets. Disable checksum insertion in the AF_XDP TX path. Applications must supply complete checksums until the driver can honor AF_XDP checksum metadata. Cc: stable+noautosel@kernel.org # high regression risk Fixes: 132c32ee5bc0 ("net: stmmac: Add TX via XDP zero-copy socket") Signed-off-by: Jisheng Zhang Link: https://patch.msgid.link/20260929121032.20835-1-jszhang@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 0c381ae0d0ff..0cfd14d24002 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2716,7 +2716,6 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget) struct netdev_queue *nq = netdev_get_tx_queue(priv->dev, queue); struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue]; struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[queue]; - bool csum = !priv->plat->tx_queues_cfg[queue].coe_unsupported; struct xsk_buff_pool *pool = tx_q->xsk_pool; unsigned int entry = tx_q->cur_tx; struct dma_desc *tx_desc = NULL; @@ -2795,7 +2794,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget) } stmmac_prepare_tx_desc(priv, tx_desc, 1, xdp_desc.len, - csum, priv->descriptor_mode, true, true, + false, priv->descriptor_mode, true, true, xdp_desc.len); stmmac_enable_dma_transmission(priv, priv->ioaddr, queue); From a9d60b086944155e0e1c2265d739d3455154ab10 Mon Sep 17 00:00:00 2001 From: Chengfeng Ye Date: Thu, 1 Oct 2026 02:11:06 +0800 Subject: [PATCH 1099/2126] net-sysfs: release queue trackers before allowing reuse An interrupted sysfs_rtnl_lock() can drop the last kobject reference to a removed TX queue without holding RTNL. netdev_queue_release() clears the kobject before releasing queue->dev_tracker, allowing the queue to be re-added while the old release still needs the shared tracker slot: CPU 0 CPU 1 netdev_queue_release() memset(kobj, 0, sizeof(*kobj)) netdev_queue_add_kobject() state_initialized is clear netdev_hold() installs new tracker netdev_put() releases the new tracker With CONFIG_NET_DEV_REFCNT_TRACKER enabled, the old tracker is leaked and the new lifetime's tracker is released prematurely. A later queue release then reports a double release. The numeric device references remain balanced. The kernel reported: ref_tracker: reference already released. ref_tracker: allocated in: netdev_queue_update_kobjects+0x23d/0x5c0 netif_set_real_num_tx_queues+0x111/0x820 veth_set_channels+0x327/0x930 ethtool_set_channels+0x3ee/0x490 ref_tracker: freed in: netdev_queue_release+0xbd/0x130 kobject_put+0x1f9/0x280 sysfs_rtnl_lock+0x18b/0x1f0 xps_rxqs_show+0xad/0x250 WARNING: lib/ref_tracker.c:322 at ref_tracker_free+0x49e/0x6d0 Call Trace: netdev_queue_release+0xbd/0x130 kobject_put+0x1f9/0x280 netdev_queue_update_kobjects+0x3f9/0x5c0 netif_set_real_num_tx_queues+0x111/0x820 veth_set_channels+0x327/0x930 ethtool_set_channels+0x3ee/0x490 RX queues have the same ordering. Their removal and re-addition are normally serialized by RTNL, but CONFIG_DEBUG_KOBJECT_RELEASE can defer the release callback to workqueue context and expose the same reuse window. Release each tracker before clearing its kobject. Pair full memory barriers on the release and add sides so that an add which observes state_initialized clear cannot install a new tracker before the old release has finished accessing the shared tracker slot. Keep the numeric device reference until after the reset so that the queue storage remains alive throughout the callback's accesses. Cc: stable+noautosel@kernel.org # bug in debug instrumentation Fixes: b0b6fcfa6ad8 ("net-sysfs: remove rtnl_trylock from queue attributes") Signed-off-by: Chengfeng Ye Reviewed-by: Eric Dumazet Reviewed-by: Antoine Tenart Link: https://patch.msgid.link/20260930181106.271547-1-nicoyip.dev@gmail.com Signed-off-by: Jakub Kicinski --- net/core/net-sysfs.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index fa790e442570..728ff0a68248 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1170,8 +1170,11 @@ static void rx_queue_release(struct kobject *kobj) kvfree_rcu_mightsleep(rps_tag_to_table(tag_ptr)); #endif + netdev_tracker_free(queue->dev, &queue->dev_tracker); + /* Pairs with the smp_mb() in rx_queue_add_kobject(). */ + smp_mb(); memset(kobj, 0, sizeof(*kobj)); - netdev_put(queue->dev, &queue->dev_tracker); + __dev_put(queue->dev); } static const struct ns_common *rx_queue_namespace(const struct kobject *kobj) @@ -1244,6 +1247,9 @@ static int rx_queue_add_kobject(struct net_device *dev, int index) return -EAGAIN; } + /* Pairs with the smp_mb() in rx_queue_release(). */ + smp_mb(); + /* Kobject_put later will trigger rx_queue_release call which * decreases dev refcount: Take that reference here */ @@ -1920,8 +1926,11 @@ static void netdev_queue_release(struct kobject *kobj) { struct netdev_queue *queue = to_netdev_queue(kobj); + netdev_tracker_free(queue->dev, &queue->dev_tracker); + /* Pairs with the smp_mb() in netdev_queue_add_kobject(). */ + smp_mb(); memset(kobj, 0, sizeof(*kobj)); - netdev_put(queue->dev, &queue->dev_tracker); + __dev_put(queue->dev); } static const struct ns_common *netdev_queue_namespace(const struct kobject *kobj) @@ -1981,6 +1990,9 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index) return -EAGAIN; } + /* Pairs with the smp_mb() in netdev_queue_release(). */ + smp_mb(); + /* Kobject_put later will trigger netdev_queue_release call * which decreases dev refcount: Take that reference here */ From 9a550198d4243228b1258bf865044951eee27af3 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Thu, 1 Oct 2026 15:56:33 +0000 Subject: [PATCH 1100/2126] ipv4: use zero IPID for atomic datagrams on connected sockets ip_select_ident_segs() uses the per-socket private generator for connected sockets, even for packets with IP_DF set. This was historically done to work around buggy Windows95/2000 VJ header compression implementations, dropping every other packet in a TCP stream when the IP ID field did not change. RFC 6864 section 4.2 states that "Originating sources MAY set the IPv4 ID field of atomic datagrams to any value". Packets with IP_DF set and skb->ignore_df cleared can not be fragmented, neither locally (ip_fragment() refuses to do so) nor by routers on the path. Set their IPID to zero, like we already do for unconnected sockets and in ip_build_and_send_pkt(). FreeBSD also does the same by default (net.inet.ip.rfc6864 = 1). For GSO packets, segments get IP IDs 0, 1, ..., n-1 from GSO/TSO. This does not hurt GRO on receivers, because TCP already forces a PSH flag on every TSO packet since commit 051ba67447de ("tcp: force a PSH flag on TSO packets"), so GRO already flushes at TSO packet boundaries. Connected sockets still use their private generator for packets without IP_DF, or with skb->ignore_df set. Update the inet_id kernel-doc accordingly. This avoids an atomic operation on a shared cache line for connected UDP sockets using IP_PMTUDISC_DO/IP_PMTUDISC_PROBE, and TCP no longer touches inet->inet_id in the fast path. Minor side effects: IP IDs can no longer be used to distinguish network duplicates from TCP retransmits, or to correlate packet captures taken at different points. OS fingerprints will also change. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261001155633.2562504-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- include/net/inet_sock.h | 2 +- include/net/ip.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 7cdcbed3e5cb..24cbabc24582 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -207,7 +207,7 @@ struct rtable; * @inet_saddr - Sending source * @uc_ttl - Unicast TTL * @inet_sport - Source port - * @inet_id - ID counter for DF pkts + * @inet_id - ID counter for non atomic pkts * @tos - TOS * @mc_ttl - Multicasting TTL * @uc_index - Unicast outgoing device index diff --git a/include/net/ip.h b/include/net/ip.h index 6a3e8271a73b..604018cbf0f4 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -584,6 +584,13 @@ static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb, { struct iphdr *iph = ip_hdr(skb); + /* RFC 6864: the IPv4 ID of atomic datagrams has no meaning. + * DF packets without ignore_df can not be fragmented. + */ + if ((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) { + iph->id = 0; + return; + } /* We had many attacks based on IPID, use the private * generator as much as we can. */ @@ -603,12 +610,8 @@ static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb, iph->id = htons(val); return; } - if ((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) { - iph->id = 0; - } else { - /* Unfortunately we need the big hammer to get a suitable IPID */ - __ip_select_ident(net, iph, segs); - } + /* Unfortunately we need the big hammer to get a suitable IPID */ + __ip_select_ident(net, iph, segs); } static inline void ip_select_ident(struct net *net, struct sk_buff *skb, From e404a2de7ed1a19ed356086e3b012e2227c1024d Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Wed, 30 Sep 2026 16:46:46 -0700 Subject: [PATCH 1101/2126] selftests: drv-net: psp: swap closed for connected sockets in assoc tests Future work will only allow rx-assoc and tx-assoc to be performed when the sock is in TCP_ESTABLISHED state. Several assoc_ tests, as well as dev_rotate_spi, test using the rx-assoc and tx-assoc uapi calls against sockets in TCP_CLOSE state. These tests don't involve sending or receiving data, nor involve looking up psp device by dst entry, so using a disposable disconnected socket was just a convenience. These can be replaced by a disposable loopback socket. The loopback sockets are IPv4, where the sockets they replace were AF_INET6. This doesn't reduce coverage, since the assoc handlers accept any TCP socket and don't look at the address family. Some users of rx-assoc and tx-assoc on closed sockets are left if they validate errors that are returned before the kernel will check the socket for TCP_ESTABLISHED. Signed-off-by: Daniel Zahka Fixes: 6b46ca260e22 ("net: psp: add socket security association code") Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260930-psp-defeat-v2-1-f266e7447129@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/psp.py | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index 5a81f40cac7d..0a2329f41431 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -11,6 +11,8 @@ import struct import termios import time +from contextlib import contextmanager + from lib.py import defer from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_gt, ksft_raises @@ -58,6 +60,17 @@ def _make_psp_conn(cfg, version=0, ipver=None): return s +@contextmanager +def _make_lo_conn(): + # After tx-assoc, the client's egress is dropped, since lo has no + # psp_dev, so its FIN never reaches the server. Closing the server + # resets the unaccepted child, and the client accepts the cleartext + # RST because it hasn't received any PSP traffic yet. + with socket.create_server(("localhost", 0)) as srv, \ + socket.create_connection(srv.getsockname()[:2]) as s: + yield s + + def _close_conn(cfg, s): _send_with_ack(cfg, b'data close\0') s.close() @@ -200,20 +213,18 @@ def dev_rotate_spi(cfg): _init_psp_dev(cfg) top_a = top_b = 0 - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with _make_lo_conn() as s: assoc_a = cfg.pspnl.rx_assoc({"version": 0, "dev-id": cfg.psp_dev_id, "sock-fd": s.fileno()}) top_a = assoc_a['rx-key']['spi'] >> 31 - s.close() rot = cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with _make_lo_conn() as s: ksft_eq(rot['id'], cfg.psp_dev_id) assoc_b = cfg.pspnl.rx_assoc({"version": 0, "dev-id": cfg.psp_dev_id, "sock-fd": s.fileno()}) top_b = assoc_b['rx-key']['spi'] >> 31 - s.close() ksft_ne(top_a, top_b) @@ -221,7 +232,7 @@ def assoc_basic(cfg): """ Test creating associations """ _init_psp_dev(cfg) - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with _make_lo_conn() as s: assoc = cfg.pspnl.rx_assoc({"version": 0, "dev-id": cfg.psp_dev_id, "sock-fd": s.fileno()}) @@ -234,7 +245,6 @@ def assoc_basic(cfg): "tx-key": assoc['rx-key'], "sock-fd": s.fileno()}) ksft_eq(len(assoc), 0) - s.close() def assoc_bad_dev(cfg): @@ -320,7 +330,7 @@ def assoc_version_mismatch(cfg): # Translate versions to integers versions = [cfg.pspnl.consts["version"].entries[v].value for v in versions] - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with _make_lo_conn() as s: rx = cfg.pspnl.rx_assoc({"version": versions[0], "dev-id": cfg.psp_dev_id, "sock-fd": s.fileno()}) @@ -393,7 +403,7 @@ def assoc_twice(cfg): return assoc - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with _make_lo_conn() as s: assoc = rx_assoc_check(s) tx = cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, "version": 0, @@ -402,7 +412,7 @@ def assoc_twice(cfg): ksft_eq(len(tx), 0) # Use the same Tx assoc second time - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s2: + with _make_lo_conn() as s2: rx_assoc_check(s2) tx = cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, "version": 0, @@ -410,8 +420,6 @@ def assoc_twice(cfg): "sock-fd": s2.fileno()}) ksft_eq(len(tx), 0) - s.close() - def _data_basic_send(cfg, version, ipver): """ Test basic data send """ From 86a19284425fb0c420e1702f8d0de891279df6b7 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Wed, 30 Sep 2026 16:46:47 -0700 Subject: [PATCH 1102/2126] net: psp: require an established connection for association setup Check sk_state under the socket lock in both the rx-assoc and tx-assoc handlers, and only allow association setup on sockets in TCP_ESTABLISHED. Also, fail connect() when PSP assoc state is already present, and remove the dead PSP MSS adjustment from tcp_v[46]_connect(). The net effect of this commit is: 1. PSP assoc state can never exist on a listen socket. 2. The upgrade to PSP must be done while the socket is in TCP_ESTABLISHED. This change defeatures behavior that was previously allowed under the PSP uapi. My justification is: Nothing useful can be done after association setup on closed or listen sockets today. Listen sockets could accept a PSP-encrypted TCP SYN, but the child socket will not inherit any PSP state. On the other side, establishing PSP state prior to connect() will result in a PSP-encrypted TCP SYN sent to a listening peer, which in turn has the aforementioned limitations. That implies that there cannot be any users of this feature, so it should be safe to remove it from the PSP uapi. In theory, the check in the tx-assoc path is more restrictive than necessary. FIN_WAIT1/2, CLOSING, LAST_ACK and CLOSE_WAIT could be allowed, and the peer would accept PSP-encrypted ACKs in the post-FIN-sent states, or data in the half-close case, but it is simpler to disallow those states because they don't fit the upgrade model. The check in the tx-assoc path fixes a bug in commit 6b46ca260e22 ("net: psp: add socket security association code") where an unsynchronized write can be performed on an assoc shared with a timewait socket when the socket is in TCP_CLOSE after shutdown. This commit is not targeted at net because its premise of preventing listen sockets from holding assoc state depends on net-next commit 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between ehash and lhash2.") Signed-off-by: Daniel Zahka Fixes: 6b46ca260e22 ("net: psp: add socket security association code") Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260930-psp-defeat-v2-2-f266e7447129@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/psp.rst | 8 ++++++++ net/ipv4/tcp_ipv4.c | 7 +++++-- net/ipv6/tcp_ipv6.c | 9 ++++++--- net/psp/psp_sock.c | 12 ++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/psp.rst b/Documentation/networking/psp.rst index 4ac09e64e95a..0f9b6b73f244 100644 --- a/Documentation/networking/psp.rst +++ b/Documentation/networking/psp.rst @@ -132,6 +132,14 @@ numbers in a way that deletes a prefix of the PSP protected part of the TCP stream. If userspace cares to mitigate this type of attack, a special "start of PSP" message should be exchanged after ``tx-assoc``. +Upgrade to PSP must be done on established TCP connections. +``rx-assoc`` and ``tx-assoc`` will return ``-ENOTCONN`` if +``sk_state`` is not ``TCP_ESTABLISHED``. + +The PSP assoc state of a socket is not reset when the connection is +torn down. ``connect()`` on a socket that has PSP assoc state will +return ``-EINVAL``. + Rotation notifications ---------------------- diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index c107b7e44e5b..410d63d9e5c1 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -238,6 +238,9 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len if (usin->sin_family != AF_INET) return -EAFNOSUPPORT; + if (psp_sk_assoc(sk)) + return -EINVAL; + nexthop = daddr = usin->sin_addr.s_addr; inet_opt = rcu_dereference_protected(inet->inet_opt, lockdep_sock_is_held(sk)); @@ -291,9 +294,9 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len inet->inet_dport = usin->sin_port; sk_daddr_set(sk, daddr); - inet_csk(sk)->icsk_ext_hdr_len = psp_sk_overhead(sk); + inet_csk(sk)->icsk_ext_hdr_len = 0; if (inet_opt) - inet_csk(sk)->icsk_ext_hdr_len += inet_opt->opt.optlen; + inet_csk(sk)->icsk_ext_hdr_len = inet_opt->opt.optlen; tp->rx_opt.mss_clamp = TCP_MSS_DEFAULT; diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index afb4d8e9fa67..e006a30360ea 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -153,6 +153,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, if (usin->sin6_family != AF_INET6) return -EAFNOSUPPORT; + if (psp_sk_assoc(sk)) + return -EINVAL; + fl6 = &inet_sk(sk)->cork.fl.u.ip6; memset(fl6, 0, sizeof(*fl6)); @@ -311,10 +314,10 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, sk->sk_gso_type = SKB_GSO_TCPV6; ip6_dst_store(sk, dst, false, false); - icsk->icsk_ext_hdr_len = psp_sk_overhead(sk); + icsk->icsk_ext_hdr_len = 0; if (opt) - icsk->icsk_ext_hdr_len += opt->opt_flen + - opt->opt_nflen; + icsk->icsk_ext_hdr_len = opt->opt_flen + + opt->opt_nflen; tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c index a9cfeebe4ba1..a6b1c42dd626 100644 --- a/net/psp/psp_sock.c +++ b/net/psp/psp_sock.c @@ -159,6 +159,12 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas, lock_sock(sk); + if (sk->sk_state != TCP_ESTABLISHED) { + NL_SET_ERR_MSG(extack, "Socket must be in established state"); + err = -ENOTCONN; + goto exit_unlock; + } + if (psp_sk_assoc(sk)) { NL_SET_ERR_MSG(extack, "Socket already has PSP state"); err = -EBUSY; @@ -252,6 +258,12 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd, lock_sock(sk); + if (sk->sk_state != TCP_ESTABLISHED) { + NL_SET_ERR_MSG(extack, "Socket must be in established state"); + err = -ENOTCONN; + goto exit_unlock; + } + pas = psp_sk_assoc(sk); if (!pas) { NL_SET_ERR_MSG(extack, "Socket has no Rx key"); From c135ee9f4975f9f05465a5fe5eb0970b0a47c55d Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Wed, 30 Sep 2026 16:46:48 -0700 Subject: [PATCH 1103/2126] net: psp: drop psp assoc clear in sk_clone() Unwind the change from commit 1d2929d0850f ("net: psp: do not inherit the Rx association on clone"), now that assoc state cannot exist on listen sockets. With commit 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between ehash and lhash2."), and the change in this series restricting PSP assoc operations to established sockets, this state should be unreachable. Signed-off-by: Daniel Zahka Fixes: 6b46ca260e22 ("net: psp: add socket security association code") Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260930-psp-defeat-v2-3-f266e7447129@gmail.com Signed-off-by: Jakub Kicinski --- net/core/sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/sock.c b/net/core/sock.c index 972c72c5bcc6..2b4c277ef6d9 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2496,7 +2496,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority, RCU_INIT_POINTER(newsk->sk_bpf_storage, NULL); #endif #if IS_ENABLED(CONFIG_INET_PSP) - RCU_INIT_POINTER(newsk->psp_assoc, NULL); + DEBUG_NET_WARN_ON_ONCE(rcu_access_pointer(sk->psp_assoc)); #endif /* SANITY */ From ab1f1ed8e0bbd7721240fce0150194b232121f19 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Wed, 30 Sep 2026 16:46:49 -0700 Subject: [PATCH 1104/2126] selftests: drv-net: psp: test that rx-assoc fails on closed and listen socks Cover two of the basic psp assoc states that have been defeatured. Do not include tests with shutdown(), connect(..., AF_UNSPEC), etc. I don't think the coverage is worth the complexity. That should be done with packetdrill. Signed-off-by: Daniel Zahka Fixes: 6b46ca260e22 ("net: psp: add socket security association code") Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260930-psp-defeat-v2-4-f266e7447129@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/psp.py | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index 0a2329f41431..473500901879 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -319,6 +319,32 @@ def assoc_sk_only_unconn(cfg): ksft_eq(the_exception.nl_msg.error, -errno.EINVAL) +def assoc_rx_unconnected(cfg): + """ Test that an Rx assoc is rejected on an unconnected socket """ + _init_psp_dev(cfg) + + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + with ksft_raises(NlError) as cm: + cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.ENOTCONN) + ksft_eq(cm.exception.nl_msg.extack['bad-attr'], ".sock-fd") + + +def assoc_rx_listener(cfg): + """ Test that an Rx assoc is rejected on a listening socket """ + _init_psp_dev(cfg) + + with socket.create_server(("localhost", 0)) as s: + with ksft_raises(NlError) as cm: + cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.ENOTCONN) + ksft_eq(cm.exception.nl_msg.extack['bad-attr'], ".sock-fd") + + def assoc_version_mismatch(cfg): """ Test creating associations where Rx and Tx PSP versions do not match """ _init_psp_dev(cfg) From ed0e5b924d8f47a04a8671dc96bd9857122b454d Mon Sep 17 00:00:00 2001 From: Sabrina Dubroca Date: Thu, 1 Oct 2026 09:57:25 +0200 Subject: [PATCH 1105/2126] net: strparser: remove unused abort_parser/lock/unlock callbacks The lock/unlock callbacks were introduced in 2017 (bbb03029a899 ("strparser: Generalize strparser")) and haven't been used. The abort_parser callback has existed since strp was committed (2016) and has also never been used. This patch replaces those indirections with the only possible direct call. Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/e55bcc033317dddd47a6dfda6575c755ae7175f7.1790702233.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski --- include/net/strparser.h | 3 --- net/strparser/strparser.c | 39 +++++---------------------------------- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/include/net/strparser.h b/include/net/strparser.h index 0ed73e364faa..78e8e3e12ed3 100644 --- a/include/net/strparser.h +++ b/include/net/strparser.h @@ -46,9 +46,6 @@ struct strp_callbacks { int (*read_sock)(struct strparser *strp, read_descriptor_t *desc, sk_read_actor_t recv_actor); int (*read_sock_done)(struct strparser *strp, int err); - void (*abort_parser)(struct strparser *strp, int err); - void (*lock)(struct strparser *strp); - void (*unlock)(struct strparser *strp); }; struct strp_msg { diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c index a23f4b4dfc67..b5319ed56857 100644 --- a/net/strparser/strparser.c +++ b/net/strparser/strparser.c @@ -75,7 +75,7 @@ static void strp_parser_err(struct strparser *strp, int err, desc->error = err; kfree_skb(strp->skb_head); strp->skb_head = NULL; - strp->cb.abort_parser(strp, err); + strp_abort_strp(strp, err); } static inline int strp_peek_len(struct strparser *strp) @@ -409,7 +409,7 @@ static void do_strp_work(struct strparser *strp) /* We need the read lock to synchronize with strp_data_ready. We * need the socket lock for calling strp_read_sock. */ - strp->cb.lock(strp); + lock_sock(strp->sk); if (unlikely(strp->stopped)) goto out; @@ -421,7 +421,7 @@ static void do_strp_work(struct strparser *strp) queue_work(strp_wq, &strp->work); out: - strp->cb.unlock(strp); + release_sock(strp->sk); } static void strp_work(struct work_struct *w) @@ -436,18 +436,8 @@ static void strp_msg_timeout(struct work_struct *w) /* Message assembly timed out */ STRP_STATS_INCR(strp->stats.msg_timeouts); - strp->cb.lock(strp); - strp->cb.abort_parser(strp, -ETIMEDOUT); - strp->cb.unlock(strp); -} - -static void strp_sock_lock(struct strparser *strp) -{ lock_sock(strp->sk); -} - -static void strp_sock_unlock(struct strparser *strp) -{ + strp_abort_strp(strp, -ETIMEDOUT); release_sock(strp->sk); } @@ -455,36 +445,17 @@ int strp_init(struct strparser *strp, struct sock *sk, const struct strp_callbacks *cb) { - if (!cb || !cb->rcv_msg || !cb->parse_msg) + if (!cb || !cb->rcv_msg || !cb->parse_msg || !sk) return -EINVAL; - /* The sk (sock) arg determines the mode of the stream parser. - * - * If the sock is set then the strparser is in receive callback mode. - * The upper layer calls strp_data_ready to kick receive processing - * and strparser calls the read_sock function on the socket to - * get packets. - * - * If the sock is not set then the strparser is in general mode. - * The upper layer calls strp_process for each skb to be parsed. - */ - - if (!sk) { - if (!cb->lock || !cb->unlock) - return -EINVAL; - } - memset(strp, 0, sizeof(*strp)); strp->sk = sk; - strp->cb.lock = cb->lock ? : strp_sock_lock; - strp->cb.unlock = cb->unlock ? : strp_sock_unlock; strp->cb.rcv_msg = cb->rcv_msg; strp->cb.parse_msg = cb->parse_msg; strp->cb.read_sock = cb->read_sock; strp->cb.read_sock_done = cb->read_sock_done ? : default_read_sock_done; - strp->cb.abort_parser = cb->abort_parser ? : strp_abort_strp; INIT_DELAYED_WORK(&strp->msg_timer_work, strp_msg_timeout); INIT_WORK(&strp->work, strp_work); From 05e37190ba07f6c601349725f3634909f88b3044 Mon Sep 17 00:00:00 2001 From: Sabrina Dubroca Date: Thu, 1 Oct 2026 09:57:26 +0200 Subject: [PATCH 1106/2126] net: strparser: remove strp->sk NULL checks strp_init makes sure strp->sk != NULL. Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/a823a8decf85b3586e50adf8c6d768f59538140a.1790702233.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski --- net/strparser/strparser.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c index b5319ed56857..6cdbd12f41e0 100644 --- a/net/strparser/strparser.c +++ b/net/strparser/strparser.c @@ -36,6 +36,8 @@ static inline struct _strp_msg *_strp_msg(struct sk_buff *skb) /* Lower lock held */ static void strp_abort_strp(struct strparser *strp, int err) { + struct sock *sk = strp->sk; + /* Unrecoverable error in receive */ cancel_delayed_work(&strp->msg_timer_work); @@ -53,13 +55,9 @@ static void strp_abort_strp(struct strparser *strp, int err) strp->skb_nextp = NULL; strp->need_bytes = 0; - if (strp->sk) { - struct sock *sk = strp->sk; - - /* Report an error on the lower socket */ - sk->sk_err = -err; - sk_error_report(sk); - } + /* Report an error on the lower socket */ + sk->sk_err = -err; + sk_error_report(sk); } static void strp_start_timer(struct strparser *strp, long timeo) @@ -80,17 +78,9 @@ static void strp_parser_err(struct strparser *strp, int err, static inline int strp_peek_len(struct strparser *strp) { - if (strp->sk) { - struct socket *sock = strp->sk->sk_socket; + struct socket *sock = strp->sk->sk_socket; - return sock->ops->peek_len(sock); - } - - /* If we don't have an associated socket there's nothing to peek. - * Return int max to avoid stopping the strparser. - */ - - return INT_MAX; + return sock->ops->peek_len(sock); } /* Lower socket lock held */ From b5e153a5c8eefb9fe9f6e1ea592898cac9f8cf13 Mon Sep 17 00:00:00 2001 From: Sabrina Dubroca Date: Thu, 1 Oct 2026 09:57:27 +0200 Subject: [PATCH 1107/2126] net: strparser: remove strp_process() It's unused. Then we can revert the changes that commit bbb03029a899 ("strparser: Generalize strparser") did to extract __strp_recv(). Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/04c57c1e928ec2a94a71413b49b6bec68a71c39d.1790702233.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski --- include/net/strparser.h | 3 --- net/strparser/strparser.c | 30 ++++-------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/include/net/strparser.h b/include/net/strparser.h index 78e8e3e12ed3..a72dff8e6a3f 100644 --- a/include/net/strparser.h +++ b/include/net/strparser.h @@ -160,8 +160,5 @@ void strp_check_rcv(struct strparser *strp); int strp_init(struct strparser *strp, struct sock *sk, const struct strp_callbacks *cb); void strp_data_ready(struct strparser *strp); -int strp_process(struct strparser *strp, struct sk_buff *orig_skb, - unsigned int orig_offset, size_t orig_len, - size_t max_msg_size, long timeo); #endif /* __NET_STRPARSER_H_ */ diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c index 6cdbd12f41e0..80f7555f9670 100644 --- a/net/strparser/strparser.c +++ b/net/strparser/strparser.c @@ -84,11 +84,11 @@ static inline int strp_peek_len(struct strparser *strp) } /* Lower socket lock held */ -static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, - unsigned int orig_offset, size_t orig_len, - size_t max_msg_size, long timeo) +static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, + unsigned int orig_offset, size_t orig_len) { struct strparser *strp = (struct strparser *)desc->arg.data; + long timeo = READ_ONCE(strp->sk->sk_rcvtimeo); struct _strp_msg *stm; struct sk_buff *head, *skb; size_t eaten = 0, cand_len; @@ -230,7 +230,7 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, } strp_parser_err(strp, len, desc); break; - } else if (len > max_msg_size) { + } else if (len > strp->sk->sk_rcvbuf) { /* Message length exceeds maximum allowed */ STRP_STATS_INCR(strp->stats.msg_too_big); strp_parser_err(strp, -EMSGSIZE, desc); @@ -312,28 +312,6 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, return eaten; } -int strp_process(struct strparser *strp, struct sk_buff *orig_skb, - unsigned int orig_offset, size_t orig_len, - size_t max_msg_size, long timeo) -{ - read_descriptor_t desc; /* Dummy arg to strp_recv */ - - desc.arg.data = strp; - - return __strp_recv(&desc, orig_skb, orig_offset, orig_len, - max_msg_size, timeo); -} -EXPORT_SYMBOL_GPL(strp_process); - -static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, - unsigned int orig_offset, size_t orig_len) -{ - struct strparser *strp = (struct strparser *)desc->arg.data; - - return __strp_recv(desc, orig_skb, orig_offset, orig_len, - strp->sk->sk_rcvbuf, READ_ONCE(strp->sk->sk_rcvtimeo)); -} - static int default_read_sock_done(struct strparser *strp, int err) { return err; From 02fd0a21113749e41be286b3645c9d63971f8121 Mon Sep 17 00:00:00 2001 From: Sabrina Dubroca Date: Thu, 1 Oct 2026 09:57:28 +0200 Subject: [PATCH 1108/2126] net: strparser: removed the aborted bit and aborts counter strp->aborted is never set, so the aborts counter is also never updated. Remove them, and hard-code a 0 in kcm_stats_seq_show() to preserve the user-visible format. Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/53d83ac52f192a7cf2a8decaf72d454cbb86211a.1790702233.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski --- include/net/strparser.h | 5 ----- net/kcm/kcmproc.c | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/net/strparser.h b/include/net/strparser.h index a72dff8e6a3f..3c9c8ca08828 100644 --- a/include/net/strparser.h +++ b/include/net/strparser.h @@ -32,7 +32,6 @@ struct strp_aggr_stats { unsigned int msg_too_big; unsigned int msg_timeouts; unsigned int bad_hdr_len; - unsigned int aborts; unsigned int interrupted; unsigned int unrecov_intr; }; @@ -90,7 +89,6 @@ struct strparser { u32 stopped : 1; u32 paused : 1; - u32 aborted : 1; u32 interrupted : 1; u32 unrecov_intr : 1; @@ -128,8 +126,6 @@ static inline void save_strp_stats(struct strparser *strp, SAVE_PSOCK_STATS(bad_hdr_len); #undef SAVE_PSOCK_STATS - if (strp->aborted) - agg_stats->aborts++; if (strp->interrupted) agg_stats->interrupted++; if (strp->unrecov_intr) @@ -147,7 +143,6 @@ static inline void aggregate_strp_stats(struct strp_aggr_stats *stats, SAVE_PSOCK_STATS(msg_too_big); SAVE_PSOCK_STATS(msg_timeouts); SAVE_PSOCK_STATS(bad_hdr_len); - SAVE_PSOCK_STATS(aborts); SAVE_PSOCK_STATS(interrupted); SAVE_PSOCK_STATS(unrecov_intr); #undef SAVE_PSOCK_STATS diff --git a/net/kcm/kcmproc.c b/net/kcm/kcmproc.c index 25c1007f1098..f065406f57a8 100644 --- a/net/kcm/kcmproc.c +++ b/net/kcm/kcmproc.c @@ -332,7 +332,7 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v) psock_stats.tx_bytes, psock_stats.reserved, psock_stats.unreserved, - strp_stats.aborts, + 0, strp_stats.interrupted, strp_stats.unrecov_intr, strp_stats.mem_fail, From 5f193cdabf257bda213dbfb4b42e303fa9e17ffe Mon Sep 17 00:00:00 2001 From: Sabrina Dubroca Date: Thu, 1 Oct 2026 09:57:29 +0200 Subject: [PATCH 1109/2126] docs: networking: strparser: remove general mode Now that the general mode of strp has been removed from the code, update the documentation. Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/0a31a783d4c9c38594da338c49bf085fe6336c92.1790702233.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski --- Documentation/networking/strparser.rst | 120 ++++++++----------------- 1 file changed, 36 insertions(+), 84 deletions(-) diff --git a/Documentation/networking/strparser.rst b/Documentation/networking/strparser.rst index 372106b61e65..9a21bbe93691 100644 --- a/Documentation/networking/strparser.rst +++ b/Documentation/networking/strparser.rst @@ -8,32 +8,24 @@ Introduction ============ The stream parser (strparser) is a utility that parses messages of an -application layer protocol running over a data stream. The stream +application layer protocol running over a TCP connection. The stream parser works in conjunction with an upper layer in the kernel to provide kernel support for application layer messages. For instance, Kernel Connection Multiplexor (KCM) uses the Stream Parser to parse messages using a BPF program. -The strparser works in one of two modes: receive callback or general -mode. - -In receive callback mode, the strparser is called from the data_ready -callback of a TCP socket. Messages are parsed and delivered as they are -received on the socket. - -In general mode, a sequence of skbs are fed to strparser from an -outside source. Message are parsed and delivered as the sequence is -processed. This modes allows strparser to be applied to arbitrary -streams of data. +The strparser is called from the data_ready callback of a TCP +socket. Messages are parsed and delivered as they are received on the +socket. Interface ========= The API includes a context structure, a set of callbacks, utility -functions, and a data_ready function for receive callback mode. The -callbacks include a parse_msg function that is called to perform -parsing (e.g. BPF parsing in case of KCM), and a rcv_msg function -that is called when a full message has been completed. +functions, and a data_ready function. The callbacks include a +parse_msg function that is called to perform parsing (e.g. BPF parsing +in case of KCM), and a rcv_msg function that is called when a full +message has been completed. Functions ========= @@ -45,9 +37,8 @@ Functions Called to initialize a stream parser. strp is a struct of type strparser that is allocated by the upper layer. sk is the TCP - socket associated with the stream parser for use with receive - callback mode; in general mode this is set to NULL. Callbacks - are called by the stream parser (the callbacks are listed below). + socket associated with the stream parser. Callbacks are called by + the stream parser (the callbacks are listed below). :: @@ -79,18 +70,6 @@ Functions parser instance. This must be called after the stream processor has been stopped. - :: - - int strp_process(struct strparser *strp, struct sk_buff *orig_skb, - unsigned int orig_offset, size_t orig_len, - size_t max_msg_size, long timeo) - - strp_process is called in general mode for a stream parser to - parse an sk_buff. The number of bytes processed or a negative - error number is returned. Note that strp_process does not - consume the sk_buff. max_msg_size is maximum size the stream - parser will parse. timeo is timeout for completing a message. - :: void strp_data_ready(struct strparser *strp); @@ -112,16 +91,15 @@ Functions Callbacks ========= -There are seven callbacks: +There are four callbacks: :: int (*parse_msg)(struct strparser *strp, struct sk_buff *skb); - parse_msg is called to determine the length of the next message - in the stream. The upper layer must implement this function. It - should parse the sk_buff as containing the headers for the - next application layer message in the stream. + parse_msg is called to determine the length of the next message in + the stream. It should parse the sk_buff as containing the headers + for the next application layer message in the stream. The strparser metadata in the input skb can be accessed with strp_msg(skb). Only the offset field is relevant in parse_msg and @@ -141,30 +119,13 @@ There are seven callbacks: ========= =========================================================== In the case that an error is returned (return value is less than - zero) and the parser is in receive callback mode, then it will set - the error on TCP socket and wake it up. If parse_msg returned - -ESTRPIPE and the stream parser had previously read some bytes for - the current message, then the error set on the attached socket is - ENODATA since the stream is unrecoverable in that case. + zero), it will set the error on TCP socket and wake it up. If + parse_msg returned -ESTRPIPE and the stream parser had previously + read some bytes for the current message, then the error set on the + attached socket is ENODATA since the stream is unrecoverable in + that case. - :: - - void (*lock)(struct strparser *strp) - - The lock callback is called to lock the strp structure when - the strparser is performing an asynchronous operation (such as - processing a timeout). In receive callback mode the default - function is to lock_sock for the associated socket. In general - mode the callback must be set appropriately. - - :: - - void (*unlock)(struct strparser *strp) - - The unlock callback is called to release the lock obtained - by the lock callback. In receive callback mode the default - function is release_sock for the associated socket. In general - mode the callback must be set appropriately. + This callback must be set. :: @@ -173,8 +134,7 @@ There are seven callbacks: rcv_msg is called when a full message has been received and is queued. The callee must consume the sk_buff; it can call strp_pause to prevent any further messages from being - received in rcv_msg (see strp_pause above). This callback - must be set. + received in rcv_msg (see strp_pause above). The strparser metadata in the input skb can be accessed with strp_msg(skb). This struct contains two fields: offset and full_len. @@ -182,6 +142,8 @@ There are seven callbacks: the length of the message. skb->len - offset may be greater than full_len since strparser does not trim the skb. + This callback must be set. + :: int (*read_sock)(struct strparser *strp, read_descriptor_t *desc, @@ -189,25 +151,20 @@ There are seven callbacks: The read_sock callback is used by strparser instead of sock->ops->read_sock, if provided. + + This callback is optional. + :: int (*read_sock_done)(struct strparser *strp, int err); read_sock_done is called when the stream parser is done reading - the TCP socket in receive callback mode. The stream parser may - read multiple messages in a loop and this function allows cleanup - to occur when exiting the loop. If the callback is not set (NULL - in strp_init) a default function is used. + the TCP socket. The stream parser may read multiple messages in a + loop and this function allows cleanup to occur when exiting the + loop. If the callback is not set (NULL in strp_init) a default + function is used. - :: - - void (*abort_parser)(struct strparser *strp, int err); - - This function is called when stream parser encounters an error - in parsing. The default function stops the stream parser and - sets the error in the socket if the parser is in receive callback - mode. The default function can be changed by setting the callback - to non-NULL in strp_init. + This callback is optional. Statistics ========== @@ -224,23 +181,18 @@ Message assembly limits The stream parser provide mechanisms to limit the resources consumed by message assembly. -A timer is set when assembly starts for a new message. In receive -callback mode the message timeout is taken from rcvtime for the -associated TCP socket. In general mode, the timeout is passed as an -argument in strp_process. If the timer fires before assembly completes -the stream parser is aborted and the ETIMEDOUT error is set on the TCP -socket if in receive callback mode. +A timer is set when assembly starts for a new message. The message +timeout is taken from rcvtime for the associated TCP socket. If the +timer fires before assembly completes the stream parser is aborted and +the ETIMEDOUT error is set on the TCP socket. -In receive callback mode, message length is limited to the receive +Message length is limited to the receive buffer size of the associated TCP socket. If the length returned by parse_msg is greater than the socket buffer size then the stream parser is aborted with EMSGSIZE error set on the TCP socket. Note that this makes the maximum size of receive skbuffs for a socket with a stream parser to be 2*sk_rcvbuf of the TCP socket. -In general mode the message length limit is passed in as an argument -to strp_process. - Author ====== From e234d7625598b2eaded84fa99f53c8062650828f Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:35 +0000 Subject: [PATCH 1110/2126] dlm: fix send buffer backpressure handling lowcomms.c tests and clears SOCKWQ_ASYNC_NOSPACE in con->sock->flags, but this bit has not been stored there for ten years. Commit 9cd3e072b0be ("net: rename SOCK_ASYNC_NOSPACE and SOCK_ASYNC_WAITDATA") mechanically renamed the two dlm users, then commit ceb5d58b2170 ("net: fix sock_wake_async() rcu protection") moved the bit from socket->flags to the RCU protected socket_wq->flags, where it is reachable only through sk_set_bit() and sk_clear_bit(), and is only maintained for sockets having SOCK_FASYNC set. dlm uses kernel sockets, which never have SOCK_FASYNC set, and never sets the bit itself, so the test in send_to_sock() has been false ever since. The consequence is that when sock_sendmsg() returns -EAGAIN because the socket send buffer is full, dlm no longer sets CF_APP_LIMITED, does not increment sk_write_pending, and does not return DLM_IO_END to wait for lowcomms_write_space(). It returns DLM_IO_RESCHED instead, and process_send_sockets() immediately requeues the send work. A connection to a peer that is slow to drain thus keeps cycling through sock_sendmsg() and -EAGAIN, burning CPU, instead of sleeping until TCP reports that space is available again. Test SOCK_NOSPACE instead. This is the bit that lives in socket->flags, that TCP sets whenever sendmsg() returns -EAGAIN for lack of send buffer space (tcp_sendmsg_locked() and sk_stream_wait_memory()), and that lowcomms_write_space() already clears. This restores the semantics dlm had before the bit moved. Also remove the clear_bit() of SOCKWQ_ASYNC_NOSPACE from lowcomms_write_space(), for the same reason. SCTP connections are deliberately left as they are. SCTP does not set SOCK_NOSPACE, and it never calls sk->sk_write_space(): sctp_wfree() ends up in sctp_wake_up_waiters(), which calls sctp_write_space() directly. lowcomms_write_space() is thus never invoked for an SCTP connection, and the test added here stays false, so send_to_sock() keeps returning DLM_IO_RESCHED as it does today. This is the only safe behavior, as returning DLM_IO_END would wait for a callback that never comes. Fixes: ceb5d58b2170 ("net: fix sock_wake_async() rcu protection") Cc: stable@vger.kernel.org Cc: David Teigland Acked-by: Alexander Aring Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260929071743.23624-2-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- fs/dlm/lowcomms.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 2aff1c7c17de..abe9ae4c643f 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -522,10 +522,8 @@ static void lowcomms_write_space(struct sock *sk) clear_bit(SOCK_NOSPACE, &con->sock->flags); spin_lock_bh(&con->writequeue_lock); - if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) { + if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) con->sock->sk->sk_write_pending--; - clear_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags); - } lowcomms_queue_swork(con); spin_unlock_bh(&con->writequeue_lock); @@ -1391,7 +1389,7 @@ static int send_to_sock(struct connection *con) if (ret == -EAGAIN || ret == 0) { lock_sock(con->sock->sk); spin_lock_bh(&con->writequeue_lock); - if (test_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags) && + if (test_bit(SOCK_NOSPACE, &con->sock->flags) && !test_and_set_bit(CF_APP_LIMITED, &con->flags)) { /* Notify TCP that we're limited by the * application window size. From 6ba48a271bdb9c3e106314936ee202f7f249a3db Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:36 +0000 Subject: [PATCH 1111/2126] net: add sk_set_nospace() and sk_clear_nospace() SOCK_NOSPACE lives in sk->sk_socket->flags and is manipulated from about thirty places in the tree, all of them open coding the sk->sk_socket dereference, some with a NULL check, some without, and some reaching the struct socket by yet another path. Add sk_set_nospace() and sk_clear_nospace() helpers and convert the core networking setters and clearers to them; the following patches convert the remaining subsystem callers so that "git grep _bit(SOCK_NOSPACE" only reports the two helpers and the remaining test_bit() sites. Callers that had no NULL check are all called from user context with a socket attached, so folding the check into the helpers only makes them more robust. No functional change intended. This is a preparation patch: a following one gives TCP a cheaper private copy of this bit, and needs a single choke point to keep it in sync. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260929071743.23624-3-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- include/net/sock.h | 2 ++ net/core/sock.c | 37 +++++++++++++++++++++++++++++++++++-- net/core/stream.c | 6 +++--- net/ipv4/tcp.c | 4 ++-- net/ipv4/tcp_bpf.c | 2 +- net/kcm/kcmsock.c | 4 ++-- net/mptcp/protocol.c | 4 ++-- net/smc/af_smc.c | 2 +- net/smc/smc_tx.c | 6 +++--- net/tls/tls_sw.c | 2 +- 10 files changed, 52 insertions(+), 17 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 60ea55dc1885..f4dd2e105171 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1129,6 +1129,8 @@ static inline void sk_forward_alloc_add(struct sock *sk, int val) } void sk_stream_write_space(struct sock *sk); +void sk_set_nospace(struct sock *sk); +void sk_clear_nospace(struct sock *sk); /* OOB backlog add */ static inline void __sk_add_backlog(struct sock *sk, struct sk_buff *skb) diff --git a/net/core/sock.c b/net/core/sock.c index 2b4c277ef6d9..4a6cf652950c 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2957,6 +2957,39 @@ void sock_kzfree_s(struct sock *sk, void *mem, int size) } EXPORT_SYMBOL(sock_kzfree_s); +/** + * sk_set_nospace - tell the transport a writer is waiting for space + * @sk: socket + * + * Must be called before the final check of the available send space, + * so that the transport can not miss the request and forget to call + * sk->sk_write_space() once space is available again. + */ +void sk_set_nospace(struct sock *sk) +{ + struct socket *sock = sk->sk_socket; + + if (sock) + set_bit(SOCK_NOSPACE, &sock->flags); +} +EXPORT_SYMBOL(sk_set_nospace); + +/** + * sk_clear_nospace - tell the transport no writer is waiting for space + * @sk: socket + * + * Called from ->sk_write_space() handlers, once send space has been + * made available to writers. + */ +void sk_clear_nospace(struct sock *sk) +{ + struct socket *sock = sk->sk_socket; + + if (sock) + clear_bit(SOCK_NOSPACE, &sock->flags); +} +EXPORT_SYMBOL(sk_clear_nospace); + /* It is almost wait_for_tcp_memory minus release_sock/lock_sock. I think, these locks should be removed for datagram sockets. */ @@ -2970,7 +3003,7 @@ static long sock_wait_for_wmem(struct sock *sk, long timeo) break; if (signal_pending(current)) break; - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); if (refcount_read(&sk->sk_wmem_alloc) < READ_ONCE(sk->sk_sndbuf)) break; @@ -3011,7 +3044,7 @@ struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len, break; sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); err = -EAGAIN; if (!timeo) goto failure; diff --git a/net/core/stream.c b/net/core/stream.c index 5c0adc3077f0..cb255e2a3a5d 100644 --- a/net/core/stream.c +++ b/net/core/stream.c @@ -37,7 +37,7 @@ void sk_stream_write_space(struct sock *sk) struct socket_wq *wq; if (__sk_stream_is_writeable(sk, 1) && sock) { - clear_bit(SOCK_NOSPACE, &sock->flags); + sk_clear_nospace(sk); rcu_read_lock(); wq = rcu_dereference(sk->sk_wq); @@ -143,7 +143,7 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p) if (sk_stream_memory_free(sk) && !vm_wait) break; - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); sk->sk_write_pending++; ret = sk_wait_event(sk, ¤t_timeo, READ_ONCE(sk->sk_err) || (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) || @@ -177,7 +177,7 @@ do_eagain: * When TCP receives ACK packets that make room, tcp_check_space() * only calls tcp_new_space() if SOCK_NOSPACE is set. */ - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); err = -EAGAIN; goto out; do_interrupted: diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 7c9d8305094c..bf339dc1f366 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -607,7 +607,7 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait) mask |= EPOLLOUT | EPOLLWRNORM; } else { /* send SIGIO later */ sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); /* Race breaker. If space is freed after * wspace test but before the flags are set, @@ -1397,7 +1397,7 @@ new_segment: continue; wait_for_space: - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); tcp_remove_empty_skb(sk); if (copied) tcp_push(sk, flags & ~MSG_MORE, mss_now, diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 338c5d90e550..9dfa25347615 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -600,7 +600,7 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) goto out_err; continue; wait_for_sndbuf: - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); wait_for_memory: err = sk_stream_wait_memory(sk, &timeo); if (err) { diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index 71af69d442f2..b29c0ed9caf5 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -735,7 +735,7 @@ static void kcm_tx_work(struct work_struct *w) /* Primarily for SOCK_SEQPACKET sockets */ if (likely(sk->sk_socket) && test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { - clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_clear_nospace(sk); sk->sk_write_space(sk); } @@ -779,7 +779,7 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) /* Call the sk_stream functions to manage the sndbuf mem. */ if (!sk_stream_memory_free(sk)) { kcm_push(kcm); - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); err = sk_stream_wait_memory(sk, &timeo); if (err) goto out_error; diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b543eb245136..6ca5717ce009 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2106,7 +2106,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) continue; wait_for_memory: - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); __mptcp_push_pending(sk, msg->msg_flags); ret = sk_stream_wait_memory(sk, &timeo); if (ret) @@ -4471,7 +4471,7 @@ static __poll_t mptcp_check_writeable(struct mptcp_sock *msk) if (__mptcp_stream_is_writeable(sk, 1)) return EPOLLOUT | EPOLLWRNORM; - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); smp_mb__after_atomic(); /* NOSPACE is changed by mptcp_write_space() */ if (__mptcp_stream_is_writeable(sk, 1)) return EPOLLOUT | EPOLLWRNORM; diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 7f762bb31879..9663dc44e532 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -2925,7 +2925,7 @@ __poll_t smc_poll(struct file *file, struct socket *sock, mask |= EPOLLOUT | EPOLLWRNORM; } else { sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); if (sk->sk_state != SMC_INIT) { /* Race breaker the same way as tcp_poll(). */ diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c index c5c00c63ce4c..9e22a1983475 100644 --- a/net/smc/smc_tx.c +++ b/net/smc/smc_tx.c @@ -48,7 +48,7 @@ static void smc_tx_write_space(struct sock *sk) if (atomic_read(&smc->conn.sndbuf_space) && sock) { if (test_bit(SOCK_NOSPACE, &sock->flags)) SMC_STAT_RMB_TX_FULL(smc, !smc->conn.lnk); - clear_bit(SOCK_NOSPACE, &sock->flags); + sk_clear_nospace(sk); rcu_read_lock(); wq = rcu_dereference(sk->sk_wq); if (skwq_has_sleeper(wq)) @@ -100,7 +100,7 @@ static int smc_tx_wait(struct smc_sock *smc, int flags) } if (!timeo) { /* ensure EPOLLOUT is subsequently generated */ - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); rc = -EAGAIN; break; } @@ -111,7 +111,7 @@ static int smc_tx_wait(struct smc_sock *smc, int flags) sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); if (atomic_read(&conn->sndbuf_space) && !conn->urg_tx_pend) break; /* at least 1 byte of free & no urgent data */ - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); sk_wait_event(sk, &timeo, READ_ONCE(sk->sk_err) || (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) || diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index d1ad31986cf2..312e51270f29 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -966,7 +966,7 @@ copied: continue; wait_for_sndbuf: - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); wait_for_memory: ret = sk_stream_wait_memory(sk, &timeo); if (ret) { From 28613c4d4757b1ffad39f3227c95c85506487397 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:37 +0000 Subject: [PATCH 1112/2126] sunrpc: use sk_set_nospace() and sk_clear_nospace() Use the new helpers instead of open coding the SOCK_NOSPACE manipulation, so that TCP can later maintain a cheaper private copy of this bit. No functional change intended. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Acked-by: Chuck Lever Link: https://patch.msgid.link/20260929071743.23624-4-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/sunrpc/svcsock.c | 4 ++-- net/sunrpc/xprtsock.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 50e5e7f5b762..2d8cdee0798d 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -792,11 +792,11 @@ static int svc_udp_has_wspace(struct svc_xprt *xprt) * Set the SOCK_NOSPACE flag before checking the available * sock space. */ - set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags); + sk_set_nospace(svsk->sk_sk); required = atomic_read(&svsk->sk_xprt.xpt_reserved) + serv->sv_max_mesg; if (required*2 > sock_wspace(svsk->sk_sk)) return 0; - clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags); + sk_clear_nospace(svsk->sk_sk); return 1; } diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 7f60723fa64d..b97c70c12f62 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -858,7 +858,7 @@ static int xs_nospace(struct rpc_rqst *req, struct sock_xprt *transport) if (xprt_connected(xprt)) { /* wait for more buffer space */ set_bit(XPRT_SOCK_NOSPACE, &transport->sock_state); - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); sk->sk_write_pending++; xprt_wait_for_buffer_space(xprt); } else @@ -1615,7 +1615,7 @@ static void xs_write_space(struct sock *sk) if (!sk->sk_socket) return; - clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_clear_nospace(sk); if (unlikely(!(xprt = xprt_from_sock(sk)))) return; From b747807ccaf99ab59e3539151904695762266f69 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:38 +0000 Subject: [PATCH 1113/2126] rds: use sk_set_nospace() Use the new helpers instead of open coding the SOCK_NOSPACE manipulation, so that TCP can later maintain a cheaper private copy of this bit. No functional change intended. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Acked-by: Allison Henderson Link: https://patch.msgid.link/20260929071743.23624-5-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/rds/tcp_send.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c index 7c52acc749cf..824222c47511 100644 --- a/net/rds/tcp_send.c +++ b/net/rds/tcp_send.c @@ -100,7 +100,7 @@ int rds_tcp_xmit(struct rds_connection *conn, struct rds_message *rm, if (hdr_off < sizeof(struct rds_header)) { /* see rds_tcp_write_space() */ - set_bit(SOCK_NOSPACE, &tc->t_sock->sk->sk_socket->flags); + sk_set_nospace(tc->t_sock->sk); ret = rds_tcp_sendmsg(tc->t_sock, (void *)&rm->m_inc.i_hdr + hdr_off, @@ -221,6 +221,5 @@ out: */ write_space(sk); - if (sk->sk_socket) - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); } From 0e0be63cb35ded8617d236fb15608e37ea508e90 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:39 +0000 Subject: [PATCH 1114/2126] dlm: use sk_set_nospace() and sk_clear_nospace() Use the new helpers instead of open coding the SOCK_NOSPACE manipulation, so that TCP can later maintain a cheaper private copy of this bit. No functional change intended. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260929071743.23624-6-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- fs/dlm/lowcomms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index abe9ae4c643f..6aa68a24acab 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -519,7 +519,7 @@ static void lowcomms_write_space(struct sock *sk) { struct connection *con = sock2con(sk); - clear_bit(SOCK_NOSPACE, &con->sock->flags); + sk_clear_nospace(sk); spin_lock_bh(&con->writequeue_lock); if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) @@ -1394,7 +1394,7 @@ static int send_to_sock(struct connection *con) /* Notify TCP that we're limited by the * application window size. */ - set_bit(SOCK_NOSPACE, &con->sock->sk->sk_socket->flags); + sk_set_nospace(con->sock->sk); con->sock->sk->sk_write_pending++; clear_bit(CF_SEND_PENDING, &con->flags); From 24280d1d28328778c47094fe288a7dee83138da1 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:40 +0000 Subject: [PATCH 1115/2126] drbd: use sk_set_nospace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new helpers instead of open coding the SOCK_NOSPACE manipulation, so that TCP can later maintain a cheaper private copy of this bit. No functional change intended. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Acked-by: Christoph Böhmwalder Link: https://patch.msgid.link/20260929071743.23624-7-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- drivers/block/drbd/drbd_worker.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c index 0697f99fed18..8e50131b5a56 100644 --- a/drivers/block/drbd/drbd_worker.c +++ b/drivers/block/drbd/drbd_worker.c @@ -635,8 +635,7 @@ static int make_resync_request(struct drbd_peer_device *const peer_device, int c int sndbuf = sk->sk_sndbuf; if (queued > sndbuf / 2) { requeue = 1; - if (sk->sk_socket) - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_set_nospace(sk); } } else requeue = 1; From f80fa2ddfe95c12d84c7ca7c5d0b0846ec6a43eb Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:41 +0000 Subject: [PATCH 1116/2126] nvme-tcp: use sk_clear_nospace() Use the new helpers instead of open coding the SOCK_NOSPACE manipulation, so that TCP can later maintain a cheaper private copy of this bit. No functional change intended. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260929071743.23624-8-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- drivers/nvme/host/tcp.c | 2 +- drivers/nvme/target/tcp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 921934028e0b..b853ca2d598f 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1133,7 +1133,7 @@ static void nvme_tcp_write_space(struct sock *sk) read_lock_bh(&sk->sk_callback_lock); queue = sk->sk_user_data; if (likely(queue && sk_stream_is_writeable(sk))) { - clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_clear_nospace(sk); /* Ensure pending TLS partial records are retried */ if (nvme_tcp_queue_tls(queue)) queue->write_space(sk); diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index e59810175262..c38ea3501ea5 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1686,7 +1686,7 @@ static void nvmet_tcp_write_space(struct sock *sk) } if (sk_stream_is_writeable(sk)) { - clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_clear_nospace(sk); queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); } out: From 5181ac617537474e6e3de40e22bfd009b4f6e231 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:42 +0000 Subject: [PATCH 1117/2126] libceph: use sk_clear_nospace() Use the new helpers instead of open coding the SOCK_NOSPACE manipulation, so that TCP can later maintain a cheaper private copy of this bit. No functional change intended. Reviewed-by: Kuniyuki Iwashima Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260929071743.23624-9-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ceph/messenger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 212e7797f9e4..cc7db8c61db3 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -375,7 +375,7 @@ static void ceph_sock_write_space(struct sock *sk) if (ceph_con_flag_test(con, CEPH_CON_F_WRITE_PENDING)) { if (sk_stream_is_writeable(sk)) { dout("%s %p queueing write work\n", __func__, con); - clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + sk_clear_nospace(sk); queue_con(con); } } else { From 4eee6d58ad1497518b59f8f2c0eb42e258d9cc82 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 29 Sep 2026 07:17:43 +0000 Subject: [PATCH 1118/2126] tcp: add tp->tcp_nospace tcp_check_space() runs for every incoming ACK and for every packet we send, and reads SOCK_NOSPACE from sk->sk_socket->flags. struct socket lives in its own cache line, which the TCP fast paths do not otherwise touch, so testing sk->sk_socket->flags pulls in an extra cache line that is cold when the working set is large. Add tp->tcp_nospace, a mirror of SOCK_NOSPACE placed right after tp->chrono_type in the tcp_sock_write_tx group, in a cache line both the transmit and the ACK paths already touch (bytes_sent, data_segs_out, delivered, bytes_acked, chrono_type). It fits in an existing 3-byte hole before chrono_start, so no other field moves and sizeof(struct tcp_sock) is unchanged. The two flags are now only changed from sk_set_nospace() and sk_clear_nospace(), which maintain this invariant: SOCK_NOSPACE set => tp->tcp_nospace set sk_set_nospace() sets SOCK_NOSPACE before tp->tcp_nospace (using smp_mb__after_atomic() and smp_store_mb()), while sk_clear_nospace() clears tp->tcp_nospace before SOCK_NOSPACE (using smp_mb__before_atomic()). If a lockless sk_set_nospace() from tcp_poll() races with sk_clear_nospace() and SOCK_NOSPACE ends up set, set_bit(SOCK_NOSPACE) happened after clear_bit(SOCK_NOSPACE), so tp->tcp_nospace = 1 happens after tp->tcp_nospace = 0 as well. tcp_check_space() can thus test tp->tcp_nospace alone and leave the authoritative SOCK_NOSPACE test to __tcp_check_space(). The invariant is one directional on purpose: a stale tp->tcp_nospace only costs an extra call to __tcp_check_space(), which is what we do unconditionally today, while a stale SOCK_NOSPACE would cost a missed EPOLLOUT. Note the smp_mb() is kept. tcp_poll() sets the flag without the socket lock, and the store-buffer pattern it forms with tcp_check_space() needs a full barrier on both sides. MPTCP subflows share the struct socket of their parent, hence its SOCK_NOSPACE bit, which can not be mirrored in the subflow tcp_sock. Pin their tp->tcp_nospace in subflow_ulp_init(), so that they always reach __tcp_check_space() and keep the current behavior. Microbenchmark on an AMD EPYC 7B13, 64 threads, each thread calling tcp_check_space() in a loop over a private set of sockets. Numbers are cycles per call above a baseline loop that performs the work the callers already did (the cache lines tcp_write_xmit() and tcp_clean_rtx_queue() touched) but not tcp_check_space() itself, so they are the marginal cost of the function. Median of 11 runs. The set size controls whether struct socket is still cached: sockets/thread before after 1 +0.6 +0.7 256 (64 KB) +8.3 +3.9 4096 (1 MB) +22.4 +1.1 262144 (64 MB) +48.4 -0.8 Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260929071743.23624-10-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 3 ++ include/net/tcp.h | 30 ++++++++++++++++++- net/core/sock.c | 17 ++++++++--- net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 8 ++++- net/mptcp/subflow.c | 5 ++++ 7 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst index 0f6088c4ab8b..103328dc409e 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -50,6 +50,7 @@ u8:1 tcp_usec_ts read_mostly read_m u32 chrono_start read_write tcp_chrono_start/stop(tcp_write_xmit,tcp_cwnd_validate,tcp_send_syn_data) u32[3] chrono_stat read_write tcp_chrono_start/stop(tcp_write_xmit,tcp_cwnd_validate,tcp_send_syn_data) u8:2 chrono_type read_write tcp_chrono_start/stop(tcp_write_xmit,tcp_cwnd_validate,tcp_send_syn_data) +u8 tcp_nospace read_mostly read_mostly tcp_check_space(tx);tcp_check_space(rx) u8:1 rate_app_limited read_write tcp_rate_gen u8:1 fastopen_connect u8:1 fastopen_no_cookie diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 6a8c77719322..e4d1720f49f0 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -269,6 +269,9 @@ struct tcp_sock { */ u32 snd_sml; /* Last byte of the most recently transmitted small packet */ u8 chrono_type; /* current chronograph type */ + u8 tcp_nospace; /* mirrors SOCK_NOSPACE, must be set whenever + * SOCK_NOSPACE is set. + */ u32 chrono_start; /* Start time in jiffies of a TCP chrono */ u32 chrono_stat[3]; /* Time in jiffies for chrono_stat stats */ u32 write_seq; /* Tail(+1) of data held in tcp send buffer */ diff --git a/include/net/tcp.h b/include/net/tcp.h index 74f54bfa51f1..0265c27a5fd7 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -783,14 +783,42 @@ void tcp_done_with_error(struct sock *sk, int err); void tcp_reset(struct sock *sk, struct sk_buff *skb); void tcp_fin(struct sock *sk); void __tcp_check_space(struct sock *sk); + +/* Mirror of SOCK_NOSPACE in tcp_sock, maintained by sk_set_nospace() + * and sk_clear_nospace(). + * + * MPTCP subflows share the parent socket, and thus its SOCK_NOSPACE bit. + * Keep their mirror always set (see subflow_ulp_init()) so that they + * always reach __tcp_check_space() and behave as before. + */ +static inline void tcp_set_nospace(struct sock *sk) +{ + if (sk_is_tcp(sk)) { + /* pairs with smp_mb__before_atomic() in tcp_clear_nospace() */ + smp_mb__after_atomic(); + /* pairs with smp_mb() in tcp_check_space() */ + smp_store_mb(tcp_sk(sk)->tcp_nospace, 1); + } +} + +static inline void tcp_clear_nospace(struct sock *sk) +{ + if (sk_is_tcp(sk) && !sk_is_mptcp(sk)) { + WRITE_ONCE(tcp_sk(sk)->tcp_nospace, 0); + /* pairs with smp_mb__after_atomic() in tcp_set_nospace() */ + smp_mb__before_atomic(); + } +} + static inline void tcp_check_space(struct sock *sk) { /* pairs with tcp_poll() */ smp_mb(); - if (sk->sk_socket && test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) + if (unlikely(READ_ONCE(tcp_sk(sk)->tcp_nospace))) __tcp_check_space(sk); } + void tcp_sack_compress_send_ack(struct sock *sk); static inline void tcp_cleanup_skb(struct sk_buff *skb) diff --git a/net/core/sock.c b/net/core/sock.c index 4a6cf652950c..6db7c8295d58 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2969,8 +2969,15 @@ void sk_set_nospace(struct sock *sk) { struct socket *sock = sk->sk_socket; - if (sock) - set_bit(SOCK_NOSPACE, &sock->flags); + if (!sock) + return; + /* Set SOCK_NOSPACE before tp->tcp_nospace (paired with + * sk_clear_nospace() clearing tp->tcp_nospace before SOCK_NOSPACE) + * so a concurrent clear cannot leave SOCK_NOSPACE set with + * tp->tcp_nospace cleared. + */ + set_bit(SOCK_NOSPACE, &sock->flags); + tcp_set_nospace(sk); } EXPORT_SYMBOL(sk_set_nospace); @@ -2985,8 +2992,10 @@ void sk_clear_nospace(struct sock *sk) { struct socket *sock = sk->sk_socket; - if (sock) - clear_bit(SOCK_NOSPACE, &sock->flags); + if (!sock) + return; + tcp_clear_nospace(sk); + clear_bit(SOCK_NOSPACE, &sock->flags); } EXPORT_SYMBOL(sk_clear_nospace); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index bf339dc1f366..7629e43661b3 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -5240,6 +5240,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, first_tx_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, delivered_mstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, snd_sml); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, tcp_nospace); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, chrono_start); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, chrono_stat); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, write_seq); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 01d748230135..1ddce9c4b7e8 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6111,8 +6111,14 @@ static void tcp_new_space(struct sock *sk) */ void __tcp_check_space(struct sock *sk) { + struct socket *sock = sk->sk_socket; + + /* tp->tcp_nospace is only a hint, SOCK_NOSPACE is authoritative. */ + if (!sock || !test_bit(SOCK_NOSPACE, &sock->flags)) + return; + tcp_new_space(sk); - if (!test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) + if (!test_bit(SOCK_NOSPACE, &sock->flags)) tcp_chrono_stop(sk, TCP_CHRONO_SNDBUF_LIMITED); } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index e9cb19188069..3d5f3f68a33a 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -2001,6 +2001,11 @@ static int subflow_ulp_init(struct sock *sk) pr_debug("subflow=%p, family=%d\n", ctx, sk->sk_family); tp->is_mptcp = 1; + /* Subflows share the MPTCP socket, and thus its SOCK_NOSPACE bit, + * which tcp_check_space() can not mirror. Pin the mirror so that + * __tcp_check_space() always tests the shared bit. + */ + tp->tcp_nospace = 1; ctx->icsk_af_ops = icsk->icsk_af_ops; icsk->icsk_af_ops = subflow_default_af_ops(sk); ctx->tcp_state_change = sk->sk_state_change; From 3c9d88b04e6cfd1dac03e89166fef34077c79763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Wed, 30 Sep 2026 20:35:36 +0200 Subject: [PATCH 1119/2126] net: macb: move printk() calls out of bp->lock critical section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit printk() call while bp->lock is acquired might be a bad idea: - It grows the spinlock atomic section. - If netconsole is active on the same interface (and we run on the queue's CPU), we risk a deadlock because macb_poll_controller() calls macb_interrupt() which grab bp->lock if an IRQ is pending. Three messages are changed: - In macb_tx_error_task(), defer netdev_err("halt tx timed out") call to after the critical section. Update the message to highlight it occurred in the past. Inherit the buffer exhaustion boolean variable name from the old code comment. - In macb_tx_error_task(), defer the netdev_err("TX buffers exhausted mid-frame") call out of the loop. This also means it goes from 1-per-error to 1-per-task-invocation. - In IRQ handling, move HRESP error printing out of macb_interrupt_misc() into macb_interrupt(). Again, it means we dedup error reporting if status is read multiple times in a row with HRESP bit set. This is fine as from past instances I've seen, this message spams our log if it occurs. Notice we *ignore* debug printks; if you are debugging MACB maybe don't use netconsole... The netconsole deadlock is theoretical & never reproduced. Signed-off-by: Théo Lebrun Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20260930-macb-irq-v1-1-8994a4c8f3bb@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb_main.c | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 1520a9b4edaf..c4223ca848df 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1282,6 +1282,7 @@ static void macb_tx_error_task(struct work_struct *work) struct macb_tx_skb *tx_skb; struct macb_dma_desc *desc; bool halt_timeout = false; + bool buggy_driver = false; struct sk_buff *skb; unsigned long flags; unsigned int tail; @@ -1308,7 +1309,6 @@ static void macb_tx_error_task(struct work_struct *work) * macb/gem must be halted to write TBQP register */ if (macb_halt_tx(bp)) { - netdev_err(bp->netdev, "BUG: halt tx timed out\n"); macb_writel(bp, NCR, macb_readl(bp, NCR) & (~MACB_BIT(TE))); halt_timeout = true; } @@ -1353,8 +1353,7 @@ static void macb_tx_error_task(struct work_struct *work) * those. Statistics are updated by hardware. */ if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED)) - netdev_err(bp->netdev, - "BUG: TX buffers exhausted mid-frame\n"); + buggy_driver = true; desc->ctrl = ctrl | MACB_BIT(TX_USED); } @@ -1391,7 +1390,14 @@ static void macb_tx_error_task(struct work_struct *work) macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); spin_unlock_irqrestore(&bp->lock, flags); + napi_enable(&queue->napi_tx); + + if (halt_timeout) + netdev_err(bp->netdev, "BUG: halt tx timed out, we ignored it\n"); + + if (buggy_driver) + netdev_err(bp->netdev, "BUG: TX buffers exhausted mid-frame\n"); } static bool ptp_one_step_sync(struct sk_buff *skb) @@ -2143,11 +2149,8 @@ static void gem_wol_interrupt(struct macb_queue *queue, u32 status) static int macb_interrupt_misc(struct macb_queue *queue, u32 status) { struct macb *bp = queue->bp; - struct net_device *netdev; u32 ctrl; - netdev = bp->netdev; - if (unlikely(status & (MACB_TX_ERR_FLAGS))) { queue_writel(queue, IDR, MACB_TX_INT_FLAGS); schedule_work(&queue->tx_error_task); @@ -2187,7 +2190,6 @@ static int macb_interrupt_misc(struct macb_queue *queue, u32 status) if (status & MACB_BIT(HRESP)) { queue_work(system_bh_wq, &bp->hresp_err_bh_work); - netdev_err(netdev, "DMA bus error: HRESP not OK\n"); macb_queue_isr_clear(bp, queue, MACB_BIT(HRESP)); } @@ -2207,6 +2209,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) struct macb_queue *queue = dev_id; struct macb *bp = queue->bp; struct net_device *netdev = bp->netdev; + bool hresp_err = false; u32 status; status = queue_readl(queue, ISR); @@ -2253,15 +2256,22 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) napi_schedule_irqoff(&queue->napi_tx); } - if (unlikely(status & MACB_INT_MISC_FLAGS)) + if (unlikely(status & MACB_INT_MISC_FLAGS)) { if (macb_interrupt_misc(queue, status)) break; + if (status & MACB_BIT(HRESP)) + hresp_err = true; + } + status = queue_readl(queue, ISR); } spin_unlock(&bp->lock); + if (hresp_err) + netdev_err(netdev, "DMA bus error: HRESP not OK\n"); + return IRQ_HANDLED; } From 1a2dbdb6602a668f87d243261ece58f297a6e528 Mon Sep 17 00:00:00 2001 From: David Yang Date: Wed, 30 Sep 2026 22:11:48 +0800 Subject: [PATCH 1120/2126] net: dsa: motorcomm: Fix register rollback in LED setup The LED error path writes back a stale snapshot of the whole words taken before the class device registration, silently reverting LED2 state of sibling LED groups already registered and reachable from sysfs. Although the odds are very small, fix it by reverting this group's fields only for correctness. Fixes: 9af9a8168213 ("net: dsa: motorcomm: Add LED support") Signed-off-by: David Yang Link: https://patch.msgid.link/20260930141151.3973221-1-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/leds.c | 69 +++++++++++++++++++------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c index 6613fe3b0471..c97b560299d6 100644 --- a/drivers/net/dsa/motorcomm/leds.c +++ b/drivers/net/dsa/motorcomm/leds.c @@ -420,13 +420,15 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, char name[LED_MAX_NAME_SIZE]; enum led_default_state state; struct yt921x_led *led; + int polarity_orig; bool force_high; bool force_low; - u32 led2_val; - u32 inv_val; + u32 led2_orig; + int polarity; u32 group; u32 mask; u32 ctrl; + u32 val; bool on; int res; int ret; @@ -452,6 +454,7 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, port, group); return -EINVAL; } + polarity = force_high ? 1 : force_low ? -1 : 0; led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); if (!led) { @@ -470,23 +473,27 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, /* Inversion is internal - force on will give low logic. * In the rest of the file, treat LEDs as if active-low. */ - inv_val = U32_MAX; - if (force_high || force_low) { - res = yt921x_reg_read(priv, YT921X_LED_PAR_INV, &inv_val); + polarity_orig = 0; + if (polarity) { + res = yt921x_reg_read(priv, YT921X_LED_PAR_INV, &val); if (res) - goto revoke_inv; + goto err_inv; mask = YT921X_LED_PAR_INV_INVnm(group, port); - ctrl = force_high ? inv_val | mask : inv_val & ~mask; - res = yt921x_reg_write(priv, YT921X_LED_PAR_INV, ctrl); - if (res) - goto revoke_inv; + ctrl = polarity > 0 ? val | mask : val & ~mask; + if (ctrl != val) { + res = yt921x_reg_write(priv, YT921X_LED_PAR_INV, ctrl); + if (res) + goto err_inv; + + polarity_orig = -polarity; + } } - led2_val = U32_MAX; - res = yt921x_reg_read(priv, YT921X_LED2_PORTn(port), &led2_val); + led2_orig = U32_MAX; + res = yt921x_reg_read(priv, YT921X_LED2_PORTn(port), &val); if (res) - goto revoke_led2; + goto err_led2; mask = YT921X_LED2_PORT_FORCEn_M(group); switch (state) { @@ -494,16 +501,20 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, case LEDS_DEFSTATE_ON: default: on = state == LEDS_DEFSTATE_ON; - ctrl = on ? YT921X_LED2_PORT_FORCEn_ON(group) : - YT921X_LED2_PORT_FORCEn_OFF(group); - res = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), - (led2_val & ~mask) | ctrl); - if (res) - goto revoke_led2; + ctrl = (val & ~mask) | + (on ? YT921X_LED2_PORT_FORCEn_ON(group) : + YT921X_LED2_PORT_FORCEn_OFF(group)); + if (ctrl != val) { + res = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), + ctrl); + if (res) + goto err_led2; + + led2_orig = val & mask; + } break; case LEDS_DEFSTATE_KEEP: - on = (led2_val & mask) == YT921X_LED2_PORT_FORCEn_ON(group); - led2_val = U32_MAX; + on = (val & mask) == YT921X_LED2_PORT_FORCEn_ON(group); break; } @@ -539,22 +550,26 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, revoke: mutex_lock(&priv->reg_lock); -revoke_led2: - if (led2_val != U32_MAX) { - ret = yt921x_reg_write(priv, YT921X_LED2_PORTn(port), led2_val); + if (led2_orig != U32_MAX) { + ret = yt921x_reg_update_bits(priv, YT921X_LED2_PORTn(port), + YT921X_LED2_PORT_FORCEn_M(group), + led2_orig); if (ret) dev_err(dev, "Failed to restore %s for LED %02d:%02u: %d\n", "LED2_PORT", port, group, ret); } -revoke_inv: - if (inv_val != U32_MAX) { - ret = yt921x_reg_write(priv, YT921X_LED_PAR_INV, inv_val); +err_led2: + if (polarity_orig) { + ret = yt921x_reg_toggle_bits(priv, YT921X_LED_PAR_INV, + YT921X_LED_PAR_INV_INVnm(group, port), + polarity_orig > 0); if (ret) dev_err(dev, "Failed to restore %s for LED %02d:%02u: %d\n", "LED_PAR_INV", port, group, ret); } +err_inv: mutex_unlock(&priv->reg_lock); pp->leds[group] = NULL; From 82e2c7db0830d67d335ed4d1174fb2a9a2becb34 Mon Sep 17 00:00:00 2001 From: Alexander Sverdlin Date: Tue, 29 Sep 2026 14:51:41 +0200 Subject: [PATCH 1121/2126] net: dsa: mxl-gsw1xx: force internal PHYs into a known reset state When bootstrapped with PS_NOWAIT = 0 the internal PHYs stay held in reset, so the driver only worked with PS_NOWAIT = 1 where they are released automatically. Add a ->setup() hook, run before the MDIO bus is registered so PHY IDs are readable during the bus scan, that programs the RST_REQ PHY reset lines: release the PHYs of used ports and hold all other internal PHYs in reset. Driving both directions yields the same state regardless of the PS_NOWAIT bootstrap and keeps unused PHYs from staying powered. A single 300ms settle delay is applied only when at least one PHY is released. Signed-off-by: Alexander Sverdlin Link: https://patch.msgid.link/20260929125143.2890583-1-alexander.sverdlin@siemens.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lantiq/lantiq_gswip.h | 2 ++ drivers/net/dsa/lantiq/lantiq_gswip_common.c | 10 ++++++ drivers/net/dsa/lantiq/mxl-gsw1xx.c | 35 ++++++++++++++++++++ drivers/net/dsa/lantiq/mxl-gsw1xx.h | 2 ++ 4 files changed, 49 insertions(+) diff --git a/drivers/net/dsa/lantiq/lantiq_gswip.h b/drivers/net/dsa/lantiq/lantiq_gswip.h index 0b75be14dc10..4f95877c59d1 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip.h +++ b/drivers/net/dsa/lantiq/lantiq_gswip.h @@ -261,6 +261,8 @@ struct gswip_hw_info { const struct gswip_pce_microcode (*pce_microcode)[]; size_t pce_microcode_size; enum dsa_tag_protocol tag_protocol; + + int (*setup)(struct dsa_switch *ds); void (*phylink_get_caps)(struct dsa_switch *ds, int port, struct phylink_config *config); struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config, diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c index 20ed487f37ca..5bb5f4ab4cbf 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c @@ -689,6 +689,16 @@ static int gswip_setup(struct dsa_switch *ds) */ regmap_write(priv->mdio, GSWIP_MDIO_MDC_CFG0, 0x0); + /* GSW1xx will wake up the PHYs here, so it makes sense that it happens + * after the auto-polling deactivation above, but before the MDIO bus + * registration below + */ + if (priv->hw_info->setup) { + err = priv->hw_info->setup(ds); + if (err) + return err; + } + /* Configure the MDIO Clock 2.5 MHz */ regmap_write_bits(priv->mdio, GSWIP_MDIO_MDC_CFG1, 0xff, 0x09); diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.c b/drivers/net/dsa/lantiq/mxl-gsw1xx.c index 66bf7e331905..a26f78e1a44c 100644 --- a/drivers/net/dsa/lantiq/mxl-gsw1xx.c +++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.c @@ -589,6 +589,37 @@ static void gsw150_phylink_get_caps(struct dsa_switch *ds, int port, gsw1xx_phylink_get_lpi_caps(config); } +static int gsw1xx_setup(struct dsa_switch *ds) +{ + struct gsw1xx_priv *priv = container_of(ds->priv, struct gsw1xx_priv, gswip); + struct gswip_priv *gswip_priv = ds->priv; + u32 active_mask = 0; + u32 phy_mask = 0; + int port, ret; + + for (port = 0; port < gswip_priv->hw_info->max_ports; port++) { + struct phylink_config cfg = {}; + + gswip_priv->hw_info->phylink_get_caps(ds, port, &cfg); + if (!test_bit(PHY_INTERFACE_MODE_INTERNAL, cfg.supported_interfaces)) + break; + + phy_mask |= GSW1XX_RST_REQ_PHY(port); + + if (!dsa_is_unused_port(ds, port)) + active_mask |= GSW1XX_RST_REQ_PHY(port); + } + + ret = regmap_update_bits(priv->shell, GSW1XX_SHELL_RST_REQ, phy_mask, ~active_mask); + if (ret) + return ret; + + if (active_mask) + msleep(300); + + return 0; +} + static struct phylink_pcs *gsw1xx_phylink_mac_select_pcs(struct phylink_config *config, phy_interface_t interface) { @@ -830,6 +861,7 @@ static const struct gswip_hw_info gsw12x_data = { [GSW1XX_MII_PORT] = GSWIP_MII_PCDU0, [GSW1XX_MII_PORT + 1 ... GSWIP_MAX_PORTS - 1] = -1, }, + .setup = gsw1xx_setup, .mac_select_pcs = gsw1xx_phylink_mac_select_pcs, .phylink_get_caps = &gsw1xx_phylink_get_caps, .supports_2500m = true, @@ -852,6 +884,7 @@ static const struct gswip_hw_info gsw140_data = { [GSW1XX_MII_PORT] = GSWIP_MII_PCDU0, [GSW1XX_MII_PORT + 1 ... GSWIP_MAX_PORTS - 1] = -1, }, + .setup = gsw1xx_setup, .mac_select_pcs = gsw1xx_phylink_mac_select_pcs, .phylink_get_caps = &gsw1xx_phylink_get_caps, .supports_2500m = true, @@ -874,6 +907,7 @@ static const struct gswip_hw_info gsw141_data = { [GSW1XX_MII_PORT] = GSWIP_MII_PCDU0, [GSW1XX_MII_PORT + 1 ... GSWIP_MAX_PORTS - 1] = -1, }, + .setup = gsw1xx_setup, .mac_select_pcs = gsw1xx_phylink_mac_select_pcs, .phylink_get_caps = gsw1xx_phylink_get_caps, .port_setup = gsw1xx_port_setup, @@ -895,6 +929,7 @@ static const struct gswip_hw_info gsw150_data = { [5] = 1, [6] = 11, }, + .setup = gsw1xx_setup, .phylink_get_caps = gsw150_phylink_get_caps, /* There is only a single RGMII_SLEW_CFG register in GSW150 and it is * unknown if RGMII slew configuration affects both RGMII ports diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.h b/drivers/net/dsa/lantiq/mxl-gsw1xx.h index caa8f1008587..81bc00eabbfb 100644 --- a/drivers/net/dsa/lantiq/mxl-gsw1xx.h +++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.h @@ -110,6 +110,8 @@ #define GSW1XX_SHELL_BASE 0xfa00 #define GSW1XX_SHELL_RST_REQ 0x01 #define GSW1XX_RST_REQ_SGMII_SHELL BIT(5) +/* Valid only for internal-PHY ports (vary per switch type) */ +#define GSW1XX_RST_REQ_PHY(p) BIT(p) #define GSW1XX_SHELL_MANU_ID 0x10 #define GSW1XX_SHELL_MANU_ID_PNUML GENMASK(15, 12) #define GSW1XX_SHELL_MANU_ID_MANID GENMASK(11, 1) From 130634764549aa3c4745ee96db57443ded848611 Mon Sep 17 00:00:00 2001 From: Harshitha Ramamurthy Date: Wed, 30 Sep 2026 19:04:17 +0000 Subject: [PATCH 1122/2126] gve: add struct gve_device_info to hold device properties In the current AdminQ mode, device properties are written into struct gve_device_descriptor that is allocated in shared memory between the driver and device. In the upcoming MailboxQ mode, these properties will be returned in the response of a mailbox message. Hence, add struct gve_device_info as the structure that holds all the properties that are negotiated with the device in either mode. Change the AdminQ mode method gve_adminq_describe_device() and its children to fill up device information into this newly introduced struct gve_device_info. Move a few helper functions and code that set device properties in the priv structure into gve_init_priv(). So now gve_init_priv() calls/does the following: - gve_set_mtu() - gve_set_mac() - gve_set_queue_properties() - gve_set_buf_sizes() - set flow steering and RSS properties - set other priv properties When MailboxQ support is added, device information will be filled into the same structure and the same gve_init_priv() path would be used to set device properties to ensure common code reusage. Most of these changes are refactors only, except for one: with the introduction of the central struct gve_device_info, in AdminQ mode, gve_set_mtu() now validates the final max mtu: the mtu from the device descriptor, or the jumbo frames device option value when it is present. Previously only the descriptor mtu was validated. This sets up the driver nicely for the MailboxQ mode where both the default and the maximum mtu are provided at once and they are validated in gve_set_mtu(). Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-2-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 29 +++++ drivers/net/ethernet/google/gve/gve_adminq.c | 128 +++++++++++-------- drivers/net/ethernet/google/gve/gve_adminq.h | 6 - drivers/net/ethernet/google/gve/gve_main.c | 86 +++++++++---- 4 files changed, 169 insertions(+), 80 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index c280ff35ee77..021adb9108df 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -797,6 +797,34 @@ struct gve_ptp { struct gve_priv *priv; }; +struct gve_device_info { + enum gve_queue_format queue_format; + u16 default_tx_queues; + u16 default_rx_queues; + u16 max_tx_queues; + u16 max_rx_queues; + u16 default_tx_ring_size; + u16 default_rx_ring_size; + u16 max_tx_ring_size; + u16 max_rx_ring_size; + u16 min_tx_ring_size; + u16 min_rx_ring_size; + u16 max_mtu; + u8 mac[ETH_ALEN]; + u16 max_rx_buffer_size; + u16 header_buf_size; + u32 max_flow_rules; + u16 rss_key_size; + u16 rss_lut_size; + u16 tx_pages_per_qpl; + u16 num_event_counters; + u64 max_registered_pages; + bool default_min_ring_size; + bool nic_timestamp_supported; + bool modify_ring_size_enabled; + bool cache_rss_config; +}; + struct gve_priv { struct net_device *dev; struct gve_tx_ring *tx; /* array of tx_cfg.num_queues */ @@ -929,6 +957,7 @@ struct gve_priv { struct gve_nic_ts_report *nic_ts_report; dma_addr_t nic_ts_report_bus; u64 last_sync_nic_counter; /* Clock counter from last NIC TS report */ + struct gve_device_info device_info; }; enum gve_service_task_flags_bit { diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index f05f4895f4c7..512349c5517f 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -70,7 +70,7 @@ void gve_parse_device_option(struct gve_priv *priv, dev_info(&priv->pdev->dev, "Gqi raw addressing device option enabled.\n"); - priv->queue_format = GVE_GQI_RDA_FORMAT; + priv->device_info.queue_format = GVE_GQI_RDA_FORMAT; break; case GVE_DEV_OPT_ID_GQI_RDA: if (option_length < sizeof(**dev_op_gqi_rda) || @@ -190,7 +190,7 @@ void gve_parse_device_option(struct gve_priv *priv, /* device has not provided min ring size */ if (option_length == GVE_DEVICE_OPTION_NO_MIN_RING_SIZE) - priv->default_min_ring_size = true; + priv->device_info.default_min_ring_size = true; break; case GVE_DEV_OPT_ID_FLOW_STEERING: if (option_length < sizeof(**dev_op_flow_steering) || @@ -922,10 +922,13 @@ out: static void gve_set_default_rss_sizes(struct gve_priv *priv) { - if (!gve_is_gqi(priv)) { - priv->rss_key_size = GVE_RSS_KEY_SIZE; - priv->rss_lut_size = GVE_RSS_INDIR_SIZE; - priv->cache_rss_config = true; + struct gve_device_info *device_info = &priv->device_info; + + if (device_info->queue_format == GVE_DQO_RDA_FORMAT || + device_info->queue_format == GVE_DQO_QPL_FORMAT) { + device_info->rss_key_size = GVE_RSS_KEY_SIZE; + device_info->rss_lut_size = GVE_RSS_INDIR_SIZE; + device_info->cache_rss_config = true; } } @@ -946,77 +949,105 @@ static void gve_enable_supported_features(struct gve_priv *priv, const struct gve_device_option_modify_ring *dev_op_modify_ring) { + struct gve_device_info *info = &priv->device_info; + /* Before control reaches this point, the page-size-capped max MTU from * the gve_device_descriptor field has already been stored in - * priv->dev->max_mtu. We overwrite it with the true max MTU below. + * device_info->max_mtu. We overwrite it with the true max MTU below. */ if (dev_op_jumbo_frames && (supported_features_mask & GVE_SUP_JUMBO_FRAMES_MASK)) { dev_info(&priv->pdev->dev, "JUMBO FRAMES device option enabled.\n"); - priv->dev->max_mtu = be16_to_cpu(dev_op_jumbo_frames->max_mtu); + info->max_mtu = be16_to_cpu(dev_op_jumbo_frames->max_mtu); } if (dev_op_buffer_sizes && (supported_features_mask & GVE_SUP_BUFFER_SIZES_MASK)) { - priv->max_rx_buffer_size = + info->max_rx_buffer_size = be16_to_cpu(dev_op_buffer_sizes->packet_buffer_size); - priv->header_buf_size = + info->header_buf_size = be16_to_cpu(dev_op_buffer_sizes->header_buffer_size); dev_info(&priv->pdev->dev, "BUFFER SIZES device option enabled with max_rx_buffer_size of %u, header_buf_size of %u.\n", - priv->max_rx_buffer_size, priv->header_buf_size); - if (gve_is_dqo(priv) && - priv->max_rx_buffer_size > GVE_DEFAULT_RX_BUFFER_SIZE) - priv->rx_cfg.packet_buffer_size = - priv->max_rx_buffer_size; + info->max_rx_buffer_size, info->header_buf_size); } /* Read and store ring size ranges given by device */ if (dev_op_modify_ring && (supported_features_mask & GVE_SUP_MODIFY_RING_MASK)) { - priv->modify_ring_size_enabled = true; - priv->max_rx_desc_cnt = + info->modify_ring_size_enabled = true; + info->max_rx_ring_size = be16_to_cpu(dev_op_modify_ring->max_rx_ring_size); - priv->max_tx_desc_cnt = + info->max_tx_ring_size = be16_to_cpu(dev_op_modify_ring->max_tx_ring_size); - if (priv->default_min_ring_size) { + if (info->default_min_ring_size) { /* If device hasn't provided minimums, use default minimums */ - priv->min_tx_desc_cnt = GVE_DEFAULT_MIN_TX_RING_SIZE; - priv->min_rx_desc_cnt = GVE_DEFAULT_MIN_RX_RING_SIZE; + info->min_tx_ring_size = GVE_DEFAULT_MIN_TX_RING_SIZE; + info->min_rx_ring_size = GVE_DEFAULT_MIN_RX_RING_SIZE; } else { - priv->min_rx_desc_cnt = be16_to_cpu(dev_op_modify_ring->min_rx_ring_size); - priv->min_tx_desc_cnt = be16_to_cpu(dev_op_modify_ring->min_tx_ring_size); + info->min_rx_ring_size = + be16_to_cpu(dev_op_modify_ring->min_rx_ring_size); + info->min_tx_ring_size = + be16_to_cpu(dev_op_modify_ring->min_tx_ring_size); } } if (dev_op_flow_steering && (supported_features_mask & GVE_SUP_FLOW_STEERING_MASK)) { if (dev_op_flow_steering->max_flow_rules) { - priv->max_flow_rules = + info->max_flow_rules = be32_to_cpu(dev_op_flow_steering->max_flow_rules); - priv->dev->hw_features |= NETIF_F_NTUPLE; dev_info(&priv->pdev->dev, "FLOW STEERING device option enabled with max rule limit of %u.\n", - priv->max_flow_rules); + info->max_flow_rules); } } if (dev_op_rss_config && (supported_features_mask & GVE_SUP_RSS_CONFIG_MASK)) { - priv->rss_key_size = + info->rss_key_size = be16_to_cpu(dev_op_rss_config->hash_key_size); - priv->rss_lut_size = + info->rss_lut_size = be16_to_cpu(dev_op_rss_config->hash_lut_size); - priv->cache_rss_config = false; + info->cache_rss_config = false; dev_dbg(&priv->pdev->dev, "RSS device option enabled with key size of %u, lut size of %u.\n", - priv->rss_key_size, priv->rss_lut_size); + info->rss_key_size, info->rss_lut_size); } if (dev_op_nic_timestamp && (supported_features_mask & GVE_SUP_NIC_TIMESTAMP_MASK)) - priv->nic_timestamp_supported = true; + info->nic_timestamp_supported = true; +} + +static void gve_fill_device_info(struct gve_priv *priv, + struct gve_device_descriptor *descriptor) +{ + struct gve_device_info *device_info = &priv->device_info; + u16 default_num_queues; + + device_info->tx_pages_per_qpl = + be16_to_cpu(descriptor->tx_pages_per_qpl); + device_info->max_registered_pages = + be64_to_cpu(descriptor->max_registered_pages); + device_info->num_event_counters = be16_to_cpu(descriptor->counters); + ether_addr_copy(device_info->mac, descriptor->mac); + device_info->max_mtu = be16_to_cpu(descriptor->mtu); + + default_num_queues = be16_to_cpu(descriptor->default_num_queues); + device_info->default_tx_queues = default_num_queues; + device_info->default_rx_queues = default_num_queues; + device_info->default_tx_ring_size = + be16_to_cpu(descriptor->tx_queue_entries); + device_info->default_rx_ring_size = + be16_to_cpu(descriptor->rx_queue_entries); + + /* set default ranges */ + device_info->max_tx_ring_size = device_info->default_tx_ring_size; + device_info->max_rx_ring_size = device_info->default_rx_ring_size; + device_info->min_tx_ring_size = device_info->default_tx_ring_size; + device_info->min_rx_ring_size = device_info->default_rx_ring_size; } int gve_adminq_describe_device(struct gve_priv *priv) @@ -1027,6 +1058,7 @@ int gve_adminq_describe_device(struct gve_priv *priv) struct gve_device_option_jumbo_frames *dev_op_jumbo_frames = NULL; struct gve_device_option_modify_ring *dev_op_modify_ring = NULL; struct gve_device_option_rss_config *dev_op_rss_config = NULL; + struct gve_device_info *device_info = &priv->device_info; struct gve_device_option_gqi_rda *dev_op_gqi_rda = NULL; struct gve_device_option_gqi_qpl *dev_op_gqi_qpl = NULL; struct gve_device_option_dqo_rda *dev_op_dqo_rda = NULL; @@ -1070,26 +1102,26 @@ int gve_adminq_describe_device(struct gve_priv *priv) * DqoRda, DqoQpl, GqiRda, GqiQpl. Use GqiQpl as default. */ if (dev_op_dqo_rda) { - priv->queue_format = GVE_DQO_RDA_FORMAT; + device_info->queue_format = GVE_DQO_RDA_FORMAT; dev_info(&priv->pdev->dev, "Driver is running with DQO RDA queue format.\n"); supported_features_mask = be32_to_cpu(dev_op_dqo_rda->supported_features_mask); } else if (dev_op_dqo_qpl) { - priv->queue_format = GVE_DQO_QPL_FORMAT; + device_info->queue_format = GVE_DQO_QPL_FORMAT; supported_features_mask = be32_to_cpu(dev_op_dqo_qpl->supported_features_mask); } else if (dev_op_gqi_rda) { - priv->queue_format = GVE_GQI_RDA_FORMAT; + device_info->queue_format = GVE_GQI_RDA_FORMAT; dev_info(&priv->pdev->dev, "Driver is running with GQI RDA queue format.\n"); supported_features_mask = be32_to_cpu(dev_op_gqi_rda->supported_features_mask); - } else if (priv->queue_format == GVE_GQI_RDA_FORMAT) { + } else if (device_info->queue_format == GVE_GQI_RDA_FORMAT) { dev_info(&priv->pdev->dev, "Driver is running with GQI RDA queue format.\n"); } else { - priv->queue_format = GVE_GQI_QPL_FORMAT; + device_info->queue_format = GVE_GQI_QPL_FORMAT; if (dev_op_gqi_qpl) supported_features_mask = be32_to_cpu(dev_op_gqi_qpl->supported_features_mask); @@ -1097,18 +1129,9 @@ int gve_adminq_describe_device(struct gve_priv *priv) "Driver is running with GQI QPL queue format.\n"); } + gve_fill_device_info(priv, descriptor); gve_set_default_rss_sizes(priv); - err = gve_set_mtu(priv, descriptor); - if (err) - goto free_device_descriptor; - - priv->num_event_counters = be16_to_cpu(descriptor->counters); - - gve_set_mac(priv, descriptor); - - gve_set_queue_properties(priv, descriptor); - gve_enable_supported_features(priv, supported_features_mask, dev_op_jumbo_frames, dev_op_dqo_qpl, dev_op_buffer_sizes, dev_op_flow_steering, @@ -1595,6 +1618,8 @@ int gve_set_num_ntfy_blks(struct gve_priv *priv) void gve_set_num_queues(struct gve_priv *priv) { + struct gve_device_info *device_info = &priv->device_info; + priv->tx_cfg.max_queues = min_t(int, priv->tx_cfg.max_queues, priv->num_ntfy_blks / 2); priv->rx_cfg.max_queues = @@ -1602,10 +1627,13 @@ void gve_set_num_queues(struct gve_priv *priv) priv->tx_cfg.num_queues = priv->tx_cfg.max_queues; priv->rx_cfg.num_queues = priv->rx_cfg.max_queues; - if (priv->default_num_queues > 0) { - priv->tx_cfg.num_queues = min_t(int, priv->default_num_queues, + if (device_info->default_tx_queues > 0) + priv->tx_cfg.num_queues = min_t(int, + device_info->default_tx_queues, priv->tx_cfg.num_queues); - priv->rx_cfg.num_queues = min_t(int, priv->default_num_queues, + + if (device_info->default_rx_queues > 0) + priv->rx_cfg.num_queues = min_t(int, + device_info->default_rx_queues, priv->rx_cfg.num_queues); - } } diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 68c63ce75505..a17af755b454 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -658,10 +658,4 @@ int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv, struct gve_ptype_lut *ptype_lut); int gve_set_num_ntfy_blks(struct gve_priv *priv); void gve_set_num_queues(struct gve_priv *priv); -void gve_set_queue_properties(struct gve_priv *priv, - struct gve_device_descriptor *descriptor); -int gve_set_mtu(struct gve_priv *priv, - struct gve_device_descriptor *descriptor); -void gve_set_mac(struct gve_priv *priv, - struct gve_device_descriptor *descriptor); #endif /* _GVE_ADMINQ_H */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 9cc343a16271..d3882de584e3 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -2398,57 +2398,71 @@ static const struct xdp_metadata_ops gve_xdp_metadata_ops = { .xmo_rx_timestamp = gve_xdp_rx_timestamp, }; -static void gve_set_default_desc_cnt(struct gve_priv *priv, - const struct gve_device_descriptor *descriptor) +static void gve_set_desc_cnt(struct gve_priv *priv) { - priv->tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries); - priv->rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries); + struct gve_device_info *device_info = &priv->device_info; - /* set default ranges */ - priv->max_tx_desc_cnt = priv->tx_desc_cnt; - priv->max_rx_desc_cnt = priv->rx_desc_cnt; - priv->min_tx_desc_cnt = priv->tx_desc_cnt; - priv->min_rx_desc_cnt = priv->rx_desc_cnt; + priv->tx_desc_cnt = device_info->default_tx_ring_size; + priv->rx_desc_cnt = device_info->default_rx_ring_size; + priv->max_tx_desc_cnt = device_info->max_tx_ring_size; + priv->max_rx_desc_cnt = device_info->max_rx_ring_size; + priv->min_tx_desc_cnt = device_info->min_tx_ring_size; + priv->min_rx_desc_cnt = device_info->min_rx_ring_size; } -void gve_set_queue_properties(struct gve_priv *priv, - struct gve_device_descriptor *descriptor) +static void gve_set_queue_properties(struct gve_priv *priv) { - /* set default descriptor counts */ - gve_set_default_desc_cnt(priv, descriptor); + struct gve_device_info *device_info = &priv->device_info; - priv->max_registered_pages = be64_to_cpu(descriptor->max_registered_pages); - priv->tx_pages_per_qpl = be16_to_cpu(descriptor->tx_pages_per_qpl); - priv->default_num_queues = be16_to_cpu(descriptor->default_num_queues); + gve_set_desc_cnt(priv); + priv->max_registered_pages = device_info->max_registered_pages; + priv->tx_pages_per_qpl = device_info->tx_pages_per_qpl; } -int gve_set_mtu(struct gve_priv *priv, - struct gve_device_descriptor *descriptor) +static int gve_set_mtu(struct gve_priv *priv) { + struct gve_device_info *device_info = &priv->device_info; u16 mtu; - mtu = be16_to_cpu(descriptor->mtu); + mtu = device_info->max_mtu; if (mtu < ETH_MIN_MTU) { dev_err(&priv->pdev->dev, "MTU %d below minimum MTU\n", mtu); return -EINVAL; } priv->dev->max_mtu = mtu; + priv->dev->mtu = mtu; return 0; } -void gve_set_mac(struct gve_priv *priv, - struct gve_device_descriptor *descriptor) +static void gve_set_mac(struct gve_priv *priv) { + struct gve_device_info *device_info = &priv->device_info; u8 *mac; - mac = descriptor->mac; + mac = device_info->mac; eth_hw_addr_set(priv->dev, mac); dev_info(&priv->pdev->dev, "MAC addr: %pM\n", mac); } +static void gve_set_buf_sizes(struct gve_priv *priv) +{ + struct gve_device_info *device_info = &priv->device_info; + + if (device_info->max_rx_buffer_size) + priv->max_rx_buffer_size = device_info->max_rx_buffer_size; + + if (gve_is_dqo(priv) && + priv->max_rx_buffer_size > GVE_DEFAULT_RX_BUFFER_SIZE) + priv->rx_cfg.packet_buffer_size = priv->max_rx_buffer_size; + + if (device_info->header_buf_size) + priv->header_buf_size = device_info->header_buf_size; +} + static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) { + struct gve_device_info *device_info = &priv->device_info; int err; /* Set up the adminq */ @@ -2471,7 +2485,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) if (skip_describe_device) goto setup_device; - priv->queue_format = GVE_QUEUE_FORMAT_UNSPECIFIED; + device_info->queue_format = GVE_QUEUE_FORMAT_UNSPECIFIED; /* Get the initial information we need from the device */ err = gve_adminq_describe_device(priv); if (err) { @@ -2480,6 +2494,8 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) goto err; } + priv->queue_format = priv->device_info.queue_format; + err = gve_set_num_ntfy_blks(priv); if (err) { dev_err(&priv->pdev->dev, @@ -2507,12 +2523,34 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) netif_set_tso_max_size(priv->dev, GVE_DQO_TX_MAX); } - priv->dev->mtu = priv->dev->max_mtu; + if (gve_set_mtu(priv)) { + err = -EINVAL; + goto err; + } + + priv->num_event_counters = device_info->num_event_counters; + + gve_set_mac(priv); + + gve_set_queue_properties(priv); + priv->modify_ring_size_enabled = device_info->modify_ring_size_enabled; + + gve_set_buf_sizes(priv); + + priv->max_flow_rules = device_info->max_flow_rules; + if (priv->max_flow_rules) + priv->dev->hw_features |= NETIF_F_NTUPLE; + + priv->rss_key_size = device_info->rss_key_size; + priv->rss_lut_size = device_info->rss_lut_size; + priv->cache_rss_config = device_info->cache_rss_config; + priv->numa_node = dev_to_node(&priv->pdev->dev); priv->tx_cfg.num_xdp_queues = 0; priv->rx_copybreak = GVE_DEFAULT_RX_COPYBREAK; priv->ts_config.tx_type = HWTSTAMP_TX_OFF; priv->ts_config.rx_filter = HWTSTAMP_FILTER_NONE; + priv->nic_timestamp_supported = device_info->nic_timestamp_supported; setup_device: priv->xsk_pools = bitmap_zalloc(priv->rx_cfg.max_queues, GFP_KERNEL); From d6194e4eaff92cc8a432eb5cb5376976bb272b9b Mon Sep 17 00:00:00 2001 From: Harshitha Ramamurthy Date: Wed, 30 Sep 2026 19:04:18 +0000 Subject: [PATCH 1123/2126] gve: introduce control plane operations structure To abstract out the difference in implementation of control plane operations between the existing Adminq ABI and the upcoming Mailbox ABI, introduce a new gve_ctrl_ops structure which will contain the basic operations. At probe, these ops will be set based on the ABI and the corresponding ops will be called in relevant places. As of this patch, only Adminq ops are set. In future patches, corresponding ops will be set for the new mailbox mode. Implement a ctrl op to map/unmap the doorbell bar. Since this functionality has moved to a control op, call this op after control ops are set for AdminQ mode. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-3-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 11 +++++++ drivers/net/ethernet/google/gve/gve_adminq.c | 21 ++++++++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 2 ++ drivers/net/ethernet/google/gve/gve_main.c | 34 +++++++++++--------- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 021adb9108df..56148ea3cfbf 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -825,6 +825,16 @@ struct gve_device_info { bool cache_rss_config; }; +/** + * struct gve_ctrl_ops - Control plane operations structure + * @map_db_bar: Maps the doorbell BAR for the device and store in @priv. + * @unmap_db_bar: Unmaps the doorbell BAR previously mapped by @map_db_bar. + */ +struct gve_ctrl_ops { + int (*map_db_bar)(struct gve_priv *priv); + void (*unmap_db_bar)(struct gve_priv *priv); +}; + struct gve_priv { struct net_device *dev; struct gve_tx_ring *tx; /* array of tx_cfg.num_queues */ @@ -958,6 +968,7 @@ struct gve_priv { dma_addr_t nic_ts_report_bus; u64 last_sync_nic_counter; /* Clock counter from last NIC TS report */ struct gve_device_info device_info; + const struct gve_ctrl_ops *ctrl_ops; }; enum gve_service_task_flags_bit { diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 512349c5517f..08d8e49d563e 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1637,3 +1637,24 @@ void gve_set_num_queues(struct gve_priv *priv) device_info->default_rx_queues, priv->rx_cfg.num_queues); } + +int gve_adminq_map_db_bar(struct gve_priv *priv) +{ + struct pci_dev *pdev = priv->pdev; + void __iomem *db_bar; + + db_bar = pci_iomap(pdev, GVE_DOORBELL_BAR, 0); + if (!db_bar) { + dev_err(&pdev->dev, "Failed to map doorbell bar!\n"); + return -ENOMEM; + } + priv->db_bar2 = db_bar; + return 0; +} + +void gve_adminq_unmap_db_bar(struct gve_priv *priv) +{ + struct pci_dev *pdev = priv->pdev; + + pci_iounmap(pdev, priv->db_bar2); +} diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index a17af755b454..93d3cabb67f1 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -658,4 +658,6 @@ int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv, struct gve_ptype_lut *ptype_lut); int gve_set_num_ntfy_blks(struct gve_priv *priv); void gve_set_num_queues(struct gve_priv *priv); +int gve_adminq_map_db_bar(struct gve_priv *priv); +void gve_adminq_unmap_db_bar(struct gve_priv *priv); #endif /* _GVE_ADMINQ_H */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index d3882de584e3..d721347e54b4 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -2460,6 +2460,11 @@ static void gve_set_buf_sizes(struct gve_priv *priv) priv->header_buf_size = device_info->header_buf_size; } +static const struct gve_ctrl_ops gve_adminq_ops = { + .map_db_bar = gve_adminq_map_db_bar, + .unmap_db_bar = gve_adminq_unmap_db_bar, +}; + static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) { struct gve_device_info *device_info = &priv->device_info; @@ -2861,7 +2866,6 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { int max_tx_queues, max_rx_queues; struct net_device *dev; - __be32 __iomem *db_bar; struct gve_registers __iomem *reg_bar; struct gve_priv *priv; int err; @@ -2889,13 +2893,6 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto abort_with_pci_region; } - db_bar = pci_iomap(pdev, GVE_DOORBELL_BAR, 0); - if (!db_bar) { - dev_err(&pdev->dev, "Failed to map doorbell bar!\n"); - err = -ENOMEM; - goto abort_with_reg_bar; - } - gve_write_version(®_bar->driver_version); /* Get max queues to alloc etherdev */ max_tx_queues = ioread32be(®_bar->max_tx_queues); @@ -2905,7 +2902,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (!dev) { dev_err(&pdev->dev, "could not allocate netdev\n"); err = -ENOMEM; - goto abort_with_db_bar; + goto abort_with_reg_bar; } SET_NETDEV_DEV(dev, &pdev->dev); pci_set_drvdata(pdev, dev); @@ -2937,19 +2934,25 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->pdev = pdev; priv->msg_enable = DEFAULT_MSG_LEVEL; priv->reg_bar0 = reg_bar; - priv->db_bar2 = db_bar; priv->service_task_flags = 0x0; priv->state_flags = 0x0; priv->ethtool_flags = 0x0; priv->rx_cfg.packet_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE; priv->max_rx_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE; + /* Set adminq ctrl ops */ + priv->ctrl_ops = &gve_adminq_ops; + + err = priv->ctrl_ops->map_db_bar(priv); + if (err) + goto abort_with_netdev; + gve_set_probe_in_progress(priv); priv->gve_wq = alloc_ordered_workqueue("gve", 0); if (!priv->gve_wq) { dev_err(&pdev->dev, "Could not allocate workqueue"); err = -ENOMEM; - goto abort_with_netdev; + goto abort_with_unmap_db_bar; } INIT_WORK(&priv->service_task, gve_service_task); INIT_WORK(&priv->stats_report_task, gve_stats_report_task); @@ -2979,12 +2982,12 @@ abort_with_gve_init: abort_with_wq: destroy_workqueue(priv->gve_wq); +abort_with_unmap_db_bar: + priv->ctrl_ops->unmap_db_bar(priv); + abort_with_netdev: free_netdev(dev); -abort_with_db_bar: - pci_iounmap(pdev, db_bar); - abort_with_reg_bar: pci_iounmap(pdev, reg_bar); @@ -3000,14 +3003,13 @@ static void gve_remove(struct pci_dev *pdev) { struct net_device *netdev = pci_get_drvdata(pdev); struct gve_priv *priv = netdev_priv(netdev); - __be32 __iomem *db_bar = priv->db_bar2; void __iomem *reg_bar = priv->reg_bar0; unregister_netdev(netdev); gve_teardown_priv_resources(priv); destroy_workqueue(priv->gve_wq); + priv->ctrl_ops->unmap_db_bar(priv); free_netdev(netdev); - pci_iounmap(pdev, db_bar); pci_iounmap(pdev, reg_bar); pci_release_regions(pdev); pci_disable_device(pdev); From d320436137b793132d39e99e18269cf6d0d792f0 Mon Sep 17 00:00:00 2001 From: Harshitha Ramamurthy Date: Wed, 30 Sep 2026 19:04:19 +0000 Subject: [PATCH 1124/2126] gve: introduce ctrl ops to set vectors and Qs Introduce following ctrl ops for Adminq mode. - set_num_queues to set maximum and default TX/RX queues in the alloc structures used in the initialization flow. - set_num_ntfy_blks op to set number of vectors(ntfy_blks) in the initialization flow. This is done by attaching the adminq_ prefix to the existing functions placed in the gve_adminq.c file. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-4-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 6 ++++++ drivers/net/ethernet/google/gve/gve_adminq.c | 4 ++-- drivers/net/ethernet/google/gve/gve_adminq.h | 4 ++-- drivers/net/ethernet/google/gve/gve_main.c | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 56148ea3cfbf..1bc5e32b6618 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -829,10 +829,16 @@ struct gve_device_info { * struct gve_ctrl_ops - Control plane operations structure * @map_db_bar: Maps the doorbell BAR for the device and store in @priv. * @unmap_db_bar: Unmaps the doorbell BAR previously mapped by @map_db_bar. + * @set_num_queues: Sets default and max TX/RX queues into allocation + * structures stored in @priv to be used during initialization. + * @set_num_ntfy_blks: Sets no. of vectors into @priv to be used during + * initialization. */ struct gve_ctrl_ops { int (*map_db_bar)(struct gve_priv *priv); void (*unmap_db_bar)(struct gve_priv *priv); + void (*set_num_queues)(struct gve_priv *priv); + int (*set_num_ntfy_blks)(struct gve_priv *priv); }; struct gve_priv { diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 08d8e49d563e..046155ae7d66 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1592,7 +1592,7 @@ out: return err; } -int gve_set_num_ntfy_blks(struct gve_priv *priv) +int gve_adminq_set_num_ntfy_blks(struct gve_priv *priv) { int num_ntfy; @@ -1616,7 +1616,7 @@ int gve_set_num_ntfy_blks(struct gve_priv *priv) return 0; } -void gve_set_num_queues(struct gve_priv *priv) +void gve_adminq_set_num_queues(struct gve_priv *priv) { struct gve_device_info *device_info = &priv->device_info; diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 93d3cabb67f1..ed3504853908 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -656,8 +656,8 @@ int gve_adminq_report_nic_ts(struct gve_priv *priv, struct gve_ptype_lut; int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv, struct gve_ptype_lut *ptype_lut); -int gve_set_num_ntfy_blks(struct gve_priv *priv); -void gve_set_num_queues(struct gve_priv *priv); +int gve_adminq_set_num_ntfy_blks(struct gve_priv *priv); +void gve_adminq_set_num_queues(struct gve_priv *priv); int gve_adminq_map_db_bar(struct gve_priv *priv); void gve_adminq_unmap_db_bar(struct gve_priv *priv); #endif /* _GVE_ADMINQ_H */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index d721347e54b4..da53c1fb6afb 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -2463,6 +2463,8 @@ static void gve_set_buf_sizes(struct gve_priv *priv) static const struct gve_ctrl_ops gve_adminq_ops = { .map_db_bar = gve_adminq_map_db_bar, .unmap_db_bar = gve_adminq_unmap_db_bar, + .set_num_queues = gve_adminq_set_num_queues, + .set_num_ntfy_blks = gve_adminq_set_num_ntfy_blks, }; static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) @@ -2501,14 +2503,14 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) priv->queue_format = priv->device_info.queue_format; - err = gve_set_num_ntfy_blks(priv); + err = priv->ctrl_ops->set_num_ntfy_blks(priv); if (err) { dev_err(&priv->pdev->dev, "Could not setup notify blocks: err=%d\n", err); goto err; } - gve_set_num_queues(priv); + priv->ctrl_ops->set_num_queues(priv); dev_info(&priv->pdev->dev, "TX queues %d, RX queues %d\n", priv->tx_cfg.num_queues, priv->rx_cfg.num_queues); dev_info(&priv->pdev->dev, "Max TX queues %d, Max RX queues %d\n", From a01cb6b77e9a3fe0db8ea247a89892a1db98c6b1 Mon Sep 17 00:00:00 2001 From: Harshitha Ramamurthy Date: Wed, 30 Sep 2026 19:04:20 +0000 Subject: [PATCH 1125/2126] gve: introduce gve_adminq_get_device_properties() Introduce gve_adminq_get_device_properties() which executes the first two Adminq commands: VERIFY_DRIVER_COMPATIBILITY and DESCRIBE_DEVICE so that this can be called during initialization. Move these to Adminq specific files. This is just code movement, no functional change. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-5-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve_adminq.c | 68 ++++++++++++++++++-- drivers/net/ethernet/google/gve/gve_adminq.h | 5 +- drivers/net/ethernet/google/gve/gve_main.c | 47 +------------- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 046155ae7d66..f420a8e1dd3d 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -6,6 +6,8 @@ #include #include +#include +#include #include "gve.h" #include "gve_adminq.h" #include "gve_register.h" @@ -1143,6 +1145,27 @@ free_device_descriptor: return err; } +int gve_adminq_get_device_properties(struct gve_priv *priv) +{ + int err; + + err = gve_adminq_verify_driver_compatibility(priv); + if (err) { + dev_err(&priv->pdev->dev, + "Could not verify driver compatibility: err=%d\n", err); + return err; + } + + /* Get the initial information we need from the device */ + err = gve_adminq_describe_device(priv); + if (err) { + dev_err(&priv->pdev->dev, + "Could not get device information: err=%d\n", err); + return err; + } + return 0; +} + int gve_adminq_register_page_list(struct gve_priv *priv, struct gve_queue_page_list *qpl) { @@ -1205,20 +1228,53 @@ int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len, return gve_adminq_execute_cmd(priv, &cmd); } -int gve_adminq_verify_driver_compatibility(struct gve_priv *priv, - u64 driver_info_len, - dma_addr_t driver_info_addr) +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv) { + struct gve_driver_info *driver_info; union gve_adminq_command cmd; + dma_addr_t driver_info_bus; + int err; + + driver_info = dma_alloc_coherent(&priv->pdev->dev, + sizeof(struct gve_driver_info), + &driver_info_bus, GFP_KERNEL); + if (!driver_info) + return -ENOMEM; + + *driver_info = (struct gve_driver_info) { + .os_type = 1, /* Linux */ + .os_version_major = cpu_to_be32(LINUX_VERSION_MAJOR), + .os_version_minor = cpu_to_be32(LINUX_VERSION_SUBLEVEL), + .os_version_sub = cpu_to_be32(LINUX_VERSION_PATCHLEVEL), + .driver_capability_flags = { + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1), + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2), + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3), + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4), + }, + }; + strscpy(driver_info->os_version_str1, utsname()->release, + sizeof(driver_info->os_version_str1)); + strscpy(driver_info->os_version_str2, utsname()->version, + sizeof(driver_info->os_version_str2)); memset(&cmd, 0, sizeof(cmd)); cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY); cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) { - .driver_info_len = cpu_to_be64(driver_info_len), - .driver_info_addr = cpu_to_be64(driver_info_addr), + .driver_info_len = cpu_to_be64(sizeof(struct gve_driver_info)), + .driver_info_addr = cpu_to_be64(driver_info_bus), }; - return gve_adminq_execute_cmd(priv, &cmd); + err = gve_adminq_execute_cmd(priv, &cmd); + + /* It's ok if the device doesn't support this */ + if (err == -EOPNOTSUPP) + err = 0; + + dma_free_coherent(&priv->pdev->dev, + sizeof(struct gve_driver_info), + driver_info, driver_info_bus); + return err; } int gve_adminq_report_link_speed(struct gve_priv *priv) diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index ed3504853908..2ab68c822e22 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -640,9 +640,8 @@ int gve_adminq_register_page_list(struct gve_priv *priv, int gve_adminq_unregister_page_list(struct gve_priv *priv, u32 page_list_id); int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len, dma_addr_t stats_report_addr, u64 interval); -int gve_adminq_verify_driver_compatibility(struct gve_priv *priv, - u64 driver_info_len, - dma_addr_t driver_info_addr); +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv); +int gve_adminq_get_device_properties(struct gve_priv *priv); int gve_adminq_report_link_speed(struct gve_priv *priv); int gve_adminq_add_flow_rule(struct gve_priv *priv, struct gve_adminq_flow_rule *rule, u32 loc); int gve_adminq_del_flow_rule(struct gve_priv *priv, u32 loc); diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index da53c1fb6afb..addfd8dc1a1a 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -17,8 +17,6 @@ #include #include #include -#include -#include #include #include #include @@ -41,49 +39,6 @@ char gve_driver_name[] = "gve"; const char gve_version_str[] = GVE_VERSION; static const char gve_version_prefix[] = GVE_VERSION_PREFIX; -static int gve_verify_driver_compatibility(struct gve_priv *priv) -{ - int err; - struct gve_driver_info *driver_info; - dma_addr_t driver_info_bus; - - driver_info = dma_alloc_coherent(&priv->pdev->dev, - sizeof(struct gve_driver_info), - &driver_info_bus, GFP_KERNEL); - if (!driver_info) - return -ENOMEM; - - *driver_info = (struct gve_driver_info) { - .os_type = 1, /* Linux */ - .os_version_major = cpu_to_be32(LINUX_VERSION_MAJOR), - .os_version_minor = cpu_to_be32(LINUX_VERSION_SUBLEVEL), - .os_version_sub = cpu_to_be32(LINUX_VERSION_PATCHLEVEL), - .driver_capability_flags = { - cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1), - cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2), - cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3), - cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4), - }, - }; - strscpy(driver_info->os_version_str1, utsname()->release, - sizeof(driver_info->os_version_str1)); - strscpy(driver_info->os_version_str2, utsname()->version, - sizeof(driver_info->os_version_str2)); - - err = gve_adminq_verify_driver_compatibility(priv, - sizeof(struct gve_driver_info), - driver_info_bus); - - /* It's ok if the device doesn't support this */ - if (err == -EOPNOTSUPP) - err = 0; - - dma_free_coherent(&priv->pdev->dev, - sizeof(struct gve_driver_info), - driver_info, driver_info_bus); - return err; -} - static netdev_features_t gve_features_check(struct sk_buff *skb, struct net_device *dev, netdev_features_t features) @@ -2480,7 +2435,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) return err; } - err = gve_verify_driver_compatibility(priv); + err = gve_adminq_verify_driver_compatibility(priv); if (err) { dev_err(&priv->pdev->dev, "Could not verify driver compatibility: err=%d\n", err); From fd1e72e0966171d63e2604d5a42305f410d5825d Mon Sep 17 00:00:00 2001 From: Harshitha Ramamurthy Date: Wed, 30 Sep 2026 19:04:21 +0000 Subject: [PATCH 1126/2126] gve: refactor gve_init_priv for reset path The driver does not need to renegotiate all properties with the device on a reset since those should stay constant through a reset. Hence change gve_init_priv() into a method that only sets these properties into the priv structure and hence needs to be only called once during gve_probe(). To achieve this end state of gve_init_priv(), do the following: - introduce gve_adminq_init() which writes the driver version register and allocates the AdminQ and call it in gve_probe() - call gve_adminq_get_device_properties() into gve_probe() to learn device properties - introduce gve_setup_device() which deals with device setup logic and call it in gve_probe() - resetting no. of registered pages is moved into gve_setup_device() since that needs to be reset every time queues are re-created. With these changes, gve_adminq_get_device_properties() and gve_init_priv() are only called once during gve_probe. gve_reset_recovery() now calls targeted setup functions directly. This prepares the driver to add mailbox mode's control plane initialization and device properties negotiation in the same place as is done in AdminQ mode in the upcoming patches when adding the mailbox ABI. These changes are only code movement, no functional change. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-6-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 2 + drivers/net/ethernet/google/gve/gve_adminq.c | 12 +- drivers/net/ethernet/google/gve/gve_adminq.h | 2 +- drivers/net/ethernet/google/gve/gve_main.c | 143 ++++++++++--------- 4 files changed, 92 insertions(+), 67 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 1bc5e32b6618..48cc8a6be186 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -1253,6 +1253,8 @@ static inline bool gve_is_clock_enabled(struct gve_priv *priv) return priv->nic_ts_report; } +void gve_adminq_write_version(u8 __iomem *driver_version_register); + /* gqi napi handler defined in gve_main.c */ int gve_napi_poll(struct napi_struct *napi, int budget); diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index f420a8e1dd3d..a62cb7a921d0 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -298,8 +298,10 @@ gve_process_device_options(struct gve_priv *priv, return 0; } -int gve_adminq_alloc(struct device *dev, struct gve_priv *priv) +static int gve_adminq_alloc(struct gve_priv *priv) { + struct device *dev = &priv->pdev->dev; + priv->adminq_pool = dma_pool_create("adminq_pool", dev, GVE_ADMINQ_BUFFER_SIZE, 0, 0); if (unlikely(!priv->adminq_pool)) @@ -355,6 +357,14 @@ int gve_adminq_alloc(struct device *dev, struct gve_priv *priv) return 0; } +int gve_adminq_init(struct gve_priv *priv) +{ + struct gve_registers __iomem *reg_bar = priv->reg_bar0; + + gve_adminq_write_version(®_bar->driver_version); + return gve_adminq_alloc(priv); +} + void gve_adminq_release(struct gve_priv *priv) { int i = 0; diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 2ab68c822e22..78eee3b5cb7f 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -619,7 +619,7 @@ union gve_adminq_command { static_assert(sizeof(union gve_adminq_command) == 64); -int gve_adminq_alloc(struct device *dev, struct gve_priv *priv); +int gve_adminq_init(struct gve_priv *priv); void gve_adminq_free(struct gve_priv *priv); void gve_adminq_release(struct gve_priv *priv); int gve_adminq_describe_device(struct gve_priv *priv); diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index addfd8dc1a1a..2fe280cf7e68 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -2415,6 +2415,35 @@ static void gve_set_buf_sizes(struct gve_priv *priv) priv->header_buf_size = device_info->header_buf_size; } +static int gve_setup_device(struct gve_priv *priv) +{ + int err; + + priv->num_registered_pages = 0; + + priv->xsk_pools = bitmap_zalloc(priv->rx_cfg.max_queues, GFP_KERNEL); + if (!priv->xsk_pools) { + err = -ENOMEM; + goto err; + } + + gve_set_netdev_xdp_features(priv); + if (!gve_is_gqi(priv)) + priv->dev->xdp_metadata_ops = &gve_xdp_metadata_ops; + + err = gve_setup_device_resources(priv); + if (err) + goto err_free_xsk_bitmap; + + return 0; + +err_free_xsk_bitmap: + bitmap_free(priv->xsk_pools); + priv->xsk_pools = NULL; +err: + return err; +} + static const struct gve_ctrl_ops gve_adminq_ops = { .map_db_bar = gve_adminq_map_db_bar, .unmap_db_bar = gve_adminq_unmap_db_bar, @@ -2422,47 +2451,18 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .set_num_ntfy_blks = gve_adminq_set_num_ntfy_blks, }; -static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) +static int gve_init_priv(struct gve_priv *priv) { struct gve_device_info *device_info = &priv->device_info; int err; - /* Set up the adminq */ - err = gve_adminq_alloc(&priv->pdev->dev, priv); - if (err) { - dev_err(&priv->pdev->dev, - "Failed to alloc admin queue: err=%d\n", err); - return err; - } - - err = gve_adminq_verify_driver_compatibility(priv); - if (err) { - dev_err(&priv->pdev->dev, - "Could not verify driver compatibility: err=%d\n", err); - goto err; - } - - priv->num_registered_pages = 0; - - if (skip_describe_device) - goto setup_device; - - device_info->queue_format = GVE_QUEUE_FORMAT_UNSPECIFIED; - /* Get the initial information we need from the device */ - err = gve_adminq_describe_device(priv); - if (err) { - dev_err(&priv->pdev->dev, - "Could not get device information: err=%d\n", err); - goto err; - } - priv->queue_format = priv->device_info.queue_format; err = priv->ctrl_ops->set_num_ntfy_blks(priv); if (err) { dev_err(&priv->pdev->dev, "Could not setup notify blocks: err=%d\n", err); - goto err; + return err; } priv->ctrl_ops->set_num_queues(priv); @@ -2485,10 +2485,8 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) netif_set_tso_max_size(priv->dev, GVE_DQO_TX_MAX); } - if (gve_set_mtu(priv)) { - err = -EINVAL; - goto err; - } + if (gve_set_mtu(priv)) + return -EINVAL; priv->num_event_counters = device_info->num_event_counters; @@ -2513,30 +2511,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device) priv->ts_config.tx_type = HWTSTAMP_TX_OFF; priv->ts_config.rx_filter = HWTSTAMP_FILTER_NONE; priv->nic_timestamp_supported = device_info->nic_timestamp_supported; - -setup_device: - priv->xsk_pools = bitmap_zalloc(priv->rx_cfg.max_queues, GFP_KERNEL); - if (!priv->xsk_pools) { - err = -ENOMEM; - goto err; - } - - gve_set_netdev_xdp_features(priv); - if (!gve_is_gqi(priv)) - priv->dev->xdp_metadata_ops = &gve_xdp_metadata_ops; - - err = gve_setup_device_resources(priv); - if (err) - goto err_free_xsk_bitmap; - return 0; - -err_free_xsk_bitmap: - bitmap_free(priv->xsk_pools); - priv->xsk_pools = NULL; -err: - gve_adminq_free(priv); - return err; } static void gve_teardown_priv_resources(struct gve_priv *priv) @@ -2566,15 +2541,32 @@ static int gve_reset_recovery(struct gve_priv *priv, bool was_up) { int err; - err = gve_init_priv(priv, true); - if (err) + err = gve_adminq_init(priv); + if (err) { + dev_err(&priv->pdev->dev, + "Failed to alloc admin queue: err=%d\n", err); goto err; + } + + err = gve_adminq_verify_driver_compatibility(priv); + if (err) { + dev_err(&priv->pdev->dev, + "Could not verify driver compatibility: err=%d\n", err); + goto err_free_adminq; + } + + err = gve_setup_device(priv); + if (err) + goto err_free_adminq; if (was_up) { err = gve_open(priv->dev); if (err) - goto err; + return err; } return 0; + +err_free_adminq: + gve_adminq_free(priv); err: dev_err(&priv->pdev->dev, "Reset failed! !!! DISABLING ALL QUEUES !!!\n"); gve_turndown(priv); @@ -2617,7 +2609,7 @@ int gve_reset(struct gve_priv *priv, bool attempt_teardown) return err; } -static void gve_write_version(u8 __iomem *driver_version_register) +void gve_adminq_write_version(u8 __iomem *driver_version_register) { const char *c = gve_version_prefix; @@ -2850,7 +2842,6 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto abort_with_pci_region; } - gve_write_version(®_bar->driver_version); /* Get max queues to alloc etherdev */ max_tx_queues = ioread32be(®_bar->max_tx_queues); max_rx_queues = ioread32be(®_bar->max_rx_queues); @@ -2897,12 +2888,24 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->rx_cfg.packet_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE; priv->max_rx_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE; + err = gve_adminq_init(priv); + if (err) { + dev_err(&priv->pdev->dev, + "Failed to alloc admin queue: err=%d\n", err); + goto abort_with_netdev; + } + + priv->device_info.queue_format = GVE_QUEUE_FORMAT_UNSPECIFIED; + err = gve_adminq_get_device_properties(priv); + if (err) + goto abort_with_adminq; + /* Set adminq ctrl ops */ priv->ctrl_ops = &gve_adminq_ops; err = priv->ctrl_ops->map_db_bar(priv); if (err) - goto abort_with_netdev; + goto abort_with_adminq; gve_set_probe_in_progress(priv); priv->gve_wq = alloc_ordered_workqueue("gve", 0); @@ -2916,10 +2919,17 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->tx_cfg.max_queues = max_tx_queues; priv->rx_cfg.max_queues = max_rx_queues; - err = gve_init_priv(priv, false); + err = gve_init_priv(priv); if (err) goto abort_with_wq; + err = gve_setup_device(priv); + if (err) { + dev_err(&priv->pdev->dev, + "Could not setup device: err=%d\n", err); + goto abort_with_wq; + } + if (!gve_is_gqi(priv) && !gve_is_qpl(priv)) dev->netmem_tx = NETMEM_TX_DMA; @@ -2942,6 +2952,9 @@ abort_with_wq: abort_with_unmap_db_bar: priv->ctrl_ops->unmap_db_bar(priv); +abort_with_adminq: + gve_adminq_free(priv); + abort_with_netdev: free_netdev(dev); From 23b3b49d204b2c7f6e4a212eacf8ef2af2206919 Mon Sep 17 00:00:00 2001 From: Joshua Washington Date: Wed, 30 Sep 2026 19:04:22 +0000 Subject: [PATCH 1127/2126] gve: simplify reset logic Current GVE reset logic is quite complex, with a number of methods with similar names and functionalities. This complexity has allowed a number of bugs to enter the reset/recovery path, including the potential for reset loops if an operation fails during teardown. Simplify the reset path by doing the following: 1) Removing recursive resets. Recursive resets have two major issues. First, there is the potential for stack overflows if resets are invoked too many times in a row. Second, long recursive calls mean that GVE never gives up the RTNL lock, or at the very least holds it for too long. Resets triggered by methods as part of the reset path are implicitly ignored because gve_reset() now checks if there is a reset in progress before proceeding. 2) Removing resets during the teardown portion of reset. This is partly covered by removing recursive resets, but the primary goal in this case is to allow the driver to complete teardown in a more direct manner. Before this patch, gve_close() when called as part of gve_shutdown, could end up triggering a hardware reset, then attempt to close again. In such a case, destroying hardware queues would inevitably fail, causing a loop. gve_close() is no longer called directly in gve_reset() breaking any possibility of this loop. 3) Decompose allocation/de-allocation and setup/teardown. Performing allocation and setup for each control plane system (RSS, ptype map, etc) leaves many more error conditions to handle, causing teardown in the case of failures to be much more complex than they need to be. This will also be useful to better align a major behavioral change in mailbox mode, which will use separate response buffers instead to get data from the device instead of a pre-allocated shared memory region. With the new reset functionality, shared resources between the device and driver are not freed until after the hardware reset has completed in the event that deconfigure_device_resources() fails, meaning that the device could potentially still be holding on to shared memory. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-7-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 2 +- drivers/net/ethernet/google/gve/gve_adminq.c | 9 +- drivers/net/ethernet/google/gve/gve_adminq.h | 1 - drivers/net/ethernet/google/gve/gve_ethtool.c | 2 +- .../net/ethernet/google/gve/gve_flow_rule.c | 15 +- drivers/net/ethernet/google/gve/gve_main.c | 539 +++++++++--------- 6 files changed, 302 insertions(+), 266 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 48cc8a6be186..026d685ecaee 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -1348,7 +1348,7 @@ struct page_pool *gve_rx_create_page_pool(struct gve_priv *priv, /* Reset */ void gve_schedule_reset(struct gve_priv *priv); -int gve_reset(struct gve_priv *priv, bool attempt_teardown); +int gve_reset(struct gve_priv *priv, bool skip_queue_setup); void gve_get_curr_alloc_cfgs(struct gve_priv *priv, struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, struct gve_rx_alloc_rings_cfg *rx_alloc_cfg); diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index a62cb7a921d0..901673d2e264 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -365,7 +365,7 @@ int gve_adminq_init(struct gve_priv *priv) return gve_adminq_alloc(priv); } -void gve_adminq_release(struct gve_priv *priv) +static void gve_adminq_release(struct gve_priv *priv) { int i = 0; @@ -394,7 +394,6 @@ void gve_adminq_release(struct gve_priv *priv) } gve_clear_device_rings_ok(priv); gve_clear_device_resources_ok(priv); - gve_clear_admin_queue_ok(priv); } void gve_adminq_free(struct gve_priv *priv) @@ -1377,12 +1376,8 @@ gve_adminq_configure_flow_rule(struct gve_priv *priv, sizeof(struct gve_adminq_configure_flow_rule), flow_rule_cmd); - if (err == -ETIME) { - dev_err(&priv->pdev->dev, "Timeout to configure the flow rule, trigger reset"); - gve_reset(priv, true); - } else if (!err) { + if (!err) priv->flow_rules_cache.rules_cache_synced = false; - } return err; } diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 78eee3b5cb7f..fe1e8868cdfe 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -621,7 +621,6 @@ static_assert(sizeof(union gve_adminq_command) == 64); int gve_adminq_init(struct gve_priv *priv); void gve_adminq_free(struct gve_priv *priv); -void gve_adminq_release(struct gve_priv *priv); int gve_adminq_describe_device(struct gve_priv *priv); int gve_adminq_configure_device_resources(struct gve_priv *priv, dma_addr_t counter_array_bus_addr, diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c index 8199738ba979..dd1c44fedc77 100644 --- a/drivers/net/ethernet/google/gve/gve_ethtool.c +++ b/drivers/net/ethernet/google/gve/gve_ethtool.c @@ -651,7 +651,7 @@ static int gve_user_reset(struct net_device *netdev, u32 *flags) if (*flags == ETH_RESET_ALL) { *flags = 0; - return gve_reset(priv, true); + return gve_reset(priv, false); } return -EOPNOTSUPP; diff --git a/drivers/net/ethernet/google/gve/gve_flow_rule.c b/drivers/net/ethernet/google/gve/gve_flow_rule.c index 2c80cda28ef3..fae552f4ad6f 100644 --- a/drivers/net/ethernet/google/gve/gve_flow_rule.c +++ b/drivers/net/ethernet/google/gve/gve_flow_rule.c @@ -278,6 +278,11 @@ int gve_add_flow_rule(struct gve_priv *priv, struct ethtool_rxnfc *cmd) goto out; err = gve_adminq_add_flow_rule(priv, rule, fsp->location); + if (err == -ETIME) { + dev_err(&priv->pdev->dev, + "Timeout to add flow rule, trigger reset."); + gve_reset(priv, false); + } out: kvfree(rule); @@ -290,9 +295,17 @@ out: int gve_del_flow_rule(struct gve_priv *priv, struct ethtool_rxnfc *cmd) { struct ethtool_rx_flow_spec *fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; + int err; if (!priv->max_flow_rules) return -EOPNOTSUPP; - return gve_adminq_del_flow_rule(priv, fsp->location); + err = gve_adminq_del_flow_rule(priv, fsp->location); + if (err == -ETIME) { + dev_err(&priv->pdev->dev, + "Timeout to delete flow rule, trigger reset."); + gve_reset(priv, false); + } + + return err; } diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 2fe280cf7e68..3ca0f8dba683 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -261,6 +261,7 @@ static void gve_free_stats_report(struct gve_priv *priv) return; timer_delete_sync(&priv->stats_report_timer); + cancel_work_sync(&priv->stats_report_task); dma_free_coherent(&priv->pdev->dev, priv->stats_report_len, priv->stats_report, priv->stats_report_bus); priv->stats_report = NULL; @@ -590,7 +591,80 @@ static void gve_free_notify_blocks(struct gve_priv *priv) priv->msix_vectors = NULL; } -static int gve_setup_device_resources(struct gve_priv *priv) +static void gve_tx_get_curr_alloc_cfg(struct gve_priv *priv, + struct gve_tx_alloc_rings_cfg *cfg) +{ + cfg->qcfg = &priv->tx_cfg; + cfg->raw_addressing = !gve_is_qpl(priv); + cfg->ring_size = priv->tx_desc_cnt; + cfg->pages_per_qpl = priv->tx_pages_per_qpl; + cfg->num_xdp_rings = cfg->qcfg->num_xdp_queues; + cfg->tx = priv->tx; +} + +static void gve_rx_get_curr_alloc_cfg(struct gve_priv *priv, + struct gve_rx_alloc_rings_cfg *cfg) +{ + cfg->qcfg_rx = &priv->rx_cfg; + cfg->qcfg_tx = &priv->tx_cfg; + cfg->raw_addressing = !gve_is_qpl(priv); + cfg->enable_header_split = priv->header_split_enabled; + cfg->ring_size = priv->rx_desc_cnt; + cfg->pages_per_qpl = priv->rx_pages_per_qpl; + cfg->packet_buffer_size = priv->rx_cfg.packet_buffer_size; + cfg->rx = priv->rx; + cfg->xdp = !!cfg->qcfg_tx->num_xdp_queues; +} + +void gve_get_curr_alloc_cfgs(struct gve_priv *priv, + struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, + struct gve_rx_alloc_rings_cfg *rx_alloc_cfg) +{ + gve_tx_get_curr_alloc_cfg(priv, tx_alloc_cfg); + gve_rx_get_curr_alloc_cfg(priv, rx_alloc_cfg); +} + +static void gve_queues_mem_free(struct gve_priv *priv, + struct gve_tx_alloc_rings_cfg *tx_cfg, + struct gve_rx_alloc_rings_cfg *rx_cfg) +{ + if (gve_is_gqi(priv)) { + gve_tx_free_rings_gqi(priv, tx_cfg); + gve_rx_free_rings_gqi(priv, rx_cfg); + } else { + gve_tx_free_rings_dqo(priv, tx_cfg); + gve_rx_free_rings_dqo(priv, rx_cfg); + } +} + +static void gve_queues_mem_remove(struct gve_priv *priv) +{ + struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0}; + struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0}; + + gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg); + gve_queues_mem_free(priv, &tx_alloc_cfg, &rx_alloc_cfg); + priv->tx = NULL; + priv->rx = NULL; +} + +static void gve_free_control_plane_resources(struct gve_priv *priv) +{ + bitmap_free(priv->xsk_pools); + priv->xsk_pools = NULL; + + kvfree(priv->ptype_lut_dqo); + priv->ptype_lut_dqo = NULL; + + gve_teardown_clock(priv); + gve_free_stats_report(priv); + gve_free_notify_blocks(priv); + gve_free_counter_array(priv); + gve_free_rss_config_cache(priv); + gve_free_flow_rule_caches(priv); +} + +static int gve_alloc_control_plane_resources(struct gve_priv *priv) { int err; @@ -599,16 +673,42 @@ static int gve_setup_device_resources(struct gve_priv *priv) return err; err = gve_alloc_rss_config_cache(priv); if (err) - goto abort_with_flow_rule_caches; + goto abort; err = gve_alloc_counter_array(priv); if (err) - goto abort_with_rss_config_cache; + goto abort; err = gve_alloc_notify_blocks(priv); if (err) - goto abort_with_counter; + goto abort; err = gve_alloc_stats_report(priv); if (err) - goto abort_with_ntfy_blocks; + goto abort; + + if (!gve_is_gqi(priv)) { + priv->ptype_lut_dqo = kvzalloc_obj(*priv->ptype_lut_dqo, + GFP_KERNEL); + if (!priv->ptype_lut_dqo) { + err = -ENOMEM; + goto abort; + } + } + + priv->xsk_pools = bitmap_zalloc(priv->rx_cfg.max_queues, GFP_KERNEL); + if (!priv->xsk_pools) { + err = -ENOMEM; + goto abort; + } + + return 0; +abort: + gve_free_control_plane_resources(priv); + return err; +} + +static int gve_setup_control_plane_resources(struct gve_priv *priv) +{ + int err = 0; + err = gve_adminq_configure_device_resources(priv, priv->counter_array_bus, priv->num_event_counters, @@ -618,20 +718,15 @@ static int gve_setup_device_resources(struct gve_priv *priv) dev_err(&priv->pdev->dev, "could not setup device_resources: err=%d\n", err); err = -ENXIO; - goto abort_with_stats_report; + return err; } if (!gve_is_gqi(priv)) { - priv->ptype_lut_dqo = kvzalloc_obj(*priv->ptype_lut_dqo); - if (!priv->ptype_lut_dqo) { - err = -ENOMEM; - goto abort_with_stats_report; - } err = gve_adminq_get_ptype_map_dqo(priv, priv->ptype_lut_dqo); if (err) { dev_err(&priv->pdev->dev, "Failed to get ptype map: err=%d\n", err); - goto abort_with_ptype_lut; + goto deconfigure_device; } } @@ -646,7 +741,7 @@ static int gve_setup_device_resources(struct gve_priv *priv) err = gve_init_rss_config(priv, priv->rx_cfg.num_queues); if (err) { dev_err(&priv->pdev->dev, "Failed to init RSS config"); - goto abort_with_clock; + goto deconfigure_device; } err = gve_adminq_report_stats(priv, priv->stats_report_len, @@ -658,67 +753,77 @@ static int gve_setup_device_resources(struct gve_priv *priv) gve_set_device_resources_ok(priv); return 0; -abort_with_clock: - gve_teardown_clock(priv); -abort_with_ptype_lut: - kvfree(priv->ptype_lut_dqo); - priv->ptype_lut_dqo = NULL; -abort_with_stats_report: - gve_free_stats_report(priv); -abort_with_ntfy_blocks: - gve_free_notify_blocks(priv); -abort_with_counter: - gve_free_counter_array(priv); -abort_with_rss_config_cache: - gve_free_rss_config_cache(priv); -abort_with_flow_rule_caches: - gve_free_flow_rule_caches(priv); - +deconfigure_device: + gve_adminq_deconfigure_device_resources(priv); return err; } -static void gve_trigger_reset(struct gve_priv *priv); - -static void gve_teardown_device_resources(struct gve_priv *priv) +/** + * gve_teardown_control_plane_resources() - Request the device to release any + * shared allocated resources. + * + * @priv: Pointer to the GVE private device data structure. + * + * If any part of the teardown step fails, the failure is documented, but is + * otherwise ignored. It is expected that a device reset is triggered + * immediately after tearing down device resources, which would clear any + * lingering state on the device. + */ +static void gve_teardown_control_plane_resources(struct gve_priv *priv) { int err; + if (priv->ptp) + ptp_cancel_worker_sync(priv->ptp->clock); + /* Tell device its resources are being freed */ if (gve_get_device_resources_ok(priv)) { err = gve_flow_rules_reset(priv); - if (err) { + if (err) dev_err(&priv->pdev->dev, "Failed to reset flow rules: err=%d\n", err); - gve_trigger_reset(priv); - } /* detach the stats report */ err = gve_adminq_report_stats(priv, 0, 0x0, GVE_STATS_REPORT_TIMER_PERIOD); - if (err) { + if (err) dev_err(&priv->pdev->dev, "Failed to detach stats report: err=%d\n", err); - gve_trigger_reset(priv); - } err = gve_adminq_deconfigure_device_resources(priv); - if (err) { + if (err) dev_err(&priv->pdev->dev, "Could not deconfigure device resources: err=%d\n", err); - gve_trigger_reset(priv); - } } - kvfree(priv->ptype_lut_dqo); - priv->ptype_lut_dqo = NULL; - - gve_free_flow_rule_caches(priv); - gve_free_rss_config_cache(priv); - gve_free_counter_array(priv); - gve_free_notify_blocks(priv); - gve_free_stats_report(priv); - gve_teardown_clock(priv); gve_clear_device_resources_ok(priv); } +/** + * gve_reset_device() - Reset the device + * + * @priv: Pointer to the GVE private device data structure. + * + * Once this returns, the device is guaranteed not to access any memory it + * shares with the driver, so it is safe for the caller to recycle it. Device + * commands in gve_teardown_control_plane_resources() can fail, in which case + * the hardware reset triggered by gve_adminq_free() is the only such + * guarantee. + */ +static void gve_reset_device(struct gve_priv *priv) +{ + gve_teardown_control_plane_resources(priv); + gve_adminq_free(priv); +} + +static void gve_teardown_device(struct gve_priv *priv) +{ + gve_reset_device(priv); + /* Free any resources shared with the device only after we have a + * guarantee that the device will not try to access such resources. + */ + gve_free_control_plane_resources(priv); + gve_queues_mem_remove(priv); +} + static int gve_unregister_qpl(struct gve_priv *priv, struct gve_queue_page_list *qpl) { @@ -916,17 +1021,6 @@ static void gve_init_sync_stats(struct gve_priv *priv) u64_stats_init(&priv->rx[i].statss); } -static void gve_tx_get_curr_alloc_cfg(struct gve_priv *priv, - struct gve_tx_alloc_rings_cfg *cfg) -{ - cfg->qcfg = &priv->tx_cfg; - cfg->raw_addressing = !gve_is_qpl(priv); - cfg->ring_size = priv->tx_desc_cnt; - cfg->pages_per_qpl = priv->tx_pages_per_qpl; - cfg->num_xdp_rings = cfg->qcfg->num_xdp_queues; - cfg->tx = priv->tx; -} - static void gve_tx_stop_rings(struct gve_priv *priv, int num_rings) { int i; @@ -1044,19 +1138,6 @@ static int gve_destroy_rings(struct gve_priv *priv) return 0; } -static void gve_queues_mem_free(struct gve_priv *priv, - struct gve_tx_alloc_rings_cfg *tx_cfg, - struct gve_rx_alloc_rings_cfg *rx_cfg) -{ - if (gve_is_gqi(priv)) { - gve_tx_free_rings_gqi(priv, tx_cfg); - gve_rx_free_rings_gqi(priv, rx_cfg); - } else { - gve_tx_free_rings_dqo(priv, tx_cfg); - gve_rx_free_rings_dqo(priv, rx_cfg); - } -} - int gve_alloc_page(struct gve_priv *priv, struct device *dev, struct page **page, dma_addr_t *dma, enum dma_data_direction dir, gfp_t gfp_flags) @@ -1157,8 +1238,6 @@ void gve_schedule_reset(struct gve_priv *priv) queue_work(priv->gve_wq, &priv->service_task); } -static void gve_reset_and_teardown(struct gve_priv *priv, bool was_up); -static int gve_reset_recovery(struct gve_priv *priv, bool was_up); static void gve_turndown(struct gve_priv *priv); static void gve_turnup(struct gve_priv *priv); @@ -1269,37 +1348,16 @@ err: return err; } - static void gve_drain_page_cache(struct gve_priv *priv) { int i; + if (!priv->rx) + return; for (i = 0; i < priv->rx_cfg.num_queues; i++) page_frag_cache_drain(&priv->rx[i].page_cache); } -static void gve_rx_get_curr_alloc_cfg(struct gve_priv *priv, - struct gve_rx_alloc_rings_cfg *cfg) -{ - cfg->qcfg_rx = &priv->rx_cfg; - cfg->qcfg_tx = &priv->tx_cfg; - cfg->raw_addressing = !gve_is_qpl(priv); - cfg->enable_header_split = priv->header_split_enabled; - cfg->ring_size = priv->rx_desc_cnt; - cfg->pages_per_qpl = priv->rx_pages_per_qpl; - cfg->packet_buffer_size = priv->rx_cfg.packet_buffer_size; - cfg->rx = priv->rx; - cfg->xdp = !!cfg->qcfg_tx->num_xdp_queues; -} - -void gve_get_curr_alloc_cfgs(struct gve_priv *priv, - struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, - struct gve_rx_alloc_rings_cfg *rx_alloc_cfg) -{ - gve_tx_get_curr_alloc_cfg(priv, tx_alloc_cfg); - gve_rx_get_curr_alloc_cfg(priv, rx_alloc_cfg); -} - static void gve_rx_start_ring(struct gve_priv *priv, int i) { if (gve_is_gqi(priv)) @@ -1335,15 +1393,16 @@ static void gve_rx_stop_rings(struct gve_priv *priv, int num_rings) gve_rx_stop_ring(priv, i); } -static void gve_queues_mem_remove(struct gve_priv *priv) +static void gve_queues_stop(struct gve_priv *priv) { - struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0}; - struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0}; + gve_unreg_xdp_info(priv); + gve_drain_page_cache(priv); - gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg); - gve_queues_mem_free(priv, &tx_alloc_cfg, &rx_alloc_cfg); - priv->tx = NULL; - priv->rx = NULL; + timer_delete_sync(&priv->stats_report_timer); + cancel_work_sync(&priv->stats_report_task); + + gve_tx_stop_rings(priv, gve_num_tx_queues(priv)); + gve_rx_stop_rings(priv, priv->rx_cfg.num_queues); } /* The passed-in queue memory is stored into priv and the queues are made live. @@ -1368,6 +1427,8 @@ static int gve_queues_start(struct gve_priv *priv, priv->rx_desc_cnt = rx_alloc_cfg->ring_size; priv->tx_pages_per_qpl = tx_alloc_cfg->pages_per_qpl; priv->rx_pages_per_qpl = rx_alloc_cfg->pages_per_qpl; + priv->header_split_enabled = rx_alloc_cfg->enable_header_split; + priv->rx_cfg.packet_buffer_size = rx_alloc_cfg->packet_buffer_size; gve_tx_start_rings(priv, gve_num_tx_queues(priv)); gve_rx_start_rings(priv, rx_alloc_cfg->qcfg_rx->num_queues); @@ -1375,14 +1436,14 @@ static int gve_queues_start(struct gve_priv *priv, err = netif_set_real_num_tx_queues(dev, priv->tx_cfg.num_queues); if (err) - goto stop_and_free_rings; + goto stop_rings; err = netif_set_real_num_rx_queues(dev, priv->rx_cfg.num_queues); if (err) - goto stop_and_free_rings; + goto stop_rings; err = gve_reg_xdp_info(priv, dev); if (err) - goto stop_and_free_rings; + goto stop_rings; if (rx_alloc_cfg->reset_rss) { err = gve_init_rss_config(priv, priv->rx_cfg.num_queues); @@ -1394,9 +1455,6 @@ static int gve_queues_start(struct gve_priv *priv, if (err) goto reset; - priv->header_split_enabled = rx_alloc_cfg->enable_header_split; - priv->rx_cfg.packet_buffer_size = rx_alloc_cfg->packet_buffer_size; - err = gve_create_rings(priv); if (err) goto reset; @@ -1415,16 +1473,14 @@ static int gve_queues_start(struct gve_priv *priv, reset: if (gve_get_reset_in_progress(priv)) - goto stop_and_free_rings; - gve_reset_and_teardown(priv, true); - /* if this fails there is nothing we can do so just ignore the return */ - gve_reset_recovery(priv, false); - /* return the original error */ - return err; -stop_and_free_rings: - gve_tx_stop_rings(priv, gve_num_tx_queues(priv)); - gve_rx_stop_rings(priv, priv->rx_cfg.num_queues); - gve_queues_mem_remove(priv); + goto stop_rings; + + /* Attempt to reset. If reset is successful, gve_queues_start was + * successful with the new config. + */ + return gve_reset(priv, false); +stop_rings: + gve_queues_stop(priv); return err; } @@ -1435,57 +1491,25 @@ static int gve_open(struct net_device *dev) struct gve_priv *priv = netdev_priv(dev); int err; + if (!gve_get_device_resources_ok(priv)) { + dev_err(&priv->pdev->dev, + "Attempting to open netdev without resources. Device must be reset."); + return -ENODEV; + } + gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg); err = gve_queues_mem_alloc(priv, &tx_alloc_cfg, &rx_alloc_cfg); if (err) return err; - /* No need to free on error: ownership of resources is lost after - * calling gve_queues_start. - */ err = gve_queues_start(priv, &tx_alloc_cfg, &rx_alloc_cfg); - if (err) + if (err) { + gve_queues_mem_remove(priv); return err; - - return 0; -} - -static int gve_queues_stop(struct gve_priv *priv) -{ - int err; - - netif_carrier_off(priv->dev); - if (gve_get_device_rings_ok(priv)) { - gve_turndown(priv); - gve_drain_page_cache(priv); - err = gve_destroy_rings(priv); - if (err) - goto err; - err = gve_unregister_qpls(priv); - if (err) - goto err; - gve_clear_device_rings_ok(priv); } - timer_delete_sync(&priv->stats_report_timer); - gve_unreg_xdp_info(priv); - - gve_tx_stop_rings(priv, gve_num_tx_queues(priv)); - gve_rx_stop_rings(priv, priv->rx_cfg.num_queues); - - priv->interface_down_cnt++; return 0; - -err: - /* This must have been called from a reset due to the rtnl lock - * so just return at this point. - */ - if (gve_get_reset_in_progress(priv)) - return err; - /* Otherwise reset before returning */ - gve_reset_and_teardown(priv, true); - return gve_reset_recovery(priv, false); } static int gve_close(struct net_device *dev) @@ -1493,12 +1517,29 @@ static int gve_close(struct net_device *dev) struct gve_priv *priv = netdev_priv(dev); int err; - err = gve_queues_stop(priv); - if (err) - return err; + gve_turndown(priv); + /* Surrender to reset if the queue destroying adminq cmds fail. Reset + * will not re-enable the interface. + */ + if (gve_get_device_rings_ok(priv)) { + gve_clear_device_rings_ok(priv); + err = gve_destroy_rings(priv); + if (err) + goto reset; + err = gve_unregister_qpls(priv); + if (err) + goto reset; + } + + gve_queues_stop(priv); gve_queues_mem_remove(priv); + priv->interface_down_cnt++; return 0; + +reset: + err = gve_reset(priv, true); + return err; } static void gve_handle_link_status(struct gve_priv *priv, bool link_status) @@ -1833,9 +1874,7 @@ int gve_adjust_config(struct gve_priv *priv, if (err) { netif_err(priv, drv, priv->dev, "Adjust config failed to start new queues, !!! DISABLING ALL QUEUES !!!\n"); - /* No need to free on error: ownership of resources is lost after - * calling gve_queues_start. - */ + gve_queues_mem_remove(priv); gve_turndown(priv); return err; } @@ -2149,8 +2188,11 @@ static int gve_set_features(struct net_device *netdev, } if ((netdev->features & NETIF_F_NTUPLE) && !(features & NETIF_F_NTUPLE)) { err = gve_flow_rules_reset(priv); - if (err) + if (err) { + if (err == -ETIME) + gve_schedule_reset(priv); goto revert_features; + } } return 0; @@ -2235,7 +2277,8 @@ static void gve_handle_reset(struct gve_priv *priv) if (gve_get_do_reset(priv)) { rtnl_lock(); netdev_lock(priv->dev); - gve_reset(priv, false); + if (gve_get_do_reset(priv)) + gve_reset(priv, false); netdev_unlock(priv->dev); rtnl_unlock(); } @@ -2421,25 +2464,17 @@ static int gve_setup_device(struct gve_priv *priv) priv->num_registered_pages = 0; - priv->xsk_pools = bitmap_zalloc(priv->rx_cfg.max_queues, GFP_KERNEL); - if (!priv->xsk_pools) { - err = -ENOMEM; - goto err; - } - gve_set_netdev_xdp_features(priv); if (!gve_is_gqi(priv)) priv->dev->xdp_metadata_ops = &gve_xdp_metadata_ops; - err = gve_setup_device_resources(priv); + err = gve_alloc_control_plane_resources(priv); if (err) - goto err_free_xsk_bitmap; - + goto err; + err = gve_setup_control_plane_resources(priv); + if (err) + goto err; return 0; - -err_free_xsk_bitmap: - bitmap_free(priv->xsk_pools); - priv->xsk_pools = NULL; err: return err; } @@ -2514,30 +2549,7 @@ static int gve_init_priv(struct gve_priv *priv) return 0; } -static void gve_teardown_priv_resources(struct gve_priv *priv) -{ - gve_teardown_device_resources(priv); - gve_adminq_free(priv); - bitmap_free(priv->xsk_pools); - priv->xsk_pools = NULL; -} - -static void gve_trigger_reset(struct gve_priv *priv) -{ - /* Reset the device by releasing the AQ */ - gve_adminq_release(priv); -} - -static void gve_reset_and_teardown(struct gve_priv *priv, bool was_up) -{ - gve_trigger_reset(priv); - /* With the reset having already happened, close cannot fail */ - if (was_up) - gve_close(priv->dev); - gve_teardown_priv_resources(priv); -} - -static int gve_reset_recovery(struct gve_priv *priv, bool was_up) +static int gve_recover(struct gve_priv *priv, bool setup_queues) { int err; @@ -2545,62 +2557,79 @@ static int gve_reset_recovery(struct gve_priv *priv, bool was_up) if (err) { dev_err(&priv->pdev->dev, "Failed to alloc admin queue: err=%d\n", err); - goto err; + goto teardown_device; } err = gve_adminq_verify_driver_compatibility(priv); if (err) { dev_err(&priv->pdev->dev, "Could not verify driver compatibility: err=%d\n", err); - goto err_free_adminq; + goto teardown_device; } err = gve_setup_device(priv); if (err) - goto err_free_adminq; - if (was_up) { + goto teardown_device; + + if (setup_queues) { + /* On failure, hold on to the control plane to give a + * chance for the queues to be brought up later. + */ err = gve_open(priv->dev); - if (err) + if (err) { + dev_err(&priv->pdev->dev, + "Failed to start queues: err=%d, !!! DISABLING ALL QUEUES !!!\n", + err); return err; + } } + + /* undo any detach from an earlier failure */ + netif_device_attach(priv->dev); + return 0; -err_free_adminq: - gve_adminq_free(priv); -err: - dev_err(&priv->pdev->dev, "Reset failed! !!! DISABLING ALL QUEUES !!!\n"); - gve_turndown(priv); +teardown_device: + dev_err(&priv->pdev->dev, "Recover failed: err=%d, detaching device\n", + err); + netif_device_detach(priv->dev); + gve_teardown_device(priv); return err; } -int gve_reset(struct gve_priv *priv, bool attempt_teardown) +int gve_reset(struct gve_priv *priv, bool skip_queue_setup) { bool was_up = netif_running(priv->dev); int err; + if (gve_get_reset_in_progress(priv)) + return 0; + dev_info(&priv->pdev->dev, "Performing reset\n"); gve_clear_do_reset(priv); gve_set_reset_in_progress(priv); - /* If we aren't attempting to teardown normally, just go turndown and - * reset right away. - */ - if (!attempt_teardown) { + + if (was_up) { gve_turndown(priv); - gve_reset_and_teardown(priv, was_up); - } else { - /* Otherwise attempt to close normally */ - if (was_up) { - err = gve_close(priv->dev); - /* If that fails reset as we did above */ - if (err) - gve_reset_and_teardown(priv, was_up); + if (gve_get_device_rings_ok(priv)) { + gve_clear_device_rings_ok(priv); + gve_destroy_rings(priv); + gve_unregister_qpls(priv); } - /* Clean up any remaining resources */ - gve_teardown_priv_resources(priv); } - /* Set it all back up */ - err = gve_reset_recovery(priv, was_up); + disable_work(&priv->service_task); + gve_reset_device(priv); + gve_queues_stop(priv); + gve_queues_mem_remove(priv); + gve_free_control_plane_resources(priv); + + enable_work(&priv->service_task); + err = gve_recover(priv, was_up && !skip_queue_setup); + if (err) + dev_info(&priv->pdev->dev, + "Failed to recover in reset: %d\n", err); + gve_clear_reset_in_progress(priv); priv->reset_cnt++; priv->interface_up_cnt = 0; @@ -2927,7 +2956,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) { dev_err(&priv->pdev->dev, "Could not setup device: err=%d\n", err); - goto abort_with_wq; + goto abort_teardown_device; } if (!gve_is_gqi(priv) && !gve_is_qpl(priv)) @@ -2935,7 +2964,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = register_netdev(dev); if (err) - goto abort_with_gve_init; + goto abort_teardown_device; dev_info(&pdev->dev, "GVE version %s\n", gve_version_str); dev_info(&pdev->dev, "GVE queue format %d\n", (int)priv->queue_format); @@ -2943,8 +2972,9 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) queue_work(priv->gve_wq, &priv->service_task); return 0; -abort_with_gve_init: - gve_teardown_priv_resources(priv); +abort_teardown_device: + disable_work_sync(&priv->service_task); + gve_teardown_device(priv); abort_with_wq: destroy_workqueue(priv->gve_wq); @@ -2976,7 +3006,8 @@ static void gve_remove(struct pci_dev *pdev) void __iomem *reg_bar = priv->reg_bar0; unregister_netdev(netdev); - gve_teardown_priv_resources(priv); + disable_work_sync(&priv->service_task); + gve_teardown_device(priv); destroy_workqueue(priv->gve_wq); priv->ctrl_ops->unmap_db_bar(priv); free_netdev(netdev); @@ -2991,17 +3022,16 @@ static void gve_shutdown(struct pci_dev *pdev) struct gve_priv *priv = netdev_priv(netdev); bool was_up = netif_running(priv->dev); - netif_device_detach(netdev); + disable_work_sync(&priv->service_task); rtnl_lock(); netdev_lock(netdev); - if (was_up && gve_close(priv->dev)) { - /* If the dev was up, attempt to close, if close fails, reset */ - gve_reset_and_teardown(priv, was_up); - } else { - /* If the dev wasn't up or close worked, finish tearing down */ - gve_teardown_priv_resources(priv); - } + if (was_up) + gve_close(priv->dev); + + /* detach here because gve_close() might attach in recovery */ + netif_device_detach(netdev); + gve_teardown_device(priv); netdev_unlock(netdev); rtnl_unlock(); } @@ -3013,16 +3043,14 @@ static int gve_suspend(struct device *dev) struct gve_priv *priv = netdev_priv(netdev); bool was_up = netif_running(priv->dev); + disable_work_sync(&priv->service_task); + priv->suspend_cnt++; rtnl_lock(); netdev_lock(netdev); - if (was_up && gve_close(priv->dev)) { - /* If the dev was up, attempt to close, if close fails, reset */ - gve_reset_and_teardown(priv, was_up); - } else { - /* If the dev wasn't up or close worked, finish tearing down */ - gve_teardown_priv_resources(priv); - } + if (was_up) + gve_close(priv->dev); + gve_teardown_device(priv); priv->up_before_suspend = was_up; netdev_unlock(netdev); rtnl_unlock(); @@ -3039,7 +3067,8 @@ static int gve_resume(struct device *dev) priv->resume_cnt++; rtnl_lock(); netdev_lock(netdev); - err = gve_reset_recovery(priv, priv->up_before_suspend); + enable_work(&priv->service_task); + err = gve_recover(priv, priv->up_before_suspend); netdev_unlock(netdev); rtnl_unlock(); return err; From 5914443d971b20838de587507014c4a18caa849f Mon Sep 17 00:00:00 2001 From: Joshua Washington Date: Wed, 30 Sep 2026 19:04:23 +0000 Subject: [PATCH 1128/2126] gve: add gve_ctrl_ops for gve initialization/teardown sequences Driver initialization and teardown involve a number of control plane operations that need to be defined for gve_probe to operate in both mailbox and adminq modes. This list includes: - get_ptype_map: a mapping of packet types (L3+L4) held in RX completion descriptors - configure_rss: set up default RSS configuration if the device is not queryable - setup_stats_report: set up DMA region for stats report (AQ-only) - reset_flow_rules: needed in teardown; flushes all flow rules from device Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-8-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 12 ++++++++++ drivers/net/ethernet/google/gve/gve_adminq.c | 7 +++--- drivers/net/ethernet/google/gve/gve_adminq.h | 3 +-- drivers/net/ethernet/google/gve/gve_main.c | 23 +++++++++++++++----- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 026d685ecaee..e0583e8cd2cd 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -833,12 +833,24 @@ struct gve_device_info { * structures stored in @priv to be used during initialization. * @set_num_ntfy_blks: Sets no. of vectors into @priv to be used during * initialization. + * @get_ptype_map: Learn packet type map from device and store it in @priv + * @configure_rss: Set up default RSS configuration + * @setup_stats_report: Set up DMA region for stats report (AdminQ only) + * @reset_flow_rules: Flush all flow rules from device */ struct gve_ctrl_ops { int (*map_db_bar)(struct gve_priv *priv); void (*unmap_db_bar)(struct gve_priv *priv); void (*set_num_queues)(struct gve_priv *priv); int (*set_num_ntfy_blks)(struct gve_priv *priv); + int (*get_ptype_map)(struct gve_priv *priv); + int (*configure_rss)(struct gve_priv *priv, + struct ethtool_rxfh_param *param); + int (*setup_stats_report)(struct gve_priv *priv, + u64 stats_report_len, + dma_addr_t stats_report_addr, + u64 interval_ms); /* AQ-specific */ + int (*reset_flow_rules)(struct gve_priv *priv); }; struct gve_priv { diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 901673d2e264..1176e13fafc0 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1329,8 +1329,7 @@ int gve_adminq_report_nic_ts(struct gve_priv *priv, return gve_adminq_execute_cmd(priv, &cmd); } -int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv, - struct gve_ptype_lut *ptype_lut) +int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv) { struct gve_ptype_map *ptype_map; union gve_adminq_command cmd; @@ -1356,9 +1355,9 @@ int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv, /* Populate ptype_lut. */ for (i = 0; i < GVE_NUM_PTYPES; i++) { - ptype_lut->ptypes[i].l3_type = + priv->ptype_lut_dqo->ptypes[i].l3_type = ptype_map->ptypes[i].l3_type; - ptype_lut->ptypes[i].l4_type = + priv->ptype_lut_dqo->ptypes[i].l4_type = ptype_map->ptypes[i].l4_type; } err: diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index fe1e8868cdfe..5e51c060e237 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -652,8 +652,7 @@ int gve_adminq_report_nic_ts(struct gve_priv *priv, dma_addr_t nic_ts_report_addr); struct gve_ptype_lut; -int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv, - struct gve_ptype_lut *ptype_lut); +int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv); int gve_adminq_set_num_ntfy_blks(struct gve_priv *priv); void gve_adminq_set_num_queues(struct gve_priv *priv); int gve_adminq_map_db_bar(struct gve_priv *priv); diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 3ca0f8dba683..156bee612ba6 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -707,7 +707,8 @@ abort: static int gve_setup_control_plane_resources(struct gve_priv *priv) { - int err = 0; + const struct gve_ctrl_ops *ops = priv->ctrl_ops; + int err; err = gve_adminq_configure_device_resources(priv, priv->counter_array_bus, @@ -722,7 +723,7 @@ static int gve_setup_control_plane_resources(struct gve_priv *priv) } if (!gve_is_gqi(priv)) { - err = gve_adminq_get_ptype_map_dqo(priv, priv->ptype_lut_dqo); + err = ops->get_ptype_map(priv); if (err) { dev_err(&priv->pdev->dev, "Failed to get ptype map: err=%d\n", err); @@ -744,12 +745,13 @@ static int gve_setup_control_plane_resources(struct gve_priv *priv) goto deconfigure_device; } - err = gve_adminq_report_stats(priv, priv->stats_report_len, + err = ops->setup_stats_report(priv, priv->stats_report_len, priv->stats_report_bus, GVE_STATS_REPORT_TIMER_PERIOD); if (err) dev_err(&priv->pdev->dev, "Failed to report stats: err=%d\n", err); + gve_set_device_resources_ok(priv); return 0; @@ -771,6 +773,7 @@ deconfigure_device: */ static void gve_teardown_control_plane_resources(struct gve_priv *priv) { + const struct gve_ctrl_ops *ops = priv->ctrl_ops; int err; if (priv->ptp) @@ -783,7 +786,8 @@ static void gve_teardown_control_plane_resources(struct gve_priv *priv) dev_err(&priv->pdev->dev, "Failed to reset flow rules: err=%d\n", err); /* detach the stats report */ - err = gve_adminq_report_stats(priv, 0, 0x0, GVE_STATS_REPORT_TIMER_PERIOD); + err = ops->setup_stats_report(priv, 0, 0x0, + GVE_STATS_REPORT_TIMER_PERIOD); if (err) dev_err(&priv->pdev->dev, "Failed to detach stats report: err=%d\n", err); @@ -1820,6 +1824,7 @@ static int gve_xdp(struct net_device *dev, struct netdev_bpf *xdp) int gve_init_rss_config(struct gve_priv *priv, u16 num_queues) { + const struct gve_ctrl_ops *ops = priv->ctrl_ops; struct gve_rss_config *rss_config = &priv->rss_config; struct ethtool_rxfh_param rxfh = {0}; u16 i; @@ -1835,15 +1840,17 @@ int gve_init_rss_config(struct gve_priv *priv, u16 num_queues) rxfh.hfunc = ETH_RSS_HASH_TOP; - return gve_adminq_configure_rss(priv, &rxfh); + return ops->configure_rss(priv, &rxfh); } int gve_flow_rules_reset(struct gve_priv *priv) { + const struct gve_ctrl_ops *ops = priv->ctrl_ops; + if (!priv->max_flow_rules) return 0; - return gve_adminq_reset_flow_rules(priv); + return ops->reset_flow_rules(priv); } int gve_adjust_config(struct gve_priv *priv, @@ -2484,6 +2491,10 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .unmap_db_bar = gve_adminq_unmap_db_bar, .set_num_queues = gve_adminq_set_num_queues, .set_num_ntfy_blks = gve_adminq_set_num_ntfy_blks, + .get_ptype_map = gve_adminq_get_ptype_map_dqo, + .reset_flow_rules = gve_adminq_reset_flow_rules, + .setup_stats_report = gve_adminq_report_stats, + .configure_rss = gve_adminq_configure_rss, }; static int gve_init_priv(struct gve_priv *priv) From fed9970a6550c1b6f10f1593a2c1bda576a56afe Mon Sep 17 00:00:00 2001 From: Joshua Washington Date: Wed, 30 Sep 2026 19:04:24 +0000 Subject: [PATCH 1129/2126] gve: split up notify block allocation and setup paths Before this patch, notify block allocation and setup occurred in the same method. This all occurred before gve_adminq_configure_device_resources, which populates the irq_db_indicies array, a DMA region with BAR offsets for MSI-X vectors. The coming mailbox mode will require notify blocks to be set up only after receiving the IRQ doorbell offsets, as the request does not work with a supplied DMA buffer in the way that admin queue mode does. The intended flow in that case would be: 1) allocate notify blocks 2) request doorbell information 3) set up MSI-X vectors based on doorbell info This ordering also works for admin queue mode, so it will be updated to match. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-9-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 2 + drivers/net/ethernet/google/gve/gve_main.c | 155 +++++++++++--------- drivers/net/ethernet/google/gve/gve_utils.c | 4 +- 3 files changed, 89 insertions(+), 72 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index e0583e8cd2cd..f624a3e385e4 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -674,6 +674,7 @@ struct gve_notify_block { struct gve_tx_ring *tx; /* tx rings on this block */ struct gve_rx_ring *rx; /* rx rings on this block */ u32 irq; + bool irq_requested; }; /* Tracks allowed and current rx queue settings */ @@ -954,6 +955,7 @@ struct gve_priv { u64 link_speed; bool up_before_suspend; /* True if dev was up before suspend */ + bool mgmt_irq_requested; struct gve_ptype_lut *ptype_lut_dqo; /* Must be a power of two. */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 156bee612ba6..01a271680d78 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -425,6 +425,24 @@ int gve_napi_poll_dqo(struct napi_struct *napi, int budget) return work_done; } +static void gve_free_notify_blocks(struct gve_priv *priv) +{ + pci_disable_msix(priv->pdev); + if (priv->irq_db_indices) { + dma_free_coherent(&priv->pdev->dev, + priv->num_ntfy_blks * + sizeof(*priv->irq_db_indices), + priv->irq_db_indices, + priv->irq_db_indices_bus); + priv->irq_db_indices = NULL; + } + + kvfree(priv->ntfy_blocks); + priv->ntfy_blocks = NULL; + kvfree(priv->msix_vectors); + priv->msix_vectors = NULL; +} + static const struct cpumask *gve_get_node_mask(struct gve_priv *priv) { if (priv->numa_node == NUMA_NO_NODE) @@ -436,11 +454,9 @@ static const struct cpumask *gve_get_node_mask(struct gve_priv *priv) static int gve_alloc_notify_blocks(struct gve_priv *priv) { int num_vecs_requested = priv->num_ntfy_blks + 1; - const struct cpumask *node_mask; - unsigned int cur_cpu; int vecs_enabled; - int i, j; int err; + int i; priv->msix_vectors = kvzalloc_objs(*priv->msix_vectors, num_vecs_requested); @@ -454,7 +470,7 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) dev_err(&priv->pdev->dev, "Could not enable min msix %d/%d\n", GVE_MIN_MSIX, vecs_enabled); err = vecs_enabled; - goto abort_with_msix_vectors; + goto abort; } if (vecs_enabled != num_vecs_requested) { int new_num_ntfy_blks = (vecs_enabled - 1) & ~0x1; @@ -477,15 +493,6 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) priv->rx_cfg.num_queues = priv->rx_cfg.max_queues; } - /* Setup Management Vector - the last vector */ - snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), "gve-mgmnt@pci:%s", - pci_name(priv->pdev)); - err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, - gve_mgmnt_intr, 0, priv->mgmt_msix_name, priv); - if (err) { - dev_err(&priv->pdev->dev, "Did not receive management vector.\n"); - goto abort_with_msix_enabled; - } priv->irq_db_indices = dma_alloc_coherent(&priv->pdev->dev, priv->num_ntfy_blks * @@ -493,15 +500,64 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) &priv->irq_db_indices_bus, GFP_KERNEL); if (!priv->irq_db_indices) { err = -ENOMEM; - goto abort_with_mgmt_vector; + goto abort; } priv->ntfy_blocks = kvzalloc(priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks), GFP_KERNEL); if (!priv->ntfy_blocks) { err = -ENOMEM; - goto abort_with_irq_db_indices; + goto abort; } + return 0; + +abort: + gve_free_notify_blocks(priv); + return err; +} + +static void gve_teardown_notify_blocks(struct gve_priv *priv) +{ + int i; + + if (priv->mgmt_irq_requested) { + free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); + priv->mgmt_irq_requested = false; + } + + if (!priv->ntfy_blocks) + return; + + for (i = 0; i < priv->num_ntfy_blks; i++) { + struct gve_notify_block *block = &priv->ntfy_blocks[i]; + + if (!block->irq_requested) + continue; + + irq_set_affinity_hint(priv->msix_vectors[i].vector, + NULL); + free_irq(priv->msix_vectors[i].vector, block); + block->irq_requested = false; + } +} + +static int gve_setup_notify_blocks(struct gve_priv *priv) +{ + const struct cpumask *node_mask; + unsigned int cur_cpu; + int i; + int err; + + /* Setup Management Vector - the last vector */ + snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), + "gve-mgmnt@pci:%s", pci_name(priv->pdev)); + err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, + gve_mgmnt_intr, 0, priv->mgmt_msix_name, priv); + if (err) { + dev_err(&priv->pdev->dev, "Did not receive management vector.\n"); + return err; + } + priv->mgmt_irq_requested = true; /* Setup the other blocks - the first n-1 vectors */ node_mask = gve_get_node_mask(priv); @@ -519,9 +575,10 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) if (err) { dev_err(&priv->pdev->dev, "Failed to receive msix vector %d\n", i); - goto abort_with_some_ntfy_blocks; + goto abort; } block->irq = priv->msix_vectors[msix_idx].vector; + block->irq_requested = true; irq_set_affinity_and_hint(block->irq, cpumask_of(cur_cpu)); block->irq_db_index = &priv->irq_db_indices[i].index; @@ -535,61 +592,12 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) cur_cpu = cpumask_first(node_mask); } return 0; -abort_with_some_ntfy_blocks: - for (j = 0; j < i; j++) { - struct gve_notify_block *block = &priv->ntfy_blocks[j]; - int msix_idx = j; - irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, - NULL); - free_irq(priv->msix_vectors[msix_idx].vector, block); - block->irq = 0; - } - kvfree(priv->ntfy_blocks); - priv->ntfy_blocks = NULL; -abort_with_irq_db_indices: - dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * - sizeof(*priv->irq_db_indices), - priv->irq_db_indices, priv->irq_db_indices_bus); - priv->irq_db_indices = NULL; -abort_with_mgmt_vector: - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); -abort_with_msix_enabled: - pci_disable_msix(priv->pdev); -abort_with_msix_vectors: - kvfree(priv->msix_vectors); - priv->msix_vectors = NULL; +abort: + gve_teardown_notify_blocks(priv); return err; } -static void gve_free_notify_blocks(struct gve_priv *priv) -{ - int i; - - if (!priv->msix_vectors) - return; - - /* Free the irqs */ - for (i = 0; i < priv->num_ntfy_blks; i++) { - struct gve_notify_block *block = &priv->ntfy_blocks[i]; - int msix_idx = i; - - irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, - NULL); - free_irq(priv->msix_vectors[msix_idx].vector, block); - block->irq = 0; - } - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); - kvfree(priv->ntfy_blocks); - priv->ntfy_blocks = NULL; - dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * - sizeof(*priv->irq_db_indices), - priv->irq_db_indices, priv->irq_db_indices_bus); - priv->irq_db_indices = NULL; - pci_disable_msix(priv->pdev); - kvfree(priv->msix_vectors); - priv->msix_vectors = NULL; -} static void gve_tx_get_curr_alloc_cfg(struct gve_priv *priv, struct gve_tx_alloc_rings_cfg *cfg) @@ -824,6 +832,7 @@ static void gve_teardown_device(struct gve_priv *priv) /* Free any resources shared with the device only after we have a * guarantee that the device will not try to access such resources. */ + gve_teardown_notify_blocks(priv); gve_free_control_plane_resources(priv); gve_queues_mem_remove(priv); } @@ -2477,13 +2486,16 @@ static int gve_setup_device(struct gve_priv *priv) err = gve_alloc_control_plane_resources(priv); if (err) - goto err; + return err; + err = gve_setup_control_plane_resources(priv); if (err) - goto err; + return err; + + err = gve_setup_notify_blocks(priv); + if (err) + return err; return 0; -err: - return err; } static const struct gve_ctrl_ops gve_adminq_ops = { @@ -2633,6 +2645,7 @@ int gve_reset(struct gve_priv *priv, bool skip_queue_setup) gve_reset_device(priv); gve_queues_stop(priv); gve_queues_mem_remove(priv); + gve_teardown_notify_blocks(priv); gve_free_control_plane_resources(priv); enable_work(&priv->service_task); diff --git a/drivers/net/ethernet/google/gve/gve_utils.c b/drivers/net/ethernet/google/gve/gve_utils.c index b53b7fcdcdaf..caed38cd5f2b 100644 --- a/drivers/net/ethernet/google/gve/gve_utils.c +++ b/drivers/net/ethernet/google/gve/gve_utils.c @@ -119,6 +119,8 @@ void gve_remove_napi(struct gve_priv *priv, int ntfy_idx) { struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx]; - disable_irq(block->irq); + if (block->irq_requested) + disable_irq(block->irq); + netif_napi_del_locked(&block->napi); } From 5bc0c9796787212612519394bd68837e850f4a4c Mon Sep 17 00:00:00 2001 From: Joshua Washington Date: Wed, 30 Sep 2026 19:04:25 +0000 Subject: [PATCH 1130/2126] gve: introduce new methods to handle IRQ doorbells Introduce `request_db_info` and `release_db_resources` to `struct gve_ctrl_ops`. These encapsulate the configuration of device resources (counter arrays and IRQ doorbell indices) which vary between Admin Queue and Mailbox modes. All behaviors related to the IRQ doorbell indices will be managed by these new methods instead of occurring directly in notify_block setup/teardown methods. Similarly, GQ ring counters will be managed in `request_db_info`. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-10-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 10 ++ drivers/net/ethernet/google/gve/gve_adminq.c | 37 +++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 2 + drivers/net/ethernet/google/gve/gve_main.c | 101 +++++++++---------- 4 files changed, 99 insertions(+), 51 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index f624a3e385e4..6c46c842070b 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -834,6 +834,9 @@ struct gve_device_info { * structures stored in @priv to be used during initialization. * @set_num_ntfy_blks: Sets no. of vectors into @priv to be used during * initialization. + * @request_db_info: Request and store doorbell information into @priv + * @release_db_resources: Release device hold on DMA memory holding doorbell + * info (AdminQ only) * @get_ptype_map: Learn packet type map from device and store it in @priv * @configure_rss: Set up default RSS configuration * @setup_stats_report: Set up DMA region for stats report (AdminQ only) @@ -844,6 +847,8 @@ struct gve_ctrl_ops { void (*unmap_db_bar)(struct gve_priv *priv); void (*set_num_queues)(struct gve_priv *priv); int (*set_num_ntfy_blks)(struct gve_priv *priv); + int (*request_db_info)(struct gve_priv *priv); + void (*release_db_resources)(struct gve_priv *priv); int (*get_ptype_map)(struct gve_priv *priv); int (*configure_rss)(struct gve_priv *priv, struct ethtool_rxfh_param *param); @@ -1164,6 +1169,11 @@ static inline u32 gve_rx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx) return (priv->num_ntfy_blks / 2) + queue_idx; } +static inline u32 gve_ntfy_to_msix_idx(struct gve_priv *priv, u32 ntfy_blk_idx) +{ + return ntfy_blk_idx; +} + static inline bool gve_is_qpl(struct gve_priv *priv) { return priv->queue_format == GVE_GQI_QPL_FORMAT || diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 1176e13fafc0..b89825a85db8 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1718,3 +1718,40 @@ void gve_adminq_unmap_db_bar(struct gve_priv *priv) pci_iounmap(pdev, priv->db_bar2); } + +int gve_adminq_request_db_info(struct gve_priv *priv) +{ + int err; + int i; + + err = gve_adminq_configure_device_resources(priv, + priv->counter_array_bus, + priv->num_event_counters, + priv->irq_db_indices_bus, + priv->num_ntfy_blks); + if (unlikely(err)) { + dev_err(&priv->pdev->dev, + "could not setup device_resources: err=%d\n", err); + return -ENXIO; + } + + for (i = 0; i < priv->num_ntfy_blks; i++) + priv->ntfy_blocks[i].irq_db_index = + &priv->irq_db_indices[i].index; + return 0; +} + +void gve_adminq_release_db_resources(struct gve_priv *priv) +{ + int err; + + /* Log error in deconfigure device, but don't fail. This is only ever + * called as a reset is about to be triggered, so it would be redundant + * to trigger a reset. + */ + err = gve_adminq_deconfigure_device_resources(priv); + if (err) + dev_err(&priv->pdev->dev, + "Could not deconfigure device resources: err=%d\n", + err); +} diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 5e51c060e237..52172bf228eb 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -657,4 +657,6 @@ int gve_adminq_set_num_ntfy_blks(struct gve_priv *priv); void gve_adminq_set_num_queues(struct gve_priv *priv); int gve_adminq_map_db_bar(struct gve_priv *priv); void gve_adminq_unmap_db_bar(struct gve_priv *priv); +int gve_adminq_request_db_info(struct gve_priv *priv); +void gve_adminq_release_db_resources(struct gve_priv *priv); #endif /* _GVE_ADMINQ_H */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 01a271680d78..d8fafe56f5b8 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -203,6 +203,30 @@ static void gve_free_counter_array(struct gve_priv *priv) priv->counter_array = NULL; } +static int gve_alloc_irq_db_indices(struct gve_priv *priv) +{ + priv->irq_db_indices = + dma_alloc_coherent(&priv->pdev->dev, + priv->num_ntfy_blks * + sizeof(*priv->irq_db_indices), + &priv->irq_db_indices_bus, GFP_KERNEL); + if (!priv->irq_db_indices) + return -ENOMEM; + + return 0; +} + +static void gve_free_irq_db_indices(struct gve_priv *priv) +{ + if (!priv->irq_db_indices) + return; + + dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * + sizeof(*priv->irq_db_indices), + priv->irq_db_indices, priv->irq_db_indices_bus); + priv->irq_db_indices = NULL; +} + /* NIC requests to report stats */ static void gve_stats_report_task(struct work_struct *work) { @@ -428,15 +452,6 @@ int gve_napi_poll_dqo(struct napi_struct *napi, int budget) static void gve_free_notify_blocks(struct gve_priv *priv) { pci_disable_msix(priv->pdev); - if (priv->irq_db_indices) { - dma_free_coherent(&priv->pdev->dev, - priv->num_ntfy_blks * - sizeof(*priv->irq_db_indices), - priv->irq_db_indices, - priv->irq_db_indices_bus); - priv->irq_db_indices = NULL; - } - kvfree(priv->ntfy_blocks); priv->ntfy_blocks = NULL; kvfree(priv->msix_vectors); @@ -493,24 +508,14 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv) priv->rx_cfg.num_queues = priv->rx_cfg.max_queues; } - priv->irq_db_indices = - dma_alloc_coherent(&priv->pdev->dev, - priv->num_ntfy_blks * - sizeof(*priv->irq_db_indices), - &priv->irq_db_indices_bus, GFP_KERNEL); - if (!priv->irq_db_indices) { - err = -ENOMEM; - goto abort; - } - priv->ntfy_blocks = kvzalloc(priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks), GFP_KERNEL); if (!priv->ntfy_blocks) { err = -ENOMEM; goto abort; } - return 0; + return 0; abort: gve_free_notify_blocks(priv); return err; @@ -530,13 +535,14 @@ static void gve_teardown_notify_blocks(struct gve_priv *priv) for (i = 0; i < priv->num_ntfy_blks; i++) { struct gve_notify_block *block = &priv->ntfy_blocks[i]; + int msix_idx = gve_ntfy_to_msix_idx(priv, i); if (!block->irq_requested) continue; - irq_set_affinity_hint(priv->msix_vectors[i].vector, + irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, NULL); - free_irq(priv->msix_vectors[i].vector, block); + free_irq(priv->msix_vectors[msix_idx].vector, block); block->irq_requested = false; } } @@ -548,7 +554,7 @@ static int gve_setup_notify_blocks(struct gve_priv *priv) int i; int err; - /* Setup Management Vector - the last vector */ + /* Setup Management Vector */ snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), "gve-mgmnt@pci:%s", pci_name(priv->pdev)); err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, @@ -559,12 +565,11 @@ static int gve_setup_notify_blocks(struct gve_priv *priv) } priv->mgmt_irq_requested = true; - /* Setup the other blocks - the first n-1 vectors */ node_mask = gve_get_node_mask(priv); cur_cpu = cpumask_first(node_mask); for (i = 0; i < priv->num_ntfy_blks; i++) { struct gve_notify_block *block = &priv->ntfy_blocks[i]; - int msix_idx = i; + int msix_idx = gve_ntfy_to_msix_idx(priv, i); snprintf(block->name, sizeof(block->name), "gve-ntfy-blk%d@pci:%s", i, pci_name(priv->pdev)); @@ -574,14 +579,13 @@ static int gve_setup_notify_blocks(struct gve_priv *priv) IRQF_NO_AUTOEN, block->name, block); if (err) { dev_err(&priv->pdev->dev, - "Failed to receive msix vector %d\n", i); + "Failed to receive msix vector %d\n", msix_idx); goto abort; } block->irq = priv->msix_vectors[msix_idx].vector; block->irq_requested = true; irq_set_affinity_and_hint(block->irq, cpumask_of(cur_cpu)); - block->irq_db_index = &priv->irq_db_indices[i].index; cur_cpu = cpumask_next(cur_cpu, node_mask); /* Wrap once CPUs in the node have been exhausted, or when @@ -598,7 +602,6 @@ abort: return err; } - static void gve_tx_get_curr_alloc_cfg(struct gve_priv *priv, struct gve_tx_alloc_rings_cfg *cfg) { @@ -665,9 +668,10 @@ static void gve_free_control_plane_resources(struct gve_priv *priv) priv->ptype_lut_dqo = NULL; gve_teardown_clock(priv); - gve_free_stats_report(priv); - gve_free_notify_blocks(priv); + gve_free_irq_db_indices(priv); gve_free_counter_array(priv); + gve_free_notify_blocks(priv); + gve_free_stats_report(priv); gve_free_rss_config_cache(priv); gve_free_flow_rule_caches(priv); } @@ -680,15 +684,18 @@ static int gve_alloc_control_plane_resources(struct gve_priv *priv) if (err) return err; err = gve_alloc_rss_config_cache(priv); - if (err) - goto abort; - err = gve_alloc_counter_array(priv); if (err) goto abort; err = gve_alloc_notify_blocks(priv); if (err) goto abort; err = gve_alloc_stats_report(priv); + if (err) + goto abort; + err = gve_alloc_counter_array(priv); + if (err) + goto abort; + err = gve_alloc_irq_db_indices(priv); if (err) goto abort; @@ -718,15 +725,9 @@ static int gve_setup_control_plane_resources(struct gve_priv *priv) const struct gve_ctrl_ops *ops = priv->ctrl_ops; int err; - err = gve_adminq_configure_device_resources(priv, - priv->counter_array_bus, - priv->num_event_counters, - priv->irq_db_indices_bus, - priv->num_ntfy_blks); - if (unlikely(err)) { - dev_err(&priv->pdev->dev, - "could not setup device_resources: err=%d\n", err); - err = -ENXIO; + err = ops->request_db_info(priv); + if (err) { + dev_err(&priv->pdev->dev, "Failed to get db info"); return err; } @@ -735,7 +736,7 @@ static int gve_setup_control_plane_resources(struct gve_priv *priv) if (err) { dev_err(&priv->pdev->dev, "Failed to get ptype map: err=%d\n", err); - goto deconfigure_device; + goto release_db_resources; } } @@ -750,7 +751,7 @@ static int gve_setup_control_plane_resources(struct gve_priv *priv) err = gve_init_rss_config(priv, priv->rx_cfg.num_queues); if (err) { dev_err(&priv->pdev->dev, "Failed to init RSS config"); - goto deconfigure_device; + goto release_db_resources; } err = ops->setup_stats_report(priv, priv->stats_report_len, @@ -763,8 +764,8 @@ static int gve_setup_control_plane_resources(struct gve_priv *priv) gve_set_device_resources_ok(priv); return 0; -deconfigure_device: - gve_adminq_deconfigure_device_resources(priv); +release_db_resources: + ops->release_db_resources(priv); return err; } @@ -799,11 +800,7 @@ static void gve_teardown_control_plane_resources(struct gve_priv *priv) if (err) dev_err(&priv->pdev->dev, "Failed to detach stats report: err=%d\n", err); - err = gve_adminq_deconfigure_device_resources(priv); - if (err) - dev_err(&priv->pdev->dev, - "Could not deconfigure device resources: err=%d\n", - err); + ops->release_db_resources(priv); } gve_clear_device_resources_ok(priv); @@ -2507,6 +2504,8 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .reset_flow_rules = gve_adminq_reset_flow_rules, .setup_stats_report = gve_adminq_report_stats, .configure_rss = gve_adminq_configure_rss, + .request_db_info = gve_adminq_request_db_info, + .release_db_resources = gve_adminq_release_db_resources, }; static int gve_init_priv(struct gve_priv *priv) From 5e86cf5e2f24223db594b77777eb6737c4b8c672 Mon Sep 17 00:00:00 2001 From: Joshua Washington Date: Wed, 30 Sep 2026 19:04:26 +0000 Subject: [PATCH 1131/2126] gve: setup and teardown management interrupts Introduce control ops to setup/teardown control plane IRQs. Admin queue-specific functionality is moved to admin queue files. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-11-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 4 +++ drivers/net/ethernet/google/gve/gve_adminq.c | 32 ++++++++++++++++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 2 ++ drivers/net/ethernet/google/gve/gve_main.c | 26 +++++----------- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 6c46c842070b..016e85ed91a5 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -837,6 +837,8 @@ struct gve_device_info { * @request_db_info: Request and store doorbell information into @priv * @release_db_resources: Release device hold on DMA memory holding doorbell * info (AdminQ only) + * @setup_mgmt_irq: Setup control plane IRQ + * @teardown_mgmt_irq: Teardown control plane IRQ * @get_ptype_map: Learn packet type map from device and store it in @priv * @configure_rss: Set up default RSS configuration * @setup_stats_report: Set up DMA region for stats report (AdminQ only) @@ -849,6 +851,8 @@ struct gve_ctrl_ops { int (*set_num_ntfy_blks)(struct gve_priv *priv); int (*request_db_info)(struct gve_priv *priv); void (*release_db_resources)(struct gve_priv *priv); + int (*setup_mgmt_irq)(struct gve_priv *priv); + void (*teardown_mgmt_irq)(struct gve_priv *priv); int (*get_ptype_map)(struct gve_priv *priv); int (*configure_rss)(struct gve_priv *priv, struct ethtool_rxfh_param *param); diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index b89825a85db8..05b011417bf3 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1755,3 +1755,35 @@ void gve_adminq_release_db_resources(struct gve_priv *priv) "Could not deconfigure device resources: err=%d\n", err); } + +static irqreturn_t gve_mgmnt_intr(int irq, void *arg) +{ + struct gve_priv *priv = arg; + + queue_work(priv->gve_wq, &priv->service_task); + return IRQ_HANDLED; +} + +int gve_adminq_setup_mgmt_irq(struct gve_priv *priv) +{ + int err; + + snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), + "gve-mgmnt@pci:%s", pci_name(priv->pdev)); + err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, + gve_mgmnt_intr, 0, priv->mgmt_msix_name, priv); + if (err) + return err; + + priv->mgmt_irq_requested = true; + + return 0; +} + +void gve_adminq_teardown_mgmt_irq(struct gve_priv *priv) +{ + if (priv->mgmt_irq_requested) { + free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); + priv->mgmt_irq_requested = false; + } +} diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 52172bf228eb..0b48e9f2a82a 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -659,4 +659,6 @@ int gve_adminq_map_db_bar(struct gve_priv *priv); void gve_adminq_unmap_db_bar(struct gve_priv *priv); int gve_adminq_request_db_info(struct gve_priv *priv); void gve_adminq_release_db_resources(struct gve_priv *priv); +int gve_adminq_setup_mgmt_irq(struct gve_priv *priv); +void gve_adminq_teardown_mgmt_irq(struct gve_priv *priv); #endif /* _GVE_ADMINQ_H */ diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index d8fafe56f5b8..63377bf2a0f8 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -291,14 +291,6 @@ static void gve_free_stats_report(struct gve_priv *priv) priv->stats_report = NULL; } -static irqreturn_t gve_mgmnt_intr(int irq, void *arg) -{ - struct gve_priv *priv = arg; - - queue_work(priv->gve_wq, &priv->service_task); - return IRQ_HANDLED; -} - static irqreturn_t gve_intr(int irq, void *arg) { struct gve_notify_block *block = arg; @@ -523,12 +515,10 @@ abort: static void gve_teardown_notify_blocks(struct gve_priv *priv) { + const struct gve_ctrl_ops *ops = priv->ctrl_ops; int i; - if (priv->mgmt_irq_requested) { - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); - priv->mgmt_irq_requested = false; - } + ops->teardown_mgmt_irq(priv); if (!priv->ntfy_blocks) return; @@ -549,21 +539,19 @@ static void gve_teardown_notify_blocks(struct gve_priv *priv) static int gve_setup_notify_blocks(struct gve_priv *priv) { + const struct gve_ctrl_ops *ops = priv->ctrl_ops; const struct cpumask *node_mask; unsigned int cur_cpu; int i; int err; /* Setup Management Vector */ - snprintf(priv->mgmt_msix_name, sizeof(priv->mgmt_msix_name), - "gve-mgmnt@pci:%s", pci_name(priv->pdev)); - err = request_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, - gve_mgmnt_intr, 0, priv->mgmt_msix_name, priv); + err = ops->setup_mgmt_irq(priv); if (err) { - dev_err(&priv->pdev->dev, "Did not receive management vector.\n"); + dev_err(&priv->pdev->dev, + "Did not receive management vector.\n"); return err; } - priv->mgmt_irq_requested = true; node_mask = gve_get_node_mask(priv); cur_cpu = cpumask_first(node_mask); @@ -2506,6 +2494,8 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .configure_rss = gve_adminq_configure_rss, .request_db_info = gve_adminq_request_db_info, .release_db_resources = gve_adminq_release_db_resources, + .setup_mgmt_irq = gve_adminq_setup_mgmt_irq, + .teardown_mgmt_irq = gve_adminq_teardown_mgmt_irq, }; static int gve_init_priv(struct gve_priv *priv) From 71f905f14b834b965136504925655e916cae0fa5 Mon Sep 17 00:00:00 2001 From: Harshitha Ramamurthy Date: Wed, 30 Sep 2026 19:04:27 +0000 Subject: [PATCH 1132/2126] gve: add ctrl ops for queue operations Add the next few control ops to - create queues - destroy queues These changes are just moving existing code into ops, no functional change. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-12-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 4 ++ drivers/net/ethernet/google/gve/gve_adminq.c | 50 ++++++++++++++++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 2 + drivers/net/ethernet/google/gve/gve_main.c | 43 +++-------------- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 016e85ed91a5..00966b6a730f 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -843,6 +843,8 @@ struct gve_device_info { * @configure_rss: Set up default RSS configuration * @setup_stats_report: Set up DMA region for stats report (AdminQ only) * @reset_flow_rules: Flush all flow rules from device + * @create_queues: Sends commands to the device to create TX/RX queues. + * @destroy_queues: Sends commands to the device to destroy TX/RX queues. */ struct gve_ctrl_ops { int (*map_db_bar)(struct gve_priv *priv); @@ -861,6 +863,8 @@ struct gve_ctrl_ops { dma_addr_t stats_report_addr, u64 interval_ms); /* AQ-specific */ int (*reset_flow_rules)(struct gve_priv *priv); + int (*create_queues)(struct gve_priv *priv); + int (*destroy_queues)(struct gve_priv *priv); }; struct gve_priv { diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 05b011417bf3..54f235ea27c1 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -943,6 +943,30 @@ static void gve_set_default_rss_sizes(struct gve_priv *priv) } } +int gve_adminq_destroy_queues(struct gve_priv *priv) +{ + int num_tx_queues = gve_num_tx_queues(priv); + int err; + + err = gve_adminq_destroy_tx_queues(priv, 0, num_tx_queues); + if (err) { + netif_err(priv, drv, priv->dev, + "failed to destroy tx queues\n"); + /* This failure will trigger a reset - no need to clean up */ + return err; + } + netif_dbg(priv, drv, priv->dev, "destroyed tx queues\n"); + err = gve_adminq_destroy_rx_queues(priv, priv->rx_cfg.num_queues); + if (err) { + netif_err(priv, drv, priv->dev, + "failed to destroy rx queues\n"); + /* This failure will trigger a reset - no need to clean up */ + return err; + } + netif_dbg(priv, drv, priv->dev, "destroyed rx queues\n"); + return err; +} + static void gve_enable_supported_features(struct gve_priv *priv, u32 supported_features_mask, const struct gve_device_option_jumbo_frames @@ -1787,3 +1811,29 @@ void gve_adminq_teardown_mgmt_irq(struct gve_priv *priv) priv->mgmt_irq_requested = false; } } + +int gve_adminq_create_queues(struct gve_priv *priv) +{ + int num_tx_queues = gve_num_tx_queues(priv); + int err; + + err = gve_adminq_create_tx_queues(priv, 0, num_tx_queues); + if (err) { + netif_err(priv, drv, priv->dev, "failed to create %d tx queues\n", + num_tx_queues); + return err; + } + netif_dbg(priv, drv, priv->dev, "created %d tx queues\n", + num_tx_queues); + + err = gve_adminq_create_rx_queues(priv, priv->rx_cfg.num_queues); + if (err) { + netif_err(priv, drv, priv->dev, "failed to create %d rx queues\n", + priv->rx_cfg.num_queues); + return err; + } + netif_dbg(priv, drv, priv->dev, "created %d rx queues\n", + priv->rx_cfg.num_queues); + + return err; +} diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index 0b48e9f2a82a..d696e4932a8b 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -628,6 +628,8 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv, dma_addr_t db_array_bus_addr, u32 num_ntfy_blks); int gve_adminq_deconfigure_device_resources(struct gve_priv *priv); +int gve_adminq_create_queues(struct gve_priv *priv); +int gve_adminq_destroy_queues(struct gve_priv *priv); int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_queues); int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_queues); int gve_adminq_create_single_rx_queue(struct gve_priv *priv, u32 queue_index); diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 63377bf2a0f8..8d628c419972 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -944,33 +944,16 @@ static int gve_unregister_qpls(struct gve_priv *priv) static int gve_create_rings(struct gve_priv *priv) { - int num_tx_queues = gve_num_tx_queues(priv); int err; int i; - err = gve_adminq_create_tx_queues(priv, 0, num_tx_queues); + err = priv->ctrl_ops->create_queues(priv); if (err) { - netif_err(priv, drv, priv->dev, "failed to create %d tx queues\n", - num_tx_queues); /* This failure will trigger a reset - no need to clean * up */ return err; } - netif_dbg(priv, drv, priv->dev, "created %d tx queues\n", - num_tx_queues); - - err = gve_adminq_create_rx_queues(priv, priv->rx_cfg.num_queues); - if (err) { - netif_err(priv, drv, priv->dev, "failed to create %d rx queues\n", - priv->rx_cfg.num_queues); - /* This failure will trigger a reset - no need to clean - * up - */ - return err; - } - netif_dbg(priv, drv, priv->dev, "created %d rx queues\n", - priv->rx_cfg.num_queues); if (gve_is_gqi(priv)) { /* Rx data ring has been prefilled with packet buffers at queue @@ -1114,26 +1097,12 @@ free_tx: static int gve_destroy_rings(struct gve_priv *priv) { - int num_tx_queues = gve_num_tx_queues(priv); int err; - err = gve_adminq_destroy_tx_queues(priv, 0, num_tx_queues); - if (err) { - netif_err(priv, drv, priv->dev, - "failed to destroy tx queues\n"); - /* This failure will trigger a reset - no need to clean up */ - return err; - } - netif_dbg(priv, drv, priv->dev, "destroyed tx queues\n"); - err = gve_adminq_destroy_rx_queues(priv, priv->rx_cfg.num_queues); - if (err) { - netif_err(priv, drv, priv->dev, - "failed to destroy rx queues\n"); - /* This failure will trigger a reset - no need to clean up */ - return err; - } - netif_dbg(priv, drv, priv->dev, "destroyed rx queues\n"); - return 0; + err = priv->ctrl_ops->destroy_queues(priv); + + /* A failure will trigger a reset - no need to clean up */ + return err; } int gve_alloc_page(struct gve_priv *priv, struct device *dev, @@ -2496,6 +2465,8 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .release_db_resources = gve_adminq_release_db_resources, .setup_mgmt_irq = gve_adminq_setup_mgmt_irq, .teardown_mgmt_irq = gve_adminq_teardown_mgmt_irq, + .create_queues = gve_adminq_create_queues, + .destroy_queues = gve_adminq_destroy_queues, }; static int gve_init_priv(struct gve_priv *priv) From bbe522b0f237f7e25b68c57361b91953a563b733 Mon Sep 17 00:00:00 2001 From: Joshua Washington Date: Wed, 30 Sep 2026 19:04:28 +0000 Subject: [PATCH 1133/2126] gve: add link status/speed ctrl ops Refactor link status check to use a control plane op. Introduce new op for retrieving the link status in AQ mode. This op reads the link status from the device status register and stores the value in priv. Also add an op for retrieving link speed in AQ mode which calls into gve_adminq_report_link_speed. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Reviewed-by: Przemek Kitszel Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20260930190428.1130007-13-hramamurthy@google.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 5 ++++ drivers/net/ethernet/google/gve/gve_adminq.c | 10 +++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 1 + drivers/net/ethernet/google/gve/gve_ethtool.c | 3 +-- drivers/net/ethernet/google/gve/gve_main.c | 26 ++++++++++++------- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index 00966b6a730f..b7ce6e8632db 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -845,6 +845,8 @@ struct gve_device_info { * @reset_flow_rules: Flush all flow rules from device * @create_queues: Sends commands to the device to create TX/RX queues. * @destroy_queues: Sends commands to the device to destroy TX/RX queues. + * @report_link_status: Set link status into @priv->link_up + * @report_link_speed: Set link speed into @priv->link_speed */ struct gve_ctrl_ops { int (*map_db_bar)(struct gve_priv *priv); @@ -865,6 +867,8 @@ struct gve_ctrl_ops { int (*reset_flow_rules)(struct gve_priv *priv); int (*create_queues)(struct gve_priv *priv); int (*destroy_queues)(struct gve_priv *priv); + int (*report_link_status)(struct gve_priv *priv); + int (*report_link_speed)(struct gve_priv *priv); }; struct gve_priv { @@ -966,6 +970,7 @@ struct gve_priv { /* Gvnic device link speed from hypervisor. */ u64 link_speed; + bool link_up; bool up_before_suspend; /* True if dev was up before suspend */ bool mgmt_irq_requested; diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 54f235ea27c1..8b215fca9c1b 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1837,3 +1837,13 @@ int gve_adminq_create_queues(struct gve_priv *priv) return err; } + +int gve_adminq_report_link_status(struct gve_priv *priv) +{ + u32 status; + + status = ioread32be(&priv->reg_bar0->device_status); + WRITE_ONCE(priv->link_up, + !!(GVE_DEVICE_STATUS_LINK_STATUS_MASK & status)); + return 0; +} diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index d696e4932a8b..8daac5fd685a 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -643,6 +643,7 @@ int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len, dma_addr_t stats_report_addr, u64 interval); int gve_adminq_verify_driver_compatibility(struct gve_priv *priv); int gve_adminq_get_device_properties(struct gve_priv *priv); +int gve_adminq_report_link_status(struct gve_priv *priv); int gve_adminq_report_link_speed(struct gve_priv *priv); int gve_adminq_add_flow_rule(struct gve_priv *priv, struct gve_adminq_flow_rule *rule, u32 loc); int gve_adminq_del_flow_rule(struct gve_priv *priv, u32 loc); diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c index dd1c44fedc77..a3220c651438 100644 --- a/drivers/net/ethernet/google/gve/gve_ethtool.c +++ b/drivers/net/ethernet/google/gve/gve_ethtool.c @@ -749,12 +749,11 @@ static int gve_get_link_ksettings(struct net_device *netdev, int err = 0; if (priv->link_speed == 0) - err = gve_adminq_report_link_speed(priv); + err = priv->ctrl_ops->report_link_speed(priv); cmd->base.speed = priv->link_speed; cmd->base.duplex = DUPLEX_FULL; - return err; } diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 8d628c419972..0b84ae4ef7ad 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1509,15 +1509,18 @@ reset: return err; } -static void gve_handle_link_status(struct gve_priv *priv, bool link_status) +static void gve_handle_link_status(struct gve_priv *priv) { + bool link_up; + if (!gve_get_napi_enabled(priv)) return; - if (link_status == netif_carrier_ok(priv->dev)) + link_up = READ_ONCE(priv->link_up); + if (link_up == netif_carrier_ok(priv->dev)) return; - if (link_status) { + if (link_up) { netdev_info(priv->dev, "Device link is up.\n"); netif_carrier_on(priv->dev); } else { @@ -1544,7 +1547,6 @@ static int gve_set_xdp(struct gve_priv *priv, struct bpf_prog *prog, { struct bpf_prog *old_prog; int err = 0; - u32 status; old_prog = READ_ONCE(priv->xdp_prog); if (!netif_running(priv->dev)) { @@ -1571,8 +1573,8 @@ static int gve_set_xdp(struct gve_priv *priv, struct bpf_prog *prog, bpf_prog_put(old_prog); out: - status = ioread32be(&priv->reg_bar0->device_status); - gve_handle_link_status(priv, GVE_DEVICE_STATUS_LINK_STATUS_MASK & status); + priv->ctrl_ops->report_link_status(priv); + gve_handle_link_status(priv); return err; } @@ -2003,11 +2005,11 @@ static void gve_turnup(struct gve_priv *priv) static void gve_turnup_and_check_status(struct gve_priv *priv) { - u32 status; + const struct gve_ctrl_ops *ops = priv->ctrl_ops; gve_turnup(priv); - status = ioread32be(&priv->reg_bar0->device_status); - gve_handle_link_status(priv, GVE_DEVICE_STATUS_LINK_STATUS_MASK & status); + ops->report_link_status(priv); + gve_handle_link_status(priv); } static struct gve_notify_block *gve_get_tx_notify_block(struct gve_priv *priv, @@ -2335,12 +2337,14 @@ static void gve_service_task(struct work_struct *work) { struct gve_priv *priv = container_of(work, struct gve_priv, service_task); + const struct gve_ctrl_ops *ops = priv->ctrl_ops; u32 status = ioread32be(&priv->reg_bar0->device_status); gve_handle_status(priv, status); gve_handle_reset(priv); - gve_handle_link_status(priv, GVE_DEVICE_STATUS_LINK_STATUS_MASK & status); + ops->report_link_status(priv); + gve_handle_link_status(priv); } static void gve_set_netdev_xdp_features(struct gve_priv *priv) @@ -2467,6 +2471,8 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .teardown_mgmt_irq = gve_adminq_teardown_mgmt_irq, .create_queues = gve_adminq_create_queues, .destroy_queues = gve_adminq_destroy_queues, + .report_link_status = gve_adminq_report_link_status, + .report_link_speed = gve_adminq_report_link_speed, }; static int gve_init_priv(struct gve_priv *priv) From 0de04d82b63c045b82c78bb47ef9510f9c9e5704 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 1 Oct 2026 09:38:58 -0700 Subject: [PATCH 1134/2126] eth: mpnic: use WRITE_ONCE() for BDQ head and tail updates Convert writes to BDQ ring head and tail in the NAPI path to WRITE_ONCE(), so that a buffer NAPI depletion check task later in the series can READ_ONCE() those fields from a workqueue outside of NAPI. The remaining writers in mpnic_enable_bdq() and mpnic_clean_bdq() run with NAPI disabled and the instance lock, so don't bother converting them. The NAPI depletion check later in the series will run under the instance lock. Signed-off-by: Daniel Zahka Reviewed-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20261001-linux-mpnic-v1-1-6422ee74233a@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index edb07b7f334b..49061c7316d5 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -384,7 +384,7 @@ static unsigned int __mpnic_fill_bdq(struct mpnic_ring *bdq) static void __mpnic_bdq_commit_tail(struct mpnic_ring *bdq, unsigned int tail) { if (bdq->tail != tail) { - bdq->tail = tail; + WRITE_ONCE(bdq->tail, tail); writeq(tail, bdq->doorbell); } @@ -483,7 +483,7 @@ mpnic_pkt_prepare(u64 rcd, struct mpnic_rcq_state *state, pg_start = mpnic_hdr_pg_start(pg_off); page = mpnic_page_pool_get(&state->hdr, &qt->sub0, pg_idx); - qt->sub0.head = (pg_idx + 1) & qt->sub0.size_mask; + WRITE_ONCE(qt->sub0.head, (pg_idx + 1) & qt->sub0.size_mask); /* Short-cut the end calculation if the page is fully consumed */ pg_end = fin ? page_size(page) : mpnic_hdr_pg_end(pg_off, len); @@ -513,7 +513,7 @@ mpnic_add_rx_frag(u64 rcd, struct mpnic_rcq_state *state, struct page *page; page = mpnic_page_pool_get(&state->payld, &qt->sub1, pg_idx); - qt->sub1.head = (pg_idx + 1) & qt->sub1.size_mask; + WRITE_ONCE(qt->sub1.head, (pg_idx + 1) & qt->sub1.size_mask); truesz = (fin ? page_size(page) : ALIGN(pg_off + len, 128)) - pg_off; From d990f86c796b6cbe84ecaa139e3e3c1ac00ae5de Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 1 Oct 2026 09:38:59 -0700 Subject: [PATCH 1135/2126] eth: mpnic: add a service task Add a service task that runs while the netdevice is running. For now, the service task does nothing besides conditionally reschedule itself. Signed-off-by: Daniel Zahka Reviewed-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20261001-linux-mpnic-v1-2-6422ee74233a@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/mpnic/mpnic.h | 3 +++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 3 +++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic.h b/drivers/net/ethernet/meta/mpnic/mpnic.h index 78359ab6abb1..8b08af0fadcc 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "mpnic_csr.h" @@ -27,6 +28,8 @@ struct mpnic_dev { u32 __iomem *uc_addr0; + struct delayed_work service_task; + u16 num_irqs; u64 dsn; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c index 2c0309d0c221..bd10df4a9d46 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -35,6 +35,8 @@ static int mpnic_open(struct net_device *netdev) netif_tx_wake_all_queues(netdev); netif_carrier_on(netdev); + schedule_delayed_work(&mpn->mpd->service_task, HZ); + return 0; err_free_resources: @@ -48,6 +50,7 @@ static int mpnic_stop(struct net_device *netdev) { struct mpnic_net *mpn = netdev_priv(netdev); + cancel_delayed_work(&mpn->mpd->service_task); netif_carrier_off(netdev); mpnic_napi_disable(mpn); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c index 968cd611b8ea..17eae5a9ba16 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c @@ -53,6 +53,20 @@ u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg) return ~0ULL; } +static void mpnic_service_task(struct work_struct *work) +{ + struct mpnic_dev *mpd = container_of(to_delayed_work(work), + struct mpnic_dev, service_task); + struct net_device *netdev = mpd->netdev; + + netdev_lock(netdev); + + if (netif_running(netdev)) + schedule_delayed_work(&mpd->service_task, HZ); + + netdev_unlock(netdev); +} + static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev) { struct mpnic_dev *mpd; @@ -69,6 +83,8 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev) mpd->readrq = pcie_get_readrq(pdev); mpd->relaxed_ord = pcie_relaxed_ordering_enabled(pdev); + INIT_DELAYED_WORK(&mpd->service_task, mpnic_service_task); + return mpd; } @@ -162,6 +178,7 @@ static void mpnic_remove(struct pci_dev *pdev) struct mpnic_dev *mpd = pci_get_drvdata(pdev); unregister_netdev(mpd->netdev); + cancel_delayed_work_sync(&mpd->service_task); mpnic_netdev_free(mpd); mpnic_free_irqs(mpd); kfree(mpd); From 9e072eda51cadc944c7c0d6b64d9c7169d43a5ad Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 1 Oct 2026 09:39:00 -0700 Subject: [PATCH 1136/2126] eth: mpnic: set Rx buffer minimums using page size and mtu Set buffer based drop thresholds in the Rx path based on page size and the max MTU supported. The device will drop packets if it does not have at least the minimum number of completely unused buffer descriptors available. These thresholds are currently set to 17 BDs for both HPQ and PPQ. These are overly conservative. With our current max MTU of 9742B, the settings we should target are: 4KiB page size: 1 HPQ, 3 PPQ 64KiB page size: 1 HPQ, 1 PPQ The HPQ and PPQ rings are always given PAGE_SIZE sized buffers. The RDE_CTL register encodes the thresholds as one less than the number of BDs needed. Signed-off-by: Daniel Zahka Reviewed-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20261001-linux-mpnic-v1-3-6422ee74233a@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/mpnic/mpnic_init.c | 13 +++++++++---- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_init.c b/drivers/net/ethernet/meta/mpnic/mpnic_init.c index 2daed458f5fc..ace4124158fb 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_init.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_init.c @@ -10,6 +10,7 @@ #include #include "mpnic.h" +#include "mpnic_txrx.h" #define MPNIC_MEM_INIT_POLL_US 500 #define MPNIC_MEM_INIT_TO_US 5000 @@ -272,10 +273,14 @@ static void mpnic_rxglb_init(struct mpnic_dev *mpd) * the per-queue prefetch FIFO. */ mpnic_wr64(mpd, MPNIC_RDE_CTL, - FIELD_PREP(MPNIC_RDE_CTL_HPQ_DROP_THRESHOLD, 16) | - FIELD_PREP(MPNIC_RDE_CTL_PPQ_DROP_THRESHOLD, 16) | - FIELD_PREP(MPNIC_RDE_CTL_HPQ_LOCAL_DROP_THRESHOLD, 16) | - FIELD_PREP(MPNIC_RDE_CTL_PPQ_LOCAL_DROP_THRESHOLD, 16)); + FIELD_PREP(MPNIC_RDE_CTL_HPQ_DROP_THRESHOLD, + MPNIC_RX_HPQ_DROP_THRS - 1) | + FIELD_PREP(MPNIC_RDE_CTL_PPQ_DROP_THRESHOLD, + MPNIC_RX_PPQ_DROP_THRS - 1) | + FIELD_PREP(MPNIC_RDE_CTL_HPQ_LOCAL_DROP_THRESHOLD, + MPNIC_RX_HPQ_DROP_THRS - 1) | + FIELD_PREP(MPNIC_RDE_CTL_PPQ_LOCAL_DROP_THRESHOLD, + MPNIC_RX_PPQ_DROP_THRS - 1)); /* Receive side coalescing is not supported yet */ mpnic_wr64(mpd, MPNIC_RSC_GLOBAL_CONF, diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 834eb9bfffd1..9397010557eb 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -58,6 +58,12 @@ struct mpnic_net; #define MPNIC_MAX_JUMBO_FRAME_SIZE 9742 +#define MPNIC_RX_HPQ_DROP_THRS \ + DIV_ROUND_UP(MPNIC_RX_HROOM + MPNIC_RX_MAX_HDR + MPNIC_RX_TROOM, \ + PAGE_SIZE) +#define MPNIC_RX_PPQ_DROP_THRS \ + DIV_ROUND_UP(MPNIC_MAX_JUMBO_FRAME_SIZE, PAGE_SIZE) + /* The page a buffer descriptor queue is currently handing out. Records * how many of the references taken on it are still unused. */ From 56f2178ff7f6c1f458eeb5f79ab2385028ae8a02 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Thu, 1 Oct 2026 09:39:01 -0700 Subject: [PATCH 1137/2126] eth: mpnic: add a NAPI depletion check The Rx path can wedge if page pool allocations fail in __mpnic_fill_bdq(). The problematic sequence is: page pool allocations fail, bdq rings are empty, device receives packet from the network, but drops it for lack of buffer space and does not raise interrupt, mpnic_poll() does not run, so page pool allocations are not retried. To break out of this cycle, we can add a depletion check to our service task. The depletion check checks if posted buffers are under a low watermark, and raises a completion queue interrupt, so that mpnic_poll will run on the corresponding napi vector. A note about the lock free reads: We don't bother synchronizing the ring head and tail reads with mpnic_poll(), because a false positive signal would simply raise a spurious interrupt scheduling mpnic_poll(), and a false negative signal will result in a retry, where if mpnic_poll() has truly not been running, should then report accurately whether or not posted Rx buffers are low. Signed-off-by: Daniel Zahka Reviewed-by: Harshitha Ramamurthy Link: https://patch.msgid.link/20261001-linux-mpnic-v1-4-6422ee74233a@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 4 +++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 31 ++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 1 + 3 files changed, 36 insertions(+) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c index 17eae5a9ba16..125fb26edf93 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c @@ -11,6 +11,7 @@ #include "mpnic.h" #include "mpnic_netdev.h" +#include "mpnic_txrx.h" #define PCI_DEVICE_ID_META_MPNIC 0x0014 @@ -61,6 +62,9 @@ static void mpnic_service_task(struct work_struct *work) netdev_lock(netdev); + if (netif_carrier_ok(netdev)) + mpnic_napi_depletion_check(netdev_priv(netdev)); + if (netif_running(netdev)) schedule_delayed_work(&mpd->service_task, HZ); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index 49061c7316d5..5495e9a9aa65 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -55,6 +55,12 @@ static unsigned int mpnic_desc_unused(struct mpnic_ring *ring) return (ring->head - ring->tail - 1) & ring->size_mask; } +static unsigned int mpnic_desc_used(struct mpnic_ring *ring) +{ + return (READ_ONCE(ring->tail) - READ_ONCE(ring->head)) & + ring->size_mask; +} + static struct netdev_queue *mpnic_txring_txq(const struct net_device *dev, const struct mpnic_ring *ring) { @@ -1393,3 +1399,28 @@ void mpnic_napi_enable(struct mpnic_net *mpn) mpnic_wrfl(mpn->mpd); } + +void mpnic_napi_depletion_check(struct mpnic_net *mpn) +{ + int i, j, t; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (t = nv->txt_count, j = 0; j < nv->rxt_count; j++, t++) { + /* Check if BDs posted covers a max sized frame + * + 1 BD held by RDE as a spare + * + 1 BD of extra safety margin + */ + if (mpnic_desc_used(&nv->qt[t].sub0) < + MPNIC_RX_HPQ_DROP_THRS + 2 || + mpnic_desc_used(&nv->qt[t].sub1) < + MPNIC_RX_PPQ_DROP_THRS + 2) { + mpnic_nv_irq_trigger(nv); + break; + } + } + } + + mpnic_wrfl(mpn->mpd); +} diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 9397010557eb..767d87a36c35 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -148,6 +148,7 @@ int mpnic_set_netif_queues(struct mpnic_net *mpn); void mpnic_reset_netif_queues(struct mpnic_net *mpn); void mpnic_napi_enable(struct mpnic_net *mpn); void mpnic_napi_disable(struct mpnic_net *mpn); +void mpnic_napi_depletion_check(struct mpnic_net *mpn); void mpnic_enable(struct mpnic_net *mpn); void mpnic_disable(struct mpnic_net *mpn); void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd); From 095dc989f0025f2d37aee54329224f4ee6ab8bfe Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Thu, 1 Oct 2026 21:21:37 +0200 Subject: [PATCH 1138/2126] selftests/net: add SO_RESERVE_MEM test Add a kselftest suite covering SO_RESERVE_MEM behavior: - Reject unsupported socket types (UDP/SOCK_DGRAM, UNIX/SOCK_STREAM, SOCK_RAW, MPTCP) with EOPNOTSUPP, for both zero and non-zero values. - Validate bounds (negative values and values > SZ_1G return EINVAL). - Verify reserve adjustments (increase, decrease, page rounding, and reset to 0) and corresponding sk_meminfo[SK_MEMINFO_FWD_ALLOC] changes via getsockopt(SO_MEMINFO). - Exercise cgroup v2 memory.max enforcement returning ENOMEM when the requested reservation exceeds the cgroup limit. - Verify that a child socket returned by accept() starts with a 0 reserve even when its parent listener configured a non-zero SO_RESERVE_MEM. - Verify reserve retention across TCP send/receive/ACK cycles. Each test runs in private mount and network namespaces. cgroup2 is mounted on a private tmpfs, so nothing is left behind in the host filesystem. The test process is moved to a dedicated leaf cgroup, and back to its original cgroup on teardown. The memory controller is enabled in the root of the hierarchy if needed, and left enabled like selftests/cgroup do, as disabling it could break other users. Also enable CONFIG_CGROUPS=y and CONFIG_MEMCG=y in tools/testing/selftests/net/config. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261001192137.309983-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 2 + tools/testing/selftests/net/so_reserve_mem.c | 448 +++++++++++++++++++ 4 files changed, 452 insertions(+) create mode 100644 tools/testing/selftests/net/so_reserve_mem.c diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore index dacd36ed8455..21412510ac26 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore @@ -41,6 +41,7 @@ skf_net_off socket so_incoming_cpu so_netns_cookie +so_reserve_mem so_rcv_listener stress_reuseport_listen tap diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index cab3f2c90039..54beea2e348c 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -197,6 +197,7 @@ TEST_GEN_PROGS := \ sk_connect_zero_addr \ sk_so_peek_off \ so_incoming_cpu \ + so_reserve_mem \ tap \ tcp_port_share \ tls \ diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index 737e7e6327b3..d355cf980597 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -7,6 +7,7 @@ CONFIG_BRIDGE_VLAN_FILTERING=y CONFIG_CAN=m CONFIG_CAN_DEV=m CONFIG_CAN_VXCAN=m +CONFIG_CGROUPS=y CONFIG_CRYPTO_ARIA=y CONFIG_CRYPTO_CHACHA20POLY1305=m CONFIG_CRYPTO_SHA1=y @@ -61,6 +62,7 @@ CONFIG_L2TP_V3=y CONFIG_MACSEC=m CONFIG_MACVLAN=y CONFIG_MACVTAP=y +CONFIG_MEMCG=y CONFIG_MPLS=y CONFIG_MPLS_IPTUNNEL=m CONFIG_MPLS_ROUTING=m diff --git a/tools/testing/selftests/net/so_reserve_mem.c b/tools/testing/selftests/net/so_reserve_mem.c new file mode 100644 index 000000000000..aca5960ddff2 --- /dev/null +++ b/tools/testing/selftests/net/so_reserve_mem.c @@ -0,0 +1,448 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kselftest_harness.h" + +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif + +#define SO_RESERVE_MEM_MAX (1 << 30) + +/* cgroup2 is mounted here, on a tmpfs, in a private mount namespace. */ +#define CG_TMP "/tmp" +#define CG_MNT CG_TMP "/cgroup2" + +static int cg_write(const char *dir, const char *file, const char *buf, + int flags) +{ + ssize_t len = strlen(buf); + char path[PATH_MAX]; + int fd, ret; + + snprintf(path, sizeof(path), "%s/%s", dir, file); + fd = open(path, O_WRONLY | flags); + if (fd < 0) + return -1; + ret = write(fd, buf, len) == len ? 0 : -1; + close(fd); + return ret; +} + +static int cg_read(const char *dir, const char *file, char *buf, size_t size) +{ + char path[PATH_MAX]; + ssize_t n; + int fd; + + snprintf(path, sizeof(path), "%s/%s", dir, file); + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + n = read(fd, buf, size - 1); + close(fd); + if (n < 0) + return -1; + buf[n] = '\0'; + return 0; +} + +static int cg_enter(const char *dir) +{ + char buf[32]; + + snprintf(buf, sizeof(buf), "%d\n", getpid()); + return cg_write(dir, "cgroup.procs", buf, 0); +} + +/* Path of the current cgroup, below CG_MNT. */ +static int cg_get_current(char *buf, size_t size) +{ + char line[PATH_MAX]; + int ret = -1; + FILE *f; + + f = fopen("/proc/self/cgroup", "r"); + if (!f) + return -1; + while (fgets(line, sizeof(line), f)) { + if (strncmp(line, "0::", 3)) + continue; + line[strcspn(line, "\n")] = '\0'; + if (snprintf(buf, size, "%s%s", CG_MNT, line + 3) < (int)size) + ret = 0; + break; + } + fclose(f); + return ret; +} + +static int get_reserve_mem(struct __test_metadata *_metadata, int fd) +{ + int val = -1; + socklen_t len = sizeof(val); + + EXPECT_EQ(getsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, &len), 0); + return val; +} + +static __u32 get_fwd_alloc(struct __test_metadata *_metadata, int fd) +{ + __u32 meminfo[SK_MEMINFO_VARS] = {}; + socklen_t len = sizeof(meminfo); + + EXPECT_EQ(getsockopt(fd, SOL_SOCKET, SO_MEMINFO, meminfo, &len), 0); + return meminfo[SK_MEMINFO_FWD_ALLOC]; +} + +/* Wait until a single SO_MEMINFO snapshot shows an empty write queue + * and at least @min_fwd_alloc bytes of forward alloc: ACK processing + * (possibly running on another CPU) first decrements sk_wmem_queued, + * then uncharges sk_forward_alloc. + */ +static void wait_wmem_drained(struct __test_metadata *_metadata, int fd, + __u32 min_fwd_alloc) +{ + __u32 meminfo[SK_MEMINFO_VARS] = {}; + socklen_t len; + int i; + + for (i = 0; i < 5000; i++) { + len = sizeof(meminfo); + ASSERT_EQ(getsockopt(fd, SOL_SOCKET, SO_MEMINFO, meminfo, &len), 0); + if (meminfo[SK_MEMINFO_WMEM_QUEUED] == 0 && + meminfo[SK_MEMINFO_FWD_ALLOC] >= min_fwd_alloc) + return; + usleep(1000); + } + EXPECT_EQ(meminfo[SK_MEMINFO_WMEM_QUEUED], 0U); + EXPECT_GE(meminfo[SK_MEMINFO_FWD_ALLOC], min_fwd_alloc); +} + +FIXTURE(so_reserve_mem) +{ + char cg_orig[PATH_MAX]; /* cgroup the test started in */ + char cg_test[PATH_MAX]; /* cgroup the test sockets are charged to */ + long page_size; + bool cg_created; +}; + +/* The cgroup2 mount lives in a private mount namespace which goes away + * with the test process, no need to unmount it. + */ +FIXTURE_TEARDOWN(so_reserve_mem) +{ + if (!self->cg_created) + return; + + /* Leave cg_test so that it can be removed. */ + EXPECT_EQ(cg_enter(self->cg_orig), 0); + EXPECT_EQ(rmdir(self->cg_test), 0); + self->cg_created = false; +} + +FIXTURE_SETUP(so_reserve_mem) +{ + struct ifreq ifr = { + .ifr_name = "lo", + .ifr_flags = IFF_UP, + }; + int fd, err, ret, val = 0; + char buf[256]; + + self->page_size = sysconf(_SC_PAGESIZE); + ASSERT_GT(self->page_size, 0); + + if (unshare(CLONE_NEWNS | CLONE_NEWNET)) + SKIP(return, "Failed to unshare namespaces (need root)"); + + /* Make sure the mounts below do not propagate to the host. */ + ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); + + if (mount("none", CG_TMP, "tmpfs", 0, NULL) || + mkdir(CG_MNT, 0755) || + mount("none", CG_MNT, "cgroup2", 0, NULL)) + SKIP(return, "Failed to mount cgroup2"); + + ASSERT_EQ(cg_get_current(self->cg_orig, sizeof(self->cg_orig)), 0); + + /* cg_test needs the memory controller to be enabled in the root of + * the hierarchy (which is not necessarily the global root cgroup + * when running in a cgroup namespace). Like selftests/cgroup, leave + * it enabled on exit: disabling it could break other users of the + * hierarchy. + */ + ASSERT_EQ(cg_read(CG_MNT, "cgroup.subtree_control", buf, sizeof(buf)), 0); + if (!strstr(buf, "memory") && + cg_write(CG_MNT, "cgroup.subtree_control", "+memory", 0)) + SKIP(return, "cgroup2 memory controller not available"); + + /* cg_test is a leaf cgroup, it can always host the test process. */ + snprintf(self->cg_test, sizeof(self->cg_test), + "%s/ksft_so_reserve_mem_%d", CG_MNT, getpid()); + if (mkdir(self->cg_test, 0755)) + SKIP(return, "Failed to create test cgroup"); + self->cg_created = true; + + ret = cg_enter(self->cg_test); + if (ret) + so_reserve_mem_teardown(_metadata, self, variant); + ASSERT_EQ(ret, 0); + + /* Bring up loopback and verify memcg socket accounting is enabled */ + fd = socket(AF_INET, SOCK_STREAM, 0); + ret = fd < 0 ? -1 : ioctl(fd, SIOCSIFFLAGS, &ifr); + if (ret) { + if (fd >= 0) + close(fd); + so_reserve_mem_teardown(_metadata, self, variant); + } + ASSERT_EQ(ret, 0); + + ret = setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)); + err = errno; + close(fd); + if (ret) { + so_reserve_mem_teardown(_metadata, self, variant); + if (err == EOPNOTSUPP) + SKIP(return, "memcg socket accounting not enabled"); + } + ASSERT_EQ(ret, 0); +} + +static void check_non_tcp_rejected(struct __test_metadata *_metadata, + int domain, int type, int protocol, + int val) +{ + int fd = socket(domain, type, protocol); + int zero = 0; + + if (fd < 0) { + /* Protocol not available, or no CAP_NET_RAW */ + EXPECT_TRUE(errno == EAFNOSUPPORT || + errno == EPROTONOSUPPORT || + errno == ENOPROTOOPT || + errno == EPERM || + errno == EACCES); + TH_LOG("socket(%d, %d, %d): %s, skipped", + domain, type, protocol, strerror(errno)); + return; + } + EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &zero, sizeof(zero)), -1); + EXPECT_EQ(errno, EOPNOTSUPP); + EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), -1); + EXPECT_EQ(errno, EOPNOTSUPP); + close(fd); +} + +TEST_F(so_reserve_mem, non_tcp_rejected) +{ + int val = self->page_size * 4; + + check_non_tcp_rejected(_metadata, AF_INET, SOCK_DGRAM, 0, val); + check_non_tcp_rejected(_metadata, AF_UNIX, SOCK_STREAM, 0, val); + check_non_tcp_rejected(_metadata, AF_INET, SOCK_RAW, IPPROTO_ICMP, val); + check_non_tcp_rejected(_metadata, AF_INET, SOCK_STREAM, IPPROTO_MPTCP, val); +} + +TEST_F(so_reserve_mem, grow_shrink_and_rounding) +{ + int ps = self->page_size; + int fd, val; + + fd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(fd, 0); + + EXPECT_EQ(get_reserve_mem(_metadata, fd), 0); + EXPECT_EQ(get_fwd_alloc(_metadata, fd), 0U); + + /* Negative or > SO_RESERVE_MEM_MAX value -> EINVAL */ + val = -1; + EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), -1); + EXPECT_EQ(errno, EINVAL); + + val = SO_RESERVE_MEM_MAX + 1; + EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), -1); + EXPECT_EQ(errno, EINVAL); + + val = INT_MAX; + EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), -1); + EXPECT_EQ(errno, EINVAL); + + /* 1 byte rounds up to 1 page */ + val = 1; + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, fd), ps); + EXPECT_EQ(get_fwd_alloc(_metadata, fd), (__u32)ps); + + /* Grow to 16 pages */ + val = 16 * ps; + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, fd), 16 * ps); + EXPECT_EQ(get_fwd_alloc(_metadata, fd), (__u32)(16 * ps)); + + /* Shrink by 1 byte (rounds delta down to 0 -> stays 16 pages) */ + val = 16 * ps - 1; + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, fd), 16 * ps); + EXPECT_EQ(get_fwd_alloc(_metadata, fd), (__u32)(16 * ps)); + + /* Shrink to 4 pages */ + val = 4 * ps; + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, fd), 4 * ps); + EXPECT_EQ(get_fwd_alloc(_metadata, fd), (__u32)(4 * ps)); + + /* Release all */ + val = 0; + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, fd), 0); + EXPECT_EQ(get_fwd_alloc(_metadata, fd), 0U); + + close(fd); +} + +TEST_F(so_reserve_mem, cgroup_memory_max) +{ + int ps = self->page_size; + char buf[32]; + int fd, val; + + /* The socket is charged to cg_test */ + fd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(fd, 0); + + /* Move the test process back to its original cgroup before lowering + * cg_test's memory.max, so that the limit only governs the socket's + * memcg charges and cannot trigger OOM on the test process itself. + */ + ASSERT_EQ(cg_enter(self->cg_orig), 0); + + /* Limit cg_test memory to 8 pages and try to reserve 128 pages. + * O_NONBLOCK: do not try to reclaim cg_test usage above the new limit. + */ + snprintf(buf, sizeof(buf), "%d\n", 8 * ps); + ASSERT_EQ(cg_write(self->cg_test, "memory.max", buf, O_NONBLOCK), 0); + + val = 128 * ps; + EXPECT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), -1); + EXPECT_EQ(errno, ENOMEM); + EXPECT_EQ(get_reserve_mem(_metadata, fd), 0); + + /* Restore unlimited memory.max */ + ASSERT_EQ(cg_write(self->cg_test, "memory.max", "max\n", 0), 0); + + val = 4 * ps; + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, fd), 4 * ps); + + close(fd); +} + +TEST_F(so_reserve_mem, accept_child_zero_reserve) +{ + struct sockaddr_in addr = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + }; + socklen_t alen = sizeof(addr); + int ps = self->page_size; + int lfd, cfd, sfd, val; + + lfd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(lfd, 0); + + /* Set SO_RESERVE_MEM on listener before listen() */ + val = 4 * ps; + ASSERT_EQ(setsockopt(lfd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + ASSERT_EQ(bind(lfd, (struct sockaddr *)&addr, sizeof(addr)), 0); + ASSERT_EQ(listen(lfd, 2), 0); + ASSERT_EQ(getsockname(lfd, (struct sockaddr *)&addr, &alen), 0); + + /* Grow SO_RESERVE_MEM on listener after listen() */ + val = 8 * ps; + ASSERT_EQ(setsockopt(lfd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, lfd), 8 * ps); + EXPECT_EQ(get_fwd_alloc(_metadata, lfd), (__u32)(8 * ps)); + + cfd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(cfd, 0); + ASSERT_EQ(connect(cfd, (struct sockaddr *)&addr, sizeof(addr)), 0); + + sfd = accept(lfd, NULL, NULL); + ASSERT_GE(sfd, 0); + + /* Child after accept() must have 0 reserve while listener keeps 8 pages */ + EXPECT_EQ(get_reserve_mem(_metadata, sfd), 0); + EXPECT_EQ(get_fwd_alloc(_metadata, sfd), 0U); + EXPECT_EQ(get_reserve_mem(_metadata, lfd), 8 * ps); + EXPECT_EQ(get_fwd_alloc(_metadata, lfd), (__u32)(8 * ps)); + + /* Child can still independently set its own SO_RESERVE_MEM */ + val = 6 * ps; + ASSERT_EQ(setsockopt(sfd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + EXPECT_EQ(get_reserve_mem(_metadata, sfd), 6 * ps); + EXPECT_EQ(get_fwd_alloc(_metadata, sfd), (__u32)(6 * ps)); + + close(sfd); + close(cfd); + close(lfd); +} + +TEST_F(so_reserve_mem, preserved_after_traffic) +{ + struct sockaddr_in addr = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + }; + socklen_t alen = sizeof(addr); + int ps = self->page_size; + int lfd, cfd, sfd, val; + char buf[8192] = {}; + + lfd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(lfd, 0); + ASSERT_EQ(bind(lfd, (struct sockaddr *)&addr, sizeof(addr)), 0); + ASSERT_EQ(listen(lfd, 1), 0); + ASSERT_EQ(getsockname(lfd, (struct sockaddr *)&addr, &alen), 0); + + cfd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(cfd, 0); + val = 16 * ps; + ASSERT_EQ(setsockopt(cfd, SOL_SOCKET, SO_RESERVE_MEM, &val, sizeof(val)), 0); + ASSERT_EQ(connect(cfd, (struct sockaddr *)&addr, sizeof(addr)), 0); + + sfd = accept(lfd, NULL, NULL); + ASSERT_GE(sfd, 0); + + /* Send & drain traffic; cfd must retain its 16-page forward alloc, + * while sfd (0 reserve) reclaims its forward alloc back to 0. + */ + ASSERT_EQ(send(cfd, buf, sizeof(buf), 0), (ssize_t)sizeof(buf)); + ASSERT_EQ(recv(sfd, buf, sizeof(buf), MSG_WAITALL), (ssize_t)sizeof(buf)); + wait_wmem_drained(_metadata, cfd, 16 * ps); + + EXPECT_EQ(get_fwd_alloc(_metadata, sfd), 0U); + + close(sfd); + close(cfd); + close(lfd); +} + +TEST_HARNESS_MAIN From a089139eb47bf80d13cc394f59a96b868d88c09e Mon Sep 17 00:00:00 2001 From: Sang-Hoon Choi Date: Fri, 2 Oct 2026 19:47:40 +0000 Subject: [PATCH 1139/2126] mlxsw: spectrum_router: destroy FIB hash table on bind failure mlxsw_sp_fib_create() initializes fib->ht before binding the LPM tree. If the bind fails, the error path releases the tree and frees fib without destroying the initialized hash table, leaking its bucket allocation. Destroy fib->ht on the post-initialization failure path. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Fixes: 2b52ce02e1d1 ("mlxsw: spectrum_router: Remove unnecessary prefix lengths from LPM tree") Reported-by: Changyul Lee Signed-off-by: Sang-Hoon Choi Reviewed-by: Ivan Vecera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003.final104.6f67a6ed1c4476b7@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index f4a435885ba4..e55f376881c1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -556,6 +556,7 @@ static struct mlxsw_sp_fib *mlxsw_sp_fib_create(struct mlxsw_sp *mlxsw_sp, err_lpm_tree_bind: mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree); + rhashtable_destroy(&fib->ht); err_rhashtable_init: kfree(fib); return ERR_PTR(err); From a032c035272aff415a3ac7ec48bd16aada5fc4bf Mon Sep 17 00:00:00 2001 From: Sang-Hoon Choi Date: Fri, 2 Oct 2026 19:47:40 +0000 Subject: [PATCH 1140/2126] nfp: flower: remove merge entry when conntrack offload fails nfp_ct_do_nft_merge() inserts nft_m_entry into nft_merge_tb and increments nft_merge_count before calling nfp_fl_ct_add_offload(). If that call fails, the error path removes the entry from its lists and frees it, but leaves the hash entry and count behind. Remove the hash entry and undo the count increment before freeing nft_m_entry. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Fixes: a87ceb3d42af ("nfp: flower: offload tc flows of multiple conntrack zones") Reported-by: Changyul Lee Signed-off-by: Sang-Hoon Choi Link: https://patch.msgid.link/20261003.final049.214b9988b1e1f0a7@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/netronome/nfp/flower/conntrack.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/netronome/nfp/flower/conntrack.c b/drivers/net/ethernet/netronome/nfp/flower/conntrack.c index c983e8b1799d..522ad555e8ec 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/conntrack.c +++ b/drivers/net/ethernet/netronome/nfp/flower/conntrack.c @@ -1260,6 +1260,10 @@ static int nfp_ct_do_nft_merge(struct nfp_fl_ct_zone_entry *zt, err_nft_ct_offload: nfp_fl_ct_del_offload(zt->priv->app, nft_m_entry->tc_flower_cookie, nft_m_entry->netdev); + WARN_ON_ONCE(rhashtable_remove_fast(&zt->nft_merge_tb, + &nft_m_entry->hash_node, + nfp_nft_ct_merge_params)); + zt->nft_merge_count--; err_nft_ct_merge_insert: list_del(&nft_m_entry->tc_merge_list); list_del(&nft_m_entry->nft_flow_list); From 57f66330c6bb264dd558ff7abc06dccf8191a37a Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Fri, 2 Oct 2026 11:42:07 +0200 Subject: [PATCH 1141/2126] net: move the netdev_ops checks into a helper register_netdevice() already does two ops sanity checks and is about to get a third. Collect them in netdev_check_ops(). The call stays after ndo_init() because drivers set features from there. Signed-off-by: Nicolai Buchwitz Link: https://patch.msgid.link/20261002094211.2350702-2-nb@tipi-net.de Signed-off-by: Jakub Kicinski --- net/core/dev.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 5ac08da8b9d7..a44bcfc29d54 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11451,6 +11451,24 @@ static void netdev_free_phy_link_topology(struct net_device *dev) } } +static int netdev_check_ops(struct net_device *dev) +{ + const struct net_device_ops *ops = dev->netdev_ops; + + if (((dev->hw_features | dev->features) & + NETIF_F_HW_VLAN_CTAG_FILTER) && + (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) { + netdev_WARN(dev, "Buggy VLAN acceleration in driver!\n"); + return -EINVAL; + } + + if (netdev_need_ops_lock(dev) && ops->ndo_set_rx_mode && + !ops->ndo_set_rx_mode_async) + netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n"); + + return 0; +} + /** * register_netdevice() - register a network device * @dev: device to register @@ -11506,19 +11524,9 @@ int register_netdevice(struct net_device *dev) } } - if (((dev->hw_features | dev->features) & - NETIF_F_HW_VLAN_CTAG_FILTER) && - (!dev->netdev_ops->ndo_vlan_rx_add_vid || - !dev->netdev_ops->ndo_vlan_rx_kill_vid)) { - netdev_WARN(dev, "Buggy VLAN acceleration in driver!\n"); - ret = -EINVAL; + ret = netdev_check_ops(dev); + if (ret) goto err_uninit; - } - - if (netdev_need_ops_lock(dev) && - dev->netdev_ops->ndo_set_rx_mode && - !dev->netdev_ops->ndo_set_rx_mode_async) - netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n"); ret = netdev_do_alloc_pcpu_stats(dev); if (ret) From 05fe748456ea1c276c666f462f1b41882e0179ef Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Fri, 2 Oct 2026 11:42:08 +0200 Subject: [PATCH 1142/2126] net: reject ops-locked drivers without ndo_set_rx_mode_async ndo_set_rx_mode cannot sleep and runs with netif_addr_lock_bh held, so an ops-locked driver cannot take the instance lock from it. ndo_set_rx_mode_async is the replacement and runs in process context. Registration has only warned about this since v7.1, long enough to find the offenders. Make it an error. Suggested-by: Jakub Kicinski Signed-off-by: Nicolai Buchwitz Link: https://patch.msgid.link/20261002094211.2350702-3-nb@tipi-net.de Signed-off-by: Jakub Kicinski --- net/core/dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index a44bcfc29d54..ca7f4844cc40 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11463,8 +11463,10 @@ static int netdev_check_ops(struct net_device *dev) } if (netdev_need_ops_lock(dev) && ops->ndo_set_rx_mode && - !ops->ndo_set_rx_mode_async) + !ops->ndo_set_rx_mode_async) { netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n"); + return -EINVAL; + } return 0; } From 810a662abcd56509db2db3e385a6979a0d5cf021 Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Fri, 2 Oct 2026 11:42:09 +0200 Subject: [PATCH 1143/2126] net: reject a netdev that implements only one hwtstamp NDO ndo_hwtstamp_get and ndo_hwtstamp_set only make sense as a pair. A driver providing just one gets no complaint today, and the mismatch turns up in user space, where a set can succeed while the matching get fails. Catch it at registration instead. Suggested-by: Jakub Kicinski Signed-off-by: Nicolai Buchwitz Link: https://patch.msgid.link/20261002094211.2350702-4-nb@tipi-net.de Signed-off-by: Jakub Kicinski --- net/core/dev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index ca7f4844cc40..db765cb5811e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11462,6 +11462,11 @@ static int netdev_check_ops(struct net_device *dev) return -EINVAL; } + if (!ops->ndo_hwtstamp_get != !ops->ndo_hwtstamp_set) { + netdev_WARN(dev, "driver implements only one hwtstamp NDO\n"); + return -EINVAL; + } + if (netdev_need_ops_lock(dev) && ops->ndo_set_rx_mode && !ops->ndo_set_rx_mode_async) { netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n"); From 9b84b36a527ccc831389628058a5bb1fcad66008 Mon Sep 17 00:00:00 2001 From: Luiz Angelo Daros de Luca Date: Fri, 2 Oct 2026 11:14:57 -0300 Subject: [PATCH 1144/2126] net: dsa: realtek: rtl8365mb: define masks using BIT() and GENMASK() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor register bitmask definitions to use the standard BIT() and GENMASK() macros instead of hardcoded hexadecimal values. This improves code readability, reducing the chance of errors such as unintentional gaps or overlaps. Introduce RTL8365MB_PORT_MASK as an alias for GENMASK(10, 0) to replace the repetitive 0x07FF values used across various port-related bitfields. This is a pure refactoring patch; no functional changes are introduced. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Alvin Šipraga Link: https://patch.msgid.link/20261002-realtek_bit-v1-1-771fb0e39083@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/rtl8365mb_main.c | 168 ++++++++++++----------- drivers/net/dsa/realtek/rtl8365mb_vlan.c | 4 +- 2 files changed, 87 insertions(+), 85 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 87ec924a0611..da06f952a053 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -132,32 +132,32 @@ #define RTL8365MB_MAGIC_VALUE 0x0249 /* Chip reset register */ -#define RTL8365MB_CHIP_RESET_REG 0x1322 -#define RTL8365MB_CHIP_RESET_DW8051_MASK 0x0010 -#define RTL8365MB_CHIP_RESET_SW_MASK 0x0002 -#define RTL8365MB_CHIP_RESET_HW_MASK 0x0001 +#define RTL8365MB_CHIP_RESET_REG 0x1322 +#define RTL8365MB_CHIP_RESET_DW8051_MASK BIT(4) +#define RTL8365MB_CHIP_RESET_SW_MASK BIT(1) +#define RTL8365MB_CHIP_RESET_HW_MASK BIT(0) /* Interrupt polarity register */ #define RTL8365MB_INTR_POLARITY_REG 0x1100 -#define RTL8365MB_INTR_POLARITY_MASK 0x0001 +#define RTL8365MB_INTR_POLARITY_MASK BIT(0) #define RTL8365MB_INTR_POLARITY_HIGH 0 #define RTL8365MB_INTR_POLARITY_LOW 1 /* Interrupt control/status register - enable/check specific interrupt types */ #define RTL8365MB_INTR_CTRL_REG 0x1101 -#define RTL8365MB_INTR_STATUS_REG 0x1102 -#define RTL8365MB_INTR_SLIENT_START_2_MASK 0x1000 -#define RTL8365MB_INTR_SLIENT_START_MASK 0x0800 -#define RTL8365MB_INTR_ACL_ACTION_MASK 0x0200 -#define RTL8365MB_INTR_CABLE_DIAG_FIN_MASK 0x0100 -#define RTL8365MB_INTR_INTERRUPT_8051_MASK 0x0080 -#define RTL8365MB_INTR_LOOP_DETECTION_MASK 0x0040 -#define RTL8365MB_INTR_GREEN_TIMER_MASK 0x0020 -#define RTL8365MB_INTR_SPECIAL_CONGEST_MASK 0x0010 -#define RTL8365MB_INTR_SPEED_CHANGE_MASK 0x0008 -#define RTL8365MB_INTR_LEARN_OVER_MASK 0x0004 -#define RTL8365MB_INTR_METER_EXCEEDED_MASK 0x0002 -#define RTL8365MB_INTR_LINK_CHANGE_MASK 0x0001 +#define RTL8365MB_INTR_STATUS_REG 0x1102 +#define RTL8365MB_INTR_SLIENT_START_2_MASK BIT(12) +#define RTL8365MB_INTR_SLIENT_START_MASK BIT(11) +#define RTL8365MB_INTR_ACL_ACTION_MASK BIT(9) +#define RTL8365MB_INTR_CABLE_DIAG_FIN_MASK BIT(8) +#define RTL8365MB_INTR_INTERRUPT_8051_MASK BIT(7) +#define RTL8365MB_INTR_LOOP_DETECTION_MASK BIT(6) +#define RTL8365MB_INTR_GREEN_TIMER_MASK BIT(5) +#define RTL8365MB_INTR_SPECIAL_CONGEST_MASK BIT(4) +#define RTL8365MB_INTR_SPEED_CHANGE_MASK BIT(3) +#define RTL8365MB_INTR_LEARN_OVER_MASK BIT(2) +#define RTL8365MB_INTR_METER_EXCEEDED_MASK BIT(1) +#define RTL8365MB_INTR_LINK_CHANGE_MASK BIT(0) #define RTL8365MB_INTR_ALL_MASK \ (RTL8365MB_INTR_SLIENT_START_2_MASK | \ RTL8365MB_INTR_SLIENT_START_MASK | \ @@ -172,20 +172,22 @@ RTL8365MB_INTR_METER_EXCEEDED_MASK | \ RTL8365MB_INTR_LINK_CHANGE_MASK) +#define RTL8365MB_PORT_MASK GENMASK(10, 0) + /* Per-port interrupt type status registers */ #define RTL8365MB_PORT_LINKDOWN_IND_REG 0x1106 -#define RTL8365MB_PORT_LINKDOWN_IND_MASK 0x07FF +#define RTL8365MB_PORT_LINKDOWN_IND_MASK RTL8365MB_PORT_MASK #define RTL8365MB_PORT_LINKUP_IND_REG 0x1107 -#define RTL8365MB_PORT_LINKUP_IND_MASK 0x07FF +#define RTL8365MB_PORT_LINKUP_IND_MASK RTL8365MB_PORT_MASK /* PHY indirect access registers */ #define RTL8365MB_INDIRECT_ACCESS_CTRL_REG 0x1F00 -#define RTL8365MB_INDIRECT_ACCESS_CTRL_RW_MASK 0x0002 -#define RTL8365MB_INDIRECT_ACCESS_CTRL_RW_READ 0 -#define RTL8365MB_INDIRECT_ACCESS_CTRL_RW_WRITE 1 -#define RTL8365MB_INDIRECT_ACCESS_CTRL_CMD_MASK 0x0001 -#define RTL8365MB_INDIRECT_ACCESS_CTRL_CMD_VALUE 1 +#define RTL8365MB_INDIRECT_ACCESS_CTRL_RW_MASK BIT(1) +#define RTL8365MB_INDIRECT_ACCESS_CTRL_RW_READ 0 +#define RTL8365MB_INDIRECT_ACCESS_CTRL_RW_WRITE 1 +#define RTL8365MB_INDIRECT_ACCESS_CTRL_CMD_MASK BIT(0) +#define RTL8365MB_INDIRECT_ACCESS_CTRL_CMD_VALUE 1 #define RTL8365MB_INDIRECT_ACCESS_STATUS_REG 0x1F01 #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_REG 0x1F02 #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_OCPADR_5_1_MASK GENMASK(4, 0) @@ -197,8 +199,8 @@ /* PHY OCP address prefix register */ #define RTL8365MB_GPHY_OCP_MSB_0_REG 0x1D15 -#define RTL8365MB_GPHY_OCP_MSB_0_CFG_CPU_OCPADR_MASK 0x0FC0 -#define RTL8365MB_PHY_OCP_ADDR_PREFIX_MASK 0xFC00 +#define RTL8365MB_GPHY_OCP_MSB_0_CFG_CPU_OCPADR_MASK GENMASK(11, 6) +#define RTL8365MB_PHY_OCP_ADDR_PREFIX_MASK GENMASK(15, 10) /* The full 16-bit OCP address is split across two registers: bits [15:10] are * the prefix (RTL8365MB_PHY_OCP_ADDR_PREFIX_MASK above), and bits [9:1] go into @@ -252,8 +254,8 @@ (_extint) == 1 ? RTL8365MB_EXT_RGMXF_REG1 : \ (_extint) == 2 ? RTL8365MB_EXT_RGMXF_REG2 : \ 0x0) -#define RTL8365MB_EXT_RGMXF_RXDELAY_MASK 0x0007 -#define RTL8365MB_EXT_RGMXF_TXDELAY_MASK 0x0008 +#define RTL8365MB_EXT_RGMXF_RXDELAY_MASK GENMASK(2, 0) +#define RTL8365MB_EXT_RGMXF_TXDELAY_MASK BIT(3) /* External interface line rate bypass register - one bit per external * interface, indexed by the external port number with port 5 (the first @@ -271,28 +273,28 @@ */ #define RTL8365MB_INGRESSBW_PORT6_RATE_CTRL0_REG 0x00CF #define RTL8365MB_INGRESSBW_PORT6_RATE_CTRL1_REG 0x00D0 -#define RTL8365MB_INGRESSBW_PORT6_RATE_CTRL1_MASK 0x0007 +#define RTL8365MB_INGRESSBW_PORT6_RATE_CTRL1_MASK GENMASK(2, 0) #define RTL8365MB_PORT6_EGRESSBW_CTRL0_REG 0x0398 #define RTL8365MB_PORT6_EGRESSBW_CTRL1_REG 0x0399 -#define RTL8365MB_PORT6_EGRESSBW_CTRL1_MASK 0x0007 +#define RTL8365MB_PORT6_EGRESSBW_CTRL1_MASK GENMASK(2, 0) /* SerDes indirect access registers */ #define RTL8365MB_SDS_INDACS_CMD_REG 0x6600 -#define RTL8365MB_SDS_INDACS_CMD_BUSY_MASK 0x0100 -#define RTL8365MB_SDS_INDACS_CMD_RUN_MASK 0x0080 -#define RTL8365MB_SDS_INDACS_CMD_WR_MASK 0x0040 +#define RTL8365MB_SDS_INDACS_CMD_BUSY_MASK BIT(8) +#define RTL8365MB_SDS_INDACS_CMD_RUN_MASK BIT(7) +#define RTL8365MB_SDS_INDACS_CMD_WR_MASK BIT(6) #define RTL8365MB_SDS_INDACS_ADR_REG 0x6601 #define RTL8365MB_SDS_INDACS_DATA_REG 0x6602 /* SerDes miscellaneous configuration register */ #define RTL8365MB_SDS_MISC_REG 0x1D11 -#define RTL8365MB_SDS_MISC_SGMII_RXFC_MASK 0x4000 -#define RTL8365MB_SDS_MISC_SGMII_TXFC_MASK 0x2000 -#define RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK 0x0800 -#define RTL8365MB_SDS_MISC_SGMII_FDUP_MASK 0x0400 -#define RTL8365MB_SDS_MISC_SGMII_LINK_MASK 0x0200 -#define RTL8365MB_SDS_MISC_SGMII_SPD_MASK 0x0180 -#define RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK 0x0040 +#define RTL8365MB_SDS_MISC_SGMII_RXFC_MASK BIT(14) +#define RTL8365MB_SDS_MISC_SGMII_TXFC_MASK BIT(13) +#define RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK BIT(11) +#define RTL8365MB_SDS_MISC_SGMII_FDUP_MASK BIT(10) +#define RTL8365MB_SDS_MISC_SGMII_LINK_MASK BIT(9) +#define RTL8365MB_SDS_MISC_SGMII_SPD_MASK GENMASK(8, 7) +#define RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK BIT(6) /* SerDes internal registers, accessed via the SDS_INDACS registers. The BMCR * data path reset holds BMCR_ANENABLE | BMCR_ISOLATE while toggling the @@ -303,12 +305,12 @@ #define RTL8365MB_SDS_BMCR_DPRST_PHASE1 (BMCR_ANENABLE | BMCR_ISOLATE | 0x1) #define RTL8365MB_SDS_BMCR_DPRST_PHASE2 (BMCR_ANENABLE | BMCR_ISOLATE | 0x3) #define RTL8365MB_SDS_REG_NWAY 0x0002 -#define RTL8365MB_SDS_NWAY_EN_MASK 0x0200 -#define RTL8365MB_SDS_NWAY_RESTART_MASK 0x0100 +#define RTL8365MB_SDS_NWAY_EN_MASK BIT(9) +#define RTL8365MB_SDS_NWAY_RESTART_MASK BIT(8) #define RTL8365MB_SDS_REG_RESET 0x0003 #define RTL8365MB_SDS_RESET_DEASSERT 0x7106 #define RTL8365MB_SDS_REG_LINK_STATUS 0x003d -#define RTL8365MB_SDS_LINK_STATUS_LINK_MASK 0x0010 +#define RTL8365MB_SDS_LINK_STATUS_LINK_MASK BIT(4) /* The embedded SerDes can only be muxed to external interface 1 (MAC8), * which is port 6. @@ -335,7 +337,7 @@ * the firmware would otherwise do. */ #define RTL8365MB_MISC_CFG0_REG 0x130C -#define RTL8365MB_MISC_CFG0_DW8051_EN_MASK 0x0020 +#define RTL8365MB_MISC_CFG0_DW8051_EN_MASK BIT(5) /* External interface port speed values - used in DIGITAL_INTERFACE_FORCE */ #define RTL8365MB_PORT_SPEED_10M 0 @@ -351,31 +353,31 @@ (_extint) == 1 ? RTL8365MB_DIGITAL_INTERFACE_FORCE_REG1 : \ (_extint) == 2 ? RTL8365MB_DIGITAL_INTERFACE_FORCE_REG2 : \ 0x0) -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_EN_MASK 0x1000 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_NWAY_MASK 0x0080 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_TXPAUSE_MASK 0x0040 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_RXPAUSE_MASK 0x0020 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_LINK_MASK 0x0010 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_DUPLEX_MASK 0x0004 -#define RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK 0x0003 +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_EN_MASK BIT(12) +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_NWAY_MASK BIT(7) +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_TXPAUSE_MASK BIT(6) +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_RXPAUSE_MASK BIT(5) +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_LINK_MASK BIT(4) +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_DUPLEX_MASK BIT(2) +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK GENMASK(1, 0) /* CPU port mask register - controls which ports are treated as CPU ports */ #define RTL8365MB_CPU_PORT_MASK_REG 0x1219 -#define RTL8365MB_CPU_PORT_MASK_MASK 0x07FF +#define RTL8365MB_CPU_PORT_MASK_MASK RTL8365MB_PORT_MASK /* CPU control register */ #define RTL8365MB_CPU_CTRL_REG 0x121A -#define RTL8365MB_CPU_CTRL_TRAP_PORT_EXT_MASK 0x0400 -#define RTL8365MB_CPU_CTRL_TAG_FORMAT_MASK 0x0200 -#define RTL8365MB_CPU_CTRL_RXBYTECOUNT_MASK 0x0080 -#define RTL8365MB_CPU_CTRL_TAG_POSITION_MASK 0x0040 -#define RTL8365MB_CPU_CTRL_TRAP_PORT_MASK 0x0038 -#define RTL8365MB_CPU_CTRL_INSERTMODE_MASK 0x0006 -#define RTL8365MB_CPU_CTRL_EN_MASK 0x0001 +#define RTL8365MB_CPU_CTRL_TRAP_PORT_EXT_MASK BIT(10) +#define RTL8365MB_CPU_CTRL_TAG_FORMAT_MASK BIT(9) +#define RTL8365MB_CPU_CTRL_RXBYTECOUNT_MASK BIT(7) +#define RTL8365MB_CPU_CTRL_TAG_POSITION_MASK BIT(6) +#define RTL8365MB_CPU_CTRL_TRAP_PORT_MASK GENMASK(5, 3) +#define RTL8365MB_CPU_CTRL_INSERTMODE_MASK GENMASK(2, 1) +#define RTL8365MB_CPU_CTRL_EN_MASK BIT(0) /* Maximum packet length register */ #define RTL8365MB_CFG0_MAX_LEN_REG 0x088C -#define RTL8365MB_CFG0_MAX_LEN_MASK 0x3FFF +#define RTL8365MB_CFG0_MAX_LEN_MASK GENMASK(13, 0) #define RTL8365MB_CFG0_MAX_LEN_MAX 0x3FFF /* Port learning limit registers */ @@ -387,7 +389,7 @@ #define RTL8365MB_PORT_ISOLATION_REG_BASE 0x08A2 #define RTL8365MB_PORT_ISOLATION_REG(_physport) \ (RTL8365MB_PORT_ISOLATION_REG_BASE + (_physport)) -#define RTL8365MB_PORT_ISOLATION_MASK 0x07FF +#define RTL8365MB_PORT_ISOLATION_MASK RTL8365MB_PORT_MASK /* Extended filter ID registers - used to key forwarding database with IVL */ #define RTL8365MB_EFID_MASK GENMASK(2, 0) @@ -407,16 +409,16 @@ (0x3 << RTL8365MB_MSTI_CTRL_PORT_STATE_OFFSET((_physport))) /* Unknown unicast DA flooding port mask */ -#define RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_REG 0x0890 -#define RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_MASK 0x07FF +#define RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_REG 0x0890 +#define RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_MASK RTL8365MB_PORT_MASK /* Unknown multicast DA flooding port mask */ -#define RTL8365MB_UNKNOWN_MULTICAST_FLOODING_PMASK_REG 0x0891 -#define RTL8365MB_UNKNOWN_MULTICAST_FLOODING_PMASK_MASK 0x07FF +#define RTL8365MB_UNKNOWN_MULTICAST_FLOODING_PMASK_REG 0x0891 +#define RTL8365MB_UNKNOWN_MULTICAST_FLOODING_PMASK_MASK RTL8365MB_PORT_MASK /* Broadcast flooding port mask */ -#define RTL8365MB_UNKNOWN_BROADCAST_FLOODING_PMASK_REG 0x0892 -#define RTL8365MB_UNKNOWN_BROADCAST_FLOODING_PMASK_MASK 0x07FF +#define RTL8365MB_UNKNOWN_BROADCAST_FLOODING_PMASK_REG 0x0892 +#define RTL8365MB_UNKNOWN_BROADCAST_FLOODING_PMASK_MASK RTL8365MB_PORT_MASK #define RTL8365MB_SUPPORTED_BRIDGE_FLAGS \ (BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD) @@ -425,19 +427,19 @@ #define RTL8365MB_PORT_MISC_CFG_REG_BASE 0x000E #define RTL8365MB_PORT_MISC_CFG_REG(_p) \ (RTL8365MB_PORT_MISC_CFG_REG_BASE + ((_p) << 5)) -#define RTL8365MB_PORT_MISC_CFG_SMALL_TAG_IPG_MASK 0x8000 -#define RTL8365MB_PORT_MISC_CFG_TX_ITFSP_MODE_MASK 0x4000 -#define RTL8365MB_PORT_MISC_CFG_FLOWCTRL_INDEP_MASK 0x2000 -#define RTL8365MB_PORT_MISC_CFG_DOT1Q_REMARK_ENABLE_MASK 0x1000 -#define RTL8365MB_PORT_MISC_CFG_INGRESSBW_FLOWCTRL_MASK 0x0800 -#define RTL8365MB_PORT_MISC_CFG_INGRESSBW_IFG_MASK 0x0400 -#define RTL8365MB_PORT_MISC_CFG_RX_SPC_MASK 0x0200 -#define RTL8365MB_PORT_MISC_CFG_CRC_SKIP_MASK 0x0100 -#define RTL8365MB_PORT_MISC_CFG_PKTGEN_TX_FIRST_MASK 0x0080 -#define RTL8365MB_PORT_MISC_CFG_MAC_LOOPBACK_MASK 0x0040 +#define RTL8365MB_PORT_MISC_CFG_SMALL_TAG_IPG_MASK BIT(15) +#define RTL8365MB_PORT_MISC_CFG_TX_ITFSP_MODE_MASK BIT(14) +#define RTL8365MB_PORT_MISC_CFG_FLOWCTRL_INDEP_MASK BIT(13) +#define RTL8365MB_PORT_MISC_CFG_DOT1Q_REMARK_ENABLE_MASK BIT(12) +#define RTL8365MB_PORT_MISC_CFG_INGRESSBW_FLOWCTRL_MASK BIT(11) +#define RTL8365MB_PORT_MISC_CFG_INGRESSBW_IFG_MASK BIT(10) +#define RTL8365MB_PORT_MISC_CFG_RX_SPC_MASK BIT(9) +#define RTL8365MB_PORT_MISC_CFG_CRC_SKIP_MASK BIT(8) +#define RTL8365MB_PORT_MISC_CFG_PKTGEN_TX_FIRST_MASK BIT(7) +#define RTL8365MB_PORT_MISC_CFG_MAC_LOOPBACK_MASK BIT(6) /* See &rtl8365mb_vlan_egress_mode */ -#define RTL8365MB_PORT_MISC_CFG_VLAN_EGRESS_MODE_MASK 0x0030 -#define RTL8365MB_PORT_MISC_CFG_CONGESTION_SUSTAIN_TIME_MASK 0x000F +#define RTL8365MB_PORT_MISC_CFG_VLAN_EGRESS_MODE_MASK GENMASK(5, 4) +#define RTL8365MB_PORT_MISC_CFG_CONGESTION_SUSTAIN_TIME_MASK GENMASK(3, 0) /** * enum rtl8365mb_vlan_egress_mode - port VLAN egress mode @@ -459,7 +461,7 @@ enum rtl8365mb_vlan_egress_mode { /* VLAN control register */ #define RTL8365MB_VLAN_CTRL_REG 0x07A8 -#define RTL8365MB_VLAN_CTRL_EN_MASK 0x0001 +#define RTL8365MB_VLAN_CTRL_EN_MASK BIT(0) /* VLAN ingress filter register */ #define RTL8365MB_VLAN_INGRESS_REG 0x07A9 @@ -483,8 +485,8 @@ enum rtl8365mb_vlan_egress_mode { (((RTL8365MB_MIB_ADDRESS_PORT_OFFSET) * (_p) + (_x)) >> 2) #define RTL8365MB_MIB_CTRL0_REG 0x1005 -#define RTL8365MB_MIB_CTRL0_RESET_MASK 0x0002 -#define RTL8365MB_MIB_CTRL0_BUSY_MASK 0x0001 +#define RTL8365MB_MIB_CTRL0_RESET_MASK BIT(1) +#define RTL8365MB_MIB_CTRL0_BUSY_MASK BIT(0) /* The DSA callback .get_stats64 runs in atomic context, so we are not allowed * to block. On the other hand, accessing MIB counters absolutely requires us to diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.c b/drivers/net/dsa/realtek/rtl8365mb_vlan.c index 64dd8d90a5ee..8d49ffadce92 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_vlan.c +++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.c @@ -106,8 +106,8 @@ #define RTL8365MB_VLAN_PVID_CTRL_BASE 0x0700 #define RTL8365MB_VLAN_PVID_CTRL_REG(_p) \ (RTL8365MB_VLAN_PVID_CTRL_BASE + ((_p) >> 1)) -#define RTL8365MB_VLAN_PVID_CTRL_PORT0_MCIDX_MASK 0x001F -#define RTL8365MB_VLAN_PVID_CTRL_PORT1_MCIDX_MASK 0x1F00 +#define RTL8365MB_VLAN_PVID_CTRL_PORT0_MCIDX_MASK GENMASK(4, 0) +#define RTL8365MB_VLAN_PVID_CTRL_PORT1_MCIDX_MASK GENMASK(12, 8) #define RTL8365MB_VLAN_PVID_CTRL_PORT_MCIDX_OFFSET(_p) \ (((_p) & 1) << 3) #define RTL8365MB_VLAN_PVID_CTRL_PORT_MCIDX_MASK(_p) \ From 363cf8def36201fa6bbca6b2b9f87b32340eba01 Mon Sep 17 00:00:00 2001 From: Alice Mikityanska Date: Thu, 1 Oct 2026 15:42:01 +0300 Subject: [PATCH 1145/2126] selftests: net: Fix minor issues in cork_fragsize.py return None is unreachable in check_kernel_config, because the try block always returns a True or False value, and the except block continues the loop. The return None was supposed to be outside the for loop, to make pylint happy by making all the flows of the function return a value explicitly. While at it, make the docstring of check_dmesg_clean clearer by explaining the return values. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260901195714.673548-1-alice.kernel%40fastmail.im Signed-off-by: Alice Mikityanska Link: https://patch.msgid.link/20261001124201.584805-1-alice.kernel@fastmail.im Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/cork_fragsize.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/cork_fragsize.py b/tools/testing/selftests/net/cork_fragsize.py index 7afd643d07ec..ae6be804b7a2 100755 --- a/tools/testing/selftests/net/cork_fragsize.py +++ b/tools/testing/selftests/net/cork_fragsize.py @@ -54,7 +54,7 @@ def check_kernel_config(option: str) -> bool | None: return False except OSError: continue - return None + return None def assert_debug_kernel() -> None: @@ -71,7 +71,8 @@ def assert_debug_kernel() -> None: def check_dmesg_clean(func: str) -> bool: ''' - Check if the given function produced a WARN in dmesg. + Check if the given function produced a WARN in dmesg. Returns True if dmesg + is clean, i.e. doesn't contain traces of a WARNING in the given function. ''' with subprocess.Popen(['dmesg'], stdout=subprocess.PIPE) as dmesg: From 10c339aff290684dc424ca6b6eed5579569ee781 Mon Sep 17 00:00:00 2001 From: Nagamani PV Date: Wed, 30 Sep 2026 09:02:33 +0200 Subject: [PATCH 1146/2126] s390/ctcm: Fix timer corruption in fsm_addtimer() fsm_addtimer() calls timer_setup() unconditionally before add_timer(). If called on an already-pending timer, timer_setup() re-initializes the timer's list_head fields while the timer is still enqueued in the wheel, corrupting the timer list. The timer is already initialized once by fsm_settimer() which calls timer_setup() correctly. Multiple callsites invoke fsm_addtimer() without a preceding fsm_deltimer(), including ctcm_main.c ctcmpc_send_sweep_req() and ctcm_mpc.c mpc_action_side_xid(), making the redundant timer_setup() in fsm_addtimer() a real corruption risk. Remove the redundant timer_setup() calls from fsm_addtimer() and fsm_modtimer(), and replace add_timer() with mod_timer() which safely handles both pending and non-pending timers atomically without corrupting the timer wheel. Cc: stable+noautosel@kernel.org # never worked Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20260803182736.2356374-1-nagamani@linux.ibm.com?part=1 Reviewed-by: Aswin Karuvally Tested-by: Aswin Karuvally Signed-off-by: Nagamani PV Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260930070234.569500-2-nagamani@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/s390/net/fsm.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/s390/net/fsm.c b/drivers/s390/net/fsm.c index 9b8622aef807..936ed0bc8401 100644 --- a/drivers/s390/net/fsm.c +++ b/drivers/s390/net/fsm.c @@ -171,11 +171,9 @@ fsm_addtimer(fsm_timer *this, int millisec, int event, void *arg) this->fi->name, this, millisec); #endif - timer_setup(&this->tl, fsm_expire_timer, 0); this->expire_event = event; this->event_arg = arg; - this->tl.expires = jiffies + (millisec * HZ) / 1000; - add_timer(&this->tl); + mod_timer(&this->tl, jiffies + msecs_to_jiffies(millisec)); return 0; } @@ -189,12 +187,9 @@ fsm_modtimer(fsm_timer *this, int millisec, int event, void *arg) this->fi->name, this, millisec); #endif - timer_delete(&this->tl); - timer_setup(&this->tl, fsm_expire_timer, 0); this->expire_event = event; this->event_arg = arg; - this->tl.expires = jiffies + (millisec * HZ) / 1000; - add_timer(&this->tl); + mod_timer(&this->tl, jiffies + msecs_to_jiffies(millisec)); } EXPORT_SYMBOL(init_fsm); From 65629387fd4c0d2e7a4e6303364acfdcbcf843d9 Mon Sep 17 00:00:00 2001 From: Nagamani PV Date: Wed, 30 Sep 2026 09:02:34 +0200 Subject: [PATCH 1147/2126] s390/ctcm: Fix use-after-free in channel_remove() channel_remove() uses fsm_deltimer() which calls timer_delete(), returning immediately even if the timer callback is running on another CPU. This leaves a window where fsm_expire_timer() accesses ch->fsm after kfree_fsm(). For MPC channels the teardown has a circular dependency: ch->timer callback -> ctcm_chx_txretry() -> mpc_action_go_inop() -> tasklet_hi_schedule(&ch->ch_disc_tasklet) ch_tasklet -> ctcmpc_send_sweep_resp() -> fsm_addtimer(&ch->sweep_timer) sweep_timer callback -> fsm_addtimer(&ch->timer) Use timer_shutdown_sync() for both timers: it waits for any running callback and permanently prevents rearming. Shut down sweep_timer first (its callback rearms ch->timer at ctcm_fsms.c), then ch->timer. Only then call tasklet_kill() -- catching any tasklet scheduled by an in-flight callback before shutdown. kfree(ch->discontact_th) follows tasklet_kill(ch_disc_tasklet) since ch->ccw[15].cda points to discontact_th and mpc_action_send_discontact() starts I/O through ch->ccw[15]. timer_shutdown_sync() is also used for non-MPC ch->timer: ctcm_chx_txretry() (CTC_STATE_TX + CTC_EVENT_TIMER) calls fsm_addtimer(&ch->timer) on both paths. Depends on "s390/ctcm: Fix timer corruption in fsm_addtimer()" which replaces add_timer() with mod_timer(). mod_timer() on a shut-down timer is discarded; without it fsm_addtimer() calls timer_setup() defeating timer_shutdown_sync(). Backporting without that prerequisite is unsafe. Cc: stable+noautosel@kernel.org # fix for a driver (de)init path race Fixes: 293d984f0e36 ("ctcm: infrastructure for replaced ctc driver") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20260922101913.239103-1-nagamani@linux.ibm.com?part=2 Signed-off-by: Nagamani PV Reviewed-by: Aswin Karuvally Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260930070234.569500-3-nagamani@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/s390/net/ctcm_main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c index 8b0d76a47d9f..27a22dbc9280 100644 --- a/drivers/s390/net/ctcm_main.c +++ b/drivers/s390/net/ctcm_main.c @@ -211,9 +211,14 @@ static void channel_remove(struct channel *ch) while (*c) { if (*c == ch) { *c = ch->next; - fsm_deltimer(&ch->timer); if (IS_MPC(ch)) - fsm_deltimer(&ch->sweep_timer); + timer_shutdown_sync(&ch->sweep_timer.tl); + timer_shutdown_sync(&ch->timer.tl); + if (IS_MPC(ch)) { + tasklet_kill(&ch->ch_tasklet); + tasklet_kill(&ch->ch_disc_tasklet); + kfree(ch->discontact_th); + } kfree_fsm(ch->fsm); clear_normalized_cda(&ch->ccw[4]); @@ -221,11 +226,6 @@ static void channel_remove(struct channel *ch) clear_normalized_cda(&ch->ccw[1]); dev_kfree_skb_any(ch->trans_skb); } - if (IS_MPC(ch)) { - tasklet_kill(&ch->ch_tasklet); - tasklet_kill(&ch->ch_disc_tasklet); - kfree(ch->discontact_th); - } kfree(ch->ccw); kfree(ch->irb); kfree(ch); From 6451576b53961f620de641c0ab3bfa8eabc7184b Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 2 Oct 2026 20:55:09 +0200 Subject: [PATCH 1148/2126] net: remove IPX raw 802.3 detection from eth_type_trans() eth_type_trans() and vlan_set_encap_proto() still carry a "magic hack" to spot Novell raw 802.3 frames (IPX directly over 802.3, without an 802.2 LLC header) by looking for 0xFFFF in the first two bytes of the payload, and report them as ETH_P_802_3. IPX was removed in commit 7a2e838d28cf ("staging: ipx: delete it from the tree") and there is no in-kernel packet handler for ETH_P_802_3 on the Ethernet receive path anymore. Simply classify all frames using a length field as ETH_P_802_2, which is what the remaining LLC users (STP, GARP, SNAP) register for. This removes a skb_header_pointer() call (and the skb->dev scratch trick used to avoid a stack canary) from eth_type_trans(), and lets skb_vlan_untag() only pull VLAN_HLEN bytes, as the extra two bytes were only needed for this check since commit 55eff0eb7460 ("net: Fix potential wrong skb->protocol in skb_vlan_untag()"). Note that such frames are now reported to AF_PACKET, tc, BPF and nftables with skb->protocol == ETH_P_802_2 instead of ETH_P_802_3. $ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/0 grow/shrink: 2/5 up/down: 33/-187 (-154) Function old new delta skb_shift 1736 1768 +32 eth_type_trans.cold 45 46 +1 skb_vlan_untag 690 678 -12 __skb_vlan_pop 489 477 -12 nf_flow_encap_pop 462 449 -13 eth_type_trans 354 220 -134 Total: Before=31212910, After=31212756, chg -0.00% Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261002185509.17226-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- include/linux/if_vlan.h | 18 ++---------------- net/core/skbuff.c | 3 +-- net/ethernet/eth.c | 18 ++---------------- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 4846032bf4ff..975892367136 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -698,7 +698,6 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb, struct vlan_hdr *vhdr) { __be16 proto; - unsigned short *rawp; /* * Was a VLAN packet, grab the encapsulated protocol, which the layer @@ -711,21 +710,8 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb, return; } - rawp = (unsigned short *)(vhdr + 1); - if (*rawp == 0xFFFF) - /* - * This is a magic hack to spot IPX packets. Older Novell - * breaks the protocol design and runs IPX over 802.3 without - * an 802.2 LLC layer. We look for FFFF which isn't a used - * 802.2 SSAP/DSAP. This won't work for fault tolerant netware - * but does for the rest. - */ - skb->protocol = htons(ETH_P_802_3); - else - /* - * Real 802.2 LLC - */ - skb->protocol = htons(ETH_P_802_2); + /* No ethertype: this is an 802.2 LLC frame (length field). */ + skb->protocol = htons(ETH_P_802_2); } /** diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 5c4024a03e10..43ebe61c7fc4 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6355,8 +6355,7 @@ struct sk_buff *skb_vlan_untag(struct sk_buff *skb) skb = skb_share_check(skb, GFP_ATOMIC); if (unlikely(!skb)) goto err_free; - /* We may access the two bytes after vlan_hdr in vlan_set_encap_proto(). */ - if (unlikely(!pskb_may_pull(skb, VLAN_HLEN + sizeof(unsigned short)))) + if (unlikely(!pskb_may_pull(skb, VLAN_HLEN))) goto err_free; vhdr = (struct vlan_hdr *)skb->data; diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index d9faadbe9b6c..39aab0f8035a 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -154,9 +154,7 @@ EXPORT_SYMBOL(eth_get_headlen); */ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) { - const unsigned short *sap; const struct ethhdr *eth; - __be16 res; skb->dev = dev; skb_reset_mac_header(skb); @@ -176,20 +174,8 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) if (likely(eth_proto_is_802_3(eth->h_proto))) return eth->h_proto; - /* - * This is a magic hack to spot IPX packets. Older Novell breaks - * the protocol design and runs IPX over 802.3 without an 802.2 LLC - * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This - * won't work for fault tolerant netware but does for the rest. - * We use skb->dev as temporary storage to not hit - * CONFIG_STACKPROTECTOR_STRONG=y costs on some platforms. - */ - sap = skb_header_pointer(skb, 0, sizeof(*sap), &skb->dev); - res = (sap && *sap == 0xFFFF) ? htons(ETH_P_802_3) : htons(ETH_P_802_2); - - /* restore skb->dev in case it was mangled by skb_header_pointer(). */ - skb->dev = dev; - return res; + /* No ethertype: this is an 802.2 LLC frame (length field). */ + return htons(ETH_P_802_2); } EXPORT_SYMBOL(eth_type_trans); From 6986ff35f5bb2acf994468d40af5b9494c5b6c3e Mon Sep 17 00:00:00 2001 From: Zhang Yunfei Date: Wed, 30 Sep 2026 17:47:47 +0800 Subject: [PATCH 1149/2126] net: ngbe: propagate resume errors to the PM core After a failed resume from suspend, the device stays detached from the networking stack: every attempt to bring the interface up fails the netif_device_present() check in __dev_open() with -ENODEV, while the PM core is told that resume succeeded. ngbe_resume() declares err as u32 and unconditionally returns 0: the return value of ngbe_reset_hw() is ignored entirely, and failures of wx_init_interrupt_scheme() and ngbe_open() are silently swallowed. The interrupt scheme torn down at suspend is never rebuilt, so the device cannot self-heal. Fix the type to int and propagate the errors, making the whole tail of the resume path consistent with the pci_enable_device_mem() failure path at the top. If the hardware reset fails, return early: the remaining resume steps cannot succeed. The suspend path may already have torn the interface down (ngbe_close() and wx_clear_interrupt_scheme()), leaving freed rings and IRQs behind while netif_running() still reports true, so set WX_STATE_RES_FREED on every failing return, the same mark ngbe_down_suspend() uses for the PCI error recovery path: a later ngbe_close() skips the teardown of the already-freed state, and ngbe_up_complete() clears the bit again so later opens are unaffected. This is safe on the wx_init_interrupt_scheme() failure path too, as it cleans up after itself. Found by manual code inspection of the PM error paths; the missing ngbe_reset_hw() propagation was reported by Sashiko in its review of v1. The failure paths are unreachable without fault injection: a loadable test module injects failures into ngbe_reset_hw(), wx_init_interrupt_scheme() and ngbe_open(). In a QEMU VM the unfixed driver hits the kernel "Trying to free already-free IRQ" warning on the post-suspend close; with the fix, the error is reported and no warning appears. No physical ngbe device is involved. Cc: stable+noautosel@kernel.org # LLM fix, not seen in real life Fixes: 6963e463256e ("net: ngbe: add Wake on Lan support") Reported-by: Sashiko Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917090050.1927999-1-zhangyunfei1%40kylinos.cn Signed-off-by: Zhang Yunfei Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260930094748.1198085-2-zhangyunfei1@kylinos.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index 855dc963c610..8247f6c14be0 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -954,13 +954,14 @@ static int ngbe_resume(struct pci_dev *pdev) { struct net_device *netdev; struct wx *wx; - u32 err; + int err; wx = pci_get_drvdata(pdev); netdev = wx->netdev; err = pci_enable_device_mem(pdev); if (err) { + set_bit(WX_STATE_RES_FREED, wx->state); wx_err(wx, "Cannot enable PCI device from suspend\n"); return err; } @@ -968,16 +969,23 @@ static int ngbe_resume(struct pci_dev *pdev) pci_set_master(pdev); device_wakeup_disable(&pdev->dev); - ngbe_reset_hw(wx); + err = ngbe_reset_hw(wx); + if (err) { + set_bit(WX_STATE_RES_FREED, wx->state); + wx_err(wx, "Hardware reset failed: %d\n", err); + return err; + } rtnl_lock(); err = wx_init_interrupt_scheme(wx); if (!err && netif_running(netdev)) err = ngbe_open(netdev); if (!err) netif_device_attach(netdev); + else + set_bit(WX_STATE_RES_FREED, wx->state); rtnl_unlock(); - return 0; + return err; } static struct pci_driver ngbe_driver = { From 7b36b48049f4daf164a2ab4b711ac44dc403044f Mon Sep 17 00:00:00 2001 From: Zhang Yunfei Date: Wed, 30 Sep 2026 17:47:48 +0800 Subject: [PATCH 1150/2126] net: ngbe: clear DRV_LOAD bit when ngbe_open() fails On NCSI-managed systems, a failed ifup - for example when IRQ or ring allocation fails under memory pressure - leaves the port without either host or firmware driving it: the firmware already handed the port over on open, so out-of-band management of the NIC through that port stops until the next successful ifup. ngbe_open() sets the WX_CFG_PORT_CTL_DRV_LOAD bit to tell the management firmware the host has taken over the port, but every error path returns without clearing it, leaving rings, IRQs and the PHY torn down while the firmware still believes the host owns the port. Roll the bit back on all open error paths, matching ngbe_close() and ngbe_dev_shutdown(), so a failed ifup leaves the same firmware-visible state as if the interface had never been opened. Found by manual code inspection of the open error paths. The deterministic reproduction uses a loadable test module injecting a wx_setup_resources() failure: in a QEMU VM the unfixed driver leaves DRV_LOAD set after a failed open, and with the fix the bit is cleared. No physical ngbe device is involved. Cc: stable+noautosel@kernel.org # LLM fix, not seen in real life Fixes: a1cf597b99a7 ("net: ngbe: Add ngbe mdio bus driver.") Signed-off-by: Zhang Yunfei Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260930094748.1198085-3-zhangyunfei1@kylinos.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index 8247f6c14be0..0aea5a99a1e2 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -494,7 +494,7 @@ static int ngbe_open(struct net_device *netdev) err = wx_setup_resources(wx); if (err) - return err; + goto err_control_hw; wx_configure(wx); @@ -526,6 +526,8 @@ err_free_irq: err_free_resources: wx_free_isb_resources(wx); wx_free_resources(wx); +err_control_hw: + wx_control_hw(wx, false); return err; } From e7226f9c3c24088aa80a347e44de481b9bed7318 Mon Sep 17 00:00:00 2001 From: Stanislaw Gruszka Date: Tue, 6 Oct 2026 10:14:41 +0200 Subject: [PATCH 1151/2126] wifi: iwlegacy: set debug level using debugfs Instead of custom sysfs file use debugfs for setting/reading debug level. Use hex only format since 'level' is actually a mask. Signed-off-by: Stanislaw Gruszka Link: https://patch.msgid.link/20261006081443.28017-2-stf_xl@wp.pl Signed-off-by: Johannes Berg --- .../net/wireless/intel/iwlegacy/3945-mac.c | 46 ------------------- .../net/wireless/intel/iwlegacy/4965-mac.c | 46 ------------------- drivers/net/wireless/intel/iwlegacy/debug.c | 3 ++ 3 files changed, 3 insertions(+), 92 deletions(-) diff --git a/drivers/net/wireless/intel/iwlegacy/3945-mac.c b/drivers/net/wireless/intel/iwlegacy/3945-mac.c index f7ca182d1494..b03dd4f21f64 100644 --- a/drivers/net/wireless/intel/iwlegacy/3945-mac.c +++ b/drivers/net/wireless/intel/iwlegacy/3945-mac.c @@ -3010,49 +3010,6 @@ il3945_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, * *****************************************************************************/ -#ifdef CONFIG_IWLEGACY_DEBUG - -/* - * The following adds a new attribute to the sysfs representation - * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) - * used for controlling the debug level. - * - * See the level definitions in iwl for details. - * - * The debug_level being managed using sysfs below is a per device debug - * level that is used instead of the global debug level if it (the per - * device debug level) is set. - */ -static ssize_t -il3945_show_debug_level(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - return sprintf(buf, "0x%08X\n", il_get_debug_level(il)); -} - -static ssize_t -il3945_store_debug_level(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - unsigned long val; - int ret; - - ret = kstrtoul(buf, 0, &val); - if (ret) - IL_INFO("%s is not in hex or decimal form.\n", buf); - else - il->debug_level = val; - - return strnlen(buf, count); -} - -static DEVICE_ATTR(debug_level, 0644, il3945_show_debug_level, - il3945_store_debug_level); - -#endif /* CONFIG_IWLEGACY_DEBUG */ - static ssize_t il3945_show_temperature(struct device *d, struct device_attribute *attr, char *buf) @@ -3385,9 +3342,6 @@ static struct attribute *il3945_sysfs_entries[] = { &dev_attr_status.attr, &dev_attr_temperature.attr, &dev_attr_tx_power.attr, -#ifdef CONFIG_IWLEGACY_DEBUG - &dev_attr_debug_level.attr, -#endif NULL }; diff --git a/drivers/net/wireless/intel/iwlegacy/4965-mac.c b/drivers/net/wireless/intel/iwlegacy/4965-mac.c index 18bb55682643..dc420366dff3 100644 --- a/drivers/net/wireless/intel/iwlegacy/4965-mac.c +++ b/drivers/net/wireless/intel/iwlegacy/4965-mac.c @@ -4526,49 +4526,6 @@ il4965_irq_tasklet(struct tasklet_struct *t) * *****************************************************************************/ -#ifdef CONFIG_IWLEGACY_DEBUG - -/* - * The following adds a new attribute to the sysfs representation - * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/) - * used for controlling the debug level. - * - * See the level definitions in iwl for details. - * - * The debug_level being managed using sysfs below is a per device debug - * level that is used instead of the global debug level if it (the per - * device debug level) is set. - */ -static ssize_t -il4965_show_debug_level(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - return sprintf(buf, "0x%08X\n", il_get_debug_level(il)); -} - -static ssize_t -il4965_store_debug_level(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - unsigned long val; - int ret; - - ret = kstrtoul(buf, 0, &val); - if (ret) - IL_ERR("%s is not in hex or decimal form.\n", buf); - else - il->debug_level = val; - - return strnlen(buf, count); -} - -static DEVICE_ATTR(debug_level, 0644, il4965_show_debug_level, - il4965_store_debug_level); - -#endif /* CONFIG_IWLEGACY_DEBUG */ - static ssize_t il4965_show_temperature(struct device *d, struct device_attribute *attr, char *buf) @@ -4623,9 +4580,6 @@ static DEVICE_ATTR(tx_power, 0644, il4965_show_tx_power, static struct attribute *il_sysfs_entries[] = { &dev_attr_temperature.attr, &dev_attr_tx_power.attr, -#ifdef CONFIG_IWLEGACY_DEBUG - &dev_attr_debug_level.attr, -#endif NULL }; diff --git a/drivers/net/wireless/intel/iwlegacy/debug.c b/drivers/net/wireless/intel/iwlegacy/debug.c index 8a9f79ff1c6e..6f95961037d1 100644 --- a/drivers/net/wireless/intel/iwlegacy/debug.c +++ b/drivers/net/wireless/intel/iwlegacy/debug.c @@ -1361,6 +1361,9 @@ il_dbgfs_register(struct il_priv *il, const char *name) DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf, &il->disable_chain_noise_cal); DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal); +#ifdef CONFIG_IWLEGACY_DEBUG + debugfs_create_x32("debug_level", 0600, dir_debug, &il->debug_level); +#endif } EXPORT_SYMBOL(il_dbgfs_register); From 00e2289befe725a72a902b14078a6fa9c2b1f5a1 Mon Sep 17 00:00:00 2001 From: Stanislaw Gruszka Date: Tue, 6 Oct 2026 10:14:42 +0200 Subject: [PATCH 1152/2126] wifi: iwlegacy: 4965: remove custom sysfs files Remove undocumented sysfs files used for driver debugging and development. Given the age of the driver, it is highly unlikely that access to any of this information is needed, but if so, proper debugfs entries can be added. Suggested-by: Johannes Berg Signed-off-by: Stanislaw Gruszka Link: https://patch.msgid.link/20261006081443.28017-3-stf_xl@wp.pl Signed-off-by: Johannes Berg --- .../net/wireless/intel/iwlegacy/4965-mac.c | 75 ------------------- 1 file changed, 75 deletions(-) diff --git a/drivers/net/wireless/intel/iwlegacy/4965-mac.c b/drivers/net/wireless/intel/iwlegacy/4965-mac.c index dc420366dff3..621a6ccdaaa6 100644 --- a/drivers/net/wireless/intel/iwlegacy/4965-mac.c +++ b/drivers/net/wireless/intel/iwlegacy/4965-mac.c @@ -4520,74 +4520,6 @@ il4965_irq_tasklet(struct tasklet_struct *t) #endif } -/***************************************************************************** - * - * sysfs attributes - * - *****************************************************************************/ - -static ssize_t -il4965_show_temperature(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - - if (!il_is_alive(il)) - return -EAGAIN; - - return sprintf(buf, "%d\n", il->temperature); -} - -static DEVICE_ATTR(temperature, 0444, il4965_show_temperature, NULL); - -static ssize_t -il4965_show_tx_power(struct device *d, struct device_attribute *attr, char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - - if (!il_is_ready_rf(il)) - return sprintf(buf, "off\n"); - else - return sprintf(buf, "%d\n", il->tx_power_user_lmt); -} - -static ssize_t -il4965_store_tx_power(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - unsigned long val; - int ret; - - ret = kstrtoul(buf, 10, &val); - if (ret) - IL_INFO("%s is not in decimal form.\n", buf); - else { - mutex_lock(&il->mutex); - ret = il_set_tx_power(il, val, false); - mutex_unlock(&il->mutex); - if (ret) - IL_ERR("failed setting tx power (0x%08x).\n", ret); - else - ret = count; - } - return ret; -} - -static DEVICE_ATTR(tx_power, 0644, il4965_show_tx_power, - il4965_store_tx_power); - -static struct attribute *il_sysfs_entries[] = { - &dev_attr_temperature.attr, - &dev_attr_tx_power.attr, - NULL -}; - -static const struct attribute_group il_attribute_group = { - .name = NULL, /* put in device directory */ - .attrs = il_sysfs_entries, -}; - /****************************************************************************** * * uCode download functions @@ -4922,12 +4854,6 @@ il4965_ucode_callback(const struct firmware *ucode_raw, void *context) il_dbgfs_register(il, DRV_NAME); - err = sysfs_create_group(&il->pci_dev->dev.kobj, &il_attribute_group); - if (err) { - IL_ERR("failed to create sysfs device attributes\n"); - goto out_unbind; - } - /* We have our copies now, allow OS release its copies */ release_firmware(ucode_raw); complete(&il->_4965.firmware_loading_complete); @@ -6653,7 +6579,6 @@ il4965_pci_remove(struct pci_dev *pdev) D_INFO("*** UNLOAD DRIVER ***\n"); il_dbgfs_unregister(il); - sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group); /* ieee80211_unregister_hw call wil cause il_mac_stop to * be called and il4965_down since we are removing the device From 3c91d4499171c44dbde784468d96fd38a68f1cc0 Mon Sep 17 00:00:00 2001 From: Stanislaw Gruszka Date: Tue, 6 Oct 2026 10:14:43 +0200 Subject: [PATCH 1153/2126] wifi: iwlegacy: 3945: remove custom sysfs files Remove undocumented sysfs files used for driver debugging and development. Given the age of the driver, it is highly unlikely that access to any of this information is needed, but if so, proper debugfs entries can be added. Suggested-by: Johannes Berg Signed-off-by: Stanislaw Gruszka Link: https://patch.msgid.link/20261006081443.28017-4-stf_xl@wp.pl Signed-off-by: Johannes Berg --- .../net/wireless/intel/iwlegacy/3945-mac.c | 395 +----------------- 1 file changed, 2 insertions(+), 393 deletions(-) diff --git a/drivers/net/wireless/intel/iwlegacy/3945-mac.c b/drivers/net/wireless/intel/iwlegacy/3945-mac.c index b03dd4f21f64..899b016d45d9 100644 --- a/drivers/net/wireless/intel/iwlegacy/3945-mac.c +++ b/drivers/net/wireless/intel/iwlegacy/3945-mac.c @@ -634,85 +634,6 @@ drop: return -1; } -static int -il3945_get_measurement(struct il_priv *il, - struct ieee80211_measurement_params *params, u8 type) -{ - struct il_spectrum_cmd spectrum; - struct il_rx_pkt *pkt; - struct il_host_cmd cmd = { - .id = C_SPECTRUM_MEASUREMENT, - .data = (void *)&spectrum, - .flags = CMD_WANT_SKB, - }; - u32 add_time = le64_to_cpu(params->start_time); - int rc; - int spectrum_resp_status; - int duration = le16_to_cpu(params->duration); - - if (il_is_associated(il)) - add_time = - il_usecs_to_beacons(il, - le64_to_cpu(params->start_time) - - il->_3945.last_tsf, - le16_to_cpu(il->timing.beacon_interval)); - - memset(&spectrum, 0, sizeof(spectrum)); - - spectrum.channel_count = cpu_to_le16(1); - spectrum.flags = - RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; - spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; - cmd.len = sizeof(spectrum); - spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); - - if (il_is_associated(il)) - spectrum.start_time = - il_add_beacon_time(il, il->_3945.last_beacon_time, add_time, - le16_to_cpu(il->timing.beacon_interval)); - else - spectrum.start_time = 0; - - spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); - spectrum.channels[0].channel = params->channel; - spectrum.channels[0].type = type; - if (il->active.flags & RXON_FLG_BAND_24G_MSK) - spectrum.flags |= - RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK | - RXON_FLG_TGG_PROTECT_MSK; - - rc = il_send_cmd_sync(il, &cmd); - if (rc) - return rc; - - pkt = (struct il_rx_pkt *)cmd.reply_page; - if (pkt->hdr.flags & IL_CMD_FAILED_MSK) { - IL_ERR("Bad return from N_RX_ON_ASSOC command\n"); - rc = -EIO; - } - - spectrum_resp_status = le16_to_cpu(pkt->u.spectrum.status); - switch (spectrum_resp_status) { - case 0: /* Command will be handled */ - if (pkt->u.spectrum.id != 0xff) { - D_INFO("Replaced existing measurement: %d\n", - pkt->u.spectrum.id); - il->measurement_status &= ~MEASUREMENT_READY; - } - il->measurement_status |= MEASUREMENT_ACTIVE; - rc = 0; - break; - - case 1: /* Command will not be handled */ - rc = -EAGAIN; - break; - } - - il_free_pages(il, cmd.reply_page); - - return rc; -} - static void il3945_hdl_alive(struct il_priv *il, struct il_rx_buf *rxb) { @@ -3004,290 +2925,6 @@ il3945_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; } -/***************************************************************************** - * - * sysfs attributes - * - *****************************************************************************/ - -static ssize_t -il3945_show_temperature(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - - if (!il_is_alive(il)) - return -EAGAIN; - - return sprintf(buf, "%d\n", il3945_hw_get_temperature(il)); -} - -static DEVICE_ATTR(temperature, 0444, il3945_show_temperature, NULL); - -static ssize_t -il3945_show_tx_power(struct device *d, struct device_attribute *attr, char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - return sprintf(buf, "%d\n", il->tx_power_user_lmt); -} - -static ssize_t -il3945_store_tx_power(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - char *p = (char *)buf; - u32 val; - - val = simple_strtoul(p, &p, 10); - if (p == buf) - IL_INFO(": %s is not in decimal form.\n", buf); - else - il3945_hw_reg_set_txpower(il, val); - - return count; -} - -static DEVICE_ATTR(tx_power, 0644, il3945_show_tx_power, il3945_store_tx_power); - -static ssize_t -il3945_show_flags(struct device *d, struct device_attribute *attr, char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - - return sprintf(buf, "0x%04X\n", il->active.flags); -} - -static ssize_t -il3945_store_flags(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - u32 flags = simple_strtoul(buf, NULL, 0); - - mutex_lock(&il->mutex); - if (le32_to_cpu(il->staging.flags) != flags) { - /* Cancel any currently running scans... */ - if (il_scan_cancel_timeout(il, 100)) - IL_WARN("Could not cancel scan.\n"); - else { - D_INFO("Committing rxon.flags = 0x%04X\n", flags); - il->staging.flags = cpu_to_le32(flags); - il3945_commit_rxon(il); - } - } - mutex_unlock(&il->mutex); - - return count; -} - -static DEVICE_ATTR(flags, 0644, il3945_show_flags, il3945_store_flags); - -static ssize_t -il3945_show_filter_flags(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - - return sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags)); -} - -static ssize_t -il3945_store_filter_flags(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - u32 filter_flags = simple_strtoul(buf, NULL, 0); - - mutex_lock(&il->mutex); - if (le32_to_cpu(il->staging.filter_flags) != filter_flags) { - /* Cancel any currently running scans... */ - if (il_scan_cancel_timeout(il, 100)) - IL_WARN("Could not cancel scan.\n"); - else { - D_INFO("Committing rxon.filter_flags = " "0x%04X\n", - filter_flags); - il->staging.filter_flags = cpu_to_le32(filter_flags); - il3945_commit_rxon(il); - } - } - mutex_unlock(&il->mutex); - - return count; -} - -static DEVICE_ATTR(filter_flags, 0644, il3945_show_filter_flags, - il3945_store_filter_flags); - -static ssize_t -il3945_show_measurement(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - struct il_spectrum_notification measure_report; - u32 size = sizeof(measure_report), len = 0, ofs = 0; - u8 *data = (u8 *) &measure_report; - unsigned long flags; - - spin_lock_irqsave(&il->lock, flags); - if (!(il->measurement_status & MEASUREMENT_READY)) { - spin_unlock_irqrestore(&il->lock, flags); - return 0; - } - memcpy(&measure_report, &il->measure_report, size); - il->measurement_status = 0; - spin_unlock_irqrestore(&il->lock, flags); - - while (size && PAGE_SIZE - len) { - hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, - PAGE_SIZE - len, true); - len = strlen(buf); - if (PAGE_SIZE - len) - buf[len++] = '\n'; - - ofs += 16; - size -= min(size, 16U); - } - - return len; -} - -static ssize_t -il3945_store_measurement(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - struct ieee80211_measurement_params params = { - .channel = le16_to_cpu(il->active.channel), - .start_time = cpu_to_le64(il->_3945.last_tsf), - .duration = cpu_to_le16(1), - }; - u8 type = IL_MEASURE_BASIC; - u8 buffer[32]; - u8 channel; - - if (count) { - char *p = buffer; - strscpy(buffer, buf, sizeof(buffer)); - channel = simple_strtoul(p, NULL, 0); - if (channel) - params.channel = channel; - - p = buffer; - while (*p && *p != ' ') - p++; - if (*p) - type = simple_strtoul(p + 1, NULL, 0); - } - - D_INFO("Invoking measurement of type %d on " "channel %d (for '%s')\n", - type, params.channel, buf); - mutex_lock(&il->mutex); - il3945_get_measurement(il, ¶ms, type); - mutex_unlock(&il->mutex); - - return count; -} - -static DEVICE_ATTR(measurement, 0600, il3945_show_measurement, - il3945_store_measurement); - -static ssize_t -il3945_store_retry_rate(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - - il->retry_rate = simple_strtoul(buf, NULL, 0); - if (il->retry_rate <= 0) - il->retry_rate = 1; - - return count; -} - -static ssize_t -il3945_show_retry_rate(struct device *d, struct device_attribute *attr, - char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - return sprintf(buf, "%d", il->retry_rate); -} - -static DEVICE_ATTR(retry_rate, 0600, il3945_show_retry_rate, - il3945_store_retry_rate); - -static ssize_t -il3945_show_channels(struct device *d, struct device_attribute *attr, char *buf) -{ - /* all this shit doesn't belong into sysfs anyway */ - return 0; -} - -static DEVICE_ATTR(channels, 0400, il3945_show_channels, NULL); - -static ssize_t -il3945_show_antenna(struct device *d, struct device_attribute *attr, char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - - if (!il_is_alive(il)) - return -EAGAIN; - - return sprintf(buf, "%d\n", il3945_mod_params.antenna); -} - -static ssize_t -il3945_store_antenna(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il __maybe_unused = dev_get_drvdata(d); - int ant; - - if (count == 0) - return 0; - - if (sscanf(buf, "%1i", &ant) != 1) { - D_INFO("not in hex or decimal form.\n"); - return count; - } - - if (ant >= 0 && ant <= 2) { - D_INFO("Setting antenna select to %d.\n", ant); - il3945_mod_params.antenna = (enum il3945_antenna)ant; - } else - D_INFO("Bad antenna select value %d.\n", ant); - - return count; -} - -static DEVICE_ATTR(antenna, 0644, il3945_show_antenna, il3945_store_antenna); - -static ssize_t -il3945_show_status(struct device *d, struct device_attribute *attr, char *buf) -{ - struct il_priv *il = dev_get_drvdata(d); - if (!il_is_alive(il)) - return -EAGAIN; - return sprintf(buf, "0x%08x\n", (int)il->status); -} - -static DEVICE_ATTR(status, 0444, il3945_show_status, NULL); - -static ssize_t -il3945_dump_error_log(struct device *d, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct il_priv *il = dev_get_drvdata(d); - char *p = (char *)buf; - - if (p[0] == '1') - il3945_dump_nic_error_log(il); - - return strnlen(buf, count); -} - -static DEVICE_ATTR(dump_errors, 0200, NULL, il3945_dump_error_log); - /***************************************************************************** * * driver setup and tear down @@ -3331,25 +2968,6 @@ il3945_cancel_deferred_work(struct il_priv *il) il_cancel_scan_deferred_work(il); } -static struct attribute *il3945_sysfs_entries[] = { - &dev_attr_antenna.attr, - &dev_attr_channels.attr, - &dev_attr_dump_errors.attr, - &dev_attr_flags.attr, - &dev_attr_filter_flags.attr, - &dev_attr_measurement.attr, - &dev_attr_retry_rate.attr, - &dev_attr_status.attr, - &dev_attr_temperature.attr, - &dev_attr_tx_power.attr, - NULL -}; - -static const struct attribute_group il3945_attribute_group = { - .name = NULL, /* put in device directory */ - .attrs = il3945_sysfs_entries, -}; - static struct ieee80211_ops il3945_mac_ops __ro_after_init = { .add_chanctx = ieee80211_emulate_add_chanctx, .remove_chanctx = ieee80211_emulate_remove_chanctx, @@ -3632,16 +3250,11 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto out_disable_msi; } - err = sysfs_create_group(&pdev->dev.kobj, &il3945_attribute_group); - if (err) { - IL_ERR("failed to create sysfs device attributes\n"); - goto out_release_irq; - } - il_set_rxon_channel(il, &il->bands[NL80211_BAND_2GHZ].channels[5]); + err = il3945_setup_deferred_work(il); if (err) - goto out_remove_sysfs; + goto out_release_irq; il3945_setup_handlers(il); il_power_initialize(il); @@ -3666,8 +3279,6 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) out_destroy_workqueue: destroy_workqueue(il->workqueue); il->workqueue = NULL; -out_remove_sysfs: - sysfs_remove_group(&pdev->dev.kobj, &il3945_attribute_group); out_release_irq: free_irq(il->pci_dev->irq, il); out_disable_msi: @@ -3732,8 +3343,6 @@ il3945_pci_remove(struct pci_dev *pdev) il3945_synchronize_irq(il); - sysfs_remove_group(&pdev->dev.kobj, &il3945_attribute_group); - cancel_delayed_work_sync(&il->_3945.rfkill_poll); il3945_dealloc_ucode_pci(il); From f7463a9c99a506b3308a852f9aaaf2a26b659e95 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Mon, 5 Oct 2026 12:32:59 +0200 Subject: [PATCH 1154/2126] wifi: brcmsmac: Adjust txpwrindex value in nphy_ipa_rxcal_gaintbl_2GHz After a recent change in clang to warn on signed char conversions within array initializers [1], there is a warning (or error with CONFIG_WERROR=y / W=e) from nphy_ipa_rxcal_gaintbl_2GHz: drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c:224:18: error: implicit conversion from 'int' to 's8' (aka 'signed char') changes value from 128 to -128 [-Werror,-Wconstant-conversion] 224 | {0, 0, 0, 0, 0, 128}, | ~ ^~~ 1 error generated. This value was introduced in the original staging merge of brcmsmac in commit a9533e7ea3c4 ("Staging: Add initial release of brcm80211 - Broadcom 802.11n wireless LAN driver.") and it is the same in the proprietary driver [2]. Presumably it is correct since there have been no reported issues, so update the value to '-128' to be type correct and clear up the warning. Cc: stable@vger.kernel.org Fixes: a9533e7ea3c4 ("Staging: Add initial release of brcm80211 - Broadcom 802.11n wireless LAN driver.") Link: https://github.com/llvm/llvm-project/commit/a5ef934a8d295dc03be3960f2b3744ec2e53238e [1] Link: https://lore.kernel.org/1a107e21b08.2873.9b12b7fc0a3841636cfb5e919b41b954@broadcom.com/ [2] Signed-off-by: Nathan Chancellor Acked-by: Arend van Spriel Link: https://patch.msgid.link/20261005-brcmsmac-clang-24-constant-conversion-v1-1-a30c5692d582@kernel.org Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c index 86cfa3e87a04..9ddd5d519893 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c @@ -221,7 +221,7 @@ static const struct nphy_ipa_txrxgain nphy_ipa_rxcal_gaintbl_5GHz[] = { }; static const struct nphy_ipa_txrxgain nphy_ipa_rxcal_gaintbl_2GHz[] = { - {0, 0, 0, 0, 0, 128}, + {0, 0, 0, 0, 0, -128}, {0, 0, 0, 0, 0, 70}, {0, 0, 0, 0, 0, 20}, {0, 0, 0, 3, 0, 20}, From 2d03b83ef76294216c414b271415892c08fa9fd8 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 11:44:14 +0200 Subject: [PATCH 1155/2126] wifi: mac80211: fix non-MLD link ID handling In mac80211 the deflink link IDs for non-MLO are set to zero to match the array index where their pointer lives. However, the rx->link_id is expected to be -1 in these cases, so just mapping it to the link/sta_link link_id broke a few things such as reporting of spurious 4-addr frames. Set the link ID to -1 in these cases. Reported-by: Jouni Malinen Fixes: 6d531b9af16e ("wifi: mac80211: rework RX packet handling") Link: https://patch.msgid.link/20261005114413.816905704456.Ib59a1ecce6ad74b23e4382e03cf3c113cbbdea2e@changeid Signed-off-by: Johannes Berg --- net/mac80211/rx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 1121e650b0dd..b06301c1e88b 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4345,7 +4345,10 @@ static bool ieee80211_rx_data_set_link_sta(struct ieee80211_rx_data *rx, if (!rx->link) return false; - rx->link_id = rx->link->link_id; + if (ieee80211_vif_is_mld(&sta->sdata->vif)) + rx->link_id = rx->link->link_id; + else + rx->link_id = -1; rx->link_sta = link_sta; return true; @@ -5296,6 +5299,7 @@ static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, struct ieee80211_fast_rx *fast_rx; struct ieee80211_rx_data rx; struct sta_info *sta; + int link_id = -1; memset(&rx, 0, sizeof(rx)); rx.skb = skb; @@ -5312,11 +5316,11 @@ static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, goto drop; sta = container_of(link_pubsta->sta, struct sta_info, sta); - if (!ieee80211_rx_data_set_sta(&rx, sta, link_pubsta->link_id)) + if (sta->sta.valid_links) + link_id = link_pubsta->link_id; + if (!ieee80211_rx_data_set_sta(&rx, sta, link_id)) goto drop; - rx.link_id = link_pubsta->link_id; - fast_rx = rcu_dereference(rx.sta->fast_rx); if (!fast_rx) goto drop; @@ -5579,7 +5583,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, rx.sdata = sdata; rx.local = sdata->local; rx.link = link; - rx.link_id = link->link_id; + rx.link_id = link != &sdata->deflink ? link->link_id : -1; rx.sta = NULL; rx.link_sta = NULL; From a79d7328ba193d759e3a11911e564de58b6d77db Mon Sep 17 00:00:00 2001 From: Raj Ojha Date: Sat, 3 Oct 2026 16:57:41 +0530 Subject: [PATCH 1156/2126] wifi: mac80211: acquire wiphy lock for unlisted sdata teardown When netdev registration fails or an interface cannot be moved out of a dying network namespace, the netdev core calls ->ndo_uninit() (ieee80211_uninit) with RTNL held. However, ieee80211_uninit() calls ieee80211_teardown_sdata() without holding wiphy_lock. During teardown, ieee80211_free_keys() invokes wiphy_delayed_work_cancel(), which triggers a lockdep warning: WARNING: CPU: 0 PID: 6112 at net/wireless/core.c:1839 wiphy_delayed_work_cancel+0x85/0xb0 ... Call Trace: ieee80211_free_keys+0x31a/0x3c0 net/mac80211/key.c:380 ieee80211_teardown_sdata+0x2b8/0x10f0 net/mac80211/iface.c:928 ieee80211_uninit+0x3f/0x50 net/mac80211/iface.c:954 rollback_registered_many+0xa5c/0xef0 net/core/dev.c:10065 In the normal deletion path (ieee80211_del_virtual_intf), both RTNL and wiphy_lock are held when ieee80211_teardown_sdata() runs, and the sdata is removed from local->interfaces. Change ieee80211_unlist_sdata() to return a boolean indicating whether the sdata was present in the list, and acquire wiphy_lock in ieee80211_uninit() only if the interface is actually being unlisted here. Reported-by: syzbot+e9cbd080a7801f06cf08@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=e9cbd080a7801f06cf08 Tested-by: syzbot+e9cbd080a7801f06cf08@syzkaller.appspotmail.com Signed-off-by: Raj Ojha Link: https://patch.msgid.link/20261003112741.52-1-rajojha047@gmail.com [dissolve ieee80211_unlist_sdata() to avoid weird locking] Signed-off-by: Johannes Berg --- net/mac80211/iface.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index d55f156555de..d0b0a503b229 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -927,32 +927,30 @@ static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata) } } -/* - * The netdev can be unregistered without mac80211 doing it, e.g. by the netdev - * core when cfg80211 couldn't move it out of a network namespace that's being - * destroyed. Drop it from the interface list either way. - */ -static void ieee80211_unlist_sdata(struct ieee80211_sub_if_data *sdata) +static void ieee80211_uninit(struct net_device *dev) { + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_local *local = sdata->local; struct ieee80211_sub_if_data *iter; ASSERT_RTNL(); + /* + * The netdev can be unregistered without mac80211 doing it, e.g. by the + * netdev core when cfg80211 couldn't move it out of a network namespace + * that's being destroyed. If so, it's still listed and the wiphy mutex + * isn't held yet. + */ list_for_each_entry(iter, &local->interfaces, list) { if (iter != sdata) continue; - guard(mutex)(&local->iflist_mtx); - list_del_rcu(&sdata->list); + guard(wiphy)(local->hw.wiphy); + scoped_guard(mutex, &local->iflist_mtx) + list_del_rcu(&sdata->list); + ieee80211_teardown_sdata(sdata); return; } -} -static void ieee80211_uninit(struct net_device *dev) -{ - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); - - ieee80211_unlist_sdata(sdata); ieee80211_teardown_sdata(sdata); } From b6f009284138884c4b07bbef7b07d780aa9b5daf Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 30 Sep 2026 10:48:19 +0200 Subject: [PATCH 1157/2126] wifi: mac80211: use the AP address as RA for a 4-addr MLO station In 4-address mode, ieee80211_build_hdr() and ieee80211_check_fast_xmit() set A1 to sdata->deflink.u.mgd.bssid, which is not valid for an MLO connection. Use sdata->vif.cfg.ap_addr instead, like the 3-address case does. Signed-off-by: Felix Fietkau Link: https://patch.msgid.link/20260930084819.3000572-2-nbd@nbd.name Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 1953ec35c783..efe12384c59b 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2914,7 +2914,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); /* RA TA DA SA */ - memcpy(hdr.addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); + memcpy(hdr.addr1, sdata->vif.cfg.ap_addr, ETH_ALEN); memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); memcpy(hdr.addr3, skb->data, ETH_ALEN); memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); @@ -3210,7 +3210,7 @@ void ieee80211_check_fast_xmit(struct sta_info *sta) fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); /* RA TA DA SA */ - memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); + memcpy(hdr->addr1, sdata->vif.cfg.ap_addr, ETH_ALEN); memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); build.da_offs = offsetof(struct ieee80211_hdr, addr3); build.sa_offs = offsetof(struct ieee80211_hdr, addr4); From 20dff14006b189baf05011b44e785d100458cc95 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 1 Oct 2026 20:47:13 +0000 Subject: [PATCH 1158/2126] net: Order blackhole_netdev_init(), inet_init(), and inet6_init(). Commit 309b905deee5 ("ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs") started to call inet6_init() as device_initcall(). It explains the reason as a race condition on IPv6 addrconf, but this is not accurate. The change initially used fs_initcall() but switched to device_initcall() due to the null-ptr-deref stack trace in the link below. It happened because blackhole_netdev_init() uses device_initcall() and blackhole_netdev was NULL when addrconf_init() called ipv6_add_dev(blackhole_netdev). Due to the order in Kbuild, $ cat -n Kbuild | grep -E "(drivers|net)" 111 obj-y += drivers/ 114 obj-$(CONFIG_NET) += net/ using device_initcall() for IPv6 allows built-in drivers to be initialised earlier, which requires unnecessary NULL checks. For the same ordering reason, IPv4 uses late_initcall() to initialise blackhole_netdev. Given loopback_net_ops is registered in net_dev_init() at subsys_initcall(), blackhole_netdev_init() can be called after that. In addition, some places assume that IPv4 must be initialised before IPv6. For example, mptcp_proto_v6_init() copies mptcp_prot to mptcp_v6_prot, which would otherwise have NULL mptcp_v6_prot.h.hashinfo. Let's explicitly order blackhole_netdev_init() -> inet_init() -> inet6_init() before device_initcall() with 3 different initcall levels: subsys_initcall : 4 : net_dev_init() subsys_initcall_sync : 4s : blackhole_netdev_init() fs_initcall : 5 : inet_init() fs_initcall_sync : 5s : inet6_init() device_initcall : 6 : built-in drivers Note that both IPv4 and IPv6 can still use fs_initcall() thanks to the order in net/Makefile, but explicit ordering would be less error-prone. $ cat -n net/Makefile | grep ipv 17 obj-$(CONFIG_INET) += ipv4/ 22 obj-y += ipv6/ Link: https://lore.kernel.org/netdev/20260309074758.0ea95a18@kernel.org/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Tested-by: Chris J Arges Reviewed-by: Fernando Fernandez Mancera Link: https://patch.msgid.link/20261001204752.2572265-2-kuniyu@google.com Signed-off-by: Jakub Kicinski --- drivers/net/loopback.c | 2 +- net/ipv6/af_inet6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 1fb6ce6843ad..55ecd5ebac0f 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -289,4 +289,4 @@ static int __init blackhole_netdev_init(void) return 0; } -device_initcall(blackhole_netdev_init); +subsys_initcall_sync(blackhole_netdev_init); diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index f0efdc13baf4..a9b8b4b42a1a 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -1217,4 +1217,4 @@ out_unregister_tcp_proto: proto_unregister(&tcpv6_prot); goto out; } -device_initcall(inet6_init); +fs_initcall_sync(inet6_init); From 3d51928a882b768581e79c0ef04b63e196d5ef4c Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 1 Oct 2026 20:47:14 +0000 Subject: [PATCH 1159/2126] ipv4: Inline inet_blackhole_dev_init() to devinet_init(). Commit 22600596b675 ("ipv4: give an IPv4 dev to blackhole_netdev") started to allocate in_device for blackhole_netdev. It used late_initcall() because blackhole_netdev was allocated at device_initcall(). Now, it is allocated before inet_init(), and we no longer need to use late_initcall(). Let's inline inet_blackhole_dev_init() to devinet_init(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Tested-by: Chris J Arges Link: https://patch.msgid.link/20261001204752.2572265-3-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv4/devinet.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index e84d3cf92247..2ed4c706ca9e 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -340,18 +340,6 @@ static void inetdev_destroy(struct in_device *in_dev) in_dev_put(in_dev); } -static int __init inet_blackhole_dev_init(void) -{ - struct in_device *in_dev; - - rtnl_lock(); - in_dev = inetdev_init(blackhole_netdev); - rtnl_unlock(); - - return PTR_ERR_OR_ZERO(in_dev); -} -late_initcall(inet_blackhole_dev_init); - int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b) { const struct in_ifaddr *ifa; @@ -2974,4 +2962,9 @@ void __init devinet_init(void) panic("Unable to register inet_af_ops\n"); rtnl_register_many(devinet_rtnl_msg_handlers); + + rtnl_lock(); + if (IS_ERR(inetdev_init(blackhole_netdev))) + panic("IP: failed to allocate in_device for blackhole_netdev\n"); + rtnl_unlock(); } From 2e65372a2b64a1d6d1e27dff0579b3a609b2e405 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 1 Oct 2026 20:47:15 +0000 Subject: [PATCH 1160/2126] net: Rename dev_isalive() to netif_is_alive(). The next patch needs to use dev_isalive() in xfrm. We should try to avoid using the dev_ prefix on APIs we export via include/linux/. Let's move it to include/linux/netdevice.h and rename to netif_is_alive(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Tested-by: Chris J Arges Link: https://patch.msgid.link/20261001204752.2572265-4-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 6 ++++++ net/core/dev.h | 6 ------ net/core/net-sysfs.c | 16 ++++++++-------- net/core/netdev_work.c | 4 ++-- net/core/rtnetlink.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f61c97231309..8cae9b00211e 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5715,6 +5715,12 @@ static inline const char *netdev_name(const struct net_device *dev) return dev->name; } +/* Caller holds RTNL, netdev->lock or RCU */ +static inline bool netif_is_alive(const struct net_device *dev) +{ + return READ_ONCE(dev->reg_state) <= NETREG_REGISTERED; +} + static inline const char *netdev_reg_state(const struct net_device *dev) { u8 reg_state = READ_ONCE(dev->reg_state); diff --git a/net/core/dev.h b/net/core/dev.h index 4793a994f7f1..4e9e8cd15697 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -419,10 +419,4 @@ int dev_get_hwtstamp_phylib(struct net_device *dev, struct kernel_hwtstamp_config *cfg); int net_hwtstamp_validate(const struct kernel_hwtstamp_config *cfg); -/* Caller holds RTNL, netdev->lock or RCU */ -static inline bool dev_isalive(const struct net_device *dev) -{ - return READ_ONCE(dev->reg_state) <= NETREG_REGISTERED; -} - #endif diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 728ff0a68248..fa6f821c8846 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -100,7 +100,7 @@ static int sysfs_rtnl_lock(struct kobject *kobj, struct attribute *attr, /* Check dismantle on the device hasn't started, otherwise deny the * operation. */ - if (!dev_isalive(ndev)) { + if (!netif_is_alive(ndev)) { rtnl_unlock(); ret = -ENODEV; goto unbreak; @@ -143,7 +143,7 @@ static int sysfs_get_link_ksettings(struct device *dev, } netdev_lock_ops(netdev); - if (!dev_isalive(netdev)) { + if (!netif_is_alive(netdev)) { ret = -ENODEV; goto unlock; } @@ -170,7 +170,7 @@ static ssize_t netdev_show(const struct device *dev, ssize_t ret = -EINVAL; rcu_read_lock(); - if (dev_isalive(ndev)) + if (netif_is_alive(ndev)) ret = (*format)(ndev, buf); rcu_read_unlock(); @@ -247,7 +247,7 @@ netdev_lock_store(struct device *dev, struct device_attribute *attr, netdev_lock(netdev); - if (dev_isalive(netdev)) { + if (netif_is_alive(netdev)) { ret = (*set)(netdev, new); if (ret == 0) ret = len; @@ -303,7 +303,7 @@ static ssize_t address_show(struct device *dev, struct device_attribute *attr, down_read(&dev_addr_sem); rcu_read_lock(); - if (dev_isalive(ndev)) + if (netif_is_alive(ndev)) ret = sysfs_format_mac(buf, ndev->dev_addr, ndev->addr_len); rcu_read_unlock(); @@ -319,7 +319,7 @@ static ssize_t broadcast_show(struct device *dev, int ret = -EINVAL; rcu_read_lock(); - if (dev_isalive(ndev)) + if (netif_is_alive(ndev)) ret = sysfs_format_mac(buf, ndev->broadcast, ndev->addr_len); rcu_read_unlock(); return ret; @@ -747,7 +747,7 @@ static ssize_t threaded_show(struct device *dev, rcu_read_lock(); - if (dev_isalive(netdev)) + if (netif_is_alive(netdev)) ret = sysfs_emit(buf, fmt_dec, READ_ONCE(netdev->threaded)); rcu_read_unlock(); @@ -824,7 +824,7 @@ static ssize_t netstat_show(const struct device *d, offset % sizeof(u64) != 0); rcu_read_lock(); - if (dev_isalive(dev)) { + if (netif_is_alive(dev)) { struct rtnl_link_stats64 temp; const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); diff --git a/net/core/netdev_work.c b/net/core/netdev_work.c index c99967907e18..1b11bcbeb196 100644 --- a/net/core/netdev_work.c +++ b/net/core/netdev_work.c @@ -30,7 +30,7 @@ static void netdev_work_enqueue(struct net_device *dev, unsigned long events, return; spin_lock_bh(&netdev_work_lock); - if (!dev_isalive(dev)) { + if (!netif_is_alive(dev)) { spin_unlock_bh(&netdev_work_lock); return; } @@ -154,7 +154,7 @@ static void netdev_work_proc(struct work_struct *work) /* We took another ref above */ netdev_put(dev, &dev->work_tracker); - if (!dev_isalive(dev)) + if (!netif_is_alive(dev)) core = events = 0; } spin_unlock_bh(&netdev_work_lock); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 5bbebce0c2f5..15bffafbf0a9 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4360,7 +4360,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, retry: if (need_rtnl) { rtnl_lock(); - if (!dev_isalive(dev)) { + if (!netif_is_alive(dev)) { err = -ENODEV; nskb = NULL; goto unlock; From 4eb2e2f358fcc055641879a56885d428e47878ed Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 1 Oct 2026 20:47:16 +0000 Subject: [PATCH 1161/2126] xfrm: Check netif_is_alive() in xfrm_bundle_create() and xfrm_create_dummy_bundle(). struct dst_entry passed to xfrm_bundle_create() and xfrm_create_dummy_bundle() could outlive synchronize_net() in unregister_netdevice_many_notify(). For example, ip_route_output_flow() calls __ip_route_output_key() to fetch a dst under RCU, but calls xfrm_lookup_route() outside of that RCU critical section. Thus, xfrm_fill_dst() could add a new uncached route after the first NETDEV_UNREGISTER notification and rely on the rebroadcast in netdev_wait_allrefs_any(). The following patches will move the uncached route flush for dying netdev from the NETDEV_UNREGISTER handler to netdev_run_todo(), where the rebroadcast is also skipped due to dev->dismantle, making such late additions problematic. Let's check netif_is_alive() after fetching dst_dev_rcu(dst) under RCU. This ensures that xfrm either finishes adding the uncached route before synchronize_net() or fails with -ENODEV. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Tested-by: Chris J Arges Link: https://patch.msgid.link/20261001204752.2572265-5-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/xfrm/xfrm_policy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 513c9f228334..9ea60c7717ff 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -2772,7 +2772,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy, err = -ENODEV; rcu_read_lock(); dev = dst_dev_rcu(dst); - if (!dev) { + if (!dev || !netif_is_alive(dev)) { rcu_read_unlock(); goto free_dst; } @@ -3066,7 +3066,7 @@ static struct xfrm_dst *xfrm_create_dummy_bundle(struct net *net, err = -ENODEV; rcu_read_lock(); dev = dst_dev_rcu(dst); - if (!dev) { + if (!dev || !netif_is_alive(dev)) { rcu_read_unlock(); goto free_dst; } From ca6854799069778fef446d307935f764cc3d3afb Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 1 Oct 2026 20:47:17 +0000 Subject: [PATCH 1162/2126] ipv4: Batch rt_flush_dev() in netdev_run_todo(). IPv4 uncached routes are linked to the global per-cpu lists, rt_uncached_list. When unregistering a netdev, rt_flush_dev() iterates over the potentially long lists to find uncached routes tied to the device and swap it with blackhole_netdev. Since it is called for every device in dying netns under RTNL, it adds O(N_dev x (N_cpu + N_route)) costs to any batched device unregistration. Let's call it once per batched device unregistration without RTNL. Note that rt_flush_dev() must be called after setting dev->reg_state to NETREG_UNREGISTERED. Otherwise, because rt_flush_dev(NULL) runs without RTNL, it could race with unregister_netdevice_many_notify() and prematurely purge routes for NETREG_UNREGISTERING dev, for which flush_all_backlogs() has not been called yet. Reported-by: Chris J Arges Closes: https://lore.kernel.org/netdev/20260917-hash-bucket-route-lists-v3-0-30493a37b6eb@cloudflare.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Tested-by: Chris J Arges Link: https://patch.msgid.link/20261001204752.2572265-6-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/route.h | 6 ++++++ net/core/dev.c | 4 ++++ net/ipv4/route.c | 11 +++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/net/route.h b/include/net/route.h index 6b55de2e4df8..3fccd31eb74d 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -129,7 +129,13 @@ struct in_device; int ip_rt_init(void); void rt_cache_flush(struct net *net); +#ifdef CONFIG_INET void rt_flush_dev(struct net_device *dev); +#else +static inline void rt_flush_dev(struct net_device *dev) +{ +} +#endif static inline void inet_sk_init_flowi4(const struct inet_sock *inet, struct flowi4 *fl4) diff --git a/net/core/dev.c b/net/core/dev.c index db765cb5811e..f76a4459d8e1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -129,6 +129,7 @@ #include #include #include +#include #include #include #include @@ -11886,6 +11887,9 @@ void netdev_run_todo(void) linkwatch_sync_dev(dev); } + if (!list_empty(&list)) + rt_flush_dev(NULL); + cnt = 0; while (!list_empty(&list)) { dev = netdev_wait_allrefs_any(&list); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index d7da2f1acbb5..1b641901f10d 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1587,6 +1587,9 @@ void rt_flush_dev(struct net_device *dev) struct rtable *rt, *safe; int cpu; + if (dev && dev->dismantle) + return; + for_each_possible_cpu(cpu) { struct uncached_list *ul = &per_cpu(rt_uncached_list, cpu); @@ -1595,10 +1598,14 @@ void rt_flush_dev(struct net_device *dev) spin_lock_bh(&ul->lock); list_for_each_entry_safe(rt, safe, &ul->head, dst.rt_uncached) { - if (rt->dst.dev != dev) + struct net_device *rt_dev = rt->dst.dev; + + if (dev ? rt_dev != dev : + READ_ONCE(rt_dev->reg_state) != NETREG_UNREGISTERED) continue; + rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev); - netdev_ref_replace(dev, blackhole_netdev, + netdev_ref_replace(rt_dev, blackhole_netdev, &rt->dst.dev_tracker, GFP_ATOMIC); list_del_init(&rt->dst.rt_uncached); } From f12d2907992db7ba91cc4a1796dce3cffb01318c Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Thu, 1 Oct 2026 20:47:18 +0000 Subject: [PATCH 1163/2126] ipv6: Batch rt6_uncached_list_flush_dev() in netdev_run_todo(). IPv6 uncached routes are linked to the global per-cpu lists, rt6_uncached_list. When unregistering a netdev, rt6_uncached_list_flush_dev() iterates over the potentially long lists to find uncached routes tied to the device and swap it with blackhole_netdev. Since it is called for every device in dying netns under RTNL, it adds O(N_dev x (N_cpu + N_route)) costs to any batched device unregistration. Let's call it once per batched device unregistration without RTNL. Because it now runs without RTNL, rt->dst.dev and rt->rt6i_idev->dev may transition to NETREG_UNREGISTERED at different times. Thus, we must check that both devices are blackhole_netdev before unlinking the route; otherwise, the remaining device reference would not be flushed when the other device is unregistered. In addition, since netdev_run_todo() runs even when IPv6 is disabled, rt6_uncached_list_flush_dev() must check ipv6_mod_enabled() before touching rt6_uncached_list. Note also that netdev_run_todo() cannot be called before rt6_uncached_list is initialised because: 1. unregister_netdevice_many_notify() panics when dev_boot_phase == 1 (net_dev_init() is subsys_initcall()). 2. the only device registered before fs_initcall_sync() is loopback and loopback_net_init() panics in case of failure. Reported-by: Chris J Arges Closes: https://lore.kernel.org/netdev/20260917-hash-bucket-route-lists-v3-0-30493a37b6eb@cloudflare.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Tested-by: Chris J Arges Link: https://patch.msgid.link/20261001204752.2572265-7-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/ip6_route.h | 7 +++++++ net/core/dev.c | 5 ++++- net/ipv6/route.c | 24 ++++++++++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 0f9b7a260d25..b9de335b639a 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -231,6 +231,13 @@ void rt6_multipath_rebalance(struct fib6_info *f6i); void rt6_uncached_list_add(struct rt6_info *rt); void rt6_uncached_list_del(struct rt6_info *rt); +#ifdef CONFIG_IPV6 +void rt6_uncached_list_flush_dev(struct net_device *dev); +#else +static inline void rt6_uncached_list_flush_dev(struct net_device *dev) +{ +} +#endif static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb) { diff --git a/net/core/dev.c b/net/core/dev.c index f76a4459d8e1..f587645e930a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -131,6 +131,7 @@ #include #include #include +#include #include #include #include @@ -11887,8 +11888,10 @@ void netdev_run_todo(void) linkwatch_sync_dev(dev); } - if (!list_empty(&list)) + if (!list_empty(&list)) { rt_flush_dev(NULL); + rt6_uncached_list_flush_dev(NULL); + } cnt = 0; while (!list_empty(&list)) { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index a76869ff87cd..b1dcb5e5da88 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -158,10 +158,16 @@ void rt6_uncached_list_del(struct rt6_info *rt) } } -static void rt6_uncached_list_flush_dev(struct net_device *dev) +void rt6_uncached_list_flush_dev(struct net_device *dev) { int cpu; + if (!ipv6_mod_enabled()) + return; + + if (dev && dev->dismantle) + return; + for_each_possible_cpu(cpu) { struct uncached_list *ul = per_cpu_ptr(&rt6_uncached_list, cpu); struct rt6_info *rt, *safe; @@ -173,22 +179,24 @@ static void rt6_uncached_list_flush_dev(struct net_device *dev) list_for_each_entry_safe(rt, safe, &ul->head, dst.rt_uncached) { struct inet6_dev *rt_idev = rt->rt6i_idev; struct net_device *rt_dev = rt->dst.dev; - bool handled = false; - if (rt_idev && rt_idev->dev == dev) { + if (rt_idev && + (dev ? rt_idev->dev == dev : + READ_ONCE(rt_idev->dev->reg_state) == NETREG_UNREGISTERED)) { rt->rt6i_idev = in6_dev_get(blackhole_netdev); in6_dev_put(rt_idev); - handled = true; } - if (rt_dev == dev) { - rt->dst.dev = blackhole_netdev; + if (dev ? rt_dev == dev : + READ_ONCE(rt_dev->reg_state) == NETREG_UNREGISTERED) { + rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev); netdev_ref_replace(rt_dev, blackhole_netdev, &rt->dst.dev_tracker, GFP_ATOMIC); - handled = true; } - if (handled) + + if (rt->dst.dev == blackhole_netdev && + (!rt->rt6i_idev || rt->rt6i_idev->dev == blackhole_netdev)) list_del_init(&rt->dst.rt_uncached); } spin_unlock_bh(&ul->lock); From 388e1d3a179fc9cb32c39bbba29a20171157382d Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Thu, 1 Oct 2026 22:40:54 +0000 Subject: [PATCH 1164/2126] net: devmem: use page_pool_put_netmem_bulk Instead of looping over napi_pp_put_page() and repeatedly acquiring the page_pool producer lock in sock_devmem_dontneed(), use page_pool_put_netmem_bulk() to return the netmem references in batches. This reduces the number of lock acquisitions on the page pool ring producer lock when releasing user tokens. Reviewed-by: Mina Almasry Acked-by: Stanislav Fomichev Signed-off-by: Kaifeng Wang Link: https://patch.msgid.link/20261001224054.1525365-1-kaifengw@google.com Signed-off-by: Jakub Kicinski --- net/core/sock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/core/sock.c b/net/core/sock.c index 6db7c8295d58..ee81c62be517 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -129,6 +129,7 @@ #include #include #include +#include #include #include #include @@ -1086,7 +1087,7 @@ success: static noinline_for_stack int sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen) { - unsigned int num_tokens, i, j, k, netmem_num = 0; + unsigned int num_tokens, i, j, netmem_num = 0; struct dmabuf_token *tokens; int ret = 0, num_frags = 0; netmem_ref netmems[16]; @@ -1123,8 +1124,8 @@ sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen) netmems[netmem_num++] = netmem; if (netmem_num == ARRAY_SIZE(netmems)) { xa_unlock_bh(&sk->sk_user_frags); - for (k = 0; k < netmem_num; k++) - WARN_ON_ONCE(!napi_pp_put_page(netmems[k])); + page_pool_put_netmem_bulk(netmems, + ARRAY_SIZE(netmems)); netmem_num = 0; xa_lock_bh(&sk->sk_user_frags); } @@ -1134,8 +1135,7 @@ sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen) frag_limit_reached: xa_unlock_bh(&sk->sk_user_frags); - for (k = 0; k < netmem_num; k++) - WARN_ON_ONCE(!napi_pp_put_page(netmems[k])); + page_pool_put_netmem_bulk(netmems, netmem_num); kvfree(tokens); return ret; From 06192231d08937dd523ef8c8a691c390e1e638c0 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 1 Oct 2026 16:02:33 +0300 Subject: [PATCH 1165/2126] net: usb: lan78xx: register the PHY interrupt with the MDIO bus The interrupt this driver maps for its PHY is written only into phydev->irq, while the bus table mdiobus->irq[] keeps reading PHY_POLL for the same address. That table is where phylib records what the bus described - phy_device_create() seeds phydev->irq from it - so the number lives only as long as nothing else writes that one field. Copy the number into the table entry of the PHY this driver attaches, and into no other. The chip has one PHY interrupt, and on 7801 phy_mask is 0, so other PHYs on the bus keep what the bus gave them. The address is known only after the scan, so the write to phydev->irq stays. Found going through the drivers that keep a PHY interrupt outside the bus table, so that the restore on detach later in this series has a number to hand back here as well. Signed-off-by: Aleksei Sviridkin Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261001130236.106059-2-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/usb/lan78xx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 5655941f1478..babd34cda374 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -2897,6 +2897,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) phydev->irq = dev->domain_data.phyirq; else phydev->irq = PHY_POLL; + dev->mdiobus->irq[phydev->mdio.addr] = phydev->irq; netdev_dbg(dev->net, "phydev->irq = %d\n", phydev->irq); ret = phylink_connect_phy(dev->phylink, phydev); From 2c583f49e8f080791925288797dd2ac541191fdc Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 1 Oct 2026 16:02:34 +0300 Subject: [PATCH 1166/2126] net: usb: smsc95xx: register the PHY interrupt with the MDIO bus The interrupt this driver maps for its PHY is written only into phydev->irq, while the bus table mdiobus->irq[] keeps reading PHY_POLL for the same address. That table is where phylib records what the bus described - phy_device_create() seeds phydev->irq from it - so the number lives only as long as nothing else writes that one field. Copy the number into the table entry of the PHY this driver found, and into no other. With an external PHY phy_mask is 0, so other PHYs on the bus keep polling. The address is known only after the scan, so the write to phydev->irq stays. Found going through the drivers that keep a PHY interrupt outside the bus table, so that the restore on detach later in this series has a number to hand back here as well. Signed-off-by: Aleksei Sviridkin Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261001130236.106059-3-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/usb/smsc95xx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 42e4048b574b..130a460c1f54 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -1252,6 +1252,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) goto unregister_mdio; } + pdata->mdiobus->irq[pdata->phydev->mdio.addr] = phy_irq; pdata->phydev->irq = phy_irq; pdata->phydev->is_internal = pdata->is_internal_phy; From 026bb4593faf31585a82781df25370c82cf95ed6 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 1 Oct 2026 16:02:35 +0300 Subject: [PATCH 1167/2126] net: phy: take the interrupt back from the bus on detach When a PHY's driver is a module that is not loaded yet when the MAC connects, the PHY gets the generic driver first. phy_probe() then replaces phydev->irq with PHY_POLL, because genphy has no interrupt support. Nothing puts the number back, so after the real driver binds the PHY is polled for the rest of the uptime. Seen on a Keenetic KN-1012: the Airoha EN8811H behind an MT7531 port has its driver on the root filesystem. Its devicetree interrupt maps to irq 15, and after the real driver binds phydev->irq reads -1. Restore the number when the PHY detaches. It comes from the bus table, mdiobus->irq[], where the bus or the MAC driver recorded it. Do it only when phy_attach_direct() bound the generic driver, since that is the substitution being undone; otherwise the field belongs to whoever wrote it. Do it before device_release_driver(), because after the release a probing driver can write the same field. The store is ordered before the release rather than locked against it: device_release_driver() takes the device lock itself. A MAC that sets phydev->irq before phy_start(), as phy.rst describes, is not affected, since the restore runs on detach, between connections. Tested on the KN-1012 with a 6.18 distribution kernel: phydev->irq reads 15 after the real driver binds, and -1 without this patch. Cc: stable+noautosel@kernel.org # never worked Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of the connected PHY's design and operation details.") Signed-off-by: Aleksei Sviridkin Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261001130236.106059-4-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 5b13a74e2fa9..d6dd16f1960e 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1737,6 +1737,8 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus) * real driver could be loaded */ if (phydev->is_genphy_driven) { + /* The release below lets phy_probe() write this field. */ + phydev->irq = phydev->mdio.bus->irq[phydev->mdio.addr]; device_release_driver(&phydev->mdio.dev); phydev->is_genphy_driven = 0; } From 4719b69bb66be74d7a2cb4d3887031de90c66ac9 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 1 Oct 2026 16:02:36 +0300 Subject: [PATCH 1168/2126] net: phy: restore the interrupt when the generic bind cycle fails When phy_attach_direct() binds the generic driver itself and the bind fails, the PHY is left with polling in place of its interrupt. phy_probe() has already replaced phydev->irq with PHY_POLL by then. The unwind does not go through phy_detach(), so the restore there does not run, and a later attach finds a PHY that can only be polled. Found on a Keenetic KN-1012 while adding the restore in phy_detach(), as the other way out of the same bind cycle. Save the interrupt number on entry and put it back on the error path. The bus table is not the right source here. The same label is reached when a second attach of a PHY already attached through the generic driver fails, and there the field is live. The table also misses a PHY_MAC_INTERRUPT that a MAC wrote into phydev->irq. Tested on the KN-1012 with a 6.18 distribution kernel and an injected failure of the generic probe: phydev->irq reads 15 afterwards, and -1 with only the restore in phy_detach(). Cc: stable+noautosel@kernel.org # never worked Fixes: 6d9f66ac7fec ("net: phy: Fix PHY module checks and NULL deref in phy_attach_direct()") Signed-off-by: Aleksei Sviridkin Link: https://patch.msgid.link/20261001130236.106059-5-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index d6dd16f1960e..bfce8b893644 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1794,6 +1794,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, struct mii_bus *bus = phydev->mdio.bus; struct device *d = &phydev->mdio.dev; struct module *ndev_owner = NULL; + int irq = phydev->irq; int err; /* For Ethernet device drivers that register their own MDIO bus, we @@ -1941,6 +1942,7 @@ error: error_module_put: module_put(d->driver->owner); + phydev->irq = irq; phydev->is_genphy_driven = 0; d->driver = NULL; error_put_device: From 88fb9fad5cbe95d2d3e1ac02e764d88217e5f668 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Sun, 4 Oct 2026 13:10:53 -0400 Subject: [PATCH 1169/2126] net/packet: ignore timestamp bits when testing tx frame status Since the commit in Fixes, the tx completion handler writes the frame status as TP_STATUS_AVAILABLE | ts, where ts can be TP_STATUS_TS_SOFTWARE or TP_STATUS_TS_RAW_HARDWARE. Two places compare a tx frame status to TP_STATUS_AVAILABLE for equality, and so fail to detect such a released frame: - tpacket_snd(), when packet_xmit() fails: the packet is silently dropped instead of an error being returned to the caller for retry. - packet_poll(), on the tx ring head frame: the socket is not reported as writable. Mask out the timestamp bits in both. In packet_lookup_frame(), only do so when testing a tx ring frame for TP_STATUS_AVAILABLE. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: b9c32fb27170 ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got") Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20261004171847.186954-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- net/packet/af_packet.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index e9a7ff36118a..2c5c1f256947 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -398,6 +398,10 @@ static inline struct page * __pure pgv_to_page(void *addr) return virt_to_page(addr); } +/* Timestamp bits that may be set in addition to the frame state */ +static const u32 tp_status_ts_mask = TP_STATUS_TS_SOFTWARE | + TP_STATUS_TS_RAW_HARDWARE; + static void __packet_set_status(struct packet_sock *po, void *frame, int status) { union tpacket_uhdr h; @@ -519,6 +523,7 @@ static void *packet_lookup_frame(const struct packet_sock *po, { unsigned int pg_vec_pos, frame_offset; union tpacket_uhdr h; + u32 mask = 0; pg_vec_pos = position / rb->frames_per_block; frame_offset = position % rb->frames_per_block; @@ -526,7 +531,10 @@ static void *packet_lookup_frame(const struct packet_sock *po, h.raw = rb->pg_vec[pg_vec_pos].buffer + (frame_offset * rb->frame_size); - if (status != __packet_get_status(po, h.raw)) + if (rb == &po->tx_ring && status == TP_STATUS_AVAILABLE) + mask = tp_status_ts_mask; + + if (status != (__packet_get_status(po, h.raw) & ~mask)) return NULL; return h.raw; @@ -2947,7 +2955,7 @@ tpacket_error: if (unlikely(err != 0)) { if (err > 0) err = net_xmit_errno(err); - if (err && __packet_get_status(po, ph) == + if (err && (__packet_get_status(po, ph) & ~tp_status_ts_mask) == TP_STATUS_AVAILABLE) { /* skb was destructed already */ skb = NULL; From 60b5268444a1e684785ee4dec8226338a1b54919 Mon Sep 17 00:00:00 2001 From: Umang Pokhriyal Date: Sun, 4 Oct 2026 23:17:38 +0530 Subject: [PATCH 1170/2126] tap: report IFF_DETACH_QUEUE in TUNGETIFF tun sets IFF_DETACH_QUEUE in the flags returned by TUNGETIFF when the queue is detached, since commit 3d407a80b62f ("tun: Report whether the queue is attached or not"). tap does not, so userspace cannot tell a detached macvtap or ipvtap queue from an attached one. Cloud Hypervisor ran into this when checking queue state on macvtap. Report the flag from q->enabled, as tun does. Unlike tun, tap accepts TUNSETIFF on a bound fd, so ignore IFF_DETACH_QUEUE there to keep writing the TUNGETIFF flags back working. Signed-off-by: Umang Pokhriyal Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20261004174739.36179-1-umangpokhriyall@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/tap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index ff67d99deb39..832439b8a898 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -932,6 +932,9 @@ static long tap_ioctl(struct file *file, unsigned int cmd, if (get_user(u, &ifr->ifr_flags)) return -EFAULT; + /* TUNGETIFF may report IFF_DETACH_QUEUE, ignore it here */ + u &= ~IFF_DETACH_QUEUE; + ret = 0; if ((u & ~TAP_IFFEATURES) != (IFF_NO_PI | IFF_TAP)) ret = -EINVAL; @@ -950,6 +953,8 @@ static long tap_ioctl(struct file *file, unsigned int cmd, ret = 0; u = q->flags; + if (!q->enabled) + u |= IFF_DETACH_QUEUE; if (copy_to_user(&ifr->ifr_name, tap->dev->name, IFNAMSIZ) || put_user(u, &ifr->ifr_flags)) ret = -EFAULT; From d11306ac26896ade50a0d706f781999eb2e37c5c Mon Sep 17 00:00:00 2001 From: Yongzhao Chen Date: Sat, 3 Oct 2026 19:24:02 +0200 Subject: [PATCH 1171/2126] net: dsa: qca8k: propagate MDIO errors qca8k_mii_write32() ignores errors from both 16-bit half-word writes. Its callers (register writes and read-modify-write helpers) then return the earlier successful page selection or read result, incorrectly reporting success even when writing the switch register failed. Propagate write errors from both the low and high half-words through the regmap paths and internal MDIO master transactions. Attempt to clear MASTER_EN even if a transaction fails, preserving the initial error, and report a cleanup failure if the transaction itself succeeded. Preserve the existing Ethernet-to-MDIO fallback order. Propagate read errors through the internal and legacy MDIO bus callbacks instead of masking them as 0xffff. Returning 0xffff causes PHY read-modify-write callers to treat the failed read as valid register data, which can corrupt unrelated bits on writeback. Stop polling when reading the MDIO busy status fails, and return the error immediately. Because the read helper clears its output on failure, checking only the BUSY bit mistakes an unsuccessful read for transaction completion. Code inspection found these problems. Fault injection into a userspace model of the driver's functions reproduces them; the corresponding cases pass after this change. qca8k_mii_write32() has not returned write errors since its introduction in commit 6b93fb46480a ("net-next: dsa: add new driver for qca8xxx family"). Signed-off-by: Yongzhao Chen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261003172405.342-2-yongzhao.derek@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/qca/qca8k-8xxx.c | 53 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 60f2a615a5cc..b73c7c52e0f9 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -129,13 +129,16 @@ err: return ret; } -static void +static int qca8k_mii_write32(struct mii_bus *bus, int phy_id, u32 regnum, u32 val) { - if (qca8k_mii_write_lo(bus, phy_id, regnum, val) < 0) - return; + int ret; - qca8k_mii_write_hi(bus, phy_id, regnum + 1, val); + ret = qca8k_mii_write_lo(bus, phy_id, regnum, val); + if (ret < 0) + return ret; + + return qca8k_mii_write_hi(bus, phy_id, regnum + 1, val); } static int @@ -462,7 +465,7 @@ qca8k_write_mii(struct qca8k_priv *priv, uint32_t reg, uint32_t val) if (ret < 0) goto exit; - qca8k_mii_write32(bus, 0x10 | r2, r1, val); + ret = qca8k_mii_write32(bus, 0x10 | r2, r1, val); exit: mutex_unlock(&bus->mdio_lock); @@ -492,7 +495,7 @@ qca8k_regmap_update_bits_mii(struct qca8k_priv *priv, uint32_t reg, val &= ~mask; val |= write_val; - qca8k_mii_write32(bus, 0x10 | r2, r1, val); + ret = qca8k_mii_write32(bus, 0x10 | r2, r1, val); exit: mutex_unlock(&bus->mdio_lock); @@ -794,19 +797,18 @@ static int qca8k_mdio_busy_wait(struct mii_bus *bus, u32 reg, u32 mask) { u16 r1, r2, page; - u32 val; int ret, ret1; + u32 val; qca8k_split_addr(reg, &r1, &r2, &page); - ret = read_poll_timeout(qca8k_mii_read_hi, ret1, !(val & mask), 0, + ret = read_poll_timeout(qca8k_mii_read_hi, ret1, + ret1 < 0 || !(val & mask), 0, QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC, false, bus, 0x10 | r2, r1 + 1, &val); - /* Check if qca8k_read has failed for a different reason - * before returnting -ETIMEDOUT - */ - if (ret < 0 && ret1 < 0) + /* Preserve an MDIO read error instead of treating it as ready. */ + if (ret1 < 0) return ret1; return ret; @@ -817,8 +819,8 @@ qca8k_mdio_write(struct qca8k_priv *priv, int phy, int regnum, u16 data) { struct mii_bus *bus = priv->bus; u16 r1, r2, page; + int ret, ret1; u32 val; - int ret; if (regnum >= QCA8K_MDIO_MASTER_MAX_REG) return -EINVAL; @@ -836,14 +838,18 @@ qca8k_mdio_write(struct qca8k_priv *priv, int phy, int regnum, u16 data) if (ret) goto exit; - qca8k_mii_write32(bus, 0x10 | r2, r1, val); + ret = qca8k_mii_write32(bus, 0x10 | r2, r1, val); + if (ret < 0) + goto exit; ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL, QCA8K_MDIO_MASTER_BUSY); exit: /* even if the busy_wait timeouts try to clear the MASTER_EN */ - qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, 0); + ret1 = qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, 0); + if (!ret) + ret = ret1; mutex_unlock(&bus->mdio_lock); @@ -855,8 +861,8 @@ qca8k_mdio_read(struct qca8k_priv *priv, int phy, int regnum) { struct mii_bus *bus = priv->bus; u16 r1, r2, page; + int ret, ret1; u32 val; - int ret; if (regnum >= QCA8K_MDIO_MASTER_MAX_REG) return -EINVAL; @@ -873,7 +879,9 @@ qca8k_mdio_read(struct qca8k_priv *priv, int phy, int regnum) if (ret) goto exit; - qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, val); + ret = qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, val); + if (ret < 0) + goto exit; ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL, QCA8K_MDIO_MASTER_BUSY); @@ -884,7 +892,9 @@ qca8k_mdio_read(struct qca8k_priv *priv, int phy, int regnum) exit: /* even if the busy_wait timeouts try to clear the MASTER_EN */ - qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, 0); + ret1 = qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, 0); + if (!ret) + ret = ret1; mutex_unlock(&bus->mdio_lock); @@ -919,12 +929,7 @@ qca8k_internal_mdio_read(struct mii_bus *slave_bus, int phy, int regnum) if (ret >= 0) return ret; - ret = qca8k_mdio_read(priv, phy, regnum); - - if (ret < 0) - return 0xffff; - - return ret; + return qca8k_mdio_read(priv, phy, regnum); } static int From 2fc23f832e30a7918ca3e97e03845ea2f863af45 Mon Sep 17 00:00:00 2001 From: Yongzhao Chen Date: Sat, 3 Oct 2026 19:24:03 +0200 Subject: [PATCH 1172/2126] net: dsa: qca8k: do not clear MASTER_EN after a failed page select qca8k_mdio_write() and qca8k_mdio_read() take the common exit path when selecting the page of QCA8K_MDIO_MASTER_CTRL fails. That path clears MASTER_CTRL[31:16] with a raw write to phy 0x10, reg 0x1f, which only addresses MASTER_CTRL while page 0 is selected. After a failed page select that did not reach the switch, the previous page remains selected. The write can then clear the upper half of an unrelated register at page * 0x200 + 0x3c. No MDIO master transaction has been started at that point, so there is nothing to clean up. Unlock and return the error directly. qca8k_set_page() also keeps the old cached page when the page write fails. If the write did reach the switch, a later access to the cached page skips the page select and reaches the wrong register. Invalidate the cache on failure so that the next access selects the page again. The Sashiko review of v1 identified the stray cleanup write. A userspace model of the driver's functions reproduces both problems by injecting page-select failures with and without a hardware page change; these cases pass after this change. The cleanup write comes from commit 759bafb8a322 ("net: dsa: qca8k: add support for internal phy and internal mdio"), and the stale page cache from commit ba5707ec58cf ("net: dsa: qca8k: handle qca8k_set_page errors"). Signed-off-by: Yongzhao Chen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261003172405.342-3-yongzhao.derek@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/qca/qca8k-8xxx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index b73c7c52e0f9..2708430413d3 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -153,6 +153,8 @@ qca8k_set_page(struct qca8k_priv *priv, u16 page) ret = bus->write(bus, 0x18, 0, page); if (ret < 0) { + /* The switch may or may not have switched pages. */ + *cached_page = 0xffff; dev_err_ratelimited(&bus->dev, "failed to set qca8k page\n"); return ret; @@ -836,7 +838,7 @@ qca8k_mdio_write(struct qca8k_priv *priv, int phy, int regnum, u16 data) ret = qca8k_set_page(priv, page); if (ret) - goto exit; + goto unlock; ret = qca8k_mii_write32(bus, 0x10 | r2, r1, val); if (ret < 0) @@ -851,6 +853,7 @@ exit: if (!ret) ret = ret1; +unlock: mutex_unlock(&bus->mdio_lock); return ret; @@ -877,7 +880,7 @@ qca8k_mdio_read(struct qca8k_priv *priv, int phy, int regnum) ret = qca8k_set_page(priv, page); if (ret) - goto exit; + goto unlock; ret = qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, val); if (ret < 0) @@ -896,6 +899,7 @@ exit: if (!ret) ret = ret1; +unlock: mutex_unlock(&bus->mdio_lock); if (ret >= 0) From fe0811dd1a33f4b50d7107220334a1eb783bbe6b Mon Sep 17 00:00:00 2001 From: Yongzhao Chen Date: Sat, 3 Oct 2026 19:24:04 +0200 Subject: [PATCH 1173/2126] net: dsa: qca8k: fail mgmt Ethernet MDIO access on busy wait errors qca8k_phy_eth_command() polls MASTER_CTRL over management Ethernet until BUSY clears, but only bails out when the poll timed out and the last poll request also failed. If every request succeeds while BUSY stays set, the -ETIMEDOUT is dropped. A read then returns MASTER_CTRL data from a transaction that has not completed, and qca8k_internal_mdio_read() does not fall back to the MDIO bus. A failed poll request does not stop the loop either. qca8k_phy_eth_busy_wait() leaves the value unchanged on failure, so the BUSY test then uses the previous value, or an uninitialized one if the first request fails. Stop polling when a request fails and return the poll error or timeout. The poll-error path also leaked read_skb, which is only consumed when the read request is sent; free it on this path. The Sashiko review of v1 identified the dropped timeout. A userspace model of the driver's functions reproduces it and the poll-error path with scripted BUSY responses and failed poll requests; these cases pass after this change. The polling loop comes from commit 2cd548566384 ("net: dsa: qca8k: add support for phy read/write with mgmt Ethernet"). Signed-off-by: Yongzhao Chen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261003172405.342-4-yongzhao.derek@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/qca/qca8k-8xxx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 2708430413d3..07227ae8bc04 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -728,12 +728,15 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy, } ret = read_poll_timeout(qca8k_phy_eth_busy_wait, ret1, - !(val & QCA8K_MDIO_MASTER_BUSY), 0, + ret1 < 0 || !(val & QCA8K_MDIO_MASTER_BUSY), 0, QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC, false, mgmt_eth_data, read_skb, &val); - if (ret < 0 && ret1 < 0) { + if (ret1 < 0) ret = ret1; + + if (ret < 0) { + kfree_skb(read_skb); goto exit; } From 28eef87694a50e86cd868b1e13580480bd9e8450 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:38:21 +0800 Subject: [PATCH 1174/2126] tun: Drain eBPF RCU callbacks on module exit Replacing or clearing a TUN eBPF program defers its destruction to tun_prog_free(). In the device teardown path, tun_free_netdev() can queue this callback as a private destructor. The rcu_barrier() in netdev_run_todo() runs before private destructors, so it cannot drain the new callback. After the last file or persistent-device reference is released, tun can therefore unload before the callback runs. Drain outstanding callbacks at the end of module cleanup so they cannot execute from freed module text. These issues were found by a static analysis method. Cc: stable+noautosel@kernel.org # needs real net-admin (non-ns) Fixes: 96f84061620c ("tun: add eBPF based queue selection method") Signed-off-by: Jiale Yao Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20261003093822.544964-1-yaojiale02@163.com Signed-off-by: Jakub Kicinski --- drivers/net/tun.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 5a302709a68a..bde5032bf4f4 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -3855,6 +3855,7 @@ static void __exit tun_cleanup(void) misc_deregister(&tun_miscdev); rtnl_link_unregister(&tun_link_ops); unregister_netdevice_notifier(&tun_notifier_block); + rcu_barrier(); } /* Get an underlying socket object from tun file. Returns error unless file is From 46d20a256be5069d4e238677c8a5736672b724da Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Mon, 5 Oct 2026 17:39:32 +0300 Subject: [PATCH 1175/2126] net: bridge: rename dst to fwd in br_flood_vlan Rename dst to fwd to be consistent and avoid confusion (dst is used for fdbs). Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005143937.877466-2-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_forward.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 82645db32efb..54365c6104b5 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -291,7 +291,7 @@ static int br_flood_vlan(struct br_fwd_dst *prev, { struct net_bridge_vlan_port_array *array; struct net_bridge_vlan *masterv, *pv; - struct br_fwd_dst dst; + struct br_fwd_dst fwd; int err; masterv = br_vlan_is_master(v) ? v : v->brvlan; @@ -301,18 +301,18 @@ static int br_flood_vlan(struct br_fwd_dst *prev, for (i = 0; i < array->count; i++) { pv = array->vlans[i]; - dst.port = pv->port; - dst.vlan = pv; - err = br_flood_port(prev, &dst, skb, pkt_type, + fwd.port = pv->port; + fwd.vlan = pv; + err = br_flood_port(prev, &fwd, skb, pkt_type, local_orig); if (err) return err; } } else { list_for_each_entry_rcu(pv, &masterv->port_vlist, port_vlist) { - dst.port = pv->port; - dst.vlan = pv; - err = br_flood_port(prev, &dst, skb, pkt_type, + fwd.port = pv->port; + fwd.vlan = pv; + err = br_flood_port(prev, &fwd, skb, pkt_type, local_orig); if (err) return err; From 6317ffc9bdd0594fcada1a065539ebf5b928746c Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Mon, 5 Oct 2026 17:39:33 +0300 Subject: [PATCH 1176/2126] net: bridge: fdb: update the comment for br_fdb_cleanup_by_dst Update the comment for br_fdb_cleanup_by_dst to better reflect what it is doing after the recent changes. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005143937.877466-3-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 730b178cf6c4..ce09e3fbc58b 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -868,9 +868,11 @@ int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev, return 0; } -/* Clean up all entries referring to a specific destination. - * if do_all is set also flush static entries - * if vid is set delete all entries that match the vlan_id +/* Clean up entries referring to cleanup_dst's port. + * If do_all is set ignore vid and entry flags. Otherwise vid selects + * the VLAN (0 means all), keeping static and non-offloaded ext learned entries. + * For a port-VLAN dst, vid must match its VLAN ID. Always clean up its local + * entry unless user-added and fall back to the port dst for retained entries. */ void br_fdb_cleanup_by_dst(struct net_bridge *br, struct net_bridge_dst cleanup_dst, u16 vid, From 33c73892eaab32ffa1c86088717996a00eda6cf9 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Mon, 5 Oct 2026 17:39:34 +0300 Subject: [PATCH 1177/2126] net: bridge: vlan: share VLAN validation in br_should_learn Both the pvid and tagged paths now resolve a VLAN entry. Select the entry first and share the state check and output assignment. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005143937.877466-4-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_vlan.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 0675f74cf1b9..dcf783e1a440 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -742,21 +742,16 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, if (!br_vlan_get_tag(skb, &vid) && skb->vlan_proto != br->vlan_proto) vid = 0; - if (!vid) { + if (vid) + v = br_vlan_find(vg, vid); + else v = rcu_dereference(vg->pvid); - if (!v || !br_vlan_state_allowed(br_vlan_get_state(v), true)) - return false; - *vlan = v; - return true; - } - v = br_vlan_find(vg, vid); - if (v && br_vlan_state_allowed(br_vlan_get_state(v), true)) { - *vlan = v; - return true; - } + if (!v || !br_vlan_state_allowed(br_vlan_get_state(v), true)) + return false; - return false; + *vlan = v; + return true; } static int br_vlan_add_existing(struct net_bridge *br, From 1fbe2d9d37adbc881c3a558de0903c8c0e70651c Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Mon, 5 Oct 2026 17:39:35 +0300 Subject: [PATCH 1178/2126] net: bridge: vlan: inline pvid pointer updates After caching the pvid VLAN entry directly, the add and delete helpers only check and update the pointer. So inline them both and clear pvid directly in __vlan_flush before walking the VLAN entries. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005143937.877466-5-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_vlan.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index dcf783e1a440..c4e7e03e0969 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -34,24 +34,6 @@ static struct net_bridge_vlan *br_vlan_lookup(struct rhashtable *tbl, u16 vid) return rhashtable_lookup_fast(tbl, &vid, br_vlan_rht_params); } -static void __vlan_add_pvid(struct net_bridge_vlan_group *vg, - struct net_bridge_vlan *v) -{ - if (rcu_access_pointer(vg->pvid) == v) - return; - - RCU_INIT_POINTER(vg->pvid, v); -} - -static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, - struct net_bridge_vlan *v) -{ - if (rcu_access_pointer(vg->pvid) != v) - return; - - RCU_INIT_POINTER(vg->pvid, NULL); -} - /* Update the BRIDGE_VLAN_INFO_PVID and BRIDGE_VLAN_INFO_UNTAGGED flags of @v. * If @commit is false, return just whether the BRIDGE_VLAN_INFO_PVID and * BRIDGE_VLAN_INFO_UNTAGGED bits of @flags would produce any change onto @v. @@ -78,10 +60,12 @@ static bool __vlan_flags_update(struct net_bridge_vlan *v, u16 flags, if (!commit) goto out; - if (flags & BRIDGE_VLAN_INFO_PVID) - __vlan_add_pvid(vg, v); - else - __vlan_delete_pvid(vg, v); + if (flags & BRIDGE_VLAN_INFO_PVID) { + if (pvid != v) + RCU_INIT_POINTER(vg->pvid, v); + } else if (pvid == v) { + RCU_INIT_POINTER(vg->pvid, NULL); + } if (flags & BRIDGE_VLAN_INFO_UNTAGGED) vlan_flags |= BRIDGE_VLAN_INFO_UNTAGGED; @@ -432,7 +416,8 @@ out_filt: static void __vlan_unpublish(struct net_bridge_vlan_group *vg, struct net_bridge_vlan *v) { - __vlan_delete_pvid(vg, v); + if (rcu_access_pointer(vg->pvid) == v) + RCU_INIT_POINTER(vg->pvid, NULL); if (!br_vlan_is_master(v)) { struct net_bridge_vlan *masterv = v->brvlan; @@ -503,7 +488,7 @@ static void __vlan_flush(const struct net_bridge *br, struct net_bridge_vlan *vlan, *tmp; u16 v_start = 0, v_end = 0; - __vlan_delete_pvid(vg, rtnl_dereference(vg->pvid)); + RCU_INIT_POINTER(vg->pvid, NULL); list_for_each_entry_safe(vlan, tmp, &vg->vlan_list, vlist) { /* take care of disjoint ranges */ if (!v_start) { From d65082c8bfb8779b214c8f723f5f19dd9de5921e Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Mon, 5 Oct 2026 17:39:36 +0300 Subject: [PATCH 1179/2126] net: bridge: fdb: factor out configured entry destination updates Share the destination update logic used by user configured and ext learned entries. Report a modification only when the port changes. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005143937.877466-6-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index ce09e3fbc58b..927e5f23df5b 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -1193,6 +1193,22 @@ static bool fdb_handle_notify(struct net_bridge_fdb_entry *fdb, u8 notify) return modified; } +static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb, + struct net_bridge_dst old_dst, + struct net_bridge_dst dst) +{ + if (br_dst_equal(old_dst, dst)) + return false; + + if (br_dst_port(old_dst) == br_dst_port(dst)) { + br_fdb_dst_replace(fdb, old_dst, dst); + return false; + } + + br_fdb_dst_write(fdb, dst); + return true; +} + /* Update (create or replace) forwarding database entry */ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst, const u8 *addr, struct ndmsg *ndm, u16 flags, u16 vid, @@ -1246,14 +1262,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst, return -EEXIST; old_dst = br_fdb_dst_read(fdb); - if (!br_dst_equal(old_dst, dst)) { - if (br_dst_port(old_dst) != source) { - modified = true; - br_fdb_dst_write(fdb, dst); - } else { - br_fdb_dst_replace(fdb, old_dst, dst); - } - } + modified = fdb_update_dst(fdb, old_dst, dst); set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags)) @@ -1634,14 +1643,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, WRITE_ONCE(fdb->updated, jiffies); - if (!br_dst_equal(old_dst, dst)) { - if (br_dst_port(old_dst) != p) { - modified = true; - br_fdb_dst_write(fdb, dst); - } else { - br_fdb_dst_replace(fdb, old_dst, dst); - } - } + modified = fdb_update_dst(fdb, old_dst, dst); if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) { /* Refresh entry */ From 8f8a20dc7bf0e349b36c28badcb7005f88314fcb Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Mon, 5 Oct 2026 17:39:37 +0300 Subject: [PATCH 1180/2126] net: bridge: fdb: use the entry key in __fdb_update The address and VLAN ID passed to __fdb_update() match the key of the entry just found, so we can just use it. Signed-off-by: Nikolay Aleksandrov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005143937.877466-7-razor@blackwall.org Signed-off-by: Jakub Kicinski --- net/bridge/br_fdb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 927e5f23df5b..b601245ad923 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -1000,7 +1000,6 @@ static void __fdb_update(struct net_bridge *br, struct net_bridge_fdb_entry *fdb, struct net_bridge_port *source, struct net_bridge_dst dst, - const unsigned char *addr, u16 vid, unsigned long flags) { struct net_bridge_port *old_port; @@ -1012,7 +1011,8 @@ static void __fdb_update(struct net_bridge *br, if (unlikely(test_bit(BR_FDB_LOCAL, &fdb->flags))) { if (net_ratelimit()) br_warn(br, "received packet on %s with own address as source address (addr:%pM, vlan:%u)\n", - source->dev->name, addr, vid); + source->dev->name, fdb->key.addr.addr, + fdb->key.vlan_id); return; } @@ -1055,7 +1055,8 @@ static void __fdb_update(struct net_bridge *br, } if (unlikely(fdb_modified)) { - trace_br_fdb_update(br, source, addr, vid, flags); + trace_br_fdb_update(br, source, fdb->key.addr.addr, + fdb->key.vlan_id, flags); fdb_notify(br, fdb, RTM_NEWNEIGH, true); } } @@ -1075,7 +1076,7 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid); if (likely(fdb)) { - __fdb_update(br, fdb, source, dst, addr, vid, flags); + __fdb_update(br, fdb, source, dst, flags); } else { spin_lock(&br->hash_lock); fdb = fdb_create(br, dst, addr, vid, flags); From cc7a4a3138a4df44b83940afbe2de330173cc28c Mon Sep 17 00:00:00 2001 From: Bhargava Marreddy Date: Mon, 5 Oct 2026 17:47:01 +0530 Subject: [PATCH 1181/2126] bnge: fix NULL deref in bnge_alloc_core() on failure bnge_alloc_core() previously jumped to a single error label that called bnge_free_core() to unwind. However, bnge_free_core() assumes a fully initialized state and dereferences rx/tx ring arrays unconditionally. If ring allocations fail early, this causes a near-NULL dereference. Introduce a standard goto ladder to unwind only the resources that were successfully allocated, preventing NULL dereferences. Cc: stable+noautosel@kernel.org # fix to unlikely driver error path Fixes: 0259379037ca ("bng_en: Add initial support for RX and TX rings") Signed-off-by: Bhargava Marreddy Reviewed-by: Dharmender Garg Reviewed-by: Rajashekar Hudumula Reviewed-by: Ramakrishna Koduri Reviewed-by: Przemek Kitszel Link: https://patch.msgid.link/20261005121704.227866-2-bhargava.marreddy@broadcom.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c index a4288f0258f8..bf101eded3bf 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c @@ -1243,7 +1243,7 @@ static int bnge_alloc_core(struct bnge_net *bn) bn->rx_ring = kzalloc_objs(struct bnge_rx_ring_info, bd->rx_nr_rings); if (!bn->rx_ring) - goto err_free_core; + goto err_free_bnapi; for (i = 0; i < bd->rx_nr_rings; i++) { struct bnge_rx_ring_info *rxr = &bn->rx_ring[i]; @@ -1258,12 +1258,12 @@ static int bnge_alloc_core(struct bnge_net *bn) bn->tx_ring = kzalloc_objs(struct bnge_tx_ring_info, bd->tx_nr_rings); if (!bn->tx_ring) - goto err_free_core; + goto err_free_rx_ring; bn->tx_ring_map = kcalloc(bd->tx_nr_rings, sizeof(u16), GFP_KERNEL); if (!bn->tx_ring_map) - goto err_free_core; + goto err_free_tx_ring; if (bd->flags & BNGE_EN_SHARED_CHNL) j = 0; @@ -1289,42 +1289,64 @@ static int bnge_alloc_core(struct bnge_net *bn) rc = bnge_alloc_ring_stats(bn); if (rc) - goto err_free_core; + goto err_free_tx_ring_map; bnge_init_stats(bn); rc = bnge_alloc_vnics(bn); if (rc) - goto err_free_core; + goto err_free_ring_stats; rc = bnge_alloc_nq_arrays(bn); if (rc) - goto err_free_core; + goto err_free_vnics; bnge_init_ring_struct(bn); rc = bnge_alloc_rx_rings(bn); if (rc) - goto err_free_core; + goto err_free_nq_arrays; rc = bnge_alloc_tx_rings(bn); if (rc) - goto err_free_core; + goto err_free_rx_rings; rc = bnge_alloc_nq_tree(bn); if (rc) - goto err_free_core; + goto err_free_tx_rings; bn->vnic_info[BNGE_VNIC_DEFAULT].flags |= BNGE_VNIC_RSS_FLAG | BNGE_VNIC_MCAST_FLAG | BNGE_VNIC_UCAST_FLAG; rc = bnge_alloc_vnic_attributes(bn); if (rc) - goto err_free_core; + goto err_free_nq_tree; return 0; -err_free_core: - bnge_free_core(bn); +err_free_nq_tree: + bnge_free_nq_tree(bn); +err_free_tx_rings: + bnge_free_tx_rings(bn); +err_free_rx_rings: + bnge_free_rx_rings(bn); +err_free_nq_arrays: + bnge_free_nq_arrays(bn); +err_free_vnics: + bnge_free_vnics(bn); +err_free_ring_stats: + bnge_free_ring_stats(bn); +err_free_tx_ring_map: + kfree(bn->tx_ring_map); + bn->tx_ring_map = NULL; +err_free_tx_ring: + kfree(bn->tx_ring); + bn->tx_ring = NULL; +err_free_rx_ring: + kfree(bn->rx_ring); + bn->rx_ring = NULL; +err_free_bnapi: + kfree(bn->bnapi); + bn->bnapi = NULL; return rc; } From f94521b9d40782d7fd635a336df0d43cc3bd318e Mon Sep 17 00:00:00 2001 From: Bhargava Marreddy Date: Mon, 5 Oct 2026 17:47:02 +0530 Subject: [PATCH 1182/2126] bnge: require NQ vectors beyond aux reservation If exactly aux_msix vectors are granted, probe continues with zero NQ vectors. This leads to zero-sized allocations and out-of-bounds array accesses during ring setup. Require at least 'min' vectors beyond the aux reservation to ensure the driver always has an NQ vector to work with. Cc: stable+noautosel@kernel.org # fix to unlikely driver error path Fixes: 18a975389fcc ("bng_en: Add irq allocation support") Signed-off-by: Bhargava Marreddy Reviewed-by: Dharmender Garg Reviewed-by: Rajashekar Hudumula Reviewed-by: Ramakrishna Koduri Reviewed-by: Przemek Kitszel Link: https://patch.msgid.link/20261005121704.227866-3-bhargava.marreddy@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnge/bnge_resc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_resc.c b/drivers/net/ethernet/broadcom/bnge/bnge_resc.c index 4711dd4945ff..7c26943c5cb3 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_resc.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_resc.c @@ -382,7 +382,7 @@ int bnge_alloc_irqs(struct bnge_dev *bd) irqs_demand = pci_alloc_irq_vectors(bd->pdev, min, irqs_demand, PCI_IRQ_MSIX); aux_msix = bnge_aux_get_msix(bd); - if (irqs_demand < 0 || irqs_demand < aux_msix) { + if (irqs_demand < 0 || irqs_demand < aux_msix + min) { rc = -ENODEV; goto err_free_irqs; } From dc9a69f4d853cba5fb617e2960d9e80fdad59a50 Mon Sep 17 00:00:00 2001 From: Bhargava Marreddy Date: Mon, 5 Oct 2026 17:47:03 +0530 Subject: [PATCH 1183/2126] bnge: do not fail open if IRQ affinity hint fails IRQ affinity hints are advisory and not fatal to driver operations. On uniprocessor builds (CONFIG_SMP=n), irq_set_affinity_hint() always returns -EINVAL, which currently prevents ndo_open() from succeeding. Log a warning and continue instead of failing open on affinity error. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Signed-off-by: Bhargava Marreddy Reviewed-by: Dharmender Garg Reviewed-by: Rajashekar Hudumula Reviewed-by: Ramakrishna Koduri Reviewed-by: Przemek Kitszel Link: https://patch.msgid.link/20261005121704.227866-4-bhargava.marreddy@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnge/bnge_netdev.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c index bf101eded3bf..ca14d13fa3e9 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c @@ -2666,12 +2666,10 @@ static int bnge_request_irq(struct bnge_net *bn) irq->have_cpumask = 1; cpumask_set_cpu(cpumask_local_spread(i, numa_node), irq->cpu_mask); - rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask); - if (rc) { + if (irq_set_affinity_hint(irq->vector, irq->cpu_mask)) { netdev_warn(bn->netdev, "Set affinity failed, IRQ = %d\n", irq->vector); - goto err_free_irq; } } } From 21162b65d468eef20f5c5eca54188d44fbe53d8c Mon Sep 17 00:00:00 2001 From: Bhargava Marreddy Date: Mon, 5 Oct 2026 17:47:04 +0530 Subject: [PATCH 1184/2126] bnge: clear bd->netdev on allocation failure If bnge_netdev_alloc() fails after storing the net_device pointer in bd->netdev, it calls free_netdev() but leaves bd->netdev as a dangling pointer. Explicitly set bd->netdev to NULL on the error path to prevent potential use-after-free or invalid pointer dereferences. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: 13a68c1ed754 ("bng_en: Add a network device") Signed-off-by: Bhargava Marreddy Reviewed-by: Dharmender Garg Reviewed-by: Rajashekar Hudumula Reviewed-by: Ramakrishna Koduri Reviewed-by: Przemek Kitszel Link: https://patch.msgid.link/20261005121704.227866-5-bhargava.marreddy@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnge/bnge_netdev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c index ca14d13fa3e9..7dbe853a5a47 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c @@ -3551,6 +3551,7 @@ err_free_workq: destroy_workqueue(bn->bnge_pf_wq); err_netdev: free_netdev(netdev); + bd->netdev = NULL; return rc; } From ea311fea32363f331ec091e1287727ce972c7ddc Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Tue, 29 Sep 2026 13:34:00 -0700 Subject: [PATCH 1185/2126] net: bcmasp: fix lost TX wakeup race with lockless queue API netif_stop_queue() in bcmasp_xmit() raced with netif_wake_queue() in bcmasp_tx_poll(): a reclaim landing between the ring-full check and the stop call left the queue stopped despite free descriptors, hanging TX until timeout. Switch to netif_txq_maybe_stop()/netif_txq_completed_wake() (the lockless TX queue API, which also brings in BQL), replace tx_spb_ring_full() with a live bcmasp_tx_avail() count. This issue was discovered using LLM and is only theoretical. Tested on a BCM74110 that no regressions were encountered. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Signed-off-by: Justin Chen Reviewed-by: Nicolai Buchwitz Reviewed-by: Florian Fainelli Link: https://patch.msgid.link/20260929203400.1588868-1-justin.chen@broadcom.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/broadcom/asp2/bcmasp_intf.c | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index f2176ef3a127..3369c45b49d5 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -15,11 +15,15 @@ #include #include #include +#include #include #include "bcmasp.h" #include "bcmasp_intf_defs.h" +#define BCMASP_TX_STOP_THRS (MAX_SKB_FRAGS + 1) +#define BCMASP_TX_START_THRS (2 * MAX_SKB_FRAGS) + static int incr_ring(int index, int ring_count) { index++; @@ -143,19 +147,13 @@ static void bcmasp_clean_txcb(struct bcmasp_intf *intf, int index) txcb->last = false; } -static int tx_spb_ring_full(struct bcmasp_intf *intf, int cnt) +static int bcmasp_tx_avail(struct bcmasp_intf *intf) { - int next_index, i; + int used = (READ_ONCE(intf->tx_spb_index) - + READ_ONCE(intf->tx_spb_clean_index) + DESC_RING_COUNT) % + DESC_RING_COUNT; - /* Check if we have enough room for cnt descriptors */ - next_index = intf->tx_spb_index; - for (i = 0; i < cnt; i++) { - next_index = incr_ring(next_index, DESC_RING_COUNT); - if (next_index == intf->tx_spb_clean_index) - return 1; - } - - return 0; + return DESC_RING_COUNT - used - 1; } static struct sk_buff *bcmasp_csum_offload(struct net_device *dev, @@ -241,16 +239,19 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) struct bcmasp_tx_cb *txcb; dma_addr_t mapping, valid; struct bcmasp_desc *desc; + struct netdev_queue *txq; bool csum_hw = false; struct device *kdev; skb_frag_t *frag; kdev = &intf->parent->pdev->dev; + txq = netdev_get_tx_queue(dev, 0); nr_frags = skb_shinfo(skb)->nr_frags; - if (tx_spb_ring_full(intf, nr_frags + 1)) { - netif_stop_queue(dev); + if (unlikely(bcmasp_tx_avail(intf) < nr_frags + 1)) { + netif_txq_try_stop(txq, bcmasp_tx_avail(intf), + BCMASP_TX_START_THRS); if (net_ratelimit()) netdev_err(dev, "Tx Ring Full!\n"); return NETDEV_TX_BUSY; @@ -333,15 +334,17 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) */ wmb(); - intf->tx_spb_index = spb_index; + WRITE_ONCE(intf->tx_spb_index, spb_index); intf->tx_spb_dma_valid = valid; + netdev_tx_sent_queue(txq, total_bytes); + skb_tx_timestamp(skb); tx_spb_dma_wq(intf, intf->tx_spb_dma_valid, TX_SPB_DMA_VALID); - if (tx_spb_ring_full(intf, MAX_SKB_FRAGS + 1)) - netif_stop_queue(dev); + netif_txq_maybe_stop(txq, bcmasp_tx_avail(intf), + BCMASP_TX_STOP_THRS, BCMASP_TX_START_THRS); return NETDEV_TX_OK; } @@ -398,14 +401,16 @@ static void umac_enable_set(struct bcmasp_intf *intf, u32 mask, usleep_range(1000, 2000); } -static int bcmasp_tx_reclaim(struct bcmasp_intf *intf) +static int bcmasp_tx_reclaim(struct bcmasp_intf *intf, unsigned int *bytes_out) { struct bcmasp_intf_stats64 *stats = &intf->stats64; struct device *kdev = &intf->parent->pdev->dev; - unsigned long read, released = 0; + unsigned int bytes_compl = 0; struct bcmasp_tx_cb *txcb; struct bcmasp_desc *desc; + unsigned long read; dma_addr_t mapping; + int packets = 0; read = tx_spb_dma_rq(intf, TX_SPB_DMA_READ); while (intf->tx_spb_dma_read != read) { @@ -423,6 +428,9 @@ static int bcmasp_tx_reclaim(struct bcmasp_intf *intf) u64_stats_inc(&stats->tx_packets); u64_stats_add(&stats->tx_bytes, txcb->bytes_sent); u64_stats_update_end(&stats->syncp); + + bytes_compl += txcb->bytes_sent; + packets++; } desc = &intf->tx_spb_cpu[intf->tx_spb_clean_index]; @@ -433,33 +441,37 @@ static int bcmasp_tx_reclaim(struct bcmasp_intf *intf) intf->tx_spb_clean_index); bcmasp_clean_txcb(intf, intf->tx_spb_clean_index); - released++; - intf->tx_spb_clean_index = incr_ring(intf->tx_spb_clean_index, - DESC_RING_COUNT); + WRITE_ONCE(intf->tx_spb_clean_index, + incr_ring(intf->tx_spb_clean_index, DESC_RING_COUNT)); intf->tx_spb_dma_read = incr_first_byte(intf->tx_spb_dma_read, intf->tx_spb_dma_addr, DESC_RING_COUNT); } - return released; + if (bytes_out) + *bytes_out = bytes_compl; + + return packets; } static int bcmasp_tx_poll(struct napi_struct *napi, int budget) { struct bcmasp_intf *intf = container_of(napi, struct bcmasp_intf, tx_napi); - int released = 0; + struct netdev_queue *txq = netdev_get_tx_queue(intf->ndev, 0); + unsigned int bytes = 0; + int packets; - released = bcmasp_tx_reclaim(intf); + packets = bcmasp_tx_reclaim(intf, &bytes); + + netif_txq_completed_wake(txq, packets, bytes, + bcmasp_tx_avail(intf), BCMASP_TX_START_THRS); napi_complete(&intf->tx_napi); bcmasp_enable_tx_irq(intf, 1); - if (released) - netif_wake_queue(intf->ndev); - return 0; } @@ -847,6 +859,7 @@ static void bcmasp_init_tx(struct bcmasp_intf *intf) intf->tx_spb_index = 0; intf->tx_spb_clean_index = 0; memset(intf->tx_cbs, 0, sizeof(struct bcmasp_tx_cb) * DESC_RING_COUNT); + netdev_tx_reset_queue(netdev_get_tx_queue(intf->ndev, 0)); /* Make sure channels are disabled */ tx_spb_ctrl_wl(intf, 0x0, TX_SPB_CTRL_ENABLE); @@ -944,7 +957,7 @@ static void bcmasp_netif_deinit(struct net_device *dev, bool stop_phy) } while (timeout-- > 0); tx_spb_dma_wl(intf, 0x0, TX_SPB_DMA_FIFO_CTRL); - bcmasp_tx_reclaim(intf); + bcmasp_tx_reclaim(intf, NULL); umac_enable_set(intf, UMC_CMD_TX_EN, 0); From d065de29c919afac71e46a91a7449203ceb018ce Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Wed, 30 Sep 2026 20:48:17 +0800 Subject: [PATCH 1186/2126] pfcp: fix metadata_dst leak in pfcp_encap_recv() pfcp_encap_recv() allocates tun_dst with udp_tun_rx_dst() but only attaches it to the skb after iptunnel_pull_header() has succeeded. When iptunnel_pull_header() fails, the code jumps to the drop label, which frees the skb but not tun_dst, so the metadata_dst is leaked. iptunnel_pull_header() can fail for a GSO skb that is cloned, when skb_unclone() cannot allocate a new header with GFP_ATOMIC. The dst cannot simply be attached earlier, since skb_scrub_packet() in iptunnel_pull_header() drops it for cross-netns devices. Release it explicitly on the error paths instead. The !md check can never be true, but route it through the same label for consistency. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: 6dd514f48110 ("pfcp: always set pfcp metadata") Signed-off-by: Haishuang Yan Link: https://patch.msgid.link/20260930124818.114224-2-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- drivers/net/pfcp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/pfcp.c b/drivers/net/pfcp.c index 3ecd43cafdf0..68ad28dde40f 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -74,7 +74,7 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) md = ip_tunnel_info_opts(&tun_dst->u.tun_info); if (unlikely(!md)) - goto drop; + goto drop_dst; if (unparsed->flags & PFCP_SEID_FLAG) pfcp_session_recv(pfcp, skb, md); @@ -87,7 +87,7 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) if (unlikely(iptunnel_pull_header(skb, PFCP_HLEN, skb->protocol, !net_eq(sock_net(sk), dev_net(pfcp->dev))))) - goto drop; + goto drop_dst; skb_dst_set(skb, (struct dst_entry *)tun_dst); @@ -98,6 +98,8 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) gro_cells_receive(&pfcp->gro_cells, skb); return 0; +drop_dst: + dst_release(&tun_dst->dst); drop: kfree_skb(skb); return 0; From 7d3e5984d0fc10982812e893cee9ac44f761b2b3 Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Mon, 5 Oct 2026 13:18:22 -0700 Subject: [PATCH 1187/2126] net: devmem: remove net_iov_area base_virtual Since commit 083e64a3af77 ("net: devmem: replace gen_pool with freelist"), a binding has a single net_iov_area covering the whole dma-buf, and base_virtual is always 0. Its only reader is net_iov_virtual_addr(), where it adds nothing. io_uring zcrx never uses it. Drop the field and the store, and compute the dma-buf offset from the net_iov index alone. No functional change. From review feedback on: https://lore.kernel.org/netdev/asPUZ8DPllHd6Yu9@devvm7509.cco0.facebook.com/ Signed-off-by: Stanislav Fomichev Acked-by: Mina Almasry Link: https://patch.msgid.link/20261005201822.3060658-1-sdf@fomichev.me Signed-off-by: Jakub Kicinski --- include/net/netmem.h | 3 --- net/core/devmem.c | 1 - net/core/devmem.h | 3 +-- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/net/netmem.h b/include/net/netmem.h index cc97611632dc..0cc8572f62ca 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -102,9 +102,6 @@ struct net_iov_area { /* Array of net_iovs for this area. */ struct net_iov *niovs; size_t num_niovs; - - /* Offset into the dma-buf where this chunk starts. */ - unsigned long base_virtual; }; static inline struct net_iov_area *net_iov_owner(const struct net_iov *niov) diff --git a/net/core/devmem.c b/net/core/devmem.c index 71c83730d73d..07c62e2e3088 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -252,7 +252,6 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } - binding->area.base_virtual = 0; binding->area.num_niovs = dmabuf->size >> niov_shift; if (direction == DMA_TO_DEVICE) { binding->tx_vec = kvmalloc_objs(struct net_iov *, diff --git a/net/core/devmem.h b/net/core/devmem.h index 28d6fa7bcb57..1cec10f0257c 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -112,8 +112,7 @@ static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov); - return net_iov_owner(niov)->base_virtual + - ((unsigned long)net_iov_idx(niov) << binding->niov_shift); + return (unsigned long)net_iov_idx(niov) << binding->niov_shift; } static inline bool From 45ad84d2800e4a092fb8d96006a533b2d0ab13f6 Mon Sep 17 00:00:00 2001 From: Oleg Zadorozhnyi Date: Wed, 30 Sep 2026 23:37:16 +0000 Subject: [PATCH 1188/2126] dt-bindings: dpll: allow hex unit addresses on output pins The output-pins node matches its children against "^pin@[0-9]+$", while input-pins takes "^pin@[0-9a-f]+$". A unit address is the reg value in hex, so a device with more than ten outputs cannot describe the eleventh: dtc wants pin@a for reg = <10>, and the output pattern refuses it. Use the input pattern for the outputs as well. Signed-off-by: Oleg Zadorozhnyi Signed-off-by: Ali Rouhi Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260930233714.87679-2-arouhi@sitime.com Signed-off-by: Jakub Kicinski --- Documentation/devicetree/bindings/dpll/dpll-device.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/dpll/dpll-device.yaml b/Documentation/devicetree/bindings/dpll/dpll-device.yaml index fb8d7a9a3693..4b5184500b9f 100644 --- a/Documentation/devicetree/bindings/dpll/dpll-device.yaml +++ b/Documentation/devicetree/bindings/dpll/dpll-device.yaml @@ -65,7 +65,7 @@ properties: const: 0 patternProperties: - "^pin@[0-9]+$": + "^pin@[0-9a-f]+$": $ref: /schemas/dpll/dpll-pin.yaml unevaluatedProperties: false From 54b96109768276fa6dd0bad8e5701ad55643412a Mon Sep 17 00:00:00 2001 From: Samuele Yang Date: Tue, 29 Sep 2026 13:34:08 +1000 Subject: [PATCH 1189/2126] wifi: mm81x: start beaconing on beacon enable not interface add Currently we only initialise and start the beaconing process when the AP interface is first added. If the BSS alone is reconfigured and beaconing is temporarily stopped, the subsequent call to re-enable the beacon via BSS_CHANGED_BEACON_ENABLED is ignored and beaconing will be permanently stopped until the interface is completely re-added. To fix, move the beaconing start/stop to mm81x_mac_ops_bss_info_changed and react accordingly to info->enable_beacon and just keep the per-vif work item init in the add_interface callback. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Samuele Yang Link: https://patch.msgid.link/20260929033408.69266-1-samuele.yang@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 1a7382d27475..13b09d31d80b 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -1355,11 +1355,10 @@ static void mm81x_mac_beacon_work(struct work_struct *work) mm81x_mac_send_buffered_bc(mors, vif); } -static void mm81x_mac_beacon_init(struct mm81x_vif *mors_vif) +static void mm81x_mac_beacon_start(struct mm81x_vif *mors_vif) { struct mm81x *mors = mm81x_vif_to_mors(mors_vif); - INIT_WORK(&mors_vif->u.ap.beacon_work, mm81x_mac_beacon_work); mm81x_mac_beacon_irq_enable(mors_vif, true); atomic_inc(&mors->num_bcn_vifs); } @@ -1582,7 +1581,9 @@ static void mm81x_mac_ops_bss_info_changed(struct ieee80211_hw *hw, mm81x_cmd_config_beacon_timer(mors, mors_vif, info->enable_beacon); - if (!info->enable_beacon) + if (info->enable_beacon) + mm81x_mac_beacon_start(mors_vif); + else mm81x_mac_beacon_finish(mors_vif); } @@ -2260,7 +2261,7 @@ static int mm81x_mac_ops_add_interface(struct ieee80211_hw *hw, rcu_assign_pointer(mors->vifs[mors_vif->id], vif); if (vif->type == NL80211_IFTYPE_AP) - mm81x_mac_beacon_init(mors_vif); + INIT_WORK(&mors_vif->u.ap.beacon_work, mm81x_mac_beacon_work); ret = mm81x_cmd_get_capabilities(mors, mors_vif->id, &mors->fw_caps); if (ret) { From 356ed3640068cccb107373b5314edbea215d72c1 Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Fri, 25 Sep 2026 15:59:07 -0400 Subject: [PATCH 1190/2126] wifi: mm81x: switch to use fns() Replace the local nth_bit() helper with fns(), which provides the same zero-based set-bit selection for rate capability masks. Signed-off-by: Yury Norov Link: https://patch.msgid.link/20260925195908.252810-2-ynorov@nvidia.com [remove morsemicro prefix from commit message] Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mmrc.c | 26 +++++--------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mmrc.c b/drivers/net/wireless/morsemicro/mm81x/mmrc.c index fe7e4f501d6c..4cbc35535e07 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mmrc.c +++ b/drivers/net/wireless/morsemicro/mm81x/mmrc.c @@ -2,6 +2,8 @@ /* * Copyright (c) 2017-2026 Morse Micro */ +#include + #include "mmrc.h" /* @@ -198,22 +200,6 @@ */ static const u32 sym_table[10] = { 24, 36, 48, 72, 96, 144, 192, 216, 256, 288 }; -/* - * Calculate which bit is the nth bit set in an integer based flag. - */ -static u8 nth_bit(u16 in, u16 index) -{ - u32 i; - u8 count = 0; - - for (i = 0; count != index + 1; i++) { - if (((1u << i) & in) != 0) - count++; - } - - return i - 1; -} - /* * Calculate the input bit's index among all the set bits in an integer * based flag. @@ -291,19 +277,19 @@ static struct mmrc_rate get_rate_row(struct mmrc_table *tb, u16 index) u16 mcs_index = index / rows; u16 mcs_modulo = index % rows; - mcs = nth_bit(tb->caps.rates, mcs_index); + mcs = fns(tb->caps.rates, mcs_index); /* Find our spatial stream */ rows = rows / streams; - streams = nth_bit(tb->caps.spatial_streams, mcs_modulo / rows); + streams = fns(tb->caps.spatial_streams, mcs_modulo / rows); /* Find our bandwidth */ ss_index = index % rows; rows = rows / bw; - bw = nth_bit(tb->caps.bandwidth, ss_index / rows); + bw = fns(tb->caps.bandwidth, ss_index / rows); /* Find our guard */ - guard = nth_bit(tb->caps.guard, index % guard); + guard = fns(tb->caps.guard, index % guard); /* Add range checks to keep scan-build happy */ if (bw >= MMRC_BW_MAX) From da28021bc062d9c4dc6e885d6080aafd20359ed5 Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Fri, 25 Sep 2026 15:59:08 -0400 Subject: [PATCH 1191/2126] wifi: mm81x: use hweight16() to calculate bit index Count the set bits through bit_pos with hweight16() and an inclusive mask. Preserve the zero fallback and zero-based index. Signed-off-by: Yury Norov Link: https://patch.msgid.link/20260925195908.252810-3-ynorov@nvidia.com [remove morsemicro prefix from commit message] Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mmrc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mmrc.c b/drivers/net/wireless/morsemicro/mm81x/mmrc.c index 4cbc35535e07..6bedcdbcb61f 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mmrc.c +++ b/drivers/net/wireless/morsemicro/mm81x/mmrc.c @@ -206,13 +206,7 @@ static const u32 sym_table[10] = { 24, 36, 48, 72, 96, 144, 192, 216, 256, 288 } */ static u16 bit_index(u16 in, u32 bit_pos) { - u16 i; - u16 index = 0; - - for (i = 0; i != bit_pos + 1; i++) { - if (((1u << i) & in) != 0) - index++; - } + u16 index = hweight16(in & GENMASK(bit_pos, 0)); if (index == 0) { /* Could not match bit pos to caps */ From ad130fe516914076f3fb11940b1bf9181de04425 Mon Sep 17 00:00:00 2001 From: Aamir Ahmed Date: Fri, 11 Sep 2026 23:15:31 +0100 Subject: [PATCH 1192/2126] wifi: mm81x: validate n_channels in disabled channels response mm81x_mac_check_fw_disabled_chans() iterates over n_channels entries of the firmware response without validating the response length against the array size. A firmware response with n_channels larger than ARRAY_SIZE(mors_s1ghz_channels) reads past the end of the response buffer. To fix, make sure we validate the length prior to use. Assisted-by: LLM Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Aamir Ahmed Link: https://patch.msgid.link/AS8P251MB00015A3FFF9F9A9628CB0BB0C8BE2@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM [slightly reword commit message] Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 13b09d31d80b..383f420b37ec 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -282,6 +282,11 @@ static void mm81x_mac_check_fw_disabled_chans(struct ieee80211_hw *hw) if (ret) goto out; + if (le32_to_cpu(resp->n_channels) > ARRAY_SIZE(mors_s1ghz_channels)) { + ret = -EINVAL; + goto out; + } + for (i = 0; i < ARRAY_SIZE(mors_s1ghz_channels); i++) { struct ieee80211_channel *ch = &mors_s1ghz_channels[i]; From 64331a0ce58e3e4c9e604fe11c890275f6c3424a Mon Sep 17 00:00:00 2001 From: Chih-Kang Chang Date: Wed, 30 Sep 2026 14:45:19 +0800 Subject: [PATCH 1193/2126] wifi: rtw89: ps: send H2C command related to MLO info when FWIPS When entering FWIPS, also send the H2C command related to MLO info, the same as in LPS. Otherwise, the firmware cannot get enough information. Signed-off-by: Chih-Kang Chang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260930064524.39403-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/fw.h | 11 +++++++++++ drivers/net/wireless/realtek/rtw89/ps.c | 7 +------ drivers/net/wireless/realtek/rtw89/wow.c | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 9b616ec9323b..b879bdd94b88 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -5871,6 +5871,17 @@ int rtw89_chip_h2c_wow_cam_update(struct rtw89_dev *rtwdev, return chip->ops->h2c_wow_cam_update(rtwdev, cam_info); } +static inline void rtw89_fw_h2c_lps_ch_ml_info_routing(struct rtw89_dev *rtwdev, + struct rtw89_vif *rtwvif) +{ + if (RTW89_CHK_FW_FEATURE(LPS_CH_INFO, &rtwdev->fw)) + rtw89_fw_h2c_lps_ch_info(rtwdev, rtwvif); + else if (RTW89_CHK_FW_FEATURE(LPS_ML_INFO_V1, &rtwdev->fw)) + rtw89_fw_h2c_lps_ml_cmn_info_v1(rtwdev, rtwvif); + else + rtw89_fw_h2c_lps_ml_cmn_info(rtwdev, rtwvif); +} + /* Must consider compatibility; don't insert new in the mid. * Fill each field's default value in rtw89_regd_entcpy(). */ diff --git a/drivers/net/wireless/realtek/rtw89/ps.c b/drivers/net/wireless/realtek/rtw89/ps.c index 23a9c7a0704a..3639292eba7a 100644 --- a/drivers/net/wireless/realtek/rtw89/ps.c +++ b/drivers/net/wireless/realtek/rtw89/ps.c @@ -187,12 +187,7 @@ void rtw89_enter_lps(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif, rtw89_fw_h2c_rf_ps_info(rtwdev, rtwvif); - if (RTW89_CHK_FW_FEATURE(LPS_CH_INFO, &rtwdev->fw)) - rtw89_fw_h2c_lps_ch_info(rtwdev, rtwvif); - else if (RTW89_CHK_FW_FEATURE(LPS_ML_INFO_V1, &rtwdev->fw)) - rtw89_fw_h2c_lps_ml_cmn_info_v1(rtwdev, rtwvif); - else - rtw89_fw_h2c_lps_ml_cmn_info(rtwdev, rtwvif); + rtw89_fw_h2c_lps_ch_ml_info_routing(rtwdev, rtwvif); if (ps_mode && can_ps_mode) __rtw89_enter_ps_mode(rtwdev); diff --git a/drivers/net/wireless/realtek/rtw89/wow.c b/drivers/net/wireless/realtek/rtw89/wow.c index 7a2d6904951f..b9892ab84225 100644 --- a/drivers/net/wireless/realtek/rtw89/wow.c +++ b/drivers/net/wireless/realtek/rtw89/wow.c @@ -749,10 +749,12 @@ static void rtw89_wow_enter_ps(struct rtw89_dev *rtwdev) { struct rtw89_vif_link *rtwvif_link = rtwdev->wow.rtwvif_link; - if (rtw89_wow_mgd_linked(rtwdev)) + if (rtw89_wow_mgd_linked(rtwdev)) { rtw89_enter_lps(rtwdev, rtwvif_link->rtwvif, false); - else if (rtw89_wow_no_link(rtwdev)) + } else if (rtw89_wow_no_link(rtwdev)) { rtw89_fw_h2c_fwips(rtwdev, rtwvif_link, true); + rtw89_fw_h2c_lps_ch_ml_info_routing(rtwdev, rtwvif_link->rtwvif); + } } static void rtw89_wow_leave_ps(struct rtw89_dev *rtwdev, bool enable_wow) From 0fd2ed6a50740c0bfcda67fc51b5d5069125edd3 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 30 Sep 2026 14:45:20 +0800 Subject: [PATCH 1194/2126] wifi: rtw89: pci: fix typo of "deliver" The "diliver" should be "deliver", so fix them. (No logic is changed.) Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260930064524.39403-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/pci.c | 18 +++++++++--------- drivers/net/wireless/realtek/rtw89/pci.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c index 941fb5ca15b6..ddb27c7782a9 100644 --- a/drivers/net/wireless/realtek/rtw89/pci.c +++ b/drivers/net/wireless/realtek/rtw89/pci.c @@ -321,10 +321,10 @@ static u32 rtw89_pci_get_rx_skb_idx(struct rtw89_dev *rtwdev, static u32 rtw89_pci_rxbd_deliver_skbs(struct rtw89_dev *rtwdev, struct rtw89_pci_rx_ring *rx_ring) { - struct rtw89_rx_desc_info *desc_info = &rx_ring->diliver_desc; + struct rtw89_rx_desc_info *desc_info = &rx_ring->deliver_desc; struct rtw89_pci_dma_ring *bd_ring = &rx_ring->bd_ring; const struct rtw89_pci_info *info = rtwdev->pci_info; - struct sk_buff *new = rx_ring->diliver_skb; + struct sk_buff *new = rx_ring->deliver_skb; struct rtw89_pci_rx_info *rx_info; struct sk_buff *skb; u32 rxinfo_size = sizeof(struct rtw89_pci_rxbd_info); @@ -370,7 +370,7 @@ static u32 rtw89_pci_rxbd_deliver_skbs(struct rtw89_dev *rtwdev, if (!new) goto err_sync_device; - rx_ring->diliver_skb = new; + rx_ring->deliver_skb = new; /* first segment has RX desc */ offset = desc_info->offset + desc_info->rxd_len; @@ -392,7 +392,7 @@ static u32 rtw89_pci_rxbd_deliver_skbs(struct rtw89_dev *rtwdev, } if (ls) { rtw89_core_rx(rtwdev, desc_info, new); - rx_ring->diliver_skb = NULL; + rx_ring->deliver_skb = NULL; desc_info->ready = false; } @@ -404,7 +404,7 @@ err_sync_device: err_free_resource: if (new) dev_kfree_skb_any(new); - rx_ring->diliver_skb = NULL; + rx_ring->deliver_skb = NULL; desc_info->ready = false; return cnt; @@ -1840,8 +1840,8 @@ static void rtw89_pci_reset_trx_rings(struct rtw89_dev *rtwdev) else bd_ring->wp = 0; bd_ring->rp = 0; - rx_ring->diliver_skb = NULL; - rx_ring->diliver_desc.ready = false; + rx_ring->deliver_skb = NULL; + rx_ring->deliver_desc.ready = false; rx_ring->target_rx_tag = 0; if (info->group_bd_addr) { @@ -3719,8 +3719,8 @@ static int rtw89_pci_alloc_rx_ring(struct rtw89_dev *rtwdev, rx_ring->bd_ring.wp = 0; rx_ring->bd_ring.rp = 0; rx_ring->buf_sz = buf_sz; - rx_ring->diliver_skb = NULL; - rx_ring->diliver_desc.ready = false; + rx_ring->deliver_skb = NULL; + rx_ring->deliver_desc.ready = false; rx_ring->target_rx_tag = 0; for (i = 0; i < len; i++) { diff --git a/drivers/net/wireless/realtek/rtw89/pci.h b/drivers/net/wireless/realtek/rtw89/pci.h index cba52584ea68..0f9ea4bf54ea 100644 --- a/drivers/net/wireless/realtek/rtw89/pci.h +++ b/drivers/net/wireless/realtek/rtw89/pci.h @@ -1608,8 +1608,8 @@ struct rtw89_pci_rx_ring { struct rtw89_pci_dma_ring bd_ring; struct sk_buff *buf[RTW89_PCI_RXBD_NUM_MAX]; u32 buf_sz; - struct sk_buff *diliver_skb; - struct rtw89_rx_desc_info diliver_desc; + struct sk_buff *deliver_skb; + struct rtw89_rx_desc_info deliver_desc; u32 target_rx_tag:13; }; From 7a363850333529d67edabed0b98fe70e09f83cf9 Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 30 Sep 2026 14:45:21 +0800 Subject: [PATCH 1195/2126] wifi: rtw89: rx: refine skb/desc naming to improve readability In rx path, there are skb of Wi-Fi and skb of PPDU. However, skb_ppdu was used in some places for Wi-Fi skb. It was a bit confused. So, refine the naming as follow-up. Call skb for skb of Wi-Fi, and call skb_ppdu for skb of PPDU. Besides, call desc_ppdu for rx_desc_info of PPDU. (No logic is changed.) Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260930064524.39403-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 88 +++++++++++------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 2a1f54e9664a..0ae5aff8a122 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -1945,11 +1945,11 @@ void rtw89_core_fill_txdesc_fwcmd_v2(struct rtw89_dev *rtwdev, EXPORT_SYMBOL(rtw89_core_fill_txdesc_fwcmd_v2); static int rtw89_core_rx_process_mac_ppdu(struct rtw89_dev *rtwdev, - struct sk_buff *skb, + struct sk_buff *skb_ppdu, struct rtw89_rx_phy_ppdu *phy_ppdu) { const struct rtw89_chip_info *chip = rtwdev->chip; - const struct rtw89_rxinfo *rxinfo = (const struct rtw89_rxinfo *)skb->data; + const struct rtw89_rxinfo *rxinfo = (const struct rtw89_rxinfo *)skb_ppdu->data; const struct rtw89_rxinfo_user *user; enum rtw89_chip_gen chip_gen = rtwdev->chip->chip_gen; int rx_cnt_size = RTW89_PPDU_MAC_RX_CNT_SIZE; @@ -2003,7 +2003,7 @@ static int rtw89_core_rx_process_mac_ppdu(struct rtw89_dev *rtwdev, break; } - phy_sts = skb->data + RTW89_PPDU_MAC_INFO_SIZE; + phy_sts = skb_ppdu->data + RTW89_PPDU_MAC_INFO_SIZE; phy_sts += usr_num * RTW89_PPDU_MAC_INFO_USR_SIZE; /* 8-byte alignment */ if (usr_num & BIT(0)) @@ -2012,11 +2012,11 @@ static int rtw89_core_rx_process_mac_ppdu(struct rtw89_dev *rtwdev, phy_sts += rx_cnt_size; phy_sts += plcp_size; - if (phy_sts > skb->data + skb->len) + if (phy_sts > skb_ppdu->data + skb_ppdu->len) return -EINVAL; phy_ppdu->buf = phy_sts; - phy_ppdu->len = skb->data + skb->len - phy_sts; + phy_ppdu->len = skb_ppdu->data + skb_ppdu->len - phy_sts; return 0; } @@ -2443,16 +2443,16 @@ bool rtw89_check_rx_statu_gi_match(struct ieee80211_rx_status *status, u8 gi_ltf } static bool rtw89_core_rx_ppdu_match(struct rtw89_dev *rtwdev, - struct rtw89_rx_desc_info *desc_info, + struct rtw89_rx_desc_info *desc_ppdu, struct ieee80211_rx_status *status) { - u8 band = desc_info->bb_sel ? RTW89_PHY_1 : RTW89_PHY_0; + u8 band = desc_ppdu->bb_sel ? RTW89_PHY_1 : RTW89_PHY_0; u8 data_rate_mode, bw, rate_idx = MASKBYTE0, gi_ltf; bool eht = false; u16 data_rate; bool ret; - data_rate = desc_info->data_rate; + data_rate = desc_ppdu->data_rate; data_rate_mode = rtw89_get_data_rate_mode(rtwdev, data_rate); if (data_rate_mode == DATA_RATE_MODE_NON_HT) { rate_idx = rtw89_get_data_not_ht_idx(rtwdev, data_rate); @@ -2468,9 +2468,9 @@ static bool rtw89_core_rx_ppdu_match(struct rtw89_dev *rtwdev, } eht = data_rate_mode == DATA_RATE_MODE_EHT; - bw = rtw89_hw_to_rate_info_bw(desc_info->bw); - gi_ltf = rtw89_rxdesc_to_nl_he_eht_gi(rtwdev, desc_info->gi_ltf, false, eht); - ret = rtwdev->ppdu_sts.curr_rx_ppdu_cnt[band] == desc_info->ppdu_cnt && + bw = rtw89_hw_to_rate_info_bw(desc_ppdu->bw); + gi_ltf = rtw89_rxdesc_to_nl_he_eht_gi(rtwdev, desc_ppdu->gi_ltf, false, eht); + ret = rtwdev->ppdu_sts.curr_rx_ppdu_cnt[band] == desc_ppdu->ppdu_cnt && status->rate_idx == rate_idx && rtw89_check_rx_statu_gi_match(status, gi_ltf, eht) && status->bw == bw; @@ -4005,7 +4005,7 @@ static bool rtw89_core_skb_pn_valid(struct rtw89_dev *rtwdev, static void rtw89_core_rx_to_mac80211(struct rtw89_dev *rtwdev, struct rtw89_rx_phy_ppdu *phy_ppdu, struct rtw89_rx_desc_info *desc_info, - struct sk_buff *skb_ppdu, + struct sk_buff *skb, struct ieee80211_rx_status *rx_status) { struct napi_struct *napi = &rtwdev->napi; @@ -4015,57 +4015,57 @@ static void rtw89_core_rx_to_mac80211(struct rtw89_dev *rtwdev, napi = NULL; rtw89_core_hw_to_sband_rate(rx_status); - rtw89_core_rx_stats(rtwdev, phy_ppdu, desc_info, skb_ppdu); + rtw89_core_rx_stats(rtwdev, phy_ppdu, desc_info, skb); rtw89_core_update_rx_status_by_ppdu(rtwdev, rx_status, phy_ppdu); - rtw89_core_update_radiotap(rtwdev, desc_info, skb_ppdu, rx_status, phy_ppdu); + rtw89_core_update_radiotap(rtwdev, desc_info, skb, rx_status, phy_ppdu); rtw89_core_validate_rx_signal(rx_status); - rtw89_core_update_rx_freq_from_ie(rtwdev, skb_ppdu, rx_status); + rtw89_core_update_rx_freq_from_ie(rtwdev, skb, rx_status); rtw89_core_correct_mcc_chan(rtwdev, desc_info, rx_status, phy_ppdu); /* In low power mode, it does RX in thread context. */ local_bh_disable(); - ieee80211_rx_napi(rtwdev->hw, NULL, skb_ppdu, napi); + ieee80211_rx_napi(rtwdev->hw, NULL, skb, napi); local_bh_enable(); rtwdev->napi_budget_countdown--; } static void rtw89_core_rx_pending_skb(struct rtw89_dev *rtwdev, struct rtw89_rx_phy_ppdu *phy_ppdu, - struct rtw89_rx_desc_info *desc_info, - struct sk_buff *skb) + struct rtw89_rx_desc_info *desc_ppdu, + struct sk_buff *skb_ppdu) { - u8 band = desc_info->bb_sel ? RTW89_PHY_1 : RTW89_PHY_0; + u8 band = desc_ppdu->bb_sel ? RTW89_PHY_1 : RTW89_PHY_0; int curr = rtwdev->ppdu_sts.curr_rx_ppdu_cnt[band]; - struct sk_buff *skb_ppdu = NULL, *tmp; + struct sk_buff *skb = NULL, *tmp; struct ieee80211_rx_status *rx_status; if (curr > RTW89_MAX_PPDU_CNT) return; - skb_queue_walk_safe(&rtwdev->ppdu_sts.rx_queue[band], skb_ppdu, tmp) { - skb_unlink(skb_ppdu, &rtwdev->ppdu_sts.rx_queue[band]); - rx_status = IEEE80211_SKB_RXCB(skb_ppdu); - if (rtw89_core_rx_ppdu_match(rtwdev, desc_info, rx_status)) + skb_queue_walk_safe(&rtwdev->ppdu_sts.rx_queue[band], skb, tmp) { + skb_unlink(skb, &rtwdev->ppdu_sts.rx_queue[band]); + rx_status = IEEE80211_SKB_RXCB(skb); + if (rtw89_core_rx_ppdu_match(rtwdev, desc_ppdu, rx_status)) rtw89_chip_query_ppdu(rtwdev, phy_ppdu, rx_status); rtw89_correct_cck_chan(rtwdev, rx_status); - rtw89_core_rx_to_mac80211(rtwdev, phy_ppdu, desc_info, skb_ppdu, rx_status); + rtw89_core_rx_to_mac80211(rtwdev, phy_ppdu, desc_ppdu, skb, rx_status); } } static void rtw89_core_rx_process_ppdu_sts(struct rtw89_dev *rtwdev, - struct rtw89_rx_desc_info *desc_info, - struct sk_buff *skb) + struct rtw89_rx_desc_info *desc_ppdu, + struct sk_buff *skb_ppdu) { - struct rtw89_rx_phy_ppdu phy_ppdu = {.buf = skb->data, .valid = false, - .len = skb->len, - .to_self = desc_info->addr1_match, - .rate = desc_info->data_rate, - .mac_id = desc_info->mac_id, - .phy_idx = desc_info->bb_sel}; + struct rtw89_rx_phy_ppdu phy_ppdu = {.buf = skb_ppdu->data, .valid = false, + .len = skb_ppdu->len, + .to_self = desc_ppdu->addr1_match, + .rate = desc_ppdu->data_rate, + .mac_id = desc_ppdu->mac_id, + .phy_idx = desc_ppdu->bb_sel}; int ret; - if (desc_info->mac_info_valid) { - ret = rtw89_core_rx_process_mac_ppdu(rtwdev, skb, &phy_ppdu); + if (desc_ppdu->mac_info_valid) { + ret = rtw89_core_rx_process_mac_ppdu(rtwdev, skb_ppdu, &phy_ppdu); if (ret) goto out; } @@ -4077,8 +4077,8 @@ static void rtw89_core_rx_process_ppdu_sts(struct rtw89_dev *rtwdev, rtw89_core_rx_process_phy_sts(rtwdev, &phy_ppdu); out: - rtw89_core_rx_pending_skb(rtwdev, &phy_ppdu, desc_info, skb); - dev_kfree_skb_any(skb); + rtw89_core_rx_pending_skb(rtwdev, &phy_ppdu, desc_ppdu, skb_ppdu); + dev_kfree_skb_any(skb_ppdu); } static void rtw89_core_rx_process_report(struct rtw89_dev *rtwdev, @@ -4476,24 +4476,24 @@ static void rtw89_core_flush_ppdu_rx_queue(struct rtw89_dev *rtwdev, struct rtw89_ppdu_sts_info *ppdu_sts = &rtwdev->ppdu_sts; u8 band = desc_info->bb_sel ? RTW89_PHY_1 : RTW89_PHY_0; struct ieee80211_rx_status *rx_status; - struct sk_buff *skb_ppdu, *tmp; + struct sk_buff *skb, *tmp; - skb_queue_walk_safe(&ppdu_sts->rx_queue[band], skb_ppdu, tmp) { - skb_unlink(skb_ppdu, &ppdu_sts->rx_queue[band]); - rx_status = IEEE80211_SKB_RXCB(skb_ppdu); - rtw89_core_rx_to_mac80211(rtwdev, NULL, desc_info, skb_ppdu, rx_status); + skb_queue_walk_safe(&ppdu_sts->rx_queue[band], skb, tmp) { + skb_unlink(skb, &ppdu_sts->rx_queue[band]); + rx_status = IEEE80211_SKB_RXCB(skb); + rtw89_core_rx_to_mac80211(rtwdev, NULL, desc_info, skb, rx_status); } } static void rtw89_core_rx_pkt_hdl(struct rtw89_dev *rtwdev, const struct sk_buff *skb, - const struct rtw89_rx_desc_info *desc) + const struct rtw89_rx_desc_info *desc_info) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct rtw89_sta_link *rtwsta_link; struct ieee80211_sta *sta; struct rtw89_sta *rtwsta; - u8 macid = desc->mac_id; + u8 macid = desc_info->mac_id; if (!refcount_read(&rtwdev->refcount_ap_info)) return; From 2995f5234ab2e363d7c114af66895c510c14fefe Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 30 Sep 2026 14:45:22 +0800 Subject: [PATCH 1196/2126] wifi: rtw89: rx: no need to cancel 6 GHz probe per vif To cancel some 6 GHz probe cases, it just depends on if a skb matches some corresponding conditions. Because the decision has nothing to do with vif, it's redundant to do the cancellation per vif, i.e., single case will be cancelled multiple times. So, move it out of iteration. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260930064524.39403-5-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 0ae5aff8a122..8b9f9a4574f7 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -3080,11 +3080,6 @@ static void rtw89_vif_rx_stats_iter(void *data, u8 *mac, struct rtw89_bb_ctx *bb; const u8 *target_bssid; - if (rtwdev->scanning && - (ieee80211_is_beacon(hdr->frame_control) || - ieee80211_is_probe_resp(hdr->frame_control))) - rtw89_core_cancel_6ghz_probe_tx(rtwdev, skb); - rcu_read_lock(); rtwvif_link = rtw89_vif_get_link_inst(rtwvif, desc_info->bb_sel); @@ -3168,8 +3163,14 @@ static void rtw89_core_rx_stats(struct rtw89_dev *rtwdev, struct rtw89_rx_desc_info *desc_info, struct sk_buff *skb) { + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct rtw89_vif_rx_stats_iter_data iter_data; + if (rtwdev->scanning && + (ieee80211_is_beacon(hdr->frame_control) || + ieee80211_is_probe_resp(hdr->frame_control))) + rtw89_core_cancel_6ghz_probe_tx(rtwdev, skb); + rtw89_traffic_stats_accu(rtwdev, NULL, skb, true, false); iter_data.rtwdev = rtwdev; From a4d288b5200a3d06d320331108224b63bea6b7bc Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Wed, 30 Sep 2026 14:45:23 +0800 Subject: [PATCH 1197/2126] wifi: rtw89: phy: write full data for BB gain table type 15 Type 15 gain-table records now encode the FEM index in bits 31:16 and the gain-table version in bits 15:0. Signed-off-by: Eric Huang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260930064524.39403-6-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/phy_be.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/phy_be.c b/drivers/net/wireless/realtek/rtw89/phy_be.c index b94754d38673..73c98ae358ad 100644 --- a/drivers/net/wireless/realtek/rtw89/phy_be.c +++ b/drivers/net/wireless/realtek/rtw89/phy_be.c @@ -434,7 +434,7 @@ static void rtw89_phy_config_bb_gain_be(struct rtw89_dev *rtwdev, rtw89_phy_cfg_bb_gain_op1db_be(rtwdev, arg, reg->data); break; case 15: - rtw89_phy_write32_idx(rtwdev, reg->addr & 0xFFFFF, MASKHWORD, + rtw89_phy_write32_idx(rtwdev, reg->addr & 0xFFFFF, MASKDWORD, reg->data, RTW89_PHY_0); break; case 4: From 11a7351f30b98c1ab6ecc9d7f474f82823208931 Mon Sep 17 00:00:00 2001 From: Johnson Tsai Date: Wed, 30 Sep 2026 14:45:24 +0800 Subject: [PATCH 1198/2126] wifi: rtw89: pack I/O during RF nctl init to reduce execution time Wrap the register writes of rtw89_phy_init_rf_nctl() with rtw89_io_pack/unpack so they are batched into single bus transactions, reducing API execution time. 8852C USB2.0 AMD B450 initialization time: rtw89_phy_init_rf_nctl 5355 ms -> 10 ms Signed-off-by: Johnson Tsai Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20260930064524.39403-7-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/phy.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index 074865665b16..795920b899d9 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -2071,7 +2071,10 @@ static void rtw89_phy_init_rf_nctl(struct rtw89_dev *rtwdev) rtw89_phy_preinit_rf_nctl(rtwdev); nctl_table = elm_info->rf_nctl ? elm_info->rf_nctl : chip->nctl_table; + + rtw89_io_pack(rtwdev); rtw89_phy_init_reg(rtwdev, nctl_table, false, rtw89_phy_config_bb_reg, NULL); + rtw89_io_unpack(rtwdev); if (chip->nctl_post_table) rtw89_rfk_parser(rtwdev, chip->nctl_post_table); From 54a54c06868d0c2beb9ec3e2ffda0f6cb33d5c8e Mon Sep 17 00:00:00 2001 From: Muhammad Bilal Date: Sun, 20 Sep 2026 00:22:31 +0500 Subject: [PATCH 1199/2126] wifi: mm81x: check bytes_remaining before reading delimiter mm81x_yaps_hw_read_pkts() reads a full 4-byte delimiter and then subtracts sizeof(delim) from bytes_remaining on every loop iteration, guarded only by "bytes_remaining > 0". If 1-3 bytes are left in the window, this reads past the end of the valid data and then subtracts 4 from a value smaller than 4, driving bytes_remaining negative. A negative bytes_remaining then reaches the total_len > bytes_remaining branch, where "bytes_remaining" is passed to memcpy() as the copy length. Implicitly converted to size_t, a negative int becomes a huge value, turning that memcpy() into a massive out-of-bounds copy. Bail out of the split loop once fewer than sizeof(delim) bytes remain, the same way the existing "end of stream" check bails on a zero delimiter. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Muhammad Bilal Link: https://patch.msgid.link/20260919192231.272078-1-meatuni001@gmail.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/yaps_hw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c b/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c index 3d641d23c35b..e1102b8fb802 100644 --- a/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c +++ b/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c @@ -486,6 +486,9 @@ static int mm81x_yaps_hw_read_pkts(struct mm81x_yaps *yaps, int total_len; int pkt_size; + if (bytes_remaining < (int)sizeof(delim)) + break; + delim = le32_to_cpu(*((__le32 *)read_ptr)); read_ptr += sizeof(delim); bytes_remaining -= sizeof(delim); From 5a4847b554e8581ab93898a55b59ae8b5b1c7a51 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Fri, 2 Oct 2026 14:50:58 +0800 Subject: [PATCH 1200/2126] wifi: rtw89: remove discouraged imply from Kconfig LED The 'imply' in Kconfig to weakly and implicitly select dependencies is discouraged. Remove them to simply logic. Reported-by: Arnd Bergmann Closes: https://lore.kernel.org/linux-wireless/7cdc36a9-aadd-4636-8a29-847d89638c8d@app.fastmail.com/T/#t Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261002065058.13535-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/Kconfig | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/Kconfig b/drivers/net/wireless/realtek/rtw89/Kconfig index 9c6c16af7f35..0899f0c25612 100644 --- a/drivers/net/wireless/realtek/rtw89/Kconfig +++ b/drivers/net/wireless/realtek/rtw89/Kconfig @@ -209,14 +209,12 @@ config RTW89_LEDS bool depends on RTW89_CORE depends on LEDS_CLASS=y || LEDS_CLASS=MAC80211 - imply MAC80211_LEDS default y config RTW89_LEDS_MC bool depends on RTW89_LEDS depends on LEDS_CLASS_MULTICOLOR=y || LEDS_CLASS_MULTICOLOR=RTW89_CORE - imply LEDS_TRIGGER_TIMER default y endif From bf4c84e72fbd1e65918863145297c508225c1202 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:06 +0800 Subject: [PATCH 1201/2126] wifi: rtw89: coex: fix RF band check in _set_rf_trx_para() and its propagation dm->tdd_bind.rf_band holds a bitmask built from BIT(BTC_BT_B2G) and BIT(BTC_BT_B5G), but _set_rf_trx_para() compared it against the raw band enum values RTW89_BAND_5G and RTW89_BAND_2G instead of their BIT() form. Every other site in this file that reads tdd_bind.rf_band wraps the enum with BIT() before comparing. Because RTW89_BAND_5G equals 1 and BIT(BTC_BT_B2G) also equals 1, a Wi-Fi/Bluetooth coexistence session bound to the 2.4 GHz band was misclassified as BTC_WLINK_V0_5G. This incorrectly skipped the RF Tx/Rx parameter adjustment for 2.4 GHz STA traffic and kept clearing wl_stb_chg to 0, so chip->ops->btc_wl_s1_standby() never re-enabled the Wi-Fi standby workaround for the Bluetooth Tx-to-Rx GNT switch on RTL8852C, degrading Wi-Fi performance while coexisting with Bluetooth on 2.4 GHz. Compare rf_band against BIT(RTW89_BAND_5G) and BIT(RTW89_BAND_2G) to match its actual bitmask representation. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 6b72e2c80d14..271b002a2d40 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -4186,10 +4186,10 @@ static void _set_bt_tx_power(struct rtw89_dev *rtwdev, bool force_exec, u8 bid, buf[1] = rf_band; /* bit-map: bit1->5GHz/6Ghz, bit0->2.4GHz */ if (!force_exec && !btc->cli_h2c_cmd) { - if (rf_band == RTW89_BAND_2G && + if (rf_band == BIT(RTW89_BAND_2G) && bt->tx_power_now == level) continue; - else if (rf_band != RTW89_BAND_2G && + else if (rf_band != BIT(RTW89_BAND_2G) && bt->tx_power_now_6g == level) continue; } @@ -4199,7 +4199,7 @@ static void _set_bt_tx_power(struct rtw89_dev *rtwdev, bool force_exec, u8 bid, if (!_send_fw_cmd(rtwdev, BTFC_SET, h2c_func, buf, len)) { btc->dm.rf_trx_para.bt_tx_power[i] = level; - if (rf_band == RTW89_BAND_2G) + if (rf_band == BIT(RTW89_BAND_2G)) bt->tx_power_now = level; else bt->tx_power_now_6g = level; @@ -4240,7 +4240,7 @@ static void _set_bt_rx_gain(struct rtw89_dev *rtwdev, bool force_exec, u8 bid, id_stop = bid; } - if (rf_band == RTW89_BAND_2G) + if (rf_band == BIT(RTW89_BAND_2G)) scbd_bit |= BTC_WSCB_RXGAIN; else scbd_bit |= BTC_WSCB_RXGAIN_56G; @@ -4256,10 +4256,10 @@ static void _set_bt_rx_gain(struct rtw89_dev *rtwdev, bool force_exec, u8 bid, /* return if same setup */ if (!force_exec && !btc->cli_h2c_cmd) { - if (rf_band == RTW89_BAND_2G && + if (rf_band == BIT(RTW89_BAND_2G) && bt->lna_constrain == level) continue; - else if (rf_band != RTW89_BAND_2G && + else if (rf_band != BIT(RTW89_BAND_2G) && bt->lna_constrain_6g == level) continue; } @@ -4400,9 +4400,9 @@ static void _set_rf_trx_para(struct rtw89_dev *rtwdev) if (bmode == BTC_WLINK_NOLINK) { return; - } else if (rf_band == RTW89_BAND_5G) { + } else if (rf_band == BIT(RTW89_BAND_5G)) { mode = BTC_WLINK_V0_5G; - } else if (rf_band == RTW89_BAND_2G && bmode == BTC_WLINK_STA) { + } else if (rf_band == BIT(RTW89_BAND_2G) && bmode == BTC_WLINK_STA) { mode = BTC_WLINK_V0_2G_STA; } From fd4d5551eae1e9864def396995b2cae328e9c424 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:07 +0800 Subject: [PATCH 1202/2126] wifi: rtw89: coex: track per-HW-band WL role fields with arrays The role info fields that distinguish HW-band 0 from HW-band 1 were kept as separate scalar members with a "_hb1" suffix for the second band, which forced every caller to branch on hw_band and duplicate the same logic for each member. Convert link_mode, p2p_exist and role_map in the role info, plus is_5g_hi_ch, go_client_exist, noa_exist and bg_mode in the WL info, into RTW89_MAC_NUM-indexed arrays so a single hw_band index addresses both bands. This lets _update_wl_link_mode(), _update_wl_mlo_info(), _modify_role_link_mode() and _update_wl_info() drop their hw_band == RTW89_PHY_1 branches in favor of direct array indexing, and removes the duplicated per-band assignments at every call site. The firmware-facing H2C formats are unchanged; only the internal representation moved from named pairs to an array. Add v11 of the role info H2C structure and its sender so a later firmware version bump has a destination to send to. And it should not sharing layout with the existing v10 structure. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 138 ++++++++++------------ drivers/net/wireless/realtek/rtw89/core.h | 38 +++--- drivers/net/wireless/realtek/rtw89/fw.c | 113 +++++++++++++++--- drivers/net/wireless/realtek/rtw89/fw.h | 6 + 4 files changed, 186 insertions(+), 109 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 271b002a2d40..8412c082ddc8 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -3793,6 +3793,8 @@ static void _fw_set_drv_info(struct rtw89_dev *rtwdev, u8 index) rtw89_fw_h2c_cxdrv_role_v8(rtwdev, index); else if (ver->fwlrole == 10) rtw89_fw_h2c_cxdrv_role_v10(rtwdev, index); + else if (ver->fwlrole == 11) + rtw89_fw_h2c_cxdrv_role_v11(rtwdev, index); break; case CXDRVINFO_CTRL: if (ver->drvinfo_ver != 0) @@ -5244,7 +5246,7 @@ void rtw89_btc_set_policy(struct rtw89_dev *rtwdev, u16 policy_type) case BTC_CXP_PFIX: /* PS-TDMA Fix-Slot */ tdma_on = true; *t = t_def[CXTD_PFIX]; - if (btc->cx.wl.role_info.role_map & BIT(RTW89_WIFI_ROLE_AP)) + if (btc->cx.wl.role_info.role_map[RTW89_MAC_0] & BIT(RTW89_WIFI_ROLE_AP)) _tdma_set_flctrl(btc, CXFLC_QOSNULL); switch (policy_type) { @@ -5449,7 +5451,7 @@ void rtw89_btc_set_policy_v1(struct rtw89_dev *rtwdev, u16 policy_type) tbl_b1 = cxtbl[17]; tbl_b4 = cxtbl[17]; - if (wl->bg_mode) + if (wl->bg_mode[RTW89_MAC_0]) tbl_w1 = cxtbl[8]; else if ((wl->status.map.traffic_dir & BIT(RTW89_TFC_UL)) && hid->exist) @@ -5925,7 +5927,7 @@ static void _set_ant(struct rtw89_dev *rtwdev, bool force_exec, dm->run_reason == BTC_RSN_CMD_SET_COEX) force_exec = FC_EXEC; - if (wl_rinfo->link_mode != BTC_WLINK_DB_MCC && + if (wl_rinfo->link_mode[RTW89_MAC_0] != BTC_WLINK_DB_MCC && btc->dm.wl_btg_rx == 2) force_exec = FC_EXEC; @@ -6141,7 +6143,7 @@ static void _action_bt_hfp(struct rtw89_dev *rtwdev) _set_policy(rtwdev, BTC_CXP_OFF_BWB1, BTC_ACT_BT_HFP); } } else { - if (wl->bg_mode) + if (wl->bg_mode[RTW89_MAC_0]) _set_policy(rtwdev, BTC_CXP_OFF_BWB1, BTC_ACT_BT_HFP); else if (wl->status.map.traffic_dir & BIT(RTW89_TFC_UL)) _set_policy(rtwdev, BTC_CXP_OFF_EQ5, BTC_ACT_BT_HFP); @@ -6179,7 +6181,7 @@ static void _action_bt_hid(struct rtw89_dev *rtwdev) policy_type = BTC_CXP_OFF_BWB1; } } else { /* dedicated-antenna */ - if (wl->bg_mode) + if (wl->bg_mode[RTW89_MAC_0]) policy_type = BTC_CXP_OFF_BWB1; else if (wl->status.map.traffic_dir & BIT(RTW89_TFC_UL)) policy_type = BTC_CXP_OFF_EQ4; @@ -6520,7 +6522,7 @@ static void _set_btg_ctrl(struct rtw89_dev *rtwdev) /* bb call ctrl_btg() in WL FW by slot */ if (!btc->ver->fcxosi && - wl_rinfo->link_mode == BTC_WLINK_DB_MCC) + wl_rinfo->link_mode[RTW89_MAC_0] == BTC_WLINK_DB_MCC) is_btg = BTC_BTGCTRL_BB_GNT_FWCTRL; } @@ -6580,7 +6582,7 @@ static void _set_wl_preagc_ctrl(struct rtw89_dev *rtwdev) is_preagc = BTC_PREAGC_DISABLE; } else if (dm->tdd_bind.rf_band == BIT(RTW89_BAND_5G)) { is_preagc = BTC_PREAGC_DISABLE; - } else if (rinfo->link_mode == BTC_WLINK_NOLINK || + } else if (rinfo->link_mode[RTW89_MAC_0] == BTC_WLINK_NOLINK || btc->cx.bt0.link_info.link_cnt.now == 0) { is_preagc = BTC_PREAGC_DISABLE; } else if (dm->tdma_now.type != CXTDMA_OFF && @@ -6596,7 +6598,7 @@ static void _set_wl_preagc_ctrl(struct rtw89_dev *rtwdev) is_preagc = BTC_PREAGC_ENABLE; } - if (!btc->ver->fcxosi && rinfo->link_mode == BTC_WLINK_DB_MCC) + if (!btc->ver->fcxosi && rinfo->link_mode[RTW89_MAC_0] == BTC_WLINK_DB_MCC) is_preagc = BTC_PREAGC_BB_FWCTRL; if (dm->wl_pre_agc_rb != dm->wl_pre_agc && @@ -6743,7 +6745,7 @@ static void _set_wl_tx_limit(struct rtw89_dev *rtwdev) if (btc->dm.freerun || btc->ctrl.igno_bt || b->link_cnt.now == 0 || dm->tdd_bind.rf_band == BIT(RTW89_BAND_5G) || - wl_rinfo->link_mode == BTC_WLINK_NOLINK) { + wl_rinfo->link_mode[RTW89_MAC_0] == BTC_WLINK_NOLINK) { enable = 0; tx_time = BTC_MAX_TX_TIME_DEF; tx_retry = BTC_MAX_TX_RETRY_DEF; @@ -6852,7 +6854,7 @@ static void _set_bt_rx_agc(struct rtw89_dev *rtwdev) struct rtw89_btc_bt_info *bt = &btc->cx.bt0; bool bt_hi_lna_rx = false; - if (wl_rinfo->link_mode != BTC_WLINK_NOLINK && btc->dm.wl_btg_rx) + if (wl_rinfo->link_mode[RTW89_MAC_0] != BTC_WLINK_NOLINK && btc->dm.wl_btg_rx) bt_hi_lna_rx = true; if (bt_hi_lna_rx == bt->hi_lna_rx) @@ -6903,7 +6905,7 @@ static void _update_zb_coex_tbl(struct rtw89_dev *rtwdev) struct rtw89_btc *btc = &rtwdev->btc; u32 zb_tbl0 = 0xda5a5a5a, zb_tbl1 = 0xda5a5a5a; u8 link_mode_chg = btc->cx.wl.link_mode_chg; - u8 mode = btc->cx.wl.role_info.link_mode; + u8 mode = btc->cx.wl.role_info.link_mode[RTW89_MAC_0]; if (btc->dm.run_reason != BTC_RSN_NTFY_INIT && !link_mode_chg) return; @@ -7501,46 +7503,43 @@ static void _update_wl_link_mode(struct rtw89_dev *rtwdev, u8 hw_band, u8 type) struct rtw89_btc_wl_info *wl = &btc->cx.wl; struct rtw89_btc_wl_mlo_info *mlo_info = &wl->mlo_info; struct rtw89_btc_wl_role_info *r = &wl->role_info; - u8 p2p_exist = wl->role_info.p2p_exist; - - if (hw_band == RTW89_PHY_1) - p2p_exist = wl->role_info.p2p_exist_hb1; + u8 p2p_exist = wl->role_info.p2p_exist[hw_band]; /* MLD: nLmR --> 2L1R: 2-Link by 1-RF, 2L2R: 2-link by 2-RF */ switch (type) { case RTW89_MR_WTYPE_NONE: /* no-link */ - r->link_mode = BTC_WLINK_NOLINK; + r->link_mode[hw_band] = BTC_WLINK_NOLINK; break; case RTW89_MR_WTYPE_NONMLD: /* Non_MLO 1-role 2+0/0+2 */ case RTW89_MR_WTYPE_MLD1L1R: /* MLO only-1 link 2+0/0+2 */ if (mlo_info->wmode[hw_band] == RTW89_MR_WMODE_1AP) { - r->link_mode = BTC_WLINK_GO; + r->link_mode[hw_band] = BTC_WLINK_GO; } else if (mlo_info->wmode[hw_band] == RTW89_MR_WMODE_1CLIENT && p2p_exist) { - r->link_mode = BTC_WLINK_GC; + r->link_mode[hw_band] = BTC_WLINK_GC; } else { - r->link_mode = BTC_WLINK_STA; + r->link_mode[hw_band] = BTC_WLINK_STA; } break; case RTW89_MR_WTYPE_NONMLD_NONMLD: /* Non_MLO 2-role 2+0/0+2 */ case RTW89_MR_WTYPE_MLD1L1R_NONMLD: /* MLO only-1 link + P2P 2+0/0+2 */ if (mlo_info->ch_type[hw_band] == RTW89_MR_CTX2_2GHZ_5GHZ || mlo_info->ch_type[hw_band] == RTW89_MR_CTX2_2GHZ_6GHZ) { - r->link_mode = BTC_WLINK_DB_MCC; + r->link_mode[hw_band] = BTC_WLINK_DB_MCC; } else if (mlo_info->ch_type[hw_band] == RTW89_MR_CTX2_2GHZ || mlo_info->ch_type[hw_band] == RTW89_MR_CTX2_5GHZ || mlo_info->ch_type[hw_band] == RTW89_MR_CTX2_6GHZ || mlo_info->ch_type[hw_band] == RTW89_MR_CTX2_5GHZ_6GHZ) { - r->link_mode = BTC_WLINK_SB_MCC; + r->link_mode[hw_band] = BTC_WLINK_SB_MCC; } else { - r->link_mode = BTC_WLINK_SCC; + r->link_mode[hw_band] = BTC_WLINK_SCC; } break; case RTW89_MR_WTYPE_MLD2L1R: /* MLO_MLSR 2+0/0+2 */ if (p2p_exist) /* MLO_MLSR only support STA/GC */ - r->link_mode = BTC_WLINK_GC; + r->link_mode[hw_band] = BTC_WLINK_GC; else - r->link_mode = BTC_WLINK_STA; + r->link_mode[hw_band] = BTC_WLINK_STA; break; case RTW89_MR_WTYPE_MLD2L1R_NONMLD: /* MLO_MLSR + P2P 2+0/0+2 */ case RTW89_MR_WTYPE_MLD2L2R_NONMLD: /* MLO_MLMR + P2P 1+1/2+2*/ @@ -7548,11 +7547,11 @@ static void _update_wl_link_mode(struct rtw89_dev *rtwdev, u8 hw_band, u8 type) * 2G+5G -> TDMA slot switch by E2G/E5G * 5G only -> TDMA slot switch by E5G */ - r->link_mode = BTC_WLINK_DB_MCC; + r->link_mode[hw_band] = BTC_WLINK_DB_MCC; break; case RTW89_MR_WTYPE_MLD2L2R: /* MLO_MLMR 1+1/2+2 */ /* MLMR only support STA now (2024) */ - r->link_mode = BTC_WLINK_STA; + r->link_mode[hw_band] = BTC_WLINK_STA; break; } } @@ -7647,7 +7646,7 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) case MLO_2_PLUS_0_1RF: /* 2+0 */ case MLO_2_PLUS_0_2RF: _update_wl_link_mode(rtwdev, RTW89_MAC_0, type); - wl_rinfo->link_mode_hb1 = wl_rinfo->link_mode; + wl_rinfo->link_mode[RTW89_MAC_1] = wl_rinfo->link_mode[RTW89_MAC_0]; wl_rinfo->pta_req_band = RTW89_MAC_0; wl_rinfo->dbcc_2g_phy = RTW89_PHY_0; wl_rinfo->dbcc_en = 0; @@ -7659,7 +7658,7 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) case MLO_0_PLUS_2_1RF: /* 0+2 */ case MLO_0_PLUS_2_2RF: _update_wl_link_mode(rtwdev, RTW89_MAC_1, type); - wl_rinfo->link_mode_hb1 = wl_rinfo->link_mode; + wl_rinfo->link_mode[RTW89_MAC_0] = wl_rinfo->link_mode[RTW89_MAC_1]; wl_rinfo->pta_req_band = RTW89_MAC_1; wl_rinfo->dbcc_2g_phy = RTW89_PHY_1; wl_rinfo->dbcc_en = 0; @@ -7686,7 +7685,6 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) if (hw_band == RTW89_MAC_0) { mlo_info->path_rf_band[BTC_RF_S0] = rf_band; } else { - wl_rinfo->link_mode_hb1 = wl_rinfo->link_mode; mlo_info->path_rf_band[BTC_RF_S1] = rf_band; } @@ -7706,8 +7704,10 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) break; } - rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s(), mode=%s, pta_band=%d", - __func__, id_to_linkmode(wl_rinfo->link_mode), + rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s(), link_mode(HWB0=%s/HWB1=%s), pta_band=%d", + __func__, + id_to_linkmode(wl_rinfo->link_mode[RTW89_MAC_0]), + id_to_linkmode(wl_rinfo->link_mode[RTW89_MAC_1]), wl_rinfo->pta_req_band); } @@ -7780,8 +7780,8 @@ static void _update_wl_non_mlo_info(struct rtw89_dev *rtwdev) mode = _get_role_link_mode(cid_role[0]); } - wl_rinfo->link_mode = mode; - wl_rinfo->link_mode_hb1 = mode; + wl_rinfo->link_mode[RTW89_MAC_0] = mode; + wl_rinfo->link_mode[RTW89_MAC_1] = mode; } static void _sync_wl_link_mode_v0(struct rtw89_dev *rtwdev) @@ -7796,12 +7796,12 @@ static void _sync_wl_link_mode_v0(struct rtw89_dev *rtwdev) r->rlink[i][j].rf_band == RTW89_BAND_2G) has_2g = true; - if (!has_2g && r->link_mode != BTC_WLINK_NOLINK) { + if (!has_2g && r->link_mode[RTW89_MAC_0] != BTC_WLINK_NOLINK) { r->link_mode_v0 = BTC_WLINK_V0_5G; return; } - switch (r->link_mode) { + switch (r->link_mode[RTW89_MAC_0]) { case BTC_WLINK_NOLINK: r->link_mode_v0 = BTC_WLINK_V0_NOLINK; break; @@ -7837,18 +7837,12 @@ static void _modify_role_link_mode(struct rtw89_dev *rtwdev, u8 hw_band) struct rtw89_btc *btc = &rtwdev->btc; struct rtw89_btc_wl_info *wl = &btc->cx.wl; struct rtw89_btc_wl_role_info *wl_rinfo = &wl->role_info; - u8 go_cleint_exist = wl->go_client_exist; - u8 *link_mode = &wl_rinfo->link_mode; - u32 role_map = wl_rinfo->role_map; - u8 noa_exist = wl->noa_exist; + u8 go_cleint_exist = wl->go_client_exist[hw_band]; + u8 *link_mode = &wl_rinfo->link_mode[hw_band]; + u32 role_map = wl_rinfo->role_map[hw_band]; + u8 noa_exist = wl->noa_exist[hw_band]; u32 mrole = BTC_WLMROLE_NONE; - if (hw_band == RTW89_PHY_1) { - *link_mode = wl_rinfo->link_mode_hb1; - role_map = wl_rinfo->role_map_hb1; - go_cleint_exist = wl->go_client_exist_hb1; - } - /* if no client_joined, don't care P2P-GO/AP role */ if (((role_map & BIT(RTW89_WIFI_ROLE_P2P_GO)) || (role_map & BIT(RTW89_WIFI_ROLE_AP))) && !go_cleint_exist) { @@ -7892,7 +7886,7 @@ static void _modify_role_link_mode(struct rtw89_dev *rtwdev, u8 hw_band) rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s(): link_mode=%s, mrole_type=%d\n", __func__, - id_to_linkmode(wl_rinfo->link_mode), wl_rinfo->mrole_type); + id_to_linkmode(*link_mode), wl_rinfo->mrole_type); } static void _update_wl_info(struct rtw89_dev *rtwdev, struct rtw89_btc_wl_link_info *wl_linfo) @@ -7981,23 +7975,13 @@ static void _update_wl_info(struct rtw89_dev *rtwdev, struct rtw89_btc_wl_link_i bg_mode = 1; } - if (rlink_id == RTW89_PHY_0) { - link_mode_ori = wl_rinfo->link_mode; - wl->is_5g_hi_ch = is_5g_hi_ch; - wl->bg_mode = bg_mode; - wl->go_client_exist = go_client_exist; - wl->noa_exist = noa_exist; - wl_rinfo->p2p_exist = p2p_exist; - wl_rinfo->role_map = role_map; - } else { - link_mode_ori = wl_rinfo->link_mode_hb1; - wl->is_5g_hi_ch_hb1 = is_5g_hi_ch; - wl->bg_mode_hb1 = bg_mode; - wl->go_client_exist_hb1 = go_client_exist; - wl->noa_exist_hb1 = noa_exist; - wl_rinfo->p2p_exist_hb1 = p2p_exist; - wl_rinfo->role_map_hb1 = role_map; - } + link_mode_ori = wl_rinfo->link_mode[rlink_id]; + wl->is_5g_hi_ch[rlink_id] = is_5g_hi_ch; + wl->bg_mode[rlink_id] = bg_mode; + wl->go_client_exist[rlink_id] = go_client_exist; + wl->noa_exist[rlink_id] = noa_exist; + wl_rinfo->p2p_exist[rlink_id] = p2p_exist; + wl_rinfo->role_map[rlink_id] = role_map; dbcc_en_ori = wl_rinfo->dbcc_en; @@ -8011,8 +7995,7 @@ static void _update_wl_info(struct rtw89_dev *rtwdev, struct rtw89_btc_wl_link_i _modify_role_link_mode(rtwdev, rlink_id); _sync_wl_link_mode_v0(rtwdev); - if ((rlink_id == RTW89_PHY_0 && wl_rinfo->link_mode != link_mode_ori) || - (rlink_id == RTW89_PHY_1 && wl_rinfo->link_mode_hb1 != link_mode_ori)) { + if (wl_rinfo->link_mode[rlink_id] != link_mode_ori) { wl_rinfo->link_mode_chg = 1; wl->link_mode_chg = 1; } @@ -8487,7 +8470,7 @@ static void _set_bind_info(struct rtw89_btc *btc, u8 type) * HW-Band is decided by wl->mlo_info.mrcx_act_hwb_map */ if (wl->mlo_info.wtype == RTW89_MR_WTYPE_MLD2L1R_NONMLD) { - if (wl->role_info.link_mode != BTC_WLINK_DB_MCC) { /* mode chg */ + if (wl->role_info.link_mode[RTW89_MAC_0] != BTC_WLINK_DB_MCC) { /* mode chg */ if (wl->mlo_info.mrcx_act_hwb_map == BIT(RTW89_MAC_1)) path_hwb[BTC_RF_S0] = RTW89_PHY_1; /* S0/1->HWB1 */ else @@ -8527,19 +8510,19 @@ static void _set_bind_info(struct rtw89_btc *btc, u8 type) if (wl->mlo_info.wtype == RTW89_MR_WTYPE_MLD2L2R && (bd->wl_hwb_sel == (BIT(RTW89_MAC_1) | BIT(RTW89_MAC_0)))) { - if (wl->role_info.link_mode == BTC_WLINK_AP || - wl->role_info.link_mode_hb1 == BTC_WLINK_AP) + if (wl->role_info.link_mode[RTW89_MAC_0] == BTC_WLINK_AP || + wl->role_info.link_mode[RTW89_MAC_1] == BTC_WLINK_AP) bd->wl_link_mode = BTC_WLINK_DB_MCC; else bd->wl_link_mode = BTC_WLINK_STA; - bd->wl_bg_mode = wl->bg_mode | wl->bg_mode_hb1; + bd->wl_bg_mode = wl->bg_mode[RTW89_MAC_0] | wl->bg_mode[RTW89_MAC_1]; } else if (bd->wl_hwb_sel == (BIT(RTW89_MAC_1))) { - bd->wl_link_mode = wl->role_info.link_mode_hb1; - bd->wl_bg_mode = wl->bg_mode_hb1; + bd->wl_link_mode = wl->role_info.link_mode[RTW89_MAC_1]; + bd->wl_bg_mode = wl->bg_mode[RTW89_MAC_1]; } else {/* HW-BAND-0 or no-hw-band */ bd->wl_hwb_sel = BIT(RTW89_MAC_0); - bd->wl_link_mode = wl->role_info.link_mode; - bd->wl_bg_mode = wl->bg_mode; + bd->wl_link_mode = wl->role_info.link_mode[RTW89_MAC_0]; + bd->wl_bg_mode = wl->bg_mode[RTW89_MAC_0]; } /* update Bind-BT status map for BT0/BT1 */ @@ -8657,7 +8640,7 @@ static void _set_coex_binding(struct rtw89_btc *btc) * In this case, BTC_RF_S0->HWB0, BTC_RF_S1->HWB1 */ if (wl->mlo_info.wtype == RTW89_MR_WTYPE_MLD2L1R_NONMLD) { - if (wl->role_info.link_mode != BTC_WLINK_DB_MCC) {/* mode chg */ + if (wl->role_info.link_mode[RTW89_MAC_0] != BTC_WLINK_DB_MCC) {/* mode chg */ if (wl->mlo_info.mrcx_act_hwb_map == BIT(RTW89_PHY_1)) path_hwb[BTC_RF_S0] = RTW89_PHY_1;/* S0/1->HWB1 */ else @@ -10317,10 +10300,11 @@ static int _show_wl_info(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) p += scnprintf(p, end - p, "========== [WL Status] ==========\n"); - mode = wl_rinfo->link_mode; + mode = wl_rinfo->link_mode[RTW89_MAC_0]; - p += scnprintf(p, end - p, " %-15s : link_mode:%s, ", "[status]", - id_to_linkmode(mode)); + p += scnprintf(p, end - p, " %-15s : link_mode:%s(HWB0)/%s(HWB1), ", "[status]", + id_to_linkmode(mode), + id_to_linkmode(wl_rinfo->link_mode[RTW89_MAC_1])); p += scnprintf(p, end - p, "rf_off:%d, power_save:%d, scan:%s(band:%d/phy_map:0x%x), ", diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 7e74b5c9ed49..d66a1febb85c 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -2055,6 +2055,23 @@ struct rtw89_btc_wl_role_info_v10 { /* H2C info, struct size must be n*4 bytes * __le32 mrole_type; /* btc_wl_mrole_type: [31:16]:band1, [15:0]:band0 */ } __packed; +struct rtw89_btc_wl_role_info_v11 { /* H2C info, struct size must be n*4 bytes */ + struct rtw89_btc_wl_rlink_v10 rlink[RTW89_BE_BTC_WL_MAX_ROLE_NUMBER][RTW89_MAC_NUM]; + u8 link_mode; + u8 link_mode_hb1; + u8 p2p_exist; + u8 p2p_exist_hb1; + + u8 pta_req_band; + u8 dbcc_en; /* 1+1 and 2.4G-included */ + u8 dbcc_2g_phy; /* which phy operate in 2G, HW_PHY_0 or HW_PHY_1 */ + u8 rsvd; + + __le32 role_map; + __le32 role_map_hb1; + __le32 mrole_type; /* btc_wl_mrole_type: [31:16]:band1, [15:0]:band0 */ +} __packed; + struct rtw89_btc_wl_rlink { /* Logic dynamic using */ u8 connected; u8 pid; @@ -2089,18 +2106,15 @@ struct rtw89_btc_wl_rlink { /* Logic dynamic using */ struct rtw89_btc_wl_role_info { /* Logic dynamic using */ struct rtw89_btc_wl_rlink rlink[RTW89_BE_BTC_WL_MAX_ROLE_NUMBER][RTW89_MAC_NUM]; - u8 link_mode; - u8 link_mode_hb1; - u8 p2p_exist; - u8 p2p_exist_hb1; + u8 link_mode[RTW89_MAC_NUM]; + u8 p2p_exist[RTW89_MAC_NUM]; u8 pta_req_band; u8 dbcc_en; /* 1+1 and 2.4G-included */ u8 dbcc_2g_phy; /* which phy operate in 2G, HW_PHY_0 or HW_PHY_1 */ u8 rsvd; - u32 role_map; - u32 role_map_hb1; + u32 role_map[RTW89_MAC_NUM]; u32 mrole_type; /* btc_wl_mrole_type: [31:16]:band1, [15:0]:band0 */ /* Before v10 use this linkmode */ @@ -2397,15 +2411,11 @@ struct rtw89_btc_wl_info { u8 ch_map[12]; u8 ch_map_le[5]; - bool is_5g_hi_ch; - bool is_5g_hi_ch_hb1; - bool go_client_exist; - bool go_client_exist_hb1; - bool noa_exist; - bool noa_exist_hb1; + bool is_5g_hi_ch[RTW89_MAC_NUM]; + bool go_client_exist[RTW89_MAC_NUM]; + bool noa_exist[RTW89_MAC_NUM]; bool pta_reg_mac_chg; - bool bg_mode; - bool bg_mode_hb1; + bool bg_mode[RTW89_MAC_NUM]; bool he_mode; bool scbd_chg[BTC_ALL_BT]; bool fw_ver_mismatch; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 4ac2fd117b95..886d7c32d2ef 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -6456,7 +6456,7 @@ int rtw89_fw_h2c_cxdrv_role(struct rtw89_dev *rtwdev, u8 type) const struct rtw89_btc_ver *ver = btc->ver; struct rtw89_btc_wl_rlink *rl; struct sk_buff *skb; - u32 rmap = r->role_map; + u32 rmap = r->role_map[RTW89_MAC_0]; u8 offset = 0; u32 len; u8 *cmd; @@ -6477,7 +6477,7 @@ int rtw89_fw_h2c_cxdrv_role(struct rtw89_dev *rtwdev, u8 type) RTW89_SET_FWCMD_CXHDR_LEN(cmd, len - H2C_LEN_CXDRVHDR); RTW89_SET_FWCMD_CXROLE_CONNECT_CNT(cmd, r->connect_cnt); - RTW89_SET_FWCMD_CXROLE_LINK_MODE(cmd, r->link_mode); + RTW89_SET_FWCMD_CXROLE_LINK_MODE(cmd, r->link_mode[RTW89_MAC_0]); RTW89_SET_FWCMD_CXROLE_ROLE_NONE(cmd, !!(rmap & BIT(RTW89_WIFI_ROLE_NONE))); RTW89_SET_FWCMD_CXROLE_ROLE_STA(cmd, !!(rmap & BIT(RTW89_WIFI_ROLE_STATION))); @@ -6538,7 +6538,7 @@ int rtw89_fw_h2c_cxdrv_role_v1(struct rtw89_dev *rtwdev, u8 type) struct rtw89_btc_wl_role_info *r = &wl->role_info; struct rtw89_btc_wl_rlink *rl; struct sk_buff *skb; - u32 rmap = r->role_map; + u32 rmap = r->role_map[RTW89_MAC_0]; u8 *cmd, offset; u32 len; int ret; @@ -6558,7 +6558,7 @@ int rtw89_fw_h2c_cxdrv_role_v1(struct rtw89_dev *rtwdev, u8 type) RTW89_SET_FWCMD_CXHDR_LEN(cmd, len - H2C_LEN_CXDRVHDR); RTW89_SET_FWCMD_CXROLE_CONNECT_CNT(cmd, r->connect_cnt); - RTW89_SET_FWCMD_CXROLE_LINK_MODE(cmd, r->link_mode); + RTW89_SET_FWCMD_CXROLE_LINK_MODE(cmd, r->link_mode[RTW89_MAC_0]); RTW89_SET_FWCMD_CXROLE_ROLE_NONE(cmd, !!(rmap & BIT(RTW89_WIFI_ROLE_NONE))); RTW89_SET_FWCMD_CXROLE_ROLE_STA(cmd, !!(rmap & BIT(RTW89_WIFI_ROLE_STATION))); @@ -6643,8 +6643,8 @@ int rtw89_fw_h2c_cxdrv_role_v101(struct rtw89_dev *rtwdev, u8 type) h2c->hdr.len = len - H2C_LEN_CXDRVHDR; h2c->connect_cnt = role_info->connect_cnt; - h2c->link_mode = role_info->link_mode; - h2c->role_map = cpu_to_le16(role_info->role_map); + h2c->link_mode = role_info->link_mode[RTW89_MAC_0]; + h2c->role_map = cpu_to_le16(role_info->role_map[RTW89_MAC_0]); for (i = 0; i < RTW89_PORT_NUM; i++) { active = &role_info->rlink[i][0]; @@ -6712,7 +6712,7 @@ int rtw89_fw_h2c_cxdrv_role_v2(struct rtw89_dev *rtwdev, u8 type) struct rtw89_btc_wl_role_info *r = &wl->role_info; struct rtw89_btc_wl_rlink *rl; struct sk_buff *skb; - u32 rmap = r->role_map; + u32 rmap = r->role_map[RTW89_MAC_0]; u32 len; u8 *cmd, offset; int ret; @@ -6732,7 +6732,7 @@ int rtw89_fw_h2c_cxdrv_role_v2(struct rtw89_dev *rtwdev, u8 type) RTW89_SET_FWCMD_CXHDR_LEN(cmd, len - H2C_LEN_CXDRVHDR); RTW89_SET_FWCMD_CXROLE_CONNECT_CNT(cmd, r->connect_cnt); - RTW89_SET_FWCMD_CXROLE_LINK_MODE(cmd, r->link_mode); + RTW89_SET_FWCMD_CXROLE_LINK_MODE(cmd, r->link_mode[RTW89_MAC_0]); RTW89_SET_FWCMD_CXROLE_ROLE_NONE(cmd, !!(rmap & BIT(RTW89_WIFI_ROLE_NONE))); RTW89_SET_FWCMD_CXROLE_ROLE_STA(cmd, !!(rmap & BIT(RTW89_WIFI_ROLE_STATION))); @@ -6813,7 +6813,7 @@ int rtw89_fw_h2c_cxdrv_role_v7(struct rtw89_dev *rtwdev, u8 type) h2c->hdr.len = len - H2C_LEN_CXDRVHDR_V7; h2c->r.connect_cnt = r->connect_cnt; - h2c->r.link_mode = r->link_mode; + h2c->r.link_mode = r->link_mode[RTW89_MAC_0]; h2c->r.link_mode_chg = r->link_mode_chg; h2c->r.p2p_2g = r->p2p_2g; @@ -6834,7 +6834,7 @@ int rtw89_fw_h2c_cxdrv_role_v7(struct rtw89_dev *rtwdev, u8 type) h2c->r.active_role[i].client_cnt = rl->client_cnt; } - rm = cpu_to_le32(r->role_map); + rm = cpu_to_le32(r->role_map[RTW89_MAC_0]); memcpy(&h2c->r.role_map, &rm, sizeof(h2c->r.role_map)); h2c->r.mrole_type = cpu_to_le32(r->mrole_type); h2c->r.mrole_noa_duration = cpu_to_le32(r->mrole_noa_duration); @@ -6883,7 +6883,7 @@ int rtw89_fw_h2c_cxdrv_role_v8(struct rtw89_dev *rtwdev, u8 type) h2c->hdr.ver = 8; h2c->hdr.len = len - H2C_LEN_CXDRVHDR_V7; h2c->r.connect_cnt = r->connect_cnt; - h2c->r.link_mode = r->link_mode; + h2c->r.link_mode = r->link_mode[RTW89_MAC_0]; h2c->r.link_mode_chg = r->link_mode_chg; h2c->r.p2p_2g = r->p2p_2g; h2c->r.pta_req_band = r->pta_req_band; @@ -6911,7 +6911,7 @@ int rtw89_fw_h2c_cxdrv_role_v8(struct rtw89_dev *rtwdev, u8 type) } } - rm = cpu_to_le32(r->role_map); + rm = cpu_to_le32(r->role_map[RTW89_MAC_0]); memcpy(&h2c->r.role_map, &rm, sizeof(h2c->r.role_map)); h2c->r.mrole_type = cpu_to_le32(r->mrole_type); h2c->r.mrole_noa_duration = cpu_to_le32(r->mrole_noa_duration); @@ -6978,18 +6978,95 @@ int rtw89_fw_h2c_cxdrv_role_v10(struct rtw89_dev *rtwdev, u8 type) } } - h2c->r.link_mode = r->link_mode; - h2c->r.link_mode_hb1 = r->link_mode_hb1; - h2c->r.p2p_exist = r->p2p_exist; - h2c->r.p2p_exist_hb1 = r->p2p_exist_hb1; + h2c->r.link_mode = r->link_mode[RTW89_MAC_0]; + h2c->r.link_mode_hb1 = r->link_mode[RTW89_MAC_1]; + h2c->r.p2p_exist = r->p2p_exist[RTW89_MAC_0]; + h2c->r.p2p_exist_hb1 = r->p2p_exist[RTW89_MAC_1]; h2c->r.pta_req_band = r->pta_req_band; h2c->r.dbcc_en = r->dbcc_en; h2c->r.dbcc_2g_phy = r->dbcc_2g_phy; - rm = cpu_to_le32(r->role_map); + rm = cpu_to_le32(r->role_map[RTW89_MAC_0]); memcpy(&h2c->r.role_map, &rm, sizeof(h2c->r.role_map)); - rm = cpu_to_le32(r->role_map_hb1); + rm = cpu_to_le32(r->role_map[RTW89_MAC_1]); + memcpy(&h2c->r.role_map_hb1, &rm, sizeof(h2c->r.role_map_hb1)); + h2c->r.mrole_type = cpu_to_le32(r->mrole_type); + + rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, + H2C_CAT_OUTSRC, BTFC_SET, + SET_DRV_INFO, 0, 0, + len); + + ret = rtw89_h2c_tx(rtwdev, skb, false); + if (ret) { + rtw89_err(rtwdev, "failed to send h2c\n"); + goto fail; + } + + return 0; +fail: + dev_kfree_skb_any(skb); + + return ret; +} + +int rtw89_fw_h2c_cxdrv_role_v11(struct rtw89_dev *rtwdev, u8 type) +{ + struct rtw89_btc_wl_role_info *r = &rtwdev->btc.cx.wl.role_info; + struct rtw89_h2c_cxrole_v11 *h2c; + struct rtw89_btc_wl_rlink *rl; + u32 len = sizeof(*h2c); + struct sk_buff *skb; + __le32 rm; + int ret; + u8 i, j; + + skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); + if (!skb) { + rtw89_err(rtwdev, "failed to alloc skb for h2c cxdrv_role\n"); + return -ENOMEM; + } + skb_put(skb, len); + h2c = (struct rtw89_h2c_cxrole_v11 *)skb->data; + + h2c->hdr.type = type; + h2c->hdr.ver = 11; + h2c->hdr.len = len - H2C_LEN_CXDRVHDR_V7; + + for (j = RTW89_MAC_0; j <= RTW89_MAC_1; j++) { + for (i = 0; i < RTW89_BE_BTC_WL_MAX_ROLE_NUMBER; i++) { + rl = &r->rlink[i][j]; + h2c->r.rlink[i][j].connected = rl->connected; + h2c->r.rlink[i][j].pid = rl->pid; + h2c->r.rlink[i][j].phy = rl->phy; + h2c->r.rlink[i][j].noa = rl->noa; + + h2c->r.rlink[i][j].rf_band = rl->rf_band; + h2c->r.rlink[i][j].active = rl->active; + h2c->r.rlink[i][j].bw = rl->bw; + h2c->r.rlink[i][j].role = rl->role; + + h2c->r.rlink[i][j].ch = rl->ch; + h2c->r.rlink[i][j].noa_dur = rl->noa_dur; + h2c->r.rlink[i][j].client_cnt = rl->client_cnt; + h2c->r.rlink[i][j].mode = rl->mode; + h2c->r.rlink[i][j].mac_id = rl->mac_id; + } + } + + h2c->r.link_mode = r->link_mode[RTW89_MAC_0]; + h2c->r.link_mode_hb1 = r->link_mode[RTW89_MAC_1]; + h2c->r.p2p_exist = r->p2p_exist[RTW89_MAC_0]; + h2c->r.p2p_exist_hb1 = r->p2p_exist[RTW89_MAC_1]; + + h2c->r.pta_req_band = r->pta_req_band; + h2c->r.dbcc_en = r->dbcc_en; + h2c->r.dbcc_2g_phy = r->dbcc_2g_phy; + + rm = cpu_to_le32(r->role_map[RTW89_MAC_0]); + memcpy(&h2c->r.role_map, &rm, sizeof(h2c->r.role_map)); + rm = cpu_to_le32(r->role_map[RTW89_MAC_1]); memcpy(&h2c->r.role_map_hb1, &rm, sizeof(h2c->r.role_map_hb1)); h2c->r.mrole_type = cpu_to_le32(r->mrole_type); diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index b879bdd94b88..5afdae3b1e79 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -2507,6 +2507,11 @@ struct rtw89_h2c_cxrole_v10 { struct rtw89_btc_wl_role_info_v10 r; } __packed; +struct rtw89_h2c_cxrole_v11 { + struct rtw89_h2c_cxhdr_v7 hdr; + struct rtw89_btc_wl_role_info_v11 r; +} __packed; + struct rtw89_h2c_cxmlo_v2 { struct rtw89_h2c_cxhdr_v7 hdr; struct rtw89_btc_wl_mlo_info_v2 mlo; @@ -5545,6 +5550,7 @@ int rtw89_fw_h2c_cxdrv_role_v2(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_role_v7(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_role_v8(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_role_v10(struct rtw89_dev *rtwdev, u8 type); +int rtw89_fw_h2c_cxdrv_role_v11(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_init_v11(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_mlo_v2(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_osi_info(struct rtw89_dev *rtwdev, u8 type); From fbe6912f19807b2e482d5aad1b3f59d72f2d27a1 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:08 +0800 Subject: [PATCH 1203/2126] wifi: rtw89: coex: show per-HW-band MLO state in WL status dump The WL status debug dump only printed role, channel and link-mode state for HW-band 0, even on chips where MLO support means both bands carry an independent connection. Add an [MLO] line that prints the operating mode, channel type, RF band and P2P-exist state for each HW-band side by side, gated on the chip actually supporting MLO so single-band chips keep the shorter dump. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 8412c082ddc8..556c35e84043 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -10292,6 +10292,7 @@ static int _show_wl_info(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) struct rtw89_btc_cx *cx = &btc->cx; struct rtw89_btc_wl_info *wl = &cx->wl; struct rtw89_btc_wl_role_info *wl_rinfo = &wl->role_info; + struct rtw89_btc_wl_mlo_info *wl_minfo = &wl->mlo_info; char *p = buf, *end = buf + bufsz; u8 mode; @@ -10319,6 +10320,25 @@ static int _show_wl_info(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) wl->status.map._4way ? "Y" : "N", wl->status.map.init_ok ? "Y" : "N"); + if (rtwdev->chip->para_ver & BTC_FEAT_MLO_SUPPORT) { + p += scnprintf(p, end - p, + " %-15s : type:%d/rf_comb:%d/dbcc_en:%d, ", + "[MLO]", wl_minfo->wtype, wl_minfo->rf_combination, + wl_rinfo->dbcc_en); + p += scnprintf(p, end - p, + "HWB0(wmode:%d/ch:%d/rf_band:%d/p2p:%d), ", + wl_minfo->wmode[RTW89_MAC_0], + wl_minfo->ch_type[RTW89_MAC_0], + wl_minfo->hwb_rf_band[RTW89_MAC_0], + wl_rinfo->p2p_exist[RTW89_MAC_0]); + p += scnprintf(p, end - p, + "HWB1(wmode:%d/ch:%d/rf_band:%d/p2p:%d)\n", + wl_minfo->wmode[RTW89_MAC_1], + wl_minfo->ch_type[RTW89_MAC_1], + wl_minfo->hwb_rf_band[RTW89_MAC_1], + wl_rinfo->p2p_exist[RTW89_MAC_1]); + } + p += _show_wl_role_info(rtwdev, p, end - p); return p - buf; From 806bd61d51396878cbc3e03e62e800ccd9f5b539 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:09 +0800 Subject: [PATCH 1204/2126] wifi: rtw89: coex: add outsrc-set-info v7 for BT SPDT state The outsrc-set-info H2C used its last reserved byte for nothing. A newer firmware version reuses that byte to carry whether BT shares an SPDT switch with WL at the BB level, which the firmware needs to pick the right RF constraint. Add a v7 variant of the struct with the top bit of that byte named is_spdt_bb and the rest kept reserved, a matching H2C sender, and dispatch fcxosi == 7 to it. Also widen the gnt_set_be branch in the GNT H2C sender to cover fcxosi == 7, since it shares the same GNT layout as v6, and add the paired W2B/B2W scoreboard bits that let WL request and BT acknowledge the LNA-backoff table for this fcxosi version. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-5-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 6 +- drivers/net/wireless/realtek/rtw89/core.h | 28 ++++++++- drivers/net/wireless/realtek/rtw89/fw.c | 76 ++++++++++++++++++++++- drivers/net/wireless/realtek/rtw89/fw.h | 6 ++ 4 files changed, 113 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 556c35e84043..fbd1a6b33cb6 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -526,6 +526,7 @@ enum btc_b2w_scoreboard { BTC_BSCB_BT_CONNECT_56G = BIT(17), BTC_BSCB_BT_LNAB0_56G = BIT(18), BTC_BSCB_BT_LNAB1_56G = BIT(19), + BTC_BSCB_BT_BACKOFF_LNA = BIT(21), BTC_BSCB_HID_ACT = BIT(23), BTC_BSCB_BT_15DOT4 = BIT(24), BTC_BSCB_BT_PROTECT = BIT(27), @@ -829,6 +830,7 @@ enum btc_w2b_scoreboard { BTC_WSCB_CTCODE = BIT(15), BTC_WSCB_RXGAIN_56G = BIT(16), BTC_WSCB_BT_HILNA_56G = BIT(17), + BTC_WSCB_BT_BACKOFF_LNA = BIT(18), BTC_WSCB_ALL = GENMASK(23, 0), }; @@ -3871,6 +3873,8 @@ static void _fw_set_drv_info(struct rtw89_dev *rtwdev, u8 index) rtw89_fw_h2c_cxdrv_osi_info(rtwdev, index); else if (ver->fcxosi == 6) rtw89_fw_h2c_cxdrv_osi_info_v6(rtwdev, index); + else if (ver->fcxosi == 7) + rtw89_fw_h2c_cxdrv_osi_info_v7(rtwdev, index); else return; break; @@ -4018,7 +4022,7 @@ static void _set_gnt(struct rtw89_dev *rtwdev, u8 phy_map, memcpy(o->wlact_set, dm->wlact_set, sizeof(o->wlact_set)); - if (btc->ver->fcxosi == 6) { + if (btc->ver->fcxosi == 6 || btc->ver->fcxosi == 7) { memcpy(o->gnt_set_be, dm->gnt_set, sizeof(o->gnt_set_be)); return; } else if (btc->ver->fcxosi == 1) { diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index d66a1febb85c..30c5822d63b8 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -3925,6 +3925,32 @@ struct rtw89_btc_fbtc_outsrc_set_info_v6 { __le32 wl_tx_limit_time; } __packed; +struct rtw89_btc_fbtc_outsrc_set_info_v7 { + u8 rf_band[BTC_RF_NUM]; + u8 btg_rx[BTC_RF_NUM]; + u8 nbtg_tx[BTC_RF_NUM]; + + struct rtw89_btc_gnt_ctrl gnt_set[RTW89_MAC_AX_COEX_GNT_NR]; + struct rtw89_mac_ax_wl_act wlact_set[BTC_ALL_BT_EZL]; + + u8 pta_req_hw_band; + u8 rf_gbt_source; + u8 bt_enable_state; + u8 bt_plut_type; + u8 wl_tx_limit_en; + u8 fc_exec; + u8 wl_btg_standby_chg; + u8 option; +#define OPTION_SPDT_BB BIT(0) + u8 bb_path_sel_bt[BTC_RF_NUM]; + u8 bb_phy_sel_bt[RTW89_PHY_NUM]; + u8 fbd_group_en[RTW89_MAC_NUM][2]; + __le16 rf_center_freq[RTW89_MAC_NUM]; + __le16 freq_diff_thres[RTW89_MAC_NUM][BTC_ALL_BT_EZL]; + __le16 fbd_group_bound[RTW89_MAC_NUM][2]; + __le32 wl_tx_limit_time; +} __packed; + struct rtw89_btc_fbtc_outsrc_set_info { u8 rf_band[BTC_RF_NUM]; /* 0:2GHz/1:5GHz for MPI_bb_hwsi_ignore_gnt_wl() */ u8 btg_rx[BTC_RF_NUM]; /* for MPI_bb_btg_bt_rx() */ @@ -3945,7 +3971,7 @@ struct rtw89_btc_fbtc_outsrc_set_info { u8 wl_tx_limit_en; u8 fc_exec; u8 wl_btg_standby_chg; /* keep RX-IQGen on in standby mode */ - u8 rsvd; + u8 is_spdt_bb; /* v7: BT shares an SPDT with WL at BB level */ u8 bb_path_sel_bt[BTC_RF_NUM]; /* bb s0(1) select GNT_BT0 or BT1 */ u8 bb_phy_sel_bt[RTW89_PHY_NUM]; /* bb phy0(1) select GNT_BT0 or BT1 */ diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index 886d7c32d2ef..e9f6dc25b94c 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -7248,7 +7248,81 @@ int rtw89_fw_h2c_cxdrv_osi_info_v6(struct rtw89_dev *rtwdev, u8 type) h2c->osi.wl_tx_limit_en = osi->wl_tx_limit_en; h2c->osi.fc_exec = osi->fc_exec; h2c->osi.wl_btg_standby_chg = osi->wl_btg_standby_chg; - h2c->osi.rsvd = osi->rsvd; + h2c->osi.rsvd = 0; + + memcpy(h2c->osi.bb_path_sel_bt, osi->bb_path_sel_bt, sizeof(osi->bb_path_sel_bt)); + memcpy(h2c->osi.bb_phy_sel_bt, osi->bb_phy_sel_bt, sizeof(osi->bb_phy_sel_bt)); + memcpy(h2c->osi.fbd_group_en, osi->fbd_group_en, sizeof(osi->fbd_group_en)); + + for (i = 0; i < RTW89_MAC_NUM; i++) { + h2c->osi.rf_center_freq[i] = cpu_to_le16(osi->rf_center_freq[i]); + for (j = 0; j < BTC_RF_NUM; j++) + h2c->osi.fbd_group_bound[i][j] = + cpu_to_le16(osi->fbd_group_bound[i][j]); + } + + for (i = 0; i < RTW89_MAC_NUM; i++) { + for (j = 0; j < BTC_ALL_BT_EZL; j++) + h2c->osi.freq_diff_thres[i][j] = + cpu_to_le16(osi->freq_diff_thres[i][j]); + } + + h2c->osi.wl_tx_limit_time = cpu_to_le32(osi->wl_tx_limit_time); + + rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C, + H2C_CAT_OUTSRC, BTFC_SET, + SET_DRV_INFO, 0, 0, + len); + + ret = rtw89_h2c_tx(rtwdev, skb, false); + if (ret) { + rtw89_err(rtwdev, "failed to send h2c\n"); + goto fail; + } + + return 0; +fail: + dev_kfree_skb_any(skb); + + return ret; +} + +int rtw89_fw_h2c_cxdrv_osi_info_v7(struct rtw89_dev *rtwdev, u8 type) +{ + struct rtw89_btc *btc = &rtwdev->btc; + struct rtw89_btc_fbtc_outsrc_set_info *osi = &btc->dm.ost_info; + struct rtw89_h2c_cxosi_v7 *h2c; + u32 len = sizeof(*h2c); + struct sk_buff *skb; + int ret; + u8 i, j; + + skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len); + if (!skb) { + rtw89_err(rtwdev, "failed to alloc skb for h2c cxdrv_osi_v7\n"); + return -ENOMEM; + } + skb_put(skb, len); + h2c = (struct rtw89_h2c_cxosi_v7 *)skb->data; + + h2c->hdr.type = type; + h2c->hdr.ver = btc->ver->fcxosi; + h2c->hdr.len = len - H2C_LEN_CXDRVHDR_V7; + + memcpy(h2c->osi.rf_band, osi->rf_band, sizeof(osi->rf_band)); + memcpy(h2c->osi.btg_rx, osi->btg_rx, sizeof(osi->btg_rx)); + memcpy(h2c->osi.nbtg_tx, osi->nbtg_tx, sizeof(osi->nbtg_tx)); + memcpy(h2c->osi.gnt_set, osi->gnt_set, sizeof(osi->gnt_set)); + memcpy(h2c->osi.wlact_set, osi->wlact_set, sizeof(osi->wlact_set)); + + h2c->osi.pta_req_hw_band = osi->pta_req_hw_band; + h2c->osi.rf_gbt_source = osi->rf_gbt_source; + h2c->osi.bt_enable_state = osi->bt_enable_state; + h2c->osi.bt_plut_type = osi->bt_plut_type; + h2c->osi.wl_tx_limit_en = osi->wl_tx_limit_en; + h2c->osi.fc_exec = osi->fc_exec; + h2c->osi.wl_btg_standby_chg = osi->wl_btg_standby_chg; + h2c->osi.option = u8_encode_bits(!!osi->is_spdt_bb, OPTION_SPDT_BB); memcpy(h2c->osi.bb_path_sel_bt, osi->bb_path_sel_bt, sizeof(osi->bb_path_sel_bt)); memcpy(h2c->osi.bb_phy_sel_bt, osi->bb_phy_sel_bt, sizeof(osi->bb_phy_sel_bt)); diff --git a/drivers/net/wireless/realtek/rtw89/fw.h b/drivers/net/wireless/realtek/rtw89/fw.h index 5afdae3b1e79..e4d3331fc18f 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.h +++ b/drivers/net/wireless/realtek/rtw89/fw.h @@ -2527,6 +2527,11 @@ struct rtw89_h2c_cxosi_v6 { struct rtw89_btc_fbtc_outsrc_set_info_v6 osi; } __packed; +struct rtw89_h2c_cxosi_v7 { + struct rtw89_h2c_cxhdr_v7 hdr; + struct rtw89_btc_fbtc_outsrc_set_info_v7 osi; +} __packed; + struct rtw89_h2c_cxinit { struct rtw89_h2c_cxhdr hdr; u8 ant_type; @@ -5555,6 +5560,7 @@ int rtw89_fw_h2c_cxdrv_init_v11(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_mlo_v2(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_osi_info(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_osi_info_v6(struct rtw89_dev *rtwdev, u8 type); +int rtw89_fw_h2c_cxdrv_osi_info_v7(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_ctrl(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_ctrl_v7(struct rtw89_dev *rtwdev, u8 type); int rtw89_fw_h2c_cxdrv_ctrl_v9(struct rtw89_dev *rtwdev, u8 type); From 235a6ff568c36ece70a5081885bb3230d38c4e78 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:10 +0800 Subject: [PATCH 1205/2126] wifi: rtw89: coex: compute WL/BT cross-talk interference maps The TDD/FDD binding logic consumed dm->sit_xmap and dm->xtk_xmap to decide whether a WL RF-path and a BT device need TDD or FDD coexistence, but nothing in the driver ever wrote those two maps, so they stayed all-zero and the binding logic silently fell back to whatever that implied. Add _update_wl_rssi_status() to track the minimum WL RSSI across all connected roles and HW-bands and turn it into a per-BT interference state by comparing it against each BT's Tx power minus antenna isolation, and _update_sdm_map() to turn that state plus the existing antenna-sharing map into the cross-talk and space-interaction maps the binding logic expects. Call _update_wl_rssi_status() from the per-station notify path where RSSI is refreshed, and recompute the maps whenever it reports a change or whenever the BT scoreboard flips the dedicated TRX-active bit that forces TDD regardless of RSSI. _update_sdm_map() also runs once during coex init so the maps are populated before the first coex cycle, and _set_coex_binding() now derives dm->fit_used_path and a per-path dm->fit_map alongside the existing fit_xmap use, which a later change will need once it introduces 1SS Rx-path limiting. Whether the WL path under a 1SS RX limit still co-receives with a BT device also depends on traffic direction: the limit only confines RX, so the cross-talk map that feeds the TDD/FDD binding is derived differently for downlink than for uplink. Also recompute the maps when the per-station notify path latches a traffic direction flip, so a downlink-to-uplink switch with a steady RSSI does not leave the binding running on the previous direction's map until some later event happens to refresh it. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-6-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 291 +++++++++++++++++++++- drivers/net/wireless/realtek/rtw89/core.h | 4 + 2 files changed, 284 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index fbd1a6b33cb6..1d3ffde71c07 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -527,6 +527,7 @@ enum btc_b2w_scoreboard { BTC_BSCB_BT_LNAB0_56G = BIT(18), BTC_BSCB_BT_LNAB1_56G = BIT(19), BTC_BSCB_BT_BACKOFF_LNA = BIT(21), + BTC_BSCB_BT_15DOT4_TRX = BIT(22), BTC_BSCB_HID_ACT = BIT(23), BTC_BSCB_BT_15DOT4 = BIT(24), BTC_BSCB_BT_PROTECT = BIT(27), @@ -1013,6 +1014,7 @@ static void _run_coex(struct rtw89_dev *rtwdev, static void _write_scbd(struct rtw89_dev *rtwdev, u8 bid, u32 val, bool state); static u8 _sned_h2c_w2bscbd(struct rtw89_dev *rtwdev, bool force_exec, u8 bid); static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid, bool is_c2h); +static void _update_sdm_map(struct rtw89_dev *rtwdev); static const char *id_to_h2c(u32 id); static void _reset_h2c_macro(struct rtw89_btc *btc) @@ -8202,6 +8204,10 @@ static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid, bool is_c2h) !!(val & BTC_BSCB_BT_LNAB1) * 2; if (rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT) { + if ((val & BTC_BSCB_BT_15DOT4_TRX) != + (bt->scbd & BTC_BSCB_BT_15DOT4_TRX)) + _update_sdm_map(rtwdev); + if (val & BTC_BSCB_BT_15DOT4) bt->func_type |= (BTC_BTF_THREAD | BTC_BTF_ZB); else @@ -8597,9 +8603,142 @@ static void _set_bind_info(struct rtw89_btc *btc, u8 type) bd->bt_smap.ull_exist = 1; } -#define _bind_is_btonly 0x7 -static void _set_coex_binding(struct rtw89_btc *btc) +/* + * Get the only WL RF-path that still receives under 1SS MIMO-PS. + * + * Single source of truth for "is WL Rx confined to one RF-path, and which + * one". Both _update_sdm_map() (xtk_xmap) and _set_coex_binding() (fit_map) + * must agree, otherwise the two maps describe different WL Rx topologies. + * + * Conditions: + * - rx_limit: the BB/RF was actually programmed to 1SS by _set_trx_nss() + * - DL only: rx_limit shrinks the Rx stream, WL Tx still runs 2SS/2TX on both + * paths for UL, so every path stays BT-interactive there + * - 2+0/0+2 only: both RF-path serve the same link on one HW-band, so there + * is an unused path. In 1+1/2+2 each RF-path serves its own link on its own + * HW-band and none of them can be dropped + * + * Return dm->wl_trx_nss.rx_path (RF_PATH_A/B, == BTC_RF_S0/S1) if 1SS + * MIMO-PS is active, RF_PATH_AB if WL keeps both Rx paths. + */ +static u8 _get_sdm_1ss_path(struct rtw89_dev *rtwdev) { + struct rtw89_btc_wl_trx_nss_para *trx_nss = &rtwdev->btc.dm.wl_trx_nss; + struct rtw89_btc_wl_info *wl = &rtwdev->btc.cx.wl; + + if (!trx_nss->rx_limit || + !(wl->status.map.traffic_dir & BIT(RTW89_TFC_DL))) + return RF_PATH_AB; + + if (wl->mlo_info.rf_combination != BTC_MLO_RF_2_PLUS_0 && + wl->mlo_info.rf_combination != BTC_MLO_RF_0_PLUS_2) + return RF_PATH_AB; + + /* + * rx_path is what _set_trx_nss() passed to cfg_trx_path(), it must be + * a single path to be used as an RF-path index below + */ + if (trx_nss->rx_path != RF_PATH_A && trx_nss->rx_path != RF_PATH_B) + return RF_PATH_AB; + + return trx_nss->rx_path; +} + +static void _update_sdm_map(struct rtw89_dev *rtwdev) +{ + struct rtw89_btc *btc = &rtwdev->btc; + struct rtw89_btc_module *module = &btc->mdinfo; + struct rtw89_btc_cx *cx = &btc->cx; + struct rtw89_btc_bt_info *bt0 = &cx->bt0; + struct rtw89_btc_bt_info *bt1 = &cx->bt1; + struct rtw89_btc_wl_info *wl = &cx->wl; + struct rtw89_btc_dm *dm = &btc->dm; + u8 map[BTC_RF_NUM][BTC_ALL_BT_EZL]; + bool mlo_1_plus_1 = false; + u8 used_path; + u8 i, j; + + /* + * xtk_xmap(Cross-talk map)-> 1: interaction, 0: no-interaction + * calculate WL/BT interference by SIR + * ==>1:If WL_RSSI < (BT-Pin -SIR), it means BT-Tx interfer with WL-Rx + * ==>BT-pin = BT-Tx-Power - Ant-isolation + */ + if (wl->mlo_info.wtype != RTW89_MR_WTYPE_MLD2L1R_NONMLD && + (wl->mlo_info.rf_combination == BTC_MLO_RF_1_PLUS_1 || + wl->mlo_info.rf_combination == BTC_MLO_RF_2_PLUS_2)) + mlo_1_plus_1 = true; + + /* + * WL running 1SS MIMO-PS (CIS LE-audio): WL Rx is confined to a single + * path. The used path co-Rx with its co-ant BT (=1) or follows RSSI vs. + * the other BT; the unused path no longer co-Rx with any BT (=0). + * RF_PATH_AB -> not 1SS, keep the original per-path logic. + * + * Record it: this function also runs at the _set_trx_nss() exit, after + * rx_limit/rx_path changed, so dm->fit_used_path stays the up-to-date + * 1SS state for the _action_common() consumers that run later in the + * same coex cycle (_set_wl_preagc_ctrl, _set_bt_corx_table). + */ + used_path = _get_sdm_1ss_path(rtwdev); + dm->fit_used_path = used_path; + + memset(map, 0, sizeof(map)); + for (i = 0; i < BTC_RF_NUM; i++) { + if (module->ant.num == 1 && i == BTC_RF_S1) + break; + + for (j = 0; j < BTC_ALL_BT_EZL; j++) { + if ((bt0->scbd_c2h & BTC_BSCB_BT_15DOT4_TRX) || + (bt1->scbd_c2h & BTC_BSCB_BT_15DOT4_TRX)) { + /* 15.4 TRX active: force BT0/BT1 to TDD */ + if (j < BTC_ALL_BT) + dm->xtk_xmap[i][j] = 1; + else + continue; /* j == EXT: not force TDD */ + } else if (used_path != RF_PATH_AB && j < BTC_ALL_BT) { + /* 1SS MIMO-PS: only the used WL path co-Rx */ + if (i != used_path) + dm->xtk_xmap[i][j] = 0; + else if (dm->ant_xmap[i][j] == 1) + dm->xtk_xmap[i][j] = 1; + else + dm->xtk_xmap[i][j] = + BTC_RSSI_LOW(dm->sir_state[j]) ? 1 : 0; + } else if (dm->ant_xmap[i][j] == 1) { + /* if WL RF-pathx co-ant with BTx */ + dm->xtk_xmap[i][j] = 1; + } else if (((j == BTC_BT_1ST && + module->bt0_sw_type != BTC_SWITCH_V1_NONE) || + (j == BTC_BT_2ND && + module->bt1_sw_type != BTC_SWITCH_V1_NONE)) && + !mlo_1_plus_1) { + /* + * if WL RF-pathx not co-ant/path with BTx + * but BTx co-ant/path with the other WL-path + * and WL is 2+0/0+2 + * ex: WL-S0 + (WL-S1 & BT0-S1) -> + * BT0-S1 vs. WL-S0 = 1 + */ + dm->xtk_xmap[i][j] = 1; + } else if (BTC_RSSI_LOW(dm->sir_state[j])) { + /* if WL_RSSI below BT-Tx interference thres */ + dm->xtk_xmap[i][j] = 1; + } else { + dm->xtk_xmap[i][j] = 0; + } + + map[i][j] = dm->ant_xmap[i][j] | dm->xtk_xmap[i][j]; + } + } + + memcpy(dm->sit_xmap, map, sizeof(map)); +} + +#define _bind_is_btonly 0x7 +static void _set_coex_binding(struct rtw89_dev *rtwdev) +{ + struct rtw89_btc *btc = &rtwdev->btc; struct rtw89_btc_cx *cx = &btc->cx; struct rtw89_btc_extsoc_info *bt2 = &cx->bt_ext; struct rtw89_btc_bt_info *bt0 = &cx->bt0; @@ -8608,7 +8747,7 @@ static void _set_coex_binding(struct rtw89_btc *btc) struct rtw89_btc_dm *dm = &btc->dm; u8 path_hwb[BTC_RF_NUM] = {RTW89_PHY_0, RTW89_PHY_1}; u8 wl_rf_band[RTW89_BAND_NUM] = {}; - u8 i, j, val = 0; + u8 i, j, val = 0, fit, used_path; /* * sit_xmap(Space-Interaction) = ant_xmap | xtk_xmap @@ -8657,21 +8796,49 @@ static void _set_coex_binding(struct rtw89_btc *btc) path_hwb[BTC_RF_S0] = RTW89_PHY_1; /* 2+0 RF-S0/1->HWB1 */ } + /* + * WL 1SS MIMO-PS: WL Rx is confined to a single path, so the unused + * path has no WL-Rx frequency interference with any BT. + * RF_PATH_AB -> not 1SS, both paths keep their real fit_xmap. + * Same helper as _update_sdm_map(), so xtk_xmap and fit_map always + * agree on which RF-path is the unused one. + * e.g. CIS@BT_2ND -> rx_path=RF_PATH_B, used_path=S1: + * RF-S1 keeps its real fit_xmap, RF-S0 is cleared. + */ + used_path = _get_sdm_1ss_path(rtwdev); + dm->fit_used_path = used_path; /* record for dbg cmd "xmap" */ + /* * tdd_map = sit_xmap * fdm_map, 1: WL-RF-Sx vs. BTx take TDD-Action * fdd_map =(!sit_xmap) * fdm_map, 1: WL-RF-Sx vs.BTx take FDD-Action * co-rx map = ant_xmap * fdm_map 1:WL/BT co-rx (for halbb-btg-ctrl) * sit_xmap,ant_xmap = 0 or 1, so tdd/fdd use multiplication (*) + * + * fit: WL-BT freq-interact(2bit band-map) of RF-Sx vs. BTx, + * = fit_xmap[HWB][BTx], the used_path keeps this real band-map, + * the unused path is cleared to 0 if 1SS MIMO-PS. */ for (i = 0; i < BTC_RF_NUM; i++) for (j = 0; j < BTC_ALL_BT_EZL; j++) { - dm->tdd_map[i][j] = dm->sit_xmap[i][j] * - dm->fit_xmap[path_hwb[i]][j]; - dm->fdd_map[i][j] = !dm->sit_xmap[i][j] * - dm->fit_xmap[path_hwb[i]][j]; - dm->corx_map[i][j] = dm->ant_xmap[i][j] * - dm->fit_xmap[path_hwb[i]][j]; + fit = dm->fit_xmap[path_hwb[i]][j]; + + /* + * 1SS MIMO-PS: no WL-Rx on the unused path. + * Only the local fit is dropped, dm->fit_xmap keeps + * the real per-HW-band map: it is indexed by HW-band, + * and both RF-path may map to the same HW-band, so + * clearing it there would also drop used_path's entry + * (and the other MLO link's entry in DB_MCC). + */ + if (used_path != RF_PATH_AB && i != used_path) + fit = 0; + + dm->fit_map[i][j] = fit; /* for dbg cmd "xmap" */ + + dm->tdd_map[i][j] = dm->sit_xmap[i][j] * fit; + dm->fdd_map[i][j] = !dm->sit_xmap[i][j] * fit; + dm->corx_map[i][j] = dm->ant_xmap[i][j] * fit; } /* TDD-Binding */ @@ -8794,7 +8961,7 @@ void _run_coex(struct rtw89_dev *rtwdev, enum btc_reason_and_action reason) dm->fddt_train = BTC_FDDT_DISABLE; bt->scan_rx_low_pri = false; - _set_coex_binding(btc); + _set_coex_binding(rtwdev); _update_btc_state_map(rtwdev); dm->freerun_chk = _check_freerun(rtwdev); /* check if meet freerun */ @@ -9031,6 +9198,8 @@ static void _set_init_info(struct rtw89_dev *rtwdev) btc_fw_set_monreg(rtwdev); _set_ext_interface(rtwdev); _set_wl_tx_power(rtwdev, RTW89_BTC_WL_DEF_TX_PWR, RTW89_PHY_0); + + _update_sdm_map(rtwdev); } void rtw89_btc_ntfy_init(struct rtw89_dev *rtwdev, u8 mode) @@ -9970,6 +10139,96 @@ static void rtw89_btc_ntfy_wl_sta_iter(void *data, struct ieee80211_sta *sta) #define BTC_NHM_CHK_INTVL 20 +static bool _update_wl_rssi_status(struct rtw89_dev *rtwdev) +{ + struct rtw89_btc *btc = &rtwdev->btc; + struct rtw89_btc_cx *cx = &btc->cx; + struct rtw89_btc_wl_info *wl = &cx->wl; + struct rtw89_btc_dm *dm = &btc->dm; + struct rtw89_btc_bt_link_info *b; + u8 i, j, ant_iso, th, rssi, nxt, bt_enable; + u8 wl_rf_band = RTW89_BAND_2G, cnt = 0; + bool status_change = false; + s8 bt_pin; + s32 val; + + /* Update WL RSSI (search the min value between all role/HW-band) */ + rssi = 110; /* unit: % */ + for (i = 0; i < RTW89_BE_BTC_WL_MAX_ROLE_NUMBER; i++) { + for (j = 0; j < RTW89_MAC_NUM; j++) { + if (!wl->rlink_info[i][j].active || + wl->rlink_info[i][j].connected == MLME_NO_LINK) + continue; + + if (wl->rlink_info[i][j].stat.rssi < rssi) { /* find min */ + rssi = wl->rlink_info[i][j].stat.rssi; + wl_rf_band = wl->rlink_info[i][j].band; + cnt++; + } + } + } + + if (cnt == 0) /* no wifi link exist */ + wl->rssi = 0; + else + wl->rssi = rssi; + + /* SIR state: compare WL_RSSI with each BT-Tx interference */ + for (i = BTC_BT_1ST; i <= BTC_BT_EXT; i++) { + switch (i) { + case BTC_BT_1ST: + default: + bt_enable = cx->bt0.enable.now; + ant_iso = cx->bt0.ant_iso_to_wl; + if (wl_rf_band != RTW89_BAND_2G) /* find same rf-band */ + b = &cx->bt0.link_info_56g; + else + b = &cx->bt0.link_info; + if (b->bt_txpwr_desc.le_dbm > b->bt_txpwr_desc.br_dbm) + bt_pin = b->bt_txpwr_desc.le_dbm; + else + bt_pin = b->bt_txpwr_desc.br_dbm; + break; + case BTC_BT_2ND: + bt_enable = cx->bt1.enable.now; + ant_iso = cx->bt1.ant_iso_to_wl; + if (wl_rf_band != RTW89_BAND_2G) /* find same rf-band */ + b = &cx->bt0.link_info_56g; + else + b = &cx->bt0.link_info; + if (b->bt_txpwr_desc.le_dbm > b->bt_txpwr_desc.br_dbm) + bt_pin = b->bt_txpwr_desc.le_dbm; + else + bt_pin = b->bt_txpwr_desc.br_dbm; + break; + case BTC_BT_EXT: + bt_enable = !!cx->bt_ext.func_type; + ant_iso = cx->bt_ext.ant_iso_to_wl; + bt_pin = cx->bt_ext.max_tx_pwr; + break; + } + + val = 110 + bt_pin - ant_iso - dm->sir_thres; + if (!bt_enable || val <= 0) + th = 0; + else if (val >= 110) + th = 110; + else + th = (u8)val; + + dm->tdd_rssi_thres = th; + + nxt = _update_rssi_state(rtwdev, dm->sir_state[i], wl->rssi, th); + + if (nxt != dm->sir_state[i]) { + dm->sir_state[i] = nxt; + status_change = true; + } + } + + return status_change; +} + void rtw89_btc_ntfy_wl_sta(struct rtw89_dev *rtwdev) { struct rtw89_btc *btc = &rtwdev->btc; @@ -9995,6 +10254,9 @@ void rtw89_btc_ntfy_wl_sta(struct rtw89_dev *rtwdev) if (dm->trx_info.wl_rssi != wl->rssi_level) dm->trx_info.wl_rssi = wl->rssi_level; + if (_update_wl_rssi_status(rtwdev)) + _update_sdm_map(rtwdev); + rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s(): busy=%d\n", __func__, !!wl->status.map.busy); @@ -10004,7 +10266,14 @@ void rtw89_btc_ntfy_wl_sta(struct rtw89_dev *rtwdev) _fw_set_drv_info(rtwdev, CXDRVINFO_ROLE); if (data.is_sta_change) { wl->status.map.busy = data.busy_all; - wl->status.map.traffic_dir = data.dir_all; + if (wl->status.map.traffic_dir != data.dir_all) { + wl->status.map.traffic_dir = data.dir_all; + /* + * traffic_dir (UL/DL) switch changes the 1SS MIMO-PS + * xtk_xmap, recompute sit_xmap in the same coex cycle + */ + _update_sdm_map(rtwdev); + } _run_coex(rtwdev, BTC_RSN_NTFY_WL_STA); } else if (btc->dm.cnt_notify[BTC_NCNT_WL_STA] >= btc->dm.cnt_dm[BTC_DCNT_WL_STA_LAST] + BTC_NHM_CHK_INTVL) { diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 30c5822d63b8..340633c42c9f 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -2403,6 +2403,7 @@ struct rtw89_btc_wl_info { u8 port_id[RTW89_WIFI_ROLE_MLME_MAX]; u8 rssi_level; + u8 rssi; /* min WL RSSI among all active role/HW-band, 0~110% */ u8 cn_report; u8 coex_mode; u8 pta_req_mac; @@ -4144,6 +4145,9 @@ struct rtw89_btc_dm { u8 tdd_map[BTC_RF_NUM][BTC_ALL_BT_EZL]; /* WL-BT tdd-map */ u8 fdd_map[BTC_RF_NUM][BTC_ALL_BT_EZL]; /* WL-BT fdd-map */ u8 corx_map[BTC_RF_NUM][BTC_ALL_BT_EZL]; /* WL-BT Co-Rx */ + /* RF-Sx view of fit_xmap, 1SS MIMO-PS applied */ + u8 fit_map[BTC_RF_NUM][BTC_ALL_BT_EZL]; + u8 fit_used_path; /* 1SS MIMO-PS Rx path, RF_PATH_AB if no limit */ u8 sit_xmap_last[BTC_RF_NUM][BTC_ALL_BT_EZL]; u8 fit_xmap_last[RTW89_PHY_NUM][BTC_ALL_BT_EZL]; From c4b17492a37c03bf4db98e99d75321d3f3a00a13 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:11 +0800 Subject: [PATCH 1206/2126] wifi: rtw89: coex: add 1SS MIMO-PS decision for dual-BT CIS When a BT CIS (LE-audio) link exists on a dual-BT, shared-antenna chip, limiting WL to 1SS on the RF-path that is isolated from that link protects WL Rx from the CIS traffic without a full freerun fallback. Add _set_trx_nss() to compute whether that 1SS limit should apply, which path it should apply to, and what stream count and path the WL TRX should fall back to when it does not, gated on a chip-reported MIMO-PS capability flag and limited to Lenovo designs or dual-BT chips to match the hardware this has been validated on. The result also re-arms the limit once after a device exits low-power state, since LPS can clear the BB/RF setup the previous decision put in place. The RTL8922D 3-antenna shared configuration also claimed that capability, but it has no WL path shared with BT to power down, so the limit there would cost a stream without buying any isolation. Measurement on that configuration confirms it, so stop reporting the capability for it and leave the 2-antenna configuration as the only one that does. There is currently no driver API to apply the computed stream/path decision to the BB and RF, so the function stops right after printing the decision for debug and before it would otherwise update dm->wl_trx_nss, recompute the cross-talk maps, or call into set_rfe(). Those steps follow once that HW-apply API exists. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-7-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 128 ++++++++++++++++++ drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/rtw8922d.c | 1 - 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 1d3ffde71c07..0b9858d1859a 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -6993,6 +6993,133 @@ static void _set_fw_report_map(struct rtw89_dev *rtwdev) rtw89_btc_fw_en_rpt(rtwdev, false, rpt_map); } +static void _set_trx_nss(struct rtw89_dev *rtwdev) +{ + struct rtw89_btc *btc = &rtwdev->btc; + struct rtw89_btc_dm *dm = &btc->dm; + struct rtw89_btc_bind_bt_status *btdd = &dm->tdd_bind.bt_smap; + struct rtw89_btc_bind_bt_status *bfdd = &dm->fdd_bind.bt_smap; + struct rtw89_btc_wl_trx_nss_para *trx_nss = &dm->wl_trx_nss; + struct rtw89_btc_module *module = &btc->mdinfo; + struct rtw89_btc_cx *cx = &btc->cx; + struct rtw89_btc_wl_info *wl = &cx->wl; + bool bt0_cis = cx->bt0.link_info.leaudio_desc.cis_exist; + bool bt1_cis = cx->bt1.link_info.leaudio_desc.cis_exist; + u8 tx_ss, rx_ss, tx_path, rx_path, limit_path; + u8 tx_limit = 0, rx_limit = 0; + + /* tx/rx_limit: 1 = 1ss, 0 = HW default */ + rtw89_debug(rtwdev, RTW89_DBG_BTC, + "[BTC], %s(): wl_rinfo->link_mode=%d, dm->wl_trx_nss_en=%d\n", + __func__, wl->role_info.link_mode[RTW89_MAC_0], dm->wl_trx_nss_en); + + /* + * Skip 1SS MIMO-PS if: + * - manual mode or DBCC enabled + * - !wl_trx_nss_en: no MIMO-PS capability. The RFE configs that share + * a WL path with BT are selected in ops->set_rfe() (e.g. 8922D only + * sets it for ant.num=2), so this flag is the single gate here, no + * extra ant.num/bt1_sw_type check. + * - non-LNV vendor and no DUAL_BT. Dual-BT chips run MIMO-PS for every + * vendor, single-BT chips only for LNV (LNV: PCIE-12223) + */ + if (btc->manual_ctrl || wl->role_info.dbcc_en || !dm->wl_trx_nss_en || + (dm->vid != RTW89_CUSTID_LENOVO && + !(rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT))) + return; + + /* + * Disable 1SS limit when: + * - No WiFi link (WL idle state) + * - Out-of-band scenario (no BT coex needed) + */ + if (wl->role_info.link_mode[RTW89_MAC_0] == BTC_WLINK_NOLINK || + wl->role_info.link_mode[RTW89_MAC_1] == BTC_WLINK_NOLINK || + dm->out_of_band) { + tx_limit = 0; + rx_limit = 0; + } else if (bt0_cis || bt1_cis || btdd->cis_exist || bfdd->cis_exist) { + /* + * Enable 2T1R when BT CIS profile exists (low latency audio). + * tx_limit=1 (1T1R full isolation) reserved for future use + * when WL needs to fully isolate Tx from BT on shared antenna. + */ + tx_limit = 0; + rx_limit = 1; + } + + /* + * BT1 at S0 has CIS -> WL must use S1 (path B) + * BT0 at S1 has CIS -> WL must use S0 (path A) + */ + limit_path = bt1_cis ? RF_PATH_B : RF_PATH_A; + + /* + * Re-arm the exit-LPS one-shot once the event is over. lps_exiting is + * held for a while by the LPS-exit timer, so it must not be used as + * the force-exec condition directly. + */ + if (!wl->status.map.lps_exiting) + dm->trx_nss_lps_done = 0; + + if (trx_nss->rx_limit == rx_limit && trx_nss->tx_limit == tx_limit && + (!rx_limit || trx_nss->rx_path == limit_path)) { + /* + * WL just exited LPS: LPS may have cleared the BB/RF 1SS + * setup, so re-issue cfg_1ss/cfg_trx_path/set_rfe once per + * exit-LPS event. They are heavy (set_rfe() re-reads efuse and + * does several RF I/O), so a one-shot flag instead of lps_exiting. + */ + if (wl->status.map.lps_exiting && !dm->trx_nss_lps_done) + goto force_exec; + + return; + } + +force_exec: + /* one-shot consumed, no re-exec until the next exit-LPS event */ + dm->trx_nss_lps_done = wl->status.map.lps_exiting; + + rtw89_debug(rtwdev, RTW89_DBG_BTC, + "[BTC], %s(): stream_cnt=0x%02x, path_pos=0x%02x\n", + __func__, module->ant.stream_cnt, module->ant.path_pos); + + /* + * Reduce TX to 1SS on the isolated path to avoid BT interference, + * else restore TX to HW default stream count and path. + */ + if (tx_limit) { + tx_ss = 1; + tx_path = limit_path; + } else { + tx_ss = FIELD_GET(BTC_ANT_TX_MASK, module->ant.stream_cnt); + tx_path = FIELD_GET(BTC_ANT_TX_MASK, module->ant.path_pos); + } + + /* + * Reduce RX to 1SS on the isolated path to protect WL Rx stream, + * else restore RX to HW default stream count and path. + */ + if (rx_limit) { + rx_ss = 1; + rx_path = limit_path; + } else { + rx_ss = FIELD_GET(BTC_ANT_RX_MASK, module->ant.stream_cnt); + rx_path = FIELD_GET(BTC_ANT_RX_MASK, module->ant.path_pos); + } + + rtw89_debug(rtwdev, RTW89_DBG_BTC, + "[BTC], %s(): tx_ss=%d, rx_ss=%d, tx_path=%d, rx_path=%d\n", + __func__, tx_ss, rx_ss, tx_path, rx_path); + + /* + * TODO: no driver API to apply tx_limit/rx_limit/tx_ss/rx_ss/tx_path/ + * rx_path to the BB/RF 1SS MIMO-PS HW state yet. Stop here so + * trx_nss/always_freerun/ant.type/set_rfe()/_update_sdm_map() below + * never run from a decision that was never applied to HW. + */ +} + static void _action_common(struct rtw89_dev *rtwdev) { struct rtw89_btc *btc = &rtwdev->btc; @@ -7002,6 +7129,7 @@ static void _action_common(struct rtw89_dev *rtwdev) u8 i; _wl_req_mac(rtwdev, rinfo->pta_req_band); + _set_trx_nss(rtwdev); _update_zb_coex_tbl(rtwdev); _set_btg_ctrl(rtwdev); _set_wl_preagc_ctrl(rtwdev); diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 340633c42c9f..624b8d1b4742 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -4188,6 +4188,7 @@ struct rtw89_btc_dm { u8 vid; u8 client_ps_tdma_on; u8 wl_trx_nss_en; + u8 trx_nss_lps_done; /* 1SS re-setup done for this exit-LPS */ u8 wl_pre_agc: 2; u8 wl_lna2: 1; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 41e2aa1c8f78..7ac15a5d949a 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -3336,7 +3336,6 @@ static void rtw8922d_btc_set_rfe(struct rtw89_dev *rtwdev) md->bt0_pos = BTC_BT_BTG; md->bt0_sw_type = BTC_SWITCH_V1_INTERNAL; dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; - dm->wl_trx_nss_en = 1; /* 1ss MIMO-PS capability */ } else { md->ant.func[0] = BTC_EFMAP_NONE; md->ant.func[1] = BTC_EFMAP_NONE; From a35cf81f60846ed2a0f9591003f3459f681d6951 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:12 +0800 Subject: [PATCH 1207/2126] wifi: rtw89: coex: add firmware 0.35.119.3 support for RTL8922A/D Firmware 0.35.119.3 moves both RTL8922A and RTL8922D to coex H2C role-info version 11 and outsrc-set-info version 7. Add top ver_defs entries for both chips with the new fwlrole and fcxosi values; all other scope versions are unchanged from the previous firmware. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-8-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 0b9858d1859a..80c278aa96f0 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -133,6 +133,15 @@ static const u32 cxtbl[] = { static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { /* firmware version must be in decreasing order for each chip */ + {RTL8922D, RTW89_FW_VER_CODE(0, 35, 119, 3), + .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, + .fcxstep = 7, .fcxnullsta = 7, .fcxmreg = 7, .fcxgpiodbg = 8, + .fcxbtver = 8, .fcxbtscan = 8, .fcxbtafh = 8, .fcxbtdevinfo = 8, + .fwlrole = 11, .frptmap = 5, .fcxctrl = 9, .fcxinit = 11, + .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800, + .max_role_num = 6, .fcxosi = 7, .fcxmlo = 2, .bt_desired = 8, + .fcxtrx = 9, .fcxtxpwr = 1, + }, {RTL8922D, RTW89_FW_VER_CODE(0, 35, 111, 0), .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, .fcxstep = 7, .fcxnullsta = 7, .fcxmreg = 7, .fcxgpiodbg = 8, @@ -178,6 +187,15 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = { .max_role_num = 6, .fcxosi = 0, .fcxmlo = 0, .bt_desired = 8, .fcxtrx = 0, .fcxtxpwr = 0, }, + {RTL8922A, RTW89_FW_VER_CODE(0, 35, 119, 3), + .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, + .fcxstep = 7, .fcxnullsta = 7, .fcxmreg = 7, .fcxgpiodbg = 8, + .fcxbtver = 8, .fcxbtscan = 8, .fcxbtafh = 8, .fcxbtdevinfo = 8, + .fwlrole = 11, .frptmap = 5, .fcxctrl = 9, .fcxinit = 11, + .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800, + .max_role_num = 6, .fcxosi = 7, .fcxmlo = 2, .bt_desired = 8, + .fcxtrx = 9, .fcxtxpwr = 1, + }, {RTL8922A, RTW89_FW_VER_CODE(0, 35, 111, 0), .fcxbtcrpt = 11, .fcxtdma = 8, .fcxslots = 7, .fcxcysta = 8, .fcxstep = 7, .fcxnullsta = 7, .fcxmreg = 7, .fcxgpiodbg = 8, From 8773800337cd10db114b6779912fe87e782a1687 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:13 +0800 Subject: [PATCH 1208/2126] wifi: rtw89: coex: raise default BT TX power to 10 dBm The TDD/FDD switch threshold is derived as the WL RSSI at which a BT device's TX power, after antenna isolation, starts to interfere: 110 + bt_pin - ant_iso - sir_thres, in RSSI percent. Before the first BT TX power report arrives, and on any link whose report never arrives, bt_pin falls back to the BR/LE defaults, so those defaults decide where coexistence flips between TDD and FDD. Both defaults were 4 dBm, which places the threshold about 6 dB below what the BT side actually transmits at, so the driver stays in FDD well past the point where BT TX already interferes with WL RX. Raise both to 10 dBm, which matches the BT TX power these designs report once their first query completes. The 8922A ext-SOC path already used a separate 10 dBm define for the same reason; drop it now that the common default carries that value. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-9-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 5 ++--- drivers/net/wireless/realtek/rtw89/rtw8922a.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 624b8d1b4742..b1f92c1d0428 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -2656,10 +2656,9 @@ enum rtw89_btc_bt_func_type { #define RTW89_BTC_BTC_SCAN_V1_FLAG_ENABLE BIT(0) #define RTW89_BTC_BTC_SCAN_V1_FLAG_INTERLACE BIT(1) -#define RTW89_BTC_BT_DEF_BR_TX_PWR 4 -#define RTW89_BTC_BT_DEF_LE_TX_PWR 4 +#define RTW89_BTC_BT_DEF_BR_TX_PWR 10 /* in dBm */ +#define RTW89_BTC_BT_DEF_LE_TX_PWR 10 #define RTW89_BTC_DEFAULT_ANISO 10 -#define RTW89_BTC_BT_DEF_LE_TX_PWR_1 10 struct rtw89_btc_bt_scan_info_v1 { __le16 win; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922a.c b/drivers/net/wireless/realtek/rtw89/rtw8922a.c index 6402bd4f06aa..e48300287697 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922a.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922a.c @@ -2796,7 +2796,7 @@ static void rtw8922a_btc_set_rfe(struct rtw89_dev *rtwdev) default: case BTC_ESOC_NONE: memset(&btc->cx.bt_ext, 0, sizeof(struct rtw89_btc_extsoc_info)); - btc->cx.bt_ext.max_tx_pwr = RTW89_BTC_BT_DEF_LE_TX_PWR_1; + btc->cx.bt_ext.max_tx_pwr = RTW89_BTC_BT_DEF_LE_TX_PWR; btc->cx.bt_ext.ant_iso_to_wl = RTW89_BTC_DEFAULT_ANISO; break; case BTC_ESOC_8771: From d4a862cf7661254baa4ea3f468b5bf4a5bf43999 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:14 +0800 Subject: [PATCH 1209/2126] wifi: rtw89: coex: bind the RF band in use while WL is doing RFK The RF band that TDD and FDD bind to is picked by scoring each BT link's weight against the WL/BT band-overlap map. That map is built from connected WL links, so while WL is running RFK on a band it has not associated on yet, neither band scores and the binding ends up empty. Coexistence then treats the chip as having no WL/BT band overlap at all and leaves RFK unprotected against a BT device already transmitting on that same band, which can corrupt the calibration result. Force the score of the band being calibrated up to the binding threshold when any BT is on an overlapping band, so the RFK band binds for as long as the calibration runs. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-10-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 80c278aa96f0..ebc4b1b415c8 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -8610,6 +8610,26 @@ static void _set_bind_info(struct rtw89_btc *btc, u8 type) b5g_score += link_weight[j][BTC_BT_B5G]; } + /* + * Consider WL RFK band for coex (avoid missing RFK case) + * If WL is doing RFK, check RFK band vs BT band overlap + * Only add score when RFK band matches BT band + */ + if (wl->rfk_info.state != BTC_WRFK_STOP) { + if (wl->rfk_info.band == RTW89_BAND_2G) { + /* RFK on 2.4GHz, check if any BT is also on 2.4GHz */ + if ((cx->bt0.rf_band_map & BIT(RTW89_BAND_2G)) || + (cx->bt1.rf_band_map & BIT(RTW89_BAND_2G))) + b2g_score = thres; + } else if (wl->rfk_info.band == RTW89_BAND_5G || + wl->rfk_info.band == RTW89_BAND_6G) { + /* RFK on 5/6GHz, check if any BT is also on 5GHz */ + if ((cx->bt0.rf_band_map & BIT(RTW89_BAND_5G)) || + (cx->bt1.rf_band_map & BIT(RTW89_BAND_5G))) + b5g_score = thres; + } + } + /* rf-band bound by comparing link weight */ if (b2g_score == 0 && b5g_score == 0) /* no-rf-band overlap */ bd->rf_band = 0; From 96ad55bfbb657c46623c2aac7c15309bf215affa Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:15 +0800 Subject: [PATCH 1210/2126] wifi: rtw89: coex: store BT TX power per device and per RF band A BT TX power report identifies which BT device came from, in bit 7 of its second byte, whether it describes that device's 2.4 GHz or 5/6 GHz link. The handler ignored both and always wrote the first BT device's 2.4 GHz link info. On a chip with two BT devices or with 5/6 GHz BT support, the reported power therefore never reached the second device or the 5/6 GHz link. The TDD/FDD switch threshold reads exactly those fields when the WL link is not on 2.4 GHz or when it scores the second BT, so on those paths it kept comparing against the reset default instead of what BT actually transmits at. Select the device from the report's own index and the link from its band bit, the same way the other BT mailbox reports already do. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-11-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index ebc4b1b415c8..c25bc9e619ce 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -8542,14 +8542,23 @@ static void _update_bt_bistdma_info(struct rtw89_dev *rtwdev, u8 bid, } #define BTC_BTINFO_PWR_LEN 5 -static void _update_bt_txpwr_info(struct rtw89_dev *rtwdev, u8 *buf, u32 len) +static void _update_bt_txpwr_info(struct rtw89_dev *rtwdev, u8 bid, u8 *buf, + u32 len) { - struct rtw89_btc_bt_info *bt = &rtwdev->btc.cx.bt0; - struct rtw89_btc_bt_link_info *b = &bt->link_info; + struct rtw89_btc_cx *cx = &rtwdev->btc.cx; + struct rtw89_btc_bt_link_info *b; + struct rtw89_btc_bt_info *bt; if (len != BTC_BTINFO_PWR_LEN) return; + bt = bid == BTC_BT_1ST ? &cx->bt0 : &cx->bt1; + + if ((buf[BTC_BTINFO_L1] & BIT(7)) && bt->band_56G_support) + b = &bt->link_info_56g; + else + b = &bt->link_info; + if (!memcmp(bt->txpwr_info, buf, sizeof(bt->txpwr_info))) { rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s return by info duplicate!\n", __func__); @@ -10594,7 +10603,7 @@ void rtw89_btc_c2h_handle(struct rtw89_dev *rtwdev, struct sk_buff *skb, break; case BTF_EVNT_BT_QUERY_TXPWR: bt->bcnt[BTC_BCNT_TXPWR_UPDATE]++; - _update_bt_txpwr_info(rtwdev, buf, len); + _update_bt_txpwr_info(rtwdev, bid, buf, len); } } From f3207ae572742077b42bb398316197ffb423c054 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:16 +0800 Subject: [PATCH 1211/2126] wifi: rtw89: coex: set the WL/BT antenna map on shared-antenna chips The WL/BT space-interaction map that decides whether a WL RF-path and a BT take a TDD or an FDD action is built from the antenna-division map with the cross-talk map. A WL RF-path that physically shares its antenna with a BT must be marked in the antenna-division map, otherwise it is only ever marked interacting when the measured WL RSSI happens to fall below the BT Tx interference threshold, and a shared-antenna design with a strong WL signal gets bound to FDD where it has to coexist in time instead. Chips with a single BT never filled that map, so fill it from the RFE type that the antenna configuration is already derived from: mark the one WL RF-path that carries the BTG circuit as sharing with the only BT whenever the antenna type is shared, and leave the map clear for the dedicated-antenna RFE types where the BT has an antenna of its own. The second-BT and external-coexistence columns stay clear because these designs have neither. This is driver-internal state only. The coex init information these chips send to firmware has no antenna-map field, so what reaches the firmware is unchanged. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-12-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8851b.c | 5 +++++ drivers/net/wireless/realtek/rtw89/rtw8852a.c | 5 +++++ drivers/net/wireless/realtek/rtw89/rtw8852b.c | 5 +++++ drivers/net/wireless/realtek/rtw89/rtw8852bt.c | 6 ++++++ drivers/net/wireless/realtek/rtw89/rtw8852c.c | 5 +++++ 5 files changed, 26 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851b.c b/drivers/net/wireless/realtek/rtw89/rtw8851b.c index db37ad6653bc..272f4f4e1fb9 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8851b.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8851b.c @@ -2119,6 +2119,7 @@ static u8 rtw8851b_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_p static void rtw8851b_btc_set_rfe(struct rtw89_dev *rtwdev) { struct rtw89_btc_module *md = &rtwdev->btc.mdinfo; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; md->rfe_type = rtwdev->efuse.rfe_type; md->kt_ver = rtwdev->hal.cv; @@ -2127,6 +2128,8 @@ static void rtw8851b_btc_set_rfe(struct rtw89_dev *rtwdev) md->ant.isolation = 10; md->kt_ver_adie = rtwdev->hal.acv; + memset(dm->ant_xmap, 0, sizeof(dm->ant_xmap)); + if (md->rfe_type == 0) return; @@ -2145,6 +2148,8 @@ static void rtw8851b_btc_set_rfe(struct rtw89_dev *rtwdev) md->bt0_pos = BTC_BT_BTG; md->wa_type = 1; md->ant.diversity = 0; + /* the only BT shares the BTG antenna with WL path A */ + dm->ant_xmap[BTC_RF_S0][BTC_BT_1ST] = 1; } else { /* ant.num == 2 */ md->ant.type = BTC_ANT_DEDICATED; md->bt0_pos = BTC_BT_ALONE; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852a.c b/drivers/net/wireless/realtek/rtw89/rtw8852a.c index 4b364f039464..5207df4f9cd5 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852a.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852a.c @@ -1836,6 +1836,7 @@ static u8 rtw8852a_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_p static void rtw8852a_btc_set_rfe(struct rtw89_dev *rtwdev) { struct rtw89_btc_module *md = &rtwdev->btc.mdinfo; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; md->rfe_type = rtwdev->efuse.rfe_type; md->kt_ver = rtwdev->hal.cv; @@ -1850,12 +1851,16 @@ static void rtw8852a_btc_set_rfe(struct rtw89_dev *rtwdev) md->ant.diversity = 0; md->ant.isolation = 10; + memset(dm->ant_xmap, 0, sizeof(dm->ant_xmap)); + if (md->ant.num == 3) { md->ant.type = BTC_ANT_DEDICATED; md->bt0_pos = BTC_BT_ALONE; } else { md->ant.type = BTC_ANT_SHARED; md->bt0_pos = BTC_BT_BTG; + /* the only BT shares the BTG antenna with WL path B */ + dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; } rtwdev->btc.btg_pos = md->ant.btg_pos; rtwdev->btc.ant_type = md->ant.type; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852b.c b/drivers/net/wireless/realtek/rtw89/rtw8852b.c index c3c53a6b8119..060c99532936 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852b.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852b.c @@ -748,6 +748,7 @@ static void rtw8852b_rfk_track(struct rtw89_dev *rtwdev) static void rtw8852b_btc_set_rfe(struct rtw89_dev *rtwdev) { struct rtw89_btc_module *md = &rtwdev->btc.mdinfo; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; md->rfe_type = rtwdev->efuse.rfe_type; md->kt_ver = rtwdev->hal.cv; @@ -762,12 +763,16 @@ static void rtw8852b_btc_set_rfe(struct rtw89_dev *rtwdev) md->ant.diversity = 0; md->ant.isolation = 10; + memset(dm->ant_xmap, 0, sizeof(dm->ant_xmap)); + if (md->ant.num == 3) { md->ant.type = BTC_ANT_DEDICATED; md->bt0_pos = BTC_BT_ALONE; } else { md->ant.type = BTC_ANT_SHARED; md->bt0_pos = BTC_BT_BTG; + /* the only BT shares the BTG antenna with WL path B */ + dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; } rtwdev->btc.btg_pos = md->ant.btg_pos; rtwdev->btc.ant_type = md->ant.type; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852bt.c b/drivers/net/wireless/realtek/rtw89/rtw8852bt.c index 3d93cee562c2..23ad02d1fcd4 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852bt.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852bt.c @@ -636,6 +636,7 @@ static void rtw8852bt_rfk_track(struct rtw89_dev *rtwdev) static void rtw8852bt_btc_set_rfe(struct rtw89_dev *rtwdev) { struct rtw89_btc_module *md = &rtwdev->btc.mdinfo; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; md->rfe_type = rtwdev->efuse.rfe_type; md->kt_ver = rtwdev->hal.cv; @@ -653,6 +654,10 @@ static void rtw8852bt_btc_set_rfe(struct rtw89_dev *rtwdev) md->ant.single_pos = RF_PATH_A; md->ant.btg_pos = RF_PATH_B; + memset(dm->ant_xmap, 0, sizeof(dm->ant_xmap)); + /* the only BT shares the BTG antenna with WL path B */ + dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; + if (md->rfe_type == 0) { rtwdev->btc.dm.error.map.rfe_type0 = true; return; @@ -669,6 +674,7 @@ static void rtw8852bt_btc_set_rfe(struct rtw89_dev *rtwdev) } else { md->ant.type = BTC_ANT_DEDICATED; md->bt0_pos = BTC_BT_ALONE; + dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 0; } } diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852c.c b/drivers/net/wireless/realtek/rtw89/rtw8852c.c index 624f23b3f2a1..e556ba0c14a7 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852c.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852c.c @@ -2609,6 +2609,7 @@ static u8 rtw8852c_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_p static void rtw8852c_btc_set_rfe(struct rtw89_dev *rtwdev) { struct rtw89_btc_module *md = &rtwdev->btc.mdinfo; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; md->rfe_type = rtwdev->efuse.rfe_type; md->kt_ver = rtwdev->hal.cv; @@ -2623,12 +2624,16 @@ static void rtw8852c_btc_set_rfe(struct rtw89_dev *rtwdev) md->ant.diversity = 0; md->ant.isolation = 10; + memset(dm->ant_xmap, 0, sizeof(dm->ant_xmap)); + if (md->ant.num == 3) { md->ant.type = BTC_ANT_DEDICATED; md->bt0_pos = BTC_BT_ALONE; } else { md->ant.type = BTC_ANT_SHARED; md->bt0_pos = BTC_BT_BTG; + /* the only BT shares the BTG antenna with WL path B */ + dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; } rtwdev->btc.btg_pos = md->ant.btg_pos; rtwdev->btc.ant_type = md->ant.type; From 236478d51ffceba4ad0f580fc97ffc3308cbe02d Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:17 +0800 Subject: [PATCH 1212/2126] wifi: rtw89: coex: use the right switch-type enum on RTL8922D Two unrelated enumerations describe a BT antenna switch type. The one the RTL8922D antenna configuration uses numbers the absent switch as zero and the internal switch as one, while the older one numbers the internal switch as zero. The shared 2-antenna case picked the internal value from the older enumeration, so it stored zero and claimed no switch at all. A BT whose switch type says there is no switch is treated as not sharing an antenna with the WL RF-path that the other RF-path shares with it, which drops the cross-talk entry for that path. Store the value from the enumeration this field is read with. The 1-antenna and 3-antenna cases in the same function already do. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-13-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 7ac15a5d949a..271a92123158 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -3305,7 +3305,7 @@ static void rtw8922d_btc_set_rfe(struct rtw89_dev *rtwdev) if (is_bt_share) { /* WL-S0 + (WL-S1 & BT0-S1) */ md->ant.type = BTC_ANT_SHARED; md->bt0_pos = BTC_BT_BTG; - md->bt0_sw_type = BTC_SWITCH_INTERNAL; + md->bt0_sw_type = BTC_SWITCH_V1_INTERNAL; dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; } else { /* WL-S0 + BT0-S1 */ md->ant.type = BTC_ANT_DEDICATED; From c739640e347f5e04ffb4452495db538621f3e744 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:18 +0800 Subject: [PATCH 1213/2126] wifi: rtw89: phy: Implement API to control BTG to turn on/off BT TX/RX The WiFi BE serials chips could disable BT TX/RX by BTG control, with this control logic, WiFi could lower down the interference signal from BT. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-14-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/fw.c | 2 ++ drivers/net/wireless/realtek/rtw89/phy.h | 12 ++++++++++++ drivers/net/wireless/realtek/rtw89/phy_be.c | 18 ++++++++++++++++++ drivers/net/wireless/realtek/rtw89/reg.h | 2 ++ 5 files changed, 35 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index b1f92c1d0428..d70123602801 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6120,6 +6120,7 @@ enum rtw89_fw_feature { RTW89_FW_FEATURE_LPS_ML_INFO_V1_EXTRA, RTW89_FW_FEATURE_SER_POST_RECOVER_DMAC, RTW89_FW_FEATURE_TX_HISTORY_V1, + RTW89_FW_FEATURE_NO_DRV_BT_TXRX_EN, NUM_OF_RTW89_FW_FEATURES, }; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index e9f6dc25b94c..ea7dba077f5d 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -1026,6 +1026,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = { __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 109, 1, SCAN_OFFLOAD_BE_V1), __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 113, 2, SCAN_OFFLOAD_BE_V2), __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 119, 0, CH_INFO_BE_V1), + __CFG_FW_FEAT(RTL8922A, lt, 0, 35, 119, 3, NO_DRV_BT_TXRX_EN), __CFG_FW_FEAT(RTL8922D, ge, 0, 0, 0, 0, MACID_PAUSE_SLEEP), __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 75, 2, SCAN_OFFLOAD), __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 75, 2, BEACON_FILTER), @@ -1044,6 +1045,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = { __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 113, 2, SCAN_OFFLOAD_BE_V2), __CFG_FW_FEAT(RTL8922D, ge, 0, 35, 119, 0, LPS_ML_INFO_V1_EXTRA), __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 119, 0, CH_INFO_BE_V1), + __CFG_FW_FEAT(RTL8922D, lt, 0, 35, 119, 3, NO_DRV_BT_TXRX_EN), }; static void rtw89_fw_iterate_feature_cfg(struct rtw89_fw_info *fw, diff --git a/drivers/net/wireless/realtek/rtw89/phy.h b/drivers/net/wireless/realtek/rtw89/phy.h index 7bbda2ba5b5c..84eb1defaaf2 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.h +++ b/drivers/net/wireless/realtek/rtw89/phy.h @@ -686,6 +686,7 @@ struct rtw89_phy_gen_def { void (*preinit_rf_nctl)(struct rtw89_dev *rtwdev); void (*bb_wrap_init)(struct rtw89_dev *rtwdev); void (*ch_info_init)(struct rtw89_dev *rtwdev); + int (*btc_bttrx_en)(struct rtw89_dev *rtwdev, u8 bt_en_int, bool enable); void (*set_txpwr_byrate)(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, @@ -1066,6 +1067,17 @@ static inline void rtw89_phy_ch_info_init(struct rtw89_dev *rtwdev) phy->ch_info_init(rtwdev); } +static inline +int rtw89_phy_btc_bttrx_en(struct rtw89_dev *rtwdev, u8 bt_en_int, bool enable) +{ + const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def; + + if (!phy->btc_bttrx_en) + return 0; + + return phy->btc_bttrx_en(rtwdev, bt_en_int, enable); +} + static inline void rtw89_phy_set_txpwr_byrate(struct rtw89_dev *rtwdev, const struct rtw89_chan *chan, diff --git a/drivers/net/wireless/realtek/rtw89/phy_be.c b/drivers/net/wireless/realtek/rtw89/phy_be.c index 73c98ae358ad..0571e18f69c8 100644 --- a/drivers/net/wireless/realtek/rtw89/phy_be.c +++ b/drivers/net/wireless/realtek/rtw89/phy_be.c @@ -1293,6 +1293,22 @@ static void rtw89_phy_ch_info_init_be_v1(struct rtw89_dev *rtwdev) rtw89_phy_set_phy_regs(rtwdev, R_CHINFO_ALG_BE4, B_CHINFO_ALG_BE4, 0); } +static int rtw89_phy_btc_bttrx_en_be(struct rtw89_dev *rtwdev, u8 bt_en_int, + bool enable) +{ + if (RTW89_CHK_FW_FEATURE(NO_DRV_BT_TXRX_EN, &rtwdev->fw)) + return 0; + + rtw89_io_pack(rtwdev); + + rtw89_write_rf(rtwdev, RF_PATH_A, RR_BTG_CONTROL, + RR_BTG_CONTROL_EN << bt_en_int, enable); + rtw89_write_rf(rtwdev, RF_PATH_B, RR_BTG_CONTROL, + RR_BTG_CONTROL_EN << bt_en_int, enable); + + return rtw89_io_unpack(rtwdev); +} + struct rtw89_byr_spec_ent_be { struct rtw89_rate_desc init; u8 num_of_idx; @@ -2035,6 +2051,7 @@ const struct rtw89_phy_gen_def rtw89_phy_gen_be = { .preinit_rf_nctl = rtw89_phy_preinit_rf_nctl_be, .bb_wrap_init = rtw89_phy_bb_wrap_init_be, .ch_info_init = rtw89_phy_ch_info_init_be, + .btc_bttrx_en = rtw89_phy_btc_bttrx_en_be, .set_txpwr_byrate = rtw89_phy_set_txpwr_byrate_be, .set_txpwr_offset = rtw89_phy_set_txpwr_offset_be, @@ -2061,6 +2078,7 @@ const struct rtw89_phy_gen_def rtw89_phy_gen_be_v1 = { .preinit_rf_nctl = rtw89_phy_preinit_rf_nctl_be_v1, .bb_wrap_init = rtw89_phy_bb_wrap_init_be, .ch_info_init = rtw89_phy_ch_info_init_be_v1, + .btc_bttrx_en = rtw89_phy_btc_bttrx_en_be, .set_txpwr_byrate = rtw89_phy_set_txpwr_byrate_be, .set_txpwr_offset = rtw89_phy_set_txpwr_offset_be, diff --git a/drivers/net/wireless/realtek/rtw89/reg.h b/drivers/net/wireless/realtek/rtw89/reg.h index 11b30be8f880..4829f9fd8eb5 100644 --- a/drivers/net/wireless/realtek/rtw89/reg.h +++ b/drivers/net/wireless/realtek/rtw89/reg.h @@ -8582,6 +8582,8 @@ #define RR_MODOPT_M_TXPWR GENMASK(5, 0) #define RR_WLSEL 0x02 #define RR_WLSEL_AG GENMASK(18, 16) +#define RR_BTG_CONTROL 0x4 +#define RR_BTG_CONTROL_EN BIT(2) #define RR_RSV1 0x05 #define RR_RSV1_RST BIT(0) #define RR_BBDC 0x10005 From 256725d0ec78caecd5df48b0aec956f592995d34 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:19 +0800 Subject: [PATCH 1214/2126] wifi: rtw89: coex: turn BT TX/RX on and off through the BTG control Nothing drives the BTG control that turns the BT TX/RX on and off, so the BT keeps transmitting and receiving even where COEX already knows it is not in use, and WL takes interference it does not have to. Program it from the BT enable state coex already maintains, which is the same value reported to the firmware, so a driver-side write and a firmware-side one always agree. This matters for the BT-only case, where that state is forced to enable both BT while the per-BT enable may still be clear. That report was not actually reaching the firmware. The control information is sent only when it differs from what was sent last, but the comparison is inverted, so an unchanged run sends a redundant command while a real change is dropped. Drop the inversion, so the state programmed here is the state the firmware is told about. Each BT keeps its own shadow of what was programmed and of whether that is trustworthy, rather than writing on a change of the enable state. A change is a one-shot edge, so an RF write the lower layer refuses would never be retried, and an offloaded write can be refused for reasons coex cannot see. The shadow is dropped on init and on a radio-state change since the RF may have been re-initialized, and compared on every run so that a redundant write is suppressed without losing the retry. Skip the whole thing while the RF is off, and on chips with a single BT, which do not drive this control from the driver side. Report the state and the shadow in the coex mechanism-status dump. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-15-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 81 +++++++++++++++++++++-- drivers/net/wireless/realtek/rtw89/core.h | 2 + 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index c25bc9e619ce..9107a6c8c6fc 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -8910,6 +8910,59 @@ static void _update_sdm_map(struct rtw89_dev *rtwdev) memcpy(dm->sit_xmap, map, sizeof(map)); } +static void _set_bttrx_en(struct rtw89_dev *rtwdev) +{ + struct rtw89_btc_wl_smap *wl_smap = &rtwdev->btc.cx.wl.status.map; + struct rtw89_btc_dm *dm = &rtwdev->btc.dm; + u8 state = dm->ost_info.bt_enable_state; + u8 i, want, done; + + /* only dual-BT chips drive the BT TX/RX enable from the driver */ + if (!(rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT)) + return; + + /* + * RF is not accessible, leave the shadow alone. Leaving this state is + * a radio-state run, which drops the shadow and re-programs below. + */ + if (wl_smap->rf_off || wl_smap->lps == BTC_LPS_RF_OFF) + return; + + /* + * RF may have been re-initialized, drop the shadow and re-program. + * Power-off is not listed, it is always followed by an init run + * before the next RF access. + */ + if (dm->run_reason == BTC_RSN_NTFY_INIT || + dm->run_reason == BTC_RSN_NTFY_RADIO_STATE) + dm->bttrx_en_ack = 0; + + for (i = BTC_BT_1ST; i <= BTC_BT_2ND; i++) { + want = !!(state & BIT(i)); + done = !!(dm->bttrx_en_done & BIT(i)); + + if (dm->bttrx_en_ack & BIT(i) && want == done) + continue; + + if (rtw89_phy_btc_bttrx_en(rtwdev, i, want)) { + /* leave the bit un-acked, the next run retries it */ + dm->bttrx_en_ack &= ~BIT(i); + + rtw89_debug(rtwdev, RTW89_DBG_BTC, + "[BTC], %s(): BT%d trx_en=%d write fail\n", + __func__, i, want); + continue; + } + + dm->bttrx_en_ack |= BIT(i); + + if (want) + dm->bttrx_en_done |= BIT(i); + else + dm->bttrx_en_done &= ~BIT(i); + } +} + #define _bind_is_btonly 0x7 static void _set_coex_binding(struct rtw89_dev *rtwdev) { @@ -8927,7 +8980,7 @@ static void _set_coex_binding(struct rtw89_dev *rtwdev) /* * sit_xmap(Space-Interaction) = ant_xmap | xtk_xmap * 1: WL-BT space-interference, always 1 if BTG/BTA/SPDT = 1 - * if dedicated-ant, it may be 1 if BT-Tx is bigger than WL-Rx(xtk_xmap) + * if dedicated-ant, it may be 1 if BT-TX is bigger than WL-Rx(xtk_xmap) * * ant_xmap(ANT-Division-Multiplexing) * ==> dedicated-ant->0, BTG/BTA/SPDT->1 @@ -8972,8 +9025,8 @@ static void _set_coex_binding(struct rtw89_dev *rtwdev) } /* - * WL 1SS MIMO-PS: WL Rx is confined to a single path, so the unused - * path has no WL-Rx frequency interference with any BT. + * WL 1SS MIMO-PS: WL RX is confined to a single path, so the unused + * path has no WL-RX frequency interference with any BT. * RF_PATH_AB -> not 1SS, both paths keep their real fit_xmap. * Same helper as _update_sdm_map(), so xtk_xmap and fit_map always * agree on which RF-path is the unused one. @@ -9028,15 +9081,23 @@ static void _set_coex_binding(struct rtw89_dev *rtwdev) /* set BT on/off state for GNT_WL Combined-MUX control */ if (bt0->enable.now) - val |= BIT(0); + val |= BIT(BTC_BT_1ST); if (bt1->enable.now) - val |= BIT(1); + val |= BIT(BTC_BT_2ND); if (bt2->func_type) - val |= BIT(2); + val |= BIT(BTC_BT_EXT); dm->ost_info.bt_enable_state = dm->bt_only ? _bind_is_btonly : val; + + /* + * Turn the BT TX/RX on/off by the BTG control in WL RF. Driven by + * bt_enable_state shadow instead of its change, so a write the RF + * layer rejects is retried in the next run. Call it every time, the + * shadow compare inside is what suppresses the redundant RF I/O. + */ + _set_bttrx_en(rtwdev); } static void _update_run_ctrl_info(struct rtw89_dev *rtwdev) @@ -9063,7 +9124,7 @@ static void _update_run_ctrl_info(struct rtw89_dev *rtwdev) wl_ctrl_info->rf_ch[i] = wl->rf_ch_info[i].center_ch; } - if (!memcmp(&btc->ctrl, &ctrl, sizeof(struct rtw89_btc_ctrl))) { + if (memcmp(&btc->ctrl, &ctrl, sizeof(struct rtw89_btc_ctrl))) { memcpy(&btc->ctrl, &ctrl, sizeof(struct rtw89_btc_ctrl)); if (btc->ver->fcxctrl >= 9) _fw_set_drv_info(rtwdev, CXDRVINFO_CTRL); @@ -11444,6 +11505,12 @@ static int _show_dm_info(struct rtw89_dev *rtwdev, char *buf, size_t bufsz) " %-15s : pre_agc:%d, btg_rx:%d\n", "[dm_bb_ctrl]", dm->wl_pre_agc, dm->wl_btg_rx); + if (rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT) + p += scnprintf(p, end - p, + " %-15s : bt_en_state:0x%x, shadow[done:0x%x/ack:0x%x]\n", + "[dm_bttrx_en]", dm->ost_info.bt_enable_state, + dm->bttrx_en_done, dm->bttrx_en_ack); + p += scnprintf(p, end - p, " %-15s : wl_tx_limit[en:%d/max_t:%dus/max_retry:%d], bt_slot_reg:%d-TU, bt_scan_rx_low_pri:%d\n", "[dm_ctrl]", dm->wl_tx_limit.enable, diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index d70123602801..a1e899576582 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -4188,6 +4188,8 @@ struct rtw89_btc_dm { u8 client_ps_tdma_on; u8 wl_trx_nss_en; u8 trx_nss_lps_done; /* 1SS re-setup done for this exit-LPS */ + u8 bttrx_en_done; /* BT TRX enable last programmed to RF */ + u8 bttrx_en_ack; /* which bttrx_en_done bits are trustworthy */ u8 wl_pre_agc: 2; u8 wl_lna2: 1; From 57dc6b251419a9bb57e4ef2a622bf8818fe22c4e Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Sun, 4 Oct 2026 11:45:20 +0800 Subject: [PATCH 1215/2126] wifi: rtw89: coex: set rf_combination in _update_wl_mlo_info() _update_wl_mlo_info() derives path_rf_band, link_mode, dbcc_en and other per-RF-path fields from the current MLO link_status, but never wrote mlo_info->rf_combination in any of the three link_status cases. The field stayed at its zero-initialized value, which aliases BTC_MLO_RF_2_PLUS_0. _set_bind_info() and _set_coex_binding() both branch on rf_combination to decide how to bind WL RF-paths to BT devices for 1+1, 2+2, 2+0 and 0+2 MLO combinations. With the field always zero, those branches silently treated every MLO combination as 2+0, producing an incorrect WL/BT binding whenever the real combination was 1+1, 2+2 or 0+2. Set rf_combination to the matching BTC_MLO_RF_* value in each of the 2+0, 0+2 and 1+1/2+2 branches so the binding logic sees the actual RF combination. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261004034520.33695-16-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 9107a6c8c6fc..e81581e6da5a 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -7806,6 +7806,7 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) rf_band = wl->rf_band_map[RTW89_PHY_0]; mlo_info->path_rf_band[BTC_RF_S0] = rf_band; mlo_info->path_rf_band[BTC_RF_S1] = rf_band; + mlo_info->rf_combination = BTC_MLO_RF_2_PLUS_0; break; case MLO_0_PLUS_2_1RF: /* 0+2 */ case MLO_0_PLUS_2_2RF: @@ -7818,6 +7819,7 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) rf_band = wl->rf_band_map[RTW89_PHY_1]; mlo_info->path_rf_band[BTC_RF_S0] = rf_band; mlo_info->path_rf_band[BTC_RF_S1] = rf_band; + mlo_info->rf_combination = BTC_MLO_RF_0_PLUS_2; break; case MLO_1_PLUS_1_1RF: /* 1+1 */ case MLO_1_PLUS_1_2RF: /* 1+1 */ @@ -7853,6 +7855,11 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band) } wl_rinfo->dbcc_en = 1; /* two HW-band both active */ + + if (mlo_info->link_status == MLO_2_PLUS_2_2RF) + mlo_info->rf_combination = BTC_MLO_RF_2_PLUS_2; + else + mlo_info->rf_combination = BTC_MLO_RF_1_PLUS_1; break; } From 48d051024430f77a47a7f6bca240782b6fc274c0 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Wed, 7 Oct 2026 15:59:58 +1100 Subject: [PATCH 1216/2126] wifi: mm81x: provide the station to mac80211 on rx Right now we look up the station on rx to update its average RSSI but then hand the frame to mac80211 without it, leaving mac80211 to look the station up again. Use ieee80211_rx_napi() and rework the code a bit so we pass the station directly to mac80211 to prevent another lookup. Link: https://patch.msgid.link/20261007050000.127009-2-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 34 ++++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 383f420b37ec..add2b44423c5 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -1932,22 +1932,13 @@ static void mm81x_rx_h_fill_status(struct mm81x *mors, rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; } -static void mm81x_rx_h_update_sta(struct ieee80211_vif *vif, - struct ieee80211_hdr *hdr, +static void mm81x_rx_h_update_sta(struct ieee80211_sta *sta, struct ieee80211_rx_status *rx_status) { - struct ieee80211_sta *sta; - struct mm81x_sta *msta; - u8 *lookup = ieee80211_is_s1g_beacon(hdr->frame_control) ? hdr->addr1 : - hdr->addr2; + struct mm81x_sta *msta = (void *)sta->drv_priv; lockdep_assert_in_rcu_read_lock(); - sta = ieee80211_find_sta(vif, lookup); - if (!sta) - return; - - msta = (void *)sta->drv_priv; if (msta->avg_rssi) { msta->avg_rssi = CALC_AVG_RSSI(msta->avg_rssi, rx_status->signal); @@ -1975,9 +1966,11 @@ void mm81x_mac_rx_skb(struct mm81x *mors, struct sk_buff *skb, struct mm81x_skb_rx_status *hdr_rx_status) { struct ieee80211_vif *vif; + struct ieee80211_sta *sta = NULL; struct ieee80211_hw *hw = mors->hw; struct ieee80211_rx_status rx_status; struct ieee80211_hdr *hdr = (void *)skb->data; + u8 *lookup; memset(&rx_status, 0, sizeof(rx_status)); @@ -1986,19 +1979,24 @@ void mm81x_mac_rx_skb(struct mm81x *mors, struct sk_buff *skb, return; } + lookup = ieee80211_is_s1g_beacon(hdr->frame_control) ? hdr->addr1 : + hdr->addr2; + mm81x_rx_h_fill_status(mors, hdr_rx_status, &rx_status, skb); + memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); scoped_guard(rcu) { vif = mm81x_rx_h_skb_get_vif(mors, skb, hdr_rx_status); - if (!vif) - goto rx; + if (vif) { + sta = ieee80211_find_sta(vif, lookup); + if (sta) + mm81x_rx_h_update_sta(sta, &rx_status); + } - mm81x_rx_h_update_sta(vif, hdr, &rx_status); + local_bh_disable(); + ieee80211_rx_napi(hw, sta ? &sta->deflink : NULL, skb, NULL); + local_bh_enable(); } - -rx: - memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); - ieee80211_rx_ni(hw, skb); } static void mm81x_mac_flush_queues(struct mm81x *mors) From 71a6d9ba64ddba00a241006b95d2d8e8dda15fd6 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Wed, 7 Oct 2026 15:59:59 +1100 Subject: [PATCH 1217/2126] wifi: mm81x: add monitor mode support Introduce monitor mode support by extending the command to add a monitor interface to the firmware and inserting the S1G radiotap TLV. Also rework the .configure_filter() callback to better handle frame filtering when we are in monitor mode. This implementation works best as a standalone sniffer currently, as support is yet to be added in mac80211 to handle building the radiotap for tx frames (i.e if you bind a monitor interface to an existing station or AP). Right now the S1G radiotap header is not really complete and lacks the ability to convey the frequency offset and correct NDP reporting. The process to amend the S1G TLV will begin after this initial support is complete. Link: https://patch.msgid.link/20261007050000.127009-3-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- .../net/wireless/morsemicro/mm81x/command.c | 5 +- drivers/net/wireless/morsemicro/mm81x/core.h | 16 +- drivers/net/wireless/morsemicro/mm81x/mac.c | 208 +++++++++++++++--- 3 files changed, 195 insertions(+), 34 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/command.c b/drivers/net/wireless/morsemicro/mm81x/command.c index afb7ee9bb236..56dd338321f0 100644 --- a/drivers/net/wireless/morsemicro/mm81x/command.c +++ b/drivers/net/wireless/morsemicro/mm81x/command.c @@ -262,6 +262,9 @@ int mm81x_cmd_add_if(struct mm81x *mors, u16 *vif_id, const u8 *addr, case NL80211_IFTYPE_AP: req.interface_type = cpu_to_le32(HOST_CMD_INTERFACE_TYPE_AP); break; + case NL80211_IFTYPE_MONITOR: + req.interface_type = cpu_to_le32(HOST_CMD_INTERFACE_TYPE_MON); + break; default: return -EOPNOTSUPP; } @@ -458,7 +461,7 @@ int mm81x_cmd_cfg_multicast_filter(struct mm81x *mors, struct mm81x_vif *mors_vif) { struct host_cmd_req_mcast_filter *req; - struct mcast_filter *filter = mors->mcast_filter; + struct mm81x_mcast_filter *filter = mors->mcast_filter; u16 filter_list_len = sizeof(filter->addr_list[0]) * filter->count; u16 alloc_len = filter_list_len + sizeof(*req); int ret = 0; diff --git a/drivers/net/wireless/morsemicro/mm81x/core.h b/drivers/net/wireless/morsemicro/mm81x/core.h index 75e998e8e324..d46323815304 100644 --- a/drivers/net/wireless/morsemicro/mm81x/core.h +++ b/drivers/net/wireless/morsemicro/mm81x/core.h @@ -225,7 +225,7 @@ struct mm81x_stale_tx_status { struct timer_list timer; }; -struct mcast_filter { +struct mm81x_mcast_filter { u8 count; /* * Integer representation of the last four bytes of a multicast MAC @@ -335,6 +335,18 @@ struct mm81x { struct ieee80211_vif __rcu *vifs[MM81X_MAX_IF]; + /* + * Groups A-MPDU subframes for monitor reporting. The firmware stamps + * every subframe of an A-MPDU with the same receive timestamp, so a + * change in timestamp starts a new reference. + */ + struct { + u64 timestamp; + u32 reference; + } rx_ampdu; + + bool monitor_en; + /* @mm81x_state_flags */ unsigned long state_flags; @@ -377,7 +389,7 @@ struct mm81x { wait_queue_head_t tx_empty_waitq; struct cfg80211_chan_def chandef; - struct mcast_filter *mcast_filter; + struct mm81x_mcast_filter *mcast_filter; atomic_t num_bcn_vifs; unsigned long beacon_irqs_enabled; u8 drv_priv[] __aligned(sizeof(void *)); diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index add2b44423c5..03c80ab999a1 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include "hif.h" @@ -1400,6 +1401,9 @@ static void mm81x_mac_ops_remove_interface(struct ieee80211_hw *hw, dev_err(mors->dev, "mm81x_cmd_rm_if failed %d", ret); RCU_INIT_POINTER(mors->vifs[mors_vif->id], NULL); + + if (vif->type == NL80211_IFTYPE_MONITOR) + __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, hw->flags); } static s32 mm81x_mac_get_max_txpower(struct mm81x *mors) @@ -1514,6 +1518,9 @@ static int mm81x_mac_ops_config(struct ieee80211_hw *hw, int radio_idx, return ret; } + if (changed & IEEE80211_CONF_CHANGE_MONITOR) + mors->monitor_en = conf->flags & IEEE80211_CONF_MONITOR; + if ((changed & IEEE80211_CONF_CHANGE_POWER) && !(changed & IEEE80211_CONF_CHANGE_CHANNEL) && !(conf->flags & IEEE80211_CONF_MONITOR)) { @@ -1605,7 +1612,7 @@ static u64 mm81x_mac_ops_prepare_multicast(struct ieee80211_hw *hw, struct netdev_hw_addr_list *mc_list) { struct mm81x *mors = hw->priv; - struct mcast_filter *filter; + struct mm81x_mcast_filter *filter; struct netdev_hw_addr *addr; u16 addr_count = netdev_hw_addr_list_count(mc_list); u16 len = sizeof(*filter) + addr_count * sizeof(filter->addr_list[0]); @@ -1632,17 +1639,38 @@ static u64 mm81x_mac_ops_prepare_multicast(struct ieee80211_hw *hw, return (u64)(unsigned long)filter; } +static void mm81x_mc_iface_iterator(void *data, u8 *mac, + struct ieee80211_vif *vif) +{ + struct mm81x_vif *mors_vif = ieee80211_vif_to_mors_vif(vif); + struct mm81x *mors = data; + int ret; + + if (vif->type == NL80211_IFTYPE_MONITOR) + return; + + ret = mm81x_cmd_cfg_multicast_filter(mors, mors_vif); + if (ret) + dev_err(mors->dev, "Multicast filtering failed - rc=%d", ret); +} + +#define MM81X_MONITOR_FILTERS \ + (FIF_ALLMULTI | \ + FIF_BCN_PRBRESP_PROMISC | \ + FIF_CONTROL | \ + FIF_FCSFAIL | \ + FIF_OTHER_BSS | \ + FIF_PSPOLL | \ + FIF_PROBE_REQ | \ + FIF_MCAST_ACTION) + static void mm81x_mac_ops_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, unsigned int *total_flags, u64 multicast) { + struct mm81x_mcast_filter *cmd = (void *)(unsigned long)multicast; struct mm81x *mors = hw->priv; - struct mcast_filter *cmd = (void *)(unsigned long)multicast; - struct mm81x_vif *mors_vif = NULL; - struct ieee80211_vif *vif = NULL; - int vif_id = 0; - int ret = 0; if (!cmd) goto out; @@ -1650,25 +1678,15 @@ static void mm81x_mac_ops_configure_filter(struct ieee80211_hw *hw, kfree(mors->mcast_filter); mors->mcast_filter = cmd; - for (vif_id = 0; vif_id < ARRAY_SIZE(mors->vifs); vif_id++) { - vif = mm81x_rcu_dereference_vif_id(mors, vif_id, false); - if (!vif) - continue; - - mors_vif = ieee80211_vif_to_mors_vif(vif); - - ret = mm81x_cmd_cfg_multicast_filter(mors, mors_vif); - if (!ret) - continue; - - dev_err(mors->dev, "Multicast filtering failed - rc=%d", ret); - mors->mcast_filter = NULL; - kfree(cmd); - break; - } + ieee80211_iterate_active_interfaces(mors->hw, + IEEE80211_IFACE_ITER_NORMAL, + mm81x_mc_iface_iterator, mors); out: - *total_flags &= 0; + if (mors->monitor_en) + *total_flags &= MM81X_MONITOR_FILTERS; + else + *total_flags = 0; } static int mm81x_mac_ops_conf_tx(struct ieee80211_hw *hw, @@ -1906,14 +1924,95 @@ static u8 mm81x_rx_h_rc_bw_to_rx_bw(__le32 ratecode) } } +static u32 mm81x_rx_h_ampdu_reference(struct mm81x *mors, u64 timestamp) +{ + if (timestamp != mors->rx_ampdu.timestamp) { + mors->rx_ampdu.timestamp = timestamp; + mors->rx_ampdu.reference++; + } + + return mors->rx_ampdu.reference; +} + +static enum ieee80211_radiotap_s1g_ppdu_format +mm81x_rx_h_ppdu_format(__le32 ratecode) +{ + switch (mm81x_ratecode_preamble_get(ratecode)) { + case MM81X_RATE_PREAMBLE_S1G_1M: + return IEEE80211_RADIOTAP_S1G_PPDU_FORMAT_1M; + case MM81X_RATE_PREAMBLE_S1G_LONG: + return IEEE80211_RADIOTAP_S1G_PPDU_FORMAT_LONG; + default: + return IEEE80211_RADIOTAP_S1G_PPDU_FORMAT_SHORT; + } +} + +#define S1G_RADIOTAP_TLV_LEN \ + (sizeof(struct ieee80211_radiotap_tlv) + \ + ALIGN(sizeof(struct ieee80211_radiotap_s1g), 4)) + +static void mm81x_rx_h_add_rt_s1g_tlv(struct sk_buff *skb, + struct mm81x_skb_rx_status *hdr_rx_status, + struct ieee80211_rx_status *rx_status) +{ + __le32 ratecode = hdr_rx_status->mm81x_ratecode; + u32 flags = le32_to_cpu(hdr_rx_status->flags); + u8 color = hdr_rx_status->bss_color; + struct ieee80211_radiotap_tlv *tlv; + struct ieee80211_radiotap_s1g s1g; + + if (skb_headroom(skb) < S1G_RADIOTAP_TLV_LEN) + return; + + s1g.known = cpu_to_le16(IEEE80211_RADIOTAP_S1G_KNOWN_PPDU_FORMAT | + IEEE80211_RADIOTAP_S1G_KNOWN_RESPONSE_IND | + IEEE80211_RADIOTAP_S1G_KNOWN_GI | + IEEE80211_RADIOTAP_S1G_KNOWN_BW | + IEEE80211_RADIOTAP_S1G_KNOWN_UPLINK_IND | + IEEE80211_RADIOTAP_S1G_KNOWN_NSS | + IEEE80211_RADIOTAP_S1G_KNOWN_MCS | + IEEE80211_RADIOTAP_S1G_KNOWN_COLOR); + + s1g.data1 = le16_encode_bits(mm81x_rx_h_ppdu_format(ratecode), + IEEE80211_RADIOTAP_S1G_DATA1_PPDU_FORMAT) | + le16_encode_bits(MM81X_RX_STATUS_FLAGS_RI_GET(flags), + IEEE80211_RADIOTAP_S1G_DATA1_RESPONSE_IND) | + le16_encode_bits(mm81x_ratecode_sgi_get(ratecode), + IEEE80211_RADIOTAP_S1G_DATA1_GI) | + le16_encode_bits(mm81x_ratecode_nss_index_get(ratecode), + IEEE80211_RADIOTAP_S1G_DATA1_NSS) | + le16_encode_bits(mm81x_ratecode_bw_index_get(ratecode), + IEEE80211_RADIOTAP_S1G_DATA1_BW) | + le16_encode_bits(mm81x_ratecode_mcs_index_get(ratecode), + IEEE80211_RADIOTAP_S1G_DATA1_MCS); + + s1g.data2 = le16_encode_bits(color, IEEE80211_RADIOTAP_S1G_DATA2_COLOR) | + le16_encode_bits(MM81X_RX_STATUS_FLAGS_UPL_IND_GET(flags), + IEEE80211_RADIOTAP_S1G_DATA2_UPLINK_IND) | + le16_encode_bits((u8)rx_status->signal, + IEEE80211_RADIOTAP_S1G_DATA2_RSSI); + + tlv = skb_push(skb, S1G_RADIOTAP_TLV_LEN); + tlv->type = cpu_to_le16(IEEE80211_RADIOTAP_S1G); + tlv->len = cpu_to_le16(sizeof(s1g)); + + memcpy(tlv->data, &s1g, sizeof(s1g)); + memset(tlv->data + sizeof(s1g), 0, + S1G_RADIOTAP_TLV_LEN - sizeof(*tlv) - sizeof(s1g)); + + skb_set_mac_header(skb, S1G_RADIOTAP_TLV_LEN); + rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END; +} + static void mm81x_rx_h_fill_status(struct mm81x *mors, struct mm81x_skb_rx_status *hdr_rx_status, struct ieee80211_rx_status *rx_status, struct sk_buff *skb) { - u32 flags = le32_to_cpu(hdr_rx_status->flags); + u64 timestamp = le64_to_cpu(hdr_rx_status->rx_timestamp_us); u16 freq_100khz = le16_to_cpu(hdr_rx_status->freq_100khz); __le32 ratecode = hdr_rx_status->mm81x_ratecode; + u32 flags = le32_to_cpu(hdr_rx_status->flags); rx_status->signal = le16_to_cpu(hdr_rx_status->rssi); rx_status->encoding = RX_ENC_S1G; @@ -1921,15 +2020,51 @@ static void mm81x_rx_h_fill_status(struct mm81x *mors, rx_status->freq = KHZ100_TO_MHZ(freq_100khz); rx_status->freq_offset = (freq_100khz % 10) ? 1 : 0; rx_status->nss = NSS_IDX_TO_NSS(mm81x_ratecode_nss_index_get(ratecode)); + rx_status->rate_idx = mm81x_ratecode_mcs_index_get(ratecode); + rx_status->bw = mm81x_rx_h_rc_bw_to_rx_bw(ratecode); + rx_status->mactime = timestamp; + rx_status->flag |= RX_FLAG_MACTIME_IS_RTAP_TS64; if (flags & MM81X_RX_STATUS_FLAGS_DECRYPTED) rx_status->flag |= RX_FLAG_DECRYPTED; - rx_status->rate_idx = mm81x_ratecode_mcs_index_get(ratecode); - rx_status->bw = mm81x_rx_h_rc_bw_to_rx_bw(ratecode); - if (mm81x_ratecode_sgi_get(ratecode)) rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; + + if (mors->monitor_en) { + if (flags & MM81X_RX_STATUS_FLAGS_CRC_ERROR) + rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; + + if (flags & MM81X_RX_STATUS_FLAGS_AMPDU) { + rx_status->flag |= RX_FLAG_AMPDU_DETAILS | + RX_FLAG_AMPDU_EOF_BIT_KNOWN; + rx_status->ampdu_reference = + mm81x_rx_h_ampdu_reference(mors, timestamp); + + if (flags & MM81X_RX_STATUS_FLAGS_EOF) + rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; + } + + if (flags & MM81X_RX_STATUS_FLAGS_NDP) { + rx_status->flag |= RX_FLAG_NO_PSDU; + + /* + * S1G PSDUs are not standardised in radiotap yet, so + * for now report as sounding PSDUs so that acks etc. + * can be passed through. + */ + rx_status->zero_length_psdu_type = + IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING; + + /* + * Null Data Packets contain no data, therefore no + * mcs encoding. The STF/LTF are usually BPSK, therefore + * the NDP mcs rate can always be considered as 0. + */ + rx_status->rate_idx = 0; + rx_status->nss = 1; + } + } } static void mm81x_rx_h_update_sta(struct ieee80211_sta *sta, @@ -1983,7 +2118,6 @@ void mm81x_mac_rx_skb(struct mm81x *mors, struct sk_buff *skb, hdr->addr2; mm81x_rx_h_fill_status(mors, hdr_rx_status, &rx_status, skb); - memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); scoped_guard(rcu) { vif = mm81x_rx_h_skb_get_vif(mors, skb, hdr_rx_status); @@ -1993,6 +2127,11 @@ void mm81x_mac_rx_skb(struct mm81x *mors, struct sk_buff *skb, mm81x_rx_h_update_sta(sta, &rx_status); } + if (mors->monitor_en) + mm81x_rx_h_add_rt_s1g_tlv(skb, hdr_rx_status, &rx_status); + + memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); + local_bh_disable(); ieee80211_rx_napi(hw, sta ? &sta->deflink : NULL, skb, NULL); local_bh_enable(); @@ -2263,9 +2402,6 @@ static int mm81x_mac_ops_add_interface(struct ieee80211_hw *hw, rcu_assign_pointer(mors->vifs[mors_vif->id], vif); - if (vif->type == NL80211_IFTYPE_AP) - INIT_WORK(&mors_vif->u.ap.beacon_work, mm81x_mac_beacon_work); - ret = mm81x_cmd_get_capabilities(mors, mors_vif->id, &mors->fw_caps); if (ret) { dev_err(mors->dev, @@ -2274,6 +2410,12 @@ static int mm81x_mac_ops_add_interface(struct ieee80211_hw *hw, return ret; } + if (vif->type == NL80211_IFTYPE_MONITOR) + ieee80211_hw_set(hw, RX_INCLUDES_FCS); + + if (vif->type == NL80211_IFTYPE_AP) + INIT_WORK(&mors_vif->u.ap.beacon_work, mm81x_mac_beacon_work); + ieee80211_wake_queues(mors->hw); return ret; } @@ -2347,6 +2489,9 @@ static void mm81x_mac_config_hw(struct mm81x *mors) hw->sta_data_size = sizeof(struct mm81x_sta); hw->extra_tx_headroom = sizeof(struct mm81x_skb_hdr) + mm81x_bus_get_alignment(mors); + hw->radiotap_timestamp.units_pos = + IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | + IEEE80211_RADIOTAP_TIMESTAMP_SPOS_BEGIN_MDPU; mors->wiphy = hw->wiphy; @@ -2361,6 +2506,7 @@ static void mm81x_mac_config_hw(struct mm81x *mors) ieee80211_hw_set(hw, PS_NULLFUNC_STACK); ieee80211_hw_set(hw, SUPPORTS_TX_FRAG); ieee80211_hw_set(hw, SUPPORTS_NDP_BLOCKACK); + ieee80211_hw_set(hw, WANT_MONITOR_VIF); SET_IEEE80211_PERM_ADDR(hw, mors->macaddr); From 4ec869de9c62ff34db1a31fca84c096961175035 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Wed, 7 Oct 2026 16:00:00 +1100 Subject: [PATCH 1218/2126] wifi: mm81x: copy new sband for each module the sband information existed as a single static struct and was directly modified in place by both the stack and the driver. If the regdom was ever changed to 00 where all the S1G channels are NO_IR and a bus module then removed, these flags would remain even after changing the regdom and prevent channels from being used. Instead, make sure we copy the sband each time we init our mac80211 hw such that when a bus module is removed the state is reset and flags don't persist. Link: https://patch.msgid.link/20261007050000.127009-4-lachlan.hodges@morsemicro.com Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/mac.c | 47 ++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 03c80ab999a1..6f1feb24fe6a 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -84,7 +84,7 @@ .max_power = 30, \ } -static struct ieee80211_channel mors_s1ghz_channels[] = { +static const struct ieee80211_channel mors_s1ghz_channels[] = { CHANS1G(1, 902, 500, IEEE80211_CHAN_S1G_NO_PRIMARY), CHANS1G(3, 903, 500, 0), CHANS1G(5, 904, 500, 0), @@ -115,11 +115,9 @@ static struct ieee80211_channel mors_s1ghz_channels[] = { /* clang-format on */ -static struct ieee80211_supported_band mors_band_s1ghz = { +static const struct ieee80211_supported_band mors_band_s1ghz = { .band = NL80211_BAND_S1GHZ, .s1g_cap.s1g = true, - .channels = mors_s1ghz_channels, - .n_channels = ARRAY_SIZE(mors_s1ghz_channels), .bitrates = NULL, .n_bitrates = 0, .s1g_cap.cap[4] = 0x80 /* STA type sensor only for AP & STA */ @@ -269,8 +267,10 @@ static void mm81x_mac_check_fw_disabled_chans(struct ieee80211_hw *hw) u32 i; struct mm81x *mors = hw->priv; struct host_cmd_resp_get_disabled_channels *resp; + struct ieee80211_supported_band *sband = + hw->wiphy->bands[NL80211_BAND_S1GHZ]; u32 resp_len = sizeof(struct host_cmd_disabled_channel_entry) * - ARRAY_SIZE(mors_s1ghz_channels) + + sband->n_channels + sizeof(*resp); resp = kzalloc(resp_len, GFP_KERNEL); @@ -283,13 +283,13 @@ static void mm81x_mac_check_fw_disabled_chans(struct ieee80211_hw *hw) if (ret) goto out; - if (le32_to_cpu(resp->n_channels) > ARRAY_SIZE(mors_s1ghz_channels)) { + if (le32_to_cpu(resp->n_channels) > sband->n_channels) { ret = -EINVAL; goto out; } - for (i = 0; i < ARRAY_SIZE(mors_s1ghz_channels); i++) { - struct ieee80211_channel *ch = &mors_s1ghz_channels[i]; + for (i = 0; i < sband->n_channels; i++) { + struct ieee80211_channel *ch = &sband->channels[i]; if (ch->flags & IEEE80211_CHAN_DISABLED) continue; @@ -342,7 +342,8 @@ static int mm81x_tx_h_get_max_tx_bw(struct mm81x *mors) static void mm81x_mac_caps_init(struct mm81x *mors) { struct mm81x_fw_caps *fw_caps = &mors->fw_caps; - struct ieee80211_sta_s1g_cap *s1g = &mors_band_s1ghz.s1g_cap; + struct ieee80211_sta_s1g_cap *s1g = + &mors->hw->wiphy->bands[NL80211_BAND_S1GHZ]->s1g_cap; #define __FW_CAP_N(_n, _cap, _bit) \ do { \ @@ -2476,7 +2477,6 @@ static void mm81x_mac_config_hw(struct mm81x *mors) for (i = 0; i < NUM_NL80211_BANDS; i++) hw->wiphy->bands[i] = NULL; - hw->wiphy->bands[NL80211_BAND_S1GHZ] = &mors_band_s1ghz; hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_STATION); hw->wiphy->reg_notifier = mm81x_reg_notifier; @@ -2554,6 +2554,28 @@ static void mm81x_mac_stale_tx_status_timer_init(struct mm81x *mors) timer_setup(&mors->stale_status.timer, mm81x_stale_tx_status_timer, 0); } +static int mm81x_mac_set_sband(struct mm81x *mors) +{ + struct ieee80211_supported_band *sband; + + sband = devm_kmemdup(mors->dev, &mors_band_s1ghz, sizeof(*sband), + GFP_KERNEL); + if (!sband) + return -ENOMEM; + + sband->channels = devm_kmemdup_array(mors->dev, mors_s1ghz_channels, + ARRAY_SIZE(mors_s1ghz_channels), + sizeof(*mors_s1ghz_channels), + GFP_KERNEL); + if (!sband->channels) + return -ENOMEM; + + sband->n_channels = ARRAY_SIZE(mors_s1ghz_channels); + mors->hw->wiphy->bands[NL80211_BAND_S1GHZ] = sband; + + return 0; +} + int mm81x_mac_register(struct mm81x *mors) { int ret; @@ -2568,6 +2590,11 @@ int mm81x_mac_register(struct mm81x *mors) return ret; mm81x_mac_config_hw(mors); + + ret = mm81x_mac_set_sband(mors); + if (ret) + return ret; + mm81x_mac_hw_scan_init(mors); mm81x_mac_stale_tx_status_timer_init(mors); From 00c3f77b0ca47d338b19b762f61e682e408b4c82 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Aug 2026 12:58:21 +0000 Subject: [PATCH 1219/2126] wifi: mt76: mt7996: program a link again if the driver holds it The firmware needs the driver to remove active links from the BSSINFO table when it destroys the interface. A link therefore stays registered from its first chanctx assignment until the interface goes away. If the driver holds the link already, a second add does nothing. mac80211 gives a non-AP MLD a new address each time it sets a link up. A link that comes back after a failed attempt thus carries an address that the hardware does not know, on a BSS that the driver never programs again. The station then authenticates from an address that nothing answers. The failure repeats until the driver tears the interface down for good. Program the address and the BSS again. This is the pair that the initial add sets up. For a station it does what mt7996_mcu_mld_link_oper() does for an AP. Fixes: 08813703ac41 ("wifi: mt76: mt7996: Destroy vif active links in mt7996_remove_interface()") Link: https://patch.msgid.link/20260818125825.395538-1-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index e218856b0c45..d17d1dbb2038 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -310,7 +310,14 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, if (vif->type == NL80211_IFTYPE_AP) return mt7996_mcu_mld_link_oper(dev, link_conf, link, true); - return 0; + + /* update the link address */ + ret = mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, true); + if (ret) + return ret; + + return mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, + msta_link, true); } mlink->idx = __ffs64(~dev->mt76.vif_mask); From d6173b8b36e5cefc7cce34c31a0cc63fb3bd77f4 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Aug 2026 12:58:22 +0000 Subject: [PATCH 1220/2126] wifi: mt76: check the owner of a remain-on-channel request mvif->roc_phy points to the phy of the request that started last for the interface. That request can end, and the phy can start a request for a different interface. The driver does not always clear the pointer. Two callers trust the pointer: - mt76_vif_cleanup() aborts the request on that phy when the driver removes the interface. - mt76_cancel_remain_on_channel() aborts the request on that phy for the interface. If the phy holds a request for a different interface, both callers abort the wrong request. The request of the interface stays active. Its work then runs after the driver removes the interface. The work tears the link down through the freed bss_conf. Compare phy->roc_vif with the interface in both callers before the abort. Fixes: a8f424c1287c ("wifi: mt76: add multi-radio remain_on_channel functions") Link: https://patch.msgid.link/20260818125825.395538-2-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 2 +- drivers/net/wireless/mediatek/mt76/mac80211.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 28ad7bcaffd4..1d2635672ac3 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -423,7 +423,7 @@ int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw, struct mt76_vif_data *mvif = mlink->mvif; struct mt76_phy *phy = mvif->roc_phy; - if (!phy) + if (!phy || phy->roc_vif != vif) return 0; mt76_abort_roc(phy); diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index cda5c5d51aab..9dd93f90de40 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -2110,7 +2110,7 @@ void mt76_vif_cleanup(struct mt76_dev *dev, struct ieee80211_vif *vif) rcu_assign_pointer(mvif->link[0], NULL); mt76_abort_scan(dev); - if (mvif->roc_phy) + if (mvif->roc_phy && mvif->roc_phy->roc_vif == vif) mt76_abort_roc(mvif->roc_phy); } EXPORT_SYMBOL_GPL(mt76_vif_cleanup); From 5bb4c6967b40506d8c8e0c05d42f250997e75fde Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Aug 2026 12:58:23 +0000 Subject: [PATCH 1221/2126] wifi: mt76: mt7996: take over connection monitoring mt76 runs its own beacon monitor. mt76_beacon_mon_check() counts a miss for each affiliated link of an MLD, and it stops the count while the phy is off channel. mt7996 supplies it through mt76_rx_beacon(), but it does not set CONNECTION_MONITOR. Therefore mac80211 also starts its legacy monitor. The legacy monitor knows one interface, not a set of links. It also counts while the radio serves a different link. After seven beacon intervals it removes an association that still carries traffic on the other links. Set the CONNECTION_MONITOR flag to disable the legacy monitor. Fixes: 4df75606ece5 ("wifi: mt76: add per-link beacon monitoring for MLO") Link: https://patch.msgid.link/20260818125825.395538-3-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index fb635a092584..2db63c3be9d1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -540,6 +540,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed) ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); ieee80211_hw_set(hw, CHANCTX_STA_CSA); + ieee80211_hw_set(hw, CONNECTION_MONITOR); hw->max_tx_fragments = 4; wiphy->txq_memory_limit = 32 << 20; /* 32 MiB */ From 3aaa4871006d2abb3a597028c45042311acbc640 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Aug 2026 12:58:24 +0000 Subject: [PATCH 1222/2126] wifi: mt76: clear offchannel state if a scan has no channel to restore mt76_scan_complete() restores the operating channel only if the phy has one. __mt76_set_channel() is the only function that clears phy->offchannel. A phy can run a scan while it has no operating channel. A 6 GHz radio with no configured interface is one example. After such a scan, the flag stays set. mt76_txq_schedule_list() skips each TXQ whose wcid points to a phy in this state. All traffic for the stations on that band stops. The frames stay in the mac80211 queues. They do not reach the hardware, and no counter shows them. Only an unrelated channel set clears the flag. Fixes: 31083e38548f ("wifi: mt76: add code for emulating hardware scanning") Fixes: a8f424c1287c ("wifi: mt76: add multi-radio remain_on_channel functions") Link: https://patch.msgid.link/20260818125825.395538-4-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 2 ++ drivers/net/wireless/mediatek/mt76/scan.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 1d2635672ac3..903f3a420e4c 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -330,6 +330,8 @@ void mt76_roc_complete(struct mt76_phy *phy) !test_bit(MT76_MCU_RESET, &dev->phy.state)) { __mt76_set_channel(phy, &phy->main_chandef, false); mt76_offchannel_notify(phy, false); + } else { + phy->offchannel = false; } mt76_put_vif_phy_link(phy, phy->roc_vif, phy->roc_link); phy->roc_vif = NULL; diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c index 3594b599662d..c8c4d096c809 100644 --- a/drivers/net/wireless/mediatek/mt76/scan.c +++ b/drivers/net/wireless/mediatek/mt76/scan.c @@ -29,6 +29,13 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort) __mt76_set_channel(phy, &phy->main_chandef, false); if (offchannel) mt76_offchannel_notify(phy, false); + } else { + /* A phy that has no operating channel has nothing to restore, + * but the flag also gates the TX queues of every station whose + * wcid points at this band, so leaving it set stalls them until + * something else happens to set a channel. + */ + phy->offchannel = false; } mt76_put_vif_phy_link(phy, dev->scan.vif, dev->scan.mlink); memset(&dev->scan, 0, sizeof(dev->scan)); From 8834613dba564fda431eb87c1375e749490c2518 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Aug 2026 12:58:25 +0000 Subject: [PATCH 1223/2126] wifi: mt76: account non-AQL frames per peer rather than per link The driver increments wcid->non_aql_packets when a frame goes to the hardware queue. The completion path decrements the counter again. For an MLO peer, the hardware reports the completion on the link that it used for the transmission. This link can differ from the link that the driver queued the frame on. In that case, the increment and the decrement go to different link wcids, and the count drifts upwards until it blocks the station. Keep the count on the wcid of the primary link, like the other peer-wide state. Fixes: 86c051f2c418 ("wifi: mt76: mt7925: enabling MLO when the firmware supports it") Link: https://patch.msgid.link/20260818125825.395538-5-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt76.h | 7 +++++++ drivers/net/wireless/mediatek/mt76/tx.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 62b41c8bb7c0..2ade848fe3bb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -1426,6 +1426,13 @@ mtxq_to_txq(struct mt76_txq *mtxq) return container_of(ptr, struct ieee80211_txq, drv_priv); } +/* peer-wide state uses the wcid of the primary link */ +static inline struct mt76_wcid * +mt76_wcid_primary(struct mt76_wcid *wcid) +{ + return wcid->def_wcid ? wcid->def_wcid : wcid; +} + static inline struct ieee80211_sta * wcid_to_sta(struct mt76_wcid *wcid) { diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c index 3707ee19e4ae..b1e894b19cbd 100644 --- a/drivers/net/wireless/mediatek/mt76/tx.c +++ b/drivers/net/wireless/mediatek/mt76/tx.c @@ -234,6 +234,8 @@ mt76_tx_check_non_aql(struct mt76_dev *dev, struct mt76_wcid *wcid, if (!wcid || info->tx_time_est) return; + wcid = mt76_wcid_primary(wcid); + pending = atomic_dec_return(&wcid->non_aql_packets); if (pending < 0) atomic_cmpxchg(&wcid->non_aql_packets, pending, 0); @@ -344,7 +346,8 @@ __mt76_tx_queue_skb(struct mt76_phy *phy, int qid, struct sk_buff *skb, if (!non_aql) return idx; - pending = atomic_inc_return(&wcid->non_aql_packets); + /* the hardware can report the completion on a different link */ + pending = atomic_inc_return(&mt76_wcid_primary(wcid)->non_aql_packets); if (stop && pending >= MT_MAX_NON_AQL_PKT) *stop = true; @@ -506,7 +509,8 @@ mt76_txq_send_burst(struct mt76_phy *phy, struct mt76_queue *q, return 0; } - if (atomic_read(&wcid->non_aql_packets) >= MT_MAX_NON_AQL_PKT) + if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >= + MT_MAX_NON_AQL_PKT) return 0; skb = mt76_txq_dequeue(phy, mtxq); @@ -603,7 +607,8 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid) continue; } - if (atomic_read(&wcid->non_aql_packets) >= MT_MAX_NON_AQL_PKT) + if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >= + MT_MAX_NON_AQL_PKT) continue; if (dev->queue_ops->tx_cleanup && q->queued + 2 * MT_TXQ_FREE_THR >= q->ndesc) { From bce4aef211b3941af9ca297162406fc84f22ed5d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 2 Jul 2026 15:09:01 +0000 Subject: [PATCH 1224/2126] wifi: mt76: mt7915: check default EEPROM firmware size before copying mt7915_eeprom_load_default() copied mt7915_eeprom_size() bytes from the firmware blob after only checking that it was non-NULL. A truncated default bin caused an out-of-bounds read past the firmware buffer into the EEPROM image. Reject a blob smaller than the EEPROM size. Fixes: beed8bea8d74 ("mt76: mt7915: add mt7916 calibrated data support") Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c index fe7b29ebc0bf..145d14a1012d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c @@ -111,6 +111,12 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) goto out; } + if (fw->size < mt7915_eeprom_size(dev)) { + dev_err(dev->mt76.dev, "Invalid default bin size\n"); + ret = -EINVAL; + goto out; + } + memcpy(eeprom, fw->data, mt7915_eeprom_size(dev)); dev->flash_mode = true; From c88f880c6430948492a4eee00d90e48fa800febf Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 2 Jul 2026 15:14:11 +0000 Subject: [PATCH 1225/2126] wifi: mt76: mt7996: validate firmware event lengths before parsing Two unsolicited event handlers trusted firmware-provided lengths: mt7996_mcu_rx_all_sta_info_event() looped over res->sta_num without checking it against skb->len, reading the flex array out of bounds; and mt7996_mcu_rx_log_message() could compute a negative or oversized length from tlv->len and feed it to %.*s and the debugfs log path. Bound both against the actual skb length. Fixes: adde3eed4a75 ("wifi: mt76: mt7996: Add mcu commands for getting sta tx statistic") Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c index cd7587ce5b8a..6acb8897feb8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c @@ -572,21 +572,32 @@ mt7996_mcu_rx_log_message(struct mt7996_dev *dev, struct sk_buff *skb) { #define UNI_EVENT_FW_LOG_FORMAT 0 struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; - const char *data = (char *)&rxd[1] + 4, *type; - struct tlv *tlv = (struct tlv *)data; + const char *data, *type; + struct tlv *tlv; int len; + if (skb->len < sizeof(*rxd)) + return; + if (!(rxd->option & MCU_UNI_CMD_EVENT)) { - len = skb->len - sizeof(*rxd); data = (char *)&rxd[1]; + len = skb->len - sizeof(*rxd); goto out; } + if (skb->len < sizeof(*rxd) + 4 + sizeof(*tlv)) + return; + + tlv = (struct tlv *)((char *)&rxd[1] + 4); if (le16_to_cpu(tlv->tag) != UNI_EVENT_FW_LOG_FORMAT) return; - data += sizeof(*tlv) + 4; + if (le16_to_cpu(tlv->len) < sizeof(*tlv) + 4) + return; + + data = (char *)tlv + sizeof(*tlv) + 4; len = le16_to_cpu(tlv->len) - sizeof(*tlv) - 4; + len = min_t(int, len, skb->len - (int)(data - (char *)skb->data)); out: switch (rxd->s2d_index) { @@ -648,13 +659,38 @@ static void mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb) { struct mt7996_mcu_all_sta_info_event *res; + u32 elem_size; + u16 sta_num; u16 i; + if (skb->len < sizeof(struct mt7996_mcu_rxd)) + return; + skb_pull(skb, sizeof(struct mt7996_mcu_rxd)); res = (struct mt7996_mcu_all_sta_info_event *)skb->data; + if (skb->len < sizeof(*res)) + return; - for (i = 0; i < le16_to_cpu(res->sta_num); i++) { + sta_num = le16_to_cpu(res->sta_num); + switch (le16_to_cpu(res->tag)) { + case UNI_ALL_STA_TXRX_RATE: + elem_size = sizeof(res->rate[0]); + break; + case UNI_ALL_STA_TXRX_ADM_STAT: + elem_size = sizeof(res->adm_stat[0]); + break; + case UNI_ALL_STA_TXRX_MSDU_COUNT: + elem_size = sizeof(res->msdu_cnt[0]); + break; + default: + return; + } + + if (sta_num > (skb->len - sizeof(*res)) / elem_size) + sta_num = (skb->len - sizeof(*res)) / elem_size; + + for (i = 0; i < sta_num; i++) { u8 ac; u16 wlan_idx; struct mt76_wcid *wcid; From b8286bc7fe520e7117e7b6e1a1fd4c0df439aa3a Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 2 Jul 2026 15:21:12 +0000 Subject: [PATCH 1226/2126] wifi: mt76: mt7915: unregister thermal cooling device on hwmon failure mt7915_thermal_init() registered the thermal cooling device and its sysfs link, then returned the hwmon registration error without undoing them. The cooling device (not devm-managed) and the link then leaked, and its callbacks referenced the freed phy. Unregister the cooling device before returning the error. Fixes: 0ae3ff568451 ("mt76: mt7915: fix hwmon temp sensor mem use-after-free") Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c index ca46a203aa48..aeefd323c10e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c @@ -248,7 +248,12 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, phy, mt7915_hwmon_groups); - return PTR_ERR_OR_ZERO(hwmon); + if (IS_ERR(hwmon)) { + mt7915_unregister_thermal(phy); + return PTR_ERR(hwmon); + } + + return 0; } static void mt7915_led_set_config(struct led_classdev *led_cdev, From decf5142c2d4c295684da8644d4cb93dcf956c5d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 2 Jul 2026 15:51:53 +0000 Subject: [PATCH 1227/2126] wifi: mt76: mt7915: guard firmware memory dump write on disabled memdump mt7915_coredump_build()/mt7996_coredump_build() wrote dump_mem->len unconditionally, but the allocation only reserves room for the memory dump header when coredump_memdump is enabled and memdump_buf_len is non-zero. In the default configuration the allocation ends right after the fixed header, so the write landed one struct past the buffer. Only populate the memory-dump section when it was actually allocated. Fixes: 4dbcb9125cc3 ("wifi: mt76: mt7915: enable coredump support") Fixes: 878161d5d4a4 ("wifi: mt76: mt7996: enable coredump support") Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7915/coredump.c | 7 ++++--- drivers/net/wireless/mediatek/mt76/mt7996/coredump.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/coredump.c b/drivers/net/wireless/mediatek/mt76/mt7915/coredump.c index 6c7273e5b0bc..db079b274a93 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/coredump.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/coredump.c @@ -345,11 +345,12 @@ static struct mt7915_coredump *mt7915_coredump_build(struct mt7915_dev *dev) mt7915_coredump_fw_stack(dev, dump, exception); /* gather memory content */ - dump_mem = (struct mt7915_coredump_mem *)(buf + sofar); - dump_mem->len = crash_data->memdump_buf_len; - if (coredump_memdump && crash_data->memdump_buf_len) + if (coredump_memdump && crash_data->memdump_buf_len) { + dump_mem = (struct mt7915_coredump_mem *)(buf + sofar); + dump_mem->len = crash_data->memdump_buf_len; memcpy(dump_mem->data, crash_data->memdump_buf, crash_data->memdump_buf_len); + } mutex_unlock(&dev->dump_mutex); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/coredump.c b/drivers/net/wireless/mediatek/mt76/mt7996/coredump.c index 5c293ae965cd..be4c882b3184 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/coredump.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/coredump.c @@ -202,11 +202,12 @@ static struct mt7996_coredump *mt7996_coredump_build(struct mt7996_dev *dev) mt7996_coredump_fw_stack(dev, dump, exception); /* gather memory content */ - dump_mem = (struct mt7996_coredump_mem *)(buf + sofar); - dump_mem->len = crash_data->memdump_buf_len; - if (coredump_memdump && crash_data->memdump_buf_len) + if (coredump_memdump && crash_data->memdump_buf_len) { + dump_mem = (struct mt7996_coredump_mem *)(buf + sofar); + dump_mem->len = crash_data->memdump_buf_len; memcpy(dump_mem->data, crash_data->memdump_buf, crash_data->memdump_buf_len); + } mutex_unlock(&dev->dump_mutex); From ec0889c74734131c6526493bd3134eea7de25bf8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 2 Jul 2026 15:54:59 +0000 Subject: [PATCH 1228/2126] wifi: mt76: mt7996: bound RRO session id before indexing addr_elem[] seq_id from the WED RRO indication is a 12-bit field (0-4095), but only values up to MT7996_RRO_MAX_SESSION map into wed_rro.addr_elem[], which has MT7996_RRO_ADDR_ELEM_LEN (128) entries. A larger session id computes an out-of-bounds element index that is then read and, on a signature mismatch, written. Reject an out-of-range session id. Fixes: a09d2f9d69af ("wifi: mt76: Convert mt76_wed_rro_ind to LE") Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index 1cba381a78b8..898cd9b8ff96 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -1936,6 +1936,9 @@ void mt7996_rro_rx_process(struct mt76_dev *mdev, void *data) struct mt7996_msdu_page *p = NULL; int i, seq_num = 0; + if (seq_id > MT7996_RRO_MAX_SESSION) + return; + for (i = 0; i < ind_count; i++) { struct mt7996_wed_rro_addr *e; struct mt76_rx_status *status; From a34595a955af242372cea2abfa7604f544399286 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:13 -0500 Subject: [PATCH 1229/2126] wifi: mt76: mt7925: fix NAN NDP STA record role index The NDP STA record role_idx must carry the NAN BSS band0 index rather than the mac80211 BSS index, otherwise the firmware maps the NDP peer to the wrong role. Use the fixed NAN_BSS_INDEX_BAND0 value. While at it, drop the inline peer-schedule setup in mt792x_nan_map_sta_rec(): the peer schedule is already driven by the upper layer through the peer_sched_changed callback (mt792x_nan_set_peer_schedule()), so the redundant call and the now-unused local variables are removed. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-2-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 33 +------------------ .../net/wireless/mediatek/mt76/mt7925/nan.h | 2 ++ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index d260e803d056..2c03ad9c452c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -984,21 +984,17 @@ int mt792x_nan_map_sta_rec(struct mt76_dev *mdev, struct mt7925_nan_common_hdr *hdr; struct ieee80211_sta *nmi_sta; struct mt792x_sta *nmi_msta; - struct mt792x_vif *mvif; struct mt792x_sta *msta; u8 nmi_addr[ETH_ALEN]; struct sk_buff *skb; int ndp_ctx_id = 0; int ret = -ENOMEM; - struct mt792x_dev *dev; struct tlv *tlv; if (!mdev || !vif || !sta) return -EINVAL; - dev = container_of(mdev, struct mt792x_dev, mt76); msta = (struct mt792x_sta *)sta->drv_priv; - mvif = (struct mt792x_vif *)vif->drv_priv; rcu_read_lock(); nmi_sta = rcu_dereference(sta->nmi); @@ -1012,33 +1008,6 @@ int mt792x_nan_map_sta_rec(struct mt76_dev *mdev, memcpy(nmi_addr, nmi_sta->addr, ETH_ALEN); nmi_msta = (struct mt792x_sta *)nmi_sta->drv_priv; - if (!nmi_msta->nan_sched.idx_assigned) { - if (!nmi_sta->nan_sched) { - rcu_read_unlock(); - dev_err(mdev->dev, - "NAN: peer schedule missing for NDI sta %pM\n", - sta->addr); - return -EAGAIN; - } - - rcu_read_unlock(); - ret = mt792x_nan_set_peer_schedule(dev, nmi_sta); - if (ret) - return ret; - - rcu_read_lock(); - nmi_sta = rcu_dereference(sta->nmi); - if (!nmi_sta) { - rcu_read_unlock(); - dev_err(mdev->dev, - "NAN: NMI sta not found for NDI sta %pM\n", - sta->addr); - return -EINVAL; - } - - nmi_msta = (struct mt792x_sta *)nmi_sta->drv_priv; - } - ndp_ctx_id = find_first_zero_bit(&nmi_msta->nan_sched.ndp_ctx_bitmap, NAN_MAX_NDP_CXT); if (ndp_ctx_id >= NAN_MAX_NDP_CXT) { @@ -1073,7 +1042,7 @@ int mt792x_nan_map_sta_rec(struct mt76_dev *mdev, memcpy(map_tlv->nmi_addr, nmi_addr, ETH_ALEN); map_tlv->sta_rec_idx = msta->deflink.wcid.idx; map_tlv->ndp_ctx_id = ndp_ctx_id; - map_tlv->role_idx = cpu_to_le32(mvif->bss_conf.mt76.idx); + map_tlv->role_idx = cpu_to_le32(NAN_BSS_INDEX_BAND0); memcpy(map_tlv->ndi_addr, vif->addr, ETH_ALEN); ret = mt76_mcu_skb_send_msg(mdev, skb, diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index f55730e25f46..1dcc888d98f9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -65,6 +65,8 @@ #define UNII3_LOWER_BOUND 149 #define UNII3_UPPER_BOUND 165 +#define NAN_BSS_INDEX_BAND0 0 + enum nan_uni_cmd_tag { NAN_UNI_CMD_SET_MASTER_PREFERENCE = 0, NAN_UNI_CMD_ENABLE_REQUEST = 7, From e2f7c78a764c41f231e86533257ab623d4b4fed9 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:14 -0500 Subject: [PATCH 1230/2126] wifi: mt76: mt7925: fix NAN start failure mt7925_start_nan() called mt7925_nan_set_nmi_addr(), which makes NAN start fail. The NMI address is not managed here, so drop the call. Also track dev->nan_vif only in add/remove_interface and fold the single BSS rollback into an inline error check. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-3-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/main.c | 17 +--------- .../net/wireless/mediatek/mt76/mt7925/nan.c | 32 ------------------- .../net/wireless/mediatek/mt76/mt7925/nan.h | 2 -- 3 files changed, 1 insertion(+), 50 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 5993b31e1aae..5f131c0484b9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -2592,21 +2592,9 @@ static int mt7925_start_nan(struct ieee80211_hw *hw, if (err < 0) goto out; - dev->nan_vif = vif; - - err = mt7925_nan_set_nmi_addr(dev, vif->addr); - if (err) - goto rollback_bss; - err = mt7925_nan_enable(vif, dev, conf); if (err) - goto rollback_bss; - - goto out; - -rollback_bss: - dev->nan_vif = NULL; - mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf, NULL, false); + mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf, NULL, false); out: mt792x_mutex_release(dev); @@ -2630,9 +2618,6 @@ static int mt7925_stop_nan(struct ieee80211_hw *hw, if (!err) err = ret; - if (dev->nan_vif == vif) - dev->nan_vif = NULL; - mt792x_mutex_release(dev); return err; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 2c03ad9c452c..51aab5cad4bd 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -144,38 +144,6 @@ mt7925_nan_update_conf(struct mt792x_vif *mvif, memcpy(mvif->nan.conf.cluster_id, conf->cluster_id, ETH_ALEN); } -int mt7925_nan_set_nmi_addr(struct mt792x_dev *dev, const u8 *addr) -{ - struct mt76_dev *mdev; - struct { - u8 rsv[4]; - struct mt7925_nan_nmi_addr_tlv nmi_addr_tlv; - } nmi_cmd = { - .rsv = { 0 }, - .nmi_addr_tlv = { - .tag = cpu_to_le16(NAN_UNI_CMD_CHANGE_NMI_ADDRESS), - .len = cpu_to_le16(sizeof(struct mt7925_nan_nmi_addr_tlv)), - }, - }; - int ret; - - if (!dev || !addr) - return -EINVAL; - - if (is_zero_ether_addr(addr) || is_multicast_ether_addr(addr)) { - dev_err(dev->mt76.dev, "NAN: invalid NMI address %pM\n", addr); - return -EINVAL; - } - - mdev = &dev->mt76; - memcpy(nmi_cmd.nmi_addr_tlv.nmi_addr, addr, ETH_ALEN); - - ret = mt76_mcu_send_msg(mdev, MCU_UNI_CMD(NAN), &nmi_cmd, - sizeof(nmi_cmd), true); - - return ret; -} - int mt7925_nan_enable(struct ieee80211_vif *vif, struct mt792x_dev *dev, struct cfg80211_nan_conf *conf) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index 1dcc888d98f9..91f4e999711e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -405,8 +405,6 @@ int mt7925_nan_change_configure(struct ieee80211_vif *vif, void mt7925_nan_mcu_event(struct mt792x_dev *dev, struct sk_buff *skb); -int mt7925_nan_set_nmi_addr(struct mt792x_dev *dev, const u8 *addr); - void mt7925_nan_local_sched_changed(struct mt792x_dev *dev, struct ieee80211_vif *vif); From d7e818693cca1e8e474a4df33cffce0583e02880 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:15 -0500 Subject: [PATCH 1231/2126] wifi: mt76: mt7925: fix NAN committed CRB timeline layout The committed CRB timeline carried a local_map_id byte that does not exist in the firmware NAN_SCHEDULE_TIMELINE_T layout (map id plus 3 reserved bytes), shifting the availability bitmap. Drop it and match the firmware structure. The common-slot check is also dropped as redundant: mac80211 already tracks common slots, so avail_map is built directly from the peer schedule. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-4-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 37 ++++++------------- .../net/wireless/mediatek/mt76/mt7925/nan.h | 3 +- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 51aab5cad4bd..81a1563b1408 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -753,52 +753,38 @@ static int mt7925_nan_peer_cap_tlv(struct sk_buff *skb, static void mt7925_nan_fill_crb_committed(struct mt7925_nan_sched_update_crb_tlv *crb_tlv, - struct ieee80211_vif *vif, struct ieee80211_nan_peer_sched *sched) { - struct ieee80211_nan_sched_cfg *local_sched; - u8 local_map_id; u32 m, slot; - if (!vif || !sched) + if (!sched) return; - local_sched = &vif->cfg.nan_sched; - local_map_id = mt7925_nan_avail_attr_ctrl(local_sched) & - NAN_AVAIL_CTRL_MAPID; - for (m = 0; m < CFG80211_NAN_MAX_PEER_MAPS && m < NAN_TIMELINE_MGMT_SIZE; m++) { + struct ieee80211_nan_peer_map *map = &sched->maps[m]; struct mt7925_nan_sched_timeline *tl = &crb_tlv->comm_faw_timeline[m]; - struct ieee80211_nan_peer_map *map = &sched->maps[m]; - u32 avail_map = 0; if (map->map_id == CFG80211_NAN_INVALID_MAP_ID) continue; tl->map_id = map->map_id; - tl->local_map_id = local_map_id; + /* + * Convert peer schedule slots to FW avail_map bitmap. + * Each bit in avail_map[0] represents one time slot where + * the peer has committed availability. + */ for (slot = 0; slot < CFG80211_NAN_SCHED_NUM_TIME_SLOTS; slot++) { - struct ieee80211_nan_channel *local_ch; - struct ieee80211_nan_channel *peer_ch; + struct ieee80211_nan_channel *ch = map->slots[slot]; - local_ch = local_sched->schedule[slot]; - peer_ch = map->slots[slot]; - - if (!local_ch || !local_ch->chanctx_conf || - !peer_ch || !peer_ch->chanctx_conf) + if (!ch || !ch->chanctx_conf) continue; - if (local_ch->chanctx_conf != peer_ch->chanctx_conf) - continue; - - avail_map |= BIT(slot); + tl->avail_map[0] |= cpu_to_le32(BIT(slot)); } - - tl->avail_map[0] = cpu_to_le32(avail_map); } } @@ -824,8 +810,7 @@ static int mt7925_nan_update_crb_tlv(struct sk_buff *skb, crb_tlv->is_use_ranging = false; crb_tlv->comm_ndc_ctrl.is_valid = false; - mt7925_nan_fill_crb_committed(crb_tlv, msta->vif->phy->dev->nan_vif, - sta->nan_sched); + mt7925_nan_fill_crb_committed(crb_tlv, sta->nan_sched); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index 91f4e999711e..fab10b829eaa 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -348,8 +348,7 @@ struct mt7925_nan_sched_update_peer_cap_tlv { struct mt7925_nan_sched_timeline { u8 map_id; - u8 local_map_id; - u8 reserved[2]; + u8 reserved[3]; union { __le32 avail_map[NAN_TOTAL_DW]; u8 avail_block[NAN_TOTAL_DW * 4]; From 4d57010abf701cb08d7216b30143c696a8c2405b Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:16 -0500 Subject: [PATCH 1232/2126] wifi: mt76: mt7925: report only 2.4 GHz NAN supported band The firmware only checks the 2.4 GHz bit of the local device capability supported_bands field, so set it directly and drop the unused helper. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-5-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 81a1563b1408..36de42193190 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -680,23 +680,6 @@ static int mt7925_nan_peer_rec_tlv(struct sk_buff *skb, return 0; } -static u8 mt7925_nan_get_supported_bands(struct mt792x_vif *mvif) -{ - struct wiphy *wiphy; - u8 bands = 0; - - if (!mvif || !mvif->phy) - return BIT(NAN_SUPPORTED_BAND_ID_2P4G); - - wiphy = mvif->phy->mt76->hw->wiphy; - if (wiphy->nan_supported_bands & BIT(NL80211_BAND_2GHZ)) - bands |= BIT(NAN_SUPPORTED_BAND_ID_2P4G); - if (wiphy->nan_supported_bands & BIT(NL80211_BAND_5GHZ)) - bands |= BIT(NAN_SUPPORTED_BAND_ID_5G); - - return bands ?: BIT(NAN_SUPPORTED_BAND_ID_2P4G); -} - static int mt7925_nan_peer_cap_tlv(struct sk_buff *skb, struct ieee80211_sta *sta, struct mt792x_sta *msta) @@ -723,8 +706,7 @@ static int mt7925_nan_peer_cap_tlv(struct sk_buff *skb, peer_cap_tlv = (struct mt7925_nan_sched_update_peer_cap_tlv *)tlv; peer_cap_tlv->sch_idx = cpu_to_le32(msta->nan_sched.sch_idx); - peer_cap_tlv->supported_bands = - mt7925_nan_get_supported_bands(msta->vif); + peer_cap_tlv->supported_bands = BIT(NAN_SUPPORTED_BAND_ID_2P4G); peer_cap_tlv->max_chnl_switch_time = cpu_to_le16(sched->max_chan_switch); for (i = 0; i < sched->n_channels; i++) { From f87a9e7f49495e822e41828421ce51550e752dce Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:17 -0500 Subject: [PATCH 1233/2126] wifi: mt76: mt7925: drop unused NAN 2.4/5 GHz support config The config_support_5g/support_5g_val and config_2dot4g_support/ support_2dot4g_val fields in the NAN enable request are not used by the firmware, so stop setting them and drop mt7925_nan_set_2g_support(). Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-6-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/nan.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 36de42193190..c3a9a592dddf 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -32,8 +32,6 @@ static void mt7925_nan_set_5g_channel(struct mt792x_dev *dev, if (!mt7925_regd_is_valid_channel(dev, NL80211_BAND_5GHZ, chan)) return; - req->config_support_5g = 1; - req->support_5g_val = 1; req->config_5g_channel = 1; if (chan->hw_value == NAN_5G_LOW_DISC_CHANNEL) @@ -44,16 +42,6 @@ static void mt7925_nan_set_5g_channel(struct mt792x_dev *dev, req->channel_5g_val = cpu_to_le32(ch5g); } -static void mt7925_nan_set_2g_support(struct mt7925_nan_enable_req_tlv *req, - struct cfg80211_nan_conf *conf) -{ - if (!conf->band_cfgs[NL80211_BAND_2GHZ].chan) - return; - - req->config_2dot4g_support = 1; - req->support_2dot4g_val = 1; -} - static void mt7925_nan_set_cluster_id(struct mt7925_nan_enable_req_tlv *req, const u8 *cluster_id) { @@ -172,7 +160,6 @@ int mt7925_nan_enable(struct ieee80211_vif *vif, p_nan_req_tlv->master_pref = conf->master_pref; - mt7925_nan_set_2g_support(p_nan_req_tlv, conf); mt7925_nan_set_5g_channel(dev, p_nan_req_tlv, conf); mt7925_nan_set_cluster_id(p_nan_req_tlv, conf->cluster_id); mt7925_nan_set_dw_interval(p_nan_req_tlv, conf); From 851b8f026ac10afa978f8d8af3eb2af4a4930c92 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:18 -0500 Subject: [PATCH 1234/2126] wifi: mt76: mt7925: drop deferred NAN local schedule update handling The deferred NAN local schedule update path in mt7925_nan_local_sched_changed() is removed for now; it will be implemented separately. Drop the now set-but-unused ret variable along with it. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-7-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/nan.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index c3a9a592dddf..2be2251aeadb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -602,15 +602,12 @@ void mt7925_nan_local_sched_changed(struct mt792x_dev *dev, { struct mt7925_nan_common_hdr *hdr; struct mt76_dev *mdev; - bool deferred; struct sk_buff *skb; - int ret = -ENOMEM; if (!dev || !vif) return; mdev = &dev->mt76; - deferred = vif->cfg.nan_sched.deferred; mt792x_mutex_acquire(dev); @@ -627,19 +624,9 @@ void mt7925_nan_local_sched_changed(struct mt792x_dev *dev, goto out; } - ret = mt76_mcu_skb_send_msg(mdev, skb, - MCU_UNI_CMD(NAN), true); + mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(NAN), true); out: mt792x_mutex_release(dev); - - if (deferred) { - if (ret) - dev_err(mdev->dev, - "NAN: local schedule update failed: %d\n", - ret); - - ieee80211_nan_sched_update_done(vif); - } } static int mt7925_nan_peer_rec_tlv(struct sk_buff *skb, From b757f5b8c346d02d69c88e4520537ecbb4cfef90 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:19 -0500 Subject: [PATCH 1235/2126] wifi: mt76: mt7925: use OFDM-only PHY mode for NAN STA records NAN operates with OFDM and does not support CCK, so the phy, rate control and BSS rate TLVs must not fall back to 2.4 GHz. Borrow the 5 GHz band lookup to keep the STA records OFDM-only. Fixes: 9824fb4edbf3 ("wifi: mt76: mt7925: add NAN MCU handling") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-8-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index aeb017516186..2afd3f5e3266 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -1914,11 +1914,9 @@ mt7925_mcu_sta_phy_tlv(struct sk_buff *skb, phy = (struct sta_rec_phy *)tlv; if (mt7925_vif_is_nan(vif)) { - enum nl80211_band band = chandef->chan ? chandef->chan->band - : NL80211_BAND_2GHZ; phy->phy_type = PHY_TYPE_BIT_OFDM | PHY_TYPE_BIT_ERP; phy->phy_type |= mt76_connac_get_phy_mode_v2(mvif->phy->mt76, vif, - band, + NL80211_BAND_5GHZ, link_sta); } else { phy->phy_type = mt76_connac_get_phy_mode_v2(mvif->phy->mt76, vif, @@ -2003,7 +2001,11 @@ mt7925_mcu_sta_rate_ctrl_tlv(struct sk_buff *skb, ra_info = (struct sta_rec_ra_info *)tlv; if (mt7925_vif_is_nan(vif)) - band = chandef->chan ? chandef->chan->band : NL80211_BAND_2GHZ; + /* NAN is OFDM-only per spec; borrow the 5 GHz band lookup to + * avoid PHY_TYPE_BIT_HR_DSSS/CCK bits being added to phy_type. + * NAN interfaces have no chanctx, so chandef->chan is always NULL. + */ + band = NL80211_BAND_5GHZ; else band = chandef->chan->band; @@ -2847,7 +2849,7 @@ mt7925_mcu_bss_bmc_tlv(struct sk_buff *skb, struct mt792x_phy *phy, bmc = (struct bss_rate_tlv *)tlv; if (mt7925_vif_is_nan(vif)) - band = chandef->chan ? chandef->chan->band : NL80211_BAND_2GHZ; + band = NL80211_BAND_5GHZ; else band = chandef->chan->band; From 9d758e4f60c12a396bd75b246b30cc9064dd1e47 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:20 -0500 Subject: [PATCH 1236/2126] wifi: mt76: mt7925: share TLV setup for NAN enable command Refactor mt7925_nan_enable() to build the MCU command from separate TLVs via skb instead of inline fields in the enable request struct. The cluster ID, DW interval, discovery beacon interval and RSSI threshold settings are now shared with mt7925_nan_change_configure() through the common TLV helpers, avoiding duplicated setup code. Fixes: a5487a682406 ("wifi: mt76: mt7925: add NAN MCU helpers") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-9-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 190 +++++++----------- .../net/wireless/mediatek/mt76/mt7925/nan.h | 7 + 2 files changed, 78 insertions(+), 119 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 2be2251aeadb..1c69db94b73d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -42,63 +42,6 @@ static void mt7925_nan_set_5g_channel(struct mt792x_dev *dev, req->channel_5g_val = cpu_to_le32(ch5g); } -static void mt7925_nan_set_cluster_id(struct mt7925_nan_enable_req_tlv *req, - const u8 *cluster_id) -{ - if (!cluster_id) - return; - - req->cluster_high = cpu_to_le16(cluster_id[4] | cluster_id[5] << 8); - req->cluster_low = cpu_to_le16((u16)cluster_id[3]); -} - -static void mt7925_nan_set_dw_interval(struct mt7925_nan_enable_req_tlv *req, - struct cfg80211_nan_conf *conf) -{ - if (conf->band_cfgs[NL80211_BAND_2GHZ].awake_dw_interval > 0) { - req->config_dw.config_2dot4g_dw_band = 1; - req->config_dw.dw_2dot4g_interval_val = - cpu_to_le32(conf->band_cfgs[NL80211_BAND_2GHZ].awake_dw_interval); - } - - if (conf->band_cfgs[NL80211_BAND_5GHZ].awake_dw_interval > 0) { - req->config_dw.config_5g_dw_band = 1; - req->config_dw.dw_5g_interval_val = - cpu_to_le32(conf->band_cfgs[NL80211_BAND_5GHZ].awake_dw_interval); - } -} - -static void mt7925_nan_set_disc_beacon(struct mt7925_nan_enable_req_tlv *req, - struct cfg80211_nan_conf *conf) -{ - if (conf->discovery_beacon_interval > 0) { - req->config_2dot4g_beacons = true; - req->beacon_2dot4g_val = conf->discovery_beacon_interval; - } -} - -static void mt7925_nan_set_rssi_thresholds(struct mt7925_nan_enable_req_tlv *req, - struct cfg80211_nan_conf *conf) -{ - if (conf->band_cfgs[NL80211_BAND_2GHZ].chan) { - req->config_2dot4g_rssi_close = 1; - req->rssi_close_2dot4g_val = - abs(conf->band_cfgs[NL80211_BAND_2GHZ].rssi_close); - req->config_2dot4g_rssi_middle = 1; - req->rssi_middle_2dot4g_val = - abs(conf->band_cfgs[NL80211_BAND_2GHZ].rssi_middle); - } - - if (conf->band_cfgs[NL80211_BAND_5GHZ].chan) { - req->config_5g_rssi_close = 1; - req->rssi_close_5g_val = - abs(conf->band_cfgs[NL80211_BAND_5GHZ].rssi_close); - req->config_5g_rssi_middle = 1; - req->rssi_middle_5g_val = - abs(conf->band_cfgs[NL80211_BAND_5GHZ].rssi_middle); - } -} - static void mt7925_nan_set_scan_params(struct mt7925_nan_enable_req_tlv *req, struct cfg80211_nan_conf *conf) { @@ -132,68 +75,6 @@ mt7925_nan_update_conf(struct mt792x_vif *mvif, memcpy(mvif->nan.conf.cluster_id, conf->cluster_id, ETH_ALEN); } -int mt7925_nan_enable(struct ieee80211_vif *vif, - struct mt792x_dev *dev, - struct cfg80211_nan_conf *conf) -{ - struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; - struct mt76_dev *mdev = &dev->mt76; - struct { - u8 rsv[4]; - struct mt7925_nan_enable_req_tlv nan_req_tlv; - } nan_cmd = { - .rsv = { 0 }, - .nan_req_tlv = { - .tag = cpu_to_le16(NAN_UNI_CMD_ENABLE_REQUEST), - .len = cpu_to_le16(sizeof(struct mt7925_nan_enable_req_tlv)), - .config_random_factor_force = 0, - .random_factor_force_val = 0, - .config_hop_count_force = 0, - .hop_count_force_val = 0, - }, - }; - struct mt7925_nan_enable_req_tlv *p_nan_req_tlv = &nan_cmd.nan_req_tlv; - int ret; - - if (!vif || !dev || !conf) - return -EINVAL; - - p_nan_req_tlv->master_pref = conf->master_pref; - - mt7925_nan_set_5g_channel(dev, p_nan_req_tlv, conf); - mt7925_nan_set_cluster_id(p_nan_req_tlv, conf->cluster_id); - mt7925_nan_set_dw_interval(p_nan_req_tlv, conf); - mt7925_nan_set_disc_beacon(p_nan_req_tlv, conf); - mt7925_nan_set_rssi_thresholds(p_nan_req_tlv, conf); - mt7925_nan_set_scan_params(p_nan_req_tlv, conf); - - mt7925_nan_update_conf(mvif, conf); - - ret = mt76_mcu_send_msg(mdev, MCU_UNI_CMD(NAN), &nan_cmd, sizeof(nan_cmd), true); - - return ret; -} - -int mt7925_nan_disable(struct ieee80211_vif *vif, struct mt792x_dev *dev) -{ - struct mt76_dev *mdev = &dev->mt76; - struct { - u8 rsv[4]; - struct tlv nan_dis_tlv; - } nan_cmd = { - .rsv = { 0 }, - .nan_dis_tlv = { - .tag = cpu_to_le16(NAN_UNI_CMD_DISABLE_REQUEST), - .len = cpu_to_le16(sizeof(struct tlv)), - }, - }; - - if (!dev) - return -EINVAL; - - return mt76_mcu_send_msg(mdev, MCU_UNI_CMD(NAN), &nan_cmd, sizeof(nan_cmd), true); -} - static int mt7925_nan_mp_tlv(struct sk_buff *skb, u8 master_pref) { @@ -312,6 +193,77 @@ mt7925_nan_sync_rssi_tlv(struct sk_buff *skb, struct cfg80211_nan_conf *conf) return 0; } +int mt7925_nan_enable(struct ieee80211_vif *vif, + struct mt792x_dev *dev, + struct cfg80211_nan_conf *conf) +{ + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + struct mt76_dev *mdev = &dev->mt76; + struct mt7925_nan_common_hdr *hdr; + struct mt7925_nan_enable_req_tlv *req; + struct sk_buff *skb; + + if (!vif || !dev || !conf) + return -EINVAL; + + skb = mt76_mcu_msg_alloc(mdev, NULL, MT7925_NAN_ENABLE_MAX_SIZE); + if (!skb) + return -ENOMEM; + + hdr = (struct mt7925_nan_common_hdr *)skb_put(skb, sizeof(*hdr)); + memset(hdr, 0, sizeof(*hdr)); + + /* Set cluster id before joining cluster */ + if (mt7925_nan_cluster_id_tlv(skb, conf->cluster_id)) { + dev_kfree_skb(skb); + return -ENOMEM; + } + + /* NAN enable request tlv */ + req = (struct mt7925_nan_enable_req_tlv *) + mt76_connac_mcu_add_tlv(skb, NAN_UNI_CMD_ENABLE_REQUEST, + sizeof(*req)); + if (!req) { + dev_kfree_skb(skb); + return -ENOMEM; + } + + req->master_pref = conf->master_pref; + + mt7925_nan_set_5g_channel(dev, req, conf); + mt7925_nan_set_scan_params(req, conf); + + if (mt7925_nan_dw_tlv(skb, conf) || + mt7925_nan_sync_rssi_tlv(skb, conf)) { + dev_kfree_skb(skb); + return -ENOMEM; + } + + mt7925_nan_update_conf(mvif, conf); + + return mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(NAN), true); +} + +int mt7925_nan_disable(struct ieee80211_vif *vif, struct mt792x_dev *dev) +{ + struct mt76_dev *mdev = &dev->mt76; + struct { + u8 rsv[4]; + struct tlv nan_dis_tlv; + } nan_cmd = { + .rsv = { 0 }, + .nan_dis_tlv = { + .tag = cpu_to_le16(NAN_UNI_CMD_DISABLE_REQUEST), + .len = cpu_to_le16(sizeof(struct tlv)), + }, + }; + + if (!dev) + return -EINVAL; + + return mt76_mcu_send_msg(mdev, MCU_UNI_CMD(NAN), &nan_cmd, sizeof(nan_cmd), true); +} + int mt7925_nan_change_configure(struct ieee80211_vif *vif, struct mt792x_dev *dev, struct cfg80211_nan_conf *conf) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index fab10b829eaa..31341c1df8f9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -28,6 +28,13 @@ #define NAN_MAX_CONN_CFG 8 #define NAN_MAX_NDP_CXT 4 +#define MT7925_NAN_ENABLE_MAX_SIZE \ + (sizeof(struct mt7925_nan_common_hdr) + \ + sizeof(struct mt7925_nan_enable_req_tlv) + \ + sizeof(struct mt7925_nan_dw_interval_tlv) + \ + sizeof(struct mt7925_nan_cluster_id_tlv) + \ + sizeof(struct mt7925_nan_sync_rssi_tlv)) + #define MT7925_NAN_CONF_MAX_SIZE \ (sizeof(struct mt7925_nan_common_hdr) + \ sizeof(struct mt7925_nan_master_preference_tlv) + \ From ad393e4d799cc52e282003cba4a1f5ed1b01cfa3 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:21 -0500 Subject: [PATCH 1237/2126] wifi: mt76: mt7925: replace NAN DW end event with DW start Handle the NAN DW start event instead of the DW end event for DW notification. Queuing NDP action frames at the beginning of the DW window, rather than after it ends, improves NDP handshake reliability. Fixes: a5487a682406 ("wifi: mt76: mt7925: add NAN MCU helpers") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-10-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/nan.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7925/nan.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 1c69db94b73d..8194e7678131 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -422,7 +422,7 @@ void mt7925_nan_mcu_event(struct mt792x_dev *dev, struct sk_buff *skb) case NAN_UNI_EVENT_ID_DE_EVENT_IND: mt7925_nan_mcu_handle_de_event(dev, tlv); break; - case NAN_UNI_EVENT_REPORT_DW_END: + case NAN_UNI_EVENT_REPORT_DW_START: mt7925_nan_handle_dw_ind(dev, tlv); break; default: diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index 31341c1df8f9..4b424e0ece52 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -93,6 +93,7 @@ enum nan_uni_cmd_tag { enum nan_uni_event_tag { NAN_UNI_EVENT_ID_DE_EVENT_IND = 19, + NAN_UNI_EVENT_REPORT_DW_START = 59, NAN_UNI_EVENT_REPORT_DW_END = 60, }; From 4489c66f64289cdf07a396f5edc7487af584b2db Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:22 -0500 Subject: [PATCH 1238/2126] wifi: mt76: mt7925: fill all DW intervals in NAN avail_map Fill avail_map for all DW intervals instead of only DW index 0. FW requires the bitmap to be set across all 16 DW intervals for correct NAN scheduling. Without this, NDP ping latency is extremely high (~200ms) because FW only schedules data in the first DW interval. Also set ch_type = 1 for new channel entries to indicate channel-based (non-band) availability. Fixes: a5487a682406 ("wifi: mt76: mt7925: add NAN MCU helpers") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-11-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 27 ++++++++++++++----- .../net/wireless/mediatek/mt76/mt7925/nan.h | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 8194e7678131..79e57bae566d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -491,9 +491,14 @@ static u32 mt7925_nan_slot_to_bitmap(struct ieee80211_vif *vif, if (FIELD_GET(NAN_CH_CTRL_PRIMARY_CH, raw) == slot_chan->chan->hw_value) { - u32 map = le32_to_cpu(ch_list[j].avail_map[0]); + u32 dw; - ch_list[j].avail_map[0] = cpu_to_le32(map | BIT(i)); + for (dw = 0; dw < NAN_TOTAL_DW; dw++) { + u32 map = le32_to_cpu(ch_list[j].avail_map[dw]); + + ch_list[j].avail_map[dw] = + cpu_to_le32(map | BIT(i)); + } le32_add_cpu(&ch_list[j].num, 1); is_found = true; break; @@ -501,12 +506,18 @@ static u32 mt7925_nan_slot_to_bitmap(struct ieee80211_vif *vif, } if (!is_found && num_channels < NAN_TIMELINE_MGMT_CHNL_LIST_NUM) { + u32 dw; + ch_list[num_channels].ch_info = - cpu_to_le32(FIELD_PREP(NAN_CH_CTRL_OP_CLASS, + cpu_to_le32(FIELD_PREP(NAN_CH_CTRL_CH_TYPE, + NAN_BAND_CHANNEL_ENTRY_LIST_TYPE_CHANNEL) | + FIELD_PREP(NAN_CH_CTRL_OP_CLASS, slot->channel_entry[0]) | FIELD_PREP(NAN_CH_CTRL_PRIMARY_CH, slot_chan->chan->hw_value)); - ch_list[num_channels].avail_map[0] = cpu_to_le32(BIT(i)); + for (dw = 0; dw < NAN_TOTAL_DW; dw++) + ch_list[num_channels].avail_map[dw] = + cpu_to_le32(BIT(i)); le32_add_cpu(&ch_list[num_channels].num, 1); ch_list[num_channels].is_valid++; num_channels++; @@ -681,17 +692,19 @@ mt7925_nan_fill_crb_committed(struct mt7925_nan_sched_update_crb_tlv *crb_tlv, /* * Convert peer schedule slots to FW avail_map bitmap. - * Each bit in avail_map[0] represents one time slot where - * the peer has committed availability. + * Each bit represents one time slot where the peer has + * committed availability. Fill all DW intervals the same. */ for (slot = 0; slot < CFG80211_NAN_SCHED_NUM_TIME_SLOTS; slot++) { struct ieee80211_nan_channel *ch = map->slots[slot]; + u32 dw; if (!ch || !ch->chanctx_conf) continue; - tl->avail_map[0] |= cpu_to_le32(BIT(slot)); + for (dw = 0; dw < NAN_TOTAL_DW; dw++) + tl->avail_map[dw] |= cpu_to_le32(BIT(slot)); } } } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index 4b424e0ece52..eadb07e34b3e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -118,12 +118,15 @@ enum nan_peer_supported_bands { NAN_SUPPORTED_BN_NUM }; +#define NAN_CH_CTRL_CH_TYPE BIT(0) #define NAN_CH_CTRL_OP_CLASS GENMASK(15, 8) #define NAN_CH_CTRL_PRIMARY_CH GENMASK(23, 16) #define NAN_CRB_USE_DATA_PATH BIT(0) #define NAN_CRB_AVAIL_6G_FORMAT GENMASK(2, 1) +#define NAN_BAND_CHANNEL_ENTRY_LIST_TYPE_CHANNEL 1 + struct mt7925_nan_social_ch_scan_params { u8 dwell_time[NAN_MAX_SOCIAL_CHANNELS]; __le16 scan_period[NAN_MAX_SOCIAL_CHANNELS]; From f0793ef2f7d48fa32d11e1b0915d9989ceb1de9a Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:23 -0500 Subject: [PATCH 1239/2126] wifi: mt76: mt7925: clear CRB before deactivating NAN peer record Send a zero avail_map CRB TLV before the peer record deactivation command. This ensures FW clears the committed schedule slots for the departing peer, preventing stale CRB entries from affecting subsequent NDP connections. Fixes: a5487a682406 ("wifi: mt76: mt7925: add NAN MCU helpers") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-12-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 79e57bae566d..16f3e40c75e7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -809,18 +809,18 @@ clear_idx: int mt792x_nan_set_peer_rec(struct mt76_dev *mdev, struct ieee80211_sta *sta) { + struct mt7925_nan_sched_update_crb_tlv *crb_tlv; struct mt7925_nan_common_hdr *hdr; struct mt792x_sta *msta; struct mt792x_nan *nan; struct sk_buff *skb; + struct tlv *tlv; int ret; if (!mdev || !sta) return -EINVAL; - skb = mt76_mcu_msg_alloc(mdev, NULL, - sizeof(struct mt7925_nan_common_hdr) + - sizeof(struct mt7925_nan_sched_manage_peer_rec_tlv)); + skb = mt76_mcu_msg_alloc(mdev, NULL, MT7925_NAN_PEER_MAX_SIZE); if (!skb) return -ENOMEM; @@ -835,6 +835,25 @@ int mt792x_nan_set_peer_rec(struct mt76_dev *mdev, return 0; } + /* Send a zero-avail_map CRB TLV before deactivating the peer record so + * firmware clears the committed schedule slots for this peer. Without + * this, stale CRB entries linger and cause scheduling conflicts for + * subsequent NDP connections that reuse the same sch_idx. + */ + tlv = mt76_connac_mcu_add_tlv(skb, NAN_UNI_CMD_UPDATE_CRB, + sizeof(struct mt7925_nan_sched_update_crb_tlv)); + if (!tlv) { + dev_kfree_skb(skb); + return -ENOMEM; + } + crb_tlv = (struct mt7925_nan_sched_update_crb_tlv *)tlv; + crb_tlv->sch_idx = cpu_to_le32(msta->nan_sched.sch_idx); + crb_tlv->flags = NAN_CRB_USE_DATA_PATH; + crb_tlv->is_use_ranging = false; + crb_tlv->comm_ndc_ctrl.is_valid = false; + /* avail_map is zero-initialised by mt76_connac_mcu_add_tlv */ + + /* Deactivate peer record and release connection index */ if (mt7925_nan_peer_rec_tlv(skb, sta, msta, false)) { dev_kfree_skb(skb); return -ENOMEM; From 0ed6ac64344e0dcbed04f270426ca6f4a240b472 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:24 -0500 Subject: [PATCH 1240/2126] wifi: mt76: mt7925: add ULW event handling and peer ULW update Forward NAN Unaligned Window attributes between FW and mac80211: report ULW updates from FW via cfg80211_nan_ulw_update() and push peer ULW attributes to FW with NAN_UNI_CMD_UPDATE_ULW. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-13-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/nan.c | 84 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7925/nan.h | 40 ++++++++- 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 16f3e40c75e7..bfb1e6de5757 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -397,6 +397,52 @@ mt7925_nan_mcu_handle_de_event(struct mt792x_dev *dev, struct tlv *tlv) ieee80211_nan_cluster_joined(dev->nan_vif, cluster_id, true, GFP_KERNEL); } +static void +mt7925_nan_handle_ulw_update(struct mt792x_dev *dev, struct tlv *tlv) +{ + struct mt7925_nan_ulw_event *evt; + struct mt7925_nan_ulw_attr attr; + struct wireless_dev *wdev; + u16 len; + + if (!dev || !tlv) + return; + + if (!dev->nan_vif || !ieee80211_vif_nan_started(dev->nan_vif)) + return; + + len = le16_to_cpu(tlv->len); + if (len < sizeof(*tlv) + sizeof(*evt)) { + dev_warn(dev->mt76.dev, + "nan: short ulw event tlv len=%u\n", len); + return; + } + + evt = (struct mt7925_nan_ulw_event *)tlv->data; + wdev = ieee80211_vif_to_wdev(dev->nan_vif); + if (!wdev) + return; + + dev_dbg(dev->mt76.dev, + "nan: ulw_update wdev=%p owner_nlportid=%u sched_id=%u seq=%u dur=%u\n", + wdev, wdev->owner_nlportid, + evt->sched_id, evt->seq_id, le32_to_cpu(evt->duration)); + + /* Reorder the FW fields into NAN spec Table 109 attribute layout */ + attr.attr_id = NAN_ULW_ATTR_ID; + attr.length = cpu_to_le16(NAN_ULW_FIXED_PAYLOAD); + attr.sched_id = evt->sched_id; + attr.seq_id = evt->seq_id; + attr.start_time = evt->start_time; + attr.duration = evt->duration; + attr.period = evt->period; + attr.count_down = evt->count_down; + attr.ulw_overwrite = evt->ulw_overwrite; + + cfg80211_nan_ulw_update(wdev, (const u8 *)&attr, sizeof(attr), + GFP_KERNEL); +} + void mt7925_nan_mcu_event(struct mt792x_dev *dev, struct sk_buff *skb) { struct tlv *tlv; @@ -425,6 +471,9 @@ void mt7925_nan_mcu_event(struct mt792x_dev *dev, struct sk_buff *skb) case NAN_UNI_EVENT_REPORT_DW_START: mt7925_nan_handle_dw_ind(dev, tlv); break; + case NAN_UNI_EVENT_ID_ULW_UPDATE: + mt7925_nan_handle_ulw_update(dev, tlv); + break; default: break; } @@ -736,6 +785,37 @@ static int mt7925_nan_update_crb_tlv(struct sk_buff *skb, return 0; } +static int +mt7925_nan_peer_ulw_tlv(struct sk_buff *skb, + struct ieee80211_sta *sta, + struct mt792x_sta *msta) +{ + struct mt7925_nan_update_ulw_tlv *ulw_tlv = NULL; + struct ieee80211_nan_peer_sched *sched = NULL; + struct tlv *tlv = NULL; + + if (!skb || !sta || !msta) + return -EINVAL; + + sched = sta->nan_sched; + if (!sched || !sched->init_ulw || !sched->ulw_size) + return 0; /* No ULW to send, not an error */ + + if (sched->ulw_size > NAN_ULW_MAX_SIZE) + return -EINVAL; + + tlv = mt76_connac_mcu_add_tlv(skb, NAN_UNI_CMD_UPDATE_ULW, + sizeof(struct mt7925_nan_update_ulw_tlv)); + if (!tlv) + return -ENOMEM; + + ulw_tlv = (struct mt7925_nan_update_ulw_tlv *)tlv; + ether_addr_copy(ulw_tlv->nmi_addr, sta->addr); + memcpy(ulw_tlv->ulw_attr, sched->init_ulw, sched->ulw_size); + + return 0; +} + int mt792x_nan_set_peer_schedule(struct mt792x_dev *dev, struct ieee80211_sta *sta) { @@ -788,6 +868,10 @@ int mt792x_nan_set_peer_schedule(struct mt792x_dev *dev, goto free_skb; } + ret = mt7925_nan_peer_ulw_tlv(skb, sta, msta); + if (ret) + goto free_skb; + ret = mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(NAN), true); if (ret && idx_allocated) goto clear_idx; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index eadb07e34b3e..a0da16adf182 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -51,7 +51,8 @@ (sizeof(struct mt7925_nan_common_hdr) + \ sizeof(struct mt7925_nan_sched_manage_peer_rec_tlv) + \ sizeof(struct mt7925_nan_sched_update_peer_cap_tlv) + \ - sizeof(struct mt7925_nan_sched_update_crb_tlv)) + sizeof(struct mt7925_nan_sched_update_crb_tlv) + \ + sizeof(struct mt7925_nan_update_ulw_tlv)) /* NAN Availability Attribute */ #define NAN_AVAIL_ATTR_ID_OFFSET 0 @@ -82,6 +83,7 @@ enum nan_uni_cmd_tag { NAN_UNI_CMD_UPDATE_CRB = 10, NAN_UNI_CMD_MANAGE_PEER_SCH_RECORD = 12, NAN_UNI_CMD_MAP_STA_RECORD = 13, + NAN_UNI_CMD_UPDATE_ULW = 16, NAN_UNI_CMD_UPDATE_AVAILABILITY_CTRL = 20, NAN_UNI_CMD_UPDATE_PEER_CAPABILITY = 21, NAN_UNI_CMD_CHANGE_NMI_ADDRESS = 24, @@ -93,6 +95,7 @@ enum nan_uni_cmd_tag { enum nan_uni_event_tag { NAN_UNI_EVENT_ID_DE_EVENT_IND = 19, + NAN_UNI_EVENT_ID_ULW_UPDATE = 39, NAN_UNI_EVENT_REPORT_DW_START = 59, NAN_UNI_EVENT_REPORT_DW_END = 60, }; @@ -166,6 +169,32 @@ struct nan_rpt_dw_evt { __le16 dw_num; }; +#define NAN_ULW_ATTR_ID 0x17 +#define NAN_ULW_FIXED_PAYLOAD 16 /* Table 109 fixed fields */ + +struct mt7925_nan_ulw_event { + u8 sched_id; + u8 seq_id; + u8 count_down; + u8 ulw_overwrite; + __le32 start_time; + __le32 duration; + __le32 period; +} __packed; + +/* ULW attribute laid out in NAN spec Table 109 field order */ +struct mt7925_nan_ulw_attr { + u8 attr_id; + __le16 length; + u8 sched_id; + u8 seq_id; + __le32 start_time; + __le32 duration; + __le32 period; + u8 count_down; + u8 ulw_overwrite; +} __packed; + struct mt7925_nan_conf_dw { u8 config_2dot4g_dw_band; __le32 dw_2dot4g_interval_val; @@ -390,6 +419,15 @@ struct mt7925_nan_sched_update_crb_tlv { struct mt7925_nan_sched_faw_ndc_timeline faw_ndc_timeline[NAN_TIMELINE_MGMT_SIZE]; } __packed __aligned(4); +#define NAN_ULW_MAX_SIZE 256 + +struct mt7925_nan_update_ulw_tlv { + __le16 tag; + __le16 len; + u8 nmi_addr[ETH_ALEN]; + u8 ulw_attr[NAN_ULW_MAX_SIZE]; +} __packed __aligned(4); + struct mt7925_nan_sched_map_sta_rec_tlv { __le16 tag; __le16 len; From bbb8334e63824c941dbe685e62345d4c41afeb69 Mon Sep 17 00:00:00 2001 From: Stella Liu Date: Mon, 24 Aug 2026 14:52:25 -0500 Subject: [PATCH 1241/2126] wifi: mt76: mt7925: configure NAN PHY setting on enable Implement NAN_UNI_CMD_UPDATE_PHY_SETTING (tag=18) to configure the BSS-level PHY parameters that the FW NAN scheduler uses when it switches channels. The command carries separate 2G and 5G PHY settings, each with its own phy type, rate sets and protection modes. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Stella Liu Link: https://patch.msgid.link/20260824195227.12589-14-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/main.c | 6 +- .../net/wireless/mediatek/mt76/mt7925/nan.c | 74 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7925/nan.h | 29 ++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 5f131c0484b9..f58d7fcd58ea 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -2593,8 +2593,12 @@ static int mt7925_start_nan(struct ieee80211_hw *hw, goto out; err = mt7925_nan_enable(vif, dev, conf); - if (err) + if (err) { mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf, NULL, false); + goto out; + } + + err = mt7925_nan_update_phy_setting(dev); out: mt792x_mutex_release(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index bfb1e6de5757..445b8bbd7777 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -193,6 +193,80 @@ mt7925_nan_sync_rssi_tlv(struct sk_buff *skb, struct cfg80211_nan_conf *conf) return 0; } +/* FW rate set bit definitions (matches FW wlan_def_cmm.h) */ +#define NAN_RATE_SET_BIT_1M BIT(0) +#define NAN_RATE_SET_BIT_2M BIT(1) +#define NAN_RATE_SET_BIT_5_5M BIT(2) +#define NAN_RATE_SET_BIT_11M BIT(3) +#define NAN_RATE_SET_BIT_6M BIT(6) +#define NAN_RATE_SET_BIT_9M BIT(7) +#define NAN_RATE_SET_BIT_12M BIT(8) +#define NAN_RATE_SET_BIT_18M BIT(9) +#define NAN_RATE_SET_BIT_24M BIT(10) +#define NAN_RATE_SET_BIT_36M BIT(11) +#define NAN_RATE_SET_BIT_48M BIT(12) +#define NAN_RATE_SET_BIT_54M BIT(13) + +#define NAN_RATE_SET_ALL_A (NAN_RATE_SET_BIT_6M | NAN_RATE_SET_BIT_9M | \ + NAN_RATE_SET_BIT_12M | NAN_RATE_SET_BIT_18M | \ + NAN_RATE_SET_BIT_24M | NAN_RATE_SET_BIT_36M | \ + NAN_RATE_SET_BIT_48M | NAN_RATE_SET_BIT_54M) + +/* 5G basic: 6M+12M+24M (OFDM) */ +#define NAN_BASIC_RATE_SET_5G (NAN_RATE_SET_BIT_6M | NAN_RATE_SET_BIT_12M | \ + NAN_RATE_SET_BIT_24M) + +/* GF_MODE_DISALLOWED = 2, RIFS_MODE_DISALLOWED = 1 */ +#define NAN_GF_MODE_DISALLOWED 2 +#define NAN_RIFS_MODE_DISALLOWED 1 + +int mt7925_nan_update_phy_setting(struct mt792x_dev *dev) +{ + struct mt76_phy *mphy = &dev->mphy; + struct ieee80211_supported_band *sband_5g; + struct mt7925_nan_phy_setting *phy; + struct { + u8 rsv[4]; + struct mt7925_nan_update_phy_setting_tlv tlv; + } req = {}; + + sband_5g = mphy->hw->wiphy->bands[NL80211_BAND_5GHZ]; + + req.tlv.tag = cpu_to_le16(NAN_UNI_CMD_UPDATE_PHY_SETTING); + req.tlv.len = cpu_to_le16(sizeof(req.tlv)); + + /* 2G: ERP + HT (no CCK/HR_DSSS - NAN uses OFDM only) */ + phy = &req.tlv.phy_2g; + phy->phy_type_set = PHY_TYPE_BIT_ERP | PHY_TYPE_BIT_HT; + phy->non_ht_basic_phy_type = PHY_TYPE_ERP_INDEX; + phy->use_short_preamble = 1; + phy->use_short_slot_time = 1; + phy->operational_rate_set = cpu_to_le16(NAN_RATE_SET_ALL_A); + phy->bss_basic_rate_set = cpu_to_le16(NAN_BASIC_RATE_SET_5G); + phy->gf_operation_mode = cpu_to_le32(NAN_GF_MODE_DISALLOWED); + phy->rifs_operation_mode = cpu_to_le32(NAN_RIFS_MODE_DISALLOWED); + + /* 5G: OFDM + HT + VHT (NAN_MODE_11A) */ + phy = &req.tlv.phy_5g; + phy->phy_type_set = PHY_TYPE_BIT_OFDM | PHY_TYPE_BIT_HT | + PHY_TYPE_BIT_VHT; + phy->non_ht_basic_phy_type = PHY_TYPE_OFDM_INDEX; + phy->use_short_preamble = 1; + phy->use_short_slot_time = 1; + phy->operational_rate_set = cpu_to_le16(NAN_RATE_SET_ALL_A); + phy->bss_basic_rate_set = cpu_to_le16(NAN_BASIC_RATE_SET_5G); + phy->gf_operation_mode = cpu_to_le32(NAN_GF_MODE_DISALLOWED); + phy->rifs_operation_mode = cpu_to_le32(NAN_RIFS_MODE_DISALLOWED); + + /* VHT basic MCS set from sband capability */ + if (sband_5g && sband_5g->vht_cap.vht_supported) + phy->vht_basic_mcs_set = + sband_5g->vht_cap.vht_mcs.rx_mcs_map; + + return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(NAN), + &req, sizeof(req), true); +} + int mt7925_nan_enable(struct ieee80211_vif *vif, struct mt792x_dev *dev, struct cfg80211_nan_conf *conf) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index a0da16adf182..08c13768b357 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -84,6 +84,7 @@ enum nan_uni_cmd_tag { NAN_UNI_CMD_MANAGE_PEER_SCH_RECORD = 12, NAN_UNI_CMD_MAP_STA_RECORD = 13, NAN_UNI_CMD_UPDATE_ULW = 16, + NAN_UNI_CMD_UPDATE_PHY_SETTING = 18, NAN_UNI_CMD_UPDATE_AVAILABILITY_CTRL = 20, NAN_UNI_CMD_UPDATE_PEER_CAPABILITY = 21, NAN_UNI_CMD_CHANGE_NMI_ADDRESS = 24, @@ -440,6 +441,34 @@ struct mt7925_nan_sched_map_sta_rec_tlv { u8 reserved[2]; } __packed __aligned(4); +/* Matches FW NAN_PHY_SETTING_T (enum fields are 4 bytes on ARM) */ +struct mt7925_nan_phy_setting { + u8 phy_type_set; + u8 non_ht_basic_phy_type; + u8 use_short_preamble; + u8 use_short_slot_time; + __le16 operational_rate_set; + __le16 bss_basic_rate_set; + __le16 vht_basic_mcs_set; + u8 erp_protect_mode; + u8 ht_op_info1; + __le16 ht_op_info2; + __le16 ht_op_info3; + __le32 ht_protect_mode; + __le32 gf_operation_mode; + __le32 rifs_operation_mode; +} __packed; + +/* Matches FW NAN_SCHED_CMD_UPDATE_PHY_PARAM_T */ +struct mt7925_nan_update_phy_setting_tlv { + __le16 tag; + __le16 len; + struct mt7925_nan_phy_setting phy_2g; + struct mt7925_nan_phy_setting phy_5g; +} __packed __aligned(4); + +int mt7925_nan_update_phy_setting(struct mt792x_dev *dev); + int mt7925_nan_enable(struct ieee80211_vif *vif, struct mt792x_dev *dev, struct cfg80211_nan_conf *conf); From 86bd20cb500a201318d2008cf346647ce5a311e5 Mon Sep 17 00:00:00 2001 From: Jacobs Wu Date: Mon, 24 Aug 2026 14:52:26 -0500 Subject: [PATCH 1242/2126] wifi: mt76: mt7925: support deferred NAN schedule update and cluster events Send the is_deferred flag in the availability control TLV so FW applies a deferred schedule change at the next DW boundary, and report the NAN_UNI_EVENT_ID_SCHED_UPDATE_DONE and STARTED_CLUSTER events to mac80211 via ieee80211_nan_sched_update_done() and ieee80211_nan_cluster_joined(). Both events arrive on the BH-disabled MCU RX path, where notifying mac80211 inline is wrong: ieee80211_nan_sched_update_done() needs the wiphy mutex and may sleep, and ieee80211_nan_cluster_joined() would fire during NAN_START before mac80211 sets sdata->u.nan.started and before the supplicant subscribes to NL80211_MCGRP_NAN, so the self-anchor cluster-join is lost and a solo anchor master can never publish a service. Deliver both events from a shared nan_deferred_work selected by a pending bitmap instead. The bitmap spinlock is taken with spin_lock_bh() on the RX side, the work re-checks nan_vif under the wiphy mutex, and the stop path clears the bitmap. STARTED_CLUSTER signals new_cluster=true, and JOINED_CLUSTER is corrected to new_cluster=false. Fixes: a5487a682406 ("wifi: mt76: mt7925: add NAN MCU helpers") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Co-developed-by: Stella Liu Signed-off-by: Stella Liu Signed-off-by: Jacobs Wu Link: https://patch.msgid.link/20260824195227.12589-15-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/init.c | 2 + .../net/wireless/mediatek/mt76/mt7925/main.c | 7 ++ .../wireless/mediatek/mt76/mt7925/mt7925.h | 1 + .../net/wireless/mediatek/mt76/mt7925/nan.c | 85 ++++++++++++++++++- .../net/wireless/mediatek/mt76/mt7925/nan.h | 12 ++- .../net/wireless/mediatek/mt76/mt7925/pci.c | 1 + .../net/wireless/mediatek/mt76/mt7925/usb.c | 15 +++- drivers/net/wireless/mediatek/mt76/mt792x.h | 8 ++ 8 files changed, 126 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/init.c b/drivers/net/wireless/mediatek/mt76/mt7925/init.c index cd22fcc021b1..8c3049b66a85 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/init.c @@ -270,6 +270,8 @@ int mt7925_register_device(struct mt792x_dev *dev) INIT_WORK(&dev->reset_work, mt7925_mac_reset_work); INIT_WORK(&dev->init_work, mt7925_init_work); + INIT_WORK(&dev->nan_deferred_work, mt7925_nan_deferred_work); + spin_lock_init(&dev->nan_deferred_lock); INIT_WORK(&dev->phy.roc_work, mt7925_roc_work); timer_setup(&dev->phy.roc_timer, mt792x_roc_timer, 0); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index f58d7fcd58ea..58da8fd0cd5f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -2613,6 +2613,13 @@ static int mt7925_stop_nan(struct ieee80211_hw *hw, struct mt792x_dev *dev = mt792x_hw_dev(hw); int err, ret; + /* Drop a deferred event queued just before stop so a stale cluster_id + * cannot leak into a restart; the work re-checks liveness anyway. + */ + spin_lock_bh(&dev->nan_deferred_lock); + dev->nan_deferred_pending = 0; + spin_unlock_bh(&dev->nan_deferred_lock); + mt792x_mutex_acquire(dev); err = mt7925_nan_disable(vif, dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h index 321e732347f2..33782d9ba9ed 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h @@ -361,6 +361,7 @@ void mt7925_mcu_set_suspend_iter(void *priv, u8 *mac, void mt7925_connac_mcu_set_suspend_iter(void *priv, u8 *mac, struct ieee80211_vif *vif); void mt7925_set_ipv6_ns_work(struct work_struct *work); +void mt7925_nan_deferred_work(struct work_struct *work); int mt7925_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, bool enable); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 445b8bbd7777..5fa0f11d62b6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -454,9 +454,27 @@ mt7925_nan_mcu_handle_de_event(struct mt792x_dev *dev, struct tlv *tlv) dev_dbg(dev->mt76.dev, "nan: evt=%u cluster=%pM\n", de_evt->event_type, de_evt->cluster_id); - if (de_evt->event_type != NAN_EVENT_ID_JOINED_CLUSTER) + if (de_evt->event_type != NAN_EVENT_ID_JOINED_CLUSTER && + de_evt->event_type != NAN_EVENT_ID_STARTED_CLUSTER) return; + /* STARTED_CLUSTER fires during NAN_START, before nan.started is set and + * before the supplicant subscribes - defer past NAN_START via the work + * so ieee80211_nan_cluster_joined() actually reaches userspace. + */ + if (de_evt->event_type == NAN_EVENT_ID_STARTED_CLUSTER) { + dev_dbg(dev->mt76.dev, + "nan: deferring STARTED_CLUSTER cluster=%pM\n", + cluster_id); + spin_lock_bh(&dev->nan_deferred_lock); + memcpy(dev->nan_started_cluster_id, cluster_id, ETH_ALEN); + set_bit(MT7925_NAN_DEFERRED_STARTED_CLUSTER, + &dev->nan_deferred_pending); + spin_unlock_bh(&dev->nan_deferred_lock); + ieee80211_queue_work(dev->mt76.hw, &dev->nan_deferred_work); + return; + } + if (!dev->nan_vif || !ieee80211_vif_nan_started(dev->nan_vif)) { dev_warn(dev->mt76.dev, "nan: joined-cluster event but NAN not started\n"); return; @@ -468,7 +486,43 @@ mt7925_nan_mcu_handle_de_event(struct mt792x_dev *dev, struct tlv *tlv) dev_dbg(dev->mt76.dev, "nan: own_nmi=%pM master_nmi=%pM\n", de_evt->own_nmi, de_evt->master_nmi); - ieee80211_nan_cluster_joined(dev->nan_vif, cluster_id, true, GFP_KERNEL); + /* joined an existing cluster, not a self-anchored new one */ + ieee80211_nan_cluster_joined(dev->nan_vif, cluster_id, false, GFP_KERNEL); +} + +/* Runs the deferred NAN MCU events in process context; takes wiphy_lock + * before nan_vif, which the NAN stop path frees under that mutex. + */ +void +mt7925_nan_deferred_work(struct work_struct *work) +{ + struct mt792x_dev *dev = container_of(work, struct mt792x_dev, + nan_deferred_work); + struct ieee80211_vif *vif; + unsigned long pending; + u8 cluster_id[ETH_ALEN]; + + spin_lock_bh(&dev->nan_deferred_lock); + pending = dev->nan_deferred_pending; + dev->nan_deferred_pending = 0; + memcpy(cluster_id, dev->nan_started_cluster_id, ETH_ALEN); + spin_unlock_bh(&dev->nan_deferred_lock); + + if (!pending) + return; + + wiphy_lock(dev->mt76.hw->wiphy); + vif = dev->nan_vif; + if (!vif || !ieee80211_vif_nan_started(vif)) + goto out; + + if (test_bit(MT7925_NAN_DEFERRED_STARTED_CLUSTER, &pending)) + ieee80211_nan_cluster_joined(vif, cluster_id, true, GFP_KERNEL); + + if (test_bit(MT7925_NAN_DEFERRED_SCHED_UPDATE_DONE, &pending)) + ieee80211_nan_sched_update_done(vif); +out: + wiphy_unlock(dev->mt76.hw->wiphy); } static void @@ -517,6 +571,27 @@ mt7925_nan_handle_ulw_update(struct mt792x_dev *dev, struct tlv *tlv) GFP_KERNEL); } +static void +mt7925_nan_handle_sched_update_done(struct mt792x_dev *dev, struct tlv *tlv) +{ + struct ieee80211_vif *vif; + + if (!dev || !tlv) + return; + + vif = dev->nan_vif; + if (!vif || !ieee80211_vif_nan_started(vif)) + return; + + /* Runs in the BH-disabled MCU-event RX path; the mac80211 helper needs + * the wiphy mutex and may sleep, so hand it to the work instead. + */ + spin_lock_bh(&dev->nan_deferred_lock); + set_bit(MT7925_NAN_DEFERRED_SCHED_UPDATE_DONE, &dev->nan_deferred_pending); + spin_unlock_bh(&dev->nan_deferred_lock); + ieee80211_queue_work(dev->mt76.hw, &dev->nan_deferred_work); +} + void mt7925_nan_mcu_event(struct mt792x_dev *dev, struct sk_buff *skb) { struct tlv *tlv; @@ -548,6 +623,9 @@ void mt7925_nan_mcu_event(struct mt792x_dev *dev, struct sk_buff *skb) case NAN_UNI_EVENT_ID_ULW_UPDATE: mt7925_nan_handle_ulw_update(dev, tlv); break; + case NAN_UNI_EVENT_ID_SCHED_UPDATE_DONE: + mt7925_nan_handle_sched_update_done(dev, tlv); + break; default: break; } @@ -585,6 +663,7 @@ static int mt7925_nan_avail_ctrl_tlv(struct sk_buff *skb, avail_ctrl_tlv->avail_ctrl = cpu_to_le16(ctrl & NAN_AVAIL_CTRL_CHECK_FOR_CHANGED); avail_ctrl_tlv->seq_id = seq_id; + avail_ctrl_tlv->is_deferred = sched->deferred ? 1 : 0; return 0; } @@ -710,7 +789,7 @@ void mt7925_nan_local_sched_changed(struct mt792x_dev *dev, goto out; } - mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(NAN), true); + mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(NAN), false); out: mt792x_mutex_release(dev); } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index 08c13768b357..f9644945a22c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -97,15 +97,25 @@ enum nan_uni_cmd_tag { enum nan_uni_event_tag { NAN_UNI_EVENT_ID_DE_EVENT_IND = 19, NAN_UNI_EVENT_ID_ULW_UPDATE = 39, + NAN_UNI_EVENT_ID_SCHED_UPDATE_DONE = 43, NAN_UNI_EVENT_REPORT_DW_START = 59, NAN_UNI_EVENT_REPORT_DW_END = 60, }; enum nan_disc_event_type { NAN_EVENT_ID_DISC_MAC_ADDR = 0, + NAN_EVENT_ID_STARTED_CLUSTER = 1, NAN_EVENT_ID_JOINED_CLUSTER = 2, }; +/* bit indices into mt792x_dev->nan_deferred_pending, set from the atomic + * MCU-event RX path and consumed by mt7925_nan_deferred_work() + */ +enum mt7925_nan_deferred_event { + MT7925_NAN_DEFERRED_STARTED_CLUSTER, + MT7925_NAN_DEFERRED_SCHED_UPDATE_DONE, +}; + /* NAN 4.0 Table 79. Device Capability attribute format, Supported Bands */ enum nan_supported_bands { NAN_SUPPORTED_BAND_ID_2P4G = 2, @@ -345,7 +355,7 @@ struct mt7925_nan_avail_ctrl_tlv { __le16 len; __le16 avail_ctrl; u8 seq_id; - u8 reserved[1]; + u8 is_deferred; } __packed __aligned(4); struct mt7925_nan_ch_timeline { diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c index 02ef09dd797d..24585c992ff5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c @@ -55,6 +55,7 @@ static void mt7925e_unregister_device(struct mt792x_dev *dev) cancel_delayed_work_sync(&pm->ps_work); cancel_delayed_work_sync(&dev->mlo_pm_work); cancel_work_sync(&pm->wake_work); + cancel_work_sync(&dev->nan_deferred_work); mt7925_tx_token_put(dev); __mt792x_mcu_drv_pmctrl(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/usb.c b/drivers/net/wireless/mediatek/mt76/mt7925/usb.c index 1757023ea70d..afd62a6dbecb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/usb.c @@ -348,6 +348,19 @@ failed: } #endif /* CONFIG_PM */ +static void mt7925u_disconnect(struct usb_interface *usb_intf) +{ + struct mt792x_dev *dev = usb_get_intfdata(usb_intf); + + /* mt792xu_disconnect() ends in mt76_free_device(), so the work has to + * go before it rather than after mt76_unregister_device() as on PCI. + */ + if (dev) + cancel_work_sync(&dev->nan_deferred_work); + + mt792xu_disconnect(usb_intf); +} + MODULE_DEVICE_TABLE(usb, mt7925u_device_table); MODULE_FIRMWARE(MT7925_FIRMWARE_WM); MODULE_FIRMWARE(MT7925_ROM_PATCH); @@ -356,7 +369,7 @@ static struct usb_driver mt7925u_driver = { .name = KBUILD_MODNAME, .id_table = mt7925u_device_table, .probe = mt7925u_probe, - .disconnect = mt792xu_disconnect, + .disconnect = mt7925u_disconnect, #ifdef CONFIG_PM .suspend = mt7925u_suspend, .resume = mt7925u_resume, diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 9efc251cb745..9722d840c1af 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -342,6 +342,14 @@ struct mt792x_dev { struct ieee80211_vif *nan_vif; const struct ieee80211_iface_combination *iface_combinations; int n_iface_combinations; + /* deferred NAN MCU events run out of the atomic RX path on one shared + * work; see mt7925_nan_deferred_work() and enum mt7925_nan_deferred_event + */ + struct work_struct nan_deferred_work; + /* protects @nan_deferred_pending */ + spinlock_t nan_deferred_lock; + unsigned long nan_deferred_pending; + u8 nan_started_cluster_id[ETH_ALEN]; }; static inline struct mt792x_bss_conf * From 3590825b642ccda15690125d82d3d82206671486 Mon Sep 17 00:00:00 2001 From: Jacobs Wu Date: Mon, 24 Aug 2026 14:52:27 -0500 Subject: [PATCH 1243/2126] wifi: mt76: mt7925: fix HT/VHT caps and rates for NAN NDP peers NAN NDP peers were added with bare link_sta caps: no HT cap or QoS flag (so no BA/A-MPDU), no VHT cap / bandwidth / rx_nss, a data BSS phy mode that still read legacy when the firmware built the peer's rate table, and caps filtered down by the currently committed schedule. Push the NAN_DATA BSS phymode before sta_update, force the HT cap and QoS flag, seed VHT80 / bandwidth / rx_nss=2 from the BSS RLM, fix the NDP HT/VHT rate selection and stop filtering the link_sta caps by the schedule, so rate control always sees the peer's real capabilities. Bench (MT7925<->MT7925 NDP, 5 GHz ch149): 866.7M VHT80 MCS9 NSS2 link rate, UDP ~290 Mbit/s. Fixes: 0f3605e4f8de ("wifi: mt76: mt7925: wire up NAN operations") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Jacobs Wu Link: https://patch.msgid.link/20260824195227.12589-16-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/main.c | 19 +++++- .../net/wireless/mediatek/mt76/mt7925/nan.c | 62 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7925/nan.h | 4 ++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 58da8fd0cd5f..c882952f5df1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -964,6 +964,21 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, link_conf = mt792x_vif_to_bss_conf(vif, link_id); + /* NAN_DATA (NDI) peers skip association - fill link_sta caps + * from sband and push BSS_INFO with correct phymode + RLM. + */ + if (vif->type == NL80211_IFTYPE_NAN_DATA) { + struct ieee80211_chanctx_conf *nan_ctx; + + nan_ctx = mt7925_nan_seed_link_sta(dev, link_sta); + mconf->mt76.ctx = nan_ctx; + + ret = mt7925_mcu_add_bss_info(&dev->phy, nan_ctx, + link_conf, link_sta, true); + if (ret) + goto out_pm; + } + /* should update bss info before STA add */ if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) { struct mt792x_link_sta *mlink_bc; @@ -2587,8 +2602,8 @@ static int mt7925_start_nan(struct ieee80211_hw *hw, cfg80211_chandef_create(&link_conf->chanreq.oper, chan, NL80211_CHAN_NO_HT); - err = mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf, - NULL, true); + err = mt7925_mcu_add_bss_info(&dev->phy, NULL, + link_conf, NULL, true); if (err < 0) goto out; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 5fa0f11d62b6..1adef4d52f65 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -267,6 +267,68 @@ int mt7925_nan_update_phy_setting(struct mt792x_dev *dev) &req, sizeof(req), true); } +struct ieee80211_chanctx_conf * +mt7925_nan_seed_link_sta(struct mt792x_dev *dev, + struct ieee80211_link_sta *link_sta) +{ + struct ieee80211_supported_band *sband_2g, *sband_5g; + struct ieee80211_chanctx_conf *nan_ctx = NULL; + struct ieee80211_vif *nan_vif = dev->nan_vif; + + /* Fill HT cap from 2G sband */ + sband_2g = dev->mphy.hw->wiphy->bands[NL80211_BAND_2GHZ]; + sband_5g = dev->mphy.hw->wiphy->bands[NL80211_BAND_5GHZ]; + if (sband_2g) + link_sta->ht_cap = sband_2g->ht_cap; + + link_sta->sta->wme = true; + link_sta->rx_nss = hweight8(dev->mphy.antenna_mask); + + /* Get chanctx from NAN schedule. + * Prefer 5G committed slot for wider BW (VHT), fallback + * to first valid slot if no 5G data slot is scheduled. + */ + if (nan_vif) { + struct ieee80211_nan_channel **slots = + nan_vif->cfg.nan_sched.schedule; + int i; + + for (i = 0; i < CFG80211_NAN_SCHED_NUM_TIME_SLOTS; i++) { + struct ieee80211_chanctx_conf *ctx; + + if (!slots[i] || IS_ERR(slots[i]) || + !slots[i]->chanctx_conf) + continue; + + ctx = slots[i]->chanctx_conf; + if (!nan_ctx) + nan_ctx = ctx; + if (ctx->def.chan->band == NL80211_BAND_5GHZ) { + nan_ctx = ctx; + break; + } + } + } + + /* Capability describes what the device can do and must not be + * filtered by the current schedule - firmware gates the VHT rate + * mode per the data schedule and re-derives it on schedule + * change, which only works if the caps are present up front. + */ + if (sband_5g) + link_sta->vht_cap = sband_5g->vht_cap; + + /* Bandwidth here is the capability ceiling, not the operating + * width - the per-slot operating bandwidth follows the current + * slot channel via the firmware RLM sync, so deriving it from + * the schedule at STA-add time would cap a later 5 GHz schedule + * at the bring-up width. + */ + link_sta->bandwidth = IEEE80211_STA_RX_BW_80; + + return nan_ctx; +} + int mt7925_nan_enable(struct ieee80211_vif *vif, struct mt792x_dev *dev, struct cfg80211_nan_conf *conf) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h index f9644945a22c..9a0cd1d06d45 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.h @@ -479,6 +479,10 @@ struct mt7925_nan_update_phy_setting_tlv { int mt7925_nan_update_phy_setting(struct mt792x_dev *dev); +struct ieee80211_chanctx_conf * +mt7925_nan_seed_link_sta(struct mt792x_dev *dev, + struct ieee80211_link_sta *link_sta); + int mt7925_nan_enable(struct ieee80211_vif *vif, struct mt792x_dev *dev, struct cfg80211_nan_conf *conf); From 3dcb98c5cb51a70750ae8dc006d6d787ca09f425 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sun, 9 Aug 2026 21:53:37 -0700 Subject: [PATCH 1244/2126] wifi: mt76: mt7921: fix lock inversion between dev->mutex and iflist_mtx mt7921_config() holds dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx. mac80211 uses the opposite order: ieee80211_del_virtual_monitor() holds iflist_mtx while calling drv_unassign_vif_chanctx(), and mt792x_unassign_vif_chanctx() takes dev->mutex. Deleting a monitor interface that has a channel assigned reaches the second order and lockdep reports the cycle. The driver side of it: -> #1 (&local->iflist_mtx){+.+.}-{4:4}: __mutex_lock+0xda/0x1070 ieee80211_iterate_interfaces+0x34/0x70 [mac80211] mt7921_config+0xb8/0xe0 [mt7921_common] drv_config+0x63/0x1d0 [mac80211] .config is only reached through drv_config(), which asserts the wiphy mutex, so ieee80211_iterate_active_interfaces_mtx() can be used. It walks the same list under the wiphy mutex and never takes iflist_mtx, which drops the driver's dev->mutex -> iflist_mtx edge. Fixes: cbaa0a404f8d ("mt76: mt7921: fix up the monitor mode") Link: https://lore.kernel.org/linux-wireless/20260730053916.109426-1-lucid_duck@justthetip.ca/ Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260810045338.118923-2-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index 68a059504e83..4559a1a25801 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -652,9 +652,9 @@ static int mt7921_config(struct ieee80211_hw *hw, int radio_idx, u32 changed) } if (changed & IEEE80211_CONF_CHANGE_MONITOR) { - ieee80211_iterate_active_interfaces(hw, - IEEE80211_IFACE_ITER_RESUME_ALL, - mt7921_sniffer_interface_iter, dev); + ieee80211_iterate_active_interfaces_mtx(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7921_sniffer_interface_iter, dev); } out: From 3208623121309a42f878364aff3c770f597d6a70 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sun, 9 Aug 2026 21:53:38 -0700 Subject: [PATCH 1245/2126] wifi: mt76: mt7925: fix lock inversion between dev->mutex and iflist_mtx mt7925_config() has the same inversion as mt7921_config(): it holds dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx, while mac80211 calls drv_unassign_vif_chanctx() with iflist_mtx already held. .config is only reached through drv_config(), which asserts the wiphy mutex, so use ieee80211_iterate_active_interfaces_mtx() here too. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260810045338.118923-3-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index c882952f5df1..210c25d687fc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -840,9 +840,9 @@ static int mt7925_config(struct ieee80211_hw *hw, int radio_idx, u32 changed) } if (changed & IEEE80211_CONF_CHANGE_MONITOR) { - ieee80211_iterate_active_interfaces(hw, - IEEE80211_IFACE_ITER_RESUME_ALL, - mt7925_sniffer_interface_iter, dev); + ieee80211_iterate_active_interfaces_mtx(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7925_sniffer_interface_iter, dev); } out: From 75673ab3c0e4186628e0a76b94443cddfbeca255 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sat, 8 Aug 2026 18:23:09 -0700 Subject: [PATCH 1246/2126] wifi: mt76: mt7921: check drv_pmctrl return in the PCIe reset path mt7921e_mac_reset() ignores the return value of mt792xe_mcu_drv_pmctrl(). When the driver-own handshake fails, __mt792xe_mcu_drv_pmctrl() returns -EIO without reinitialising WPDMA or clearing MT76_STATE_PM, and the reset carries on: it writes the interrupt enable registers, cycles NAPI, resets WPDMA and downloads firmware to a chip the driver does not own. Return the error instead. The call is the first statement in the function, before any teardown, so nothing needs unwinding. Reported-by: moosager Link: https://lore.kernel.org/linux-wireless/anG46qbvCqCHGF-f@fedora.fritz.box/ Fixes: dfc7743de1eb ("mt76: mt7921: refactor mcu.c to be bus independent") Signed-off-by: Devin Wittmayer Tested-by: moosager Link: https://patch.msgid.link/20260809012309.43657-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c index 98b3469ac597..d5c33a0d409c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c @@ -57,7 +57,9 @@ int mt7921e_mac_reset(struct mt792x_dev *dev) { int i, err; - mt792xe_mcu_drv_pmctrl(dev); + err = mt792xe_mcu_drv_pmctrl(dev); + if (err) + return err; mt76_connac_free_pending_tx_skbs(&dev->pm, NULL); From d12a54be2604ecd23a1e9ac863583e34034aadde Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sun, 9 Aug 2026 13:55:59 -0700 Subject: [PATCH 1247/2126] wifi: mt76: mt7925: check drv_pmctrl return in the PCIe reset path mt7925e_mac_reset() ignores the return value of mt792xe_mcu_drv_pmctrl(), unlike the two pmctrl calls later in the same function. When the driver-own handshake fails, __mt792xe_mcu_drv_pmctrl() returns -EIO without reinitialising WPDMA or clearing MT76_STATE_PM, and the reset carries on: it writes the interrupt enable registers, cycles NAPI, resets WPDMA and calls mt7925_run_firmware() on a chip the driver does not own. Return the error instead. The call is the first statement in the function, before MT76_RESET is set and before the TX worker and NAPI are disabled, so nothing needs unwinding. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260809205559.32116-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c index 8477d21abc66..280797fa0d85 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c @@ -73,7 +73,9 @@ int mt7925e_mac_reset(struct mt792x_dev *dev) const struct mt792x_irq_map *irq_map = dev->irq_map; int i, err; - mt792xe_mcu_drv_pmctrl(dev); + err = mt792xe_mcu_drv_pmctrl(dev); + if (err) + return err; mt76_connac_free_pending_tx_skbs(&dev->pm, NULL); From 8d2f5990cd429a2fe5fff05f7acf84d6799d4324 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 27 Aug 2026 18:21:15 +0200 Subject: [PATCH 1248/2126] wifi: mt76: mt7925: restore the reset state when fw_pmctrl fails mt7925e_mac_reset() returns directly when mt792xe_mcu_fw_pmctrl() fails, leaving MT76_RESET set and the TX worker parked. Every other error path jumps to out, which clears both. mt7925_mac_reset_work() clears neither, so once every reset attempt fails there, TX stays blocked until another reset succeeds. Jump to out instead. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Link: https://patch.msgid.link/20260827162115.1449757-1-nbd@nbd.name Acked-by: Lorenzo Bianconi Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c index 280797fa0d85..67eb86746779 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c @@ -127,7 +127,7 @@ int mt7925e_mac_reset(struct mt792x_dev *dev) err = mt792xe_mcu_fw_pmctrl(dev); if (err) - return err; + goto out; err = __mt792xe_mcu_drv_pmctrl(dev); if (err) From 0e6472108d51a42272332f5b6a95871244b64301 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sat, 29 Aug 2026 23:42:00 -0700 Subject: [PATCH 1249/2126] wifi: mt76: mt7921: fix the lock inversion in suspend and resume Same inversion as the config path, same one word fix, missed the first time. Both are called with the wiphy mutex held, so the walk can rely on that instead of taking the list mutex. No new splat: same class pair as the accepted fix, and lockdep reports a pair once per boot. Fixes: ffa1bf97425b ("mt76: mt7921: introduce PM support") Link: https://patch.msgid.link/20260810045338.118923-2-lucid_duck@justthetip.ca Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260830064201.92285-2-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index 4559a1a25801..e3cf195cced5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -1156,10 +1156,10 @@ static int mt7921_suspend(struct ieee80211_hw *hw, mt792x_mutex_acquire(dev); clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); - ieee80211_iterate_active_interfaces(hw, - IEEE80211_IFACE_ITER_RESUME_ALL, - mt7921_mcu_set_suspend_iter, - &dev->mphy); + ieee80211_iterate_active_interfaces_mtx(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7921_mcu_set_suspend_iter, + &dev->mphy); mt792x_mutex_release(dev); @@ -1174,10 +1174,10 @@ static int mt7921_resume(struct ieee80211_hw *hw) mt792x_mutex_acquire(dev); set_bit(MT76_STATE_RUNNING, &phy->mt76->state); - ieee80211_iterate_active_interfaces(hw, - IEEE80211_IFACE_ITER_RESUME_ALL, - mt76_connac_mcu_set_suspend_iter, - &dev->mphy); + ieee80211_iterate_active_interfaces_mtx(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt76_connac_mcu_set_suspend_iter, + &dev->mphy); ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, MT792x_WATCHDOG_TIME); From a105a9fe9a07a56d1e0b5a6978a49cde2ac7e7be Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sat, 29 Aug 2026 23:42:01 -0700 Subject: [PATCH 1250/2126] wifi: mt76: mt7925: fix the lock inversion in suspend and resume Same as the previous patch, other driver. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260830064201.92285-3-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 210c25d687fc..1693164b0991 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -1732,10 +1732,10 @@ static int mt7925_suspend(struct ieee80211_hw *hw, mt792x_mutex_acquire(dev); clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); - ieee80211_iterate_active_interfaces(hw, - IEEE80211_IFACE_ITER_RESUME_ALL, - mt7925_mcu_set_suspend_iter, - &dev->mphy); + ieee80211_iterate_active_interfaces_mtx(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7925_mcu_set_suspend_iter, + &dev->mphy); mt792x_mutex_release(dev); @@ -1750,10 +1750,10 @@ static int mt7925_resume(struct ieee80211_hw *hw) mt792x_mutex_acquire(dev); set_bit(MT76_STATE_RUNNING, &phy->mt76->state); - ieee80211_iterate_active_interfaces(hw, - IEEE80211_IFACE_ITER_RESUME_ALL, - mt7925_mcu_set_suspend_iter, - &dev->mphy); + ieee80211_iterate_active_interfaces_mtx(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7925_mcu_set_suspend_iter, + &dev->mphy); ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, MT792x_WATCHDOG_TIME); From fbd12e8dabc8a9d2e81f427906749b4cff85d641 Mon Sep 17 00:00:00 2001 From: Mark Anthony Agarro Date: Wed, 26 Aug 2026 05:27:55 -0400 Subject: [PATCH 1251/2126] wifi: mt76: mt76x02: validate TX-status rate index before mac80211 handoff mt76x02_mac_process_tx_rate() extracts the rate index straight from the hardware's raw TX-status word with no bounds check for the HT/HT_GF/VHT cases, and mt76x02_mac_fill_tx_status() ignores its return value. A stale or corrupt hardware index reaches mac80211's minstrel_ht rate control, whose per-group rate array is a fixed 10 entries (MCS_GROUP_RATES), causing an out-of-bounds write. Validate the index in mt76x02_mac_process_tx_rate() (HT: 0-31, VHT: MCS nibble 0-9) and have mt76x02_mac_fill_tx_status() bail out cleanly on failure instead of passing an invalid index through. Fixes: 7c1f88812690 ("mt76: unify send_tx_status and related helpers") Cc: stable@vger.kernel.org Tested-by: Devin Wittmayer Signed-off-by: Mark Anthony Agarro Link: https://patch.msgid.link/20260826092755.480190-1-markanthonyagarro@gmail.com Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt76x02_mac.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c index 21f8b1e64101..231685bb62d2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c @@ -302,10 +302,14 @@ mt76x02_mac_process_tx_rate(struct ieee80211_tx_rate *txrate, u16 rate, txrate->flags |= IEEE80211_TX_RC_GREEN_FIELD; fallthrough; case MT_PHY_TYPE_HT: + if (idx > 31) + return -EINVAL; txrate->flags |= IEEE80211_TX_RC_MCS; txrate->idx = idx; break; case MT_PHY_TYPE_VHT: + if ((idx & 0xf) > 9) + return -EINVAL; txrate->flags |= IEEE80211_TX_RC_VHT_MCS; txrate->idx = idx; break; @@ -493,18 +497,21 @@ mt76x02_mac_fill_tx_status(struct mt76x02_dev *dev, struct mt76x02_sta *msta, first_rate = st->rate & ~MT_PKTID_RATE; first_rate |= st->pktid & MT_PKTID_RATE; - mt76x02_mac_process_tx_rate(&rate[0], first_rate, - dev->mphy.chandef.chan->band); + if (mt76x02_mac_process_tx_rate(&rate[0], first_rate, + dev->mphy.chandef.chan->band)) + return; } else if (rate[0].idx < 0) { if (!msta) return; - mt76x02_mac_process_tx_rate(&rate[0], msta->wcid.tx_info, - dev->mphy.chandef.chan->band); + if (mt76x02_mac_process_tx_rate(&rate[0], msta->wcid.tx_info, + dev->mphy.chandef.chan->band)) + return; } - mt76x02_mac_process_tx_rate(&last_rate, st->rate, - dev->mphy.chandef.chan->band); + if (mt76x02_mac_process_tx_rate(&last_rate, st->rate, + dev->mphy.chandef.chan->band)) + return; for (i = 0; i < ARRAY_SIZE(info->status.rates); i++) { retry--; From 31b53a9c4ada2ce49201ed0da0105819acfd86bf Mon Sep 17 00:00:00 2001 From: Mark Anthony Agarro Date: Wed, 26 Aug 2026 05:17:57 -0400 Subject: [PATCH 1252/2126] wifi: mt76: mt7925: honour mac80211's FIF_FCSFAIL instead of hardcoding drop_err mt7925_mcu_config_sniffer() hardcodes drop_err = 1, ignoring what mac80211 actually requested via configure_filter(). FIF_FCSFAIL is computed there but discarded instead of persisted. Persist the FCSFAIL bit on the phy in mt7925_configure_filter() and read it back in mt7925_mcu_config_sniffer() to derive drop_err, so the firmware sniffer only passes through unfiltered/marginal frames when a monitor listener actually requested them. mt7925_mcu_config_sniffer() is only reached from mt7925_change_chanctx(), which is itself only exercised on a monitor-mode chanctx, so this stays scoped to monitor mode. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Tested-by: Devin Wittmayer Signed-off-by: Mark Anthony Agarro Link: https://patch.msgid.link/20260826091757.469953-1-markanthonyagarro@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 7 +++---- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h | 5 +++++ drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 1693164b0991..d124d4666707 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -856,11 +856,8 @@ static void mt7925_configure_filter(struct ieee80211_hw *hw, unsigned int *total_flags, u64 multicast) { -#define MT7925_FILTER_FCSFAIL BIT(2) -#define MT7925_FILTER_CONTROL BIT(5) -#define MT7925_FILTER_OTHER_BSS BIT(6) -#define MT7925_FILTER_ENABLE BIT(31) struct mt792x_dev *dev = mt792x_hw_dev(hw); + struct mt792x_phy *phy = mt792x_hw_phy(hw); u32 flags = MT7925_FILTER_ENABLE; #define MT7925_FILTER(_fif, _type) do { \ @@ -872,6 +869,8 @@ static void mt7925_configure_filter(struct ieee80211_hw *hw, MT7925_FILTER(FIF_CONTROL, CONTROL); MT7925_FILTER(FIF_OTHER_BSS, OTHER_BSS); + phy->rxfilter = flags; + mt792x_mutex_acquire(dev); mt7925_mcu_set_rxfilter(dev, flags, 0, 0); mt792x_mutex_release(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index 2afd3f5e3266..698b649edccc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -2356,7 +2356,7 @@ int mt7925_mcu_config_sniffer(struct mt792x_vif *vif, .len = cpu_to_le16(sizeof(req.tlv)), .control_ch = chandef->chan->hw_value, .center_ch = ieee80211_frequency_to_channel(freq1), - .drop_err = 1, + .drop_err = !(vif->phy->rxfilter & MT7925_FILTER_FCSFAIL), }, }; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h index 33782d9ba9ed..cc4270863ebd 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h @@ -7,6 +7,11 @@ #include "../mt792x.h" #include "regs.h" +#define MT7925_FILTER_FCSFAIL BIT(2) +#define MT7925_FILTER_CONTROL BIT(5) +#define MT7925_FILTER_OTHER_BSS BIT(6) +#define MT7925_FILTER_ENABLE BIT(31) + #define MT7925_BEACON_RATES_TBL 25 #define MT7925_TX_RING_SIZE 2048 diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 9722d840c1af..49c7b6958480 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -214,6 +214,7 @@ struct mt792x_phy { s16 coverage_class; u8 slottime; + u32 rxfilter; u32 rx_ampdu_ts; u32 ampdu_ref; From f8794eb3ff6dedbba0337c5197626b62da0ef057 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Wed, 26 Aug 2026 16:10:29 -0700 Subject: [PATCH 1253/2126] wifi: mt76: mt7921: honour FIF_FCSFAIL instead of hardcoding drop_err When a monitor interface asks to see frames that failed their checksum, mac80211 passes the request down to the driver. mt7921 works out the answer, sends it to the firmware as a receive filter, and then configures the sniffer with a hardcoded byte telling it to drop those frames anyway. The answer is used once and never kept, so the sniffer never gets to see it. That matters to anyone using monitor mode to judge a link honestly, which is most of the reason to be in monitor mode at all. Mark Anthony Agarro posted the same change for mt7925: keep what mac80211 asked for on the phy, and read it back when the sniffer is configured. This does that for mt7921, and applies on top of it, since that patch is what adds the field. https://lore.kernel.org/linux-wireless/20260826091757.469953-1-markanthonyagarro@gmail.com/ The stored value is read in one place only, configuring the sniffer, which has a single caller, and that call sits inside a branch reached only by a monitor interface. Nothing else changes. Measured on an MT7922 with a read-only probe on the command as the driver sends it, so these are the driver's own bytes rather than an inference from what came back: request arm drop_err none stock 1 1 1 1 none patched 1 1 1 1 fcsfail stock 1 1 fcsfail patched 0 0 Stock sends the drop byte whether or not anyone asked for it. Patched sends it only when nobody did. Withdrawing the request and making it again inside one driver load moves the byte back and forth, 0 then 1 then 0 across three changes, so nothing sticks once set. If it does appear to stick when trying this against an MT7927, that is mac80211 rather than the driver. It raises the filter count unconditionally when a monitor comes up, but skips lowering it again for drivers that set NO_VIRTUAL_MONITOR, and that is the only chip in this family which does. Fixes: 914189af23b8 ("wifi: mt76: mt7921: fix channel switch fail in monitor mode") Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260826231029.39632-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 8 +++----- drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h | 5 +++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index e3cf195cced5..d0f6460c7fd8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -668,12 +668,8 @@ static void mt7921_configure_filter(struct ieee80211_hw *hw, unsigned int *total_flags, u64 multicast) { -#define MT7921_FILTER_FCSFAIL BIT(2) -#define MT7921_FILTER_CONTROL BIT(5) -#define MT7921_FILTER_OTHER_BSS BIT(6) -#define MT7921_FILTER_ENABLE BIT(31) - struct mt792x_dev *dev = mt792x_hw_dev(hw); + struct mt792x_phy *phy = mt792x_hw_phy(hw); u32 flags = MT7921_FILTER_ENABLE; #define MT7921_FILTER(_fif, _type) do { \ @@ -685,6 +681,8 @@ static void mt7921_configure_filter(struct ieee80211_hw *hw, MT7921_FILTER(FIF_CONTROL, CONTROL); MT7921_FILTER(FIF_OTHER_BSS, OTHER_BSS); + phy->rxfilter = flags; + mt792x_mutex_acquire(dev); mt7921_mcu_set_rxfilter(dev, flags, 0, 0); mt792x_mutex_release(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c index 40546005c743..c90d0da706a1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -1231,7 +1231,7 @@ int mt7921_mcu_config_sniffer(struct mt792x_vif *vif, .len = cpu_to_le16(sizeof(req.tlv)), .control_ch = chandef->chan->hw_value, .center_ch = ieee80211_frequency_to_channel(freq1), - .drop_err = 1, + .drop_err = !(vif->phy->rxfilter & MT7921_FILTER_FCSFAIL), }, }; if (chandef->chan->band < ARRAY_SIZE(ch_band)) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h index fb8654b7c5e7..f7ed11353d28 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h @@ -7,6 +7,11 @@ #include "../mt792x.h" #include "regs.h" +#define MT7921_FILTER_FCSFAIL BIT(2) +#define MT7921_FILTER_CONTROL BIT(5) +#define MT7921_FILTER_OTHER_BSS BIT(6) +#define MT7921_FILTER_ENABLE BIT(31) + #define MT7921_MAX_AID 20 #define MT7921_TX_RING_SIZE 2048 From 022f5f8b7a0580da50fcbc34da853d03d4321fe2 Mon Sep 17 00:00:00 2001 From: Zhao Li Date: Tue, 25 Aug 2026 19:26:20 +0800 Subject: [PATCH 1254/2126] wifi: mt76: mt7996: unlink TWT flow if the MCU rejects the agreement mt7996_mac_add_twt_setup() links a new flow into dev->twt_list before asking the MCU to add the agreement, but exits without unlinking the flow if the request fails. The flow-ID and table masks are only committed after MCU success, so the still-linked flow is invisible to the mask-gated teardown paths. If the station retries the setup, the same slot is cleared and its embedded list node reinitialized while it is still linked, corrupting dev->twt_list. If the station disassociates instead, teardown skips the flow and station storage can be freed while the node remains linked. A later scheduling or debugfs twt_stats walk can then dereference the freed flow, resulting in a use-after-free. Unlink the flow when the MCU rejects the agreement. This restores the list to its pre-request state while leaving the unchanged mask and agreement accounting untouched. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20260729173632.14387-3-enderaoelyther@gmail.com/ Assisted-by: Codex:gpt-5.6-sol Assisted-by: Kimi:K3 Signed-off-by: Zhao Li Link: https://patch.msgid.link/20260825112620.97568-1-enderaoelyther@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index 898cd9b8ff96..a8c4f629109b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -3288,8 +3288,10 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, flow->tsf = le64_to_cpu(twt_agrt->twt); if (mt7996_mcu_twt_agrt_update(dev, &msta->vif->deflink, flow, - MCU_TWT_AGRT_ADD)) + MCU_TWT_AGRT_ADD)) { + list_del(&flow->list); goto unlock; + } setup_cmd = TWT_SETUP_CMD_ACCEPT; dev->twt.table_mask |= BIT(table_id); From f7517b3d8b7f1008e07edcb8bb692c6ca53ef23b Mon Sep 17 00:00:00 2001 From: Mark Anthony Agarro Date: Thu, 13 Aug 2026 08:20:59 -0700 Subject: [PATCH 1255/2126] wifi: mt76: mt7615: do not tear down BSS/STA state for monitor vifs Tearing down a monitor interface oopses: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:mt76_connac_mcu_uni_add_bss+0x144/0x370 [mt76_connac_lib] Call Trace: mt7615_remove_interface+0x6a/0x200 [mt7615_common] drv_remove_interface+0x60/0x140 [mac80211] ieee80211_del_virtual_monitor+0x8f/0xc0 [mac80211] ieee80211_do_open+0x550/0x7d0 [mac80211] ieee80211_open+0xaa/0xb0 [mac80211] __dev_open+0x11b/0x280 mt7615_remove_interface() tears down BSS and STA state for every vif type. On MT7663 with offload firmware that reaches mt76_connac_mcu_uni_add_bss(), which has no monitor case in its iftype switch. It takes WARN_ON(1), then copies ETH_ALEN from vif->bss_conf.bssid, which is NULL for a monitor vif. mt76_connac_mcu_bss_basic_tlv() in the same file handles this. It has an NL80211_IFTYPE_MONITOR case and it copies phy->macaddr in place of the bssid. The uni variant has neither. There is nothing to tear down. mt7615_add_interface() only calls mt7615_mcu_add_dev_info(). The BSS and STA state comes from beacon enable in mt7615_bss_info_changed(), from mt7615_set_key() and from mt7615_mac_sta_add(), so a monitor vif never has any. Reported on mt7615e going from monitor back to managed, and on mt7663u on an "ip link set down", both through ieee80211_del_virtual_monitor(). Fixes: d9852ab2f362 ("mt76: mt7615: keep mcu_add_bss_info enabled till interface removal") Cc: stable@vger.kernel.org Reported-by: Orly Orge Closes: https://lore.kernel.org/linux-wireless/CANj5C4mTOHs6riyWee=dFdkE5p=714J8xs-x3hq3ewQ+r6O_Nw@mail.gmail.com/ Reported-by: Inanix Closes: https://github.com/morrownr/mt76/issues/79 Tested-by: Inanix Signed-off-by: Mark Anthony Agarro Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260813152059.15747-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index 67f56e428d9a..175e847f49ef 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -254,8 +254,10 @@ static void mt7615_remove_interface(struct ieee80211_hw *hw, mt7615_mutex_acquire(dev); - mt7615_mcu_add_bss_info(phy, vif, NULL, false); - mt7615_mcu_sta_add(phy, vif, NULL, false); + if (vif->type != NL80211_IFTYPE_MONITOR) { + mt7615_mcu_add_bss_info(phy, vif, NULL, false); + mt7615_mcu_sta_add(phy, vif, NULL, false); + } mt76_testmode_reset(phy->mt76, true); if (vif == phy->monitor_vif) From f5dd4833463ed45794027e33928539b3c532f82d Mon Sep 17 00:00:00 2001 From: Eason Lai Date: Mon, 14 Sep 2026 10:19:19 +0800 Subject: [PATCH 1256/2126] wifi: mt76: mt792x: fix UAF in SDIO TX path when out of memory Using __skb_pad() instead of skb_pad() in mt76_skb_adjust_pad() to prevent double-free, as the caller handles cleanup. Free the MCU message skb in __mt76x02u_mcu_send_msg() as well, which relied on skb_pad() to release it. Fixes: 808f2767d421 ("wifi: mt76: mt792x: Fix memory leak in SDIO TX path") Cc: stable@vger.kernel.org Closes: https://github.com/morrownr/mt76/issues/83 Co-developed-by: Devin Wittmayer Signed-off-by: Devin Wittmayer Signed-off-by: Eason Lai Link: https://patch.msgid.link/20260914021920.32246-2-eason.lai@mediatek.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/tx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c index 968c73e06a5f..6f931d483bd6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c @@ -90,7 +90,7 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb, MT_MCU_MSG_TYPE_CMD; ret = mt76x02u_skb_dma_info(skb, CPU_TX_PORT, info); if (ret) - return ret; + goto out; ret = mt76u_bulk_msg(dev, skb->data, skb->len, NULL, 500, MT_EP_OUT_INBAND_CMD); diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c index b1e894b19cbd..f199f33653d6 100644 --- a/drivers/net/wireless/mediatek/mt76/tx.c +++ b/drivers/net/wireless/mediatek/mt76/tx.c @@ -884,7 +884,7 @@ int mt76_skb_adjust_pad(struct sk_buff *skb, int pad) } } - if (skb_pad(last, pad)) + if (__skb_pad(last, pad, false)) return -ENOMEM; __skb_put(last, pad); From 82856da2d3b6a30011f4db6ea5f34c13484e0ef8 Mon Sep 17 00:00:00 2001 From: Eason Lai Date: Mon, 14 Sep 2026 10:19:20 +0800 Subject: [PATCH 1257/2126] wifi: mt76: fix memory leak in USB TX path When errors occur in mt76u_tx_queue_skb(), the skb is not properly freed, leading to memory leaks. This happens when: - The queue is full - tx_prepare_skb() drops zero-length frames (such as WMM NULL frames) to prevent hardware TX hangs - Buffer setup fails Fix by properly releasing the skb with ieee80211_tx_status_ext() when the queue is full or tx_prepare_skb() fails, and using mt76_tx_complete_skb() when mt76u_tx_setup_buffers() fails (since tx_prepare_skb() has already succeeded and may have allocated resources that need cleanup) Fixes: b40b15e1521f ("mt76: add usb support to mt76 layer") Cc: stable@vger.kernel.org Tested-by: Devin Wittmayer Closes: https://github.com/morrownr/mt76/issues/83 Signed-off-by: Eason Lai Tested-by: Hans Buchheim Reported-by: Sergei Melnichenko Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260914021920.32246-3-eason.lai@mediatek.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/usb.c | 31 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index a9af3aa6b80a..dfc12f6944a7 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -893,6 +893,9 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, enum mt76_txq_id qid, struct sk_buff *skb, struct mt76_wcid *wcid, struct ieee80211_sta *sta) { + struct ieee80211_tx_status status = { + .sta = sta, + }; struct mt76_tx_info tx_info = { .skb = skb, }; @@ -900,17 +903,27 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, u16 idx = q->head; int err; - if (q->queued == q->ndesc) - return -ENOSPC; + if (q->queued == q->ndesc) { + err = -ENOSPC; + goto err_free_skb; + } skb->prev = skb->next = NULL; err = dev->drv->tx_prepare_skb(dev, NULL, qid, wcid, sta, &tx_info); if (err < 0) - return err; + goto err_free_skb; err = mt76u_tx_setup_buffers(dev, tx_info.skb, q->entry[idx].urb); - if (err < 0) - return err; + if (err < 0) { + /* + * mt76_tx_status_skb_get() walks the idr and dereferences + * a freed skb. This SKB is not counted in non-AQL counter + * due to error return, so using 0xffff as wcid to keep + * balanced. + */ + mt76_tx_complete_skb(dev, 0xffff, tx_info.skb); + goto err_ret; + } mt76u_fill_bulk_urb(dev, USB_DIR_OUT, q->ep, q->entry[idx].urb, mt76u_complete_tx, &q->entry[idx]); @@ -921,6 +934,14 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, q->queued++; return idx; + +err_free_skb: + status.skb = tx_info.skb; + spin_lock_bh(&dev->rx_lock); + ieee80211_tx_status_ext(dev->hw, &status); + spin_unlock_bh(&dev->rx_lock); +err_ret: + return err; } static void mt76u_tx_kick(struct mt76_dev *dev, struct mt76_queue *q) From 7907d5270dc5c13b6a95754c08a77d5b06bbc786 Mon Sep 17 00:00:00 2001 From: Myeonghun Pak Date: Thu, 10 Sep 2026 17:54:41 -0400 Subject: [PATCH 1258/2126] wifi: mt76: mt7615: restore DBDC state after ext PHY failure mt7615_register_ext_phy() limits the primary PHY to DBDC capabilities before allocating and registering the secondary PHY. If allocation, EEPROM override, or PHY registration fails, it returns without restoring the primary PHY capabilities. The EEPROM override failure also leaks the newly allocated ieee80211_hw. Route all failures through common labels that free the secondary hardware when it was allocated and restore the primary PHY capabilities. This issue was identified during our ongoing static-analysis research while reviewing kernel code. Fixes: 0f2173f093b3 ("mt76: mt7615: add support for registering a second wiphy via debugfs") Cc: stable@vger.kernel.org Co-developed-by: Ijae Kim Signed-off-by: Ijae Kim Signed-off-by: Myeonghun Pak Link: https://patch.msgid.link/20260910215441.76683-1-mhun512@gmail.com Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7615/init.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c index e437e088b2e9..665b0f1e939f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c @@ -541,8 +541,10 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev) mt7615_cap_dbdc_enable(dev); mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7615_ops, MT_BAND1); - if (!mphy) - return -ENOMEM; + if (!mphy) { + ret = -ENOMEM; + goto error; + } phy = mphy->priv; phy->dev = dev; @@ -572,7 +574,7 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev) ret = mt76_eeprom_override(mphy); if (ret) - return ret; + goto error_free_hw; /* second phy can only handle 5 GHz */ mphy->cap.has_5ghz = true; @@ -590,7 +592,14 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev) ret = mt76_register_phy(mphy, true, mt76_rates, ARRAY_SIZE(mt76_rates)); if (ret) - ieee80211_free_hw(mphy->hw); + goto error_free_hw; + + return 0; + +error_free_hw: + ieee80211_free_hw(mphy->hw); +error: + mt7615_cap_dbdc_disable(dev); return ret; } From a2d1c02c59f84e982179751bced5fb2fd5bb4212 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 21 Aug 2026 09:00:01 +0000 Subject: [PATCH 1259/2126] wifi: mt76: mt7915: publish wcid before MCU add commands mt7915_add_interface() enables the BSS/STA in firmware via mt7915_mcu_add_bss_info() and mt7915_mcu_add_sta() before publishing dev->mt76.wcid[idx] with rcu_assign_pointer(). Firmware can start generating tx-status/tx-free events referencing that wcid as soon as it processes those MCU commands, but mt76's rx/tx-free handlers (e.g. mt7915_mac_tx_free()) look up dev->mt76.wcid[idx] to service them, and won't find it published yet. This can lead to memory corruption and kernel crashes shortly after an AP interface is brought up. This ordering was introduced by commit 8e3e7567b8c1 ("mt76: mt7915: add sta_rec with EXTRA_INFO_NEW for the first time only"): mt7915_mcu_add_sta() derived its "newly added" flag from !rcu_access_pointer(dev->mt76.wcid[idx]), so the publish had to happen after that call. Commit 33eb14f10290 ("wifi: mt76: mt7915: use mac80211 .sta_state op") later replaced that flag with a caller-supplied `newly` argument to mt7915_mcu_add_sta(), now simply hardcoded to true, so the ordering is no longer required. Move the rcu_assign_pointer() before the MCU add_bss_info/add_sta calls, so that the wcid is visible to lookups before firmware is told it's live. This makes the ordering symmetric with mt7915_remove_interface(), which keeps the pointer published until after the MCU disable commands have been issued. Closes: https://github.com/openwrt/openwrt/issues/24594 Fixes: 8e3e7567b8c1 ("mt76: mt7915: add sta_rec with EXTRA_INFO_NEW for the first time only") Signed-off-by: Ryan Leung Link: https://patch.msgid.link/20260821-mt7915-wcid-publish-order-v2-1-acf0b7f32cbd@protonmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c index a8286f8becf9..9c6c339f1b38 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c @@ -273,9 +273,9 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, mt7915_init_bitrate_mask(vif); memset(&mvif->cap, -1, sizeof(mvif->cap)); + rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); mt7915_mcu_add_bss_info(phy, vif, true); mt7915_mcu_add_sta(dev, vif, NULL, CONN_STATE_PORT_SECURE, true); - rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); mutex_unlock(&dev->mt76.mutex); From cfb05250ded4d6de09dfd273c2a72092f48b55a3 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 21 Aug 2026 11:42:49 +0000 Subject: [PATCH 1260/2126] wifi: mt76: fix unlocked wcid check in mt76_tx_status_skb_add() mt76_tx_status_skb_add() checks rcu_access_pointer(dev->wcid[wcid->idx]) before taking dev->status_lock, then allocates a pktid afterwards. A concurrent mt76_wcid_cleanup() can run between the check and the lock, letting a stale wcid be re-added to dev->wcid_list after teardown. Worse, the check only tests for a non-NULL slot, so it also passes if a different wcid has since been published at the same idx. Move the check under status_lock, alongside idr_alloc(), and compare identity (rcu_access_pointer(dev->wcid[wcid->idx]) != wcid) instead of just testing for non-NULL, so that a reused index is correctly rejected. Fixes: fcfe1b5e162b ("mt76: fix tx status related use-after-free race on station removal") Signed-off-by: Ryan Leung Link: https://patch.msgid.link/20260821-mt76-stale-wcid-race-v2-1-8f41ee96fb73@protonmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/tx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c index f199f33653d6..7abe8f3346bc 100644 --- a/drivers/net/wireless/mediatek/mt76/tx.c +++ b/drivers/net/wireless/mediatek/mt76/tx.c @@ -129,7 +129,7 @@ mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid, memset(cb, 0, sizeof(*cb)); - if (!wcid || !rcu_access_pointer(dev->wcid[wcid->idx])) + if (!wcid) return MT_PACKET_ID_NO_ACK; if (info->flags & IEEE80211_TX_CTL_NO_ACK) @@ -147,6 +147,11 @@ mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid, spin_lock_bh(&dev->status_lock); + if (rcu_access_pointer(dev->wcid[wcid->idx]) != wcid) { + pid = MT_PACKET_ID_NO_ACK; + goto out; + } + pid = idr_alloc(&wcid->pktid, skb, MT_PACKET_ID_FIRST, MT_PACKET_ID_MASK, GFP_ATOMIC); if (pid < 0) { From 5cebbd7a87df834efe002c8e54211e6adc99703a Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 21 Aug 2026 13:26:43 +0000 Subject: [PATCH 1261/2126] wifi: mt76: fix wcid teardown ordering in mt76_reset_device() mt76_reset_device() tears down each wcid's pktid idr before clearing dev->wcid[i], which is the reverse of the ordering used on the sta removal path. Until the pointer is cleared, a concurrent lookup under status_lock can still find the wcid and access its already destroyed idr. Clear dev->wcid[i] before calling mt76_wcid_cleanup(), reproducing the ordering mac80211 already enforces for normal sta removal (where mt76_sta_pre_rcu_remove() clears dev->wcid[idx] before mt76_wcid_cleanup() runs via the .sta_state callback). Fixes: 065c79df595a ("wifi: mt76: mt7915: fix list corruption after hardware restart") Signed-off-by: Ryan Leung Link: https://patch.msgid.link/20260821-mt76-wcid-null-before-cleanup-v1-1-0e364d9062d6@protonmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 9dd93f90de40..0e45533ea89c 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -856,8 +856,8 @@ void mt76_reset_device(struct mt76_dev *dev) continue; wcid->sta = 0; - mt76_wcid_cleanup(dev, wcid); rcu_assign_pointer(dev->wcid[i], NULL); + mt76_wcid_cleanup(dev, wcid); } rcu_read_unlock(); From e9fd0a209ff7f646e6ce9221a73c92c4912175c7 Mon Sep 17 00:00:00 2001 From: Charlie-cy Wu Date: Wed, 30 Sep 2026 16:31:02 +0800 Subject: [PATCH 1262/2126] wifi: mt76: connac2: fill TXD spe_idx for connac2 fixed-rate frames On connac2 chipsets - MT7920, MT7921 and MT7922 - the spe_idx of fixed-rate frames was never programmed, so every management frame - auth and assoc req included - went out 1SS 1T on WF0 instead of 1SS 2T duplicate, giving up ~3dB of array gain during connection setup, which is exactly when the link budget is worst. mt76_connac2_mac_write_txwi() takes the MT_TXD2_FIX_RATE path for any non-data frame, but the block filling MT_TXD7_SPE_IDX was guarded by !is_connac2(), leaving the field at 0. As spe_idx 0 also encodes "WF0" the hardware happily transmitted on a single path. Drop the guard so connac2 fills the index like the other generations do. Do not set MT_TXD6_SPE_ID_IDX along with it: on connac2 that bit points the hardware at the WTBL instead of the TXD, and the WTBL spe_idx is still 0 while connecting, so setting it puts the frames back on WF0. This matches connac3, where SPE_IXD_SELECT_TXD is 0 and SPE_IXD_SELECT_BMC_WTBL is 1, and is the opposite of what the falcon firmware macro name HAL_MAC_TX_DESC_SET_FR_SPE_IDX_SPE_BY_TXD suggests. Guard the duplicate fallback with hweight8() as well: ant_to_spe[] maps a single-antenna mask to 0 too, so without the check a user asking for one antenna would still get spe_idx 24 and duplicate onto both paths. Verified on MT7922: TXD DW7 spe_idx now reads 0x18 and the in-chip sniffer reports spe_idx 0x18 in the TXV of auth and assoc req, where it previously reported 0x0. MT7920 and MT7921 share the same connac2 TXD path and are fixed by the same change. Fixes: 5c81a4f182d9 ("wifi: mt76: connac: use is_connac2() to replace is_mt7921() checks") Signed-off-by: Charlie-cy Wu Link: https://patch.msgid.link/20260930083103.1284937-1-jb.tsai@mediatek.com Signed-off-by: Felix Fietkau --- .../wireless/mediatek/mt76/mt76_connac_mac.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c index 8a8d608dd56e..8481eac8d783 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c @@ -600,6 +600,7 @@ void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi, vif ? &vif->bss_conf : NULL, beacon, multicast); u32 val = MT_TXD6_FIXED_BW; + u8 spe_idx = mt76_connac_spe_idx(mphy->antenna_mask); /* hardware won't add HTC for mgmt/ctrl frame */ txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD); @@ -608,13 +609,18 @@ void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi, txwi[6] |= cpu_to_le32(val); txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE); - if (!is_connac2(dev)) { - u8 spe_idx = mt76_connac_spe_idx(mphy->antenna_mask); - - if (!spe_idx) - spe_idx = 24 + phy_idx; - txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, spe_idx)); - } + /* Fixed-rate frames (all mgmt, so auth/assoc req too) otherwise + * carry spe_idx 0 and TX 1SS 1T on WF0. Fill spe_idx like the + * other connac generations do, but do NOT touch + * MT_TXD6_SPE_ID_IDX: on connac2 setting it points HW at the + * WTBL and the index below is ignored. + * + * spe_idx 0 is also a valid single-path index (WF0), so only + * take the duplicate fallback when a second path exists. + */ + if (!spe_idx && hweight8(mphy->antenna_mask) > 1) + spe_idx = 24 + phy_idx; + txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, spe_idx)); txwi[7] &= ~cpu_to_le32(MT_TXD7_HW_AMSDU); } From a7871a7ae5a8625f0ba0a89454ac734c383dd538 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sat, 3 Oct 2026 16:30:56 -0700 Subject: [PATCH 1263/2126] wifi: mt76: take rcu_read_lock in the USB/SDIO tx completion path The USB and SDIO completion path reads a station pointer that RCU protects, without holding the read lock. Lockdep catches it on the first association: mt76.h:1305 suspicious rcu_dereference_check() usage! no locks held by mt76-usb-status/1254. mt7925_usb_sdio_tx_complete_skb+0x119/0x130 [mt7925_common] mt76_queue_tx_complete+0x27/0x60 [mt76] mt76u_status_worker+0xed/0x1e0 [mt76_usb] mt7925/mac.c:856 suspicious rcu_dereference_check() usage! mt7925_tx_check_aggr.part.0+0xc2/0xe0 [mt7925_common] mt7925_usb_sdio_tx_complete_skb+0xa0/0x130 [mt7925_common] mt7921 does the same, and warns once instead of twice because its aggregation check reads the default link directly. The DMA path makes the same reads but completes from softirq, so it stays quiet. Take the read lock around the lookup and the check. Tested on 7.2-rc5 with lockdep, fresh module load per arm, 4000 packets each and no change to the link: splats before after MT7925 Netgear A9000 2 0 MT7921 Alfa 1 0 mt7921e same kernel 0 0 Fixes: dc66a129adf1 ("wifi: mt76: add a wrapper for wcid access with validation") Fixes: c22769de2509 ("wifi: mt76: mt7925u: use connac3 tx aggr check in tx complete") Cc: stable@vger.kernel.org Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20261003233056.94497-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +++ drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index e69978184f68..ad1352ddf1fc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -831,11 +831,14 @@ void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, u16 idx; idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX); + + rcu_read_lock(); wcid = __mt76_wcid_ptr(mdev, idx); sta = wcid_to_sta(wcid); if (sta && likely(e->skb->protocol != cpu_to_be16(ETH_P_PAE))) mt76_connac2_tx_check_aggr(sta, txwi); + rcu_read_unlock(); skb_pull(e->skb, headroom); mt76_tx_complete_skb(mdev, e->wcid, e->skb); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c index 101f571b027f..45bc79727426 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c @@ -1687,11 +1687,14 @@ void mt7925_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, u16 idx; idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX); + + rcu_read_lock(); wcid = __mt76_wcid_ptr(mdev, idx); sta = wcid_to_sta(wcid); if (sta && likely(e->skb->protocol != cpu_to_be16(ETH_P_PAE))) mt7925_tx_check_aggr(sta, e->skb, wcid); + rcu_read_unlock(); skb_pull(e->skb, headroom); mt76_tx_complete_skb(mdev, e->wcid, e->skb); From 9f299215d1d835aeeee8b269dad09e1be06f856e Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Sat, 3 Oct 2026 16:49:44 -0700 Subject: [PATCH 1264/2126] wifi: mt76: mt7925: cancel mlo_pm_work on the USB stop path Every other teardown path cancels this work, PCIe unbind included. USB unbind does not: PCIe has its own unregister hook for it, while USB shares a generic one and the stop callback that would have covered it is replaced in probe. That cancel came in commit 81faf578320d ("wifi: mt76: mt7925: cancel mlo_pm_work on stop"), whose last line says it covers both buses. That's mine and it's a boo-boo. Give the USB path its own stop that cancels the work first. Two-link MLO on a Netgear A9000, work armed then the interface down: stock patched stop ran 3/3 3/3 work still ran 3/3 0/3 Skipping the stop entirely leaves both builds running it, so the zero is the cancel. Fixes: 276a56883257 ("wifi: mt76: mt7925: update the power-saving flow") Cc: stable@vger.kernel.org Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20261003234944.96066-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/usb.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/usb.c b/drivers/net/wireless/mediatek/mt76/mt7925/usb.c index afd62a6dbecb..f97f787b2198 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/usb.c @@ -147,6 +147,15 @@ out: return err; } +static void mt7925u_stop(struct ieee80211_hw *hw, bool suspend) +{ + struct mt792x_dev *dev = mt792x_hw_dev(hw); + + cancel_delayed_work_sync(&dev->mlo_pm_work); + + mt792xu_stop(hw, suspend); +} + static int mt7925u_probe(struct usb_interface *usb_intf, const struct usb_device_id *id) { @@ -193,7 +202,7 @@ static int mt7925u_probe(struct usb_interface *usb_intf, if (!ops) return -ENOMEM; - ops->stop = mt792xu_stop; + ops->stop = mt7925u_stop; mdev = mt76_alloc_device(&usb_intf->dev, sizeof(*dev), ops, &drv_ops); if (!mdev) From 68342a7bd7e5e273e2969e3c0f4c62ee3d006ce8 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Wed, 30 Sep 2026 17:35:01 -0700 Subject: [PATCH 1265/2126] wifi: mt76: move the channel survey when the channel changes mt7921 and mt7925 report every survey counter against one channel and never mark the one in use. With firmware channel management, both use channel contexts and never call __mt76_set_channel(), so phy->chan_state, phy->chandef and phy->main_chandef keep the first channel of the band. Update them when a context is assigned or changed, after booking the time spent on the old channel. This also makes the legacy rate lookup in mt76_connac2_mac_fill_txs() and mt7925_mac_add_txs_skb() use the band of the current channel. With two channel contexts (multi-channel or MLO), the survey follows the context that was assigned or changed last, since the driver reads the band 0 counters only. Tested on MT7922 over PCIe, MT7921AU and MT7925 over USB. Fixes: 41ac53c899bd ("wifi: mt76: mt7921: introduce chanctx support") Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Cc: stable@vger.kernel.org Reported-by: Chris Closes: https://lore.kernel.org/linux-wireless/CAHaeJsT8O8Nhq351hFp3NAL8e0iU85N-LBdYZ9nYHFHVy7t_hQ@mail.gmail.com/ Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20261001003501.2425492-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 14 ++++++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ drivers/net/wireless/mediatek/mt76/mt7921/main.c | 1 + drivers/net/wireless/mediatek/mt76/mt7925/main.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt792x_core.c | 1 + 5 files changed, 20 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 0e45533ea89c..3991696515e2 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1045,6 +1045,20 @@ void mt76_update_survey(struct mt76_phy *phy) } EXPORT_SYMBOL_GPL(mt76_update_survey); +void mt76_phy_chandef_set(struct mt76_phy *phy, + struct cfg80211_chan_def *chandef) +{ + if (!chandef->chan) + return; + + mt76_update_survey(phy); + + phy->chandef = *chandef; + phy->main_chandef = *chandef; + phy->chan_state = mt76_channel_state(phy, chandef->chan); +} +EXPORT_SYMBOL_GPL(mt76_phy_chandef_set); + int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, bool offchannel) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 2ade848fe3bb..e9bbec1269fa 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -1555,6 +1555,8 @@ void mt76_sta_ps_transition(struct mt76_dev *dev, struct mt76_wcid *wcid, bool mt76_has_tx_pending(struct mt76_phy *phy); int mt76_update_channel(struct mt76_phy *phy); void mt76_update_survey(struct mt76_phy *phy); +void mt76_phy_chandef_set(struct mt76_phy *phy, + struct cfg80211_chan_def *chandef); void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time); int mt76_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey); diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index d0f6460c7fd8..d041df807f61 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -1421,6 +1421,7 @@ mt7921_change_chanctx(struct ieee80211_hw *hw, } else { mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->bss_conf.mt76, ctx); } + mt76_phy_chandef_set(mvif->phy->mt76, &ctx->def); mt792x_mutex_release(phy->dev); } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index d124d4666707..3a5d6f51832c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -2077,6 +2077,7 @@ mt7925_change_chanctx(struct ieee80211_hw *hw, link_conf, ctx); } } + mt76_phy_chandef_set(mvif->phy->mt76, &ctx->def); mt792x_mutex_release(phy->dev); } @@ -2413,6 +2414,7 @@ static int mt7925_assign_vif_chanctx(struct ieee80211_hw *hw, mconf->mt76.ctx = ctx; mctx->bss_conf = mconf; + mt76_phy_chandef_set(mvif->phy->mt76, &ctx->def); mutex_unlock(&dev->mt76.mutex); return 0; diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c index 0ad33f74c228..f56f03bfe387 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c @@ -472,6 +472,7 @@ int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw, mutex_lock(&dev->mt76.mutex); mvif->bss_conf.mt76.ctx = ctx; mctx->bss_conf = &mvif->bss_conf; + mt76_phy_chandef_set(&dev->mphy, &ctx->def); mutex_unlock(&dev->mt76.mutex); return 0; From baf375ca58eaa24503f9febac75c056852694c3a Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Fri, 25 Sep 2026 23:27:54 +0800 Subject: [PATCH 1266/2126] wifi: mt76: mt76x02: validate RX padding before use The RX descriptor provides L2 and PN padding lengths that are used to locate the CCMP IV and determine how many bytes to remove from the packet. These lengths are not checked against the received skb length before the IV is read or mt76x02_remove_hdr_pad() is called. Reject frames whose IV does not fit within the skb or whose header padding would extend past the end of the skb. Fixes: 30ce7f4456ae ("mt76: validate rx CCMP PN") Signed-off-by: Jiale Yao Link: https://patch.msgid.link/20260925152754.2323624-1-yaojiale02@163.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt76x02_mac.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c index 231685bb62d2..158aa356b710 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c @@ -816,9 +816,13 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb, len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl); pn_len = FIELD_GET(MT_RXINFO_PN_LEN, rxinfo); if (pn_len) { - int offset = ieee80211_get_hdrlen_from_skb(skb) + pad_len; - u8 *data = skb->data + offset; + unsigned int offset = ieee80211_get_hdrlen_from_skb(skb) + pad_len; + u8 *data; + if (offset + 8 > skb->len) + return -EINVAL; + + data = skb->data + offset; status->iv[0] = data[7]; status->iv[1] = data[6]; status->iv[2] = data[5]; @@ -838,6 +842,9 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb, } } + if (pad_len + ieee80211_get_hdrlen_from_skb(skb) > skb->len) + return -EINVAL; + mt76x02_remove_hdr_pad(skb, pad_len); if ((rxinfo & MT_RXINFO_BA) && !(rxinfo & MT_RXINFO_NULL)) From 5b779c63fb1e20e6729d3241b78be7502759296d Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sun, 27 Sep 2026 18:10:40 +0800 Subject: [PATCH 1267/2126] wifi: mt76: mt7615: cancel reset work during unregister The MCU error interrupt handler queues reset_work on the device workqueue. Device removal can reach mt76_unregister_device() while that work is still pending, since the workqueue is not destroyed until mt76_free_device(). If reset_work runs in this window, it operates on an unregistered hw and can requeue mac_work after ieee80211_unregister_hw() has torn the device down. Cancel it before unregistering the device so it cannot outlive the registered hw. Fixes: 61c4fa721968 ("mt76: mt7615: implement hardware reset support") Cc: stable@vger.kernel.org Signed-off-by: Jiale Yao Link: https://patch.msgid.link/20260927101041.957362-1-yaojiale02@163.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c index a9178e077fd6..7d8580720cd8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c @@ -116,6 +116,7 @@ void mt7615_unregister_device(struct mt7615_dev *dev) mcu_running = mt7615_wait_for_mcu_init(dev); mt7615_unregister_ext_phy(dev); + cancel_work_sync(&dev->reset_work); mt76_unregister_device(&dev->mt76); if (mcu_running) mt7615_mcu_exit(dev); From 29329dfa41de31f8adc7ff0aac0abccb555bb738 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 28 Sep 2026 16:51:44 +0200 Subject: [PATCH 1268/2126] wifi: mt76: mt7996: add NET_AIROHA dependency MT7996E fails to link as build-in when NET_AIROHA=m: WARNING: unmet direct dependencies detected for MT76_NPU Depends on [m]: NETDEVICES [=y] && WLAN [=y] && WLAN_VENDOR_MEDIATEK [=y] && (NET_AIROHA_NPU [=y]=y [=y] || MT76_CORE [=y]=NET_AIROHA_NPU [=y]) && (NET_AIROHA [=m] || !NET_AIROHA [=m]) Selected by [y]: - MT7996_NPU [=y] && NETDEVICES [=y] && WLAN [=y] && WLAN_VENDOR_MEDIATEK [=y] && MT7996E [=y] && (NET_AIROHA_NPU [=y]=y [=y] || MT76_CORE [=y]=NET_AIROHA_NPU [=y]) arm-linux-gnueabi-ld: drivers/net/wireless/mediatek/mt76/npu.o: in function `mt76_npu_init': npu.c:(.text.mt76_npu_init+0x4c): undefined reference to `airoha_ppe_get_dev' arm-linux-gnueabi-ld: npu.c:(.text.mt76_npu_init+0xf8): undefined reference to `airoha_ppe_put_dev' Add another dependency to prevent this configuration, with an explicit special case to allow the NPU to be used while the PPE code is stubbed out with NET_AIROHA=n. Fixes: 377aa17d2aed ("wifi: mt76: mt7996: Add NPU offload support to MT7996 driver") Signed-off-by: Arnd Bergmann Link: https://patch.msgid.link/20260928145210.3153783-1-arnd@kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/Kconfig | 1 + drivers/net/wireless/mediatek/mt76/mt7996/Kconfig | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/Kconfig b/drivers/net/wireless/mediatek/mt76/Kconfig index 2ca96e0527c0..a4ece38f938d 100644 --- a/drivers/net/wireless/mediatek/mt76/Kconfig +++ b/drivers/net/wireless/mediatek/mt76/Kconfig @@ -40,6 +40,7 @@ config MT792x_USB config MT76_NPU tristate depends on NET_AIROHA_NPU=y || MT76_CORE=NET_AIROHA_NPU + depends on NET_AIROHA=y || NET_AIROHA=n || MT76_CORE=NET_AIROHA source "drivers/net/wireless/mediatek/mt76/mt76x0/Kconfig" source "drivers/net/wireless/mediatek/mt76/mt76x2/Kconfig" diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/Kconfig b/drivers/net/wireless/mediatek/mt76/mt7996/Kconfig index 5742bce12fbb..3c51b402f44e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/Kconfig +++ b/drivers/net/wireless/mediatek/mt76/mt7996/Kconfig @@ -17,5 +17,6 @@ config MT7996_NPU bool "MT7996 (PCIe) NPU support" depends on MT7996E depends on NET_AIROHA_NPU=y || MT76_CORE=NET_AIROHA_NPU + depends on NET_AIROHA=y || NET_AIROHA=n || MT76_CORE=NET_AIROHA select MT76_NPU default n From dd3f17ef69ed6d0085cd94a15b9dec227b4ebfb1 Mon Sep 17 00:00:00 2001 From: Andrei Rusu de Castro Date: Sun, 4 Oct 2026 15:49:02 +0000 Subject: [PATCH 1269/2126] wifi: mt76: mt7925: keep MLD membership consistent during link add mt7925_mac_link_sta_add() sends an ASSOC update for the primary WCID before sending the update for a new secondary WCID. The new link is published in msta->link[] and msta->valid_links only after both commands succeed. Selecting the secondary entry from the subject of each command gives the primary STA_REC_MLD one link and the secondary STA_REC_MLD two links. Enumerating published links alone still omits the pending link from the primary command. Firmware-bound command captures reproduce this n=1/n=2 sequence during a secondary addition. Build each MLD TLV from the station's published links and an explicit pending link. Pass the initialized pending link through both add-time station updates, including the update whose subject is the primary. Keep the primary first, bound entries by the firmware array, and skip links without station and BSS state. Other update callers have no pending link. This leaves msta->link[] publication after successful link setup and preserves the existing add-failure cleanup. The pending pointer is used synchronously to populate the command, not stored in shared state. Fixes: ff643b81bc38 ("wifi: mt76: mt7925: pass mlink and mconf to sta_mld_tlv()") Link: https://lore.kernel.org/linux-wireless/066b30cc-a9e6-4aeb-964d-71551e8ea3ef@posteo.de/ Signed-off-by: Andrei Rusu de Castro Tested-by: Devin Wittmayer Tested-by: Jonas Hort Link: https://patch.msgid.link/20261004-mt7925-mld-v2-248bb5e6404f@empyreal.works Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/mac.c | 2 +- .../net/wireless/mediatek/mt76/mt7925/main.c | 16 +++--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 53 +++++++++++++++---- .../wireless/mediatek/mt76/mt7925/mt7925.h | 3 +- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c index 45bc79727426..a05468559c03 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c @@ -1502,7 +1502,7 @@ mt7925_vif_connect_iter(void *priv, u8 *mac, true, NULL); mt7925_mcu_sta_update(dev, NULL, vif, &mvif->sta.deflink, true, - MT76_STA_INFO_STATE_NONE); + MT76_STA_INFO_STATE_NONE, NULL); mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, true); } } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 3a5d6f51832c..245b8a51b64b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -1005,7 +1005,7 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, link_sta == mlink->pri_link) { ret = mt7925_mcu_sta_update(dev, link_sta, vif, mlink, true, - MT76_STA_INFO_STATE_NONE); + MT76_STA_INFO_STATE_NONE, NULL); if (ret) goto out_pm; } else if (ieee80211_vif_is_mld(vif) && @@ -1027,19 +1027,19 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, ret = mt7925_mcu_sta_update(dev, mlink->pri_link, vif, pri_mlink, true, - MT76_STA_INFO_STATE_ASSOC); + MT76_STA_INFO_STATE_ASSOC, mlink); if (ret) goto out_pm; ret = mt7925_mcu_sta_update(dev, link_sta, vif, mlink, true, - MT76_STA_INFO_STATE_ASSOC); + MT76_STA_INFO_STATE_ASSOC, mlink); if (ret) goto out_pm; } else { ret = mt7925_mcu_sta_update(dev, link_sta, vif, mlink, true, - MT76_STA_INFO_STATE_NONE); + MT76_STA_INFO_STATE_NONE, NULL); if (ret) goto out_pm; } @@ -1247,7 +1247,7 @@ static void mt7925_mac_link_sta_assoc(struct mt76_dev *mdev, memset(mlink->airtime_ac, 0, sizeof(mlink->airtime_ac)); mt7925_mcu_sta_update(dev, link_sta, vif, mlink, true, - MT76_STA_INFO_STATE_ASSOC); + MT76_STA_INFO_STATE_ASSOC, NULL); mt792x_mutex_release(dev); } @@ -1307,7 +1307,7 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev, mt76_connac_pm_wake(&dev->mphy, &dev->pm); mt7925_mcu_sta_update(dev, link_sta, vif, mlink, false, - MT76_STA_INFO_STATE_NONE); + MT76_STA_INFO_STATE_NONE, NULL); mt7925_mac_wtbl_update(dev, mlink->wcid.idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR); @@ -1978,7 +1978,7 @@ mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, err = mt7925_mcu_sta_update(dev, NULL, vif, &mvif->sta.deflink, true, - MT76_STA_INFO_STATE_NONE); + MT76_STA_INFO_STATE_NONE, NULL); out: mt792x_mutex_release(dev); @@ -2123,7 +2123,7 @@ static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw, if (changed & BSS_CHANGED_ASSOC) { mt7925_mcu_sta_update(dev, NULL, vif, &mvif->sta.deflink, true, - MT76_STA_INFO_STATE_ASSOC); + MT76_STA_INFO_STATE_ASSOC, NULL); mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc); if (ieee80211_vif_is_mld(vif)) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index 698b649edccc..c86f2dc37913 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -2065,14 +2065,18 @@ mt7925_mcu_sta_mld_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, struct ieee80211_sta *sta, struct mt792x_bss_conf *mconf, - struct mt792x_link_sta *mlink) + struct mt792x_link_sta *mlink, + struct mt792x_link_sta *pending) { struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; struct mt792x_dev *dev = mvif->phy->dev; + unsigned long valid = msta->valid_links; struct mt792x_bss_conf *mconf_pri; struct sta_rec_mld *mld; + unsigned int link_id; struct tlv *tlv; + u8 max_links; u8 cnt = 0; /* Primary link always uses driver's deflink WCID. */ @@ -2101,11 +2105,38 @@ mt7925_mcu_sta_mld_tlv(struct sk_buff *skb, mld->link[cnt].wlan_id = cpu_to_le16(msta->deflink.wcid.idx); mld->link[cnt++].bss_idx = mconf_pri->mt76.idx; - /* Optionally encode the currently-updated secondary link. */ - if (mlink && mlink != &msta->deflink && mconf) { - mld->secondary_id = cpu_to_le16(mlink->wcid.idx); - mld->link[cnt].wlan_id = cpu_to_le16(mlink->wcid.idx); - mld->link[cnt++].bss_idx = mconf->mt76.idx; + max_links = ARRAY_SIZE(mld->link); + + /* A link being added is not set in msta->valid_links yet */ + if (pending && pending != &msta->deflink) + valid |= BIT(pending->wcid.link_id); + + for_each_set_bit(link_id, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt792x_link_sta *mlink_sec; + struct mt792x_bss_conf *mconf_sec; + + if (cnt == max_links) + break; + + if (link_id == msta->deflink_id) + continue; + + mlink_sec = mt792x_sta_to_link(msta, link_id); + if (!mlink_sec && pending && link_id == pending->wcid.link_id) + mlink_sec = pending; + if (!mlink_sec || mlink_sec == &msta->deflink) + continue; + + mconf_sec = rcu_dereference_protected(mvif->link_conf[link_id], + lockdep_is_held(&dev->mt76.mutex)); + if (!mconf_sec) + continue; + + if (cnt == 1) + mld->secondary_id = cpu_to_le16(mlink_sec->wcid.idx); + + mld->link[cnt].wlan_id = cpu_to_le16(mlink_sec->wcid.idx); + mld->link[cnt++].bss_idx = mconf_sec->mt76.idx; } mld->link_num = cnt; @@ -2124,7 +2155,8 @@ mt7925_mcu_sta_remove_tlv(struct sk_buff *skb) static int mt7925_mcu_sta_cmd(struct mt76_phy *phy, - struct mt76_sta_cmd_info *info) + struct mt76_sta_cmd_info *info, + struct mt792x_link_sta *pending) { struct mt792x_vif *mvif = (struct mt792x_vif *)info->vif->drv_priv; struct mt76_dev *dev = phy->dev; @@ -2165,7 +2197,7 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy, if (info->state != MT76_STA_INFO_STATE_NONE) { mt7925_mcu_sta_mld_tlv(skb, info->vif, info->link_sta->sta, - mconf, mlink); + mconf, mlink, pending); mt7925_mcu_sta_eht_mld_tlv(skb, info->vif, info->link_sta->sta); } @@ -2190,7 +2222,8 @@ int mt7925_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_vif *vif, struct mt792x_link_sta *mlink, bool enable, - enum mt76_sta_info_state state) + enum mt76_sta_info_state state, + struct mt792x_link_sta *pending) { struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; int rssi = -ewma_rssi_read(&mvif->bss_conf.rssi); @@ -2208,7 +2241,7 @@ int mt7925_mcu_sta_update(struct mt792x_dev *dev, info.wcid = &mlink->wcid; info.newly = state != MT76_STA_INFO_STATE_ASSOC; - return mt7925_mcu_sta_cmd(&dev->mphy, &info); + return mt7925_mcu_sta_cmd(&dev->mphy, &info, pending); } int mt7925_mcu_set_beacon_filter(struct mt792x_dev *dev, diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h index cc4270863ebd..ef72b50e1a7c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h @@ -291,7 +291,8 @@ int mt7925_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_vif *vif, struct mt792x_link_sta *mlink, bool enable, - enum mt76_sta_info_state state); + enum mt76_sta_info_state state, + struct mt792x_link_sta *pending); int mt7925_mcu_set_chan_info(struct mt792x_phy *phy, u16 tag); int mt7925_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_bss_conf *bss_conf); int mt7925_mcu_set_eeprom(struct mt792x_dev *dev); From d4e5ca3483a0ce95ff8417e16d42af99f7a98da4 Mon Sep 17 00:00:00 2001 From: Anthony Liu Date: Mon, 5 Oct 2026 16:39:04 +0800 Subject: [PATCH 1270/2126] wifi: mt76: mt7928: makes struct beacon_tlv 4-byte aligned. mt76 fails when offloading beacon to MT7928 FW. This is caused by newly added 4-byte alignment check in MT7928 FW and works when beacon_tlv is 4-byte aligned. MT7925 is not affected because it accepts same struct with or without extra padding bytes. Signed-off-by: Anthony Liu Link: https://patch.msgid.link/20261005083904.107527-1-anthony.liu@mediatek.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index c86f2dc37913..26cdb3f0a98a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -2427,10 +2427,13 @@ mt7925_mcu_uni_add_beacon_offload(struct mt792x_dev *dev, u8 pad[3]; } __packed hdr; struct bcn_content_tlv { + /* DW 0 */ __le16 tag; __le16 len; + /* DW 1 */ __le16 tim_ie_pos; __le16 csa_ie_pos; + /* DW 2 */ __le16 bcc_ie_pos; /* 0: disable beacon offload * 1: enable beacon offload @@ -2441,8 +2444,9 @@ mt7925_mcu_uni_add_beacon_offload(struct mt792x_dev *dev, * 1: only cap field IE */ u8 type; + /* DW 3~130 */ __le16 pkt_len; - u8 pkt[512]; + u8 pkt[510]; } __packed beacon_tlv; } req = { .hdr = { From 6f591a4bb5d9a6a4a28f3f2fd77f394ddbcc4e05 Mon Sep 17 00:00:00 2001 From: Mark Anthony Agarro Date: Mon, 5 Oct 2026 13:38:46 -0700 Subject: [PATCH 1271/2126] wifi: mt76: mt7921: keep the join ROC until the station is authorized When an association succeeds mac80211 calls mgd_complete_tx(), and mt7921 aborts the join ROC there. The AP starts the 4-way handshake right away, so the abort lands where message 3 arrives. On an MT7922 this loses message 3 often enough to matter: the supplicant sends message 2 (acked), never receives message 3, and the connection ends with reason 15 (4WAY_HANDSHAKE_TIMEOUT) after about 3.3 s. The mt7925 capture in the linked issue shows the same ordering: abort, message 2 out, then message 3 retried by the AP several times without an answer. Keep the ROC after a successful (re)association on a station interface and release it when the station is authorized, on disassociation, or when the station is removed. The ROC timer still ends it if none of that happens. The state lives in a flag in struct mt792x_vif so that an unrelated ROC, for example a user remain-on-channel, is never aborted by the authorize hook. Tested on an MT7922 (PCIe), kernel 7.3.0-rc4, WPA3-SAE AP, two rounds of 20 disconnect/reconnect cycles per build in the same boot, unpatched and patched in ABAB order: unpatched 34 of 73 association attempts: M1 rx, M2 tx acked, no M3, reason 15 patched 0 of 40 Delaying the abort by 20 ms before it made no difference (8 of 29), and delaying 20 ms after it removed the failures (0 of 20), so what matters is where the abort lands relative to the handshake. The firmware behaviour after the abort is inferred from these outcomes, not observed directly. Not tested: MT7921 and other connac2 parts, USB and SDIO, APs other than the one above, open or WPA2 networks, scheduled scan, suspend and resume. Fixes: 41ac53c899bd ("wifi: mt76: mt7921: introduce chanctx support") Link: https://github.com/morrownr/mt76/issues/106 Signed-off-by: Mark Anthony Agarro Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20261005203846.239445-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7921/main.c | 17 +++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index d041df807f61..09574d4417cd 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -863,6 +863,12 @@ int mt7921_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, if (sta->aid > MT7921_MAX_AID) return -ENOENT; + if (mvif->roc_join_held && !sta->tdls && + (ev == MT76_STA_EVENT_AUTHORIZE || ev == MT76_STA_EVENT_DISASSOC)) { + mvif->roc_join_held = false; + mt7921_abort_roc(mvif->phy, mvif); + } + if (ev != MT76_STA_EVENT_ASSOC) return 0; @@ -904,6 +910,7 @@ void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; mvif->wep_sta = NULL; + mvif->roc_join_held = false; ewma_rssi_init(&mvif->bss_conf.rssi); if (!sta->tdls) mt76_connac_mcu_uni_add_bss(&dev->mphy, vif, @@ -1446,6 +1453,16 @@ static void mt7921_mgd_complete_tx(struct ieee80211_hw *hw, { struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + /* Keep the join ROC until the station is authorized, so that it + * covers the 4-way handshake. mt7921_mac_sta_event() releases it. + */ + if (vif->type == NL80211_IFTYPE_STATION && info->success && + (info->subtype == IEEE80211_STYPE_ASSOC_REQ || + info->subtype == IEEE80211_STYPE_REASSOC_REQ)) { + mvif->roc_join_held = true; + return; + } + mt7921_abort_roc(mvif->phy, mvif); } diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 49c7b6958480..7b838a8655be 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -191,6 +191,7 @@ struct mt792x_vif { struct mt792x_sta *wep_sta; struct mt792x_phy *phy; + bool roc_join_held; /* join ROC kept until the STA is authorized */ u16 valid_links; u8 deflink_id; enum mt792x_mlo_pm_state mlo_pm_state; From ac22c8c723c62013dd45b74e32249fc877c86fe0 Mon Sep 17 00:00:00 2001 From: Mark Anthony Agarro Date: Mon, 5 Oct 2026 20:14:25 -0700 Subject: [PATCH 1272/2126] wifi: mt76: mt7925: keep the join ROC until the station is authorized When a non-MLO station associates, mgd_complete_tx() aborts the join ROC as soon as the association succeeds, which is right before the supplicant sends message 2 of the 4-way handshake. With the abort that close to message 2, the adapter acknowledges nothing the AP sends for the next several ms: the AP sends message 3 and its seven retries within about 5 ms, none is acknowledged, and the handshake ends with reason 15 (4WAY_HANDSHAKE_TIMEOUT). Keep the ROC after a successful (re)association on a non-MLD station interface and release it when the station is authorized, on disassociation, or when the station is removed. The ROC timer still ends it if none of that happens. MLD interfaces keep the old behaviour: there the ROC that is active at this point is the MLO ROC set up by mt7925_mac_set_links(), and holding it makes mt7925_set_mlo_roc() fail with -EBUSY in the link activation work, which leaves one link instead of two. Tested by a reporter on an MT7925U (USB) against a FRITZ!Box 5690 Pro on a 6 GHz-only, non-MLO SSID, kernel 7.2.3, from traces and monitor captures taken in separate runs: handshakes first M3 acked abort before M2 unpatched 8 of 84 0 of 83 84 of 84 this patch 30 of 30 31 of 31 0 of 30 With the patch the AP sends message 3 once and the adapter acknowledges it straight away; the ROC is released right after the station is authorized. A 20 ms delay after the abort instead of this change gave 15 of 15, which points at the abort timing and not at the delay. Tested here on an MT7925 and an MT7927 (PCIe), kernel 7.3.0-rc4: on a non-MLO SSID neither build showed the failure (1 stalled handshake in 110 unpatched, none patched), so no effect could be measured there. On an MLO connection the change is inert: 16 of 16 link activations succeeded in two rounds per build, with two active links and the same ROC order as before. Not tested: other APs, other USB parts, MT7927 over USB, MLO connections beyond the check above. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Reported-by: Mark Junker Closes: https://github.com/morrownr/mt76/issues/106 Tested-by: Mark Junker Signed-off-by: Mark Anthony Agarro Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20261006031425.20922-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7925/main.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 245b8a51b64b..b46408f4aed2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -1257,6 +1257,13 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); struct ieee80211_link_sta *link_sta = &sta->deflink; + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + + if (mvif->roc_join_held && !sta->tdls && + (ev == MT76_STA_EVENT_AUTHORIZE || ev == MT76_STA_EVENT_DISASSOC)) { + mvif->roc_join_held = false; + mt7925_abort_roc(mvif->phy, &mvif->bss_conf); + } switch (ev) { case MT76_STA_EVENT_ASSOC: @@ -1452,6 +1459,7 @@ void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, if (vif->type == NL80211_IFTYPE_STATION) { mvif->wep_sta = NULL; + mvif->roc_join_held = false; ewma_rssi_init(&mvif->bss_conf.rssi); } @@ -2104,6 +2112,19 @@ static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw, { struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + /* Keep the join ROC until the station is authorized, so that it + * covers the 4-way handshake. mt7925_mac_sta_event() releases it. + * On MLD, the active ROC is the MLO ROC, which must be released + * before the link activation work sets its own. + */ + if (vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) && + info->success && + (info->subtype == IEEE80211_STYPE_ASSOC_REQ || + info->subtype == IEEE80211_STYPE_REASSOC_REQ)) { + mvif->roc_join_held = true; + return; + } + mt7925_abort_roc(mvif->phy, &mvif->bss_conf); } From 3c334603f0ecd0ce3db05c068ba775e6e37b7c72 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Wed, 23 Sep 2026 10:24:24 -0700 Subject: [PATCH 1273/2126] wifi: mt76: mt792x: defer the MCU shutdown past unregister on USB The USB disconnect path abandons the MCU before it unregisters, so the teardown commands that follow cannot be answered. The response parser reads the silence as a timeout and starts a chip reset for each one, queueing the work that was cancelled nine lines earlier and reloading firmware onto a device being removed. Shut the MCU down after unregister instead. MT7921AU on a Pi 5, eight unload cycles per arm: unload 5.67 s -> 2.81 s MCU timeouts 8 -> 0 reset queued 8/8 -> 0/8 Deauthorizing the port with the link up, to cover a surprise removal, goes from 3.21 s to 0.33 s. Fixes: 7910bd565d8b ("wifi: mt76: mt792x: quiesce USB paths on disconnect") Tested-by: Eason Lai Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260923172424.24021-1-lucid_duck@justthetip.ca Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt792x_usb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_usb.c b/drivers/net/wireless/mediatek/mt76/mt792x_usb.c index 850f6b2cfc4a..5e19e64a9a00 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_usb.c @@ -502,21 +502,26 @@ void mt792xu_disconnect(struct usb_interface *usb_intf) return; set_bit(MT76_RESET, &dev->mphy.state); - set_bit(MT76_MCU_RESET, &dev->mphy.state); clear_bit(MT76_STATE_RUNNING, &dev->mphy.state); - wake_up(&dev->mt76.mcu.wait); - skb_queue_purge(&dev->mt76.mcu.res_q); - cancel_work_sync(&dev->reset_work); cancel_work_sync(&dev->init_work); mt76_worker_disable(&dev->mt76.tx_worker); mt792xu_reset_work_cleanup(dev); if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state)) { + set_bit(MT76_MCU_RESET, &dev->mphy.state); + wake_up(&dev->mt76.mcu.wait); + skb_queue_purge(&dev->mt76.mcu.res_q); + cancel_work_sync(&dev->reset_work); set_bit(MT76_REMOVED, &dev->mphy.state); return; } mt76_unregister_device(&dev->mt76); + + set_bit(MT76_MCU_RESET, &dev->mphy.state); + wake_up(&dev->mt76.mcu.wait); + skb_queue_purge(&dev->mt76.mcu.res_q); + cancel_work_sync(&dev->reset_work); mt792xu_cleanup(dev); set_bit(MT76_REMOVED, &dev->mphy.state); From d435130cdd064b901d8ce5ada0322298e6a86a49 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Fri, 25 Sep 2026 23:05:54 +0800 Subject: [PATCH 1274/2126] wifi: mt76: usb: fix source overread in mt76u_copy mt76u_copy() rounds up len to a multiple of four and uses the rounded length as the bound for memcpy() from the source buffer. When the caller's length is not four-byte aligned, the final copy reads up to three bytes past the source buffer. Keep the original length for the source copy and zero the remaining bytes in the transmit buffer so that the hardware access width remains four-byte aligned. Fixes: 9446248669968 ("mt76: speed up usb bulk copy") Signed-off-by: Jiale Yao Link: https://patch.msgid.link/20260925150556.2304003-2-yaojiale02@163.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/usb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index dfc12f6944a7..be48a88a3ad0 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -171,8 +171,10 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset, { struct mt76_usb *usb = &dev->usb; const u8 *val = data; - int ret; int current_batch_size; + int len_aligned; + int copy_len; + int ret; int i = 0; /* Assure that always a multiple of 4 bytes are copied, @@ -180,12 +182,16 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset, * See: "mt76: round up length on mt76_wr_copy" * Commit 850e8f6fbd5d0003b0 */ - len = round_up(len, 4); + len_aligned = round_up(len, 4); mutex_lock(&usb->usb_ctrl_mtx); - while (i < len) { - current_batch_size = min_t(int, usb->data_len, len - i); - memcpy(usb->data, val + i, current_batch_size); + while (i < len_aligned) { + current_batch_size = min_t(int, usb->data_len, len_aligned - i); + copy_len = min_t(int, current_batch_size, len - i); + memcpy(usb->data, val + i, copy_len); + if (copy_len < current_batch_size) + memset(usb->data + copy_len, 0, + current_batch_size - copy_len); ret = __mt76u_vendor_request(dev, MT_VEND_MULTI_WRITE, USB_DIR_OUT | USB_TYPE_VENDOR, 0, offset + i, usb->data, From 0c2fcb5225361f71905697ef9db287b24bcc67cf Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Fri, 25 Sep 2026 23:05:55 +0800 Subject: [PATCH 1275/2126] wifi: mt76: mt7615: usb: fix source overread in mt7663u_copy mt7663u_copy() rounds up len to a multiple of four and uses the rounded length as the bound for memcpy() from the source buffer. When the caller's length is not four-byte aligned, the final copy reads up to three bytes past the source buffer. Keep the original length for the source copy and zero the remaining bytes in the transmit buffer so that the hardware access width remains four-byte aligned. Fixes: 6cb596ba84e3 ("mt76: usb: introduce __mt76u_init utility routine") Signed-off-by: Jiale Yao Link: https://patch.msgid.link/20260925150556.2304003-3-yaojiale02@163.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/usb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c index bab7b91f14be..3629e3d9bf47 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c @@ -58,15 +58,22 @@ static void mt7663u_copy(struct mt76_dev *dev, u32 offset, const void *data, int len) { struct mt76_usb *usb = &dev->usb; - int ret, i = 0, batch_len; const u8 *val = data; + int len_aligned; + int batch_len; + int copy_len; + int ret; + int i = 0; - len = round_up(len, 4); + len_aligned = round_up(len, 4); mutex_lock(&usb->usb_ctrl_mtx); - while (i < len) { - batch_len = min_t(int, usb->data_len, len - i); - memcpy(usb->data, val + i, batch_len); + while (i < len_aligned) { + batch_len = min_t(int, usb->data_len, len_aligned - i); + copy_len = min_t(int, batch_len, len - i); + memcpy(usb->data, val + i, copy_len); + if (copy_len < batch_len) + memset(usb->data + copy_len, 0, batch_len - copy_len); ret = __mt76u_vendor_request(dev, MT_VEND_WRITE_EXT, USB_DIR_OUT | USB_TYPE_VENDOR, (offset + i) >> 16, offset + i, From 9be6ee96184c3f1219f2ab023345d22268e06833 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Sat, 3 Oct 2026 04:01:04 +0000 Subject: [PATCH 1276/2126] wifi: mt76: mt7915: fix thermal zone use-after-free The thermal zone registered via devm_thermal_of_zone_register() on the parent device is never torn down when the phy is unregistered, so the thermal core can still dereference it after the phy is freed. Unregister the thermal zone alongside the cooling device in mt7915_unregister_thermal(). Also clear phy->tzone and phy->cdev after unregistering so the function is safe to call when only a subset of the objects were registered, e.g. after a partially failed mt7915_thermal_init(). While at it, include the band index in the thermal zone registration warning to help identify which band failed on multi-band chips. Fixes: 313f1a27ebcb ("wifi: mt76: mt7915: add thermal zone device registration") Signed-off-by: Ryan Leung Link: https://patch.msgid.link/20261003-mt7915-unregister-thermal-v4-1-8ed55f6f5535@protonmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c index aeefd323c10e..9feb2d8cb551 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c @@ -200,11 +200,17 @@ static void mt7915_unregister_thermal(struct mt7915_phy *phy) { struct wiphy *wiphy = phy->mt76->hw->wiphy; + if (phy->tzone) { + devm_thermal_of_zone_unregister(phy->dev->mt76.dev, phy->tzone); + phy->tzone = NULL; + } + if (!phy->cdev) return; sysfs_remove_link(&wiphy->dev.kobj, "cooling_device"); thermal_cooling_device_unregister(phy->cdev); + phy->cdev = NULL; } static int mt7915_thermal_init(struct mt7915_phy *phy) @@ -238,8 +244,8 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) if (IS_ERR(phy->tzone)) { if (PTR_ERR(phy->tzone) != -ENODEV) dev_warn(phy->dev->mt76.dev, - "failed to register thermal zone: %ld\n", - PTR_ERR(phy->tzone)); + "failed to register thermal zone %d: %ld\n", + phy->mt76->band_idx, PTR_ERR(phy->tzone)); phy->tzone = NULL; } From 9956c4cac9d3f479817d6fe6a057aef3e86defcf Mon Sep 17 00:00:00 2001 From: Cristian Papa Date: Tue, 22 Sep 2026 19:08:14 -0300 Subject: [PATCH 1277/2126] wifi: mt76: mt7603: don't drop short frames looped back on PS entry When a station enters power save, mt7603 has the PSE redirect the frames still queued for it back to the host, and mt7603_rx_loopback_skb() parks them until the station wakes up. The handler rejects every frame shorter than a four-address header (sizeof(struct ieee80211_hdr), 30 bytes) before looking at it. A BlockAck request is 20 bytes and a QoS-Null 26, so both are freed without a trace. Since commit b473c0e47f04 ("wifi: mt76: mt7603: fix tx queue of loopback packets"), a BAR would also be freed later as a frame that is not a bufferable MMPDU, although mac80211 buffers BARs for a sleeping station like any other unicast frame. mac80211 queues the BAR with IEEE80211_TX_CTL_REQ_TX_STATUS, so it only learns about the loss when the tx status times out, and the recipient keeps waiting on its reorder window until then. Check the length against the header length of the actual frame, and park a BlockAck request on the queue of its TID, behind the data frames it refers to. Found on a TP-Link Archer XR500v (MT7603E) with a client whose Bluetooth coexistence toggles PM every ~15 ms under load. To test the change on its own, a temporary debugfs switch flipped between the old and the new checks every 30 seconds during a bidirectional TCP test, with counters on the loop-back path and on the tx status of BARs. With the old check, all 92 BARs that came back were freed, and 91 of the 544 BARs queued in those phases never got a tx status from the hardware. With this change, all 129 BARs that came back were parked and sent again, and 11 of 411 got no tx status. Throughput was the same with both checks. Fixes: e004b7006600 ("mt76: mt7603: notify mac80211 about buffered frames in ps queue") Assisted-by: LLM Signed-off-by: Cristian Papa Link: https://patch.msgid.link/20260922220814.15070-1-pcristian292@gmail.com Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7603/dma.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/dma.c b/drivers/net/wireless/mediatek/mt76/mt7603/dma.c index 477a9b7a8cf7..491c8c937031 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7603/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7603/dma.c @@ -34,7 +34,7 @@ mt7603_rx_loopback_skb(struct mt7603_dev *dev, struct sk_buff *skb) int idx; u32 val; - if (skb->len < MT_TXD_SIZE + sizeof(struct ieee80211_hdr)) + if (skb->len < MT_TXD_SIZE + 2) goto free; val = le32_to_cpu(txd[1]); @@ -52,6 +52,9 @@ mt7603_rx_loopback_skb(struct mt7603_dev *dev, struct sk_buff *skb) sta = container_of(priv, struct ieee80211_sta, drv_priv); hdr = (struct ieee80211_hdr *)&skb->data[MT_TXD_SIZE]; + if (skb->len < MT_TXD_SIZE + ieee80211_hdrlen(hdr->frame_control)) + goto free; + hwq = wmm_queue_map[IEEE80211_AC_BE]; if (ieee80211_is_data_qos(hdr->frame_control)) { tid = *ieee80211_get_qos_ctl(hdr) & @@ -62,6 +65,19 @@ mt7603_rx_loopback_skb(struct mt7603_dev *dev, struct sk_buff *skb) } else if (ieee80211_is_data(hdr->frame_control)) { skb_set_queue_mapping(skb, IEEE80211_AC_BE); hwq = wmm_queue_map[IEEE80211_AC_BE]; + } else if (ieee80211_is_back_req(hdr->frame_control)) { + struct ieee80211_bar *bar = (struct ieee80211_bar *)hdr; + + if (skb->len < MT_TXD_SIZE + sizeof(*bar)) + goto free; + + tid = (le16_to_cpu(bar->control) & + IEEE80211_BAR_CTRL_TID_INFO_MASK) >> + IEEE80211_BAR_CTRL_TID_INFO_SHIFT; + tid &= IEEE80211_QOS_CTL_TAG1D_MASK; + qid = tid_to_ac[tid]; + hwq = wmm_queue_map[qid]; + skb_set_queue_mapping(skb, qid); } else { skb_pull(skb, MT_TXD_SIZE); if (!ieee80211_is_bufferable_mmpdu(skb)) From 43fa49b185832a3dac6845e6d30de44c87a91f16 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Fri, 18 Sep 2026 19:16:59 +1000 Subject: [PATCH 1278/2126] wifi: mt76: mt7996: refresh the tx BA session timer on NPU devices mt7996_mac_add_txs_skb() refreshes mac80211's tx BlockAck session timer only when a WED device is active. Airoha boards offload through the NPU instead, so on those the condition is never true and nothing keeps the timer alive. NPU-forwarded frames do not traverse mac80211, and the only other places that stamp tid_tx->last_tx are in the software tx path. When the peer negotiates a non-zero BlockAck timeout in the ADDBA response (Intel stations commonly do, most others answer 0) mac80211 arms tid_tx->session_timer, which then expires in the middle of an offloaded transfer and tears the session down with a DELBA. The session does not come back on its own either: mt7996 restarts one from mt7996_tx_check_aggr(), reached via mt7996_txwi_free(), and offloaded frames carry no driver token so they never get there. mac80211's ieee80211_aggr_check() fallback needs RATE_CTRL_CAPA_AMPDU_TRIGGER, which mt7996 does not set. The reported symptom is a file transfer to an Intel client dropping from line rate to a few MB/s and staying there, with a single ping from the router - one frame on the software path - restoring it instantly. Extend the check with mt76_npu_device_active(). TXS reports do arrive for NPU-forwarded frames, measured at roughly 24 per second on a busy radio, which is far more than a seconds-scale session timer needs. A second user who independently saw the same collapse, held off only by a once-a-second ping from the AP, ran a patched image for 100 hours (~175 TB of offloaded iperf3 traffic, ~4 Gbit/s) without it recurring. Link: https://forum.openwrt.org/t/quantum-fiber-w1700k-support/222776/3900 Link: https://forum.openwrt.org/t/quantum-fiber-w1700k-support/222776/3901 Link: https://forum.openwrt.org/t/gemtek-w1700k-community-builds/249319/458 Fixes: 377aa17d2aed ("wifi: mt76: mt7996: Add NPU offload support to MT7996 driver") Signed-off-by: Chris Scott Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20260918091659.1176350-1-gilroyscott@hotmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index a8c4f629109b..42c0c53f1023 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -1503,7 +1503,8 @@ mt7996_mac_add_txs_skb(struct mt7996_dev *dev, struct mt76_wcid *wcid, } } - if (mtk_wed_device_active(&dev->mt76.mmio.wed) && wcid->sta) { + if ((mtk_wed_device_active(&dev->mt76.mmio.wed) || + mt76_npu_device_active(&dev->mt76)) && wcid->sta) { struct ieee80211_sta *sta; u8 tid; From 7f0770eab862c055d70c4d46539921267415eee4 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 8 Sep 2026 19:29:55 +0200 Subject: [PATCH 1279/2126] wifi: mt76: avoid iter_keys_rcu() where not needed This place already holds the wiphy mutex, so it doesn't need the _rcu() variant. Simplify the code. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20260908192955.5cf136377203.I70dc9768829e44d43a68e62b8e0590044dd3c2d3@changeid Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index 2c49f3b493bd..4ba3ff95e475 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -2487,9 +2487,7 @@ int mt76_connac_mcu_update_gtk_rekey(struct ieee80211_hw *hw, gtk_tlv->rekey_mode = 2; gtk_tlv->option = 1; - rcu_read_lock(); - ieee80211_iter_keys_rcu(hw, vif, mt76_connac_mcu_key_iter, gtk_tlv); - rcu_read_unlock(); + ieee80211_iter_keys(hw, vif, mt76_connac_mcu_key_iter, gtk_tlv); memcpy(gtk_tlv->kek, key->kek, NL80211_KEK_LEN); memcpy(gtk_tlv->kck, key->kck, NL80211_KCK_LEN); From e75897e6cb8b900d095acf6fbff1ffb026c86c35 Mon Sep 17 00:00:00 2001 From: Aamir Ahmed Date: Mon, 7 Sep 2026 09:00:39 +0000 Subject: [PATCH 1280/2126] wifi: mt76: mt7996: validate TLV length in mt7996_mcu_ie_countdown() mt7996_mcu_ie_countdown() iterates over TLV entries in the countdown event but only checks for a non-zero tlv->len. A malformed event with a TLV length smaller than the 4-byte TLV header advances the cursor by less than a header size, causing misaligned reads on subsequent iterations. A TLV whose declared length exceeds the remaining buffer is also not caught, so the cursor can overshoot the end. The band field of the event header is also read without checking that the event is long enough to contain it. This is the same class of bug fixed for mt7925 in commit fc7801b7f11d ("wifi: mt76: mt7925: fix infinite loop in UNI event TLV parsing"). Fix by checking that the event contains the header before reading the band, and that each TLV is large enough to contain the countdown notify payload and does not exceed the remaining buffer. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Assisted-by: Claude (Anthropic) Signed-off-by: Aamir Ahmed Link: https://patch.msgid.link/AS8P251MB0001CCE8D1BEE1F330D9E57AC8B22@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c index 6acb8897feb8..a534d07ea1e8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c @@ -488,6 +488,9 @@ mt7996_mcu_ie_countdown(struct mt7996_dev *dev, struct sk_buff *skb) struct mt7996_mcu_countdown_notify *event; struct mt7996_mcu_countdown_data cdata; + if (skb->len < sizeof(*rxd) + sizeof(*hdr)) + return; + if (hdr->band >= ARRAY_SIZE(dev->mt76.phys)) return; @@ -497,9 +500,14 @@ mt7996_mcu_ie_countdown(struct mt7996_dev *dev, struct sk_buff *skb) tail = skb->data + skb->len; data += sizeof(*hdr); - while (data + sizeof(*tlv) < tail && le16_to_cpu(tlv->len)) { - event = (struct mt7996_mcu_countdown_notify *)tlv->data; + while (data + sizeof(*tlv) <= tail) { + u16 tag_len = le16_to_cpu(tlv->len); + if (tag_len < sizeof(*tlv) + sizeof(*event) || + data + tag_len > tail) + break; + + event = (struct mt7996_mcu_countdown_notify *)tlv->data; cdata.omac_idx = event->omac_idx; switch (le16_to_cpu(tlv->tag)) { @@ -517,7 +525,7 @@ mt7996_mcu_ie_countdown(struct mt7996_dev *dev, struct sk_buff *skb) break; } - data += le16_to_cpu(tlv->len); + data += tag_len; tlv = (struct tlv *)data; } } From 4014192e1cbe7775882c85692d517c00a97c1d35 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 3 Sep 2026 16:10:07 +0100 Subject: [PATCH 1281/2126] wifi: mt76: Fix spelling mistake "dowload" -> "download" There is a spelling mistake in a dev_err message. Fix it. Signed-off-by: Colin Ian King Reviewed-by: Chelsy Ratnawat Link: https://patch.msgid.link/20260903151007.14832-1-colin.i.king@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index 4ba3ff95e475..a1febfcb2a9c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -3125,7 +3125,7 @@ mt76_connac_mcu_send_phy_ram_firmware(struct mt76_dev *dev, err = mt76_connac_mcu_init_download(dev, addr, len, mode); if (err) { dev_err(dev->dev, - "The request to dowload PHY firmware failed.\n"); + "The request to download PHY firmware failed.\n"); return err; } From 2e48b38ac854d9f46fa0a7a36faf9335bf4ac184 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 3 Sep 2026 16:42:04 +0100 Subject: [PATCH 1282/2126] wifi: mt76: mt7996: Fix spelling mistake "retriving" -> "retrieving" There are multiple spelling mistakes in dev_warn messages. Fix them. Signed-off-by: Colin Ian King Link: https://patch.msgid.link/20260903154204.20872-1-colin.i.king@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/npu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/npu.c b/drivers/net/wireless/mediatek/mt76/mt7996/npu.c index b8006b8729a1..3fb9f39c2f61 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/npu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/npu.c @@ -283,7 +283,7 @@ static int mt7996_npu_rxd_init(struct mt7996_dev *dev, struct airoha_npu *npu) &val, GFP_KERNEL); if (err) { dev_warn(dev->mt76.dev, - "failed retriving NPU wlan rx ring0 addr\n"); + "failed retrieving NPU wlan rx ring0 addr\n"); return err; } writel(val, &dev->mt76.q_rx[MT_RXQ_RRO_BAND0].regs->desc_base); @@ -292,7 +292,7 @@ static int mt7996_npu_rxd_init(struct mt7996_dev *dev, struct airoha_npu *npu) &val, GFP_KERNEL); if (err) { dev_warn(dev->mt76.dev, - "failed retriving NPU wlan rx ring2 addr\n"); + "failed retrieving NPU wlan rx ring2 addr\n"); return err; } writel(val, &dev->mt76.q_rx[MT_RXQ_RRO_BAND2].regs->desc_base); @@ -302,7 +302,7 @@ static int mt7996_npu_rxd_init(struct mt7996_dev *dev, struct airoha_npu *npu) &val, GFP_KERNEL); if (err) { dev_warn(dev->mt76.dev, - "failed retriving NPU wlan msdu pg ring addr\n"); + "failed retrieving NPU wlan msdu pg ring addr\n"); return err; } writel(val, &dev->mt76.q_rx[MT_RXQ_MSDU_PAGE_BAND0].regs->desc_base); @@ -311,7 +311,7 @@ static int mt7996_npu_rxd_init(struct mt7996_dev *dev, struct airoha_npu *npu) &val, GFP_KERNEL); if (err) { dev_warn(dev->mt76.dev, - "failed retriving NPU wlan msdu pg ring addr\n"); + "failed retrieving NPU wlan msdu pg ring addr\n"); return err; } writel(val, &dev->mt76.q_rx[MT_RXQ_MSDU_PAGE_BAND1].regs->desc_base); @@ -320,7 +320,7 @@ static int mt7996_npu_rxd_init(struct mt7996_dev *dev, struct airoha_npu *npu) &val, GFP_KERNEL); if (err) { dev_warn(dev->mt76.dev, - "failed retriving NPU wlan msdu pg ring addr\n"); + "failed retrieving NPU wlan msdu pg ring addr\n"); return err; } writel(val, &dev->mt76.q_rx[MT_RXQ_MSDU_PAGE_BAND2].regs->desc_base); @@ -330,7 +330,7 @@ static int mt7996_npu_rxd_init(struct mt7996_dev *dev, struct airoha_npu *npu) &val, GFP_KERNEL); if (err) { dev_warn(dev->mt76.dev, - "failed retriving NPU wlan ind_cmd ring addr\n"); + "failed retrieving NPU wlan ind_cmd ring addr\n"); return err; } writel(val, &dev->mt76.q_rx[MT_RXQ_RRO_IND].regs->desc_base); From 158c1145fe7ddd82914011a00de7cc3262616b16 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 20 Aug 2026 12:45:01 +0000 Subject: [PATCH 1283/2126] wifi: mt76: fix wcid->pktid corruption in mt76_wcid_cleanup() mt76_wcid_cleanup() releases dev->status_lock before calling idr_destroy(&wcid->pktid) to tear down the pktid idr. Meanwhile, mt76_tx_status_skb_add() from tx.c can concurrently insert into that same idr during tx completion handling: spin_lock_bh(&dev->status_lock); pid = idr_alloc(&wcid->pktid, skb, MT_PACKET_ID_FIRST, MT_PACKET_ID_MASK, GFP_ATOMIC); Since idr_destroy() runs outside the lock, it can execute concurrently with idr_alloc() on the same idr, corrupting its internal data structures. Because idr nodes are freed through the generic slab allocator, this corruption can resurface later as an unrelated-looking crash anywhere in the kernel that happens to reuse the same freed memory. Fix this by calling idr_destroy() before releasing dev->status_lock, so that the table teardown and any concurrent insertion are mutually exclusive. Closes: https://github.com/openwrt/openwrt/issues/24594 Fixes: bd1e3e7b693c ("mt76: introduce packet_id idr") Signed-off-by: Ryan Leung Link: https://patch.msgid.link/20260820-mt76-pktid-idr-race-v1-1-451f176a6495@protonmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 3991696515e2..bc26833ff3f9 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1761,9 +1761,8 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid) mt76_tx_status_lock(dev, &list); mt76_tx_status_skb_get(dev, wcid, -1, &list); - mt76_tx_status_unlock(dev, &list); - idr_destroy(&wcid->pktid); + mt76_tx_status_unlock(dev, &list); /* Remove from sta_poll_list to prevent list corruption after reset. * Without this, mt76_reset_device() reinitializes sta_poll_list but From 8db0381351fe6af82f81693d5085790e291b2f17 Mon Sep 17 00:00:00 2001 From: Ethan Tidmore Date: Mon, 17 Aug 2026 20:54:40 -0500 Subject: [PATCH 1284/2126] wifi: mt76: mt7925: Remove useless condition The condition (master_pref > NAN_MAX_MASTER_PREFERENCE) will always be false because the variable 'master_pref' is of type u8 and the macro 'NAN_MAX_MASTER_PREFERENCE' is equal to 255. Fixes: a5487a6824068 ("wifi: mt76: mt7925: add NAN MCU helpers") Signed-off-by: Ethan Tidmore Link: https://patch.msgid.link/20260818015440.875703-1-ethantidmore06@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/nan.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c index 1adef4d52f65..ce2571832c08 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/nan.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/nan.c @@ -91,9 +91,6 @@ mt7925_nan_mp_tlv(struct sk_buff *skb, u8 master_pref) mp_tlv = (struct mt7925_nan_master_preference_tlv *)tlv; - if (master_pref > NAN_MAX_MASTER_PREFERENCE) - return 0; - mp_tlv->master_preference = master_pref; return 0; From 40217d8e6cba433a6ccb8c73737dd38b54dcc26f Mon Sep 17 00:00:00 2001 From: Ahmed Naseef Date: Wed, 19 Aug 2026 23:29:11 +0400 Subject: [PATCH 1285/2126] wifi: mt76: mt7615: read MT7663 temperature from the correct offset On MT7663 the hwmon temp1_input attribute always reads 0. mt7615_mcu_parse_response() takes the temperature from the first dword of the THERMAL_CTRL response payload, but MT7663 firmware reports it in the second one. On a DASAN H660GM-A (MT7663E, N9 firmware 7663mp1827) the request and its response are: request: 00 00 00 00 response: 00 00 00 00 2a 00 00 00 0x2a is the reading, 42 degrees, while the driver returns the leading zero. mt7915 and mt7921 already pull sizeof(*rxd) + 4 for this command. Restrict the extra pull to MT7663, as no MT7615 or MT7622 hardware was available to check whether their firmware uses the same layout. Fixes: f40ac0f3d3c0 ("mt76: mt7615: introduce mt7663e support") Signed-off-by: Ahmed Naseef Link: https://patch.msgid.link/20260819192911.1886457-1-naseefkm@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/mcu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c index ff57ede87f71..1ce0192c2c91 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c @@ -153,6 +153,8 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, ret = *skb->data; } else if (cmd == MCU_EXT_CMD(THERMAL_CTRL)) { skb_pull(skb, sizeof(*rxd)); + if (is_mt7663(mdev)) + skb_pull(skb, 4); ret = le32_to_cpu(*(__le32 *)skb->data); } else if (cmd == MCU_EXT_QUERY(RF_REG_ACCESS)) { skb_pull(skb, sizeof(*rxd)); From 8d604c899f7bd1a76a2eb21c0b706c02878abd36 Mon Sep 17 00:00:00 2001 From: Wentao Liang Date: Thu, 17 Sep 2026 12:19:44 +0000 Subject: [PATCH 1286/2126] wifi: mt76: Fix of_node reference leak in mt76_get_rate_power_limits() mt76_find_power_limits_node() and mt76_find_channel_node() return nodes with the reference held, but mt76_get_rate_power_limits() overwrites the "txpower-" node reference and never releases the channel node reference, leaking both. Drop the intermediate and the channel node reference on every exit path, and take a reference on the fallback node returned by mt76_find_power_limits_node() so the caller's of_node_put() is balanced. Fixes: 22b980badc0f ("mt76: add functions for parsing rate power limits from DT") Cc: stable@vger.kernel.org Signed-off-by: Wentao Liang Link: https://patch.msgid.link/20260917121944.2150737-1-vulab@iscas.ac.cn Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/eeprom.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c index afdb73661866..93552f6f7f34 100644 --- a/drivers/net/wireless/mediatek/mt76/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c @@ -231,12 +231,14 @@ mt76_find_power_limits_node(struct mt76_dev *dev) struct property *regd = of_find_property(cur, "regdomain", NULL); if (!country && !regd) { - fallback = cur; + of_node_put(fallback); + fallback = of_node_get(cur); continue; } if (mt76_string_prop_find(country, dev->alpha2) || mt76_string_prop_find(regd, region_name)) { + of_node_put(fallback); of_node_put(np); return cur; } @@ -429,7 +431,7 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, s8 target_power) { struct mt76_dev *dev = phy->dev; - struct device_node *np; + struct device_node *np, *band_np; const s8 *val; char name[16]; char band; @@ -459,15 +461,18 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, band = '6'; break; default: + of_node_put(np); return target_power; } snprintf(name, sizeof(name), "txpower-%cg", band); - np = of_get_child_by_name(np, name); - if (!np) + band_np = of_get_child_by_name(np, name); + of_node_put(np); + if (!band_np) return target_power; - np = mt76_find_channel_node(np, chan); + np = mt76_find_channel_node(band_np, chan); + of_node_put(band_np); if (!np) return target_power; @@ -514,6 +519,8 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, ARRAY_SIZE(dest->path.ru_bf), val, len, target_power, txs_delta, &max_power, n_chains, MT76_SKU_BACKOFF); + of_node_put(np); + return max_power; } EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits); From 356735fc612ea54062eb741ea15fa4ff7df4fc36 Mon Sep 17 00:00:00 2001 From: Pengpeng Hou Date: Sun, 30 Aug 2026 21:10:49 +0800 Subject: [PATCH 1287/2126] wifi: mt76: mt7615: validate MCU response lengths mt7615_mcu_parse_response() reads the common response header before checking its size and then consumes command-specific fields after unchecked skb_pull() calls. A short firmware response can therefore be read beyond its current extent. Validate the common header and each command-specific payload before reading it. Fixes: 0e6a29e477f3 ("mt76: mt7615: add support to read temperature from mcu") Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260830131049.2097-1-pengpeng@iscas.ac.cn Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/mcu.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c index 1ce0192c2c91..aab4303fef65 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c @@ -145,6 +145,9 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, } rxd = (struct mt7615_mcu_rxd *)skb->data; + if (skb->len < sizeof(*rxd)) + return -EMSGSIZE; + if (seq != rxd->seq) return -EAGAIN; @@ -152,11 +155,15 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, skb_pull(skb, sizeof(*rxd) - 4); ret = *skb->data; } else if (cmd == MCU_EXT_CMD(THERMAL_CTRL)) { + if (skb->len < sizeof(*rxd) + (is_mt7663(mdev) ? 8 : 4)) + return -EMSGSIZE; skb_pull(skb, sizeof(*rxd)); if (is_mt7663(mdev)) skb_pull(skb, 4); ret = le32_to_cpu(*(__le32 *)skb->data); } else if (cmd == MCU_EXT_QUERY(RF_REG_ACCESS)) { + if (skb->len < sizeof(*rxd) + 8 + sizeof(__le32)) + return -EMSGSIZE; skb_pull(skb, sizeof(*rxd)); ret = le32_to_cpu(*(__le32 *)&skb->data[8]); } else if (cmd == MCU_UNI_CMD(DEV_INFO_UPDATE) || @@ -167,12 +174,16 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, cmd == MCU_UNI_CMD(SUSPEND)) { struct mt76_connac_mcu_uni_event *event; + if (skb->len < sizeof(*rxd) + sizeof(*event)) + return -EMSGSIZE; skb_pull(skb, sizeof(*rxd)); event = (struct mt76_connac_mcu_uni_event *)skb->data; ret = le32_to_cpu(event->status); } else if (cmd == MCU_CE_QUERY(REG_READ)) { struct mt76_connac_mcu_reg_event *event; + if (skb->len < sizeof(*rxd) + sizeof(*event)) + return -EMSGSIZE; skb_pull(skb, sizeof(*rxd)); event = (struct mt76_connac_mcu_reg_event *)skb->data; ret = (int)le32_to_cpu(event->val); From 130eb5fc5904b2b9f237e08295629e4279b3da76 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 17:58:39 +0200 Subject: [PATCH 1288/2126] wifi: mt76: connac: pass the command to mt76_connac_mcu_chip_config() mt76_connac_mcu_chip_config() can only send the "assert" command, so mt76_connac_mcu_set_deep_sleep() builds the same CHIP_CONFIG request by itself. A further command for mt7921 would add a third copy. Make the command a parameter and send the deep sleep command through it, like mt7925_mcu_chip_config() does for mt7925. Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c | 2 +- .../net/wireless/mediatek/mt76/mt76_connac_mcu.c | 13 +++++-------- .../net/wireless/mediatek/mt76/mt76_connac_mcu.h | 2 +- drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c index 6a1475e3c899..83cffa94bc0e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c @@ -54,7 +54,7 @@ static int mt7615_config(void *data, u64 val) int ret; mt7615_mutex_acquire(dev); - ret = mt76_connac_mcu_chip_config(&dev->mt76); + ret = mt76_connac_mcu_chip_config(&dev->mt76, "assert"); mt7615_mutex_release(dev); return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index a1febfcb2a9c..9bdfff24b702 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -2041,13 +2041,13 @@ int mt76_connac_mcu_sched_scan_enable(struct mt76_phy *phy, } EXPORT_SYMBOL_GPL(mt76_connac_mcu_sched_scan_enable); -int mt76_connac_mcu_chip_config(struct mt76_dev *dev) +int mt76_connac_mcu_chip_config(struct mt76_dev *dev, const char *cmd) { struct mt76_connac_config req = { .resp_type = 0, }; - strscpy(req.data, "assert"); + strscpy(req.data, cmd); return mt76_mcu_send_msg(dev, MCU_CE_CMD(CHIP_CONFIG), &req, sizeof(req), false); @@ -2056,14 +2056,11 @@ EXPORT_SYMBOL_GPL(mt76_connac_mcu_chip_config); int mt76_connac_mcu_set_deep_sleep(struct mt76_dev *dev, bool enable) { - struct mt76_connac_config req = { - .resp_type = 0, - }; + char cmd[16]; - snprintf(req.data, sizeof(req.data), "KeepFullPwr %d", !enable); + snprintf(cmd, sizeof(cmd), "KeepFullPwr %d", !enable); - return mt76_mcu_send_msg(dev, MCU_CE_CMD(CHIP_CONFIG), - &req, sizeof(req), false); + return mt76_connac_mcu_chip_config(dev, cmd); } EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_deep_sleep); diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h index 0ededa569e9a..45f77c80e879 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h @@ -2098,7 +2098,7 @@ void mt76_connac_mcu_set_suspend_iter(void *priv, u8 *mac, int mt76_connac_sta_state_dp(struct mt76_dev *dev, enum ieee80211_sta_state old_state, enum ieee80211_sta_state new_state); -int mt76_connac_mcu_chip_config(struct mt76_dev *dev); +int mt76_connac_mcu_chip_config(struct mt76_dev *dev, const char *cmd); int mt76_connac_mcu_set_deep_sleep(struct mt76_dev *dev, bool enable); void mt76_connac_mcu_coredump_event(struct mt76_dev *dev, struct sk_buff *skb, struct mt76_connac_coredump *coredump); diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c index a5a70d8e8544..62bf33347e9e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c @@ -237,7 +237,7 @@ static int mt7921_chip_reset(void *data, u64 val) default: /* Collect the core dump before reset wifisys. */ mt792x_mutex_acquire(dev); - ret = mt76_connac_mcu_chip_config(&dev->mt76); + ret = mt76_connac_mcu_chip_config(&dev->mt76, "assert"); mt792x_mutex_release(dev); break; } From c2f5993f1f169f7865cb01e61b9a78cf80ba1483 Mon Sep 17 00:00:00 2001 From: Allen Chien Date: Wed, 30 Sep 2026 11:36:29 +0800 Subject: [PATCH 1289/2126] wifi: mt76: mt7921: enable thermal protection Enable the firmware thermal protection for MT7920/MT7921/MT7922 by sending the DowngradeTxStreamTemp chip config command each time the firmware starts, so that the setting also applies after a chip reset. Signed-off-by: Allen Chien Link: https://patch.msgid.link/20260930033630.1020235-1-jb.tsai@mediatek.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 17 +++++++++++++++++ .../net/wireless/mediatek/mt76/mt7921/mt7921.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c index c90d0da706a1..bdeb6614a5a9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -676,6 +676,10 @@ int mt7921_run_firmware(struct mt792x_dev *dev) return err; set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); + err = mt7921_mcu_set_thermal_protect(dev); + if (err) + return err; + return mt7921_mcu_fw_log_2_host(dev, 1); } EXPORT_SYMBOL_GPL(mt7921_run_firmware); @@ -1479,6 +1483,19 @@ int mt7921_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy, u8 action) sizeof(req), action ? true : false); } +#define MT7921_THERMAL_PROT_LOW_TEMP 105 +#define MT7921_THERMAL_PROT_HIGH_TEMP 115 + +int mt7921_mcu_set_thermal_protect(struct mt792x_dev *dev) +{ + char cmd[64]; + + snprintf(cmd, sizeof(cmd), "DowngradeTxStreamTemp %d %d", + MT7921_THERMAL_PROT_LOW_TEMP, MT7921_THERMAL_PROT_HIGH_TEMP); + + return mt76_connac_mcu_chip_config(&dev->mt76, cmd); +} + int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, u8 bit_op, u32 bit_map) { diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h index f7ed11353d28..3baf6094612f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h @@ -329,6 +329,7 @@ int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, int mt7921_mcu_config_sniffer(struct mt792x_vif *vif, struct ieee80211_chanctx_conf *ctx); int mt7921_mcu_get_temperature(struct mt792x_phy *phy); +int mt7921_mcu_set_thermal_protect(struct mt792x_dev *dev); int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, enum mt76_txq_id qid, struct mt76_wcid *wcid, From fb03c4204498f300ffa3324f2e90df5742a2984d Mon Sep 17 00:00:00 2001 From: Slavin Liu Date: Fri, 11 Sep 2026 14:09:22 +0800 Subject: [PATCH 1290/2126] wifi: mt76: mt7996: guard station-only MLO TX handling Pending frames can be retried after their station is no longer available. Require a station for both MLO-specific branches and retain the existing non-station transmission path for valid vif traffic. Detected by static analysis and reviewed with AI-assisted source auditing. Fixes: 7ef0c7ad735b ("wifi: mt76: mt7996: Implement MLD address translation for EAPOL") Fixes: 85cd5534a3f2 ("wifi: mt76: mt7996: use correct link_id when filling TXD and TXP") Assisted-by: LLM Signed-off-by: Slavin Liu Link: https://patch.msgid.link/20260911060922.94383-1-bolin.liu@seu.edu.cn Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index 42c0c53f1023..eb39526548e8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -1057,7 +1057,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, if (!wcid) wcid = &dev->mt76.global_wcid; - if ((is_8023 || ieee80211_is_data_qos(hdr->frame_control)) && sta->mlo && + if (sta && (is_8023 || ieee80211_is_data_qos(hdr->frame_control)) && sta->mlo && likely(tx_info->skb->protocol != cpu_to_be16(ETH_P_PAE))) { u8 tid = tx_info->skb->priority & IEEE80211_QOS_CTL_TID_MASK; @@ -1097,7 +1097,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, * compatible with 802.11 EAPOL frame, we do the translation by * software */ - if (tx_info->skb->protocol == cpu_to_be16(ETH_P_PAE) && sta->mlo) { + if (sta && tx_info->skb->protocol == cpu_to_be16(ETH_P_PAE) && sta->mlo) { struct ieee80211_hdr *hdr = (void *)tx_info->skb->data; struct ieee80211_bss_conf *link_conf; struct ieee80211_link_sta *link_sta; From d0115096429ca090a592770c7645f9553a839954 Mon Sep 17 00:00:00 2001 From: Yi Cong Date: Mon, 24 Aug 2026 10:14:29 +0800 Subject: [PATCH 1291/2126] wifi: mt76: mt792x: fix negative errno truncation in offload capability Returning a negative errno as u8 turned -ENOENT into 0xfe, wrongly enabling CNM and NAN caps. Return int and default to no caps on error. Fixes: e8a264ccd2de ("wifi: mt76: mt7921: move init shared code in mt792x-lib module") Cc: stable@vger.kernel.org Signed-off-by: Yi Cong Link: https://patch.msgid.link/20260824021429.43761-1-cong.yi@linux.dev Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt792x_core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c index f56f03bfe387..3ce6c6ceac81 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c @@ -858,7 +858,7 @@ int mt792x_init_wiphy(struct ieee80211_hw *hw) } EXPORT_SYMBOL_GPL(mt792x_init_wiphy); -static u8 +static int mt792x_get_offload_capability(struct device *dev, const char *fw_wm) { const struct mt76_connac2_fw_trailer *hdr; @@ -927,13 +927,20 @@ mt792x_get_mac80211_ops(struct device *dev, void *drv_data, u8 *fw_features) { struct ieee80211_ops *ops; + int ret; ops = devm_kmemdup(dev, mac80211_ops, sizeof(struct ieee80211_ops), GFP_KERNEL); if (!ops) return NULL; - *fw_features = mt792x_get_offload_capability(dev, drv_data); + ret = mt792x_get_offload_capability(dev, drv_data); + if (ret < 0) { + dev_warn(dev, "failed to read firmware offload caps: %d\n", ret); + *fw_features = 0; + } else { + *fw_features = ret; + } if (mt792x_needs_cnm_runtime(drv_data)) *fw_features |= MT792x_FW_CAP_CNM; From d92bac6b6af2602516ee82ae112709c71af27cf6 Mon Sep 17 00:00:00 2001 From: Linlin Yang Date: Mon, 24 Aug 2026 17:29:37 +0800 Subject: [PATCH 1292/2126] wifi: mt76: mt7996: fix PCI device reference leak in mt7996_pci_init_hif2() pci_get_device() increments the reference count on the returned struct pci_dev. In mt7996_pci_init_hif2(), three pci_get_device() calls are made but their return values are only checked for NULL and then discarded. pci_dev_put() is never called, causing a PCI device reference count leak. Fix this by storing the return value and calling pci_dev_put() before returning, following the same pattern already used in the sibling driver mt7915/pci.c. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Cc: stable@vger.kernel.org Signed-off-by: Linlin Yang Link: https://patch.msgid.link/20260824092937.683240-1-yanglinlin@kylinos.cn Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/pci.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c index b7d9193e042f..a7c23b33dde0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c @@ -63,12 +63,18 @@ static void mt7996_put_hif2(struct mt7996_hif *hif) static struct mt7996_hif *mt7996_pci_init_hif2(struct pci_dev *pdev) { + struct pci_dev *tmp_pdev; + hif_idx++; - if (!pci_get_device(PCI_VENDOR_ID_MEDIATEK, MT7996_DEVICE_ID_2, NULL) && - !pci_get_device(PCI_VENDOR_ID_MEDIATEK, MT7992_DEVICE_ID_2, NULL) && - !pci_get_device(PCI_VENDOR_ID_MEDIATEK, MT7990_DEVICE_ID_2, NULL)) + tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, MT7996_DEVICE_ID_2, NULL); + if (!tmp_pdev) + tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, MT7992_DEVICE_ID_2, NULL); + if (!tmp_pdev) + tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, MT7990_DEVICE_ID_2, NULL); + if (!tmp_pdev) return NULL; + pci_dev_put(tmp_pdev); writel(hif_idx | MT_PCIE_RECOG_ID_SEM, pcim_iomap_table(pdev)[0] + MT_PCIE_RECOG_ID); From c182bfe944eb275f7526cc326f81229b0e974a0c Mon Sep 17 00:00:00 2001 From: "ck.chang" Date: Wed, 5 Aug 2026 17:24:09 +0800 Subject: [PATCH 1293/2126] wifi: mt76: mt7925: fix reset panic caused by the WM2 rx irq mask mt7925_irq_map sets wm2_complete_mask, but mt7925_dma_layout has no tx done ring, so the MT_RXQ_MCU_WA queue and its NAPI are never set up. On a chip reset, mt7925e_mac_reset() calls napi_disable() on that NAPI and crashes: BUG: kernel NULL pointer dereference, address: 0000000000000a40 Workqueue: mt76 mt7925_mac_reset_work [mt7925_common] RIP: 0010:mutex_lock+0x1c/0x50 Call Trace: napi_disable+0x1d/0x50 mt7925e_mac_reset+0x327/0x420 [mt7925e] mt7925_mac_reset_work+0x9a/0x1a0 [mt7925_common] Remove the WM2 mask from mt7925_irq_map and from MT7925_INT_RX_DONE_ALL. Fixes: c4edf9e3e0e5 ("wifi: mt76: mt7925: replace shared rx irq masks with per-chip definitions") Signed-off-by: ck.chang Link: https://patch.msgid.link/20260805092409.1489401-1-eason.lai@mediatek.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/pci.c | 1 - drivers/net/wireless/mediatek/mt76/mt7925/regs.h | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c index 24585c992ff5..76d8f8ea19ec 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c @@ -494,7 +494,6 @@ static const struct mt792x_irq_map mt7925_irq_map = { .all_complete_mask = MT7925_INT_RX_DONE_ALL, .data_complete_mask = MT7925_INT_RX_DONE_DATA, .wm_complete_mask = MT7925_INT_RX_DONE_WM, - .wm2_complete_mask = MT_INT_RX_DONE_WM2, }, }; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/regs.h b/drivers/net/wireless/mediatek/mt76/mt7925/regs.h index ab6c33b4a180..e040dff321dd 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/regs.h @@ -48,8 +48,7 @@ #define MT7925_INT_RX_DONE_DATA HOST_RX_DONE_INT_ENA2 #define MT7925_INT_RX_DONE_WM HOST_RX_DONE_INT_ENA0 #define MT7925_INT_RX_DONE_ALL (MT7925_INT_RX_DONE_DATA | \ - MT7925_INT_RX_DONE_WM | \ - MT_INT_RX_DONE_WM2) + MT7925_INT_RX_DONE_WM) #define MT7927_INT_RX_DONE_DATA MT7927_RX_DONE_INT_ENA4 #define MT7927_INT_RX_DONE_WM MT7927_RX_DONE_INT_ENA6 From e1534fef1ae4df6e16401117394c26dbef84f361 Mon Sep 17 00:00:00 2001 From: Cristian Papa Date: Thu, 24 Sep 2026 00:26:39 -0300 Subject: [PATCH 1294/2126] wifi: mt76: feed the station RSSI average from the chain signals mt76_check_sta() adds status->signal of every received frame to the station's RSSI average, wcid->rssi, which mt76_get_min_avg_rssi() reads for the dynamic sensitivity of mt7603 and mt7615 and for the gain control of mt76x0 and mt76x2. Since commit 4550fb9e9810 ("mt76: improve signal strength reporting"), drivers no longer set status->signal: mt76_rx_convert() computes it from the chain values when the frame is handed to mac80211, after mt76_check_sta() has run. Except on mt7921, which still sets it, the average is fed zeros. mt76_get_min_avg_rssi() then returns 0, so mt7603 and mt7615 leave the sensitivity at its default, and mt76x0 and mt76x2 fall back to -75 dBm for their gain settings. Compute the signal from the chain values in mt76_check_sta() as well, as mt76_rx_convert() does. On mt7921, the average now follows the same combined value that mac80211 gets instead of the strongest chain. Tested on a TP-Link Archer XR500v with one client, switching between the old and the new input every 30 seconds. On the MT7662E (mt76x2), the average the AGC works with was -75 dBm, its fallback, with the old input and -54 dBm with the new one, while iw reported -54 and -52 dBm for the station, and the AGC mostly used its low_gain 2 setting instead of 1. On the MT7603E, the station average was 0 with the old input and -41 dBm with the new one, while iw reported -42 and -41 dBm. The mt7603 sensitivity still stayed at its default: a separate bug keeps it from leaving 0. Fixes: 4550fb9e9810 ("mt76: improve signal strength reporting") Assisted-by: LLM Signed-off-by: Cristian Papa Link: https://patch.msgid.link/20260924032639.28158-1-pcristian292@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index bc26833ff3f9..48349bbc5a8f 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1485,6 +1485,7 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb) struct ieee80211_hw *hw; struct mt76_wcid *wcid = status->wcid; u8 tidno = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK; + int signal; bool ps; hw = mt76_phy_hw(dev, status->phy_idx); @@ -1502,8 +1503,9 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb) sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv); - if (status->signal <= 0) - ewma_signal_add(&wcid->rssi, -status->signal); + signal = mt76_rx_signal(status->chains, status->chain_signal); + if (signal <= 0 && signal > -128) + ewma_signal_add(&wcid->rssi, -signal); wcid->inactive_count = 0; From 87b67aa8eb32cf89dab4c6df88d65e07fec46592 Mon Sep 17 00:00:00 2001 From: Mahesh Saran Date: Tue, 6 Oct 2026 22:05:53 +0530 Subject: [PATCH 1295/2126] wifi: mt76: mt7921: clear WM2 from MT7902 RX all_complete_mask MT7902 does not have an MCU_WA ring and sets wm2_complete_mask to 0. However, commit 83c65e82e5b2 ("wifi: mt76: connac2: apply new rx all_complete_mask") populated all_complete_mask in the shared irq_map template with MT_INT_RX_DONE_ALL, which includes MT_INT_RX_DONE_WM2. Because MT7902 duplicates irq_map but only clears wm2_complete_mask, its all_complete_mask still contains MT_INT_RX_DONE_WM2. This leaves the MT7902 RX interrupt configuration inconsistent: the aggregate RX completion mask includes WM2 even though the corresponding RX queue is not present on MT7902. Clear MT_INT_RX_DONE_WM2 from all_complete_mask for MT7902 as well. Fixes: 83c65e82e5b2 ("wifi: mt76: connac2: apply new rx all_complete_mask") Signed-off-by: Mahesh Saran Link: https://patch.msgid.link/20261006163553.11193-1-maheshsaran477@gmail.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c index 56a914aaa81e..f87c44f2a8b6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -375,6 +375,7 @@ static int mt7921_pci_probe(struct pci_dev *pdev, } map->rx.wm2_complete_mask = 0; + map->rx.all_complete_mask &= ~MT_INT_RX_DONE_WM2; dev->irq_map = map; } From 79941e85f4b3b1385b545cf18998fda6e1176919 Mon Sep 17 00:00:00 2001 From: Eason Lai Date: Mon, 17 Aug 2026 13:28:39 +0800 Subject: [PATCH 1296/2126] wifi: mt76: mt7925: Fix MCU command timeouts during module unload Move MT76_REMOVED flag setting from mt7925_pci_remove() to after mt76_unregister_device() completes. Setting it too early causes mt792x_irq_handler() to drop MCU completion interrupts, timing out teardown commands (scan abort, BSS_INFO_UPDATE, etc). The flag must still be set before napi_disable() to prevent reset_work from re-enabling NAPI and causing deadlock. Also guard mt792x_reset() to skip queuing work when device is removed. With nothing associated it still costs 9 to 10 seconds, so a bare rmmod does reach this, just small enough there to read as normal teardown. Fixes: eb628006a2c6 ("wifi: mt76: mt7925: Fix unregister deadlock") Tested-by: Devin Wittmayer Signed-off-by: Eason Lai Link: https://patch.msgid.link/20260817052840.99478-1-eason.lai@mediatek.com Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7925/pci.c | 4 ++-- drivers/net/wireless/mediatek/mt76/mt792x_mac.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c index 76d8f8ea19ec..12c1f7868d91 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c @@ -47,9 +47,10 @@ static void mt7925e_unregister_device(struct mt792x_dev *dev) if (dev->phy.chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN) wiphy_rfkill_stop_polling(hw->wiphy); - cancel_work_sync(&dev->reset_work); cancel_work_sync(&dev->init_work); mt76_unregister_device(&dev->mt76); + set_bit(MT76_REMOVED, &dev->mphy.state); + cancel_work_sync(&dev->reset_work); mt76_for_each_q_rx(&dev->mt76, i) napi_disable(&dev->mt76.napi[i]); cancel_delayed_work_sync(&pm->ps_work); @@ -725,7 +726,6 @@ static void mt7925_pci_remove(struct pci_dev *pdev) struct mt76_dev *mdev = pci_get_drvdata(pdev); struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); - set_bit(MT76_REMOVED, &mdev->phy.state); mt7925e_unregister_device(dev); devm_free_irq(&pdev->dev, pdev->irq, dev); mt76_free_device(&dev->mt76); diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_mac.c b/drivers/net/wireless/mediatek/mt76/mt792x_mac.c index 888e5a505673..1e20b333cc61 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_mac.c @@ -278,6 +278,9 @@ void mt792x_reset(struct mt76_dev *mdev) if (pm->suspended) return; + if (test_bit(MT76_REMOVED, &mdev->phy.state)) + return; + queue_work(dev->mt76.wq, &dev->reset_work); } EXPORT_SYMBOL_GPL(mt792x_reset); From 9ae1a74a7f9fb12632edb15801a927afd008a4c3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 11 Aug 2026 17:45:38 +0800 Subject: [PATCH 1297/2126] wifi: mt76: mt7925: add AXI DMA calibration cache for MT7928 MT7928 supports caching calibration (fact-cal) data in a host-side DMA buffer over AXI DMA, so the firmware can reuse previously computed calibration results across warm resets instead of recomputing them on every bring-up. Add a new cached_cal source file under mt7925/, built into mt7925e since the cache is reachable only over PCIe AXI DMA, that: - allocates a coherent DMA region laid out for the common/group/channel fact-cal buffers plus the mapping table, - programs the firmware with the region base/offset via the new MCU_UNI_CMD_AXIDMA command, - builds and streams the fact-cal mapping table to the firmware via the new MCU_UNI_CMD_FACT_CAL command. On MT7928 run-firmware, the cache is enabled only when the chip advertises MT792x_CHIP_CAP_AXIDMA_EN. A carried-over buffer that still holds FW-written cal data is reused (reused=true); a freshly allocated zeroed buffer starts cold. The region is freed on device unregister. The buf_info and mapping-table layouts are size-asserted to match the MT7928 firmware ABI. Signed-off-by: Allan Wang Link: https://patch.msgid.link/20260811094538.588332-1-allan.wang@mediatek.com Signed-off-by: Felix Fietkau --- .../wireless/mediatek/mt76/mt76_connac_mcu.h | 2 + .../wireless/mediatek/mt76/mt7925/Makefile | 2 +- .../mediatek/mt76/mt7925/cached_cal.c | 298 ++++++++++++++++++ .../mediatek/mt76/mt7925/cached_cal.h | 151 +++++++++ .../wireless/mediatek/mt76/mt7925/mt7925.h | 1 + .../net/wireless/mediatek/mt76/mt7925/pci.c | 60 +++- .../wireless/mediatek/mt76/mt7925/pci_mac.c | 2 + .../wireless/mediatek/mt76/mt7925/pci_mcu.c | 2 + drivers/net/wireless/mediatek/mt76/mt792x.h | 8 + 9 files changed, 524 insertions(+), 2 deletions(-) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.h diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h index 45f77c80e879..74e37d722710 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h @@ -1357,9 +1357,11 @@ enum { MCU_UNI_CMD_ALL_STA_INFO = 0x6e, MCU_UNI_CMD_ASSERT_DUMP = 0x6f, MCU_UNI_CMD_EXT_EEPROM_CTRL = 0x74, + MCU_UNI_CMD_FACT_CAL = 0x7c, MCU_UNI_CMD_RADIO_STATUS = 0x80, MCU_UNI_CMD_MLD = 0x82, MCU_UNI_CMD_SDO = 0x88, + MCU_UNI_CMD_AXIDMA = 0xa2, }; enum { diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/Makefile b/drivers/net/wireless/mediatek/mt76/mt7925/Makefile index f9dcc0bba393..33539121a15c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/Makefile +++ b/drivers/net/wireless/mediatek/mt76/mt7925/Makefile @@ -6,5 +6,5 @@ obj-$(CONFIG_MT7925U) += mt7925u.o mt7925-common-y := mac.o mcu.o regd.o main.o init.o debugfs.o nan.o mt7925-common-$(CONFIG_NL80211_TESTMODE) += testmode.o -mt7925e-y := pci.o pci_mac.o pci_mcu.o +mt7925e-y := pci.o pci_mac.o pci_mcu.o cached_cal.o mt7925u-y := usb.o diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c b/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c new file mode 100644 index 000000000000..0209606e1a47 --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c @@ -0,0 +1,298 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +/* Copyright (C) 2026 MediaTek Inc. */ + +#include +#include "../mt792x.h" +#include "cached_cal.h" + +static void mt7925_cal_cache_calc_layout(struct mt7925_cal_cache_layout *l) +{ + u32 hdr = sizeof(struct mt7925_fact_cal_buf_info); + + l->common_stride = hdr + MT7925_FACT_CAL_LEN_COM; + l->group_stride = hdr + MT7925_FACT_CAL_LEN_GRP; + l->channel_stride = hdr + MT7925_FACT_CAL_LEN_CH; + + l->common_off = 0; + l->group_off = l->common_off + + l->common_stride * MT7925_FACT_CAL_COMMON_BAND_NUM; + l->channel_off = l->group_off + + l->group_stride * MT7925_FACT_CAL_GROUP_NUM; + l->mapping_off = l->channel_off + + l->channel_stride * MT7925_FACT_CAL_CH_NUM_ALL; + l->total = l->mapping_off + + sizeof(struct mt7925_fact_cal_mapping_tbl); +} + +static u32 mt7925_cal_cache_region_size(void) +{ + struct mt7925_cal_cache_layout l; + + mt7925_cal_cache_calc_layout(&l); + + return l.total; +} + +int mt7925_axidma_alloc(struct mt792x_dev *dev) +{ + u32 total_size; + dma_addr_t dma_addr; + void *va; + + if (dev->cached_cal.va) + return 0; + + total_size = mt7925_cal_cache_region_size(); + + va = dma_alloc_coherent(dev->mt76.dev, total_size, &dma_addr, + GFP_KERNEL); + if (!va) + return -ENOMEM; + + dev->cached_cal.va = va; + dev->cached_cal.dma_addr = dma_addr; + dev->cached_cal.size = total_size; + + return 0; +} + +void mt7925_axidma_free(struct mt792x_dev *dev) +{ + if (!dev->cached_cal.va) + return; + + dma_free_coherent(dev->mt76.dev, dev->cached_cal.size, + dev->cached_cal.va, dev->cached_cal.dma_addr); + + memset(&dev->cached_cal, 0, sizeof(dev->cached_cal)); +} + +int mt7925_mcu_send_axidma_info(struct mt792x_dev *dev) +{ + struct mt7925_axidma_info_req *req; + u32 remap_base, pa_offset; + int ret; + + if (!dev->cached_cal.va) + return -EINVAL; + + req = kzalloc(sizeof(*req), GFP_KERNEL); + if (!req) + return -ENOMEM; + + remap_base = (u32)(dev->cached_cal.dma_addr >> 16); + pa_offset = (u32)(dev->cached_cal.dma_addr & 0xFFFF); + + req->remap.tag = cpu_to_le16(MT7925_AXIDMA_TAG_REMAP); + req->remap.len = cpu_to_le16(sizeof(req->remap)); + req->remap.remap_addr = cpu_to_le32(remap_base); + + req->fact_cal.tag = cpu_to_le16(MT7925_AXIDMA_TAG_FACT_CAL); + req->fact_cal.len = cpu_to_le16(sizeof(req->fact_cal)); + req->fact_cal.host_addr_offset = cpu_to_le32(pa_offset); + req->fact_cal.size = cpu_to_le32(dev->cached_cal.size); + req->fact_cal.bound = cpu_to_le32(pa_offset + dev->cached_cal.size - 1); + + ret = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(AXIDMA), + req, sizeof(*req), true); + + kfree(req); + + if (ret) + dev_err(dev->mt76.dev, + "failed to send AXI DMA info: %d\n", ret); + + return ret; +} + +static bool mt7925_cal_cache_read_slot(struct mt792x_dev *dev, u32 region_off, + u32 stride, u32 idx, + u32 *cal_param, u32 *total_buf_num) +{ + const struct mt7925_fact_cal_buf_info *bi; + u32 off = region_off + stride * idx; + + if (!dev->cached_cal.va || off + sizeof(*bi) > dev->cached_cal.size) + return false; + + bi = (const struct mt7925_fact_cal_buf_info *) + ((const u8 *)dev->cached_cal.va + off); + if (cal_param) + *cal_param = le32_to_cpu(bi->cal_param); + if (total_buf_num) + *total_buf_num = le32_to_cpu(bi->total_buf_num); + return true; +} + +static void mt7925_fact_cal_build_mapping_tbl(struct mt792x_dev *dev, + struct mt7925_fact_cal_mapping_tbl *tbl) +{ + dma_addr_t common_pa, group_pa, channel_pa, mapping_pa; + u32 hdr = sizeof(struct mt7925_fact_cal_buf_info); + dma_addr_t base = dev->cached_cal.dma_addr; + struct mt7925_cal_cache_layout l; + + mt7925_cal_cache_calc_layout(&l); + + common_pa = base + l.common_off; + group_pa = base + l.group_off; + channel_pa = base + l.channel_off; + mapping_pa = base + l.mapping_off; + + memset(tbl, 0, sizeof(*tbl)); + + tbl->common.phy_addr_h = cpu_to_le32(upper_32_bits(common_pa)); + tbl->common.phy_addr_l = cpu_to_le32(lower_32_bits(common_pa)); + tbl->common.offset = cpu_to_le32(l.common_stride); + + tbl->group.phy_addr_h = cpu_to_le32(upper_32_bits(group_pa)); + tbl->group.phy_addr_l = cpu_to_le32(lower_32_bits(group_pa)); + tbl->group.offset = cpu_to_le32(l.group_stride); + + tbl->channel.phy_addr_h = cpu_to_le32(upper_32_bits(channel_pa)); + tbl->channel.phy_addr_l = cpu_to_le32(lower_32_bits(channel_pa)); + tbl->channel.offset = cpu_to_le32(l.channel_stride); + + if (dev->cached_cal.reused) { + u32 i, cal_param, total_buf_num; + + for (i = 0; i < MT7925_FACT_CAL_COMMON_BAND_NUM; i++) + if (mt7925_cal_cache_read_slot(dev, l.common_off, + l.common_stride, i, + &cal_param, NULL)) + tbl->common.band[i] = cal_param & 0xff; + + for (i = 0; i < MT7925_FACT_CAL_GROUP_NUM; i++) + if (mt7925_cal_cache_read_slot(dev, l.group_off, + l.group_stride, i, + &cal_param, NULL)) + tbl->group.group[i] = cal_param & 0xff; + + for (i = 0; i < MT7925_FACT_CAL_CH_NUM_ALL; i++) + if (mt7925_cal_cache_read_slot(dev, l.channel_off, + l.channel_stride, i, + &cal_param, + &total_buf_num)) { + tbl->channel.cal_param[i] = + cpu_to_le32(cal_param); + tbl->channel.total_buf_num[i] = + total_buf_num & 0xff; + } + } + + tbl->buf_info_size = cpu_to_le32(hdr); + tbl->phy_addr_h = cpu_to_le32(upper_32_bits(mapping_pa)); + tbl->phy_addr_l = cpu_to_le32(lower_32_bits(mapping_pa)); +} + +static int mt7925_mcu_fact_cal_rapid_set(struct mt792x_dev *dev, u8 cal_type, + u32 seq_num, bool done, + const void *data, u32 data_len) +{ + struct mt7925_fact_cal_req *req; + int ret; + + if (data_len > MT7925_FACT_CAL_DATA_BUF_LEN) + return -EINVAL; + + req = kzalloc(sizeof(*req), GFP_KERNEL); + if (!req) + return -ENOMEM; + + req->set.tag = cpu_to_le16(MT7925_FACT_CAL_TAG_RAPID_SET); + req->set.len = cpu_to_le16(sizeof(req->set)); + req->set.seq_num = cpu_to_le32(seq_num); + req->set.buf_data_len = cpu_to_le32(data_len); + req->set.cal_type = cal_type; + req->set.done = done; + if (data && data_len) + memcpy(req->set.buf_data, data, data_len); + + ret = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(FACT_CAL), + req, sizeof(*req), true); + kfree(req); + + return ret; +} + +int mt7925_mcu_send_fact_cal_mapping_tbl(struct mt792x_dev *dev) +{ + struct mt7925_fact_cal_mapping_tbl *tbl; + __le32 cfg[MT7925_FACT_CAL_BUF_CFG_LEN / sizeof(__le32)] = {0}; + u32 seq = 0, off = 0, left; + int ret; + + if (!dev->cached_cal.va) + return -EINVAL; + + tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); + if (!tbl) + return -ENOMEM; + + mt7925_fact_cal_build_mapping_tbl(dev, tbl); + + cfg[1] = cpu_to_le32(sizeof(*tbl)); + cfg[2] = cpu_to_le32(MT7925_FACT_CAL_DATA_BUF_NUM_MAX); + ret = mt7925_mcu_fact_cal_rapid_set(dev, MT7925_FACT_CAL_TYPE_MAPPING_TBL, + seq, false, cfg, sizeof(cfg)); + if (ret) { + dev_err(dev->mt76.dev, + "fact-cal mapping tbl header send failed (seq=%u): %d\n", + seq, ret); + goto out; + } + + left = sizeof(*tbl); + while (left) { + u32 chunk = min_t(u32, left, MT7925_FACT_CAL_DATA_BUF_LEN); + + ret = mt7925_mcu_fact_cal_rapid_set(dev, + MT7925_FACT_CAL_TYPE_MAPPING_TBL, + ++seq, false, + (u8 *)tbl + off, chunk); + if (ret) { + dev_err(dev->mt76.dev, + "fact-cal mapping tbl data send failed (seq=%u, off=%u, chunk=%u): %d\n", + seq, off, chunk, ret); + goto out; + } + + off += chunk; + left -= chunk; + } + + ret = mt7925_mcu_fact_cal_rapid_set(dev, MT7925_FACT_CAL_TYPE_MAPPING_TBL, + ++seq, true, NULL, 0); + if (ret) { + dev_err(dev->mt76.dev, + "fact-cal mapping tbl done send failed (seq=%u): %d\n", + seq, ret); + goto out; + } +out: + kfree(tbl); + + return ret; +} + +int mt7925_mcu_fact_cal_set_bypass(struct mt792x_dev *dev, bool enable) +{ + struct { + u8 _rsv[4]; + + struct { + __le16 tag; + __le16 len; + __le32 data; + } __packed update_flag; + } req = { + .update_flag = { + .tag = cpu_to_le16(MT7925_FACT_CAL_TAG_UPDATE_FLAG), + .len = cpu_to_le16(sizeof(req.update_flag)), + .data = cpu_to_le32(enable ? 1 : 0), + }, + }; + + return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(FACT_CAL), + &req, sizeof(req), true); +} diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.h b/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.h new file mode 100644 index 000000000000..6572513b7646 --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.h @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: BSD-3-Clause-Clear */ +/* Copyright (C) 2026 MediaTek Inc. */ + +#ifndef __CACHED_CAL_H +#define __CACHED_CAL_H + +enum mt7925_axidma_info_tag { + MT7925_AXIDMA_TAG_REMAP = 0, + MT7925_AXIDMA_TAG_FACT_CAL = 1, + MT7925_AXIDMA_TAG_NUM +}; + +enum mt7925_fact_cal_tag { + MT7925_FACT_CAL_TAG_TRIGGER = 2, + MT7925_FACT_CAL_TAG_UPDATE_FLAG = 3, + MT7925_FACT_CAL_TAG_RAPID_GET = 4, + MT7925_FACT_CAL_TAG_RAPID_SET = 5, +}; + +enum mt7925_fact_cal_type { + MT7925_FACT_CAL_TYPE_COMMON = 0, + MT7925_FACT_CAL_TYPE_GROUP = 1, + MT7925_FACT_CAL_TYPE_CHANNEL = 2, + MT7925_FACT_CAL_TYPE_MAPPING_TBL = 4, +}; + +#define MT7925_FACT_CAL_DATA_BUF_LEN 1400 +#define MT7925_FACT_CAL_BUF_CFG_LEN 16 +#define MT7925_FACT_CAL_DATA_BUF_NUM_MAX 4 +#define MT7925_FACT_CAL_BUF_CFG_U32_LEN 4 +#define MT7925_FACT_CAL_DATA_MAX_BUF_LEN \ + (MT7925_FACT_CAL_DATA_BUF_NUM_MAX * MT7925_FACT_CAL_BUF_CFG_U32_LEN) + +#define MT7925_FACT_CAL_COMMON_BAND_NUM 2 +#define MT7925_FACT_CAL_GROUP_NUM 35 +#define MT7925_FACT_CAL_CH_NUM_2G 14 +#define MT7925_FACT_CAL_CH_NUM_5G 68 +#define MT7925_FACT_CAL_CH_NUM_6G 109 +#define MT7925_FACT_CAL_CH_NUM_ALL \ + (MT7925_FACT_CAL_CH_NUM_2G + MT7925_FACT_CAL_CH_NUM_5G + \ + MT7925_FACT_CAL_CH_NUM_6G) + +#define MT7925_FACT_CAL_LEN_COM 600 +#define MT7925_FACT_CAL_LEN_GRP 4500 +#define MT7925_FACT_CAL_LEN_CH 2800 + +struct mt7925_fact_cal_buf_info { + __le32 cal_type; + __le32 cal_param; + __le32 buf_seq_num; + __le32 total_buf_num; + __le32 buf_data_len; + u8 valid; + u8 done; + u8 rsv[2]; + __le32 buf_cfg_info[MT7925_FACT_CAL_DATA_MAX_BUF_LEN]; +} __packed; + +static_assert(sizeof(struct mt7925_fact_cal_buf_info) == 88, + "buf_info must match the MT7928 FW (88 bytes) or it rejects the mapping table"); + +struct mt7925_fact_cal_common_map { + __le32 phy_addr_h; + __le32 phy_addr_l; + __le32 offset; + u8 band[MT7925_FACT_CAL_COMMON_BAND_NUM]; + u8 rsv[2]; +} __packed; + +struct mt7925_fact_cal_group_map { + __le32 phy_addr_h; + __le32 phy_addr_l; + __le32 offset; + u8 group[MT7925_FACT_CAL_GROUP_NUM]; + u8 rsv; +} __packed; + +struct mt7925_fact_cal_channel_map { + __le32 phy_addr_h; + __le32 phy_addr_l; + __le32 offset; + __le32 cal_param[MT7925_FACT_CAL_CH_NUM_ALL]; + u8 total_buf_num[MT7925_FACT_CAL_CH_NUM_ALL]; + u8 rsv; +} __packed; + +struct mt7925_fact_cal_mapping_tbl { + struct mt7925_fact_cal_common_map common; + struct mt7925_fact_cal_group_map group; + struct mt7925_fact_cal_channel_map channel; + __le32 buf_info_size; + __le32 phy_addr_h; + __le32 phy_addr_l; +} __packed; + +static_assert(sizeof(struct mt7925_fact_cal_mapping_tbl) == 1044, + "mapping table must match the MT7928 FW (1044 bytes) or the FW parse corrupts"); + +struct mt7925_cal_cache_layout { + u32 common_off, group_off, channel_off, mapping_off; + u32 common_stride, group_stride, channel_stride; + u32 total; +}; + +struct mt7925_axidma_info_req { + u8 _rsv[4]; + + struct { + __le16 tag; + __le16 len; + __le32 remap_addr; + __le32 reserved; + } __packed remap; + + struct { + __le16 tag; + __le16 len; + __le32 host_addr_offset; + __le32 size; + __le32 bound; + __le32 reserved; + } __packed fact_cal; +} __packed; + +struct mt7925_fact_cal_req { + u8 _rsv[4]; + + struct { + __le16 tag; + __le16 len; + __le32 data; + __le32 seq_num; + __le32 buf_data_len; + u8 cal_type; + u8 done; + u8 rsv[2]; + u8 buf_data[MT7925_FACT_CAL_DATA_BUF_LEN]; + } __packed set; +} __packed; + +int mt7925_axidma_alloc(struct mt792x_dev *dev); + +void mt7925_axidma_free(struct mt792x_dev *dev); + +int mt7925_mcu_send_axidma_info(struct mt792x_dev *dev); + +int mt7925_mcu_send_fact_cal_mapping_tbl(struct mt792x_dev *dev); + +int mt7925_mcu_fact_cal_set_bypass(struct mt792x_dev *dev, bool enable); + +#endif /* __CACHED_CAL_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h index ef72b50e1a7c..636efe038392 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h @@ -359,6 +359,7 @@ int mt7925_mcu_parse_response(struct mt76_dev *mdev, int cmd, int mt7925e_mac_reset(struct mt792x_dev *dev); int mt7925e_mcu_init(struct mt792x_dev *dev); +void mt7925e_axidma_cal_cache_init(struct mt792x_dev *dev); void mt7925_mac_add_txs(struct mt792x_dev *dev, void *data); void mt7928_mac_add_txs_msg(struct mt792x_dev *dev, void *evt); void mt7925_set_runtime_pm(struct mt792x_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c index 12c1f7868d91..0d477dc1086c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c @@ -9,6 +9,7 @@ #include "mac.h" #include "mcu.h" #include "regd.h" +#include "cached_cal.h" #include "../dma.h" static const struct pci_device_id mt7925_pci_device_table[] = { @@ -38,6 +39,62 @@ static int mt7925e_init_reset(struct mt792x_dev *dev) return mt792x_wpdma_reset(dev, true); } +/* Set up the factory-calibration cache in host memory. PCIe only: the FW + * reaches the buffer through AXI DMA, so it has no meaning on other buses. + * Every failure just leaves the cache off, which is not fatal. + */ +void mt7925e_axidma_cal_cache_init(struct mt792x_dev *dev) +{ + if (!(dev->phy.chip_cap & MT792x_CHIP_CAP_AXIDMA_EN)) + return; + + if (dev->cached_cal.va) { + /* Carried-over buffer still holds FW-written cal data. */ + dev->cached_cal.reused = true; + } else { + if (mt7925_axidma_alloc(dev)) { + dev_warn(dev->mt76.dev, + "AXI DMA cal cache disabled: buffer alloc failed\n"); + return; + } + /* Freshly allocated buffer is zeroed: no cal data yet. */ + dev->cached_cal.reused = false; + } + + if (mt7925_mcu_send_axidma_info(dev)) { + dev_warn(dev->mt76.dev, + "AXI DMA cal cache disabled: info cmd to FW failed\n"); + return; + } + + /* Enable the bypass-cal flow so the FW reuses cached cal data + * (common / power-on group) instead of running a full calibration; + * must be set before the mapping table is sent. + */ + if (mt7925_mcu_fact_cal_set_bypass(dev, true)) { + dev_warn(dev->mt76.dev, + "AXI DMA cal cache disabled: bypass flag set failed\n"); + return; + } + + if (mt7925_mcu_send_fact_cal_mapping_tbl(dev)) { + dev_warn(dev->mt76.dev, + "AXI DMA cal cache disabled: mapping tbl send failed\n"); + return; + } + + if (mt7925_mcu_fact_cal_set_bypass(dev, false)) { + dev_warn(dev->mt76.dev, + "AXI DMA cal cache disabled: bypass flag set failed\n"); + return; + } + + dev_info(dev->mt76.dev, + "AXI DMA cal cache enabled (DMA=%pad, size=%u, reused=%d)\n", + &dev->cached_cal.dma_addr, dev->cached_cal.size, + dev->cached_cal.reused); +} + static void mt7925e_unregister_device(struct mt792x_dev *dev) { int i; @@ -62,6 +119,7 @@ static void mt7925e_unregister_device(struct mt792x_dev *dev) __mt792x_mcu_drv_pmctrl(dev); mt792x_dma_cleanup(dev); mt792x_wfsys_reset(dev); + mt7925_axidma_free(dev); skb_queue_purge(&dev->mt76.mcu.res_q); tasklet_disable(&dev->mt76.irq_tasklet); @@ -588,7 +646,7 @@ static int mt7925_pci_probe(struct pci_dev *pdev, is_mt7928_hw = (pdev->device == 0x7928 || pdev->device == 0x7935); if (is_mt7928_hw) - ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(34)); + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(34)); else ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c index 67eb86746779..18f125bf3df4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c @@ -137,6 +137,8 @@ int mt7925e_mac_reset(struct mt792x_dev *dev) if (err) goto out; + mt7925e_axidma_cal_cache_init(dev); + err = mt7925_mcu_set_eeprom(dev); if (err) goto out; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mcu.c index 72707eddc3db..258f3753db1f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mcu.c @@ -46,6 +46,8 @@ int mt7925e_mcu_init(struct mt792x_dev *dev) mt76_rmw_field(dev, dev->pcie_reg->pm, MT_PCIE_MAC_PM_L0S_DIS, 1); err = mt7925_run_firmware(dev); + if (!err) + mt7925e_axidma_cal_cache_init(dev); mt76_queue_tx_cleanup(dev, dev->mt76.q_mcu[MT_MCUQ_FWDL], false); diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 7b838a8655be..a7d71e007da0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -33,6 +33,7 @@ #define MT792x_CHIP_CAP_REGD_EN BIT(5) #define MT792x_CHIP_CAP_MLO_EN BIT(8) #define MT792x_CHIP_CAP_MLO_EML_EN BIT(9) +#define MT792x_CHIP_CAP_AXIDMA_EN BIT(16) /* NOTE: used to map mt76_rates. idx may change if firmware expands table */ #define MT792x_BASIC_RATES_TBL 14 @@ -352,6 +353,13 @@ struct mt792x_dev { spinlock_t nan_deferred_lock; unsigned long nan_deferred_pending; u8 nan_started_cluster_id[ETH_ALEN]; + + struct { + void *va; + dma_addr_t dma_addr; + u32 size; + bool reused; + } cached_cal; }; static inline struct mt792x_bss_conf * From c7a6b6a1dcc8fc0ac49ec0d7418b4603684e7d73 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:10 +0200 Subject: [PATCH 1298/2126] wifi: mt76: abort a scan only for a link change on the scanning radio mt76_assign_vif_chanctx() and mt76_unassign_vif_chanctx() abort the scan whenever the scanning vif gains or loses a link, on any radio. An AP MLD that scans on one radio for ACS while its link on another radio comes up therefore loses the whole scan, and hostapd gets an aborted scan. mac80211 does not continue an aborted scan with the next band. The scan uses the link of the vif that mt76_get_vif_phy_link() returns for the scanning radio, so it needs to stop only for a channel context on that radio: the new link would duplicate the offchannel link, or the removed link is the one the scan uses. Abort only in that case, as mt76_add_chanctx() does. Fixes: e411b8190fe7 ("wifi: mt76: add multi-radio support to scanning code") Link: https://patch.msgid.link/20261006205936.669125-1-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 903f3a420e4c..8d4daa76be54 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -114,7 +114,7 @@ int mt76_assign_vif_chanctx(struct ieee80211_hw *hw, bool mlink_alloc = false; int ret = 0; - if (dev->scan.vif == vif) + if (dev->scan.vif == vif && dev->scan.phy == phy) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -161,7 +161,7 @@ void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw, struct mt76_phy *phy = ctx->phy; struct mt76_dev *dev = phy->dev; - if (dev->scan.vif == vif) + if (dev->scan.vif == vif && dev->scan.phy == phy) mt76_abort_scan(dev); mutex_lock(&dev->mutex); From 267424ac63aa65fb28b7f3cff1e1a7d0098c4d6f Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:11 +0200 Subject: [PATCH 1299/2126] wifi: mt76: mt7996: enable the SKU power limit table mt7996_mcu_set_txpower_sku() uploads the per-rate power limit table, but the firmware applies it only after the driver enables the SKU power limit. mt7915 does that in mt7915_mcu_set_sku_en(); mt7996 never does, so the radio keeps the EEPROM target power and the configured tx power has no effect. Add the power control command and enable the table per band in mt7996_run(), as the MediaTek vendor driver does. The backoff table stays disabled. This driver does not build the per-path limits; it pads that part of the message with zeros. Fixes: f75e4779d215 ("wifi: mt76: mt7996: add txpower setting support") Link: https://patch.msgid.link/20261006205936.669125-2-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 5 +++ .../net/wireless/mediatek/mt76/mt7996/mcu.c | 34 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.h | 23 +++++++++++++ .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 4 files changed, 63 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index d17d1dbb2038..c04e980f6ee7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -34,6 +34,11 @@ int mt7996_run(struct mt7996_phy *phy) if (ret) return ret; + ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, + true); + if (ret) + return ret; + set_bit(MT76_STATE_RUNNING, &phy->mt76->state); ieee80211_queue_delayed_work(dev->mphy.hw, &phy->mt76->mac_work, diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c index a534d07ea1e8..310ce18ec12c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c @@ -5488,6 +5488,40 @@ int mt7996_mcu_set_sniffer_mode(struct mt7996_phy *phy, bool enabled) sizeof(req), true); } +int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 data) +{ + struct mt7996_dev *dev = phy->dev; + struct tx_power_ctrl req = { + .tag = cpu_to_le16(power_ctrl_id), + .len = cpu_to_le16(sizeof(req) - 4), + .power_ctrl_id = power_ctrl_id, + .band_idx = phy->mt76->band_idx, + }; + + switch (power_ctrl_id) { + case UNI_TXPOWER_SKU_POWER_LIMIT_CTRL: + req.sku_enable = !!data; + break; + case UNI_TXPOWER_PERCENTAGE_CTRL: + req.percentage_ctrl_enable = !!data; + break; + case UNI_TXPOWER_PERCENTAGE_DROP_CTRL: + req.power_drop_level = data; + break; + case UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL: + req.bf_backoff_enable = !!data; + break; + case UNI_TXPOWER_ATE_MODE_CTRL: + req.ate_mode_enable = !!data; + break; + default: + return -EINVAL; + } + + return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(TXPOWER), + &req, sizeof(req), false); +} + int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy) { #define TX_POWER_LIMIT_TABLE_RATE 0 diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h index 74b70fb6da3d..87573688171b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h @@ -1036,8 +1036,31 @@ enum { UNI_CMD_THERMAL_PROTECT_DUTY_CONFIG, }; +struct tx_power_ctrl { + u8 _rsv[4]; + + __le16 tag; + __le16 len; + + u8 power_ctrl_id; + union { + bool sku_enable; + bool ate_mode_enable; + bool percentage_ctrl_enable; + bool bf_backoff_enable; + u8 power_drop_level; + }; + u8 band_idx; + u8 rsv[1]; +} __packed; + enum { + UNI_TXPOWER_SKU_POWER_LIMIT_CTRL = 0, + UNI_TXPOWER_PERCENTAGE_CTRL = 1, + UNI_TXPOWER_PERCENTAGE_DROP_CTRL = 2, + UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL = 3, UNI_TXPOWER_POWER_LIMIT_TABLE_CTRL = 4, + UNI_TXPOWER_ATE_MODE_CTRL = 6, }; enum { diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index 2a0cdb56f822..dcfdcd5975c3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -778,6 +778,7 @@ int mt7996_mcu_get_temperature(struct mt7996_phy *phy); int mt7996_mcu_set_thermal_throttling(struct mt7996_phy *phy, u8 state); int mt7996_mcu_set_thermal_protect(struct mt7996_phy *phy, bool enable); int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy); +int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 data); int mt7996_mcu_rdd_resume_tx(struct mt7996_phy *phy); int mt7996_mcu_rdd_cmd(struct mt7996_dev *dev, int cmd, u8 rdd_idx, u8 val); int mt7996_mcu_rdd_background_enable(struct mt7996_phy *phy, From 78072c1a661d643f341536219c19c28ba0a0fed3 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:12 +0200 Subject: [PATCH 1300/2126] wifi: mt76: mt7996: set sniffer mode on a radio that is already running mt7996_add_interface() skips a radio that has MT76_STATE_RUNNING set, and the skip covers both the start of the radio and the call to mt7996_set_monitor(). mt7996_init_wiphy_band() sets MT_WF_RFCR_DROP_OTHER_UC in phy->rxfilter on every band, and mt7996_configure_filter() does not clear it, so only mt7996_set_monitor() does. A monitor interface that is added while an AP runs on the same radio thus receives no unicast frame addressed to another device. Start only an idle radio, but put every radio of a monitor interface into sniffer mode. mt7996_remove_interface() already clears sniffer mode whether the radio runs or not. Fixes: 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy") Link: https://patch.msgid.link/20261006205936.669125-3-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index c04e980f6ee7..d013a472c28d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -570,13 +570,14 @@ static int mt7996_add_interface(struct ieee80211_hw *hw, for (i = 0; i < MT7996_MAX_RADIOS; i++) { struct mt7996_phy *phy = dev->radio_phy[i]; - if (!phy || !(wdev->radio_mask & BIT(i)) || - test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) + if (!phy || !(wdev->radio_mask & BIT(i))) continue; - err = mt7996_run(phy); - if (err) - goto out; + if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) { + err = mt7996_run(phy); + if (err) + goto out; + } if (vif->type == NL80211_IFTYPE_MONITOR) mt7996_set_monitor(phy, true); From cebf7dbfa14a39bdf3913f3fa7452d096c90c15b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:13 +0200 Subject: [PATCH 1301/2126] wifi: mt76: mt7996: update the address of an AP link that is added again mt7996_vif_link_remove() only stops an AP link and keeps its BSS, so a link that is added again takes the early branch of mt7996_vif_link_add(). For other interface types that branch sends DEV_INFO with the new link address. For an AP it only restarts the link, and the firmware keeps the own MAC address the link had when it was first created. The hardware takes A2 of an encapsulation offload frame from that address. A reload that gives an AP MLD link a new address therefore makes every data frame on that link carry the old address as TA. The receiver acknowledges the frame by its RA but cannot find a key for the TA and drops it, so the AP counts no failure. The BSS_INFO update on BSS_CHANGED_BEACON_ENABLED restores the BSSID, but nothing sends DEV_INFO again. Send DEV_INFO for an AP link as well, before the link is restarted. Fixes: 08813703ac41 ("wifi: mt76: mt7996: Destroy vif active links in mt7996_remove_interface()") Link: https://patch.msgid.link/20261006205936.669125-4-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index d013a472c28d..621e1337dec2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -312,15 +312,15 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, if ((mvif->mt76.valid_links & BIT(link_conf->link_id)) && !mlink->offchannel) { - if (vif->type == NL80211_IFTYPE_AP) - return mt7996_mcu_mld_link_oper(dev, link_conf, link, - true); - /* update the link address */ ret = mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, true); if (ret) return ret; + if (vif->type == NL80211_IFTYPE_AP) + return mt7996_mcu_mld_link_oper(dev, link_conf, link, + true); + return mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, msta_link, true); } From 24cc6d911e1d2f6ada086402f07b30b42fe6b545 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:14 +0200 Subject: [PATCH 1302/2126] wifi: mt76: mt7996: size the MLD setup TLV by the links it describes mt7996_mcu_sta_mld_setup_tlv() sets link_num and the TLV length from hweight16(sta->valid_links), but fills an entry only for active links that have driver state. On a station interface mac80211 activates only the association link at first, and drv_change_sta_links() masks the other links with vif->active_links, so the driver has no state for them. A station with valid_links 0x3 and active_links 0x2 thus sends STA_REC_MLD with link_num 2 and a second entry of zeroes, at association and again at authorization. The zeroed entry names WTBL index 0 and BSS index 0 as a link of the MLD. Count the links with driver state first and describe exactly those, with the secondary id taken from them. A link removed without flush keeps its mt7996_sta_link but is no longer valid, so leave it out as well. Fixes: 00cef41d9d8f ("wifi: mt76: mt7996: Add mt7996_mcu_sta_mld_setup_tlv() and mt7996_mcu_sta_eht_mld_tlv()") Link: https://patch.msgid.link/20261006205936.669125-5-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 30 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.c | 26 +++++++--------- .../wireless/mediatek/mt76/mt7996/mt7996.h | 2 ++ 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 621e1337dec2..0c229a8f071f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1262,6 +1262,36 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev, } } +u16 mt7996_mac_sta_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + struct ieee80211_link_sta *link_sta; + unsigned int link_id; + u16 links = 0; + + for_each_sta_active_link(vif, sta, link_sta, link_id) { + struct mt7996_sta_link *msta_link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + if (!msta_link) + continue; + + if (sta->valid_links && !msta_link->wcid.link_valid) + continue; + + if (!link_conf_dereference_protected(vif, link_id)) + continue; + + if (!mt7996_vif_link(dev, vif, link_id)) + continue; + + links |= BIT(link_id); + } + + return links; +} + static void mt7996_mac_sta_remove_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta, unsigned long links, diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c index 310ce18ec12c..02f9bcfdf5d9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c @@ -2759,18 +2759,20 @@ mt7996_mcu_sta_mld_setup_tlv(struct mt7996_dev *dev, struct sk_buff *skb, struct ieee80211_sta *sta) { struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - unsigned int nlinks = hweight16(sta->valid_links); + unsigned long links = mt7996_mac_sta_links(dev, vif, sta); + unsigned int nlinks = hweight16(links); struct mld_setup_link *mld_setup_link; - struct ieee80211_link_sta *link_sta; struct sta_rec_mld_setup *mld_setup; struct mt7996_sta_link *msta_link; + u8 seclink_id = msta->deflink_id; unsigned int link_id; struct tlv *tlv; - msta_link = mt7996_sta_link_protected(dev, msta, msta->deflink_id); - if (!msta_link) + if (!(links & BIT(msta->deflink_id))) return; + msta_link = mt7996_sta_link_protected(dev, msta, msta->deflink_id); + tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_MLD, sizeof(struct sta_rec_mld_setup) + sizeof(struct mld_setup_link) * nlinks); @@ -2780,26 +2782,18 @@ mt7996_mcu_sta_mld_setup_tlv(struct mt7996_dev *dev, struct sk_buff *skb, mld_setup->setup_wcid = cpu_to_le16(msta_link->wcid.idx); mld_setup->primary_id = cpu_to_le16(msta_link->wcid.idx); - if (nlinks > 1) { - msta_link = mt7996_sta_link_protected(dev, msta, - msta->seclink_id); - if (!msta_link) - return; - } + if (links & BIT(msta->seclink_id)) + seclink_id = msta->seclink_id; + msta_link = mt7996_sta_link_protected(dev, msta, seclink_id); mld_setup->seconed_id = cpu_to_le16(msta_link->wcid.idx); mld_setup->link_num = nlinks; mld_setup_link = (struct mld_setup_link *)mld_setup->link_info; - for_each_sta_active_link(vif, sta, link_sta, link_id) { + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { struct mt7996_vif_link *link; msta_link = mt7996_sta_link_protected(dev, msta, link_id); - if (!msta_link) - continue; - link = mt7996_vif_link(dev, vif, link_id); - if (!link) - continue; mld_setup_link->wcid = cpu_to_le16(msta_link->wcid.idx); mld_setup_link->bss_idx = link->mt76.idx; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index dcfdcd5975c3..82a2a8a5db69 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -894,6 +894,8 @@ void mt7996_mac_twt_teardown_flow(struct mt7996_dev *dev, void mt7996_mac_sta_remove_link(struct mt7996_dev *dev, struct ieee80211_sta *sta, unsigned int link_id, bool flush); +u16 mt7996_mac_sta_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta); void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, struct ieee80211_sta *sta, struct ieee80211_twt_setup *twt); From 90abe74d274fad080dffaf3c671e5f31cee53a5b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:15 +0200 Subject: [PATCH 1303/2126] wifi: mt76: mt7996: find the last MLD link among the links torn down On disassociation, mt7996_mac_sta_event() sends STA_REC_MLD_OFF when the link it handles is the last of sta->valid_links, but it handles only active links with driver state. On a station interface with one active link out of two valid links, no link is ever the last one, so the firmware never gets STA_REC_MLD_OFF for the MLD. Walk the same set of links that mt7996_mcu_sta_mld_setup_tlv() describes, and detect the last link within that set. The per-link event handling moves into a helper that takes the set of links, so that a later change can bring up links that became active after association. Fixes: c1d6dd5d03eb ("wifi: mt76: mt7996: Add mt7996_mcu_teardown_mld_sta rouine") Link: https://patch.msgid.link/20261006205936.669125-6-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 0c229a8f071f..e5f74f23d469 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1406,34 +1406,26 @@ mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, } static int -mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, - struct ieee80211_sta *sta, enum mt76_sta_event ev) +mt7996_mac_sta_links_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, unsigned long links, + enum mt76_sta_event ev) { struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - unsigned long links = sta->valid_links; - struct ieee80211_link_sta *link_sta; + unsigned long iter_links = links; unsigned int link_id; - int err = 0; + int err; - mutex_lock(&dev->mt76.mutex); - - for_each_sta_active_link(vif, sta, link_sta, link_id) { + for_each_set_bit(link_id, &iter_links, IEEE80211_MLD_MAX_NUM_LINKS) { struct ieee80211_bss_conf *link_conf; + struct ieee80211_link_sta *link_sta; struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; int i; link_conf = link_conf_dereference_protected(vif, link_id); - if (!link_conf) - continue; - - link = mt7996_vif_link(dev, vif, link_id); - if (!link) - continue; - + link_sta = link_sta_dereference_protected(sta, link_id); msta_link = mt7996_sta_link_protected(dev, msta, link_id); - if (!msta_link) - continue; + link = mt7996_vif_link(dev, vif, link_id); switch (ev) { case MT76_STA_EVENT_ASSOC: @@ -1441,12 +1433,12 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, link, msta_link, CONN_STATE_CONNECT, true); if (err) - goto unlock; + return err; err = mt7996_mcu_add_rate_ctrl(dev, msta_link->sta, vif, link_id, false); if (err) - goto unlock; + return err; msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET; break; @@ -1455,7 +1447,7 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, link, msta_link, CONN_STATE_PORT_SECURE, false); if (err) - goto unlock; + return err; break; case MT76_STA_EVENT_DISASSOC: for (i = 0; i < ARRAY_SIZE(msta_link->twt.flow); i++) @@ -1475,7 +1467,20 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, break; } } -unlock: + + return 0; +} + +static int +mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, enum mt76_sta_event ev) +{ + int err; + + mutex_lock(&dev->mt76.mutex); + err = mt7996_mac_sta_links_event(dev, vif, sta, + mt7996_mac_sta_links(dev, vif, sta), + ev); mutex_unlock(&dev->mt76.mutex); return err; From 2ec14ab42dfd195976bd834fecbcea00ae7da600 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:16 +0200 Subject: [PATCH 1304/2126] wifi: mt76: mt7996: upload only the keys of the link being set up mt7996_vif_link_add() and mt7996_vif_link_destroy() walk the vif keys through mt7996_key_iter(), which passes every group key to mt7996_set_hw_key() for the link being set up. On an MLD interface each group key belongs to one link, as key->link_id says, so a new link gets the GTK and BIGTK of the other links written to its group WTBL entry, and its hw_key_idx set to their key index. Skip keys that belong to a different link, as mt7996_set_key() already does for keys that mac80211 installs. Fixes: eddc7286f6bb ("wifi: mt76: mt7996: fix key add/remove imbalance") Link: https://patch.msgid.link/20261006205936.669125-7-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index e5f74f23d469..e74254928578 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -291,6 +291,9 @@ mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif, if (sta) return; + if (key->link_id >= 0 && key->link_id != it->link_id) + return; + WARN_ON(mt7996_set_hw_key(hw, it->cmd, vif, NULL, it->link_id, key)); } From b31a3c76156101c96c08306b362ccb0705abbdd0 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:17 +0200 Subject: [PATCH 1305/2126] wifi: mt76: mt7996: do not walk the vif keys when a link is destroyed Since commit eddc7286f6bb ("wifi: mt76: mt7996: fix key add/remove imbalance"), mt7996_vif_link_destroy() walks the vif keys with SET_KEY. Before that commit the walk used DISABLE_KEY. The commit message says a key for a link is added and removed only once, but a SET_KEY walk on destroy uploads the keys again, and for a BIGTK with beaconing enabled it also removes and adds the beacon of the link being destroyed. Remove the walk. mac80211 removes the keys itself with set_key() calls, which is the one removal that commit describes. The walk currently finds no keys: mt7996_vif_link_destroy() runs for a non-offchannel link only from mt7996_remove_interface(), and ieee80211_do_stop() frees the keys of the interface before drv_remove_interface(). An interface type change goes through the same path, since mt7996 has no .change_interface. Found by inspection. Link: https://patch.msgid.link/20261006205936.669125-8-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index e74254928578..f94b5fdfca24 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -425,19 +425,12 @@ static void mt7996_vif_link_destroy(struct mt7996_phy *phy, struct mt7996_sta_link *msta_link = &link->msta_link; unsigned int link_id = msta_link->wcid.link_id; struct mt76_vif_link *mlink = &link->mt76; - struct mt7996_key_iter_data it = { - .cmd = SET_KEY, - .link_id = link_id, - }; struct mt7996_dev *dev = phy->dev; int idx = msta_link->wcid.idx; if (!link_conf) link_conf = &vif->bss_conf; - if (!mlink->wcid->offchannel) - ieee80211_iter_keys(phy->mt76->hw, vif, mt7996_key_iter, &it); - mt7996_mcu_add_sta(dev, link_conf, NULL, link, NULL, CONN_STATE_DISCONNECT, false); mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, msta_link, false); From a9792846fbc62af2290552ab66b5a855415acaa8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:18 +0200 Subject: [PATCH 1306/2126] wifi: mt76: mt7996: report station statistics from the primary link mt7996_sta_statistics() and mt7996_ethtool_worker() read the TX rate, the TX counters and the ACK signal from msta->deflink. That is the msta_link of the first link of the station, not of its primary link. When the first link of an MLD station is removed, msta->deflink keeps the values of the removed link, and the station reports them until it is removed. Read them from the link that deflink_id selects. msta->deflink also holds the RX reorder state, the TX aggregation state and the def_wcid target of all links. These are state of the whole station, and wcid_to_sta() needs def_wcid at the start of drv_priv, so they stay there. Fixes: f520eceacd24 ("wifi: mt76: mt7996: Add mt7996_mac_sta_change_links callback") Link: https://patch.msgid.link/20261006205936.669125-9-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index f94b5fdfca24..f44af31281b7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1920,9 +1920,16 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw, { struct mt7996_dev *dev = mt7996_hw_dev(hw); struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - struct mt7996_sta_link *msta_link = &msta->deflink; - struct rate_info *txrate = &msta_link->wcid.rate; + struct mt7996_sta_link *msta_link; + struct rate_info *txrate; + rcu_read_lock(); + + msta_link = mt7996_sta_link(msta, msta->deflink_id); + if (!msta_link) + goto out; + + txrate = &msta_link->wcid.rate; if (txrate->legacy || txrate->flags) { if (txrate->legacy) { sinfo->txrate.legacy = txrate->legacy; @@ -1965,6 +1972,9 @@ static void mt7996_sta_statistics(struct ieee80211_hw *hw, sinfo->rx_packets = msta_link->wcid.stats.rx_packets; sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS); } + +out: + rcu_read_unlock(); } static void mt7996_link_rate_ctrl_update(void *data, @@ -2264,11 +2274,15 @@ static void mt7996_ethtool_worker(void *wi_data, struct ieee80211_sta *sta) { struct mt76_ethtool_worker_info *wi = wi_data; struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - struct mt7996_sta_link *msta_link = &msta->deflink; + struct mt7996_sta_link *msta_link; if (msta->vif->deflink.mt76.idx != wi->idx) return; + msta_link = mt7996_sta_link(msta, msta->deflink_id); + if (!msta_link) + return; + mt76_ethtool_worker(wi, &msta_link->wcid.stats, true); } From a53699a3d482a980efb016469b99ffac172280af Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:19 +0200 Subject: [PATCH 1307/2126] wifi: mt76: mt7996: clear all link wcid entries in sta_pre_rcu_remove mt76_sta_pre_rcu_remove() clears the wcid table entry of msta->deflink only. mac80211 calls it before the synchronize_net() that ends the RCU readers of the station, and frees the station right after mt7996_mac_sta_remove(). For an MLD station, the wcid table entries of the other links stay set until mt7996_mac_sta_remove(), after that grace period. An RX or TX status reader that looks up one of these entries in that window can follow msta_link->sta or def_wcid into the freed station. Clear the wcid table entries of all links of the station in .sta_pre_rcu_remove. Fixes: dd82a9e02c05 ("wifi: mt76: mt7996: Rely on mt7996_sta_link in sta_add/sta_remove callbacks") Link: https://patch.msgid.link/20261006205936.669125-10-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index f44af31281b7..3c27cc02d527 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1513,6 +1513,30 @@ mt7996_set_active_links(struct ieee80211_vif *vif) ieee80211_set_active_links_async(vif, active_links); } +static void +mt7996_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + struct ieee80211_sta *sta) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + struct mt7996_dev *dev = mt7996_hw_dev(hw); + unsigned int link_id; + + mutex_lock(&dev->mt76.mutex); + spin_lock_bh(&dev->mt76.status_lock); + + for (link_id = 0; link_id < ARRAY_SIZE(msta->link); link_id++) { + struct mt7996_sta_link *msta_link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + if (msta_link) + rcu_assign_pointer(dev->mt76.wcid[msta_link->wcid.idx], + NULL); + } + + spin_unlock_bh(&dev->mt76.status_lock); + mutex_unlock(&dev->mt76.mutex); +} + static int mt7996_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta, enum ieee80211_sta_state old_state, @@ -2618,7 +2642,7 @@ const struct ieee80211_ops mt7996_ops = { .vif_cfg_changed = mt7996_vif_cfg_changed, .link_info_changed = mt7996_link_info_changed, .sta_state = mt7996_sta_state, - .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove, + .sta_pre_rcu_remove = mt7996_sta_pre_rcu_remove, .link_sta_rc_update = mt7996_link_sta_rc_update, .set_key = mt7996_set_key, .ampdu_action = mt7996_ampdu_action, From 36f1934a2bf04f355e748c68ba7f7cbb5e6950fc Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:20 +0200 Subject: [PATCH 1308/2126] wifi: mt76: mt7996: free the WTBL index if a link allocation fails mt7996_mac_sta_init_link() takes a WTBL index from wcid_mask before it allocates the msta_link of a link other than the first one. If that allocation fails, the function returns -ENOMEM and the index stays set in wcid_mask, so no later station can use it. Return the index to wcid_mask on that error. Fixes: dd82a9e02c05 ("wifi: mt76: mt7996: Rely on mt7996_sta_link in sta_add/sta_remove callbacks") Link: https://patch.msgid.link/20261006205936.669125-11-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 3c27cc02d527..5207def2fd36 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1159,8 +1159,10 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, mt7996_sta_init_txq_wcid(sta, idx); } else { msta_link = kzalloc_obj(*msta_link); - if (!msta_link) + if (!msta_link) { + mt76_wcid_mask_clear(dev->mt76.wcid_mask, idx); return -ENOMEM; + } if (msta->seclink_id == msta->deflink_id && (sta->valid_links & ~BIT(msta->deflink_id))) From 53eadd11e92729976168d74f27345461a5e1ef46 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:21 +0200 Subject: [PATCH 1309/2126] wifi: mt76: mt7996: pick the secondary link from links with driver state mt7996_mac_sta_init_link() takes the secondary link from sta->valid_links. On a station interface mac80211 creates driver state only for active links, since drv_change_sta_links() masks both link sets with vif->active_links. With three valid links of which links 0 and 2 are active, seclink_id then points at link 1, which has no mt7996_sta_link. mt7996_tx_prepare_skb() maps odd TIDs to seclink_id, keeps the primary wcid for them and passes the inactive link id to mt7996_mac_write_txwi(), which finds no vif link and falls back to OMAC and WMM index 0. Choose the secondary link among the links that have driver state and are valid, and choose it again whenever such a link is added, restored or removed. A removed secondary link now hands over to another remaining link instead of the primary one, and a secondary link that was promoted to primary gets a successor. Fixes: 85cd5534a3f2 ("wifi: mt76: mt7996: use correct link_id when filling TXD and TXP") Link: https://patch.msgid.link/20261006205936.669125-12-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 5207def2fd36..9de455939125 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1133,6 +1133,32 @@ mt7996_sta_init_txq_wcid(struct ieee80211_sta *sta, int idx) } } +static u8 +mt7996_sta_seclink_get(struct mt7996_dev *dev, struct mt7996_sta *msta) +{ + struct mt7996_sta_link *msta_link; + unsigned int link_id; + + if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) + return IEEE80211_LINK_UNSPECIFIED; + + msta_link = mt7996_sta_link_protected(dev, msta, msta->seclink_id); + if (msta->seclink_id != msta->deflink_id && msta_link && + msta_link->wcid.link_valid) + return msta->seclink_id; + + for (link_id = 0; link_id < ARRAY_SIZE(msta->link); link_id++) { + if (link_id == msta->deflink_id) + continue; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + if (msta_link && msta_link->wcid.link_valid) + return link_id; + } + + return msta->deflink_id; +} + static int mt7996_mac_sta_init_link(struct mt7996_dev *dev, struct ieee80211_bss_conf *link_conf, @@ -1155,7 +1181,6 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) { msta_link = &msta->deflink; msta->deflink_id = link_id; - msta->seclink_id = msta->deflink_id; mt7996_sta_init_txq_wcid(sta, idx); } else { msta_link = kzalloc_obj(*msta_link); @@ -1163,11 +1188,6 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, mt76_wcid_mask_clear(dev->mt76.wcid_mask, idx); return -ENOMEM; } - - if (msta->seclink_id == msta->deflink_id && - (sta->valid_links & ~BIT(msta->deflink_id))) - msta->seclink_id = __ffs(sta->valid_links & - ~BIT(msta->deflink_id)); } INIT_LIST_HEAD(&msta_link->rc_list); @@ -1186,6 +1206,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, ewma_signal_init(&msta_link->wcid.rssi); rcu_assign_pointer(msta->link[link_id], msta_link); + msta->seclink_id = mt7996_sta_seclink_get(dev, msta); mt7996_mac_wtbl_update(dev, idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR); mt7996_mcu_add_sta(dev, link_conf, link_sta, link, msta_link, @@ -1223,10 +1244,7 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev, if (msta->deflink_id == link_id) { msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; - if (msta->seclink_id == link_id) { - /* no secondary link available */ - msta->seclink_id = msta->deflink_id; - } else { + if (msta->seclink_id != link_id) { struct mt7996_sta_link *msta_seclink; /* switch to the secondary link */ @@ -1239,10 +1257,9 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev, msta_seclink->wcid.idx); } } - } else if (msta->seclink_id == link_id) { - msta->seclink_id = msta->deflink_id; } msta_link->wcid.link_valid = false; + msta->seclink_id = mt7996_sta_seclink_get(dev, msta); } if (flush) { @@ -1319,6 +1336,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, msta_link = mt76_dereference(msta->link[link_id], &dev->mt76); if (msta_link) { msta_link->wcid.link_valid = true; + msta->seclink_id = mt7996_sta_seclink_get(dev, msta); continue; } From db6282754bcfa8b6ba9c4e1c02dff076247a96b9 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:22 +0200 Subject: [PATCH 1310/2126] wifi: mt76: mt7996: make a returning link primary if a station has none mt7996_mac_sta_remove_link() clears deflink_id when it removes the primary link and no secondary link is left to take its place. If the removed link then comes back, mt7996_mac_sta_add_links() finds its existing msta_link and only marks it valid again. deflink_id stays IEEE80211_LINK_UNSPECIFIED, so the station has no primary link: the TXQs keep the WLAN index that they had before, seclink_id stays unspecified, mt7996_sta_rate_ctrl_update() finds no primary link, and mt7996_sta_set_4addr() treats every link as a secondary link. Make a returning link the primary link when the station has none, in the same way as mt7996_mac_sta_init_link() does for a new link. Move the two steps that set the primary link, and the switch to the secondary link on removal, to helpers. Fixes: e8c819df0243 ("wifi: mt76: mt7996: Destroy active sta links in mt7996_mac_sta_remove()") Link: https://patch.msgid.link/20261006205936.669125-13-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 9de455939125..8f483b1de852 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1133,6 +1133,38 @@ mt7996_sta_init_txq_wcid(struct ieee80211_sta *sta, int idx) } } +static void +mt7996_sta_deflink_set(struct ieee80211_sta *sta, unsigned int link_id, + int idx) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + + msta->deflink_id = link_id; + mt7996_sta_init_txq_wcid(sta, idx); +} + +static void +mt7996_sta_deflink_release(struct mt7996_dev *dev, struct ieee80211_sta *sta, + unsigned int link_id) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + struct mt7996_sta_link *msta_seclink; + + if (msta->deflink_id != link_id) + return; + + msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; + if (msta->seclink_id == link_id) + return; + + /* switch to the secondary link */ + msta_seclink = mt76_dereference(msta->link[msta->seclink_id], + &dev->mt76); + if (msta_seclink) + mt7996_sta_deflink_set(sta, msta->seclink_id, + msta_seclink->wcid.idx); +} + static u8 mt7996_sta_seclink_get(struct mt7996_dev *dev, struct mt7996_sta *msta) { @@ -1180,8 +1212,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) { msta_link = &msta->deflink; - msta->deflink_id = link_id; - mt7996_sta_init_txq_wcid(sta, idx); + mt7996_sta_deflink_set(sta, link_id, idx); } else { msta_link = kzalloc_obj(*msta_link); if (!msta_link) { @@ -1242,22 +1273,7 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev, mt7996_mac_wtbl_update(dev, msta_link->wcid.idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR); - if (msta->deflink_id == link_id) { - msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; - if (msta->seclink_id != link_id) { - struct mt7996_sta_link *msta_seclink; - - /* switch to the secondary link */ - msta_seclink = mt76_dereference( - msta->link[msta->seclink_id], - &dev->mt76); - if (msta_seclink) { - msta->deflink_id = msta->seclink_id; - mt7996_sta_init_txq_wcid(sta, - msta_seclink->wcid.idx); - } - } - } + mt7996_sta_deflink_release(dev, sta, link_id); msta_link->wcid.link_valid = false; msta->seclink_id = mt7996_sta_seclink_get(dev, msta); } @@ -1336,6 +1352,9 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, msta_link = mt76_dereference(msta->link[link_id], &dev->mt76); if (msta_link) { msta_link->wcid.link_valid = true; + if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) + mt7996_sta_deflink_set(sta, link_id, + msta_link->wcid.idx); msta->seclink_id = mt7996_sta_seclink_get(dev, msta); continue; } From 51773d5196a0b85884ad245aa788370c4c8ac58d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:23 +0200 Subject: [PATCH 1311/2126] wifi: mt76: mt7996: do not reuse the deflink of a removed station link mt7996_mac_sta_init_link() puts a new link in msta->deflink whenever the station has no primary link. A removed link keeps its msta_link until the station is removed, and the station has no primary link after one mt7996_mac_sta_change_links() call removes all of its links and adds others. If the removed primary link was in msta->deflink, the new link then overwrites it: both link slots point to the same msta_link, and the WTBL index of the removed link is lost, so mt7996_mac_sta_remove() never returns it to wcid_mask. Use msta->deflink only if no link slot of the station points to it, and allocate the msta_link otherwise. Choose the primary link as before. Fixes: e8c819df0243 ("wifi: mt76: mt7996: Destroy active sta links in mt7996_mac_sta_remove()") Link: https://patch.msgid.link/20261006205936.669125-14-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 8f483b1de852..8e70a4061ed6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1143,6 +1143,20 @@ mt7996_sta_deflink_set(struct ieee80211_sta *sta, unsigned int link_id, mt7996_sta_init_txq_wcid(sta, idx); } +static bool +mt7996_sta_deflink_busy(struct mt7996_dev *dev, struct mt7996_sta *msta) +{ + unsigned int link_id; + + for (link_id = 0; link_id < ARRAY_SIZE(msta->link); link_id++) { + if (mt7996_sta_link_protected(dev, msta, link_id) == + &msta->deflink) + return true; + } + + return false; +} + static void mt7996_sta_deflink_release(struct mt7996_dev *dev, struct ieee80211_sta *sta, unsigned int link_id) @@ -1210,17 +1224,19 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, if (idx < 0) return -ENOSPC; - if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) { - msta_link = &msta->deflink; - mt7996_sta_deflink_set(sta, link_id, idx); - } else { + if (mt7996_sta_deflink_busy(dev, msta)) { msta_link = kzalloc_obj(*msta_link); if (!msta_link) { mt76_wcid_mask_clear(dev->mt76.wcid_mask, idx); return -ENOMEM; } + } else { + msta_link = &msta->deflink; } + if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) + mt7996_sta_deflink_set(sta, link_id, idx); + INIT_LIST_HEAD(&msta_link->rc_list); INIT_LIST_HEAD(&msta_link->wcid.poll_list); msta_link->sta = msta; From 6541956cadc484eeed719e7a8e9e7d27e5900289 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:24 +0200 Subject: [PATCH 1312/2126] wifi: mt76: mt7996: keep a returning link when adding station links fails mt7996_mac_sta_add_links() removes all links that it was asked to add, with flush set, when one of them fails. A link that comes back after a removal kept its msta_link and may still have a firmware entry. The flush frees its msta_link and returns its WTBL index to wcid_mask, so a later station can be given an index whose entry still belongs to this station. Flush only the links that this call created, and remove a returning link again without flush. Fixes: e8c819df0243 ("wifi: mt76: mt7996: Destroy active sta links in mt7996_mac_sta_remove()") Link: https://patch.msgid.link/20261006205936.669125-15-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 8e70a4061ed6..58a487549ddf 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1355,6 +1355,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta, unsigned long new_links) { struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + unsigned long created = 0, returned = 0; unsigned int link_id; int err = 0; @@ -1372,6 +1373,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, mt7996_sta_deflink_set(sta, link_id, msta_link->wcid.idx); msta->seclink_id = mt7996_sta_seclink_get(dev, msta); + returned |= BIT(link_id); continue; } @@ -1405,12 +1407,14 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, goto error_unlink; mphy->num_sta++; + created |= BIT(link_id); } return 0; error_unlink: - mt7996_mac_sta_remove_links(dev, vif, sta, new_links, true); + mt7996_mac_sta_remove_links(dev, vif, sta, created, true); + mt7996_mac_sta_remove_links(dev, vif, sta, returned, false); return err; } From 854c8d4358272ad1204e9436996dec264fe334b1 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:25 +0200 Subject: [PATCH 1313/2126] wifi: mt76: mt7996: add the station BMC entry as new once per BSSID A station link sends its broadcast STA_REC with EXTRA_INFO_NEW on every BSS_CHANGED_BSSID. Commit 8e3e7567b8c1 ("mt76: mt7915: add sta_rec with EXTRA_INFO_NEW for the first time only") notes that the firmware may remove an entry that is added as new twice. Since a removed vif link keeps its firmware entry, this happens on a link that is deactivated and activated again: _ieee80211_set_active_links() reports BSS_CHANGED_BSSID with the same BSSID, after ieee80211_key_switch_links() has installed the group keys of the link, and nothing in the driver installs them again after the entry is added as new. Record the BSSID the entry was added with, and add it as new only for a different BSSID. A BSSID that goes to zero on disconnection clears the record, so that the next association adds the entry as new again. A link that is set up clears the record as well, since the firmware has no entry for it then. Fixes: 08813703ac41 ("wifi: mt76: mt7996: Destroy vif active links in mt7996_remove_interface()") Link: https://patch.msgid.link/20261006205936.669125-16-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 38 ++++++++++++------- .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 58a487549ddf..d868e9641334 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -341,6 +341,7 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, return -ENOSPC; link->mld_idx = mld_idx; + eth_zero_addr(link->bmc_bssid); mlink->omac_idx = idx; mlink->band_idx = band_idx; mlink->wmm_idx = vif->type == NL80211_IFTYPE_AP ? 0 : 3; @@ -898,6 +899,23 @@ mt7996_update_mu_group(struct ieee80211_hw *hw, struct mt7996_vif_link *link, mt76_wr(dev, MT_WF_PHYRX_BAND_GID_TAB_POS3(band), mu[3]); } +static void +mt7996_vif_link_bss_add(struct mt7996_phy *phy, struct ieee80211_vif *vif, + struct ieee80211_bss_conf *link_conf, + struct mt7996_vif_link *link, bool newly) +{ + if (vif->type == NL80211_IFTYPE_STATION) { + newly = !ether_addr_equal_unaligned(link->bmc_bssid, + link_conf->bssid); + memcpy(link->bmc_bssid, link_conf->bssid, ETH_ALEN); + } + + mt7996_mcu_add_bss_info(phy, vif, link_conf, &link->mt76, + &link->msta_link, true); + mt7996_mcu_add_sta(phy->dev, link_conf, NULL, link, NULL, + CONN_STATE_PORT_SECURE, newly); +} + static void mt7996_vif_cfg_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 changed) @@ -929,12 +947,8 @@ mt7996_vif_cfg_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, if (!phy) continue; - mt7996_mcu_add_bss_info(phy, vif, link_conf, - &link->mt76, &link->msta_link, - true); - mt7996_mcu_add_sta(dev, link_conf, NULL, link, NULL, - CONN_STATE_PORT_SECURE, - !!(changed & BSS_CHANGED_BSSID)); + mt7996_vif_link_bss_add(phy, vif, link_conf, link, + !!(changed & BSS_CHANGED_BSSID)); } } @@ -980,13 +994,11 @@ mt7996_link_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, * and then peer references bss_info_rfch to set bandwidth cap. */ if ((changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) || - (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon)) { - mt7996_mcu_add_bss_info(phy, vif, info, &link->mt76, - &link->msta_link, true); - mt7996_mcu_add_sta(dev, info, NULL, link, NULL, - CONN_STATE_PORT_SECURE, - !!(changed & BSS_CHANGED_BSSID)); - } + (changed & BSS_CHANGED_BEACON_ENABLED && info->enable_beacon)) + mt7996_vif_link_bss_add(phy, vif, info, link, + !!(changed & BSS_CHANGED_BSSID)); + else if (changed & BSS_CHANGED_BSSID) + eth_zero_addr(link->bmc_bssid); if (changed & BSS_CHANGED_HT || changed & BSS_CHANGED_ERP_CTS_PROT) mt7996_mcu_set_protection(phy, link, info->ht_operation_mode, diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index 82a2a8a5db69..03fc0e7fd4f1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -279,6 +279,7 @@ struct mt7996_vif_link { struct cfg80211_bitrate_mask bitrate_mask; u8 mld_idx; + u8 bmc_bssid[ETH_ALEN]; }; struct mt7996_vif_link_info { From 72f050d4b04e40f450573ffb95cb4717c8bbfefb Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:26 +0200 Subject: [PATCH 1314/2126] wifi: mt76: mt7996: keep 4-address and decap state per station mac80211 reports 4-address mode and decap offload once per station, through sta_set_4addr and sta_set_decap_offload. mt7996_sta_set_4addr() and mt7996_sta_set_decap_offload() set MT_WCID_FLAG_4ADDR and MT_WCID_FLAG_HDR_TRANS only on the links that exist at that moment, but the hardware keeps header translation per link. A link that is added later starts without the flags, and a link that is removed at that time keeps its old flags when it comes back, so the firmware gets the wrong to_ds/from_ds pair for that link. Keep both states in the station, and apply them to a link when the callbacks run, when the link is set up and when it comes back. Fixes: f520eceacd24 ("wifi: mt76: mt7996: Add mt7996_mac_sta_change_links callback") Fixes: e8c819df0243 ("wifi: mt76: mt7996: Destroy active sta links in mt7996_mac_sta_remove()") Link: https://patch.msgid.link/20261006205936.669125-17-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 29 +++++++++++-------- .../wireless/mediatek/mt76/mt7996/mt7996.h | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index d868e9641334..bba5a8c6dec8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1155,6 +1155,16 @@ mt7996_sta_deflink_set(struct ieee80211_sta *sta, unsigned int link_id, mt7996_sta_init_txq_wcid(sta, idx); } +static void +mt7996_sta_link_hdr_trans_set(struct mt7996_sta *msta, + struct mt7996_sta_link *msta_link) +{ + assign_bit(MT_WCID_FLAG_4ADDR, &msta_link->wcid.flags, + test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid_flags)); + assign_bit(MT_WCID_FLAG_HDR_TRANS, &msta_link->wcid.flags, + test_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid_flags)); +} + static bool mt7996_sta_deflink_busy(struct mt7996_dev *dev, struct mt7996_sta *msta) { @@ -1261,6 +1271,8 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, if (link_sta->sta->tdls) set_bit(MT_WCID_FLAG_TDLS_PEER, &msta_link->wcid.flags); + mt7996_sta_link_hdr_trans_set(msta, msta_link); + ewma_avg_signal_init(&msta_link->avg_ack_signal); ewma_signal_init(&msta_link->wcid.rssi); @@ -1381,6 +1393,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, msta_link = mt76_dereference(msta->link[link_id], &dev->mt76); if (msta_link) { msta_link->wcid.link_valid = true; + mt7996_sta_link_hdr_trans_set(msta, msta_link); if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) mt7996_sta_deflink_set(sta, link_id, msta_link->wcid.idx); @@ -2166,6 +2179,7 @@ static void mt7996_sta_set_4addr(struct ieee80211_hw *hw, mutex_lock(&dev->mt76.mutex); + assign_bit(MT_WCID_FLAG_4ADDR, &msta->wcid_flags, enabled); for_each_sta_active_link(vif, sta, link_sta, link_id) { struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; @@ -2178,11 +2192,7 @@ static void mt7996_sta_set_4addr(struct ieee80211_hw *hw, if (!msta_link) continue; - if (enabled) - set_bit(MT_WCID_FLAG_4ADDR, &msta_link->wcid.flags); - else - clear_bit(MT_WCID_FLAG_4ADDR, &msta_link->wcid.flags); - + mt7996_sta_link_hdr_trans_set(msta, msta_link); if (!msta_link->wcid.sta) continue; @@ -2212,6 +2222,7 @@ static void mt7996_sta_set_decap_offload(struct ieee80211_hw *hw, mutex_lock(&dev->mt76.mutex); + assign_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid_flags, enabled); for_each_sta_active_link(vif, sta, link_sta, link_id) { struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; @@ -2224,13 +2235,7 @@ static void mt7996_sta_set_decap_offload(struct ieee80211_hw *hw, if (!msta_link) continue; - if (enabled) - set_bit(MT_WCID_FLAG_HDR_TRANS, - &msta_link->wcid.flags); - else - clear_bit(MT_WCID_FLAG_HDR_TRANS, - &msta_link->wcid.flags); - + mt7996_sta_link_hdr_trans_set(msta, msta_link); if (!msta_link->wcid.sta) continue; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index 03fc0e7fd4f1..949e659b8e2d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -269,6 +269,8 @@ struct mt7996_sta { u8 deflink_id; u8 seclink_id; + unsigned long wcid_flags; + struct mt7996_vif *vif; }; From ad8e618e4474dda22936a52757838ff990e6cda1 Mon Sep 17 00:00:00 2001 From: Howard Hsu Date: Tue, 6 Oct 2026 22:59:27 +0200 Subject: [PATCH 1315/2126] wifi: mt76: mt7996: do not add a station link in disconnected state Since the driver uses the .sta_state op, mt7996_mac_sta_init_link() sends a STA_REC with CONN_STATE_DISCONNECT when a station link is set up. Before that change, the first STA_REC for a station was the one that connects it. MediaTek reports that DL OFDMA fails after a station reconnects. Only send a STA_REC for a station link when it connects. Until then the firmware has no STA_REC for the link, so track whether a link is connected, and skip rate control updates and the 4-address and decap updates for a link that is not. wcid.sta cannot be used for this, since it is set when the link is set up. Fixes: 13e2e9c6b348 ("wifi: mt76: mt7996: use mac80211 .sta_state op") Signed-off-by: Howard Hsu Link: https://patch.msgid.link/20261006205936.669125-18-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/mac.c | 4 +++ .../net/wireless/mediatek/mt76/mt7996/main.c | 33 +++++++++++++------ .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index eb39526548e8..c4e82b1e259c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -2948,6 +2948,10 @@ void mt7996_mac_sta_rc_work(struct work_struct *work) changed = msta_link->changed; msta_link->changed = 0; + + if (!msta_link->connected) + continue; + mvif = msta_link->sta->vif; vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index bba5a8c6dec8..a23d148eafa6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1229,7 +1229,6 @@ mt7996_sta_seclink_get(struct mt7996_dev *dev, struct mt7996_sta *msta) static int mt7996_mac_sta_init_link(struct mt7996_dev *dev, - struct ieee80211_bss_conf *link_conf, struct ieee80211_link_sta *link_sta, struct mt7996_vif_link *link, unsigned int link_id) { @@ -1262,6 +1261,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, INIT_LIST_HEAD(&msta_link->rc_list); INIT_LIST_HEAD(&msta_link->wcid.poll_list); msta_link->sta = msta; + msta_link->connected = false; msta_link->wcid.sta = 1; msta_link->wcid.idx = idx; msta_link->wcid.link_id = link_id; @@ -1280,8 +1280,6 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, msta->seclink_id = mt7996_sta_seclink_get(dev, msta); mt7996_mac_wtbl_update(dev, idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR); - mt7996_mcu_add_sta(dev, link_conf, link_sta, link, msta_link, - CONN_STATE_DISCONNECT, true); rcu_assign_pointer(dev->mt76.wcid[idx], &msta_link->wcid); mt76_wcid_init(&msta_link->wcid, phy->mt76->band_idx); @@ -1384,7 +1382,6 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, int err = 0; for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) { - struct ieee80211_bss_conf *link_conf; struct ieee80211_link_sta *link_sta; struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; @@ -1402,8 +1399,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, continue; } - link_conf = link_conf_dereference_protected(vif, link_id); - if (!link_conf) { + if (!link_conf_dereference_protected(vif, link_id)) { err = -EINVAL; goto error_unlink; } @@ -1426,8 +1422,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, goto error_unlink; } - err = mt7996_mac_sta_init_link(dev, link_conf, link_sta, link, - link_id); + err = mt7996_mac_sta_init_link(dev, link_sta, link, link_id); if (err) goto error_unlink; @@ -1515,6 +1510,7 @@ mt7996_mac_sta_links_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, if (err) return err; + msta_link->connected = true; err = mt7996_mcu_add_rate_ctrl(dev, msta_link->sta, vif, link_id, false); if (err) @@ -1551,16 +1547,33 @@ mt7996_mac_sta_links_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, return 0; } +static void +mt7996_mac_sta_clear_connected(struct mt7996_dev *dev, struct mt7996_sta *msta) +{ + unsigned int link_id; + + for (link_id = 0; link_id < ARRAY_SIZE(msta->link); link_id++) { + struct mt7996_sta_link *msta_link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + if (msta_link) + msta_link->connected = false; + } +} + static int mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta, enum mt76_sta_event ev) { + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; int err; mutex_lock(&dev->mt76.mutex); err = mt7996_mac_sta_links_event(dev, vif, sta, mt7996_mac_sta_links(dev, vif, sta), ev); + if (!err && ev == MT76_STA_EVENT_DISASSOC) + mt7996_mac_sta_clear_connected(dev, msta); mutex_unlock(&dev->mt76.mutex); return err; @@ -2193,7 +2206,7 @@ static void mt7996_sta_set_4addr(struct ieee80211_hw *hw, continue; mt7996_sta_link_hdr_trans_set(msta, msta_link); - if (!msta_link->wcid.sta) + if (!msta_link->connected) continue; mt7996_mcu_wtbl_update_hdr_trans(dev, vif, link, msta_link); @@ -2236,7 +2249,7 @@ static void mt7996_sta_set_decap_offload(struct ieee80211_hw *hw, continue; mt7996_sta_link_hdr_trans_set(msta, msta_link); - if (!msta_link->wcid.sta) + if (!msta_link->connected) continue; mt7996_mcu_wtbl_update_hdr_trans(dev, vif, link, msta_link); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index 949e659b8e2d..ec453f5ff3a5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -244,6 +244,7 @@ struct mt7996_sta_link { struct mt76_wcid wcid; /* must be first */ struct mt7996_sta *sta; + bool connected; struct list_head rc_list; u32 airtime_ac[8]; From d07675fcbf2bedb6ae58368276b2e8652bda8e99 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:28 +0200 Subject: [PATCH 1316/2126] wifi: mt76: mt7996: record the connection state of a station mt7996_sta_state() turns the station state transitions into STA_REC updates for the links of the station, but the driver keeps no record of the state that the station reached. A link that is added after association needs that state to be brought up to the same level as the other links. Record the connection state after each station event, and lower it to CONN_STATE_CONNECT when the station leaves IEEE80211_STA_AUTHORIZED, for example when hostapd de-authorizes it for a re-authentication. No functional change on its own. Link: https://patch.msgid.link/20261006205936.669125-19-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 30 ++++++++++++++++++- .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index a23d148eafa6..7792c3a878af 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1472,6 +1472,7 @@ mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; msta->seclink_id = IEEE80211_LINK_UNSPECIFIED; + msta->conn_state = CONN_STATE_DISCONNECT; msta->vif = mvif; err = mt7996_mac_sta_add_links(dev, vif, sta, links); @@ -1569,11 +1570,27 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, int err; mutex_lock(&dev->mt76.mutex); + err = mt7996_mac_sta_links_event(dev, vif, sta, mt7996_mac_sta_links(dev, vif, sta), ev); - if (!err && ev == MT76_STA_EVENT_DISASSOC) + if (err) + goto out; + + switch (ev) { + case MT76_STA_EVENT_ASSOC: + msta->conn_state = CONN_STATE_CONNECT; + break; + case MT76_STA_EVENT_AUTHORIZE: + msta->conn_state = CONN_STATE_PORT_SECURE; + break; + case MT76_STA_EVENT_DISASSOC: + msta->conn_state = CONN_STATE_DISCONNECT; mt7996_mac_sta_clear_connected(dev, msta); + break; + } + +out: mutex_unlock(&dev->mt76.mutex); return err; @@ -1650,6 +1667,17 @@ mt7996_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif, new_state == IEEE80211_STA_NOTEXIST) mt7996_mac_sta_remove(dev, vif, sta); + if (old_state == IEEE80211_STA_AUTHORIZED && + new_state == IEEE80211_STA_ASSOC) { + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + + mutex_lock(&dev->mt76.mutex); + msta->conn_state = CONN_STATE_CONNECT; + mutex_unlock(&dev->mt76.mutex); + + return 0; + } + if (old_state == IEEE80211_STA_AUTH && new_state == IEEE80211_STA_ASSOC) { mt7996_set_active_links(vif); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index ec453f5ff3a5..ead211391404 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -269,6 +269,7 @@ struct mt7996_sta { struct mt7996_sta_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS]; u8 deflink_id; u8 seclink_id; + u8 conn_state; unsigned long wcid_flags; From b5ca7f065a6456add4caea464060427f7aff78f7 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:29 +0200 Subject: [PATCH 1317/2126] wifi: mt76: mt7996: keep the block ack session parameters per station mt7996_mcu_add_tx_ba() and mt7996_mcu_add_rx_ba() send STA_REC_BA to the links that are active when mac80211 starts the session. To set up a running session on a link that is added later, the driver needs the parameters of that session, but it records a TX session only as a bit in ampdu_state and keeps no RX session parameters. Store the parameters of each running TX and RX session per TID, and pass the set of links to update to mt7996_mcu_add_tx_ba() and mt7996_mcu_add_rx_ba(). mt7996_ampdu_action() passes the links from mt7996_mac_sta_links(), which are the links that have driver state. No functional change on its own. Link: https://patch.msgid.link/20261006205936.669125-20-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 40 ++++++++++++++++--- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 12 +++--- .../wireless/mediatek/mt76/mt7996/mt7996.h | 17 +++++++- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 7792c3a878af..d90ada7f0f2a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1473,6 +1473,8 @@ mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, msta->deflink_id = IEEE80211_LINK_UNSPECIFIED; msta->seclink_id = IEEE80211_LINK_UNSPECIFIED; msta->conn_state = CONN_STATE_DISCONNECT; + msta->ba_tx_mask = 0; + msta->ba_rx_mask = 0; msta->vif = mvif; err = mt7996_mac_sta_add_links(dev, vif, sta, links); @@ -1809,6 +1811,21 @@ static int mt7996_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx, return ret; } +static void +mt7996_sta_ba_update(u16 *mask, struct mt7996_sta_ba *ba, + struct ieee80211_ampdu_params *params, bool enable) +{ + if (!enable) { + *mask &= ~BIT(params->tid); + return; + } + + *mask |= BIT(params->tid); + ba[params->tid].ssn = params->ssn; + ba[params->tid].buf_size = params->buf_size; + ba[params->tid].amsdu = params->amsdu; +} + static int mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_ampdu_params *params) @@ -1820,6 +1837,7 @@ mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 tid = params->tid; u16 ssn = params->ssn; struct mt76_txq *mtxq; + unsigned long links; int ret = 0; if (!txq) @@ -1829,6 +1847,8 @@ mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&dev->mt76.mutex); + links = mt7996_mac_sta_links(dev, vif, sta); + switch (params->action) { case IEEE80211_AMPDU_RX_START: /* Since packets belonging to the same TID can be split over @@ -1837,22 +1857,30 @@ mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, */ mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid, ssn, params->buf_size); - ret = mt7996_mcu_add_rx_ba(dev, params, vif, true); + ret = mt7996_mcu_add_rx_ba(dev, params, vif, links, true); + mt7996_sta_ba_update(&msta->ba_rx_mask, msta->ba_rx, params, + !ret); break; case IEEE80211_AMPDU_RX_STOP: mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid); - ret = mt7996_mcu_add_rx_ba(dev, params, vif, false); + mt7996_sta_ba_update(&msta->ba_rx_mask, msta->ba_rx, params, + false); + ret = mt7996_mcu_add_rx_ba(dev, params, vif, links, false); break; case IEEE80211_AMPDU_TX_OPERATIONAL: mtxq->aggr = true; mtxq->send_bar = false; - ret = mt7996_mcu_add_tx_ba(dev, params, vif, true); + ret = mt7996_mcu_add_tx_ba(dev, params, vif, links, true); + mt7996_sta_ba_update(&msta->ba_tx_mask, msta->ba_tx, params, + !ret); break; case IEEE80211_AMPDU_TX_STOP_FLUSH: case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: mtxq->aggr = false; clear_bit(tid, &msta->deflink.wcid.ampdu_state); - ret = mt7996_mcu_add_tx_ba(dev, params, vif, false); + mt7996_sta_ba_update(&msta->ba_tx_mask, msta->ba_tx, params, + false); + ret = mt7996_mcu_add_tx_ba(dev, params, vif, links, false); break; case IEEE80211_AMPDU_TX_START: set_bit(tid, &msta->deflink.wcid.ampdu_state); @@ -1861,7 +1889,9 @@ mt7996_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, case IEEE80211_AMPDU_TX_STOP_CONT: mtxq->aggr = false; clear_bit(tid, &msta->deflink.wcid.ampdu_state); - ret = mt7996_mcu_add_tx_ba(dev, params, vif, false); + mt7996_sta_ba_update(&msta->ba_tx_mask, msta->ba_tx, params, + false); + ret = mt7996_mcu_add_tx_ba(dev, params, vif, links, false); ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); break; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c index 02f9bcfdf5d9..1d2ee1ca5298 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c @@ -1511,15 +1511,15 @@ mt7996_mcu_sta_ba(struct mt7996_dev *dev, struct mt76_vif_link *mvif, /** starec & wtbl **/ int mt7996_mcu_add_tx_ba(struct mt7996_dev *dev, struct ieee80211_ampdu_params *params, - struct ieee80211_vif *vif, bool enable) + struct ieee80211_vif *vif, unsigned long links, + bool enable) { struct ieee80211_sta *sta = params->sta; struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - struct ieee80211_link_sta *link_sta; unsigned int link_id; int ret = 0; - for_each_sta_active_link(vif, sta, link_sta, link_id) { + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; @@ -1545,15 +1545,15 @@ int mt7996_mcu_add_tx_ba(struct mt7996_dev *dev, int mt7996_mcu_add_rx_ba(struct mt7996_dev *dev, struct ieee80211_ampdu_params *params, - struct ieee80211_vif *vif, bool enable) + struct ieee80211_vif *vif, unsigned long links, + bool enable) { struct ieee80211_sta *sta = params->sta; struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - struct ieee80211_link_sta *link_sta; unsigned int link_id; int ret = 0; - for_each_sta_active_link(vif, sta, link_sta, link_id) { + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index ead211391404..8744411e0717 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -264,6 +264,12 @@ struct mt7996_sta_link { struct rcu_head rcu_head; }; +struct mt7996_sta_ba { + u16 ssn; + u16 buf_size; + bool amsdu; +}; + struct mt7996_sta { struct mt7996_sta_link deflink; /* must be first */ struct mt7996_sta_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS]; @@ -273,6 +279,11 @@ struct mt7996_sta { unsigned long wcid_flags; + u16 ba_tx_mask; + u16 ba_rx_mask; + struct mt7996_sta_ba ba_tx[IEEE80211_NUM_TIDS]; + struct mt7996_sta_ba ba_rx[IEEE80211_NUM_TIDS]; + struct mt7996_vif *vif; }; @@ -733,10 +744,12 @@ int mt7996_mcu_teardown_mld_sta(struct mt7996_dev *dev, void mt7996_mcu_update_sta_rec_bw(void *data, struct ieee80211_sta *sta); int mt7996_mcu_add_tx_ba(struct mt7996_dev *dev, struct ieee80211_ampdu_params *params, - struct ieee80211_vif *vif, bool enable); + struct ieee80211_vif *vif, unsigned long links, + bool enable); int mt7996_mcu_add_rx_ba(struct mt7996_dev *dev, struct ieee80211_ampdu_params *params, - struct ieee80211_vif *vif, bool enable); + struct ieee80211_vif *vif, unsigned long links, + bool enable); int mt7996_mcu_update_bss_color(struct mt7996_dev *dev, struct mt76_vif_link *mlink, struct cfg80211_he_bss_color *he_bss_color); From 7c20cafcc1727bf9af57e7b76a6ba9971f84d020 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:30 +0200 Subject: [PATCH 1318/2126] wifi: mt76: mt7996: set up the BSS of a late station link before its peer On association, a station link gets its BSS_INFO with the BSSID and its broadcast STA_REC from BSS_CHANGED_BSSID before the peer STA_REC is created, and mt7996_link_info_changed() notes that station mode maps the peer entry through the BSSID. For a link that becomes active later, _ieee80211_set_active_links() calls drv_change_sta_links() first and reports BSS_CHANGED_BSSID for the link only afterwards. Send the BSS_INFO and the broadcast STA_REC of an added station link from mt7996_mac_sta_change_links() before its peer entry is set up when the station is already associated, in the order of an association. The later BSS_CHANGED_BSSID finds the BSSID recorded and does not add the broadcast entry as new again. This prepares for bringing up such links in the following change. Link: https://patch.msgid.link/20261006205936.669125-21-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 72 +++++++++++++------ 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index d90ada7f0f2a..4f3ebe4cee65 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1439,26 +1439,6 @@ error_unlink: return err; } -static int -mt7996_mac_sta_change_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, - struct ieee80211_sta *sta, u16 old_links, - u16 new_links) -{ - struct mt7996_dev *dev = mt7996_hw_dev(hw); - unsigned long add = new_links & ~old_links; - unsigned long rem = old_links & ~new_links; - int ret; - - mutex_lock(&dev->mt76.mutex); - - mt7996_mac_sta_remove_links(dev, vif, sta, rem, false); - ret = mt7996_mac_sta_add_links(dev, vif, sta, add); - - mutex_unlock(&dev->mt76.mutex); - - return ret; -} - static int mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta) @@ -1598,6 +1578,58 @@ out: return err; } +static void +mt7996_mac_sta_links_bss_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, unsigned long links) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + unsigned int link_id; + + if (vif->type != NL80211_IFTYPE_STATION || + msta->conn_state == CONN_STATE_DISCONNECT) + return; + + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { + struct ieee80211_bss_conf *link_conf; + struct mt7996_vif_link *link; + struct mt7996_phy *phy; + + link_conf = link_conf_dereference_protected(vif, link_id); + if (!link_conf || !link_conf->bssid || + is_zero_ether_addr(link_conf->bssid)) + continue; + + link = mt7996_vif_link(dev, vif, link_id); + if (!link) + continue; + + phy = mt7996_vif_link_phy(link); + if (phy) + mt7996_vif_link_bss_add(phy, vif, link_conf, link, true); + } +} + +static int +mt7996_mac_sta_change_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, u16 old_links, + u16 new_links) +{ + struct mt7996_dev *dev = mt7996_hw_dev(hw); + unsigned long add = new_links & ~old_links; + unsigned long rem = old_links & ~new_links; + int ret; + + mutex_lock(&dev->mt76.mutex); + + mt7996_mac_sta_remove_links(dev, vif, sta, rem, false); + mt7996_mac_sta_links_bss_add(dev, vif, sta, add); + ret = mt7996_mac_sta_add_links(dev, vif, sta, add); + + mutex_unlock(&dev->mt76.mutex); + + return ret; +} + static void mt7996_mac_sta_remove(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta) From 1aef01d3cbbe88cec919fd51999f3becfc639ad8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:31 +0200 Subject: [PATCH 1319/2126] wifi: mt76: mt7996: bring up station links added after association mt7996_mac_sta_change_links() only sets up the driver state of a link that is added to a station. The CONN_STATE_CONNECT and CONN_STATE_PORT_SECURE STA_RECs and the rate control setup come from mt7996_mac_sta_event(), which runs once per station state change, so a link that becomes active after association has no firmware entry. This is the normal case on a station interface: mac80211 activates only the association link at first, and mt7996_sta_state() requests the other links with ieee80211_set_active_links_async() when the station moves to IEEE80211_STA_ASSOC. The STA_REC_MLD of the links already connected also keeps the old set of links. When links are added, replay the association on the links that are not connected yet, install the keys of the station on them, and replay the authorization if the station is authorized. mac80211 does not install the pairwise key again, since ieee80211_key_switch_links() moves only keys with key->link_id >= 0. Send the other links a STA_REC with only STA_REC_MLD and STA_REC_EHT_MLD, so that their link list follows the change. A 4-address link other than the primary link also gets the PS leave request that mt7996_sta_set_4addr() sends on association. If bringing up the added links fails, reset and remove them again without flush, since the firmware can still hold an entry for their WTBL index, and send the remaining links their STA_REC_MLD again. While here, indent struct mt7996_key_iter_data with tabs. Fixes: f520eceacd24 ("wifi: mt76: mt7996: Add mt7996_mac_sta_change_links callback") Link: https://patch.msgid.link/20261006205936.669125-22-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 152 ++++++++++++++++-- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 21 +++ .../wireless/mediatek/mt76/mt7996/mt7996.h | 5 + 3 files changed, 166 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 4f3ebe4cee65..324d3b195a3f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -277,8 +277,9 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, } struct mt7996_key_iter_data { - enum set_key_cmd cmd; - unsigned int link_id; + enum set_key_cmd cmd; + unsigned int link_id; + struct ieee80211_sta *sta; }; static void @@ -288,13 +289,13 @@ mt7996_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif, { struct mt7996_key_iter_data *it = data; - if (sta) + if (sta != it->sta) return; if (key->link_id >= 0 && key->link_id != it->link_id) return; - WARN_ON(mt7996_set_hw_key(hw, it->cmd, vif, NULL, it->link_id, key)); + WARN_ON(mt7996_set_hw_key(hw, it->cmd, vif, sta, it->link_id, key)); } int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, @@ -1530,6 +1531,23 @@ mt7996_mac_sta_links_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, return 0; } +static void +mt7996_mac_sta_link_ps_leave(struct mt7996_dev *dev, + struct mt7996_vif_link *link, + struct mt7996_sta_link *msta_link) +{ + /* HW cannot derive the BSSID from 4-address non-AMSDU frames, + * so PS exit is missed on links other than the setup link. + * Let the firmware wake those links instead. + */ + if (!is_mt7996(&dev->mt76) || + !test_bit(MT_WCID_FLAG_4ADDR, &msta_link->wcid.flags) || + msta_link->wcid.link_id == msta_link->sta->deflink_id) + return; + + mt7996_mcu_ps_leave(dev, link, msta_link); +} + static void mt7996_mac_sta_clear_connected(struct mt7996_dev *dev, struct mt7996_sta *msta) { @@ -1578,6 +1596,113 @@ out: return err; } +static void +mt7996_mac_sta_links_set_keys(struct mt7996_dev *dev, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, unsigned long links) +{ + unsigned int link_id; + + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt7996_key_iter_data it = { + .cmd = SET_KEY, + .link_id = link_id, + .sta = sta, + }; + + ieee80211_iter_keys(mt76_hw(dev), vif, mt7996_key_iter, &it); + } +} + +static int +mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, unsigned long links, + unsigned long add) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + unsigned long new_links = 0, updated; + unsigned int link_id; + int err; + + if (msta->conn_state == CONN_STATE_DISCONNECT) + return 0; + + links &= mt7996_mac_sta_links(dev, vif, sta); + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt7996_sta_link *msta_link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + if (!msta_link->connected) + new_links |= BIT(link_id); + } + + err = mt7996_mac_sta_links_event(dev, vif, sta, new_links, + MT76_STA_EVENT_ASSOC); + if (err) + return err; + + mt7996_mac_sta_links_set_keys(dev, vif, sta, links & add); + + updated = new_links; + if (msta->conn_state == CONN_STATE_PORT_SECURE) { + err = mt7996_mac_sta_links_event(dev, vif, sta, updated, + MT76_STA_EVENT_AUTHORIZE); + if (err) + return err; + } + + for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt7996_sta_link *msta_link; + struct mt7996_vif_link *link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + link = mt7996_vif_link(dev, vif, link_id); + mt7996_mac_sta_link_ps_leave(dev, link, msta_link); + } + + updated = sta->mlo ? links & ~updated : 0; + for_each_set_bit(link_id, &updated, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt7996_sta_link *msta_link; + struct mt7996_vif_link *link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + link = mt7996_vif_link(dev, vif, link_id); + err = mt7996_mcu_update_mld_sta(dev, vif, sta, link, msta_link); + if (err) + return err; + } + + return 0; +} + +static void +mt7996_mac_sta_links_reset(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, unsigned long links) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + unsigned int link_id; + + for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt7996_sta_link *msta_link; + struct mt7996_vif_link *link; + int i; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + if (!msta_link) + continue; + + link = mt7996_vif_link(dev, vif, link_id); + if (link) { + for (i = 0; i < ARRAY_SIZE(msta_link->twt.flow); i++) + mt7996_mac_twt_teardown_flow(dev, link, + msta_link, i); + } + + msta_link->wcid.tx_info &= ~MT_WCID_TX_INFO_SET; + msta_link->wcid.hw_key_idx = -1; + } +} + static void mt7996_mac_sta_links_bss_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta, unsigned long links) @@ -1624,7 +1749,17 @@ mt7996_mac_sta_change_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mt7996_mac_sta_remove_links(dev, vif, sta, rem, false); mt7996_mac_sta_links_bss_add(dev, vif, sta, add); ret = mt7996_mac_sta_add_links(dev, vif, sta, add); + if (ret) + goto out; + ret = mt7996_mac_sta_links_sync(dev, vif, sta, new_links, add); + if (ret) { + mt7996_mac_sta_links_reset(dev, vif, sta, add); + mt7996_mac_sta_remove_links(dev, vif, sta, add, false); + mt7996_mac_sta_links_sync(dev, vif, sta, new_links & ~add, 0); + } + +out: mutex_unlock(&dev->mt76.mutex); return ret; @@ -2300,14 +2435,7 @@ static void mt7996_sta_set_4addr(struct ieee80211_hw *hw, continue; mt7996_mcu_wtbl_update_hdr_trans(dev, vif, link, msta_link); - - /* HW cannot derive the BSSID from 4-address non-AMSDU frames, - * so PS exit is missed on links other than the setup link. - * Let the firmware wake those links instead. - */ - if (enabled && msta->deflink_id != link_id && - is_mt7996(&dev->mt76)) - mt7996_mcu_ps_leave(dev, link, msta_link); + mt7996_mac_sta_link_ps_leave(dev, link, msta_link); } mutex_unlock(&dev->mt76.mutex); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c index 1d2ee1ca5298..c324d199b212 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c @@ -2910,6 +2910,27 @@ int mt7996_mcu_teardown_mld_sta(struct mt7996_dev *dev, MCU_WMWA_UNI_CMD(STA_REC_UPDATE), true); } +int mt7996_mcu_update_mld_sta(struct mt7996_dev *dev, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct mt7996_vif_link *link, + struct mt7996_sta_link *msta_link) +{ + struct sk_buff *skb; + + skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &link->mt76, + &msta_link->wcid, + MT7996_STA_UPDATE_MAX_SIZE); + if (IS_ERR(skb)) + return PTR_ERR(skb); + + mt7996_mcu_sta_mld_setup_tlv(dev, skb, vif, sta); + mt7996_mcu_sta_eht_mld_tlv(dev, skb, sta); + + return mt76_mcu_skb_send_msg(&dev->mt76, skb, + MCU_WMWA_UNI_CMD(STA_REC_UPDATE), true); +} + void mt7996_mcu_update_sta_rec_bw(void *data, struct ieee80211_sta *sta) { struct mt7996_vif_link *link = (struct mt7996_vif_link *)data; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index 8744411e0717..ae97ca091673 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -741,6 +741,11 @@ int mt7996_mcu_add_sta(struct mt7996_dev *dev, int mt7996_mcu_teardown_mld_sta(struct mt7996_dev *dev, struct mt7996_vif_link *link, struct mt7996_sta_link *msta_link); +int mt7996_mcu_update_mld_sta(struct mt7996_dev *dev, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct mt7996_vif_link *link, + struct mt7996_sta_link *msta_link); void mt7996_mcu_update_sta_rec_bw(void *data, struct ieee80211_sta *sta); int mt7996_mcu_add_tx_ba(struct mt7996_dev *dev, struct ieee80211_ampdu_params *params, From 1e9a44e38f131eb9b09e0d87cfbea7b2c50dd091 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:32 +0200 Subject: [PATCH 1320/2126] wifi: mt76: mt7996: set up block ack sessions on station links added later mt7996_ampdu_action() sends STA_REC_BA to the links that the station has when mac80211 starts a session. A link that is brought up later gets no STA_REC_BA, so it transmits without aggregation and, as a recipient, is not set up for hardware reordering. mac80211 does not start the sessions again when a link is added. Send STA_REC_BA for each running TX and RX session on the links that mt7996_mac_sta_change_links() brings up. For an RX session, use the current head of the reorder window, which mt76_rx_aggr_start() keeps on the default link, as the starting sequence number. That head moves only when the host reorders: with hardware RRO, mt7996 marks the frames as already aggregated and mt7996_mac_fill_rx() skips the host reorder state; with WED or the NPU active, mt76_rx_poll_complete() does not call mt76_rx_aggr_reorder(). The driver has no MCU query for the current window. In those modes, stop the RX sessions with ieee80211_stop_rx_ba_session() instead, so that the originator sets up new sessions, which then reach all links through the regular IEEE80211_AMPDU_RX_START path. Fixes: ef3f5941e560 ("wifi: mt76: mt7996: rework mt7996_ampdu_action to support MLO") Link: https://patch.msgid.link/20261006205936.669125-23-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 324d3b195a3f..89e9ef855a78 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1614,6 +1614,85 @@ mt7996_mac_sta_links_set_keys(struct mt7996_dev *dev, } } +static bool +mt7996_rx_reorder_host(struct mt7996_dev *dev) +{ + return !mt7996_has_hwrro(dev) && + !mtk_wed_device_active(&dev->mt76.mmio.wed) && + !mt76_npu_device_active(&dev->mt76); +} + +static u16 +mt7996_mac_sta_ba_rx_ssn(struct mt7996_dev *dev, struct mt7996_sta *msta, + unsigned int tid) +{ + struct mt76_rx_tid *tid_rx; + u16 ssn; + + tid_rx = mt76_dereference(msta->deflink.wcid.aggr[tid], &dev->mt76); + if (!tid_rx) + return msta->ba_rx[tid].ssn; + + spin_lock_bh(&tid_rx->lock); + ssn = tid_rx->head; + spin_unlock_bh(&tid_rx->lock); + + return ssn; +} + +static int +mt7996_mac_sta_links_ba_add(struct mt7996_dev *dev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, unsigned long links) +{ + struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + u16 rx_restart = 0; + unsigned int tid; + int err; + + if (!links) + return 0; + + for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) { + struct ieee80211_ampdu_params params = { + .sta = sta, + .tid = tid, + }; + + if (msta->ba_tx_mask & BIT(tid)) { + params.ssn = msta->ba_tx[tid].ssn; + params.buf_size = msta->ba_tx[tid].buf_size; + params.amsdu = msta->ba_tx[tid].amsdu; + err = mt7996_mcu_add_tx_ba(dev, ¶ms, vif, links, + true); + if (err) + return err; + } + + if (!(msta->ba_rx_mask & BIT(tid))) + continue; + + /* without host reordering, the reorder head stays at the + * session start, so have the originator set up a new session + */ + if (!mt7996_rx_reorder_host(dev)) { + rx_restart |= BIT(tid); + continue; + } + + params.ssn = mt7996_mac_sta_ba_rx_ssn(dev, msta, tid); + params.buf_size = msta->ba_rx[tid].buf_size; + params.amsdu = msta->ba_rx[tid].amsdu; + err = mt7996_mcu_add_rx_ba(dev, ¶ms, vif, links, true); + if (err) + return err; + } + + if (rx_restart) + ieee80211_stop_rx_ba_session(vif, rx_restart, sta->addr); + + return 0; +} + static int mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta, unsigned long links, @@ -1672,7 +1751,7 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, return err; } - return 0; + return mt7996_mac_sta_links_ba_add(dev, vif, sta, new_links); } static void From 28f776d5d4e119164da9e3db69bf900cccf74134 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:33 +0200 Subject: [PATCH 1321/2126] wifi: mt76: mt7996: restore a station link that returns after a removal When mt7996_mac_sta_change_links() removes a link from a station, it keeps the msta_link and the firmware entry of the link. Commit e077071e7ac4 ("wifi: mt76: mt7996: fix teardown command for an MLD peer") removed the per-link DISCONNECT command for MLD peers, and a link that comes back must not get a second STA_REC with EXTRA_INFO_NEW, which commit 8e3e7567b8c1 ("mt76: mt7915: add sta_rec with EXTRA_INFO_NEW for the first time only") says can remove the entry. A link that comes back is therefore not connected again, and gets no rate control, keys or authorization. On removal, reset only the driver state of the link: its TWT flows, the TX state and the key index. When the link comes back with its entry still connected, send it the header translation state, rate control, its keys and, for an authorized station, the CONN_STATE_PORT_SECURE update without EXTRA_INFO_NEW, which also carries the header translation state. Send the 4-address PS leave request and the block ack sessions as for a new link, since the link can come back as a link other than the primary link. Fixes: e8c819df0243 ("wifi: mt76: mt7996: Destroy active sta links in mt7996_mac_sta_remove()") Link: https://patch.msgid.link/20261006205936.669125-24-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/main.c | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 89e9ef855a78..9965ac136bec 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -1263,6 +1263,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev, INIT_LIST_HEAD(&msta_link->wcid.poll_list); msta_link->sta = msta; msta_link->connected = false; + msta_link->wcid.tx_info = 0; msta_link->wcid.sta = 1; msta_link->wcid.idx = idx; msta_link->wcid.link_id = link_id; @@ -1699,7 +1700,7 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, unsigned long add) { struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; - unsigned long new_links = 0, updated; + unsigned long new_links = 0, resumed = 0, joined, updated; unsigned int link_id; int err; @@ -1713,6 +1714,8 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, msta_link = mt7996_sta_link_protected(dev, msta, link_id); if (!msta_link->connected) new_links |= BIT(link_id); + else if (!(msta_link->wcid.tx_info & MT_WCID_TX_INFO_SET)) + resumed |= BIT(link_id); } err = mt7996_mac_sta_links_event(dev, vif, sta, new_links, @@ -1720,17 +1723,40 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, if (err) return err; + for_each_set_bit(link_id, &resumed, IEEE80211_MLD_MAX_NUM_LINKS) { + struct mt7996_sta_link *msta_link; + struct mt7996_vif_link *link; + + msta_link = mt7996_sta_link_protected(dev, msta, link_id); + link = mt7996_vif_link(dev, vif, link_id); + + if (msta->conn_state != CONN_STATE_PORT_SECURE) { + err = mt7996_mcu_wtbl_update_hdr_trans(dev, vif, link, + msta_link); + if (err) + return err; + } + + err = mt7996_mcu_add_rate_ctrl(dev, msta, vif, link_id, false); + if (err) + return err; + + msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET; + } + mt7996_mac_sta_links_set_keys(dev, vif, sta, links & add); updated = new_links; if (msta->conn_state == CONN_STATE_PORT_SECURE) { + updated |= resumed; err = mt7996_mac_sta_links_event(dev, vif, sta, updated, MT76_STA_EVENT_AUTHORIZE); if (err) return err; } - for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) { + joined = new_links | resumed; + for_each_set_bit(link_id, &joined, IEEE80211_MLD_MAX_NUM_LINKS) { struct mt7996_sta_link *msta_link; struct mt7996_vif_link *link; @@ -1751,7 +1777,7 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif, return err; } - return mt7996_mac_sta_links_ba_add(dev, vif, sta, new_links); + return mt7996_mac_sta_links_ba_add(dev, vif, sta, new_links | resumed); } static void @@ -1825,6 +1851,7 @@ mt7996_mac_sta_change_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&dev->mt76.mutex); + mt7996_mac_sta_links_reset(dev, vif, sta, rem); mt7996_mac_sta_remove_links(dev, vif, sta, rem, false); mt7996_mac_sta_links_bss_add(dev, vif, sta, add); ret = mt7996_mac_sta_add_links(dev, vif, sta, add); From c33af2e4622baafc56c565a13823f6b89d3f50db Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:34 +0200 Subject: [PATCH 1322/2126] wifi: mt76: mt7996: fix PLE free page and AC queue register offsets The PLE register map in the MediaTek vendor driver places the free page counter, the free page head and tail, and the HIF group page status at 0x3a0, 0x3a4 and 0x3a8. The driver reads them at 0x380, 0x384 and 0x388, and the vendor map has the band 1 TXCMD queue empty status at 0x388. The same map has 0x100 bytes per AC for the station queue empty bitmaps, with the MT7992 extension register at offset 0x80. The driver uses 0x80, which cannot hold the 34 registers per AC of MT7996, so the hw-queues file reads AC1 to AC3 of a station from the wrong register. Use the offsets of the vendor register map. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Link: https://patch.msgid.link/20261006205936.669125-25-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/regs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/regs.h b/drivers/net/wireless/mediatek/mt76/mt7996/regs.h index 8ff78cf6eb04..30bec7a0a987 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/regs.h @@ -155,12 +155,12 @@ enum offs_rev { #define MT_FL_Q2_CTRL MT_PLE(0x3e8) #define MT_FL_Q3_CTRL MT_PLE(0x3ec) -#define MT_PLE_FREEPG_CNT MT_PLE(0x380) -#define MT_PLE_FREEPG_HEAD_TAIL MT_PLE(0x384) +#define MT_PLE_FREEPG_CNT MT_PLE(0x3a0) +#define MT_PLE_FREEPG_HEAD_TAIL MT_PLE(0x3a4) #define MT_PLE_PG_HIF_GROUP MT_PLE(0x00c) -#define MT_PLE_HIF_PG_INFO MT_PLE(0x388) +#define MT_PLE_HIF_PG_INFO MT_PLE(0x3a8) -#define MT_PLE_AC_QEMPTY(ac, n) MT_PLE(0x600 + 0x80 * (ac) + ((n) << 2)) +#define MT_PLE_AC_QEMPTY(ac, n) MT_PLE(0x600 + 0x100 * (ac) + ((n) << 2)) #define MT_PLE_AMSDU_PACK_MSDU_CNT(n) MT_PLE(0x10e0 + ((n) << 2)) /* WF MDP TOP */ From ef28298ab88bd7ba8d805fb8dfaaacd9246d5fbf Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 Oct 2026 22:59:35 +0200 Subject: [PATCH 1323/2126] wifi: mt76: mt7996: fix the hw-queues debugfs queue requests The hw-queues debugfs file builds its own queue requests, and these do not match the register map of the MediaTek vendor driver: - The port ID goes to bits 11:10 of the PLE queue control register, but the field is at bits 17:16. Bits 11:10 are part of the WLAN index, so each request reads port 0 and, for a station, the WLAN index with bit 11 set. - The head and tail frame IDs, the packet count and the page counters are read as 12-bit fields, but they have 13 bits. - The PSE queues are read from the PLE empty and queue control registers, with bit positions that do not match the PSE queue map. - The station queues of MT7992 and MT7990 with a WLAN index from 512 to 543 are read from register 16, but these chips keep that group in the extension register at index 32. - The file iterates the stations of the same ieee80211_hw once for each band, so it shows each station queue up to three times. - mt7996_hw_queue_read() takes the private data of the file as a struct mt7996_phy, but it is a struct mt7996_dev. The dev member of the phy then aliases mt76.phy.dev of the device, which points back to the device, so the file works by chance. A queue request also writes the queue control register 0 and then reads the result from the queue control registers 2 and 3, without a lock. When the global and a per-station hw-queues file are read at the same time, one reader can get the result of the request of the other. Describe the PLE and PSE queues in tables with the field layout of the vendor register map, and send all queue requests through one helper, which holds a spinlock from the write of the request to the read of its result. A spinlock is needed because the station requests are sent from ieee80211_iterate_stations_atomic(). Iterate the stations once. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Link: https://patch.msgid.link/20261006205936.669125-26-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../wireless/mediatek/mt76/mt7996/debugfs.c | 319 +++++++++++------- .../net/wireless/mediatek/mt76/mt7996/regs.h | 28 ++ 2 files changed, 230 insertions(+), 117 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c index b85c3e549f8b..644abd0a0216 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c @@ -13,13 +13,6 @@ /** global debugfs **/ -struct hw_queue_map { - const char *name; - u8 index; - u8 pid; - u8 qid; -}; - static int mt7996_implicit_txbf_set(void *data, u64 val) { @@ -604,87 +597,230 @@ mt7996_tx_stats_show(struct seq_file *file, void *data) DEFINE_SHOW_ATTRIBUTE(mt7996_tx_stats); +enum { + MT_QUEUE_PORT_HIF, + MT_QUEUE_PORT_CPU, + MT_QUEUE_PORT_LMAC, + MT_QUEUE_PORT_PLE_CTRL, +}; + +struct mt7996_hw_queue { + const char *name; + u8 pid; + u8 qid; + u8 tgid; +}; + +#define MT7996_HW_QUEUE(_name, _pid, _qid, _tgid) \ + { .name = _name, .pid = MT_QUEUE_PORT_##_pid, .qid = _qid, .tgid = _tgid } + +static const struct mt7996_hw_queue mt7996_ple_queues[32] = { + [0] = MT7996_HW_QUEUE("CPU Q0", CPU, 0, 0), + [1] = MT7996_HW_QUEUE("CPU Q1", CPU, 1, 0), + [2] = MT7996_HW_QUEUE("CPU Q2", CPU, 2, 0), + [3] = MT7996_HW_QUEUE("CPU Q3", CPU, 3, 0), + [4] = MT7996_HW_QUEUE("ALTX Q0", LMAC, 0x10, 0), + [5] = MT7996_HW_QUEUE("BMC Q0", LMAC, 0x11, 0), + [6] = MT7996_HW_QUEUE("BCN Q0", LMAC, 0x12, 0), + [7] = MT7996_HW_QUEUE("PSMP Q0", LMAC, 0x13, 0), + [8] = MT7996_HW_QUEUE("ALTX Q1", LMAC, 0x10, 1), + [9] = MT7996_HW_QUEUE("BMC Q1", LMAC, 0x11, 1), + [10] = MT7996_HW_QUEUE("BCN Q1", LMAC, 0x12, 1), + [11] = MT7996_HW_QUEUE("PSMP Q1", LMAC, 0x13, 1), + [12] = MT7996_HW_QUEUE("ALTX Q2", LMAC, 0x1c, 2), + [13] = MT7996_HW_QUEUE("BMC Q2", LMAC, 0x1d, 2), + [14] = MT7996_HW_QUEUE("BCN Q2", LMAC, 0x1e, 2), + [15] = MT7996_HW_QUEUE("PSMP Q2", LMAC, 0x1f, 2), + [16] = MT7996_HW_QUEUE("NAF Q", LMAC, 0x18, 0), + [17] = MT7996_HW_QUEUE("NBCN Q", LMAC, 0x19, 0), + [20] = MT7996_HW_QUEUE("FIXFID Q", LMAC, 0x1a, 0), + [28] = MT7996_HW_QUEUE("RLS4 Q", PLE_CTRL, 0x7c, 0), + [29] = MT7996_HW_QUEUE("RLS3 Q", PLE_CTRL, 0x7d, 0), + [30] = MT7996_HW_QUEUE("RLS2 Q", PLE_CTRL, 0x7e, 0), + [31] = MT7996_HW_QUEUE("RLS Q", PLE_CTRL, 0x7f, 0), +}; + +static const struct mt7996_hw_queue mt7996_pse_queues[32] = { + [0] = MT7996_HW_QUEUE("CPU Q0", CPU, 0, 0), + [1] = MT7996_HW_QUEUE("CPU Q1", CPU, 1, 0), + [2] = MT7996_HW_QUEUE("CPU Q2", CPU, 2, 0), + [3] = MT7996_HW_QUEUE("CPU Q3", CPU, 3, 0), + [16] = MT7996_HW_QUEUE("LMAC Q", LMAC, 0, 0), + [17] = MT7996_HW_QUEUE("MDP TX Q0", LMAC, 1, 0), + [18] = MT7996_HW_QUEUE("MDP RX Q", LMAC, 2, 0), + [19] = MT7996_HW_QUEUE("SEC TX Q0", LMAC, 3, 0), + [20] = MT7996_HW_QUEUE("SEC RX Q", LMAC, 4, 0), + [21] = MT7996_HW_QUEUE("SFD PARK Q", LMAC, 5, 0), + [22] = MT7996_HW_QUEUE("MDP TXIOC Q0", LMAC, 6, 0), + [23] = MT7996_HW_QUEUE("MDP RXIOC Q0", LMAC, 7, 0), + [24] = MT7996_HW_QUEUE("MDP TX Q1", LMAC, 0x11, 0), + [25] = MT7996_HW_QUEUE("SEC TX Q1", LMAC, 0x13, 0), + [26] = MT7996_HW_QUEUE("MDP TXIOC Q1", LMAC, 0x16, 0), + [27] = MT7996_HW_QUEUE("MDP RXIOC Q1", LMAC, 0x17, 0), + [28] = MT7996_HW_QUEUE("CPU Q4", CPU, 4, 0), + [31] = MT7996_HW_QUEUE("RLS Q", PLE_CTRL, 0x1f, 0), +}; + +static const struct mt7996_hw_queue mt7996_pse_queues_1[32] = { + [0] = MT7996_HW_QUEUE("MDP TDPIOC Q0", LMAC, 0x08, 0), + [1] = MT7996_HW_QUEUE("MDP RDPIOC Q0", LMAC, 0x09, 0), + [2] = MT7996_HW_QUEUE("MDP TDPIOC Q1", LMAC, 0x18, 0), + [3] = MT7996_HW_QUEUE("MDP RDPIOC Q1", LMAC, 0x19, 0), + [4] = MT7996_HW_QUEUE("MDP TDPIOC Q2", LMAC, 0x28, 0), + [5] = MT7996_HW_QUEUE("MDP RDPIOC Q2", LMAC, 0x29, 0), + [7] = MT7996_HW_QUEUE("MDP RDPIOC Q3", LMAC, 0x39, 0), + [8] = MT7996_HW_QUEUE("MDP TX Q2", LMAC, 0x21, 0), + [9] = MT7996_HW_QUEUE("SEC TX Q2", LMAC, 0x23, 0), + [10] = MT7996_HW_QUEUE("MDP TXIOC Q2", LMAC, 0x26, 0), + [11] = MT7996_HW_QUEUE("MDP RXIOC Q2", LMAC, 0x27, 0), + [15] = MT7996_HW_QUEUE("MDP RXIOC Q3", LMAC, 0x37, 0), + [16] = MT7996_HW_QUEUE("HIF Q0", HIF, 0, 0), + [17] = MT7996_HW_QUEUE("HIF Q1", HIF, 1, 0), + [18] = MT7996_HW_QUEUE("HIF Q2", HIF, 2, 0), + [19] = MT7996_HW_QUEUE("HIF Q3", HIF, 3, 0), + [20] = MT7996_HW_QUEUE("HIF Q4", HIF, 4, 0), + [21] = MT7996_HW_QUEUE("HIF Q5", HIF, 5, 0), + [22] = MT7996_HW_QUEUE("HIF Q6", HIF, 6, 0), + [23] = MT7996_HW_QUEUE("HIF Q7", HIF, 7, 0), + [24] = MT7996_HW_QUEUE("HIF Q8", HIF, 8, 0), + [25] = MT7996_HW_QUEUE("HIF Q9", HIF, 9, 0), + [26] = MT7996_HW_QUEUE("HIF Q10", HIF, 10, 0), + [27] = MT7996_HW_QUEUE("HIF Q11", HIF, 11, 0), + [28] = MT7996_HW_QUEUE("HIF Q12", HIF, 12, 0), + [29] = MT7996_HW_QUEUE("HIF Q13", HIF, 13, 0), +}; + static void -mt7996_hw_queue_read(struct seq_file *s, u32 size, - const struct hw_queue_map *map) +mt7996_fl_queue_show(struct seq_file *s, struct mt7996_dev *dev, bool pse, + const struct mt7996_hw_queue *q, u16 wlan_idx) { - struct mt7996_phy *phy = s->private; - struct mt7996_dev *dev = phy->dev; - u32 i, val; + static DEFINE_SPINLOCK(lock); + u32 val, fid, num; - val = mt76_rr(dev, MT_FL_Q_EMPTY); - for (i = 0; i < size; i++) { - u32 ctrl, head, tail, queued; + val = MT_FL_Q0_CTRL_EXECUTE | + u32_encode_bits(q->qid, MT_FL_Q0_CTRL_QID) | + u32_encode_bits(q->tgid, MT_FL_Q0_CTRL_TGID) | + u32_encode_bits(q->pid, MT_FL_Q0_CTRL_PID) | + u32_encode_bits(wlan_idx, MT_FL_Q0_CTRL_WLAN_IDX); - if (val & BIT(map[i].index)) + spin_lock(&lock); + mt76_wr(dev, pse ? MT_PSE_FL_Q0_CTRL : MT_FL_Q0_CTRL, val); + fid = mt76_rr(dev, pse ? MT_PSE_FL_Q2_CTRL : MT_FL_Q2_CTRL); + num = mt76_rr(dev, pse ? MT_PSE_FL_Q3_CTRL : MT_FL_Q3_CTRL); + spin_unlock(&lock); + + seq_printf(s, "tail/head fid 0x%04x/0x%04x, packets %u", + u32_get_bits(fid, MT_FL_Q2_CTRL_TAIL_FID), + u32_get_bits(fid, MT_FL_Q2_CTRL_HEAD_FID), + u32_get_bits(num, MT_FL_Q3_CTRL_PKT_NUM)); +} + +static void +mt7996_fl_queues_show(struct seq_file *s, struct mt7996_dev *dev, bool pse, + const struct mt7996_hw_queue *queues, unsigned long empty) +{ + unsigned int i; + + for_each_clear_bit(i, &empty, 32) { + if (!queues[i].name) continue; - ctrl = BIT(31) | (map[i].pid << 10) | ((u32)map[i].qid << 24); - mt76_wr(dev, MT_FL_Q0_CTRL, ctrl); - - head = mt76_get_field(dev, MT_FL_Q2_CTRL, - GENMASK(11, 0)); - tail = mt76_get_field(dev, MT_FL_Q2_CTRL, - GENMASK(27, 16)); - queued = mt76_get_field(dev, MT_FL_Q3_CTRL, - GENMASK(11, 0)); - - seq_printf(s, "\t%s: ", map[i].name); - seq_printf(s, "queued:0x%03x head:0x%03x tail:0x%03x\n", - queued, head, tail); + seq_printf(s, "\t%s: ", queues[i].name); + mt7996_fl_queue_show(s, dev, pse, &queues[i], 0); + seq_puts(s, "\n"); } } +static void +mt7996_freepg_show(struct seq_file *s, u32 cnt, u32 head_tail) +{ + seq_printf(s, "\tfree pages 0x%04x, free for all 0x%04x, head/tail 0x%04x/0x%04x\n", + u32_get_bits(cnt, MT_FREEPG_CNT_FREE), + u32_get_bits(cnt, MT_FREEPG_CNT_FFA), + u32_get_bits(head_tail, MT_FREEPG_HEAD_TAIL_HEAD), + u32_get_bits(head_tail, MT_FREEPG_HEAD_TAIL_TAIL)); +} + +static void +mt7996_pg_group_show(struct seq_file *s, const char *name, u32 group, u32 info) +{ + seq_printf(s, "\t%s group: max/min quota 0x%04x/0x%04x, used/reserved 0x%04x/0x%04x\n", + name, u32_get_bits(group, MT_PG_GROUP_MAX_QUOTA), + u32_get_bits(group, MT_PG_GROUP_MIN_QUOTA), + u32_get_bits(info, MT_PG_INFO_SRC_CNT), + u32_get_bits(info, MT_PG_INFO_RSV_CNT)); +} + +static unsigned int +mt7996_ple_sta_cr_num(struct mt7996_dev *dev) +{ + return is_mt7996(&dev->mt76) ? 34 : 17; +} + +static unsigned int +mt7996_ple_sta_cr(struct mt7996_dev *dev, unsigned int n) +{ + /* MT7992 and MT7990 keep the last station group in the + * extension register that follows the first 32 groups + */ + if (!is_mt7996(&dev->mt76) && n == mt7996_ple_sta_cr_num(dev) - 1) + return 32; + + return n; +} + static void mt7996_sta_hw_queue_read(void *data, struct ieee80211_sta *sta) { struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; struct mt7996_vif *mvif = msta->vif; - struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink); struct ieee80211_link_sta *link_sta; struct seq_file *s = data; struct ieee80211_vif *vif; - struct mt7996_dev *dev; unsigned int link_id; - if (!phy) - return; - vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv); - dev = phy->dev; rcu_read_lock(); for_each_sta_active_link(vif, sta, link_sta, link_id) { struct mt7996_sta_link *msta_link; struct mt76_vif_link *mlink; + struct mt7996_phy *phy; + unsigned int cr; + u16 wlan_idx; u8 ac; mlink = rcu_dereference(mvif->mt76.link[link_id]); if (!mlink) continue; + phy = mt7996_vif_link_phy(container_of(mlink, + struct mt7996_vif_link, + mt76)); + if (!phy) + continue; + msta_link = mt7996_sta_link(msta, link_id); if (!msta_link) continue; - for (ac = 0; ac < 4; ac++) { - u32 idx = msta_link->wcid.idx >> 5, qlen, ctrl, val; - u8 offs = msta_link->wcid.idx & GENMASK(4, 0); + wlan_idx = msta_link->wcid.idx; + cr = mt7996_ple_sta_cr(phy->dev, wlan_idx / 32); + for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { + struct mt7996_hw_queue q = { + .pid = MT_QUEUE_PORT_LMAC, + .qid = ac, + }; - ctrl = BIT(31) | BIT(11) | (ac << 24); - val = mt76_rr(dev, MT_PLE_AC_QEMPTY(ac, idx)); - - if (val & BIT(offs)) + if (mt76_rr(phy->dev, MT_PLE_AC_QEMPTY(ac, cr)) & + BIT(wlan_idx % 32)) continue; - mt76_wr(dev, - MT_FL_Q0_CTRL, ctrl | msta_link->wcid.idx); - qlen = mt76_get_field(dev, MT_FL_Q3_CTRL, - GENMASK(11, 0)); - seq_printf(s, "\tSTA %pM wcid %d: AC%d%d queued:%d\n", - sta->addr, msta_link->wcid.idx, - mlink->wmm_idx, ac, qlen); + seq_printf(s, "\tSTA %pM wcid %u AC%u%u: ", sta->addr, + wlan_idx, mlink->wmm_idx, ac); + mt7996_fl_queue_show(s, phy->dev, false, &q, wlan_idx); + seq_puts(s, "\n"); } } @@ -692,78 +828,27 @@ mt7996_sta_hw_queue_read(void *data, struct ieee80211_sta *sta) } static int -mt7996_hw_queues_show(struct seq_file *file, void *data) +mt7996_hw_queues_show(struct seq_file *s, void *data) { - struct mt7996_dev *dev = file->private; - struct mt7996_phy *phy = &dev->phy; - static const struct hw_queue_map ple_queue_map[] = { - { "CPU_Q0", 0, 1, MT_CTX0 }, - { "CPU_Q1", 1, 1, MT_CTX0 + 1 }, - { "CPU_Q2", 2, 1, MT_CTX0 + 2 }, - { "CPU_Q3", 3, 1, MT_CTX0 + 3 }, - { "ALTX_Q0", 8, 2, MT_LMAC_ALTX0 }, - { "BMC_Q0", 9, 2, MT_LMAC_BMC0 }, - { "BCN_Q0", 10, 2, MT_LMAC_BCN0 }, - { "PSMP_Q0", 11, 2, MT_LMAC_PSMP0 }, - { "ALTX_Q1", 12, 2, MT_LMAC_ALTX0 + 4 }, - { "BMC_Q1", 13, 2, MT_LMAC_BMC0 + 4 }, - { "BCN_Q1", 14, 2, MT_LMAC_BCN0 + 4 }, - { "PSMP_Q1", 15, 2, MT_LMAC_PSMP0 + 4 }, - }; - static const struct hw_queue_map pse_queue_map[] = { - { "CPU Q0", 0, 1, MT_CTX0 }, - { "CPU Q1", 1, 1, MT_CTX0 + 1 }, - { "CPU Q2", 2, 1, MT_CTX0 + 2 }, - { "CPU Q3", 3, 1, MT_CTX0 + 3 }, - { "HIF_Q0", 8, 0, MT_HIF0 }, - { "HIF_Q1", 9, 0, MT_HIF0 + 1 }, - { "HIF_Q2", 10, 0, MT_HIF0 + 2 }, - { "HIF_Q3", 11, 0, MT_HIF0 + 3 }, - { "HIF_Q4", 12, 0, MT_HIF0 + 4 }, - { "HIF_Q5", 13, 0, MT_HIF0 + 5 }, - { "LMAC_Q", 16, 2, 0 }, - { "MDP_TXQ", 17, 2, 1 }, - { "MDP_RXQ", 18, 2, 2 }, - { "SEC_TXQ", 19, 2, 3 }, - { "SEC_RXQ", 20, 2, 4 }, - }; - u32 val, head, tail; + struct mt7996_dev *dev = s->private; - /* ple queue */ - val = mt76_rr(dev, MT_PLE_FREEPG_CNT); - head = mt76_get_field(dev, MT_PLE_FREEPG_HEAD_TAIL, GENMASK(11, 0)); - tail = mt76_get_field(dev, MT_PLE_FREEPG_HEAD_TAIL, GENMASK(27, 16)); - seq_puts(file, "PLE page info:\n"); - seq_printf(file, - "\tTotal free page: 0x%08x head: 0x%03x tail: 0x%03x\n", - val, head, tail); + seq_puts(s, "PLE page info:\n"); + mt7996_freepg_show(s, mt76_rr(dev, MT_PLE_FREEPG_CNT), + mt76_rr(dev, MT_PLE_FREEPG_HEAD_TAIL)); + mt7996_pg_group_show(s, "HIF", mt76_rr(dev, MT_PLE_PG_HIF_GROUP), + mt76_rr(dev, MT_PLE_HIF_PG_INFO)); - val = mt76_rr(dev, MT_PLE_PG_HIF_GROUP); - head = mt76_get_field(dev, MT_PLE_HIF_PG_INFO, GENMASK(11, 0)); - tail = mt76_get_field(dev, MT_PLE_HIF_PG_INFO, GENMASK(27, 16)); - seq_printf(file, "\tHIF free page: 0x%03x res: 0x%03x used: 0x%03x\n", - val, head, tail); + seq_puts(s, "PLE non-empty queue info:\n"); + mt7996_fl_queues_show(s, dev, false, mt7996_ple_queues, + mt76_rr(dev, MT_FL_Q_EMPTY)); + ieee80211_iterate_stations_atomic(dev->mphy.hw, + mt7996_sta_hw_queue_read, s); - seq_puts(file, "PLE non-empty queue info:\n"); - mt7996_hw_queue_read(file, ARRAY_SIZE(ple_queue_map), - &ple_queue_map[0]); - - /* iterate per-sta ple queue */ - ieee80211_iterate_stations_atomic(phy->mt76->hw, - mt7996_sta_hw_queue_read, file); - phy = mt7996_phy2(dev); - if (phy) - ieee80211_iterate_stations_atomic(phy->mt76->hw, - mt7996_sta_hw_queue_read, file); - phy = mt7996_phy3(dev); - if (phy) - ieee80211_iterate_stations_atomic(phy->mt76->hw, - mt7996_sta_hw_queue_read, file); - - /* pse queue */ - seq_puts(file, "PSE non-empty queue info:\n"); - mt7996_hw_queue_read(file, ARRAY_SIZE(pse_queue_map), - &pse_queue_map[0]); + seq_puts(s, "PSE non-empty queue info:\n"); + mt7996_fl_queues_show(s, dev, true, mt7996_pse_queues, + mt76_rr(dev, MT_PSE_QUEUE_EMPTY)); + mt7996_fl_queues_show(s, dev, true, mt7996_pse_queues_1, + mt76_rr(dev, MT_PSE_QUEUE_EMPTY_1)); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/regs.h b/drivers/net/wireless/mediatek/mt76/mt7996/regs.h index 30bec7a0a987..6df6e4c3d45d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/regs.h @@ -155,6 +155,15 @@ enum offs_rev { #define MT_FL_Q2_CTRL MT_PLE(0x3e8) #define MT_FL_Q3_CTRL MT_PLE(0x3ec) +#define MT_FL_Q0_CTRL_EXECUTE BIT(31) +#define MT_FL_Q0_CTRL_QID GENMASK(30, 24) +#define MT_FL_Q0_CTRL_TGID GENMASK(21, 20) +#define MT_FL_Q0_CTRL_PID GENMASK(17, 16) +#define MT_FL_Q0_CTRL_WLAN_IDX GENMASK(11, 0) +#define MT_FL_Q2_CTRL_TAIL_FID GENMASK(28, 16) +#define MT_FL_Q2_CTRL_HEAD_FID GENMASK(12, 0) +#define MT_FL_Q3_CTRL_PKT_NUM GENMASK(12, 0) + #define MT_PLE_FREEPG_CNT MT_PLE(0x3a0) #define MT_PLE_FREEPG_HEAD_TAIL MT_PLE(0x3a4) #define MT_PLE_PG_HIF_GROUP MT_PLE(0x00c) @@ -163,6 +172,25 @@ enum offs_rev { #define MT_PLE_AC_QEMPTY(ac, n) MT_PLE(0x600 + 0x100 * (ac) + ((n) << 2)) #define MT_PLE_AMSDU_PACK_MSDU_CNT(n) MT_PLE(0x10e0 + ((n) << 2)) +#define MT_FREEPG_CNT_FFA GENMASK(28, 16) +#define MT_FREEPG_CNT_FREE GENMASK(12, 0) +#define MT_FREEPG_HEAD_TAIL_TAIL GENMASK(28, 16) +#define MT_FREEPG_HEAD_TAIL_HEAD GENMASK(12, 0) +#define MT_PG_GROUP_MAX_QUOTA GENMASK(28, 16) +#define MT_PG_GROUP_MIN_QUOTA GENMASK(12, 0) +#define MT_PG_INFO_SRC_CNT GENMASK(28, 16) +#define MT_PG_INFO_RSV_CNT GENMASK(12, 0) + +/* PSE */ +#define MT_PSE_BASE 0x820c8000 +#define MT_PSE(ofs) (MT_PSE_BASE + (ofs)) + +#define MT_PSE_QUEUE_EMPTY MT_PSE(0x0b0) +#define MT_PSE_QUEUE_EMPTY_1 MT_PSE(0x0bc) +#define MT_PSE_FL_Q0_CTRL MT_PSE(0x1b0) +#define MT_PSE_FL_Q2_CTRL MT_PSE(0x1b8) +#define MT_PSE_FL_Q3_CTRL MT_PSE(0x1bc) + /* WF MDP TOP */ #define MT_MDP_BASE 0x820cc000 #define MT_MDP(ofs) (MT_MDP_BASE + (ofs)) From 7a5a3843178c61d99d939b231318692d08fff79b Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 6 Oct 2026 22:59:36 +0200 Subject: [PATCH 1324/2126] wifi: mt76: mt7996: disable the RX NAPIs before the DMA cleanup mt7996_unregister_device() leaves the RX NAPIs enabled, so mt76_dma_cleanup() deletes enabled NAPIs and destroys page pools that are still bound to them. On rmmod, the kernel warns in __netif_napi_del_locked() for every RX queue and in page_pool_disable_direct_recycling(). Until the IRQ tasklet is disabled, an interrupt can still schedule a NAPI that was already deleted. Disable every RX NAPI that was added before the MCU exit and the DMA cleanup. This includes the host RRO queues: mt76_dma_init() skips them, but mt7996_dma_rro_start() adds their NAPIs later when WED is not active, so a check for mt76_queue_is_wed_rro() would miss them. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Signed-off-by: John Crispin Link: https://patch.msgid.link/20261006205936.669125-27-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index 2db63c3be9d1..ad9919c516e7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -1810,6 +1810,8 @@ error: void mt7996_unregister_device(struct mt7996_dev *dev) { + int i; + cancel_work_sync(&dev->dump_work); cancel_work_sync(&dev->wed_rro.work); cancel_work_sync(&dev->reset_work); @@ -1820,6 +1822,10 @@ void mt7996_unregister_device(struct mt7996_dev *dev) mt7996_coredump_unregister(dev); mt76_unregister_device(&dev->mt76); mt7996_wed_rro_free(dev); + for (i = 0; i < ARRAY_SIZE(dev->mt76.napi); i++) { + if (dev->mt76.napi[i].dev) + napi_disable(&dev->mt76.napi[i]); + } mt7996_mcu_exit(dev); mt7996_tx_token_put(dev); mt7996_dma_cleanup(dev); From 3807d0bfeef650d2b3b567e36d218b4cb3e31d4b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:11 +0200 Subject: [PATCH 1325/2126] wifi: mt76: mt7996: refuse scan and ROC until the hardware restart is done mt7996_mac_restart() clears MT76_MCU_RESET before it loads the firmware again, and mac80211 adds the interfaces back only later, in ieee80211_reconfig() after ieee80211_restart_hw(). A scan or remain on channel that reaches mt76_hw_scan() or mt76_remain_on_channel() in between, for example a request that waited for dev->mutex during the reset, runs on a device that has no interfaces configured. Mark a full reset with MT76_RESTART and refuse a scan or remain on channel while it is set. Clear the flag in .start: ieee80211_reconfig() adds the interfaces back before it releases the wiphy lock, so no request runs in between. .reconfig_complete is not suitable, because mac80211 skips it when no interface is open, and the flag would then stay set. Fixes: c56d6edebc1f ("wifi: mt76: mt7996: use emulated hardware scan support") Fixes: 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy") Link: https://patch.msgid.link/20261007112419.1277594-1-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 3 ++- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 1 + drivers/net/wireless/mediatek/mt76/mt7996/main.c | 2 ++ drivers/net/wireless/mediatek/mt76/scan.c | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 8d4daa76be54..ce1824da7563 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -382,7 +382,8 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&dev->mutex); if (phy->roc_vif || dev->scan.phy == phy || - test_bit(MT76_MCU_RESET, &dev->phy.state)) { + test_bit(MT76_MCU_RESET, &dev->phy.state) || + test_bit(MT76_RESTART, &dev->phy.state)) { ret = -EBUSY; goto out; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index c4e82b1e259c..ce1e4773bddd 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -2467,6 +2467,7 @@ mt7996_mac_full_reset(struct mt7996_dev *dev) dev->recovery.hw_full_reset = true; + set_bit(MT76_RESTART, &dev->mphy.state); set_bit(MT76_MCU_RESET, &dev->mphy.state); wake_up(&dev->mt76.mcu.wait); ieee80211_stop_queues(hw); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c index 9965ac136bec..d37bd9efde79 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c @@ -59,6 +59,8 @@ static int mt7996_start(struct ieee80211_hw *hw) flush_work(&dev->init_work); + clear_bit(MT76_RESTART, &dev->mphy.state); + mutex_lock(&dev->mt76.mutex); ret = mt7996_mcu_set_hdr_trans(dev, true); if (!ret && !is_mt7996(&dev->mt76)) { diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c index c8c4d096c809..7bf9b7d4a8d7 100644 --- a/drivers/net/wireless/mediatek/mt76/scan.c +++ b/drivers/net/wireless/mediatek/mt76/scan.c @@ -216,7 +216,8 @@ int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&dev->mutex); if (dev->scan.req || phy->roc_vif || - test_bit(MT76_MCU_RESET, &dev->phy.state)) { + test_bit(MT76_MCU_RESET, &dev->phy.state) || + test_bit(MT76_RESTART, &dev->phy.state)) { ret = -EBUSY; goto out; } From a45aea434cd7e0b4c3cea5a0ca4ebc54a6388a1c Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:12 +0200 Subject: [PATCH 1326/2126] wifi: mt76: report an aborted scan or ROC to mac80211 during a reset mt7996_mac_full_reset() and the L1 SER branch of mt7996_mac_reset_work() abort a running scan and remain on channel. mt76_scan_complete() and mt76_roc_complete() then skip ieee80211_scan_completed() and ieee80211_remain_on_channel_expired() while MT76_MCU_RESET is set. mac80211 clears a hardware scan only from the completion. After an L1 SER recovery, which does not restart the hardware, every later scan on the wiphy is then refused, and a remain on channel stays pending until userspace cancels it. After a full reset, ieee80211_restart_work() warns: WARN(test_bit(SCAN_HW_SCANNING, &local->scanning), "%s called with hardware scan in progress\n", __func__); Report an aborted scan to mac80211 in a reset as well, and an aborted remain on channel unless a hardware restart follows. On a restart, ieee80211_reconfig_roc() restarts a remain on channel that had not begun and ends one that had. Since the scan is reported as aborted, mac80211 does not continue it on the next band during the reset. Fixes: b36d55610215 ("wifi: mt76: abort scan/roc on hw restart") Link: https://patch.msgid.link/20261007112419.1277594-2-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 2 +- drivers/net/wireless/mediatek/mt76/scan.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index ce1824da7563..243d252e7644 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -336,7 +336,7 @@ void mt76_roc_complete(struct mt76_phy *phy) mt76_put_vif_phy_link(phy, phy->roc_vif, phy->roc_link); phy->roc_vif = NULL; phy->roc_link = NULL; - if (!test_bit(MT76_MCU_RESET, &dev->phy.state)) + if (!test_bit(MT76_RESTART, &dev->phy.state)) ieee80211_remain_on_channel_expired(phy->hw); } diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c index 7bf9b7d4a8d7..4a5cdb4efc61 100644 --- a/drivers/net/wireless/mediatek/mt76/scan.c +++ b/drivers/net/wireless/mediatek/mt76/scan.c @@ -39,8 +39,7 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort) } mt76_put_vif_phy_link(phy, dev->scan.vif, dev->scan.mlink); memset(&dev->scan, 0, sizeof(dev->scan)); - if (!test_bit(MT76_MCU_RESET, &dev->phy.state)) - ieee80211_scan_completed(phy->hw, &info); + ieee80211_scan_completed(phy->hw, &info); } void mt76_abort_scan(struct mt76_dev *dev) From 2f209a8dca88507bc094de370e582adefc55723e Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:13 +0200 Subject: [PATCH 1327/2126] wifi: mt76: mt7921: fix of_node reference leaks in regd update mt7921_regd_channel_update() and __mt7921_mcu_set_clc() never release the nodes returned by mt76_find_power_limits_node(), of_get_child_by_name() and mt76_find_channel_node(). Each regulatory domain change and each CLC update on a device with DT power limits leaks these references. Release every node after use. This relies on mt76_find_power_limits_node() also returning a reference for the fallback node, which it does since commit 3a62c9f7ec3d ("wifi: mt76: Fix of_node reference leak in mt76_get_rate_power_limits()"). Fixes: 09382d8f8641 ("wifi: mt76: mt7921: update the channel usage when the regd domain changed") Link: https://patch.msgid.link/20261007112419.1277594-3-nbd@nbd.name Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7921/mcu.c | 7 ++++- .../net/wireless/mediatek/mt76/mt7921/regd.c | 28 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c index bdeb6614a5a9..25638c68c468 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -3,6 +3,7 @@ #include #include +#include #include "mt7921.h" #include "regd.h" #include "mcu.h" @@ -1363,6 +1364,7 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, .acpi_conf = mt792x_acpi_get_flags(&dev->phy), .mtcl_conf = mt792x_acpi_get_mtcl_conf(&dev->phy, alpha2), }; + struct device_node *np; int ret, valid_cnt = 0; u32 buf_len = 0; u8 *pos; @@ -1372,8 +1374,11 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, if (dev->phy.chip_cap & MT792x_CHIP_CAP_CLC_EVT_EN) req.cap |= CLC_CAP_EVT_EN; - if (mt76_find_power_limits_node(&dev->mt76)) + + np = mt76_find_power_limits_node(&dev->mt76); + if (np) req.cap |= CLC_CAP_DTS_EN; + of_node_put(np); buf_len = le32_to_cpu(clc->len) - sizeof(*clc); pos = clc->data; diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c index fcdeb65cd8ef..699617d9e48f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c @@ -28,6 +28,21 @@ bool mt7921_regd_clc_supported(struct mt792x_dev *dev) return true; } +static bool +mt7921_regd_dt_has_channel(struct device_node *band_np, + struct ieee80211_channel *ch) +{ + struct device_node *chan_np; + + if (!band_np) + return false; + + chan_np = mt76_find_channel_node(band_np, ch); + of_node_put(chan_np); + + return !!chan_np; +} + static void mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) { @@ -43,14 +58,14 @@ mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) sband = wiphy->bands[NL80211_BAND_5GHZ]; if (!sband) - return; + goto out; band_np = np ? of_get_child_by_name(np, "txpower-5g") : NULL; for (i = 0; i < sband->n_channels; i++) { ch = &sband->channels[i]; cfreq = ch->center_freq; - if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) { + if (np && !mt7921_regd_dt_has_channel(band_np, ch)) { ch->flags |= IEEE80211_CHAN_DISABLED; continue; } @@ -59,17 +74,18 @@ mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) if (IS_UNII_INVALID(0, 5845, 5925)) ch->flags |= IEEE80211_CHAN_DISABLED; } + of_node_put(band_np); sband = wiphy->bands[NL80211_BAND_6GHZ]; if (!sband) - return; + goto out; band_np = np ? of_get_child_by_name(np, "txpower-6g") : NULL; for (i = 0; i < sband->n_channels; i++) { ch = &sband->channels[i]; cfreq = ch->center_freq; - if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) { + if (np && !mt7921_regd_dt_has_channel(band_np, ch)) { ch->flags |= IEEE80211_CHAN_DISABLED; continue; } @@ -81,6 +97,10 @@ mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) IS_UNII_INVALID(4, 6875, 7125)) ch->flags |= IEEE80211_CHAN_DISABLED; } + of_node_put(band_np); + +out: + of_node_put(np); } int __mt7921_mcu_regd_update(struct mt792x_dev *dev, u8 *alpha2, From 2d12f56631ef307e58651b560ccda1f324a059f9 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:14 +0200 Subject: [PATCH 1328/2126] wifi: mt76: mt792x: compute the assoc RSSI from the chain signals mt792x_mac_rssi_iter() adds status->signal of auth and assoc response frames to the BSS RSSI average, which mt7921_mcu_sta_update() and mt7925_mcu_sta_update() send to the firmware as the station RCPI. mt7925 never sets status->signal, since mt76_rx_convert() computes it from the chain values later. The average is thus fed 0 dBm on mt7925. Compute the signal from the chain values, as mt76_rx_convert() and mt76_check_sta() do, and skip a frame without a valid chain signal. On mt7921, the average now follows the combined value instead of the strongest chain. Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Link: https://patch.msgid.link/20261007112419.1277594-4-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt792x_mac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_mac.c b/drivers/net/wireless/mediatek/mt76/mt792x_mac.c index 1e20b333cc61..ebf4c32924c4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_mac.c @@ -165,14 +165,16 @@ mt792x_mac_rssi_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb); + int signal; - if (status->signal > 0) + signal = mt76_rx_signal(status->chains, status->chain_signal); + if (signal > 0 || signal <= -128) return; if (!ether_addr_equal(vif->addr, hdr->addr1)) return; - ewma_rssi_add(&mvif->bss_conf.rssi, -status->signal); + ewma_rssi_add(&mvif->bss_conf.rssi, -signal); } void mt792x_mac_assoc_rssi(struct mt792x_dev *dev, struct sk_buff *skb) From 557a895d92f5b2b738fa60844799d96b23cfc08f Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:15 +0200 Subject: [PATCH 1329/2126] wifi: mt76: remove the unused signal field from struct mt76_rx_status mt76_rx_convert() computes the signal for mac80211 from the chain signals and overwrites the value of the signal field of struct mt76_rx_status. Since mt792x_mac_rssi_iter() also uses the chain signals, no code reads the field. mt7921_mac_fill_rx() is the last driver that still sets it. Remove the field and its computation in mt7921_mac_fill_rx(). Link: https://patch.msgid.link/20261007112419.1277594-5-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 1 - drivers/net/wireless/mediatek/mt76/mt76.h | 1 - drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 11 +---------- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 48349bbc5a8f..2584c0e2a2c9 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1297,7 +1297,6 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb, status->rate_idx = mstat.rate_idx; status->nss = mstat.nss; status->band = mstat.band; - status->signal = mstat.signal; status->chains = mstat.chains; status->ampdu_reference = mstat.ampdu_ref; status->device_timestamp = mstat.timestamp; diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index e9bbec1269fa..93576472f5af 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -767,7 +767,6 @@ struct mt76_rx_status { u8 amsdu:1, first_amsdu:1, last_amsdu:1; u8 rate_idx; u8 nss:5, band:3; - s8 signal; u8 chains; s8 chain_signal[IEEE80211_MAX_CHAINS]; }; diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index ad1352ddf1fc..6f5e31489e2d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -188,7 +188,7 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) u16 seq_ctrl = 0; __le16 fc = 0; u8 mode = 0; - int i, idx; + int idx; memset(status, 0, sizeof(*status)); @@ -368,15 +368,6 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v1); status->chain_signal[2] = to_rssi(MT_PRXV_RCPI2, v1); status->chain_signal[3] = to_rssi(MT_PRXV_RCPI3, v1); - status->signal = -128; - for (i = 0; i < hweight8(mphy->antenna_mask); i++) { - if (!(status->chains & BIT(i)) || - status->chain_signal[i] >= 0) - continue; - - status->signal = max(status->signal, - status->chain_signal[i]); - } } amsdu_info = FIELD_GET(MT_RXD4_NORMAL_PAYLOAD_FORMAT, rxd4); From 833de192a443659de3bf77555523c58727bb153d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:16 +0200 Subject: [PATCH 1330/2126] wifi: mt76: mt7996: take the offchannel link of a frame from its wcid mt7996_mac_write_txwi() and mt7996_tx_prepare_skb() take the own MAC, WMM and band index of an offchannel frame from mvif->offchannel_link, which holds one link per vif. mac80211 runs one scan or remain on channel at a time, so a vif has at most one offchannel link today. A scan that runs on several radios at the same time needs one offchannel link per radio, and its frames would then be sent with the indexes of whichever link was added last. Each offchannel link has its own wcid, and offchannel frames are sent on it, so take the link from the wcid of the frame. Drop offchannel_link, which has no other user. Link: https://patch.msgid.link/20261007112419.1277594-6-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 5 ----- drivers/net/wireless/mediatek/mt76/mt76.h | 1 - drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 4 ++-- drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 12 ++++++++++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 243d252e7644..75f0db3bc4f0 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -295,7 +295,6 @@ struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy, kfree(mlink); return ERR_PTR(ret); } - rcu_assign_pointer(mvif->offchannel_link, mlink); return mlink; } @@ -304,14 +303,10 @@ void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif, struct mt76_vif_link *mlink) { struct mt76_dev *dev = phy->dev; - struct mt76_vif_data *mvif; if (IS_ERR_OR_NULL(mlink) || !mlink->offchannel) return; - mvif = mlink->mvif; - - rcu_assign_pointer(mvif->offchannel_link, NULL); dev->drv->vif_link_remove(phy, vif, &vif->bss_conf, mlink); kfree_rcu(mlink, rcu_head); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 93576472f5af..09b9507250f9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -846,7 +846,6 @@ struct mt76_vif_link { struct mt76_vif_data { struct mt76_vif_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS]; - struct mt76_vif_link __rcu *offchannel_link; struct mt76_phy *roc_phy; u16 valid_links; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index ce1e4773bddd..f36da545045b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -915,7 +915,7 @@ void mt7996_mac_write_txwi(struct mt7996_dev *dev, __le32 *txwi, mvif = vif ? (struct mt7996_vif *)vif->drv_priv : NULL; if (mvif) { if (wcid->offchannel) - mlink = rcu_dereference(mvif->mt76.offchannel_link); + mlink = mt7996_offchannel_link(wcid); if (!mlink && link_id != IEEE80211_LINK_UNSPECIFIED) mlink = rcu_dereference(mvif->mt76.link[link_id]); } @@ -1196,7 +1196,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, if (mvif) { if (wcid->offchannel) - mlink = rcu_dereference(mvif->mt76.offchannel_link); + mlink = mt7996_offchannel_link(wcid); if (!mlink) mlink = rcu_dereference(mvif->mt76.link[wcid->link_id]); diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index ae97ca091673..da9958647b54 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -659,6 +659,18 @@ mt7996_vif_conf_link(struct mt7996_dev *dev, struct ieee80211_vif *vif, link_conf); } +static inline struct mt76_vif_link * +mt7996_offchannel_link(struct mt76_wcid *wcid) +{ + struct mt7996_sta_link *msta_link; + struct mt7996_vif_link *link; + + msta_link = container_of(wcid, struct mt7996_sta_link, wcid); + link = container_of(msta_link, struct mt7996_vif_link, msta_link); + + return &link->mt76; +} + static inline struct mt7996_sta_link * mt7996_sta_link(struct mt7996_sta *msta, u8 link_id) { From 3049a7f210adaa633e834a7e9e0fd3c6cf8600b4 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 7 Oct 2026 13:24:17 +0200 Subject: [PATCH 1331/2126] wifi: mt76: scan all radios of a request at the same time A device with several radios on one wiphy has one scan state for the whole device, and mt76_hw_scan() picks the radio from the band of the first channel. A scan therefore covers one radio, and mac80211 visits the bands one after another. Run the scan on every radio that has a channel in the request, and let each radio visit only its own channels. Report the scan as complete once all radios are done, and as aborted if any of them aborted. Build the probe request from the IEs of the band of the channel and the common IEs, because a request can now hold the IEs of several bands. A driver can now set SINGLE_SCAN_ON_ALL_BANDS to scan all of its radios in parallel with one request. Signed-off-by: John Crispin Link: https://patch.msgid.link/20261007112419.1277594-7-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 12 +- drivers/net/wireless/mediatek/mt76/mac80211.c | 4 +- drivers/net/wireless/mediatek/mt76/mt76.h | 27 ++- drivers/net/wireless/mediatek/mt76/scan.c | 215 ++++++++++++------ 4 files changed, 173 insertions(+), 85 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 75f0db3bc4f0..192276cf19fd 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -41,7 +41,7 @@ int mt76_add_chanctx(struct ieee80211_hw *hw, if (WARN_ON_ONCE(!phy)) return ret; - if (dev->scan.phy == phy) + if (mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -66,7 +66,7 @@ void mt76_remove_chanctx(struct ieee80211_hw *hw, if (WARN_ON_ONCE(!phy)) return; - if (dev->scan.phy == phy) + if (mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -114,7 +114,7 @@ int mt76_assign_vif_chanctx(struct ieee80211_hw *hw, bool mlink_alloc = false; int ret = 0; - if (dev->scan.vif == vif && dev->scan.phy == phy) + if (dev->scan.vif == vif && mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -161,7 +161,7 @@ void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw, struct mt76_phy *phy = ctx->phy; struct mt76_dev *dev = phy->dev; - if (dev->scan.vif == vif && dev->scan.phy == phy) + if (dev->scan.vif == vif && mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -209,7 +209,7 @@ int mt76_switch_vif_chanctx(struct ieee80211_hw *hw, continue; if (phy->chanctx != new_ctx) { - if (dev->scan.phy == phy) + if (mt76_phy_scanning(phy)) mt76_abort_scan(dev); cancel_delayed_work_sync(&phy->mac_work); @@ -376,7 +376,7 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&dev->mutex); - if (phy->roc_vif || dev->scan.phy == phy || + if (phy->roc_vif || mt76_phy_scanning(phy) || test_bit(MT76_MCU_RESET, &dev->phy.state) || test_bit(MT76_RESTART, &dev->phy.state)) { ret = -EBUSY; diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 2584c0e2a2c9..c9762082f473 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -432,6 +432,7 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw) INIT_LIST_HEAD(&phy->tx_list); spin_lock_init(&phy->tx_lock); INIT_DELAYED_WORK(&phy->roc_work, mt76_roc_complete_work); + INIT_DELAYED_WORK(&phy->scan_work, mt76_scan_work); if ((void *)phy != hw->priv) return 0; @@ -729,7 +730,6 @@ mt76_alloc_device(struct device *pdev, unsigned int size, INIT_LIST_HEAD(&dev->txwi_cache); INIT_LIST_HEAD(&dev->rxwi_cache); dev->token_size = dev->drv->token_size; - INIT_DELAYED_WORK(&dev->scan_work, mt76_scan_work); spin_lock_init(&dev->scan_lock); for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) @@ -2338,7 +2338,7 @@ void mt76_rx_beacon(struct mt76_phy *phy, struct sk_buff *skb) .bssid = hdr->addr3, }; - mt76_scan_rx_beacon(phy->dev, phy->chandef.chan); + mt76_scan_rx_beacon(phy, phy->chandef.chan); if (!phy->num_sta) return; diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 09b9507250f9..9e851dea71d9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -877,6 +877,15 @@ struct mt76_phy { struct ieee80211_vif *roc_vif; struct mt76_vif_link *roc_link; + struct delayed_work scan_work; + struct { + struct ieee80211_channel *chan; + struct mt76_vif_link *mlink; + int chan_idx; + bool beacon_wait; + bool beacon_received; + } scan; + struct mt76_chanctx *chanctx; struct mt76_channel_state *chan_state; @@ -1013,17 +1022,12 @@ struct mt76_dev { u32 rxfilter; - struct delayed_work scan_work; spinlock_t scan_lock; struct { - struct cfg80211_scan_request *req; - struct ieee80211_channel *chan; + struct ieee80211_scan_request *req; struct ieee80211_vif *vif; - struct mt76_vif_link *mlink; - struct mt76_phy *phy; - int chan_idx; - bool beacon_wait; - bool beacon_received; + unsigned long phy_mask; + bool aborted; } scan; #ifdef CONFIG_NL80211_TESTMODE @@ -1396,6 +1400,11 @@ mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx) return mt76_dev_phy(dev, phy_idx)->hw; } +static inline bool mt76_phy_scanning(struct mt76_phy *phy) +{ + return test_bit(phy->band_idx, &phy->dev->scan.phy_mask); +} + static inline u8 * mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t) { @@ -1623,7 +1632,7 @@ int mt76_get_rate(struct mt76_dev *dev, int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_scan_request *hw_req); void mt76_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); -void mt76_scan_rx_beacon(struct mt76_dev *dev, struct ieee80211_channel *chan); +void mt76_scan_rx_beacon(struct mt76_phy *phy, struct ieee80211_channel *chan); void mt76_rx_beacon(struct mt76_phy *phy, struct sk_buff *skb); void mt76_beacon_mon_check(struct mt76_phy *phy); void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c index 4a5cdb4efc61..ada7a8984971 100644 --- a/drivers/net/wireless/mediatek/mt76/scan.c +++ b/drivers/net/wireless/mediatek/mt76/scan.c @@ -4,16 +4,26 @@ */ #include "mt76.h" -static void mt76_scan_complete(struct mt76_dev *dev, bool abort) +static struct mt76_phy * +mt76_scan_chan_phy(struct ieee80211_hw *hw, struct ieee80211_channel *chan) { - struct mt76_phy *phy = dev->scan.phy; - struct cfg80211_scan_info info = { - .aborted = abort, - }; + struct mt76_phy *phy = hw->priv; + + if (hw->wiphy->n_radio > 1) + return phy->dev->band_phys[chan->band]; + + return phy; +} + +static void mt76_scan_phy_complete(struct mt76_phy *phy, bool abort) +{ + struct mt76_dev *dev = phy->dev; + struct cfg80211_scan_info info = {}; + struct ieee80211_hw *hw = phy->hw; lockdep_assert_held(&dev->mutex); - if (!phy) + if (!mt76_phy_scanning(phy)) return; clear_bit(MT76_SCANNING, &phy->state); @@ -37,39 +47,64 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort) */ phy->offchannel = false; } - mt76_put_vif_phy_link(phy, dev->scan.vif, dev->scan.mlink); + mt76_put_vif_phy_link(phy, dev->scan.vif, phy->scan.mlink); + memset(&phy->scan, 0, sizeof(phy->scan)); + + clear_bit(phy->band_idx, &dev->scan.phy_mask); + if (abort) + dev->scan.aborted = true; + + if (dev->scan.phy_mask) + return; + + info.aborted = dev->scan.aborted; memset(&dev->scan, 0, sizeof(dev->scan)); - ieee80211_scan_completed(phy->hw, &info); + ieee80211_scan_completed(hw, &info); } void mt76_abort_scan(struct mt76_dev *dev) { - spin_lock_bh(&dev->scan_lock); - dev->scan.beacon_wait = false; - spin_unlock_bh(&dev->scan_lock); + struct mt76_phy *phy; + int i; - cancel_delayed_work_sync(&dev->scan_work); + for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { + phy = dev->phys[i]; + if (!phy) + continue; + + spin_lock_bh(&dev->scan_lock); + phy->scan.beacon_wait = false; + spin_unlock_bh(&dev->scan_lock); + + cancel_delayed_work_sync(&phy->scan_work); + } mutex_lock(&dev->mutex); - mt76_scan_complete(dev, true); + for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { + phy = dev->phys[i]; + if (phy) + mt76_scan_phy_complete(phy, true); + } mutex_unlock(&dev->mutex); } EXPORT_SYMBOL_GPL(mt76_abort_scan); static void -mt76_scan_send_probe(struct mt76_dev *dev, struct cfg80211_ssid *ssid) +mt76_scan_send_probe(struct mt76_phy *phy, struct cfg80211_ssid *ssid) { - struct cfg80211_scan_request *req = dev->scan.req; + struct mt76_dev *dev = phy->dev; + struct cfg80211_scan_request *req = &dev->scan.req->req; + struct ieee80211_scan_ies *ies = &dev->scan.req->ies; struct ieee80211_vif *vif = dev->scan.vif; - struct mt76_vif_link *mvif = dev->scan.mlink; - enum nl80211_band band = dev->scan.chan->band; - struct mt76_phy *phy = dev->scan.phy; + struct mt76_vif_link *mvif = phy->scan.mlink; + enum nl80211_band band = phy->scan.chan->band; struct ieee80211_tx_info *info; struct sk_buff *skb; u8 link_id; skb = ieee80211_probereq_get(phy->hw, vif->addr, ssid->ssid, - ssid->ssid_len, req->ie_len); + ssid->ssid_len, + ies->len[band] + ies->common_ie_len); if (!skb) return; @@ -80,8 +115,10 @@ mt76_scan_send_probe(struct mt76_dev *dev, struct cfg80211_ssid *ssid) ether_addr_copy(hdr->addr3, req->bssid); } - if (req->ie_len) - skb_put_data(skb, req->ie, req->ie_len); + if (ies->len[band]) + skb_put_data(skb, ies->ies[band], ies->len[band]); + if (ies->common_ie_len) + skb_put_data(skb, ies->common_ies, ies->common_ie_len); skb->priority = 7; skb_set_queue_mapping(skb, IEEE80211_AC_VO); @@ -106,65 +143,77 @@ out: rcu_read_unlock(); } -void mt76_scan_rx_beacon(struct mt76_dev *dev, struct ieee80211_channel *chan) +void mt76_scan_rx_beacon(struct mt76_phy *phy, struct ieee80211_channel *chan) { - struct mt76_phy *phy; + struct mt76_dev *dev = phy->dev; spin_lock(&dev->scan_lock); - if (!dev->scan.beacon_wait || dev->scan.beacon_received || - dev->scan.chan != chan) + if (!phy->scan.beacon_wait || phy->scan.beacon_received || + phy->scan.chan != chan) goto out; - phy = dev->scan.phy; - if (!phy) - goto out; - - dev->scan.beacon_received = true; - ieee80211_queue_delayed_work(phy->hw, &dev->scan_work, 0); + phy->scan.beacon_received = true; + ieee80211_queue_delayed_work(phy->hw, &phy->scan_work, 0); out: spin_unlock(&dev->scan_lock); } -void mt76_scan_work(struct work_struct *work) +static int mt76_scan_next_chan_idx(struct mt76_phy *phy) { - struct mt76_dev *dev = container_of(work, struct mt76_dev, - scan_work.work); - struct cfg80211_scan_request *req = dev->scan.req; - struct cfg80211_chan_def chandef = {}; - struct mt76_phy *phy = dev->scan.phy; - int duration = HZ / 9; /* ~110 ms */ - bool beacon_rx, offchannel = true; + struct cfg80211_scan_request *req = &phy->dev->scan.req->req; int i; - if (!phy || !req) + for (i = phy->scan.chan_idx; i < req->n_channels; i++) + if (mt76_scan_chan_phy(phy->hw, req->channels[i]) == phy) + return i; + + return -1; +} + +void mt76_scan_work(struct work_struct *work) +{ + struct mt76_phy *phy = container_of(work, struct mt76_phy, + scan_work.work); + struct mt76_dev *dev = phy->dev; + struct cfg80211_scan_request *req; + struct cfg80211_chan_def chandef = {}; + int duration = HZ / 9; /* ~110 ms */ + bool beacon_rx, offchannel = true; + int i, idx; + + if (!dev->scan.req || !mt76_phy_scanning(phy)) return; + req = &dev->scan.req->req; + spin_lock_bh(&dev->scan_lock); - beacon_rx = dev->scan.beacon_wait && dev->scan.beacon_received; - dev->scan.beacon_wait = false; + beacon_rx = phy->scan.beacon_wait && phy->scan.beacon_received; + phy->scan.beacon_wait = false; spin_unlock_bh(&dev->scan_lock); if (beacon_rx) goto probe; - if (dev->scan.chan_idx >= req->n_channels) { + idx = mt76_scan_next_chan_idx(phy); + if (idx < 0) { mutex_lock(&dev->mutex); - mt76_scan_complete(dev, false); + mt76_scan_phy_complete(phy, false); mutex_unlock(&dev->mutex); return; } - if (dev->scan.chan && phy->num_sta && phy->offchannel) { - dev->scan.chan = NULL; + if (phy->scan.chan && phy->num_sta && phy->offchannel) { + phy->scan.chan = NULL; mt76_set_channel(phy, &phy->main_chandef, false); mt76_offchannel_notify(phy, false); goto out; } - dev->scan.chan = req->channels[dev->scan.chan_idx++]; - offchannel = mt76_offchannel_chandef(phy, dev->scan.chan, &chandef); + phy->scan.chan = req->channels[idx]; + phy->scan.chan_idx = idx + 1; + offchannel = mt76_offchannel_chandef(phy, phy->scan.chan, &chandef); if (offchannel) mt76_offchannel_notify(phy, true); @@ -175,8 +224,8 @@ void mt76_scan_work(struct work_struct *work) if (chandef.chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) { spin_lock_bh(&dev->scan_lock); - dev->scan.beacon_received = false; - dev->scan.beacon_wait = true; + phy->scan.beacon_received = false; + phy->scan.beacon_wait = true; spin_unlock_bh(&dev->scan_lock); goto out; } @@ -186,16 +235,16 @@ probe: duration = HZ / 16; /* ~60 ms */ local_bh_disable(); for (i = 0; i < req->n_ssids; i++) - mt76_scan_send_probe(dev, &req->ssids[i]); + mt76_scan_send_probe(phy, &req->ssids[i]); local_bh_enable(); out: - if (dev->scan.chan && phy->offchannel) + if (phy->scan.chan && phy->offchannel) duration = max_t(int, duration, msecs_to_jiffies(req->duration + (req->duration >> 5))); - ieee80211_queue_delayed_work(dev->phy.hw, &dev->scan_work, duration); + ieee80211_queue_delayed_work(phy->hw, &phy->scan_work, duration); } int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, @@ -203,37 +252,67 @@ int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, { struct mt76_phy *phy = hw->priv; struct mt76_dev *dev = phy->dev; + unsigned long phy_mask = 0; struct mt76_vif_link *mlink; - int ret = 0; + int i, ret = 0; - if (hw->wiphy->n_radio > 1) { - phy = dev->band_phys[req->req.channels[0]->band]; + for (i = 0; i < req->req.n_channels; i++) { + phy = mt76_scan_chan_phy(hw, req->req.channels[i]); if (!phy) return -EINVAL; + + phy_mask |= BIT(phy->band_idx); } mutex_lock(&dev->mutex); - if (dev->scan.req || phy->roc_vif || - test_bit(MT76_MCU_RESET, &dev->phy.state) || + if (dev->scan.req || test_bit(MT76_MCU_RESET, &dev->phy.state) || test_bit(MT76_RESTART, &dev->phy.state)) { ret = -EBUSY; goto out; } - mlink = mt76_get_vif_phy_link(phy, vif); - if (IS_ERR(mlink)) { - ret = PTR_ERR(mlink); - goto out; + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + if (dev->phys[i]->roc_vif) { + ret = -EBUSY; + goto out; + } } - memset(&dev->scan, 0, sizeof(dev->scan)); - dev->scan.req = &req->req; + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + phy = dev->phys[i]; + mlink = mt76_get_vif_phy_link(phy, vif); + if (IS_ERR(mlink)) { + ret = PTR_ERR(mlink); + goto put_links; + } + + memset(&phy->scan, 0, sizeof(phy->scan)); + phy->scan.mlink = mlink; + } + + dev->scan.req = req; dev->scan.vif = vif; - dev->scan.phy = phy; - dev->scan.mlink = mlink; - set_bit(MT76_SCANNING, &phy->state); - ieee80211_queue_delayed_work(dev->phy.hw, &dev->scan_work, 0); + dev->scan.phy_mask = phy_mask; + dev->scan.aborted = false; + + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + phy = dev->phys[i]; + set_bit(MT76_SCANNING, &phy->state); + ieee80211_queue_delayed_work(phy->hw, &phy->scan_work, 0); + } + + goto out; + +put_links: + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + phy = dev->phys[i]; + if (!phy->scan.mlink) + break; + + mt76_put_vif_phy_link(phy, vif, phy->scan.mlink); + phy->scan.mlink = NULL; + } out: mutex_unlock(&dev->mutex); From ac5ec769afce2c6d715832247429e34efb29d148 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 7 Oct 2026 13:24:18 +0200 Subject: [PATCH 1332/2126] wifi: mt76: mt7996: scan all bands with one request mt76 runs the channels of one scan request on all radios in parallel. Let mac80211 pass all bands in one request, so that a scan across the 2.4, 5 and 6 GHz radios takes as long as the slowest radio, not the sum of all three. Signed-off-by: John Crispin Link: https://patch.msgid.link/20261007112419.1277594-8-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index ad9919c516e7..312b35ac622e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -541,6 +541,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed) ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); ieee80211_hw_set(hw, CHANCTX_STA_CSA); ieee80211_hw_set(hw, CONNECTION_MONITOR); + ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); hw->max_tx_fragments = 4; wiphy->txq_memory_limit = 32 << 20; /* 32 MiB */ From 49701802948aadc573d84840853e04c9f1cf6777 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 13:24:19 +0200 Subject: [PATCH 1333/2126] wifi: mt76: keep beacons from queueing the scan work during an abort mt76_abort_scan() clears beacon_wait and then cancels the scan work. A scan work that runs at that time can set beacon_wait again when it moves to a NO_IR or radar channel. After the cancel, a beacon on that channel makes mt76_scan_rx_beacon() queue the work again. The work then runs without dev->mutex while mt76_scan_phy_complete() removes the scan link, so mt76_scan_send_probe() can use the removed link. Reachable via mac80211 cancel_hw_scan, chanctx changes, interface removal and the mt7996 reset work. Disable the scan works instead of cancelling them, so that no beacon can queue them until the abort completes the scan. Enable them again with dev->mutex held, so that a scan that mt76_hw_scan() starts after the abort can always queue its work. Fixes: 360552c8592d ("wifi: mt76: support upgrading passive scans to active") Link: https://patch.msgid.link/20261007112419.1277594-9-nbd@nbd.name Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/scan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c index ada7a8984971..3271a2fa100d 100644 --- a/drivers/net/wireless/mediatek/mt76/scan.c +++ b/drivers/net/wireless/mediatek/mt76/scan.c @@ -76,14 +76,17 @@ void mt76_abort_scan(struct mt76_dev *dev) phy->scan.beacon_wait = false; spin_unlock_bh(&dev->scan_lock); - cancel_delayed_work_sync(&phy->scan_work); + disable_delayed_work_sync(&phy->scan_work); } mutex_lock(&dev->mutex); for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { phy = dev->phys[i]; - if (phy) - mt76_scan_phy_complete(phy, true); + if (!phy) + continue; + + mt76_scan_phy_complete(phy, true); + enable_delayed_work(&phy->scan_work); } mutex_unlock(&dev->mutex); } From 07cc2b151a262c3e81be6608bb84a4f112fec445 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:14 +0000 Subject: [PATCH 1334/2126] ipv4: Rename ipv4_neigh_lookup() to ipv4_dst_neigh_lookup(). Later, we will add ipv4_neigh_lookup() as a wrapper for neigh_lookup(arp_table(net), ...). The existing ipv4_neigh_lookup() is more like ip6_dst_neigh_lookup(). Let's rename ipv4_neigh_lookup() to ipv4_dst_neigh_lookup(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-2-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/ipv4/route.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 1b641901f10d..c7e7d7714e6e 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -146,9 +146,9 @@ static u32 *ipv4_cow_metrics(struct dst_entry *dst, unsigned long old) return NULL; } -static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst, - struct sk_buff *skb, - const void *daddr); +static struct neighbour *ipv4_dst_neigh_lookup(const struct dst_entry *dst, + struct sk_buff *skb, + const void *daddr); static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr); static struct dst_ops ipv4_dst_ops = { @@ -163,7 +163,7 @@ static struct dst_ops ipv4_dst_ops = { .update_pmtu = ip_rt_update_pmtu, .redirect = ip_do_redirect, .local_out = __ip_local_out, - .neigh_lookup = ipv4_neigh_lookup, + .neigh_lookup = ipv4_dst_neigh_lookup, .confirm_neigh = ipv4_confirm_neigh, }; @@ -409,9 +409,9 @@ void rt_cache_flush(struct net *net) rt_genid_bump_ipv4(net); } -static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst, - struct sk_buff *skb, - const void *daddr) +static struct neighbour *ipv4_dst_neigh_lookup(const struct dst_entry *dst, + struct sk_buff *skb, + const void *daddr) { const struct rtable *rt = container_of(dst, struct rtable, dst); struct net_device *dev; @@ -2917,7 +2917,7 @@ out: static struct dst_ops ipv4_dst_blackhole_ops = { .family = AF_INET, .default_advmss = ipv4_default_advmss, - .neigh_lookup = ipv4_neigh_lookup, + .neigh_lookup = ipv4_dst_neigh_lookup, .check = dst_blackhole_check, .cow_metrics = dst_blackhole_cow_metrics, .update_pmtu = dst_blackhole_update_pmtu, From 3e33cdcf54ee1143b47b2ee324fc20923ac6fcf3 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:15 +0000 Subject: [PATCH 1335/2126] ipv6: Rename ip6_neigh_lookup() to __ip6_dst_neigh_lookup(). Later, we will add ipv6_neigh_lookup() as a wrapper for neigh_lookup(nd_table(net), ...). The existing ip6_neigh_lookup() is called from ip6_dst_neigh_lookup() with a gateway address. Let's rename ip6_neigh_lookup() to __ip6_dst_neigh_lookup(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-3-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/ip6_route.h | 6 +++--- net/ipv6/ndisc.c | 12 ++++++------ net/ipv6/route.c | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index b9de335b639a..5f47cef0be46 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -437,7 +437,7 @@ u32 ip6_mtu_from_fib6(const struct fib6_result *res, const struct in6_addr *daddr, const struct in6_addr *saddr); -struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw, - struct net_device *dev, struct sk_buff *skb, - const void *daddr); +struct neighbour *__ip6_dst_neigh_lookup(const struct in6_addr *gw, + struct net_device *dev, struct sk_buff *skb, + const void *daddr); #endif diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 12d85d7f8234..e1cbffaa0ad0 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1359,9 +1359,9 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) /* routes added from RAs do not use nexthop objects */ rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev); if (rt) { - neigh = ip6_neigh_lookup(&rt->fib6_nh->fib_nh_gw6, - rt->fib6_nh->fib_nh_dev, NULL, - &ipv6_hdr(skb)->saddr); + neigh = __ip6_dst_neigh_lookup(&rt->fib6_nh->fib_nh_gw6, + rt->fib6_nh->fib_nh_dev, NULL, + &ipv6_hdr(skb)->saddr); if (!neigh) { net_err_ratelimited("RA: %s got default router without neighbour\n", __func__); @@ -1395,9 +1395,9 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) return reason; } - neigh = ip6_neigh_lookup(&rt->fib6_nh->fib_nh_gw6, - rt->fib6_nh->fib_nh_dev, NULL, - &ipv6_hdr(skb)->saddr); + neigh = __ip6_dst_neigh_lookup(&rt->fib6_nh->fib_nh_gw6, + rt->fib6_nh->fib_nh_dev, NULL, + &ipv6_hdr(skb)->saddr); if (!neigh) { net_err_ratelimited("RA: %s got default router without neighbour\n", __func__); diff --git a/net/ipv6/route.c b/net/ipv6/route.c index b1dcb5e5da88..6bd9659b3870 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -214,10 +214,10 @@ static inline const void *choose_neigh_daddr(const struct in6_addr *p, return daddr; } -struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw, - struct net_device *dev, - struct sk_buff *skb, - const void *daddr) +struct neighbour *__ip6_dst_neigh_lookup(const struct in6_addr *gw, + struct net_device *dev, + struct sk_buff *skb, + const void *daddr) { struct neighbour *n; @@ -236,8 +236,8 @@ static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst, { const struct rt6_info *rt = dst_rt6_info(dst); - return ip6_neigh_lookup(rt6_nexthop(rt, &in6addr_any), - dst_dev(dst), skb, daddr); + return __ip6_dst_neigh_lookup(rt6_nexthop(rt, &in6addr_any), + dst_dev(dst), skb, daddr); } static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr) From 33ea2463c432eeee551d63652cc99ac791c15351 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:16 +0000 Subject: [PATCH 1336/2126] ipv4: Add wrappers for neigh_lookup() and neigh_create(). neigh_lookup() accepts struct neigh_table *tbl and struct net_device *dev, and both of them must exist in the same netns. It is error-prone to require callers to fetch a netns and get neigh_table, which might belong to a different netns than dev_net(dev). Let's add IPv4-specific wrappers for neigh_lookup() and neigh_create() that always fetch netns from dev. Note that we do not add wrappers for __neigh_lookup() and __neigh_lookup_errno(), which we will remove later. __neigh_lookup_errno() is a simple combo of neigh_lookup() and neigh_create(). __neigh_lookup() is almost the same but converts errno from neigh_create() to NULL. So both names are confusing. For IPv4, __neigh_lookup_errno() is only used in arp_req_set() and is not worth a new wrapper. Instead, it should be inlined. arp_process() uses __neigh_lookup(create=0) but it should simply be neigh_lookup(), and then __neigh_lookup(create=1) is only used in arp_process(), so this should be inlined too. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-4-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/arp.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/net/arp.h b/include/net/arp.h index e932def63d62..329a5456987a 100644 --- a/include/net/arp.h +++ b/include/net/arp.h @@ -51,6 +51,22 @@ static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 return n; } +static inline struct neighbour *ipv4_neigh_lookup(struct net_device *dev, + const void *pkey) +{ + struct neigh_table *tbl = arp_table(dev_net(dev)); + + return neigh_lookup(tbl, pkey, dev); +} + +static inline struct neighbour *ipv4_neigh_create(struct net_device *dev, + const void *pkey) +{ + struct neigh_table *tbl = arp_table(dev_net(dev)); + + return neigh_create(tbl, pkey, dev); +} + static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key) { struct neighbour *n; From 616b2143f901435fa9f01c8be6e3baff2290196a Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:17 +0000 Subject: [PATCH 1337/2126] ipv6: Add wrappers for neigh_lookup() and (__)?neigh_create(). neigh_lookup() accepts struct neigh_table *tbl and struct net_device *dev, and both of them must exist in the same netns. It is error-prone to require callers to fetch a netns and get neigh_table, which might belong to a different netns than dev_net(dev). Let's add IPv6-specific wrappers for neigh_lookup() and (__)?neigh_create() that always fetch netns from dev. Similar to IPv4, we do not add wrappers for __neigh_lookup() since 3 out of 4 users call it with create=1, which should be simply written as neigh_lookup() and neigh_create(). IPv6 has 3 callers of __neigh_create(want_ref=false), so ipv6_neigh_create_noref() is also added. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-5-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/ndisc.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/net/ndisc.h b/include/net/ndisc.h index 96e3bb6e83af..2fce6fccf55a 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -381,6 +381,30 @@ static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, cons return n; } +static inline struct neighbour *ipv6_neigh_lookup(struct net_device *dev, + const void *pkey) +{ + struct neigh_table *tbl = nd_table(dev_net(dev)); + + return neigh_lookup(tbl, pkey, dev); +} + +static inline struct neighbour *ipv6_neigh_create(struct net_device *dev, + const void *pkey) +{ + struct neigh_table *tbl = nd_table(dev_net(dev)); + + return neigh_create(tbl, pkey, dev); +} + +static inline struct neighbour *ipv6_neigh_create_noref(struct net_device *dev, + const void *pkey) +{ + struct neigh_table *tbl = nd_table(dev_net(dev)); + + return __neigh_create(tbl, pkey, dev, false); +} + static inline void __ipv6_confirm_neigh(struct net_device *dev, const void *pkey) { From 98071355ffc9ccbcd63cddc83a98250524eb1526 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:18 +0000 Subject: [PATCH 1338/2126] mlxsw: spectrum: Resolve neigh_table right before neigh_lookup(). We will replace neigh_lookup() and neigh_create() with IPv4/IPv6-specific helpers. mlxsw has two paths where neigh_table is fetched in advance and passed down to a function which calls neigh_lookup() and neigh_create(). To keep the changes simple, let's prepare them beforehand by delaying the neigh_table resolution until right before neigh_lookup(). struct mlxsw_sp_nexthop caches neigh_tbl, so it is replaced with family, and a new helper, mlxsw_sp_nexthop_neigh_lookup(), resolves neigh_table and calls neigh_lookup() and neigh_create(). Similarly, mlxsw_sp_span_entry_gretap[46]_parms() now pass family to mlxsw_sp_span_dmac() to resolve neigh_table there just before neigh_lookup() and neigh_create(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-6-kuniyu@google.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlxsw/spectrum_router.c | 65 ++++++++++++------- .../ethernet/mellanox/mlxsw/spectrum_span.c | 31 +++++---- 2 files changed, 58 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index e55f376881c1..9d1d6034fc89 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -3073,9 +3073,9 @@ struct mlxsw_sp_nexthop { * this nexthop belongs to */ struct rhash_head ht_node; - struct neigh_table *neigh_tbl; struct mlxsw_sp_nexthop_key key; unsigned char gw_addr[sizeof(struct in6_addr)]; + int family; int ifindex; int nh_weight; int norm_nh_weight; @@ -4301,28 +4301,49 @@ static void __mlxsw_sp_nexthop_neigh_update(struct mlxsw_sp_nexthop *nh, nh->update = 1; } +static struct neighbour * +mlxsw_sp_nexthop_neigh_lookup(struct mlxsw_sp_nexthop *nh) +{ + struct neigh_table *tbl; + struct net_device *dev; + struct neighbour *n; + struct net *net; + + dev = mlxsw_sp_nexthop_dev(nh); + net = dev_net(dev); + +#if IS_ENABLED(CONFIG_IPV6) + if (nh->family == AF_INET6) + tbl = nd_table(net); + else +#endif + tbl = arp_table(net); + + n = neigh_lookup(tbl, &nh->gw_addr, dev); + if (!n) { + n = neigh_create(tbl, &nh->gw_addr, dev); + if (!IS_ERR(n)) + neigh_event_send(n, NULL); + } + + return n; +} + static int mlxsw_sp_nexthop_dead_neigh_replace(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_neigh_entry *neigh_entry) { struct neighbour *n, *old_n = neigh_entry->key.n; struct mlxsw_sp_nexthop *nh; - struct net_device *dev; bool entry_connected; u8 nud_state, dead; int err; nh = list_first_entry(&neigh_entry->nexthop_list, struct mlxsw_sp_nexthop, neigh_list_node); - dev = mlxsw_sp_nexthop_dev(nh); - - n = neigh_lookup(nh->neigh_tbl, &nh->gw_addr, dev); - if (!n) { - n = neigh_create(nh->neigh_tbl, &nh->gw_addr, dev); - if (IS_ERR(n)) - return PTR_ERR(n); - neigh_event_send(n, NULL); - } + n = mlxsw_sp_nexthop_neigh_lookup(nh); + if (IS_ERR(n)) + return PTR_ERR(n); mlxsw_sp_neigh_entry_remove(mlxsw_sp, neigh_entry); neigh_entry->key.n = n; @@ -4403,7 +4424,6 @@ static int mlxsw_sp_nexthop_neigh_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_nexthop *nh) { struct mlxsw_sp_neigh_entry *neigh_entry; - struct net_device *dev; struct neighbour *n; u8 nud_state, dead; int err; @@ -4413,20 +4433,16 @@ static int mlxsw_sp_nexthop_neigh_init(struct mlxsw_sp *mlxsw_sp, if (!nh->nhgi->gateway || nh->neigh_entry) return 0; - dev = mlxsw_sp_nexthop_dev(nh); /* Take a reference of neigh here ensuring that neigh would * not be destructed before the nexthop entry is finished. * The reference is taken either in neigh_lookup() or * in neigh_create() in case n is not found. */ - n = neigh_lookup(nh->neigh_tbl, &nh->gw_addr, dev); - if (!n) { - n = neigh_create(nh->neigh_tbl, &nh->gw_addr, dev); - if (IS_ERR(n)) - return PTR_ERR(n); - neigh_event_send(n, NULL); - } + n = mlxsw_sp_nexthop_neigh_lookup(nh); + if (IS_ERR(n)) + return PTR_ERR(n); + neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, n); if (!neigh_entry) { neigh_entry = mlxsw_sp_neigh_entry_create(mlxsw_sp, n); @@ -4631,7 +4647,7 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp, nh->nh_weight = 1; #endif memcpy(&nh->gw_addr, &fib_nh->fib_nh_gw4, sizeof(fib_nh->fib_nh_gw4)); - nh->neigh_tbl = arp_table(mlxsw_sp_net(mlxsw_sp)); + nh->family = AF_INET; err = mlxsw_sp_nexthop_insert(mlxsw_sp, nh); if (err) return err; @@ -5121,7 +5137,6 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp, struct nh_notifier_single_info *nh_obj, int weight) { struct net_device *dev = nh_obj->dev; - struct net *net = dev_net(dev); int err; nh->nhgi = nh_grp->nhgi; @@ -5130,12 +5145,12 @@ mlxsw_sp_nexthop_obj_init(struct mlxsw_sp *mlxsw_sp, switch (nh_obj->gw_family) { case AF_INET: memcpy(&nh->gw_addr, &nh_obj->ipv4, sizeof(nh_obj->ipv4)); - nh->neigh_tbl = arp_table(net); + nh->family = AF_INET; break; case AF_INET6: memcpy(&nh->gw_addr, &nh_obj->ipv6, sizeof(nh_obj->ipv6)); #if IS_ENABLED(CONFIG_IPV6) - nh->neigh_tbl = nd_table(net); + nh->family = AF_INET6; #endif break; } @@ -6991,7 +7006,7 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp, nh->nh_weight = rt->fib6_nh->fib_nh_weight; memcpy(&nh->gw_addr, &rt->fib6_nh->fib_nh_gw6, sizeof(nh->gw_addr)); #if IS_ENABLED(CONFIG_IPV6) - nh->neigh_tbl = nd_table(mlxsw_sp_net(mlxsw_sp)); + nh->family = AF_INET6; #endif err = mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index 1cd8347c274d..d34d2040177b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -224,14 +224,24 @@ struct mlxsw_sp_span_entry_ops mlxsw_sp_span_entry_ops_phys = { .deconfigure = mlxsw_sp_span_entry_phys_deconfigure, }; -static int mlxsw_sp_span_dmac(struct neigh_table *tbl, +static int mlxsw_sp_span_dmac(int family, const void *pkey, struct net_device *dev, unsigned char dmac[ETH_ALEN]) { - struct neighbour *neigh = neigh_lookup(tbl, pkey, dev); + struct net *net = dev_net(dev); + struct neigh_table *tbl; + struct neighbour *neigh; int err = 0; +#if IS_ENABLED(CONFIG_IPV6_GRE) + if (family == AF_INET6) + tbl = nd_table(net); + else +#endif + tbl = arp_table(net); + + neigh = neigh_lookup(tbl, pkey, dev); if (!neigh) { neigh = neigh_create(tbl, pkey, dev); if (IS_ERR(neigh)) @@ -355,8 +365,7 @@ mlxsw_sp_span_entry_tunnel_parms_common(struct net_device *edev, union mlxsw_sp_l3addr saddr, union mlxsw_sp_l3addr daddr, union mlxsw_sp_l3addr gw, - __u8 ttl, - struct neigh_table *tbl, + __u8 ttl, int family, struct mlxsw_sp_span_parms *sparmsp) { unsigned char dmac[ETH_ALEN]; @@ -365,7 +374,7 @@ mlxsw_sp_span_entry_tunnel_parms_common(struct net_device *edev, if (mlxsw_sp_l3addr_is_zero(gw)) gw = daddr; - if (!edev || mlxsw_sp_span_dmac(tbl, &gw, edev, dmac)) + if (!edev || mlxsw_sp_span_dmac(family, &gw, edev, dmac)) goto unoffloadable; if (is_vlan_dev(edev)) @@ -456,7 +465,6 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp, bool inherit_tos = tparm.iph.tos & 0x1; bool inherit_ttl = !tparm.iph.ttl; union mlxsw_sp_l3addr gw = daddr; - struct neigh_table *tbl = NULL; struct net_device *l3edev; if (!(to_dev->flags & IFF_UP) || @@ -470,11 +478,10 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp, return mlxsw_sp_span_entry_unoffloadable(sparmsp); l3edev = mlxsw_sp_span_gretap4_route(to_dev, &saddr.addr4, &gw.addr4); - if (l3edev) - tbl = arp_table(dev_net(l3edev)); + return mlxsw_sp_span_entry_tunnel_parms_common(l3edev, saddr, daddr, gw, tparm.iph.ttl, - tbl, sparmsp); + AF_INET, sparmsp); } static int @@ -564,7 +571,6 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp, union mlxsw_sp_l3addr daddr = { .addr6 = tparm.raddr }; bool inherit_ttl = !tparm.hop_limit; union mlxsw_sp_l3addr gw = daddr; - struct neigh_table *tbl = NULL; struct net_device *l3edev; if (!(to_dev->flags & IFF_UP) || @@ -578,11 +584,10 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp, return mlxsw_sp_span_entry_unoffloadable(sparmsp); l3edev = mlxsw_sp_span_gretap6_route(to_dev, &saddr.addr6, &gw.addr6); - if (l3edev) - tbl = nd_table(dev_net(l3edev)); + return mlxsw_sp_span_entry_tunnel_parms_common(l3edev, saddr, daddr, gw, tparm.hop_limit, - tbl, sparmsp); + AF_INET6, sparmsp); } static int From 0e59523b440c90ed1899476f32ad4e949282f43e Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:19 +0000 Subject: [PATCH 1339/2126] ipv6: Use ipv6_neigh_lookup() and friends. syzbot reported the splat below in neigh_mark_dead() [0] where tbl->lock was not held while neigh_ifdown() should have acquired one. This only happens when a neigh_table accidentally has a neighbour from a different netns. In ip6_finish_output2(), the net argument is the caller's and does not always match dev_net(dev) fetched from dst. (e.g. xfrm) It is error-prone to require callers to fetch netns and neigh_table and pass it with dev to neigh_lookup(), etc. Let's replace neigh_lookup() and friends with IPv6 helpers. Note that __neigh_lookup() is split into ipv6_neigh_lookup() and ipv6_neigh_create(). [0]: debug_locks && !(lock_is_held(&(&n->tbl->lock)->dep_map) != 0) WARNING: net/core/neighbour.c:154 at neigh_mark_dead+0x2fb/0x340 net/core/neighbour.c:154, CPU#0: syz.0.857/9765 Modules linked in: CPU: 0 UID: 0 PID: 9765 Comm: syz.0.857 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026 RIP: 0010:neigh_mark_dead+0x2fb/0x340 net/core/neighbour.c:154 Code: e8 03 42 80 3c 28 00 74 08 48 89 df e8 ee 9a 80 f8 4c 89 33 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc cc e8 86 95 10 f8 90 <0f> 0b 90 e9 8f fd ff ff 48 c7 c1 80 9a 7a 90 80 e1 07 80 c1 03 38 RSP: 0018:ffffc90003726600 EFLAGS: 00010287 RAX: ffffffff89b7467a RBX: ffff888022e86000 RCX: 0000000000080000 RDX: ffffc900047fa000 RSI: 0000000000003e08 RDI: 0000000000003e09 RBP: 0000000000000000 R08: 0000000000000003 R09: 0000000000000004 R10: dffffc0000000000 R11: fffff520006e4cb8 R12: ffff888022e8613c R13: dffffc0000000000 R14: ffff888022e86020 R15: ffff888022e86000 FS: 00007f9c30f046c0(0000) GS:ffff888124cc6000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000000076c56000 CR4: 00000000003526f0 Call Trace: neigh_flush_one+0x27c/0x5a0 net/core/neighbour.c:388 neigh_flush_dev net/core/neighbour.c:432 [inline] __neigh_ifdown+0x1fb/0xc70 net/core/neighbour.c:465 neigh_ifdown+0x1f/0x30 net/core/neighbour.c:487 rt6_disable_ip+0x751/0x7e0 net/ipv6/route.c:5058 addrconf_ifdown+0x155/0x1ad0 net/ipv6/addrconf.c:3892 addrconf_notify+0x1bc/0x1050 net/ipv6/addrconf.c:-1 notifier_call_chain+0x1a5/0x3d0 kernel/notifier.c:85 call_netdevice_notifiers_mtu net/core/dev.c:2350 [inline] netif_set_mtu_ext+0x5ac/0x830 net/core/dev.c:9963 do_setlink+0xa81/0x47a0 net/core/rtnetlink.c:3247 rtnl_setlink+0x578/0x820 net/core/rtnetlink.c:3623 rtnetlink_rcv_msg+0x802/0xc00 net/core/rtnetlink.c:7159 netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2572 netlink_unicast_kernel net/netlink/af_netlink.c:1335 [inline] netlink_unicast+0x7bd/0x940 net/netlink/af_netlink.c:1361 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1916 sock_sendmsg_nosec+0x13a/0x180 net/socket.c:800 __sock_sendmsg net/socket.c:815 [inline] sock_write_iter+0x2de/0x3e0 net/socket.c:1266 do_iter_readv_writev+0x612/0x8c0 fs/read_write.c:-1 vfs_writev+0x343/0x990 fs/read_write.c:1058 do_writev+0x154/0x2e0 fs/read_write.c:1104 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f9c2ff9e159 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f9c30f04028 EFLAGS: 00000246 ORIG_RAX: 0000000000000014 RAX: ffffffffffffffda RBX: 00007f9c30225fa0 RCX: 00007f9c2ff9e159 RDX: 0000000000000001 RSI: 00002000000003c0 RDI: 0000000000000004 RBP: 00007f9c3003506b R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f9c30226038 R14: 00007f9c30225fa0 R15: 00007ffed3c74808 Fixes: df5f4f372de5 ("ipv6: Replace &nd_tbl with nd_table(net).") Reported-by: syzbot+5a8857f0b4a0a7b12c62@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/6abd69a9.80e1c6cc.22483f.0005.GAE@google.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-7-kuniyu@google.com Signed-off-by: Jakub Kicinski --- .../mellanox/mlx5/core/en/tc_tun_encap.c | 15 ++++---- .../ethernet/mellanox/mlxsw/spectrum_router.c | 29 ++++++++------- .../ethernet/mellanox/mlxsw/spectrum_span.c | 24 ++++++++----- .../netronome/nfp/flower/tunnel_conf.c | 4 +-- drivers/net/ethernet/sfc/tc_counters.c | 5 ++- drivers/net/vrf.c | 4 +-- drivers/net/vxlan/vxlan_core.c | 6 ++-- include/net/ndisc.h | 7 ++-- net/bridge/br_arp_nd_proxy.c | 2 +- net/ieee802154/6lowpan/tx.c | 3 +- net/ipv4/fib_semantics.c | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/ndisc.c | 36 ++++++++++++------- net/ipv6/route.c | 11 +++--- net/sched/sch_teql.c | 12 ++++++- 15 files changed, 91 insertions(+), 71 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c index 67c12ca19d59..fe0258375ef6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c @@ -439,21 +439,18 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) if (neigh_used) { struct net_device *dev = READ_ONCE(nhe->neigh_dev); struct net *net = dev_net(dev); - struct neigh_table *tbl; nhe->reported_lastuse = jiffies; -#if IS_ENABLED(CONFIG_IPV6) - if (m_neigh->family != AF_INET) - tbl = nd_table(net); - else -#endif - tbl = arp_table(net); - /* find the relevant neigh according to the cached device and * dst ip pair */ - n = neigh_lookup(tbl, &m_neigh->dst_ip, dev); +#if IS_ENABLED(CONFIG_IPV6) + if (m_neigh->family != AF_INET) + n = ipv6_neigh_lookup(dev, &m_neigh->dst_ip); + else +#endif + n = neigh_lookup(arp_table(net), &m_neigh->dst_ip, dev); if (!n) return; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 9d1d6034fc89..ee3bc9852233 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -2450,8 +2450,6 @@ static void mlxsw_sp_router_neigh_ent_ipv6_process(struct mlxsw_sp *mlxsw_sp, char *rauhtd_pl, int rec_index) { - struct net *net = mlxsw_sp_net(mlxsw_sp); - struct neigh_table *tbl; struct net_device *dev; struct neighbour *n; struct in6_addr dip; @@ -2465,9 +2463,8 @@ static void mlxsw_sp_router_neigh_ent_ipv6_process(struct mlxsw_sp *mlxsw_sp, return; } - tbl = nd_table(net); dev = mlxsw_sp_rif_dev(mlxsw_sp->router->rifs[rif]); - n = neigh_lookup(tbl, &dip, dev); + n = ipv6_neigh_lookup(dev, &dip); if (!n) return; @@ -4313,17 +4310,23 @@ mlxsw_sp_nexthop_neigh_lookup(struct mlxsw_sp_nexthop *nh) net = dev_net(dev); #if IS_ENABLED(CONFIG_IPV6) - if (nh->family == AF_INET6) - tbl = nd_table(net); - else + if (nh->family == AF_INET6) { + n = ipv6_neigh_lookup(dev, &nh->gw_addr); + if (!n) { + n = ipv6_neigh_create(dev, &nh->gw_addr); + if (!IS_ERR(n)) + neigh_event_send(n, NULL); + } + } else #endif + { tbl = arp_table(net); - - n = neigh_lookup(tbl, &nh->gw_addr, dev); - if (!n) { - n = neigh_create(tbl, &nh->gw_addr, dev); - if (!IS_ERR(n)) - neigh_event_send(n, NULL); + n = neigh_lookup(tbl, &nh->gw_addr, dev); + if (!n) { + n = neigh_create(tbl, &nh->gw_addr, dev); + if (!IS_ERR(n)) + neigh_event_send(n, NULL); + } } return n; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index d34d2040177b..79947f68b10d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -235,17 +235,23 @@ static int mlxsw_sp_span_dmac(int family, int err = 0; #if IS_ENABLED(CONFIG_IPV6_GRE) - if (family == AF_INET6) - tbl = nd_table(net); - else + if (family == AF_INET6) { + neigh = ipv6_neigh_lookup(dev, pkey); + if (!neigh) { + neigh = ipv6_neigh_create(dev, pkey); + if (IS_ERR(neigh)) + return PTR_ERR(neigh); + } + } else #endif + { tbl = arp_table(net); - - neigh = neigh_lookup(tbl, pkey, dev); - if (!neigh) { - neigh = neigh_create(tbl, pkey, dev); - if (IS_ERR(neigh)) - return PTR_ERR(neigh); + neigh = neigh_lookup(tbl, pkey, dev); + if (!neigh) { + neigh = neigh_create(tbl, pkey, dev); + if (IS_ERR(neigh)) + return PTR_ERR(neigh); + } } neigh_event_send(neigh, NULL); diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c index d650d33e3709..27d80ec8e895 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c @@ -253,7 +253,6 @@ void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb) #if IS_ENABLED(CONFIG_IPV6) struct nfp_tun_active_tuns_v6 *payload; struct net_device *netdev; - struct neigh_table *tbl; int count, i, pay_len; struct neighbour *n; void *ipv6_add; @@ -280,8 +279,7 @@ void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb) if (!netdev) continue; - tbl = nd_table(dev_net(netdev)); - n = neigh_lookup(tbl, ipv6_add, netdev); + n = ipv6_neigh_lookup(netdev, ipv6_add); if (!n) continue; diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index 793a562fc1f7..ae6cc6b93864 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -116,9 +116,8 @@ static void efx_tc_counter_work(struct work_struct *work) encap->neigh->egdev); else #if IS_ENABLED(CONFIG_IPV6) - n = neigh_lookup(nd_table(net), - &encap->neigh->dst_ip6, - encap->neigh->egdev); + n = ipv6_neigh_lookup(encap->neigh->egdev, + &encap->neigh->dst_ip6); #else n = NULL; #endif diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index 320f3584a43b..79d433f49f80 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -614,9 +614,9 @@ static int vrf_finish_output6(struct net *net, struct sock *sk, rcu_read_lock(); nexthop = rt6_nexthop(dst_rt6_info(dst), &ipv6_hdr(skb)->daddr); - neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop); + neigh = __ipv6_neigh_lookup_noref(dev, nexthop); if (unlikely(!neigh)) - neigh = __neigh_create(nd_table(net), nexthop, dst->dev, false); + neigh = ipv6_neigh_create_noref(dev, nexthop); if (!IS_ERR(neigh)) { sock_confirm_neigh(skb, neigh); ret = neigh_output(neigh, skb, false); diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 27b0b6567d52..513779c07621 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2091,8 +2091,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, ipv6_addr_is_multicast(&msg->target)) goto out; - n = neigh_lookup(nd_table(dev_net(dev)), &msg->target, dev); - + n = ipv6_neigh_lookup(dev, &msg->target); if (n) { struct vxlan_rdst *rdst = NULL; u8 ha[ETH_ALEN] __aligned(2); @@ -2189,9 +2188,8 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb, if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) return false; - tbl = nd_table(dev_net(dev)); pip6 = ipv6_hdr(skb); - n = neigh_lookup(tbl, &pip6->daddr, dev); + n = ipv6_neigh_lookup(dev, &pip6->daddr); if (!n && (cfg->flags & VXLAN_F_L3MISS)) { union vxlan_addr ipa = { .sin6.sin6_addr = pip6->daddr, diff --git a/include/net/ndisc.h b/include/net/ndisc.h index 2fce6fccf55a..91898a2475e7 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -423,11 +423,8 @@ static inline struct neighbour *ip_neigh_gw6(struct net_device *dev, struct neighbour *neigh; neigh = __ipv6_neigh_lookup_noref(dev, addr); - if (unlikely(!neigh)) { - struct neigh_table *tbl = nd_table(dev_net(dev)); - - neigh = __neigh_create(tbl, addr, dev, false); - } + if (unlikely(!neigh)) + neigh = ipv6_neigh_create_noref(dev, addr); return neigh; #else diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index ba4a63840b21..c23b99517cd5 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -487,7 +487,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, return; } - n = neigh_lookup(nd_table(dev_net(vlandev)), &msg->target, vlandev); + n = ipv6_neigh_lookup(vlandev, &msg->target); if (n) { struct net_bridge_fdb_entry *f; u8 ha[ETH_ALEN] __aligned(2); diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c index 4f511476b992..b261daedc290 100644 --- a/net/ieee802154/6lowpan/tx.c +++ b/net/ieee802154/6lowpan/tx.c @@ -58,9 +58,8 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev, info->daddr.mode = IEEE802154_ADDR_SHORT; } else { __le16 short_addr = cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC); - struct neigh_table *tbl = nd_table(dev_net(ldev)); - n = neigh_lookup(tbl, &hdr->daddr, ldev); + n = ipv6_neigh_lookup(ldev, &hdr->daddr); if (n) { llneigh = lowpan_802154_neigh(neighbour_priv(n)); read_lock_bh(&n->lock); diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index e3bcc25229b0..a98c7670d2ce 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -617,7 +617,7 @@ static int fib_detect_death(struct fib_info *fi, int order, if (likely(nhc->nhc_gw_family == AF_INET)) n = neigh_lookup(arp_table(net), &nhc->nhc_gw.ipv4, nhc->nhc_dev); else if (IS_ENABLED(CONFIG_IPV6) && nhc->nhc_gw_family == AF_INET6) - n = neigh_lookup(nd_table(net), &nhc->nhc_gw.ipv6, nhc->nhc_dev); + n = ipv6_neigh_lookup(nhc->nhc_dev, &nhc->nhc_gw.ipv6); else n = NULL; diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 10146a57b69e..25fe0ba98b1a 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -127,7 +127,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * if (IS_ERR_OR_NULL(neigh)) { if (unlikely(!neigh)) - neigh = __neigh_create(nd_table(net), nexthop, dev, false); + neigh = ipv6_neigh_create_noref(dev, nexthop); if (IS_ERR(neigh)) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTNOROUTES); kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index e1cbffaa0ad0..0ed1a619372b 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -947,8 +947,12 @@ have_ifp: * update / create cache entry * for the source address */ - neigh = __neigh_lookup(tbl, saddr, dev, - !inc || lladdr || !dev->addr_len); + neigh = ipv6_neigh_lookup(dev, saddr); + if (!neigh && (!inc || lladdr || !dev->addr_len)) { + neigh = ipv6_neigh_create(dev, saddr); + if (IS_ERR(neigh)) + neigh = NULL; + } if (neigh) ndisc_update(dev, neigh, lladdr, NUD_STALE, NEIGH_UPDATE_F_WEAK_OVERRIDE| @@ -998,7 +1002,6 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) struct net *net = dev_net(dev); struct ndisc_options ndopts; struct inet6_ifaddr *ifp; - struct neigh_table *tbl; struct neighbour *neigh; struct inet6_dev *idev; u8 *lladdr = NULL; @@ -1063,8 +1066,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) return reason; } - tbl = nd_table(net); - neigh = neigh_lookup(tbl, &msg->target, dev); + neigh = ipv6_neigh_lookup(dev, &msg->target); /* RFC 9131 updates original Neighbour Discovery RFC 4861. * NAs with Target LL Address option can now create a STALE neighbor @@ -1093,7 +1095,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) return reason; } if (!neigh) - neigh = neigh_create(tbl, &msg->target, dev); + neigh = ipv6_neigh_create(dev, &msg->target); new_state = NUD_STALE; } @@ -1108,7 +1110,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb) if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) && READ_ONCE(net->ipv6.devconf_all->forwarding) && READ_ONCE(net->ipv6.devconf_all->proxy_ndp) && - pneigh_lookup(tbl, &msg->target, dev)) { + pneigh_lookup(nd_table(dev_net(dev)), &msg->target, dev)) { /* XXX: idev->cnf.proxy_ndp */ goto out; } @@ -1141,7 +1143,6 @@ static enum skb_drop_reason ndisc_recv_rs(struct sk_buff *skb) unsigned long ndoptlen = skb->len - sizeof(*rs_msg); struct net_device *dev = skb->dev; struct ndisc_options ndopts; - struct neigh_table *tbl; struct neighbour *neigh; struct inet6_dev *idev; u8 *lladdr = NULL; @@ -1177,8 +1178,12 @@ static enum skb_drop_reason ndisc_recv_rs(struct sk_buff *skb) goto out; } - tbl = nd_table(dev_net(dev)); - neigh = __neigh_lookup(tbl, saddr, dev, 1); + neigh = ipv6_neigh_lookup(dev, saddr); + if (!neigh) { + neigh = ipv6_neigh_create(dev, saddr); + if (IS_ERR(neigh)) + goto out; + } if (neigh) { ndisc_update(dev, neigh, lladdr, NUD_STALE, NEIGH_UPDATE_F_WEAK_OVERRIDE| @@ -1478,9 +1483,14 @@ skip_linkparms: * Process options. */ - if (!neigh) - neigh = __neigh_lookup(nd_table(net), &ipv6_hdr(skb)->saddr, - skb->dev, 1); + if (!neigh) { + neigh = ipv6_neigh_lookup(skb->dev, &ipv6_hdr(skb)->saddr); + if (!neigh) { + neigh = ipv6_neigh_create(skb->dev, &ipv6_hdr(skb)->saddr); + if (IS_ERR(neigh)) + neigh = NULL; + } + } if (neigh) { u8 *lladdr = NULL; if (ndopts.nd_opts_src_lladdr) { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 6bd9659b3870..5ffb3dc73cf4 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -226,7 +226,7 @@ struct neighbour *__ip6_dst_neigh_lookup(const struct in6_addr *gw, if (n) return n; - n = neigh_create(nd_table(dev_net(dev)), daddr, dev); + n = ipv6_neigh_create(dev, daddr); return IS_ERR(n) ? NULL : n; } @@ -4285,9 +4285,12 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu */ dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); - neigh = __neigh_lookup(nd_table(dev_net(dev)), &msg->target, dev, 1); - if (!neigh) - return; + neigh = ipv6_neigh_lookup(dev, &msg->target); + if (!neigh) { + neigh = ipv6_neigh_create(dev, &msg->target); + if (IS_ERR(neigh)) + return; + } /* * We have finally decided to accept it. diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c index 409ce50cc0db..19ccf1a55988 100644 --- a/net/sched/sch_teql.c +++ b/net/sched/sch_teql.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -257,7 +258,16 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res, if (dst->dev != dev) { struct neighbour *mn; - mn = __neigh_lookup_errno(n->tbl, n->primary_key, dev); +#if IS_ENABLED(CONFIG_IPV6) + if (n->tbl->family == AF_INET6) { + mn = ipv6_neigh_lookup(dev, n->primary_key); + if (!mn) + mn = ipv6_neigh_create(dev, n->primary_key); + } else +#endif + { + mn = __neigh_lookup_errno(n->tbl, n->primary_key, dev); + } neigh_release(n); if (IS_ERR(mn)) return PTR_ERR(mn); From f2f25d59f56a0a225447af203d73e51b4f7f92f5 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:20 +0000 Subject: [PATCH 1340/2126] ipv4: Use ipv4_neigh_lookup() and friends. It is error-prone to require callers to fetch netns and neigh_table and pass it with dev to neigh_lookup(), etc. Let's replace neigh_lookup() and friends with IPv4 helpers. Note that __neigh_lookup(create=false) is replaced with ipv4_neigh_lookup() and __neigh_lookup(create=true) and __neigh_lookup_errno() are split into ipv4_neigh_lookup() and ipv4_neigh_create(). Fixes: 2430df635a59 ("ipv4: Replace &arp_tbl with arp_table(net).") Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-8-kuniyu@google.com Signed-off-by: Jakub Kicinski --- .../marvell/prestera/prestera_router.c | 14 ++++------ .../mellanox/mlx5/core/en/tc_tun_encap.c | 3 +-- .../mellanox/mlx5/core/en_accel/ipsec.c | 6 ++--- .../ethernet/mellanox/mlxsw/spectrum_router.c | 13 +++------- .../ethernet/mellanox/mlxsw/spectrum_span.c | 7 ++--- .../netronome/nfp/flower/tunnel_conf.c | 4 +-- drivers/net/ethernet/rocker/rocker_ofdpa.c | 2 +- drivers/net/ethernet/sfc/tc_counters.c | 6 ++--- drivers/net/vxlan/vxlan_core.c | 8 ++---- net/bridge/br_arp_nd_proxy.c | 2 +- net/ipv4/arp.c | 26 ++++++++++++------- net/ipv4/fib_semantics.c | 3 +-- net/ipv4/route.c | 2 +- net/sched/sch_teql.c | 5 +++- 14 files changed, 42 insertions(+), 59 deletions(-) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_router.c b/drivers/net/ethernet/marvell/prestera/prestera_router.c index ba45b61b09bb..44c9c1fa3189 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_router.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_router.c @@ -683,8 +683,7 @@ __prestera_k_arb_n_offload_set(struct prestera_switch *sw, { struct neighbour *n; - n = neigh_lookup(arp_table(&init_net), &nc->key.addr.u.ipv4, - nc->key.dev); + n = ipv4_neigh_lookup(nc->key.dev, &nc->key.addr.u.ipv4); if (!n) return; @@ -790,7 +789,7 @@ __prestera_k_arb_nc_kern_n_fetch(struct prestera_switch *sw, int err; memset(&nc->nh_neigh_info, 0, sizeof(nc->nh_neigh_info)); - n = neigh_lookup(arp_table(&init_net), &nc->key.addr.u.ipv4, nc->key.dev); + n = ipv4_neigh_lookup(nc->key.dev, &nc->key.addr.u.ipv4); if (!n) goto out; @@ -1052,13 +1051,10 @@ static void __prestera_k_arb_hw_state_upd(struct prestera_switch *sw, #endif /* PRESTERA_IMPLICITY_RESOLVE_DEAD_NEIGH */ if (nc->key.addr.v == PRESTERA_IPV4) { - struct neigh_table *tbl = arp_table(&init_net); - - n = neigh_lookup(tbl, &nc->key.addr.u.ipv4, - nc->key.dev); + n = ipv4_neigh_lookup(nc->key.dev, &nc->key.addr.u.ipv4); if (!n) - n = neigh_create(tbl, &nc->key.addr.u.ipv4, - nc->key.dev); + n = ipv4_neigh_create(nc->key.dev, + &nc->key.addr.u.ipv4); } else { n = NULL; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c index fe0258375ef6..5e40107efa26 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c @@ -438,7 +438,6 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) if (neigh_used) { struct net_device *dev = READ_ONCE(nhe->neigh_dev); - struct net *net = dev_net(dev); nhe->reported_lastuse = jiffies; @@ -450,7 +449,7 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) n = ipv6_neigh_lookup(dev, &m_neigh->dst_ip); else #endif - n = neigh_lookup(arp_table(net), &m_neigh->dst_ip, dev); + n = ipv4_neigh_lookup(dev, &m_neigh->dst_ip); if (!n) return; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c index 37a8ddee3ea1..16edd3263aed 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c @@ -262,7 +262,6 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry, struct net_device *netdev = sa_entry->dev; struct xfrm_state *x = sa_entry->x; struct dst_entry *rt_dst_entry; - struct neigh_table *tbl; struct flowi4 fl4 = {}; struct flowi6 fl6 = {}; struct neighbour *n; @@ -365,10 +364,9 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry, return; neigh: - tbl = arp_table(dev_net(netdev)); - n = neigh_lookup(tbl, pkey, netdev); + n = ipv4_neigh_lookup(netdev, pkey); if (!n) { - n = neigh_create(tbl, pkey, netdev); + n = ipv4_neigh_create(netdev, pkey); if (IS_ERR(n)) return; neigh_event_send(n, NULL); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index ee3bc9852233..27b6b78127ac 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -2416,8 +2416,6 @@ static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp, int ent_index) { u64 max_rifs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); - struct net *net = mlxsw_sp_net(mlxsw_sp); - struct neigh_table *tbl; struct net_device *dev; struct neighbour *n; __be32 dipn; @@ -2433,10 +2431,9 @@ static void mlxsw_sp_router_neigh_ent_ipv4_process(struct mlxsw_sp *mlxsw_sp, return; } - tbl = arp_table(net); dipn = htonl(dip); dev = mlxsw_sp_rif_dev(mlxsw_sp->router->rifs[rif]); - n = neigh_lookup(tbl, &dipn, dev); + n = ipv4_neigh_lookup(dev, &dipn); if (!n) return; @@ -4301,13 +4298,10 @@ static void __mlxsw_sp_nexthop_neigh_update(struct mlxsw_sp_nexthop *nh, static struct neighbour * mlxsw_sp_nexthop_neigh_lookup(struct mlxsw_sp_nexthop *nh) { - struct neigh_table *tbl; struct net_device *dev; struct neighbour *n; - struct net *net; dev = mlxsw_sp_nexthop_dev(nh); - net = dev_net(dev); #if IS_ENABLED(CONFIG_IPV6) if (nh->family == AF_INET6) { @@ -4320,10 +4314,9 @@ mlxsw_sp_nexthop_neigh_lookup(struct mlxsw_sp_nexthop *nh) } else #endif { - tbl = arp_table(net); - n = neigh_lookup(tbl, &nh->gw_addr, dev); + n = ipv4_neigh_lookup(dev, &nh->gw_addr); if (!n) { - n = neigh_create(tbl, &nh->gw_addr, dev); + n = ipv4_neigh_create(dev, &nh->gw_addr); if (!IS_ERR(n)) neigh_event_send(n, NULL); } diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index 79947f68b10d..0b84a25e2ea8 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -229,8 +229,6 @@ static int mlxsw_sp_span_dmac(int family, struct net_device *dev, unsigned char dmac[ETH_ALEN]) { - struct net *net = dev_net(dev); - struct neigh_table *tbl; struct neighbour *neigh; int err = 0; @@ -245,10 +243,9 @@ static int mlxsw_sp_span_dmac(int family, } else #endif { - tbl = arp_table(net); - neigh = neigh_lookup(tbl, pkey, dev); + neigh = ipv4_neigh_lookup(dev, pkey); if (!neigh) { - neigh = neigh_create(tbl, pkey, dev); + neigh = ipv4_neigh_create(dev, pkey); if (IS_ERR(neigh)) return PTR_ERR(neigh); } diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c index 27d80ec8e895..3b47e9fe64e1 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c @@ -209,7 +209,6 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb) { struct nfp_tun_active_tuns *payload; struct net_device *netdev; - struct neigh_table *tbl; int count, i, pay_len; struct neighbour *n; __be32 ipv4_addr; @@ -236,8 +235,7 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb) if (!netdev) continue; - tbl = arp_table(dev_net(netdev)); - n = neigh_lookup(tbl, &ipv4_addr, netdev); + n = ipv4_neigh_lookup(netdev, &ipv4_addr); if (!n) continue; diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c index ead8b447b89c..ace69a1d5275 100644 --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c @@ -1336,7 +1336,7 @@ static int ofdpa_port_ipv4_resolve(struct ofdpa_port *ofdpa_port, int err = 0; if (!n) { - n = neigh_create(arp_table(&init_net), &ip_addr, dev); + n = ipv4_neigh_create(dev, &ip_addr); if (IS_ERR(n)) return PTR_ERR(n); } diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index ae6cc6b93864..fcb2be6abb20 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -91,7 +91,6 @@ static void efx_tc_counter_work(struct work_struct *work) struct efx_tc_action_set *act; unsigned long touched; struct neighbour *n; - struct net *net; spin_lock_bh(&cnt->lock); touched = READ_ONCE(cnt->touched); @@ -106,14 +105,13 @@ static void efx_tc_counter_work(struct work_struct *work) continue; encap->neigh->used = touched; - net = encap->neigh->net; /* We have passed traffic using this ARP entry, so * indicate to the ARP cache that it's still active */ if (encap->neigh->dst_ip) - n = neigh_lookup(arp_table(net), &encap->neigh->dst_ip, - encap->neigh->egdev); + n = ipv4_neigh_lookup(encap->neigh->egdev, + &encap->neigh->dst_ip); else #if IS_ENABLED(CONFIG_IPV6) n = ipv6_neigh_lookup(encap->neigh->egdev, diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 513779c07621..35bd92f5e460 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1877,7 +1877,6 @@ static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb) static int arp_reduce(struct net_device *dev, struct sk_buff *skb, const struct vxlan_config *cfg, __be32 vni) { - struct neigh_table *tbl = arp_table(dev_net(dev)); struct vxlan_dev *vxlan = netdev_priv(dev); struct neighbour *n; struct arphdr *parp; @@ -1914,8 +1913,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, ipv4_is_multicast(tip)) goto out; - n = neigh_lookup(tbl, &tip, dev); - + n = ipv4_neigh_lookup(dev, &tip); if (n) { struct vxlan_rdst *rdst = NULL; u8 ha[ETH_ALEN] __aligned(2); @@ -2145,7 +2143,6 @@ out: static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb, const struct vxlan_config *cfg) { - struct neigh_table *tbl; struct neighbour *n; if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) @@ -2160,9 +2157,8 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb, if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) return false; - tbl = arp_table(dev_net(dev)); pip = ip_hdr(skb); - n = neigh_lookup(tbl, &pip->daddr, dev); + n = ipv4_neigh_lookup(dev, &pip->daddr); if (!n && (cfg->flags & VXLAN_F_L3MISS)) { union vxlan_addr ipa = { .sin.sin_addr.s_addr = pip->daddr, diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index c23b99517cd5..2123344a5677 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -210,7 +210,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, return; } - n = neigh_lookup(arp_table(dev_net(vlandev)), &tip, vlandev); + n = ipv4_neigh_lookup(vlandev, &tip); if (n) { struct net_bridge_fdb_entry *f; u8 ha[ETH_ALEN] __aligned(2); diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 95f3359d0f92..1ca4ced280ae 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -892,7 +892,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) /* Update our ARP tables */ - n = __neigh_lookup(tbl, &sip, dev, 0); + n = ipv4_neigh_lookup(dev, &sip); addr_type = -1; if (n || arp_accept(in_dev, sip)) { @@ -911,9 +911,14 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) (addr_type == RTN_UNICAST || (addr_type < 0 && /* postpone calculation to as late as possible */ - inet_addr_type_dev_table(net, dev, sip) == - RTN_UNICAST))))) - n = __neigh_lookup(tbl, &sip, dev, 1); + inet_addr_type_dev_table(net, dev, sip) == RTN_UNICAST))))) { + n = ipv4_neigh_lookup(dev, &sip); + if (!n) { + n = ipv4_neigh_create(dev, &sip); + if (IS_ERR(n)) + n = NULL; + } + } } if (n) { @@ -1102,7 +1107,6 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, static int arp_req_set(struct net *net, struct arpreq *r) { - struct neigh_table *tbl = arp_table(net); struct neighbour *neigh; struct net_device *dev; __be32 ip; @@ -1138,7 +1142,9 @@ static int arp_req_set(struct net *net, struct arpreq *r) ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - neigh = __neigh_lookup_errno(tbl, &ip, dev); + neigh = ipv4_neigh_lookup(dev, &ip); + if (!neigh) + neigh = ipv4_neigh_create(dev, &ip); err = PTR_ERR(neigh); if (!IS_ERR(neigh)) { unsigned int state = NUD_STALE; @@ -1174,7 +1180,6 @@ static unsigned int arp_state_to_flags(struct neighbour *neigh) static int arp_req_get(struct net *net, struct arpreq *r) { __be32 ip = ((struct sockaddr_in *) &r->arp_pa)->sin_addr.s_addr; - struct neigh_table *tbl = arp_table(net); struct neighbour *neigh; struct net_device *dev; @@ -1185,7 +1190,7 @@ static int arp_req_get(struct net *net, struct arpreq *r) if (IS_ERR(dev)) return PTR_ERR(dev); - neigh = neigh_lookup(tbl, &ip, dev); + neigh = ipv4_neigh_lookup(dev, &ip); if (!neigh) return -ENXIO; @@ -1210,12 +1215,13 @@ static int arp_req_get(struct net *net, struct arpreq *r) int arp_invalidate(struct net_device *dev, __be32 ip, bool force) { - struct neigh_table *tbl = arp_table(dev_net(dev)); struct neighbour *neigh; int err = -ENXIO; - neigh = neigh_lookup(tbl, &ip, dev); + neigh = ipv4_neigh_lookup(dev, &ip); if (neigh) { + struct neigh_table *tbl = neigh->tbl; + if ((READ_ONCE(neigh->nud_state) & NUD_VALID) && !force) { neigh_release(neigh); return 0; diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index a98c7670d2ce..235c51a6f8e5 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -610,12 +610,11 @@ static int fib_detect_death(struct fib_info *fi, int order, int dflt) { const struct fib_nh_common *nhc = fib_info_nhc(fi, 0); - struct net *net = fi->fib_net; int state = NUD_NONE; struct neighbour *n; if (likely(nhc->nhc_gw_family == AF_INET)) - n = neigh_lookup(arp_table(net), &nhc->nhc_gw.ipv4, nhc->nhc_dev); + n = ipv4_neigh_lookup(nhc->nhc_dev, &nhc->nhc_gw.ipv4); else if (IS_ENABLED(CONFIG_IPV6) && nhc->nhc_gw_family == AF_INET6) n = ipv6_neigh_lookup(nhc->nhc_dev, &nhc->nhc_gw.ipv6); else diff --git a/net/ipv4/route.c b/net/ipv4/route.c index c7e7d7714e6e..15803e287487 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -817,7 +817,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow n = __ipv4_neigh_lookup(rt->dst.dev, (__force u32)new_gw); if (!n) - n = neigh_create(arp_table(net), &new_gw, rt->dst.dev); + n = ipv4_neigh_create(rt->dst.dev, &new_gw); if (!IS_ERR(n)) { if (!(READ_ONCE(n->nud_state) & NUD_VALID)) { neigh_event_send(n, NULL); diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c index 19ccf1a55988..e9cb7d408ca0 100644 --- a/net/sched/sch_teql.c +++ b/net/sched/sch_teql.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -266,7 +267,9 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res, } else #endif { - mn = __neigh_lookup_errno(n->tbl, n->primary_key, dev); + mn = ipv4_neigh_lookup(dev, n->primary_key); + if (!mn) + mn = ipv4_neigh_create(dev, n->primary_key); } neigh_release(n); if (IS_ERR(mn)) From 29ff0101dc00817831c6fb522301a5d9d40fd1a9 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:21 +0000 Subject: [PATCH 1341/2126] neighbour: Remove __neigh_lookup() and __neigh_lookup_errno(). Both __neigh_lookup() and __neigh_lookup_errno() not only look up but also create a new neighbour entry. The names were misleading and there was __neigh_lookup(..., 0), which should have been simply written as neigh_lookup(). Now, __neigh_lookup() has only 1 user left. Let's convert the last user to neigh_lookup() and neigh_create() and remove __neigh_lookup() and __neigh_lookup_errno(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-9-kuniyu@google.com Signed-off-by: Jakub Kicinski --- include/net/neighbour.h | 24 ------------------------ net/core/neighbour.c | 9 +++++++-- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index ed9d9ae6d3a6..79a5a548a129 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -554,30 +554,6 @@ static inline int neigh_output(struct neighbour *n, struct sk_buff *skb, return READ_ONCE(n->output)(n, skb); } -static inline struct neighbour * -__neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat) -{ - struct neighbour *n = neigh_lookup(tbl, pkey, dev); - - if (n || !creat) - return n; - - n = neigh_create(tbl, pkey, dev); - return IS_ERR(n) ? NULL : n; -} - -static inline struct neighbour * -__neigh_lookup_errno(struct neigh_table *tbl, const void *pkey, - struct net_device *dev) -{ - struct neighbour *n = neigh_lookup(tbl, pkey, dev); - - if (n) - return n; - - return neigh_create(tbl, pkey, dev); -} - struct neighbour_cb { unsigned long sched_next; unsigned int flags; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6ed8eb075146..0d883c043956 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1569,8 +1569,13 @@ struct neighbour *neigh_event_ns(struct neigh_table *tbl, u8 *lladdr, void *saddr, struct net_device *dev) { - struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev, - lladdr || !dev->addr_len); + struct neighbour *neigh = neigh_lookup(tbl, saddr, dev); + + if (!neigh && (lladdr || !dev->addr_len)) { + neigh = neigh_create(tbl, saddr, dev); + if (IS_ERR(neigh)) + neigh = NULL; + } if (neigh) neigh_update(neigh, lladdr, NUD_STALE, NEIGH_UPDATE_F_OVERRIDE, 0); From 023753192e3c2089f5236ad758b59e52fad4ead0 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Sat, 3 Oct 2026 21:23:22 +0000 Subject: [PATCH 1342/2126] neighbour: Check n->parms->tbl under tbl->lock in ___neigh_create(). Sashiko reported that if ___neigh_create() is called outside of RCU, it could create a new entry for dev in a different netns while __dev_change_net_namespace() is running concurrently: creator ipv6_neigh_create(dev, ...) tbl = nd_table(dev_net(dev)) <- old netns __dev_change_net_namespace() NETDEV_UNREGISTER rcu_barrier() dev_net_set(dev, new_net) NETDEV_REGISTER <- new in6_dev creator resumes neigh_create(old_tbl, ...) ndisc_constructor() in6_dev_get(dev) <- new in6_dev, live parms Let's check n->parms->tbl under tbl->lock. Fixes: cda2962b6e2b ("neighbour: Namespacify neigh_tables.") Reported-by: netdev-bot+sashiko@kernel.org Closes: https://lore.kernel.org/netdev/179090663305.434549.17214258093385242325@kernel.org/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Fernando Fernandez Mancera Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261003212336.1304988-10-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 0d883c043956..90335895b415 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -690,7 +690,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, hash_val = tbl->hash(n->primary_key, dev, nht->hash_rnd) >> (32 - nht->hash_shift); - if (n->parms->dead) { + if (n->parms->dead || n->parms->tbl != tbl) { rc = ERR_PTR(-EINVAL); goto out_tbl_unlock; } From 237782c3d416b392a12642f32959e9d3c94e0c26 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Thu, 1 Oct 2026 11:26:12 +0200 Subject: [PATCH 1343/2126] net: stmmac: fix TX coalesce race and div-by-zero in XDP/legacy path tx_coal_frames[] is written by ethtool (stmmac_set_coalesce) and read locklessly from the TX fast path (stmmac_xmit, stmmac_tso_xmit, stmmac_xdp_xmit_zc and stmmac_xdp_xmit_xdpf), so pair every access with READ_ONCE()/WRITE_ONCE() to mark the intentional data race and read a consistent value into a local variable. Moreover, ethtool allows disabling TX coalescing by setting tx_max_coalesced_frames to 0: guard the modulo operation in stmmac_xdp_xmit_xdpf() against a zero tx_coal_frames[queue] to avoid a division by zero. Both issues were found by code inspection while extending the XDP TX path with multi-buff support, and neither has ever been triggered, so they are only theoretical. Tested on the Qualcomm RB3-gen2 board. Fixes: db2f2842e6f5 ("net: stmmac: add per-queue TX & RX coalesce ethtool support") Fixes: be8b38a722e6 ("net: stmmac: Add support for XDP_TX action") Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261001-b4-stmmac-xmit-mb-v4-1-664e0c3eb289@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 11 ++--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 42 ++++++++----------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 1cf0f8820b33..30e0d499326d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -798,7 +798,8 @@ static int __stmmac_get_coalesce(struct net_device *dev, if (queue < tx_cnt) { ec->tx_coalesce_usecs = priv->tx_coal_timer[queue]; - ec->tx_max_coalesced_frames = priv->tx_coal_frames[queue]; + ec->tx_max_coalesced_frames = + READ_ONCE(priv->tx_coal_frames[queue]); } else { ec->tx_coalesce_usecs = 0; ec->tx_max_coalesced_frames = 0; @@ -887,14 +888,14 @@ static int __stmmac_set_coalesce(struct net_device *dev, int i; for (i = 0; i < tx_cnt; i++) { - priv->tx_coal_frames[i] = - ec->tx_max_coalesced_frames; + WRITE_ONCE(priv->tx_coal_frames[i], + ec->tx_max_coalesced_frames); priv->tx_coal_timer[i] = ec->tx_coalesce_usecs; } } else if (queue < tx_cnt) { - priv->tx_coal_frames[queue] = - ec->tx_max_coalesced_frames; + WRITE_ONCE(priv->tx_coal_frames[queue], + ec->tx_max_coalesced_frames); priv->tx_coal_timer[queue] = ec->tx_coalesce_usecs; } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 0cfd14d24002..e91da27555ab 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2732,7 +2732,8 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget) struct stmmac_metadata_request meta_req; struct xsk_tx_metadata *meta = NULL; dma_addr_t dma_addr; - bool set_ic; + bool set_ic = false; + u32 tx_coal; /* We are sharing with slow path and stop XSK TX desc submission when * available TX ring is less than threshold. @@ -2773,12 +2774,9 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget) tx_q->tx_count_frames++; - if (!priv->tx_coal_frames[queue]) - set_ic = false; - else if (tx_q->tx_count_frames % priv->tx_coal_frames[queue] == 0) + tx_coal = READ_ONCE(priv->tx_coal_frames[queue]); + if (tx_coal && !(tx_q->tx_count_frames % tx_coal)) set_ic = true; - else - set_ic = false; meta_req.priv = priv; meta_req.tx_desc = tx_desc; @@ -3420,7 +3418,7 @@ static void stmmac_init_coalesce(struct stmmac_priv *priv) for (chan = 0; chan < tx_channel_count; chan++) { struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[chan]; - priv->tx_coal_frames[chan] = STMMAC_TX_FRAMES; + WRITE_ONCE(priv->tx_coal_frames[chan], STMMAC_TX_FRAMES); priv->tx_coal_timer[chan] = STMMAC_COAL_TX_TIMER; hrtimer_setup(&tx_q->txtimer, stmmac_tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); @@ -4558,10 +4556,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) struct dma_desc *desc, *first, *mss_desc = NULL; struct stmmac_priv *priv = netdev_priv(dev); struct stmmac_txq_stats *txq_stats; + u32 tx_coal, pay_len, mss, queue; int i, first_tx, nfrags, ndesc; struct stmmac_tx_queue *tx_q; bool set_ic, is_last_segment; - u32 pay_len, mss, queue; dma_addr_t des; u8 hdr; @@ -4680,16 +4678,16 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) priv->dma_conf.dma_tx_size); tx_q->tx_count_frames += tx_packets; + tx_coal = READ_ONCE(priv->tx_coal_frames[queue]); if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && priv->hwts_tx_en) set_ic = true; - else if (!priv->tx_coal_frames[queue]) + else if (!tx_coal) set_ic = false; else if (!netdev_xmit_more()) set_ic = true; - else if (tx_packets > priv->tx_coal_frames[queue]) + else if (tx_packets > tx_coal) set_ic = true; - else if ((tx_q->tx_count_frames % - priv->tx_coal_frames[queue]) < tx_packets) + else if ((tx_q->tx_count_frames % tx_coal) < tx_packets) set_ic = true; else set_ic = false; @@ -4844,9 +4842,9 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) struct dma_desc *desc, *first_desc; struct stmmac_tx_queue *tx_q; int i, csum_insertion = 0; + u32 tx_coal, sdu_len; int entry, first_tx; dma_addr_t dma_addr; - u32 sdu_len; if (priv->tx_path_in_lpi_mode && priv->eee_sw_timer_en) stmmac_stop_sw_lpi(priv); @@ -4987,16 +4985,16 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) tx_packets = CIRC_CNT(entry + 1, first_tx, priv->dma_conf.dma_tx_size); tx_q->tx_count_frames += tx_packets; + tx_coal = READ_ONCE(priv->tx_coal_frames[queue]); if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && priv->hwts_tx_en) set_ic = true; - else if (!priv->tx_coal_frames[queue]) + else if (!tx_coal) set_ic = false; else if (!netdev_xmit_more()) set_ic = true; - else if (tx_packets > priv->tx_coal_frames[queue]) + else if (tx_packets > tx_coal) set_ic = true; - else if ((tx_q->tx_count_frames % - priv->tx_coal_frames[queue]) < tx_packets) + else if ((tx_q->tx_count_frames % tx_coal) < tx_packets) set_ic = true; else set_ic = false; @@ -5261,7 +5259,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue, enum stmmac_txbuf_type buf_type; struct dma_desc *tx_desc; dma_addr_t dma_addr; - bool set_ic; + u32 tx_coal; if (stmmac_tx_avail(priv, queue) < STMMAC_TX_THRESH(priv)) return STMMAC_XDP_CONSUMED; @@ -5306,12 +5304,8 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue, tx_q->tx_count_frames++; - if (tx_q->tx_count_frames % priv->tx_coal_frames[queue] == 0) - set_ic = true; - else - set_ic = false; - - if (set_ic) { + tx_coal = READ_ONCE(priv->tx_coal_frames[queue]); + if (tx_coal && !(tx_q->tx_count_frames % tx_coal)) { tx_q->tx_count_frames = 0; stmmac_set_tx_ic(priv, tx_desc); u64_stats_update_begin(&txq_stats->q_syncp); From 74c553648fb897b3a6e3c621564121bc60c70db1 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Thu, 1 Oct 2026 11:26:13 +0200 Subject: [PATCH 1344/2126] net: stmmac: add XDP multi-buff support for TX side Extend stmmac_xdp_xmit_xdpf() to transmit XDP frames with fragments (multi-buff). Each buffer, i.e. the frame head and every frag, is mapped and programmed into a dedicated TX descriptor. Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261001-b4-stmmac-xmit-mb-v4-2-664e0c3eb289@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 124 ++++++++++++------ .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 2 +- 2 files changed, 86 insertions(+), 40 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index e91da27555ab..b5ce00a1dea7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5252,73 +5252,119 @@ static unsigned int stmmac_rx_buf2_len(struct stmmac_priv *priv, static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue, struct xdp_frame *xdpf, bool dma_map) { - struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[queue]; + struct skb_shared_info *sinfo = xdp_get_shared_info_from_frame(xdpf); struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue]; bool csum = !priv->plat->tx_queues_cfg[queue].coe_unsupported; + unsigned int txq_thr = STMMAC_TX_THRESH(priv); + unsigned int first_entry = tx_q->cur_tx; unsigned int entry = tx_q->cur_tx; - enum stmmac_txbuf_type buf_type; - struct dma_desc *tx_desc; - dma_addr_t dma_addr; + unsigned int num_frames = 1; + struct dma_desc *desc; u32 tx_coal; + int i = 0; - if (stmmac_tx_avail(priv, queue) < STMMAC_TX_THRESH(priv)) + if (unlikely(xdp_frame_has_frags(xdpf))) + num_frames += sinfo->nr_frags; + + if (stmmac_tx_avail(priv, queue) < max(num_frames, txq_thr)) return STMMAC_XDP_CONSUMED; if (priv->est && priv->est->enable && priv->est->max_sdu[queue] && - xdpf->len > priv->est->max_sdu[queue]) { + xdp_get_frame_len(xdpf) > priv->est->max_sdu[queue]) { priv->xstats.max_sdu_txq_drop[queue]++; return STMMAC_XDP_CONSUMED; } - tx_desc = stmmac_get_tx_desc(priv, tx_q, entry); - if (dma_map) { - dma_addr = dma_map_single(priv->device, xdpf->data, - xdpf->len, DMA_TO_DEVICE); - if (dma_mapping_error(priv->device, dma_addr)) - return STMMAC_XDP_CONSUMED; + while (true) { + skb_frag_t *frag = i ? &sinfo->frags[i - 1] : NULL; + int len = frag ? skb_frag_size(frag) : xdpf->len; + bool last_frame = i == num_frames - 1; + enum stmmac_txbuf_type buf_type; + dma_addr_t dma_addr; - buf_type = STMMAC_TXBUF_T_XDP_NDO; - } else { - struct page *page = virt_to_page(xdpf->data); + desc = stmmac_get_tx_desc(priv, tx_q, entry); + if (dma_map) { + if (frag) + dma_addr = skb_frag_dma_map(priv->device, + frag, 0, len, + DMA_TO_DEVICE); + else + dma_addr = dma_map_single(priv->device, + xdpf->data, len, + DMA_TO_DEVICE); + if (dma_mapping_error(priv->device, dma_addr)) + goto error_dma_unmap; - dma_addr = page_pool_get_dma_addr(page) + sizeof(*xdpf) + - xdpf->headroom; - dma_sync_single_for_device(priv->device, dma_addr, - xdpf->len, DMA_BIDIRECTIONAL); + buf_type = STMMAC_TXBUF_T_XDP_NDO; + } else { + struct page *page; - buf_type = STMMAC_TXBUF_T_XDP_TX; + page = frag ? skb_frag_page(frag) + : virt_to_page(xdpf->data); + dma_addr = page_pool_get_dma_addr(page); + if (frag) + dma_addr += skb_frag_off(frag); + else + dma_addr += sizeof(*xdpf) + xdpf->headroom; + dma_sync_single_for_device(priv->device, dma_addr, + len, DMA_BIDIRECTIONAL); + buf_type = STMMAC_TXBUF_T_XDP_TX; + } + + stmmac_set_tx_dma_entry(tx_q, entry, buf_type, dma_addr, len, + dma_map && frag); + stmmac_set_desc_addr(priv, desc, dma_addr); + stmmac_prepare_tx_desc(priv, desc, !i, len, csum, + priv->descriptor_mode, !!i, last_frame, + xdp_get_frame_len(xdpf)); + tx_q->xdpf[entry] = last_frame ? xdpf : NULL; + if (last_frame) { + stmmac_set_tx_dma_last_segment(tx_q, entry); + break; + } + + entry = STMMAC_NEXT_ENTRY(entry, priv->dma_conf.dma_tx_size); + i++; } - - stmmac_set_tx_dma_entry(tx_q, entry, buf_type, dma_addr, xdpf->len, - false); - stmmac_set_tx_dma_last_segment(tx_q, entry); - - tx_q->xdpf[entry] = xdpf; - - stmmac_set_desc_addr(priv, tx_desc, dma_addr); - - stmmac_prepare_tx_desc(priv, tx_desc, 1, xdpf->len, - csum, priv->descriptor_mode, true, true, - xdpf->len); - - tx_q->tx_count_frames++; + tx_q->tx_count_frames += num_frames; tx_coal = READ_ONCE(priv->tx_coal_frames[queue]); - if (tx_coal && !(tx_q->tx_count_frames % tx_coal)) { + if (tx_coal && (tx_q->tx_count_frames % tx_coal) < num_frames) { + struct stmmac_txq_stats *txq_stats; + + desc = stmmac_get_tx_desc(priv, tx_q, entry); + stmmac_set_tx_ic(priv, desc); tx_q->tx_count_frames = 0; - stmmac_set_tx_ic(priv, tx_desc); + + txq_stats = &priv->xstats.txq_stats[queue]; u64_stats_update_begin(&txq_stats->q_syncp); u64_stats_inc(&txq_stats->q.tx_set_ic_bit); u64_stats_update_end(&txq_stats->q_syncp); } + /* Set the OWN bit on the first descriptor now that all descriptors + * for this xdp_frame are populated. + */ + desc = stmmac_get_tx_desc(priv, tx_q, first_entry); + dma_wmb(); + stmmac_set_tx_owner(priv, desc); + tx_q->cur_tx = STMMAC_NEXT_ENTRY(entry, priv->dma_conf.dma_tx_size); stmmac_enable_dma_transmission(priv, priv->ioaddr, queue); - entry = STMMAC_NEXT_ENTRY(entry, priv->dma_conf.dma_tx_size); - tx_q->cur_tx = entry; - return STMMAC_XDP_TX; + +error_dma_unmap: + while (first_entry != entry) { + desc = stmmac_get_tx_desc(priv, tx_q, first_entry); + stmmac_release_tx_desc(priv, desc, priv->descriptor_mode); + stmmac_free_tx_buffer(priv, &priv->dma_conf, queue, + first_entry); + first_entry = STMMAC_NEXT_ENTRY(first_entry, + priv->dma_conf.dma_tx_size); + } + + return STMMAC_XDP_CONSUMED; } static int stmmac_xdp_get_tx_queue(struct stmmac_priv *priv, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c index d7e4db7224b0..9af9e0cb366c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c @@ -135,7 +135,7 @@ int stmmac_xdp_set_prog(struct stmmac_priv *priv, struct bpf_prog *prog, stmmac_xdp_open(dev); if (prog) - xdp_features_set_redirect_target(dev, false); + xdp_features_set_redirect_target(dev, true); return 0; } From 7e6689cbbf9e6040e4ce38656a126459aa994f68 Mon Sep 17 00:00:00 2001 From: Felix Hoffmann Date: Wed, 7 Oct 2026 11:30:21 +0200 Subject: [PATCH 1345/2126] wifi: mm81x: validate YAPS receive framing The receive byte count comes from device-controlled status registers, but the packet splitter unconditionally consumes a four-byte delimiter. A count of one to three bytes therefore makes bytes_remaining negative. If the reused receive buffer contains a valid delimiter, the negative value is passed to memcpy() and converted to a near-SIZE_MAX length, corrupting kernel memory. YAPS streams are word aligned, so reject byte counts that cannot contain complete delimiters. Also reject delimiter sizes which do not leave any packet data after removing the reserved metadata page. Assisted-by: LLM Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Felix Hoffmann Link: https://patch.msgid.link/20261007093021.17132-1-f3lix.dev@gmx.de [remove Suggested-by and fix Assisted-by] Signed-off-by: Lachlan Hodges --- drivers/net/wireless/morsemicro/mm81x/yaps_hw.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c b/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c index e1102b8fb802..1d90137470c2 100644 --- a/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c +++ b/drivers/net/wireless/morsemicro/mm81x/yaps_hw.c @@ -401,16 +401,17 @@ exit: static bool mm81x_read_pkts_h_is_valid_delim(u32 delim) { u8 calc_crc = mm81x_yaps_hw_crc(delim); - int pkt_size = YAPS_DELIM_GET_PHANDLE_SIZE(delim); + int pkt_size = YAPS_DELIM_GET_PKT_SIZE(delim); int padding = YAPS_DELIM_GET_PADDING(delim); if (calc_crc != YAPS_DELIM_GET_CRC(delim)) return false; - if (pkt_size == 0) + if (pkt_size <= 0) return false; - if ((pkt_size + padding) > YAPS_MAX_PKT_SIZE_BYTES) + if ((pkt_size + YAPS_RESERVED_PAGE_SIZE + padding) > + YAPS_MAX_PKT_SIZE_BYTES) return false; /* Pkt length + padding should not require more padding */ @@ -455,6 +456,10 @@ static int mm81x_yaps_hw_read_pkts(struct mm81x_yaps *yaps, return 0; if (bytes_remaining < 0) return bytes_remaining; + if (!IS_ALIGNED(bytes_remaining, sizeof(u32))) { + dev_warn(yaps->mors->dev, "yaps truncated delimiter"); + return -EIO; + } if (bytes_remaining > YAPS_HW_WINDOW_SIZE_BYTES) { bytes_remaining = YAPS_HW_WINDOW_SIZE_BYTES; From 2a1359aa651f5e08b9c4ae3aafbb47ee64c5d281 Mon Sep 17 00:00:00 2001 From: Sang-Hoon Choi Date: Fri, 2 Oct 2026 19:47:40 +0000 Subject: [PATCH 1346/2126] sfc: handle rhashtable walk errors in mport lookup rhashtable_walk_next() can return ERR_PTR(-EAGAIN) when the table is resized. efx_mae_lookup_mport() currently dereferences that value as an mport descriptor. Skip error values and continue the walk, as the other rhashtable walkers in this driver already do. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: 5227adff37af ("sfc: add mport lookup based on driver's mport data") Reported-by: Changyul Lee Signed-off-by: Sang-Hoon Choi Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261003.final089.e0910b3ffb849fe4@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/sfc/mae.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index 7a8606efd492..b6de61062a86 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -1030,6 +1030,8 @@ int efx_mae_lookup_mport(struct efx_nic *efx, u32 vf_idx, u32 *id) rhashtable_walk_enter(&mae->mports_ht, &walk); rhashtable_walk_start(&walk); while ((m = rhashtable_walk_next(&walk)) != NULL) { + if (IS_ERR(m)) + continue; if (m->mport_type == MAE_MPORT_DESC_MPORT_TYPE_VNIC && m->interface_idx == nic_data->local_mae_intf && m->pf_idx == 0 && From f9d58127380a5370b207279a215ff1d8ce37a018 Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Sun, 4 Oct 2026 09:59:30 +0300 Subject: [PATCH 1347/2126] net: axienet: do not report TX completions as NAPI work axienet_tx_poll() reclaims every completed TX descriptor in one pass: it passes lp->tx_bd_num to axienet_free_tx_chain() as the descriptor limit, and @budget is only used as the napi_consume_skb() bulk-free hint. It then returns the number of packets reclaimed, which is bounded by the ring size rather than by the budget, so the poll can report more work than it was given. This was seen after TX completion interrupts had not been taken for a while and a full ring was reclaimed at once: eth0: NAPI poll function axienet_tx_poll+0x0/0x180 [xilinx_emac] returned 96, exceeding its budget of 64. netpoll is affected as well. poll_one_napi() polls with a budget of 0 to reclaim the TX path only, and warns once if any work is reported. TX completions are not budgeted work: Documentation/networking/napi.rst lets a poll process any number of them. Do as bcmgenet does since commit a58cdf56b6eb ("net: bcmgenet: complete Tx NAPI after one reclaim pass"): reclaim the ring, complete NAPI with no work done, re-enable the TX completion interrupt and return 0. Re-enabling the interrupt raises it straight away if more completions are already pending, so none is left behind. This also drops the extra poll that used to follow a full budget's worth of completions, which only found an empty ring. netpoll polls with a budget of 0 and must not complete NAPI, so skip the completion then; napi_complete_done() refuses it in that case anyway. Signed-off-by: Sagi Maimon Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261004065930.1004953-1-maimon.sagi@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index ae8ed4495ea0..a92171e45364 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -986,9 +986,9 @@ xmit_error_drop_skb: * axienet_tx_poll - Invoked once a transmit is completed by the * Axi DMA Tx channel. * @napi: Pointer to NAPI structure. - * @budget: Max number of TX packets to process. + * @budget: NAPI budget, or 0 when polled by netpoll. * - * Return: Number of TX packets processed. + * Return: Always 0. TX completions are not counted against the budget. * * This function is invoked from the NAPI processing to notify the completion * of transmit operation. It clears fields in the corresponding Tx BDs and @@ -1020,7 +1020,12 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget) netif_wake_queue(ndev); } - if (packets < budget && napi_complete_done(napi, packets)) { + /* The whole ring was reclaimed above, so there is nothing left to + * poll for: complete with no work done, as TX completions do not + * count against the budget. netpoll polls with a budget of 0 and + * must not complete NAPI. + */ + if (budget && napi_complete_done(napi, 0)) { /* Re-enable TX completion interrupts. This should * cause an immediate interrupt if any TX packets are * already pending. @@ -1029,7 +1034,7 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget) axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr); spin_unlock_irq(&lp->tx_cr_lock); } - return packets; + return 0; } /** From f46b52335f7690896579d1dc298b8c3caad1ca44 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 2 Oct 2026 11:59:19 +0200 Subject: [PATCH 1348/2126] eea: Drop temporary buffer by using %*pEhp directly Instead of calling string_escape_str() followed by %s specifier, use %*pEhp specifier directly. With this being done, drop temporary buffer. Note, as Sashiko pointed out in [1] the %*pEp, which is the direct substitution of the original call to string_escape_str() with ESCAPE_NP flag set, makes the whole thing like "no escape". To add some sanity to this the used specifier also includes ESCAPE_HEX. Link: https://lore.kernel.org/r/179089728102.434549.12368098081790653201@kernel.org [1] Signed-off-by: Andy Shevchenko Reviewed-by: Joe Damato Link: https://patch.msgid.link/20261002100035.863275-2-andriy.shevchenko@linux.intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/alibaba/eea/eea_adminq.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/alibaba/eea/eea_adminq.c b/drivers/net/ethernet/alibaba/eea/eea_adminq.c index 73d0caf25700..f2284fc885c3 100644 --- a/drivers/net/ethernet/alibaba/eea/eea_adminq.c +++ b/drivers/net/ethernet/alibaba/eea/eea_adminq.c @@ -522,16 +522,9 @@ void eea_adminq_config_host_info(struct eea_net *enet) dev_warn(dev, "The hardware-driven state validation may be abnormal.\n"); if (rep->has_reply) { - char buf[EEA_HINFO_MAX_REP_LEN] = {0}; - rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0'; - - string_escape_str(rep->reply_str, buf, sizeof(buf), - ESCAPE_NP, NULL); - - buf[EEA_HINFO_MAX_REP_LEN - 1] = '\0'; - - dev_warn(dev, "Device replied: %s\n", buf); + dev_warn(dev, "Device replied: %*pEhp\n", + (int)strlen(rep->reply_str), rep->reply_str); } } From c1333be192b0f4f77e8db5e4c7a4c55f1e673aae Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 2 Oct 2026 11:59:20 +0200 Subject: [PATCH 1349/2126] eea: Remove unneeded assignment The initial err is not used anywhere, drop the unneeded assignment. Signed-off-by: Andy Shevchenko Reviewed-by: Joe Damato Link: https://patch.msgid.link/20261002100035.863275-3-andriy.shevchenko@linux.intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/alibaba/eea/eea_adminq.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/alibaba/eea/eea_adminq.c b/drivers/net/ethernet/alibaba/eea/eea_adminq.c index f2284fc885c3..4876f8a1e686 100644 --- a/drivers/net/ethernet/alibaba/eea/eea_adminq.c +++ b/drivers/net/ethernet/alibaba/eea/eea_adminq.c @@ -266,7 +266,7 @@ int eea_create_adminq(struct eea_net *enet, u32 qid) u32 db_size, q_size, num; struct eea_ring *ering; struct eea_aq *aq; - int err = -ENOMEM; + int err; num = enet->edev->rx_num + enet->edev->tx_num; aq = &enet->adminq; @@ -347,11 +347,12 @@ static void qcfg_fill(struct eea_aq_create *qcfg, struct eea_ring *ering, int eea_adminq_create_q(struct eea_net *enet, u32 num, u32 flags) { - int i, db_size, q_size, err = -ENOMEM; struct eea_net_cfg *cfg; struct eea_ring *ering; + int i, db_size, q_size; struct eea_aq *aq; u32 reply_len; + int err; cfg = &enet->cfg; aq = &enet->adminq; @@ -483,7 +484,7 @@ void eea_adminq_config_host_info(struct eea_net *enet) struct device *dev = enet->edev->dma_dev; struct eea_aq_host_info_cfg *cfg; struct eea_aq_host_info_rep *rep; - int rc = -ENOMEM; + int rc; cfg = kzalloc_obj(*cfg); if (!cfg) From 8724ed6e604cbf603946c4fd2131e52ef56dc0d8 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 2 Oct 2026 11:59:21 +0200 Subject: [PATCH 1350/2126] eea: Refactor error handling in eea_adminq_config_host_info() Use traditional pattern to check for error first in eea_adminq_config_host_info(). Signed-off-by: Andy Shevchenko Reviewed-by: Joe Damato Link: https://patch.msgid.link/20261002100035.863275-4-andriy.shevchenko@linux.intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/alibaba/eea/eea_adminq.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/alibaba/eea/eea_adminq.c b/drivers/net/ethernet/alibaba/eea/eea_adminq.c index 4876f8a1e686..92eeff32b00c 100644 --- a/drivers/net/ethernet/alibaba/eea/eea_adminq.c +++ b/drivers/net/ethernet/alibaba/eea/eea_adminq.c @@ -517,18 +517,19 @@ void eea_adminq_config_host_info(struct eea_net *enet) rc = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO, cfg, sizeof(*cfg), rep, sizeof(*rep), NULL); + if (rc) + goto err_free_rep; - if (!rc) { - if (rep->op_code == EEA_HINFO_REP_BAD) - dev_warn(dev, "The hardware-driven state validation may be abnormal.\n"); + if (rep->op_code == EEA_HINFO_REP_BAD) + dev_warn(dev, "The hardware-driven state validation may be abnormal.\n"); - if (rep->has_reply) { - rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0'; - dev_warn(dev, "Device replied: %*pEhp\n", - (int)strlen(rep->reply_str), rep->reply_str); - } + if (rep->has_reply) { + rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0'; + dev_warn(dev, "Device replied: %*pEhp\n", + (int)strlen(rep->reply_str), rep->reply_str); } +err_free_rep: kfree(rep); err_free_cfg: kfree(cfg); From ecc57880bbb0f2e4df4986dee9934045322b4273 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 2 Oct 2026 11:59:23 +0200 Subject: [PATCH 1351/2126] eea: Use 2-argument strscpy() Use 2-argument strscpy(), which is not only shorter but also provides an additional check that destination buffer is an array. Signed-off-by: Andy Shevchenko Reviewed-by: Joe Damato Link: https://patch.msgid.link/20261002100035.863275-6-andriy.shevchenko@linux.intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/alibaba/eea/eea_adminq.c | 4 ++-- drivers/net/ethernet/alibaba/eea/eea_ethtool.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/alibaba/eea/eea_adminq.c b/drivers/net/ethernet/alibaba/eea/eea_adminq.c index 92eeff32b00c..8e5f4a740b95 100644 --- a/drivers/net/ethernet/alibaba/eea/eea_adminq.c +++ b/drivers/net/ethernet/alibaba/eea/eea_adminq.c @@ -512,8 +512,8 @@ void eea_adminq_config_host_info(struct eea_net *enet) cfg->pci_bdf = cpu_to_le16(eea_pci_bdf(enet->edev)); cfg->pci_domain = cpu_to_le32(eea_pci_domain_nr(enet->edev)); - strscpy(cfg->os_ver_str, utsname()->release, sizeof(cfg->os_ver_str)); - strscpy(cfg->isa_str, utsname()->machine, sizeof(cfg->isa_str)); + strscpy(cfg->os_ver_str, utsname()->release); + strscpy(cfg->isa_str, utsname()->machine); rc = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO, cfg, sizeof(*cfg), rep, sizeof(*rep), NULL); diff --git a/drivers/net/ethernet/alibaba/eea/eea_ethtool.c b/drivers/net/ethernet/alibaba/eea/eea_ethtool.c index 479779aa2dd8..15f4c7b2d898 100644 --- a/drivers/net/ethernet/alibaba/eea/eea_ethtool.c +++ b/drivers/net/ethernet/alibaba/eea/eea_ethtool.c @@ -40,8 +40,8 @@ static void eea_get_drvinfo(struct net_device *netdev, struct eea_net *enet = netdev_priv(netdev); struct eea_device *edev = enet->edev; - strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); - strscpy(info->bus_info, eea_pci_name(edev), sizeof(info->bus_info)); + strscpy(info->driver, KBUILD_MODNAME); + strscpy(info->bus_info, eea_pci_name(edev)); } static void eea_get_ringparam(struct net_device *netdev, From 2554c08e16aaeeaa7284bce64e16618f4b8cb0b7 Mon Sep 17 00:00:00 2001 From: Haseeb Malik Date: Thu, 1 Oct 2026 22:33:57 -0400 Subject: [PATCH 1352/2126] macsec: check the resolved SCI for duplicates An all-ones IFLA_MACSEC_SCI selects the default SCI derived from the MACsec device's MAC address and port 1. macsec_init_secy() resolves this value and stores the result in secy.sci, but macsec_newlink() checks for duplicates using the unchanged local sci argument. Consequently, an all-ones request can create a second MACsec device with the same transmit SCI on the same lower device, while requesting that SCI explicitly returns -EBUSY. Resolve an undefined SCI in macsec_newlink() before initializing the SecY, so initialization and duplicate detection use the same value. Preserve the all-ones fallback when the resulting SCI is available. The duplicate acceptance was flagged by Sashiko, an LLM review bot, during review of an earlier MACsec initialization fix. Source and history inspection, followed by raw-netlink checks and selftests on the unfixed kernel, confirmed the issue. Link: https://lists.openwall.net/netdev/2026/09/16/11 Signed-off-by: Haseeb Malik Link: https://patch.msgid.link/20261001-fix-macsec-duplicate-sci-v3-1-0f179fbe1f2d@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/macsec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index af8c23a322b8..409fd855235b 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4175,9 +4175,6 @@ static void macsec_init_secy(struct net_device *dev, sci_t sci, u8 icv_len) struct macsec_dev *macsec = macsec_priv(dev); struct macsec_secy *secy = &macsec->secy; - if (sci == MACSEC_UNDEF_SCI) - sci = dev_to_sci(dev, MACSEC_PORT_ES); - secy->netdev = dev; secy->operational = true; secy->key_len = DEFAULT_SAK_LEN; @@ -4210,7 +4207,7 @@ static int macsec_newlink(struct net_device *dev, u8 icv_len = MACSEC_DEFAULT_ICV_LEN; struct net_device *real_dev; int err, mtu; - sci_t sci; + sci_t sci = MACSEC_UNDEF_SCI; if (!tb[IFLA_LINK]) return -EINVAL; @@ -4263,7 +4260,8 @@ static int macsec_newlink(struct net_device *dev, sci = nla_get_sci(data[IFLA_MACSEC_SCI]); else if (data && data[IFLA_MACSEC_PORT]) sci = dev_to_sci(dev, nla_get_be16(data[IFLA_MACSEC_PORT])); - else + + if (sci == MACSEC_UNDEF_SCI) sci = dev_to_sci(dev, MACSEC_PORT_ES); /* Registration can notify listeners before returning. */ From 2dcf7c1af6896fc28e4197141580e45e98d3f6cb Mon Sep 17 00:00:00 2001 From: Haseeb Malik Date: Thu, 1 Oct 2026 22:33:58 -0400 Subject: [PATCH 1353/2126] selftests: net: test MACsec undefined SCI uniqueness Exercise duplicate transmit SCI rejection using default, explicit and all-ones SCI requests on the same lower device. Cover an all-ones request for both the first and second device, and clean up the second device if a kernel incorrectly accepts the duplicate. Also verify that an all-ones SCI still resolves to the default when a different port is already in use, and that deleting the device makes its SCI available for reuse. These cases cover the duplicate acceptance flagged by Sashiko during review of an earlier MACsec initialization fix. The same tests produce five passes and two failures before the fix, and seven passes after it. Check local iproute2 MACsec support before running the new tests. Keep the existing local and remote checks for callers supplying a configuration, without requiring remote or offload support for the new local tests. Link: https://lists.openwall.net/netdev/2026/09/16/11 Signed-off-by: Haseeb Malik Link: https://patch.msgid.link/20261001-fix-macsec-duplicate-sci-v3-2-0f179fbe1f2d@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/macsec.py | 57 ++++++++++++++++++- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/net/macsec.py b/tools/testing/selftests/drivers/net/macsec.py index 9a83d9542e04..81003bda9b0d 100755 --- a/tools/testing/selftests/drivers/net/macsec.py +++ b/tools/testing/selftests/drivers/net/macsec.py @@ -34,9 +34,10 @@ def _get_features(dev): return ethtool(f"-k {dev}", json=True)[0] -def _require_ip_macsec(cfg): - """SKIP if iproute2 on local or remote lacks 'ip macsec' support.""" - for host in [None, cfg.remote]: +def _require_ip_macsec(cfg=None): + """SKIP if iproute2 lacks MACsec locally or on cfg.remote, when given.""" + hosts = [None, cfg.remote] if cfg is not None else [None] + for host in hosts: out = cmd("ip macsec help", fail=False, host=host) if "Usage" not in out.stdout + out.stderr: where = "remote" if host else "local" @@ -263,6 +264,54 @@ def test_offload_state(cfg) -> None: "features should match first offload-on snapshot") +@ksft_variants([ + KsftNamedVariant("default", "", ""), + KsftNamedVariant("explicit", "", "sci {sci}"), + KsftNamedVariant("undefined", "", "sci ffffffffffffffff"), + KsftNamedVariant("undefined_default", "sci ffffffffffffffff", ""), + KsftNamedVariant("undefined_explicit", "sci ffffffffffffffff", "sci {sci}"), + KsftNamedVariant("undefined_twice", "sci ffffffffffffffff", + "sci ffffffffffffffff"), +]) +def test_duplicate_sci(cfg, first, second) -> None: + """Reject duplicate transmit SCIs, including the undefined-SCI fallback.""" + + _require_ip_macsec() + ms0 = _macsec_name(0) + ms1 = _macsec_name(1) + sci = _get_mac(cfg.ifname).replace(":", "") + "0001" + + ip(f"link add link {cfg.ifname} {ms0} type macsec {first}") + defer(ip, f"link del {ms0}") + with ksft_raises(CmdExitFailure): + ip(f"link add link {cfg.ifname} {ms1} type macsec " + f"{second.format(sci=sci)}") + # Clean up if the kernel incorrectly accepted the duplicate. + defer(ip, f"link del {ms1}") + + +def test_undefined_sci(cfg) -> None: + """An undefined SCI still selects the default when it is available.""" + + _require_ip_macsec() + ms0 = _macsec_name(0) + ms1 = _macsec_name(1) + sci = _get_mac(cfg.ifname).replace(":", "") + "0001" + + # A different port on the same lower device must not block the fallback. + ip(f"link add link {cfg.ifname} {ms0} type macsec port 2") + defer(ip, f"link del {ms0}") + ip(f"link add link {cfg.ifname} {ms1} type macsec sci ffffffffffffffff") + cleanup = defer(ip, f"link del {ms1}") + info = ip(f"-d link show dev {ms1}", json=True)[0] + ksft_eq(info["linkinfo"]["info_data"]["sci"], sci) + + # Deleting a device must make its SCI available again. + cleanup.exec() + ip(f"link add link {cfg.ifname} {ms1} type macsec sci ffffffffffffffff") + defer(ip, f"link del {ms1}") + + def _check_nsim_vid(cfg, vid, expected) -> None: """Checks if a VLAN is present. Only works on netdevsim.""" @@ -333,6 +382,8 @@ def main() -> None: test_max_secy, test_max_sc, test_offload_state, + test_duplicate_sci, + test_undefined_sci, test_vlan, test_vlan_toggle, ], args=(cfg,)) From 592d0fdb02dfd5f53ef50cc364aa989819792f73 Mon Sep 17 00:00:00 2001 From: Yunpeng Tian Date: Fri, 2 Oct 2026 20:50:18 -0700 Subject: [PATCH 1354/2126] tipc: bound the device MTU accepted for L2 bearers struct tipc_bearer keeps the bearer MTU in a u32 while struct tipc_link keeps the link MTU in a u16. tipc_enable_l2_media() and the NETDEV_CHANGEMTU notifier both do b->mtu = dev->mtu, tipc_link_create() assigns that into l->mtu, and tipc_link_set_queue_limits() divides by it: int max_bulk = TIPC_MAX_PUBL / (l->mtu / ITEM_SIZE); ITEM_SIZE is 20, so a device MTU of 65536 truncates to 0 and the division faults. tipc_mtu_bad() is the only check on either assignment and tests a lower bound only. The truncation defeats even that: a device MTU of 65556 passes it, yet the link comes out with l->mtu = 20, below the TIPC_MIN_BEARER_MTU the check exists to enforce, and tipc_link_mss() then evaluates 20 - INT_H_SIZE - EMSG_OVERHEAD as an int and stores it in the u32 tipc_link_entry::mtu. Read back over TIPC_NL_LINK_GET, every device MTU above 65535 leaves the link with a wrong MTU: 20 at 65556, 464 at 66000, 32768 at 98304. The bound added in commit 9f29cd8a8e79 ("tipc: fix u16 MTU truncation in media and bearer MTU validation") applies to TIPC_NLA_PROP_MTU in tipc_nl_prop_policy, which covers TIPC_NL_MEDIA_SET and TIPC_NL_BEARER_SET. A device MTU never passes through that policy. dummy sets max_mtu to 0, and dev_validate_mtu() applies its ceiling only when max_mtu is non-zero, so the device accepts 65536; a macvlan inherits max_mtu from its lower device, and two macvlans in bridge mode on one dummy carry each other's TIPC discovery frames, so the bearer reaches tipc_node_check_dest() and tipc_link_create() with b->mtu = 65536. TIPC_NL_BEARER_ENABLE is GENL_UNS_ADMIN_PERM, so an unprivileged user can do this in a user namespace of their own, on a kernel that has TIPC loaded. Oops: divide error: 0000 [#1] SMP KASAN NOPTI RIP: 0010:tipc_link_create (net/tipc/link.c:2531 net/tipc/link.c:520) Call Trace: tipc_node_check_dest (net/tipc/node.c:1284) tipc_disc_rcv (net/tipc/discover.c:252) tipc_rcv (net/tipc/node.c:2134) tipc_l2_rcv_msg (net/tipc/bearer.c:669) __netif_receive_skb_one_core (net/core/dev.c:6216) process_backlog (net/core/dev.c:6680) __napi_poll (net/core/dev.c:7739) net_rx_action (net/core/dev.c:7802) handle_softirqs (kernel/softirq.c:622) Kernel panic - not syncing: Fatal exception in interrupt Give tipc_mtu_bad() the matching upper bound, so the limit sits next to the existing minimum and one check covers both assignments. A device MTU of 65535 is still accepted and the link still comes up, with the 65532 that TIPC rounds it to. The u32 max_pkt fields became u16 mtu and advertised_mtu in commit ed193ece2649 ("tipc: simplify link mtu negotiation"), which also removed link_init_max_pkt(); that had clamped the bearer MTU to MAX_MSG_SIZE before it could reach this division. Cc: stable+noautosel@kernel.org # local DoS by userns are a dime a dozen Fixes: ed193ece2649 ("tipc: simplify link mtu negotiation") Reported-by: Gongming Wang Reported-by: Mingda Zhang Reported-by: Xiaoyu Zhou Reported-by: Qinrun Dai Signed-off-by: Yunpeng Tian Reviewed-by: Tung Nguyen Link: https://patch.msgid.link/20261003035018.397-1-shionthanatos@gmail.com Signed-off-by: Jakub Kicinski --- net/tipc/bearer.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 9ccc9ffa925a..f9bfcc9a7765 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -63,6 +63,13 @@ /* Minimum bearer MTU */ #define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE) +/* Maximum bearer MTU + * + * struct tipc_link stores the link MTU in a u16, so a larger bearer MTU would + * be truncated when a link is created on the bearer. + */ +#define TIPC_MAX_BEARER_MTU U16_MAX + /* Identifiers for distinguishing between broadcast/multicast and replicast */ #define TIPC_BROADCAST_SUPPORT 1 @@ -255,12 +262,13 @@ static inline void tipc_loopback_trace(struct net *net, tipc_clone_to_loopback(net, pkts); } -/* check if device MTU is too low for tipc headers */ +/* check if device MTU is usable for tipc bearers */ static inline bool tipc_mtu_bad(struct net_device *dev) { - if (dev->mtu >= TIPC_MIN_BEARER_MTU) + if (dev->mtu >= TIPC_MIN_BEARER_MTU && + dev->mtu <= TIPC_MAX_BEARER_MTU) return false; - netdev_warn(dev, "MTU too low for tipc bearer\n"); + netdev_warn(dev, "MTU not usable for tipc bearer\n"); return true; } From 3917a13917e6266d33cc933530c0f492a394efbc Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Mon, 5 Oct 2026 15:28:08 -0500 Subject: [PATCH 1355/2126] dt-bindings: net: Convert HiSilicon hns-dsaf to DT schema Convert the HiSilicon hns-dsaf binding to DT schema format. Drop 'phy-handle' at top level as there are no users. Add undocumented 'media-type' property. Support for 4 'reg' regions is dropped as that has long been deprecated and there are no known users of it. Signed-off-by: Rob Herring (Arm) Link: https://patch.msgid.link/20261005202808.1982164-2-robh@kernel.org Signed-off-by: Jakub Kicinski --- .../bindings/net/hisilicon,hns-dsaf-v1.yaml | 170 ++++++++++++++++++ .../bindings/net/hisilicon-hns-dsaf.txt | 90 ---------- 2 files changed, 170 insertions(+), 90 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/hisilicon,hns-dsaf-v1.yaml delete mode 100644 Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt diff --git a/Documentation/devicetree/bindings/net/hisilicon,hns-dsaf-v1.yaml b/Documentation/devicetree/bindings/net/hisilicon,hns-dsaf-v1.yaml new file mode 100644 index 000000000000..4629acbba810 --- /dev/null +++ b/Documentation/devicetree/bindings/net/hisilicon,hns-dsaf-v1.yaml @@ -0,0 +1,170 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2025 Hisilicon Ltd. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/hisilicon,hns-dsaf-v1.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hisilicon DSA Fabric device controller + +maintainers: + - Jian Shen + - Jijie Shao + +properties: + compatible: + items: + - enum: + - hisilicon,hns-dsaf-v1 + - hisilicon,hns-dsaf-v2 + + reg: + minItems: 1 + items: + - description: + PPE register base and size + - description: + DSA Fabric base register and size (not required for single-port mode) + + reg-names: + minItems: 1 + items: + - const: ppe-base + - const: dsaf-base + + interrupts: + minItems: 1 + maxItems: 409 + + dma-coherent: true + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + mode: + description: DSA Fabric mode string + $ref: /schemas/types.yaml#/definitions/string + enum: + - 2port-64vf + - 6port-16rss + - 6port-16vf + - single-port + + subctrl-syscon: + description: syscon handle for external interface control register + $ref: /schemas/types.yaml#/definitions/phandle + + reset-field-offset: + description: offset of reset field in the control register + $ref: /schemas/types.yaml#/definitions/uint32 + + buf-size: + description: RX buffer size (bytes) + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [512, 1024, 2048, 4096] + + desc-num: + description: number of descriptors in TX and RX queue + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 16 + maximum: 1024 + +patternProperties: + "^port@[0-5]$": + description: DSA Fabric port node + $ref: ethernet-switch-port.yaml# + additionalProperties: false + + properties: + reg: + maximum: 5 + + phy-handle: true + + serdes-syscon: + description: syscon handle for SerDes register + $ref: /schemas/types.yaml#/definitions/phandle + + cpld-syscon: + description: syscon handle plus register offset for CPLD register + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: CPLD phandle + - description: offset + + port-rst-offset: + description: reset field offset for this port + $ref: /schemas/types.yaml#/definitions/uint32 + + port-mode-offset: + description: port mode field offset for this port + $ref: /schemas/types.yaml#/definitions/uint32 + + mc-mac-mask: + description: multicast MAC address mask + $ref: /schemas/types.yaml#/definitions/uint8-array + maxItems: 6 + + media-type: + $ref: /schemas/types.yaml#/definitions/string + enum: + - backplane + - copper + - fiber + + required: + - reg + - serdes-syscon + +required: + - compatible + - reg + - reg-names + - interrupts + - subctrl-syscon + - mode + - buf-size + - desc-num + +additionalProperties: false + +examples: + - | + dsa@c5000000 { + compatible = "hisilicon,hns-dsaf-v1"; + #address-cells = <1>; + #size-cells = <0>; + mode = "6port-16rss"; + reg = <0xc5000000 0x890000 + 0xc7000000 0x60000>; + reg-names = "ppe-base", "dsaf-base"; + subctrl-syscon = <&subctrl>; + reset-field-offset = <0>; + interrupts = <131 4>, <132 4>, <133 4>, <134 4>, + <135 4>, <136 4>, <137 4>, <138 4>, + <139 4>, <140 4>, <141 4>, <142 4>, + <143 4>, <144 4>, <145 4>, <146 4>, + <147 4>, <148 4>, <384 1>, <385 1>, + <386 1>, <387 1>, <388 1>, <389 1>, + <390 1>, <391 1>; + buf-size = <4096>; + desc-num = <1024>; + dma-coherent; + + port@0 { + reg = <0>; + phy-handle = <&phy0>; + serdes-syscon = <&serdes>; + mc-mac-mask = [ff f0 00 00 00 00]; + }; + + port@1 { + reg = <1>; + serdes-syscon = <&serdes>; + mc-mac-mask = [ff f0 00 00 00 00]; + }; + }; diff --git a/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt b/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt deleted file mode 100644 index 8ee4b1cedae8..000000000000 --- a/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt +++ /dev/null @@ -1,90 +0,0 @@ -Hisilicon DSA Fabric device controller - -Required properties: -- compatible: should be "hisilicon,hns-dsaf-v1" or "hisilicon,hns-dsaf-v2". - "hisilicon,hns-dsaf-v1" is for hip05. - "hisilicon,hns-dsaf-v2" is for Hi1610 and Hi1612. -- mode: dsa fabric mode string. only support one of dsaf modes like these: - "2port-64vf", - "6port-16rss", - "6port-16vf", - "single-port". -- interrupts: should contain the DSA Fabric and rcb interrupt. -- reg: specifies base physical address(es) and size of the device registers. - The first region is external interface control register base and size(optional, - only used when subctrl-syscon does not exist). It is recommended using - subctrl-syscon rather than this address. - The second region is SerDes base register and size(optional, only used when - serdes-syscon in port node does not exist). It is recommended using - serdes-syscon rather than this address. - The third region is the PPE register base and size. - The fourth region is dsa fabric base register and size. It is not required for - single-port mode. -- reg-names: may be ppe-base and(or) dsaf-base. It is used to find the - corresponding reg's index. - -- phy-handle: phy handle of physical port, 0 if not any phy device. It is optional - attribute. If port node exists, phy-handle in each port node will be used. - see ethernet.txt [1]. -- subctrl-syscon: is syscon handle for external interface control register. -- reset-field-offset: is offset of reset field. Its value depends on the hardware - user manual. -- buf-size: rx buffer size, should be 16-1024. -- desc-num: number of description in TX and RX queue, should be 512, 1024, 2048 or 4096. - -- port: subnodes of dsaf. A dsaf node may contain several port nodes(Depending - on mode of dsaf). Port node contain some attributes listed below: -- reg: is physical port index in one dsaf. -- phy-handle: phy handle of physical port. It is not required if there isn't - phy device. see ethernet.txt [1]. -- serdes-syscon: is syscon handle for SerDes register. -- cpld-syscon: is syscon handle + register offset pair for cpld register. It is - not required if there isn't cpld device. -- port-rst-offset: is offset of reset field for each port in dsaf. Its value - depends on the hardware user manual. -- port-mode-offset: is offset of port mode field for each port in dsaf. Its - value depends on the hardware user manual. -- mc-mac-mask: mask of multicast address, determines bit in multicast address - to set: - 1 stands for this bit will be precisely matched, TCAM will check this bit of - MAC address. - 0 stands for this bit will be fuzzy matched, TCAM won't care about this bit - of MAC address. - -[1] Documentation/devicetree/bindings/net/phy.txt - -Example: - -dsaf0: dsa@c7000000 { - compatible = "hisilicon,hns-dsaf-v1"; - mode = "6port-16rss"; - interrupt-parent = <&mbigen_dsa>; - reg = <0x0 0xc5000000 0x0 0x890000 - 0x0 0xc7000000 0x0 0x60000>; - reg-names = "ppe-base", "dsaf-base"; - subctrl-syscon = <&subctrl>; - reset-field-offset = 0; - interrupts = <131 4>,<132 4>, <133 4>,<134 4>, - <135 4>,<136 4>, <137 4>,<138 4>, - <139 4>,<140 4>, <141 4>,<142 4>, - <143 4>,<144 4>, <145 4>,<146 4>, - <147 4>,<148 4>, <384 1>,<385 1>, - <386 1>,<387 1>, <388 1>,<389 1>, - <390 1>,<391 1>, - buf-size = <4096>; - desc-num = <1024>; - dma-coherent; - - port@0 { - reg = 0; - phy-handle = <&phy0>; - serdes-syscon = <&serdes>; - mc-mac-mask = [ff f0 00 00 00 00]; - }; - - port@1 { - reg = 1; - serdes-syscon = <&serdes>; - mc-mac-mask = [ff f0 00 00 00 00]; - }; -}; From 8c37b775c92eb03e9209605a816c2a5fc8f3a64c Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Thu, 1 Oct 2026 15:24:37 -0700 Subject: [PATCH 1356/2126] e1000e: fix IRQ leak when request_irq() fails in e1000_request_msix() An internal syzbot instance reported the warning below. comedi (comedi_parport) lets userspace request_irq() an arbitrary IRQ number and can thus grab one of e1000e's MSI-X vectors. When e1000_request_msix() then fails partway through, it returned without freeing the vectors it had already requested; pci_disable_msix() later tears those descriptors down while their irqaction is still attached, leaking the /proc/irq entry. Free the already requested IRQs on the error path. genirq: Flags mismatch irq 28. 00200000 (eth1-tx-0) vs. 00200000 (comedi_parport) remove_proc_entry: removing non-empty directory 'irq/27', leaking at least 'eth1-rx-0' WARNING: fs/proc/generic.c:742 at remove_proc_entry+0x436/0x560, CPU#3: ip/445 Modules linked in: CPU: 3 UID: 0 PID: 445 Comm: ip Not tainted 7.1.0+ #284 PREEMPT RIP: 0010:remove_proc_entry (fs/proc/generic.c:742 (discriminator 4)) PKRU: 55555554 Call Trace: unregister_irq_proc (kernel/irq/proc.c:406) free_desc (kernel/irq/irqdesc.c:482) irq_free_descs (kernel/irq/irqdesc.c:874 kernel/irq/irqdesc.c:865) irq_domain_free_irqs (kernel/irq/irqdomain.c:1917) msi_domain_free_locked.part.0 (kernel/irq/msi.c:1619 kernel/irq/msi.c:1645) msi_domain_free_irqs_all_locked (kernel/irq/msi.c:1632) pci_msi_teardown_msi_irqs (drivers/pci/msi/irqdomain.c:28) pci_free_msi_irqs (drivers/pci/msi/msi.c:925) pci_disable_msix (drivers/pci/msi/api.c:200 drivers/pci/msi/api.c:193) e1000_request_irq (drivers/net/ethernet/intel/e1000e/netdev.c:2028) e1000e_open (drivers/net/ethernet/intel/e1000e/netdev.c:4681) __dev_open (net/core/dev.c:1702) netif_change_flags (net/core/dev.c:9806) do_setlink.isra.0 (net/core/rtnetlink.c:3207 (discriminator 1)) rtnetlink_rcv_msg (net/core/rtnetlink.c:7068) netlink_rcv_skb (net/netlink/af_netlink.c:2556) Cc: stable+noautosel@kernel.org # assumes malicious PCIe device Fixes: 4662e82b2cb4 ("e1000e: add support for new 82574L part") Signed-off-by: Jiayuan Chen Reviewed-by: Dima Ruinskiy Reviewed-by: Simon Horman Reviewed-by: Piotr Kwapulinski Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261001222443.3500206-5-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/e1000e/netdev.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c index 844f31ab37ad..746a39586999 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -2111,7 +2111,7 @@ void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) static int e1000_request_msix(struct e1000_adapter *adapter) { struct net_device *netdev = adapter->netdev; - int err = 0, vector = 0; + int err = 0, vector = 0, i; if (strlen(netdev->name) < (IFNAMSIZ - 5)) snprintf(adapter->rx_ring->name, @@ -2123,7 +2123,7 @@ static int e1000_request_msix(struct e1000_adapter *adapter) e1000_intr_msix_rx, 0, adapter->rx_ring->name, netdev); if (err) - return err; + goto err_free; adapter->rx_ring->itr_register = adapter->hw.hw_addr + E1000_EITR_82574(vector); adapter->rx_ring->itr_val = adapter->itr; @@ -2139,7 +2139,7 @@ static int e1000_request_msix(struct e1000_adapter *adapter) e1000_intr_msix_tx, 0, adapter->tx_ring->name, netdev); if (err) - return err; + goto err_free; adapter->tx_ring->itr_register = adapter->hw.hw_addr + E1000_EITR_82574(vector); adapter->tx_ring->itr_val = adapter->itr; @@ -2148,11 +2148,16 @@ static int e1000_request_msix(struct e1000_adapter *adapter) err = request_irq(adapter->msix_entries[vector].vector, e1000_msix_other, 0, netdev->name, netdev); if (err) - return err; + goto err_free; e1000_configure_msix(adapter); return 0; + +err_free: + for (i = vector - 1; i >= 0; i--) + free_irq(adapter->msix_entries[i].vector, netdev); + return err; } /** From e357e76b6ca59d61d622556a5d2e3c1030c14f96 Mon Sep 17 00:00:00 2001 From: Pu Lehui Date: Thu, 1 Oct 2026 15:24:38 -0700 Subject: [PATCH 1357/2126] e1000e: Fix out-of-bounds MMIO access by validating BAR0 size Syzkaller reported a kernel panic caused by an out-of-bounds MMIO access in the e1000e driver. [ 82.868719][ T404] e1000e 0000:00:02.0: The NVM Checksum Is Not Valid [ 82.872328][ T404] Unable to handle kernel paging request at virtual address ffff80008894e090 [ 83.085218][ T404] CPU: 2 UID: 0 PID: 404 Comm: bash Not tainted 7.2.0-rc2-g3f1f75536668 #1 PREEMPTLAZY [ 83.129013][ T404] pc : e1000_get_cfg_done_82571+0x70/0x158 [ 83.140092][ T404] lr : e1000_get_cfg_done_82571+0x68/0x158 [ 83.151196][ T404] sp : ffff80008ac37410 [ 83.158922][ T404] x29: ffff80008ac37410 x28: ffff0000cd6a11b8 x27: ffff0000c58190d0 [ 83.173919][ T404] x26: ffff0000cd6a11b8 x25: ffff0000cd6a0bc0 x24: ffff0000cd6a0000 [ 83.189417][ T404] x23: 0000000000001010 x22: ffff0000cd6a11c0 x21: ffff0000cd6a11b8 [ 83.205195][ T404] x20: 0000000000000064 x19: ffff80008894e090 x18: 0000000000000000 [ 83.220545][ T404] x17: ffff800081c1a3f4 x16: ffff800081c19c10 x15: ffff800081e86510 [ 83.235764][ T404] x14: 0000000000000001 x13: 0000000000000001 x12: ffff60001bc8a8b3 [ 83.251301][ T404] x11: 1fffe0001bc8a8b2 x10: ffff60001bc8a8b2 x9 : ffff800081eae25c [ 83.266705][ T404] x8 : 00009fffe437574e x7 : ffff0000de454593 x6 : 0000000000000001 [ 83.281919][ T404] x5 : ffff0000cf2b9640 x4 : 0000000000000000 x3 : dfff800000000000 [ 83.297317][ T404] x2 : 0000000000000007 x1 : ffff0000cd6a11c0 x0 : 0000000000000000 [ 83.312601][ T404] Call trace: [ 83.318662][ T404] e1000_get_cfg_done_82571+0x70/0x158 (P) [ 83.329748][ T404] e1000e_phy_hw_reset_generic+0x17c/0x1a8 [ 83.341541][ T404] e1000_probe+0xbd8/0x1988 [ 83.350334][ T404] local_pci_probe+0x84/0x130 Repetition steps: 1. Find PCI device which BAR0 size <= 4K. If it's: Device Addr: 0000:00:02.0 BAR0 SIZE: 4K Vendor/Device ID: 0x1af4 0x1004 2. Unbind the above PCI device echo '0000:00:02.0' > /sys/bus/pci/devices/0000:00:02.0/driver/unbind 3. Set the above device to e1000e new_id echo '1af4 1004' > /sys/bus/pci/drivers/e1000e/new_id During e1000_probe(), the driver maps the device's BAR0 memory region. If the device has a 4K BAR0, ioremap() maps only 4K of space. Later in the probe process, when the NVM checksum validation fails, the driver attempts to perform a hardware reset and falls back to the err_eeprom cleanup path. This cleanup path will trigger an OOB access kernel panic: e1000_phy_hw_reset e1000e_phy_hw_reset_generic e1000_get_cfg_done_82571 er32(EEMNGCTL) readl(hw->hw_addr + EEMNGCTL); <-- EEMNGCTL(0x1010) > 4K, OOB access Fix this by verifying that the MMIO length (pci_resource_len(pdev, 0)) is at least SZ_64K before calling ioremap(). This accounts not only for standard registers up to E1000_SYSSTMPH, but also for flash registers mapped on ICH/PCH chipsets (up to offset 0xE074 / ~57.1 KB). Since PCI BAR sizes are power-of-two aligned, SZ_64K is the minimum valid BAR0 size required to ensure all subsequent MMIO accesses remain strictly within the mapped boundary. Cc: stable+noautosel@kernel.org # assumes malicious PCIe device Fixes: bc7f75fa9788 ("[E1000E]: New pci-express e1000 driver (currently for ICH9 devices only)") Signed-off-by: Pu Lehui Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261001222443.3500206-6-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/e1000e/netdev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c index 746a39586999..ad9b88c9af22 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -7455,6 +7455,12 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) mmio_len = pci_resource_len(pdev, 0); err = -EIO; + /* Smallest BAR0 that covers every register the driver accesses */ + if (mmio_len < SZ_64K) { + dev_err(&pdev->dev, "MMIO len is too small\n"); + goto err_ioremap; + } + adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); if (!adapter->hw.hw_addr) goto err_ioremap; From 47bb8dfbe1d214d6031fdd7b9215e381d9675f73 Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Sun, 4 Oct 2026 19:11:59 +0300 Subject: [PATCH 1358/2126] amt: mark relay data as a UDP tunnel packet before sending it amt_send_multicast_data() encapsulates the multicast packet in AMT + UDP + IP headers, but unlike other UDP tunnels it never calls udp_tunnel_handle_offloads(). If tx checksum offload is enabled on the amt device (off by default), GSO packets (e.g. from a UDP_SEGMENT sender) reach amt_dev_xmit() unsegmented. They are then sent with neither skb->encapsulation nor SKB_GSO_UDP_TUNNEL_CSUM set, and the lower device drops them: __udp_gso_segment() fails because csum_start does not match the (outer) transport header. Call udp_tunnel_handle_offloads(skb, true), as other UDP tunnels do. udp_csum is true because udp_tunnel_xmit_skb() is called with nocheck == false. Also reset the mac header of the copy before recording the inner headers. amt_dev_xmit() pulled the Ethernet header without moving mac_header, so inner_mac_header would point 14 bytes before the inner IP header. That makes tnl_hlen negative in __skb_udp_tunnel_segment(). Suggested-by: Eric Dumazet Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261004161200.27196-2-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 0277e4cac39b..a8236d40c2e7 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -1078,7 +1078,17 @@ static void amt_send_multicast_data(struct amt_dev *amt, if (!skb) return; + /* amt_dev_xmit() pulled the Ethernet header without moving the mac + * header. The tunnelled payload has no link-layer header, so the + * inner mac header must coincide with the inner IP header. + */ + skb_reset_mac_header(skb); skb_reset_inner_headers(skb); + if (udp_tunnel_handle_offloads(skb, true)) { + kfree_skb(skb); + return; + } + memset(&fl4, 0, sizeof(struct flowi4)); fl4.flowi4_oif = amt->stream_dev->ifindex; fl4.daddr = tunnel->ip4; From c43d4f8796dc073a6980a1640168d22950c740f7 Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Mon, 5 Oct 2026 13:38:55 +0800 Subject: [PATCH 1359/2126] wifi: rtw89: coex: fix off-by-one in H2C macro buffer full check The buffer full check used >=, which rejects a command that would exactly fill the buffer even though it still fits. Change to > so a command is only rejected when it would actually overflow hbuf. Also drop the duplicate BTC_H2C_MAXLENC definition in core.h and keep BTC_H2C_MAXLEN from coex.h as the single source of truth for the H2C macro buffer size. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261005053855.17740-1-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- drivers/net/wireless/realtek/rtw89/coex.h | 1 - drivers/net/wireless/realtek/rtw89/core.h | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index e81581e6da5a..4798868b1ea7 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -1114,7 +1114,7 @@ static int _send_fw_cmd(struct rtw89_dev *rtwdev, u8 h2c_class, u8 h2c_func, _reset_h2c_macro(btc); /* Type:1 byte, Length:2 Bytes, Data:len bytes */ - if (btc->hbuf_len + len + 3 >= BTC_H2C_MAXLEN) { + if (btc->hbuf_len + len + 3 > BTC_H2C_MAXLEN) { rtw89_debug(rtwdev, RTW89_DBG_BTC, "[BTC], %s():return by MACRO buf full(%d)\n", __func__, btc->hbuf_len + len + 3); diff --git a/drivers/net/wireless/realtek/rtw89/coex.h b/drivers/net/wireless/realtek/rtw89/coex.h index 3e9e1510c44f..38ffd0eff2c3 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.h +++ b/drivers/net/wireless/realtek/rtw89/coex.h @@ -7,7 +7,6 @@ #include "core.h" -#define BTC_H2C_MAXLEN 2020 #define BTC_TLV_SLOT_ID_LEN_V7 1 #define BTC_SLOT_REQ_TH 2 diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index a1e899576582..8a0a68e1ac31 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -4476,7 +4476,7 @@ struct rtw89_btc_btf_fwinfo { }; #define RTW89_BTC_POLICY_MAXLEN 512 -#define BTC_H2C_MAXLENC 2020 +#define BTC_H2C_MAXLEN 2020 struct rtw89_btc { const struct rtw89_btc_ver *ver; @@ -4497,7 +4497,7 @@ struct rtw89_btc { u32 bt_req_len[RTW89_PHY_NUM]; u8 policy[RTW89_BTC_POLICY_MAXLEN]; - u8 hbuf[BTC_H2C_MAXLENC]; /* H2C Macro buffer */ + u8 hbuf[BTC_H2C_MAXLEN]; /* H2C Macro buffer */ u8 hbuf_cnt; /* H2C cmd count in buffer */ u8 ant_type; u8 btg_pos; From 802f463057877e29244064dd6578ae8c4e453e6a Mon Sep 17 00:00:00 2001 From: Xinsheng Zhu Date: Mon, 5 Oct 2026 01:59:43 -0400 Subject: [PATCH 1360/2126] net: usb: r8153_ecm: reject short register reads pla_read_word() and pla_write_word() read four bytes into an uninitialized stack variable, but only check usbnet_read_cmd() for negative return values. The helper can also return a non-negative length smaller than requested, leaving part or all of tmp uninitialized. pla_read_word() may then derive the register value from uninitialized bytes. pla_write_word() may include uninitialized bytes in the buffer sent to the device during its read-modify-write operation. Require the return value to equal sizeof(tmp) before using the buffer. Return -ENODATA for short reads while preserving negative errors from usbnet_read_cmd(). Found by manual code inspection with LLM assistance. The issue has not been reproduced at runtime. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153") Signed-off-by: Xinsheng Zhu Link: https://patch.msgid.link/20261005055943.35180-1-xinsheng.zhu.ny@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/r8153_ecm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/r8153_ecm.c b/drivers/net/usb/r8153_ecm.c index 8d860dacdf49..0988a3444c55 100644 --- a/drivers/net/usb/r8153_ecm.c +++ b/drivers/net/usb/r8153_ecm.c @@ -23,8 +23,10 @@ static int pla_read_word(struct usbnet *dev, u16 index) ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index, MCU_TYPE_PLA | byen, &tmp, sizeof(tmp)); - if (ret < 0) + if (ret != sizeof(tmp)) { + ret = ret < 0 ? ret : -ENODATA; goto out; + } ret = __le32_to_cpu(tmp); ret >>= (shift * 8); @@ -55,8 +57,10 @@ static int pla_write_word(struct usbnet *dev, u16 index, u32 data) ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index, MCU_TYPE_PLA | byen, &tmp, sizeof(tmp)); - if (ret < 0) + if (ret != sizeof(tmp)) { + ret = ret < 0 ? ret : -ENODATA; goto out; + } data |= __le32_to_cpu(tmp) & ~mask; tmp = __cpu_to_le32(data); From 8df0638138d3e0344fd1fb36cf2d1ca1cf5028f0 Mon Sep 17 00:00:00 2001 From: Xinsheng Zhu Date: Mon, 5 Oct 2026 11:59:20 -0400 Subject: [PATCH 1361/2126] net: usb: sierra_net: reject short firmware attribute reads sierra_net_get_fw_attr() only checks usbnet_read_cmd() for negative return values before converting attrdata and storing it in *datap. A zero-length or one-byte response leaves attrdata wholly or partially uninitialized. Although sierra_net_bind() rejects responses of unexpected length, its dev_dbg() call uses fwattr before that check. When the debug message is enabled, the incomplete value may therefore be used in the debug output. Require the return value to equal sizeof(attrdata) before accessing the buffer. Return -EIO for short reads, retaining the existing handling of negative errors and leaving the output parameter untouched on failure. Found by manual code inspection with LLM assistance. The issue has not been reproduced at runtime. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: eb4fd8cd355c ("net/usb: add sierra_net.c driver") Signed-off-by: Xinsheng Zhu Link: https://patch.msgid.link/20261005155920.27735-1-xinsheng.zhu.ny@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/sierra_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c index 4d3ed642b3e7..95668a5ccd5f 100644 --- a/drivers/net/usb/sierra_net.c +++ b/drivers/net/usb/sierra_net.c @@ -637,7 +637,7 @@ static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap) sizeof(attrdata) /* __u16 size */ ); - if (result < 0) + if (result != sizeof(attrdata)) return -EIO; *datap = le16_to_cpu(attrdata); From 19354c4b346aeaee18a2e42e5dae60e7c1b52a5c Mon Sep 17 00:00:00 2001 From: Ching-Te Ku Date: Wed, 7 Oct 2026 09:10:55 +0800 Subject: [PATCH 1362/2126] wifi: rtw89: coex: Update Wi-Fi/Bluetooth coexistence version to 9.24.2 Update 0.35.119.3 Wi-Fi firmware support. Fix dual BT, dual MAC, MLO mechanism binding control not working issue. Fix AX/BE serial chips logic mixing error. Signed-off-by: Ching-Te Ku Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261007011057.12125-2-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/coex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 4798868b1ea7..61e8b601ca34 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -11,7 +11,7 @@ #include "ps.h" #include "reg.h" -#define RTW89_COEX_VERSION 0x09180113 +#define RTW89_COEX_VERSION 0x09180213 #define FCXDEF_STEP 50 /* MUST <= FCXMAX_STEP and match with wl fw*/ #define BTC_E2G_LIMIT_DEF 80 From 52f00f0c99ef5cd3889952bb5d0bbfac46589d8e Mon Sep 17 00:00:00 2001 From: Zong-Zhe Yang Date: Wed, 7 Oct 2026 09:10:56 +0800 Subject: [PATCH 1363/2126] wifi: rtw89: regd: add NZ/BR/AR for individual TX power settings Add NZ (New Zealand), BR (Brazil) and Add AR (Argentina) into Realtek regulatory enum. Some chipsets may need individual TX power settings for them. Signed-off-by: Zong-Zhe Yang Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261007011057.12125-3-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/core.h | 3 +++ drivers/net/wireless/realtek/rtw89/regd.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index 8a0a68e1ac31..f9c0f4923d82 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -791,6 +791,9 @@ enum rtw89_regulation_type { RTW89_QATAR = 13, RTW89_UK = 14, RTW89_THAILAND = 15, + RTW89_NZ = 16, + RTW89_BR = 17, + RTW89_AR = 18, RTW89_REGD_NUM, }; diff --git a/drivers/net/wireless/realtek/rtw89/regd.c b/drivers/net/wireless/realtek/rtw89/regd.c index 942f55633942..f0d47c313bb0 100644 --- a/drivers/net/wireless/realtek/rtw89/regd.c +++ b/drivers/net/wireless/realtek/rtw89/regd.c @@ -666,6 +666,9 @@ static const char * const rtw89_regd_string[] = { RTW89_DEF_REGD_STR(QATAR), RTW89_DEF_REGD_STR(UK), RTW89_DEF_REGD_STR(THAILAND), + RTW89_DEF_REGD_STR(NZ), + RTW89_DEF_REGD_STR(BR), + RTW89_DEF_REGD_STR(AR), }; static_assert(ARRAY_SIZE(rtw89_regd_string) == RTW89_REGD_NUM); From b706b5f2fd2480f229febfd772ffa85353d6e211 Mon Sep 17 00:00:00 2001 From: Ping-Ke Shih Date: Wed, 7 Oct 2026 09:10:57 +0800 Subject: [PATCH 1364/2126] wifi: rtw89: 8922d: update supported firmware format to 1 The firmware version 0.35.119.0 changes hw_scan format, which isn't compatible with old driver. The BT-coexistence also implements much features in firmware side until 0.35.119.3, which needs driver side implementation accordingly. The REGD table included in firmware file add NZ/BR/AR countries. Increase format to 1 to prevent old driver load the new firmware. Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261007011057.12125-4-pkshih@realtek.com --- drivers/net/wireless/realtek/rtw89/rtw8922d.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922d.c b/drivers/net/wireless/realtek/rtw89/rtw8922d.c index 271a92123158..bdf9bcf2cf22 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8922d.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8922d.c @@ -14,12 +14,12 @@ #include "sar.h" #include "util.h" -#define RTW8922D_FW_FORMAT_MAX 0 +#define RTW8922D_FW_FORMAT_MAX 1 #define RTW8922D_FW_BASENAME "rtw89/rtw8922d_fw" #define RTW8922D_MODULE_FIRMWARE \ RTW89_GEN_MODULE_FWNAME(RTW8922D_FW_BASENAME, RTW8922D_FW_FORMAT_MAX) -#define RTW8922DS_FW_FORMAT_MAX 0 +#define RTW8922DS_FW_FORMAT_MAX 1 #define RTW8922DS_FW_BASENAME "rtw89/rtw8922ds_fw" #define RTW8922DS_MODULE_FIRMWARE \ RTW89_GEN_MODULE_FWNAME(RTW8922DS_FW_BASENAME, RTW8922DS_FW_FORMAT_MAX) From 9f596b63010b681720106c0b0888aa60fcc5b6cb Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:06:55 +0200 Subject: [PATCH 1365/2126] wifi: rtw88: move the 88xxa CCK power detect setter to phy.c The CCK power detect setter in rtw88xxa.c programs values that are not specific to that chip family. The RTL8723B wants the same setter, but pulling in the whole rtw88_88xxa module for one helper is not worth it. Move it to phy.c as rtw_phy_cck_pd_set(), where the rest of the CCK power detect code and the level enum already live. rtw8812a and rtw8821a call the core version, so rtw88xxa.c no longer provides it. No logical changes have been made at all. Signed-off-by: Luka Gejak Reviewed-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-2-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/phy.c | 39 +++++++++++++++++++ drivers/net/wireless/realtek/rtw88/phy.h | 1 + drivers/net/wireless/realtek/rtw88/rtw8812a.c | 2 +- drivers/net/wireless/realtek/rtw88/rtw8821a.c | 2 +- drivers/net/wireless/realtek/rtw88/rtw88xxa.c | 38 ------------------ drivers/net/wireless/realtek/rtw88/rtw88xxa.h | 1 - 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c index e2ac5c6fd500..e2515a662bb3 100644 --- a/drivers/net/wireless/realtek/rtw88/phy.c +++ b/drivers/net/wireless/realtek/rtw88/phy.c @@ -811,6 +811,45 @@ static void rtw_phy_cck_pd(struct rtw_dev *rtwdev) chip->ops->cck_pd_set(rtwdev, level); } +void rtw_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl) +{ + static const u8 pd[CCK_PD_LV_MAX] = {0x40, 0x83, 0xcd, 0xdd, 0xed}; + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + + /* + * Override rtw_phy_cck_pd_lv_link(). It implements something + * like type 2/3/4. We need type 1 here. + */ + if (rtw_is_assoc(rtwdev)) { + if (dm_info->min_rssi > 60) { + new_lvl = CCK_PD_LV3; + } else if (dm_info->min_rssi > 35) { + new_lvl = CCK_PD_LV2; + } else if (dm_info->min_rssi > 20) { + if (dm_info->cck_fa_avg > 500) + new_lvl = CCK_PD_LV2; + else if (dm_info->cck_fa_avg < 250) + new_lvl = CCK_PD_LV1; + else + return; + } else { + new_lvl = CCK_PD_LV1; + } + } + + rtw_dbg(rtwdev, RTW_DBG_PHY, "lv: (%d) -> (%d)\n", + dm_info->cck_pd_lv[RTW_CHANNEL_WIDTH_20][RF_PATH_A], new_lvl); + + if (dm_info->cck_pd_lv[RTW_CHANNEL_WIDTH_20][RF_PATH_A] == new_lvl) + return; + + dm_info->cck_fa_avg = CCK_FA_AVG_RESET; + dm_info->cck_pd_lv[RTW_CHANNEL_WIDTH_20][RF_PATH_A] = new_lvl; + + rtw_write8(rtwdev, REG_CCK_PD_TH, pd[new_lvl]); +} +EXPORT_SYMBOL(rtw_phy_cck_pd_set); + static void rtw_phy_pwr_track(struct rtw_dev *rtwdev) { rtwdev->chip->ops->pwr_track(rtwdev); diff --git a/drivers/net/wireless/realtek/rtw88/phy.h b/drivers/net/wireless/realtek/rtw88/phy.h index 8449936497bb..8a843aac7350 100644 --- a/drivers/net/wireless/realtek/rtw88/phy.h +++ b/drivers/net/wireless/realtek/rtw88/phy.h @@ -65,6 +65,7 @@ void rtw_phy_config_swing_table(struct rtw_dev *rtwdev, struct rtw_swing_table *swing_table); void rtw_phy_set_edcca_th(struct rtw_dev *rtwdev, u8 l2h, u8 h2l); void rtw_phy_adaptivity_set_mode(struct rtw_dev *rtwdev); +void rtw_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl); void rtw_phy_parsing_cfo(struct rtw_dev *rtwdev, struct rtw_rx_pkt_stat *pkt_stat); void rtw_phy_tx_path_diversity(struct rtw_dev *rtwdev); diff --git a/drivers/net/wireless/realtek/rtw88/rtw8812a.c b/drivers/net/wireless/realtek/rtw88/rtw8812a.c index 2078eb6e3628..781b66ccde67 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8812a.c +++ b/drivers/net/wireless/realtek/rtw88/rtw8812a.c @@ -929,7 +929,7 @@ static const struct rtw_chip_ops rtw8812a_ops = { .set_ampdu_factor = NULL, .false_alarm_statistics = rtw88xxa_false_alarm_statistics, .phy_calibration = rtw8812a_phy_calibration, - .cck_pd_set = rtw88xxa_phy_cck_pd_set, + .cck_pd_set = rtw_phy_cck_pd_set, .pwr_track = rtw8812a_pwr_track, .config_bfee = NULL, .set_gid_table = NULL, diff --git a/drivers/net/wireless/realtek/rtw88/rtw8821a.c b/drivers/net/wireless/realtek/rtw88/rtw8821a.c index cab85203b828..6096d3b8e41b 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8821a.c +++ b/drivers/net/wireless/realtek/rtw88/rtw8821a.c @@ -875,7 +875,7 @@ static const struct rtw_chip_ops rtw8821a_ops = { .set_ampdu_factor = NULL, .false_alarm_statistics = rtw88xxa_false_alarm_statistics, .phy_calibration = rtw8821a_phy_calibration, - .cck_pd_set = rtw88xxa_phy_cck_pd_set, + .cck_pd_set = rtw_phy_cck_pd_set, .pwr_track = rtw8821a_pwr_track, .config_bfee = NULL, .set_gid_table = NULL, diff --git a/drivers/net/wireless/realtek/rtw88/rtw88xxa.c b/drivers/net/wireless/realtek/rtw88/rtw88xxa.c index 2eaadcfec4cb..c298fa0fb2a6 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw88xxa.c +++ b/drivers/net/wireless/realtek/rtw88/rtw88xxa.c @@ -1947,44 +1947,6 @@ iqk: } EXPORT_SYMBOL(rtw88xxa_phy_pwrtrack); -void rtw88xxa_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl) -{ - static const u8 pd[CCK_PD_LV_MAX] = {0x40, 0x83, 0xcd, 0xdd, 0xed}; - struct rtw_dm_info *dm_info = &rtwdev->dm_info; - - /* Override rtw_phy_cck_pd_lv_link(). It implements something - * like type 2/3/4. We need type 1 here. - */ - if (rtw_is_assoc(rtwdev)) { - if (dm_info->min_rssi > 60) { - new_lvl = CCK_PD_LV3; - } else if (dm_info->min_rssi > 35) { - new_lvl = CCK_PD_LV2; - } else if (dm_info->min_rssi > 20) { - if (dm_info->cck_fa_avg > 500) - new_lvl = CCK_PD_LV2; - else if (dm_info->cck_fa_avg < 250) - new_lvl = CCK_PD_LV1; - else - return; - } else { - new_lvl = CCK_PD_LV1; - } - } - - rtw_dbg(rtwdev, RTW_DBG_PHY, "lv: (%d) -> (%d)\n", - dm_info->cck_pd_lv[RTW_CHANNEL_WIDTH_20][RF_PATH_A], new_lvl); - - if (dm_info->cck_pd_lv[RTW_CHANNEL_WIDTH_20][RF_PATH_A] == new_lvl) - return; - - dm_info->cck_fa_avg = CCK_FA_AVG_RESET; - dm_info->cck_pd_lv[RTW_CHANNEL_WIDTH_20][RF_PATH_A] = new_lvl; - - rtw_write8(rtwdev, REG_CCK_PD_TH, pd[new_lvl]); -} -EXPORT_SYMBOL(rtw88xxa_phy_cck_pd_set); - MODULE_AUTHOR("Realtek Corporation"); MODULE_DESCRIPTION("Realtek 802.11ac wireless 8821a/8811a/8812a common code"); MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/wireless/realtek/rtw88/rtw88xxa.h b/drivers/net/wireless/realtek/rtw88/rtw88xxa.h index 09a45c1a4129..d9c8db58909c 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw88xxa.h +++ b/drivers/net/wireless/realtek/rtw88/rtw88xxa.h @@ -170,6 +170,5 @@ bool rtw88xxa_iqk_finish(int average, int threshold, void rtw88xxa_phy_pwrtrack(struct rtw_dev *rtwdev, void (*do_lck)(struct rtw_dev *rtwdev), void (*do_iqk)(struct rtw_dev *rtwdev)); -void rtw88xxa_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl); #endif From 6501c79b341dcb817f46c7d4671ad433adf38037 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:06:56 +0200 Subject: [PATCH 1366/2126] wifi: rtw88: 8723b: add the RTL8723B register definitions Add the register offsets and bit definitions the RTL8723B driver uses, including the power and system function bits, the BT antenna and efuse control registers, the packet lifetime and MAC ID drop registers, the FPGA0 HSSI and RF switch control registers, and the RFE antenna path registers. Signed-off-by: Luka Gejak Reviewed-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-3-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/reg.h | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/reg.h b/drivers/net/wireless/realtek/rtw88/reg.h index 0b9ba6f37680..afcdb66fdb9a 100644 --- a/drivers/net/wireless/realtek/rtw88/reg.h +++ b/drivers/net/wireless/realtek/rtw88/reg.h @@ -8,7 +8,9 @@ #define REG_SYS_FUNC_EN 0x0002 #define BIT_FEN_EN_25_1 BIT(13) #define BIT_FEN_ELDR BIT(12) +#define BIT_FEN_PPLL BIT(7) #define BIT_FEN_PCIEA BIT(6) +#define BIT_FEN_DIO_PCIE BIT(5) #define BIT_FEN_CPUEN BIT(2) #define BIT_FEN_USBA BIT(2) #define BIT_FEN_BB_GLB_RST BIT(1) @@ -19,6 +21,7 @@ #define BIT_PFM_WOWL BIT(3) #define BIT_APFM_OFFMAC BIT(9) #define REG_APS_FSMCO 0x0004 +#define BIT_EN_PDN BIT(4) #define APS_FSMCO_MAC_ENABLE BIT(8) #define APS_FSMCO_MAC_OFF BIT(9) #define APS_FSMCO_HW_POWERDOWN BIT(15) @@ -67,6 +70,9 @@ #define BIT_SHIFT_LDO25_VOLTAGE 4 #define BIT_LDO25_EN BIT(7) +#define REG_PWR_DATA 0x0038 +#define BIT_EEPRPAD_RFE_CTRL_EN BIT(11) + #define REG_ACLK_MON 0x3e #define REG_GPIO_MUXCFG 0x0040 @@ -105,6 +111,12 @@ #define BIT_BTGP_SPI_EN BIT(20) #define BIT_LED1DIS BIT(15) #define BIT_SW_DPDT_SEL_DATA BIT(0) +#define REG_BT_ANT_SEL 0x0067 +#define BIT_BT_SEL_BY_WIFI BIT(5) +/* 0x006b is the high byte of the 16 bit register at 0x006a. */ +#define REG_BT_EFUSE_CTRL 0x006b +#define BIT_BT_PWR_CUT BIT(6) +#define BIT_BT_OUT_ISO BIT(7) #define REG_WL_BT_PWR_CTRL 0x0068 #define BIT_BT_FUNC_EN BIT(18) #define BIT_BT_DIG_CLK_EN BIT(8) @@ -301,6 +313,8 @@ #define REG_HMEBOX3 0x01DC #define REG_LLT_INIT 0x01E0 #define BIT_LLT_WRITE_ACCESS BIT(30) +#define REG_RFK_FW_ACK 0x01E7 +#define BIT_RFK_FW_ACK BIT(0) #define REG_HMEBOX0_EX 0x01F0 #define REG_HMEBOX1_EX 0x01F4 #define REG_HMEBOX2_EX 0x01F8 @@ -429,6 +443,8 @@ #define REG_ARFRH5 0x04A8 #define REG_SW_AMPDU_BURST_MODE_CTRL 0x04BC #define BIT_PRE_TX_CMD BIT(6) +#define REG_PKT_VO_VI_LIFE_TIME 0x04C0 +#define REG_PKT_BE_BK_LIFE_TIME 0x04C2 #define REG_QUEUE_CTRL 0x04C6 #define BIT_PTA_WL_TX_EN BIT(4) #define BIT_PTA_EDCCA_EN BIT(5) @@ -437,6 +453,8 @@ #define REG_PROT_MODE_CTRL 0x04C8 #define REG_MAX_AGGR_NUM 0x04CA #define REG_BAR_MODE_CTRL 0x04CC +#define REG_MACID_PKT_DROP0 0x04D0 +#define REG_MACID_PKT_SLEEP 0x04D4 #define REG_PRECNT_CTRL 0x04E5 #define BIT_BTCCA_CTRL (BIT(0) | BIT(1)) #define BIT_EN_PRECNT BIT(11) @@ -520,6 +538,7 @@ #define BIT_UC_MD_EN BIT(16) #define BIT_RXSK_PERPKT BIT(15) #define BIT_HTC_LOC_CTRL BIT(14) +#define BIT_AMF BIT(13) #define BIT_RPFM_CAM_ENABLE BIT(12) #define BIT_TA_BCN BIT(11) #define BIT_RCR_ADF BIT(11) @@ -546,6 +565,7 @@ #define REG_ACKTO 0x0640 #define REG_EIFS 0x0642 #define REG_NAV_CTRL 0x0650 +#define REG_NAV_UPPER 0x0652 #define REG_WMAC_TRXPTCL_CTL 0x0668 #define BIT_RFMOD (BIT(7) | BIT(8)) #define BIT_RFMOD_80M BIT(8) @@ -581,6 +601,7 @@ #define REG_BT_COEX_V2 0x0762 #define BIT_GNT_BT_POLARITY BIT(12) #define BIT_LTE_COEX_EN BIT(7) +#define REG_BT_CONTROL 0x0764 #define REG_GNT_BT 0x0765 #define BIT_PTA_SW_CTL GENMASK(4, 3) #define REG_BT_COEX_ENH_INTR_CTRL 0x76E @@ -606,12 +627,20 @@ #define BIT_RX_PSEL_RST (BIT(28) | BIT(29)) #define REG_TXPSEL 0x080C #define REG_RX_GAIN_EN 0x081c +#define REG_FPGA0_XA_HSSI_PARM2 0x0824 +#define HSSI_3WIRE_ADDR_LEN 0x400 +#define HSSI_3WIRE_DATA_LEN 0x800 #define REG_CCASEL 0x082C +#define REG_FPGA0_XB_HSSI_PARM2 0x082C #define REG_PDMFTH 0x0830 #define REG_BWINDICATION 0x0834 #define REG_CCA2ND 0x0838 #define REG_L1PKTH 0x0848 #define REG_CLKTRK 0x0860 +#define REG_FPGA0_XA_RF_INT_OE 0x0860 +#define REG_FPGA0_XB_RF_INT_OE 0x0864 +#define REG_FPGA0_XA_RF_SW_CTRL 0x0870 +#define RFSI_RFENV 0x10 #define REG_CSI_MASK_SETTING1 0x0874 #define REG_NBI_SETTING 0x087c #define BIT_NBI_ENABLE BIT(13) @@ -630,6 +659,9 @@ #define REG_PSD 0x0910 #define BIT_PSD_INI GENMASK(23, 22) #define REG_SINGLE_TONE_CONT_TX 0x0914 +#define REG_RFE_CTRL_ANTA_SRC 0x0930 +#define REG_RFE_CTRL_ANT_SW 0x0944 +#define BIT_RFE_CTRL_ANT_SW_SEL GENMASK(1, 0) #define REG_AGC_TABLE 0x0958 #define REG_RFE_CTRL_E 0x0974 #define REG_2ND_CCA_CTRL 0x0976 @@ -649,6 +681,7 @@ #define REG_CCA_MF 0x0a20 #define BIT_MBC_WIN GENMASK(5, 4) #define REG_CCK0_TX_FILTER1 0x0a20 +#define REG_CCK_SWING 0x0a22 #define REG_CCK0_TX_FILTER2 0x0a24 #define REG_CCK0_DEBUG_PORT 0x0a28 #define REG_CCK0_FAREPORT 0x0a2c @@ -683,6 +716,7 @@ #define REG_RX_IQC_AB_A 0x0c10 #define REG_RX_IQC_CD_A 0x0c14 #define REG_TXSCALE_A 0x0c1c +#define REG_B_RXIQI 0x0c1c #define BB_SWING_MASK GENMASK(31, 21) #define REG_TX_AGC_A_CCK_11_CCK_1 0xc20 #define REG_TX_AGC_A_OFDM18_OFDM6 0xc24 From a9283c7371a3b5ea70d7a69ff0f022e9f9b3af3a Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:06:57 +0200 Subject: [PATCH 1367/2126] wifi: rtw88: 8723b: add the RTL8723B BB, RF and AGC tables Add the MAC register table and the baseband, RF and AGC parameter tables for the RTL8723B, and the transmit power limit and power by rate tables, in the layout the shared rtw88 phy code expects. The RTL8723B chip support is based on the initial work by Michael Straube . Link: https://github.com/mistraube/rtw88/tree/rtl8723bs Co-developed-by: Michael Straube Signed-off-by: Michael Straube Signed-off-by: Luka Gejak Reviewed-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-4-luka.gejak@linux.dev --- .../wireless/realtek/rtw88/rtw8723b_table.c | 861 ++++++++++++++++++ .../wireless/realtek/rtw88/rtw8723b_table.h | 17 + 2 files changed, 878 insertions(+) create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8723b_table.c create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8723b_table.h diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723b_table.c b/drivers/net/wireless/realtek/rtw88/rtw8723b_table.c new file mode 100644 index 000000000000..0e4e7213810a --- /dev/null +++ b/drivers/net/wireless/realtek/rtw88/rtw8723b_table.c @@ -0,0 +1,861 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* Copyright(c) 2026 Realtek Corporation + * Copyright(c) Michael Straube + * Copyright(c) 2024-2026 Luka Gejak + */ + +#include "main.h" +#include "phy.h" +#include "rtw8723b_table.h" + +static const u32 rtw8723b_mac[] = { + 0x02F, 0x00000030, + 0x035, 0x00000000, + 0x039, 0x00000008, + 0x064, 0x00000000, + 0x067, 0x00000020, + 0x421, 0x0000000F, + 0x428, 0x0000000A, + 0x429, 0x00000010, + 0x430, 0x00000000, + 0x431, 0x00000000, + 0x432, 0x00000000, + 0x433, 0x00000001, + 0x434, 0x00000004, + 0x435, 0x00000005, + 0x436, 0x00000007, + 0x437, 0x00000008, + 0x43C, 0x00000004, + 0x43D, 0x00000005, + 0x43E, 0x00000007, + 0x43F, 0x00000008, + 0x440, 0x0000005D, + 0x441, 0x00000001, + 0x442, 0x00000000, + 0x444, 0x00000010, + 0x445, 0x00000000, + 0x446, 0x00000000, + 0x447, 0x00000000, + 0x448, 0x00000000, + 0x449, 0x000000F0, + 0x44A, 0x0000000F, + 0x44B, 0x0000003E, + 0x44C, 0x00000010, + 0x44D, 0x00000000, + 0x44E, 0x00000000, + 0x44F, 0x00000000, + 0x450, 0x00000000, + 0x451, 0x000000F0, + 0x452, 0x0000000F, + 0x453, 0x00000000, + 0x456, 0x0000005E, + 0x460, 0x00000066, + 0x461, 0x00000066, + 0x4C8, 0x000000FF, + 0x4C9, 0x00000008, + 0x4CC, 0x000000FF, + 0x4CD, 0x000000FF, + 0x4CE, 0x00000001, + 0x500, 0x00000026, + 0x501, 0x000000A2, + 0x502, 0x0000002F, + 0x503, 0x00000000, + 0x504, 0x00000028, + 0x505, 0x000000A3, + 0x506, 0x0000005E, + 0x507, 0x00000000, + 0x508, 0x0000002B, + 0x509, 0x000000A4, + 0x50A, 0x0000005E, + 0x50B, 0x00000000, + 0x50C, 0x0000004F, + 0x50D, 0x000000A4, + 0x50E, 0x00000000, + 0x50F, 0x00000000, + 0x512, 0x0000001C, + 0x514, 0x0000000A, + 0x516, 0x0000000A, + 0x525, 0x0000004F, + 0x550, 0x00000010, + 0x551, 0x00000010, + 0x559, 0x00000002, + 0x55C, 0x00000050, + 0x55D, 0x000000FF, + 0x605, 0x00000030, + 0x608, 0x0000000E, + 0x609, 0x0000002A, + 0x620, 0x000000FF, + 0x621, 0x000000FF, + 0x622, 0x000000FF, + 0x623, 0x000000FF, + 0x624, 0x000000FF, + 0x625, 0x000000FF, + 0x626, 0x000000FF, + 0x627, 0x000000FF, + 0x638, 0x00000050, + 0x63C, 0x0000000A, + 0x63D, 0x0000000A, + 0x63E, 0x0000000E, + 0x63F, 0x0000000E, + 0x640, 0x00000040, + 0x642, 0x00000040, + 0x643, 0x00000000, + 0x652, 0x000000C8, + 0x66E, 0x00000005, + 0x700, 0x00000021, + 0x701, 0x00000043, + 0x702, 0x00000065, + 0x703, 0x00000087, + 0x708, 0x00000021, + 0x709, 0x00000043, + 0x70A, 0x00000065, + 0x70B, 0x00000087, + 0x765, 0x00000018, + 0x76E, 0x00000004, +}; + +RTW_DECL_TABLE_PHY_COND(rtw8723b_mac, rtw_phy_cfg_mac); + +static const u32 rtw8723b_agc[] = { + 0xC78, 0xFD000001, + 0xC78, 0xFC010001, + 0xC78, 0xFB020001, + 0xC78, 0xFA030001, + 0xC78, 0xF9040001, + 0xC78, 0xF8050001, + 0xC78, 0xF7060001, + 0xC78, 0xF6070001, + 0xC78, 0xF5080001, + 0xC78, 0xF4090001, + 0xC78, 0xF30A0001, + 0xC78, 0xF20B0001, + 0xC78, 0xF10C0001, + 0xC78, 0xF00D0001, + 0xC78, 0xEF0E0001, + 0xC78, 0xEE0F0001, + 0xC78, 0xED100001, + 0xC78, 0xEC110001, + 0xC78, 0xEB120001, + 0xC78, 0xEA130001, + 0xC78, 0xE9140001, + 0xC78, 0xE8150001, + 0xC78, 0xE7160001, + 0xC78, 0xE6170001, + 0xC78, 0xE5180001, + 0xC78, 0xE4190001, + 0xC78, 0xE31A0001, + 0xC78, 0xA51B0001, + 0xC78, 0xA41C0001, + 0xC78, 0xA31D0001, + 0xC78, 0x671E0001, + 0xC78, 0x661F0001, + 0xC78, 0x65200001, + 0xC78, 0x64210001, + 0xC78, 0x63220001, + 0xC78, 0x4A230001, + 0xC78, 0x49240001, + 0xC78, 0x48250001, + 0xC78, 0x47260001, + 0xC78, 0x46270001, + 0xC78, 0x45280001, + 0xC78, 0x44290001, + 0xC78, 0x432A0001, + 0xC78, 0x422B0001, + 0xC78, 0x292C0001, + 0xC78, 0x282D0001, + 0xC78, 0x272E0001, + 0xC78, 0x262F0001, + 0xC78, 0x0A300001, + 0xC78, 0x09310001, + 0xC78, 0x08320001, + 0xC78, 0x07330001, + 0xC78, 0x06340001, + 0xC78, 0x05350001, + 0xC78, 0x04360001, + 0xC78, 0x03370001, + 0xC78, 0x02380001, + 0xC78, 0x01390001, + 0xC78, 0x013A0001, + 0xC78, 0x013B0001, + 0xC78, 0x013C0001, + 0xC78, 0x013D0001, + 0xC78, 0x013E0001, + 0xC78, 0x013F0001, + 0xC78, 0xFC400001, + 0xC78, 0xFB410001, + 0xC78, 0xFA420001, + 0xC78, 0xF9430001, + 0xC78, 0xF8440001, + 0xC78, 0xF7450001, + 0xC78, 0xF6460001, + 0xC78, 0xF5470001, + 0xC78, 0xF4480001, + 0xC78, 0xF3490001, + 0xC78, 0xF24A0001, + 0xC78, 0xF14B0001, + 0xC78, 0xF04C0001, + 0xC78, 0xEF4D0001, + 0xC78, 0xEE4E0001, + 0xC78, 0xED4F0001, + 0xC78, 0xEC500001, + 0xC78, 0xEB510001, + 0xC78, 0xEA520001, + 0xC78, 0xE9530001, + 0xC78, 0xE8540001, + 0xC78, 0xE7550001, + 0xC78, 0xE6560001, + 0xC78, 0xE5570001, + 0xC78, 0xE4580001, + 0xC78, 0xE3590001, + 0xC78, 0xA65A0001, + 0xC78, 0xA55B0001, + 0xC78, 0xA45C0001, + 0xC78, 0xA35D0001, + 0xC78, 0x675E0001, + 0xC78, 0x665F0001, + 0xC78, 0x65600001, + 0xC78, 0x64610001, + 0xC78, 0x63620001, + 0xC78, 0x62630001, + 0xC78, 0x61640001, + 0xC78, 0x48650001, + 0xC78, 0x47660001, + 0xC78, 0x46670001, + 0xC78, 0x45680001, + 0xC78, 0x44690001, + 0xC78, 0x436A0001, + 0xC78, 0x426B0001, + 0xC78, 0x286C0001, + 0xC78, 0x276D0001, + 0xC78, 0x266E0001, + 0xC78, 0x256F0001, + 0xC78, 0x24700001, + 0xC78, 0x09710001, + 0xC78, 0x08720001, + 0xC78, 0x07730001, + 0xC78, 0x06740001, + 0xC78, 0x05750001, + 0xC78, 0x04760001, + 0xC78, 0x03770001, + 0xC78, 0x02780001, + 0xC78, 0x01790001, + 0xC78, 0x017A0001, + 0xC78, 0x017B0001, + 0xC78, 0x017C0001, + 0xC78, 0x017D0001, + 0xC78, 0x017E0001, + 0xC78, 0x017F0001, + 0xC50, 0x69553422, + 0xC50, 0x69553420, + 0x824, 0x00390204, +}; + +RTW_DECL_TABLE_PHY_COND(rtw8723b_agc, rtw_phy_cfg_agc); + +static const u32 rtw8723b_bb[] = { + 0x800, 0x80040000, + 0x804, 0x00000003, + 0x808, 0x0000FC00, + 0x80C, 0x0000000A, + 0x810, 0x10001331, + 0x814, 0x020C3D10, + 0x818, 0x02200385, + 0x81C, 0x00000000, + 0x820, 0x01000100, + 0x824, 0x00190204, + 0x828, 0x00000000, + 0x82C, 0x00000000, + 0x830, 0x00000000, + 0x834, 0x00000000, + 0x838, 0x00000000, + 0x83C, 0x00000000, + 0x840, 0x00010000, + 0x844, 0x00000000, + 0x848, 0x00000000, + 0x84C, 0x00000000, + 0x850, 0x00000000, + 0x854, 0x00000000, + 0x858, 0x569A11A9, + 0x85C, 0x01000014, + 0x860, 0x66F60110, + 0x864, 0x061F0649, + 0x868, 0x00000000, + 0x86C, 0x27272700, + 0x870, 0x07000760, + 0x874, 0x25004000, + 0x878, 0x00000808, + 0x87C, 0x00000000, + 0x880, 0xB0000C1C, + 0x884, 0x00000001, + 0x888, 0x00000000, + 0x88C, 0xCCC000C0, + 0x890, 0x00000800, + 0x894, 0xFFFFFFFE, + 0x898, 0x40302010, + 0x89C, 0x00706050, + 0x900, 0x00000000, + 0x904, 0x00000023, + 0x908, 0x00000000, + 0x90C, 0x81121111, + 0x910, 0x00000002, + 0x914, 0x00000201, + 0xA00, 0x00D047C8, + 0xA04, 0x80FF800C, + 0xA08, 0x8C838300, + 0xA0C, 0x2E7F120F, + 0xA10, 0x9500BB78, + 0xA14, 0x1114D028, + 0xA18, 0x00881117, + 0xA1C, 0x89140F00, + 0xA20, 0x1A1B0000, + 0xA24, 0x090E1317, + 0xA28, 0x00000204, + 0xA2C, 0x00D30000, + 0xA70, 0x101FBF00, + 0xA74, 0x00000007, + 0xA78, 0x00000900, + 0xA7C, 0x225B0606, + 0xA80, 0x21806490, + 0xB2C, 0x00000000, + 0xC00, 0x48071D40, + 0xC04, 0x03A05611, + 0xC08, 0x000000E4, + 0xC0C, 0x6C6C6C6C, + 0xC10, 0x08800000, + 0xC14, 0x40000100, + 0xC18, 0x08800000, + 0xC1C, 0x40000100, + 0xC20, 0x00000000, + 0xC24, 0x00000000, + 0xC28, 0x00000000, + 0xC2C, 0x00000000, + 0xC30, 0x69E9AC44, + 0xC34, 0x469652AF, + 0xC38, 0x49795994, + 0xC3C, 0x0A97971C, + 0xC40, 0x1F7C403F, + 0xC44, 0x000100B7, + 0xC48, 0xEC020107, + 0xC4C, 0x007F037F, + 0xC50, 0x69553420, + 0xC54, 0x43BC0094, + 0xC58, 0x00013147, + 0xC5C, 0x00250492, + 0xC60, 0x00000000, + 0xC64, 0x5112848B, + 0xC68, 0x47C00BFF, + 0xC6C, 0x00000036, + 0xC70, 0x2C7F000D, + 0xC74, 0x020610DB, + 0xC78, 0x0000001F, + 0xC7C, 0x00B91612, + 0xC80, 0x390000E4, + 0xC84, 0x21F60000, + 0xC88, 0x40000100, + 0xC8C, 0x20200000, + 0xC90, 0x00020E1A, + 0xC94, 0x00000000, + 0xC98, 0x00020E1A, + 0xC9C, 0x00007F7F, + 0xCA0, 0x00000000, + 0xCA4, 0x000300A0, + 0xCA8, 0x00000000, + 0xCAC, 0x00000000, + 0xCB0, 0x00000000, + 0xCB4, 0x00000000, + 0xCB8, 0x00000000, + 0xCBC, 0x28000000, + 0xCC0, 0x00000000, + 0xCC4, 0x00000000, + 0xCC8, 0x00000000, + 0xCCC, 0x00000000, + 0xCD0, 0x00000000, + 0xCD4, 0x00000000, + 0xCD8, 0x64B22427, + 0xCDC, 0x00766932, + 0xCE0, 0x00222222, + 0xCE4, 0x00000000, + 0xCE8, 0x37644302, + 0xCEC, 0x2F97D40C, + 0xD00, 0x00000740, + 0xD04, 0x40020401, + 0xD08, 0x0000907F, + 0xD0C, 0x20010201, + 0xD10, 0xA0633333, + 0xD14, 0x3333BC53, + 0xD18, 0x7A8F5B6F, + 0xD2C, 0xCC979975, + 0xD30, 0x00000000, + 0xD34, 0x80608000, + 0xD38, 0x00000000, + 0xD3C, 0x00127353, + 0xD40, 0x00000000, + 0xD44, 0x00000000, + 0xD48, 0x00000000, + 0xD4C, 0x00000000, + 0xD50, 0x6437140A, + 0xD54, 0x00000000, + 0xD58, 0x00000282, + 0xD5C, 0x30032064, + 0xD60, 0x4653DE68, + 0xD64, 0x04518A3C, + 0xD68, 0x00002101, + 0xD6C, 0x2A201C16, + 0xD70, 0x1812362E, + 0xD74, 0x322C2220, + 0xD78, 0x000E3C24, + 0xE00, 0x2D2D2D2D, + 0xE04, 0x2D2D2D2D, + 0xE08, 0x0390272D, + 0xE10, 0x2D2D2D2D, + 0xE14, 0x2D2D2D2D, + 0xE18, 0x2D2D2D2D, + 0xE1C, 0x2D2D2D2D, + 0xE28, 0x00000000, + 0xE30, 0x1000DC1F, + 0xE34, 0x10008C1F, + 0xE38, 0x02140102, + 0xE3C, 0x681604C2, + 0xE40, 0x01007C00, + 0xE44, 0x01004800, + 0xE48, 0xFB000000, + 0xE4C, 0x000028D1, + 0xE50, 0x1000DC1F, + 0xE54, 0x10008C1F, + 0xE58, 0x02140102, + 0xE5C, 0x28160D05, + 0xE60, 0x00000048, + 0xE68, 0x001B2556, + 0xE6C, 0x00C00096, + 0xE70, 0x00C00096, + 0xE74, 0x01000056, + 0xE78, 0x01000014, + 0xE7C, 0x01000056, + 0xE80, 0x01000014, + 0xE84, 0x00C00096, + 0xE88, 0x01000056, + 0xE8C, 0x00C00096, + 0xED0, 0x00C00096, + 0xED4, 0x00C00096, + 0xED8, 0x00C00096, + 0xEDC, 0x000000D6, + 0xEE0, 0x000000D6, + 0xEEC, 0x01C00016, + 0xF14, 0x00000003, + 0xF4C, 0x00000000, + 0xF00, 0x00000300, + 0x820, 0x01000100, + 0x800, 0x83040000, +}; + +RTW_DECL_TABLE_PHY_COND(rtw8723b_bb, rtw_phy_cfg_bb); + +static const struct rtw_phy_pg_cfg_pair rtw8723b_bb_pg[] = { + { 0, 0, 0, 0x00000e08, 0x0000ff00, 0x00003800, }, + { 0, 0, 0, 0x0000086c, 0xffffff00, 0x32343600, }, + { 0, 0, 0, 0x00000e00, 0xffffffff, 0x40424444, }, + { 0, 0, 0, 0x00000e04, 0xffffffff, 0x28323638, }, + { 0, 0, 0, 0x00000e10, 0xffffffff, 0x38404244, }, + { 0, 0, 0, 0x00000e14, 0xffffffff, 0x26303436, }, +}; + +RTW_DECL_TABLE_BB_PG(rtw8723b_bb_pg); + +static const u32 rtw8723b_rf_a[] = { + 0x000, 0x00010000, + 0x0B0, 0x000DFFE0, + 0xFFE, 0x00000000, + 0xFFE, 0x00000000, + 0xFFE, 0x00000000, + 0x0B1, 0x00000018, + 0xFFE, 0x00000000, + 0xFFE, 0x00000000, + 0xFFE, 0x00000000, + 0x0B2, 0x00084C00, + 0x0B5, 0x0000D2CC, + 0x0B6, 0x000925AA, + 0x0B7, 0x00000010, + 0x0B8, 0x0000907F, + 0x05C, 0x00000002, + 0x07C, 0x00000002, + 0x07E, 0x00000005, + 0x08B, 0x0006FC00, + 0x0B0, 0x000FF9F0, + 0x01C, 0x000739D2, + 0x01E, 0x00000000, + 0x0DF, 0x00000780, + 0x050, 0x00067435, + 0x80002000, 0x00000000, 0x40000000, 0x00000000, + 0x051, 0x0006F10E, + 0x052, 0x000007D3, + 0x90003000, 0x00000000, 0x40000000, 0x00000000, + 0x051, 0x0006F10E, + 0x052, 0x000007D3, + 0x90004000, 0x00000000, 0x40000000, 0x00000000, + 0x051, 0x0006F10E, + 0x052, 0x000007D3, + 0xA0000000, 0x00000000, + 0x051, 0x0006B04E, + 0x052, 0x000007D2, + 0xB0000000, 0x00000000, + 0x053, 0x00000000, + 0x054, 0x00050400, + 0x055, 0x0004026E, + 0x0DD, 0x0000004C, + 0x070, 0x00067435, + 0x80002000, 0x00000000, 0x40000000, 0x00000000, + 0x071, 0x0006F10E, + 0x072, 0x000007D3, + 0x90003000, 0x00000000, 0x40000000, 0x00000000, + 0x071, 0x0006F10E, + 0x072, 0x000007D3, + 0x90004000, 0x00000000, 0x40000000, 0x00000000, + 0x071, 0x0006F10E, + 0x072, 0x000007D3, + 0xA0000000, 0x00000000, + 0x071, 0x0006B04E, + 0x072, 0x000007D2, + 0xB0000000, 0x00000000, + 0x073, 0x00000000, + 0x074, 0x00050400, + 0x075, 0x0004026E, + 0x0EF, 0x00000100, + 0x034, 0x0000ADD7, + 0x035, 0x00005C00, + 0x034, 0x00009DD4, + 0x035, 0x00005000, + 0x034, 0x00008DD1, + 0x035, 0x00004400, + 0x034, 0x00007DCE, + 0x035, 0x00003800, + 0x034, 0x00006CD1, + 0x035, 0x00004400, + 0x034, 0x00005CCE, + 0x035, 0x00003800, + 0x034, 0x000048CE, + 0x035, 0x00004400, + 0x034, 0x000034CE, + 0x035, 0x00003800, + 0x034, 0x00002451, + 0x035, 0x00004400, + 0x034, 0x0000144E, + 0x035, 0x00003800, + 0x034, 0x00000051, + 0x035, 0x00004400, + 0x0EF, 0x00000000, + 0x0EF, 0x00000100, + 0x0ED, 0x00000010, + 0x044, 0x0000ADD7, + 0x044, 0x00009DD4, + 0x044, 0x00008DD1, + 0x044, 0x00007DCE, + 0x044, 0x00006CC1, + 0x044, 0x00005CCE, + 0x044, 0x000044D1, + 0x044, 0x000034CE, + 0x044, 0x00002451, + 0x044, 0x0000144E, + 0x044, 0x00000051, + 0x0EF, 0x00000000, + 0x0ED, 0x00000000, + 0x07F, 0x00020080, + 0x0EF, 0x00002000, + 0x03B, 0x000389EF, + 0x03B, 0x000302FE, + 0x03B, 0x00028CE6, + 0x03B, 0x000200BC, + 0x03B, 0x000188A5, + 0x03B, 0x00010FBC, + 0x03B, 0x00008F71, + 0x03B, 0x00000900, + 0x0EF, 0x00000000, + 0x0ED, 0x00000001, + 0x040, 0x000380EF, + 0x040, 0x000302FE, + 0x040, 0x00028CE6, + 0x040, 0x000200BC, + 0x040, 0x000188A5, + 0x040, 0x00010FBC, + 0x040, 0x00008F71, + 0x040, 0x00000900, + 0x0ED, 0x00000000, + 0x082, 0x00080000, + 0x083, 0x00008000, + 0x084, 0x00049F80, + 0x085, 0x00068000, + 0x0A2, 0x00080000, + 0x0A3, 0x00008000, + 0x0A4, 0x00048D80, + 0x0A5, 0x00068000, + 0x0ED, 0x00000002, + 0x0EF, 0x00000002, + 0x056, 0x00000032, + 0x076, 0x00000032, + 0x01F, 0x00001008, + 0x001, 0x00000780, +}; + +RTW_DECL_TABLE_RF_RADIO(rtw8723b_rf_a, A); + +/* + * Regd: FCC -> 0, ETSI -> 2, MKK -> 1 + * Band: 2.4G -> 0, 5G -> 1 + * Bandwidth (bw): 20M -> 0, 40M -> 1, 80M -> 2, 160M -> 3 + * Rate Section (rs): CCK -> 0, OFDM -> 1, HT -> 2, VHT -> 3 + */ +static const struct rtw_txpwr_lmt_cfg_pair rtw8723b_txpwr_lmt[] = { + {0, 0, 0, 0, 1, 30}, + {2, 0, 0, 0, 1, 26}, + {1, 0, 0, 0, 1, 32}, + {0, 0, 0, 0, 2, 30}, + {2, 0, 0, 0, 2, 26}, + {1, 0, 0, 0, 2, 32}, + {0, 0, 0, 0, 3, 30}, + {2, 0, 0, 0, 3, 26}, + {1, 0, 0, 0, 3, 32}, + {0, 0, 0, 0, 4, 30}, + {2, 0, 0, 0, 4, 26}, + {1, 0, 0, 0, 4, 32}, + {0, 0, 0, 0, 5, 30}, + {2, 0, 0, 0, 5, 26}, + {1, 0, 0, 0, 5, 32}, + {0, 0, 0, 0, 6, 30}, + {2, 0, 0, 0, 6, 26}, + {1, 0, 0, 0, 6, 32}, + {0, 0, 0, 0, 7, 30}, + {2, 0, 0, 0, 7, 26}, + {1, 0, 0, 0, 7, 32}, + {0, 0, 0, 0, 8, 30}, + {2, 0, 0, 0, 8, 26}, + {1, 0, 0, 0, 8, 32}, + {0, 0, 0, 0, 9, 30}, + {2, 0, 0, 0, 9, 26}, + {1, 0, 0, 0, 9, 32}, + {0, 0, 0, 0, 10, 30}, + {2, 0, 0, 0, 10, 26}, + {1, 0, 0, 0, 10, 32}, + {0, 0, 0, 0, 11, 30}, + {2, 0, 0, 0, 11, 26}, + {1, 0, 0, 0, 11, 32}, + {0, 0, 0, 0, 12, 63}, + {2, 0, 0, 0, 12, 26}, + {1, 0, 0, 0, 12, 32}, + {0, 0, 0, 0, 13, 63}, + {2, 0, 0, 0, 13, 26}, + {1, 0, 0, 0, 13, 32}, + {0, 0, 0, 0, 14, 63}, + {2, 0, 0, 0, 14, 63}, + {1, 0, 0, 0, 14, 32}, + {0, 0, 0, 1, 1, 28}, + {2, 0, 0, 1, 1, 28}, + {1, 0, 0, 1, 1, 28}, + {0, 0, 0, 1, 2, 28}, + {2, 0, 0, 1, 2, 32}, + {1, 0, 0, 1, 2, 32}, + {0, 0, 0, 1, 3, 32}, + {2, 0, 0, 1, 3, 32}, + {1, 0, 0, 1, 3, 32}, + {0, 0, 0, 1, 4, 32}, + {2, 0, 0, 1, 4, 32}, + {1, 0, 0, 1, 4, 32}, + {0, 0, 0, 1, 5, 32}, + {2, 0, 0, 1, 5, 32}, + {1, 0, 0, 1, 5, 32}, + {0, 0, 0, 1, 6, 32}, + {2, 0, 0, 1, 6, 32}, + {1, 0, 0, 1, 6, 32}, + {0, 0, 0, 1, 7, 32}, + {2, 0, 0, 1, 7, 32}, + {1, 0, 0, 1, 7, 32}, + {0, 0, 0, 1, 8, 32}, + {2, 0, 0, 1, 8, 32}, + {1, 0, 0, 1, 8, 32}, + {0, 0, 0, 1, 9, 32}, + {2, 0, 0, 1, 9, 32}, + {1, 0, 0, 1, 9, 32}, + {0, 0, 0, 1, 10, 28}, + {2, 0, 0, 1, 10, 32}, + {1, 0, 0, 1, 10, 32}, + {0, 0, 0, 1, 11, 28}, + {2, 0, 0, 1, 11, 32}, + {1, 0, 0, 1, 11, 32}, + {0, 0, 0, 1, 12, 63}, + {2, 0, 0, 1, 12, 32}, + {1, 0, 0, 1, 12, 32}, + {0, 0, 0, 1, 13, 63}, + {2, 0, 0, 1, 13, 28}, + {1, 0, 0, 1, 13, 28}, + {0, 0, 0, 1, 14, 63}, + {2, 0, 0, 1, 14, 63}, + {1, 0, 0, 1, 14, 63}, + {0, 0, 0, 2, 1, 26}, + {2, 0, 0, 2, 1, 26}, + {1, 0, 0, 2, 1, 28}, + {0, 0, 0, 2, 2, 26}, + {2, 0, 0, 2, 2, 32}, + {1, 0, 0, 2, 2, 32}, + {0, 0, 0, 2, 3, 32}, + {2, 0, 0, 2, 3, 32}, + {1, 0, 0, 2, 3, 32}, + {0, 0, 0, 2, 4, 32}, + {2, 0, 0, 2, 4, 32}, + {1, 0, 0, 2, 4, 32}, + {0, 0, 0, 2, 5, 32}, + {2, 0, 0, 2, 5, 32}, + {1, 0, 0, 2, 5, 32}, + {0, 0, 0, 2, 6, 32}, + {2, 0, 0, 2, 6, 32}, + {1, 0, 0, 2, 6, 32}, + {0, 0, 0, 2, 7, 32}, + {2, 0, 0, 2, 7, 32}, + {1, 0, 0, 2, 7, 32}, + {0, 0, 0, 2, 8, 32}, + {2, 0, 0, 2, 8, 32}, + {1, 0, 0, 2, 8, 32}, + {0, 0, 0, 2, 9, 32}, + {2, 0, 0, 2, 9, 32}, + {1, 0, 0, 2, 9, 32}, + {0, 0, 0, 2, 10, 26}, + {2, 0, 0, 2, 10, 32}, + {1, 0, 0, 2, 10, 32}, + {0, 0, 0, 2, 11, 26}, + {2, 0, 0, 2, 11, 32}, + {1, 0, 0, 2, 11, 32}, + {0, 0, 0, 2, 12, 63}, + {2, 0, 0, 2, 12, 32}, + {1, 0, 0, 2, 12, 32}, + {0, 0, 0, 2, 13, 63}, + {2, 0, 0, 2, 13, 26}, + {1, 0, 0, 2, 13, 28}, + {0, 0, 0, 2, 14, 63}, + {2, 0, 0, 2, 14, 63}, + {1, 0, 0, 2, 14, 63}, + {0, 0, 0, 2, 1, 30}, + {2, 0, 0, 2, 1, 32}, + {1, 0, 0, 2, 1, 32}, + {0, 0, 0, 2, 2, 32}, + {2, 0, 0, 2, 2, 32}, + {1, 0, 0, 2, 2, 32}, + {0, 0, 0, 2, 3, 32}, + {2, 0, 0, 2, 3, 32}, + {1, 0, 0, 2, 3, 32}, + {0, 0, 0, 2, 4, 32}, + {2, 0, 0, 2, 4, 32}, + {1, 0, 0, 2, 4, 32}, + {0, 0, 0, 2, 5, 32}, + {2, 0, 0, 2, 5, 32}, + {1, 0, 0, 2, 5, 32}, + {0, 0, 0, 2, 6, 32}, + {2, 0, 0, 2, 6, 32}, + {1, 0, 0, 2, 6, 32}, + {0, 0, 0, 2, 7, 32}, + {2, 0, 0, 2, 7, 32}, + {1, 0, 0, 2, 7, 32}, + {0, 0, 0, 2, 8, 32}, + {2, 0, 0, 2, 8, 32}, + {1, 0, 0, 2, 8, 32}, + {0, 0, 0, 2, 9, 32}, + {2, 0, 0, 2, 9, 32}, + {1, 0, 0, 2, 9, 32}, + {0, 0, 0, 2, 10, 32}, + {2, 0, 0, 2, 10, 32}, + {1, 0, 0, 2, 10, 32}, + {0, 0, 0, 2, 11, 30}, + {2, 0, 0, 2, 11, 32}, + {1, 0, 0, 2, 11, 32}, + {0, 0, 0, 2, 12, 63}, + {2, 0, 0, 2, 12, 32}, + {1, 0, 0, 2, 12, 32}, + {0, 0, 0, 2, 13, 63}, + {2, 0, 0, 2, 13, 32}, + {1, 0, 0, 2, 13, 32}, + {0, 0, 0, 2, 14, 63}, + {2, 0, 0, 2, 14, 63}, + {1, 0, 0, 2, 14, 63}, + {0, 0, 1, 2, 1, 63}, + {2, 0, 1, 2, 1, 63}, + {1, 0, 1, 2, 1, 63}, + {0, 0, 1, 2, 2, 63}, + {2, 0, 1, 2, 2, 63}, + {1, 0, 1, 2, 2, 63}, + {0, 0, 1, 2, 3, 26}, + {2, 0, 1, 2, 3, 26}, + {1, 0, 1, 2, 3, 26}, + {0, 0, 1, 2, 4, 26}, + {2, 0, 1, 2, 4, 28}, + {1, 0, 1, 2, 4, 26}, + {0, 0, 1, 2, 5, 28}, + {2, 0, 1, 2, 5, 28}, + {1, 0, 1, 2, 5, 26}, + {0, 0, 1, 2, 6, 28}, + {2, 0, 1, 2, 6, 28}, + {1, 0, 1, 2, 6, 26}, + {0, 0, 1, 2, 7, 28}, + {2, 0, 1, 2, 7, 28}, + {1, 0, 1, 2, 7, 26}, + {0, 0, 1, 2, 8, 26}, + {2, 0, 1, 2, 8, 28}, + {1, 0, 1, 2, 8, 26}, + {0, 0, 1, 2, 9, 26}, + {2, 0, 1, 2, 9, 28}, + {1, 0, 1, 2, 9, 26}, + {0, 0, 1, 2, 10, 26}, + {2, 0, 1, 2, 10, 28}, + {1, 0, 1, 2, 10, 26}, + {0, 0, 1, 2, 11, 26}, + {2, 0, 1, 2, 11, 26}, + {1, 0, 1, 2, 11, 26}, + {0, 0, 1, 2, 12, 63}, + {2, 0, 1, 2, 12, 26}, + {1, 0, 1, 2, 12, 26}, + {0, 0, 1, 2, 13, 63}, + {2, 0, 1, 2, 13, 26}, + {1, 0, 1, 2, 13, 26}, + {0, 0, 1, 2, 14, 63}, + {2, 0, 1, 2, 14, 63}, + {1, 0, 1, 2, 14, 63}, + {0, 0, 1, 2, 1, 63}, + {2, 0, 1, 2, 1, 63}, + {1, 0, 1, 2, 1, 63}, + {0, 0, 1, 2, 2, 63}, + {2, 0, 1, 2, 2, 63}, + {1, 0, 1, 2, 2, 63}, + {0, 0, 1, 2, 3, 30}, + {2, 0, 1, 2, 3, 30}, + {1, 0, 1, 2, 3, 30}, + {0, 0, 1, 2, 4, 32}, + {2, 0, 1, 2, 4, 30}, + {1, 0, 1, 2, 4, 30}, + {0, 0, 1, 2, 5, 32}, + {2, 0, 1, 2, 5, 30}, + {1, 0, 1, 2, 5, 30}, + {0, 0, 1, 2, 6, 32}, + {2, 0, 1, 2, 6, 30}, + {1, 0, 1, 2, 6, 30}, + {0, 0, 1, 2, 7, 32}, + {2, 0, 1, 2, 7, 30}, + {1, 0, 1, 2, 7, 30}, + {0, 0, 1, 2, 8, 32}, + {2, 0, 1, 2, 8, 30}, + {1, 0, 1, 2, 8, 30}, + {0, 0, 1, 2, 9, 32}, + {2, 0, 1, 2, 9, 30}, + {1, 0, 1, 2, 9, 30}, + {0, 0, 1, 2, 10, 32}, + {2, 0, 1, 2, 10, 30}, + {1, 0, 1, 2, 10, 30}, + {0, 0, 1, 2, 11, 30}, + {2, 0, 1, 2, 11, 30}, + {1, 0, 1, 2, 11, 30}, + {0, 0, 1, 2, 12, 63}, + {2, 0, 1, 2, 12, 32}, + {1, 0, 1, 2, 12, 32}, + {0, 0, 1, 2, 13, 63}, + {2, 0, 1, 2, 13, 32}, + {1, 0, 1, 2, 13, 32}, + {0, 0, 1, 2, 14, 63}, + {2, 0, 1, 2, 14, 63}, + {1, 0, 1, 2, 14, 63}, +}; + +RTW_DECL_TABLE_TXPWR_LMT(rtw8723b_txpwr_lmt); diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723b_table.h b/drivers/net/wireless/realtek/rtw88/rtw8723b_table.h new file mode 100644 index 000000000000..cfed60e23249 --- /dev/null +++ b/drivers/net/wireless/realtek/rtw88/rtw8723b_table.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* Copyright(c) 2026 Realtek Corporation + * Copyright(c) Michael Straube + * Copyright(c) 2024-2026 Luka Gejak + */ + +#ifndef __RTW8723B_TABLE_H__ +#define __RTW8723B_TABLE_H__ + +extern const struct rtw_table rtw8723b_mac_tbl; +extern const struct rtw_table rtw8723b_agc_tbl; +extern const struct rtw_table rtw8723b_bb_tbl; +extern const struct rtw_table rtw8723b_bb_pg_tbl; +extern const struct rtw_table rtw8723b_rf_a_tbl; +extern const struct rtw_table rtw8723b_txpwr_lmt_tbl; + +#endif From 6879a85cf4b27ed1d734dc5227d3607b87d5fb0e Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:06:58 +0200 Subject: [PATCH 1368/2126] wifi: rtw88: move the shared 8723x definitions to rtw8723x.h The RTL8723B driver needs the receive PHY status layout, the SDIO aggregation burst fields and four baseband registers, which currently live in rtw8703b.h. Move them to rtw8723x.h, the header for the definitions shared within the family, and rename struct phy_status_8703b to struct phy_status_8723x. The layout is called phy_status_rpt_8192cd in the vendor driver. This is not a logical change. Signed-off-by: Luka Gejak Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-5-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/rtw8703b.c | 4 +- drivers/net/wireless/realtek/rtw88/rtw8703b.h | 63 ------------------- drivers/net/wireless/realtek/rtw88/rtw8723x.h | 60 ++++++++++++++++++ 3 files changed, 62 insertions(+), 65 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/rtw8703b.c b/drivers/net/wireless/realtek/rtw88/rtw8703b.c index 42cfc8e62db8..25456f0367b2 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8703b.c +++ b/drivers/net/wireless/realtek/rtw88/rtw8703b.c @@ -930,7 +930,7 @@ static s8 get_cck_rx_pwr(struct rtw_dev *rtwdev, u8 lna_idx, u8 vga_idx) static void query_phy_status_cck(struct rtw_dev *rtwdev, u8 *phy_raw, struct rtw_rx_pkt_stat *pkt_stat) { - struct phy_status_8703b *phy_status = (struct phy_status_8703b *)phy_raw; + struct phy_status_8723x *phy_status = (struct phy_status_8723x *)phy_raw; u8 vga_idx = phy_status->cck_agc_rpt_ofdm_cfosho_a & VGA_BITS; u8 lna_idx = phy_status->cck_agc_rpt_ofdm_cfosho_a & LNA_L_BITS; s8 rx_power; @@ -952,7 +952,7 @@ static void query_phy_status_cck(struct rtw_dev *rtwdev, u8 *phy_raw, static void query_phy_status_ofdm(struct rtw_dev *rtwdev, u8 *phy_raw, struct rtw_rx_pkt_stat *pkt_stat) { - struct phy_status_8703b *phy_status = (struct phy_status_8703b *)phy_raw; + struct phy_status_8723x *phy_status = (struct phy_status_8723x *)phy_raw; struct rtw_dm_info *dm_info = &rtwdev->dm_info; s8 val_s8; diff --git a/drivers/net/wireless/realtek/rtw88/rtw8703b.h b/drivers/net/wireless/realtek/rtw88/rtw8703b.h index 3e2da2e6739d..51e9038e7c1e 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8703b.h +++ b/drivers/net/wireless/realtek/rtw88/rtw8703b.h @@ -16,62 +16,7 @@ extern const struct rtw_chip_info rtw8703b_hw_spec; #define BIT_LNA_H_MASK BIT(3) #define BIT_LNA_L_MASK GENMASK(2, 0) -struct phy_rx_agc_info { -#ifdef __LITTLE_ENDIAN - u8 gain: 7; - u8 trsw: 1; -#else - u8 trsw: 1; - u8 gain: 7; -#endif -} __packed; - -/* This struct is called phy_status_rpt_8192cd in the vendor driver, - * there might be potential to share it with drivers for other chips - * of the same generation. - */ -struct phy_status_8703b { - struct phy_rx_agc_info path_agc[2]; - u8 ch_corr[2]; - u8 cck_sig_qual_ofdm_pwdb_all; - /* for CCK: bits 0:4: VGA index, bits 5:7: LNA index (low) */ - u8 cck_agc_rpt_ofdm_cfosho_a; - /* for CCK: bit 7 is high bit of LNA index if long report type */ - u8 cck_rpt_b_ofdm_cfosho_b; - u8 reserved_1; - u8 noise_power_db_msb; - s8 path_cfotail[2]; - u8 pcts_mask[2]; - s8 stream_rxevm[2]; - u8 path_rxsnr[2]; - u8 noise_power_db_lsb; - u8 reserved_2[3]; - u8 stream_csi[2]; - u8 stream_target_csi[2]; - s8 sig_evm; - u8 reserved_3; - -#ifdef __LITTLE_ENDIAN - u8 antsel_rx_keep_2: 1; - u8 sgi_en: 1; - u8 rxsc: 2; - u8 idle_long: 1; - u8 r_ant_train_en: 1; - u8 ant_sel_b: 1; - u8 ant_sel: 1; -#else /* __BIG_ENDIAN */ - u8 ant_sel: 1; - u8 ant_sel_b: 1; - u8 r_ant_train_en: 1; - u8 idle_long: 1; - u8 rxsc: 2; - u8 sgi_en: 1; - u8 antsel_rx_keep_2: 1; -#endif -} __packed; - /* Baseband registers */ -#define REG_BB_PWR_SAV5_11N 0x0818 /* BIT(11) should be 1 for 8703B *and* 8723D, which means LNA uses 4 * bit for CCK rates in report, not 3. Vendor driver logs a warning if * it's 0, but handles the case. @@ -87,16 +32,8 @@ struct phy_status_8703b { #define REG_CCK_TXSF2 0x0a24 /* CCK TX filter 2 */ #define REG_CCK_DBG 0x0a28 /* debug port */ #define REG_OFDM0_A_TX_AFE 0x0c84 -#define REG_TXIQK_MATRIXB_LSB2_11N 0x0c9c -#define REG_OFDM0_TX_PSD_NOISE 0x0ce4 /* TX pseudo noise weighting */ -#define REG_IQK_RDY 0x0e90 /* is != 0 when IQK is done */ /* RF registers */ #define RF_RCK1 0x1E -#define AGG_BURST_NUM 3 -#define AGG_BURST_SIZE 0 /* 1K */ -#define BIT_MASK_AGG_BURST_NUM (GENMASK(3, 2)) -#define BIT_MASK_AGG_BURST_SIZE (GENMASK(5, 4)) - #endif /* __RTW8703B_H__ */ diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723x.h b/drivers/net/wireless/realtek/rtw88/rtw8723x.h index 0fc70dfdfc8b..e07b6ca99b3d 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8723x.h +++ b/drivers/net/wireless/realtek/rtw88/rtw8723x.h @@ -162,6 +162,57 @@ struct rtw8723x_common { extern const struct rtw8723x_common rtw8723x_common; +struct phy_rx_agc_info { +#ifdef __LITTLE_ENDIAN + u8 gain: 7; + u8 trsw: 1; +#else + u8 trsw: 1; + u8 gain: 7; +#endif +} __packed; + +/* Receive PHY status layout, shared by the 8723x chips. */ +struct phy_status_8723x { + struct phy_rx_agc_info path_agc[2]; + u8 ch_corr[2]; + u8 cck_sig_qual_ofdm_pwdb_all; + /* for CCK: bits 0:4: VGA index, bits 5:7: LNA index (low) */ + u8 cck_agc_rpt_ofdm_cfosho_a; + /* for CCK: bit 7 is high bit of LNA index if long report type */ + u8 cck_rpt_b_ofdm_cfosho_b; + u8 reserved_1; + u8 noise_power_db_msb; + s8 path_cfotail[2]; + u8 pcts_mask[2]; + s8 stream_rxevm[2]; + u8 path_rxsnr[2]; + u8 noise_power_db_lsb; + u8 reserved_2[3]; + u8 stream_csi[2]; + u8 stream_target_csi[2]; + s8 sig_evm; + u8 reserved_3; + +#ifdef __LITTLE_ENDIAN + u8 antsel_rx_keep_2: 1; + u8 sgi_en: 1; + u8 rxsc: 2; + u8 idle_long: 1; + u8 r_ant_train_en: 1; + u8 ant_sel_b: 1; + u8 ant_sel: 1; +#else /* __BIG_ENDIAN */ + u8 ant_sel: 1; + u8 ant_sel_b: 1; + u8 r_ant_train_en: 1; + u8 idle_long: 1; + u8 rxsc: 2; + u8 sgi_en: 1; + u8 antsel_rx_keep_2: 1; +#endif +} __packed; + #define PATH_IQK_RETRY 2 #define MAX_TOLERANCE 5 #define IQK_TX_X_ERR 0x142 @@ -176,6 +227,11 @@ extern const struct rtw8723x_common rtw8723x_common; #define WLAN_TXQ_RPT_EN 0x1F +#define AGG_BURST_NUM 3 +#define AGG_BURST_SIZE 0 /* 1K */ +#define BIT_MASK_AGG_BURST_NUM (GENMASK(3, 2)) +#define BIT_MASK_AGG_BURST_SIZE (GENMASK(5, 4)) + #define SPUR_THRES 0x16 #define DIS_3WIRE 0xccf000c0 #define EN_3WIRE 0xccc000c0 @@ -201,6 +257,7 @@ extern const struct rtw8723x_common rtw8723x_common; #define REG_LTECOEX_WRITE_DATA 0x07c4 #define REG_LTECOEX_READ_DATA 0x07c8 #define REG_PSDFN 0x0808 +#define REG_BB_PWR_SAV5_11N 0x0818 #define REG_BB_PWR_SAV1_11N 0x0874 #define REG_ANA_PARAM1 0x0880 #define REG_ANALOG_P4 0x088c @@ -261,6 +318,7 @@ extern const struct rtw8723x_common rtw8723x_common; #define BIT_MASK_TXIQ_ELM_D GENMASK(31, 22) #define REG_TXIQK_MATRIXA_LSB2_11N 0x0c94 #define BIT_SET_TXIQ_ELM_C1(c) (((c) & 0x000003C0) >> 6) +#define REG_TXIQK_MATRIXB_LSB2_11N 0x0c9c #define REG_RXIQK_MATRIX_LSB_11N 0x0ca0 #define BIT_MASK_RXIQ_S1_Y2 0xF0000000 #define BIT_SET_RXIQ_S1_Y2(y) (((y) >> 6) & 0xF) @@ -276,6 +334,7 @@ extern const struct rtw8723x_common rtw8723x_common; #define REG_RXIQ_AB_S0 0x0cd8 #define BIT_MASK_RXIQ_X_S0 0x000003FF #define BIT_MASK_RXIQ_Y_S0 0x003FF000 +#define REG_OFDM0_TX_PSD_NOISE 0x0ce4 /* TX pseudo noise weighting */ #define REG_OFDM_FA_TYPE1_11N 0x0cf0 #define BIT_MASK_OFDM_FF_CNT GENMASK(15, 0) #define BIT_MASK_OFDM_SF_CNT GENMASK(31, 16) @@ -315,6 +374,7 @@ extern const struct rtw8723x_common rtw8723x_common; #define REG_RX_IQK_TONE_B 0x0e54 #define REG_TXIQK_PI_B 0x0e58 #define REG_RXIQK_PI_B 0x0e5c +#define REG_IQK_RDY 0x0e90 /* is != 0 when IQK is done */ #define REG_IQK_RES_TX 0x0e94 #define BIT_MASK_RES_TX GENMASK(25, 16) #define REG_IQK_RES_TY 0x0e9c From d726c70ce08224873f3b0e10349fb8fc20a69f77 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:06:59 +0200 Subject: [PATCH 1369/2126] wifi: rtw88: 8723b: add the RTL8723B chip driver Add the Realtek RTL8723B 802.11n chip driver: the chip operations, the power sequences, the efuse layout, the RF and IQ calibration, and the chip specific coexistence handling. The RTL8723B chip support is based on the initial work by Michael Straube . Link: https://github.com/mistraube/rtw88/tree/rtl8723bs Co-developed-by: Michael Straube Signed-off-by: Michael Straube Signed-off-by: Luka Gejak Reviewed-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-6-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/rtw8723b.c | 2534 +++++++++++++++++ drivers/net/wireless/realtek/rtw88/rtw8723b.h | 14 + 2 files changed, 2548 insertions(+) create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8723b.c create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8723b.h diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723b.c b/drivers/net/wireless/realtek/rtw88/rtw8723b.c new file mode 100644 index 000000000000..8bb9c03d769c --- /dev/null +++ b/drivers/net/wireless/realtek/rtw88/rtw8723b.c @@ -0,0 +1,2534 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* Copyright(c) 2026 Realtek Corporation + * Copyright(c) Michael Straube + * Copyright(c) 2024-2026 Luka Gejak + */ + +#include "main.h" +#include "coex.h" +#include "fw.h" +#include "mac.h" +#include "phy.h" +#include "rtw8723b.h" +#include "rtw8723b_table.h" +#include "sdio.h" +#include "tx.h" + +#define TRANS_SEQ_END \ + 0xFFFF, \ + RTW_PWR_CUT_ALL_MSK, \ + RTW_PWR_INTF_ALL_MSK, \ + 0, \ + RTW_PWR_CMD_END, 0, 0 + +#define TBTT_PROHIBIT_SETUP_TIME 0x04 +#define TBTT_PROHIBIT_HOLD_TIME_STOP_BCN 0x64 +#define WLAN_BCN_DMA_TIME 0x02 +#define WLAN_BAR_VAL 0x0201ffff +#define WLAN_SLOT_TIME 0x09 +#define WLAN_RF_CTRL_ENABLE (BIT_RF_EN | BIT_RF_RSTB | \ + BIT_RF_SDM_RSTB) + +#define ADDA_ON_VAL_8723B 0x01c00014 + +/* + * BIT(7) lets the 8051 control antenna selection, BIT(1) is LED2_CM. + */ +#define WLAN_ANT_SEL (BIT(7) | BIT(1)) + +#define IQK_DELAY_TIME_8723B 20 + +/* rssi in percent (dbm = % - 100); the values are the vendor driver's. */ +static const u8 wl_rssi_step_8723b[] = {60, 50, 44, 30}; +static const u8 bt_rssi_step_8723b[] = {30, 30, 30, 30}; +static const struct coex_5g_afh_map afh_5g_8723b[] = { {0, 0, 0} }; + +static const struct coex_rf_para rf_para_tx_8723b[] = { + {0, 0, false, 7}, /* for normal */ + {0, 10, false, 7}, /* for WL-CPT */ + {1, 0, true, 4}, + {1, 2, true, 4}, + {1, 10, true, 4}, + {1, 15, true, 4} +}; + +static const struct coex_rf_para rf_para_rx_8723b[] = { + {0, 0, false, 7}, /* for normal */ + {0, 10, false, 7}, /* for WL-CPT */ + {1, 0, true, 5}, + {1, 2, true, 5}, + {1, 10, true, 5}, + {1, 15, true, 5} +}; + +static_assert(ARRAY_SIZE(rf_para_tx_8723b) == ARRAY_SIZE(rf_para_rx_8723b)); + +static const u32 rtw8723b_ofdm_swing_table[] = { + 0x0b40002d, /* 0, -15.0dB */ + 0x0c000030, /* 1, -14.5dB */ + 0x0cc00033, /* 2, -14.0dB */ + 0x0d800036, /* 3, -13.5dB */ + 0x0e400039, /* 4, -13.0dB */ + 0x0f00003c, /* 5, -12.5dB */ + 0x10000040, /* 6, -12.0dB */ + 0x11000044, /* 7, -11.5dB */ + 0x12000048, /* 8, -11.0dB */ + 0x1300004c, /* 9, -10.5dB */ + 0x14400051, /* 10, -10.0dB */ + 0x15800056, /* 11, -9.5dB */ + 0x16c0005b, /* 12, -9.0dB */ + 0x18000060, /* 13, -8.5dB */ + 0x19800066, /* 14, -8.0dB */ + 0x1b00006c, /* 15, -7.5dB */ + 0x1c800072, /* 16, -7.0dB */ + 0x1e400079, /* 17, -6.5dB */ + 0x20000080, /* 18, -6.0dB */ + 0x22000088, /* 19, -5.5dB */ + 0x24000090, /* 20, -5.0dB */ + 0x26000098, /* 21, -4.5dB */ + 0x288000a2, /* 22, -4.0dB */ + 0x2ac000ab, /* 23, -3.5dB */ + 0x2d4000b5, /* 24, -3.0dB */ + 0x300000c0, /* 25, -2.5dB */ + 0x32c000cb, /* 26, -2.0dB */ + 0x35c000d7, /* 27, -1.5dB */ + 0x390000e4, /* 28, -1.0dB */ + 0x3c8000f2, /* 29, -0.5dB */ + 0x40000100, /* 30, +0dB */ + 0x43c0010f, /* 31, +0.5dB */ + 0x47c0011f, /* 32, +1.0dB */ + 0x4c000130, /* 33, +1.5dB */ + 0x50800142, /* 34, +2.0dB */ + 0x55400155, /* 35, +2.5dB */ + 0x5a400169, /* 36, +3.0dB */ + 0x5fc0017f, /* 37, +3.5dB */ + 0x65400195, /* 38, +4.0dB */ + 0x6b8001ae, /* 39, +4.5dB */ + 0x71c001c7, /* 40, +5.0dB */ + 0x788001e2, /* 41, +5.5dB */ + 0x7f8001fe, /* 42, +6.0dB */ +}; + +/* The eight per-rate CCK transmit power registers are consecutive. */ +#define RTW_CCK_SWING_REG_NUM 8 + +static const u8 rtw8723b_cck_swing_table_ch1_ch13[][8] = { + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 32, +0dB */ +}; + +static const u8 rtw8723b_cck_swing_table_ch14[][8] = { + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 32, +0dB */ +}; + +static_assert(ARRAY_SIZE(rtw8723b_cck_swing_table_ch1_ch13) == + ARRAY_SIZE(rtw8723b_cck_swing_table_ch14)); + +#define RTW_OFDM_SWING_TABLE_SIZE ARRAY_SIZE(rtw8723b_ofdm_swing_table) +#define RTW_CCK_SWING_TABLE_SIZE ARRAY_SIZE(rtw8723b_cck_swing_table_ch14) + +/* + * Swing index field of REG_OFDM_0_XA_TX_IQ_IMBALANCE; the table entries + * below hold the full register value, so read them back with + * u32_get_bits(). + */ +#define OFDM_SWING_MASK GENMASK(31, 22) + +static const struct rtw_pwr_seq_cmd trans_pre_enable_8723b[] = { + /* unlock ISO/CLK/power control register */ + {REG_RSV_CTRL, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xff, 0}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8723b[] = { + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(3) | BIT(7), 0}, + {0x0086, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_SDIO, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + {0x0086, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_SDIO, + RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, + {0x004A, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), 0}, + {0x0023, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(4), 0}, + {0x0301, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_PCI_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd trans_cardemu_to_act_8723b[] = { + {0x0020, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x0067, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(4), 0}, + {0x0001, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_DELAY, 1, RTW_PWR_DELAY_MS}, + {0x0000, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(5), 0}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0}, + {0x0075, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_PCI_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x0006, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, + {0x0075, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_PCI_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + {0x0006, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(7), 0}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(4) | BIT(3), 0}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, BIT(0), 0}, + {0x0010, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(6), BIT(6)}, + {0x0049, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, + {0x0063, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, + {0x0062, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), 0}, + {0x0058, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x005A, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, + {0x0068, + RTW_PWR_CUT_TEST_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(3), BIT(3)}, + {0x0069, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(6), BIT(6)}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd trans_act_to_lps_8723b[] = { + {0x0301, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_PCI_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0xFF}, + {0x0522, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0xFF}, + {0x05F8, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, 0xFF, 0}, + {0x05F9, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, 0xFF, 0}, + {0x05FA, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, 0xFF, 0}, + {0x05FB, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, 0xFF, 0}, + {0x0002, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + {0x0002, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_DELAY, 0, RTW_PWR_DELAY_US}, + {0x0002, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), 0}, + {0x0100, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0x03}, + {0x0101, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), 0}, + {0x0093, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0x00}, + {0x0553, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(5), BIT(5)}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd trans_act_to_reset_mcu_8723b[] = { + {REG_SYS_FUNC_EN + 1, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT_FEN_CPUEN, 0}, + /* reset MCU ready */ + {REG_MCUFW_CTRL, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xff, 0}, + /* reset MCU IO wrapper */ + {REG_RSV_CTRL + 1, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + {REG_RSV_CTRL + 1, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 1}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd trans_act_to_cardemu_8723b[] = { + {0x001F, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0}, + {0x0049, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), 0}, + {0x0006, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_POLLING, BIT(1), 0}, + {0x0010, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_ALL_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(6), 0}, + {0x0000, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(5), BIT(5)}, + {0x0020, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 0}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd trans_cardemu_to_carddis_8723b[] = { + {0x0007, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, 0xFF, 0x20}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)}, + {0x0005, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_PCI_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(2), BIT(2)}, + {0x004A, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_USB_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(0), 1}, + {0x0023, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_MAC, + RTW_PWR_CMD_WRITE, BIT(4), BIT(4)}, + {0x0086, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_SDIO, + RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, + {0x0086, + RTW_PWR_CUT_ALL_MSK, + RTW_PWR_INTF_SDIO_MSK, + RTW_PWR_ADDR_SDIO, + RTW_PWR_CMD_POLLING, BIT(1), 0}, + {TRANS_SEQ_END}, +}; + +static const struct rtw_pwr_seq_cmd * const card_enable_flow_8723b[] = { + trans_pre_enable_8723b, + trans_carddis_to_cardemu_8723b, + trans_cardemu_to_act_8723b, + NULL +}; + +static const struct rtw_pwr_seq_cmd * const card_disable_flow_8723b[] = { + trans_act_to_lps_8723b, + trans_act_to_reset_mcu_8723b, + trans_act_to_cardemu_8723b, + trans_cardemu_to_carddis_8723b, + NULL +}; + +static const struct rtw_page_table page_table_8723b[] = { + {12, 2, 2, 0, 1}, /* SDIO */ + {12, 2, 2, 0, 1}, + {12, 2, 2, 0, 1}, + {12, 2, 2, 0, 1}, + {12, 2, 2, 0, 1}, +}; + +static const struct rtw_rqpn rqpn_table_8723b[] = { + /* SDIO maps VO, MGMT and HI to the high queue. */ + {RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_NORMAL, + RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, + RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, + /* PCIE */ + {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, + RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, + RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, + /* USB bulkout 2 */ + {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, + RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_HIGH, + RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, + /* USB bulkout 3 */ + {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, + RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, + RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, + /* USB bulkout 4 */ + {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, + RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, + RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, +}; + +static const u8 rtw8723b_pwrtrk_2gb_n[] = { + 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 6, + 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15 +}; + +static const u8 rtw8723b_pwrtrk_2gb_p[] = { + 0, 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, + 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15 +}; + +static const u8 rtw8723b_pwrtrk_2ga_n[] = { + 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 6, + 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15 +}; + +static const u8 rtw8723b_pwrtrk_2ga_p[] = { + 0, 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, + 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15 +}; + +static const u8 rtw8723b_pwrtrk_2g_cck_b_n[] = { + 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8, + 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 +}; + +static const u8 rtw8723b_pwrtrk_2g_cck_b_p[] = { + 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 +}; + +static const u8 rtw8723b_pwrtrk_2g_cck_a_n[] = { + 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8, + 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 +}; + +static const u8 rtw8723b_pwrtrk_2g_cck_a_p[] = { + 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 +}; + +static const struct rtw_pwr_track_tbl rtw8723b_rtw_pwr_track_tbl = { + .pwrtrk_2gb_n = rtw8723b_pwrtrk_2gb_n, + .pwrtrk_2gb_p = rtw8723b_pwrtrk_2gb_p, + .pwrtrk_2ga_n = rtw8723b_pwrtrk_2ga_n, + .pwrtrk_2ga_p = rtw8723b_pwrtrk_2ga_p, + .pwrtrk_2g_cckb_n = rtw8723b_pwrtrk_2g_cck_b_n, + .pwrtrk_2g_cckb_p = rtw8723b_pwrtrk_2g_cck_b_p, + .pwrtrk_2g_ccka_n = rtw8723b_pwrtrk_2g_cck_a_n, + .pwrtrk_2g_ccka_p = rtw8723b_pwrtrk_2g_cck_a_p, + /* rtw8723x_pwrtrack_set_xtal() is not used on this chip. */ + .pwrtrk_xtal_n = NULL, + .pwrtrk_xtal_p = NULL, +}; + +static const struct rtw_rfe_def rtw8723b_rfe_defs[] = { + [0] = { .phy_pg_tbl = &rtw8723b_bb_pg_tbl, + .txpwr_lmt_tbl = &rtw8723b_txpwr_lmt_tbl, + .pwr_track_tbl = &rtw8723b_rtw_pwr_track_tbl, }, +}; + +/* Shared-Antenna Coex Table */ +static const struct coex_table_para table_sant_8723b[] = { + {0xffffffff, 0xffffffff}, /* case-0 */ + {0x55555555, 0x55555555}, + {0x66555555, 0x66555555}, + {0xaaaaaaaa, 0xaaaaaaaa}, + {0x5a5a5a5a, 0x5a5a5a5a}, + {0xfafafafa, 0xfafafafa}, /* case-5 */ + {0x6a5a5555, 0xaaaaaaaa}, + {0x6a5a56aa, 0x6a5a56aa}, + {0x6a5a5a5a, 0x6a5a5a5a}, + {0x66555555, 0x5a5a5a5a}, + {0x66555555, 0x6a5a5a5a}, /* case-10 */ + {0x66555555, 0x6a5a5aaa}, + {0x66555555, 0x5a5a5aaa}, + {0x66555555, 0x6aaa5aaa}, + {0x66555555, 0xaaaa5aaa}, + {0x66555555, 0xaaaaaaaa}, /* case-15 */ + {0xffff55ff, 0xfafafafa}, + {0xffff55ff, 0x6afa5afa}, + {0xaaffffaa, 0xfafafafa}, + {0xaa5555aa, 0x5a5a5a5a}, + {0xaa5555aa, 0x6a5a5a5a}, /* case-20 */ + {0xaa5555aa, 0xaaaaaaaa}, + {0xffffffff, 0x5a5a5a5a}, + {0xffffffff, 0x5a5a5a5a}, + {0xffffffff, 0x55555555}, + {0xffffffff, 0x5a5a5aaa}, /* case-25 */ + {0x55555555, 0x5a5a5a5a}, + {0x55555555, 0xaaaaaaaa}, + {0x55555555, 0x6a5a6a5a}, + {0x66556655, 0x66556655}, + {0x66556aaa, 0x6a5a6aaa}, /* case-30 */ + {0xffffffff, 0x5aaa5aaa}, + {0x56555555, 0x5a5a5aaa}, +}; + +/* Non-Shared-Antenna Coex Table */ +static const struct coex_table_para table_nsant_8723b[] = { + {0xffffffff, 0xffffffff}, /* case-100 */ + {0x55555555, 0x55555555}, + {0x66555555, 0x66555555}, + {0xaaaaaaaa, 0xaaaaaaaa}, + {0x5a5a5a5a, 0x5a5a5a5a}, + {0xfafafafa, 0xfafafafa}, /* case-105 */ + {0x5afa5afa, 0x5afa5afa}, + {0x55555555, 0xfafafafa}, + {0x66555555, 0xfafafafa}, + {0x66555555, 0x5a5a5a5a}, + {0x66555555, 0x6a5a5a5a}, /* case-110 */ + {0x66555555, 0xaaaaaaaa}, + {0xffff55ff, 0xfafafafa}, + {0xffff55ff, 0x5afa5afa}, + {0xffff55ff, 0xaaaaaaaa}, + {0xffff55ff, 0xffff55ff}, /* case-115 */ + {0xaaffffaa, 0x5afa5afa}, + {0xaaffffaa, 0xaaaaaaaa}, + {0xffffffff, 0xfafafafa}, + {0xffffffff, 0x5afa5afa}, + {0xffffffff, 0xaaaaaaaa}, /* case-120 */ + {0x55ff55ff, 0x5afa5afa}, + {0x55ff55ff, 0xaaaaaaaa}, + {0x55ff55ff, 0x55ff55ff} +}; + +/* Shared-Antenna TDMA */ +static const struct coex_tdma_para tdma_sant_8723b[] = { + { {0x00, 0x00, 0x00, 0x00, 0x00} }, /* case-0 */ + { {0x61, 0x45, 0x03, 0x11, 0x11} }, /* case-1 */ + { {0x61, 0x3a, 0x03, 0x11, 0x11} }, + { {0x61, 0x30, 0x03, 0x11, 0x11} }, + { {0x61, 0x20, 0x03, 0x11, 0x11} }, + { {0x61, 0x10, 0x03, 0x11, 0x11} }, /* case-5 */ + { {0x61, 0x45, 0x03, 0x11, 0x10} }, + { {0x61, 0x3a, 0x03, 0x11, 0x10} }, + { {0x61, 0x30, 0x03, 0x11, 0x10} }, + { {0x61, 0x20, 0x03, 0x11, 0x10} }, + { {0x61, 0x10, 0x03, 0x11, 0x10} }, /* case-10 */ + { {0x61, 0x08, 0x03, 0x11, 0x14} }, + { {0x61, 0x08, 0x03, 0x10, 0x14} }, + { {0x51, 0x08, 0x03, 0x10, 0x54} }, + { {0x51, 0x08, 0x03, 0x10, 0x55} }, + { {0x51, 0x08, 0x07, 0x10, 0x54} }, /* case-15 */ + { {0x51, 0x45, 0x03, 0x10, 0x50} }, + { {0x51, 0x3a, 0x03, 0x10, 0x50} }, + { {0x51, 0x30, 0x03, 0x10, 0x50} }, + { {0x51, 0x20, 0x03, 0x10, 0x50} }, + { {0x51, 0x10, 0x03, 0x10, 0x50} }, /* case-20 */ + { {0x51, 0x4a, 0x03, 0x10, 0x50} }, + { {0x51, 0x0c, 0x03, 0x10, 0x54} }, + { {0x55, 0x08, 0x03, 0x10, 0x54} }, + { {0x65, 0x10, 0x03, 0x11, 0x10} }, + { {0x51, 0x10, 0x03, 0x10, 0x51} }, /* case-25 */ + { {0x51, 0x08, 0x03, 0x10, 0x50} }, + { {0x61, 0x08, 0x03, 0x11, 0x11} } +}; + +/* Non-Shared-Antenna TDMA */ +static const struct coex_tdma_para tdma_nsant_8723b[] = { + { {0x00, 0x00, 0x00, 0x00, 0x01} }, /* case-100 */ + { {0x61, 0x45, 0x03, 0x11, 0x11} }, /* case-101 */ + { {0x61, 0x3a, 0x03, 0x11, 0x11} }, + { {0x61, 0x30, 0x03, 0x11, 0x11} }, + { {0x61, 0x20, 0x03, 0x11, 0x11} }, + { {0x61, 0x10, 0x03, 0x11, 0x11} }, /* case-105 */ + { {0x61, 0x45, 0x03, 0x11, 0x10} }, + { {0x61, 0x3a, 0x03, 0x11, 0x10} }, + { {0x61, 0x30, 0x03, 0x11, 0x10} }, + { {0x61, 0x20, 0x03, 0x11, 0x10} }, + { {0x61, 0x10, 0x03, 0x11, 0x10} }, /* case-110 */ + { {0x61, 0x08, 0x03, 0x11, 0x14} }, + { {0x61, 0x08, 0x03, 0x10, 0x14} }, + { {0x51, 0x08, 0x03, 0x10, 0x54} }, + { {0x51, 0x08, 0x03, 0x10, 0x55} }, + { {0x51, 0x08, 0x07, 0x10, 0x54} }, /* case-115 */ + { {0x51, 0x45, 0x03, 0x10, 0x50} }, + { {0x51, 0x3a, 0x03, 0x10, 0x50} }, + { {0x51, 0x30, 0x03, 0x10, 0x50} }, + { {0x51, 0x20, 0x03, 0x10, 0x50} }, + { {0x51, 0x10, 0x03, 0x10, 0x50} }, /* case-120 */ + { {0x51, 0x08, 0x03, 0x10, 0x50} } +}; + +static void rtw8723b_efuse_grant(struct rtw_dev *rtwdev, bool on) +{ + rtw_write8_set(rtwdev, REG_BT_EFUSE_CTRL, + on ? BIT_BT_PWR_CUT : BIT_BT_OUT_ISO); + + rtw8723x_efuse_grant(rtwdev, on); +} + +static u8 rtw8723b_default_ofdm_index(struct rtw_dev *rtwdev) +{ + u32 swing; + u8 i; + + swing = rtw_read32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, + OFDM_SWING_MASK); + + for (i = 0; i < RTW_OFDM_SWING_TABLE_SIZE; i++) { + if (u32_get_bits(rtw8723b_ofdm_swing_table[i], + OFDM_SWING_MASK) == swing) + break; + } + + if (i >= RTW_OFDM_SWING_TABLE_SIZE) + i = 30; /* 30, +0dB */ + + return i; +} + +static u8 rtw8723b_default_cck_index(struct rtw_dev *rtwdev) +{ + const u8 (*table)[RTW_CCK_SWING_REG_NUM]; + u8 swing; + u8 i; + + table = rtw8723b_cck_swing_table_ch1_ch13; + if (rtwdev->hal.current_channel == 14) + table = rtw8723b_cck_swing_table_ch14; + + swing = rtw_read8(rtwdev, REG_CCK_SWING); + + for (i = 0; i < RTW_CCK_SWING_TABLE_SIZE; i++) { + if (table[i][0] == swing) + break; + } + + if (i >= RTW_CCK_SWING_TABLE_SIZE) + i = 20; /* 20, -6.0dB */ + + return i; +} + +static void rtw8723b_pwrtrack_init(struct rtw_dev *rtwdev) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + u8 path; + + dm_info->default_ofdm_index = rtw8723b_default_ofdm_index(rtwdev); + dm_info->default_cck_index = rtw8723b_default_cck_index(rtwdev); + + /* Clear the OFDM remnant per path: tracking keeps one per path. */ + for (path = RF_PATH_A; path < rtwdev->hal.rf_path_num; path++) { + ewma_thermal_init(&dm_info->avg_thermal[path]); + dm_info->delta_power_index[path] = 0; + dm_info->txagc_remnant_ofdm[path] = 0; + } + dm_info->pwr_trk_triggered = false; + dm_info->pwr_trk_init_trigger = true; + dm_info->thermal_meter_k = rtwdev->efuse.thermal_meter_k; + dm_info->txagc_remnant_cck = 0; +} + +static void rtw8723b_post_enable_flow(struct rtw_dev *rtwdev) +{ + /* + * Enable falling edge triggered interrupts and GPIO9 interrupt mode. + * The power-on sequence sets both, but it runs before the firmware is + * downloaded, so reassert them here as the vendor driver does. + */ + rtw_write32_set(rtwdev, REG_GPIO_INTM, BIT(9)); + rtw_write32_set(rtwdev, REG_GPIO_PIN_CTRL_2, BIT(25)); + + rtw_write16_set(rtwdev, REG_APS_FSMCO, BIT_EN_PDN); + + /* + * Only OR in the missing enables: writing CR to zero would reset the + * hardware free-page counters and leave TX DMA no pages to allocate. + */ + rtw_write16_set(rtwdev, REG_CR, MAC_TRX_ENABLE | BIT_MAC_SEC_EN | + BIT_32K_CAL_TMR_EN); + + if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_SDIO) + rtw_write16_set(rtwdev, REG_PWR_DATA, + BIT_EEPRPAD_RFE_CTRL_EN); + + rtw_write8(rtwdev, REG_EARLY_MODE_CONTROL, 0); + + /* Keep every MACID eligible for firmware-scheduled TX at power-on. */ + rtw_write32(rtwdev, REG_MACID_PKT_DROP0, 0); + rtw_write32(rtwdev, REG_MACID_PKT_SLEEP, 0); +} + +static void rtw8723b_phy_bb_config(struct rtw_dev *rtwdev) +{ + u8 xtal_cap; + + /* Enable BB and RF */ + rtw_write16_set(rtwdev, REG_SYS_FUNC_EN, + BIT_FEN_EN_25_1 | BIT_FEN_BB_GLB_RST | BIT_FEN_BB_RSTB); + + if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_USB) + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x0); + else + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x280); + + /* Full write: preserving spuriously set bits can wedge the RF bus. */ + rtw_write8(rtwdev, REG_RF_CTRL, WLAN_RF_CTRL_ENABLE); + fsleep(1000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK, 0x0780); + rtw_write8(rtwdev, REG_SYS_FUNC_EN, + BIT_FEN_PPLL | BIT_FEN_PCIEA | BIT_FEN_DIO_PCIE | + BIT_FEN_BB_GLB_RST | BIT_FEN_BB_RSTB); + rtw_write8(rtwdev, REG_AFE_CTRL1 + 1, 0x80); + + xtal_cap = rtwdev->efuse.crystal_cap & 0x3f; + rtw_write32_mask(rtwdev, REG_AFE_CTRL3, BIT_MASK_XTAL, + xtal_cap | (xtal_cap << 6)); +} + +static void rtw8723b_phy_load_bb_tables(struct rtw_dev *rtwdev) +{ + const struct rtw_rfe_def *rfe_def = rtw_get_rfe_def(rtwdev); + const struct rtw_chip_info *chip = rtwdev->chip; + + rtw_load_table(rtwdev, chip->bb_tbl); + rtw_load_table(rtwdev, chip->agc_tbl); + if (rfe_def && rfe_def->agc_btg_tbl) + rtw_load_table(rtwdev, rfe_def->agc_btg_tbl); +} + +static void rtw8723b_phy_rf6052_config(struct rtw_dev *rtwdev) +{ + struct rtw_hal *hal = &rtwdev->hal; + u32 intf_s, intf_oe, hssi_2; + u32 val32, mask; + u8 path; + + for (path = RF_PATH_A; path < hal->rf_path_num; path++) { + switch (path) { + case RF_PATH_A: + intf_s = REG_FPGA0_XA_RF_SW_CTRL; + intf_oe = REG_FPGA0_XA_RF_INT_OE; + hssi_2 = REG_FPGA0_XA_HSSI_PARM2; + mask = RFSI_RFENV; + break; + case RF_PATH_B: + /* + * The path B switch control is the upper half of the + * word at REG_FPGA0_XA_RF_SW_CTRL, which the shifted + * mask already selects. Addressing 0x0872 directly + * would be a 32-bit access on a 2-byte boundary and + * would reach into the register that follows. + */ + intf_s = REG_FPGA0_XA_RF_SW_CTRL; + intf_oe = REG_FPGA0_XB_RF_INT_OE; + hssi_2 = REG_FPGA0_XB_HSSI_PARM2; + mask = RFSI_RFENV << 16; + break; + default: + rtw_err(rtwdev, "invalid rf path %c\n", path + 'A'); + return; + } + + val32 = rtw_read32_mask(rtwdev, intf_s, mask); + + rtw_write32_mask(rtwdev, intf_oe, RFSI_RFENV << 16, 0x1); + udelay(1); + + rtw_write32_mask(rtwdev, intf_oe, RFSI_RFENV, 0x1); + udelay(1); + + rtw_write32_mask(rtwdev, hssi_2, HSSI_3WIRE_ADDR_LEN, 0x0); + udelay(1); + + rtw_write32_mask(rtwdev, hssi_2, HSSI_3WIRE_DATA_LEN, 0x0); + udelay(1); + + /* Path B has no table of its own; radio_a serves both paths. */ + rtw_load_table(rtwdev, rtwdev->chip->rf_tbl[RF_PATH_A]); + + rtw_write32_mask(rtwdev, intf_s, mask, val32); + } +} + +static void rtw8723b_phy_lck(struct rtw_dev *rtwdev) +{ + rtw_write_rf(rtwdev, RF_PATH_A, RF_SYN_PFD, RFREG_MASK, 0xdfbe0); + rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, 0x8c01); + fsleep(200 * 1000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_SYN_PFD, RFREG_MASK, 0xdffe0); +} + +static void rtw8723b_lck(struct rtw_dev *rtwdev) +{ + /* + * The vendor's LC calibration turns the PFD LDO on before the LCK + * trigger and off after it, every time it runs, not only during the + * initial RF configuration. + */ + rtw_write_rf(rtwdev, RF_PATH_A, RF_SYN_PFD, RFREG_MASK, 0xdfbe0); + + rtw8723x_lck(rtwdev); + + rtw_write_rf(rtwdev, RF_PATH_A, RF_SYN_PFD, RFREG_MASK, 0xdffe0); +} + +static void rtw8723b_phy_rf_config(struct rtw_dev *rtwdev) +{ + rtw8723b_phy_rf6052_config(rtwdev); + + /* LCK must run as part of the RF configuration. */ + rtw8723b_phy_lck(rtwdev); +} + +static void rtw8723b_init_transfer_page_size(struct rtw_dev *rtwdev) +{ + rtw_write8(rtwdev, REG_PBP, + u8_encode_bits(PBP_128, PBP_RX_MASK) | + u8_encode_bits(PBP_128, PBP_TX_MASK)); +} + +static void rtw8723b_init_adaptive_ctrl(struct rtw_dev *rtwdev) +{ + /* + * Firmware validates RRSR at init: narrowing it to the mandatory + * rates makes it drop all management TX, so keep the full set. + */ + rtw_write32_mask(rtwdev, REG_RRSR, 0xfffff, 0xffff1); + rtwdev->dm_info.rrsr_val_init = 0xffff1; + rtw_write16(rtwdev, REG_RETRY_LIMIT, 0x3030); +} + +static void rtw8723b_init_edca(struct rtw_dev *rtwdev) +{ + rtw_write16(rtwdev, REG_SPEC_SIFS, 0x100a); + rtw_write16(rtwdev, REG_MAC_SPEC_SIFS, 0x100a); + rtw_write16(rtwdev, REG_SIFS, 0x100a); + rtw_write16(rtwdev, REG_SIFS + 2, 0x100a); + + /* + * RESP_SIFS must leave the AP enough slack, or it times out before the + * ACK reaches the air and the unicast handshake never completes. + */ + rtw_write16(rtwdev, REG_RESP_SIFS_CCK, 0x0808); + rtw_write16(rtwdev, REG_RESP_SIFS_OFDM, 0x0a0a); + + /* TXOP */ + rtw_write32(rtwdev, REG_EDCA_BE_PARAM, 0x005EA42B); + rtw_write32(rtwdev, REG_EDCA_BK_PARAM, 0x0000A44F); + rtw_write32(rtwdev, REG_EDCA_VI_PARAM, 0x005EA324); + rtw_write32(rtwdev, REG_EDCA_VO_PARAM, 0x002FA226); +} + +static void rtw8723b_init_beacon_parameters(struct rtw_dev *rtwdev) +{ + /* + * Both ports get DIS_TSF_UDT and EN_BCN_FUNCTION only; DIS_BCNQ_SUB + * belongs to AP/IBSS and must stay clear for station mode. + */ + rtw_write16(rtwdev, REG_BCN_CTRL, + (BIT_DIS_TSF_UDT | BIT_EN_BCN_FUNCTION) | + ((BIT_DIS_TSF_UDT | BIT_EN_BCN_FUNCTION) << 8)); + rtw_write8(rtwdev, REG_TBTT_PROHIBIT, TBTT_PROHIBIT_SETUP_TIME); + rtw_write8(rtwdev, REG_TBTT_PROHIBIT + 1, + TBTT_PROHIBIT_HOLD_TIME_STOP_BCN & 0xff); + rtw_write8(rtwdev, REG_TBTT_PROHIBIT + 2, + (rtw_read8(rtwdev, REG_TBTT_PROHIBIT + 2) & 0xf0) | + (TBTT_PROHIBIT_HOLD_TIME_STOP_BCN >> 8)); + + rtw_write8(rtwdev, REG_BCNDMATIM, WLAN_BCN_DMA_TIME); + /* Largest beacon AIFS: the chip does not contend before beaconing. */ + rtw_write16(rtwdev, REG_BCNTCFG, 0x660F); +} + +static void rtw8723b_init_antenna_selection(struct rtw_dev *rtwdev) +{ + rtw_write8(rtwdev, REG_LEDCFG2, WLAN_ANT_SEL); +} + +static void rtw8723b_inform_rfk_status(struct rtw_dev *rtwdev, bool start) +{ + u8 val8; + int ret; + + rtw_fw_inform_rfk_status(rtwdev, start); + + if (!start) + return; + + ret = read_poll_timeout(rtw_read8, val8, + val8 & BIT_RFK_FW_ACK, + 50000, 400000, false, + rtwdev, REG_RFK_FW_ACK); + if (ret) + rtw_warn(rtwdev, "failed to poll firmware RFK start ack\n"); +} + +static void rtw8723b_phy_set_param(struct rtw_dev *rtwdev) +{ + const struct rtw_chip_info *chip = rtwdev->chip; + u32 val32; + + rtw8723b_post_enable_flow(rtwdev); + + rtw_load_table(rtwdev, chip->mac_tbl); + rtw8723b_phy_bb_config(rtwdev); + rtw8723b_phy_load_bb_tables(rtwdev); + rtw8723b_phy_rf_config(rtwdev); + + /* enable CCK and OFDM block */ + rtw_write32_set(rtwdev, REG_FPGA0_RFMOD, BIT_CCKEN | BIT_OFDMEN); + + rtw8723b_init_transfer_page_size(rtwdev); + + /* + * The MAC table overwrites REG_MAR with 0xff, which would restrict + * multicast reception; accept every multicast address instead. + */ + rtw_write32(rtwdev, REG_MAR, 0xffffffff); + rtw_write32(rtwdev, REG_MAR + 4, 0xffffffff); + + rtw8723b_init_adaptive_ctrl(rtwdev); + rtw8723b_init_edca(rtwdev); + + rtw_write8_set(rtwdev, REG_FWHW_TXQ_CTRL, BIT(7)); + rtw_write8(rtwdev, REG_ACKTO, 0x40); + + /* sdio.c sets the DMA mode, but not the burst parameters. */ + rtw_write8(rtwdev, REG_RXDMA_MODE, + BIT_DMA_MODE | + FIELD_PREP_CONST(BIT_MASK_AGG_BURST_NUM, AGG_BURST_NUM) | + FIELD_PREP_CONST(BIT_MASK_AGG_BURST_SIZE, AGG_BURST_SIZE)); + + rtw8723b_init_beacon_parameters(rtwdev); + + /* configure packet burst */ + rtw_write8_set(rtwdev, REG_SINGLE_AMPDU_CTRL, BIT_EN_SINGLE_APMDU); + rtw_write8(rtwdev, REG_RX_PKT_LIMIT, 0x18); + rtw_write8(rtwdev, REG_MAX_AGGR_NUM, 0x1F); + rtw_write8(rtwdev, REG_PIFS, 0x00); + rtw_write8_clr(rtwdev, REG_FWHW_TXQ_CTRL, BIT(7)); + rtw_write8(rtwdev, REG_AMPDU_MAX_TIME, 0x70); + + /* + * 256 ms per-AC lifetime: the ROM default of ~1 s lets the chip retry + * data frames past the EAPOL retry window and reorders the connect. + */ + rtw_write16(rtwdev, REG_PKT_VO_VI_LIFE_TIME, 0x0400); + rtw_write16(rtwdev, REG_PKT_BE_BK_LIFE_TIME, 0x0400); + + rtw_write8(rtwdev, REG_SLOT, WLAN_SLOT_TIME); + + /* disable BAR */ + rtw_write32(rtwdev, REG_BAR_MODE_CTRL, WLAN_BAR_VAL); + + /* Enable hardware sequence numbering for all queues. */ + rtw_write8(rtwdev, REG_HWSEQ_CTRL, 0xff); + + if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_SDIO) { + /* + * Enable Rx DMA timer masking: clear 0x0[2:0] and + * 0x2[15:0] only. + */ + val32 = rtw_read32(rtwdev, REG_SDIO_TX_CTRL); + val32 &= 0x0000fff8; + rtw_write32(rtwdev, REG_SDIO_TX_CTRL, val32); + } + + rtw_write16(rtwdev, REG_ATIMWND, 0x2); + + rtw8723b_init_antenna_selection(rtwdev); + + rtw_write8_set(rtwdev, REG_CR, BIT_MACTXEN | BIT_MACRXEN); + + rtw_write8(rtwdev, REG_NAV_UPPER, 0xeb); /* ((30000 + 128 - 1) / 128) */ + + /* ack for xmit mgmt frames */ + rtw_write32_set(rtwdev, REG_FWHW_TXQ_CTRL, BIT(12)); + + rtw_phy_init(rtwdev); + + rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, 0x50); + rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, 0x20); + + rtw8723b_pwrtrack_init(rtwdev); +} + +static u32 rtw8723b_iqk_ant_switch_path(struct rtw_dev *rtwdev) +{ + bool shared_ant = rtwdev->efuse.bt_setting & BIT(0); + bool ant_path_b; + + if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_USB) + ant_path_b = shared_ant; + else + ant_path_b = rtwdev->efuse.bt_setting & BIT(6); + + if (!shared_ant || !ant_path_b) + return 0x0; + + return 0x280; +} + +static void rtw8723b_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw) +{ + u32 rf_cfgch; + + rf_cfgch = rtw_read_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK); + + u32p_replace_bits(&rf_cfgch, channel, RFCFGCH_CHANNEL_MASK); + + rf_cfgch &= ~RFCFGCH_BW_MASK; + rf_cfgch |= bw == RTW_CHANNEL_WIDTH_40 ? RFCFGCH_BW_40M : + RFCFGCH_BW_20M; + + /* The vendor driver programs both paths from the path A value. */ + rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_cfgch); + if (rtwdev->hal.rf_path_num > 1) + rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_cfgch); +} + +static void rtw8723b_set_channel_bb(struct rtw_dev *rtwdev, u8 bw, + u8 primary_ch_idx) +{ + switch (bw) { + case RTW_CHANNEL_WIDTH_20: + rtw_write32_mask(rtwdev, REG_FPGA0_RFMOD, BIT_MASK_RFMOD, 0x0); + rtw_write32_mask(rtwdev, REG_FPGA1_RFMOD, BIT_MASK_RFMOD, 0x0); + rtw_write32_mask(rtwdev, REG_OFDM0_TX_PSD_NOISE, + GENMASK(31, 30), 0x0); + break; + case RTW_CHANNEL_WIDTH_40: + rtw_write32_mask(rtwdev, REG_FPGA0_RFMOD, BIT_MASK_RFMOD, 0x1); + rtw_write32_mask(rtwdev, REG_FPGA1_RFMOD, BIT_MASK_RFMOD, 0x1); + rtw_write32_mask(rtwdev, REG_CCK0_SYS, BIT_CCK_SIDE_BAND, + primary_ch_idx == RTW_SC_20_UPPER ? 1 : 0); + rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTD_11N, 0xc00, + primary_ch_idx == RTW_SC_20_UPPER ? 2 : 1); + rtw_write32_mask(rtwdev, REG_BB_PWR_SAV5_11N, GENMASK(27, 26), + primary_ch_idx == RTW_SC_20_UPPER ? 1 : 2); + break; + default: + break; + } +} + +static void rtw8723b_set_channel(struct rtw_dev *rtwdev, u8 channel, + u8 bw, u8 primary_chan_idx) +{ + rtw8723b_set_channel_rf(rtwdev, channel, bw); + rtw_set_channel_mac(rtwdev, channel, bw, primary_chan_idx); + rtw8723b_set_channel_bb(rtwdev, bw, primary_chan_idx); +} + +static s8 rtw8723b_cck_rx_power(u8 lna_idx, u8 vga_idx) +{ + s8 rx_power = 0; + + switch (lna_idx) { + case 6: + rx_power = -40 - (2 * vga_idx); + break; + case 4: + rx_power = -20 - (2 * vga_idx); + break; + case 1: + rx_power = 0 - (2 * vga_idx); + break; + case 0: + rx_power = 10 - (2 * vga_idx); + break; + default: + break; + } + + return rx_power; +} + +static void rtw8723b_query_phy_status_cck(struct rtw_dev *rtwdev, void *phy_raw, + struct rtw_rx_pkt_stat *pkt_stat) +{ + struct phy_status_8723x *phy_status = phy_raw; + u8 lna_idx = u8_get_bits(phy_status->cck_agc_rpt_ofdm_cfosho_a, 0xE0); + u8 vga_idx = u8_get_bits(phy_status->cck_agc_rpt_ofdm_cfosho_a, 0x1F); + s8 rx_power = rtw8723b_cck_rx_power(lna_idx, vga_idx); + s8 min_rx_power = -120; + + pkt_stat->bw = RTW_CHANNEL_WIDTH_20; + + pkt_stat->rx_power[RF_PATH_A] = rx_power; + pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1); + pkt_stat->signal_power = max(pkt_stat->rx_power[RF_PATH_A], + min_rx_power); + rtwdev->dm_info.rssi[RF_PATH_A] = pkt_stat->rssi; +} + +static void rtw8723b_query_phy_status_ofdm(struct rtw_dev *rtwdev, void *phy_raw, + struct rtw_rx_pkt_stat *pkt_stat) +{ + struct phy_status_8723x *phy_status = phy_raw; + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + s8 val_s8; + + /* pkt_stat->bw comes from the RX descriptor, not the PHY status. */ + + val_s8 = phy_status->path_agc[RF_PATH_A].gain & 0x3F; + pkt_stat->rx_power[RF_PATH_A] = (val_s8 * 2) - 110; + + pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1); + pkt_stat->rx_snr[RF_PATH_A] = (s8)(phy_status->path_rxsnr[RF_PATH_A] / 2); + + /* signal power reported by HW */ + val_s8 = phy_status->cck_sig_qual_ofdm_pwdb_all >> 1; + pkt_stat->signal_power = (val_s8 & 0x7f) - 110; + + pkt_stat->rx_evm[RF_PATH_A] = phy_status->stream_rxevm[RF_PATH_A]; + pkt_stat->cfo_tail[RF_PATH_A] = phy_status->path_cfotail[RF_PATH_A]; + + dm_info->curr_rx_rate = pkt_stat->rate; + dm_info->rssi[RF_PATH_A] = pkt_stat->rssi; + dm_info->rx_snr[RF_PATH_A] = pkt_stat->rx_snr[RF_PATH_A] >> 1; + dm_info->cfo_tail[RF_PATH_A] = (pkt_stat->cfo_tail[RF_PATH_A] * 5) >> 1; + + val_s8 = (s8)pkt_stat->rx_evm[RF_PATH_A]; + val_s8 = clamp_t(s8, -val_s8 >> 1, 0, 64); + val_s8 &= 0x3F; /* 64->0: second path of 1SS rate is 64 */ + dm_info->rx_evm_dbm[RF_PATH_A] = val_s8; +} + +static void rtw8723b_query_phy_status(struct rtw_dev *rtwdev, u8 *phy_status, + struct rtw_rx_pkt_stat *pkt_stat) +{ + /* + * The 8723B PHY status does not report the channel, so we must + * mark it invalid to allow mac80211/rtw88 to parse it from the IE + * during scanning. + */ + pkt_stat->channel_invalid = true; + + if (pkt_stat->rate <= DESC_RATE11M) + rtw8723b_query_phy_status_cck(rtwdev, phy_status, pkt_stat); + else + rtw8723b_query_phy_status_ofdm(rtwdev, phy_status, pkt_stat); +} + +static void rtw8723b_set_iqk_matrix_by_result(struct rtw_dev *rtwdev, + u32 ofdm_swing, u8 path) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + s32 ele_a, ele_d, ele_c, ele_a_ext; + s32 iqk_result_x; + s32 iqk_result_y; + s32 value32; + + switch (path) { + default: + case RF_PATH_A: + iqk_result_x = dm_info->iqk.result.s1_x; + iqk_result_y = dm_info->iqk.result.s1_y; + break; + case RF_PATH_B: + iqk_result_x = dm_info->iqk.result.s0_x; + iqk_result_y = dm_info->iqk.result.s0_y; + break; + } + + /* new element D */ + ele_d = OFDM_SWING_D(ofdm_swing); + + /* new element A */ + iqk_result_x = iqkxy_to_s32(iqk_result_x); + ele_a = iqk_mult(iqk_result_x, ele_d, &ele_a_ext); + + /* new element C */ + iqk_result_y = iqkxy_to_s32(iqk_result_y); + ele_c = iqk_mult(iqk_result_y, ele_d, NULL); + + switch (path) { + case RF_PATH_A: + default: + /* write new elements A, C, D, element B is always 0 */ + value32 = BIT_SET_TXIQ_ELM_ACD(ele_a, ele_c, ele_d); + rtw_write32(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, value32); + value32 = BIT_SET_TXIQ_ELM_C1(ele_c); + rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N, MASKH4BITS, + value32); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), + ele_a_ext); + break; + + case RF_PATH_B: + /* write new elements A, C, D, element B is always 0 */ + value32 = BIT_SET_TXIQ_ELM_ACD(ele_a, ele_c, ele_d); + rtw_write32(rtwdev, REG_OFDM_0_XB_TX_IQ_IMBALANCE, value32); + value32 = BIT_SET_TXIQ_ELM_C1(ele_c); + rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXB_LSB2_11N, MASKH4BITS, + value32); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), + ele_a_ext); + break; + } +} + +static void rtw8723b_set_iqk_matrix(struct rtw_dev *rtwdev, s8 ofdm_index, + u8 path) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + u32 ofdm_swing; + + ofdm_index = clamp_t(s8, ofdm_index, 0, RTW_OFDM_SWING_TABLE_SIZE - 1); + + ofdm_swing = rtw8723b_ofdm_swing_table[ofdm_index]; + + if (dm_info->iqk.done) { + rtw8723b_set_iqk_matrix_by_result(rtwdev, ofdm_swing, path); + return; + } + + switch (path) { + case RF_PATH_A: + default: + rtw_write32(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, ofdm_swing); + rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N, MASKH4BITS, + 0x00); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), + 0x00); + break; + + case RF_PATH_B: + rtw_write32(rtwdev, REG_OFDM_0_XB_TX_IQ_IMBALANCE, ofdm_swing); + rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXB_LSB2_11N, MASKH4BITS, + 0x00); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), + 0x00); + break; + } +} + +static u8 rtw8723b_iqk_check_tx_failed(struct rtw_dev *rtwdev) +{ + s32 tx_x, tx_y; + u32 tx_fail; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xeac = 0x%x\n", + rtw_read32(rtwdev, REG_IQK_RES_RY)); + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xe94 = 0x%x, 0xe9c = 0x%x\n", + rtw_read32(rtwdev, REG_IQK_RES_TX), + rtw_read32(rtwdev, REG_IQK_RES_TY)); + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] 0xe90(before IQK) = 0x%x, 0xe98(after IQK) = 0x%x\n", + rtw_read32(rtwdev, REG_IQK_RDY), + rtw_read32(rtwdev, 0xe98)); + + tx_fail = rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_IQK_TX_FAIL); + tx_x = rtw_read32_mask(rtwdev, REG_IQK_RES_TX, BIT_MASK_RES_TX); + tx_y = rtw_read32_mask(rtwdev, REG_IQK_RES_TY, BIT_MASK_RES_TY); + + if (!tx_fail && tx_x != IQK_TX_X_ERR && tx_y != IQK_TX_Y_ERR) + return IQK_TX_OK; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] A TX IQK failed\n"); + + return 0; +} + +static u8 rtw8723b_iqk_check_rx_failed(struct rtw_dev *rtwdev) +{ + s32 rx_x, rx_y; + u32 rx_fail; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xea4 = 0x%x, 0xeac = 0x%x\n", + rtw_read32(rtwdev, REG_IQK_RES_RX), + rtw_read32(rtwdev, REG_IQK_RES_RY)); + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] 0xea0(before IQK) = 0x%x, 0xea8(after IQK) = 0x%x\n", + rtw_read32(rtwdev, 0xea0), + rtw_read32(rtwdev, 0xea8)); + + rx_fail = rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_IQK_RX_FAIL); + rx_x = rtw_read32_mask(rtwdev, REG_IQK_RES_RX, BIT_MASK_RES_RX); + rx_y = rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_MASK_RES_RY); + rx_y = abs(iqkxy_to_s32(rx_y)); + + if (!rx_fail && rx_x != IQK_RX_X_ERR && rx_y != IQK_RX_Y_ERR && + rx_x < IQK_RX_X_UPPER && rx_x > IQK_RX_X_LOWER && + rx_y < IQK_RX_Y_LMT) + return IQK_RX_OK; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] A RX IQK failed\n"); + + return 0; +} + +static u8 rtw8723b_iqk_tx_path_a(struct rtw_dev *rtwdev) +{ + u32 path_sel; + u8 status; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path A TX IQK!\n"); + + /* Save RF path */ + path_sel = rtw_read32(rtwdev, REG_BB_SEL_BTG); + + /* leave IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + + /* enable path A PA in TX IQK mode */ + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE, 0x80000, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_ADDR, RFREG_MASK, + 0x20000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA0, RFREG_MASK, 0x0003f); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA1, RFREG_MASK, 0xc7f87); + + /* Tx IQK setting */ + rtw_write32(rtwdev, REG_TXIQK_11N, 0x01007c00); + rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); + + /* path-A IQK setting */ + rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x18008c1c); + rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x38008c1c); + rtw_write32(rtwdev, REG_TX_IQK_TONE_B, 0x38008c1c); + rtw_write32(rtwdev, REG_RX_IQK_TONE_B, 0x38008c1c); + + rtw_write32(rtwdev, REG_TXIQK_PI_A_11N, 0x821403ea); + rtw_write32(rtwdev, REG_RXIQK_PI_A_11N, 0x28110000); + rtw_write32(rtwdev, REG_TXIQK_PI_B, 0x82110000); + rtw_write32(rtwdev, REG_RXIQK_PI_B, 0x28110000); + + /* LO calibration setting */ + rtw_write32(rtwdev, REG_IQK_AGC_RSP_11N, 0x00462911); + + /* enter IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x808000); + + /* ant switch */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, + rtw8723b_iqk_ant_switch_path(rtwdev)); + + /* GNT_BT = 0 */ + rtw_write32(rtwdev, REG_BT_CONTROL, 0x00000800); + + /* One shot, path A LOK & IQK */ + rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf9000000); + rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf8000000); + + msleep(IQK_DELAY_TIME_8723B); + + /* restore ant path */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, path_sel); + + /* GNT_BT = 1 */ + rtw_write32(rtwdev, REG_BT_CONTROL, 0x00001800); + + /* leave IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + + status = rtw8723b_iqk_check_tx_failed(rtwdev); + + return status; +} + +static u8 rtw8723b_iqk_rx_path_a(struct rtw_dev *rtwdev) +{ + u32 reg_e94, reg_e9c, val32, path_sel; + u8 status; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path A RX IQK step1!\n"); + + /* Save RF path */ + path_sel = rtw_read32(rtwdev, REG_BB_SEL_BTG); + + /* leave IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE, 0x80000, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_ADDR, RFREG_MASK, + 0x30000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA0, RFREG_MASK, 0x0001f); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA1, RFREG_MASK, 0xf7fb7); + + /* IQK setting */ + rtw_write32(rtwdev, REG_TXIQK_11N, 0x01007c00); + rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); + + /* path-A IQK setting */ + rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x18008c1c); + rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x38008c1c); + rtw_write32(rtwdev, REG_TX_IQK_TONE_B, 0x38008c1c); + rtw_write32(rtwdev, REG_RX_IQK_TONE_B, 0x38008c1c); + + rtw_write32(rtwdev, REG_TXIQK_PI_A_11N, 0x82160ff0); + rtw_write32(rtwdev, REG_RXIQK_PI_A_11N, 0x28110000); + rtw_write32(rtwdev, REG_TXIQK_PI_B, 0x82110000); + rtw_write32(rtwdev, REG_RXIQK_PI_B, 0x28110000); + + /* LO calibration setting */ + rtw_write32(rtwdev, REG_IQK_AGC_RSP_11N, 0x0046a911); + + /* enter IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x808000); + + /* ant switch */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, + rtw8723b_iqk_ant_switch_path(rtwdev)); + + /* GNT_BT = 0 (disable BT) */ + rtw_write32(rtwdev, REG_BT_CONTROL, 0x00000800); + + /* One shot, path A LOK & IQK */ + rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf9000000); + rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf8000000); + + msleep(IQK_DELAY_TIME_8723B); + + /* restore ant path */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, path_sel); + + /* GNT_BT = 1 */ + rtw_write32(rtwdev, REG_BT_CONTROL, 0x00001800); + + /* leave IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + + status = rtw8723b_iqk_check_tx_failed(rtwdev); + + /* if Tx not OK, ignore Rx */ + if (!status) + return status; + + reg_e94 = rtw_read32(rtwdev, REG_IQK_RES_TX); + reg_e9c = rtw_read32(rtwdev, REG_IQK_RES_TY); + val32 = 0x80007c00 | (reg_e94 & 0x3ff0000) | + ((reg_e9c & 0x3ff0000) >> 16); + rtw_write32(rtwdev, REG_TXIQK_11N, val32); + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path A RX IQK step2!\n"); + + /* modify RX IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE, 0x80000, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_ADDR, RFREG_MASK, + 0x30000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA0, RFREG_MASK, 0x0001f); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA1, RFREG_MASK, 0xf7d77); + + /* PA, PAD setting */ + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTDBG, RFREG_MASK, 0xf80); + rtw_write_rf(rtwdev, RF_PATH_A, 0x55, RFREG_MASK, 0x4021f); + + /* IQK setting */ + rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); + + /* path-A IQK setting */ + rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x38008c1c); + rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x18008c1c); + rtw_write32(rtwdev, REG_TX_IQK_TONE_B, 0x38008c1c); + rtw_write32(rtwdev, REG_RX_IQK_TONE_B, 0x38008c1c); + + rtw_write32(rtwdev, REG_TXIQK_PI_A_11N, 0x82110000); + rtw_write32(rtwdev, REG_RXIQK_PI_A_11N, 0x2816001f); + rtw_write32(rtwdev, REG_TXIQK_PI_B, 0x82110000); + rtw_write32(rtwdev, REG_RXIQK_PI_B, 0x28110000); + + /* LO calibration setting */ + rtw_write32(rtwdev, REG_IQK_AGC_RSP_11N, 0x0046a8d1); + + /* enter IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x808000); + + /* ant switch */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, + rtw8723b_iqk_ant_switch_path(rtwdev)); + + /* GNT_BT = 0 */ + rtw_write32(rtwdev, REG_BT_CONTROL, 0x00000800); + + /* One shot, path A LOK & IQK */ + rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf9000000); + rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf8000000); + + msleep(IQK_DELAY_TIME_8723B); + + /* restore ant path */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, path_sel); + + /* GNT_BT = 1 */ + rtw_write32(rtwdev, REG_BT_CONTROL, 0x00001800); + + /* leave IQK mode */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTDBG, RFREG_MASK, 0x780); + + status |= rtw8723b_iqk_check_rx_failed(rtwdev); + + return status; +} + +static void +rtw8723b_iqk_fill_a_matrix(struct rtw_dev *rtwdev, const s32 result[]) +{ + s32 tx1_a, tx1_a_ext; + s32 tx1_c, tx1_c_ext; + s32 oldval_1; + s32 x, y; + + if (result[IQK_S1_TX_X] == 0) + return; + + oldval_1 = rtw_read32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, + BIT_MASK_TXIQ_ELM_D); + + x = iqkxy_to_s32(result[IQK_S1_TX_X]); + tx1_a = iqk_mult(x, oldval_1, &tx1_a_ext); + rtw_write32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, + BIT_MASK_TXIQ_ELM_A, tx1_a); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, + BIT_MASK_OFDM0_EXT_A, tx1_a_ext); + + y = iqkxy_to_s32(result[IQK_S1_TX_Y]); + tx1_c = iqk_mult(y, oldval_1, &tx1_c_ext); + rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N, MASKH4BITS, + BIT_SET_TXIQ_ELM_C1(tx1_c)); + rtw_write32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, + BIT_MASK_TXIQ_ELM_C, BIT_SET_TXIQ_ELM_C2(tx1_c)); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, + BIT_MASK_OFDM0_EXT_C, tx1_c_ext); + + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] X = 0x%x, TX1_A = 0x%x, oldval_1 0x%x\n", + x, tx1_a, oldval_1); + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] Y = 0x%x, TX1_C = 0x%x\n", y, tx1_c); + + if (result[IQK_S1_RX_X] == 0) + return; + + rtw_write32_mask(rtwdev, REG_A_RXIQI, BIT_MASK_RXIQ_S1_X, + result[IQK_S1_RX_X]); + rtw_write32_mask(rtwdev, REG_A_RXIQI, BIT_MASK_RXIQ_S1_Y1, + BIT_SET_RXIQ_S1_Y1(result[IQK_S1_RX_Y])); + rtw_write32_mask(rtwdev, REG_RXIQK_MATRIX_LSB_11N, BIT_MASK_RXIQ_S1_Y2, + BIT_SET_RXIQ_S1_Y2(result[IQK_S1_RX_Y])); +} + +static void +rtw8723b_iqk_fill_b_matrix(struct rtw_dev *rtwdev, const s32 result[]) +{ + s32 tx0_a, tx0_a_ext; + s32 tx0_c, tx0_c_ext; + s32 oldval_0; + s32 x, y; + + if (result[IQK_S0_TX_X] == 0) + return; + + oldval_0 = rtw_read32_mask(rtwdev, REG_OFDM_0_XB_TX_IQ_IMBALANCE, + BIT_MASK_TXIQ_ELM_D); + + x = iqkxy_to_s32(result[IQK_S0_TX_X]); + tx0_a = iqk_mult(x, oldval_0, &tx0_a_ext); + + rtw_write32_mask(rtwdev, REG_OFDM_0_XB_TX_IQ_IMBALANCE, + BIT_MASK_TXIQ_ELM_A, tx0_a); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, BIT(27), + tx0_a_ext); + + y = iqkxy_to_s32(result[IQK_S0_TX_Y]); + tx0_c = iqk_mult(y, oldval_0, &tx0_c_ext); + + rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXB_LSB2_11N, MASKH4BITS, + BIT_SET_TXIQ_ELM_C1(tx0_c)); + rtw_write32_mask(rtwdev, REG_OFDM_0_XB_TX_IQ_IMBALANCE, + BIT_MASK_TXIQ_ELM_C, BIT_SET_TXIQ_ELM_C2(tx0_c)); + rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, BIT(25), + tx0_c_ext); + + if (result[IQK_S0_RX_X] == 0) + return; + + rtw_write32_mask(rtwdev, REG_B_RXIQI, BIT_MASK_RXIQ_X_S0, + result[IQK_S0_RX_X]); + rtw_write32_mask(rtwdev, REG_B_RXIQI, BIT_MASK_RXIQ_S1_Y1, + BIT_SET_RXIQ_S1_Y1(result[IQK_S0_RX_Y])); +} + +static void +rtw8723b_iqk_config_mac(struct rtw_dev *rtwdev, + const struct rtw8723x_iqk_backup_regs *backup) +{ + int i; + + rtw_write8(rtwdev, rtw8723x_common.iqk_mac8_regs[0], 0x3f); + + for (i = 1; i < RTW8723X_IQK_MAC8_REG_NUM; i++) + rtw_write8(rtwdev, rtw8723x_common.iqk_mac8_regs[i], + backup->mac8[i] & (~BIT(3))); + + /* This MAC backup register needs a byte-wide write. */ + rtw_write8(rtwdev, rtw8723x_common.iqk_mac32_regs[0], + backup->mac32[0] & (~BIT(5))); +} + +static void +rtw8723b_iqk_one_round(struct rtw_dev *rtwdev, s32 result[][IQK_NR], u8 t, + const struct rtw8723x_iqk_backup_regs *backup) +{ + u8 a_ok; + u32 i; + + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] IQ Calibration for 1T1R_S0/S1 for %d times\n", t); + + rtw8723x_iqk_path_adda_on(rtwdev, ADDA_ON_VAL_8723B); + rtw8723b_iqk_config_mac(rtwdev, backup); + + rtw_write32_mask(rtwdev, REG_CCK_ANT_SEL_11N, 0x0f000000, 0xf); + rtw_write32(rtwdev, REG_BB_RX_PATH_11N, 0x03a05600); + rtw_write32(rtwdev, REG_TRMUX_11N, 0x000800e4); + rtw_write32(rtwdev, REG_BB_PWR_SAV1_11N, 0x22204000); + + /* + * RX IQ calibration setting for 8723B D cut large current issue + * when leaving IPS + */ + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE, 0x80000, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_ADDR, RFREG_MASK, 0x30000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA0, RFREG_MASK, 0x0001f); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA1, RFREG_MASK, 0xf7fb7); + rtw_write_rf(rtwdev, RF_PATH_A, 0xed, 0x20, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, 0x43, RFREG_MASK, 0x60fbd); + + for (i = 0; i < PATH_IQK_RETRY; i++) { + a_ok = rtw8723b_iqk_tx_path_a(rtwdev); + if (a_ok != IQK_TX_OK) { + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] path A TX IQK fail!\n"); + result[t][IQK_S1_TX_X] = 0x100; + result[t][IQK_S1_TX_Y] = 0x0; + continue; + } + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path A TX IQK success!\n"); + + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, + MASKH3BYTES, 0x000000); + + result[t][IQK_S1_TX_X] = + rtw_read32_mask(rtwdev, REG_IQK_RES_TX, + BIT_MASK_RES_TX); + result[t][IQK_S1_TX_Y] = + rtw_read32_mask(rtwdev, REG_IQK_RES_TY, + BIT_MASK_RES_TY); + break; + } + + for (i = 0; i < PATH_IQK_RETRY; i++) { + a_ok = rtw8723b_iqk_rx_path_a(rtwdev); + if (a_ok != (IQK_TX_OK | IQK_RX_OK)) { + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] path A RX IQK fail!\n"); + result[t][IQK_S1_RX_X] = 0x100; + result[t][IQK_S1_RX_Y] = 0x0; + continue; + } + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path A RX IQK success!\n"); + result[t][IQK_S1_RX_X] = + rtw_read32_mask(rtwdev, REG_IQK_RES_RX, + BIT_MASK_RES_RX); + result[t][IQK_S1_RX_Y] = + rtw_read32_mask(rtwdev, REG_IQK_RES_RY, + BIT_MASK_RES_RY); + break; + } + + if (a_ok == 0x0) + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path A IQK fail!\n"); + + /* + * The vendor driver calibrates path B only when the board is not + * 1-antenna (its is2T), which this driver does not support. + */ + + rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, MASKH3BYTES, 0x000000); +} + +static void rtw8723b_phy_calibration(struct rtw_dev *rtwdev) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + struct rtw8723x_iqk_backup_regs backup; + s32 result[IQK_ROUND_SIZE][IQK_NR]; + u32 bt_control_before; + u8 final_candidate; + bool good; + u8 i, j; + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] Start!\n"); + memset(result, 0, sizeof(result)); + final_candidate = IQK_ROUND_INVALID; + + rtw8723b_lck(rtwdev); + rtw8723b_inform_rfk_status(rtwdev, true); + + /* The LTE path GNT backup that 8723d does is not needed on SDIO. */ + rtw8723x_iqk_backup_path_ctrl(rtwdev, &backup); + rtw8723x_iqk_backup_regs(rtwdev, &backup); + + /* save default GNT_BT */ + bt_control_before = rtw_read32(rtwdev, REG_BT_CONTROL); + + for (i = IQK_ROUND_0; i <= IQK_ROUND_2; i++) { + rtw8723b_iqk_one_round(rtwdev, result, i, &backup); + + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] back to BB mode, load original value!\n"); + + if (i > IQK_ROUND_0) { + rtw8723x_iqk_restore_regs(rtwdev, &backup); + + /* Restore RX initial gain */ + rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, 0x50); + rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, backup.igia); + + /* load 0xe30 IQC default value */ + rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x01008c00); + rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x01008c00); + } + + for (j = IQK_ROUND_0; j < i; j++) { + good = rtw8723x_iqk_similarity_cmp(rtwdev, result, j, i); + if (good) { + final_candidate = j; + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] cmp %d:%d final_candidate is %x\n", + j, i, final_candidate); + goto iqk_done; + } + } + } + + if (final_candidate == IQK_ROUND_INVALID) { + s32 reg_tmp = 0; + + for (i = 0; i < IQK_NR; i++) + reg_tmp += result[IQK_ROUND_HYBRID][i]; + + if (reg_tmp != 0) { + final_candidate = IQK_ROUND_HYBRID; + } else { + rtw_warn(rtwdev, "IQK failed\n"); + goto out; + } + } + +iqk_done: + if (result[final_candidate][IQK_S1_TX_X]) + rtw8723b_iqk_fill_a_matrix(rtwdev, result[final_candidate]); + if (result[final_candidate][IQK_S0_TX_X]) + rtw8723b_iqk_fill_b_matrix(rtwdev, result[final_candidate]); + + dm_info->iqk.result.s1_x = result[final_candidate][IQK_S1_TX_X]; + dm_info->iqk.result.s1_y = result[final_candidate][IQK_S1_TX_Y]; + dm_info->iqk.result.s0_x = result[final_candidate][IQK_S0_TX_X]; + dm_info->iqk.result.s0_y = result[final_candidate][IQK_S0_TX_Y]; + dm_info->iqk.done = true; + +out: + /* restore RF path */ + rtw_write32(rtwdev, REG_BB_SEL_BTG, backup.bb_sel_btg); + + /* restore GNT_BT */ + rtw_write32(rtwdev, REG_BT_CONTROL, bt_control_before); + + /* Restore RX mode table parameter */ + rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE, 0x80000, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_ADDR, RFREG_MASK, 0x18000); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA0, RFREG_MASK, 0x0001f); + rtw_write_rf(rtwdev, RF_PATH_A, RF_MODE_TABLE_DATA1, RFREG_MASK, 0xe6177); + rtw_write_rf(rtwdev, RF_PATH_A, 0xed, 0x20, 0x1); + rtw_write_rf(rtwdev, RF_PATH_A, 0x43, RFREG_MASK, 0x300bd); + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] final_candidate is %x\n", + final_candidate); + + for (i = IQK_ROUND_0; i < IQK_ROUND_SIZE; i++) { + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] Result %u s1: rege94=%x rege9c=%x regea4=%x regeac=%x\n", + i, result[i][0], result[i][1], result[i][2], + result[i][3]); + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK] Result %u s0: rege94=%x rege9c=%x regea4=%x regeac=%x%s\n", + i, result[i][4], result[i][5], result[i][6], + result[i][7], + final_candidate == i ? " (final candidate)" : ""); + } + + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK]0xc80 = 0x%x 0xc94 = 0x%x 0xc14 = 0x%x 0xca0 = 0x%x\n", + rtw_read32(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE), + rtw_read32(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N), + rtw_read32(rtwdev, REG_A_RXIQI), + rtw_read32(rtwdev, REG_RXIQK_MATRIX_LSB_11N)); + rtw_dbg(rtwdev, RTW_DBG_RFK, + "[IQK]0xcd0 = 0x%x 0xcd4 = 0x%x 0xcd8 = 0x%x\n", + rtw_read32(rtwdev, REG_TXIQ_AB_S0), + rtw_read32(rtwdev, REG_TXIQ_CD_S0), + rtw_read32(rtwdev, REG_RXIQ_AB_S0)); + + rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] finished\n"); + + rtw8723b_inform_rfk_status(rtwdev, false); +} + +static void rtw8723b_pwrtrack_set_ofdm_pwr(struct rtw_dev *rtwdev, u8 path, + s8 swing_idx, s8 txagc_idx) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + + dm_info->txagc_remnant_ofdm[path] = txagc_idx; + + rtw8723b_set_iqk_matrix(rtwdev, swing_idx, path); +} + +static void rtw8723b_pwrtrack_set_cck_pwr(struct rtw_dev *rtwdev, s8 swing_idx, + s8 txagc_idx) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + const u8 *table; + int i; + + dm_info->txagc_remnant_cck = txagc_idx; + + swing_idx = clamp_t(s8, swing_idx, 0, RTW_CCK_SWING_TABLE_SIZE - 1); + + BUILD_BUG_ON(ARRAY_SIZE(rtw8723b_cck_swing_table_ch1_ch13[0]) != + RTW_CCK_SWING_REG_NUM); + + table = rtwdev->hal.current_channel == 14 ? + rtw8723b_cck_swing_table_ch14[swing_idx] : + rtw8723b_cck_swing_table_ch1_ch13[swing_idx]; + + for (i = 0; i < RTW_CCK_SWING_REG_NUM; i++) + rtw_write8(rtwdev, REG_CCK_SWING + i, table[i]); +} + +static void rtw8723b_pwrtrack_set(struct rtw_dev *rtwdev, u8 path) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + struct rtw_hal *hal = &rtwdev->hal; + s8 final_ofdm_swing_index; + s8 final_cck_swing_index; + /* + * 8703b and 8723d seem to use RTW_CCK_SWING_TABLE_SIZE, which is + * -2dB on this chip. + */ + u8 limit_cck = 28; + u8 limit_ofdm; + + limit_ofdm = rtw8723x_pwrtrack_get_limit_ofdm(rtwdev); + + final_ofdm_swing_index = dm_info->default_ofdm_index + + dm_info->delta_power_index[path]; + final_cck_swing_index = dm_info->default_cck_index + + dm_info->delta_power_index[path]; + + if (final_ofdm_swing_index > limit_ofdm) + rtw8723b_pwrtrack_set_ofdm_pwr(rtwdev, path, limit_ofdm, + final_ofdm_swing_index - limit_ofdm); + else if (final_ofdm_swing_index < 0) + rtw8723b_pwrtrack_set_ofdm_pwr(rtwdev, path, 0, + final_ofdm_swing_index); + else + rtw8723b_pwrtrack_set_ofdm_pwr(rtwdev, path, final_ofdm_swing_index, 0); + + if (final_cck_swing_index > limit_cck) + rtw8723b_pwrtrack_set_cck_pwr(rtwdev, limit_cck, + final_cck_swing_index - limit_cck); + else if (final_cck_swing_index < 0) + rtw8723b_pwrtrack_set_cck_pwr(rtwdev, 0, + final_cck_swing_index); + else + rtw8723b_pwrtrack_set_cck_pwr(rtwdev, final_cck_swing_index, 0); + + rtw_phy_set_tx_power_level(rtwdev, hal->current_channel); +} + +static void rtw8723b_phy_pwrtrack(struct rtw_dev *rtwdev) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + struct rtw_swing_table swing_table; + u8 thermal_value, delta, path; + bool do_lck = false; + + rtw_phy_config_swing_table(rtwdev, &swing_table); + + if (rtwdev->efuse.thermal_meter[0] == 0xff) + return; + + thermal_value = rtw_read_rf(rtwdev, RF_PATH_A, RF_T_METER, 0xfc00); + + /* Average the thermal meter readings. */ + rtw_phy_pwrtrack_avg(rtwdev, thermal_value, RF_PATH_A); + + /* + * The vendor's power tracking redoes the LC calibration when the + * thermal value drifts, but it skips the IQK for this chip, so the + * threshold that rtw_phy_pwrtrack_need_iqk() tracks gates only the + * LC calibration here. + */ + do_lck = rtw_phy_pwrtrack_need_iqk(rtwdev); + + if (do_lck) + rtw8723b_lck(rtwdev); + + if (dm_info->pwr_trk_init_trigger) + dm_info->pwr_trk_init_trigger = false; + else if (!rtw_phy_pwrtrack_thermal_changed(rtwdev, thermal_value, + RF_PATH_A)) + return; + + delta = rtw_phy_pwrtrack_get_delta(rtwdev, RF_PATH_A); + + for (path = 0; path < rtwdev->hal.rf_path_num; path++) { + s8 delta_cur, delta_last; + + delta_last = dm_info->delta_power_index[path]; + delta_cur = rtw_phy_pwrtrack_get_pwridx(rtwdev, &swing_table, + path, RF_PATH_A, delta); + if (delta_last == delta_cur) + continue; + + dm_info->delta_power_index[path] = delta_cur; + rtw8723b_pwrtrack_set(rtwdev, path); + } +} + +static void rtw8723b_pwr_track(struct rtw_dev *rtwdev) +{ + struct rtw_dm_info *dm_info = &rtwdev->dm_info; + struct rtw_efuse *efuse = &rtwdev->efuse; + + if (efuse->power_track_type != 0) + return; + + if (!dm_info->pwr_trk_triggered) { + rtw_write_rf(rtwdev, RF_PATH_A, RF_T_METER, + GENMASK(17, 16), 0x03); + dm_info->pwr_trk_triggered = true; + return; + } + + rtw8723b_phy_pwrtrack(rtwdev); + dm_info->pwr_trk_triggered = false; +} + +/* + * The vendor sequence for this chip differs from rtw8723x_coex_cfg_init(): + * REG_BT_TDMA_TIME is written whole, PTA pins and REG_QUEUE_CTRL untouched. + */ +static void rtw8723b_coex_cfg_init(struct rtw_dev *rtwdev) +{ + /* enable TBTT interrupt */ + rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION); + + /* BT report packet sample rate, 0x790[5:0] = 0x5 */ + rtw_write8(rtwdev, REG_BT_TDMA_TIME, 0x5); + + /* enable BT counter statistics */ + rtw_write8(rtwdev, REG_BT_STAT_CTRL, 0x1); + + /* enable PTA (3-wire function from BT side) */ + rtw_write8_mask(rtwdev, REG_GPIO_MUXCFG, BIT_BT_PTA_EN, 0x1); +} + +static void rtw8723b_coex_set_gnt_fix(struct rtw_dev *rtwdev) +{ + /* intentionally empty: rtw8723d's coex_set_gnt_fix is empty too */ +} + +static void rtw8723b_coex_set_gnt_debug(struct rtw_dev *rtwdev) +{ + /* GNT_BT debug routing is not implemented; not needed for operation. */ +} + +static bool rtw8723b_coex_ant_is_aux(struct rtw_dev *rtwdev) +{ + return !!(rtwdev->efuse.bt_setting & BIT(6)); +} + +static void rtw8723b_coex_set_ant_ctrl_by_wifi(struct rtw_dev *rtwdev) +{ + /* 0x4c[23] = 1, 0x4c[24] = 0: antenna control by 0x64. */ + rtw_write32_clr(rtwdev, REG_LED_CFG, BIT(24)); + rtw_write32_set(rtwdev, REG_LED_CFG, BIT(23)); +} + +static void rtw8723b_coex_set_ant_ctrl_by_bt(struct rtw_dev *rtwdev) +{ + /* 0x4c[24:23] = 0: antenna control by BT_RFE_CTRL. */ + rtw_write32_clr(rtwdev, REG_LED_CFG, BIT(23) | BIT(24)); +} + +static void rtw8723b_coex_cfg_ant_buffer(struct rtw_dev *rtwdev) +{ + rtw_write8_set(rtwdev, REG_PWR_DATA + 1, + BIT_EEPRPAD_RFE_CTRL_EN >> 8); + rtw_write8(rtwdev, REG_RFE_CTRL_E, 0xff); + rtw_write8_mask(rtwdev, REG_RFE_CTRL_ANT_SW, BIT_RFE_CTRL_ANT_SW_SEL, 0x3); + rtw_write8(rtwdev, REG_RFE_CTRL_ANTA_SRC, 0x77); +} + +static u32 rtw8723b_coex_ant_path_value(struct rtw_dev *rtwdev, u8 pos_type) +{ + bool aux = rtw8723b_coex_ant_is_aux(rtwdev); + + switch (pos_type) { + case COEX_SWITCH_TO_BT: + return aux ? 0x0 : 0x280; + case COEX_SWITCH_TO_WLG: + case COEX_SWITCH_TO_WLA: + return aux ? 0x280 : 0x0; + case COEX_SWITCH_TO_WLG_BT: + case COEX_SWITCH_TO_NOCARE: + default: + return aux ? 0x80 : 0x200; + } +} + +static void rtw8723b_coex_cfg_ant_switch(struct rtw_dev *rtwdev, + u8 ctrl_type, u8 pos_type) +{ + u32 ant_path; + + if (rtw_hci_type(rtwdev) != RTW_HCI_TYPE_SDIO) + return; + + if (ctrl_type == COEX_SWITCH_CTRL_BY_BT) { + rtw_write8(rtwdev, REG_GNT_BT, 0x18); + rtw_write8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL, 0x4); + rtw_write8_clr(rtwdev, REG_BT_ANT_SEL, + BIT_BT_SEL_BY_WIFI); + rtw8723b_coex_set_ant_ctrl_by_bt(rtwdev); + ant_path = rtw8723b_coex_ant_path_value(rtwdev, + COEX_SWITCH_TO_BT); + rtw_write32(rtwdev, REG_BB_SEL_BTG, ant_path); + + rtw_dbg(rtwdev, RTW_DBG_COEX, + "[BTCoex], 8723bs ant switch by BT BB_SEL_BTG=0x%08x 0x4c=0x%08x 0x67=0x%02x 0x765=0x%02x 0x76e=0x%02x\n", + rtw_read32(rtwdev, REG_BB_SEL_BTG), + rtw_read32(rtwdev, REG_LED_CFG), + rtw_read8(rtwdev, REG_BT_ANT_SEL), + rtw_read8(rtwdev, REG_GNT_BT), + rtw_read8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL)); + return; + } + + rtw8723b_coex_set_ant_ctrl_by_wifi(rtwdev); + rtw_write8(rtwdev, REG_BT_ANT_SEL, 0x20); + + if (ctrl_type == COEX_SWITCH_CTRL_BY_BBSW && + pos_type == COEX_SWITCH_TO_BT) { + rtw_write8(rtwdev, REG_GNT_BT, 0x18); + rtw_write8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL, 0x4); + } else { + if (rtw_read8(rtwdev, REG_GNT_BT) != 0) + rtw_write8(rtwdev, REG_GNT_BT, 0x0); + + if (rtw_read8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL) != 0xc) + rtw_write8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL, 0xc); + } + + if (ctrl_type == COEX_SWITCH_CTRL_BY_BBSW) + ant_path = rtw8723b_coex_ant_path_value(rtwdev, pos_type); + else + ant_path = rtw8723b_coex_ant_path_value(rtwdev, + COEX_SWITCH_TO_NOCARE); + + rtw_write32(rtwdev, REG_BB_SEL_BTG, ant_path); + + rtw_dbg(rtwdev, RTW_DBG_COEX, + "[BTCoex], 8723bs ant switch ctrl=%u pos=%u BB_SEL_BTG=0x%08x 0x4c=0x%08x 0x67=0x%02x 0x765=0x%02x 0x76e=0x%02x\n", + ctrl_type, pos_type, rtw_read32(rtwdev, REG_BB_SEL_BTG), + rtw_read32(rtwdev, REG_LED_CFG), + rtw_read8(rtwdev, REG_BT_ANT_SEL), + rtw_read8(rtwdev, REG_GNT_BT), + rtw_read8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL)); +} + +static void rtw8723b_coex_set_rfe_type(struct rtw_dev *rtwdev) +{ + enum rtw_hci_type hci_type = rtw_hci_type(rtwdev); + struct rtw_coex_rfe *coex_rfe = &rtwdev->coex.rfe; + bool aux = rtw8723b_coex_ant_is_aux(rtwdev); + u32 reg; + + coex_rfe->rfe_module_type = rtwdev->efuse.rfe_option; + coex_rfe->ant_switch_polarity = aux ? 1 : 0; + coex_rfe->ant_switch_exist = hci_type == RTW_HCI_TYPE_SDIO; + coex_rfe->ant_switch_with_bt = false; + coex_rfe->ant_switch_diversity = false; + coex_rfe->wlg_at_btg = true; + + rtw_write8(rtwdev, REG_BT_ANT_SEL, 0x20); + + /* set GRAN_BT = 1 */ + rtw_write8(rtwdev, REG_GNT_BT, 0x18); + + /* set WLAN_ACT = 0 */ + rtw_write8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL, 0x4); + + switch (hci_type) { + case RTW_HCI_TYPE_USB: + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x0); + rtw_write8(rtwdev, 0xfe08, 0x1); + break; + case RTW_HCI_TYPE_PCIE: + reg = 0x384; + /* 0xc3[6]: 0 = S1 (main, path A), 1 = S0 (aux, path B). */ + if (aux) { + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x0); + rtw_write8(rtwdev, reg, 0x1); + } else { + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x280); + rtw_write8(rtwdev, reg, 0x0); + } + break; + case RTW_HCI_TYPE_SDIO: + /* + * Internal switch: WiFi drives S0/S1, firmware gets the + * inverse hint. + */ + rtw_write_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK, 0x0780); + + if (aux) { + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x0); + rtw_write8(rtwdev, REG_SDIO_H2C, 0x1); + } else { + rtw_write32(rtwdev, REG_BB_SEL_BTG, 0x280); + rtw_write8(rtwdev, REG_SDIO_H2C, 0x0); + } + + rtw8723b_coex_set_ant_ctrl_by_wifi(rtwdev); + rtw_write8_mask(rtwdev, REG_PAD_CTRL1, + BIT_SW_DPDT_SEL_DATA, 0x0); + rtw8723b_coex_cfg_ant_buffer(rtwdev); + + /* COEX_ANT_SEL_RSV is sent later from rtw_power_on(). */ + break; + default: + break; + } +} + +static void rtw8723b_coex_set_wl_tx_power(struct rtw_dev *rtwdev, u8 wl_pwr) +{ + /* Deferred: 8723d adjusts WL Tx power (0xb2/0x90) with BT on. */ +} + +static void rtw8723b_coex_set_wl_rx_gain(struct rtw_dev *rtwdev, bool low_gain) +{ + /* Deferred: 8723d lowers the WL Rx AGC while BT is active. */ +} + +static void rtw8723b_cfg_ldo25(struct rtw_dev *rtwdev, bool enable) +{ + /* Nothing to do: rtw88 only reads the efuse, it never writes it. */ +} + +static void rtw8723b_fill_txdesc_checksum(struct rtw_dev *rtwdev, + struct rtw_tx_pkt_info *pkt_info, + u8 *txdesc) +{ + /* Unlike the shared 8723x helper, the checksum is not inverted here. */ + fill_txdesc_checksum_common(txdesc, 16); +} + +static int rtw8723b_read_efuse(struct rtw_dev *rtwdev, u8 *log_map) +{ + struct rtw_efuse *efuse = &rtwdev->efuse; + int ret; + + ret = rtw8723x_read_efuse(rtwdev, log_map); + if (ret) + return ret; + + /* + * Report a power track type this driver does not implement once, + * here, rather than on every two second pwr_track() tick. + */ + if (efuse->power_track_type != 0) + rtw_warn(rtwdev, "unsupported power track type\n"); + + /* + * No firmware hardware feature report exists, so fill the hardware + * capability here; a zero stream count kills the HT MCS set. + */ + efuse->hw_cap.nss = max_t(u8, rtwdev->hal.rf_path_num, 1); + efuse->hw_cap.ant_num = efuse->hw_cap.nss; + efuse->hw_cap.bw = BIT(RTW_CHANNEL_WIDTH_20) | + BIT(RTW_CHANNEL_WIDTH_40); + + return 0; +} + +static const struct rtw_chip_ops rtw8723b_ops = { + .power_on = rtw_power_on, + .power_off = rtw_power_off, + + .mac_init = rtw8723x_mac_init, + .mac_postinit = rtw8723x_mac_postinit, + + .dump_fw_crash = NULL, + /* + * 8723d sets REG_HCI_OPT_CTRL BIT_USB_SUS_DIS in its shutdown + * function; that is USB-only. + */ + .shutdown = NULL, + .read_efuse = rtw8723b_read_efuse, + .phy_set_param = rtw8723b_phy_set_param, + + .set_channel = rtw8723b_set_channel, + + .query_phy_status = rtw8723b_query_phy_status, + .read_rf = rtw_phy_read_rf_sipi, + .write_rf = rtw_phy_write_rf_reg_sipi, + .set_tx_power_index = rtw8723x_set_tx_power_index, + .rsvd_page_dump = NULL, + .set_antenna = NULL, + .cfg_ldo25 = rtw8723b_cfg_ldo25, + .efuse_grant = rtw8723b_efuse_grant, + .set_ampdu_factor = NULL, + .false_alarm_statistics = rtw8723x_false_alarm_statistics, + .phy_calibration = rtw8723b_phy_calibration, + .dpk_track = NULL, + .cck_pd_set = rtw_phy_cck_pd_set, + .pwr_track = rtw8723b_pwr_track, + .config_bfee = NULL, + .set_gid_table = NULL, + .cfg_csi_rate = NULL, + .adaptivity_init = NULL, + .adaptivity = NULL, + .cfo_init = NULL, + .cfo_track = NULL, + .config_tx_path = NULL, + .config_txrx_mode = NULL, + .led_set = NULL, + .fill_txdesc_checksum = rtw8723b_fill_txdesc_checksum, + + .coex_set_init = rtw8723b_coex_cfg_init, + .coex_set_ant_switch = rtw8723b_coex_cfg_ant_switch, + .coex_set_gnt_fix = rtw8723b_coex_set_gnt_fix, + .coex_set_gnt_debug = rtw8723b_coex_set_gnt_debug, + .coex_set_rfe_type = rtw8723b_coex_set_rfe_type, + .coex_set_wl_tx_power = rtw8723b_coex_set_wl_tx_power, + .coex_set_wl_rx_gain = rtw8723b_coex_set_wl_rx_gain, +}; + +const struct rtw_chip_info rtw8723b_hw_spec = { + .ops = &rtw8723b_ops, + .id = RTW_CHIP_TYPE_8723B, + .fw_name = "rtw88/rtw8723b_fw.bin", + .wlan_cpu = RTW_WCPU_8051, + .tx_pkt_desc_sz = 40, + .tx_buf_desc_sz = 16, + .rx_pkt_desc_sz = 24, + .rx_buf_desc_sz = 8, + .phy_efuse_size = 512, + .log_efuse_size = 512, + .ptct_efuse_size = 15, + .txff_size = 32768, + .rxff_size = 16384, + .rsvd_drv_pg_num = 8, + .txgi_factor = 1, + .is_pwr_by_rate_dec = true, + .max_power_index = 0x3f, + .csi_buf_pg_num = 0, + .band = RTW_BAND_2G, + .page_size = TX_PAGE_SIZE, + .dig_min = 0x20, + .usb_tx_agg_desc_num = 6, + /* + * The firmware reports id 0xfd instead of C2H_HW_FEATURE_REPORT, so + * the hardware feature report is not supported on this chip. + */ + .hw_feature_report = false, + .c2h_ra_report_size = 4, + .old_datarate_fb_limit = true, + .path_div_supported = false, + .ht_supported = true, + .vht_supported = false, + .lps_deep_mode_supported = 0, + .sys_func_en = 0xfd, + .pwr_on_seq = card_enable_flow_8723b, + .pwr_off_seq = card_disable_flow_8723b, + .page_table = page_table_8723b, + .rqpn_table = rqpn_table_8723b, + /* same shared table as the sibling rtw8703b and rtw8723d */ + .prioq_addrs = &rtw8723x_common.prioq_addrs, + /* used only in pci.c, not needed for SDIO devices */ + .intf_table = NULL, + .dig = rtw8723x_common.dig, + /* The vendor driver never writes the CCK IGI on this chip. */ + .dig_cck = NULL, + .rf_sipi_addr = {0x840, 0x844}, + .rf_sipi_read_addr = rtw8723x_common.rf_sipi_addr, + .fix_rf_phy_num = 2, + /* This chip has no LTE coex registers. */ + .ltecoex_addr = NULL, + .mac_tbl = &rtw8723b_mac_tbl, + .agc_tbl = &rtw8723b_agc_tbl, + .bb_tbl = &rtw8723b_bb_tbl, + .rf_tbl = {&rtw8723b_rf_a_tbl}, + .rfe_defs = rtw8723b_rfe_defs, + .rfe_defs_size = ARRAY_SIZE(rtw8723b_rfe_defs), + .iqk_threshold = 8, + .rx_ldpc = false, + .tx_stbc = false, + .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16, + .max_scan_ie_len = IEEE80211_MAX_DATA_LEN, + .coex_para_ver = 20180201, /* glcoex_ver_date_8723b_1ant */ + .bt_desired_ver = 0x6d, + .scbd_support = false, + .new_scbd10_def = true, + .ble_hid_profile_support = false, + .wl_mimo_ps_support = false, + .pstdma_type = COEX_PSTDMA_FORCE_LPSOFF, + .bt_rssi_type = COEX_BTRSSI_RATIO, + .ant_isolation = 15, + .rssi_tolerance = 2, + .wl_rssi_step = wl_rssi_step_8723b, + .bt_rssi_step = bt_rssi_step_8723b, + .table_sant_num = ARRAY_SIZE(table_sant_8723b), + .table_sant = table_sant_8723b, + .table_nsant_num = ARRAY_SIZE(table_nsant_8723b), + .table_nsant = table_nsant_8723b, + .tdma_sant_num = ARRAY_SIZE(tdma_sant_8723b), + .tdma_sant = tdma_sant_8723b, + .tdma_nsant_num = ARRAY_SIZE(tdma_nsant_8723b), + .tdma_nsant = tdma_nsant_8723b, + .wl_rf_para_num = ARRAY_SIZE(rf_para_tx_8723b), + .wl_rf_para_tx = rf_para_tx_8723b, + .wl_rf_para_rx = rf_para_rx_8723b, + .bt_afh_span_bw20 = 0x20, + .bt_afh_span_bw40 = 0x30, + .afh_5g_num = ARRAY_SIZE(afh_5g_8723b), + .afh_5g = afh_5g_8723b, + /* BTG_SEL is driven by the cardemu_to_act power sequence instead. */ + .btg_reg = NULL, + .coex_info_hw_regs_num = 0, + .coex_info_hw_regs = NULL, +}; +EXPORT_SYMBOL(rtw8723b_hw_spec); + +MODULE_FIRMWARE("rtw88/rtw8723b_fw.bin"); + +MODULE_AUTHOR("Luka Gejak "); +MODULE_AUTHOR("Michael Straube "); +MODULE_DESCRIPTION("Realtek 802.11n wireless 8723b driver"); +MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723b.h b/drivers/net/wireless/realtek/rtw88/rtw8723b.h new file mode 100644 index 000000000000..cf93b93ede81 --- /dev/null +++ b/drivers/net/wireless/realtek/rtw88/rtw8723b.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* Copyright(c) 2026 Realtek Corporation + * Copyright(c) Michael Straube + * Copyright(c) 2024-2026 Luka Gejak + */ + +#ifndef __RTW8723B_H__ +#define __RTW8723B_H__ + +#include "rtw8723x.h" + +extern const struct rtw_chip_info rtw8723b_hw_spec; + +#endif From 7629d6db839f196f108504662f1ad3b2fa822d0d Mon Sep 17 00:00:00 2001 From: Anton Danilov Date: Mon, 5 Oct 2026 23:14:14 +0300 Subject: [PATCH 1370/2126] vxlan: rename the drop reasons for use by other tunnels VXLAN_INVALID_HDR and VXLAN_VNI_NOT_FOUND describe conditions that are not specific to vxlan: a malformed tunnel header, and a packet for which no tunnel device is found. The GRE receive paths drop packets for the same two conditions, and can report them with the same reasons once they are converted to drop reasons. Rename them to TUNNEL_INVALID_HDR and TUNNEL_NOT_FOUND and reword their descriptions, the way VXLAN_NO_REMOTE became NO_TX_TARGET in commit 46e0ccfb88f0 ("net: vxlan: rename SKB_DROP_REASON_VXLAN_NO_REMOTE"). The numeric values stay the same; the names that the skb:kfree_skb tracepoint and drop_monitor report change. Suggested-by: Ido Schimmel Signed-off-by: Anton Danilov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005201417.906344-2-littlesmilingcloud@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 8 ++++---- include/net/dropreason-core.h | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 35bd92f5e460..11385dc88c86 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1700,7 +1700,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) if (!(vh->vx_flags & VXLAN_HF_VNI)) { netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n", ntohl(vh->vx_flags), ntohl(vh->vx_vni)); - reason = SKB_DROP_REASON_VXLAN_INVALID_HDR; + reason = SKB_DROP_REASON_TUNNEL_INVALID_HDR; /* Return non vxlan pkt */ goto drop; } @@ -1713,7 +1713,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex, vni, &vninode); if (!vxlan) { - reason = SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND; + reason = SKB_DROP_REASON_TUNNEL_NOT_FOUND; goto drop; } @@ -1729,7 +1729,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) * previous stack code, and also is more robust and provides a * little more security in adding extensions to VXLAN. */ - reason = SKB_DROP_REASON_VXLAN_INVALID_HDR; + reason = SKB_DROP_REASON_TUNNEL_INVALID_HDR; DEV_STATS_INC(vxlan->dev, rx_frame_errors); DEV_STATS_INC(vxlan->dev, rx_errors); vxlan_vnifilter_count(vxlan, cfg, vni, vninode, @@ -2383,7 +2383,7 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, DEV_STATS_INC(dev, tx_errors); vxlan_vnifilter_count(vxlan, cfg, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0); - kfree_skb_reason(skb, SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND); + kfree_skb_reason(skb, SKB_DROP_REASON_TUNNEL_NOT_FOUND); return -ENOENT; } diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 12f909651591..40a27d8887af 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -111,8 +111,8 @@ FN(PACKET_SOCK_ERROR) \ FN(TC_CHAIN_NOTFOUND) \ FN(TC_RECLASSIFY_LOOP) \ - FN(VXLAN_INVALID_HDR) \ - FN(VXLAN_VNI_NOT_FOUND) \ + FN(TUNNEL_INVALID_HDR) \ + FN(TUNNEL_NOT_FOUND) \ FN(MAC_INVALID_SOURCE) \ FN(VXLAN_ENTRY_EXISTS) \ FN(NO_TX_TARGET) \ @@ -539,13 +539,16 @@ enum skb_drop_reason { */ SKB_DROP_REASON_TC_RECLASSIFY_LOOP, /** - * @SKB_DROP_REASON_VXLAN_INVALID_HDR: VXLAN header is invalid. E.g.: - * 1) reserved fields are not zero - * 2) "I" flag is not set + * @SKB_DROP_REASON_TUNNEL_INVALID_HDR: tunnel header is invalid. E.g.: + * 1) VXLAN reserved fields are not zero + * 2) VXLAN "I" flag is not set */ - SKB_DROP_REASON_VXLAN_INVALID_HDR, - /** @SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND: no VXLAN device found for VNI */ - SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND, + SKB_DROP_REASON_TUNNEL_INVALID_HDR, + /** + * @SKB_DROP_REASON_TUNNEL_NOT_FOUND: no tunnel device found for the + * packet, e.g. no VXLAN device for its VNI + */ + SKB_DROP_REASON_TUNNEL_NOT_FOUND, /** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */ SKB_DROP_REASON_MAC_INVALID_SOURCE, /** From 6c0509aa8900134db0ca7de56fc6aa10eac3d026 Mon Sep 17 00:00:00 2001 From: Anton Danilov Date: Mon, 5 Oct 2026 23:14:15 +0300 Subject: [PATCH 1371/2126] ip_tunnel: make __iptunnel_pull_header() return a drop reason __iptunnel_pull_header() returns -ENOMEM whenever it fails. It can fail in two pskb_may_pull() calls, one for the tunnel header and one for the inner Ethernet header of ETH_P_TEB, and in the skb_unclone() done for GSO packets. pskb_may_pull() fails when the packet is shorter than the requested length as well as when pulling from the frags cannot allocate, so a truncated packet and an allocation failure look the same to the callers. The ones that report a drop reason can only pick SKB_DROP_REASON_NOMEM, as vxlan_rcv() does, and so would the GRE receive paths once they report drop reasons. In ip6_gre, gre_rcv() pulls the header before the tunnel lookup, so a packet from any sender whose ETH_P_TEB inner Ethernet header or WCCPv2 extra word is cut short would be reported as an out of memory condition. Make __iptunnel_pull_header() and iptunnel_pull_header() return the reason pskb_may_pull_reason() already computes, SKB_DROP_REASON_NOMEM when skb_unclone() fails, and SKB_NOT_DROPPED_YET on success. A failure is still non-zero, so the callers that only test the result keep working. Three callers, in ip_gre and ip6_gre, test it with "< 0" instead; the enum has no negative values, so that test would always be false, and the compiler does not warn about it. Make them test for a non-zero value. vxlan_rcv() keeps reporting NOMEM for any failure until the next patch has it report the returned reason. Suggested-by: Ido Schimmel Signed-off-by: Anton Danilov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005201417.906344-3-littlesmilingcloud@gmail.com Signed-off-by: Jakub Kicinski --- include/net/ip_tunnels.h | 10 ++++++---- net/ipv4/ip_gre.c | 4 ++-- net/ipv4/ip_tunnel_core.c | 22 +++++++++++++++------- net/ipv6/ip6_gre.c | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 7102aa11fae2..5cccf4c0e691 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -614,11 +614,13 @@ static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph, return INET_ECN_encapsulate(tos, inner); } -int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len, - __be16 inner_proto, bool raw_proto, bool xnet); +enum skb_drop_reason +__iptunnel_pull_header(struct sk_buff *skb, int hdr_len, + __be16 inner_proto, bool raw_proto, bool xnet); -static inline int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, - __be16 inner_proto, bool xnet) +static inline enum skb_drop_reason +iptunnel_pull_header(struct sk_buff *skb, int hdr_len, + __be16 inner_proto, bool xnet) { return __iptunnel_pull_header(skb, hdr_len, inner_proto, false, xnet); } diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 51fcd603939c..3ee437fa3eae 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -312,7 +312,7 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, if (__iptunnel_pull_header(skb, len, htons(ETH_P_TEB), - false, false) < 0) + false, false)) goto drop; if (tunnel->collect_md) { @@ -378,7 +378,7 @@ static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi, const struct iphdr *tnl_params; if (__iptunnel_pull_header(skb, hdr_len, tpi->proto, - raw_proto, false) < 0) + raw_proto, false)) goto drop; /* Special case for ipgre_header_parse(), which expects the diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c index bab42b9e277f..6c2855adff28 100644 --- a/net/ipv4/ip_tunnel_core.c +++ b/net/ipv4/ip_tunnel_core.c @@ -106,19 +106,24 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, } EXPORT_SYMBOL_GPL(iptunnel_xmit); -int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len, - __be16 inner_proto, bool raw_proto, bool xnet) +enum skb_drop_reason +__iptunnel_pull_header(struct sk_buff *skb, int hdr_len, + __be16 inner_proto, bool raw_proto, bool xnet) { - if (unlikely(!pskb_may_pull(skb, hdr_len))) - return -ENOMEM; + enum skb_drop_reason reason; + + reason = pskb_may_pull_reason(skb, hdr_len); + if (unlikely(reason)) + return reason; skb_pull_rcsum(skb, hdr_len); if (!raw_proto && inner_proto == htons(ETH_P_TEB)) { struct ethhdr *eh; - if (unlikely(!pskb_may_pull(skb, ETH_HLEN))) - return -ENOMEM; + reason = pskb_may_pull_reason(skb, ETH_HLEN); + if (unlikely(reason)) + return reason; eh = (struct ethhdr *)skb->data; if (likely(eth_proto_is_802_3(eh->h_proto))) @@ -135,7 +140,10 @@ int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len, skb_set_queue_mapping(skb, 0); skb_scrub_packet(skb, xnet); - return iptunnel_pull_offloads(skb); + if (unlikely(iptunnel_pull_offloads(skb))) + return SKB_DROP_REASON_NOMEM; + + return SKB_NOT_DROPPED_YET; } EXPORT_SYMBOL_GPL(__iptunnel_pull_header); diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 258239a7c53b..0392f6ba862b 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -512,7 +512,7 @@ static int ip6erspan_rcv(struct sk_buff *skb, if (__iptunnel_pull_header(skb, len, htons(ETH_P_TEB), - false, false) < 0) + false, false)) return PACKET_REJECT; if (tunnel->parms.collect_md) { From 0518c33e1d7e5600e441027100079aaf9c0dda74 Mon Sep 17 00:00:00 2001 From: Anton Danilov Date: Mon, 5 Oct 2026 23:14:16 +0300 Subject: [PATCH 1372/2126] vxlan: report the drop reason of __iptunnel_pull_header() vxlan_rcv() reports SKB_DROP_REASON_NOMEM whenever __iptunnel_pull_header() fails, as the helper used to return -ENOMEM for any failure. The VXLAN header is already in the linear area at this point, but the inner Ethernet header of a packet without GPE may not be, so a packet whose inner frame is shorter than an Ethernet header is reported as an out of memory condition. Report the reason __iptunnel_pull_header() now returns instead: PKT_TOO_SMALL for such a packet, NOMEM when an allocation fails. Suggested-by: Ido Schimmel Signed-off-by: Anton Danilov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005201417.906344-4-littlesmilingcloud@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 11385dc88c86..3e7a3e64a83b 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1743,11 +1743,11 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) raw_proto = true; } - if (__iptunnel_pull_header(skb, VXLAN_HLEN, protocol, raw_proto, - !net_eq(vxlan->net, dev_net(vxlan->dev)))) { - reason = SKB_DROP_REASON_NOMEM; + reason = __iptunnel_pull_header(skb, VXLAN_HLEN, protocol, raw_proto, + !net_eq(vxlan->net, + dev_net(vxlan->dev))); + if (reason) goto drop; - } if (cfg->flags & VXLAN_F_REMCSUM_RX) { reason = vxlan_remcsum(skb, cfg->flags); From d476bb7c0efd56aa3d579114802305e4500bec85 Mon Sep 17 00:00:00 2001 From: Anton Danilov Date: Mon, 5 Oct 2026 23:14:17 +0300 Subject: [PATCH 1373/2126] vxlan: report a circular route as SKB_DROP_REASON_RECURSION_LIMIT udp_tunnel_dst_lookup() and udp_tunnel6_dst_lookup() return -ELOOP when the route to the remote end goes out of the vxlan device itself, and vxlan_xmit_one() counts that in collisions, apart from the -ENETUNREACH of a failed lookup. The drop reason does not tell them apart: both are reported as SKB_DROP_REASON_IP_OUTNOROUTES, which describes a failed route lookup. Such a route would send the encapsulated packet back into the device it leaves, which is the dead loop on a virtual device that SKB_DROP_REASON_RECURSION_LIMIT describes. Report the -ELOOP case with that reason, and add the tunnel case to the description of the reason as an example. ip_tunnel and ip6_tunnel make the same check, rt->dst.dev == dev in ip_tunnel_xmit() and ip_md_tunnel_xmit() and tdev == dev in ip6_tnl_xmit(), and can report it with the same reason. Signed-off-by: Anton Danilov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005201417.906344-5-littlesmilingcloud@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_core.c | 10 ++++++++-- include/net/dropreason-core.h | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 3e7a3e64a83b..278d41f58d89 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2541,7 +2541,10 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos, use_cache ? dst_cache : NULL); if (IS_ERR(rt)) { err = PTR_ERR(rt); - reason = SKB_DROP_REASON_IP_OUTNOROUTES; + if (err == -ELOOP) + reason = SKB_DROP_REASON_RECURSION_LIMIT; + else + reason = SKB_DROP_REASON_IP_OUTNOROUTES; goto tx_error; } @@ -2627,7 +2630,10 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, if (IS_ERR(ndst)) { err = PTR_ERR(ndst); ndst = NULL; - reason = SKB_DROP_REASON_IP_OUTNOROUTES; + if (err == -ELOOP) + reason = SKB_DROP_REASON_RECURSION_LIMIT; + else + reason = SKB_DROP_REASON_IP_OUTNOROUTES; goto tx_error; } diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 40a27d8887af..664249924219 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -613,7 +613,11 @@ enum skb_drop_reason { SKB_DROP_REASON_PSP_INPUT, /** @SKB_DROP_REASON_PSP_OUTPUT: PSP output checks failed */ SKB_DROP_REASON_PSP_OUTPUT, - /** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */ + /** + * @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device, e.g. a + * tunnel whose route to its remote end goes out of the tunnel device + * itself. + */ SKB_DROP_REASON_RECURSION_LIMIT, /** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which From 269946cba92eeb19d3ff497b5d2ecd927d77b1d4 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:07:00 +0200 Subject: [PATCH 1374/2126] wifi: rtw88: 8723bs: add the RTL8723BS SDIO bind Add the SDIO module for the RTL8723BS, the SDIO variant of the RTL8723B. It binds the Realtek SDIO device ids to the shared rtw88 SDIO probe and points it at the RTL8723B chip information. The device id table carries the same six ids the staging rtl8723bs driver binds to this chip, so the staging driver can be dropped without losing hardware support. I only have the 0xb723 variant to test with. The other five are included for parity with staging, which has carried them for years, rather than being left behind. The RTL8723B chip support is based on the initial work by Michael Straube . Link: https://github.com/mistraube/rtw88/tree/rtl8723bs Co-developed-by: Michael Straube Signed-off-by: Michael Straube Signed-off-by: Luka Gejak Reviewed-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-7-luka.gejak@linux.dev --- .../net/wireless/realtek/rtw88/rtw8723bs.c | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8723bs.c diff --git a/drivers/net/wireless/realtek/rtw88/rtw8723bs.c b/drivers/net/wireless/realtek/rtw88/rtw8723bs.c new file mode 100644 index 000000000000..62ad44db20de --- /dev/null +++ b/drivers/net/wireless/realtek/rtw88/rtw8723bs.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* Copyright(c) 2026 Realtek Corporation + * Copyright(c) Michael Straube + * Copyright(c) 2024-2026 Luka Gejak + */ + +#include +#include +#include +#include "main.h" +#include "rtw8723b.h" +#include "sdio.h" + +static const struct sdio_device_id rtw_8723bs_id_table[] = { + { + SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK, + SDIO_DEVICE_ID_REALTEK_RTW8723BS), + .driver_data = (kernel_ulong_t)&rtw8723b_hw_spec, + }, + { + SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK, 0x0523), + .driver_data = (kernel_ulong_t)&rtw8723b_hw_spec, + }, + { + SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK, 0x0525), + .driver_data = (kernel_ulong_t)&rtw8723b_hw_spec, + }, + { + SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK, 0x0623), + .driver_data = (kernel_ulong_t)&rtw8723b_hw_spec, + }, + { + SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK, 0x0626), + .driver_data = (kernel_ulong_t)&rtw8723b_hw_spec, + }, + { + SDIO_DEVICE(SDIO_VENDOR_ID_REALTEK, 0x0627), + .driver_data = (kernel_ulong_t)&rtw8723b_hw_spec, + }, + {} +}; +MODULE_DEVICE_TABLE(sdio, rtw_8723bs_id_table); + +static struct sdio_driver rtw_8723bs_driver = { + .name = KBUILD_MODNAME, + .id_table = rtw_8723bs_id_table, + .probe = rtw_sdio_probe, + .remove = rtw_sdio_remove, + .shutdown = rtw_sdio_shutdown, + .drv = { + .pm = &rtw_sdio_pm_ops, + } +}; +module_sdio_driver(rtw_8723bs_driver); + +MODULE_AUTHOR("Luka Gejak "); +MODULE_AUTHOR("Michael Straube "); +MODULE_DESCRIPTION("Realtek 802.11n wireless 8723bs driver"); +MODULE_LICENSE("Dual BSD/GPL"); From b2d251aa7f16e8ec0322a447b8b24c7f69a29832 Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Tue, 6 Oct 2026 15:07:01 +0200 Subject: [PATCH 1375/2126] wifi: rtw88: 8723bs: enable building the RTL8723BS driver Now that the chip support, firmware interface, coexistence, power management and the SDIO transfer and association paths are all in place, add the Kconfig symbols and Makefile rules that build the RTL8723B chip module and the RTL8723BS SDIO front end. Signed-off-by: Luka Gejak Reviewed-by: Bitterblue Smith Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261006130701.120460-8-luka.gejak@linux.dev --- drivers/net/wireless/realtek/rtw88/Kconfig | 18 ++++++++++++++++++ drivers/net/wireless/realtek/rtw88/Makefile | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/Kconfig b/drivers/net/wireless/realtek/rtw88/Kconfig index 3736f290bd42..e1f40d6785e6 100644 --- a/drivers/net/wireless/realtek/rtw88/Kconfig +++ b/drivers/net/wireless/realtek/rtw88/Kconfig @@ -36,6 +36,10 @@ config RTW88_8703B tristate select RTW88_8723X +config RTW88_8723B + tristate + select RTW88_8723X + config RTW88_8723D tristate select RTW88_8723X @@ -159,6 +163,20 @@ config RTW88_8723CS If you choose to build a module, it'll be called rtw88_8723cs. +config RTW88_8723BS + tristate "Realtek 8723BS SDIO wireless network adapter" + depends on MMC + select RTW88_CORE + select RTW88_SDIO + select RTW88_8723B + help + Select this option to enable support for 8723BS chipset + + This module adds support for the 8723BS 802.11n SDIO + wireless network adapter. + + If you choose to build a module, it'll be called rtw88_8723bs. + config RTW88_8723DU tristate "Realtek 8723DU USB wireless network adapter" depends on USB diff --git a/drivers/net/wireless/realtek/rtw88/Makefile b/drivers/net/wireless/realtek/rtw88/Makefile index 0b3da05a2938..6889b3796449 100644 --- a/drivers/net/wireless/realtek/rtw88/Makefile +++ b/drivers/net/wireless/realtek/rtw88/Makefile @@ -55,6 +55,12 @@ rtw88_8703b-objs := rtw8703b.o rtw8703b_tables.o obj-$(CONFIG_RTW88_8723CS) += rtw88_8723cs.o rtw88_8723cs-objs := rtw8723cs.o +obj-$(CONFIG_RTW88_8723B) += rtw88_8723b.o +rtw88_8723b-objs := rtw8723b.o rtw8723b_table.o + +obj-$(CONFIG_RTW88_8723BS) += rtw88_8723bs.o +rtw88_8723bs-objs := rtw8723bs.o + obj-$(CONFIG_RTW88_8723D) += rtw88_8723d.o rtw88_8723d-objs := rtw8723d.o rtw8723d_table.o From c520f3af7df423a49c3f2a334eae018d1c0b67ee Mon Sep 17 00:00:00 2001 From: Luka Gejak Date: Wed, 7 Oct 2026 10:28:17 +0000 Subject: [PATCH 1376/2126] staging: rtl8723bs: remove the obsolete driver RTW88 now supports RTL8723B family, via rtw8723b driver which handles RTL8723BS, so the staging driver is obsolete. Remove it together with its Kconfig and Makefile wiring. Signed-off-by: Luka Gejak Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261007102819.19904-1-luka.gejak@linux.dev --- drivers/staging/Kconfig | 2 - drivers/staging/Makefile | 1 - drivers/staging/rtl8723bs/Kconfig | 13 - drivers/staging/rtl8723bs/Makefile | 60 - drivers/staging/rtl8723bs/TODO | 7 - drivers/staging/rtl8723bs/core/rtw_ap.c | 1943 ------ drivers/staging/rtl8723bs/core/rtw_btcoex.c | 75 - drivers/staging/rtl8723bs/core/rtw_cmd.c | 1936 ------ drivers/staging/rtl8723bs/core/rtw_efuse.c | 253 - .../staging/rtl8723bs/core/rtw_ieee80211.c | 1199 ---- drivers/staging/rtl8723bs/core/rtw_io.c | 145 - .../staging/rtl8723bs/core/rtw_ioctl_set.c | 494 -- drivers/staging/rtl8723bs/core/rtw_mlme.c | 2565 ------- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 5901 ----------------- drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 1139 ---- drivers/staging/rtl8723bs/core/rtw_recv.c | 2249 ------- drivers/staging/rtl8723bs/core/rtw_security.c | 1470 ---- drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 549 -- .../staging/rtl8723bs/core/rtw_wlan_util.c | 1759 ----- drivers/staging/rtl8723bs/core/rtw_xmit.c | 2569 ------- drivers/staging/rtl8723bs/hal/Hal8723BReg.h | 65 - .../staging/rtl8723bs/hal/HalBtc8723b1Ant.c | 2595 -------- .../staging/rtl8723bs/hal/HalBtc8723b1Ant.h | 184 - .../staging/rtl8723bs/hal/HalBtc8723b2Ant.c | 2624 -------- .../staging/rtl8723bs/hal/HalBtc8723b2Ant.h | 146 - drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h | 426 -- .../staging/rtl8723bs/hal/HalHWImg8723B_BB.c | 556 -- .../staging/rtl8723bs/hal/HalHWImg8723B_BB.h | 39 - .../staging/rtl8723bs/hal/HalHWImg8723B_MAC.c | 237 - .../staging/rtl8723bs/hal/HalHWImg8723B_MAC.h | 19 - .../staging/rtl8723bs/hal/HalHWImg8723B_RF.c | 554 -- .../staging/rtl8723bs/hal/HalHWImg8723B_RF.h | 40 - drivers/staging/rtl8723bs/hal/HalPhyRf.c | 268 - drivers/staging/rtl8723bs/hal/HalPhyRf.h | 39 - .../staging/rtl8723bs/hal/HalPhyRf_8723B.c | 1767 ----- .../staging/rtl8723bs/hal/HalPhyRf_8723B.h | 66 - drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c | 144 - drivers/staging/rtl8723bs/hal/Mp_Precomp.h | 23 - drivers/staging/rtl8723bs/hal/hal_btcoex.c | 1303 ---- drivers/staging/rtl8723bs/hal/hal_com.c | 767 --- .../staging/rtl8723bs/hal/hal_com_phycfg.c | 973 --- drivers/staging/rtl8723bs/hal/hal_intf.c | 283 - drivers/staging/rtl8723bs/hal/hal_pwr_seq.c | 128 - drivers/staging/rtl8723bs/hal/hal_sdio.c | 100 - drivers/staging/rtl8723bs/hal/odm.c | 988 --- drivers/staging/rtl8723bs/hal/odm.h | 1109 ---- .../staging/rtl8723bs/hal/odm_CfoTracking.c | 210 - .../staging/rtl8723bs/hal/odm_CfoTracking.h | 39 - drivers/staging/rtl8723bs/hal/odm_DIG.c | 799 --- drivers/staging/rtl8723bs/hal/odm_DIG.h | 164 - .../rtl8723bs/hal/odm_DynamicBBPowerSaving.c | 81 - .../rtl8723bs/hal/odm_DynamicBBPowerSaving.h | 31 - .../rtl8723bs/hal/odm_DynamicTxPower.c | 22 - .../rtl8723bs/hal/odm_DynamicTxPower.h | 29 - .../rtl8723bs/hal/odm_EdcaTurboCheck.c | 158 - .../rtl8723bs/hal/odm_EdcaTurboCheck.h | 23 - drivers/staging/rtl8723bs/hal/odm_HWConfig.c | 439 -- drivers/staging/rtl8723bs/hal/odm_HWConfig.h | 85 - .../rtl8723bs/hal/odm_RegConfig8723B.c | 176 - .../rtl8723bs/hal/odm_RegConfig8723B.h | 45 - .../staging/rtl8723bs/hal/odm_RegDefine11N.h | 160 - drivers/staging/rtl8723bs/hal/odm_interface.h | 29 - drivers/staging/rtl8723bs/hal/odm_precomp.h | 47 - drivers/staging/rtl8723bs/hal/odm_reg.h | 91 - drivers/staging/rtl8723bs/hal/odm_types.h | 40 - drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c | 933 --- drivers/staging/rtl8723bs/hal/rtl8723b_dm.c | 256 - .../staging/rtl8723bs/hal/rtl8723b_hal_init.c | 2826 -------- .../staging/rtl8723bs/hal/rtl8723b_phycfg.c | 759 --- .../staging/rtl8723bs/hal/rtl8723b_rf6052.c | 135 - .../staging/rtl8723bs/hal/rtl8723b_rxdesc.c | 69 - .../staging/rtl8723bs/hal/rtl8723bs_recv.c | 477 -- .../staging/rtl8723bs/hal/rtl8723bs_xmit.c | 568 -- drivers/staging/rtl8723bs/hal/sdio_halinit.c | 1192 ---- drivers/staging/rtl8723bs/hal/sdio_ops.c | 859 --- .../rtl8723bs/include/Hal8192CPhyReg.h | 232 - .../staging/rtl8723bs/include/HalPwrSeqCmd.h | 111 - .../staging/rtl8723bs/include/basic_types.h | 175 - drivers/staging/rtl8723bs/include/cmd_osdep.h | 16 - drivers/staging/rtl8723bs/include/drv_types.h | 431 -- .../rtl8723bs/include/drv_types_sdio.h | 25 - .../staging/rtl8723bs/include/hal_btcoex.h | 54 - drivers/staging/rtl8723bs/include/hal_com.h | 152 - .../staging/rtl8723bs/include/hal_com_h2c.h | 28 - .../rtl8723bs/include/hal_com_phycfg.h | 108 - .../staging/rtl8723bs/include/hal_com_reg.h | 594 -- drivers/staging/rtl8723bs/include/hal_data.h | 276 - drivers/staging/rtl8723bs/include/hal_intf.h | 250 - drivers/staging/rtl8723bs/include/hal_pg.h | 63 - drivers/staging/rtl8723bs/include/hal_phy.h | 73 - .../staging/rtl8723bs/include/hal_phy_cfg.h | 63 - .../staging/rtl8723bs/include/hal_phy_reg.h | 17 - .../staging/rtl8723bs/include/hal_pwr_seq.h | 226 - drivers/staging/rtl8723bs/include/hal_sdio.h | 18 - drivers/staging/rtl8723bs/include/ieee80211.h | 748 --- .../rtl8723bs/include/ioctl_cfg80211.h | 58 - .../staging/rtl8723bs/include/osdep_intf.h | 42 - .../staging/rtl8723bs/include/osdep_service.h | 53 - .../rtl8723bs/include/osdep_service_linux.h | 118 - .../staging/rtl8723bs/include/rtl8192c_recv.h | 33 - .../staging/rtl8723bs/include/rtl8723b_cmd.h | 182 - .../staging/rtl8723bs/include/rtl8723b_dm.h | 32 - .../staging/rtl8723bs/include/rtl8723b_hal.h | 246 - .../staging/rtl8723bs/include/rtl8723b_recv.h | 95 - .../staging/rtl8723bs/include/rtl8723b_rf.h | 17 - .../staging/rtl8723bs/include/rtl8723b_spec.h | 237 - .../staging/rtl8723bs/include/rtl8723b_xmit.h | 421 -- drivers/staging/rtl8723bs/include/rtw_ap.h | 39 - .../staging/rtl8723bs/include/rtw_btcoex.h | 27 - .../staging/rtl8723bs/include/rtw_byteorder.h | 16 - drivers/staging/rtl8723bs/include/rtw_cmd.h | 705 -- .../staging/rtl8723bs/include/rtw_eeprom.h | 118 - drivers/staging/rtl8723bs/include/rtw_efuse.h | 78 - drivers/staging/rtl8723bs/include/rtw_event.h | 92 - drivers/staging/rtl8723bs/include/rtw_ht.h | 83 - drivers/staging/rtl8723bs/include/rtw_io.h | 58 - .../staging/rtl8723bs/include/rtw_ioctl_set.h | 27 - drivers/staging/rtl8723bs/include/rtw_mlme.h | 397 -- .../staging/rtl8723bs/include/rtw_mlme_ext.h | 708 -- .../staging/rtl8723bs/include/rtw_pwrctrl.h | 254 - drivers/staging/rtl8723bs/include/rtw_qos.h | 15 - drivers/staging/rtl8723bs/include/rtw_recv.h | 457 -- drivers/staging/rtl8723bs/include/rtw_rf.h | 100 - .../staging/rtl8723bs/include/rtw_security.h | 272 - .../staging/rtl8723bs/include/rtw_version.h | 3 - .../staging/rtl8723bs/include/rtw_wifi_regd.h | 16 - drivers/staging/rtl8723bs/include/rtw_xmit.h | 470 -- drivers/staging/rtl8723bs/include/sdio_hal.h | 14 - drivers/staging/rtl8723bs/include/sdio_ops.h | 33 - .../rtl8723bs/include/sdio_ops_linux.h | 29 - drivers/staging/rtl8723bs/include/sta_info.h | 330 - drivers/staging/rtl8723bs/include/wifi.h | 409 -- .../staging/rtl8723bs/include/wlan_bssdef.h | 195 - .../staging/rtl8723bs/include/xmit_osdep.h | 43 - .../staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 2795 -------- drivers/staging/rtl8723bs/os_dep/os_intfs.c | 1189 ---- .../staging/rtl8723bs/os_dep/osdep_service.c | 201 - drivers/staging/rtl8723bs/os_dep/sdio_intf.c | 465 -- .../staging/rtl8723bs/os_dep/sdio_ops_linux.c | 495 -- drivers/staging/rtl8723bs/os_dep/wifi_regd.c | 129 - drivers/staging/rtl8723bs/os_dep/xmit_linux.c | 216 - 141 files changed, 66186 deletions(-) delete mode 100644 drivers/staging/rtl8723bs/Kconfig delete mode 100644 drivers/staging/rtl8723bs/Makefile delete mode 100644 drivers/staging/rtl8723bs/TODO delete mode 100644 drivers/staging/rtl8723bs/core/rtw_ap.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_btcoex.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_cmd.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_efuse.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_ieee80211.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_io.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_ioctl_set.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_mlme.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_pwrctrl.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_recv.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_security.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_sta_mgt.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_wlan_util.c delete mode 100644 drivers/staging/rtl8723bs/core/rtw_xmit.c delete mode 100644 drivers/staging/rtl8723bs/hal/Hal8723BReg.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalPhyRf.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalPhyRf.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c delete mode 100644 drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.h delete mode 100644 drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c delete mode 100644 drivers/staging/rtl8723bs/hal/Mp_Precomp.h delete mode 100644 drivers/staging/rtl8723bs/hal/hal_btcoex.c delete mode 100644 drivers/staging/rtl8723bs/hal/hal_com.c delete mode 100644 drivers/staging/rtl8723bs/hal/hal_com_phycfg.c delete mode 100644 drivers/staging/rtl8723bs/hal/hal_intf.c delete mode 100644 drivers/staging/rtl8723bs/hal/hal_pwr_seq.c delete mode 100644 drivers/staging/rtl8723bs/hal/hal_sdio.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_CfoTracking.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_CfoTracking.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_DIG.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_DIG.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_HWConfig.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_HWConfig.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.c delete mode 100644 drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_interface.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_precomp.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_reg.h delete mode 100644 drivers/staging/rtl8723bs/hal/odm_types.h delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723b_dm.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c delete mode 100644 drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c delete mode 100644 drivers/staging/rtl8723bs/hal/sdio_halinit.c delete mode 100644 drivers/staging/rtl8723bs/hal/sdio_ops.c delete mode 100644 drivers/staging/rtl8723bs/include/Hal8192CPhyReg.h delete mode 100644 drivers/staging/rtl8723bs/include/HalPwrSeqCmd.h delete mode 100644 drivers/staging/rtl8723bs/include/basic_types.h delete mode 100644 drivers/staging/rtl8723bs/include/cmd_osdep.h delete mode 100644 drivers/staging/rtl8723bs/include/drv_types.h delete mode 100644 drivers/staging/rtl8723bs/include/drv_types_sdio.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_btcoex.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_com.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_com_h2c.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_com_phycfg.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_com_reg.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_data.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_intf.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_pg.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_phy.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_phy_cfg.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_phy_reg.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_pwr_seq.h delete mode 100644 drivers/staging/rtl8723bs/include/hal_sdio.h delete mode 100644 drivers/staging/rtl8723bs/include/ieee80211.h delete mode 100644 drivers/staging/rtl8723bs/include/ioctl_cfg80211.h delete mode 100644 drivers/staging/rtl8723bs/include/osdep_intf.h delete mode 100644 drivers/staging/rtl8723bs/include/osdep_service.h delete mode 100644 drivers/staging/rtl8723bs/include/osdep_service_linux.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8192c_recv.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_cmd.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_dm.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_hal.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_recv.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_rf.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_spec.h delete mode 100644 drivers/staging/rtl8723bs/include/rtl8723b_xmit.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_ap.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_btcoex.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_byteorder.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_cmd.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_eeprom.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_efuse.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_event.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_ht.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_io.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_ioctl_set.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_mlme.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_mlme_ext.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_pwrctrl.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_qos.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_recv.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_rf.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_security.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_version.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_wifi_regd.h delete mode 100644 drivers/staging/rtl8723bs/include/rtw_xmit.h delete mode 100644 drivers/staging/rtl8723bs/include/sdio_hal.h delete mode 100644 drivers/staging/rtl8723bs/include/sdio_ops.h delete mode 100644 drivers/staging/rtl8723bs/include/sdio_ops_linux.h delete mode 100644 drivers/staging/rtl8723bs/include/sta_info.h delete mode 100644 drivers/staging/rtl8723bs/include/wifi.h delete mode 100644 drivers/staging/rtl8723bs/include/wlan_bssdef.h delete mode 100644 drivers/staging/rtl8723bs/include/xmit_osdep.h delete mode 100644 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c delete mode 100644 drivers/staging/rtl8723bs/os_dep/os_intfs.c delete mode 100644 drivers/staging/rtl8723bs/os_dep/osdep_service.c delete mode 100644 drivers/staging/rtl8723bs/os_dep/sdio_intf.c delete mode 100644 drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c delete mode 100644 drivers/staging/rtl8723bs/os_dep/wifi_regd.c delete mode 100644 drivers/staging/rtl8723bs/os_dep/xmit_linux.c diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 2f92cd698bef..46b460bfb436 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -24,8 +24,6 @@ menuconfig STAGING if STAGING -source "drivers/staging/rtl8723bs/Kconfig" - source "drivers/staging/octeon/Kconfig" source "drivers/staging/iio/Kconfig" diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index f5b8876aa536..7e2e7a7e773a 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -2,7 +2,6 @@ # Makefile for staging directory obj-y += media/ -obj-$(CONFIG_RTL8723BS) += rtl8723bs/ obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ obj-$(CONFIG_VME_BUS) += vme_user/ obj-$(CONFIG_IIO) += iio/ diff --git a/drivers/staging/rtl8723bs/Kconfig b/drivers/staging/rtl8723bs/Kconfig deleted file mode 100644 index 414982893b6b..000000000000 --- a/drivers/staging/rtl8723bs/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -config RTL8723BS - tristate "Realtek RTL8723BS SDIO Wireless LAN NIC driver" - depends on WLAN && MMC && CFG80211 - depends on m - select CRYPTO_LIB_AES - select CRYPTO_LIB_ARC4 - select CRYPTO_LIB_UTILS - help - This option enables support for RTL8723BS SDIO drivers, such as - the wifi found on the 1st gen Intel Compute Stick, the CHIP - and many other Intel Atom and ARM based devices. - If built as a module, it will be called r8723bs. diff --git a/drivers/staging/rtl8723bs/Makefile b/drivers/staging/rtl8723bs/Makefile deleted file mode 100644 index 1768b8123f03..000000000000 --- a/drivers/staging/rtl8723bs/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -r8723bs-y = \ - core/rtw_ap.o \ - core/rtw_btcoex.o \ - core/rtw_cmd.o \ - core/rtw_efuse.o \ - core/rtw_io.o \ - core/rtw_ioctl_set.o \ - core/rtw_ieee80211.o \ - core/rtw_mlme.o \ - core/rtw_mlme_ext.o \ - core/rtw_pwrctrl.o \ - core/rtw_recv.o \ - core/rtw_security.o \ - core/rtw_sta_mgt.o \ - core/rtw_wlan_util.o \ - core/rtw_xmit.o \ - hal/hal_intf.o \ - hal/hal_com.o \ - hal/hal_com_phycfg.o \ - hal/hal_btcoex.o \ - hal/hal_sdio.o \ - hal/hal_pwr_seq.o \ - hal/HalPhyRf.o \ - hal/HalPwrSeqCmd.o \ - hal/odm.o \ - hal/odm_CfoTracking.o \ - hal/odm_DIG.o \ - hal/odm_DynamicBBPowerSaving.o \ - hal/odm_DynamicTxPower.o \ - hal/odm_EdcaTurboCheck.o \ - hal/odm_HWConfig.o \ - hal/odm_RegConfig8723B.o \ - hal/rtl8723b_cmd.o \ - hal/rtl8723b_dm.o \ - hal/rtl8723b_hal_init.o \ - hal/rtl8723b_phycfg.o \ - hal/rtl8723b_rf6052.o \ - hal/rtl8723b_rxdesc.o \ - hal/rtl8723bs_recv.o \ - hal/rtl8723bs_xmit.o \ - hal/sdio_halinit.o \ - hal/sdio_ops.o \ - hal/HalBtc8723b1Ant.o \ - hal/HalBtc8723b2Ant.o \ - hal/HalHWImg8723B_BB.o \ - hal/HalHWImg8723B_MAC.o \ - hal/HalHWImg8723B_RF.o \ - hal/HalPhyRf_8723B.o \ - os_dep/ioctl_cfg80211.o \ - os_dep/osdep_service.o \ - os_dep/os_intfs.o \ - os_dep/sdio_intf.o \ - os_dep/sdio_ops_linux.o \ - os_dep/wifi_regd.o \ - os_dep/xmit_linux.o - -obj-$(CONFIG_RTL8723BS) := r8723bs.o - -ccflags-y += -I$(src)/include -I$(src)/hal diff --git a/drivers/staging/rtl8723bs/TODO b/drivers/staging/rtl8723bs/TODO deleted file mode 100644 index 34c216e6da32..000000000000 --- a/drivers/staging/rtl8723bs/TODO +++ /dev/null @@ -1,7 +0,0 @@ -TODO: -- find and remove any code for other chips that is left over -- convert any remaining unusual variable types -- checkpatch.pl fixes - most of the remaining ones are lines too long. Many - of them will require refactoring -- merge Realtek's bugfixes and new features into the driver -- switch to use MAC80211 diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c deleted file mode 100644 index 4728f62a1557..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_ap.c +++ /dev/null @@ -1,1943 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include - -void init_mlme_ap_info(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct sta_priv *pstapriv = &padapter->stapriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - - spin_lock_init(&pmlmepriv->bcn_update_lock); - - /* for ACL */ - INIT_LIST_HEAD(&pacl_list->acl_node_q.queue); - spin_lock_init(&pacl_list->acl_node_q.lock); - - start_ap_mode(padapter); -} - -void free_mlme_ap_info(struct adapter *padapter) -{ - struct sta_info *psta = NULL; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pmlmepriv->update_bcn = false; - pmlmeext->bstart_bss = false; - - rtw_sta_flush(padapter); - - pmlmeinfo->state = _HW_STATE_NOLINK_; - - /* free_assoc_sta_resources */ - rtw_free_all_stainfo(padapter); - - /* free bc/mc sta_info */ - psta = rtw_get_bcmc_stainfo(padapter); - rtw_free_stainfo(padapter, psta); -} - -static void update_BCNTIM(struct adapter *padapter) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network; - unsigned char *pie = pnetwork_mlmeext->ies; - - /* update TIM IE */ - u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL; - __le16 tim_bitmap_le; - unsigned int offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen; - - tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap); - - p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, - WLAN_EID_TIM, - &tim_ielen, - pnetwork_mlmeext->ie_length - _FIXED_IE_LENGTH_ - ); - if (p && tim_ielen > 0) { - tim_ielen += 2; - - premainder_ie = p + tim_ielen; - - tim_ie_offset = (signed int)(p - pie); - - remainder_ielen = pnetwork_mlmeext->ie_length - tim_ie_offset - tim_ielen; - - /* append TIM IE from dst_ie offset */ - dst_ie = p; - } else { - tim_ielen = 0; - - /* calculate head_len */ - offset = _FIXED_IE_LENGTH_; - - /* get ssid_ie len */ - p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, - WLAN_EID_SSID, - &tmp_len, - (pnetwork_mlmeext->ie_length - _BEACON_IE_OFFSET_) - ); - if (p) - offset += tmp_len + 2; - - /* get supported rates len */ - p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, - WLAN_EID_SUPP_RATES, &tmp_len, - (pnetwork_mlmeext->ie_length - _BEACON_IE_OFFSET_) - ); - if (p) - offset += tmp_len + 2; - - /* DS Parameter Set IE, len =3 */ - offset += 3; - - premainder_ie = pie + offset; - - remainder_ielen = pnetwork_mlmeext->ie_length - offset - tim_ielen; - - /* append TIM IE from offset */ - dst_ie = pie + offset; - } - - if (premainder_ie && remainder_ielen) - pbackup_remainder_ie = kmemdup(premainder_ie, remainder_ielen, GFP_ATOMIC); - - *dst_ie++ = WLAN_EID_TIM; - - if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fe)) - tim_ielen = 5; - else - tim_ielen = 4; - - *dst_ie++ = tim_ielen; - - *dst_ie++ = 0;/* DTIM count */ - *dst_ie++ = 1;/* DTIM period */ - - if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */ - *dst_ie++ = BIT(0);/* bitmap ctrl */ - else - *dst_ie++ = 0; - - if (tim_ielen == 4) { - __le16 pvb; - - if (pstapriv->tim_bitmap & 0xff00) - pvb = cpu_to_le16(pstapriv->tim_bitmap >> 8); - else - pvb = tim_bitmap_le; - - *dst_ie++ = le16_to_cpu(pvb); - - } else if (tim_ielen == 5) { - memcpy(dst_ie, &tim_bitmap_le, 2); - dst_ie += 2; - } - - /* copy remainder IE */ - if (pbackup_remainder_ie) { - memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen); - - kfree(pbackup_remainder_ie); - } - - offset = (unsigned int)(dst_ie - pie); - pnetwork_mlmeext->ie_length = offset + remainder_ielen; -} - -static u8 chk_sta_is_alive(struct sta_info *psta) -{ - sta_update_last_rx_pkts(psta); - - return true; -} - -void expire_timeout_chk(struct adapter *padapter) -{ - struct list_head *phead, *plist, *tmp; - u8 updated = false; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - u8 chk_alive_num = 0; - char chk_alive_list[NUM_STA]; - struct sta_info *psta_tmp; - LIST_HEAD(free_list); - int i; - - spin_lock_bh(&pstapriv->auth_list_lock); - - phead = &pstapriv->auth_list; - /* check auth_queue */ - list_for_each_safe(plist, tmp, phead) { - psta = list_entry(plist, struct sta_info, auth_list); - - if (psta->expire_to > 0) { - psta->expire_to--; - if (psta->expire_to == 0) { - list_move(&psta->auth_list, &free_list); - pstapriv->auth_list_cnt--; - } - } - } - - spin_unlock_bh(&pstapriv->auth_list_lock); - - list_for_each_entry_safe(psta, psta_tmp, &free_list, auth_list) { - list_del_init(&psta->auth_list); - rtw_free_stainfo(padapter, psta); - } - - psta = NULL; - - spin_lock_bh(&pstapriv->asoc_list_lock); - - phead = &pstapriv->asoc_list; - /* check asoc_queue */ - list_for_each_safe(plist, tmp, phead) { - psta = list_entry(plist, struct sta_info, asoc_list); - if (chk_sta_is_alive(psta) || !psta->expire_to) { - psta->expire_to = pstapriv->expire_to; - psta->keep_alive_trycnt = 0; - psta->under_exist_checking = 0; - } else { - if (psta->expire_to > 0) - psta->expire_to--; - } - - if (psta->expire_to == 0) { - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - if (padapter->registrypriv.wifi_spec == 1) { - psta->expire_to = pstapriv->expire_to; - continue; - } - - if (psta->state & WIFI_SLEEP_STATE) { - if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) { - /* to check if alive by another methods */ - /* if station is at ps mode. */ - psta->expire_to = pstapriv->expire_to; - psta->state |= WIFI_STA_ALIVE_CHK_STATE; - - /* to update bcn with tim_bitmap for this station */ - pstapriv->tim_bitmap |= BIT(psta->aid); - update_beacon(padapter, WLAN_EID_TIM, true); - - if (!pmlmeext->active_keep_alive_check) - continue; - } - } - if (pmlmeext->active_keep_alive_check) { - int stainfo_offset; - - stainfo_offset = rtw_stainfo_offset(pstapriv, psta); - if (stainfo_offset_valid(stainfo_offset)) - chk_alive_list[chk_alive_num++] = stainfo_offset; - - continue; - } - list_del_init(&psta->asoc_list); - pstapriv->asoc_list_cnt--; - updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING); - } else { - /* TODO: Aging mechanism to digest frames in sleep_q to */ - /* avoid running out of xmitframe */ - if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt) && - padapter->xmitpriv.free_xmitframe_cnt < - ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)) - wakeup_sta_to_xmit(padapter, psta); - } - } - - spin_unlock_bh(&pstapriv->asoc_list_lock); - - if (chk_alive_num) { - u8 backup_oper_channel = 0; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - /* switch to correct channel of current network before issue keep-alive frames */ - if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) { - backup_oper_channel = rtw_get_oper_ch(padapter); - r8723bs_select_channel(padapter, pmlmeext->cur_channel); - } - - /* issue null data to check sta alive*/ - for (i = 0; i < chk_alive_num; i++) { - int ret = _FAIL; - - psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]); - if (!(psta->state & _FW_LINKED)) - continue; - - if (psta->state & WIFI_SLEEP_STATE) - ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50); - else - ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50); - - psta->keep_alive_trycnt++; - if (ret == _SUCCESS) { - psta->expire_to = pstapriv->expire_to; - psta->keep_alive_trycnt = 0; - continue; - } else if (psta->keep_alive_trycnt <= 3) { - psta->expire_to = 1; - continue; - } - - psta->keep_alive_trycnt = 0; - spin_lock_bh(&pstapriv->asoc_list_lock); - if (!list_empty(&psta->asoc_list)) { - list_del_init(&psta->asoc_list); - pstapriv->asoc_list_cnt--; - updated = ap_free_sta(padapter, psta, false, - WLAN_REASON_DEAUTH_LEAVING); - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - } - - if (backup_oper_channel > 0) /* back to the original operation channel */ - r8723bs_select_channel(padapter, backup_oper_channel); - } - - associated_clients_update(padapter, updated); -} - -void add_ratid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level) -{ - unsigned char sta_band = 0, short_gi_rate = false; - unsigned int tx_ra_bitmap = 0; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_bssid_ex - *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; - - if (!psta) - return; - - if (!(psta->state & _FW_LINKED)) - return; - - rtw_hal_update_sta_rate_mask(padapter, psta); - tx_ra_bitmap = psta->ra_mask; - - short_gi_rate = query_ra_short_GI(psta); - - if (pcur_network->configuration.ds_config > 14) { - sta_band |= WIRELESS_INVALID; - } else { - if (tx_ra_bitmap & 0xffff000) - sta_band |= WIRELESS_11_24N; - - if (tx_ra_bitmap & 0xff0) - sta_band |= WIRELESS_11G; - - if (tx_ra_bitmap & 0x0f) - sta_band |= WIRELESS_11B; - } - - psta->wireless_mode = sta_band; - psta->raid = networktype_to_raid_ex(padapter, psta); - - if (psta->aid < NUM_STA) { - u8 arg[4] = {0}; - - arg[0] = psta->mac_id; - arg[1] = psta->raid; - arg[2] = short_gi_rate; - arg[3] = psta->init_rate; - - rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, rssi_level); - } -} - -void update_bmc_sta(struct adapter *padapter) -{ - unsigned char network_type; - unsigned int tx_ra_bitmap = 0; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex - *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; - struct sta_info *psta = rtw_get_bcmc_stainfo(padapter); - - if (psta) { - psta->aid = 0;/* default set to 0 */ - psta->mac_id = psta->aid + 1;/* mac_id = 1 for bc/mc stainfo */ - - pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta; - - psta->qos_option = 0; - psta->htpriv.ht_option = false; - - psta->ieee8021x_blocked = false; - - memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats)); - - /* prepare for add_ratid */ - network_type = rtw_check_network_type((u8 *)&pcur_network->supported_rates, - pcur_network->configuration.ds_config - ); - if (is_supported_tx_cck(network_type)) { - network_type = WIRELESS_11B; - } else if (network_type == WIRELESS_INVALID) { /* error handling */ - - if (pcur_network->configuration.ds_config > 14) - network_type = WIRELESS_INVALID; - else - network_type = WIRELESS_11B; - } - update_sta_basic_rate(psta, network_type); - psta->wireless_mode = network_type; - - rtw_hal_update_sta_rate_mask(padapter, psta); - tx_ra_bitmap = psta->ra_mask; - - psta->raid = networktype_to_raid_ex(padapter, psta); - - /* ap mode */ - rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true); - - /* if (pHalData->fw_ractrl == true) */ - { - u8 arg[4] = {0}; - - arg[0] = psta->mac_id; - arg[1] = psta->raid; - arg[2] = 0; - arg[3] = psta->init_rate; - - rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, 0); - } - - rtw_sta_media_status_rpt(padapter, psta, 1); - - spin_lock_bh(&psta->lock); - psta->state = _FW_LINKED; - spin_unlock_bh(&psta->lock); - } -} - -/* notes: */ -/* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */ -/* MAC_ID = AID+1 for sta in ap/adhoc mode */ -/* MAC_ID = 1 for bc/mc for sta/ap/adhoc */ -/* MAC_ID = 0 for bssid for sta/ap/adhoc */ -/* CAM_ID = 0~3 for default key, cmd_id =macid + 3, macid =aid+1; */ - -void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv; - struct ht_priv *phtpriv_sta = &psta->htpriv; - u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0; - - /* ap mode */ - rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true); - - if (psecuritypriv->dot11_auth_algrthm == dot11_auth_algrthm_8021x) - psta->ieee8021x_blocked = true; - else - psta->ieee8021x_blocked = false; - - /* update sta's cap */ - - /* ERP */ - VCS_update(padapter, psta); - - /* HT related cap */ - if (phtpriv_sta->ht_option) { - /* check if sta supports rx ampdu */ - phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable; - - phtpriv_sta->rx_ampdu_min_spacing = - (phtpriv_sta->ht_cap.ampdu_params_info & - IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2; - - /* bwmode */ - if ((phtpriv_sta->ht_cap.cap_info & - phtpriv_ap->ht_cap.cap_info) & - cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH)) - psta->bw_mode = CHANNEL_WIDTH_40; - else - psta->bw_mode = CHANNEL_WIDTH_20; - - if (pmlmeext->cur_bwmode < psta->bw_mode) - psta->bw_mode = pmlmeext->cur_bwmode; - - phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset; - - /* check if sta support s Short GI 20M */ - if ((phtpriv_sta->ht_cap.cap_info & - phtpriv_ap->ht_cap.cap_info) & - cpu_to_le16(IEEE80211_HT_CAP_SGI_20)) - phtpriv_sta->sgi_20m = true; - - /* check if sta support s Short GI 40M */ - if ((phtpriv_sta->ht_cap.cap_info & - phtpriv_ap->ht_cap.cap_info) & - cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) { - if (psta->bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */ - phtpriv_sta->sgi_40m = true; - else - phtpriv_sta->sgi_40m = false; - } - - psta->qos_option = true; - - /* B0 Config LDPC Coding Capability */ - if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) && - GET_HT_CAPABILITY_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) - SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX)); - - /* B7 B8 B9 Config STBC setting */ - if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) && - GET_HT_CAPABILITY_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) - SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX)); - } else { - phtpriv_sta->ampdu_enable = false; - - phtpriv_sta->sgi_20m = false; - phtpriv_sta->sgi_40m = false; - psta->bw_mode = CHANNEL_WIDTH_20; - phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - } - - phtpriv_sta->ldpc_cap = cur_ldpc_cap; - phtpriv_sta->stbc_cap = cur_stbc_cap; - phtpriv_sta->beamform_cap = cur_beamform_cap; - - /* Rx AMPDU */ - send_delba(padapter, 0, psta->hwaddr);/* recipient */ - - /* TX AMPDU */ - send_delba(padapter, 1, psta->hwaddr);/* originator */ - phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */ - phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */ - - update_ldpc_stbc_cap(psta); - - /* todo: init other variables */ - - memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats)); - - spin_lock_bh(&psta->lock); - psta->state |= _FW_LINKED; - spin_unlock_bh(&psta->lock); -} - -static void update_ap_info(struct adapter *padapter, struct sta_info *psta) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_bssid_ex - *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv; - - psta->wireless_mode = pmlmeext->cur_wireless_mode; - - psta->bssratelen = rtw_get_rateset_len(pnetwork->supported_rates); - memcpy(psta->bssrateset, pnetwork->supported_rates, psta->bssratelen); - - /* HT related cap */ - if (phtpriv_ap->ht_option) { - /* check if sta support s Short GI 20M */ - if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20)) - phtpriv_ap->sgi_20m = true; - - /* check if sta support s Short GI 40M */ - if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) - phtpriv_ap->sgi_40m = true; - - psta->qos_option = true; - } else { - phtpriv_ap->ampdu_enable = false; - - phtpriv_ap->sgi_20m = false; - phtpriv_ap->sgi_40m = false; - } - - psta->bw_mode = pmlmeext->cur_bwmode; - phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset; - - phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */ - phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */ - - memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv)); -} - -static void update_hw_ht_param(struct adapter *padapter) -{ - unsigned char max_AMPDU_len; - unsigned char min_MPDU_spacing; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - /* handle A-MPDU parameter field - * - * AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k - * AMPDU_para [4:2]:Min MPDU Start Spacing - */ - max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03; - - min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2; - - rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing)); - - rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len)); - - /* */ - /* Config SM Power Save setting */ - /* */ - pmlmeinfo->SM_PS = - (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & - 0x0C) >> 2; -} - -void start_bss_network(struct adapter *padapter) -{ - u8 *p; - u8 val8, cur_channel, cur_bwmode, cur_ch_offset; - u16 bcn_interval; - u32 acparm; - int ie_len; - struct registry_priv *pregpriv = &padapter->registrypriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct wlan_bssid_ex - *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network; - struct HT_info_element *pht_info = NULL; - u8 cbw40_enable = 0; - - bcn_interval = (u16)pnetwork->configuration.beacon_period; - cur_channel = pnetwork->configuration.ds_config; - cur_bwmode = CHANNEL_WIDTH_20; - cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - - /* - * check if there is wps ie, - * if there is wpsie in beacon, - * the hostapd will update beacon twice when stating hostapd, - * and at first time the security ie (RSN/WPA IE) will not include in beacon. - */ - if (!rtw_get_wps_ie(pnetwork->ies + _FIXED_IE_LENGTH_, - pnetwork->ie_length - _FIXED_IE_LENGTH_, NULL, NULL)) - pmlmeext->bstart_bss = true; - - /* todo: update wmm, ht cap */ - if (pmlmepriv->qospriv.qos_option) - pmlmeinfo->WMM_enable = true; - if (pmlmepriv->htpriv.ht_option) { - pmlmeinfo->WMM_enable = true; - pmlmeinfo->HT_enable = true; - update_hw_ht_param(padapter); - } - - if (!pmlmepriv->cur_network.join_res) { /* setting only at first time */ - - /* WEP Key will be set before this function, do not clear CAM. */ - if ((psecuritypriv->dot11_privacy_algrthm != _WEP40_) && - (psecuritypriv->dot11_privacy_algrthm != _WEP104_)) - flush_all_cam_entry(padapter); /* clear CAM */ - } - - /* set MSR to AP_Mode */ - set_msr(padapter, _HW_STATE_AP_); - - /* Set BSSID REG */ - rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->mac_address); - - /* Set EDCA param reg */ - acparm = 0x002F3217; /* VO */ - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm)); - acparm = 0x005E4317; /* VI */ - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm)); - acparm = 0x005ea42b; - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm)); - acparm = 0x0000A444; /* BK */ - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm)); - - /* Set Security */ - val8 = (psecuritypriv->dot11_auth_algrthm == - dot11_auth_algrthm_8021x) ? 0xcc : 0xcf; - rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8)); - - /* Beacon Control related register */ - rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval)); - - if (!pmlmepriv->cur_network.join_res) { /* setting only at first time */ - /* turn on all dynamic functions */ - switch_dm_func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); - } - - /* set channel, bwmode */ - p = rtw_get_ie((pnetwork->ies + sizeof(struct ndis_802_11_fix_ie)), - WLAN_EID_HT_OPERATION, - &ie_len, - (pnetwork->ie_length - sizeof(struct ndis_802_11_fix_ie)) - ); - if (p && ie_len) { - pht_info = (struct HT_info_element *)(p + 2); - - if ((pregpriv->bw_mode & 0x0f) > 0) - cbw40_enable = 1; - - if ((cbw40_enable) && (pht_info->infos[0] & BIT(2))) { - /* switch to the 40M Hz mode */ - cur_bwmode = CHANNEL_WIDTH_40; - switch (pht_info->infos[0] & 0x3) { - case 1: - cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER; - break; - - case 3: - cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER; - break; - - default: - cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - break; - } - } - } - - set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode); - pmlmeext->cur_channel = cur_channel; - pmlmeext->cur_bwmode = cur_bwmode; - pmlmeext->cur_ch_offset = cur_ch_offset; - pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type; - - /* let pnetwork_mlmeext == pnetwork_mlme. */ - memcpy(pnetwork_mlmeext, pnetwork, pnetwork->length); - - /* update cur_wireless_mode */ - update_wireless_mode(padapter); - - /* update RRSR after set channel and bandwidth */ - update_basic_rate_table(padapter, pnetwork->supported_rates); - rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->supported_rates); - - /* update capability after cur_wireless_mode updated */ - update_capinfo(padapter, - rtw_get_capability((struct wlan_bssid_ex *)pnetwork)); - - if (pmlmeext->bstart_bss) { - update_beacon(padapter, WLAN_EID_TIM, true); - - /* issue beacon frame */ - send_beacon(padapter); - } - - /* update bc/mc sta_info */ - update_bmc_sta(padapter); -} - -int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) -{ - int ret = _SUCCESS; - u8 *p; - u8 *ht_caps_ie = NULL; - u8 *ht_info_ie = NULL; - struct sta_info *psta = NULL; - u16 cap, ht_cap = false; - unsigned int ie_len = 0; - int group_cipher, pairwise_cipher; - u8 channel, network_type, support_rate[NDIS_802_11_LENGTH_RATES_EX]; - int support_rate_num = 0; - u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01}; - u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01}; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_bssid_ex - *pbss_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; - u8 *ie = pbss_network->ies; - - if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) - return _FAIL; - - if (len < 0 || len > MAX_IE_SZ) - return _FAIL; - - pbss_network->ie_length = len; - - memset(ie, 0, MAX_IE_SZ); - - memcpy(ie, pbuf, pbss_network->ie_length); - - if (pbss_network->infrastructure_mode != NL80211_IFTYPE_AP) - return _FAIL; - - pbss_network->rssi = 0; - - memcpy(pbss_network->mac_address, myid(&padapter->eeprompriv), ETH_ALEN); - - /* beacon interval */ - /* ie + 8; 8: TimeStamp, 2: Beacon Interval 2:Capability */ - p = rtw_get_beacon_interval_from_ie(ie); - pbss_network->configuration.beacon_period = get_unaligned_le16(p); - - /* capability */ - cap = get_unaligned_le16(ie); - - /* SSID */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_SSID, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) { - memset(&pbss_network->ssid, 0, sizeof(struct ndis_802_11_ssid)); - memcpy(pbss_network->ssid.ssid, (p + 2), ie_len); - pbss_network->ssid.ssid_length = ie_len; - } - - /* channel */ - channel = 0; - pbss_network->configuration.length = 0; - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_DS_PARAMS, &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) - channel = *(p + 2); - - pbss_network->configuration.ds_config = channel; - - memset(support_rate, 0, NDIS_802_11_LENGTH_RATES_EX); - /* get supported rates */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_SUPP_RATES, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p) { - memcpy(support_rate, p + 2, ie_len); - support_rate_num = ie_len; - } - - /* get ext_supported rates */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_EXT_SUPP_RATES, - &ie_len, - pbss_network->ie_length - _BEACON_IE_OFFSET_); - if (p) - memcpy(support_rate + support_rate_num, p + 2, ie_len); - - network_type = rtw_check_network_type(support_rate, channel); - - rtw_set_supported_rate(pbss_network->supported_rates, network_type); - - /* parsing ERP_IE */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_ERP_INFO, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) - ERP_IE_handler(padapter, (struct ndis_80211_var_ie *)p); - - /* update privacy/security */ - if (cap & BIT(4)) - pbss_network->privacy = 1; - else - pbss_network->privacy = 0; - - psecuritypriv->wpa_psk = 0; - - /* wpa2 */ - group_cipher = 0; pairwise_cipher = 0; - psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_; - psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_; - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_RSN, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) { - if (rtw_parse_wpa2_ie(p, - ie_len + 2, - &group_cipher, - &pairwise_cipher, - NULL) == _SUCCESS) { - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_8021x; - - psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */ - psecuritypriv->wpa_psk |= BIT(1); - - psecuritypriv->wpa2_group_cipher = group_cipher; - psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher; - } - } - - /* wpa */ - ie_len = 0; - group_cipher = 0; pairwise_cipher = 0; - psecuritypriv->wpa_group_cipher = _NO_PRIVACY_; - psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_; - for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) { - p = rtw_get_ie(p, - WLAN_EID_VENDOR_SPECIFIC, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2))); - if ((p) && (!memcmp(p + 2, OUI1, 4))) { - if (rtw_parse_wpa_ie(p, - ie_len + 2, - &group_cipher, - &pairwise_cipher, - NULL) == _SUCCESS) { - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_8021x; - - psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */ - - psecuritypriv->wpa_psk |= BIT(0); - - psecuritypriv->wpa_group_cipher = group_cipher; - psecuritypriv->wpa_pairwise_cipher = pairwise_cipher; - } - - break; - } - - if (!p || ie_len == 0) - break; - } - - /* wmm */ - ie_len = 0; - pmlmepriv->qospriv.qos_option = 0; - if (pregistrypriv->wmm_enable) { - for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) { - p = rtw_get_ie(p, - WLAN_EID_VENDOR_SPECIFIC, - &ie_len, - (pbss_network->ie_length - - _BEACON_IE_OFFSET_ - (ie_len + 2))); - if ((p) && !memcmp(p + 2, WMM_PARA_IE, 6)) { - pmlmepriv->qospriv.qos_option = 1; - - *(p + 8) |= BIT(7);/* QoS Info, support U-APSD */ - - /* disable all ACM bits since the WMM admission */ - /* control is not supported */ - *(p + 10) &= ~BIT(4); /* BE */ - *(p + 14) &= ~BIT(4); /* BK */ - *(p + 18) &= ~BIT(4); /* VI */ - *(p + 22) &= ~BIT(4); /* VO */ - - break; - } - - if (!p || ie_len == 0) - break; - } - } - - /* parsing HT_CAP_IE */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_HT_CAPABILITY, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) { - u8 max_rx_ampdu_factor = 0; - struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p + 2); - - ht_caps_ie = p; - - ht_cap = true; - network_type |= WIRELESS_11_24N; - - rtw_ht_use_default_setting(padapter); - - if (!pmlmepriv->htpriv.sgi_20m) - pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_SGI_20)); - - if (!pmlmepriv->htpriv.sgi_40m) - pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_SGI_40)); - - if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX)) - pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_LDPC_CODING)); - - if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX)) - pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_TX_STBC)); - - if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX)) - pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_RX_STBC_3R)); - - pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | - IEEE80211_HT_CAP_AMPDU_DENSITY); - - if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) || - (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP)) { - pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & - (0x07 << 2)); - } else { - pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & - 0x00); - } - - rtw_hal_get_def_var(padapter, - HW_VAR_MAX_RX_AMPDU_FACTOR, - &max_rx_ampdu_factor); - /* set Max Rx AMPDU size to 64K */ - pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & - max_rx_ampdu_factor); - - pht_cap->mcs.rx_mask[0] = 0xff; - pht_cap->mcs.rx_mask[1] = 0x0; - - memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len); - } - - /* parsing HT_INFO_IE */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_HT_OPERATION, - &ie_len, - (pbss_network->ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) - ht_info_ie = p; - - pmlmepriv->cur_network.network_type = network_type; - - pmlmepriv->htpriv.ht_option = false; - - /* ht_cap */ - if (pregistrypriv->ht_enable && ht_cap) { - pmlmepriv->htpriv.ht_option = true; - pmlmepriv->qospriv.qos_option = 1; - - if (pregistrypriv->ampdu_enable == 1) - pmlmepriv->htpriv.ampdu_enable = true; - - HT_caps_handler(padapter, (struct ndis_80211_var_ie *)ht_caps_ie); - - HT_info_handler(padapter, (struct ndis_80211_var_ie *)ht_info_ie); - } - - pbss_network->length = - get_wlan_bssid_ex_sz((struct wlan_bssid_ex *)pbss_network); - - /* issue beacon to start bss network */ - rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK); - - /* alloc sta_info for ap itself */ - psta = rtw_get_stainfo(&padapter->stapriv, pbss_network->mac_address); - if (!psta) { - psta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->mac_address); - if (!psta) - return _FAIL; - } - - /* update AP's sta info */ - update_ap_info(padapter, psta); - - psta->state |= WIFI_AP_STATE; - rtw_indicate_connect(padapter); - - pmlmepriv->cur_network.join_res = true;/* for check if already set beacon */ - - return ret; -} - -void rtw_set_macaddr_acl(struct adapter *padapter, int mode) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - - pacl_list->mode = mode; -} - -int rtw_acl_add_sta(struct adapter *padapter, u8 *addr) -{ - struct list_head *plist, *phead; - u8 added = false; - int i, ret = 0; - struct rtw_wlan_acl_node *paclnode; - struct sta_priv *pstapriv = &padapter->stapriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - struct __queue *pacl_node_q = &pacl_list->acl_node_q; - - if ((NUM_ACL - 1) < pacl_list->num) - return (-1); - - spin_lock_bh(&pacl_node_q->lock); - - phead = get_list_head(pacl_node_q); - list_for_each(plist, phead) { - paclnode = list_entry(plist, struct rtw_wlan_acl_node, list); - - if (!memcmp(paclnode->addr, addr, ETH_ALEN)) { - if (paclnode->valid) { - added = true; - break; - } - } - } - - spin_unlock_bh(&pacl_node_q->lock); - - if (added) - return ret; - - spin_lock_bh(&pacl_node_q->lock); - - for (i = 0; i < NUM_ACL; i++) { - paclnode = &pacl_list->aclnode[i]; - - if (!paclnode->valid) { - INIT_LIST_HEAD(&paclnode->list); - - memcpy(paclnode->addr, addr, ETH_ALEN); - - paclnode->valid = true; - - list_add_tail(&paclnode->list, get_list_head(pacl_node_q)); - - pacl_list->num++; - - break; - } - } - - spin_unlock_bh(&pacl_node_q->lock); - - return ret; -} - -void rtw_acl_remove_sta(struct adapter *padapter, u8 *addr) -{ - struct list_head *plist, *phead, *tmp; - struct rtw_wlan_acl_node *paclnode; - struct sta_priv *pstapriv = &padapter->stapriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - struct __queue *pacl_node_q = &pacl_list->acl_node_q; - - spin_lock_bh(&pacl_node_q->lock); - - phead = get_list_head(pacl_node_q); - list_for_each_safe(plist, tmp, phead) { - paclnode = list_entry(plist, struct rtw_wlan_acl_node, list); - - if (!memcmp(paclnode->addr, addr, ETH_ALEN) || - is_broadcast_ether_addr(addr)) { - if (paclnode->valid) { - paclnode->valid = false; - - list_del_init(&paclnode->list); - - pacl_list->num--; - } - } - } - - spin_unlock_bh(&pacl_node_q->lock); -} - -u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta) -{ - struct cmd_obj *ph2c; - struct set_stakey_parm *psetstakey_para; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - psetstakey_para = kzalloc_obj(*psetstakey_para); - if (!psetstakey_para) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, SET_STA_KEY_CMD); - - psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy; - - memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN); - - memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - - return res; -} - -static int rtw_ap_set_key(struct adapter *padapter, - u8 *key, - u8 alg, - int keyid, - u8 set_tx) -{ - u8 keylen; - struct cmd_obj *pcmd; - struct setkey_parm *psetkeyparm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - int res = _SUCCESS; - - pcmd = kzalloc_obj(*pcmd); - if (!pcmd) { - res = _FAIL; - goto exit; - } - psetkeyparm = kzalloc_obj(*psetkeyparm); - if (!psetkeyparm) { - kfree(pcmd); - res = _FAIL; - goto exit; - } - - psetkeyparm->keyid = (u8)keyid; - if (is_wep_enc(alg)) - padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid); - - psetkeyparm->algorithm = alg; - - psetkeyparm->set_tx = set_tx; - - switch (alg) { - case _WEP40_: - keylen = 5; - break; - case _WEP104_: - keylen = 13; - break; - case _TKIP_: - case _TKIP_WTMIC_: - case _AES_: - default: - keylen = 16; - } - - memcpy(&psetkeyparm->key[0], key, keylen); - - pcmd->cmdcode = SET_KEY_CMD; - pcmd->parmbuf = (u8 *)psetkeyparm; - pcmd->cmdsz = (sizeof(struct setkey_parm)); - pcmd->rsp = NULL; - pcmd->rspsz = 0; - - INIT_LIST_HEAD(&pcmd->list); - - res = rtw_enqueue_cmd(pcmdpriv, pcmd); - -exit: - - return res; -} - -int rtw_ap_set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid) -{ - return rtw_ap_set_key(padapter, key, alg, keyid, 1); -} - -int rtw_ap_set_wep_key(struct adapter *padapter, - u8 *key, - u8 keylen, - int keyid, - u8 set_tx) -{ - u8 alg; - - switch (keylen) { - case 5: - alg = _WEP40_; - break; - case 13: - alg = _WEP104_; - break; - default: - alg = _NO_PRIVACY_; - } - - return rtw_ap_set_key(padapter, key, alg, keyid, set_tx); -} - -static void update_bcn_fixed_ie(struct adapter *padapter) -{ -} - -static void update_bcn_erpinfo_ie(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network; - unsigned char *p, *ie = pnetwork->ies; - u32 len = 0; - - if (!pmlmeinfo->ERP_enable) - return; - - /* parsing ERP_IE */ - p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, - WLAN_EID_ERP_INFO, - &len, - (pnetwork->ie_length - _BEACON_IE_OFFSET_)); - if (p && len > 0) { - struct ndis_80211_var_ie *erp_ie = (struct ndis_80211_var_ie *)p; - - if (pmlmepriv->num_sta_non_erp == 1) - erp_ie->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | - RTW_ERP_INFO_USE_PROTECTION; - else - erp_ie->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | - RTW_ERP_INFO_USE_PROTECTION); - - if (pmlmepriv->num_sta_no_short_preamble > 0) - erp_ie->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE; - else - erp_ie->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE); - - ERP_IE_handler(padapter, erp_ie); - } -} - -static void update_bcn_htcap_ie(struct adapter *padapter) -{ -} - -static void update_bcn_htinfo_ie(struct adapter *padapter) -{ -} - -static void update_bcn_rsn_ie(struct adapter *padapter) -{ -} - -void update_beacon(struct adapter *padapter, u8 ie_id, u8 tx) -{ - struct mlme_priv *pmlmepriv; - struct mlme_ext_priv *pmlmeext; - - if (!padapter) - return; - - pmlmepriv = &padapter->mlmepriv; - pmlmeext = &padapter->mlmeextpriv; - - if (!pmlmeext->bstart_bss) - return; - - spin_lock_bh(&pmlmepriv->bcn_update_lock); - - switch (ie_id) { - case 0xFF: - - update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */ - - break; - - case WLAN_EID_TIM: - - update_BCNTIM(padapter); - - break; - - case WLAN_EID_ERP_INFO: - - update_bcn_erpinfo_ie(padapter); - - break; - - case WLAN_EID_HT_CAPABILITY: - - update_bcn_htcap_ie(padapter); - - break; - - case WLAN_EID_RSN: - - update_bcn_rsn_ie(padapter); - - break; - - case WLAN_EID_HT_OPERATION: - - update_bcn_htinfo_ie(padapter); - - break; - - default: - break; - } - - pmlmepriv->update_bcn = true; - - spin_unlock_bh(&pmlmepriv->bcn_update_lock); - - if (tx) - set_tx_beacon_cmd(padapter); -} - -/* - * op_mode - * Set to 0 (HT pure) under the following conditions - * - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or - * - all STAs in the BSS are 20 MHz HT in 20 MHz BSS - * Set to 1 (HT non-member protection) if there may be non-HT STAs - * in both the primary and the secondary channel - * Set to 2 if only HT STAs are associated in BSS, - * however and at least one 20 MHz HT STA is associated - * Set to 3 (HT mixed mode) when one or more non-HT STAs are associated - * (currently non-GF HT station is considered as non-HT STA also) - */ -static int rtw_ht_operation_update(struct adapter *padapter) -{ - u16 cur_op_mode, new_op_mode; - int op_mode_changes = 0; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv; - - if (pmlmepriv->htpriv.ht_option) - return 0; - - if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && - pmlmepriv->num_sta_ht_no_gf) { - pmlmepriv->ht_op_mode |= - IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT; - op_mode_changes++; - } else if ((pmlmepriv->ht_op_mode & - IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && - pmlmepriv->num_sta_ht_no_gf == 0) { - pmlmepriv->ht_op_mode &= - ~IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT; - op_mode_changes++; - } - - if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) && - (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) { - pmlmepriv->ht_op_mode |= IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; - op_mode_changes++; - } else if ((pmlmepriv->ht_op_mode & - IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) && - (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) { - pmlmepriv->ht_op_mode &= - ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; - op_mode_changes++; - } - - /* Note: currently we switch to the MIXED op mode if HT non-greenfield - * station is associated. Probably it's a theoretical case, since - * it looks like all known HT STAs support greenfield. - */ - new_op_mode = 0; - if (pmlmepriv->num_sta_no_ht || - (pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)) - new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED; - else if ((le16_to_cpu(phtpriv_ap->ht_cap.cap_info) & - IEEE80211_HT_CAP_SUP_WIDTH) && - pmlmepriv->num_sta_ht_20mhz) - new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ; - else if (pmlmepriv->olbc_ht) - new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER; - else - new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; - - cur_op_mode = pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_PROTECTION; - if (cur_op_mode != new_op_mode) { - pmlmepriv->ht_op_mode &= ~IEEE80211_HT_OP_MODE_PROTECTION; - pmlmepriv->ht_op_mode |= new_op_mode; - op_mode_changes++; - } - - return op_mode_changes; -} - -void associated_clients_update(struct adapter *padapter, u8 updated) -{ - /* update associated stations cap. */ - if (updated) { - struct list_head *phead, *plist; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - - spin_lock_bh(&pstapriv->asoc_list_lock); - - phead = &pstapriv->asoc_list; - /* check asoc_queue */ - list_for_each(plist, phead) { - psta = list_entry(plist, struct sta_info, asoc_list); - - VCS_update(padapter, psta); - } - - spin_unlock_bh(&pstapriv->asoc_list_lock); - } -} - -/* called > TSR LEVEL for USB or SDIO Interface*/ -void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) -{ - u8 beacon_updated = false; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) { - if (!psta->no_short_preamble_set) { - psta->no_short_preamble_set = 1; - - pmlmepriv->num_sta_no_short_preamble++; - - if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && - (pmlmepriv->num_sta_no_short_preamble == 1)) { - beacon_updated = true; - update_beacon(padapter, 0xFF, true); - } - } - } else { - if (psta->no_short_preamble_set) { - psta->no_short_preamble_set = 0; - - pmlmepriv->num_sta_no_short_preamble--; - - if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && - (pmlmepriv->num_sta_no_short_preamble == 0)) { - beacon_updated = true; - update_beacon(padapter, 0xFF, true); - } - } - } - - if (psta->flags & WLAN_STA_NONERP) { - if (!psta->nonerp_set) { - psta->nonerp_set = 1; - - pmlmepriv->num_sta_non_erp++; - - if (pmlmepriv->num_sta_non_erp == 1) { - beacon_updated = true; - update_beacon(padapter, WLAN_EID_ERP_INFO, true); - } - } - } else { - if (psta->nonerp_set) { - psta->nonerp_set = 0; - - pmlmepriv->num_sta_non_erp--; - - if (pmlmepriv->num_sta_non_erp == 0) { - beacon_updated = true; - update_beacon(padapter, WLAN_EID_ERP_INFO, true); - } - } - } - - if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) { - if (!psta->no_short_slot_time_set) { - psta->no_short_slot_time_set = 1; - - pmlmepriv->num_sta_no_short_slot_time++; - - if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && - (pmlmepriv->num_sta_no_short_slot_time == 1)) { - beacon_updated = true; - update_beacon(padapter, 0xFF, true); - } - } - } else { - if (psta->no_short_slot_time_set) { - psta->no_short_slot_time_set = 0; - - pmlmepriv->num_sta_no_short_slot_time--; - - if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && - (pmlmepriv->num_sta_no_short_slot_time == 0)) { - beacon_updated = true; - update_beacon(padapter, 0xFF, true); - } - } - } - - if (psta->flags & WLAN_STA_HT) { - u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info); - - if (psta->no_ht_set) { - psta->no_ht_set = 0; - pmlmepriv->num_sta_no_ht--; - } - - if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) { - if (!psta->no_ht_gf_set) { - psta->no_ht_gf_set = 1; - pmlmepriv->num_sta_ht_no_gf++; - } - } - - if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) { - if (!psta->ht_20mhz_set) { - psta->ht_20mhz_set = 1; - pmlmepriv->num_sta_ht_20mhz++; - } - } - - } else { - if (!psta->no_ht_set) { - psta->no_ht_set = 1; - pmlmepriv->num_sta_no_ht++; - } - } - - if (rtw_ht_operation_update(padapter) > 0) { - update_beacon(padapter, WLAN_EID_HT_CAPABILITY, false); - update_beacon(padapter, WLAN_EID_HT_OPERATION, true); - } - - /* update associated stations cap. */ - associated_clients_update(padapter, beacon_updated); -} - -u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta) -{ - u8 beacon_updated = false; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - if (!psta) - return beacon_updated; - - if (psta->no_short_preamble_set) { - psta->no_short_preamble_set = 0; - pmlmepriv->num_sta_no_short_preamble--; - if (pmlmeext->cur_wireless_mode > WIRELESS_11B && - pmlmepriv->num_sta_no_short_preamble == 0){ - beacon_updated = true; - update_beacon(padapter, 0xFF, true); - } - } - - if (psta->nonerp_set) { - psta->nonerp_set = 0; - pmlmepriv->num_sta_non_erp--; - if (pmlmepriv->num_sta_non_erp == 0) { - beacon_updated = true; - update_beacon(padapter, WLAN_EID_ERP_INFO, true); - } - } - - if (psta->no_short_slot_time_set) { - psta->no_short_slot_time_set = 0; - pmlmepriv->num_sta_no_short_slot_time--; - if (pmlmeext->cur_wireless_mode > WIRELESS_11B && - pmlmepriv->num_sta_no_short_slot_time == 0){ - beacon_updated = true; - update_beacon(padapter, 0xFF, true); - } - } - - if (psta->no_ht_gf_set) { - psta->no_ht_gf_set = 0; - pmlmepriv->num_sta_ht_no_gf--; - } - - if (psta->no_ht_set) { - psta->no_ht_set = 0; - pmlmepriv->num_sta_no_ht--; - } - - if (psta->ht_20mhz_set) { - psta->ht_20mhz_set = 0; - pmlmepriv->num_sta_ht_20mhz--; - } - - if (rtw_ht_operation_update(padapter) > 0) { - update_beacon(padapter, WLAN_EID_HT_CAPABILITY, false); - update_beacon(padapter, WLAN_EID_HT_OPERATION, true); - } - - return beacon_updated; -} - -u8 ap_free_sta(struct adapter *padapter, - struct sta_info *psta, - bool active, - u16 reason) -{ - u8 beacon_updated = false; - - if (!psta) - return beacon_updated; - - if (active) { - /* tear down Rx AMPDU */ - send_delba(padapter, 0, psta->hwaddr);/* recipient */ - - /* tear down TX AMPDU */ - send_delba(padapter, 1, psta->hwaddr);/* // originator */ - - issue_deauth(padapter, psta->hwaddr, reason); - } - - psta->htpriv.agg_enable_bitmap = 0x0;/* reset */ - psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */ - - /* clear cam entry / key */ - rtw_clearstakey_cmd(padapter, psta, true); - - spin_lock_bh(&psta->lock); - psta->state &= ~_FW_LINKED; - spin_unlock_bh(&psta->lock); - - rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason); - - report_del_sta_event(padapter, psta->hwaddr, reason); - - beacon_updated = bss_cap_update_on_sta_leave(padapter, psta); - - rtw_free_stainfo(padapter, psta); - - return beacon_updated; -} - -void rtw_sta_flush(struct adapter *padapter) -{ - struct list_head *phead, *plist, *tmp; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - - if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE) - return; - - spin_lock_bh(&pstapriv->asoc_list_lock); - phead = &pstapriv->asoc_list; - /* free sta asoc_queue */ - list_for_each_safe(plist, tmp, phead) { - psta = list_entry(plist, struct sta_info, asoc_list); - - list_del_init(&psta->asoc_list); - pstapriv->asoc_list_cnt--; - - ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - - issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING); - - associated_clients_update(padapter, true); -} - -/* called > TSR LEVEL for USB or SDIO Interface*/ -void sta_info_update(struct adapter *padapter, struct sta_info *psta) -{ - int flags = psta->flags; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - /* update wmm cap. */ - if (WLAN_STA_WME & flags) - psta->qos_option = 1; - else - psta->qos_option = 0; - - if (pmlmepriv->qospriv.qos_option == 0) - psta->qos_option = 0; - - /* update 802.11n ht cap. */ - if (WLAN_STA_HT & flags) { - psta->htpriv.ht_option = true; - psta->qos_option = 1; - } else { - psta->htpriv.ht_option = false; - } - - if (!pmlmepriv->htpriv.ht_option) - psta->htpriv.ht_option = false; - - update_sta_info_apmode(padapter, psta); -} - -/* called >= TSR LEVEL for USB or SDIO Interface*/ -void ap_sta_info_defer_update(struct adapter *padapter, struct sta_info *psta) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (psta->state & _FW_LINKED) { - pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta; - - /* add ratid */ - add_ratid(padapter, psta, 0);/* DM_RATR_STA_INIT */ - } -} - -/* restore hw setting from sw data structures */ -void rtw_ap_restore_network(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *psta; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct list_head *phead, *plist; - u8 chk_alive_num = 0; - char chk_alive_list[NUM_STA]; - int i; - - rtw_setopmode_cmd(padapter, NL80211_IFTYPE_AP, false); - - set_channel_bwmode(padapter, - pmlmeext->cur_channel, - pmlmeext->cur_ch_offset, - pmlmeext->cur_bwmode); - - start_bss_network(padapter); - - if ((padapter->securitypriv.dot11_privacy_algrthm == _TKIP_) || - (padapter->securitypriv.dot11_privacy_algrthm == _AES_)) { - /* restore group key, WEP keys is restored in ips_leave() */ - rtw_set_key(padapter, - psecuritypriv, - psecuritypriv->dot118021XGrpKeyid, - 0, - false); - } - - spin_lock_bh(&pstapriv->asoc_list_lock); - - phead = &pstapriv->asoc_list; - list_for_each(plist, phead) { - int stainfo_offset; - - psta = list_entry(plist, struct sta_info, asoc_list); - - stainfo_offset = rtw_stainfo_offset(pstapriv, psta); - if (stainfo_offset_valid(stainfo_offset)) - chk_alive_list[chk_alive_num++] = stainfo_offset; - } - - spin_unlock_bh(&pstapriv->asoc_list_lock); - - for (i = 0; i < chk_alive_num; i++) { - psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]); - - if (!psta) - continue; - - if (psta->state & _FW_LINKED) { - rtw_sta_media_status_rpt(padapter, psta, 1); - update_ra_entry(padapter, psta); - /* pairwise key */ - /* per sta pairwise key and settings */ - if ((psecuritypriv->dot11_privacy_algrthm == _TKIP_) || - (psecuritypriv->dot11_privacy_algrthm == _AES_)) { - rtw_setstakey_cmd(padapter, psta, true, false); - } - } - } -} - -void start_ap_mode(struct adapter *padapter) -{ - int i; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - - pmlmepriv->update_bcn = false; - - pmlmeext->bstart_bss = false; - - pmlmepriv->num_sta_non_erp = 0; - - pmlmepriv->num_sta_no_short_slot_time = 0; - - pmlmepriv->num_sta_no_short_preamble = 0; - - pmlmepriv->num_sta_ht_no_gf = 0; - pmlmepriv->num_sta_no_ht = 0; - pmlmepriv->num_sta_ht_20mhz = 0; - - pmlmepriv->olbc = false; - - pmlmepriv->olbc_ht = false; - - pmlmepriv->ht_op_mode = 0; - - for (i = 0; i < NUM_STA; i++) - pstapriv->sta_aid[i] = NULL; - - pmlmepriv->wps_beacon_ie = NULL; - pmlmepriv->wps_probe_resp_ie = NULL; - pmlmepriv->wps_assoc_resp_ie = NULL; - - pmlmepriv->p2p_beacon_ie = NULL; - pmlmepriv->p2p_probe_resp_ie = NULL; - - /* for ACL */ - INIT_LIST_HEAD(&pacl_list->acl_node_q.queue); - pacl_list->num = 0; - pacl_list->mode = 0; - for (i = 0; i < NUM_ACL; i++) { - INIT_LIST_HEAD(&pacl_list->aclnode[i].list); - pacl_list->aclnode[i].valid = false; - } -} - -void stop_ap_mode(struct adapter *padapter) -{ - struct list_head *phead, *plist, *tmp; - struct rtw_wlan_acl_node *paclnode; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - struct __queue *pacl_node_q = &pacl_list->acl_node_q; - - pmlmepriv->update_bcn = false; - pmlmeext->bstart_bss = false; - - /* reset and init security priv , this can refine with rtw_reset_securitypriv */ - memset((unsigned char *)&padapter->securitypriv, - 0, - sizeof(struct security_priv)); - padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen; - padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled; - - /* for ACL */ - spin_lock_bh(&pacl_node_q->lock); - phead = get_list_head(pacl_node_q); - list_for_each_safe(plist, tmp, phead) { - paclnode = list_entry(plist, struct rtw_wlan_acl_node, list); - - if (paclnode->valid) { - paclnode->valid = false; - - list_del_init(&paclnode->list); - - pacl_list->num--; - } - } - spin_unlock_bh(&pacl_node_q->lock); - - rtw_sta_flush(padapter); - - /* free_assoc_sta_resources */ - rtw_free_all_stainfo(padapter); - - psta = rtw_get_bcmc_stainfo(padapter); - rtw_free_stainfo(padapter, psta); - - rtw_init_bcmc_stainfo(padapter); - - rtw_free_mlme_priv_ie_data(pmlmepriv); - - rtw_btcoex_media_status_notify(padapter, 0); /* disconnect */ -} diff --git a/drivers/staging/rtl8723bs/core/rtw_btcoex.c b/drivers/staging/rtl8723bs/core/rtw_btcoex.c deleted file mode 100644 index 9e00424d00bd..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_btcoex.c +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include - -void rtw_btcoex_media_status_notify(struct adapter *padapter, u8 media_status) -{ - if ((media_status == RT_MEDIA_CONNECT) && - check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) { - rtw_hal_set_hwreg(padapter, HW_VAR_DL_RSVD_PAGE, NULL); - } - - hal_btcoex_MediaStatusNotify(padapter, media_status); -} - -void rtw_btcoex_halt_notify(struct adapter *padapter) -{ - if (!padapter->bup) - return; - - if (padapter->bSurpriseRemoved) - return; - - hal_btcoex_HaltNotify(padapter); -} - -/* ================================================== */ -/* Below Functions are called by BT-Coex */ -/* ================================================== */ -void rtw_btcoex_reject_ap_aggregated_packet(struct adapter *padapter, u8 enable) -{ - struct mlme_ext_info *pmlmeinfo; - struct sta_info *psta; - - pmlmeinfo = &padapter->mlmeextpriv.mlmext_info; - psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv)); - - if (enable) { - pmlmeinfo->accept_addba_req = false; - if (psta) - send_delba(padapter, 0, psta->hwaddr); - } else { - pmlmeinfo->accept_addba_req = true; - } -} - -void rtw_btcoex_lps_enter(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv; - u8 lps_val; - - pwrpriv = adapter_to_pwrctl(padapter); - - pwrpriv->bpower_saving = true; - lps_val = hal_btcoex_LpsVal(padapter); - rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, lps_val, "BTCOEX"); -} - -void rtw_btcoex_lps_leave(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv; - - pwrpriv = adapter_to_pwrctl(padapter); - - if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) { - rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "BTCOEX"); - LPS_RF_ON_check(padapter, 100); - pwrpriv->bpower_saving = false; - } -} diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c deleted file mode 100644 index ce3dfa1fee26..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c +++ /dev/null @@ -1,1936 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include -#include -#include - -static struct _cmd_callback rtw_cmd_callback[] = { - {READ_MACREG_CMD, NULL}, /*0*/ - {WRITE_MACREG_CMD, NULL}, - {READ_BBREG_CMD, &rtw_getbbrfreg_cmdrsp_callback}, - {WRITE_BBREG_CMD, NULL}, - {READ_RFREG_CMD, &rtw_getbbrfreg_cmdrsp_callback}, - {WRITE_RFREG_CMD, NULL}, /*5*/ - {READ_EEPROM_CMD, NULL}, - {WRITE_EEPROM_CMD, NULL}, - {READ_EFUSE_CMD, NULL}, - {WRITE_EFUSE_CMD, NULL}, - - {READ_CAM_CMD, NULL}, /*10*/ - {WRITE_CAM_CMD, NULL}, - {SET_BCNITV_CMD, NULL}, - {SET_MBIDCFG_CMD, NULL}, - {JOIN_BSS_CMD, &rtw_joinbss_cmd_callback}, /*14*/ - {DISCONNECT_CMD, &rtw_disassoc_cmd_callback}, /*15*/ - {CREATE_BSS_CMD, &rtw_createbss_cmd_callback}, - {SET_OP_MODE_CMD, NULL}, - {SITE_SURVEY_CMD, &rtw_survey_cmd_callback}, /*18*/ - {SET_AUTH_CMD, NULL}, - - {SET_KEY_CMD, NULL}, /*20*/ - {SET_STA_KEY_CMD, &rtw_setstaKey_cmdrsp_callback}, - {SET_ASSOC_STA_CMD, &rtw_setassocsta_cmdrsp_callback}, - {DEL_ASSOC_STA_CMD, NULL}, - {SET_STA_PWR_STATE_CMD, NULL}, - {SET_BASIC_RATE_CMD, NULL}, /*25*/ - {GET_BASIC_RATE_CMD, NULL}, - {SET_DATA_RATE_CMD, NULL}, - {GET_DATA_RATE_CMD, NULL}, - {SET_PHY_INFO_CMD, NULL}, - - {GET_PHY_INFO_CMD, NULL}, /*30*/ - {SET_PHY_CMD, NULL}, - {GET_PHY_CMD, NULL}, - {READ_RSSI_CMD, NULL}, - {READ_GAIN_CMD, NULL}, - {SET_ATIM_CMD, NULL}, /*35*/ - {SET_PWR_MODE_CMD, NULL}, - {JOIN_BSS_RPT_CMD, NULL}, - {SET_RA_TABLE_CMD, NULL}, - {GET_RA_TABLE_CMD, NULL}, - - {GET_CCX_REPORT_CMD, NULL}, /*40*/ - {GET_DTM_REPORT_CMD, NULL}, - {GET_TX_RATE_STATISTICS_CMD, NULL}, - {SET_USB_SUSPEND_CMD, NULL}, - {SET_H2C_LBK_CMD, NULL}, - {ADD_BA_REQ_CMD, NULL}, /*45*/ - {SET_CHANNEL_CMD, NULL}, /*46*/ - {SET_TX_POWER_CMD, NULL}, - {SWITCH_ANTENNA_CMD, NULL}, - {SET_CRYSTAL_CAP_CMD, NULL}, - {SET_SINGLE_CARRIER_TX_CMD, NULL}, /*50*/ - - {SET_SINGLE_TONE_TX_CMD, NULL}, /*51*/ - {SET_CARRIER_SUPPRESSION_TX_CMD, NULL}, - {SET_CONTINUOUS_TX_CMD, NULL}, - {SWITCH_BANDWIDTH_CMD, NULL}, /*54*/ - {TX_BEACON_CMD, NULL},/*55*/ - - {SET_MLME_EVT_CMD, NULL},/*56*/ - {SET_DRV_EXTRA_CMD, NULL},/*57*/ - {SET_H2C_MSG_CMD, NULL},/*58*/ - {SET_CHANNEL_PLAN_CMD, NULL},/*59*/ - - {SET_CHANNEL_SWITCH_CMD, NULL},/*60*/ - {TDLS_CMD, NULL},/*61*/ - {CHK_BMC_SLEEPQ_CMD, NULL}, /*62*/ - - {RUN_IN_THREAD_CMD, NULL},/*63*/ -}; - -static struct cmd_hdl wlancmds[] = { - GEN_DRV_CMD_HANDLER(0, NULL) /*0*/ - GEN_DRV_CMD_HANDLER(0, NULL) - GEN_DRV_CMD_HANDLER(0, NULL) - GEN_DRV_CMD_HANDLER(0, NULL) - GEN_DRV_CMD_HANDLER(0, NULL) - GEN_DRV_CMD_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) /*10*/ - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct joinbss_parm), join_cmd_hdl) /*14*/ - GEN_MLME_EXT_HANDLER(sizeof(struct disconnect_parm), disconnect_hdl) - GEN_MLME_EXT_HANDLER(sizeof(struct createbss_parm), createbss_hdl) - GEN_MLME_EXT_HANDLER(sizeof(struct setopmode_parm), setopmode_hdl) - GEN_MLME_EXT_HANDLER(sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl) /*18*/ - GEN_MLME_EXT_HANDLER(sizeof(struct setauth_parm), setauth_hdl) - GEN_MLME_EXT_HANDLER(sizeof(struct setkey_parm), setkey_hdl) /*20*/ - GEN_MLME_EXT_HANDLER(sizeof(struct set_stakey_parm), set_stakey_hdl) - GEN_MLME_EXT_HANDLER(sizeof(struct set_assocsta_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct del_assocsta_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct setstapwrstate_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct setbasicrate_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct getbasicrate_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct setdatarate_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct getdatarate_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct setphyinfo_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct getphyinfo_parm), NULL) /*30*/ - GEN_MLME_EXT_HANDLER(sizeof(struct setphy_parm), NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct getphy_parm), NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) /*40*/ - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl) - GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl) /* 46 */ - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) /*50*/ - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(0, NULL) - GEN_MLME_EXT_HANDLER(sizeof(struct Tx_Beacon_param), tx_beacon_hdl) /*55*/ - - GEN_MLME_EXT_HANDLER(0, mlme_evt_hdl) /*56*/ - GEN_MLME_EXT_HANDLER(0, rtw_drvextra_cmd_hdl) /*57*/ - - GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/ - GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl) /*59*/ - - GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param), set_csa_hdl) /*60*/ - GEN_MLME_EXT_HANDLER(sizeof(struct TDLSoption_param), tdls_hdl) /*61*/ - GEN_MLME_EXT_HANDLER(0, chk_bmc_sleepq_hdl) /*62*/ - GEN_MLME_EXT_HANDLER(sizeof(struct RunInThread_param), run_in_thread_hdl) /*63*/ -}; - -/* - * Caller and the rtw_cmd_thread can protect cmd_q by spin_lock. - * No irqsave is necessary. - */ - -int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) -{ - init_completion(&pcmdpriv->cmd_queue_comp); - init_completion(&pcmdpriv->terminate_cmdthread_comp); - - INIT_LIST_HEAD(&pcmdpriv->cmd_queue.queue); - spin_lock_init(&pcmdpriv->cmd_queue.lock); - - /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ - - pcmdpriv->cmd_seq = 1; - - pcmdpriv->cmd_allocated_buf = kzalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ, GFP_ATOMIC); - if (!pcmdpriv->cmd_allocated_buf) - return -ENOMEM; - - pcmdpriv->cmd_buf = PTR_ALIGN(pcmdpriv->cmd_allocated_buf, CMDBUFF_ALIGN_SZ); - - pcmdpriv->rsp_buf = kzalloc(MAX_RSPSZ, GFP_ATOMIC); - if (!pcmdpriv->rsp_buf) { - kfree(pcmdpriv->cmd_allocated_buf); - return -ENOMEM; - } - - pcmdpriv->cmd_issued_cnt = 0; - pcmdpriv->cmd_done_cnt = 0; - pcmdpriv->rsp_cnt = 0; - - mutex_init(&pcmdpriv->sctx_mutex); - - return 0; -} - -static void c2h_wk_callback(struct work_struct *work); -int rtw_init_evt_priv(struct evt_priv *pevtpriv) -{ - /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ - atomic_set(&pevtpriv->event_seq, 0); - pevtpriv->evt_done_cnt = 0; - - _init_workitem(&pevtpriv->c2h_wk, c2h_wk_callback, NULL); - pevtpriv->c2h_wk_alive = false; - pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN + 1); - if (!pevtpriv->c2h_queue) - return -ENOMEM; - - return 0; -} - -void _rtw_free_evt_priv(struct evt_priv *pevtpriv) -{ - _cancel_workitem_sync(&pevtpriv->c2h_wk); - while (pevtpriv->c2h_wk_alive) - fsleep(10 * USEC_PER_MSEC); - - while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) { - void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue); - - if (c2h && c2h != (void *)pevtpriv) - kfree(c2h); - } - kfree(pevtpriv->c2h_queue); -} - -void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv) -{ - if (pcmdpriv) { - kfree(pcmdpriv->cmd_allocated_buf); - - kfree(pcmdpriv->rsp_buf); - - mutex_destroy(&pcmdpriv->sctx_mutex); - } -} - -/* - * Calling Context: - * - * rtw_enqueue_cmd can only be called between kernel thread, - * since only spin_lock is used. - * - * ISR/Call-Back functions can't call this sub-function. - * - */ - -static int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj) -{ - unsigned long irqL; - - if (!obj) - return 0; - - /* spin_lock_bh(&queue->lock); */ - spin_lock_irqsave(&queue->lock, irqL); - - list_add_tail(&obj->list, &queue->queue); - - /* spin_unlock_bh(&queue->lock); */ - spin_unlock_irqrestore(&queue->lock, irqL); - - return 0; -} - -struct cmd_obj *_rtw_dequeue_cmd(struct __queue *queue) -{ - unsigned long irqL; - struct cmd_obj *obj; - - /* spin_lock_bh(&(queue->lock)); */ - spin_lock_irqsave(&queue->lock, irqL); - if (list_empty(&queue->queue)) { - obj = NULL; - } else { - obj = container_of(get_next(&queue->queue), struct cmd_obj, list); - list_del_init(&obj->list); - } - - /* spin_unlock_bh(&(queue->lock)); */ - spin_unlock_irqrestore(&queue->lock, irqL); - - return obj; -} - -void rtw_free_evt_priv(struct evt_priv *pevtpriv) -{ - _rtw_free_evt_priv(pevtpriv); -} - -void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv) -{ - _rtw_free_cmd_priv(pcmdpriv); -} - -int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj); -int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj) -{ - bool allow = false; /* set to true to allow enqueuing cmd when hw_init_completed is false */ - - if (cmd_obj->cmdcode == SET_CHANNEL_PLAN_CMD) - allow = true; - - if ((!pcmdpriv->padapter->hw_init_completed && !allow) || - !atomic_read(&pcmdpriv->cmdthd_running)) /* com_thread not running */ - return _FAIL; - - return _SUCCESS; -} - -int rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj) -{ - int res; - struct adapter *padapter = pcmdpriv->padapter; - - if (!cmd_obj) - return _FAIL; - - cmd_obj->padapter = padapter; - - res = rtw_cmd_filter(pcmdpriv, cmd_obj); - if (res == _FAIL) { - rtw_free_cmd_obj(cmd_obj); - return _FAIL; - } - - res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj); - - if (res == 0) { - complete(&pcmdpriv->cmd_queue_comp); - return _SUCCESS; - } - - return _FAIL; -} - -struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv) -{ - return _rtw_dequeue_cmd(&pcmdpriv->cmd_queue); -} - -void rtw_free_cmd_obj(struct cmd_obj *pcmd) -{ - if ((pcmd->cmdcode != JOIN_BSS_CMD) && - (pcmd->cmdcode != CREATE_BSS_CMD)) { - /* free parmbuf in cmd_obj */ - kfree(pcmd->parmbuf); - } - - if (pcmd->rsp) { - if (pcmd->rspsz != 0) { - /* free rsp in cmd_obj */ - kfree(pcmd->rsp); - } - } - - /* free cmd_obj */ - kfree(pcmd); -} - -void rtw_stop_cmd_thread(struct adapter *adapter) -{ - if (adapter->cmdThread && - atomic_read(&adapter->cmdpriv.cmdthd_running) && - adapter->cmdpriv.stop_req == 0) { - adapter->cmdpriv.stop_req = 1; - complete(&adapter->cmdpriv.cmd_queue_comp); - wait_for_completion(&adapter->cmdpriv.terminate_cmdthread_comp); - } -} - -int rtw_cmd_thread(void *context) -{ - u8 ret; - struct cmd_obj *pcmd; - u8 *pcmdbuf; - u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf); - void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd); - struct adapter *padapter = context; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct drvextra_cmd_parm *extra_parm = NULL; - - allow_signal(SIGTERM); - - pcmdbuf = pcmdpriv->cmd_buf; - - pcmdpriv->stop_req = 0; - atomic_set(&pcmdpriv->cmdthd_running, true); - complete(&pcmdpriv->terminate_cmdthread_comp); - - while (1) { - if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp)) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp) return != 0, break\n", - FUNC_ADPT_ARG(padapter)); - break; - } - - if (padapter->driver_stopped || padapter->bSurpriseRemoved) { - netdev_dbg(padapter->pnetdev, - "%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n", - __func__, padapter->driver_stopped, - padapter->bSurpriseRemoved, __LINE__); - break; - } - - if (pcmdpriv->stop_req) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " stop_req:%u, break\n", - FUNC_ADPT_ARG(padapter), - pcmdpriv->stop_req); - break; - } - - if (list_empty(&pcmdpriv->cmd_queue.queue)) - continue; - - if (rtw_register_cmd_alive(padapter) != _SUCCESS) - continue; - -_next: - if (padapter->driver_stopped || padapter->bSurpriseRemoved) { - netdev_dbg(padapter->pnetdev, - "%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n", - __func__, padapter->driver_stopped, - padapter->bSurpriseRemoved, __LINE__); - break; - } - - pcmd = rtw_dequeue_cmd(pcmdpriv); - if (!pcmd) { - rtw_unregister_cmd_alive(padapter); - continue; - } - - if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) { - pcmd->res = H2C_DROPPED; - goto post_process; - } - - pcmdpriv->cmd_issued_cnt++; - - pcmd->cmdsz = round_up((pcmd->cmdsz), 4); - - memcpy(pcmdbuf, pcmd->parmbuf, pcmd->cmdsz); - - if (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) { - cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns; - - if (cmd_hdl) { - ret = cmd_hdl(pcmd->padapter, pcmdbuf); - pcmd->res = ret; - } - - pcmdpriv->cmd_seq++; - } else { - pcmd->res = H2C_PARAMETERS_ERROR; - } - - cmd_hdl = NULL; - -post_process: - - if (mutex_lock_interruptible(&pcmd->padapter->cmdpriv.sctx_mutex) == 0) { - if (pcmd->sctx) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " pcmd->sctx\n", - FUNC_ADPT_ARG(pcmd->padapter)); - - if (pcmd->res == H2C_SUCCESS) - rtw_sctx_done(&pcmd->sctx); - else - rtw_sctx_done_err(&pcmd->sctx, RTW_SCTX_DONE_CMD_ERROR); - } - mutex_unlock(&pcmd->padapter->cmdpriv.sctx_mutex); - } - - /* call callback function for post-processed */ - if (pcmd->cmdcode < ARRAY_SIZE(rtw_cmd_callback)) { - pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback; - if (!pcmd_callback) { - rtw_free_cmd_obj(pcmd); - } else { - /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!= NULL) */ - pcmd_callback(pcmd->padapter, pcmd);/* need consider that free cmd_obj in rtw_cmd_callback */ - } - } else { - rtw_free_cmd_obj(pcmd); - } - flush_signals_thread(); - goto _next; - } - - /* free all cmd_obj resources */ - do { - pcmd = rtw_dequeue_cmd(pcmdpriv); - if (!pcmd) { - rtw_unregister_cmd_alive(padapter); - break; - } - - if (pcmd->cmdcode == SET_DRV_EXTRA_CMD) { - extra_parm = (struct drvextra_cmd_parm *)pcmd->parmbuf; - if (extra_parm->pbuf && extra_parm->size > 0) - kfree(extra_parm->pbuf); - } - - rtw_free_cmd_obj(pcmd); - } while (1); - - complete(&pcmdpriv->terminate_cmdthread_comp); - atomic_set(&pcmdpriv->cmdthd_running, false); - - return 0; -} - -/* - * rtw_sitesurvey_cmd(~) - * ### NOTE:#### (!!!!) - * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock - */ - -u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num, - struct rtw_ieee80211_channel *ch, int ch_num) -{ - u8 res = _FAIL; - struct cmd_obj *ph2c; - struct sitesurvey_parm *survey_para; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1); - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) - return _FAIL; - - survey_para = kzalloc_obj(*survey_para, GFP_ATOMIC); - if (!survey_para) { - kfree(ph2c); - return _FAIL; - } - - rtw_free_network_queue(padapter, false); - - init_h2fwcmd_w_parm_no_rsp(ph2c, survey_para, SITE_SURVEY_CMD); - - /* psurveyPara->bsslimit = 48; */ - survey_para->scan_mode = pmlmepriv->scan_mode; - - /* prepare ssid list */ - if (ssid) { - int i; - - for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) { - if (ssid[i].ssid_length) { - memcpy(&survey_para->ssid[i], &ssid[i], sizeof(struct ndis_802_11_ssid)); - survey_para->ssid_num++; - } - } - } - - /* prepare channel list */ - if (ch) { - int i; - - for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) { - if (ch[i].hw_value && !(ch[i].flags & RTW_IEEE80211_CHAN_DISABLED)) { - memcpy(&survey_para->ch[i], &ch[i], sizeof(struct rtw_ieee80211_channel)); - survey_para->ch_num++; - } - } - } - - set_fwstate(pmlmepriv, _FW_UNDER_SURVEY); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - - if (res == _SUCCESS) { - pmlmepriv->scan_start_time = jiffies; - _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT); - } else { - _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); - } - return res; -} - -void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - /* rtw_free_cmd_obj(pcmd); */ - kfree(pcmd->parmbuf); - kfree(pcmd); -} - -u8 rtw_createbss_cmd(struct adapter *padapter) -{ - struct cmd_obj *pcmd; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct wlan_bssid_ex *pdev_network = &padapter->registrypriv.dev_network; - u8 res = _SUCCESS; - - pcmd = kzalloc_obj(*pcmd, GFP_ATOMIC); - if (!pcmd) { - res = _FAIL; - goto exit; - } - - INIT_LIST_HEAD(&pcmd->list); - pcmd->cmdcode = CREATE_BSS_CMD; - pcmd->parmbuf = (unsigned char *)pdev_network; - pcmd->cmdsz = get_wlan_bssid_ex_sz((struct wlan_bssid_ex *)pdev_network); - pcmd->rsp = NULL; - pcmd->rspsz = 0; - - pdev_network->length = pcmd->cmdsz; - - res = rtw_enqueue_cmd(pcmdpriv, pcmd); - -exit: - return res; -} - -int rtw_startbss_cmd(struct adapter *padapter, int flags) -{ - struct cmd_obj *pcmd; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct submit_ctx sctx; - int res = _SUCCESS; - - if (flags & RTW_CMDF_DIRECTLY) { - /* no need to enqueue, do the cmd hdl directly and free cmd parameter */ - start_bss_network(padapter); - } else { - /* need enqueue, prepare cmd_obj and enqueue */ - pcmd = kzalloc_obj(*pcmd); - if (!pcmd) { - res = _FAIL; - goto exit; - } - - INIT_LIST_HEAD(&pcmd->list); - pcmd->cmdcode = CREATE_BSS_CMD; - pcmd->parmbuf = NULL; - pcmd->cmdsz = 0; - pcmd->rsp = NULL; - pcmd->rspsz = 0; - - if (flags & RTW_CMDF_WAIT_ACK) { - pcmd->sctx = &sctx; - rtw_sctx_init(&sctx, 2000); - } - - res = rtw_enqueue_cmd(pcmdpriv, pcmd); - - if (res == _SUCCESS && (flags & RTW_CMDF_WAIT_ACK)) { - rtw_sctx_wait(&sctx); - if (mutex_lock_interruptible(&pcmdpriv->sctx_mutex) == 0) { - if (sctx.status == RTW_SCTX_SUBMITTED) - pcmd->sctx = NULL; - mutex_unlock(&pcmdpriv->sctx_mutex); - } - } - } - -exit: - return res; -} - -u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork) -{ - u8 res = _SUCCESS; - unsigned int t_len = 0; - struct wlan_bssid_ex *psecnetwork; - struct cmd_obj *pcmd; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct qos_priv *pqospriv = &pmlmepriv->qospriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - enum nl80211_iftype ndis_network_mode = pnetwork->network.infrastructure_mode; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u32 tmp_len; - u8 *ptmp = NULL; - - pcmd = kzalloc_obj(*pcmd); - if (!pcmd) { - res = _FAIL; - goto exit; - } - /* for ies is fix buf size */ - t_len = sizeof(struct wlan_bssid_ex); - - /* for hidden ap to set fw_state here */ - if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE)) { - switch (ndis_network_mode) { - case NL80211_IFTYPE_ADHOC: - set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); - break; - - case NL80211_IFTYPE_STATION: - set_fwstate(pmlmepriv, WIFI_STATION_STATE); - break; - - default: - break; - } - } - - psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss; - - memset(psecnetwork, 0, t_len); - - memcpy(psecnetwork, &pnetwork->network, get_wlan_bssid_ex_sz(&pnetwork->network)); - - psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->ie_length; - - if ((psecnetwork->ie_length - 12) < (256 - 1)) - memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->ies[12], psecnetwork->ie_length - 12); - else - memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->ies[12], (256 - 1)); - - psecnetwork->ie_length = 0; - /* Added by Albert 2009/02/18 */ - /* If the driver wants to use the bssid to create the connection. */ - /* If not, we have to copy the connecting AP's MAC address to it so that */ - /* the driver just has the bssid information for PMKIDList searching. */ - - if (!pmlmepriv->assoc_by_bssid) - memcpy(&pmlmepriv->assoc_bssid[0], &pnetwork->network.mac_address[0], ETH_ALEN); - - psecnetwork->ie_length = rtw_restruct_sec_ie(padapter, - &pnetwork->network.ies[0], - &psecnetwork->ies[0], - pnetwork->network.ie_length); - - pqospriv->qos_option = 0; - - if (pregistrypriv->wmm_enable) { - tmp_len = rtw_restruct_wmm_ie(padapter, - &pnetwork->network.ies[0], - &psecnetwork->ies[0], - pnetwork->network.ie_length, - psecnetwork->ie_length); - - if (psecnetwork->ie_length != tmp_len) { - psecnetwork->ie_length = tmp_len; - pqospriv->qos_option = 1; /* There is WMM IE in this corresp. beacon */ - } else { - pqospriv->qos_option = 0;/* There is no WMM IE in this corresp. beacon */ - } - } - - phtpriv->ht_option = false; - ptmp = rtw_get_ie(&pnetwork->network.ies[12], WLAN_EID_HT_CAPABILITY, &tmp_len, - pnetwork->network.ie_length - 12); - - if (pregistrypriv->ht_enable && ptmp && tmp_len > 0) { - /* Added by Albert 2010/06/23 */ - /* For the WEP mode, we will use the bg mode to do the connection to avoid some IOT issue. */ - /* Especially for Realtek 8192u SoftAP. */ - if ((padapter->securitypriv.dot11_privacy_algrthm != _WEP40_) && - (padapter->securitypriv.dot11_privacy_algrthm != _WEP104_) && - (padapter->securitypriv.dot11_privacy_algrthm != _TKIP_)) { - rtw_ht_use_default_setting(padapter); - - rtw_build_wmm_ie_ht(padapter, &psecnetwork->ies[12], &psecnetwork->ie_length); - - /* rtw_restructure_ht_ie */ - rtw_restructure_ht_ie(padapter, &pnetwork->network.ies[12], &psecnetwork->ies[0], - pnetwork->network.ie_length - 12, &psecnetwork->ie_length, - pnetwork->network.configuration.ds_config); - } - } - - rtw_append_exented_cap(padapter, &psecnetwork->ies[0], &psecnetwork->ie_length); - - pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->network.ies, pnetwork->network.ie_length); - - pcmd->cmdsz = get_wlan_bssid_ex_sz(psecnetwork);/* get cmdsz before endian conversion */ - - INIT_LIST_HEAD(&pcmd->list); - pcmd->cmdcode = JOIN_BSS_CMD; - pcmd->parmbuf = (unsigned char *)psecnetwork; - pcmd->rsp = NULL; - pcmd->rspsz = 0; - - res = rtw_enqueue_cmd(pcmdpriv, pcmd); - -exit: - return res; -} - -u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue) /* for sta_mode */ -{ - struct cmd_obj *cmdobj = NULL; - struct disconnect_parm *param = NULL; - struct cmd_priv *cmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - /* prepare cmd parameter */ - param = kzalloc_obj(*param); - if (!param) { - res = _FAIL; - goto exit; - } - param->deauth_timeout_ms = deauth_timeout_ms; - - if (enqueue) { - /* need enqueue, prepare cmd_obj and enqueue */ - cmdobj = kzalloc_obj(*cmdobj); - if (!cmdobj) { - res = _FAIL; - kfree(param); - goto exit; - } - init_h2fwcmd_w_parm_no_rsp(cmdobj, param, DISCONNECT_CMD); - res = rtw_enqueue_cmd(cmdpriv, cmdobj); - } else { - /* no need to enqueue, do the cmd hdl directly and free cmd parameter */ - if (disconnect_hdl(padapter, (u8 *)param) != H2C_SUCCESS) - res = _FAIL; - kfree(param); - } - -exit: - return res; -} - -u8 rtw_setopmode_cmd(struct adapter *padapter, enum nl80211_iftype networktype, bool enqueue) -{ - struct cmd_obj *ph2c; - struct setopmode_parm *psetop; - - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - psetop = kzalloc_obj(*psetop); - if (!psetop) { - res = _FAIL; - goto exit; - } - psetop->mode = (u8)networktype; - - if (enqueue) { - ph2c = kzalloc_obj(*ph2c); - if (!ph2c) { - kfree(psetop); - res = _FAIL; - goto exit; - } - - init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, SET_OP_MODE_CMD); - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - } else { - setopmode_hdl(padapter, (u8 *)psetop); - kfree(psetop); - } -exit: - return res; -} - -u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue) -{ - struct cmd_obj *ph2c; - struct set_stakey_parm *psetstakey_para; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct set_stakey_rsp *psetstakey_rsp = NULL; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - u8 res = _SUCCESS; - - psetstakey_para = kzalloc_obj(*psetstakey_para); - if (!psetstakey_para) { - res = _FAIL; - goto exit; - } - - memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) - psetstakey_para->algorithm = (unsigned char)psecuritypriv->dot11_privacy_algrthm; - else - GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false); - - if (unicast_key) - memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16); - else - memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16); - - /* jeff: set this because at least sw key is ready */ - padapter->securitypriv.busetkipkey = true; - - if (enqueue) { - ph2c = kzalloc_obj(*ph2c); - if (!ph2c) { - kfree_sensitive(psetstakey_para); - res = _FAIL; - goto exit; - } - - psetstakey_rsp = kzalloc_obj(*psetstakey_rsp); - if (!psetstakey_rsp) { - kfree(ph2c); - kfree_sensitive(psetstakey_para); - res = _FAIL; - goto exit; - } - - init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, SET_STA_KEY_CMD); - ph2c->rsp = (u8 *)psetstakey_rsp; - ph2c->rspsz = sizeof(struct set_stakey_rsp); - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - } else { - set_stakey_hdl(padapter, (u8 *)psetstakey_para); - kfree_sensitive(psetstakey_para); - } -exit: - return res; -} - -u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue) -{ - struct cmd_obj *ph2c; - struct set_stakey_parm *psetstakey_para; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct set_stakey_rsp *psetstakey_rsp = NULL; - s16 cam_id = 0; - u8 res = _SUCCESS; - - if (!enqueue) { - while ((cam_id = rtw_camid_search(padapter, sta->hwaddr, -1)) >= 0) { - netdev_dbg(padapter->pnetdev, - "clear key for addr:%pM, camid:%d\n", - sta->hwaddr, cam_id); - clear_cam_entry(padapter, cam_id); - rtw_camid_free(padapter, cam_id); - } - } else { - ph2c = kzalloc_obj(*ph2c); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - psetstakey_para = kzalloc_obj(*psetstakey_para); - if (!psetstakey_para) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - psetstakey_rsp = kzalloc_obj(*psetstakey_rsp); - if (!psetstakey_rsp) { - kfree(ph2c); - kfree_sensitive(psetstakey_para); - res = _FAIL; - goto exit; - } - - init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, SET_STA_KEY_CMD); - ph2c->rsp = (u8 *)psetstakey_rsp; - ph2c->rspsz = sizeof(struct set_stakey_rsp); - - memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN); - - psetstakey_para->algorithm = _NO_PRIVACY_; - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - } -exit: - return res; -} - -u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr) -{ - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct cmd_obj *ph2c; - struct addBaReq_parm *paddbareq_parm; - - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - paddbareq_parm = kzalloc_obj(*paddbareq_parm, GFP_ATOMIC); - if (!paddbareq_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - paddbareq_parm->tid = tid; - memcpy(paddbareq_parm->addr, addr, ETH_ALEN); - - init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm, ADD_BA_REQ_CMD); - - /* rtw_enqueue_cmd(pcmdpriv, ph2c); */ - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - return res; -} - -u8 rtw_reset_securitypriv_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = RESET_SECURITYPRIV; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - /* rtw_enqueue_cmd(pcmdpriv, ph2c); */ - res = rtw_enqueue_cmd(pcmdpriv, ph2c); -exit: - return res; -} - -u8 rtw_free_assoc_resources_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = FREE_ASSOC_RESOURCES; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - /* rtw_enqueue_cmd(pcmdpriv, ph2c); */ - res = rtw_enqueue_cmd(pcmdpriv, ph2c); -exit: - return res; -} - -u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - /* only primary padapter does this cmd */ - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = DYNAMIC_CHK_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - /* rtw_enqueue_cmd(pcmdpriv, ph2c); */ - res = rtw_enqueue_cmd(pcmdpriv, ph2c); -exit: - return res; -} - -static void collect_traffic_statistics(struct adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - - /* Tx */ - pdvobjpriv->traffic_stat.tx_bytes = padapter->xmitpriv.tx_bytes; - pdvobjpriv->traffic_stat.tx_pkts = padapter->xmitpriv.tx_pkts; - pdvobjpriv->traffic_stat.tx_drop = padapter->xmitpriv.tx_drop; - - /* Rx */ - pdvobjpriv->traffic_stat.rx_bytes = padapter->recvpriv.rx_bytes; - pdvobjpriv->traffic_stat.rx_pkts = padapter->recvpriv.rx_pkts; - pdvobjpriv->traffic_stat.rx_drop = padapter->recvpriv.rx_drop; - - /* Calculate throughput in last interval */ - pdvobjpriv->traffic_stat.cur_tx_bytes = pdvobjpriv->traffic_stat.tx_bytes - pdvobjpriv->traffic_stat.last_tx_bytes; - pdvobjpriv->traffic_stat.cur_rx_bytes = pdvobjpriv->traffic_stat.rx_bytes - pdvobjpriv->traffic_stat.last_rx_bytes; - pdvobjpriv->traffic_stat.last_tx_bytes = pdvobjpriv->traffic_stat.tx_bytes; - pdvobjpriv->traffic_stat.last_rx_bytes = pdvobjpriv->traffic_stat.rx_bytes; - - pdvobjpriv->traffic_stat.cur_tx_tp = (u32)(pdvobjpriv->traffic_stat.cur_tx_bytes * 8 / 2 / 1024 / 1024); - pdvobjpriv->traffic_stat.cur_rx_tp = (u32)(pdvobjpriv->traffic_stat.cur_rx_bytes * 8 / 2 / 1024 / 1024); -} - -bool traffic_status_watchdog(struct adapter *padapter, bool from_timer) -{ - bool should_enter_ps = false; - u16 busy_threshold_high = 25; - u16 busy_threshold_low = 10; - u16 busy_threshold = busy_threshold_high; - bool busy_traffic = false; - bool tx_busy_traffic = false; - bool rx_busy_traffic = false; - bool higher_busy_traffic = false; - bool higher_busy_rx_traffic = false; - bool higher_busy_tx_traffic = false; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - collect_traffic_statistics(padapter); - - /* */ - /* Determine if our traffic is busy now */ - /* */ - if ((check_fwstate(pmlmepriv, _FW_LINKED)) - /*&& !MgntInitAdapterInProgress(pMgntInfo)*/) { - /* if we raise busy_traffic in last watchdog, using lower threshold. */ - if (pmlmepriv->link_detect_info.busy_traffic) - busy_threshold = busy_threshold_low; - - if (pmlmepriv->link_detect_info.num_rx_ok_in_period > busy_threshold || - pmlmepriv->link_detect_info.num_tx_ok_in_period > busy_threshold) { - busy_traffic = true; - - if (pmlmepriv->link_detect_info.num_rx_ok_in_period > - pmlmepriv->link_detect_info.num_tx_ok_in_period) - rx_busy_traffic = true; - else - tx_busy_traffic = true; - } - - /* Higher Tx/Rx data. */ - if (pmlmepriv->link_detect_info.num_rx_ok_in_period > 4000 || - pmlmepriv->link_detect_info.num_tx_ok_in_period > 4000) { - higher_busy_traffic = true; - - if (pmlmepriv->link_detect_info.num_rx_ok_in_period > - pmlmepriv->link_detect_info.num_tx_ok_in_period) - higher_busy_rx_traffic = true; - else - higher_busy_tx_traffic = true; - } - - /* check traffic for powersaving. */ - if (((pmlmepriv->link_detect_info.num_rx_unicast_ok_in_period + - pmlmepriv->link_detect_info.num_tx_ok_in_period) > 8) || - (pmlmepriv->link_detect_info.num_rx_unicast_ok_in_period > 2)) { - should_enter_ps = false; - - if (busy_traffic) { - if (pmlmepriv->link_detect_info.traffic_transition_count <= 4) - pmlmepriv->link_detect_info.traffic_transition_count = 4; - - pmlmepriv->link_detect_info.traffic_transition_count++; - - if (pmlmepriv->link_detect_info.traffic_transition_count > 30) - pmlmepriv->link_detect_info.traffic_transition_count = 30; - } - } else { - if (pmlmepriv->link_detect_info.traffic_transition_count >= 2) - pmlmepriv->link_detect_info.traffic_transition_count -= 2; - else - pmlmepriv->link_detect_info.traffic_transition_count = 0; - - if (pmlmepriv->link_detect_info.traffic_transition_count == 0) - should_enter_ps = true; - } - - /* LeisurePS only work in infra mode. */ - if (should_enter_ps) { - if (!from_timer) - LPS_Enter(padapter, "TRAFFIC_IDLE"); - } else { - if (!from_timer) - LPS_Leave(padapter, "TRAFFIC_BUSY"); - else - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_TRAFFIC_BUSY, 1); - } - } else { - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - int n_assoc_iface = 0; - - if (check_fwstate(&dvobj->padapters->mlmepriv, WIFI_ASOC_STATE)) - n_assoc_iface++; - - if (!from_timer && n_assoc_iface == 0) - LPS_Leave(padapter, "NON_LINKED"); - } - - pmlmepriv->link_detect_info.num_rx_ok_in_period = 0; - pmlmepriv->link_detect_info.num_tx_ok_in_period = 0; - pmlmepriv->link_detect_info.num_rx_unicast_ok_in_period = 0; - pmlmepriv->link_detect_info.busy_traffic = busy_traffic; - pmlmepriv->link_detect_info.tx_busy_traffic = tx_busy_traffic; - pmlmepriv->link_detect_info.rx_busy_traffic = rx_busy_traffic; - pmlmepriv->link_detect_info.higher_busy_traffic = higher_busy_traffic; - pmlmepriv->link_detect_info.higher_busy_rx_traffic = higher_busy_rx_traffic; - pmlmepriv->link_detect_info.higher_busy_tx_traffic = higher_busy_tx_traffic; - - return should_enter_ps; -} - -static void dynamic_chk_wk_hdl(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv; - - pmlmepriv = &padapter->mlmepriv; - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - expire_timeout_chk(padapter); - - /* for debug purpose */ - _linked_info_dump(padapter); - /* if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING|_FW_UNDER_SURVEY) ==false) */ - { - linked_status_chk(padapter); - traffic_status_watchdog(padapter, false); - } - rtw_hal_dm_watchdog(padapter); - - /* check_hw_pbc(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type); */ - - /* */ - /* BT-Coexist */ - /* */ - hal_btcoex_Handler(padapter); - - /* always call rtw_ps_processor() at last one. */ - rtw_ps_processor(padapter); -} - -void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type); -void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - u8 mstatus; - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - return; - } - - switch (lps_ctrl_type) { - case LPS_CTRL_SCAN: - hal_btcoex_ScanNotify(padapter, true); - - if (check_fwstate(pmlmepriv, _FW_LINKED)) { - /* connect */ - LPS_Leave(padapter, "LPS_CTRL_SCAN"); - } - break; - case LPS_CTRL_JOINBSS: - LPS_Leave(padapter, "LPS_CTRL_JOINBSS"); - break; - case LPS_CTRL_CONNECT: - mstatus = 1;/* connect */ - /* Reset LPS Setting */ - pwrpriv->LpsIdleCount = 0; - rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus)); - rtw_btcoex_media_status_notify(padapter, mstatus); - break; - case LPS_CTRL_DISCONNECT: - mstatus = 0;/* disconnect */ - rtw_btcoex_media_status_notify(padapter, mstatus); - LPS_Leave(padapter, "LPS_CTRL_DISCONNECT"); - rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus)); - break; - case LPS_CTRL_SPECIAL_PACKET: - pwrpriv->delay_lps_last_time_stamp = jiffies; - hal_btcoex_SpecialPacketNotify(padapter, PACKET_DHCP); - LPS_Leave(padapter, "LPS_CTRL_SPECIAL_PACKET"); - break; - case LPS_CTRL_LEAVE: - LPS_Leave(padapter, "LPS_CTRL_LEAVE"); - break; - case LPS_CTRL_TRAFFIC_BUSY: - LPS_Leave(padapter, "LPS_CTRL_TRAFFIC_BUSY"); - break; - default: - break; - } -} - -u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - /* struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); */ - u8 res = _SUCCESS; - - if (enqueue) { - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, - GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = LPS_CTRL_WK_CID; - pdrvextra_cmd_parm->type = lps_ctrl_type; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - } else { - lps_ctrl_wk_hdl(padapter, lps_ctrl_type); - } - -exit: - return res; -} - -static void rtw_dm_in_lps_hdl(struct adapter *padapter) -{ - rtw_hal_set_hwreg(padapter, HW_VAR_DM_IN_LPS, NULL); -} - -u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = DM_IN_LPS_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - return res; -} - -static void rtw_lps_change_dtim_hdl(struct adapter *padapter, u8 dtim) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - if (dtim <= 0 || dtim > 16) - return; - - if (hal_btcoex_IsBtControlLps(padapter)) - return; - - mutex_lock(&pwrpriv->lock); - - pwrpriv->dtim = dtim; - - if (pwrpriv->fw_current_in_ps_mode && (pwrpriv->pwr_mode > PS_MODE_ACTIVE)) { - u8 ps_mode = pwrpriv->pwr_mode; - - rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode)); - } - - mutex_unlock(&pwrpriv->lock); -} - -static void rtw_dm_ra_mask_hdl(struct adapter *padapter, struct sta_info *psta) -{ - if (psta) - set_sta_rate(padapter, psta); -} - -u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = DM_RA_MSK_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = psta; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - - return res; -} - -u8 rtw_ps_cmd(struct adapter *padapter) -{ - struct cmd_obj *ppscmd; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ppscmd = kzalloc_obj(*ppscmd, GFP_ATOMIC); - if (!ppscmd) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ppscmd); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ppscmd); - -exit: - return res; -} - -u32 g_wait_hiq_empty; - -static void rtw_chk_hi_queue_hdl(struct adapter *padapter) -{ - struct sta_info *psta_bmc; - struct sta_priv *pstapriv = &padapter->stapriv; - unsigned long start = jiffies; - u8 empty = false; - - psta_bmc = rtw_get_bcmc_stainfo(padapter); - if (!psta_bmc) - return; - - rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty); - - while (!empty && jiffies_to_msecs(jiffies - start) < g_wait_hiq_empty) { - fsleep(100 * USEC_PER_MSEC); - rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty); - } - - if (psta_bmc->sleepq_len == 0) { - if (empty == _SUCCESS) { - bool update_tim = false; - - if (pstapriv->tim_bitmap & BIT(0)) - update_tim = true; - - pstapriv->tim_bitmap &= ~BIT(0); - pstapriv->sta_dz_bitmap &= ~BIT(0); - - if (update_tim) - update_beacon(padapter, WLAN_EID_TIM, true); - } else {/* re check again */ - rtw_chk_hi_queue_cmd(padapter); - } - } -} - -u8 rtw_chk_hi_queue_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = CHECK_HIQ_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = 0; - pdrvextra_cmd_parm->pbuf = NULL; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - return res; -} - -struct btinfo { - u8 cid; - u8 len; - - u8 bConnection:1; - u8 bSCOeSCO:1; - u8 bInQPage:1; - u8 bACLBusy:1; - u8 bSCOBusy:1; - u8 bHID:1; - u8 bA2DP:1; - u8 bFTP:1; - - u8 retry_cnt:4; - u8 rsvd_34:1; - u8 rsvd_35:1; - u8 rsvd_36:1; - u8 rsvd_37:1; - - u8 rssi; - - u8 rsvd_50:1; - u8 rsvd_51:1; - u8 rsvd_52:1; - u8 rsvd_53:1; - u8 rsvd_54:1; - u8 rsvd_55:1; - u8 eSCO_SCO:1; - u8 Master_Slave:1; - - u8 rsvd_6; - u8 rsvd_7; -}; - -static void rtw_btinfo_hdl(struct adapter *adapter, u8 *buf, u16 buf_len) -{ - #define BTINFO_WIFI_FETCH 0x23 - #define BTINFO_BT_AUTO_RPT 0x27 - struct btinfo *info = (struct btinfo *)buf; - u8 cmd_idx; - u8 len; - - cmd_idx = info->cid; - - if (info->len > buf_len - 2) { - WARN_ON(1); - len = buf_len - 2; - } else { - len = info->len; - } - - /* transform BT-FW btinfo to WiFI-FW C2H format and notify */ - if (cmd_idx == BTINFO_WIFI_FETCH) - buf[1] = 0; - else if (cmd_idx == BTINFO_BT_AUTO_RPT) - buf[1] = 2; - hal_btcoex_BtInfoNotify(adapter, len + 1, &buf[1]); -} - -u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm, GFP_ATOMIC); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = C2H_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = length; - pdrvextra_cmd_parm->pbuf = pbuf; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - return res; -} - -/* do not call R/W in this function, because SDIO interrupt have claim host */ -/* or deadlock will happen and cause special-systemserver-died in android */ -u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt) -{ - struct cmd_obj *ph2c; - struct drvextra_cmd_parm *pdrvextra_cmd_parm; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm = kzalloc_obj(*pdrvextra_cmd_parm); - if (!pdrvextra_cmd_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - pdrvextra_cmd_parm->ec_id = C2H_WK_CID; - pdrvextra_cmd_parm->type = 0; - pdrvextra_cmd_parm->size = c2h_evt ? 16 : 0; - pdrvextra_cmd_parm->pbuf = c2h_evt; - - init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, SET_DRV_EXTRA_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - - return res; -} - -static void c2h_wk_callback(struct work_struct *work) -{ - struct evt_priv *evtpriv = container_of(work, struct evt_priv, c2h_wk); - struct adapter *adapter = container_of(evtpriv, struct adapter, evtpriv); - u8 *c2h_evt; - c2h_id_filter ccx_id_filter = rtw_hal_c2h_id_filter_ccx(adapter); - - evtpriv->c2h_wk_alive = true; - - while (!rtw_cbuf_empty(evtpriv->c2h_queue)) { - c2h_evt = (u8 *)rtw_cbuf_pop(evtpriv->c2h_queue); - if (c2h_evt) { - /* This C2H event is read, clear it */ - c2h_evt_clear(adapter); - } else { - c2h_evt = kmalloc(16, GFP_ATOMIC); - if (c2h_evt) { - /* This C2H event is not read, read & clear now */ - if (c2h_evt_read_88xx(adapter, c2h_evt) != _SUCCESS) { - kfree(c2h_evt); - continue; - } - } else { - continue; - } - } - - /* Special pointer to trigger c2h_evt_clear only */ - if ((void *)c2h_evt == (void *)evtpriv) - continue; - - if (!rtw_hal_c2h_valid(adapter, c2h_evt)) { - kfree(c2h_evt); - continue; - } - - if (ccx_id_filter(c2h_evt)) { - /* Handle CCX report here */ - rtw_hal_c2h_handler(adapter, c2h_evt); - kfree(c2h_evt); - } else { - /* Enqueue into cmd_thread for others */ - rtw_c2h_wk_cmd(adapter, c2h_evt); - } - } - - evtpriv->c2h_wk_alive = false; -} - -u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - struct drvextra_cmd_parm *pdrvextra_cmd; - - if (!pbuf) - return H2C_PARAMETERS_ERROR; - - pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf; - - switch (pdrvextra_cmd->ec_id) { - case DYNAMIC_CHK_WK_CID:/* only primary padapter go to this cmd, but execute dynamic_chk_wk_hdl() for two interfaces */ - dynamic_chk_wk_hdl(padapter); - break; - case POWER_SAVING_CTRL_WK_CID: - rtw_ps_processor(padapter); - break; - case LPS_CTRL_WK_CID: - lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type); - break; - case DM_IN_LPS_WK_CID: - rtw_dm_in_lps_hdl(padapter); - break; - case LPS_CHANGE_DTIM_CID: - rtw_lps_change_dtim_hdl(padapter, (u8)pdrvextra_cmd->type); - break; - case CHECK_HIQ_WK_CID: - rtw_chk_hi_queue_hdl(padapter); - break; - case RESET_SECURITYPRIV: - rtw_reset_securitypriv(padapter); - break; - case FREE_ASSOC_RESOURCES: - rtw_free_assoc_resources(padapter, 1); - break; - case C2H_WK_CID: - rtw_hal_set_hwreg_with_buf(padapter, HW_VAR_C2H_HANDLE, - pdrvextra_cmd->pbuf, pdrvextra_cmd->size); - break; - case DM_RA_MSK_WK_CID: - rtw_dm_ra_mask_hdl(padapter, (struct sta_info *)pdrvextra_cmd->pbuf); - break; - case BTINFO_WK_CID: - rtw_btinfo_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->size); - break; - default: - break; - } - - if (pdrvextra_cmd->pbuf && pdrvextra_cmd->size > 0) - kfree(pdrvextra_cmd->pbuf); - - return H2C_SUCCESS; -} - -void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (pcmd->res != H2C_SUCCESS) { - /* TODO: cancel timer and do timeout handler directly... */ - _set_timer(&pmlmepriv->scan_to_timer, 1); - } - - /* free cmd */ - rtw_free_cmd_obj(pcmd); -} - -void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (pcmd->res != H2C_SUCCESS) { - spin_lock_bh(&pmlmepriv->lock); - set_fwstate(pmlmepriv, _FW_LINKED); - spin_unlock_bh(&pmlmepriv->lock); - - return; - } - /* free cmd */ - rtw_free_cmd_obj(pcmd); -} - -void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (pcmd->res != H2C_SUCCESS) { - /* TODO: cancel timer and do timeout handler directly... */ - _set_timer(&pmlmepriv->assoc_timer, 1); - } - - rtw_free_cmd_obj(pcmd); -} - -void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - struct sta_info *psta = NULL; - struct wlan_network *pwlan = NULL; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf; - struct wlan_network *tgt_network = &pmlmepriv->cur_network; - - if (!pcmd->parmbuf) - goto exit; - - if (pcmd->res != H2C_SUCCESS) - _set_timer(&pmlmepriv->assoc_timer, 1); - - timer_delete_sync(&pmlmepriv->assoc_timer); - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - psta = rtw_get_stainfo(&padapter->stapriv, pnetwork->mac_address); - if (!psta) { - psta = rtw_alloc_stainfo(&padapter->stapriv, pnetwork->mac_address); - if (!psta) - goto createbss_cmd_fail; - } - - rtw_indicate_connect(padapter); - } else { - pwlan = rtw_alloc_network(pmlmepriv); - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - if (!pwlan) { - pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue); - if (!pwlan) { - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - goto createbss_cmd_fail; - } - pwlan->last_scanned = jiffies; - } else { - list_add_tail(&pwlan->list, &pmlmepriv->scanned_queue.queue); - } - - pnetwork->length = get_wlan_bssid_ex_sz(pnetwork); - memcpy(&pwlan->network, pnetwork, pnetwork->length); - /* pwlan->fixed = true; */ - - /* list_add_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue); */ - - /* copy pdev_network information to pmlmepriv->cur_network */ - memcpy(&tgt_network->network, pnetwork, (get_wlan_bssid_ex_sz(pnetwork))); - - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - /* we will set _FW_LINKED when there is one more sat to join us (rtw_stassoc_event_callback) */ - } - -createbss_cmd_fail: - - spin_unlock_bh(&pmlmepriv->lock); -exit: - rtw_free_cmd_obj(pcmd); -} - -void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *)(pcmd->rsp); - struct sta_info *psta = rtw_get_stainfo(pstapriv, psetstakey_rsp->addr); - - if (!psta) - goto exit; - -exit: - rtw_free_cmd_obj(pcmd); -} - -void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct set_assocsta_parm *passocsta_parm = (struct set_assocsta_parm *)(pcmd->parmbuf); - struct set_assocsta_rsp *passocsta_rsp = (struct set_assocsta_rsp *)(pcmd->rsp); - struct sta_info *psta = rtw_get_stainfo(pstapriv, passocsta_parm->addr); - - if (!psta) - goto exit; - - psta->aid = passocsta_rsp->cam_id; - psta->mac_id = passocsta_rsp->cam_id; - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, WIFI_MP_STATE) && check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - - set_fwstate(pmlmepriv, _FW_LINKED); - spin_unlock_bh(&pmlmepriv->lock); - -exit: - rtw_free_cmd_obj(pcmd); -} diff --git a/drivers/staging/rtl8723bs/core/rtw_efuse.c b/drivers/staging/rtl8723bs/core/rtw_efuse.c deleted file mode 100644 index 168ecb7a998f..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_efuse.c +++ /dev/null @@ -1,253 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include - -/* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */ -u8 -rtw_efuse_calculate_word_counts(u8 word_en) -{ - u8 word_cnts = 0; - - if (!(word_en & BIT(0))) - word_cnts++; /* 0 : write enable */ - if (!(word_en & BIT(1))) - word_cnts++; - if (!(word_en & BIT(2))) - word_cnts++; - if (!(word_en & BIT(3))) - word_cnts++; - return word_cnts; -} - -/*----------------------------------------------------------------------------- - * Function: rtw_efuse_read_1_byte - * - * Overview: Copy from WMAC fot EFUSE read 1 byte. - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - * When Who Remark - * 09/23/2008 MHC Copy from WMAC. - * - */ -u8 rtw_efuse_read_1_byte(struct adapter *Adapter, u16 Address) -{ - u8 Bytetemp = {0x00}; - u8 temp = {0x00}; - u32 k = 0; - u16 contentLen = 0; - - Hal_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, &contentLen); - - if (Address < contentLen) {/* E-fuse 512Byte */ - /* Write E-fuse Register address bit0~7 */ - temp = Address & 0xFF; - rtw_write8(Adapter, EFUSE_CTRL + 1, temp); - Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 2); - /* Write E-fuse Register address bit8~9 */ - temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC); - rtw_write8(Adapter, EFUSE_CTRL + 2, temp); - - /* Write 0x30[31]= 0 */ - Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 3); - temp = Bytetemp & 0x7F; - rtw_write8(Adapter, EFUSE_CTRL + 3, temp); - - /* Wait Write-ready (0x30[31]= 1) */ - Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 3); - while (!(Bytetemp & 0x80)) { - Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 3); - k++; - if (k == 1000) - break; - } - return rtw_read8(Adapter, EFUSE_CTRL); - } else { - return 0xFF; - } -} /* rtw_efuse_read_1_byte */ - -/* 11/16/2008 MH Read one byte from real Efuse. */ -u8 rtw_efuse_one_byte_read(struct adapter *padapter, u16 addr, u8 *data) -{ - u32 tmpidx = 0; - u8 bResult; - u8 readbyte; - - /* <20130121, Kordan> For SMIC EFUSE specificatoin. */ - /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */ - /* PHY_SetMacReg(padapter, 0x34, BIT11, 0); */ - rtw_write16(padapter, 0x34, rtw_read16(padapter, 0x34) & (~BIT(11))); - - /* -----------------e-fuse reg ctrl --------------------------------- */ - /* address */ - rtw_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xff)); - rtw_write8(padapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) | - (rtw_read8(padapter, EFUSE_CTRL + 2) & 0xFC)); - - /* rtw_write8(padapter, EFUSE_CTRL+3, 0x72); read cmd */ - /* Write bit 32 0 */ - readbyte = rtw_read8(padapter, EFUSE_CTRL + 3); - rtw_write8(padapter, EFUSE_CTRL + 3, (readbyte & 0x7f)); - - while (!(0x80 & rtw_read8(padapter, EFUSE_CTRL + 3)) && (tmpidx < 1000)) { - mdelay(1); - tmpidx++; - } - if (tmpidx < 100) { - *data = rtw_read8(padapter, EFUSE_CTRL); - bResult = true; - } else { - *data = 0xff; - bResult = false; - } - - return bResult; -} - -/*----------------------------------------------------------------------------- - * Function: Efuse_ReadAllMap - * - * Overview: Read All Efuse content - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - * When Who Remark - * 11/11/2008 MHC Create Version 0. - * - */ -static void Efuse_ReadAllMap(struct adapter *padapter, u8 efuseType, u8 *Efuse) -{ - u16 mapLen = 0; - - Hal_EfusePowerSwitch(padapter, true); - - Hal_GetEfuseDefinition(padapter, efuseType, TYPE_EFUSE_MAP_LEN, &mapLen); - - Hal_ReadEFuse(padapter, efuseType, 0, mapLen, Efuse); - - Hal_EfusePowerSwitch(padapter, false); -} - -/*----------------------------------------------------------------------------- - * Function: efuse_ShadowRead1Byte - * efuse_ShadowRead2Byte - * efuse_ShadowRead4Byte - * - * Overview: Read from efuse init map by one/two/four bytes !!!!! - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - * When Who Remark - * 11/12/2008 MHC Create Version 0. - * - */ -static void efuse_ShadowRead1Byte(struct adapter *padapter, u16 Offset, u8 *Value) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - *Value = pEEPROM->efuse_eeprom_data[Offset]; - -} /* EFUSE_ShadowRead1Byte */ - -/* Read Two Bytes */ -static void efuse_ShadowRead2Byte(struct adapter *padapter, u16 Offset, u16 *Value) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - *Value = pEEPROM->efuse_eeprom_data[Offset]; - *Value |= pEEPROM->efuse_eeprom_data[Offset + 1] << 8; - -} /* EFUSE_ShadowRead2Byte */ - -/* Read Four Bytes */ -static void efuse_ShadowRead4Byte(struct adapter *padapter, u16 Offset, u32 *Value) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - *Value = pEEPROM->efuse_eeprom_data[Offset]; - *Value |= pEEPROM->efuse_eeprom_data[Offset + 1] << 8; - *Value |= pEEPROM->efuse_eeprom_data[Offset + 2] << 16; - *Value |= pEEPROM->efuse_eeprom_data[Offset + 3] << 24; - -} /* efuse_ShadowRead4Byte */ - -/*----------------------------------------------------------------------------- - * Function: rtw_efuse_shadow_map_update - * - * Overview: Transfer current EFUSE content to shadow init and modify map. - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - * When Who Remark - * 11/13/2008 MHC Create Version 0. - * - */ -void rtw_efuse_shadow_map_update(struct adapter *padapter, u8 efuseType) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - u16 mapLen = 0; - - Hal_GetEfuseDefinition(padapter, efuseType, TYPE_EFUSE_MAP_LEN, &mapLen); - - if (pEEPROM->bautoload_fail_flag) - memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen); - else - Efuse_ReadAllMap(padapter, efuseType, pEEPROM->efuse_eeprom_data); - - /* PlatformMoveMemory((void *)&pHalData->EfuseMap[EFUSE_MODIFY_MAP][0], */ - /* void *)&pHalData->EfuseMap[EFUSE_INIT_MAP][0], mapLen); */ -} /* rtw_efuse_shadow_map_update */ - -/*----------------------------------------------------------------------------- - * Function: rtw_efuse_shadow_read - * - * Overview: Read from efuse init map !!!!! - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - * When Who Remark - * 11/12/2008 MHC Create Version 0. - * - */ -void rtw_efuse_shadow_read(struct adapter *padapter, u8 Type, u16 Offset, u32 *Value) -{ - if (Type == 1) - efuse_ShadowRead1Byte(padapter, Offset, (u8 *)Value); - else if (Type == 2) - efuse_ShadowRead2Byte(padapter, Offset, (u16 *)Value); - else if (Type == 4) - efuse_ShadowRead4Byte(padapter, Offset, (u32 *)Value); - -} /* rtw_efuse_shadow_read*/ diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c deleted file mode 100644 index 66f476a46aad..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c +++ /dev/null @@ -1,1199 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include -#include - -u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 }; -u16 RTW_WPA_VERSION = 1; -u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 }; -u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 }; -u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 }; -u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 }; -u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 }; -u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 }; -u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 }; -u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 }; -u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 }; - -u16 RSN_VERSION_BSD = 1; -u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 }; -u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 }; -u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 }; -u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 }; -u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 }; -u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 }; -u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 }; -u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 }; -/* */ -/* for adhoc-master to generate ie and provide supported-rate to fw */ -/* */ - -static u8 WIFI_CCKRATES[] = { - (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK), - (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK), - (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK), - (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK) -}; - -static u8 WIFI_OFDMRATES[] = { - (IEEE80211_OFDM_RATE_6MB), - (IEEE80211_OFDM_RATE_9MB), - (IEEE80211_OFDM_RATE_12MB), - (IEEE80211_OFDM_RATE_18MB), - (IEEE80211_OFDM_RATE_24MB), - IEEE80211_OFDM_RATE_36MB, - IEEE80211_OFDM_RATE_48MB, - IEEE80211_OFDM_RATE_54MB -}; - -int rtw_get_bit_value_from_ieee_value(u8 val) -{ - static const unsigned char dot11_rate_table[] = { - 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0 - }; /* last element must be zero!! */ - int i = 0; - - while (dot11_rate_table[i] != 0) { - if (dot11_rate_table[i] == val) - return BIT(i); - i++; - } - return 0; -} - -bool rtw_is_cckrates_included(u8 *rate) -{ - while (*rate) { - u8 r = *rate & 0x7f; - - if (r == 2 || r == 4 || r == 11 || r == 22) - return true; - rate++; - } - - return false; -} - -bool rtw_is_cckratesonly_included(u8 *rate) -{ - while (*rate) { - u8 r = *rate & 0x7f; - - if (r != 2 && r != 4 && r != 11 && r != 22) - return false; - rate++; - } - - return true; -} - -int rtw_check_network_type(unsigned char *rate, int channel) -{ - if (channel > 14) - return WIRELESS_INVALID; - /* could be pure B, pure G, or B/G */ - if (rtw_is_cckratesonly_included(rate)) - return WIRELESS_11B; - if (rtw_is_cckrates_included(rate)) - return WIRELESS_11BG; - return WIRELESS_11G; -} - -u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source, - unsigned int *frlen) -{ - memcpy(pbuf, source, len); - *frlen = *frlen + len; - return pbuf + len; -} - -/* rtw_set_ie will update frame length */ -u8 *rtw_set_ie(u8 *pbuf, - signed int index, - uint len, - u8 *source, - uint *frlen) /* frame length */ -{ - *pbuf = (u8)index; - - *(pbuf + 1) = (u8)len; - - if (len > 0) - memcpy(pbuf + 2, source, len); - - *frlen = *frlen + (len + 2); - - return pbuf + len + 2; -} - -/* index: the information element id index, limit is the limit for search */ -u8 *rtw_get_ie(u8 *pbuf, signed int index, signed int *len, signed int limit) -{ - signed int tmp, i; - u8 *p; - - if (limit < 2) - return NULL; - - p = pbuf; - i = 0; - *len = 0; - while (i + 2 <= limit) { - tmp = *(p + 1); - if (i + 2 + tmp > limit) - break; - - if (*p == index) { - *len = tmp; - return p; - } - - p += (tmp + 2); - i += (tmp + 2); - } - return NULL; -} - -/** - * rtw_get_ie_ex - Search specific IE from a series of IEs - * @in_ie: Address of IEs to search - * @in_len: Length limit from in_ie - * @eid: Element ID to match - * @oui: OUI to match - * @oui_len: OUI length - * @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE - * @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE - * - * Returns: The address of the specific IE found, or NULL - */ -u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen) -{ - uint cnt; - u8 *target_ie = NULL; - - if (ielen) - *ielen = 0; - - if (!in_ie || in_len <= 0) - return target_ie; - - cnt = 0; - - while (cnt + 2 <= in_len) { - u8 ie_len = in_ie[cnt + 1]; - - if (cnt + 2 + ie_len > in_len) - break; - - if (eid == in_ie[cnt] && - (!oui || (ie_len >= oui_len && !memcmp(&in_ie[cnt + 2], oui, oui_len)))) { - target_ie = &in_ie[cnt]; - - if (ie) - memcpy(ie, &in_ie[cnt], ie_len + 2); - - if (ielen) - *ielen = ie_len + 2; - - break; - } - cnt += ie_len + 2; /* goto next */ - } - - return target_ie; -} - -/** - * rtw_ies_remove_ie - Find matching IEs and remove - * @ies: Address of IEs to search - * @ies_len: Pointer of length of ies, will update to new length - * @offset: The offset to start search - * @eid: Element ID to match - * @oui: OUI to match - * @oui_len: OUI length - * - * Returns: _SUCCESS: ies is updated, _FAIL: not updated - */ -int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len) -{ - int ret = _FAIL; - u8 *target_ie; - u32 target_ielen; - u8 *start; - uint search_len; - - if (!ies || !ies_len || *ies_len <= offset) - goto exit; - - start = ies + offset; - search_len = *ies_len - offset; - - while (1) { - target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen); - if (target_ie && target_ielen) { - u8 *remain_ies = target_ie + target_ielen; - uint remain_len = search_len - (remain_ies - start); - - memcpy(target_ie, remain_ies, remain_len); - *ies_len = *ies_len - target_ielen; - ret = _SUCCESS; - - start = target_ie; - search_len = remain_len; - } else { - break; - } - } -exit: - return ret; -} - -void rtw_set_supported_rate(u8 *supported_rates, uint mode) -{ - memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX); - - switch (mode) { - case WIRELESS_11B: - memcpy(supported_rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN); - break; - - case WIRELESS_11G: - memcpy(supported_rates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN); - break; - - case WIRELESS_11BG: - case WIRELESS_11G_24N: - case WIRELESS_11_24N: - case WIRELESS_11BG_24N: - memcpy(supported_rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN); - memcpy(supported_rates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN); - break; - } -} - -uint rtw_get_rateset_len(u8 *rateset) -{ - uint i; - - for (i = 0; i < 13; i++) - if (rateset[i] == 0) - break; - return i; -} - -int rtw_generate_ie(struct registry_priv *pregistrypriv) -{ - u8 wireless_mode; - int sz = 0, rate_len; - struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network; - u8 *ie = pdev_network->ies; - - /* timestamp will be inserted by hardware */ - sz += 8; - ie += sz; - - /* beacon interval : 2bytes */ - *(__le16 *)ie = cpu_to_le16((u16)pdev_network->configuration.beacon_period);/* BCN_INTERVAL; */ - sz += 2; - ie += 2; - - /* capability info */ - *(u16 *)ie = 0; - - *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_IBSS); - - if (pregistrypriv->preamble == PREAMBLE_SHORT) - *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); - - if (pdev_network->privacy) - *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); - - sz += 2; - ie += 2; - - /* SSID */ - ie = rtw_set_ie(ie, WLAN_EID_SSID, pdev_network->ssid.ssid_length, pdev_network->ssid.ssid, &sz); - - /* supported rates */ - wireless_mode = pregistrypriv->wireless_mode; - - rtw_set_supported_rate(pdev_network->supported_rates, wireless_mode); - - rate_len = rtw_get_rateset_len(pdev_network->supported_rates); - - if (rate_len > 8) { - ie = rtw_set_ie(ie, WLAN_EID_SUPP_RATES, 8, pdev_network->supported_rates, &sz); - /* ie = rtw_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8), (pdev_network->supported_rates + 8), &sz); */ - } else { - ie = rtw_set_ie(ie, WLAN_EID_SUPP_RATES, rate_len, pdev_network->supported_rates, &sz); - } - - /* DS parameter set */ - ie = rtw_set_ie(ie, WLAN_EID_DS_PARAMS, 1, (u8 *)&(pdev_network->configuration.ds_config), &sz); - - /* IBSS Parameter Set */ - - ie = rtw_set_ie(ie, WLAN_EID_IBSS_PARAMS, 2, (u8 *)&(pdev_network->configuration.atim_window), &sz); - - if (rate_len > 8) - ie = rtw_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8), (pdev_network->supported_rates + 8), &sz); - - /* HT Cap. */ - if ((pregistrypriv->wireless_mode & WIRELESS_11_24N) && - pregistrypriv->ht_enable) { - /* todo: */ - } - - /* pdev_network->ie_length = sz; update ie_length */ - - /* return _SUCCESS; */ - - return sz; -} - -unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit) -{ - int len; - u16 val16; - unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01}; - u8 *pbuf = pie; - int limit_new = limit; - __le16 le_tmp; - - while (1) { - pbuf = rtw_get_ie(pbuf, WLAN_EID_VENDOR_SPECIFIC, &len, limit_new); - - if (pbuf) { - if (len < 6) - goto check_next_ie; - - /* check if oui matches... */ - if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type))) - goto check_next_ie; - - /* check version... */ - memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16)); - - val16 = le16_to_cpu(le_tmp); - if (val16 != 0x0001) - goto check_next_ie; - - *wpa_ie_len = *(pbuf + 1); - - return pbuf; - - } else { - *wpa_ie_len = 0; - return NULL; - } - -check_next_ie: - - limit_new = limit - (pbuf - pie) - 2 - len; - - if (limit_new <= 0) - break; - - pbuf += (2 + len); - } - - *wpa_ie_len = 0; - - return NULL; -} - -unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit) -{ - return rtw_get_ie(pie, WLAN_EID_RSN, rsn_ie_len, limit); -} - -int rtw_get_wpa_cipher_suite(u8 *s) -{ - if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN)) - return WPA_CIPHER_NONE; - if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN)) - return WPA_CIPHER_WEP40; - if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN)) - return WPA_CIPHER_TKIP; - if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN)) - return WPA_CIPHER_CCMP; - if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN)) - return WPA_CIPHER_WEP104; - - return 0; -} - -int rtw_get_wpa2_cipher_suite(u8 *s) -{ - if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN)) - return WPA_CIPHER_NONE; - if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN)) - return WPA_CIPHER_WEP40; - if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN)) - return WPA_CIPHER_TKIP; - if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN)) - return WPA_CIPHER_CCMP; - if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN)) - return WPA_CIPHER_WEP104; - - return 0; -} - -int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x) -{ - int i, ret = _SUCCESS; - int left, count; - u8 *pos; - u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1}; - - if (wpa_ie_len <= 0) { - /* No WPA IE - fail silently */ - return _FAIL; - } - - if ((*wpa_ie != WLAN_EID_VENDOR_SPECIFIC) || - (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) || - (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN))) - return _FAIL; - - pos = wpa_ie; - - pos += 8; - left = wpa_ie_len - 8; - - /* group_cipher */ - if (left >= WPA_SELECTOR_LEN) { - *group_cipher = rtw_get_wpa_cipher_suite(pos); - - pos += WPA_SELECTOR_LEN; - left -= WPA_SELECTOR_LEN; - - } else if (left > 0) { - return _FAIL; - } - - /* pairwise_cipher */ - if (left >= 2) { - /* count = le16_to_cpu(*(u16*)pos); */ - count = get_unaligned_le16(pos); - pos += 2; - left -= 2; - - if (count == 0 || left < count * WPA_SELECTOR_LEN) - return _FAIL; - - for (i = 0; i < count; i++) { - *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos); - - pos += WPA_SELECTOR_LEN; - left -= WPA_SELECTOR_LEN; - } - - } else if (left == 1) { - return _FAIL; - } - - if (is_8021x) { - if (left >= 6) { - pos += 2; - if (!memcmp(pos, SUITE_1X, 4)) - *is_8021x = 1; - } - } - - return ret; -} - -int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x) -{ - int i, ret = _SUCCESS; - int left, count; - u8 *pos; - u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01}; - - if (rsn_ie_len <= 0) { - /* No RSN IE - fail silently */ - return _FAIL; - } - - if ((*rsn_ie != WLAN_EID_RSN) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2))) - return _FAIL; - - pos = rsn_ie; - pos += 4; - left = rsn_ie_len - 4; - - /* group_cipher */ - if (left >= RSN_SELECTOR_LEN) { - *group_cipher = rtw_get_wpa2_cipher_suite(pos); - - pos += RSN_SELECTOR_LEN; - left -= RSN_SELECTOR_LEN; - - } else if (left > 0) { - return _FAIL; - } - - /* pairwise_cipher */ - if (left >= 2) { - /* count = le16_to_cpu(*(u16*)pos); */ - count = get_unaligned_le16(pos); - pos += 2; - left -= 2; - - if (count == 0 || left < count * RSN_SELECTOR_LEN) - return _FAIL; - - for (i = 0; i < count; i++) { - *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos); - - pos += RSN_SELECTOR_LEN; - left -= RSN_SELECTOR_LEN; - } - - } else if (left == 1) { - return _FAIL; - } - - if (is_8021x) { - if (left >= 6) { - pos += 2; - if (!memcmp(pos, SUITE_1X, 4)) - *is_8021x = 1; - } - } - - return ret; -} - -int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len) -{ - int len = 0; - u8 authmode; - uint cnt; - u8 wapi_oui1[4] = {0x0, 0x14, 0x72, 0x01}; - u8 wapi_oui2[4] = {0x0, 0x14, 0x72, 0x02}; - - if (wapi_len) - *wapi_len = 0; - - if (!in_ie || in_len <= 0) - return len; - - cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_); - - while (cnt < in_len) { - if (cnt + 2 > in_len) - break; - if (cnt + 2 + in_ie[cnt + 1] > in_len) - break; - authmode = in_ie[cnt]; - - if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY && - in_ie[cnt + 1] >= 8 && - (!memcmp(&in_ie[cnt + 6], wapi_oui1, 4) || - !memcmp(&in_ie[cnt + 6], wapi_oui2, 4))) { - if (wapi_ie) - memcpy(wapi_ie, &in_ie[cnt], in_ie[cnt + 1] + 2); - - if (wapi_len) - *wapi_len = in_ie[cnt + 1] + 2; - } - - cnt += in_ie[cnt + 1] + 2; /* get next */ - } - - if (wapi_len) - len = *wapi_len; - - return len; -} - -void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len) -{ - u8 authmode; - u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01}; - uint cnt; - - /* Search required WPA or WPA2 IE and copy to sec_ie[ ] */ - - cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_); - - while (cnt < in_len) { - if (cnt + 2 > in_len) - break; - if (cnt + 2 + in_ie[cnt + 1] > in_len) - break; - authmode = in_ie[cnt]; - - if ((authmode == WLAN_EID_VENDOR_SPECIFIC) && - in_ie[cnt + 1] >= 4 && - (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) { - if (wpa_ie) - memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2); - - *wpa_len = in_ie[cnt + 1] + 2; - } else if (authmode == WLAN_EID_RSN) { - if (rsn_ie) - memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2); - - *rsn_len = in_ie[cnt + 1] + 2; - } - - cnt += in_ie[cnt + 1] + 2; /* get next */ - } -} - -/** - * rtw_get_wps_ie - Search WPS IE from a series of IEs - * @in_ie: Address of IEs to search - * @in_len: Length limit from in_ie - * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie - * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE - * - * Returns: The address of the WPS IE found, or NULL - */ -u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen) -{ - uint cnt; - u8 *wpsie_ptr = NULL; - u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; - - if (wps_ielen) - *wps_ielen = 0; - - if (!in_ie || in_len <= 0) - return wpsie_ptr; - - cnt = 0; - - while (cnt < in_len) { - eid = in_ie[cnt]; - - if (cnt + 2 > in_len) - break; - - if (in_ie[cnt + 1] + 2 > in_len - cnt) - break; - - if ((eid == WLAN_EID_VENDOR_SPECIFIC) && (in_ie[cnt + 1] >= 4) && - (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) { - wpsie_ptr = &in_ie[cnt]; - - if (wps_ie) - memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2); - - if (wps_ielen) - *wps_ielen = in_ie[cnt + 1] + 2; - - cnt += in_ie[cnt + 1] + 2; - - break; - } - cnt += in_ie[cnt + 1] + 2; /* goto next */ - } - - return wpsie_ptr; -} - -/** - * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE - * @wps_ie: Address of WPS IE to search - * @wps_ielen: Length limit from wps_ie - * @target_attr_id: The attribute ID of WPS attribute to search - * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr - * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute - * - * Returns: the address of the specific WPS attribute found, or NULL - */ -u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr) -{ - u8 *attr_ptr = NULL; - u8 *target_attr_ptr = NULL; - u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04}; - - if (len_attr) - *len_attr = 0; - - if (wps_ielen < 6) - return attr_ptr; - - if ((wps_ie[0] != WLAN_EID_VENDOR_SPECIFIC) || - (memcmp(wps_ie + 2, wps_oui, 4))) { - return attr_ptr; - } - - /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */ - attr_ptr = wps_ie + 6; /* goto first attr */ - - while (attr_ptr - wps_ie < wps_ielen) { - /* 4 = 2(Attribute ID) + 2(Length) */ - if (attr_ptr + 4 > wps_ie + wps_ielen) - break; - u16 attr_id = get_unaligned_be16(attr_ptr); - u16 attr_data_len = get_unaligned_be16(attr_ptr + 2); - u16 attr_len = attr_data_len + 4; - - if (attr_id == target_attr_id) { - target_attr_ptr = attr_ptr; - - if (buf_attr) - memcpy(buf_attr, attr_ptr, attr_len); - - if (len_attr) - *len_attr = attr_len; - - break; - } - attr_ptr += attr_len; /* goto next */ - } - - return target_attr_ptr; -} - -/** - * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE - * @wps_ie: Address of WPS IE to search - * @wps_ielen: Length limit from wps_ie - * @target_attr_id: The attribute ID of WPS attribute to search - * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content - * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content - * - * Returns: the address of the specific WPS attribute content found, or NULL - */ -u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content) -{ - u8 *attr_ptr; - u32 attr_len; - - if (len_content) - *len_content = 0; - - attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len); - - if (attr_ptr && attr_len) { - if (buf_content) - memcpy(buf_content, attr_ptr + 4, attr_len - 4); - - if (len_content) - *len_content = attr_len - 4; - - return attr_ptr + 4; - } - - return NULL; -} - -static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen, - struct rtw_ieee802_11_elems *elems, - int show_errors) -{ - unsigned int oui; - - /* - * first 3 bytes in vendor specific information element are the IEEE - * OUI of the vendor. The following byte is used a vendor specific - * sub-type. - */ - if (elen < 4) - return -1; - - oui = get_unaligned_be24(pos); - switch (oui) { - case OUI_MICROSOFT: - /* - * Microsoft/Wi-Fi information elements are further typed and - * subtyped - */ - switch (pos[3]) { - case 1: - /* - * Microsoft OUI (00:50:F2) with OUI Type 1: - * real WPA information element - */ - elems->wpa_ie = pos; - elems->wpa_ie_len = elen; - break; - case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */ - if (elen < 5) - return -1; - - switch (pos[4]) { - case WME_OUI_SUBTYPE_INFORMATION_ELEMENT: - case WME_OUI_SUBTYPE_PARAMETER_ELEMENT: - elems->wme = pos; - elems->wme_len = elen; - break; - case WME_OUI_SUBTYPE_TSPEC_ELEMENT: - elems->wme_tspec = pos; - elems->wme_tspec_len = elen; - break; - default: - return -1; - } - break; - case 4: - /* Wi-Fi Protected Setup (WPS) IE */ - elems->wps_ie = pos; - elems->wps_ie_len = elen; - break; - default: - return -1; - } - break; - - case OUI_BROADCOM: - switch (pos[3]) { - case VENDOR_HT_CAPAB_OUI_TYPE: - elems->vendor_ht_cap = pos; - elems->vendor_ht_cap_len = elen; - break; - default: - return -1; - } - break; - - default: - return -1; - } - - return 0; -} - -/** - * rtw_ieee802_11_parse_elems - Parse information elements in management frames - * @start: Pointer to the start of IEs - * @len: Length of IE buffer in octets - * @elems: Data structure for parsed elements - * @show_errors: Whether to show parsing errors in debug log - * Returns: Parsing result - */ -enum parse_result rtw_ieee802_11_parse_elems(u8 *start, uint len, - struct rtw_ieee802_11_elems *elems, - int show_errors) -{ - uint left = len; - u8 *pos = start; - int unknown = 0; - - memset(elems, 0, sizeof(*elems)); - - while (left >= 2) { - u8 id, elen; - - id = *pos++; - elen = *pos++; - left -= 2; - - if (elen > left) - return PARSE_FAILED; - - switch (id) { - case WLAN_EID_SSID: - elems->ssid = pos; - elems->ssid_len = elen; - break; - case WLAN_EID_SUPP_RATES: - elems->supp_rates = pos; - elems->supp_rates_len = elen; - break; - case WLAN_EID_FH_PARAMS: - elems->fh_params = pos; - elems->fh_params_len = elen; - break; - case WLAN_EID_DS_PARAMS: - elems->ds_params = pos; - elems->ds_params_len = elen; - break; - case WLAN_EID_CF_PARAMS: - elems->cf_params = pos; - elems->cf_params_len = elen; - break; - case WLAN_EID_TIM: - elems->tim = pos; - elems->tim_len = elen; - break; - case WLAN_EID_IBSS_PARAMS: - elems->ibss_params = pos; - elems->ibss_params_len = elen; - break; - case WLAN_EID_CHALLENGE: - elems->challenge = pos; - elems->challenge_len = elen; - break; - case WLAN_EID_ERP_INFO: - elems->erp_info = pos; - elems->erp_info_len = elen; - break; - case WLAN_EID_EXT_SUPP_RATES: - elems->ext_supp_rates = pos; - elems->ext_supp_rates_len = elen; - break; - case WLAN_EID_VENDOR_SPECIFIC: - if (rtw_ieee802_11_parse_vendor_specific(pos, elen, - elems, - show_errors)) - unknown++; - break; - case WLAN_EID_RSN: - elems->rsn_ie = pos; - elems->rsn_ie_len = elen; - break; - case WLAN_EID_PWR_CAPABILITY: - elems->power_cap = pos; - elems->power_cap_len = elen; - break; - case WLAN_EID_SUPPORTED_CHANNELS: - elems->supp_channels = pos; - elems->supp_channels_len = elen; - break; - case WLAN_EID_MOBILITY_DOMAIN: - elems->mdie = pos; - elems->mdie_len = elen; - break; - case WLAN_EID_FAST_BSS_TRANSITION: - elems->ftie = pos; - elems->ftie_len = elen; - break; - case WLAN_EID_TIMEOUT_INTERVAL: - elems->timeout_int = pos; - elems->timeout_int_len = elen; - break; - case WLAN_EID_HT_CAPABILITY: - elems->ht_capabilities = pos; - elems->ht_capabilities_len = elen; - break; - case WLAN_EID_HT_OPERATION: - elems->ht_operation = pos; - elems->ht_operation_len = elen; - break; - case WLAN_EID_VHT_CAPABILITY: - elems->vht_capabilities = pos; - elems->vht_capabilities_len = elen; - break; - case WLAN_EID_VHT_OPERATION: - elems->vht_operation = pos; - elems->vht_operation_len = elen; - break; - case WLAN_EID_OPMODE_NOTIF: - elems->vht_op_mode_notify = pos; - elems->vht_op_mode_notify_len = elen; - break; - default: - unknown++; - break; - } - - left -= elen; - pos += elen; - } - - if (left) - return PARSE_FAILED; - - return unknown ? PARSE_UNKNOWN : PARSE_OK; -} - -void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr) -{ - u8 mac[ETH_ALEN]; - struct device_node *np = dev->of_node; - const unsigned char *addr; - int len; - - if (!mac_addr) - return; - - if (rtw_initmac && mac_pton(rtw_initmac, mac)) { - /* Users specify the mac address */ - ether_addr_copy(mac_addr, mac); - } else { - /* Use the mac address stored in the Efuse */ - ether_addr_copy(mac, mac_addr); - } - - if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) { - addr = of_get_property(np, "local-mac-address", &len); - - if (addr && len == ETH_ALEN) - ether_addr_copy(mac_addr, addr); - else - eth_random_addr(mac_addr); - } -} - -static int rtw_get_cipher_info(struct wlan_network *pnetwork) -{ - u32 wpa_ielen; - unsigned char *pbuf; - int group_cipher = 0, pairwise_cipher = 0, is8021x = 0; - int ret = _FAIL; - - pbuf = rtw_get_wpa_ie(&pnetwork->network.ies[12], - &wpa_ielen, - pnetwork->network.ie_length - 12); - - if (pbuf && (wpa_ielen > 0)) { - if (rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, - &pairwise_cipher, &is8021x) == _SUCCESS) { - pnetwork->bcn_info.pairwise_cipher = pairwise_cipher; - pnetwork->bcn_info.group_cipher = group_cipher; - pnetwork->bcn_info.is_8021x = is8021x; - ret = _SUCCESS; - } - } else { - pbuf = rtw_get_wpa2_ie(&pnetwork->network.ies[12], &wpa_ielen, - pnetwork->network.ie_length - 12); - - if (pbuf && (wpa_ielen > 0)) { - if (rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, - &pairwise_cipher, &is8021x) == _SUCCESS) { - pnetwork->bcn_info.pairwise_cipher = pairwise_cipher; - pnetwork->bcn_info.group_cipher = group_cipher; - pnetwork->bcn_info.is_8021x = is8021x; - ret = _SUCCESS; - } - } - } - - return ret; -} - -void rtw_get_bcn_info(struct wlan_network *pnetwork) -{ - unsigned short cap = 0; - u8 bencrypt = 0; - /* u8 wpa_ie[255], rsn_ie[255]; */ - u16 wpa_len = 0, rsn_len = 0; - struct HT_info_element *pht_info = NULL; - struct ieee80211_ht_cap *pht_cap = NULL; - unsigned int len; - unsigned char *p; - __le16 le_cap; - - memcpy((u8 *)&le_cap, rtw_get_capability_from_ie(pnetwork->network.ies), 2); - cap = le16_to_cpu(le_cap); - if (cap & WLAN_CAPABILITY_PRIVACY) { - bencrypt = 1; - pnetwork->network.privacy = 1; - } else { - pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS; - } - rtw_get_sec_ie(pnetwork->network.ies, pnetwork->network.ie_length, NULL, &rsn_len, NULL, &wpa_len); - - if (rsn_len > 0) { - pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WPA2; - } else if (wpa_len > 0) { - pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WPA; - } else { - if (bencrypt) - pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WEP; - } - rtw_get_cipher_info(pnetwork); - - /* get bwmode and ch_offset */ - /* parsing HT_CAP_IE */ - p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_CAPABILITY, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_); - if (p && len > 0) { - pht_cap = (struct ieee80211_ht_cap *)(p + 2); - pnetwork->bcn_info.ht_cap_info = le16_to_cpu(pht_cap->cap_info); - } else { - pnetwork->bcn_info.ht_cap_info = 0; - } - /* parsing HT_INFO_IE */ - p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_OPERATION, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_); - if (p && len > 0) { - pht_info = (struct HT_info_element *)(p + 2); - pnetwork->bcn_info.ht_info_infos_0 = pht_info->infos[0]; - } else { - pnetwork->bcn_info.ht_info_infos_0 = 0; - } -} - -/* show MCS rate, unit: 100Kbps */ -u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate) -{ - u16 max_rate = 0; - - if (MCS_rate[0] & BIT(7)) - max_rate = (bw_40MHz) ? ((short_GI) ? 1500 : 1350) : ((short_GI) ? 722 : 650); - else if (MCS_rate[0] & BIT(6)) - max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585); - else if (MCS_rate[0] & BIT(5)) - max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520); - else if (MCS_rate[0] & BIT(4)) - max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390); - else if (MCS_rate[0] & BIT(3)) - max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260); - else if (MCS_rate[0] & BIT(2)) - max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195); - else if (MCS_rate[0] & BIT(1)) - max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130); - else if (MCS_rate[0] & BIT(0)) - max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65); - - return max_rate; -} - -int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action) -{ - const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr); - u16 fc; - u8 c; - u8 a = ACT_PUBLIC_MAX; - - fc = le16_to_cpu(((struct ieee80211_hdr_3addr *)frame)->frame_control); - - if ((fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) != - (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION)) - return false; - - c = frame_body[0]; - - switch (c) { - case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */ - break; - default: - a = frame_body[1]; - } - - if (category) - *category = c; - if (action) - *action = a; - - return true; -} - -static const char * const _action_public_str[] = { - "ACT_PUB_BSSCOEXIST", - "ACT_PUB_DSE_ENABLE", - "ACT_PUB_DSE_DEENABLE", - "ACT_PUB_DSE_REG_LOCATION", - "ACT_PUB_EXT_CHL_SWITCH", - "ACT_PUB_DSE_MSR_REQ", - "ACT_PUB_DSE_MSR_RPRT", - "ACT_PUB_MP", - "ACT_PUB_DSE_PWR_CONSTRAINT", - "ACT_PUB_VENDOR", - "ACT_PUB_GAS_INITIAL_REQ", - "ACT_PUB_GAS_INITIAL_RSP", - "ACT_PUB_GAS_COMEBACK_REQ", - "ACT_PUB_GAS_COMEBACK_RSP", - "ACT_PUB_TDLS_DISCOVERY_RSP", - "ACT_PUB_LOCATION_TRACK", - "ACT_PUB_RSVD", -}; - -const char *action_public_str(u8 action) -{ - action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action; - return _action_public_str[action]; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_io.c b/drivers/staging/rtl8723bs/core/rtw_io.c deleted file mode 100644 index 49c9e4cb8bf6..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_io.c +++ /dev/null @@ -1,145 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* - * The purpose of rtw_io.c - * - * a. provides the API - * - * b. provides the protocol engine - * - * c. provides the software interface between caller and the hardware interface - * - * jackson@realtek.com.tw - */ - -#include - -u8 rtw_read8(struct adapter *adapter, u32 addr) -{ - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr); - - _read8 = pintfhdl->io_ops._read8; - - return _read8(pintfhdl, addr); -} - -u16 rtw_read16(struct adapter *adapter, u32 addr) -{ - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr); - - _read16 = pintfhdl->io_ops._read16; - - return _read16(pintfhdl, addr); -} - -u32 rtw_read32(struct adapter *adapter, u32 addr) -{ - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr); - - _read32 = pintfhdl->io_ops._read32; - - return _read32(pintfhdl, addr); -} - -int rtw_write8(struct adapter *adapter, u32 addr, u8 val) -{ - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val); - int ret; - - _write8 = pintfhdl->io_ops._write8; - - ret = _write8(pintfhdl, addr, val); - - return RTW_STATUS_CODE(ret); -} - -int rtw_write16(struct adapter *adapter, u32 addr, u16 val) -{ - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val); - int ret; - - _write16 = pintfhdl->io_ops._write16; - - ret = _write16(pintfhdl, addr, val); - return RTW_STATUS_CODE(ret); -} - -int rtw_write32(struct adapter *adapter, u32 addr, u32 val) -{ - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val); - int ret; - - _write32 = pintfhdl->io_ops._write32; - - ret = _write32(pintfhdl, addr, val); - - return RTW_STATUS_CODE(ret); -} - -u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem) -{ - u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); - struct io_priv *pio_priv = &adapter->iopriv; - struct intf_hdl *pintfhdl = &pio_priv->intf; - - _write_port = pintfhdl->io_ops._write_port; - - return _write_port(pintfhdl, addr, cnt, pmem); -} - -int rtw_init_io_priv(struct adapter *padapter, - void (*set_intf_ops)(struct adapter *padapter, - struct _io_ops *pops)) -{ - struct io_priv *piopriv = &padapter->iopriv; - struct intf_hdl *pintf = &piopriv->intf; - - if (!set_intf_ops) - return _FAIL; - - piopriv->padapter = padapter; - pintf->padapter = padapter; - pintf->pintf_dev = adapter_to_dvobj(padapter); - - set_intf_ops(padapter, &pintf->io_ops); - - return _SUCCESS; -} - -/* - * Increase and check if the continual_io_error of this @param dvobjprive - * is larger than MAX_CONTINUAL_IO_ERR - * @return true: - * @return false: - */ -int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj) -{ - int error_count = atomic_inc_return(&dvobj->continual_io_error); - - if (error_count > MAX_CONTINUAL_IO_ERR) - return true; - - return false; -} - -/* Set the continual_io_error of this @param dvobjprive to 0 */ -void rtw_reset_continual_io_error(struct dvobj_priv *dvobj) -{ - atomic_set(&dvobj->continual_io_error, 0); -} diff --git a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c deleted file mode 100644 index 2739d0e99098..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +++ /dev/null @@ -1,494 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include - -u8 rtw_validate_bssid(u8 *bssid) -{ - u8 ret = true; - - if (is_zero_ether_addr(bssid) || - is_broadcast_ether_addr(bssid) || - is_multicast_ether_addr(bssid)) - ret = false; - - return ret; -} - -u8 rtw_validate_ssid(struct ndis_802_11_ssid *ssid) -{ - u8 ret = true; - - if (ssid->ssid_length > 32) { - ret = false; - goto exit; - } - -exit: - return ret; -} - -u8 rtw_do_join(struct adapter *padapter) -{ - struct list_head *plist, *phead; - u8 *pibss = NULL; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct __queue *queue = &(pmlmepriv->scanned_queue); - u8 ret = _SUCCESS; - - spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); - phead = get_list_head(queue); - plist = get_next(phead); - - pmlmepriv->cur_network.join_res = -2; - - set_fwstate(pmlmepriv, _FW_UNDER_LINKING); - - pmlmepriv->pscanned = plist; - - pmlmepriv->to_join = true; - - if (list_empty(&queue->queue)) { - spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - - /* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */ - /* we try to issue sitesurvey firstly */ - - if (!pmlmepriv->link_detect_info.busy_traffic || rtw_to_roam(padapter) > 0) { - /* submit site_survey_cmd */ - ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0); - if (ret != _SUCCESS) - pmlmepriv->to_join = false; - - } else { - pmlmepriv->to_join = false; - ret = _FAIL; - } - - goto exit; - } else { - int select_ret; - - spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); - select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv); - if (select_ret == _SUCCESS) { - pmlmepriv->to_join = false; - _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT); - } else { - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - /* submit createbss_cmd to change to a ADHOC_MASTER */ - - /* pmlmepriv->lock has been acquired by caller... */ - struct wlan_bssid_ex *pdev_network = &(padapter->registrypriv.dev_network); - - pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE; - - pibss = padapter->registrypriv.dev_network.mac_address; - - memcpy(&pdev_network->ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); - - rtw_update_registrypriv_dev_network(padapter); - - rtw_generate_random_ibss(pibss); - - if (rtw_createbss_cmd(padapter) != _SUCCESS) { - ret = false; - goto exit; - } - - pmlmepriv->to_join = false; - - } else { - /* can't associate ; reset under-linking */ - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - - /* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */ - /* we try to issue sitesurvey firstly */ - if (!pmlmepriv->link_detect_info.busy_traffic || - rtw_to_roam(padapter) > 0) { - ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0); - if (ret != _SUCCESS) - pmlmepriv->to_join = false; - - } else { - ret = _FAIL; - pmlmepriv->to_join = false; - } - } - } - } - -exit: - return ret; -} - -u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid) -{ - u8 status = _SUCCESS; - - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *pnetwork = &pmlmepriv->cur_network; - - netdev_dbg(padapter->pnetdev, "set ssid [%s] fw_state = 0x%08x\n", - ssid->ssid, get_fwstate(pmlmepriv)); - - if (!padapter->hw_init_completed) { - status = _FAIL; - goto exit; - } - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - goto handle_tkip_countermeasure; - else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) - goto release_mlme_lock; - - if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) { - if ((pmlmepriv->assoc_ssid.ssid_length == ssid->ssid_length) && - (!memcmp(&pmlmepriv->assoc_ssid.ssid, ssid->ssid, ssid->ssid_length))) { - if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - if (!rtw_is_same_ibss(padapter, pnetwork)) { - /* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */ - rtw_disassoc_cmd(padapter, 0, true); - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_indicate_disconnect(padapter); - - rtw_free_assoc_resources(padapter, 1); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); - set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); - } - } else { - goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */ - } - } else { - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 1); - } - } else { - rtw_disassoc_cmd(padapter, 0, true); - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_indicate_disconnect(padapter); - - rtw_free_assoc_resources(padapter, 1); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); - set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); - } - } - } - -handle_tkip_countermeasure: - if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) { - status = _FAIL; - goto release_mlme_lock; - } - - if (!rtw_validate_ssid(ssid)) { - status = _FAIL; - goto release_mlme_lock; - } - - memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid)); - pmlmepriv->assoc_by_bssid = false; - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - pmlmepriv->to_join = true; - else - status = rtw_do_join(padapter); - -release_mlme_lock: - spin_unlock_bh(&pmlmepriv->lock); - -exit: - - return status; -} - -u8 rtw_set_802_11_connect(struct adapter *padapter, u8 *bssid, struct ndis_802_11_ssid *ssid) -{ - u8 status = _SUCCESS; - bool bssid_valid = true; - bool ssid_valid = true; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (!ssid || !rtw_validate_ssid(ssid)) - ssid_valid = false; - - if (!bssid || !rtw_validate_bssid(bssid)) - bssid_valid = false; - - if (!ssid_valid && !bssid_valid) { - status = _FAIL; - goto exit; - } - - if (!padapter->hw_init_completed) { - status = _FAIL; - goto exit; - } - - spin_lock_bh(&pmlmepriv->lock); - - netdev_dbg(padapter->pnetdev, FUNC_ADPT_FMT " fw_state = 0x%08x\n", - FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv)); - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - goto handle_tkip_countermeasure; - else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) - goto release_mlme_lock; - -handle_tkip_countermeasure: - if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) { - status = _FAIL; - goto release_mlme_lock; - } - - if (ssid && ssid_valid) - memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid)); - else - memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid)); - - if (bssid && bssid_valid) { - memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN); - pmlmepriv->assoc_by_bssid = true; - } else { - pmlmepriv->assoc_by_bssid = false; - } - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - pmlmepriv->to_join = true; - else - status = rtw_do_join(padapter); - -release_mlme_lock: - spin_unlock_bh(&pmlmepriv->lock); - -exit: - return status; -} - -u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter, - enum nl80211_iftype networktype) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *cur_network = &pmlmepriv->cur_network; - enum nl80211_iftype *pold_state = &(cur_network->network.infrastructure_mode); - - if (*pold_state != networktype) { - if (*pold_state == NL80211_IFTYPE_AP) { - /* change to other mode from AP mode */ - cur_network->join_res = -1; - - stop_ap_mode(padapter); - } - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, _FW_LINKED) || (*pold_state == NL80211_IFTYPE_ADHOC)) - rtw_disassoc_cmd(padapter, 0, true); - - if (check_fwstate(pmlmepriv, _FW_LINKED) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) - rtw_free_assoc_resources(padapter, 1); - - if ((*pold_state == NL80211_IFTYPE_STATION) || (*pold_state == NL80211_IFTYPE_ADHOC)) { - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_indicate_disconnect(padapter); /* will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not */ - } - - *pold_state = networktype; - - _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE); - - switch (networktype) { - case NL80211_IFTYPE_ADHOC: - set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); - break; - - case NL80211_IFTYPE_STATION: - set_fwstate(pmlmepriv, WIFI_STATION_STATE); - break; - - case NL80211_IFTYPE_AP: - set_fwstate(pmlmepriv, WIFI_AP_STATE); - start_ap_mode(padapter); - /* rtw_indicate_connect(padapter); */ - - break; - - default: - break; - } - - /* SecClearAllKeys(adapter); */ - - spin_unlock_bh(&pmlmepriv->lock); - } - return true; -} - -u8 rtw_set_802_11_disassociate(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, _FW_LINKED)) { - rtw_disassoc_cmd(padapter, 0, true); - rtw_indicate_disconnect(padapter); - rtw_free_assoc_resources_cmd(padapter); - rtw_pwr_wakeup(padapter); - } - - spin_unlock_bh(&pmlmepriv->lock); - - return true; -} - -u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct ndis_802_11_ssid *pssid, int ssid_max_num) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - u8 res = true; - - if (!padapter) { - res = false; - goto exit; - } - if (!padapter->hw_init_completed) { - res = false; - goto exit; - } - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) || - pmlmepriv->link_detect_info.busy_traffic) { - /* Scan or linking is in progress, do nothing. */ - res = true; - - } else { - if (rtw_is_scan_deny(padapter)) - return _SUCCESS; - - spin_lock_bh(&pmlmepriv->lock); - - res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, NULL, 0); - - spin_unlock_bh(&pmlmepriv->lock); - } -exit: - - return res; -} - -u8 rtw_set_802_11_authentication_mode(struct adapter *padapter, enum ndis_802_11_authentication_mode authmode) -{ - struct security_priv *psecuritypriv = &padapter->securitypriv; - int res; - u8 ret; - - psecuritypriv->ndisauthtype = authmode; - - if (psecuritypriv->ndisauthtype > 3) - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_8021x; - - res = rtw_set_auth(padapter, psecuritypriv); - - if (res == _SUCCESS) - ret = true; - else - ret = false; - - return ret; -} - -u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep) -{ - signed int keyid, res; - struct security_priv *psecuritypriv = &(padapter->securitypriv); - u8 ret = _SUCCESS; - - keyid = wep->key_index & 0x3fffffff; - - if (keyid >= 4) { - ret = false; - goto exit; - } - - switch (wep->key_length) { - case 5: - psecuritypriv->dot11_privacy_algrthm = _WEP40_; - break; - case 13: - psecuritypriv->dot11_privacy_algrthm = _WEP104_; - break; - default: - psecuritypriv->dot11_privacy_algrthm = _NO_PRIVACY_; - break; - } - - memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->key_material), wep->key_length); - - psecuritypriv->dot11DefKeylen[keyid] = wep->key_length; - - psecuritypriv->dot11PrivacyKeyIndex = keyid; - - res = rtw_set_key(padapter, psecuritypriv, keyid, 1, true); - - if (res == _FAIL) - ret = false; -exit: - - return ret; -} - -/* - * rtw_get_cur_max_rate - - * @adapter: pointer to struct adapter structure - * - * Return 0 or 100Kbps - */ -u16 rtw_get_cur_max_rate(struct adapter *adapter) -{ - int i = 0; - u16 rate = 0, max_rate = 0; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; - struct sta_info *psta = NULL; - u8 short_GI = 0; - - if (!check_fwstate(pmlmepriv, _FW_LINKED) && - !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) - return 0; - - psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(pmlmepriv)); - if (!psta) - return 0; - - short_GI = query_ra_short_GI(psta); - - if (is_supported_ht(psta->wireless_mode)) { - max_rate = rtw_mcs_rate(psta->bw_mode == CHANNEL_WIDTH_40 ? 1 : 0, - short_GI, - psta->htpriv.ht_cap.mcs.rx_mask); - } else { - while ((pcur_bss->supported_rates[i] != 0) && (pcur_bss->supported_rates[i] != 0xFF)) { - rate = pcur_bss->supported_rates[i]&0x7F; - if (rate > max_rate) - max_rate = rate; - i++; - } - - max_rate = max_rate*10/2; - } - - return max_rate; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c deleted file mode 100644 index fc46b33b836a..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c +++ /dev/null @@ -1,2565 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include -#include - -static void _dynamic_check_timer_handler(struct timer_list *t) -{ - struct adapter *adapter = - timer_container_of(adapter, t, mlmepriv.dynamic_chk_timer); - - rtw_dynamic_check_timer_handler(adapter); - - _set_timer(&adapter->mlmepriv.dynamic_chk_timer, 2000); -} - -static void _rtw_set_scan_deny_timer_hdl(struct timer_list *t) -{ - struct adapter *adapter = - timer_container_of(adapter, t, mlmepriv.set_scan_deny_timer); - - rtw_clear_scan_deny(adapter); -} - -static void rtw_init_mlme_timer(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - timer_setup(&pmlmepriv->assoc_timer, _rtw_join_timeout_handler, 0); - timer_setup(&pmlmepriv->scan_to_timer, rtw_scan_timeout_handler, 0); - timer_setup(&pmlmepriv->dynamic_chk_timer, - _dynamic_check_timer_handler, 0); - timer_setup(&pmlmepriv->set_scan_deny_timer, - _rtw_set_scan_deny_timer_hdl, 0); -} - -int rtw_init_mlme_priv(struct adapter *padapter) -{ - int i; - u8 *pbuf; - struct wlan_network *pnetwork; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - int res = _SUCCESS; - - pmlmepriv->nic_hdl = (u8 *)padapter; - - pmlmepriv->pscanned = NULL; - pmlmepriv->fw_state = WIFI_STATION_STATE; /* Must sync with rtw_wdev_alloc() */ - pmlmepriv->cur_network.network.infrastructure_mode = NL80211_IFTYPE_UNSPECIFIED; - pmlmepriv->scan_mode = SCAN_ACTIVE;/* 1: active, 0: passive. Maybe someday we should rename this variable to "active_mode" (Jeff) */ - - spin_lock_init(&pmlmepriv->lock); - INIT_LIST_HEAD(&pmlmepriv->free_bss_pool.queue); - spin_lock_init(&pmlmepriv->free_bss_pool.lock); - INIT_LIST_HEAD(&pmlmepriv->scanned_queue.queue); - spin_lock_init(&pmlmepriv->scanned_queue.lock); - - memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid)); - - pbuf = vzalloc(array_size(MAX_BSS_CNT, sizeof(struct wlan_network))); - - if (!pbuf) { - res = _FAIL; - goto exit; - } - pmlmepriv->free_bss_buf = pbuf; - - pnetwork = (struct wlan_network *)pbuf; - - for (i = 0; i < MAX_BSS_CNT; i++) { - INIT_LIST_HEAD(&pnetwork->list); - - list_add_tail(&pnetwork->list, &pmlmepriv->free_bss_pool.queue); - - pnetwork++; - } - - /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ - - rtw_clear_scan_deny(padapter); - - #define RTW_ROAM_SCAN_RESULT_EXP_MS 5000 - #define RTW_ROAM_RSSI_DIFF_TH 10 - #define RTW_ROAM_SCAN_INTERVAL_MS 10000 - - pmlmepriv->roam_flags = 0 - | RTW_ROAM_ON_EXPIRED - | RTW_ROAM_ON_RESUME - ; - - pmlmepriv->roam_scanr_exp_ms = RTW_ROAM_SCAN_RESULT_EXP_MS; - pmlmepriv->roam_rssi_diff_th = RTW_ROAM_RSSI_DIFF_TH; - pmlmepriv->roam_scan_int_ms = RTW_ROAM_SCAN_INTERVAL_MS; - - rtw_init_mlme_timer(padapter); - -exit: - - return res; -} - -static void rtw_free_mlme_ie_data(u8 **ppie, u32 *plen) -{ - if (*ppie) { - kfree(*ppie); - *plen = 0; - *ppie = NULL; - } -} - -void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv) -{ - rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len); - rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len); - rtw_free_mlme_ie_data(&pmlmepriv->wps_beacon_ie, &pmlmepriv->wps_beacon_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_req_ie, &pmlmepriv->wps_probe_req_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_resp_ie, &pmlmepriv->wps_probe_resp_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->wps_assoc_resp_ie, &pmlmepriv->wps_assoc_resp_ie_len); - - rtw_free_mlme_ie_data(&pmlmepriv->p2p_beacon_ie, &pmlmepriv->p2p_beacon_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_req_ie, &pmlmepriv->p2p_probe_req_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_resp_ie, &pmlmepriv->p2p_probe_resp_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->p2p_go_probe_resp_ie, &pmlmepriv->p2p_go_probe_resp_ie_len); - rtw_free_mlme_ie_data(&pmlmepriv->p2p_assoc_req_ie, &pmlmepriv->p2p_assoc_req_ie_len); -} - -void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv) -{ - if (pmlmepriv) { - rtw_free_mlme_priv_ie_data(pmlmepriv); - vfree(pmlmepriv->free_bss_buf); - } -} - -struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv) -{ - struct wlan_network *pnetwork; - struct __queue *free_queue = &pmlmepriv->free_bss_pool; - struct list_head *plist = NULL; - - spin_lock_bh(&free_queue->lock); - - if (list_empty(&free_queue->queue)) { - pnetwork = NULL; - goto exit; - } - plist = get_next(&free_queue->queue); - - pnetwork = container_of(plist, struct wlan_network, list); - - list_del_init(&pnetwork->list); - - pnetwork->network_type = 0; - pnetwork->fixed = false; - pnetwork->last_scanned = jiffies; - pnetwork->aid = 0; - pnetwork->join_res = 0; - -exit: - spin_unlock_bh(&free_queue->lock); - - return pnetwork; -} - -void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall) -{ - unsigned int delta_time; - u32 lifetime = SCANQUEUE_LIFETIME; - struct __queue *free_queue = &pmlmepriv->free_bss_pool; - - if (!pnetwork) - return; - - if (pnetwork->fixed) - return; - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) - lifetime = 1; - - if (!isfreeall) { - delta_time = jiffies_to_msecs(jiffies - pnetwork->last_scanned); - if (delta_time < lifetime)/* unit:msec */ - return; - } - - spin_lock_bh(&free_queue->lock); - - list_del_init(&pnetwork->list); - - list_add_tail(&pnetwork->list, &free_queue->queue); - - spin_unlock_bh(&free_queue->lock); -} - -void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork) -{ - struct __queue *free_queue = &pmlmepriv->free_bss_pool; - - if (!pnetwork) - return; - - if (pnetwork->fixed) - return; - - list_del_init(&pnetwork->list); - - list_add_tail(&pnetwork->list, get_list_head(free_queue)); -} - -/* - * return the wlan_network with the matching addr - * - * Shall be called under atomic context... to avoid possible racing condition... - */ -struct wlan_network *_rtw_find_network(struct __queue *scanned_queue, u8 *addr) -{ - struct list_head *phead, *plist; - struct wlan_network *pnetwork = NULL; - - if (is_zero_ether_addr(addr)) { - pnetwork = NULL; - goto exit; - } - - phead = get_list_head(scanned_queue); - list_for_each(plist, phead) { - pnetwork = list_entry(plist, struct wlan_network, list); - - if (!memcmp(addr, pnetwork->network.mac_address, ETH_ALEN)) - break; - } - - if (plist == phead) - pnetwork = NULL; - -exit: - return pnetwork; -} - -void rtw_free_network_queue(struct adapter *padapter, u8 isfreeall) -{ - struct list_head *phead, *plist, *tmp; - struct wlan_network *pnetwork; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct __queue *scanned_queue = &pmlmepriv->scanned_queue; - - spin_lock_bh(&scanned_queue->lock); - - phead = get_list_head(scanned_queue); - list_for_each_safe(plist, tmp, phead) { - pnetwork = list_entry(plist, struct wlan_network, list); - - _rtw_free_network(pmlmepriv, pnetwork, isfreeall); - } - - spin_unlock_bh(&scanned_queue->lock); -} - -bool rtw_if_up(struct adapter *padapter) -{ - if (padapter->driver_stopped || padapter->bSurpriseRemoved || - !check_fwstate(&padapter->mlmepriv, _FW_LINKED)) - return false; - - return true; -} - -void rtw_generate_random_ibss(u8 *pibss) -{ - unsigned long curtime = jiffies; - - pibss[0] = 0x02; /* in ad-hoc mode bit1 must set to 1 */ - pibss[1] = 0x11; - pibss[2] = 0x87; - pibss[3] = (u8)(curtime & 0xff) ;/* p[0]; */ - pibss[4] = (u8)((curtime >> 8) & 0xff) ;/* p[1]; */ - pibss[5] = (u8)((curtime >> 16) & 0xff) ;/* p[2]; */ -} - -u8 *rtw_get_capability_from_ie(u8 *ie) -{ - return ie + 8 + 2; -} - -u16 rtw_get_capability(struct wlan_bssid_ex *bss) -{ - __le16 val; - - memcpy((u8 *)&val, rtw_get_capability_from_ie(bss->ies), 2); - - return le16_to_cpu(val); -} - -u8 *rtw_get_beacon_interval_from_ie(u8 *ie) -{ - return ie + 8; -} - -void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv) -{ - _rtw_free_mlme_priv(pmlmepriv); -} - -void rtw_free_network_nolock(struct adapter *padapter, struct wlan_network *pnetwork); -void rtw_free_network_nolock(struct adapter *padapter, struct wlan_network *pnetwork) -{ - _rtw_free_network_nolock(&padapter->mlmepriv, pnetwork); - rtw_cfg80211_unlink_bss(padapter, pnetwork); -} - -/* - * return the wlan_network with the matching addr - * - * Shall be called under atomic context... to avoid possible racing condition... - */ -struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr) -{ - struct wlan_network *pnetwork = _rtw_find_network(scanned_queue, addr); - - return pnetwork; -} - -bool rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork) -{ - struct security_priv *psecuritypriv = &adapter->securitypriv; - - if ((psecuritypriv->dot11_privacy_algrthm != _NO_PRIVACY_) && - (pnetwork->network.privacy == 0)) - return false; - else if ((psecuritypriv->dot11_privacy_algrthm == _NO_PRIVACY_) && - (pnetwork->network.privacy == 1)) - return false; - - return true; -} - -inline int is_same_ess(struct wlan_bssid_ex *a, struct wlan_bssid_ex *b) -{ - return (a->ssid.ssid_length == b->ssid.ssid_length) && - !memcmp(a->ssid.ssid, b->ssid.ssid, a->ssid.ssid_length); -} - -int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst, u8 feature) -{ - u16 s_cap, d_cap; - __le16 tmps, tmpd; - - memcpy((u8 *)&tmps, rtw_get_capability_from_ie(src->ies), 2); - memcpy((u8 *)&tmpd, rtw_get_capability_from_ie(dst->ies), 2); - - s_cap = le16_to_cpu(tmps); - d_cap = le16_to_cpu(tmpd); - - return (src->ssid.ssid_length == dst->ssid.ssid_length) && - ((!memcmp(src->mac_address, dst->mac_address, ETH_ALEN))) && - ((!memcmp(src->ssid.ssid, dst->ssid.ssid, src->ssid.ssid_length))) && - ((s_cap & WLAN_CAPABILITY_IBSS) == - (d_cap & WLAN_CAPABILITY_IBSS)) && - ((s_cap & WLAN_CAPABILITY_ESS) == - (d_cap & WLAN_CAPABILITY_ESS)); -} - -struct wlan_network *_rtw_find_same_network(struct __queue *scanned_queue, struct wlan_network *network) -{ - struct list_head *phead, *plist; - struct wlan_network *found = NULL; - - phead = get_list_head(scanned_queue); - list_for_each(plist, phead) { - found = list_entry(plist, struct wlan_network, list); - - if (is_same_network(&network->network, &found->network, 0)) - break; - } - - if (plist == phead) - found = NULL; - - return found; -} - -struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue) -{ - struct list_head *plist, *phead; - - struct wlan_network *pwlan = NULL; - struct wlan_network *oldest = NULL; - - phead = get_list_head(scanned_queue); - - list_for_each(plist, phead) { - pwlan = list_entry(plist, struct wlan_network, list); - - if (!pwlan->fixed) { - if (!oldest || time_after(oldest->last_scanned, pwlan->last_scanned)) - oldest = pwlan; - } - } - return oldest; -} - -void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src, - struct adapter *padapter, bool update_ie) -{ - long rssi_ori = dst->rssi; - - u8 sq_smp = src->phy_info.signal_quality; - - u8 ss_final; - u8 sq_final; - long rssi_final; - - /* The rule below is 1/5 for sample value, 4/5 for history value */ - if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) && is_same_network(&padapter->mlmepriv.cur_network.network, src, 0)) { - /* Take the recvpriv's value for the connected AP*/ - ss_final = padapter->recvpriv.signal_strength; - sq_final = padapter->recvpriv.signal_qual; - /* the rssi value here is undecorated, and will be used for antenna diversity */ - if (sq_smp != 101) /* from the right channel */ - rssi_final = (src->rssi + dst->rssi * 4) / 5; - else - rssi_final = rssi_ori; - } else { - if (sq_smp != 101) { /* from the right channel */ - ss_final = ((u32)(src->phy_info.signal_strength) + (u32)(dst->phy_info.signal_strength) * 4) / 5; - sq_final = ((u32)(src->phy_info.signal_quality) + (u32)(dst->phy_info.signal_quality) * 4) / 5; - rssi_final = (src->rssi + dst->rssi * 4) / 5; - } else { - /* bss info not receiving from the right channel, use the original RX signal infos */ - ss_final = dst->phy_info.signal_strength; - sq_final = dst->phy_info.signal_quality; - rssi_final = dst->rssi; - } - } - - if (update_ie) { - dst->reserved[0] = src->reserved[0]; - dst->reserved[1] = src->reserved[1]; - memcpy((u8 *)dst, (u8 *)src, get_wlan_bssid_ex_sz(src)); - } - - dst->phy_info.signal_strength = ss_final; - dst->phy_info.signal_quality = sq_final; - dst->rssi = rssi_final; -} - -static void update_current_network(struct adapter *adapter, struct wlan_bssid_ex *pnetwork) -{ - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - - if (check_fwstate(pmlmepriv, _FW_LINKED) && (is_same_network(&pmlmepriv->cur_network.network, pnetwork, 0))) { - update_network(&pmlmepriv->cur_network.network, pnetwork, adapter, true); - if (pmlmepriv->cur_network.network.ie_length < sizeof(struct ndis_802_11_fix_ie)) - return; - - rtw_update_protection(adapter, (pmlmepriv->cur_network.network.ies) + sizeof(struct ndis_802_11_fix_ie), - pmlmepriv->cur_network.network.ie_length - sizeof(struct ndis_802_11_fix_ie)); - } -} - -/* Caller must hold pmlmepriv->lock first. */ -void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *target) -{ - struct list_head *plist, *phead; - u32 bssid_ex_sz; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct __queue *queue = &pmlmepriv->scanned_queue; - struct wlan_network *pnetwork = NULL; - struct wlan_network *oldest = NULL; - int target_find = 0; - u8 feature = 0; - - spin_lock_bh(&queue->lock); - phead = get_list_head(queue); - list_for_each(plist, phead) { - pnetwork = list_entry(plist, struct wlan_network, list); - - if (is_same_network(&pnetwork->network, target, feature)) { - target_find = 1; - break; - } - - if (rtw_roam_flags(adapter)) { - /* TODO: don't select network in the same ess as oldest if it's new enough*/ - } - - if (!oldest || time_after(oldest->last_scanned, pnetwork->last_scanned)) - oldest = pnetwork; - } - - /* - * If we didn't find a match, then get a new network slot to initialize - * with this beacon's information - */ - if (!target_find) { - if (list_empty(&pmlmepriv->free_bss_pool.queue)) { - /* If there are no more slots, expire the oldest */ - /* list_del_init(&oldest->list); */ - pnetwork = oldest; - if (!pnetwork) - goto exit; - - memcpy(&pnetwork->network, target, get_wlan_bssid_ex_sz(target)); - /* variable initialize */ - pnetwork->fixed = false; - pnetwork->last_scanned = jiffies; - - pnetwork->network_type = 0; - pnetwork->aid = 0; - pnetwork->join_res = 0; - - /* bss info not receiving from the right channel */ - if (pnetwork->network.phy_info.signal_quality == 101) - pnetwork->network.phy_info.signal_quality = 0; - } else { - /* Otherwise just pull from the free list */ - - pnetwork = rtw_alloc_network(pmlmepriv); /* will update scan_time */ - - if (!pnetwork) - goto exit; - - bssid_ex_sz = get_wlan_bssid_ex_sz(target); - target->length = bssid_ex_sz; - memcpy(&pnetwork->network, target, bssid_ex_sz); - - pnetwork->last_scanned = jiffies; - - /* bss info not receiving from the right channel */ - if (pnetwork->network.phy_info.signal_quality == 101) - pnetwork->network.phy_info.signal_quality = 0; - - list_add_tail(&pnetwork->list, &queue->queue); - } - } else { - /* we have an entry and we are going to update it. But this entry may - * be already expired. In this case we do the same as we found a new - * net and call the new_net handler - */ - bool update_ie = true; - - pnetwork->last_scanned = jiffies; - - /* target.reserved[0]== 1, means that scanned network is a bcn frame. */ - if (pnetwork->network.ie_length > target->ie_length && target->reserved[0] == 1) - update_ie = false; - - /* probe resp(3) > beacon(1) > probe req(2) */ - if (target->reserved[0] != 2 && - target->reserved[0] >= pnetwork->network.reserved[0]) { - update_ie = true; - } else { - update_ie = false; - } - - update_network(&pnetwork->network, target, adapter, update_ie); - } - -exit: - spin_unlock_bh(&queue->lock); -} - -static void rtw_add_network(struct adapter *adapter, struct wlan_bssid_ex *pnetwork) -{ - update_current_network(adapter, pnetwork); - rtw_update_scanned_network(adapter, pnetwork); -} - -/* select the desired network based on the capability of the (i)bss. - * check items: - * (1) security - * (2) network_type - * (3) WMM - * (4) HT - * (5) others - */ -static bool rtw_is_desired_network(struct adapter *adapter, struct wlan_network *pnetwork) -{ - struct security_priv *psecuritypriv = &adapter->securitypriv; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - u32 desired_encmode; - u32 privacy; - uint wps_ielen; - bool bselected = true; - - desired_encmode = psecuritypriv->ndisencryptstatus; - privacy = pnetwork->network.privacy; - - if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) { - if (pnetwork->network.ie_length < _FIXED_IE_LENGTH_) - return false; - if (rtw_get_wps_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, pnetwork->network.ie_length - _FIXED_IE_LENGTH_, NULL, &wps_ielen)) - return true; - else - return false; - } - - if (adapter->registrypriv.wifi_spec == 1) { /* for correct flow of 8021X to do.... */ - u8 *p = NULL; - uint ie_len = 0; - - if ((desired_encmode == Ndis802_11EncryptionDisabled) && (privacy != 0)) - bselected = false; - - if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK) { - if (pnetwork->network.ie_length < _BEACON_IE_OFFSET_) { - bselected = false; - } else { - p = rtw_get_ie(pnetwork->network.ies + _BEACON_IE_OFFSET_, WLAN_EID_RSN, &ie_len, (pnetwork->network.ie_length - _BEACON_IE_OFFSET_)); - if (p && ie_len > 0) - bselected = true; - else - bselected = false; - } - } - } - - if ((desired_encmode != Ndis802_11EncryptionDisabled) && (privacy == 0)) - bselected = false; - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - if (pnetwork->network.infrastructure_mode != pmlmepriv->cur_network.network.infrastructure_mode) - bselected = false; - } - - return bselected; -} - -void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf) -{ - u32 len; - struct wlan_bssid_ex *pnetwork; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - - pnetwork = (struct wlan_bssid_ex *)pbuf; - - len = get_wlan_bssid_ex_sz(pnetwork); - if (len > (sizeof(struct wlan_bssid_ex))) - return; - - spin_lock_bh(&pmlmepriv->lock); - - /* update IBSS_network 's timestamp */ - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - if (!memcmp(&pmlmepriv->cur_network.network.mac_address, pnetwork->mac_address, ETH_ALEN)) { - struct wlan_network *ibss_wlan = NULL; - - memcpy(pmlmepriv->cur_network.network.ies, pnetwork->ies, 8); - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - ibss_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->mac_address); - if (ibss_wlan) { - memcpy(ibss_wlan->network.ies, pnetwork->ies, 8); - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - goto exit; - } - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - } - } - - /* lock pmlmepriv->lock when you accessing network_q */ - if (!check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) { - if (pnetwork->ssid.ssid[0] == 0) - pnetwork->ssid.ssid_length = 0; - rtw_add_network(adapter, pnetwork); - } - -exit: - - spin_unlock_bh(&pmlmepriv->lock); -} - -void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf) -{ - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - - spin_lock_bh(&pmlmepriv->lock); - if (pmlmepriv->wps_probe_req_ie) { - pmlmepriv->wps_probe_req_ie_len = 0; - kfree(pmlmepriv->wps_probe_req_ie); - pmlmepriv->wps_probe_req_ie = NULL; - } - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) { - spin_unlock_bh(&pmlmepriv->lock); - timer_delete_sync(&pmlmepriv->scan_to_timer); - spin_lock_bh(&pmlmepriv->lock); - _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); - } - - rtw_set_signal_stat_timer(&adapter->recvpriv); - - if (pmlmepriv->to_join) { - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - if (!check_fwstate(pmlmepriv, _FW_LINKED)) { - set_fwstate(pmlmepriv, _FW_UNDER_LINKING); - - if (rtw_select_and_join_from_scanned_queue(pmlmepriv) == _SUCCESS) { - _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT); - } else { - u8 ret = _SUCCESS; - struct wlan_bssid_ex *pdev_network = - &adapter->registrypriv.dev_network; - - u8 *pibss = adapter->registrypriv.dev_network.mac_address; - - /* pmlmepriv->fw_state ^= _FW_UNDER_SURVEY;because don't set assoc_timer */ - _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); - - memcpy(&pdev_network->ssid, &pmlmepriv->assoc_ssid, - sizeof(struct ndis_802_11_ssid)); - - rtw_update_registrypriv_dev_network(adapter); - rtw_generate_random_ibss(pibss); - - pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE; - - pmlmepriv->to_join = false; - - ret = rtw_createbss_cmd(adapter); - if (ret != _SUCCESS) - goto unlock; - } - } - } else { - int s_ret; - - set_fwstate(pmlmepriv, _FW_UNDER_LINKING); - pmlmepriv->to_join = false; - s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv); - if (s_ret == _SUCCESS) { - _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT); - } else if (s_ret == 2) {/* there is no need to wait for join */ - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - rtw_indicate_connect(adapter); - } else { - if (rtw_to_roam(adapter) != 0) { - if (rtw_dec_to_roam(adapter) == 0 || - rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, - 1, NULL, 0) != _SUCCESS) { - rtw_set_to_roam(adapter, 0); - rtw_free_assoc_resources(adapter, 1); - rtw_indicate_disconnect(adapter); - } else { - pmlmepriv->to_join = true; - } - } else { - rtw_indicate_disconnect(adapter); - } - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - } - } - } else { - if (rtw_chk_roam_flags(adapter, RTW_ROAM_ACTIVE)) { - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && - check_fwstate(pmlmepriv, _FW_LINKED)) { - if (rtw_select_roaming_candidate(pmlmepriv) == _SUCCESS) { - receive_disconnect(adapter, pmlmepriv->cur_network.network.mac_address - , WLAN_REASON_ACTIVE_ROAM); - } - } - } - } - -unlock: - spin_unlock_bh(&pmlmepriv->lock); - - rtw_os_xmit_schedule(adapter); - - rtw_cfg80211_surveydone_event_callback(adapter); - - rtw_indicate_scan_done(adapter, false); -} - -void rtw_dummy_event_callback(struct adapter *adapter, u8 *pbuf) -{ -} - -void rtw_fwdbg_event_callback(struct adapter *adapter, u8 *pbuf) -{ -} - -static void free_scanqueue(struct mlme_priv *pmlmepriv) -{ - struct __queue *free_queue = &pmlmepriv->free_bss_pool; - struct __queue *scan_queue = &pmlmepriv->scanned_queue; - struct list_head *plist, *phead, *ptemp; - - spin_lock_bh(&scan_queue->lock); - spin_lock_bh(&free_queue->lock); - - phead = get_list_head(scan_queue); - plist = get_next(phead); - - while (plist != phead) { - ptemp = get_next(plist); - list_del_init(plist); - list_add_tail(plist, &free_queue->queue); - plist = ptemp; - } - - spin_unlock_bh(&free_queue->lock); - spin_unlock_bh(&scan_queue->lock); -} - -static void find_network(struct adapter *adapter) -{ - struct wlan_network *pwlan = NULL; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct wlan_network *tgt_network = &pmlmepriv->cur_network; - - pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.mac_address); - if (!pwlan) - return; - - pwlan->fixed = false; - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) && - (adapter->stapriv.asoc_sta_count == 1)) - rtw_free_network_nolock(adapter, pwlan); -} - -/* rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock */ -void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue) -{ - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct wlan_network *tgt_network = &pmlmepriv->cur_network; - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_AP_STATE)) { - struct sta_info *psta; - - psta = rtw_get_stainfo(&adapter->stapriv, tgt_network->network.mac_address); - rtw_free_stainfo(adapter, psta); - } - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE | WIFI_AP_STATE)) { - struct sta_info *psta; - - rtw_free_all_stainfo(adapter); - - psta = rtw_get_bcmc_stainfo(adapter); - rtw_free_stainfo(adapter, psta); - - rtw_init_bcmc_stainfo(adapter); - } - - find_network(adapter); - - if (lock_scanned_queue) - adapter->securitypriv.key_mask = 0; -} - -/* rtw_indicate_connect: the caller has to lock pmlmepriv->lock */ -void rtw_indicate_connect(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - pmlmepriv->to_join = false; - - if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { - set_fwstate(pmlmepriv, _FW_LINKED); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) - rtw_cfg80211_ibss_indicate_connect(padapter); - else - rtw_cfg80211_indicate_connect(padapter); - - netif_carrier_on(padapter->pnetdev); - - if (padapter->pid[2] != 0) - rtw_signal_process(padapter->pid[2], SIGALRM); - } - - rtw_set_to_roam(padapter, 0); - rtw_set_scan_deny(padapter, 3000); -} - -/* rtw_indicate_disconnect: the caller has to lock pmlmepriv->lock */ -void rtw_indicate_disconnect(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING | WIFI_UNDER_WPS); - - if (rtw_to_roam(padapter) > 0) - _clr_fwstate_(pmlmepriv, _FW_LINKED); - - if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) || rtw_to_roam(padapter) <= 0) { - /* Do it first for tx broadcast pkt after disconnection issue! */ - netif_carrier_off(padapter->pnetdev); - - rtw_cfg80211_indicate_disconnect(padapter); - - rtw_reset_securitypriv_cmd(padapter); - - /* set ips_deny_time to avoid enter IPS before LPS leave */ - rtw_set_ips_deny(padapter, 3000); - - _clr_fwstate_(pmlmepriv, _FW_LINKED); - - rtw_clear_scan_deny(padapter); - } - - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 1); -} - -inline void rtw_indicate_scan_done(struct adapter *padapter, bool aborted) -{ - rtw_cfg80211_indicate_scan_done(padapter, aborted); - - if ((!adapter_to_pwrctl(padapter)->bInSuspend) && - (!check_fwstate(&padapter->mlmepriv, - WIFI_ASOC_STATE | WIFI_UNDER_LINKING))) { - rtw_set_ips_deny(padapter, 0); - _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 1); - } -} - -void rtw_scan_abort(struct adapter *adapter) -{ - unsigned long start; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; - - start = jiffies; - pmlmeext->scan_abort = true; - while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) - && jiffies_to_msecs(start) <= 200) { - if (adapter->driver_stopped || adapter->bSurpriseRemoved) - break; - - msleep(20); - } - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - rtw_indicate_scan_done(adapter, true); - - pmlmeext->scan_abort = false; -} - -static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, struct wlan_network *pnetwork) -{ - int i; - struct sta_info *bmc_sta, *psta = NULL; - struct recv_reorder_ctrl *preorder_ctrl; - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - psta = rtw_get_stainfo(pstapriv, pnetwork->network.mac_address); - if (!psta) - psta = rtw_alloc_stainfo(pstapriv, pnetwork->network.mac_address); - - if (psta) { /* update ptarget_sta */ - - psta->aid = pnetwork->join_res; - - update_sta_info(padapter, psta); - - /* update station supportRate */ - psta->bssratelen = rtw_get_rateset_len(pnetwork->network.supported_rates); - memcpy(psta->bssrateset, pnetwork->network.supported_rates, psta->bssratelen); - rtw_hal_update_sta_rate_mask(padapter, psta); - - psta->wireless_mode = pmlmeext->cur_wireless_mode; - psta->raid = networktype_to_raid_ex(padapter, psta); - - /* sta mode */ - rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true); - - /* security related */ - if (padapter->securitypriv.dot11_auth_algrthm == dot11_auth_algrthm_8021x) { - padapter->securitypriv.binstallGrpkey = false; - padapter->securitypriv.busetkipkey = false; - padapter->securitypriv.bgrpkey_handshake = false; - - psta->ieee8021x_blocked = true; - psta->dot118021XPrivacy = padapter->securitypriv.dot11_privacy_algrthm; - - memset((u8 *)&psta->dot118021x_UncstKey, 0, sizeof(union Keytype)); - - memset((u8 *)&psta->dot11tkiprxmickey, 0, sizeof(union Keytype)); - memset((u8 *)&psta->dot11tkiptxmickey, 0, sizeof(union Keytype)); - - memset((u8 *)&psta->dot11txpn, 0, sizeof(union pn48)); - psta->dot11txpn.val = psta->dot11txpn.val + 1; - memset((u8 *)&psta->dot11wtxpn, 0, sizeof(union pn48)); - memset((u8 *)&psta->dot11rxpn, 0, sizeof(union pn48)); - } - - /* When doing the WPS, the wps_ie_len won't equal to 0 */ - /* And the Wi-Fi driver shouldn't allow the data packet to be transmitted. */ - if (padapter->securitypriv.wps_ie_len != 0) { - psta->ieee8021x_blocked = true; - padapter->securitypriv.wps_ie_len = 0; - } - - /* for A-MPDU Rx reordering buffer control for bmc_sta & sta_info */ - /* if A-MPDU Rx is enabled, resetting rx_ordering_ctrl wstart_b(indicate_seq) to default value = 0xffff */ - /* todo: check if AP can send A-MPDU packets */ - for (i = 0; i < 16 ; i++) { - preorder_ctrl = &psta->recvreorder_ctrl[i]; - preorder_ctrl->enable = false; - preorder_ctrl->indicate_seq = 0xffff; - preorder_ctrl->wend_b = 0xffff; - preorder_ctrl->wsize_b = 64;/* max_ampdu_sz;ex. 32(kbytes) -> wsize_b =32 */ - } - - bmc_sta = rtw_get_bcmc_stainfo(padapter); - if (bmc_sta) { - for (i = 0; i < 16 ; i++) { - preorder_ctrl = &bmc_sta->recvreorder_ctrl[i]; - preorder_ctrl->enable = false; - preorder_ctrl->indicate_seq = 0xffff; - preorder_ctrl->wend_b = 0xffff; - preorder_ctrl->wsize_b = 64;/* max_ampdu_sz;ex. 32(kbytes) -> wsize_b =32 */ - } - } - } - - return psta; -} - -/* pnetwork : returns from rtw_joinbss_event_callback */ -/* ptarget_wlan: found from scanned_queue */ -static void rtw_joinbss_update_network(struct adapter *padapter, struct wlan_network *ptarget_wlan, - struct wlan_network *pnetwork) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *cur_network = &pmlmepriv->cur_network; - - /* why not use ptarget_wlan?? */ - memcpy(&cur_network->network, &pnetwork->network, pnetwork->network.length); - /* some ies in pnetwork is wrong, so we should use ptarget_wlan ies */ - cur_network->network.ie_length = ptarget_wlan->network.ie_length; - memcpy(&cur_network->network.ies[0], &ptarget_wlan->network.ies[0], MAX_IE_SZ); - - cur_network->aid = pnetwork->join_res; - - rtw_set_signal_stat_timer(&padapter->recvpriv); - - padapter->recvpriv.signal_strength = ptarget_wlan->network.phy_info.signal_strength; - padapter->recvpriv.signal_qual = ptarget_wlan->network.phy_info.signal_quality; - /* the ptarget_wlan->network.rssi is raw data, we use ptarget_wlan->network.phy_info.signal_strength instead (has scaled) */ - padapter->recvpriv.rssi = translate_percentage_to_dbm(ptarget_wlan->network.phy_info.signal_strength); - - rtw_set_signal_stat_timer(&padapter->recvpriv); - - /* update fw_state will clr _FW_UNDER_LINKING here indirectly */ - switch (pnetwork->network.infrastructure_mode) { - case NL80211_IFTYPE_STATION: - - if (pmlmepriv->fw_state & WIFI_UNDER_WPS) - pmlmepriv->fw_state = WIFI_STATION_STATE | WIFI_UNDER_WPS; - else - pmlmepriv->fw_state = WIFI_STATION_STATE; - - break; - case NL80211_IFTYPE_ADHOC: - pmlmepriv->fw_state = WIFI_ADHOC_STATE; - break; - default: - pmlmepriv->fw_state = WIFI_NULL_STATE; - break; - } - - if (cur_network->network.ie_length < sizeof(struct ndis_802_11_fix_ie)) - return; - - rtw_update_protection(padapter, (cur_network->network.ies) + sizeof(struct ndis_802_11_fix_ie), - (cur_network->network.ie_length - sizeof(struct ndis_802_11_fix_ie))); - - rtw_update_ht_cap(padapter, cur_network->network.ies, cur_network->network.ie_length, (u8) cur_network->network.configuration.ds_config); -} - -static struct rt_pmkid_list backupPMKIDList[NUM_PMKID_CACHE]; -void rtw_reset_securitypriv(struct adapter *adapter) -{ - u8 backupPMKIDIndex = 0; - u8 backupTKIPCountermeasure = 0x00; - u32 backupTKIPcountermeasure_time = 0; - struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; - - spin_lock_bh(&adapter->security_key_mutex); - - if (adapter->securitypriv.dot11_auth_algrthm == dot11_auth_algrthm_8021x) { - /* 802.1x */ - /* Added by Albert 2009/02/18 */ - /* We have to backup the PMK information for WiFi PMK Caching test item. */ - /* */ - /* Backup the btkip_countermeasure information. */ - /* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */ - - memcpy(&backupPMKIDList[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); - backupPMKIDIndex = adapter->securitypriv.PMKIDIndex; - backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure; - backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time; - - /* reset RX BIP packet number */ - pmlmeext->mgnt_80211w_IPN_rx = 0; - - memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv)); - - /* Added by Albert 2009/02/18 */ - /* Restore the PMK information to securitypriv structure for the following connection. */ - memcpy(&adapter->securitypriv.PMKIDList[0], &backupPMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); - adapter->securitypriv.PMKIDIndex = backupPMKIDIndex; - adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure; - adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time; - - adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen; - adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled; - - } else { - /* reset values in securitypriv */ - /* if (adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */ - /* */ - struct security_priv *psec_priv = &adapter->securitypriv; - - psec_priv->dot11_auth_algrthm = dot11_auth_algrthm_open; /* open system */ - psec_priv->dot11_privacy_algrthm = _NO_PRIVACY_; - psec_priv->dot11PrivacyKeyIndex = 0; - - psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_; - psec_priv->dot118021XGrpKeyid = 1; - - psec_priv->ndisauthtype = Ndis802_11AuthModeOpen; - psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled; - /* */ - } - spin_unlock_bh(&adapter->security_key_mutex); -} - -/* Notes: the function could be > passive_level (the same context as Rx tasklet) */ -/* pnetwork : returns from rtw_joinbss_event_callback */ -/* ptarget_wlan: found from scanned_queue */ -/* if join_res > 0, for (fw_state ==WIFI_STATION_STATE), we check if "ptarget_sta" & "ptarget_wlan" exist. */ -/* if join_res > 0, for (fw_state ==WIFI_ADHOC_STATE), we only check if "ptarget_wlan" exist. */ -/* if join_res > 0, update "cur_network->network" from "pnetwork->network" if (ptarget_wlan != NULL). */ -/* */ -void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf) -{ - struct sta_info *ptarget_sta = NULL, *pcur_sta = NULL; - struct sta_priv *pstapriv = &adapter->stapriv; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct wlan_network *pnetwork = (struct wlan_network *)pbuf; - struct wlan_network *cur_network = &pmlmepriv->cur_network; - struct wlan_network *pcur_wlan = NULL, *ptarget_wlan = NULL; - unsigned int the_same_macaddr = false; - - the_same_macaddr = !memcmp(pnetwork->network.mac_address, cur_network->network.mac_address, ETH_ALEN); - - pnetwork->network.length = get_wlan_bssid_ex_sz(&pnetwork->network); - if (pnetwork->network.length > sizeof(struct wlan_bssid_ex)) - return; - - spin_lock_bh(&pmlmepriv->lock); - - pmlmepriv->link_detect_info.traffic_transition_count = 0; - pmlmepriv->link_detect_info.low_power_transition_count = 0; - - if (pnetwork->join_res == -4) { - rtw_reset_securitypriv(adapter); - _set_timer(&pmlmepriv->assoc_timer, 1); - - if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - - spin_unlock_bh(&pmlmepriv->lock); - return; - } - - if (pnetwork->join_res <= 0) { /* if join_res < 0 (join fails), then try again */ - _set_timer(&pmlmepriv->assoc_timer, 1); - _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); - spin_unlock_bh(&pmlmepriv->lock); - return; - } - - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - - if (!check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) { - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - spin_unlock_bh(&pmlmepriv->lock); - return; - } - - /* s1. find ptarget_wlan */ - if (check_fwstate(pmlmepriv, _FW_LINKED)) { - if (the_same_macaddr) { - ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, cur_network->network.mac_address); - } else { - pcur_wlan = rtw_find_network(&pmlmepriv->scanned_queue, cur_network->network.mac_address); - if (pcur_wlan) - pcur_wlan->fixed = false; - - pcur_sta = rtw_get_stainfo(pstapriv, cur_network->network.mac_address); - if (pcur_sta) - rtw_free_stainfo(adapter, pcur_sta); - - ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->network.mac_address); - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - if (ptarget_wlan) - ptarget_wlan->fixed = true; - } - } - } else { - ptarget_wlan = _rtw_find_same_network(&pmlmepriv->scanned_queue, pnetwork); - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - if (ptarget_wlan) - ptarget_wlan->fixed = true; - } - } - - /* s2. update cur_network */ - if (!ptarget_wlan) { - netdev_dbg(adapter->pnetdev, - "Can't find ptarget_wlan when joinbss_event callback\n"); - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - spin_unlock_bh(&pmlmepriv->lock); - return; - } - - rtw_joinbss_update_network(adapter, ptarget_wlan, pnetwork); - - /* s3. find ptarget_sta & update ptarget_sta after update cur_network only for station mode */ - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - ptarget_sta = rtw_joinbss_update_stainfo(adapter, pnetwork); - if (!ptarget_sta) { - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - spin_unlock_bh(&pmlmepriv->lock); - return; - } - } - - /* s4. indicate connect */ - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - pmlmepriv->cur_network_scanned = ptarget_wlan; - rtw_indicate_connect(adapter); - } - - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - - spin_unlock_bh(&pmlmepriv->lock); - /* s5. Cancel assoc_timer */ - timer_delete_sync(&pmlmepriv->assoc_timer); -} - -void rtw_joinbss_event_callback(struct adapter *adapter, u8 *pbuf) -{ - struct wlan_network *pnetwork = (struct wlan_network *)pbuf; - - mlmeext_joinbss_event_callback(adapter, pnetwork->join_res); - - rtw_os_xmit_schedule(adapter); -} - -/* FOR STA, AP , AD-HOC mode */ -void rtw_sta_media_status_rpt(struct adapter *adapter, struct sta_info *psta, u32 mstatus) -{ - u16 media_status_rpt; - - if (!psta) - return; - - media_status_rpt = (u16)((psta->mac_id << 8) | mstatus); /* MACID|OPMODE:1 connect */ - rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status_rpt); -} - -void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf) -{ - struct sta_info *psta; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct stassoc_event *pstassoc = (struct stassoc_event *)pbuf; - struct wlan_network *cur_network = &pmlmepriv->cur_network; - struct wlan_network *ptarget_wlan = NULL; - - if (!rtw_access_ctrl(adapter, pstassoc->macaddr)) - return; - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - psta = rtw_get_stainfo(&adapter->stapriv, pstassoc->macaddr); - if (psta) { - u8 *passoc_req = NULL; - u32 assoc_req_len = 0; - - rtw_sta_media_status_rpt(adapter, psta, 1); - - ap_sta_info_defer_update(adapter, psta); - - /* report to upper layer */ - spin_lock_bh(&psta->lock); - if (psta->passoc_req && psta->assoc_req_len > 0) { - passoc_req = kmemdup(psta->passoc_req, psta->assoc_req_len, GFP_ATOMIC); - if (passoc_req) { - assoc_req_len = psta->assoc_req_len; - - kfree(psta->passoc_req); - psta->passoc_req = NULL; - psta->assoc_req_len = 0; - } - } - spin_unlock_bh(&psta->lock); - - if (passoc_req && assoc_req_len > 0) { - rtw_cfg80211_indicate_sta_assoc(adapter, passoc_req, assoc_req_len); - - kfree(passoc_req); - } - } - return; - } - - /* for AD-HOC mode */ - psta = rtw_get_stainfo(&adapter->stapriv, pstassoc->macaddr); - if (psta) { - /* the sta have been in sta_info_queue => do nothing */ - - return; /* between drv has received this event before and fw have not yet to set key to CAM_ENTRY) */ - } - - psta = rtw_alloc_stainfo(&adapter->stapriv, pstassoc->macaddr); - if (!psta) - return; - - /* to do : init sta_info variable */ - psta->qos_option = 0; - psta->mac_id = (uint)pstassoc->cam_id; - - /* for ad-hoc mode */ - rtw_hal_set_odm_var(adapter, HAL_ODM_STA_INFO, psta, true); - - rtw_sta_media_status_rpt(adapter, psta, 1); - - if (adapter->securitypriv.dot11_auth_algrthm == dot11_auth_algrthm_8021x) - psta->dot118021XPrivacy = adapter->securitypriv.dot11_privacy_algrthm; - - psta->ieee8021x_blocked = false; - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - if (adapter->stapriv.asoc_sta_count == 2) { - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, cur_network->network.mac_address); - pmlmepriv->cur_network_scanned = ptarget_wlan; - if (ptarget_wlan) - ptarget_wlan->fixed = true; - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - /* a sta + bc/mc_stainfo (not Ibss_stainfo) */ - rtw_indicate_connect(adapter); - } - } - - spin_unlock_bh(&pmlmepriv->lock); - - mlmeext_sta_add_event_callback(adapter, psta); -} - -void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf) -{ - int mac_id = (-1); - struct sta_info *psta; - struct wlan_network *pwlan = NULL; - struct wlan_bssid_ex *pdev_network = NULL; - u8 *pibss = NULL; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct stadel_event *pstadel = (struct stadel_event *)pbuf; - struct wlan_network *tgt_network = &pmlmepriv->cur_network; - struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - psta = rtw_get_stainfo(&adapter->stapriv, pstadel->macaddr); - if (psta) - mac_id = psta->mac_id; - else - mac_id = pstadel->mac_id; - - if (mac_id >= 0) { - u16 media_status; - - media_status = (mac_id << 8) | 0; /* MACID|OPMODE:0 means disconnect */ - /* for STA, AP, ADHOC mode, report disconnect status to FW */ - rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status); - } - - /* if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) */ - if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) - return; - - mlmeext_sta_del_event_callback(adapter); - - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - u16 reason = *((unsigned short *)(pstadel->rsvd)); - bool roam = false; - struct wlan_network *roam_target = NULL; - - if (adapter->registrypriv.wifi_spec == 1) { - roam = false; - } else if (reason == WLAN_REASON_EXPIRATION_CHK && rtw_chk_roam_flags(adapter, RTW_ROAM_ON_EXPIRED)) { - roam = true; - } else if (reason == WLAN_REASON_ACTIVE_ROAM && rtw_chk_roam_flags(adapter, RTW_ROAM_ACTIVE)) { - roam = true; - roam_target = pmlmepriv->roam_network; - } - - if (roam) { - if (rtw_to_roam(adapter) > 0) - rtw_dec_to_roam(adapter); /* this stadel_event is caused by roaming, decrease to_roam */ - else if (rtw_to_roam(adapter) == 0) - rtw_set_to_roam(adapter, adapter->registrypriv.max_roaming_times); - } else { - rtw_set_to_roam(adapter, 0); - } - - rtw_free_uc_swdec_pending_queue(adapter); - - rtw_free_assoc_resources(adapter, 1); - rtw_indicate_disconnect(adapter); - - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - /* remove the network entry in scanned_queue */ - pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.mac_address); - if (pwlan) { - pwlan->fixed = false; - rtw_free_network_nolock(adapter, pwlan); - } - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - - _rtw_roaming(adapter, roam_target); - } - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - rtw_free_stainfo(adapter, psta); - - if (adapter->stapriv.asoc_sta_count == 1) {/* a sta + bc/mc_stainfo (not Ibss_stainfo) */ - u8 ret = _SUCCESS; - - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - /* free old ibss network */ - pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.mac_address); - if (pwlan) { - pwlan->fixed = false; - rtw_free_network_nolock(adapter, pwlan); - } - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - /* re-create ibss */ - pdev_network = &adapter->registrypriv.dev_network; - pibss = adapter->registrypriv.dev_network.mac_address; - - memcpy(pdev_network, &tgt_network->network, get_wlan_bssid_ex_sz(&tgt_network->network)); - - memcpy(&pdev_network->ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); - - rtw_update_registrypriv_dev_network(adapter); - - rtw_generate_random_ibss(pibss); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { - set_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE); - _clr_fwstate_(pmlmepriv, WIFI_ADHOC_STATE); - } - - ret = rtw_createbss_cmd(adapter); - if (ret != _SUCCESS) - goto unlock; - } - } - -unlock: - spin_unlock_bh(&pmlmepriv->lock); -} - -void rtw_cpwm_event_callback(struct adapter *padapter, u8 *pbuf) -{ - struct reportpwrstate_parm *preportpwrstate; - - preportpwrstate = (struct reportpwrstate_parm *)pbuf; - preportpwrstate->state |= (u8)(adapter_to_pwrctl(padapter)->cpwm_tog + 0x80); - cpwm_int_hdl(padapter, preportpwrstate); -} - -void rtw_wmm_event_callback(struct adapter *padapter, u8 *pbuf) -{ - WMMOnAssocRsp(padapter); -} - -/* - * _rtw_join_timeout_handler - Timeout/failure handler for CMD JoinBss - * @adapter: pointer to struct adapter structure - */ -void _rtw_join_timeout_handler(struct timer_list *t) -{ - struct adapter *adapter = timer_container_of(adapter, t, - mlmepriv.assoc_timer); - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - - if (adapter->driver_stopped || adapter->bSurpriseRemoved) - return; - - spin_lock_bh(&pmlmepriv->lock); - - if (rtw_to_roam(adapter) > 0) { /* join timeout caused by roaming */ - while (1) { - rtw_dec_to_roam(adapter); - if (rtw_to_roam(adapter) != 0) { /* try another */ - int do_join_r; - - do_join_r = rtw_do_join(adapter); - if (do_join_r != _SUCCESS) - continue; - - break; - } - - rtw_indicate_disconnect(adapter); - break; - } - - } else { - rtw_indicate_disconnect(adapter); - free_scanqueue(pmlmepriv);/* */ - - /* indicate disconnect for the case that join_timeout and check_fwstate != FW_LINKED */ - rtw_cfg80211_indicate_disconnect(adapter); - } - - spin_unlock_bh(&pmlmepriv->lock); -} - -/* - * rtw_scan_timeout_handler - Timeout/Failure handler for CMD SiteSurvey - * @adapter: pointer to struct adapter structure - */ -void rtw_scan_timeout_handler(struct timer_list *t) -{ - struct adapter *adapter = timer_container_of(adapter, t, - mlmepriv.scan_to_timer); - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - - spin_lock_bh(&pmlmepriv->lock); - - _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); - - spin_unlock_bh(&pmlmepriv->lock); - - rtw_indicate_scan_done(adapter, true); -} - -void rtw_mlme_reset_auto_scan_int(struct adapter *adapter) -{ - struct mlme_priv *mlme = &adapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (pmlmeinfo->VHT_enable) { - /* disable auto scan when connect to 11AC AP */ - mlme->auto_scan_int_ms = 0; - } else if (adapter->registrypriv.wifi_spec && is_client_associated_to_ap(adapter)) { - mlme->auto_scan_int_ms = 60 * 1000; - } else if (rtw_chk_roam_flags(adapter, RTW_ROAM_ACTIVE)) { - if (check_fwstate(mlme, WIFI_STATION_STATE) && check_fwstate(mlme, _FW_LINKED)) - mlme->auto_scan_int_ms = mlme->roam_scan_int_ms; - } else { - mlme->auto_scan_int_ms = 0; /* disabled */ - } -} - -static void rtw_auto_scan_handler(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - rtw_mlme_reset_auto_scan_int(padapter); - - if (pmlmepriv->auto_scan_int_ms != 0 && - jiffies_to_msecs(jiffies - pmlmepriv->scan_start_time) > pmlmepriv->auto_scan_int_ms) { - if (!padapter->registrypriv.wifi_spec) { - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) - goto exit; - - if (pmlmepriv->link_detect_info.busy_traffic) - goto exit; - } - - rtw_set_802_11_bssid_list_scan(padapter, NULL, 0); - } - -exit: - return; -} - -void rtw_dynamic_check_timer_handler(struct adapter *adapter) -{ - if (!adapter) - return; - - if (!adapter->hw_init_completed) - return; - - if (adapter->driver_stopped || adapter->bSurpriseRemoved) - return; - - if (adapter->net_closed) - return; - - if ((adapter_to_pwrctl(adapter)->fw_current_in_ps_mode) && - !(hal_btcoex_IsBtControlLps(adapter)) - ) { - bool should_enter_ps; - - linked_status_chk(adapter); - - should_enter_ps = traffic_status_watchdog(adapter, true); - if (should_enter_ps) { - /* rtw_lps_ctrl_wk_cmd(adapter, LPS_CTRL_ENTER, 1); */ - rtw_hal_dm_watchdog_in_lps(adapter); - } else { - /* call rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1) in traffic_status_watchdog() */ - } - - } else { - rtw_dynamic_chk_wk_cmd(adapter); - } - - /* auto site survey */ - rtw_auto_scan_handler(adapter); -} - -inline bool rtw_is_scan_deny(struct adapter *adapter) -{ - struct mlme_priv *mlmepriv = &adapter->mlmepriv; - - return (atomic_read(&mlmepriv->set_scan_deny) != 0) ? true : false; -} - -inline void rtw_clear_scan_deny(struct adapter *adapter) -{ - struct mlme_priv *mlmepriv = &adapter->mlmepriv; - - atomic_set(&mlmepriv->set_scan_deny, 0); -} - -void rtw_set_scan_deny(struct adapter *adapter, u32 ms) -{ - struct mlme_priv *mlmepriv = &adapter->mlmepriv; - - atomic_set(&mlmepriv->set_scan_deny, 1); - _set_timer(&mlmepriv->set_scan_deny_timer, ms); -} - -/* - * Select a new roaming candidate from the original @param candidate and @param competitor - * @return true: candidate is updated - * @return false: candidate is not updated - */ -static int rtw_check_roaming_candidate(struct mlme_priv *mlme - , struct wlan_network **candidate, struct wlan_network *competitor) -{ - int updated = false; - struct adapter *adapter = container_of(mlme, struct adapter, mlmepriv); - - if (!is_same_ess(&competitor->network, &mlme->cur_network.network)) - goto exit; - - if (!rtw_is_desired_network(adapter, competitor)) - goto exit; - - /* got specific addr to roam */ - if (!is_zero_ether_addr(mlme->roam_tgt_addr)) { - if (!memcmp(mlme->roam_tgt_addr, competitor->network.mac_address, ETH_ALEN)) - goto update; - else - goto exit; - } - if (jiffies_to_msecs(jiffies - competitor->last_scanned) >= mlme->roam_scanr_exp_ms) - goto exit; - - if (competitor->network.rssi - mlme->cur_network_scanned->network.rssi < mlme->roam_rssi_diff_th) - goto exit; - - if (*candidate && (*candidate)->network.rssi >= competitor->network.rssi) - goto exit; - -update: - *candidate = competitor; - updated = true; - -exit: - return updated; -} - -int rtw_select_roaming_candidate(struct mlme_priv *mlme) -{ - int ret = _FAIL; - struct list_head *phead; - struct __queue *queue = &mlme->scanned_queue; - struct wlan_network *pnetwork = NULL; - struct wlan_network *candidate = NULL; - - if (!mlme->cur_network_scanned) { - WARN_ON(1); - return ret; - } - - spin_lock_bh(&mlme->scanned_queue.lock); - phead = get_list_head(queue); - - list_for_each(mlme->pscanned, phead) { - pnetwork = list_entry(mlme->pscanned, struct wlan_network, - list); - - rtw_check_roaming_candidate(mlme, &candidate, pnetwork); - } - - if (!candidate) { - ret = _FAIL; - goto exit; - } else { - mlme->roam_network = candidate; - - if (!memcmp(candidate->network.mac_address, mlme->roam_tgt_addr, ETH_ALEN)) - eth_zero_addr(mlme->roam_tgt_addr); - } - - ret = _SUCCESS; -exit: - spin_unlock_bh(&mlme->scanned_queue.lock); - - return ret; -} - -/* - * Select a new join candidate from the original @param candidate and @param competitor - * @return true: candidate is updated - * @return false: candidate is not updated - */ -static int rtw_check_join_candidate(struct mlme_priv *mlme - , struct wlan_network **candidate, struct wlan_network *competitor) -{ - int updated = false; - struct adapter *adapter = container_of(mlme, struct adapter, mlmepriv); - - /* check bssid, if needed */ - if (mlme->assoc_by_bssid) { - if (memcmp(competitor->network.mac_address, mlme->assoc_bssid, ETH_ALEN)) - goto exit; - } - - /* check ssid, if needed */ - if (mlme->assoc_ssid.ssid[0] && mlme->assoc_ssid.ssid_length) { - if (competitor->network.ssid.ssid_length != mlme->assoc_ssid.ssid_length || - memcmp(competitor->network.ssid.ssid, mlme->assoc_ssid.ssid, mlme->assoc_ssid.ssid_length) - ) - goto exit; - } - - if (!rtw_is_desired_network(adapter, competitor)) - goto exit; - - if (rtw_to_roam(adapter) > 0) { - if (jiffies_to_msecs(jiffies - competitor->last_scanned) >= - mlme->roam_scanr_exp_ms || - !is_same_ess(&competitor->network, &mlme->cur_network.network)) - goto exit; - } - - if (!*candidate || (*candidate)->network.rssi < competitor->network.rssi) { - *candidate = competitor; - updated = true; - } - -exit: - return updated; -} - -/* - * Calling context: - * The caller of the sub-routine will be in critical section... - * The caller must hold the following spinlock - * pmlmepriv->lock - */ - -int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv) -{ - int ret; - struct list_head *phead; - struct adapter *adapter; - struct __queue *queue = &pmlmepriv->scanned_queue; - struct wlan_network *pnetwork = NULL; - struct wlan_network *candidate = NULL; - - adapter = (struct adapter *)pmlmepriv->nic_hdl; - - spin_lock_bh(&pmlmepriv->scanned_queue.lock); - - if (pmlmepriv->roam_network) { - candidate = pmlmepriv->roam_network; - pmlmepriv->roam_network = NULL; - goto candidate_exist; - } - - phead = get_list_head(queue); - list_for_each(pmlmepriv->pscanned, phead) { - pnetwork = list_entry(pmlmepriv->pscanned, - struct wlan_network, list); - - rtw_check_join_candidate(pmlmepriv, &candidate, pnetwork); - } - - if (!candidate) { - ret = _FAIL; - goto exit; - } else { - goto candidate_exist; - } - -candidate_exist: - - /* check for situation of _FW_LINKED */ - if (check_fwstate(pmlmepriv, _FW_LINKED)) { - rtw_disassoc_cmd(adapter, 0, true); - rtw_indicate_disconnect(adapter); - rtw_free_assoc_resources(adapter, 0); - } - - set_fwstate(pmlmepriv, _FW_UNDER_LINKING); - ret = rtw_joinbss_cmd(adapter, candidate); - -exit: - spin_unlock_bh(&pmlmepriv->scanned_queue.lock); - return ret; -} - -signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv) -{ - struct cmd_obj *pcmd; - struct setauth_parm *psetauthparm; - struct cmd_priv *pcmdpriv = &adapter->cmdpriv; - signed int res = _SUCCESS; - - pcmd = kzalloc_obj(*pcmd); - if (!pcmd) { - res = _FAIL; /* try again */ - goto exit; - } - - psetauthparm = kzalloc_obj(*psetauthparm); - if (!psetauthparm) { - kfree(pcmd); - res = _FAIL; - goto exit; - } - - psetauthparm->mode = (unsigned char)psecuritypriv->dot11_auth_algrthm; - - pcmd->cmdcode = SET_AUTH_CMD; - pcmd->parmbuf = (unsigned char *)psetauthparm; - pcmd->cmdsz = (sizeof(struct setauth_parm)); - pcmd->rsp = NULL; - pcmd->rspsz = 0; - - INIT_LIST_HEAD(&pcmd->list); - - res = rtw_enqueue_cmd(pcmdpriv, pcmd); - -exit: - return res; -} - -signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, signed int keyid, u8 set_tx, bool enqueue) -{ - u8 keylen; - struct cmd_obj *pcmd; - struct setkey_parm *psetkeyparm; - struct cmd_priv *pcmdpriv = &adapter->cmdpriv; - signed int res = _SUCCESS; - - psetkeyparm = kzalloc_obj(*psetkeyparm); - if (!psetkeyparm) { - res = _FAIL; - goto exit; - } - - if (psecuritypriv->dot11_auth_algrthm == dot11_auth_algrthm_8021x) - psetkeyparm->algorithm = (unsigned char)psecuritypriv->dot118021XGrpPrivacy; - else - psetkeyparm->algorithm = (u8)psecuritypriv->dot11_privacy_algrthm; - - psetkeyparm->keyid = (u8)keyid;/* 0~3 */ - psetkeyparm->set_tx = set_tx; - if (is_wep_enc(psetkeyparm->algorithm)) - adapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid); - - switch (psetkeyparm->algorithm) { - case _WEP40_: - keylen = 5; - memcpy(&psetkeyparm->key[0], &psecuritypriv->dot11DefKey[keyid].skey[0], keylen); - break; - case _WEP104_: - keylen = 13; - memcpy(&psetkeyparm->key[0], &psecuritypriv->dot11DefKey[keyid].skey[0], keylen); - break; - case _TKIP_: - keylen = 16; - memcpy(&psetkeyparm->key, &psecuritypriv->dot118021XGrpKey[keyid], keylen); - psetkeyparm->grpkey = 1; - break; - case _AES_: - keylen = 16; - memcpy(&psetkeyparm->key, &psecuritypriv->dot118021XGrpKey[keyid], keylen); - psetkeyparm->grpkey = 1; - break; - default: - res = _FAIL; - kfree(psetkeyparm); - goto exit; - } - - if (enqueue) { - pcmd = kzalloc_obj(*pcmd); - if (!pcmd) { - kfree(psetkeyparm); - res = _FAIL; /* try again */ - goto exit; - } - - pcmd->cmdcode = SET_KEY_CMD; - pcmd->parmbuf = (u8 *)psetkeyparm; - pcmd->cmdsz = (sizeof(struct setkey_parm)); - pcmd->rsp = NULL; - pcmd->rspsz = 0; - - INIT_LIST_HEAD(&pcmd->list); - - res = rtw_enqueue_cmd(pcmdpriv, pcmd); - } else { - setkey_hdl(adapter, (u8 *)psetkeyparm); - kfree(psetkeyparm); - } -exit: - return res; -} - -/* adjust ies for rtw_joinbss_cmd in WMM */ -int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len) -{ - unsigned int ielength = 0; - unsigned int i, j; - - i = 12; /* after the fixed IE */ - while (i < in_len) { - ielength = initial_out_len; - - if (i + 5 < in_len && - in_ie[i] == 0xDD && in_ie[i + 2] == 0x00 && - in_ie[i + 3] == 0x50 && in_ie[i + 4] == 0xF2 && - in_ie[i + 5] == 0x02) { - for (j = i; j < i + 9; j++) { - out_ie[ielength] = in_ie[j]; - ielength++; - } - out_ie[initial_out_len + 1] = 0x07; - out_ie[initial_out_len + 6] = 0x00; - out_ie[initial_out_len + 8] = 0x00; - - break; - } - - i += (in_ie[i + 1] + 2); /* to the next IE element */ - } - - return ielength; -} - -/* Ported from 8185: IsInPreAuthKeyList(). - * (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) - * Added by Annie, 2006-05-07. - * - * Search by BSSID, - * - * Return Value: - * -1: if there is no pre-auth key in the table - * >=0: if there is pre-auth key, and return the entry id - */ -static int SecIsInPMKIDList(struct adapter *Adapter, u8 *bssid) -{ - struct security_priv *p = &Adapter->securitypriv; - int i; - - for (i = 0; i < NUM_PMKID_CACHE; i++) - if ((p->PMKIDList[i].bUsed) && - (!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN))) - return i; - return -1; -} - -/* */ -/* Check the RSN IE length */ -/* If the RSN IE length <= 20, the RSN IE didn't include the PMKID information */ -/* 0-11th element in the array are the fixed IE */ -/* 12th element in the array is the IE */ -/* 13th element in the array is the IE length */ -/* */ - -static int rtw_append_pmkid(struct adapter *Adapter, int iEntry, u8 *ie, uint ie_len) -{ - struct security_priv *psecuritypriv = &Adapter->securitypriv; - - if (ie[13] <= 20) { - /* The RSN IE didn't include the PMK ID, append the PMK information */ - ie[ie_len] = 1; - ie_len++; - ie[ie_len] = 0; /* PMKID count = 0x0100 */ - ie_len++; - memcpy(&ie[ie_len], &psecuritypriv->PMKIDList[iEntry].PMKID, 16); - ie_len += 16; - ie[13] += 18;/* PMKID length = 2+16 */ - } - return ie_len; -} - -static void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie) -{ - uint len; - u8 *buff, *p; - union iwreq_data wrqu; - - buff = NULL; - if (authmode == WLAN_EID_VENDOR_SPECIFIC) { - buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC); - if (!buff) - return; - - p = buff; - - p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), "ASSOCINFO(ReqIEs ="); - - len = sec_ie[1] + 2; - len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX; - - p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), " %*ph", len, sec_ie); - - p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), ")"); - - memset(&wrqu, 0, sizeof(wrqu)); - - wrqu.data.length = p - buff; - - wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? wrqu.data.length : IW_CUSTOM_MAX; - - kfree(buff); - } -} - -signed int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len) -{ - u8 authmode = 0x0; - uint ielength; - int iEntry; - - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct security_priv *psecuritypriv = &adapter->securitypriv; - uint ndisauthmode = psecuritypriv->ndisauthtype; - - /* copy fixed ie only */ - memcpy(out_ie, in_ie, 12); - ielength = 12; - if ((ndisauthmode == Ndis802_11AuthModeWPA) || (ndisauthmode == Ndis802_11AuthModeWPAPSK)) - authmode = WLAN_EID_VENDOR_SPECIFIC; - if ((ndisauthmode == Ndis802_11AuthModeWPA2) || (ndisauthmode == Ndis802_11AuthModeWPA2PSK)) - authmode = WLAN_EID_RSN; - - if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) { - memcpy(out_ie + ielength, psecuritypriv->wps_ie, psecuritypriv->wps_ie_len); - - ielength += psecuritypriv->wps_ie_len; - } else if ((authmode == WLAN_EID_VENDOR_SPECIFIC) || (authmode == WLAN_EID_RSN)) { - /* copy RSN or SSN */ - memcpy(&out_ie[ielength], &psecuritypriv->supplicant_ie[0], psecuritypriv->supplicant_ie[1] + 2); - ielength += psecuritypriv->supplicant_ie[1] + 2; - rtw_report_sec_ie(adapter, authmode, psecuritypriv->supplicant_ie); - } - - iEntry = SecIsInPMKIDList(adapter, pmlmepriv->assoc_bssid); - if (iEntry < 0) - return ielength; - - if (authmode == WLAN_EID_RSN) - ielength = rtw_append_pmkid(adapter, iEntry, out_ie, ielength); - - return ielength; -} - -void rtw_init_registrypriv_dev_network(struct adapter *adapter) -{ - struct registry_priv *pregistrypriv = &adapter->registrypriv; - struct eeprom_priv *peepriv = &adapter->eeprompriv; - struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network; - u8 *myhwaddr = myid(peepriv); - - memcpy(pdev_network->mac_address, myhwaddr, ETH_ALEN); - - memcpy(&pdev_network->ssid, &pregistrypriv->ssid, sizeof(struct ndis_802_11_ssid)); - - pdev_network->configuration.length = sizeof(struct ndis_802_11_conf); - pdev_network->configuration.beacon_period = 100; -} - -void rtw_update_registrypriv_dev_network(struct adapter *adapter) -{ - int sz = 0; - struct registry_priv *pregistrypriv = &adapter->registrypriv; - struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network; - struct security_priv *psecuritypriv = &adapter->securitypriv; - struct wlan_network *cur_network = &adapter->mlmepriv.cur_network; - - pdev_network->privacy = (psecuritypriv->dot11_privacy_algrthm > 0 ? 1 : 0) ; /* adhoc no 802.1x */ - - pdev_network->rssi = 0; - - pdev_network->configuration.ds_config = (pregistrypriv->channel); - - if (cur_network->network.infrastructure_mode == NL80211_IFTYPE_ADHOC) - pdev_network->configuration.atim_window = (0); - - pdev_network->infrastructure_mode = (cur_network->network.infrastructure_mode); - - /* 1. Supported rates */ - /* 2. IE */ - - /* rtw_set_supported_rate(pdev_network->supported_rates, pregistrypriv->wireless_mode) ; will be called in rtw_generate_ie */ - sz = rtw_generate_ie(pregistrypriv); - - pdev_network->ie_length = sz; - - pdev_network->length = get_wlan_bssid_ex_sz((struct wlan_bssid_ex *)pdev_network); - - /* notes: translate ie_length & length after assign the length to cmdsz in createbss_cmd(); */ - /* pdev_network->ie_length = cpu_to_le32(sz); */ -} - -/* the function is at passive_level */ -void rtw_joinbss_reset(struct adapter *padapter) -{ - u8 threshold; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - - /* todo: if you want to do something io/reg/hw setting before join_bss, please add code here */ - - pmlmepriv->num_FortyMHzIntolerant = 0; - - pmlmepriv->num_sta_no_ht = 0; - - phtpriv->ampdu_enable = false;/* reset to disabled */ - - /* TH = 1 => means that invalidate usb rx aggregation */ - /* TH = 0 => means that validate usb rx aggregation, use init value. */ - if (phtpriv->ht_option) { - if (padapter->registrypriv.wifi_spec == 1) - threshold = 1; - else - threshold = 0; - rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, (u8 *)(&threshold)); - } else { - threshold = 1; - rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, (u8 *)(&threshold)); - } -} - -void rtw_ht_use_default_setting(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - bool bHwLDPCSupport = false, bHwSTBCSupport = false; - bool bHwSupportBeamformer = false, bHwSupportBeamformee = false; - - if (pregistrypriv->wifi_spec) - phtpriv->bss_coexist = 1; - else - phtpriv->bss_coexist = 0; - - phtpriv->sgi_40m = TEST_FLAG(pregistrypriv->short_gi, BIT(1)) ? true : false; - phtpriv->sgi_20m = TEST_FLAG(pregistrypriv->short_gi, BIT(0)) ? true : false; - - /* LDPC support */ - rtw_hal_get_def_var(padapter, HAL_DEF_RX_LDPC, (u8 *)&bHwLDPCSupport); - CLEAR_FLAGS(phtpriv->ldpc_cap); - if (bHwLDPCSupport) { - if (TEST_FLAG(pregistrypriv->ldpc_cap, BIT(4))) - SET_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_RX); - } - rtw_hal_get_def_var(padapter, HAL_DEF_TX_LDPC, (u8 *)&bHwLDPCSupport); - if (bHwLDPCSupport) { - if (TEST_FLAG(pregistrypriv->ldpc_cap, BIT(5))) - SET_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX); - } - - /* STBC */ - rtw_hal_get_def_var(padapter, HAL_DEF_TX_STBC, (u8 *)&bHwSTBCSupport); - CLEAR_FLAGS(phtpriv->stbc_cap); - if (bHwSTBCSupport) { - if (TEST_FLAG(pregistrypriv->stbc_cap, BIT(5))) - SET_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX); - } - rtw_hal_get_def_var(padapter, HAL_DEF_RX_STBC, (u8 *)&bHwSTBCSupport); - if (bHwSTBCSupport) { - if (TEST_FLAG(pregistrypriv->stbc_cap, BIT(4))) - SET_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_RX); - } - - /* Beamforming setting */ - rtw_hal_get_def_var(padapter, HAL_DEF_EXPLICIT_BEAMFORMER, (u8 *)&bHwSupportBeamformer); - rtw_hal_get_def_var(padapter, HAL_DEF_EXPLICIT_BEAMFORMEE, (u8 *)&bHwSupportBeamformee); - CLEAR_FLAGS(phtpriv->beamform_cap); - if (TEST_FLAG(pregistrypriv->beamform_cap, BIT(4)) && bHwSupportBeamformer) - SET_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE); - - if (TEST_FLAG(pregistrypriv->beamform_cap, BIT(5)) && bHwSupportBeamformee) - SET_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE); -} - -void rtw_build_wmm_ie_ht(struct adapter *padapter, u8 *out_ie, uint *pout_len) -{ - unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00}; - int out_len; - - if (padapter->mlmepriv.qospriv.qos_option == 0) { - out_len = *pout_len; - rtw_set_ie(out_ie + out_len, WLAN_EID_VENDOR_SPECIFIC, - _WMM_IE_Length_, WMM_IE, pout_len); - - padapter->mlmepriv.qospriv.qos_option = 1; - } -} - -/* the function is >= passive_level */ -unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel) -{ - u32 ielen, out_len; - enum ieee80211_max_ampdu_length_exp max_rx_ampdu_factor; - unsigned char *p; - struct ieee80211_ht_cap ht_capie; - u8 cbw40_enable = 0, stbc_rx_enable = 0, operation_bw = 0; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - phtpriv->ht_option = false; - - out_len = *pout_len; - - memset(&ht_capie, 0, sizeof(struct ieee80211_ht_cap)); - - ht_capie.cap_info = cpu_to_le16(IEEE80211_HT_CAP_DSSSCCK40); - - if (phtpriv->sgi_20m) - ht_capie.cap_info |= cpu_to_le16(IEEE80211_HT_CAP_SGI_20); - - /* Get HT BW */ - if (!in_ie) { - /* TDLS: TODO 20/40 issue */ - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - operation_bw = padapter->mlmeextpriv.cur_bwmode; - if (operation_bw > CHANNEL_WIDTH_40) - operation_bw = CHANNEL_WIDTH_40; - } else { - /* TDLS: TODO 40? */ - operation_bw = CHANNEL_WIDTH_40; - } - } else { - p = rtw_get_ie(in_ie, WLAN_EID_HT_OPERATION, &ielen, in_len); - if (p && (ielen == sizeof(struct ieee80211_ht_addt_info))) { - struct HT_info_element *pht_info = (struct HT_info_element *)(p + 2); - - if (pht_info->infos[0] & BIT(2)) { - switch (pht_info->infos[0] & 0x3) { - case 1: - case 3: - operation_bw = CHANNEL_WIDTH_40; - break; - default: - operation_bw = CHANNEL_WIDTH_20; - break; - } - } else { - operation_bw = CHANNEL_WIDTH_20; - } - } - } - - /* to disable 40M Hz support while gd_bw_40MHz_en = 0 */ - if ((pregistrypriv->bw_mode & 0x0f) > 0) - cbw40_enable = 1; - - if ((cbw40_enable == 1) && (operation_bw == CHANNEL_WIDTH_40)) { - ht_capie.cap_info |= cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH); - if (phtpriv->sgi_40m) - ht_capie.cap_info |= cpu_to_le16(IEEE80211_HT_CAP_SGI_40); - } - - if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX)) - ht_capie.cap_info |= cpu_to_le16(IEEE80211_HT_CAP_TX_STBC); - - /* todo: disable SM power save mode */ - ht_capie.cap_info |= cpu_to_le16(IEEE80211_HT_CAP_SM_PS); - - if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_RX)) { - if ((channel <= 14 && pregistrypriv->rx_stbc == 0x1) || /* enable for 2.4GHz */ - (pregistrypriv->wifi_spec == 1)) - stbc_rx_enable = 1; - } - - /* fill default supported_mcs_set */ - memcpy(&ht_capie.mcs, pmlmeext->default_supported_mcs_set, 16); - - /* update default supported_mcs_set */ - if (stbc_rx_enable) - ht_capie.cap_info |= cpu_to_le16(IEEE80211_HT_CAP_RX_STBC_1R);/* RX STBC One spatial stream */ - - set_mcs_rate_by_mask(ht_capie.mcs.rx_mask, MCS_RATE_1R); - - { - u32 rx_packet_offset, max_recvbuf_sz; - - rtw_hal_get_def_var(padapter, HAL_DEF_RX_PACKET_OFFSET, &rx_packet_offset); - rtw_hal_get_def_var(padapter, HAL_DEF_MAX_RECVBUF_SZ, &max_recvbuf_sz); - } - - if (padapter->driver_rx_ampdu_factor != 0xFF) - max_rx_ampdu_factor = - (enum ieee80211_max_ampdu_length_exp)padapter->driver_rx_ampdu_factor; - else - rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, - &max_rx_ampdu_factor); - - ht_capie.ampdu_params_info = (max_rx_ampdu_factor & 0x03); - - if (padapter->securitypriv.dot11_privacy_algrthm == _AES_) - ht_capie.ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2)); - else - ht_capie.ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00); - - rtw_set_ie(out_ie + out_len, WLAN_EID_HT_CAPABILITY, - sizeof(struct ieee80211_ht_cap), (unsigned char *)&ht_capie, pout_len); - - phtpriv->ht_option = true; - - if (in_ie) { - p = rtw_get_ie(in_ie, WLAN_EID_HT_OPERATION, &ielen, in_len); - if (p && (ielen == sizeof(struct ieee80211_ht_addt_info))) { - out_len = *pout_len; - rtw_set_ie(out_ie + out_len, WLAN_EID_HT_OPERATION, ielen, p + 2, pout_len); - } - } - - return phtpriv->ht_option; -} - -/* the function is > passive_level (in critical_section) */ -void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len, u8 channel) -{ - u8 *p, max_ampdu_sz; - int len; - struct ieee80211_ht_cap *pht_capie; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 cbw40_enable = 0; - - if (!phtpriv->ht_option) - return; - - if ((!pmlmeinfo->HT_info_enable) || (!pmlmeinfo->HT_caps_enable)) - return; - - /* maybe needs check if ap supports rx ampdu. */ - if (!(phtpriv->ampdu_enable) && pregistrypriv->ampdu_enable == 1) - phtpriv->ampdu_enable = true; - - /* check Max Rx A-MPDU Size */ - len = 0; - p = rtw_get_ie(pie + sizeof(struct ndis_802_11_fix_ie), WLAN_EID_HT_CAPABILITY, &len, ie_len - sizeof(struct ndis_802_11_fix_ie)); - if (p && len > 0) { - pht_capie = (struct ieee80211_ht_cap *)(p + 2); - max_ampdu_sz = (pht_capie->ampdu_params_info & IEEE80211_HT_CAP_AMPDU_FACTOR); - max_ampdu_sz = 1 << (max_ampdu_sz + 3); /* max_ampdu_sz (kbytes); */ - - phtpriv->rx_ampdu_maxlen = max_ampdu_sz; - } - - len = 0; - p = rtw_get_ie(pie + sizeof(struct ndis_802_11_fix_ie), WLAN_EID_HT_OPERATION, &len, ie_len - sizeof(struct ndis_802_11_fix_ie)); - if (p && len > 0) { - /* todo: */ - } - - if ((pregistrypriv->bw_mode & 0x0f) > 0) - cbw40_enable = 1; - - /* update cur_bwmode & cur_ch_offset */ - if ((cbw40_enable) && - (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & - BIT(1)) && (pmlmeinfo->HT_info.infos[0] & BIT(2))) { - int i; - - /* update the MCS set */ - for (i = 0; i < 16; i++) - pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= pmlmeext->default_supported_mcs_set[i]; - - /* update the MCS rates */ - set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_1R); - - /* switch to the 40M Hz mode according to the AP */ - /* pmlmeext->cur_bwmode = CHANNEL_WIDTH_40; */ - switch ((pmlmeinfo->HT_info.infos[0] & 0x3)) { - case EXTCHNL_OFFSET_UPPER: - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER; - break; - - case EXTCHNL_OFFSET_LOWER: - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER; - break; - - default: - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - break; - } - } - - /* */ - /* Config SM Power Save setting */ - /* */ - pmlmeinfo->SM_PS = - (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & - 0x0C) >> 2; - - /* */ - /* Config current HT Protection mode. */ - /* */ - pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; -} - -void rtw_issue_addbareq_cmd(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - u8 issued; - int priority; - struct sta_info *psta; - struct ht_priv *phtpriv; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - s32 bmcst = is_multicast_ether_addr(pattrib->ra); - - if (bmcst || (padapter->mlmepriv.link_detect_info.num_tx_ok_in_period < 100)) - return; - - priority = pattrib->priority; - - psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); - if (pattrib->psta != psta) - return; - - if (!psta) - return; - - if (!(psta->state & _FW_LINKED)) - return; - - phtpriv = &psta->htpriv; - - if (phtpriv->ht_option && phtpriv->ampdu_enable) { - issued = (phtpriv->agg_enable_bitmap >> priority) & 0x1; - issued |= (phtpriv->candidate_tid_bitmap >> priority) & 0x1; - - if (issued == 0) { - psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority); - rtw_addbareq_cmd(padapter, (u8) priority, pattrib->ra); - } - } -} - -void rtw_append_exented_cap(struct adapter *padapter, u8 *out_ie, uint *pout_len) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - u8 cap_content[8] = {0}; - - if (phtpriv->bss_coexist) - SET_EXT_CAPABILITY_ELE_BSS_COEXIST(cap_content, 1); - - rtw_set_ie(out_ie + *pout_len, WLAN_EID_EXT_CAPABILITY, 8, cap_content, pout_len); -} - -inline void rtw_set_to_roam(struct adapter *adapter, u8 to_roam) -{ - if (to_roam == 0) - adapter->mlmepriv.to_join = false; - adapter->mlmepriv.to_roam = to_roam; -} - -inline u8 rtw_dec_to_roam(struct adapter *adapter) -{ - adapter->mlmepriv.to_roam--; - return adapter->mlmepriv.to_roam; -} - -inline u8 rtw_to_roam(struct adapter *adapter) -{ - return adapter->mlmepriv.to_roam; -} - -void rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - spin_lock_bh(&pmlmepriv->lock); - _rtw_roaming(padapter, tgt_network); - spin_unlock_bh(&pmlmepriv->lock); -} - -void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *cur_network = &pmlmepriv->cur_network; - - if (rtw_to_roam(padapter) > 0) { - memcpy(&pmlmepriv->assoc_ssid, &cur_network->network.ssid, sizeof(struct ndis_802_11_ssid)); - - pmlmepriv->assoc_by_bssid = false; - - while (rtw_do_join(padapter) != _SUCCESS) { - rtw_dec_to_roam(padapter); - if (rtw_to_roam(padapter) <= 0) { - rtw_indicate_disconnect(padapter); - break; - } - } - } -} - -bool rtw_linked_check(struct adapter *padapter) -{ - if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) || - check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) { - if (padapter->stapriv.asoc_sta_count > 2) - return true; - } else { /* Station mode */ - if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) - return true; - } - return false; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c deleted file mode 100644 index e965133d94ab..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +++ /dev/null @@ -1,5901 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include -#include -#include -#include - -static struct mlme_handler mlme_sta_tbl[] = { - {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq}, - {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp}, - {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq}, - {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp}, - {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq}, - {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp}, - - /* below 2 are reserved */ - {0, "DoReserved", &DoReserved}, - {0, "DoReserved", &DoReserved}, - {WIFI_BEACON, "OnBeacon", &OnBeacon}, - {WIFI_ATIM, "OnATIM", &OnAtim}, - {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc}, - {WIFI_AUTH, "OnAuth", &OnAuthClient}, - {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth}, - {WIFI_ACTION, "OnAction", &OnAction}, - {WIFI_ACTION_NOACK, "OnActionNoAck", &OnAction}, -}; - -static struct action_handler OnAction_tbl[] = { - {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct}, - {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &DoReserved}, - {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &DoReserved}, - {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back}, - {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public}, - {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved}, - {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &DoReserved}, - {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht}, - {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &OnAction_sa_query}, - {RTW_WLAN_CATEGORY_UNPROTECTED_WNM, "ACTION_UNPROTECTED_WNM", &DoReserved}, - {RTW_WLAN_CATEGORY_SELF_PROTECTED, "ACTION_SELF_PROTECTED", &DoReserved}, - {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &DoReserved}, - {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &DoReserved}, -}; - -static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; - -/* OUI definitions for the vendor specific IE */ -unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01}; -unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02}; -unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04}; -unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09}; -unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A}; - -unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01}; -unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01}; - -static unsigned char REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20}; - -/* ChannelPlan definitions */ -static struct rt_channel_plan_2g RTW_ChannelPlan2G[RT_CHANNEL_DOMAIN_2G_MAX] = { - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x00, RT_CHANNEL_DOMAIN_2G_WORLD , Passive scan CH 12, 13 */ - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x01, RT_CHANNEL_DOMAIN_2G_ETSI1 */ - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, /* 0x02, RT_CHANNEL_DOMAIN_2G_FCC1 */ - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, /* 0x03, RT_CHANNEL_DOMAIN_2G_MIKK1 */ - {{10, 11, 12, 13}, 4}, /* 0x04, RT_CHANNEL_DOMAIN_2G_ETSI2 */ - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, /* 0x05, RT_CHANNEL_DOMAIN_2G_GLOBAL , Passive scan CH 12, 13, 14 */ - {{}, 0}, /* 0x06, RT_CHANNEL_DOMAIN_2G_NULL */ -}; - -static struct rt_channel_plan_map RTW_ChannelPlanMap[RT_CHANNEL_DOMAIN_MAX] = { - /* 0x00 ~ 0x1F , Old Define ===== */ - {0x02}, /* 0x00, RT_CHANNEL_DOMAIN_FCC */ - {0x02}, /* 0x01, RT_CHANNEL_DOMAIN_IC */ - {0x01}, /* 0x02, RT_CHANNEL_DOMAIN_ETSI */ - {0x01}, /* 0x03, RT_CHANNEL_DOMAIN_SPAIN */ - {0x01}, /* 0x04, RT_CHANNEL_DOMAIN_FRANCE */ - {0x03}, /* 0x05, RT_CHANNEL_DOMAIN_MKK */ - {0x03}, /* 0x06, RT_CHANNEL_DOMAIN_MKK1 */ - {0x01}, /* 0x07, RT_CHANNEL_DOMAIN_ISRAEL */ - {0x03}, /* 0x08, RT_CHANNEL_DOMAIN_TELEC */ - {0x03}, /* 0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN */ - {0x00}, /* 0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13 */ - {0x02}, /* 0x0B, RT_CHANNEL_DOMAIN_TAIWAN */ - {0x01}, /* 0x0C, RT_CHANNEL_DOMAIN_CHINA */ - {0x02}, /* 0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO */ - {0x02}, /* 0x0E, RT_CHANNEL_DOMAIN_KOREA */ - {0x02}, /* 0x0F, RT_CHANNEL_DOMAIN_TURKEY */ - {0x01}, /* 0x10, RT_CHANNEL_DOMAIN_JAPAN */ - {0x02}, /* 0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS */ - {0x01}, /* 0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */ - {0x00}, /* 0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G */ - {0x02}, /* 0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS */ - {0x00}, /* 0x15, RT_CHANNEL_DOMAIN_ETSI_NO_DFS */ - {0x00}, /* 0x16, RT_CHANNEL_DOMAIN_KOREA_NO_DFS */ - {0x03}, /* 0x17, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */ - {0x06}, /* 0x18, RT_CHANNEL_DOMAIN_PAKISTAN_NO_DFS */ - {0x02}, /* 0x19, RT_CHANNEL_DOMAIN_TAIWAN2_NO_DFS */ - {0x00}, /* 0x1A, */ - {0x00}, /* 0x1B, */ - {0x00}, /* 0x1C, */ - {0x00}, /* 0x1D, */ - {0x00}, /* 0x1E, */ - {0x06}, /* 0x1F, RT_CHANNEL_DOMAIN_WORLD_WIDE_ONLY_5G */ - /* 0x20 ~ 0x7F , New Define ===== */ - {0x00}, /* 0x20, RT_CHANNEL_DOMAIN_WORLD_NULL */ - {0x01}, /* 0x21, RT_CHANNEL_DOMAIN_ETSI1_NULL */ - {0x02}, /* 0x22, RT_CHANNEL_DOMAIN_FCC1_NULL */ - {0x03}, /* 0x23, RT_CHANNEL_DOMAIN_MKK1_NULL */ - {0x04}, /* 0x24, RT_CHANNEL_DOMAIN_ETSI2_NULL */ - {0x02}, /* 0x25, RT_CHANNEL_DOMAIN_FCC1_FCC1 */ - {0x00}, /* 0x26, RT_CHANNEL_DOMAIN_WORLD_ETSI1 */ - {0x03}, /* 0x27, RT_CHANNEL_DOMAIN_MKK1_MKK1 */ - {0x00}, /* 0x28, RT_CHANNEL_DOMAIN_WORLD_KCC1 */ - {0x00}, /* 0x29, RT_CHANNEL_DOMAIN_WORLD_FCC2 */ - {0x00}, /* 0x2A, */ - {0x00}, /* 0x2B, */ - {0x00}, /* 0x2C, */ - {0x00}, /* 0x2D, */ - {0x00}, /* 0x2E, */ - {0x00}, /* 0x2F, */ - {0x00}, /* 0x30, RT_CHANNEL_DOMAIN_WORLD_FCC3 */ - {0x00}, /* 0x31, RT_CHANNEL_DOMAIN_WORLD_FCC4 */ - {0x00}, /* 0x32, RT_CHANNEL_DOMAIN_WORLD_FCC5 */ - {0x00}, /* 0x33, RT_CHANNEL_DOMAIN_WORLD_FCC6 */ - {0x02}, /* 0x34, RT_CHANNEL_DOMAIN_FCC1_FCC7 */ - {0x00}, /* 0x35, RT_CHANNEL_DOMAIN_WORLD_ETSI2 */ - {0x00}, /* 0x36, RT_CHANNEL_DOMAIN_WORLD_ETSI3 */ - {0x03}, /* 0x37, RT_CHANNEL_DOMAIN_MKK1_MKK2 */ - {0x03}, /* 0x38, RT_CHANNEL_DOMAIN_MKK1_MKK3 */ - {0x02}, /* 0x39, RT_CHANNEL_DOMAIN_FCC1_NCC1 */ - {0x00}, /* 0x3A, */ - {0x00}, /* 0x3B, */ - {0x00}, /* 0x3C, */ - {0x00}, /* 0x3D, */ - {0x00}, /* 0x3E, */ - {0x00}, /* 0x3F, */ - {0x02}, /* 0x40, RT_CHANNEL_DOMAIN_FCC1_NCC2 */ - {0x05}, /* 0x41, RT_CHANNEL_DOMAIN_GLOBAL_NULL */ - {0x01}, /* 0x42, RT_CHANNEL_DOMAIN_ETSI1_ETSI4 */ - {0x02}, /* 0x43, RT_CHANNEL_DOMAIN_FCC1_FCC2 */ - {0x02}, /* 0x44, RT_CHANNEL_DOMAIN_FCC1_NCC3 */ - {0x00}, /* 0x45, RT_CHANNEL_DOMAIN_WORLD_ETSI5 */ - {0x02}, /* 0x46, RT_CHANNEL_DOMAIN_FCC1_FCC8 */ - {0x00}, /* 0x47, RT_CHANNEL_DOMAIN_WORLD_ETSI6 */ - {0x00}, /* 0x48, RT_CHANNEL_DOMAIN_WORLD_ETSI7 */ - {0x00}, /* 0x49, RT_CHANNEL_DOMAIN_WORLD_ETSI8 */ - {0x00}, /* 0x50, RT_CHANNEL_DOMAIN_WORLD_ETSI9 */ - {0x00}, /* 0x51, RT_CHANNEL_DOMAIN_WORLD_ETSI10 */ - {0x00}, /* 0x52, RT_CHANNEL_DOMAIN_WORLD_ETSI11 */ - {0x02}, /* 0x53, RT_CHANNEL_DOMAIN_FCC1_NCC4 */ - {0x00}, /* 0x54, RT_CHANNEL_DOMAIN_WORLD_ETSI12 */ - {0x02}, /* 0x55, RT_CHANNEL_DOMAIN_FCC1_FCC9 */ - {0x00}, /* 0x56, RT_CHANNEL_DOMAIN_WORLD_ETSI13 */ - {0x02}, /* 0x57, RT_CHANNEL_DOMAIN_FCC1_FCC10 */ -}; - - /* use the combination for max channel numbers */ -static struct rt_channel_plan_map RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03}; - -/* Search the @param ch in given @param ch_set - * @ch_set: the given channel set - * @ch: the given channel number - * - * return the index of channel_num in channel_set, -1 if not found - */ -int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch) -{ - int i; - - for (i = 0; ch_set[i].channel_num != 0; i++) { - if (ch == ch_set[i].channel_num) - break; - } - - if (i >= ch_set[i].channel_num) - return -1; - return i; -} - -/* Following are the initialization functions for WiFi MLME */ - -void init_hw_mlme_ext(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - set_channel_bwmode(padapter, pmlmeext->cur_channel, - pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); -} - -void init_mlme_default_rate_set(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - unsigned char mixed_datarate[NumRates] = {_1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_, _9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_, _48M_RATE_, _54M_RATE_, 0xff}; - unsigned char mixed_basicrate[NumRates] = {_1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_, _12M_RATE_, _24M_RATE_, 0xff,}; - unsigned char supported_mcs_set[16] = {0xff, 0xff, 0x00, 0x00, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - - memcpy(pmlmeext->datarate, mixed_datarate, NumRates); - memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates); - - memcpy(pmlmeext->default_supported_mcs_set, supported_mcs_set, sizeof(pmlmeext->default_supported_mcs_set)); -} - -static void init_mlme_ext_priv_value(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - atomic_set(&pmlmeext->event_seq, 0); - pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */ - pmlmeext->sa_query_seq = 0; - pmlmeext->mgnt_80211w_IPN = 0; - pmlmeext->mgnt_80211w_IPN_rx = 0; - pmlmeext->cur_channel = padapter->registrypriv.channel; - pmlmeext->cur_bwmode = CHANNEL_WIDTH_20; - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - - pmlmeext->retry = 0; - - pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode; - - init_mlme_default_rate_set(padapter); - - pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB; - pmlmeext->sitesurvey_res.state = SCAN_DISABLE; - pmlmeext->sitesurvey_res.channel_idx = 0; - pmlmeext->sitesurvey_res.bss_cnt = 0; - pmlmeext->scan_abort = false; - - pmlmeinfo->state = WIFI_FW_NULL_STATE; - pmlmeinfo->reauth_count = 0; - pmlmeinfo->reassoc_count = 0; - pmlmeinfo->link_count = 0; - pmlmeinfo->auth_seq = 0; - pmlmeinfo->auth_algo = dot11_auth_algrthm_open; - pmlmeinfo->key_index = 0; - pmlmeinfo->iv = 0; - - pmlmeinfo->enc_algo = _NO_PRIVACY_; - pmlmeinfo->authModeToggle = 0; - - memset(pmlmeinfo->chg_txt, 0, 128); - - pmlmeinfo->slotTime = SHORT_SLOT_TIME; - pmlmeinfo->preamble_mode = PREAMBLE_AUTO; - - pmlmeinfo->dialogToken = 0; - - pmlmeext->action_public_rxseq = 0xffff; - pmlmeext->action_public_dialog_token = 0xff; -} - -static int has_channel(struct rt_channel_info *channel_set, - u8 chanset_size, - u8 chan) -{ - int i; - - for (i = 0; i < chanset_size; i++) - if (channel_set[i].channel_num == chan) - return 1; - - return 0; -} - -static void init_channel_list(struct adapter *padapter, struct rt_channel_info *channel_set, - u8 chanset_size, - struct p2p_channels *channel_list) -{ - static const struct p2p_oper_class_map op_class[] = { - { IEEE80211G, 81, 1, 13, 1, BW20 }, - { IEEE80211G, 82, 14, 14, 1, BW20 }, - { IEEE80211A, 115, 36, 48, 4, BW20 }, - { IEEE80211A, 116, 36, 44, 8, BW40PLUS }, - { IEEE80211A, 117, 40, 48, 8, BW40MINUS }, - { IEEE80211A, 124, 149, 161, 4, BW20 }, - { IEEE80211A, 125, 149, 169, 4, BW20 }, - { IEEE80211A, 126, 149, 157, 8, BW40PLUS }, - { IEEE80211A, 127, 153, 161, 8, BW40MINUS }, - { -1, 0, 0, 0, 0, BW20 } - }; - - int cla, op; - - cla = 0; - - for (op = 0; op_class[op].op_class; op++) { - u8 ch; - const struct p2p_oper_class_map *o = &op_class[op]; - struct p2p_reg_class *reg = NULL; - - for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { - if (!has_channel(channel_set, chanset_size, ch)) - continue; - - if ((padapter->registrypriv.ht_enable == 0) && (o->inc == 8)) - continue; - - if ((0 < (padapter->registrypriv.bw_mode & 0xf0)) && - ((o->bw == BW40MINUS) || (o->bw == BW40PLUS))) - continue; - - if (!reg) { - reg = &channel_list->reg_class[cla]; - cla++; - reg->reg_class = o->op_class; - reg->channels = 0; - } - reg->channel[reg->channels] = ch; - reg->channels++; - } - } - channel_list->reg_classes = cla; -} - -static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, struct rt_channel_info *channel_set) -{ - u8 index, chanset_size = 0; - u8 b2_4GBand = false; - u8 Index2G = 0; - - memset(channel_set, 0, sizeof(struct rt_channel_info) * MAX_CHANNEL_NUM); - - if (ChannelPlan >= RT_CHANNEL_DOMAIN_MAX && ChannelPlan != RT_CHANNEL_DOMAIN_REALTEK_DEFINE) - return chanset_size; - - if (is_supported_24g(padapter->registrypriv.wireless_mode)) { - b2_4GBand = true; - if (ChannelPlan == RT_CHANNEL_DOMAIN_REALTEK_DEFINE) - Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G; - else - Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G; - } - - if (b2_4GBand) { - for (index = 0; index < RTW_ChannelPlan2G[Index2G].Len; index++) { - channel_set[chanset_size].channel_num = - RTW_ChannelPlan2G[Index2G].Channel[index]; - - if ((ChannelPlan == RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN) ||/* Channel 1~11 is active, and 12~14 is passive */ - (ChannelPlan == RT_CHANNEL_DOMAIN_GLOBAL_NULL)) { - if (channel_set[chanset_size].channel_num >= 1 && - channel_set[chanset_size].channel_num <= 11) - channel_set[chanset_size].scan_type = SCAN_ACTIVE; - else if (channel_set[chanset_size].channel_num >= 12 && - channel_set[chanset_size].channel_num <= 14) - channel_set[chanset_size].scan_type = SCAN_PASSIVE; - } else if (ChannelPlan == RT_CHANNEL_DOMAIN_WORLD_WIDE_13 || - Index2G == RT_CHANNEL_DOMAIN_2G_WORLD) { /* channel 12~13, passive scan */ - if (channel_set[chanset_size].channel_num <= 11) - channel_set[chanset_size].scan_type = SCAN_ACTIVE; - else - channel_set[chanset_size].scan_type = SCAN_PASSIVE; - } else - channel_set[chanset_size].scan_type = SCAN_ACTIVE; - - chanset_size++; - } - } - - return chanset_size; -} - -static void init_mlme_ext_timer(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - timer_setup(&pmlmeext->survey_timer, survey_timer_hdl, 0); - timer_setup(&pmlmeext->link_timer, link_timer_hdl, 0); - timer_setup(&pmlmeext->sa_query_timer, sa_query_timer_hdl, 0); -} - -void init_mlme_ext_priv(struct adapter *padapter) -{ - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pmlmeext->padapter = padapter; - - /* fill_fwpriv(padapter, &(pmlmeext->fwpriv)); */ - - init_mlme_ext_priv_value(padapter); - pmlmeinfo->accept_addba_req = pregistrypriv->accept_addba_req; - - init_mlme_ext_timer(padapter); - - init_mlme_ap_info(padapter); - - pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan, pmlmeext->channel_set); - init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list); - pmlmeext->last_scan_time = 0; - pmlmeext->chan_scan_time = SURVEY_TO; - pmlmeext->mlmeext_init = true; - pmlmeext->active_keep_alive_check = true; -} - -void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext) -{ - struct adapter *padapter = pmlmeext->padapter; - - if (!padapter) - return; - - if (padapter->driver_stopped) { - timer_delete_sync(&pmlmeext->survey_timer); - timer_delete_sync(&pmlmeext->link_timer); - /* timer_delete_sync(&pmlmeext->ADDBA_timer); */ - } -} - -static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, union recv_frame *precv_frame) -{ - u8 *pframe = precv_frame->u.hdr.rx_data; - - if (ptable->func) { - /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */ - if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) && - !is_broadcast_ether_addr(GetAddr1Ptr(pframe))) - return; - - ptable->func(padapter, precv_frame); - } -} - -void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame) -{ - int index; - struct mlme_handler *ptable; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - u8 *pframe = precv_frame->u.hdr.rx_data; - struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe)); - - if (GetFrameType(pframe) != WIFI_MGT_TYPE) - return; - - /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */ - if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) && - !is_broadcast_ether_addr(GetAddr1Ptr(pframe))) { - return; - } - - ptable = mlme_sta_tbl; - - index = GetFrameSubType(pframe) >> 4; - - if (index >= ARRAY_SIZE(mlme_sta_tbl)) - return; - - ptable += index; - - if (psta) { - if (GetRetry(pframe)) { - if (precv_frame->u.hdr.attrib.seq_num == psta->rx_mgmt_frame_seq_num) { - /* drop the duplicate management frame */ - return; - } - } - psta->rx_mgmt_frame_seq_num = precv_frame->u.hdr.attrib.seq_num; - } - - switch (GetFrameSubType(pframe)) { - case WIFI_AUTH: - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - ptable->func = &OnAuth; - else - ptable->func = &OnAuthClient; - fallthrough; - case WIFI_ASSOCREQ: - case WIFI_REASSOCREQ: - _mgt_dispatcher(padapter, ptable, precv_frame); - break; - case WIFI_PROBEREQ: - _mgt_dispatcher(padapter, ptable, precv_frame); - break; - case WIFI_BEACON: - _mgt_dispatcher(padapter, ptable, precv_frame); - break; - case WIFI_ACTION: - /* if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) */ - _mgt_dispatcher(padapter, ptable, precv_frame); - break; - default: - _mgt_dispatcher(padapter, ptable, precv_frame); - break; - } -} - -/* Following are the callback functions for each subtype of the management frames */ - -unsigned int OnProbeReq(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned int ielen; - unsigned char *p; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur = &pmlmeinfo->network; - u8 *pframe = precv_frame->u.hdr.rx_data; - uint len = precv_frame->u.hdr.len; - u8 is_valid_p2p_probereq = false; - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) - return _SUCCESS; - - if (!check_fwstate(pmlmepriv, _FW_LINKED) && - !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_AP_STATE)) { - return _SUCCESS; - } - - p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, WLAN_EID_SSID, (int *)&ielen, - len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_); - - /* check (wildcard) SSID */ - if (p) { - if (is_valid_p2p_probereq) - goto _issue_probersp; - - if ((ielen != 0 && false == !memcmp((p + 2), cur->ssid.ssid, cur->ssid.ssid_length)) - || (ielen == 0 && pmlmeinfo->hidden_ssid_mode) - ) - return _SUCCESS; - -_issue_probersp: - if ((check_fwstate(pmlmepriv, _FW_LINKED) && - pmlmepriv->cur_network.join_res) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) - issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq); - } - - return _SUCCESS; -} - -unsigned int OnProbeRsp(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) { - report_survey_event(padapter, precv_frame); - return _SUCCESS; - } - - return _SUCCESS; -} - -unsigned int OnBeacon(struct adapter *padapter, union recv_frame *precv_frame) -{ - int cam_idx; - struct sta_info *psta; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct sta_priv *pstapriv = &padapter->stapriv; - u8 *pframe = precv_frame->u.hdr.rx_data; - uint len = precv_frame->u.hdr.len; - struct wlan_bssid_ex *pbss; - int ret = _SUCCESS; - u8 *p = NULL; - u32 ielen = 0; - - p = rtw_get_ie(pframe + sizeof(struct ieee80211_hdr_3addr) + _BEACON_IE_OFFSET_, WLAN_EID_EXT_SUPP_RATES, &ielen, precv_frame->u.hdr.len - sizeof(struct ieee80211_hdr_3addr) - _BEACON_IE_OFFSET_); - if (p && ielen > 0) { - if (p + 2 + ielen < pframe + len) { - if ((*(p + 1 + ielen) == 0x2D) && (*(p + 2 + ielen) != 0x2D)) - /* Invalid value 0x2D is detected in Extended Supported Rates (ESR) IE. Try to fix the IE length to avoid failed Beacon parsing. */ - *(p + 1) = ielen - 1; - } - } - - if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) { - report_survey_event(padapter, precv_frame); - return _SUCCESS; - } - - if (!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) { - if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) { - /* we should update current network before auth, or some IE is wrong */ - pbss = kmalloc_obj(*pbss, GFP_ATOMIC); - if (pbss) { - if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) { - update_network(&(pmlmepriv->cur_network.network), pbss, padapter, true); - rtw_get_bcn_info(&(pmlmepriv->cur_network)); - } - kfree(pbss); - } - - /* check the vendor of the assoc AP */ - pmlmeinfo->assoc_AP_vendor = - check_assoc_AP(pframe + sizeof(struct ieee80211_hdr_3addr), - len - sizeof(struct ieee80211_hdr_3addr)); - - /* update TSF Value */ - update_TSF(pmlmeext, pframe, len); - - /* reset for adaptive_early_32k */ - pmlmeext->adaptive_tsf_done = false; - pmlmeext->DrvBcnEarly = 0xff; - pmlmeext->DrvBcnTimeOut = 0xff; - pmlmeext->bcn_cnt = 0; - memset(pmlmeext->bcn_delay_cnt, 0, sizeof(pmlmeext->bcn_delay_cnt)); - memset(pmlmeext->bcn_delay_ratio, 0, sizeof(pmlmeext->bcn_delay_ratio)); - - /* start auth */ - start_clnt_auth(padapter); - - return _SUCCESS; - } - - if (((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) && - (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) { - psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - if (psta) { - ret = rtw_check_bcn_info(padapter, pframe, len); - if (!ret) { - netdev_dbg(padapter->pnetdev, - "ap has changed, disconnect now\n"); - receive_disconnect(padapter, - pmlmeinfo->network.mac_address, 0); - return _SUCCESS; - } - /* update WMM, ERP in the beacon */ - /* todo: the timer is used instead of the number of the beacon received */ - if ((sta_rx_pkts(psta) & 0xf) == 0) - update_beacon_info(padapter, pframe, len, psta); - - adaptive_early_32k(pmlmeext, pframe, len); - } - } else if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) { - psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - if (psta) { - /* update WMM, ERP in the beacon */ - /* todo: the timer is used instead of the number of the beacon received */ - if ((sta_rx_pkts(psta) & 0xf) == 0) - update_beacon_info(padapter, pframe, len, psta); - } else { - /* allocate a new CAM entry for IBSS station */ - cam_idx = allocate_fw_sta_entry(padapter); - if (cam_idx == NUM_STA) - goto _END_ONBEACON_; - - /* get supported rate */ - if (update_sta_support_rate(padapter, (pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_), (len - WLAN_HDR_A3_LEN - _BEACON_IE_OFFSET_), cam_idx) == _FAIL) { - pmlmeinfo->FW_sta_info[cam_idx].status = 0; - goto _END_ONBEACON_; - } - - /* update TSF Value */ - update_TSF(pmlmeext, pframe, len); - - /* report sta add event */ - report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx); - } - } - } - -_END_ONBEACON_: - - return _SUCCESS; -} - -unsigned int OnAuth(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned int auth_mode, seq, ie_len; - unsigned char *sa, *p; - u16 algorithm; - int status; - static struct sta_info stat; - struct sta_info *pstat = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 *pframe = precv_frame->u.hdr.rx_data; - uint len = precv_frame->u.hdr.len; - u8 offset = 0; - - if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE) - return _FAIL; - - if (len < WLAN_HDR_A3_LEN) - return _FAIL; - - sa = GetAddr2Ptr(pframe); - - auth_mode = psecuritypriv->dot11_auth_algrthm; - - if (GetPrivacy(pframe)) { - u8 *iv; - struct rx_pkt_attrib *prxattrib = &(precv_frame->u.hdr.attrib); - - prxattrib->hdrlen = WLAN_HDR_A3_LEN; - prxattrib->encrypt = _WEP40_; - - if (len < WLAN_HDR_A3_LEN + 8) - return _FAIL; - - iv = pframe + prxattrib->hdrlen; - prxattrib->key_index = ((iv[3] >> 6) & 0x3); - - prxattrib->iv_len = 4; - prxattrib->icv_len = 4; - - rtw_wep_decrypt(padapter, (u8 *)precv_frame); - - offset = 4; - } - - algorithm = le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset)); - seq = le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2)); - - if (auth_mode == 2 && - psecuritypriv->dot11_privacy_algrthm != _WEP40_ && - psecuritypriv->dot11_privacy_algrthm != _WEP104_) - auth_mode = 0; - - if ((algorithm > 0 && auth_mode == 0) || /* rx a shared-key auth but shared not enabled */ - (algorithm == 0 && auth_mode == 1)) { /* rx a open-system auth but shared-key is enabled */ - - status = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; - - goto auth_fail; - } - - if (!rtw_access_ctrl(padapter, sa)) { - status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; - goto auth_fail; - } - - pstat = rtw_get_stainfo(pstapriv, sa); - if (!pstat) { - /* allocate a new one */ - pstat = rtw_alloc_stainfo(pstapriv, sa); - if (!pstat) { - status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; - goto auth_fail; - } - - pstat->state = WIFI_FW_AUTH_NULL; - pstat->auth_seq = 0; - - /* pstat->flags = 0; */ - /* pstat->capability = 0; */ - } else { - spin_lock_bh(&pstapriv->asoc_list_lock); - if (!list_empty(&pstat->asoc_list)) { - list_del_init(&pstat->asoc_list); - pstapriv->asoc_list_cnt--; - if (pstat->expire_to > 0) { - /* TODO: STA re_auth within expire_to */ - } - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - - if (seq == 1) { - /* TODO: STA re_auth and auth timeout */ - } - } - - spin_lock_bh(&pstapriv->auth_list_lock); - if (list_empty(&pstat->auth_list)) { - list_add_tail(&pstat->auth_list, &pstapriv->auth_list); - pstapriv->auth_list_cnt++; - } - spin_unlock_bh(&pstapriv->auth_list_lock); - - if (pstat->auth_seq == 0) - pstat->expire_to = pstapriv->auth_to; - - if ((pstat->auth_seq + 1) != seq) { - status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; - goto auth_fail; - } - - if (algorithm == 0 && (auth_mode == 0 || auth_mode == 2 || auth_mode == 3)) { - if (seq == 1) { - pstat->state &= ~WIFI_FW_AUTH_NULL; - pstat->state |= WIFI_FW_AUTH_SUCCESS; - pstat->expire_to = pstapriv->assoc_to; - pstat->authalg = algorithm; - } else { - status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; - goto auth_fail; - } - } else { /* shared system or auto authentication */ - if (seq == 1) { - /* prepare for the challenging txt... */ - memset(pstat->chg_txt, 78, 128); - - pstat->state &= ~WIFI_FW_AUTH_NULL; - pstat->state |= WIFI_FW_AUTH_STATE; - pstat->authalg = algorithm; - } else if (seq == 3) { - p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_, WLAN_EID_CHALLENGE, (int *)&ie_len, - len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4); - - if (!p || ie_len != 128) { - status = WLAN_STATUS_CHALLENGE_FAIL; - goto auth_fail; - } - - if (!memcmp((p + 2), pstat->chg_txt, 128)) { - pstat->state &= (~WIFI_FW_AUTH_STATE); - pstat->state |= WIFI_FW_AUTH_SUCCESS; - /* challenging txt is correct... */ - pstat->expire_to = pstapriv->assoc_to; - } else { - status = WLAN_STATUS_CHALLENGE_FAIL; - goto auth_fail; - } - } else { - status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; - goto auth_fail; - } - } - - /* Now, we are going to issue_auth... */ - pstat->auth_seq = seq + 1; - - issue_auth(padapter, pstat, (unsigned short)(WLAN_STATUS_SUCCESS)); - - if (pstat->state & WIFI_FW_AUTH_SUCCESS) - pstat->auth_seq = 0; - - return _SUCCESS; - -auth_fail: - - if (pstat) - rtw_free_stainfo(padapter, pstat); - - pstat = &stat; - memset((char *)pstat, '\0', sizeof(stat)); - pstat->auth_seq = 2; - memcpy(pstat->hwaddr, sa, 6); - - issue_auth(padapter, pstat, (unsigned short)status); - - return _FAIL; -} - -unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned int seq, len, status, offset; - unsigned char *p; - unsigned int go2asoc = 0; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 *pframe = precv_frame->u.hdr.rx_data; - uint pkt_len = precv_frame->u.hdr.len; - - /* check A1 matches or not */ - if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN)) - return _SUCCESS; - - if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE)) - return _SUCCESS; - - offset = (GetPrivacy(pframe)) ? 4 : 0; - - seq = le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2)); - status = le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 4)); - - if (status != 0) { - if (status == 13) { /* pmlmeinfo->auth_algo == dot11_auth_algrthm_auto) */ - if (pmlmeinfo->auth_algo == dot11_auth_algrthm_shared) - pmlmeinfo->auth_algo = dot11_auth_algrthm_open; - else - pmlmeinfo->auth_algo = dot11_auth_algrthm_shared; - /* pmlmeinfo->reauth_count = 0; */ - } - - set_link_timer(pmlmeext, 1); - goto authclnt_fail; - } - - if (seq == 2) { - if (pmlmeinfo->auth_algo == dot11_auth_algrthm_shared) { - /* legendary shared system */ - p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, WLAN_EID_CHALLENGE, (int *)&len, - pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_); - - if (!p || len != WLAN_AUTH_CHALLENGE_LEN) - goto authclnt_fail; - - memcpy(pmlmeinfo->chg_txt, p + 2, len); - pmlmeinfo->auth_seq = 3; - issue_auth(padapter, NULL, 0); - set_link_timer(pmlmeext, REAUTH_TO); - - return _SUCCESS; - } - /* open system */ - go2asoc = 1; - } else if (seq == 4) { - if (pmlmeinfo->auth_algo == dot11_auth_algrthm_shared) - go2asoc = 1; - else - goto authclnt_fail; - } else { - /* this is also illegal */ - goto authclnt_fail; - } - - if (go2asoc) { - netdev_dbg(padapter->pnetdev, "auth success, start assoc\n"); - start_clnt_assoc(padapter); - return _SUCCESS; - } - -authclnt_fail: - - /* pmlmeinfo->state &= ~(WIFI_FW_AUTH_STATE); */ - - return _FAIL; -} - -unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) -{ - u16 capab_info; - struct rtw_ieee802_11_elems elems; - struct sta_info *pstat; - unsigned char *p, *pos, *wpa_ie; - unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01}; - int i, ie_len, left; - u8 wpa_ie_len; - unsigned char supportRate[16]; - int support_rate_num; - unsigned short status = WLAN_STATUS_SUCCESS; - unsigned short frame_type, ie_offset = 0; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur = &(pmlmeinfo->network); - struct sta_priv *pstapriv = &padapter->stapriv; - u8 *pframe = precv_frame->u.hdr.rx_data; - uint pkt_len = precv_frame->u.hdr.len; - - if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE) - return _FAIL; - - frame_type = GetFrameSubType(pframe); - if (frame_type == WIFI_ASSOCREQ) - ie_offset = _ASOCREQ_IE_OFFSET_; - else /* WIFI_REASSOCREQ */ - ie_offset = _REASOCREQ_IE_OFFSET_; - - if (pkt_len < sizeof(struct ieee80211_hdr_3addr) + ie_offset) - return _FAIL; - - pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - if (!pstat) { - status = WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA; - goto asoc_class2_error; - } - - capab_info = get_unaligned_le16(pframe + WLAN_HDR_A3_LEN); - /* capab_info = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN)); */ - - left = pkt_len - (sizeof(struct ieee80211_hdr_3addr) + ie_offset); - pos = pframe + (sizeof(struct ieee80211_hdr_3addr) + ie_offset); - - /* check if this stat has been successfully authenticated/associated */ - if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS)) { - if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS)) { - status = WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA; - goto asoc_class2_error; - } else { - pstat->state &= (~WIFI_FW_ASSOC_SUCCESS); - pstat->state |= WIFI_FW_ASSOC_STATE; - } - } else { - pstat->state &= (~WIFI_FW_AUTH_SUCCESS); - pstat->state |= WIFI_FW_ASSOC_STATE; - } - - pstat->capability = capab_info; - - /* now parse all ieee802_11 ie to point to elems */ - if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == PARSE_FAILED || - !elems.ssid) { - status = WLAN_STATUS_CHALLENGE_FAIL; - goto OnAssocReqFail; - } - - /* now we should check all the fields... */ - /* checking SSID */ - p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, WLAN_EID_SSID, &ie_len, - pkt_len - WLAN_HDR_A3_LEN - ie_offset); - - if (!p || ie_len == 0) { - /* broadcast ssid, however it is not allowed in assocreq */ - status = WLAN_STATUS_CHALLENGE_FAIL; - goto OnAssocReqFail; - } else { - /* check if ssid match */ - if (memcmp(p + 2, cur->ssid.ssid, cur->ssid.ssid_length)) - status = WLAN_STATUS_CHALLENGE_FAIL; - - if (ie_len != cur->ssid.ssid_length) - status = WLAN_STATUS_CHALLENGE_FAIL; - } - - if (status != WLAN_STATUS_SUCCESS) - goto OnAssocReqFail; - - /* check if the supported rate is ok */ - p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, WLAN_EID_SUPP_RATES, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset); - if (!p) { - /* use our own rate set as statoin used */ - /* memcpy(supportRate, AP_BSSRATE, AP_BSSRATE_LEN); */ - /* support_rate_num = AP_BSSRATE_LEN; */ - - status = WLAN_STATUS_CHALLENGE_FAIL; - goto OnAssocReqFail; - } else { - if (ie_len > sizeof(supportRate)) - ie_len = sizeof(supportRate); - - memcpy(supportRate, p + 2, ie_len); - support_rate_num = ie_len; - - p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, WLAN_EID_EXT_SUPP_RATES, &ie_len, - pkt_len - WLAN_HDR_A3_LEN - ie_offset); - if (p) { - if (support_rate_num + ie_len <= sizeof(supportRate)) { - memcpy(supportRate + support_rate_num, p + 2, ie_len); - support_rate_num += ie_len; - } - } - } - - /* todo: mask supportRate between AP & STA -> move to update raid */ - /* get_matched_rate(pmlmeext, supportRate, &support_rate_num, 0); */ - - /* update station supportRate */ - pstat->bssratelen = support_rate_num; - memcpy(pstat->bssrateset, supportRate, support_rate_num); - update_basic_rate_table_soft_ap(pstat->bssrateset, pstat->bssratelen); - - /* check RSN/WPA/WPS */ - pstat->dot8021xalg = 0; - pstat->wpa_psk = 0; - pstat->wpa_group_cipher = 0; - pstat->wpa2_group_cipher = 0; - pstat->wpa_pairwise_cipher = 0; - pstat->wpa2_pairwise_cipher = 0; - memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie)); - if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) { - int group_cipher = 0, pairwise_cipher = 0; - - wpa_ie = elems.rsn_ie; - wpa_ie_len = elems.rsn_ie_len; - - if (rtw_parse_wpa2_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, - &pairwise_cipher, NULL) == _SUCCESS) { - pstat->dot8021xalg = 1;/* psk, todo:802.1x */ - pstat->wpa_psk |= BIT(1); - - pstat->wpa2_group_cipher = group_cipher & psecuritypriv->wpa2_group_cipher; - pstat->wpa2_pairwise_cipher = pairwise_cipher & - psecuritypriv->wpa2_pairwise_cipher; - - if (!pstat->wpa2_group_cipher) - status = WLAN_STATUS_INVALID_GROUP_CIPHER; - - if (!pstat->wpa2_pairwise_cipher) - status = WLAN_STATUS_INVALID_PAIRWISE_CIPHER; - } else { - status = WLAN_STATUS_INVALID_IE; - } - - } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) { - int group_cipher = 0, pairwise_cipher = 0; - - wpa_ie = elems.wpa_ie; - wpa_ie_len = elems.wpa_ie_len; - - if (rtw_parse_wpa_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, - &pairwise_cipher, NULL) == _SUCCESS) { - pstat->dot8021xalg = 1;/* psk, todo:802.1x */ - pstat->wpa_psk |= BIT(0); - - pstat->wpa_group_cipher = group_cipher & psecuritypriv->wpa_group_cipher; - pstat->wpa_pairwise_cipher = pairwise_cipher & - psecuritypriv->wpa_pairwise_cipher; - - if (!pstat->wpa_group_cipher) - status = WLAN_STATUS_INVALID_GROUP_CIPHER; - - if (!pstat->wpa_pairwise_cipher) - status = WLAN_STATUS_INVALID_PAIRWISE_CIPHER; - - } else { - status = WLAN_STATUS_INVALID_IE; - } - - } else { - wpa_ie = NULL; - wpa_ie_len = 0; - } - - if (status != WLAN_STATUS_SUCCESS) - goto OnAssocReqFail; - - pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS); - if (!wpa_ie) { - if (elems.wps_ie) - pstat->flags |= WLAN_STA_WPS; - else - pstat->flags |= WLAN_STA_MAYBE_WPS; - - /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */ - /* that the selected registrar of AP is _FLASE */ - if ((psecuritypriv->wpa_psk > 0) && - (pstat->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) { - if (pmlmepriv->wps_beacon_ie) { - u8 selected_registrar = 0; - - rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL); - - if (!selected_registrar) { - status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; - - goto OnAssocReqFail; - } - } - } - - } else { - int copy_len; - - if (psecuritypriv->wpa_psk == 0) { - status = WLAN_STATUS_INVALID_IE; - - goto OnAssocReqFail; - } - - if (elems.wps_ie) { - pstat->flags |= WLAN_STA_WPS; - copy_len = 0; - } else { - copy_len = min(sizeof(pstat->wpa_ie), wpa_ie_len + 2u); - } - - if (copy_len > 0) - memcpy(pstat->wpa_ie, wpa_ie - 2, copy_len); - } - - /* check if there is WMM IE & support WWM-PS */ - pstat->flags &= ~WLAN_STA_WME; - pstat->qos_option = 0; - pstat->qos_info = 0; - pstat->has_legacy_ac = true; - pstat->uapsd_vo = 0; - pstat->uapsd_vi = 0; - pstat->uapsd_be = 0; - pstat->uapsd_bk = 0; - if (pmlmepriv->qospriv.qos_option) { - p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0; - for (;;) { - p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset); - if (!p) - break; - - if (memcmp(p + 2, WMM_IE, 6)) { - p = p + ie_len + 2; - continue; - } - - pstat->flags |= WLAN_STA_WME; - - pstat->qos_option = 1; - pstat->qos_info = *(p + 8); - - pstat->max_sp_len = (pstat->qos_info >> 5) & 0x3; - - if ((pstat->qos_info & 0xf) != 0xf) - pstat->has_legacy_ac = true; - else - pstat->has_legacy_ac = false; - - if (pstat->qos_info & 0xf) { - if (pstat->qos_info & BIT(0)) - pstat->uapsd_vo = BIT(0) | BIT(1); - else - pstat->uapsd_vo = 0; - - if (pstat->qos_info & BIT(1)) - pstat->uapsd_vi = BIT(0) | BIT(1); - else - pstat->uapsd_vi = 0; - - if (pstat->qos_info & BIT(2)) - pstat->uapsd_bk = BIT(0) | BIT(1); - else - pstat->uapsd_bk = 0; - - if (pstat->qos_info & BIT(3)) - pstat->uapsd_be = BIT(0) | BIT(1); - else - pstat->uapsd_be = 0; - } - - break; - } - } - - /* save HT capabilities in the sta object */ - memset(&pstat->htpriv.ht_cap, 0, sizeof(struct ieee80211_ht_cap)); - if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_cap)) { - pstat->flags |= WLAN_STA_HT; - - pstat->flags |= WLAN_STA_WME; - - memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct ieee80211_ht_cap)); - - } else - pstat->flags &= ~WLAN_STA_HT; - - if (!pmlmepriv->htpriv.ht_option && (pstat->flags & WLAN_STA_HT)) { - status = WLAN_STATUS_CHALLENGE_FAIL; - goto OnAssocReqFail; - } - - if ((pstat->flags & WLAN_STA_HT) && - ((pstat->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) || - (pstat->wpa_pairwise_cipher & WPA_CIPHER_TKIP))) { - /* status = WLAN_STATUS_CIPHER_SUITE_REJECTED; */ - /* goto OnAssocReqFail; */ - } - pstat->flags |= WLAN_STA_NONERP; - for (i = 0; i < pstat->bssratelen; i++) { - if ((pstat->bssrateset[i] & 0x7f) > 22) { - pstat->flags &= ~WLAN_STA_NONERP; - break; - } - } - - if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) - pstat->flags |= WLAN_STA_SHORT_PREAMBLE; - else - pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE; - - /* TODO: identify_proprietary_vendor_ie(); */ - /* Realtek proprietary IE */ - /* identify if this is Broadcom sta */ - /* identify if this is ralink sta */ - /* Customer proprietary IE */ - - /* get a unique AID */ - if (pstat->aid == 0) { - for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++) - if (!pstapriv->sta_aid[pstat->aid - 1]) - break; - - /* if (pstat->aid > NUM_STA) { */ - if (pstat->aid > pstapriv->max_num_sta) { - pstat->aid = 0; - - status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; - - goto OnAssocReqFail; - - } else { - pstapriv->sta_aid[pstat->aid - 1] = pstat; - } - } - - pstat->state &= (~WIFI_FW_ASSOC_STATE); - pstat->state |= WIFI_FW_ASSOC_SUCCESS; - - spin_lock_bh(&pstapriv->auth_list_lock); - if (!list_empty(&pstat->auth_list)) { - list_del_init(&pstat->auth_list); - pstapriv->auth_list_cnt--; - } - spin_unlock_bh(&pstapriv->auth_list_lock); - - spin_lock_bh(&pstapriv->asoc_list_lock); - if (list_empty(&pstat->asoc_list)) { - pstat->expire_to = pstapriv->expire_to; - list_add_tail(&pstat->asoc_list, &pstapriv->asoc_list); - pstapriv->asoc_list_cnt++; - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - - /* now the station is qualified to join our BSS... */ - if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (status == WLAN_STATUS_SUCCESS)) { - /* 1 bss_cap_update & sta_info_update */ - bss_cap_update_on_sta_join(padapter, pstat); - sta_info_update(padapter, pstat); - - /* 2 issue assoc rsp before notify station join event. */ - if (frame_type == WIFI_ASSOCREQ) - issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP); - else - issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP); - - spin_lock_bh(&pstat->lock); - kfree(pstat->passoc_req); - pstat->assoc_req_len = 0; - pstat->passoc_req = kmemdup(pframe, pkt_len, GFP_ATOMIC); - if (pstat->passoc_req) - pstat->assoc_req_len = pkt_len; - - spin_unlock_bh(&pstat->lock); - - /* 3-(1) report sta add event */ - report_add_sta_event(padapter, pstat->hwaddr, pstat->aid); - } - - return _SUCCESS; - -asoc_class2_error: - - issue_deauth(padapter, GetAddr2Ptr(pframe), status); - - return _FAIL; - -OnAssocReqFail: - - pstat->aid = 0; - if (frame_type == WIFI_ASSOCREQ) - issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP); - else - issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP); - - return _FAIL; -} - -unsigned int OnAssocRsp(struct adapter *padapter, union recv_frame *precv_frame) -{ - uint i; - int res; - unsigned short status; - struct ndis_80211_var_ie *pIE; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */ - u8 *pframe = precv_frame->u.hdr.rx_data; - uint pkt_len = precv_frame->u.hdr.len; - - /* check A1 matches or not */ - if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN)) - return _SUCCESS; - - if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE))) - return _SUCCESS; - - if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) - return _SUCCESS; - - timer_delete_sync(&pmlmeext->link_timer); - - /* status */ - status = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 2)); - if (status > 0) { - pmlmeinfo->state = WIFI_FW_NULL_STATE; - res = -4; - goto report_assoc_result; - } - - /* get capabilities */ - pmlmeinfo->capability = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN)); - - /* set slot time */ - pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10)) ? 9 : 20; - - /* AID */ - pmlmeinfo->aid = (int)(le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 4)) & 0x3fff); - res = pmlmeinfo->aid; - - /* following are moved to join event callback function */ - /* to handle HT, WMM, rate adaptive, update MAC reg */ - /* for not to handle the synchronous IO in the tasklet */ - for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) { - if (i + sizeof(*pIE) > pkt_len) - break; - pIE = (struct ndis_80211_var_ie *)(pframe + i); - if (i + sizeof(*pIE) + pIE->length > pkt_len) - break; - - switch (pIE->element_id) { - case WLAN_EID_VENDOR_SPECIFIC: - if (!memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */ - WMM_param_handler(padapter, pIE); - break; - - case WLAN_EID_HT_CAPABILITY: /* HT caps */ - HT_caps_handler(padapter, pIE); - break; - - case WLAN_EID_HT_OPERATION: /* HT info */ - HT_info_handler(padapter, pIE); - break; - - case WLAN_EID_ERP_INFO: - ERP_IE_handler(padapter, pIE); - break; - - default: - break; - } - - i += (pIE->length + 2); - } - - pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE); - pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS; - - /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */ - update_basic_rate_table(padapter, pmlmeinfo->network.supported_rates); - -report_assoc_result: - if (res > 0) - rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len); - else - rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len); - - report_join_res(padapter, res); - - return _SUCCESS; -} - -unsigned int OnDeAuth(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned short reason; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 *pframe = precv_frame->u.hdr.rx_data; - int ignore_received_deauth = 0; - - /* check A3 */ - if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) - return _SUCCESS; - - reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN)); - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - struct sta_info *psta; - struct sta_priv *pstapriv = &padapter->stapriv; - - /* rtw_free_stainfo(padapter, psta); */ - - netdev_dbg(padapter->pnetdev, - "ap recv deauth reason code(%d) sta:%pM\n", reason, - GetAddr2Ptr(pframe)); - - psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - if (psta) { - u8 updated = false; - - spin_lock_bh(&pstapriv->asoc_list_lock); - if (!list_empty(&psta->asoc_list)) { - list_del_init(&psta->asoc_list); - pstapriv->asoc_list_cnt--; - updated = ap_free_sta(padapter, psta, false, reason); - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - - associated_clients_update(padapter, updated); - } - - return _SUCCESS; - } - - /* Commented by Albert 20130604 - * Before sending the auth frame to start the STA/GC mode connection with AP/GO, - * we will send the deauth first. - * However, the Win8.1 with BRCM Wi-Fi will send the deauth with reason code 6 to us after receieving our deauth. - * Added the following code to avoid this case. - */ - if ((pmlmeinfo->state & WIFI_FW_AUTH_STATE) || - (pmlmeinfo->state & WIFI_FW_ASSOC_STATE)) { - if (reason == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA) { - ignore_received_deauth = 1; - } else if (reason == WLAN_REASON_PREV_AUTH_NOT_VALID) { - /* TODO: 802.11r */ - ignore_received_deauth = 1; - } - } - - netdev_dbg(padapter->pnetdev, - "sta recv deauth reason code(%d) sta:%pM, ignore = %d\n", - reason, GetAddr3Ptr(pframe), - ignore_received_deauth); - - if (ignore_received_deauth == 0) - receive_disconnect(padapter, GetAddr3Ptr(pframe), reason); - - pmlmepriv->link_detect_info.busy_traffic = false; - return _SUCCESS; -} - -unsigned int OnDisassoc(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned short reason; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 *pframe = precv_frame->u.hdr.rx_data; - - /* check A3 */ - if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) - return _SUCCESS; - - reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN)); - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - struct sta_info *psta; - struct sta_priv *pstapriv = &padapter->stapriv; - - /* rtw_free_stainfo(padapter, psta); */ - - netdev_dbg(padapter->pnetdev, - "ap recv disassoc reason code(%d) sta:%pM\n", - reason, GetAddr2Ptr(pframe)); - - psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - if (psta) { - u8 updated = false; - - spin_lock_bh(&pstapriv->asoc_list_lock); - if (!list_empty(&psta->asoc_list)) { - list_del_init(&psta->asoc_list); - pstapriv->asoc_list_cnt--; - updated = ap_free_sta(padapter, psta, false, reason); - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - - associated_clients_update(padapter, updated); - } - - return _SUCCESS; - } - netdev_dbg(padapter->pnetdev, - "sta recv disassoc reason code(%d) sta:%pM\n", - reason, GetAddr3Ptr(pframe)); - - receive_disconnect(padapter, GetAddr3Ptr(pframe), reason); - - pmlmepriv->link_detect_info.busy_traffic = false; - return _SUCCESS; -} - -unsigned int OnAtim(struct adapter *padapter, union recv_frame *precv_frame) -{ - return _SUCCESS; -} - -unsigned int on_action_spct(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - u8 *pframe = precv_frame->u.hdr.rx_data; - u8 *frame_body = (u8 *)(pframe + sizeof(struct ieee80211_hdr_3addr)); - u8 category; - u8 action; - - psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - - if (!psta) - goto exit; - - category = frame_body[0]; - if (category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT) - goto exit; - - action = frame_body[1]; - switch (action) { - case WLAN_ACTION_SPCT_MSR_REQ: - case WLAN_ACTION_SPCT_MSR_RPRT: - case WLAN_ACTION_SPCT_TPC_REQ: - case WLAN_ACTION_SPCT_TPC_RPRT: - case WLAN_ACTION_SPCT_CHL_SWITCH: - break; - default: - break; - } - -exit: - return _FAIL; -} - -unsigned int OnAction_back(struct adapter *padapter, union recv_frame *precv_frame) -{ - u8 *addr; - struct sta_info *psta = NULL; - struct recv_reorder_ctrl *preorder_ctrl; - unsigned char *frame_body; - unsigned char category, action; - unsigned short tid, status; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 *pframe = precv_frame->u.hdr.rx_data; - struct sta_priv *pstapriv = &padapter->stapriv; - - /* check RA matches or not */ - if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))/* for if1, sta/ap mode */ - return _SUCCESS; - - if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE) - if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) - return _SUCCESS; - - addr = GetAddr2Ptr(pframe); - psta = rtw_get_stainfo(pstapriv, addr); - - if (!psta) - return _SUCCESS; - - frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr)); - - category = frame_body[0]; - if (category == RTW_WLAN_CATEGORY_BACK) {/* representing Block Ack */ - if (!pmlmeinfo->HT_enable) - return _SUCCESS; - - action = frame_body[1]; - switch (action) { - case WLAN_ACTION_ADDBA_REQ: /* ADDBA request */ - - memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request)); - /* process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), GetAddr3Ptr(pframe)); */ - process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), addr); - - if (pmlmeinfo->accept_addba_req) - issue_action_BA(padapter, addr, WLAN_ACTION_ADDBA_RESP, 0); - else - issue_action_BA(padapter, addr, WLAN_ACTION_ADDBA_RESP, 37);/* reject ADDBA Req */ - - break; - - case WLAN_ACTION_ADDBA_RESP: /* ADDBA response */ - status = get_unaligned_le16(&frame_body[3]); - tid = ((frame_body[5] >> 2) & 0x7); - - if (status == 0) { - /* successful */ - psta->htpriv.agg_enable_bitmap |= BIT(tid); - psta->htpriv.candidate_tid_bitmap &= ~BIT(tid); - } else { - psta->htpriv.agg_enable_bitmap &= ~BIT(tid); - } - - if (psta->state & WIFI_STA_ALIVE_CHK_STATE) { - psta->htpriv.agg_enable_bitmap &= ~BIT(tid); - psta->expire_to = pstapriv->expire_to; - psta->state ^= WIFI_STA_ALIVE_CHK_STATE; - } - - break; - - case WLAN_ACTION_DELBA: /* DELBA */ - if ((frame_body[3] & BIT(3)) == 0) { - psta->htpriv.agg_enable_bitmap &= - ~BIT((frame_body[3] >> 4) & 0xf); - psta->htpriv.candidate_tid_bitmap &= - ~BIT((frame_body[3] >> 4) & 0xf); - } else if ((frame_body[3] & BIT(3)) == BIT(3)) { - tid = (frame_body[3] >> 4) & 0x0F; - - preorder_ctrl = &psta->recvreorder_ctrl[tid]; - preorder_ctrl->enable = false; - preorder_ctrl->indicate_seq = 0xffff; - } - /* todo: how to notify the host while receiving DELETE BA */ - break; - - default: - break; - } - } - return _SUCCESS; -} - -static s32 rtw_action_public_decache(union recv_frame *recv_frame, s32 token) -{ - struct adapter *adapter = recv_frame->u.hdr.adapter; - struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv); - u8 *frame = recv_frame->u.hdr.rx_data; - u16 seq_ctrl = ((recv_frame->u.hdr.attrib.seq_num & 0xffff) << 4) | - (recv_frame->u.hdr.attrib.frag_num & 0xf); - - if (GetRetry(frame)) { - if (token >= 0) { - if ((seq_ctrl == mlmeext->action_public_rxseq) - && (token == mlmeext->action_public_dialog_token)) - return _FAIL; - } else { - if (seq_ctrl == mlmeext->action_public_rxseq) - return _FAIL; - } - } - - mlmeext->action_public_rxseq = seq_ctrl; - - if (token >= 0) - mlmeext->action_public_dialog_token = token; - - return _SUCCESS; -} - -static unsigned int on_action_public_p2p(union recv_frame *precv_frame) -{ - u8 *pframe = precv_frame->u.hdr.rx_data; - u8 *frame_body; - u8 dialogToken = 0; - - frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr)); - - dialogToken = frame_body[7]; - - if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL) - return _FAIL; - - return _SUCCESS; -} - -static unsigned int on_action_public_vendor(union recv_frame *precv_frame) -{ - unsigned int ret = _FAIL; - u8 *pframe = precv_frame->u.hdr.rx_data; - u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); - - if (!memcmp(frame_body + 2, P2P_OUI, 4)) - ret = on_action_public_p2p(precv_frame); - - return ret; -} - -static unsigned int on_action_public_default(union recv_frame *precv_frame, u8 action) -{ - unsigned int ret = _FAIL; - u8 *pframe = precv_frame->u.hdr.rx_data; - uint frame_len = precv_frame->u.hdr.len; - u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); - u8 token; - struct adapter *adapter = precv_frame->u.hdr.adapter; - char msg[64]; - - token = frame_body[2]; - - if (rtw_action_public_decache(precv_frame, token) == _FAIL) - goto exit; - - scnprintf(msg, sizeof(msg), "%s(token:%u)", action_public_str(action), token); - rtw_cfg80211_rx_action(adapter, pframe, frame_len, msg); - - ret = _SUCCESS; - -exit: - return ret; -} - -unsigned int on_action_public(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned int ret = _FAIL; - u8 *pframe = precv_frame->u.hdr.rx_data; - u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); - u8 category, action; - - /* check RA matches or not */ - if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN)) - goto exit; - - category = frame_body[0]; - if (category != RTW_WLAN_CATEGORY_PUBLIC) - goto exit; - - action = frame_body[1]; - switch (action) { - case ACT_PUBLIC_VENDOR: - ret = on_action_public_vendor(precv_frame); - break; - default: - ret = on_action_public_default(precv_frame, action); - break; - } - -exit: - return ret; -} - -unsigned int OnAction_ht(struct adapter *padapter, union recv_frame *precv_frame) -{ - u8 *pframe = precv_frame->u.hdr.rx_data; - u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); - u8 category, action; - - /* check RA matches or not */ - if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN)) - goto exit; - - category = frame_body[0]; - if (category != RTW_WLAN_CATEGORY_HT) - goto exit; - - action = frame_body[1]; - switch (action) { - case WLAN_HT_ACTION_COMPRESSED_BF: - break; - default: - break; - } - -exit: - - return _SUCCESS; -} - -unsigned int OnAction_sa_query(struct adapter *padapter, union recv_frame *precv_frame) -{ - u8 *pframe = precv_frame->u.hdr.rx_data; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - unsigned short tid; - - switch (pframe[WLAN_HDR_A3_LEN + 1]) { - case 0: /* SA Query req */ - memcpy(&tid, &pframe[WLAN_HDR_A3_LEN + 2], sizeof(unsigned short)); - issue_action_SA_Query(padapter, GetAddr2Ptr(pframe), 1, tid); - break; - - case 1: /* SA Query rsp */ - timer_delete_sync(&pmlmeext->sa_query_timer); - break; - default: - break; - } - - return _SUCCESS; -} - -unsigned int OnAction(struct adapter *padapter, union recv_frame *precv_frame) -{ - int i; - unsigned char category; - struct action_handler *ptable; - unsigned char *frame_body; - u8 *pframe = precv_frame->u.hdr.rx_data; - - frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr)); - - category = frame_body[0]; - - for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) { - ptable = &OnAction_tbl[i]; - - if (category == ptable->num) - ptable->func(padapter, precv_frame); - } - - return _SUCCESS; -} - -unsigned int DoReserved(struct adapter *padapter, union recv_frame *precv_frame) -{ - return _SUCCESS; -} - -static struct xmit_frame *_alloc_mgtxmitframe(struct xmit_priv *pxmitpriv, bool once) -{ - struct xmit_frame *pmgntframe; - struct xmit_buf *pxmitbuf; - - if (once) - pmgntframe = rtw_alloc_xmitframe_once(pxmitpriv); - else - pmgntframe = rtw_alloc_xmitframe_ext(pxmitpriv); - - if (!pmgntframe) - goto exit; - - pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv); - if (!pxmitbuf) { - rtw_free_xmitframe(pxmitpriv, pmgntframe); - pmgntframe = NULL; - goto exit; - } - - pmgntframe->frame_tag = MGNT_FRAMETAG; - pmgntframe->pxmitbuf = pxmitbuf; - pmgntframe->buf_addr = pxmitbuf->pbuf; - pxmitbuf->priv_data = pmgntframe; - -exit: - return pmgntframe; -} - -inline struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv) -{ - return _alloc_mgtxmitframe(pxmitpriv, false); -} - -/* Following are some TX functions for WiFi MLME */ - -void update_mgnt_tx_rate(struct adapter *padapter, u8 rate) -{ - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - - pmlmeext->tx_rate = rate; -} - -void update_mgntframe_attrib(struct adapter *padapter, struct pkt_attrib *pattrib) -{ - u8 wireless_mode; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - - /* memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib)); */ - - pattrib->hdrlen = 24; - pattrib->nr_frags = 1; - pattrib->priority = 7; - pattrib->mac_id = 0; - pattrib->qsel = 0x12; - - pattrib->pktlen = 0; - - if (pmlmeext->tx_rate == IEEE80211_CCK_RATE_1MB) - wireless_mode = WIRELESS_11B; - else - wireless_mode = WIRELESS_11G; - pattrib->raid = rtw_get_mgntframe_raid(padapter, wireless_mode); - pattrib->rate = pmlmeext->tx_rate; - - pattrib->encrypt = _NO_PRIVACY_; - pattrib->bswenc = false; - - pattrib->qos_en = false; - pattrib->ht_en = false; - pattrib->bwmode = CHANNEL_WIDTH_20; - pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - pattrib->sgi = false; - - pattrib->seqnum = pmlmeext->mgnt_seq; - - pattrib->retry_ctrl = true; - - pattrib->mbssid = 0; -} - -void update_mgntframe_attrib_addr(struct adapter *padapter, struct xmit_frame *pmgntframe) -{ - u8 *pframe; - struct pkt_attrib *pattrib = &pmgntframe->attrib; - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - - memcpy(pattrib->ra, GetAddr1Ptr(pframe), ETH_ALEN); - memcpy(pattrib->ta, GetAddr2Ptr(pframe), ETH_ALEN); -} - -void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe) -{ - if (padapter->bSurpriseRemoved || - padapter->driver_stopped) { - rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe); - return; - } - - rtw_hal_mgnt_xmit(padapter, pmgntframe); -} - -s32 dump_mgntframe_and_wait(struct adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms) -{ - s32 ret = _FAIL; - unsigned long irqL; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf; - struct submit_ctx sctx; - - if (padapter->bSurpriseRemoved || - padapter->driver_stopped) { - rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe); - return ret; - } - - rtw_sctx_init(&sctx, timeout_ms); - pxmitbuf->sctx = &sctx; - - ret = rtw_hal_mgnt_xmit(padapter, pmgntframe); - - if (ret == _SUCCESS) - ret = rtw_sctx_wait(&sctx); - - spin_lock_irqsave(&pxmitpriv->lock_sctx, irqL); - pxmitbuf->sctx = NULL; - spin_unlock_irqrestore(&pxmitpriv->lock_sctx, irqL); - - return ret; -} - -s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmgntframe) -{ - static u8 seq_no; - s32 ret = _FAIL; - u32 timeout_ms = 500;/* 500ms */ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - if (padapter->bSurpriseRemoved || - padapter->driver_stopped) { - rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe); - return -1; - } - - if (mutex_lock_interruptible(&pxmitpriv->ack_tx_mutex) == 0) { - pxmitpriv->ack_tx = true; - pxmitpriv->seq_no = seq_no++; - pmgntframe->ack_report = 1; - if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) - ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms); - - pxmitpriv->ack_tx = false; - mutex_unlock(&pxmitpriv->ack_tx_mutex); - } - - return ret; -} - -static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode) -{ - u8 *ssid_ie; - signed int ssid_len_ori; - int len_diff = 0; - - ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len); - - if (ssid_ie && ssid_len_ori > 0) { - switch (hidden_ssid_mode) { - case 1: - { - u8 *next_ie = ssid_ie + 2 + ssid_len_ori; - u32 remain_len = 0; - - remain_len = ies_len - (next_ie - ies); - - ssid_ie[1] = 0; - memcpy(ssid_ie + 2, next_ie, remain_len); - len_diff -= ssid_len_ori; - - break; - } - case 2: - memset(&ssid_ie[2], 0, ssid_len_ori); - break; - default: - break; - } - } - - return len_diff; -} - -void issue_beacon(struct adapter *padapter, int timeout_ms) -{ - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - unsigned int rate_len; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - spin_lock_bh(&pmlmepriv->bcn_update_lock); - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->qsel = 0x10; - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - eth_broadcast_addr(pwlanhdr->addr1); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN); - - SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/); - /* pmlmeext->mgnt_seq++; */ - SetFrameSubType(pframe, WIFI_BEACON); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) { - { - int len_diff; - - memcpy(pframe, cur_network->ies, cur_network->ie_length); - len_diff = update_hidden_ssid(pframe + _BEACON_IE_OFFSET_, - cur_network->ie_length - _BEACON_IE_OFFSET_, - pmlmeinfo->hidden_ssid_mode); - pframe += (cur_network->ie_length + len_diff); - pattrib->pktlen += (cur_network->ie_length + len_diff); - } - - { - u8 *wps_ie; - uint wps_ielen; - u8 sr = 0; - - wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr + TXDESC_OFFSET + - sizeof(struct ieee80211_hdr_3addr) + - _BEACON_IE_OFFSET_, - pattrib->pktlen - - sizeof(struct ieee80211_hdr_3addr) - - _BEACON_IE_OFFSET_, NULL, &wps_ielen); - if (wps_ie && wps_ielen > 0) - rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL); - if (sr != 0) - set_fwstate(pmlmepriv, WIFI_UNDER_WPS); - else - _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS); - } - - goto _issue_bcn; - } - - /* below for ad-hoc mode */ - - /* timestamp will be inserted by hardware */ - pframe += 8; - pattrib->pktlen += 8; - - /* beacon interval: 2 bytes */ - - memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->ies)), 2); - - pframe += 2; - pattrib->pktlen += 2; - - /* capability info: 2 bytes */ - - memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->ies)), 2); - - pframe += 2; - pattrib->pktlen += 2; - - /* SSID */ - pframe = rtw_set_ie(pframe, WLAN_EID_SSID, cur_network->ssid.ssid_length, cur_network->ssid.ssid, &pattrib->pktlen); - - /* supported rates... */ - rate_len = rtw_get_rateset_len(cur_network->supported_rates); - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, ((rate_len > 8) ? 8 : rate_len), cur_network->supported_rates, &pattrib->pktlen); - - /* DS parameter set */ - pframe = rtw_set_ie(pframe, WLAN_EID_DS_PARAMS, 1, (unsigned char *)&(cur_network->configuration.ds_config), &pattrib->pktlen); - - /* if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) */ - { - u8 erpinfo = 0; - u32 ATIMWindow; - /* IBSS Parameter Set... */ - /* ATIMWindow = cur->configuration.ATIMWindow; */ - ATIMWindow = 0; - pframe = rtw_set_ie(pframe, WLAN_EID_IBSS_PARAMS, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen); - - /* ERP IE */ - pframe = rtw_set_ie(pframe, WLAN_EID_ERP_INFO, 1, &erpinfo, &pattrib->pktlen); - } - - /* EXTERNDED SUPPORTED RATE */ - if (rate_len > 8) - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8), (cur_network->supported_rates + 8), &pattrib->pktlen); - - /* todo:HT for adhoc */ - -_issue_bcn: - - pmlmepriv->update_bcn = false; - - spin_unlock_bh(&pmlmepriv->bcn_update_lock); - - if ((pattrib->pktlen + TXDESC_SIZE) > 512) { - rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(pxmitpriv, pmgntframe); - return; - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - if (timeout_ms > 0) - dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms); - else - dump_mgntframe(padapter, pmgntframe); -} - -void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq) -{ - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - unsigned char *mac, *bssid; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - - u8 *pwps_ie; - uint wps_ielen; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); - unsigned int rate_len; - - if (!da) - return; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - mac = myid(&(padapter->eeprompriv)); - bssid = cur_network->mac_address; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - memcpy(pwlanhdr->addr1, da, ETH_ALEN); - memcpy(pwlanhdr->addr2, mac, ETH_ALEN); - memcpy(pwlanhdr->addr3, bssid, ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(fctrl, WIFI_PROBERSP); - - pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = pattrib->hdrlen; - pframe += pattrib->hdrlen; - - if (cur_network->ie_length > MAX_IE_SZ) { - rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(pxmitpriv, pmgntframe); - return; - } - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) { - pwps_ie = rtw_get_wps_ie(cur_network->ies + _FIXED_IE_LENGTH_, - cur_network->ie_length - _FIXED_IE_LENGTH_, - NULL, &wps_ielen); - - /* inerset & update wps_probe_resp_ie */ - if (pmlmepriv->wps_probe_resp_ie && pwps_ie && wps_ielen > 0) { - uint wps_offset, remainder_ielen; - u8 *premainder_ie; - - wps_offset = (uint)(pwps_ie - cur_network->ies); - - premainder_ie = pwps_ie + wps_ielen; - - remainder_ielen = cur_network->ie_length - wps_offset - wps_ielen; - - memcpy(pframe, cur_network->ies, wps_offset); - pframe += wps_offset; - pattrib->pktlen += wps_offset; - - wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */ - if ((wps_offset + wps_ielen + 2) <= MAX_IE_SZ) { - memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen + 2); - pframe += wps_ielen + 2; - pattrib->pktlen += wps_ielen + 2; - } - - if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) { - memcpy(pframe, premainder_ie, remainder_ielen); - pframe += remainder_ielen; - pattrib->pktlen += remainder_ielen; - } - } else { - memcpy(pframe, cur_network->ies, cur_network->ie_length); - pframe += cur_network->ie_length; - pattrib->pktlen += cur_network->ie_length; - } - - /* retrieve SSID IE from cur_network->ssid */ - { - u8 *ssid_ie; - signed int ssid_ielen; - signed int ssid_ielen_diff; - u8 *buf; - u8 *ies = pmgntframe->buf_addr + TXDESC_OFFSET + - sizeof(struct ieee80211_hdr_3addr); - - buf = kzalloc(MAX_IE_SZ, GFP_ATOMIC); - if (!buf) { - rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(pxmitpriv, pmgntframe); - return; - } - - ssid_ie = rtw_get_ie(ies + _FIXED_IE_LENGTH_, WLAN_EID_SSID, &ssid_ielen, - (pframe - ies) - _FIXED_IE_LENGTH_); - - ssid_ielen_diff = cur_network->ssid.ssid_length - ssid_ielen; - - if (ssid_ie && cur_network->ssid.ssid_length) { - uint remainder_ielen; - u8 *remainder_ie; - - remainder_ie = ssid_ie + 2; - remainder_ielen = (pframe - remainder_ie); - - if (remainder_ielen > MAX_IE_SZ) { - netdev_warn(padapter->pnetdev, - FUNC_ADPT_FMT " remainder_ielen > MAX_IE_SZ\n", - FUNC_ADPT_ARG(padapter)); - remainder_ielen = MAX_IE_SZ; - } - - memcpy(buf, remainder_ie, remainder_ielen); - memcpy(remainder_ie + ssid_ielen_diff, buf, remainder_ielen); - *(ssid_ie + 1) = cur_network->ssid.ssid_length; - memcpy(ssid_ie + 2, cur_network->ssid.ssid, - cur_network->ssid.ssid_length); - - pframe += ssid_ielen_diff; - pattrib->pktlen += ssid_ielen_diff; - } - kfree(buf); - } - } else { - /* timestamp will be inserted by hardware */ - pframe += 8; - pattrib->pktlen += 8; - - /* beacon interval: 2 bytes */ - - memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->ies)), 2); - - pframe += 2; - pattrib->pktlen += 2; - - /* capability info: 2 bytes */ - - memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->ies)), 2); - - pframe += 2; - pattrib->pktlen += 2; - - /* below for ad-hoc mode */ - - /* SSID */ - pframe = rtw_set_ie(pframe, WLAN_EID_SSID, cur_network->ssid.ssid_length, cur_network->ssid.ssid, &pattrib->pktlen); - - /* supported rates... */ - rate_len = rtw_get_rateset_len(cur_network->supported_rates); - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, ((rate_len > 8) ? 8 : rate_len), cur_network->supported_rates, &pattrib->pktlen); - - /* DS parameter set */ - pframe = rtw_set_ie(pframe, WLAN_EID_DS_PARAMS, 1, (unsigned char *)&(cur_network->configuration.ds_config), &pattrib->pktlen); - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) { - u8 erpinfo = 0; - u32 ATIMWindow; - /* IBSS Parameter Set... */ - /* ATIMWindow = cur->configuration.ATIMWindow; */ - ATIMWindow = 0; - pframe = rtw_set_ie(pframe, WLAN_EID_IBSS_PARAMS, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen); - - /* ERP IE */ - pframe = rtw_set_ie(pframe, WLAN_EID_ERP_INFO, 1, &erpinfo, &pattrib->pktlen); - } - - /* EXTERNDED SUPPORTED RATE */ - if (rate_len > 8) - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8), (cur_network->supported_rates + 8), &pattrib->pktlen); - - /* todo:HT for adhoc */ - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - dump_mgntframe(padapter, pmgntframe); -} - -static int _issue_probereq(struct adapter *padapter, - struct ndis_802_11_ssid *pssid, - u8 *da, u8 ch, bool append_wps, bool wait_ack) -{ - int ret = _FAIL; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - unsigned char *mac; - unsigned char bssrate[NumRates]; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - int bssrate_len = 0; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - goto exit; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - mac = myid(&(padapter->eeprompriv)); - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - if (da) { - /* unicast probe request frame */ - memcpy(pwlanhdr->addr1, da, ETH_ALEN); - memcpy(pwlanhdr->addr3, da, ETH_ALEN); - } else { - /* broadcast probe request frame */ - eth_broadcast_addr(pwlanhdr->addr1); - eth_broadcast_addr(pwlanhdr->addr3); - } - - memcpy(pwlanhdr->addr2, mac, ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_PROBEREQ); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - if (pssid) - pframe = rtw_set_ie(pframe, WLAN_EID_SSID, pssid->ssid_length, pssid->ssid, &(pattrib->pktlen)); - else - pframe = rtw_set_ie(pframe, WLAN_EID_SSID, 0, NULL, &(pattrib->pktlen)); - - get_rate_set(padapter, bssrate, &bssrate_len); - - if (bssrate_len > 8) { - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, 8, bssrate, &(pattrib->pktlen)); - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_SUPP_RATES, (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen)); - } else { - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, bssrate_len, bssrate, &(pattrib->pktlen)); - } - - if (ch) - pframe = rtw_set_ie(pframe, WLAN_EID_DS_PARAMS, 1, &ch, &pattrib->pktlen); - - if (append_wps) { - /* add wps_ie for wps2.0 */ - if (pmlmepriv->wps_probe_req_ie_len > 0 && pmlmepriv->wps_probe_req_ie) { - memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len); - pframe += pmlmepriv->wps_probe_req_ie_len; - pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len; - } - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - if (wait_ack) { - ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe); - } else { - dump_mgntframe(padapter, pmgntframe); - ret = _SUCCESS; - } - -exit: - return ret; -} - -inline void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da) -{ - _issue_probereq(padapter, pssid, da, 0, 1, false); -} - -int issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, u8 ch, bool append_wps, - int try_cnt, int wait_ms) -{ - int ret; - int i = 0; - - do { - ret = _issue_probereq(padapter, pssid, da, ch, append_wps, - wait_ms > 0); - - i++; - - if (padapter->driver_stopped || padapter->bSurpriseRemoved) - break; - - if (i < try_cnt && wait_ms > 0 && ret == _FAIL) - msleep(wait_ms); - - } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0))); - - if (ret != _FAIL) { - ret = _SUCCESS; - #ifndef DBG_XMIT_ACK - goto exit; - #endif - } - -exit: - return ret; -} - -/* if psta == NULL, indicate we are station(client) now... */ -void issue_auth(struct adapter *padapter, struct sta_info *psta, unsigned short status) -{ - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - unsigned int val32; - unsigned short val16; - int use_shared_key = 0; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - __le16 le_tmp; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_AUTH); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - if (psta) { /* for AP mode */ - memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN); - - /* setting auth algo number */ - val16 = (u16)psta->authalg; - - if (status != WLAN_STATUS_SUCCESS) - val16 = 0; - - if (val16) - use_shared_key = 1; - - le_tmp = cpu_to_le16(val16); - - pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - /* setting auth seq number */ - val16 = (u16)psta->auth_seq; - le_tmp = cpu_to_le16(val16); - pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - /* setting status code... */ - val16 = status; - le_tmp = cpu_to_le16(val16); - pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - /* added challenging text... */ - if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) - pframe = rtw_set_ie(pframe, WLAN_EID_CHALLENGE, 128, psta->chg_txt, &(pattrib->pktlen)); - - } else { - memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN); - - /* setting auth algo number */ - val16 = (pmlmeinfo->auth_algo == dot11_auth_algrthm_shared) ? 1 : 0;/* 0:OPEN System, 1:Shared key */ - if (val16) - use_shared_key = 1; - le_tmp = cpu_to_le16(val16); - - /* setting IV for auth seq #3 */ - if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) { - __le32 le_tmp32; - - val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30)); - le_tmp32 = cpu_to_le32(val32); - pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&le_tmp32, &(pattrib->pktlen)); - - pattrib->iv_len = 4; - } - - pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - /* setting auth seq number */ - le_tmp = cpu_to_le16(pmlmeinfo->auth_seq); - pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - /* setting status code... */ - le_tmp = cpu_to_le16(status); - pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - /* then checking to see if sending challenging text... */ - if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) { - pframe = rtw_set_ie(pframe, WLAN_EID_CHALLENGE, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen)); - - SetPrivacy(fctrl); - - pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr); - - pattrib->encrypt = _WEP40_; - - pattrib->icv_len = 4; - - pattrib->pktlen += pattrib->icv_len; - } - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - rtw_wep_encrypt(padapter, (u8 *)pmgntframe); - dump_mgntframe(padapter, pmgntframe); -} - -void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type) -{ - struct xmit_frame *pmgntframe; - struct ieee80211_hdr *pwlanhdr; - struct pkt_attrib *pattrib; - unsigned char *pbuf, *pframe; - unsigned short val; - __le16 *fctrl; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); - u8 *ie = pnetwork->ies; - __le16 lestatus, le_tmp; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - memcpy(GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN); - memcpy(GetAddr2Ptr(pwlanhdr), myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP)) { - SetFrameSubType(pwlanhdr, pkt_type); - } else { - rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(pxmitpriv, pmgntframe); - return; - } - - pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen += pattrib->hdrlen; - pframe += pattrib->hdrlen; - - /* capability */ - val = *(unsigned short *)rtw_get_capability_from_ie(ie); - - pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_, (unsigned char *)&val, &(pattrib->pktlen)); - - lestatus = cpu_to_le16(status); - pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&lestatus, &(pattrib->pktlen)); - - le_tmp = cpu_to_le16(pstat->aid | BIT(14) | BIT(15)); - pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - if (pstat->bssratelen <= 8) { - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen)); - } else { - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, 8, pstat->bssrateset, &(pattrib->pktlen)); - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_SUPP_RATES, (pstat->bssratelen - 8), - pstat->bssrateset + 8, &pattrib->pktlen); - } - - if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option)) { - uint ie_len = 0; - - /* FILL HT CAP INFO IE */ - /* p = hostapd_eid_ht_capabilities_info(hapd, p); */ - pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_HT_CAPABILITY, &ie_len, (pnetwork->ie_length - _BEACON_IE_OFFSET_)); - if (pbuf && ie_len > 0) { - memcpy(pframe, pbuf, ie_len + 2); - pframe += (ie_len + 2); - pattrib->pktlen += (ie_len + 2); - } - - /* FILL HT ADD INFO IE */ - /* p = hostapd_eid_ht_operation(hapd, p); */ - pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_HT_OPERATION, &ie_len, (pnetwork->ie_length - _BEACON_IE_OFFSET_)); - if (pbuf && ie_len > 0) { - memcpy(pframe, pbuf, ie_len + 2); - pframe += (ie_len + 2); - pattrib->pktlen += (ie_len + 2); - } - } - - /* FILL WMM IE */ - if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option)) { - uint ie_len = 0; - unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01}; - - for (pbuf = ie + _BEACON_IE_OFFSET_; ; pbuf += (ie_len + 2)) { - pbuf = rtw_get_ie(pbuf, WLAN_EID_VENDOR_SPECIFIC, &ie_len, (pnetwork->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2))); - if (pbuf && !memcmp(pbuf + 2, WMM_PARA_IE, 6)) { - memcpy(pframe, pbuf, ie_len + 2); - pframe += (ie_len + 2); - pattrib->pktlen += (ie_len + 2); - - break; - } - - if (!pbuf || ie_len == 0) - break; - } - } - - if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK) - pframe = rtw_set_ie(pframe, WLAN_EID_VENDOR_SPECIFIC, 6, REALTEK_96B_IE, &(pattrib->pktlen)); - - /* add WPS IE ie for wps 2.0 */ - if (pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len > 0) { - memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len); - - pframe += pmlmepriv->wps_assoc_resp_ie_len; - pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len; - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - dump_mgntframe(padapter, pmgntframe); -} - -void issue_assocreq(struct adapter *padapter) -{ - int ret = _FAIL; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - __le16 val16; - unsigned int i, j, index = 0; - unsigned char bssrate[NumRates], sta_bssrate[NumRates]; - struct ndis_80211_var_ie *pIE; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - int bssrate_len = 0, sta_bssrate_len = 0; - u8 vs_ie_length = 0; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - goto exit; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_ASSOCREQ); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - /* caps */ - memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.ies), 2); - - pframe += 2; - pattrib->pktlen += 2; - - /* listen interval */ - /* todo: listen interval for power saving */ - val16 = cpu_to_le16(3); - memcpy(pframe, (unsigned char *)&val16, 2); - pframe += 2; - pattrib->pktlen += 2; - - /* SSID */ - pframe = rtw_set_ie(pframe, WLAN_EID_SSID, pmlmeinfo->network.ssid.ssid_length, pmlmeinfo->network.ssid.ssid, &(pattrib->pktlen)); - - /* supported rate & extended supported rate */ - - /* Check if the AP's supported rates are also supported by STA. */ - get_rate_set(padapter, sta_bssrate, &sta_bssrate_len); - - if (pmlmeext->cur_channel == 14) /* for JAPAN, channel 14 can only uses B Mode(CCK) */ - sta_bssrate_len = 4; - - /* for (i = 0; i < sta_bssrate_len; i++) { */ - /* */ - - for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) { - if (pmlmeinfo->network.supported_rates[i] == 0) - break; - } - - for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) { - if (pmlmeinfo->network.supported_rates[i] == 0) - break; - - /* Check if the AP's supported rates are also supported by STA. */ - for (j = 0; j < sta_bssrate_len; j++) { - /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */ - if ((pmlmeinfo->network.supported_rates[i] | IEEE80211_BASIC_RATE_MASK) - == (sta_bssrate[j] | IEEE80211_BASIC_RATE_MASK)) - break; - } - - if (j != sta_bssrate_len) - /* the rate is supported by STA */ - bssrate[index++] = pmlmeinfo->network.supported_rates[i]; - } - - bssrate_len = index; - - if (bssrate_len == 0) { - rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf); - rtw_free_xmitframe(pxmitpriv, pmgntframe); - goto exit; /* don't connect to AP if no joint supported rate */ - } - - if (bssrate_len > 8) { - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, 8, bssrate, &(pattrib->pktlen)); - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_SUPP_RATES, (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen)); - } else - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, bssrate_len, bssrate, &(pattrib->pktlen)); - - /* vendor specific IE, such as WPA, WMM, WPS */ - for (i = sizeof(struct ndis_802_11_fix_ie); i < pmlmeinfo->network.ie_length;) { - if (i + sizeof(*pIE) > pmlmeinfo->network.ie_length) - break; - pIE = (struct ndis_80211_var_ie *)(pmlmeinfo->network.ies + i); - if (i + sizeof(*pIE) + pIE->length > pmlmeinfo->network.ie_length) - break; - - switch (pIE->element_id) { - case WLAN_EID_VENDOR_SPECIFIC: - if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) || - (!memcmp(pIE->data, WMM_OUI, 4)) || - (!memcmp(pIE->data, WPS_OUI, 4))) { - vs_ie_length = pIE->length; - if ((!padapter->registrypriv.wifi_spec) && (!memcmp(pIE->data, WPS_OUI, 4))) { - /* Commented by Kurt 20110629 - * In some older APs, WPS handshake - * would be fail if we append vendor - * extensions information to AP - */ - - vs_ie_length = 14; - } - - pframe = rtw_set_ie(pframe, WLAN_EID_VENDOR_SPECIFIC, vs_ie_length, pIE->data, &(pattrib->pktlen)); - } - break; - - case WLAN_EID_RSN: - pframe = rtw_set_ie(pframe, WLAN_EID_RSN, pIE->length, pIE->data, &(pattrib->pktlen)); - break; - case WLAN_EID_HT_CAPABILITY: - if (padapter->mlmepriv.htpriv.ht_option) { - if (!(is_ap_in_tkip(padapter))) { - memcpy(&(pmlmeinfo->HT_caps), pIE->data, sizeof(struct HT_caps_element)); - pframe = rtw_set_ie(pframe, WLAN_EID_HT_CAPABILITY, pIE->length, (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen)); - } - } - break; - - case WLAN_EID_EXT_CAPABILITY: - if (padapter->mlmepriv.htpriv.ht_option) - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_CAPABILITY, pIE->length, pIE->data, &(pattrib->pktlen)); - break; - default: - break; - } - - i += (pIE->length + 2); - } - - if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK) - pframe = rtw_set_ie(pframe, WLAN_EID_VENDOR_SPECIFIC, 6, REALTEK_96B_IE, &(pattrib->pktlen)); - - pattrib->last_txcmdsz = pattrib->pktlen; - dump_mgntframe(padapter, pmgntframe); - - ret = _SUCCESS; - -exit: - if (ret == _SUCCESS) - rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen); - else - rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len); -} - -/* when wait_ack is true, this function should be called at process context */ -static int _issue_nulldata(struct adapter *padapter, unsigned char *da, - unsigned int power_mode, bool wait_ack) -{ - int ret = _FAIL; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - struct xmit_priv *pxmitpriv; - struct mlme_ext_priv *pmlmeext; - struct mlme_ext_info *pmlmeinfo; - - if (!padapter) - goto exit; - - pxmitpriv = &(padapter->xmitpriv); - pmlmeext = &(padapter->mlmeextpriv); - pmlmeinfo = &pmlmeext->mlmext_info; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - goto exit; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->retry_ctrl = false; - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) - SetFrDs(fctrl); - else if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) - SetToDs(fctrl); - - if (power_mode) - SetPwrMgt(fctrl); - - memcpy(pwlanhdr->addr1, da, ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_DATA_NULL); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - pattrib->last_txcmdsz = pattrib->pktlen; - - if (wait_ack) { - ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe); - } else { - dump_mgntframe(padapter, pmgntframe); - ret = _SUCCESS; - } - -exit: - return ret; -} - -/* - * [IMPORTANT] Don't call this function in interrupt context - * - * When wait_ms > 0, this function should be called at process context - * da == NULL for station mode - */ -int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms) -{ - int ret; - int i = 0; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct sta_info *psta; - - /* da == NULL, assume it's null data for sta to ap*/ - if (!da) - da = get_my_bssid(&(pmlmeinfo->network)); - - psta = rtw_get_stainfo(&padapter->stapriv, da); - if (psta) { - if (power_mode) - rtw_hal_macid_sleep(padapter, psta->mac_id); - else - rtw_hal_macid_wakeup(padapter, psta->mac_id); - } else { - WARN_ON(1); - } - - do { - ret = _issue_nulldata(padapter, da, power_mode, wait_ms > 0); - - i++; - - if (padapter->driver_stopped || padapter->bSurpriseRemoved) - break; - - if (i < try_cnt && wait_ms > 0 && ret == _FAIL) - msleep(wait_ms); - - } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0))); - - if (ret != _FAIL) { - ret = _SUCCESS; - #ifndef DBG_XMIT_ACK - goto exit; - #endif - } - -exit: - return ret; -} - -/* - * [IMPORTANT] This function run in interrupt context - * - * The null data packet would be sent without power bit, - * and not guarantee success. - */ -s32 issue_nulldata_in_interrupt(struct adapter *padapter, u8 *da) -{ - struct mlme_ext_priv *pmlmeext; - struct mlme_ext_info *pmlmeinfo; - - pmlmeext = &padapter->mlmeextpriv; - pmlmeinfo = &pmlmeext->mlmext_info; - - /* da == NULL, assume it's null data for sta to ap*/ - if (!da) - da = get_my_bssid(&(pmlmeinfo->network)); - - return _issue_nulldata(padapter, da, 0, false); -} - -/* when wait_ack is true, this function should be called at process context */ -static int _issue_qos_nulldata(struct adapter *padapter, unsigned char *da, - u16 tid, bool wait_ack) -{ - int ret = _FAIL; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - u16 *qc; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - goto exit; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - pattrib->hdrlen += 2; - pattrib->qos_en = true; - pattrib->eosp = 1; - pattrib->ack_policy = 0; - pattrib->mdata = 0; - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) - SetFrDs(fctrl); - else if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) - SetToDs(fctrl); - - qc = (unsigned short *)(pframe + pattrib->hdrlen - 2); - - SetPriority(qc, tid); - - SetEOSP(qc, pattrib->eosp); - - SetAckpolicy(qc, pattrib->ack_policy); - - memcpy(pwlanhdr->addr1, da, ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_QOS_DATA_NULL); - - pframe += sizeof(struct ieee80211_qos_hdr); - pattrib->pktlen = sizeof(struct ieee80211_qos_hdr); - - pattrib->last_txcmdsz = pattrib->pktlen; - - if (wait_ack) { - ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe); - } else { - dump_mgntframe(padapter, pmgntframe); - ret = _SUCCESS; - } - -exit: - return ret; -} - -/* when wait_ms >0 , this function should be called at process context */ -/* da == NULL for station mode */ -int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms) -{ - int ret; - int i = 0; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - /* da == NULL, assume it's null data for sta to ap*/ - if (!da) - da = get_my_bssid(&(pmlmeinfo->network)); - - do { - ret = _issue_qos_nulldata(padapter, da, tid, wait_ms > 0); - - i++; - - if (padapter->driver_stopped || padapter->bSurpriseRemoved) - break; - - if (i < try_cnt && wait_ms > 0 && ret == _FAIL) - msleep(wait_ms); - - } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0))); - - if (ret != _FAIL) { - ret = _SUCCESS; - #ifndef DBG_XMIT_ACK - goto exit; - #endif - } - -exit: - return ret; -} - -static int _issue_deauth(struct adapter *padapter, unsigned char *da, - unsigned short reason, bool wait_ack) -{ - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - int ret = _FAIL; - __le16 le_tmp; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - goto exit; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->retry_ctrl = false; - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - memcpy(pwlanhdr->addr1, da, ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_DEAUTH); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - le_tmp = cpu_to_le16(reason); - pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_, (unsigned char *)&le_tmp, &(pattrib->pktlen)); - - pattrib->last_txcmdsz = pattrib->pktlen; - - if (wait_ack) { - ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe); - } else { - dump_mgntframe(padapter, pmgntframe); - ret = _SUCCESS; - } - -exit: - return ret; -} - -int issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason) -{ - return _issue_deauth(padapter, da, reason, false); -} - -int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int try_cnt, - int wait_ms) -{ - int ret; - int i = 0; - - do { - ret = _issue_deauth(padapter, da, reason, wait_ms > 0); - - i++; - - if (padapter->driver_stopped || padapter->bSurpriseRemoved) - break; - - if (i < try_cnt && wait_ms > 0 && ret == _FAIL) - mdelay(wait_ms); - - } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0))); - - if (ret != _FAIL) { - ret = _SUCCESS; - #ifndef DBG_XMIT_ACK - goto exit; - #endif - } - -exit: - return ret; -} - -void issue_action_SA_Query(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short tid) -{ - u8 category = RTW_WLAN_CATEGORY_SA_QUERY; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - u8 *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - __le16 le_tmp; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - if (raddr) - memcpy(pwlanhdr->addr1, raddr, ETH_ALEN); - else - memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_ACTION); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - pframe = rtw_set_fixed_ie(pframe, 1, &category, &pattrib->pktlen); - pframe = rtw_set_fixed_ie(pframe, 1, &action, &pattrib->pktlen); - - switch (action) { - case 0: /* SA Query req */ - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)&pmlmeext->sa_query_seq, &pattrib->pktlen); - pmlmeext->sa_query_seq++; - /* send sa query request to AP, AP should reply sa query response in 1 second */ - set_sa_query_timer(pmlmeext, 1000); - break; - - case 1: /* SA Query rsp */ - le_tmp = cpu_to_le16(tid); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)&le_tmp, &pattrib->pktlen); - break; - default: - break; - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - dump_mgntframe(padapter, pmgntframe); -} - -void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status) -{ - u8 category = RTW_WLAN_CATEGORY_BACK; - u16 start_seq; - u16 BA_para_set; - u16 reason_code; - u16 BA_timeout_value; - u16 BA_starting_seqctrl = 0; - enum ieee80211_max_ampdu_length_exp max_rx_ampdu_factor; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - u8 *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct sta_info *psta; - struct sta_priv *pstapriv = &padapter->stapriv; - struct registry_priv *pregpriv = &padapter->registrypriv; - __le16 le_tmp; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - /* memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); */ - memcpy(pwlanhdr->addr1, raddr, ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_ACTION); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen)); - pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen)); - - if (category == 3) { - switch (action) { - case 0: /* ADDBA req */ - do { - pmlmeinfo->dialogToken++; - } while (pmlmeinfo->dialogToken == 0); - pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen)); - - if (hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter)) { - /* A-MSDU NOT Supported */ - BA_para_set = 0; - /* immediate Block Ack */ - BA_para_set |= BIT(1) & IEEE80211_ADDBA_PARAM_POLICY_MASK; - /* TID */ - BA_para_set |= (status << 2) & IEEE80211_ADDBA_PARAM_TID_MASK; - /* max buffer size is 8 MSDU */ - BA_para_set |= (8 << 6) & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK; - } else { - BA_para_set = (0x1002 | ((status & 0xf) << 2)); /* immediate ack & 64 buffer size */ - } - le_tmp = cpu_to_le16(BA_para_set); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen)); - - BA_timeout_value = 5000;/* 5ms */ - le_tmp = cpu_to_le16(BA_timeout_value); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen)); - - /* if ((psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.mac_address)) != NULL) */ - psta = rtw_get_stainfo(pstapriv, raddr); - if (psta) { - start_seq = (psta->sta_xmitpriv.txseq_tid[status & 0x07] % 4096u) + 1; - - psta->BA_starting_seqctrl[status & 0x07] = start_seq; - - BA_starting_seqctrl = start_seq << 4; - } - - le_tmp = cpu_to_le16(BA_starting_seqctrl); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen)); - break; - - case 1: /* ADDBA rsp */ - pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen)); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen)); - if (padapter->driver_rx_ampdu_factor != 0xFF) - max_rx_ampdu_factor = - (enum ieee80211_max_ampdu_length_exp)padapter->driver_rx_ampdu_factor; - else - rtw_hal_get_def_var(padapter, - HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor); - - if (max_rx_ampdu_factor == IEEE80211_HT_MAX_AMPDU_64K) - BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); /* 64 buffer size */ - else if (max_rx_ampdu_factor == IEEE80211_HT_MAX_AMPDU_32K) - BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0800); /* 32 buffer size */ - else if (max_rx_ampdu_factor == IEEE80211_HT_MAX_AMPDU_16K) - BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0400); /* 16 buffer size */ - else if (max_rx_ampdu_factor == IEEE80211_HT_MAX_AMPDU_8K) - BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x0200); /* 8 buffer size */ - else - BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); /* 64 buffer size */ - - if (hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter) && - padapter->driver_rx_ampdu_factor == 0xFF) { - /* max buffer size is 8 MSDU */ - BA_para_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK; - BA_para_set |= (8 << 6) & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK; - } - - if (pregpriv->ampdu_amsdu == 0)/* disabled */ - le_tmp = cpu_to_le16(BA_para_set & ~BIT(0)); - else if (pregpriv->ampdu_amsdu == 1)/* enabled */ - le_tmp = cpu_to_le16(BA_para_set | BIT(0)); - else /* auto */ - le_tmp = cpu_to_le16(BA_para_set); - - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen)); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen)); - break; - case 2:/* DELBA */ - BA_para_set = (status & 0x1F) << 3; - le_tmp = cpu_to_le16(BA_para_set); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen)); - - reason_code = 37; - le_tmp = cpu_to_le16(reason_code); - pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen)); - break; - default: - break; - } - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - dump_mgntframe(padapter, pmgntframe); -} - -static void issue_action_BSSCoexistPacket(struct adapter *padapter) -{ - struct list_head *plist, *phead; - unsigned char category, action; - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - struct wlan_network *pnetwork = NULL; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct __queue *queue = &(pmlmepriv->scanned_queue); - u8 InfoContent[16] = {0}; - u8 ICS[8][15]; - - if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0)) - return; - - if (true == pmlmeinfo->bwmode_updated) - return; - - category = RTW_WLAN_CATEGORY_PUBLIC; - action = ACT_PUBLIC_BSSCOEXIST; - - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - return; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); - memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); - - SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq); - pmlmeext->mgnt_seq++; - SetFrameSubType(pframe, WIFI_ACTION); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pattrib->pktlen = sizeof(struct ieee80211_hdr_3addr); - - pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen)); - pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen)); - - /* */ - if (pmlmepriv->num_FortyMHzIntolerant > 0) { - u8 iedata = 0; - - iedata |= BIT(2);/* 20 MHz BSS Width Request */ - - pframe = rtw_set_ie(pframe, WLAN_EID_BSS_COEX_2040, 1, &iedata, &(pattrib->pktlen)); - } - - /* */ - memset(ICS, 0, sizeof(ICS)); - if (pmlmepriv->num_sta_no_ht > 0) { - int i; - - spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); - - phead = get_list_head(queue); - plist = get_next(phead); - - while (1) { - int len; - u8 *p; - struct wlan_bssid_ex *pbss_network; - - if (phead == plist) - break; - - pnetwork = container_of(plist, struct wlan_network, list); - - plist = get_next(plist); - - pbss_network = (struct wlan_bssid_ex *)&pnetwork->network; - - p = rtw_get_ie(pbss_network->ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_CAPABILITY, &len, pbss_network->ie_length - _FIXED_IE_LENGTH_); - if (!p || len == 0) {/* non-HT */ - - if (pbss_network->configuration.ds_config <= 0) - continue; - - ICS[0][pbss_network->configuration.ds_config] = 1; - - if (ICS[0][0] == 0) - ICS[0][0] = 1; - } - } - - spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); - - for (i = 0; i < 8; i++) { - int j, k = 0; - - if (ICS[i][0] != 1) - continue; - - InfoContent[k] = i; - /* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent, i); */ - k++; - - for (j = 1; j <= 14; j++) { - if (ICS[i][j] != 1) - continue; - - if (k < 16) { - InfoContent[k] = j; /* channel number */ - /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */ - k++; - } - } - - pframe = rtw_set_ie(pframe, WLAN_EID_BSS_INTOLERANT_CHL_REPORT, k, InfoContent, &(pattrib->pktlen)); - } - } - - pattrib->last_txcmdsz = pattrib->pktlen; - - dump_mgntframe(padapter, pmgntframe); -} - -unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *psta = NULL; - /* struct recv_reorder_ctrl *preorder_ctrl; */ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u16 tid; - - if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE) - if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) - return _SUCCESS; - - psta = rtw_get_stainfo(pstapriv, addr); - if (!psta) - return _SUCCESS; - - if (initiator == 0) {/* recipient */ - for (tid = 0; tid < MAXTID; tid++) { - if (psta->recvreorder_ctrl[tid].enable) { - issue_action_BA(padapter, addr, WLAN_ACTION_DELBA, - (((tid << 1) | initiator) & 0x1F)); - psta->recvreorder_ctrl[tid].enable = false; - psta->recvreorder_ctrl[tid].indicate_seq = 0xffff; - } - } - } else if (initiator == 1) {/* originator */ - for (tid = 0; tid < MAXTID; tid++) { - if (psta->htpriv.agg_enable_bitmap & BIT(tid)) { - issue_action_BA(padapter, addr, WLAN_ACTION_DELBA, - (((tid << 1) | initiator) & 0x1F)); - psta->htpriv.agg_enable_bitmap &= ~BIT(tid); - psta->htpriv.candidate_tid_bitmap &= ~BIT(tid); - } - } - } - - return _SUCCESS; -} - -unsigned int send_beacon(struct adapter *padapter) -{ - u8 bxmitok = false; - int issue = 0; - int poll = 0; - - rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL); - rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL); - do { - issue_beacon(padapter, 100); - issue++; - do { - cond_resched(); - rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok)); - poll++; - } while ((poll % 10) != 0 && !bxmitok && - !padapter->bSurpriseRemoved && - !padapter->driver_stopped); - - } while (false == bxmitok && issue < 100 && !padapter->bSurpriseRemoved && - !padapter->driver_stopped); - - if (padapter->bSurpriseRemoved || padapter->driver_stopped) - return _FAIL; - - if (!bxmitok) - return _FAIL; - else - return _SUCCESS; -} - -/* Following are some utility functions for WiFi MLME */ - -void site_survey(struct adapter *padapter) -{ - unsigned char survey_channel = 0, val8; - enum rt_scan_type scan_type = SCAN_PASSIVE; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u32 initialgain = 0; - u32 channel_scan_time_ms = 0; - - { - struct rtw_ieee80211_channel *ch; - - if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) { - ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx]; - survey_channel = ch->hw_value; - scan_type = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? - SCAN_PASSIVE : SCAN_ACTIVE; - } - } - - if (survey_channel != 0) { - if (pmlmeext->sitesurvey_res.channel_idx == 0) - set_channel_bwmode(padapter, survey_channel, - HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20); - else - r8723bs_select_channel(padapter, survey_channel); - - if (scan_type == SCAN_ACTIVE) { /* obey the channel plan setting... */ - { - int i; - - for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) { - if (!pmlmeext->sitesurvey_res.ssid[i].ssid_length) - continue; - - /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */ - if (padapter->registrypriv.wifi_spec) - issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL); - else - issue_probereq_ex(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL, 0, 0, 0, 0); - - issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL); - } - - if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) { - /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */ - if (padapter->registrypriv.wifi_spec) - issue_probereq(padapter, NULL, NULL); - else - issue_probereq_ex(padapter, NULL, NULL, 0, 0, 0, 0); - issue_probereq(padapter, NULL, NULL); - } - } - } - - channel_scan_time_ms = pmlmeext->chan_scan_time; - - set_survey_timer(pmlmeext, channel_scan_time_ms); - } else { - /* channel number is 0 or this channel is not valid. */ - - { - pmlmeext->sitesurvey_res.state = SCAN_COMPLETE; - - /* switch back to the original channel */ - /* SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset); */ - - set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); - - /* flush 4-AC Queue after site_survey */ - /* val8 = 0; */ - /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */ - - /* config MSR */ - set_msr(padapter, (pmlmeinfo->state & 0x3)); - - initialgain = 0xff; /* restore RX GAIN */ - rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); - /* turn on dynamic functions */ - restore_dm_func_flag(padapter); - /* switch_dm_func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); */ - - if (is_client_associated_to_ap(padapter)) - issue_nulldata(padapter, NULL, 0, 3, 500); - - val8 = 0; /* survey done */ - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8)); - - report_surveydone_event(padapter); - - pmlmeext->chan_scan_time = SURVEY_TO; - pmlmeext->sitesurvey_res.state = SCAN_DISABLE; - - issue_action_BSSCoexistPacket(padapter); - issue_action_BSSCoexistPacket(padapter); - issue_action_BSSCoexistPacket(padapter); - } - } -} - -/* collect bss info from Beacon and Probe request/response frames. */ -u8 collect_bss_info(struct adapter *padapter, union recv_frame *precv_frame, struct wlan_bssid_ex *bssid) -{ - int i; - u32 len; - u8 *p; - u16 val16, subtype; - u8 *pframe = precv_frame->u.hdr.rx_data; - u32 packet_len = precv_frame->u.hdr.len; - u8 ie_offset; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - __le32 le32_tmp; - - len = packet_len - sizeof(struct ieee80211_hdr_3addr); - - if (len > MAX_IE_SZ) - return _FAIL; - - memset(bssid, 0, sizeof(struct wlan_bssid_ex)); - - subtype = GetFrameSubType(pframe); - - if (subtype == WIFI_BEACON) { - bssid->reserved[0] = 1; - ie_offset = _BEACON_IE_OFFSET_; - } else { - /* FIXME : more type */ - if (subtype == WIFI_PROBERSP) { - ie_offset = _PROBERSP_IE_OFFSET_; - bssid->reserved[0] = 3; - } else if (subtype == WIFI_PROBEREQ) { - ie_offset = _PROBEREQ_IE_OFFSET_; - bssid->reserved[0] = 2; - } else { - bssid->reserved[0] = 0; - ie_offset = _FIXED_IE_LENGTH_; - } - } - - bssid->length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len; - - /* below is to copy the information element */ - bssid->ie_length = len; - memcpy(bssid->ies, (pframe + sizeof(struct ieee80211_hdr_3addr)), bssid->ie_length); - - /* get the signal strength */ - bssid->rssi = precv_frame->u.hdr.attrib.phy_info.RecvSignalPower; /* in dBM.raw data */ - bssid->phy_info.signal_quality = precv_frame->u.hdr.attrib.phy_info.SignalQuality;/* in percentage */ - bssid->phy_info.signal_strength = precv_frame->u.hdr.attrib.phy_info.SignalStrength;/* in percentage */ - - /* checking SSID */ - p = rtw_get_ie(bssid->ies + ie_offset, WLAN_EID_SSID, &len, bssid->ie_length - ie_offset); - if (!p) - return _FAIL; - - if (*(p + 1)) { - if (len > NDIS_802_11_LENGTH_SSID) - return _FAIL; - - memcpy(bssid->ssid.ssid, (p + 2), *(p + 1)); - bssid->ssid.ssid_length = *(p + 1); - } else - bssid->ssid.ssid_length = 0; - - memset(bssid->supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX); - - /* checking rate info... */ - i = 0; - p = rtw_get_ie(bssid->ies + ie_offset, WLAN_EID_SUPP_RATES, &len, bssid->ie_length - ie_offset); - if (p) { - if (len > NDIS_802_11_LENGTH_RATES_EX) - return _FAIL; - - memcpy(bssid->supported_rates, (p + 2), len); - i = len; - } - - p = rtw_get_ie(bssid->ies + ie_offset, WLAN_EID_EXT_SUPP_RATES, &len, bssid->ie_length - ie_offset); - if (p) { - if (len > (NDIS_802_11_LENGTH_RATES_EX - i)) - return _FAIL; - - memcpy(bssid->supported_rates + i, (p + 2), len); - } - - if (bssid->ie_length < 12) - return _FAIL; - - /* Checking for ds_config */ - p = rtw_get_ie(bssid->ies + ie_offset, WLAN_EID_DS_PARAMS, &len, bssid->ie_length - ie_offset); - - bssid->configuration.ds_config = 0; - bssid->configuration.length = 0; - - if (p) { - bssid->configuration.ds_config = *(p + 2); - } else { - /* In 5G, some ap do not have DSSET IE */ - /* checking HT info for channel */ - p = rtw_get_ie(bssid->ies + ie_offset, WLAN_EID_HT_OPERATION, &len, bssid->ie_length - ie_offset); - if (p) { - struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2); - - bssid->configuration.ds_config = HT_info->primary_channel; - } else { /* use current channel */ - bssid->configuration.ds_config = rtw_get_oper_ch(padapter); - } - } - - memcpy(&le32_tmp, rtw_get_beacon_interval_from_ie(bssid->ies), 2); - bssid->configuration.beacon_period = le32_to_cpu(le32_tmp); - - val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid); - - if (val16 & BIT(0)) { - bssid->infrastructure_mode = NL80211_IFTYPE_STATION; - memcpy(bssid->mac_address, GetAddr2Ptr(pframe), ETH_ALEN); - } else { - bssid->infrastructure_mode = NL80211_IFTYPE_ADHOC; - memcpy(bssid->mac_address, GetAddr3Ptr(pframe), ETH_ALEN); - } - - if (val16 & BIT(4)) - bssid->privacy = 1; - else - bssid->privacy = 0; - - bssid->configuration.atim_window = 0; - - /* 20/40 BSS Coexistence check */ - if ((pregistrypriv->wifi_spec == 1) && (false == pmlmeinfo->bwmode_updated)) { - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - p = rtw_get_ie(bssid->ies + ie_offset, WLAN_EID_HT_CAPABILITY, &len, bssid->ie_length - ie_offset); - if (p && len > 0) { - struct HT_caps_element *pHT_caps; - - pHT_caps = (struct HT_caps_element *)(p + 2); - - if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info) & BIT(14)) - pmlmepriv->num_FortyMHzIntolerant++; - } else - pmlmepriv->num_sta_no_ht++; - } - - /* mark bss info receiving from nearby channel as signal_quality 101 */ - if (bssid->configuration.ds_config != rtw_get_oper_ch(padapter)) - bssid->phy_info.signal_quality = 101; - - return _SUCCESS; -} - -void start_create_ibss(struct adapter *padapter) -{ - unsigned short caps; - u8 val8; - u8 join_type; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); - - pmlmeext->cur_channel = (u8)pnetwork->configuration.ds_config; - pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork); - - /* update wireless mode */ - update_wireless_mode(padapter); - - /* update capability */ - caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork); - update_capinfo(padapter, caps); - if (caps & WLAN_CAPABILITY_IBSS) {/* adhoc master */ - val8 = 0xcf; - rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8)); - - /* switch channel */ - /* SelectChannel(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE); */ - set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20); - - beacon_timing_control(padapter); - - /* set msr to WIFI_FW_ADHOC_STATE */ - pmlmeinfo->state = WIFI_FW_ADHOC_STATE; - set_msr(padapter, (pmlmeinfo->state & 0x3)); - - /* issue beacon */ - if (send_beacon(padapter) == _FAIL) { - report_join_res(padapter, -1); - pmlmeinfo->state = WIFI_FW_NULL_STATE; - } else { - rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.mac_address); - join_type = 0; - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type)); - - report_join_res(padapter, 1); - pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS; - rtw_indicate_connect(padapter); - } - } else { - return; - } - /* update bc/mc sta_info */ - update_bmc_sta(padapter); -} - -void start_clnt_join(struct adapter *padapter) -{ - unsigned short caps; - u8 val8; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); - int beacon_timeout; - - /* update wireless mode */ - update_wireless_mode(padapter); - - /* update capability */ - caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork); - update_capinfo(padapter, caps); - if (caps & WLAN_CAPABILITY_ESS) { - set_msr(padapter, WIFI_FW_STATION_STATE); - - val8 = (pmlmeinfo->auth_algo == dot11_auth_algrthm_8021x) ? 0xcc : 0xcf; - - rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8)); - - /* Because of AP's not receiving deauth before - * AP may: 1)not response auth or 2)deauth us after link is complete - * issue deauth before issuing auth to deal with the situation - * - * Commented by Albert 2012/07/21 - * For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it. - */ - { - /* To avoid connecting to AP fail during resume process, change retry count from 5 to 1 */ - issue_deauth_ex(padapter, pnetwork->mac_address, WLAN_REASON_DEAUTH_LEAVING, 1, 100); - } - - /* here wait for receiving the beacon to start auth */ - /* and enable a timer */ - beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval); - set_link_timer(pmlmeext, beacon_timeout); - _set_timer(&padapter->mlmepriv.assoc_timer, - (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO * REASSOC_LIMIT) + beacon_timeout); - - pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE; - } else if (caps & WLAN_CAPABILITY_IBSS) { /* adhoc client */ - set_msr(padapter, WIFI_FW_ADHOC_STATE); - - val8 = 0xcf; - rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8)); - - beacon_timing_control(padapter); - - pmlmeinfo->state = WIFI_FW_ADHOC_STATE; - - report_join_res(padapter, 1); - } else { - return; - } -} - -void start_clnt_auth(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - timer_delete_sync(&pmlmeext->link_timer); - - pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL); - pmlmeinfo->state |= WIFI_FW_AUTH_STATE; - - pmlmeinfo->auth_seq = 1; - pmlmeinfo->reauth_count = 0; - pmlmeinfo->reassoc_count = 0; - pmlmeinfo->link_count = 0; - pmlmeext->retry = 0; - - netdev_dbg(padapter->pnetdev, "start auth\n"); - issue_auth(padapter, NULL, 0); - - set_link_timer(pmlmeext, REAUTH_TO); -} - -void start_clnt_assoc(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - timer_delete_sync(&pmlmeext->link_timer); - - pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE)); - pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE); - - issue_assocreq(padapter); - - set_link_timer(pmlmeext, REASSOC_TO); -} - -unsigned int receive_disconnect(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - /* check A3 */ - if (!(!memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))) - return _SUCCESS; - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) { - if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) { - pmlmeinfo->state = WIFI_FW_NULL_STATE; - report_del_sta_event(padapter, MacAddr, reason); - - } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) { - pmlmeinfo->state = WIFI_FW_NULL_STATE; - report_join_res(padapter, -2); - } - } - - return _SUCCESS; -} - -static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid) -{ - struct registry_priv *pregistrypriv; - struct mlme_ext_priv *pmlmeext; - struct rt_channel_info *chplan_new; - u8 channel; - u8 i; - - pregistrypriv = &padapter->registrypriv; - pmlmeext = &padapter->mlmeextpriv; - - /* Adjust channel plan by AP Country IE */ - if (pregistrypriv->enable80211d && - (!pmlmeext->update_channel_plan_by_ap_done)) { - u8 *ie, *p; - u32 len; - struct rt_channel_plan chplan_ap; - struct rt_channel_info chplan_sta[MAX_CHANNEL_NUM]; - u8 country[4]; - u8 fcn; /* first channel number */ - u8 noc; /* number of channel */ - u8 j, k; - - ie = rtw_get_ie(bssid->ies + _FIXED_IE_LENGTH_, WLAN_EID_COUNTRY, &len, bssid->ie_length - _FIXED_IE_LENGTH_); - if (!ie) - return; - if (len < 6) - return; - - ie += 2; - p = ie; - ie += len; - - memset(country, 0, 4); - memcpy(country, p, 3); - p += 3; - - i = 0; - while ((ie - p) >= 3) { - fcn = *(p++); - noc = *(p++); - p++; - - for (j = 0; j < noc; j++) { - if (fcn <= 14) - channel = fcn + j; /* 2.4 GHz */ - else - channel = fcn + j * 4; /* 5 GHz */ - - chplan_ap.Channel[i++] = channel; - } - } - chplan_ap.Len = i; - - memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta)); - - memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set)); - chplan_new = pmlmeext->channel_set; - - i = j = k = 0; - if (pregistrypriv->wireless_mode & WIRELESS_11G) { - do { - if ((i == MAX_CHANNEL_NUM) || - (chplan_sta[i].channel_num == 0) || - (chplan_sta[i].channel_num > 14)) - break; - - if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14)) - break; - - if (chplan_sta[i].channel_num == chplan_ap.Channel[j]) { - chplan_new[k].channel_num = chplan_ap.Channel[j]; - chplan_new[k].scan_type = SCAN_ACTIVE; - i++; - j++; - k++; - } else if (chplan_sta[i].channel_num < chplan_ap.Channel[j]) { - chplan_new[k].channel_num = chplan_sta[i].channel_num; - chplan_new[k].scan_type = SCAN_PASSIVE; - i++; - k++; - } else if (chplan_sta[i].channel_num > chplan_ap.Channel[j]) { - chplan_new[k].channel_num = chplan_ap.Channel[j]; - chplan_new[k].scan_type = SCAN_ACTIVE; - j++; - k++; - } - } while (1); - - /* change AP not support channel to Passive scan */ - while ((i < MAX_CHANNEL_NUM) && - (chplan_sta[i].channel_num != 0) && - (chplan_sta[i].channel_num <= 14)) { - chplan_new[k].channel_num = chplan_sta[i].channel_num; - chplan_new[k].scan_type = SCAN_PASSIVE; - i++; - k++; - } - - /* add channel AP supported */ - while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) { - chplan_new[k].channel_num = chplan_ap.Channel[j]; - chplan_new[k].scan_type = SCAN_ACTIVE; - j++; - k++; - } - } else { - /* keep original STA 2.4G channel plan */ - while ((i < MAX_CHANNEL_NUM) && - (chplan_sta[i].channel_num != 0) && - (chplan_sta[i].channel_num <= 14)) { - chplan_new[k].channel_num = chplan_sta[i].channel_num; - chplan_new[k].scan_type = chplan_sta[i].scan_type; - i++; - k++; - } - - /* skip AP 2.4G channel plan */ - while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) - j++; - } - - pmlmeext->update_channel_plan_by_ap_done = 1; - } - - /* If channel is used by AP, set channel scan type to active */ - channel = bssid->configuration.ds_config; - chplan_new = pmlmeext->channel_set; - i = 0; - while ((i < MAX_CHANNEL_NUM) && (chplan_new[i].channel_num != 0)) { - if (chplan_new[i].channel_num == channel) { - if (chplan_new[i].scan_type == SCAN_PASSIVE) - chplan_new[i].scan_type = SCAN_ACTIVE; - break; - } - i++; - } -} - -/* Following are the functions to report events */ - -void report_survey_event(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct cmd_obj *pcmd_obj; - u8 *pevtcmd; - u32 cmdsz; - struct survey_event *psurvey_evt; - struct C2HEvent_Header *pc2h_evt_hdr; - struct mlme_ext_priv *pmlmeext; - struct cmd_priv *pcmdpriv; - /* u8 *pframe = precv_frame->u.hdr.rx_data; */ - /* uint len = precv_frame->u.hdr.len; */ - - if (!padapter) - return; - - pmlmeext = &padapter->mlmeextpriv; - pcmdpriv = &padapter->cmdpriv; - - pcmd_obj = kzalloc_obj(*pcmd_obj, GFP_ATOMIC); - if (!pcmd_obj) - return; - - cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header)); - pevtcmd = kzalloc(cmdsz, GFP_ATOMIC); - if (!pevtcmd) { - kfree(pcmd_obj); - return; - } - - INIT_LIST_HEAD(&pcmd_obj->list); - - pcmd_obj->cmdcode = SET_MLME_EVT_CMD; - pcmd_obj->cmdsz = cmdsz; - pcmd_obj->parmbuf = pevtcmd; - - pcmd_obj->rsp = NULL; - pcmd_obj->rspsz = 0; - - pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd); - pc2h_evt_hdr->len = sizeof(struct survey_event); - pc2h_evt_hdr->ID = SURVEY_EVENT; - pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq); - - psurvey_evt = (struct survey_event *)(pevtcmd + sizeof(struct C2HEvent_Header)); - - if (collect_bss_info(padapter, precv_frame, (struct wlan_bssid_ex *)&psurvey_evt->bss) == _FAIL) { - kfree(pcmd_obj); - kfree(pevtcmd); - return; - } - - process_80211d(padapter, &psurvey_evt->bss); - - rtw_enqueue_cmd(pcmdpriv, pcmd_obj); - - pmlmeext->sitesurvey_res.bss_cnt++; -} - -void report_surveydone_event(struct adapter *padapter) -{ - struct cmd_obj *pcmd_obj; - u8 *pevtcmd; - u32 cmdsz; - struct surveydone_event *psurveydone_evt; - struct C2HEvent_Header *pc2h_evt_hdr; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - - pcmd_obj = kzalloc_obj(*pcmd_obj, GFP_ATOMIC); - if (!pcmd_obj) - return; - - cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header)); - pevtcmd = kzalloc(cmdsz, GFP_ATOMIC); - if (!pevtcmd) { - kfree(pcmd_obj); - return; - } - - INIT_LIST_HEAD(&pcmd_obj->list); - - pcmd_obj->cmdcode = SET_MLME_EVT_CMD; - pcmd_obj->cmdsz = cmdsz; - pcmd_obj->parmbuf = pevtcmd; - - pcmd_obj->rsp = NULL; - pcmd_obj->rspsz = 0; - - pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd); - pc2h_evt_hdr->len = sizeof(struct surveydone_event); - pc2h_evt_hdr->ID = SURVEY_DONE_EVENT; - pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq); - - psurveydone_evt = (struct surveydone_event *)(pevtcmd + sizeof(struct C2HEvent_Header)); - psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt; - - rtw_enqueue_cmd(pcmdpriv, pcmd_obj); -} - -void report_join_res(struct adapter *padapter, int res) -{ - struct cmd_obj *pcmd_obj; - u8 *pevtcmd; - u32 cmdsz; - struct joinbss_event *pjoinbss_evt; - struct C2HEvent_Header *pc2h_evt_hdr; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - - pcmd_obj = kzalloc_obj(*pcmd_obj, GFP_ATOMIC); - if (!pcmd_obj) - return; - - cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header)); - pevtcmd = kzalloc(cmdsz, GFP_ATOMIC); - if (!pevtcmd) { - kfree(pcmd_obj); - return; - } - - INIT_LIST_HEAD(&pcmd_obj->list); - - pcmd_obj->cmdcode = SET_MLME_EVT_CMD; - pcmd_obj->cmdsz = cmdsz; - pcmd_obj->parmbuf = pevtcmd; - - pcmd_obj->rsp = NULL; - pcmd_obj->rspsz = 0; - - pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd); - pc2h_evt_hdr->len = sizeof(struct joinbss_event); - pc2h_evt_hdr->ID = JOIN_BSS_EVENT; - pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq); - - pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header)); - memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex)); - pjoinbss_evt->network.join_res = pjoinbss_evt->network.aid = res; - - rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network); - - rtw_enqueue_cmd(pcmdpriv, pcmd_obj); -} - -void report_wmm_edca_update(struct adapter *padapter) -{ - struct cmd_obj *pcmd_obj; - u8 *pevtcmd; - u32 cmdsz; - struct wmm_event *pwmm_event; - struct C2HEvent_Header *pc2h_evt_hdr; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - - pcmd_obj = kzalloc_obj(*pcmd_obj, GFP_ATOMIC); - if (!pcmd_obj) - return; - - cmdsz = (sizeof(struct wmm_event) + sizeof(struct C2HEvent_Header)); - pevtcmd = kzalloc(cmdsz, GFP_ATOMIC); - if (!pevtcmd) { - kfree(pcmd_obj); - return; - } - - INIT_LIST_HEAD(&pcmd_obj->list); - - pcmd_obj->cmdcode = SET_MLME_EVT_CMD; - pcmd_obj->cmdsz = cmdsz; - pcmd_obj->parmbuf = pevtcmd; - - pcmd_obj->rsp = NULL; - pcmd_obj->rspsz = 0; - - pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd); - pc2h_evt_hdr->len = sizeof(struct wmm_event); - pc2h_evt_hdr->ID = WMM_EVENT; - pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq); - - pwmm_event = (struct wmm_event *)(pevtcmd + sizeof(struct C2HEvent_Header)); - pwmm_event->wmm = 0; - - rtw_enqueue_cmd(pcmdpriv, pcmd_obj); -} - -void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason) -{ - struct cmd_obj *pcmd_obj; - u8 *pevtcmd; - u32 cmdsz; - struct sta_info *psta; - int mac_id; - struct stadel_event *pdel_sta_evt; - struct C2HEvent_Header *pc2h_evt_hdr; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - - pcmd_obj = kzalloc_obj(*pcmd_obj, GFP_ATOMIC); - if (!pcmd_obj) - return; - - cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header)); - pevtcmd = kzalloc(cmdsz, GFP_ATOMIC); - if (!pevtcmd) { - kfree(pcmd_obj); - return; - } - - INIT_LIST_HEAD(&pcmd_obj->list); - - pcmd_obj->cmdcode = SET_MLME_EVT_CMD; - pcmd_obj->cmdsz = cmdsz; - pcmd_obj->parmbuf = pevtcmd; - - pcmd_obj->rsp = NULL; - pcmd_obj->rspsz = 0; - - pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd); - pc2h_evt_hdr->len = sizeof(struct stadel_event); - pc2h_evt_hdr->ID = DEL_STA_EVENT; - pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq); - - pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header)); - memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN); - memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2); - - psta = rtw_get_stainfo(&padapter->stapriv, MacAddr); - if (psta) - mac_id = (int)psta->mac_id; - else - mac_id = (-1); - - pdel_sta_evt->mac_id = mac_id; - - rtw_enqueue_cmd(pcmdpriv, pcmd_obj); -} - -void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int cam_idx) -{ - struct cmd_obj *pcmd_obj; - u8 *pevtcmd; - u32 cmdsz; - struct stassoc_event *padd_sta_evt; - struct C2HEvent_Header *pc2h_evt_hdr; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - - pcmd_obj = kzalloc_obj(*pcmd_obj, GFP_ATOMIC); - if (!pcmd_obj) - return; - - cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header)); - pevtcmd = kzalloc(cmdsz, GFP_ATOMIC); - if (!pevtcmd) { - kfree(pcmd_obj); - return; - } - - INIT_LIST_HEAD(&pcmd_obj->list); - - pcmd_obj->cmdcode = SET_MLME_EVT_CMD; - pcmd_obj->cmdsz = cmdsz; - pcmd_obj->parmbuf = pevtcmd; - - pcmd_obj->rsp = NULL; - pcmd_obj->rspsz = 0; - - pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd); - pc2h_evt_hdr->len = sizeof(struct stassoc_event); - pc2h_evt_hdr->ID = ADD_STA_EVENT; - pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq); - - padd_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header)); - memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN); - padd_sta_evt->cam_id = cam_idx; - - rtw_enqueue_cmd(pcmdpriv, pcmd_obj); -} - -/* Following are the event callback functions */ - -/* for sta/adhoc mode */ -void update_sta_info(struct adapter *padapter, struct sta_info *psta) -{ - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - /* ERP */ - VCS_update(padapter, psta); - - /* HT */ - if (pmlmepriv->htpriv.ht_option) { - psta->htpriv.ht_option = true; - - psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable; - - psta->htpriv.rx_ampdu_min_spacing = - (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & - IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2; - - if (support_short_GI(padapter, &(pmlmeinfo->HT_caps), CHANNEL_WIDTH_20)) - psta->htpriv.sgi_20m = true; - - if (support_short_GI(padapter, &(pmlmeinfo->HT_caps), CHANNEL_WIDTH_40)) - psta->htpriv.sgi_40m = true; - - psta->qos_option = true; - - psta->htpriv.ldpc_cap = pmlmepriv->htpriv.ldpc_cap; - psta->htpriv.stbc_cap = pmlmepriv->htpriv.stbc_cap; - psta->htpriv.beamform_cap = pmlmepriv->htpriv.beamform_cap; - - memcpy(&psta->htpriv.ht_cap, &pmlmeinfo->HT_caps, sizeof(struct ieee80211_ht_cap)); - } else { - psta->htpriv.ht_option = false; - - psta->htpriv.ampdu_enable = false; - - psta->htpriv.sgi_20m = false; - psta->htpriv.sgi_40m = false; - psta->qos_option = false; - } - - psta->htpriv.ch_offset = pmlmeext->cur_ch_offset; - - psta->htpriv.agg_enable_bitmap = 0x0;/* reset */ - psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */ - - psta->bw_mode = pmlmeext->cur_bwmode; - - /* QoS */ - if (pmlmepriv->qospriv.qos_option) - psta->qos_option = true; - - update_ldpc_stbc_cap(psta); - - spin_lock_bh(&psta->lock); - psta->state = _FW_LINKED; - spin_unlock_bh(&psta->lock); -} - -static void rtw_mlmeext_disconnect(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); - - /* set_opmode_cmd(padapter, infra_client_with_mlme); */ - - /* For safety, prevent from keeping macid sleep. - * If we can sure all power mode enter/leave are paired, - * this check can be removed. - * Lucas@20131113 - */ - /* wakeup macid after disconnect. */ - { - struct sta_info *psta; - - psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(pnetwork)); - if (psta) - rtw_hal_macid_wakeup(padapter, psta->mac_id); - } - - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL); - rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr); - - /* set MSR to no link state -> infra. mode */ - set_msr(padapter, _HW_STATE_STATION_); - - pmlmeinfo->state = WIFI_FW_NULL_STATE; - - /* switch to the 20M Hz mode after disconnect */ - pmlmeext->cur_bwmode = CHANNEL_WIDTH_20; - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - - set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); - - flush_all_cam_entry(padapter); - - timer_delete_sync(&pmlmeext->link_timer); - - pmlmepriv->link_detect_info.traffic_transition_count = 0; - pmlmepriv->link_detect_info.low_power_transition_count = 0; -} - -void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); - struct sta_priv *pstapriv = &padapter->stapriv; - u8 join_type; - struct sta_info *psta; - - if (join_res < 0) { - join_type = 1; - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type)); - rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr); - - return; - } - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) - /* update bc/mc sta_info */ - update_bmc_sta(padapter); - - /* turn on dynamic functions */ - switch_dm_func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); - - /* update IOT-related issue */ - update_IOT_info(padapter); - - rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->supported_rates); - - /* BCN interval */ - rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval)); - - /* update capability */ - update_capinfo(padapter, pmlmeinfo->capability); - - /* WMM, Update EDCA param */ - WMMOnAssocRsp(padapter); - - /* HT */ - HTOnAssocRsp(padapter); - - /* Set cur_channel&cur_bwmode&cur_ch_offset */ - set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); - - psta = rtw_get_stainfo(pstapriv, cur_network->mac_address); - if (psta) { /* only for infra. mode */ - - pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta; - - psta->wireless_mode = pmlmeext->cur_wireless_mode; - - /* set per sta rate after updating HT cap. */ - set_sta_rate(padapter, psta); - - rtw_sta_media_status_rpt(padapter, psta, 1); - - /* - * wakeup macid after join bss successfully to ensure - * the subsequent data frames can be sent out normally - */ - rtw_hal_macid_wakeup(padapter, psta->mac_id); - } - - join_type = 2; - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type)); - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) { - /* correcting TSF */ - correct_TSF(padapter, pmlmeext); - - /* set_link_timer(pmlmeext, DISCONNECT_TO); */ - } - - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0); -} - -/* currently only adhoc mode will go here */ -void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *psta) -{ - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 join_type; - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) { - if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) { /* adhoc master or sta_count>1 */ - - /* nothing to do */ - } else { /* adhoc client */ - /* update TSF Value */ - /* update_TSF(pmlmeext, pframe, len); */ - - /* correcting TSF */ - correct_TSF(padapter, pmlmeext); - - /* start beacon */ - if (send_beacon(padapter) == _FAIL) { - pmlmeinfo->FW_sta_info[psta->mac_id].status = 0; - - pmlmeinfo->state ^= WIFI_FW_ADHOC_STATE; - - return; - } - - pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS; - } - - join_type = 2; - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type)); - } - - pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta; - - psta->bssratelen = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[psta->mac_id].SupportedRates); - memcpy(psta->bssrateset, pmlmeinfo->FW_sta_info[psta->mac_id].SupportedRates, psta->bssratelen); - - /* update adhoc sta_info */ - update_sta_info(padapter, psta); - - rtw_hal_update_sta_rate_mask(padapter, psta); - - /* ToDo: HT for Ad-hoc */ - psta->wireless_mode = rtw_check_network_type(psta->bssrateset, pmlmeext->cur_channel); - psta->raid = networktype_to_raid_ex(padapter, psta); - - /* rate radaptive */ - update_ra_entry(padapter, psta); -} - -void mlmeext_sta_del_event_callback(struct adapter *padapter) -{ - if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter)) - rtw_mlmeext_disconnect(padapter); -} - -/* Following are the functions for the timer handlers */ - -void _linked_info_dump(struct adapter *padapter) -{ - int i; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - int UndecoratedSmoothedPWDB; - struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter); - - if (padapter->bLinkInfoDump) { - if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) - rtw_hal_get_def_var(padapter, - HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, - &UndecoratedSmoothedPWDB); - - for (i = 0; i < NUM_STA; i++) { - if (pdvobj->macid[i]) { - if (i != 1) /* skip bc/mc sta */ - /* tx info ============ */ - rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &i); - } - } - } -} - -static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta) -{ - u8 ret = false; - - if ((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta)) - && sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta) - && sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta) - ) { - ret = false; - } else { - ret = true; - } - - sta_update_last_rx_pkts(psta); - - return ret; -} - -void linked_status_chk(struct adapter *padapter) -{ - u32 i; - struct sta_info *psta; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct sta_priv *pstapriv = &padapter->stapriv; - - if (is_client_associated_to_ap(padapter)) { - /* linked infrastructure client mode */ - - int tx_chk = _SUCCESS, rx_chk = _SUCCESS; - int rx_chk_limit; - int link_count_limit; - - #if defined(DBG_ROAMING_TEST) - rx_chk_limit = 1; - #else - rx_chk_limit = 8; - #endif - link_count_limit = 7; /* 16 sec */ - - /* Marked by Kurt 20130715 */ - /* For WiDi 3.5 and latered on, they don't ask WiDi sink to do roaming, */ - /* so we could not check rx limit that strictly. */ - /* todo: To check why we under miracast session, rx_chk would be false */ - psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.mac_address); - if (psta) { - if (!chk_ap_is_alive(padapter, psta)) - rx_chk = _FAIL; - - if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts) - tx_chk = _FAIL; - - { - if (rx_chk != _SUCCESS) { - if (pmlmeext->retry == 0) { - issue_probereq_ex(padapter, - &pmlmeinfo->network.ssid, - pmlmeinfo->network.mac_address, - 0, 0, 0, 0); - issue_probereq_ex(padapter, - &pmlmeinfo->network.ssid, - pmlmeinfo->network.mac_address, - 0, 0, 0, 0); - issue_probereq_ex(padapter, - &pmlmeinfo->network.ssid, - pmlmeinfo->network.mac_address, - 0, 0, 0, 0); - } - } - - if (tx_chk != _SUCCESS && - pmlmeinfo->link_count++ == link_count_limit) - tx_chk = issue_nulldata_in_interrupt(padapter, NULL); - } - - if (rx_chk == _FAIL) { - pmlmeext->retry++; - if (pmlmeext->retry > rx_chk_limit) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " disconnect or roaming\n", - FUNC_ADPT_ARG(padapter)); - receive_disconnect(padapter, pmlmeinfo->network.mac_address - , WLAN_REASON_EXPIRATION_CHK); - return; - } - } else { - pmlmeext->retry = 0; - } - - if (tx_chk == _FAIL) { - pmlmeinfo->link_count %= (link_count_limit + 1); - } else { - pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts; - pmlmeinfo->link_count = 0; - } - - } /* end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.mac_address)) != NULL) */ - } else if (is_client_associated_to_ibss(padapter)) { - /* linked IBSS mode */ - /* for each assoc list entry to check the rx pkt counter */ - for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) { - if (pmlmeinfo->FW_sta_info[i].status == 1) { - psta = pmlmeinfo->FW_sta_info[i].psta; - - if (!psta) - continue; - - if (pmlmeinfo->FW_sta_info[i].rx_pkt == sta_rx_pkts(psta)) { - if (pmlmeinfo->FW_sta_info[i].retry < 3) { - pmlmeinfo->FW_sta_info[i].retry++; - } else { - pmlmeinfo->FW_sta_info[i].retry = 0; - pmlmeinfo->FW_sta_info[i].status = 0; - report_del_sta_event(padapter, psta->hwaddr - , 65535/* indicate disconnect caused by no rx */ - ); - } - } else { - pmlmeinfo->FW_sta_info[i].retry = 0; - pmlmeinfo->FW_sta_info[i].rx_pkt = (u32)sta_rx_pkts(psta); - } - } - } - - /* set_link_timer(pmlmeext, DISCONNECT_TO); */ - } -} - -void survey_timer_hdl(struct timer_list *t) -{ - struct adapter *padapter = - timer_container_of(padapter, t, mlmeextpriv.survey_timer); - struct cmd_obj *ph2c; - struct sitesurvey_parm *psurveyPara; - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - /* issue rtw_sitesurvey_cmd */ - if (pmlmeext->sitesurvey_res.state > SCAN_START) { - if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) - pmlmeext->sitesurvey_res.channel_idx++; - - if (pmlmeext->scan_abort) { - pmlmeext->sitesurvey_res.channel_idx = pmlmeext->sitesurvey_res.ch_num; - - pmlmeext->scan_abort = false;/* reset */ - } - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) - return; - - psurveyPara = kzalloc_obj(*psurveyPara, GFP_ATOMIC); - if (!psurveyPara) { - kfree(ph2c); - return; - } - - init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, SITE_SURVEY_CMD); - rtw_enqueue_cmd(pcmdpriv, ph2c); - } -} - -void link_timer_hdl(struct timer_list *t) -{ - struct adapter *padapter = - timer_container_of(padapter, t, mlmeextpriv.link_timer); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) { - pmlmeinfo->state = WIFI_FW_NULL_STATE; - report_join_res(padapter, -3); - } else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE) { - /* re-auth timer */ - if (++pmlmeinfo->reauth_count > REAUTH_LIMIT) { - pmlmeinfo->state = 0; - report_join_res(padapter, -1); - return; - } - - pmlmeinfo->auth_seq = 1; - issue_auth(padapter, NULL, 0); - set_link_timer(pmlmeext, REAUTH_TO); - } else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE) { - /* re-assoc timer */ - if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT) { - pmlmeinfo->state = WIFI_FW_NULL_STATE; - report_join_res(padapter, -2); - return; - } - - issue_assocreq(padapter); - set_link_timer(pmlmeext, REASSOC_TO); - } -} - -void addba_timer_hdl(struct timer_list *t) -{ - struct sta_info *psta = timer_container_of(psta, t, addba_retry_timer); - struct ht_priv *phtpriv; - - if (!psta) - return; - - phtpriv = &psta->htpriv; - - if (phtpriv->ht_option && phtpriv->ampdu_enable) { - if (phtpriv->candidate_tid_bitmap) - phtpriv->candidate_tid_bitmap = 0x0; - } -} - -void sa_query_timer_hdl(struct timer_list *t) -{ - struct adapter *padapter = - timer_container_of(padapter, t, mlmeextpriv.sa_query_timer); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - /* disconnect */ - spin_lock_bh(&pmlmepriv->lock); - - if (check_fwstate(pmlmepriv, _FW_LINKED)) { - rtw_disassoc_cmd(padapter, 0, true); - rtw_indicate_disconnect(padapter); - rtw_free_assoc_resources(padapter, 1); - } - - spin_unlock_bh(&pmlmepriv->lock); -} - -u8 NULL_hdl(struct adapter *padapter, u8 *pbuf) -{ - return H2C_SUCCESS; -} - -u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf) -{ - u8 type; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf; - - if (psetop->mode == NL80211_IFTYPE_AP) { - pmlmeinfo->state = WIFI_FW_AP_STATE; - type = _HW_STATE_AP_; - /* start_ap_mode(padapter); */ - } else if (psetop->mode == NL80211_IFTYPE_STATION) { - pmlmeinfo->state &= ~(BIT(0) | BIT(1));/* clear state */ - pmlmeinfo->state |= WIFI_FW_STATION_STATE;/* set to STATION_STATE */ - type = _HW_STATE_STATION_; - } else if (psetop->mode == NL80211_IFTYPE_ADHOC) { - type = _HW_STATE_ADHOC_; - } else { - type = _HW_STATE_NOLINK_; - } - - rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type)); - /* set_msr(padapter, type); */ - - if (psetop->mode == NL80211_IFTYPE_AP) { - /* Do this after port switch to */ - /* prevent from downloading rsvd page to wrong port */ - rtw_btcoex_media_status_notify(padapter, 1); /* connect */ - } - - return H2C_SUCCESS; -} - -u8 createbss_hdl(struct adapter *padapter, u8 *pbuf) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); - struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf; - /* u32 initialgain; */ - - if (pmlmeinfo->state == WIFI_FW_AP_STATE) { - start_bss_network(padapter); - return H2C_SUCCESS; - } - - /* below is for ad-hoc master */ - if (pparm->network.infrastructure_mode == NL80211_IFTYPE_ADHOC) { - rtw_joinbss_reset(padapter); - - pmlmeext->cur_bwmode = CHANNEL_WIDTH_20; - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - pmlmeinfo->ERP_enable = 0; - pmlmeinfo->WMM_enable = 0; - pmlmeinfo->HT_enable = 0; - pmlmeinfo->HT_caps_enable = 0; - pmlmeinfo->HT_info_enable = 0; - pmlmeinfo->agg_enable_bitmap = 0; - pmlmeinfo->candidate_tid_bitmap = 0; - - /* disable dynamic functions, such as high power, DIG */ - save_dm_func_flag(padapter); - switch_dm_func(padapter, DYNAMIC_FUNC_DISABLE, false); - - /* config the initial gain under linking, need to write the BB registers */ - /* initialgain = 0x1E; */ - /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */ - - /* cancel link timer */ - timer_delete_sync(&pmlmeext->link_timer); - - /* clear CAM */ - flush_all_cam_entry(padapter); - - memcpy(pnetwork, pbuf, offsetof(struct wlan_bssid_ex, ie_length)); - pnetwork->ie_length = ((struct wlan_bssid_ex *)pbuf)->ie_length; - - if (pnetwork->ie_length > MAX_IE_SZ)/* Check pbuf->ie_length */ - return H2C_PARAMETERS_ERROR; - - memcpy(pnetwork->ies, ((struct wlan_bssid_ex *)pbuf)->ies, pnetwork->ie_length); - - start_create_ibss(padapter); - } - - return H2C_SUCCESS; -} - -u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf) -{ - u8 join_type; - struct ndis_80211_var_ie *pIE; - struct registry_priv *pregpriv = &padapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); - u32 i; - u8 cbw40_enable = 0; - /* u32 initialgain; */ - /* u32 acparm; */ - u8 ch, bw, offset; - - /* check already connecting to AP or not */ - if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) { - if (pmlmeinfo->state & WIFI_FW_STATION_STATE) - issue_deauth_ex(padapter, pnetwork->mac_address, WLAN_REASON_DEAUTH_LEAVING, 1, 100); - pmlmeinfo->state = WIFI_FW_NULL_STATE; - - /* clear CAM */ - flush_all_cam_entry(padapter); - - timer_delete_sync(&pmlmeext->link_timer); - - /* set MSR to nolink -> infra. mode */ - /* set_msr(padapter, _HW_STATE_NOLINK_); */ - set_msr(padapter, _HW_STATE_STATION_); - - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL); - } - - rtw_joinbss_reset(padapter); - - pmlmeext->cur_bwmode = CHANNEL_WIDTH_20; - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - pmlmeinfo->ERP_enable = 0; - pmlmeinfo->WMM_enable = 0; - pmlmeinfo->HT_enable = 0; - pmlmeinfo->HT_caps_enable = 0; - pmlmeinfo->HT_info_enable = 0; - pmlmeinfo->agg_enable_bitmap = 0; - pmlmeinfo->candidate_tid_bitmap = 0; - pmlmeinfo->bwmode_updated = false; - /* pmlmeinfo->assoc_AP_vendor = HT_IOT_PEER_MAX; */ - pmlmeinfo->VHT_enable = 0; - - memcpy(pnetwork, pbuf, offsetof(struct wlan_bssid_ex, ie_length)); - pnetwork->ie_length = ((struct wlan_bssid_ex *)pbuf)->ie_length; - - if (pnetwork->ie_length > MAX_IE_SZ)/* Check pbuf->ie_length */ - return H2C_PARAMETERS_ERROR; - - memcpy(pnetwork->ies, ((struct wlan_bssid_ex *)pbuf)->ies, pnetwork->ie_length); - - pmlmeext->cur_channel = (u8)pnetwork->configuration.ds_config; - pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork); - - /* Check AP vendor to move rtw_joinbss_cmd() */ - /* pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->ies, pnetwork->ie_length); */ - - /* sizeof(struct ndis_802_11_fix_ie) */ - for (i = _FIXED_IE_LENGTH_; i < pnetwork->ie_length;) { - if (i + sizeof(*pIE) > pnetwork->ie_length) - break; - pIE = (struct ndis_80211_var_ie *)(pnetwork->ies + i); - if (i + sizeof(*pIE) + pIE->length > pnetwork->ie_length) - break; - - switch (pIE->element_id) { - case WLAN_EID_VENDOR_SPECIFIC:/* Get WMM IE. */ - if (!memcmp(pIE->data, WMM_OUI, 4)) - WMM_param_handler(padapter, pIE); - break; - - case WLAN_EID_HT_CAPABILITY: /* Get HT Cap IE. */ - pmlmeinfo->HT_caps_enable = 1; - break; - - case WLAN_EID_HT_OPERATION: /* Get HT Info IE. */ - pmlmeinfo->HT_info_enable = 1; - - /* spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz */ - { - struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data); - - if (pnetwork->configuration.ds_config <= 14) { - if ((pregpriv->bw_mode & 0x0f) > CHANNEL_WIDTH_20) - cbw40_enable = 1; - } - - if ((cbw40_enable) && (pht_info->infos[0] & BIT(2))) { - /* switch to the 40M Hz mode according to the AP */ - pmlmeext->cur_bwmode = CHANNEL_WIDTH_40; - switch (pht_info->infos[0] & 0x3) { - case 1: - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER; - break; - - case 3: - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER; - break; - - default: - pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - pmlmeext->cur_bwmode = CHANNEL_WIDTH_20; - break; - } - } - } - break; - default: - break; - } - - i += (pIE->length + 2); - } - - /* check channel, bandwidth, offset and switch */ - if (rtw_chk_start_clnt_join(padapter, &ch, &bw, &offset) == _FAIL) { - report_join_res(padapter, (-4)); - return H2C_SUCCESS; - } - - /* disable dynamic functions, such as high power, DIG */ - /* switch_dm_func(padapter, DYNAMIC_FUNC_DISABLE, false); */ - - /* config the initial gain under linking, need to write the BB registers */ - /* initialgain = 0x1E; */ - /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */ - - rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.mac_address); - join_type = 0; - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type)); - - set_channel_bwmode(padapter, ch, offset, bw); - - /* cancel link timer */ - timer_delete_sync(&pmlmeext->link_timer); - - start_clnt_join(padapter); - - return H2C_SUCCESS; -} - -u8 disconnect_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - struct disconnect_parm *param = (struct disconnect_parm *)pbuf; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); - u8 val8; - - if (is_client_associated_to_ap(padapter)) - issue_deauth_ex(padapter, pnetwork->mac_address, WLAN_REASON_DEAUTH_LEAVING, - param->deauth_timeout_ms / 100, 100); - - if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || - ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE)) { - /* Stop BCN */ - val8 = 0; - rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8)); - } - - rtw_mlmeext_disconnect(padapter); - - rtw_free_uc_swdec_pending_queue(padapter); - - return H2C_SUCCESS; -} - -static int rtw_scan_ch_decision(struct adapter *padapter, struct rtw_ieee80211_channel *out, - u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num) -{ - int i, j; - int set_idx; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - /* clear first */ - memset(out, 0, sizeof(struct rtw_ieee80211_channel) * out_num); - - /* acquire channels from in */ - j = 0; - for (i = 0; i < in_num; i++) { - set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, in[i].hw_value); - if (in[i].hw_value && !(in[i].flags & RTW_IEEE80211_CHAN_DISABLED) - && set_idx >= 0 - ) { - if (j >= out_num) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " out_num:%u not enough\n", - FUNC_ADPT_ARG(padapter), out_num); - break; - } - - memcpy(&out[j], &in[i], sizeof(struct rtw_ieee80211_channel)); - - if (pmlmeext->channel_set[set_idx].scan_type == SCAN_PASSIVE) - out[j].flags |= RTW_IEEE80211_CHAN_PASSIVE_SCAN; - - j++; - } - if (j >= out_num) - break; - } - - /* if out is empty, use channel_set as default */ - if (j == 0) { - for (i = 0; i < pmlmeext->max_chan_nums; i++) { - if (j >= out_num) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " out_num:%u not enough\n", - FUNC_ADPT_ARG(padapter), - out_num); - break; - } - - out[j].hw_value = pmlmeext->channel_set[i].channel_num; - - if (pmlmeext->channel_set[i].scan_type == SCAN_PASSIVE) - out[j].flags |= RTW_IEEE80211_CHAN_PASSIVE_SCAN; - - j++; - } - } - - return j; -} - -u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf; - u8 bdelayscan = false; - u8 val8; - u32 initialgain; - u32 i; - - if (pmlmeext->sitesurvey_res.state == SCAN_DISABLE) { - pmlmeext->sitesurvey_res.state = SCAN_START; - pmlmeext->sitesurvey_res.bss_cnt = 0; - pmlmeext->sitesurvey_res.channel_idx = 0; - - for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) { - if (pparm->ssid[i].ssid_length) { - memcpy(pmlmeext->sitesurvey_res.ssid[i].ssid, - pparm->ssid[i].ssid, - IW_ESSID_MAX_SIZE); - pmlmeext->sitesurvey_res.ssid[i].ssid_length = - pparm->ssid[i].ssid_length; - } else { - pmlmeext->sitesurvey_res.ssid[i].ssid_length = 0; - } - } - - pmlmeext->sitesurvey_res.ch_num = rtw_scan_ch_decision(padapter - , pmlmeext->sitesurvey_res.ch, RTW_CHANNEL_SCAN_AMOUNT - , pparm->ch, pparm->ch_num - ); - - pmlmeext->sitesurvey_res.scan_mode = pparm->scan_mode; - - /* issue null data if associating to the AP */ - if (is_client_associated_to_ap(padapter)) { - pmlmeext->sitesurvey_res.state = SCAN_TXNULL; - - issue_nulldata(padapter, NULL, 1, 3, 500); - - bdelayscan = true; - } - if (bdelayscan) { - /* delay 50ms to protect nulldata(1). */ - set_survey_timer(pmlmeext, 50); - return H2C_SUCCESS; - } - } - - if ((pmlmeext->sitesurvey_res.state == SCAN_START) || - (pmlmeext->sitesurvey_res.state == SCAN_TXNULL)) { - /* disable dynamic functions, such as high power, DIG */ - save_dm_func_flag(padapter); - switch_dm_func(padapter, DYNAMIC_FUNC_DISABLE, false); - - /* config the initial gain under scanning, need to write the BB - * registers - */ - initialgain = 0x1e; - - rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); - - /* set MSR to no link state */ - set_msr(padapter, _HW_STATE_NOLINK_); - - val8 = 1; /* under site survey */ - rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8)); - - pmlmeext->sitesurvey_res.state = SCAN_PROCESS; - } - - site_survey(padapter); - - return H2C_SUCCESS; -} - -u8 setauth_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - struct setauth_parm *pparm = (struct setauth_parm *)pbuf; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (pparm->mode < 4) - pmlmeinfo->auth_algo = pparm->mode; - - return H2C_SUCCESS; -} - -u8 setkey_hdl(struct adapter *padapter, u8 *pbuf) -{ - u16 ctrl = 0; - s16 cam_id = 0; - struct setkey_parm *pparm = (struct setkey_parm *)pbuf; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - unsigned char null_addr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - u8 *addr; - - /* main tx key for wep. */ - if (pparm->set_tx) - pmlmeinfo->key_index = pparm->keyid; - - cam_id = rtw_camid_alloc(padapter, NULL, pparm->keyid); - - if (cam_id < 0) { - } else { - if (cam_id > 3) /* not default key, searched by A2 */ - addr = get_bssid(&padapter->mlmepriv); - else - addr = null_addr; - - ctrl = BIT(15) | BIT(6) | ((pparm->algorithm) << 2) | pparm->keyid; - write_cam(padapter, cam_id, ctrl, addr, pparm->key); - netdev_dbg(padapter->pnetdev, - "set group key camid:%d, addr:%pM, kid:%d, type:%s\n", - cam_id, addr, pparm->keyid, - security_type_str(pparm->algorithm)); - } - - if (cam_id >= 0 && cam_id <= 3) - rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)true); - - /* allow multicast packets to driver */ - SetHwReg8723BS(padapter, HW_VAR_ON_RCR_AM, null_addr); - - return H2C_SUCCESS; -} - -u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf) -{ - u16 ctrl = 0; - s16 cam_id = 0; - u8 ret = H2C_SUCCESS; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf; - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *psta; - - if (pparm->algorithm == _NO_PRIVACY_) - goto write_to_cam; - - psta = rtw_get_stainfo(pstapriv, pparm->addr); - if (!psta) { - netdev_dbg(padapter->pnetdev, "%s sta:%pM not found\n", - __func__, pparm->addr); - ret = H2C_REJECTED; - goto exit; - } - - pmlmeinfo->enc_algo = pparm->algorithm; - cam_id = rtw_camid_alloc(padapter, psta, 0); - if (cam_id < 0) - goto exit; - -write_to_cam: - if (pparm->algorithm == _NO_PRIVACY_) { - while ((cam_id = rtw_camid_search(padapter, pparm->addr, -1)) >= 0) { - netdev_dbg(padapter->pnetdev, - "clear key for addr:%pM, camid:%d\n", - pparm->addr, cam_id); - clear_cam_entry(padapter, cam_id); - rtw_camid_free(padapter, cam_id); - } - } else { - netdev_dbg(padapter->pnetdev, - "set pairwise key camid:%d, addr:%pM, kid:%d, type:%s\n", - cam_id, pparm->addr, pparm->keyid, - security_type_str(pparm->algorithm)); - ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid; - write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key); - } - ret = H2C_SUCCESS_RSP; - -exit: - return ret; -} - -u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr); - - if (!psta) - return H2C_SUCCESS; - - if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) || - ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE)) { - /* pmlmeinfo->ADDBA_retry_count = 0; */ - /* pmlmeinfo->candidate_tid_bitmap |= (0x1 << pparm->tid); */ - /* psta->htpriv.candidate_tid_bitmap |= BIT(pparm->tid); */ - issue_action_BA(padapter, pparm->addr, WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid); - /* _set_timer(&pmlmeext->ADDBA_timer, ADDBA_TO); */ - _set_timer(&psta->addba_retry_timer, ADDBA_TO); - } else { - psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid); - } - return H2C_SUCCESS; -} - -u8 chk_bmc_sleepq_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); - u8 res = _SUCCESS; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - init_h2fwcmd_w_parm_no_parm_rsp(ph2c, CHK_BMC_SLEEPQ_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - return res; -} - -u8 set_tx_beacon_cmd(struct adapter *padapter) -{ - struct cmd_obj *ph2c; - struct Tx_Beacon_param *ptxBeacon_parm; - struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u8 res = _SUCCESS; - int len_diff = 0; - - ph2c = kzalloc_obj(*ph2c, GFP_ATOMIC); - if (!ph2c) { - res = _FAIL; - goto exit; - } - - ptxBeacon_parm = kzalloc_obj(*ptxBeacon_parm, GFP_ATOMIC); - if (!ptxBeacon_parm) { - kfree(ph2c); - res = _FAIL; - goto exit; - } - - memcpy(&(ptxBeacon_parm->network), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex)); - - len_diff = update_hidden_ssid(ptxBeacon_parm->network.ies + _BEACON_IE_OFFSET_, - ptxBeacon_parm->network.ie_length - _BEACON_IE_OFFSET_, - pmlmeinfo->hidden_ssid_mode); - ptxBeacon_parm->network.ie_length += len_diff; - - init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, TX_BEACON_CMD); - - res = rtw_enqueue_cmd(pcmdpriv, ph2c); - -exit: - return res; -} - -static struct fwevent wlanevents[] = { - {0, rtw_dummy_event_callback}, /* 0 */ - {0, NULL}, /* 1 */ - {0, NULL}, /* 2 */ - {0, NULL}, /* 3 */ - {0, NULL}, /* 4 */ - {0, NULL}, /* 5 */ - {0, NULL}, /* 6 */ - {0, NULL}, /* 7 */ - {0, rtw_survey_event_callback}, /* 8 */ - {sizeof(struct surveydone_event), rtw_surveydone_event_callback}, /* 9 */ - {0, rtw_joinbss_event_callback}, /* 10 */ - {sizeof(struct stassoc_event), rtw_stassoc_event_callback}, /* 11 */ - {sizeof(struct stadel_event), rtw_stadel_event_callback}, /* 12 */ - {0, rtw_dummy_event_callback}, /* 13 */ - {0, rtw_dummy_event_callback}, /* 14 */ - {0, NULL}, /* 15 */ - {0, NULL}, /* 16 */ - {0, NULL}, /* 17 */ - {0, NULL}, /* 18 */ - {0, rtw_fwdbg_event_callback}, /* 19 */ - {0, NULL}, /* 20 */ - {0, NULL}, /* 21 */ - {0, NULL}, /* 22 */ - {0, rtw_cpwm_event_callback}, /* 23 */ - {0, NULL}, /* 24 */ - {0, rtw_wmm_event_callback}, /* 25 */ -}; - -u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - u8 evt_code; - u16 evt_sz; - uint *peventbuf; - void (*event_callback)(struct adapter *dev, u8 *pbuf); - struct evt_priv *pevt_priv = &(padapter->evtpriv); - - if (!pbuf) - goto _abort_event_; - - peventbuf = (uint *)pbuf; - evt_sz = (u16)(*peventbuf & 0xffff); - evt_code = (u8)((*peventbuf >> 16) & 0xff); - - /* checking if event code is valid */ - if (evt_code >= MAX_C2HEVT) - goto _abort_event_; - - /* checking if event size match the event parm size */ - if ((wlanevents[evt_code].parmsize != 0) && - (wlanevents[evt_code].parmsize != evt_sz)) - goto _abort_event_; - - atomic_inc(&pevt_priv->event_seq); - - peventbuf += 2; - - if (peventbuf) { - event_callback = wlanevents[evt_code].event_callback; - event_callback(padapter, (u8 *)peventbuf); - - pevt_priv->evt_done_cnt++; - } - -_abort_event_: - return H2C_SUCCESS; -} - -u8 h2c_msg_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - if (!pbuf) - return H2C_PARAMETERS_ERROR; - - return H2C_SUCCESS; -} - -u8 chk_bmc_sleepq_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - struct sta_info *psta_bmc; - struct list_head *xmitframe_plist, *xmitframe_phead, *tmp; - struct xmit_frame *pxmitframe = NULL; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct sta_priv *pstapriv = &padapter->stapriv; - - /* for BC/MC Frames */ - psta_bmc = rtw_get_bcmc_stainfo(padapter); - if (!psta_bmc) - return H2C_SUCCESS; - - if ((pstapriv->tim_bitmap & BIT(0)) && (psta_bmc->sleepq_len > 0)) { - msleep(10);/* 10ms, ATIM(HIQ) Windows */ - - /* spin_lock_bh(&psta_bmc->sleep_q.lock); */ - spin_lock_bh(&pxmitpriv->lock); - - xmitframe_phead = get_list_head(&psta_bmc->sleep_q); - list_for_each_safe(xmitframe_plist, tmp, xmitframe_phead) { - pxmitframe = list_entry(xmitframe_plist, - struct xmit_frame, list); - - list_del_init(&pxmitframe->list); - - psta_bmc->sleepq_len--; - if (psta_bmc->sleepq_len > 0) - pxmitframe->attrib.mdata = 1; - else - pxmitframe->attrib.mdata = 0; - - pxmitframe->attrib.triggered = 1; - - if (xmitframe_hiq_filter(pxmitframe)) - pxmitframe->attrib.qsel = 0x11;/* HIQ */ - - rtw_hal_xmitframe_enqueue(padapter, pxmitframe); - } - - /* spin_unlock_bh(&psta_bmc->sleep_q.lock); */ - spin_unlock_bh(&pxmitpriv->lock); - - /* check hi queue and bmc_sleepq */ - rtw_chk_hi_queue_cmd(padapter); - } - - return H2C_SUCCESS; -} - -u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - if (send_beacon(padapter) == _FAIL) - return H2C_PARAMETERS_ERROR; - - /* tx bc/mc frames after update TIM */ - chk_bmc_sleepq_hdl(padapter, NULL); - - return H2C_SUCCESS; -} - -int rtw_chk_start_clnt_join(struct adapter *padapter, u8 *ch, u8 *bw, u8 *offset) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - unsigned char cur_ch = pmlmeext->cur_channel; - unsigned char cur_bw = pmlmeext->cur_bwmode; - unsigned char cur_ch_offset = pmlmeext->cur_ch_offset; - bool connect_allow = true; - - if (!ch || !bw || !offset) { - WARN_ON(1); - connect_allow = false; - } - - if (connect_allow) { - *ch = cur_ch; - *bw = cur_bw; - *offset = cur_ch_offset; - } - - return connect_allow ? _SUCCESS : _FAIL; -} - -u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf) -{ - struct set_ch_parm *set_ch_parm; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - if (!pbuf) - return H2C_PARAMETERS_ERROR; - - set_ch_parm = (struct set_ch_parm *)pbuf; - - pmlmeext->cur_channel = set_ch_parm->ch; - pmlmeext->cur_ch_offset = set_ch_parm->ch_offset; - pmlmeext->cur_bwmode = set_ch_parm->bw; - - set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw); - - return H2C_SUCCESS; -} - -u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - struct SetChannelPlan_param *setChannelPlan_param; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - if (!pbuf) - return H2C_PARAMETERS_ERROR; - - setChannelPlan_param = (struct SetChannelPlan_param *)pbuf; - - pmlmeext->max_chan_nums = init_channel_set(padapter, - setChannelPlan_param->channel_plan, - pmlmeext->channel_set); - init_channel_list(padapter, - pmlmeext->channel_set, - pmlmeext->max_chan_nums, - &pmlmeext->channel_list); - - if (padapter->rtw_wdev && padapter->rtw_wdev->wiphy) { - struct regulatory_request request; - - request.initiator = NL80211_REGDOM_SET_BY_DRIVER; - rtw_reg_notifier(padapter->rtw_wdev->wiphy, &request); - } - - return H2C_SUCCESS; -} - -u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - return H2C_REJECTED; -} - -/* TDLS_ESTABLISHED : write RCR DATA BIT */ -/* TDLS_CS_OFF : go back to the channel linked with AP, terminating channel switch procedure */ -/* TDLS_INIT_CH_SEN : init channel sensing, receive all data and mgnt frame */ -/* TDLS_DONE_CH_SEN : channel sensing and report candidate channel */ -/* TDLS_OFF_CH : first time set channel to off channel */ -/* TDLS_BASE_CH : go back tp the channel linked with AP when set */ -/* base channel as target channel */ -/* TDLS_P_OFF_CH : periodically go to off channel */ -/* TDLS_P_BASE_CH : periodically go back to base channel */ -/* TDLS_RS_RCR : restore RCR */ -/* TDLS_TEAR_STA : free tdls sta */ -u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf) -{ - return H2C_REJECTED; -} - -u8 run_in_thread_hdl(struct adapter *padapter, u8 *pbuf) -{ - struct RunInThread_param *p; - - if (!pbuf) - return H2C_PARAMETERS_ERROR; - p = (struct RunInThread_param *)pbuf; - - if (p->func) - p->func(p->context); - - return H2C_SUCCESS; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c deleted file mode 100644 index 448611ad8237..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +++ /dev/null @@ -1,1139 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include - -void _ips_enter(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - pwrpriv->bips_processing = true; - - /* syn ips_mode with request */ - pwrpriv->ips_mode = pwrpriv->ips_mode_req; - - pwrpriv->ips_enter_cnts++; - - if (rf_off == pwrpriv->change_rfpwrstate) { - pwrpriv->bpower_saving = true; - - if (pwrpriv->ips_mode == IPS_LEVEL_2) - pwrpriv->bkeepfwalive = true; - - rtw_ips_pwr_down(padapter); - pwrpriv->rf_pwrstate = rf_off; - } - pwrpriv->bips_processing = false; -} - -void ips_enter(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - hal_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req); - - mutex_lock(&pwrpriv->lock); - _ips_enter(padapter); - mutex_unlock(&pwrpriv->lock); -} - -int _ips_leave(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - int result = _SUCCESS; - - if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) { - pwrpriv->bips_processing = true; - pwrpriv->change_rfpwrstate = rf_on; - pwrpriv->ips_leave_cnts++; - - result = rtw_ips_pwr_up(padapter); - if (result == _SUCCESS) - pwrpriv->rf_pwrstate = rf_on; - pwrpriv->bips_processing = false; - - pwrpriv->bkeepfwalive = false; - pwrpriv->bpower_saving = false; - } - - return result; -} - -int ips_leave(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - int ret; - - mutex_lock(&pwrpriv->lock); - ret = _ips_leave(padapter); - mutex_unlock(&pwrpriv->lock); - - if (ret == _SUCCESS) - hal_btcoex_IpsNotify(padapter, IPS_NONE); - - return ret; -} - -static bool rtw_pwr_unassociated_idle(struct adapter *adapter) -{ - struct adapter *buddy = adapter->pbuddy_adapter; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct xmit_priv *pxmit_priv = &adapter->xmitpriv; - - bool ret = false; - - if (adapter_to_pwrctl(adapter)->bpower_saving) - goto exit; - - if (time_before(jiffies, adapter_to_pwrctl(adapter)->ips_deny_time)) - goto exit; - - if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE | WIFI_SITE_MONITOR) || - check_fwstate(pmlmepriv, WIFI_UNDER_LINKING | WIFI_UNDER_WPS) || - check_fwstate(pmlmepriv, WIFI_AP_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE) - ) - goto exit; - - /* consider buddy, if exist */ - if (buddy) { - struct mlme_priv *b_pmlmepriv = &buddy->mlmepriv; - - if (check_fwstate(b_pmlmepriv, WIFI_ASOC_STATE | WIFI_SITE_MONITOR) || - check_fwstate(b_pmlmepriv, WIFI_UNDER_LINKING | WIFI_UNDER_WPS) || - check_fwstate(b_pmlmepriv, WIFI_AP_STATE) || - check_fwstate(b_pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE) - ) - goto exit; - } - - if (pxmit_priv->free_xmitbuf_cnt != NR_XMITBUFF || - pxmit_priv->free_xmit_extbuf_cnt != NR_XMIT_EXTBUFF) { - netdev_dbg(adapter->pnetdev, - "There are some pkts to transmit\n"); - netdev_dbg(adapter->pnetdev, - "free_xmitbuf_cnt: %d, free_xmit_extbuf_cnt: %d\n", - pxmit_priv->free_xmitbuf_cnt, - pxmit_priv->free_xmit_extbuf_cnt); - goto exit; - } - - ret = true; - -exit: - return ret; -} - -/* - * ATTENTION: - *rtw_ps_processor() doesn't handle LPS. - */ -void rtw_ps_processor(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - u32 ps_deny = 0; - - mutex_lock(&adapter_to_pwrctl(padapter)->lock); - ps_deny = rtw_ps_deny_get(padapter); - mutex_unlock(&adapter_to_pwrctl(padapter)->lock); - if (ps_deny != 0) - goto exit; - - if (pwrpriv->bInSuspend) /* system suspend or autosuspend */ - return; - - pwrpriv->ps_processing = true; - - if (pwrpriv->ips_mode_req == IPS_NONE) - goto exit; - - if (!rtw_pwr_unassociated_idle(padapter)) - goto exit; - - if ((pwrpriv->rf_pwrstate == rf_on) && ((pwrpriv->pwr_state_check_cnts % 4) == 0)) { - pwrpriv->change_rfpwrstate = rf_off; - { - ips_enter(padapter); - } - } -exit: - pwrpriv->ps_processing = false; -} - -static void pwr_state_check_handler(struct timer_list *t) -{ - struct pwrctrl_priv *pwrctrlpriv = - timer_container_of(pwrctrlpriv, t, pwr_state_check_timer); - struct adapter *padapter = pwrctrlpriv->adapter; - - rtw_ps_cmd(padapter); -} - -void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets) -{ - static unsigned long start_time; - static u32 xmit_cnt; - u8 bLeaveLPS = false; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (tx) { /* from tx */ - xmit_cnt += tx_packets; - - if (start_time == 0) - start_time = jiffies; - - if (jiffies_to_msecs(jiffies - start_time) > 2000) { /* 2 sec == watch dog timer */ - if (xmit_cnt > 8) { - if (adapter_to_pwrctl(padapter)->bLeisurePs && - (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE) && - !(hal_btcoex_IsBtControlLps(padapter))) { - bLeaveLPS = true; - } - } - - start_time = jiffies; - xmit_cnt = 0; - } - - } else { /* from rx path */ - if (pmlmepriv->link_detect_info.num_rx_unicast_ok_in_period > 4) { - if (adapter_to_pwrctl(padapter)->bLeisurePs && - (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE) && - !(hal_btcoex_IsBtControlLps(padapter))) - bLeaveLPS = true; - } - } - - if (bLeaveLPS) - /* rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1); */ - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, tx ? 0 : 1); -} - -/* - * Description: - *This function MUST be called under power lock protect - * - * Parameters - *padapter - *pslv power state level, only could be PS_STATE_S0 ~ PS_STATE_S4 - * - */ -void rtw_set_rpwm(struct adapter *padapter, u8 pslv) -{ - u8 rpwm; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - u8 cpwm_orig; - - pslv = PS_STATE(pslv); - - if (!pwrpriv->brpwmtimeout) { - if (pwrpriv->rpwm == pslv || - (pwrpriv->rpwm >= PS_STATE_S2 && pslv >= PS_STATE_S2)) - return; - } - - if ((padapter->bSurpriseRemoved) || !(padapter->hw_init_completed)) { - pwrpriv->cpwm = PS_STATE_S4; - return; - } - - if (padapter->driver_stopped) { - if (pslv < PS_STATE_S2) - return; - } - - rpwm = pslv | pwrpriv->tog; - /* only when from PS_STATE S0/S1 to S2 and higher needs ACK */ - if ((pwrpriv->cpwm < PS_STATE_S2) && (pslv >= PS_STATE_S2)) - rpwm |= PS_ACK; - - pwrpriv->rpwm = pslv; - - cpwm_orig = 0; - if (rpwm & PS_ACK) - rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig); - - if (rpwm & PS_ACK) - _set_timer(&pwrpriv->pwr_rpwm_timer, LPS_RPWM_WAIT_MS); - rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm)); - - pwrpriv->tog += 0x80; - - /* No LPS 32K, No Ack */ - if (rpwm & PS_ACK) { - unsigned long start_time; - u8 cpwm_now; - - start_time = jiffies; - - /* polling cpwm */ - do { - mdelay(1); - rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_now); - if ((cpwm_orig ^ cpwm_now) & 0x80) { - pwrpriv->cpwm = PS_STATE_S4; - pwrpriv->cpwm_tog = cpwm_now & PS_TOGGLE; - break; - } - - if (jiffies_to_msecs(jiffies - start_time) > LPS_RPWM_WAIT_MS) { - _set_timer(&pwrpriv->pwr_rpwm_timer, 1); - break; - } - } while (1); - } else { - pwrpriv->cpwm = pslv; - } -} - -static u8 PS_RDY_CHECK(struct adapter *padapter) -{ - unsigned long curr_time, delta_time; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (pwrpriv->bInSuspend) - return false; - - curr_time = jiffies; - - delta_time = curr_time - pwrpriv->delay_lps_last_time_stamp; - - if (delta_time < LPS_DELAY_TIME) - return false; - - if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR) || - check_fwstate(pmlmepriv, WIFI_UNDER_LINKING | WIFI_UNDER_WPS) || - check_fwstate(pmlmepriv, WIFI_AP_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE) || - rtw_is_scan_deny(padapter) - ) - return false; - - if (padapter->securitypriv.dot11_auth_algrthm == dot11_auth_algrthm_8021x && - !padapter->securitypriv.binstallGrpkey) - return false; - - if (!rtw_cfg80211_pwr_mgmt(padapter)) - return false; - - return true; -} - -void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, - u8 smart_ps, u8 bcn_ant_mode, const char *msg) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - if (ps_mode > PM_Card_Disable) - return; - - if (pwrpriv->pwr_mode == ps_mode) - if (ps_mode == PS_MODE_ACTIVE) - return; - - mutex_lock(&pwrpriv->lock); - - /* if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) */ - if (ps_mode == PS_MODE_ACTIVE) { - if (!(hal_btcoex_IsBtControlLps(padapter)) || - (hal_btcoex_IsBtControlLps(padapter) && - !(hal_btcoex_IsLpsOn(padapter)))) { - pwrpriv->pwr_mode = ps_mode; - rtw_set_rpwm(padapter, PS_STATE_S4); - - rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode)); - pwrpriv->fw_current_in_ps_mode = false; - - hal_btcoex_LpsNotify(padapter, ps_mode); - } - } else { - if ((PS_RDY_CHECK(padapter) && - check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) || - ((hal_btcoex_IsBtControlLps(padapter)) && (hal_btcoex_IsLpsOn(padapter))) - ) { - u8 pslv; - - hal_btcoex_LpsNotify(padapter, ps_mode); - - pwrpriv->fw_current_in_ps_mode = true; - pwrpriv->pwr_mode = ps_mode; - pwrpriv->smart_ps = smart_ps; - pwrpriv->bcn_ant_mode = bcn_ant_mode; - rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode)); - - pslv = PS_STATE_S2; - if (pwrpriv->alives == 0) - pslv = PS_STATE_S0; - - if (!(hal_btcoex_IsBtDisabled(padapter)) && - (hal_btcoex_IsBtControlLps(padapter))) { - u8 val8; - - val8 = hal_btcoex_LpsVal(padapter); - if (val8 & BIT(4)) - pslv = PS_STATE_S2; - } - - rtw_set_rpwm(padapter, pslv); - } - } - - mutex_unlock(&pwrpriv->lock); -} - -/* - * Return: - * 0: Leave OK - * -ETIMEDOUT: Timeout - * -ENODEV: Other error - */ -int LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms) -{ - unsigned long start_time; - u8 bAwake = false; - - start_time = jiffies; - while (1) { - rtw_hal_get_hwreg(padapter, HW_VAR_FWLPS_RF_ON, &bAwake); - if (bAwake) - return 0; - - if (padapter->bSurpriseRemoved) - return -ENODEV; - - if (jiffies_to_msecs(jiffies - start_time) > delay_ms) - return -ETIMEDOUT; - - msleep(1); - } -} - -/* Description: Enter the leisure power save mode. */ -void LPS_Enter(struct adapter *padapter, const char *msg) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj); - int n_assoc_iface = 0; - char buf[32] = {0}; - - if (hal_btcoex_IsBtControlLps(padapter)) - return; - - /* Skip lps enter request if number of associated adapters is not 1 */ - if (check_fwstate(&dvobj->padapters->mlmepriv, WIFI_ASOC_STATE)) - n_assoc_iface++; - if (n_assoc_iface != 1) - return; - - if (!PS_RDY_CHECK(dvobj->padapters)) - return; - - if (pwrpriv->bLeisurePs) { - /* Idle for a while if we connect to AP a while ago. */ - if (pwrpriv->LpsIdleCount >= 2) { /* 4 Sec */ - if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) { - scnprintf(buf, sizeof(buf), "WIFI-%s", msg); - pwrpriv->bpower_saving = true; - rtw_set_ps_mode(padapter, pwrpriv->power_mgnt, - padapter->registrypriv.smart_ps, 0, buf); - } - } else { - pwrpriv->LpsIdleCount++; - } - } -} - -/* Description: Leave the leisure power save mode. */ -void LPS_Leave(struct adapter *padapter, const char *msg) -{ -#define LPS_LEAVE_TIMEOUT_MS 100 - - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj); - char buf[32] = {0}; - - if (hal_btcoex_IsBtControlLps(padapter)) - return; - - if (pwrpriv->bLeisurePs) { - if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) { - scnprintf(buf, sizeof(buf), "WIFI-%s", msg); - rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, buf); - - if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) - LPS_RF_ON_check(padapter, LPS_LEAVE_TIMEOUT_MS); - } - } - - pwrpriv->bpower_saving = false; -} - -void LeaveAllPowerSaveModeDirect(struct adapter *Adapter) -{ - struct adapter *pri_padapter = GET_PRIMARY_ADAPTER(Adapter); - struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter); - - if (Adapter->bSurpriseRemoved) - return; - - if (check_fwstate(pmlmepriv, _FW_LINKED)) { /* connect */ - - if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) - return; - - mutex_lock(&pwrpriv->lock); - - rtw_set_rpwm(Adapter, PS_STATE_S4); - - mutex_unlock(&pwrpriv->lock); - - rtw_lps_ctrl_wk_cmd(pri_padapter, LPS_CTRL_LEAVE, 0); - } else { - if (pwrpriv->rf_pwrstate == rf_off) - ips_leave(pri_padapter); - } -} - -/* */ -/* Description: Leave all power save mode: LPS, FwLPS, IPS if needed. */ -/* Move code to function by tynli. 2010.03.26. */ -/* */ -void LeaveAllPowerSaveMode(struct adapter *Adapter) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(Adapter); - u8 enqueue = 0; - int n_assoc_iface = 0; - - if (!Adapter->bup) - return; - - if (Adapter->bSurpriseRemoved) - return; - - if (check_fwstate(&dvobj->padapters->mlmepriv, WIFI_ASOC_STATE)) - n_assoc_iface++; - - if (n_assoc_iface) { /* connect */ - enqueue = 1; - - rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, enqueue); - - LPS_Leave_check(Adapter); - } else { - if (adapter_to_pwrctl(Adapter)->rf_pwrstate == rf_off) - ips_leave(Adapter); - } -} - -void LPS_Leave_check(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv; - unsigned long start_time; - u8 bReady; - - pwrpriv = adapter_to_pwrctl(padapter); - - bReady = false; - start_time = jiffies; - - cond_resched(); - - while (1) { - mutex_lock(&pwrpriv->lock); - - if (padapter->bSurpriseRemoved || - !(padapter->hw_init_completed) || - (pwrpriv->pwr_mode == PS_MODE_ACTIVE)) - bReady = true; - - mutex_unlock(&pwrpriv->lock); - - if (bReady) - break; - - if (jiffies_to_msecs(jiffies - start_time) > 100) - break; - - msleep(1); - } -} - -/* - * Caller:ISR handler... - * - * This will be called when CPWM interrupt is up. - * - * using to update cpwn of drv; and drv will make a decision to up or down pwr level - */ -void cpwm_int_hdl(struct adapter *padapter, struct reportpwrstate_parm *preportpwrstate) -{ - struct pwrctrl_priv *pwrpriv; - - pwrpriv = adapter_to_pwrctl(padapter); - - mutex_lock(&pwrpriv->lock); - - if (pwrpriv->rpwm < PS_STATE_S2) - goto exit; - - pwrpriv->cpwm = PS_STATE(preportpwrstate->state); - pwrpriv->cpwm_tog = preportpwrstate->state & PS_TOGGLE; - - if (pwrpriv->cpwm >= PS_STATE_S2) { - if (pwrpriv->alives & CMD_ALIVE) - complete(&padapter->cmdpriv.cmd_queue_comp); - - if (pwrpriv->alives & XMIT_ALIVE) - complete(&padapter->xmitpriv.xmit_comp); - } - -exit: - mutex_unlock(&pwrpriv->lock); -} - -static void cpwm_event_callback(struct work_struct *work) -{ - struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, cpwm_event); - struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv); - struct adapter *adapter = dvobj->if1; - struct reportpwrstate_parm report; - - report.state = PS_STATE_S2; - cpwm_int_hdl(adapter, &report); -} - -static void rpwmtimeout_workitem_callback(struct work_struct *work) -{ - struct adapter *padapter; - struct dvobj_priv *dvobj; - struct pwrctrl_priv *pwrpriv; - - pwrpriv = container_of(work, struct pwrctrl_priv, rpwmtimeoutwi); - dvobj = pwrctl_to_dvobj(pwrpriv); - padapter = dvobj->if1; - - mutex_lock(&pwrpriv->lock); - if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2)) - goto exit; - - mutex_unlock(&pwrpriv->lock); - - if (rtw_read8(padapter, 0x100) != 0xEA) { - struct reportpwrstate_parm report; - - report.state = PS_STATE_S2; - cpwm_int_hdl(padapter, &report); - - return; - } - - mutex_lock(&pwrpriv->lock); - - if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2)) - goto exit; - - pwrpriv->brpwmtimeout = true; - rtw_set_rpwm(padapter, pwrpriv->rpwm); - pwrpriv->brpwmtimeout = false; - -exit: - mutex_unlock(&pwrpriv->lock); -} - -/* - * This function is a timer handler, can't do any IO in it. - */ -static void pwr_rpwm_timeout_handler(struct timer_list *t) -{ - struct pwrctrl_priv *pwrpriv = timer_container_of(pwrpriv, t, - pwr_rpwm_timer); - - if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2)) - return; - - _set_workitem(&pwrpriv->rpwmtimeoutwi); -} - -static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag) -{ - pwrctrl->alives |= tag; -} - -static inline void unregister_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag) -{ - pwrctrl->alives &= ~tag; -} - -/* - * Description: - *Check if the fw_pwrstate is okay for I/O. - *If not (cpwm is less than S2), then the sub-routine - *will raise the cpwm to be greater than or equal to S2. - * - *Calling Context: Passive - * - *Constraint: - * 1. this function will request pwrctrl->lock - * - * Return Value: - *_SUCCESS hardware is ready for I/O - *_FAIL can't I/O right now - */ -s32 rtw_register_task_alive(struct adapter *padapter, u32 task) -{ - s32 res; - struct pwrctrl_priv *pwrctrl; - u8 pslv; - - res = _SUCCESS; - pwrctrl = adapter_to_pwrctl(padapter); - pslv = PS_STATE_S2; - - mutex_lock(&pwrctrl->lock); - - register_task_alive(pwrctrl, task); - - if (pwrctrl->fw_current_in_ps_mode) { - if (pwrctrl->cpwm < pslv) { - if (pwrctrl->cpwm < PS_STATE_S2) - res = _FAIL; - if (pwrctrl->rpwm < pslv) - rtw_set_rpwm(padapter, pslv); - } - } - - mutex_unlock(&pwrctrl->lock); - - if (res == _FAIL) - if (pwrctrl->cpwm >= PS_STATE_S2) - res = _SUCCESS; - - return res; -} - -/* - * Description: - *If task is done, call this func. to power down firmware again. - * - *Constraint: - * 1. this function will request pwrctrl->lock - * - * Return Value: - *none - */ -void rtw_unregister_task_alive(struct adapter *padapter, u32 task) -{ - struct pwrctrl_priv *pwrctrl; - u8 pslv; - - pwrctrl = adapter_to_pwrctl(padapter); - pslv = PS_STATE_S0; - - if (!(hal_btcoex_IsBtDisabled(padapter)) && hal_btcoex_IsBtControlLps(padapter)) { - u8 val8; - - val8 = hal_btcoex_LpsVal(padapter); - if (val8 & BIT(4)) - pslv = PS_STATE_S2; - } - - mutex_lock(&pwrctrl->lock); - - unregister_task_alive(pwrctrl, task); - - if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) && pwrctrl->fw_current_in_ps_mode) { - if (pwrctrl->cpwm > pslv) { - if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0)) - rtw_set_rpwm(padapter, pslv); - } - } - - mutex_unlock(&pwrctrl->lock); -} - -/* - * Caller: rtw_xmit_thread - * - * Check if the fw_pwrstate is okay for xmit. - * If not (cpwm is less than S3), then the sub-routine - * will raise the cpwm to be greater than or equal to S3. - * - * Calling Context: Passive - * - * Return Value: - * _SUCCESS rtw_xmit_thread can write fifo/txcmd afterwards. - * _FAIL rtw_xmit_thread can not do anything. - */ -s32 rtw_register_tx_alive(struct adapter *padapter) -{ - s32 res; - struct pwrctrl_priv *pwrctrl; - u8 pslv; - - res = _SUCCESS; - pwrctrl = adapter_to_pwrctl(padapter); - pslv = PS_STATE_S2; - - mutex_lock(&pwrctrl->lock); - - register_task_alive(pwrctrl, XMIT_ALIVE); - - if (pwrctrl->fw_current_in_ps_mode) { - if (pwrctrl->cpwm < pslv) { - if (pwrctrl->cpwm < PS_STATE_S2) - res = _FAIL; - if (pwrctrl->rpwm < pslv) - rtw_set_rpwm(padapter, pslv); - } - } - - mutex_unlock(&pwrctrl->lock); - - if (res == _FAIL) - if (pwrctrl->cpwm >= PS_STATE_S2) - res = _SUCCESS; - - return res; -} - -/* - * Caller: rtw_cmd_thread - * - * Check if the fw_pwrstate is okay for issuing cmd. - * If not (cpwm should be is less than S2), then the sub-routine - * will raise the cpwm to be greater than or equal to S2. - * - * Calling Context: Passive - * - * Return Value: - *_SUCCESS rtw_cmd_thread can issue cmds to firmware afterwards. - *_FAIL rtw_cmd_thread can not do anything. - */ -s32 rtw_register_cmd_alive(struct adapter *padapter) -{ - s32 res; - struct pwrctrl_priv *pwrctrl; - u8 pslv; - - res = _SUCCESS; - pwrctrl = adapter_to_pwrctl(padapter); - pslv = PS_STATE_S2; - - mutex_lock(&pwrctrl->lock); - - register_task_alive(pwrctrl, CMD_ALIVE); - - if (pwrctrl->fw_current_in_ps_mode) { - if (pwrctrl->cpwm < pslv) { - if (pwrctrl->cpwm < PS_STATE_S2) - res = _FAIL; - if (pwrctrl->rpwm < pslv) - rtw_set_rpwm(padapter, pslv); - } - } - - mutex_unlock(&pwrctrl->lock); - - if (res == _FAIL) - if (pwrctrl->cpwm >= PS_STATE_S2) - res = _SUCCESS; - - return res; -} - -/* - * Caller: ISR - * - * If ISR's txdone, - * No more pkts for TX, - * Then driver shall call this fun. to power down firmware again. - */ -void rtw_unregister_tx_alive(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrctrl; - u8 pslv; - - pwrctrl = adapter_to_pwrctl(padapter); - pslv = PS_STATE_S0; - - if (!(hal_btcoex_IsBtDisabled(padapter)) && hal_btcoex_IsBtControlLps(padapter)) { - u8 val8; - - val8 = hal_btcoex_LpsVal(padapter); - if (val8 & BIT(4)) - pslv = PS_STATE_S2; - } - - mutex_lock(&pwrctrl->lock); - - unregister_task_alive(pwrctrl, XMIT_ALIVE); - - if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) && pwrctrl->fw_current_in_ps_mode) { - if (pwrctrl->cpwm > pslv) - if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0)) - rtw_set_rpwm(padapter, pslv); - } - - mutex_unlock(&pwrctrl->lock); -} - -/* - * Caller: ISR - * - * If all commands have been done, - * and no more command to do, - * then driver shall call this fun. to power down firmware again. - */ -void rtw_unregister_cmd_alive(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrctrl; - u8 pslv; - - pwrctrl = adapter_to_pwrctl(padapter); - pslv = PS_STATE_S0; - - if (!(hal_btcoex_IsBtDisabled(padapter)) && hal_btcoex_IsBtControlLps(padapter)) { - u8 val8; - - val8 = hal_btcoex_LpsVal(padapter); - if (val8 & BIT(4)) - pslv = PS_STATE_S2; - } - - mutex_lock(&pwrctrl->lock); - - unregister_task_alive(pwrctrl, CMD_ALIVE); - - if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) && pwrctrl->fw_current_in_ps_mode) { - if (pwrctrl->cpwm > pslv) { - if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0)) - rtw_set_rpwm(padapter, pslv); - } - } - - mutex_unlock(&pwrctrl->lock); -} - -void rtw_init_pwrctrl_priv(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); - - mutex_init(&pwrctrlpriv->lock); - pwrctrlpriv->rf_pwrstate = rf_on; - pwrctrlpriv->ips_enter_cnts = 0; - pwrctrlpriv->ips_leave_cnts = 0; - pwrctrlpriv->bips_processing = false; - - pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode; - pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode; - - pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL; - pwrctrlpriv->pwr_state_check_cnts = 0; - pwrctrlpriv->bInternalAutoSuspend = false; - pwrctrlpriv->bInSuspend = false; - pwrctrlpriv->bkeepfwalive = false; - - pwrctrlpriv->LpsIdleCount = 0; - pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;/* PS_MODE_MIN; */ - pwrctrlpriv->bLeisurePs = pwrctrlpriv->power_mgnt != PS_MODE_ACTIVE; - - pwrctrlpriv->fw_current_in_ps_mode = false; - - pwrctrlpriv->rpwm = 0; - pwrctrlpriv->cpwm = PS_STATE_S4; - - pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE; - pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps; - pwrctrlpriv->bcn_ant_mode = 0; - pwrctrlpriv->dtim = 0; - - pwrctrlpriv->tog = 0x80; - - rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&pwrctrlpriv->rpwm)); - - _init_workitem(&pwrctrlpriv->cpwm_event, cpwm_event_callback, NULL); - - pwrctrlpriv->brpwmtimeout = false; - pwrctrlpriv->adapter = padapter; - _init_workitem(&pwrctrlpriv->rpwmtimeoutwi, rpwmtimeout_workitem_callback, NULL); - timer_setup(&pwrctrlpriv->pwr_rpwm_timer, pwr_rpwm_timeout_handler, 0); - timer_setup(&pwrctrlpriv->pwr_state_check_timer, - pwr_state_check_handler, 0); - - pwrctrlpriv->wowlan_mode = false; - pwrctrlpriv->wowlan_ap_mode = false; -} - -void rtw_free_pwrctrl_priv(struct adapter *adapter) -{ -} - -inline void rtw_set_ips_deny(struct adapter *padapter, u32 ms) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ms); -} - -/* - * rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend - * @adapter: pointer to struct adapter structure - * @ips_deffer_ms: the ms will prevent from falling into IPS after wakeup - * Return _SUCCESS or _FAIL - */ - -int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *caller) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj); - struct mlme_priv *pmlmepriv; - int ret = _SUCCESS; - unsigned long start = jiffies; - unsigned long deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms); - - /* for LPS */ - LeaveAllPowerSaveMode(padapter); - - /* IPS still bound with primary adapter */ - padapter = GET_PRIMARY_ADAPTER(padapter); - pmlmepriv = &padapter->mlmepriv; - - if (time_before(pwrpriv->ips_deny_time, deny_time)) - pwrpriv->ips_deny_time = deny_time; - - if (pwrpriv->ps_processing) - while (pwrpriv->ps_processing && jiffies_to_msecs(jiffies - start) <= 3000) - mdelay(10); - - if (!(pwrpriv->bInternalAutoSuspend) && pwrpriv->bInSuspend) - while (pwrpriv->bInSuspend && jiffies_to_msecs(jiffies - start) <= 3000 - ) - mdelay(10); - - /* System suspend is not allowed to wakeup */ - if (!(pwrpriv->bInternalAutoSuspend) && pwrpriv->bInSuspend) { - ret = _FAIL; - goto exit; - } - - /* block??? */ - if (pwrpriv->bInternalAutoSuspend && padapter->net_closed) { - ret = _FAIL; - goto exit; - } - - /* I think this should be check in IPS, LPS, autosuspend functions... */ - if (check_fwstate(pmlmepriv, _FW_LINKED)) { - ret = _SUCCESS; - goto exit; - } - - if (rf_off == pwrpriv->rf_pwrstate) { - { - if (ips_leave(padapter) == _FAIL) { - ret = _FAIL; - goto exit; - } - } - } - - /* TODO: the following checking need to be merged... */ - if (padapter->driver_stopped || !padapter->bup || !padapter->hw_init_completed) { - ret = false; - goto exit; - } - -exit: - deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms); - if (time_before(pwrpriv->ips_deny_time, deny_time)) - pwrpriv->ips_deny_time = deny_time; - return ret; -} - -int rtw_pm_set_lps(struct adapter *padapter, u8 mode) -{ - int ret = 0; - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); - - if (mode < PS_MODE_NUM) { - if (pwrctrlpriv->power_mgnt != mode) { - if (mode == PS_MODE_ACTIVE) - LeaveAllPowerSaveMode(padapter); - else - pwrctrlpriv->LpsIdleCount = 2; - - pwrctrlpriv->power_mgnt = mode; - pwrctrlpriv->bLeisurePs = - pwrctrlpriv->power_mgnt != PS_MODE_ACTIVE; - } - } else { - ret = -EINVAL; - } - - return ret; -} - -int rtw_pm_set_ips(struct adapter *padapter, u8 mode) -{ - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); - - if (mode == IPS_NORMAL || mode == IPS_LEVEL_2) { - rtw_ips_mode_req(pwrctrlpriv, mode); - return 0; - } else if (mode == IPS_NONE) { - rtw_ips_mode_req(pwrctrlpriv, mode); - if ((padapter->bSurpriseRemoved == 0) && (rtw_pwr_wakeup(padapter) == _FAIL)) - return -EFAULT; - } else { - return -EINVAL; - } - - return 0; -} - -/* - * ATTENTION: - *This function will request pwrctrl LOCK! - */ -void rtw_ps_deny(struct adapter *padapter, enum ps_deny_reason reason) -{ - struct pwrctrl_priv *pwrpriv; - - pwrpriv = adapter_to_pwrctl(padapter); - - mutex_lock(&pwrpriv->lock); - pwrpriv->ps_deny |= BIT(reason); - mutex_unlock(&pwrpriv->lock); -} - -/* - * ATTENTION: - *This function will request pwrctrl LOCK! - */ -void rtw_ps_deny_cancel(struct adapter *padapter, enum ps_deny_reason reason) -{ - struct pwrctrl_priv *pwrpriv; - - pwrpriv = adapter_to_pwrctl(padapter); - - mutex_lock(&pwrpriv->lock); - pwrpriv->ps_deny &= ~BIT(reason); - mutex_unlock(&pwrpriv->lock); -} - -/* - * ATTENTION: - *Before calling this function pwrctrl lock should be occupied already, - *otherwise it may return incorrect value. - */ -u32 rtw_ps_deny_get(struct adapter *padapter) -{ - return adapter_to_pwrctl(padapter)->ps_deny; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c b/drivers/staging/rtl8723bs/core/rtw_recv.c deleted file mode 100644 index 7568fc514d7c..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_recv.c +++ /dev/null @@ -1,2249 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include -#include -#include - -static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37}; -static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3}; - -static void rtw_signal_stat_timer_hdl(struct timer_list *t); - -void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv) -{ - memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv)); - - spin_lock_init(&psta_recvpriv->lock); - - INIT_LIST_HEAD(&psta_recvpriv->defrag_q.queue); - spin_lock_init(&psta_recvpriv->defrag_q.lock); -} - -signed int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter) -{ - signed int i; - union recv_frame *precvframe; - signed int res = _SUCCESS; - - spin_lock_init(&precvpriv->lock); - - INIT_LIST_HEAD(&precvpriv->free_recv_queue.queue); - spin_lock_init(&precvpriv->free_recv_queue.lock); - INIT_LIST_HEAD(&precvpriv->recv_pending_queue.queue); - spin_lock_init(&precvpriv->recv_pending_queue.lock); - INIT_LIST_HEAD(&precvpriv->uc_swdec_pending_queue.queue); - spin_lock_init(&precvpriv->uc_swdec_pending_queue.lock); - - precvpriv->adapter = padapter; - - precvpriv->free_recvframe_cnt = NR_RECVFRAME; - - precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(union recv_frame) - + RXFRAME_ALIGN_SZ); - - if (!precvpriv->pallocated_frame_buf) { - res = _FAIL; - goto exit; - } - - precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ); - /* precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + RXFRAME_ALIGN_SZ - */ - /* ((SIZE_PTR) (precvpriv->pallocated_frame_buf) &(RXFRAME_ALIGN_SZ-1)); */ - - precvframe = (union recv_frame *)precvpriv->precv_frame_buf; - - for (i = 0; i < NR_RECVFRAME; i++) { - INIT_LIST_HEAD(&(precvframe->u.list)); - - list_add_tail(&(precvframe->u.list), &(precvpriv->free_recv_queue.queue)); - - precvframe->u.hdr.pkt_newalloc = NULL; - precvframe->u.hdr.pkt = NULL; - - precvframe->u.hdr.len = 0; - - precvframe->u.hdr.adapter = padapter; - precvframe++; - } - - res = rtw_hal_init_recv_priv(padapter); - - timer_setup(&precvpriv->signal_stat_timer, rtw_signal_stat_timer_hdl, - 0); - - precvpriv->signal_stat_sampling_interval = 2000; /* ms */ - - rtw_set_signal_stat_timer(precvpriv); - -exit: - return res; -} - -void _rtw_free_recv_priv(struct recv_priv *precvpriv) -{ - signed int i; - union recv_frame *precvframe; - struct adapter *padapter = precvpriv->adapter; - - rtw_free_uc_swdec_pending_queue(padapter); - - precvframe = (union recv_frame *)precvpriv->precv_frame_buf; - - for (i = 0; i < NR_RECVFRAME; i++) { - if (precvframe->u.hdr.pkt) { - /* free skb by driver */ - dev_kfree_skb_any(precvframe->u.hdr.pkt); - precvframe->u.hdr.pkt = NULL; - } - precvframe++; - } - - vfree(precvpriv->pallocated_frame_buf); - - rtw_hal_free_recv_priv(padapter); -} - -union recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue) -{ - union recv_frame *precvframe; - struct list_head *plist, *phead; - struct adapter *padapter; - struct recv_priv *precvpriv; - - if (list_empty(&pfree_recv_queue->queue)) { - precvframe = NULL; - } else { - phead = get_list_head(pfree_recv_queue); - - plist = get_next(phead); - - precvframe = (union recv_frame *)plist; - - list_del_init(&precvframe->u.hdr.list); - padapter = precvframe->u.hdr.adapter; - if (padapter) { - precvpriv = &padapter->recvpriv; - if (pfree_recv_queue == &precvpriv->free_recv_queue) - precvpriv->free_recvframe_cnt--; - } - } - return precvframe; -} - -union recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue) -{ - union recv_frame *precvframe; - - spin_lock_bh(&pfree_recv_queue->lock); - - precvframe = _rtw_alloc_recvframe(pfree_recv_queue); - - spin_unlock_bh(&pfree_recv_queue->lock); - - return precvframe; -} - -int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue) -{ - struct adapter *padapter = precvframe->u.hdr.adapter; - struct recv_priv *precvpriv = &padapter->recvpriv; - - if (precvframe->u.hdr.pkt) { - dev_kfree_skb_any(precvframe->u.hdr.pkt);/* free skb by driver */ - precvframe->u.hdr.pkt = NULL; - } - - spin_lock_bh(&pfree_recv_queue->lock); - - list_del_init(&(precvframe->u.hdr.list)); - - precvframe->u.hdr.len = 0; - - list_add_tail(&(precvframe->u.hdr.list), get_list_head(pfree_recv_queue)); - - if (padapter) { - if (pfree_recv_queue == &precvpriv->free_recv_queue) - precvpriv->free_recvframe_cnt++; - } - spin_unlock_bh(&pfree_recv_queue->lock); - return _SUCCESS; -} - -signed int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue) -{ - struct adapter *padapter = precvframe->u.hdr.adapter; - struct recv_priv *precvpriv = &padapter->recvpriv; - - /* INIT_LIST_HEAD(&(precvframe->u.hdr.list)); */ - list_del_init(&(precvframe->u.hdr.list)); - - list_add_tail(&(precvframe->u.hdr.list), get_list_head(queue)); - - if (padapter) - if (queue == &precvpriv->free_recv_queue) - precvpriv->free_recvframe_cnt++; - - return _SUCCESS; -} - -signed int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue) -{ - signed int ret; - - /* _spinlock(&pfree_recv_queue->lock); */ - spin_lock_bh(&queue->lock); - ret = _rtw_enqueue_recvframe(precvframe, queue); - /* spin_unlock(&pfree_recv_queue->lock); */ - spin_unlock_bh(&queue->lock); - - return ret; -} - -/* - * caller : defrag ; recvframe_chk_defrag in recv_thread (passive) - * pframequeue: defrag_queue : will be accessed in recv_thread (passive) - * - * using spinlock to protect - * - */ - -void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue) -{ - union recv_frame *precvframe; - struct list_head *plist, *phead; - - spin_lock(&pframequeue->lock); - - phead = get_list_head(pframequeue); - plist = get_next(phead); - - while (phead != plist) { - precvframe = (union recv_frame *)plist; - - plist = get_next(plist); - - rtw_free_recvframe(precvframe, pfree_recv_queue); - } - - spin_unlock(&pframequeue->lock); -} - -u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter) -{ - u32 cnt = 0; - union recv_frame *pending_frame; - - while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) { - rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue); - cnt++; - } - - return cnt; -} - -signed int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue) -{ - spin_lock_bh(&queue->lock); - - list_del_init(&precvbuf->list); - list_add(&precvbuf->list, get_list_head(queue)); - - spin_unlock_bh(&queue->lock); - - return _SUCCESS; -} - -signed int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue) -{ - spin_lock_bh(&queue->lock); - - list_del_init(&precvbuf->list); - - list_add_tail(&precvbuf->list, get_list_head(queue)); - spin_unlock_bh(&queue->lock); - return _SUCCESS; -} - -struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue) -{ - struct recv_buf *precvbuf; - struct list_head *plist, *phead; - - spin_lock_bh(&queue->lock); - - if (list_empty(&queue->queue)) { - precvbuf = NULL; - } else { - phead = get_list_head(queue); - - plist = get_next(phead); - - precvbuf = container_of(plist, struct recv_buf, list); - - list_del_init(&precvbuf->list); - } - - spin_unlock_bh(&queue->lock); - - return precvbuf; -} - -static void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup) -{ - enum nl80211_key_type key_type = 0; - union iwreq_data wrqu; - struct iw_michaelmicfailure ev; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - unsigned long cur_time = 0; - - if (psecuritypriv->last_mic_err_time == 0) { - psecuritypriv->last_mic_err_time = jiffies; - } else { - cur_time = jiffies; - - if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) { - psecuritypriv->btkip_countermeasure = true; - psecuritypriv->last_mic_err_time = 0; - psecuritypriv->btkip_countermeasure_time = cur_time; - } else { - psecuritypriv->last_mic_err_time = jiffies; - } - } - - if (bgroup) - key_type |= NL80211_KEYTYPE_GROUP; - else - key_type |= NL80211_KEYTYPE_PAIRWISE; - - cfg80211_michael_mic_failure(padapter->pnetdev, (u8 *)&pmlmepriv->assoc_bssid[0], key_type, -1, - NULL, GFP_ATOMIC); - - memset(&ev, 0x00, sizeof(ev)); - if (bgroup) - ev.flags |= IW_MICFAILURE_GROUP; - else - ev.flags |= IW_MICFAILURE_PAIRWISE; - - ev.src_addr.sa_family = ARPHRD_ETHER; - memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN); - - memset(&wrqu, 0x00, sizeof(wrqu)); - wrqu.data.length = sizeof(ev); -} - -static signed int recvframe_chkmic(struct adapter *adapter, union recv_frame *precvframe) -{ - signed int i, res = _SUCCESS; - u32 datalen; - u8 miccode[8]; - u8 bmic_err = false, brpt_micerror = true; - u8 *pframe, *payload, *pframemic; - u8 *mickey; - /* u8 *iv, rxdata_key_idx = 0; */ - struct sta_info *stainfo; - struct rx_pkt_attrib *prxattrib = &precvframe->u.hdr.attrib; - struct security_priv *psecuritypriv = &adapter->securitypriv; - - struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); - - stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]); - - if (prxattrib->encrypt == _TKIP_) { - /* calculate mic code */ - if (stainfo) { - if (is_multicast_ether_addr(prxattrib->ra)) { - /* mickey =&psecuritypriv->dot118021XGrprxmickey.skey[0]; */ - /* iv = precvframe->u.hdr.rx_data+prxattrib->hdrlen; */ - /* rxdata_key_idx =(((iv[3])>>6)&0x3) ; */ - mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0]; - - /* psecuritypriv->dot118021XGrpKeyid, pmlmeinfo->key_index, rxdata_key_idx); */ - - if (!psecuritypriv->binstallGrpkey) { - res = _FAIL; - goto exit; - } - } else { - mickey = &stainfo->dot11tkiprxmickey.skey[0]; - } - - datalen = precvframe->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len - prxattrib->icv_len - 8;/* icv_len included the mic code */ - pframe = precvframe->u.hdr.rx_data; - payload = pframe + prxattrib->hdrlen + prxattrib->iv_len; - - rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0], (unsigned char)prxattrib->priority); /* care the length of the data */ - - pframemic = payload + datalen; - - bmic_err = false; - - for (i = 0; i < 8; i++) { - if (miccode[i] != *(pframemic + i)) - bmic_err = true; - } - - if (bmic_err) { - /* double check key_index for some timing issue , */ - /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */ - if (is_multicast_ether_addr(prxattrib->ra) && - (prxattrib->key_index != pmlmeinfo->key_index)) - brpt_micerror = false; - - if (prxattrib->bdecrypted && brpt_micerror) - rtw_handle_tkip_mic_err(adapter, (u8)is_multicast_ether_addr(prxattrib->ra)); - - res = _FAIL; - - } else { - /* mic checked ok */ - if (!psecuritypriv->bcheck_grpkey && - is_multicast_ether_addr(prxattrib->ra)) - psecuritypriv->bcheck_grpkey = true; - } - } - - recvframe_pull_tail(precvframe, 8); - } - -exit: - return res; -} - -/* decrypt and set the ivlen, icvlen of the recv_frame */ -static union recv_frame *decryptor(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - union recv_frame *return_packet = precv_frame; - u32 res = _SUCCESS; - - if (prxattrib->encrypt > 0) { - u8 *iv = precv_frame->u.hdr.rx_data + prxattrib->hdrlen; - - prxattrib->key_index = (((iv[3]) >> 6) & 0x3); - - if (prxattrib->key_index > WEP_KEYS) { - switch (prxattrib->encrypt) { - case _WEP40_: - case _WEP104_: - prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex; - break; - case _TKIP_: - case _AES_: - default: - prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid; - break; - } - } - } - - if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || psecuritypriv->sw_decrypt)) { - psecuritypriv->hw_decrypted = false; - - switch (prxattrib->encrypt) { - case _WEP40_: - case _WEP104_: - rtw_wep_decrypt(padapter, (u8 *)precv_frame); - break; - case _TKIP_: - res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame); - break; - case _AES_: - res = rtw_aes_decrypt(padapter, (u8 *)precv_frame); - break; - default: - break; - } - } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 && - (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_) - ) { - psecuritypriv->hw_decrypted = true; - } else { - } - - if (res == _FAIL) { - rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue); - return_packet = NULL; - } else { - prxattrib->bdecrypted = true; - } - - return return_packet; -} - -/* set the security information in the recv_frame */ -static union recv_frame *portctrl(struct adapter *adapter, union recv_frame *precv_frame) -{ - u8 *psta_addr = NULL; - u8 *ptr; - unsigned int auth_alg; - struct recv_frame_hdr *pfhdr; - struct sta_info *psta; - struct sta_priv *pstapriv; - union recv_frame *prtnframe; - u16 ether_type = 0; - u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */ - struct rx_pkt_attrib *pattrib; - - pstapriv = &adapter->stapriv; - - auth_alg = adapter->securitypriv.dot11_auth_algrthm; - - ptr = precv_frame->u.hdr.rx_data; - pfhdr = &precv_frame->u.hdr; - pattrib = &pfhdr->attrib; - psta_addr = pattrib->ta; - - prtnframe = NULL; - - psta = rtw_get_stainfo(pstapriv, psta_addr); - - if (auth_alg == 2) { - if ((psta) && (psta->ieee8021x_blocked)) { - __be16 be_tmp; - - /* blocked */ - /* only accept EAPOL frame */ - - prtnframe = precv_frame; - - /* get ether_type */ - ptr = ptr + pfhdr->attrib.hdrlen + pfhdr->attrib.iv_len + LLC_HEADER_LENGTH; - memcpy(&be_tmp, ptr, 2); - ether_type = ntohs(be_tmp); - - if (ether_type == eapol_type) { - prtnframe = precv_frame; - } else { - /* free this frame */ - rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue); - prtnframe = NULL; - } - } else { - /* allowed */ - /* check decryption status, and decrypt the frame if needed */ - - prtnframe = precv_frame; - /* check is the EAPOL frame or not (Rekey) */ - /* if (ether_type == eapol_type) { */ - /* check Rekey */ - - /* prtnframe =precv_frame; */ - /* */ - /* else { */ - /* */ - } - } else { - prtnframe = precv_frame; - } - - return prtnframe; -} - -static signed int recv_decache(union recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache) -{ - signed int tid = precv_frame->u.hdr.attrib.priority; - - u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num & 0xffff) << 4) | - (precv_frame->u.hdr.attrib.frag_num & 0xf); - - if (tid > 15) - return _FAIL; - - if (1) { /* if (bretry) */ - if (seq_ctrl == prxcache->tid_rxseq[tid]) - return _FAIL; - } - - prxcache->tid_rxseq[tid] = seq_ctrl; - - return _SUCCESS; -} - -static void process_pwrbit_data(struct adapter *padapter, union recv_frame *precv_frame) -{ - unsigned char pwrbit; - u8 *ptr = precv_frame->u.hdr.rx_data; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *psta = NULL; - - psta = rtw_get_stainfo(pstapriv, pattrib->src); - - pwrbit = GetPwrMgt(ptr); - - if (psta) { - if (pwrbit) { - if (!(psta->state & WIFI_SLEEP_STATE)) { - /* psta->state |= WIFI_SLEEP_STATE; */ - /* pstapriv->sta_dz_bitmap |= BIT(psta->aid); */ - - stop_sta_xmit(padapter, psta); - } - } else { - if (psta->state & WIFI_SLEEP_STATE) { - /* psta->state ^= WIFI_SLEEP_STATE; */ - /* pstapriv->sta_dz_bitmap &= ~BIT(psta->aid); */ - - wakeup_sta_to_xmit(padapter, psta); - } - } - } -} - -static void process_wmmps_data(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *psta = NULL; - - psta = rtw_get_stainfo(pstapriv, pattrib->src); - - if (!psta) - return; - - if (!psta->qos_option) - return; - - if (!(psta->qos_info & 0xf)) - return; - - if (psta->state & WIFI_SLEEP_STATE) { - u8 wmmps_ac = 0; - - switch (pattrib->priority) { - case 1: - case 2: - wmmps_ac = psta->uapsd_bk & BIT(1); - break; - case 4: - case 5: - wmmps_ac = psta->uapsd_vi & BIT(1); - break; - case 6: - case 7: - wmmps_ac = psta->uapsd_vo & BIT(1); - break; - case 0: - case 3: - default: - wmmps_ac = psta->uapsd_be & BIT(1); - break; - } - - if (wmmps_ac) { - if (psta->sleepq_ac_len > 0) - /* process received triggered frame */ - xmit_delivery_enabled_frames(padapter, psta); - else - /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */ - issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0); - } - } -} - -static void count_rx_stats(struct adapter *padapter, union recv_frame *prframe, struct sta_info *sta) -{ - int sz; - struct sta_info *psta = NULL; - struct stainfo_stats *pstats = NULL; - struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; - struct recv_priv *precvpriv = &padapter->recvpriv; - - sz = get_recvframe_len(prframe); - precvpriv->rx_bytes += sz; - - padapter->mlmepriv.link_detect_info.num_rx_ok_in_period++; - - if ((!is_broadcast_ether_addr(pattrib->dst)) && (!is_multicast_ether_addr(pattrib->dst))) - padapter->mlmepriv.link_detect_info.num_rx_unicast_ok_in_period++; - - if (sta) - psta = sta; - else - psta = prframe->u.hdr.psta; - - if (psta) { - pstats = &psta->sta_stats; - - pstats->rx_data_pkts++; - pstats->rx_bytes += sz; - } - - traffic_check_for_leave_lps(padapter, false, 0); -} - -static signed int sta2sta_data_frame(struct adapter *adapter, union recv_frame *precv_frame, - struct sta_info **psta) -{ - u8 *ptr = precv_frame->u.hdr.rx_data; - signed int ret = _SUCCESS; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - struct sta_priv *pstapriv = &adapter->stapriv; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - u8 *mybssid = get_bssid(pmlmepriv); - u8 *myhwaddr = myid(&adapter->eeprompriv); - u8 *sta_addr = NULL; - signed int bmcast = is_multicast_ether_addr(pattrib->dst); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - /* filter packets that SA is myself or multicast or broadcast */ - if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) { - ret = _FAIL; - goto exit; - } - - if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) { - ret = _FAIL; - goto exit; - } - - if (is_zero_ether_addr(pattrib->bssid) || - is_zero_ether_addr(mybssid) || - (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) { - ret = _FAIL; - goto exit; - } - - sta_addr = pattrib->src; - - } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */ - if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) { - ret = _FAIL; - goto exit; - } - - sta_addr = pattrib->bssid; - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - if (bmcast) { - /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */ - if (!is_multicast_ether_addr(pattrib->bssid)) { - ret = _FAIL; - goto exit; - } - } else { /* not mc-frame */ - /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */ - if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) { - ret = _FAIL; - goto exit; - } - - sta_addr = pattrib->src; - } - - } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) { - memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN); - memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN); - memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN); - memcpy(pattrib->ra, pattrib->dst, ETH_ALEN); - memcpy(pattrib->ta, pattrib->src, ETH_ALEN); - - sta_addr = mybssid; - } else { - ret = _FAIL; - } - - if (bmcast) - *psta = rtw_get_bcmc_stainfo(adapter); - else - *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */ - - if (!*psta) { - ret = _FAIL; - goto exit; - } - -exit: - return ret; -} - -static signed int ap2sta_data_frame(struct adapter *adapter, union recv_frame *precv_frame, - struct sta_info **psta) -{ - u8 *ptr = precv_frame->u.hdr.rx_data; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - signed int ret = _SUCCESS; - struct sta_priv *pstapriv = &adapter->stapriv; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - u8 *mybssid = get_bssid(pmlmepriv); - u8 *myhwaddr = myid(&adapter->eeprompriv); - signed int bmcast = is_multicast_ether_addr(pattrib->dst); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && - (check_fwstate(pmlmepriv, _FW_LINKED) || - check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) { - /* filter packets that SA is myself or multicast or broadcast */ - if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) { - ret = _FAIL; - goto exit; - } - - /* da should be for me */ - if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) { - ret = _FAIL; - goto exit; - } - - /* check BSSID */ - if (is_zero_ether_addr(pattrib->bssid) || - is_zero_ether_addr(mybssid) || - (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) { - if (!bmcast) - issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); - - ret = _FAIL; - goto exit; - } - - if (bmcast) - *psta = rtw_get_bcmc_stainfo(adapter); - else - *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */ - - if (!*psta) { - ret = _FAIL; - goto exit; - } - - if (GetFrameSubType(ptr) & BIT(6)) { - /* No data, will not indicate to upper layer, temporarily count it here */ - count_rx_stats(adapter, precv_frame, *psta); - ret = RTW_RX_HANDLED; - goto exit; - } - - } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) && - check_fwstate(pmlmepriv, _FW_LINKED)) { - memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN); - memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN); - memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN); - memcpy(pattrib->ra, pattrib->dst, ETH_ALEN); - memcpy(pattrib->ta, pattrib->src, ETH_ALEN); - - /* */ - memcpy(pattrib->bssid, mybssid, ETH_ALEN); - - *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */ - if (!*psta) { - ret = _FAIL; - goto exit; - } - - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - /* Special case */ - ret = RTW_RX_HANDLED; - goto exit; - } else { - if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) { - *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */ - if (!*psta) { - /* for AP multicast issue , modify by yiwei */ - static unsigned long send_issue_deauth_time; - - if (jiffies_to_msecs(jiffies - send_issue_deauth_time) > 10000 || send_issue_deauth_time == 0) { - send_issue_deauth_time = jiffies; - - issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); - } - } - } - - ret = _FAIL; - } - -exit: - return ret; -} - -static signed int sta2ap_data_frame(struct adapter *adapter, union recv_frame *precv_frame, - struct sta_info **psta) -{ - u8 *ptr = precv_frame->u.hdr.rx_data; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - struct sta_priv *pstapriv = &adapter->stapriv; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - unsigned char *mybssid = get_bssid(pmlmepriv); - signed int ret = _SUCCESS; - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - /* For AP mode, RA =BSSID, TX =STA(SRC_ADDR), A3 =DST_ADDR */ - if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) { - ret = _FAIL; - goto exit; - } - - *psta = rtw_get_stainfo(pstapriv, pattrib->src); - if (!*psta) { - issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); - - ret = RTW_RX_HANDLED; - goto exit; - } - - process_pwrbit_data(adapter, precv_frame); - - if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) - process_wmmps_data(adapter, precv_frame); - - if (GetFrameSubType(ptr) & BIT(6)) { - /* No data, will not indicate to upper layer, temporarily count it here */ - count_rx_stats(adapter, precv_frame, *psta); - ret = RTW_RX_HANDLED; - goto exit; - } - } else { - u8 *myhwaddr = myid(&adapter->eeprompriv); - - if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) { - ret = RTW_RX_HANDLED; - goto exit; - } - issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); - ret = RTW_RX_HANDLED; - goto exit; - } - -exit: - return ret; -} - -static signed int validate_recv_ctrl_frame(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - struct sta_priv *pstapriv = &padapter->stapriv; - u8 *pframe = precv_frame->u.hdr.rx_data; - struct sta_info *psta = NULL; - /* uint len = precv_frame->u.hdr.len; */ - - if (GetFrameType(pframe) != WIFI_CTRL_TYPE) - return _FAIL; - - /* receive the frames that ra(a1) is my address */ - if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN)) - return _FAIL; - - psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); - if (!psta) - return _FAIL; - - /* for rx pkt statistics */ - psta->sta_stats.rx_ctrl_pkts++; - - /* only handle ps-poll */ - if (GetFrameSubType(pframe) == WIFI_PSPOLL) { - u16 aid; - u8 wmmps_ac = 0; - - aid = GetAid(pframe); - if (psta->aid != aid) - return _FAIL; - - switch (pattrib->priority) { - case 1: - case 2: - wmmps_ac = psta->uapsd_bk & BIT(0); - break; - case 4: - case 5: - wmmps_ac = psta->uapsd_vi & BIT(0); - break; - case 6: - case 7: - wmmps_ac = psta->uapsd_vo & BIT(0); - break; - case 0: - case 3: - default: - wmmps_ac = psta->uapsd_be & BIT(0); - break; - } - - if (wmmps_ac) - return _FAIL; - - if (psta->state & WIFI_STA_ALIVE_CHK_STATE) { - psta->expire_to = pstapriv->expire_to; - psta->state ^= WIFI_STA_ALIVE_CHK_STATE; - } - - if ((psta->state & WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap & BIT(psta->aid))) { - struct list_head *xmitframe_plist, *xmitframe_phead; - struct xmit_frame *pxmitframe = NULL; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - /* spin_lock_bh(&psta->sleep_q.lock); */ - spin_lock_bh(&pxmitpriv->lock); - - xmitframe_phead = get_list_head(&psta->sleep_q); - xmitframe_plist = get_next(xmitframe_phead); - - if (xmitframe_phead != xmitframe_plist) { - pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list); - - xmitframe_plist = get_next(xmitframe_plist); - - list_del_init(&pxmitframe->list); - - psta->sleepq_len--; - - if (psta->sleepq_len > 0) - pxmitframe->attrib.mdata = 1; - else - pxmitframe->attrib.mdata = 0; - - pxmitframe->attrib.triggered = 1; - - rtw_hal_xmitframe_enqueue(padapter, pxmitframe); - - if (psta->sleepq_len == 0) { - pstapriv->tim_bitmap &= ~BIT(psta->aid); - - /* update BCN for TIM IE */ - /* update_BCNTIM(padapter); */ - update_beacon(padapter, WLAN_EID_TIM, true); - } - - /* spin_unlock_bh(&psta->sleep_q.lock); */ - spin_unlock_bh(&pxmitpriv->lock); - - } else { - /* spin_unlock_bh(&psta->sleep_q.lock); */ - spin_unlock_bh(&pxmitpriv->lock); - - if (pstapriv->tim_bitmap & BIT(psta->aid)) { - if (psta->sleepq_len == 0) { - /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */ - issue_nulldata_in_interrupt(padapter, psta->hwaddr); - } else { - psta->sleepq_len = 0; - } - - pstapriv->tim_bitmap &= ~BIT(psta->aid); - - /* update BCN for TIM IE */ - /* update_BCNTIM(padapter); */ - update_beacon(padapter, WLAN_EID_TIM, true); - } - } - } - } - - return _FAIL; -} - -/* perform defrag */ -static union recv_frame *recvframe_defrag(struct adapter *adapter, - struct __queue *defrag_q) -{ - struct list_head *plist, *phead; - u8 wlanhdr_offset; - u8 curfragnum; - struct recv_frame_hdr *pfhdr, *pnfhdr; - union recv_frame *prframe, *pnextrframe; - struct __queue *pfree_recv_queue; - - curfragnum = 0; - pfree_recv_queue = &adapter->recvpriv.free_recv_queue; - - phead = get_list_head(defrag_q); - plist = get_next(phead); - prframe = (union recv_frame *)plist; - pfhdr = &prframe->u.hdr; - list_del_init(&(prframe->u.list)); - - if (curfragnum != pfhdr->attrib.frag_num) { - /* the first fragment number must be 0 */ - /* free the whole queue */ - rtw_free_recvframe(prframe, pfree_recv_queue); - rtw_free_recvframe_queue(defrag_q, pfree_recv_queue); - - return NULL; - } - - curfragnum++; - - plist = get_list_head(defrag_q); - - plist = get_next(plist); - - while (phead != plist) { - pnextrframe = (union recv_frame *)plist; - pnfhdr = &pnextrframe->u.hdr; - - /* check the fragment sequence (2nd ~n fragment frame) */ - - if (curfragnum != pnfhdr->attrib.frag_num) { - /* the fragment number must be increasing (after decache) */ - /* release the defrag_q & prframe */ - rtw_free_recvframe(prframe, pfree_recv_queue); - rtw_free_recvframe_queue(defrag_q, pfree_recv_queue); - return NULL; - } - - curfragnum++; - - /* copy the 2nd~n fragment frame's payload to the first fragment */ - /* get the 2nd~last fragment frame's payload */ - - wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len; - - recvframe_pull(pnextrframe, wlanhdr_offset); - - /* append to first fragment frame's tail (if privacy frame, pull the ICV) */ - recvframe_pull_tail(prframe, pfhdr->attrib.icv_len); - - /* memcpy */ - memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len); - - recvframe_put(prframe, pnfhdr->len); - - pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len; - plist = get_next(plist); - } - - /* free the defrag_q queue and return the prframe */ - rtw_free_recvframe_queue(defrag_q, pfree_recv_queue); - - return prframe; -} - -/* check if need to defrag, if needed queue the frame to defrag_q */ -static union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_frame *precv_frame) -{ - u8 ismfrag; - u8 fragnum; - u8 *psta_addr; - struct recv_frame_hdr *pfhdr; - struct sta_info *psta; - struct sta_priv *pstapriv; - struct list_head *phead; - union recv_frame *prtnframe = NULL; - struct __queue *pfree_recv_queue, *pdefrag_q; - - pstapriv = &padapter->stapriv; - - pfhdr = &precv_frame->u.hdr; - - pfree_recv_queue = &padapter->recvpriv.free_recv_queue; - - /* need to define struct of wlan header frame ctrl */ - ismfrag = pfhdr->attrib.mfrag; - fragnum = pfhdr->attrib.frag_num; - - psta_addr = pfhdr->attrib.ta; - psta = rtw_get_stainfo(pstapriv, psta_addr); - if (!psta) { - u8 type = GetFrameType(pfhdr->rx_data); - - if (type != WIFI_DATA_TYPE) { - psta = rtw_get_bcmc_stainfo(padapter); - pdefrag_q = &psta->sta_recvpriv.defrag_q; - } else { - pdefrag_q = NULL; - } - } else { - pdefrag_q = &psta->sta_recvpriv.defrag_q; - } - - if ((ismfrag == 0) && (fragnum == 0)) - prtnframe = precv_frame;/* isn't a fragment frame */ - - if (ismfrag == 1) { - /* 0~(n-1) fragment frame */ - /* enqueue to defraf_g */ - if (pdefrag_q) { - if (fragnum == 0) - /* the first fragment */ - if (!list_empty(&pdefrag_q->queue)) - /* free current defrag_q */ - rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue); - - /* Then enqueue the 0~(n-1) fragment into the defrag_q */ - - /* spin_lock(&pdefrag_q->lock); */ - phead = get_list_head(pdefrag_q); - list_add_tail(&pfhdr->list, phead); - /* spin_unlock(&pdefrag_q->lock); */ - - prtnframe = NULL; - - } else { - /* can't find this ta's defrag_queue, so free this recv_frame */ - rtw_free_recvframe(precv_frame, pfree_recv_queue); - prtnframe = NULL; - } - } - - if ((ismfrag == 0) && (fragnum != 0)) { - /* the last fragment frame */ - /* enqueue the last fragment */ - if (pdefrag_q) { - /* spin_lock(&pdefrag_q->lock); */ - phead = get_list_head(pdefrag_q); - list_add_tail(&pfhdr->list, phead); - /* spin_unlock(&pdefrag_q->lock); */ - - /* call recvframe_defrag to defrag */ - precv_frame = recvframe_defrag(padapter, pdefrag_q); - prtnframe = precv_frame; - - } else { - /* can't find this ta's defrag_queue, so free this recv_frame */ - rtw_free_recvframe(precv_frame, pfree_recv_queue); - prtnframe = NULL; - } - } - - if ((prtnframe) && (prtnframe->u.hdr.attrib.privacy)) { - /* after defrag we must check tkip mic code */ - if (recvframe_chkmic(padapter, prtnframe) == _FAIL) { - rtw_free_recvframe(prtnframe, pfree_recv_queue); - prtnframe = NULL; - } - } - return prtnframe; -} - -static signed int validate_recv_mgnt_frame(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct sta_info *psta; - - precv_frame = recvframe_chk_defrag(padapter, precv_frame); - if (!precv_frame) - return _SUCCESS; - - /* for rx pkt statistics */ - psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(precv_frame->u.hdr.rx_data)); - if (!psta) - goto exit; - - psta->sta_stats.rx_mgnt_pkts++; - - switch (GetFrameSubType(precv_frame->u.hdr.rx_data)) { - case WIFI_BEACON: - psta->sta_stats.rx_beacon_pkts++; - break; - case WIFI_PROBEREQ: - psta->sta_stats.rx_probereq_pkts++; - break; - case WIFI_PROBERSP: - if (!memcmp(padapter->eeprompriv.mac_addr, - GetAddr1Ptr(precv_frame->u.hdr.rx_data), - ETH_ALEN)) - psta->sta_stats.rx_probersp_pkts++; - else if (is_broadcast_ether_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data)) || - is_multicast_ether_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data))) - psta->sta_stats.rx_probersp_bm_pkts++; - else - psta->sta_stats.rx_probersp_uo_pkts++; - - break; - } - -exit: - mgt_dispatcher(padapter, precv_frame); - - return _SUCCESS; -} - -static signed int validate_recv_data_frame(struct adapter *adapter, union recv_frame *precv_frame) -{ - u8 bretry; - u8 *psa, *pda, *pbssid; - struct sta_info *psta = NULL; - u8 *ptr = precv_frame->u.hdr.rx_data; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - struct security_priv *psecuritypriv = &adapter->securitypriv; - signed int ret = _SUCCESS; - - bretry = GetRetry(ptr); - pda = get_da(ptr); - psa = get_sa(ptr); - pbssid = get_hdr_bssid(ptr); - - if (!pbssid) { - ret = _FAIL; - goto exit; - } - - memcpy(pattrib->dst, pda, ETH_ALEN); - memcpy(pattrib->src, psa, ETH_ALEN); - - memcpy(pattrib->bssid, pbssid, ETH_ALEN); - - switch (pattrib->to_fr_ds) { - case 0: - memcpy(pattrib->ra, pda, ETH_ALEN); - memcpy(pattrib->ta, psa, ETH_ALEN); - ret = sta2sta_data_frame(adapter, precv_frame, &psta); - break; - - case 1: - memcpy(pattrib->ra, pda, ETH_ALEN); - memcpy(pattrib->ta, pbssid, ETH_ALEN); - ret = ap2sta_data_frame(adapter, precv_frame, &psta); - break; - - case 2: - memcpy(pattrib->ra, pbssid, ETH_ALEN); - memcpy(pattrib->ta, psa, ETH_ALEN); - ret = sta2ap_data_frame(adapter, precv_frame, &psta); - break; - - case 3: - memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN); - memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN); - ret = _FAIL; - break; - - default: - ret = _FAIL; - break; - } - - if (ret == _FAIL || ret == RTW_RX_HANDLED) - goto exit; - - if (!psta) { - ret = _FAIL; - goto exit; - } - - /* psta->rssi = prxcmd->rssi; */ - /* psta->signal_quality = prxcmd->sq; */ - precv_frame->u.hdr.psta = psta; - - pattrib->amsdu = 0; - pattrib->ack_policy = 0; - /* parsing QC field */ - if (pattrib->qos == 1) { - pattrib->priority = GetPriority((ptr + 24)); - pattrib->ack_policy = GetAckpolicy((ptr + 24)); - pattrib->amsdu = GetAMsdu((ptr + 24)); - pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26; - - if (pattrib->priority != 0 && pattrib->priority != 3) - adapter->recvpriv.bIsAnyNonBEPkts = true; - - } else { - pattrib->priority = 0; - pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24; - } - - if (pattrib->order)/* HT-CTRL 11n */ - pattrib->hdrlen += 4; - - precv_frame->u.hdr.preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority]; - - /* decache, drop duplicate recv packets */ - if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) { - ret = _FAIL; - goto exit; - } - - if (pattrib->privacy) { - GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, is_multicast_ether_addr(pattrib->ra)); - - SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt); - } else { - pattrib->encrypt = 0; - pattrib->iv_len = pattrib->icv_len = 0; - } - -exit: - return ret; -} - -static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame *precv_frame) -{ - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - u8 *ptr = precv_frame->u.hdr.rx_data; - u8 subtype; - - subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */ - - /* only support station mode */ - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED) && - adapter->securitypriv.binstallBIPkey) { - /* unicast management frame decrypt */ - if (pattrib->privacy && !(is_multicast_ether_addr(GetAddr1Ptr(ptr))) && - (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC || subtype == WIFI_ACTION)) { - u8 *mgmt_DATA; - u32 data_len = 0; - - pattrib->bdecrypted = 0; - pattrib->encrypt = _AES_; - pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr); - /* set iv and icv length */ - SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt); - memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN); - memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN); - /* actual management data frame body */ - data_len = pattrib->pkt_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - mgmt_DATA = kzalloc(data_len, GFP_ATOMIC); - if (!mgmt_DATA) - goto validate_80211w_fail; - precv_frame = decryptor(adapter, precv_frame); - /* save actual management data frame body */ - memcpy(mgmt_DATA, ptr + pattrib->hdrlen + pattrib->iv_len, data_len); - /* overwrite the iv field */ - memcpy(ptr + pattrib->hdrlen, mgmt_DATA, data_len); - /* remove the iv and icv length */ - pattrib->pkt_len = pattrib->pkt_len - pattrib->iv_len - pattrib->icv_len; - kfree(mgmt_DATA); - if (!precv_frame) - goto validate_80211w_fail; - } else if (is_multicast_ether_addr(GetAddr1Ptr(ptr)) && - (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC)) { - signed int BIP_ret = _SUCCESS; - /* verify BIP MME IE of broadcast/multicast de-auth/disassoc packet */ - BIP_ret = rtw_BIP_verify(adapter, (u8 *)precv_frame); - if (BIP_ret == _FAIL) { - goto validate_80211w_fail; - } else if (BIP_ret == RTW_RX_HANDLED) { - /* issue sa query request */ - issue_action_SA_Query(adapter, NULL, 0, 0); - goto validate_80211w_fail; - } - } else { /* 802.11w protect */ - if (subtype == WIFI_ACTION) { - /* according 802.11-2012 standard, these five types are not robust types */ - if (ptr[WLAN_HDR_A3_LEN] != RTW_WLAN_CATEGORY_PUBLIC && - ptr[WLAN_HDR_A3_LEN] != RTW_WLAN_CATEGORY_HT && - ptr[WLAN_HDR_A3_LEN] != RTW_WLAN_CATEGORY_UNPROTECTED_WNM && - ptr[WLAN_HDR_A3_LEN] != RTW_WLAN_CATEGORY_SELF_PROTECTED && - ptr[WLAN_HDR_A3_LEN] != RTW_WLAN_CATEGORY_P2P) { - goto validate_80211w_fail; - } - } else if (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC) { - /* issue sa query request */ - issue_action_SA_Query(adapter, NULL, 0, 0); - goto validate_80211w_fail; - } - } - } - return _SUCCESS; - -validate_80211w_fail: - return _FAIL; -} - -static signed int validate_recv_frame(struct adapter *adapter, union recv_frame *precv_frame) -{ - /* shall check frame subtype, to / from ds, da, bssid */ - - /* then call check if rx seq/frag. duplicated. */ - - u8 type; - u8 subtype; - signed int retval = _SUCCESS; - - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - - u8 *ptr = precv_frame->u.hdr.rx_data; - u8 ver = (unsigned char) (*ptr) & 0x3; - - /* add version chk */ - if (ver != 0) { - retval = _FAIL; - goto exit; - } - - type = GetFrameType(ptr); - subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */ - - pattrib->to_fr_ds = get_tofr_ds(ptr); - - pattrib->frag_num = GetFragNum(ptr); - pattrib->seq_num = GetSequence(ptr); - - pattrib->pw_save = GetPwrMgt(ptr); - pattrib->mfrag = GetMFrag(ptr); - pattrib->mdata = GetMData(ptr); - pattrib->privacy = GetPrivacy(ptr); - pattrib->order = GetOrder(ptr); - - switch (type) { - case WIFI_MGT_TYPE: /* mgnt */ - if (validate_80211w_mgmt(adapter, precv_frame) == _FAIL) { - retval = _FAIL; - break; - } - - retval = validate_recv_mgnt_frame(adapter, precv_frame); - retval = _FAIL; /* only data frame return _SUCCESS */ - break; - case WIFI_CTRL_TYPE: /* ctrl */ - retval = validate_recv_ctrl_frame(adapter, precv_frame); - retval = _FAIL; /* only data frame return _SUCCESS */ - break; - case WIFI_DATA_TYPE: /* data */ - pattrib->qos = (subtype & BIT(7)) ? 1 : 0; - retval = validate_recv_data_frame(adapter, precv_frame); - if (retval == _FAIL) { - struct recv_priv *precvpriv = &adapter->recvpriv; - - precvpriv->rx_drop++; - } - break; - default: - retval = _FAIL; - break; - } - -exit: - return retval; -} - -/* remove the wlanhdr and add the eth_hdr */ -static signed int wlanhdr_to_ethhdr(union recv_frame *precvframe) -{ - signed int rmv_len; - u16 eth_type, len; - u8 bsnaphdr; - u8 *psnap_type; - struct ieee80211_snap_hdr *psnap; - __be16 be_tmp; - struct adapter *adapter = precvframe->u.hdr.adapter; - struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - u8 *ptr = precvframe->u.hdr.rx_data; /* point to frame_ctrl field */ - struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib; - - if (pattrib->encrypt) - recvframe_pull_tail(precvframe, pattrib->icv_len); - - psnap = (struct ieee80211_snap_hdr *)(ptr + pattrib->hdrlen + pattrib->iv_len); - psnap_type = ptr + pattrib->hdrlen + pattrib->iv_len + SNAP_SIZE; - /* convert hdr + possible LLC headers into Ethernet header */ - /* eth_type = (psnap_type[0] << 8) | psnap_type[1]; */ - if ((!memcmp(psnap, rfc1042_header, SNAP_SIZE) && - (memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2)) && - (memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2))) || - /* eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) || */ - !memcmp(psnap, bridge_tunnel_header, SNAP_SIZE)) { - /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */ - bsnaphdr = true; - } else { - /* Leave Ethernet header part of hdr and full payload */ - bsnaphdr = false; - } - - rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0); - len = precvframe->u.hdr.len - rmv_len; - - memcpy(&be_tmp, ptr + rmv_len, 2); - eth_type = ntohs(be_tmp); /* pattrib->ether_type */ - pattrib->eth_type = eth_type; - - if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) { - ptr += rmv_len; - *ptr = 0x87; - *(ptr + 1) = 0x12; - - eth_type = 0x8712; - /* append rx status for mp test packets */ - ptr = recvframe_pull(precvframe, (rmv_len - sizeof(struct ethhdr) + 2) - 24); - if (!ptr) - return _FAIL; - memcpy(ptr, get_rxmem(precvframe), 24); - ptr += 24; - } else { - ptr = recvframe_pull(precvframe, (rmv_len - sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0))); - if (!ptr) - return _FAIL; - } - - memcpy(ptr, pattrib->dst, ETH_ALEN); - memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN); - - if (!bsnaphdr) { - be_tmp = htons(len); - memcpy(ptr + 12, &be_tmp, 2); - } - - return _SUCCESS; -} - -static struct sk_buff *rtw_alloc_msdu_pkt(union recv_frame *prframe, u16 subframe_len, u8 *pdata) -{ - u16 eth_type; - struct sk_buff *sub_skb; - struct rx_pkt_attrib *pattrib; - - pattrib = &prframe->u.hdr.attrib; - - sub_skb = __dev_alloc_skb(subframe_len + 12, GFP_ATOMIC); - if (!sub_skb) - return NULL; - - skb_reserve(sub_skb, 12); - skb_put_data(sub_skb, (pdata + ETH_HLEN), subframe_len); - - eth_type = get_unaligned_be16(&sub_skb->data[6]); - - if (sub_skb->len >= 8 && - ((!memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) && - eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) || - !memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE))) { - /* - * remove RFC1042 or Bridge-Tunnel encapsulation and replace - * EtherType - */ - skb_pull(sub_skb, SNAP_SIZE); - memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN); - memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN); - } else { - __be16 len; - /* Leave Ethernet header part of hdr and full payload */ - len = htons(sub_skb->len); - memcpy(skb_push(sub_skb, 2), &len, 2); - memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN); - memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN); - } - - return sub_skb; -} - -static void rtw_recv_indicate_pkt(struct adapter *padapter, struct sk_buff *pkt, struct rx_pkt_attrib *pattrib) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - /* Indicate the packets to upper layer */ - if (pkt) { - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - struct sk_buff *pskb2 = NULL; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - int bmcast = is_multicast_ether_addr(pattrib->dst); - - if (memcmp(pattrib->dst, myid(&padapter->eeprompriv), ETH_ALEN)) { - if (bmcast) { - psta = rtw_get_bcmc_stainfo(padapter); - pskb2 = skb_clone(pkt, GFP_ATOMIC); - } else { - psta = rtw_get_stainfo(pstapriv, pattrib->dst); - } - - if (psta) { - struct net_device *pnetdev = (struct net_device *)padapter->pnetdev; - /* skb->ip_summed = CHECKSUM_NONE; */ - pkt->dev = pnetdev; - skb_set_queue_mapping(pkt, rtw_recv_select_queue(pkt)); - - _rtw_xmit_entry(pkt, pnetdev); - - if (bmcast && pskb2) - pkt = pskb2; - else - return; - } - } else { - /* to APself */ - } - } - - pkt->protocol = eth_type_trans(pkt, padapter->pnetdev); - pkt->dev = padapter->pnetdev; - - pkt->ip_summed = CHECKSUM_NONE; - - rtw_netif_rx(padapter->pnetdev, pkt); - } -} - -static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe) -{ - int a_len, padding_len; - u16 subframe_len; - u8 nr_subframes, i; - u8 *pdata; - struct sk_buff *sub_pkt, *subframes[MAX_SUBFRAME_COUNT]; - struct recv_priv *precvpriv = &padapter->recvpriv; - struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue); - - nr_subframes = 0; - - recvframe_pull(prframe, prframe->u.hdr.attrib.hdrlen); - - if (prframe->u.hdr.attrib.iv_len > 0) - recvframe_pull(prframe, prframe->u.hdr.attrib.iv_len); - - a_len = prframe->u.hdr.len; - - pdata = prframe->u.hdr.rx_data; - - while (a_len > ETH_HLEN) { - /* Offset 12 denote 2 mac address */ - subframe_len = get_unaligned_be16(pdata + 12); - - if (a_len < ETH_HLEN + subframe_len) - break; - - sub_pkt = rtw_alloc_msdu_pkt(prframe, subframe_len, pdata); - if (!sub_pkt) - break; - - /* move the data point to data content */ - pdata += ETH_HLEN; - a_len -= ETH_HLEN; - - subframes[nr_subframes++] = sub_pkt; - - if (nr_subframes >= MAX_SUBFRAME_COUNT) - break; - - pdata += subframe_len; - a_len -= subframe_len; - if (a_len != 0) { - padding_len = 4 - ((subframe_len + ETH_HLEN) & (4 - 1)); - if (padding_len == 4) - padding_len = 0; - - if (a_len < padding_len) - break; - - pdata += padding_len; - a_len -= padding_len; - } - } - - for (i = 0; i < nr_subframes; i++) { - sub_pkt = subframes[i]; - - /* Indicate the packets to upper layer */ - if (sub_pkt) - rtw_recv_indicate_pkt(padapter, sub_pkt, &prframe->u.hdr.attrib); - } - - prframe->u.hdr.len = 0; - rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */ - - return _SUCCESS; -} - -static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num) -{ - u8 wsize = preorder_ctrl->wsize_b; - u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) % 4096u; - - /* Rx Reorder initialize condition. */ - if (preorder_ctrl->indicate_seq == 0xFFFF) - preorder_ctrl->indicate_seq = seq_num; - - /* Drop out the packet which SeqNum is smaller than WinStart */ - if (SN_LESS(seq_num, preorder_ctrl->indicate_seq)) - return false; - - /* */ - /* Sliding window manipulation. Conditions includes: */ - /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */ - /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */ - /* */ - if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) { - preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) % 4096u; - - } else if (SN_LESS(wend, seq_num)) { - /* boundary situation, when seq_num cross 0xFFF */ - if (seq_num >= (wsize - 1)) - preorder_ctrl->indicate_seq = seq_num + 1 - wsize; - else - preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1; - } - - return true; -} - -static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, union recv_frame *prframe) -{ - struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; - struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; - struct list_head *phead, *plist; - union recv_frame *pnextrframe; - struct rx_pkt_attrib *pnextattrib; - - /* spin_lock_irqsave(&ppending_recvframe_queue->lock, irql); */ - /* spin_lock(&ppending_recvframe_queue->lock); */ - - phead = get_list_head(ppending_recvframe_queue); - plist = get_next(phead); - - while (phead != plist) { - pnextrframe = (union recv_frame *)plist; - pnextattrib = &pnextrframe->u.hdr.attrib; - - if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) - plist = get_next(plist); - else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num)) - /* Duplicate entry is found!! Do not insert current entry. */ - /* spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); */ - return false; - else - break; - } - - /* spin_lock_irqsave(&ppending_recvframe_queue->lock, irql); */ - /* spin_lock(&ppending_recvframe_queue->lock); */ - - list_del_init(&(prframe->u.hdr.list)); - - list_add_tail(&(prframe->u.hdr.list), plist); - - /* spin_unlock(&ppending_recvframe_queue->lock); */ - /* spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); */ - - return true; -} - -static int rtw_recv_indicatepkt(struct adapter *padapter, union recv_frame *precv_frame) -{ - struct recv_priv *precvpriv; - struct __queue *pfree_recv_queue; - struct sk_buff *skb; - struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; - - precvpriv = &(padapter->recvpriv); - pfree_recv_queue = &(precvpriv->free_recv_queue); - - skb = precv_frame->u.hdr.pkt; - if (!skb) - goto _recv_indicatepkt_drop; - - skb->data = precv_frame->u.hdr.rx_data; - - skb_set_tail_pointer(skb, precv_frame->u.hdr.len); - - skb->len = precv_frame->u.hdr.len; - - rtw_recv_indicate_pkt(padapter, skb, pattrib); - - /* pointers to NULL before rtw_free_recvframe() */ - precv_frame->u.hdr.pkt = NULL; - - rtw_free_recvframe(precv_frame, pfree_recv_queue); - - return _SUCCESS; - -_recv_indicatepkt_drop: - - /* enqueue back to free_recv_queue */ - rtw_free_recvframe(precv_frame, pfree_recv_queue); - - return _FAIL; -} - -static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced) -{ - struct list_head *phead, *plist; - union recv_frame *prframe; - struct rx_pkt_attrib *pattrib; - /* u8 index = 0; */ - int bPktInBuf = false; - struct recv_priv *precvpriv = &padapter->recvpriv; - struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; - - /* spin_lock_irqsave(&ppending_recvframe_queue->lock, irql); */ - /* spin_lock(&ppending_recvframe_queue->lock); */ - - phead = get_list_head(ppending_recvframe_queue); - plist = get_next(phead); - - /* Handling some condition for forced indicate case. */ - if (bforced) { - if (list_empty(phead)) { - /* spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); */ - /* spin_unlock(&ppending_recvframe_queue->lock); */ - return true; - } - - prframe = (union recv_frame *)plist; - pattrib = &prframe->u.hdr.attrib; - - preorder_ctrl->indicate_seq = pattrib->seq_num; - } - - /* Prepare indication list and indication. */ - /* Check if there is any packet need indicate. */ - while (!list_empty(phead)) { - prframe = (union recv_frame *)plist; - pattrib = &prframe->u.hdr.attrib; - - if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) { - plist = get_next(plist); - list_del_init(&(prframe->u.hdr.list)); - - if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num)) - preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) % 4096u; - - /* Set this as a lock to make sure that only one thread is indicating packet. */ - /* pTS->RxIndicateState = RXTS_INDICATE_PROCESSING; */ - - /* Indicate packets */ - - /* indicate this recv_frame */ - if (!pattrib->amsdu) { - if (!padapter->driver_stopped && - !padapter->bSurpriseRemoved) - rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */ - - } else if (pattrib->amsdu == 1) { - if (amsdu_to_msdu(padapter, prframe) != _SUCCESS) - rtw_free_recvframe(prframe, &precvpriv->free_recv_queue); - - } else { - /* error condition; */ - } - - /* Update local variables. */ - bPktInBuf = false; - - } else { - bPktInBuf = true; - break; - } - } - - /* spin_unlock(&ppending_recvframe_queue->lock); */ - /* spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); */ - - return bPktInBuf; -} - -static int recv_indicatepkt_reorder(struct adapter *padapter, union recv_frame *prframe) -{ - int retval = _SUCCESS; - struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; - struct recv_reorder_ctrl *preorder_ctrl = prframe->u.hdr.preorder_ctrl; - struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; - - if (!pattrib->amsdu) { - /* s1. */ - wlanhdr_to_ethhdr(prframe); - - if (pattrib->qos != 1) { - if (!padapter->driver_stopped && - !padapter->bSurpriseRemoved) { - rtw_recv_indicatepkt(padapter, prframe); - return _SUCCESS; - } - - return _FAIL; - } - - if (!preorder_ctrl->enable) { - /* indicate this recv_frame */ - preorder_ctrl->indicate_seq = pattrib->seq_num; - - rtw_recv_indicatepkt(padapter, prframe); - - preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) % 4096; - - return _SUCCESS; - } - } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */ - if (!preorder_ctrl->enable) { - preorder_ctrl->indicate_seq = pattrib->seq_num; - - retval = amsdu_to_msdu(padapter, prframe); - - preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) % 4096; - - return retval; - } - } - - spin_lock_bh(&ppending_recvframe_queue->lock); - - /* s2. check if winstart_b(indicate_seq) needs to been updated */ - if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) - goto _err_exit; - - /* s3. Insert all packet into Reorder Queue to maintain its ordering. */ - if (!enqueue_reorder_recvframe(preorder_ctrl, prframe)) { - /* spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); */ - /* return _FAIL; */ - goto _err_exit; - } - - /* s4. */ - /* Indication process. */ - /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */ - /* with the SeqNum smaller than latest WinStart and buffer other packets. */ - /* */ - /* For Rx Reorder condition: */ - /* 1. All packets with SeqNum smaller than WinStart => Indicate */ - /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */ - /* */ - - /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */ - if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) { - _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME); - spin_unlock_bh(&ppending_recvframe_queue->lock); - } else { - spin_unlock_bh(&ppending_recvframe_queue->lock); - timer_delete_sync(&preorder_ctrl->reordering_ctrl_timer); - } - - return _SUCCESS; - -_err_exit: - spin_unlock_bh(&ppending_recvframe_queue->lock); - - return _FAIL; -} - -void rtw_reordering_ctrl_timeout_handler(struct timer_list *t) -{ - struct recv_reorder_ctrl *preorder_ctrl = - timer_container_of(preorder_ctrl, t, reordering_ctrl_timer); - struct adapter *padapter = preorder_ctrl->padapter; - struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; - - if (padapter->driver_stopped || padapter->bSurpriseRemoved) - return; - - spin_lock_bh(&ppending_recvframe_queue->lock); - - if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true)) - _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME); - - spin_unlock_bh(&ppending_recvframe_queue->lock); -} - -static int process_recv_indicatepkts(struct adapter *padapter, union recv_frame *prframe) -{ - int retval = _SUCCESS; - /* struct recv_priv *precvpriv = &padapter->recvpriv; */ - /* struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; */ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - - if (phtpriv->ht_option) { /* B/G/N Mode */ - /* prframe->u.hdr.preorder_ctrl = &precvpriv->recvreorder_ctrl[pattrib->priority]; */ - - if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) { /* including perform A-MPDU Rx Ordering Buffer Control */ - - if (!padapter->driver_stopped && - !padapter->bSurpriseRemoved) { - retval = _FAIL; - return retval; - } - } - } else { /* B/G mode */ - retval = wlanhdr_to_ethhdr(prframe); - if (retval != _SUCCESS) - return retval; - - if (!padapter->driver_stopped && !padapter->bSurpriseRemoved) { - /* indicate this recv_frame */ - rtw_recv_indicatepkt(padapter, prframe); - } else { - retval = _FAIL; - return retval; - } - } - - return retval; -} - -static int recv_func_prehandle(struct adapter *padapter, union recv_frame *rframe) -{ - int ret = _SUCCESS; - struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue; - - /* check the frame crtl field and decache */ - ret = validate_recv_frame(padapter, rframe); - if (ret != _SUCCESS) { - rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */ - goto exit; - } - -exit: - return ret; -} - -static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prframe) -{ - int ret = _SUCCESS; - union recv_frame *orig_prframe = prframe; - struct recv_priv *precvpriv = &padapter->recvpriv; - struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue; - - prframe = decryptor(padapter, prframe); - if (!prframe) { - ret = _FAIL; - goto _recv_data_drop; - } - - prframe = recvframe_chk_defrag(padapter, prframe); - if (!prframe) - goto _recv_data_drop; - - prframe = portctrl(padapter, prframe); - if (!prframe) { - ret = _FAIL; - goto _recv_data_drop; - } - - count_rx_stats(padapter, prframe, NULL); - - ret = process_recv_indicatepkts(padapter, prframe); - if (ret != _SUCCESS) { - rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */ - goto _recv_data_drop; - } - -_recv_data_drop: - precvpriv->rx_drop++; - return ret; -} - -static int recv_func(struct adapter *padapter, union recv_frame *rframe) -{ - int ret; - struct rx_pkt_attrib *prxattrib = &rframe->u.hdr.attrib; - struct recv_priv *recvpriv = &padapter->recvpriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct mlme_priv *mlmepriv = &padapter->mlmepriv; - - /* check if need to handle uc_swdec_pending_queue*/ - if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) { - union recv_frame *pending_frame; - - while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) - recv_func_posthandle(padapter, pending_frame); - } - - ret = recv_func_prehandle(padapter, rframe); - - if (ret == _SUCCESS) { - /* check if need to enqueue into uc_swdec_pending_queue*/ - if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && - !is_multicast_ether_addr(prxattrib->ra) && - prxattrib->encrypt > 0 && - (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) && - psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPAPSK && - !psecuritypriv->busetkipkey) { - rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue); - - if (recvpriv->free_recvframe_cnt < NR_RECVFRAME / 4) { - /* to prevent from recvframe starvation, get recvframe from uc_swdec_pending_queue to free_recvframe_cnt */ - rframe = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue); - if (rframe) - goto do_posthandle; - } - goto exit; - } - -do_posthandle: - ret = recv_func_posthandle(padapter, rframe); - } - -exit: - return ret; -} - -s32 rtw_recv_entry(union recv_frame *precvframe) -{ - struct adapter *padapter; - struct recv_priv *precvpriv; - s32 ret = _SUCCESS; - - padapter = precvframe->u.hdr.adapter; - - precvpriv = &padapter->recvpriv; - - ret = recv_func(padapter, precvframe); - if (ret == _FAIL) - goto _recv_entry_drop; - - precvpriv->rx_pkts++; - - return ret; - -_recv_entry_drop: - - return ret; -} - -static void rtw_signal_stat_timer_hdl(struct timer_list *t) -{ - struct adapter *adapter = - timer_container_of(adapter, t, recvpriv.signal_stat_timer); - struct recv_priv *recvpriv = &adapter->recvpriv; - - u32 tmp_s, tmp_q; - u8 avg_signal_strength = 0; - u8 avg_signal_qual = 0; - u32 num_signal_strength = 0; - u32 __maybe_unused num_signal_qual = 0; - u8 _alpha = 5; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */ - - if (adapter->recvpriv.is_signal_dbg) { - /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */ - adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg; - adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg); - } else { - if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */ - avg_signal_strength = recvpriv->signal_strength_data.avg_val; - num_signal_strength = recvpriv->signal_strength_data.total_num; - /* after avg_vals are acquired, we can re-stat the signal values */ - recvpriv->signal_strength_data.update_req = 1; - } - - if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */ - avg_signal_qual = recvpriv->signal_qual_data.avg_val; - num_signal_qual = recvpriv->signal_qual_data.total_num; - /* after avg_vals are acquired, we can re-stat the signal values */ - recvpriv->signal_qual_data.update_req = 1; - } - - if (num_signal_strength == 0) { - if (rtw_get_on_cur_ch_time(adapter) == 0 || - jiffies_to_msecs(jiffies - rtw_get_on_cur_ch_time(adapter)) < 2 * adapter->mlmeextpriv.mlmext_info.bcn_interval - ) { - goto set_timer; - } - } - - if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) || - !check_fwstate(&adapter->mlmepriv, _FW_LINKED) - ) { - goto set_timer; - } - - /* update value of signal_strength, rssi, signal_qual */ - tmp_s = (avg_signal_strength + (_alpha - 1) * recvpriv->signal_strength); - if (tmp_s % _alpha) - tmp_s = tmp_s / _alpha + 1; - else - tmp_s = tmp_s / _alpha; - if (tmp_s > 100) - tmp_s = 100; - - tmp_q = (avg_signal_qual + (_alpha - 1) * recvpriv->signal_qual); - if (tmp_q % _alpha) - tmp_q = tmp_q / _alpha + 1; - else - tmp_q = tmp_q / _alpha; - if (tmp_q > 100) - tmp_q = 100; - - recvpriv->signal_strength = tmp_s; - recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s); - recvpriv->signal_qual = tmp_q; - } - -set_timer: - rtw_set_signal_stat_timer(recvpriv); -} diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c deleted file mode 100644 index 2217cffac5f2..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_security.c +++ /dev/null @@ -1,1470 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include -#include -#include -#include - -static const char * const _security_type_str[] = { - "N/A", - "WEP40", - "TKIP", - "TKIP_WM", - "AES", - "WEP104", - "SMS4", - "WEP_WPA", - "BIP", -}; - -const char *security_type_str(u8 value) -{ - if (value <= _BIP_) - return _security_type_str[value]; - return NULL; -} - -/* WEP related ===== */ - -/* Need to consider the fragment situation */ -void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) -{ /* exclude ICV */ - union { - __le32 f0; - unsigned char f1[4]; - } crc; - - signed int curfragnum, length; - u32 keylength; - - u8 *pframe, *payload, *iv; /* wepkey */ - u8 wepkey[16]; - u8 hw_hdr_offset = 0; - struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct arc4_ctx *ctx = &psecuritypriv->xmit_arc4_ctx; - - if (!((struct xmit_frame *)pxmitframe)->buf_addr) - return; - - hw_hdr_offset = TXDESC_OFFSET; - pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset; - - /* start to encrypt each fragment */ - if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { - keylength = psecuritypriv->dot11DefKeylen[psecuritypriv->dot11PrivacyKeyIndex]; - - for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { - iv = pframe + pattrib->hdrlen; - memcpy(&wepkey[0], iv, 3); - memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength); - payload = pframe + pattrib->iv_len + pattrib->hdrlen; - - if ((curfragnum + 1) == pattrib->nr_frags) { /* the last fragment */ - - length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - - crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length)); - - arc4_setkey(ctx, wepkey, 3 + keylength); - arc4_crypt(ctx, payload, payload, length); - arc4_crypt(ctx, payload + length, crc.f1, 4); - - } else { - length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length)); - arc4_setkey(ctx, wepkey, 3 + keylength); - arc4_crypt(ctx, payload, payload, length); - arc4_crypt(ctx, payload + length, crc.f1, 4); - - pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4); - } - } - } -} - -void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) -{ - /* exclude ICV */ - u8 crc[4]; - signed int length; - u32 keylength; - u8 *pframe, *payload, *iv, wepkey[16]; - u8 keyindex; - struct rx_pkt_attrib *prxattrib = &(((union recv_frame *)precvframe)->u.hdr.attrib); - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct arc4_ctx *ctx = &psecuritypriv->recv_arc4_ctx; - - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; - - /* start to decrypt recvframe */ - if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) { - iv = pframe + prxattrib->hdrlen; - /* keyindex =(iv[3]&0x3); */ - keyindex = prxattrib->key_index; - keylength = psecuritypriv->dot11DefKeylen[keyindex]; - memcpy(&wepkey[0], iv, 3); - /* memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength); */ - memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength); - length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len; - - payload = pframe + prxattrib->iv_len + prxattrib->hdrlen; - - /* decrypt payload include icv */ - arc4_setkey(ctx, wepkey, 3 + keylength); - arc4_crypt(ctx, payload, payload, length); - - /* calculate icv and compare the icv */ - *((u32 *)crc) = ~crc32_le(~0, payload, length - 4); - } -} - -/* 3 =====TKIP related ===== */ - -static void secmicclear(struct mic_data *pmicdata) -{ -/* Reset the state to the empty message. */ - pmicdata->L = pmicdata->K0; - pmicdata->R = pmicdata->K1; - pmicdata->nBytesInM = 0; - pmicdata->M = 0; -} - -void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key) -{ - /* Set the key */ - pmicdata->K0 = get_unaligned_le32(key); - pmicdata->K1 = get_unaligned_le32(key + 4); - /* and reset the message */ - secmicclear(pmicdata); -} - -void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b) -{ - /* Append the byte to our word-sized buffer */ - pmicdata->M |= ((unsigned long)b) << (8 * pmicdata->nBytesInM); - pmicdata->nBytesInM++; - /* Process the word if it is full. */ - if (pmicdata->nBytesInM >= 4) { - pmicdata->L ^= pmicdata->M; - pmicdata->R ^= ROL32(pmicdata->L, 17); - pmicdata->L += pmicdata->R; - pmicdata->R ^= ((pmicdata->L & 0xff00ff00) >> 8) | ((pmicdata->L & 0x00ff00ff) << 8); - pmicdata->L += pmicdata->R; - pmicdata->R ^= ROL32(pmicdata->L, 3); - pmicdata->L += pmicdata->R; - pmicdata->R ^= ROR32(pmicdata->L, 2); - pmicdata->L += pmicdata->R; - /* Clear the buffer */ - pmicdata->M = 0; - pmicdata->nBytesInM = 0; - } -} - -void rtw_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nbytes) -{ - /* This is simple */ - while (nbytes > 0) { - rtw_secmicappendbyte(pmicdata, *src++); - nbytes--; - } -} - -void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst) -{ - /* Append the minimum padding */ - rtw_secmicappendbyte(pmicdata, 0x5a); - rtw_secmicappendbyte(pmicdata, 0); - rtw_secmicappendbyte(pmicdata, 0); - rtw_secmicappendbyte(pmicdata, 0); - rtw_secmicappendbyte(pmicdata, 0); - /* and then zeroes until the length is a multiple of 4 */ - while (pmicdata->nBytesInM != 0) - rtw_secmicappendbyte(pmicdata, 0); - /* The appendByte function has already computed the result. */ - put_unaligned_le32(pmicdata->L, dst); - put_unaligned_le32(pmicdata->R, dst + 4); - /* Reset to the empty message. */ - secmicclear(pmicdata); -} - -void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len, u8 *mic_code, u8 pri) -{ - struct mic_data micdata; - u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; - - rtw_secmicsetkey(&micdata, key); - priority[0] = pri; - - /* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */ - if (header[1] & 1) { /* ToDS == 1 */ - rtw_secmicappend(&micdata, &header[16], 6); /* DA */ - if (header[1] & 2) /* From Ds == 1 */ - rtw_secmicappend(&micdata, &header[24], 6); - else - rtw_secmicappend(&micdata, &header[10], 6); - } else { /* ToDS == 0 */ - rtw_secmicappend(&micdata, &header[4], 6); /* DA */ - if (header[1] & 2) /* From Ds == 1 */ - rtw_secmicappend(&micdata, &header[16], 6); - else - rtw_secmicappend(&micdata, &header[10], 6); - } - rtw_secmicappend(&micdata, &priority[0], 4); - - rtw_secmicappend(&micdata, data, data_len); - - rtw_secgetmic(&micdata, mic_code); -} - -/* macros for extraction/creation of unsigned char/unsigned short values */ -#define Lo8(v16) ((u8)((v16) & 0x00FF)) -#define Hi8(v16) ((u8)(((v16) >> 8) & 0x00FF)) -#define Lo16(v32) ((u16)((v32) & 0xFFFF)) -#define Hi16(v32) ((u16)(((v32) >> 16) & 0xFFFF)) -#define Mk16(hi, lo) ((lo) ^ (((u16)(hi)) << 8)) - -/* select the Nth 16-bit word of the temporal key unsigned char array TK[] */ -#define TK16(N) Mk16(tk[2 * (N) + 1], tk[2 * (N)]) - -/* S-box lookup: 16 bits --> 16 bits */ -#define _S_(v16) (Sbox1[0][Lo8(v16)] ^ Sbox1[1][Hi8(v16)]) - -/* fixed algorithm "parameters" */ -#define PHASE1_LOOP_CNT 8 /* this needs to be "big enough" */ - -/* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */ -static const unsigned short Sbox1[2][256] = { /* Sbox for hash (can be in ROM) */ -{ - 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154, - 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A, - 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B, - 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B, - 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F, - 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F, - 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5, - 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F, - 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB, - 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397, - 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED, - 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A, - 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194, - 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3, - 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104, - 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D, - 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39, - 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695, - 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83, - 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76, - 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4, - 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B, - 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0, - 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018, - 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751, - 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85, - 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12, - 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9, - 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7, - 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A, - 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8, - 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A, - }, - - { /* second half of table is unsigned char-reversed version of first! */ - 0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491, - 0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC, - 0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB, - 0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B, - 0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83, - 0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A, - 0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F, - 0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA, - 0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B, - 0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713, - 0xF5A6, 0x68B9, 0x0000, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6, - 0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85, - 0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411, - 0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B, - 0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1, - 0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF, - 0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E, - 0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6, - 0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B, - 0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD, - 0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8, - 0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2, - 0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049, - 0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810, - 0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438, 0xF157, 0xC773, 0x5197, - 0x23CB, 0x7CA1, 0x9CE8, 0x213E, 0xDD96, 0xDC61, 0x860D, 0x850F, - 0x90E0, 0x427C, 0xC471, 0xAACC, 0xD890, 0x0506, 0x01F7, 0x121C, - 0xA3C2, 0x5F6A, 0xF9AE, 0xD069, 0x9117, 0x5899, 0x273A, 0xB927, - 0x38D9, 0x13EB, 0xB32B, 0x3322, 0xBBD2, 0x70A9, 0x8907, 0xA733, - 0xB62D, 0x223C, 0x9215, 0x20C9, 0x4987, 0xFFAA, 0x7850, 0x7AA5, - 0x8F03, 0xF859, 0x8009, 0x171A, 0xDA65, 0x31D7, 0xC684, 0xB8D0, - 0xC382, 0xB029, 0x775A, 0x111E, 0xCB7B, 0xFCA8, 0xD66D, 0x3A2C, - } -}; - -/* - * Routine: Phase 1 -- generate P1K, given TA, TK, IV32 - * - * Inputs: - * tk[] = temporal key [128 bits] - * ta[] = transmitter's MAC address [ 48 bits] - * iv32 = upper 32 bits of IV [ 32 bits] - * Output: - * p1k[] = Phase 1 key [ 80 bits] - * - * Note: - * This function only needs to be called every 2**16 packets, - * although in theory it could be called every packet. - */ -static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, u32 iv32) -{ - signed int i; - - /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */ - p1k[0] = Lo16(iv32); - p1k[1] = Hi16(iv32); - p1k[2] = Mk16(ta[1], ta[0]); /* use TA[] as little-endian */ - p1k[3] = Mk16(ta[3], ta[2]); - p1k[4] = Mk16(ta[5], ta[4]); - - /* Now compute an unbalanced Feistel cipher with 80-bit block */ - /* size on the 80-bit block P1K[], using the 128-bit key TK[] */ - for (i = 0; i < PHASE1_LOOP_CNT; i++) { - /* Each add operation here is mod 2**16 */ - p1k[0] += _S_(p1k[4] ^ TK16((i & 1) + 0)); - p1k[1] += _S_(p1k[0] ^ TK16((i & 1) + 2)); - p1k[2] += _S_(p1k[1] ^ TK16((i & 1) + 4)); - p1k[3] += _S_(p1k[2] ^ TK16((i & 1) + 6)); - p1k[4] += _S_(p1k[3] ^ TK16((i & 1) + 0)); - p1k[4] += (unsigned short)i; /* avoid "slide attacks" */ - } -} - -/* - * Routine: Phase 2 -- generate RC4KEY, given TK, P1K, IV16 - * - * Inputs: - * tk[] = Temporal key [128 bits] - * p1k[] = Phase 1 output key [ 80 bits] - * iv16 = low 16 bits of IV counter [ 16 bits] - * Output: - * rc4key[] = the key used to encrypt the packet [128 bits] - * - * Note: - * The value {TA, IV32, IV16} for Phase1/Phase2 must be unique - * across all packets using the same key TK value. Then, for a - * given value of TK[], this TKIP48 construction guarantees that - * the final RC4KEY value is unique across all packets. - * - * Suggested implementation optimization: if PPK[] is "overlaid" - * appropriately on RC4KEY[], there is no need for the final - * for loop below that copies the PPK[] result into RC4KEY[]. - */ -static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16) -{ - signed int i; - u16 PPK[6]; /* temporary key for mixing */ - - /* Note: all adds in the PPK[] equations below are mod 2**16 */ - for (i = 0; i < 5; i++) - PPK[i] = p1k[i]; /* first, copy P1K to PPK */ - - PPK[5] = p1k[4] + iv16; /* next, add in IV16 */ - - /* Bijective non-linear mixing of the 96 bits of PPK[0..5] */ - PPK[0] += _S_(PPK[5] ^ TK16(0)); /* Mix key in each "round" */ - PPK[1] += _S_(PPK[0] ^ TK16(1)); - PPK[2] += _S_(PPK[1] ^ TK16(2)); - PPK[3] += _S_(PPK[2] ^ TK16(3)); - PPK[4] += _S_(PPK[3] ^ TK16(4)); - PPK[5] += _S_(PPK[4] ^ TK16(5)); /* Total # S-box lookups == 6 */ - - /* Final sweep: bijective, "linear". Rotates kill LSB correlations */ - PPK[0] += ror16(PPK[5] ^ TK16(6), 1); - PPK[1] += ror16(PPK[0] ^ TK16(7), 1); /* Use all of TK[] in Phase2 */ - PPK[2] += ror16(PPK[1], 1); - PPK[3] += ror16(PPK[2], 1); - PPK[4] += ror16(PPK[3], 1); - PPK[5] += ror16(PPK[4], 1); - /* Note: At this point, for a given key TK[0..15], the 96-bit output */ - /* value PPK[0..5] is guaranteed to be unique, as a function */ - /* of the 96-bit "input" value {TA, IV32, IV16}. That is, P1K */ - /* is now a keyed permutation of {TA, IV32, IV16}. */ - - /* Set RC4KEY[0..3], which includes "cleartext" portion of RC4 key */ - rc4key[0] = Hi8(iv16); /* RC4KEY[0..2] is the WEP IV */ - rc4key[1] = (Hi8(iv16) | 0x20) & 0x7F; /* Help avoid weak (FMS) keys */ - rc4key[2] = Lo8(iv16); - rc4key[3] = Lo8((PPK[5] ^ TK16(0)) >> 1); - - /* Copy 96 bits of PPK[0..5] to RC4KEY[4..15] (little-endian) */ - for (i = 0; i < 6; i++) { - rc4key[4 + 2 * i] = Lo8(PPK[i]); - rc4key[5 + 2 * i] = Hi8(PPK[i]); - } -} - -/* The hlen isn't include the IV */ -u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe) -{ /* exclude ICV */ - u16 pnl; - u32 pnh; - u8 rc4key[16]; - u8 ttkey[16]; - union { - __le32 f0; - u8 f1[4]; - } crc; - u8 hw_hdr_offset = 0; - signed int curfragnum, length; - - u8 *pframe, *payload, *iv, *prwskey; - union pn48 dot11txpn; - struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct arc4_ctx *ctx = &psecuritypriv->xmit_arc4_ctx; - u32 res = _SUCCESS; - - if (!((struct xmit_frame *)pxmitframe)->buf_addr) - return _FAIL; - - hw_hdr_offset = TXDESC_OFFSET; - pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset; - - /* 4 start to encrypt each fragment */ - if (pattrib->encrypt != _TKIP_) - return _SUCCESS; - - if (is_multicast_ether_addr(pattrib->ra)) - prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey; - else - prwskey = pattrib->dot118021x_UncstKey.skey; - - for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { - iv = pframe + pattrib->hdrlen; - payload = pframe + pattrib->iv_len + pattrib->hdrlen; - - GET_TKIP_PN(iv, dot11txpn); - - pnl = (u16)(dot11txpn.val); - pnh = (u32)(dot11txpn.val >> 16); - - phase1((u16 *)&ttkey[0], prwskey, &pattrib->ta[0], pnh); - - phase2(&rc4key[0], prwskey, (u16 *)&ttkey[0], pnl); - - if ((curfragnum + 1) == pattrib->nr_frags) { /* 4 the last fragment */ - length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length)); - - arc4_setkey(ctx, rc4key, 16); - arc4_crypt(ctx, payload, payload, length); - arc4_crypt(ctx, payload + length, crc.f1, 4); - - } else { - length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length)); - - arc4_setkey(ctx, rc4key, 16); - arc4_crypt(ctx, payload, payload, length); - arc4_crypt(ctx, payload + length, crc.f1, 4); - - pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4); - } - } - return res; -} - -/* The hlen isn't include the IV */ -u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe) -{ /* exclude ICV */ - u16 pnl; - u32 pnh; - u8 rc4key[16]; - u8 ttkey[16]; - u8 crc[4]; - signed int length; - - u8 *pframe, *payload, *iv, *prwskey; - union pn48 dot11txpn; - struct sta_info *stainfo; - struct rx_pkt_attrib *prxattrib = &((union recv_frame *)precvframe)->u.hdr.attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct arc4_ctx *ctx = &psecuritypriv->recv_arc4_ctx; - u32 res = _SUCCESS; - - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; - - /* 4 start to decrypt recvframe */ - if (prxattrib->encrypt != _TKIP_) - return _SUCCESS; - - stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); - if (!stainfo) - return _FAIL; - - if (is_multicast_ether_addr(prxattrib->ra)) { - static unsigned long start; - static u32 no_gkey_bc_cnt; - static u32 no_gkey_mc_cnt; - - if (!psecuritypriv->binstallGrpkey) { - res = _FAIL; - - if (start == 0) - start = jiffies; - - if (is_broadcast_ether_addr(prxattrib->ra)) - no_gkey_bc_cnt++; - else - no_gkey_mc_cnt++; - - if (jiffies_to_msecs(jiffies - start) > 1000) { - if (no_gkey_bc_cnt || no_gkey_mc_cnt) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n", - FUNC_ADPT_ARG(padapter), - no_gkey_bc_cnt, - no_gkey_mc_cnt); - } - start = jiffies; - no_gkey_bc_cnt = 0; - no_gkey_mc_cnt = 0; - } - goto exit; - } - - if (no_gkey_bc_cnt || no_gkey_mc_cnt) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " gkey installed. no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n", - FUNC_ADPT_ARG(padapter), - no_gkey_bc_cnt, - no_gkey_mc_cnt); - } - start = 0; - no_gkey_bc_cnt = 0; - no_gkey_mc_cnt = 0; - - prwskey = psecuritypriv->dot118021XGrpKey[prxattrib->key_index].skey; - } else { - prwskey = &stainfo->dot118021x_UncstKey.skey[0]; - } - - iv = pframe + prxattrib->hdrlen; - payload = pframe + prxattrib->iv_len + prxattrib->hdrlen; - length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len; - - GET_TKIP_PN(iv, dot11txpn); - - pnl = (u16)(dot11txpn.val); - pnh = (u32)(dot11txpn.val >> 16); - - phase1((u16 *)&ttkey[0], prwskey, &prxattrib->ta[0], pnh); - phase2(&rc4key[0], prwskey, (unsigned short *)&ttkey[0], pnl); - - /* 4 decrypt payload include icv */ - - arc4_setkey(ctx, rc4key, 16); - arc4_crypt(ctx, payload, payload, length); - - *((u32 *)crc) = ~crc32_le(~0, payload, length - 4); - - if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || - crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) - res = _FAIL; -exit: - return res; -} - -/* 3 =====AES related ===== */ - -#define MAX_MSG_SIZE 2048 - -/****************************************/ -/* aes128k128d() */ -/* Performs a 128 bit AES encrypt with */ -/* 128 bit data. */ -/****************************************/ -static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext) -{ - struct aes_enckey aes; - - aes_prepareenckey(&aes, key, 16); - aes_encrypt(&aes, ciphertext, data); - memzero_explicit(&aes, sizeof(aes)); -} - -/************************************************/ -/* construct_mic_iv() */ -/* Builds the MIC IV from header fields and PN */ -/* Baron think the function is construct CCM */ -/* nonce */ -/************************************************/ -static void construct_mic_iv(u8 *mic_iv, - signed int qc_exists, - signed int a4_exists, - u8 *mpdu, - uint payload_length, - u8 *pn_vector, - uint frtype) -{ - signed int i; - - mic_iv[0] = 0x59; - - if (qc_exists && a4_exists) - mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */ - - if (qc_exists && !a4_exists) - mic_iv[1] = mpdu[24] & 0x0f; /* mute bits 7-4 */ - - if (!qc_exists) - mic_iv[1] = 0x00; - - /* 802.11w management frame should set management bit(4) */ - if (frtype == WIFI_MGT_TYPE) - mic_iv[1] |= BIT(4); - - for (i = 2; i < 8; i++) - mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */ - for (i = 8; i < 14; i++) - mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */ - mic_iv[14] = (unsigned char)(payload_length / 256); - mic_iv[15] = (unsigned char)(payload_length % 256); -} - -/************************************************/ -/* construct_mic_header1() */ -/* Builds the first MIC header block from */ -/* header fields. */ -/* Build AAD SC, A1, A2 */ -/************************************************/ -static void construct_mic_header1(u8 *mic_header1, - signed int header_length, - u8 *mpdu, - uint frtype) -{ - mic_header1[0] = (u8)((header_length - 2) / 256); - mic_header1[1] = (u8)((header_length - 2) % 256); - - /* 802.11w management frame don't AND subtype bits 4, 5, 6 of frame control field */ - if (frtype == WIFI_MGT_TYPE) - mic_header1[2] = mpdu[0]; - else - mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */ - - mic_header1[3] = mpdu[1] & 0xc7; /* Mute retry, more data and pwr mgt bits */ - mic_header1[4] = mpdu[4]; /* A1 */ - mic_header1[5] = mpdu[5]; - mic_header1[6] = mpdu[6]; - mic_header1[7] = mpdu[7]; - mic_header1[8] = mpdu[8]; - mic_header1[9] = mpdu[9]; - mic_header1[10] = mpdu[10]; /* A2 */ - mic_header1[11] = mpdu[11]; - mic_header1[12] = mpdu[12]; - mic_header1[13] = mpdu[13]; - mic_header1[14] = mpdu[14]; - mic_header1[15] = mpdu[15]; -} - -/************************************************/ -/* construct_mic_header2() */ -/* Builds the last MIC header block from */ -/* header fields. */ -/************************************************/ -static void construct_mic_header2(u8 *mic_header2, - u8 *mpdu, - signed int a4_exists, - signed int qc_exists) -{ - signed int i; - - for (i = 0; i < 16; i++) - mic_header2[i] = 0x00; - - mic_header2[0] = mpdu[16]; /* A3 */ - mic_header2[1] = mpdu[17]; - mic_header2[2] = mpdu[18]; - mic_header2[3] = mpdu[19]; - mic_header2[4] = mpdu[20]; - mic_header2[5] = mpdu[21]; - - mic_header2[6] = 0x00; - mic_header2[7] = 0x00; /* mpdu[23]; */ - - if (!qc_exists && a4_exists) { - for (i = 0; i < 6; i++) - mic_header2[8 + i] = mpdu[24 + i]; /* A4 */ - } - - if (qc_exists && !a4_exists) { - mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */ - mic_header2[9] = mpdu[25] & 0x00; - } - - if (qc_exists && a4_exists) { - for (i = 0; i < 6; i++) - mic_header2[8 + i] = mpdu[24 + i]; /* A4 */ - - mic_header2[14] = mpdu[30] & 0x0f; - mic_header2[15] = mpdu[31] & 0x00; - } -} - -/************************************************/ -/* construct_mic_header2() */ -/* Builds the last MIC header block from */ -/* header fields. */ -/* Baron think the function is construct CCM */ -/* nonce */ -/************************************************/ -static void construct_ctr_preload(u8 *ctr_preload, - signed int a4_exists, - signed int qc_exists, - u8 *mpdu, - u8 *pn_vector, - signed int c, - uint frtype) -{ - signed int i = 0; - - for (i = 0; i < 16; i++) - ctr_preload[i] = 0x00; - i = 0; - - ctr_preload[0] = 0x01; /* flag */ - if (qc_exists && a4_exists) - ctr_preload[1] = mpdu[30] & 0x0f; /* QoC_Control */ - if (qc_exists && !a4_exists) - ctr_preload[1] = mpdu[24] & 0x0f; - - /* 802.11w management frame should set management bit(4) */ - if (frtype == WIFI_MGT_TYPE) - ctr_preload[1] |= BIT(4); - - for (i = 2; i < 8; i++) - ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */ - for (i = 8; i < 14; i++) - ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */ - ctr_preload[14] = (unsigned char)(c / 256); /* Ctr */ - ctr_preload[15] = (unsigned char)(c % 256); -} - -static signed int aes_cipher(u8 *key, uint hdrlen, - u8 *pframe, uint plen) -{ - uint qc_exists, a4_exists, i, j, payload_remainder, - num_blocks, payload_index; - - u8 pn_vector[6]; - u8 mic_iv[16] = {}; - u8 mic_header1[16] = {}; - u8 mic_header2[16] = {}; - u8 ctr_preload[16] = {}; - - /* Intermediate Buffers */ - u8 chain_buffer[16] = {}; - u8 aes_out[16] = {}; - u8 padded_buffer[16] = {}; - u8 mic[8]; - uint frtype = GetFrameType(pframe); - uint frsubtype = GetFrameSubType(pframe); - - frsubtype = frsubtype >> 4; - - if ((hdrlen == WLAN_HDR_A3_LEN) || (hdrlen == WLAN_HDR_A3_QOS_LEN)) - a4_exists = 0; - else - a4_exists = 1; - - if (((frtype | frsubtype) == WIFI_DATA_CFACK) || - ((frtype | frsubtype) == WIFI_DATA_CFPOLL) || - ((frtype | frsubtype) == WIFI_DATA_CFACKPOLL)) { - qc_exists = 1; - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - - } else if ((frtype == WIFI_DATA) && - ((frsubtype == 0x08) || - (frsubtype == 0x09) || - (frsubtype == 0x0a) || - (frsubtype == 0x0b))) { - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - - qc_exists = 1; - } else { - qc_exists = 0; - } - - pn_vector[0] = pframe[hdrlen]; - pn_vector[1] = pframe[hdrlen + 1]; - pn_vector[2] = pframe[hdrlen + 4]; - pn_vector[3] = pframe[hdrlen + 5]; - pn_vector[4] = pframe[hdrlen + 6]; - pn_vector[5] = pframe[hdrlen + 7]; - - construct_mic_iv(mic_iv, - qc_exists, - a4_exists, - pframe, /* message, */ - plen, - pn_vector, - frtype); - - construct_mic_header1(mic_header1, - hdrlen, - pframe, /* message */ - frtype); - - construct_mic_header2(mic_header2, - pframe, /* message, */ - a4_exists, - qc_exists); - - payload_remainder = plen % 16; - num_blocks = plen / 16; - - /* Find start of payload */ - payload_index = (hdrlen + 8); - - /* Calculate MIC */ - aes128k128d(key, mic_iv, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, mic_header1, 16); - aes128k128d(key, chain_buffer, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, mic_header2, 16); - aes128k128d(key, chain_buffer, aes_out); - - for (i = 0; i < num_blocks; i++) { - crypto_xor_cpy(chain_buffer, aes_out, &pframe[payload_index], 16); - - payload_index += 16; - aes128k128d(key, chain_buffer, aes_out); - } - - /* Add on the final payload block if it needs padding */ - if (payload_remainder > 0) { - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < payload_remainder; j++) - padded_buffer[j] = pframe[payload_index++]; - - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - aes128k128d(key, chain_buffer, aes_out); - } - - for (j = 0 ; j < 8; j++) - mic[j] = aes_out[j]; - - /* Insert MIC into payload */ - for (j = 0; j < 8; j++) - pframe[payload_index + j] = mic[j]; - - payload_index = hdrlen + 8; - for (i = 0; i < num_blocks; i++) { - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, /* message, */ - pn_vector, i + 1, frtype); - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, &pframe[payload_index], 16); - for (j = 0; j < 16; j++) - pframe[payload_index++] = chain_buffer[j]; - } - - if (payload_remainder > 0) { - /* If there is a short final block, then pad it,*/ - /* encrypt it and copy the unpadded part back */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, /* message, */ - pn_vector, num_blocks + 1, frtype); - - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < payload_remainder; j++) - padded_buffer[j] = pframe[payload_index + j]; - - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - for (j = 0; j < payload_remainder; j++) - pframe[payload_index++] = chain_buffer[j]; - } - - /* Encrypt the MIC */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, /* message, */ - pn_vector, 0, frtype); - - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < 8; j++) - padded_buffer[j] = pframe[j + hdrlen + 8 + plen]; - - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - for (j = 0; j < 8; j++) - pframe[payload_index++] = chain_buffer[j]; - - return _SUCCESS; -} - -u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe) -{ /* exclude ICV */ - - /*static*/ - /* unsigned char message[MAX_MSG_SIZE]; */ - - /* Intermediate Buffers */ - signed int curfragnum, length; - u8 *pframe, *prwskey; /* *payload,*iv */ - u8 hw_hdr_offset = 0; - struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - u32 res = _SUCCESS; - - if (!((struct xmit_frame *)pxmitframe)->buf_addr) - return _FAIL; - - hw_hdr_offset = TXDESC_OFFSET; - pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset; - - /* 4 start to encrypt each fragment */ - if (pattrib->encrypt != _AES_) - return _SUCCESS; - - if (is_multicast_ether_addr(pattrib->ra)) - prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey; - else - prwskey = pattrib->dot118021x_UncstKey.skey; - - for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { - if ((curfragnum + 1) == pattrib->nr_frags) { /* 4 the last fragment */ - length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - - aes_cipher(prwskey, pattrib->hdrlen, pframe, length); - } else { - length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len; - - aes_cipher(prwskey, pattrib->hdrlen, pframe, length); - pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up((SIZE_PTR)(pframe), 4); - } - } - return res; -} - -static signed int aes_decipher(u8 *key, uint hdrlen, - u8 *pframe, uint plen) -{ - static u8 message[MAX_MSG_SIZE]; - uint qc_exists, a4_exists, i, j, payload_remainder, - num_blocks, payload_index; - signed int res = _SUCCESS; - u8 pn_vector[6]; - u8 mic_iv[16] = {}; - u8 mic_header1[16] = {}; - u8 mic_header2[16] = {}; - u8 ctr_preload[16] = {}; - - /* Intermediate Buffers */ - u8 chain_buffer[16] = {}; - u8 aes_out[16] = {}; - u8 padded_buffer[16] = {}; - u8 mic[8]; - - uint frtype = GetFrameType(pframe); - uint frsubtype = GetFrameSubType(pframe); - - frsubtype = frsubtype >> 4; - - /* start to decrypt the payload */ - - num_blocks = (plen - 8) / 16; /* plen including LLC, payload_length and mic) */ - - payload_remainder = (plen - 8) % 16; - - pn_vector[0] = pframe[hdrlen]; - pn_vector[1] = pframe[hdrlen + 1]; - pn_vector[2] = pframe[hdrlen + 4]; - pn_vector[3] = pframe[hdrlen + 5]; - pn_vector[4] = pframe[hdrlen + 6]; - pn_vector[5] = pframe[hdrlen + 7]; - - if ((hdrlen == WLAN_HDR_A3_LEN) || (hdrlen == WLAN_HDR_A3_QOS_LEN)) - a4_exists = 0; - else - a4_exists = 1; - - if (((frtype | frsubtype) == WIFI_DATA_CFACK) || - ((frtype | frsubtype) == WIFI_DATA_CFPOLL) || - ((frtype | frsubtype) == WIFI_DATA_CFACKPOLL)) { - qc_exists = 1; - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - - } else if ((frtype == WIFI_DATA) && - ((frsubtype == 0x08) || - (frsubtype == 0x09) || - (frsubtype == 0x0a) || - (frsubtype == 0x0b))) { - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - - qc_exists = 1; - } else { - qc_exists = 0; - } - - /* now, decrypt pframe with hdrlen offset and plen long */ - - payload_index = hdrlen + 8; /* 8 is for extiv */ - - for (i = 0; i < num_blocks; i++) { - construct_ctr_preload(ctr_preload, a4_exists, - qc_exists, pframe, - pn_vector, i + 1, - frtype); - - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, &pframe[payload_index], 16); - - for (j = 0; j < 16; j++) - pframe[payload_index++] = chain_buffer[j]; - } - - if (payload_remainder > 0) { - /* If there is a short final block, then pad it,*/ - /* encrypt it and copy the unpadded part back */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, pn_vector, - num_blocks + 1, frtype); - - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < payload_remainder; j++) - padded_buffer[j] = pframe[payload_index + j]; - - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - for (j = 0; j < payload_remainder; j++) - pframe[payload_index++] = chain_buffer[j]; - } - - /* start to calculate the mic */ - if ((hdrlen + plen + 8) <= MAX_MSG_SIZE) - memcpy(message, pframe, (hdrlen + plen + 8)); /* 8 is for ext iv len */ - - pn_vector[0] = pframe[hdrlen]; - pn_vector[1] = pframe[hdrlen + 1]; - pn_vector[2] = pframe[hdrlen + 4]; - pn_vector[3] = pframe[hdrlen + 5]; - pn_vector[4] = pframe[hdrlen + 6]; - pn_vector[5] = pframe[hdrlen + 7]; - - construct_mic_iv(mic_iv, qc_exists, a4_exists, message, plen - 8, pn_vector, frtype); - - construct_mic_header1(mic_header1, hdrlen, message, frtype); - construct_mic_header2(mic_header2, message, a4_exists, qc_exists); - - payload_remainder = (plen - 8) % 16; - num_blocks = (plen - 8) / 16; - - /* Find start of payload */ - payload_index = (hdrlen + 8); - - /* Calculate MIC */ - aes128k128d(key, mic_iv, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, mic_header1, 16); - aes128k128d(key, chain_buffer, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, mic_header2, 16); - aes128k128d(key, chain_buffer, aes_out); - - for (i = 0; i < num_blocks; i++) { - crypto_xor_cpy(chain_buffer, aes_out, &message[payload_index], 16); - - payload_index += 16; - aes128k128d(key, chain_buffer, aes_out); - } - - /* Add on the final payload block if it needs padding */ - if (payload_remainder > 0) { - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < payload_remainder; j++) - padded_buffer[j] = message[payload_index++]; - - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - aes128k128d(key, chain_buffer, aes_out); - } - - for (j = 0; j < 8; j++) - mic[j] = aes_out[j]; - - /* Insert MIC into payload */ - for (j = 0; j < 8; j++) - message[payload_index + j] = mic[j]; - - payload_index = hdrlen + 8; - for (i = 0; i < num_blocks; i++) { - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, message, pn_vector, i + 1, - frtype); - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, &message[payload_index], 16); - for (j = 0; j < 16; j++) - message[payload_index++] = chain_buffer[j]; - } - - if (payload_remainder > 0) { - /* If there is a short final block, then pad it,*/ - /* encrypt it and copy the unpadded part back */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, message, pn_vector, - num_blocks + 1, frtype); - - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < payload_remainder; j++) - padded_buffer[j] = message[payload_index + j]; - - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - for (j = 0; j < payload_remainder; j++) - message[payload_index++] = chain_buffer[j]; - } - - /* Encrypt the MIC */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, message, pn_vector, 0, frtype); - - for (j = 0; j < 16; j++) - padded_buffer[j] = 0x00; - for (j = 0; j < 8; j++) - padded_buffer[j] = message[j + hdrlen + 8 + plen - 8]; - - aes128k128d(key, ctr_preload, aes_out); - crypto_xor_cpy(chain_buffer, aes_out, padded_buffer, 16); - for (j = 0; j < 8; j++) - message[payload_index++] = chain_buffer[j]; - - /* compare the mic */ - for (i = 0; i < 8; i++) { - if (pframe[hdrlen + 8 + plen - 8 + i] != message[hdrlen + 8 + plen - 8 + i]) - res = _FAIL; - } - return res; -} - -u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe) -{ /* exclude ICV */ - - /*static*/ - /* unsigned char message[MAX_MSG_SIZE]; */ - - /* Intermediate Buffers */ - - signed int length; - u8 *pframe, *prwskey; /* *payload,*iv */ - struct sta_info *stainfo; - struct rx_pkt_attrib *prxattrib = &((union recv_frame *)precvframe)->u.hdr.attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - u32 res = _SUCCESS; - - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; - /* 4 start to encrypt each fragment */ - if (prxattrib->encrypt != _AES_) - return _SUCCESS; - stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); - if (!stainfo) - return _FAIL; - if (is_multicast_ether_addr(prxattrib->ra)) { - static unsigned long start; - static u32 no_gkey_bc_cnt; - static u32 no_gkey_mc_cnt; - - if (!psecuritypriv->binstallGrpkey) { - res = _FAIL; - - if (start == 0) - start = jiffies; - - if (is_broadcast_ether_addr(prxattrib->ra)) - no_gkey_bc_cnt++; - else - no_gkey_mc_cnt++; - - if (jiffies_to_msecs(jiffies - start) > 1000) { - if (no_gkey_bc_cnt || no_gkey_mc_cnt) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n", - FUNC_ADPT_ARG(padapter), - no_gkey_bc_cnt, - no_gkey_mc_cnt); - } - start = jiffies; - no_gkey_bc_cnt = 0; - no_gkey_mc_cnt = 0; - } - - goto exit; - } - - if (no_gkey_bc_cnt || no_gkey_mc_cnt) { - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " gkey installed. no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n", - FUNC_ADPT_ARG(padapter), - no_gkey_bc_cnt, - no_gkey_mc_cnt); - } - start = 0; - no_gkey_bc_cnt = 0; - no_gkey_mc_cnt = 0; - - prwskey = psecuritypriv->dot118021XGrpKey[prxattrib->key_index].skey; - if (psecuritypriv->dot118021XGrpKeyid != prxattrib->key_index) { - res = _FAIL; - goto exit; - } - } else { - prwskey = &stainfo->dot118021x_UncstKey.skey[0]; - } - - length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len; - - res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length); - -exit: - return res; -} - -u32 rtw_BIP_verify(struct adapter *padapter, u8 *precvframe) -{ - struct rx_pkt_attrib *pattrib = &((union recv_frame *)precvframe)->u.hdr.attrib; - u8 *pframe; - u8 *BIP_AAD, *p; - u32 res = _FAIL; - uint len, ori_len; - struct ieee80211_hdr *pwlanhdr; - u8 mic[16]; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - __le16 le_tmp; - __le64 le_tmp64 = 0; - - ori_len = pattrib->pkt_len - WLAN_HDR_A3_LEN + BIP_AAD_SIZE; - BIP_AAD = kzalloc(ori_len, GFP_KERNEL); - if (!BIP_AAD) - return _FAIL; - - /* PKT start */ - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; - /* mapping to wlan header */ - pwlanhdr = (struct ieee80211_hdr *)pframe; - /* save the frame body + MME */ - memcpy(BIP_AAD + BIP_AAD_SIZE, pframe + WLAN_HDR_A3_LEN, pattrib->pkt_len - WLAN_HDR_A3_LEN); - /* find MME IE pointer */ - p = rtw_get_ie(BIP_AAD + BIP_AAD_SIZE, WLAN_EID_MMIE, &len, pattrib->pkt_len - WLAN_HDR_A3_LEN); - /* Baron */ - if (p) { - u16 keyid = 0; - u64 temp_ipn = 0; - /* save packet number */ - memcpy(&le_tmp64, p + 4, 6); - temp_ipn = le64_to_cpu(le_tmp64); - /* BIP packet number should bigger than previous BIP packet */ - if (temp_ipn <= pmlmeext->mgnt_80211w_IPN_rx) - goto BIP_exit; - - /* copy key index */ - memcpy(&le_tmp, p + 2, 2); - keyid = le16_to_cpu(le_tmp); - if (keyid != padapter->securitypriv.dot11wBIPKeyid) - goto BIP_exit; - - /* clear the MIC field of MME to zero */ - memset(p + 2 + len - 8, 0, 8); - - /* conscruct AAD, copy frame control field */ - memcpy(BIP_AAD, &pwlanhdr->frame_control, 2); - ClearRetry(BIP_AAD); - ClearPwrMgt(BIP_AAD); - ClearMData(BIP_AAD); - /* conscruct AAD, copy address 1 to address 3 */ - memcpy(BIP_AAD + 2, &pwlanhdr->addrs, sizeof(pwlanhdr->addrs)); - - if (omac1_aes_128(padapter->securitypriv.dot11wBIPKey[padapter->securitypriv.dot11wBIPKeyid].skey - , BIP_AAD, ori_len, mic)) - goto BIP_exit; - - /* MIC field should be last 8 bytes of packet (packet without FCS) */ - if (!memcmp(mic, pframe + pattrib->pkt_len - 8, 8)) { - pmlmeext->mgnt_80211w_IPN_rx = temp_ipn; - res = _SUCCESS; - } else { - } - - } else { - res = RTW_RX_HANDLED; - } -BIP_exit: - - kfree(BIP_AAD); - return res; -} - -static void gf_mulx(u8 *pad) -{ - int i, carry; - - carry = pad[0] & 0x80; - for (i = 0; i < AES_BLOCK_SIZE - 1; i++) - pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7); - - pad[AES_BLOCK_SIZE - 1] <<= 1; - if (carry) - pad[AES_BLOCK_SIZE - 1] ^= 0x87; -} - -/** - * omac1_aes_128_vector - One-Key CBC MAC (OMAC1) hash with AES-128 - * @key: 128-bit key for the hash operation - * @num_elem: Number of elements in the data vector - * @addr: Pointers to the data areas - * @len: Lengths of the data blocks - * @mac: Buffer for MAC (128 bits, i.e., 16 bytes) - * Returns: 0 on success, -1 on failure - * - * This is a mode for using block cipher (AES in this case) for authentication. - * OMAC1 was standardized with the name CMAC by NIST in a Special Publication - * (SP) 800-38B. - */ -static int omac1_aes_128_vector(u8 *key, size_t num_elem, - u8 *addr[], size_t *len, u8 *mac) -{ - struct aes_enckey aes; - u8 cbc[AES_BLOCK_SIZE], pad[AES_BLOCK_SIZE]; - u8 *pos, *end; - size_t i, e, left, total_len; - int ret; - - ret = aes_prepareenckey(&aes, key, 16); - if (ret) - return -1; - memset(cbc, 0, AES_BLOCK_SIZE); - - total_len = 0; - for (e = 0; e < num_elem; e++) - total_len += len[e]; - left = total_len; - - e = 0; - pos = addr[0]; - end = pos + len[0]; - - while (left >= AES_BLOCK_SIZE) { - for (i = 0; i < AES_BLOCK_SIZE; i++) { - cbc[i] ^= *pos++; - if (pos >= end) { - e++; - pos = addr[e]; - end = pos + len[e]; - } - } - if (left > AES_BLOCK_SIZE) - aes_encrypt(&aes, cbc, cbc); - left -= AES_BLOCK_SIZE; - } - - memset(pad, 0, AES_BLOCK_SIZE); - aes_encrypt(&aes, pad, pad); - gf_mulx(pad); - - if (left || total_len == 0) { - for (i = 0; i < left; i++) { - cbc[i] ^= *pos++; - if (pos >= end) { - e++; - pos = addr[e]; - end = pos + len[e]; - } - } - cbc[left] ^= 0x80; - gf_mulx(pad); - } - - for (i = 0; i < AES_BLOCK_SIZE; i++) - pad[i] ^= cbc[i]; - aes_encrypt(&aes, pad, mac); - memzero_explicit(&aes, sizeof(aes)); - return 0; -} - -/** - * omac1_aes_128 - One-Key CBC MAC (OMAC1) hash with AES-128 (aka AES-CMAC) - * @key: 128-bit key for the hash operation - * @data: Data buffer for which a MAC is determined - * @data_len: Length of data buffer in bytes - * @mac: Buffer for MAC (128 bits, i.e., 16 bytes) - * Returns: 0 on success, -1 on failure - * - * This is a mode for using block cipher (AES in this case) for authentication. - * OMAC1 was standardized with the name CMAC by NIST in a Special Publication - * (SP) 800-38B. - */ -int omac1_aes_128(u8 *key, u8 *data, size_t data_len, u8 *mac) -{ - return omac1_aes_128_vector(key, 1, &data, &data_len, mac); -} - -/* Restore HW wep key setting according to key_mask */ -void rtw_sec_restore_wep_key(struct adapter *adapter) -{ - struct security_priv *securitypriv = &adapter->securitypriv; - signed int keyid; - - if ((securitypriv->dot11_privacy_algrthm == _WEP40_) || (securitypriv->dot11_privacy_algrthm == _WEP104_)) { - for (keyid = 0; keyid < 4; keyid++) { - if (securitypriv->key_mask & BIT(keyid)) { - if (keyid == securitypriv->dot11PrivacyKeyIndex) - rtw_set_key(adapter, securitypriv, keyid, 1, false); - else - rtw_set_key(adapter, securitypriv, keyid, 0, false); - } - } - } -} - -u8 rtw_handle_tkip_countermeasure(struct adapter *adapter, const char *caller) -{ - struct security_priv *securitypriv = &adapter->securitypriv; - u8 status = _SUCCESS; - - if (securitypriv->btkip_countermeasure) { - unsigned long passing_ms = jiffies_to_msecs(jiffies - securitypriv->btkip_countermeasure_time); - - if (passing_ms > 60 * 1000) { - netdev_dbg(adapter->pnetdev, - "%s(%s) countermeasure time:%lus > 60s\n", - caller, ADPT_ARG(adapter), - passing_ms / 1000); - securitypriv->btkip_countermeasure = false; - securitypriv->btkip_countermeasure_time = 0; - } else { - netdev_dbg(adapter->pnetdev, - "%s(%s) countermeasure time:%lus < 60s\n", - caller, ADPT_ARG(adapter), - passing_ms / 1000); - status = _FAIL; - } - } - - return status; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_sta_mgt.c b/drivers/staging/rtl8723bs/core/rtw_sta_mgt.c deleted file mode 100644 index 6d014bf8fa96..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +++ /dev/null @@ -1,549 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include - -void _rtw_init_stainfo(struct sta_info *psta); -void _rtw_init_stainfo(struct sta_info *psta) -{ - memset((u8 *)psta, 0, sizeof(struct sta_info)); - - spin_lock_init(&psta->lock); - INIT_LIST_HEAD(&psta->list); - INIT_LIST_HEAD(&psta->hash_list); - /* INIT_LIST_HEAD(&psta->asoc_list); */ - /* INIT_LIST_HEAD(&psta->sleep_list); */ - /* INIT_LIST_HEAD(&psta->wakeup_list); */ - - INIT_LIST_HEAD(&psta->sleep_q.queue); - spin_lock_init(&psta->sleep_q.lock); - psta->sleepq_len = 0; - - _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); - _rtw_init_sta_recv_priv(&psta->sta_recvpriv); - - INIT_LIST_HEAD(&psta->asoc_list); - - INIT_LIST_HEAD(&psta->auth_list); - - psta->expire_to = 0; - - psta->flags = 0; - - psta->capability = 0; - - psta->bpairwise_key_installed = false; - - psta->nonerp_set = 0; - psta->no_short_slot_time_set = 0; - psta->no_short_preamble_set = 0; - psta->no_ht_gf_set = 0; - psta->no_ht_set = 0; - psta->ht_20mhz_set = 0; - - psta->under_exist_checking = 0; - - psta->keep_alive_trycnt = 0; -} - -u32 _rtw_init_sta_priv(struct sta_priv *pstapriv) -{ - struct sta_info *psta; - s32 i; - - pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4); - - if (!pstapriv->pallocated_stainfo_buf) - return _FAIL; - - pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 - - ((SIZE_PTR)(pstapriv->pallocated_stainfo_buf) & 3); - - INIT_LIST_HEAD(&pstapriv->free_sta_queue.queue); - spin_lock_init(&pstapriv->free_sta_queue.lock); - - spin_lock_init(&pstapriv->sta_hash_lock); - - pstapriv->asoc_sta_count = 0; - INIT_LIST_HEAD(&pstapriv->sleep_q.queue); - spin_lock_init(&pstapriv->sleep_q.lock); - INIT_LIST_HEAD(&pstapriv->wakeup_q.queue); - spin_lock_init(&pstapriv->wakeup_q.lock); - - psta = (struct sta_info *)(pstapriv->pstainfo_buf); - - for (i = 0; i < NUM_STA; i++) { - _rtw_init_stainfo(psta); - - INIT_LIST_HEAD(&pstapriv->sta_hash[i]); - - list_add_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue)); - - psta++; - } - - pstapriv->sta_dz_bitmap = 0; - pstapriv->tim_bitmap = 0; - - INIT_LIST_HEAD(&pstapriv->asoc_list); - INIT_LIST_HEAD(&pstapriv->auth_list); - spin_lock_init(&pstapriv->asoc_list_lock); - spin_lock_init(&pstapriv->auth_list_lock); - pstapriv->asoc_list_cnt = 0; - pstapriv->auth_list_cnt = 0; - - pstapriv->auth_to = 3; /* 3*2 = 6 sec */ - pstapriv->assoc_to = 3; - pstapriv->expire_to = 3; /* 3*2 = 6 sec */ - pstapriv->max_num_sta = NUM_STA; - return _SUCCESS; -} - -inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta) -{ - int offset = (((u8 *)sta) - stapriv->pstainfo_buf) / sizeof(struct sta_info); - - return offset; -} - -inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset) -{ - return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info)); -} - -/* this function is used to free the memory of lock || sema for all stainfos */ -void kfree_all_stainfo(struct sta_priv *pstapriv); -void kfree_all_stainfo(struct sta_priv *pstapriv) -{ - struct list_head *plist, *phead; - - spin_lock_bh(&pstapriv->sta_hash_lock); - - phead = get_list_head(&pstapriv->free_sta_queue); - plist = get_next(phead); - - while (phead != plist) - plist = get_next(plist); - - spin_unlock_bh(&pstapriv->sta_hash_lock); -} - -void kfree_sta_priv_lock(struct sta_priv *pstapriv); -void kfree_sta_priv_lock(struct sta_priv *pstapriv) -{ - kfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */ -} - -u32 _rtw_free_sta_priv(struct sta_priv *pstapriv) -{ - struct list_head *phead, *plist; - struct sta_info *psta = NULL; - struct recv_reorder_ctrl *preorder_ctrl; - int index; - - if (pstapriv) { - /*delete all reordering_ctrl_timer */ - spin_lock_bh(&pstapriv->sta_hash_lock); - for (index = 0; index < NUM_STA; index++) { - phead = &pstapriv->sta_hash[index]; - list_for_each(plist, phead) { - int i; - - psta = list_entry(plist, struct sta_info, - hash_list); - - for (i = 0; i < 16 ; i++) { - preorder_ctrl = &psta->recvreorder_ctrl[i]; - timer_delete_sync(&preorder_ctrl->reordering_ctrl_timer); - } - } - } - spin_unlock_bh(&pstapriv->sta_hash_lock); - /*===============================*/ - - kfree_sta_priv_lock(pstapriv); - - vfree(pstapriv->pallocated_stainfo_buf); - } - return _SUCCESS; -} - -/* struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr) */ -struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) -{ - s32 index; - struct list_head *phash_list; - struct sta_info *psta; - struct __queue *pfree_sta_queue; - struct recv_reorder_ctrl *preorder_ctrl; - int i = 0; - u16 wRxSeqInitialValue = 0xffff; - - pfree_sta_queue = &pstapriv->free_sta_queue; - - /* spin_lock_bh(&(pfree_sta_queue->lock)); */ - spin_lock_bh(&pstapriv->sta_hash_lock); - if (list_empty(&pfree_sta_queue->queue)) { - /* spin_unlock_bh(&(pfree_sta_queue->lock)); */ - spin_unlock_bh(&pstapriv->sta_hash_lock); - return NULL; - } - psta = container_of(get_next(&pfree_sta_queue->queue), struct sta_info, list); - - list_del_init(&psta->list); - - /* spin_unlock_bh(&(pfree_sta_queue->lock)); */ - - _rtw_init_stainfo(psta); - - psta->padapter = pstapriv->padapter; - - memcpy(psta->hwaddr, hwaddr, ETH_ALEN); - - index = wifi_mac_hash(hwaddr); - - if (index >= NUM_STA) { - spin_unlock_bh(&pstapriv->sta_hash_lock); - psta = NULL; - goto exit; - } - phash_list = &pstapriv->sta_hash[index]; - - /* spin_lock_bh(&(pstapriv->sta_hash_lock)); */ - - list_add_tail(&psta->hash_list, phash_list); - - pstapriv->asoc_sta_count++; - - /* spin_unlock_bh(&(pstapriv->sta_hash_lock)); */ - - /* Commented by Albert 2009/08/13 */ - /* For the SMC router, the sequence number of first packet of WPS handshake will be 0. */ - /* In this case, this packet will be dropped by recv_decache function if we use the 0x00 as the default value for tid_rxseq variable. */ - /* So, we initialize the tid_rxseq variable as the 0xffff. */ - - for (i = 0; i < 16; i++) - memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2); - - timer_setup(&psta->addba_retry_timer, addba_timer_hdl, 0); - - /* for A-MPDU Rx reordering buffer control */ - for (i = 0; i < 16 ; i++) { - preorder_ctrl = &psta->recvreorder_ctrl[i]; - - preorder_ctrl->padapter = pstapriv->padapter; - - preorder_ctrl->enable = false; - - preorder_ctrl->indicate_seq = 0xffff; - preorder_ctrl->wend_b = 0xffff; - /* preorder_ctrl->wsize_b = (NR_RECVBUFF-2); */ - preorder_ctrl->wsize_b = 64;/* 64; */ - - INIT_LIST_HEAD(&preorder_ctrl->pending_recvframe_queue.queue); - spin_lock_init(&preorder_ctrl->pending_recvframe_queue.lock); - - /* init recv timer */ - timer_setup(&preorder_ctrl->reordering_ctrl_timer, - rtw_reordering_ctrl_timeout_handler, 0); - } - - /* init for DM */ - psta->rssi_stat.UndecoratedSmoothedPWDB = (-1); - psta->rssi_stat.UndecoratedSmoothedCCK = (-1); - - /* init for the sequence number of received management frame */ - psta->rx_mgmt_frame_seq_num = 0xffff; - spin_unlock_bh(&pstapriv->sta_hash_lock); - /* alloc mac id for non-bc/mc station, */ - rtw_alloc_macid(pstapriv->padapter, psta); - -exit: - - return psta; -} - -u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta) -{ - int i; - struct __queue *pfree_sta_queue; - struct recv_reorder_ctrl *preorder_ctrl; - struct sta_xmit_priv *pstaxmitpriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct sta_priv *pstapriv = &padapter->stapriv; - struct hw_xmit *phwxmit; - - if (!psta) - goto exit; - - spin_lock_bh(&psta->lock); - psta->state &= ~_FW_LINKED; - spin_unlock_bh(&psta->lock); - - pfree_sta_queue = &pstapriv->free_sta_queue; - - pstaxmitpriv = &psta->sta_xmitpriv; - - /* list_del_init(&psta->sleep_list); */ - - /* list_del_init(&psta->wakeup_list); */ - - spin_lock_bh(&pxmitpriv->lock); - - rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q); - psta->sleepq_len = 0; - - /* vo */ - /* spin_lock_bh(&(pxmitpriv->vo_pending.lock)); */ - rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending); - list_del_init(&pstaxmitpriv->vo_q.tx_pending); - phwxmit = pxmitpriv->hwxmits; - phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt; - pstaxmitpriv->vo_q.qcnt = 0; - /* spin_unlock_bh(&(pxmitpriv->vo_pending.lock)); */ - - /* vi */ - /* spin_lock_bh(&(pxmitpriv->vi_pending.lock)); */ - rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending); - list_del_init(&pstaxmitpriv->vi_q.tx_pending); - phwxmit = pxmitpriv->hwxmits + 1; - phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt; - pstaxmitpriv->vi_q.qcnt = 0; - /* spin_unlock_bh(&(pxmitpriv->vi_pending.lock)); */ - - /* be */ - /* spin_lock_bh(&(pxmitpriv->be_pending.lock)); */ - rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending); - list_del_init(&pstaxmitpriv->be_q.tx_pending); - phwxmit = pxmitpriv->hwxmits + 2; - phwxmit->accnt -= pstaxmitpriv->be_q.qcnt; - pstaxmitpriv->be_q.qcnt = 0; - /* spin_unlock_bh(&(pxmitpriv->be_pending.lock)); */ - - /* bk */ - /* spin_lock_bh(&(pxmitpriv->bk_pending.lock)); */ - rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending); - list_del_init(&pstaxmitpriv->bk_q.tx_pending); - phwxmit = pxmitpriv->hwxmits + 3; - phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt; - pstaxmitpriv->bk_q.qcnt = 0; - /* spin_unlock_bh(&(pxmitpriv->bk_pending.lock)); */ - - spin_unlock_bh(&pxmitpriv->lock); - - spin_lock_bh(&pstapriv->sta_hash_lock); - list_del_init(&psta->hash_list); - pstapriv->asoc_sta_count--; - spin_unlock_bh(&pstapriv->sta_hash_lock); - - /* re-init sta_info; 20061114 will be init in alloc_stainfo */ - /* _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); */ - /* _rtw_init_sta_recv_priv(&psta->sta_recvpriv); */ - - timer_delete_sync(&psta->addba_retry_timer); - - /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */ - for (i = 0; i < 16 ; i++) { - struct list_head *phead, *plist; - union recv_frame *prframe; - struct __queue *ppending_recvframe_queue; - struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue; - - preorder_ctrl = &psta->recvreorder_ctrl[i]; - - timer_delete_sync(&preorder_ctrl->reordering_ctrl_timer); - - ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; - - spin_lock_bh(&ppending_recvframe_queue->lock); - - phead = get_list_head(ppending_recvframe_queue); - plist = get_next(phead); - - while (!list_empty(phead)) { - prframe = (union recv_frame *)plist; - - plist = get_next(plist); - - list_del_init(&prframe->u.hdr.list); - - rtw_free_recvframe(prframe, pfree_recv_queue); - } - - spin_unlock_bh(&ppending_recvframe_queue->lock); - } - - if (!(psta->state & WIFI_AP_STATE)) - rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, false); - - /* release mac id for non-bc/mc station, */ - rtw_release_macid(pstapriv->padapter, psta); - spin_lock_bh(&pstapriv->auth_list_lock); - if (!list_empty(&psta->auth_list)) { - list_del_init(&psta->auth_list); - pstapriv->auth_list_cnt--; - } - spin_unlock_bh(&pstapriv->auth_list_lock); - - psta->expire_to = 0; - psta->sleepq_ac_len = 0; - psta->qos_info = 0; - - psta->max_sp_len = 0; - psta->uapsd_bk = 0; - psta->uapsd_be = 0; - psta->uapsd_vi = 0; - psta->uapsd_vo = 0; - - psta->has_legacy_ac = 0; - - pstapriv->sta_dz_bitmap &= ~BIT(psta->aid); - pstapriv->tim_bitmap &= ~BIT(psta->aid); - - if ((psta->aid > 0) && (pstapriv->sta_aid[psta->aid - 1] == psta)) { - pstapriv->sta_aid[psta->aid - 1] = NULL; - psta->aid = 0; - } - - psta->under_exist_checking = 0; - - /* spin_lock_bh(&(pfree_sta_queue->lock)); */ - list_add_tail(&psta->list, get_list_head(pfree_sta_queue)); - /* spin_unlock_bh(&(pfree_sta_queue->lock)); */ - -exit: - return _SUCCESS; -} - -/* free all stainfo which in sta_hash[all] */ -void rtw_free_all_stainfo(struct adapter *padapter) -{ - struct list_head *plist, *phead, *tmp; - s32 index; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter); - LIST_HEAD(stainfo_free_list); - - if (pstapriv->asoc_sta_count == 1) - return; - - spin_lock_bh(&pstapriv->sta_hash_lock); - - for (index = 0; index < NUM_STA; index++) { - phead = &pstapriv->sta_hash[index]; - list_for_each_safe(plist, tmp, phead) { - psta = list_entry(plist, struct sta_info, hash_list); - - if (pbcmc_stainfo != psta) - list_move(&psta->hash_list, &stainfo_free_list); - } - } - - spin_unlock_bh(&pstapriv->sta_hash_lock); - - list_for_each_safe(plist, tmp, &stainfo_free_list) { - psta = list_entry(plist, struct sta_info, hash_list); - rtw_free_stainfo(padapter, psta); - } -} - -/* any station allocated can be searched by hash list */ -struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) -{ - struct list_head *plist, *phead; - struct sta_info *psta = NULL; - u32 index; - u8 *addr; - u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - - if (!hwaddr) - return NULL; - - if (is_multicast_ether_addr(hwaddr)) - addr = bc_addr; - else - addr = hwaddr; - - index = wifi_mac_hash(addr); - - spin_lock_bh(&pstapriv->sta_hash_lock); - - phead = &pstapriv->sta_hash[index]; - list_for_each(plist, phead) { - psta = list_entry(plist, struct sta_info, hash_list); - - if ((!memcmp(psta->hwaddr, addr, ETH_ALEN))) - /* if found the matched address */ - break; - - psta = NULL; - } - - spin_unlock_bh(&pstapriv->sta_hash_lock); - return psta; -} - -u32 rtw_init_bcmc_stainfo(struct adapter *padapter) -{ - struct sta_info *psta; - u8 bcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - - struct sta_priv *pstapriv = &padapter->stapriv; - /* struct __queue *pstapending = &padapter->xmitpriv.bm_pending; */ - - psta = rtw_alloc_stainfo(pstapriv, bcast_addr); - - if (!psta) - return _FAIL; - - /* default broadcast & multicast use macid 1 */ - psta->mac_id = 1; - - return _SUCCESS; -} - -struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - - return rtw_get_stainfo(pstapriv, bc_addr); -} - -u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr) -{ - bool res = true; - struct list_head *plist, *phead; - struct rtw_wlan_acl_node *paclnode; - bool match = false; - struct sta_priv *pstapriv = &padapter->stapriv; - struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; - struct __queue *pacl_node_q = &pacl_list->acl_node_q; - - spin_lock_bh(&pacl_node_q->lock); - phead = get_list_head(pacl_node_q); - list_for_each(plist, phead) { - paclnode = list_entry(plist, struct rtw_wlan_acl_node, list); - - if (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) - if (paclnode->valid) { - match = true; - break; - } - } - spin_unlock_bh(&pacl_node_q->lock); - - if (pacl_list->mode == 1) /* accept unless in deny list */ - res = !match; - - else if (pacl_list->mode == 2)/* deny unless in accept list */ - res = match; - else - res = true; - - return res; -} diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c deleted file mode 100644 index 8c1f4670679b..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c +++ /dev/null @@ -1,1759 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include - -static unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f}; -static unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74}; - -static unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18}; -static unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7}; -static unsigned char BROADCOM_OUI3[] = {0x00, 0x05, 0xb5}; - -static unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96}; -static unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43}; -static unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43}; -static unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c}; -static unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5}; -static unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02}; -static unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02}; - -/* define WAIT_FOR_BCN_TO_MIN (3000) */ -#define WAIT_FOR_BCN_TO_MIN (6000) -#define WAIT_FOR_BCN_TO_MAX (20000) - -#define DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS 1000 -#define DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD 3 - -static u8 rtw_basic_rate_cck[4] = { - IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, - IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK, - IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, - IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK -}; - -static u8 rtw_basic_rate_ofdm[3] = { - IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, - IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK, - IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK -}; - -u8 networktype_to_raid_ex(struct adapter *adapter, struct sta_info *psta) -{ - u8 raid; - - switch (psta->wireless_mode) { - case WIRELESS_11B: - raid = RATEID_IDX_B; - break; - case WIRELESS_11G: - raid = RATEID_IDX_G; - break; - case WIRELESS_11BG: - raid = RATEID_IDX_BG; - break; - case WIRELESS_11_24N: - case WIRELESS_11G_24N: - raid = RATEID_IDX_GN_N1SS; - break; - case WIRELESS_11B_24N: - case WIRELESS_11BG_24N: - if (psta->bw_mode == CHANNEL_WIDTH_20) - raid = RATEID_IDX_BGN_20M_1SS_BN; - else - raid = RATEID_IDX_BGN_40M_1SS; - break; - default: - raid = RATEID_IDX_BGN_40M_2SS; - break; - } - return raid; -} - -unsigned char ratetbl_val_2wifirate(unsigned char rate); -unsigned char ratetbl_val_2wifirate(unsigned char rate) -{ - switch (rate & 0x7f) { - case 0: - return IEEE80211_CCK_RATE_1MB; - case 1: - return IEEE80211_CCK_RATE_2MB; - case 2: - return IEEE80211_CCK_RATE_5MB; - case 3: - return IEEE80211_CCK_RATE_11MB; - case 4: - return IEEE80211_OFDM_RATE_6MB; - case 5: - return IEEE80211_OFDM_RATE_9MB; - case 6: - return IEEE80211_OFDM_RATE_12MB; - case 7: - return IEEE80211_OFDM_RATE_18MB; - case 8: - return IEEE80211_OFDM_RATE_24MB; - case 9: - return IEEE80211_OFDM_RATE_36MB; - case 10: - return IEEE80211_OFDM_RATE_48MB; - case 11: - return IEEE80211_OFDM_RATE_54MB; - default: - return 0; - } -} - -int is_basicrate(struct adapter *padapter, unsigned char rate); -int is_basicrate(struct adapter *padapter, unsigned char rate) -{ - int i; - unsigned char val; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - for (i = 0; i < NumRates; i++) { - val = pmlmeext->basicrate[i]; - - if ((val != 0xff) && (val != 0xfe)) - if (rate == ratetbl_val_2wifirate(val)) - return true; - } - - return false; -} - -unsigned int ratetbl2rateset(struct adapter *padapter, unsigned char *rateset); -unsigned int ratetbl2rateset(struct adapter *padapter, unsigned char *rateset) -{ - int i; - unsigned char rate; - unsigned int len = 0; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - - for (i = 0; i < NumRates; i++) { - rate = pmlmeext->datarate[i]; - - switch (rate) { - case 0xff: - return len; - - case 0xfe: - continue; - - default: - rate = ratetbl_val_2wifirate(rate); - - if (is_basicrate(padapter, rate)) - rate |= IEEE80211_BASIC_RATE_MASK; - - rateset[len] = rate; - len++; - break; - } - } - return len; -} - -void get_rate_set(struct adapter *padapter, unsigned char *pbssrate, int *bssrate_len) -{ - unsigned char supportedrates[NumRates]; - - memset(supportedrates, 0, NumRates); - *bssrate_len = ratetbl2rateset(padapter, supportedrates); - memcpy(pbssrate, supportedrates, *bssrate_len); -} - -void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask) -{ - u8 mcs_rate_1r = (u8)(mask & 0xff); - u8 mcs_rate_2r = (u8)((mask >> 8) & 0xff); - u8 mcs_rate_3r = (u8)((mask >> 16) & 0xff); - u8 mcs_rate_4r = (u8)((mask >> 24) & 0xff); - - mcs_set[0] &= mcs_rate_1r; - mcs_set[1] &= mcs_rate_2r; - mcs_set[2] &= mcs_rate_3r; - mcs_set[3] &= mcs_rate_4r; -} - -void update_basic_rate_table(struct adapter *Adapter, u8 *mBratesOS) -{ - u8 i; - u8 rate; - - /* 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */ - for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) { - rate = mBratesOS[i] & 0x7f; - switch (rate) { - case IEEE80211_CCK_RATE_1MB: - case IEEE80211_CCK_RATE_2MB: - case IEEE80211_CCK_RATE_5MB: - case IEEE80211_CCK_RATE_11MB: - case IEEE80211_OFDM_RATE_6MB: - case IEEE80211_OFDM_RATE_12MB: - case IEEE80211_OFDM_RATE_24MB: - mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK; - break; - } - } -} - -void update_basic_rate_table_soft_ap(u8 *bssrateset, u32 bssratelen) -{ - u8 i; - u8 rate; - - for (i = 0; i < bssratelen; i++) { - rate = bssrateset[i] & 0x7f; - switch (rate) { - case IEEE80211_CCK_RATE_1MB: - case IEEE80211_CCK_RATE_2MB: - case IEEE80211_CCK_RATE_5MB: - case IEEE80211_CCK_RATE_11MB: - bssrateset[i] |= IEEE80211_BASIC_RATE_MASK; - break; - } - } -} - -void save_dm_func_flag(struct adapter *padapter) -{ - u8 bSaveFlag = true; - - rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag)); -} - -void restore_dm_func_flag(struct adapter *padapter) -{ - u8 bSaveFlag = false; - - rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag)); -} - -void switch_dm_func(struct adapter *padapter, u32 mode, u8 enable) -{ - if (enable) - rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_SET, (u8 *)(&mode)); - else - rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode)); -} - -void set_msr(struct adapter *padapter, u8 type) -{ - rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type)); -} - -inline u8 rtw_get_oper_ch(struct adapter *adapter) -{ - return adapter_to_dvobj(adapter)->oper_channel; -} - -inline void rtw_set_oper_ch(struct adapter *adapter, u8 ch) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - - if (dvobj->oper_channel != ch) - dvobj->on_oper_ch_time = jiffies; - - dvobj->oper_channel = ch; -} - -inline void rtw_set_oper_bw(struct adapter *adapter, u8 bw) -{ - adapter_to_dvobj(adapter)->oper_bwmode = bw; -} - -inline void rtw_set_oper_choffset(struct adapter *adapter, u8 offset) -{ - adapter_to_dvobj(adapter)->oper_ch_offset = offset; -} - -u8 rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset) -{ - u8 center_ch = channel; - - if (chnl_bw == CHANNEL_WIDTH_40) { - if (chnl_offset == HAL_PRIME_CHNL_OFFSET_LOWER) - center_ch = channel + 2; - else - center_ch = channel - 2; - } - - return center_ch; -} - -inline unsigned long rtw_get_on_cur_ch_time(struct adapter *adapter) -{ - if (adapter->mlmeextpriv.cur_channel == adapter_to_dvobj(adapter)->oper_channel) - return adapter_to_dvobj(adapter)->on_oper_ch_time; - else - return 0; -} - -void r8723bs_select_channel(struct adapter *padapter, unsigned char channel) -{ - if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->setch_mutex))) - return; - - /* saved channel info */ - rtw_set_oper_ch(padapter, channel); - - rtw_hal_set_chan(padapter, channel); - - mutex_unlock(&(adapter_to_dvobj(padapter)->setch_mutex)); -} - -void set_channel_bwmode(struct adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode) -{ - u8 center_ch, chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - - center_ch = rtw_get_center_ch(channel, bwmode, channel_offset); - - /* set Channel */ - if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->setch_mutex))) - return; - - /* saved channel/bw info */ - rtw_set_oper_ch(padapter, channel); - rtw_set_oper_bw(padapter, bwmode); - rtw_set_oper_choffset(padapter, channel_offset); - - rtw_hal_set_chnl_bw(padapter, center_ch, bwmode, channel_offset, chnl_offset80); /* set center channel */ - - mutex_unlock(&(adapter_to_dvobj(padapter)->setch_mutex)); -} - -inline u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork) -{ - return pnetwork->mac_address; -} - -u16 get_beacon_interval(struct wlan_bssid_ex *bss) -{ - __le16 val; - - memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->ies), 2); - - return le16_to_cpu(val); -} - -int is_client_associated_to_ap(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext; - struct mlme_ext_info *pmlmeinfo; - - if (!padapter) - return _FAIL; - - pmlmeext = &padapter->mlmeextpriv; - pmlmeinfo = &pmlmeext->mlmext_info; - - if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE)) - return true; - else - return _FAIL; -} - -int is_client_associated_to_ibss(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE)) - return true; - else - return _FAIL; -} - -int is_IBSS_empty(struct adapter *padapter) -{ - unsigned int i; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) { - if (pmlmeinfo->FW_sta_info[i].status == 1) - return _FAIL; - } - - return true; -} - -unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval) -{ - if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN) - return WAIT_FOR_BCN_TO_MIN; - else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX) - return WAIT_FOR_BCN_TO_MAX; - else - return bcn_interval << 2; -} - -void invalidate_cam_all(struct adapter *padapter) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - - rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, NULL); - - spin_lock_bh(&cam_ctl->lock); - cam_ctl->bitmap = 0; - memset(dvobj->cam_cache, 0, sizeof(struct cam_entry_cache) * TOTAL_CAM_ENTRY); - spin_unlock_bh(&cam_ctl->lock); -} - -void _write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key) -{ - unsigned int i, val, addr; - int j; - u32 cam_val[2]; - - addr = entry << 3; - - for (j = 5; j >= 0; j--) { - switch (j) { - case 0: - val = (ctrl | (mac[0] << 16) | (mac[1] << 24)); - break; - case 1: - val = (mac[2] | (mac[3] << 8) | (mac[4] << 16) | (mac[5] << 24)); - break; - default: - i = (j - 2) << 2; - val = (key[i] | (key[i + 1] << 8) | (key[i + 2] << 16) | (key[i + 3] << 24)); - break; - } - - cam_val[0] = val; - cam_val[1] = addr + (unsigned int)j; - - rtw_hal_set_hwreg(padapter, HW_VAR_CAM_WRITE, (u8 *)cam_val); - } -} - -void _clear_cam_entry(struct adapter *padapter, u8 entry) -{ - unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - _write_cam(padapter, entry, 0, null_sta, null_key); -} - -inline void write_cam(struct adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key) -{ - _write_cam(adapter, id, ctrl, mac, key); - write_cam_cache(adapter, id, ctrl, mac, key); -} - -inline void clear_cam_entry(struct adapter *adapter, u8 id) -{ - _clear_cam_entry(adapter, id); - clear_cam_cache(adapter, id); -} - -void write_cam_cache(struct adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - - spin_lock_bh(&cam_ctl->lock); - - dvobj->cam_cache[id].ctrl = ctrl; - memcpy(dvobj->cam_cache[id].mac, mac, ETH_ALEN); - memcpy(dvobj->cam_cache[id].key, key, 16); - - spin_unlock_bh(&cam_ctl->lock); -} - -void clear_cam_cache(struct adapter *adapter, u8 id) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - - spin_lock_bh(&cam_ctl->lock); - - memset(&dvobj->cam_cache[id], 0, sizeof(struct cam_entry_cache)); - - spin_unlock_bh(&cam_ctl->lock); -} - -static bool _rtw_camid_is_gk(struct adapter *adapter, u8 cam_id) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - bool ret = false; - - if (cam_id >= TOTAL_CAM_ENTRY) - goto exit; - - if (!(cam_ctl->bitmap & BIT(cam_id))) - goto exit; - - ret = (dvobj->cam_cache[cam_id].ctrl & BIT(6)) ? true : false; - -exit: - return ret; -} - -static s16 _rtw_camid_search(struct adapter *adapter, u8 *addr, s16 kid) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - int i; - s16 cam_id = -1; - - for (i = 0; i < TOTAL_CAM_ENTRY; i++) { - if (addr && memcmp(dvobj->cam_cache[i].mac, addr, ETH_ALEN)) - continue; - if (kid >= 0 && kid != (dvobj->cam_cache[i].ctrl & 0x03)) - continue; - - cam_id = i; - break; - } - - return cam_id; -} - -s16 rtw_camid_search(struct adapter *adapter, u8 *addr, s16 kid) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - s16 cam_id = -1; - - spin_lock_bh(&cam_ctl->lock); - cam_id = _rtw_camid_search(adapter, addr, kid); - spin_unlock_bh(&cam_ctl->lock); - - return cam_id; -} - -s16 rtw_camid_alloc(struct adapter *adapter, struct sta_info *sta, u8 kid) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - s16 cam_id = -1; - struct mlme_ext_info *mlmeinfo; - - spin_lock_bh(&cam_ctl->lock); - - mlmeinfo = &adapter->mlmeextpriv.mlmext_info; - - if ((((mlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) || ((mlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE)) - && !sta) { - /* AP/Ad-hoc mode group key: static allocation to default key by key ID */ - if (kid > 3) { - netdev_dbg(adapter->pnetdev, - FUNC_ADPT_FMT " group key with invalid key id:%u\n", - FUNC_ADPT_ARG(adapter), kid); - WARN_ON(1); - goto bitmap_handle; - } - - cam_id = kid; - } else { - int i; - u8 *addr = sta ? sta->hwaddr : NULL; - - if (!sta) { - if (!(mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) { - /* bypass STA mode group key setting before connected(ex:WEP) because bssid is not ready */ - goto bitmap_handle; - } - - addr = get_bssid(&adapter->mlmepriv); - } - - i = _rtw_camid_search(adapter, addr, kid); - if (i >= 0) { - /* Fix issue that pairwise and group key have same key id. - * Pairwise key first, group key can overwrite group only(ex: rekey) - */ - if (sta || _rtw_camid_is_gk(adapter, i)) - cam_id = i; - else - netdev_dbg(adapter->pnetdev, - FUNC_ADPT_FMT " group key id:%u the same key id as pairwise key\n", - FUNC_ADPT_ARG(adapter), kid); - goto bitmap_handle; - } - - for (i = 4; i < TOTAL_CAM_ENTRY; i++) - if (!(cam_ctl->bitmap & BIT(i))) - break; - - if (i == TOTAL_CAM_ENTRY) { - if (sta) - netdev_dbg(adapter->pnetdev, - FUNC_ADPT_FMT " pairwise key with %pM id:%u no room\n", - FUNC_ADPT_ARG(adapter), - sta->hwaddr, kid); - else - netdev_dbg(adapter->pnetdev, - FUNC_ADPT_FMT " group key id:%u no room\n", - FUNC_ADPT_ARG(adapter), kid); - WARN_ON(1); - goto bitmap_handle; - } - - cam_id = i; - } - -bitmap_handle: - if (cam_id >= 0 && cam_id < 32) - cam_ctl->bitmap |= BIT(cam_id); - - spin_unlock_bh(&cam_ctl->lock); - - return cam_id; -} - -void rtw_camid_free(struct adapter *adapter, u8 cam_id) -{ - struct dvobj_priv *dvobj = adapter_to_dvobj(adapter); - struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl; - - spin_lock_bh(&cam_ctl->lock); - - if (cam_id < TOTAL_CAM_ENTRY) - cam_ctl->bitmap &= ~(BIT(cam_id)); - - spin_unlock_bh(&cam_ctl->lock); -} - -int allocate_fw_sta_entry(struct adapter *padapter) -{ - unsigned int mac_id; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - for (mac_id = IBSS_START_MAC_ID; mac_id < NUM_STA; mac_id++) { - if (pmlmeinfo->FW_sta_info[mac_id].status == 0) { - pmlmeinfo->FW_sta_info[mac_id].status = 1; - pmlmeinfo->FW_sta_info[mac_id].retry = 0; - break; - } - } - - return mac_id; -} - -void flush_all_cam_entry(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - invalidate_cam_all(padapter); - /* clear default key related key search setting */ - rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)false); - - memset((u8 *)(pmlmeinfo->FW_sta_info), 0, sizeof(pmlmeinfo->FW_sta_info)); -} - -int WMM_param_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE) -{ - /* struct registry_priv *pregpriv = &padapter->registrypriv; */ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (pmlmepriv->qospriv.qos_option == 0) { - pmlmeinfo->WMM_enable = 0; - return false; - } - - if (pIE->length != WLAN_WMM_LEN) - return false; - - if (!memcmp(&pmlmeinfo->WMM_param, (pIE->data + 6), sizeof(struct WMM_para_element))) - return false; - - memcpy(&pmlmeinfo->WMM_param, (pIE->data + 6), sizeof(struct WMM_para_element)); - - pmlmeinfo->WMM_enable = 1; - return true; -} - -static void sort_wmm_ac_params(u32 *inx, u32 *edca) -{ - u32 i, j, change_inx = false; - - /* entry index: 0->vo, 1->vi, 2->be, 3->bk. */ - for (i = 0; i < 4; i++) { - for (j = i + 1; j < 4; j++) { - /* compare CW and AIFS */ - if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF)) { - change_inx = true; - } else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) { - /* compare TXOP */ - if ((edca[j] >> 16) > (edca[i] >> 16)) - change_inx = true; - } - - if (change_inx) { - swap(edca[i], edca[j]); - swap(inx[i], inx[j]); - - change_inx = false; - } - } - } -} - -void WMMOnAssocRsp(struct adapter *padapter) -{ - u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime; - u8 acm_mask; - u16 TXOP; - u32 acParm, i; - u32 edca[4], inx[4]; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct registry_priv *pregpriv = &padapter->registrypriv; - - acm_mask = 0; - - if (pmlmeext->cur_wireless_mode & WIRELESS_11_24N) - aSifsTime = 16; - else - aSifsTime = 10; - - if (pmlmeinfo->WMM_enable == 0) { - padapter->mlmepriv.acm_mask = 0; - - AIFS = aSifsTime + (2 * pmlmeinfo->slotTime); - - if (pmlmeext->cur_wireless_mode & WIRELESS_11G) { - ECWMin = 4; - ECWMax = 10; - } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) { - ECWMin = 5; - ECWMax = 10; - } else { - ECWMin = 4; - ECWMax = 10; - } - - TXOP = 0; - acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16); - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm)); - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm)); - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm)); - - ECWMin = 2; - ECWMax = 3; - TXOP = 0x2f; - acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16); - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm)); - } else { - edca[0] = edca[1] = edca[2] = edca[3] = 0; - - for (i = 0; i < 4; i++) { - ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03; - ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01; - - /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */ - AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime; - - ECWMin = (pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f); - ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4; - TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit); - - acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16); - - switch (ACI) { - case 0x0: - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm)); - acm_mask |= (ACM ? BIT(1) : 0); - edca[XMIT_BE_QUEUE] = acParm; - break; - - case 0x1: - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm)); - /* acm_mask |= (ACM? BIT(0):0); */ - edca[XMIT_BK_QUEUE] = acParm; - break; - - case 0x2: - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm)); - acm_mask |= (ACM ? BIT(2) : 0); - edca[XMIT_VI_QUEUE] = acParm; - break; - - case 0x3: - rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm)); - acm_mask |= (ACM ? BIT(3) : 0); - edca[XMIT_VO_QUEUE] = acParm; - break; - } - } - - if (padapter->registrypriv.acm_method == 1) - rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask)); - else - padapter->mlmepriv.acm_mask = acm_mask; - - inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3; - - if (pregpriv->wifi_spec == 1) - sort_wmm_ac_params(inx, edca); - - for (i = 0; i < 4; i++) - pxmitpriv->wmm_para_seq[i] = inx[i]; - } -} - -static void bwmode_update_check(struct adapter *padapter, struct ndis_80211_var_ie *pIE) -{ - unsigned char new_bwmode; - unsigned char new_ch_offset; - struct HT_info_element *pHT_info; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - u8 cbw40_enable = 0; - - if (!pIE) - return; - - if (!phtpriv->ht_option) - return; - - if (pIE->length > sizeof(struct HT_info_element)) - return; - - pHT_info = (struct HT_info_element *)pIE->data; - - if ((pregistrypriv->bw_mode & 0x0f) > 0) - cbw40_enable = 1; - - if ((pHT_info->infos[0] & BIT(2)) && cbw40_enable) { - new_bwmode = CHANNEL_WIDTH_40; - - switch (pHT_info->infos[0] & 0x3) { - case 1: - new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER; - break; - - case 3: - new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER; - break; - - default: - new_bwmode = CHANNEL_WIDTH_20; - new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - break; - } - } else { - new_bwmode = CHANNEL_WIDTH_20; - new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - } - - if ((new_bwmode != pmlmeext->cur_bwmode) || (new_ch_offset != pmlmeext->cur_ch_offset)) { - pmlmeinfo->bwmode_updated = true; - - pmlmeext->cur_bwmode = new_bwmode; - pmlmeext->cur_ch_offset = new_ch_offset; - - /* update HT info also */ - HT_info_handler(padapter, pIE); - } else { - pmlmeinfo->bwmode_updated = false; - } - - if (true == pmlmeinfo->bwmode_updated) { - struct sta_info *psta; - struct wlan_bssid_ex *cur_network = &pmlmeinfo->network; - struct sta_priv *pstapriv = &padapter->stapriv; - - /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */ - - /* update ap's stainfo */ - psta = rtw_get_stainfo(pstapriv, cur_network->mac_address); - if (psta) { - struct ht_priv *phtpriv_sta = &psta->htpriv; - - if (phtpriv_sta->ht_option) { - /* bwmode */ - psta->bw_mode = pmlmeext->cur_bwmode; - phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset; - } else { - psta->bw_mode = CHANNEL_WIDTH_20; - phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - } - - rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta); - } - } -} - -void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE) -{ - unsigned int i; - u8 max_AMPDU_len, min_MPDU_spacing; - u8 cur_ldpc_cap = 0, cur_stbc_cap = 0; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - - if (!pIE) - return; - - if (!phtpriv->ht_option) - return; - - pmlmeinfo->HT_caps_enable = 1; - - for (i = 0; i < umin(pIE->length, - sizeof(pmlmeinfo->HT_caps.u.HT_cap)); i++) { - if (i != 2) { - /* Commented by Albert 2010/07/12 */ - /* Got the endian issue here. */ - pmlmeinfo->HT_caps.u.HT_cap[i] &= (pIE->data[i]); - } else { - /* modify from fw by Thomas 2010/11/17 */ - max_AMPDU_len = min(pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3, - pIE->data[i] & 0x3); - - min_MPDU_spacing = max(pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c, - pIE->data[i] & 0x1c); - - pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para = max_AMPDU_len | min_MPDU_spacing; - } - } - - /* update the MCS set */ - for (i = 0; i < 16; i++) - pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= pmlmeext->default_supported_mcs_set[i]; - - /* update the MCS rates */ - set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_1R); - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - /* Config STBC setting */ - if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && - GET_HT_CAPABILITY_ELE_TX_STBC(pIE->data)) - SET_FLAG(cur_stbc_cap, STBC_HT_ENABLE_TX); - - phtpriv->stbc_cap = cur_stbc_cap; - } else { - /* Config LDPC Coding Capability */ - if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX) && - GET_HT_CAPABILITY_ELE_LDPC_CAP(pIE->data)) - SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX)); - - phtpriv->ldpc_cap = cur_ldpc_cap; - - /* Config STBC setting */ - if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && - GET_HT_CAPABILITY_ELE_RX_STBC(pIE->data)) - SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX)); - - phtpriv->stbc_cap = cur_stbc_cap; - } -} - -void HT_info_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ht_priv *phtpriv = &pmlmepriv->htpriv; - - if (!pIE) - return; - - if (!phtpriv->ht_option) - return; - - if (pIE->length > sizeof(struct HT_info_element)) - return; - - pmlmeinfo->HT_info_enable = 1; - memcpy(&pmlmeinfo->HT_info, pIE->data, pIE->length); -} - -void HTOnAssocRsp(struct adapter *padapter) -{ - unsigned char max_AMPDU_len; - unsigned char min_MPDU_spacing; - /* struct registry_priv *pregpriv = &padapter->registrypriv; */ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable)) { - pmlmeinfo->HT_enable = 1; - } else { - pmlmeinfo->HT_enable = 0; - /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */ - return; - } - - /* handle A-MPDU parameter field */ - /* - * AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k - * AMPDU_para [4:2]:Min MPDU Start Spacing - */ - max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03; - - min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2; - - rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing)); - - rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len)); -} - -void ERP_IE_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (pIE->length > 1) - return; - - pmlmeinfo->ERP_enable = 1; - memcpy(&pmlmeinfo->ERP_IE, pIE->data, pIE->length); -} - -void VCS_update(struct adapter *padapter, struct sta_info *psta) -{ - struct registry_priv *pregpriv = &padapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - switch (pregpriv->vrtl_carrier_sense) {/* 0:off 1:on 2:auto */ - case 0: /* off */ - psta->rtsen = 0; - psta->cts2self = 0; - break; - - case 1: /* on */ - if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */ - psta->rtsen = 1; - psta->cts2self = 0; - } else { - psta->rtsen = 0; - psta->cts2self = 1; - } - break; - - case 2: /* auto */ - default: - if ((pmlmeinfo->ERP_enable) && (pmlmeinfo->ERP_IE & BIT(1))) { - if (pregpriv->vcs_type == 1) { - psta->rtsen = 1; - psta->cts2self = 0; - } else { - psta->rtsen = 0; - psta->cts2self = 1; - } - } else { - psta->rtsen = 0; - psta->cts2self = 0; - } - break; - } -} - -void update_ldpc_stbc_cap(struct sta_info *psta) -{ - if (psta->htpriv.ht_option) { - if (TEST_FLAG(psta->htpriv.ldpc_cap, LDPC_HT_ENABLE_TX)) - psta->ldpc = 1; - - if (TEST_FLAG(psta->htpriv.stbc_cap, STBC_HT_ENABLE_TX)) - psta->stbc = 1; - } else { - psta->ldpc = 0; - psta->stbc = 0; - } -} - -int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len) -{ - unsigned int len; - unsigned char *p; - unsigned short val16, subtype; - struct wlan_network *cur_network = &Adapter->mlmepriv.cur_network; - /* u8 wpa_ie[255], rsn_ie[255]; */ - u16 wpa_len = 0, rsn_len = 0; - u8 encryp_protocol = 0; - struct wlan_bssid_ex *bssid; - int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0; - unsigned char *pbuf; - u32 wpa_ielen = 0; - u8 *pbssid = GetAddr3Ptr(pframe); - struct HT_info_element *pht_info = NULL; - struct ieee80211_ht_cap *pht_cap = NULL; - u32 bcn_channel; - unsigned short ht_cap_info; - unsigned char ht_info_infos_0; - struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; - int ssid_len; - - if (!is_client_associated_to_ap(Adapter)) - return true; - - len = packet_len - sizeof(struct ieee80211_hdr_3addr); - - if (len > MAX_IE_SZ) - return _FAIL; - - if (memcmp(cur_network->network.mac_address, pbssid, 6)) - return true; - - bssid = kzalloc_obj(*bssid); - if (!bssid) - return true; - - if ((pmlmepriv->timeBcnInfoChkStart != 0) && (jiffies_to_msecs(jiffies - pmlmepriv->timeBcnInfoChkStart) > DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS)) { - pmlmepriv->timeBcnInfoChkStart = 0; - pmlmepriv->NumOfBcnInfoChkFail = 0; - } - - subtype = GetFrameSubType(pframe) >> 4; - - if (subtype == WIFI_BEACON) - bssid->reserved[0] = 1; - - bssid->length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len; - - /* below is to copy the information element */ - bssid->ie_length = len; - memcpy(bssid->ies, (pframe + sizeof(struct ieee80211_hdr_3addr)), bssid->ie_length); - - /* check bw and channel offset */ - /* parsing HT_CAP_IE */ - p = rtw_get_ie(bssid->ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_CAPABILITY, &len, bssid->ie_length - _FIXED_IE_LENGTH_); - if (p && len > 0) { - pht_cap = (struct ieee80211_ht_cap *)(p + 2); - ht_cap_info = le16_to_cpu(pht_cap->cap_info); - } else { - ht_cap_info = 0; - } - /* parsing HT_INFO_IE */ - p = rtw_get_ie(bssid->ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_OPERATION, &len, bssid->ie_length - _FIXED_IE_LENGTH_); - if (p && len > 0) { - pht_info = (struct HT_info_element *)(p + 2); - ht_info_infos_0 = pht_info->infos[0]; - } else { - ht_info_infos_0 = 0; - } - if (ht_cap_info != cur_network->bcn_info.ht_cap_info || - ((ht_info_infos_0 & 0x03) != (cur_network->bcn_info.ht_info_infos_0 & 0x03))) { - { - /* bcn_info_update */ - cur_network->bcn_info.ht_cap_info = ht_cap_info; - cur_network->bcn_info.ht_info_infos_0 = ht_info_infos_0; - /* to do : need to check that whether modify related register of BB or not */ - } - /* goto _mismatch; */ - } - - /* Checking for channel */ - p = rtw_get_ie(bssid->ies + _FIXED_IE_LENGTH_, WLAN_EID_DS_PARAMS, &len, bssid->ie_length - _FIXED_IE_LENGTH_); - if (p) { - bcn_channel = *(p + 2); - } else {/* In 5G, some ap do not have DSSET IE checking HT info for channel */ - rtw_get_ie(bssid->ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_OPERATION, - &len, bssid->ie_length - _FIXED_IE_LENGTH_); - if (pht_info) - bcn_channel = pht_info->primary_channel; - else /* we don't find channel IE, so don't check it */ - bcn_channel = Adapter->mlmeextpriv.cur_channel; - } - - if (bcn_channel != Adapter->mlmeextpriv.cur_channel) - goto _mismatch; - - /* checking SSID */ - ssid_len = 0; - p = rtw_get_ie(bssid->ies + _FIXED_IE_LENGTH_, WLAN_EID_SSID, &len, bssid->ie_length - _FIXED_IE_LENGTH_); - if (p) { - ssid_len = *(p + 1); - if (ssid_len > NDIS_802_11_LENGTH_SSID) - ssid_len = 0; - memcpy(bssid->ssid.ssid, (p + 2), ssid_len); - } - bssid->ssid.ssid_length = ssid_len; - - if (memcmp(bssid->ssid.ssid, cur_network->network.ssid.ssid, 32) || - bssid->ssid.ssid_length != cur_network->network.ssid.ssid_length) - if (bssid->ssid.ssid[0] != '\0' && - bssid->ssid.ssid_length != 0) /* not hidden ssid */ - goto _mismatch; - - /* check encryption info */ - val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid); - - if (val16 & BIT(4)) - bssid->privacy = 1; - else - bssid->privacy = 0; - - if (cur_network->network.privacy != bssid->privacy) - goto _mismatch; - - rtw_get_sec_ie(bssid->ies, bssid->ie_length, NULL, &rsn_len, NULL, &wpa_len); - - if (rsn_len > 0) - encryp_protocol = ENCRYP_PROTOCOL_WPA2; - else if (wpa_len > 0) - encryp_protocol = ENCRYP_PROTOCOL_WPA; - else - if (bssid->privacy) - encryp_protocol = ENCRYP_PROTOCOL_WEP; - - if (cur_network->bcn_info.encryp_protocol != encryp_protocol) - goto _mismatch; - - if (encryp_protocol == ENCRYP_PROTOCOL_WPA || encryp_protocol == ENCRYP_PROTOCOL_WPA2) { - pbuf = rtw_get_wpa_ie(&bssid->ies[12], &wpa_ielen, bssid->ie_length - 12); - if (pbuf && (wpa_ielen > 0)) { - rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, - &pairwise_cipher, &is_8021x); - } else { - pbuf = rtw_get_wpa2_ie(&bssid->ies[12], &wpa_ielen, bssid->ie_length - 12); - - if (pbuf && (wpa_ielen > 0)) - rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, - &pairwise_cipher, &is_8021x); - } - - if (pairwise_cipher != cur_network->bcn_info.pairwise_cipher || - group_cipher != cur_network->bcn_info.group_cipher) - goto _mismatch; - - if (is_8021x != cur_network->bcn_info.is_8021x) - goto _mismatch; - } - - kfree(bssid); - return _SUCCESS; - -_mismatch: - kfree(bssid); - - if (pmlmepriv->NumOfBcnInfoChkFail == 0) - pmlmepriv->timeBcnInfoChkStart = jiffies; - - pmlmepriv->NumOfBcnInfoChkFail++; - - if ((pmlmepriv->timeBcnInfoChkStart != 0) && (jiffies_to_msecs(jiffies - pmlmepriv->timeBcnInfoChkStart) <= DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS) - && (pmlmepriv->NumOfBcnInfoChkFail >= DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD)) { - pmlmepriv->timeBcnInfoChkStart = 0; - pmlmepriv->NumOfBcnInfoChkFail = 0; - return _FAIL; - } - - return _SUCCESS; -} - -void update_beacon_info(struct adapter *padapter, u8 *pframe, uint pkt_len, struct sta_info *psta) -{ - unsigned int i; - unsigned int len; - struct ndis_80211_var_ie *pIE; - - len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN); - - for (i = 0; i < len;) { - if (i + sizeof(*pIE) > len) - break; - pIE = (struct ndis_80211_var_ie *)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i); - if (i + sizeof(*pIE) + pIE->length > len) - break; - - switch (pIE->element_id) { - case WLAN_EID_VENDOR_SPECIFIC: - /* to update WMM parameter set while receiving beacon */ - if (!memcmp(pIE->data, WMM_PARA_OUI, 6) && pIE->length == WLAN_WMM_LEN) /* WMM */ - if (WMM_param_handler(padapter, pIE)) - report_wmm_edca_update(padapter); - - break; - - case WLAN_EID_HT_OPERATION: /* HT info */ - /* HT_info_handler(padapter, pIE); */ - bwmode_update_check(padapter, pIE); - break; - - case WLAN_EID_ERP_INFO: - ERP_IE_handler(padapter, pIE); - VCS_update(padapter, psta); - break; - - default: - break; - } - - i += sizeof(*pIE) + pIE->length; - } -} - -unsigned int is_ap_in_tkip(struct adapter *padapter) -{ - u32 i; - struct ndis_80211_var_ie *pIE; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur_network = &pmlmeinfo->network; - - if (rtw_get_capability((struct wlan_bssid_ex *)cur_network) & WLAN_CAPABILITY_PRIVACY) { - for (i = sizeof(struct ndis_802_11_fix_ie); i < pmlmeinfo->network.ie_length;) { - pIE = (struct ndis_80211_var_ie *)(pmlmeinfo->network.ies + i); - - if (i + sizeof(*pIE) > pmlmeinfo->network.ie_length) - break; - if (i + sizeof(*pIE) + pIE->length > pmlmeinfo->network.ie_length) - break; - - switch (pIE->element_id) { - case WLAN_EID_VENDOR_SPECIFIC: - if (pIE->length >= 16 && - !memcmp(pIE->data, RTW_WPA_OUI, 4) && - !memcmp((pIE->data + 12), WPA_TKIP_CIPHER, 4)) - return true; - - break; - - case WLAN_EID_RSN: - if (pIE->length >= 12 && - !memcmp((pIE->data + 8), RSN_TKIP_CIPHER, 4)) - return true; - break; - - default: - break; - } - - i += sizeof(*pIE) + pIE->length; - } - - return false; - } else { - return false; - } -} - -int support_short_GI(struct adapter *padapter, struct HT_caps_element *pHT_caps, u8 bwmode) -{ - unsigned char bit_offset; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (!(pmlmeinfo->HT_enable)) - return _FAIL; - - bit_offset = (bwmode & CHANNEL_WIDTH_40) ? 6 : 5; - - if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info) & (0x1 << bit_offset)) - return _SUCCESS; - else - return _FAIL; -} - -unsigned char get_highest_rate_idx(u32 mask) -{ - int i; - unsigned char rate_idx = 0; - - for (i = 31; i >= 0; i--) { - if (mask & BIT(i)) { - rate_idx = i; - break; - } - } - - return rate_idx; -} - -void update_ra_entry(struct adapter *padapter, struct sta_info *psta) -{ - rtw_hal_update_ra_mask(psta, 0); -} - -void set_sta_rate(struct adapter *padapter, struct sta_info *psta) -{ - /* rate adaptive */ - update_ra_entry(padapter, psta); -} - -static u32 get_realtek_assoc_AP_vender(struct ndis_80211_var_ie *pIE) -{ - u32 Vender = HT_IOT_PEER_REALTEK; - - if (pIE->length >= 5) { - if (pIE->data[4] == 1) - /* if (pIE->data[5] & RT_HT_CAP_USE_LONG_PREAMBLE) */ - /* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_LONG_PREAMBLE; */ - if (pIE->data[5] & RT_HT_CAP_USE_92SE) - /* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE; */ - Vender = HT_IOT_PEER_REALTEK_92SE; - - if (pIE->data[5] & RT_HT_CAP_USE_SOFTAP) - Vender = HT_IOT_PEER_REALTEK_SOFTAP; - - if (pIE->data[4] == 2) { - if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_BCUT) - Vender = HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP; - - if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_CCUT) - Vender = HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP; - } - } - - return Vender; -} - -unsigned char check_assoc_AP(u8 *pframe, uint len) -{ - unsigned int i; - struct ndis_80211_var_ie *pIE; - - for (i = sizeof(struct ndis_802_11_fix_ie); i < len;) { - pIE = (struct ndis_80211_var_ie *)(pframe + i); - - switch (pIE->element_id) { - case WLAN_EID_VENDOR_SPECIFIC: - if ((!memcmp(pIE->data, ARTHEROS_OUI1, 3)) || (!memcmp(pIE->data, ARTHEROS_OUI2, 3))) - return HT_IOT_PEER_ATHEROS; - else if ((!memcmp(pIE->data, BROADCOM_OUI1, 3)) || - (!memcmp(pIE->data, BROADCOM_OUI2, 3)) || - (!memcmp(pIE->data, BROADCOM_OUI3, 3))) - return HT_IOT_PEER_BROADCOM; - else if (!memcmp(pIE->data, MARVELL_OUI, 3)) - return HT_IOT_PEER_MARVELL; - else if (!memcmp(pIE->data, RALINK_OUI, 3)) - return HT_IOT_PEER_RALINK; - else if (!memcmp(pIE->data, CISCO_OUI, 3)) - return HT_IOT_PEER_CISCO; - else if (!memcmp(pIE->data, REALTEK_OUI, 3)) - return get_realtek_assoc_AP_vender(pIE); - else if (!memcmp(pIE->data, AIRGOCAP_OUI, 3)) - return HT_IOT_PEER_AIRGO; - break; - default: - break; - } - - i += (pIE->length + 2); - } - - return HT_IOT_PEER_UNKNOWN; -} - -void update_IOT_info(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - switch (pmlmeinfo->assoc_AP_vendor) { - case HT_IOT_PEER_MARVELL: - pmlmeinfo->turboMode_cts2self = 1; - pmlmeinfo->turboMode_rtsen = 0; - break; - - case HT_IOT_PEER_RALINK: - pmlmeinfo->turboMode_cts2self = 0; - pmlmeinfo->turboMode_rtsen = 1; - /* disable high power */ - switch_dm_func(padapter, ((u32)(~DYNAMIC_BB_DYNAMIC_TXPWR)), false); - break; - case HT_IOT_PEER_REALTEK: - /* rtw_write16(padapter, 0x4cc, 0xffff); */ - /* rtw_write16(padapter, 0x546, 0x01c0); */ - /* disable high power */ - switch_dm_func(padapter, ((u32)(~DYNAMIC_BB_DYNAMIC_TXPWR)), false); - break; - default: - pmlmeinfo->turboMode_cts2self = 0; - pmlmeinfo->turboMode_rtsen = 1; - break; - } -} - -void update_capinfo(struct adapter *Adapter, u16 updateCap) -{ - struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - bool ShortPreamble; - - /* Check preamble mode, 2005.01.06, by rcnjko. */ - /* Mark to update preamble value forever, 2008.03.18 by lanhsin */ - /* if (pMgntInfo->RegPreambleMode == PREAMBLE_AUTO) */ - { - if (updateCap & cShortPreamble) { - /* Short Preamble */ - if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) { /* PREAMBLE_LONG or PREAMBLE_AUTO */ - ShortPreamble = true; - pmlmeinfo->preamble_mode = PREAMBLE_SHORT; - rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble); - } - } else { - /* Long Preamble */ - if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) { /* PREAMBLE_SHORT or PREAMBLE_AUTO */ - ShortPreamble = false; - pmlmeinfo->preamble_mode = PREAMBLE_LONG; - rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble); - } - } - } - - if (updateCap & cIBSS) { - /* Filen: See 802.11-2007 p.91 */ - pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME; - } else { - /* Filen: See 802.11-2007 p.90 */ - if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N)) { - pmlmeinfo->slotTime = SHORT_SLOT_TIME; - } else if (pmlmeext->cur_wireless_mode & (WIRELESS_11G)) { - if ((updateCap & cShortSlotTime) /* && (!(pMgntInfo->pHTInfo->RT2RT_HT_Mode & RT_HT_CAP_USE_LONG_PREAMBLE)) */) - /* Short Slot Time */ - pmlmeinfo->slotTime = SHORT_SLOT_TIME; - else - /* Long Slot Time */ - pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME; - } else { - /* B Mode */ - pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME; - } - } - - rtw_hal_set_hwreg(Adapter, HW_VAR_SLOT_TIME, &pmlmeinfo->slotTime); -} - -void update_wireless_mode(struct adapter *padapter) -{ - int network_type = 0; - u32 SIFS_Timer; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur_network = &pmlmeinfo->network; - unsigned char *rate = cur_network->supported_rates; - - if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable)) - pmlmeinfo->HT_enable = 1; - - if (pmlmeinfo->HT_enable) - network_type = WIRELESS_11_24N; - - if (rtw_is_cckratesonly_included(rate)) - network_type |= WIRELESS_11B; - else if (rtw_is_cckrates_included(rate)) - network_type |= WIRELESS_11BG; - else - network_type |= WIRELESS_11G; - - pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode; - - SIFS_Timer = 0x0a0a0808; /* 0x0808 -> for CCK, 0x0a0a -> for OFDM */ - /* change this value if having IOT issues. */ - - SetHwReg8723BS(padapter, HW_VAR_RESP_SIFS, (u8 *)&SIFS_Timer); - - SetHwReg8723BS(padapter, HW_VAR_WIRELESS_MODE, (u8 *)&pmlmeext->cur_wireless_mode); - - if (pmlmeext->cur_wireless_mode & WIRELESS_11B) - update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB); - else - update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB); -} - -void update_sta_basic_rate(struct sta_info *psta, u8 wireless_mode) -{ - if (is_supported_tx_cck(wireless_mode)) { - /* Only B, B/G, and B/G/N AP could use CCK rate */ - memcpy(psta->bssrateset, rtw_basic_rate_cck, 4); - psta->bssratelen = 4; - } else { - memcpy(psta->bssrateset, rtw_basic_rate_ofdm, 3); - psta->bssratelen = 3; - } -} - -int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie, uint var_ie_len, int cam_idx) -{ - unsigned int ie_len; - struct ndis_80211_var_ie *pIE; - int support_rate_num = 0; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pIE = (struct ndis_80211_var_ie *)rtw_get_ie(pvar_ie, WLAN_EID_SUPP_RATES, &ie_len, var_ie_len); - if (!pIE) - return _FAIL; - if (ie_len > sizeof(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates)) - return _FAIL; - - memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates, pIE->data, ie_len); - support_rate_num = ie_len; - - pIE = (struct ndis_80211_var_ie *)rtw_get_ie(pvar_ie, WLAN_EID_EXT_SUPP_RATES, &ie_len, var_ie_len); - if (pIE && (ie_len <= sizeof(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates) - support_rate_num)) - memcpy((pmlmeinfo->FW_sta_info[cam_idx].SupportedRates + support_rate_num), pIE->data, ie_len); - - return _SUCCESS; -} - -void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr) -{ - struct sta_info *psta; - u16 tid, param; - struct recv_reorder_ctrl *preorder_ctrl; - struct sta_priv *pstapriv = &padapter->stapriv; - struct ADDBA_request *preq = (struct ADDBA_request *)paddba_req; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - psta = rtw_get_stainfo(pstapriv, addr); - - if (psta) { - param = le16_to_cpu(preq->BA_para_set); - tid = (param >> 2) & 0x0f; - - preorder_ctrl = &psta->recvreorder_ctrl[tid]; - - preorder_ctrl->indicate_seq = 0xffff; - - preorder_ctrl->enable = pmlmeinfo->accept_addba_req; - } -} - -void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len) -{ - u8 *pIE; - __le32 *pbuf; - - pIE = pframe + sizeof(struct ieee80211_hdr_3addr); - pbuf = (__le32 *)pIE; - - pmlmeext->TSFValue = le32_to_cpu(*(pbuf + 1)); - - pmlmeext->TSFValue = pmlmeext->TSFValue << 32; - - pmlmeext->TSFValue |= le32_to_cpu(*pbuf); -} - -void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext) -{ - rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, NULL); -} - -void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len) -{ - int i; - u8 *pIE; - __le32 *pbuf; - u64 tsf = 0; - u32 delay_ms; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pmlmeext->bcn_cnt++; - - pIE = pframe + sizeof(struct ieee80211_hdr_3addr); - pbuf = (__le32 *)pIE; - - tsf = le32_to_cpu(*(pbuf + 1)); - tsf = tsf << 32; - tsf |= le32_to_cpu(*pbuf); - - /* delay = (timestamp mod 1024*100)/1000 (unit: ms) */ - /* delay_ms = do_div(tsf, (pmlmeinfo->bcn_interval*1024))/1000; */ - delay_ms = do_div(tsf, (pmlmeinfo->bcn_interval * 1024)); - delay_ms = delay_ms / 1000; - - if (delay_ms >= 8) - pmlmeext->bcn_delay_cnt[8]++; - /* pmlmeext->bcn_delay_ratio[8] = (pmlmeext->bcn_delay_cnt[8] * 100) /pmlmeext->bcn_cnt; */ - else - pmlmeext->bcn_delay_cnt[delay_ms]++; - /* pmlmeext->bcn_delay_ratio[delay_ms] = (pmlmeext->bcn_delay_cnt[delay_ms] * 100) /pmlmeext->bcn_cnt; */ - /* dump for adaptive_early_32k */ - if (pmlmeext->bcn_cnt > 100 && pmlmeext->adaptive_tsf_done) { - u8 ratio_20_delay, ratio_80_delay; - u8 DrvBcnEarly, DrvBcnTimeOut; - - ratio_20_delay = 0; - ratio_80_delay = 0; - DrvBcnEarly = 0xff; - DrvBcnTimeOut = 0xff; - - for (i = 0; i < 9; i++) { - pmlmeext->bcn_delay_ratio[i] = (pmlmeext->bcn_delay_cnt[i] * 100) / pmlmeext->bcn_cnt; - - ratio_20_delay += pmlmeext->bcn_delay_ratio[i]; - ratio_80_delay += pmlmeext->bcn_delay_ratio[i]; - - if (ratio_20_delay > 20 && DrvBcnEarly == 0xff) - DrvBcnEarly = i; - - if (ratio_80_delay > 80 && DrvBcnTimeOut == 0xff) - DrvBcnTimeOut = i; - - /* reset adaptive_early_32k cnt */ - pmlmeext->bcn_delay_cnt[i] = 0; - pmlmeext->bcn_delay_ratio[i] = 0; - } - - pmlmeext->DrvBcnEarly = DrvBcnEarly; - pmlmeext->DrvBcnTimeOut = DrvBcnTimeOut; - - pmlmeext->bcn_cnt = 0; - } -} - -void rtw_alloc_macid(struct adapter *padapter, struct sta_info *psta) -{ - int i; - struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter); - - if (is_broadcast_ether_addr(psta->hwaddr)) - return; - - if (!memcmp(psta->hwaddr, myid(&padapter->eeprompriv), ETH_ALEN)) { - psta->mac_id = NUM_STA; - return; - } - - spin_lock_bh(&pdvobj->lock); - for (i = 0; i < NUM_STA; i++) { - if (!pdvobj->macid[i]) { - pdvobj->macid[i] = true; - break; - } - } - spin_unlock_bh(&pdvobj->lock); - - if (i > (NUM_STA - 1)) - psta->mac_id = NUM_STA; - else - psta->mac_id = i; -} - -void rtw_release_macid(struct adapter *padapter, struct sta_info *psta) -{ - struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter); - - if (is_broadcast_ether_addr(psta->hwaddr)) - return; - - if (!memcmp(psta->hwaddr, myid(&padapter->eeprompriv), ETH_ALEN)) - return; - - spin_lock_bh(&pdvobj->lock); - if (psta->mac_id < NUM_STA && psta->mac_id != 1) { - if (pdvobj->macid[psta->mac_id]) { - pdvobj->macid[psta->mac_id] = false; - psta->mac_id = NUM_STA; - } - } - spin_unlock_bh(&pdvobj->lock); -} diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c b/drivers/staging/rtl8723bs/core/rtw_xmit.c deleted file mode 100644 index 81d9e713fc12..000000000000 --- a/drivers/staging/rtl8723bs/core/rtw_xmit.c +++ /dev/null @@ -1,2569 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include - -static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 }; -static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 }; - -static void _init_txservq(struct tx_servq *ptxservq) -{ - INIT_LIST_HEAD(&ptxservq->tx_pending); - INIT_LIST_HEAD(&ptxservq->sta_pending.queue); - spin_lock_init(&ptxservq->sta_pending.lock); - ptxservq->qcnt = 0; -} - -void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv) -{ - memset((unsigned char *)psta_xmitpriv, 0, sizeof(struct sta_xmit_priv)); - - spin_lock_init(&psta_xmitpriv->lock); - - _init_txservq(&psta_xmitpriv->be_q); - _init_txservq(&psta_xmitpriv->bk_q); - _init_txservq(&psta_xmitpriv->vi_q); - _init_txservq(&psta_xmitpriv->vo_q); - INIT_LIST_HEAD(&psta_xmitpriv->legacy_dz); - INIT_LIST_HEAD(&psta_xmitpriv->apsd); -} - -static s32 rtw_alloc_hwxmits(struct adapter *padapter) -{ - struct hw_xmit *hwxmits; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - pxmitpriv->hwxmit_entry = HWXMIT_ENTRY; - - pxmitpriv->hwxmits = NULL; - - pxmitpriv->hwxmits = kzalloc_objs(*hwxmits, pxmitpriv->hwxmit_entry, - GFP_ATOMIC); - if (!pxmitpriv->hwxmits) - return -ENOMEM; - - hwxmits = pxmitpriv->hwxmits; - - if (pxmitpriv->hwxmit_entry == 5) { - hwxmits[0] .sta_queue = &pxmitpriv->bm_pending; - - hwxmits[1] .sta_queue = &pxmitpriv->vo_pending; - - hwxmits[2] .sta_queue = &pxmitpriv->vi_pending; - - hwxmits[3] .sta_queue = &pxmitpriv->bk_pending; - - hwxmits[4] .sta_queue = &pxmitpriv->be_pending; - } else if (pxmitpriv->hwxmit_entry == 4) { - hwxmits[0] .sta_queue = &pxmitpriv->vo_pending; - - hwxmits[1] .sta_queue = &pxmitpriv->vi_pending; - - hwxmits[2] .sta_queue = &pxmitpriv->be_pending; - - hwxmits[3] .sta_queue = &pxmitpriv->bk_pending; - } else { - } - - return 0; -} - -static int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz, u8 flag) -{ - if (alloc_sz > 0) { - pxmitbuf->pallocated_buf = kzalloc(alloc_sz, GFP_KERNEL); - if (!pxmitbuf->pallocated_buf) - return -ENOMEM; - - pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ); - } - - return 0; -} - -s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) -{ - int i; - struct xmit_buf *pxmitbuf; - struct xmit_frame *pxframe; - int res; - - spin_lock_init(&pxmitpriv->lock); - spin_lock_init(&pxmitpriv->lock_sctx); - init_completion(&pxmitpriv->xmit_comp); - init_completion(&pxmitpriv->terminate_xmitthread_comp); - - pxmitpriv->adapter = padapter; - - INIT_LIST_HEAD(&pxmitpriv->be_pending.queue); - spin_lock_init(&pxmitpriv->be_pending.lock); - INIT_LIST_HEAD(&pxmitpriv->bk_pending.queue); - spin_lock_init(&pxmitpriv->bk_pending.lock); - INIT_LIST_HEAD(&pxmitpriv->vi_pending.queue); - spin_lock_init(&pxmitpriv->vi_pending.lock); - INIT_LIST_HEAD(&pxmitpriv->vo_pending.queue); - spin_lock_init(&pxmitpriv->vo_pending.lock); - INIT_LIST_HEAD(&pxmitpriv->bm_pending.queue); - spin_lock_init(&pxmitpriv->bm_pending.lock); - - INIT_LIST_HEAD(&pxmitpriv->free_xmit_queue.queue); - spin_lock_init(&pxmitpriv->free_xmit_queue.lock); - - /* - * Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME, - * and initialize free_xmit_frame below. - * Please also apply free_txobj to link_up all the xmit_frames... - */ - - pxmitpriv->pallocated_frame_buf = vzalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4); - - if (!pxmitpriv->pallocated_frame_buf) { - pxmitpriv->pxmit_frame_buf = NULL; - return -ENOMEM; - } - pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_frame_buf), 4); - - pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf; - - for (i = 0; i < NR_XMITFRAME; i++) { - INIT_LIST_HEAD(&pxframe->list); - - pxframe->padapter = padapter; - pxframe->frame_tag = NULL_FRAMETAG; - - pxframe->pkt = NULL; - - pxframe->buf_addr = NULL; - pxframe->pxmitbuf = NULL; - - list_add_tail(&pxframe->list, - &pxmitpriv->free_xmit_queue.queue); - - pxframe++; - } - - pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME; - - pxmitpriv->frag_len = MAX_FRAG_THRESHOLD; - - /* init xmit_buf */ - INIT_LIST_HEAD(&pxmitpriv->free_xmitbuf_queue.queue); - spin_lock_init(&pxmitpriv->free_xmitbuf_queue.lock); - INIT_LIST_HEAD(&pxmitpriv->pending_xmitbuf_queue.queue); - spin_lock_init(&pxmitpriv->pending_xmitbuf_queue.lock); - - pxmitpriv->pallocated_xmitbuf = vzalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4); - - if (!pxmitpriv->pallocated_xmitbuf) - return -ENOMEM; - - pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmitbuf), 4); - - pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf; - - for (i = 0; i < NR_XMITBUFF; i++) { - INIT_LIST_HEAD(&pxmitbuf->list); - - pxmitbuf->priv_data = NULL; - pxmitbuf->padapter = padapter; - pxmitbuf->buf_tag = XMITBUF_DATA; - - /* Tx buf allocation may fail sometimes, so sleep and retry. */ - res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), true); - if (res) { - fsleep(10 * USEC_PER_MSEC); - res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), true); - if (res) - return res; - } - - pxmitbuf->phead = pxmitbuf->pbuf; - pxmitbuf->pend = pxmitbuf->pbuf + MAX_XMITBUF_SZ; - pxmitbuf->len = 0; - pxmitbuf->pdata = pxmitbuf->phead; - pxmitbuf->ptail = pxmitbuf->phead; - - pxmitbuf->flags = XMIT_VO_QUEUE; - - list_add_tail(&pxmitbuf->list, - &pxmitpriv->free_xmitbuf_queue.queue); - pxmitbuf++; - } - - pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF; - - /* init xframe_ext queue, the same count as extbuf */ - INIT_LIST_HEAD(&pxmitpriv->free_xframe_ext_queue.queue); - spin_lock_init(&pxmitpriv->free_xframe_ext_queue.lock); - - pxmitpriv->xframe_ext_alloc_addr = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_frame) + 4); - - if (!pxmitpriv->xframe_ext_alloc_addr) { - pxmitpriv->xframe_ext = NULL; - return -ENOMEM; - } - pxmitpriv->xframe_ext = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->xframe_ext_alloc_addr), 4); - pxframe = (struct xmit_frame *)pxmitpriv->xframe_ext; - - for (i = 0; i < NR_XMIT_EXTBUFF; i++) { - INIT_LIST_HEAD(&pxframe->list); - - pxframe->padapter = padapter; - pxframe->frame_tag = NULL_FRAMETAG; - - pxframe->pkt = NULL; - - pxframe->buf_addr = NULL; - pxframe->pxmitbuf = NULL; - - pxframe->ext_tag = 1; - - list_add_tail(&pxframe->list, - &pxmitpriv->free_xframe_ext_queue.queue); - - pxframe++; - } - pxmitpriv->free_xframe_ext_cnt = NR_XMIT_EXTBUFF; - - /* Init xmit extension buff */ - INIT_LIST_HEAD(&pxmitpriv->free_xmit_extbuf_queue.queue); - spin_lock_init(&pxmitpriv->free_xmit_extbuf_queue.lock); - - pxmitpriv->pallocated_xmit_extbuf = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_buf) + 4); - - if (!pxmitpriv->pallocated_xmit_extbuf) - return -ENOMEM; - - pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmit_extbuf), 4); - - pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf; - - for (i = 0; i < NR_XMIT_EXTBUFF; i++) { - INIT_LIST_HEAD(&pxmitbuf->list); - - pxmitbuf->priv_data = NULL; - pxmitbuf->padapter = padapter; - pxmitbuf->buf_tag = XMITBUF_MGNT; - - res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, MAX_XMIT_EXTBUF_SZ + XMITBUF_ALIGN_SZ, true); - if (res) - return res; - - pxmitbuf->phead = pxmitbuf->pbuf; - pxmitbuf->pend = pxmitbuf->pbuf + MAX_XMIT_EXTBUF_SZ; - pxmitbuf->len = 0; - pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead; - - list_add_tail(&pxmitbuf->list, - &pxmitpriv->free_xmit_extbuf_queue.queue); - pxmitbuf++; - } - - pxmitpriv->free_xmit_extbuf_cnt = NR_XMIT_EXTBUFF; - - for (i = 0; i < CMDBUF_MAX; i++) { - pxmitbuf = &pxmitpriv->pcmd_xmitbuf[i]; - if (pxmitbuf) { - INIT_LIST_HEAD(&pxmitbuf->list); - - pxmitbuf->priv_data = NULL; - pxmitbuf->padapter = padapter; - pxmitbuf->buf_tag = XMITBUF_CMD; - - res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, - MAX_CMDBUF_SZ + XMITBUF_ALIGN_SZ, - true); - if (res) - return res; - - pxmitbuf->phead = pxmitbuf->pbuf; - pxmitbuf->pend = pxmitbuf->pbuf + MAX_CMDBUF_SZ; - pxmitbuf->len = 0; - pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead; - pxmitbuf->alloc_sz = MAX_CMDBUF_SZ + XMITBUF_ALIGN_SZ; - } - } - - res = rtw_alloc_hwxmits(padapter); - if (res) - return res; - rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry); - - for (i = 0; i < 4; i++) - pxmitpriv->wmm_para_seq[i] = i; - - pxmitpriv->ack_tx = false; - mutex_init(&pxmitpriv->ack_tx_mutex); - rtw_sctx_init(&pxmitpriv->ack_tx_ops, 0); - - rtw_hal_init_xmit_priv(padapter); - - return 0; -} - -void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv) -{ - int i; - struct adapter *padapter = pxmitpriv->adapter; - struct xmit_frame *pxmitframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf; - struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf; - - rtw_hal_free_xmit_priv(padapter); - - if (!pxmitpriv->pxmit_frame_buf) - return; - - for (i = 0; i < NR_XMITFRAME; i++) { - rtw_os_xmit_complete(padapter, pxmitframe); - - pxmitframe++; - } - - for (i = 0; i < NR_XMITBUFF; i++) { - rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), true); - - pxmitbuf++; - } - - vfree(pxmitpriv->pallocated_frame_buf); - vfree(pxmitpriv->pallocated_xmitbuf); - - /* free xframe_ext queue, the same count as extbuf */ - pxmitframe = (struct xmit_frame *)pxmitpriv->xframe_ext; - if (pxmitframe) { - for (i = 0; i < NR_XMIT_EXTBUFF; i++) { - rtw_os_xmit_complete(padapter, pxmitframe); - pxmitframe++; - } - } - - vfree(pxmitpriv->xframe_ext_alloc_addr); - - /* free xmit extension buff */ - pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf; - for (i = 0; i < NR_XMIT_EXTBUFF; i++) { - rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMIT_EXTBUF_SZ + XMITBUF_ALIGN_SZ), true); - - pxmitbuf++; - } - - vfree(pxmitpriv->pallocated_xmit_extbuf); - - for (i = 0; i < CMDBUF_MAX; i++) { - pxmitbuf = &pxmitpriv->pcmd_xmitbuf[i]; - if (pxmitbuf) - rtw_os_xmit_resource_free(padapter, pxmitbuf, - MAX_CMDBUF_SZ + XMITBUF_ALIGN_SZ, - true); - } - - rtw_free_hwxmits(padapter); - - mutex_destroy(&pxmitpriv->ack_tx_mutex); -} - -u8 query_ra_short_GI(struct sta_info *psta) -{ - u8 sgi = false, sgi_20m = false, sgi_40m = false; - - sgi_20m = psta->htpriv.sgi_20m; - sgi_40m = psta->htpriv.sgi_40m; - - switch (psta->bw_mode) { - case CHANNEL_WIDTH_40: - sgi = sgi_40m; - break; - case CHANNEL_WIDTH_20: - default: - sgi = sgi_20m; - break; - } - - return sgi; -} - -static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - u32 sz; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - /* struct sta_info *psta = pattrib->psta; */ - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - if (pattrib->nr_frags != 1) - sz = padapter->xmitpriv.frag_len; - else /* no frag */ - sz = pattrib->last_txcmdsz; - - /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */ - /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */ - /* Other fragments are protected by previous fragment. */ - /* So we only need to check the length of first fragment. */ - if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) { - if (sz > padapter->registrypriv.rts_thresh) { - pattrib->vcs_mode = RTS_CTS; - } else { - if (pattrib->rtsen) - pattrib->vcs_mode = RTS_CTS; - else if (pattrib->cts2self) - pattrib->vcs_mode = CTS_TO_SELF; - else - pattrib->vcs_mode = NONE_VCS; - } - } else { - while (true) { - /* IOT action */ - if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS) && - pattrib->ampdu_en && - (padapter->securitypriv.dot11_privacy_algrthm == _AES_)) { - pattrib->vcs_mode = CTS_TO_SELF; - break; - } - - /* check ERP protection */ - if (pattrib->rtsen || pattrib->cts2self) { - if (pattrib->rtsen) - pattrib->vcs_mode = RTS_CTS; - else if (pattrib->cts2self) - pattrib->vcs_mode = CTS_TO_SELF; - - break; - } - - /* check HT op mode */ - if (pattrib->ht_en) { - u8 HTOpMode = pmlmeinfo->HT_protection; - - if ((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) || - (!pmlmeext->cur_bwmode && HTOpMode == 3)) { - pattrib->vcs_mode = RTS_CTS; - break; - } - } - - /* check rts */ - if (sz > padapter->registrypriv.rts_thresh) { - pattrib->vcs_mode = RTS_CTS; - break; - } - - /* to do list: check MIMO power save condition. */ - - /* check AMPDU aggregation for TXOP */ - if (pattrib->ampdu_en) { - pattrib->vcs_mode = RTS_CTS; - break; - } - - pattrib->vcs_mode = NONE_VCS; - break; - } - } - - /* for debug : force driver control vrtl_carrier_sense. */ - if (padapter->driver_vcs_en == 1) - pattrib->vcs_mode = padapter->driver_vcs_type; -} - -static void update_attrib_phy_info(struct adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta) -{ - struct mlme_ext_priv *mlmeext = &padapter->mlmeextpriv; - - pattrib->rtsen = psta->rtsen; - pattrib->cts2self = psta->cts2self; - - pattrib->mdata = 0; - pattrib->eosp = 0; - pattrib->triggered = 0; - pattrib->ampdu_spacing = 0; - - /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */ - pattrib->qos_en = psta->qos_option; - - pattrib->raid = psta->raid; - - pattrib->bwmode = min(mlmeext->cur_bwmode, psta->bw_mode); - - pattrib->sgi = query_ra_short_GI(psta); - - pattrib->ldpc = psta->ldpc; - pattrib->stbc = psta->stbc; - - pattrib->ht_en = psta->htpriv.ht_option; - pattrib->ch_offset = psta->htpriv.ch_offset; - pattrib->ampdu_en = false; - - if (padapter->driver_ampdu_spacing != 0xFF) /* driver control AMPDU Density for peer sta's rx */ - pattrib->ampdu_spacing = padapter->driver_ampdu_spacing; - else - pattrib->ampdu_spacing = psta->htpriv.rx_ampdu_min_spacing; - - pattrib->retry_ctrl = false; -} - -static int update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - signed int bmcast = is_multicast_ether_addr(pattrib->ra); - - memset(pattrib->dot118021x_UncstKey.skey, 0, 16); - memset(pattrib->dot11tkiptxmickey.skey, 0, 16); - pattrib->mac_id = psta->mac_id; - - if (psta->ieee8021x_blocked) { - pattrib->encrypt = 0; - - if ((pattrib->ether_type != 0x888e) && !check_fwstate(pmlmepriv, WIFI_MP_STATE)) - return -EINVAL; - } else { - GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast); - - switch (psecuritypriv->dot11_auth_algrthm) { - case dot11_auth_algrthm_open: - case dot11_auth_algrthm_shared: - case dot11_auth_algrthm_auto: - pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex; - break; - case dot11_auth_algrthm_8021x: - if (bmcast) - pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid; - else - pattrib->key_idx = 0; - break; - default: - pattrib->key_idx = 0; - break; - } - - /* For WPS 1.0 WEP, driver should not encrypt EAPOL Packet for WPS handshake. */ - if (((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) && (pattrib->ether_type == 0x888e)) - pattrib->encrypt = _NO_PRIVACY_; - } - - switch (pattrib->encrypt) { - case _WEP40_: - case _WEP104_: - pattrib->iv_len = 4; - pattrib->icv_len = 4; - WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); - break; - - case _TKIP_: - pattrib->iv_len = 8; - pattrib->icv_len = 4; - - if (psecuritypriv->busetkipkey == _FAIL) - return -EINVAL; - - if (bmcast) - TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); - else - TKIP_IV(pattrib->iv, psta->dot11txpn, 0); - - memcpy(pattrib->dot11tkiptxmickey.skey, psta->dot11tkiptxmickey.skey, 16); - - break; - - case _AES_: - - pattrib->iv_len = 8; - pattrib->icv_len = 8; - - if (bmcast) - AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); - else - AES_IV(pattrib->iv, psta->dot11txpn, 0); - - break; - - default: - pattrib->iv_len = 0; - pattrib->icv_len = 0; - break; - } - - if (pattrib->encrypt > 0) - memcpy(pattrib->dot118021x_UncstKey.skey, psta->dot118021x_UncstKey.skey, 16); - - if (pattrib->encrypt && - ((padapter->securitypriv.sw_encrypt) || (!psecuritypriv->hw_decrypted))) - pattrib->bswenc = true; - else - pattrib->bswenc = false; - - return 0; -} - -u8 qos_acm(u8 acm_mask, u8 priority) -{ - switch (priority) { - case 0: - case 3: - if (acm_mask & BIT(1)) - priority = 1; - break; - case 1: - case 2: - break; - case 4: - case 5: - if (acm_mask & BIT(2)) - priority = 0; - break; - case 6: - case 7: - if (acm_mask & BIT(3)) - priority = 5; - break; - default: - break; - } - - return priority; -} - -static int set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib) -{ - struct ethhdr etherhdr; - struct iphdr ip_hdr; - s32 UserPriority = 0; - int ret; - - _rtw_open_pktfile(ppktfile->pkt, ppktfile); - ret = _rtw_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN); - if (ret < 0) - return ret; - - /* get UserPriority from IP hdr */ - if (pattrib->ether_type == 0x0800) { - ret = _rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr)); - if (ret < 0) - return ret; - - UserPriority = ip_hdr.tos >> 5; - } - pattrib->priority = UserPriority; - pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN; - pattrib->subtype = WIFI_QOS_DATA_TYPE; - - return 0; -} - -static int update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pkt_attrib *pattrib) -{ - struct pkt_file pktfile; - struct sta_info *psta = NULL; - struct ethhdr etherhdr; - - signed int bmcast; - struct sta_priv *pstapriv = &padapter->stapriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct qos_priv *pqospriv = &pmlmepriv->qospriv; - int ret; - - _rtw_open_pktfile(pkt, &pktfile); - ret = _rtw_pktfile_read(&pktfile, (u8 *)ðerhdr, ETH_HLEN); - if (ret < 0) - return ret; - - pattrib->ether_type = ntohs(etherhdr.h_proto); - - memcpy(pattrib->dst, ðerhdr.h_dest, ETH_ALEN); - memcpy(pattrib->src, ðerhdr.h_source, ETH_ALEN); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - memcpy(pattrib->ra, pattrib->dst, ETH_ALEN); - memcpy(pattrib->ta, pattrib->src, ETH_ALEN); - } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN); - memcpy(pattrib->ta, pattrib->src, ETH_ALEN); - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - memcpy(pattrib->ra, pattrib->dst, ETH_ALEN); - memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN); - } - - pattrib->pktlen = pktfile.pkt_len; - - if (pattrib->ether_type == ETH_P_IP) { - /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */ - /* to prevent DHCP protocol fail */ - - u8 tmp[24]; - - ret = _rtw_pktfile_read(&pktfile, &tmp[0], 24); - if (ret < 0) - return ret; - - pattrib->dhcp_pkt = 0; - if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */ - if (pattrib->ether_type == ETH_P_IP) {/* IP header */ - if (((tmp[21] == 68) && (tmp[23] == 67)) || - ((tmp[21] == 67) && (tmp[23] == 68))) { - /* 68 : UDP BOOTP client */ - /* 67 : UDP BOOTP server */ - pattrib->dhcp_pkt = 1; - } - } - } - - /* for parsing ICMP packets */ - { - struct iphdr *piphdr = (struct iphdr *)tmp; - - pattrib->icmp_pkt = 0; - if (piphdr->protocol == 0x1) /* protocol type in ip header 0x1 is ICMP */ - pattrib->icmp_pkt = 1; - } - } else if (pattrib->ether_type == 0x888e) { - netdev_dbg(padapter->pnetdev, "send eapol packet\n"); - } - - if ((pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1)) - rtw_set_scan_deny(padapter, 3000); - - /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */ - if (pattrib->icmp_pkt == 1) - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1); - else if (pattrib->dhcp_pkt == 1) - rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1); - - bmcast = is_multicast_ether_addr(pattrib->ra); - - /* get sta_info */ - if (bmcast) { - psta = rtw_get_bcmc_stainfo(padapter); - } else { - psta = rtw_get_stainfo(pstapriv, pattrib->ra); - if (!psta) /* if we cannot get psta => drop the pkt */ - return -EINVAL; - else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) && !(psta->state & _FW_LINKED)) - return -EINVAL; - } - - if (!psta) { - /* if we cannot get psta => drop the pkt */ - return -EINVAL; - } - - if (!(psta->state & _FW_LINKED)) - return -EINVAL; - - spin_lock_bh(&psta->lock); - ret = update_attrib_sec_info(padapter, pattrib, psta); - if (ret) { - spin_unlock_bh(&psta->lock); - return ret; - } - - update_attrib_phy_info(padapter, pattrib, psta); - - pattrib->psta = psta; - spin_unlock_bh(&psta->lock); - - pattrib->pctrl = 0; - - pattrib->ack_policy = 0; - /* get ether_hdr_len */ - pattrib->pkt_hdrlen = ETH_HLEN;/* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */ - - pattrib->hdrlen = WLAN_HDR_A3_LEN; - pattrib->subtype = WIFI_DATA_TYPE; - pattrib->priority = 0; - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE | WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) { - if (pattrib->qos_en) { - ret = set_qos(&pktfile, pattrib); - if (ret < 0) - return ret; - } - } else { - if (pqospriv->qos_option) { - ret = set_qos(&pktfile, pattrib); - if (ret < 0) - return ret; - - if (pmlmepriv->acm_mask != 0) - pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority); - } - } - - /* pattrib->priority = 5; force to used VI queue, for testing */ - return 0; -} - -static int xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - signed int curfragnum, length; - u8 *pframe, *payload, mic[8]; - struct mic_data micdata; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; - u8 hw_hdr_offset = 0; - signed int bmcst = is_multicast_ether_addr(pattrib->ra); - - hw_hdr_offset = TXDESC_OFFSET; - - if (pattrib->encrypt == _TKIP_) { - /* encode mic code */ - { - u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - - pframe = pxmitframe->buf_addr + hw_hdr_offset; - - if (bmcst) { - if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)) - return -EINVAL; - /* start to calculate the mic code */ - rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey); - } else { - if (!memcmp(&pattrib->dot11tkiptxmickey.skey[0], null_key, 16)) - return -EINVAL; - /* start to calculate the mic code */ - rtw_secmicsetkey(&micdata, &pattrib->dot11tkiptxmickey.skey[0]); - } - - if (pframe[1] & 1) { /* ToDS == 1 */ - rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */ - if (pframe[1] & 2) /* From Ds == 1 */ - rtw_secmicappend(&micdata, &pframe[24], 6); - else - rtw_secmicappend(&micdata, &pframe[10], 6); - } else { /* ToDS == 0 */ - rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */ - if (pframe[1] & 2) /* From Ds == 1 */ - rtw_secmicappend(&micdata, &pframe[16], 6); - else - rtw_secmicappend(&micdata, &pframe[10], 6); - } - - if (pattrib->qos_en) - priority[0] = (u8)pxmitframe->attrib.priority; - - rtw_secmicappend(&micdata, &priority[0], 4); - - payload = pframe; - - for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { - payload = (u8 *)round_up((SIZE_PTR)(payload), 4); - payload = payload + pattrib->hdrlen + pattrib->iv_len; - - if ((curfragnum + 1) == pattrib->nr_frags) { - length = pattrib->last_txcmdsz - pattrib->hdrlen - - pattrib->iv_len - - ((pattrib->bswenc) ? pattrib->icv_len : 0); - rtw_secmicappend(&micdata, payload, length); - payload = payload + length; - } else { - length = pxmitpriv->frag_len - pattrib->hdrlen - - pattrib->iv_len - - ((pattrib->bswenc) ? pattrib->icv_len : 0); - rtw_secmicappend(&micdata, payload, length); - payload = payload + length + pattrib->icv_len; - } - } - rtw_secgetmic(&micdata, &mic[0]); - /* add mic code and add the mic code length in last_txcmdsz */ - - memcpy(payload, &mic[0], 8); - pattrib->last_txcmdsz += 8; - } - } - return 0; -} - -static s32 xmitframe_swencrypt(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - struct pkt_attrib *pattrib = &pxmitframe->attrib; - - if (pattrib->bswenc) { - switch (pattrib->encrypt) { - case _WEP40_: - case _WEP104_: - rtw_wep_encrypt(padapter, (u8 *)pxmitframe); - break; - case _TKIP_: - rtw_tkip_encrypt(padapter, (u8 *)pxmitframe); - break; - case _AES_: - rtw_aes_encrypt(padapter, (u8 *)pxmitframe); - break; - default: - break; - } - } - - return _SUCCESS; -} - -int rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib) -{ - u16 *qc; - - struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct qos_priv *pqospriv = &pmlmepriv->qospriv; - u8 qos_option = false; - __le16 *fctrl = &pwlanhdr->frame_control; - - memset(hdr, 0, WLANHDR_OFFSET); - - SetFrameSubType(fctrl, pattrib->subtype); - - if (pattrib->subtype & WIFI_DATA_TYPE) { - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - /* to_ds = 1, fr_ds = 0; */ - - { - /* 1.Data transfer to AP */ - /* 2.Arp pkt will relayed by AP */ - SetToDs(fctrl); - memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN); - memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN); - memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN); - } - - if (pqospriv->qos_option) - qos_option = true; - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - /* to_ds = 0, fr_ds = 1; */ - SetFrDs(fctrl); - memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN); - memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), ETH_ALEN); - memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN); - - if (pattrib->qos_en) - qos_option = true; - } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN); - memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN); - memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN); - - if (pattrib->qos_en) - qos_option = true; - } else { - return -EINVAL; - } - - if (pattrib->mdata) - SetMData(fctrl); - - if (pattrib->encrypt) - SetPrivacy(fctrl); - - if (qos_option) { - qc = (unsigned short *)(hdr + pattrib->hdrlen - 2); - - if (pattrib->priority) - SetPriority(qc, pattrib->priority); - - SetEOSP(qc, pattrib->eosp); - - SetAckpolicy(qc, pattrib->ack_policy); - } - - /* TODO: fill HT Control Field */ - - /* Update Seq Num will be handled by f/w */ - { - struct sta_info *psta; - - psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); - if (pattrib->psta != psta) - return -EINVAL; - - if (!psta) - return -ENOENT; - - if (!(psta->state & _FW_LINKED)) - return -ENOLINK; - - if (psta) { - psta->sta_xmitpriv.txseq_tid[pattrib->priority]++; - psta->sta_xmitpriv.txseq_tid[pattrib->priority] %= 4096u; - pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority]; - - SetSeqNum(hdr, pattrib->seqnum); - - /* check if enable ampdu */ - if (pattrib->ht_en && psta->htpriv.ampdu_enable) - if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority)) - pattrib->ampdu_en = true; - - /* re-check if enable ampdu by BA_starting_seqctrl */ - if (pattrib->ampdu_en) { - u16 tx_seq; - - tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f]; - - /* check BA_starting_seqctrl */ - if (SN_LESS(pattrib->seqnum, tx_seq)) { - pattrib->ampdu_en = false;/* AGG BK */ - } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) { - psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = - (tx_seq + 1) % 4096u; - - pattrib->ampdu_en = true;/* AGG EN */ - } else { - psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = - (pattrib->seqnum + 1) % 4096u; - - pattrib->ampdu_en = true;/* AGG EN */ - } - } - } - } - } else { - } - - return 0; -} - -s32 rtw_txframes_pending(struct adapter *padapter) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - return ((!list_empty(&pxmitpriv->be_pending.queue)) || - (!list_empty(&pxmitpriv->bk_pending.queue)) || - (!list_empty(&pxmitpriv->vi_pending.queue)) || - (!list_empty(&pxmitpriv->vo_pending.queue))); -} - -/* - * Calculate wlan 802.11 packet MAX size from pkt_attrib - * This function doesn't consider fragment case - */ -u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib) -{ - u32 len = 0; - - len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */ - len += SNAP_SIZE + sizeof(u16); /* LLC */ - len += pattrib->pktlen; - if (pattrib->encrypt == _TKIP_) - len += 8; /* MIC */ - len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */ - - return len; -} - -/* - * This sub-routine will perform all the following: - * 1. remove 802.3 header. - * 2. create wlan_header, based on the info in pxmitframe - * 3. append sta's iv/ext-iv - * 4. append LLC - * 5. move frag chunk from pframe to pxmitframe->mem - * 6. apply sw-encrypt, if necessary. - */ -int rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe) -{ - struct pkt_file pktfile; - - s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz; - - SIZE_PTR addr; - - u8 *pframe, *mem_start; - u8 hw_hdr_offset; - - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - struct pkt_attrib *pattrib = &pxmitframe->attrib; - - u8 *pbuf_start; - - s32 bmcst = is_multicast_ether_addr(pattrib->ra); - int ret; - - if (!pxmitframe->buf_addr) - return -EINVAL; - - pbuf_start = pxmitframe->buf_addr; - - hw_hdr_offset = TXDESC_OFFSET; - mem_start = pbuf_start + hw_hdr_offset; - - ret = rtw_make_wlanhdr(padapter, mem_start, pattrib); - if (ret) - return ret; - - _rtw_open_pktfile(pkt, &pktfile); - ret = _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen); - if (ret < 0) - return ret; - - frg_inx = 0; - frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */ - - while (1) { - llc_sz = 0; - - mpdu_len = frg_len; - - pframe = mem_start; - - SetMFrag(mem_start); - - pframe += pattrib->hdrlen; - mpdu_len -= pattrib->hdrlen; - - /* adding icv, if necessary... */ - if (pattrib->iv_len) { - memcpy(pframe, pattrib->iv, pattrib->iv_len); - - pframe += pattrib->iv_len; - - mpdu_len -= pattrib->iv_len; - } - - if (frg_inx == 0) { - llc_sz = rtw_put_snap(pframe, pattrib->ether_type); - pframe += llc_sz; - mpdu_len -= llc_sz; - } - - if ((pattrib->icv_len > 0) && (pattrib->bswenc)) - mpdu_len -= pattrib->icv_len; - - if (bmcst) { - /* don't do fragment to broadcast/multicast packets */ - mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen); - } else { - mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len); - } - - if (mem_sz < 0) - return mem_sz; - - pframe += mem_sz; - - if ((pattrib->icv_len > 0) && (pattrib->bswenc)) { - memcpy(pframe, pattrib->icv, pattrib->icv_len); - pframe += pattrib->icv_len; - } - - frg_inx++; - - if (bmcst || rtw_endofpktfile(&pktfile)) { - pattrib->nr_frags = frg_inx; - - pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + - ((pattrib->nr_frags == 1) ? llc_sz : 0) + - ((pattrib->bswenc) ? pattrib->icv_len : 0) + - mem_sz; - - ClearMFrag(mem_start); - - break; - } - - addr = (SIZE_PTR)(pframe); - - mem_start = (unsigned char *)round_up(addr, 4) + hw_hdr_offset; - memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen); - } - - ret = xmitframe_addmic(padapter, pxmitframe); - if (ret) - return ret; - - xmitframe_swencrypt(padapter, pxmitframe); - - if (!bmcst) - update_attrib_vcs_info(padapter, pxmitframe); - else - pattrib->vcs_mode = NONE_VCS; - - return 0; -} - -/* broadcast or multicast management pkt use BIP, unicast management pkt use CCMP encryption */ -s32 rtw_mgmt_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe) -{ - u8 *pframe, *mem_start = NULL, *tmp_buf = NULL; - u8 subtype; - struct sta_info *psta = NULL; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - s32 bmcst = is_multicast_ether_addr(pattrib->ra); - u8 *BIP_AAD = NULL; - u8 *MGMT_body = NULL; - - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct ieee80211_hdr *pwlanhdr; - u8 MME[_MME_IE_LENGTH_]; - u32 ori_len; - - mem_start = pframe = (u8 *)(pxmitframe->buf_addr) + TXDESC_OFFSET; - pwlanhdr = (struct ieee80211_hdr *)pframe; - - ori_len = BIP_AAD_SIZE + pattrib->pktlen; - BIP_AAD = kzalloc(ori_len, GFP_ATOMIC); - - if (!BIP_AAD) - return _FAIL; - - tmp_buf = BIP_AAD; - subtype = GetFrameSubType(pframe); /* bit(7)~bit(2) */ - spin_lock_bh(&padapter->security_key_mutex); - - /* only support station mode */ - if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE) || !check_fwstate(pmlmepriv, _FW_LINKED)) - goto xmitframe_coalesce_success; - - /* IGTK key is not install, it may not support 802.11w */ - if (!padapter->securitypriv.binstallBIPkey) - goto xmitframe_coalesce_success; - - /* station mode doesn't need TX BIP, just ready the code */ - if (bmcst) { - int frame_body_len; - u8 mic[16]; - - memset(MME, 0, 18); - - /* other types doesn't need the BIP */ - if (GetFrameSubType(pframe) != WIFI_DEAUTH && GetFrameSubType(pframe) != WIFI_DISASSOC) - goto xmitframe_coalesce_fail; - - MGMT_body = pframe + sizeof(struct ieee80211_hdr_3addr); - pframe += pattrib->pktlen; - - /* octent 0 and 1 is key index , BIP keyid is 4 or 5, LSB only need octent 0 */ - MME[0] = padapter->securitypriv.dot11wBIPKeyid; - /* copy packet number */ - memcpy(&MME[2], &pmlmeext->mgnt_80211w_IPN, 6); - /* increase the packet number */ - pmlmeext->mgnt_80211w_IPN++; - - /* add MME IE with MIC all zero, MME string doesn't include element id and length */ - pframe = rtw_set_ie(pframe, WLAN_EID_MMIE, 16, - MME, &pattrib->pktlen); - pattrib->last_txcmdsz = pattrib->pktlen; - /* total frame length - header length */ - frame_body_len = pattrib->pktlen - sizeof(struct ieee80211_hdr_3addr); - - /* conscruct AAD, copy frame control field */ - memcpy(BIP_AAD, &pwlanhdr->frame_control, 2); - ClearRetry(BIP_AAD); - ClearPwrMgt(BIP_AAD); - ClearMData(BIP_AAD); - /* conscruct AAD, copy address 1 to address 3 */ - memcpy(BIP_AAD + 2, &pwlanhdr->addrs, sizeof(pwlanhdr->addrs)); - /* copy management fram body */ - memcpy(BIP_AAD + BIP_AAD_SIZE, MGMT_body, frame_body_len); - /* calculate mic */ - if (omac1_aes_128(padapter->securitypriv.dot11wBIPKey[padapter->securitypriv.dot11wBIPKeyid].skey - , BIP_AAD, BIP_AAD_SIZE + frame_body_len, mic)) - goto xmitframe_coalesce_fail; - - /* copy right BIP mic value, total is 128bits, we use the 0~63 bits */ - memcpy(pframe - 8, mic, 8); - } else { /* unicast mgmt frame TX */ - /* start to encrypt mgmt frame */ - if (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC || - subtype == WIFI_REASSOCREQ || subtype == WIFI_ACTION) { - if (pattrib->psta) - psta = pattrib->psta; - else - psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); - - if (!psta) - goto xmitframe_coalesce_fail; - - if (!(psta->state & _FW_LINKED) || !pxmitframe->buf_addr) - goto xmitframe_coalesce_fail; - - /* according 802.11-2012 standard, these five types are not robust types */ - if (subtype == WIFI_ACTION && - (pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_PUBLIC || - pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_HT || - pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_UNPROTECTED_WNM || - pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_SELF_PROTECTED || - pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_P2P)) - goto xmitframe_coalesce_fail; - /* before encrypt dump the management packet content */ - if (pattrib->encrypt > 0) - memcpy(pattrib->dot118021x_UncstKey.skey, psta->dot118021x_UncstKey.skey, 16); - /* bakeup original management packet */ - memcpy(tmp_buf, pframe, pattrib->pktlen); - /* move to data portion */ - pframe += pattrib->hdrlen; - - /* 802.11w unicast management packet must be _AES_ */ - pattrib->iv_len = 8; - /* it's MIC of AES */ - pattrib->icv_len = 8; - - switch (pattrib->encrypt) { - case _AES_: - /* set AES IV header */ - AES_IV(pattrib->iv, psta->dot11wtxpn, 0); - break; - default: - goto xmitframe_coalesce_fail; - } - /* insert iv header into management frame */ - memcpy(pframe, pattrib->iv, pattrib->iv_len); - pframe += pattrib->iv_len; - /* copy mgmt data portion after CCMP header */ - memcpy(pframe, tmp_buf + pattrib->hdrlen, - pattrib->pktlen - pattrib->hdrlen); - /* move pframe to end of mgmt pkt */ - pframe += pattrib->pktlen - pattrib->hdrlen; - /* add 8 bytes CCMP IV header to length */ - pattrib->pktlen += pattrib->iv_len; - if ((pattrib->icv_len > 0) && (pattrib->bswenc)) { - memcpy(pframe, pattrib->icv, pattrib->icv_len); - pframe += pattrib->icv_len; - } - /* add 8 bytes MIC */ - pattrib->pktlen += pattrib->icv_len; - /* set final tx command size */ - pattrib->last_txcmdsz = pattrib->pktlen; - - /* set protected bit must be before SW encrypt */ - SetPrivacy(mem_start); - /* software encrypt */ - xmitframe_swencrypt(padapter, pxmitframe); - } - } - -xmitframe_coalesce_success: - spin_unlock_bh(&padapter->security_key_mutex); - kfree(BIP_AAD); - return _SUCCESS; - -xmitframe_coalesce_fail: - spin_unlock_bh(&padapter->security_key_mutex); - kfree(BIP_AAD); - return _FAIL; -} - -/* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header - * IEEE LLC/SNAP header contains 8 octets - * First 3 octets comprise the LLC portion - * SNAP portion, 5 octets, is divided into two fields: - *Organizationally Unique Identifier(OUI), 3 octets, - *type, defined by that organization, 2 octets. - */ -s32 rtw_put_snap(u8 *data, u16 h_proto) -{ - struct ieee80211_snap_hdr *snap; - u8 *oui; - - snap = (struct ieee80211_snap_hdr *)data; - snap->dsap = 0xaa; - snap->ssap = 0xaa; - snap->ctrl = 0x03; - - if (h_proto == 0x8137 || h_proto == 0x80f3) - oui = P802_1H_OUI; - else - oui = RFC1042_OUI; - - snap->oui[0] = oui[0]; - snap->oui[1] = oui[1]; - snap->oui[2] = oui[2]; - - *(__be16 *)(data + SNAP_SIZE) = htons(h_proto); - - return SNAP_SIZE + sizeof(u16); -} - -void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len) -{ - uint protection; - u8 *perp; - signed int erp_len; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct registry_priv *pregistrypriv = &padapter->registrypriv; - - switch (pxmitpriv->vcs_setting) { - case DISABLE_VCS: - pxmitpriv->vcs = NONE_VCS; - break; - - case ENABLE_VCS: - break; - - case AUTO_VCS: - default: - perp = rtw_get_ie(ie, WLAN_EID_ERP_INFO, &erp_len, ie_len); - if (!perp) { - pxmitpriv->vcs = NONE_VCS; - } else { - protection = (*(perp + 2)) & BIT(1); - if (protection) { - if (pregistrypriv->vcs_type == RTS_CTS) - pxmitpriv->vcs = RTS_CTS; - else - pxmitpriv->vcs = CTS_TO_SELF; - } else { - pxmitpriv->vcs = NONE_VCS; - } - } - - break; - } -} - -void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz) -{ - struct sta_info *psta = NULL; - struct stainfo_stats *pstats = NULL; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - u8 pkt_num = 1; - - if ((pxmitframe->frame_tag & 0x0f) == DATA_FRAMETAG) { - pkt_num = pxmitframe->agg_num; - - pmlmepriv->link_detect_info.num_tx_ok_in_period += pkt_num; - - pxmitpriv->tx_pkts += pkt_num; - - pxmitpriv->tx_bytes += sz; - - psta = pxmitframe->attrib.psta; - if (psta) { - pstats = &psta->sta_stats; - - pstats->tx_pkts += pkt_num; - - pstats->tx_bytes += sz; - } - } -} - -static struct xmit_buf *__rtw_alloc_cmd_xmitbuf(struct xmit_priv *pxmitpriv, - enum cmdbuf_type buf_type) -{ - struct xmit_buf *pxmitbuf = NULL; - - pxmitbuf = &pxmitpriv->pcmd_xmitbuf[buf_type]; - if (pxmitbuf) { - pxmitbuf->priv_data = NULL; - - pxmitbuf->len = 0; - pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead; - pxmitbuf->agg_num = 0; - pxmitbuf->pg_num = 0; - - if (pxmitbuf->sctx) - rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC); - } - - return pxmitbuf; -} - -struct xmit_frame *__rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv, - enum cmdbuf_type buf_type) -{ - struct xmit_frame *pcmdframe; - struct xmit_buf *pxmitbuf; - - pcmdframe = rtw_alloc_xmitframe(pxmitpriv); - if (!pcmdframe) - return NULL; - - pxmitbuf = __rtw_alloc_cmd_xmitbuf(pxmitpriv, buf_type); - if (!pxmitbuf) { - rtw_free_xmitframe(pxmitpriv, pcmdframe); - return NULL; - } - - pcmdframe->frame_tag = MGNT_FRAMETAG; - - pcmdframe->pxmitbuf = pxmitbuf; - - pcmdframe->buf_addr = pxmitbuf->pbuf; - - pxmitbuf->priv_data = pcmdframe; - - return pcmdframe; -} - -struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv) -{ - unsigned long irqL; - struct xmit_buf *pxmitbuf = NULL; - struct list_head *plist, *phead; - struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue; - - spin_lock_irqsave(&pfree_queue->lock, irqL); - - if (list_empty(&pfree_queue->queue)) { - pxmitbuf = NULL; - } else { - phead = get_list_head(pfree_queue); - - plist = get_next(phead); - - pxmitbuf = container_of(plist, struct xmit_buf, list); - - list_del_init(&pxmitbuf->list); - } - - if (pxmitbuf) { - pxmitpriv->free_xmit_extbuf_cnt--; - - pxmitbuf->priv_data = NULL; - - pxmitbuf->len = 0; - pxmitbuf->pdata = pxmitbuf->phead; - pxmitbuf->ptail = pxmitbuf->phead; - pxmitbuf->agg_num = 1; - - if (pxmitbuf->sctx) - rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC); - } - - spin_unlock_irqrestore(&pfree_queue->lock, irqL); - - return pxmitbuf; -} - -s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf) -{ - unsigned long irqL; - struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue; - - if (!pxmitbuf) - return _FAIL; - - spin_lock_irqsave(&pfree_queue->lock, irqL); - - list_del_init(&pxmitbuf->list); - - list_add_tail(&pxmitbuf->list, get_list_head(pfree_queue)); - pxmitpriv->free_xmit_extbuf_cnt++; - - spin_unlock_irqrestore(&pfree_queue->lock, irqL); - - return _SUCCESS; -} - -struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv) -{ - unsigned long irqL; - struct xmit_buf *pxmitbuf = NULL; - struct list_head *plist, *phead; - struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue; - - spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL); - - if (list_empty(&pfree_xmitbuf_queue->queue)) { - pxmitbuf = NULL; - } else { - phead = get_list_head(pfree_xmitbuf_queue); - - plist = get_next(phead); - - pxmitbuf = container_of(plist, struct xmit_buf, list); - - list_del_init(&pxmitbuf->list); - } - - if (pxmitbuf) { - pxmitpriv->free_xmitbuf_cnt--; - - pxmitbuf->priv_data = NULL; - - pxmitbuf->len = 0; - pxmitbuf->pdata = pxmitbuf->phead; - pxmitbuf->ptail = pxmitbuf->phead; - pxmitbuf->agg_num = 0; - pxmitbuf->pg_num = 0; - - if (pxmitbuf->sctx) - rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC); - } - - spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL); - - return pxmitbuf; -} - -s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf) -{ - unsigned long irqL; - struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue; - - if (!pxmitbuf) - return _FAIL; - - if (pxmitbuf->sctx) - rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE); - - if (pxmitbuf->buf_tag == XMITBUF_CMD) { - } else if (pxmitbuf->buf_tag == XMITBUF_MGNT) { - rtw_free_xmitbuf_ext(pxmitpriv, pxmitbuf); - } else { - spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL); - - list_del_init(&pxmitbuf->list); - - list_add_tail(&pxmitbuf->list, - get_list_head(pfree_xmitbuf_queue)); - - pxmitpriv->free_xmitbuf_cnt++; - spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL); - } - return _SUCCESS; -} - -static void rtw_init_xmitframe(struct xmit_frame *pxframe) -{ - if (pxframe) { /* default value setting */ - pxframe->buf_addr = NULL; - pxframe->pxmitbuf = NULL; - - memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib)); - - pxframe->frame_tag = DATA_FRAMETAG; - - pxframe->pg_num = 1; - pxframe->agg_num = 1; - pxframe->ack_report = 0; - } -} - -/* - * Calling context: - * 1. OS_TXENTRY - * 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack) - * - * If we turn on USE_RXTHREAD, then, no need for critical section. - * Otherwise, we must use _enter/_exit critical to protect free_xmit_queue... - * - * Must be very, very cautious... - */ -struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)/* _queue *pfree_xmit_queue) */ -{ - /* - * Please remember to use all the osdep_service api, - * and lock/unlock or _enter/_exit critical to protect - * pfree_xmit_queue - */ - - struct xmit_frame *pxframe = NULL; - struct list_head *plist, *phead; - struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue; - - spin_lock_bh(&pfree_xmit_queue->lock); - - if (list_empty(&pfree_xmit_queue->queue)) { - pxframe = NULL; - } else { - phead = get_list_head(pfree_xmit_queue); - - plist = get_next(phead); - - pxframe = container_of(plist, struct xmit_frame, list); - - list_del_init(&pxframe->list); - pxmitpriv->free_xmitframe_cnt--; - } - - spin_unlock_bh(&pfree_xmit_queue->lock); - - rtw_init_xmitframe(pxframe); - return pxframe; -} - -struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv) -{ - struct xmit_frame *pxframe = NULL; - struct list_head *plist, *phead; - struct __queue *queue = &pxmitpriv->free_xframe_ext_queue; - - spin_lock_bh(&queue->lock); - - if (list_empty(&queue->queue)) { - pxframe = NULL; - } else { - phead = get_list_head(queue); - plist = get_next(phead); - pxframe = container_of(plist, struct xmit_frame, list); - - list_del_init(&pxframe->list); - pxmitpriv->free_xframe_ext_cnt--; - } - - spin_unlock_bh(&queue->lock); - - rtw_init_xmitframe(pxframe); - - return pxframe; -} - -struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv) -{ - struct xmit_frame *pxframe = NULL; - u8 *alloc_addr; - - alloc_addr = kzalloc(sizeof(*pxframe) + 4, GFP_ATOMIC); - if (!alloc_addr) - goto exit; - - pxframe = (struct xmit_frame *)N_BYTE_ALIGMENT((SIZE_PTR)(alloc_addr), 4); - pxframe->alloc_addr = alloc_addr; - - pxframe->padapter = pxmitpriv->adapter; - pxframe->frame_tag = NULL_FRAMETAG; - - pxframe->pkt = NULL; - - pxframe->buf_addr = NULL; - pxframe->pxmitbuf = NULL; - - rtw_init_xmitframe(pxframe); - -exit: - return pxframe; -} - -s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe) -{ - struct __queue *queue = NULL; - struct adapter *padapter = pxmitpriv->adapter; - struct sk_buff *pndis_pkt = NULL; - - if (!pxmitframe) - return _SUCCESS; - - if (pxmitframe->pkt) { - pndis_pkt = pxmitframe->pkt; - pxmitframe->pkt = NULL; - } - - if (pxmitframe->alloc_addr) { - kfree(pxmitframe->alloc_addr); - goto check_pkt_complete; - } - - if (pxmitframe->ext_tag == 0) - queue = &pxmitpriv->free_xmit_queue; - else if (pxmitframe->ext_tag == 1) - queue = &pxmitpriv->free_xframe_ext_queue; - - spin_lock_bh(&queue->lock); - - list_del_init(&pxmitframe->list); - list_add_tail(&pxmitframe->list, get_list_head(queue)); - if (pxmitframe->ext_tag == 0) - pxmitpriv->free_xmitframe_cnt++; - else if (pxmitframe->ext_tag == 1) - pxmitpriv->free_xframe_ext_cnt++; - - spin_unlock_bh(&queue->lock); - -check_pkt_complete: - - if (pndis_pkt) - rtw_os_pkt_complete(padapter, pndis_pkt); - - return _SUCCESS; -} - -void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue) -{ - struct list_head *plist, *phead, *tmp; - struct xmit_frame *pxmitframe; - - spin_lock_bh(&pframequeue->lock); - - phead = get_list_head(pframequeue); - list_for_each_safe(plist, tmp, phead) { - pxmitframe = list_entry(plist, struct xmit_frame, list); - - rtw_free_xmitframe(pxmitpriv, pxmitframe); - } - spin_unlock_bh(&pframequeue->lock); -} - -/* - * Will enqueue pxmitframe to the proper queue, - * and indicate it to xx_pending list..... - */ -static int rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - u8 ac_index; - struct sta_info *psta; - struct tx_servq *ptxservq; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits; - - psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); - if (pattrib->psta != psta) - return -ENODEV; - - if (!psta) - return -EINVAL; - - if (!(psta->state & _FW_LINKED)) - return -ENETDOWN; - - ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index)); - - if (list_empty(&ptxservq->tx_pending)) - list_add_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue)); - - list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending)); - ptxservq->qcnt++; - phwxmits[ac_index].accnt++; - - return 0; -} - -int rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - int res; - - res = rtw_xmit_classifier(padapter, pxmitframe); - if (res) - return res; - - return 0; -} - -struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, signed int up, u8 *ac) -{ - struct tx_servq *ptxservq = NULL; - - switch (up) { - case 1: - case 2: - ptxservq = &psta->sta_xmitpriv.bk_q; - *(ac) = 3; - break; - - case 4: - case 5: - ptxservq = &psta->sta_xmitpriv.vi_q; - *(ac) = 1; - break; - - case 6: - case 7: - ptxservq = &psta->sta_xmitpriv.vo_q; - *(ac) = 0; - break; - - case 0: - case 3: - default: - ptxservq = &psta->sta_xmitpriv.be_q; - *(ac) = 2; - break; - } - - return ptxservq; -} - -void rtw_free_hwxmits(struct adapter *padapter) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - kfree(pxmitpriv->hwxmits); -} - -void rtw_init_hwxmits(struct hw_xmit *phwxmit, signed int entry) -{ - signed int i; - - for (i = 0; i < entry; i++, phwxmit++) - phwxmit->accnt = 0; -} - -u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe) -{ - u32 addr; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - - switch (pattrib->qsel) { - case 0: - case 3: - addr = BE_QUEUE_INX; - break; - case 1: - case 2: - addr = BK_QUEUE_INX; - break; - case 4: - case 5: - addr = VI_QUEUE_INX; - break; - case 6: - case 7: - addr = VO_QUEUE_INX; - break; - case 0x10: - addr = BCN_QUEUE_INX; - break; - case 0x11:/* BC/MC in PS (HIQ) */ - addr = HIGH_QUEUE_INX; - break; - case 0x12: - default: - addr = MGT_QUEUE_INX; - break; - } - - return addr; -} - -static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib) -{ - u8 qsel; - - qsel = pattrib->priority; - - pattrib->qsel = qsel; -} - -/* - * The main transmit(tx) entry - * - * Return - *1 enqueue - *0 success, hardware will handle this xmit frame(packet) - *<0 fail - */ -s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt) -{ - static unsigned long start; - - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct xmit_frame *pxmitframe = NULL; - - int ret; - - if (start == 0) - start = jiffies; - - pxmitframe = rtw_alloc_xmitframe(pxmitpriv); - - if (jiffies_to_msecs(jiffies - start) > 2000) - start = jiffies; - - if (!pxmitframe) - return -1; - - ret = update_attrib(padapter, *ppkt, &pxmitframe->attrib); - if (ret) { - rtw_free_xmitframe(pxmitpriv, pxmitframe); - return -1; - } - pxmitframe->pkt = *ppkt; - - do_queue_select(padapter, &pxmitframe->attrib); - - spin_lock_bh(&pxmitpriv->lock); - if (xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe)) { - spin_unlock_bh(&pxmitpriv->lock); - return 1; - } - spin_unlock_bh(&pxmitpriv->lock); - - /* pre_xmitframe */ - if (!rtw_hal_xmit(padapter, pxmitframe)) - return 1; - - return 0; -} - -#define RTW_HIQ_FILTER_ALLOW_ALL 0 -#define RTW_HIQ_FILTER_ALLOW_SPECIAL 1 -#define RTW_HIQ_FILTER_DENY_ALL 2 - -inline bool xmitframe_hiq_filter(struct xmit_frame *xmitframe) -{ - bool allow = false; - struct adapter *adapter = xmitframe->padapter; - struct registry_priv *registry = &adapter->registrypriv; - - if (registry->hiq_filter == RTW_HIQ_FILTER_ALLOW_SPECIAL) { - struct pkt_attrib *attrib = &xmitframe->attrib; - - if (attrib->ether_type == ETH_P_ARP || - attrib->ether_type == ETH_P_PAE || - attrib->dhcp_pkt - ) - allow = true; - - } else if (registry->hiq_filter == RTW_HIQ_FILTER_ALLOW_ALL) - allow = true; - else if (registry->hiq_filter == RTW_HIQ_FILTER_DENY_ALL) { - } else { - WARN_ON(1); - } - - return allow; -} - -signed int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - signed int ret = false; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct pkt_attrib *pattrib = &pxmitframe->attrib; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - signed int bmcst = is_multicast_ether_addr(pattrib->ra); - bool update_tim = false; - - if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) - return ret; - psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); - if (pattrib->psta != psta) - return false; - - if (!psta) - return false; - - if (!(psta->state & _FW_LINKED)) - return false; - - if (pattrib->triggered == 1) { - if (bmcst && xmitframe_hiq_filter(pxmitframe)) - pattrib->qsel = 0x11;/* HIQ */ - - return ret; - } - - if (bmcst) { - spin_lock_bh(&psta->sleep_q.lock); - - if (pstapriv->sta_dz_bitmap) { /* if anyone sta is in ps mode */ - /* pattrib->qsel = 0x11;HIQ */ - - list_del_init(&pxmitframe->list); - - list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q)); - - psta->sleepq_len++; - - if (!(pstapriv->tim_bitmap & BIT(0))) - update_tim = true; - - pstapriv->tim_bitmap |= BIT(0); - pstapriv->sta_dz_bitmap |= BIT(0); - - if (update_tim) - update_beacon(padapter, WLAN_EID_TIM, true); - else - chk_bmc_sleepq_cmd(padapter); - - ret = true; - } - - spin_unlock_bh(&psta->sleep_q.lock); - - return ret; - } - - spin_lock_bh(&psta->sleep_q.lock); - - if (psta->state & WIFI_SLEEP_STATE) { - u8 wmmps_ac = 0; - - if (pstapriv->sta_dz_bitmap & BIT(psta->aid)) { - list_del_init(&pxmitframe->list); - - list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q)); - - psta->sleepq_len++; - - switch (pattrib->priority) { - case 1: - case 2: - wmmps_ac = psta->uapsd_bk & BIT(0); - break; - case 4: - case 5: - wmmps_ac = psta->uapsd_vi & BIT(0); - break; - case 6: - case 7: - wmmps_ac = psta->uapsd_vo & BIT(0); - break; - case 0: - case 3: - default: - wmmps_ac = psta->uapsd_be & BIT(0); - break; - } - - if (wmmps_ac) - psta->sleepq_ac_len++; - - if (((psta->has_legacy_ac) && (!wmmps_ac)) || ((!psta->has_legacy_ac) && (wmmps_ac))) { - if (!(pstapriv->tim_bitmap & BIT(psta->aid))) - update_tim = true; - - pstapriv->tim_bitmap |= BIT(psta->aid); - - if (update_tim) - /* update BCN for TIM IE */ - update_beacon(padapter, WLAN_EID_TIM, true); - } - - ret = true; - } - } - - spin_unlock_bh(&psta->sleep_q.lock); - - return ret; -} - -static void dequeue_xmitframes_to_sleeping_queue(struct adapter *padapter, - struct sta_info *psta, - struct __queue *pframequeue) -{ - signed int ret; - struct list_head *plist, *phead, *tmp; - u8 ac_index; - struct tx_servq *ptxservq; - struct pkt_attrib *pattrib; - struct xmit_frame *pxmitframe; - struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits; - - phead = get_list_head(pframequeue); - list_for_each_safe(plist, tmp, phead) { - pxmitframe = list_entry(plist, struct xmit_frame, list); - - pattrib = &pxmitframe->attrib; - - pattrib->triggered = 0; - - ret = xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe); - - if (true == ret) { - ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index)); - - ptxservq->qcnt--; - phwxmits[ac_index].accnt--; - } else { - } - } -} - -void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta) -{ - struct sta_info *psta_bmc; - struct sta_xmit_priv *pstaxmitpriv; - struct sta_priv *pstapriv = &padapter->stapriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - pstaxmitpriv = &psta->sta_xmitpriv; - - /* for BC/MC Frames */ - psta_bmc = rtw_get_bcmc_stainfo(padapter); - - spin_lock_bh(&pxmitpriv->lock); - - psta->state |= WIFI_SLEEP_STATE; - - pstapriv->sta_dz_bitmap |= BIT(psta->aid); - - dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending); - list_del_init(&pstaxmitpriv->vo_q.tx_pending); - - dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending); - list_del_init(&pstaxmitpriv->vi_q.tx_pending); - - dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending); - list_del_init(&pstaxmitpriv->be_q.tx_pending); - - dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending); - list_del_init(&pstaxmitpriv->bk_q.tx_pending); - - /* for BC/MC Frames */ - pstaxmitpriv = &psta_bmc->sta_xmitpriv; - dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending); - list_del_init(&pstaxmitpriv->be_q.tx_pending); - - spin_unlock_bh(&pxmitpriv->lock); -} - -void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta) -{ - u8 update_mask = 0, wmmps_ac = 0; - struct sta_info *psta_bmc; - struct list_head *xmitframe_plist, *xmitframe_phead, *tmp; - struct xmit_frame *pxmitframe = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - psta_bmc = rtw_get_bcmc_stainfo(padapter); - - spin_lock_bh(&pxmitpriv->lock); - - xmitframe_phead = get_list_head(&psta->sleep_q); - list_for_each_safe(xmitframe_plist, tmp, xmitframe_phead) { - pxmitframe = list_entry(xmitframe_plist, struct xmit_frame, - list); - - list_del_init(&pxmitframe->list); - - switch (pxmitframe->attrib.priority) { - case 1: - case 2: - wmmps_ac = psta->uapsd_bk & BIT(1); - break; - case 4: - case 5: - wmmps_ac = psta->uapsd_vi & BIT(1); - break; - case 6: - case 7: - wmmps_ac = psta->uapsd_vo & BIT(1); - break; - case 0: - case 3: - default: - wmmps_ac = psta->uapsd_be & BIT(1); - break; - } - - psta->sleepq_len--; - if (psta->sleepq_len > 0) - pxmitframe->attrib.mdata = 1; - else - pxmitframe->attrib.mdata = 0; - - if (wmmps_ac) { - psta->sleepq_ac_len--; - if (psta->sleepq_ac_len > 0) { - pxmitframe->attrib.mdata = 1; - pxmitframe->attrib.eosp = 0; - } else { - pxmitframe->attrib.mdata = 0; - pxmitframe->attrib.eosp = 1; - } - } - - pxmitframe->attrib.triggered = 1; - - rtw_hal_xmitframe_enqueue(padapter, pxmitframe); - } - - if (psta->sleepq_len == 0) { - if (pstapriv->tim_bitmap & BIT(psta->aid)) - update_mask = BIT(0); - - pstapriv->tim_bitmap &= ~BIT(psta->aid); - - if (psta->state & WIFI_SLEEP_STATE) - psta->state ^= WIFI_SLEEP_STATE; - - if (psta->state & WIFI_STA_ALIVE_CHK_STATE) { - psta->expire_to = pstapriv->expire_to; - psta->state ^= WIFI_STA_ALIVE_CHK_STATE; - } - - pstapriv->sta_dz_bitmap &= ~BIT(psta->aid); - } - - /* for BC/MC Frames */ - if (!psta_bmc) - goto _exit; - - if ((pstapriv->sta_dz_bitmap & 0xfffe) == 0x0) { /* no any sta in ps mode */ - xmitframe_phead = get_list_head(&psta_bmc->sleep_q); - list_for_each_safe(xmitframe_plist, tmp, xmitframe_phead) { - pxmitframe = list_entry(xmitframe_plist, - struct xmit_frame, list); - - list_del_init(&pxmitframe->list); - - psta_bmc->sleepq_len--; - if (psta_bmc->sleepq_len > 0) - pxmitframe->attrib.mdata = 1; - else - pxmitframe->attrib.mdata = 0; - - pxmitframe->attrib.triggered = 1; - rtw_hal_xmitframe_enqueue(padapter, pxmitframe); - } - - if (psta_bmc->sleepq_len == 0) { - if (pstapriv->tim_bitmap & BIT(0)) - update_mask |= BIT(1); - - pstapriv->tim_bitmap &= ~BIT(0); - pstapriv->sta_dz_bitmap &= ~BIT(0); - } - } - -_exit: - - spin_unlock_bh(&pxmitpriv->lock); - - if (update_mask) - update_beacon(padapter, WLAN_EID_TIM, true); -} - -void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta) -{ - u8 wmmps_ac = 0; - struct list_head *xmitframe_plist, *xmitframe_phead, *tmp; - struct xmit_frame *pxmitframe = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - spin_lock_bh(&pxmitpriv->lock); - - xmitframe_phead = get_list_head(&psta->sleep_q); - list_for_each_safe(xmitframe_plist, tmp, xmitframe_phead) { - pxmitframe = list_entry(xmitframe_plist, struct xmit_frame, - list); - - switch (pxmitframe->attrib.priority) { - case 1: - case 2: - wmmps_ac = psta->uapsd_bk & BIT(1); - break; - case 4: - case 5: - wmmps_ac = psta->uapsd_vi & BIT(1); - break; - case 6: - case 7: - wmmps_ac = psta->uapsd_vo & BIT(1); - break; - case 0: - case 3: - default: - wmmps_ac = psta->uapsd_be & BIT(1); - break; - } - - if (!wmmps_ac) - continue; - - list_del_init(&pxmitframe->list); - - psta->sleepq_len--; - psta->sleepq_ac_len--; - - if (psta->sleepq_ac_len > 0) { - pxmitframe->attrib.mdata = 1; - pxmitframe->attrib.eosp = 0; - } else { - pxmitframe->attrib.mdata = 0; - pxmitframe->attrib.eosp = 1; - } - - pxmitframe->attrib.triggered = 1; - rtw_hal_xmitframe_enqueue(padapter, pxmitframe); - - if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) && (wmmps_ac)) { - pstapriv->tim_bitmap &= ~BIT(psta->aid); - - update_beacon(padapter, WLAN_EID_TIM, true); - } - } - - spin_unlock_bh(&pxmitpriv->lock); -} - -void enqueue_pending_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf) -{ - struct __queue *pqueue; - struct adapter *pri_adapter = pxmitpriv->adapter; - - pqueue = &pxmitpriv->pending_xmitbuf_queue; - - spin_lock_bh(&pqueue->lock); - list_del_init(&pxmitbuf->list); - list_add_tail(&pxmitbuf->list, get_list_head(pqueue)); - spin_unlock_bh(&pqueue->lock); - - complete(&pri_adapter->xmitpriv.xmit_comp); -} - -void enqueue_pending_xmitbuf_to_head(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf) -{ - struct __queue *pqueue; - - pqueue = &pxmitpriv->pending_xmitbuf_queue; - - spin_lock_bh(&pqueue->lock); - list_del_init(&pxmitbuf->list); - list_add(&pxmitbuf->list, get_list_head(pqueue)); - spin_unlock_bh(&pqueue->lock); -} - -struct xmit_buf *dequeue_pending_xmitbuf(struct xmit_priv *pxmitpriv) -{ - struct xmit_buf *pxmitbuf; - struct __queue *pqueue; - - pxmitbuf = NULL; - pqueue = &pxmitpriv->pending_xmitbuf_queue; - - spin_lock_bh(&pqueue->lock); - - if (!list_empty(&pqueue->queue)) { - struct list_head *plist, *phead; - - phead = get_list_head(pqueue); - plist = get_next(phead); - pxmitbuf = container_of(plist, struct xmit_buf, list); - list_del_init(&pxmitbuf->list); - } - - spin_unlock_bh(&pqueue->lock); - - return pxmitbuf; -} - -struct xmit_buf *dequeue_pending_xmitbuf_under_survey(struct xmit_priv *pxmitpriv) -{ - struct xmit_buf *pxmitbuf; - struct __queue *pqueue; - - pxmitbuf = NULL; - pqueue = &pxmitpriv->pending_xmitbuf_queue; - - spin_lock_bh(&pqueue->lock); - - if (!list_empty(&pqueue->queue)) { - struct list_head *plist, *phead; - u8 type; - - phead = get_list_head(pqueue); - plist = phead; - do { - plist = get_next(plist); - if (plist == phead) - break; - - pxmitbuf = container_of(plist, struct xmit_buf, list); - - type = GetFrameSubType(pxmitbuf->pbuf + TXDESC_OFFSET); - - if ((type == WIFI_PROBEREQ) || - (type == WIFI_DATA_NULL) || - (type == WIFI_QOS_DATA_NULL)) { - list_del_init(&pxmitbuf->list); - break; - } - pxmitbuf = NULL; - } while (1); - } - - spin_unlock_bh(&pqueue->lock); - - return pxmitbuf; -} - -signed int check_pending_xmitbuf(struct xmit_priv *pxmitpriv) -{ - struct __queue *pqueue; - signed int ret = false; - - pqueue = &pxmitpriv->pending_xmitbuf_queue; - - spin_lock_bh(&pqueue->lock); - - if (!list_empty(&pqueue->queue)) - ret = true; - - spin_unlock_bh(&pqueue->lock); - - return ret; -} - -int rtw_xmit_thread(void *context) -{ - s32 err; - struct adapter *padapter; - - err = _SUCCESS; - padapter = context; - - allow_signal(SIGTERM); - - do { - err = rtw_hal_xmit_thread_handler(padapter); - flush_signals_thread(); - } while (err == _SUCCESS); - - complete(&padapter->xmitpriv.terminate_xmitthread_comp); - - return 0; -} - -void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms) -{ - sctx->timeout_ms = timeout_ms; - sctx->submit_time = jiffies; - init_completion(&sctx->done); - sctx->status = RTW_SCTX_SUBMITTED; -} - -int rtw_sctx_wait(struct submit_ctx *sctx) -{ - int ret = _FAIL; - unsigned long expire; - int status = 0; - - expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) : MAX_SCHEDULE_TIMEOUT; - if (!wait_for_completion_timeout(&sctx->done, expire)) - /* timeout, do something?? */ - status = RTW_SCTX_DONE_TIMEOUT; - else - status = sctx->status; - - if (status == RTW_SCTX_DONE_SUCCESS) - ret = _SUCCESS; - - return ret; -} - -void rtw_sctx_done_err(struct submit_ctx **sctx, int status) -{ - if (*sctx) { - (*sctx)->status = status; - complete(&((*sctx)->done)); - *sctx = NULL; - } -} - -void rtw_sctx_done(struct submit_ctx **sctx) -{ - rtw_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS); -} - -int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms) -{ - struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops; - - pack_tx_ops->submit_time = jiffies; - pack_tx_ops->timeout_ms = timeout_ms; - pack_tx_ops->status = RTW_SCTX_SUBMITTED; - - return rtw_sctx_wait(pack_tx_ops); -} - -void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status) -{ - struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops; - - if (pxmitpriv->ack_tx) - rtw_sctx_done_err(&pack_tx_ops, status); -} diff --git a/drivers/staging/rtl8723bs/hal/Hal8723BReg.h b/drivers/staging/rtl8723bs/hal/Hal8723BReg.h deleted file mode 100644 index 0b327a70aa15..000000000000 --- a/drivers/staging/rtl8723bs/hal/Hal8723BReg.h +++ /dev/null @@ -1,65 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/***************************************************************************** - *Copyright(c) 2009, RealTEK Technology Inc. All Right Reserved. - * - * Module: __INC_HAL8723BREG_H - * - * - * Note: 1. Define Mac register address and corresponding bit mask map - * - * - * Export: Constants, macro, functions(API), global variables(None). - * - * Abbrev: - * - * History: - * Data Who Remark - * - *****************************************************************************/ -#ifndef __INC_HAL8723BREG_H -#define __INC_HAL8723BREG_H - -/* */ -/* */ -/* 0x0100h ~ 0x01FFh MACTOP General Configuration */ -/* */ -/* */ -#define REG_C2HEVT_CMD_SEQ_88XX 0x01A1 -#define REG_C2HEVT_CMD_LEN_88XX 0x01AE - -/* */ -/* */ -/* 0x0200h ~ 0x027Fh TXDMA Configuration */ -/* */ -/* */ -#define REG_DWBCN1_CTRL_8723B 0x0228 - -/* spec version 11 */ -/* */ -/* */ -/* 0x0400h ~ 0x047Fh Protocol Configuration */ -/* */ -/* */ -#define REG_FWHW_TXQ_CTRL_8723B 0x0420 -#define REG_ARFR0_8723B 0x0444 -#define REG_ARFR1_8723B 0x044C -#define REG_CCK_CHECK_8723B 0x0454 -#define REG_AMPDU_MAX_TIME_8723B 0x0456 - -#define REG_AMPDU_MAX_LENGTH_8723B 0x0458 -#define REG_DATA_SC_8723B 0x0483 -#define REG_MAX_AGGR_NUM_8723B 0x04CA - -/* */ -/* */ -/* 0x0500h ~ 0x05FFh EDCA Configuration */ -/* */ -/* */ -#define REG_PIFS_8723B 0x0512 - -/* 0x0600h ~ 0x07FFh WMAC Configuration */ -#define REG_RX_PKT_LIMIT_8723B 0x060C - -#define REG_TRXPTCL_CTL_8723B 0x0668 - -#endif /* #ifndef __INC_HAL8723BREG_H */ diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c deleted file mode 100644 index 0613beaa3752..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +++ /dev/null @@ -1,2595 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "Mp_Precomp.h" - -/* Global variables, these are static variables */ -static struct coex_dm_8723b_1ant GLCoexDm8723b1Ant; -static struct coex_dm_8723b_1ant *pCoexDm = &GLCoexDm8723b1Ant; -static struct coex_sta_8723b_1ant GLCoexSta8723b1Ant; -static struct coex_sta_8723b_1ant *pCoexSta = &GLCoexSta8723b1Ant; - -/* local function proto type if needed */ -/* local function start with halbtc8723b1ant_ */ -static u8 halbtc8723b1ant_BtRssiState( - u8 levelNum, u8 rssiThresh, u8 rssiThresh1 -) -{ - s32 btRssi = 0; - u8 btRssiState = pCoexSta->preBtRssiState; - - btRssi = pCoexSta->btRssi; - - if (levelNum == 2) { - if ( - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) || - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW) - ) { - if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT)) - - btRssiState = BTC_RSSI_STATE_HIGH; - else - btRssiState = BTC_RSSI_STATE_STAY_LOW; - } else { - if (btRssi < rssiThresh) - btRssiState = BTC_RSSI_STATE_LOW; - else - btRssiState = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (levelNum == 3) { - if (rssiThresh > rssiThresh1) - return pCoexSta->preBtRssiState; - - if ( - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) || - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW) - ) { - if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT)) - btRssiState = BTC_RSSI_STATE_MEDIUM; - else - btRssiState = BTC_RSSI_STATE_STAY_LOW; - } else if ( - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) || - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM) - ) { - if (btRssi >= (rssiThresh1 + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT)) - btRssiState = BTC_RSSI_STATE_HIGH; - else if (btRssi < rssiThresh) - btRssiState = BTC_RSSI_STATE_LOW; - else - btRssiState = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (btRssi < rssiThresh1) - btRssiState = BTC_RSSI_STATE_MEDIUM; - else - btRssiState = BTC_RSSI_STATE_STAY_HIGH; - } - } - - pCoexSta->preBtRssiState = btRssiState; - - return btRssiState; -} - -static void halbtc8723b1ant_UpdateRaMask( - struct btc_coexist *pBtCoexist, bool bForceExec, u32 disRateMask -) -{ - pCoexDm->curRaMask = disRateMask; - - if (bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask)) - pBtCoexist->fBtcSet( - pBtCoexist, - BTC_SET_ACT_UPDATE_RAMASK, - &pCoexDm->curRaMask - ); - pCoexDm->preRaMask = pCoexDm->curRaMask; -} - -static void halbtc8723b1ant_AutoRateFallbackRetry( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 type -) -{ - bool bWifiUnderBMode = false; - - pCoexDm->curArfrType = type; - - if (bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType)) { - switch (pCoexDm->curArfrType) { - case 0: /* normal mode */ - pBtCoexist->fBtcWrite4Byte( - pBtCoexist, 0x430, pCoexDm->backupArfrCnt1 - ); - pBtCoexist->fBtcWrite4Byte( - pBtCoexist, 0x434, pCoexDm->backupArfrCnt2 - ); - break; - case 1: - pBtCoexist->fBtcGet( - pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode - ); - if (bWifiUnderBMode) { - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101); - } else { - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201); - } - break; - default: - break; - } - } - - pCoexDm->preArfrType = pCoexDm->curArfrType; -} - -static void halbtc8723b1ant_RetryLimit( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 type -) -{ - pCoexDm->curRetryLimitType = type; - - if ( - bForceExec || - (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType) - ) { - switch (pCoexDm->curRetryLimitType) { - case 0: /* normal mode */ - pBtCoexist->fBtcWrite2Byte( - pBtCoexist, 0x42a, pCoexDm->backupRetryLimit - ); - break; - case 1: /* retry limit =8 */ - pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808); - break; - default: - break; - } - } - - pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType; -} - -static void halbtc8723b1ant_AmpduMaxTime( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 type -) -{ - pCoexDm->curAmpduTimeType = type; - - if ( - bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType) - ) { - switch (pCoexDm->curAmpduTimeType) { - case 0: /* normal mode */ - pBtCoexist->fBtcWrite1Byte( - pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime - ); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38); - break; - default: - break; - } - } - - pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType; -} - -static void halbtc8723b1ant_LimitedTx( - struct btc_coexist *pBtCoexist, - bool bForceExec, - u8 raMaskType, - u8 arfrType, - u8 retryLimitType, - u8 ampduTimeType -) -{ - switch (raMaskType) { - case 0: /* normal mode */ - halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7); - break; - default: - break; - } - - halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType); - halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType); - halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType); -} - -static void halbtc8723b1ant_LimitedRx( - struct btc_coexist *pBtCoexist, - bool bForceExec, - bool bRejApAggPkt, - bool bBtCtrlAggBufSize, - u8 aggBufSize -) -{ - bool bRejectRxAgg = bRejApAggPkt; - bool bBtCtrlRxAggSize = bBtCtrlAggBufSize; - u8 rxAggSize = aggBufSize; - - /* */ - /* Rx Aggregation related setting */ - /* */ - pBtCoexist->fBtcSet( - pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg - ); - /* decide BT control aggregation buf size or not */ - pBtCoexist->fBtcSet( - pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize - ); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize); - /* real update aggregation setting */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -static void halbtc8723b1ant_QueryBtInfo(struct btc_coexist *pBtCoexist) -{ - u8 H2C_Parameter[1] = {0}; - - pCoexSta->bC2hBtInfoReqSent = true; - - H2C_Parameter[0] |= BIT(0); /* trigger */ - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter); -} - -static void halbtc8723b1ant_MonitorBtCtr(struct btc_coexist *pBtCoexist) -{ - u32 regHPTxRx, regLPTxRx, u4Tmp; - u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0; - static u8 NumOfBtCounterChk; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8)) */ - - if (pCoexSta->bUnderIps) { - pCoexSta->highPriorityTx = 65535; - pCoexSta->highPriorityRx = 65535; - pCoexSta->lowPriorityTx = 65535; - pCoexSta->lowPriorityRx = 65535; - return; - } - - regHPTxRx = 0x770; - regLPTxRx = 0x774; - - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx); - regHPTx = u4Tmp & bMaskLWord; - regHPRx = (u4Tmp & bMaskHWord) >> 16; - - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx); - regLPTx = u4Tmp & bMaskLWord; - regLPRx = (u4Tmp & bMaskHWord) >> 16; - - pCoexSta->highPriorityTx = regHPTx; - pCoexSta->highPriorityRx = regHPRx; - pCoexSta->lowPriorityTx = regLPTx; - pCoexSta->lowPriorityRx = regLPRx; - - if ((pCoexSta->lowPriorityTx >= 1050) && (!pCoexSta->bC2hBtInquiryPage)) - pCoexSta->popEventCnt++; - - /* reset counter */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); - - if ((regHPTx == 0) && (regHPRx == 0) && (regLPTx == 0) && (regLPRx == 0)) { - NumOfBtCounterChk++; - if (NumOfBtCounterChk >= 3) { - halbtc8723b1ant_QueryBtInfo(pBtCoexist); - NumOfBtCounterChk = 0; - } - } -} - -static void halbtc8723b1ant_MonitorWiFiCtr(struct btc_coexist *pBtCoexist) -{ - s32 wifiRssi = 0; - bool bWifiBusy = false, bWifiUnderBMode = false; - static u8 nCCKLockCounter; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi); - pBtCoexist->fBtcGet( - pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode - ); - - if (pCoexSta->bUnderIps) { - pCoexSta->nCRCOK_CCK = 0; - pCoexSta->nCRCOK_11g = 0; - pCoexSta->nCRCOK_11n = 0; - pCoexSta->nCRCOK_11nAgg = 0; - - pCoexSta->nCRCErr_CCK = 0; - pCoexSta->nCRCErr_11g = 0; - pCoexSta->nCRCErr_11n = 0; - pCoexSta->nCRCErr_11nAgg = 0; - } else { - pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88); - pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94); - pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90); - pCoexSta->nCRCOK_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8); - - pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84); - pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96); - pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92); - pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba); - } - - /* reset counter */ - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1); - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0); - - if (bWifiBusy && (wifiRssi >= 30) && !bWifiUnderBMode) { - if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) - ) { - if ( - pCoexSta->nCRCOK_CCK > ( - pCoexSta->nCRCOK_11g + - pCoexSta->nCRCOK_11n + - pCoexSta->nCRCOK_11nAgg - ) - ) { - if (nCCKLockCounter < 5) - nCCKLockCounter++; - } else { - if (nCCKLockCounter > 0) - nCCKLockCounter--; - } - - } else { - if (nCCKLockCounter > 0) - nCCKLockCounter--; - } - } else { - if (nCCKLockCounter > 0) - nCCKLockCounter--; - } - - if (!pCoexSta->bPreCCKLock) { - - if (nCCKLockCounter >= 5) - pCoexSta->bCCKLock = true; - else - pCoexSta->bCCKLock = false; - } else { - if (nCCKLockCounter == 0) - pCoexSta->bCCKLock = false; - else - pCoexSta->bCCKLock = true; - } - - pCoexSta->bPreCCKLock = pCoexSta->bCCKLock; -} - -static bool halbtc8723b1ant_IsWifiStatusChanged(struct btc_coexist *pBtCoexist) -{ - static bool bPreWifiBusy, bPreUnder4way, bPreBtHsOn; - bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false; - bool bWifiConnected = false; - - pBtCoexist->fBtcGet( - pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected - ); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - pBtCoexist->fBtcGet( - pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way - ); - - if (bWifiConnected) { - if (bWifiBusy != bPreWifiBusy) { - bPreWifiBusy = bWifiBusy; - return true; - } - - if (bUnder4way != bPreUnder4way) { - bPreUnder4way = bUnder4way; - return true; - } - - if (bBtHsOn != bPreBtHsOn) { - bPreBtHsOn = bBtHsOn; - return true; - } - } - - return false; -} - -static void halbtc8723b1ant_UpdateBtLinkInfo(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bBtHsOn = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - - pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist; - pBtLinkInfo->bScoExist = pCoexSta->bScoExist; - pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist; - pBtLinkInfo->bPanExist = pCoexSta->bPanExist; - pBtLinkInfo->bHidExist = pCoexSta->bHidExist; - - /* work around for HS mode. */ - if (bBtHsOn) { - pBtLinkInfo->bPanExist = true; - pBtLinkInfo->bBtLinkExist = true; - } - - /* check if Sco only */ - if ( - pBtLinkInfo->bScoExist && - !pBtLinkInfo->bA2dpExist && - !pBtLinkInfo->bPanExist && - !pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bScoOnly = true; - else - pBtLinkInfo->bScoOnly = false; - - /* check if A2dp only */ - if ( - !pBtLinkInfo->bScoExist && - pBtLinkInfo->bA2dpExist && - !pBtLinkInfo->bPanExist && - !pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bA2dpOnly = true; - else - pBtLinkInfo->bA2dpOnly = false; - - /* check if Pan only */ - if ( - !pBtLinkInfo->bScoExist && - !pBtLinkInfo->bA2dpExist && - pBtLinkInfo->bPanExist && - !pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bPanOnly = true; - else - pBtLinkInfo->bPanOnly = false; - - /* check if Hid only */ - if ( - !pBtLinkInfo->bScoExist && - !pBtLinkInfo->bA2dpExist && - !pBtLinkInfo->bPanExist && - pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bHidOnly = true; - else - pBtLinkInfo->bHidOnly = false; -} - -static u8 halbtc8723b1ant_ActionAlgorithm(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bBtHsOn = false; - u8 algorithm = BT_8723B_1ANT_COEX_ALGO_UNDEFINED; - u8 numOfDiffProfile = 0; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - - if (!pBtLinkInfo->bBtLinkExist) - return algorithm; - - if (pBtLinkInfo->bScoExist) - numOfDiffProfile++; - if (pBtLinkInfo->bHidExist) - numOfDiffProfile++; - if (pBtLinkInfo->bPanExist) - numOfDiffProfile++; - if (pBtLinkInfo->bA2dpExist) - numOfDiffProfile++; - - if (numOfDiffProfile == 1) { - if (pBtLinkInfo->bScoExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_SCO; - } else { - if (pBtLinkInfo->bHidExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_HID; - } else if (pBtLinkInfo->bA2dpExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP; - } else if (pBtLinkInfo->bPanExist) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR; - } - } - } else if (numOfDiffProfile == 2) { - if (pBtLinkInfo->bScoExist) { - if (pBtLinkInfo->bHidExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_HID; - } else if (pBtLinkInfo->bA2dpExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_SCO; - } else if (pBtLinkInfo->bPanExist) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_SCO; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID; - } - } else { - if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP; - } else if (pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID; - } else if (pBtLinkInfo->bPanExist && pBtLinkInfo->bA2dpExist) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } else if (numOfDiffProfile == 3) { - if (pBtLinkInfo->bScoExist) { - if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) { - algorithm = BT_8723B_1ANT_COEX_ALGO_HID; - } else if ( - pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist - ) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID; - } else if (pBtLinkInfo->bPanExist && pBtLinkInfo->bA2dpExist) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_SCO; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID; - } - } else { - if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bPanExist && - pBtLinkInfo->bA2dpExist - ) { - if (bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP; - else - algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } else if (numOfDiffProfile >= 3) { - if (pBtLinkInfo->bScoExist) { - if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bPanExist && - pBtLinkInfo->bA2dpExist - ) { - if (!bBtHsOn) - algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID; - - } - } - } - - return algorithm; -} - -static void halbtc8723b1ant_SetSwPenaltyTxRateAdaptive( - struct btc_coexist *pBtCoexist, bool bLowPenaltyRa -) -{ - u8 H2C_Parameter[6] = {0}; - - H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */ - - if (bLowPenaltyRa) { - H2C_Parameter[1] |= BIT(0); - H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter); -} - -static void halbtc8723b1ant_LowPenaltyRa( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bLowPenaltyRa -) -{ - pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa; - - if (!bForceExec) { - if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) - return; - } - halbtc8723b1ant_SetSwPenaltyTxRateAdaptive( - pBtCoexist, pCoexDm->bCurLowPenaltyRa - ); - - pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa; -} - -static void halbtc8723b1ant_SetCoexTable( - struct btc_coexist *pBtCoexist, - u32 val0x6c0, - u32 val0x6c4, - u32 val0x6c8, - u8 val0x6cc -) -{ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0); - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4); - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8); - - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc); -} - -static void halbtc8723b1ant_CoexTable( - struct btc_coexist *pBtCoexist, - bool bForceExec, - u32 val0x6c0, - u32 val0x6c4, - u32 val0x6c8, - u8 val0x6cc -) -{ - pCoexDm->curVal0x6c0 = val0x6c0; - pCoexDm->curVal0x6c4 = val0x6c4; - pCoexDm->curVal0x6c8 = val0x6c8; - pCoexDm->curVal0x6cc = val0x6cc; - - if (!bForceExec) { - if ( - (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) && - (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) && - (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) && - (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) - ) - return; - } - - halbtc8723b1ant_SetCoexTable( - pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc - ); - - pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0; - pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4; - pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8; - pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc; -} - -static void halbtc8723b1ant_CoexTableWithType( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 type -) -{ - static const u32 table[8][2] = { - {0x55555555, 0x55555555}, - {0x55555555, 0x5a5a5a5a}, - {0x5a5a5a5a, 0x5a5a5a5a}, - {0xaaaa5555, 0xaaaa5a5a}, - {0x55555555, 0xaaaa5a5a}, - {0x5a5a5a5a, 0xaaaa5a5a}, - {0x55555555, 0xaaaaaaaa}, - {0xaaaaaaaa, 0xaaaaaaaa} - }; - - pCoexSta->nCoexTableType = type; - - if (type < 8) - halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, table[type][0], - table[type][1], 0xffffff, 0x3); -} - -static void halbtc8723b1ant_SetFwIgnoreWlanAct( - struct btc_coexist *pBtCoexist, bool bEnable -) -{ - u8 H2C_Parameter[1] = {0}; - - if (bEnable) - H2C_Parameter[0] |= BIT(0); /* function enable */ - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter); -} - -static void halbtc8723b1ant_IgnoreWlanAct( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bEnable -) -{ - pCoexDm->bCurIgnoreWlanAct = bEnable; - - if (!bForceExec) { - if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct) - return; - } - halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable); - - pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct; -} - -static void halbtc8723b1ant_SetLpsRpwm( - struct btc_coexist *pBtCoexist, u8 lpsVal, u8 rpwmVal -) -{ - u8 lps = lpsVal; - u8 rpwm = rpwmVal; - - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps); - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -static void halbtc8723b1ant_LpsRpwm( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 lpsVal, u8 rpwmVal -) -{ - pCoexDm->curLps = lpsVal; - pCoexDm->curRpwm = rpwmVal; - - if (!bForceExec) { - if ( - (pCoexDm->preLps == pCoexDm->curLps) && - (pCoexDm->preRpwm == pCoexDm->curRpwm) - ) { - return; - } - } - halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal); - - pCoexDm->preLps = pCoexDm->curLps; - pCoexDm->preRpwm = pCoexDm->curRpwm; -} - -static void halbtc8723b1ant_SwMechanism( - struct btc_coexist *pBtCoexist, bool bLowPenaltyRA -) -{ - halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA); -} - -static void halbtc8723b1ant_SetAntPath( - struct btc_coexist *pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff -) -{ - struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo; - u32 fwVer = 0, u4Tmp = 0, cntBtCalChk = 0; - bool bPgExtSwitch = false; - bool bUseExtSwitch = false; - bool bIsInMpMode = false; - u8 H2C_Parameter[2] = {0}, u1Tmp = 0; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */ - - if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch) - bUseExtSwitch = true; - - if (bInitHwCfg) { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi TRx Mask on */ - pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT TRx Mask on */ - - if (fwVer >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - H2C_Parameter[0] = 1; - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter); - } else { /* set grant_bt to high */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); - } - - /* set wlan_act control by PTA */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); - - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */ - - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1); - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff); - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3); - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77); - } else if (bWifiOff) { - if (fwVer >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - H2C_Parameter[0] = 1; - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter); - } else { /* set grant_bt to high */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); - } - - /* set wlan_act to always low */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode); - if (!bIsInMpMode) - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */ - else - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */ - - /* 0x4c[24:23]= 00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac = 0xf002 */ - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c); - u4Tmp &= ~BIT(23); - u4Tmp &= ~BIT(24); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp); - } else { - /* Use H2C to set GNT_BT to LOW */ - if (fwVer >= 0x180000) { - if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765) != 0) { - H2C_Parameter[0] = 0; - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter); - } - } else { - /* BT calibration check */ - while (cntBtCalChk <= 20) { - u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d); - cntBtCalChk++; - - if (u1Tmp & BIT(0)) - mdelay(50); - else - break; - } - - /* set grant_bt to PTA */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0); - } - - if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) != 0xc) - /* set wlan_act control by PTA */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); - } - - if (bUseExtSwitch) { - if (bInitHwCfg) { - /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */ - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c); - u4Tmp &= ~BIT(23); - u4Tmp |= BIT(24); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp); - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */ - - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) { - /* tell firmware "no antenna inverse" */ - H2C_Parameter[0] = 0; - H2C_Parameter[1] = 1; /* ext switch type */ - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter); - } else { - /* tell firmware "antenna inverse" */ - H2C_Parameter[0] = 1; - H2C_Parameter[1] = 1; /* ext switch type */ - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter); - } - } - - /* ext switch setting */ - switch (antPosType) { - case BTC_ANT_PATH_WIFI: - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); - else - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); - break; - case BTC_ANT_PATH_BT: - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); - else - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); - break; - default: - case BTC_ANT_PATH_PTA: - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); - else - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); - break; - } - - } else { - if (bInitHwCfg) { - /* 0x4c[23]= 1, 0x4c[24]= 0 Antenna control by 0x64 */ - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c); - u4Tmp |= BIT(23); - u4Tmp &= ~BIT(24); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp); - - /* Fix Ext switch Main->S1, Aux->S0 */ - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); - - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) { - - /* tell firmware "no antenna inverse" */ - H2C_Parameter[0] = 0; - H2C_Parameter[1] = 0; /* internal switch type */ - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter); - } else { - - /* tell firmware "antenna inverse" */ - H2C_Parameter[0] = 1; - H2C_Parameter[1] = 0; /* internal switch type */ - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter); - } - } - - /* internal switch setting */ - switch (antPosType) { - case BTC_ANT_PATH_WIFI: - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - else - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); - break; - case BTC_ANT_PATH_BT: - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); - else - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - break; - default: - case BTC_ANT_PATH_PTA: - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200); - else - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80); - break; - } - } -} - -static void halbtc8723b1ant_SetFwPstdma( - struct btc_coexist *pBtCoexist, u8 byte1, u8 byte2, u8 byte3, u8 byte4, u8 byte5 -) -{ - u8 H2C_Parameter[5] = {0}; - u8 realByte1 = byte1, realByte5 = byte5; - bool bApEnable = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable); - - if (bApEnable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - realByte1 &= ~BIT(4); - realByte1 |= BIT(5); - - realByte5 |= BIT(5); - realByte5 &= ~BIT(6); - } - } - - H2C_Parameter[0] = realByte1; - H2C_Parameter[1] = byte2; - H2C_Parameter[2] = byte3; - H2C_Parameter[3] = byte4; - H2C_Parameter[4] = realByte5; - - pCoexDm->psTdmaPara[0] = realByte1; - pCoexDm->psTdmaPara[1] = byte2; - pCoexDm->psTdmaPara[2] = byte3; - pCoexDm->psTdmaPara[3] = byte4; - pCoexDm->psTdmaPara[4] = realByte5; - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter); -} - -static void halbtc8723b1ant_PsTdma( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bTurnOn, u8 type -) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bWifiBusy = false; - u8 rssiAdjustVal = 0; - u8 psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10; - s8 nWiFiDurationAdjust = 0x0; - /* u32 fwVer = 0; */ - - pCoexDm->bCurPsTdmaOn = bTurnOn; - pCoexDm->curPsTdma = type; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - - if (!bForceExec) { - if ( - (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) && - (pCoexDm->prePsTdma == pCoexDm->curPsTdma) - ) - return; - } - - if (pCoexSta->nScanAPNum <= 5) - nWiFiDurationAdjust = 5; - else if (pCoexSta->nScanAPNum >= 40) - nWiFiDurationAdjust = -15; - else if (pCoexSta->nScanAPNum >= 20) - nWiFiDurationAdjust = -10; - - if (!pCoexSta->bForceLpsOn) { /* only for A2DP-only case 1/2/9/11 */ - psTdmaByte0Val = 0x61; /* no null-pkt */ - psTdmaByte3Val = 0x11; /* no tx-pause at BT-slot */ - psTdmaByte4Val = 0x10; /* 0x778 = d/1 toggle */ - } - - if (bTurnOn) { - if (pBtLinkInfo->bSlaveRole) - psTdmaByte4Val = psTdmaByte4Val | 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - - switch (type) { - default: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val - ); - break; - case 1: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, - psTdmaByte0Val, - 0x3a + nWiFiDurationAdjust, - 0x03, - psTdmaByte3Val, - psTdmaByte4Val - ); - break; - case 2: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, - psTdmaByte0Val, - 0x2d + nWiFiDurationAdjust, - 0x03, - psTdmaByte3Val, - psTdmaByte4Val - ); - break; - case 3: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x10 - ); - break; - case 4: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0 - ); - break; - case 5: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10 - ); - break; - case 6: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x11 - ); - break; - case 7: - halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0); - break; - case 8: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0 - ); - break; - case 9: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, - psTdmaByte0Val, - 0x21, - 0x3, - psTdmaByte3Val, - psTdmaByte4Val - ); - break; - case 10: - halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40); - break; - case 11: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, - psTdmaByte0Val, - 0x21, - 0x03, - psTdmaByte3Val, - psTdmaByte4Val - ); - break; - case 12: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50 - ); - break; - case 13: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x10 - ); - break; - case 14: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x51, 0x21, 0x3, 0x10, psTdmaByte4Val - ); - break; - case 15: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0 - ); - break; - case 16: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0 - ); - break; - case 18: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0 - ); - break; - case 20: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x61, 0x3f, 0x03, 0x11, 0x10 - - ); - break; - case 21: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11 - ); - break; - case 22: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10 - ); - break; - case 23: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18 - ); - break; - case 24: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18 - ); - break; - case 25: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18 - ); - break; - case 26: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18 - ); - break; - case 27: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98 - ); - break; - case 28: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0 - ); - break; - case 29: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10 - ); - break; - case 30: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10 - ); - break; - case 31: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x58 - ); - break; - case 32: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11 - ); - break; - case 33: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90 - ); - break; - case 34: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10 - ); - break; - case 35: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10 - ); - break; - case 36: - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50 - ); - break; - case 40: /* SoftAP only with no sta associated, BT disable , TDMA mode for power saving */ - /* here softap mode screen off will cost 70-80mA for phone */ - halbtc8723b1ant_SetFwPstdma( - pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24 - ); - break; - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0); - halbtc8723b1ant_SetAntPath( - pBtCoexist, BTC_ANT_PATH_PTA, false, false - ); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0); - halbtc8723b1ant_SetAntPath( - pBtCoexist, BTC_ANT_PATH_BT, false, false - ); - break; - case 9: /* Software control, Antenna at WiFi side */ - halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0); - halbtc8723b1ant_SetAntPath( - pBtCoexist, BTC_ANT_PATH_WIFI, false, false - ); - break; - } - } - - rssiAdjustVal = 0; - pBtCoexist->fBtcSet( - pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal - ); - - /* update pre state */ - pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn; - pCoexDm->prePsTdma = pCoexDm->curPsTdma; -} - -static bool halbtc8723b1ant_IsCommonAction(struct btc_coexist *pBtCoexist) -{ - bool bCommon = false, bWifiConnected = false, bWifiBusy = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - - if ( - !bWifiConnected && - pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE - ) { - /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */ - - bCommon = true; - } else if ( - bWifiConnected && - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE) - ) { - /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */ - - bCommon = true; - } else if ( - !bWifiConnected && - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE) - ) { - /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */ - - bCommon = true; - } else if ( - bWifiConnected && - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE) - ) { - /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */ - - bCommon = true; - } else if ( - !bWifiConnected && - (pCoexDm->btStatus != BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE) - ) { - /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */ - - bCommon = true; - } else { - bCommon = false; - } - - return bCommon; -} - -static void halbtc8723b1ant_TdmaDurationAdjustForAcl( - struct btc_coexist *pBtCoexist, u8 wifiStatus -) -{ - static s32 up, dn, m, n, WaitCount; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retryCount = 0, btInfoExt; - - if ( - (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN) || - (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN) || - (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT) - ) { - if ( - pCoexDm->curPsTdma != 1 && - pCoexDm->curPsTdma != 2 && - pCoexDm->curPsTdma != 3 && - pCoexDm->curPsTdma != 9 - ) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9); - pCoexDm->psTdmaDuAdjType = 9; - - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - WaitCount = 0; - } - return; - } - - if (!pCoexDm->bAutoTdmaAdjust) { - pCoexDm->bAutoTdmaAdjust = true; - - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2); - pCoexDm->psTdmaDuAdjType = 2; - /* */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - WaitCount = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retryCount = pCoexSta->btRetryCnt; - btInfoExt = pCoexSta->btInfoExt; - - if (pCoexSta->lowPriorityTx > 1050 || pCoexSta->lowPriorityRx > 1250) - retryCount++; - - result = 0; - WaitCount++; - - if (retryCount == 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */ - WaitCount = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retryCount <= 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */ - if (WaitCount <= 2) - m++; /* 避免一直在兩個level中來回 */ - else - m = 1; - - if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - WaitCount = 0; - result = -1; - } - } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */ - if (WaitCount == 1) - m++; /* 避免一直在兩個level中來回 */ - else - m = 1; - - if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - WaitCount = 0; - result = -1; - } - - if (result == -1) { - if ( - BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt) && - ((pCoexDm->curPsTdma == 1) || (pCoexDm->curPsTdma == 2)) - ) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9); - pCoexDm->psTdmaDuAdjType = 9; - } else if (pCoexDm->curPsTdma == 1) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2); - pCoexDm->psTdmaDuAdjType = 2; - } else if (pCoexDm->curPsTdma == 2) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9); - pCoexDm->psTdmaDuAdjType = 9; - } else if (pCoexDm->curPsTdma == 9) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11); - pCoexDm->psTdmaDuAdjType = 11; - } - } else if (result == 1) { - if ( - BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt) && - ((pCoexDm->curPsTdma == 1) || (pCoexDm->curPsTdma == 2)) - ) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9); - pCoexDm->psTdmaDuAdjType = 9; - } else if (pCoexDm->curPsTdma == 11) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9); - pCoexDm->psTdmaDuAdjType = 9; - } else if (pCoexDm->curPsTdma == 9) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2); - pCoexDm->psTdmaDuAdjType = 2; - } else if (pCoexDm->curPsTdma == 2) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1); - pCoexDm->psTdmaDuAdjType = 1; - } - } - - if ( - pCoexDm->curPsTdma != 1 && - pCoexDm->curPsTdma != 2 && - pCoexDm->curPsTdma != 9 && - pCoexDm->curPsTdma != 11 - ) /* recover to previous adjust type */ - halbtc8723b1ant_PsTdma( - pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType - ); - } -} - -static void halbtc8723b1ant_PsTdmaCheckForPowerSaveState( - struct btc_coexist *pBtCoexist, bool bNewPsState -) -{ - u8 lpsMode = 0x0; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode); - - if (lpsMode) { /* already under LPS state */ - if (bNewPsState) { - /* keep state under LPS, do nothing. */ - } else { /* will leave LPS state, turn off psTdma first */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); - } - } else { /* NO PS state */ - if (bNewPsState) { /* will enter LPS state, turn off psTdma first */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -static void halbtc8723b1ant_PowerSaveState( - struct btc_coexist *pBtCoexist, u8 psType, u8 lpsVal, u8 rpwmVal -) -{ - bool bLowPwrDisable = false; - - switch (psType) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - bLowPwrDisable = false; - pBtCoexist->fBtcSet( - pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable - ); - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL); - pCoexSta->bForceLpsOn = false; - break; - case BTC_PS_LPS_ON: - halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, true); - halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal); - /* when coex force to enter LPS, do not enter 32k low power. */ - bLowPwrDisable = true; - pBtCoexist->fBtcSet( - pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable - ); - /* power save must executed before psTdma. */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL); - pCoexSta->bForceLpsOn = true; - break; - case BTC_PS_LPS_OFF: - halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, false); - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL); - pCoexSta->bForceLpsOn = false; - break; - default: - break; - } -} - -/* */ -/* */ -/* Software Coex Mechanism start */ -/* */ -/* */ - -/* */ -/* */ -/* Non-Software Coex Mechanism start */ -/* */ -/* */ -static void halbtc8723b1ant_ActionWifiMultiPort(struct btc_coexist *pBtCoexist) -{ - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); -} - -static void halbtc8723b1ant_ActionHs(struct btc_coexist *pBtCoexist) -{ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); -} - -static void halbtc8723b1ant_ActionBtInquiry(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bWifiConnected = false; - bool bApEnable = false; - bool bWifiBusy = false; - bool bBtBusy = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy); - - if (!bWifiConnected && !pCoexSta->bWiFiIsHighPriTask) { - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - } else if ( - pBtLinkInfo->bScoExist || - pBtLinkInfo->bHidExist || - pBtLinkInfo->bA2dpExist - ) { - /* SCO/HID/A2DP busy */ - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else if (pBtLinkInfo->bPanExist || bWifiBusy) { - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20); - - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - } -} - -static void halbtc8723b1ant_ActionBtScoHidOnlyBusy( - struct btc_coexist *pBtCoexist, u8 wifiStatus -) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bWifiConnected = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - - /* tdma and coex table */ - - if (pBtLinkInfo->bScoExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5); - } else { /* HID */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5); - } -} - -static void halbtc8723b1ant_ActionWifiConnectedBtAclBusy( - struct btc_coexist *pBtCoexist, u8 wifiStatus -) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - - halbtc8723b1ant_BtRssiState(2, 28, 0); - - if ((pCoexSta->lowPriorityRx >= 1000) && (pCoexSta->lowPriorityRx != 65535)) - pBtLinkInfo->bSlaveRole = true; - else - pBtLinkInfo->bSlaveRole = false; - - if (pBtLinkInfo->bHidOnly) { /* HID */ - halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus); - pCoexDm->bAutoTdmaAdjust = false; - return; - } else if (pBtLinkInfo->bA2dpOnly) { /* A2DP */ - if (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - pCoexDm->bAutoTdmaAdjust = false; - } else { - halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - pCoexDm->bAutoTdmaAdjust = true; - } - } else if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) { /* HID+A2DP */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14); - pCoexDm->bAutoTdmaAdjust = false; - - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else if ( - pBtLinkInfo->bPanOnly || - (pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist) - ) { /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - pCoexDm->bAutoTdmaAdjust = false; - } else if ( - (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) || - (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) - ) { /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - pCoexDm->bAutoTdmaAdjust = false; - } else { - /* BT no-profile busy (0x9) */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - pCoexDm->bAutoTdmaAdjust = false; - } -} - -static void halbtc8723b1ant_ActionWifiNotConnected(struct btc_coexist *pBtCoexist) -{ - /* power save state */ - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - /* tdma and coex table */ - halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); -} - -static void halbtc8723b1ant_ActionWifiNotConnectedScan( - struct btc_coexist *pBtCoexist -) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - /* tdma and coex table */ - if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { - if (pBtLinkInfo->bA2dpExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } - } else if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) - ) { - halbtc8723b1ant_ActionBtScoHidOnlyBusy( - pBtCoexist, BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN - ); - } else { - /* Bryant Add */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - } -} - -static void halbtc8723b1ant_ActionWifiNotConnectedAssoAuth( - struct btc_coexist *pBtCoexist -) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - /* tdma and coex table */ - if ( - (pBtLinkInfo->bScoExist) || - (pBtLinkInfo->bHidExist) || - (pBtLinkInfo->bA2dpExist) - ) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else if (pBtLinkInfo->bPanExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - } -} - -static void halbtc8723b1ant_ActionWifiConnectedScan(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - /* tdma and coex table */ - if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { - if (pBtLinkInfo->bA2dpExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } - } else if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) - ) { - halbtc8723b1ant_ActionBtScoHidOnlyBusy( - pBtCoexist, BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN - ); - } else { - /* Bryant Add */ - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - } -} - -static void halbtc8723b1ant_ActionWifiConnectedSpecialPacket( - struct btc_coexist *pBtCoexist -) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - /* tdma and coex table */ - if ( - (pBtLinkInfo->bScoExist) || - (pBtLinkInfo->bHidExist) || - (pBtLinkInfo->bA2dpExist) - ) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else if (pBtLinkInfo->bPanExist) { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - } -} - -static void halbtc8723b1ant_ActionWifiConnected(struct btc_coexist *pBtCoexist) -{ - bool bWifiBusy = false; - bool bScan = false, bLink = false, bRoam = false; - bool bUnder4way = false, bApEnable = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way); - if (bUnder4way) { - halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist); - return; - } - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam); - if (bScan || bLink || bRoam) { - if (bScan) - halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist); - else - halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist); - return; - } - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - - /* power save state */ - if ( - !bApEnable && - pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY && - !pBtCoexist->btLinkInfo.bHidOnly - ) { - if (pBtCoexist->btLinkInfo.bA2dpOnly) { /* A2DP */ - if (!bWifiBusy) - halbtc8723b1ant_PowerSaveState( - pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0 - ); - else { /* busy */ - if (pCoexSta->nScanAPNum >= BT_8723B_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */ - halbtc8723b1ant_PowerSaveState( - pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0 - ); - else - halbtc8723b1ant_PowerSaveState( - pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4 - ); - } - } else if ( - (!pCoexSta->bPanExist) && - (!pCoexSta->bA2dpExist) && - (!pCoexSta->bHidExist) - ) - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - else - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4); - } else { - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - } - - /* tdma and coex table */ - if (!bWifiBusy) { - if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { - halbtc8723b1ant_ActionWifiConnectedBtAclBusy( - pBtCoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE - ); - } else if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) - ) { - halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - - if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60) - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - } - } else { - if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { - halbtc8723b1ant_ActionWifiConnectedBtAclBusy( - pBtCoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY - ); - } else if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) - ) { - halbtc8723b1ant_ActionBtScoHidOnlyBusy( - pBtCoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY - ); - } else { - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8); - - if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60) - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - } - } -} - -static void halbtc8723b1ant_RunSwCoexistMechanism(struct btc_coexist *pBtCoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist); - pCoexDm->curAlgorithm = algorithm; - - if (halbtc8723b1ant_IsCommonAction(pBtCoexist)) { - - } else { - pCoexDm->preAlgorithm = pCoexDm->curAlgorithm; - } -} - -static void halbtc8723b1ant_RunCoexistMechanism(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bWifiConnected = false, bBtHsOn = false; - bool bIncreaseScanDevNum = false; - bool bBtCtrlAggBufSize = false; - u8 aggBufSize = 5; - u32 wifiLinkStatus = 0; - u32 numOfWifiLink = 0; - - if (pBtCoexist->bManualControl) - return; - - if (pBtCoexist->bStopCoexDm) - return; - - if (pCoexSta->bUnderIps) - return; - - if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) - ){ - bIncreaseScanDevNum = true; - } - - pBtCoexist->fBtcSet( - pBtCoexist, - BTC_SET_BL_INC_SCAN_DEV_NUM, - &bIncreaseScanDevNum - ); - pBtCoexist->fBtcGet( - pBtCoexist, - BTC_GET_BL_WIFI_CONNECTED, - &bWifiConnected - ); - - pBtCoexist->fBtcGet( - pBtCoexist, - BTC_GET_U4_WIFI_LINK_STATUS, - &wifiLinkStatus - ); - numOfWifiLink = wifiLinkStatus >> 16; - - if ((numOfWifiLink >= 2) || (wifiLinkStatus & WIFI_P2P_GO_CONNECTED)) { - halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize); - - if ((pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage)) - halbtc8723b1ant_ActionBtInquiry(pBtCoexist); - else - halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist); - - return; - } - - if ((pBtLinkInfo->bBtLinkExist) && (bWifiConnected)) { - halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1); - - if (pBtLinkInfo->bScoExist) - halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5); - else - halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x8); - - halbtc8723b1ant_SwMechanism(pBtCoexist, true); - halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */ - } else { - halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x5); - - halbtc8723b1ant_SwMechanism(pBtCoexist, false); - halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */ - } - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - if (pCoexSta->bC2hBtInquiryPage) { - halbtc8723b1ant_ActionBtInquiry(pBtCoexist); - return; - } else if (bBtHsOn) { - halbtc8723b1ant_ActionHs(pBtCoexist); - return; - } - - if (!bWifiConnected) { - bool bScan = false, bLink = false, bRoam = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam); - - if (bScan || bLink || bRoam) { - if (bScan) - halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist); - else - halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist); - } else - halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist); - } else { /* wifi LPS/Busy */ - halbtc8723b1ant_ActionWifiConnected(pBtCoexist); - } -} - -static void halbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist) -{ - /* force to reset coex mechanism */ - - /* sw all off */ - halbtc8723b1ant_SwMechanism(pBtCoexist, false); - - /* halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); */ - halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0); - - pCoexSta->popEventCnt = 0; -} - -static void halbtc8723b1ant_InitHwConfig( - struct btc_coexist *pBtCoexist, - bool bBackUp, - bool bWifiOnly -) -{ - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); /* enable TBTT nterrupt */ - - /* 0x790[5:0]= 0x5 */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5); - - /* Enable counter statistics */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1); - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1); - - /* Antenna config */ - if (bWifiOnly) { - halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, true, false); - halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 9); - } else { - halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, true, false); - } - - /* PTA parameter */ - halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0); - - pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948); - pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765); - pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67); -} - -/* */ -/* work around function start with wa_halbtc8723b1ant_ */ -/* */ -/* */ -/* extern function start with EXhalbtc8723b1ant_ */ -/* */ -void EXhalbtc8723b1ant_PowerOnSetting(struct btc_coexist *pBtCoexist) -{ - struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo; - u8 u1Tmp = 0x0; - u16 u2Tmp = 0x0; - - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20); - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2); - pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp | BIT(0) | BIT(1)); - - /* set GRAN_BT = 1 */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); - /* set WLAN_ACT = 0 */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */ - if (pBtCoexist->chipInterface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - - u1Tmp |= 0x1; /* antenna inverse */ - pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp); - - pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT; - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (pBoardInfo->singleAntPath == 0) { - /* set to S1 */ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); - pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; - } else if (pBoardInfo->singleAntPath == 1) { - /* set to S0 */ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - u1Tmp |= 0x1; /* antenna inverse */ - pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT; - } - - if (pBtCoexist->chipInterface == BTC_INTF_PCI) - pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp); - else if (pBtCoexist->chipInterface == BTC_INTF_SDIO) - pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp); - } -} - -void EXhalbtc8723b1ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bWifiOnly) -{ - halbtc8723b1ant_InitHwConfig(pBtCoexist, true, bWifiOnly); -} - -void EXhalbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist) -{ - pBtCoexist->bStopCoexDm = false; - - halbtc8723b1ant_InitCoexDm(pBtCoexist); - - halbtc8723b1ant_QueryBtInfo(pBtCoexist); -} - -void EXhalbtc8723b1ant_IpsNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm) - return; - - if (type == BTC_IPS_ENTER) { - pCoexSta->bUnderIps = true; - - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true); - } else if (type == BTC_IPS_LEAVE) { - pCoexSta->bUnderIps = false; - - halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false); - halbtc8723b1ant_InitCoexDm(pBtCoexist); - halbtc8723b1ant_QueryBtInfo(pBtCoexist); - } -} - -void EXhalbtc8723b1ant_LpsNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm) - return; - - if (type == BTC_LPS_ENABLE) - pCoexSta->bUnderLps = true; - else if (type == BTC_LPS_DISABLE) - pCoexSta->bUnderLps = false; -} - -void EXhalbtc8723b1ant_ScanNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - bool bWifiConnected = false, bBtHsOn = false; - u32 wifiLinkStatus = 0; - u32 numOfWifiLink = 0; - bool bBtCtrlAggBufSize = false; - u8 aggBufSize = 5; - - if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm) - return; - - if (type == BTC_SCAN_START) { - pCoexSta->bWiFiIsHighPriTask = true; - - halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); /* Force antenna setup for no scan result issue */ - pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948); - pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765); - pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67); - } else { - pCoexSta->bWiFiIsHighPriTask = false; - - pBtCoexist->fBtcGet( - pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum - ); - } - - if (pBtCoexist->btInfo.bBtDisabled) - return; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - - halbtc8723b1ant_QueryBtInfo(pBtCoexist); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus); - numOfWifiLink = wifiLinkStatus >> 16; - - if (numOfWifiLink >= 2) { - halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_LimitedRx( - pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize - ); - halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist); - return; - } - - if (pCoexSta->bC2hBtInquiryPage) { - halbtc8723b1ant_ActionBtInquiry(pBtCoexist); - return; - } else if (bBtHsOn) { - halbtc8723b1ant_ActionHs(pBtCoexist); - return; - } - - if (type == BTC_SCAN_START) { - if (!bWifiConnected) /* non-connected scan */ - halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist); - else /* wifi is connected */ - halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist); - } else if (type == BTC_SCAN_FINISH) { - if (!bWifiConnected) /* non-connected scan */ - halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist); - else - halbtc8723b1ant_ActionWifiConnected(pBtCoexist); - } -} - -void EXhalbtc8723b1ant_ConnectNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - bool bWifiConnected = false, bBtHsOn = false; - u32 wifiLinkStatus = 0; - u32 numOfWifiLink = 0; - bool bBtCtrlAggBufSize = false; - u8 aggBufSize = 5; - - if ( - pBtCoexist->bManualControl || - pBtCoexist->bStopCoexDm || - pBtCoexist->btInfo.bBtDisabled - ) - return; - - if (type == BTC_ASSOCIATE_START) { - pCoexSta->bWiFiIsHighPriTask = true; - pCoexDm->nArpCnt = 0; - } else { - pCoexSta->bWiFiIsHighPriTask = false; - /* pCoexDm->nArpCnt = 0; */ - } - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus); - numOfWifiLink = wifiLinkStatus >> 16; - if (numOfWifiLink >= 2) { - halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize); - halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist); - return; - } - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - if (pCoexSta->bC2hBtInquiryPage) { - halbtc8723b1ant_ActionBtInquiry(pBtCoexist); - return; - } else if (bBtHsOn) { - halbtc8723b1ant_ActionHs(pBtCoexist); - return; - } - - if (type == BTC_ASSOCIATE_START) { - halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist); - } else if (type == BTC_ASSOCIATE_FINISH) { - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - if (!bWifiConnected) /* non-connected scan */ - halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist); - else - halbtc8723b1ant_ActionWifiConnected(pBtCoexist); - } -} - -void EXhalbtc8723b1ant_MediaStatusNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - u8 H2C_Parameter[3] = {0}; - u32 wifiBw; - u8 wifiCentralChnl; - bool bWifiUnderBMode = false; - - if ( - pBtCoexist->bManualControl || - pBtCoexist->bStopCoexDm || - pBtCoexist->btInfo.bBtDisabled - ) - return; - - if (type == BTC_MEDIA_CONNECT) { - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (bWifiUnderBMode) { - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); /* CCK Tx */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); /* CCK Rx */ - } else { - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); /* CCK Tx */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); /* CCK Rx */ - } - - pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430); - pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434); - pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a); - pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456); - } else { - pCoexDm->nArpCnt = 0; - - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); /* CCK Tx */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); /* CCK Rx */ - } - - /* only 2.4G we need to inform bt the chnl mask */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl); - if ((type == BTC_MEDIA_CONNECT) && (wifiCentralChnl <= 14)) { - /* H2C_Parameter[0] = 0x1; */ - H2C_Parameter[0] = 0x0; - H2C_Parameter[1] = wifiCentralChnl; - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - - if (wifiBw == BTC_WIFI_BW_HT40) - H2C_Parameter[2] = 0x30; - else - H2C_Parameter[2] = 0x20; - } - - pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0]; - pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1]; - pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2]; - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter); -} - -void EXhalbtc8723b1ant_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - bool bBtHsOn = false; - u32 wifiLinkStatus = 0; - u32 numOfWifiLink = 0; - bool bBtCtrlAggBufSize = false; - u8 aggBufSize = 5; - - if ( - pBtCoexist->bManualControl || - pBtCoexist->bStopCoexDm || - pBtCoexist->btInfo.bBtDisabled - ) - return; - - if ( - type == BTC_PACKET_DHCP || - type == BTC_PACKET_EAPOL || - type == BTC_PACKET_ARP - ) { - if (type == BTC_PACKET_ARP) { - pCoexDm->nArpCnt++; - - if (pCoexDm->nArpCnt >= 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) */ - pCoexSta->bWiFiIsHighPriTask = false; - else - pCoexSta->bWiFiIsHighPriTask = true; - } else { - pCoexSta->bWiFiIsHighPriTask = true; - } - } else { - pCoexSta->bWiFiIsHighPriTask = false; - } - - pCoexSta->specialPktPeriodCnt = 0; - - pBtCoexist->fBtcGet( - pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus - ); - numOfWifiLink = wifiLinkStatus >> 16; - - if (numOfWifiLink >= 2) { - halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_LimitedRx( - pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize - ); - halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist); - return; - } - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - if (pCoexSta->bC2hBtInquiryPage) { - halbtc8723b1ant_ActionBtInquiry(pBtCoexist); - return; - } else if (bBtHsOn) { - halbtc8723b1ant_ActionHs(pBtCoexist); - return; - } - - if ( - type == BTC_PACKET_DHCP || - type == BTC_PACKET_EAPOL || - ((type == BTC_PACKET_ARP) && (pCoexSta->bWiFiIsHighPriTask)) - ) - halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist); -} - -void EXhalbtc8723b1ant_BtInfoNotify( - struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length -) -{ - u8 btInfo = 0; - u8 i, rspSource = 0; - bool bWifiConnected = false; - bool bBtBusy = false; - - pCoexSta->bC2hBtInfoReqSent = false; - - rspSource = tmpBuf[0] & 0xf; - if (rspSource >= BT_INFO_SRC_8723B_1ANT_MAX) - rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW; - pCoexSta->btInfoC2hCnt[rspSource]++; - - for (i = 0; i < length; i++) { - pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i]; - if (i == 1) - btInfo = tmpBuf[i]; - } - - if (rspSource != BT_INFO_SRC_8723B_1ANT_WIFI_FW) { - pCoexSta->btRetryCnt = pCoexSta->btInfoC2h[rspSource][2] & 0xf; - - if (pCoexSta->btRetryCnt >= 1) - pCoexSta->popEventCnt++; - - if (pCoexSta->btInfoC2h[rspSource][2] & 0x20) - pCoexSta->bC2hBtPage = true; - else - pCoexSta->bC2hBtPage = false; - - pCoexSta->btRssi = pCoexSta->btInfoC2h[rspSource][3] * 2 - 90; - /* pCoexSta->btInfoC2h[rspSource][3]*2+10; */ - - pCoexSta->btInfoExt = pCoexSta->btInfoC2h[rspSource][4]; - - pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2] & 0x40); - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask); - - if (!pCoexSta->bBtTxRxMask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */ - pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if (pCoexSta->btInfoExt & BIT(1)) { - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - if (bWifiConnected) - EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT); - else - EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT); - } - - if (pCoexSta->btInfoExt & BIT(3)) { - if (!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm) - halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false); - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE) - pCoexSta->bC2hBtInquiryPage = true; - else - pCoexSta->bC2hBtInquiryPage = false; - - /* set link exist status */ - if (!(btInfo & BT_INFO_8723B_1ANT_B_CONNECTION)) { - pCoexSta->bBtLinkExist = false; - pCoexSta->bPanExist = false; - pCoexSta->bA2dpExist = false; - pCoexSta->bHidExist = false; - pCoexSta->bScoExist = false; - } else { /* connection exists */ - pCoexSta->bBtLinkExist = true; - if (btInfo & BT_INFO_8723B_1ANT_B_FTP) - pCoexSta->bPanExist = true; - else - pCoexSta->bPanExist = false; - - if (btInfo & BT_INFO_8723B_1ANT_B_A2DP) - pCoexSta->bA2dpExist = true; - else - pCoexSta->bA2dpExist = false; - - if (btInfo & BT_INFO_8723B_1ANT_B_HID) - pCoexSta->bHidExist = true; - else - pCoexSta->bHidExist = false; - - if (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO) - pCoexSta->bScoExist = true; - else - pCoexSta->bScoExist = false; - } - - halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist); - - btInfo = btInfo & 0x1f; /* mask profile bit for connect-ilde identification (for CSR case: A2DP idle --> 0x41) */ - - if (!(btInfo & BT_INFO_8723B_1ANT_B_CONNECTION)) { - pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - } else if (btInfo == BT_INFO_8723B_1ANT_B_CONNECTION) { - /* connection exists but no busy */ - pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE; - } else if ( - (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO) || - (btInfo & BT_INFO_8723B_1ANT_B_SCO_BUSY) - ) { - pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY; - } else if (btInfo & BT_INFO_8723B_1ANT_B_ACL_BUSY) { - if (pCoexDm->btStatus != BT_8723B_1ANT_BT_STATUS_ACL_BUSY) - pCoexDm->bAutoTdmaAdjust = false; - - pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY; - } else { - pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX; - } - - if ( - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) - ) - bBtBusy = true; - else - bBtBusy = false; - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy); - - halbtc8723b1ant_RunCoexistMechanism(pBtCoexist); -} - -void EXhalbtc8723b1ant_HaltNotify(struct btc_coexist *pBtCoexist) -{ - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 0); - halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true); - - halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true); - - EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT); - - pBtCoexist->bStopCoexDm = true; -} - -void EXhalbtc8723b1ant_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState) -{ - if (pnpState == BTC_WIFI_PNP_SLEEP) { - halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); - halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true); - - pBtCoexist->bStopCoexDm = true; - } else if (pnpState == BTC_WIFI_PNP_WAKE_UP) { - pBtCoexist->bStopCoexDm = false; - halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false); - halbtc8723b1ant_InitCoexDm(pBtCoexist); - halbtc8723b1ant_QueryBtInfo(pBtCoexist); - } -} - -void EXhalbtc8723b1ant_Periodical(struct btc_coexist *pBtCoexist) -{ - static u8 disVerInfoCnt; - u32 fwVer = 0, btPatchVer = 0; - - if (disVerInfoCnt <= 5) { - disVerInfoCnt += 1; - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); - } - - halbtc8723b1ant_MonitorBtCtr(pBtCoexist); - halbtc8723b1ant_MonitorWiFiCtr(pBtCoexist); - - if ( - halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) || - pCoexDm->bAutoTdmaAdjust - ) - halbtc8723b1ant_RunCoexistMechanism(pBtCoexist); - - pCoexSta->specialPktPeriodCnt++; -} diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.h b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.h deleted file mode 100644 index 7a12d92da0a9..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.h +++ /dev/null @@ -1,184 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* The following is for 8723B 1ANT BT Co-exist definition */ -#define BT_INFO_8723B_1ANT_B_FTP BIT(7) -#define BT_INFO_8723B_1ANT_B_A2DP BIT(6) -#define BT_INFO_8723B_1ANT_B_HID BIT(5) -#define BT_INFO_8723B_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8723B_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8723B_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8723B_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8723B_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_ & BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT 2 - -#define BT_8723B_1ANT_WIFI_NOISY_THRESH 30 /* max: 255 */ - -enum { - BT_INFO_SRC_8723B_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8723B_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8723B_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8723B_1ANT_MAX -}; - -enum { - BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8723B_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8723B_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8723B_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8723B_1ANT_BT_STATUS_MAX -}; - -enum { - BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT = 0x3, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8723B_1ANT_WIFI_STATUS_MAX -}; - -enum { - BT_8723B_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8723B_1ANT_COEX_ALGO_SCO = 0x1, - BT_8723B_1ANT_COEX_ALGO_HID = 0x2, - BT_8723B_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8723B_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8723B_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8723B_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8723B_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8723B_1ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8723b_1ant { - /* fw mechanism */ - bool bCurIgnoreWlanAct; - bool bPreIgnoreWlanAct; - u8 prePsTdma; - u8 curPsTdma; - u8 psTdmaPara[5]; - u8 psTdmaDuAdjType; - bool bAutoTdmaAdjust; - bool bPrePsTdmaOn; - bool bCurPsTdmaOn; - bool bPreBtAutoReport; - bool bCurBtAutoReport; - u8 preLps; - u8 curLps; - u8 preRpwm; - u8 curRpwm; - - /* sw mechanism */ - bool bPreLowPenaltyRa; - bool bCurLowPenaltyRa; - u32 preVal0x6c0; - u32 curVal0x6c0; - u32 preVal0x6c4; - u32 curVal0x6c4; - u32 preVal0x6c8; - u32 curVal0x6c8; - u8 preVal0x6cc; - u8 curVal0x6cc; - bool bLimitedDig; - - u32 backupArfrCnt1; /* Auto Rate Fallback Retry cnt */ - u32 backupArfrCnt2; /* Auto Rate Fallback Retry cnt */ - u16 backupRetryLimit; - u8 backupAmpduMaxTime; - - /* algorithm related */ - u8 preAlgorithm; - u8 curAlgorithm; - u8 btStatus; - u8 wifiChnlInfo[3]; - - u32 preRaMask; - u32 curRaMask; - u8 preArfrType; - u8 curArfrType; - u8 preRetryLimitType; - u8 curRetryLimitType; - u8 preAmpduTimeType; - u8 curAmpduTimeType; - u32 nArpCnt; - - u8 errorCondition; -}; - -struct coex_sta_8723b_1ant { - bool bBtLinkExist; - bool bScoExist; - bool bA2dpExist; - bool bHidExist; - bool bPanExist; - - bool bUnderLps; - bool bUnderIps; - u32 specialPktPeriodCnt; - u32 highPriorityTx; - u32 highPriorityRx; - u32 lowPriorityTx; - u32 lowPriorityRx; - s8 btRssi; - bool bBtTxRxMask; - u8 preBtRssiState; - u8 preWifiRssiState[4]; - bool bC2hBtInfoReqSent; - u8 btInfoC2h[BT_INFO_SRC_8723B_1ANT_MAX][10]; - u32 btInfoC2hCnt[BT_INFO_SRC_8723B_1ANT_MAX]; - bool bC2hBtInquiryPage; - bool bC2hBtPage; /* Add for win8.1 page out issue */ - bool bWiFiIsHighPriTask; /* Add for win8.1 page out issue */ - u8 btRetryCnt; - u8 btInfoExt; - u32 popEventCnt; - u8 nScanAPNum; - - u32 nCRCOK_CCK; - u32 nCRCOK_11g; - u32 nCRCOK_11n; - u32 nCRCOK_11nAgg; - - u32 nCRCErr_CCK; - u32 nCRCErr_11g; - u32 nCRCErr_11n; - u32 nCRCErr_11nAgg; - - bool bCCKLock; - bool bPreCCKLock; - u8 nCoexTableType; - - bool bForceLpsOn; -}; - -/* */ -/* The following is interface which will notify coex module. */ -/* */ -void EXhalbtc8723b1ant_PowerOnSetting(struct btc_coexist *pBtCoexist); -void EXhalbtc8723b1ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bWifiOnly); -void EXhalbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist); -void EXhalbtc8723b1ant_IpsNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b1ant_LpsNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b1ant_ScanNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b1ant_ConnectNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b1ant_MediaStatusNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b1ant_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b1ant_BtInfoNotify( - struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length -); -void EXhalbtc8723b1ant_HaltNotify(struct btc_coexist *pBtCoexist); -void EXhalbtc8723b1ant_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState); -void EXhalbtc8723b1ant_Periodical(struct btc_coexist *pBtCoexist); diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c deleted file mode 100644 index 0220bacee181..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c +++ /dev/null @@ -1,2624 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "Mp_Precomp.h" - -/* defines */ -#define HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(val) \ -do { \ - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, val); \ - pCoexDm->psTdmaDuAdjType = val; \ -} while (0) - -/* Global variables, these are static variables */ -static struct coex_dm_8723b_2ant GLCoexDm8723b2Ant; -static struct coex_dm_8723b_2ant *pCoexDm = &GLCoexDm8723b2Ant; -static struct coex_sta_8723b_2ant GLCoexSta8723b2Ant; -static struct coex_sta_8723b_2ant *pCoexSta = &GLCoexSta8723b2Ant; - -/* local function start with halbtc8723b2ant_ */ -static u8 halbtc8723b2ant_BtRssiState( - u8 levelNum, u8 rssiThresh, u8 rssiThresh1 -) -{ - s32 btRssi = 0; - u8 btRssiState = pCoexSta->preBtRssiState; - - btRssi = pCoexSta->btRssi; - - if (levelNum == 2) { - if ( - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) || - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW) - ) { - if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) { - btRssiState = BTC_RSSI_STATE_HIGH; - } else { - btRssiState = BTC_RSSI_STATE_STAY_LOW; - } - } else { - if (btRssi < rssiThresh) { - btRssiState = BTC_RSSI_STATE_LOW; - } else { - btRssiState = BTC_RSSI_STATE_STAY_HIGH; - } - } - } else if (levelNum == 3) { - if (rssiThresh > rssiThresh1) { - return pCoexSta->preBtRssiState; - } - - if ( - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) || - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW) - ) { - if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) { - btRssiState = BTC_RSSI_STATE_MEDIUM; - } else { - btRssiState = BTC_RSSI_STATE_STAY_LOW; - } - } else if ( - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) || - (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM) - ) { - if (btRssi >= (rssiThresh1 + BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) { - btRssiState = BTC_RSSI_STATE_HIGH; - } else if (btRssi < rssiThresh) { - btRssiState = BTC_RSSI_STATE_LOW; - } else { - btRssiState = BTC_RSSI_STATE_STAY_MEDIUM; - } - } else { - if (btRssi < rssiThresh1) { - btRssiState = BTC_RSSI_STATE_MEDIUM; - } else { - btRssiState = BTC_RSSI_STATE_STAY_HIGH; - } - } - } - - pCoexSta->preBtRssiState = btRssiState; - - return btRssiState; -} - -static u8 halbtc8723b2ant_WifiRssiState( - struct btc_coexist *pBtCoexist, - u8 index, - u8 levelNum, - u8 rssiThresh, - u8 rssiThresh1 -) -{ - s32 wifiRssi = 0; - u8 wifiRssiState = pCoexSta->preWifiRssiState[index]; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi); - - if (levelNum == 2) { - if ( - (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) || - (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW) - ) { - if (wifiRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) { - wifiRssiState = BTC_RSSI_STATE_HIGH; - } else { - wifiRssiState = BTC_RSSI_STATE_STAY_LOW; - } - } else { - if (wifiRssi < rssiThresh) { - wifiRssiState = BTC_RSSI_STATE_LOW; - } else { - wifiRssiState = BTC_RSSI_STATE_STAY_HIGH; - } - } - } else if (levelNum == 3) { - if (rssiThresh > rssiThresh1) { - return pCoexSta->preWifiRssiState[index]; - } - - if ( - (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) || - (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW) - ) { - if (wifiRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) { - wifiRssiState = BTC_RSSI_STATE_MEDIUM; - } else { - wifiRssiState = BTC_RSSI_STATE_STAY_LOW; - } - } else if ( - (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) || - (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM) - ) { - if (wifiRssi >= (rssiThresh1 + BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) { - wifiRssiState = BTC_RSSI_STATE_HIGH; - } else if (wifiRssi < rssiThresh) { - wifiRssiState = BTC_RSSI_STATE_LOW; - } else { - wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM; - } - } else { - if (wifiRssi < rssiThresh1) { - wifiRssiState = BTC_RSSI_STATE_MEDIUM; - } else { - wifiRssiState = BTC_RSSI_STATE_STAY_HIGH; - } - } - } - - pCoexSta->preWifiRssiState[index] = wifiRssiState; - - return wifiRssiState; -} - -static void halbtc8723b2ant_LimitedRx( - struct btc_coexist *pBtCoexist, - bool bForceExec, - bool bRejApAggPkt, - bool bBtCtrlAggBufSize, - u8 aggBufSize -) -{ - bool bRejectRxAgg = bRejApAggPkt; - bool bBtCtrlRxAggSize = bBtCtrlAggBufSize; - u8 rxAggSize = aggBufSize; - - /* */ - /* Rx Aggregation related setting */ - /* */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg); - /* decide BT control aggregation buf size or not */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize); - /* real update aggregation setting */ - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -static void halbtc8723b2ant_QueryBtInfo(struct btc_coexist *pBtCoexist) -{ - u8 H2C_Parameter[1] = {0}; - - pCoexSta->bC2hBtInfoReqSent = true; - - H2C_Parameter[0] |= BIT(0); /* trigger */ - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter); -} - -static bool halbtc8723b2ant_IsWifiStatusChanged(struct btc_coexist *pBtCoexist) -{ - static bool bPreWifiBusy, bPreUnder4way, bPreBtHsOn; - bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false; - bool bWifiConnected = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way); - - if (bWifiConnected) { - if (bWifiBusy != bPreWifiBusy) { - bPreWifiBusy = bWifiBusy; - return true; - } - - if (bUnder4way != bPreUnder4way) { - bPreUnder4way = bUnder4way; - return true; - } - - if (bBtHsOn != bPreBtHsOn) { - bPreBtHsOn = bBtHsOn; - return true; - } - } - - return false; -} - -static void halbtc8723b2ant_UpdateBtLinkInfo(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bBtHsOn = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - - pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist; - pBtLinkInfo->bScoExist = pCoexSta->bScoExist; - pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist; - pBtLinkInfo->bPanExist = pCoexSta->bPanExist; - pBtLinkInfo->bHidExist = pCoexSta->bHidExist; - - /* work around for HS mode. */ - if (bBtHsOn) { - pBtLinkInfo->bPanExist = true; - pBtLinkInfo->bBtLinkExist = true; - } - - /* check if Sco only */ - if ( - pBtLinkInfo->bScoExist && - !pBtLinkInfo->bA2dpExist && - !pBtLinkInfo->bPanExist && - !pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bScoOnly = true; - else - pBtLinkInfo->bScoOnly = false; - - /* check if A2dp only */ - if ( - !pBtLinkInfo->bScoExist && - pBtLinkInfo->bA2dpExist && - !pBtLinkInfo->bPanExist && - !pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bA2dpOnly = true; - else - pBtLinkInfo->bA2dpOnly = false; - - /* check if Pan only */ - if ( - !pBtLinkInfo->bScoExist && - !pBtLinkInfo->bA2dpExist && - pBtLinkInfo->bPanExist && - !pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bPanOnly = true; - else - pBtLinkInfo->bPanOnly = false; - - /* check if Hid only */ - if ( - !pBtLinkInfo->bScoExist && - !pBtLinkInfo->bA2dpExist && - !pBtLinkInfo->bPanExist && - pBtLinkInfo->bHidExist - ) - pBtLinkInfo->bHidOnly = true; - else - pBtLinkInfo->bHidOnly = false; -} - -static u8 halbtc8723b2ant_ActionAlgorithm(struct btc_coexist *pBtCoexist) -{ - struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo; - bool bBtHsOn = false; - u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED; - u8 numOfDiffProfile = 0; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - - if (!pBtLinkInfo->bBtLinkExist) - return algorithm; - - if (pBtLinkInfo->bScoExist) - numOfDiffProfile++; - - if (pBtLinkInfo->bHidExist) - numOfDiffProfile++; - - if (pBtLinkInfo->bPanExist) - numOfDiffProfile++; - - if (pBtLinkInfo->bA2dpExist) - numOfDiffProfile++; - - if (numOfDiffProfile == 1) { - if (pBtLinkInfo->bScoExist) { - algorithm = BT_8723B_2ANT_COEX_ALGO_SCO; - } else { - if (pBtLinkInfo->bHidExist) { - algorithm = BT_8723B_2ANT_COEX_ALGO_HID; - } else if (pBtLinkInfo->bA2dpExist) { - algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP; - } else if (pBtLinkInfo->bPanExist) { - if (bBtHsOn) { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANHS; - } else { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (numOfDiffProfile == 2) { - if (pBtLinkInfo->bScoExist) { - if (pBtLinkInfo->bHidExist) { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if (pBtLinkInfo->bA2dpExist) { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if (pBtLinkInfo->bPanExist) { - if (bBtHsOn) { - algorithm = BT_8723B_2ANT_COEX_ALGO_SCO; - } else { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bA2dpExist - ) { - algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP; - } else if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bPanExist - ) { - if (bBtHsOn) { - algorithm = BT_8723B_2ANT_COEX_ALGO_HID; - } else { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if ( - pBtLinkInfo->bPanExist && - pBtLinkInfo->bA2dpExist - ) { - if (bBtHsOn) { - algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (numOfDiffProfile == 3) { - if (pBtLinkInfo->bScoExist) { - if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bA2dpExist - ) { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bPanExist - ) { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if ( - pBtLinkInfo->bPanExist && - pBtLinkInfo->bA2dpExist - ) { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } else { - if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bPanExist && - pBtLinkInfo->bA2dpExist - ) { - if (bBtHsOn) { - algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP; - } else { - algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (numOfDiffProfile >= 3) { - if (pBtLinkInfo->bScoExist) { - if ( - pBtLinkInfo->bHidExist && - pBtLinkInfo->bPanExist && - pBtLinkInfo->bA2dpExist - ) { - if (bBtHsOn) { - } else { - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -static void halbtc8723b2ant_SetFwDacSwingLevel( - struct btc_coexist *pBtCoexist, u8 dacSwingLvl -) -{ - u8 H2C_Parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - H2C_Parameter[0] = dacSwingLvl; - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter); -} - -static void halbtc8723b2ant_SetFwDecBtPwr( - struct btc_coexist *pBtCoexist, u8 decBtPwrLvl -) -{ - u8 H2C_Parameter[1] = {0}; - - H2C_Parameter[0] = decBtPwrLvl; - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter); -} - -static void halbtc8723b2ant_DecBtPwr( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 decBtPwrLvl -) -{ - pCoexDm->curBtDecPwrLvl = decBtPwrLvl; - - if (!bForceExec) { - if (pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl) - return; - } - halbtc8723b2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl); - - pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl; -} - -static void halbtc8723b2ant_FwDacSwingLvl( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 fwDacSwingLvl -) -{ - pCoexDm->curFwDacSwingLvl = fwDacSwingLvl; - - if (!bForceExec) { - if (pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) - return; - } - - halbtc8723b2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl); - - pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl; -} - -static void halbtc8723b2ant_SetSwRfRxLpfCorner( - struct btc_coexist *pBtCoexist, - bool bRxRfShrinkOn -) -{ - if (bRxRfShrinkOn) { - /* Shrink RF Rx LPF corner */ - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc); - } else { - /* Resume RF Rx LPF corner */ - /* After initialized, we can use pCoexDm->btRf0x1eBackup */ - if (pBtCoexist->bInitilized) { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup); - } - } -} - -static void halbtc8723b2ant_RfShrink( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bRxRfShrinkOn -) -{ - pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn; - - if (!bForceExec) { - if (pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) - return; - } - halbtc8723b2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink); - - pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink; -} - -static void halbtc8723b2ant_SetSwPenaltyTxRateAdaptive( - struct btc_coexist *pBtCoexist, bool bLowPenaltyRa -) -{ - u8 H2C_Parameter[6] = {0}; - - H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */ - - if (bLowPenaltyRa) { - H2C_Parameter[1] |= BIT(0); - H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter); -} - -static void halbtc8723b2ant_LowPenaltyRa( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bLowPenaltyRa -) -{ - /* return; */ - pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa; - - if (!bForceExec) { - if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) - return; - } - halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa); - - pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa; -} - -static void halbtc8723b2ant_SetDacSwingReg(struct btc_coexist *pBtCoexist, u32 level) -{ - u8 val = (u8)level; - - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val); -} - -static void halbtc8723b2ant_SetSwFullTimeDacSwing( - struct btc_coexist *pBtCoexist, bool bSwDacSwingOn, u32 swDacSwingLvl -) -{ - if (bSwDacSwingOn) - halbtc8723b2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl); - else - halbtc8723b2ant_SetDacSwingReg(pBtCoexist, 0x18); -} - -static void halbtc8723b2ant_DacSwing( - struct btc_coexist *pBtCoexist, - bool bForceExec, - bool bDacSwingOn, - u32 dacSwingLvl -) -{ - pCoexDm->bCurDacSwingOn = bDacSwingOn; - pCoexDm->curDacSwingLvl = dacSwingLvl; - - if (!bForceExec) { - if ((pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) && - (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl)) - return; - } - mdelay(30); - halbtc8723b2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl); - - pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn; - pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl; -} - -static void halbtc8723b2ant_SetAgcTable( - struct btc_coexist *pBtCoexist, bool bAgcTableEn -) -{ - u8 rssiAdjustVal = 0; - - /* BB AGC Gain Table */ - if (bAgcTableEn) { - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6e1A0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6d1B0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6c1C0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6b1D0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6a1E0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x691F0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x68200001); - } else { - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa4200001); - } - - /* RF Gain */ - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000); - if (bAgcTableEn) { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe); - } else { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6); - } - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1); - if (bAgcTableEn) { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe); - } else { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6); - } - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0); - - /* set rssiAdjustVal for wifi module. */ - if (bAgcTableEn) - rssiAdjustVal = 8; - - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal); -} - -static void halbtc8723b2ant_AgcTable( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bAgcTableEn -) -{ - pCoexDm->bCurAgcTableEn = bAgcTableEn; - - if (!bForceExec) { - if (pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) - return; - } - halbtc8723b2ant_SetAgcTable(pBtCoexist, bAgcTableEn); - - pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn; -} - -static void halbtc8723b2ant_SetCoexTable( - struct btc_coexist *pBtCoexist, - u32 val0x6c0, - u32 val0x6c4, - u32 val0x6c8, - u8 val0x6cc -) -{ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0); - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4); - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8); - - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc); -} - -static void halbtc8723b2ant_CoexTable( - struct btc_coexist *pBtCoexist, - bool bForceExec, - u32 val0x6c0, - u32 val0x6c4, - u32 val0x6c8, - u8 val0x6cc -) -{ - pCoexDm->curVal0x6c0 = val0x6c0; - pCoexDm->curVal0x6c4 = val0x6c4; - pCoexDm->curVal0x6c8 = val0x6c8; - pCoexDm->curVal0x6cc = val0x6cc; - - if (!bForceExec) { - if ( - (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) && - (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) && - (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) && - (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) - ) - return; - } - halbtc8723b2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc); - - pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0; - pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4; - pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8; - pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc; -} - -static void halbtc8723b2ant_CoexTableWithType( - struct btc_coexist *pBtCoexist, bool bForceExec, u8 type -) -{ - switch (type) { - case 0: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffff, 0x3); - break; - case 1: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffff, 0x3); - break; - case 2: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3); - break; - case 3: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffff, 0x3); - break; - case 4: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffff, 0x3); - break; - case 5: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffff, 0x3); - break; - case 6: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffff, 0x3); - break; - case 7: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0xfafafafa, 0xffff, 0x3); - break; - case 8: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3); - break; - case 9: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aea5aea, 0xffff, 0x3); - break; - case 10: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aff5aff, 0xffff, 0x3); - break; - case 11: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5f5a5f, 0xffff, 0x3); - break; - case 12: - halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5f5f5f5f, 0xffff, 0x3); - break; - default: - break; - } -} - -static void halbtc8723b2ant_SetFwIgnoreWlanAct( - struct btc_coexist *pBtCoexist, bool bEnable -) -{ - u8 H2C_Parameter[1] = {0}; - - if (bEnable) - H2C_Parameter[0] |= BIT(0); /* function enable */ - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter); -} - -static void halbtc8723b2ant_IgnoreWlanAct( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bEnable -) -{ - pCoexDm->bCurIgnoreWlanAct = bEnable; - - if (!bForceExec) { - if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct) - return; - } - halbtc8723b2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable); - - pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct; -} - -static void halbtc8723b2ant_SetFwPstdma( - struct btc_coexist *pBtCoexist, - u8 byte1, - u8 byte2, - u8 byte3, - u8 byte4, - u8 byte5 -) -{ - u8 H2C_Parameter[5] = {0}; - - H2C_Parameter[0] = byte1; - H2C_Parameter[1] = byte2; - H2C_Parameter[2] = byte3; - H2C_Parameter[3] = byte4; - H2C_Parameter[4] = byte5; - - pCoexDm->psTdmaPara[0] = byte1; - pCoexDm->psTdmaPara[1] = byte2; - pCoexDm->psTdmaPara[2] = byte3; - pCoexDm->psTdmaPara[3] = byte4; - pCoexDm->psTdmaPara[4] = byte5; - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter); -} - -static void halbtc8723b2ant_SwMechanism1( - struct btc_coexist *pBtCoexist, - bool bShrinkRxLPF, - bool bLowPenaltyRA, - bool bLimitedDIG, - bool bBTLNAConstrain -) -{ - halbtc8723b2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF); - halbtc8723b2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA); -} - -static void halbtc8723b2ant_SwMechanism2( - struct btc_coexist *pBtCoexist, - bool bAGCTableShift, - bool bADCBackOff, - bool bSWDACSwing, - u32 dacSwingLvl -) -{ - halbtc8723b2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift); - halbtc8723b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl); -} - -static void halbtc8723b2ant_SetAntPath( - struct btc_coexist *pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff -) -{ - struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo; - u32 fwVer = 0, u4Tmp = 0; - bool bPgExtSwitch = false; - bool bUseExtSwitch = false; - u8 H2C_Parameter[2] = {0}; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */ - - if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch) - bUseExtSwitch = true; - - if (bInitHwCfg) { - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1); - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff); - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3); - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77); - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); - - if (fwVer >= 0x180000) { - /* Use H2C to set GNT_BT to LOW */ - H2C_Parameter[0] = 0; - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter); - } else { - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0); - } - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); /* WiFi TRx Mask off */ - pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01); /* BT TRx Mask off */ - - if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) { - /* tell firmware "no antenna inverse" */ - H2C_Parameter[0] = 0; - } else { - /* tell firmware "antenna inverse" */ - H2C_Parameter[0] = 1; - } - - if (bUseExtSwitch) { - /* ext switch type */ - H2C_Parameter[1] = 1; - } else { - /* int switch type */ - H2C_Parameter[1] = 0; - } - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter); - } - - /* ext switch setting */ - if (bUseExtSwitch) { - if (bInitHwCfg) { - /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */ - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c); - u4Tmp &= ~BIT(23); - u4Tmp |= BIT(24); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp); - } - - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */ - switch (antPosType) { - case BTC_ANT_WIFI_AT_MAIN: - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); /* ext switch main at wifi */ - break; - case BTC_ANT_WIFI_AT_AUX: - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); /* ext switch aux at wifi */ - break; - } - } else { /* internal switch */ - if (bInitHwCfg) { - /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */ - u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c); - u4Tmp |= BIT(23); - u4Tmp &= ~BIT(24); - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp); - } - - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); /* fixed external switch S1->Main, S0->Aux */ - switch (antPosType) { - case BTC_ANT_WIFI_AT_MAIN: - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */ - break; - case BTC_ANT_WIFI_AT_AUX: - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); /* fixed internal switch S0->WiFi, S1->BT */ - break; - } - } -} - -static void halbtc8723b2ant_PsTdma( - struct btc_coexist *pBtCoexist, bool bForceExec, bool bTurnOn, u8 type -) -{ - pCoexDm->bCurPsTdmaOn = bTurnOn; - pCoexDm->curPsTdma = type; - - if (!bForceExec) { - if ( - (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) && - (pCoexDm->prePsTdma == pCoexDm->curPsTdma) - ) - return; - } - - if (bTurnOn) { - switch (type) { - case 1: - default: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); - break; - case 2: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); - break; - case 3: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90); - break; - case 4: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90); - break; - case 5: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); - break; - case 6: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); - break; - case 7: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90); - break; - case 8: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90); - break; - case 9: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); - break; - case 10: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); - break; - case 11: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90); - break; - case 12: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90); - break; - case 13: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); - break; - case 14: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); - break; - case 15: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90); - break; - case 16: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90); - break; - case 17: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90); - break; - case 18: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90); - break; - case 19: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90); - break; - case 20: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90); - break; - case 21: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90); - break; - case 71: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0); - break; - case 1: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0); - break; - default: - halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0); - break; - } - } - - /* update pre state */ - pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn; - pCoexDm->prePsTdma = pCoexDm->curPsTdma; -} - -static void halbtc8723b2ant_CoexAllOff(struct btc_coexist *pBtCoexist) -{ - /* fw all off */ - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - - /* hw all off */ - /* pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); -} - -static void halbtc8723b2ant_InitCoexDm(struct btc_coexist *pBtCoexist) -{ - /* force to reset coex mechanism */ - - halbtc8723b2ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 1); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6); - halbtc8723b2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0); - - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); -} - -static void halbtc8723b2ant_ActionBtInquiry(struct btc_coexist *pBtCoexist) -{ - bool bWifiConnected = false; - bool bLowPwrDisable = true; - - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - - if (bWifiConnected) { - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3); - } else { - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - } - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6); - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - - pCoexDm->bNeedRecover0x948 = true; - pCoexDm->backup0x948 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948); - - halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_AUX, false, false); -} - -static bool halbtc8723b2ant_IsCommonAction(struct btc_coexist *pBtCoexist) -{ - u8 btRssiState = BTC_RSSI_STATE_HIGH; - bool bCommon = false, bWifiConnected = false, bWifiBusy = false; - bool bBtHsOn = false, bLowPwrDisable = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); - - if (!bWifiConnected) { - bLowPwrDisable = false; - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable); - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - - bCommon = true; - } else { - if (pCoexDm->btStatus == BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE) { - bLowPwrDisable = false; - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable); - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb); - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - - bCommon = true; - } else if (pCoexDm->btStatus == BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE) { - bLowPwrDisable = true; - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable); - - if (bBtHsOn) - return false; - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb); - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - - bCommon = true; - } else { - bLowPwrDisable = true; - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable); - - if (bWifiBusy) { - bCommon = false; - } else { - if (bBtHsOn) - return false; - - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 21); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - bCommon = true; - } - } - } - - return bCommon; -} - -static void halbtc8723b2ant_TdmaDurationAdjust( - struct btc_coexist *pBtCoexist, bool bScoHid, bool bTxPause, u8 maxInterval -) -{ - static s32 up, dn, m, n, WaitCount; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retryCount = 0; - - if (!pCoexDm->bAutoTdmaAdjust) { - pCoexDm->bAutoTdmaAdjust = true; - { - if (bScoHid) { - if (bTxPause) { - if (maxInterval == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13); - else if (maxInterval == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - } else { - if (maxInterval == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9); - else if (maxInterval == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - } - } else { - if (bTxPause) { - if (maxInterval == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5); - else if (maxInterval == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - } else { - if (maxInterval == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1); - else if (maxInterval == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - } - } - } - /* */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - WaitCount = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retryCount = pCoexSta->btRetryCnt; - result = 0; - WaitCount++; - - if (retryCount == 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */ - WaitCount = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retryCount <= 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */ - if (WaitCount <= 2) - m++; /* 避免一直在兩個level中來回 */ - else - m = 1; - - if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - WaitCount = 0; - result = -1; - } - } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */ - if (WaitCount == 1) - m++; /* 避免一直在兩個level中來回 */ - else - m = 1; - - if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - WaitCount = 0; - result = -1; - } - - if (maxInterval == 1) { - if (bTxPause) { - if (pCoexDm->curPsTdma == 71) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5); - else if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 4) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8); - - if (pCoexDm->curPsTdma == 9) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 12) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16); - - if (result == -1) { - if (pCoexDm->curPsTdma == 5) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8); - else if (pCoexDm->curPsTdma == 13) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16); - } else if (result == 1) { - if (pCoexDm->curPsTdma == 8) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5); - else if (pCoexDm->curPsTdma == 16) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13); - } - } else { - if (pCoexDm->curPsTdma == 5) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(71); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 8) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4); - - if (pCoexDm->curPsTdma == 13) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 16) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12); - - if (result == -1) { - if (pCoexDm->curPsTdma == 71) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1); - else if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4); - else if (pCoexDm->curPsTdma == 9) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12); - } else if (result == 1) { - if (pCoexDm->curPsTdma == 4) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1); - else if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(71); - else if (pCoexDm->curPsTdma == 12) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9); - } - } - } else if (maxInterval == 2) { - if (bTxPause) { - if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 4) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8); - - if (pCoexDm->curPsTdma == 9) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 12) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16); - - if (result == -1) { - if (pCoexDm->curPsTdma == 5) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8); - else if (pCoexDm->curPsTdma == 13) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16); - } else if (result == 1) { - if (pCoexDm->curPsTdma == 8) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (pCoexDm->curPsTdma == 16) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - } - } else { - if (pCoexDm->curPsTdma == 5) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 8) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4); - - if (pCoexDm->curPsTdma == 13) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 16) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12); - - if (result == -1) { - if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4); - else if (pCoexDm->curPsTdma == 9) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12); - } else if (result == 1) { - if (pCoexDm->curPsTdma == 4) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (pCoexDm->curPsTdma == 12) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - } - } - } else if (maxInterval == 3) { - if (bTxPause) { - if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 4) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8); - - if (pCoexDm->curPsTdma == 9) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 12) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16); - - if (result == -1) { - if (pCoexDm->curPsTdma == 5) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8); - else if (pCoexDm->curPsTdma == 13) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16); - } else if (result == 1) { - if (pCoexDm->curPsTdma == 8) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); - else if (pCoexDm->curPsTdma == 16) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); - } - } else { - if (pCoexDm->curPsTdma == 5) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 6) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 7) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 8) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4); - - if (pCoexDm->curPsTdma == 13) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 14) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 15) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 16) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12); - - if (result == -1) { - if (pCoexDm->curPsTdma == 1) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4); - else if (pCoexDm->curPsTdma == 9) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12); - } else if (result == 1) { - if (pCoexDm->curPsTdma == 4) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 2) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); - else if (pCoexDm->curPsTdma == 12) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 11) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - else if (pCoexDm->curPsTdma == 10) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); - } - } - } - } - - /* if current PsTdma not match with the recorded one (when scan, dhcp...), */ - /* then we have to adjust it back to the previous record one. */ - if (pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType) { - bool bScan = false, bLink = false, bRoam = false; - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam); - - if (!bScan && !bLink && !bRoam) - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType); - - } -} - -/* SCO only or SCO+PAN(HS) */ -static void halbtc8723b2ant_ActionSco(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - - if (wifiBw == BTC_WIFI_BW_LEGACY) /* for SCO quality at 11b/g mode */ - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2); - else /* for SCO quality & wifi performance balance at 11n mode */ - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8); - - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); /* for voice quality */ - - /* sw mechanism */ - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4); - } - } -} - -static void halbtc8723b2ant_ActionHid(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - - if (wifiBw == BTC_WIFI_BW_LEGACY) /* for HID at 11b/g mode */ - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - else /* for HID quality & wifi performance balance at 11n mode */ - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 9); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9); - else - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13); - - /* sw mechanism */ - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -static void halbtc8723b2ant_ActionA2dp(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, wifiRssiState1, btRssiState; - u32 wifiBw; - u8 apNum = 0; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - wifiRssiState1 = halbtc8723b2ant_WifiRssiState(pBtCoexist, 1, 2, 40, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum); - - /* define the office environment */ - if (apNum >= 10 && BTC_RSSI_HIGH(wifiRssiState1)) { - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - - /* sw mechanism */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_HT40) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18); - } - return; - } - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 1); - else - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 1); - - /* sw mechanism */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -static void halbtc8723b2ant_ActionA2dpPanHs(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 2); - - /* sw mechanism */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -static void halbtc8723b2ant_ActionPanEdr(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 10); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1); - else - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5); - - /* sw mechanism */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -/* PAN(HS) only */ -static void halbtc8723b2ant_ActionPanHs(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - - halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -/* PAN(EDR)+A2DP */ -static void halbtc8723b2ant_ActionPanEdrA2dp(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12); - if (wifiBw == BTC_WIFI_BW_HT40) - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 3); - else - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 3); - } else { - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 3); - } - - /* sw mechanism */ - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -static void halbtc8723b2ant_ActionPanEdrHid(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - if (wifiBw == BTC_WIFI_BW_HT40) { - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 3); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); - } else { - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - } - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 2); - } else { - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11); - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2); - } - - /* sw mechanism */ - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -/* HID+A2DP+PAN(EDR) */ -static void halbtc8723b2ant_ActionHidA2dpPanEdr(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - if (wifiBw == BTC_WIFI_BW_HT40) - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2); - else - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 3); - } else - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 3); - - /* sw mechanism */ - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -static void halbtc8723b2ant_ActionHidA2dp(struct btc_coexist *pBtCoexist) -{ - u8 wifiRssiState, btRssiState; - u32 wifiBw; - u8 apNum = 0; - - wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0); - /* btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); */ - btRssiState = halbtc8723b2ant_BtRssiState(3, 29, 37); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5); - - halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_LEGACY) { - if (BTC_RSSI_HIGH(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else if (BTC_RSSI_MEDIUM(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - } else { - /* only 802.11N mode we have to dec bt power to 4 degree */ - if (BTC_RSSI_HIGH(btRssiState)) { - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum); - /* need to check ap Number of Not */ - if (apNum < 10) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - } else if (BTC_RSSI_MEDIUM(btRssiState)) - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0); - } - - halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); - - if ( - (btRssiState == BTC_RSSI_STATE_HIGH) || - (btRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 2); - else - halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2); - - /* sw mechanism */ - if (wifiBw == BTC_WIFI_BW_HT40) { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } else { - if ( - (wifiRssiState == BTC_RSSI_STATE_HIGH) || - (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) - ) { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18); - } else { - halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false); - halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18); - } - } -} - -static void halbtc8723b2ant_RunCoexistMechanism(struct btc_coexist *pBtCoexist) -{ - u8 algorithm = 0; - - if (pBtCoexist->bManualControl) { - return; - } - - if (pCoexSta->bUnderIps) { - return; - } - - algorithm = halbtc8723b2ant_ActionAlgorithm(pBtCoexist); - if (pCoexSta->bC2hBtInquiryPage && (algorithm != BT_8723B_2ANT_COEX_ALGO_PANHS)) { - halbtc8723b2ant_ActionBtInquiry(pBtCoexist); - return; - } else { - if (pCoexDm->bNeedRecover0x948) { - pCoexDm->bNeedRecover0x948 = false; - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, pCoexDm->backup0x948); - } - } - - pCoexDm->curAlgorithm = algorithm; - - if (halbtc8723b2ant_IsCommonAction(pBtCoexist)) { - pCoexDm->bAutoTdmaAdjust = false; - } else { - if (pCoexDm->curAlgorithm != pCoexDm->preAlgorithm) { - pCoexDm->bAutoTdmaAdjust = false; - } - - switch (pCoexDm->curAlgorithm) { - case BT_8723B_2ANT_COEX_ALGO_SCO: - halbtc8723b2ant_ActionSco(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_HID: - halbtc8723b2ant_ActionHid(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_A2DP: - halbtc8723b2ant_ActionA2dp(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS: - halbtc8723b2ant_ActionA2dpPanHs(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANEDR: - halbtc8723b2ant_ActionPanEdr(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANHS: - halbtc8723b2ant_ActionPanHs(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP: - halbtc8723b2ant_ActionPanEdrA2dp(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID: - halbtc8723b2ant_ActionPanEdrHid(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - halbtc8723b2ant_ActionHidA2dpPanEdr(pBtCoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_HID_A2DP: - halbtc8723b2ant_ActionHidA2dp(pBtCoexist); - break; - default: - halbtc8723b2ant_CoexAllOff(pBtCoexist); - break; - } - pCoexDm->preAlgorithm = pCoexDm->curAlgorithm; - } -} - -static void halbtc8723b2ant_WifiOffHwCfg(struct btc_coexist *pBtCoexist) -{ - bool bIsInMpMode = false; - u8 H2C_Parameter[2] = {0}; - u32 fwVer = 0; - - /* set wlan_act to low */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); - - pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi goto standby while GNT_BT 0-->1 */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); - if (fwVer >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - H2C_Parameter[0] = 1; - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter); - } else - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); - - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode); - if (!bIsInMpMode) - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */ - else - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */ -} - -static void halbtc8723b2ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bBackUp) -{ - u8 u1Tmp = 0; - - /* backup rf 0x1e value */ - pCoexDm->btRf0x1eBackup = - pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff); - - /* 0x790[5:0]= 0x5 */ - u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790); - u1Tmp &= 0xc0; - u1Tmp |= 0x5; - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp); - - /* Antenna config */ - halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, true, false); - - /* PTA parameter */ - halbtc8723b2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0); - - /* Enable counter statistics */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); /* 0x76e[3] = 1, WLAN_Act control by PTA */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3); - pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1); -} - -/* */ -/* work around function start with wa_halbtc8723b2ant_ */ -/* */ -/* */ -/* extern function start with EXhalbtc8723b2ant_ */ -/* */ -void EXhalbtc8723b2ant_PowerOnSetting(struct btc_coexist *pBtCoexist) -{ - struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo; - u8 u1Tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ - u16 u2Tmp = 0x0; - - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20); - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2); - pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp | BIT(0) | BIT(1)); - - /* set GRAN_BT = 1 */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); - /* set WLAN_ACT = 0 */ - pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */ - if (pBtCoexist->chipInterface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - - u1Tmp |= 0x1; /* antenna inverse */ - pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp); - - pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT; - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (pBoardInfo->singleAntPath == 0) { - /* set to S1 */ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); - pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; - } else if (pBoardInfo->singleAntPath == 1) { - /* set to S0 */ - pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); - u1Tmp |= 0x1; /* antenna inverse */ - pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT; - } - - if (pBtCoexist->chipInterface == BTC_INTF_PCI) - pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp); - else if (pBtCoexist->chipInterface == BTC_INTF_SDIO) - pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp); - } -} - -void EXhalbtc8723b2ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bWifiOnly) -{ - halbtc8723b2ant_InitHwConfig(pBtCoexist, true); -} - -void EXhalbtc8723b2ant_InitCoexDm(struct btc_coexist *pBtCoexist) -{ - halbtc8723b2ant_InitCoexDm(pBtCoexist); -} - -void EXhalbtc8723b2ant_IpsNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - if (type == BTC_IPS_ENTER) { - pCoexSta->bUnderIps = true; - halbtc8723b2ant_WifiOffHwCfg(pBtCoexist); - halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true); - halbtc8723b2ant_CoexAllOff(pBtCoexist); - } else if (type == BTC_IPS_LEAVE) { - pCoexSta->bUnderIps = false; - halbtc8723b2ant_InitHwConfig(pBtCoexist, false); - halbtc8723b2ant_InitCoexDm(pBtCoexist); - halbtc8723b2ant_QueryBtInfo(pBtCoexist); - } -} - -void EXhalbtc8723b2ant_LpsNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - if (type == BTC_LPS_ENABLE) { - pCoexSta->bUnderLps = true; - } else if (type == BTC_LPS_DISABLE) { - pCoexSta->bUnderLps = false; - } -} - -void EXhalbtc8723b2ant_ScanNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - if (type == BTC_SCAN_START) { - } else if (type == BTC_SCAN_FINISH) { - } -} - -void EXhalbtc8723b2ant_ConnectNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - if (type == BTC_ASSOCIATE_START) { - } else if (type == BTC_ASSOCIATE_FINISH) { - } -} - -void EXhalbtc8723b2ant_MediaStatusNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - u8 H2C_Parameter[3] = {0}; - u32 wifiBw; - u8 wifiCentralChnl; - u8 apNum = 0; - - /* only 2.4G we need to inform bt the chnl mask */ - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl); - if ((type == BTC_MEDIA_CONNECT) && (wifiCentralChnl <= 14)) { - H2C_Parameter[0] = 0x1; - H2C_Parameter[1] = wifiCentralChnl; - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); - if (wifiBw == BTC_WIFI_BW_HT40) - H2C_Parameter[2] = 0x30; - else { - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum); - if (apNum < 10) - H2C_Parameter[2] = 0x30; - else - H2C_Parameter[2] = 0x20; - } - } - - pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0]; - pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1]; - pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2]; - - pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter); -} - -void EXhalbtc8723b2ant_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 type) -{ -} - -void EXhalbtc8723b2ant_BtInfoNotify( - struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length -) -{ - u8 btInfo = 0; - u8 i, rspSource = 0; - bool bBtBusy = false, bLimitedDig = false; - bool bWifiConnected = false; - - pCoexSta->bC2hBtInfoReqSent = false; - - rspSource = tmpBuf[0] & 0xf; - if (rspSource >= BT_INFO_SRC_8723B_2ANT_MAX) - rspSource = BT_INFO_SRC_8723B_2ANT_WIFI_FW; - - pCoexSta->btInfoC2hCnt[rspSource]++; - - for (i = 0; i < length; i++) { - pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i]; - if (i == 1) - btInfo = tmpBuf[i]; - - } - - if (pBtCoexist->bManualControl) { - return; - } - - if (rspSource != BT_INFO_SRC_8723B_2ANT_WIFI_FW) { - pCoexSta->btRetryCnt = pCoexSta->btInfoC2h[rspSource][2] & 0xf; /* [3:0] */ - - pCoexSta->btRssi = pCoexSta->btInfoC2h[rspSource][3] * 2 + 10; - - pCoexSta->btInfoExt = pCoexSta->btInfoC2h[rspSource][4]; - - pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2] & 0x40); - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask); - if (pCoexSta->bBtTxRxMask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */ - pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01); - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if ((pCoexSta->btInfoExt & BIT(1))) { - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); - - if (bWifiConnected) - EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT); - else - EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT); - } - - if ((pCoexSta->btInfoExt & BIT(3))) { - halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false); - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (btInfo & BT_INFO_8723B_2ANT_B_INQ_PAGE) - pCoexSta->bC2hBtInquiryPage = true; - else - pCoexSta->bC2hBtInquiryPage = false; - - /* set link exist status */ - if (!(btInfo & BT_INFO_8723B_2ANT_B_CONNECTION)) { - pCoexSta->bBtLinkExist = false; - pCoexSta->bPanExist = false; - pCoexSta->bA2dpExist = false; - pCoexSta->bHidExist = false; - pCoexSta->bScoExist = false; - } else { /* connection exists */ - pCoexSta->bBtLinkExist = true; - if (btInfo & BT_INFO_8723B_2ANT_B_FTP) - pCoexSta->bPanExist = true; - else - pCoexSta->bPanExist = false; - if (btInfo & BT_INFO_8723B_2ANT_B_A2DP) - pCoexSta->bA2dpExist = true; - else - pCoexSta->bA2dpExist = false; - if (btInfo & BT_INFO_8723B_2ANT_B_HID) - pCoexSta->bHidExist = true; - else - pCoexSta->bHidExist = false; - if (btInfo & BT_INFO_8723B_2ANT_B_SCO_ESCO) - pCoexSta->bScoExist = true; - else - pCoexSta->bScoExist = false; - } - - halbtc8723b2ant_UpdateBtLinkInfo(pBtCoexist); - - if (!(btInfo & BT_INFO_8723B_2ANT_B_CONNECTION)) { - pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - } else if (btInfo == BT_INFO_8723B_2ANT_B_CONNECTION) { /* connection exists but no busy */ - pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE; - } else if ( - (btInfo & BT_INFO_8723B_2ANT_B_SCO_ESCO) || - (btInfo & BT_INFO_8723B_2ANT_B_SCO_BUSY) - ) { - pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_SCO_BUSY; - } else if (btInfo & BT_INFO_8723B_2ANT_B_ACL_BUSY) { - pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_ACL_BUSY; - } else { - pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_MAX; - } - - if ( - (pCoexDm->btStatus == BT_8723B_2ANT_BT_STATUS_ACL_BUSY) || - (pCoexDm->btStatus == BT_8723B_2ANT_BT_STATUS_SCO_BUSY) || - (pCoexDm->btStatus == BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY) - ) { - bBtBusy = true; - bLimitedDig = true; - } else { - bBtBusy = false; - bLimitedDig = false; - } - - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy); - - pCoexDm->bLimitedDig = bLimitedDig; - pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig); - - halbtc8723b2ant_RunCoexistMechanism(pBtCoexist); -} - -void EXhalbtc8723b2ant_HaltNotify(struct btc_coexist *pBtCoexist) -{ - halbtc8723b2ant_WifiOffHwCfg(pBtCoexist); - pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */ - halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true); - - EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT); -} - -void EXhalbtc8723b2ant_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState) -{ - if (pnpState == BTC_WIFI_PNP_SLEEP) { - } else if (pnpState == BTC_WIFI_PNP_WAKE_UP) { - halbtc8723b2ant_InitHwConfig(pBtCoexist, false); - halbtc8723b2ant_InitCoexDm(pBtCoexist); - halbtc8723b2ant_QueryBtInfo(pBtCoexist); - } -} - -void EXhalbtc8723b2ant_Periodical(struct btc_coexist *pBtCoexist) -{ - static u8 disVerInfoCnt; - u32 fwVer = 0, btPatchVer = 0; - - if (disVerInfoCnt <= 5) { - disVerInfoCnt += 1; - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer); - pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); - } - - if ( - halbtc8723b2ant_IsWifiStatusChanged(pBtCoexist) || - pCoexDm->bAutoTdmaAdjust - ) - halbtc8723b2ant_RunCoexistMechanism(pBtCoexist); -} diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.h b/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.h deleted file mode 100644 index ebc47f65e8d2..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.h +++ /dev/null @@ -1,146 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* The following is for 8723B 2Ant BT Co-exist definition */ -#define BT_INFO_8723B_2ANT_B_FTP BIT(7) -#define BT_INFO_8723B_2ANT_B_A2DP BIT(6) -#define BT_INFO_8723B_2ANT_B_HID BIT(5) -#define BT_INFO_8723B_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8723B_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8723B_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8723B_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8723B_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT 2 - -enum { - BT_INFO_SRC_8723B_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8723B_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8723B_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8723B_2ANT_MAX -}; - -enum { - BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8723B_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8723B_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8723B_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8723B_2ANT_BT_STATUS_MAX -}; - -enum { - BT_8723B_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8723B_2ANT_COEX_ALGO_SCO = 0x1, - BT_8723B_2ANT_COEX_ALGO_HID = 0x2, - BT_8723B_2ANT_COEX_ALGO_A2DP = 0x3, - BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8723B_2ANT_COEX_ALGO_PANEDR = 0x5, - BT_8723B_2ANT_COEX_ALGO_PANHS = 0x6, - BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8723B_2ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8723B_2ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8723b_2ant { - /* fw mechanism */ - u8 preBtDecPwrLvl; - u8 curBtDecPwrLvl; - u8 preFwDacSwingLvl; - u8 curFwDacSwingLvl; - bool bCurIgnoreWlanAct; - bool bPreIgnoreWlanAct; - u8 prePsTdma; - u8 curPsTdma; - u8 psTdmaPara[5]; - u8 psTdmaDuAdjType; - bool bResetTdmaAdjust; - bool bAutoTdmaAdjust; - bool bPrePsTdmaOn; - bool bCurPsTdmaOn; - bool bPreBtAutoReport; - bool bCurBtAutoReport; - - /* sw mechanism */ - bool bPreRfRxLpfShrink; - bool bCurRfRxLpfShrink; - u32 btRf0x1eBackup; - bool bPreLowPenaltyRa; - bool bCurLowPenaltyRa; - bool bPreDacSwingOn; - u32 preDacSwingLvl; - bool bCurDacSwingOn; - u32 curDacSwingLvl; - bool bPreAdcBackOff; - bool bCurAdcBackOff; - bool bPreAgcTableEn; - bool bCurAgcTableEn; - u32 preVal0x6c0; - u32 curVal0x6c0; - u32 preVal0x6c4; - u32 curVal0x6c4; - u32 preVal0x6c8; - u32 curVal0x6c8; - u8 preVal0x6cc; - u8 curVal0x6cc; - bool bLimitedDig; - - /* algorithm related */ - u8 preAlgorithm; - u8 curAlgorithm; - u8 btStatus; - u8 wifiChnlInfo[3]; - - bool bNeedRecover0x948; - u32 backup0x948; -}; - -struct coex_sta_8723b_2ant { - bool bBtLinkExist; - bool bScoExist; - bool bA2dpExist; - bool bHidExist; - bool bPanExist; - - bool bUnderLps; - bool bUnderIps; - u32 highPriorityTx; - u32 highPriorityRx; - u32 lowPriorityTx; - u32 lowPriorityRx; - u8 btRssi; - bool bBtTxRxMask; - u8 preBtRssiState; - u8 preWifiRssiState[4]; - bool bC2hBtInfoReqSent; - u8 btInfoC2h[BT_INFO_SRC_8723B_2ANT_MAX][10]; - u32 btInfoC2hCnt[BT_INFO_SRC_8723B_2ANT_MAX]; - bool bC2hBtInquiryPage; - u8 btRetryCnt; - u8 btInfoExt; -}; - -/* */ -/* The following is interface which will notify coex module. */ -/* */ -void EXhalbtc8723b2ant_PowerOnSetting(struct btc_coexist *pBtCoexist); -void EXhalbtc8723b2ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bWifiOnly); -void EXhalbtc8723b2ant_InitCoexDm(struct btc_coexist *pBtCoexist); -void EXhalbtc8723b2ant_IpsNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b2ant_LpsNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b2ant_ScanNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b2ant_ConnectNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b2ant_MediaStatusNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b2ant_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtc8723b2ant_BtInfoNotify( - struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length -); -void EXhalbtc8723b2ant_HaltNotify(struct btc_coexist *pBtCoexist); -void EXhalbtc8723b2ant_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState); -void EXhalbtc8723b2ant_Periodical(struct btc_coexist *pBtCoexist); diff --git a/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h b/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h deleted file mode 100644 index 36b0f429dd4c..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h +++ /dev/null @@ -1,426 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HALBTC_OUT_SRC_H__ -#define __HALBTC_OUT_SRC_H__ - -#define NORMAL_EXEC false -#define FORCE_EXEC true - -#define BTC_RF_OFF 0x0 -#define BTC_RF_ON 0x1 - -#define BTC_RF_A 0x0 -#define BTC_RF_B 0x1 -#define BTC_RF_C 0x2 -#define BTC_RF_D 0x3 - -#define BTC_SMSP SINGLEMAC_SINGLEPHY -#define BTC_DMDP DUALMAC_DUALPHY -#define BTC_DMSP DUALMAC_SINGLEPHY -#define BTC_MP_UNKNOWN 0xff - -#define BT_COEX_ANT_TYPE_PG 0 -#define BT_COEX_ANT_TYPE_ANTDIV 1 -#define BT_COEX_ANT_TYPE_DETECTED 2 - -#define BTC_MIMO_PS_STATIC 0 /* 1ss */ -#define BTC_MIMO_PS_DYNAMIC 1 /* 2ss */ - -#define BTC_RATE_DISABLE 0 -#define BTC_RATE_ENABLE 1 - -/* single Antenna definition */ -#define BTC_ANT_PATH_WIFI 0 -#define BTC_ANT_PATH_BT 1 -#define BTC_ANT_PATH_PTA 2 -/* dual Antenna definition */ -#define BTC_ANT_WIFI_AT_MAIN 0 -#define BTC_ANT_WIFI_AT_AUX 1 -/* coupler Antenna definition */ -#define BTC_ANT_WIFI_AT_CPL_MAIN 0 -#define BTC_ANT_WIFI_AT_CPL_AUX 1 - -enum { - BTC_PS_WIFI_NATIVE = 0, /* wifi original power save behavior */ - BTC_PS_LPS_ON = 1, - BTC_PS_LPS_OFF = 2, - BTC_PS_MAX -}; - -enum { - BTC_BT_REG_RF = 0, - BTC_BT_REG_MODEM = 1, - BTC_BT_REG_BLUEWIZE = 2, - BTC_BT_REG_VENDOR = 3, - BTC_BT_REG_LE = 4, - BTC_BT_REG_MAX -}; - -enum btc_chip_interface { - BTC_INTF_UNKNOWN = 0, - BTC_INTF_PCI = 1, - BTC_INTF_USB = 2, - BTC_INTF_SDIO = 3, - BTC_INTF_MAX -}; - -/* following is for wifi link status */ -#define WIFI_STA_CONNECTED BIT(0) -#define WIFI_AP_CONNECTED BIT(1) -#define WIFI_HS_CONNECTED BIT(2) -#define WIFI_P2P_GO_CONNECTED BIT(3) -#define WIFI_P2P_GC_CONNECTED BIT(4) - -struct btc_board_info { - /* The following is some board information */ - u8 pgAntNum; /* pg ant number */ - u8 btdmAntNum; /* ant number for btdm */ - u8 btdmAntPos; /* Bryant Add to indicate Antenna Position for (pgAntNum = 2) && (btdmAntNum = 1) (DPDT+1Ant case) */ - u8 singleAntPath; /* current used for 8723b only, 1 =>s0, 0 =>s1 */ - /* bool bBtExist; */ -}; - -enum { - BTC_RSSI_STATE_HIGH = 0x0, - BTC_RSSI_STATE_MEDIUM = 0x1, - BTC_RSSI_STATE_LOW = 0x2, - BTC_RSSI_STATE_STAY_HIGH = 0x3, - BTC_RSSI_STATE_STAY_MEDIUM = 0x4, - BTC_RSSI_STATE_STAY_LOW = 0x5, - BTC_RSSI_MAX -}; -#define BTC_RSSI_HIGH(_rssi_) ((_rssi_ == BTC_RSSI_STATE_HIGH || _rssi_ == BTC_RSSI_STATE_STAY_HIGH) ? true : false) -#define BTC_RSSI_MEDIUM(_rssi_) ((_rssi_ == BTC_RSSI_STATE_MEDIUM || _rssi_ == BTC_RSSI_STATE_STAY_MEDIUM) ? true : false) -#define BTC_RSSI_LOW(_rssi_) ((_rssi_ == BTC_RSSI_STATE_LOW || _rssi_ == BTC_RSSI_STATE_STAY_LOW) ? true : false) - -enum { - BTC_WIFI_BW_LEGACY = 0x0, - BTC_WIFI_BW_HT20 = 0x1, - BTC_WIFI_BW_HT40 = 0x2, - BTC_WIFI_BW_MAX -}; - -enum { - BTC_WIFI_TRAFFIC_TX = 0x0, - BTC_WIFI_TRAFFIC_RX = 0x1, - BTC_WIFI_TRAFFIC_MAX -}; - -enum { - BTC_WIFI_PNP_WAKE_UP = 0x0, - BTC_WIFI_PNP_SLEEP = 0x1, - BTC_WIFI_PNP_MAX -}; - -/* defined for BFP_BTC_GET */ -enum { - /* type bool */ - BTC_GET_BL_HS_OPERATION, - BTC_GET_BL_HS_CONNECTING, - BTC_GET_BL_WIFI_CONNECTED, - BTC_GET_BL_WIFI_BUSY, - BTC_GET_BL_WIFI_SCAN, - BTC_GET_BL_WIFI_LINK, - BTC_GET_BL_WIFI_ROAM, - BTC_GET_BL_WIFI_4_WAY_PROGRESS, - BTC_GET_BL_WIFI_AP_MODE_ENABLE, - BTC_GET_BL_WIFI_ENABLE_ENCRYPTION, - BTC_GET_BL_WIFI_UNDER_B_MODE, - BTC_GET_BL_EXT_SWITCH, - BTC_GET_BL_WIFI_IS_IN_MP_MODE, - - /* type s32 */ - BTC_GET_S4_WIFI_RSSI, - BTC_GET_S4_HS_RSSI, - - /* type u32 */ - BTC_GET_U4_WIFI_BW, - BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, - BTC_GET_U4_WIFI_FW_VER, - BTC_GET_U4_WIFI_LINK_STATUS, - BTC_GET_U4_BT_PATCH_VER, - - /* type u8 */ - BTC_GET_U1_WIFI_DOT11_CHNL, - BTC_GET_U1_WIFI_CENTRAL_CHNL, - BTC_GET_U1_WIFI_HS_CHNL, - BTC_GET_U1_MAC_PHY_MODE, - BTC_GET_U1_AP_NUM, - - /* for 1Ant ====== */ - BTC_GET_U1_LPS_MODE, - - BTC_GET_MAX -}; - -/* defined for BFP_BTC_SET */ -enum { - /* type bool */ - BTC_SET_BL_BT_DISABLE, - BTC_SET_BL_BT_TRAFFIC_BUSY, - BTC_SET_BL_BT_LIMITED_DIG, - BTC_SET_BL_FORCE_TO_ROAM, - BTC_SET_BL_TO_REJ_AP_AGG_PKT, - BTC_SET_BL_BT_CTRL_AGG_SIZE, - BTC_SET_BL_INC_SCAN_DEV_NUM, - BTC_SET_BL_BT_TX_RX_MASK, - - /* type u8 */ - BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, - BTC_SET_U1_AGG_BUF_SIZE, - - /* type trigger some action */ - BTC_SET_ACT_GET_BT_RSSI, - BTC_SET_ACT_AGGREGATE_CTRL, - /* for 1Ant ====== */ - /* type bool */ - - /* type u8 */ - BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, - BTC_SET_U1_LPS_VAL, - BTC_SET_U1_RPWM_VAL, - /* type trigger some action */ - BTC_SET_ACT_LEAVE_LPS, - BTC_SET_ACT_ENTER_LPS, - BTC_SET_ACT_NORMAL_LPS, - BTC_SET_ACT_DISABLE_LOW_POWER, - BTC_SET_ACT_UPDATE_RAMASK, - BTC_SET_ACT_SEND_MIMO_PS, - /* BT Coex related */ - BTC_SET_ACT_CTRL_BT_INFO, - BTC_SET_ACT_CTRL_BT_COEX, - BTC_SET_ACT_CTRL_8723B_ANT, - /* */ - BTC_SET_MAX -}; - -enum { - BTC_DBG_DISP_COEX_STATISTICS = 0x0, - BTC_DBG_DISP_BT_LINK_INFO = 0x1, - BTC_DBG_DISP_FW_PWR_MODE_CMD = 0x2, - BTC_DBG_DISP_MAX -}; - -enum { - BTC_IPS_LEAVE = 0x0, - BTC_IPS_ENTER = 0x1, - BTC_IPS_MAX -}; - -enum { - BTC_LPS_DISABLE = 0x0, - BTC_LPS_ENABLE = 0x1, - BTC_LPS_MAX -}; - -enum { - BTC_SCAN_FINISH = 0x0, - BTC_SCAN_START = 0x1, - BTC_SCAN_MAX -}; - -enum { - BTC_ASSOCIATE_FINISH = 0x0, - BTC_ASSOCIATE_START = 0x1, - BTC_ASSOCIATE_MAX -}; - -enum { - BTC_MEDIA_DISCONNECT = 0x0, - BTC_MEDIA_CONNECT = 0x1, - BTC_MEDIA_MAX -}; - -enum { - BTC_PACKET_UNKNOWN = 0x0, - BTC_PACKET_DHCP = 0x1, - BTC_PACKET_ARP = 0x2, - BTC_PACKET_EAPOL = 0x3, - BTC_PACKET_MAX -}; - -/* Bryant Add */ -enum { - BTC_ANTENNA_AT_MAIN_PORT = 0x1, - BTC_ANTENNA_AT_AUX_PORT = 0x2, -}; - -typedef u8 (*BFP_BTC_R1)(void *pBtcContext, u32 RegAddr); -typedef u16(*BFP_BTC_R2)(void *pBtcContext, u32 RegAddr); -typedef u32 (*BFP_BTC_R4)(void *pBtcContext, u32 RegAddr); -typedef void (*BFP_BTC_W1)(void *pBtcContext, u32 RegAddr, u8 Data); -typedef void(*BFP_BTC_W1_BIT_MASK)( - void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b -); -typedef void (*BFP_BTC_W2)(void *pBtcContext, u32 RegAddr, u16 Data); -typedef void (*BFP_BTC_W4)(void *pBtcContext, u32 RegAddr, u32 Data); -typedef void (*BFP_BTC_LOCAL_REG_W1)(void *pBtcContext, u32 RegAddr, u8 Data); -typedef void (*BFP_BTC_SET_BB_REG)( - void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data -); -typedef u32 (*BFP_BTC_GET_BB_REG)(void *pBtcContext, u32 RegAddr, u32 BitMask); -typedef void (*BFP_BTC_SET_RF_REG)( - void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data -); -typedef u32 (*BFP_BTC_GET_RF_REG)( - void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask -); -typedef void (*BFP_BTC_FILL_H2C)( - void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer -); - -typedef u8 (*BFP_BTC_GET)(void *pBtCoexist, u8 getType, void *pOutBuf); - -typedef u8 (*BFP_BTC_SET)(void *pBtCoexist, u8 setType, void *pInBuf); -typedef void (*BFP_BTC_SET_BT_REG)( - void *pBtcContext, u8 regType, u32 offset, u32 value -); -typedef u32 (*BFP_BTC_GET_BT_REG)(void *pBtcContext, u8 regType, u32 offset); -typedef void (*BFP_BTC_DISP_DBG_MSG)(void *pBtCoexist, u8 dispType); - -struct btc_bt_info { - bool bBtDisabled; - u8 rssiAdjustForAgcTableOn; - u8 rssiAdjustFor1AntCoexType; - bool bPreBtCtrlAggBufSize; - bool bBtCtrlAggBufSize; - bool bRejectAggPkt; - bool bIncreaseScanDevNum; - bool bBtTxRxMask; - u8 preAggBufSize; - u8 aggBufSize; - bool bBtBusy; - bool bLimitedDig; - u16 btHciVer; - u16 btRealFwVer; - u8 btFwVer; - u32 getBtFwVerCnt; - - bool bBtDisableLowPwr; - - bool bBtCtrlLps; - bool bBtLpsOn; - bool bForceToRoam; /* for 1Ant solution */ - u8 lpsVal; - u8 rpwmVal; - u32 raMask; -}; - -struct btc_stack_info { - bool bProfileNotified; - u16 hciVersion; /* stack hci version */ - u8 numOfLink; - bool bBtLinkExist; - bool bScoExist; - bool bAclExist; - bool bA2dpExist; - bool bHidExist; - u8 numOfHid; - bool bPanExist; - bool bUnknownAclExist; - s8 minBtRssi; -}; - -struct btc_bt_link_info { - bool bBtLinkExist; - bool bScoExist; - bool bScoOnly; - bool bA2dpExist; - bool bA2dpOnly; - bool bHidExist; - bool bHidOnly; - bool bPanExist; - bool bPanOnly; - bool bSlaveRole; -}; - -struct btc_statistics { - u32 cntBind; - u32 cntPowerOn; - u32 cntInitHwConfig; - u32 cntInitCoexDm; - u32 cntIpsNotify; - u32 cntLpsNotify; - u32 cntScanNotify; - u32 cntConnectNotify; - u32 cntMediaStatusNotify; - u32 cntSpecialPacketNotify; - u32 cntBtInfoNotify; - u32 cntRfStatusNotify; - u32 cntPeriodical; - u32 cntCoexDmSwitch; - u32 cntStackOperationNotify; - u32 cntDbgCtrl; -}; - -struct btc_coexist { - bool bBinded; /* make sure only one adapter can bind the data context */ - void *Adapter; /* default adapter */ - struct btc_board_info boardInfo; - struct btc_bt_info btInfo; /* some bt info referenced by non-bt module */ - struct btc_stack_info stackInfo; - struct btc_bt_link_info btLinkInfo; - enum btc_chip_interface chipInterface; - - bool bInitilized; - bool bStopCoexDm; - bool bManualControl; - struct btc_statistics statistics; - u8 pwrModeVal[10]; - - /* function pointers */ - /* io related */ - BFP_BTC_R1 fBtcRead1Byte; - BFP_BTC_W1 fBtcWrite1Byte; - BFP_BTC_W1_BIT_MASK fBtcWrite1ByteBitMask; - BFP_BTC_R2 fBtcRead2Byte; - BFP_BTC_W2 fBtcWrite2Byte; - BFP_BTC_R4 fBtcRead4Byte; - BFP_BTC_W4 fBtcWrite4Byte; - BFP_BTC_LOCAL_REG_W1 fBtcWriteLocalReg1Byte; - /* read/write bb related */ - BFP_BTC_SET_BB_REG fBtcSetBbReg; - BFP_BTC_GET_BB_REG fBtcGetBbReg; - - /* read/write rf related */ - BFP_BTC_SET_RF_REG fBtcSetRfReg; - BFP_BTC_GET_RF_REG fBtcGetRfReg; - - /* fill h2c related */ - BFP_BTC_FILL_H2C fBtcFillH2c; - /* normal get/set related */ - BFP_BTC_GET fBtcGet; - BFP_BTC_SET fBtcSet; - - BFP_BTC_GET_BT_REG fBtcGetBtReg; - BFP_BTC_SET_BT_REG fBtcSetBtReg; -}; - -extern struct btc_coexist GLBtCoexist; - -void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist); -void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly); -void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist); -void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type); -void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action); -void EXhalbtcoutsrc_MediaStatusNotify( - struct btc_coexist *pBtCoexist, enum rt_media_status mediaStatus -); -void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType); -void EXhalbtcoutsrc_BtInfoNotify( - struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length -); -void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist); -void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState); -void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist); -void EXhalbtcoutsrc_SetChipType(u8 chipType); -void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum); -void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c deleted file mode 100644 index afdde3980ec3..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c +++ /dev/null @@ -1,556 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include "odm_precomp.h" - -static bool CheckPositive(struct dm_odm_t *pDM_Odm, const u32 Condition1, const u32 Condition2) -{ - u8 _BoardType = - ((pDM_Odm->BoardType & BIT(4)) >> 4) << 0 | /* _GLNA */ - ((pDM_Odm->BoardType & BIT(3)) >> 3) << 1 | /* _GPA */ - ((pDM_Odm->BoardType & BIT(7)) >> 7) << 2 | /* _ALNA */ - ((pDM_Odm->BoardType & BIT(6)) >> 6) << 3 | /* _APA */ - ((pDM_Odm->BoardType & BIT(2)) >> 2) << 4; /* _BT */ - - u32 cond1 = Condition1, cond2 = Condition2; - u32 driver1 = - pDM_Odm->CutVersion << 24 | - pDM_Odm->SupportPlatform << 16 | - pDM_Odm->PackageType << 12 | - pDM_Odm->SupportInterface << 8 | - _BoardType; - - u32 driver2 = - pDM_Odm->TypeGLNA << 0 | - pDM_Odm->TypeGPA << 8 | - pDM_Odm->TypeALNA << 16 | - pDM_Odm->TypeAPA << 24; - - /* Value Defined Check =============== */ - /* QFN Type [15:12] and Cut Version [27:24] need to do value check */ - - if (((cond1 & 0x0000F000) != 0) && ((cond1 & 0x0000F000) != (driver1 & 0x0000F000))) - return false; - if (((cond1 & 0x0F000000) != 0) && ((cond1 & 0x0F000000) != (driver1 & 0x0F000000))) - return false; - - /* Bit Defined Check ================ */ - /* We don't care [31:28] and [23:20] */ - /* */ - cond1 &= 0x000F0FFF; - driver1 &= 0x000F0FFF; - - if ((cond1 & driver1) == cond1) { - u32 bitMask = 0; - - if ((cond1 & 0x0F) == 0) /* BoardType is DONTCARE */ - return true; - - if ((cond1 & BIT(0)) != 0) /* GLNA */ - bitMask |= 0x000000FF; - if ((cond1 & BIT(1)) != 0) /* GPA */ - bitMask |= 0x0000FF00; - if ((cond1 & BIT(2)) != 0) /* ALNA */ - bitMask |= 0x00FF0000; - if ((cond1 & BIT(3)) != 0) /* APA */ - bitMask |= 0xFF000000; - - /* BoardType of each RF path is matched */ - if ((cond2 & bitMask) == (driver2 & bitMask)) - return true; - } - return false; -} - -/****************************************************************************** - * AGC_TAB.TXT - ******************************************************************************/ - -static u32 Array_MP_8723B_AGC_TAB[] = { - 0xC78, 0xFD000001, - 0xC78, 0xFC010001, - 0xC78, 0xFB020001, - 0xC78, 0xFA030001, - 0xC78, 0xF9040001, - 0xC78, 0xF8050001, - 0xC78, 0xF7060001, - 0xC78, 0xF6070001, - 0xC78, 0xF5080001, - 0xC78, 0xF4090001, - 0xC78, 0xF30A0001, - 0xC78, 0xF20B0001, - 0xC78, 0xF10C0001, - 0xC78, 0xF00D0001, - 0xC78, 0xEF0E0001, - 0xC78, 0xEE0F0001, - 0xC78, 0xED100001, - 0xC78, 0xEC110001, - 0xC78, 0xEB120001, - 0xC78, 0xEA130001, - 0xC78, 0xE9140001, - 0xC78, 0xE8150001, - 0xC78, 0xE7160001, - 0xC78, 0xE6170001, - 0xC78, 0xE5180001, - 0xC78, 0xE4190001, - 0xC78, 0xE31A0001, - 0xC78, 0xA51B0001, - 0xC78, 0xA41C0001, - 0xC78, 0xA31D0001, - 0xC78, 0x671E0001, - 0xC78, 0x661F0001, - 0xC78, 0x65200001, - 0xC78, 0x64210001, - 0xC78, 0x63220001, - 0xC78, 0x4A230001, - 0xC78, 0x49240001, - 0xC78, 0x48250001, - 0xC78, 0x47260001, - 0xC78, 0x46270001, - 0xC78, 0x45280001, - 0xC78, 0x44290001, - 0xC78, 0x432A0001, - 0xC78, 0x422B0001, - 0xC78, 0x292C0001, - 0xC78, 0x282D0001, - 0xC78, 0x272E0001, - 0xC78, 0x262F0001, - 0xC78, 0x0A300001, - 0xC78, 0x09310001, - 0xC78, 0x08320001, - 0xC78, 0x07330001, - 0xC78, 0x06340001, - 0xC78, 0x05350001, - 0xC78, 0x04360001, - 0xC78, 0x03370001, - 0xC78, 0x02380001, - 0xC78, 0x01390001, - 0xC78, 0x013A0001, - 0xC78, 0x013B0001, - 0xC78, 0x013C0001, - 0xC78, 0x013D0001, - 0xC78, 0x013E0001, - 0xC78, 0x013F0001, - 0xC78, 0xFC400001, - 0xC78, 0xFB410001, - 0xC78, 0xFA420001, - 0xC78, 0xF9430001, - 0xC78, 0xF8440001, - 0xC78, 0xF7450001, - 0xC78, 0xF6460001, - 0xC78, 0xF5470001, - 0xC78, 0xF4480001, - 0xC78, 0xF3490001, - 0xC78, 0xF24A0001, - 0xC78, 0xF14B0001, - 0xC78, 0xF04C0001, - 0xC78, 0xEF4D0001, - 0xC78, 0xEE4E0001, - 0xC78, 0xED4F0001, - 0xC78, 0xEC500001, - 0xC78, 0xEB510001, - 0xC78, 0xEA520001, - 0xC78, 0xE9530001, - 0xC78, 0xE8540001, - 0xC78, 0xE7550001, - 0xC78, 0xE6560001, - 0xC78, 0xE5570001, - 0xC78, 0xE4580001, - 0xC78, 0xE3590001, - 0xC78, 0xA65A0001, - 0xC78, 0xA55B0001, - 0xC78, 0xA45C0001, - 0xC78, 0xA35D0001, - 0xC78, 0x675E0001, - 0xC78, 0x665F0001, - 0xC78, 0x65600001, - 0xC78, 0x64610001, - 0xC78, 0x63620001, - 0xC78, 0x62630001, - 0xC78, 0x61640001, - 0xC78, 0x48650001, - 0xC78, 0x47660001, - 0xC78, 0x46670001, - 0xC78, 0x45680001, - 0xC78, 0x44690001, - 0xC78, 0x436A0001, - 0xC78, 0x426B0001, - 0xC78, 0x286C0001, - 0xC78, 0x276D0001, - 0xC78, 0x266E0001, - 0xC78, 0x256F0001, - 0xC78, 0x24700001, - 0xC78, 0x09710001, - 0xC78, 0x08720001, - 0xC78, 0x07730001, - 0xC78, 0x06740001, - 0xC78, 0x05750001, - 0xC78, 0x04760001, - 0xC78, 0x03770001, - 0xC78, 0x02780001, - 0xC78, 0x01790001, - 0xC78, 0x017A0001, - 0xC78, 0x017B0001, - 0xC78, 0x017C0001, - 0xC78, 0x017D0001, - 0xC78, 0x017E0001, - 0xC78, 0x017F0001, - 0xC50, 0x69553422, - 0xC50, 0x69553420, - 0x824, 0x00390204, - -}; - -void ODM_ReadAndConfig_MP_8723B_AGC_TAB(struct dm_odm_t *pDM_Odm) -{ - u32 i = 0; - u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_AGC_TAB); - u32 *Array = Array_MP_8723B_AGC_TAB; - - for (i = 0; i < ArrayLen; i += 2) { - u32 v1 = Array[i]; - u32 v2 = Array[i + 1]; - - /* This (offset, data) pair doesn't care the condition. */ - if (v1 < 0x40000000) { - odm_ConfigBB_AGC_8723B(pDM_Odm, v1, bMaskDWord, v2); - continue; - } else { - /* This line is the beginning of branch. */ - bool bMatched = true; - u8 cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - - if (cCond == COND_ELSE) { /* ELSE, ENDIF */ - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } else if (!CheckPositive(pDM_Odm, v1, v2)) { - bMatched = false; - READ_NEXT_PAIR(v1, v2, i); - READ_NEXT_PAIR(v1, v2, i); - } else { - READ_NEXT_PAIR(v1, v2, i); - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } - - if (!bMatched) { - /* - * Condition isn't matched. - * Discard the following (offset, data) pairs. - */ - while (v1 < 0x40000000 && i < ArrayLen - 2) - READ_NEXT_PAIR(v1, v2, i); - - i -= 2; /* prevent from for-loop += 2 */ - } else { - /* Configure matched pairs and skip to end of if-else. */ - while (v1 < 0x40000000 && i < ArrayLen - 2) { - odm_ConfigBB_AGC_8723B(pDM_Odm, v1, bMaskDWord, v2); - READ_NEXT_PAIR(v1, v2, i); - } - - /* Keeps reading until ENDIF. */ - cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - while (cCond != COND_ENDIF && i < ArrayLen - 2) { - READ_NEXT_PAIR(v1, v2, i); - cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - } - } - } - } -} - -/****************************************************************************** - * PHY_REG.TXT - ******************************************************************************/ - -static u32 Array_MP_8723B_PHY_REG[] = { - 0x800, 0x80040000, - 0x804, 0x00000003, - 0x808, 0x0000FC00, - 0x80C, 0x0000000A, - 0x810, 0x10001331, - 0x814, 0x020C3D10, - 0x818, 0x02200385, - 0x81C, 0x00000000, - 0x820, 0x01000100, - 0x824, 0x00190204, - 0x828, 0x00000000, - 0x82C, 0x00000000, - 0x830, 0x00000000, - 0x834, 0x00000000, - 0x838, 0x00000000, - 0x83C, 0x00000000, - 0x840, 0x00010000, - 0x844, 0x00000000, - 0x848, 0x00000000, - 0x84C, 0x00000000, - 0x850, 0x00000000, - 0x854, 0x00000000, - 0x858, 0x569A11A9, - 0x85C, 0x01000014, - 0x860, 0x66F60110, - 0x864, 0x061F0649, - 0x868, 0x00000000, - 0x86C, 0x27272700, - 0x870, 0x07000760, - 0x874, 0x25004000, - 0x878, 0x00000808, - 0x87C, 0x00000000, - 0x880, 0xB0000C1C, - 0x884, 0x00000001, - 0x888, 0x00000000, - 0x88C, 0xCCC000C0, - 0x890, 0x00000800, - 0x894, 0xFFFFFFFE, - 0x898, 0x40302010, - 0x89C, 0x00706050, - 0x900, 0x00000000, - 0x904, 0x00000023, - 0x908, 0x00000000, - 0x90C, 0x81121111, - 0x910, 0x00000002, - 0x914, 0x00000201, - 0xA00, 0x00D047C8, - 0xA04, 0x80FF800C, - 0xA08, 0x8C838300, - 0xA0C, 0x2E7F120F, - 0xA10, 0x9500BB78, - 0xA14, 0x1114D028, - 0xA18, 0x00881117, - 0xA1C, 0x89140F00, - 0xA20, 0x1A1B0000, - 0xA24, 0x090E1317, - 0xA28, 0x00000204, - 0xA2C, 0x00D30000, - 0xA70, 0x101FBF00, - 0xA74, 0x00000007, - 0xA78, 0x00000900, - 0xA7C, 0x225B0606, - 0xA80, 0x21806490, - 0xB2C, 0x00000000, - 0xC00, 0x48071D40, - 0xC04, 0x03A05611, - 0xC08, 0x000000E4, - 0xC0C, 0x6C6C6C6C, - 0xC10, 0x08800000, - 0xC14, 0x40000100, - 0xC18, 0x08800000, - 0xC1C, 0x40000100, - 0xC20, 0x00000000, - 0xC24, 0x00000000, - 0xC28, 0x00000000, - 0xC2C, 0x00000000, - 0xC30, 0x69E9AC44, - 0xC34, 0x469652AF, - 0xC38, 0x49795994, - 0xC3C, 0x0A97971C, - 0xC40, 0x1F7C403F, - 0xC44, 0x000100B7, - 0xC48, 0xEC020107, - 0xC4C, 0x007F037F, - 0xC50, 0x69553420, - 0xC54, 0x43BC0094, - 0xC58, 0x00013149, - 0xC5C, 0x00250492, - 0xC60, 0x00000000, - 0xC64, 0x7112848B, - 0xC68, 0x47C00BFF, - 0xC6C, 0x00000036, - 0xC70, 0x2C7F000D, - 0xC74, 0x020610DB, - 0xC78, 0x0000001F, - 0xC7C, 0x00B91612, - 0xC80, 0x390000E4, - 0xC84, 0x20F60000, - 0xC88, 0x40000100, - 0xC8C, 0x20200000, - 0xC90, 0x00020E1A, - 0xC94, 0x00000000, - 0xC98, 0x00020E1A, - 0xC9C, 0x00007F7F, - 0xCA0, 0x00000000, - 0xCA4, 0x000300A0, - 0xCA8, 0x00000000, - 0xCAC, 0x00000000, - 0xCB0, 0x00000000, - 0xCB4, 0x00000000, - 0xCB8, 0x00000000, - 0xCBC, 0x28000000, - 0xCC0, 0x00000000, - 0xCC4, 0x00000000, - 0xCC8, 0x00000000, - 0xCCC, 0x00000000, - 0xCD0, 0x00000000, - 0xCD4, 0x00000000, - 0xCD8, 0x64B22427, - 0xCDC, 0x00766932, - 0xCE0, 0x00222222, - 0xCE4, 0x00000000, - 0xCE8, 0x37644302, - 0xCEC, 0x2F97D40C, - 0xD00, 0x00000740, - 0xD04, 0x40020401, - 0xD08, 0x0000907F, - 0xD0C, 0x20010201, - 0xD10, 0xA0633333, - 0xD14, 0x3333BC53, - 0xD18, 0x7A8F5B6F, - 0xD2C, 0xCC979975, - 0xD30, 0x00000000, - 0xD34, 0x80608000, - 0xD38, 0x00000000, - 0xD3C, 0x00127353, - 0xD40, 0x00000000, - 0xD44, 0x00000000, - 0xD48, 0x00000000, - 0xD4C, 0x00000000, - 0xD50, 0x6437140A, - 0xD54, 0x00000000, - 0xD58, 0x00000282, - 0xD5C, 0x30032064, - 0xD60, 0x4653DE68, - 0xD64, 0x04518A3C, - 0xD68, 0x00002101, - 0xD6C, 0x2A201C16, - 0xD70, 0x1812362E, - 0xD74, 0x322C2220, - 0xD78, 0x000E3C24, - 0xE00, 0x2D2D2D2D, - 0xE04, 0x2D2D2D2D, - 0xE08, 0x0390272D, - 0xE10, 0x2D2D2D2D, - 0xE14, 0x2D2D2D2D, - 0xE18, 0x2D2D2D2D, - 0xE1C, 0x2D2D2D2D, - 0xE28, 0x00000000, - 0xE30, 0x1000DC1F, - 0xE34, 0x10008C1F, - 0xE38, 0x02140102, - 0xE3C, 0x681604C2, - 0xE40, 0x01007C00, - 0xE44, 0x01004800, - 0xE48, 0xFB000000, - 0xE4C, 0x000028D1, - 0xE50, 0x1000DC1F, - 0xE54, 0x10008C1F, - 0xE58, 0x02140102, - 0xE5C, 0x28160D05, - 0xE60, 0x00000008, - 0xE68, 0x001B2556, - 0xE6C, 0x00C00096, - 0xE70, 0x00C00096, - 0xE74, 0x01000056, - 0xE78, 0x01000014, - 0xE7C, 0x01000056, - 0xE80, 0x01000014, - 0xE84, 0x00C00096, - 0xE88, 0x01000056, - 0xE8C, 0x00C00096, - 0xED0, 0x00C00096, - 0xED4, 0x00C00096, - 0xED8, 0x00C00096, - 0xEDC, 0x000000D6, - 0xEE0, 0x000000D6, - 0xEEC, 0x01C00016, - 0xF14, 0x00000003, - 0xF4C, 0x00000000, - 0xF00, 0x00000300, - 0x820, 0x01000100, - 0x800, 0x83040000, - -}; - -void ODM_ReadAndConfig_MP_8723B_PHY_REG(struct dm_odm_t *pDM_Odm) -{ - u32 i = 0; - u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_PHY_REG); - u32 *Array = Array_MP_8723B_PHY_REG; - - for (i = 0; i < ArrayLen; i += 2) { - u32 v1 = Array[i]; - u32 v2 = Array[i + 1]; - - /* This (offset, data) pair doesn't care the condition. */ - if (v1 < 0x40000000) { - odm_ConfigBB_PHY_8723B(pDM_Odm, v1, bMaskDWord, v2); - continue; - } else { - /* This line is the beginning of branch. */ - bool bMatched = true; - u8 cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - - if (cCond == COND_ELSE) { /* ELSE, ENDIF */ - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } else if (!CheckPositive(pDM_Odm, v1, v2)) { - bMatched = false; - READ_NEXT_PAIR(v1, v2, i); - READ_NEXT_PAIR(v1, v2, i); - } else { - READ_NEXT_PAIR(v1, v2, i); - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } - - if (!bMatched) { - /* - * Condition isn't matched. - * Discard the following (offset, data) pairs. - */ - while (v1 < 0x40000000 && i < ArrayLen - 2) - READ_NEXT_PAIR(v1, v2, i); - - i -= 2; /* prevent from for-loop += 2 */ - } else { /* Configure matched pairs and skip to end of if-else. */ - while (v1 < 0x40000000 && i < ArrayLen - 2) { - odm_ConfigBB_PHY_8723B(pDM_Odm, v1, bMaskDWord, v2); - READ_NEXT_PAIR(v1, v2, i); - } - - /* Keeps reading until ENDIF. */ - cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - while (cCond != COND_ENDIF && i < ArrayLen - 2) { - READ_NEXT_PAIR(v1, v2, i); - cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - } - } - } - } -} - -/****************************************************************************** - * PHY_REG_PG.TXT - ******************************************************************************/ - -static u32 Array_MP_8723B_PHY_REG_PG[] = { - 0, 0x00000e08, 0x0000ff00, 0x00003800, - 0, 0x0000086c, 0xffffff00, 0x32343600, - 0, 0x00000e00, 0xffffffff, 0x40424444, - 0, 0x00000e04, 0xffffffff, 0x28323638, - 0, 0x00000e10, 0xffffffff, 0x38404244, - 0, 0x00000e14, 0xffffffff, 0x26303436 -}; - -void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(struct dm_odm_t *pDM_Odm) -{ - u32 i = 0; - u32 *Array = Array_MP_8723B_PHY_REG_PG; - - pDM_Odm->PhyRegPgVersion = 1; - pDM_Odm->PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE; - - for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_PHY_REG_PG); i += 4) { - u32 v1 = Array[i]; - u32 v2 = Array[i + 1]; - u32 v3 = Array[i + 2]; - u32 v4 = Array[i + 3]; - - odm_ConfigBB_PHY_REG_PG_8723B(pDM_Odm, v1, v2, v3, v4); - } -} diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.h b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.h deleted file mode 100644 index 054acfe231b4..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __INC_MP_BB_HW_IMG_8723B_H -#define __INC_MP_BB_HW_IMG_8723B_H - -/****************************************************************************** - * AGC_TAB.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_AGC_TAB(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); - -/****************************************************************************** - * PHY_REG.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_PHY_REG(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); - -/****************************************************************************** - * PHY_REG_PG.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); -u32 ODM_GetVersion_MP_8723B_PHY_REG_PG(void); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c deleted file mode 100644 index 0e098bd2d9f6..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c +++ /dev/null @@ -1,237 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include "odm_precomp.h" - -static bool CheckPositive(struct dm_odm_t *pDM_Odm, const u32 Condition1, const u32 Condition2) -{ - u8 _BoardType = - ((pDM_Odm->BoardType & BIT(4)) >> 4) << 0 | /* _GLNA */ - ((pDM_Odm->BoardType & BIT(3)) >> 3) << 1 | /* _GPA */ - ((pDM_Odm->BoardType & BIT(7)) >> 7) << 2 | /* _ALNA */ - ((pDM_Odm->BoardType & BIT(6)) >> 6) << 3 | /* _APA */ - ((pDM_Odm->BoardType & BIT(2)) >> 2) << 4; /* _BT */ - - u32 cond1 = Condition1, cond2 = Condition2; - u32 driver1 = - pDM_Odm->CutVersion << 24 | - pDM_Odm->SupportPlatform << 16 | - pDM_Odm->PackageType << 12 | - pDM_Odm->SupportInterface << 8 | - _BoardType; - - u32 driver2 = - pDM_Odm->TypeGLNA << 0 | - pDM_Odm->TypeGPA << 8 | - pDM_Odm->TypeALNA << 16 | - pDM_Odm->TypeAPA << 24; - - /* Value Defined Check =============== */ - /* QFN Type [15:12] and Cut Version [27:24] need to do value check */ - - if (((cond1 & 0x0000F000) != 0) && ((cond1 & 0x0000F000) != (driver1 & 0x0000F000))) - return false; - if (((cond1 & 0x0F000000) != 0) && ((cond1 & 0x0F000000) != (driver1 & 0x0F000000))) - return false; - - /* Bit Defined Check ================ */ - /* We don't care [31:28] and [23:20] */ - /* */ - cond1 &= 0x000F0FFF; - driver1 &= 0x000F0FFF; - - if ((cond1 & driver1) == cond1) { - u32 bitMask = 0; - - if ((cond1 & 0x0F) == 0) /* BoardType is DONTCARE */ - return true; - - if ((cond1 & BIT(0)) != 0) /* GLNA */ - bitMask |= 0x000000FF; - if ((cond1 & BIT(1)) != 0) /* GPA */ - bitMask |= 0x0000FF00; - if ((cond1 & BIT(2)) != 0) /* ALNA */ - bitMask |= 0x00FF0000; - if ((cond1 & BIT(3)) != 0) /* APA */ - bitMask |= 0xFF000000; - - /* BoardType of each RF path is matched */ - if ((cond2 & bitMask) == (driver2 & bitMask)) - return true; - } - return false; -} - -/****************************************************************************** - * MAC_REG.TXT - ******************************************************************************/ - -static u32 Array_MP_8723B_MAC_REG[] = { - 0x02F, 0x00000030, - 0x035, 0x00000000, - 0x039, 0x00000008, - 0x04E, 0x000000E0, - 0x064, 0x00000000, - 0x067, 0x00000020, - 0x428, 0x0000000A, - 0x429, 0x00000010, - 0x430, 0x00000000, - 0x431, 0x00000000, - 0x432, 0x00000000, - 0x433, 0x00000001, - 0x434, 0x00000004, - 0x435, 0x00000005, - 0x436, 0x00000007, - 0x437, 0x00000008, - 0x43C, 0x00000004, - 0x43D, 0x00000005, - 0x43E, 0x00000007, - 0x43F, 0x00000008, - 0x440, 0x0000005D, - 0x441, 0x00000001, - 0x442, 0x00000000, - 0x444, 0x00000010, - 0x445, 0x00000000, - 0x446, 0x00000000, - 0x447, 0x00000000, - 0x448, 0x00000000, - 0x449, 0x000000F0, - 0x44A, 0x0000000F, - 0x44B, 0x0000003E, - 0x44C, 0x00000010, - 0x44D, 0x00000000, - 0x44E, 0x00000000, - 0x44F, 0x00000000, - 0x450, 0x00000000, - 0x451, 0x000000F0, - 0x452, 0x0000000F, - 0x453, 0x00000000, - 0x456, 0x0000005E, - 0x460, 0x00000066, - 0x461, 0x00000066, - 0x4C8, 0x000000FF, - 0x4C9, 0x00000008, - 0x4CC, 0x000000FF, - 0x4CD, 0x000000FF, - 0x4CE, 0x00000001, - 0x500, 0x00000026, - 0x501, 0x000000A2, - 0x502, 0x0000002F, - 0x503, 0x00000000, - 0x504, 0x00000028, - 0x505, 0x000000A3, - 0x506, 0x0000005E, - 0x507, 0x00000000, - 0x508, 0x0000002B, - 0x509, 0x000000A4, - 0x50A, 0x0000005E, - 0x50B, 0x00000000, - 0x50C, 0x0000004F, - 0x50D, 0x000000A4, - 0x50E, 0x00000000, - 0x50F, 0x00000000, - 0x512, 0x0000001C, - 0x514, 0x0000000A, - 0x516, 0x0000000A, - 0x525, 0x0000004F, - 0x550, 0x00000010, - 0x551, 0x00000010, - 0x559, 0x00000002, - 0x55C, 0x00000050, - 0x55D, 0x000000FF, - 0x605, 0x00000030, - 0x608, 0x0000000E, - 0x609, 0x0000002A, - 0x620, 0x000000FF, - 0x621, 0x000000FF, - 0x622, 0x000000FF, - 0x623, 0x000000FF, - 0x624, 0x000000FF, - 0x625, 0x000000FF, - 0x626, 0x000000FF, - 0x627, 0x000000FF, - 0x638, 0x00000050, - 0x63C, 0x0000000A, - 0x63D, 0x0000000A, - 0x63E, 0x0000000E, - 0x63F, 0x0000000E, - 0x640, 0x00000040, - 0x642, 0x00000040, - 0x643, 0x00000000, - 0x652, 0x000000C8, - 0x66E, 0x00000005, - 0x700, 0x00000021, - 0x701, 0x00000043, - 0x702, 0x00000065, - 0x703, 0x00000087, - 0x708, 0x00000021, - 0x709, 0x00000043, - 0x70A, 0x00000065, - 0x70B, 0x00000087, - 0x765, 0x00000018, - 0x76E, 0x00000004, - -}; - -void ODM_ReadAndConfig_MP_8723B_MAC_REG(struct dm_odm_t *pDM_Odm) -{ - u32 i = 0; - u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_MAC_REG); - u32 *Array = Array_MP_8723B_MAC_REG; - - for (i = 0; i < ArrayLen; i += 2) { - u32 v1 = Array[i]; - u32 v2 = Array[i + 1]; - - /* This (offset, data) pair doesn't care the condition. */ - if (v1 < 0x40000000) { - odm_ConfigMAC_8723B(pDM_Odm, v1, (u8)v2); - continue; - } else { - /* This line is the beginning of branch. */ - bool bMatched = true; - u8 cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - - if (cCond == COND_ELSE) { /* ELSE, ENDIF */ - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } else if (!CheckPositive(pDM_Odm, v1, v2)) { - bMatched = false; - READ_NEXT_PAIR(v1, v2, i); - READ_NEXT_PAIR(v1, v2, i); - } else { - READ_NEXT_PAIR(v1, v2, i); - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } - - if (!bMatched) { - /* - * Condition isn't matched. - * Discard the following (offset, data) pairs. - */ - while (v1 < 0x40000000 && i < ArrayLen - 2) - READ_NEXT_PAIR(v1, v2, i); - - i -= 2; /* prevent from for-loop += 2 */ - } else { /* Configure matched pairs and skip to end of if-else. */ - while (v1 < 0x40000000 && i < ArrayLen - 2) { - odm_ConfigMAC_8723B(pDM_Odm, v1, (u8)v2); - READ_NEXT_PAIR(v1, v2, i); - } - - /* Keeps reading until ENDIF. */ - cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - while (cCond != COND_ENDIF && i < ArrayLen - 2) { - READ_NEXT_PAIR(v1, v2, i); - cCond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28); - } - } - } - } -} diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.h b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.h deleted file mode 100644 index 250861325919..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.h +++ /dev/null @@ -1,19 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __INC_MP_MAC_HW_IMG_8723B_H -#define __INC_MP_MAC_HW_IMG_8723B_H - -/****************************************************************************** - * MAC_REG.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_MAC_REG(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); -#endif diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c deleted file mode 100644 index 30c8624bba25..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c +++ /dev/null @@ -1,554 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include "odm_precomp.h" - -static bool CheckPositive( - struct dm_odm_t *pDM_Odm, const u32 Condition1, const u32 Condition2 -) -{ - u8 _BoardType = - ((pDM_Odm->BoardType & BIT(4)) >> 4) << 0 | /* _GLNA */ - ((pDM_Odm->BoardType & BIT(3)) >> 3) << 1 | /* _GPA */ - ((pDM_Odm->BoardType & BIT(7)) >> 7) << 2 | /* _ALNA */ - ((pDM_Odm->BoardType & BIT(6)) >> 6) << 3 | /* _APA */ - ((pDM_Odm->BoardType & BIT(2)) >> 2) << 4; /* _BT */ - - u32 cond1 = Condition1, cond2 = Condition2; - u32 driver1 = - pDM_Odm->CutVersion << 24 | - pDM_Odm->SupportPlatform << 16 | - pDM_Odm->PackageType << 12 | - pDM_Odm->SupportInterface << 8 | - _BoardType; - - u32 driver2 = - pDM_Odm->TypeGLNA << 0 | - pDM_Odm->TypeGPA << 8 | - pDM_Odm->TypeALNA << 16 | - pDM_Odm->TypeAPA << 24; - - /* Value Defined Check =============== */ - /* QFN Type [15:12] and Cut Version [27:24] need to do value check */ - - if ( - ((cond1 & 0x0000F000) != 0) && - ((cond1 & 0x0000F000) != (driver1 & 0x0000F000)) - ) - return false; - - if ( - ((cond1 & 0x0F000000) != 0) && - ((cond1 & 0x0F000000) != (driver1 & 0x0F000000)) - ) - return false; - - /* Bit Defined Check ================ */ - /* We don't care [31:28] and [23:20] */ - cond1 &= 0x000F0FFF; - driver1 &= 0x000F0FFF; - - if ((cond1 & driver1) == cond1) { - u32 bitMask = 0; - - if ((cond1 & 0x0F) == 0) /* BoardType is DONTCARE */ - return true; - - if ((cond1 & BIT(0)) != 0) /* GLNA */ - bitMask |= 0x000000FF; - if ((cond1 & BIT(1)) != 0) /* GPA */ - bitMask |= 0x0000FF00; - if ((cond1 & BIT(2)) != 0) /* ALNA */ - bitMask |= 0x00FF0000; - if ((cond1 & BIT(3)) != 0) /* APA */ - bitMask |= 0xFF000000; - - /* BoardType of each RF path is matched */ - if ((cond2 & bitMask) == (driver2 & bitMask)) - return true; - - return false; - } - - return false; -} - -/****************************************************************************** - * RadioA.TXT - ******************************************************************************/ - -static u32 Array_MP_8723B_RadioA[] = { - 0x000, 0x00010000, - 0x0B0, 0x000DFFE0, - 0x0FE, 0x00000000, - 0x0FE, 0x00000000, - 0x0FE, 0x00000000, - 0x0B1, 0x00000018, - 0x0FE, 0x00000000, - 0x0FE, 0x00000000, - 0x0FE, 0x00000000, - 0x0B2, 0x00084C00, - 0x0B5, 0x0000D2CC, - 0x0B6, 0x000925AA, - 0x0B7, 0x00000010, - 0x0B8, 0x0000907F, - 0x05C, 0x00000002, - 0x07C, 0x00000002, - 0x07E, 0x00000005, - 0x08B, 0x0006FC00, - 0x0B0, 0x000FF9F0, - 0x01C, 0x000739D2, - 0x01E, 0x00000000, - 0x0DF, 0x00000780, - 0x050, 0x00067435, - 0x80002000, 0x00000000, 0x40000000, 0x00000000, - 0x051, 0x0006B10E, - 0x90003000, 0x00000000, 0x40000000, 0x00000000, - 0x051, 0x0006B10E, - 0x90004000, 0x00000000, 0x40000000, 0x00000000, - 0x051, 0x0006B10E, - 0xA0000000, 0x00000000, - 0x051, 0x0006B04E, - 0xB0000000, 0x00000000, - 0x052, 0x000007D2, - 0x053, 0x00000000, - 0x054, 0x00050400, - 0x055, 0x0004026E, - 0x0DD, 0x0000004C, - 0x070, 0x00067435, - 0x80002000, 0x00000000, 0x40000000, 0x00000000, - 0x071, 0x0006B10E, - 0x90003000, 0x00000000, 0x40000000, 0x00000000, - 0x071, 0x0006B10E, - 0x90004000, 0x00000000, 0x40000000, 0x00000000, - 0x071, 0x0006B10E, - 0xA0000000, 0x00000000, - 0x071, 0x0006B04E, - 0xB0000000, 0x00000000, - 0x072, 0x000007D2, - 0x073, 0x00000000, - 0x074, 0x00050400, - 0x075, 0x0004026E, - 0x0EF, 0x00000100, - 0x034, 0x0000ADD7, - 0x035, 0x00005C00, - 0x034, 0x00009DD4, - 0x035, 0x00005000, - 0x034, 0x00008DD1, - 0x035, 0x00004400, - 0x034, 0x00007DCE, - 0x035, 0x00003800, - 0x034, 0x00006CD1, - 0x035, 0x00004400, - 0x034, 0x00005CCE, - 0x035, 0x00003800, - 0x034, 0x000048CE, - 0x035, 0x00004400, - 0x034, 0x000034CE, - 0x035, 0x00003800, - 0x034, 0x00002451, - 0x035, 0x00004400, - 0x034, 0x0000144E, - 0x035, 0x00003800, - 0x034, 0x00000051, - 0x035, 0x00004400, - 0x0EF, 0x00000000, - 0x0EF, 0x00000100, - 0x0ED, 0x00000010, - 0x044, 0x0000ADD7, - 0x044, 0x00009DD4, - 0x044, 0x00008DD1, - 0x044, 0x00007DCE, - 0x044, 0x00006CC1, - 0x044, 0x00005CCE, - 0x044, 0x000044D1, - 0x044, 0x000034CE, - 0x044, 0x00002451, - 0x044, 0x0000144E, - 0x044, 0x00000051, - 0x0EF, 0x00000000, - 0x0ED, 0x00000000, - 0x07F, 0x00020080, - 0x0EF, 0x00002000, - 0x03B, 0x000380EF, - 0x03B, 0x000302FE, - 0x03B, 0x00028CE6, - 0x03B, 0x000200BC, - 0x03B, 0x000188A5, - 0x03B, 0x00010FBC, - 0x03B, 0x00008F71, - 0x03B, 0x00000900, - 0x0EF, 0x00000000, - 0x0ED, 0x00000001, - 0x040, 0x000380EF, - 0x040, 0x000302FE, - 0x040, 0x00028CE6, - 0x040, 0x000200BC, - 0x040, 0x000188A5, - 0x040, 0x00010FBC, - 0x040, 0x00008F71, - 0x040, 0x00000900, - 0x0ED, 0x00000000, - 0x082, 0x00080000, - 0x083, 0x00008000, - 0x084, 0x00048D80, - 0x085, 0x00068000, - 0x0A2, 0x00080000, - 0x0A3, 0x00008000, - 0x0A4, 0x00048D80, - 0x0A5, 0x00068000, - 0x0ED, 0x00000002, - 0x0EF, 0x00000002, - 0x056, 0x00000032, - 0x076, 0x00000032, - 0x001, 0x00000780, - -}; - -void ODM_ReadAndConfig_MP_8723B_RadioA(struct dm_odm_t *pDM_Odm) -{ - u32 i = 0; - u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_RadioA); - u32 *Array = Array_MP_8723B_RadioA; - - for (i = 0; i < ArrayLen; i += 2) { - u32 v1 = Array[i]; - u32 v2 = Array[i+1]; - - /* This (offset, data) pair doesn't care the condition. */ - if (v1 < 0x40000000) { - odm_ConfigRF_RadioA_8723B(pDM_Odm, v1, v2); - continue; - } else { - /* This line is the beginning of branch. */ - bool bMatched = true; - u8 cCond = (u8)((v1 & (BIT(29)|BIT(28))) >> 28); - - if (cCond == COND_ELSE) { /* ELSE, ENDIF */ - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } else if (!CheckPositive(pDM_Odm, v1, v2)) { - bMatched = false; - READ_NEXT_PAIR(v1, v2, i); - READ_NEXT_PAIR(v1, v2, i); - } else { - READ_NEXT_PAIR(v1, v2, i); - bMatched = true; - READ_NEXT_PAIR(v1, v2, i); - } - - if (!bMatched) { - /* - * Condition isn't matched. - * Discard the following (offset, data) pairs. - */ - while (v1 < 0x40000000 && i < ArrayLen-2) - READ_NEXT_PAIR(v1, v2, i); - - i -= 2; /* prevent from for-loop += 2 */ - } else { - /* Configure matched pairs and skip to end of if-else. */ - while (v1 < 0x40000000 && i < ArrayLen-2) { - odm_ConfigRF_RadioA_8723B(pDM_Odm, v1, v2); - READ_NEXT_PAIR(v1, v2, i); - } - - /* Keeps reading until ENDIF. */ - cCond = (u8)((v1 & (BIT(29)|BIT(28))) >> 28); - while (cCond != COND_ENDIF && i < ArrayLen-2) { - READ_NEXT_PAIR(v1, v2, i); - cCond = (u8)((v1 & (BIT(29)|BIT(28))) >> 28); - } - } - } - } -} - -/****************************************************************************** - * TxPowerTrack_SDIO.TXT - ******************************************************************************/ - -static u8 gDeltaSwingTableIdx_MP_2GB_N_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 6, - 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GB_P_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, - 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GA_N_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 6, - 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GA_P_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, - 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GCCKB_N_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8, - 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GCCKB_P_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 7, 7, - 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GCCKA_N_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8, - 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 -}; -static u8 gDeltaSwingTableIdx_MP_2GCCKA_P_TxPowerTrack_SDIO_8723B[] = { - 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 7, 7, - 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 15 -}; - -void ODM_ReadAndConfig_MP_8723B_TxPowerTrack_SDIO(struct dm_odm_t *pDM_Odm) -{ - struct odm_rf_cal_t *pRFCalibrateInfo = &pDM_Odm->RFCalibrateInfo; - - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GA_P, - gDeltaSwingTableIdx_MP_2GA_P_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GA_N, - gDeltaSwingTableIdx_MP_2GA_N_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GB_P, - gDeltaSwingTableIdx_MP_2GB_P_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GB_N, - gDeltaSwingTableIdx_MP_2GB_N_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_P, - gDeltaSwingTableIdx_MP_2GCCKA_P_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_N, - gDeltaSwingTableIdx_MP_2GCCKA_N_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_P, - gDeltaSwingTableIdx_MP_2GCCKB_P_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); - memcpy( - pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_N, - gDeltaSwingTableIdx_MP_2GCCKB_N_TxPowerTrack_SDIO_8723B, - DELTA_SWINGIDX_SIZE - ); -} - -/****************************************************************************** - * TXPWR_LMT.TXT - ******************************************************************************/ - -static u8 *Array_MP_8723B_TXPWR_LMT[] = { - "FCC", "20M", "CCK", "1T", "01", "32", - "ETSI", "20M", "CCK", "1T", "01", "32", - "MKK", "20M", "CCK", "1T", "01", "32", - "FCC", "20M", "CCK", "1T", "02", "32", - "ETSI", "20M", "CCK", "1T", "02", "32", - "MKK", "20M", "CCK", "1T", "02", "32", - "FCC", "20M", "CCK", "1T", "03", "32", - "ETSI", "20M", "CCK", "1T", "03", "32", - "MKK", "20M", "CCK", "1T", "03", "32", - "FCC", "20M", "CCK", "1T", "04", "32", - "ETSI", "20M", "CCK", "1T", "04", "32", - "MKK", "20M", "CCK", "1T", "04", "32", - "FCC", "20M", "CCK", "1T", "05", "32", - "ETSI", "20M", "CCK", "1T", "05", "32", - "MKK", "20M", "CCK", "1T", "05", "32", - "FCC", "20M", "CCK", "1T", "06", "32", - "ETSI", "20M", "CCK", "1T", "06", "32", - "MKK", "20M", "CCK", "1T", "06", "32", - "FCC", "20M", "CCK", "1T", "07", "32", - "ETSI", "20M", "CCK", "1T", "07", "32", - "MKK", "20M", "CCK", "1T", "07", "32", - "FCC", "20M", "CCK", "1T", "08", "32", - "ETSI", "20M", "CCK", "1T", "08", "32", - "MKK", "20M", "CCK", "1T", "08", "32", - "FCC", "20M", "CCK", "1T", "09", "32", - "ETSI", "20M", "CCK", "1T", "09", "32", - "MKK", "20M", "CCK", "1T", "09", "32", - "FCC", "20M", "CCK", "1T", "10", "32", - "ETSI", "20M", "CCK", "1T", "10", "32", - "MKK", "20M", "CCK", "1T", "10", "32", - "FCC", "20M", "CCK", "1T", "11", "32", - "ETSI", "20M", "CCK", "1T", "11", "32", - "MKK", "20M", "CCK", "1T", "11", "32", - "FCC", "20M", "CCK", "1T", "12", "63", - "ETSI", "20M", "CCK", "1T", "12", "32", - "MKK", "20M", "CCK", "1T", "12", "32", - "FCC", "20M", "CCK", "1T", "13", "63", - "ETSI", "20M", "CCK", "1T", "13", "32", - "MKK", "20M", "CCK", "1T", "13", "32", - "FCC", "20M", "CCK", "1T", "14", "63", - "ETSI", "20M", "CCK", "1T", "14", "63", - "MKK", "20M", "CCK", "1T", "14", "32", - "FCC", "20M", "OFDM", "1T", "01", "28", - "ETSI", "20M", "OFDM", "1T", "01", "32", - "MKK", "20M", "OFDM", "1T", "01", "32", - "FCC", "20M", "OFDM", "1T", "02", "28", - "ETSI", "20M", "OFDM", "1T", "02", "32", - "MKK", "20M", "OFDM", "1T", "02", "32", - "FCC", "20M", "OFDM", "1T", "03", "32", - "ETSI", "20M", "OFDM", "1T", "03", "32", - "MKK", "20M", "OFDM", "1T", "03", "32", - "FCC", "20M", "OFDM", "1T", "04", "32", - "ETSI", "20M", "OFDM", "1T", "04", "32", - "MKK", "20M", "OFDM", "1T", "04", "32", - "FCC", "20M", "OFDM", "1T", "05", "32", - "ETSI", "20M", "OFDM", "1T", "05", "32", - "MKK", "20M", "OFDM", "1T", "05", "32", - "FCC", "20M", "OFDM", "1T", "06", "32", - "ETSI", "20M", "OFDM", "1T", "06", "32", - "MKK", "20M", "OFDM", "1T", "06", "32", - "FCC", "20M", "OFDM", "1T", "07", "32", - "ETSI", "20M", "OFDM", "1T", "07", "32", - "MKK", "20M", "OFDM", "1T", "07", "32", - "FCC", "20M", "OFDM", "1T", "08", "32", - "ETSI", "20M", "OFDM", "1T", "08", "32", - "MKK", "20M", "OFDM", "1T", "08", "32", - "FCC", "20M", "OFDM", "1T", "09", "32", - "ETSI", "20M", "OFDM", "1T", "09", "32", - "MKK", "20M", "OFDM", "1T", "09", "32", - "FCC", "20M", "OFDM", "1T", "10", "28", - "ETSI", "20M", "OFDM", "1T", "10", "32", - "MKK", "20M", "OFDM", "1T", "10", "32", - "FCC", "20M", "OFDM", "1T", "11", "28", - "ETSI", "20M", "OFDM", "1T", "11", "32", - "MKK", "20M", "OFDM", "1T", "11", "32", - "FCC", "20M", "OFDM", "1T", "12", "63", - "ETSI", "20M", "OFDM", "1T", "12", "32", - "MKK", "20M", "OFDM", "1T", "12", "32", - "FCC", "20M", "OFDM", "1T", "13", "63", - "ETSI", "20M", "OFDM", "1T", "13", "32", - "MKK", "20M", "OFDM", "1T", "13", "32", - "FCC", "20M", "OFDM", "1T", "14", "63", - "ETSI", "20M", "OFDM", "1T", "14", "63", - "MKK", "20M", "OFDM", "1T", "14", "63", - "FCC", "20M", "HT", "1T", "01", "26", - "ETSI", "20M", "HT", "1T", "01", "32", - "MKK", "20M", "HT", "1T", "01", "32", - "FCC", "20M", "HT", "1T", "02", "26", - "ETSI", "20M", "HT", "1T", "02", "32", - "MKK", "20M", "HT", "1T", "02", "32", - "FCC", "20M", "HT", "1T", "03", "32", - "ETSI", "20M", "HT", "1T", "03", "32", - "MKK", "20M", "HT", "1T", "03", "32", - "FCC", "20M", "HT", "1T", "04", "32", - "ETSI", "20M", "HT", "1T", "04", "32", - "MKK", "20M", "HT", "1T", "04", "32", - "FCC", "20M", "HT", "1T", "05", "32", - "ETSI", "20M", "HT", "1T", "05", "32", - "MKK", "20M", "HT", "1T", "05", "32", - "FCC", "20M", "HT", "1T", "06", "32", - "ETSI", "20M", "HT", "1T", "06", "32", - "MKK", "20M", "HT", "1T", "06", "32", - "FCC", "20M", "HT", "1T", "07", "32", - "ETSI", "20M", "HT", "1T", "07", "32", - "MKK", "20M", "HT", "1T", "07", "32", - "FCC", "20M", "HT", "1T", "08", "32", - "ETSI", "20M", "HT", "1T", "08", "32", - "MKK", "20M", "HT", "1T", "08", "32", - "FCC", "20M", "HT", "1T", "09", "32", - "ETSI", "20M", "HT", "1T", "09", "32", - "MKK", "20M", "HT", "1T", "09", "32", - "FCC", "20M", "HT", "1T", "10", "26", - "ETSI", "20M", "HT", "1T", "10", "32", - "MKK", "20M", "HT", "1T", "10", "32", - "FCC", "20M", "HT", "1T", "11", "26", - "ETSI", "20M", "HT", "1T", "11", "32", - "MKK", "20M", "HT", "1T", "11", "32", - "FCC", "20M", "HT", "1T", "12", "63", - "ETSI", "20M", "HT", "1T", "12", "32", - "MKK", "20M", "HT", "1T", "12", "32", - "FCC", "20M", "HT", "1T", "13", "63", - "ETSI", "20M", "HT", "1T", "13", "32", - "MKK", "20M", "HT", "1T", "13", "32", - "FCC", "20M", "HT", "1T", "14", "63", - "ETSI", "20M", "HT", "1T", "14", "63", - "MKK", "20M", "HT", "1T", "14", "63", - "FCC", "40M", "HT", "1T", "01", "63", - "ETSI", "40M", "HT", "1T", "01", "63", - "MKK", "40M", "HT", "1T", "01", "63", - "FCC", "40M", "HT", "1T", "02", "63", - "ETSI", "40M", "HT", "1T", "02", "63", - "MKK", "40M", "HT", "1T", "02", "63", - "FCC", "40M", "HT", "1T", "03", "26", - "ETSI", "40M", "HT", "1T", "03", "32", - "MKK", "40M", "HT", "1T", "03", "32", - "FCC", "40M", "HT", "1T", "04", "26", - "ETSI", "40M", "HT", "1T", "04", "32", - "MKK", "40M", "HT", "1T", "04", "32", - "FCC", "40M", "HT", "1T", "05", "32", - "ETSI", "40M", "HT", "1T", "05", "32", - "MKK", "40M", "HT", "1T", "05", "32", - "FCC", "40M", "HT", "1T", "06", "32", - "ETSI", "40M", "HT", "1T", "06", "32", - "MKK", "40M", "HT", "1T", "06", "32", - "FCC", "40M", "HT", "1T", "07", "32", - "ETSI", "40M", "HT", "1T", "07", "32", - "MKK", "40M", "HT", "1T", "07", "32", - "FCC", "40M", "HT", "1T", "08", "26", - "ETSI", "40M", "HT", "1T", "08", "32", - "MKK", "40M", "HT", "1T", "08", "32", - "FCC", "40M", "HT", "1T", "09", "26", - "ETSI", "40M", "HT", "1T", "09", "32", - "MKK", "40M", "HT", "1T", "09", "32", - "FCC", "40M", "HT", "1T", "10", "26", - "ETSI", "40M", "HT", "1T", "10", "32", - "MKK", "40M", "HT", "1T", "10", "32", - "FCC", "40M", "HT", "1T", "11", "26", - "ETSI", "40M", "HT", "1T", "11", "32", - "MKK", "40M", "HT", "1T", "11", "32", - "FCC", "40M", "HT", "1T", "12", "63", - "ETSI", "40M", "HT", "1T", "12", "32", - "MKK", "40M", "HT", "1T", "12", "32", - "FCC", "40M", "HT", "1T", "13", "63", - "ETSI", "40M", "HT", "1T", "13", "32", - "MKK", "40M", "HT", "1T", "13", "32", - "FCC", "40M", "HT", "1T", "14", "63", - "ETSI", "40M", "HT", "1T", "14", "63", - "MKK", "40M", "HT", "1T", "14", "63" -}; - -void ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(struct dm_odm_t *pDM_Odm) -{ - u32 i = 0; - u8 **Array = Array_MP_8723B_TXPWR_LMT; - - for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_TXPWR_LMT); i += 6) { - u8 *regulation = Array[i]; - u8 *bandwidth = Array[i+1]; - u8 *rate = Array[i+2]; - u8 *rfPath = Array[i+3]; - u8 *chnl = Array[i+4]; - u8 *val = Array[i+5]; - - odm_ConfigBB_TXPWR_LMT_8723B( - pDM_Odm, - regulation, - bandwidth, - rate, - rfPath, - chnl, - val - ); - } -} diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.h b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.h deleted file mode 100644 index 7b4f399fcdff..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __INC_MP_RF_HW_IMG_8723B_H -#define __INC_MP_RF_HW_IMG_8723B_H - -/****************************************************************************** - * RadioA.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_RadioA(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); - -/****************************************************************************** - * TxPowerTrack_SDIO.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_TxPowerTrack_SDIO(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); -u32 ODM_GetVersion_MP_8723B_TxPowerTrack_SDIO(void); - -/****************************************************************************** - * TXPWR_LMT.TXT - ******************************************************************************/ - -void -ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(/* TC: Test Chip, MP: MP Chip */ - struct dm_odm_t *pDM_Odm -); -u32 ODM_GetVersion_MP_8723B_TXPWR_LMT(void); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf.c b/drivers/staging/rtl8723bs/hal/HalPhyRf.c deleted file mode 100644 index bf44c1050be5..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalPhyRf.c +++ /dev/null @@ -1,268 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -/* include "Mp_Precomp.h" */ -#include "odm_precomp.h" - -void ConfigureTxpowerTrack(struct dm_odm_t *pDM_Odm, struct txpwrtrack_cfg *pConfig) -{ - ConfigureTxpowerTrack_8723B(pConfig); -} - -/* */ -/* <20121113, Kordan> This function should be called when TxAGC changed. */ -/* Otherwise the previous compensation is gone, because we record the */ -/* delta of temperature between two TxPowerTracking watch dogs. */ -/* */ -/* NOTE: If Tx BB swing or Tx scaling is varified during run-time, still */ -/* need to call this function. */ -/* */ -void ODM_ClearTxPowerTrackingState(struct dm_odm_t *pDM_Odm) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(pDM_Odm->Adapter); - u8 p = 0; - - pDM_Odm->BbSwingIdxCckBase = pDM_Odm->DefaultCckIndex; - pDM_Odm->BbSwingIdxCck = pDM_Odm->DefaultCckIndex; - pDM_Odm->RFCalibrateInfo.CCK_index = 0; - - for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { - pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->DefaultOfdmIndex; - pDM_Odm->BbSwingIdxOfdm[p] = pDM_Odm->DefaultOfdmIndex; - pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->DefaultOfdmIndex; - - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] = 0; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] = 0; - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; - - /* Initial Mix mode power tracking */ - pDM_Odm->Absolute_OFDMSwingIdx[p] = 0; - pDM_Odm->Remnant_OFDMSwingIdx[p] = 0; - } - - /* Initial at Modify Tx Scaling Mode */ - pDM_Odm->Modify_TxAGC_Flag_PathA = false; - /* Initial at Modify Tx Scaling Mode */ - pDM_Odm->Modify_TxAGC_Flag_PathB = false; - pDM_Odm->Remnant_CCKSwingIdx = 0; - pDM_Odm->RFCalibrateInfo.ThermalValue = pHalData->EEPROMThermalMeter; - pDM_Odm->RFCalibrateInfo.ThermalValue_IQK = pHalData->EEPROMThermalMeter; - pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = pHalData->EEPROMThermalMeter; -} - -void ODM_TXPowerTrackingCallback_ThermalMeter(struct adapter *Adapter) -{ - - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - u8 ThermalValue = 0, delta, delta_LCK, p = 0, i = 0; - u8 ThermalValue_AVG_count = 0; - u32 ThermalValue_AVG = 0; - - u8 OFDM_min_index = 0; /* OFDM BB Swing should be less than +3.0dB, which is required by Arthur */ - u8 Indexforchannel = 0; /* GetRightChnlPlaceforIQK(pHalData->CurrentChannel) */ - - struct txpwrtrack_cfg c; - - /* 4 1. The following TWO tables decide the final index of OFDM/CCK swing table. */ - u8 *deltaSwingTableIdx_TUP_A; - u8 *deltaSwingTableIdx_TDOWN_A; - u8 *deltaSwingTableIdx_TUP_B; - u8 *deltaSwingTableIdx_TDOWN_B; - - /* 4 2. Initialization (7 steps in total) */ - - ConfigureTxpowerTrack(pDM_Odm, &c); - - (*c.GetDeltaSwingTable)( - pDM_Odm, - (u8 **)&deltaSwingTableIdx_TUP_A, - (u8 **)&deltaSwingTableIdx_TDOWN_A, - (u8 **)&deltaSwingTableIdx_TUP_B, - (u8 **)&deltaSwingTableIdx_TDOWN_B - ); - - /* cosa add for debug */ - pDM_Odm->RFCalibrateInfo.TXPowerTrackingCallbackCnt++; - pDM_Odm->RFCalibrateInfo.bTXPowerTrackingInit = true; - - ThermalValue = (u8)PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH_A, c.ThermalRegAddr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ - if ( - !pDM_Odm->RFCalibrateInfo.TxPowerTrackControl || - pHalData->EEPROMThermalMeter == 0 || - pHalData->EEPROMThermalMeter == 0xFF - ) - return; - - /* 4 3. Initialize ThermalValues of RFCalibrateInfo */ - - /* 4 4. Calculate average thermal meter */ - - pDM_Odm->RFCalibrateInfo.ThermalValue_AVG[pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index] = ThermalValue; - pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index++; - if (pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index == c.AverageThermalNum) /* Average times = c.AverageThermalNum */ - pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index = 0; - - for (i = 0; i < c.AverageThermalNum; i++) { - if (pDM_Odm->RFCalibrateInfo.ThermalValue_AVG[i]) { - ThermalValue_AVG += pDM_Odm->RFCalibrateInfo.ThermalValue_AVG[i]; - ThermalValue_AVG_count++; - } - } - - /* Calculate Average ThermalValue after average enough times */ - if (ThermalValue_AVG_count) { - ThermalValue = (u8)(ThermalValue_AVG / ThermalValue_AVG_count); - } - - /* 4 5. Calculate delta, delta_LCK */ - /* delta" here is used to determine whether thermal value changes or not. */ - delta = - (ThermalValue > pDM_Odm->RFCalibrateInfo.ThermalValue) ? - (ThermalValue - pDM_Odm->RFCalibrateInfo.ThermalValue) : - (pDM_Odm->RFCalibrateInfo.ThermalValue - ThermalValue); - delta_LCK = - (ThermalValue > pDM_Odm->RFCalibrateInfo.ThermalValue_LCK) ? - (ThermalValue - pDM_Odm->RFCalibrateInfo.ThermalValue_LCK) : - (pDM_Odm->RFCalibrateInfo.ThermalValue_LCK - ThermalValue); - - /* 4 6. If necessary, do LCK. */ - /* Delta temperature is equal to or larger than 20 centigrade. */ - if (delta_LCK >= c.Threshold_IQK) { - pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = ThermalValue; - if (c.PHY_LCCalibrate) - (*c.PHY_LCCalibrate)(pDM_Odm); - } - - /* 3 7. If necessary, move the index of swing table to adjust Tx power. */ - if (delta > 0 && pDM_Odm->RFCalibrateInfo.TxPowerTrackControl) { - /* delta" here is used to record the absolute value of difference. */ - delta = - ThermalValue > pHalData->EEPROMThermalMeter ? - (ThermalValue - pHalData->EEPROMThermalMeter) : - (pHalData->EEPROMThermalMeter - ThermalValue); - - if (delta >= TXPWR_TRACK_TABLE_SIZE) - delta = TXPWR_TRACK_TABLE_SIZE - 1; - - /* 4 7.1 The Final Power Index = BaseIndex + PowerIndexOffset */ - if (ThermalValue > pHalData->EEPROMThermalMeter) { - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_A] = - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A]; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A] = - deltaSwingTableIdx_TUP_A[delta]; - - /* Record delta swing for mix mode power tracking */ - pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_A] = - deltaSwingTableIdx_TUP_A[delta]; - - if (c.RfPathCount > 1) { - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_B] = - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B]; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B] = - deltaSwingTableIdx_TUP_B[delta]; - - /* Record delta swing for mix mode power tracking */ - pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_B] = - deltaSwingTableIdx_TUP_B[delta]; - } - - } else { - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_A] = - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A]; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A] = - -1 * deltaSwingTableIdx_TDOWN_A[delta]; - - /* Record delta swing for mix mode power tracking */ - pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_A] = - -1 * deltaSwingTableIdx_TDOWN_A[delta]; - - if (c.RfPathCount > 1) { - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_B] = - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B]; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B] = - -1 * deltaSwingTableIdx_TDOWN_B[delta]; - - /* Record delta swing for mix mode power tracking */ - pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_B] = - -1 * deltaSwingTableIdx_TDOWN_B[delta]; - } - } - - for (p = RF_PATH_A; p < c.RfPathCount; p++) { - if ( - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] == - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] - ) /* If Thermal value changes but lookup table value still the same */ - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; - else - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p]; /* Power Index Diff between 2 times Power Tracking */ - - pDM_Odm->RFCalibrateInfo.OFDM_index[p] = - pDM_Odm->BbSwingIdxOfdmBase[p] + - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p]; - - pDM_Odm->RFCalibrateInfo.CCK_index = - pDM_Odm->BbSwingIdxCckBase + - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p]; - - pDM_Odm->BbSwingIdxCck = - pDM_Odm->RFCalibrateInfo.CCK_index; - - pDM_Odm->BbSwingIdxOfdm[p] = - pDM_Odm->RFCalibrateInfo.OFDM_index[p]; - - /* 4 7.1 Handle boundary conditions of index. */ - if (pDM_Odm->RFCalibrateInfo.OFDM_index[p] > c.SwingTableSize_OFDM - 1) - pDM_Odm->RFCalibrateInfo.OFDM_index[p] = c.SwingTableSize_OFDM - 1; - else if (pDM_Odm->RFCalibrateInfo.OFDM_index[p] < OFDM_min_index) - pDM_Odm->RFCalibrateInfo.OFDM_index[p] = OFDM_min_index; - } - if (pDM_Odm->RFCalibrateInfo.CCK_index > c.SwingTableSize_CCK - 1) - pDM_Odm->RFCalibrateInfo.CCK_index = c.SwingTableSize_CCK - 1; - /* else if (pDM_Odm->RFCalibrateInfo.CCK_index < 0) */ - /* pDM_Odm->RFCalibrateInfo.CCK_index = 0; */ - } else { - for (p = RF_PATH_A; p < c.RfPathCount; p++) - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; - } - - if ( - (pDM_Odm->RFCalibrateInfo.PowerIndexOffset[RF_PATH_A] != 0 || - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[RF_PATH_B] != 0) && - pDM_Odm->RFCalibrateInfo.TxPowerTrackControl - ) { - /* 4 7.2 Configure the Swing Table to adjust Tx Power. */ - - pDM_Odm->RFCalibrateInfo.bTxPowerChanged = true; /* Always true after Tx Power is adjusted by power tracking. */ - /* */ - /* 2012/04/23 MH According to Luke's suggestion, we can not write BB digital */ - /* to increase TX power. Otherwise, EVM will be bad. */ - /* */ - /* 2012/04/25 MH Add for tx power tracking to set tx power in tx agc for 88E. */ - - if (ThermalValue > pHalData->EEPROMThermalMeter) { - for (p = RF_PATH_A; p < c.RfPathCount; p++) - (*c.ODM_TxPwrTrackSetPwr)(pDM_Odm, MIX_MODE, p, 0); - } else { - for (p = RF_PATH_A; p < c.RfPathCount; p++) - (*c.ODM_TxPwrTrackSetPwr)(pDM_Odm, MIX_MODE, p, Indexforchannel); - } - - /* Record last time Power Tracking result as base. */ - pDM_Odm->BbSwingIdxCckBase = pDM_Odm->BbSwingIdxCck; - for (p = RF_PATH_A; p < c.RfPathCount; p++) - pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->BbSwingIdxOfdm[p]; - - /* Record last Power Tracking Thermal Value */ - pDM_Odm->RFCalibrateInfo.ThermalValue = ThermalValue; - } - - pDM_Odm->RFCalibrateInfo.TXPowercount = 0; -} diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf.h b/drivers/staging/rtl8723bs/hal/HalPhyRf.h deleted file mode 100644 index bd9430db968f..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalPhyRf.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - - #ifndef __HAL_PHY_RF_H__ - #define __HAL_PHY_RF_H__ - -enum pwrtrack_method { - BBSWING, - TXAGC, - MIX_MODE -}; - -typedef void (*FuncSetPwr)(struct dm_odm_t *, enum pwrtrack_method, u8, u8); -typedef void (*FuncLCK)(struct dm_odm_t *); -typedef void (*FuncSwing)(struct dm_odm_t *, u8 **, u8 **, u8 **, u8 **); - -struct txpwrtrack_cfg { - u8 SwingTableSize_CCK; - u8 SwingTableSize_OFDM; - u8 Threshold_IQK; - u8 AverageThermalNum; - u8 RfPathCount; - u32 ThermalRegAddr; - FuncSetPwr ODM_TxPwrTrackSetPwr; - FuncLCK PHY_LCCalibrate; - FuncSwing GetDeltaSwingTable; -}; - -void ConfigureTxpowerTrack(struct dm_odm_t *pDM_Odm, struct txpwrtrack_cfg *pConfig); - -void ODM_ClearTxPowerTrackingState(struct dm_odm_t *pDM_Odm); - -void ODM_TXPowerTrackingCallback_ThermalMeter(struct adapter *Adapter); - -#endif /* #ifndef __HAL_PHY_RF_H__ */ diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c b/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c deleted file mode 100644 index 6c5f56d5a1f4..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c +++ /dev/null @@ -1,1767 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/***************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include "odm_precomp.h" - -/* MACRO definition for pRFCalibrateInfo->TxIQC_8723B[0] */ -#define PATH_S0 1 /* RF_PATH_B */ -#define IDX_0xC94 0 -#define IDX_0xC80 1 -#define IDX_0xC14 0 -#define IDX_0xCA0 1 -#define KEY 0 -#define VAL 1 - -/* MACRO definition for pRFCalibrateInfo->TxIQC_8723B[1] */ -#define PATH_S1 0 /* RF_PATH_A */ -#define IDX_0xC4C 2 - -/*---------------------------Define Local Constant---------------------------*/ - -/* In the case that we fail to read TxPowerTrack.txt, we use the table for - * 88E as the default table. - */ -static u8 DeltaSwingTableIdx_2GA_N_8188E[] = { - 0, 0, 0, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, - 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11 -}; -static u8 DeltaSwingTableIdx_2GA_P_8188E[] = { - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, - 4, 4, 4, 5, 5, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9 -}; - -/* 3 ============================================================ */ -/* 3 Tx Power Tracking */ -/* 3 ============================================================ */ - -static void setIqkMatrix_8723B( - struct dm_odm_t *pDM_Odm, - u8 OFDM_index, - u8 RFPath, - s32 IqkResult_X, - s32 IqkResult_Y -) -{ - s32 ele_A = 0, ele_D, ele_C = 0, value32; - - if (OFDM_index >= OFDM_TABLE_SIZE) - OFDM_index = OFDM_TABLE_SIZE-1; - - ele_D = (OFDMSwingTable_New[OFDM_index] & 0xFFC00000)>>22; - - /* new element A = element D x X */ - if (IqkResult_X != 0) { - if ((IqkResult_X & 0x00000200) != 0) /* consider minus */ - IqkResult_X = IqkResult_X | 0xFFFFFC00; - ele_A = ((IqkResult_X * ele_D)>>8)&0x000003FF; - - /* new element C = element D x Y */ - if ((IqkResult_Y & 0x00000200) != 0) - IqkResult_Y = IqkResult_Y | 0xFFFFFC00; - ele_C = ((IqkResult_Y * ele_D)>>8)&0x000003FF; - - /* if (RFPath == RF_PATH_A) */ - switch (RFPath) { - case RF_PATH_A: - /* write new elements A, C, D to regC80 and regC94, - * element B is always 0 - */ - value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XATxIQImbalance, bMaskDWord, value32); - - value32 = (ele_C&0x000003C0)>>6; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XCTxAFE, bMaskH4Bits, value32); - - value32 = ((IqkResult_X * ele_D)>>7)&0x01; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(24), value32); - break; - case RF_PATH_B: - /* write new elements A, C, D to regC88 and regC9C, - * element B is always 0 - */ - value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XBTxIQImbalance, bMaskDWord, value32); - - value32 = (ele_C&0x000003C0)>>6; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XDTxAFE, bMaskH4Bits, value32); - - value32 = ((IqkResult_X * ele_D)>>7)&0x01; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(28), value32); - - break; - default: - break; - } - } else { - switch (RFPath) { - case RF_PATH_A: - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XATxIQImbalance, bMaskDWord, OFDMSwingTable_New[OFDM_index]); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XCTxAFE, bMaskH4Bits, 0x00); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(24), 0x00); - break; - - case RF_PATH_B: - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XBTxIQImbalance, bMaskDWord, OFDMSwingTable_New[OFDM_index]); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XDTxAFE, bMaskH4Bits, 0x00); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(28), 0x00); - break; - - default: - break; - } - } -} - -static void setCCKFilterCoefficient(struct dm_odm_t *pDM_Odm, u8 CCKSwingIndex) -{ - u8 (*swingtable)[8]; - - if (!pDM_Odm->RFCalibrateInfo.bCCKinCH14) - swingtable = CCKSwingTable_Ch1_Ch13_New; - else - swingtable = CCKSwingTable_Ch14_New; - - for (int i = 0; i < 8; i++) - rtw_write8(pDM_Odm->Adapter, 0xa22 + i, swingtable[CCKSwingIndex][i]); -} - -/*----------------------------------------------------------------------------- - * Function: odm_TxPwrTrackSetPwr88E() - * - * Overview: 88E change all channel tx power according to flag. - * OFDM & CCK are all different. - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - *When Who Remark - *04/23/2012 MHC Create Version 0. - * - *--------------------------------------------------------------------------- - */ -void ODM_TxPwrTrackSetPwr_8723B( - struct dm_odm_t *pDM_Odm, - enum pwrtrack_method Method, - u8 RFPath, - u8 ChannelMappedIndex -) -{ - struct adapter *Adapter = pDM_Odm->Adapter; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u8 PwrTrackingLimit_OFDM = 34; /* 0dB */ - u8 PwrTrackingLimit_CCK = 28; /* 2dB */ - u8 TxRate = 0xFF; - u8 Final_OFDM_Swing_Index = 0; - u8 Final_CCK_Swing_Index = 0; - - { - u16 rate = *(pDM_Odm->pForcedDataRate); - - if (!rate) { /* auto rate */ - if (pDM_Odm->TxRate != 0xFF) - TxRate = HwRateToMRate(pDM_Odm->TxRate); - } else /* force rate */ - TxRate = (u8)rate; - - } - - if (TxRate != 0xFF) { - /* 2 CCK */ - if ((TxRate >= MGN_1M) && (TxRate <= MGN_11M)) - PwrTrackingLimit_CCK = 28; /* 2dB */ - /* 2 OFDM */ - else if ((TxRate >= MGN_6M) && (TxRate <= MGN_48M)) - PwrTrackingLimit_OFDM = 36; /* 3dB */ - else if (TxRate == MGN_54M) - PwrTrackingLimit_OFDM = 34; /* 2dB */ - - /* 2 HT */ - else if ((TxRate >= MGN_MCS0) && (TxRate <= MGN_MCS2)) /* QPSK/BPSK */ - PwrTrackingLimit_OFDM = 38; /* 4dB */ - else if ((TxRate >= MGN_MCS3) && (TxRate <= MGN_MCS4)) /* 16QAM */ - PwrTrackingLimit_OFDM = 36; /* 3dB */ - else if ((TxRate >= MGN_MCS5) && (TxRate <= MGN_MCS7)) /* 64QAM */ - PwrTrackingLimit_OFDM = 34; /* 2dB */ - - else - PwrTrackingLimit_OFDM = pDM_Odm->DefaultOfdmIndex; /* Default OFDM index = 30 */ - } - - if (Method == TXAGC) { - pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = pDM_Odm->Absolute_OFDMSwingIdx[RFPath]; - - pDM_Odm->Modify_TxAGC_Flag_PathA = true; - pDM_Odm->Modify_TxAGC_Flag_PathA_CCK = true; - - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, CCK); - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, OFDM); - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, HT_MCS0_MCS7); - } else if (Method == BBSWING) { - Final_OFDM_Swing_Index = pDM_Odm->DefaultOfdmIndex + pDM_Odm->Absolute_OFDMSwingIdx[RFPath]; - Final_CCK_Swing_Index = pDM_Odm->DefaultCckIndex + pDM_Odm->Absolute_OFDMSwingIdx[RFPath]; - - /* Adjust BB swing by OFDM IQ matrix */ - if (Final_OFDM_Swing_Index >= PwrTrackingLimit_OFDM) - Final_OFDM_Swing_Index = PwrTrackingLimit_OFDM; - else if (Final_OFDM_Swing_Index <= 0) - Final_OFDM_Swing_Index = 0; - - if (Final_CCK_Swing_Index >= CCK_TABLE_SIZE) - Final_CCK_Swing_Index = CCK_TABLE_SIZE-1; - else if (pDM_Odm->BbSwingIdxCck <= 0) - Final_CCK_Swing_Index = 0; - - setIqkMatrix_8723B(pDM_Odm, Final_OFDM_Swing_Index, RFPath, - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][0], - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][1]); - - setCCKFilterCoefficient(pDM_Odm, Final_CCK_Swing_Index); - - } else if (Method == MIX_MODE) { - Final_OFDM_Swing_Index = pDM_Odm->DefaultOfdmIndex + pDM_Odm->Absolute_OFDMSwingIdx[RFPath]; - Final_CCK_Swing_Index = pDM_Odm->DefaultCckIndex + pDM_Odm->Absolute_OFDMSwingIdx[RFPath]; - - if (Final_OFDM_Swing_Index > PwrTrackingLimit_OFDM) { /* BBSwing higher then Limit */ - pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index - PwrTrackingLimit_OFDM; - - setIqkMatrix_8723B(pDM_Odm, PwrTrackingLimit_OFDM, RFPath, - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][0], - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][1]); - - pDM_Odm->Modify_TxAGC_Flag_PathA = true; - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, OFDM); - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, HT_MCS0_MCS7); - } else if (Final_OFDM_Swing_Index <= 0) { - pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index; - - setIqkMatrix_8723B(pDM_Odm, 0, RFPath, - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][0], - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][1]); - - pDM_Odm->Modify_TxAGC_Flag_PathA = true; - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, OFDM); - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, HT_MCS0_MCS7); - } else { - setIqkMatrix_8723B(pDM_Odm, Final_OFDM_Swing_Index, RFPath, - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][0], - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[ChannelMappedIndex][1]); - - if (pDM_Odm->Modify_TxAGC_Flag_PathA) { /* If TxAGC has changed, reset TxAGC again */ - pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = 0; - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, OFDM); - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, HT_MCS0_MCS7); - pDM_Odm->Modify_TxAGC_Flag_PathA = false; - } - } - - if (Final_CCK_Swing_Index > PwrTrackingLimit_CCK) { - pDM_Odm->Remnant_CCKSwingIdx = Final_CCK_Swing_Index - PwrTrackingLimit_CCK; - setCCKFilterCoefficient(pDM_Odm, PwrTrackingLimit_CCK); - pDM_Odm->Modify_TxAGC_Flag_PathA_CCK = true; - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, CCK); - } else if (Final_CCK_Swing_Index <= 0) { /* Lowest CCK Index = 0 */ - pDM_Odm->Remnant_CCKSwingIdx = Final_CCK_Swing_Index; - setCCKFilterCoefficient(pDM_Odm, 0); - pDM_Odm->Modify_TxAGC_Flag_PathA_CCK = true; - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, CCK); - } else { - setCCKFilterCoefficient(pDM_Odm, Final_CCK_Swing_Index); - - if (pDM_Odm->Modify_TxAGC_Flag_PathA_CCK) { /* If TxAGC has changed, reset TxAGC again */ - pDM_Odm->Remnant_CCKSwingIdx = 0; - PHY_SetTxPowerIndexByRateSection(Adapter, RFPath, pHalData->CurrentChannel, CCK); - pDM_Odm->Modify_TxAGC_Flag_PathA_CCK = false; - } - } - } else - return; /* This method is not supported. */ -} - -static void GetDeltaSwingTable_8723B( - struct dm_odm_t *pDM_Odm, - u8 **TemperatureUP_A, - u8 **TemperatureDOWN_A, - u8 **TemperatureUP_B, - u8 **TemperatureDOWN_B -) -{ - struct adapter *Adapter = pDM_Odm->Adapter; - struct odm_rf_cal_t *pRFCalibrateInfo = &pDM_Odm->RFCalibrateInfo; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u16 rate = *(pDM_Odm->pForcedDataRate); - u8 channel = pHalData->CurrentChannel; - - if (channel >= 1 && channel <= 14) { - if (IS_CCK_RATE(rate)) { - *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_P; - *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_N; - *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_P; - *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_N; - } else { - *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GA_P; - *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GA_N; - *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GB_P; - *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GB_N; - } - } else { - *TemperatureUP_A = (u8 *)DeltaSwingTableIdx_2GA_P_8188E; - *TemperatureDOWN_A = (u8 *)DeltaSwingTableIdx_2GA_N_8188E; - *TemperatureUP_B = (u8 *)DeltaSwingTableIdx_2GA_P_8188E; - *TemperatureDOWN_B = (u8 *)DeltaSwingTableIdx_2GA_N_8188E; - } -} - -void ConfigureTxpowerTrack_8723B(struct txpwrtrack_cfg *pConfig) -{ - pConfig->SwingTableSize_CCK = CCK_TABLE_SIZE; - pConfig->SwingTableSize_OFDM = OFDM_TABLE_SIZE; - pConfig->Threshold_IQK = IQK_THRESHOLD; - pConfig->AverageThermalNum = AVG_THERMAL_NUM_8723B; - pConfig->RfPathCount = MAX_PATH_NUM_8723B; - pConfig->ThermalRegAddr = RF_T_METER_8723B; - - pConfig->ODM_TxPwrTrackSetPwr = ODM_TxPwrTrackSetPwr_8723B; - pConfig->PHY_LCCalibrate = PHY_LCCalibrate_8723B; - pConfig->GetDeltaSwingTable = GetDeltaSwingTable_8723B; -} - -/* 1 7. IQK */ -#define MAX_TOLERANCE 5 - -/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ -static u8 phy_PathA_IQK_8723B( - struct adapter *padapter, bool configPathB, u8 RF_Path -) -{ - u32 regEAC, regE94, regE9C, tmp, Path_SEL_BB /*, regEA4*/; - u8 result = 0x00; - - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - /* Save RF Path */ - Path_SEL_BB = PHY_QueryBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* enable path A PA in TXIQK mode */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x18000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0003f); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xc7f87); - /* disable path B PA in TXIQK mode */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xed, bRFRegOffsetMask, 0x00020); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x43, bRFRegOffsetMask, 0x40ec1); */ - - /* 1 Tx IQK */ - /* IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK, bMaskDWord, 0x01007c00); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK, bMaskDWord, 0x01004800); - /* path-A IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x18008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_B, bMaskDWord, 0x38008c1c); -/* PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x8214010a); */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x821303ea); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x28110000); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_B, bMaskDWord, 0x82110000); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_B, bMaskDWord, 0x28110000); - - /* LO calibration setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Rsp, bMaskDWord, 0x00462911); - - /* enter IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* Ant switch */ - if (configPathB || (RF_Path == 0)) - /* wifi switch to S1 */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000000); - else - /* wifi switch to S0 */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); - - /* GNT_BT = 0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00000800); - - /* One shot, path A LOK & IQK */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); - - /* delay x ms */ - /* PlatformStallExecution(IQK_DELAY_TIME_8723B*1000); */ - mdelay(IQK_DELAY_TIME_8723B); - - /* restore Ant Path */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, Path_SEL_BB); - /* GNT_BT = 1 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00001800); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* Check failed */ - regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); - regE94 = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord); - regE9C = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord); - - /* Allen 20131125 */ - tmp = (regE9C & 0x03FF0000)>>16; - if ((tmp & 0x200) > 0) - tmp = 0x400 - tmp; - - if ( - !(regEAC & BIT(28)) && - (((regE94 & 0x03FF0000)>>16) != 0x142) && - (((regE9C & 0x03FF0000)>>16) != 0x42) && - (((regE94 & 0x03FF0000)>>16) < 0x110) && - (((regE94 & 0x03FF0000)>>16) > 0xf0) && - (tmp < 0xf) - ) - result |= 0x01; - else /* if Tx not OK, ignore Rx */ - return result; - - return result; -} - -/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ -static u8 phy_PathA_RxIQK8723B( - struct adapter *padapter, bool configPathB, u8 RF_Path -) -{ - u32 regEAC, regE94, regE9C, regEA4, u4tmp, tmp, Path_SEL_BB; - u8 result = 0x00; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - /* Save RF Path */ - Path_SEL_BB = PHY_QueryBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - /* 1 Get TXIMR setting */ - /* modify RXIQK mode table */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x18000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0001f); - /* LNA2 off, PA on for Dcut */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xf7fb7); -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x0); */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK, bMaskDWord, 0x01007c00); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK, bMaskDWord, 0x01004800); - - /* path-A IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x18008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - -/* PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82160c1f); */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82130ff0); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x28110000); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_B, bMaskDWord, 0x82110000); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_B, bMaskDWord, 0x28110000); - - /* LO calibration setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Rsp, bMaskDWord, 0x0046a911); - - /* enter IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* Ant switch */ - if (configPathB || (RF_Path == 0)) - /* wifi switch to S1 */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000000); - else - /* wifi switch to S0 */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); - - /* GNT_BT = 0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00000800); - - /* One shot, path A LOK & IQK */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); - - /* delay x ms */ - /* PlatformStallExecution(IQK_DELAY_TIME_8723B*1000); */ - mdelay(IQK_DELAY_TIME_8723B); - - /* restore Ant Path */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, Path_SEL_BB); - /* GNT_BT = 1 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00001800); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* Check failed */ - regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); - regE94 = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord); - regE9C = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord); - - /* Allen 20131125 */ - tmp = (regE9C & 0x03FF0000)>>16; - if ((tmp & 0x200) > 0) - tmp = 0x400 - tmp; - - if ( - !(regEAC & BIT(28)) && - (((regE94 & 0x03FF0000)>>16) != 0x142) && - (((regE9C & 0x03FF0000)>>16) != 0x42) && - (((regE94 & 0x03FF0000)>>16) < 0x110) && - (((regE94 & 0x03FF0000)>>16) > 0xf0) && - (tmp < 0xf) - ) - result |= 0x01; - else /* if Tx not OK, ignore Rx */ - return result; - - u4tmp = 0x80007C00 | (regE94&0x3FF0000) | ((regE9C&0x3FF0000) >> 16); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK, bMaskDWord, u4tmp); - - /* modify RXIQK mode table */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x18000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0001f); - /* LAN2 on, PA off for Dcut */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xf7d77); -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x0); */ - - /* PA, PAD setting */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xdf, bRFRegOffsetMask, 0xf80); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x55, bRFRegOffsetMask, 0x4021f); - - /* IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK, bMaskDWord, 0x01004800); - - /* path-A IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x18008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82110000); -/* PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x281604c2); */ - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x2813001f); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_B, bMaskDWord, 0x82110000); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_B, bMaskDWord, 0x28110000); - - /* LO calibration setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Rsp, bMaskDWord, 0x0046a8d1); - - /* enter IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* Ant switch */ - if (configPathB || (RF_Path == 0)) - /* wifi switch to S1 */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000000); - else - /* wifi switch to S0 */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); - - /* GNT_BT = 0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00000800); - - /* One shot, path A LOK & IQK */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); - - /* delay x ms */ - /* PlatformStallExecution(IQK_DELAY_TIME_8723B*1000); */ - mdelay(IQK_DELAY_TIME_8723B); - - /* restore Ant Path */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, Path_SEL_BB); - /* GNT_BT = 1 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00001800); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* Check failed */ - regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); - regEA4 = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_Before_IQK_A_2, bMaskDWord); - - /* PA/PAD controlled by 0x0 */ - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xdf, bRFRegOffsetMask, 0x780); - - /* Allen 20131125 */ - tmp = (regEAC & 0x03FF0000)>>16; - if ((tmp & 0x200) > 0) - tmp = 0x400 - tmp; - - if ( - !(regEAC & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ - (((regEA4 & 0x03FF0000)>>16) != 0x132) && - (((regEAC & 0x03FF0000)>>16) != 0x36) && - (((regEA4 & 0x03FF0000)>>16) < 0x110) && - (((regEA4 & 0x03FF0000)>>16) > 0xf0) && - (tmp < 0xf) - ) - result |= 0x02; - - return result; -} - -/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ -static u8 phy_PathB_IQK_8723B(struct adapter *padapter) -{ - u32 regEAC, regE94, regE9C, tmp, Path_SEL_BB/*, regEC4, regECC, Path_SEL_BB*/; - u8 result = 0x00; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - /* Save RF Path */ - Path_SEL_BB = PHY_QueryBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* in TXIQK mode */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x20000); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0003f); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xc7f87); */ - /* enable path B PA in TXIQK mode */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xed, 0x20, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x43, bRFRegOffsetMask, 0x30fc1); - - /* 1 Tx IQK */ - /* IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK, bMaskDWord, 0x01007c00); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK, bMaskDWord, 0x01004800); - /* path-A IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x18008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - -/* PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82140114); */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x821303ea); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x28110000); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_B, bMaskDWord, 0x82110000); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_B, bMaskDWord, 0x28110000); - - /* LO calibration setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Rsp, bMaskDWord, 0x00462911); - - /* enter IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* switch to path B */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, bRFRegOffsetMask, 0xeffe0); */ - - /* GNT_BT = 0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00000800); - - /* One shot, path B LOK & IQK */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); - - /* delay x ms */ - /* PlatformStallExecution(IQK_DELAY_TIME_88E*1000); */ - mdelay(IQK_DELAY_TIME_8723B); - - /* restore Ant Path */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, Path_SEL_BB); - /* GNT_BT = 1 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00001800); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* Check failed */ - regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); - regE94 = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord); - regE9C = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord); - - /* Allen 20131125 */ - tmp = (regE9C & 0x03FF0000)>>16; - if ((tmp & 0x200) > 0) - tmp = 0x400 - tmp; - - if ( - !(regEAC & BIT(28)) && - (((regE94 & 0x03FF0000)>>16) != 0x142) && - (((regE9C & 0x03FF0000)>>16) != 0x42) && - (((regE94 & 0x03FF0000)>>16) < 0x110) && - (((regE94 & 0x03FF0000)>>16) > 0xf0) && - (tmp < 0xf) - ) - result |= 0x01; - - return result; -} - -/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ -static u8 phy_PathB_RxIQK8723B(struct adapter *padapter, bool configPathB) -{ - u32 regE94, regE9C, regEA4, regEAC, u4tmp, tmp, Path_SEL_BB; - u8 result = 0x00; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - /* Save RF Path */ - Path_SEL_BB = PHY_QueryBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord); - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* switch to path B */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); - /* modify RXIQK mode table */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x18000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0001f); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xf7fb7); - /* open PA S1 & SMIXER */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xed, 0x20, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x43, bRFRegOffsetMask, 0x30fcd); - - /* IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK, bMaskDWord, 0x01007c00); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK, bMaskDWord, 0x01004800); - - /* path-B IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x18008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - -/* PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82160c1f); */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82130ff0); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x28110000); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_B, bMaskDWord, 0x82110000); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_B, bMaskDWord, 0x28110000); - - /* LO calibration setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Rsp, bMaskDWord, 0x0046a911); - - /* enter IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* switch to path B */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, bRFRegOffsetMask, 0xeffe0); */ - - /* GNT_BT = 0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00000800); - - /* One shot, path B TXIQK @ RXIQK */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); - - /* delay x ms */ - /* PlatformStallExecution(IQK_DELAY_TIME_88E*1000); */ - mdelay(IQK_DELAY_TIME_8723B); - - /* restore Ant Path */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, Path_SEL_BB); - /* GNT_BT = 1 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00001800); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* Check failed */ - regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); - regE94 = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord); - regE9C = PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord); - - /* Allen 20131125 */ - tmp = (regE9C & 0x03FF0000)>>16; - if ((tmp & 0x200) > 0) - tmp = 0x400 - tmp; - - if ( - !(regEAC & BIT(28)) && - (((regE94 & 0x03FF0000)>>16) != 0x142) && - (((regE9C & 0x03FF0000)>>16) != 0x42) && - (((regE94 & 0x03FF0000)>>16) < 0x110) && - (((regE94 & 0x03FF0000)>>16) > 0xf0) && - (tmp < 0xf) - ) - result |= 0x01; - else /* if Tx not OK, ignore Rx */ - return result; - - u4tmp = 0x80007C00 | (regE94&0x3FF0000) | ((regE9C&0x3FF0000) >> 16); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK, bMaskDWord, u4tmp); - - /* modify RXIQK mode table */ - /* 20121009, Kordan> RF Mode = 3 */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x18000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0001f); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xf7d77); -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x0); */ - - /* open PA S1 & close SMIXER */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xed, 0x20, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x43, bRFRegOffsetMask, 0x30ebd); - - /* PA, PAD setting */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xdf, bRFRegOffsetMask, 0xf80); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x56, bRFRegOffsetMask, 0x51000); */ - - /* IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK, bMaskDWord, 0x01004800); - - /* path-B IQK setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x18008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_B, bMaskDWord, 0x38008c1c); - - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_A, bMaskDWord, 0x82110000); -/* PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x281604c2); */ - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_A, bMaskDWord, 0x2813001f); - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_PI_B, bMaskDWord, 0x82110000); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_PI_B, bMaskDWord, 0x28110000); - - /* LO calibration setting */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Rsp, bMaskDWord, 0x0046a8d1); - - /* enter IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x808000); - - /* switch to path B */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, 0x00000280); -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, bRFRegOffsetMask, 0xeffe0); */ - - /* GNT_BT = 0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00000800); - - /* One shot, path B LOK & IQK */ - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); - PHY_SetBBReg(pDM_Odm->Adapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); - - /* delay x ms */ - /* PlatformStallExecution(IQK_DELAY_TIME_88E*1000); */ - mdelay(IQK_DELAY_TIME_8723B); - - /* restore Ant Path */ - PHY_SetBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskDWord, Path_SEL_BB); - /* GNT_BT = 1 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, 0x00001800); - - /* leave IQK mode */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - - /* Check failed */ - regEAC = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord); - regEA4 = PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_Before_IQK_A_2, bMaskDWord); - - /* PA/PAD controlled by 0x0 */ - /* leave IQK mode */ -/* PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, 0xffffff00, 0x00000000); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_B, 0xdf, bRFRegOffsetMask, 0x180); */ - - /* Allen 20131125 */ - tmp = (regEAC & 0x03FF0000)>>16; - if ((tmp & 0x200) > 0) - tmp = 0x400 - tmp; - - if ( - !(regEAC & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ - (((regEA4 & 0x03FF0000)>>16) != 0x132) && - (((regEAC & 0x03FF0000)>>16) != 0x36) && - (((regEA4 & 0x03FF0000)>>16) < 0x110) && - (((regEA4 & 0x03FF0000)>>16) > 0xf0) && - (tmp < 0xf) - ) - result |= 0x02; - - return result; -} - -static void _PHY_PathAFillIQKMatrix8723B( - struct adapter *padapter, - bool bIQKOK, - s32 result[][8], - u8 final_candidate, - bool bTxOnly -) -{ - u32 Oldval_0, X, TX0_A, reg; - s32 Y, TX0_C; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - struct odm_rf_cal_t *pRFCalibrateInfo = &pDM_Odm->RFCalibrateInfo; - - if (final_candidate == 0xFF) - return; - - else if (bIQKOK) { - Oldval_0 = (PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XATxIQImbalance, bMaskDWord) >> 22) & 0x3FF; - - X = result[final_candidate][0]; - if ((X & 0x00000200) != 0) - X = X | 0xFFFFFC00; - TX0_A = (X * Oldval_0) >> 8; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XATxIQImbalance, 0x3FF, TX0_A); - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(31), ((X*Oldval_0>>7) & 0x1)); - - Y = result[final_candidate][1]; - if ((Y & 0x00000200) != 0) - Y = Y | 0xFFFFFC00; - - /* 2 Tx IQC */ - TX0_C = (Y * Oldval_0) >> 8; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XCTxAFE, 0xF0000000, ((TX0_C&0x3C0)>>6)); - pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC94][KEY] = rOFDM0_XCTxAFE; - pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC94][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XCTxAFE, bMaskDWord); - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XATxIQImbalance, 0x003F0000, (TX0_C&0x3F)); - pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC80][KEY] = rOFDM0_XATxIQImbalance; - pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC80][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XATxIQImbalance, bMaskDWord); - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(29), ((Y*Oldval_0>>7) & 0x1)); - pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC4C][KEY] = rOFDM0_ECCAThreshold; - pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC4C][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskDWord); - - if (bTxOnly) { - /* <20130226, Kordan> Saving RxIQC, otherwise not initialized. */ - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xCA0][KEY] = rOFDM0_RxIQExtAnta; - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xCA0][VAL] = 0xfffffff & PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_RxIQExtAnta, bMaskDWord); - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xC14][KEY] = rOFDM0_XARxIQImbalance; -/* pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xC14][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XARxIQImbalance, bMaskDWord); */ - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xC14][VAL] = 0x40000100; - return; - } - - reg = result[final_candidate][2]; - - /* 2 Rx IQC */ - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XARxIQImbalance, 0x3FF, reg); - reg = result[final_candidate][3] & 0x3F; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XARxIQImbalance, 0xFC00, reg); - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xC14][KEY] = rOFDM0_XARxIQImbalance; - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xC14][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XARxIQImbalance, bMaskDWord); - - reg = (result[final_candidate][3] >> 6) & 0xF; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_RxIQExtAnta, 0xF0000000, reg); - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xCA0][KEY] = rOFDM0_RxIQExtAnta; - pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xCA0][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_RxIQExtAnta, bMaskDWord); - - } -} - -static void _PHY_PathBFillIQKMatrix8723B( - struct adapter *padapter, - bool bIQKOK, - s32 result[][8], - u8 final_candidate, - bool bTxOnly /* do Tx only */ -) -{ - u32 Oldval_1, X, TX1_A, reg; - s32 Y, TX1_C; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - struct odm_rf_cal_t *pRFCalibrateInfo = &pDM_Odm->RFCalibrateInfo; - - if (final_candidate == 0xFF) - return; - - else if (bIQKOK) { - Oldval_1 = (PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XBTxIQImbalance, bMaskDWord) >> 22) & 0x3FF; - - X = result[final_candidate][4]; - if ((X & 0x00000200) != 0) - X = X | 0xFFFFFC00; - TX1_A = (X * Oldval_1) >> 8; - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XBTxIQImbalance, 0x3FF, TX1_A); - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(27), ((X*Oldval_1>>7) & 0x1)); - - Y = result[final_candidate][5]; - if ((Y & 0x00000200) != 0) - Y = Y | 0xFFFFFC00; - - TX1_C = (Y * Oldval_1) >> 8; - - /* 2 Tx IQC */ - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XDTxAFE, 0xF0000000, ((TX1_C&0x3C0)>>6)); -/* pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC9C][KEY] = rOFDM0_XDTxAFE; */ -/* pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC9C][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XDTxAFE, bMaskDWord); */ - pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC94][KEY] = rOFDM0_XCTxAFE; - pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC94][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XDTxAFE, bMaskDWord); - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XBTxIQImbalance, 0x003F0000, (TX1_C&0x3F)); - pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC80][KEY] = rOFDM0_XATxIQImbalance; - pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC80][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XBTxIQImbalance, bMaskDWord); - - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, BIT(25), ((Y*Oldval_1>>7) & 0x1)); - pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC4C][KEY] = rOFDM0_ECCAThreshold; - pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC4C][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskDWord); - - if (bTxOnly) { - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xC14][KEY] = rOFDM0_XARxIQImbalance; -/* pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xC14][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XARxIQImbalance, bMaskDWord); */ - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xC14][VAL] = 0x40000100; - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xCA0][KEY] = rOFDM0_RxIQExtAnta; - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xCA0][VAL] = 0x0fffffff & PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_RxIQExtAnta, bMaskDWord); - return; - } - - /* 2 Rx IQC */ - reg = result[final_candidate][6]; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XBRxIQImbalance, 0x3FF, reg); - reg = result[final_candidate][7] & 0x3F; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_XBRxIQImbalance, 0xFC00, reg); - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xC14][KEY] = rOFDM0_XARxIQImbalance; - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xC14][VAL] = PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_XBRxIQImbalance, bMaskDWord); - - reg = (result[final_candidate][7] >> 6) & 0xF; -/* PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_AGCRSSITable, 0x0000F000, reg); */ - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xCA0][KEY] = rOFDM0_RxIQExtAnta; - pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xCA0][VAL] = (reg << 28)|(PHY_QueryBBReg(pDM_Odm->Adapter, rOFDM0_RxIQExtAnta, bMaskDWord)&0x0fffffff); - } -} - -/* */ -/* 2011/07/26 MH Add an API for testing IQK fail case. */ -/* */ -/* MP Already declare in odm.c */ - -void ODM_SetIQCbyRFpath(struct dm_odm_t *pDM_Odm, u32 RFpath) -{ - - struct odm_rf_cal_t *pRFCalibrateInfo = &pDM_Odm->RFCalibrateInfo; - u8 path; - - if ( - (pRFCalibrateInfo->TxIQC_8723B[PATH_S0][IDX_0xC80][VAL] != 0x0) && - (pRFCalibrateInfo->RxIQC_8723B[PATH_S0][IDX_0xC14][VAL] != 0x0) && - (pRFCalibrateInfo->TxIQC_8723B[PATH_S1][IDX_0xC80][VAL] != 0x0) && - (pRFCalibrateInfo->RxIQC_8723B[PATH_S1][IDX_0xC14][VAL] != 0x0) - ) { - if (RFpath) - path = PATH_S0; - else - path = PATH_S1; - - /* TX IQC */ - PHY_SetBBReg(pDM_Odm->Adapter, pRFCalibrateInfo->TxIQC_8723B[path][IDX_0xC94][KEY], bMaskDWord, pRFCalibrateInfo->TxIQC_8723B[path][IDX_0xC94][VAL]); - PHY_SetBBReg(pDM_Odm->Adapter, pRFCalibrateInfo->TxIQC_8723B[path][IDX_0xC80][KEY], bMaskDWord, pRFCalibrateInfo->TxIQC_8723B[path][IDX_0xC80][VAL]); - PHY_SetBBReg(pDM_Odm->Adapter, pRFCalibrateInfo->TxIQC_8723B[path][IDX_0xC4C][KEY], bMaskDWord, pRFCalibrateInfo->TxIQC_8723B[path][IDX_0xC4C][VAL]); - /* RX IQC */ - PHY_SetBBReg(pDM_Odm->Adapter, pRFCalibrateInfo->RxIQC_8723B[path][IDX_0xC14][KEY], bMaskDWord, pRFCalibrateInfo->RxIQC_8723B[path][IDX_0xC14][VAL]); - PHY_SetBBReg(pDM_Odm->Adapter, pRFCalibrateInfo->RxIQC_8723B[path][IDX_0xCA0][KEY], bMaskDWord, pRFCalibrateInfo->RxIQC_8723B[path][IDX_0xCA0][VAL]); - } -} - -static bool ODM_CheckPowerStatus(struct adapter *Adapter) -{ - return true; -} - -static void _PHY_SaveADDARegisters8723B( - struct adapter *padapter, - u32 *ADDAReg, - u32 *ADDABackup, - u32 RegisterNum -) -{ - u32 i; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - if (!ODM_CheckPowerStatus(padapter)) - return; - - for (i = 0 ; i < RegisterNum ; i++) { - ADDABackup[i] = PHY_QueryBBReg(pDM_Odm->Adapter, ADDAReg[i], bMaskDWord); - } -} - -static void _PHY_SaveMACRegisters8723B( - struct adapter *padapter, u32 *MACReg, u32 *MACBackup -) -{ - u32 i; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) { - MACBackup[i] = rtw_read8(pDM_Odm->Adapter, MACReg[i]); - } - MACBackup[i] = rtw_read32(pDM_Odm->Adapter, MACReg[i]); - -} - -static void _PHY_ReloadADDARegisters8723B( - struct adapter *padapter, - u32 *ADDAReg, - u32 *ADDABackup, - u32 RegiesterNum -) -{ - u32 i; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - for (i = 0 ; i < RegiesterNum; i++) { - PHY_SetBBReg(pDM_Odm->Adapter, ADDAReg[i], bMaskDWord, ADDABackup[i]); - } -} - -static void _PHY_ReloadMACRegisters8723B( - struct adapter *padapter, u32 *MACReg, u32 *MACBackup -) -{ - u32 i; - - for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) { - rtw_write8(padapter, MACReg[i], (u8)MACBackup[i]); - } - rtw_write32(padapter, MACReg[i], MACBackup[i]); -} - -static void _PHY_PathADDAOn8723B( - struct adapter *padapter, - u32 *ADDAReg, - bool is2T -) -{ - u32 pathOn; - u32 i; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - pathOn = 0x01c00014; - if (!is2T) { - pathOn = 0x01c00014; - PHY_SetBBReg(pDM_Odm->Adapter, ADDAReg[0], bMaskDWord, 0x01c00014); - } else { - PHY_SetBBReg(pDM_Odm->Adapter, ADDAReg[0], bMaskDWord, pathOn); - } - - for (i = 1 ; i < IQK_ADDA_REG_NUM ; i++) { - PHY_SetBBReg(pDM_Odm->Adapter, ADDAReg[i], bMaskDWord, pathOn); - } - -} - -static void _PHY_MACSettingCalibration8723B( - struct adapter *padapter, u32 *MACReg, u32 *MACBackup -) -{ - u32 i = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - rtw_write8(pDM_Odm->Adapter, MACReg[i], 0x3F); - - for (i = 1 ; i < (IQK_MAC_REG_NUM - 1); i++) { - rtw_write8(pDM_Odm->Adapter, MACReg[i], (u8)(MACBackup[i]&(~BIT(3)))); - } - rtw_write8(pDM_Odm->Adapter, MACReg[i], (u8)(MACBackup[i]&(~BIT(5)))); - -} - -static bool phy_SimularityCompare_8723B( - struct adapter *padapter, - s32 result[][8], - u8 c1, - u8 c2 -) -{ - u32 i, j, diff, SimularityBitMap, bound = 0; - u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */ - bool bResult = true; - s32 tmp1 = 0, tmp2 = 0; - - bound = 8; - SimularityBitMap = 0; - - for (i = 0; i < bound; i++) { - - if ((i == 1) || (i == 3) || (i == 5) || (i == 7)) { - if ((result[c1][i] & 0x00000200) != 0) - tmp1 = result[c1][i] | 0xFFFFFC00; - else - tmp1 = result[c1][i]; - - if ((result[c2][i] & 0x00000200) != 0) - tmp2 = result[c2][i] | 0xFFFFFC00; - else - tmp2 = result[c2][i]; - } else { - tmp1 = result[c1][i]; - tmp2 = result[c2][i]; - } - - diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1); - - if (diff > MAX_TOLERANCE) { - if ((i == 2 || i == 6) && !SimularityBitMap) { - if (result[c1][i]+result[c1][i+1] == 0) - final_candidate[(i/4)] = c2; - else if (result[c2][i]+result[c2][i+1] == 0) - final_candidate[(i/4)] = c1; - else - SimularityBitMap = SimularityBitMap|(1<odmpriv; - - u32 i; - u8 PathAOK, PathBOK; - u8 tmp0xc50 = (u8)PHY_QueryBBReg(pDM_Odm->Adapter, 0xC50, bMaskByte0); - u8 tmp0xc58 = (u8)PHY_QueryBBReg(pDM_Odm->Adapter, 0xC58, bMaskByte0); - u32 ADDA_REG[IQK_ADDA_REG_NUM] = { - rFPGA0_XCD_SwitchControl, - rBlue_Tooth, - rRx_Wait_CCA, - rTx_CCK_RFON, - rTx_CCK_BBON, - rTx_OFDM_RFON, - rTx_OFDM_BBON, - rTx_To_Rx, - rTx_To_Tx, - rRx_CCK, - rRx_OFDM, - rRx_Wait_RIFS, - rRx_TO_Rx, - rStandby, - rSleep, - rPMPD_ANAEN - }; - u32 IQK_MAC_REG[IQK_MAC_REG_NUM] = { - REG_TXPAUSE, - REG_BCN_CTRL, - REG_BCN_CTRL_1, - REG_GPIO_MUXCFG - }; - - /* since 92C & 92D have the different define in IQK_BB_REG */ - u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { - rOFDM0_TRxPathEnable, - rOFDM0_TRMuxPar, - rFPGA0_XCD_RFInterfaceSW, - rConfig_AntA, - rConfig_AntB, - rFPGA0_XAB_RFInterfaceSW, - rFPGA0_XA_RFInterfaceOE, - rFPGA0_XB_RFInterfaceOE, - rCCK0_AFESetting - }; - const u32 retryCount = 2; - - /* Note: IQ calibration must be performed after loading */ - /* PHY_REG.txt , and radio_a, radio_b.txt */ - - /* u32 bbvalue; */ - - if (t == 0) { - - /* Save ADDA parameters, turn Path A ADDA on */ - _PHY_SaveADDARegisters8723B(padapter, ADDA_REG, pDM_Odm->RFCalibrateInfo.ADDA_backup, IQK_ADDA_REG_NUM); - _PHY_SaveMACRegisters8723B(padapter, IQK_MAC_REG, pDM_Odm->RFCalibrateInfo.IQK_MAC_backup); - _PHY_SaveADDARegisters8723B(padapter, IQK_BB_REG_92C, pDM_Odm->RFCalibrateInfo.IQK_BB_backup, IQK_BB_REG_NUM); - } - - _PHY_PathADDAOn8723B(padapter, ADDA_REG, is2T); - -/* no serial mode */ - - /* save RF path for 8723B */ -/* Path_SEL_BB = PHY_QueryBBReg(pDM_Odm->Adapter, 0x948, bMaskDWord); */ -/* Path_SEL_RF = PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, 0xfffff); */ - - /* MAC settings */ - _PHY_MACSettingCalibration8723B(padapter, IQK_MAC_REG, pDM_Odm->RFCalibrateInfo.IQK_MAC_backup); - - /* BB setting */ - /* PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_RFMOD, BIT24, 0x00); */ - PHY_SetBBReg(pDM_Odm->Adapter, rCCK0_AFESetting, 0x0f000000, 0xf); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_TRxPathEnable, bMaskDWord, 0x03a05600); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_TRMuxPar, bMaskDWord, 0x000800e4); - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_XCD_RFInterfaceSW, bMaskDWord, 0x22204000); - -/* PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_XAB_RFInterfaceSW, BIT10, 0x01); */ -/* PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_XAB_RFInterfaceSW, BIT26, 0x01); */ -/* PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_XA_RFInterfaceOE, BIT10, 0x00); */ -/* PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_XB_RFInterfaceOE, BIT10, 0x00); */ - -/* RX IQ calibration setting for 8723B D cut large current issue when leaving IPS */ - - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x30000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0001f); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xf7fb7); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xed, 0x20, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x43, bRFRegOffsetMask, 0x60fbd); - -/* path A TX IQK */ - for (i = 0 ; i < retryCount ; i++) { - PathAOK = phy_PathA_IQK_8723B(padapter, is2T, RF_Path); -/* if (PathAOK == 0x03) { */ - if (PathAOK == 0x01) { - /* Path A Tx IQK Success */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - pDM_Odm->RFCalibrateInfo.TxLOK[RF_PATH_A] = PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x8, bRFRegOffsetMask); - - result[t][0] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, - bMaskDWord) & 0x3FF0000) >> 16; - result[t][1] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, - bMaskDWord) & 0x3FF0000) >> 16; - break; - } - } - -/* path A RXIQK */ - for (i = 0 ; i < retryCount ; i++) { - PathAOK = phy_PathA_RxIQK8723B(padapter, is2T, RF_Path); - if (PathAOK == 0x03) { -/* result[t][0] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord)&0x3FF0000)>>16; */ -/* result[t][1] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord)&0x3FF0000)>>16; */ - result[t][2] = (PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_Before_IQK_A_2, bMaskDWord)&0x3FF0000)>>16; - result[t][3] = (PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord)&0x3FF0000)>>16; - break; - } - } - -/* path B IQK */ - if (is2T) { - - /* path B TX IQK */ - for (i = 0 ; i < retryCount ; i++) { - PathBOK = phy_PathB_IQK_8723B(padapter); - if (PathBOK == 0x01) { - /* Path B Tx IQK Success */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0x000000); - pDM_Odm->RFCalibrateInfo.TxLOK[RF_PATH_B] = PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH_B, 0x8, bRFRegOffsetMask); - - result[t][4] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord)&0x3FF0000)>>16; - result[t][5] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord)&0x3FF0000)>>16; - break; - } - } - -/* path B RX IQK */ - for (i = 0 ; i < retryCount ; i++) { - PathBOK = phy_PathB_RxIQK8723B(padapter, is2T); - if (PathBOK == 0x03) { -/* result[t][0] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_Before_IQK_A, bMaskDWord)&0x3FF0000)>>16; */ -/* result[t][1] = (PHY_QueryBBReg(pDM_Odm->Adapter, rTx_Power_After_IQK_A, bMaskDWord)&0x3FF0000)>>16; */ - result[t][6] = (PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_Before_IQK_A_2, bMaskDWord)&0x3FF0000)>>16; - result[t][7] = (PHY_QueryBBReg(pDM_Odm->Adapter, rRx_Power_After_IQK_A_2, bMaskDWord)&0x3FF0000)>>16; - break; - } - } - -/* Allen end */ - } - - /* Back to BB mode, load original value */ - PHY_SetBBReg(pDM_Odm->Adapter, rFPGA0_IQK, bMaskH3Bytes, 0); - - if (t != 0) { - /* Reload ADDA power saving parameters */ - _PHY_ReloadADDARegisters8723B(padapter, ADDA_REG, pDM_Odm->RFCalibrateInfo.ADDA_backup, IQK_ADDA_REG_NUM); - - /* Reload MAC parameters */ - _PHY_ReloadMACRegisters8723B(padapter, IQK_MAC_REG, pDM_Odm->RFCalibrateInfo.IQK_MAC_backup); - - _PHY_ReloadADDARegisters8723B(padapter, IQK_BB_REG_92C, pDM_Odm->RFCalibrateInfo.IQK_BB_backup, IQK_BB_REG_NUM); - - /* Reload RF path */ -/* PHY_SetBBReg(pDM_Odm->Adapter, 0x948, bMaskDWord, Path_SEL_BB); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, 0xfffff, Path_SEL_RF); */ - - /* Allen initial gain 0xc50 */ - /* Restore RX initial gain */ - PHY_SetBBReg(pDM_Odm->Adapter, 0xc50, bMaskByte0, 0x50); - PHY_SetBBReg(pDM_Odm->Adapter, 0xc50, bMaskByte0, tmp0xc50); - if (is2T) { - PHY_SetBBReg(pDM_Odm->Adapter, 0xc58, bMaskByte0, 0x50); - PHY_SetBBReg(pDM_Odm->Adapter, 0xc58, bMaskByte0, tmp0xc58); - } - - /* load 0xe30 IQC default value */ - PHY_SetBBReg(pDM_Odm->Adapter, rTx_IQK_Tone_A, bMaskDWord, 0x01008c00); - PHY_SetBBReg(pDM_Odm->Adapter, rRx_IQK_Tone_A, bMaskDWord, 0x01008c00); - - } - -} - -static void phy_LCCalibrate_8723B(struct dm_odm_t *pDM_Odm, bool is2T) -{ - u8 tmpReg; - u32 RF_Amode = 0, RF_Bmode = 0, LC_Cal; - struct adapter *padapter = pDM_Odm->Adapter; - - /* Check continuous TX and Packet TX */ - tmpReg = rtw_read8(pDM_Odm->Adapter, 0xd03); - - if ((tmpReg&0x70) != 0) /* Deal with contisuous TX case */ - rtw_write8(pDM_Odm->Adapter, 0xd03, tmpReg&0x8F); /* disable all continuous TX */ - else /* Deal with Packet TX case */ - rtw_write8(pDM_Odm->Adapter, REG_TXPAUSE, 0xFF); /* block all queues */ - - if ((tmpReg&0x70) != 0) { - /* 1. Read original RF mode */ - /* Path-A */ - RF_Amode = PHY_QueryRFReg(padapter, RF_PATH_A, RF_AC, bMask12Bits); - - /* Path-B */ - if (is2T) - RF_Bmode = PHY_QueryRFReg(padapter, RF_PATH_B, RF_AC, bMask12Bits); - - /* 2. Set RF mode = standby mode */ - /* Path-A */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_AC, bMask12Bits, (RF_Amode&0x8FFFF)|0x10000); - - /* Path-B */ - if (is2T) - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_B, RF_AC, bMask12Bits, (RF_Bmode&0x8FFFF)|0x10000); - } - - /* 3. Read RF reg18 */ - LC_Cal = PHY_QueryRFReg(padapter, RF_PATH_A, RF_CHNLBW, bMask12Bits); - - /* 4. Set LC calibration begin bit15 */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xB0, bRFRegOffsetMask, 0xDFBE0); /* LDO ON */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_CHNLBW, bMask12Bits, LC_Cal|0x08000); - - mdelay(100); - - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xB0, bRFRegOffsetMask, 0xDFFE0); /* LDO OFF */ - - /* Channel 10 LC calibration issue for 8723bs with 26M xtal */ - if (pDM_Odm->SupportInterface == ODM_ITRF_SDIO && pDM_Odm->PackageType >= 0x2) { - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_CHNLBW, bMask12Bits, LC_Cal); - } - - /* Restore original situation */ - if ((tmpReg&0x70) != 0) { /* Deal with contisuous TX case */ - /* Path-A */ - rtw_write8(pDM_Odm->Adapter, 0xd03, tmpReg); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_AC, bMask12Bits, RF_Amode); - - /* Path-B */ - if (is2T) - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_B, RF_AC, bMask12Bits, RF_Bmode); - } else /* Deal with Packet TX case */ - rtw_write8(pDM_Odm->Adapter, REG_TXPAUSE, 0x00); -} - -/* IQK version:V2.5 20140123 */ -/* IQK is controlled by Is2ant, RF path */ -void PHY_IQCalibrate_8723B( - struct adapter *padapter, - bool bReCovery, - bool bRestore, - bool Is2ant, /* false:1ant, true:2-ant */ - u8 RF_Path /* 0:S1, 1:S0 */ -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - s32 result[4][8]; /* last is final result */ - u8 i, final_candidate; - bool bPathAOK, bPathBOK; - s32 RegE94, RegE9C, RegEA4, RegEB4, RegEBC, RegEC4, RegTmp = 0; - bool is12simular, is13simular, is23simular; - bool bSingleTone = false, bCarrierSuppression = false; - u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { - rOFDM0_XARxIQImbalance, - rOFDM0_XBRxIQImbalance, - rOFDM0_ECCAThreshold, - rOFDM0_AGCRSSITable, - rOFDM0_XATxIQImbalance, - rOFDM0_XBTxIQImbalance, - rOFDM0_XCTxAFE, - rOFDM0_XDTxAFE, - rOFDM0_RxIQExtAnta - }; -/* u32 Path_SEL_BB = 0; */ - u32 GNT_BT_default; - - if (!ODM_CheckPowerStatus(padapter)) - return; - - if (!(pDM_Odm->SupportAbility & ODM_RF_CALIBRATION)) - return; - - /* 20120213 Turn on when continuous Tx to pass lab testing. (required by Edlu) */ - if (bSingleTone || bCarrierSuppression) - return; - - if (pDM_Odm->RFCalibrateInfo.bIQKInProgress) - return; - - pDM_Odm->RFCalibrateInfo.bIQKInProgress = true; - - if (bRestore) { - u32 offset, data; - u8 path, bResult = SUCCESS; - struct odm_rf_cal_t *pRFCalibrateInfo = &pDM_Odm->RFCalibrateInfo; - - path = (PHY_QueryBBReg(pDM_Odm->Adapter, rS0S1_PathSwitch, bMaskByte0) == 0x00) ? RF_PATH_A : RF_PATH_B; - - /* Restore TX IQK */ - for (i = 0; i < 3; ++i) { - offset = pRFCalibrateInfo->TxIQC_8723B[path][i][0]; - data = pRFCalibrateInfo->TxIQC_8723B[path][i][1]; - if ((offset == 0) || (data == 0)) { - bResult = FAIL; - break; - } - PHY_SetBBReg(pDM_Odm->Adapter, offset, bMaskDWord, data); - } - - /* Restore RX IQK */ - for (i = 0; i < 2; ++i) { - offset = pRFCalibrateInfo->RxIQC_8723B[path][i][0]; - data = pRFCalibrateInfo->RxIQC_8723B[path][i][1]; - if ((offset == 0) || (data == 0)) { - bResult = FAIL; - break; - } - PHY_SetBBReg(pDM_Odm->Adapter, offset, bMaskDWord, data); - } - - if (pDM_Odm->RFCalibrateInfo.TxLOK[RF_PATH_A] == 0) { - bResult = FAIL; - } else { - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXM_IDAC, bRFRegOffsetMask, pDM_Odm->RFCalibrateInfo.TxLOK[RF_PATH_A]); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_B, RF_TXM_IDAC, bRFRegOffsetMask, pDM_Odm->RFCalibrateInfo.TxLOK[RF_PATH_B]); - } - - if (bResult == SUCCESS) - return; - } - - if (bReCovery) { - _PHY_ReloadADDARegisters8723B(padapter, IQK_BB_REG_92C, pDM_Odm->RFCalibrateInfo.IQK_BB_backup_recover, 9); - return; - } - - /* save default GNT_BT */ - GNT_BT_default = PHY_QueryBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord); - /* Save RF Path */ -/* Path_SEL_BB = PHY_QueryBBReg(pDM_Odm->Adapter, 0x948, bMaskDWord); */ -/* Path_SEL_RF = PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, 0xfffff); */ - - /* set GNT_BT = 0, pause BT traffic */ -/* PHY_SetBBReg(pDM_Odm->Adapter, 0x764, BIT12, 0x0); */ -/* PHY_SetBBReg(pDM_Odm->Adapter, 0x764, BIT11, 0x1); */ - - for (i = 0; i < 8; i++) { - result[0][i] = 0; - result[1][i] = 0; - result[2][i] = 0; - result[3][i] = 0; - } - - final_candidate = 0xff; - bPathAOK = false; - bPathBOK = false; - is12simular = false; - is23simular = false; - is13simular = false; - - for (i = 0; i < 3; i++) { - phy_IQCalibrate_8723B(padapter, result, i, Is2ant, RF_Path); - - if (i == 1) { - is12simular = phy_SimularityCompare_8723B(padapter, result, 0, 1); - if (is12simular) { - final_candidate = 0; - break; - } - } - - if (i == 2) { - is13simular = phy_SimularityCompare_8723B(padapter, result, 0, 2); - if (is13simular) { - final_candidate = 0; - - break; - } - - is23simular = phy_SimularityCompare_8723B(padapter, result, 1, 2); - if (is23simular) { - final_candidate = 1; - } else { - for (i = 0; i < 8; i++) - RegTmp += result[3][i]; - - if (RegTmp != 0) - final_candidate = 3; - else - final_candidate = 0xFF; - } - } - } - - for (i = 0; i < 4; i++) { - RegE94 = result[i][0]; - RegE9C = result[i][1]; - RegEA4 = result[i][2]; - RegEB4 = result[i][4]; - RegEBC = result[i][5]; - RegEC4 = result[i][6]; - } - - if (final_candidate != 0xff) { - pDM_Odm->RFCalibrateInfo.RegE94 = RegE94 = result[final_candidate][0]; - pDM_Odm->RFCalibrateInfo.RegE9C = RegE9C = result[final_candidate][1]; - RegEA4 = result[final_candidate][2]; - pDM_Odm->RFCalibrateInfo.RegEB4 = RegEB4 = result[final_candidate][4]; - pDM_Odm->RFCalibrateInfo.RegEBC = RegEBC = result[final_candidate][5]; - RegEC4 = result[final_candidate][6]; - bPathAOK = bPathBOK = true; - } else { - pDM_Odm->RFCalibrateInfo.RegE94 = pDM_Odm->RFCalibrateInfo.RegEB4 = 0x100; /* X default value */ - pDM_Odm->RFCalibrateInfo.RegE9C = pDM_Odm->RFCalibrateInfo.RegEBC = 0x0; /* Y default value */ - } - - { - if (RegE94 != 0) - _PHY_PathAFillIQKMatrix8723B(padapter, bPathAOK, result, final_candidate, (RegEA4 == 0)); - } - { - if (RegEB4 != 0) - _PHY_PathBFillIQKMatrix8723B(padapter, bPathBOK, result, final_candidate, (RegEC4 == 0)); - } - -/* To Fix BSOD when final_candidate is 0xff */ -/* by sherry 20120321 */ - if (final_candidate < 4) { - for (i = 0; i < IQK_MATRIX_REG_NUM; i++) - pDM_Odm->RFCalibrateInfo.iqk_matrix_regs_setting_value[0][i] = result[final_candidate][i]; - } - - _PHY_SaveADDARegisters8723B(padapter, IQK_BB_REG_92C, pDM_Odm->RFCalibrateInfo.IQK_BB_backup_recover, 9); - - /* restore GNT_BT */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x764, bMaskDWord, GNT_BT_default); - /* Restore RF Path */ -/* PHY_SetBBReg(pDM_Odm->Adapter, 0x948, bMaskDWord, Path_SEL_BB); */ -/* PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xb0, 0xfffff, Path_SEL_RF); */ - - /* Resotr RX mode table parameter */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_RCK_OS, bRFRegOffsetMask, 0x18000); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G1, bRFRegOffsetMask, 0x0001f); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_TXPA_G2, bRFRegOffsetMask, 0xe6177); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0xed, 0x20, 0x1); - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, 0x43, bRFRegOffsetMask, 0x300bd); - - /* set GNT_BT = HW control */ -/* PHY_SetBBReg(pDM_Odm->Adapter, 0x764, BIT12, 0x0); */ -/* PHY_SetBBReg(pDM_Odm->Adapter, 0x764, BIT11, 0x0); */ - - if (Is2ant) { - if (RF_Path == 0x0) /* S1 */ - ODM_SetIQCbyRFpath(pDM_Odm, 0); - else /* S0 */ - ODM_SetIQCbyRFpath(pDM_Odm, 1); - } - - pDM_Odm->RFCalibrateInfo.bIQKInProgress = false; -} - -void PHY_LCCalibrate_8723B(struct dm_odm_t *pDM_Odm) -{ - bool bSingleTone = false, bCarrierSuppression = false; - u32 timeout = 2000, timecount = 0; - - if (!(pDM_Odm->SupportAbility & ODM_RF_CALIBRATION)) - return; - - /* 20120213 Turn on when continuous Tx to pass lab testing. (required by Edlu) */ - if (bSingleTone || bCarrierSuppression) - return; - - while (*(pDM_Odm->pbScanInProcess) && timecount < timeout) { - mdelay(50); - timecount += 50; - } - - pDM_Odm->RFCalibrateInfo.bLCKInProgress = true; - - phy_LCCalibrate_8723B(pDM_Odm, false); - - pDM_Odm->RFCalibrateInfo.bLCKInProgress = false; -} diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.h b/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.h deleted file mode 100644 index 14b328378b8b..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.h +++ /dev/null @@ -1,66 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __HAL_PHY_RF_8723B_H__ -#define __HAL_PHY_RF_8723B_H__ - -/*--------------------------Define Parameters-------------------------------*/ -#define IQK_DELAY_TIME_8723B 20 /* ms */ -#define IQK_DEFERRED_TIME_8723B 4 -#define index_mapping_NUM_8723B 15 -#define AVG_THERMAL_NUM_8723B 4 -#define RF_T_METER_8723B 0x42 /* */ - -void ConfigureTxpowerTrack_8723B(struct txpwrtrack_cfg *pConfig); - -void ODM_TxPwrTrackSetPwr_8723B( - struct dm_odm_t *pDM_Odm, - enum pwrtrack_method Method, - u8 RFPath, - u8 ChannelMappedIndex -); - -/* 1 7. IQK */ -void PHY_IQCalibrate_8723B( - struct adapter *Adapter, - bool bReCovery, - bool bRestore, - bool Is2ant, - u8 RF_Path -); - -void ODM_SetIQCbyRFpath(struct dm_odm_t *pDM_Odm, u32 RFpath); - -/* */ -/* LC calibrate */ -/* */ -void PHY_LCCalibrate_8723B(struct dm_odm_t *pDM_Odm); - -/* */ -/* AP calibrate */ -/* */ -void PHY_DigitalPredistortion_8723B(struct adapter *padapter); - -void _PHY_SaveADDARegisters_8723B( - struct adapter *padapter, - u32 *ADDAReg, - u32 *ADDABackup, - u32 RegisterNum -); - -void _PHY_PathADDAOn_8723B( - struct adapter *padapter, - u32 *ADDAReg, - bool isPathAOn, - bool is2T -); - -void _PHY_MACSettingCalibration_8723B( - struct adapter *padapter, u32 *MACReg, u32 *MACBackup -); - -#endif /* #ifndef __HAL_PHY_RF_8188E_H__ */ diff --git a/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c b/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c deleted file mode 100644 index c254e3481cc2..000000000000 --- a/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c +++ /dev/null @@ -1,144 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* - * Copyright (c) Realtek Semiconductor Corp. All rights reserved. - * - * Module Name: - * HalPwrSeqCmd.c - * - * Abstract: - * Implement HW Power sequence configuration CMD handling routine for Realtek devices. - * - * Major Change History: - * When Who What - * ---------- --------------- ------------------------------- - * 2011-10-26 Lucas Modify to be compatible with SD4-CE driver. - * 2011-07-07 Roger Create. - * - */ -#include -#include - -/* */ -/* Description: */ -/* This routine deal with the Power Configuration CMDs parsing for RTL8723/RTL8188E Series IC. */ -/* */ -/* Assumption: */ -/* We should follow specific format which was released from HW SD. */ -/* */ -/* 2011.07.07, added by Roger. */ -/* */ -u8 HalPwrSeqCmdParsing( - struct adapter *padapter, - u8 CutVersion, - u8 FabVersion, - u8 InterfaceType, - struct wlan_pwr_cfg PwrSeqCmd[] -) -{ - struct wlan_pwr_cfg PwrCfgCmd; - u8 bPollingBit = false; - u32 AryIdx = 0; - u8 value = 0; - u32 offset = 0; - u32 pollingCount = 0; /* polling autoload done. */ - u32 maxPollingCnt = 5000; - - do { - PwrCfgCmd = PwrSeqCmd[AryIdx]; - - /* 2 Only Handle the command whose FAB, CUT, and Interface are matched */ - if ( - (GET_PWR_CFG_FAB_MASK(PwrCfgCmd) & FabVersion) && - (GET_PWR_CFG_CUT_MASK(PwrCfgCmd) & CutVersion) && - (GET_PWR_CFG_INTF_MASK(PwrCfgCmd) & InterfaceType) - ) { - switch (GET_PWR_CFG_CMD(PwrCfgCmd)) { - case PWR_CMD_READ: - break; - - case PWR_CMD_WRITE: - offset = GET_PWR_CFG_OFFSET(PwrCfgCmd); - - /* */ - /* We should deal with interface specific address mapping for some interfaces, e.g., SDIO interface */ - /* 2011.07.07. */ - /* */ - if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO) { - /* Read Back SDIO Local value */ - value = SdioLocalCmd52Read1Byte(padapter, offset); - - value &= ~(GET_PWR_CFG_MASK(PwrCfgCmd)); - value |= ( - GET_PWR_CFG_VALUE(PwrCfgCmd) & - GET_PWR_CFG_MASK(PwrCfgCmd) - ); - - /* Write Back SDIO Local value */ - SdioLocalCmd52Write1Byte(padapter, offset, value); - } else { - /* Read the value from system register */ - value = rtw_read8(padapter, offset); - - value &= (~(GET_PWR_CFG_MASK(PwrCfgCmd))); - value |= ( - GET_PWR_CFG_VALUE(PwrCfgCmd) - & GET_PWR_CFG_MASK(PwrCfgCmd) - ); - - /* Write the value back to system register */ - rtw_write8(padapter, offset, value); - } - break; - - case PWR_CMD_POLLING: - - bPollingBit = false; - offset = GET_PWR_CFG_OFFSET(PwrCfgCmd); - do { - if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO) - value = SdioLocalCmd52Read1Byte(padapter, offset); - else - value = rtw_read8(padapter, offset); - - value = value & GET_PWR_CFG_MASK(PwrCfgCmd); - if ( - value == (GET_PWR_CFG_VALUE(PwrCfgCmd) & - GET_PWR_CFG_MASK(PwrCfgCmd)) - ) - bPollingBit = true; - else - udelay(10); - - if (pollingCount++ > maxPollingCnt) - return false; - - } while (!bPollingBit); - - break; - - case PWR_CMD_DELAY: - if (GET_PWR_CFG_VALUE(PwrCfgCmd) == PWRSEQ_DELAY_US) - udelay(GET_PWR_CFG_OFFSET(PwrCfgCmd)); - else - udelay(GET_PWR_CFG_OFFSET(PwrCfgCmd) * 1000); - break; - - case PWR_CMD_END: - /* When this command is parsed, end the process */ - return true; - - default: - break; - } - } - - AryIdx++;/* Add Array Index */ - } while (1); - - return true; -} diff --git a/drivers/staging/rtl8723bs/hal/Mp_Precomp.h b/drivers/staging/rtl8723bs/hal/Mp_Precomp.h deleted file mode 100644 index f08823a8dd7b..000000000000 --- a/drivers/staging/rtl8723bs/hal/Mp_Precomp.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __MP_PRECOMP_H__ -#define __MP_PRECOMP_H__ - -#include -#include - -#define BT_TMP_BUF_SIZE 100 - -#ifdef bEnable -#undef bEnable -#endif - -#include "HalBtcOutSrc.h" -#include "HalBtc8723b1Ant.h" -#include "HalBtc8723b2Ant.h" - -#endif /* __MP_PRECOMP_H__ */ diff --git a/drivers/staging/rtl8723bs/hal/hal_btcoex.c b/drivers/staging/rtl8723bs/hal/hal_btcoex.c deleted file mode 100644 index 61cdc27a64ac..000000000000 --- a/drivers/staging/rtl8723bs/hal/hal_btcoex.c +++ /dev/null @@ -1,1303 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include - -/* Global variables */ - -struct btc_coexist GLBtCoexist; -static u8 GLBtcWiFiInScanState; -static u8 GLBtcWiFiInIQKState; - -/* */ -/* Debug related function */ -/* */ -static u8 halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist *pBtCoexist) -{ - if (!pBtCoexist->bBinded || !pBtCoexist->Adapter) - return false; - - return true; -} - -static void halbtcoutsrc_LeaveLps(struct btc_coexist *pBtCoexist) -{ - struct adapter *padapter; - - padapter = pBtCoexist->Adapter; - - pBtCoexist->btInfo.bBtCtrlLps = true; - pBtCoexist->btInfo.bBtLpsOn = false; - - rtw_btcoex_lps_leave(padapter); -} - -static void halbtcoutsrc_EnterLps(struct btc_coexist *pBtCoexist) -{ - struct adapter *padapter; - - padapter = pBtCoexist->Adapter; - - pBtCoexist->btInfo.bBtCtrlLps = true; - pBtCoexist->btInfo.bBtLpsOn = true; - - rtw_btcoex_lps_enter(padapter); -} - -static void halbtcoutsrc_NormalLps(struct btc_coexist *pBtCoexist) -{ - struct adapter *padapter; - - padapter = pBtCoexist->Adapter; - - if (pBtCoexist->btInfo.bBtCtrlLps) { - pBtCoexist->btInfo.bBtLpsOn = false; - rtw_btcoex_lps_leave(padapter); - pBtCoexist->btInfo.bBtCtrlLps = false; - - /* recover the LPS state to the original */ - } -} - -/* - * Constraint: - * 1. this function will request pwrctrl->lock - */ -static void halbtcoutsrc_LeaveLowPower(struct btc_coexist *pBtCoexist) -{ - struct adapter *padapter; - s32 ready; - unsigned long stime; - unsigned long utime; - u32 timeout; /* unit: ms */ - - padapter = pBtCoexist->Adapter; - ready = _FAIL; -#ifdef LPS_RPWM_WAIT_MS - timeout = LPS_RPWM_WAIT_MS; -#else /* !LPS_RPWM_WAIT_MS */ - timeout = 30; -#endif /* !LPS_RPWM_WAIT_MS */ - - stime = jiffies; - do { - ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE); - if (ready == _SUCCESS) - break; - - utime = jiffies_to_msecs(jiffies - stime); - if (utime > timeout) - break; - - msleep(1); - } while (1); -} - -/* - * Constraint: - * 1. this function will request pwrctrl->lock - */ -static void halbtcoutsrc_NormalLowPower(struct btc_coexist *pBtCoexist) -{ - struct adapter *padapter; - - padapter = pBtCoexist->Adapter; - rtw_unregister_task_alive(padapter, BTCOEX_ALIVE); -} - -static void halbtcoutsrc_DisableLowPower(struct btc_coexist *pBtCoexist, u8 bLowPwrDisable) -{ - pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable; - if (bLowPwrDisable) - halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */ - else - halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */ -} - -static void halbtcoutsrc_AggregationCheck(struct btc_coexist *pBtCoexist) -{ - struct adapter *padapter; - bool bNeedToAct; - - padapter = pBtCoexist->Adapter; - bNeedToAct = false; - - if (pBtCoexist->btInfo.bRejectAggPkt) { - rtw_btcoex_reject_ap_aggregated_packet(padapter, true); - } else { - if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize != - pBtCoexist->btInfo.bBtCtrlAggBufSize) { - bNeedToAct = true; - pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize; - } - - if (pBtCoexist->btInfo.bBtCtrlAggBufSize) { - if (pBtCoexist->btInfo.preAggBufSize != - pBtCoexist->btInfo.aggBufSize){ - bNeedToAct = true; - } - pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize; - } - - if (bNeedToAct) { - rtw_btcoex_reject_ap_aggregated_packet(padapter, true); - rtw_btcoex_reject_ap_aggregated_packet(padapter, false); - } - } -} - -static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv; - - pmlmepriv = &padapter->mlmepriv; - - if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE)) { - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - return true; - if (pmlmepriv->link_detect_info.busy_traffic) - return true; - } - - return false; -} - -static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv; - u8 bp2p; - u32 portConnectedStatus; - - pmlmepriv = &padapter->mlmepriv; - bp2p = false; - portConnectedStatus = 0; - - if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE)) { - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - if (bp2p) - portConnectedStatus |= WIFI_P2P_GO_CONNECTED; - else - portConnectedStatus |= WIFI_AP_CONNECTED; - } else { - if (bp2p) - portConnectedStatus |= WIFI_P2P_GC_CONNECTED; - else - portConnectedStatus |= WIFI_STA_CONNECTED; - } - } - - return portConnectedStatus; -} - -static u32 halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist *pBtCoexist) -{ - /* */ - /* return value: */ - /* [31:16]=> connected port number */ - /* [15:0]=> port connected bit define */ - /* */ - - struct adapter *padapter; - u32 retVal; - u32 portConnectedStatus, numOfConnectedPort; - - padapter = pBtCoexist->Adapter; - portConnectedStatus = 0; - numOfConnectedPort = 0; - - retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter); - if (retVal) { - portConnectedStatus |= retVal; - numOfConnectedPort++; - } - - retVal = (numOfConnectedPort << 16) | portConnectedStatus; - - return retVal; -} - -static u32 halbtcoutsrc_GetBtPatchVer(struct btc_coexist *pBtCoexist) -{ - return pBtCoexist->btInfo.btRealFwVer; -} - -static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB; -} - -static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext; - static u8 scan_AP_num; - - pmlmeext = &padapter->mlmeextpriv; - - if (!GLBtcWiFiInScanState) { - if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF) - scan_AP_num = 0xFF; - else - scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt; - } - - return scan_AP_num; -} - -static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - struct hal_com_data *pHalData; - struct mlme_ext_priv *mlmeext; - u8 *pu8; - s32 *pS4Tmp; - u32 *pU4Tmp; - u8 ret; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return false; - - padapter = pBtCoexist->Adapter; - pHalData = GET_HAL_DATA(padapter); - mlmeext = &padapter->mlmeextpriv; - pu8 = pOutBuf; - pS4Tmp = pOutBuf; - pU4Tmp = pOutBuf; - ret = true; - - switch (getType) { - case BTC_GET_BL_HS_OPERATION: - *pu8 = false; - ret = false; - break; - - case BTC_GET_BL_HS_CONNECTING: - *pu8 = false; - ret = false; - break; - - case BTC_GET_BL_WIFI_CONNECTED: - *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE); - break; - - case BTC_GET_BL_WIFI_BUSY: - *pu8 = halbtcoutsrc_IsWifiBusy(padapter); - break; - - case BTC_GET_BL_WIFI_SCAN: - /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag - WIFI_SITE_MONITOR in fwstate may not be cleared in time */ - *pu8 = GLBtcWiFiInScanState; - break; - - case BTC_GET_BL_WIFI_LINK: - *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING); - break; - - case BTC_GET_BL_WIFI_ROAM: - *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING); - break; - - case BTC_GET_BL_WIFI_4_WAY_PROGRESS: - *pu8 = false; - break; - - case BTC_GET_BL_WIFI_AP_MODE_ENABLE: - *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE); - break; - - case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION: - *pu8 = padapter->securitypriv.dot11_privacy_algrthm != 0; - break; - - case BTC_GET_BL_WIFI_UNDER_B_MODE: - if (mlmeext->cur_wireless_mode == WIRELESS_11B) - *pu8 = true; - else - *pu8 = false; - break; - - case BTC_GET_BL_WIFI_IS_IN_MP_MODE: - *pu8 = false; - break; - - case BTC_GET_BL_EXT_SWITCH: - *pu8 = false; - break; - - case BTC_GET_S4_WIFI_RSSI: - *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter); - break; - - case BTC_GET_S4_HS_RSSI: - *pS4Tmp = 0; - ret = false; - break; - - case BTC_GET_U4_WIFI_BW: - if (is_legacy_only(mlmeext->cur_wireless_mode)) - *pU4Tmp = BTC_WIFI_BW_LEGACY; - else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20) - *pU4Tmp = BTC_WIFI_BW_HT20; - else - *pU4Tmp = BTC_WIFI_BW_HT40; - break; - - case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: - { - struct rt_link_detect_t *plinkinfo; - - plinkinfo = &padapter->mlmepriv.link_detect_info; - - if (plinkinfo->num_tx_ok_in_period > plinkinfo->num_rx_ok_in_period) - *pU4Tmp = BTC_WIFI_TRAFFIC_TX; - else - *pU4Tmp = BTC_WIFI_TRAFFIC_RX; - } - break; - - case BTC_GET_U4_WIFI_FW_VER: - *pU4Tmp = pHalData->FirmwareVersion << 16; - *pU4Tmp |= pHalData->FirmwareSubVersion; - break; - - case BTC_GET_U4_WIFI_LINK_STATUS: - *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist); - break; - - case BTC_GET_U4_BT_PATCH_VER: - *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist); - break; - - case BTC_GET_U1_WIFI_DOT11_CHNL: - *pu8 = padapter->mlmeextpriv.cur_channel; - break; - - case BTC_GET_U1_WIFI_CENTRAL_CHNL: - *pu8 = pHalData->CurrentChannel; - break; - - case BTC_GET_U1_WIFI_HS_CHNL: - *pu8 = 0; - ret = false; - break; - - case BTC_GET_U1_MAC_PHY_MODE: - *pu8 = BTC_SMSP; - break; - - case BTC_GET_U1_AP_NUM: - *pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter); - break; - - /* 1Ant =========== */ - case BTC_GET_U1_LPS_MODE: - *pu8 = padapter->dvobj->pwrctl_priv.pwr_mode; - break; - - default: - ret = false; - break; - } - - return ret; -} - -static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - u8 *pu8; - u32 *pU4Tmp; - u8 ret; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - pu8 = pInBuf; - pU4Tmp = pInBuf; - ret = true; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return false; - - switch (setType) { - /* set some u8 type variables. */ - case BTC_SET_BL_BT_DISABLE: - pBtCoexist->btInfo.bBtDisabled = *pu8; - break; - - case BTC_SET_BL_BT_TRAFFIC_BUSY: - pBtCoexist->btInfo.bBtBusy = *pu8; - break; - - case BTC_SET_BL_BT_LIMITED_DIG: - pBtCoexist->btInfo.bLimitedDig = *pu8; - break; - - case BTC_SET_BL_FORCE_TO_ROAM: - pBtCoexist->btInfo.bForceToRoam = *pu8; - break; - - case BTC_SET_BL_TO_REJ_AP_AGG_PKT: - pBtCoexist->btInfo.bRejectAggPkt = *pu8; - break; - - case BTC_SET_BL_BT_CTRL_AGG_SIZE: - pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8; - break; - - case BTC_SET_BL_INC_SCAN_DEV_NUM: - pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8; - break; - - case BTC_SET_BL_BT_TX_RX_MASK: - pBtCoexist->btInfo.bBtTxRxMask = *pu8; - break; - - /* set some u8 type variables. */ - case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON: - pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8; - break; - - case BTC_SET_U1_AGG_BUF_SIZE: - pBtCoexist->btInfo.aggBufSize = *pu8; - break; - - /* the following are some action which will be triggered */ - case BTC_SET_ACT_GET_BT_RSSI: - ret = false; - break; - - case BTC_SET_ACT_AGGREGATE_CTRL: - halbtcoutsrc_AggregationCheck(pBtCoexist); - break; - - /* 1Ant =========== */ - /* set some u8 type variables. */ - case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE: - pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8; - break; - - case BTC_SET_U1_LPS_VAL: - pBtCoexist->btInfo.lpsVal = *pu8; - break; - - case BTC_SET_U1_RPWM_VAL: - pBtCoexist->btInfo.rpwmVal = *pu8; - break; - - /* the following are some action which will be triggered */ - case BTC_SET_ACT_LEAVE_LPS: - halbtcoutsrc_LeaveLps(pBtCoexist); - break; - - case BTC_SET_ACT_ENTER_LPS: - halbtcoutsrc_EnterLps(pBtCoexist); - break; - - case BTC_SET_ACT_NORMAL_LPS: - halbtcoutsrc_NormalLps(pBtCoexist); - break; - - case BTC_SET_ACT_DISABLE_LOW_POWER: - halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8); - break; - - case BTC_SET_ACT_UPDATE_RAMASK: - pBtCoexist->btInfo.raMask = *pU4Tmp; - - if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) { - struct sta_info *psta; - struct wlan_bssid_ex *cur_network; - - cur_network = &padapter->mlmeextpriv.mlmext_info.network; - psta = rtw_get_stainfo(&padapter->stapriv, cur_network->mac_address); - rtw_hal_update_ra_mask(psta, 0); - } - break; - - case BTC_SET_ACT_SEND_MIMO_PS: - ret = false; - break; - - case BTC_SET_ACT_CTRL_BT_INFO: - ret = false; - break; - - case BTC_SET_ACT_CTRL_BT_COEX: - ret = false; - break; - case BTC_SET_ACT_CTRL_8723B_ANT: - ret = false; - break; - /* */ - default: - ret = false; - break; - } - - return ret; -} - -/* */ -/* IO related function */ -/* */ -static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - return rtw_read8(padapter, RegAddr); -} - -static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - return rtw_read16(padapter, RegAddr); -} - -static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - return rtw_read32(padapter, RegAddr); -} - -static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - rtw_write8(padapter, RegAddr, Data); -} - -static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - u8 originalValue, bitShift; - u8 i; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - originalValue = 0; - bitShift = 0; - - if (bitMask != 0xFF) { - originalValue = rtw_read8(padapter, regAddr); - - for (i = 0; i <= 7; i++) { - if ((bitMask >> i) & 0x1) - break; - } - bitShift = i; - - data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask); - } - - rtw_write8(padapter, regAddr, data1b); -} - -static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - rtw_write16(padapter, RegAddr, Data); -} - -static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - rtw_write32(padapter, RegAddr, Data); -} - -static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data) -{ - struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; - struct adapter *Adapter = pBtCoexist->Adapter; - - if (pBtCoexist->chipInterface == BTC_INTF_SDIO) - rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data); - else - rtw_write8(Adapter, RegAddr, Data); -} - -static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - PHY_SetBBReg(padapter, RegAddr, BitMask, Data); -} - -static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - return PHY_QueryBBReg(padapter, RegAddr, BitMask); -} - -static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data); -} - -static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask); -} - -static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - u8 CmdBuffer1[4] = {0}; - u8 CmdBuffer2[4] = {0}; - u8 *AddrToSet = (u8 *)&RegAddr; - u8 *ValueToSet = (u8 *)&Data; - u8 OperVer = 0; - u8 ReqNum = 0; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */ - CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */ - CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */ - CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */ - rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0])); - - msleep(200); - ReqNum++; - - CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */ - CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */ - CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */ - CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */ - rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0])); -} - -static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr) -{ - /* To be implemented. Always return 0 temporarily */ - return 0; -} - -static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer) -{ - struct btc_coexist *pBtCoexist; - struct adapter *padapter; - - pBtCoexist = (struct btc_coexist *)pBtcContext; - padapter = pBtCoexist->Adapter; - - rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer); -} - -/* */ -/* Extern functions called by other module */ -/* */ -static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter) -{ - struct btc_coexist *pBtCoexist = &GLBtCoexist; - - if (pBtCoexist->bBinded) - return false; - else - pBtCoexist->bBinded = true; - - pBtCoexist->statistics.cntBind++; - - pBtCoexist->Adapter = padapter; - - pBtCoexist->stackInfo.bProfileNotified = false; - - pBtCoexist->btInfo.bBtCtrlAggBufSize = false; - pBtCoexist->btInfo.aggBufSize = 5; - - pBtCoexist->btInfo.bIncreaseScanDevNum = false; - - /* set default antenna position to main port */ - pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; - - return true; -} - -void hal_btcoex_Initialize(void *padapter) -{ - struct btc_coexist *pBtCoexist; - - memset(&GLBtCoexist, 0, sizeof(GLBtCoexist)); - - pBtCoexist = &GLBtCoexist; - - /* pBtCoexist->statistics.cntBind++; */ - - pBtCoexist->chipInterface = BTC_INTF_SDIO; - - EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter); - - pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte; - pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte; - pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte; - pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte; - pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte; - pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte; - pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte; - pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte; - - pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg; - pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg; - - pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg; - pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg; - - pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd; - - pBtCoexist->fBtcGet = halbtcoutsrc_Get; - pBtCoexist->fBtcSet = halbtcoutsrc_Set; - pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg; - pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg; - - pBtCoexist->boardInfo.singleAntPath = 0; - - GLBtcWiFiInScanState = false; - - GLBtcWiFiInIQKState = false; -} - -void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - /* Power on setting function is only added in 8723B currently */ - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist); -} - -void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - pBtCoexist->statistics.cntInitHwConfig++; - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly); -} - -void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - pBtCoexist->statistics.cntInitCoexDm++; - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_InitCoexDm(pBtCoexist); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_InitCoexDm(pBtCoexist); - - pBtCoexist->bInitilized = true; -} - -void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - u8 ipsType; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - pBtCoexist->statistics.cntIpsNotify++; - if (pBtCoexist->bManualControl) - return; - - if (type == IPS_NONE) - ipsType = BTC_IPS_LEAVE; - else - ipsType = BTC_IPS_ENTER; - - /* All notify is called in cmd thread, don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - u8 lpsType; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - pBtCoexist->statistics.cntLpsNotify++; - if (pBtCoexist->bManualControl) - return; - - if (type == PS_MODE_ACTIVE) - lpsType = BTC_LPS_DISABLE; - else - lpsType = BTC_LPS_ENABLE; - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType); -} - -void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type) -{ - u8 scanType; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - pBtCoexist->statistics.cntScanNotify++; - if (pBtCoexist->bManualControl) - return; - - if (type) { - scanType = BTC_SCAN_START; - GLBtcWiFiInScanState = true; - } else { - scanType = BTC_SCAN_FINISH; - GLBtcWiFiInScanState = false; - } - - /* All notify is called in cmd thread, don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action) -{ - u8 assoType; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - pBtCoexist->statistics.cntConnectNotify++; - if (pBtCoexist->bManualControl) - return; - - if (action) - assoType = BTC_ASSOCIATE_START; - else - assoType = BTC_ASSOCIATE_FINISH; - - /* All notify is called in cmd thread, don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist *pBtCoexist, enum - rt_media_status mediaStatus) -{ - u8 mStatus; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - pBtCoexist->statistics.cntMediaStatusNotify++; - if (pBtCoexist->bManualControl) - return; - - if (mediaStatus == RT_MEDIA_CONNECT) - mStatus = BTC_MEDIA_CONNECT; - else - mStatus = BTC_MEDIA_DISCONNECT; - - /* All notify is called in cmd thread, don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType) -{ - u8 packetType; - - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - pBtCoexist->statistics.cntSpecialPacketNotify++; - if (pBtCoexist->bManualControl) - return; - - if (pktType == PACKET_DHCP) { - packetType = BTC_PACKET_DHCP; - } else if (pktType == PACKET_EAPOL) { - packetType = BTC_PACKET_EAPOL; - } else if (pktType == PACKET_ARP) { - packetType = BTC_PACKET_ARP; - } else { - return; - } - - /* All notify is called in cmd thread, don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - pBtCoexist->statistics.cntBtInfoNotify++; - - /* All notify is called in cmd thread, don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_HaltNotify(pBtCoexist); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_HaltNotify(pBtCoexist); - - pBtCoexist->bBinded = false; -} - -void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - - /* */ - /* currently only 1ant we have to do the notification, */ - /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */ - /* */ - - if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState); - else if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState); -} - -void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist) -{ - if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) - return; - pBtCoexist->statistics.cntPeriodical++; - - /* Periodical should be called in cmd thread, */ - /* don't need to leave low power again */ -/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ - - if (pBtCoexist->boardInfo.btdmAntNum == 2) - EXhalbtc8723b2ant_Periodical(pBtCoexist); - else if (pBtCoexist->boardInfo.btdmAntNum == 1) - EXhalbtc8723b1ant_Periodical(pBtCoexist); - -/* halbtcoutsrc_NormalLowPower(pBtCoexist); */ -} - -void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum) -{ - if (type == BT_COEX_ANT_TYPE_PG) { - GLBtCoexist.boardInfo.pgAntNum = antNum; - GLBtCoexist.boardInfo.btdmAntNum = antNum; - } else if (type == BT_COEX_ANT_TYPE_ANTDIV) { - GLBtCoexist.boardInfo.btdmAntNum = antNum; - /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */ - } else if (type == BT_COEX_ANT_TYPE_DETECTED) { - GLBtCoexist.boardInfo.btdmAntNum = antNum; - /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */ - } -} - -/* */ -/* Currently used by 8723b only, S0 or S1 */ -/* */ -void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath) -{ - GLBtCoexist.boardInfo.singleAntPath = singleAntPath; -} - -/* - * Description: - *Run BT-Coexist mechanism or not - * - */ -void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist) -{ - struct hal_com_data *pHalData; - - pHalData = GET_HAL_DATA(padapter); - pHalData->bt_coexist.bBtExist = bBtExist; -} - -/* - * Dewcription: - *Check is co-exist mechanism enabled or not - * - * Return: - *true Enable BT co-exist mechanism - *false Disable BT co-exist mechanism - */ -bool hal_btcoex_IsBtExist(struct adapter *padapter) -{ - struct hal_com_data *pHalData; - - pHalData = GET_HAL_DATA(padapter); - return pHalData->bt_coexist.bBtExist; -} - -bool hal_btcoex_IsBtDisabled(struct adapter *padapter) -{ - if (!hal_btcoex_IsBtExist(padapter)) - return true; - - if (GLBtCoexist.btInfo.bBtDisabled) - return true; - else - return false; -} - -void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum) -{ - struct hal_com_data *pHalData; - - pHalData = GET_HAL_DATA(padapter); - - pHalData->bt_coexist.btTotalAntNum = antNum; - EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum); -} - -void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath) -{ - EXhalbtcoutsrc_SetSingleAntPath(singleAntPath); -} - -void hal_btcoex_PowerOnSetting(struct adapter *padapter) -{ - EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist); -} - -void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly) -{ - if (!hal_btcoex_IsBtExist(padapter)) - return; - - EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly); - EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist); -} - -void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type) -{ - EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type); -} - -void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type) -{ - EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type); -} - -void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type) -{ - EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type); -} - -void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action) -{ - EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action); -} - -void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus) -{ - EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus); -} - -void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType) -{ - EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType); -} - -void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state) -{ - GLBtcWiFiInIQKState = state; -} - -void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf) -{ - if (GLBtcWiFiInIQKState) - return; - - EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length); -} - -void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state) -{ - if (state == 1) - state = BTC_WIFI_PNP_SLEEP; - else - state = BTC_WIFI_PNP_WAKE_UP; - - EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state); -} - -void hal_btcoex_HaltNotify(struct adapter *padapter) -{ - EXhalbtcoutsrc_HaltNotify(&GLBtCoexist); -} - -void hal_btcoex_Handler(struct adapter *padapter) -{ - EXhalbtcoutsrc_Periodical(&GLBtCoexist); -} - -s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter) -{ - return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize; -} - -bool hal_btcoex_IsBtControlLps(struct adapter *padapter) -{ - if (!hal_btcoex_IsBtExist(padapter)) - return false; - - if (GLBtCoexist.btInfo.bBtDisabled) - return false; - - if (GLBtCoexist.btInfo.bBtCtrlLps) - return true; - - return false; -} - -bool hal_btcoex_IsLpsOn(struct adapter *padapter) -{ - if (!hal_btcoex_IsBtExist(padapter)) - return false; - - if (GLBtCoexist.btInfo.bBtDisabled) - return false; - - if (GLBtCoexist.btInfo.bBtLpsOn) - return true; - - return false; -} - -u8 hal_btcoex_RpwmVal(struct adapter *padapter) -{ - return GLBtCoexist.btInfo.rpwmVal; -} - -u8 hal_btcoex_LpsVal(struct adapter *padapter) -{ - return GLBtCoexist.btInfo.lpsVal; -} - -u32 hal_btcoex_GetRaMask(struct adapter *padapter) -{ - if (!hal_btcoex_IsBtExist(padapter)) - return 0; - - if (GLBtCoexist.btInfo.bBtDisabled) - return 0; - - if (GLBtCoexist.boardInfo.btdmAntNum != 1) - return 0; - - return GLBtCoexist.btInfo.raMask; -} - -void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen) -{ - memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen); -} diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c b/drivers/staging/rtl8723bs/hal/hal_com.c deleted file mode 100644 index 2c856a2721b2..000000000000 --- a/drivers/staging/rtl8723bs/hal/hal_com.c +++ /dev/null @@ -1,767 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include "hal_com_h2c.h" - -#include "odm_precomp.h" - -u8 rtw_hal_data_init(struct adapter *padapter) -{ - padapter->hal_data_sz = sizeof(struct hal_com_data); - padapter->HalData = vzalloc(padapter->hal_data_sz); - if (!padapter->HalData) - return _FAIL; - - return _SUCCESS; -} - -void rtw_hal_data_deinit(struct adapter *padapter) -{ - if (padapter->HalData) { - vfree(padapter->HalData); - padapter->HalData = NULL; - padapter->hal_data_sz = 0; - } -} - -#define EEPROM_CHANNEL_PLAN_BY_HW_MASK 0x80 - -/* - * Description: - *Use hardware(efuse), driver parameter(registry) and default channel plan - *to decide which one should be used. - * - * Parameters: - *padapter pointer of adapter - *hw_channel_plan channel plan from HW (efuse/eeprom) - * BIT[7] software configure mode; 0:Enable, 1:disable - * BIT[6:0] Channel Plan - *sw_channel_plan channel plan from SW (registry/module param) - *def_channel_plan channel plan used when HW/SW both invalid - *auto_load_fail efuse autoload fail or not - * - * Return: - *Final channel plan decision - * - */ -u8 hal_com_config_channel_plan( - struct adapter *padapter, - u8 hw_channel_plan, - u8 sw_channel_plan, - u8 def_channel_plan, - bool auto_load_fail -) -{ - struct hal_com_data *pHalData; - u8 chnlPlan; - - pHalData = GET_HAL_DATA(padapter); - pHalData->bDisableSWChannelPlan = false; - chnlPlan = def_channel_plan; - - if (hw_channel_plan == 0xFF) - auto_load_fail = true; - - if (!auto_load_fail) { - u8 hw_chnlPlan; - - hw_chnlPlan = hw_channel_plan & (~EEPROM_CHANNEL_PLAN_BY_HW_MASK); - if (rtw_is_channel_plan_valid(hw_chnlPlan)) { - if (hw_channel_plan & EEPROM_CHANNEL_PLAN_BY_HW_MASK) - pHalData->bDisableSWChannelPlan = true; - - chnlPlan = hw_chnlPlan; - } - } - - if ( - (false == pHalData->bDisableSWChannelPlan) && - rtw_is_channel_plan_valid(sw_channel_plan) - ) - chnlPlan = sw_channel_plan; - - return chnlPlan; -} - -bool HAL_IsLegalChannel(struct adapter *adapter, u32 Channel) -{ - bool bLegalChannel = true; - - if ((Channel <= 14) && (Channel >= 1)) { - if (!is_supported_24g(adapter->registrypriv.wireless_mode)) - bLegalChannel = false; - } else { - bLegalChannel = false; - } - - return bLegalChannel; -} - -u8 MRateToHwRate(u8 rate) -{ - u8 ret = DESC_RATE1M; - - switch (rate) { - case MGN_1M: - ret = DESC_RATE1M; - break; - case MGN_2M: - ret = DESC_RATE2M; - break; - case MGN_5_5M: - ret = DESC_RATE5_5M; - break; - case MGN_11M: - ret = DESC_RATE11M; - break; - case MGN_6M: - ret = DESC_RATE6M; - break; - case MGN_9M: - ret = DESC_RATE9M; - break; - case MGN_12M: - ret = DESC_RATE12M; - break; - case MGN_18M: - ret = DESC_RATE18M; - break; - case MGN_24M: - ret = DESC_RATE24M; - break; - case MGN_36M: - ret = DESC_RATE36M; - break; - case MGN_48M: - ret = DESC_RATE48M; - break; - case MGN_54M: - ret = DESC_RATE54M; - break; - case MGN_MCS0: - ret = DESC_RATEMCS0; - break; - case MGN_MCS1: - ret = DESC_RATEMCS1; - break; - case MGN_MCS2: - ret = DESC_RATEMCS2; - break; - case MGN_MCS3: - ret = DESC_RATEMCS3; - break; - case MGN_MCS4: - ret = DESC_RATEMCS4; - break; - case MGN_MCS5: - ret = DESC_RATEMCS5; - break; - case MGN_MCS6: - ret = DESC_RATEMCS6; - break; - case MGN_MCS7: - ret = DESC_RATEMCS7; - break; - default: - break; - } - - return ret; -} - -u8 HwRateToMRate(u8 rate) -{ - u8 ret_rate = MGN_1M; - - switch (rate) { - case DESC_RATE1M: - ret_rate = MGN_1M; - break; - case DESC_RATE2M: - ret_rate = MGN_2M; - break; - case DESC_RATE5_5M: - ret_rate = MGN_5_5M; - break; - case DESC_RATE11M: - ret_rate = MGN_11M; - break; - case DESC_RATE6M: - ret_rate = MGN_6M; - break; - case DESC_RATE9M: - ret_rate = MGN_9M; - break; - case DESC_RATE12M: - ret_rate = MGN_12M; - break; - case DESC_RATE18M: - ret_rate = MGN_18M; - break; - case DESC_RATE24M: - ret_rate = MGN_24M; - break; - case DESC_RATE36M: - ret_rate = MGN_36M; - break; - case DESC_RATE48M: - ret_rate = MGN_48M; - break; - case DESC_RATE54M: - ret_rate = MGN_54M; - break; - case DESC_RATEMCS0: - ret_rate = MGN_MCS0; - break; - case DESC_RATEMCS1: - ret_rate = MGN_MCS1; - break; - case DESC_RATEMCS2: - ret_rate = MGN_MCS2; - break; - case DESC_RATEMCS3: - ret_rate = MGN_MCS3; - break; - case DESC_RATEMCS4: - ret_rate = MGN_MCS4; - break; - case DESC_RATEMCS5: - ret_rate = MGN_MCS5; - break; - case DESC_RATEMCS6: - ret_rate = MGN_MCS6; - break; - case DESC_RATEMCS7: - ret_rate = MGN_MCS7; - break; - default: - break; - } - - return ret_rate; -} - -void HalSetBrateCfg(struct adapter *Adapter, u8 *mBratesOS, u16 *pBrateCfg) -{ - u8 i, is_brate, brate; - - for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) { - is_brate = mBratesOS[i] & IEEE80211_BASIC_RATE_MASK; - brate = mBratesOS[i] & 0x7f; - - if (is_brate) { - switch (brate) { - case IEEE80211_CCK_RATE_1MB: - *pBrateCfg |= RATE_1M; - break; - case IEEE80211_CCK_RATE_2MB: - *pBrateCfg |= RATE_2M; - break; - case IEEE80211_CCK_RATE_5MB: - *pBrateCfg |= RATE_5_5M; - break; - case IEEE80211_CCK_RATE_11MB: - *pBrateCfg |= RATE_11M; - break; - case IEEE80211_OFDM_RATE_6MB: - *pBrateCfg |= RATE_6M; - break; - case IEEE80211_OFDM_RATE_9MB: - *pBrateCfg |= RATE_9M; - break; - case IEEE80211_OFDM_RATE_12MB: - *pBrateCfg |= RATE_12M; - break; - case IEEE80211_OFDM_RATE_18MB: - *pBrateCfg |= RATE_18M; - break; - case IEEE80211_OFDM_RATE_24MB: - *pBrateCfg |= RATE_24M; - break; - case IEEE80211_OFDM_RATE_36MB: - *pBrateCfg |= RATE_36M; - break; - case IEEE80211_OFDM_RATE_48MB: - *pBrateCfg |= RATE_48M; - break; - case IEEE80211_OFDM_RATE_54MB: - *pBrateCfg |= RATE_54M; - break; - } - } - } -} - -static void _OneOutPipeMapping(struct adapter *padapter) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - - pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */ - pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */ - pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[0];/* BE */ - pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[0];/* BK */ - - pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */ - pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */ - pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */ - pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */ -} - -static void _TwoOutPipeMapping(struct adapter *padapter, bool bWIFICfg) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - - if (bWIFICfg) { /* WMM */ - - /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */ - /* 0, 1, 0, 1, 0, 0, 0, 0, 0 }; */ - /* 0:ep_0 num, 1:ep_1 num */ - - pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[1];/* VO */ - pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */ - pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[1];/* BE */ - pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[0];/* BK */ - - pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */ - pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */ - pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */ - pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */ - - } else { /* typical setting */ - - /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */ - /* 1, 1, 0, 0, 0, 0, 0, 0, 0 }; */ - /* 0:ep_0 num, 1:ep_1 num */ - - pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */ - pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[0];/* VI */ - pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[1];/* BE */ - pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[1];/* BK */ - - pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */ - pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */ - pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */ - pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */ - - } - -} - -static void _ThreeOutPipeMapping(struct adapter *padapter, bool bWIFICfg) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - - if (bWIFICfg) { /* for WMM */ - - /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */ - /* 1, 2, 1, 0, 0, 0, 0, 0, 0 }; */ - /* 0:H, 1:N, 2:L */ - - pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */ - pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[1];/* VI */ - pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[2];/* BE */ - pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[1];/* BK */ - - pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */ - pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */ - pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */ - pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */ - - } else { /* typical setting */ - - /* BK, BE, VI, VO, BCN, CMD, MGT, HIGH, HCCA */ - /* 2, 2, 1, 0, 0, 0, 0, 0, 0 }; */ - /* 0:H, 1:N, 2:L */ - - pdvobjpriv->Queue2Pipe[0] = pdvobjpriv->RtOutPipe[0];/* VO */ - pdvobjpriv->Queue2Pipe[1] = pdvobjpriv->RtOutPipe[1];/* VI */ - pdvobjpriv->Queue2Pipe[2] = pdvobjpriv->RtOutPipe[2];/* BE */ - pdvobjpriv->Queue2Pipe[3] = pdvobjpriv->RtOutPipe[2];/* BK */ - - pdvobjpriv->Queue2Pipe[4] = pdvobjpriv->RtOutPipe[0];/* BCN */ - pdvobjpriv->Queue2Pipe[5] = pdvobjpriv->RtOutPipe[0];/* MGT */ - pdvobjpriv->Queue2Pipe[6] = pdvobjpriv->RtOutPipe[0];/* HIGH */ - pdvobjpriv->Queue2Pipe[7] = pdvobjpriv->RtOutPipe[0];/* TXCMD */ - } - -} - -bool Hal_MappingOutPipe(struct adapter *padapter, u8 NumOutPipe) -{ - struct registry_priv *pregistrypriv = &padapter->registrypriv; - - bool bWIFICfg = (pregistrypriv->wifi_spec) ? true : false; - - bool result = true; - - switch (NumOutPipe) { - case 2: - _TwoOutPipeMapping(padapter, bWIFICfg); - break; - case 3: - case 4: - _ThreeOutPipeMapping(padapter, bWIFICfg); - break; - case 1: - _OneOutPipeMapping(padapter); - break; - default: - result = false; - break; - } - - return result; - -} - -void hal_init_macaddr(struct adapter *adapter) -{ - rtw_hal_set_hwreg(adapter, HW_VAR_MAC_ADDR, adapter->eeprompriv.mac_addr); -} - -void rtw_init_hal_com_default_value(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - pHalData->AntDetection = 1; -} - -/* - * C2H event format: - * Field TRIGGER CONTENT CMD_SEQ CMD_LEN CMD_ID - * BITS [127:120] [119:16] [15:8] [7:4] [3:0] - */ - -void c2h_evt_clear(struct adapter *adapter) -{ - rtw_write8(adapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE); -} - -/* - * C2H event format: - * Field TRIGGER CMD_LEN CONTENT CMD_SEQ CMD_ID - * BITS [127:120] [119:112] [111:16] [15:8] [7:0] - */ -s32 c2h_evt_read_88xx(struct adapter *adapter, u8 *buf) -{ - s32 ret = _FAIL; - struct c2h_evt_hdr_88xx *c2h_evt; - int i; - u8 trigger; - - if (!buf) - goto exit; - - trigger = rtw_read8(adapter, REG_C2HEVT_CLEAR); - - if (trigger == C2H_EVT_HOST_CLOSE) - goto exit; /* Not ready */ - else if (trigger != C2H_EVT_FW_CLOSE) - goto clear_evt; /* Not a valid value */ - - c2h_evt = (struct c2h_evt_hdr_88xx *)buf; - - memset(c2h_evt, 0, 16); - - c2h_evt->id = rtw_read8(adapter, REG_C2HEVT_MSG_NORMAL); - c2h_evt->seq = rtw_read8(adapter, REG_C2HEVT_CMD_SEQ_88XX); - c2h_evt->plen = rtw_read8(adapter, REG_C2HEVT_CMD_LEN_88XX); - - /* Read the content */ - for (i = 0; i < c2h_evt->plen; i++) - c2h_evt->payload[i] = rtw_read8(adapter, REG_C2HEVT_MSG_NORMAL + 2 + i); - - ret = _SUCCESS; - -clear_evt: - /* - * Clear event to notify FW we have read the command. - * If this field isn't clear, the FW won't update the next command message. - */ - c2h_evt_clear(adapter); -exit: - return ret; -} - -u8 rtw_get_mgntframe_raid(struct adapter *adapter, unsigned char network_type) -{ - return (network_type & WIRELESS_11B) ? RATEID_IDX_B : RATEID_IDX_G; -} - -void rtw_hal_update_sta_rate_mask(struct adapter *padapter, struct sta_info *psta) -{ - u8 i, limit; - u32 tx_ra_bitmap; - - if (!psta) - return; - - tx_ra_bitmap = 0; - - /* b/g mode ra_bitmap */ - for (i = 0; i < sizeof(psta->bssrateset); i++) { - if (psta->bssrateset[i]) - tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i]&0x7f); - } - - /* n mode ra_bitmap */ - if (psta->htpriv.ht_option) { - limit = 8; /* 1R */ - - for (i = 0; i < limit; i++) { - if (psta->htpriv.ht_cap.mcs.rx_mask[i/8] & BIT(i%8)) - tx_ra_bitmap |= BIT(i+12); - } - } - - psta->ra_mask = tx_ra_bitmap; - psta->init_rate = get_highest_rate_idx(tx_ra_bitmap)&0x3f; -} - -void SetHwReg(struct adapter *adapter, u8 variable, u8 *val) -{ - struct hal_com_data *hal_data = GET_HAL_DATA(adapter); - struct dm_odm_t *odm = &(hal_data->odmpriv); - - switch (variable) { - case HW_VAR_INIT_RTS_RATE: - WARN_ON(1); - break; - case HW_VAR_SEC_CFG: - { - u16 reg_scr; - - reg_scr = rtw_read16(adapter, REG_SECCFG); - rtw_write16(adapter, REG_SECCFG, reg_scr|SCR_CHK_KEYID|SCR_RxDecEnable|SCR_TxEncEnable); - } - break; - case HW_VAR_SEC_DK_CFG: - { - struct security_priv *sec = &adapter->securitypriv; - u8 reg_scr = rtw_read8(adapter, REG_SECCFG); - - if (val) { /* Enable default key related setting */ - reg_scr |= SCR_TXBCUSEDK; - if (sec->dot11_auth_algrthm != dot11_auth_algrthm_8021x) - reg_scr |= (SCR_RxUseDK|SCR_TxUseDK); - } else /* Disable default key related setting */ - reg_scr &= ~(SCR_RXBCUSEDK|SCR_TXBCUSEDK|SCR_RxUseDK|SCR_TxUseDK); - - rtw_write8(adapter, REG_SECCFG, reg_scr); - } - break; - case HW_VAR_DM_FLAG: - odm->SupportAbility = *((u32 *)val); - break; - case HW_VAR_DM_FUNC_OP: - if (*((u8 *)val)) { - /* save dm flag */ - odm->BK_SupportAbility = odm->SupportAbility; - } else { - /* restore dm flag */ - odm->SupportAbility = odm->BK_SupportAbility; - } - break; - case HW_VAR_DM_FUNC_SET: - if (*((u32 *)val) == DYNAMIC_ALL_FUNC_ENABLE) { - struct dm_priv *dm = &hal_data->dmpriv; - - dm->DMFlag = dm->InitDMFlag; - odm->SupportAbility = dm->InitODMFlag; - } else { - odm->SupportAbility |= *((u32 *)val); - } - break; - case HW_VAR_DM_FUNC_CLR: - /* - * input is already a mask to clear function - * don't invert it again! George, Lucas@20130513 - */ - odm->SupportAbility &= *((u32 *)val); - break; - case HW_VAR_AMPDU_MIN_SPACE: - /* TODO - Is something needed here? */ - break; - case HW_VAR_WIRELESS_MODE: - /* TODO - Is something needed here? */ - break; - default: - netdev_dbg(adapter->pnetdev, - FUNC_ADPT_FMT " variable(%d) not defined!\n", - FUNC_ADPT_ARG(adapter), variable); - break; - } -} - -void GetHwReg(struct adapter *adapter, u8 variable, u8 *val) -{ - struct hal_com_data *hal_data = GET_HAL_DATA(adapter); - struct dm_odm_t *odm = &(hal_data->odmpriv); - - switch (variable) { - case HW_VAR_BASIC_RATE: - *((u16 *)val) = hal_data->BasicRateSet; - break; - case HW_VAR_DM_FLAG: - *((u32 *)val) = odm->SupportAbility; - break; - default: - netdev_dbg(adapter->pnetdev, - FUNC_ADPT_FMT " variable(%d) not defined!\n", - FUNC_ADPT_ARG(adapter), variable); - break; - } -} - -u8 GetHalDefVar( - struct adapter *adapter, enum hal_def_variable variable, void *value -) -{ - struct hal_com_data *hal_data = GET_HAL_DATA(adapter); - u8 bResult = _SUCCESS; - - switch (variable) { - case HAL_DEF_UNDERCORATEDSMOOTHEDPWDB: - { - struct mlme_priv *pmlmepriv; - struct sta_priv *pstapriv; - struct sta_info *psta; - - pmlmepriv = &adapter->mlmepriv; - pstapriv = &adapter->stapriv; - psta = rtw_get_stainfo(pstapriv, pmlmepriv->cur_network.network.mac_address); - if (psta) - *((int *)value) = psta->rssi_stat.UndecoratedSmoothedPWDB; - } - break; - case HAL_DEF_DBG_DM_FUNC: - *((u32 *)value) = hal_data->odmpriv.SupportAbility; - break; - case HAL_DEF_ANT_DETECT: - *((u8 *)value) = hal_data->AntDetection; - break; - case HAL_DEF_MACID_SLEEP: - *(u8 *)value = false; - break; - case HAL_DEF_TX_PAGE_SIZE: - *((u32 *)value) = PAGE_SIZE_128; - break; - default: - netdev_dbg(adapter->pnetdev, - "%s: [WARNING] HAL_DEF_VARIABLE(%d) not defined!\n", - __func__, variable); - bResult = _FAIL; - break; - } - - return bResult; -} - -void SetHalODMVar( - struct adapter *Adapter, - enum hal_odm_variable eVariable, - void *pValue1, - bool bSet -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_odm_t *podmpriv = &pHalData->odmpriv; - /* _irqL irqL; */ - switch (eVariable) { - case HAL_ODM_STA_INFO: - { - struct sta_info *psta = pValue1; - - if (bSet) { - ODM_CmnInfoPtrArrayHook(podmpriv, ODM_CMNINFO_STA_STATUS, psta->mac_id, psta); - } else { - /* spin_lock_bh(&pHalData->odm_stainfo_lock); */ - ODM_CmnInfoPtrArrayHook(podmpriv, ODM_CMNINFO_STA_STATUS, psta->mac_id, NULL); - - /* spin_unlock_bh(&pHalData->odm_stainfo_lock); */ - } - } - break; - case HAL_ODM_P2P_STATE: - ODM_CmnInfoUpdate(podmpriv, ODM_CMNINFO_WIFI_DIRECT, bSet); - break; - case HAL_ODM_WIFI_DISPLAY_STATE: - ODM_CmnInfoUpdate(podmpriv, ODM_CMNINFO_WIFI_DISPLAY, bSet); - break; - - default: - break; - } -} - -bool GetU1ByteIntegerFromStringInDecimal(char *Str, u8 *pInt) -{ - u16 i = 0; - *pInt = 0; - - while (Str[i] != '\0') { - if (Str[i] >= '0' && Str[i] <= '9') { - *pInt *= 10; - *pInt += (Str[i] - '0'); - } else - return false; - - ++i; - } - - return true; -} - -void rtw_hal_check_rxfifo_full(struct adapter *adapter) -{ - /* switch counter to RX fifo */ - rtw_write8(adapter, REG_RXERR_RPT+3, rtw_read8(adapter, REG_RXERR_RPT+3)|0xf0); -} - -static u32 Array_kfreemap[] = { - 0xf8, 0xe, - 0xf6, 0xc, - 0xf4, 0xa, - 0xf2, 0x8, - 0xf0, 0x6, - 0xf3, 0x4, - 0xf5, 0x2, - 0xf7, 0x0, - 0xf9, 0x0, - 0xfc, 0x0, -}; - -#define REG_RF_BB_GAIN_OFFSET 0x7f -//#define RF_GAIN_OFFSET_MASK 0xfffff - -void rtw_bb_rf_gain_offset(struct adapter *padapter) -{ - u8 value = padapter->eeprompriv.EEPROMRFGainOffset; - u32 *Array = Array_kfreemap; - u32 v1 = 0, v2 = 0, target = 0; - u32 i = 0; - - if (value & BIT(4)) { - if (padapter->eeprompriv.EEPROMRFGainVal != 0xff) { - rtw_hal_read_rfreg(padapter, RF_PATH_A, 0x7f, 0xffffffff); - - for (i = 0; i < ARRAY_SIZE(Array_kfreemap); i += 2) { - v1 = Array[i]; - v2 = Array[i+1]; - if (v1 == padapter->eeprompriv.EEPROMRFGainVal) { - target = v2; - break; - } - } - PHY_SetRFReg(padapter, RF_PATH_A, REG_RF_BB_GAIN_OFFSET, BIT(18)|BIT(17)|BIT(16)|BIT(15), target); - - rtw_hal_read_rfreg(padapter, RF_PATH_A, 0x7f, 0xffffffff); - } - } -} diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c deleted file mode 100644 index df0eaff4c841..000000000000 --- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +++ /dev/null @@ -1,973 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include -#include - -u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 RfPath, - enum rate_section RateSection) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u8 value = 0; - - if (RfPath >= RF_PATH_MAX) - return 0; - - switch (RateSection) { - case CCK: - value = pHalData->TxPwrByRateBase2_4G[RfPath][0]; - break; - case OFDM: - value = pHalData->TxPwrByRateBase2_4G[RfPath][1]; - break; - case HT_MCS0_MCS7: - value = pHalData->TxPwrByRateBase2_4G[RfPath][2]; - break; - default: - break; - } - - return value; -} - -static void -phy_SetTxPowerByRateBase(struct adapter *Adapter, u8 RfPath, - enum rate_section RateSection, u8 Value) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - if (RfPath >= RF_PATH_MAX) - return; - - switch (RateSection) { - case CCK: - pHalData->TxPwrByRateBase2_4G[RfPath][0] = Value; - break; - case OFDM: - pHalData->TxPwrByRateBase2_4G[RfPath][1] = Value; - break; - case HT_MCS0_MCS7: - pHalData->TxPwrByRateBase2_4G[RfPath][2] = Value; - break; - default: - break; - } -} - -static void phy_StoreTxPowerByRateBase(struct adapter *padapter) -{ - u8 path, base; - - for (path = RF_PATH_A; path <= RF_PATH_B; ++path) { - base = PHY_GetTxPowerByRate(padapter, path, MGN_11M); - phy_SetTxPowerByRateBase(padapter, path, CCK, base); - - base = PHY_GetTxPowerByRate(padapter, path, MGN_54M); - phy_SetTxPowerByRateBase(padapter, path, OFDM, base); - - base = PHY_GetTxPowerByRate(padapter, path, MGN_MCS7); - phy_SetTxPowerByRateBase(padapter, path, HT_MCS0_MCS7, base); - } -} - -u8 PHY_GetRateSectionIndexOfTxPowerByRate( - struct adapter *padapter, u32 RegAddr, u32 BitMask -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - u8 index = 0; - - if (pDM_Odm->PhyRegPgVersion == 0) { - switch (RegAddr) { - case rTxAGC_A_Rate18_06: - index = 0; - break; - case rTxAGC_A_Rate54_24: - index = 1; - break; - case rTxAGC_A_CCK1_Mcs32: - index = 6; - break; - case rTxAGC_B_CCK11_A_CCK2_11: - if (BitMask == bMaskH3Bytes) - index = 7; - else if (BitMask == 0x000000ff) - index = 15; - break; - - case rTxAGC_A_Mcs03_Mcs00: - index = 2; - break; - case rTxAGC_A_Mcs07_Mcs04: - index = 3; - break; - case rTxAGC_B_Rate18_06: - index = 8; - break; - case rTxAGC_B_Rate54_24: - index = 9; - break; - case rTxAGC_B_CCK1_55_Mcs32: - index = 14; - break; - case rTxAGC_B_Mcs03_Mcs00: - index = 10; - break; - case rTxAGC_B_Mcs07_Mcs04: - index = 11; - break; - default: - break; - } - } - - return index; -} - -void -PHY_GetRateValuesOfTxPowerByRate( - struct adapter *padapter, - u32 RegAddr, - u32 BitMask, - u32 Value, - u8 *RateIndex, - s8 *PwrByRateVal, - u8 *RateNum -) -{ - u8 i = 0; - - switch (RegAddr) { - case rTxAGC_A_Rate18_06: - case rTxAGC_B_Rate18_06: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_6M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_9M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_12M); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_18M); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case rTxAGC_A_Rate54_24: - case rTxAGC_B_Rate54_24: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_24M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_36M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_48M); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_54M); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case rTxAGC_A_CCK1_Mcs32: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M); - PwrByRateVal[0] = (s8) ((((Value >> (8 + 4)) & 0xF)) * 10 + - ((Value >> 8) & 0xF)); - *RateNum = 1; - break; - - case rTxAGC_B_CCK11_A_CCK2_11: - if (BitMask == 0xffffff00) { - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M); - for (i = 1; i < 4; ++i) { - PwrByRateVal[i - 1] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 3; - } else if (BitMask == 0x000000ff) { - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M); - PwrByRateVal[0] = (s8) ((((Value >> 4) & 0xF)) * 10 + (Value & 0xF)); - *RateNum = 1; - } - break; - - case rTxAGC_A_Mcs03_Mcs00: - case rTxAGC_B_Mcs03_Mcs00: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS0); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS1); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS2); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS3); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case rTxAGC_A_Mcs07_Mcs04: - case rTxAGC_B_Mcs07_Mcs04: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS4); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS5); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS6); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS7); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case rTxAGC_B_CCK1_55_Mcs32: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M); - for (i = 1; i < 4; ++i) { - PwrByRateVal[i - 1] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 3; - break; - - case 0xC20: - case 0xE20: - case 0x1820: - case 0x1a20: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_1M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_2M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_5_5M); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_11M); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case 0xC24: - case 0xE24: - case 0x1824: - case 0x1a24: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_6M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_9M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_12M); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_18M); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case 0xC28: - case 0xE28: - case 0x1828: - case 0x1a28: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_24M); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_36M); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_48M); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_54M); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case 0xC2C: - case 0xE2C: - case 0x182C: - case 0x1a2C: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS0); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS1); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS2); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS3); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - case 0xC30: - case 0xE30: - case 0x1830: - case 0x1a30: - RateIndex[0] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS4); - RateIndex[1] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS5); - RateIndex[2] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS6); - RateIndex[3] = PHY_GetRateIndexOfTxPowerByRate(MGN_MCS7); - for (i = 0; i < 4; ++i) { - PwrByRateVal[i] = (s8) ((((Value >> (i * 8 + 4)) & 0xF)) * 10 + - ((Value >> (i * 8)) & 0xF)); - } - *RateNum = 4; - break; - - default: - break; - } -} - -static void PHY_StoreTxPowerByRateNew(struct adapter *padapter, u32 RfPath, - u32 RegAddr, u32 BitMask, u32 Data) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 i = 0, rateIndex[4] = {0}, rateNum = 0; - s8 PwrByRateVal[4] = {0}; - - PHY_GetRateValuesOfTxPowerByRate(padapter, RegAddr, BitMask, Data, rateIndex, PwrByRateVal, &rateNum); - - if (RfPath >= RF_PATH_MAX) - return; - - for (i = 0; i < rateNum; ++i) { - pHalData->TxPwrByRateOffset[RfPath][rateIndex[i]] = PwrByRateVal[i]; - } -} - -void PHY_InitTxPowerByRate(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 rfPath, rate; - - for (rfPath = RF_PATH_A; rfPath < MAX_RF_PATH_NUM; ++rfPath) - for (rate = 0; rate < TX_PWR_BY_RATE_NUM_RATE; ++rate) - pHalData->TxPwrByRateOffset[rfPath][rate] = 0; -} - -void PHY_StoreTxPowerByRate( - struct adapter *padapter, - u32 RfPath, - u32 RegAddr, - u32 BitMask, - u32 Data -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - if (pDM_Odm->PhyRegPgVersion > 0) - PHY_StoreTxPowerByRateNew(padapter, RfPath, RegAddr, BitMask, Data); -} - -static void -phy_ConvertTxPowerByRateInDbmToRelativeValues( -struct adapter *padapter - ) -{ - u8 base = 0, i = 0, value = 0, path = 0; - u8 cckRates[4] = { - MGN_1M, MGN_2M, MGN_5_5M, MGN_11M - }; - u8 ofdmRates[8] = { - MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M - }; - u8 mcs0_7Rates[8] = { - MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7 - }; - for (path = RF_PATH_A; path < RF_PATH_MAX; ++path) { - /* CCK */ - base = PHY_GetTxPowerByRate(padapter, path, MGN_11M); - for (i = 0; i < ARRAY_SIZE(cckRates); ++i) { - value = PHY_GetTxPowerByRate(padapter, path, cckRates[i]); - PHY_SetTxPowerByRate(padapter, path, cckRates[i], value - base); - } - - /* OFDM */ - base = PHY_GetTxPowerByRate(padapter, path, MGN_54M); - for (i = 0; i < sizeof(ofdmRates); ++i) { - value = PHY_GetTxPowerByRate(padapter, path, ofdmRates[i]); - PHY_SetTxPowerByRate(padapter, path, ofdmRates[i], value - base); - } - - /* HT MCS0~7 */ - base = PHY_GetTxPowerByRate(padapter, path, MGN_MCS7); - for (i = 0; i < sizeof(mcs0_7Rates); ++i) { - value = PHY_GetTxPowerByRate(padapter, path, mcs0_7Rates[i]); - PHY_SetTxPowerByRate(padapter, path, mcs0_7Rates[i], value - base); - } - } -} - -/* - * This function must be called if the value in the PHY_REG_PG.txt(or header) - * is exact dBm values - */ -void PHY_TxPowerByRateConfiguration(struct adapter *padapter) -{ - phy_StoreTxPowerByRateBase(padapter); - phy_ConvertTxPowerByRateInDbmToRelativeValues(padapter); -} - -void PHY_SetTxPowerIndexByRateSection( - struct adapter *padapter, u8 RFPath, u8 Channel, u8 RateSection -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - if (RateSection == CCK) { - u8 cckRates[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M}; - - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, - pHalData->CurrentChannelBW, - Channel, cckRates, - ARRAY_SIZE(cckRates)); - - } else if (RateSection == OFDM) { - u8 ofdmRates[] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M}; - - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, - pHalData->CurrentChannelBW, - Channel, ofdmRates, - ARRAY_SIZE(ofdmRates)); - - } else if (RateSection == HT_MCS0_MCS7) { - u8 htRates1T[] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7}; - - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, - pHalData->CurrentChannelBW, - Channel, htRates1T, - ARRAY_SIZE(htRates1T)); - - } -} - -u8 PHY_GetTxPowerIndexBase( - struct adapter *padapter, - u8 RFPath, - u8 Rate, - enum channel_width BandWidth, - u8 Channel -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 txPower = 0; - u8 chnlIdx = (Channel - 1); - - if (!HAL_IsLegalChannel(padapter, Channel)) - chnlIdx = 0; - - if (IS_CCK_RATE(Rate)) - txPower = pHalData->Index24G_CCK_Base[RFPath][chnlIdx]; - else if (Rate >= MGN_6M) - txPower = pHalData->Index24G_BW40_Base[RFPath][chnlIdx]; - - /* OFDM-1T */ - if ((Rate >= MGN_6M && Rate <= MGN_54M) && !IS_CCK_RATE(Rate)) - txPower += pHalData->OFDM_24G_Diff[RFPath][TX_1S]; - - if (Rate >= MGN_MCS0 && Rate <= MGN_MCS7) { - if (BandWidth == CHANNEL_WIDTH_20) /* BW20-1S, BW20-2S */ - txPower += pHalData->BW20_24G_Diff[RFPath][TX_1S]; - else if (BandWidth == CHANNEL_WIDTH_40) /* BW40-1S, BW40-2S */ - txPower += pHalData->BW40_24G_Diff[RFPath][TX_1S]; - } - - return txPower; -} - -s8 PHY_GetTxPowerTrackingOffset(struct adapter *padapter, u8 RFPath, u8 Rate) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - s8 offset = 0; - - if (!pDM_Odm->RFCalibrateInfo.TxPowerTrackControl) - return offset; - - if ((Rate == MGN_1M) || (Rate == MGN_2M) || (Rate == MGN_5_5M) || (Rate == MGN_11M)) - offset = pDM_Odm->Remnant_CCKSwingIdx; - else - offset = pDM_Odm->Remnant_OFDMSwingIdx[RFPath]; - - return offset; -} - -u8 PHY_GetRateIndexOfTxPowerByRate(u8 Rate) -{ - u8 index = 0; - - switch (Rate) { - case MGN_1M: - index = 0; - break; - case MGN_2M: - index = 1; - break; - case MGN_5_5M: - index = 2; - break; - case MGN_11M: - index = 3; - break; - case MGN_6M: - index = 4; - break; - case MGN_9M: - index = 5; - break; - case MGN_12M: - index = 6; - break; - case MGN_18M: - index = 7; - break; - case MGN_24M: - index = 8; - break; - case MGN_36M: - index = 9; - break; - case MGN_48M: - index = 10; - break; - case MGN_54M: - index = 11; - break; - case MGN_MCS0: - index = 12; - break; - case MGN_MCS1: - index = 13; - break; - case MGN_MCS2: - index = 14; - break; - case MGN_MCS3: - index = 15; - break; - case MGN_MCS4: - index = 16; - break; - case MGN_MCS5: - index = 17; - break; - case MGN_MCS6: - index = 18; - break; - case MGN_MCS7: - index = 19; - break; - default: - break; - } - return index; -} - -s8 PHY_GetTxPowerByRate(struct adapter *padapter, u8 RFPath, u8 Rate) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - s8 value = 0; - u8 rateIndex = PHY_GetRateIndexOfTxPowerByRate(Rate); - - if ((padapter->registrypriv.reg_enable_tx_power_by_rate == 2 && - pHalData->EEPROMRegulatory == 2) || - padapter->registrypriv.reg_enable_tx_power_by_rate == 0) - return 0; - - if (RFPath >= RF_PATH_MAX) - return value; - - if (rateIndex >= TX_PWR_BY_RATE_NUM_RATE) - return value; - - return pHalData->TxPwrByRateOffset[RFPath][rateIndex]; - -} - -void PHY_SetTxPowerByRate( - struct adapter *padapter, - u8 RFPath, - u8 Rate, - s8 Value -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 rateIndex = PHY_GetRateIndexOfTxPowerByRate(Rate); - - if (RFPath >= RF_PATH_MAX) - return; - - if (rateIndex >= TX_PWR_BY_RATE_NUM_RATE) - return; - - pHalData->TxPwrByRateOffset[RFPath][rateIndex] = Value; -} - -void PHY_SetTxPowerLevelByPath(struct adapter *Adapter, u8 channel, u8 path) -{ - PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, CCK); - - PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, OFDM); - PHY_SetTxPowerIndexByRateSection(Adapter, path, channel, HT_MCS0_MCS7); -} - -void PHY_SetTxPowerIndexByRateArray( - struct adapter *padapter, - u8 RFPath, - enum channel_width BandWidth, - u8 Channel, - u8 *Rates, - u8 RateArraySize -) -{ - u32 powerIndex = 0; - int i = 0; - - for (i = 0; i < RateArraySize; ++i) { - powerIndex = PHY_GetTxPowerIndex(padapter, RFPath, Rates[i], BandWidth, Channel); - PHY_SetTxPowerIndex(padapter, powerIndex, RFPath, Rates[i]); - } -} - -static s8 phy_GetWorldWideLimit(s8 *LimitTable) -{ - s8 min = LimitTable[0]; - u8 i = 0; - - for (i = 0; i < MAX_REGULATION_NUM; ++i) { - if (LimitTable[i] < min) - min = LimitTable[i]; - } - - return min; -} - -static s8 phy_GetChannelIndexOfTxPowerLimit(u8 Channel) -{ - return Channel - 1; -} - -static s16 get_bandwidth_idx(const enum channel_width bandwidth) -{ - switch (bandwidth) { - case CHANNEL_WIDTH_20: - return 0; - case CHANNEL_WIDTH_40: - return 1; - default: - return -1; - } -} - -static s16 get_rate_sctn_idx(const u8 rate) -{ - switch (rate) { - case MGN_1M: case MGN_2M: case MGN_5_5M: case MGN_11M: - return 0; - case MGN_6M: case MGN_9M: case MGN_12M: case MGN_18M: - case MGN_24M: case MGN_36M: case MGN_48M: case MGN_54M: - return 1; - case MGN_MCS0: case MGN_MCS1: case MGN_MCS2: case MGN_MCS3: - case MGN_MCS4: case MGN_MCS5: case MGN_MCS6: case MGN_MCS7: - return 2; - default: - return -1; - } -} - -s8 phy_get_tx_pwr_lmt(struct adapter *adapter, u32 reg_pwr_tbl_sel, - enum channel_width bandwidth, - u8 rf_path, u8 data_rate, u8 channel) -{ - s16 idx_regulation = -1; - s16 idx_bandwidth = -1; - s16 idx_rate_sctn = -1; - s16 idx_channel = -1; - s8 pwr_lmt = MAX_POWER_INDEX; - struct hal_com_data *hal_data = GET_HAL_DATA(adapter); - s8 limits[10] = {0}; u8 i = 0; - - if (((adapter->registrypriv.reg_enable_tx_power_limit == 2) && - (hal_data->EEPROMRegulatory != 1)) || - (adapter->registrypriv.reg_enable_tx_power_limit == 0)) - return MAX_POWER_INDEX; - - switch (adapter->registrypriv.reg_pwr_tbl_sel) { - case 1: - idx_regulation = TXPWR_LMT_ETSI; - break; - case 2: - idx_regulation = TXPWR_LMT_MKK; - break; - case 3: - idx_regulation = TXPWR_LMT_FCC; - break; - case 4: - idx_regulation = TXPWR_LMT_WW; - break; - default: - idx_regulation = hal_data->Regulation2_4G; - break; - } - - idx_bandwidth = get_bandwidth_idx(bandwidth); - idx_rate_sctn = get_rate_sctn_idx(data_rate); - - /* workaround for wrong index combination to obtain tx power limit, */ - /* OFDM only exists in BW 20M */ - /* CCK table will only be given in BW 20M */ - /* HT on 80M will reference to HT on 40M */ - if (idx_rate_sctn == 0 || idx_rate_sctn == 1) - idx_bandwidth = 0; - - channel = phy_GetChannelIndexOfTxPowerLimit(channel); - - if (idx_regulation == -1 || idx_bandwidth == -1 || - idx_rate_sctn == -1 || idx_channel == -1) - return MAX_POWER_INDEX; - - for (i = 0; i < MAX_REGULATION_NUM; i++) - limits[i] = hal_data->TxPwrLimit_2_4G[i] - [idx_bandwidth] - [idx_rate_sctn] - [idx_channel] - [rf_path]; - - pwr_lmt = (idx_regulation == TXPWR_LMT_WW) ? - phy_GetWorldWideLimit(limits) : - hal_data->TxPwrLimit_2_4G[idx_regulation] - [idx_bandwidth] - [idx_rate_sctn] - [idx_channel] - [rf_path]; - - return pwr_lmt; -} - -void PHY_ConvertTxPowerLimitToPowerIndex(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct registry_priv *r = &Adapter->registrypriv; - u8 BW40PwrBasedBm2_4G = 0x2E; - u8 regulation, bw, channel, rateSection; - s8 tempValue = 0, tempPwrLmt = 0; - u8 rfPath = 0; - - for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) { - for (bw = 0; bw < MAX_2_4G_BANDWIDTH_NUM; ++bw) { - for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G; ++channel) { - for (rateSection = 0; rateSection < MAX_RATE_SECTION_NUM; ++rateSection) { - tempPwrLmt = pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][RF_PATH_A]; - - for (rfPath = RF_PATH_A; rfPath < MAX_RF_PATH_NUM; ++rfPath) { - if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) { - if (rateSection == 2) /* HT 1T */ - BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, rfPath, HT_MCS0_MCS7); - else if (rateSection == 1) /* OFDM */ - BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, rfPath, OFDM); - else if (rateSection == 0) /* CCK */ - BW40PwrBasedBm2_4G = PHY_GetTxPowerByRateBase(Adapter, rfPath, CCK); - } else - BW40PwrBasedBm2_4G = r->reg_power_base * 2; - - if (tempPwrLmt != MAX_POWER_INDEX) { - tempValue = tempPwrLmt - BW40PwrBasedBm2_4G; - pHalData->TxPwrLimit_2_4G[regulation][bw][rateSection][channel][rfPath] = tempValue; - } - } - } - } - } - } -} - -void PHY_InitTxPowerLimit(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u8 i, j, k, l, m; - - for (i = 0; i < MAX_REGULATION_NUM; ++i) { - for (j = 0; j < MAX_2_4G_BANDWIDTH_NUM; ++j) - for (k = 0; k < MAX_RATE_SECTION_NUM; ++k) - for (m = 0; m < CHANNEL_MAX_NUMBER_2G; ++m) - for (l = 0; l < MAX_RF_PATH_NUM; ++l) - pHalData->TxPwrLimit_2_4G[i][j][k][m][l] = MAX_POWER_INDEX; - } -} - -void PHY_SetTxPowerLimit( - struct adapter *Adapter, - u8 *Regulation, - u8 *Bandwidth, - u8 *RateSection, - u8 *RfPath, - u8 *Channel, - u8 *PowerLimit -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u8 regulation = 0, bandwidth = 0, rateSection = 0, channel; - s8 powerLimit = 0, prevPowerLimit, channelIndex; - - GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel); - GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit); - - powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit; - - if (strcmp(Regulation, "FCC") == 0) - regulation = 0; - else if (strcmp(Regulation, "MKK") == 0) - regulation = 1; - else if (strcmp(Regulation, "ETSI") == 0) - regulation = 2; - else if (strcmp(Regulation, "WW13") == 0) - regulation = 3; - - if (strcmp(RateSection, "CCK") == 0 && strcmp(RfPath, "1T") == 0) - rateSection = 0; - else if (strcmp(RateSection, "OFDM") == 0 && strcmp(RfPath, "1T") == 0) - rateSection = 1; - else if (strcmp(RateSection, "HT") == 0 && strcmp(RfPath, "1T") == 0) - rateSection = 2; - else - return; - - if (strcmp(Bandwidth, "20M") == 0) - bandwidth = 0; - else if (strcmp(Bandwidth, "40M") == 0) - bandwidth = 1; - - channelIndex = phy_GetChannelIndexOfTxPowerLimit(channel); - - if (channelIndex == -1) - return; - - prevPowerLimit = pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][RF_PATH_A]; - - if (powerLimit < prevPowerLimit) - pHalData->TxPwrLimit_2_4G[regulation][bandwidth][rateSection][channelIndex][RF_PATH_A] = powerLimit; -} - -void Hal_ChannelPlanToRegulation(struct adapter *Adapter, u16 ChannelPlan) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - pHalData->Regulation2_4G = TXPWR_LMT_WW; - - switch (ChannelPlan) { - case RT_CHANNEL_DOMAIN_WORLD_NULL: - pHalData->Regulation2_4G = TXPWR_LMT_WW; - break; - case RT_CHANNEL_DOMAIN_ETSI1_NULL: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_NULL: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_MKK1_NULL: - pHalData->Regulation2_4G = TXPWR_LMT_MKK; - break; - case RT_CHANNEL_DOMAIN_ETSI2_NULL: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_FCC1: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI1: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_MKK1_MKK1: - pHalData->Regulation2_4G = TXPWR_LMT_MKK; - break; - case RT_CHANNEL_DOMAIN_WORLD_KCC1: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_FCC2: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_FCC3: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_FCC4: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_FCC5: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_FCC6: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_FCC1_FCC7: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI2: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI3: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_MKK1_MKK2: - pHalData->Regulation2_4G = TXPWR_LMT_MKK; - break; - case RT_CHANNEL_DOMAIN_MKK1_MKK3: - pHalData->Regulation2_4G = TXPWR_LMT_MKK; - break; - case RT_CHANNEL_DOMAIN_FCC1_NCC1: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_FCC1_NCC2: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_GLOBAL_NULL: - pHalData->Regulation2_4G = TXPWR_LMT_WW; - break; - case RT_CHANNEL_DOMAIN_ETSI1_ETSI4: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_FCC2: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_FCC1_NCC3: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI5: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_FCC8: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI6: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI7: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI8: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI9: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI10: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI11: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_NCC4: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI12: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_FCC9: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_WORLD_ETSI13: - pHalData->Regulation2_4G = TXPWR_LMT_ETSI; - break; - case RT_CHANNEL_DOMAIN_FCC1_FCC10: - pHalData->Regulation2_4G = TXPWR_LMT_FCC; - break; - case RT_CHANNEL_DOMAIN_REALTEK_DEFINE: /* Realtek Reserve */ - pHalData->Regulation2_4G = TXPWR_LMT_WW; - break; - default: - break; - } -} diff --git a/drivers/staging/rtl8723bs/hal/hal_intf.c b/drivers/staging/rtl8723bs/hal/hal_intf.c deleted file mode 100644 index 2caade1a8bdd..000000000000 --- a/drivers/staging/rtl8723bs/hal/hal_intf.c +++ /dev/null @@ -1,283 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include - -static void rtw_hal_init_opmode(struct adapter *padapter) -{ - enum nl80211_iftype networkType = NL80211_IFTYPE_UNSPECIFIED; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - signed int fw_state; - - fw_state = get_fwstate(pmlmepriv); - - if (fw_state & WIFI_ADHOC_STATE) - networkType = NL80211_IFTYPE_ADHOC; - else if (fw_state & WIFI_STATION_STATE) - networkType = NL80211_IFTYPE_STATION; - else if (fw_state & WIFI_AP_STATE) - networkType = NL80211_IFTYPE_AP; - else - return; - - rtw_setopmode_cmd(padapter, networkType, false); -} - -uint rtw_hal_init(struct adapter *padapter) -{ - uint status; - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - - status = rtl8723bs_hal_init(padapter); - - if (status == _SUCCESS) { - rtw_hal_init_opmode(padapter); - - dvobj->padapters->hw_init_completed = true; - - if (padapter->registrypriv.notch_filter == 1) - rtw_hal_notch_filter(padapter, 1); - - rtw_sec_restore_wep_key(dvobj->padapters); - - init_hw_mlme_ext(padapter); - - rtw_bb_rf_gain_offset(padapter); - } else { - dvobj->padapters->hw_init_completed = false; - } - - return status; -} - -uint rtw_hal_deinit(struct adapter *padapter) -{ - uint status = _SUCCESS; - struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); - - status = rtl8723bs_hal_deinit(padapter); - - if (status == _SUCCESS) { - padapter = dvobj->padapters; - padapter->hw_init_completed = false; - } - - return status; -} - -void rtw_hal_set_hwreg(struct adapter *padapter, u8 variable, u8 *val) -{ - SetHwReg8723BS(padapter, variable, val); -} - -void rtw_hal_get_hwreg(struct adapter *padapter, u8 variable, u8 *val) -{ - GetHwReg8723BS(padapter, variable, val); -} - -void rtw_hal_set_hwreg_with_buf(struct adapter *padapter, u8 variable, u8 *pbuf, int len) -{ - SetHwRegWithBuf8723B(padapter, variable, pbuf, len); -} - -u8 rtw_hal_get_def_var(struct adapter *padapter, enum hal_def_variable eVariable, void *pValue) -{ - return GetHalDefVar8723BSDIO(padapter, eVariable, pValue); -} - -void rtw_hal_set_odm_var(struct adapter *padapter, enum hal_odm_variable eVariable, void *pValue1, bool bSet) -{ - SetHalODMVar(padapter, eVariable, pValue1, bSet); -} - -u8 rtw_hal_check_ips_status(struct adapter *padapter) -{ - return CheckIPSStatus(padapter); -} - -int rtw_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - return rtl8723bs_hal_xmitframe_enqueue(padapter, pxmitframe); -} - -s32 rtw_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe) -{ - if (rtl8723bs_hal_xmit(padapter, pxmitframe)) - return _FAIL; - - return _SUCCESS; -} - -/* - * [IMPORTANT] This function would be run in interrupt context. - */ -s32 rtw_hal_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe) -{ - update_mgntframe_attrib_addr(padapter, pmgntframe); - /* pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; */ - /* pwlanhdr = (struct rtw_ieee80211_hdr *)pframe; */ - /* memcpy(pmgntframe->attrib.ra, pwlanhdr->addr1, ETH_ALEN); */ - - if (padapter->securitypriv.binstallBIPkey) { - if (is_multicast_ether_addr(pmgntframe->attrib.ra)) { - pmgntframe->attrib.encrypt = _BIP_; - /* pmgntframe->attrib.bswenc = true; */ - } else { - pmgntframe->attrib.encrypt = _AES_; - pmgntframe->attrib.bswenc = true; - } - rtw_mgmt_xmitframe_coalesce(padapter, pmgntframe->pkt, pmgntframe); - } - - return rtl8723bs_mgnt_xmit(padapter, pmgntframe); -} - -s32 rtw_hal_init_xmit_priv(struct adapter *padapter) -{ - return rtl8723bs_init_xmit_priv(padapter); -} - -void rtw_hal_free_xmit_priv(struct adapter *padapter) -{ - rtl8723bs_free_xmit_priv(padapter); -} - -s32 rtw_hal_init_recv_priv(struct adapter *padapter) -{ - return rtl8723bs_init_recv_priv(padapter); -} - -void rtw_hal_free_recv_priv(struct adapter *padapter) -{ - rtl8723bs_free_recv_priv(padapter); -} - -void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level) -{ - struct adapter *padapter; - struct mlme_priv *pmlmepriv; - - if (!psta) - return; - - padapter = psta->padapter; - - pmlmepriv = &(padapter->mlmepriv); - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - add_ratid(padapter, psta, rssi_level); - else - UpdateHalRAMask8723B(padapter, psta->mac_id, rssi_level); -} - -void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level) -{ - rtl8723b_Add_RateATid(padapter, bitmap, arg, rssi_level); -} - -u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask) -{ - return PHY_QueryBBReg_8723B(padapter, RegAddr, BitMask); -} -void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data) -{ - PHY_SetBBReg_8723B(padapter, RegAddr, BitMask, Data); -} - -u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask) -{ - return PHY_QueryRFReg_8723B(padapter, eRFPath, RegAddr, BitMask); -} -void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data) -{ - PHY_SetRFReg_8723B(padapter, eRFPath, RegAddr, BitMask, Data); -} - -void rtw_hal_set_chan(struct adapter *padapter, u8 channel) -{ - PHY_SwChnl8723B(padapter, channel); -} - -void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel, - enum channel_width Bandwidth, u8 Offset40, u8 Offset80) -{ - PHY_SetSwChnlBWMode8723B(padapter, channel, Bandwidth, Offset40, Offset80); -} - -void rtw_hal_dm_watchdog(struct adapter *padapter) -{ - rtl8723b_HalDmWatchDog(padapter); -} - -void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter) -{ - if (adapter_to_pwrctl(padapter)->fw_current_in_ps_mode) - rtl8723b_HalDmWatchDog_in_LPS(padapter); /* this function caller is in interrupt context */ -} - -void beacon_timing_control(struct adapter *padapter) -{ - rtl8723b_SetBeaconRelatedRegisters(padapter); -} - -s32 rtw_hal_xmit_thread_handler(struct adapter *padapter) -{ - return rtl8723bs_xmit_buf_handler(padapter); -} - -void rtw_hal_notch_filter(struct adapter *adapter, bool enable) -{ - hal_notch_filter_8723b(adapter, enable); -} - -bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf) -{ - return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf); -} - -s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt) -{ - return c2h_handler_8723b(adapter, c2h_evt); -} - -c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter) -{ - return c2h_id_filter_ccx_8723b; -} - -s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid) -{ - u8 support; - - support = false; - rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support); - if (false == support) - return _FAIL; - - rtw_hal_set_hwreg(padapter, HW_VAR_MACID_SLEEP, (u8 *)&macid); - - return _SUCCESS; -} - -s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid) -{ - u8 support; - - support = false; - rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support); - if (false == support) - return _FAIL; - - rtw_hal_set_hwreg(padapter, HW_VAR_MACID_WAKEUP, (u8 *)&macid); - - return _SUCCESS; -} - -s32 rtw_hal_fill_h2c_cmd(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer) -{ - return FillH2CCmd8723B(padapter, ElementID, CmdLen, pCmdBuffer); -} diff --git a/drivers/staging/rtl8723bs/hal/hal_pwr_seq.c b/drivers/staging/rtl8723bs/hal/hal_pwr_seq.c deleted file mode 100644 index 0b60eba128af..000000000000 --- a/drivers/staging/rtl8723bs/hal/hal_pwr_seq.c +++ /dev/null @@ -1,128 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -/* - * This file includes all kinds of Power Action event for RTL8723B - * and corresponding hardware configurations which are released from HW SD. - * - * Major Change History: - * When Who What - * ---------- --------------- ------------------------------- - * 2011-08-08 Roger Create. - */ - -#include "hal_pwr_seq.h" - -/* drivers should parse below arrays and do the corresponding actions */ -/* 3 Power on Array */ -struct wlan_pwr_cfg rtl8723B_power_on_flow[ - RTL8723B_TRANS_CARDEMU_TO_ACT_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_CARDEMU_TO_ACT - RTL8723B_TRANS_END -}; - -/* 3Radio off GPIO Array */ -struct wlan_pwr_cfg rtl8723B_radio_off_flow[ - RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_ACT_TO_CARDEMU - RTL8723B_TRANS_END -}; - -/* 3Card Disable Array */ -struct wlan_pwr_cfg rtl8723B_card_disable_flow[ - RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+ - RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_ACT_TO_CARDEMU - RTL8723B_TRANS_CARDEMU_TO_CARDDIS - RTL8723B_TRANS_END -}; - -/* 3 Card Enable Array */ -struct wlan_pwr_cfg rtl8723B_card_enable_flow[ - RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+ - RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_CARDDIS_TO_CARDEMU - RTL8723B_TRANS_CARDEMU_TO_ACT - RTL8723B_TRANS_END -}; - -/* 3Suspend Array */ -struct wlan_pwr_cfg rtl8723B_suspend_flow[ - RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+ - RTL8723B_TRANS_CARDEMU_TO_SUS_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_ACT_TO_CARDEMU - RTL8723B_TRANS_CARDEMU_TO_SUS - RTL8723B_TRANS_END -}; - -/* 3 Resume Array */ -struct wlan_pwr_cfg rtl8723B_resume_flow[ - RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+ - RTL8723B_TRANS_CARDEMU_TO_SUS_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_SUS_TO_CARDEMU - RTL8723B_TRANS_CARDEMU_TO_ACT - RTL8723B_TRANS_END -}; - -/* 3HWPDN Array */ -struct wlan_pwr_cfg rtl8723B_hwpdn_flow[ - RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+ - RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS+ - RTL8723B_TRANS_END_STEPS -] = { - RTL8723B_TRANS_ACT_TO_CARDEMU - RTL8723B_TRANS_CARDEMU_TO_PDN - RTL8723B_TRANS_END -}; - -/* 3 Enter LPS */ -struct wlan_pwr_cfg rtl8723B_enter_lps_flow[ - RTL8723B_TRANS_ACT_TO_LPS_STEPS+RTL8723B_TRANS_END_STEPS -] = { - /* FW behavior */ - RTL8723B_TRANS_ACT_TO_LPS - RTL8723B_TRANS_END -}; - -/* 3 Leave LPS */ -struct wlan_pwr_cfg rtl8723B_leave_lps_flow[ - RTL8723B_TRANS_LPS_TO_ACT_STEPS+RTL8723B_TRANS_END_STEPS -] = { - /* FW behavior */ - RTL8723B_TRANS_LPS_TO_ACT - RTL8723B_TRANS_END -}; - -/* 3 Enter SW LPS */ -struct wlan_pwr_cfg rtl8723B_enter_swlps_flow[ - RTL8723B_TRANS_ACT_TO_SWLPS_STEPS+RTL8723B_TRANS_END_STEPS -] = { - /* SW behavior */ - RTL8723B_TRANS_ACT_TO_SWLPS - RTL8723B_TRANS_END -}; - -/* 3 Leave SW LPS */ -struct wlan_pwr_cfg rtl8723B_leave_swlps_flow[ - RTL8723B_TRANS_SWLPS_TO_ACT_STEPS+RTL8723B_TRANS_END_STEPS -] = { - /* SW behavior */ - RTL8723B_TRANS_SWLPS_TO_ACT - RTL8723B_TRANS_END -}; diff --git a/drivers/staging/rtl8723bs/hal/hal_sdio.c b/drivers/staging/rtl8723bs/hal/hal_sdio.c deleted file mode 100644 index 7cead9664c99..000000000000 --- a/drivers/staging/rtl8723bs/hal/hal_sdio.c +++ /dev/null @@ -1,100 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include - -u8 rtw_hal_sdio_max_txoqt_free_space(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - if (pHalData->SdioTxOQTMaxFreeSpace < 8) - pHalData->SdioTxOQTMaxFreeSpace = 8; - - return pHalData->SdioTxOQTMaxFreeSpace; -} - -u8 rtw_hal_sdio_query_tx_freepage( - struct adapter *padapter, u8 PageIdx, u8 RequiredPageNum -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - if ((pHalData->SdioTxFIFOFreePage[PageIdx] + pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]) >= (RequiredPageNum)) - return true; - else - return false; -} - -void rtw_hal_sdio_update_tx_freepage( - struct adapter *padapter, u8 PageIdx, u8 RequiredPageNum -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 DedicatedPgNum = 0; - u8 RequiredPublicFreePgNum = 0; - /* _irqL irql; */ - - DedicatedPgNum = pHalData->SdioTxFIFOFreePage[PageIdx]; - if (RequiredPageNum <= DedicatedPgNum) { - pHalData->SdioTxFIFOFreePage[PageIdx] -= RequiredPageNum; - } else { - pHalData->SdioTxFIFOFreePage[PageIdx] = 0; - RequiredPublicFreePgNum = RequiredPageNum - DedicatedPgNum; - pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX] -= RequiredPublicFreePgNum; - } -} - -void rtw_hal_set_sdio_tx_max_length( - struct adapter *padapter, u8 numHQ, u8 numNQ, u8 numLQ, u8 numPubQ -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u32 page_size; - u32 lenHQ, lenNQ, lenLQ; - - rtw_hal_get_def_var(padapter, HAL_DEF_TX_PAGE_SIZE, &page_size); - - lenHQ = ((numHQ + numPubQ) >> 1) * page_size; - lenNQ = ((numNQ + numPubQ) >> 1) * page_size; - lenLQ = ((numLQ + numPubQ) >> 1) * page_size; - - pHalData->sdio_tx_max_len[HI_QUEUE_IDX] = - (lenHQ > MAX_XMITBUF_SZ) ? MAX_XMITBUF_SZ : lenHQ; - pHalData->sdio_tx_max_len[MID_QUEUE_IDX] = - (lenNQ > MAX_XMITBUF_SZ) ? MAX_XMITBUF_SZ : lenNQ; - pHalData->sdio_tx_max_len[LOW_QUEUE_IDX] = - (lenLQ > MAX_XMITBUF_SZ) ? MAX_XMITBUF_SZ : lenLQ; -} - -u32 rtw_hal_get_sdio_tx_max_length(struct adapter *padapter, u8 queue_idx) -{ - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u32 deviceId, max_len; - - deviceId = ffaddr2deviceId(pdvobjpriv, queue_idx); - switch (deviceId) { - case WLAN_TX_HIQ_DEVICE_ID: - max_len = pHalData->sdio_tx_max_len[HI_QUEUE_IDX]; - break; - - case WLAN_TX_MIQ_DEVICE_ID: - max_len = pHalData->sdio_tx_max_len[MID_QUEUE_IDX]; - break; - - case WLAN_TX_LOQ_DEVICE_ID: - max_len = pHalData->sdio_tx_max_len[LOW_QUEUE_IDX]; - break; - - default: - max_len = pHalData->sdio_tx_max_len[MID_QUEUE_IDX]; - break; - } - - return max_len; -} diff --git a/drivers/staging/rtl8723bs/hal/odm.c b/drivers/staging/rtl8723bs/hal/odm.c deleted file mode 100644 index d18df407e365..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm.c +++ /dev/null @@ -1,988 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -/* Global var */ - -u32 OFDMSwingTable_New[OFDM_TABLE_SIZE] = { - 0x0b40002d, /* 0, -15.0dB */ - 0x0c000030, /* 1, -14.5dB */ - 0x0cc00033, /* 2, -14.0dB */ - 0x0d800036, /* 3, -13.5dB */ - 0x0e400039, /* 4, -13.0dB */ - 0x0f00003c, /* 5, -12.5dB */ - 0x10000040, /* 6, -12.0dB */ - 0x11000044, /* 7, -11.5dB */ - 0x12000048, /* 8, -11.0dB */ - 0x1300004c, /* 9, -10.5dB */ - 0x14400051, /* 10, -10.0dB */ - 0x15800056, /* 11, -9.5dB */ - 0x16c0005b, /* 12, -9.0dB */ - 0x18000060, /* 13, -8.5dB */ - 0x19800066, /* 14, -8.0dB */ - 0x1b00006c, /* 15, -7.5dB */ - 0x1c800072, /* 16, -7.0dB */ - 0x1e400079, /* 17, -6.5dB */ - 0x20000080, /* 18, -6.0dB */ - 0x22000088, /* 19, -5.5dB */ - 0x24000090, /* 20, -5.0dB */ - 0x26000098, /* 21, -4.5dB */ - 0x288000a2, /* 22, -4.0dB */ - 0x2ac000ab, /* 23, -3.5dB */ - 0x2d4000b5, /* 24, -3.0dB */ - 0x300000c0, /* 25, -2.5dB */ - 0x32c000cb, /* 26, -2.0dB */ - 0x35c000d7, /* 27, -1.5dB */ - 0x390000e4, /* 28, -1.0dB */ - 0x3c8000f2, /* 29, -0.5dB */ - 0x40000100, /* 30, +0dB */ - 0x43c0010f, /* 31, +0.5dB */ - 0x47c0011f, /* 32, +1.0dB */ - 0x4c000130, /* 33, +1.5dB */ - 0x50800142, /* 34, +2.0dB */ - 0x55400155, /* 35, +2.5dB */ - 0x5a400169, /* 36, +3.0dB */ - 0x5fc0017f, /* 37, +3.5dB */ - 0x65400195, /* 38, +4.0dB */ - 0x6b8001ae, /* 39, +4.5dB */ - 0x71c001c7, /* 40, +5.0dB */ - 0x788001e2, /* 41, +5.5dB */ - 0x7f8001fe /* 42, +6.0dB */ -}; - -u8 CCKSwingTable_Ch1_Ch13_New[CCK_TABLE_SIZE][8] = { - {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */ - {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */ - {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */ - {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */ - {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */ - {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */ - {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */ - {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */ - {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */ - {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */ - {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */ - {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */ - {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */ - {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */ - {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ - {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */ - {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ - {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */ - {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ - {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */ - {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 20, -6.0dB */ - {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */ - {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ - {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */ - {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ - {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */ - {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */ - {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */ - {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ - {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */ - {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */ - {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */ - {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB */ -}; - -u8 CCKSwingTable_Ch14_New[CCK_TABLE_SIZE][8] = { - {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */ - {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */ - {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */ - {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */ - {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */ - {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */ - {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */ - {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */ - {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */ - {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */ - {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */ - {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */ - {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */ - {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */ - {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */ - {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */ - {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ - {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */ - {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ - {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ - {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ - {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */ - {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ - {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */ - {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ - {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ - {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ - {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */ - {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ - {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */ - {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ - {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ - {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */ -}; - -/* Remove Edca by Yu Chen */ - -static void odm_CommonInfoSelfInit(struct dm_odm_t *pDM_Odm) -{ - pDM_Odm->bCckHighPower = (bool) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(CCK_RPT_FORMAT), ODM_BIT(CCK_RPT_FORMAT)); - pDM_Odm->RFPathRxEnable = (u8) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(BB_RX_PATH), ODM_BIT(BB_RX_PATH)); - - pDM_Odm->TxRate = 0xFF; -} - -static void odm_CommonInfoSelfUpdate(struct dm_odm_t *pDM_Odm) -{ - u8 EntryCnt = 0; - u8 i; - PSTA_INFO_T pEntry; - - if (*(pDM_Odm->pBandWidth) == ODM_BW40M) { - if (*(pDM_Odm->pSecChOffset) == 1) - pDM_Odm->ControlChannel = *(pDM_Odm->pChannel)-2; - else if (*(pDM_Odm->pSecChOffset) == 2) - pDM_Odm->ControlChannel = *(pDM_Odm->pChannel)+2; - } else - pDM_Odm->ControlChannel = *(pDM_Odm->pChannel); - - for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) { - pEntry = pDM_Odm->pODM_StaInfo[i]; - if (IS_STA_VALID(pEntry)) - EntryCnt++; - } - - if (EntryCnt == 1) - pDM_Odm->bOneEntryOnly = true; - else - pDM_Odm->bOneEntryOnly = false; -} - -/* 3 ============================================================ */ -/* 3 RATR MASK */ -/* 3 ============================================================ */ -/* 3 ============================================================ */ -/* 3 Rate Adaptive */ -/* 3 ============================================================ */ - -static void odm_RateAdaptiveMaskInit(struct dm_odm_t *pDM_Odm) -{ - struct odm_rate_adaptive *pOdmRA = &pDM_Odm->RateAdaptive; - - pOdmRA->Type = DM_Type_ByDriver; - if (pOdmRA->Type == DM_Type_ByDriver) - pDM_Odm->bUseRAMask = true; - else - pDM_Odm->bUseRAMask = false; - - pOdmRA->RATRState = DM_RATR_STA_INIT; - pOdmRA->LdpcThres = 35; - pOdmRA->bUseLdpc = false; - pOdmRA->HighRSSIThresh = 50; - pOdmRA->LowRSSIThresh = 20; -} - -u32 ODM_Get_Rate_Bitmap( - struct dm_odm_t *pDM_Odm, - u32 macid, - u32 ra_mask, - u8 rssi_level -) -{ - PSTA_INFO_T pEntry; - u32 rate_bitmap = 0; - u8 WirelessMode; - - pEntry = pDM_Odm->pODM_StaInfo[macid]; - if (!IS_STA_VALID(pEntry)) - return ra_mask; - - WirelessMode = pEntry->wireless_mode; - - switch (WirelessMode) { - case ODM_WM_B: - if (ra_mask & 0x0000000c) /* 11M or 5.5M enable */ - rate_bitmap = 0x0000000d; - else - rate_bitmap = 0x0000000f; - break; - - case (ODM_WM_G): - if (rssi_level == DM_RATR_STA_HIGH) - rate_bitmap = 0x00000f00; - else - rate_bitmap = 0x00000ff0; - break; - - case (ODM_WM_B|ODM_WM_G): - if (rssi_level == DM_RATR_STA_HIGH) - rate_bitmap = 0x00000f00; - else if (rssi_level == DM_RATR_STA_MIDDLE) - rate_bitmap = 0x00000ff0; - else - rate_bitmap = 0x00000ff5; - break; - - case (ODM_WM_B|ODM_WM_G|ODM_WM_N24G): - case (ODM_WM_B|ODM_WM_N24G): - case (ODM_WM_G|ODM_WM_N24G): - if (rssi_level == DM_RATR_STA_HIGH) - rate_bitmap = 0x000f0000; - else if (rssi_level == DM_RATR_STA_MIDDLE) - rate_bitmap = 0x000ff000; - else { - if (*(pDM_Odm->pBandWidth) == ODM_BW40M) - rate_bitmap = 0x000ff015; - else - rate_bitmap = 0x000ff005; - } - break; - - default: - rate_bitmap = 0x0fffffff; - break; - } - - return ra_mask & rate_bitmap; - -} - -static void odm_RefreshRateAdaptiveMaskCE(struct dm_odm_t *pDM_Odm) -{ - u8 i; - struct adapter *padapter = pDM_Odm->Adapter; - - if (padapter->driver_stopped) - return; - - if (!pDM_Odm->bUseRAMask) - return; - - for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) { - PSTA_INFO_T pstat = pDM_Odm->pODM_StaInfo[i]; - - if (IS_STA_VALID(pstat)) { - if (is_multicast_ether_addr(pstat->hwaddr)) /* if (psta->mac_id == 1) */ - continue; - - if (true == ODM_RAStateCheck(pDM_Odm, pstat->rssi_stat.UndecoratedSmoothedPWDB, false, &pstat->rssi_level)) { - rtw_hal_update_ra_mask(pstat, pstat->rssi_level); - } - - } - } -} - -/*----------------------------------------------------------------------------- - * Function: odm_RefreshRateAdaptiveMask() - * - * Overview: Update rate table mask according to rssi - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - *When Who Remark - *05/27/2009 hpfan Create Version 0. - * - * -------------------------------------------------------------------------- - */ -static void odm_RefreshRateAdaptiveMask(struct dm_odm_t *pDM_Odm) -{ - - if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK)) - return; - - odm_RefreshRateAdaptiveMaskCE(pDM_Odm); -} - -/* Return Value: bool */ -/* - true: RATRState is changed. */ -bool ODM_RAStateCheck( - struct dm_odm_t *pDM_Odm, - s32 RSSI, - bool bForceUpdate, - u8 *pRATRState -) -{ - struct odm_rate_adaptive *pRA = &pDM_Odm->RateAdaptive; - const u8 GoUpGap = 5; - u8 HighRSSIThreshForRA = pRA->HighRSSIThresh; - u8 LowRSSIThreshForRA = pRA->LowRSSIThresh; - u8 RATRState; - - /* Threshold Adjustment: */ - /* when RSSI state trends to go up one or two levels, make sure RSSI is high enough. */ - /* Here GoUpGap is added to solve the boundary's level alternation issue. */ - switch (*pRATRState) { - case DM_RATR_STA_INIT: - case DM_RATR_STA_HIGH: - break; - - case DM_RATR_STA_MIDDLE: - HighRSSIThreshForRA += GoUpGap; - break; - - case DM_RATR_STA_LOW: - HighRSSIThreshForRA += GoUpGap; - LowRSSIThreshForRA += GoUpGap; - break; - - default: - netdev_dbg(pDM_Odm->Adapter->pnetdev, - "wrong rssi level setting %d !", *pRATRState); - break; - } - - /* Decide RATRState by RSSI. */ - if (RSSI > HighRSSIThreshForRA) - RATRState = DM_RATR_STA_HIGH; - else if (RSSI > LowRSSIThreshForRA) - RATRState = DM_RATR_STA_MIDDLE; - else - RATRState = DM_RATR_STA_LOW; - - if (*pRATRState != RATRState || bForceUpdate) { - *pRATRState = RATRState; - return true; - } - - return false; -} - -/* */ - -/* 3 ============================================================ */ -/* 3 RSSI Monitor */ -/* 3 ============================================================ */ - -static void odm_RSSIMonitorInit(struct dm_odm_t *pDM_Odm) -{ - struct ra_t *pRA_Table = &pDM_Odm->DM_RA_Table; - - pRA_Table->firstconnect = false; - -} - -static void FindMinimumRSSI(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_priv *pdmpriv = &pHalData->dmpriv; - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - /* 1 1.Determine the minimum RSSI */ - - if (!pDM_Odm->bLinked && (pdmpriv->EntryMinUndecoratedSmoothedPWDB == 0)) - pdmpriv->MinUndecoratedPWDBForDM = 0; - else - pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB; -} - -static void odm_RSSIMonitorCheckCE(struct dm_odm_t *pDM_Odm) -{ - struct adapter *Adapter = pDM_Odm->Adapter; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_priv *pdmpriv = &pHalData->dmpriv; - int i; - int tmpEntryMaxPWDB = 0, tmpEntryMinPWDB = 0xff; - u8 sta_cnt = 0; - u32 PWDB_rssi[NUM_STA] = {0};/* 0~15]:MACID, [16~31]:PWDB_rssi */ - struct ra_t *pRA_Table = &pDM_Odm->DM_RA_Table; - - if (!pDM_Odm->bLinked) - return; - - pRA_Table->firstconnect = pDM_Odm->bLinked; - - /* if (check_fwstate(&Adapter->mlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == true) */ - { - struct sta_info *psta; - - for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) { - psta = pDM_Odm->pODM_StaInfo[i]; - if (IS_STA_VALID(psta)) { - if (is_multicast_ether_addr(psta->hwaddr)) /* if (psta->mac_id == 1) */ - continue; - - if (psta->rssi_stat.UndecoratedSmoothedPWDB == (-1)) - continue; - - if (psta->rssi_stat.UndecoratedSmoothedPWDB < tmpEntryMinPWDB) - tmpEntryMinPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB; - - if (psta->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB) - tmpEntryMaxPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB; - - if (psta->rssi_stat.UndecoratedSmoothedPWDB != (-1)) - PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16)); - } - } - - for (i = 0; i < sta_cnt; i++) { - if (PWDB_rssi[i] != (0)) { - if (pHalData->fw_ractrl)/* Report every sta's RSSI to FW */ - rtl8723b_set_rssi_cmd(Adapter, (u8 *)(&PWDB_rssi[i])); - } - } - } - - if (tmpEntryMaxPWDB != 0) /* If associated entry is found */ - pdmpriv->EntryMaxUndecoratedSmoothedPWDB = tmpEntryMaxPWDB; - else - pdmpriv->EntryMaxUndecoratedSmoothedPWDB = 0; - - if (tmpEntryMinPWDB != 0xff) /* If associated entry is found */ - pdmpriv->EntryMinUndecoratedSmoothedPWDB = tmpEntryMinPWDB; - else - pdmpriv->EntryMinUndecoratedSmoothedPWDB = 0; - - FindMinimumRSSI(Adapter);/* get pdmpriv->MinUndecoratedPWDBForDM */ - - pDM_Odm->RSSI_Min = pdmpriv->MinUndecoratedPWDBForDM; - /* ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */ -} - -static void odm_RSSIMonitorCheck(struct dm_odm_t *pDM_Odm) -{ - if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR)) - return; - - odm_RSSIMonitorCheckCE(pDM_Odm); - -} /* odm_RSSIMonitorCheck */ - -/* 3 ============================================================ */ -/* 3 SW Antenna Diversity */ -/* 3 ============================================================ */ -static void odm_SwAntDetectInit(struct dm_odm_t *pDM_Odm) -{ - struct swat_t *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table; - - pDM_SWAT_Table->SWAS_NoLink_BK_Reg92c = rtw_read32(pDM_Odm->Adapter, rDPDT_control); - pDM_SWAT_Table->PreAntenna = MAIN_ANT; - pDM_SWAT_Table->CurAntenna = MAIN_ANT; - pDM_SWAT_Table->SWAS_NoLink_State = 0; -} - -/* 3 ============================================================ */ -/* 3 Tx Power Tracking */ -/* 3 ============================================================ */ - -static u8 getSwingIndex(struct dm_odm_t *pDM_Odm) -{ - struct adapter *Adapter = pDM_Odm->Adapter; - u8 i = 0; - u32 bbSwing; - u32 swingTableSize; - u32 *pSwingTable; - - bbSwing = PHY_QueryBBReg(Adapter, rOFDM0_XATxIQImbalance, 0xFFC00000); - - pSwingTable = OFDMSwingTable_New; - swingTableSize = OFDM_TABLE_SIZE; - - for (i = 0; i < swingTableSize; ++i) { - u32 tableValue = pSwingTable[i]; - - if (tableValue >= 0x100000) - tableValue >>= 22; - if (bbSwing == tableValue) - break; - } - return i; -} - -void odm_TXPowerTrackingInit(struct dm_odm_t *pDM_Odm) -{ - u8 defaultSwingIndex = getSwingIndex(pDM_Odm); - u8 p = 0; - struct adapter *Adapter = pDM_Odm->Adapter; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - struct dm_priv *pdmpriv = &pHalData->dmpriv; - - pdmpriv->bTXPowerTracking = true; - pdmpriv->TXPowercount = 0; - pdmpriv->bTXPowerTrackingInit = false; - - if (*(pDM_Odm->mp_mode) != 1) - pdmpriv->TxPowerTrackControl = true; - else - pdmpriv->TxPowerTrackControl = false; - - /* pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = true; */ - pDM_Odm->RFCalibrateInfo.ThermalValue = pHalData->EEPROMThermalMeter; - pDM_Odm->RFCalibrateInfo.ThermalValue_IQK = pHalData->EEPROMThermalMeter; - pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = pHalData->EEPROMThermalMeter; - - /* The index of "0 dB" in SwingTable. */ - pDM_Odm->DefaultOfdmIndex = (defaultSwingIndex >= OFDM_TABLE_SIZE) ? 30 : defaultSwingIndex; - pDM_Odm->DefaultCckIndex = 20; - - pDM_Odm->BbSwingIdxCckBase = pDM_Odm->DefaultCckIndex; - pDM_Odm->RFCalibrateInfo.CCK_index = pDM_Odm->DefaultCckIndex; - - for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { - pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->DefaultOfdmIndex; - pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->DefaultOfdmIndex; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] = 0; - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] = 0; - pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; - } - -} - -void ODM_TXPowerTrackingCheck(struct dm_odm_t *pDM_Odm) -{ - struct adapter *Adapter = pDM_Odm->Adapter; - - if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK)) - return; - - if (!pDM_Odm->RFCalibrateInfo.TM_Trigger) { /* at least delay 1 sec */ - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_T_METER_NEW, (BIT(17) | BIT(16)), 0x03); - - pDM_Odm->RFCalibrateInfo.TM_Trigger = 1; - return; - } else { - ODM_TXPowerTrackingCallback_ThermalMeter(Adapter); - pDM_Odm->RFCalibrateInfo.TM_Trigger = 0; - } -} - -/* */ -/* 3 Export Interface */ -/* */ - -/* */ -/* 2011/09/21 MH Add to describe different team necessary resource allocate?? */ -/* */ -void ODM_DMInit(struct dm_odm_t *pDM_Odm) -{ - - odm_CommonInfoSelfInit(pDM_Odm); - odm_DIGInit(pDM_Odm); - odm_NHMCounterStatisticsInit(pDM_Odm); - odm_AdaptivityInit(pDM_Odm); - odm_RateAdaptiveMaskInit(pDM_Odm); - ODM_CfoTrackingInit(pDM_Odm); - ODM_EdcaTurboInit(pDM_Odm); - odm_RSSIMonitorInit(pDM_Odm); - odm_TXPowerTrackingInit(pDM_Odm); - - ODM_ClearTxPowerTrackingState(pDM_Odm); - - odm_DynamicBBPowerSavingInit(pDM_Odm); - odm_DynamicTxPowerInit(pDM_Odm); - - odm_SwAntDetectInit(pDM_Odm); -} - -/* */ -/* 2011/09/20 MH This is the entry pointer for all team to execute HW out source DM. */ -/* You can not add any dummy function here, be care, you can only use DM structure */ -/* to perform any new ODM_DM. */ -/* */ -void ODM_DMWatchdog(struct dm_odm_t *pDM_Odm) -{ - odm_CommonInfoSelfUpdate(pDM_Odm); - odm_FalseAlarmCounterStatistics(pDM_Odm); - odm_NHMCounterStatistics(pDM_Odm); - - odm_RSSIMonitorCheck(pDM_Odm); - - /* For CE Platform(SPRD or Tablet) */ - /* 8723A or 8189ES platform */ - /* NeilChen--2012--08--24-- */ - /* Fix Leave LPS issue */ - if (adapter_to_pwrctl(pDM_Odm->Adapter)->pwr_mode != PS_MODE_ACTIVE) { - /* in LPS mode */ - odm_DIGbyRSSI_LPS(pDM_Odm); - } else { - odm_DIG(pDM_Odm); - } - - { - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - - odm_Adaptivity(pDM_Odm, pDM_DigTable->CurIGValue); - } - odm_CCKPacketDetectionThresh(pDM_Odm); - - if (*pDM_Odm->pbPowerSaving) - return; - - odm_RefreshRateAdaptiveMask(pDM_Odm); - odm_EdcaTurboCheck(pDM_Odm); - ODM_CfoTracking(pDM_Odm); - - ODM_TXPowerTrackingCheck(pDM_Odm); - - /* odm_EdcaTurboCheck(pDM_Odm); */ - - /* 2010.05.30 LukeLee: For CE platform, files in IC subfolders may not be included to be compiled, */ - /* so compile flags must be left here to prevent from compile errors */ - pDM_Odm->PhyDbgInfo.NumQryBeaconPkt = 0; -} - -/* */ -/* Init /.. Fixed HW value. Only init time. */ -/* */ -void ODM_CmnInfoInit(struct dm_odm_t *pDM_Odm, enum odm_cmninfo_e CmnInfo, u32 Value) -{ - /* */ - /* This section is used for init value */ - /* */ - switch (CmnInfo) { - /* */ - /* Fixed ODM value. */ - /* */ - case ODM_CMNINFO_ABILITY: - pDM_Odm->SupportAbility = (u32)Value; - break; - - case ODM_CMNINFO_PLATFORM: - pDM_Odm->SupportPlatform = (u8)Value; - break; - - case ODM_CMNINFO_INTERFACE: - pDM_Odm->SupportInterface = (u8)Value; - break; - - case ODM_CMNINFO_IC_TYPE: - pDM_Odm->SupportICType = Value; - break; - - case ODM_CMNINFO_CUT_VER: - pDM_Odm->CutVersion = (u8)Value; - break; - - case ODM_CMNINFO_FAB_VER: - pDM_Odm->FabVersion = (u8)Value; - break; - - case ODM_CMNINFO_RFE_TYPE: - pDM_Odm->RFEType = (u8)Value; - break; - - case ODM_CMNINFO_RF_ANTENNA_TYPE: - pDM_Odm->AntDivType = (u8)Value; - break; - - case ODM_CMNINFO_PACKAGE_TYPE: - pDM_Odm->PackageType = (u8)Value; - break; - - case ODM_CMNINFO_EXT_LNA: - pDM_Odm->ExtLNA = (u8)Value; - break; - - case ODM_CMNINFO_EXT_PA: - pDM_Odm->ExtPA = (u8)Value; - break; - - case ODM_CMNINFO_GPA: - pDM_Odm->TypeGPA = (enum odm_type_gpa_e)Value; - break; - case ODM_CMNINFO_APA: - pDM_Odm->TypeAPA = (enum odm_type_apa_e)Value; - break; - case ODM_CMNINFO_GLNA: - pDM_Odm->TypeGLNA = (enum odm_type_glna_e)Value; - break; - case ODM_CMNINFO_ALNA: - pDM_Odm->TypeALNA = (enum odm_type_alna_e)Value; - break; - - case ODM_CMNINFO_EXT_TRSW: - pDM_Odm->ExtTRSW = (u8)Value; - break; - case ODM_CMNINFO_PATCH_ID: - pDM_Odm->PatchID = (u8)Value; - break; - case ODM_CMNINFO_BINHCT_TEST: - pDM_Odm->bInHctTest = (bool)Value; - break; - case ODM_CMNINFO_BWIFI_TEST: - pDM_Odm->bWIFITest = (bool)Value; - break; - - case ODM_CMNINFO_SMART_CONCURRENT: - pDM_Odm->bDualMacSmartConcurrent = (bool)Value; - break; - - /* To remove the compiler warning, must add an empty default statement to handle the other values. */ - default: - /* do nothing */ - break; - } - -} - -void ODM_CmnInfoHook(struct dm_odm_t *pDM_Odm, enum odm_cmninfo_e CmnInfo, void *pValue) -{ - /* */ - /* Hook call by reference pointer. */ - /* */ - switch (CmnInfo) { - /* */ - /* Dynamic call by reference pointer. */ - /* */ - case ODM_CMNINFO_MAC_PHY_MODE: - pDM_Odm->pMacPhyMode = pValue; - break; - - case ODM_CMNINFO_TX_UNI: - pDM_Odm->pNumTxBytesUnicast = pValue; - break; - - case ODM_CMNINFO_RX_UNI: - pDM_Odm->pNumRxBytesUnicast = pValue; - break; - - case ODM_CMNINFO_WM_MODE: - pDM_Odm->pwirelessmode = pValue; - break; - - case ODM_CMNINFO_SEC_CHNL_OFFSET: - pDM_Odm->pSecChOffset = pValue; - break; - - case ODM_CMNINFO_SEC_MODE: - pDM_Odm->pSecurity = pValue; - break; - - case ODM_CMNINFO_BW: - pDM_Odm->pBandWidth = pValue; - break; - - case ODM_CMNINFO_CHNL: - pDM_Odm->pChannel = pValue; - break; - - case ODM_CMNINFO_DMSP_GET_VALUE: - pDM_Odm->pbGetValueFromOtherMac = pValue; - break; - - case ODM_CMNINFO_BUDDY_ADAPTOR: - pDM_Odm->pBuddyAdapter = pValue; - break; - - case ODM_CMNINFO_DMSP_IS_MASTER: - pDM_Odm->pbMasterOfDMSP = pValue; - break; - - case ODM_CMNINFO_SCAN: - pDM_Odm->pbScanInProcess = pValue; - break; - - case ODM_CMNINFO_POWER_SAVING: - pDM_Odm->pbPowerSaving = pValue; - break; - - case ODM_CMNINFO_ONE_PATH_CCA: - pDM_Odm->pOnePathCCA = pValue; - break; - - case ODM_CMNINFO_DRV_STOP: - pDM_Odm->pbDriverStopped = pValue; - break; - - case ODM_CMNINFO_PNP_IN: - pDM_Odm->pbDriverIsGoingToPnpSetPowerSleep = pValue; - break; - - case ODM_CMNINFO_INIT_ON: - pDM_Odm->pinit_adpt_in_progress = pValue; - break; - - case ODM_CMNINFO_ANT_TEST: - pDM_Odm->pAntennaTest = pValue; - break; - - case ODM_CMNINFO_NET_CLOSED: - pDM_Odm->pbNet_closed = pValue; - break; - - case ODM_CMNINFO_FORCED_RATE: - pDM_Odm->pForcedDataRate = pValue; - break; - - case ODM_CMNINFO_FORCED_IGI_LB: - pDM_Odm->pu1ForcedIgiLb = pValue; - break; - - case ODM_CMNINFO_MP_MODE: - pDM_Odm->mp_mode = pValue; - break; - - /* case ODM_CMNINFO_RTSTA_AID: */ - /* pDM_Odm->pAidMap = (u8 *)pValue; */ - /* break; */ - - /* case ODM_CMNINFO_BT_COEXIST: */ - /* pDM_Odm->BTCoexist = (bool *)pValue; */ - - /* case ODM_CMNINFO_STA_STATUS: */ - /* pDM_Odm->pODM_StaInfo[] = (PSTA_INFO_T)pValue; */ - /* break; */ - - /* case ODM_CMNINFO_PHY_STATUS: */ - /* pDM_Odm->pPhyInfo = (ODM_PHY_INFO *)pValue; */ - /* break; */ - - /* case ODM_CMNINFO_MAC_STATUS: */ - /* pDM_Odm->pMacInfo = (struct odm_mac_status_info *)pValue; */ - /* break; */ - /* To remove the compiler warning, must add an empty default statement to handle the other values. */ - default: - /* do nothing */ - break; - } - -} - -void ODM_CmnInfoPtrArrayHook( - struct dm_odm_t *pDM_Odm, - enum odm_cmninfo_e CmnInfo, - u16 Index, - void *pValue -) -{ - /* */ - /* Hook call by reference pointer. */ - /* */ - switch (CmnInfo) { - /* */ - /* Dynamic call by reference pointer. */ - /* */ - case ODM_CMNINFO_STA_STATUS: - pDM_Odm->pODM_StaInfo[Index] = (PSTA_INFO_T)pValue; - break; - /* To remove the compiler warning, must add an empty default statement to handle the other values. */ - default: - /* do nothing */ - break; - } - -} - -/* */ -/* Update Band/CHannel/.. The values are dynamic but non-per-packet. */ -/* */ -void ODM_CmnInfoUpdate(struct dm_odm_t *pDM_Odm, u32 CmnInfo, u64 Value) -{ - /* */ - /* This init variable may be changed in run time. */ - /* */ - switch (CmnInfo) { - case ODM_CMNINFO_LINK_IN_PROGRESS: - pDM_Odm->bLinkInProcess = (bool)Value; - break; - - case ODM_CMNINFO_ABILITY: - pDM_Odm->SupportAbility = (u32)Value; - break; - - case ODM_CMNINFO_WIFI_DIRECT: - pDM_Odm->bWIFI_Direct = (bool)Value; - break; - - case ODM_CMNINFO_WIFI_DISPLAY: - pDM_Odm->bWIFI_Display = (bool)Value; - break; - - case ODM_CMNINFO_LINK: - pDM_Odm->bLinked = (bool)Value; - break; - - case ODM_CMNINFO_STATION_STATE: - pDM_Odm->bsta_state = (bool)Value; - break; - - case ODM_CMNINFO_RSSI_MIN: - pDM_Odm->RSSI_Min = (u8)Value; - break; - - case ODM_CMNINFO_RA_THRESHOLD_HIGH: - pDM_Odm->RateAdaptive.HighRSSIThresh = (u8)Value; - break; - - case ODM_CMNINFO_RA_THRESHOLD_LOW: - pDM_Odm->RateAdaptive.LowRSSIThresh = (u8)Value; - break; - /* The following is for BT HS mode and BT coexist mechanism. */ - case ODM_CMNINFO_BT_ENABLED: - pDM_Odm->bBtEnabled = (bool)Value; - break; - - case ODM_CMNINFO_BT_HS_CONNECT_PROCESS: - pDM_Odm->bBtConnectProcess = (bool)Value; - break; - - case ODM_CMNINFO_BT_HS_RSSI: - pDM_Odm->btHsRssi = (u8)Value; - break; - - case ODM_CMNINFO_BT_OPERATION: - pDM_Odm->bBtHsOperation = (bool)Value; - break; - - case ODM_CMNINFO_BT_LIMITED_DIG: - pDM_Odm->bBtLimitedDig = (bool)Value; - break; - - case ODM_CMNINFO_BT_DISABLE_EDCA: - pDM_Odm->bBtDisableEdcaTurbo = (bool)Value; - break; - - default: - /* do nothing */ - break; - } -} - -/* 3 ============================================================ */ -/* 3 DIG */ -/* 3 ============================================================ */ -/*----------------------------------------------------------------------------- - * Function: odm_DIGInit() - * - * Overview: Set DIG scheme init value. - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - *When Who Remark - * - *--------------------------------------------------------------------------- - */ - -/* Remove DIG by yuchen */ - -/* Remove DIG and FA check by Yu Chen */ - -/* 3 ============================================================ */ -/* 3 BB Power Save */ -/* 3 ============================================================ */ - -/* Remove BB power saving by Yuchen */ - -/* 3 ============================================================ */ -/* 3 Dynamic Tx Power */ -/* 3 ============================================================ */ - -/* Remove BY YuChen */ - diff --git a/drivers/staging/rtl8723bs/hal/odm.h b/drivers/staging/rtl8723bs/hal/odm.h deleted file mode 100644 index a20b48660e63..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm.h +++ /dev/null @@ -1,1109 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __HALDMOUTSRC_H__ -#define __HALDMOUTSRC_H__ - -#include "odm_EdcaTurboCheck.h" -#include "odm_DIG.h" -#include "odm_DynamicBBPowerSaving.h" -#include "odm_DynamicTxPower.h" -#include "odm_CfoTracking.h" - -#define TP_MODE 0 -#define RSSI_MODE 1 -#define TRAFFIC_LOW 0 -#define TRAFFIC_HIGH 1 -#define NONE 0 - -/* 3 Tx Power Tracking */ -/* 3 ============================================================ */ -#define DPK_DELTA_MAPPING_NUM 13 -#define index_mapping_HP_NUM 15 -#define OFDM_TABLE_SIZE 43 -#define CCK_TABLE_SIZE 33 -#define TXSCALE_TABLE_SIZE 37 -#define TXPWR_TRACK_TABLE_SIZE 30 -#define DELTA_SWINGIDX_SIZE 30 -#define BAND_NUM 4 - -/* 3 PSD Handler */ -/* 3 ============================================================ */ - -#define AFH_PSD 1 /* 0:normal PSD scan, 1: only do 20 pts PSD */ -#define MODE_40M 0 /* 0:20M, 1:40M */ -#define PSD_TH2 3 -#define PSD_CHMIN 20 /* Minimum channel number for BT AFH */ -#define SIR_STEP_SIZE 3 -#define Smooth_Size_1 5 -#define Smooth_TH_1 3 -#define Smooth_Size_2 10 -#define Smooth_TH_2 4 -#define Smooth_Size_3 20 -#define Smooth_TH_3 4 -#define Smooth_Step_Size 5 -#define Adaptive_SIR 1 -#define PSD_RESCAN 4 -#define PSD_SCAN_INTERVAL 700 /* ms */ - -/* 8723A High Power IGI Setting */ -#define DM_DIG_HIGH_PWR_IGI_LOWER_BOUND 0x22 -#define DM_DIG_Gmode_HIGH_PWR_IGI_LOWER_BOUND 0x28 -#define DM_DIG_HIGH_PWR_THRESHOLD 0x3a -#define DM_DIG_LOW_PWR_THRESHOLD 0x14 - -/* ANT Test */ -#define ANTTESTALL 0x00 /* Ant A or B will be Testing */ -#define ANTTESTA 0x01 /* Ant A will be Testing */ -#define ANTTESTB 0x02 /* Ant B will be testing */ - -#define PS_MODE_ACTIVE 0x01 - -/* for 8723A Ant Definition--2012--06--07 due to different IC may be different ANT define */ -#define MAIN_ANT 1 /* Ant A or Ant Main */ -#define AUX_ANT 2 /* AntB or Ant Aux */ -#define MAX_ANT 3 /* 3 for AP using */ - -/* Antenna Diversity Type */ -#define SW_ANTDIV 0 -#define HW_ANTDIV 1 -/* structure and define */ - -/* Remove DIG by Yuchen */ - -/* Remove BB power saving by Yuchn */ - -/* Remove DIG by yuchen */ - -struct dynamic_primary_CCA { - u8 PriCCA_flag; - u8 intf_flag; - u8 intf_type; - u8 DupRTS_flag; - u8 Monitor_flag; - u8 CH_offset; - u8 MF_state; -}; - -struct ra_t { - u8 firstconnect; -}; - -struct rxhp_t { - u8 RXHP_flag; - u8 PSD_func_trigger; - u8 PSD_bitmap_RXHP[80]; - u8 Pre_IGI; - u8 Cur_IGI; - u8 Pre_pw_th; - u8 Cur_pw_th; - bool First_time_enter; - bool RXHP_enable; - u8 TP_Mode; - struct timer_list PSDTimer; -}; - -#define ASSOCIATE_ENTRY_NUM 32 /* Max size of AsocEntry[]. */ -#define ODM_ASSOCIATE_ENTRY_NUM ASSOCIATE_ENTRY_NUM - -/* This indicates two different the steps. */ -/* In SWAW_STEP_PEAK, driver needs to switch antenna and listen to the signal on the air. */ -/* In SWAW_STEP_DETERMINE, driver just compares the signal captured in SWAW_STEP_PEAK */ -/* with original RSSI to determine if it is necessary to switch antenna. */ -#define SWAW_STEP_PEAK 0 -#define SWAW_STEP_DETERMINE 1 - -#define TP_MODE 0 -#define RSSI_MODE 1 -#define TRAFFIC_LOW 0 -#define TRAFFIC_HIGH 1 -#define TRAFFIC_UltraLOW 2 - -struct swat_t { /* _SW_Antenna_Switch_ */ - u8 Double_chk_flag; - u8 try_flag; - s32 PreRSSI; - u8 CurAntenna; - u8 PreAntenna; - u8 RSSI_Trying; - u8 TestMode; - u8 bTriggerAntennaSwitch; - u8 SelectAntennaMap; - u8 RSSI_target; - u8 reset_idx; - u16 Single_Ant_Counter; - u16 Dual_Ant_Counter; - u16 Aux_FailDetec_Counter; - u16 Retry_Counter; - - /* Before link Antenna Switch check */ - u8 SWAS_NoLink_State; - u32 SWAS_NoLink_BK_Reg860; - u32 SWAS_NoLink_BK_Reg92c; - u32 SWAS_NoLink_BK_Reg948; - bool ANTA_ON; /* To indicate Ant A is or not */ - bool ANTB_ON; /* To indicate Ant B is on or not */ - bool Pre_Aux_FailDetec; - bool RSSI_AntDect_bResult; - u8 Ant2G; - - s32 RSSI_sum_A; - s32 RSSI_sum_B; - s32 RSSI_cnt_A; - s32 RSSI_cnt_B; - - u64 lastTxOkCnt; - u64 lastRxOkCnt; - u64 TXByteCnt_A; - u64 TXByteCnt_B; - u64 RXByteCnt_A; - u64 RXByteCnt_B; - u8 TrafficLoad; - u8 Train_time; - u8 Train_time_flag; - struct timer_list SwAntennaSwitchTimer; - struct timer_list SwAntennaSwitchTimer_8723B; - u32 PktCnt_SWAntDivByCtrlFrame; - bool bSWAntDivByCtrlFrame; -}; - -/* Remove Edca by YuChen */ - -struct odm_rate_adaptive { - u8 Type; /* DM_Type_ByFW/DM_Type_ByDriver */ - u8 LdpcThres; /* if RSSI > LdpcThres => switch from LPDC to BCC */ - bool bUseLdpc; - bool bLowerRtsRate; - u8 HighRSSIThresh; /* if RSSI > HighRSSIThresh => RATRState is DM_RATR_STA_HIGH */ - u8 LowRSSIThresh; /* if RSSI <= LowRSSIThresh => RATRState is DM_RATR_STA_LOW */ - u8 RATRState; /* Current RSSI level, DM_RATR_STA_HIGH/DM_RATR_STA_MIDDLE/DM_RATR_STA_LOW */ - -}; - -#define IQK_MAC_REG_NUM 4 -#define IQK_ADDA_REG_NUM 16 -#define IQK_BB_REG_NUM_MAX 10 -#define IQK_BB_REG_NUM 9 -#define HP_THERMAL_NUM 8 - -#define AVG_THERMAL_NUM 8 -#define IQK_MATRIX_REG_NUM 8 -#define IQK_MATRIX_SETTINGS_NUM 14 /* Channels_2_4G_NUM */ - -#define DM_Type_ByFW 0 -#define DM_Type_ByDriver 1 - -/* */ -/* Declare for common info */ -/* */ -#define MAX_PATH_NUM_8723B 1 - -#define IQK_THRESHOLD 8 -#define DPK_THRESHOLD 4 - -struct odm_phy_info { - /* - * Be care, if you want to add any element, please insert it between - * rx_pwd_ball and signal_strength. - */ - u8 rx_pwd_ba11; - - u8 signal_quality; /* in 0-100 index. */ - s8 rx_mimo_signal_quality[4]; /* per-path's EVM */ - u8 rx_mimo_evm_dbm[4]; /* per-path's EVM dbm */ - - u8 rx_mimo_signal_strength[4]; /* in 0~100 index */ - - u16 cfo_short[4]; /* per-path's Cfo_short */ - u16 cfo_tail[4]; /* per-path's Cfo_tail */ - - s8 rx_power; /* in dBm Translate from PWdB */ - - /* - * Real power in dBm for this packet, no beautification and - * aggregation. Keep this raw info to be used for the other procedures. - */ - s8 recv_signal_power; - u8 bt_rx_rssi_percentage; - u8 signal_strength; /* in 0-100 index. */ - - s8 rx_pwr[4]; /* per-path's pwdb */ - - u8 rx_snr[4]; /* per-path's SNR */ - u8 band_width; - u8 bt_coex_pwr_adjust; -}; - -struct odm_packet_info { - u8 data_rate; - u8 station_id; - bool bssid_match; - bool to_self; - bool is_beacon; -}; - -struct odm_phy_dbg_info { - /* ODM Write, debug info */ - s8 RxSNRdB[4]; - u32 NumQryPhyStatus; - u32 NumQryPhyStatusCCK; - u32 NumQryPhyStatusOFDM; - u8 NumQryBeaconPkt; - /* Others */ - s32 RxEVM[4]; - -}; - -struct odm_mac_status_info { - u8 test; -}; - -/* */ -/* 2011/10/20 MH Define Common info enum for all team. */ -/* */ -enum odm_cmninfo_e { - /* Fixed value: */ - - /* HOOK BEFORE REG INIT----------- */ - ODM_CMNINFO_PLATFORM = 0, - ODM_CMNINFO_ABILITY, /* ODM_ABILITY_E */ - ODM_CMNINFO_INTERFACE, /* ODM_INTERFACE_E */ - ODM_CMNINFO_IC_TYPE, /* ODM_IC_TYPE_E */ - ODM_CMNINFO_CUT_VER, /* ODM_CUT_VERSION_E */ - ODM_CMNINFO_FAB_VER, /* ODM_FAB_E */ - ODM_CMNINFO_RFE_TYPE, - ODM_CMNINFO_PACKAGE_TYPE, - ODM_CMNINFO_EXT_LNA, /* true */ - ODM_CMNINFO_EXT_PA, - ODM_CMNINFO_GPA, - ODM_CMNINFO_APA, - ODM_CMNINFO_GLNA, - ODM_CMNINFO_ALNA, - ODM_CMNINFO_EXT_TRSW, - ODM_CMNINFO_PATCH_ID, /* CUSTOMER ID */ - ODM_CMNINFO_BINHCT_TEST, - ODM_CMNINFO_BWIFI_TEST, - ODM_CMNINFO_SMART_CONCURRENT, - /* HOOK BEFORE REG INIT----------- */ - - /* Dynamic value: */ -/* POINTER REFERENCE----------- */ - ODM_CMNINFO_MAC_PHY_MODE, /* ODM_MAC_PHY_MODE_E */ - ODM_CMNINFO_TX_UNI, - ODM_CMNINFO_RX_UNI, - ODM_CMNINFO_WM_MODE, /* ODM_WIRELESS_MODE_E */ - ODM_CMNINFO_SEC_CHNL_OFFSET, /* ODM_SEC_CHNL_OFFSET_E */ - ODM_CMNINFO_SEC_MODE, /* ODM_SECURITY_E */ - ODM_CMNINFO_BW, /* ODM_BW_E */ - ODM_CMNINFO_CHNL, - ODM_CMNINFO_FORCED_RATE, - - ODM_CMNINFO_DMSP_GET_VALUE, - ODM_CMNINFO_BUDDY_ADAPTOR, - ODM_CMNINFO_DMSP_IS_MASTER, - ODM_CMNINFO_SCAN, - ODM_CMNINFO_POWER_SAVING, - ODM_CMNINFO_ONE_PATH_CCA, /* ODM_CCA_PATH_E */ - ODM_CMNINFO_DRV_STOP, - ODM_CMNINFO_PNP_IN, - ODM_CMNINFO_INIT_ON, - ODM_CMNINFO_ANT_TEST, - ODM_CMNINFO_NET_CLOSED, - ODM_CMNINFO_MP_MODE, - /* ODM_CMNINFO_RTSTA_AID, For win driver only? */ - ODM_CMNINFO_FORCED_IGI_LB, - ODM_CMNINFO_IS1ANTENNA, - ODM_CMNINFO_RFDEFAULTPATH, -/* POINTER REFERENCE----------- */ - -/* CALL BY VALUE------------- */ - ODM_CMNINFO_WIFI_DIRECT, - ODM_CMNINFO_WIFI_DISPLAY, - ODM_CMNINFO_LINK_IN_PROGRESS, - ODM_CMNINFO_LINK, - ODM_CMNINFO_STATION_STATE, - ODM_CMNINFO_RSSI_MIN, - ODM_CMNINFO_DBG_COMP, /* u64 */ - ODM_CMNINFO_DBG_LEVEL, /* u32 */ - ODM_CMNINFO_RA_THRESHOLD_HIGH, /* u8 */ - ODM_CMNINFO_RA_THRESHOLD_LOW, /* u8 */ - ODM_CMNINFO_RF_ANTENNA_TYPE, /* u8 */ - ODM_CMNINFO_BT_ENABLED, - ODM_CMNINFO_BT_HS_CONNECT_PROCESS, - ODM_CMNINFO_BT_HS_RSSI, - ODM_CMNINFO_BT_OPERATION, - ODM_CMNINFO_BT_LIMITED_DIG, /* Need to Limited Dig or not */ - ODM_CMNINFO_BT_DISABLE_EDCA, -/* CALL BY VALUE------------- */ - - /* Dynamic ptr array hook itms. */ - ODM_CMNINFO_STA_STATUS, - ODM_CMNINFO_PHY_STATUS, - ODM_CMNINFO_MAC_STATUS, - - ODM_CMNINFO_MAX, -}; - -/* 2011/10/20 MH Define ODM support ability. ODM_CMNINFO_ABILITY */ -enum { /* _ODM_Support_Ability_Definition */ - /* */ - /* BB ODM section BIT 0-15 */ - /* */ - ODM_BB_DIG = BIT(0), - ODM_BB_RA_MASK = BIT(1), - ODM_BB_DYNAMIC_TXPWR = BIT(2), - ODM_BB_FA_CNT = BIT(3), - ODM_BB_RSSI_MONITOR = BIT(4), - ODM_BB_CCK_PD = BIT(5), - ODM_BB_ANT_DIV = BIT(6), - ODM_BB_PWR_SAVE = BIT(7), - ODM_BB_PWR_TRAIN = BIT(8), - ODM_BB_RATE_ADAPTIVE = BIT(9), - ODM_BB_PATH_DIV = BIT(10), - ODM_BB_PSD = BIT(11), - ODM_BB_RXHP = BIT(12), - ODM_BB_ADAPTIVITY = BIT(13), - ODM_BB_CFO_TRACKING = BIT(14), - - /* MAC DM section BIT 16-23 */ - ODM_MAC_EDCA_TURBO = BIT(16), - ODM_MAC_EARLY_MODE = BIT(17), - - /* RF ODM section BIT 24-31 */ - ODM_RF_TX_PWR_TRACK = BIT(24), - ODM_RF_RX_GAIN_TRACK = BIT(25), - ODM_RF_CALIBRATION = BIT(26), -}; - -/* ODM_CMNINFO_INTERFACE */ -enum { /* tag_ODM_Support_Interface_Definition */ - ODM_ITRF_SDIO = 0x4, - ODM_ITRF_ALL = 0x7, -}; - -/* ODM_CMNINFO_IC_TYPE */ -enum { /* tag_ODM_Support_IC_Type_Definition */ - ODM_RTL8723B = BIT(8), -}; - -/* ODM_CMNINFO_CUT_VER */ -enum { /* tag_ODM_Cut_Version_Definition */ - ODM_CUT_A = 0, - ODM_CUT_B = 1, - ODM_CUT_C = 2, - ODM_CUT_D = 3, - ODM_CUT_E = 4, - ODM_CUT_F = 5, - - ODM_CUT_I = 8, - ODM_CUT_J = 9, - ODM_CUT_K = 10, - ODM_CUT_TEST = 15, -}; - -/* ODM_CMNINFO_FAB_VER */ -enum { /* tag_ODM_Fab_Version_Definition */ - ODM_TSMC = 0, - ODM_UMC = 1, -}; - -/* */ -/* For example 1T2R (A+AB = BIT0|BIT4|BIT5) */ -/* */ -enum { /* tag_ODM_RF_Type_Definition */ - ODM_1T1R = 0, - ODM_1T2R = 1, - ODM_2T2R = 2, - ODM_2T3R = 3, - ODM_2T4R = 4, - ODM_3T3R = 5, - ODM_3T4R = 6, - ODM_4T4R = 7, -}; - -/* */ -/* ODM Dynamic common info value definition */ -/* */ - -/* ODM_CMNINFO_WM_MODE */ -enum { /* tag_Wireless_Mode_Definition */ - ODM_WM_UNKNOWN = 0x0, - ODM_WM_B = BIT(0), - ODM_WM_G = BIT(1), - ODM_WM_N24G = BIT(3), - ODM_WM_AUTO = BIT(5), -}; - -/* ODM_CMNINFO_BW */ -enum { /* tag_Bandwidth_Definition */ - ODM_BW20M = 0, - ODM_BW40M = 1, -}; - -/* For AC-series IC, external PA & LNA can be individually added on 2.4G */ - -enum odm_type_gpa_e { /* tag_ODM_TYPE_GPA_Definition */ - TYPE_GPA0 = 0, - TYPE_GPA1 = BIT(1)|BIT(0) -}; - -enum odm_type_apa_e { /* tag_ODM_TYPE_APA_Definition */ - TYPE_APA0 = 0, - TYPE_APA1 = BIT(1)|BIT(0) -}; - -enum odm_type_glna_e { /* tag_ODM_TYPE_GLNA_Definition */ - TYPE_GLNA0 = 0, - TYPE_GLNA1 = BIT(2)|BIT(0), - TYPE_GLNA2 = BIT(3)|BIT(1), - TYPE_GLNA3 = BIT(3)|BIT(2)|BIT(1)|BIT(0) -}; - -enum odm_type_alna_e { /* tag_ODM_TYPE_ALNA_Definition */ - TYPE_ALNA0 = 0, - TYPE_ALNA1 = BIT(2)|BIT(0), - TYPE_ALNA2 = BIT(3)|BIT(1), - TYPE_ALNA3 = BIT(3)|BIT(2)|BIT(1)|BIT(0) -}; - -/* Remove PATHDIV_PARA struct to odm_PathDiv.h */ - -struct odm_rf_cal_t { /* ODM_RF_Calibration_Structure */ - /* for tx power tracking */ - - u32 RegA24; /* for TempCCK */ - s32 RegE94; - s32 RegE9C; - s32 RegEB4; - s32 RegEBC; - - u8 TXPowercount; - bool bTXPowerTrackingInit; - bool bTXPowerTracking; - u8 TxPowerTrackControl; /* for mp mode, turn off txpwrtracking as default */ - u8 TM_Trigger; - - u8 ThermalMeter[2]; /* ThermalMeter, index 0 for RFIC0, and 1 for RFIC1 */ - u8 ThermalValue; - u8 ThermalValue_LCK; - u8 ThermalValue_IQK; - u8 ThermalValue_DPK; - u8 ThermalValue_AVG[AVG_THERMAL_NUM]; - u8 ThermalValue_AVG_index; - u8 ThermalValue_RxGain; - u8 ThermalValue_Crystal; - u8 ThermalValue_DPKstore; - u8 ThermalValue_DPKtrack; - bool TxPowerTrackingInProgress; - - bool bReloadtxpowerindex; - u8 bRfPiEnable; - u32 TXPowerTrackingCallbackCnt; /* cosa add for debug */ - - /* Tx power Tracking ------------------------- */ - u8 bCCKinCH14; - u8 CCK_index; - u8 OFDM_index[MAX_RF_PATH]; - s8 PowerIndexOffset[MAX_RF_PATH]; - s8 DeltaPowerIndex[MAX_RF_PATH]; - s8 DeltaPowerIndexLast[MAX_RF_PATH]; - bool bTxPowerChanged; - - u8 ThermalValue_HP[HP_THERMAL_NUM]; - u8 ThermalValue_HP_index; - s32 iqk_matrix_regs_setting_value[IQK_MATRIX_SETTINGS_NUM][IQK_MATRIX_REG_NUM]; - bool bNeedIQK; - bool bIQKInProgress; - u8 Delta_IQK; - u8 Delta_LCK; - s8 BBSwingDiff2G; /* Unit: dB */ - u8 DeltaSwingTableIdx_2GCCKA_P[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GCCKA_N[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GCCKB_P[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GCCKB_N[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GA_P[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GA_N[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GB_P[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GB_N[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GA_P_8188E[DELTA_SWINGIDX_SIZE]; - u8 DeltaSwingTableIdx_2GA_N_8188E[DELTA_SWINGIDX_SIZE]; - - /* */ - - /* for IQK */ - u32 RegC04; - u32 Reg874; - u32 RegC08; - u32 RegB68; - u32 RegB6C; - u32 Reg870; - u32 Reg860; - u32 Reg864; - - bool bIQKInitialized; - bool bLCKInProgress; - bool bAntennaDetected; - u32 ADDA_backup[IQK_ADDA_REG_NUM]; - u32 IQK_MAC_backup[IQK_MAC_REG_NUM]; - u32 IQK_BB_backup_recover[9]; - u32 IQK_BB_backup[IQK_BB_REG_NUM]; - u32 TxIQC_8723B[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ - u32 RxIQC_8723B[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ - - /* for APK */ - u32 APKoutput[2][2]; /* path A/B; output1_1a/output1_2a */ - u8 bAPKdone; - u8 bAPKThermalMeterIgnore; - - /* DPK */ - bool bDPKFail; - u8 bDPdone; - u8 bDPPathAOK; - u8 bDPPathBOK; - - u32 TxLOK[2]; - -}; -/* */ -/* ODM Dynamic common info value definition */ -/* */ - -struct fat_t { /* _FAST_ANTENNA_TRAINNING_ */ - u8 Bssid[6]; - u8 antsel_rx_keep_0; - u8 antsel_rx_keep_1; - u8 antsel_rx_keep_2; - u8 antsel_rx_keep_3; - u32 antSumRSSI[7]; - u32 antRSSIcnt[7]; - u32 antAveRSSI[7]; - u8 FAT_State; - u32 TrainIdx; - u8 antsel_a[ODM_ASSOCIATE_ENTRY_NUM]; - u8 antsel_b[ODM_ASSOCIATE_ENTRY_NUM]; - u8 antsel_c[ODM_ASSOCIATE_ENTRY_NUM]; - u32 MainAnt_Sum[ODM_ASSOCIATE_ENTRY_NUM]; - u32 AuxAnt_Sum[ODM_ASSOCIATE_ENTRY_NUM]; - u32 MainAnt_Cnt[ODM_ASSOCIATE_ENTRY_NUM]; - u32 AuxAnt_Cnt[ODM_ASSOCIATE_ENTRY_NUM]; - u8 RxIdleAnt; - bool bBecomeLinked; - u32 MinMaxRSSI; - u8 idx_AntDiv_counter_2G; - u32 CCK_counter_main; - u32 CCK_counter_aux; - u32 OFDM_counter_main; - u32 OFDM_counter_aux; - - u32 CCK_CtrlFrame_Cnt_main; - u32 CCK_CtrlFrame_Cnt_aux; - u32 OFDM_CtrlFrame_Cnt_main; - u32 OFDM_CtrlFrame_Cnt_aux; - u32 MainAnt_CtrlFrame_Sum; - u32 AuxAnt_CtrlFrame_Sum; - u32 MainAnt_CtrlFrame_Cnt; - u32 AuxAnt_CtrlFrame_Cnt; - -}; - -enum { - NO_ANTDIV = 0xFF, - CG_TRX_HW_ANTDIV = 0x01, - CGCS_RX_HW_ANTDIV = 0x02, - FIXED_HW_ANTDIV = 0x03, - CG_TRX_SMART_ANTDIV = 0x04, - CGCS_RX_SW_ANTDIV = 0x05, - S0S1_SW_ANTDIV = 0x06 /* 8723B intrnal switch S0 S1 */ -}; - -struct pathdiv_t { /* _ODM_PATH_DIVERSITY_ */ - u8 RespTxPath; - u8 PathSel[ODM_ASSOCIATE_ENTRY_NUM]; - u32 PathA_Sum[ODM_ASSOCIATE_ENTRY_NUM]; - u32 PathB_Sum[ODM_ASSOCIATE_ENTRY_NUM]; - u32 PathA_Cnt[ODM_ASSOCIATE_ENTRY_NUM]; - u32 PathB_Cnt[ODM_ASSOCIATE_ENTRY_NUM]; -}; - -enum phy_reg_pg_type { /* _BASEBAND_CONFIG_PHY_REG_PG_VALUE_TYPE */ - PHY_REG_PG_RELATIVE_VALUE = 0, - PHY_REG_PG_EXACT_VALUE = 1 -}; - -/* */ -/* Antenna detection information from single tone mechanism, added by Roger, 2012.11.27. */ -/* */ -struct ant_detected_info { - bool bAntDetected; - u32 dBForAntA; - u32 dBForAntB; - u32 dBForAntO; -}; - -/* */ -/* 2011/09/22 MH Copy from SD4 defined structure. We use to support PHY DM integration. */ -/* */ -struct dm_odm_t { /* DM_Out_Source_Dynamic_Mechanism_Structure */ - struct adapter *Adapter; /* For CE/NIC team */ - /* WHen you use Adapter or priv pointer, you must make sure the pointer is ready. */ - bool odm_ready; - - enum phy_reg_pg_type PhyRegPgValueType; - u8 PhyRegPgVersion; - - u32 NumQryPhyStatusAll; /* CCK + OFDM */ - u32 LastNumQryPhyStatusAll; - u32 RxPWDBAve; - bool MPDIG_2G; /* off MPDIG */ - u8 Times_2G; - -/* ODM HANDLE, DRIVER NEEDS NOT TO HOOK------ */ - bool bCckHighPower; - u8 RFPathRxEnable; /* ODM_CMNINFO_RFPATH_ENABLE */ - u8 ControlChannel; -/* ODM HANDLE, DRIVER NEEDS NOT TO HOOK------ */ - -/* 1 COMMON INFORMATION */ - - /* */ - /* Init Value */ - /* */ -/* HOOK BEFORE REG INIT----------- */ - /* ODM Platform info AP/ADSL/CE/MP = 1/2/3/4 */ - u8 SupportPlatform; - /* ODM Support Ability DIG/RATR/TX_PWR_TRACK/... = 1/2/3/... */ - u32 SupportAbility; - /* ODM PCIE/USB/SDIO = 1/2/3 */ - u8 SupportInterface; - /* ODM composite or independent. Bit oriented/ 92C+92D+ .... or any other type = 1/2/3/... */ - u32 SupportICType; - /* Cut Version TestChip/A-cut/B-cut... = 0/1/2/3/... */ - u8 CutVersion; - /* Fab Version TSMC/UMC = 0/1 */ - u8 FabVersion; - /* RF Type 4T4R/3T3R/2T2R/1T2R/1T1R/... */ - u8 RFEType; - /* Board Type Normal/HighPower/MiniCard/SLIM/Combo/... = 0/1/2/3/4/... */ - u8 BoardType; - u8 PackageType; - u8 TypeGLNA; - u8 TypeGPA; - u8 TypeALNA; - u8 TypeAPA; - /* with external LNA NO/Yes = 0/1 */ - u8 ExtLNA; - /* with external PA NO/Yes = 0/1 */ - u8 ExtPA; - /* with external TRSW NO/Yes = 0/1 */ - u8 ExtTRSW; - u8 PatchID; /* Customer ID */ - bool bInHctTest; - bool bWIFITest; - - bool bDualMacSmartConcurrent; - u32 BK_SupportAbility; - u8 AntDivType; -/* HOOK BEFORE REG INIT----------- */ - - /* */ - /* Dynamic Value */ - /* */ -/* POINTER REFERENCE----------- */ - - u8 u8_temp; - bool bool_temp; - struct adapter *adapter_temp; - - /* MAC PHY Mode SMSP/DMSP/DMDP = 0/1/2 */ - u8 *pMacPhyMode; - /* TX Unicast byte count */ - u64 *pNumTxBytesUnicast; - /* RX Unicast byte count */ - u64 *pNumRxBytesUnicast; - /* Wireless mode B/G/A/N = BIT0/BIT1/BIT2/BIT3 */ - u8 *pwirelessmode; /* ODM_WIRELESS_MODE_E */ - /* Secondary channel offset don't_care/below/above = 0/1/2 */ - u8 *pSecChOffset; - /* Security mode Open/WEP/AES/TKIP = 0/1/2/3 */ - u8 *pSecurity; - /* BW info 20M/40M/80M = 0/1/2 */ - u8 *pBandWidth; - /* Central channel location Ch1/Ch2/.... */ - u8 *pChannel; /* central channel number */ - bool DPK_Done; - /* Common info for 92D DMSP */ - - bool *pbGetValueFromOtherMac; - struct adapter **pBuddyAdapter; - bool *pbMasterOfDMSP; /* MAC0: master, MAC1: slave */ - /* Common info for Status */ - bool *pbScanInProcess; - bool *pbPowerSaving; - /* CCA Path 2-path/path-A/path-B = 0/1/2; using ODM_CCA_PATH_E. */ - u8 *pOnePathCCA; - /* pMgntInfo->AntennaTest */ - u8 *pAntennaTest; - bool *pbNet_closed; - u8 *mp_mode; - u8 *pu1ForcedIgiLb; -/* For 8723B IQK----------- */ - bool *pIs1Antenna; - u8 *pRFDefaultPath; - /* 0:S1, 1:S0 */ - -/* POINTER REFERENCE----------- */ - u16 *pForcedDataRate; -/* CALL BY VALUE------------- */ - bool bLinkInProcess; - bool bWIFI_Direct; - bool bWIFI_Display; - bool bLinked; - - bool bsta_state; - u8 RSSI_Min; - u8 InterfaceIndex; /* Add for 92D dual MAC: 0--Mac0 1--Mac1 */ - bool bOneEntryOnly; - /* Common info for BTDM */ - bool bBtEnabled; /* BT is disabled */ - bool bBtConnectProcess; /* BT HS is under connection progress. */ - u8 btHsRssi; /* BT HS mode wifi rssi value. */ - bool bBtHsOperation; /* BT HS mode is under progress */ - bool bBtDisableEdcaTurbo; /* Under some condition, don't enable the EDCA Turbo */ - bool bBtLimitedDig; /* BT is busy. */ -/* CALL BY VALUE------------- */ - u8 RSSI_A; - u8 RSSI_B; - u64 RSSI_TRSW; - u64 RSSI_TRSW_H; - u64 RSSI_TRSW_L; - u64 RSSI_TRSW_iso; - - u8 RxRate; - bool bNoisyState; - u8 TxRate; - u8 LinkedInterval; - u8 preChannel; - u32 TxagcOffsetValueA; - bool IsTxagcOffsetPositiveA; - u32 TxagcOffsetValueB; - bool IsTxagcOffsetPositiveB; - u64 lastTxOkCnt; - u64 lastRxOkCnt; - u32 BbSwingOffsetA; - bool IsBbSwingOffsetPositiveA; - u32 BbSwingOffsetB; - bool IsBbSwingOffsetPositiveB; - s8 TH_L2H_ini; - s8 TH_EDCCA_HL_diff; - s8 IGI_Base; - u8 IGI_target; - bool ForceEDCCA; - u8 AdapEn_RSSI; - s8 Force_TH_H; - s8 Force_TH_L; - u8 IGI_LowerBound; - u8 antdiv_rssi; - u8 AntType; - u8 pre_AntType; - u8 antdiv_period; - u8 antdiv_select; - u8 NdpaPeriod; - bool H2C_RARpt_connect; - - /* add by Yu Cehn for adaptivtiy */ - bool adaptivity_flag; - bool NHM_disable; - bool TxHangFlg; - bool Carrier_Sense_enable; - u8 tolerance_cnt; - u64 NHMCurTxOkcnt; - u64 NHMCurRxOkcnt; - u64 NHMLastTxOkcnt; - u64 NHMLastRxOkcnt; - u8 txEdcca1; - u8 txEdcca0; - s8 H2L_lb; - s8 L2H_lb; - u8 Adaptivity_IGI_upper; - u8 NHM_cnt_0; - - /* */ - /* 2 Define STA info. */ - /* _ODM_STA_INFO */ - /* 2012/01/12 MH For MP, we need to reduce one array pointer for default port.?? */ - PSTA_INFO_T pODM_StaInfo[ODM_ASSOCIATE_ENTRY_NUM]; - - /* */ - /* 2012/02/14 MH Add to share 88E ra with other SW team. */ - /* We need to colelct all support abilit to a proper area. */ - /* */ - bool RaSupport88E; - - /* Define ........... */ - - /* Latest packet phy info (ODM write) */ - struct odm_phy_dbg_info PhyDbgInfo; - - /* Latest packet phy info (ODM write) */ - struct odm_mac_status_info *pMacInfo; - - /* */ - /* ODM Structure */ - /* */ - struct fat_t DM_FatTable; - struct dig_t DM_DigTable; - struct ps_t DM_PSTable; - struct dynamic_primary_CCA DM_PriCCA; - struct rxhp_t dM_RXHP_Table; - struct ra_t DM_RA_Table; - struct false_ALARM_STATISTICS FalseAlmCnt; - struct false_ALARM_STATISTICS FlaseAlmCntBuddyAdapter; - struct swat_t DM_SWAT_Table; - bool RSSI_test; - struct cfo_tracking DM_CfoTrack; - - struct edca_t DM_EDCA_Table; - u32 WMMEDCA_BE; - struct pathdiv_t DM_PathDiv; - /* Copy from SD4 structure */ - /* */ - /* ================================================== */ - /* */ - - /* common */ - - bool *pbDriverStopped; - bool *pbDriverIsGoingToPnpSetPowerSleep; - bool *pinit_adpt_in_progress; - - /* PSD */ - bool bUserAssignLevel; - struct timer_list PSDTimer; - u8 RSSI_BT; /* come from BT */ - bool bPSDinProcess; - bool bPSDactive; - bool bDMInitialGainEnable; - - /* MPT DIG */ - struct timer_list MPT_DIGTimer; - - /* for rate adaptive, in fact, 88c/92c fw will handle this */ - u8 bUseRAMask; - - struct odm_rate_adaptive RateAdaptive; - - struct ant_detected_info AntDetectedInfo; /* Antenna detected information for RSSI tool */ - - struct odm_rf_cal_t RFCalibrateInfo; - - /* */ - /* TX power tracking */ - /* */ - u8 BbSwingIdxOfdm[MAX_RF_PATH]; - u8 BbSwingIdxOfdmCurrent; - u8 BbSwingIdxOfdmBase[MAX_RF_PATH]; - bool BbSwingFlagOfdm; - u8 BbSwingIdxCck; - u8 BbSwingIdxCckCurrent; - u8 BbSwingIdxCckBase; - u8 DefaultOfdmIndex; - u8 DefaultCckIndex; - bool BbSwingFlagCck; - - s8 Absolute_OFDMSwingIdx[MAX_RF_PATH]; - s8 Remnant_OFDMSwingIdx[MAX_RF_PATH]; - s8 Remnant_CCKSwingIdx; - s8 Modify_TxAGC_Value; /* Remnat compensate value at TxAGC */ - bool Modify_TxAGC_Flag_PathA; - bool Modify_TxAGC_Flag_PathB; - bool Modify_TxAGC_Flag_PathC; - bool Modify_TxAGC_Flag_PathD; - bool Modify_TxAGC_Flag_PathA_CCK; - - s8 KfreeOffset[MAX_RF_PATH]; - /* */ - /* ODM system resource. */ - /* */ - - /* ODM relative time. */ - struct timer_list PathDivSwitchTimer; - /* 2011.09.27 add for Path Diversity */ - struct timer_list CCKPathDiversityTimer; - struct timer_list FastAntTrainingTimer; - - /* ODM relative workitem. */ - - #if (BEAMFORMING_SUPPORT == 1) - RT_BEAMFORMING_INFO BeamformingInfo; - #endif -}; - -enum ODM_BB_Config_Type { - CONFIG_BB_PHY_REG, - CONFIG_BB_AGC_TAB, - CONFIG_BB_AGC_TAB_2G, - CONFIG_BB_PHY_REG_PG, - CONFIG_BB_PHY_REG_MP, - CONFIG_BB_AGC_TAB_DIFF, -}; - -enum ODM_RF_Config_Type { - CONFIG_RF_RADIO, - CONFIG_RF_TXPWR_LMT, -}; - -enum ODM_FW_Config_Type { - CONFIG_FW_NIC, - CONFIG_FW_NIC_2, - CONFIG_FW_AP, - CONFIG_FW_WoWLAN, - CONFIG_FW_WoWLAN_2, - CONFIG_FW_AP_WoWLAN, - CONFIG_FW_BT, -}; - -/* include "odm_function.h" */ - -/* 3 =========================================================== */ -/* 3 DIG */ -/* 3 =========================================================== */ - -/* Remove DIG by Yuchen */ - -/* 3 =========================================================== */ -/* 3 AGC RX High Power Mode */ -/* 3 =========================================================== */ -#define LNA_Low_Gain_1 0x64 -#define LNA_Low_Gain_2 0x5A -#define LNA_Low_Gain_3 0x58 - -#define FA_RXHP_TH1 5000 -#define FA_RXHP_TH2 1500 -#define FA_RXHP_TH3 800 -#define FA_RXHP_TH4 600 -#define FA_RXHP_TH5 500 - -/* 3 =========================================================== */ -/* 3 EDCA */ -/* 3 =========================================================== */ - -/* 3 =========================================================== */ -/* 3 Dynamic Tx Power */ -/* 3 =========================================================== */ -/* Dynamic Tx Power Control Threshold */ - -/* 3 =========================================================== */ -/* 3 Rate Adaptive */ -/* 3 =========================================================== */ -#define DM_RATR_STA_INIT 0 -#define DM_RATR_STA_HIGH 1 -#define DM_RATR_STA_MIDDLE 2 -#define DM_RATR_STA_LOW 3 - -/* 3 =========================================================== */ -/* 3 BB Power Save */ -/* 3 =========================================================== */ - -enum { /* tag_1R_CCA_Type_Definition */ - CCA_1R = 0, - CCA_2R = 1, - CCA_MAX = 2, -}; - -enum { /* tag_RF_Type_Definition */ - RF_Save = 0, - RF_Normal = 1, - RF_MAX = 2, -}; - -/* Maximal number of antenna detection mechanism needs to perform, added by Roger, 2011.12.28. */ -#define MAX_ANTENNA_DETECTION_CNT 10 - -/* */ -/* Extern Global Variables. */ -/* */ -extern u32 OFDMSwingTable_New[OFDM_TABLE_SIZE]; -extern u8 CCKSwingTable_Ch1_Ch13_New[CCK_TABLE_SIZE][8]; -extern u8 CCKSwingTable_Ch14_New[CCK_TABLE_SIZE][8]; - -/* */ -/* check Sta pointer valid or not */ -/* */ -#define IS_STA_VALID(pSta) (pSta) -/* 20100514 Joseph: Add definition for antenna switching test after link. */ -/* This indicates two different the steps. */ -/* In SWAW_STEP_PEAK, driver needs to switch antenna and listen to the signal on the air. */ -/* In SWAW_STEP_DETERMINE, driver just compares the signal captured in SWAW_STEP_PEAK */ -/* with original RSSI to determine if it is necessary to switch antenna. */ -#define SWAW_STEP_PEAK 0 -#define SWAW_STEP_DETERMINE 1 - -/* Remove BB power saving by Yuchen */ - -#define dm_CheckTXPowerTracking ODM_TXPowerTrackingCheck -void ODM_TXPowerTrackingCheck(struct dm_odm_t *pDM_Odm); - -bool ODM_RAStateCheck( - struct dm_odm_t *pDM_Odm, - s32 RSSI, - bool bForceUpdate, - u8 *pRATRState -); - -#define dm_SWAW_RSSI_Check ODM_SwAntDivChkPerPktRssi -void ODM_SwAntDivChkPerPktRssi( - struct dm_odm_t *pDM_Odm, - u8 StationID, - struct odm_phy_info *pPhyInfo -); - -u32 ODM_Get_Rate_Bitmap( - struct dm_odm_t *pDM_Odm, - u32 macid, - u32 ra_mask, - u8 rssi_level -); - -#if (BEAMFORMING_SUPPORT == 1) -BEAMFORMING_CAP Beamforming_GetEntryBeamCapByMacId(PMGNT_INFO pMgntInfo, u8 MacId); -#endif - -void odm_TXPowerTrackingInit(struct dm_odm_t *pDM_Odm); - -void ODM_DMInit(struct dm_odm_t *pDM_Odm); - -void ODM_DMWatchdog(struct dm_odm_t *pDM_Odm); /* For common use in the future */ - -void ODM_CmnInfoInit(struct dm_odm_t *pDM_Odm, enum odm_cmninfo_e CmnInfo, u32 Value); - -void ODM_CmnInfoHook(struct dm_odm_t *pDM_Odm, enum odm_cmninfo_e CmnInfo, void *pValue); - -void ODM_CmnInfoPtrArrayHook( - struct dm_odm_t *pDM_Odm, - enum odm_cmninfo_e CmnInfo, - u16 Index, - void *pValue -); - -void ODM_CmnInfoUpdate(struct dm_odm_t *pDM_Odm, u32 CmnInfo, u64 Value); - -void ODM_InitAllTimers(struct dm_odm_t *pDM_Odm); - -void ODM_CancelAllTimers(struct dm_odm_t *pDM_Odm); - -void ODM_ReleaseAllTimers(struct dm_odm_t *pDM_Odm); - -void ODM_AntselStatistics_88C( - struct dm_odm_t *pDM_Odm, - u8 MacId, - u32 PWDBAll, - bool isCCKrate -); - -void ODM_DynamicARFBSelect(struct dm_odm_t *pDM_Odm, u8 rate, bool Collision_State); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c b/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c deleted file mode 100644 index 7e6b49399abb..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c +++ /dev/null @@ -1,210 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -static void odm_SetCrystalCap(void *pDM_VOID, u8 CrystalCap) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct cfo_tracking *pCfoTrack = &pDM_Odm->DM_CfoTrack; - - if (pCfoTrack->CrystalCap == CrystalCap) - return; - - pCfoTrack->CrystalCap = CrystalCap; - - /* 0x2C[23:18] = 0x2C[17:12] = CrystalCap */ - CrystalCap = CrystalCap & 0x3F; - PHY_SetBBReg( - pDM_Odm->Adapter, - REG_MAC_PHY_CTRL, - 0x00FFF000, - (CrystalCap | (CrystalCap << 6)) - ); -} - -static u8 odm_GetDefaultCrytaltalCap(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - struct adapter *Adapter = pDM_Odm->Adapter; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - return pHalData->CrystalCap & 0x3f; -} - -static void odm_SetATCStatus(void *pDM_VOID, bool ATCStatus) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct cfo_tracking *pCfoTrack = &pDM_Odm->DM_CfoTrack; - - if (pCfoTrack->bATCStatus == ATCStatus) - return; - - PHY_SetBBReg( - pDM_Odm->Adapter, - ODM_REG(BB_ATC), - ODM_BIT(BB_ATC), - ATCStatus - ); - pCfoTrack->bATCStatus = ATCStatus; -} - -static bool odm_GetATCStatus(void *pDM_VOID) -{ - bool ATCStatus; - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - ATCStatus = (bool)PHY_QueryBBReg( - pDM_Odm->Adapter, - ODM_REG(BB_ATC), - ODM_BIT(BB_ATC) - ); - return ATCStatus; -} - -void ODM_CfoTrackingReset(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct cfo_tracking *pCfoTrack = &pDM_Odm->DM_CfoTrack; - - pCfoTrack->DefXCap = odm_GetDefaultCrytaltalCap(pDM_Odm); - pCfoTrack->bAdjust = true; - - odm_SetCrystalCap(pDM_Odm, pCfoTrack->DefXCap); - odm_SetATCStatus(pDM_Odm, true); -} - -void ODM_CfoTrackingInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct cfo_tracking *pCfoTrack = &pDM_Odm->DM_CfoTrack; - - pCfoTrack->DefXCap = - pCfoTrack->CrystalCap = odm_GetDefaultCrytaltalCap(pDM_Odm); - pCfoTrack->bATCStatus = odm_GetATCStatus(pDM_Odm); - pCfoTrack->bAdjust = true; -} - -void ODM_CfoTracking(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct cfo_tracking *pCfoTrack = &pDM_Odm->DM_CfoTrack; - int CFO_kHz_A, CFO_ave = 0; - int CFO_ave_diff; - int CrystalCap = (int)pCfoTrack->CrystalCap; - u8 Adjust_Xtal = 1; - - /* 4 Support ability */ - if (!(pDM_Odm->SupportAbility & ODM_BB_CFO_TRACKING)) - return; - - if (!pDM_Odm->bLinked || !pDM_Odm->bOneEntryOnly) { - /* 4 No link or more than one entry */ - ODM_CfoTrackingReset(pDM_Odm); - } else { - /* 3 1. CFO Tracking */ - /* 4 1.1 No new packet */ - if (pCfoTrack->packetCount == pCfoTrack->packetCount_pre) - return; - - pCfoTrack->packetCount_pre = pCfoTrack->packetCount; - - /* 4 1.2 Calculate CFO */ - CFO_kHz_A = (int)(pCfoTrack->CFO_tail[0] * 3125) / 1280; - - CFO_ave = CFO_kHz_A; - - /* 4 1.3 Avoid abnormal large CFO */ - CFO_ave_diff = - (pCfoTrack->CFO_ave_pre >= CFO_ave) ? - (pCfoTrack->CFO_ave_pre-CFO_ave) : - (CFO_ave-pCfoTrack->CFO_ave_pre); - - if ( - CFO_ave_diff > 20 && - pCfoTrack->largeCFOHit == 0 && - !pCfoTrack->bAdjust - ) { - pCfoTrack->largeCFOHit = 1; - return; - } - - pCfoTrack->largeCFOHit = 0; - pCfoTrack->CFO_ave_pre = CFO_ave; - - /* 4 1.4 Dynamic Xtal threshold */ - if (!pCfoTrack->bAdjust) { - if (CFO_ave > CFO_TH_XTAL_HIGH || CFO_ave < (-CFO_TH_XTAL_HIGH)) - pCfoTrack->bAdjust = true; - } else { - if (CFO_ave < CFO_TH_XTAL_LOW && CFO_ave > (-CFO_TH_XTAL_LOW)) - pCfoTrack->bAdjust = false; - } - - /* 4 1.5 BT case: Disable CFO tracking */ - if (pDM_Odm->bBtEnabled) { - pCfoTrack->bAdjust = false; - odm_SetCrystalCap(pDM_Odm, pCfoTrack->DefXCap); - } - - /* 4 1.6 Big jump */ - if (pCfoTrack->bAdjust) { - if (CFO_ave > CFO_TH_XTAL_LOW) - Adjust_Xtal = Adjust_Xtal + ((CFO_ave - CFO_TH_XTAL_LOW) >> 2); - else if (CFO_ave < (-CFO_TH_XTAL_LOW)) - Adjust_Xtal = Adjust_Xtal + ((CFO_TH_XTAL_LOW - CFO_ave) >> 2); - } - - /* 4 1.7 Adjust Crystal Cap. */ - if (pCfoTrack->bAdjust) { - if (CFO_ave > CFO_TH_XTAL_LOW) - CrystalCap = CrystalCap + Adjust_Xtal; - else if (CFO_ave < (-CFO_TH_XTAL_LOW)) - CrystalCap = CrystalCap - Adjust_Xtal; - - if (CrystalCap > 0x3f) - CrystalCap = 0x3f; - else if (CrystalCap < 0) - CrystalCap = 0; - - odm_SetCrystalCap(pDM_Odm, (u8)CrystalCap); - } - - /* 3 2. Dynamic ATC switch */ - if (CFO_ave < CFO_TH_ATC && CFO_ave > -CFO_TH_ATC) - odm_SetATCStatus(pDM_Odm, false); - else - odm_SetATCStatus(pDM_Odm, true); - } -} - -void odm_parsing_cfo(void *dm_void, void *pkt_info_void, s8 *cfotail) -{ - struct dm_odm_t *dm_odm = (struct dm_odm_t *)dm_void; - struct odm_packet_info *pkt_info = pkt_info_void; - struct cfo_tracking *cfo_track = &dm_odm->DM_CfoTrack; - u8 i; - - if (!(dm_odm->SupportAbility & ODM_BB_CFO_TRACKING)) - return; - - if (pkt_info->station_id != 0) { - /* - * 3 Update CFO report for path-A & path-B - * Only paht-A and path-B have CFO tail and short CFO - */ - for (i = RF_PATH_A; i <= RF_PATH_B; i++) - cfo_track->CFO_tail[i] = (int)cfotail[i]; - - /* 3 Update packet counter */ - if (cfo_track->packetCount == 0xffffffff) - cfo_track->packetCount = 0; - else - cfo_track->packetCount++; - } -} diff --git a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.h b/drivers/staging/rtl8723bs/hal/odm_CfoTracking.h deleted file mode 100644 index 8fa6d9ec5880..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODMCFOTRACK_H__ -#define __ODMCFOTRACK_H__ - -#define CFO_TH_XTAL_HIGH 20 /* kHz */ -#define CFO_TH_XTAL_LOW 10 /* kHz */ -#define CFO_TH_ATC 80 /* kHz */ - -struct cfo_tracking { - bool bATCStatus; - bool largeCFOHit; - bool bAdjust; - u8 CrystalCap; - u8 DefXCap; - int CFO_tail[2]; - int CFO_ave_pre; - u32 packetCount; - u32 packetCount_pre; - - bool bForceXtalCap; - bool bReset; -}; - -void ODM_CfoTrackingReset(void *pDM_VOID -); - -void ODM_CfoTrackingInit(void *pDM_VOID); - -void ODM_CfoTracking(void *pDM_VOID); - -void odm_parsing_cfo(void *pDM_VOID, void *pPktinfo_VOID, s8 *pcfotail); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_DIG.c b/drivers/staging/rtl8723bs/hal/odm_DIG.c deleted file mode 100644 index c862c86b7695..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_DIG.c +++ /dev/null @@ -1,799 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -void odm_NHMCounterStatisticsInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - /* PHY parameters initialize for n series */ - rtw_write16(pDM_Odm->Adapter, ODM_REG_NHM_TIMER_11N+2, 0x2710); /* 0x894[31:16]= 0x2710 Time duration for NHM unit: 4us, 0x2710 =40ms */ - /* rtw_write16(pDM_Odm->Adapter, ODM_REG_NHM_TIMER_11N+2, 0x4e20); 0x894[31:16]= 0x4e20 Time duration for NHM unit: 4us, 0x4e20 =80ms */ - rtw_write16(pDM_Odm->Adapter, ODM_REG_NHM_TH9_TH10_11N+2, 0xffff); /* 0x890[31:16]= 0xffff th_9, th_10 */ - /* rtw_write32(pDM_Odm->Adapter, ODM_REG_NHM_TH3_TO_TH0_11N, 0xffffff5c); 0x898 = 0xffffff5c th_3, th_2, th_1, th_0 */ - rtw_write32(pDM_Odm->Adapter, ODM_REG_NHM_TH3_TO_TH0_11N, 0xffffff52); /* 0x898 = 0xffffff52 th_3, th_2, th_1, th_0 */ - rtw_write32(pDM_Odm->Adapter, ODM_REG_NHM_TH7_TO_TH4_11N, 0xffffffff); /* 0x89c = 0xffffffff th_7, th_6, th_5, th_4 */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_FPGA0_IQK_11N, bMaskByte0, 0xff); /* 0xe28[7:0]= 0xff th_8 */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_NHM_TH9_TH10_11N, BIT(10)|BIT(9)|BIT(8), 0x7); /* 0x890[9:8]=3 enable CCX */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_OFDM_FA_RSTC_11N, BIT(7), 0x1); /* 0xc0c[7]= 1 max power among all RX ants */ -} - -void odm_NHMCounterStatistics(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - /* Get NHM report */ - odm_GetNHMCounterStatistics(pDM_Odm); - - /* Reset NHM counter */ - odm_NHMCounterStatisticsReset(pDM_Odm); -} - -void odm_GetNHMCounterStatistics(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - u32 value32 = 0; - - value32 = PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG_NHM_CNT_11N, bMaskDWord); - - pDM_Odm->NHM_cnt_0 = (u8)(value32 & bMaskByte0); -} - -void odm_NHMCounterStatisticsReset(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_NHM_TH9_TH10_11N, BIT(1), 0); - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_NHM_TH9_TH10_11N, BIT(1), 1); -} - -void odm_NHMBBInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - pDM_Odm->adaptivity_flag = false; - pDM_Odm->tolerance_cnt = 3; - pDM_Odm->NHMLastTxOkcnt = 0; - pDM_Odm->NHMLastRxOkcnt = 0; - pDM_Odm->NHMCurTxOkcnt = 0; - pDM_Odm->NHMCurRxOkcnt = 0; -} - -/* */ -void odm_NHMBB(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - /* u8 test_status; */ - /* struct false_ALARM_STATISTICS *pFalseAlmCnt = &pDM_Odm->FalseAlmCnt; */ - - pDM_Odm->NHMCurTxOkcnt = - *(pDM_Odm->pNumTxBytesUnicast)-pDM_Odm->NHMLastTxOkcnt; - pDM_Odm->NHMCurRxOkcnt = - *(pDM_Odm->pNumRxBytesUnicast)-pDM_Odm->NHMLastRxOkcnt; - pDM_Odm->NHMLastTxOkcnt = - *(pDM_Odm->pNumTxBytesUnicast); - pDM_Odm->NHMLastRxOkcnt = - *(pDM_Odm->pNumRxBytesUnicast); - - if ((pDM_Odm->NHMCurTxOkcnt) + 1 > (u64)(pDM_Odm->NHMCurRxOkcnt<<2) + 1) { /* Tx > 4*Rx possible for adaptivity test */ - if (pDM_Odm->NHM_cnt_0 >= 190 || pDM_Odm->adaptivity_flag) { - /* Enable EDCCA since it is possible running Adaptivity testing */ - /* test_status = 1; */ - pDM_Odm->adaptivity_flag = true; - pDM_Odm->tolerance_cnt = 0; - } else { - if (pDM_Odm->tolerance_cnt < 3) - pDM_Odm->tolerance_cnt = pDM_Odm->tolerance_cnt + 1; - else - pDM_Odm->tolerance_cnt = 4; - /* test_status = 5; */ - if (pDM_Odm->tolerance_cnt > 3) { - /* test_status = 3; */ - pDM_Odm->adaptivity_flag = false; - } - } - } else { /* TXadaptivity_flag && pDM_Odm->NHM_cnt_0 <= 200) { - /* test_status = 2; */ - pDM_Odm->tolerance_cnt = 0; - } else { - if (pDM_Odm->tolerance_cnt < 3) - pDM_Odm->tolerance_cnt = pDM_Odm->tolerance_cnt + 1; - else - pDM_Odm->tolerance_cnt = 4; - /* test_status = 5; */ - if (pDM_Odm->tolerance_cnt > 3) { - /* test_status = 4; */ - pDM_Odm->adaptivity_flag = false; - } - } - } -} - -void odm_SearchPwdBLowerBound(void *pDM_VOID, u8 IGI_target) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - u32 value32 = 0; - u8 cnt, IGI; - bool bAdjust = true; - s8 TH_L2H_dmc, TH_H2L_dmc; - s8 Diff; - - IGI = 0x50; /* find H2L, L2H lower bound */ - ODM_Write_DIG(pDM_Odm, IGI); - - Diff = IGI_target-(s8)IGI; - TH_L2H_dmc = pDM_Odm->TH_L2H_ini + Diff; - if (TH_L2H_dmc > 10) - TH_L2H_dmc = 10; - TH_H2L_dmc = TH_L2H_dmc - pDM_Odm->TH_EDCCA_HL_diff; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte0, (u8)TH_L2H_dmc); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte2, (u8)TH_H2L_dmc); - - mdelay(5); - - while (bAdjust) { - for (cnt = 0; cnt < 20; cnt++) { - value32 = PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG_RPT_11N, bMaskDWord); - - if (value32 & BIT(30)) - pDM_Odm->txEdcca1 = pDM_Odm->txEdcca1 + 1; - else if (value32 & BIT(29)) - pDM_Odm->txEdcca1 = pDM_Odm->txEdcca1 + 1; - else - pDM_Odm->txEdcca0 = pDM_Odm->txEdcca0 + 1; - } - - if (pDM_Odm->txEdcca1 > 5) { - IGI = IGI-1; - TH_L2H_dmc = TH_L2H_dmc + 1; - if (TH_L2H_dmc > 10) - TH_L2H_dmc = 10; - TH_H2L_dmc = TH_L2H_dmc - pDM_Odm->TH_EDCCA_HL_diff; - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte0, (u8)TH_L2H_dmc); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte2, (u8)TH_H2L_dmc); - - pDM_Odm->TxHangFlg = true; - pDM_Odm->txEdcca1 = 0; - pDM_Odm->txEdcca0 = 0; - - if (TH_L2H_dmc == 10) { - bAdjust = false; - pDM_Odm->TxHangFlg = false; - pDM_Odm->txEdcca1 = 0; - pDM_Odm->txEdcca0 = 0; - pDM_Odm->H2L_lb = TH_H2L_dmc; - pDM_Odm->L2H_lb = TH_L2H_dmc; - pDM_Odm->Adaptivity_IGI_upper = IGI; - } - } else { - bAdjust = false; - pDM_Odm->TxHangFlg = false; - pDM_Odm->txEdcca1 = 0; - pDM_Odm->txEdcca0 = 0; - pDM_Odm->H2L_lb = TH_H2L_dmc; - pDM_Odm->L2H_lb = TH_L2H_dmc; - pDM_Odm->Adaptivity_IGI_upper = IGI; - } - } -} - -void odm_AdaptivityInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - if (!pDM_Odm->Carrier_Sense_enable) - pDM_Odm->TH_L2H_ini = 0xf7; /* -7 */ - else - pDM_Odm->TH_L2H_ini = 0xa; - - pDM_Odm->AdapEn_RSSI = 20; - pDM_Odm->TH_EDCCA_HL_diff = 7; - - pDM_Odm->IGI_Base = 0x32; - pDM_Odm->IGI_target = 0x1c; - pDM_Odm->ForceEDCCA = 0; - pDM_Odm->NHM_disable = false; - pDM_Odm->TxHangFlg = true; - pDM_Odm->txEdcca0 = 0; - pDM_Odm->txEdcca1 = 0; - pDM_Odm->H2L_lb = 0; - pDM_Odm->L2H_lb = 0; - pDM_Odm->Adaptivity_IGI_upper = 0; - odm_NHMBBInit(pDM_Odm); - - PHY_SetBBReg(pDM_Odm->Adapter, REG_RD_CTRL, BIT(11), 1); /* stop counting if EDCCA is asserted */ -} - -void odm_Adaptivity(void *pDM_VOID, u8 IGI) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - s8 TH_L2H_dmc, TH_H2L_dmc; - s8 Diff, IGI_target; - bool EDCCA_State = false; - - if (!(pDM_Odm->SupportAbility & ODM_BB_ADAPTIVITY)) - return; - - if (*pDM_Odm->pBandWidth == ODM_BW20M) /* CHANNEL_WIDTH_20 */ - IGI_target = pDM_Odm->IGI_Base; - else if (*pDM_Odm->pBandWidth == ODM_BW40M) - IGI_target = pDM_Odm->IGI_Base + 2; - else - IGI_target = pDM_Odm->IGI_Base; - pDM_Odm->IGI_target = (u8) IGI_target; - - /* Search pwdB lower bound */ - if (pDM_Odm->TxHangFlg) { - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_DBG_RPT_11N, bMaskDWord, 0x208); - odm_SearchPwdBLowerBound(pDM_Odm, pDM_Odm->IGI_target); - } - - if ((!pDM_Odm->bLinked) || (*pDM_Odm->pChannel > 149)) { /* Band4 doesn't need adaptivity */ - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte0, 0x7f); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte2, 0x7f); - return; - } - - if (!pDM_Odm->ForceEDCCA) { - if (pDM_Odm->RSSI_Min > pDM_Odm->AdapEn_RSSI) - EDCCA_State = true; - else if (pDM_Odm->RSSI_Min < (pDM_Odm->AdapEn_RSSI - 5)) - EDCCA_State = false; - } else - EDCCA_State = true; - - if (pDM_Odm->bLinked && - !pDM_Odm->Carrier_Sense_enable && - !pDM_Odm->NHM_disable && - !pDM_Odm->TxHangFlg) - odm_NHMBB(pDM_Odm); - - if (EDCCA_State) { - Diff = IGI_target-(s8)IGI; - TH_L2H_dmc = pDM_Odm->TH_L2H_ini + Diff; - if (TH_L2H_dmc > 10) - TH_L2H_dmc = 10; - - TH_H2L_dmc = TH_L2H_dmc - pDM_Odm->TH_EDCCA_HL_diff; - - /* replace lower bound to prevent EDCCA always equal */ - if (TH_H2L_dmc < pDM_Odm->H2L_lb) - TH_H2L_dmc = pDM_Odm->H2L_lb; - if (TH_L2H_dmc < pDM_Odm->L2H_lb) - TH_L2H_dmc = pDM_Odm->L2H_lb; - } else { - TH_L2H_dmc = 0x7f; - TH_H2L_dmc = 0x7f; - } - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte0, (u8)TH_L2H_dmc); - PHY_SetBBReg(pDM_Odm->Adapter, rOFDM0_ECCAThreshold, bMaskByte2, (u8)TH_H2L_dmc); -} - -void ODM_Write_DIG(void *pDM_VOID, u8 CurrentIGI) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - - if (pDM_DigTable->bStopDIG) - return; - - if (pDM_DigTable->CurIGValue != CurrentIGI) { - /* 1 Check initial gain by upper bound */ - if (!pDM_DigTable->bPSDInProgress) { - if (CurrentIGI > pDM_DigTable->rx_gain_range_max) - CurrentIGI = pDM_DigTable->rx_gain_range_max; - - } - - /* 1 Set IGI value */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG(IGI_A), ODM_BIT(IGI), CurrentIGI); - - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG(IGI_B), ODM_BIT(IGI), CurrentIGI); - - pDM_DigTable->CurIGValue = CurrentIGI; - } - -} - -bool odm_DigAbort(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - /* SupportAbility */ - if (!(pDM_Odm->SupportAbility & ODM_BB_FA_CNT)) - return true; - - /* SupportAbility */ - if (!(pDM_Odm->SupportAbility & ODM_BB_DIG)) - return true; - - /* ScanInProcess */ - if (*(pDM_Odm->pbScanInProcess)) - return true; - - /* add by Neil Chen to avoid PSD is processing */ - if (!pDM_Odm->bDMInitialGainEnable) - return true; - - return false; -} - -void odm_DIGInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - - pDM_DigTable->bStopDIG = false; - pDM_DigTable->bPSDInProgress = false; - pDM_DigTable->CurIGValue = (u8) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(IGI_A), ODM_BIT(IGI)); - pDM_DigTable->RssiLowThresh = DM_DIG_THRESH_LOW; - pDM_DigTable->RssiHighThresh = DM_DIG_THRESH_HIGH; - pDM_DigTable->FALowThresh = DMfalseALARM_THRESH_LOW; - pDM_DigTable->FAHighThresh = DMfalseALARM_THRESH_HIGH; - pDM_DigTable->BackoffVal = DM_DIG_BACKOFF_DEFAULT; - pDM_DigTable->BackoffVal_range_max = DM_DIG_BACKOFF_MAX; - pDM_DigTable->BackoffVal_range_min = DM_DIG_BACKOFF_MIN; - pDM_DigTable->PreCCK_CCAThres = 0xFF; - pDM_DigTable->CurCCK_CCAThres = 0x83; - pDM_DigTable->ForbiddenIGI = DM_DIG_MIN_NIC; - pDM_DigTable->LargeFAHit = 0; - pDM_DigTable->Recover_cnt = 0; - pDM_DigTable->bMediaConnect_0 = false; - pDM_DigTable->bMediaConnect_1 = false; - - /* To Initialize pDM_Odm->bDMInitialGainEnable == false to avoid DIG error */ - pDM_Odm->bDMInitialGainEnable = true; - - pDM_DigTable->DIG_Dynamic_MIN_0 = DM_DIG_MIN_NIC; - pDM_DigTable->DIG_Dynamic_MIN_1 = DM_DIG_MIN_NIC; - - /* To Initi BT30 IGI */ - pDM_DigTable->BT30_CurIGI = 0x32; - - pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC; - pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC; -} - -void odm_DIG(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - /* Common parameters */ - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - struct false_ALARM_STATISTICS *pFalseAlmCnt = &pDM_Odm->FalseAlmCnt; - bool FirstConnect, FirstDisConnect; - u8 DIG_MaxOfMin, DIG_Dynamic_MIN; - u8 dm_dig_max, dm_dig_min; - u8 CurrentIGI = pDM_DigTable->CurIGValue; - u8 offset; - u32 dm_FA_thres[3]; - u8 Adap_IGI_Upper = 0; - u32 TxTp = 0, RxTp = 0; - bool bDFSBand = false; - bool bPerformance = true, bFirstTpTarget = false, bFirstCoverage = false; - - if (odm_DigAbort(pDM_Odm)) - return; - - if (pDM_Odm->adaptivity_flag) - Adap_IGI_Upper = pDM_Odm->Adaptivity_IGI_upper; - - /* 1 Update status */ - DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_0; - FirstConnect = (pDM_Odm->bLinked) && !pDM_DigTable->bMediaConnect_0; - FirstDisConnect = (!pDM_Odm->bLinked) && pDM_DigTable->bMediaConnect_0; - - /* 1 Boundary Decision */ - /* 2 For WIN\CE */ - dm_dig_max = 0x5A; - dm_dig_min = DM_DIG_MIN_NIC; - DIG_MaxOfMin = DM_DIG_MAX_AP; - - /* 1 Adjust boundary by RSSI */ - if (pDM_Odm->bLinked && bPerformance) { - /* 2 Modify DIG upper bound */ - /* 4 Modify DIG upper bound for 92E, 8723A\B, 8821 & 8812 BT */ - if (pDM_Odm->bBtLimitedDig == 1) - offset = 10; - else - offset = 15; - - if ((pDM_Odm->RSSI_Min + offset) > dm_dig_max) - pDM_DigTable->rx_gain_range_max = dm_dig_max; - else if ((pDM_Odm->RSSI_Min + offset) < dm_dig_min) - pDM_DigTable->rx_gain_range_max = dm_dig_min; - else - pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + offset; - - /* 2 Modify DIG lower bound */ - /* if (pDM_Odm->bOneEntryOnly) */ - { - if (pDM_Odm->RSSI_Min < dm_dig_min) - DIG_Dynamic_MIN = dm_dig_min; - else if (pDM_Odm->RSSI_Min > DIG_MaxOfMin) - DIG_Dynamic_MIN = DIG_MaxOfMin; - else - DIG_Dynamic_MIN = pDM_Odm->RSSI_Min; - } - } else { - pDM_DigTable->rx_gain_range_max = dm_dig_max; - DIG_Dynamic_MIN = dm_dig_min; - } - - /* 1 Force Lower Bound for AntDiv */ - if (pDM_Odm->bLinked && !pDM_Odm->bOneEntryOnly) { - if (pDM_Odm->SupportAbility & ODM_BB_ANT_DIV) { - if ( - pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV || - pDM_Odm->AntDivType == CG_TRX_SMART_ANTDIV || - pDM_Odm->AntDivType == S0S1_SW_ANTDIV - ) { - if (pDM_DigTable->AntDiv_RSSI_max > DIG_MaxOfMin) - DIG_Dynamic_MIN = DIG_MaxOfMin; - else - DIG_Dynamic_MIN = (u8) pDM_DigTable->AntDiv_RSSI_max; - } - } - } - - /* 1 Modify DIG lower bound, deal with abnormal case */ - /* 2 Abnormal false alarm case */ - if (FirstDisConnect) { - pDM_DigTable->rx_gain_range_min = DIG_Dynamic_MIN; - pDM_DigTable->ForbiddenIGI = DIG_Dynamic_MIN; - } else - pDM_DigTable->rx_gain_range_min = - odm_ForbiddenIGICheck(pDM_Odm, DIG_Dynamic_MIN, CurrentIGI); - - if (pDM_Odm->bLinked && !FirstConnect) { - if ( - (pDM_Odm->PhyDbgInfo.NumQryBeaconPkt < 5) && - pDM_Odm->bsta_state - ) { - pDM_DigTable->rx_gain_range_min = dm_dig_min; - } - } - - /* 2 Abnormal lower bound case */ - if (pDM_DigTable->rx_gain_range_min > pDM_DigTable->rx_gain_range_max) - pDM_DigTable->rx_gain_range_min = pDM_DigTable->rx_gain_range_max; - - /* 1 False alarm threshold decision */ - odm_FAThresholdCheck(pDM_Odm, bDFSBand, bPerformance, RxTp, TxTp, dm_FA_thres); - - /* 1 Adjust initial gain by false alarm */ - if (pDM_Odm->bLinked && bPerformance) { - - if (bFirstTpTarget || FirstConnect) { - pDM_DigTable->LargeFAHit = 0; - - if (pDM_Odm->RSSI_Min < DIG_MaxOfMin) { - if (CurrentIGI < pDM_Odm->RSSI_Min) - CurrentIGI = pDM_Odm->RSSI_Min; - } else { - if (CurrentIGI < DIG_MaxOfMin) - CurrentIGI = DIG_MaxOfMin; - } - - } else { - if (pFalseAlmCnt->Cnt_all > dm_FA_thres[2]) - CurrentIGI = CurrentIGI + 4; - else if (pFalseAlmCnt->Cnt_all > dm_FA_thres[1]) - CurrentIGI = CurrentIGI + 2; - else if (pFalseAlmCnt->Cnt_all < dm_FA_thres[0]) - CurrentIGI = CurrentIGI - 2; - - if ( - (pDM_Odm->PhyDbgInfo.NumQryBeaconPkt < 5) && - (pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH1) && - (pDM_Odm->bsta_state) - ) { - CurrentIGI = pDM_DigTable->rx_gain_range_min; - } - } - } else { - - if (FirstDisConnect || bFirstCoverage) { - CurrentIGI = dm_dig_min; - } else { - if (pFalseAlmCnt->Cnt_all > dm_FA_thres[2]) - CurrentIGI = CurrentIGI + 4; - else if (pFalseAlmCnt->Cnt_all > dm_FA_thres[1]) - CurrentIGI = CurrentIGI + 2; - else if (pFalseAlmCnt->Cnt_all < dm_FA_thres[0]) - CurrentIGI = CurrentIGI - 2; - } - } - - /* 1 Check initial gain by upper/lower bound */ - if (CurrentIGI < pDM_DigTable->rx_gain_range_min) - CurrentIGI = pDM_DigTable->rx_gain_range_min; - - if (CurrentIGI > pDM_DigTable->rx_gain_range_max) - CurrentIGI = pDM_DigTable->rx_gain_range_max; - - /* 1 Force upper bound and lower bound for adaptivity */ - if (pDM_Odm->SupportAbility & ODM_BB_ADAPTIVITY && - pDM_Odm->adaptivity_flag) { - if (CurrentIGI > Adap_IGI_Upper) - CurrentIGI = Adap_IGI_Upper; - - if (pDM_Odm->IGI_LowerBound != 0) { - if (CurrentIGI < pDM_Odm->IGI_LowerBound) - CurrentIGI = pDM_Odm->IGI_LowerBound; - } - } - - /* 1 Update status */ - if (pDM_Odm->bBtHsOperation) { - if (pDM_Odm->bLinked) { - if (pDM_DigTable->BT30_CurIGI > (CurrentIGI)) - ODM_Write_DIG(pDM_Odm, CurrentIGI); - else - ODM_Write_DIG(pDM_Odm, pDM_DigTable->BT30_CurIGI); - - pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked; - pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN; - } else { - if (pDM_Odm->bLinkInProcess) - ODM_Write_DIG(pDM_Odm, 0x1c); - else if (pDM_Odm->bBtConnectProcess) - ODM_Write_DIG(pDM_Odm, 0x28); - else - ODM_Write_DIG(pDM_Odm, pDM_DigTable->BT30_CurIGI);/* ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue); */ - } - } else { /* BT is not using */ - ODM_Write_DIG(pDM_Odm, CurrentIGI);/* ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue); */ - pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked; - pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN; - } -} - -void odm_DIGbyRSSI_LPS(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct false_ALARM_STATISTICS *pFalseAlmCnt = &pDM_Odm->FalseAlmCnt; - - u8 RSSI_Lower = DM_DIG_MIN_NIC; /* 0x1E or 0x1C */ - u8 CurrentIGI = pDM_Odm->RSSI_Min; - - CurrentIGI = CurrentIGI+RSSI_OFFSET_DIG; - - /* Using FW PS mode to make IGI */ - /* Adjust by FA in LPS MODE */ - if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH2_LPS) - CurrentIGI = CurrentIGI+4; - else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1_LPS) - CurrentIGI = CurrentIGI+2; - else if (pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0_LPS) - CurrentIGI = CurrentIGI-2; - - /* Lower bound checking */ - - /* RSSI Lower bound check */ - RSSI_Lower = max(pDM_Odm->RSSI_Min - 10, DM_DIG_MIN_NIC); - - /* Upper and Lower Bound checking */ - if (CurrentIGI > DM_DIG_MAX_NIC) - CurrentIGI = DM_DIG_MAX_NIC; - else if (CurrentIGI < RSSI_Lower) - CurrentIGI = RSSI_Lower; - - ODM_Write_DIG(pDM_Odm, CurrentIGI); - /* ODM_Write_DIG(pDM_Odm, pDM_DigTable->CurIGValue); */ -} - -/* 3 ============================================================ */ -/* 3 FALSE ALARM CHECK */ -/* 3 ============================================================ */ - -void odm_FalseAlarmCounterStatistics(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct false_ALARM_STATISTICS *FalseAlmCnt = &pDM_Odm->FalseAlmCnt; - u32 ret_value; - - if (!(pDM_Odm->SupportAbility & ODM_BB_FA_CNT)) - return; - - /* hold ofdm counter */ - /* hold page C counter */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_OFDM_FA_HOLDC_11N, BIT(31), 1); - /* hold page D counter */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_OFDM_FA_RSTD_11N, BIT(31), 1); - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_OFDM_FA_TYPE1_11N, bMaskDWord - ); - FalseAlmCnt->Cnt_Fast_Fsync = (ret_value&0xffff); - FalseAlmCnt->Cnt_SB_Search_fail = ((ret_value&0xffff0000)>>16); - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_OFDM_FA_TYPE2_11N, bMaskDWord - ); - FalseAlmCnt->Cnt_OFDM_CCA = (ret_value&0xffff); - FalseAlmCnt->Cnt_Parity_Fail = ((ret_value&0xffff0000)>>16); - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_OFDM_FA_TYPE3_11N, bMaskDWord - ); - FalseAlmCnt->Cnt_Rate_Illegal = (ret_value&0xffff); - FalseAlmCnt->Cnt_Crc8_fail = ((ret_value&0xffff0000)>>16); - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_OFDM_FA_TYPE4_11N, bMaskDWord - ); - FalseAlmCnt->Cnt_Mcs_fail = (ret_value&0xffff); - - FalseAlmCnt->Cnt_Ofdm_fail = - FalseAlmCnt->Cnt_Parity_Fail + - FalseAlmCnt->Cnt_Rate_Illegal + - FalseAlmCnt->Cnt_Crc8_fail + - FalseAlmCnt->Cnt_Mcs_fail + - FalseAlmCnt->Cnt_Fast_Fsync + - FalseAlmCnt->Cnt_SB_Search_fail; - - { - /* hold cck counter */ - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_CCK_FA_RST_11N, BIT(12), 1); - PHY_SetBBReg(pDM_Odm->Adapter, ODM_REG_CCK_FA_RST_11N, BIT(14), 1); - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_CCK_FA_LSB_11N, bMaskByte0 - ); - FalseAlmCnt->Cnt_Cck_fail = ret_value; - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_CCK_FA_MSB_11N, bMaskByte3 - ); - FalseAlmCnt->Cnt_Cck_fail += (ret_value&0xff)<<8; - - ret_value = PHY_QueryBBReg( - pDM_Odm->Adapter, ODM_REG_CCK_CCA_CNT_11N, bMaskDWord - ); - FalseAlmCnt->Cnt_CCK_CCA = - ((ret_value&0xFF)<<8) | ((ret_value&0xFF00)>>8); - } - - FalseAlmCnt->Cnt_all = ( - FalseAlmCnt->Cnt_Fast_Fsync + - FalseAlmCnt->Cnt_SB_Search_fail + - FalseAlmCnt->Cnt_Parity_Fail + - FalseAlmCnt->Cnt_Rate_Illegal + - FalseAlmCnt->Cnt_Crc8_fail + - FalseAlmCnt->Cnt_Mcs_fail + - FalseAlmCnt->Cnt_Cck_fail - ); - - FalseAlmCnt->Cnt_CCA_all = - FalseAlmCnt->Cnt_OFDM_CCA + FalseAlmCnt->Cnt_CCK_CCA; -} - -void odm_FAThresholdCheck( - void *pDM_VOID, - bool bDFSBand, - bool bPerformance, - u32 RxTp, - u32 TxTp, - u32 *dm_FA_thres -) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - if (pDM_Odm->bLinked && (bPerformance || bDFSBand)) { - /* For NIC */ - dm_FA_thres[0] = DM_DIG_FA_TH0; - dm_FA_thres[1] = DM_DIG_FA_TH1; - dm_FA_thres[2] = DM_DIG_FA_TH2; - } else { - dm_FA_thres[0] = 2000; - dm_FA_thres[1] = 4000; - dm_FA_thres[2] = 5000; - } -} - -u8 odm_ForbiddenIGICheck(void *pDM_VOID, u8 DIG_Dynamic_MIN, u8 CurrentIGI) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - struct false_ALARM_STATISTICS *pFalseAlmCnt = &pDM_Odm->FalseAlmCnt; - u8 rx_gain_range_min = pDM_DigTable->rx_gain_range_min; - - if (pFalseAlmCnt->Cnt_all > 10000) { - if (pDM_DigTable->LargeFAHit != 3) - pDM_DigTable->LargeFAHit++; - - /* if (pDM_DigTable->ForbiddenIGI < pDM_DigTable->CurIGValue) */ - if (pDM_DigTable->ForbiddenIGI < CurrentIGI) { - pDM_DigTable->ForbiddenIGI = CurrentIGI; - /* pDM_DigTable->ForbiddenIGI = pDM_DigTable->CurIGValue; */ - pDM_DigTable->LargeFAHit = 1; - } - - if (pDM_DigTable->LargeFAHit >= 3) { - if ((pDM_DigTable->ForbiddenIGI + 2) > pDM_DigTable->rx_gain_range_max) - rx_gain_range_min = pDM_DigTable->rx_gain_range_max; - else - rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 2); - pDM_DigTable->Recover_cnt = 1800; - } - } else { - if (pDM_DigTable->Recover_cnt != 0) { - pDM_DigTable->Recover_cnt--; - } else { - if (pDM_DigTable->LargeFAHit < 3) { - if ((pDM_DigTable->ForbiddenIGI - 2) < DIG_Dynamic_MIN) { /* DM_DIG_MIN) */ - pDM_DigTable->ForbiddenIGI = DIG_Dynamic_MIN; /* DM_DIG_MIN; */ - rx_gain_range_min = DIG_Dynamic_MIN; /* DM_DIG_MIN; */ - } else { - pDM_DigTable->ForbiddenIGI -= 2; - rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 2); - } - } else - pDM_DigTable->LargeFAHit = 0; - } - } - - return rx_gain_range_min; - -} - -/* 3 ============================================================ */ -/* 3 CCK Packet Detect Threshold */ -/* 3 ============================================================ */ - -void odm_CCKPacketDetectionThresh(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct false_ALARM_STATISTICS *FalseAlmCnt = &pDM_Odm->FalseAlmCnt; - u8 CurCCK_CCAThres; - - if ( - !(pDM_Odm->SupportAbility & ODM_BB_CCK_PD) || - !(pDM_Odm->SupportAbility & ODM_BB_FA_CNT) - ) { - return; - } - - if (pDM_Odm->ExtLNA) - return; - - if (pDM_Odm->bLinked) { - if (pDM_Odm->RSSI_Min > 25) - CurCCK_CCAThres = 0xcd; - else if ((pDM_Odm->RSSI_Min <= 25) && (pDM_Odm->RSSI_Min > 10)) - CurCCK_CCAThres = 0x83; - else { - if (FalseAlmCnt->Cnt_Cck_fail > 1000) - CurCCK_CCAThres = 0x83; - else - CurCCK_CCAThres = 0x40; - } - } else { - if (FalseAlmCnt->Cnt_Cck_fail > 1000) - CurCCK_CCAThres = 0x83; - else - CurCCK_CCAThres = 0x40; - } - - ODM_Write_CCK_CCA_Thres(pDM_Odm, CurCCK_CCAThres); -} - -void ODM_Write_CCK_CCA_Thres(void *pDM_VOID, u8 CurCCK_CCAThres) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - - /* modify by Guo.Mingzhi 2012-01-03 */ - if (pDM_DigTable->CurCCK_CCAThres != CurCCK_CCAThres) - rtw_write8(pDM_Odm->Adapter, ODM_REG(CCK_CCA), CurCCK_CCAThres); - - pDM_DigTable->PreCCK_CCAThres = pDM_DigTable->CurCCK_CCAThres; - pDM_DigTable->CurCCK_CCAThres = CurCCK_CCAThres; -} diff --git a/drivers/staging/rtl8723bs/hal/odm_DIG.h b/drivers/staging/rtl8723bs/hal/odm_DIG.h deleted file mode 100644 index 5517ef79bdf5..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_DIG.h +++ /dev/null @@ -1,164 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODMDIG_H__ -#define __ODMDIG_H__ - -struct dig_t { /* _Dynamic_Initial_Gain_Threshold_ */ - bool bStopDIG; - bool bPSDInProgress; - - u8 Dig_Enable_Flag; - u8 Dig_Ext_Port_Stage; - - int RssiLowThresh; - int RssiHighThresh; - - u32 FALowThresh; - u32 FAHighThresh; - - u8 CurSTAConnectState; - u8 PreSTAConnectState; - u8 CurMultiSTAConnectState; - - u8 PreIGValue; - u8 CurIGValue; - u8 BackupIGValue; /* MP DIG */ - u8 BT30_CurIGI; - u8 IGIBackup; - - s8 BackoffVal; - s8 BackoffVal_range_max; - s8 BackoffVal_range_min; - u8 rx_gain_range_max; - u8 rx_gain_range_min; - u8 Rssi_val_min; - - u8 PreCCK_CCAThres; - u8 CurCCK_CCAThres; - u8 PreCCKPDState; - u8 CurCCKPDState; - u8 CCKPDBackup; - - u8 LargeFAHit; - u8 ForbiddenIGI; - u32 Recover_cnt; - - u8 DIG_Dynamic_MIN_0; - u8 DIG_Dynamic_MIN_1; - bool bMediaConnect_0; - bool bMediaConnect_1; - - u32 AntDiv_RSSI_max; - u32 RSSI_max; - - u8 *pbP2pLinkInProgress; -}; - -struct false_ALARM_STATISTICS { - u32 Cnt_Parity_Fail; - u32 Cnt_Rate_Illegal; - u32 Cnt_Crc8_fail; - u32 Cnt_Mcs_fail; - u32 Cnt_Ofdm_fail; - u32 Cnt_Ofdm_fail_pre; /* For RTL8881A */ - u32 Cnt_Cck_fail; - u32 Cnt_all; - u32 Cnt_Fast_Fsync; - u32 Cnt_SB_Search_fail; - u32 Cnt_OFDM_CCA; - u32 Cnt_CCK_CCA; - u32 Cnt_CCA_all; - u32 Cnt_BW_USC; /* Gary */ - u32 Cnt_BW_LSC; /* Gary */ -}; - -#define DM_DIG_THRESH_HIGH 40 -#define DM_DIG_THRESH_LOW 35 - -#define DMfalseALARM_THRESH_LOW 400 -#define DMfalseALARM_THRESH_HIGH 1000 - -#define DM_DIG_MAX_NIC 0x3e -#define DM_DIG_MIN_NIC 0x1e /* 0x22//0x1c */ -#define DM_DIG_MAX_OF_MIN_NIC 0x3e - -#define DM_DIG_MAX_AP 0x3e -#define DM_DIG_MIN_AP 0x1c -#define DM_DIG_MAX_OF_MIN 0x2A /* 0x32 */ -#define DM_DIG_MIN_AP_DFS 0x20 - -#define DM_DIG_MAX_NIC_HP 0x46 -#define DM_DIG_MIN_NIC_HP 0x2e - -#define DM_DIG_MAX_AP_HP 0x42 -#define DM_DIG_MIN_AP_HP 0x30 - -#define DM_DIG_FA_TH0 0x200/* 0x20 */ - -#define DM_DIG_FA_TH1 0x300 -#define DM_DIG_FA_TH2 0x400 -/* this is for 92d */ -#define DM_DIG_FA_TH0_92D 0x100 -#define DM_DIG_FA_TH1_92D 0x400 -#define DM_DIG_FA_TH2_92D 0x600 - -#define DM_DIG_BACKOFF_MAX 12 -#define DM_DIG_BACKOFF_MIN -4 -#define DM_DIG_BACKOFF_DEFAULT 10 - -#define DM_DIG_FA_TH0_LPS 4 /* 4 in lps */ -#define DM_DIG_FA_TH1_LPS 15 /* 15 lps */ -#define DM_DIG_FA_TH2_LPS 30 /* 30 lps */ -#define RSSI_OFFSET_DIG 0x05 - -void odm_NHMCounterStatisticsInit(void *pDM_VOID); - -void odm_NHMCounterStatistics(void *pDM_VOID); - -void odm_NHMBBInit(void *pDM_VOID); - -void odm_NHMBB(void *pDM_VOID); - -void odm_NHMCounterStatisticsReset(void *pDM_VOID); - -void odm_GetNHMCounterStatistics(void *pDM_VOID); - -void odm_SearchPwdBLowerBound(void *pDM_VOID, u8 IGI_target); - -void odm_AdaptivityInit(void *pDM_VOID); - -void odm_Adaptivity(void *pDM_VOID, u8 IGI); - -void ODM_Write_DIG(void *pDM_VOID, u8 CurrentIGI); - -void odm_DIGInit(void *pDM_VOID); - -void odm_DIG(void *pDM_VOID); - -void odm_DIGbyRSSI_LPS(void *pDM_VOID); - -void odm_FalseAlarmCounterStatistics(void *pDM_VOID); - -void odm_FAThresholdCheck( - void *pDM_VOID, - bool bDFSBand, - bool bPerformance, - u32 RxTp, - u32 TxTp, - u32 *dm_FA_thres -); - -u8 odm_ForbiddenIGICheck(void *pDM_VOID, u8 DIG_Dynamic_MIN, u8 CurrentIGI); - -bool odm_DigAbort(void *pDM_VOID); - -void odm_CCKPacketDetectionThresh(void *pDM_VOID); - -void ODM_Write_CCK_CCA_Thres(void *pDM_VOID, u8 CurCCK_CCAThres); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.c b/drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.c deleted file mode 100644 index ba6357c6a7ed..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.c +++ /dev/null @@ -1,81 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -void odm_DynamicBBPowerSavingInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct ps_t *pDM_PSTable = &pDM_Odm->DM_PSTable; - - pDM_PSTable->PreCCAState = CCA_MAX; - pDM_PSTable->CurCCAState = CCA_MAX; - pDM_PSTable->PreRFState = RF_MAX; - pDM_PSTable->CurRFState = RF_MAX; - pDM_PSTable->Rssi_val_min = 0; - pDM_PSTable->initialize = 0; -} - -void ODM_RF_Saving(void *pDM_VOID, u8 bForceInNormal) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct ps_t *pDM_PSTable = &pDM_Odm->DM_PSTable; - u8 Rssi_Up_bound = 30; - u8 Rssi_Low_bound = 25; - - if (pDM_Odm->PatchID == 40) { /* RT_CID_819x_FUNAI_TV */ - Rssi_Up_bound = 50; - Rssi_Low_bound = 45; - } - - if (pDM_PSTable->initialize == 0) { - - pDM_PSTable->Reg874 = (PHY_QueryBBReg(pDM_Odm->Adapter, 0x874, bMaskDWord)&0x1CC000)>>14; - pDM_PSTable->RegC70 = (PHY_QueryBBReg(pDM_Odm->Adapter, 0xc70, bMaskDWord)&BIT(3))>>3; - pDM_PSTable->Reg85C = (PHY_QueryBBReg(pDM_Odm->Adapter, 0x85c, bMaskDWord)&0xFF000000)>>24; - pDM_PSTable->RegA74 = (PHY_QueryBBReg(pDM_Odm->Adapter, 0xa74, bMaskDWord)&0xF000)>>12; - /* Reg818 = PHY_QueryBBReg(padapter, 0x818, bMaskDWord); */ - pDM_PSTable->initialize = 1; - } - - if (!bForceInNormal) { - if (pDM_Odm->RSSI_Min != 0xFF) { - if (pDM_PSTable->PreRFState == RF_Normal) { - if (pDM_Odm->RSSI_Min >= Rssi_Up_bound) - pDM_PSTable->CurRFState = RF_Save; - else - pDM_PSTable->CurRFState = RF_Normal; - } else { - if (pDM_Odm->RSSI_Min <= Rssi_Low_bound) - pDM_PSTable->CurRFState = RF_Normal; - else - pDM_PSTable->CurRFState = RF_Save; - } - } else - pDM_PSTable->CurRFState = RF_MAX; - } else - pDM_PSTable->CurRFState = RF_Normal; - - if (pDM_PSTable->PreRFState != pDM_PSTable->CurRFState) { - if (pDM_PSTable->CurRFState == RF_Save) { - PHY_SetBBReg(pDM_Odm->Adapter, 0x874, 0x1C0000, 0x2); /* Reg874[20:18]=3'b010 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0xc70, BIT(3), 0); /* RegC70[3]= 1'b0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x85c, 0xFF000000, 0x63); /* Reg85C[31:24]= 0x63 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x874, 0xC000, 0x2); /* Reg874[15:14]=2'b10 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0xa74, 0xF000, 0x3); /* RegA75[7:4]= 0x3 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x818, BIT(28), 0x0); /* Reg818[28]= 1'b0 */ - PHY_SetBBReg(pDM_Odm->Adapter, 0x818, BIT(28), 0x1); /* Reg818[28]= 1'b1 */ - } else { - PHY_SetBBReg(pDM_Odm->Adapter, 0x874, 0x1CC000, pDM_PSTable->Reg874); - PHY_SetBBReg(pDM_Odm->Adapter, 0xc70, BIT(3), pDM_PSTable->RegC70); - PHY_SetBBReg(pDM_Odm->Adapter, 0x85c, 0xFF000000, pDM_PSTable->Reg85C); - PHY_SetBBReg(pDM_Odm->Adapter, 0xa74, 0xF000, pDM_PSTable->RegA74); - PHY_SetBBReg(pDM_Odm->Adapter, 0x818, BIT(28), 0x0); - } - pDM_PSTable->PreRFState = pDM_PSTable->CurRFState; - } -} diff --git a/drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.h b/drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.h deleted file mode 100644 index 3ebbbfd1dd1f..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_DynamicBBPowerSaving.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODMDYNAMICBBPOWERSAVING_H__ -#define __ODMDYNAMICBBPOWERSAVING_H__ - -struct ps_t { /* _Dynamic_Power_Saving_ */ - u8 PreCCAState; - u8 CurCCAState; - - u8 PreRFState; - u8 CurRFState; - - int Rssi_val_min; - - u8 initialize; - u32 Reg874, RegC70, Reg85C, RegA74; - -}; - -#define dm_RF_Saving ODM_RF_Saving - -void ODM_RF_Saving(void *pDM_VOID, u8 bForceInNormal); - -void odm_DynamicBBPowerSavingInit(void *pDM_VOID); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.c b/drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.c deleted file mode 100644 index 398dfa13449d..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.c +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -void odm_DynamicTxPowerInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - struct adapter *Adapter = pDM_Odm->Adapter; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_priv *pdmpriv = &pHalData->dmpriv; - - pdmpriv->bDynamicTxPowerEnable = false; - - pdmpriv->LastDTPLvl = TxHighPwrLevel_Normal; - pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal; -} diff --git a/drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.h b/drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.h deleted file mode 100644 index e2d244324ebe..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_DynamicTxPower.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODMDYNAMICTXPOWER_H__ -#define __ODMDYNAMICTXPOWER_H__ - -#define TX_POWER_NEAR_FIELD_THRESH_LVL2 74 -#define TX_POWER_NEAR_FIELD_THRESH_LVL1 67 -#define TX_POWER_NEAR_FIELD_THRESH_AP 0x3F -#define TX_POWER_NEAR_FIELD_THRESH_8812 60 - -#define TxHighPwrLevel_Normal 0 -#define TxHighPwrLevel_Level1 1 -#define TxHighPwrLevel_Level2 2 -#define TxHighPwrLevel_BT1 3 -#define TxHighPwrLevel_BT2 4 -#define TxHighPwrLevel_15 5 -#define TxHighPwrLevel_35 6 -#define TxHighPwrLevel_50 7 -#define TxHighPwrLevel_70 8 -#define TxHighPwrLevel_100 9 - -void odm_DynamicTxPowerInit(void *pDM_VOID); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c b/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c deleted file mode 100644 index 9baca2aea80e..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -static u32 edca_setting_DL_GMode[HT_IOT_PEER_MAX] = { -/*UNKNOWN, REALTEK_90, ALTEK_92SE BROADCOM, LINK ATHEROS, - *CISCO, MERU, MARVELL, 92U_AP, SELF_AP - */ - 0x4322, 0xa44f, 0x5e4322, 0xa42b, 0x5e4322, 0x4322, - 0xa42b, 0x5ea42b, 0xa44f, 0x5e4322, 0x5ea42b -}; - -static u32 edca_setting_UL[HT_IOT_PEER_MAX] = { -/*UNKNOWN, REALTEK_90, REALTEK_92SE, BROADCOM, RALINK, ATHEROS, - *CISCO, MERU, MARVELL, 92U_AP, SELF_AP(DownLink/Tx) - */ - 0x5e4322, 0xa44f, 0x5e4322, 0x5ea32b, 0x5ea422, 0x5ea322, - 0x3ea430, 0x5ea42b, 0x5ea44f, 0x5e4322, 0x5e4322}; - -static u32 edca_setting_DL[HT_IOT_PEER_MAX] = { -/*UNKNOWN, REALTEK_90, REALTEK_92SE, BROADCOM, RALINK, ATHEROS, - *CISCO, MERU, MARVELL, 92U_AP, SELF_AP(UpLink/Rx) - */ - 0xa44f, 0x5ea44f, 0x5e4322, 0x5ea42b, 0xa44f, 0xa630, - 0x5ea630, 0x5ea42b, 0xa44f, 0xa42b, 0xa42b}; - -void ODM_EdcaTurboInit(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct adapter *Adapter = pDM_Odm->Adapter; - - pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = false; - pDM_Odm->DM_EDCA_Table.bIsCurRDLState = false; - Adapter->recvpriv.bIsAnyNonBEPkts = false; -} /* ODM_InitEdcaTurbo */ - -void odm_EdcaTurboCheck(void *pDM_VOID) -{ - /* In HW integration first stage, we provide 4 different handles to - * operate at the same time. In stage2/3, we need to prove universal - * interface and merge all HW dynamic mechanism. - */ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - - if (!(pDM_Odm->SupportAbility & ODM_MAC_EDCA_TURBO)) - return; - - odm_EdcaTurboCheckCE(pDM_Odm); -} /* odm_CheckEdcaTurbo */ - -void odm_EdcaTurboCheckCE(void *pDM_VOID) -{ - struct dm_odm_t *pDM_Odm = (struct dm_odm_t *)pDM_VOID; - struct adapter *Adapter = pDM_Odm->Adapter; - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(Adapter); - struct recv_priv *precvpriv = &(Adapter->recvpriv); - struct registry_priv *pregpriv = &Adapter->registrypriv; - struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv); - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); - u32 EDCA_BE_UL = 0x5ea42b; - u32 EDCA_BE_DL = 0x5ea42b; - u32 iot_peer = 0; - u8 wirelessmode = 0xFF; /* invalid value */ - u32 trafficIndex; - u32 edca_param; - u64 cur_tx_bytes = 0; - u64 cur_rx_bytes = 0; - u8 bbtchange = false; - u8 biasonrx = false; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - if (!pDM_Odm->bLinked) { - precvpriv->bIsAnyNonBEPkts = false; - return; - } - - if (pregpriv->wifi_spec == 1) { - precvpriv->bIsAnyNonBEPkts = false; - return; - } - - if (pDM_Odm->pwirelessmode) - wirelessmode = *(pDM_Odm->pwirelessmode); - - iot_peer = pmlmeinfo->assoc_AP_vendor; - - if (iot_peer >= HT_IOT_PEER_MAX) { - precvpriv->bIsAnyNonBEPkts = false; - return; - } - - /* Check if the status needs to be changed. */ - if ((bbtchange) || (!precvpriv->bIsAnyNonBEPkts)) { - cur_tx_bytes = pdvobjpriv->traffic_stat.cur_tx_bytes; - cur_rx_bytes = pdvobjpriv->traffic_stat.cur_rx_bytes; - - /* traffic, TX or RX */ - if (biasonrx) { - if (cur_tx_bytes > (cur_rx_bytes << 2)) { - /* Uplink TP is present. */ - trafficIndex = UP_LINK; - } else { /* Balance TP is present. */ - trafficIndex = DOWN_LINK; - } - } else { - if (cur_rx_bytes > (cur_tx_bytes << 2)) { - /* Downlink TP is present. */ - trafficIndex = DOWN_LINK; - } else { /* Balance TP is present. */ - trafficIndex = UP_LINK; - } - } - - /* 92D txop can't be set to 0x3e for cisco1250 */ - if ((iot_peer == HT_IOT_PEER_CISCO) && - (wirelessmode == ODM_WM_N24G)) { - EDCA_BE_DL = edca_setting_DL[iot_peer]; - EDCA_BE_UL = edca_setting_UL[iot_peer]; - } else if ((iot_peer == HT_IOT_PEER_CISCO) && - ((wirelessmode == ODM_WM_G) || - (wirelessmode == (ODM_WM_B | ODM_WM_G)) || - (wirelessmode == ODM_WM_B))) { - EDCA_BE_DL = edca_setting_DL_GMode[iot_peer]; - } else if ((iot_peer == HT_IOT_PEER_AIRGO) && - (wirelessmode == ODM_WM_G)) { - EDCA_BE_DL = 0xa630; - } else if (iot_peer == HT_IOT_PEER_MARVELL) { - EDCA_BE_DL = edca_setting_DL[iot_peer]; - EDCA_BE_UL = edca_setting_UL[iot_peer]; - } else if (iot_peer == HT_IOT_PEER_ATHEROS) { - /* Set DL EDCA for Atheros peer to 0x3ea42b. */ - EDCA_BE_DL = edca_setting_DL[iot_peer]; - } - - if (trafficIndex == DOWN_LINK) - edca_param = EDCA_BE_DL; - else - edca_param = EDCA_BE_UL; - - rtw_write32(Adapter, REG_EDCA_BE_PARAM, edca_param); - - pDM_Odm->DM_EDCA_Table.prv_traffic_idx = trafficIndex; - - pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = true; - } else { - /* Turn Off EDCA turbo here. */ - /* Restore original EDCA according to the declaration of AP. */ - if (pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA) { - rtw_write32(Adapter, REG_EDCA_BE_PARAM, pHalData->AcParam_BE); - pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = false; - } - } -} diff --git a/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.h b/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.h deleted file mode 100644 index e9f9f07221f2..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODMEDCATURBOCHECK_H__ -#define __ODMEDCATURBOCHECK_H__ - -struct edca_t { /* _EDCA_TURBO_ */ - bool bCurrentTurboEDCA; - bool bIsCurRDLState; - - u32 prv_traffic_idx; /* edca turbo */ -}; - -void odm_EdcaTurboCheck(void *pDM_VOID); -void ODM_EdcaTurboInit(void *pDM_VOID); - -void odm_EdcaTurboCheckCE(void *pDM_VOID); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_HWConfig.c b/drivers/staging/rtl8723bs/hal/odm_HWConfig.c deleted file mode 100644 index 1716252641d3..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_HWConfig.c +++ /dev/null @@ -1,439 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -static u8 odm_query_rx_pwr_percentage(s8 ant_power) -{ - if ((ant_power <= -100) || (ant_power >= 20)) - return 0; - else if (ant_power >= 0) - return 100; - else - return 100 + ant_power; - -} - -s32 odm_signal_scale_mapping(struct dm_odm_t *dm_odm, s32 curr_sig) -{ - s32 ret_sig = 0; - - if (dm_odm->SupportInterface == ODM_ITRF_SDIO) { - if (curr_sig >= 51 && curr_sig <= 100) - ret_sig = 100; - else if (curr_sig >= 41 && curr_sig <= 50) - ret_sig = 80 + ((curr_sig - 40)*2); - else if (curr_sig >= 31 && curr_sig <= 40) - ret_sig = 66 + (curr_sig - 30); - else if (curr_sig >= 21 && curr_sig <= 30) - ret_sig = 54 + (curr_sig - 20); - else if (curr_sig >= 10 && curr_sig <= 20) - ret_sig = 42 + (((curr_sig - 10) * 2) / 3); - else if (curr_sig >= 5 && curr_sig <= 9) - ret_sig = 22 + (((curr_sig - 5) * 3) / 2); - else if (curr_sig >= 1 && curr_sig <= 4) - ret_sig = 6 + (((curr_sig - 1) * 3) / 2); - else - ret_sig = curr_sig; - } - - return ret_sig; -} - -static u8 odm_evm_db_to_percentage(s8 value) -{ - /* */ - /* -33dB~0dB to 0%~99% */ - /* */ - s8 ret_val; - - ret_val = value; - ret_val /= 2; - - if (ret_val >= 0) - ret_val = 0; - if (ret_val <= -33) - ret_val = -33; - - ret_val = 0 - ret_val; - ret_val *= 3; - - if (ret_val == 99) - ret_val = 100; - - return ret_val; -} - -static s8 odm_cck_rssi(u8 lna_idx, u8 vga_idx) -{ - s8 rx_pwr_all = 0x00; - - switch (lna_idx) { - /* 46 53 73 95 201301231630 */ - /* 46 53 77 99 201301241630 */ - - case 6: - rx_pwr_all = -34 - (2 * vga_idx); - break; - case 4: - rx_pwr_all = -14 - (2 * vga_idx); - break; - case 1: - rx_pwr_all = 6 - (2 * vga_idx); - break; - case 0: - rx_pwr_all = 16 - (2 * vga_idx); - break; - default: - /* rx_pwr_all = -53+(2*(31-VGA_idx)); */ - break; - } - return rx_pwr_all; -} - -static void odm_rx_phy_status_parsing(struct dm_odm_t *dm_odm, - struct odm_phy_info *phy_info, - u8 *phy_status, - struct odm_packet_info *pkt_info) -{ - u8 i; - s8 rx_pwr[4], rx_pwr_all = 0; - u8 evm, pwdb_all = 0, pwdb_all_bt; - u8 rssi, total_rssi = 0; - bool is_cck_rate = false; - u8 rf_rx_num = 0; - u8 lna_idx, vga_idx; - struct phy_status_rpt_8192cd_t *phy_sta_rpt = (struct phy_status_rpt_8192cd_t *)phy_status; - - is_cck_rate = pkt_info->data_rate <= DESC_RATE11M; - phy_info->rx_mimo_signal_quality[RF_PATH_A] = -1; - phy_info->rx_mimo_signal_quality[RF_PATH_B] = -1; - - if (is_cck_rate) { - u8 cck_agc_rpt; - - dm_odm->PhyDbgInfo.NumQryPhyStatusCCK++; - - /* - * (1)Hardware does not provide RSSI for CCK/ - * (2)PWDB, Average PWDB calculated by - * hardware (for rate adaptive) - */ - - cck_agc_rpt = phy_sta_rpt->cck_agc_rpt_ofdm_cfosho_a; - - /* - * 2011.11.28 LukeLee: 88E use different LNA & VGA gain table - * The RSSI formula should be modified according to the gain table - */ - lna_idx = ((cck_agc_rpt & 0xE0)>>5); - vga_idx = (cck_agc_rpt & 0x1F); - rx_pwr_all = odm_cck_rssi(lna_idx, vga_idx); - pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all); - if (pwdb_all > 100) - pwdb_all = 100; - - phy_info->rx_pwd_ba11 = pwdb_all; - phy_info->bt_rx_rssi_percentage = pwdb_all; - phy_info->recv_signal_power = rx_pwr_all; - - /* (3) Get Signal Quality (EVM) */ - - /* if (pPktinfo->bPacketMatchBSSID) */ - { - u8 sq, sq_rpt; - - if (phy_info->rx_pwd_ba11 > 40 && !dm_odm->bInHctTest) - sq = 100; - else { - sq_rpt = phy_sta_rpt->cck_sig_qual_ofdm_pwdb_all; - - if (sq_rpt > 64) - sq = 0; - else if (sq_rpt < 20) - sq = 100; - else - sq = ((64-sq_rpt) * 100) / 44; - - } - - phy_info->signal_quality = sq; - phy_info->rx_mimo_signal_quality[RF_PATH_A] = sq; - phy_info->rx_mimo_signal_quality[RF_PATH_B] = -1; - } - } else { /* is OFDM rate */ - dm_odm->PhyDbgInfo.NumQryPhyStatusOFDM++; - - /* - * (1)Get RSSI for HT rate - */ - - for (i = RF_PATH_A; i < RF_PATH_MAX; i++) { - /* 2008/01/30 MH we will judge RF RX path now. */ - if (dm_odm->RFPathRxEnable & BIT(i)) - rf_rx_num++; - /* else */ - /* continue; */ - - rx_pwr[i] = ((phy_sta_rpt->path_agc[i].gain & 0x3F) * 2) - 110; - - phy_info->rx_pwr[i] = rx_pwr[i]; - - /* Translate DBM to percentage. */ - rssi = odm_query_rx_pwr_percentage(rx_pwr[i]); - total_rssi += rssi; - - phy_info->rx_mimo_signal_strength[i] = (u8)rssi; - - /* Get Rx snr value in DB */ - phy_info->rx_snr[i] = dm_odm->PhyDbgInfo.RxSNRdB[i] = (s32)(phy_sta_rpt->path_rxsnr[i]/2); - } - - /* - * (2)PWDB, Average PWDB calculated by hardware (for rate adaptive) - */ - rx_pwr_all = ((phy_sta_rpt->cck_sig_qual_ofdm_pwdb_all >> 1) & 0x7f) - 110; - - pwdb_all_bt = pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all); - - phy_info->rx_pwd_ba11 = pwdb_all; - phy_info->bt_rx_rssi_percentage = pwdb_all_bt; - phy_info->rx_power = rx_pwr_all; - phy_info->recv_signal_power = rx_pwr_all; - - /* - * (3)EVM of HT rate - * - * Only spatial stream 1 makes sense - * - * Do not use shift operation like "rx_evmX >>= 1" - * because the compiler of free build environment - * fill most significant bit to "zero" when doing - * shifting operation which may change a negative - * value to positive one, then the dbm value (which - * is supposed to be negative) is not correct - * anymore. - */ - evm = odm_evm_db_to_percentage(phy_sta_rpt->stream_rxevm[0]); /* dbm */ - - /* Fill value in RFD, Get the first spatial stream only */ - phy_info->signal_quality = (u8)(evm & 0xff); - - phy_info->rx_mimo_signal_quality[RF_PATH_A] = (u8)(evm & 0xff); - - odm_parsing_cfo(dm_odm, pkt_info, phy_sta_rpt->path_cfotail); - } - - /* - * UI BSS List signal strength(in percentage), make it good - * looking, from 0~100. - * It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp(). - */ - if (is_cck_rate) { - phy_info->signal_strength = (u8)(odm_signal_scale_mapping(dm_odm, pwdb_all)); - } else { - if (rf_rx_num != 0) - phy_info->signal_strength = (u8)(odm_signal_scale_mapping(dm_odm, total_rssi /= rf_rx_num)); - } -} - -static void odm_Process_RSSIForDM( - struct dm_odm_t *pDM_Odm, struct odm_phy_info *pPhyInfo, struct odm_packet_info *pPktinfo -) -{ - - s32 UndecoratedSmoothedPWDB, UndecoratedSmoothedCCK, UndecoratedSmoothedOFDM, RSSI_Ave; - u8 isCCKrate = 0; - u8 RSSI_max, RSSI_min, i; - u32 OFDM_pkt = 0; - u32 Weighting = 0; - PSTA_INFO_T pEntry; - - if (pPktinfo->station_id == 0xFF) - return; - - pEntry = pDM_Odm->pODM_StaInfo[pPktinfo->station_id]; - - if (!IS_STA_VALID(pEntry)) - return; - - if ((!pPktinfo->bssid_match)) - return; - - if (pPktinfo->is_beacon) - pDM_Odm->PhyDbgInfo.NumQryBeaconPkt++; - - isCCKrate = ((pPktinfo->data_rate <= DESC_RATE11M)) ? true : false; - pDM_Odm->RxRate = pPktinfo->data_rate; - - /* Statistic for antenna/path diversity------------------ */ - if (pDM_Odm->SupportAbility & ODM_BB_ANT_DIV) { - - } - - /* Smart Antenna Debug Message------------------ */ - - UndecoratedSmoothedCCK = pEntry->rssi_stat.UndecoratedSmoothedCCK; - UndecoratedSmoothedOFDM = pEntry->rssi_stat.UndecoratedSmoothedOFDM; - UndecoratedSmoothedPWDB = pEntry->rssi_stat.UndecoratedSmoothedPWDB; - - if (pPktinfo->to_self || pPktinfo->is_beacon) { - - if (!isCCKrate) { /* ofdm rate */ - if (pPhyInfo->rx_mimo_signal_strength[RF_PATH_B] == 0) { - RSSI_Ave = pPhyInfo->rx_mimo_signal_strength[RF_PATH_A]; - pDM_Odm->RSSI_A = pPhyInfo->rx_mimo_signal_strength[RF_PATH_A]; - pDM_Odm->RSSI_B = 0; - } else { - pDM_Odm->RSSI_A = pPhyInfo->rx_mimo_signal_strength[RF_PATH_A]; - pDM_Odm->RSSI_B = pPhyInfo->rx_mimo_signal_strength[RF_PATH_B]; - - if ( - pPhyInfo->rx_mimo_signal_strength[RF_PATH_A] > - pPhyInfo->rx_mimo_signal_strength[RF_PATH_B] - ) { - RSSI_max = pPhyInfo->rx_mimo_signal_strength[RF_PATH_A]; - RSSI_min = pPhyInfo->rx_mimo_signal_strength[RF_PATH_B]; - } else { - RSSI_max = pPhyInfo->rx_mimo_signal_strength[RF_PATH_B]; - RSSI_min = pPhyInfo->rx_mimo_signal_strength[RF_PATH_A]; - } - - if ((RSSI_max-RSSI_min) < 3) - RSSI_Ave = RSSI_max; - else if ((RSSI_max-RSSI_min) < 6) - RSSI_Ave = RSSI_max - 1; - else if ((RSSI_max-RSSI_min) < 10) - RSSI_Ave = RSSI_max - 2; - else - RSSI_Ave = RSSI_max - 3; - } - - /* 1 Process OFDM RSSI */ - if (UndecoratedSmoothedOFDM <= 0) /* initialize */ - UndecoratedSmoothedOFDM = pPhyInfo->rx_pwd_ba11; - else { - if (pPhyInfo->rx_pwd_ba11 > (u32)UndecoratedSmoothedOFDM) { - UndecoratedSmoothedOFDM = - ((UndecoratedSmoothedOFDM*(Rx_Smooth_Factor-1)) + - RSSI_Ave)/Rx_Smooth_Factor; - UndecoratedSmoothedOFDM = UndecoratedSmoothedOFDM + 1; - } else { - UndecoratedSmoothedOFDM = - ((UndecoratedSmoothedOFDM*(Rx_Smooth_Factor-1)) + - RSSI_Ave)/Rx_Smooth_Factor; - } - } - - pEntry->rssi_stat.PacketMap = (pEntry->rssi_stat.PacketMap<<1) | BIT(0); - - } else { - RSSI_Ave = pPhyInfo->rx_pwd_ba11; - pDM_Odm->RSSI_A = (u8) pPhyInfo->rx_pwd_ba11; - pDM_Odm->RSSI_B = 0; - - /* 1 Process CCK RSSI */ - if (UndecoratedSmoothedCCK <= 0) /* initialize */ - UndecoratedSmoothedCCK = pPhyInfo->rx_pwd_ba11; - else { - if (pPhyInfo->rx_pwd_ba11 > (u32)UndecoratedSmoothedCCK) { - UndecoratedSmoothedCCK = - ((UndecoratedSmoothedCCK*(Rx_Smooth_Factor-1)) + - pPhyInfo->rx_pwd_ba11)/Rx_Smooth_Factor; - UndecoratedSmoothedCCK = UndecoratedSmoothedCCK + 1; - } else { - UndecoratedSmoothedCCK = - ((UndecoratedSmoothedCCK*(Rx_Smooth_Factor-1)) + - pPhyInfo->rx_pwd_ba11)/Rx_Smooth_Factor; - } - } - pEntry->rssi_stat.PacketMap = pEntry->rssi_stat.PacketMap<<1; - } - - /* if (pEntry) */ - { - /* 2011.07.28 LukeLee: modified to prevent unstable CCK RSSI */ - if (pEntry->rssi_stat.ValidBit >= 64) - pEntry->rssi_stat.ValidBit = 64; - else - pEntry->rssi_stat.ValidBit++; - - for (i = 0; i < pEntry->rssi_stat.ValidBit; i++) - OFDM_pkt += (u8)(pEntry->rssi_stat.PacketMap>>i)&BIT(0); - - if (pEntry->rssi_stat.ValidBit == 64) { - Weighting = ((OFDM_pkt<<4) > 64)?64:(OFDM_pkt<<4); - UndecoratedSmoothedPWDB = (Weighting*UndecoratedSmoothedOFDM+(64-Weighting)*UndecoratedSmoothedCCK)>>6; - } else { - if (pEntry->rssi_stat.ValidBit != 0) - UndecoratedSmoothedPWDB = (OFDM_pkt*UndecoratedSmoothedOFDM+(pEntry->rssi_stat.ValidBit-OFDM_pkt)*UndecoratedSmoothedCCK)/pEntry->rssi_stat.ValidBit; - else - UndecoratedSmoothedPWDB = 0; - } - - pEntry->rssi_stat.UndecoratedSmoothedCCK = UndecoratedSmoothedCCK; - pEntry->rssi_stat.UndecoratedSmoothedOFDM = UndecoratedSmoothedOFDM; - pEntry->rssi_stat.UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB; - } - - } -} - -/* */ -/* Endianness before calling this API */ -/* */ -void odm_phy_status_query(struct dm_odm_t *dm_odm, struct odm_phy_info *phy_info, - u8 *phy_status, struct odm_packet_info *pkt_info) -{ - - odm_rx_phy_status_parsing(dm_odm, phy_info, phy_status, pkt_info); - - if (!dm_odm->RSSI_test) - odm_Process_RSSIForDM(dm_odm, phy_info, pkt_info); -} - -/* */ -/* If you want to add a new IC, Please follow below template and generate a new one. */ -/* */ -/* */ - -enum hal_status ODM_ConfigRFWithHeaderFile( - struct dm_odm_t *pDM_Odm, - enum ODM_RF_Config_Type ConfigType, - enum rf_path eRFPath -) -{ - if (ConfigType == CONFIG_RF_RADIO) - ODM_ReadAndConfig_MP_8723B_RadioA(pDM_Odm); - else if (ConfigType == CONFIG_RF_TXPWR_LMT) - ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(pDM_Odm); - - return HAL_STATUS_SUCCESS; -} - -enum hal_status ODM_ConfigRFWithTxPwrTrackHeaderFile(struct dm_odm_t *pDM_Odm) -{ - if (pDM_Odm->SupportInterface == ODM_ITRF_SDIO) - ODM_ReadAndConfig_MP_8723B_TxPowerTrack_SDIO(pDM_Odm); - - return HAL_STATUS_SUCCESS; -} - -enum hal_status ODM_ConfigBBWithHeaderFile( - struct dm_odm_t *pDM_Odm, enum ODM_BB_Config_Type ConfigType -) -{ - if (ConfigType == CONFIG_BB_PHY_REG) - ODM_ReadAndConfig_MP_8723B_PHY_REG(pDM_Odm); - else if (ConfigType == CONFIG_BB_AGC_TAB) - ODM_ReadAndConfig_MP_8723B_AGC_TAB(pDM_Odm); - else if (ConfigType == CONFIG_BB_PHY_REG_PG) - ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(pDM_Odm); - - return HAL_STATUS_SUCCESS; -} - diff --git a/drivers/staging/rtl8723bs/hal/odm_HWConfig.h b/drivers/staging/rtl8723bs/hal/odm_HWConfig.h deleted file mode 100644 index 615145812ed2..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_HWConfig.h +++ /dev/null @@ -1,85 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __HALHWOUTSRC_H__ -#define __HALHWOUTSRC_H__ - -/* */ -/* structure and define */ -/* */ - -struct phy_rx_agc_info_t { - #if (ODM_ENDIAN_TYPE == ODM_ENDIAN_LITTLE) - u8 gain:7, trsw:1; - #else - u8 trsw:1, gain:7; - #endif -}; - -struct phy_status_rpt_8192cd_t { - struct phy_rx_agc_info_t path_agc[2]; - u8 ch_corr[2]; - u8 cck_sig_qual_ofdm_pwdb_all; - u8 cck_agc_rpt_ofdm_cfosho_a; - u8 cck_rpt_b_ofdm_cfosho_b; - u8 rsvd_1;/* ch_corr_msb; */ - u8 noise_power_db_msb; - s8 path_cfotail[2]; - u8 pcts_mask[2]; - s8 stream_rxevm[2]; - u8 path_rxsnr[2]; - u8 noise_power_db_lsb; - u8 rsvd_2[3]; - u8 stream_csi[2]; - u8 stream_target_csi[2]; - s8 sig_evm; - u8 rsvd_3; - -#if (ODM_ENDIAN_TYPE == ODM_ENDIAN_LITTLE) - u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */ - u8 sgi_en:1; - u8 rxsc:2; - u8 idle_long:1; - u8 r_ant_train_en:1; - u8 ant_sel_b:1; - u8 ant_sel:1; -#else /* _BIG_ENDIAN_ */ - u8 ant_sel:1; - u8 ant_sel_b:1; - u8 r_ant_train_en:1; - u8 idle_long:1; - u8 rxsc:2; - u8 sgi_en:1; - u8 antsel_rx_keep_2:1; /* ex_intf_flg:1; */ -#endif -}; - -void odm_phy_status_query(struct dm_odm_t *dm_odm, struct odm_phy_info *phy_info, - u8 *phy_status, struct odm_packet_info *pkt_info); - -enum hal_status ODM_ConfigRFWithTxPwrTrackHeaderFile(struct dm_odm_t *pDM_Odm); - -enum hal_status ODM_ConfigRFWithHeaderFile( - struct dm_odm_t *pDM_Odm, - enum ODM_RF_Config_Type ConfigType, - enum rf_path eRFPath -); - -enum hal_status ODM_ConfigBBWithHeaderFile( - struct dm_odm_t *pDM_Odm, enum ODM_BB_Config_Type ConfigType -); - -enum hal_status ODM_ConfigFWWithHeaderFile( - struct dm_odm_t *pDM_Odm, - enum ODM_FW_Config_Type ConfigType, - u8 *pFirmware, - u32 *pSize -); - -s32 odm_signal_scale_mapping(struct dm_odm_t *pDM_Odm, s32 CurrSig); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.c b/drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.c deleted file mode 100644 index 6514a711e6bd..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.c +++ /dev/null @@ -1,176 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include "odm_precomp.h" - -void odm_ConfigRFReg_8723B( - struct dm_odm_t *pDM_Odm, - u32 Addr, - u32 Data, - enum rf_path RF_PATH, - u32 RegAddr -) -{ - if (Addr == 0xfe || Addr == 0xffe) - msleep(50); - else { - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH, RegAddr, bRFRegOffsetMask, Data); - /* Add 1us delay between BB/RF register setting. */ - udelay(1); - - /* For disable/enable test in high temperature, the B6 value will fail to fill. Suggestion by BB Stanley, 2013.06.25. */ - if (Addr == 0xb6) { - u32 getvalue = 0; - u8 count = 0; - - getvalue = PHY_QueryRFReg( - pDM_Odm->Adapter, RF_PATH, Addr, bMaskDWord - ); - - udelay(1); - - while ((getvalue>>8) != (Data>>8)) { - count++; - PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH, RegAddr, bRFRegOffsetMask, Data); - udelay(1); - getvalue = PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH, Addr, bMaskDWord); - if (count > 5) - break; - } - } - - if (Addr == 0xb2) { - u32 getvalue = 0; - u8 count = 0; - - getvalue = PHY_QueryRFReg( - pDM_Odm->Adapter, RF_PATH, Addr, bMaskDWord - ); - - udelay(1); - - while (getvalue != Data) { - count++; - PHY_SetRFReg( - pDM_Odm->Adapter, - RF_PATH, - RegAddr, - bRFRegOffsetMask, - Data - ); - udelay(1); - /* Do LCK againg */ - PHY_SetRFReg( - pDM_Odm->Adapter, - RF_PATH, - 0x18, - bRFRegOffsetMask, - 0x0fc07 - ); - udelay(1); - getvalue = PHY_QueryRFReg( - pDM_Odm->Adapter, RF_PATH, Addr, bMaskDWord - ); - - if (count > 5) - break; - } - } - } -} - -void odm_ConfigRF_RadioA_8723B(struct dm_odm_t *pDM_Odm, u32 Addr, u32 Data) -{ - u32 content = 0x1000; /* RF_Content: radioa_txt */ - u32 maskforPhySet = (u32)(content&0xE000); - - odm_ConfigRFReg_8723B( - pDM_Odm, - Addr, - Data, - RF_PATH_A, - Addr|maskforPhySet - ); -} - -void odm_ConfigMAC_8723B(struct dm_odm_t *pDM_Odm, u32 Addr, u8 Data) -{ - rtw_write8(pDM_Odm->Adapter, Addr, Data); -} - -void odm_ConfigBB_AGC_8723B( - struct dm_odm_t *pDM_Odm, - u32 Addr, - u32 Bitmask, - u32 Data -) -{ - PHY_SetBBReg(pDM_Odm->Adapter, Addr, Bitmask, Data); - /* Add 1us delay between BB/RF register setting. */ - udelay(1); -} - -void odm_ConfigBB_PHY_REG_PG_8723B( - struct dm_odm_t *pDM_Odm, - u32 RfPath, - u32 Addr, - u32 Bitmask, - u32 Data -) -{ - if (Addr == 0xfe || Addr == 0xffe) - msleep(50); - else - PHY_StoreTxPowerByRate(pDM_Odm->Adapter, RfPath, Addr, Bitmask, Data); -} - -void odm_ConfigBB_PHY_8723B( - struct dm_odm_t *pDM_Odm, - u32 Addr, - u32 Bitmask, - u32 Data -) -{ - if (Addr == 0xfe) - msleep(50); - else if (Addr == 0xfd) - mdelay(5); - else if (Addr == 0xfc) - mdelay(1); - else if (Addr == 0xfb) - udelay(50); - else if (Addr == 0xfa) - udelay(5); - else if (Addr == 0xf9) - udelay(1); - else - PHY_SetBBReg(pDM_Odm->Adapter, Addr, Bitmask, Data); - - /* Add 1us delay between BB/RF register setting. */ - udelay(1); -} - -void odm_ConfigBB_TXPWR_LMT_8723B( - struct dm_odm_t *pDM_Odm, - u8 *Regulation, - u8 *Bandwidth, - u8 *RateSection, - u8 *RfPath, - u8 *Channel, - u8 *PowerLimit -) -{ - PHY_SetTxPowerLimit( - pDM_Odm->Adapter, - Regulation, - Bandwidth, - RateSection, - RfPath, - Channel, - PowerLimit - ); -} diff --git a/drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h b/drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h deleted file mode 100644 index fba7053ee3e1..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __INC_ODM_REGCONFIG_H_8723B -#define __INC_ODM_REGCONFIG_H_8723B - -void odm_ConfigRFReg_8723B(struct dm_odm_t *pDM_Odm, - u32 Addr, - u32 Data, - enum rf_path RF_PATH, - u32 RegAddr -); - -void odm_ConfigRF_RadioA_8723B(struct dm_odm_t *pDM_Odm, u32 Addr, u32 Data); - -void odm_ConfigMAC_8723B(struct dm_odm_t *pDM_Odm, u32 Addr, u8 Data); - -void odm_ConfigBB_AGC_8723B(struct dm_odm_t *pDM_Odm, - u32 Addr, - u32 Bitmask, - u32 Data -); - -void odm_ConfigBB_PHY_REG_PG_8723B(struct dm_odm_t *pDM_Odm, u32 RfPath, u32 Addr, - u32 Bitmask, u32 Data); - -void odm_ConfigBB_PHY_8723B(struct dm_odm_t *pDM_Odm, - u32 Addr, - u32 Bitmask, - u32 Data -); - -void odm_ConfigBB_TXPWR_LMT_8723B(struct dm_odm_t *pDM_Odm, - u8 *Regulation, - u8 *Bandwidth, - u8 *RateSection, - u8 *RfPath, - u8 *Channel, - u8 *PowerLimit -); - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h b/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h deleted file mode 100644 index 9ba8e06e5ad5..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h +++ /dev/null @@ -1,160 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODM_REGDEFINE11N_H__ -#define __ODM_REGDEFINE11N_H__ - -/* 2 RF REG LIST */ -#define ODM_REG_RF_MODE_11N 0x00 -#define ODM_REG_RF_0B_11N 0x0B -#define ODM_REG_CHNBW_11N 0x18 -#define ODM_REG_T_METER_11N 0x24 -#define ODM_REG_RF_25_11N 0x25 -#define ODM_REG_RF_26_11N 0x26 -#define ODM_REG_RF_27_11N 0x27 -#define ODM_REG_RF_2B_11N 0x2B -#define ODM_REG_RF_2C_11N 0x2C -#define ODM_REG_RXRF_A3_11N 0x3C -#define ODM_REG_T_METER_92D_11N 0x42 -#define ODM_REG_T_METER_88E_11N 0x42 - -/* 2 BB REG LIST */ -/* PAGE 8 */ -#define ODM_REG_BB_CTRL_11N 0x800 -#define ODM_REG_RF_PIN_11N 0x804 -#define ODM_REG_PSD_CTRL_11N 0x808 -#define ODM_REG_TX_ANT_CTRL_11N 0x80C -#define ODM_REG_BB_PWR_SAV5_11N 0x818 -#define ODM_REG_CCK_RPT_FORMAT_11N 0x824 -#define ODM_REG_RX_DEFAULT_A_11N 0x858 -#define ODM_REG_RX_DEFAULT_B_11N 0x85A -#define ODM_REG_BB_PWR_SAV3_11N 0x85C -#define ODM_REG_ANTSEL_CTRL_11N 0x860 -#define ODM_REG_RX_ANT_CTRL_11N 0x864 -#define ODM_REG_PIN_CTRL_11N 0x870 -#define ODM_REG_BB_PWR_SAV1_11N 0x874 -#define ODM_REG_ANTSEL_PATH_11N 0x878 -#define ODM_REG_BB_3WIRE_11N 0x88C -#define ODM_REG_SC_CNT_11N 0x8C4 -#define ODM_REG_PSD_DATA_11N 0x8B4 -#define ODM_REG_PSD_DATA_11N 0x8B4 -#define ODM_REG_NHM_TIMER_11N 0x894 -#define ODM_REG_NHM_TH9_TH10_11N 0x890 -#define ODM_REG_NHM_TH3_TO_TH0_11N 0x898 -#define ODM_REG_NHM_TH7_TO_TH4_11N 0x89c -#define ODM_REG_NHM_CNT_11N 0x8d8 -/* PAGE 9 */ -#define ODM_REG_DBG_RPT_11N 0x908 -#define ODM_REG_ANT_MAPPING1_11N 0x914 -#define ODM_REG_ANT_MAPPING2_11N 0x918 -/* PAGE A */ -#define ODM_REG_CCK_ANTDIV_PARA1_11N 0xA00 -#define ODM_REG_CCK_CCA_11N 0xA0A -#define ODM_REG_CCK_ANTDIV_PARA2_11N 0xA0C -#define ODM_REG_CCK_ANTDIV_PARA3_11N 0xA10 -#define ODM_REG_CCK_ANTDIV_PARA4_11N 0xA14 -#define ODM_REG_CCK_FILTER_PARA1_11N 0xA22 -#define ODM_REG_CCK_FILTER_PARA2_11N 0xA23 -#define ODM_REG_CCK_FILTER_PARA3_11N 0xA24 -#define ODM_REG_CCK_FILTER_PARA4_11N 0xA25 -#define ODM_REG_CCK_FILTER_PARA5_11N 0xA26 -#define ODM_REG_CCK_FILTER_PARA6_11N 0xA27 -#define ODM_REG_CCK_FILTER_PARA7_11N 0xA28 -#define ODM_REG_CCK_FILTER_PARA8_11N 0xA29 -#define ODM_REG_CCK_FA_RST_11N 0xA2C -#define ODM_REG_CCK_FA_MSB_11N 0xA58 -#define ODM_REG_CCK_FA_LSB_11N 0xA5C -#define ODM_REG_CCK_CCA_CNT_11N 0xA60 -#define ODM_REG_BB_PWR_SAV4_11N 0xA74 -/* PAGE B */ -#define ODM_REG_LNA_SWITCH_11N 0xB2C -#define ODM_REG_PATH_SWITCH_11N 0xB30 -#define ODM_REG_RSSI_CTRL_11N 0xB38 -#define ODM_REG_CONFIG_ANTA_11N 0xB68 -#define ODM_REG_RSSI_BT_11N 0xB9C -/* PAGE C */ -#define ODM_REG_OFDM_FA_HOLDC_11N 0xC00 -#define ODM_REG_BB_RX_PATH_11N 0xC04 -#define ODM_REG_TRMUX_11N 0xC08 -#define ODM_REG_OFDM_FA_RSTC_11N 0xC0C -#define ODM_REG_RXIQI_MATRIX_11N 0xC14 -#define ODM_REG_TXIQK_MATRIX_LSB1_11N 0xC4C -#define ODM_REG_IGI_A_11N 0xC50 -#define ODM_REG_ANTDIV_PARA2_11N 0xC54 -#define ODM_REG_IGI_B_11N 0xC58 -#define ODM_REG_ANTDIV_PARA3_11N 0xC5C -#define ODM_REG_L1SBD_PD_CH_11N 0XC6C -#define ODM_REG_BB_PWR_SAV2_11N 0xC70 -#define ODM_REG_RX_OFF_11N 0xC7C -#define ODM_REG_TXIQK_MATRIXA_11N 0xC80 -#define ODM_REG_TXIQK_MATRIXB_11N 0xC88 -#define ODM_REG_TXIQK_MATRIXA_LSB2_11N 0xC94 -#define ODM_REG_TXIQK_MATRIXB_LSB2_11N 0xC9C -#define ODM_REG_RXIQK_MATRIX_LSB_11N 0xCA0 -#define ODM_REG_ANTDIV_PARA1_11N 0xCA4 -#define ODM_REG_OFDM_FA_TYPE1_11N 0xCF0 -/* PAGE D */ -#define ODM_REG_OFDM_FA_RSTD_11N 0xD00 -#define ODM_REG_BB_ATC_11N 0xD2C -#define ODM_REG_OFDM_FA_TYPE2_11N 0xDA0 -#define ODM_REG_OFDM_FA_TYPE3_11N 0xDA4 -#define ODM_REG_OFDM_FA_TYPE4_11N 0xDA8 -#define ODM_REG_RPT_11N 0xDF4 -/* PAGE E */ -#define ODM_REG_TXAGC_A_6_18_11N 0xE00 -#define ODM_REG_TXAGC_A_24_54_11N 0xE04 -#define ODM_REG_TXAGC_A_1_MCS32_11N 0xE08 -#define ODM_REG_TXAGC_A_MCS0_3_11N 0xE10 -#define ODM_REG_TXAGC_A_MCS4_7_11N 0xE14 -#define ODM_REG_FPGA0_IQK_11N 0xE28 -#define ODM_REG_TXIQK_TONE_A_11N 0xE30 -#define ODM_REG_RXIQK_TONE_A_11N 0xE34 -#define ODM_REG_TXIQK_PI_A_11N 0xE38 -#define ODM_REG_RXIQK_PI_A_11N 0xE3C -#define ODM_REG_TXIQK_11N 0xE40 -#define ODM_REG_RXIQK_11N 0xE44 -#define ODM_REG_IQK_AGC_PTS_11N 0xE48 -#define ODM_REG_IQK_AGC_RSP_11N 0xE4C -#define ODM_REG_BLUETOOTH_11N 0xE6C -#define ODM_REG_RX_WAIT_CCA_11N 0xE70 -#define ODM_REG_TX_CCK_RFON_11N 0xE74 -#define ODM_REG_TX_CCK_BBON_11N 0xE78 -#define ODM_REG_OFDM_RFON_11N 0xE7C -#define ODM_REG_OFDM_BBON_11N 0xE80 -#define ODM_REG_TX2RX_11N 0xE84 -#define ODM_REG_TX2TX_11N 0xE88 -#define ODM_REG_RX_CCK_11N 0xE8C -#define ODM_REG_RX_OFDM_11N 0xED0 -#define ODM_REG_RX_WAIT_RIFS_11N 0xED4 -#define ODM_REG_RX2RX_11N 0xED8 -#define ODM_REG_STANDBY_11N 0xEDC -#define ODM_REG_SLEEP_11N 0xEE0 -#define ODM_REG_PMPD_ANAEN_11N 0xEEC -#define ODM_REG_IGI_C_11N 0xF84 -#define ODM_REG_IGI_D_11N 0xF88 - -/* 2 MAC REG LIST */ -#define ODM_REG_BB_RST_11N 0x02 -#define ODM_REG_ANTSEL_PIN_11N 0x4C -#define ODM_REG_EARLY_MODE_11N 0x4D0 -#define ODM_REG_RSSI_MONITOR_11N 0x4FE -#define ODM_REG_EDCA_VO_11N 0x500 -#define ODM_REG_EDCA_VI_11N 0x504 -#define ODM_REG_EDCA_BE_11N 0x508 -#define ODM_REG_EDCA_BK_11N 0x50C -#define ODM_REG_TXPAUSE_11N 0x522 -#define ODM_REG_RESP_TX_11N 0x6D8 -#define ODM_REG_ANT_TRAIN_PARA1_11N 0x7b0 -#define ODM_REG_ANT_TRAIN_PARA2_11N 0x7b4 - -/* DIG Related */ -#define ODM_BIT_IGI_11N 0x0000007F -#define ODM_BIT_CCK_RPT_FORMAT_11N BIT(9) -#define ODM_BIT_BB_RX_PATH_11N 0xF -#define ODM_BIT_BB_ATC_11N BIT(11) - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_interface.h b/drivers/staging/rtl8723bs/hal/odm_interface.h deleted file mode 100644 index f79c3d57edff..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_interface.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODM_INTERFACE_H__ -#define __ODM_INTERFACE_H__ - -/* =========== Macro Define */ - -#define _reg_all(_name) ODM_##_name -#define _reg_ic(_name, _ic) ODM_##_name##_ic -#define _bit_all(_name) BIT_##_name -#define _bit_ic(_name, _ic) BIT_##_name##_ic - -#define _reg_11N(_name) ODM_REG_##_name##_11N -#define _bit_11N(_name) ODM_BIT_##_name##_11N - -#define _cat(_name, _func) _func##_11N(_name) - -/* _name: name of register or bit. */ -/* Example: "ODM_REG(R_A_AGC_CORE1)" */ -/* gets "ODM_R_A_AGC_CORE1" or "ODM_R_A_AGC_CORE1_8192C". */ -#define ODM_REG(_name) _cat(_name, _reg) -#define ODM_BIT(_name) _cat(_name, _bit) - -#endif /* __ODM_INTERFACE_H__ */ diff --git a/drivers/staging/rtl8723bs/hal/odm_precomp.h b/drivers/staging/rtl8723bs/hal/odm_precomp.h deleted file mode 100644 index 2987857a8761..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_precomp.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __ODM_PRECOMP_H__ -#define __ODM_PRECOMP_H__ - -#include "odm_types.h" - -#define TEST_FALG___ 1 - -/* 2 Config Flags and Structs - defined by each ODM Type */ - - /* include */ - /* include */ - /* include */ - /* include */ - /* include */ -#define BEAMFORMING_SUPPORT 0 - -/* 2 Hardware Parameter Files */ - -/* 2 OutSrc Header Files */ - -#include "odm.h" -#include "odm_HWConfig.h" -#include "odm_RegDefine11N.h" -#include "odm_EdcaTurboCheck.h" -#include "odm_DIG.h" -#include "odm_DynamicBBPowerSaving.h" -#include "odm_DynamicTxPower.h" -#include "odm_CfoTracking.h" -#include "HalPhyRf.h" -#include "HalPhyRf_8723B.h"/* for IQK, LCK, Power-tracking */ -#include "rtl8723b_hal.h" -#include "odm_interface.h" -#include "odm_reg.h" -#include "HalHWImg8723B_MAC.h" -#include "HalHWImg8723B_RF.h" -#include "HalHWImg8723B_BB.h" -#include "Hal8723BReg.h" -#include "odm_RegConfig8723B.h" - -#endif /* __ODM_PRECOMP_H__ */ diff --git a/drivers/staging/rtl8723bs/hal/odm_reg.h b/drivers/staging/rtl8723bs/hal/odm_reg.h deleted file mode 100644 index a3b1f673774c..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_reg.h +++ /dev/null @@ -1,91 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* File Name: odm_reg.h */ -/* Description: */ -/* This file is for general register definition. */ -#ifndef __HAL_ODM_REG_H__ -#define __HAL_ODM_REG_H__ - -/* Register Definition */ - -/* MAC REG */ -#define ODM_BB_RESET 0x002 -#define ODM_DUMMY 0x4fe -#define RF_T_METER_OLD 0x24 -#define RF_T_METER_NEW 0x42 - -#define ODM_EDCA_VO_PARAM 0x500 -#define ODM_EDCA_VI_PARAM 0x504 -#define ODM_EDCA_BE_PARAM 0x508 -#define ODM_EDCA_BK_PARAM 0x50C -#define ODM_TXPAUSE 0x522 - -/* BB REG */ -#define ODM_FPGA_PHY0_PAGE8 0x800 -#define ODM_PSD_SETTING 0x808 -#define ODM_AFE_SETTING 0x818 -#define ODM_TXAGC_B_24_54 0x834 -#define ODM_TXAGC_B_MCS32_5 0x838 -#define ODM_TXAGC_B_MCS0_MCS3 0x83c -#define ODM_TXAGC_B_MCS4_MCS7 0x848 -#define ODM_ANALOG_REGISTER 0x85c -#define ODM_RF_INTERFACE_OUTPUT 0x860 -#define ODM_TXAGC_B_11_A_2_11 0x86c -#define ODM_AD_DA_LSB_MASK 0x874 -#define ODM_ENABLE_3_WIRE 0x88c -#define ODM_PSD_REPORT 0x8b4 -#define ODM_R_ANT_SELECT 0x90c -#define ODM_CCK_ANT_SELECT 0xa07 -#define ODM_CCK_PD_THRESH 0xa0a -#define ODM_CCK_RF_REG1 0xa11 -#define ODM_CCK_MATCH_FILTER 0xa20 -#define ODM_CCK_RAKE_MAC 0xa2e -#define ODM_CCK_CNT_RESET 0xa2d -#define ODM_CCK_TX_DIVERSITY 0xa2f -#define ODM_CCK_FA_CNT_MSB 0xa5b -#define ODM_CCK_FA_CNT_LSB 0xa5c -#define ODM_CCK_NEW_FUNCTION 0xa75 -#define ODM_OFDM_PHY0_PAGE_C 0xc00 -#define ODM_OFDM_RX_ANT 0xc04 -#define ODM_R_A_RXIQI 0xc14 -#define ODM_R_A_AGC_CORE1 0xc50 -#define ODM_R_A_AGC_CORE2 0xc54 -#define ODM_R_B_AGC_CORE1 0xc58 -#define ODM_R_AGC_PAR 0xc70 -#define ODM_R_HTSTF_AGC_PAR 0xc7c -#define ODM_TX_PWR_TRAINING_A 0xc90 -#define ODM_TX_PWR_TRAINING_B 0xc98 -#define ODM_OFDM_FA_CNT1 0xcf0 -#define ODM_OFDM_PHY0_PAGE_D 0xd00 -#define ODM_OFDM_FA_CNT2 0xda0 -#define ODM_OFDM_FA_CNT3 0xda4 -#define ODM_OFDM_FA_CNT4 0xda8 -#define ODM_TXAGC_A_6_18 0xe00 -#define ODM_TXAGC_A_24_54 0xe04 -#define ODM_TXAGC_A_1_MCS32 0xe08 -#define ODM_TXAGC_A_MCS0_MCS3 0xe10 -#define ODM_TXAGC_A_MCS4_MCS7 0xe14 - -/* RF REG */ -#define ODM_GAIN_SETTING 0x00 -#define ODM_CHANNEL 0x18 - -/* Ant Detect Reg */ -#define ODM_DPDT 0x300 - -/* PSD Init */ -#define ODM_PSDREG 0x808 - -/* 92D Path Div */ -#define PATHDIV_REG 0xB30 -#define PATHDIV_TRI 0xBA0 - -/* Bitmap Definition */ - -#define BIT_FA_RESET BIT0 - -#endif diff --git a/drivers/staging/rtl8723bs/hal/odm_types.h b/drivers/staging/rtl8723bs/hal/odm_types.h deleted file mode 100644 index 25f0edd716cc..000000000000 --- a/drivers/staging/rtl8723bs/hal/odm_types.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __ODM_TYPES_H__ -#define __ODM_TYPES_H__ - -#include - -/* Deifne HW endian support */ -#define ODM_ENDIAN_BIG 0 -#define ODM_ENDIAN_LITTLE 1 - -#define GET_ODM(__padapter) ((PDM_ODM_T)(&((GET_HAL_DATA(__padapter))->odmpriv))) - -enum hal_status { - HAL_STATUS_SUCCESS, - HAL_STATUS_FAILURE, -}; - - #if defined(__LITTLE_ENDIAN) - #define ODM_ENDIAN_TYPE ODM_ENDIAN_LITTLE - #else - #define ODM_ENDIAN_TYPE ODM_ENDIAN_BIG - #endif - - #define STA_INFO_T struct sta_info - #define PSTA_INFO_T struct sta_info * - - /* define useless flag to avoid compile warning */ - #define USE_WORKITEM 0 - #define FPGA_TWO_MAC_VERIFICATION 0 - -#define READ_NEXT_PAIR(v1, v2, i) do { if (i+2 >= ArrayLen) break; i += 2; v1 = Array[i]; v2 = Array[i+1]; } while (0) -#define COND_ELSE 2 -#define COND_ENDIF 3 - -#endif /* __ODM_TYPES_H__ */ diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c deleted file mode 100644 index d2b44ad60a4c..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c +++ /dev/null @@ -1,933 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include -#include -#include "hal_com_h2c.h" - -#define MAX_H2C_BOX_NUMS 4 -#define MESSAGE_BOX_SIZE 4 - -#define RTL8723B_MAX_CMD_LEN 7 -#define RTL8723B_EX_MESSAGE_BOX_SIZE 4 - -static u8 _is_fw_read_cmd_down(struct adapter *padapter, u8 msgbox_num) -{ - u8 valid; - int ret; - - ret = read_poll_timeout_atomic(rtw_read8, - valid, !(valid & BIT(msgbox_num)), - 0, 500, false, - padapter, REG_HMETFR); - - return !ret; -} - -/***************************************** - * H2C Msg format : - *| 31 - 8 |7-5 | 4 - 0 | - *| h2c_msg |Class |CMD_ID | - *| 31-0 | - *| Ext msg | - * - ******************************************/ -s32 FillH2CCmd8723B(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer) -{ - u8 h2c_box_num; - u32 msgbox_addr; - u32 msgbox_ex_addr = 0; - struct hal_com_data *pHalData; - u32 h2c_cmd = 0; - u32 h2c_cmd_ex = 0; - s32 ret = _FAIL; - - padapter = GET_PRIMARY_ADAPTER(padapter); - pHalData = GET_HAL_DATA(padapter); - if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->h2c_fwcmd_mutex))) - return ret; - - if (!pCmdBuffer) - goto exit; - - if (CmdLen > RTL8723B_MAX_CMD_LEN) - goto exit; - - if (padapter->bSurpriseRemoved) - goto exit; - - /* pay attention to if race condition happened in H2C cmd setting. */ - do { - h2c_box_num = pHalData->LastHMEBoxNum; - - if (!_is_fw_read_cmd_down(padapter, h2c_box_num)) - goto exit; - - if (CmdLen <= 3) { - memcpy((u8 *)(&h2c_cmd) + 1, pCmdBuffer, CmdLen); - } else { - memcpy((u8 *)(&h2c_cmd) + 1, pCmdBuffer, 3); - memcpy((u8 *)(&h2c_cmd_ex), pCmdBuffer + 3, CmdLen - 3); - } - - *(u8 *)(&h2c_cmd) |= ElementID; - - if (CmdLen > 3) { - msgbox_ex_addr = REG_HMEBOX_EXT0_8723B + (h2c_box_num * RTL8723B_EX_MESSAGE_BOX_SIZE); - rtw_write32(padapter, msgbox_ex_addr, h2c_cmd_ex); - } - msgbox_addr = REG_HMEBOX_0 + (h2c_box_num * MESSAGE_BOX_SIZE); - rtw_write32(padapter, msgbox_addr, h2c_cmd); - - pHalData->LastHMEBoxNum = (h2c_box_num + 1) % MAX_H2C_BOX_NUMS; - - } while (0); - - ret = _SUCCESS; - -exit: - - mutex_unlock(&(adapter_to_dvobj(padapter)->h2c_fwcmd_mutex)); - return ret; -} - -static void ConstructBeacon(struct adapter *padapter, u8 *pframe, u32 *pLength) -{ - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - u32 rate_len, pktlen; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct wlan_bssid_ex *cur_network = &pmlmeinfo->network; - - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &pwlanhdr->frame_control; - *(fctrl) = 0; - - eth_broadcast_addr(pwlanhdr->addr1); - ether_addr_copy(pwlanhdr->addr2, myid(&padapter->eeprompriv)); - ether_addr_copy(pwlanhdr->addr3, get_my_bssid(cur_network)); - - SetSeqNum(pwlanhdr, 0); - SetFrameSubType(pframe, WIFI_BEACON); - - pframe += sizeof(struct ieee80211_hdr_3addr); - pktlen = sizeof(struct ieee80211_hdr_3addr); - - /* timestamp will be inserted by hardware */ - pframe += 8; - pktlen += 8; - - /* beacon interval: 2 bytes */ - memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->ies)), 2); - - pframe += 2; - pktlen += 2; - - /* capability info: 2 bytes */ - memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->ies)), 2); - - pframe += 2; - pktlen += 2; - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) { - pktlen += cur_network->ie_length - sizeof(struct ndis_802_11_fix_ie); - memcpy(pframe, cur_network->ies + sizeof(struct ndis_802_11_fix_ie), pktlen); - - goto _ConstructBeacon; - } - - /* below for ad-hoc mode */ - - /* SSID */ - pframe = rtw_set_ie(pframe, WLAN_EID_SSID, cur_network->ssid.ssid_length, cur_network->ssid.ssid, &pktlen); - - /* supported rates... */ - rate_len = rtw_get_rateset_len(cur_network->supported_rates); - pframe = rtw_set_ie(pframe, WLAN_EID_SUPP_RATES, ((rate_len > 8) ? 8 : rate_len), cur_network->supported_rates, &pktlen); - - /* DS parameter set */ - pframe = rtw_set_ie(pframe, WLAN_EID_DS_PARAMS, 1, (unsigned char *)&cur_network->configuration.ds_config, &pktlen); - - if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) { - u32 ATIMWindow; - /* IBSS Parameter Set... */ - ATIMWindow = 0; - pframe = rtw_set_ie(pframe, WLAN_EID_IBSS_PARAMS, 2, (unsigned char *)(&ATIMWindow), &pktlen); - } - - /* todo: ERP IE */ - - /* EXTERNDED SUPPORTED RATE */ - if (rate_len > 8) - pframe = rtw_set_ie(pframe, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8), (cur_network->supported_rates + 8), &pktlen); - - /* todo:HT for adhoc */ - -_ConstructBeacon: - - if ((pktlen + TXDESC_SIZE) > 512) - return; - - *pLength = pktlen; - -} - -static void ConstructPSPoll(struct adapter *padapter, u8 *pframe, u32 *pLength) -{ - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pwlanhdr = (struct ieee80211_hdr *)pframe; - - /* Frame control. */ - fctrl = &pwlanhdr->frame_control; - *(fctrl) = 0; - SetPwrMgt(fctrl); - SetFrameSubType(pframe, WIFI_PSPOLL); - - /* AID. */ - SetDuration(pframe, (pmlmeinfo->aid | 0xc000)); - - /* BSSID. */ - ether_addr_copy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network)); - - /* TA. */ - ether_addr_copy(pwlanhdr->addr2, myid(&padapter->eeprompriv)); - - *pLength = 16; -} - -static void ConstructNullFunctionData(struct adapter *padapter, - u8 *pframe, - u32 *pLength, - u8 *StaAddr, - u8 bQoS, - u8 AC, - u8 bEosp, - u8 bForcePowerSave) -{ - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - u32 pktlen; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *cur_network = &pmlmepriv->cur_network; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - pwlanhdr = (struct ieee80211_hdr *)pframe; - - fctrl = &pwlanhdr->frame_control; - *(fctrl) = 0; - if (bForcePowerSave) - SetPwrMgt(fctrl); - - switch (cur_network->network.infrastructure_mode) { - case NL80211_IFTYPE_STATION: - SetToDs(fctrl); - ether_addr_copy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network))); - ether_addr_copy(pwlanhdr->addr2, myid(&(padapter->eeprompriv))); - ether_addr_copy(pwlanhdr->addr3, StaAddr); - break; - case NL80211_IFTYPE_AP: - SetFrDs(fctrl); - ether_addr_copy(pwlanhdr->addr1, StaAddr); - ether_addr_copy(pwlanhdr->addr2, get_my_bssid(&(pmlmeinfo->network))); - ether_addr_copy(pwlanhdr->addr3, myid(&(padapter->eeprompriv))); - break; - case NL80211_IFTYPE_ADHOC: - default: - ether_addr_copy(pwlanhdr->addr1, StaAddr); - ether_addr_copy(pwlanhdr->addr2, myid(&(padapter->eeprompriv))); - ether_addr_copy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network))); - break; - } - - SetSeqNum(pwlanhdr, 0); - - if (bQoS) { - struct ieee80211_qos_hdr *pwlanqoshdr; - - SetFrameSubType(pframe, WIFI_QOS_DATA_NULL); - - pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe; - SetPriority(&pwlanqoshdr->qos_ctrl, AC); - SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp); - - pktlen = sizeof(struct ieee80211_qos_hdr); - } else { - SetFrameSubType(pframe, WIFI_DATA_NULL); - - pktlen = sizeof(struct ieee80211_hdr_3addr); - } - - *pLength = pktlen; -} - -static void rtl8723b_set_FwRsvdPage_cmd(struct adapter *padapter, struct rsvdpage_loc *rsvdpageloc) -{ - u8 u1H2CRsvdPageParm[H2C_RSVDPAGE_LOC_LEN] = {0}; - - SET_8723B_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1H2CRsvdPageParm, rsvdpageloc->LocProbeRsp); - SET_8723B_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1H2CRsvdPageParm, rsvdpageloc->LocPsPoll); - SET_8723B_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocNullData); - SET_8723B_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocQosNull); - SET_8723B_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocBTQosNull); - - FillH2CCmd8723B(padapter, H2C_8723B_RSVD_PAGE, H2C_RSVDPAGE_LOC_LEN, u1H2CRsvdPageParm); -} - -void rtl8723b_set_FwMediaStatusRpt_cmd(struct adapter *padapter, u8 mstatus, u8 macid) -{ - u8 u1H2CMediaStatusRptParm[H2C_MEDIA_STATUS_RPT_LEN] = {0}; - u8 macid_end = 0; - - SET_8723B_H2CCMD_MSRRPT_PARM_OPMODE(u1H2CMediaStatusRptParm, mstatus); - SET_8723B_H2CCMD_MSRRPT_PARM_MACID_IND(u1H2CMediaStatusRptParm, 0); - SET_8723B_H2CCMD_MSRRPT_PARM_MACID(u1H2CMediaStatusRptParm, macid); - SET_8723B_H2CCMD_MSRRPT_PARM_MACID_END(u1H2CMediaStatusRptParm, macid_end); - - FillH2CCmd8723B(padapter, H2C_8723B_MEDIA_STATUS_RPT, H2C_MEDIA_STATUS_RPT_LEN, u1H2CMediaStatusRptParm); -} - -void rtl8723b_set_FwMacIdConfig_cmd(struct adapter *padapter, u8 mac_id, u8 raid, u8 bw, u8 sgi, u32 mask) -{ - u8 u1H2CMacIdConfigParm[H2C_MACID_CFG_LEN] = {0}; - - SET_8723B_H2CCMD_MACID_CFG_MACID(u1H2CMacIdConfigParm, mac_id); - SET_8723B_H2CCMD_MACID_CFG_RAID(u1H2CMacIdConfigParm, raid); - SET_8723B_H2CCMD_MACID_CFG_SGI_EN(u1H2CMacIdConfigParm, sgi ? 1 : 0); - SET_8723B_H2CCMD_MACID_CFG_BW(u1H2CMacIdConfigParm, bw); - SET_8723B_H2CCMD_MACID_CFG_RATE_MASK0(u1H2CMacIdConfigParm, (u8)(mask & 0x000000ff)); - SET_8723B_H2CCMD_MACID_CFG_RATE_MASK1(u1H2CMacIdConfigParm, (u8)((mask & 0x0000ff00) >> 8)); - SET_8723B_H2CCMD_MACID_CFG_RATE_MASK2(u1H2CMacIdConfigParm, (u8)((mask & 0x00ff0000) >> 16)); - SET_8723B_H2CCMD_MACID_CFG_RATE_MASK3(u1H2CMacIdConfigParm, (u8)((mask & 0xff000000) >> 24)); - - FillH2CCmd8723B(padapter, H2C_8723B_MACID_CFG, H2C_MACID_CFG_LEN, u1H2CMacIdConfigParm); -} - -void rtl8723b_set_rssi_cmd(struct adapter *padapter, u8 *param) -{ - u8 u1H2CRssiSettingParm[H2C_RSSI_SETTING_LEN] = {0}; - u8 mac_id = *param; - u8 rssi = *(param + 2); - u8 uldl_state = 0; - - SET_8723B_H2CCMD_RSSI_SETTING_MACID(u1H2CRssiSettingParm, mac_id); - SET_8723B_H2CCMD_RSSI_SETTING_RSSI(u1H2CRssiSettingParm, rssi); - SET_8723B_H2CCMD_RSSI_SETTING_ULDL_STATE(u1H2CRssiSettingParm, uldl_state); - - FillH2CCmd8723B(padapter, H2C_8723B_RSSI_SETTING, H2C_RSSI_SETTING_LEN, u1H2CRssiSettingParm); -} - -void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 psmode) -{ - int i; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - u8 u1H2CPwrModeParm[H2C_PWRMODE_LEN] = {0}; - u8 PowerState = 0, awake_intvl = 1, byte5 = 0, rlbm = 0; - - if (pwrpriv->dtim > 0 && pwrpriv->dtim < 16) - awake_intvl = pwrpriv->dtim + 1; - else - awake_intvl = 3; - - rlbm = 2; - - if (padapter->registrypriv.wifi_spec == 1) { - awake_intvl = 2; - rlbm = 2; - } - - if (psmode > 0) { - if (hal_btcoex_IsBtControlLps(padapter)) { - PowerState = hal_btcoex_RpwmVal(padapter); - byte5 = hal_btcoex_LpsVal(padapter); - - if ((rlbm == 2) && (byte5 & BIT(4))) { - /* Keep awake interval to 1 to prevent from */ - /* decreasing coex performance */ - awake_intvl = 2; - rlbm = 2; - } - } else { - PowerState = 0x00;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */ - byte5 = 0x40; - } - } else { - PowerState = 0x0C;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */ - byte5 = 0x40; - } - - SET_8723B_H2CCMD_PWRMODE_PARM_MODE(u1H2CPwrModeParm, (psmode > 0) ? 1 : 0); - SET_8723B_H2CCMD_PWRMODE_PARM_SMART_PS(u1H2CPwrModeParm, pwrpriv->smart_ps); - SET_8723B_H2CCMD_PWRMODE_PARM_RLBM(u1H2CPwrModeParm, rlbm); - SET_8723B_H2CCMD_PWRMODE_PARM_BCN_PASS_TIME(u1H2CPwrModeParm, awake_intvl); - SET_8723B_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(u1H2CPwrModeParm, padapter->registrypriv.uapsd_enable); - SET_8723B_H2CCMD_PWRMODE_PARM_PWR_STATE(u1H2CPwrModeParm, PowerState); - SET_8723B_H2CCMD_PWRMODE_PARM_BYTE5(u1H2CPwrModeParm, byte5); - if (psmode != PS_MODE_ACTIVE) { - if (!pmlmeext->adaptive_tsf_done && pmlmeext->bcn_cnt > 0) { - u8 ratio_20_delay, ratio_80_delay; - - /* byte 6 for adaptive_early_32k */ - /* 0:3] = DrvBcnEarly (ms) , [4:7] = DrvBcnTimeOut (ms) */ - /* 20% for DrvBcnEarly, 80% for DrvBcnTimeOut */ - ratio_20_delay = 0; - ratio_80_delay = 0; - pmlmeext->DrvBcnEarly = 0xff; - pmlmeext->DrvBcnTimeOut = 0xff; - - for (i = 0; i < 9; i++) { - pmlmeext->bcn_delay_ratio[i] = (pmlmeext->bcn_delay_cnt[i] * 100) / pmlmeext->bcn_cnt; - - ratio_20_delay += pmlmeext->bcn_delay_ratio[i]; - ratio_80_delay += pmlmeext->bcn_delay_ratio[i]; - - if (ratio_20_delay > 20 && pmlmeext->DrvBcnEarly == 0xff) - pmlmeext->DrvBcnEarly = i; - - if (ratio_80_delay > 80 && pmlmeext->DrvBcnTimeOut == 0xff) - pmlmeext->DrvBcnTimeOut = i; - - /* reset adaptive_early_32k cnt */ - pmlmeext->bcn_delay_cnt[i] = 0; - pmlmeext->bcn_delay_ratio[i] = 0; - - } - - pmlmeext->bcn_cnt = 0; - pmlmeext->adaptive_tsf_done = true; - - } - - } - - hal_btcoex_RecordPwrMode(padapter, u1H2CPwrModeParm, H2C_PWRMODE_LEN); - - FillH2CCmd8723B(padapter, H2C_8723B_SET_PWR_MODE, H2C_PWRMODE_LEN, u1H2CPwrModeParm); -} - -void rtl8723b_set_FwPsTuneParam_cmd(struct adapter *padapter) -{ - u8 u1H2CPsTuneParm[H2C_PSTUNEPARAM_LEN] = {0}; - u8 bcn_to_limit = 10; /* 10 * 100 * awakeinterval (ms) */ - u8 dtim_timeout = 5; /* ms wait broadcast data timer */ - u8 ps_timeout = 20; /* ms Keep awake when tx */ - u8 dtim_period = 3; - - SET_8723B_H2CCMD_PSTUNE_PARM_BCN_TO_LIMIT(u1H2CPsTuneParm, bcn_to_limit); - SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_TIMEOUT(u1H2CPsTuneParm, dtim_timeout); - SET_8723B_H2CCMD_PSTUNE_PARM_PS_TIMEOUT(u1H2CPsTuneParm, ps_timeout); - SET_8723B_H2CCMD_PSTUNE_PARM_ADOPT(u1H2CPsTuneParm, 1); - SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_PERIOD(u1H2CPsTuneParm, dtim_period); - - FillH2CCmd8723B(padapter, H2C_8723B_PS_TUNING_PARA, H2C_PSTUNEPARAM_LEN, u1H2CPsTuneParm); -} - -void rtl8723b_set_FwPwrModeInIPS_cmd(struct adapter *padapter, u8 cmd_param) -{ - - FillH2CCmd8723B(padapter, H2C_8723B_FWLPS_IN_IPS_, 1, &cmd_param); -} - -/* - * Description: Fill the reserved packets that FW will use to RSVD page. - * Now we just send 4 types packet to rsvd page. - * (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. - * - * Input: - * - * bDLFinished - false: At the first time we will send all the packets as - * a large packet to Hw, so we need to set the packet length to total length. - * - * true: At the second time, we should send the first packet (default:beacon) - * to Hw again and set the length in descriptor to the real beacon length. - */ -/* 2009.10.15 by tynli. */ -static void rtl8723b_set_FwRsvdPagePkt(struct adapter *padapter, bool bDLFinished) -{ - struct xmit_frame *pcmdframe; - struct pkt_attrib *pattrib; - struct xmit_priv *pxmitpriv; - struct mlme_ext_priv *pmlmeext; - struct mlme_ext_info *pmlmeinfo; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - u32 BeaconLength = 0, PSPollLength = 0; - u32 NullDataLength = 0, QosNullLength = 0, BTQosNullLength = 0; - u8 *ReservedPagePacket; - u8 TxDescLen = TXDESC_SIZE, TxDescOffset = TXDESC_OFFSET; - u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0; - u16 BufIndex, PageSize = 128; - u32 TotalPacketLen, MaxRsvdPageBufSize = 0; - - struct rsvdpage_loc RsvdPageLoc; - - pxmitpriv = &padapter->xmitpriv; - pmlmeext = &padapter->mlmeextpriv; - pmlmeinfo = &pmlmeext->mlmext_info; - - RsvdPageNum = BCNQ_PAGE_NUM_8723B + WOWLAN_PAGE_NUM_8723B; - MaxRsvdPageBufSize = RsvdPageNum * PageSize; - - pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv); - if (!pcmdframe) - return; - - ReservedPagePacket = pcmdframe->buf_addr; - memset(&RsvdPageLoc, 0, sizeof(struct rsvdpage_loc)); - - /* 3 (1) beacon */ - BufIndex = TxDescOffset; - ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength); - - /* When we count the first page size, we need to reserve description size for the RSVD */ - /* packet, it will be filled in front of the packet in TXPKTBUF. */ - CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength); - /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */ - if (CurtPktPageNum == 1) - CurtPktPageNum += 1; - - TotalPageNum += CurtPktPageNum; - - BufIndex += (CurtPktPageNum * PageSize); - - /* 3 (2) ps-poll */ - RsvdPageLoc.LocPsPoll = TotalPageNum; - ConstructPSPoll(padapter, &ReservedPagePacket[BufIndex], &PSPollLength); - rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex - TxDescLen], PSPollLength, true, false, false); - - CurtPktPageNum = (u8)PageNum_128(TxDescLen + PSPollLength); - - TotalPageNum += CurtPktPageNum; - - BufIndex += (CurtPktPageNum * PageSize); - - /* 3 (3) null data */ - RsvdPageLoc.LocNullData = TotalPageNum; - ConstructNullFunctionData(padapter, - &ReservedPagePacket[BufIndex], - &NullDataLength, - get_my_bssid(&pmlmeinfo->network), - false, 0, 0, false); - - rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex - TxDescLen], NullDataLength, false, false, false); - - CurtPktPageNum = (u8)PageNum_128(TxDescLen + NullDataLength); - - TotalPageNum += CurtPktPageNum; - - BufIndex += (CurtPktPageNum * PageSize); - - /* 3 (5) Qos null data */ - RsvdPageLoc.LocQosNull = TotalPageNum; - ConstructNullFunctionData(padapter, - &ReservedPagePacket[BufIndex], - &QosNullLength, - get_my_bssid(&pmlmeinfo->network), - true, 0, 0, false); - - rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex - TxDescLen], QosNullLength, false, false, false); - - CurtPktPageNum = (u8)PageNum_128(TxDescLen + QosNullLength); - - TotalPageNum += CurtPktPageNum; - - BufIndex += (CurtPktPageNum * PageSize); - - /* 3 (6) BT Qos null data */ - RsvdPageLoc.LocBTQosNull = TotalPageNum; - ConstructNullFunctionData(padapter, - &ReservedPagePacket[BufIndex], - &BTQosNullLength, - get_my_bssid(&pmlmeinfo->network), - true, 0, 0, false); - - rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex - TxDescLen], BTQosNullLength, false, true, false); - - CurtPktPageNum = (u8)PageNum_128(TxDescLen + BTQosNullLength); - - TotalPageNum += CurtPktPageNum; - - BufIndex += (CurtPktPageNum * PageSize); - - TotalPacketLen = BufIndex + BTQosNullLength; - - if (TotalPacketLen > MaxRsvdPageBufSize) { - goto error; - } else { - /* update attribute */ - pattrib = &pcmdframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->qsel = 0x10; - pattrib->pktlen = pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset; - dump_mgntframe_and_wait(padapter, pcmdframe, 100); - } - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtl8723b_set_FwRsvdPage_cmd(padapter, &RsvdPageLoc); - - return; - -error: - - rtw_free_xmitframe(pxmitpriv, pcmdframe); -} - -void rtl8723b_download_rsvd_page(struct adapter *padapter, u8 mstatus) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - bool bcn_valid = false; - u8 DLBcnCount = 0; - u32 poll = 0; - u8 val8; - - if (mstatus == RT_MEDIA_CONNECT) { - bool bRecover = false; - u8 v8; - - /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */ - /* Suggested by filen. Added by tynli. */ - rtw_write16(padapter, REG_BCN_PSR_RPT, (0xC000 | pmlmeinfo->aid)); - - /* set REG_CR bit 8 */ - v8 = rtw_read8(padapter, REG_CR + 1); - v8 |= BIT(0); /* ENSWBCN */ - rtw_write8(padapter, REG_CR + 1, v8); - - /* Disable Hw protection for a time which revserd for Hw sending beacon. */ - /* Fix download reserved page packet fail that access collision with the protection time. */ - /* 2010.05.11. Added by tynli. */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 &= ~EN_BCN_FUNCTION; - val8 |= DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - /* Set FWHW_TXQ_CTRL 0x422[6]= 0 to tell Hw the packet is not a real beacon frame. */ - if (pHalData->RegFwHwTxQCtrl & BIT(6)) - bRecover = true; - - /* To tell Hw the packet is not a real beacon frame. */ - rtw_write8(padapter, REG_FWHW_TXQ_CTRL + 2, pHalData->RegFwHwTxQCtrl & ~BIT(6)); - pHalData->RegFwHwTxQCtrl &= ~BIT(6); - - /* Clear beacon valid check bit. */ - rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL); - rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL); - - DLBcnCount = 0; - poll = 0; - do { - /* download rsvd page. */ - rtl8723b_set_FwRsvdPagePkt(padapter, 0); - DLBcnCount++; - do { - yield(); - /* mdelay(10); */ - /* check rsvd page download OK. */ - rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid)); - poll++; - } while (!bcn_valid && (poll % 10) != 0 && !padapter->bSurpriseRemoved && - !padapter->driver_stopped); - - } while (!bcn_valid && DLBcnCount <= 100 && !padapter->bSurpriseRemoved && - !padapter->driver_stopped); - - if (padapter->bSurpriseRemoved || padapter->driver_stopped) { - } else { - struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter); - - pwrctl->fw_psmode_iface_id = padapter->iface_id; - } - - /* 2010.05.11. Added by tynli. */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 |= EN_BCN_FUNCTION; - val8 &= ~DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - /* To make sure that if there exists an adapter which would like to send beacon. */ - /* If exists, the original value of 0x422[6] will be 1, we should check this to */ - /* prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */ - /* the beacon cannot be sent by HW. */ - /* 2010.06.23. Added by tynli. */ - if (bRecover) { - rtw_write8(padapter, REG_FWHW_TXQ_CTRL + 2, pHalData->RegFwHwTxQCtrl | BIT(6)); - pHalData->RegFwHwTxQCtrl |= BIT(6); - } - - /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */ - v8 = rtw_read8(padapter, REG_CR + 1); - v8 &= ~BIT(0); /* ~ENSWBCN */ - rtw_write8(padapter, REG_CR + 1, v8); - } -} - -void rtl8723b_set_FwJoinBssRpt_cmd(struct adapter *padapter, u8 mstatus) -{ - if (mstatus == 1) - rtl8723b_download_rsvd_page(padapter, RT_MEDIA_CONNECT); -} - -/* arg[0] = macid */ -/* arg[1] = raid */ -/* arg[2] = shortGIrate */ -/* arg[3] = init_rate */ -void rtl8723b_Add_RateATid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - struct sta_info *psta; - u8 mac_id = arg[0]; - u8 raid = arg[1]; - u8 shortGI = arg[2]; - u8 bw; - u32 mask = bitmap & 0x0FFFFFFF; - - psta = pmlmeinfo->FW_sta_info[mac_id].psta; - if (!psta) - return; - - bw = psta->bw_mode; - - if (rssi_level != DM_RATR_STA_INIT) - mask = ODM_Get_Rate_Bitmap(&pHalData->odmpriv, mac_id, mask, rssi_level); - - rtl8723b_set_FwMacIdConfig_cmd(padapter, mac_id, raid, bw, shortGI, mask); -} - -static void ConstructBtNullFunctionData(struct adapter *padapter, - u8 *pframe, - u32 *pLength, - u8 *StaAddr, - u8 bQoS, - u8 AC, - u8 bEosp, - u8 bForcePowerSave) -{ - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - u32 pktlen; - u8 bssid[ETH_ALEN]; - - pwlanhdr = (struct ieee80211_hdr *)pframe; - - if (!StaAddr) { - memcpy(bssid, myid(&padapter->eeprompriv), ETH_ALEN); - StaAddr = bssid; - } - - fctrl = &pwlanhdr->frame_control; - *fctrl = 0; - if (bForcePowerSave) - SetPwrMgt(fctrl); - - SetFrDs(fctrl); - ether_addr_copy(pwlanhdr->addr1, StaAddr); - ether_addr_copy(pwlanhdr->addr2, myid(&padapter->eeprompriv)); - ether_addr_copy(pwlanhdr->addr3, myid(&padapter->eeprompriv)); - - SetDuration(pwlanhdr, 0); - SetSeqNum(pwlanhdr, 0); - - if (bQoS) { - struct ieee80211_qos_hdr *pwlanqoshdr; - - SetFrameSubType(pframe, WIFI_QOS_DATA_NULL); - - pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe; - SetPriority(&pwlanqoshdr->qos_ctrl, AC); - SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp); - - pktlen = sizeof(struct ieee80211_qos_hdr); - } else { - SetFrameSubType(pframe, WIFI_DATA_NULL); - - pktlen = sizeof(struct ieee80211_hdr_3addr); - } - - *pLength = pktlen; -} - -static void SetFwRsvdPagePkt_BTCoex(struct adapter *padapter) -{ - struct xmit_frame *pcmdframe; - struct pkt_attrib *pattrib; - struct xmit_priv *pxmitpriv; - u32 BeaconLength = 0; - u32 BTQosNullLength = 0; - u8 *ReservedPagePacket; - u8 TxDescLen, TxDescOffset; - u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0; - u16 BufIndex, PageSize; - u32 TotalPacketLen, MaxRsvdPageBufSize = 0; - struct rsvdpage_loc RsvdPageLoc; - - pxmitpriv = &padapter->xmitpriv; - TxDescLen = TXDESC_SIZE; - TxDescOffset = TXDESC_OFFSET; - PageSize = PAGE_SIZE_TX_8723B; - - RsvdPageNum = BCNQ_PAGE_NUM_8723B; - MaxRsvdPageBufSize = RsvdPageNum * PageSize; - - pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv); - if (!pcmdframe) - return; - - ReservedPagePacket = pcmdframe->buf_addr; - memset(&RsvdPageLoc, 0, sizeof(struct rsvdpage_loc)); - - /* 3 (1) beacon */ - BufIndex = TxDescOffset; - ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength); - - /* When we count the first page size, we need to reserve description size for the RSVD */ - /* packet, it will be filled in front of the packet in TXPKTBUF. */ - CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength); - /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */ - if (CurtPktPageNum == 1) - CurtPktPageNum += 1; - TotalPageNum += CurtPktPageNum; - - BufIndex += (CurtPktPageNum * PageSize); - - /* Jump to lastest page */ - if (BufIndex < (MaxRsvdPageBufSize - PageSize)) { - BufIndex = TxDescOffset + (MaxRsvdPageBufSize - PageSize); - TotalPageNum = BCNQ_PAGE_NUM_8723B - 1; - } - - /* 3 (6) BT Qos null data */ - RsvdPageLoc.LocBTQosNull = TotalPageNum; - ConstructBtNullFunctionData(padapter, - &ReservedPagePacket[BufIndex], - &BTQosNullLength, - NULL, - true, 0, 0, false); - - rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex - TxDescLen], BTQosNullLength, false, true, false); - - CurtPktPageNum = (u8)PageNum_128(TxDescLen + BTQosNullLength); - - TotalPageNum += CurtPktPageNum; - - TotalPacketLen = BufIndex + BTQosNullLength; - if (TotalPacketLen > MaxRsvdPageBufSize) - goto error; - - /* update attribute */ - pattrib = &pcmdframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->qsel = 0x10; - pattrib->pktlen = pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset; - dump_mgntframe_and_wait(padapter, pcmdframe, 100); - - rtl8723b_set_FwRsvdPage_cmd(padapter, &RsvdPageLoc); - - return; - -error: - rtw_free_xmitframe(pxmitpriv, pcmdframe); -} - -void rtl8723b_download_BTCoex_AP_mode_rsvd_page(struct adapter *padapter) -{ - struct hal_com_data *pHalData; - struct mlme_ext_priv *pmlmeext; - struct mlme_ext_info *pmlmeinfo; - u8 bRecover = false; - u8 bcn_valid = false; - u8 DLBcnCount = 0; - u32 poll = 0; - u8 val8; - - pHalData = GET_HAL_DATA(padapter); - pmlmeext = &padapter->mlmeextpriv; - pmlmeinfo = &pmlmeext->mlmext_info; - - /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */ - /* Suggested by filen. Added by tynli. */ - rtw_write16(padapter, REG_BCN_PSR_RPT, (0xC000 | pmlmeinfo->aid)); - - /* set REG_CR bit 8 */ - val8 = rtw_read8(padapter, REG_CR + 1); - val8 |= BIT(0); /* ENSWBCN */ - rtw_write8(padapter, REG_CR + 1, val8); - - /* Disable Hw protection for a time which revserd for Hw sending beacon. */ - /* Fix download reserved page packet fail that access collision with the protection time. */ - /* 2010.05.11. Added by tynli. */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 &= ~EN_BCN_FUNCTION; - val8 |= DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - /* Set FWHW_TXQ_CTRL 0x422[6]= 0 to tell Hw the packet is not a real beacon frame. */ - if (pHalData->RegFwHwTxQCtrl & BIT(6)) - bRecover = true; - - /* To tell Hw the packet is not a real beacon frame. */ - pHalData->RegFwHwTxQCtrl &= ~BIT(6); - rtw_write8(padapter, REG_FWHW_TXQ_CTRL + 2, pHalData->RegFwHwTxQCtrl); - - /* Clear beacon valid check bit. */ - rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL); - rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL); - - DLBcnCount = 0; - poll = 0; - do { - SetFwRsvdPagePkt_BTCoex(padapter); - DLBcnCount++; - do { - yield(); -/* mdelay(10); */ - /* check rsvd page download OK. */ - rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, &bcn_valid); - poll++; - } while (!bcn_valid && (poll % 10) != 0 && !padapter->bSurpriseRemoved && - !padapter->driver_stopped); - } while (!bcn_valid && (DLBcnCount <= 100) && !padapter->bSurpriseRemoved && - !padapter->driver_stopped); - - if (bcn_valid) { - struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter); - - pwrctl->fw_psmode_iface_id = padapter->iface_id; - } - - /* 2010.05.11. Added by tynli. */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 |= EN_BCN_FUNCTION; - val8 &= ~DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - /* To make sure that if there exists an adapter which would like to send beacon. */ - /* If exists, the original value of 0x422[6] will be 1, we should check this to */ - /* prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */ - /* the beacon cannot be sent by HW. */ - /* 2010.06.23. Added by tynli. */ - if (bRecover) { - pHalData->RegFwHwTxQCtrl |= BIT(6); - rtw_write8(padapter, REG_FWHW_TXQ_CTRL + 2, pHalData->RegFwHwTxQCtrl); - } - - /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */ - val8 = rtw_read8(padapter, REG_CR + 1); - val8 &= ~BIT(0); /* ~ENSWBCN */ - rtw_write8(padapter, REG_CR + 1, val8); -} diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_dm.c b/drivers/staging/rtl8723bs/hal/rtl8723b_dm.c deleted file mode 100644 index 13efbfa5b58a..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_dm.c +++ /dev/null @@ -1,256 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* Description: */ -/* This file is for 92CE/92CU dynamic mechanism only */ - -#include -#include - -/* Global var */ - -/* */ -/* functions */ -/* */ -static void Init_ODM_ComInfo_8723b(struct adapter *Adapter) -{ - - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - struct dm_priv *pdmpriv = &pHalData->dmpriv; - u8 cut_ver, fab_ver; - - /* */ - /* Init Value */ - /* */ - memset(pDM_Odm, 0, sizeof(*pDM_Odm)); - - pDM_Odm->Adapter = Adapter; -#define ODM_CE 0x04 - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_PLATFORM, ODM_CE); - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_INTERFACE, RTW_SDIO); - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, pHalData->PackageType); - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_IC_TYPE, ODM_RTL8723B); - - fab_ver = ODM_TSMC; - cut_ver = ODM_CUT_A; - - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver); - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver); - - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_PATCH_ID, pHalData->CustomerID); - /* ODM_CMNINFO_BINHCT_TEST only for MP Team */ - ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_BWIFI_TEST, Adapter->registrypriv.wifi_spec); - - pdmpriv->InitODMFlag = ODM_RF_CALIBRATION|ODM_RF_TX_PWR_TRACK; - - ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_ABILITY, pdmpriv->InitODMFlag); -} - -static void Update_ODM_ComInfo_8723b(struct adapter *Adapter) -{ - struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv; - struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; - struct dvobj_priv *dvobj = adapter_to_dvobj(Adapter); - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(Adapter); - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - struct dm_priv *pdmpriv = &pHalData->dmpriv; - int i; - u8 zero = 0; - - pdmpriv->InitODMFlag = 0 - | ODM_BB_DIG - | ODM_BB_RA_MASK - | ODM_BB_DYNAMIC_TXPWR - | ODM_BB_FA_CNT - | ODM_BB_RSSI_MONITOR - | ODM_BB_CCK_PD - | ODM_BB_PWR_SAVE - | ODM_BB_CFO_TRACKING - | ODM_MAC_EDCA_TURBO - | ODM_RF_TX_PWR_TRACK - | ODM_RF_CALIBRATION - ; - - /* */ - /* Pointer reference */ - /* */ - /* ODM_CMNINFO_MAC_PHY_MODE pHalData->MacPhyMode92D */ - /* ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_MAC_PHY_MODE,&(pDM_Odm->u8_temp)); */ - - ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_ABILITY, pdmpriv->InitODMFlag); - - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_TX_UNI, &(dvobj->traffic_stat.tx_bytes)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_RX_UNI, &(dvobj->traffic_stat.rx_bytes)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_WM_MODE, &(pmlmeext->cur_wireless_mode)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_SEC_CHNL_OFFSET, &(pHalData->nCur40MhzPrimeSC)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_SEC_MODE, &(Adapter->securitypriv.dot11_privacy_algrthm)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_BW, &(pHalData->CurrentChannelBW)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_CHNL, &(pHalData->CurrentChannel)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_NET_CLOSED, &(Adapter->net_closed)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_MP_MODE, &zero); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_FORCED_IGI_LB, &(pHalData->u1ForcedIgiLb)); - - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_SCAN, &(pmlmepriv->bScanInProcess)); - ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_POWER_SAVING, &(pwrctrlpriv->bpower_saving)); - - for (i = 0; i < NUM_STA; i++) - ODM_CmnInfoPtrArrayHook(pDM_Odm, ODM_CMNINFO_STA_STATUS, i, NULL); -} - -void rtl8723b_InitHalDm(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_priv *pdmpriv = &pHalData->dmpriv; - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - - pdmpriv->DM_Type = DM_Type_ByDriver; - pdmpriv->DMFlag = DYNAMIC_FUNC_DISABLE; - - pdmpriv->DMFlag |= DYNAMIC_FUNC_BT; - - pdmpriv->InitDMFlag = pdmpriv->DMFlag; - - Update_ODM_ComInfo_8723b(Adapter); - - ODM_DMInit(pDM_Odm); -} - -void rtl8723b_HalDmWatchDog(struct adapter *Adapter) -{ - bool fw_current_in_ps_mode = false; - bool bFwPSAwake = true; - u8 hw_init_completed = false; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - hw_init_completed = Adapter->hw_init_completed; - - if (!hw_init_completed) - goto skip_dm; - - fw_current_in_ps_mode = adapter_to_pwrctl(Adapter)->fw_current_in_ps_mode; - rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&bFwPSAwake)); - - if (hw_init_completed && - (!fw_current_in_ps_mode && bFwPSAwake)) { - rtw_hal_check_rxfifo_full(Adapter); - } - - /* ODM */ - if (hw_init_completed) { - u8 bLinked = false; - u8 bsta_state = false; - bool bBtDisabled = true; - - if (rtw_linked_check(Adapter)) { - bLinked = true; - if (check_fwstate(&Adapter->mlmepriv, WIFI_STATION_STATE)) - bsta_state = true; - } - - ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_LINK, bLinked); - ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_STATION_STATE, bsta_state); - - /* ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */ - - bBtDisabled = hal_btcoex_IsBtDisabled(Adapter); - - ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_BT_ENABLED, - !bBtDisabled); - - ODM_DMWatchdog(&pHalData->odmpriv); - } - -skip_dm: - return; -} - -void rtl8723b_hal_dm_in_lps(struct adapter *padapter) -{ - u32 PWDB_rssi = 0; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - struct sta_priv *pstapriv = &padapter->stapriv; - struct sta_info *psta = NULL; - - /* update IGI */ - ODM_Write_DIG(pDM_Odm, pDM_Odm->RSSI_Min); - - /* set rssi to fw */ - psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); - if (psta && (psta->rssi_stat.UndecoratedSmoothedPWDB > 0)) { - PWDB_rssi = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16)); - - rtl8723b_set_rssi_cmd(padapter, (u8 *)&PWDB_rssi); - } - -} - -void rtl8723b_HalDmWatchDog_in_LPS(struct adapter *Adapter) -{ - u8 bLinked = false; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; - struct dm_priv *pdmpriv = &pHalData->dmpriv; - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable; - struct sta_priv *pstapriv = &Adapter->stapriv; - struct sta_info *psta = NULL; - - if (!Adapter->hw_init_completed) - goto skip_lps_dm; - - if (rtw_linked_check(Adapter)) - bLinked = true; - - ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_LINK, bLinked); - - if (!bLinked) - goto skip_lps_dm; - - if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR)) - goto skip_lps_dm; - - /* ODM_DMWatchdog(&pHalData->odmpriv); */ - /* Do DIG by RSSI In LPS-32K */ - - /* 1 Find MIN-RSSI */ - psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); - if (!psta) - goto skip_lps_dm; - - pdmpriv->EntryMinUndecoratedSmoothedPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB; - - if (pdmpriv->EntryMinUndecoratedSmoothedPWDB <= 0) - goto skip_lps_dm; - - pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB; - - pDM_Odm->RSSI_Min = pdmpriv->MinUndecoratedPWDBForDM; - - /* if (pDM_DigTable->CurIGValue != pDM_Odm->RSSI_Min) */ - if ( - (pDM_DigTable->CurIGValue > pDM_Odm->RSSI_Min + 5) || - (pDM_DigTable->CurIGValue < pDM_Odm->RSSI_Min - 5) - ) - rtw_dm_in_lps_wk_cmd(Adapter); - -skip_lps_dm: - - return; - -} - -void rtl8723b_init_dm_priv(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_priv *pdmpriv = &pHalData->dmpriv; - - memset(pdmpriv, 0, sizeof(struct dm_priv)); - Init_ODM_ComInfo_8723b(Adapter); -} diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c deleted file mode 100644 index 6a4a13544ca1..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c +++ /dev/null @@ -1,2826 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include -#include -#include "hal_com_h2c.h" - -static void _FWDownloadEnable(struct adapter *padapter, bool enable) -{ - u8 tmp, count = 0; - - if (enable) { - /* 8051 enable */ - tmp = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - rtw_write8(padapter, REG_SYS_FUNC_EN + 1, tmp | 0x04); - - tmp = rtw_read8(padapter, REG_MCUFWDL); - rtw_write8(padapter, REG_MCUFWDL, tmp|0x01); - - do { - tmp = rtw_read8(padapter, REG_MCUFWDL); - if (tmp & 0x01) - break; - rtw_write8(padapter, REG_MCUFWDL, tmp|0x01); - msleep(1); - } while (count++ < 100); - - /* 8051 reset */ - tmp = rtw_read8(padapter, REG_MCUFWDL+2); - rtw_write8(padapter, REG_MCUFWDL+2, tmp&0xf7); - } else { - /* MCU firmware download disable. */ - tmp = rtw_read8(padapter, REG_MCUFWDL); - rtw_write8(padapter, REG_MCUFWDL, tmp&0xfe); - } -} - -static int _BlockWrite(struct adapter *padapter, void *buffer, u32 buffSize) -{ - int ret = _SUCCESS; - - u32 blockSize_p1 = 4; /* (Default) Phase #1 : PCI muse use 4-byte write to download FW */ - u32 blockSize_p2 = 8; /* Phase #2 : Use 8-byte, if Phase#1 use big size to write FW. */ - u32 blockSize_p3 = 1; /* Phase #3 : Use 1-byte, the remnant of FW image. */ - u32 blockCount_p1 = 0, blockCount_p2 = 0, blockCount_p3 = 0; - u32 remainSize_p1 = 0, remainSize_p2 = 0; - u8 *bufferPtr = buffer; - u32 i = 0, offset = 0; - - /* 3 Phase #1 */ - blockCount_p1 = buffSize / blockSize_p1; - remainSize_p1 = buffSize % blockSize_p1; - - for (i = 0; i < blockCount_p1; i++) { - ret = rtw_write32(padapter, (FW_8723B_START_ADDRESS + i * blockSize_p1), *((u32 *)(bufferPtr + i * blockSize_p1))); - if (ret == _FAIL) { - netdev_dbg(padapter->pnetdev, "write failed at %s %d, block:%d\n", - __func__, __LINE__, i); - goto exit; - } - } - - /* 3 Phase #2 */ - if (remainSize_p1) { - blockCount_p2 = remainSize_p1/blockSize_p2; - remainSize_p2 = remainSize_p1%blockSize_p2; - } - - /* 3 Phase #3 */ - if (remainSize_p2) { - offset = (blockCount_p1 * blockSize_p1) + (blockCount_p2 * blockSize_p2); - - blockCount_p3 = remainSize_p2 / blockSize_p3; - - for (i = 0; i < blockCount_p3; i++) { - ret = rtw_write8(padapter, (FW_8723B_START_ADDRESS + offset + i), *(bufferPtr + offset + i)); - - if (ret == _FAIL) { - netdev_dbg(padapter->pnetdev, "write failed at %s %d, block:%d\n", - __func__, __LINE__, i); - goto exit; - } - } - } -exit: - return ret; -} - -static int _PageWrite( - struct adapter *padapter, - u32 page, - void *buffer, - u32 size -) -{ - u8 value8; - u8 u8Page = (u8) (page & 0x07); - - value8 = (rtw_read8(padapter, REG_MCUFWDL+2) & 0xF8) | u8Page; - rtw_write8(padapter, REG_MCUFWDL+2, value8); - - return _BlockWrite(padapter, buffer, size); -} - -static int _WriteFW(struct adapter *padapter, void *buffer, u32 size) -{ - /* Since we need dynamic decide method of dwonload fw, so we call this function to get chip version. */ - /* We can remove _ReadChipVersion from ReadpadapterInfo8192C later. */ - int ret = _SUCCESS; - u32 pageNums, remainSize; - u32 page, offset; - u8 *bufferPtr = buffer; - - pageNums = size / MAX_DLFW_PAGE_SIZE; - remainSize = size % MAX_DLFW_PAGE_SIZE; - - for (page = 0; page < pageNums; page++) { - offset = page * MAX_DLFW_PAGE_SIZE; - ret = _PageWrite(padapter, page, bufferPtr+offset, MAX_DLFW_PAGE_SIZE); - - if (ret == _FAIL) { - netdev_dbg(padapter->pnetdev, "page write failed at %s %d\n", - __func__, __LINE__); - goto exit; - } - } - - if (remainSize) { - offset = pageNums * MAX_DLFW_PAGE_SIZE; - page = pageNums; - ret = _PageWrite(padapter, page, bufferPtr+offset, remainSize); - - if (ret == _FAIL) { - netdev_dbg(padapter->pnetdev, "remaining page write failed at %s %d\n", - __func__, __LINE__); - goto exit; - } - } - -exit: - return ret; -} - -void _8051Reset8723(struct adapter *padapter) -{ - u8 cpu_rst; - u8 io_rst; - - /* Reset 8051(WLMCU) IO wrapper */ - /* 0x1c[8] = 0 */ - /* Suggested by Isaac@SD1 and Gimmy@SD1, coding by Lucas@20130624 */ - io_rst = rtw_read8(padapter, REG_RSV_CTRL + 1); - io_rst &= ~BIT(0); - rtw_write8(padapter, REG_RSV_CTRL + 1, io_rst); - - cpu_rst = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - cpu_rst &= ~BIT(2); - rtw_write8(padapter, REG_SYS_FUNC_EN + 1, cpu_rst); - - /* Enable 8051 IO wrapper */ - /* 0x1c[8] = 1 */ - io_rst = rtw_read8(padapter, REG_RSV_CTRL + 1); - io_rst |= BIT(0); - rtw_write8(padapter, REG_RSV_CTRL + 1, io_rst); - - cpu_rst = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - cpu_rst |= BIT(2); - rtw_write8(padapter, REG_SYS_FUNC_EN + 1, cpu_rst); -} - -u8 g_fwdl_chksum_fail; - -static s32 polling_fwdl_chksum( - struct adapter *adapter, u32 min_cnt, u32 timeout_ms -) -{ - s32 ret = _FAIL; - u32 value32; - unsigned long start = jiffies; - u32 cnt = 0; - - /* polling CheckSum report */ - do { - cnt++; - value32 = rtw_read32(adapter, REG_MCUFWDL); - if (value32 & FWDL_ChkSum_rpt || adapter->bSurpriseRemoved || - adapter->driver_stopped) - break; - yield(); - } while (jiffies_to_msecs(jiffies-start) < timeout_ms || cnt < min_cnt); - - if (!(value32 & FWDL_ChkSum_rpt)) - goto exit; - - if (g_fwdl_chksum_fail) { - g_fwdl_chksum_fail--; - goto exit; - } - - ret = _SUCCESS; - -exit: - - return ret; -} - -u8 g_fwdl_wintint_rdy_fail; - -static s32 _FWFreeToGo(struct adapter *adapter, u32 min_cnt, u32 timeout_ms) -{ - s32 ret = _FAIL; - u32 value32; - unsigned long start = jiffies; - u32 cnt = 0; - - value32 = rtw_read32(adapter, REG_MCUFWDL); - value32 |= MCUFWDL_RDY; - value32 &= ~WINTINI_RDY; - rtw_write32(adapter, REG_MCUFWDL, value32); - - _8051Reset8723(adapter); - - /* polling for FW ready */ - do { - cnt++; - value32 = rtw_read32(adapter, REG_MCUFWDL); - if (value32 & WINTINI_RDY || adapter->bSurpriseRemoved || adapter->driver_stopped) - break; - yield(); - } while (jiffies_to_msecs(jiffies - start) < timeout_ms || cnt < min_cnt); - - if (!(value32 & WINTINI_RDY)) - goto exit; - - if (g_fwdl_wintint_rdy_fail) { - g_fwdl_wintint_rdy_fail--; - goto exit; - } - - ret = _SUCCESS; - -exit: - - return ret; -} - -#define IS_FW_81xxC(padapter) (((GET_HAL_DATA(padapter))->FirmwareSignature & 0xFFF0) == 0x88C0) - -void rtl8723b_FirmwareSelfReset(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 val; - u8 Delay = 100; - - if ( - !(IS_FW_81xxC(padapter) && ((pHalData->FirmwareVersion < 0x21) || (pHalData->FirmwareVersion == 0x21 && pHalData->FirmwareSubVersion < 0x01))) - ) { /* after 88C Fw v33.1 */ - /* 0x1cf = 0x20. Inform 8051 to reset. 2009.12.25. tynli_test */ - rtw_write8(padapter, REG_HMETFR+3, 0x20); - - val = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - while (val & BIT(2)) { - Delay--; - if (Delay == 0) - break; - udelay(50); - val = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - } - - if (Delay == 0) { - /* force firmware reset */ - val = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - rtw_write8(padapter, REG_SYS_FUNC_EN + 1, val & (~BIT(2))); - } - } -} - -/* */ -/* Description: */ -/* Download 8192C firmware code. */ -/* */ -/* */ -s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw) -{ - s32 rtStatus = _SUCCESS; - u8 write_fw = 0; - unsigned long fwdl_start_time; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct rt_firmware *pFirmware; - struct rt_firmware *pBTFirmware; - struct rt_firmware_hdr *pFwHdr = NULL; - u8 *pFirmwareBuf; - u32 FirmwareLen; - const struct firmware *fw; - struct device *device = dvobj_to_dev(padapter->dvobj); - u8 *fwfilepath; - u8 tmp_ps; - - pFirmware = kzalloc_obj(struct rt_firmware); - if (!pFirmware) - return _FAIL; - pBTFirmware = kzalloc_obj(struct rt_firmware); - if (!pBTFirmware) { - kfree(pFirmware); - return _FAIL; - } - tmp_ps = rtw_read8(padapter, 0xa3); - tmp_ps &= 0xf8; - tmp_ps |= 0x02; - /* 1. write 0xA3[:2:0] = 3b'010 */ - rtw_write8(padapter, 0xa3, tmp_ps); - /* 2. read power_state = 0xA0[1:0] */ - tmp_ps = rtw_read8(padapter, 0xa0); - tmp_ps &= 0x03; - - fwfilepath = "rtlwifi/rtl8723bs_nic.bin"; - - pr_info("rtl8723bs: acquire FW from file:%s\n", fwfilepath); - - rtStatus = request_firmware(&fw, fwfilepath, device); - if (rtStatus) { - pr_err("Request firmware failed with error 0x%x\n", rtStatus); - rtStatus = _FAIL; - goto exit; - } - - if (!fw) { - pr_err("Firmware %s not available\n", fwfilepath); - rtStatus = _FAIL; - goto exit; - } - - if (fw->size > FW_8723B_SIZE) { - rtStatus = _FAIL; - release_firmware(fw); - goto exit; - } - - pFirmware->fw_buffer_sz = kmemdup(fw->data, fw->size, GFP_KERNEL); - if (!pFirmware->fw_buffer_sz) { - rtStatus = _FAIL; - release_firmware(fw); - goto exit; - } - - pFirmware->fw_length = fw->size; - release_firmware(fw); - if (pFirmware->fw_length > FW_8723B_SIZE) { - rtStatus = _FAIL; - netdev_emerg(padapter->pnetdev, - "Firmware size:%u exceed %u\n", - pFirmware->fw_length, FW_8723B_SIZE); - goto release_fw1; - } - - pFirmwareBuf = pFirmware->fw_buffer_sz; - FirmwareLen = pFirmware->fw_length; - - /* To Check Fw header. Added by tynli. 2009.12.04. */ - pFwHdr = (struct rt_firmware_hdr *)pFirmwareBuf; - - pHalData->FirmwareVersion = le16_to_cpu(pFwHdr->version); - pHalData->FirmwareSubVersion = le16_to_cpu(pFwHdr->subversion); - pHalData->FirmwareSignature = le16_to_cpu(pFwHdr->signature); - - if (IS_FW_HEADER_EXIST_8723B(pFwHdr)) { - /* Shift 32 bytes for FW header */ - pFirmwareBuf = pFirmwareBuf + 32; - FirmwareLen = FirmwareLen - 32; - } - - /* Suggested by Filen. If 8051 is running in RAM code, driver should inform Fw to reset by itself, */ - /* or it will cause download Fw fail. 2010.02.01. by tynli. */ - if (rtw_read8(padapter, REG_MCUFWDL) & RAM_DL_SEL) { /* 8051 RAM code */ - rtw_write8(padapter, REG_MCUFWDL, 0x00); - rtl8723b_FirmwareSelfReset(padapter); - } - - _FWDownloadEnable(padapter, true); - fwdl_start_time = jiffies; - while ( - !padapter->driver_stopped && - !padapter->bSurpriseRemoved && - (write_fw++ < 3 || jiffies_to_msecs(jiffies - fwdl_start_time) < 500) - ) { - /* reset FWDL chksum */ - rtw_write8(padapter, REG_MCUFWDL, rtw_read8(padapter, REG_MCUFWDL)|FWDL_ChkSum_rpt); - - rtStatus = _WriteFW(padapter, pFirmwareBuf, FirmwareLen); - if (rtStatus != _SUCCESS) - continue; - - rtStatus = polling_fwdl_chksum(padapter, 5, 50); - if (rtStatus == _SUCCESS) - break; - } - _FWDownloadEnable(padapter, false); - if (rtStatus != _SUCCESS) - goto fwdl_stat; - - rtStatus = _FWFreeToGo(padapter, 10, 200); - if (rtStatus != _SUCCESS) - goto fwdl_stat; - -fwdl_stat: - -exit: - kfree(pFirmware->fw_buffer_sz); - kfree(pFirmware); -release_fw1: - kfree(pBTFirmware); - return rtStatus; -} - -void rtl8723b_InitializeFirmwareVars(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - /* Init Fw LPS related. */ - adapter_to_pwrctl(padapter)->fw_current_in_ps_mode = false; - - /* Init H2C cmd. */ - rtw_write8(padapter, REG_HMETFR, 0x0f); - - /* Init H2C counter. by tynli. 2009.12.09. */ - pHalData->LastHMEBoxNum = 0; -/* pHalData->H2CQueueHead = 0; */ -/* pHalData->H2CQueueTail = 0; */ -/* pHalData->H2CStopInsertQueue = false; */ -} - -/* */ -/* Efuse related code */ -/* */ -static u8 hal_EfuseSwitchToBank( - struct adapter *padapter, u8 bank -) -{ - u8 bRet = true; - u32 value32 = rtw_read32(padapter, EFUSE_TEST); - - switch (bank) { - case 0: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0); - break; - case 1: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_BT_SEL_0); - break; - case 2: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_BT_SEL_1); - break; - case 3: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_BT_SEL_2); - break; - default: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0); - bRet = false; - break; - } - rtw_write32(padapter, EFUSE_TEST, value32); - - return bRet; -} - -void Hal_GetEfuseDefinition( - struct adapter *padapter, - u8 efuseType, - u8 type, - void *pOut -) -{ - switch (type) { - case TYPE_EFUSE_MAX_SECTION: - { - u8 *pMax_section = pOut; - - if (efuseType == EFUSE_WIFI) - *pMax_section = EFUSE_MAX_SECTION_8723B; - else - *pMax_section = EFUSE_BT_MAX_SECTION; - } - break; - - case TYPE_EFUSE_REAL_CONTENT_LEN: - { - u16 *pu2Tmp = pOut; - - if (efuseType == EFUSE_WIFI) - *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723B; - else - *pu2Tmp = EFUSE_BT_REAL_CONTENT_LEN; - } - break; - - case TYPE_AVAILABLE_EFUSE_BYTES_BANK: - { - u16 *pu2Tmp = pOut; - - if (efuseType == EFUSE_WIFI) - *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723B-EFUSE_OOB_PROTECT_BYTES); - else - *pu2Tmp = (EFUSE_BT_REAL_BANK_CONTENT_LEN-EFUSE_PROTECT_BYTES_BANK); - } - break; - - case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL: - { - u16 *pu2Tmp = pOut; - - if (efuseType == EFUSE_WIFI) - *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723B-EFUSE_OOB_PROTECT_BYTES); - else - *pu2Tmp = (EFUSE_BT_REAL_CONTENT_LEN-(EFUSE_PROTECT_BYTES_BANK*3)); - } - break; - - case TYPE_EFUSE_MAP_LEN: - { - u16 *pu2Tmp = pOut; - - if (efuseType == EFUSE_WIFI) - *pu2Tmp = EFUSE_MAX_MAP_LEN; - else - *pu2Tmp = EFUSE_BT_MAP_LEN; - } - break; - - case TYPE_EFUSE_PROTECT_BYTES_BANK: - { - u8 *pu1Tmp = pOut; - - if (efuseType == EFUSE_WIFI) - *pu1Tmp = EFUSE_OOB_PROTECT_BYTES; - else - *pu1Tmp = EFUSE_PROTECT_BYTES_BANK; - } - break; - - case TYPE_EFUSE_CONTENT_LEN_BANK: - { - u16 *pu2Tmp = pOut; - - if (efuseType == EFUSE_WIFI) - *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723B; - else - *pu2Tmp = EFUSE_BT_REAL_BANK_CONTENT_LEN; - } - break; - - default: - { - u8 *pu1Tmp = pOut; - *pu1Tmp = 0; - } - break; - } -} - -void Hal_EfusePowerSwitch( - struct adapter *padapter, u8 PwrState -) -{ - u8 tempval; - u16 tmpV16; - - if (PwrState) { - /* To avoid cannot access efuse registers after disable/enable several times during DTM test. */ - /* Suggested by SD1 IsaacHsu. 2013.07.08, added by tynli. */ - tempval = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HSUS_CTRL); - if (tempval & BIT(0)) { /* SDIO local register is suspend */ - u8 count = 0; - - tempval &= ~BIT(0); - rtw_write8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HSUS_CTRL, tempval); - - /* check 0x86[1:0]= 10'2h, wait power state to leave suspend */ - do { - tempval = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HSUS_CTRL); - tempval &= 0x3; - if (tempval == 0x02) - break; - - count++; - if (count >= 100) - break; - - mdelay(10); - } while (1); - } - - rtw_write8(padapter, REG_EFUSE_ACCESS, EFUSE_ACCESS_ON); - - /* Reset: 0x0000h[28], default valid */ - tmpV16 = rtw_read16(padapter, REG_SYS_FUNC_EN); - if (!(tmpV16 & FEN_ELDR)) { - tmpV16 |= FEN_ELDR; - rtw_write16(padapter, REG_SYS_FUNC_EN, tmpV16); - } - - /* Clock: Gated(0x0008h[5]) 8M(0x0008h[1]) clock from ANA, default valid */ - tmpV16 = rtw_read16(padapter, REG_SYS_CLKR); - if ((!(tmpV16 & LOADER_CLK_EN)) || (!(tmpV16 & ANA8M))) { - tmpV16 |= (LOADER_CLK_EN | ANA8M); - rtw_write16(padapter, REG_SYS_CLKR, tmpV16); - } - } else { - rtw_write8(padapter, REG_EFUSE_ACCESS, EFUSE_ACCESS_OFF); - } -} - -static void hal_ReadEFuse_WiFi( - struct adapter *padapter, - u16 _offset, - u16 _size_byte, - u8 *pbuf -) -{ - u8 *efuseTbl = NULL; - u16 eFuse_Addr = 0; - u8 offset, wden; - u8 efuseHeader, efuseExtHdr, efuseData; - u16 i, total, used; - u8 efuse_usage = 0; - - /* */ - /* Do NOT excess total size of EFuse table. Added by Roger, 2008.11.10. */ - /* */ - if ((_offset + _size_byte) > EFUSE_MAX_MAP_LEN) - return; - - efuseTbl = kmalloc(EFUSE_MAX_MAP_LEN, GFP_ATOMIC); - if (!efuseTbl) - return; - - /* 0xff will be efuse default value instead of 0x00. */ - memset(efuseTbl, 0xFF, EFUSE_MAX_MAP_LEN); - - /* switch bank back to bank 0 for later BT and wifi use. */ - hal_EfuseSwitchToBank(padapter, 0); - - while (AVAILABLE_EFUSE_ADDR(eFuse_Addr)) { - rtw_efuse_one_byte_read(padapter, eFuse_Addr++, &efuseHeader); - if (efuseHeader == 0xFF) - break; - - /* Check PG header for section num. */ - if (EXT_HEADER(efuseHeader)) { /* extended header */ - offset = GET_HDR_OFFSET_2_0(efuseHeader); - - rtw_efuse_one_byte_read(padapter, eFuse_Addr++, &efuseExtHdr); - if (ALL_WORDS_DISABLED(efuseExtHdr)) - continue; - - offset |= ((efuseExtHdr & 0xF0) >> 1); - wden = (efuseExtHdr & 0x0F); - } else { - offset = ((efuseHeader >> 4) & 0x0f); - wden = (efuseHeader & 0x0f); - } - - if (offset < EFUSE_MAX_SECTION_8723B) { - u16 addr; - /* Get word enable value from PG header */ - - addr = offset * PGPKT_DATA_SIZE; - for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { - /* Check word enable condition in the section */ - if (!(wden & (0x01< EFUSE_BT_MAP_LEN) - return; - - efuseTbl = kmalloc(EFUSE_BT_MAP_LEN, GFP_ATOMIC); - if (!efuseTbl) - return; - - /* 0xff will be efuse default value instead of 0x00. */ - memset(efuseTbl, 0xFF, EFUSE_BT_MAP_LEN); - - Hal_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_BANK, &total); - - for (bank = 1; bank < 3; bank++) { /* 8723b Max bake 0~2 */ - if (!hal_EfuseSwitchToBank(padapter, bank)) - goto exit; - - eFuse_Addr = 0; - - while (AVAILABLE_EFUSE_ADDR(eFuse_Addr)) { - rtw_efuse_one_byte_read(padapter, eFuse_Addr++, &efuseHeader); - if (efuseHeader == 0xFF) - break; - - /* Check PG header for section num. */ - if (EXT_HEADER(efuseHeader)) { /* extended header */ - offset = GET_HDR_OFFSET_2_0(efuseHeader); - - rtw_efuse_one_byte_read(padapter, eFuse_Addr++, &efuseExtHdr); - if (ALL_WORDS_DISABLED(efuseExtHdr)) - continue; - - offset |= ((efuseExtHdr & 0xF0) >> 1); - wden = (efuseExtHdr & 0x0F); - } else { - offset = ((efuseHeader >> 4) & 0x0f); - wden = (efuseHeader & 0x0f); - } - - if (offset < EFUSE_BT_MAX_SECTION) { - u16 addr = offset * PGPKT_DATA_SIZE; - - for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { - /* Check word enable condition in the section */ - if (!(wden & (0x01<chip_normal = ((value32 & RTL_ID) ? false : true); -} - -void rtl8723b_InitBeaconParameters(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u16 val16; - u8 val8 = DIS_TSF_UDT; - - val16 = val8 | (val8 << 8); /* port0 and port1 */ - - /* Enable prot0 beacon function for PSTDMA */ - val16 |= EN_BCN_FUNCTION; - - rtw_write16(padapter, REG_BCN_CTRL, val16); - - rtw_write16(padapter, REG_TBTT_PROHIBIT, TBTT_PROHIBIT_TIME_8723B); - /* Firmware will control REG_DRVERLYINT when power saving is enable, */ - /* so don't set this register on STA mode. */ - if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) - rtw_write8(padapter, REG_DRVERLYINT, DRIVER_EARLY_INT_TIME_8723B); /* 5ms */ - rtw_write8(padapter, REG_BCNDMATIM, BCN_DMA_ATIME_INT_TIME_8723B); /* 2ms */ - - /* Suggested by designer timchen. Change beacon AIFS to the largest number */ - /* because test chip does not contension before sending beacon. by tynli. 2009.11.03 */ - rtw_write16(padapter, REG_BCNTCFG, BCNTCFG_8723B); - - pHalData->RegFwHwTxQCtrl = rtw_read8(padapter, REG_FWHW_TXQ_CTRL+2); - pHalData->RegReg542 = rtw_read8(padapter, REG_TBTT_PROHIBIT+2); -} - -void _InitBurstPktLen_8723BS(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - rtw_write8(Adapter, 0x4c7, rtw_read8(Adapter, 0x4c7)|BIT(7)); /* enable single pkt ampdu */ - rtw_write8(Adapter, REG_RX_PKT_LIMIT_8723B, 0x18); /* for VHT packet length 11K */ - rtw_write8(Adapter, REG_MAX_AGGR_NUM_8723B, 0x1F); - rtw_write8(Adapter, REG_PIFS_8723B, 0x00); - rtw_write8(Adapter, REG_FWHW_TXQ_CTRL_8723B, rtw_read8(Adapter, REG_FWHW_TXQ_CTRL)&(~BIT(7))); - if (pHalData->AMPDUBurstMode) - rtw_write8(Adapter, REG_AMPDU_BURST_MODE_8723B, 0x5F); - rtw_write8(Adapter, REG_AMPDU_MAX_TIME_8723B, 0x70); - - /* ARFB table 9 for 11ac 5G 2SS */ - rtw_write32(Adapter, REG_ARFR0_8723B, 0x00000010); - if (pHalData->chip_normal) - rtw_write32(Adapter, REG_ARFR0_8723B+4, 0xfffff000); - else - rtw_write32(Adapter, REG_ARFR0_8723B+4, 0x3e0ff000); - - /* ARFB table 10 for 11ac 5G 1SS */ - rtw_write32(Adapter, REG_ARFR1_8723B, 0x00000010); - rtw_write32(Adapter, REG_ARFR1_8723B+4, 0x003ff000); -} - -static void ResumeTxBeacon(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - pHalData->RegFwHwTxQCtrl |= BIT(6); - rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl); - rtw_write8(padapter, REG_TBTT_PROHIBIT+1, 0xff); - pHalData->RegReg542 |= BIT(0); - rtw_write8(padapter, REG_TBTT_PROHIBIT+2, pHalData->RegReg542); -} - -static void StopTxBeacon(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - pHalData->RegFwHwTxQCtrl &= ~BIT(6); - rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl); - rtw_write8(padapter, REG_TBTT_PROHIBIT+1, 0x64); - pHalData->RegReg542 &= ~BIT(0); - rtw_write8(padapter, REG_TBTT_PROHIBIT+2, pHalData->RegReg542); -} - -static void _BeaconFunctionEnable(struct adapter *padapter, u8 Enable, u8 Linked) -{ - rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT | EN_BCN_FUNCTION | DIS_BCNQ_SUB); - rtw_write8(padapter, REG_RD_CTRL+1, 0x6F); -} - -void rtl8723b_SetBeaconRelatedRegisters(struct adapter *padapter) -{ - u8 val8; - u32 value32; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - u32 bcn_ctrl_reg; - - /* reset TSF, enable update TSF, correcting TSF On Beacon */ - - /* REG_BCN_INTERVAL */ - /* REG_BCNDMATIM */ - /* REG_ATIMWND */ - /* REG_TBTT_PROHIBIT */ - /* REG_DRVERLYINT */ - /* REG_BCN_MAX_ERR */ - /* REG_BCNTCFG (0x510) */ - /* REG_DUAL_TSF_RST */ - /* REG_BCN_CTRL (0x550) */ - - bcn_ctrl_reg = REG_BCN_CTRL; - - /* */ - /* ATIM window */ - /* */ - rtw_write16(padapter, REG_ATIMWND, 2); - - /* */ - /* Beacon interval (in unit of TU). */ - /* */ - rtw_write16(padapter, REG_BCN_INTERVAL, pmlmeinfo->bcn_interval); - - rtl8723b_InitBeaconParameters(padapter); - - rtw_write8(padapter, REG_SLOT, 0x09); - - /* */ - /* Reset TSF Timer to zero, added by Roger. 2008.06.24 */ - /* */ - value32 = rtw_read32(padapter, REG_TCR); - value32 &= ~TSFRST; - rtw_write32(padapter, REG_TCR, value32); - - value32 |= TSFRST; - rtw_write32(padapter, REG_TCR, value32); - - /* NOTE: Fix test chip's bug (about contention windows's randomness) */ - if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE | - WIFI_ADHOC_MASTER_STATE | WIFI_AP_STATE)) { - rtw_write8(padapter, REG_RXTSF_OFFSET_CCK, 0x50); - rtw_write8(padapter, REG_RXTSF_OFFSET_OFDM, 0x50); - } - - _BeaconFunctionEnable(padapter, true, true); - - ResumeTxBeacon(padapter); - val8 = rtw_read8(padapter, bcn_ctrl_reg); - val8 |= DIS_BCNQ_SUB; - rtw_write8(padapter, bcn_ctrl_reg, val8); -} - -void hal_notch_filter_8723b(struct adapter *adapter, bool enable) -{ - if (enable) - rtw_write8(adapter, rOFDM0_RxDSP+1, rtw_read8(adapter, rOFDM0_RxDSP+1) | BIT(1)); - else - rtw_write8(adapter, rOFDM0_RxDSP+1, rtw_read8(adapter, rOFDM0_RxDSP+1) & ~BIT(1)); -} - -void UpdateHalRAMask8723B(struct adapter *padapter, u32 mac_id, u8 rssi_level) -{ - u32 mask, rate_bitmap; - u8 short_gi_rate = false; - struct sta_info *psta; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dm_priv *pdmpriv = &pHalData->dmpriv; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); - - if (mac_id >= NUM_STA) /* CAM_SIZE */ - return; - - psta = pmlmeinfo->FW_sta_info[mac_id].psta; - if (!psta) - return; - - short_gi_rate = query_ra_short_GI(psta); - - mask = psta->ra_mask; - - rate_bitmap = 0xffffffff; - rate_bitmap = ODM_Get_Rate_Bitmap(&pHalData->odmpriv, mac_id, mask, rssi_level); - - mask &= rate_bitmap; - - rate_bitmap = hal_btcoex_GetRaMask(padapter); - mask &= ~rate_bitmap; - - if (pHalData->fw_ractrl) - rtl8723b_set_FwMacIdConfig_cmd(padapter, mac_id, psta->raid, psta->bw_mode, short_gi_rate, mask); - - /* set correct initial date rate for each mac_id */ - pdmpriv->INIDATA_RATE[mac_id] = psta->init_rate; -} - -void rtl8723b_InitAntenna_Selection(struct adapter *padapter) -{ - u8 val; - - val = rtw_read8(padapter, REG_LEDCFG2); - /* Let 8051 take control antenna setting */ - val |= BIT(7); /* DPDT_SEL_EN, 0x4C[23] */ - rtw_write8(padapter, REG_LEDCFG2, val); -} - -void rtl8723b_init_default_value(struct adapter *padapter) -{ - struct hal_com_data *pHalData; - struct dm_priv *pdmpriv; - u8 i; - - pHalData = GET_HAL_DATA(padapter); - pdmpriv = &pHalData->dmpriv; - - padapter->registrypriv.wireless_mode = WIRELESS_11BG_24N; - - /* init default value */ - pHalData->fw_ractrl = false; - if (!adapter_to_pwrctl(padapter)->bkeepfwalive) - pHalData->LastHMEBoxNum = 0; - - /* init dm default value */ - pdmpriv->TM_Trigger = 0;/* for IQK */ -/* pdmpriv->binitialized = false; */ -/* pdmpriv->prv_traffic_idx = 3; */ -/* pdmpriv->initialize = 0; */ - - pdmpriv->ThermalValue_HP_index = 0; - for (i = 0; i < HP_THERMAL_NUM; i++) - pdmpriv->ThermalValue_HP[i] = 0; - - /* init Efuse variables */ - pHalData->EfuseUsedBytes = 0; - pHalData->EfuseUsedPercentage = 0; -#ifdef HAL_EFUSE_MEMORY - pHalData->EfuseHal.fakeEfuseBank = 0; - pHalData->EfuseHal.fakeEfuseUsedBytes = 0; - memset(pHalData->EfuseHal.fakeEfuseContent, 0xFF, EFUSE_MAX_HW_SIZE); - memset(pHalData->EfuseHal.fakeEfuseInitMap, 0xFF, EFUSE_MAX_MAP_LEN); - memset(pHalData->EfuseHal.fakeEfuseModifiedMap, 0xFF, EFUSE_MAX_MAP_LEN); - pHalData->EfuseHal.BTEfuseUsedBytes = 0; - pHalData->EfuseHal.BTEfuseUsedPercentage = 0; - memset(pHalData->EfuseHal.BTEfuseContent, 0xFF, EFUSE_MAX_BT_BANK*EFUSE_MAX_HW_SIZE); - memset(pHalData->EfuseHal.BTEfuseInitMap, 0xFF, EFUSE_BT_MAX_MAP_LEN); - memset(pHalData->EfuseHal.BTEfuseModifiedMap, 0xFF, EFUSE_BT_MAX_MAP_LEN); - pHalData->EfuseHal.fakeBTEfuseUsedBytes = 0; - memset(pHalData->EfuseHal.fakeBTEfuseContent, 0xFF, EFUSE_MAX_BT_BANK*EFUSE_MAX_HW_SIZE); - memset(pHalData->EfuseHal.fakeBTEfuseInitMap, 0xFF, EFUSE_BT_MAX_MAP_LEN); - memset(pHalData->EfuseHal.fakeBTEfuseModifiedMap, 0xFF, EFUSE_BT_MAX_MAP_LEN); -#endif -} - -u8 GetEEPROMSize8723B(struct adapter *padapter) -{ - u8 size = 0; - u32 cr; - - cr = rtw_read16(padapter, REG_9346CR); - /* 6: EEPROM used is 93C46, 4: boot from E-Fuse. */ - size = (cr & BOOT_FROM_EEPROM) ? 6 : 4; - - return size; -} - -/* */ -/* */ -/* LLT R/W/Init function */ -/* */ -/* */ -s32 rtl8723b_InitLLTTable(struct adapter *padapter) -{ - unsigned long start, passing_time; - u32 val32; - s32 ret = _FAIL; - - val32 = rtw_read32(padapter, REG_AUTO_LLT); - val32 |= BIT_AUTO_INIT_LLT; - rtw_write32(padapter, REG_AUTO_LLT, val32); - - start = jiffies; - - do { - val32 = rtw_read32(padapter, REG_AUTO_LLT); - if (!(val32 & BIT_AUTO_INIT_LLT)) { - ret = _SUCCESS; - break; - } - - passing_time = jiffies_to_msecs(jiffies - start); - if (passing_time > 1000) - break; - - msleep(1); - } while (1); - - return ret; -} - -static void hal_get_chnl_group_8723b(u8 channel, u8 *group) -{ - if (channel >= 1 && channel <= 2) - *group = 0; - else if (channel >= 3 && channel <= 5) - *group = 1; - else if (channel >= 6 && channel <= 8) - *group = 2; - else if (channel >= 9 && channel <= 11) - *group = 3; - else if (channel >= 12 && channel <= 14) - *group = 4; -} - -void Hal_InitPGData(struct adapter *padapter, u8 *PROMContent) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - if (!pEEPROM->bautoload_fail_flag) { /* autoload OK. */ - if (!pEEPROM->EepromOrEfuse) { - /* Read EFUSE real map to shadow. */ - rtw_efuse_shadow_map_update(padapter, EFUSE_WIFI); - memcpy(PROMContent, pEEPROM->efuse_eeprom_data, HWSET_MAX_SIZE_8723B); - } - } else {/* autoload fail */ - if (!pEEPROM->EepromOrEfuse) - rtw_efuse_shadow_map_update(padapter, EFUSE_WIFI); - memcpy(PROMContent, pEEPROM->efuse_eeprom_data, HWSET_MAX_SIZE_8723B); - } -} - -void Hal_EfuseParseIDCode(struct adapter *padapter, u8 *hwinfo) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); -/* struct hal_com_data *pHalData = GET_HAL_DATA(padapter); */ - u16 EEPROMId; - - /* Check 0x8129 again for making sure autoload status!! */ - EEPROMId = le16_to_cpu(*((__le16 *)hwinfo)); - if (EEPROMId != RTL_EEPROM_ID) { - pEEPROM->bautoload_fail_flag = true; - } else - pEEPROM->bautoload_fail_flag = false; -} - -static void Hal_ReadPowerValueFromPROM_8723B( - struct adapter *Adapter, - struct TxPowerInfo24G *pwrInfo24G, - u8 *PROMContent, - bool AutoLoadFail -) -{ - u32 rfPath, eeAddr = EEPROM_TX_PWR_INX_8723B, group, TxCount = 0; - - memset(pwrInfo24G, 0, sizeof(struct TxPowerInfo24G)); - - if (PROMContent[eeAddr+1] == 0xFF) - AutoLoadFail = true; - - if (AutoLoadFail) { - for (rfPath = 0; rfPath < MAX_RF_PATH; rfPath++) { - /* 2.4G default value */ - for (group = 0; group < MAX_CHNL_GROUP_24G; group++) { - pwrInfo24G->IndexCCK_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX; - pwrInfo24G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX; - } - - for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) { - if (TxCount == 0) { - pwrInfo24G->BW20_Diff[rfPath][0] = EEPROM_DEFAULT_24G_HT20_DIFF; - pwrInfo24G->OFDM_Diff[rfPath][0] = EEPROM_DEFAULT_24G_OFDM_DIFF; - } else { - pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - pwrInfo24G->BW40_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - pwrInfo24G->CCK_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - } - } - } - - return; - } - - for (rfPath = 0; rfPath < MAX_RF_PATH; rfPath++) { - /* 2 2.4G default value */ - for (group = 0; group < MAX_CHNL_GROUP_24G; group++) { - pwrInfo24G->IndexCCK_Base[rfPath][group] = PROMContent[eeAddr++]; - if (pwrInfo24G->IndexCCK_Base[rfPath][group] == 0xFF) - pwrInfo24G->IndexCCK_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX; - } - - for (group = 0; group < MAX_CHNL_GROUP_24G-1; group++) { - pwrInfo24G->IndexBW40_Base[rfPath][group] = PROMContent[eeAddr++]; - if (pwrInfo24G->IndexBW40_Base[rfPath][group] == 0xFF) - pwrInfo24G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX; - } - - for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) { - if (TxCount == 0) { - pwrInfo24G->BW40_Diff[rfPath][TxCount] = 0; - if (PROMContent[eeAddr] == 0xFF) - pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_24G_HT20_DIFF; - else { - pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4; - if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ - pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0; - } - - if (PROMContent[eeAddr] == 0xFF) - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_24G_OFDM_DIFF; - else { - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f); - if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ - pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0; - } - pwrInfo24G->CCK_Diff[rfPath][TxCount] = 0; - eeAddr++; - } else { - if (PROMContent[eeAddr] == 0xFF) - pwrInfo24G->BW40_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - else { - pwrInfo24G->BW40_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4; - if (pwrInfo24G->BW40_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ - pwrInfo24G->BW40_Diff[rfPath][TxCount] |= 0xF0; - } - - if (PROMContent[eeAddr] == 0xFF) - pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - else { - pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f); - if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ - pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0; - } - eeAddr++; - - if (PROMContent[eeAddr] == 0xFF) - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - else { - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4; - if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ - pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0; - } - - if (PROMContent[eeAddr] == 0xFF) - pwrInfo24G->CCK_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; - else { - pwrInfo24G->CCK_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f); - if (pwrInfo24G->CCK_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ - pwrInfo24G->CCK_Diff[rfPath][TxCount] |= 0xF0; - } - eeAddr++; - } - } - } -} - -void Hal_EfuseParseTxPowerInfo_8723B( - struct adapter *padapter, u8 *PROMContent, bool AutoLoadFail -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct TxPowerInfo24G pwrInfo24G; - u8 rfPath, ch, TxCount = 1; - - Hal_ReadPowerValueFromPROM_8723B(padapter, &pwrInfo24G, PROMContent, AutoLoadFail); - for (rfPath = 0 ; rfPath < MAX_RF_PATH ; rfPath++) { - for (ch = 0 ; ch < CHANNEL_MAX_NUMBER; ch++) { - u8 group = 0; - - hal_get_chnl_group_8723b(ch + 1, &group); - - if (ch == 14-1) { - pHalData->Index24G_CCK_Base[rfPath][ch] = pwrInfo24G.IndexCCK_Base[rfPath][5]; - pHalData->Index24G_BW40_Base[rfPath][ch] = pwrInfo24G.IndexBW40_Base[rfPath][group]; - } else { - pHalData->Index24G_CCK_Base[rfPath][ch] = pwrInfo24G.IndexCCK_Base[rfPath][group]; - pHalData->Index24G_BW40_Base[rfPath][ch] = pwrInfo24G.IndexBW40_Base[rfPath][group]; - } - } - - for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) { - pHalData->OFDM_24G_Diff[rfPath][TxCount] = pwrInfo24G.OFDM_Diff[rfPath][TxCount]; - pHalData->BW20_24G_Diff[rfPath][TxCount] = pwrInfo24G.BW20_Diff[rfPath][TxCount]; - pHalData->BW40_24G_Diff[rfPath][TxCount] = pwrInfo24G.BW40_Diff[rfPath][TxCount]; - } - } - - /* 2010/10/19 MH Add Regulator recognize for CU. */ - if (!AutoLoadFail) { - pHalData->EEPROMRegulatory = (PROMContent[EEPROM_RF_BOARD_OPTION_8723B]&0x7); /* bit0~2 */ - if (PROMContent[EEPROM_RF_BOARD_OPTION_8723B] == 0xFF) - pHalData->EEPROMRegulatory = (EEPROM_DEFAULT_BOARD_OPTION&0x7); /* bit0~2 */ - } else - pHalData->EEPROMRegulatory = 0; -} - -void Hal_EfuseParseBTCoexistInfo_8723B( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 tempval; - u32 tmpu4; - - if (!AutoLoadFail) { - tmpu4 = rtw_read32(padapter, REG_MULTI_FUNC_CTRL); - if (tmpu4 & BT_FUNC_EN) - pHalData->EEPROMBluetoothCoexist = true; - else - pHalData->EEPROMBluetoothCoexist = false; - - tempval = hwinfo[EEPROM_RF_BT_SETTING_8723B]; - if (tempval != 0xFF) { - pHalData->EEPROMBluetoothAntNum = tempval & BIT(0); - /* EFUSE_0xC3[6] == 0, S1(Main)-RF_PATH_A; */ - /* EFUSE_0xC3[6] == 1, S0(Aux)-RF_PATH_B */ - if (tempval & BIT(6)) - pHalData->ant_path = RF_PATH_B; - else - pHalData->ant_path = RF_PATH_A; - } else { - pHalData->EEPROMBluetoothAntNum = Ant_x1; - if (pHalData->PackageType == PACKAGE_QFN68) - pHalData->ant_path = RF_PATH_B; - else - pHalData->ant_path = RF_PATH_A; - } - } else { - pHalData->EEPROMBluetoothCoexist = false; - pHalData->EEPROMBluetoothAntNum = Ant_x1; - pHalData->ant_path = RF_PATH_A; - } - - if (padapter->registrypriv.ant_num > 0) { - switch (padapter->registrypriv.ant_num) { - case 1: - pHalData->EEPROMBluetoothAntNum = Ant_x1; - break; - case 2: - pHalData->EEPROMBluetoothAntNum = Ant_x2; - break; - default: - break; - } - } - - hal_btcoex_SetBTCoexist(padapter, pHalData->EEPROMBluetoothCoexist); - hal_btcoex_SetPgAntNum(padapter, pHalData->EEPROMBluetoothAntNum == Ant_x2 ? 2 : 1); - if (pHalData->EEPROMBluetoothAntNum == Ant_x1) - hal_btcoex_SetSingleAntPath(padapter, pHalData->ant_path); -} - -void Hal_EfuseParsePackageType_8723B( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 package; - u8 efuseContent; - - Hal_EfusePowerSwitch(padapter, true); - rtw_efuse_one_byte_read(padapter, 0x1FB, &efuseContent); - Hal_EfusePowerSwitch(padapter, false); - - package = efuseContent & 0x7; - switch (package) { - case 0x4: - pHalData->PackageType = PACKAGE_TFBGA79; - break; - case 0x5: - pHalData->PackageType = PACKAGE_TFBGA90; - break; - case 0x6: - pHalData->PackageType = PACKAGE_QFN68; - break; - case 0x7: - pHalData->PackageType = PACKAGE_TFBGA80; - break; - - default: - pHalData->PackageType = PACKAGE_DEFAULT; - break; - } -} - -void Hal_EfuseParseVoltage_8723B( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - /* memcpy(pEEPROM->adjuseVoltageVal, &hwinfo[EEPROM_Voltage_ADDR_8723B], 1); */ - pEEPROM->adjuseVoltageVal = (hwinfo[EEPROM_Voltage_ADDR_8723B] & 0xf0) >> 4; -} - -void Hal_EfuseParseChnlPlan_8723B( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - padapter->mlmepriv.ChannelPlan = hal_com_config_channel_plan( - padapter, - hwinfo ? hwinfo[EEPROM_ChannelPlan_8723B] : 0xFF, - padapter->registrypriv.channel_plan, - RT_CHANNEL_DOMAIN_WORLD_NULL, - AutoLoadFail - ); - - Hal_ChannelPlanToRegulation(padapter, padapter->mlmepriv.ChannelPlan); -} - -void Hal_EfuseParseXtal_8723B( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - if (!AutoLoadFail) { - pHalData->CrystalCap = hwinfo[EEPROM_XTAL_8723B]; - if (pHalData->CrystalCap == 0xFF) - pHalData->CrystalCap = EEPROM_Default_CrystalCap_8723B; /* what value should 8812 set? */ - } else - pHalData->CrystalCap = EEPROM_Default_CrystalCap_8723B; -} - -void Hal_EfuseParseThermalMeter_8723B( - struct adapter *padapter, u8 *PROMContent, u8 AutoLoadFail -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - /* */ - /* ThermalMeter from EEPROM */ - /* */ - if (!AutoLoadFail) - pHalData->EEPROMThermalMeter = PROMContent[EEPROM_THERMAL_METER_8723B]; - else - pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter_8723B; - - if ((pHalData->EEPROMThermalMeter == 0xff) || AutoLoadFail) - pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter_8723B; -} - -void Hal_ReadRFGainOffset( - struct adapter *Adapter, u8 *PROMContent, bool AutoloadFail -) -{ - /* */ - /* BB_RF Gain Offset from EEPROM */ - /* */ - - if (!AutoloadFail) { - Adapter->eeprompriv.EEPROMRFGainOffset = PROMContent[EEPROM_RF_GAIN_OFFSET]; - Adapter->eeprompriv.EEPROMRFGainVal = rtw_efuse_read_1_byte(Adapter, - EEPROM_RF_GAIN_VAL); - } else { - Adapter->eeprompriv.EEPROMRFGainOffset = 0; - Adapter->eeprompriv.EEPROMRFGainVal = 0xFF; - } -} - -u8 BWMapping_8723B(struct adapter *Adapter, struct pkt_attrib *pattrib) -{ - u8 BWSettingOfDesc = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40) { - if (pattrib->bwmode == CHANNEL_WIDTH_40) - BWSettingOfDesc = 1; - else - BWSettingOfDesc = 0; - } else - BWSettingOfDesc = 0; - - /* if (pTcb->bBTTxPacket) */ - /* BWSettingOfDesc = 0; */ - - return BWSettingOfDesc; -} - -u8 SCMapping_8723B(struct adapter *Adapter, struct pkt_attrib *pattrib) -{ - u8 SCSettingOfDesc = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40) { - if (pattrib->bwmode == CHANNEL_WIDTH_40) { - SCSettingOfDesc = HT_DATA_SC_DONOT_CARE; - } else if (pattrib->bwmode == CHANNEL_WIDTH_20) { - if (pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER) { - SCSettingOfDesc = HT_DATA_SC_20_UPPER_OF_40MHZ; - } else if (pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) { - SCSettingOfDesc = HT_DATA_SC_20_LOWER_OF_40MHZ; - } else { - SCSettingOfDesc = HT_DATA_SC_DONOT_CARE; - } - } - } else { - SCSettingOfDesc = HT_DATA_SC_DONOT_CARE; - } - - return SCSettingOfDesc; -} - -static void rtl8723b_cal_txdesc_chksum(struct tx_desc *ptxdesc) -{ - u16 *usPtr = (u16 *)ptxdesc; - u32 count; - u32 index; - u16 checksum = 0; - - /* Clear first */ - ptxdesc->txdw7 &= cpu_to_le32(0xffff0000); - - /* checksum is always calculated by first 32 bytes, */ - /* and it doesn't depend on TX DESC length. */ - /* Thomas, Lucas@SD4, 20130515 */ - count = 16; - - for (index = 0; index < count; index++) - checksum |= le16_to_cpu(*(__le16 *)(usPtr + index)); - - ptxdesc->txdw7 |= cpu_to_le32(checksum & 0x0000ffff); -} - -static u8 fill_txdesc_sectype(struct pkt_attrib *pattrib) -{ - u8 sectype = 0; - - if ((pattrib->encrypt > 0) && !pattrib->bswenc) { - switch (pattrib->encrypt) { - /* SEC_TYPE */ - case _WEP40_: - case _WEP104_: - case _TKIP_: - case _TKIP_WTMIC_: - sectype = 1; - break; - - case _AES_: - sectype = 3; - break; - - case _NO_PRIVACY_: - default: - break; - } - } - return sectype; -} - -static void fill_txdesc_vcs_8723b(struct adapter *padapter, struct pkt_attrib *pattrib, struct txdesc_8723b *ptxdesc) -{ - if (pattrib->vcs_mode) { - switch (pattrib->vcs_mode) { - case RTS_CTS: - ptxdesc->rtsen = 1; - /* ENABLE HW RTS */ - ptxdesc->hw_rts_en = 1; - break; - - case CTS_TO_SELF: - ptxdesc->cts2self = 1; - break; - - case NONE_VCS: - default: - break; - } - - ptxdesc->rtsrate = 8; /* RTS Rate =24M */ - ptxdesc->rts_ratefb_lmt = 0xF; - - if (padapter->mlmeextpriv.mlmext_info.preamble_mode == PREAMBLE_SHORT) - ptxdesc->rts_short = 1; - - /* Set RTS BW */ - if (pattrib->ht_en) - ptxdesc->rts_sc = SCMapping_8723B(padapter, pattrib); - } -} - -static void fill_txdesc_phy_8723b(struct adapter *padapter, struct pkt_attrib *pattrib, struct txdesc_8723b *ptxdesc) -{ - if (pattrib->ht_en) { - ptxdesc->data_bw = BWMapping_8723B(padapter, pattrib); - - ptxdesc->data_sc = SCMapping_8723B(padapter, pattrib); - } -} - -static void rtl8723b_fill_default_txdesc( - struct xmit_frame *pxmitframe, u8 *pbuf -) -{ - struct adapter *padapter; - struct hal_com_data *pHalData; - struct mlme_ext_priv *pmlmeext; - struct mlme_ext_info *pmlmeinfo; - struct pkt_attrib *pattrib; - struct txdesc_8723b *ptxdesc; - s32 bmcst; - - memset(pbuf, 0, TXDESC_SIZE); - - padapter = pxmitframe->padapter; - pHalData = GET_HAL_DATA(padapter); - pmlmeext = &padapter->mlmeextpriv; - pmlmeinfo = &(pmlmeext->mlmext_info); - - pattrib = &pxmitframe->attrib; - bmcst = is_multicast_ether_addr(pattrib->ra); - - ptxdesc = (struct txdesc_8723b *)pbuf; - - if (pxmitframe->frame_tag == DATA_FRAMETAG) { - u8 drv_userate = 0; - - ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */ - ptxdesc->rate_id = pattrib->raid; - ptxdesc->qsel = pattrib->qsel; - ptxdesc->seq = pattrib->seqnum; - - ptxdesc->sectype = fill_txdesc_sectype(pattrib); - fill_txdesc_vcs_8723b(padapter, pattrib, ptxdesc); - - if (pattrib->icmp_pkt == 1 && padapter->registrypriv.wifi_spec == 1) - drv_userate = 1; - - if ( - (pattrib->ether_type != 0x888e) && - (pattrib->ether_type != 0x0806) && - (pattrib->ether_type != 0x88B4) && - (pattrib->dhcp_pkt != 1) && - (drv_userate != 1) - ) { - /* Non EAP & ARP & DHCP type data packet */ - - if (pattrib->ampdu_en) { - ptxdesc->agg_en = 1; /* AGG EN */ - ptxdesc->max_agg_num = 0x1f; - ptxdesc->ampdu_density = pattrib->ampdu_spacing; - } else - ptxdesc->bk = 1; /* AGG BK */ - - fill_txdesc_phy_8723b(padapter, pattrib, ptxdesc); - - ptxdesc->data_ratefb_lmt = 0x1F; - - if (!pHalData->fw_ractrl) { - ptxdesc->userate = 1; - - if (pHalData->dmpriv.INIDATA_RATE[pattrib->mac_id] & BIT(7)) - ptxdesc->data_short = 1; - - ptxdesc->datarate = pHalData->dmpriv.INIDATA_RATE[pattrib->mac_id] & 0x7F; - } - - if (padapter->fix_rate != 0xFF) { /* modify data rate by iwpriv */ - ptxdesc->userate = 1; - if (padapter->fix_rate & BIT(7)) - ptxdesc->data_short = 1; - - ptxdesc->datarate = (padapter->fix_rate & 0x7F); - ptxdesc->disdatafb = 1; - } - - if (pattrib->ldpc) - ptxdesc->data_ldpc = 1; - if (pattrib->stbc) - ptxdesc->data_stbc = 1; - } else { - /* EAP data packet and ARP packet. */ - /* Use the 1M data rate to send the EAP/ARP packet. */ - /* This will maybe make the handshake smooth. */ - - ptxdesc->bk = 1; /* AGG BK */ - ptxdesc->userate = 1; /* driver uses rate */ - if (pmlmeinfo->preamble_mode == PREAMBLE_SHORT) - ptxdesc->data_short = 1;/* DATA_SHORT */ - ptxdesc->datarate = MRateToHwRate(pmlmeext->tx_rate); - } - - ptxdesc->usb_txagg_num = pxmitframe->agg_num; - } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) { - ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */ - ptxdesc->qsel = pattrib->qsel; - ptxdesc->rate_id = pattrib->raid; /* Rate ID */ - ptxdesc->seq = pattrib->seqnum; - ptxdesc->userate = 1; /* driver uses rate, 1M */ - - ptxdesc->mbssid = pattrib->mbssid & 0xF; - - ptxdesc->rty_lmt_en = 1; /* retry limit enable */ - if (pattrib->retry_ctrl) { - ptxdesc->data_rt_lmt = 6; - } else { - ptxdesc->data_rt_lmt = 12; - } - - ptxdesc->datarate = MRateToHwRate(pmlmeext->tx_rate); - - /* CCX-TXRPT ack for xmit mgmt frames. */ - if (pxmitframe->ack_report) { - ptxdesc->spe_rpt = 1; - ptxdesc->sw_define = (u8)(GET_PRIMARY_ADAPTER(padapter)->xmitpriv.seq_no); - } - } else { - ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */ - ptxdesc->rate_id = pattrib->raid; /* Rate ID */ - ptxdesc->qsel = pattrib->qsel; - ptxdesc->seq = pattrib->seqnum; - ptxdesc->userate = 1; /* driver uses rate */ - ptxdesc->datarate = MRateToHwRate(pmlmeext->tx_rate); - } - - ptxdesc->pktlen = pattrib->last_txcmdsz; - ptxdesc->offset = TXDESC_SIZE + OFFSET_SZ; - - if (bmcst) - ptxdesc->bmc = 1; - - /* 2009.11.05. tynli_test. Suggested by SD4 Filen for FW LPS. - * (1) The sequence number of each non-Qos frame / broadcast / - * multicast / mgnt frame should be controlled by Hw because Fw - * will also send null data which we cannot control when Fw LPS - * enable. - * --> default enable non-Qos data sequence number. 2010.06.23. - * by tynli. - * (2) Enable HW SEQ control for beacon packet, because we use - * Hw beacon. - * (3) Use HW Qos SEQ to control the seq num of Ext port non-Qos - * packets. - * 2010.06.23. Added by tynli. - */ - if (!pattrib->qos_en) /* Hw set sequence number */ - ptxdesc->en_hwseq = 1; /* HWSEQ_EN */ -} - -/* Description: - * - * Parameters: - * pxmitframe xmitframe - * pbuf where to fill tx desc - */ -void rtl8723b_update_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf) -{ - struct tx_desc *pdesc; - - rtl8723b_fill_default_txdesc(pxmitframe, pbuf); - pdesc = (struct tx_desc *)pbuf; - rtl8723b_cal_txdesc_chksum(pdesc); -} - -/* */ -/* Description: In normal chip, we should send some packet to Hw which will be used by Fw */ -/* in FW LPS mode. The function is to fill the Tx descriptor of this packets, then */ -/* Fw can tell Hw to send these packet derectly. */ -/* Added by tynli. 2009.10.15. */ -/* */ -/* type1:pspoll, type2:null */ -void rtl8723b_fill_fake_txdesc( - struct adapter *padapter, - u8 *pDesc, - u32 BufferLen, - u8 IsPsPoll, - u8 IsBTQosNull, - u8 bDataFrame -) -{ - /* Clear all status */ - memset(pDesc, 0, TXDESC_SIZE); - - SET_TX_DESC_FIRST_SEG_8723B(pDesc, 1); /* bFirstSeg; */ - SET_TX_DESC_LAST_SEG_8723B(pDesc, 1); /* bLastSeg; */ - - SET_TX_DESC_OFFSET_8723B(pDesc, 0x28); /* Offset = 32 */ - - SET_TX_DESC_PKT_SIZE_8723B(pDesc, BufferLen); /* Buffer size + command header */ - SET_TX_DESC_QUEUE_SEL_8723B(pDesc, QSLT_MGNT); /* Fixed queue of Mgnt queue */ - - /* Set NAVUSEHDR to prevent Ps-poll AId filed to be changed to error value by Hw. */ - if (IsPsPoll) { - SET_TX_DESC_NAV_USE_HDR_8723B(pDesc, 1); - } else { - SET_TX_DESC_HWSEQ_EN_8723B(pDesc, 1); /* Hw set sequence number */ - SET_TX_DESC_HWSEQ_SEL_8723B(pDesc, 0); - } - - if (IsBTQosNull) - SET_TX_DESC_BT_INT_8723B(pDesc, 1); - - SET_TX_DESC_USE_RATE_8723B(pDesc, 1); /* use data rate which is set by Sw */ - SET_TX_DESC_OWN_8723B((u8 *)pDesc, 1); - - SET_TX_DESC_TX_RATE_8723B(pDesc, DESC8723B_RATE1M); - - /* */ - /* Encrypt the data frame if under security mode excepct null data. Suggested by CCW. */ - /* */ - if (bDataFrame) { - u32 EncAlg = padapter->securitypriv.dot11_privacy_algrthm; - - switch (EncAlg) { - case _NO_PRIVACY_: - SET_TX_DESC_SEC_TYPE_8723B(pDesc, 0x0); - break; - case _WEP40_: - case _WEP104_: - case _TKIP_: - SET_TX_DESC_SEC_TYPE_8723B(pDesc, 0x1); - break; - case _SMS4_: - SET_TX_DESC_SEC_TYPE_8723B(pDesc, 0x2); - break; - case _AES_: - SET_TX_DESC_SEC_TYPE_8723B(pDesc, 0x3); - break; - default: - SET_TX_DESC_SEC_TYPE_8723B(pDesc, 0x0); - break; - } - } - - /* USB interface drop packet if the checksum of descriptor isn't correct. */ - /* Using this checksum can let hardware recovery from packet bulk out error (e.g. Cancel URC, Bulk out error.). */ - rtl8723b_cal_txdesc_chksum((struct tx_desc *)pDesc); -} - -static void hw_var_set_opmode(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 val8; - u8 mode = *((u8 *)val); - - { - /* disable Port0 TSF update */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 |= DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - /* set net_type */ - set_msr(padapter, mode); - - if ((mode == _HW_STATE_STATION_) || (mode == _HW_STATE_NOLINK_)) { - { - StopTxBeacon(padapter); - } - - /* disable atim wnd */ - rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|EN_BCN_FUNCTION|DIS_ATIM); - /* rtw_write8(padapter, REG_BCN_CTRL, 0x18); */ - } else if (mode == _HW_STATE_ADHOC_) { - ResumeTxBeacon(padapter); - rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|EN_BCN_FUNCTION|DIS_BCNQ_SUB); - } else if (mode == _HW_STATE_AP_) { - - ResumeTxBeacon(padapter); - - rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|DIS_BCNQ_SUB); - - /* Set RCR */ - rtw_write32(padapter, REG_RCR, 0x7000208e);/* CBSSID_DATA must set to 0, reject ICV_ERR packet */ - /* enable to rx data frame */ - rtw_write16(padapter, REG_RXFLTMAP2, 0xFFFF); - /* enable to rx ps-poll */ - rtw_write16(padapter, REG_RXFLTMAP1, 0x0400); - - /* Beacon Control related register for first time */ - rtw_write8(padapter, REG_BCNDMATIM, 0x02); /* 2ms */ - - /* rtw_write8(padapter, REG_BCN_MAX_ERR, 0xFF); */ - rtw_write8(padapter, REG_ATIMWND, 0x0a); /* 10ms */ - rtw_write16(padapter, REG_BCNTCFG, 0x00); - rtw_write16(padapter, REG_TBTT_PROHIBIT, 0xff04); - rtw_write16(padapter, REG_TSFTR_SYN_OFFSET, 0x7fff);/* +32767 (~32ms) */ - - /* reset TSF */ - rtw_write8(padapter, REG_DUAL_TSF_RST, BIT(0)); - - /* enable BCN0 Function for if1 */ - /* don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received) */ - rtw_write8(padapter, REG_BCN_CTRL, (DIS_TSF_UDT|EN_BCN_FUNCTION|EN_TXBCN_RPT|DIS_BCNQ_SUB)); - - /* SW_BCN_SEL - Port0 */ - /* rtw_write8(Adapter, REG_DWBCN1_CTRL_8192E+2, rtw_read8(Adapter, REG_DWBCN1_CTRL_8192E+2) & ~BIT4); */ - rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL); - - /* select BCN on port 0 */ - rtw_write8( - padapter, - REG_CCK_CHECK_8723B, - (rtw_read8(padapter, REG_CCK_CHECK_8723B)&~BIT_BCN_PORT_SEL) - ); - - /* dis BCN1 ATIM WND if if2 is station */ - val8 = rtw_read8(padapter, REG_BCN_CTRL_1); - val8 |= DIS_ATIM; - rtw_write8(padapter, REG_BCN_CTRL_1, val8); - } - } -} - -static void hw_var_set_macaddr(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 idx = 0; - u32 reg_macid = REG_MACID; - - for (idx = 0 ; idx < 6; idx++) - rtw_write8(GET_PRIMARY_ADAPTER(padapter), (reg_macid+idx), val[idx]); -} - -static void hw_var_set_bssid(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 idx = 0; - u32 reg_bssid = REG_BSSID; - - for (idx = 0 ; idx < 6; idx++) - rtw_write8(padapter, (reg_bssid+idx), val[idx]); -} - -static void hw_var_set_bcn_func(struct adapter *padapter, u8 variable, u8 *val) -{ - u32 bcn_ctrl_reg = REG_BCN_CTRL; - - if (*(u8 *)val) - rtw_write8(padapter, bcn_ctrl_reg, (EN_BCN_FUNCTION | EN_TXBCN_RPT)); - else { - u8 val8; - - val8 = rtw_read8(padapter, bcn_ctrl_reg); - val8 &= ~(EN_BCN_FUNCTION | EN_TXBCN_RPT); - - /* Always enable port0 beacon function for PSTDMA */ - if (bcn_ctrl_reg == REG_BCN_CTRL) - val8 |= EN_BCN_FUNCTION; - - rtw_write8(padapter, bcn_ctrl_reg, val8); - } -} - -static void hw_var_set_correct_tsf(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 val8; - u64 tsf; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - - tsf = pmlmeext->TSFValue-do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024))-1024; /* us */ - - if ( - ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || - ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) - ) - StopTxBeacon(padapter); - - { - /* disable related TSF function */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 &= ~EN_BCN_FUNCTION; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - rtw_write32(padapter, REG_TSFTR, tsf); - rtw_write32(padapter, REG_TSFTR+4, tsf>>32); - - /* enable related TSF function */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 |= EN_BCN_FUNCTION; - rtw_write8(padapter, REG_BCN_CTRL, val8); - } - - if ( - ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || - ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) - ) - ResumeTxBeacon(padapter); -} - -static void hw_var_set_mlme_disconnect(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 val8; - - /* Set RCR to not to receive data frame when NO LINK state */ - /* rtw_write32(padapter, REG_RCR, rtw_read32(padapter, REG_RCR) & ~RCR_ADF); */ - /* reject all data frames */ - rtw_write16(padapter, REG_RXFLTMAP2, 0); - - /* reset TSF */ - rtw_write8(padapter, REG_DUAL_TSF_RST, BIT(0)); - - /* disable update TSF */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 |= DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); -} - -static void hw_var_set_mlme_sitesurvey(struct adapter *padapter, u8 variable, u8 *val) -{ - u32 value_rcr, rcr_clear_bit, reg_bcn_ctl; - u16 value_rxfltmap2; - u8 val8; - struct hal_com_data *pHalData; - struct mlme_priv *pmlmepriv; - - pHalData = GET_HAL_DATA(padapter); - pmlmepriv = &padapter->mlmepriv; - - reg_bcn_ctl = REG_BCN_CTRL; - - rcr_clear_bit = RCR_CBSSID_BCN; - - /* config RCR to receive different BSSID & not to receive data frame */ - value_rxfltmap2 = 0; - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - rcr_clear_bit = RCR_CBSSID_BCN; - - value_rcr = rtw_read32(padapter, REG_RCR); - - if (*((u8 *)val)) { - /* under sitesurvey */ - value_rcr &= ~(rcr_clear_bit); - rtw_write32(padapter, REG_RCR, value_rcr); - - rtw_write16(padapter, REG_RXFLTMAP2, value_rxfltmap2); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) { - /* disable update TSF */ - val8 = rtw_read8(padapter, reg_bcn_ctl); - val8 |= DIS_TSF_UDT; - rtw_write8(padapter, reg_bcn_ctl, val8); - } - - /* Save original RRSR setting. */ - pHalData->RegRRSR = rtw_read16(padapter, REG_RRSR); - } else { - /* sitesurvey done */ - if (check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE))) - /* enable to rx data frame */ - rtw_write16(padapter, REG_RXFLTMAP2, 0xFFFF); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) { - /* enable update TSF */ - val8 = rtw_read8(padapter, reg_bcn_ctl); - val8 &= ~DIS_TSF_UDT; - rtw_write8(padapter, reg_bcn_ctl, val8); - } - - value_rcr |= rcr_clear_bit; - rtw_write32(padapter, REG_RCR, value_rcr); - - /* Restore original RRSR setting. */ - rtw_write16(padapter, REG_RRSR, pHalData->RegRRSR); - } -} - -static void hw_var_set_mlme_join(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 val8; - u16 val16; - u32 val32; - u8 RetryLimit = 0x30; - u8 type = *(u8 *)val; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct eeprom_priv *pEEPROM; - - pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - if (type == 0) { /* prepare to join */ - /* enable to rx data frame.Accept all data frame */ - /* rtw_write32(padapter, REG_RCR, rtw_read32(padapter, REG_RCR)|RCR_ADF); */ - rtw_write16(padapter, REG_RXFLTMAP2, 0xFFFF); - - val32 = rtw_read32(padapter, REG_RCR); - if (padapter->in_cta_test) - val32 &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);/* RCR_ADF */ - else - val32 |= RCR_CBSSID_DATA|RCR_CBSSID_BCN; - rtw_write32(padapter, REG_RCR, val32); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) - RetryLimit = (pEEPROM->CustomerID == RT_CID_CCX) ? 7 : 48; - else /* Ad-hoc Mode */ - RetryLimit = 0x7; - } else if (type == 1) /* joinbss_event call back when join res < 0 */ - rtw_write16(padapter, REG_RXFLTMAP2, 0x00); - else if (type == 2) { /* sta add event call back */ - /* enable update TSF */ - val8 = rtw_read8(padapter, REG_BCN_CTRL); - val8 &= ~DIS_TSF_UDT; - rtw_write8(padapter, REG_BCN_CTRL, val8); - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) - RetryLimit = 0x7; - } - - val16 = (RetryLimit << RETRY_LIMIT_SHORT_SHIFT) | (RetryLimit << RETRY_LIMIT_LONG_SHIFT); - rtw_write16(padapter, REG_RL, val16); -} - -void CCX_FwC2HTxRpt_8723b(struct adapter *padapter, u8 *pdata, u8 len) -{ - -#define GET_8723B_C2H_TX_RPT_LIFE_TIME_OVER(_Header) LE_BITS_TO_1BYTE((_Header + 0), 6, 1) -#define GET_8723B_C2H_TX_RPT_RETRY_OVER(_Header) LE_BITS_TO_1BYTE((_Header + 0), 7, 1) - - if (GET_8723B_C2H_TX_RPT_RETRY_OVER(pdata) | GET_8723B_C2H_TX_RPT_LIFE_TIME_OVER(pdata)) - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_CCX_PKT_FAIL); - -/* - else if (seq_no != padapter->xmitpriv.seq_no) { - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_CCX_PKT_FAIL); - } -*/ - else - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_SUCCESS); -} - -s32 c2h_id_filter_ccx_8723b(u8 *buf) -{ - struct c2h_evt_hdr_88xx *c2h_evt = (struct c2h_evt_hdr_88xx *)buf; - s32 ret = false; - - if (c2h_evt->id == C2H_CCX_TX_RPT) - ret = true; - - return ret; -} - -s32 c2h_handler_8723b(struct adapter *padapter, u8 *buf) -{ - struct c2h_evt_hdr_88xx *pC2hEvent = (struct c2h_evt_hdr_88xx *)buf; - s32 ret = _SUCCESS; - - if (!pC2hEvent) { - ret = _FAIL; - goto exit; - } - - switch (pC2hEvent->id) { - case C2H_AP_RPT_RSP: - break; - case C2H_DBG: - { - } - break; - - case C2H_CCX_TX_RPT: -/* CCX_FwC2HTxRpt(padapter, QueueID, pC2hEvent->payload); */ - break; - - case C2H_EXT_RA_RPT: -/* C2HExtRaRptHandler(padapter, pC2hEvent->payload, C2hEvent.CmdLen); */ - break; - - case C2H_HW_INFO_EXCH: - break; - - case C2H_8723B_BT_INFO: - hal_btcoex_BtInfoNotify(padapter, pC2hEvent->plen, pC2hEvent->payload); - break; - - default: - break; - } - - /* Clear event to notify FW we have read the command. */ - /* Note: */ - /* If this field isn't clear, the FW won't update the next command message. */ -/* rtw_write8(padapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE); */ -exit: - return ret; -} - -static void process_c2h_event(struct adapter *padapter, struct c2h_evt_hdr_t *pC2hEvent, u8 *c2hBuf) -{ - if (!c2hBuf) - return; - - switch (pC2hEvent->CmdID) { - case C2H_AP_RPT_RSP: - break; - case C2H_DBG: - { - } - break; - - case C2H_CCX_TX_RPT: -/* CCX_FwC2HTxRpt(padapter, QueueID, tmpBuf); */ - break; - - case C2H_EXT_RA_RPT: -/* C2HExtRaRptHandler(padapter, tmpBuf, C2hEvent.CmdLen); */ - break; - - case C2H_HW_INFO_EXCH: - break; - - case C2H_8723B_BT_INFO: - hal_btcoex_BtInfoNotify(padapter, pC2hEvent->CmdLen, c2hBuf); - break; - - default: - break; - } -} - -void C2HPacketHandler_8723B(struct adapter *padapter, u8 *pbuffer, u16 length) -{ - struct c2h_evt_hdr_t C2hEvent; - u8 *tmpBuf = NULL; - - C2hEvent.CmdID = pbuffer[0]; - C2hEvent.CmdSeq = pbuffer[1]; - C2hEvent.CmdLen = length-2; - tmpBuf = pbuffer+2; - - process_c2h_event(padapter, &C2hEvent, tmpBuf); - /* c2h_handler_8723b(padapter,&C2hEvent); */ -} - -void SetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 val8; - u32 val32; - - switch (variable) { - case HW_VAR_MEDIA_STATUS: - val8 = rtw_read8(padapter, MSR) & 0x0c; - val8 |= *val; - rtw_write8(padapter, MSR, val8); - break; - - case HW_VAR_MEDIA_STATUS1: - val8 = rtw_read8(padapter, MSR) & 0x03; - val8 |= *val << 2; - rtw_write8(padapter, MSR, val8); - break; - - case HW_VAR_SET_OPMODE: - hw_var_set_opmode(padapter, variable, val); - break; - - case HW_VAR_MAC_ADDR: - hw_var_set_macaddr(padapter, variable, val); - break; - - case HW_VAR_BSSID: - hw_var_set_bssid(padapter, variable, val); - break; - - case HW_VAR_BASIC_RATE: - { - struct mlme_ext_info *mlmext_info = &padapter->mlmeextpriv.mlmext_info; - u16 BrateCfg = 0; - u16 rrsr_2g_force_mask = (RRSR_11M|RRSR_5_5M|RRSR_1M); - u16 rrsr_2g_allow_mask = (RRSR_24M|RRSR_12M|RRSR_6M|RRSR_CCK_RATES); - - HalSetBrateCfg(padapter, val, &BrateCfg); - - /* apply force and allow mask */ - BrateCfg |= rrsr_2g_force_mask; - BrateCfg &= rrsr_2g_allow_mask; - - /* IOT consideration */ - if (mlmext_info->assoc_AP_vendor == HT_IOT_PEER_CISCO) { - /* if peer is cisco and didn't use ofdm rate, we enable 6M ack */ - if ((BrateCfg & (RRSR_24M|RRSR_12M|RRSR_6M)) == 0) - BrateCfg |= RRSR_6M; - } - - pHalData->BasicRateSet = BrateCfg; - - /* Set RRSR rate table. */ - rtw_write16(padapter, REG_RRSR, BrateCfg); - rtw_write8(padapter, REG_RRSR+2, rtw_read8(padapter, REG_RRSR+2)&0xf0); - } - break; - - case HW_VAR_TXPAUSE: - rtw_write8(padapter, REG_TXPAUSE, *val); - break; - - case HW_VAR_BCN_FUNC: - hw_var_set_bcn_func(padapter, variable, val); - break; - - case HW_VAR_CORRECT_TSF: - hw_var_set_correct_tsf(padapter, variable, val); - break; - - case HW_VAR_CHECK_BSSID: - { - u32 val32; - - val32 = rtw_read32(padapter, REG_RCR); - if (*val) - val32 |= RCR_CBSSID_DATA|RCR_CBSSID_BCN; - else - val32 &= ~(RCR_CBSSID_DATA|RCR_CBSSID_BCN); - rtw_write32(padapter, REG_RCR, val32); - } - break; - - case HW_VAR_MLME_DISCONNECT: - hw_var_set_mlme_disconnect(padapter, variable, val); - break; - - case HW_VAR_MLME_SITESURVEY: - hw_var_set_mlme_sitesurvey(padapter, variable, val); - - hal_btcoex_ScanNotify(padapter, *val?true:false); - break; - - case HW_VAR_MLME_JOIN: - hw_var_set_mlme_join(padapter, variable, val); - - switch (*val) { - case 0: - /* prepare to join */ - hal_btcoex_ConnectNotify(padapter, true); - break; - case 1: - /* joinbss_event callback when join res < 0 */ - hal_btcoex_ConnectNotify(padapter, false); - break; - case 2: - /* sta add event callback */ -/* rtw_btcoex_MediaStatusNotify(padapter, RT_MEDIA_CONNECT); */ - break; - } - break; - - case HW_VAR_ON_RCR_AM: - val32 = rtw_read32(padapter, REG_RCR); - val32 |= RCR_AM; - rtw_write32(padapter, REG_RCR, val32); - break; - - case HW_VAR_OFF_RCR_AM: - val32 = rtw_read32(padapter, REG_RCR); - val32 &= ~RCR_AM; - rtw_write32(padapter, REG_RCR, val32); - break; - - case HW_VAR_BEACON_INTERVAL: - rtw_write16(padapter, REG_BCN_INTERVAL, *((u16 *)val)); - break; - - case HW_VAR_SLOT_TIME: - rtw_write8(padapter, REG_SLOT, *val); - break; - - case HW_VAR_RESP_SIFS: - /* SIFS_Timer = 0x0a0a0808; */ - /* RESP_SIFS for CCK */ - rtw_write8(padapter, REG_RESP_SIFS_CCK, val[0]); /* SIFS_T2T_CCK (0x08) */ - rtw_write8(padapter, REG_RESP_SIFS_CCK+1, val[1]); /* SIFS_R2T_CCK(0x08) */ - /* RESP_SIFS for OFDM */ - rtw_write8(padapter, REG_RESP_SIFS_OFDM, val[2]); /* SIFS_T2T_OFDM (0x0a) */ - rtw_write8(padapter, REG_RESP_SIFS_OFDM+1, val[3]); /* SIFS_R2T_OFDM(0x0a) */ - break; - - case HW_VAR_ACK_PREAMBLE: - { - u8 regTmp = 0; - u8 bShortPreamble = *val; - - /* Joseph marked out for Netgear 3500 TKIP channel 7 issue.(Temporarily) */ - /* regTmp = (pHalData->nCur40MhzPrimeSC)<<5; */ - if (bShortPreamble) - regTmp |= 0x80; - rtw_write8(padapter, REG_RRSR+2, regTmp); - } - break; - - case HW_VAR_CAM_EMPTY_ENTRY: - { - u8 ucIndex = *val; - u8 i; - u32 ulCommand = 0; - u32 ulContent = 0; - u32 ulEncAlgo = CAM_AES; - - for (i = 0; i < CAM_CONTENT_COUNT; i++) { - /* filled id in CAM config 2 byte */ - if (i == 0) { - ulContent |= (ucIndex & 0x03) | ((u16)(ulEncAlgo)<<2); - /* ulContent |= CAM_VALID; */ - } else - ulContent = 0; - - /* polling bit, and No Write enable, and address */ - ulCommand = CAM_CONTENT_COUNT*ucIndex+i; - ulCommand = ulCommand | CAM_POLLINIG | CAM_WRITE; - /* write content 0 is equal to mark as invalid */ - rtw_write32(padapter, WCAMI, ulContent); /* mdelay(40); */ - rtw_write32(padapter, RWCAM, ulCommand); /* mdelay(40); */ - } - } - break; - - case HW_VAR_CAM_INVALID_ALL: - rtw_write32(padapter, RWCAM, BIT(31)|BIT(30)); - break; - - case HW_VAR_CAM_WRITE: - { - u32 cmd; - u32 *cam_val = (u32 *)val; - - rtw_write32(padapter, WCAMI, cam_val[0]); - - cmd = CAM_POLLINIG | CAM_WRITE | cam_val[1]; - rtw_write32(padapter, RWCAM, cmd); - } - break; - - case HW_VAR_AC_PARAM_VO: - rtw_write32(padapter, REG_EDCA_VO_PARAM, *((u32 *)val)); - break; - - case HW_VAR_AC_PARAM_VI: - rtw_write32(padapter, REG_EDCA_VI_PARAM, *((u32 *)val)); - break; - - case HW_VAR_AC_PARAM_BE: - pHalData->AcParam_BE = ((u32 *)(val))[0]; - rtw_write32(padapter, REG_EDCA_BE_PARAM, *((u32 *)val)); - break; - - case HW_VAR_AC_PARAM_BK: - rtw_write32(padapter, REG_EDCA_BK_PARAM, *((u32 *)val)); - break; - - case HW_VAR_ACM_CTRL: - { - u8 ctrl = *((u8 *)val); - u8 hwctrl = 0; - - if (ctrl != 0) { - hwctrl |= AcmHw_HwEn; - - if (ctrl & BIT(1)) /* BE */ - hwctrl |= AcmHw_BeqEn; - - if (ctrl & BIT(2)) /* VI */ - hwctrl |= AcmHw_ViqEn; - - if (ctrl & BIT(3)) /* VO */ - hwctrl |= AcmHw_VoqEn; - } - - rtw_write8(padapter, REG_ACMHWCTRL, hwctrl); - } - break; - - case HW_VAR_AMPDU_FACTOR: - { - u32 AMPDULen = (*((u8 *)val)); - - if (AMPDULen < HT_AGG_SIZE_32K) - AMPDULen = (0x2000 << (*((u8 *)val)))-1; - else - AMPDULen = 0x7fff; - - rtw_write32(padapter, REG_AMPDU_MAX_LENGTH_8723B, AMPDULen); - } - break; - - case HW_VAR_H2C_FW_PWRMODE: - { - u8 psmode = *val; - - /* Forece leave RF low power mode for 1T1R to prevent conficting setting in Fw power */ - /* saving sequence. 2010.06.07. Added by tynli. Suggested by SD3 yschang. */ - if (psmode != PS_MODE_ACTIVE) - ODM_RF_Saving(&pHalData->odmpriv, true); - - /* if (psmode != PS_MODE_ACTIVE) { */ - /* rtl8723b_set_lowpwr_lps_cmd(padapter, true); */ - /* else { */ - /* rtl8723b_set_lowpwr_lps_cmd(padapter, false); */ - /* */ - rtl8723b_set_FwPwrMode_cmd(padapter, psmode); - } - break; - case HW_VAR_H2C_PS_TUNE_PARAM: - rtl8723b_set_FwPsTuneParam_cmd(padapter); - break; - - case HW_VAR_H2C_FW_JOINBSSRPT: - rtl8723b_set_FwJoinBssRpt_cmd(padapter, *val); - break; - - case HW_VAR_INITIAL_GAIN: - { - struct dig_t *pDigTable = &pHalData->odmpriv.DM_DigTable; - u32 rx_gain = *(u32 *)val; - - if (rx_gain == 0xff) {/* restore rx gain */ - ODM_Write_DIG(&pHalData->odmpriv, pDigTable->BackupIGValue); - } else { - pDigTable->BackupIGValue = pDigTable->CurIGValue; - ODM_Write_DIG(&pHalData->odmpriv, rx_gain); - } - } - break; - - case HW_VAR_EFUSE_USAGE: - pHalData->EfuseUsedPercentage = *val; - break; - - case HW_VAR_EFUSE_BYTES: - pHalData->EfuseUsedBytes = *((u16 *)val); - break; - - case HW_VAR_EFUSE_BT_USAGE: -#ifdef HAL_EFUSE_MEMORY - pHalData->EfuseHal.BTEfuseUsedPercentage = *val; -#endif - break; - - case HW_VAR_EFUSE_BT_BYTES: -#ifdef HAL_EFUSE_MEMORY - pHalData->EfuseHal.BTEfuseUsedBytes = *((u16 *)val); -#else - BTEfuseUsedBytes = *((u16 *)val); -#endif - break; - - case HW_VAR_FIFO_CLEARN_UP: - { - #define RW_RELEASE_EN BIT(18) - #define RXDMA_IDLE BIT(17) - - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - u8 trycnt = 100; - - /* pause tx */ - rtw_write8(padapter, REG_TXPAUSE, 0xff); - - /* keep sn */ - padapter->xmitpriv.nqos_ssn = rtw_read16(padapter, REG_NQOS_SEQ); - - if (!pwrpriv->bkeepfwalive) { - /* RX DMA stop */ - val32 = rtw_read32(padapter, REG_RXPKT_NUM); - val32 |= RW_RELEASE_EN; - rtw_write32(padapter, REG_RXPKT_NUM, val32); - do { - val32 = rtw_read32(padapter, REG_RXPKT_NUM); - val32 &= RXDMA_IDLE; - if (val32) - break; - } while (--trycnt); - - /* RQPN Load 0 */ - rtw_write16(padapter, REG_RQPN_NPQ, 0); - rtw_write32(padapter, REG_RQPN, 0x80000000); - mdelay(2); - } - } - break; - - case HW_VAR_APFM_ON_MAC: - pHalData->bMacPwrCtrlOn = *val; - break; - - case HW_VAR_NAV_UPPER: - { - u32 usNavUpper = *((u32 *)val); - - if (usNavUpper > HAL_NAV_UPPER_UNIT_8723B * 0xFF) - break; - - usNavUpper = DIV_ROUND_UP(usNavUpper, - HAL_NAV_UPPER_UNIT_8723B); - rtw_write8(padapter, REG_NAV_UPPER, (u8)usNavUpper); - } - break; - - case HW_VAR_H2C_MEDIA_STATUS_RPT: - { - u16 mstatus_rpt = (*(u16 *)val); - u8 mstatus, macId; - - mstatus = (u8) (mstatus_rpt & 0xFF); - macId = (u8)(mstatus_rpt >> 8); - rtl8723b_set_FwMediaStatusRpt_cmd(padapter, mstatus, macId); - } - break; - case HW_VAR_BCN_VALID: - { - /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2, write 1 to clear, Clear by sw */ - val8 = rtw_read8(padapter, REG_TDECTRL+2); - val8 |= BIT(0); - rtw_write8(padapter, REG_TDECTRL+2, val8); - } - break; - - case HW_VAR_DL_BCN_SEL: - { - /* SW_BCN_SEL - Port0 */ - val8 = rtw_read8(padapter, REG_DWBCN1_CTRL_8723B+2); - val8 &= ~BIT(4); - rtw_write8(padapter, REG_DWBCN1_CTRL_8723B+2, val8); - } - break; - - case HW_VAR_DL_RSVD_PAGE: - if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) - rtl8723b_download_BTCoex_AP_mode_rsvd_page(padapter); - else - rtl8723b_download_rsvd_page(padapter, RT_MEDIA_CONNECT); - break; - - case HW_VAR_MACID_SLEEP: - /* Input is MACID */ - val32 = *(u32 *)val; - if (val32 > 31) - break; - - val8 = (u8)val32; /* macid is between 0~31 */ - - val32 = rtw_read32(padapter, REG_MACID_SLEEP); - if (val32 & BIT(val8)) - break; - val32 |= BIT(val8); - rtw_write32(padapter, REG_MACID_SLEEP, val32); - break; - - case HW_VAR_MACID_WAKEUP: - /* Input is MACID */ - val32 = *(u32 *)val; - if (val32 > 31) - break; - - val8 = (u8)val32; /* macid is between 0~31 */ - - val32 = rtw_read32(padapter, REG_MACID_SLEEP); - if (!(val32 & BIT(val8))) - break; - val32 &= ~BIT(val8); - rtw_write32(padapter, REG_MACID_SLEEP, val32); - break; - - default: - SetHwReg(padapter, variable, val); - break; - } -} - -void GetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 val8; - u16 val16; - - switch (variable) { - case HW_VAR_TXPAUSE: - *val = rtw_read8(padapter, REG_TXPAUSE); - break; - - case HW_VAR_BCN_VALID: - { - /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2 */ - val8 = rtw_read8(padapter, REG_TDECTRL+2); - *val = (BIT(0) & val8) ? true : false; - } - break; - - case HW_VAR_FWLPS_RF_ON: - { - /* When we halt NIC, we should check if FW LPS is leave. */ - u32 valRCR; - - if ( - padapter->bSurpriseRemoved || - (adapter_to_pwrctl(padapter)->rf_pwrstate == rf_off) - ) { - /* If it is in HW/SW Radio OFF or IPS state, we do not check Fw LPS Leave, */ - /* because Fw is unload. */ - *val = true; - } else { - valRCR = rtw_read32(padapter, REG_RCR); - valRCR &= 0x00070000; - if (valRCR) - *val = false; - else - *val = true; - } - } - break; - - case HW_VAR_EFUSE_USAGE: - *val = pHalData->EfuseUsedPercentage; - break; - - case HW_VAR_EFUSE_BYTES: - *((u16 *)val) = pHalData->EfuseUsedBytes; - break; - - case HW_VAR_EFUSE_BT_USAGE: -#ifdef HAL_EFUSE_MEMORY - *val = pHalData->EfuseHal.BTEfuseUsedPercentage; -#endif - break; - - case HW_VAR_EFUSE_BT_BYTES: -#ifdef HAL_EFUSE_MEMORY - *((u16 *)val) = pHalData->EfuseHal.BTEfuseUsedBytes; -#else - *((u16 *)val) = BTEfuseUsedBytes; -#endif - break; - - case HW_VAR_APFM_ON_MAC: - *val = pHalData->bMacPwrCtrlOn; - break; - case HW_VAR_CHK_HI_QUEUE_EMPTY: - val16 = rtw_read16(padapter, REG_TXPKT_EMPTY); - *val = (val16 & BIT(10)) ? true : false; - break; - default: - GetHwReg(padapter, variable, val); - break; - } -} - -/* Description: - * Query setting of specified variable. - */ -u8 GetHalDefVar8723B(struct adapter *padapter, enum hal_def_variable variable, void *pval) -{ - u8 bResult = _SUCCESS; - - switch (variable) { - case HAL_DEF_MAX_RECVBUF_SZ: - *((u32 *)pval) = MAX_RECVBUF_SZ; - break; - - case HAL_DEF_RX_PACKET_OFFSET: - *((u32 *)pval) = RXDESC_SIZE + DRVINFO_SZ*8; - break; - - case HW_VAR_MAX_RX_AMPDU_FACTOR: - /* Stanley@BB.SD3 suggests 16K can get stable performance */ - /* The experiment was done on SDIO interface */ - /* coding by Lucas@20130730 */ - *(u32 *)pval = IEEE80211_HT_MAX_AMPDU_16K; - break; - case HAL_DEF_TX_LDPC: - case HAL_DEF_RX_LDPC: - *((u8 *)pval) = false; - break; - case HAL_DEF_TX_STBC: - *((u8 *)pval) = 0; - break; - case HAL_DEF_RX_STBC: - *((u8 *)pval) = 1; - break; - case HAL_DEF_EXPLICIT_BEAMFORMER: - case HAL_DEF_EXPLICIT_BEAMFORMEE: - *((u8 *)pval) = false; - break; - - case HW_DEF_RA_INFO_DUMP: - { - u8 mac_id = *(u8 *)pval; - u32 cmd = 0x40000100 | mac_id; - - rtw_write32(padapter, REG_HMEBOX_DBG_2_8723B, cmd); - msleep(10); - rtw_read32(padapter, 0x2F0); // info 1 - - cmd = 0x40000400 | mac_id; - rtw_write32(padapter, REG_HMEBOX_DBG_2_8723B, cmd); - msleep(10); - rtw_read32(padapter, 0x2F0); // info 1 - rtw_read32(padapter, 0x2F4); // info 2 - rtw_read32(padapter, 0x2F8); // rate mask 1 - rtw_read32(padapter, 0x2FC); // rate mask 2 - } - break; - - case HAL_DEF_TX_PAGE_BOUNDARY: - if (!padapter->registrypriv.wifi_spec) { - *(u8 *)pval = TX_PAGE_BOUNDARY_8723B; - } else { - *(u8 *)pval = WMM_NORMAL_TX_PAGE_BOUNDARY_8723B; - } - break; - - case HAL_DEF_MACID_SLEEP: - *(u8 *)pval = true; /* support macid sleep */ - break; - - default: - bResult = GetHalDefVar(padapter, variable, pval); - break; - } - - return bResult; -} diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c b/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c deleted file mode 100644 index 737e2a818c18..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c +++ /dev/null @@ -1,759 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include - -/** - * phy_CalculateBitShift - Get shifted position of the BitMask. - * @BitMask: Bitmask. - * - * Return: Return the shift bit position of the mask - */ -static u32 phy_CalculateBitShift(u32 BitMask) -{ - u32 i; - - for (i = 0; i <= 31; i++) { - if (((BitMask >> i) & 0x1) == 1) - break; - } - return i; -} - -/** - * PHY_QueryBBReg_8723B - Read "specific bits" from BB register. - * @Adapter: - * @RegAddr: The target address to be readback - * @BitMask: The target bit position in the target address - * to be readback - * - * Return: The readback register value - * - * .. Note:: This function is equal to "GetRegSetting" in PHY programming - * guide - */ -u32 PHY_QueryBBReg_8723B(struct adapter *Adapter, u32 RegAddr, u32 BitMask) -{ - u32 OriginalValue, BitShift; - - OriginalValue = rtw_read32(Adapter, RegAddr); - BitShift = phy_CalculateBitShift(BitMask); - - return (OriginalValue & BitMask) >> BitShift; -} - -/** - * PHY_SetBBReg_8723B - Write "Specific bits" to BB register (page 8~). - * @Adapter: - * @RegAddr: The target address to be modified - * @BitMask: The target bit position in the target address - * to be modified - * @Data: The new register value in the target bit position - * of the target address - * - * .. Note:: This function is equal to "PutRegSetting" in PHY programming - * guide - */ - -void PHY_SetBBReg_8723B( - struct adapter *Adapter, - u32 RegAddr, - u32 BitMask, - u32 Data -) -{ - /* u16 BBWaitCounter = 0; */ - u32 OriginalValue, BitShift; - - if (BitMask != bMaskDWord) { /* if not "double word" write */ - OriginalValue = rtw_read32(Adapter, RegAddr); - BitShift = phy_CalculateBitShift(BitMask); - Data = ((OriginalValue & (~BitMask)) | ((Data << BitShift) & BitMask)); - } - - rtw_write32(Adapter, RegAddr, Data); -} - -/* */ -/* 2. RF register R/W API */ -/* */ - -static u32 phy_RFSerialRead_8723B( - struct adapter *Adapter, enum rf_path eRFPath, u32 Offset -) -{ - u32 retValue = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct bb_register_def *pPhyReg = &pHalData->PHYRegDef[eRFPath]; - u32 NewOffset; - u32 tmplong2; - u8 RfPiEnable = 0; - u32 MaskforPhySet = 0; - int i = 0; - - /* */ - /* Make sure RF register offset is correct */ - /* */ - Offset &= 0xff; - - NewOffset = Offset; - - if (eRFPath == RF_PATH_A) { - tmplong2 = PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter2 | MaskforPhySet, bMaskDWord); - tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset << 23) | bLSSIReadEdge; /* T65 RF */ - PHY_SetBBReg(Adapter, rFPGA0_XA_HSSIParameter2 | MaskforPhySet, bMaskDWord, tmplong2 & (~bLSSIReadEdge)); - } else { - tmplong2 = PHY_QueryBBReg(Adapter, rFPGA0_XB_HSSIParameter2 | MaskforPhySet, bMaskDWord); - tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset << 23) | bLSSIReadEdge; /* T65 RF */ - PHY_SetBBReg(Adapter, rFPGA0_XB_HSSIParameter2 | MaskforPhySet, bMaskDWord, tmplong2 & (~bLSSIReadEdge)); - } - - tmplong2 = PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter2 | MaskforPhySet, bMaskDWord); - PHY_SetBBReg(Adapter, rFPGA0_XA_HSSIParameter2 | MaskforPhySet, bMaskDWord, tmplong2 & (~bLSSIReadEdge)); - PHY_SetBBReg(Adapter, rFPGA0_XA_HSSIParameter2 | MaskforPhySet, bMaskDWord, tmplong2 | bLSSIReadEdge); - - udelay(10); - - for (i = 0; i < 2; i++) - udelay(MAX_STALL_TIME); - udelay(10); - - if (eRFPath == RF_PATH_A) - RfPiEnable = (u8)PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter1 | MaskforPhySet, BIT(8)); - else if (eRFPath == RF_PATH_B) - RfPiEnable = (u8)PHY_QueryBBReg(Adapter, rFPGA0_XB_HSSIParameter1 | MaskforPhySet, BIT(8)); - - if (RfPiEnable) { - /* Read from BBreg8b8, 12 bits for 8190, 20bits for T65 RF */ - retValue = PHY_QueryBBReg(Adapter, pPhyReg->rfLSSIReadBackPi | MaskforPhySet, bLSSIReadBackData); - } else { - /* Read from BBreg8a0, 12 bits for 8190, 20 bits for T65 RF */ - retValue = PHY_QueryBBReg(Adapter, pPhyReg->rfLSSIReadBack | MaskforPhySet, bLSSIReadBackData); - } - return retValue; -} - -/** - * phy_RFSerialWrite_8723B - Write data to RF register (page 8~). - * @Adapter: - * @eRFPath: Radio path of A/B/C/D - * @Offset: The target address to be read - * @Data: The new register Data in the target bit position - * of the target to be read - * - * .. Note:: There are three types of serial operations: - * 1. Software serial write - * 2. Hardware LSSI-Low Speed Serial Interface - * 3. Hardware HSSI-High speed - * serial write. Driver need to implement (1) and (2). - * This function is equal to the combination of RF_ReadReg() and RFLSSIRead() - * - * .. Note:: For RF8256 only - * The total count of RTL8256(Zebra4) register is around 36 bit it only employs - * 4-bit RF address. RTL8256 uses "register mode control bit" (Reg00[12], Reg00[10]) - * to access register address bigger than 0xf. See "Appendix-4 in PHY Configuration - * programming guide" for more details. - * Thus, we define a sub-finction for RTL8526 register address conversion - * =========================================================== - * Register Mode RegCTL[1] RegCTL[0] Note - * (Reg00[12]) (Reg00[10]) - * =========================================================== - * Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf) - * ------------------------------------------------------------------ - * Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf) - * ------------------------------------------------------------------ - * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf) - * ------------------------------------------------------------------ - * - *2008/09/02 MH Add 92S RF definition - * - * - * - */ -static void phy_RFSerialWrite_8723B( - struct adapter *Adapter, - enum rf_path eRFPath, - u32 Offset, - u32 Data -) -{ - u32 DataAndAddr = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct bb_register_def *pPhyReg = &pHalData->PHYRegDef[eRFPath]; - u32 NewOffset; - - Offset &= 0xff; - - /* */ - /* Switch page for 8256 RF IC */ - /* */ - NewOffset = Offset; - - /* */ - /* Put write addr in [5:0] and write data in [31:16] */ - /* */ - DataAndAddr = ((NewOffset << 20) | (Data & 0x000fffff)) & 0x0fffffff; /* T65 RF */ - /* */ - /* Write Operation */ - /* */ - PHY_SetBBReg(Adapter, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr); -} - -/** - * PHY_QueryRFReg_8723B - Query "Specific bits" to RF register (page 8~). - * @Adapter: - * @eRFPath: Radio path of A/B/C/D - * @RegAddr: The target address to be read - * @BitMask: The target bit position in the target address - * to be read - * - * Return: Readback value - * - * .. Note:: This function is equal to "GetRFRegSetting" in PHY - * programming guide - */ -u32 PHY_QueryRFReg_8723B( - struct adapter *Adapter, - u8 eRFPath, - u32 RegAddr, - u32 BitMask -) -{ - u32 Original_Value, BitShift; - - Original_Value = phy_RFSerialRead_8723B(Adapter, eRFPath, RegAddr); - BitShift = phy_CalculateBitShift(BitMask); - - return (Original_Value & BitMask) >> BitShift; -} - -/** - * PHY_SetRFReg_8723B - Write "Specific bits" to RF register (page 8~). - * @Adapter: - * @eRFPath: Radio path of A/B/C/D - * @RegAddr: The target address to be modified - * @BitMask: The target bit position in the target address - * to be modified - * @Data: The new register Data in the target bit position - * of the target address - * - * .. Note:: This function is equal to "PutRFRegSetting" in PHY - * programming guide. - */ -void PHY_SetRFReg_8723B( - struct adapter *Adapter, - u8 eRFPath, - u32 RegAddr, - u32 BitMask, - u32 Data -) -{ - u32 Original_Value, BitShift; - - /* RF data is 12 bits only */ - if (BitMask != bRFRegOffsetMask) { - Original_Value = phy_RFSerialRead_8723B(Adapter, eRFPath, RegAddr); - BitShift = phy_CalculateBitShift(BitMask); - Data = ((Original_Value & (~BitMask)) | (Data << BitShift)); - } - - phy_RFSerialWrite_8723B(Adapter, eRFPath, RegAddr, Data); -} - -/* */ -/* 3. Initial MAC/BB/RF config by reading MAC/BB/RF txt. */ -/* */ - -/*----------------------------------------------------------------------------- - * PHY_MACConfig8192C - Config MAC by header file or parameter file. - * - * Revised History: - * When Who Remark - * 08/12/2008 MHC Create Version 0. - * - *--------------------------------------------------------------------------- - */ -s32 PHY_MACConfig8723B(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - ODM_ReadAndConfig_MP_8723B_MAC_REG(&pHalData->odmpriv); - return _SUCCESS; -} - -/** - * phy_InitBBRFRegisterDefinition - Initialize Register definition offset for - * Radio Path A/B/C/D - * @Adapter: - * - * .. Note:: The initialization value is constant and it should never be changes - */ -static void phy_InitBBRFRegisterDefinition(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - /* RF Interface Sowrtware Control */ - pHalData->PHYRegDef[RF_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; /* 16 LSBs if read 32-bit from 0x870 */ - pHalData->PHYRegDef[RF_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */ - - /* RF Interface Output (and Enable) */ - pHalData->PHYRegDef[RF_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; /* 16 LSBs if read 32-bit from 0x860 */ - pHalData->PHYRegDef[RF_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; /* 16 LSBs if read 32-bit from 0x864 */ - - /* RF Interface (Output and) Enable */ - pHalData->PHYRegDef[RF_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */ - pHalData->PHYRegDef[RF_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */ - - pHalData->PHYRegDef[RF_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; /* LSSI Parameter */ - pHalData->PHYRegDef[RF_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter; - - pHalData->PHYRegDef[RF_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; /* wire control parameter2 */ - pHalData->PHYRegDef[RF_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; /* wire control parameter2 */ - - /* Transceiver Readback LSSI/HSPI mode */ - pHalData->PHYRegDef[RF_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack; - pHalData->PHYRegDef[RF_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack; - pHalData->PHYRegDef[RF_PATH_A].rfLSSIReadBackPi = TransceiverA_HSPI_Readback; - pHalData->PHYRegDef[RF_PATH_B].rfLSSIReadBackPi = TransceiverB_HSPI_Readback; -} - -static int phy_BB8723b_Config_ParaFile(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - /* Read Tx Power Limit File */ - PHY_InitTxPowerLimit(Adapter); - if (Adapter->registrypriv.reg_enable_tx_power_limit == 1 || - (Adapter->registrypriv.reg_enable_tx_power_limit == 2 && - pHalData->EEPROMRegulatory == 1)) - ODM_ConfigRFWithHeaderFile(&pHalData->odmpriv, CONFIG_RF_TXPWR_LMT, 0); - - /* */ - /* 1. Read PHY_REG.TXT BB INIT!! */ - /* */ - ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG); - - /* If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt */ - PHY_InitTxPowerByRate(Adapter); - - if (Adapter->registrypriv.reg_enable_tx_power_by_rate == 1 || - (Adapter->registrypriv.reg_enable_tx_power_by_rate == 2 && - pHalData->EEPROMRegulatory != 2)) { - ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG_PG); - - if (pHalData->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE) - PHY_TxPowerByRateConfiguration(Adapter); - - if (Adapter->registrypriv.reg_enable_tx_power_limit == 1 || - (Adapter->registrypriv.reg_enable_tx_power_limit == 2 && - pHalData->EEPROMRegulatory == 1)) - PHY_ConvertTxPowerLimitToPowerIndex(Adapter); - } - - /* */ - /* 2. Read BB AGC table Initialization */ - /* */ - ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_AGC_TAB); - - return _SUCCESS; -} - -int PHY_BBConfig8723B(struct adapter *Adapter) -{ - int rtStatus = _SUCCESS; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u32 RegVal; - u8 CrystalCap; - - phy_InitBBRFRegisterDefinition(Adapter); - - /* Enable BB and RF */ - RegVal = rtw_read16(Adapter, REG_SYS_FUNC_EN); - rtw_write16(Adapter, REG_SYS_FUNC_EN, (u16)(RegVal | BIT(13) | BIT(0) | BIT(1))); - - rtw_write32(Adapter, rS0S1_PathSwitch, 0x280); /* Others use Antenna S1 */ - - rtw_write8(Adapter, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB); - - msleep(1); - - PHY_SetRFReg(Adapter, RF_PATH_A, 0x1, 0xfffff, 0x780); - - rtw_write8(Adapter, REG_SYS_FUNC_EN, - FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE | FEN_BB_GLB_RSTn | FEN_BBRSTB); - - rtw_write8(Adapter, REG_AFE_XTAL_CTRL + 1, 0x80); - - /* */ - /* Config BB and AGC */ - /* */ - rtStatus = phy_BB8723b_Config_ParaFile(Adapter); - - /* 0x2C[23:18] = 0x2C[17:12] = CrystalCap */ - CrystalCap = pHalData->CrystalCap & 0x3F; - PHY_SetBBReg(Adapter, REG_MAC_PHY_CTRL, 0xFFF000, (CrystalCap | (CrystalCap << 6))); - - return rtStatus; -} - -static void phy_LCK_8723B(struct adapter *Adapter) -{ - PHY_SetRFReg(Adapter, RF_PATH_A, 0xB0, bRFRegOffsetMask, 0xDFBE0); - PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, 0x8C01); - mdelay(200); - PHY_SetRFReg(Adapter, RF_PATH_A, 0xB0, bRFRegOffsetMask, 0xDFFE0); -} - -int PHY_RFConfig8723B(struct adapter *Adapter) -{ - int rtStatus = _SUCCESS; - - /* */ - /* RF config */ - /* */ - rtStatus = PHY_RF6052_Config8723B(Adapter); - - phy_LCK_8723B(Adapter); - - return rtStatus; -} - -/************************************************************************************************************** - * Description: - * The low-level interface to set TxAGC , called by both MP and Normal Driver. - * - * <20120830, Kordan> - **************************************************************************************************************/ - -void PHY_SetTxPowerIndex( - struct adapter *Adapter, - u32 PowerIndex, - u8 RFPath, - u8 Rate -) -{ - if (RFPath == RF_PATH_A || RFPath == RF_PATH_B) { - switch (Rate) { - case MGN_1M: - PHY_SetBBReg(Adapter, rTxAGC_A_CCK1_Mcs32, bMaskByte1, PowerIndex); - break; - case MGN_2M: - PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte1, PowerIndex); - break; - case MGN_5_5M: - PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte2, PowerIndex); - break; - case MGN_11M: - PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte3, PowerIndex); - break; - - case MGN_6M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate18_06, bMaskByte0, PowerIndex); - break; - case MGN_9M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate18_06, bMaskByte1, PowerIndex); - break; - case MGN_12M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate18_06, bMaskByte2, PowerIndex); - break; - case MGN_18M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate18_06, bMaskByte3, PowerIndex); - break; - - case MGN_24M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate54_24, bMaskByte0, PowerIndex); - break; - case MGN_36M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate54_24, bMaskByte1, PowerIndex); - break; - case MGN_48M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate54_24, bMaskByte2, PowerIndex); - break; - case MGN_54M: - PHY_SetBBReg(Adapter, rTxAGC_A_Rate54_24, bMaskByte3, PowerIndex); - break; - - case MGN_MCS0: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs03_Mcs00, bMaskByte0, PowerIndex); - break; - case MGN_MCS1: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs03_Mcs00, bMaskByte1, PowerIndex); - break; - case MGN_MCS2: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs03_Mcs00, bMaskByte2, PowerIndex); - break; - case MGN_MCS3: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs03_Mcs00, bMaskByte3, PowerIndex); - break; - - case MGN_MCS4: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs07_Mcs04, bMaskByte0, PowerIndex); - break; - case MGN_MCS5: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs07_Mcs04, bMaskByte1, PowerIndex); - break; - case MGN_MCS6: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs07_Mcs04, bMaskByte2, PowerIndex); - break; - case MGN_MCS7: - PHY_SetBBReg(Adapter, rTxAGC_A_Mcs07_Mcs04, bMaskByte3, PowerIndex); - break; - - default: - break; - } - } -} - -u8 PHY_GetTxPowerIndex( - struct adapter *padapter, - u8 RFPath, - u8 Rate, - enum channel_width BandWidth, - u8 Channel -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - s8 txPower = 0, powerDiffByRate = 0, limit = 0; - - txPower = (s8)PHY_GetTxPowerIndexBase(padapter, RFPath, Rate, BandWidth, Channel); - powerDiffByRate = PHY_GetTxPowerByRate(padapter, RF_PATH_A, Rate); - - limit = phy_get_tx_pwr_lmt( - padapter, - padapter->registrypriv.reg_pwr_tbl_sel, - pHalData->CurrentChannelBW, - RFPath, - Rate, - pHalData->CurrentChannel - ); - - powerDiffByRate = powerDiffByRate > limit ? limit : powerDiffByRate; - txPower += powerDiffByRate; - - txPower += PHY_GetTxPowerTrackingOffset(padapter, RFPath, Rate); - - if (txPower > MAX_POWER_INDEX) - txPower = MAX_POWER_INDEX; - - return (u8)txPower; -} - -void PHY_SetTxPowerLevel8723B(struct adapter *Adapter, u8 Channel) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; - struct fat_t *pDM_FatTable = &pDM_Odm->DM_FatTable; - u8 RFPath = RF_PATH_A; - - if (pHalData->AntDivCfg) {/* antenna diversity Enable */ - RFPath = ((pDM_FatTable->RxIdleAnt == MAIN_ANT) ? RF_PATH_A : RF_PATH_B); - } else { /* antenna diversity disable */ - RFPath = pHalData->ant_path; - } - - PHY_SetTxPowerLevelByPath(Adapter, Channel, RFPath); -} - -static void phy_SetRegBW_8723B( - struct adapter *Adapter, enum channel_width CurrentBW -) -{ - u16 RegRfMod_BW, u2tmp = 0; - - RegRfMod_BW = rtw_read16(Adapter, REG_TRXPTCL_CTL_8723B); - - switch (CurrentBW) { - case CHANNEL_WIDTH_20: - rtw_write16(Adapter, REG_TRXPTCL_CTL_8723B, (RegRfMod_BW & 0xFE7F)); /* BIT 7 = 0, BIT 8 = 0 */ - break; - - case CHANNEL_WIDTH_40: - u2tmp = RegRfMod_BW | BIT(7); - rtw_write16(Adapter, REG_TRXPTCL_CTL_8723B, (u2tmp & 0xFEFF)); /* BIT 7 = 1, BIT 8 = 0 */ - break; - - default: - break; - } -} - -static u8 phy_GetSecondaryChnl_8723B(struct adapter *Adapter) -{ - u8 SCSettingOf40 = 0, SCSettingOf20 = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40) { - if (pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER) - SCSettingOf20 = HT_DATA_SC_20_UPPER_OF_40MHZ; - else if (pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) - SCSettingOf20 = HT_DATA_SC_20_LOWER_OF_40MHZ; - } - - return (SCSettingOf40 << 4) | SCSettingOf20; -} - -static void phy_PostSetBwMode8723B(struct adapter *Adapter) -{ - u8 SubChnlNum = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - /* 3 Set Reg668 Reg440 BW */ - phy_SetRegBW_8723B(Adapter, pHalData->CurrentChannelBW); - - /* 3 Set Reg483 */ - SubChnlNum = phy_GetSecondaryChnl_8723B(Adapter); - rtw_write8(Adapter, REG_DATA_SC_8723B, SubChnlNum); - - /* 3 */ - /* 3<2>Set PHY related register */ - /* 3 */ - switch (pHalData->CurrentChannelBW) { - /* 20 MHz channel*/ - case CHANNEL_WIDTH_20: - PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bRFMOD, 0x0); - - PHY_SetBBReg(Adapter, rFPGA1_RFMOD, bRFMOD, 0x0); - - PHY_SetBBReg(Adapter, rOFDM0_TxPseudoNoiseWgt, (BIT(31) | BIT(30)), 0x0); - break; - - /* 40 MHz channel*/ - case CHANNEL_WIDTH_40: - PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bRFMOD, 0x1); - - PHY_SetBBReg(Adapter, rFPGA1_RFMOD, bRFMOD, 0x1); - - /* Set Control channel to upper or lower. These settings are required only for 40MHz */ - PHY_SetBBReg(Adapter, rCCK0_System, bCCKSideBand, (pHalData->nCur40MhzPrimeSC >> 1)); - - PHY_SetBBReg(Adapter, rOFDM1_LSTF, 0xC00, pHalData->nCur40MhzPrimeSC); - - PHY_SetBBReg(Adapter, 0x818, (BIT(26) | BIT(27)), (pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1); - break; - default: - break; - } - - /* 3<3>Set RF related register */ - PHY_RF6052SetBandwidth8723B(Adapter, pHalData->CurrentChannelBW); -} - -static void phy_SwChnl8723B(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - u8 channelToSW = pHalData->CurrentChannel; - - pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff00) | channelToSW); - PHY_SetRFReg(padapter, RF_PATH_A, RF_CHNLBW, 0x3FF, pHalData->RfRegChnlVal[0]); - PHY_SetRFReg(padapter, RF_PATH_B, RF_CHNLBW, 0x3FF, pHalData->RfRegChnlVal[0]); -} - -static void phy_SwChnlAndSetBwMode8723B(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - if (Adapter->driver_stopped || Adapter->bSurpriseRemoved) - return; - - if (pHalData->bSwChnl) { - phy_SwChnl8723B(Adapter); - pHalData->bSwChnl = false; - } - - if (pHalData->bSetChnlBW) { - phy_PostSetBwMode8723B(Adapter); - pHalData->bSetChnlBW = false; - } - - PHY_SetTxPowerLevel8723B(Adapter, pHalData->CurrentChannel); -} - -static void PHY_HandleSwChnlAndSetBW8723B( - struct adapter *Adapter, - bool bSwitchChannel, - bool bSetBandWidth, - u8 ChannelNum, - enum channel_width ChnlWidth, - enum extchnl_offset ExtChnlOffsetOf40MHz, - enum extchnl_offset ExtChnlOffsetOf80MHz, - u8 CenterFrequencyIndex1 -) -{ - /* static bool bInitialzed = false; */ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - u8 tmpChannel = pHalData->CurrentChannel; - enum channel_width tmpBW = pHalData->CurrentChannelBW; - u8 tmpnCur40MhzPrimeSC = pHalData->nCur40MhzPrimeSC; - u8 tmpnCur80MhzPrimeSC = pHalData->nCur80MhzPrimeSC; - u8 tmpCenterFrequencyIndex1 = pHalData->CurrentCenterFrequencyIndex1; - - /* check is swchnl or setbw */ - if (!bSwitchChannel && !bSetBandWidth) - return; - - /* skip change for channel or bandwidth is the same */ - if (bSwitchChannel) { - { - if (HAL_IsLegalChannel(Adapter, ChannelNum)) - pHalData->bSwChnl = true; - } - } - - if (bSetBandWidth) - pHalData->bSetChnlBW = true; - - if (!pHalData->bSetChnlBW && !pHalData->bSwChnl) - return; - - if (pHalData->bSwChnl) { - pHalData->CurrentChannel = ChannelNum; - pHalData->CurrentCenterFrequencyIndex1 = ChannelNum; - } - - if (pHalData->bSetChnlBW) { - pHalData->CurrentChannelBW = ChnlWidth; - pHalData->nCur40MhzPrimeSC = ExtChnlOffsetOf40MHz; - pHalData->nCur80MhzPrimeSC = ExtChnlOffsetOf80MHz; - pHalData->CurrentCenterFrequencyIndex1 = CenterFrequencyIndex1; - } - - /* Switch workitem or set timer to do switch channel or setbandwidth operation */ - if ((!Adapter->driver_stopped) && (!Adapter->bSurpriseRemoved)) { - phy_SwChnlAndSetBwMode8723B(Adapter); - } else { - if (pHalData->bSwChnl) { - pHalData->CurrentChannel = tmpChannel; - pHalData->CurrentCenterFrequencyIndex1 = tmpChannel; - } - - if (pHalData->bSetChnlBW) { - pHalData->CurrentChannelBW = tmpBW; - pHalData->nCur40MhzPrimeSC = tmpnCur40MhzPrimeSC; - pHalData->nCur80MhzPrimeSC = tmpnCur80MhzPrimeSC; - pHalData->CurrentCenterFrequencyIndex1 = tmpCenterFrequencyIndex1; - } - } -} - -/* Call after initialization */ -void PHY_SwChnl8723B(struct adapter *Adapter, u8 channel) -{ - PHY_HandleSwChnlAndSetBW8723B(Adapter, true, false, channel, 0, 0, 0, channel); -} - -void PHY_SetSwChnlBWMode8723B( - struct adapter *Adapter, - u8 channel, - enum channel_width Bandwidth, - u8 Offset40, - u8 Offset80 -) -{ - PHY_HandleSwChnlAndSetBW8723B(Adapter, true, true, channel, Bandwidth, Offset40, Offset80, channel); -} diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c b/drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c deleted file mode 100644 index fac1270853de..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c +++ /dev/null @@ -1,135 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/****************************************************************************** - * - * - * Module: rtl8192c_rf6052.c (Source C File) - * - * Note: Provide RF 6052 series relative API. - * - * Function: - * - * Export: - * - * Abbrev: - * - * History: - * Data Who Remark - * - * 09/25/2008 MHC Create initial version. - * 11/05/2008 MHC Add API for tw power setting. - * - * - ******************************************************************************/ - -#include - -/*---------------------------Define Local Constant---------------------------*/ -/*---------------------------Define Local Constant---------------------------*/ - -/*------------------------Define global variable-----------------------------*/ -/*------------------------Define global variable-----------------------------*/ - -/*------------------------Define local variable------------------------------*/ -/* 2008/11/20 MH For Debug only, RF */ -/*------------------------Define local variable------------------------------*/ - -/*----------------------------------------------------------------------------- - * Function: PHY_RF6052SetBandwidth() - * - * Overview: This function is called by SetBWModeCallback8190Pci() only - * - * Input: struct adapter * Adapter - * WIRELESS_BANDWIDTH_E Bandwidth 20M or 40M - * - * Output: NONE - * - * Return: NONE - * - * Note: For RF type 0222D - *--------------------------------------------------------------------------- - */ -void PHY_RF6052SetBandwidth8723B( - struct adapter *Adapter, enum channel_width Bandwidth -) /* 20M or 40M */ -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - switch (Bandwidth) { - case CHANNEL_WIDTH_20: - pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT(10) | BIT(11)); - PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); - PHY_SetRFReg(Adapter, RF_PATH_B, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); - break; - - case CHANNEL_WIDTH_40: - pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT(10)); - PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); - PHY_SetRFReg(Adapter, RF_PATH_B, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); - break; - - default: - break; - } - -} - -static int phy_RF6052_Config_ParaFile(struct adapter *Adapter) -{ - u32 u4RegValue = 0; - struct bb_register_def *pPhyReg; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - /* 3----------------------------------------------------------------- */ - /* 3 <2> Initialize RF */ - /* 3----------------------------------------------------------------- */ - - pPhyReg = &pHalData->PHYRegDef[RF_PATH_A]; - - /*----Store original RFENV control type----*/ - u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV); - - /*----Set RF_ENV enable----*/ - PHY_SetBBReg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1); - udelay(1);/* PlatformStallExecution(1); */ - - /*----Set RF_ENV output high----*/ - PHY_SetBBReg(Adapter, pPhyReg->rfintfo, bRFSI_RFENV, 0x1); - udelay(1);/* PlatformStallExecution(1); */ - - /* Set bit number of Address and Data for RF register */ - PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 1 to 4 bits for 8255 */ - udelay(1);/* PlatformStallExecution(1); */ - - PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for 8255 */ - udelay(1);/* PlatformStallExecution(1); */ - - /*----Initialize RF fom connfiguration file----*/ - ODM_ConfigRFWithHeaderFile(&pHalData->odmpriv, CONFIG_RF_RADIO, RF_PATH_A); - - /*----Restore RFENV control type----*/ - PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue); - - /* 3 ----------------------------------------------------------------- */ - /* 3 Configuration of Tx Power Tracking */ - /* 3 ----------------------------------------------------------------- */ - - ODM_ConfigRFWithTxPwrTrackHeaderFile(&pHalData->odmpriv); - - return _SUCCESS; -} - -int PHY_RF6052_Config8723B(struct adapter *Adapter) -{ - /* */ - /* Config BB and RF */ - /* */ - return phy_RF6052_Config_ParaFile(Adapter); - -} - -/* End of HalRf6052.c */ diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c b/drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c deleted file mode 100644 index ac1249676794..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include - -static void process_rssi(struct adapter *padapter, union recv_frame *prframe) -{ - struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; - struct signal_stat *signal_stat = &padapter->recvpriv.signal_strength_data; - - /* if (pRfd->Status.bPacketToSelf || pRfd->Status.bPacketBeacon) */ - { - if (signal_stat->update_req) { - signal_stat->total_num = 0; - signal_stat->total_val = 0; - signal_stat->update_req = 0; - } - - signal_stat->total_num++; - signal_stat->total_val += pattrib->phy_info.SignalStrength; - signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num; - } - -} /* Process_UI_RSSI_8192C */ - -static void process_link_qual(struct adapter *padapter, union recv_frame *prframe) -{ - struct rx_pkt_attrib *pattrib; - struct signal_stat *signal_stat; - - if (!prframe || !padapter) - return; - - pattrib = &prframe->u.hdr.attrib; - signal_stat = &padapter->recvpriv.signal_qual_data; - - if (signal_stat->update_req) { - signal_stat->total_num = 0; - signal_stat->total_val = 0; - signal_stat->update_req = 0; - } - - signal_stat->total_num++; - signal_stat->total_val += pattrib->phy_info.SignalQuality; - signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num; -} /* Process_UiLinkQuality8192S */ - -void rtl8723b_process_phy_info(struct adapter *padapter, void *prframe) -{ - union recv_frame *precvframe = prframe; - /* */ - /* Check RSSI */ - /* */ - process_rssi(padapter, precvframe); - /* */ - /* Check PWDB. */ - /* */ - /* process_PWDB(padapter, precvframe); */ - - /* UpdateRxSignalStatistics8192C(Adapter, pRfd); */ - /* */ - /* Check EVM */ - /* */ - process_link_qual(padapter, precvframe); -} diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c deleted file mode 100644 index e943c304950e..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c +++ /dev/null @@ -1,477 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include - -static void initrecvbuf(struct recv_buf *precvbuf, struct adapter *padapter) -{ - INIT_LIST_HEAD(&precvbuf->list); - spin_lock_init(&precvbuf->recvbuf_lock); - - precvbuf->adapter = padapter; -} - -static void update_recvframe_attrib(struct adapter *padapter, - union recv_frame *precvframe, - struct recv_stat *prxstat) -{ - struct rx_pkt_attrib *pattrib; - struct recv_stat report; - struct rxreport_8723b *prxreport = (struct rxreport_8723b *)&report; - - report.rxdw0 = prxstat->rxdw0; - report.rxdw1 = prxstat->rxdw1; - report.rxdw2 = prxstat->rxdw2; - report.rxdw3 = prxstat->rxdw3; - report.rxdw4 = prxstat->rxdw4; - report.rxdw5 = prxstat->rxdw5; - - pattrib = &precvframe->u.hdr.attrib; - memset(pattrib, 0, sizeof(struct rx_pkt_attrib)); - - /* update rx report to recv_frame attribute */ - pattrib->pkt_rpt_type = prxreport->c2h_ind ? C2H_PACKET : NORMAL_RX; - - if (pattrib->pkt_rpt_type == NORMAL_RX) { - /* Normal rx packet */ - /* update rx report to recv_frame attribute */ - pattrib->pkt_len = (u16)prxreport->pktlen; - pattrib->drvinfo_sz = (u8)(prxreport->drvinfosize << 3); - pattrib->physt = (u8)prxreport->physt; - - pattrib->crc_err = (u8)prxreport->crc32; - pattrib->icv_err = (u8)prxreport->icverr; - - pattrib->bdecrypted = (u8)(prxreport->swdec ? 0 : 1); - pattrib->encrypt = (u8)prxreport->security; - - pattrib->qos = (u8)prxreport->qos; - pattrib->priority = (u8)prxreport->tid; - - pattrib->amsdu = (u8)prxreport->amsdu; - - pattrib->seq_num = (u16)prxreport->seq; - pattrib->frag_num = (u8)prxreport->frag; - pattrib->mfrag = (u8)prxreport->mf; - pattrib->mdata = (u8)prxreport->md; - - pattrib->data_rate = (u8)prxreport->rx_rate; - } else { - pattrib->pkt_len = (u16)prxreport->pktlen; - } -} - -/* - * Notice: - *Before calling this function, - *precvframe->u.hdr.rx_data should be ready! - */ -static void update_recvframe_phyinfo(union recv_frame *precvframe, - struct phy_stat *pphy_status) -{ - struct adapter *padapter = precvframe->u.hdr.adapter; - struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib; - struct hal_com_data *p_hal_data = GET_HAL_DATA(padapter); - struct odm_phy_info *p_phy_info = - (struct odm_phy_info *)(&pattrib->phy_info); - - u8 *wlanhdr = precvframe->u.hdr.rx_data; - u8 *my_bssid; - u8 *rx_bssid; - u8 *rx_ra; - u8 *my_hwaddr; - u8 *sa = NULL; - - struct odm_packet_info pkt_info = { - .data_rate = 0x00, - .station_id = 0x00, - .bssid_match = false, - .to_self = false, - .is_beacon = false, - }; - - /* unsigned long irqL; */ - struct sta_priv *pstapriv; - struct sta_info *psta; - - my_bssid = get_bssid(&padapter->mlmepriv); - rx_bssid = get_hdr_bssid(wlanhdr); - pkt_info.bssid_match = ((!IsFrameTypeCtrl(wlanhdr)) && - !pattrib->icv_err && !pattrib->crc_err && - ether_addr_equal(rx_bssid, my_bssid)); - - rx_ra = rtl8723bs_get_ra(wlanhdr); - my_hwaddr = myid(&padapter->eeprompriv); - pkt_info.to_self = pkt_info.bssid_match && - ether_addr_equal(rx_ra, my_hwaddr); - - pkt_info.is_beacon = pkt_info.bssid_match && - (GetFrameSubType(wlanhdr) == WIFI_BEACON); - - sa = get_ta(wlanhdr); - - pkt_info.station_id = 0xFF; - - pstapriv = &padapter->stapriv; - psta = rtw_get_stainfo(pstapriv, sa); - if (psta) - pkt_info.station_id = psta->mac_id; - - pkt_info.data_rate = pattrib->data_rate; - - /* rtl8723b_query_rx_phy_status(precvframe, pphy_status); */ - /* spin_lock_bh(&p_hal_data->odm_stainfo_lock); */ - odm_phy_status_query(&p_hal_data->odmpriv, p_phy_info, - (u8 *)pphy_status, &(pkt_info)); - if (psta) - psta->rssi = pattrib->phy_info.RecvSignalPower; - /* spin_unlock_bh(&p_hal_data->odm_stainfo_lock); */ - precvframe->u.hdr.psta = NULL; - if ( - pkt_info.bssid_match && - (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) - ) { - if (psta) { - precvframe->u.hdr.psta = psta; - rtl8723b_process_phy_info(padapter, precvframe); - } - } else if (pkt_info.to_self || pkt_info.is_beacon) { - u32 adhoc_state = WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE; - - if (check_fwstate(&padapter->mlmepriv, adhoc_state)) - if (psta) - precvframe->u.hdr.psta = psta; - rtl8723b_process_phy_info(padapter, precvframe); - } -} - -static void rtl8723bs_c2h_packet_handler(struct adapter *padapter, - u8 *pbuf, u16 length) -{ - u8 *tmp = NULL; - u8 res = false; - - if (length == 0) - return; - - tmp = kmemdup(pbuf, length, GFP_ATOMIC); - if (!tmp) - return; - - res = rtw_c2h_packet_wk_cmd(padapter, tmp, length); - - if (!res) - kfree(tmp); -} - -static inline union recv_frame *try_alloc_recvframe(struct recv_priv *precvpriv, - struct recv_buf *precvbuf) -{ - union recv_frame *precvframe; - - precvframe = rtw_alloc_recvframe(&precvpriv->free_recv_queue); - if (!precvframe) { - rtw_enqueue_recvbuf_to_head(precvbuf, - &precvpriv->recv_buf_pending_queue); - - /* The case of can't allocate recvframe should be temporary, */ - /* schedule again and hope recvframe is available next time. */ - tasklet_schedule(&precvpriv->recv_tasklet); - } - - return precvframe; -} - -static inline bool rx_crc_err(struct recv_priv *precvpriv, - struct hal_com_data *p_hal_data, - struct rx_pkt_attrib *pattrib, - union recv_frame *precvframe) -{ - /* fix Hardware RX data error, drop whole recv_buffer */ - if ((!(p_hal_data->ReceiveConfig & RCR_ACRC32)) && pattrib->crc_err) { - rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue); - return true; - } - - return false; -} - -static inline bool pkt_exceeds_tail(struct recv_priv *precvpriv, - u8 *end, u8 *tail, - union recv_frame *precvframe) -{ - if (end > tail) { - rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue); - return true; - } - - return false; -} - -static void rtl8723bs_recv_tasklet(struct tasklet_struct *t) -{ - struct adapter *padapter = from_tasklet(padapter, t, - recvpriv.recv_tasklet); - struct hal_com_data *p_hal_data; - struct recv_priv *precvpriv; - struct recv_buf *precvbuf; - union recv_frame *precvframe; - struct rx_pkt_attrib *pattrib; - struct __queue *recv_buf_queue; - u8 *ptr; - u32 pkt_offset, skb_len, alloc_sz; - struct sk_buff *pkt_copy = NULL; - u8 shift_sz = 0, rx_report_sz = 0; - - p_hal_data = GET_HAL_DATA(padapter); - precvpriv = &padapter->recvpriv; - recv_buf_queue = &precvpriv->recv_buf_pending_queue; - - do { - precvbuf = rtw_dequeue_recvbuf(recv_buf_queue); - if (!precvbuf) - break; - - ptr = precvbuf->pdata; - - while (ptr < precvbuf->ptail) { - precvframe = try_alloc_recvframe(precvpriv, precvbuf); - if (!precvframe) - return; - - /* rx desc parsing */ - update_recvframe_attrib(padapter, precvframe, - (struct recv_stat *)ptr); - - pattrib = &precvframe->u.hdr.attrib; - - if (rx_crc_err(precvpriv, p_hal_data, - pattrib, precvframe)) - break; - - rx_report_sz = RXDESC_SIZE + pattrib->drvinfo_sz; - pkt_offset = rx_report_sz + - pattrib->shift_sz + - pattrib->pkt_len; - - if (pkt_exceeds_tail(precvpriv, ptr + pkt_offset, - precvbuf->ptail, precvframe)) - break; - - if ((pattrib->crc_err) || (pattrib->icv_err)) { - rtw_free_recvframe(precvframe, - &precvpriv->free_recv_queue); - } else { - /* Modified by Albert 20101213 */ - /* For 8 bytes IP header alignment. */ - if (pattrib->qos) /* Qos data, wireless lan header length is 26 */ - shift_sz = 6; - else - shift_sz = 0; - - skb_len = pattrib->pkt_len; - - /* for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet. */ - /* modify alloc_sz for recvive crc error packet by thomas 2011-06-02 */ - if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) { - if (skb_len <= 1650) - alloc_sz = 1664; - else - alloc_sz = skb_len + 14; - } else { - alloc_sz = skb_len; - /* 6 is for IP header 8 bytes alignment in QoS packet case. */ - /* 8 is for skb->data 4 bytes alignment. */ - alloc_sz += 14; - } - - pkt_copy = __dev_alloc_skb(alloc_sz, GFP_ATOMIC); - if (!pkt_copy) { - rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue); - break; - } - - pkt_copy->dev = padapter->pnetdev; - precvframe->u.hdr.pkt = pkt_copy; - skb_reserve(pkt_copy, 8 - ((SIZE_PTR)(pkt_copy->data) & 7));/* force pkt_copy->data at 8-byte alignment address */ - skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */ - memcpy(pkt_copy->data, (ptr + rx_report_sz + pattrib->shift_sz), skb_len); - precvframe->u.hdr.rx_head = pkt_copy->head; - precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data; - precvframe->u.hdr.rx_end = skb_end_pointer(pkt_copy); - - recvframe_put(precvframe, skb_len); - /* recvframe_pull(precvframe, drvinfo_sz + RXDESC_SIZE); */ - - if (p_hal_data->ReceiveConfig & RCR_APPFCS) - recvframe_pull_tail(precvframe, IEEE80211_FCS_LEN); - - /* move to drv info position */ - ptr += RXDESC_SIZE; - - /* update drv info */ - if (p_hal_data->ReceiveConfig & RCR_APP_BA_SSN) { - /* rtl8723s_update_bassn(padapter, pdrvinfo); */ - ptr += 4; - } - - if (pattrib->pkt_rpt_type == NORMAL_RX) { /* Normal rx packet */ - if (pattrib->physt) - update_recvframe_phyinfo(precvframe, (struct phy_stat *)ptr); - - rtw_recv_entry(precvframe); - } else if (pattrib->pkt_rpt_type == C2H_PACKET) { - struct c2h_evt_hdr_t C2hEvent; - - u16 len_c2h = pattrib->pkt_len; - u8 *pbuf_c2h = precvframe->u.hdr.rx_data; - u8 *pdata_c2h; - - C2hEvent.CmdID = pbuf_c2h[0]; - C2hEvent.CmdSeq = pbuf_c2h[1]; - C2hEvent.CmdLen = (len_c2h-2); - pdata_c2h = pbuf_c2h+2; - - if (C2hEvent.CmdID == C2H_CCX_TX_RPT) - CCX_FwC2HTxRpt_8723b(padapter, pdata_c2h, C2hEvent.CmdLen); - else - rtl8723bs_c2h_packet_handler(padapter, precvframe->u.hdr.rx_data, pattrib->pkt_len); - - rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue); - } - } - - pkt_offset = round_up(pkt_offset, 8); - precvbuf->pdata += pkt_offset; - ptr = precvbuf->pdata; - precvframe = NULL; - pkt_copy = NULL; - } - - rtw_enqueue_recvbuf(precvbuf, &precvpriv->free_recv_buf_queue); - } while (1); -} - -/* - * Initialize recv private variable for hardware dependent - * 1. recv buf - * 2. recv tasklet - * - */ -s32 rtl8723bs_init_recv_priv(struct adapter *padapter) -{ - s32 res; - u32 i, n; - struct recv_priv *precvpriv; - struct recv_buf *precvbuf; - - res = _SUCCESS; - precvpriv = &padapter->recvpriv; - - /* 3 1. init recv buffer */ - INIT_LIST_HEAD(&precvpriv->free_recv_buf_queue.queue); - spin_lock_init(&precvpriv->free_recv_buf_queue.lock); - INIT_LIST_HEAD(&precvpriv->recv_buf_pending_queue.queue); - spin_lock_init(&precvpriv->recv_buf_pending_queue.lock); - - n = NR_RECVBUFF * sizeof(struct recv_buf) + 4; - precvpriv->pallocated_recv_buf = kzalloc(n, GFP_KERNEL); - if (!precvpriv->pallocated_recv_buf) { - res = _FAIL; - goto exit; - } - - precvpriv->precv_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(precvpriv->pallocated_recv_buf), 4); - - /* init each recv buffer */ - precvbuf = (struct recv_buf *)precvpriv->precv_buf; - for (i = 0; i < NR_RECVBUFF; i++) { - initrecvbuf(precvbuf, padapter); - - if (!precvbuf->pskb) { - SIZE_PTR tmpaddr = 0; - SIZE_PTR alignment = 0; - - precvbuf->pskb = __dev_alloc_skb(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ, GFP_ATOMIC); - if (precvbuf->pskb) { - precvbuf->pskb->dev = padapter->pnetdev; - - tmpaddr = (SIZE_PTR)precvbuf->pskb->data; - alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1); - skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment)); - } - } - - list_add_tail(&precvbuf->list, &precvpriv->free_recv_buf_queue.queue); - - precvbuf++; - } - precvpriv->free_recv_buf_queue_cnt = i; - - if (res == _FAIL) - goto initbuferror; - - /* 3 2. init tasklet */ - tasklet_setup(&precvpriv->recv_tasklet, rtl8723bs_recv_tasklet); - - goto exit; - -initbuferror: - precvbuf = (struct recv_buf *)precvpriv->precv_buf; - if (precvbuf) { - n = precvpriv->free_recv_buf_queue_cnt; - precvpriv->free_recv_buf_queue_cnt = 0; - for (i = 0; i < n ; i++) { - list_del_init(&precvbuf->list); - if (precvbuf->pskb) - dev_kfree_skb_any(precvbuf->pskb); - precvbuf++; - } - precvpriv->precv_buf = NULL; - } - - kfree(precvpriv->pallocated_recv_buf); - precvpriv->pallocated_recv_buf = NULL; - -exit: - return res; -} - -/* - * Free recv private variable of hardware dependent - * 1. recv buf - * 2. recv tasklet - * - */ -void rtl8723bs_free_recv_priv(struct adapter *padapter) -{ - u32 i; - struct recv_priv *precvpriv; - struct recv_buf *precvbuf; - - precvpriv = &padapter->recvpriv; - - /* 3 1. kill tasklet */ - tasklet_kill(&precvpriv->recv_tasklet); - - /* 3 2. free all recv buffers */ - precvbuf = (struct recv_buf *)precvpriv->precv_buf; - if (precvbuf) { - precvpriv->free_recv_buf_queue_cnt = 0; - for (i = 0; i < NR_RECVBUFF; i++) { - list_del_init(&precvbuf->list); - if (precvbuf->pskb) - dev_kfree_skb_any(precvbuf->pskb); - precvbuf++; - } - precvpriv->precv_buf = NULL; - } - - kfree(precvpriv->pallocated_recv_buf); - precvpriv->pallocated_recv_buf = NULL; -} diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c deleted file mode 100644 index 7f55448d544e..000000000000 --- a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c +++ /dev/null @@ -1,568 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include - -static u8 rtw_sdio_wait_enough_TxOQT_space(struct adapter *padapter, u8 agg_num) -{ - u32 n = 0; - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - while (pHalData->SdioTxOQTFreeSpace < agg_num) { - if ( - (padapter->bSurpriseRemoved) || - (padapter->driver_stopped) - ) - return false; - - HalQueryTxOQTBufferStatus8723BSdio(padapter); - - if ((++n % 60) == 0) { - msleep(1); - /* yield(); */ - } - } - - pHalData->SdioTxOQTFreeSpace -= agg_num; - - return true; -} - -static s32 rtl8723_dequeue_writeport(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct xmit_buf *pxmitbuf; - struct adapter *pri_padapter = padapter; - s32 ret = 0; - u8 PageIdx = 0; - u32 deviceId; - u8 bUpdatePageNum = false; - - ret = ret || check_fwstate(pmlmepriv, _FW_UNDER_SURVEY); - - if (ret) - pxmitbuf = dequeue_pending_xmitbuf_under_survey(pxmitpriv); - else - pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv); - - if (!pxmitbuf) - return true; - - deviceId = ffaddr2deviceId(pdvobjpriv, pxmitbuf->ff_hwaddr); - - /* translate fifo addr to queue index */ - switch (deviceId) { - case WLAN_TX_HIQ_DEVICE_ID: - PageIdx = HI_QUEUE_IDX; - break; - - case WLAN_TX_MIQ_DEVICE_ID: - PageIdx = MID_QUEUE_IDX; - break; - - case WLAN_TX_LOQ_DEVICE_ID: - PageIdx = LOW_QUEUE_IDX; - break; - } - -query_free_page: - /* check if hardware tx fifo page is enough */ - if (!rtw_hal_sdio_query_tx_freepage(pri_padapter, PageIdx, pxmitbuf->pg_num)) { - if (!bUpdatePageNum) { - /* Total page count is not available, so update current FIFO status */ - HalQueryTxBufferStatus8723BSdio(padapter); - bUpdatePageNum = true; - goto query_free_page; - } else { - bUpdatePageNum = false; - enqueue_pending_xmitbuf_to_head(pxmitpriv, pxmitbuf); - return true; - } - } - - if ( - (padapter->bSurpriseRemoved) || - (padapter->driver_stopped) - ) - goto free_xmitbuf; - - if (!rtw_sdio_wait_enough_TxOQT_space(padapter, pxmitbuf->agg_num)) - goto free_xmitbuf; - - traffic_check_for_leave_lps(padapter, true, pxmitbuf->agg_num); - - rtw_write_port(padapter, deviceId, pxmitbuf->len, (u8 *)pxmitbuf); - - rtw_hal_sdio_update_tx_freepage(pri_padapter, PageIdx, pxmitbuf->pg_num); - -free_xmitbuf: - /* rtw_free_xmitframe(pxmitpriv, pframe); */ - /* pxmitbuf->priv_data = NULL; */ - rtw_free_xmitbuf(pxmitpriv, pxmitbuf); - - return _FAIL; -} - -/* - * Description - *Transmit xmitbuf to hardware tx fifo - * - * Return - *_SUCCESS ok - *_FAIL something error - */ -s32 rtl8723bs_xmit_buf_handler(struct adapter *padapter) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - u8 queue_empty, queue_pending; - s32 ret; - - if (wait_for_completion_interruptible(&pxmitpriv->xmit_comp)) { - netdev_emerg(padapter->pnetdev, - "%s: down SdioXmitBufSema fail!\n", __func__); - return _FAIL; - } - - ret = (padapter->driver_stopped) || (padapter->bSurpriseRemoved); - if (ret) - return _FAIL; - - queue_pending = check_pending_xmitbuf(pxmitpriv); - - if (!queue_pending) - return _SUCCESS; - - ret = rtw_register_tx_alive(padapter); - if (ret != _SUCCESS) { - return _SUCCESS; - } - - do { - queue_empty = rtl8723_dequeue_writeport(padapter); -/* dump secondary adapter xmitbuf */ - } while (!queue_empty); - - rtw_unregister_tx_alive(padapter); - - return _SUCCESS; -} - -/* - * Description: - *Aggregation packets and send to hardware - * - * Return: - *0 Success - *-1 Hardware resource(TX FIFO) not ready - *-2 Software resource(xmitbuf) not ready - */ -static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv) -{ - s32 err, ret; - u32 k = 0; - struct hw_xmit *hwxmits, *phwxmit; - u8 idx, hwentry; - struct tx_servq *ptxservq; - struct list_head *sta_plist, *sta_phead, *frame_plist, *frame_phead, *tmp; - struct xmit_frame *pxmitframe; - struct __queue *pframe_queue; - struct xmit_buf *pxmitbuf; - u32 txlen, max_xmit_len; - u8 txdesc_size = TXDESC_SIZE; - int inx[4]; - - err = 0; - hwxmits = pxmitpriv->hwxmits; - hwentry = pxmitpriv->hwxmit_entry; - ptxservq = NULL; - pxmitframe = NULL; - pframe_queue = NULL; - pxmitbuf = NULL; - - if (padapter->registrypriv.wifi_spec == 1) { - for (idx = 0; idx < 4; idx++) - inx[idx] = pxmitpriv->wmm_para_seq[idx]; - } else { - inx[0] = 0; - inx[1] = 1; - inx[2] = 2; - inx[3] = 3; - } - - /* 0(VO), 1(VI), 2(BE), 3(BK) */ - for (idx = 0; idx < hwentry; idx++) { - phwxmit = hwxmits + inx[idx]; - - if ( - (check_pending_xmitbuf(pxmitpriv)) && - (padapter->mlmepriv.link_detect_info.higher_busy_tx_traffic) - ) { - if ((phwxmit->accnt > 0) && (phwxmit->accnt < 5)) { - err = -2; - break; - } - } - - max_xmit_len = rtw_hal_get_sdio_tx_max_length(padapter, inx[idx]); - - spin_lock_bh(&pxmitpriv->lock); - - sta_phead = get_list_head(phwxmit->sta_queue); - /* because stop_sta_xmit may delete sta_plist at any time */ - /* so we should add lock here, or while loop can not exit */ - list_for_each_safe(sta_plist, tmp, sta_phead) { - ptxservq = list_entry(sta_plist, struct tx_servq, - tx_pending); - - pframe_queue = &ptxservq->sta_pending; - - frame_phead = get_list_head(pframe_queue); - - while (!list_empty(frame_phead)) { - frame_plist = get_next(frame_phead); - pxmitframe = container_of(frame_plist, struct xmit_frame, list); - - /* check xmit_buf size enough or not */ - txlen = txdesc_size + rtw_wlan_pkt_size(pxmitframe); - if (!pxmitbuf || - ((_RND(pxmitbuf->len, 8) + txlen) > max_xmit_len) || - (k >= (rtw_hal_sdio_max_txoqt_free_space(padapter) - 1)) - ) { - if (pxmitbuf) { - /* pxmitbuf->priv_data will be NULL, and will crash here */ - if (pxmitbuf->len > 0 && - pxmitbuf->priv_data) { - struct xmit_frame *pframe; - - pframe = (struct xmit_frame *)pxmitbuf->priv_data; - pframe->agg_num = k; - pxmitbuf->agg_num = k; - rtl8723b_update_txdesc(pframe, pframe->buf_addr); - rtw_free_xmitframe(pxmitpriv, pframe); - pxmitbuf->priv_data = NULL; - enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf); - /* can not yield under lock */ - /* yield(); */ - } else - rtw_free_xmitbuf(pxmitpriv, pxmitbuf); - } - - pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv); - if (!pxmitbuf) { - err = -2; - complete(&(pxmitpriv->xmit_comp)); - break; - } - k = 0; - } - - /* ok to send, remove frame from queue */ - if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) - if ( - (pxmitframe->attrib.psta->state & WIFI_SLEEP_STATE) && - (pxmitframe->attrib.triggered == 0) - ) - break; - - list_del_init(&pxmitframe->list); - ptxservq->qcnt--; - phwxmit->accnt--; - - if (k == 0) { - pxmitbuf->ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe); - pxmitbuf->priv_data = (u8 *)pxmitframe; - } - - /* coalesce the xmitframe to xmitbuf */ - pxmitframe->pxmitbuf = pxmitbuf; - pxmitframe->buf_addr = pxmitbuf->ptail; - - ret = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe); - if (ret) { - netdev_err(padapter->pnetdev, - "%s: coalesce failed with error %d\n", - __func__, ret); - /* Todo: error handler */ - } else { - k++; - if (k != 1) - rtl8723b_update_txdesc(pxmitframe, pxmitframe->buf_addr); - rtw_count_tx_stats(padapter, pxmitframe, pxmitframe->attrib.last_txcmdsz); - - txlen = txdesc_size + pxmitframe->attrib.last_txcmdsz; - pxmitframe->pg_num = (txlen + 127) / 128; - pxmitbuf->pg_num += (txlen + 127) / 128; - pxmitbuf->ptail += _RND(txlen, 8); /* round to 8 bytes alignment */ - pxmitbuf->len = _RND(pxmitbuf->len, 8) + txlen; - } - - if (k != 1) - rtw_free_xmitframe(pxmitpriv, pxmitframe); - pxmitframe = NULL; - } - - if (list_empty(&pframe_queue->queue)) - list_del_init(&ptxservq->tx_pending); - - if (err) - break; - } - spin_unlock_bh(&pxmitpriv->lock); - - /* dump xmit_buf to hw tx fifo */ - if (pxmitbuf) { - if (pxmitbuf->len > 0) { - struct xmit_frame *pframe; - - pframe = (struct xmit_frame *)pxmitbuf->priv_data; - pframe->agg_num = k; - pxmitbuf->agg_num = k; - rtl8723b_update_txdesc(pframe, pframe->buf_addr); - rtw_free_xmitframe(pxmitpriv, pframe); - pxmitbuf->priv_data = NULL; - enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf); - yield(); - } else - rtw_free_xmitbuf(pxmitpriv, pxmitbuf); - pxmitbuf = NULL; - } - - if (err) - break; - } - - return err; -} - -/* - * Description - *Transmit xmitframe from queue - * - * Return - *_SUCCESS ok - *_FAIL something error - */ -static s32 rtl8723bs_xmit_handler(struct adapter *padapter) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - s32 ret; - - if (wait_for_completion_interruptible(&pxmitpriv->SdioXmitStart)) { - netdev_emerg(padapter->pnetdev, "%s: SdioXmitStart fail!\n", - __func__); - return _FAIL; - } - -next: - if ( - (padapter->driver_stopped) || - (padapter->bSurpriseRemoved) - ) - return _FAIL; - - spin_lock_bh(&pxmitpriv->lock); - ret = rtw_txframes_pending(padapter); - spin_unlock_bh(&pxmitpriv->lock); - if (ret == 0) { - return _SUCCESS; - } - - /* dequeue frame and write to hardware */ - - ret = xmit_xmitframes(padapter, pxmitpriv); - if (ret == -2) { - /* here sleep 1ms will cause big TP loss of TX */ - /* from 50+ to 40+ */ - if (padapter->registrypriv.wifi_spec) - msleep(1); - else - yield(); - goto next; - } - - spin_lock_bh(&pxmitpriv->lock); - ret = rtw_txframes_pending(padapter); - spin_unlock_bh(&pxmitpriv->lock); - if (ret == 1) - goto next; - - return _SUCCESS; -} - -int rtl8723bs_xmit_thread(void *context) -{ - s32 ret = _SUCCESS; - struct adapter *padapter = context; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - allow_signal(SIGTERM); - - do { - ret = rtl8723bs_xmit_handler(padapter); - if (signal_pending(current)) { - flush_signals(current); - } - } while (ret == _SUCCESS); - - complete(&pxmitpriv->SdioXmitTerminate); - - return 0; -} - -s32 rtl8723bs_mgnt_xmit( - struct adapter *padapter, struct xmit_frame *pmgntframe -) -{ - s32 ret = _SUCCESS; - struct pkt_attrib *pattrib = &pmgntframe->attrib; - struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - u8 *pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - u8 txdesc_size = TXDESC_SIZE; - - rtl8723b_update_txdesc(pmgntframe, pmgntframe->buf_addr); - - pxmitbuf->len = txdesc_size + pattrib->last_txcmdsz; - pxmitbuf->pg_num = (pxmitbuf->len + 127) / 128; /* 128 is tx page size */ - pxmitbuf->ptail = pmgntframe->buf_addr + pxmitbuf->len; - pxmitbuf->ff_hwaddr = rtw_get_ff_hwaddr(pmgntframe); - - rtw_count_tx_stats(padapter, pmgntframe, pattrib->last_txcmdsz); - - rtw_free_xmitframe(pxmitpriv, pmgntframe); - - pxmitbuf->priv_data = NULL; - - if (GetFrameSubType(pframe) == WIFI_BEACON) { /* dump beacon directly */ - ret = rtw_write_port(padapter, pdvobjpriv->Queue2Pipe[pxmitbuf->ff_hwaddr], pxmitbuf->len, (u8 *)pxmitbuf); - if (ret != _SUCCESS) - rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_WRITE_PORT_ERR); - - rtw_free_xmitbuf(pxmitpriv, pxmitbuf); - } else - enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf); - - return ret; -} - -/* - * Description: - *Handle xmitframe(packet) come from rtw_xmit() - * - * Return: - * true dump packet directly ok - * false enqueue, temporary can't transmit packets to hardware - */ -s32 rtl8723bs_hal_xmit( - struct adapter *padapter, struct xmit_frame *pxmitframe -) -{ - struct xmit_priv *pxmitpriv; - s32 err; - - pxmitframe->attrib.qsel = pxmitframe->attrib.priority; - pxmitpriv = &padapter->xmitpriv; - - if ( - (pxmitframe->frame_tag == DATA_FRAMETAG) && - (pxmitframe->attrib.ether_type != 0x0806) && - (pxmitframe->attrib.ether_type != 0x888e) && - (pxmitframe->attrib.dhcp_pkt != 1) - ) { - if (padapter->mlmepriv.link_detect_info.busy_traffic) - rtw_issue_addbareq_cmd(padapter, pxmitframe); - } - - spin_lock_bh(&pxmitpriv->lock); - err = rtw_xmitframe_enqueue(padapter, pxmitframe); - spin_unlock_bh(&pxmitpriv->lock); - if (err) { - rtw_free_xmitframe(pxmitpriv, pxmitframe); - - pxmitpriv->tx_drop++; - return true; - } - - complete(&pxmitpriv->SdioXmitStart); - - return false; -} - -s32 rtl8723bs_hal_xmitframe_enqueue( - struct adapter *padapter, struct xmit_frame *pxmitframe -) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - s32 err; - - err = rtw_xmitframe_enqueue(padapter, pxmitframe); - if (err) { - rtw_free_xmitframe(pxmitpriv, pxmitframe); - - pxmitpriv->tx_drop++; - } else { - complete(&pxmitpriv->SdioXmitStart); - } - - return err; - -} - -/* - * Return - *_SUCCESS start thread ok - *_FAIL start thread fail - * - */ -s32 rtl8723bs_init_xmit_priv(struct adapter *padapter) -{ - struct xmit_priv *xmitpriv = &padapter->xmitpriv; - struct hal_com_data *phal; - - phal = GET_HAL_DATA(padapter); - - init_completion(&xmitpriv->SdioXmitStart); - init_completion(&xmitpriv->SdioXmitTerminate); - - return _SUCCESS; -} - -void rtl8723bs_free_xmit_priv(struct adapter *padapter) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct xmit_buf *pxmitbuf; - struct __queue *pqueue = &pxmitpriv->pending_xmitbuf_queue; - struct list_head *plist, *phead; - struct list_head tmplist; - - phead = get_list_head(pqueue); - INIT_LIST_HEAD(&tmplist); - - spin_lock_bh(&pqueue->lock); - if (!list_empty(&pqueue->queue)) { - /* Insert tmplist to end of queue, and delete phead */ - /* then tmplist become head of queue. */ - list_add_tail(&tmplist, phead); - list_del_init(phead); - } - spin_unlock_bh(&pqueue->lock); - - phead = &tmplist; - while (!list_empty(phead)) { - plist = get_next(phead); - list_del_init(plist); - - pxmitbuf = container_of(plist, struct xmit_buf, list); - rtw_free_xmitframe(pxmitpriv, (struct xmit_frame *)pxmitbuf->priv_data); - pxmitbuf->priv_data = NULL; - rtw_free_xmitbuf(pxmitpriv, pxmitbuf); - } -} diff --git a/drivers/staging/rtl8723bs/hal/sdio_halinit.c b/drivers/staging/rtl8723bs/hal/sdio_halinit.c deleted file mode 100644 index 57d2925642e7..000000000000 --- a/drivers/staging/rtl8723bs/hal/sdio_halinit.c +++ /dev/null @@ -1,1192 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include - -#include "hal_com_h2c.h" -/* - * Description: - *Call power on sequence to enable card - * - * Return: - *_SUCCESS enable success - *_FAIL enable fail - */ -static u8 CardEnable(struct adapter *padapter) -{ - u8 bMacPwrCtrlOn; - u8 ret = _FAIL; - - rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); - if (!bMacPwrCtrlOn) { - /* RSV_CTRL 0x1C[7:0] = 0x00 */ - /* unlock ISO/CLK/Power control register */ - rtw_write8(padapter, REG_RSV_CTRL, 0x0); - - ret = HalPwrSeqCmdParsing(padapter, - PWR_CUT_ALL_MSK, - PWR_FAB_ALL_MSK, - PWR_INTF_SDIO_MSK, - rtl8723B_card_enable_flow); - if (ret == _SUCCESS) { - bMacPwrCtrlOn = true; - rtw_hal_set_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); - } - } else { - ret = _SUCCESS; - } - - return ret; -} - -static -u8 _InitPowerOn_8723BS(struct adapter *padapter) -{ - u8 value8; - u16 value16; - u32 value32; - u8 ret; - - /* all of these MUST be configured before power on */ - - /* only cmd52 can be used before power on(card enable) */ - ret = CardEnable(padapter); - if (!ret) - return _FAIL; - - /* Radio-Off Pin Trigger */ - value8 = rtw_read8(padapter, REG_GPIO_INTM + 1); - value8 |= BIT(1); /* Enable falling edge triggering interrupt */ - rtw_write8(padapter, REG_GPIO_INTM + 1, value8); - value8 = rtw_read8(padapter, REG_GPIO_IO_SEL_2 + 1); - value8 |= BIT(1); - rtw_write8(padapter, REG_GPIO_IO_SEL_2 + 1, value8); - - /* Enable power down and GPIO interrupt */ - value16 = rtw_read16(padapter, REG_APS_FSMCO); - value16 |= EnPDN; /* Enable HW power down and RF on */ - rtw_write16(padapter, REG_APS_FSMCO, value16); - - rtw_write8(padapter, REG_CR, 0x00); - /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */ - value16 = rtw_read16(padapter, REG_CR); - value16 |= ( - HCI_TXDMA_EN | - HCI_RXDMA_EN | - TXDMA_EN | - RXDMA_EN | - PROTOCOL_EN | - SCHEDULE_EN | - ENSEC | - CALTMR_EN - ); - rtw_write16(padapter, REG_CR, value16); - - hal_btcoex_PowerOnSetting(padapter); - - /* external switch to S1 */ - /* 0x38[11] = 0x1 */ - /* 0x4c[23] = 0x1 */ - /* 0x64[0] = 0 */ - value16 = rtw_read16(padapter, REG_PWR_DATA); - /* Switch the control of EESK, EECS to RFC for DPDT or Antenna switch */ - value16 |= BIT(11); /* BIT_EEPRPAD_RFE_CTRL_EN */ - rtw_write16(padapter, REG_PWR_DATA, value16); - - value32 = rtw_read32(padapter, REG_LEDCFG0); - value32 |= BIT(23); /* DPDT_SEL_EN, 1 for SW control */ - rtw_write32(padapter, REG_LEDCFG0, value32); - - value8 = rtw_read8(padapter, REG_PAD_CTRL1_8723B); - value8 &= ~BIT(0); /* BIT_SW_DPDT_SEL_DATA, DPDT_SEL default configuration */ - rtw_write8(padapter, REG_PAD_CTRL1_8723B, value8); - - return _SUCCESS; -} - -/* Tx Page FIFO threshold */ -static void _init_available_page_threshold(struct adapter *padapter, - u8 numHQ, - u8 numNQ, - u8 numLQ, - u8 numPubQ) -{ - u16 HQ_threshold, NQ_threshold, LQ_threshold; - - HQ_threshold = (numPubQ + numHQ + 1) >> 1; - HQ_threshold |= (HQ_threshold << 8); - - NQ_threshold = (numPubQ + numNQ + 1) >> 1; - NQ_threshold |= (NQ_threshold << 8); - - LQ_threshold = (numPubQ + numLQ + 1) >> 1; - LQ_threshold |= (LQ_threshold << 8); - - rtw_write16(padapter, 0x218, HQ_threshold); - rtw_write16(padapter, 0x21A, NQ_threshold); - rtw_write16(padapter, 0x21C, LQ_threshold); -} - -static void _InitQueueReservedPage(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct registry_priv *pregistrypriv = &padapter->registrypriv; - u32 numHQ = 0; - u32 numLQ = 0; - u32 numNQ = 0; - u32 numPubQ; - u32 value32; - u8 value8; - bool bWiFiConfig = pregistrypriv->wifi_spec; - - if (pHalData->OutEpQueueSel & TX_SELE_HQ) - numHQ = bWiFiConfig ? WMM_NORMAL_PAGE_NUM_HPQ_8723B : NORMAL_PAGE_NUM_HPQ_8723B; - - if (pHalData->OutEpQueueSel & TX_SELE_LQ) - numLQ = bWiFiConfig ? WMM_NORMAL_PAGE_NUM_LPQ_8723B : NORMAL_PAGE_NUM_LPQ_8723B; - - /* NOTE: This step shall be proceed before writing REG_RQPN. */ - if (pHalData->OutEpQueueSel & TX_SELE_NQ) - numNQ = bWiFiConfig ? WMM_NORMAL_PAGE_NUM_NPQ_8723B : NORMAL_PAGE_NUM_NPQ_8723B; - - numPubQ = TX_TOTAL_PAGE_NUMBER_8723B - numHQ - numLQ - numNQ; - - value8 = (u8)_NPQ(numNQ); - rtw_write8(padapter, REG_RQPN_NPQ, value8); - - /* TX DMA */ - value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN; - rtw_write32(padapter, REG_RQPN, value32); - - rtw_hal_set_sdio_tx_max_length(padapter, numHQ, numNQ, numLQ, numPubQ); - - _init_available_page_threshold(padapter, numHQ, numNQ, numLQ, numPubQ); -} - -static void _InitTxBufferBoundary(struct adapter *padapter) -{ - struct registry_priv *pregistrypriv = &padapter->registrypriv; - - /* u16 txdmactrl; */ - u8 txpktbuf_bndy; - - if (!pregistrypriv->wifi_spec) { - txpktbuf_bndy = TX_PAGE_BOUNDARY_8723B; - } else { - /* for WMM */ - txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_8723B; - } - - rtw_write8(padapter, REG_TXPKTBUF_BCNQ_BDNY_8723B, txpktbuf_bndy); - rtw_write8(padapter, REG_TXPKTBUF_MGQ_BDNY_8723B, txpktbuf_bndy); - rtw_write8(padapter, REG_TXPKTBUF_WMAC_LBK_BF_HD_8723B, txpktbuf_bndy); - rtw_write8(padapter, REG_TRXFF_BNDY, txpktbuf_bndy); - rtw_write8(padapter, REG_TDECTRL + 1, txpktbuf_bndy); -} - -static void _InitNormalChipRegPriority( - struct adapter *Adapter, - u16 beQ, - u16 bkQ, - u16 viQ, - u16 voQ, - u16 mgtQ, - u16 hiQ -) -{ - u16 value16 = (rtw_read16(Adapter, REG_TRXDMA_CTRL) & 0x7); - - value16 |= - _TXDMA_BEQ_MAP(beQ) | - _TXDMA_BKQ_MAP(bkQ) | - _TXDMA_VIQ_MAP(viQ) | - _TXDMA_VOQ_MAP(voQ) | - _TXDMA_MGQ_MAP(mgtQ) | - _TXDMA_HIQ_MAP(hiQ); - - rtw_write16(Adapter, REG_TRXDMA_CTRL, value16); -} - -static void _InitNormalChipOneOutEpPriority(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - u16 value = 0; - - switch (pHalData->OutEpQueueSel) { - case TX_SELE_HQ: - value = QUEUE_HIGH; - break; - case TX_SELE_LQ: - value = QUEUE_LOW; - break; - case TX_SELE_NQ: - value = QUEUE_NORMAL; - break; - default: - break; - } - - _InitNormalChipRegPriority( - Adapter, value, value, value, value, value, value - ); - -} - -static void _InitNormalChipTwoOutEpPriority(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct registry_priv *pregistrypriv = &Adapter->registrypriv; - u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ; - - u16 valueHi = 0; - u16 valueLow = 0; - - switch (pHalData->OutEpQueueSel) { - case (TX_SELE_HQ | TX_SELE_LQ): - valueHi = QUEUE_HIGH; - valueLow = QUEUE_LOW; - break; - case (TX_SELE_NQ | TX_SELE_LQ): - valueHi = QUEUE_NORMAL; - valueLow = QUEUE_LOW; - break; - case (TX_SELE_HQ | TX_SELE_NQ): - valueHi = QUEUE_HIGH; - valueLow = QUEUE_NORMAL; - break; - default: - break; - } - - if (!pregistrypriv->wifi_spec) { - beQ = valueLow; - bkQ = valueLow; - viQ = valueHi; - voQ = valueHi; - mgtQ = valueHi; - hiQ = valueHi; - } else { - /* for WMM , CONFIG_OUT_EP_WIFI_MODE */ - beQ = valueLow; - bkQ = valueHi; - viQ = valueHi; - voQ = valueLow; - mgtQ = valueHi; - hiQ = valueHi; - } - - _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ); - -} - -static void _InitNormalChipThreeOutEpPriority(struct adapter *padapter) -{ - struct registry_priv *pregistrypriv = &padapter->registrypriv; - u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ; - - if (!pregistrypriv->wifi_spec) { - /* typical setting */ - beQ = QUEUE_LOW; - bkQ = QUEUE_LOW; - viQ = QUEUE_NORMAL; - voQ = QUEUE_HIGH; - mgtQ = QUEUE_HIGH; - hiQ = QUEUE_HIGH; - } else { - /* for WMM */ - beQ = QUEUE_LOW; - bkQ = QUEUE_NORMAL; - viQ = QUEUE_NORMAL; - voQ = QUEUE_HIGH; - mgtQ = QUEUE_HIGH; - hiQ = QUEUE_HIGH; - } - _InitNormalChipRegPriority(padapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ); -} - -static void _InitQueuePriority(struct adapter *Adapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - - switch (pHalData->OutEpNumber) { - case 1: - _InitNormalChipOneOutEpPriority(Adapter); - break; - case 2: - _InitNormalChipTwoOutEpPriority(Adapter); - break; - case 3: - _InitNormalChipThreeOutEpPriority(Adapter); - break; - default: - break; - } -} - -static void _InitPageBoundary(struct adapter *padapter) -{ - /* RX Page Boundary */ - u16 rxff_bndy = RX_DMA_BOUNDARY_8723B; - - rtw_write16(padapter, (REG_TRXFF_BNDY + 2), rxff_bndy); -} - -static void _InitTransferPageSize(struct adapter *padapter) -{ - /* Tx page size is always 128. */ - - u8 value8; - - value8 = _PSRX(PBP_128) | _PSTX(PBP_128); - rtw_write8(padapter, REG_PBP, value8); -} - -static void _InitDriverInfoSize(struct adapter *padapter, u8 drvInfoSize) -{ - rtw_write8(padapter, REG_RX_DRVINFO_SZ, drvInfoSize); -} - -static void _InitNetworkType(struct adapter *padapter) -{ - u32 value32; - - value32 = rtw_read32(padapter, REG_CR); - - /* TODO: use the other function to set network type */ - value32 = (value32 & ~MASK_NETTYPE) | _NETTYPE(NT_LINK_AP); - - rtw_write32(padapter, REG_CR, value32); -} - -static void _InitWMACSetting(struct adapter *padapter) -{ - struct hal_com_data *pHalData; - u16 value16; - - pHalData = GET_HAL_DATA(padapter); - - pHalData->ReceiveConfig = 0; - pHalData->ReceiveConfig |= RCR_APM | RCR_AM | RCR_AB; - pHalData->ReceiveConfig |= RCR_CBSSID_DATA | RCR_CBSSID_BCN | RCR_AMF; - pHalData->ReceiveConfig |= RCR_HTC_LOC_CTRL; - pHalData->ReceiveConfig |= RCR_APP_PHYST_RXFF | RCR_APP_ICV | RCR_APP_MIC; - rtw_write32(padapter, REG_RCR, pHalData->ReceiveConfig); - - /* Accept all multicast address */ - rtw_write32(padapter, REG_MAR, 0xFFFFFFFF); /* Offset 0x0620-0x0623 */ - rtw_write32(padapter, REG_MAR + 4, 0xFFFFFFFF); /* Offset 0x0624-0x0627 */ - - /* Accept all data frames */ - value16 = 0xFFFF; - rtw_write16(padapter, REG_RXFLTMAP2, value16); - - /* 2010.09.08 hpfan */ - /* Since ADF is removed from RCR, ps-poll will not be indicate to driver, */ - /* RxFilterMap should mask ps-poll to guarantee AP mode can rx ps-poll. */ - value16 = 0x400; - rtw_write16(padapter, REG_RXFLTMAP1, value16); - - /* Accept all management frames */ - value16 = 0xFFFF; - rtw_write16(padapter, REG_RXFLTMAP0, value16); -} - -static void _InitAdaptiveCtrl(struct adapter *padapter) -{ - u16 value16; - u32 value32; - - /* Response Rate Set */ - value32 = rtw_read32(padapter, REG_RRSR); - value32 &= ~RATE_BITMAP_ALL; - value32 |= RATE_RRSR_CCK_ONLY_1M; - rtw_write32(padapter, REG_RRSR, value32); - - /* SIFS (used in NAV) */ - value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10); - rtw_write16(padapter, REG_SPEC_SIFS, value16); - - /* Retry Limit */ - value16 = _LRL(0x30) | _SRL(0x30); - rtw_write16(padapter, REG_RL, value16); -} - -static void _InitEDCA(struct adapter *padapter) -{ - /* Set Spec SIFS (used in NAV) */ - rtw_write16(padapter, REG_SPEC_SIFS, 0x100a); - rtw_write16(padapter, REG_MAC_SPEC_SIFS, 0x100a); - - /* Set SIFS for CCK */ - rtw_write16(padapter, REG_SIFS_CTX, 0x100a); - - /* Set SIFS for OFDM */ - rtw_write16(padapter, REG_SIFS_TRX, 0x100a); - - /* TXOP */ - rtw_write32(padapter, REG_EDCA_BE_PARAM, 0x005EA42B); - rtw_write32(padapter, REG_EDCA_BK_PARAM, 0x0000A44F); - rtw_write32(padapter, REG_EDCA_VI_PARAM, 0x005EA324); - rtw_write32(padapter, REG_EDCA_VO_PARAM, 0x002FA226); -} - -static void _InitRetryFunction(struct adapter *padapter) -{ - u8 value8; - - value8 = rtw_read8(padapter, REG_FWHW_TXQ_CTRL); - value8 |= EN_AMPDU_RTY_NEW; - rtw_write8(padapter, REG_FWHW_TXQ_CTRL, value8); - - /* Set ACK timeout */ - rtw_write8(padapter, REG_ACKTO, 0x40); -} - -static void HalRxAggr8723BSdio(struct adapter *padapter) -{ - u8 valueDMATimeout; - u8 valueDMAPageCount; - - valueDMATimeout = 0x06; - valueDMAPageCount = 0x06; - - rtw_write8(padapter, REG_RXDMA_AGG_PG_TH + 1, valueDMATimeout); - rtw_write8(padapter, REG_RXDMA_AGG_PG_TH, valueDMAPageCount); -} - -static void sdio_AggSettingRxUpdate(struct adapter *padapter) -{ - u8 valueDMA; - u8 valueRxAggCtrl = 0; - u8 aggBurstNum = 3; /* 0:1, 1:2, 2:3, 3:4 */ - u8 aggBurstSize = 0; /* 0:1K, 1:512Byte, 2:256Byte... */ - - valueDMA = rtw_read8(padapter, REG_TRXDMA_CTRL); - valueDMA |= RXDMA_AGG_EN; - rtw_write8(padapter, REG_TRXDMA_CTRL, valueDMA); - - valueRxAggCtrl |= RXDMA_AGG_MODE_EN; - valueRxAggCtrl |= ((aggBurstNum << 2) & 0x0C); - valueRxAggCtrl |= ((aggBurstSize << 4) & 0x30); - rtw_write8(padapter, REG_RXDMA_MODE_CTRL_8723B, valueRxAggCtrl);/* RxAggLowThresh = 4*1K */ -} - -static void _initSdioAggregationSetting(struct adapter *padapter) -{ - /* Rx aggregation setting */ - HalRxAggr8723BSdio(padapter); - - sdio_AggSettingRxUpdate(padapter); -} - -static void _InitOperationMode(struct adapter *padapter) -{ - struct mlme_ext_priv *pmlmeext; - u8 regBwOpMode = 0; - - pmlmeext = &padapter->mlmeextpriv; - - /* 1 This part need to modified according to the rate set we filtered!! */ - /* */ - /* Set RRSR, RATR, and REG_BWOPMODE registers */ - /* */ - switch (pmlmeext->cur_wireless_mode) { - case WIRELESS_MODE_B: - regBwOpMode = BW_OPMODE_20MHZ; - break; - case WIRELESS_MODE_G: - regBwOpMode = BW_OPMODE_20MHZ; - break; - case WIRELESS_MODE_AUTO: - regBwOpMode = BW_OPMODE_20MHZ; - break; - case WIRELESS_MODE_N_24G: - /* It support CCK rate by default. */ - /* CCK rate will be filtered out only when associated AP does not support it. */ - regBwOpMode = BW_OPMODE_20MHZ; - break; - - default: /* for MacOSX compiler warning. */ - break; - } - - rtw_write8(padapter, REG_BWOPMODE, regBwOpMode); - -} - -static void _InitInterrupt(struct adapter *padapter) -{ - /* HISR - turn all off */ - rtw_write32(padapter, REG_HISR, 0); - - /* HIMR - turn all off */ - rtw_write32(padapter, REG_HIMR, 0); - - /* */ - /* Initialize and enable SDIO Host Interrupt. */ - /* */ - InitInterrupt8723BSdio(padapter); -} - -static void _RfPowerSave(struct adapter *padapter) -{ -/* YJ, TODO */ -} - -/* */ -/* 2010/08/09 MH Add for power down check. */ -/* */ -static bool HalDetectPwrDownMode(struct adapter *Adapter) -{ - u8 tmpvalue; - struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(Adapter); - - rtw_efuse_shadow_read(Adapter, 1, 0x7B/*EEPROM_RF_OPT3_92C*/, (u32 *)&tmpvalue); - - /* 2010/08/25 MH INF priority > PDN Efuse value. */ - if (tmpvalue & BIT(4) && pwrctrlpriv->reg_pdnmode) - pHalData->pwrdown = true; - else - pHalData->pwrdown = false; - - return pHalData->pwrdown; -} /* HalDetectPwrDownMode */ - -u32 rtl8723bs_hal_init(struct adapter *padapter) -{ - s32 ret; - struct hal_com_data *pHalData; - struct pwrctrl_priv *pwrctrlpriv; - u32 NavUpper = WiFiNavUpperUs; - u8 val; - - pHalData = GET_HAL_DATA(padapter); - pwrctrlpriv = adapter_to_pwrctl(padapter); - - if (adapter_to_pwrctl(padapter)->bips_processing && - adapter_to_pwrctl(padapter)->pre_ips_type == 0) { - unsigned long start_time; - u8 cpwm_orig, cpwm_now; - u8 val8, bMacPwrCtrlOn = true; - - /* for polling cpwm */ - cpwm_orig = 0; - rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig); - - /* set rpwm */ - val8 = rtw_read8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1); - val8 &= 0x80; - val8 += 0x80; - val8 |= BIT(6); - rtw_write8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1, val8); - adapter_to_pwrctl(padapter)->tog = (val8 + 0x80) & 0x80; - - /* do polling cpwm */ - start_time = jiffies; - do { - - mdelay(1); - - rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_now); - if ((cpwm_orig ^ cpwm_now) & 0x80) - break; - - if (jiffies_to_msecs(jiffies - start_time) > 100) - break; - - } while (1); - - rtl8723b_set_FwPwrModeInIPS_cmd(padapter, 0); - - rtw_hal_set_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); - - hal_btcoex_InitHwConfig(padapter, false); - - return _SUCCESS; - } - - ret = _InitPowerOn_8723BS(padapter); - if (ret == _FAIL) - return _FAIL; - - rtw_write8(padapter, REG_EARLY_MODE_CONTROL, 0); - - ret = rtl8723b_FirmwareDownload(padapter, false); - if (ret != _SUCCESS) { - padapter->bFWReady = false; - pHalData->fw_ractrl = false; - return ret; - } - - padapter->bFWReady = true; - pHalData->fw_ractrl = true; - - rtl8723b_InitializeFirmwareVars(padapter); - - if (pwrctrlpriv->reg_rfoff) - pwrctrlpriv->rf_pwrstate = rf_off; - - /* 2010/08/09 MH We need to check if we need to turnon or off RF after detecting */ - /* HW GPIO pin. Before PHY_RFConfig8192C. */ - HalDetectPwrDownMode(padapter); - - /* Save target channel */ - /* Current Channel will be updated again later. */ - pHalData->CurrentChannel = 6; - - ret = PHY_MACConfig8723B(padapter); - if (ret != _SUCCESS) - return ret; - /* */ - /* d. Initialize BB related configurations. */ - /* */ - ret = PHY_BBConfig8723B(padapter); - if (ret != _SUCCESS) - return ret; - - /* If RF is on, we need to init RF. Otherwise, skip the procedure. */ - /* We need to follow SU method to change the RF cfg.txt. Default disable RF TX/RX mode. */ - /* if (pHalData->eRFPowerState == eRfOn) */ - { - ret = PHY_RFConfig8723B(padapter); - if (ret != _SUCCESS) - return ret; - } - - /* */ - /* Joseph Note: Keep RfRegChnlVal for later use. */ - /* */ - pHalData->RfRegChnlVal[0] = - PHY_QueryRFReg(padapter, (enum rf_path)0, RF_CHNLBW, bRFRegOffsetMask); - pHalData->RfRegChnlVal[1] = - PHY_QueryRFReg(padapter, (enum rf_path)1, RF_CHNLBW, bRFRegOffsetMask); - - _InitQueueReservedPage(padapter); - _InitTxBufferBoundary(padapter); - - /* init LLT after tx buffer boundary is defined */ - ret = rtl8723b_InitLLTTable(padapter); - if (ret != _SUCCESS) - return _FAIL; - - /* */ - _InitQueuePriority(padapter); - _InitPageBoundary(padapter); - _InitTransferPageSize(padapter); - - /* Get Rx PHY status in order to report RSSI and others. */ - _InitDriverInfoSize(padapter, DRVINFO_SZ); - hal_init_macaddr(padapter); - _InitNetworkType(padapter); - _InitWMACSetting(padapter); - _InitAdaptiveCtrl(padapter); - _InitEDCA(padapter); - _InitRetryFunction(padapter); - _initSdioAggregationSetting(padapter); - _InitOperationMode(padapter); - rtl8723b_InitBeaconParameters(padapter); - _InitInterrupt(padapter); - _InitBurstPktLen_8723BS(padapter); - - /* YJ, TODO */ - rtw_write8(padapter, REG_SECONDARY_CCA_CTRL_8723B, 0x3); /* CCA */ - rtw_write8(padapter, 0x976, 0); /* hpfan_todo: 2nd CCA related */ - - rtw_write16(padapter, REG_PKT_VO_VI_LIFE_TIME, 0x0400); /* unit: 256us. 256ms */ - rtw_write16(padapter, REG_PKT_BE_BK_LIFE_TIME, 0x0400); /* unit: 256us. 256ms */ - - invalidate_cam_all(padapter); - - rtw_hal_set_chnl_bw(padapter, padapter->registrypriv.channel, - CHANNEL_WIDTH_20, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HAL_PRIME_CHNL_OFFSET_DONT_CARE); - - rtl8723b_InitAntenna_Selection(padapter); - - /* */ - /* Disable BAR, suggested by Scott */ - /* 2010.04.09 add by hpfan */ - /* */ - rtw_write32(padapter, REG_BAR_MODE_CTRL, 0x0201ffff); - - /* HW SEQ CTRL */ - /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */ - rtw_write8(padapter, REG_HWSEQ_CTRL, 0xFF); - - /* */ - /* Configure SDIO TxRx Control to enable Rx DMA timer masking. */ - /* 2010.02.24. */ - /* */ - rtw_write32(padapter, SDIO_LOCAL_BASE | SDIO_REG_TX_CTRL, 0); - - _RfPowerSave(padapter); - - rtl8723b_InitHalDm(padapter); - - /* */ - /* Update current Tx FIFO page status. */ - /* */ - HalQueryTxBufferStatus8723BSdio(padapter); - HalQueryTxOQTBufferStatus8723BSdio(padapter); - pHalData->SdioTxOQTMaxFreeSpace = pHalData->SdioTxOQTFreeSpace; - - /* Enable MACTXEN/MACRXEN block */ - val = rtw_read8(padapter, REG_CR); - val |= (MACTXEN | MACRXEN); - rtw_write8(padapter, REG_CR, val); - - rtw_hal_set_hwreg(padapter, HW_VAR_NAV_UPPER, (u8 *)&NavUpper); - - /* ack for xmit mgmt frames. */ - rtw_write32(padapter, REG_FWHW_TXQ_CTRL, rtw_read32(padapter, REG_FWHW_TXQ_CTRL) | BIT(12)); - - { - pwrctrlpriv->rf_pwrstate = rf_on; - - if (pwrctrlpriv->rf_pwrstate == rf_on) { - struct pwrctrl_priv *pwrpriv; - unsigned long start_time; - u8 restore_iqk_rst; - u8 b2Ant; - u8 h2cCmdBuf; - - pwrpriv = adapter_to_pwrctl(padapter); - - PHY_LCCalibrate_8723B(&pHalData->odmpriv); - - /* Inform WiFi FW that it is the beginning of IQK */ - h2cCmdBuf = 1; - FillH2CCmd8723B(padapter, H2C_8723B_BT_WLAN_CALIBRATION, 1, &h2cCmdBuf); - - start_time = jiffies; - do { - if (rtw_read8(padapter, 0x1e7) & 0x01) - break; - - msleep(50); - } while (jiffies_to_msecs(jiffies - start_time) <= 400); - - hal_btcoex_IQKNotify(padapter, true); - - restore_iqk_rst = pwrpriv->bips_processing; - b2Ant = pHalData->EEPROMBluetoothAntNum == Ant_x2; - PHY_IQCalibrate_8723B(padapter, - false, - restore_iqk_rst, - b2Ant, - pHalData->ant_path); - pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = true; - - hal_btcoex_IQKNotify(padapter, false); - - /* Inform WiFi FW that it is the finish of IQK */ - h2cCmdBuf = 0; - FillH2CCmd8723B(padapter, H2C_8723B_BT_WLAN_CALIBRATION, 1, &h2cCmdBuf); - - ODM_TXPowerTrackingCheck(&pHalData->odmpriv); - } - } - - /* Init BT hw config. */ - hal_btcoex_InitHwConfig(padapter, false); - - return _SUCCESS; -} - -/* */ -/* Description: */ -/* RTL8723e card disable power sequence v003 which suggested by Scott. */ -/* */ -/* First created by tynli. 2011.01.28. */ -/* */ -static void CardDisableRTL8723BSdio(struct adapter *padapter) -{ - u8 val; - u8 bMacPwrCtrlOn; - - /* Run LPS WL RFOFF flow */ - HalPwrSeqCmdParsing(padapter, - PWR_CUT_ALL_MSK, - PWR_FAB_ALL_MSK, - PWR_INTF_SDIO_MSK, - rtl8723B_enter_lps_flow); - - /* ==== Reset digital sequence ====== */ - - val = rtw_read8(padapter, REG_MCUFWDL); - if ((val & RAM_DL_SEL) && padapter->bFWReady) /* 8051 RAM code */ - rtl8723b_FirmwareSelfReset(padapter); - - /* Reset MCU 0x2[10]= 0. Suggested by Filen. 2011.01.26. by tynli. */ - val = rtw_read8(padapter, REG_SYS_FUNC_EN + 1); - val &= ~BIT(2); /* 0x2[10], FEN_CPUEN */ - rtw_write8(padapter, REG_SYS_FUNC_EN + 1, val); - - /* MCUFWDL 0x80[1:0]= 0 */ - /* reset MCU ready status */ - rtw_write8(padapter, REG_MCUFWDL, 0); - - /* Reset MCU IO Wrapper, added by Roger, 2011.08.30 */ - val = rtw_read8(padapter, REG_RSV_CTRL + 1); - val &= ~BIT(0); - rtw_write8(padapter, REG_RSV_CTRL + 1, val); - val = rtw_read8(padapter, REG_RSV_CTRL + 1); - val |= BIT(0); - rtw_write8(padapter, REG_RSV_CTRL + 1, val); - - /* ==== Reset digital sequence end ====== */ - - bMacPwrCtrlOn = false; /* Disable CMD53 R/W */ - rtw_hal_set_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); - HalPwrSeqCmdParsing(padapter, - PWR_CUT_ALL_MSK, - PWR_FAB_ALL_MSK, - PWR_INTF_SDIO_MSK, - rtl8723B_card_disable_flow); -} - -u32 rtl8723bs_hal_deinit(struct adapter *padapter) -{ - if (padapter->hw_init_completed) { - if (adapter_to_pwrctl(padapter)->bips_processing) { - if (padapter->netif_up) { - int cnt = 0; - u8 val8 = 0; - - rtl8723b_set_FwPwrModeInIPS_cmd(padapter, 0x3); - /* - * poll 0x1cc to make sure H2C command already finished by FW; - * MAC_0x1cc = 0 means H2C done by FW. - */ - do { - val8 = rtw_read8(padapter, REG_HMETFR); - cnt++; - mdelay(10); - } while (cnt < 100 && (val8 != 0)); - /* H2C done, enter 32k */ - if (val8 == 0) { - /* set rpwm to enter 32k */ - val8 = rtw_read8(padapter, - SDIO_LOCAL_BASE | SDIO_REG_HRPWM1); - val8 += 0x80; - val8 |= BIT(0); - rtw_write8(padapter, - SDIO_LOCAL_BASE | SDIO_REG_HRPWM1, - val8); - adapter_to_pwrctl(padapter)->tog = (val8 + 0x80) & 0x80; - cnt = val8 = 0; - do { - val8 = rtw_read8(padapter, REG_CR); - cnt++; - mdelay(10); - } while (cnt < 100 && (val8 != 0xEA)); - } - - adapter_to_pwrctl(padapter)->pre_ips_type = 0; - - } else { - CardDisableRTL8723BSdio(padapter); - - adapter_to_pwrctl(padapter)->pre_ips_type = 1; - } - - } else { - CardDisableRTL8723BSdio(padapter); - } - } - - return _SUCCESS; -} - -void rtl8723bs_init_default_value(struct adapter *padapter) -{ - struct hal_com_data *pHalData; - - pHalData = GET_HAL_DATA(padapter); - - rtl8723b_init_default_value(padapter); - - /* interface related variable */ - pHalData->SdioRxFIFOCnt = 0; -} - -void rtl8723bs_interface_configure(struct adapter *padapter) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter); - struct registry_priv *pregistrypriv = &padapter->registrypriv; - bool bWiFiConfig = pregistrypriv->wifi_spec; - - pdvobjpriv->RtOutPipe[0] = WLAN_TX_HIQ_DEVICE_ID; - pdvobjpriv->RtOutPipe[1] = WLAN_TX_MIQ_DEVICE_ID; - pdvobjpriv->RtOutPipe[2] = WLAN_TX_LOQ_DEVICE_ID; - - if (bWiFiConfig) - pHalData->OutEpNumber = 2; - else - pHalData->OutEpNumber = SDIO_MAX_TX_QUEUE; - - switch (pHalData->OutEpNumber) { - case 3: - pHalData->OutEpQueueSel = TX_SELE_HQ | TX_SELE_LQ | TX_SELE_NQ; - break; - case 2: - pHalData->OutEpQueueSel = TX_SELE_HQ | TX_SELE_NQ; - break; - case 1: - pHalData->OutEpQueueSel = TX_SELE_HQ; - break; - default: - break; - } - - Hal_MappingOutPipe(padapter, pHalData->OutEpNumber); -} - -/* */ -/* Description: */ -/* We should set Efuse cell selection to WiFi cell in default. */ -/* */ -/* Assumption: */ -/* PASSIVE_LEVEL */ -/* */ -/* Added by Roger, 2010.11.23. */ -/* */ -static void _EfuseCellSel(struct adapter *padapter) -{ - u32 value32; - - value32 = rtw_read32(padapter, EFUSE_TEST); - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0); - rtw_write32(padapter, EFUSE_TEST, value32); -} - -static void Hal_EfuseParseMACAddr_8723BS( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - - if (AutoLoadFail) { - eth_random_addr(pEEPROM->mac_addr); - } else { - /* Read Permanent MAC address */ - memcpy(pEEPROM->mac_addr, &hwinfo[EEPROM_MAC_ADDR_8723BS], ETH_ALEN); - } -} - -static void Hal_EfuseParseBoardType_8723BS( - struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail -) -{ - struct hal_com_data *pHalData = GET_HAL_DATA(padapter); - - if (!AutoLoadFail) { - pHalData->BoardType = (hwinfo[EEPROM_RF_BOARD_OPTION_8723B] & 0xE0) >> 5; - if (pHalData->BoardType == 0xFF) - pHalData->BoardType = (EEPROM_DEFAULT_BOARD_OPTION & 0xE0) >> 5; - } else { - pHalData->BoardType = 0; - } -} - -static void _ReadEfuseInfo8723BS(struct adapter *padapter) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - u8 *hwinfo = NULL; - - /* */ - /* This part read and parse the eeprom/efuse content */ - /* */ - - hwinfo = pEEPROM->efuse_eeprom_data; - - Hal_InitPGData(padapter, hwinfo); - - Hal_EfuseParseIDCode(padapter, hwinfo); - - Hal_EfuseParseMACAddr_8723BS(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - - Hal_EfuseParseTxPowerInfo_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - Hal_EfuseParseBoardType_8723BS(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - - /* */ - /* Read Bluetooth co-exist and initialize */ - /* */ - Hal_EfuseParsePackageType_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - Hal_EfuseParseBTCoexistInfo_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - Hal_EfuseParseChnlPlan_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - Hal_EfuseParseXtal_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - Hal_EfuseParseThermalMeter_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - - Hal_EfuseParseVoltage_8723B(padapter, hwinfo, pEEPROM->bautoload_fail_flag); - - Hal_ReadRFGainOffset(padapter, hwinfo, pEEPROM->bautoload_fail_flag); -} - -static void _ReadPROMContent(struct adapter *padapter) -{ - struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); - u8 eeValue; - - eeValue = rtw_read8(padapter, REG_9346CR); - /* To check system boot selection. */ - pEEPROM->EepromOrEfuse = (eeValue & BOOT_FROM_EEPROM) ? true : false; - pEEPROM->bautoload_fail_flag = (eeValue & EEPROM_EN) ? false : true; - - _ReadEfuseInfo8723BS(padapter); -} - -/* */ -/* Description: */ -/* Read HW adapter information by E-Fuse or EEPROM according CR9346 reported. */ -/* */ -/* Assumption: */ -/* PASSIVE_LEVEL (SDIO interface) */ -/* */ -/* */ -static s32 _ReadAdapterInfo8723BS(struct adapter *padapter) -{ - u8 val8; - - /* before access eFuse, make sure card enable has been called */ - if (!padapter->hw_init_completed) - _InitPowerOn_8723BS(padapter); - - val8 = rtw_read8(padapter, 0x4e); - val8 |= BIT(6); - rtw_write8(padapter, 0x4e, val8); - - _EfuseCellSel(padapter); - _ReadPROMContent(padapter); - - if (!padapter->hw_init_completed) { - /* for BT, Switch Ant control to BT */ - rtw_write8(padapter, 0x67, 0x00); - - /* - * for the power consumption issue, wifi ko module is loaded during booting, - * but wifi GUI is off - */ - CardDisableRTL8723BSdio(padapter); - } - - return _SUCCESS; -} - -void rtw_read_adapter_info(struct adapter *padapter) -{ - /* Read EEPROM size before call any EEPROM function */ - padapter->EepromAddressSize = GetEEPROMSize8723B(padapter); - - _ReadAdapterInfo8723BS(padapter); -} - -/* - * If variable not handled here, - * some variables will be processed in SetHwReg8723B() - */ -void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val) -{ - u8 val8; - - switch (variable) { - case HW_VAR_SET_RPWM: - /* rpwm value only use BIT0(clock bit) , BIT6(Ack bit), and BIT7(Toggle bit) */ - /* BIT0 value - 1: 32k, 0:40MHz. */ - /* BIT6 value - 1: report cpwm value after success set, 0:do not report. */ - /* BIT7 value - Toggle bit change. */ - { - val8 = *val; - val8 &= 0xC1; - rtw_write8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1, val8); - } - break; - case HW_VAR_SET_REQ_FW_PS: - { - u8 req_fw_ps = 0; - - req_fw_ps = rtw_read8(padapter, 0x8f); - req_fw_ps |= 0x10; - rtw_write8(padapter, 0x8f, req_fw_ps); - } - break; - case HW_VAR_RXDMA_AGG_PG_TH: - val8 = *val; - break; - - case HW_VAR_DM_IN_LPS: - rtl8723b_hal_dm_in_lps(padapter); - break; - default: - SetHwReg8723B(padapter, variable, val); - break; - } -} - -/* - * If variable not handled here, - * some variables will be processed in GetHwReg8723B() - */ -void GetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val) -{ - switch (variable) { - case HW_VAR_CPWM: - *val = rtw_read8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HCPWM1_8723B); - break; - - case HW_VAR_FW_PS_STATE: - { - /* 3. read dword 0x88 driver read fw ps state */ - *((u16 *)val) = rtw_read16(padapter, 0x88); - } - break; - default: - GetHwReg8723B(padapter, variable, val); - break; - } -} - -void SetHwRegWithBuf8723B(struct adapter *padapter, u8 variable, u8 *pbuf, int len) -{ - switch (variable) { - case HW_VAR_C2H_HANDLE: - C2HPacketHandler_8723B(padapter, pbuf, len); - break; - default: - break; - } -} - -/* */ -/* Description: */ -/* Query setting of specified variable. */ -/* */ -u8 GetHalDefVar8723BSDIO( - struct adapter *Adapter, enum hal_def_variable eVariable, void *pValue -) -{ - u8 bResult = _SUCCESS; - - switch (eVariable) { - case HAL_DEF_IS_SUPPORT_ANT_DIV: - break; - case HAL_DEF_CURRENT_ANTENNA: - break; - case HW_VAR_MAX_RX_AMPDU_FACTOR: - /* Stanley@BB.SD3 suggests 16K can get stable performance */ - /* coding by Lucas@20130730 */ - *(u32 *)pValue = IEEE80211_HT_MAX_AMPDU_16K; - break; - default: - bResult = GetHalDefVar8723B(Adapter, eVariable, pValue); - break; - } - - return bResult; -} diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c deleted file mode 100644 index da2d9088ab5a..000000000000 --- a/drivers/staging/rtl8723bs/hal/sdio_ops.c +++ /dev/null @@ -1,859 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - *******************************************************************************/ -#include -#include - -/* */ -/* Description: */ -/* The following mapping is for SDIO host local register space. */ -/* */ -/* Creadted by Roger, 2011.01.31. */ -/* */ -static void hal_sdio_get_cmd_addr_8723b(struct adapter *adapter, u8 device_id, - u32 addr, u32 *cmdaddr) -{ - switch (device_id) { - case SDIO_LOCAL_DEVICE_ID: - *cmdaddr = ((SDIO_LOCAL_DEVICE_ID << 13) | (addr & SDIO_LOCAL_MSK)); - break; - - case WLAN_IOREG_DEVICE_ID: - *cmdaddr = ((WLAN_IOREG_DEVICE_ID << 13) | (addr & WLAN_IOREG_MSK)); - break; - - case WLAN_TX_HIQ_DEVICE_ID: - *cmdaddr = ((WLAN_TX_HIQ_DEVICE_ID << 13) | (addr & WLAN_FIFO_MSK)); - break; - - case WLAN_TX_MIQ_DEVICE_ID: - *cmdaddr = ((WLAN_TX_MIQ_DEVICE_ID << 13) | (addr & WLAN_FIFO_MSK)); - break; - - case WLAN_TX_LOQ_DEVICE_ID: - *cmdaddr = ((WLAN_TX_LOQ_DEVICE_ID << 13) | (addr & WLAN_FIFO_MSK)); - break; - - case WLAN_RX0FF_DEVICE_ID: - *cmdaddr = ((WLAN_RX0FF_DEVICE_ID << 13) | (addr & WLAN_RX0FF_MSK)); - break; - - default: - break; - } -} - -static u8 get_deviceid(u32 addr) -{ - u8 devide_id; - u16 pseudo_id; - - pseudo_id = (u16)(addr >> 16); - switch (pseudo_id) { - case 0x1025: - devide_id = SDIO_LOCAL_DEVICE_ID; - break; - - case 0x1026: - devide_id = WLAN_IOREG_DEVICE_ID; - break; - - case 0x1031: - devide_id = WLAN_TX_HIQ_DEVICE_ID; - break; - - case 0x1032: - devide_id = WLAN_TX_MIQ_DEVICE_ID; - break; - - case 0x1033: - devide_id = WLAN_TX_LOQ_DEVICE_ID; - break; - - case 0x1034: - devide_id = WLAN_RX0FF_DEVICE_ID; - break; - - default: - devide_id = WLAN_IOREG_DEVICE_ID; - break; - } - - return devide_id; -} - -static u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset) -{ - u8 device_id; - u16 offset; - u32 ftaddr; - - device_id = get_deviceid(addr); - offset = 0; - - switch (device_id) { - case SDIO_LOCAL_DEVICE_ID: - offset = addr & SDIO_LOCAL_MSK; - break; - - case WLAN_TX_HIQ_DEVICE_ID: - case WLAN_TX_MIQ_DEVICE_ID: - case WLAN_TX_LOQ_DEVICE_ID: - offset = addr & WLAN_FIFO_MSK; - break; - - case WLAN_RX0FF_DEVICE_ID: - offset = addr & WLAN_RX0FF_MSK; - break; - - case WLAN_IOREG_DEVICE_ID: - default: - device_id = WLAN_IOREG_DEVICE_ID; - offset = addr & WLAN_IOREG_MSK; - break; - } - ftaddr = (device_id << 13) | offset; - - if (pdevice_id) - *pdevice_id = device_id; - if (poffset) - *poffset = offset; - - return ftaddr; -} - -static u8 sdio_read8(struct intf_hdl *intfhdl, u32 addr) -{ - u32 ftaddr; - - ftaddr = _cvrt2ftaddr(addr, NULL, NULL); - - return sd_read8(intfhdl, ftaddr, NULL); -} - -static u16 sdio_read16(struct intf_hdl *intfhdl, u32 addr) -{ - u32 ftaddr; - __le16 le_tmp; - - ftaddr = _cvrt2ftaddr(addr, NULL, NULL); - sd_cmd52_read(intfhdl, ftaddr, 2, (u8 *)&le_tmp); - - return le16_to_cpu(le_tmp); -} - -static u32 sdio_read32(struct intf_hdl *intfhdl, u32 addr) -{ - struct adapter *adapter; - u8 mac_pwr_ctrl_on; - u8 device_id; - u16 offset; - u32 ftaddr; - u8 shift; - u32 val; - s32 __maybe_unused err; - __le32 le_tmp; - - adapter = intfhdl->padapter; - ftaddr = _cvrt2ftaddr(addr, &device_id, &offset); - - rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on); - if ( - ((device_id == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) || - (!mac_pwr_ctrl_on) || - (adapter_to_pwrctl(adapter)->fw_current_in_ps_mode) - ) { - err = sd_cmd52_read(intfhdl, ftaddr, 4, (u8 *)&le_tmp); - return le32_to_cpu(le_tmp); - } - - /* 4 bytes alignment */ - shift = ftaddr & 0x3; - if (shift == 0) { - val = sd_read32(intfhdl, ftaddr, NULL); - } else { - u8 *tmpbuf; - - tmpbuf = kmalloc(8, GFP_ATOMIC); - if (!tmpbuf) - return SDIO_ERR_VAL32; - - ftaddr &= ~(u16)0x3; - sd_read(intfhdl, ftaddr, 8, tmpbuf); - memcpy(&le_tmp, tmpbuf + shift, 4); - val = le32_to_cpu(le_tmp); - - kfree(tmpbuf); - } - return val; -} - -static s32 sdio_write8(struct intf_hdl *intfhdl, u32 addr, u8 val) -{ - u32 ftaddr; - s32 err; - - ftaddr = _cvrt2ftaddr(addr, NULL, NULL); - sd_write8(intfhdl, ftaddr, val, &err); - - return err; -} - -static s32 sdio_write16(struct intf_hdl *intfhdl, u32 addr, u16 val) -{ - u32 ftaddr; - __le16 le_tmp; - - ftaddr = _cvrt2ftaddr(addr, NULL, NULL); - le_tmp = cpu_to_le16(val); - return sd_cmd52_write(intfhdl, ftaddr, 2, (u8 *)&le_tmp); -} - -static s32 sdio_write32(struct intf_hdl *intfhdl, u32 addr, u32 val) -{ - struct adapter *adapter; - u8 mac_pwr_ctrl_on; - u8 device_id; - u16 offset; - u32 ftaddr; - u8 shift; - s32 err; - __le32 le_tmp; - - adapter = intfhdl->padapter; - err = 0; - - ftaddr = _cvrt2ftaddr(addr, &device_id, &offset); - - rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on); - if ( - ((device_id == WLAN_IOREG_DEVICE_ID) && (offset < 0x100)) || - (!mac_pwr_ctrl_on) || - (adapter_to_pwrctl(adapter)->fw_current_in_ps_mode) - ) { - le_tmp = cpu_to_le32(val); - - return sd_cmd52_write(intfhdl, ftaddr, 4, (u8 *)&le_tmp); - } - - /* 4 bytes alignment */ - shift = ftaddr & 0x3; - if (shift == 0) { - sd_write32(intfhdl, ftaddr, val, &err); - } else { - le_tmp = cpu_to_le32(val); - err = sd_cmd52_write(intfhdl, ftaddr, 4, (u8 *)&le_tmp); - } - return err; -} - -/* - * Description: - *Read from RX FIFO - *Round read size to block size, - *and make sure data transfer will be done in one command. - * - * Parameters: - *intfhdl a pointer of intf_hdl - *addr port ID - *cnt size to read - *rmem address to put data - * - * Return: - *_SUCCESS(1) Success - *_FAIL(0) Fail - */ -static u32 sdio_read_port( - struct intf_hdl *intfhdl, - u32 addr, - u32 cnt, - u8 *mem -) -{ - struct adapter *adapter; - struct sdio_data *psdio; - struct hal_com_data *hal; - s32 err; - - adapter = intfhdl->padapter; - psdio = &adapter_to_dvobj(adapter)->intf_data; - hal = GET_HAL_DATA(adapter); - - hal_sdio_get_cmd_addr_8723b(adapter, addr, hal->SdioRxFIFOCnt++, &addr); - - if (cnt > psdio->block_transfer_len) - cnt = _RND(cnt, psdio->block_transfer_len); - - err = _sd_read(intfhdl, addr, cnt, mem); - - if (err) - return _FAIL; - return _SUCCESS; -} - -/* - * Description: - *Write to TX FIFO - *Align write size block size, - *and make sure data could be written in one command. - * - * Parameters: - *intfhdl a pointer of intf_hdl - *addr port ID - *cnt size to write - *wmem data pointer to write - * - * Return: - *_SUCCESS(1) Success - *_FAIL(0) Fail - */ -static u32 sdio_write_port( - struct intf_hdl *intfhdl, - u32 addr, - u32 cnt, - u8 *mem -) -{ - struct adapter *adapter; - struct sdio_data *psdio; - s32 err; - struct xmit_buf *xmitbuf = (struct xmit_buf *)mem; - - adapter = intfhdl->padapter; - psdio = &adapter_to_dvobj(adapter)->intf_data; - - if (!adapter->hw_init_completed) - return _FAIL; - - cnt = round_up(cnt, 4); - hal_sdio_get_cmd_addr_8723b(adapter, addr, cnt >> 2, &addr); - - if (cnt > psdio->block_transfer_len) - cnt = _RND(cnt, psdio->block_transfer_len); - - err = sd_write(intfhdl, addr, cnt, xmitbuf->pdata); - - rtw_sctx_done_err( - &xmitbuf->sctx, - err ? RTW_SCTX_DONE_WRITE_PORT_ERR : RTW_SCTX_DONE_SUCCESS - ); - - if (err) - return _FAIL; - return _SUCCESS; -} - -void sdio_set_intf_ops(struct adapter *adapter, struct _io_ops *ops) -{ - ops->_read8 = &sdio_read8; - ops->_read16 = &sdio_read16; - ops->_read32 = &sdio_read32; - - ops->_write8 = &sdio_write8; - ops->_write16 = &sdio_write16; - ops->_write32 = &sdio_write32; - ops->_write_port = &sdio_write_port; -} - -/* - * Todo: align address to 4 bytes. - */ -static s32 _sdio_local_read( - struct adapter *adapter, - u32 addr, - u32 cnt, - u8 *buf -) -{ - struct intf_hdl *intfhdl; - u8 mac_pwr_ctrl_on; - s32 err; - u8 *tmpbuf; - u32 n; - - intfhdl = &adapter->iopriv.intf; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - - rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on); - if (!mac_pwr_ctrl_on) - return _sd_cmd52_read(intfhdl, addr, cnt, buf); - - n = round_up(cnt, 4); - tmpbuf = kmalloc(n, GFP_ATOMIC); - if (!tmpbuf) - return -ENOMEM; - - err = _sd_read(intfhdl, addr, n, tmpbuf); - if (!err) - memcpy(buf, tmpbuf, cnt); - - kfree(tmpbuf); - - return err; -} - -/* - * Todo: align address to 4 bytes. - */ -s32 sdio_local_read( - struct adapter *adapter, - u32 addr, - u32 cnt, - u8 *buf -) -{ - struct intf_hdl *intfhdl; - u8 mac_pwr_ctrl_on; - s32 err; - u8 *tmpbuf; - u32 n; - - intfhdl = &adapter->iopriv.intf; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - - rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on); - if ( - (!mac_pwr_ctrl_on) || - (adapter_to_pwrctl(adapter)->fw_current_in_ps_mode) - ) - return sd_cmd52_read(intfhdl, addr, cnt, buf); - - n = round_up(cnt, 4); - tmpbuf = kmalloc(n, GFP_ATOMIC); - if (!tmpbuf) - return -ENOMEM; - - err = sd_read(intfhdl, addr, n, tmpbuf); - if (!err) - memcpy(buf, tmpbuf, cnt); - - kfree(tmpbuf); - - return err; -} - -/* - * Todo: align address to 4 bytes. - */ -s32 sdio_local_write( - struct adapter *adapter, - u32 addr, - u32 cnt, - u8 *buf -) -{ - struct intf_hdl *intfhdl; - u8 mac_pwr_ctrl_on; - s32 err; - u8 *tmpbuf; - - intfhdl = &adapter->iopriv.intf; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - - rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on); - if ( - (!mac_pwr_ctrl_on) || - (adapter_to_pwrctl(adapter)->fw_current_in_ps_mode) - ) - return sd_cmd52_write(intfhdl, addr, cnt, buf); - - tmpbuf = kmemdup(buf, cnt, GFP_ATOMIC); - if (!tmpbuf) - return -ENOMEM; - - err = sd_write(intfhdl, addr, cnt, tmpbuf); - - kfree(tmpbuf); - - return err; -} - -u8 SdioLocalCmd52Read1Byte(struct adapter *adapter, u32 addr) -{ - u8 val = 0; - struct intf_hdl *intfhdl = &adapter->iopriv.intf; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - sd_cmd52_read(intfhdl, addr, 1, &val); - - return val; -} - -static u16 sdio_local_cmd52_read2byte(struct adapter *adapter, u32 addr) -{ - __le16 val = 0; - struct intf_hdl *intfhdl = &adapter->iopriv.intf; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - sd_cmd52_read(intfhdl, addr, 2, (u8 *)&val); - - return le16_to_cpu(val); -} - -static u32 sdio_local_cmd53_read4byte(struct adapter *adapter, u32 addr) -{ - - u8 mac_pwr_ctrl_on; - u32 val = 0; - struct intf_hdl *intfhdl = &adapter->iopriv.intf; - __le32 le_tmp; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - rtw_hal_get_hwreg(adapter, HW_VAR_APFM_ON_MAC, &mac_pwr_ctrl_on); - if (!mac_pwr_ctrl_on || adapter_to_pwrctl(adapter)->fw_current_in_ps_mode) { - sd_cmd52_read(intfhdl, addr, 4, (u8 *)&le_tmp); - val = le32_to_cpu(le_tmp); - } else { - val = sd_read32(intfhdl, addr, NULL); - } - return val; -} - -void SdioLocalCmd52Write1Byte(struct adapter *adapter, u32 addr, u8 v) -{ - struct intf_hdl *intfhdl = &adapter->iopriv.intf; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - sd_cmd52_write(intfhdl, addr, 1, &v); -} - -static void sdio_local_cmd52_write4byte(struct adapter *adapter, u32 addr, u32 v) -{ - struct intf_hdl *intfhdl = &adapter->iopriv.intf; - __le32 le_tmp; - - hal_sdio_get_cmd_addr_8723b(adapter, SDIO_LOCAL_DEVICE_ID, addr, &addr); - le_tmp = cpu_to_le32(v); - sd_cmd52_write(intfhdl, addr, 4, (u8 *)&le_tmp); -} - -static s32 read_interrupt_8723b_sdio(struct adapter *adapter, u32 *phisr) -{ - u32 hisr, himr; - u8 val8, hisr_len; - - if (!phisr) - return false; - - himr = GET_HAL_DATA(adapter)->sdio_himr; - - /* decide how many bytes need to be read */ - hisr_len = 0; - while (himr) { - hisr_len++; - himr >>= 8; - } - - hisr = 0; - while (hisr_len != 0) { - hisr_len--; - val8 = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_HISR + hisr_len); - hisr |= (val8 << (8 * hisr_len)); - } - - *phisr = hisr; - - return true; -} - -/* */ -/* Description: */ -/* Initialize SDIO Host Interrupt Mask configuration variables for future use. */ -/* */ -/* Assumption: */ -/* Using SDIO Local register ONLY for configuration. */ -/* */ -/* Created by Roger, 2011.02.11. */ -/* */ -void InitInterrupt8723BSdio(struct adapter *adapter) -{ - struct hal_com_data *haldata; - - haldata = GET_HAL_DATA(adapter); - haldata->sdio_himr = (u32)(SDIO_HIMR_RX_REQUEST_MSK | - SDIO_HIMR_AVAL_MSK | - 0); -} - -/* - * Enable SDIO Host Interrupt Mask configuration on SDIO local domain. - * - * Assumption: - * 1. Using SDIO Local register ONLY for configuration. - * 2. PASSIVE LEVEL - */ -void rtw_sdio_enable_interrupt(struct adapter *adapter) -{ - struct hal_com_data *haldata; - __le32 himr; - - haldata = GET_HAL_DATA(adapter); - - himr = cpu_to_le32(haldata->sdio_himr); - sdio_local_write(adapter, SDIO_REG_HIMR, 4, (u8 *)&himr); - - /* */ - /* There are some C2H CMDs have been sent before system interrupt is enabled, e.g., C2H, CPWM. */ - /* So we need to clear all C2H events that FW has notified, otherwise FW won't schedule any commands anymore. */ - /* 2011.10.19. */ - /* */ - rtw_write8(adapter, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE); -} - -/* - * Disable SDIO Host IMR configuration to mask unnecessary interrupt service. - * - * Assumption: - * Using SDIO Local register ONLY for configuration. - */ -void rtw_sdio_disable_interrupt(struct adapter *adapter) -{ - __le32 himr; - - himr = cpu_to_le32(SDIO_HIMR_DISABLED); - sdio_local_write(adapter, SDIO_REG_HIMR, 4, (u8 *)&himr); -} - -/* */ -/* Description: */ -/* Using 0x100 to check the power status of FW. */ -/* */ -/* Assumption: */ -/* Using SDIO Local register ONLY for configuration. */ -/* */ -/* Created by Isaac, 2013.09.10. */ -/* */ -u8 CheckIPSStatus(struct adapter *adapter) -{ - if (rtw_read8(adapter, 0x100) == 0xEA) - return true; - else - return false; -} - -static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size) -{ - u32 readsize, ret; - u8 *readbuf; - struct recv_priv *recv_priv; - struct recv_buf *recvbuf; - - /* Patch for some SDIO Host 4 bytes issue */ - /* ex. RK3188 */ - readsize = round_up(size, 4); - - /* 3 1. alloc recvbuf */ - recv_priv = &adapter->recvpriv; - recvbuf = rtw_dequeue_recvbuf(&recv_priv->free_recv_buf_queue); - if (!recvbuf) { - netdev_err(adapter->pnetdev, "%s: alloc recvbuf FAIL!\n", - __func__); - return NULL; - } - - /* 3 2. alloc skb */ - if (!recvbuf->pskb) { - SIZE_PTR tmpaddr = 0; - SIZE_PTR alignment = 0; - - recvbuf->pskb = __dev_alloc_skb(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ, GFP_ATOMIC); - if (!recvbuf->pskb) - return NULL; - - recvbuf->pskb->dev = adapter->pnetdev; - - tmpaddr = (SIZE_PTR)recvbuf->pskb->data; - alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1); - skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment)); - } - - /* 3 3. read data from rxfifo */ - readbuf = recvbuf->pskb->data; - ret = sdio_read_port(&adapter->iopriv.intf, WLAN_RX0FF_DEVICE_ID, readsize, readbuf); - if (ret == _FAIL) - return NULL; - - /* 3 4. init recvbuf */ - recvbuf->len = size; - recvbuf->phead = recvbuf->pskb->head; - recvbuf->pdata = recvbuf->pskb->data; - skb_set_tail_pointer(recvbuf->pskb, size); - recvbuf->ptail = skb_tail_pointer(recvbuf->pskb); - recvbuf->pend = skb_end_pointer(recvbuf->pskb); - - return recvbuf; -} - -static void sd_rxhandler(struct adapter *adapter, struct recv_buf *recvbuf) -{ - struct recv_priv *recv_priv; - struct __queue *pending_queue; - - recv_priv = &adapter->recvpriv; - pending_queue = &recv_priv->recv_buf_pending_queue; - - /* 3 1. enqueue recvbuf */ - rtw_enqueue_recvbuf(recvbuf, pending_queue); - - /* 3 2. schedule tasklet */ - tasklet_schedule(&recv_priv->recv_tasklet); -} - -void sd_int_dpc(struct adapter *adapter) -{ - struct hal_com_data *hal; - struct dvobj_priv *dvobj; - struct intf_hdl *intfhdl = &adapter->iopriv.intf; - struct pwrctrl_priv *pwrctl; - - hal = GET_HAL_DATA(adapter); - dvobj = adapter_to_dvobj(adapter); - pwrctl = dvobj_to_pwrctl(dvobj); - - if (hal->sdio_hisr & SDIO_HISR_AVAL) { - u8 freepage[4]; - - _sdio_local_read(adapter, SDIO_REG_FREE_TXPG, 4, freepage); - complete(&(adapter->xmitpriv.xmit_comp)); - } - - if (hal->sdio_hisr & SDIO_HISR_CPWM1) { - timer_delete_sync(&(pwrctl->pwr_rpwm_timer)); - - SdioLocalCmd52Read1Byte(adapter, SDIO_REG_HCPWM1_8723B); - - _set_workitem(&(pwrctl->cpwm_event)); - } - - if (hal->sdio_hisr & SDIO_HISR_TXERR) { - u8 *status; - u32 addr; - - status = kmalloc(4, GFP_ATOMIC); - if (status) { - addr = REG_TXDMA_STATUS; - hal_sdio_get_cmd_addr_8723b(adapter, WLAN_IOREG_DEVICE_ID, addr, &addr); - _sd_read(intfhdl, addr, 4, status); - _sd_write(intfhdl, addr, 4, status); - kfree(status); - } - } - - if (hal->sdio_hisr & SDIO_HISR_C2HCMD) { - struct c2h_evt_hdr_88xx *c2h_evt; - - c2h_evt = kzalloc(16, GFP_ATOMIC); - if (c2h_evt) { - if (c2h_evt_read_88xx(adapter, (u8 *)c2h_evt) == _SUCCESS) { - if (c2h_id_filter_ccx_8723b((u8 *)c2h_evt)) { - /* Handle CCX report here */ - rtw_hal_c2h_handler(adapter, (u8 *)c2h_evt); - kfree(c2h_evt); - } else { - rtw_c2h_wk_cmd(adapter, (u8 *)c2h_evt); - } - } else { - kfree(c2h_evt); - } - } else { - /* Error handling for malloc fail */ - rtw_cbuf_push(adapter->evtpriv.c2h_queue, NULL); - _set_workitem(&adapter->evtpriv.c2h_wk); - } - } - - if (hal->sdio_hisr & SDIO_HISR_RX_REQUEST) { - struct recv_buf *recvbuf; - int alloc_fail_time = 0; - u32 hisr; - - hal->sdio_hisr ^= SDIO_HISR_RX_REQUEST; - do { - hal->SdioRxFIFOSize = sdio_local_cmd52_read2byte(adapter, SDIO_REG_RX0_REQ_LEN); - if (hal->SdioRxFIFOSize != 0) { - recvbuf = sd_recv_rxfifo(adapter, hal->SdioRxFIFOSize); - if (recvbuf) - sd_rxhandler(adapter, recvbuf); - else { - alloc_fail_time++; - if (alloc_fail_time >= 10) - break; - } - hal->SdioRxFIFOSize = 0; - } else - break; - - hisr = 0; - read_interrupt_8723b_sdio(adapter, &hisr); - hisr &= SDIO_HISR_RX_REQUEST; - if (!hisr) - break; - } while (1); - } -} - -void sd_int_hdl(struct adapter *adapter) -{ - struct hal_com_data *hal; - - if ( - (adapter->driver_stopped) || (adapter->bSurpriseRemoved) - ) - return; - - hal = GET_HAL_DATA(adapter); - - hal->sdio_hisr = 0; - read_interrupt_8723b_sdio(adapter, &hal->sdio_hisr); - - if (hal->sdio_hisr & hal->sdio_himr) { - u32 v32; - - hal->sdio_hisr &= hal->sdio_himr; - - /* clear HISR */ - v32 = hal->sdio_hisr & MASK_SDIO_HISR_CLEAR; - if (v32) - sdio_local_cmd52_write4byte(adapter, SDIO_REG_HISR, v32); - - sd_int_dpc(adapter); - } -} - -/* */ -/* Description: */ -/* Query SDIO Local register to query current the number of Free TxPacketBuffer page. */ -/* */ -/* Assumption: */ -/* 1. Running at PASSIVE_LEVEL */ -/* 2. RT_TX_SPINLOCK is NOT acquired. */ -/* */ -/* Created by Roger, 2011.01.28. */ -/* */ -u8 HalQueryTxBufferStatus8723BSdio(struct adapter *adapter) -{ - struct hal_com_data *hal; - u32 numof_free_page; - - hal = GET_HAL_DATA(adapter); - - numof_free_page = sdio_local_cmd53_read4byte(adapter, SDIO_REG_FREE_TXPG); - - memcpy(hal->SdioTxFIFOFreePage, &numof_free_page, 4); - - return true; -} - -/* Read the TX OQT free page count from the SDIO local register. */ -void HalQueryTxOQTBufferStatus8723BSdio(struct adapter *adapter) -{ - struct hal_com_data *haldata = GET_HAL_DATA(adapter); - - haldata->SdioTxOQTFreeSpace = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_OQT_FREE_PG); -} diff --git a/drivers/staging/rtl8723bs/include/Hal8192CPhyReg.h b/drivers/staging/rtl8723bs/include/Hal8192CPhyReg.h deleted file mode 100644 index f8cf2aee5157..000000000000 --- a/drivers/staging/rtl8723bs/include/Hal8192CPhyReg.h +++ /dev/null @@ -1,232 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/***************************************************************************** - * - * Module: __INC_HAL8192CPHYREG_H - * - * - * Note: 1. Define PMAC/BB register map - * 2. Define RF register map - * 3. PMAC/BB register bit mask. - * 4. RF reg bit mask. - * 5. Other BB/RF relative definition. - * - * - * Export: Constants, macro, functions(API), global variables(None). - * - * Abbrev: - * - * History: - * Data Who Remark - * 08/07/2007 MHC 1. Porting from 9x series PHYCFG.h. - * 2. Reorganize code architecture. - *09/25/2008 MH 1. Add RL6052 register definition - * - *****************************************************************************/ -#ifndef __INC_HAL8192CPHYREG_H -#define __INC_HAL8192CPHYREG_H - - -/*--------------------------Define Parameters-------------------------------*/ - -/* */ -/* 8192S Register offset definition */ -/* */ - -/* */ -/* BB-PHY register PMAC 0x100 PHY 0x800 - 0xEFF */ -/* 1. PMAC duplicate register due to connection: RF_Mode, TRxRN, NumOf L-STF */ -/* 2. 0x800/0x900/0xA00/0xC00/0xD00/0xE00 */ -/* 3. RF register 0x00-2E */ -/* 4. Bit Mask for BB/RF register */ -/* 5. Other definition for BB/RF R/W */ -/* */ - -/* */ -/* 3. Page8(0x800) */ -/* */ -#define rFPGA0_RFMOD 0x800 /* RF mode & CCK TxSC RF BW Setting?? */ - -#define rFPGA0_XA_HSSIParameter1 0x820 /* RF 3 wire register */ -#define rFPGA0_XA_HSSIParameter2 0x824 -#define rFPGA0_XB_HSSIParameter1 0x828 -#define rFPGA0_XB_HSSIParameter2 0x82c -#define rTxAGC_B_Rate18_06 0x830 -#define rTxAGC_B_Rate54_24 0x834 -#define rTxAGC_B_CCK1_55_Mcs32 0x838 -#define rTxAGC_B_Mcs03_Mcs00 0x83c - -#define rTxAGC_B_Mcs07_Mcs04 0x848 - -#define rFPGA0_XA_LSSIParameter 0x840 -#define rFPGA0_XB_LSSIParameter 0x844 - -#define rFPGA0_XCD_SwitchControl 0x85c - -#define rFPGA0_XA_RFInterfaceOE 0x860 /* RF Channel switch */ -#define rFPGA0_XB_RFInterfaceOE 0x864 - -#define rTxAGC_B_CCK11_A_CCK2_11 0x86c - -#define rFPGA0_XAB_RFInterfaceSW 0x870 /* RF Interface Software Control */ -#define rFPGA0_XCD_RFInterfaceSW 0x874 - -#define rFPGA0_XA_LSSIReadBack 0x8a0 /* Transceiver LSSI Readback */ -#define rFPGA0_XB_LSSIReadBack 0x8a4 - -#define TransceiverA_HSPI_Readback 0x8b8 /* Transceiver A HSPI Readback */ -#define TransceiverB_HSPI_Readback 0x8bc /* Transceiver B HSPI Readback */ - -/* */ -/* 4. Page9(0x900) */ -/* */ -#define rFPGA1_RFMOD 0x900 /* RF mode & OFDM TxSC RF BW Setting?? */ - -#define rS0S1_PathSwitch 0x948 - -/* */ -/* 5. PageA(0xA00) */ -/* */ -/* Set Control channel to upper or lower. These settings are required only for 40MHz */ -#define rCCK0_System 0xa00 - -#define rCCK0_AFESetting 0xa04 /* Disable init gain now Select RX path by RSSI */ - -/* */ -/* PageB(0xB00) */ -/* */ -#define rConfig_AntA 0xb68 -#define rConfig_AntB 0xb6c - -/* */ -/* 6. PageC(0xC00) */ -/* */ -#define rOFDM0_TRxPathEnable 0xc04 -#define rOFDM0_TRMuxPar 0xc08 - -#define rOFDM0_XARxIQImbalance 0xc14 /* RxIQ imbalance matrix */ -#define rOFDM0_XBRxIQImbalance 0xc1c - -#define rOFDM0_RxDSP 0xc40 /* Rx Sync Path */ -#define rOFDM0_ECCAThreshold 0xc4c /* energy CCA */ - -#define rOFDM0_AGCRSSITable 0xc78 - -#define rOFDM0_XATxIQImbalance 0xc80 /* TX PWR TRACK and DIG */ -#define rOFDM0_XBTxIQImbalance 0xc88 -#define rOFDM0_XCTxAFE 0xc94 -#define rOFDM0_XDTxAFE 0xc9c - -#define rOFDM0_RxIQExtAnta 0xca0 -#define rOFDM0_TxPseudoNoiseWgt 0xce4 - -/* */ -/* 7. PageD(0xD00) */ -/* */ -#define rOFDM1_LSTF 0xd00 - -/* */ -/* 8. PageE(0xE00) */ -/* */ -#define rTxAGC_A_Rate18_06 0xe00 -#define rTxAGC_A_Rate54_24 0xe04 -#define rTxAGC_A_CCK1_Mcs32 0xe08 -#define rTxAGC_A_Mcs03_Mcs00 0xe10 -#define rTxAGC_A_Mcs07_Mcs04 0xe14 - -#define rFPGA0_IQK 0xe28 -#define rTx_IQK_Tone_A 0xe30 -#define rRx_IQK_Tone_A 0xe34 -#define rTx_IQK_PI_A 0xe38 -#define rRx_IQK_PI_A 0xe3c - -#define rTx_IQK 0xe40 -#define rRx_IQK 0xe44 -#define rIQK_AGC_Pts 0xe48 -#define rIQK_AGC_Rsp 0xe4c -#define rTx_IQK_Tone_B 0xe50 -#define rRx_IQK_Tone_B 0xe54 -#define rTx_IQK_PI_B 0xe58 -#define rRx_IQK_PI_B 0xe5c - -#define rBlue_Tooth 0xe6c -#define rRx_Wait_CCA 0xe70 -#define rTx_CCK_RFON 0xe74 -#define rTx_CCK_BBON 0xe78 -#define rTx_OFDM_RFON 0xe7c -#define rTx_OFDM_BBON 0xe80 -#define rTx_To_Rx 0xe84 -#define rTx_To_Tx 0xe88 -#define rRx_CCK 0xe8c - -#define rTx_Power_Before_IQK_A 0xe94 -#define rTx_Power_After_IQK_A 0xe9c - -#define rRx_Power_Before_IQK_A_2 0xea4 -#define rRx_Power_After_IQK_A_2 0xeac - -#define rRx_OFDM 0xed0 -#define rRx_Wait_RIFS 0xed4 -#define rRx_TO_Rx 0xed8 -#define rStandby 0xedc -#define rSleep 0xee0 -#define rPMPD_ANAEN 0xeec - -/* */ -/* RL6052 Register definition */ -/* */ -#define RF_AC 0x00 /* */ - -#define RF_TXM_IDAC 0x08 /* */ - -#define RF_CHNLBW 0x18 /* RF channel and BW switch */ - -#define RF_RCK_OS 0x30 /* RF TX PA control */ - -#define RF_TXPA_G1 0x31 /* RF TX PA control */ -#define RF_TXPA_G2 0x32 /* RF TX PA control */ - -#define RF_WE_LUT 0xEF - -/* 2. Page8(0x800) */ -#define bRFMOD 0x1 /* Reg 0x800 rFPGA0_RFMOD */ - -#define b3WireDataLength 0x800 /* Reg 0x820~84f rFPGA0_XA_HSSIParameter1 */ -#define b3WireAddressLength 0x400 - -#define bRFSI_RFENV 0x10 /* Reg 0x870 rFPGA0_XAB_RFInterfaceSW */ - -#define bLSSIReadAddress 0x7f800000 /* T65 RF */ - -#define bLSSIReadEdge 0x80000000 /* LSSI "Read" edge signal */ - -#define bLSSIReadBackData 0xfffff /* T65 RF */ - -/* 4. PageA(0xA00) */ -#define bCCKSideBand 0x10 /* Reg 0xa00 rCCK0_System 20/40 switch */ - -/* */ -/* Other Definition */ -/* */ - -/* for PutRegsetting & GetRegSetting BitMask */ -#define bMaskByte0 0xff /* Reg 0xc50 rOFDM0_XAAGCCore~0xC6f */ -#define bMaskByte1 0xff00 -#define bMaskByte2 0xff0000 -#define bMaskByte3 0xff000000 -#define bMaskHWord 0xffff0000 -#define bMaskLWord 0x0000ffff -#define bMaskDWord 0xffffffff -#define bMaskH3Bytes 0xffffff00 -#define bMask12Bits 0xfff -#define bMaskH4Bits 0xf0000000 - -#define bEnable 0x1 /* Useless */ - -#define rDPDT_control 0x92c - -#endif /* __INC_HAL8192SPHYREG_H */ diff --git a/drivers/staging/rtl8723bs/include/HalPwrSeqCmd.h b/drivers/staging/rtl8723bs/include/HalPwrSeqCmd.h deleted file mode 100644 index b81252d374ef..000000000000 --- a/drivers/staging/rtl8723bs/include/HalPwrSeqCmd.h +++ /dev/null @@ -1,111 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HALPWRSEQCMD_H__ -#define __HALPWRSEQCMD_H__ - -#include - -/*---------------------------------------------*/ -/* 3 The value of cmd: 4 bits */ -/*---------------------------------------------*/ -#define PWR_CMD_READ 0x00 - /* offset: the read register offset */ - /* msk: the mask of the read value */ - /* value: N/A, left by 0 */ - /* note: dirver shall implement this function by read & msk */ - -#define PWR_CMD_WRITE 0x01 - /* offset: the read register offset */ - /* msk: the mask of the write bits */ - /* value: write value */ - /* note: driver shall implement this cmd by read & msk after write */ - -#define PWR_CMD_POLLING 0x02 - /* offset: the read register offset */ - /* msk: the mask of the polled value */ - /* value: the value to be polled, masked by the msd field. */ - /* note: driver shall implement this cmd by */ - /* do{ */ - /* if ((Read(offset) & msk) == (value & msk)) */ - /* break; */ - /* } while (not timeout); */ - -#define PWR_CMD_DELAY 0x03 - /* offset: the value to delay */ - /* msk: N/A */ - /* value: the unit of delay, 0: us, 1: ms */ - -#define PWR_CMD_END 0x04 - /* offset: N/A */ - /* msk: N/A */ - /* value: N/A */ - -/*---------------------------------------------*/ -/* 3 The value of base: 4 bits */ -/*---------------------------------------------*/ - /* define the base address of each block */ -#define PWR_BASEADDR_MAC 0x00 -#define PWR_BASEADDR_SDIO 0x03 - -/*---------------------------------------------*/ -/* 3 The value of interface_msk: 4 bits */ -/*---------------------------------------------*/ -#define PWR_INTF_SDIO_MSK BIT(0) -#define PWR_INTF_USB_MSK BIT(1) -#define PWR_INTF_PCI_MSK BIT(2) -#define PWR_INTF_ALL_MSK (BIT(0)|BIT(1)|BIT(2)|BIT(3)) - -/*---------------------------------------------*/ -/* 3 The value of fab_msk: 4 bits */ -/*---------------------------------------------*/ -#define PWR_FAB_ALL_MSK (BIT(0)|BIT(1)|BIT(2)|BIT(3)) - -/*---------------------------------------------*/ -/* 3 The value of cut_msk: 8 bits */ -/*---------------------------------------------*/ -#define PWR_CUT_TESTCHIP_MSK BIT(0) -#define PWR_CUT_ALL_MSK 0xFF - - -enum { - PWRSEQ_DELAY_US, - PWRSEQ_DELAY_MS, -}; - -struct wlan_pwr_cfg { - u16 offset; - u8 cut_msk; - u8 fab_msk:4; - u8 interface_msk:4; - u8 base:4; - u8 cmd:4; - u8 msk; - u8 value; -}; - - -#define GET_PWR_CFG_OFFSET(__PWR_CMD) __PWR_CMD.offset -#define GET_PWR_CFG_CUT_MASK(__PWR_CMD) __PWR_CMD.cut_msk -#define GET_PWR_CFG_FAB_MASK(__PWR_CMD) __PWR_CMD.fab_msk -#define GET_PWR_CFG_INTF_MASK(__PWR_CMD) __PWR_CMD.interface_msk -#define GET_PWR_CFG_BASE(__PWR_CMD) __PWR_CMD.base -#define GET_PWR_CFG_CMD(__PWR_CMD) __PWR_CMD.cmd -#define GET_PWR_CFG_MASK(__PWR_CMD) __PWR_CMD.msk -#define GET_PWR_CFG_VALUE(__PWR_CMD) __PWR_CMD.value - - -/* */ -/* Prototype of protected function. */ -/* */ -u8 HalPwrSeqCmdParsing( - struct adapter *padapter, - u8 CutVersion, - u8 FabVersion, - u8 InterfaceType, - struct wlan_pwr_cfg PwrCfgCmd[]); - -#endif diff --git a/drivers/staging/rtl8723bs/include/basic_types.h b/drivers/staging/rtl8723bs/include/basic_types.h deleted file mode 100644 index b6b1afaa9ab8..000000000000 --- a/drivers/staging/rtl8723bs/include/basic_types.h +++ /dev/null @@ -1,175 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __BASIC_TYPES_H__ -#define __BASIC_TYPES_H__ - -#define SUCCESS 0 -#define FAIL (-1) - -#include -#include - -#define SIZE_PTR __kernel_size_t -#define SSIZE_PTR __kernel_ssize_t - -/* port from fw by thomas */ -/* TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness */ - -/* - * Call endian free function when - * 1. Read/write packet content. - * 2. Before write integer to IO. - * 3. After read integer from IO. - */ - -/* */ -/* Byte Swapping routine. */ -/* */ -#define EF1Byte (u8) -#define EF2Byte le16_to_cpu -#define EF4Byte le32_to_cpu - -/* Convert little data endian to host ordering */ -#define EF1BYTE(_val) \ - ((u8)(_val)) -#define EF2BYTE(_val) \ - (le16_to_cpu(_val)) -#define EF4BYTE(_val) \ - (le32_to_cpu(_val)) - -/* - * Create a bit mask - * Examples: - * BIT_LEN_MASK_32(0) => 0x00000000 - * BIT_LEN_MASK_32(1) => 0x00000001 - * BIT_LEN_MASK_32(2) => 0x00000003 - * BIT_LEN_MASK_32(32) => 0xFFFFFFFF - */ -#define BIT_LEN_MASK_32(__bitlen) \ - (0xFFFFFFFF >> (32 - (__bitlen))) -#define BIT_LEN_MASK_16(__bitlen) \ - (0xFFFF >> (16 - (__bitlen))) -#define BIT_LEN_MASK_8(__bitlen) \ - (0xFF >> (8 - (__bitlen))) - -/* - * Create an offset bit mask - * Examples: - * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003 - * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000 - */ -#define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \ - (BIT_LEN_MASK_32(__bitlen) << (__bitoffset)) -#define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \ - (BIT_LEN_MASK_16(__bitlen) << (__bitoffset)) -#define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \ - (BIT_LEN_MASK_8(__bitlen) << (__bitoffset)) - -/* - * Description: - * Return 4-byte value in host byte ordering from - * 4-byte pointer in little-endian system. - */ -#define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \ - (EF4BYTE(*((__le32 *)(__pstart)))) -#define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \ - (EF2BYTE(*((__le16 *)(__pstart)))) -#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \ - (EF1BYTE(*((u8 *)(__pstart)))) - -/* - * Description: - * Translate subfield (continuous bits in little-endian) of 4-byte value in - * little byte to 4-byte value in host byte ordering. - */ -#define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \ - (\ - (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \ - BIT_LEN_MASK_32(__bitlen) \ - ) -#define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \ - (\ - (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \ - BIT_LEN_MASK_16(__bitlen) \ - ) -#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \ - (\ - (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \ - BIT_LEN_MASK_8(__bitlen) \ - ) - -/* - * Description: - * Mask subfield (continuous bits in little-endian) of 4-byte value in little - * byte ordering and return the result in 4-byte value in host byte ordering. - */ -#define LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) \ - (\ - LE_P4BYTE_TO_HOST_4BYTE(__pstart) & \ - (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)) \ - ) -#define LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) \ - (\ - LE_P2BYTE_TO_HOST_2BYTE(__pstart) & \ - (~BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen)) \ - ) -#define LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) \ - (\ - LE_P1BYTE_TO_HOST_1BYTE(__pstart) & \ - (~BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen)) \ - ) - -/* - * Description: - * Set subfield of little-endian 4-byte value to specified value. - */ -#define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \ - (*((u32 *)(__pstart)) = \ - ( \ - LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \ - ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \ - )) - -#define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \ - (*((u16 *)(__pstart)) = \ - ( \ - LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \ - ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \ - )) - -#define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \ - (*((u8 *)(__pstart)) = EF1BYTE \ - ( \ - LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) | \ - ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \ - )) - -#define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \ - (\ - LE_P1BYTE_TO_HOST_1BYTE(__pStart) \ - ) - -#define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \ -{ \ - *((u8 *)(__pStart)) = \ - EF1Byte(\ - LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \ - | \ - ((u8)__Value) \ - ); \ -} - -/* Get the N-bytes alignent offset from the current length */ -#define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment)) - -#define TEST_FLAG(__Flag, __testFlag) (((__Flag) & (__testFlag)) != 0) -#define SET_FLAG(__Flag, __setFlag) ((__Flag) |= __setFlag) -#define CLEAR_FLAG(__Flag, __clearFlag) ((__Flag) &= ~(__clearFlag)) -#define CLEAR_FLAGS(__Flag) ((__Flag) = 0) -#define TEST_FLAGS(__Flag, __testFlags) (((__Flag) & (__testFlags)) == (__testFlags)) - -#endif /* __BASIC_TYPES_H__ */ diff --git a/drivers/staging/rtl8723bs/include/cmd_osdep.h b/drivers/staging/rtl8723bs/include/cmd_osdep.h deleted file mode 100644 index 91d933d71945..000000000000 --- a/drivers/staging/rtl8723bs/include/cmd_osdep.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __CMD_OSDEP_H_ -#define __CMD_OSDEP_H_ - -int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv); -int rtw_init_evt_priv(struct evt_priv *pevtpriv); -extern void _rtw_free_evt_priv(struct evt_priv *pevtpriv); -extern void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv); -extern struct cmd_obj *_rtw_dequeue_cmd(struct __queue *queue); - -#endif diff --git a/drivers/staging/rtl8723bs/include/drv_types.h b/drivers/staging/rtl8723bs/include/drv_types.h deleted file mode 100644 index 20265770ed77..000000000000 --- a/drivers/staging/rtl8723bs/include/drv_types.h +++ /dev/null @@ -1,431 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/*------------------------------------------------------------------------------- - - For type defines and data structure defines - ---------------------------------------------------------------------------------*/ - - -#ifndef __DRV_TYPES_H__ -#define __DRV_TYPES_H__ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ioctl_cfg80211.h" - -#include -#include - -#define SPEC_DEV_ID_NONE BIT(0) -#define SPEC_DEV_ID_DISABLE_HT BIT(1) -#define SPEC_DEV_ID_ENABLE_PS BIT(2) -#define SPEC_DEV_ID_RF_CONFIG_1T1R BIT(3) -#define SPEC_DEV_ID_RF_CONFIG_2T2R BIT(4) -#define SPEC_DEV_ID_ASSIGN_IFNAME BIT(5) - -struct registry_priv { - u8 chip_version; - u8 rfintfs; - u8 lbkmode; - u8 hci; - struct ndis_802_11_ssid ssid; - u8 network_mode; /* infra, ad-hoc, auto */ - u8 channel;/* ad-hoc support requirement */ - u8 wireless_mode;/* A, B, G, auto */ - u8 scan_mode;/* active, passive */ - u8 radio_enable; - u8 preamble;/* long, short, auto */ - u8 vrtl_carrier_sense;/* Enable, Disable, Auto */ - u8 vcs_type;/* RTS/CTS, CTS-to-self */ - u16 rts_thresh; - u16 frag_thresh; - u8 adhoc_tx_pwr; - u8 soft_ap; - u8 power_mgnt; - u8 ips_mode; - u8 smart_ps; - u8 usb_rxagg_mode; - u8 long_retry_lmt; - u8 short_retry_lmt; - u16 busy_thresh; - u8 ack_policy; - u8 mp_dm; - u8 software_encrypt; - u8 software_decrypt; - u8 acm_method; - /* UAPSD */ - u8 wmm_enable; - u8 uapsd_enable; - u8 uapsd_max_sp; - u8 uapsd_acbk_en; - u8 uapsd_acbe_en; - u8 uapsd_acvi_en; - u8 uapsd_acvo_en; - - struct wlan_bssid_ex dev_network; - - u8 ht_enable; - /* - * 0: 20 MHz, 1: 40 MHz - * 2.4G use bit 0 ~ 3 - * 0x01 means enable 2.4G 40MHz - */ - u8 bw_mode; - u8 ampdu_enable;/* for tx */ - u8 rx_stbc; - u8 ampdu_amsdu;/* A-MPDU Supports A-MSDU is permitted */ - /* Short GI support Bit Map */ - /* BIT0 - 20MHz, 1: support, 0: non-support */ - /* BIT1 - 40MHz, 1: support, 0: non-support */ - /* BIT2 - 80MHz, 1: support, 0: non-support */ - /* BIT3 - 160MHz, 1: support, 0: non-support */ - u8 short_gi; - /* BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */ - u8 ldpc_cap; - /* BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */ - u8 stbc_cap; - /* BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee */ - u8 beamform_cap; - - u8 lowrate_two_xmit; - - u8 low_power; - - u8 wifi_spec;/* !turbo_mode */ - - u8 channel_plan; - - s8 ant_num; - - /* false:Reject AP's Add BA req, true:accept AP's Add BA req */ - bool accept_addba_req; - - u8 antdiv_cfg; - u8 antdiv_type; - - u8 usbss_enable;/* 0:disable, 1:enable */ - u8 hwpdn_mode;/* 0:disable, 1:enable, 2:decide by EFUSE config */ - u8 hwpwrp_detect;/* 0:disable, 1:enable */ - - u8 hw_wps_pbc;/* 0:disable, 1:enable */ - - u8 max_roaming_times; /* the max number driver will try to roaming */ - - u8 enable80211d; - - u8 ifname[16]; - - u8 notch_filter; - - /* define for tx power adjust */ - u8 reg_enable_tx_power_limit; - u8 reg_enable_tx_power_by_rate; - u8 reg_power_base; - u8 reg_pwr_tbl_sel; - u8 check_fw_ps; - - u8 qos_opt_enable; - - u8 hiq_filter; -}; - -#include - -#define GET_PRIMARY_ADAPTER(padapter) (((struct adapter *)padapter)->dvobj->if1) -#define GET_IFACE_NUMS(padapter) (((struct adapter *)padapter)->dvobj->iface_nums) -#define GET_ADAPTER(padapter, iface_id) (((struct adapter *)padapter)->dvobj->padapters[iface_id]) - -struct rtw_traffic_statistics { - /* tx statistics */ - u64 tx_bytes; - u64 tx_pkts; - u64 tx_drop; - u64 cur_tx_bytes; - u64 last_tx_bytes; - u32 cur_tx_tp; /* Tx throughput in MBps. */ - - /* rx statistics */ - u64 rx_bytes; - u64 rx_pkts; - u64 rx_drop; - u64 cur_rx_bytes; - u64 last_rx_bytes; - u32 cur_rx_tp; /* Rx throughput in MBps. */ -}; - -struct cam_ctl_t { - spinlock_t lock; - u64 bitmap; -}; - -struct cam_entry_cache { - u16 ctrl; - u8 mac[ETH_ALEN]; - u8 key[16]; -}; - -struct dvobj_priv { - /*-------- below is common data --------*/ - struct adapter *if1; /* PRIMARY_ADAPTER */ - - s32 processing_dev_remove; - - /* for local/global synchronization */ - /* */ - spinlock_t lock; - int macid[NUM_STA]; - - struct mutex hw_init_mutex; - struct mutex h2c_fwcmd_mutex; - struct mutex setch_mutex; - struct mutex setbw_mutex; - - unsigned char oper_channel; /* saved channel info when call set_channel_bw */ - unsigned char oper_bwmode; - unsigned char oper_ch_offset;/* PRIME_CHNL_OFFSET */ - unsigned long on_oper_ch_time; - - struct adapter *padapters; - - struct cam_ctl_t cam_ctl; - struct cam_entry_cache cam_cache[TOTAL_CAM_ENTRY]; - - /* In /Out Pipe information */ - int RtInPipe[2]; - int RtOutPipe[4]; - u8 Queue2Pipe[HW_QUEUE_ENTRY];/* for out pipe mapping */ - - u8 irq_alloc; - atomic_t continual_io_error; - - atomic_t disable_func; - - struct pwrctrl_priv pwrctl_priv; - - struct rtw_traffic_statistics traffic_stat; - -/*-------- below is for SDIO INTERFACE --------*/ - -struct sdio_data intf_data; - -}; - -#define dvobj_to_pwrctl(dvobj) (&(dvobj->pwrctl_priv)) - -static inline struct dvobj_priv *pwrctl_to_dvobj(struct pwrctrl_priv *pwrctl_priv) -{ - return container_of(pwrctl_priv, struct dvobj_priv, pwrctl_priv); -} - -static inline struct device *dvobj_to_dev(struct dvobj_priv *dvobj) -{ - /* todo: get interface type from dvobj and the return the dev accordingly */ - return &dvobj->intf_data.func->dev; -} - -enum { - DRIVER_NORMAL = 0, - DRIVER_DISAPPEAR = 1, - DRIVER_REPLACE_DONGLE = 2, -}; - -struct adapter { - int DriverState;/* for disable driver using module, use dongle to replace module. */ - int pid[3];/* process id from UI, 0:wps, 1:hostapd, 2:dhcpcd */ - int bDongle;/* build-in module or external dongle */ - - struct dvobj_priv *dvobj; - struct mlme_priv mlmepriv; - struct mlme_ext_priv mlmeextpriv; - struct cmd_priv cmdpriv; - struct evt_priv evtpriv; - /* struct io_queue *pio_queue; */ - struct io_priv iopriv; - struct xmit_priv xmitpriv; - struct recv_priv recvpriv; - struct sta_priv stapriv; - struct security_priv securitypriv; - spinlock_t security_key_mutex; - struct registry_priv registrypriv; - struct eeprom_priv eeprompriv; - - struct hostapd_priv *phostapdpriv; - - u32 setband; - - void *HalData; - u32 hal_data_sz; - - bool driver_stopped; - s32 bSurpriseRemoved; - s32 bCardDisableWOHSM; - - u32 IsrContent; - u32 ImrContent; - - u8 EepromAddressSize; - u8 hw_init_completed; - u8 bDriverIsGoingToUnload; - u8 init_adpt_in_progress; - u8 bHaltInProgress; - - void *cmdThread; - void *evtThread; - void *xmitThread; - void *recvThread; - - u32 (*intf_init)(struct dvobj_priv *dvobj); - void (*intf_deinit)(struct dvobj_priv *dvobj); - int (*intf_alloc_irq)(struct dvobj_priv *dvobj); - void (*intf_free_irq)(struct dvobj_priv *dvobj); - - - void (*intf_start)(struct adapter *adapter); - void (*intf_stop)(struct adapter *adapter); - - struct net_device *pnetdev; - char old_ifname[IFNAMSIZ]; - - /* used by rtw_rereg_nd_name related function */ - struct rereg_nd_name_data { - struct net_device *old_pnetdev; - char old_ifname[IFNAMSIZ]; - u8 old_bRegUseLed; - } rereg_nd_name_priv; - - int bup; - struct net_device_stats stats; - struct iw_statistics iwstats; - - struct wireless_dev *rtw_wdev; - struct rtw_wdev_priv wdev_data; - - int net_closed; - - u8 netif_up; - - u8 bFWReady; - u8 bBTFWReady; - u8 bLinkInfoDump; - u8 bRxRSSIDisplay; - /* Added by Albert 2012/10/26 */ - /* The driver will show up the desired channel number when this flag is 1. */ - u8 bNotifyChannelChange; - - /* pbuddystruct adapter is used only in two interface case, (iface_nums =2 in struct dvobj_priv) */ - /* PRIMARY ADAPTER's buddy is SECONDARY_ADAPTER */ - /* SECONDARY_ADAPTER's buddy is PRIMARY_ADAPTER */ - /* for iface_id > SECONDARY_ADAPTER(IFACE_ID1), refer to padapters[iface_id] in struct dvobj_priv */ - /* and their pbuddystruct adapter is PRIMARY_ADAPTER. */ - /* for PRIMARY_ADAPTER(IFACE_ID0) can directly refer to if1 in struct dvobj_priv */ - struct adapter *pbuddy_adapter; - - /* extend to support multi interface */ - /* IFACE_ID0 is equals to PRIMARY_ADAPTER */ - /* IFACE_ID1 is equals to SECONDARY_ADAPTER */ - u8 iface_id; - - /* for debug purpose */ - u8 fix_rate; - u8 driver_vcs_en; /* Enable = 1, Disable = 0 driver control vrtl_carrier_sense for tx */ - u8 driver_vcs_type;/* force 0:disable VCS, 1:RTS-CTS, 2:CTS-to-self when vcs_en = 1. */ - u8 driver_ampdu_spacing;/* driver control AMPDU Density for peer sta's rx */ - u8 driver_rx_ampdu_factor;/* 0xff: disable drv ctrl, 0:8k, 1:16k, 2:32k, 3:64k; */ - - unsigned char in_cta_test; -}; - -#define adapter_to_dvobj(adapter) (adapter->dvobj) -#define adapter_to_pwrctl(adapter) (dvobj_to_pwrctl(adapter->dvobj)) -#define adapter_wdev_data(adapter) (&((adapter)->wdev_data)) - -/* */ -/* Function disabled. */ -/* */ -#define DF_TX_BIT BIT(0) -#define DF_RX_BIT BIT(1) -#define DF_IO_BIT BIT(2) - -/* define RTW_ENABLE_FUNC(padapter, func) (atomic_sub(&adapter_to_dvobj(padapter)->disable_func, (func))) */ - -static inline void RTW_ENABLE_FUNC(struct adapter *padapter, int func_bit) -{ - int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func); - - df &= ~(func_bit); - atomic_set(&adapter_to_dvobj(padapter)->disable_func, df); -} - -#define RTW_IS_FUNC_DISABLED(padapter, func_bit) (atomic_read(&adapter_to_dvobj(padapter)->disable_func) & (func_bit)) - -#define RTW_CANNOT_IO(padapter) \ - ((padapter)->bSurpriseRemoved || \ - RTW_IS_FUNC_DISABLED((padapter), DF_IO_BIT)) - -#define RTW_CANNOT_RX(padapter) \ - ((padapter)->driver_stopped || \ - (padapter)->bSurpriseRemoved || \ - RTW_IS_FUNC_DISABLED((padapter), DF_RX_BIT)) - -#define RTW_CANNOT_TX(padapter) \ - ((padapter)->driver_stopped || \ - (padapter)->bSurpriseRemoved || \ - RTW_IS_FUNC_DISABLED((padapter), DF_TX_BIT)) - -static inline u8 *myid(struct eeprom_priv *peepriv) -{ - return peepriv->mac_addr; -} - -/* HCI Related header file */ -#include -#include - -#include - -extern char *rtw_initmac; -extern int rtw_mc2u_disable; -extern int rtw_ht_enable; -extern u32 g_wait_hiq_empty; -extern u8 g_fwdl_wintint_rdy_fail; -extern u8 g_fwdl_chksum_fail; - -#endif /* __DRV_TYPES_H__ */ diff --git a/drivers/staging/rtl8723bs/include/drv_types_sdio.h b/drivers/staging/rtl8723bs/include/drv_types_sdio.h deleted file mode 100644 index 25b3c3a39ee4..000000000000 --- a/drivers/staging/rtl8723bs/include/drv_types_sdio.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __DRV_TYPES_SDIO_H__ -#define __DRV_TYPES_SDIO_H__ - -/* SDIO Header Files */ - #include - #include - -struct sdio_data { - u8 func_number; - - u8 tx_block_mode; - u8 rx_block_mode; - u32 block_transfer_len; - - struct sdio_func *func; - void *sys_sdio_irq_thd; -}; - -#endif diff --git a/drivers/staging/rtl8723bs/include/hal_btcoex.h b/drivers/staging/rtl8723bs/include/hal_btcoex.h deleted file mode 100644 index 525cce3574fe..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_btcoex.h +++ /dev/null @@ -1,54 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_BTCOEX_H__ -#define __HAL_BTCOEX_H__ - -#include - -#define LPS_RPWM_WAIT_MS 300 - -/* Some variables can't get from outsrc BT-Coex, */ -/* so we need to save here */ -struct bt_coexist { - u8 bBtExist; - u8 btTotalAntNum; - u8 btChipType; - u8 bInitlized; -}; - -void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist); -bool hal_btcoex_IsBtExist(struct adapter *padapter); -bool hal_btcoex_IsBtDisabled(struct adapter *); -void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum); -void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath); - -void hal_btcoex_Initialize(void *padapter); -void hal_btcoex_PowerOnSetting(struct adapter *padapter); -void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly); - -void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type); -void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type); -void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type); -void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action); -void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus); -void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType); -void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state); -void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf); -void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state); -void hal_btcoex_HaltNotify(struct adapter *padapter); - -void hal_btcoex_Handler(struct adapter *padapter); - -s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter); -bool hal_btcoex_IsBtControlLps(struct adapter *padapter); -bool hal_btcoex_IsLpsOn(struct adapter *padapter); -u8 hal_btcoex_RpwmVal(struct adapter *); -u8 hal_btcoex_LpsVal(struct adapter *); -u32 hal_btcoex_GetRaMask(struct adapter *); -void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen); - -#endif /* !__HAL_BTCOEX_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_com.h b/drivers/staging/rtl8723bs/include/hal_com.h deleted file mode 100644 index 7bbf62cfd825..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_com.h +++ /dev/null @@ -1,152 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_COMMON_H__ -#define __HAL_COMMON_H__ - -#include "hal_pg.h" -#include "hal_phy.h" -#include "hal_phy_reg.h" -#include "hal_com_reg.h" -#include "hal_com_phycfg.h" - -/*------------------------------ Tx Desc definition Macro ------------------------*/ -/* pragma mark -- Tx Desc related definition. -- */ -/* */ -/* */ -/* Rate */ -/* */ -/* CCK Rates, TxHT = 0 */ -#define DESC_RATE1M 0x00 -#define DESC_RATE2M 0x01 -#define DESC_RATE5_5M 0x02 -#define DESC_RATE11M 0x03 - -/* OFDM Rates, TxHT = 0 */ -#define DESC_RATE6M 0x04 -#define DESC_RATE9M 0x05 -#define DESC_RATE12M 0x06 -#define DESC_RATE18M 0x07 -#define DESC_RATE24M 0x08 -#define DESC_RATE36M 0x09 -#define DESC_RATE48M 0x0a -#define DESC_RATE54M 0x0b - -/* MCS Rates, TxHT = 1 */ -#define DESC_RATEMCS0 0x0c -#define DESC_RATEMCS1 0x0d -#define DESC_RATEMCS2 0x0e -#define DESC_RATEMCS3 0x0f -#define DESC_RATEMCS4 0x10 -#define DESC_RATEMCS5 0x11 -#define DESC_RATEMCS6 0x12 -#define DESC_RATEMCS7 0x13 - -#define HDATA_RATE(rate)\ -(rate == DESC_RATE1M) ? "CCK_1M" : \ -(rate == DESC_RATE2M) ? "CCK_2M" : \ -(rate == DESC_RATE5_5M) ? "CCK5_5M" : \ -(rate == DESC_RATE11M) ? "CCK_11M" : \ -(rate == DESC_RATE6M) ? "OFDM_6M" : \ -(rate == DESC_RATE9M) ? "OFDM_9M" : \ -(rate == DESC_RATE12M) ? "OFDM_12M" : \ -(rate == DESC_RATE18M) ? "OFDM_18M" : \ -(rate == DESC_RATE24M) ? "OFDM_24M" : \ -(rate == DESC_RATE36M) ? "OFDM_36M" : \ -(rate == DESC_RATE48M) ? "OFDM_48M" : \ -(rate == DESC_RATE54M) ? "OFDM_54M" : \ -(rate == DESC_RATEMCS0) ? "MCS0" : \ -(rate == DESC_RATEMCS1) ? "MCS1" : \ -(rate == DESC_RATEMCS2) ? "MCS2" : \ -(rate == DESC_RATEMCS3) ? "MCS3" : \ -(rate == DESC_RATEMCS4) ? "MCS4" : \ -(rate == DESC_RATEMCS5) ? "MCS5" : \ -(rate == DESC_RATEMCS6) ? "MCS6" : \ -(rate == DESC_RATEMCS7) ? "MCS7" : "UNKNOWN" - -enum{ - UP_LINK, - DOWN_LINK, -}; -enum rt_media_status { - RT_MEDIA_DISCONNECT = 0, - RT_MEDIA_CONNECT = 1 -}; - -#define MAX_DLFW_PAGE_SIZE 4096 /* @ page : 4k bytes */ - -/* BK, BE, VI, VO, HCCA, MANAGEMENT, COMMAND, HIGH, BEACON. */ -/* define MAX_TX_QUEUE 9 */ - -#define TX_SELE_HQ BIT(0) /* High Queue */ -#define TX_SELE_LQ BIT(1) /* Low Queue */ -#define TX_SELE_NQ BIT(2) /* Normal Queue */ -#define TX_SELE_EQ BIT(3) /* Extern Queue */ - -#define PageNum_128(_Len) ((u32)(((_Len) >> 7) + ((_Len) & 0x7F ? 1 : 0))) - -u8 rtw_hal_data_init(struct adapter *padapter); -void rtw_hal_data_deinit(struct adapter *padapter); - -u8 /* return the final channel plan decision */ -hal_com_config_channel_plan( -struct adapter *padapter, -u8 hw_channel_plan, /* channel plan from HW (efuse/eeprom) */ -u8 sw_channel_plan, /* channel plan from SW (registry/module param) */ -u8 def_channel_plan, /* channel plan used when the former two is invalid */ -bool AutoLoadFail - ); - -bool -HAL_IsLegalChannel( -struct adapter *Adapter, -u32 Channel - ); - -u8 MRateToHwRate(u8 rate); - -u8 HwRateToMRate(u8 rate); - -void HalSetBrateCfg( - struct adapter *Adapter, - u8 *mBratesOS, - u16 *pBrateCfg); - -bool -Hal_MappingOutPipe( -struct adapter *padapter, -u8 NumOutPipe - ); - -void hal_init_macaddr(struct adapter *adapter); - -void rtw_init_hal_com_default_value(struct adapter *Adapter); - -void c2h_evt_clear(struct adapter *adapter); -s32 c2h_evt_read_88xx(struct adapter *adapter, u8 *buf); - -u8 rtw_get_mgntframe_raid(struct adapter *adapter, unsigned char network_type); -void rtw_hal_update_sta_rate_mask(struct adapter *padapter, struct sta_info *psta); - -void SetHwReg(struct adapter *padapter, u8 variable, u8 *val); -void GetHwReg(struct adapter *padapter, u8 variable, u8 *val); -void rtw_hal_check_rxfifo_full(struct adapter *adapter); - -u8 GetHalDefVar(struct adapter *adapter, enum hal_def_variable variable, - void *value); - -bool GetU1ByteIntegerFromStringInDecimal(char *str, u8 *in); - -#define HWSET_MAX_SIZE 512 - -void rtw_bb_rf_gain_offset(struct adapter *padapter); - -void SetHalODMVar( - struct adapter *Adapter, - enum hal_odm_variable eVariable, - void *pValue1, - bool bSet); -#endif /* __HAL_COMMON_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_com_h2c.h b/drivers/staging/rtl8723bs/include/hal_com_h2c.h deleted file mode 100644 index a59d13090565..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_com_h2c.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __COMMON_H2C_H__ -#define __COMMON_H2C_H__ - -#define H2C_RSVDPAGE_LOC_LEN 5 -#define H2C_MEDIA_STATUS_RPT_LEN 3 -#define H2C_PWRMODE_LEN 7 -#define H2C_PSTUNEPARAM_LEN 4 -#define H2C_MACID_CFG_LEN 7 -#define H2C_RSSI_SETTING_LEN 4 - -/* */ -/* Structure -------------------------------------------------- */ -/* */ -struct rsvdpage_loc { - u8 LocProbeRsp; - u8 LocPsPoll; - u8 LocNullData; - u8 LocQosNull; - u8 LocBTQosNull; -}; - -#endif diff --git a/drivers/staging/rtl8723bs/include/hal_com_phycfg.h b/drivers/staging/rtl8723bs/include/hal_com_phycfg.h deleted file mode 100644 index cb7c7ed74146..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_com_phycfg.h +++ /dev/null @@ -1,108 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_COM_PHYCFG_H__ -#define __HAL_COM_PHYCFG_H__ - -#define PathA 0x0 /* Useless */ -#define PathB 0x1 -#define PathC 0x2 -#define PathD 0x3 - -enum rate_section { - CCK = 0, - OFDM, - HT_MCS0_MCS7, -}; - -#define MAX_POWER_INDEX 0x3F - -enum { - TXPWR_LMT_FCC = 0, - TXPWR_LMT_MKK, - TXPWR_LMT_ETSI, - TXPWR_LMT_WW, - TXPWR_LMT_MAX_REGULATION_NUM, -}; - -/*------------------------------Define structure----------------------------*/ -struct bb_register_def { - u32 rfintfs; /* set software control: */ - /* 0x870~0x877[8 bytes] */ - - u32 rfintfo; /* output data: */ - /* 0x860~0x86f [16 bytes] */ - - u32 rfintfe; /* output enable: */ - /* 0x860~0x86f [16 bytes] */ - - u32 rf3wireOffset; /* LSSI data: */ - /* 0x840~0x84f [16 bytes] */ - - u32 rfHSSIPara2; /* wire parameter control2 : */ - /* 0x824~0x827, 0x82c~0x82f, - * 0x834~0x837, 0x83c~0x83f - */ - u32 rfLSSIReadBack; /* LSSI RF readback data SI mode */ - /* 0x8a0~0x8af [16 bytes] */ - - u32 rfLSSIReadBackPi; /* LSSI RF readback data PI mode - * 0x8b8-8bc for Path A and B */ - -}; - -u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 RfPath, - enum rate_section RateSection); - -u8 PHY_GetRateSectionIndexOfTxPowerByRate(struct adapter *padapter, u32 RegAddr, - u32 BitMask); - -void PHY_GetRateValuesOfTxPowerByRate(struct adapter *padapter, u32 RegAddr, - u32 BitMask, u32 Value, u8 *RateIndex, - s8 *PwrByRateVal, u8 *RateNum); - -u8 PHY_GetRateIndexOfTxPowerByRate(u8 Rate); - -void PHY_SetTxPowerIndexByRateSection(struct adapter *padapter, u8 RFPath, u8 Channel, - u8 RateSection); - -s8 PHY_GetTxPowerByRate(struct adapter *padapter, u8 RFPath, u8 RateIndex); - -void PHY_SetTxPowerByRate(struct adapter *padapter, u8 RFPath, u8 Rate, - s8 Value); - -void PHY_SetTxPowerLevelByPath(struct adapter *Adapter, u8 channel, u8 path); - -void PHY_SetTxPowerIndexByRateArray(struct adapter *padapter, u8 RFPath, - enum channel_width BandWidth, u8 Channel, - u8 *Rates, u8 RateArraySize); - -void PHY_InitTxPowerByRate(struct adapter *padapter); - -void PHY_StoreTxPowerByRate(struct adapter *padapter, u32 RfPath, - u32 RegAddr, u32 BitMask, u32 Data); - -void PHY_TxPowerByRateConfiguration(struct adapter *padapter); - -u8 PHY_GetTxPowerIndexBase(struct adapter *padapter, u8 RFPath, u8 Rate, - enum channel_width BandWidth, u8 Channel); - -s8 phy_get_tx_pwr_lmt(struct adapter *adapter, u32 RegPwrTblSel, - enum channel_width Bandwidth, u8 RfPath, u8 DataRate, - u8 Channel); - -void PHY_SetTxPowerLimit(struct adapter *Adapter, u8 *Regulation, u8 *Bandwidth, - u8 *RateSection, u8 *RfPath, u8 *Channel, u8 *PowerLimit); - -void PHY_ConvertTxPowerLimitToPowerIndex(struct adapter *Adapter); - -void PHY_InitTxPowerLimit(struct adapter *Adapter); - -s8 PHY_GetTxPowerTrackingOffset(struct adapter *padapter, u8 Rate, u8 RFPath); - -void Hal_ChannelPlanToRegulation(struct adapter *Adapter, u16 ChannelPlan); - -#endif /* __HAL_COMMON_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_com_reg.h b/drivers/staging/rtl8723bs/include/hal_com_reg.h deleted file mode 100644 index 4671fdfff916..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_com_reg.h +++ /dev/null @@ -1,594 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_COMMON_REG_H__ -#define __HAL_COMMON_REG_H__ - -/* */ -/* */ -/* 0x0000h ~ 0x00FFh System Configuration */ -/* */ -/* */ -#define REG_SYS_FUNC_EN 0x0002 -#define REG_APS_FSMCO 0x0004 -#define REG_SYS_CLKR 0x0008 -#define REG_9346CR 0x000A -#define REG_SYS_EEPROM_CTRL 0x000A -#define REG_RSV_CTRL 0x001C -#define REG_RF_CTRL 0x001F -#define REG_AFE_XTAL_CTRL 0x0024 -#define REG_MAC_PHY_CTRL 0x002c /* for 92d, DMDP, SMSP, DMSP control */ -#define REG_EFUSE_CTRL 0x0030 -#define REG_EFUSE_TEST 0x0034 -#define REG_PWR_DATA 0x0038 -#define REG_GPIO_MUXCFG 0x0040 -#define REG_GPIO_INTM 0x0048 -#define REG_LEDCFG0 0x004C -#define REG_LEDCFG2 0x004E -#define REG_HSIMR 0x0058 -#define REG_GPIO_IO_SEL_2 0x0062 /* RTL8723 WIFI/BT/GPS Multi-Function GPIO Select. */ -#define REG_MULTI_FUNC_CTRL 0x0068 /* RTL8723 WIFI/BT/GPS Multi-Function control source. */ -#define REG_MCUFWDL 0x0080 -#define REG_EFUSE_ACCESS 0x00CF /* Efuse access protection for RTL8723 */ -#define REG_SYS_CFG 0x00F0 -#define REG_GPIO_OUTSTS 0x00F4 /* For RTL8723 only. */ - -/* */ -/* */ -/* 0x0100h ~ 0x01FFh MACTOP General Configuration */ -/* */ -/* */ -#define REG_CR 0x0100 -#define REG_PBP 0x0104 -#define REG_TRXDMA_CTRL 0x010C -#define REG_TRXFF_BNDY 0x0114 -#define REG_HIMR 0x0120 -#define REG_HISR 0x0124 - -#define REG_C2HEVT_MSG_NORMAL 0x01A0 -#define REG_C2HEVT_CLEAR 0x01AF -#define REG_HMETFR 0x01CC -#define REG_HMEBOX_0 0x01D0 - -/* */ -/* */ -/* 0x0200h ~ 0x027Fh TXDMA Configuration */ -/* */ -/* */ -#define REG_RQPN 0x0200 -#define REG_TDECTRL 0x0208 -#define REG_TXDMA_STATUS 0x0210 -#define REG_RQPN_NPQ 0x0214 -#define REG_AUTO_LLT 0x0224 - - -/* */ -/* */ -/* 0x0280h ~ 0x02FFh RXDMA Configuration */ -/* */ -/* */ -#define REG_RXDMA_AGG_PG_TH 0x0280 -#define REG_RXPKT_NUM 0x0284 - -/* */ -/* */ -/* 0x0400h ~ 0x047Fh Protocol Configuration */ -/* */ -/* */ -#define REG_TXPKT_EMPTY 0x041A -#define REG_FWHW_TXQ_CTRL 0x0420 -#define REG_HWSEQ_CTRL 0x0423 -#define REG_SPEC_SIFS 0x0428 -#define REG_RL 0x042A -#define REG_RRSR 0x0440 - -#define REG_PKT_VO_VI_LIFE_TIME 0x04C0 -#define REG_PKT_BE_BK_LIFE_TIME 0x04C2 -#define REG_BAR_MODE_CTRL 0x04CC -#define REG_EARLY_MODE_CONTROL 0x04D0 -#define REG_MACID_SLEEP 0x04D4 -#define REG_NQOS_SEQ 0x04DC - -/* */ -/* */ -/* 0x0500h ~ 0x05FFh EDCA Configuration */ -/* */ -/* */ -#define REG_EDCA_VO_PARAM 0x0500 -#define REG_EDCA_VI_PARAM 0x0504 -#define REG_EDCA_BE_PARAM 0x0508 -#define REG_EDCA_BK_PARAM 0x050C -#define REG_BCNTCFG 0x0510 -#define REG_SIFS_CTX 0x0514 -#define REG_SIFS_TRX 0x0516 -#define REG_TSFTR_SYN_OFFSET 0x0518 -#define REG_SLOT 0x051B -#define REG_TXPAUSE 0x0522 -#define REG_RD_CTRL 0x0524 -/* */ -/* Format for offset 540h-542h: */ -/* [3:0]: TBTT prohibit setup in unit of 32us. The time for HW getting beacon content before TBTT. */ -/* [7:4]: Reserved. */ -/* [19:8]: TBTT prohibit hold in unit of 32us. The time for HW holding to send the beacon packet. */ -/* [23:20]: Reserved */ -/* Description: */ -/* | */ -/* |<--Setup--|--Hold------------>| */ -/* --------------|---------------------- */ -/* | */ -/* TBTT */ -/* Note: We cannot update beacon content to HW or send any AC packets during the time between Setup and Hold. */ -/* Described by Designer Tim and Bruce, 2011-01-14. */ -/* */ -#define REG_TBTT_PROHIBIT 0x0540 -#define REG_BCN_CTRL 0x0550 -#define REG_BCN_CTRL_1 0x0551 -#define REG_DUAL_TSF_RST 0x0553 -#define REG_BCN_INTERVAL 0x0554 /* The same as REG_MBSSID_BCN_SPACE */ -#define REG_DRVERLYINT 0x0558 -#define REG_BCNDMATIM 0x0559 -#define REG_ATIMWND 0x055A -#define REG_BCN_MAX_ERR 0x055D -#define REG_RXTSF_OFFSET_CCK 0x055E -#define REG_RXTSF_OFFSET_OFDM 0x055F -#define REG_TSFTR 0x0560 -#define REG_ACMHWCTRL 0x05C0 - -/* */ -/* */ -/* 0x0600h ~ 0x07FFh WMAC Configuration */ -/* */ -/* */ -#define REG_BWOPMODE 0x0603 -#define REG_TCR 0x0604 -#define REG_RCR 0x0608 -#define REG_RX_DRVINFO_SZ 0x060F - -#define REG_MACID 0x0610 -#define REG_BSSID 0x0618 -#define REG_MAR 0x0620 - -#define REG_MAC_SPEC_SIFS 0x063A -/* 20100719 Joseph: Hardware register definition change. (HW datasheet v54) */ -#define REG_RESP_SIFS_CCK 0x063C /* [15:8]SIFS_R2T_OFDM, [7:0]SIFS_R2T_CCK */ -#define REG_RESP_SIFS_OFDM 0x063E /* [15:8]SIFS_T2T_OFDM, [7:0]SIFS_T2T_CCK */ - -#define REG_ACKTO 0x0640 - -/* */ -/* Note: */ -/* The NAV upper value is very important to WiFi 11n 5.2.3 NAV test. The default value is */ -/* always too small, but the WiFi TestPlan test by 25, 000 microseconds of NAV through sending */ -/* CTS in the air. We must update this value greater than 25, 000 microseconds to pass the item. */ -/* The offset of NAV_UPPER in 8192C Spec is incorrect, and the offset should be 0x0652. Commented */ -/* by SD1 Scott. */ -/* By Bruce, 2011-07-18. */ -/* */ -#define REG_NAV_UPPER 0x0652 /* unit of 128 */ - -/* WMA, BA, CCX */ -#define REG_RXERR_RPT 0x0664 - -/* Security */ -#define REG_CAMCMD 0x0670 -#define REG_CAMWRITE 0x0674 -#define REG_CAMREAD 0x0678 -#define REG_SECCFG 0x0680 - -/* Power */ -#define REG_RXFLTMAP0 0x06A0 -#define REG_RXFLTMAP1 0x06A2 -#define REG_RXFLTMAP2 0x06A4 -#define REG_BCN_PSR_RPT 0x06A8 - -/* */ -/* */ -/* Redefine 8192C register definition for compatibility */ -/* */ -/* */ -#define EFUSE_CTRL REG_EFUSE_CTRL /* E-Fuse Control. */ -#define EFUSE_TEST REG_EFUSE_TEST /* E-Fuse Test. */ -#define MSR (REG_CR + 2) /* Media Status register */ - -#define PBP REG_PBP - -/* */ -/* 9. Security Control Registers (Offset:) */ -/* */ -#define RWCAM REG_CAMCMD /* IN 8190 Data Sheet is called CAMcmd */ -#define WCAMI REG_CAMWRITE /* Software write CAM input content */ - -/* */ -/* 8723/8188E Host System Interrupt Status Register (offset 0x5C, 32 byte) */ -/* */ -#define HSISR_GPIO12_0_INT BIT(0) -#define HSISR_SPS_OCP_INT BIT(5) -#define HSISR_RON_INT BIT(6) -#define HSISR_PDNINT BIT(7) -#define HSISR_GPIO9_INT BIT(25) - -/* */ -/* Response Rate Set Register (offset 0x440, 24bits) */ -/* */ -#define RRSR_1M BIT(0) -#define RRSR_2M BIT(1) -#define RRSR_5_5M BIT(2) -#define RRSR_11M BIT(3) -#define RRSR_6M BIT(4) -#define RRSR_12M BIT(6) -#define RRSR_24M BIT(8) - -#define RRSR_CCK_RATES (RRSR_11M|RRSR_5_5M|RRSR_2M|RRSR_1M) - -/* */ -/* Rate Definition */ -/* */ -/* CCK */ -#define RATE_1M BIT(0) -#define RATE_2M BIT(1) -#define RATE_5_5M BIT(2) -#define RATE_11M BIT(3) -/* OFDM */ -#define RATE_6M BIT(4) -#define RATE_9M BIT(5) -#define RATE_12M BIT(6) -#define RATE_18M BIT(7) -#define RATE_24M BIT(8) -#define RATE_36M BIT(9) -#define RATE_48M BIT(10) -#define RATE_54M BIT(11) - -/* ALL CCK Rate */ -#define RATE_BITMAP_ALL 0xFFFFF - -/* Only use CCK 1M rate for ACK */ -#define RATE_RRSR_CCK_ONLY_1M 0xFFFF1 - -/* */ -/* BW_OPMODE bits (Offset 0x603, 8bit) */ -/* */ -#define BW_OPMODE_20MHZ BIT(2) - -/* */ -/* CAM Config Setting (offset 0x680, 1 byte) */ -/* */ -#define CAM_VALID BIT(15) - -#define CAM_CONTENT_COUNT 8 - -#define CAM_AES 0x04 - -#define TOTAL_CAM_ENTRY 32 - -#define CAM_WRITE BIT(16) -#define CAM_POLLINIG BIT(31) - -/* */ -/* 12. Host Interrupt Status Registers */ -/* */ - -/* */ -/* 8192C (RCR) Receive Configuration Register (Offset 0x608, 32 bits) */ -/* */ -#define RCR_APPFCS BIT(31) /* WMAC append FCS after payload */ -#define RCR_APP_MIC BIT(30) /* MACRX will retain the MIC at the bottom of the packet. */ -#define RCR_APP_ICV BIT(29) /* MACRX will retain the ICV at the bottom of the packet. */ -#define RCR_APP_PHYST_RXFF BIT(28) /* PHY Status is appended before RX packet in RXFF */ -#define RCR_APP_BA_SSN BIT(27) /* SSN of previous TXBA is appended as after original RXDESC as the 4-th DW of RXDESC. */ -#define RCR_HTC_LOC_CTRL BIT(14) /* MFC<--HTC = 1 MFC-->HTC = 0 */ -#define RCR_AMF BIT(13) /* Accept management type frame */ -#define RCR_ADF BIT(11) /* Accept data type frame. This bit also regulates BA, BAR, and PS-Poll (AP mode only). */ -#define RCR_ACRC32 BIT(8) /* Accept CRC32 error packet */ -#define RCR_CBSSID_BCN BIT(7) /* Accept BSSID match packet (Rx beacon, probe rsp) */ -#define RCR_CBSSID_DATA BIT(6) /* Accept BSSID match packet (Data) */ -#define RCR_AB BIT(3) /* Accept broadcast packet */ -#define RCR_AM BIT(2) /* Accept multicast packet */ -#define RCR_APM BIT(1) /* Accept physical match packet */ - - -/* */ -/* */ -/* 0x0000h ~ 0x00FFh System Configuration */ -/* */ -/* */ - -/* 2 SYS_FUNC_EN */ -#define FEN_BBRSTB BIT(0) -#define FEN_BB_GLB_RSTn BIT(1) -#define FEN_DIO_PCIE BIT(5) -#define FEN_PCIEA BIT(6) -#define FEN_PPLL BIT(7) -#define FEN_CPUEN BIT(10) -#define FEN_ELDR BIT(12) - -/* 2 APS_FSMCO */ -#define EnPDN BIT(4) - -/* 2 SYS_CLKR */ -#define ANA8M BIT(1) -#define LOADER_CLK_EN BIT(5) - - -/* 2 9346CR /REG_SYS_EEPROM_CTRL */ -#define BOOT_FROM_EEPROM BIT(4) -#define EEPROM_EN BIT(5) - - -/* 2 RF_CTRL */ -#define RF_EN BIT(0) -#define RF_RSTB BIT(1) -#define RF_SDMRSTB BIT(2) - -/* 2 EFUSE_TEST (For RTL8723 partially) */ -#define EFUSE_SEL(x) (((x) & 0x3) << 8) -#define EFUSE_SEL_MASK 0x300 -#define EFUSE_WIFI_SEL_0 0x0 -#define EFUSE_BT_SEL_0 0x1 -#define EFUSE_BT_SEL_1 0x2 -#define EFUSE_BT_SEL_2 0x3 - - -/* 2 8051FWDL */ -/* 2 MCUFWDL */ -#define MCUFWDL_RDY BIT(1) -#define FWDL_ChkSum_rpt BIT(2) -#define WINTINI_RDY BIT(6) -#define RAM_DL_SEL BIT(7) - -/* 2 REG_SYS_CFG */ -#define VENDOR_ID BIT(19) - -#define RTL_ID BIT(23) /* TestChip ID, 1:Test(RLE); 0:MP(RL) */ - - -#define CHIP_VER_RTL_MASK 0xF000 /* Bit 12 ~ 15 */ -#define CHIP_VER_RTL_SHIFT 12 - -/* 2 REG_GPIO_OUTSTS (For RTL8723 only) */ -#define RF_RL_ID (BIT(31)|BIT(30)|BIT(29)|BIT(28)) - -/* */ -/* */ -/* 0x0100h ~ 0x01FFh MACTOP General Configuration */ -/* */ -/* */ - -/* 2 Function Enable Registers */ -/* 2 CR */ -#define HCI_TXDMA_EN BIT(0) -#define HCI_RXDMA_EN BIT(1) -#define TXDMA_EN BIT(2) -#define RXDMA_EN BIT(3) -#define PROTOCOL_EN BIT(4) -#define SCHEDULE_EN BIT(5) -#define MACTXEN BIT(6) -#define MACRXEN BIT(7) -#define ENSWBCN BIT(8) -#define ENSEC BIT(9) -#define CALTMR_EN BIT(10) /* 32k CAL TMR enable */ - -/* Network type */ -#define _NETTYPE(x) (((x) & 0x3) << 16) -#define MASK_NETTYPE 0x30000 -#define NT_LINK_AD_HOC 0x1 -#define NT_LINK_AP 0x2 - -/* 2 PBP - Page Size Register */ -#define _PSRX(x) (x) -#define _PSTX(x) ((x) << 4) - -#define PBP_128 0x1 - -/* 2 TX/RXDMA */ -#define RXDMA_AGG_EN BIT(2) - -/* For normal driver, 0x10C */ -#define _TXDMA_HIQ_MAP(x) (((x)&0x3) << 14) -#define _TXDMA_MGQ_MAP(x) (((x)&0x3) << 12) -#define _TXDMA_BKQ_MAP(x) (((x)&0x3) << 10) -#define _TXDMA_BEQ_MAP(x) (((x)&0x3) << 8) -#define _TXDMA_VIQ_MAP(x) (((x)&0x3) << 6) -#define _TXDMA_VOQ_MAP(x) (((x)&0x3) << 4) - -#define QUEUE_LOW 1 -#define QUEUE_NORMAL 2 -#define QUEUE_HIGH 3 - -/* */ -/* */ -/* 0x0200h ~ 0x027Fh TXDMA Configuration */ -/* */ -/* */ -/* 2 RQPN */ -#define _HPQ(x) ((x) & 0xFF) -#define _LPQ(x) (((x) & 0xFF) << 8) -#define _PUBQ(x) (((x) & 0xFF) << 16) -#define _NPQ(x) ((x) & 0xFF) /* NOTE: in RQPN_NPQ register */ - -#define LD_RQPN BIT(31) - -/* 2 AUTO_LLT */ -#define BIT_AUTO_INIT_LLT BIT(16) - -/* */ -/* */ -/* 0x0280h ~ 0x028Bh RX DMA Configuration */ -/* */ -/* */ - -/* 2 REG_RXDMA_CONTROL, 0x0286h */ -/* Write only. When this bit is set, RXDMA will decrease RX PKT counter by one. Before */ -/* this bit is polled, FW shall update RXFF_RD_PTR first. This register is write pulse and auto clear. */ -/* define RXPKT_RELEASE_POLL BIT(0) */ -/* Read only. When RXMA finishes on-going DMA operation, RXMDA will report idle state in */ -/* this bit. FW can start releasing packets after RXDMA entering idle mode. */ -/* define RXDMA_IDLE BIT(1) */ -/* When this bit is set, RXDMA will enter this mode after on-going RXDMA packet to host */ -/* completed, and stop DMA packet to host. RXDMA will then report Default: 0; */ -/* define RW_RELEASE_EN BIT(2) */ - -/* 2 REG_RXPKT_NUM, 0x0284 */ -#define RXPKT_RELEASE_POLL BIT(16) -#define RXDMA_IDLE BIT(17) -#define RW_RELEASE_EN BIT(18) - -/* */ -/* */ -/* 0x0400h ~ 0x047Fh Protocol Configuration */ -/* */ -/* */ -/* 2 FWHW_TXQ_CTRL */ -#define EN_AMPDU_RTY_NEW BIT(7) - - -/* 2 SPEC SIFS */ -#define _SPEC_SIFS_CCK(x) ((x) & 0xFF) -#define _SPEC_SIFS_OFDM(x) (((x) & 0xFF) << 8) - -/* 2 RL */ -#define RETRY_LIMIT_SHORT_SHIFT 8 -#define RETRY_LIMIT_LONG_SHIFT 0 - -/* */ -/* */ -/* 0x0500h ~ 0x05FFh EDCA Configuration */ -/* */ -/* */ - -#define _LRL(x) ((x) & 0x3F) -#define _SRL(x) (((x) & 0x3F) << 8) - - -/* 2 BCN_CTRL */ -#define EN_TXBCN_RPT BIT(2) -#define EN_BCN_FUNCTION BIT(3) - -#define DIS_ATIM BIT(0) -#define DIS_BCNQ_SUB BIT(1) -#define DIS_TSF_UDT BIT(4) - -/* 2 ACMHWCTRL */ -#define AcmHw_HwEn BIT(0) -#define AcmHw_BeqEn BIT(1) -#define AcmHw_ViqEn BIT(2) -#define AcmHw_VoqEn BIT(3) - -/* */ -/* */ -/* 0x0600h ~ 0x07FFh WMAC Configuration */ -/* */ -/* */ - -/* 2 TCR */ -#define TSFRST BIT(0) - -/* 2 RCR */ -#define AB BIT(3) - -/* 2 SECCFG */ -#define SCR_TxUseDK BIT(0) /* Force Tx Use Default Key */ -#define SCR_RxUseDK BIT(1) /* Force Rx Use Default Key */ -#define SCR_TxEncEnable BIT(2) /* Enable Tx Encryption */ -#define SCR_RxDecEnable BIT(3) /* Enable Rx Decryption */ -#define SCR_TXBCUSEDK BIT(6) /* Force Tx Broadcast packets Use Default Key */ -#define SCR_RXBCUSEDK BIT(7) /* Force Rx Broadcast packets Use Default Key */ -#define SCR_CHK_KEYID BIT(8) - -/* */ -/* */ -/* SDIO Bus Specification */ -/* */ -/* */ - -/* I/O bus domain address mapping */ -#define SDIO_LOCAL_BASE 0x10250000 - -/* SDIO host local register space mapping. */ -#define SDIO_LOCAL_MSK 0x0FFF -#define WLAN_IOREG_MSK 0x7FFF -#define WLAN_FIFO_MSK 0x1FFF /* Aggregation Length[12:0] */ -#define WLAN_RX0FF_MSK 0x0003 - -#define SDIO_LOCAL_DEVICE_ID 0 /* 0b[16], 000b[15:13] */ -#define WLAN_TX_HIQ_DEVICE_ID 4 /* 0b[16], 100b[15:13] */ -#define WLAN_TX_MIQ_DEVICE_ID 5 /* 0b[16], 101b[15:13] */ -#define WLAN_TX_LOQ_DEVICE_ID 6 /* 0b[16], 110b[15:13] */ -#define WLAN_RX0FF_DEVICE_ID 7 /* 0b[16], 111b[15:13] */ -#define WLAN_IOREG_DEVICE_ID 8 /* 1b[16] */ - -/* SDIO Tx Free Page Index */ -#define HI_QUEUE_IDX 0 -#define MID_QUEUE_IDX 1 -#define LOW_QUEUE_IDX 2 -#define PUBLIC_QUEUE_IDX 3 - -#define SDIO_MAX_TX_QUEUE 3 /* HIQ, MIQ and LOQ */ - -#define SDIO_REG_TX_CTRL 0x0000 /* SDIO Tx Control */ -#define SDIO_REG_HIMR 0x0014 /* SDIO Host Interrupt Mask */ -#define SDIO_REG_HISR 0x0018 /* SDIO Host Interrupt Service Routine */ -#define SDIO_REG_RX0_REQ_LEN 0x001C /* RXDMA Request Length */ -#define SDIO_REG_OQT_FREE_PG 0x001E /* OQT Free Page */ -#define SDIO_REG_FREE_TXPG 0x0020 /* Free Tx Buffer Page */ -#define SDIO_REG_HRPWM1 0x0080 /* HCI Request Power Mode 1 */ -#define SDIO_REG_HSUS_CTRL 0x0086 /* SDIO HCI Suspend Control */ - -#define SDIO_HIMR_DISABLED 0 - -/* RTL8723/RTL8188E SDIO Host Interrupt Mask Register */ -#define SDIO_HIMR_RX_REQUEST_MSK BIT(0) -#define SDIO_HIMR_AVAL_MSK BIT(1) - -/* SDIO Host Interrupt Service Routine */ -#define SDIO_HISR_RX_REQUEST BIT(0) -#define SDIO_HISR_AVAL BIT(1) -#define SDIO_HISR_TXERR BIT(2) -#define SDIO_HISR_RXERR BIT(3) -#define SDIO_HISR_TXFOVW BIT(4) -#define SDIO_HISR_RXFOVW BIT(5) -#define SDIO_HISR_TXBCNOK BIT(6) -#define SDIO_HISR_TXBCNERR BIT(7) -#define SDIO_HISR_C2HCMD BIT(17) -#define SDIO_HISR_CPWM1 BIT(18) -#define SDIO_HISR_CPWM2 BIT(19) -#define SDIO_HISR_HSISR_IND BIT(20) -#define SDIO_HISR_GTINT3_IND BIT(21) -#define SDIO_HISR_GTINT4_IND BIT(22) -#define SDIO_HISR_PSTIMEOUT BIT(23) -#define SDIO_HISR_OCPINT BIT(24) - -#define MASK_SDIO_HISR_CLEAR (SDIO_HISR_TXERR |\ - SDIO_HISR_RXERR |\ - SDIO_HISR_TXFOVW |\ - SDIO_HISR_RXFOVW |\ - SDIO_HISR_TXBCNOK |\ - SDIO_HISR_TXBCNERR |\ - SDIO_HISR_C2HCMD |\ - SDIO_HISR_CPWM1 |\ - SDIO_HISR_CPWM2 |\ - SDIO_HISR_HSISR_IND |\ - SDIO_HISR_GTINT3_IND |\ - SDIO_HISR_GTINT4_IND |\ - SDIO_HISR_PSTIMEOUT |\ - SDIO_HISR_OCPINT) - -/* SDIO Tx FIFO related */ -#define SDIO_TX_FREE_PG_QUEUE 4 /* The number of Tx FIFO free page */ - -/* */ -/* */ -/* 0xFE00h ~ 0xFE55h USB Configuration */ -/* */ -/* */ - -/* 2REG_C2HEVT_CLEAR */ -#define C2H_EVT_HOST_CLOSE 0x00 /* Set by driver and notify FW that the driver has read the C2H command message */ -#define C2H_EVT_FW_CLOSE 0xFF /* Set by FW indicating that FW had set the C2H command message and it's not yet read by driver. */ - -/* 2REG_MULTI_FUNC_CTRL(For RTL8723 Only) */ -#define BT_FUNC_EN BIT(18) /* BT function enable */ - -#endif /* __HAL_COMMON_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_data.h b/drivers/staging/rtl8723bs/include/hal_data.h deleted file mode 100644 index f67ca496902a..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_data.h +++ /dev/null @@ -1,276 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_DATA_H__ -#define __HAL_DATA_H__ - -#include "odm_precomp.h" -#include - -#include - -enum rt_ampdu_burst { - RT_AMPDU_BURST_NONE = 0, - RT_AMPDU_BURST_92D = 1, - RT_AMPDU_BURST_88E = 2, - RT_AMPDU_BURST_8812_4 = 3, - RT_AMPDU_BURST_8812_8 = 4, - RT_AMPDU_BURST_8812_12 = 5, - RT_AMPDU_BURST_8812_15 = 6, - RT_AMPDU_BURST_8723B = 7, -}; - -#define CHANNEL_MAX_NUMBER (14) /* 14 is the max channel number */ -#define CHANNEL_MAX_NUMBER_2G 14 -#define MAX_PG_GROUP 13 - -/* Tx Power Limit Table Size */ -#define MAX_REGULATION_NUM 4 -#define MAX_2_4G_BANDWIDTH_NUM 2 -#define MAX_RATE_SECTION_NUM 3 /* CCK:1, OFDM:1, HT:1 */ - -/* duplicate code, will move to ODM ######### */ -/* define IQK_MAC_REG_NUM 4 */ -/* define IQK_ADDA_REG_NUM 16 */ - -/* define IQK_BB_REG_NUM 10 */ - -/* define HP_THERMAL_NUM 8 */ -/* duplicate code, will move to ODM ######### */ - -enum { - SINGLEMAC_SINGLEPHY, /* SMSP */ - DUALMAC_DUALPHY, /* DMDP */ - DUALMAC_SINGLEPHY, /* DMSP */ -}; - -#define PAGE_SIZE_128 128 -#define PAGE_SIZE_256 256 -#define PAGE_SIZE_512 512 - -struct dm_priv { - u8 DM_Type; - -#define DYNAMIC_FUNC_BT BIT(0) - - u8 DMFlag; - u8 InitDMFlag; - /* u8 RSVD_1; */ - - u32 InitODMFlag; - /* Upper and Lower Signal threshold for Rate Adaptive */ - int UndecoratedSmoothedPWDB; - int UndecoratedSmoothedCCK; - int EntryMinUndecoratedSmoothedPWDB; - int EntryMaxUndecoratedSmoothedPWDB; - int MinUndecoratedPWDBForDM; - int LastMinUndecoratedPWDBForDM; - - s32 UndecoratedSmoothedBeacon; - -/* duplicate code, will move to ODM ######### */ - /* for High Power */ - u8 bDynamicTxPowerEnable; - u8 LastDTPLvl; - u8 DynamicTxHighPowerLvl;/* Add by Jacken Tx Power Control for Near/Far Range 2008/03/06 */ - - /* for tx power tracking */ - u8 bTXPowerTracking; - u8 TXPowercount; - u8 bTXPowerTrackingInit; - u8 TxPowerTrackControl; /* for mp mode, turn off txpwrtracking as default */ - u8 TM_Trigger; - - u8 ThermalMeter[2]; /* ThermalMeter, index 0 for RFIC0, and 1 for RFIC1 */ - u8 ThermalValue; - u8 ThermalValue_LCK; - u8 ThermalValue_IQK; - u8 ThermalValue_DPK; - u8 bRfPiEnable; - /* u8 RSVD_2; */ - - /* for APK */ - u32 APKoutput[2][2]; /* path A/B; output1_1a/output1_2a */ - u8 bAPKdone; - u8 bAPKThermalMeterIgnore; - u8 bDPdone; - u8 bDPPathAOK; - u8 bDPPathBOK; - /* u8 RSVD_3; */ - /* u8 RSVD_4; */ - /* u8 RSVD_5; */ - - /* for IQK */ - u32 ADDA_backup[IQK_ADDA_REG_NUM]; - u32 IQK_MAC_backup[IQK_MAC_REG_NUM]; - u32 IQK_BB_backup_recover[9]; - u32 IQK_BB_backup[IQK_BB_REG_NUM]; - - u8 PowerIndex_backup[6]; - u8 OFDM_index[2]; - - u8 bCCKinCH14; - u8 CCK_index; - u8 bDoneTxpower; - u8 CCK_index_HP; - - u8 OFDM_index_HP[2]; - u8 ThermalValue_HP[HP_THERMAL_NUM]; - u8 ThermalValue_HP_index; - /* u8 RSVD_6; */ - - /* for TxPwrTracking2 */ - s32 RegE94; - s32 RegE9C; - s32 RegEB4; - s32 RegEBC; - - u32 TXPowerTrackingCallbackCnt; /* cosa add for debug */ - - u32 prv_traffic_idx; /* edca turbo */ -/* duplicate code, will move to ODM ######### */ - - /* Add for Reading Initial Data Rate SEL Register 0x484 during watchdog. Using for fill tx desc. 2011.3.21 by Thomas */ - u8 INIDATA_RATE[32]; -}; - - -struct hal_com_data { - u16 FirmwareVersion; - u16 FirmwareVersionRev; - u16 FirmwareSubVersion; - u16 FirmwareSignature; - - /* current WIFI_PHY values */ - enum wireless_mode CurrentWirelessMode; - enum channel_width CurrentChannelBW; - u8 CurrentChannel; - u8 CurrentCenterFrequencyIndex1; - u8 nCur40MhzPrimeSC;/* Control channel sub-carrier */ - u8 nCur80MhzPrimeSC; /* used for primary 40MHz of 80MHz mode */ - - u16 CustomerID; - u16 BasicRateSet; - u32 ReceiveConfig; - - /* rf_ctrl */ - u8 PackageType; - - /* EEPROM setting. */ - u8 EEPROMRegulatory; - u8 EEPROMThermalMeter; - u8 EEPROMBluetoothCoexist; - u8 EEPROMBluetoothAntNum; - u8 bDisableSWChannelPlan; /* flag of disable software change channel plan */ - - bool EepromOrEfuse; - u8 EfuseUsedPercentage; - u16 EfuseUsedBytes; - struct efuse_hal EfuseHal; - - /* 3 [2.4G] */ - u8 Index24G_CCK_Base[MAX_RF_PATH][CHANNEL_MAX_NUMBER]; - u8 Index24G_BW40_Base[MAX_RF_PATH][CHANNEL_MAX_NUMBER]; - /* If only one tx, only BW20 and OFDM are used. */ - s8 OFDM_24G_Diff[MAX_RF_PATH][MAX_TX_COUNT]; - s8 BW20_24G_Diff[MAX_RF_PATH][MAX_TX_COUNT]; - s8 BW40_24G_Diff[MAX_RF_PATH][MAX_TX_COUNT]; - - u8 Regulation2_4G; - - /* TX power by rate table */ - /* RF: at most 2 = AB = 0/1 */ - /* CCK = 0 OFDM = 1 HT-MCS 0-7 = 2 */ - s8 TxPwrByRateOffset[MAX_RF_PATH_NUM][TX_PWR_BY_RATE_NUM_RATE]; - /* */ - - /* Power Limit Table for 2.4G */ - s8 TxPwrLimit_2_4G[MAX_REGULATION_NUM] - [MAX_2_4G_BANDWIDTH_NUM] - [MAX_RATE_SECTION_NUM] - [CHANNEL_MAX_NUMBER_2G] - [MAX_RF_PATH_NUM]; - - /* Store the original power by rate value of the base of each rate section of rf path A & B */ - u8 TxPwrByRateBase2_4G[MAX_RF_PATH_NUM][MAX_RATE_SECTION_NUM]; - - u8 CrystalCap; - - u8 TypeGLNA; - u8 TypeGPA; - u8 TypeALNA; - u8 TypeAPA; - u8 RFEType; - u8 BoardType; - bool bLCKInProgress; - - bool bSwChnl; - bool bSetChnlBW; - - u8 TxPowerTrackControl; /* for mp mode, turn off txpwrtracking as default */ - - u32 AcParam_BE; /* Original parameter for BE, use for EDCA turbo. */ - - struct bb_register_def PHYRegDef[4]; /* Radio A/B/C/D */ - - u32 RfRegChnlVal[2]; - - /* for host message to fw */ - u8 LastHMEBoxNum; - - u8 fw_ractrl; - /* Beacon function related global variable. */ - u8 RegFwHwTxQCtrl; - u8 RegReg542; - u16 RegRRSR; - - u8 CurAntenna; - u8 AntDivCfg; - u8 AntDetection; - u8 ant_path; /* for 8723B s0/s1 selection */ - - u8 u1ForcedIgiLb; /* forced IGI lower bound */ - - /* 2010/08/09 MH Add CU power down mode. */ - bool pwrdown; - - u8 OutEpQueueSel; - u8 OutEpNumber; - - /* Auto FSM to Turn On, include clock, isolation, power control for MAC only */ - u8 bMacPwrCtrlOn; - - enum rt_ampdu_burst AMPDUBurstMode; /* 92C maybe not use, but for compile successfully */ - - u32 sdio_himr; - u32 sdio_hisr; - - /* SDIO Tx FIFO related. */ - /* HIQ, MID, LOW, PUB free pages; padapter->xmitpriv.free_txpg */ - u8 SdioTxFIFOFreePage[SDIO_TX_FREE_PG_QUEUE]; - u8 SdioTxOQTMaxFreeSpace; - u8 SdioTxOQTFreeSpace; - - - /* SDIO Rx FIFO related. */ - u8 SdioRxFIFOCnt; - u16 SdioRxFIFOSize; - - u32 sdio_tx_max_len[SDIO_MAX_TX_QUEUE];/* H, N, L, used for sdio tx aggregation max length per queue */ - - struct dm_priv dmpriv; - struct dm_odm_t odmpriv; - - /* For bluetooth co-existence */ - struct bt_coexist bt_coexist; - - /* Chip version information */ - bool chip_normal; /* true - normal chip, false - test chip */ -}; - -#define GET_HAL_DATA(__padapter) ((struct hal_com_data *)((__padapter)->HalData)) - -#endif /* __HAL_DATA_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_intf.h b/drivers/staging/rtl8723bs/include/hal_intf.h deleted file mode 100644 index a7ae8c006f0c..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_intf.h +++ /dev/null @@ -1,250 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_INTF_H__ -#define __HAL_INTF_H__ - - -enum { - RTW_PCIE = BIT(0), - RTW_USB = BIT(1), - RTW_SDIO = BIT(2), - RTW_GSPI = BIT(3), -}; - -enum { - HW_VAR_MEDIA_STATUS, - HW_VAR_MEDIA_STATUS1, - HW_VAR_SET_OPMODE, - HW_VAR_MAC_ADDR, - HW_VAR_BSSID, - HW_VAR_INIT_RTS_RATE, - HW_VAR_BASIC_RATE, - HW_VAR_TXPAUSE, - HW_VAR_BCN_FUNC, - HW_VAR_CORRECT_TSF, - HW_VAR_CHECK_BSSID, - HW_VAR_MLME_DISCONNECT, - HW_VAR_MLME_SITESURVEY, - HW_VAR_MLME_JOIN, - HW_VAR_ON_RCR_AM, - HW_VAR_OFF_RCR_AM, - HW_VAR_BEACON_INTERVAL, - HW_VAR_SLOT_TIME, - HW_VAR_RESP_SIFS, - HW_VAR_ACK_PREAMBLE, - HW_VAR_SEC_CFG, - HW_VAR_SEC_DK_CFG, - HW_VAR_BCN_VALID, - HW_VAR_RF_TYPE, - HW_VAR_DM_FLAG, - HW_VAR_DM_FUNC_OP, - HW_VAR_DM_FUNC_SET, - HW_VAR_DM_FUNC_CLR, - HW_VAR_CAM_EMPTY_ENTRY, - HW_VAR_CAM_INVALID_ALL, - HW_VAR_CAM_WRITE, - HW_VAR_CAM_READ, - HW_VAR_AC_PARAM_VO, - HW_VAR_AC_PARAM_VI, - HW_VAR_AC_PARAM_BE, - HW_VAR_AC_PARAM_BK, - HW_VAR_ACM_CTRL, - HW_VAR_AMPDU_MIN_SPACE, - HW_VAR_AMPDU_FACTOR, - HW_VAR_RXDMA_AGG_PG_TH, - HW_VAR_SET_RPWM, - HW_VAR_CPWM, - HW_VAR_H2C_FW_PWRMODE, - HW_VAR_H2C_PS_TUNE_PARAM, - HW_VAR_H2C_FW_JOINBSSRPT, - HW_VAR_FWLPS_RF_ON, - HW_VAR_H2C_FW_P2P_PS_OFFLOAD, - HW_VAR_TDLS_WRCR, - HW_VAR_TDLS_INIT_CH_SEN, - HW_VAR_TDLS_RS_RCR, - HW_VAR_TDLS_DONE_CH_SEN, - HW_VAR_INITIAL_GAIN, - HW_VAR_TRIGGER_GPIO_0, - HW_VAR_BT_SET_COEXIST, - HW_VAR_BT_ISSUE_DELBA, - HW_VAR_CURRENT_ANTENNA, - HW_VAR_ANTENNA_DIVERSITY_LINK, - HW_VAR_ANTENNA_DIVERSITY_SELECT, - HW_VAR_SWITCH_EPHY_WoWLAN, - HW_VAR_EFUSE_USAGE, - HW_VAR_EFUSE_BYTES, - HW_VAR_EFUSE_BT_USAGE, - HW_VAR_EFUSE_BT_BYTES, - HW_VAR_FIFO_CLEARN_UP, - HW_VAR_CHECK_TXBUF, - HW_VAR_PCIE_STOP_TX_DMA, - HW_VAR_APFM_ON_MAC, /* Auto FSM to Turn On, include clock, isolation, power control for MAC only */ - /* The valid upper nav range for the HW updating, if the true value is larger than the upper range, the HW won't update it. */ - /* Unit in microsecond. 0 means disable this function. */ - HW_VAR_SYS_CLKR, - HW_VAR_NAV_UPPER, - HW_VAR_C2H_HANDLE, - HW_VAR_RPT_TIMER_SETTING, - HW_VAR_TX_RPT_MAX_MACID, - HW_VAR_H2C_MEDIA_STATUS_RPT, - HW_VAR_CHK_HI_QUEUE_EMPTY, - HW_VAR_DL_BCN_SEL, - HW_VAR_AMPDU_MAX_TIME, - HW_VAR_WIRELESS_MODE, - HW_VAR_USB_MODE, - HW_VAR_PORT_SWITCH, - HW_VAR_DM_IN_LPS, - HW_VAR_SET_REQ_FW_PS, - HW_VAR_FW_PS_STATE, - HW_VAR_SOUNDING_ENTER, - HW_VAR_SOUNDING_LEAVE, - HW_VAR_SOUNDING_RATE, - HW_VAR_SOUNDING_STATUS, - HW_VAR_SOUNDING_FW_NDPA, - HW_VAR_SOUNDING_CLK, - HW_VAR_DL_RSVD_PAGE, - HW_VAR_MACID_SLEEP, - HW_VAR_MACID_WAKEUP, -}; - -enum hal_def_variable { - HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, - HAL_DEF_IS_SUPPORT_ANT_DIV, - HAL_DEF_CURRENT_ANTENNA, - HAL_DEF_DRVINFO_SZ, - HAL_DEF_MAX_RECVBUF_SZ, - HAL_DEF_RX_PACKET_OFFSET, - HAL_DEF_DBG_DUMP_RXPKT,/* for dbg */ - HAL_DEF_DBG_DM_FUNC,/* for dbg */ - HAL_DEF_RA_DECISION_RATE, - HAL_DEF_RA_SGI, - HAL_DEF_PT_PWR_STATUS, - HAL_DEF_TX_LDPC, /* LDPC support */ - HAL_DEF_RX_LDPC, /* LDPC support */ - HAL_DEF_TX_STBC, /* TX STBC support */ - HAL_DEF_RX_STBC, /* RX STBC support */ - HAL_DEF_EXPLICIT_BEAMFORMER,/* Explicit Compressed Steering Capable */ - HAL_DEF_EXPLICIT_BEAMFORMEE,/* Explicit Compressed Beamforming Feedback Capable */ - HW_VAR_MAX_RX_AMPDU_FACTOR, - HW_DEF_RA_INFO_DUMP, - HAL_DEF_DBG_DUMP_TXPKT, - HW_DEF_FA_CNT_DUMP, - HW_DEF_ODM_DBG_FLAG, - HW_DEF_ODM_DBG_LEVEL, - HAL_DEF_TX_PAGE_SIZE, - HAL_DEF_TX_PAGE_BOUNDARY, - HAL_DEF_TX_PAGE_BOUNDARY_WOWLAN, - HAL_DEF_ANT_DETECT,/* to do for 8723a */ - HAL_DEF_PCI_SUUPORT_L1_BACKDOOR, /* Determine if the L1 Backdoor setting is turned on. */ - HAL_DEF_PCI_AMD_L1_SUPPORT, - HAL_DEF_PCI_ASPM_OSC, /* Support for ASPM OSC, added by Roger, 2013.03.27. */ - HAL_DEF_MACID_SLEEP, /* Support for MACID sleep */ -}; - -enum hal_odm_variable { - HAL_ODM_STA_INFO, - HAL_ODM_P2P_STATE, - HAL_ODM_WIFI_DISPLAY_STATE, - HAL_ODM_NOISE_MONITOR, -}; - -typedef s32 (*c2h_id_filter)(u8 *c2h_evt); - -#define RF_CHANGE_BY_INIT 0 -#define RF_CHANGE_BY_IPS BIT(28) -#define RF_CHANGE_BY_PS BIT(29) -#define RF_CHANGE_BY_HW BIT(30) -#define RF_CHANGE_BY_SW BIT(31) - -#define GET_EEPROM_EFUSE_PRIV(adapter) (&adapter->eeprompriv) -#define is_boot_from_eeprom(adapter) (adapter->eeprompriv.EepromOrEfuse) - -#define Rx_Pairwisekey 0x01 -#define Rx_GTK 0x02 -#define Rx_DisAssoc 0x04 -#define Rx_DeAuth 0x08 -#define Rx_ARPReq 0x09 -#define FWDecisionDisconnect 0x10 -#define Rx_MagicPkt 0x21 -#define Rx_UnicastPkt 0x22 -#define Rx_PatternPkt 0x23 -#define RX_PNOWakeUp 0x55 -#define AP_WakeUp 0x66 - -uint rtw_hal_init(struct adapter *padapter); -uint rtw_hal_deinit(struct adapter *padapter); -void rtw_hal_stop(struct adapter *padapter); -void rtw_hal_set_hwreg(struct adapter *padapter, u8 variable, u8 *val); -void rtw_hal_get_hwreg(struct adapter *padapter, u8 variable, u8 *val); - -void rtw_hal_set_hwreg_with_buf(struct adapter *padapter, u8 variable, u8 *pbuf, int len); - -u8 rtw_hal_get_def_var(struct adapter *padapter, enum hal_def_variable eVariable, void *pValue); - -void rtw_hal_set_odm_var(struct adapter *padapter, enum hal_odm_variable eVariable, void *pValue1, bool bSet); - -u8 rtw_hal_check_ips_status(struct adapter *padapter); - -int rtw_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe); -s32 rtw_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe); -s32 rtw_hal_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe); - -s32 rtw_hal_init_xmit_priv(struct adapter *padapter); -void rtw_hal_free_xmit_priv(struct adapter *padapter); - -s32 rtw_hal_init_recv_priv(struct adapter *padapter); -void rtw_hal_free_recv_priv(struct adapter *padapter); - -void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level); -void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level); - -void beacon_timing_control(struct adapter *padapter); - -u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask); -void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data); -u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask); -void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data); - -#define PHY_QueryBBReg(Adapter, RegAddr, BitMask) rtw_hal_read_bbreg((Adapter), (RegAddr), (BitMask)) -#define PHY_SetBBReg(Adapter, RegAddr, BitMask, Data) rtw_hal_write_bbreg((Adapter), (RegAddr), (BitMask), (Data)) -#define PHY_QueryRFReg(Adapter, eRFPath, RegAddr, BitMask) rtw_hal_read_rfreg((Adapter), (eRFPath), (RegAddr), (BitMask)) -#define PHY_SetRFReg(Adapter, eRFPath, RegAddr, BitMask, Data) rtw_hal_write_rfreg((Adapter), (eRFPath), (RegAddr), (BitMask), (Data)) - -#define PHY_SetMacReg PHY_SetBBReg -#define PHY_QueryMacReg PHY_QueryBBReg - -void rtw_hal_set_chan(struct adapter *padapter, u8 channel); -void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel, enum channel_width Bandwidth, u8 Offset40, u8 Offset80); -void rtw_hal_dm_watchdog(struct adapter *padapter); -void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter); - -s32 rtw_hal_xmit_thread_handler(struct adapter *padapter); - -void rtw_hal_notch_filter(struct adapter *adapter, bool enable); - -bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf); -s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt); -c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter); - -s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid); -s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid); - -s32 rtw_hal_fill_h2c_cmd(struct adapter *adapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer); - -void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val); -void GetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val); -void SetHwRegWithBuf8723B(struct adapter *padapter, u8 variable, u8 *pbuf, int len); -u8 GetHalDefVar8723BSDIO(struct adapter *Adapter, enum hal_def_variable eVariable, void *pValue); -void UpdateHalRAMask8723B(struct adapter *padapter, u32 mac_id, u8 rssi_level); -void rtl8723b_SetBeaconRelatedRegisters(struct adapter *padapter); -void Hal_EfusePowerSwitch(struct adapter *padapter, u8 PwrState); -void Hal_ReadEFuse(struct adapter *padapter, u8 efuseType, u16 _offset, - u16 _size_byte, u8 *pbuf); -void Hal_GetEfuseDefinition(struct adapter *padapter, u8 efuseType, u8 type, - void *pOut); -void hal_notch_filter_8723b(struct adapter *adapter, bool enable); -#endif /* __HAL_INTF_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_pg.h b/drivers/staging/rtl8723bs/include/hal_pg.h deleted file mode 100644 index 32e66fe451b0..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_pg.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __HAL_PG_H__ -#define __HAL_PG_H__ - -#define MAX_RF_PATH 4 -/* MAX_TX_COUNT must always be set to 4, otherwise the read efuse table - * sequence will be wrong. - */ -#define MAX_TX_COUNT 4 - -/* TX power by rate table. */ -/* RF: = AB = 0/1 */ -/* CCK = 0 OFDM = 1 HT-MCS 0-7 = 2 */ -#define TX_PWR_BY_RATE_NUM_RATE 84 -#define MAX_RF_PATH_NUM 2 -#define MAX_CHNL_GROUP_24G 6 -#define EEPROM_DEFAULT_BOARD_OPTION 0x00 - -/* EEPROM/Efuse PG Offset for 8723BE/8723BU/8723BS */ -/* 0x10 ~ 0x63 = TX power area. */ -#define EEPROM_TX_PWR_INX_8723B 0x10 -/* New EFUSE default value */ -#define EEPROM_DEFAULT_24G_INDEX 0x2D -#define EEPROM_DEFAULT_24G_HT20_DIFF 0X02 -#define EEPROM_DEFAULT_24G_OFDM_DIFF 0X04 -#define EEPROM_Default_ThermalMeter_8723B 0x18 -#define EEPROM_Default_CrystalCap_8723B 0x20 - -#define EEPROM_ChannelPlan_8723B 0xB8 -#define EEPROM_XTAL_8723B 0xB9 -#define EEPROM_THERMAL_METER_8723B 0xBA - -#define EEPROM_RF_BOARD_OPTION_8723B 0xC1 -#define EEPROM_RF_BT_SETTING_8723B 0xC3 -#define EEPROM_DEFAULT_DIFF 0XFE - -/* RTL8723BS */ -#define EEPROM_MAC_ADDR_8723BS 0x11A -#define EEPROM_Voltage_ADDR_8723B 0x8 -#define RTL_EEPROM_ID 0x8129 - -struct TxPowerInfo24G { - u8 IndexCCK_Base[MAX_RF_PATH][MAX_CHNL_GROUP_24G]; - u8 IndexBW40_Base[MAX_RF_PATH][MAX_CHNL_GROUP_24G]; - /* If only one tx, only BW20 and OFDM are used. */ - s8 CCK_Diff[MAX_RF_PATH][MAX_TX_COUNT]; - s8 OFDM_Diff[MAX_RF_PATH][MAX_TX_COUNT]; - s8 BW20_Diff[MAX_RF_PATH][MAX_TX_COUNT]; - s8 BW40_Diff[MAX_RF_PATH][MAX_TX_COUNT]; -}; - -enum { - Ant_x2 = 0, - Ant_x1 = 1 -}; - -#endif diff --git a/drivers/staging/rtl8723bs/include/hal_phy.h b/drivers/staging/rtl8723bs/include/hal_phy.h deleted file mode 100644 index abc0f27fdaa4..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_phy.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_PHY_H__ -#define __HAL_PHY_H__ -/* */ -/* Antenna detection method, i.e., using single tone detection or RSSI reported from each antenna detected. */ -/* Added by Roger, 2013.05.22. */ -/* */ -#define ANT_DETECT_BY_SINGLE_TONE BIT(0) -#define ANT_DETECT_BY_RSSI BIT(1) -#define IS_ANT_DETECT_SUPPORT_SINGLE_TONE(__Adapter) ((GET_HAL_DATA(__Adapter)->AntDetection) & ANT_DETECT_BY_SINGLE_TONE) -#define IS_ANT_DETECT_SUPPORT_RSSI(__Adapter) ((GET_HAL_DATA(__Adapter)->AntDetection) & ANT_DETECT_BY_RSSI) - - -/*--------------------------Define Parameters-------------------------------*/ -enum { - RF_TYPE_MIN = 0, /* 0 */ - RF_8225 = 1, /* 1 11b/g RF for verification only */ - RF_8256 = 2, /* 2 11b/g/n */ - RF_8258 = 3, /* 3 11a/b/g/n RF */ - RF_6052 = 4, /* 4 11b/g/n RF */ - RF_PSEUDO_11N = 5, /* 5, It is a temporality RF. */ - RF_TYPE_MAX -}; - -enum rf_path { - RF_PATH_A = 0, - RF_PATH_B, - RF_PATH_MAX -}; - -#define TX_1S 0 -#define TX_2S 1 -#define TX_3S 2 -#define TX_4S 3 - -#define RF_PATH_MAX_92C_88E 2 -#define RF_PATH_MAX_90_8812 4 /* Max RF number 90 support */ - -enum wireless_mode { - WIRELESS_MODE_UNKNOWN = 0x00, - WIRELESS_MODE_B = 0x02, - WIRELESS_MODE_G = 0x04, - WIRELESS_MODE_AUTO = 0x08, - WIRELESS_MODE_N_24G = 0x10, - WIRELESS_MODE_AC_24G = 0x80, - WIRELESS_MODE_AC_ONLY = 0x100, -}; - -enum SwChnlCmdID { - CmdID_End, - CmdID_SetTxPowerLevel, - CmdID_BBRegWrite10, - CmdID_WritePortUlong, - CmdID_WritePortUshort, - CmdID_WritePortUchar, - CmdID_RF_WriteReg, -}; - -struct SwChnlCmd { - enum SwChnlCmdID CmdID; - u32 Para1; - u32 Para2; - u32 msDelay; -}; - -/*--------------------------Exported Function prototype---------------------*/ - -#endif /* __HAL_COMMON_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_phy_cfg.h b/drivers/staging/rtl8723bs/include/hal_phy_cfg.h deleted file mode 100644 index 07bf0a8d019a..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_phy_cfg.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __INC_HAL8723BPHYCFG_H__ -#define __INC_HAL8723BPHYCFG_H__ - -/*--------------------------Define Parameters-------------------------------*/ -#define LOOP_LIMIT 5 -#define MAX_STALL_TIME 50 /* us */ -#define AntennaDiversityValue 0x80 /* Adapter->bSoftwareAntennaDiversity ? 0x00:0x80) */ -#define MAX_TXPWR_IDX_NMODE_92S 63 -#define Reset_Cnt_Limit 3 - -#define MAX_AGGR_NUM 0x07 - - -/*--------------------------Define Parameters End-------------------------------*/ - - -/*------------------------------Define structure----------------------------*/ - -/*------------------------------Define structure End----------------------------*/ - -/*--------------------------Exported Function prototype---------------------*/ -u32 PHY_QueryBBReg_8723B(struct adapter *Adapter, u32 RegAddr, u32 BitMask); - -void PHY_SetBBReg_8723B(struct adapter *Adapter, u32 RegAddr, - u32 BitMask, u32 Data); - -u32 PHY_QueryRFReg_8723B(struct adapter *Adapter, u8 eRFPath, - u32 RegAddr, u32 BitMask); - -void PHY_SetRFReg_8723B(struct adapter *Adapter, u8 eRFPath, - u32 RegAddr, u32 BitMask, u32 Data); - -/* MAC/BB/RF HAL config */ -int PHY_BBConfig8723B(struct adapter *Adapter); - -int PHY_RFConfig8723B(struct adapter *Adapter); - -s32 PHY_MACConfig8723B(struct adapter *padapter); - -void PHY_SetTxPowerIndex(struct adapter *Adapter, u32 PowerIndex, - u8 RFPath, u8 Rate); - -u8 PHY_GetTxPowerIndex(struct adapter *padapter, u8 RFPath, u8 Rate, - enum channel_width BandWidth, u8 Channel); - -void PHY_SetTxPowerLevel8723B(struct adapter *Adapter, u8 channel); - -/* Call after initialization */ -void PHY_SwChnl8723B(struct adapter *Adapter, u8 channel); - -void PHY_SetSwChnlBWMode8723B(struct adapter *Adapter, u8 channel, - enum channel_width Bandwidth, - u8 Offset40, u8 Offset80); - -/*--------------------------Exported Function prototype End---------------------*/ - -#endif diff --git a/drivers/staging/rtl8723bs/include/hal_phy_reg.h b/drivers/staging/rtl8723bs/include/hal_phy_reg.h deleted file mode 100644 index 682cdd6655ab..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_phy_reg.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_PHY_REG_H__ -#define __HAL_PHY_REG_H__ - -/* for PutRFRegsetting & GetRFRegSetting BitMask */ -/* if (RTL92SE_FPGA_VERIFY == 1) */ -/* define bRFRegOffsetMask 0xfff */ -/* else */ -#define bRFRegOffsetMask 0xfffff -/* endif */ - -#endif /* __HAL_PHY_REG_H__ */ diff --git a/drivers/staging/rtl8723bs/include/hal_pwr_seq.h b/drivers/staging/rtl8723bs/include/hal_pwr_seq.h deleted file mode 100644 index 9639eef8a51d..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_pwr_seq.h +++ /dev/null @@ -1,226 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef REALTEK_POWER_SEQUENCE_8723B -#define REALTEK_POWER_SEQUENCE_8723B - -#include "HalPwrSeqCmd.h" - -/* - Check document WM-20130815-JackieLau-RTL8723B_Power_Architecture v08.vsd - There are 6 HW Power States: - 0: POFF--Power Off - 1: PDN--Power Down - 2: CARDEMU--Card Emulation - 3: ACT--Active Mode - 4: LPS--Low Power State - 5: SUS--Suspend - - The transition from different states are defined below - TRANS_CARDEMU_TO_ACT - TRANS_ACT_TO_CARDEMU - TRANS_CARDEMU_TO_SUS - TRANS_SUS_TO_CARDEMU - TRANS_CARDEMU_TO_PDN - TRANS_ACT_TO_LPS - TRANS_LPS_TO_ACT - - TRANS_END -*/ -#define RTL8723B_TRANS_CARDEMU_TO_ACT_STEPS 26 -#define RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS 15 -#define RTL8723B_TRANS_CARDEMU_TO_SUS_STEPS 15 -#define RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS 15 -#define RTL8723B_TRANS_ACT_TO_LPS_STEPS 15 -#define RTL8723B_TRANS_LPS_TO_ACT_STEPS 15 -#define RTL8723B_TRANS_ACT_TO_SWLPS_STEPS 22 -#define RTL8723B_TRANS_SWLPS_TO_ACT_STEPS 15 -#define RTL8723B_TRANS_END_STEPS 1 - - -#define RTL8723B_TRANS_CARDEMU_TO_ACT \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0020, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)}, /*0x20[0] = 1b'1 enable LDOA12 MACRO block for all interface*/ \ - {0x0067, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0}, /*0x67[0] = 0 to disable BT_GPS_SEL pins*/ \ - {0x0001, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_DELAY, 1, PWRSEQ_DELAY_MS},/*Delay 1ms*/ \ - {0x0000, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(5), 0}, /*0x00[5] = 1b'0 release analog Ips to digital , 1:isolation*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, (BIT(4)|BIT(3)|BIT(2)), 0},/* disable SW LPS 0x04[10]= 0 and WLSUS_EN 0x04[11]= 0*/ \ - {0x0075, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/* Disable USB suspend */ \ - {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(1), BIT(1)},/* wait till 0x04[17] = 1 power ready*/ \ - {0x0075, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), (0)},/* Enable USB suspend */ \ - {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/* release WLON reset 0x04[16]= 1*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), 0},/* disable HWPDN 0x04[15]= 0*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, (BIT(4)|BIT(3)), 0},/* disable WL suspend*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/* polling until return 0*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(0), 0},/**/ \ - {0x0010, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(6), BIT(6)},/* Enable WL control XTAL setting*/ \ - {0x0049, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)},/*Enable falling edge triggering interrupt*/\ - {0x0063, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)},/*Enable GPIO9 interrupt mode*/\ - {0x0062, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), 0},/*Enable GPIO9 input mode*/\ - {0x0058, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/*Enable HSISR GPIO[C:0] interrupt*/\ - {0x005A, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)},/*Enable HSISR GPIO9 interrupt*/\ - {0x0068, PWR_CUT_TESTCHIP_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3), BIT(3)},/*For GPIO9 internal pull high setting by test chip*/\ - {0x0069, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(6), BIT(6)},/*For GPIO9 internal pull high setting*/\ - - -#define RTL8723B_TRANS_ACT_TO_CARDEMU \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x001F, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0},/*0x1F[7:0] = 0 turn off RF*/ \ - {0x0049, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), 0},/*Enable rising edge triggering interrupt*/ \ - {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/* release WLON reset 0x04[16]= 1*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)}, /*0x04[9] = 1 turn off MAC by HW state machine*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(1), 0}, /*wait till 0x04[9] = 0 polling until return 0 to disable*/ \ - {0x0010, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(6), 0},/* Enable BT control XTAL setting*/\ - {0x0000, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(5), BIT(5)}, /*0x00[5] = 1b'1 analog Ips to digital , 1:isolation*/ \ - {0x0020, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0}, /*0x20[0] = 1b'0 disable LDOA12 MACRO block*/\ - - -#define RTL8723B_TRANS_CARDEMU_TO_SUS \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4)|BIT(3), (BIT(4)|BIT(3))}, /*0x04[12:11] = 2b'11 enable WL suspend for PCIe*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3)|BIT(4), BIT(3)}, /*0x04[12:11] = 2b'01 enable WL suspend*/ \ - {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)}, /*0x23[4] = 1b'1 12H LDO enter sleep mode*/ \ - {0x0007, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x20}, /*0x07[7:0] = 0x20 SDIO SOP option to disable BG/MB/ACK/SWR*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3)|BIT(4), BIT(3)|BIT(4)}, /*0x04[12:11] = 2b'11 enable WL suspend for PCIe*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), BIT(0)}, /*Set SDIO suspend local register*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), 0}, /*wait power state to suspend*/ - -#define RTL8723B_TRANS_SUS_TO_CARDEMU \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3) | BIT(7), 0}, /*clear suspend enable and power down enable*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), 0}, /*Set SDIO suspend local register*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), BIT(1)}, /*wait power state to suspend*/\ - {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0}, /*0x23[4] = 1b'0 12H LDO enter normal mode*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3)|BIT(4), 0}, /*0x04[12:11] = 2b'01enable WL suspend*/ - -#define RTL8723B_TRANS_CARDEMU_TO_CARDDIS \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, omments here*/ \ - {0x0007, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x20}, /*0x07 = 0x20 , SOP option to disable BG/MB*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3)|BIT(4), BIT(3)}, /*0x04[12:11] = 2b'01 enable WL suspend*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(2), BIT(2)}, /*0x04[10] = 1, enable SW LPS*/ \ - {0x004A, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 1}, /*0x48[16] = 1 to enable GPIO9 as EXT WAKEUP*/ \ - {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)}, /*0x23[4] = 1b'1 12H LDO enter sleep mode*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), BIT(0)}, /*Set SDIO suspend local register*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), 0}, /*wait power state to suspend*/ - -#define RTL8723B_TRANS_CARDDIS_TO_CARDEMU \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3) | BIT(7), 0}, /*clear suspend enable and power down enable*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), 0}, /*Set SDIO suspend local register*/ \ - {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), BIT(1)}, /*wait power state to suspend*/\ - {0x004A, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0}, /*0x48[16] = 0 to disable GPIO9 as EXT WAKEUP*/ \ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3)|BIT(4), 0}, /*0x04[12:11] = 2b'01enable WL suspend*/\ - {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0}, /*0x23[4] = 1b'0 12H LDO enter normal mode*/ \ - {0x0301, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0},/*PCIe DMA start*/ - - -#define RTL8723B_TRANS_CARDEMU_TO_PDN \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)}, /*0x23[4] = 1b'1 12H LDO enter sleep mode*/ \ - {0x0007, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK|PWR_INTF_USB_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x20}, /*0x07[7:0] = 0x20 SOP option to disable BG/MB/ACK/SWR*/ \ - {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/* 0x04[16] = 0*/\ - {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), BIT(7)},/* 0x04[15] = 1*/ - -#define RTL8723B_TRANS_ACT_TO_LPS \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0301, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0xFF},/*PCIe DMA stop*/ \ - {0x0522, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0xFF},/*Tx Pause*/ \ - {0x05F8, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, 0xFF, 0},/*Should be zero if no packet is transmitting*/ \ - {0x05F9, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, 0xFF, 0},/*Should be zero if no packet is transmitting*/ \ - {0x05FA, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, 0xFF, 0},/*Should be zero if no packet is transmitting*/ \ - {0x05FB, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, 0xFF, 0},/*Should be zero if no packet is transmitting*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/*CCK and OFDM are disabled, and clock are gated*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_DELAY, 0, PWRSEQ_DELAY_US},/*Delay 1us*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), 0},/*Whole BB is reset*/ \ - {0x0100, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x03},/*Reset MAC TRX*/ \ - {0x0101, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), 0},/*check if removed later*/ \ - {0x0093, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x00},/*When driver enter Sus/ Disable, enable LOP for BT*/ \ - {0x0553, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(5), BIT(5)},/*Respond TxOK to scheduler*/ \ - - -#define RTL8723B_TRANS_LPS_TO_ACT \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0080, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_SDIO, PWR_CMD_WRITE, 0xFF, 0x84}, /*SDIO RPWM*/\ - {0xFE58, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x84}, /*USB RPWM*/\ - {0x0361, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x84}, /*PCIe RPWM*/\ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_DELAY, 0, PWRSEQ_DELAY_MS}, /*Delay*/\ - {0x0008, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0}, /*. 0x08[4] = 0 switch TSF to 40M*/\ - {0x0109, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(7), 0}, /*Polling 0x109[7]= 0 TSF in 40M*/\ - {0x0029, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(6)|BIT(7), 0}, /*. 0x29[7:6] = 2b'00 enable BB clock*/\ - {0x0101, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)}, /*. 0x101[1] = 1*/\ - {0x0100, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0xFF}, /*. 0x100[7:0] = 0xFF enable WMAC TRX*/\ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1)|BIT(0), BIT(1)|BIT(0)}, /*. 0x02[1:0] = 2b'11 enable BB macro*/\ - {0x0522, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0}, /*. 0x522 = 0*/ - - - #define RTL8723B_TRANS_ACT_TO_SWLPS \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0194, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/*enable 32 K source*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/*CCK and OFDM are disabled, and clock are gated*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 1},/*CCK and OFDM are enable*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/*CCK and OFDM are disabled, and clock are gated*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 1},/*CCK and OFDM are enable*/ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/*CCK and OFDM are disabled, and clock are gated*/ \ - {0x0100, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x3F},/*Reset MAC TRX*/ \ - {0x0101, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), 0},/*disable security engine*/ \ - {0x0093, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x40},/*When driver enter Sus/ Disable, enable LOP for BT*/ \ - {0x0553, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(5), BIT(5)},/*reset dual TSF*/ \ - {0x0003, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(2), 0},/*Reset CPU*/ \ - {0x0080, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0},/*Reset MCUFWDL register*/ \ - {0x001D, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/*Reset CPU IO Wrapper*/ \ - {0x001D, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 1},/*Reset CPU IO Wrapper*/ \ - {0x0287, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, 0xFF, 0},/*polling RXFF packet number = 0 */ \ - {0x0286, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(1), BIT(1)},/*polling RXDMA idle */ \ - {0x013D, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/*Clear FW RPWM interrupt */\ - {0x0139, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/*Set FW RPWM interrupt source*/\ - {0x0008, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)},/*switch TSF to 32K*/\ - {0x0109, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), BIT(7)},/*polling TSF stable*/\ - {0x0090, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/*Set FW LPS*/ \ - {0x0090, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(0), 0},/*polling FW LPS ready */ - - -#define RTL8723B_TRANS_SWLPS_TO_ACT \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0x0008, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0},/*switch TSF to 32K*/\ - {0x0109, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), 0},/*polling TSF stable*/\ - {0x0101, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)}, /*. 0x101[1] = 1, enable security engine*/\ - {0x0100, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0xFF}, /*. 0x100[7:0] = 0xFF enable WMAC TRX*/\ - {0x06B7, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x09}, /*. reset MAC rx state machine*/\ - {0x06B4, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x86}, /*. reset MAC rx state machine*/\ - {0x0080, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)},/* set CPU RAM code ready*/ \ - {0x001D, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},/*Reset CPU IO Wrapper*/ \ - {0x0003, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(2), 0},/* Enable CPU*/ \ - {0x001D, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},/*enable CPU IO Wrapper*/ \ - {0x0003, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(2), BIT(2)},/* Enable CPU*/ \ - {0x0080, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(7), BIT(7)},/*polling FW init ready */ \ - {0x0080, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(6), BIT(6)},/*polling FW init ready */ \ - {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)}, /*. 0x02[1:0] = 2b'11 enable BB macro*/\ - {0x0522, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0}, /*. 0x522 = 0*/ - -#define RTL8723B_TRANS_END \ - /* format */ \ - /* { offset, cut_msk, fab_msk|interface_msk, base|cmd, msk, value }, comments here*/ \ - {0xFFFF, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, 0, PWR_CMD_END, 0, 0}, - - -extern struct wlan_pwr_cfg rtl8723B_power_on_flow[RTL8723B_TRANS_CARDEMU_TO_ACT_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_radio_off_flow[RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_card_disable_flow[RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_card_enable_flow[RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_suspend_flow[RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+RTL8723B_TRANS_CARDEMU_TO_SUS_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_resume_flow[RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+RTL8723B_TRANS_CARDEMU_TO_SUS_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_hwpdn_flow[RTL8723B_TRANS_ACT_TO_CARDEMU_STEPS+RTL8723B_TRANS_CARDEMU_TO_PDN_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_enter_lps_flow[RTL8723B_TRANS_ACT_TO_LPS_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_leave_lps_flow[RTL8723B_TRANS_LPS_TO_ACT_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_enter_swlps_flow[RTL8723B_TRANS_ACT_TO_SWLPS_STEPS+RTL8723B_TRANS_END_STEPS]; -extern struct wlan_pwr_cfg rtl8723B_leave_swlps_flow[RTL8723B_TRANS_SWLPS_TO_ACT_STEPS+RTL8723B_TRANS_END_STEPS]; -#endif diff --git a/drivers/staging/rtl8723bs/include/hal_sdio.h b/drivers/staging/rtl8723bs/include/hal_sdio.h deleted file mode 100644 index 3fc8acb430e5..000000000000 --- a/drivers/staging/rtl8723bs/include/hal_sdio.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __HAL_SDIO_H_ -#define __HAL_SDIO_H_ - -#define ffaddr2deviceId(pdvobj, addr) (pdvobj->Queue2Pipe[addr]) - -u8 rtw_hal_sdio_max_txoqt_free_space(struct adapter *padapter); -u8 rtw_hal_sdio_query_tx_freepage(struct adapter *padapter, u8 PageIdx, u8 RequiredPageNum); -void rtw_hal_sdio_update_tx_freepage(struct adapter *padapter, u8 PageIdx, u8 RequiredPageNum); -void rtw_hal_set_sdio_tx_max_length(struct adapter *padapter, u8 numHQ, u8 numNQ, u8 numLQ, u8 numPubQ); -u32 rtw_hal_get_sdio_tx_max_length(struct adapter *padapter, u8 queue_idx); - -#endif /* __RTW_LED_H_ */ diff --git a/drivers/staging/rtl8723bs/include/ieee80211.h b/drivers/staging/rtl8723bs/include/ieee80211.h deleted file mode 100644 index 9f421e4875b7..000000000000 --- a/drivers/staging/rtl8723bs/include/ieee80211.h +++ /dev/null @@ -1,748 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __IEEE80211_H -#define __IEEE80211_H - -#include - -#define MGMT_QUEUE_NUM 5 - -#define ETH_TYPE_LEN 2 -#define PAYLOAD_TYPE_LEN 1 - -#define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28) - -/* RTL871X_IOCTL_HOSTAPD ioctl() cmd: */ -enum { - RTL871X_HOSTAPD_FLUSH = 1, - RTL871X_HOSTAPD_ADD_STA = 2, - RTL871X_HOSTAPD_REMOVE_STA = 3, - RTL871X_HOSTAPD_GET_INFO_STA = 4, - /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */ - RTL871X_HOSTAPD_GET_WPAIE_STA = 5, - RTL871X_SET_ENCRYPTION = 6, - RTL871X_GET_ENCRYPTION = 7, - RTL871X_HOSTAPD_SET_FLAGS_STA = 8, - RTL871X_HOSTAPD_GET_RID = 9, - RTL871X_HOSTAPD_SET_RID = 10, - RTL871X_HOSTAPD_SET_ASSOC_AP_ADDR = 11, - RTL871X_HOSTAPD_SET_GENERIC_ELEMENT = 12, - RTL871X_HOSTAPD_MLME = 13, - RTL871X_HOSTAPD_SCAN_REQ = 14, - RTL871X_HOSTAPD_STA_CLEAR_STATS = 15, - RTL871X_HOSTAPD_SET_BEACON = 16, - RTL871X_HOSTAPD_SET_WPS_BEACON = 17, - RTL871X_HOSTAPD_SET_WPS_PROBE_RESP = 18, - RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP = 19, - RTL871X_HOSTAPD_SET_HIDDEN_SSID = 20, - RTL871X_HOSTAPD_SET_MACADDR_ACL = 21, - RTL871X_HOSTAPD_ACL_ADD_STA = 22, - RTL871X_HOSTAPD_ACL_REMOVE_STA = 23, -}; - -/* STA flags */ -#define WLAN_STA_AUTH BIT(0) -#define WLAN_STA_ASSOC BIT(1) -#define WLAN_STA_PS BIT(2) -#define WLAN_STA_TIM BIT(3) -#define WLAN_STA_PERM BIT(4) -#define WLAN_STA_AUTHORIZED BIT(5) -#define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */ -#define WLAN_STA_SHORT_PREAMBLE BIT(7) -#define WLAN_STA_PREAUTH BIT(8) -#define WLAN_STA_WME BIT(9) -#define WLAN_STA_MFP BIT(10) -#define WLAN_STA_HT BIT(11) -#define WLAN_STA_WPS BIT(12) -#define WLAN_STA_MAYBE_WPS BIT(13) -#define WLAN_STA_NONERP BIT(31) - -#define IEEE_CMD_SET_WPA_PARAM 1 -#define IEEE_CMD_SET_WPA_IE 2 -#define IEEE_CMD_SET_ENCRYPTION 3 -#define IEEE_CMD_MLME 4 - -#define IEEE_PARAM_WPA_ENABLED 1 -#define IEEE_PARAM_TKIP_COUNTERMEASURES 2 -#define IEEE_PARAM_DROP_UNENCRYPTED 3 -#define IEEE_PARAM_PRIVACY_INVOKED 4 -#define IEEE_PARAM_AUTH_ALGS 5 -#define IEEE_PARAM_IEEE_802_1X 6 -#define IEEE_PARAM_WPAX_SELECT 7 - -#define IEEE_MLME_STA_DEAUTH 1 -#define IEEE_MLME_STA_DISASSOC 2 - -#define IEEE_CRYPT_ERR_UNKNOWN_ALG 2 -#define IEEE_CRYPT_ERR_UNKNOWN_ADDR 3 -#define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED 4 -#define IEEE_CRYPT_ERR_KEY_SET_FAILED 5 -#define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED 6 -#define IEEE_CRYPT_ERR_CARD_CONF_FAILED 7 - - -#define IEEE_CRYPT_ALG_NAME_LEN 16 - -#define WPA_CIPHER_NONE BIT(0) -#define WPA_CIPHER_WEP40 BIT(1) -#define WPA_CIPHER_WEP104 BIT(2) -#define WPA_CIPHER_TKIP BIT(3) -#define WPA_CIPHER_CCMP BIT(4) - - - -#define WPA_SELECTOR_LEN 4 -extern u8 RTW_WPA_OUI_TYPE[]; -extern u16 RTW_WPA_VERSION; -extern u8 WPA_AUTH_KEY_MGMT_NONE[]; -extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[]; -extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[]; -extern u8 WPA_CIPHER_SUITE_NONE[]; -extern u8 WPA_CIPHER_SUITE_WEP40[]; -extern u8 WPA_CIPHER_SUITE_TKIP[]; -extern u8 WPA_CIPHER_SUITE_WRAP[]; -extern u8 WPA_CIPHER_SUITE_CCMP[]; -extern u8 WPA_CIPHER_SUITE_WEP104[]; - - -#define RSN_HEADER_LEN 4 -#define RSN_SELECTOR_LEN 4 - -extern u16 RSN_VERSION_BSD; -extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[]; -extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[]; -extern u8 RSN_CIPHER_SUITE_NONE[]; -extern u8 RSN_CIPHER_SUITE_WEP40[]; -extern u8 RSN_CIPHER_SUITE_TKIP[]; -extern u8 RSN_CIPHER_SUITE_WRAP[]; -extern u8 RSN_CIPHER_SUITE_CCMP[]; -extern u8 RSN_CIPHER_SUITE_WEP104[]; - - -enum { - RATEID_IDX_BGN_40M_2SS = 0, - RATEID_IDX_BGN_40M_1SS = 1, - RATEID_IDX_BGN_20M_2SS_BN = 2, - RATEID_IDX_BGN_20M_1SS_BN = 3, - RATEID_IDX_GN_N2SS = 4, - RATEID_IDX_GN_N1SS = 5, - RATEID_IDX_BG = 6, - RATEID_IDX_G = 7, - RATEID_IDX_B = 8, -}; - -enum network_type { - WIRELESS_INVALID = 0, - /* Sub-Element */ - WIRELESS_11B = BIT(0), /* tx: cck only , rx: cck only, hw: cck */ - WIRELESS_11G = BIT(1), /* tx: ofdm only, rx: ofdm & cck, hw: cck & ofdm */ - WIRELESS_11_24N = BIT(3), /* tx: MCS only, rx: MCS & cck, hw: MCS & cck */ - WIRELESS_AUTO = BIT(5), - - /* Combination */ - /* Type for current wireless mode */ - WIRELESS_11BG = (WIRELESS_11B|WIRELESS_11G), /* tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */ - WIRELESS_11G_24N = (WIRELESS_11G|WIRELESS_11_24N), /* tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */ - WIRELESS_11B_24N = (WIRELESS_11B|WIRELESS_11_24N), /* tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */ - WIRELESS_11BG_24N = (WIRELESS_11B|WIRELESS_11G|WIRELESS_11_24N), /* tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */ -}; - -#define SUPPORTED_24G_NETTYPE_MSK (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N) - -#define is_legacy_only(net_type) ((net_type) == ((net_type) & (WIRELESS_11BG))) - -#define is_supported_24g(net_type) ((net_type) & SUPPORTED_24G_NETTYPE_MSK ? true : false) - -#define is_supported_tx_cck(net_type) (((net_type) & (WIRELESS_11B)) ? true : false) -#define is_supported_ht(net_type) (((net_type) & (WIRELESS_11_24N)) ? true : false) - -struct ieee_param { - u32 cmd; - u8 sta_addr[ETH_ALEN]; - union { - struct { - u8 name; - u32 value; - } wpa_param; - struct { - u32 len; - u8 reserved[32]; - u8 data[]; - } wpa_ie; - struct{ - int command; - int reason_code; - } mlme; - struct { - u8 alg[IEEE_CRYPT_ALG_NAME_LEN]; - u8 set_tx; - u32 err; - u8 idx; - u8 seq[8]; /* sequence counter (set: RX, get: TX) */ - u16 key_len; - u8 key[]; - } crypt; - struct { - u16 aid; - u16 capability; - int flags; - u8 tx_supp_rates[16]; - struct ieee80211_ht_cap ht_cap; - } add_sta; - struct { - u8 reserved[2];/* for set max_num_sta */ - u8 buf[]; - } bcn_ie; - } u; -}; - -struct ieee_param_ex { - u32 cmd; - u8 sta_addr[ETH_ALEN]; - u8 data[]; -}; - -struct sta_data { - u16 aid; - u16 capability; - int flags; - u32 sta_set; - u8 tx_supp_rates[16]; - u32 tx_supp_rates_len; - struct ieee80211_ht_cap ht_cap; - u64 rx_pkts; - u64 rx_bytes; - u64 rx_drops; - u64 tx_pkts; - u64 tx_bytes; - u64 tx_drops; -}; - -/* this is stolen from ipw2200 driver */ -#define IEEE_IBSS_MAC_HASH_SIZE 31 - -struct eapol { - u8 snap[6]; - u16 ethertype; - u8 version; - u8 type; - u16 length; -} __packed; - -#define IEEE80211_FCS_LEN 4 - -#define MIN_FRAG_THRESHOLD 256U -#define MAX_FRAG_THRESHOLD 2346U - -/* sequence control field */ -#define RTW_IEEE80211_SCTL_FRAG 0x000F -#define RTW_IEEE80211_SCTL_SEQ 0xFFF0 - - -#define RTW_ERP_INFO_NON_ERP_PRESENT BIT(0) -#define RTW_ERP_INFO_USE_PROTECTION BIT(1) -#define RTW_ERP_INFO_BARKER_PREAMBLE_MODE BIT(2) - -/* QoS, QOS */ -#define NORMAL_ACK 0 -#define NO_ACK 1 -#define NON_EXPLICIT_ACK 2 -#define BLOCK_ACK 3 - -#ifndef ETH_P_PAE -#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */ -#endif /* ETH_P_PAE */ - -#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */ - -#define ETH_P_ECONET 0x0018 - -#ifndef ETH_P_80211_RAW -#define ETH_P_80211_RAW (ETH_P_ECONET + 1) -#endif - -/* IEEE 802.11 defines */ - -#define P80211_OUI_LEN 3 - -struct ieee80211_snap_hdr { - u8 dsap; /* always 0xAA */ - u8 ssap; /* always 0xAA */ - u8 ctrl; /* always 0x03 */ - u8 oui[P80211_OUI_LEN]; /* organizational universal id */ -} __packed; - -#define SNAP_SIZE sizeof(struct ieee80211_snap_hdr) - -#define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE) -#define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE) - -#define WLAN_QC_GET_TID(qc) ((qc) & 0x0f) - -#define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG) -#define WLAN_GET_SEQ_SEQ(seq) ((seq) & RTW_IEEE80211_SCTL_SEQ) - -/* Reason codes */ -#define WLAN_REASON_ACTIVE_ROAM 65533 -#define WLAN_REASON_JOIN_WRONG_CHANNEL 65534 -#define WLAN_REASON_EXPIRATION_CHK 65535 - -#define IEEE80211_MGMT_HDR_LEN 24 -#define IEEE80211_DATA_HDR3_LEN 24 -#define IEEE80211_DATA_HDR4_LEN 30 - - -#define IEEE80211_STATMASK_SIGNAL (1<<0) -#define IEEE80211_STATMASK_RSSI (1<<1) -#define IEEE80211_STATMASK_NOISE (1<<2) -#define IEEE80211_STATMASK_RATE (1<<3) -#define IEEE80211_STATMASK_WEMASK 0x7 - - -#define IEEE80211_CCK_MODULATION (1<<0) -#define IEEE80211_OFDM_MODULATION (1<<1) - -#define IEEE80211_24GHZ_BAND (1<<0) -#define IEEE80211_52GHZ_BAND (1<<1) - -#define IEEE80211_CCK_RATE_LEN 4 -#define IEEE80211_NUM_OFDM_RATESLEN 8 - - -#define IEEE80211_CCK_RATE_1MB 0x02 -#define IEEE80211_CCK_RATE_2MB 0x04 -#define IEEE80211_CCK_RATE_5MB 0x0B -#define IEEE80211_CCK_RATE_11MB 0x16 -#define IEEE80211_OFDM_RATE_LEN 8 -#define IEEE80211_OFDM_RATE_6MB 0x0C -#define IEEE80211_OFDM_RATE_9MB 0x12 -#define IEEE80211_OFDM_RATE_12MB 0x18 -#define IEEE80211_OFDM_RATE_18MB 0x24 -#define IEEE80211_OFDM_RATE_24MB 0x30 -#define IEEE80211_OFDM_RATE_36MB 0x48 -#define IEEE80211_OFDM_RATE_48MB 0x60 -#define IEEE80211_OFDM_RATE_54MB 0x6C -#define IEEE80211_BASIC_RATE_MASK 0x80 - -#define IEEE80211_CCK_RATE_1MB_MASK (1<<0) -#define IEEE80211_CCK_RATE_2MB_MASK (1<<1) -#define IEEE80211_CCK_RATE_5MB_MASK (1<<2) -#define IEEE80211_CCK_RATE_11MB_MASK (1<<3) -#define IEEE80211_OFDM_RATE_6MB_MASK (1<<4) -#define IEEE80211_OFDM_RATE_9MB_MASK (1<<5) -#define IEEE80211_OFDM_RATE_12MB_MASK (1<<6) -#define IEEE80211_OFDM_RATE_18MB_MASK (1<<7) -#define IEEE80211_OFDM_RATE_24MB_MASK (1<<8) -#define IEEE80211_OFDM_RATE_36MB_MASK (1<<9) -#define IEEE80211_OFDM_RATE_48MB_MASK (1<<10) -#define IEEE80211_OFDM_RATE_54MB_MASK (1<<11) - -#define IEEE80211_CCK_RATES_MASK 0x0000000F -#define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \ - IEEE80211_CCK_RATE_2MB_MASK) -#define IEEE80211_CCK_DEFAULT_RATES_MASK \ - (IEEE80211_CCK_BASIC_RATES_MASK | \ - IEEE80211_CCK_RATE_5MB_MASK | \ - IEEE80211_CCK_RATE_11MB_MASK) - -#define IEEE80211_OFDM_RATES_MASK 0x00000FF0 -#define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \ - IEEE80211_OFDM_RATE_12MB_MASK | \ - IEEE80211_OFDM_RATE_24MB_MASK) -#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \ - IEEE80211_OFDM_RATE_9MB_MASK | \ - IEEE80211_OFDM_RATE_18MB_MASK | \ - IEEE80211_OFDM_RATE_36MB_MASK | \ - IEEE80211_OFDM_RATE_48MB_MASK | \ - IEEE80211_OFDM_RATE_54MB_MASK) -#define IEEE80211_DEFAULT_RATES_MASK \ - (IEEE80211_OFDM_DEFAULT_RATES_MASK | \ - IEEE80211_CCK_DEFAULT_RATES_MASK) - -#define IEEE80211_NUM_OFDM_RATES 8 -#define IEEE80211_NUM_CCK_RATES 4 -#define IEEE80211_OFDM_SHIFT_MASK_A 4 - - -enum { - MGN_1M = 0x02, - MGN_2M = 0x04, - MGN_5_5M = 0x0B, - MGN_6M = 0x0C, - MGN_9M = 0x12, - MGN_11M = 0x16, - MGN_12M = 0x18, - MGN_18M = 0x24, - MGN_24M = 0x30, - MGN_36M = 0x48, - MGN_48M = 0x60, - MGN_54M = 0x6C, - MGN_MCS32 = 0x7F, - MGN_MCS0, - MGN_MCS1, - MGN_MCS2, - MGN_MCS3, - MGN_MCS4, - MGN_MCS5, - MGN_MCS6, - MGN_MCS7, - MGN_UNKNOWN -}; - -#define IS_HT_RATE(_rate) (_rate >= MGN_MCS0 && _rate <= MGN_MCS31) -#define IS_CCK_RATE(_rate) (_rate == MGN_1M || _rate == MGN_2M || _rate == MGN_5_5M || _rate == MGN_11M) -#define IS_OFDM_RATE(_rate) (_rate >= MGN_6M && _rate <= MGN_54M && _rate != MGN_11M) - - -/* NOTE: This data is for statistical purposes; not all hardware provides this - * information for frames received. Not setting these will not cause - * any adverse affects. - */ - -/* IEEE 802.11 requires that STA supports concurrent reception of at least - * three fragmented frames. This define can be increased to support more - * concurrent frames, but it should be noted that each entry can consume about - * 2 kB of RAM and increasing cache size will slow down frame reassembly. - */ -#define IEEE80211_FRAG_CACHE_LEN 4 - -#define SEC_KEY_1 (1<<0) -#define SEC_KEY_2 (1<<1) -#define SEC_KEY_3 (1<<2) -#define SEC_KEY_4 (1<<3) -#define SEC_ACTIVE_KEY (1<<4) -#define SEC_AUTH_MODE (1<<5) -#define SEC_UNICAST_GROUP (1<<6) -#define SEC_LEVEL (1<<7) -#define SEC_ENABLED (1<<8) - -#define SEC_LEVEL_0 0 /* None */ -#define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */ -#define SEC_LEVEL_2 2 /* Level 1 + TKIP */ -#define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */ -#define SEC_LEVEL_3 4 /* Level 2 + CCMP */ - -#define WEP_KEYS 4 -#define WEP_KEY_LEN 13 - -#define BIP_MAX_KEYID 5 -#define BIP_AAD_SIZE 20 - -/* - * 802.11 data frame from AP - * - * ,-------------------------------------------------------------------. - * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 | - * |------|------|---------|---------|---------|------|---------|------| - * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs | - * | | tion | (BSSID) | | | ence | data | | - * `-------------------------------------------------------------------' - * - * Total: 28-2340 bytes - */ - -#define BEACON_PROBE_SSID_ID_POSITION 12 - -/* Management Frame Information Element Types */ -#define MFIE_TYPE_SSID 0 -#define MFIE_TYPE_RATES 1 -#define MFIE_TYPE_FH_SET 2 -#define MFIE_TYPE_DS_SET 3 -#define MFIE_TYPE_CF_SET 4 -#define MFIE_TYPE_TIM 5 -#define MFIE_TYPE_IBSS_SET 6 -#define MFIE_TYPE_CHALLENGE 16 -#define MFIE_TYPE_ERP 42 -#define MFIE_TYPE_RSN 48 -#define MFIE_TYPE_RATES_EX 50 -#define MFIE_TYPE_GENERIC 221 - -/* SWEEP TABLE ENTRIES NUMBER*/ -#define MAX_SWEEP_TAB_ENTRIES 42 -#define MAX_SWEEP_TAB_ENTRIES_PER_PACKET 7 -/* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs - * only use 8, and then use extended rates for the remaining supported - * rates. Other APs, however, stick all of their supported rates on the - * main rates information element... - */ -#define MAX_RATES_LENGTH ((u8)12) -#define MAX_RATES_EX_LENGTH ((u8)16) -#define MAX_NETWORK_COUNT 128 -#define MAX_CHANNEL_NUMBER 161 -#define IEEE80211_SOFTMAC_SCAN_TIME 400 -/* HZ / 2) */ -#define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2) - -#define CRC_LENGTH 4U - -#define MAX_WPA_IE_LEN (256) -#define MAX_WPS_IE_LEN (512) -#define MAX_P2P_IE_LEN (256) -#define MAX_WFD_IE_LEN (128) - -#define NETWORK_EMPTY_ESSID (1<<0) -#define NETWORK_HAS_OFDM (1<<1) -#define NETWORK_HAS_CCK (1<<2) - -#define IEEE80211_DTIM_MBCAST 4 -#define IEEE80211_DTIM_UCAST 2 -#define IEEE80211_DTIM_VALID 1 -#define IEEE80211_DTIM_INVALID 0 - -#define IEEE80211_PS_DISABLED 0 -#define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST -#define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST -#define IW_ESSID_MAX_SIZE 32 -/* - * join_res: - * -1: authentication fail - * -2: association fail - * > 0: TID - */ - -#define DEFAULT_MAX_SCAN_AGE (15 * HZ) -#define DEFAULT_FTS 2346 -#define IP_ARG(x) (x) - -#define CFG_IEEE80211_RESERVE_FCS (1<<0) -#define CFG_IEEE80211_COMPUTE_FCS (1<<1) - -#define MAXTID 16 - -#define IEEE_A (1<<0) -#define IEEE_B (1<<1) -#define IEEE_G (1<<2) -#define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G) - -/* Action category code */ -enum { - RTW_WLAN_CATEGORY_SPECTRUM_MGMT = 0, - RTW_WLAN_CATEGORY_QOS = 1, - RTW_WLAN_CATEGORY_DLS = 2, - RTW_WLAN_CATEGORY_BACK = 3, - RTW_WLAN_CATEGORY_PUBLIC = 4, /* IEEE 802.11 public action frames */ - RTW_WLAN_CATEGORY_RADIO_MEASUREMENT = 5, - RTW_WLAN_CATEGORY_FT = 6, - RTW_WLAN_CATEGORY_HT = 7, - RTW_WLAN_CATEGORY_SA_QUERY = 8, - RTW_WLAN_CATEGORY_UNPROTECTED_WNM = 11, - RTW_WLAN_CATEGORY_TDLS = 12, - RTW_WLAN_CATEGORY_SELF_PROTECTED = 15, - RTW_WLAN_CATEGORY_WMM = 17, - RTW_WLAN_CATEGORY_P2P = 0x7f,/* P2P action frames */ -}; - -enum { - ACT_PUBLIC_BSSCOEXIST = 0, /* 20/40 BSS Coexistence */ - ACT_PUBLIC_DSE_ENABLE = 1, - ACT_PUBLIC_DSE_DEENABLE = 2, - ACT_PUBLIC_DSE_REG_LOCATION = 3, - ACT_PUBLIC_EXT_CHL_SWITCH = 4, - ACT_PUBLIC_DSE_MSR_REQ = 5, - ACT_PUBLIC_DSE_MSR_RPRT = 6, - ACT_PUBLIC_MP = 7, /* Measurement Pilot */ - ACT_PUBLIC_DSE_PWR_CONSTRAINT = 8, - ACT_PUBLIC_VENDOR = 9, /* for WIFI_DIRECT */ - ACT_PUBLIC_GAS_INITIAL_REQ = 10, - ACT_PUBLIC_GAS_INITIAL_RSP = 11, - ACT_PUBLIC_GAS_COMEBACK_REQ = 12, - ACT_PUBLIC_GAS_COMEBACK_RSP = 13, - ACT_PUBLIC_TDLS_DISCOVERY_RSP = 14, - ACT_PUBLIC_LOCATION_TRACK = 15, - ACT_PUBLIC_MAX -}; - -#define OUI_MICROSOFT 0x0050f2 /* Microsoft OUI (also used in Wi-Fi specs) */ -#define WME_OUI_TYPE 2 -#define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0 -#define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1 -#define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2 -#define WME_VERSION 1 - -#define WME_ACTION_CODE_SETUP_REQUEST 0 -#define WME_ACTION_CODE_SETUP_RESPONSE 1 -#define WME_ACTION_CODE_TEARDOWN 2 - -#define WME_SETUP_RESPONSE_STATUS_ADMISSION_ACCEPTED 0 -#define WME_SETUP_RESPONSE_STATUS_INVALID_PARAMETERS 1 -#define WME_SETUP_RESPONSE_STATUS_REFUSED 3 - -#define WME_TSPEC_DIRECTION_UPLINK 0 -#define WME_TSPEC_DIRECTION_DOWNLINK 1 -#define WME_TSPEC_DIRECTION_BI_DIRECTIONAL 3 - - -#define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */ - -#define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */ - -/** - * enum rtw_ieee80211_channel_flags - channel flags - * - * Channel flags set by the regulatory control code. - * - * @RTW_IEEE80211_CHAN_DISABLED: This channel is disabled. - * @RTW_IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted - * on this channel. - * @RTW_IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel. - * @RTW_IEEE80211_CHAN_RADAR: Radar detection is required on this channel. - * @RTW_IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel - * is not permitted. - * @RTW_IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel - * is not permitted. - */ -enum rtw_ieee80211_channel_flags { - RTW_IEEE80211_CHAN_DISABLED = 1<<0, - RTW_IEEE80211_CHAN_PASSIVE_SCAN = 1<<1, - RTW_IEEE80211_CHAN_NO_IBSS = 1<<2, - RTW_IEEE80211_CHAN_RADAR = 1<<3, - RTW_IEEE80211_CHAN_NO_HT40PLUS = 1<<4, - RTW_IEEE80211_CHAN_NO_HT40MINUS = 1<<5, -}; - -#define RTW_IEEE80211_CHAN_NO_HT40 \ - (RTW_IEEE80211_CHAN_NO_HT40PLUS | \ - RTW_IEEE80211_CHAN_NO_HT40MINUS) - -/* Represent channel details, subset of ieee80211_channel */ -struct rtw_ieee80211_channel { - /* enum nl80211_band band; */ - /* u16 center_freq; */ - u16 hw_value; - u32 flags; - /* int max_antenna_gain; */ - /* int max_power; */ - /* int max_reg_power; */ - /* bool beacon_found; */ - /* u32 orig_flags; */ - /* int orig_mag; */ - /* int orig_mpwr; */ -}; - -/* Parsed Information Elements */ -struct rtw_ieee802_11_elems { - u8 *ssid; - u8 ssid_len; - u8 *supp_rates; - u8 supp_rates_len; - u8 *fh_params; - u8 fh_params_len; - u8 *ds_params; - u8 ds_params_len; - u8 *cf_params; - u8 cf_params_len; - u8 *tim; - u8 tim_len; - u8 *ibss_params; - u8 ibss_params_len; - u8 *challenge; - u8 challenge_len; - u8 *erp_info; - u8 erp_info_len; - u8 *ext_supp_rates; - u8 ext_supp_rates_len; - u8 *wpa_ie; - u8 wpa_ie_len; - u8 *rsn_ie; - u8 rsn_ie_len; - u8 *wme; - u8 wme_len; - u8 *wme_tspec; - u8 wme_tspec_len; - u8 *wps_ie; - u8 wps_ie_len; - u8 *power_cap; - u8 power_cap_len; - u8 *supp_channels; - u8 supp_channels_len; - u8 *mdie; - u8 mdie_len; - u8 *ftie; - u8 ftie_len; - u8 *timeout_int; - u8 timeout_int_len; - u8 *ht_capabilities; - u8 ht_capabilities_len; - u8 *ht_operation; - u8 ht_operation_len; - u8 *vendor_ht_cap; - u8 vendor_ht_cap_len; - u8 *vht_capabilities; - u8 vht_capabilities_len; - u8 *vht_operation; - u8 vht_operation_len; - u8 *vht_op_mode_notify; - u8 vht_op_mode_notify_len; -}; - -enum parse_result { - PARSE_OK = 0, - PARSE_UNKNOWN = 1, - PARSE_FAILED = -1 -}; - -enum parse_result rtw_ieee802_11_parse_elems(u8 *start, uint len, - struct rtw_ieee802_11_elems *elems, - int show_errors); - -u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source, unsigned int *frlen); -u8 *rtw_set_ie(u8 *pbuf, signed int index, uint len, u8 *source, uint *frlen); - -u8 *rtw_get_ie(u8 *pbuf, signed int index, signed int *len, signed int limit); -u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen); -int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len); - -void rtw_set_supported_rate(u8 *SupportedRates, uint mode); - -unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit); -unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit); -int rtw_get_wpa_cipher_suite(u8 *s); -int rtw_get_wpa2_cipher_suite(u8 *s); -int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len); -int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x); -int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x); - -void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len); - -u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen); -u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr); -u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content); - -/** - * for_each_ie - iterate over continuous IEs - * @ie: - * @buf: - * @buf_len: - */ -#define for_each_ie(ie, buf, buf_len) \ - for (ie = (void *)buf; (((u8 *)ie) - ((u8 *)buf) + 1) < buf_len; \ - ie = (void *)(((u8 *)ie) + *(((u8 *)ie) + 1) + 2)) - -uint rtw_get_rateset_len(u8 *rateset); - -struct registry_priv; -int rtw_generate_ie(struct registry_priv *pregistrypriv); - - -int rtw_get_bit_value_from_ieee_value(u8 val); - -bool rtw_is_cckrates_included(u8 *rate); - -bool rtw_is_cckratesonly_included(u8 *rate); - -int rtw_check_network_type(unsigned char *rate, int channel); - -void rtw_get_bcn_info(struct wlan_network *pnetwork); - -void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr); - -u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate); - -int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action); -const char *action_public_str(u8 action); - -#endif /* IEEE80211_H */ diff --git a/drivers/staging/rtl8723bs/include/ioctl_cfg80211.h b/drivers/staging/rtl8723bs/include/ioctl_cfg80211.h deleted file mode 100644 index a1fc18cd247b..000000000000 --- a/drivers/staging/rtl8723bs/include/ioctl_cfg80211.h +++ /dev/null @@ -1,58 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __IOCTL_CFG80211_H__ -#define __IOCTL_CFG80211_H__ - -struct rtw_wdev_priv { - struct wireless_dev *rtw_wdev; - - struct adapter *padapter; - - struct cfg80211_scan_request *scan_request; - spinlock_t scan_req_lock; - - struct net_device *pmon_ndev;/* for monitor interface */ - char ifname_mon[IFNAMSIZ + 1]; /* interface name for monitor interface */ - - bool block; - bool power_mgmt; -}; - -#define wiphy_to_adapter(x) (*((struct adapter **)wiphy_priv(x))) - -#define wdev_to_ndev(w) ((w)->netdev) - -int rtw_wdev_alloc(struct adapter *padapter, struct device *dev); -void rtw_wdev_free(struct wireless_dev *wdev); -void rtw_wdev_unregister(struct wireless_dev *wdev); - -void rtw_cfg80211_init_wiphy(struct adapter *padapter); - -void rtw_cfg80211_unlink_bss(struct adapter *padapter, struct wlan_network *pnetwork); -void rtw_cfg80211_surveydone_event_callback(struct adapter *padapter); -int rtw_ieee80211_channel_to_frequency(int chan); -struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wlan_network *pnetwork); -int rtw_cfg80211_check_bss(struct adapter *padapter); -void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter); -void rtw_cfg80211_indicate_connect(struct adapter *padapter); -void rtw_cfg80211_indicate_disconnect(struct adapter *padapter); -void rtw_cfg80211_indicate_scan_done(struct adapter *adapter, bool aborted); - -void rtw_cfg80211_indicate_sta_assoc(struct adapter *padapter, u8 *pmgmt_frame, unsigned int frame_len); -void rtw_cfg80211_indicate_sta_disassoc(struct adapter *padapter, unsigned char *da, unsigned short reason); - -void rtw_cfg80211_rx_action(struct adapter *adapter, u8 *frame, unsigned int frame_len, const char *msg); - -bool rtw_cfg80211_pwr_mgmt(struct adapter *adapter); - -#define rtw_cfg80211_rx_mgmt(adapter, freq, sig_dbm, buf, len, gfp) cfg80211_rx_mgmt((adapter)->rtw_wdev, freq, sig_dbm, buf, len, 0) -#define rtw_cfg80211_send_rx_assoc(adapter, bss, buf, len) cfg80211_send_rx_assoc((adapter)->pnetdev, bss, buf, len) -#define rtw_cfg80211_mgmt_tx_status(adapter, cookie, buf, len, ack, gfp) cfg80211_mgmt_tx_status((adapter)->rtw_wdev, cookie, buf, len, ack, gfp) -#define rtw_cfg80211_ready_on_channel(adapter, cookie, chan, channel_type, duration, gfp) cfg80211_ready_on_channel((adapter)->rtw_wdev, cookie, chan, duration, gfp) -#define rtw_cfg80211_remain_on_channel_expired(adapter, cookie, chan, chan_type, gfp) cfg80211_remain_on_channel_expired((adapter)->rtw_wdev, cookie, chan, gfp) - -#endif /* __IOCTL_CFG80211_H__ */ diff --git a/drivers/staging/rtl8723bs/include/osdep_intf.h b/drivers/staging/rtl8723bs/include/osdep_intf.h deleted file mode 100644 index 83a25598e962..000000000000 --- a/drivers/staging/rtl8723bs/include/osdep_intf.h +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef __OSDEP_INTF_H_ -#define __OSDEP_INTF_H_ - -struct dvobj_priv *devobj_init(void); -void devobj_deinit(struct dvobj_priv *pdvobj); - -u8 rtw_init_drv_sw(struct adapter *padapter); -u8 rtw_free_drv_sw(struct adapter *padapter); -void rtw_reset_drv_sw(struct adapter *padapter); -void rtw_dev_unload(struct adapter *padapter); - -u32 rtw_start_drv_threads(struct adapter *padapter); -void rtw_stop_drv_threads(struct adapter *padapter); -void rtw_cancel_all_timer(struct adapter *padapter); - -int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname); -struct net_device *rtw_init_netdev(struct adapter *padapter); -void rtw_unregister_netdevs(struct dvobj_priv *dvobj); - -u16 rtw_recv_select_queue(struct sk_buff *skb); - -void rtw_ips_dev_unload(struct adapter *padapter); - -int rtw_ips_pwr_up(struct adapter *padapter); -void rtw_ips_pwr_down(struct adapter *padapter); - -int rtw_drv_register_netdev(struct adapter *padapter); -void rtw_ndev_destructor(struct net_device *ndev); - -void rtw_suspend_common(struct adapter *padapter); -int rtw_resume_common(struct adapter *padapter); - -int netdev_open(struct net_device *pnetdev); - -#endif /* _OSDEP_INTF_H_ */ diff --git a/drivers/staging/rtl8723bs/include/osdep_service.h b/drivers/staging/rtl8723bs/include/osdep_service.h deleted file mode 100644 index 2f5011a8210c..000000000000 --- a/drivers/staging/rtl8723bs/include/osdep_service.h +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __OSDEP_SERVICE_H_ -#define __OSDEP_SERVICE_H_ - - -#define _FAIL 0 -#define _SUCCESS 1 -#define RTW_RX_HANDLED 2 - -#include - - -extern int RTW_STATUS_CODE(int error_code); - -int _rtw_netif_rx(struct net_device *ndev, struct sk_buff *skb); - -#define rtw_netif_rx(ndev, skb) _rtw_netif_rx(ndev, skb) - -static inline void flush_signals_thread(void) -{ - if (signal_pending(current)) - flush_signals(current); -} - -#define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r)) - -extern void rtw_free_netdev(struct net_device *netdev); - -/* Macros for handling unaligned memory accesses */ - -void rtw_buf_free(u8 **buf, u32 *buf_len); -void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len); - -struct rtw_cbuf { - u32 write; - u32 read; - u32 size; - void *bufs[]; -}; - -bool rtw_cbuf_full(struct rtw_cbuf *cbuf); -bool rtw_cbuf_empty(struct rtw_cbuf *cbuf); -bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf); -void *rtw_cbuf_pop(struct rtw_cbuf *cbuf); -struct rtw_cbuf *rtw_cbuf_alloc(u32 size); - - -#endif diff --git a/drivers/staging/rtl8723bs/include/osdep_service_linux.h b/drivers/staging/rtl8723bs/include/osdep_service_linux.h deleted file mode 100644 index c8274da940ff..000000000000 --- a/drivers/staging/rtl8723bs/include/osdep_service_linux.h +++ /dev/null @@ -1,118 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __OSDEP_LINUX_SERVICE_H_ -#define __OSDEP_LINUX_SERVICE_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* for struct tasklet_struct */ -#include -#include -#include -#include - -#include -#include - -struct __queue { - struct list_head queue; - spinlock_t lock; -}; - -static inline struct list_head *get_next(struct list_head *list) -{ - return list->next; -} - -static inline struct list_head *get_list_head(struct __queue *queue) -{ - return (&(queue->queue)); -} - -static inline void _set_timer(struct timer_list *ptimer, u32 delay_time) -{ - mod_timer(ptimer, (jiffies + (delay_time * HZ / 1000))); -} - -static inline void _init_workitem(struct work_struct *pwork, void *pfunc, void *cntx) -{ - INIT_WORK(pwork, pfunc); -} - -static inline void _set_workitem(struct work_struct *pwork) -{ - schedule_work(pwork); -} - -static inline void _cancel_workitem_sync(struct work_struct *pwork) -{ - cancel_work_sync(pwork); -} - -static inline int rtw_netif_queue_stopped(struct net_device *pnetdev) -{ - return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) && - netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) && - netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) && - netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3))); -} - -static inline void rtw_netif_wake_queue(struct net_device *pnetdev) -{ - netif_tx_wake_all_queues(pnetdev); -} - -static inline void rtw_netif_start_queue(struct net_device *pnetdev) -{ - netif_tx_start_all_queues(pnetdev); -} - -static inline void rtw_netif_stop_queue(struct net_device *pnetdev) -{ - netif_tx_stop_all_queues(pnetdev); -} - -#define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1) - -#define ADPT_ARG(adapter) adapter->pnetdev->name -#define FUNC_ADPT_FMT "%s(%s)" -#define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name - -struct rtw_netdev_priv_indicator { - void *priv; - u32 sizeof_priv; -}; - -static inline struct adapter *rtw_netdev_priv(struct net_device *netdev) -{ - return ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv; -} - -struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv); -extern struct net_device *rtw_alloc_etherdev(int sizeof_priv); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8192c_recv.h b/drivers/staging/rtl8723bs/include/rtl8192c_recv.h deleted file mode 100644 index b63625ab4e45..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8192c_recv.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _RTL8192C_RECV_H_ -#define _RTL8192C_RECV_H_ - -#define MAX_RECVBUF_SZ (10240) - -struct phy_stat { - unsigned int phydw0; - - unsigned int phydw1; - - unsigned int phydw2; - - unsigned int phydw3; - - unsigned int phydw4; - - unsigned int phydw5; - - unsigned int phydw6; - - unsigned int phydw7; -}; - -/* Rx smooth factor */ -#define Rx_Smooth_Factor (20) - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h b/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h deleted file mode 100644 index 6b2d79e19088..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h +++ /dev/null @@ -1,182 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTL8723B_CMD_H__ -#define __RTL8723B_CMD_H__ - -/* */ -/* H2C CMD DEFINITION ------------------------------------------------ */ -/* */ - -enum { - /* Common Class: 000 */ - H2C_8723B_RSVD_PAGE = 0x00, - H2C_8723B_MEDIA_STATUS_RPT = 0x01, - H2C_8723B_SCAN_ENABLE = 0x02, - H2C_8723B_KEEP_ALIVE = 0x03, - H2C_8723B_DISCON_DECISION = 0x04, - H2C_8723B_PSD_OFFLOAD = 0x05, - H2C_8723B_AP_OFFLOAD = 0x08, - H2C_8723B_BCN_RSVDPAGE = 0x09, - H2C_8723B_PROBERSP_RSVDPAGE = 0x0A, - H2C_8723B_FCS_RSVDPAGE = 0x10, - H2C_8723B_FCS_INFO = 0x11, - H2C_8723B_AP_WOW_GPIO_CTRL = 0x13, - - /* PoweSave Class: 001 */ - H2C_8723B_SET_PWR_MODE = 0x20, - H2C_8723B_PS_TUNING_PARA = 0x21, - H2C_8723B_PS_TUNING_PARA2 = 0x22, - H2C_8723B_P2P_LPS_PARAM = 0x23, - H2C_8723B_P2P_PS_OFFLOAD = 0x24, - H2C_8723B_PS_SCAN_ENABLE = 0x25, - H2C_8723B_SAP_PS_ = 0x26, - H2C_8723B_INACTIVE_PS_ = 0x27, /* Inactive_PS */ - H2C_8723B_FWLPS_IN_IPS_ = 0x28, - - /* Dynamic Mechanism Class: 010 */ - H2C_8723B_MACID_CFG = 0x40, - H2C_8723B_TXBF = 0x41, - H2C_8723B_RSSI_SETTING = 0x42, - H2C_8723B_AP_REQ_TXRPT = 0x43, - H2C_8723B_INIT_RATE_COLLECT = 0x44, - - /* BT Class: 011 */ - H2C_8723B_B_TYPE_TDMA = 0x60, - H2C_8723B_BT_INFO = 0x61, - H2C_8723B_FORCE_BT_TXPWR = 0x62, - H2C_8723B_BT_IGNORE_WLANACT = 0x63, - H2C_8723B_DAC_SWING_VALUE = 0x64, - H2C_8723B_ANT_SEL_RSV = 0x65, - H2C_8723B_WL_OPMODE = 0x66, - H2C_8723B_BT_MP_OPER = 0x67, - H2C_8723B_BT_CONTROL = 0x68, - H2C_8723B_BT_WIFI_CTRL = 0x69, - H2C_8723B_BT_FW_PATCH = 0x6A, - H2C_8723B_BT_WLAN_CALIBRATION = 0x6D, - - /* WOWLAN Class: 100 */ - H2C_8723B_WOWLAN = 0x80, - H2C_8723B_REMOTE_WAKE_CTRL = 0x81, - H2C_8723B_AOAC_GLOBAL_INFO = 0x82, - H2C_8723B_AOAC_RSVD_PAGE = 0x83, - H2C_8723B_AOAC_RSVD_PAGE2 = 0x84, - H2C_8723B_D0_SCAN_OFFLOAD_CTRL = 0x85, - H2C_8723B_D0_SCAN_OFFLOAD_INFO = 0x86, - H2C_8723B_CHNL_SWITCH_OFFLOAD = 0x87, - - H2C_8723B_RESET_TSF = 0xC0, - H2C_8723B_MAXID, -}; -/* */ -/* H2C CMD CONTENT -------------------------------------------------- */ -/* */ -/* _RSVDPAGE_LOC_CMD_0x00 */ -#define SET_8723B_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd, 0, 8, __Value) -#define SET_8723B_H2CCMD_RSVDPAGE_LOC_PSPOLL(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+1, 0, 8, __Value) -#define SET_8723B_H2CCMD_RSVDPAGE_LOC_NULL_DATA(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+2, 0, 8, __Value) -#define SET_8723B_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+3, 0, 8, __Value) -#define SET_8723B_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+4, 0, 8, __Value) - -/* _MEDIA_STATUS_RPT_PARM_CMD_0x01 */ -#define SET_8723B_H2CCMD_MSRRPT_PARM_OPMODE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 1, __Value) -#define SET_8723B_H2CCMD_MSRRPT_PARM_MACID_IND(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 1, 1, __Value) -#define SET_8723B_H2CCMD_MSRRPT_PARM_MACID(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd+1, 0, 8, __Value) -#define SET_8723B_H2CCMD_MSRRPT_PARM_MACID_END(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd+2, 0, 8, __Value) - -/* _KEEP_ALIVE_CMD_0x03 */ -#define SET_8723B_H2CCMD_KEEPALIVE_PARM_ENABLE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 1, __Value) -#define SET_8723B_H2CCMD_KEEPALIVE_PARM_ADOPT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 1, 1, __Value) -#define SET_8723B_H2CCMD_KEEPALIVE_PARM_PKT_TYPE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 2, 1, __Value) -#define SET_8723B_H2CCMD_KEEPALIVE_PARM_CHECK_PERIOD(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd+1, 0, 8, __Value) - -/* _DISCONNECT_DECISION_CMD_0x04 */ -#define SET_8723B_H2CCMD_DISCONDECISION_PARM_ENABLE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 1, __Value) -#define SET_8723B_H2CCMD_DISCONDECISION_PARM_ADOPT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 1, 1, __Value) -#define SET_8723B_H2CCMD_DISCONDECISION_PARM_CHECK_PERIOD(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd+1, 0, 8, __Value) -#define SET_8723B_H2CCMD_DISCONDECISION_PARM_TRY_PKT_NUM(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd+2, 0, 8, __Value) - -/* _PWR_MOD_CMD_0x20 */ -#define SET_8723B_H2CCMD_PWRMODE_PARM_MODE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd, 0, 8, __Value) -#define SET_8723B_H2CCMD_PWRMODE_PARM_RLBM(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE((__pH2CCmd)+1, 0, 4, __Value) -#define SET_8723B_H2CCMD_PWRMODE_PARM_SMART_PS(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE((__pH2CCmd)+1, 4, 4, __Value) -#define SET_8723B_H2CCMD_PWRMODE_PARM_BCN_PASS_TIME(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+2, 0, 8, __Value) -#define SET_8723B_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+3, 0, 8, __Value) -#define SET_8723B_H2CCMD_PWRMODE_PARM_PWR_STATE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+4, 0, 8, __Value) -#define SET_8723B_H2CCMD_PWRMODE_PARM_BYTE5(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT((__pH2CCmd)+5, 0, 8, __Value) - -#define GET_8723B_H2CCMD_PWRMODE_PARM_MODE(__pH2CCmd) LE_BITS_TO_1BYTE(__pH2CCmd, 0, 8) - -/* _PS_TUNE_PARAM_CMD_0x21 */ -#define SET_8723B_H2CCMD_PSTUNE_PARM_BCN_TO_LIMIT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 8, __Value) -#define SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_TIMEOUT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+1, 0, 8, __Value) -#define SET_8723B_H2CCMD_PSTUNE_PARM_ADOPT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 0, 1, __Value) -#define SET_8723B_H2CCMD_PSTUNE_PARM_PS_TIMEOUT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 1, 7, __Value) -#define SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_PERIOD(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+3, 0, 8, __Value) - -/* _MACID_CFG_CMD_0x40 */ -#define SET_8723B_H2CCMD_MACID_CFG_MACID(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 8, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_RAID(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+1, 0, 5, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_SGI_EN(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+1, 7, 1, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_BW(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 0, 2, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_NO_UPDATE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 3, 1, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_VHT_EN(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 4, 2, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_DISPT(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 6, 1, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_DISRA(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 7, 1, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_RATE_MASK0(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+3, 0, 8, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_RATE_MASK1(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+4, 0, 8, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_RATE_MASK2(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+5, 0, 8, __Value) -#define SET_8723B_H2CCMD_MACID_CFG_RATE_MASK3(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+6, 0, 8, __Value) - -/* _RSSI_SETTING_CMD_0x42 */ -#define SET_8723B_H2CCMD_RSSI_SETTING_MACID(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 8, __Value) -#define SET_8723B_H2CCMD_RSSI_SETTING_RSSI(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 0, 7, __Value) -#define SET_8723B_H2CCMD_RSSI_SETTING_ULDL_STATE(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+3, 0, 8, __Value) - -/* _AP_REQ_TXRPT_CMD_0x43 */ -#define SET_8723B_H2CCMD_APREQRPT_PARM_MACID1(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 8, __Value) -#define SET_8723B_H2CCMD_APREQRPT_PARM_MACID2(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+1, 0, 8, __Value) - -/* _FORCE_BT_TXPWR_CMD_0x62 */ -#define SET_8723B_H2CCMD_BT_PWR_IDX(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE_8BIT(__pH2CCmd, 0, 8, __Value) - -/* _FORCE_BT_MP_OPER_CMD_0x67 */ -#define SET_8723B_H2CCMD_BT_MPOPER_VER(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 0, 4, __Value) -#define SET_8723B_H2CCMD_BT_MPOPER_REQNUM(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd, 4, 4, __Value) -#define SET_8723B_H2CCMD_BT_MPOPER_IDX(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+1, 0, 8, __Value) -#define SET_8723B_H2CCMD_BT_MPOPER_PARAM1(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+2, 0, 8, __Value) -#define SET_8723B_H2CCMD_BT_MPOPER_PARAM2(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+3, 0, 8, __Value) -#define SET_8723B_H2CCMD_BT_MPOPER_PARAM3(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE(__pH2CCmd+4, 0, 8, __Value) - -/* _BT_FW_PATCH_0x6A */ -#define SET_8723B_H2CCMD_BT_FW_PATCH_SIZE(__pH2CCmd, __Value) SET_BITS_TO_LE_2BYTE((u8 *)(__pH2CCmd), 0, 16, __Value) -#define SET_8723B_H2CCMD_BT_FW_PATCH_ADDR0(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE((__pH2CCmd)+2, 0, 8, __Value) -#define SET_8723B_H2CCMD_BT_FW_PATCH_ADDR1(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE((__pH2CCmd)+3, 0, 8, __Value) -#define SET_8723B_H2CCMD_BT_FW_PATCH_ADDR2(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE((__pH2CCmd)+4, 0, 8, __Value) -#define SET_8723B_H2CCMD_BT_FW_PATCH_ADDR3(__pH2CCmd, __Value) SET_BITS_TO_LE_1BYTE((__pH2CCmd)+5, 0, 8, __Value) - -/* */ -/* Function Statement -------------------------------------------------- */ -/* */ - -/* host message to firmware cmd */ -void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 Mode); -void rtl8723b_set_FwJoinBssRpt_cmd(struct adapter *padapter, u8 mstatus); -void rtl8723b_set_rssi_cmd(struct adapter *padapter, u8 *param); -void rtl8723b_Add_RateATid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level); -void rtl8723b_fw_try_ap_cmd(struct adapter *padapter, u32 need_ack); -/* s32 rtl8723b_set_lowpwr_lps_cmd(struct adapter *padapter, u8 enable); */ -void rtl8723b_set_FwPsTuneParam_cmd(struct adapter *padapter); -void rtl8723b_set_FwMacIdConfig_cmd(struct adapter *padapter, u8 mac_id, u8 raid, u8 bw, u8 sgi, u32 mask); -void rtl8723b_set_FwMediaStatusRpt_cmd(struct adapter *padapter, u8 mstatus, u8 macid); -void rtl8723b_download_rsvd_page(struct adapter *padapter, u8 mstatus); -void rtl8723b_download_BTCoex_AP_mode_rsvd_page(struct adapter *padapter); - -void rtl8723b_set_FwPwrModeInIPS_cmd(struct adapter *padapter, u8 cmd_param); - -s32 FillH2CCmd8723B(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_dm.h b/drivers/staging/rtl8723bs/include/rtl8723b_dm.h deleted file mode 100644 index 50ab7aed079e..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_dm.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTL8723B_DM_H__ -#define __RTL8723B_DM_H__ -/* */ -/* Description: */ -/* */ -/* This file is for 8723B dynamic mechanism only */ -/* */ -/* */ -/* */ - -/* */ -/* structure and define */ -/* */ - -/* */ -/* function prototype */ -/* */ - -void rtl8723b_init_dm_priv(struct adapter *padapter); - -void rtl8723b_InitHalDm(struct adapter *padapter); -void rtl8723b_HalDmWatchDog(struct adapter *padapter); -void rtl8723b_HalDmWatchDog_in_LPS(struct adapter *padapter); -void rtl8723b_hal_dm_in_lps(struct adapter *padapter); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_hal.h b/drivers/staging/rtl8723bs/include/rtl8723b_hal.h deleted file mode 100644 index c442f01aa585..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_hal.h +++ /dev/null @@ -1,246 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTL8723B_HAL_H__ -#define __RTL8723B_HAL_H__ - -#include "hal_data.h" - -#include "rtl8723b_spec.h" -#include "rtl8723b_rf.h" -#include "rtl8723b_dm.h" -#include "rtl8723b_recv.h" -#include "rtl8723b_xmit.h" -#include "rtl8723b_cmd.h" -#include "hal_pwr_seq.h" -#include "Hal8192CPhyReg.h" -#include "hal_phy_cfg.h" - -/* */ -/* RTL8723B From header */ -/* */ - -#define FW_8723B_SIZE 0x8000 -#define FW_8723B_START_ADDRESS 0x1000 -#define FW_8723B_END_ADDRESS 0x1FFF /* 0x5FFF */ - -#define IS_FW_HEADER_EXIST_8723B(fw_hdr) \ - ((le16_to_cpu(fw_hdr->signature) & 0xFFF0) == 0x5300) - -struct rt_firmware { - u32 fw_length; - u8 *fw_buffer_sz; -}; - -/* This structure must be carefully byte-ordered. */ -struct rt_firmware_hdr { - /* 8-byte alignment required */ - - /* LONG WORD 0 ---- */ - __le16 signature; /* 92C0: test chip; 92C, 88C0: test chip; - * 88C1: MP A-cut; 92C1: MP A-cut - */ - u8 category; /* AP/NIC and USB/PCI */ - u8 function; /* Reserved for different FW function indications, - * for further use when driver needs to download - * different FW in different conditions. - */ - __le16 version; /* FW Version */ - __le16 subversion; /* FW Subversion, default 0x00 */ - - /* LONG WORD 1 ---- */ - u8 month; /* Release time Month field */ - u8 date; /* Release time Date field */ - u8 hour; /* Release time Hour field */ - u8 minute; /* Release time Minute field */ - - __le16 ram_code_size; /* The size of RAM code */ - __le16 rsvd2; - - /* LONG WORD 2 ---- */ - __le32 svn_idx; /* The SVN entry index */ - __le32 rsvd3; - - /* LONG WORD 3 ---- */ - __le32 rsvd4; - __le32 rsvd5; -}; - -#define DRIVER_EARLY_INT_TIME_8723B 0x05 -#define BCN_DMA_ATIME_INT_TIME_8723B 0x02 - -/* REG_TBTT_PROHIBIT (0x0540) - TBTT prohibit hold/setup in 32us units */ -#define TBTT_PROHIBIT_SETUP_8723B 0x04 -#define TBTT_PROHIBIT_HOLD_8723B 0x64 -#define TBTT_PROHIBIT_TIME_8723B \ - ((TBTT_PROHIBIT_HOLD_8723B << 8) | TBTT_PROHIBIT_SETUP_8723B) - -/* REG_BCNTCFG (0x0510) - beacon AIFS, CWmin, CWmax (EDCA-like layout) */ -#define BCN_AIFS_8723B 0x0F -#define BCN_CW_MIN_8723B 0x06 -#define BCN_CW_MAX_8723B 0x06 -#define BCNTCFG_8723B \ - ((BCN_CW_MAX_8723B << 12) | (BCN_CW_MIN_8723B << 8) | BCN_AIFS_8723B) - -/* for 8723B */ -/* TX 32K, RX 16K, Page size 128B for TX, 8B for RX */ -#define PAGE_SIZE_TX_8723B 128 -#define PAGE_SIZE_RX_8723B 8 - -#define RX_DMA_SIZE_8723B 0x4000 /* 16K */ -#define RX_DMA_RESERVED_SIZE_8723B 0x80 /* 128B, reserved for tx report */ -#define RX_DMA_BOUNDARY_8723B \ - (RX_DMA_SIZE_8723B - RX_DMA_RESERVED_SIZE_8723B - 1) - -/* Note: We will divide number of pages equally for each queue other than the - * public queue! - */ - -/* For General Reserved Page Number(Beacon Queue is reserved page) */ -/* Beacon:2, PS-Poll:1, Null Data:1, Qos Null Data:1, BT Qos Null Data:1 */ -#define BCNQ_PAGE_NUM_8723B 0x08 -#define BCNQ1_PAGE_NUM_8723B 0x00 - -#define MAX_RX_DMA_BUFFER_SIZE_8723B 0x2800 /* RX 10K */ - -/* For WoWLan, more reserved page */ -/* ARP Rsp:1, RWC:1, GTK Info:1, GTK RSP:2, GTK EXT MEM:2, PNO: 6 */ -#define WOWLAN_PAGE_NUM_8723B 0x00 - -#define TX_TOTAL_PAGE_NUMBER_8723B \ - (0xFF - BCNQ_PAGE_NUM_8723B - \ - BCNQ1_PAGE_NUM_8723B - \ - WOWLAN_PAGE_NUM_8723B) -#define TX_PAGE_BOUNDARY_8723B (TX_TOTAL_PAGE_NUMBER_8723B + 1) - -#define WMM_NORMAL_TX_TOTAL_PAGE_NUMBER_8723B TX_TOTAL_PAGE_NUMBER_8723B -#define WMM_NORMAL_TX_PAGE_BOUNDARY_8723B \ - (WMM_NORMAL_TX_TOTAL_PAGE_NUMBER_8723B + 1) - -/* For Normal Chip Setting */ -/* (HPQ + LPQ + NPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER_8723B */ -#define NORMAL_PAGE_NUM_HPQ_8723B 0x0C -#define NORMAL_PAGE_NUM_LPQ_8723B 0x02 -#define NORMAL_PAGE_NUM_NPQ_8723B 0x02 - -/* Note: For Normal Chip Setting, modify later */ -#define WMM_NORMAL_PAGE_NUM_HPQ_8723B 0x30 -#define WMM_NORMAL_PAGE_NUM_LPQ_8723B 0x20 -#define WMM_NORMAL_PAGE_NUM_NPQ_8723B 0x20 - -#include "hal_com.h" - -#define EFUSE_OOB_PROTECT_BYTES 15 - -#define HAL_EFUSE_MEMORY - -#define HWSET_MAX_SIZE_8723B 512 -#define EFUSE_REAL_CONTENT_LEN_8723B 512 -#define EFUSE_MAP_LEN_8723B 512 -#define EFUSE_MAX_SECTION_8723B 64 - -#define EFUSE_IC_ID_OFFSET 506 /* For some inferiority IC purpose. - * Added by Roger, 2009.09.02. - */ -#define AVAILABLE_EFUSE_ADDR(addr) (addr < EFUSE_REAL_CONTENT_LEN_8723B) - -#define EFUSE_ACCESS_ON 0x69 /* For RTL8723 only. */ -#define EFUSE_ACCESS_OFF 0x00 /* For RTL8723 only. */ - -/* */ -/* EFUSE for BT definition */ -/* */ -#define EFUSE_BT_REAL_BANK_CONTENT_LEN 512 -#define EFUSE_BT_REAL_CONTENT_LEN 1536 /* 512*3 */ -#define EFUSE_BT_MAP_LEN 1024 /* 1k bytes */ -#define EFUSE_BT_MAX_SECTION 128 /* 1024/8 */ - -#define EFUSE_PROTECT_BYTES_BANK 16 - -/* Description: Determine the types of C2H events that are the same in driver - * and FW; First constructed by tynli. 2009.10.09. - */ -enum { - C2H_DBG = 0, - C2H_TSF = 1, - C2H_AP_RPT_RSP = 2, - C2H_CCX_TX_RPT = 3, /* The FW notify the report - * of the specific tx packet. - */ - C2H_BT_RSSI = 4, - C2H_BT_OP_MODE = 5, - C2H_EXT_RA_RPT = 6, - C2H_8723B_BT_INFO = 9, - C2H_HW_INFO_EXCH = 10, - C2H_8723B_BT_MP_INFO = 11, - MAX_C2HEVENT -}; - -struct c2h_evt_hdr_t { - u8 CmdID; - u8 CmdLen; - u8 CmdSeq; -} __packed; - -enum { /* tag_Package_Definition */ - PACKAGE_DEFAULT, - PACKAGE_QFN68, - PACKAGE_TFBGA90, - PACKAGE_TFBGA80, - PACKAGE_TFBGA79 -}; - -/* rtl8723a_hal_init.c */ -s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw); -void rtl8723b_FirmwareSelfReset(struct adapter *padapter); -void rtl8723b_InitializeFirmwareVars(struct adapter *padapter); - -void rtl8723b_InitAntenna_Selection(struct adapter *padapter); -void rtl8723b_init_default_value(struct adapter *padapter); - -s32 rtl8723b_InitLLTTable(struct adapter *padapter); - -/* EFuse */ -u8 GetEEPROMSize8723B(struct adapter *padapter); -void Hal_InitPGData(struct adapter *padapter, u8 *PROMContent); -void Hal_EfuseParseIDCode(struct adapter *padapter, u8 *hwinfo); -void Hal_EfuseParseTxPowerInfo_8723B(struct adapter *padapter, u8 *PROMContent, - bool AutoLoadFail); -void Hal_EfuseParseBTCoexistInfo_8723B(struct adapter *padapter, u8 *hwinfo, - bool AutoLoadFail); -void Hal_EfuseParseChnlPlan_8723B(struct adapter *padapter, u8 *hwinfo, - bool AutoLoadFail); -void Hal_EfuseParseXtal_8723B(struct adapter *padapter, u8 *hwinfo, - bool AutoLoadFail); -void Hal_EfuseParseThermalMeter_8723B(struct adapter *padapter, u8 *hwinfo, - u8 AutoLoadFail); -void Hal_EfuseParsePackageType_8723B(struct adapter *padapter, u8 *hwinfo, - bool AutoLoadFail); -void Hal_EfuseParseVoltage_8723B(struct adapter *padapter, u8 *hwinfo, - bool AutoLoadFail); - -void C2HPacketHandler_8723B(struct adapter *padapter, u8 *pbuffer, u16 length); - -void SetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val); -void GetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val); -u8 GetHalDefVar8723B(struct adapter *padapter, enum hal_def_variable variable, - void *pval); - -/* register */ -void rtl8723b_InitBeaconParameters(struct adapter *padapter); -void _InitBurstPktLen_8723BS(struct adapter *adapter); -void _8051Reset8723(struct adapter *padapter); - -int FirmwareDownloadBT(struct adapter *adapter, struct rt_firmware *firmware); - -void CCX_FwC2HTxRpt_8723b(struct adapter *padapter, u8 *pdata, u8 len); -s32 c2h_id_filter_ccx_8723b(u8 *buf); -s32 c2h_handler_8723b(struct adapter *padapter, u8 *pC2hEvent); - -void Hal_ReadRFGainOffset(struct adapter *padapter, u8 *hwinfo, - bool AutoLoadFail); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_recv.h b/drivers/staging/rtl8723bs/include/rtl8723b_recv.h deleted file mode 100644 index e9ebecb224a6..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_recv.h +++ /dev/null @@ -1,95 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTL8723B_RECV_H__ -#define __RTL8723B_RECV_H__ - -#include - -struct rxreport_8723b { - /* DWORD 0 */ - u32 pktlen:14; - u32 crc32:1; - u32 icverr:1; - u32 drvinfosize:4; - u32 security:3; - u32 qos:1; - u32 shift:2; - u32 physt:1; - u32 swdec:1; - u32 rsvd0028:2; - u32 eor:1; - u32 rsvd0031:1; - - /* DWORD 1 */ - u32 macid:7; - u32 rsvd0407:1; - u32 tid:4; - u32 macid_vld:1; - u32 amsdu:1; - u32 rxid_match:1; - u32 paggr:1; - u32 a1fit:4; - u32 chkerr:1; /* 20 */ - u32 rx_ipv:1; - u32 rx_is_tcp_udp:1; - u32 chk_vld:1; /* 23 */ - u32 pam:1; - u32 pwr:1; - u32 md:1; - u32 mf:1; - u32 type:2; - u32 mc:1; - u32 bc:1; - - /* DWORD 2 */ - u32 seq:12; - u32 frag:4; - u32 rx_is_qos:1; - u32 rsvd0817:1; - u32 wlanhd_iv_len:6; - u32 hwrsvd0824:4; - u32 c2h_ind:1; - u32 rsvd0829:2; - u32 fcs_ok:1; - - /* DWORD 3 */ - u32 rx_rate:7; - u32 rsvd1207:3; - u32 htc:1; - u32 esop:1; - u32 bssid_fit:2; - u32 rsvd1214:2; - u32 dma_agg_num:8; - u32 rsvd1224:5; - u32 patternmatch:1; - u32 unicastwake:1; - u32 magicwake:1; - - /* DWORD 4 */ - u32 splcp:1; /* Ofdm sgi or cck_splcp */ - u32 ldpc:1; - u32 stbc:1; - u32 not_sounding:1; - u32 bw:2; - u32 rsvd1606:26; - - /* DWORD 5 */ - u32 tsfl; -}; - -s32 rtl8723bs_init_recv_priv(struct adapter *padapter); -void rtl8723bs_free_recv_priv(struct adapter *padapter); - -void rtl8723b_query_rx_phy_status(union recv_frame *prframe, struct phy_stat *pphy_stat); -void rtl8723b_process_phy_info(struct adapter *padapter, void *prframe); - -void rtl8723b_read_chip_version(struct adapter *padapter); -void rtl8723bs_init_default_value(struct adapter *padapter); -void rtl8723bs_interface_configure(struct adapter *padapter); -void rtw_read_adapter_info(struct adapter *padapter); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_rf.h b/drivers/staging/rtl8723bs/include/rtl8723b_rf.h deleted file mode 100644 index 525eb2facca0..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_rf.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTL8723B_RF_H__ -#define __RTL8723B_RF_H__ - - -int PHY_RF6052_Config8723B(struct adapter *Adapter); - -void -PHY_RF6052SetBandwidth8723B(struct adapter *Adapter, - enum channel_width Bandwidth); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_spec.h b/drivers/staging/rtl8723bs/include/rtl8723b_spec.h deleted file mode 100644 index 7f749e32a5b9..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_spec.h +++ /dev/null @@ -1,237 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - *******************************************************************************/ -#ifndef __RTL8723B_SPEC_H__ -#define __RTL8723B_SPEC_H__ - -#define HAL_NAV_UPPER_UNIT_8723B 128 /* micro-second */ - -/* */ -/* */ -/* 0x0000h ~ 0x00FFh System Configuration */ -/* */ -/* */ -#define REG_RSV_CTRL_8723B 0x001C /* 3 Byte */ -#define REG_BT_WIFI_ANTENNA_SWITCH_8723B 0x0038 -#define REG_HSISR_8723B 0x005c -#define REG_PAD_CTRL1_8723B 0x0064 -#define REG_AFE_CTRL_4_8723B 0x0078 -#define REG_HMEBOX_DBG_0_8723B 0x0088 -#define REG_HMEBOX_DBG_1_8723B 0x008A -#define REG_HMEBOX_DBG_2_8723B 0x008C -#define REG_HMEBOX_DBG_3_8723B 0x008E -#define REG_HIMR0_8723B 0x00B0 -#define REG_HISR0_8723B 0x00B4 -#define REG_HIMR1_8723B 0x00B8 -#define REG_HISR1_8723B 0x00BC -#define REG_PMC_DBG_CTRL2_8723B 0x00CC - -/* */ -/* */ -/* 0x0100h ~ 0x01FFh MACTOP General Configuration */ -/* */ -/* */ -#define REG_C2HEVT_CMD_ID_8723B 0x01A0 -#define REG_C2HEVT_CMD_LEN_8723B 0x01AE -#define REG_WOWLAN_WAKE_REASON 0x01C7 -#define REG_WOWLAN_GTK_DBG1 0x630 -#define REG_WOWLAN_GTK_DBG2 0x634 - -#define REG_HMEBOX_EXT0_8723B 0x01F0 -#define REG_HMEBOX_EXT1_8723B 0x01F4 -#define REG_HMEBOX_EXT2_8723B 0x01F8 -#define REG_HMEBOX_EXT3_8723B 0x01FC - -/* */ -/* */ -/* 0x0200h ~ 0x027Fh TXDMA Configuration */ -/* */ -/* */ - -/* */ -/* */ -/* 0x0280h ~ 0x02FFh RXDMA Configuration */ -/* */ -/* */ -#define REG_RXDMA_CONTROL_8723B 0x0286 /* Control the RX DMA. */ -#define REG_RXDMA_MODE_CTRL_8723B 0x0290 - -/* */ -/* */ -/* 0x0300h ~ 0x03FFh PCIe */ -/* */ -/* */ -#define REG_PCIE_CTRL_REG_8723B 0x0300 -#define REG_INT_MIG_8723B 0x0304 /* Interrupt Migration */ -#define REG_BCNQ_DESA_8723B 0x0308 /* TX Beacon Descriptor Address */ -#define REG_HQ_DESA_8723B 0x0310 /* TX High Queue Descriptor Address */ -#define REG_MGQ_DESA_8723B 0x0318 /* TX Manage Queue Descriptor Address */ -#define REG_VOQ_DESA_8723B 0x0320 /* TX VO Queue Descriptor Address */ -#define REG_VIQ_DESA_8723B 0x0328 /* TX VI Queue Descriptor Address */ -#define REG_BEQ_DESA_8723B 0x0330 /* TX BE Queue Descriptor Address */ -#define REG_BKQ_DESA_8723B 0x0338 /* TX BK Queue Descriptor Address */ -#define REG_RX_DESA_8723B 0x0340 /* RX Queue Descriptor Address */ -#define REG_DBI_WDATA_8723B 0x0348 /* DBI Write Data */ -#define REG_DBI_RDATA_8723B 0x034C /* DBI Read Data */ -#define REG_DBI_ADDR_8723B 0x0350 /* DBI Address */ -#define REG_DBI_FLAG_8723B 0x0352 /* DBI Read/Write Flag */ -#define REG_MDIO_WDATA_8723B 0x0354 /* MDIO for Write PCIE PHY */ -#define REG_MDIO_RDATA_8723B 0x0356 /* MDIO for Reads PCIE PHY */ -#define REG_MDIO_CTL_8723B 0x0358 /* MDIO for Control */ -#define REG_DBG_SEL_8723B 0x0360 /* Debug Selection Register */ -#define REG_PCIE_HRPWM_8723B 0x0361 /* PCIe RPWM */ -#define REG_PCIE_HCPWM_8723B 0x0363 /* PCIe CPWM */ -#define REG_PCIE_MULTIFET_CTRL_8723B 0x036A /* PCIE Multi-Fethc Control */ - -/* */ -/* */ -/* 0x0400h ~ 0x047Fh Protocol Configuration */ -/* */ -/* */ -#define REG_TXPKTBUF_BCNQ_BDNY_8723B 0x0424 -#define REG_TXPKTBUF_MGQ_BDNY_8723B 0x0425 -#define REG_TXPKTBUF_WMAC_LBK_BF_HD_8723B 0x045D -#define REG_AMPDU_BURST_MODE_8723B 0x04BC - -/* */ -/* */ -/* 0x0500h ~ 0x05FFh EDCA Configuration */ -/* */ -/* */ -#define REG_SECONDARY_CCA_CTRL_8723B 0x0577 - -/* */ -/* */ -/* 0x0600h ~ 0x07FFh WMAC Configuration */ -/* */ -/* */ - -/* */ -/* SDIO Bus Specification */ -/* */ - -/* */ -/* SDIO CMD Address Mapping */ -/* */ - -/* */ -/* I/O bus domain (Host) */ -/* */ - -/* */ -/* SDIO register */ -/* */ -#define SDIO_REG_HCPWM1_8723B 0x025 /* HCI Current Power Mode 1 */ - -/* */ -/* 8723 Register Bit and Content definition */ -/* */ - -/* 2 HSISR */ -/* interrupt mask which needs to clear */ -#define MASK_HSISR_CLEAR (HSISR_GPIO12_0_INT |\ - HSISR_SPS_OCP_INT |\ - HSISR_RON_INT |\ - HSISR_PDNINT |\ - HSISR_GPIO9_INT) - -/* */ -/* */ -/* 0x0100h ~ 0x01FFh MACTOP General Configuration */ -/* */ -/* */ - -/* */ -/* */ -/* 0x0200h ~ 0x027Fh TXDMA Configuration */ -/* */ -/* */ - -/* */ -/* */ -/* 0x0280h ~ 0x02FFh RXDMA Configuration */ -/* */ -/* */ -#define BIT_USB_RXDMA_AGG_EN BIT(31) -#define RXDMA_AGG_MODE_EN BIT(1) - -/* */ -/* */ -/* 0x0400h ~ 0x047Fh Protocol Configuration */ -/* */ -/* */ - -/* */ -/* 8723B REG_CCK_CHECK (offset 0x454) */ -/* */ -#define BIT_BCN_PORT_SEL BIT(5) - -/* */ -/* */ -/* 0x0500h ~ 0x05FFh EDCA Configuration */ -/* */ -/* */ - -/* */ -/* */ -/* 0x0600h ~ 0x07FFh WMAC Configuration */ -/* */ -/* */ -#define EEPROM_RF_GAIN_OFFSET 0xC1 -#define EEPROM_RF_GAIN_VAL 0x1F6 - -/* */ -/* 8195 IMR/ISR bits (offset 0xB0, 8bits) */ -/* */ -#define IMR_DISABLED_8723B 0 -/* IMR DW0(0x00B0-00B3) Bit 0-31 */ -#define IMR_TIMER2_8723B BIT(31) /* Timeout interrupt 2 */ -#define IMR_TIMER1_8723B BIT(30) /* Timeout interrupt 1 */ -#define IMR_PSTIMEOUT_8723B BIT(29) /* Power Save Time Out Interrupt */ -#define IMR_GTINT4_8723B BIT(28) /* When GTIMER4 expires, this bit is set to 1 */ -#define IMR_GTINT3_8723B BIT(27) /* When GTIMER3 expires, this bit is set to 1 */ -#define IMR_TXBCN0ERR_8723B BIT(26) /* Transmit Beacon0 Error */ -#define IMR_TXBCN0OK_8723B BIT(25) /* Transmit Beacon0 OK */ -#define IMR_TSF_BIT32_TOGGLE_8723B BIT(24) /* TSF Timer BIT32 toggle indication interrupt */ -#define IMR_BCNDMAINT0_8723B BIT(20) /* Beacon DMA Interrupt 0 */ -#define IMR_BCNDERR0_8723B BIT(16) /* Beacon Queue DMA OK0 */ -#define IMR_HSISR_IND_ON_INT_8723B BIT(15) /* HSISR Indicator (HSIMR & HSISR is true, this bit is set to 1) */ -#define IMR_BCNDMAINT_E_8723B BIT(14) /* Beacon DMA Interrupt Extension for Win7 */ -#define IMR_ATIMEND_8723B BIT(12) /* CTWidnow End or ATIM Window End */ -#define IMR_C2HCMD_8723B BIT(10) /* CPU to Host Command INT Status, Write 1 clear */ -#define IMR_CPWM2_8723B BIT(9) /* CPU power Mode exchange INT Status, Write 1 clear */ -#define IMR_CPWM_8723B BIT(8) /* CPU power Mode exchange INT Status, Write 1 clear */ -#define IMR_HIGHDOK_8723B BIT(7) /* High Queue DMA OK */ -#define IMR_MGNTDOK_8723B BIT(6) /* Management Queue DMA OK */ -#define IMR_BKDOK_8723B BIT(5) /* AC_BK DMA OK */ -#define IMR_BEDOK_8723B BIT(4) /* AC_BE DMA OK */ -#define IMR_VIDOK_8723B BIT(3) /* AC_VI DMA OK */ -#define IMR_VODOK_8723B BIT(2) /* AC_VO DMA OK */ -#define IMR_RDU_8723B BIT(1) /* Rx Descriptor Unavailable */ -#define IMR_ROK_8723B BIT(0) /* Receive DMA OK */ - -/* IMR DW1(0x00B4-00B7) Bit 0-31 */ -#define IMR_BCNDMAINT7_8723B BIT(27) /* Beacon DMA Interrupt 7 */ -#define IMR_BCNDMAINT6_8723B BIT(26) /* Beacon DMA Interrupt 6 */ -#define IMR_BCNDMAINT5_8723B BIT(25) /* Beacon DMA Interrupt 5 */ -#define IMR_BCNDMAINT4_8723B BIT(24) /* Beacon DMA Interrupt 4 */ -#define IMR_BCNDMAINT3_8723B BIT(23) /* Beacon DMA Interrupt 3 */ -#define IMR_BCNDMAINT2_8723B BIT(22) /* Beacon DMA Interrupt 2 */ -#define IMR_BCNDMAINT1_8723B BIT(21) /* Beacon DMA Interrupt 1 */ -#define IMR_BCNDOK7_8723B BIT(20) /* Beacon Queue DMA OK Interrupt 7 */ -#define IMR_BCNDOK6_8723B BIT(19) /* Beacon Queue DMA OK Interrupt 6 */ -#define IMR_BCNDOK5_8723B BIT(18) /* Beacon Queue DMA OK Interrupt 5 */ -#define IMR_BCNDOK4_8723B BIT(17) /* Beacon Queue DMA OK Interrupt 4 */ -#define IMR_BCNDOK3_8723B BIT(16) /* Beacon Queue DMA OK Interrupt 3 */ -#define IMR_BCNDOK2_8723B BIT(15) /* Beacon Queue DMA OK Interrupt 2 */ -#define IMR_BCNDOK1_8723B BIT(14) /* Beacon Queue DMA OK Interrupt 1 */ -#define IMR_ATIMEND_E_8723B BIT(13) /* ATIM Window End Extension for Win7 */ -#define IMR_TXERR_8723B BIT(11) /* Tx Error Flag Interrupt Status, write 1 clear. */ -#define IMR_RXERR_8723B BIT(10) /* Rx Error Flag INT Status, Write 1 clear */ -#define IMR_TXFOVW_8723B BIT(9) /* Transmit FIFO Overflow */ -#define IMR_RXFOVW_8723B BIT(8) /* Receive FIFO Overflow */ - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h b/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h deleted file mode 100644 index ddf868c7899b..000000000000 --- a/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h +++ /dev/null @@ -1,421 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTL8723B_XMIT_H__ -#define __RTL8723B_XMIT_H__ - -/* */ -/* Queue Select Value in TxDesc */ -/* */ -#define QSLT_BK 0x2/* 0x01 */ -#define QSLT_BE 0x0 -#define QSLT_VI 0x5/* 0x4 */ -#define QSLT_VO 0x7/* 0x6 */ -#define QSLT_BEACON 0x10 -#define QSLT_HIGH 0x11 -#define QSLT_MGNT 0x12 -#define QSLT_CMD 0x13 - -#define MAX_TID (15) - -/* OFFSET 0 */ -#define OFFSET_SZ 0 -#define OFFSET_SHT 16 -#define BMC BIT(24) -#define LSG BIT(26) -#define FSG BIT(27) -#define OWN BIT(31) - - -/* OFFSET 4 */ -#define PKT_OFFSET_SZ 0 -#define BK BIT(6) -#define QSEL_SHT 8 -#define Rate_ID_SHT 16 -#define NAVUSEHDR BIT(20) -#define PKT_OFFSET_SHT 26 -#define HWPC BIT(31) - -/* OFFSET 8 */ -#define AGG_EN BIT(29) - -/* OFFSET 12 */ -#define SEQ_SHT 16 - -/* OFFSET 16 */ -#define QoS BIT(6) -#define HW_SEQ_EN BIT(7) -#define USERATE BIT(8) -#define DISDATAFB BIT(10) -#define DATA_SHORT BIT(24) -#define DATA_BW BIT(25) - -/* OFFSET 20 */ -#define SGI BIT(6) - -/* */ -/* defined for TX DESC Operation */ -/* */ -struct txdesc_8723b { - /* Offset 0 */ - u32 pktlen:16; - u32 offset:8; - u32 bmc:1; - u32 htc:1; - u32 rsvd0026:1; - u32 rsvd0027:1; - u32 linip:1; - u32 noacm:1; - u32 gf:1; - u32 rsvd0031:1; - - /* Offset 4 */ - u32 macid:7; - u32 rsvd0407:1; - u32 qsel:5; - u32 rdg_nav_ext:1; - u32 lsig_txop_en:1; - u32 pifs:1; - u32 rate_id:5; - u32 en_desc_id:1; - u32 sectype:2; - u32 pkt_offset:5; /* unit: 8 bytes */ - u32 moredata:1; - u32 txop_ps_cap:1; - u32 txop_ps_mode:1; - - /* Offset 8 */ - u32 p_aid:9; - u32 rsvd0809:1; - u32 cca_rts:2; - u32 agg_en:1; - u32 rdg_en:1; - u32 null_0:1; - u32 null_1:1; - u32 bk:1; - u32 morefrag:1; - u32 raw:1; - u32 spe_rpt:1; - u32 ampdu_density:3; - u32 bt_null:1; - u32 g_id:6; - u32 rsvd0830:2; - - /* Offset 12 */ - u32 wheader_len:4; - u32 chk_en:1; - u32 early_rate:1; - u32 hw_ssn_sel:2; - u32 userate:1; - u32 disrtsfb:1; - u32 disdatafb:1; - u32 cts2self:1; - u32 rtsen:1; - u32 hw_rts_en:1; - u32 port_id:1; - u32 navusehdr:1; - u32 use_max_len:1; - u32 max_agg_num:5; - u32 ndpa:2; - u32 ampdu_max_time:8; - - /* Offset 16 */ - u32 datarate:7; - u32 try_rate:1; - u32 data_ratefb_lmt:5; - u32 rts_ratefb_lmt:4; - u32 rty_lmt_en:1; - u32 data_rt_lmt:6; - u32 rtsrate:5; - u32 pcts_en:1; - u32 pcts_mask_idx:2; - - /* Offset 20 */ - u32 data_sc:4; - u32 data_short:1; - u32 data_bw:2; - u32 data_ldpc:1; - u32 data_stbc:2; - u32 vcs_stbc:2; - u32 rts_short:1; - u32 rts_sc:4; - u32 rsvd2016:7; - u32 tx_ant:4; - u32 txpwr_offset:3; - u32 rsvd2031:1; - - /* Offset 24 */ - u32 sw_define:12; - u32 mbssid:4; - u32 antsel_A:3; - u32 antsel_B:3; - u32 antsel_C:3; - u32 antsel_D:3; - u32 rsvd2428:4; - - /* Offset 28 */ - u32 checksum:16; - u32 rsvd2816:8; - u32 usb_txagg_num:8; - - /* Offset 32 */ - u32 rts_rc:6; - u32 bar_rty_th:2; - u32 data_rc:6; - u32 rsvd3214:1; - u32 en_hwseq:1; - u32 nextneadpage:8; - u32 tailpage:8; - - /* Offset 36 */ - u32 padding_len:11; - u32 txbf_path:1; - u32 seq:12; - u32 final_data_rate:8; -}; - -#ifndef __INC_HAL8723BDESC_H -#define __INC_HAL8723BDESC_H - -#define RX_STATUS_DESC_SIZE_8723B 24 -#define RX_DRV_INFO_SIZE_UNIT_8723B 8 - - -/* DWORD 0 */ -#define SET_RX_STATUS_DESC_PKT_LEN_8723B(__pRxStatusDesc, __Value) SET_BITS_TO_LE_4BYTE(__pRxStatusDesc, 0, 14, __Value) -#define SET_RX_STATUS_DESC_EOR_8723B(__pRxStatusDesc, __Value) SET_BITS_TO_LE_4BYTE(__pRxStatusDesc, 30, 1, __Value) -#define SET_RX_STATUS_DESC_OWN_8723B(__pRxStatusDesc, __Value) SET_BITS_TO_LE_4BYTE(__pRxStatusDesc, 31, 1, __Value) - -#define GET_RX_STATUS_DESC_PKT_LEN_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 0, 14) -#define GET_RX_STATUS_DESC_CRC32_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 14, 1) -#define GET_RX_STATUS_DESC_ICV_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 15, 1) -#define GET_RX_STATUS_DESC_DRVINFO_SIZE_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 16, 4) -#define GET_RX_STATUS_DESC_SECURITY_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 20, 3) -#define GET_RX_STATUS_DESC_QOS_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 23, 1) -#define GET_RX_STATUS_DESC_SHIFT_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 24, 2) -#define GET_RX_STATUS_DESC_PHY_STATUS_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 26, 1) -#define GET_RX_STATUS_DESC_SWDEC_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 27, 1) -#define GET_RX_STATUS_DESC_LAST_SEG_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 28, 1) -#define GET_RX_STATUS_DESC_FIRST_SEG_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 29, 1) -#define GET_RX_STATUS_DESC_EOR_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 30, 1) -#define GET_RX_STATUS_DESC_OWN_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 31, 1) - -/* DWORD 1 */ -#define GET_RX_STATUS_DESC_MACID_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 0, 7) -#define GET_RX_STATUS_DESC_TID_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 8, 4) -#define GET_RX_STATUS_DESC_AMSDU_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 13, 1) -#define GET_RX_STATUS_DESC_RXID_MATCH_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 14, 1) -#define GET_RX_STATUS_DESC_PAGGR_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 15, 1) -#define GET_RX_STATUS_DESC_A1_FIT_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 16, 4) -#define GET_RX_STATUS_DESC_CHKERR_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 20, 1) -#define GET_RX_STATUS_DESC_IPVER_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 21, 1) -#define GET_RX_STATUS_DESC_IS_TCPUDP__8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 22, 1) -#define GET_RX_STATUS_DESC_CHK_VLD_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 23, 1) -#define GET_RX_STATUS_DESC_PAM_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 24, 1) -#define GET_RX_STATUS_DESC_PWR_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 25, 1) -#define GET_RX_STATUS_DESC_MORE_DATA_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 26, 1) -#define GET_RX_STATUS_DESC_MORE_FRAG_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 27, 1) -#define GET_RX_STATUS_DESC_TYPE_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 28, 2) -#define GET_RX_STATUS_DESC_MC_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 30, 1) -#define GET_RX_STATUS_DESC_BC_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+4, 31, 1) - -/* DWORD 2 */ -#define GET_RX_STATUS_DESC_SEQ_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+8, 0, 12) -#define GET_RX_STATUS_DESC_FRAG_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+8, 12, 4) -#define GET_RX_STATUS_DESC_RX_IS_QOS_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+8, 16, 1) -#define GET_RX_STATUS_DESC_WLANHD_IV_LEN_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+8, 18, 6) -#define GET_RX_STATUS_DESC_RPT_SEL_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+8, 28, 1) - -/* DWORD 3 */ -#define GET_RX_STATUS_DESC_RX_RATE_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 0, 7) -#define GET_RX_STATUS_DESC_HTC_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 10, 1) -#define GET_RX_STATUS_DESC_EOSP_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 11, 1) -#define GET_RX_STATUS_DESC_BSSID_FIT_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 12, 2) -#define GET_RX_STATUS_DESC_PATTERN_MATCH_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+12, 29, 1) -#define GET_RX_STATUS_DESC_UNICAST_MATCH_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+12, 30, 1) -#define GET_RX_STATUS_DESC_MAGIC_MATCH_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+12, 31, 1) - -/* DWORD 6 */ -#define GET_RX_STATUS_DESC_SPLCP_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+16, 0, 1) -#define GET_RX_STATUS_DESC_LDPC_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+16, 1, 1) -#define GET_RX_STATUS_DESC_STBC_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+16, 2, 1) -#define GET_RX_STATUS_DESC_BW_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+16, 4, 2) - -/* DWORD 5 */ -#define GET_RX_STATUS_DESC_TSFL_8723B(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 0, 32) - -#define GET_RX_STATUS_DESC_BUFF_ADDR_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+24, 0, 32) -#define GET_RX_STATUS_DESC_BUFF_ADDR64_8723B(__pRxDesc) LE_BITS_TO_4BYTE(__pRxDesc+28, 0, 32) - -#define SET_RX_STATUS_DESC_BUFF_ADDR_8723B(__pRxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pRxDesc+24, 0, 32, __Value) - - -/* Dword 0 */ -#define GET_TX_DESC_OWN_8723B(__pTxDesc) LE_BITS_TO_4BYTE(__pTxDesc, 31, 1) - -#define SET_TX_DESC_PKT_SIZE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 0, 16, __Value) -#define SET_TX_DESC_OFFSET_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 16, 8, __Value) -#define SET_TX_DESC_BMC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 24, 1, __Value) -#define SET_TX_DESC_HTC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 25, 1, __Value) -#define SET_TX_DESC_LAST_SEG_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 26, 1, __Value) -#define SET_TX_DESC_FIRST_SEG_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 27, 1, __Value) -#define SET_TX_DESC_LINIP_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 28, 1, __Value) -#define SET_TX_DESC_NO_ACM_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 29, 1, __Value) -#define SET_TX_DESC_GF_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 30, 1, __Value) -#define SET_TX_DESC_OWN_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc, 31, 1, __Value) - -/* Dword 1 */ -#define SET_TX_DESC_MACID_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 0, 7, __Value) -#define SET_TX_DESC_QUEUE_SEL_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 8, 5, __Value) -#define SET_TX_DESC_RDG_NAV_EXT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 13, 1, __Value) -#define SET_TX_DESC_LSIG_TXOP_EN_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 14, 1, __Value) -#define SET_TX_DESC_PIFS_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 15, 1, __Value) -#define SET_TX_DESC_RATE_ID_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 16, 5, __Value) -#define SET_TX_DESC_EN_DESC_ID_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 21, 1, __Value) -#define SET_TX_DESC_SEC_TYPE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 22, 2, __Value) -#define SET_TX_DESC_PKT_OFFSET_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+4, 24, 5, __Value) - - -/* Dword 2 */ -#define SET_TX_DESC_PAID_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 0, 9, __Value) -#define SET_TX_DESC_CCA_RTS_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 10, 2, __Value) -#define SET_TX_DESC_AGG_ENABLE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 12, 1, __Value) -#define SET_TX_DESC_RDG_ENABLE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 13, 1, __Value) -#define SET_TX_DESC_AGG_BREAK_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 16, 1, __Value) -#define SET_TX_DESC_MORE_FRAG_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 17, 1, __Value) -#define SET_TX_DESC_RAW_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 18, 1, __Value) -#define SET_TX_DESC_SPE_RPT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 19, 1, __Value) -#define SET_TX_DESC_AMPDU_DENSITY_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 20, 3, __Value) -#define SET_TX_DESC_BT_INT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 23, 1, __Value) -#define SET_TX_DESC_GID_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+8, 24, 6, __Value) - - -/* Dword 3 */ -#define SET_TX_DESC_WHEADER_LEN_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 0, 4, __Value) -#define SET_TX_DESC_CHK_EN_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 4, 1, __Value) -#define SET_TX_DESC_EARLY_MODE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 5, 1, __Value) -#define SET_TX_DESC_HWSEQ_SEL_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 6, 2, __Value) -#define SET_TX_DESC_USE_RATE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 8, 1, __Value) -#define SET_TX_DESC_DISABLE_RTS_FB_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 9, 1, __Value) -#define SET_TX_DESC_DISABLE_FB_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 10, 1, __Value) -#define SET_TX_DESC_CTS2SELF_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 11, 1, __Value) -#define SET_TX_DESC_RTS_ENABLE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 12, 1, __Value) -#define SET_TX_DESC_HW_RTS_ENABLE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 13, 1, __Value) -#define SET_TX_DESC_NAV_USE_HDR_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 15, 1, __Value) -#define SET_TX_DESC_USE_MAX_LEN_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 16, 1, __Value) -#define SET_TX_DESC_MAX_AGG_NUM_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 17, 5, __Value) -#define SET_TX_DESC_NDPA_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 22, 2, __Value) -#define SET_TX_DESC_AMPDU_MAX_TIME_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+12, 24, 8, __Value) - -/* Dword 4 */ -#define SET_TX_DESC_TX_RATE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+16, 0, 7, __Value) -#define SET_TX_DESC_DATA_RATE_FB_LIMIT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+16, 8, 5, __Value) -#define SET_TX_DESC_RTS_RATE_FB_LIMIT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+16, 13, 4, __Value) -#define SET_TX_DESC_RETRY_LIMIT_ENABLE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+16, 17, 1, __Value) -#define SET_TX_DESC_DATA_RETRY_LIMIT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+16, 18, 6, __Value) -#define SET_TX_DESC_RTS_RATE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+16, 24, 5, __Value) - - -/* Dword 5 */ -#define SET_TX_DESC_DATA_SC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 0, 4, __Value) -#define SET_TX_DESC_DATA_SHORT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 4, 1, __Value) -#define SET_TX_DESC_DATA_BW_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 5, 2, __Value) -#define SET_TX_DESC_DATA_LDPC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 7, 1, __Value) -#define SET_TX_DESC_DATA_STBC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 8, 2, __Value) -#define SET_TX_DESC_CTROL_STBC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 10, 2, __Value) -#define SET_TX_DESC_RTS_SHORT_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 12, 1, __Value) -#define SET_TX_DESC_RTS_SC_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+20, 13, 4, __Value) - - -/* Dword 6 */ -#define SET_TX_DESC_SW_DEFINE_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+24, 0, 12, __Value) -#define SET_TX_DESC_ANTSEL_A_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+24, 16, 3, __Value) -#define SET_TX_DESC_ANTSEL_B_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+24, 19, 3, __Value) -#define SET_TX_DESC_ANTSEL_C_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+24, 22, 3, __Value) -#define SET_TX_DESC_ANTSEL_D_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+24, 25, 3, __Value) - -/* Dword 7 */ -#define SET_TX_DESC_TX_DESC_CHECKSUM_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+28, 0, 16, __Value) -#define SET_TX_DESC_USB_TXAGG_NUM_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+28, 24, 8, __Value) -#define SET_TX_DESC_SDIO_TXSEQ_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+28, 16, 8, __Value) - -/* Dword 8 */ -#define SET_TX_DESC_HWSEQ_EN_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+32, 15, 1, __Value) - -/* Dword 9 */ -#define SET_TX_DESC_SEQ_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+36, 12, 12, __Value) - -/* Dword 10 */ -#define SET_TX_DESC_TX_BUFFER_ADDRESS_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+40, 0, 32, __Value) -#define GET_TX_DESC_TX_BUFFER_ADDRESS_8723B(__pTxDesc) LE_BITS_TO_4BYTE(__pTxDesc+40, 0, 32) - -/* Dword 11 */ -#define SET_TX_DESC_NEXT_DESC_ADDRESS_8723B(__pTxDesc, __Value) SET_BITS_TO_LE_4BYTE(__pTxDesc+48, 0, 32, __Value) - - -#define SET_EARLYMODE_PKTNUM_8723B(__pAddr, __Value) SET_BITS_TO_LE_4BYTE(__pAddr, 0, 4, __Value) -#define SET_EARLYMODE_LEN0_8723B(__pAddr, __Value) SET_BITS_TO_LE_4BYTE(__pAddr, 4, 15, __Value) -#define SET_EARLYMODE_LEN1_1_8723B(__pAddr, __Value) SET_BITS_TO_LE_4BYTE(__pAddr, 19, 13, __Value) -#define SET_EARLYMODE_LEN1_2_8723B(__pAddr, __Value) SET_BITS_TO_LE_4BYTE(__pAddr+4, 0, 2, __Value) -#define SET_EARLYMODE_LEN2_8723B(__pAddr, __Value) SET_BITS_TO_LE_4BYTE(__pAddr+4, 2, 15, __Value) -#define SET_EARLYMODE_LEN3_8723B(__pAddr, __Value) SET_BITS_TO_LE_4BYTE(__pAddr+4, 17, 15, __Value) - -#endif -/* */ -/* */ -/* Rate */ -/* */ -/* */ -/* CCK Rates, TxHT = 0 */ -#define DESC8723B_RATE1M 0x00 -#define DESC8723B_RATE2M 0x01 -#define DESC8723B_RATE5_5M 0x02 -#define DESC8723B_RATE11M 0x03 - -/* OFDM Rates, TxHT = 0 */ -#define DESC8723B_RATE6M 0x04 -#define DESC8723B_RATE9M 0x05 -#define DESC8723B_RATE12M 0x06 -#define DESC8723B_RATE18M 0x07 -#define DESC8723B_RATE24M 0x08 -#define DESC8723B_RATE36M 0x09 -#define DESC8723B_RATE48M 0x0a -#define DESC8723B_RATE54M 0x0b - -/* MCS Rates, TxHT = 1 */ -#define DESC8723B_RATEMCS0 0x0c -#define DESC8723B_RATEMCS1 0x0d -#define DESC8723B_RATEMCS2 0x0e -#define DESC8723B_RATEMCS3 0x0f -#define DESC8723B_RATEMCS4 0x10 -#define DESC8723B_RATEMCS5 0x11 -#define DESC8723B_RATEMCS6 0x12 -#define DESC8723B_RATEMCS7 0x13 - -#define RX_HAL_IS_CCK_RATE_8723B(pDesc)\ - (GET_RX_STATUS_DESC_RX_RATE_8723B(pDesc) == DESC8723B_RATE1M ||\ - GET_RX_STATUS_DESC_RX_RATE_8723B(pDesc) == DESC8723B_RATE2M ||\ - GET_RX_STATUS_DESC_RX_RATE_8723B(pDesc) == DESC8723B_RATE5_5M ||\ - GET_RX_STATUS_DESC_RX_RATE_8723B(pDesc) == DESC8723B_RATE11M) - - -void rtl8723b_update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem); -void rtl8723b_fill_fake_txdesc(struct adapter *padapter, u8 *pDesc, u32 BufferLen, u8 IsPsPoll, u8 IsBTQosNull, u8 bDataFrame); - -u32 rtl8723bs_hal_init(struct adapter *padapter); -u32 rtl8723bs_hal_deinit(struct adapter *padapter); -s32 rtl8723bs_init_xmit_priv(struct adapter *padapter); -void rtl8723bs_free_xmit_priv(struct adapter *padapter); -s32 rtl8723bs_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe); -s32 rtl8723bs_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe); -s32 rtl8723bs_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe); -s32 rtl8723bs_xmit_buf_handler(struct adapter *padapter); -int rtl8723bs_xmit_thread(void *context); - -u8 BWMapping_8723B(struct adapter *Adapter, struct pkt_attrib *pattrib); -u8 SCMapping_8723B(struct adapter *Adapter, struct pkt_attrib *pattrib); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtw_ap.h b/drivers/staging/rtl8723bs/include/rtw_ap.h deleted file mode 100644 index 866aa8386931..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_ap.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_AP_H_ -#define __RTW_AP_H_ - -void init_mlme_ap_info(struct adapter *padapter); -void free_mlme_ap_info(struct adapter *padapter); -/* void update_BCNTIM(struct adapter *padapter); */ -void update_beacon(struct adapter *padapter, u8 ie_id, u8 tx); -void add_ratid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level); -void expire_timeout_chk(struct adapter *padapter); -void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta); -void start_bss_network(struct adapter *padapter); -int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len); -void rtw_ap_restore_network(struct adapter *padapter); -void rtw_set_macaddr_acl(struct adapter *padapter, int mode); -int rtw_acl_add_sta(struct adapter *padapter, u8 *addr); -void rtw_acl_remove_sta(struct adapter *padapter, u8 *addr); - -u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta); -int rtw_ap_set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid); -int rtw_ap_set_wep_key(struct adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx); - -void associated_clients_update(struct adapter *padapter, u8 updated); -void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta); -u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta); -void sta_info_update(struct adapter *padapter, struct sta_info *psta); -void ap_sta_info_defer_update(struct adapter *padapter, struct sta_info *psta); -u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta, bool active, u16 reason); -void rtw_sta_flush(struct adapter *padapter); -void start_ap_mode(struct adapter *padapter); -void stop_ap_mode(struct adapter *padapter); - -#endif -void update_bmc_sta(struct adapter *padapter); diff --git a/drivers/staging/rtl8723bs/include/rtw_btcoex.h b/drivers/staging/rtl8723bs/include/rtw_btcoex.h deleted file mode 100644 index 765103498789..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_btcoex.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2013 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_BTCOEX_H__ -#define __RTW_BTCOEX_H__ - -#include - -#define PACKET_NORMAL 0 -#define PACKET_DHCP 1 -#define PACKET_ARP 2 -#define PACKET_EAPOL 3 - -void rtw_btcoex_media_status_notify(struct adapter *padapter, u8 media_status); -void rtw_btcoex_halt_notify(struct adapter *padapter); - -/* ================================================== */ -/* Below Functions are called by BT-Coex */ -/* ================================================== */ -void rtw_btcoex_reject_ap_aggregated_packet(struct adapter *padapter, u8 enable); -void rtw_btcoex_lps_enter(struct adapter *padapter); -void rtw_btcoex_lps_leave(struct adapter *padapter); - -#endif /* __RTW_BTCOEX_H__ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_byteorder.h b/drivers/staging/rtl8723bs/include/rtw_byteorder.h deleted file mode 100644 index c3a65f971793..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_byteorder.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _RTL871X_BYTEORDER_H_ -#define _RTL871X_BYTEORDER_H_ - -#if defined(__LITTLE_ENDIAN) -#include -#else -# include -#endif - -#endif /* _RTL871X_BYTEORDER_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_cmd.h b/drivers/staging/rtl8723bs/include/rtw_cmd.h deleted file mode 100644 index 2e791da7e815..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_cmd.h +++ /dev/null @@ -1,705 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_CMD_H_ -#define __RTW_CMD_H_ - -#include - -#define C2H_MEM_SZ (16*1024) - - #define FREE_CMDOBJ_SZ 128 - - #define MAX_CMDSZ 1024 - #define MAX_RSPSZ 512 - #define MAX_EVTSZ 1024 - - #define CMDBUFF_ALIGN_SZ 512 - - struct cmd_obj { - struct adapter *padapter; - u16 cmdcode; - u8 res; - u8 *parmbuf; - u32 cmdsz; - u8 *rsp; - u32 rspsz; - struct submit_ctx *sctx; - struct list_head list; - }; - - /* cmd flags */ - enum { - RTW_CMDF_DIRECTLY = BIT(0), - RTW_CMDF_WAIT_ACK = BIT(1), - }; - - struct cmd_priv { - struct completion cmd_queue_comp; - struct completion terminate_cmdthread_comp; - struct __queue cmd_queue; - u8 cmd_seq; - u8 *cmd_buf; /* shall be non-paged, and 4 bytes aligned */ - u8 *cmd_allocated_buf; - u8 *rsp_buf; /* shall be non-paged, and 4 bytes aligned */ - u32 cmd_issued_cnt; - u32 cmd_done_cnt; - u32 rsp_cnt; - atomic_t cmdthd_running; - /* u8 cmdthd_running; */ - u8 stop_req; - struct adapter *padapter; - struct mutex sctx_mutex; - }; - - struct evt_priv { - struct work_struct c2h_wk; - bool c2h_wk_alive; - struct rtw_cbuf *c2h_queue; - #define C2H_QUEUE_MAX_LEN 10 - - atomic_t event_seq; - u8 *evt_buf; /* shall be non-paged, and 4 bytes aligned */ - u8 *evt_allocated_buf; - u32 evt_done_cnt; - u8 *c2h_mem; - u8 *allocated_c2h_mem; - }; - -#define init_h2fwcmd_w_parm_no_rsp(pcmd, pparm, code) \ -do {\ - INIT_LIST_HEAD(&pcmd->list);\ - pcmd->cmdcode = code;\ - pcmd->parmbuf = (u8 *)(pparm);\ - pcmd->cmdsz = sizeof(*pparm);\ - pcmd->rsp = NULL;\ - pcmd->rspsz = 0;\ -} while (0) - -#define init_h2fwcmd_w_parm_no_parm_rsp(pcmd, code) \ -do {\ - INIT_LIST_HEAD(&pcmd->list);\ - pcmd->cmdcode = code;\ - pcmd->parmbuf = NULL;\ - pcmd->cmdsz = 0;\ - pcmd->rsp = NULL;\ - pcmd->rspsz = 0;\ -} while (0) - -struct c2h_evt_hdr { - u8 id:4; - u8 plen:4; - u8 seq; - u8 payload[]; -}; - -struct c2h_evt_hdr_88xx { - u8 id; - u8 seq; - u8 payload[12]; - u8 plen; - u8 trigger; -}; - -#define c2h_evt_valid(c2h_evt) ((c2h_evt)->id || (c2h_evt)->plen) - -int rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj); -extern struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv); -extern void rtw_free_cmd_obj(struct cmd_obj *pcmd); - -void rtw_stop_cmd_thread(struct adapter *adapter); -int rtw_cmd_thread(void *context); - -extern void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv); - -extern void rtw_free_evt_priv(struct evt_priv *pevtpriv); -extern void rtw_evt_notify_isr(struct evt_priv *pevtpriv); - -enum { - NONE_WK_CID, - DYNAMIC_CHK_WK_CID, - DM_CTRL_WK_CID, - PBC_POLLING_WK_CID, - POWER_SAVING_CTRL_WK_CID,/* IPS, AUTOSuspend */ - LPS_CTRL_WK_CID, - ANT_SELECT_WK_CID, - P2P_PS_WK_CID, - P2P_PROTO_WK_CID, - CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */ - INTEl_WIDI_WK_CID, - C2H_WK_CID, - RTP_TIMER_CFG_WK_CID, - RESET_SECURITYPRIV, - FREE_ASSOC_RESOURCES, - DM_IN_LPS_WK_CID, - DM_RA_MSK_WK_CID, /* add for STA update RAMask when bandwidth change. */ - BEAMFORMING_WK_CID, - LPS_CHANGE_DTIM_CID, - BTINFO_WK_CID, - MAX_WK_CID -}; - -enum { - LPS_CTRL_SCAN = 0, - LPS_CTRL_JOINBSS = 1, - LPS_CTRL_CONNECT = 2, - LPS_CTRL_DISCONNECT = 3, - LPS_CTRL_SPECIAL_PACKET = 4, - LPS_CTRL_LEAVE = 5, - LPS_CTRL_TRAFFIC_BUSY = 6, -}; - -enum { - SWSI, - HWSI, - HWPI, -}; - -/* -Caller Mode: Infra, Ad-HoC - -Notes: To join a known BSS. - -Command-Event Mode - -*/ - -/* -Caller Mode: Infra, Ad-Hoc - -Notes: To join the specified bss - -Command Event Mode - -*/ -struct joinbss_parm { - struct wlan_bssid_ex network; -}; - -/* -Caller Mode: Infra, Ad-HoC(C) - -Notes: To disconnect the current associated BSS - -Command Mode - -*/ -struct disconnect_parm { - u32 deauth_timeout_ms; -}; - -/* -Caller Mode: AP, Ad-HoC(M) - -Notes: To create a BSS - -Command Mode -*/ -struct createbss_parm { - struct wlan_bssid_ex network; -}; - -/* -Caller Mode: AP, Ad-HoC, Infra - -Notes: To set the NIC mode of RTL8711 - -Command Mode - -The definition of mode: - -#define IW_MODE_AUTO 0 Let the driver decides which AP to join -#define IW_MODE_ADHOC 1 Single cell network (Ad-Hoc Clients) -#define IW_MODE_INFRA 2 Multi cell network, roaming, .. -#define IW_MODE_MASTER 3 Synchronisation master or Access Point -#define IW_MODE_REPEAT 4 Wireless Repeater (forwarder) -#define IW_MODE_SECOND 5 Secondary master/repeater (backup) -#define IW_MODE_MONITOR 6 Passive monitor (listen only) - -*/ -struct setopmode_parm { - u8 mode; - u8 rsvd[3]; -}; - -/* -Caller Mode: AP, Ad-HoC, Infra - -Notes: To ask RTL8711 performing site-survey - -Command-Event Mode - -*/ - -#define RTW_SSID_SCAN_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */ -#define RTW_CHANNEL_SCAN_AMOUNT (14+37) -struct sitesurvey_parm { - signed int scan_mode; /* active: 1, passive: 0 */ - u8 ssid_num; - u8 ch_num; - struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT]; - struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT]; -}; - -/* -Caller Mode: Any - -Notes: To set the auth type of RTL8711. open/shared/802.1x - -Command Mode - -*/ -struct setauth_parm { - u8 mode; /* 0: legacy open, 1: legacy shared 2: 802.1x */ - u8 _1x; /* 0: PSK, 1: TLS */ - u8 rsvd[2]; -}; - -/* -Caller Mode: Infra - -a. algorithm: wep40, wep104, tkip & aes -b. keytype: grp key/unicast key -c. key contents - -when shared key ==> keyid is the camid -when 802.1x ==> keyid [0:1] ==> grp key -when 802.1x ==> keyid > 2 ==> unicast key - -*/ -struct setkey_parm { - u8 algorithm; /* encryption algorithm, could be none, wep40, TKIP, CCMP, wep104 */ - u8 keyid; - u8 grpkey; /* 1: this is the grpkey for 802.1x. 0: this is the unicast key for 802.1x */ - u8 set_tx; /* 1: main tx key for wep. 0: other key. */ - u8 key[16]; /* this could be 40 or 104 */ -}; - -/* -When in AP or Ad-Hoc mode, this is used to -allocate an sw/hw entry for a newly associated sta. - -Command - -when shared key ==> algorithm/keyid - -*/ -struct set_stakey_parm { - u8 addr[ETH_ALEN]; - u8 algorithm; - u8 keyid; - u8 key[16]; -}; - -struct set_stakey_rsp { - u8 addr[ETH_ALEN]; - u8 keyid; - u8 rsvd; -}; - -/* -Caller Ad-Hoc/AP - -Command -Rsp(AID == CAMID) mode - -This is to force fw to add an sta_data entry per driver's request. - -FW will write an cam entry associated with it. - -*/ -struct set_assocsta_parm { - u8 addr[ETH_ALEN]; -}; - -struct set_assocsta_rsp { - u8 cam_id; - u8 rsvd[3]; -}; - -/* - Caller Ad-Hoc/AP - - Command mode - - This is to force fw to del an sta_data entry per driver's request - - FW will invalidate the cam entry associated with it. - -*/ -struct del_assocsta_parm { - u8 addr[ETH_ALEN]; -}; - -/* -Caller Mode: AP/Ad-HoC(M) - -Notes: To notify fw that given staid has changed its power state - -Command Mode - -*/ -struct setstapwrstate_parm { - u8 staid; - u8 status; - u8 hwaddr[6]; -}; - -/* -Caller Mode: Any - -Notes: To setup the basic rate of RTL8711 - -Command Mode - -*/ -struct setbasicrate_parm { - u8 basicrates[NumRates]; -}; - -/* -Caller Mode: Any - -Notes: To read the current basic rate - -Command-Rsp Mode - -*/ -struct getbasicrate_parm { - u32 rsvd; -}; - -/* -Caller Mode: Any - -Notes: To setup the data rate of RTL8711 - -Command Mode - -*/ -struct setdatarate_parm { - u8 mac_id; - u8 datarates[NumRates]; -}; - -/* -Caller Mode: Any - -Notes: To read the current data rate - -Command-Rsp Mode - -*/ -struct getdatarate_parm { - u32 rsvd; - -}; - -/* -Caller Mode: Any -AP: AP can use the info for the contents of beacon frame -Infra: STA can use the info when sitesurveying -Ad-HoC(M): Like AP -Ad-HoC(C): Like STA - - -Notes: To set the phy capability of the NIC - -Command Mode - -*/ - -struct setphyinfo_parm { - struct regulatory_class class_sets[NUM_REGULATORYS]; - u8 status; -}; - -struct getphyinfo_parm { - u32 rsvd; -}; - -/* -Caller Mode: Any - -Notes: To set the channel/modem/band -This command will be used when channel/modem/band is changed. - -Command Mode - -*/ -struct setphy_parm { - u8 rfchannel; - u8 modem; -}; - -/* -Caller Mode: Any - -Notes: To get the current setting of channel/modem/band - -Command-Rsp Mode - -*/ -struct getphy_parm { - u32 rsvd; - -}; - -struct Tx_Beacon_param { - struct wlan_bssid_ex network; -}; - -/* - Notes: This command is used for H2C/C2H loopback testing - - mac[0] == 0 - ==> CMD mode, return H2C_SUCCESS. - The following condition must be true under CMD mode - mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0; - s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7; - s2 == (b1 << 8 | b0); - - mac[0] == 1 - ==> CMD_RSP mode, return H2C_SUCCESS_RSP - - The rsp layout shall be: - rsp: parm: - mac[0] = mac[5]; - mac[1] = mac[4]; - mac[2] = mac[3]; - mac[3] = mac[2]; - mac[4] = mac[1]; - mac[5] = mac[0]; - s0 = s1; - s1 = swap16(s0); - w0 = swap32(w1); - b0 = b1 - s2 = s0 + s1 - b1 = b0 - w1 = w0 - - mac[0] == 2 - ==> CMD_EVENT mode, return H2C_SUCCESS - The event layout shall be: - event: parm: - mac[0] = mac[5]; - mac[1] = mac[4]; - mac[2] = event's sequence number, starting from 1 to parm's marc[3] - mac[3] = mac[2]; - mac[4] = mac[1]; - mac[5] = mac[0]; - s0 = swap16(s0) - event.mac[2]; - s1 = s1 + event.mac[2]; - w0 = swap32(w0); - b0 = b1 - s2 = s0 + event.mac[2] - b1 = b0 - w1 = swap32(w1) - event.mac[2]; - - parm->mac[3] is the total event counts that host requested. - - - event will be the same with the cmd's param. - -*/ - -/* CMD param Formart for driver extra cmd handler */ -struct drvextra_cmd_parm { - int ec_id; /* extra cmd id */ - int type; /* Can use this field as the type id or command size */ - int size; /* buffer size */ - unsigned char *pbuf; -}; - -/*------------------- Below are used for RF/BB tuning ---------------------*/ - -struct addBaReq_parm { - unsigned int tid; - u8 addr[ETH_ALEN]; -}; - -/*H2C Handler index: 46 */ -struct set_ch_parm { - u8 ch; - u8 bw; - u8 ch_offset; -}; - -/*H2C Handler index: 59 */ -struct SetChannelPlan_param { - u8 channel_plan; -}; - -/*H2C Handler index: 61 */ -struct SetChannelSwitch_param { - u8 new_ch_no; -}; - -/*H2C Handler index: 62 */ -struct TDLSoption_param { - u8 addr[ETH_ALEN]; - u8 option; -}; - -/*H2C Handler index: 64 */ -struct RunInThread_param { - void (*func)(void *); - void *context; -}; - - -/* - -Result: -0x00: success -0x01: success, and check Response. -0x02: cmd ignored due to duplicated sequence number -0x03: cmd dropped due to invalid cmd code -0x04: reserved. - -*/ - -#define H2C_RSP_OFFSET 512 - -#define H2C_SUCCESS 0x00 -#define H2C_SUCCESS_RSP 0x01 -#define H2C_DUPLICATED 0x02 -#define H2C_DROPPED 0x03 -#define H2C_PARAMETERS_ERROR 0x04 -#define H2C_REJECTED 0x05 -#define H2C_CMD_OVERFLOW 0x06 -#define H2C_RESERVED 0x07 - -u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num, struct rtw_ieee80211_channel *ch, int ch_num); -extern u8 rtw_createbss_cmd(struct adapter *padapter); -int rtw_startbss_cmd(struct adapter *padapter, int flags); - -struct sta_info; -extern u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue); -extern u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue); - -extern u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork); -u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue); -extern u8 rtw_setopmode_cmd(struct adapter *padapter, enum nl80211_iftype networktype, bool enqueue); -extern u8 rtw_setrfintfs_cmd(struct adapter *padapter, u8 mode); - -extern u8 rtw_gettssi_cmd(struct adapter *padapter, u8 offset, u8 *pval); -extern u8 rtw_setfwdig_cmd(struct adapter *padapter, u8 type); -extern u8 rtw_setfwra_cmd(struct adapter *padapter, u8 type); - -extern u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr); -extern u8 rtw_reset_securitypriv_cmd(struct adapter *padapter); -extern u8 rtw_free_assoc_resources_cmd(struct adapter *padapter); -extern u8 rtw_dynamic_chk_wk_cmd(struct adapter *adapter); - -u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue); -u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter); - -u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta); - -extern u8 rtw_ps_cmd(struct adapter *padapter); - -u8 rtw_chk_hi_queue_cmd(struct adapter *padapter); - -extern u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length); -extern u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt); - -u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf); - -extern void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd); -extern void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd); -extern void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd); -extern void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd); -extern void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd); - -extern void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd); -extern void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd); -extern void rtw_getrttbl_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd); - - -struct _cmd_callback { - u32 cmd_code; - void (*callback)(struct adapter *padapter, struct cmd_obj *cmd); -}; - -enum { - READ_MACREG_CMD, /*0*/ - WRITE_MACREG_CMD, - READ_BBREG_CMD, - WRITE_BBREG_CMD, - READ_RFREG_CMD, - WRITE_RFREG_CMD, /*5*/ - READ_EEPROM_CMD, - WRITE_EEPROM_CMD, - READ_EFUSE_CMD, - WRITE_EFUSE_CMD, - - READ_CAM_CMD, /*10*/ - WRITE_CAM_CMD, - SET_BCNITV_CMD, - SET_MBIDCFG_CMD, - JOIN_BSS_CMD, /*14*/ - DISCONNECT_CMD, /*15*/ - CREATE_BSS_CMD, - SET_OP_MODE_CMD, - SITE_SURVEY_CMD, /*18*/ - SET_AUTH_CMD, - - SET_KEY_CMD, /*20*/ - SET_STA_KEY_CMD, - SET_ASSOC_STA_CMD, - DEL_ASSOC_STA_CMD, - SET_STA_PWR_STATE_CMD, - SET_BASIC_RATE_CMD, /*25*/ - GET_BASIC_RATE_CMD, - SET_DATA_RATE_CMD, - GET_DATA_RATE_CMD, - SET_PHY_INFO_CMD, - - GET_PHY_INFO_CMD, /*30*/ - SET_PHY_CMD, - GET_PHY_CMD, - READ_RSSI_CMD, - READ_GAIN_CMD, - SET_ATIM_CMD, /*35*/ - SET_PWR_MODE_CMD, - JOIN_BSS_RPT_CMD, - SET_RA_TABLE_CMD, - GET_RA_TABLE_CMD, - - GET_CCX_REPORT_CMD, /*40*/ - GET_DTM_REPORT_CMD, - GET_TX_RATE_STATISTICS_CMD, - SET_USB_SUSPEND_CMD, - SET_H2C_LBK_CMD, - ADD_BA_REQ_CMD, /*45*/ - SET_CHANNEL_CMD, /*46*/ - SET_TX_POWER_CMD, - SWITCH_ANTENNA_CMD, - SET_CRYSTAL_CAP_CMD, - SET_SINGLE_CARRIER_TX_CMD, /*50*/ - - SET_SINGLE_TONE_TX_CMD, /*51*/ - SET_CARRIER_SUPPRESSION_TX_CMD, - SET_CONTINUOUS_TX_CMD, - SWITCH_BANDWIDTH_CMD, /*54*/ - TX_BEACON_CMD, /*55*/ - - SET_MLME_EVT_CMD, /*56*/ - SET_DRV_EXTRA_CMD, /*57*/ - SET_H2C_MSG_CMD, /*58*/ - - SET_CHANNEL_PLAN_CMD, /*59*/ - - SET_CHANNEL_SWITCH_CMD, /*60*/ - TDLS_CMD, /*61*/ - CHK_BMC_SLEEPQ_CMD, /*62*/ - - RUN_IN_THREAD_CMD, /*63*/ - - MAX_H2CCMD -}; - -#endif /* __RTW_CMD_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_eeprom.h b/drivers/staging/rtl8723bs/include/rtw_eeprom.h deleted file mode 100644 index 9b84105af816..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_eeprom.h +++ /dev/null @@ -1,118 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_EEPROM_H__ -#define __RTW_EEPROM_H__ - - -#define RTL8712_EEPROM_ID 0x8712 -/* define EEPROM_MAX_SIZE 256 */ - -#define HWSET_MAX_SIZE_128 128 -#define HWSET_MAX_SIZE_256 256 -#define HWSET_MAX_SIZE_512 512 - -#define EEPROM_MAX_SIZE HWSET_MAX_SIZE_512 - -#define CLOCK_RATE 50 /* 100us */ - -/* EEPROM opcodes */ -#define EEPROM_READ_OPCODE 06 -#define EEPROM_WRITE_OPCODE 05 -#define EEPROM_ERASE_OPCODE 07 -#define EEPROM_EWEN_OPCODE 19 /* Erase/write enable */ -#define EEPROM_EWDS_OPCODE 16 /* Erase/write disable */ - -/* Country codes */ -#define USA 0x555320 -#define EUROPE 0x1 /* temp, should be provided later */ -#define JAPAN 0x2 /* temp, should be provided later */ - -#define eeprom_cis0_sz 17 -#define eeprom_cis1_sz 50 - -/* */ -/* Customer ID, note that: */ -/* This variable is initiailzed through EEPROM or registry, */ -/* however, its definition may be different with that in EEPROM for */ -/* EEPROM size consideration. So, we have to perform proper translation between them. */ -/* Besides, CustomerID of registry has precedence of that of EEPROM. */ -/* defined below. 060703, by rcnjko. */ -/* */ -enum { - RT_CID_DEFAULT = 0, - RT_CID_8187_ALPHA0 = 1, - RT_CID_8187_SERCOMM_PS = 2, - RT_CID_8187_HW_LED = 3, - RT_CID_8187_NETGEAR = 4, - RT_CID_WHQL = 5, - RT_CID_819x_CAMEO = 6, - RT_CID_819x_RUNTOP = 7, - RT_CID_819x_Senao = 8, - RT_CID_TOSHIBA = 9, /* Merge by Jacken, 2008/01/31. */ - RT_CID_819x_Netcore = 10, - RT_CID_Nettronix = 11, - RT_CID_DLINK = 12, - RT_CID_PRONET = 13, - RT_CID_COREGA = 14, - RT_CID_CHINA_MOBILE = 15, - RT_CID_819x_ALPHA = 16, - RT_CID_819x_Sitecom = 17, - RT_CID_CCX = 18, /* It's set under CCX logo test and isn't demanded for CCX functions, but for test behavior like retry limit and tx report. By Bruce, 2009-02-17. */ - RT_CID_819x_Lenovo = 19, - RT_CID_819x_QMI = 20, - RT_CID_819x_Edimax_Belkin = 21, - RT_CID_819x_Sercomm_Belkin = 22, - RT_CID_819x_CAMEO1 = 23, - RT_CID_819x_MSI = 24, - RT_CID_819x_Acer = 25, - RT_CID_819x_AzWave_ASUS = 26, - RT_CID_819x_AzWave = 27, /* For AzWave in PCIe, The ID is AzWave use and not only Asus */ - RT_CID_819x_HP = 28, - RT_CID_819x_WNC_COREGA = 29, - RT_CID_819x_Arcadyan_Belkin = 30, - RT_CID_819x_SAMSUNG = 31, - RT_CID_819x_CLEVO = 32, - RT_CID_819x_DELL = 33, - RT_CID_819x_PRONETS = 34, - RT_CID_819x_Edimax_ASUS = 35, - RT_CID_NETGEAR = 36, - RT_CID_PLANEX = 37, - RT_CID_CC_C = 38, - RT_CID_819x_Xavi = 39, - RT_CID_LENOVO_CHINA = 40, - RT_CID_INTEL_CHINA = 41, - RT_CID_TPLINK_HPWR = 42, - RT_CID_819x_Sercomm_Netgear = 43, - RT_CID_819x_ALPHA_Dlink = 44,/* add by ylb 20121012 for customer led for alpha */ - RT_CID_WNC_NEC = 45,/* add by page for NEC */ - RT_CID_DNI_BUFFALO = 46,/* add by page for NEC */ -}; - -struct eeprom_priv { - u8 bautoload_fail_flag; - u8 bloadfile_fail_flag; - u8 bloadmac_fail_flag; - u8 EepromOrEfuse; - - u8 mac_addr[6]; /* PermanentAddress */ - - u16 channel_plan; - u16 CustomerID; - - u8 efuse_eeprom_data[EEPROM_MAX_SIZE]; /* 92C:256bytes, 88E:512bytes, we use union set (512bytes) */ - u8 adjuseVoltageVal; - - u8 EEPROMRFGainOffset; - u8 EEPROMRFGainVal; - - u8 sdio_setting; - u32 ocr; - u8 cis0[eeprom_cis0_sz]; - u8 cis1[eeprom_cis1_sz]; -}; - -#endif /* __RTL871X_EEPROM_H__ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_efuse.h b/drivers/staging/rtl8723bs/include/rtw_efuse.h deleted file mode 100644 index 808ba94a5998..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_efuse.h +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. */ - -#ifndef __RTW_EFUSE_H__ -#define __RTW_EFUSE_H__ - -#define PGPKT_DATA_SIZE 8 - -#define EFUSE_WIFI 0 -#define EFUSE_BT 1 - -enum { - TYPE_EFUSE_MAX_SECTION = 0, - TYPE_EFUSE_REAL_CONTENT_LEN = 1, - TYPE_AVAILABLE_EFUSE_BYTES_BANK = 2, - TYPE_AVAILABLE_EFUSE_BYTES_TOTAL = 3, - TYPE_EFUSE_MAP_LEN = 4, - TYPE_EFUSE_PROTECT_BYTES_BANK = 5, - TYPE_EFUSE_CONTENT_LEN_BANK = 6, -}; - -#define EFUSE_MAX_MAP_LEN 512 - -#define EFUSE_MAX_HW_SIZE 512 -#define EFUSE_MAX_SECTION_BASE 16 - -#define EXT_HEADER(header) ((header & 0x1F) == 0x0F) -#define ALL_WORDS_DISABLED(wde) ((wde & 0x0F) == 0x0F) -#define GET_HDR_OFFSET_2_0(header) ((header & 0xE0) >> 5) - -#define EFUSE_REPEAT_THRESHOLD_ 3 - -/* */ -/* The following is for BT Efuse definition */ -/* */ -#define EFUSE_BT_MAX_MAP_LEN 1024 -#define EFUSE_MAX_BANK 4 -#define EFUSE_MAX_BT_BANK (EFUSE_MAX_BANK-1) -/* */ -/*--------------------------Define Parameters-------------------------------*/ -#define EFUSE_MAX_WORD_UNIT 4 - -/*------------------------------Define structure----------------------------*/ -struct pgpkt_struct { - u8 offset; - u8 word_en; - u8 data[8]; - u8 word_cnts; -}; - -/*------------------------------Define structure----------------------------*/ -struct efuse_hal { - u8 fakeEfuseBank; - u32 fakeEfuseUsedBytes; - u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE]; - u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN]; - u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN]; - - u16 BTEfuseUsedBytes; - u8 BTEfuseUsedPercentage; - u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE]; - u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]; - u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]; - - u16 fakeBTEfuseUsedBytes; - u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE]; - u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]; - u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]; -}; - -u8 rtw_efuse_calculate_word_counts(u8 word_en); -u8 rtw_efuse_one_byte_read(struct adapter *padapter, u16 addr, u8 *data); - -u8 rtw_efuse_read_1_byte(struct adapter *padapter, u16 Address); -void rtw_efuse_shadow_map_update(struct adapter *padapter, u8 efuseType); -void rtw_efuse_shadow_read(struct adapter *padapter, u8 Type, u16 Offset, u32 *Value); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtw_event.h b/drivers/staging/rtl8723bs/include/rtw_event.h deleted file mode 100644 index e5cb46c2a731..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_event.h +++ /dev/null @@ -1,92 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _RTW_EVENT_H_ -#define _RTW_EVENT_H_ - -/* -Used to report a bss has been scanned - -*/ -struct survey_event { - struct wlan_bssid_ex bss; -}; - -/* -Used to report that the requested site survey has been done. - -bss_cnt indicates the number of bss that has been reported. - - -*/ -struct surveydone_event { - unsigned int bss_cnt; - -}; - -/* -Used to report the link result of joining the given bss - - -join_res: --1: authentication fail --2: association fail -> 0: TID - -*/ -struct joinbss_event { - struct wlan_network network; -}; - -/* -Used to report a given STA has joinned the created BSS. -It is used in AP/Ad-HoC(M) mode. - - -*/ -struct stassoc_event { - unsigned char macaddr[6]; - unsigned char rsvd[2]; - int cam_id; - -}; - -struct stadel_event { - unsigned char macaddr[6]; - unsigned char rsvd[2]; /* for reason */ - int mac_id; -}; - -struct wmm_event { - unsigned char wmm; -}; - -struct fwevent { - u32 parmsize; - void (*event_callback)(struct adapter *dev, u8 *pbuf); -}; - - -#define C2HEVENT_SZ 32 - -struct event_node { - unsigned char *node; - unsigned char evt_code; - unsigned short evt_sz; - volatile int *caller_ff_tail; - int caller_ff_sz; -}; - -#define NETWORK_QUEUE_SZ 4 - -struct network_queue { - volatile int head; - volatile int tail; - struct wlan_bssid_ex networks[NETWORK_QUEUE_SZ]; -}; - - -#endif /* _WLANEVENT_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_ht.h b/drivers/staging/rtl8723bs/include/rtw_ht.h deleted file mode 100644 index da3efba7112a..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_ht.h +++ /dev/null @@ -1,83 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _RTW_HT_H_ -#define _RTW_HT_H_ - - -struct ht_priv { - u8 ht_option; - u8 ampdu_enable;/* for enable Tx A-MPDU */ - u8 tx_amsdu_enable;/* for enable Tx A-MSDU */ - u8 bss_coexist;/* for 20/40 Bss coexist */ - - /* u8 baddbareq_issued[16]; */ - u32 tx_amsdu_maxlen; /* 1: 8k, 0:4k ; default:8k, for tx */ - u32 rx_ampdu_maxlen; /* for rx reordering ctrl win_sz, updated when join_callback. */ - - u8 rx_ampdu_min_spacing; - - u8 ch_offset;/* PRIME_CHNL_OFFSET */ - u8 sgi_20m; - u8 sgi_40m; - - /* for processing Tx A-MPDU */ - u8 agg_enable_bitmap; - /* u8 ADDBA_retry_count; */ - u8 candidate_tid_bitmap; - - u8 ldpc_cap; - u8 stbc_cap; - u8 beamform_cap; - - struct ieee80211_ht_cap ht_cap; - -}; - -enum { - HT_AGG_SIZE_8K = 0, - HT_AGG_SIZE_16K = 1, - HT_AGG_SIZE_32K = 2, - HT_AGG_SIZE_64K = 3, -}; - -enum { - RT_HT_CAP_USE_TURBO_AGGR = 0x01, - RT_HT_CAP_USE_LONG_PREAMBLE = 0x02, - RT_HT_CAP_USE_AMPDU = 0x04, - RT_HT_CAP_USE_WOW = 0x8, - RT_HT_CAP_USE_SOFTAP = 0x10, - RT_HT_CAP_USE_92SE = 0x20, - RT_HT_CAP_USE_88C_92C = 0x40, - RT_HT_CAP_USE_AP_CLIENT_MODE = 0x80, /* AP team request to reserve this bit, by Emily */ -}; - -enum { - RT_HT_CAP_USE_VIDEO_CLIENT = 0x01, - RT_HT_CAP_USE_JAGUAR_BCUT = 0x02, - RT_HT_CAP_USE_JAGUAR_CCUT = 0x04, -}; - -#define LDPC_HT_ENABLE_RX BIT(0) -#define LDPC_HT_ENABLE_TX BIT(1) -#define LDPC_HT_CAP_TX BIT(3) - -#define STBC_HT_ENABLE_RX BIT(0) -#define STBC_HT_ENABLE_TX BIT(1) -#define STBC_HT_CAP_TX BIT(3) - -#define BEAMFORMING_HT_BEAMFORMER_ENABLE BIT(0) /* Declare our NIC supports beamformer */ -#define BEAMFORMING_HT_BEAMFORMEE_ENABLE BIT(1) /* Declare our NIC supports beamformee */ - -/* 20/40 BSS Coexist */ -#define SET_EXT_CAPABILITY_ELE_BSS_COEXIST(_pEleStart, _val) SET_BITS_TO_LE_1BYTE((_pEleStart), 0, 1, _val) - -#define GET_HT_CAPABILITY_ELE_LDPC_CAP(_pEleStart) LE_BITS_TO_1BYTE(_pEleStart, 0, 1) -#define GET_HT_CAPABILITY_ELE_TX_STBC(_pEleStart) LE_BITS_TO_1BYTE(_pEleStart, 7, 1) - -#define GET_HT_CAPABILITY_ELE_RX_STBC(_pEleStart) LE_BITS_TO_1BYTE((_pEleStart)+1, 0, 2) - -#endif /* _RTL871X_HT_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_io.h b/drivers/staging/rtl8723bs/include/rtw_io.h deleted file mode 100644 index 3c99a2bc19bd..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_io.h +++ /dev/null @@ -1,58 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef _RTW_IO_H_ -#define _RTW_IO_H_ - -struct intf_hdl; - -struct _io_ops { - u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr); - u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr); - u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr); - - int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val); - int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val); - int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val); - - u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); -}; - -struct intf_hdl { - struct adapter *padapter; - struct dvobj_priv *pintf_dev;/* pointer to &(padapter->dvobjpriv); */ - - struct _io_ops io_ops; -}; - -#define SD_IO_TRY_CNT (8) -#define MAX_CONTINUAL_IO_ERR SD_IO_TRY_CNT - -int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj); -void rtw_reset_continual_io_error(struct dvobj_priv *dvobj); - -struct io_priv { - - struct adapter *padapter; - - struct intf_hdl intf; - -}; - -extern u8 rtw_read8(struct adapter *adapter, u32 addr); -extern u16 rtw_read16(struct adapter *adapter, u32 addr); -extern u32 rtw_read32(struct adapter *adapter, u32 addr); - -extern int rtw_write8(struct adapter *adapter, u32 addr, u8 val); -extern int rtw_write16(struct adapter *adapter, u32 addr, u16 val); -extern int rtw_write32(struct adapter *adapter, u32 addr, u32 val); - -extern u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); - -int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops)); - -#endif /* _RTL8711_IO_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_ioctl_set.h b/drivers/staging/rtl8723bs/include/rtw_ioctl_set.h deleted file mode 100644 index 768e4868ecfd..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_ioctl_set.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_IOCTL_SET_H_ -#define __RTW_IOCTL_SET_H_ - -typedef u8 NDIS_802_11_PMKID_VALUE[16]; - -u8 rtw_set_802_11_authentication_mode(struct adapter *pdapter, enum ndis_802_11_authentication_mode authmode); -u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep); -u8 rtw_set_802_11_disassociate(struct adapter *padapter); -u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct ndis_802_11_ssid *pssid, int ssid_max_num); -u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter, enum nl80211_iftype networktype); -u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid); -u8 rtw_set_802_11_connect(struct adapter *padapter, u8 *bssid, struct ndis_802_11_ssid *ssid); - -u8 rtw_validate_bssid(u8 *bssid); -u8 rtw_validate_ssid(struct ndis_802_11_ssid *ssid); - -u8 rtw_do_join(struct adapter *padapter); - -u16 rtw_get_cur_max_rate(struct adapter *adapter); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme.h b/drivers/staging/rtl8723bs/include/rtw_mlme.h deleted file mode 100644 index 6faa13535b62..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_mlme.h +++ /dev/null @@ -1,397 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_MLME_H_ -#define __RTW_MLME_H_ - - -#define MAX_BSS_CNT 128 -/* define MAX_JOIN_TIMEOUT 2000 */ -/* define MAX_JOIN_TIMEOUT 2500 */ -#define MAX_JOIN_TIMEOUT 6500 - -/* Commented by Albert 20101105 */ -/* Increase the scanning timeout because of increasing the SURVEY_TO value. */ - -#define SCANNING_TIMEOUT 8000 - -#define SCANQUEUE_LIFETIME 20000 /* 20sec, unit:msec */ - -#define WIFI_NULL_STATE 0x00000000 -#define WIFI_ASOC_STATE 0x00000001 /* Under Linked state... */ -#define WIFI_SLEEP_STATE 0x00000004 -#define WIFI_STATION_STATE 0x00000008 -#define WIFI_AP_STATE 0x00000010 -#define WIFI_ADHOC_STATE 0x00000020 -#define WIFI_ADHOC_MASTER_STATE 0x00000040 -#define WIFI_UNDER_LINKING 0x00000080 - -#define WIFI_UNDER_WPS 0x00000100 -#define WIFI_STA_ALIVE_CHK_STATE 0x00000400 -#define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station is under site surveying */ - -/* ifdef UNDER_MPTEST */ -#define WIFI_MP_STATE 0x00010000 -/* endif */ - -/* define _FW_UNDER_CMD WIFI_UNDER_CMD */ -#define _FW_UNDER_LINKING WIFI_UNDER_LINKING -#define _FW_LINKED WIFI_ASOC_STATE -#define _FW_UNDER_SURVEY WIFI_SITE_MONITOR - - -enum { - dot11_auth_algrthm_open = 0, - dot11_auth_algrthm_shared, - dot11_auth_algrthm_8021x, - dot11_auth_algrthm_auto, - dot11_auth_algrthm_wapi, - dot11_auth_algrthm_maxnum -}; - -/* Scan type including active and passive scan. */ -enum rt_scan_type { - SCAN_PASSIVE, - SCAN_ACTIVE, - SCAN_MIX, -}; - -enum { - GHZ24_50 = 0, - GHZ_50, - GHZ_24, - GHZ_MAX, -}; - -/* - * There are several "locks" in mlme_priv, - * since mlme_priv is a shared resource between many threads, - * like ISR/Call-Back functions, the OID handlers, and even timer functions. - * - * Each struct __queue has its own locks, already. - * Other items in mlme_priv are protected by mlme_priv.lock, while items in - * xmit_priv are protected by xmit_priv.lock. - * - * To avoid possible dead lock, any thread trying to modifying mlme_priv - * SHALL not lock up more than one locks at a time! - * - * The only exception is that queue functions which take the __queue.lock - * may be called with the xmit_priv.lock held. In this case the order - * MUST always be first lock xmit_priv.lock and then call any queue functions - * which take __queue.lock. - */ - -struct sitesurvey_ctrl { - u64 last_tx_pkts; - uint last_rx_pkts; - signed int traffic_busy; - struct timer_list sitesurvey_ctrl_timer; -}; - -struct rt_link_detect_t { - u32 num_tx_ok_in_period; - u32 num_rx_ok_in_period; - u32 num_rx_unicast_ok_in_period; - bool busy_traffic; - bool tx_busy_traffic; - bool rx_busy_traffic; - /* For interrupt migration purpose. */ - bool higher_busy_traffic; - /* We may disable Tx interrupt according as Rx traffic. */ - bool higher_busy_rx_traffic; - /* We may disable Tx interrupt according as Tx traffic. */ - bool higher_busy_tx_traffic; - u8 traffic_transition_count; - u32 low_power_transition_count; -}; - -/* used for mlme_priv.roam_flags */ -enum { - RTW_ROAM_ON_EXPIRED = BIT(0), - RTW_ROAM_ON_RESUME = BIT(1), - RTW_ROAM_ACTIVE = BIT(2), -}; - -struct mlme_priv { - - spinlock_t lock; - signed int fw_state; /* shall we protect this variable? maybe not necessarily... */ - u8 bScanInProcess; - u8 to_join; /* flag */ - - u8 to_roam; /* roaming trying times */ - struct wlan_network *roam_network; /* the target of active roam */ - u8 roam_flags; - u8 roam_rssi_diff_th; /* rssi difference threshold for active scan candidate selection */ - u32 roam_scan_int_ms; /* scan interval for active roam */ - u32 roam_scanr_exp_ms; /* scan result expire time in ms for roam */ - u8 roam_tgt_addr[ETH_ALEN]; /* request to roam to specific target without other consideration */ - - u8 *nic_hdl; - - u8 not_indic_disco; - struct list_head *pscanned; - struct __queue free_bss_pool; - struct __queue scanned_queue; - u8 *free_bss_buf; - - struct ndis_802_11_ssid assoc_ssid; - u8 assoc_bssid[6]; - - struct wlan_network cur_network; - struct wlan_network *cur_network_scanned; - - /* uint wireless_mode; no used, remove it */ - - u32 auto_scan_int_ms; - - struct timer_list assoc_timer; - - uint assoc_by_bssid; - uint assoc_by_rssi; - - struct timer_list scan_to_timer; /* driver itself handles scan_timeout status. */ - unsigned long scan_start_time; /* used to evaluate the time spent in scanning */ - - struct timer_list set_scan_deny_timer; - atomic_t set_scan_deny; /* 0: allowed, 1: deny */ - - struct qos_priv qospriv; - - /* Number of non-HT AP/stations */ - int num_sta_no_ht; - - /* Number of HT AP/stations 20 MHz */ - /* int num_sta_ht_20mhz; */ - - - int num_FortyMHzIntolerant; - - struct ht_priv htpriv; - - struct rt_link_detect_t link_detect_info; - struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */ - - u8 acm_mask; /* for wmm acm mask */ - u8 ChannelPlan; - enum rt_scan_type scan_mode; /* active: 1, passive: 0 */ - - u8 *wps_probe_req_ie; - u32 wps_probe_req_ie_len; - - /* Number of associated Non-ERP stations (i.e., stations using 802.11b - * in 802.11g BSS) - */ - int num_sta_non_erp; - - /* Number of associated stations that do not support Short Slot Time */ - int num_sta_no_short_slot_time; - - /* Number of associated stations that do not support Short Preamble */ - int num_sta_no_short_preamble; - - int olbc; /* Overlapping Legacy BSS Condition */ - - /* Number of HT associated stations that do not support greenfield */ - int num_sta_ht_no_gf; - - /* Number of associated non-HT stations */ - /* int num_sta_no_ht; */ - - /* Number of HT associated stations 20 MHz */ - int num_sta_ht_20mhz; - - /* Overlapping BSS information */ - int olbc_ht; - - u16 ht_op_mode; - - u8 *assoc_req; - u32 assoc_req_len; - u8 *assoc_rsp; - u32 assoc_rsp_len; - - u8 *wps_beacon_ie; - /* u8 *wps_probe_req_ie; */ - u8 *wps_probe_resp_ie; - u8 *wps_assoc_resp_ie; /* this IE could include p2p ie / wfd ie */ - - u32 wps_beacon_ie_len; - /* u32 wps_probe_req_ie_len; */ - u32 wps_probe_resp_ie_len; - u32 wps_assoc_resp_ie_len; /* this IE len could include p2p ie / wfd ie */ - - u8 *p2p_beacon_ie; - u8 *p2p_probe_req_ie; - u8 *p2p_probe_resp_ie; - u8 *p2p_go_probe_resp_ie; /* for GO */ - u8 *p2p_assoc_req_ie; - - u32 p2p_beacon_ie_len; - u32 p2p_probe_req_ie_len; - u32 p2p_probe_resp_ie_len; - u32 p2p_go_probe_resp_ie_len; /* for GO */ - u32 p2p_assoc_req_ie_len; - - spinlock_t bcn_update_lock; - u8 update_bcn; - - u8 NumOfBcnInfoChkFail; - unsigned long timeBcnInfoChkStart; -}; - -void rtw_mlme_reset_auto_scan_int(struct adapter *adapter); - -struct hostapd_priv { - struct adapter *padapter; -}; - -extern int hostapd_mode_init(struct adapter *padapter); -extern void hostapd_mode_unload(struct adapter *padapter); - -extern void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf); -extern void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf); -extern void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf); -extern void rtw_joinbss_event_callback(struct adapter *adapter, u8 *pbuf); -extern void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf); -extern void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf); -extern void rtw_cpwm_event_callback(struct adapter *adapter, u8 *pbuf); -extern void rtw_wmm_event_callback(struct adapter *padapter, u8 *pbuf); - -extern void rtw_join_timeout_handler(struct timer_list *t); -extern void _rtw_scan_timeout_handler(struct timer_list *t); - -int event_thread(void *context); - -extern void rtw_free_network_queue(struct adapter *adapter, u8 isfreeall); -extern int rtw_init_mlme_priv(struct adapter *adapter);/* (struct mlme_priv *pmlmepriv); */ - -extern void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv); - - -extern signed int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv); -extern signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, signed int keyid, u8 set_tx, bool enqueue); -extern signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv); - -static inline u8 *get_bssid(struct mlme_priv *pmlmepriv) -{ /* if sta_mode:pmlmepriv->cur_network.network.mac_address => bssid */ - /* if adhoc_mode:pmlmepriv->cur_network.network.mac_address => ibss mac address */ - return pmlmepriv->cur_network.network.mac_address; -} - -static inline signed int check_fwstate(struct mlme_priv *pmlmepriv, signed int state) -{ - if (pmlmepriv->fw_state & state) - return true; - - return false; -} - -static inline signed int get_fwstate(struct mlme_priv *pmlmepriv) -{ - return pmlmepriv->fw_state; -} - -/* - * No Limit on the calling context, - * therefore set it to be the critical section... - * - * ### NOTE:#### (!!!!) - * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock - */ -static inline void set_fwstate(struct mlme_priv *pmlmepriv, signed int state) -{ - pmlmepriv->fw_state |= state; - /* FOR HW integration */ - if (state == _FW_UNDER_SURVEY) - pmlmepriv->bScanInProcess = true; -} - -static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, signed int state) -{ - pmlmepriv->fw_state &= ~state; - /* FOR HW integration */ - if (state == _FW_UNDER_SURVEY) - pmlmepriv->bScanInProcess = false; -} - -extern u16 rtw_get_capability(struct wlan_bssid_ex *bss); -extern void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *target); -extern void rtw_disconnect_hdl_under_linked(struct adapter *adapter, struct sta_info *psta, u8 free_assoc); -extern void rtw_generate_random_ibss(u8 *pibss); -extern struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr); -extern struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue); -struct wlan_network *_rtw_find_same_network(struct __queue *scanned_queue, struct wlan_network *network); - -extern void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue); -extern void rtw_indicate_disconnect(struct adapter *adapter); -extern void rtw_indicate_connect(struct adapter *adapter); -void rtw_indicate_scan_done(struct adapter *padapter, bool aborted); -void rtw_scan_abort(struct adapter *adapter); - -extern int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len); -extern int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len); -extern void rtw_init_registrypriv_dev_network(struct adapter *adapter); - -extern void rtw_update_registrypriv_dev_network(struct adapter *adapter); - -extern void _rtw_join_timeout_handler(struct timer_list *t); -extern void rtw_scan_timeout_handler(struct timer_list *t); - -extern void rtw_dynamic_check_timer_handler(struct adapter *adapter); -bool rtw_is_scan_deny(struct adapter *adapter); -void rtw_clear_scan_deny(struct adapter *adapter); -void rtw_set_scan_deny(struct adapter *adapter, u32 ms); - -void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv); - -extern void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv); - -/* extern struct wlan_network* _rtw_dequeue_network(struct __queue *queue); */ - -extern struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv); - - -extern void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall); -extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork); - - -extern struct wlan_network *_rtw_find_network(struct __queue *scanned_queue, u8 *addr); - -bool rtw_if_up(struct adapter *padapter); - -bool rtw_linked_check(struct adapter *padapter); - -u8 *rtw_get_capability_from_ie(u8 *ie); -u8 *rtw_get_beacon_interval_from_ie(u8 *ie); - - -void rtw_joinbss_reset(struct adapter *padapter); - -void rtw_ht_use_default_setting(struct adapter *padapter); -void rtw_build_wmm_ie_ht(struct adapter *padapter, u8 *out_ie, uint *pout_len); -unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel); -void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len, u8 channel); -void rtw_issue_addbareq_cmd(struct adapter *padapter, struct xmit_frame *pxmitframe); -void rtw_append_exented_cap(struct adapter *padapter, u8 *out_ie, uint *pout_len); - -bool rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork); -int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst, u8 feature); - -#define rtw_roam_flags(adapter) ((adapter)->mlmepriv.roam_flags) -#define rtw_chk_roam_flags(adapter, flags) ((adapter)->mlmepriv.roam_flags & flags) - -void _rtw_roaming(struct adapter *adapter, struct wlan_network *tgt_network); -void rtw_roaming(struct adapter *adapter, struct wlan_network *tgt_network); -void rtw_set_to_roam(struct adapter *adapter, u8 to_roam); -u8 rtw_dec_to_roam(struct adapter *adapter); -u8 rtw_to_roam(struct adapter *adapter); -int rtw_select_roaming_candidate(struct mlme_priv *pmlmepriv); - -void rtw_sta_media_status_rpt(struct adapter *adapter, struct sta_info *psta, u32 mstatus); -void rtw_reset_securitypriv(struct adapter *adapter); - -#endif /* __RTL871X_MLME_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h deleted file mode 100644 index 179fae4d8fcc..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +++ /dev/null @@ -1,708 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_MLME_EXT_H_ -#define __RTW_MLME_EXT_H_ - - -/* Commented by Albert 20101105 */ -/* Increase the SURVEY_TO value from 100 to 150 (100ms to 150ms) */ -/* The Realtek 8188CE SoftAP will spend around 100ms to send the probe response after receiving the probe request. */ -/* So, this driver tried to extend the dwell time for each scanning channel. */ -/* This will increase the chance to receive the probe response from SoftAP. */ - -#define SURVEY_TO (100) -#define REAUTH_TO (300) /* 50) */ -#define REASSOC_TO (300) /* 50) */ -/* define DISCONNECT_TO (3000) */ -#define ADDBA_TO (2000) - -#define REAUTH_LIMIT (4) -#define REASSOC_LIMIT (4) - -#define DYNAMIC_FUNC_DISABLE (0x0) - -/* ====== ODM_ABILITY_E ======== */ -/* BB ODM section BIT 0-15 */ -#define DYNAMIC_BB_DIG BIT(0) /* ODM_BB_DIG */ -#define DYNAMIC_BB_DYNAMIC_TXPWR BIT(2) /* ODM_BB_DYNAMIC_TXPWR */ -#define DYNAMIC_BB_ANT_DIV BIT(6) /* ODM_BB_ANT_DIV */ - -/* RF ODM section BIT 24-31 */ -#define DYNAMIC_RF_CALIBRATION BIT(26)/* ODM_RF_CALIBRATION */ - -#define DYNAMIC_ALL_FUNC_ENABLE 0xFFFFFFF - -#define _HW_STATE_NOLINK_ 0x00 -#define _HW_STATE_ADHOC_ 0x01 -#define _HW_STATE_STATION_ 0x02 -#define _HW_STATE_AP_ 0x03 - - -#define _1M_RATE_ 0 -#define _2M_RATE_ 1 -#define _5M_RATE_ 2 -#define _11M_RATE_ 3 -#define _6M_RATE_ 4 -#define _9M_RATE_ 5 -#define _12M_RATE_ 6 -#define _18M_RATE_ 7 -#define _24M_RATE_ 8 -#define _36M_RATE_ 9 -#define _48M_RATE_ 10 -#define _54M_RATE_ 11 - -/******************************************************** -MCS rate definitions -*********************************************************/ -#define MCS_RATE_1R (0x000000ff) - -extern unsigned char RTW_WPA_OUI[]; -extern unsigned char WMM_OUI[]; -extern unsigned char WPS_OUI[]; -extern unsigned char WFD_OUI[]; -extern unsigned char P2P_OUI[]; - -extern unsigned char WMM_INFO_OUI[]; -extern unsigned char WMM_PARA_OUI[]; - - -/* */ -/* Channel Plan Type. */ -/* Note: */ -/* We just add new channel plan when the new channel plan is different from any of the following */ -/* channel plan. */ -/* If you just want to customize the actions(scan period or join actions) about one of the channel plan, */ -/* customize them in rt_channel_info in the RT_CHANNEL_LIST. */ -/* */ -enum { - /* old channel plan mapping ===== */ - RT_CHANNEL_DOMAIN_FCC = 0x00, - RT_CHANNEL_DOMAIN_IC = 0x01, - RT_CHANNEL_DOMAIN_ETSI = 0x02, - RT_CHANNEL_DOMAIN_SPAIN = 0x03, - RT_CHANNEL_DOMAIN_FRANCE = 0x04, - RT_CHANNEL_DOMAIN_MKK = 0x05, - RT_CHANNEL_DOMAIN_MKK1 = 0x06, - RT_CHANNEL_DOMAIN_ISRAEL = 0x07, - RT_CHANNEL_DOMAIN_TELEC = 0x08, - RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN = 0x09, - RT_CHANNEL_DOMAIN_WORLD_WIDE_13 = 0x0A, - RT_CHANNEL_DOMAIN_TAIWAN = 0x0B, - RT_CHANNEL_DOMAIN_CHINA = 0x0C, - RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO = 0x0D, - RT_CHANNEL_DOMAIN_KOREA = 0x0E, - RT_CHANNEL_DOMAIN_TURKEY = 0x0F, - RT_CHANNEL_DOMAIN_JAPAN = 0x10, - RT_CHANNEL_DOMAIN_FCC_NO_DFS = 0x11, - RT_CHANNEL_DOMAIN_JAPAN_NO_DFS = 0x12, - RT_CHANNEL_DOMAIN_WORLD_WIDE_5G = 0x13, - RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS = 0x14, - - /* new channel plan mapping, (2GDOMAIN_5GDOMAIN) ===== */ - RT_CHANNEL_DOMAIN_WORLD_NULL = 0x20, - RT_CHANNEL_DOMAIN_ETSI1_NULL = 0x21, - RT_CHANNEL_DOMAIN_FCC1_NULL = 0x22, - RT_CHANNEL_DOMAIN_MKK1_NULL = 0x23, - RT_CHANNEL_DOMAIN_ETSI2_NULL = 0x24, - RT_CHANNEL_DOMAIN_FCC1_FCC1 = 0x25, - RT_CHANNEL_DOMAIN_WORLD_ETSI1 = 0x26, - RT_CHANNEL_DOMAIN_MKK1_MKK1 = 0x27, - RT_CHANNEL_DOMAIN_WORLD_KCC1 = 0x28, - RT_CHANNEL_DOMAIN_WORLD_FCC2 = 0x29, - RT_CHANNEL_DOMAIN_WORLD_FCC3 = 0x30, - RT_CHANNEL_DOMAIN_WORLD_FCC4 = 0x31, - RT_CHANNEL_DOMAIN_WORLD_FCC5 = 0x32, - RT_CHANNEL_DOMAIN_WORLD_FCC6 = 0x33, - RT_CHANNEL_DOMAIN_FCC1_FCC7 = 0x34, - RT_CHANNEL_DOMAIN_WORLD_ETSI2 = 0x35, - RT_CHANNEL_DOMAIN_WORLD_ETSI3 = 0x36, - RT_CHANNEL_DOMAIN_MKK1_MKK2 = 0x37, - RT_CHANNEL_DOMAIN_MKK1_MKK3 = 0x38, - RT_CHANNEL_DOMAIN_FCC1_NCC1 = 0x39, - RT_CHANNEL_DOMAIN_FCC1_NCC2 = 0x40, - RT_CHANNEL_DOMAIN_GLOBAL_NULL = 0x41, - RT_CHANNEL_DOMAIN_ETSI1_ETSI4 = 0x42, - RT_CHANNEL_DOMAIN_FCC1_FCC2 = 0x43, - RT_CHANNEL_DOMAIN_FCC1_NCC3 = 0x44, - RT_CHANNEL_DOMAIN_WORLD_ETSI5 = 0x45, - RT_CHANNEL_DOMAIN_FCC1_FCC8 = 0x46, - RT_CHANNEL_DOMAIN_WORLD_ETSI6 = 0x47, - RT_CHANNEL_DOMAIN_WORLD_ETSI7 = 0x48, - RT_CHANNEL_DOMAIN_WORLD_ETSI8 = 0x49, - RT_CHANNEL_DOMAIN_WORLD_ETSI9 = 0x50, - RT_CHANNEL_DOMAIN_WORLD_ETSI10 = 0x51, - RT_CHANNEL_DOMAIN_WORLD_ETSI11 = 0x52, - RT_CHANNEL_DOMAIN_FCC1_NCC4 = 0x53, - RT_CHANNEL_DOMAIN_WORLD_ETSI12 = 0x54, - RT_CHANNEL_DOMAIN_FCC1_FCC9 = 0x55, - RT_CHANNEL_DOMAIN_WORLD_ETSI13 = 0x56, - RT_CHANNEL_DOMAIN_FCC1_FCC10 = 0x57, - /* Add new channel plan above this line =============== */ - RT_CHANNEL_DOMAIN_MAX, - RT_CHANNEL_DOMAIN_REALTEK_DEFINE = 0x7F, -}; - -enum { - RT_CHANNEL_DOMAIN_2G_WORLD = 0x00, /* Worldwird 13 */ - RT_CHANNEL_DOMAIN_2G_ETSI1 = 0x01, /* Europe */ - RT_CHANNEL_DOMAIN_2G_FCC1 = 0x02, /* US */ - RT_CHANNEL_DOMAIN_2G_MKK1 = 0x03, /* Japan */ - RT_CHANNEL_DOMAIN_2G_ETSI2 = 0x04, /* France */ - RT_CHANNEL_DOMAIN_2G_GLOBAL = 0x05, /* Global domain */ - RT_CHANNEL_DOMAIN_2G_NULL = 0x06, - /* Add new channel plan above this line =============== */ - RT_CHANNEL_DOMAIN_2G_MAX, -}; - -#define rtw_is_channel_plan_valid(chplan) (chplan < RT_CHANNEL_DOMAIN_MAX || chplan == RT_CHANNEL_DOMAIN_REALTEK_DEFINE) - -struct rt_channel_plan { - unsigned char Channel[MAX_CHANNEL_NUM]; - unsigned char Len; -}; - -struct rt_channel_plan_2g { - unsigned char Channel[MAX_CHANNEL_NUM_2G]; - unsigned char Len; -}; - -struct rt_channel_plan_map { - unsigned char Index2G; -}; - -enum { - HT_IOT_PEER_UNKNOWN = 0, - HT_IOT_PEER_REALTEK = 1, - HT_IOT_PEER_REALTEK_92SE = 2, - HT_IOT_PEER_BROADCOM = 3, - HT_IOT_PEER_RALINK = 4, - HT_IOT_PEER_ATHEROS = 5, - HT_IOT_PEER_CISCO = 6, - HT_IOT_PEER_MERU = 7, - HT_IOT_PEER_MARVELL = 8, - HT_IOT_PEER_REALTEK_SOFTAP = 9,/* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */ - HT_IOT_PEER_SELF_SOFTAP = 10, /* Self is SoftAP */ - HT_IOT_PEER_AIRGO = 11, - HT_IOT_PEER_INTEL = 12, - HT_IOT_PEER_RTK_APCLIENT = 13, - HT_IOT_PEER_REALTEK_81XX = 14, - HT_IOT_PEER_REALTEK_WOW = 15, - HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP = 16, - HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP = 17, - HT_IOT_PEER_MAX = 18 -}; - - -enum { - SCAN_DISABLE = 0, - SCAN_START = 1, - SCAN_TXNULL = 2, - SCAN_PROCESS = 3, - SCAN_COMPLETE = 4, - SCAN_STATE_MAX, -}; - -struct mlme_handler { - unsigned int num; - char *str; - unsigned int (*func)(struct adapter *padapter, union recv_frame *precv_frame); -}; - -struct action_handler { - unsigned int num; - char *str; - unsigned int (*func)(struct adapter *padapter, union recv_frame *precv_frame); -}; - -struct ss_res { - int state; - int bss_cnt; - int channel_idx; - int scan_mode; - u8 ssid_num; - u8 ch_num; - struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT]; - struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT]; -}; - -/* define AP_MODE 0x0C */ -/* define STATION_MODE 0x08 */ -/* define AD_HOC_MODE 0x04 */ -/* define NO_LINK_MODE 0x00 */ - -#define WIFI_FW_NULL_STATE _HW_STATE_NOLINK_ -#define WIFI_FW_STATION_STATE _HW_STATE_STATION_ -#define WIFI_FW_AP_STATE _HW_STATE_AP_ -#define WIFI_FW_ADHOC_STATE _HW_STATE_ADHOC_ - -#define WIFI_FW_AUTH_NULL 0x00000100 -#define WIFI_FW_AUTH_STATE 0x00000200 -#define WIFI_FW_AUTH_SUCCESS 0x00000400 - -#define WIFI_FW_ASSOC_STATE 0x00002000 -#define WIFI_FW_ASSOC_SUCCESS 0x00004000 - -#define WIFI_FW_LINKING_STATE (WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE | WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE) - -struct FW_Sta_Info { - struct sta_info *psta; - u32 status; - u32 rx_pkt; - u32 retry; - NDIS_802_11_RATES_EX SupportedRates; -}; - -/* - * Usage: - * When one iface acted as AP mode and the other iface is STA mode and scanning, - * it should switch back to AP's operating channel periodically. - * Parameters info: - * When the driver scanned RTW_SCAN_NUM_OF_CH channels, it would switch back to AP's operating channel for - * RTW_STAY_AP_CH_MILLISECOND * SURVEY_TO milliseconds. - * Example: - * For chip supports 2.4G and AP mode is operating in channel 1, - * RTW_SCAN_NUM_OF_CH is 8, RTW_STAY_AP_CH_MILLISECOND is 3 and SURVEY_TO is 100. - * When it's STA mode gets set_scan command, - * it would - * 1. Doing the scan on channel 1.2.3.4.5.6.7.8 - * 2. Back to channel 1 for 300 milliseconds - * 3. Go through doing site survey on channel 9.10.11 - * 4. Back to channel 1 for 300 milliseconds - * 5. ... and so on, till survey done. - */ -struct mlme_ext_info { - u32 state; - u32 reauth_count; - u32 reassoc_count; - u32 link_count; - u32 auth_seq; - u32 auth_algo; /* 802.11 auth, could be open, shared, auto */ - u32 authModeToggle; - u32 enc_algo;/* encrypt algorithm; */ - u32 key_index; /* this is only valid for legendary wep, 0~3 for key id. */ - u32 iv; - u8 chg_txt[128]; - u16 aid; - u16 bcn_interval; - u16 capability; - u8 assoc_AP_vendor; - u8 slotTime; - u8 preamble_mode; - u8 WMM_enable; - u8 ERP_enable; - u8 ERP_IE; - u8 HT_enable; - u8 HT_caps_enable; - u8 HT_info_enable; - u8 HT_protection; - u8 turboMode_cts2self; - u8 turboMode_rtsen; - u8 SM_PS; - u8 agg_enable_bitmap; - u8 ADDBA_retry_count; - u8 candidate_tid_bitmap; - u8 dialogToken; - /* Accept ADDBA Request */ - bool accept_addba_req; - u8 bwmode_updated; - u8 hidden_ssid_mode; - u8 VHT_enable; - - struct ADDBA_request ADDBA_req; - struct WMM_para_element WMM_param; - struct HT_caps_element HT_caps; - struct HT_info_element HT_info; - struct wlan_bssid_ex network;/* join network or bss_network, if in ap mode, it is the same to cur_network.network */ - struct FW_Sta_Info FW_sta_info[NUM_STA]; -}; - -/* The channel information about this channel including joining, scanning, and power constraints. */ -struct rt_channel_info { - u8 channel_num; /* The channel number. */ - enum rt_scan_type scan_type; /* Scan type such as passive or active scan. */ -}; - -int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch); - -/* P2P_MAX_REG_CLASSES - Maximum number of regulatory classes */ -#define P2P_MAX_REG_CLASSES 10 - -/* P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class */ -#define P2P_MAX_REG_CLASS_CHANNELS 20 - -/* struct p2p_channels - List of supported channels */ -struct p2p_channels { - /* struct p2p_reg_class - Supported regulatory class */ - struct p2p_reg_class { - /* reg_class - Regulatory class (IEEE 802.11-2007, Annex J) */ - u8 reg_class; - - /* channel - Supported channels */ - u8 channel[P2P_MAX_REG_CLASS_CHANNELS]; - - /* channels - Number of channel entries in use */ - size_t channels; - } reg_class[P2P_MAX_REG_CLASSES]; - - /* reg_classes - Number of reg_class entries in use */ - size_t reg_classes; -}; - -struct p2p_oper_class_map { - enum hw_mode {IEEE80211G, IEEE80211A} mode; - u8 op_class; - u8 min_chan; - u8 max_chan; - u8 inc; - enum { BW20, BW40PLUS, BW40MINUS } bw; -}; - -struct mlme_ext_priv { - struct adapter *padapter; - u8 mlmeext_init; - atomic_t event_seq; - u16 mgnt_seq; - u16 sa_query_seq; - u64 mgnt_80211w_IPN; - u64 mgnt_80211w_IPN_rx; - /* struct fw_priv fwpriv; */ - - unsigned char cur_channel; - unsigned char cur_bwmode; - unsigned char cur_ch_offset;/* PRIME_CHNL_OFFSET */ - unsigned char cur_wireless_mode; /* NETWORK_TYPE */ - - unsigned char max_chan_nums; - struct rt_channel_info channel_set[MAX_CHANNEL_NUM]; - struct p2p_channels channel_list; - unsigned char basicrate[NumRates]; - unsigned char datarate[NumRates]; - unsigned char default_supported_mcs_set[16]; - - struct ss_res sitesurvey_res; - struct mlme_ext_info mlmext_info; /* for sta/adhoc mode, including current scanning/connecting/connected related info. */ - /* for ap mode, network includes ap's cap_info */ - struct timer_list survey_timer; - struct timer_list link_timer; - struct timer_list sa_query_timer; - /* struct timer_list ADDBA_timer; */ - u16 chan_scan_time; - unsigned long last_scan_time; - u8 scan_abort; - u8 tx_rate; /* TXRATE when USERATE is set. */ - - u32 retry; /* retry for issue probereq */ - - u64 TSFValue; - - /* for LPS-32K to adaptive bcn early and timeout */ - u8 adaptive_tsf_done; - u32 bcn_delay_cnt[9]; - u32 bcn_delay_ratio[9]; - u32 bcn_cnt; - u8 DrvBcnEarly; - u8 DrvBcnTimeOut; - - unsigned char bstart_bss; - - u8 update_channel_plan_by_ap_done; - - /* recv_decache check for Action_public frame */ - u8 action_public_dialog_token; - u16 action_public_rxseq; - - u8 active_keep_alive_check; -}; - -void init_mlme_default_rate_set(struct adapter *padapter); -void init_mlme_ext_priv(struct adapter *padapter); -void init_hw_mlme_ext(struct adapter *padapter); -void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext); -extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv); - -/* void fill_fwpriv(struct adapter *padapter, struct fw_priv *pfwpriv); */ - -u8 networktype_to_raid_ex(struct adapter *adapter, struct sta_info *psta); - -void get_rate_set(struct adapter *padapter, unsigned char *pbssrate, int *bssrate_len); -void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask); -void update_basic_rate_table(struct adapter *padapter, u8 *mBratesOS); -void update_basic_rate_table_soft_ap(u8 *bssrateset, u32 bssratelen); - -void save_dm_func_flag(struct adapter *padapter); -void restore_dm_func_flag(struct adapter *padapter); -void switch_dm_func(struct adapter *padapter, u32 mode, u8 enable); - -void set_msr(struct adapter *padapter, u8 type); - -u8 rtw_get_oper_ch(struct adapter *adapter); -void rtw_set_oper_ch(struct adapter *adapter, u8 ch); -void rtw_set_oper_bw(struct adapter *adapter, u8 bw); -void rtw_set_oper_choffset(struct adapter *adapter, u8 offset); -u8 rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset); -unsigned long rtw_get_on_cur_ch_time(struct adapter *adapter); - -void set_channel_bwmode(struct adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode); -void r8723bs_select_channel(struct adapter *padapter, unsigned char channel); - -unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval); - -/* modify HW only */ -void _write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key); -void _clear_cam_entry(struct adapter *padapter, u8 entry); - -/* modify both HW and cache */ -void write_cam(struct adapter *padapter, u8 id, u16 ctrl, u8 *mac, u8 *key); -void clear_cam_entry(struct adapter *padapter, u8 id); - -/* modify cache only */ -void write_cam_cache(struct adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key); -void clear_cam_cache(struct adapter *adapter, u8 id); - -void invalidate_cam_all(struct adapter *padapter); - - -int allocate_fw_sta_entry(struct adapter *padapter); -void flush_all_cam_entry(struct adapter *padapter); - -void site_survey(struct adapter *padapter); -u8 collect_bss_info(struct adapter *padapter, union recv_frame *precv_frame, struct wlan_bssid_ex *bssid); -void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src, struct adapter *padapter, bool update_ie); - -u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork); -u16 get_beacon_interval(struct wlan_bssid_ex *bss); - -int is_client_associated_to_ap(struct adapter *padapter); -int is_client_associated_to_ibss(struct adapter *padapter); -int is_IBSS_empty(struct adapter *padapter); - -unsigned char check_assoc_AP(u8 *pframe, uint len); - -int WMM_param_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE); -void WMMOnAssocRsp(struct adapter *padapter); - -void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE); -void HT_info_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE); -void HTOnAssocRsp(struct adapter *padapter); - -void ERP_IE_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE); -void VCS_update(struct adapter *padapter, struct sta_info *psta); -void update_ldpc_stbc_cap(struct sta_info *psta); - -void update_beacon_info(struct adapter *padapter, u8 *pframe, uint len, struct sta_info *psta); -int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len); -void update_IOT_info(struct adapter *padapter); -void update_capinfo(struct adapter *Adapter, u16 updateCap); -void update_wireless_mode(struct adapter *padapter); -void update_sta_basic_rate(struct sta_info *psta, u8 wireless_mode); -int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie, uint var_ie_len, int cam_idx); - -/* for sta/adhoc mode */ -void update_sta_info(struct adapter *padapter, struct sta_info *psta); -void update_ra_entry(struct adapter *padapter, struct sta_info *psta); -void set_sta_rate(struct adapter *padapter, struct sta_info *psta); - -unsigned int receive_disconnect(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason); - -unsigned char get_highest_rate_idx(u32 mask); -int support_short_GI(struct adapter *padapter, struct HT_caps_element *pHT_caps, u8 bwmode); -unsigned int is_ap_in_tkip(struct adapter *padapter); - -s16 rtw_camid_search(struct adapter *adapter, u8 *addr, s16 kid); -s16 rtw_camid_alloc(struct adapter *adapter, struct sta_info *sta, u8 kid); -void rtw_camid_free(struct adapter *adapter, u8 cam_id); - -extern void rtw_alloc_macid(struct adapter *padapter, struct sta_info *psta); -extern void rtw_release_macid(struct adapter *padapter, struct sta_info *psta); - -void report_join_res(struct adapter *padapter, int res); -void report_survey_event(struct adapter *padapter, union recv_frame *precv_frame); -void report_surveydone_event(struct adapter *padapter); -void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason); -void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int cam_idx); -void report_wmm_edca_update(struct adapter *padapter); - -u8 chk_bmc_sleepq_cmd(struct adapter *padapter); -extern u8 set_tx_beacon_cmd(struct adapter *padapter); -unsigned int setup_beacon_frame(struct adapter *padapter, unsigned char *beacon_frame); -void update_mgnt_tx_rate(struct adapter *padapter, u8 rate); -void update_mgntframe_attrib(struct adapter *padapter, struct pkt_attrib *pattrib); -void update_mgntframe_attrib_addr(struct adapter *padapter, struct xmit_frame *pmgntframe); -void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe); -s32 dump_mgntframe_and_wait(struct adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms); -s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmgntframe); - -void issue_beacon(struct adapter *padapter, int timeout_ms); -void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq); -void issue_assocreq(struct adapter *padapter); -void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type); -void issue_auth(struct adapter *padapter, struct sta_info *psta, unsigned short status); -void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da); -s32 issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, u8 ch, bool append_wps, int try_cnt, int wait_ms); -int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms); -s32 issue_nulldata_in_interrupt(struct adapter *padapter, u8 *da); -int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms); -int issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason); -int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int try_cnt, int wait_ms); -void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status); -void issue_action_SA_Query(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short tid); -unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr); -unsigned int send_beacon(struct adapter *padapter); - -void start_clnt_assoc(struct adapter *padapter); -void start_clnt_auth(struct adapter *padapter); -void start_clnt_join(struct adapter *padapter); -void start_create_ibss(struct adapter *padapter); - -unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAssocRsp(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnProbeReq(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnProbeRsp(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int DoReserved(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnBeacon(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAtim(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnDisassoc(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAuth(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnDeAuth(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAction(struct adapter *padapter, union recv_frame *precv_frame); - -unsigned int on_action_spct(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAction_back(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int on_action_public(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAction_ht(struct adapter *padapter, union recv_frame *precv_frame); -unsigned int OnAction_sa_query(struct adapter *padapter, union recv_frame *precv_frame); - -void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res); -void mlmeext_sta_del_event_callback(struct adapter *padapter); -void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *psta); - -void linked_status_chk(struct adapter *padapter); - -void _linked_info_dump(struct adapter *padapter); - -void survey_timer_hdl(struct timer_list *t); -void link_timer_hdl(struct timer_list *t); -void addba_timer_hdl(struct timer_list *t); -void sa_query_timer_hdl(struct timer_list *t); -/* void reauth_timer_hdl(struct adapter *padapter); */ -/* void reassoc_timer_hdl(struct adapter *padapter); */ - -#define set_survey_timer(mlmeext, ms) \ - do { \ - _set_timer(&(mlmeext)->survey_timer, (ms)); \ - } while (0) - -#define set_link_timer(mlmeext, ms) \ - do { \ - _set_timer(&(mlmeext)->link_timer, (ms)); \ - } while (0) -#define set_sa_query_timer(mlmeext, ms) \ - do { \ - _set_timer(&(mlmeext)->sa_query_timer, (ms)); \ - } while (0) - -extern void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr); - -extern void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len); -extern void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext); -extern void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len); -extern bool traffic_status_watchdog(struct adapter *padapter, bool from_timer); - -int rtw_chk_start_clnt_join(struct adapter *padapter, u8 *ch, u8 *bw, u8 *offset); - -struct cmd_hdl { - uint parmsize; - u8 (*h2cfuns)(struct adapter *padapter, u8 *pbuf); -}; - - -u8 read_macreg_hdl(struct adapter *padapter, u8 *pbuf); -u8 write_macreg_hdl(struct adapter *padapter, u8 *pbuf); -u8 read_bbreg_hdl(struct adapter *padapter, u8 *pbuf); -u8 write_bbreg_hdl(struct adapter *padapter, u8 *pbuf); -u8 read_rfreg_hdl(struct adapter *padapter, u8 *pbuf); -u8 write_rfreg_hdl(struct adapter *padapter, u8 *pbuf); - - -u8 NULL_hdl(struct adapter *padapter, u8 *pbuf); -u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf); -u8 disconnect_hdl(struct adapter *padapter, u8 *pbuf); -u8 createbss_hdl(struct adapter *padapter, u8 *pbuf); -u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf); -u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf); -u8 setauth_hdl(struct adapter *padapter, u8 *pbuf); -u8 setkey_hdl(struct adapter *padapter, u8 *pbuf); -u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf); -u8 set_assocsta_hdl(struct adapter *padapter, u8 *pbuf); -u8 del_assocsta_hdl(struct adapter *padapter, u8 *pbuf); -u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf); - -u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf); -u8 h2c_msg_hdl(struct adapter *padapter, unsigned char *pbuf); -u8 chk_bmc_sleepq_hdl(struct adapter *padapter, unsigned char *pbuf); -u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf); -u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf); -u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf); -u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf); /* Kurt: Handling DFS channel switch announcement ie. */ -u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf); -u8 run_in_thread_hdl(struct adapter *padapter, u8 *pbuf); - - -#define GEN_DRV_CMD_HANDLER(size, cmd) {size, &cmd ## _hdl}, -#define GEN_MLME_EXT_HANDLER(size, cmd) {size, cmd}, - -struct C2HEvent_Header { - -#ifdef __LITTLE_ENDIAN - - unsigned int len:16; - unsigned int ID:8; - unsigned int seq:8; -#else - unsigned int seq:8; - unsigned int ID:8; - unsigned int len:16; -#endif - unsigned int rsvd; -}; - -void rtw_dummy_event_callback(struct adapter *adapter, u8 *pbuf); -void rtw_fwdbg_event_callback(struct adapter *adapter, u8 *pbuf); - -enum { - READ_MACREG_EVENT = 0, /*0*/ - READ_BBREG_EVENT, - READ_RFREG_EVENT, - READ_EEPROM_EVENT, - READ_EFUSE_EVENT, - READ_CAM_EVENT, /*5*/ - GET_BASICRATE_EVENT, - GET_DATARATE_EVENT, - SURVEY_EVENT, /*8*/ - SURVEY_DONE_EVENT, /*9*/ - - JOIN_BSS_EVENT, /*10*/ - ADD_STA_EVENT, - DEL_STA_EVENT, - ATIM_DONE_EVENT, - TX_REPORT_EVENT, - CCX_REPORT_EVENT, /*15*/ - DTM_REPORT_EVENT, - TX_RATE_STATISTICS_EVENT, - C2HLBK_EVENT, - FWDBG_EVENT, - C2HFEEDBACK_EVENT, /*20*/ - ADDBA_EVENT, - C2HBCN_EVENT, - REPORT_PWR_STATE_EVENT, /* filen: only for PCIE, USB */ - CLOSE_RF_EVENT, /* filen: only for PCIE, work around ASPM */ - WMM_EVENT, /*25*/ - MAX_C2HEVT -}; - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtw_pwrctrl.h b/drivers/staging/rtl8723bs/include/rtw_pwrctrl.h deleted file mode 100644 index 182b8c88ccc8..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_pwrctrl.h +++ /dev/null @@ -1,254 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_PWRCTRL_H_ -#define __RTW_PWRCTRL_H_ - -#include - -#define XMIT_ALIVE BIT(0) -#define CMD_ALIVE BIT(2) -#define BTCOEX_ALIVE BIT(4) - - -enum { - PS_MODE_ACTIVE = 0, - PS_MODE_MIN, - PS_MODE_MAX, - PS_MODE_DTIM, /* PS_MODE_SELF_DEFINED */ - PS_MODE_VOIP, - PS_MODE_UAPSD_WMM, - PS_MODE_UAPSD, - PS_MODE_IBSS, - PS_MODE_WWLAN, - PM_Radio_Off, - PM_Card_Disable, - PS_MODE_NUM, -}; - -/* - BIT[2:0] = HW state - BIT[3] = Protocol PS state, 0: register active state , 1: register sleep state - BIT[4] = sub-state -*/ - -#define PS_DPS BIT(0) -#define PS_LCLK (PS_DPS) -#define PS_RF_OFF BIT(1) -#define PS_ALL_ON BIT(2) -#define PS_ST_ACTIVE BIT(3) - -#define PS_ACK BIT(6) -#define PS_TOGGLE BIT(7) - -#define PS_STATE_MASK (0x0F) - -#define PS_STATE(x) (PS_STATE_MASK & (x)) - -#define PS_STATE_S0 (PS_DPS) -#define PS_STATE_S2 (PS_RF_OFF) -#define PS_STATE_S4 ((PS_ST_ACTIVE) | (PS_ALL_ON)) - -struct reportpwrstate_parm { - unsigned char mode; - unsigned char state; /* the CPWM value */ - unsigned short rsvd; -}; - -#define LPS_DELAY_TIME (1 * HZ) /* 1 sec */ - -/* RF state. */ -enum rt_rf_power_state { - rf_on, /* RF is on after RFSleep or RFOff */ - rf_sleep, /* 802.11 Power Save mode */ - rf_off, /* HW/SW Radio OFF or Inactive Power Save */ - /* Add the new RF state above this line ===== */ - rf_max -}; - -/* RF Off Level for IPS or HW/SW radio off */ -#define RT_RF_OFF_LEVL_ASPM BIT(0) /* PCI ASPM */ -#define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /* PCI clock request */ -#define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /* PCI D3 mode */ -#define RT_RF_OFF_LEVL_HALT_NIC BIT(3) /* NIC halt, re-initialize hw parameters */ -#define RT_RF_OFF_LEVL_FREE_FW BIT(4) /* FW free, re-download the FW */ -#define RT_RF_OFF_LEVL_FW_32K BIT(5) /* FW in 32k */ -#define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6) /* Always enable ASPM and Clock Req in initialization. */ -#define RT_RF_LPS_DISALBE_2R BIT(30) /* When LPS is on, disable 2R if no packet is received or transmitted. */ -#define RT_RF_LPS_LEVEL_ASPM BIT(31) /* LPS with ASPM */ - -#define RT_IN_PS_LEVEL(ppsc, _PS_FLAG) ((ppsc->cur_ps_level & _PS_FLAG) ? true : false) -#define RT_CLEAR_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level &= (~(_PS_FLAG))) -#define RT_SET_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level |= _PS_FLAG) - -/* ASPM OSC Control bit, added by Roger, 2013.03.29. */ -#define RT_PCI_ASPM_OSC_IGNORE 0 /* PCI ASPM ignore OSC control in default */ -#define RT_PCI_ASPM_OSC_ENABLE BIT(0) /* PCI ASPM controlled by OS according to ACPI Spec 5.0 */ -#define RT_PCI_ASPM_OSC_DISABLE BIT(1) /* PCI ASPM controlled by driver or BIOS, i.e., force enable ASPM */ - -enum { - PSBBREG_RF0 = 0, - PSBBREG_RF1, - PSBBREG_RF2, - PSBBREG_AFE0, - PSBBREG_TOTALCNT -}; - -enum { /* for ips_mode */ - IPS_NONE = 0, - IPS_NORMAL, - IPS_LEVEL_2, - IPS_NUM -}; - -/* Design for pwrctrl_priv.ips_deny, 32 bits for 32 reasons at most */ -enum ps_deny_reason { - PS_DENY_DRV_INITIAL = 0, - PS_DENY_SCAN, - PS_DENY_JOIN, - PS_DENY_DISCONNECT, - PS_DENY_SUSPEND, - PS_DENY_IOCTL, - PS_DENY_MGNT_TX, - PS_DENY_DRV_REMOVE = 30, - PS_DENY_OTHERS = 31 -}; - -struct pwrctrl_priv { - struct mutex lock; - volatile u8 rpwm; /* requested power state for fw */ - volatile u8 cpwm; /* fw current power state. updated when 1. read from HCPWM 2. driver lowers power level */ - volatile u8 tog; /* toggling */ - volatile u8 cpwm_tog; /* toggling */ - - u8 pwr_mode; - u8 smart_ps; - u8 bcn_ant_mode; - u8 dtim; - - u32 alives; - struct work_struct cpwm_event; - u8 brpwmtimeout; - struct work_struct rpwmtimeoutwi; - struct timer_list pwr_rpwm_timer; - u8 bpower_saving; /* for LPS/IPS */ - - u8 b_hw_radio_off; - u8 reg_rfoff; - u8 reg_pdnmode; /* powerdown mode */ - u32 rfoff_reason; - - /* RF OFF Level */ - u32 cur_ps_level; - u32 reg_rfps_level; - - uint ips_enter_cnts; - uint ips_leave_cnts; - - u8 ips_mode; - u8 ips_org_mode; - u8 ips_mode_req; /* used to accept the mode setting request, will update to ipsmode later */ - bool bips_processing; - unsigned long ips_deny_time; /* will deny IPS when system time is smaller than this */ - u8 pre_ips_type;/* 0: default flow, 1: carddisbale flow */ - - /* ps_deny: if 0, power save is free to go; otherwise deny all kinds of power save. */ - /* Use enum ps_deny_reason to decide reason. */ - /* Don't access this variable directly without control function, */ - /* and this variable should be protected by lock. */ - u32 ps_deny; - - u8 ps_processing; /* temporarily used to mark whether in rtw_ps_processor */ - - u8 fw_psmode_iface_id; - u8 bLeisurePs; - u8 LpsIdleCount; - u8 power_mgnt; - u8 org_power_mgnt; - bool fw_current_in_ps_mode; - unsigned long delay_lps_last_time_stamp; - s32 pnp_current_pwr_state; - u8 pnp_bstop_trx; - - - u8 bInternalAutoSuspend; - u8 bInSuspend; - - u8 bAutoResume; - u8 autopm_cnt; - - u8 bSupportRemoteWakeup; - u8 wowlan_wake_reason; - u8 wowlan_ap_mode; - u8 wowlan_mode; - struct timer_list pwr_state_check_timer; - struct adapter *adapter; - int pwr_state_check_interval; - u8 pwr_state_check_cnts; - - int ps_flag; /* used by autosuspend */ - - enum rt_rf_power_state rf_pwrstate;/* cur power state, only for IPS */ - /* rt_rf_power_state current_rfpwrstate; */ - enum rt_rf_power_state change_rfpwrstate; - - u8 bHWPowerdown; /* power down mode selection. 0:radio off, 1:power down */ - u8 bHWPwrPindetect; /* come from registrypriv.hwpwrp_detect. enable power down function. 0:disable, 1:enable */ - u8 bkeepfwalive; - u8 brfoffbyhw; - unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT]; -}; - -#define rtw_ips_mode_req(pwrctl, ips_mode) \ - ((pwrctl)->ips_mode_req = (ips_mode)) - -#define RTW_PWR_STATE_CHK_INTERVAL 2000 - -#define _rtw_set_pwr_state_check_timer(pwrctl, ms) \ - do { \ - _set_timer(&(pwrctl)->pwr_state_check_timer, (ms)); \ - } while (0) - -extern void rtw_init_pwrctrl_priv(struct adapter *adapter); -extern void rtw_free_pwrctrl_priv(struct adapter *adapter); - -s32 rtw_register_task_alive(struct adapter *adapter, u32 task); -void rtw_unregister_task_alive(struct adapter *adapter, u32 task); -extern s32 rtw_register_tx_alive(struct adapter *padapter); -extern void rtw_unregister_tx_alive(struct adapter *padapter); -extern s32 rtw_register_cmd_alive(struct adapter *padapter); -extern void rtw_unregister_cmd_alive(struct adapter *padapter); -extern void cpwm_int_hdl(struct adapter *padapter, struct reportpwrstate_parm *preportpwrstate); -extern void LPS_Leave_check(struct adapter *padapter); - -extern void LeaveAllPowerSaveMode(struct adapter *Adapter); -extern void LeaveAllPowerSaveModeDirect(struct adapter *Adapter); -void _ips_enter(struct adapter *padapter); -void ips_enter(struct adapter *padapter); -int _ips_leave(struct adapter *padapter); -int ips_leave(struct adapter *padapter); - -void rtw_ps_processor(struct adapter *padapter); - -int LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms); -void LPS_Enter(struct adapter *padapter, const char *msg); -void LPS_Leave(struct adapter *padapter, const char *msg); -void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets); -void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode, const char *msg); -void rtw_set_rpwm(struct adapter *padapter, u8 val8); - -void rtw_set_ips_deny(struct adapter *padapter, u32 ms); -int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *caller); -#define rtw_pwr_wakeup(adapter) _rtw_pwr_wakeup(adapter, RTW_PWR_STATE_CHK_INTERVAL, __func__) -#define rtw_pwr_wakeup_ex(adapter, ips_deffer_ms) _rtw_pwr_wakeup(adapter, ips_deffer_ms, __func__) -int rtw_pm_set_ips(struct adapter *padapter, u8 mode); -int rtw_pm_set_lps(struct adapter *padapter, u8 mode); - -void rtw_ps_deny(struct adapter *padapter, enum ps_deny_reason reason); -void rtw_ps_deny_cancel(struct adapter *padapter, enum ps_deny_reason reason); -u32 rtw_ps_deny_get(struct adapter *padapter); - -#endif /* __RTL871X_PWRCTRL_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_qos.h b/drivers/staging/rtl8723bs/include/rtw_qos.h deleted file mode 100644 index 733bfacef0b9..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_qos.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#ifndef _RTW_QOS_H_ -#define _RTW_QOS_H_ - -struct qos_priv { - unsigned int qos_option; /* bit mask option: u-apsd, s-apsd, ts, block ack... */ -}; - -#endif /* _RTL871X_QOS_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_recv.h b/drivers/staging/rtl8723bs/include/rtw_recv.h deleted file mode 100644 index 9c32d480a20a..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_recv.h +++ /dev/null @@ -1,457 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _RTW_RECV_H_ -#define _RTW_RECV_H_ - -#define NR_RECVBUFF (8) - -#define NR_RECVFRAME 256 - -#define RXFRAME_ALIGN 8 -#define RXFRAME_ALIGN_SZ (1<network.PhyInfo.SignalStrength); */ - /* s8 rxpwdb; */ - s16 noise; - /* int RxSNRdB[2]; */ - /* s8 RxRssi[2]; */ - /* int FalseAlmCnt_all; */ - - - struct timer_list signal_stat_timer; - u32 signal_stat_sampling_interval; - /* u32 signal_stat_converging_constant; */ - struct signal_stat signal_qual_data; - struct signal_stat signal_strength_data; -}; - -#define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval) - -struct sta_recv_priv { - - spinlock_t lock; - signed int option; - - /* struct __queue blk_strms[MAX_RX_NUMBLKS]; */ - struct __queue defrag_q; /* keeping the fragment frame until defrag */ - - struct stainfo_rxcache rxcache; - - /* uint sta_rx_bytes; */ - /* uint sta_rx_pkts; */ - /* uint sta_rx_fail; */ - -}; - - -struct recv_buf { - struct list_head list; - - spinlock_t recvbuf_lock; - - u32 ref_cnt; - - struct adapter *adapter; - - u8 *pbuf; - u8 *pallocated_buf; - - u32 len; - u8 *phead; - u8 *pdata; - u8 *ptail; - u8 *pend; - - struct sk_buff *pskb; - u8 reuse; -}; - - -/* - head -----> - - data -----> - - payload - - tail -----> - - - end -----> - - len = (unsigned int)(tail - data); - -*/ -struct recv_frame_hdr { - struct list_head list; - struct sk_buff *pkt; - struct sk_buff *pkt_newalloc; - - struct adapter *adapter; - - u8 fragcnt; - - int frame_tag; - - struct rx_pkt_attrib attrib; - - uint len; - u8 *rx_head; - u8 *rx_data; - u8 *rx_tail; - u8 *rx_end; - - void *precvbuf; - - - /* */ - struct sta_info *psta; - - /* for A-MPDU Rx reordering buffer control */ - struct recv_reorder_ctrl *preorder_ctrl; -}; - - -union recv_frame { - union{ - struct list_head list; - struct recv_frame_hdr hdr; - uint mem[RECVFRAME_HDR_ALIGN>>2]; - } u; - - /* uint mem[MAX_RXSZ>>2]; */ - -}; - -enum { - NORMAL_RX,/* Normal rx packet */ - TX_REPORT1,/* CCX */ - TX_REPORT2,/* TX RPT */ - HIS_REPORT,/* USB HISR RPT */ - C2H_PACKET -}; - -extern union recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ -extern union recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ -extern int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue); - -extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue); -extern int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue); - -extern void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue); -u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter); - -signed int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue); -signed int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue); -struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue); - -void rtw_reordering_ctrl_timeout_handler(struct timer_list *t); - -signed int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter); -void _rtw_free_recv_priv(struct recv_priv *precvpriv); -s32 rtw_recv_entry(union recv_frame *precv_frame); - -static inline u8 *get_rxmem(union recv_frame *precvframe) -{ - /* always return rx_head... */ - if (!precvframe) - return NULL; - - return precvframe->u.hdr.rx_head; -} - -static inline u8 *recvframe_pull(union recv_frame *precvframe, signed int sz) -{ - /* rx_data += sz; move rx_data sz bytes hereafter */ - - /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */ - - - if (!precvframe) - return NULL; - - - precvframe->u.hdr.rx_data += sz; - - if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) { - precvframe->u.hdr.rx_data -= sz; - return NULL; - } - - precvframe->u.hdr.len -= sz; - - return precvframe->u.hdr.rx_data; - -} - -static inline u8 *recvframe_put(union recv_frame *precvframe, signed int sz) -{ - /* rx_tai += sz; move rx_tail sz bytes hereafter */ - - /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */ - /* after putting, rx_tail must be still larger than rx_end. */ - unsigned char *prev_rx_tail; - - if (!precvframe) - return NULL; - - prev_rx_tail = precvframe->u.hdr.rx_tail; - - precvframe->u.hdr.rx_tail += sz; - - if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) { - precvframe->u.hdr.rx_tail = prev_rx_tail; - return NULL; - } - - precvframe->u.hdr.len += sz; - - return precvframe->u.hdr.rx_tail; - -} - - - -static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, signed int sz) -{ - /* rmv data from rx_tail (by yitsen) */ - - /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */ - /* after pulling, rx_end must be still larger than rx_data. */ - - if (!precvframe) - return NULL; - - precvframe->u.hdr.rx_tail -= sz; - - if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) { - precvframe->u.hdr.rx_tail += sz; - return NULL; - } - - precvframe->u.hdr.len -= sz; - - return precvframe->u.hdr.rx_tail; - -} - -static inline signed int get_recvframe_len(union recv_frame *precvframe) -{ - return precvframe->u.hdr.len; -} - - -static inline s32 translate_percentage_to_dbm(u32 SignalStrengthIndex) -{ - s32 SignalPower; /* in dBm. */ - - /* Translate to dBm (x = 0.5y-95). */ - SignalPower = (s32)((SignalStrengthIndex + 1) >> 1); - SignalPower -= 95; - - return SignalPower; -} - - -struct sta_info; - -extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv); - -extern void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtw_rf.h b/drivers/staging/rtl8723bs/include/rtw_rf.h deleted file mode 100644 index 9f98b3f5a2e3..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_rf.h +++ /dev/null @@ -1,100 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_RF_H_ -#define __RTW_RF_H_ - - -#define OFDM_PHY 1 -#define MIXED_PHY 2 -#define CCK_PHY 3 - -#define NumRates 13 - -/* slot time for 11g */ -#define SHORT_SLOT_TIME 9 -#define NON_SHORT_SLOT_TIME 20 - -#define RTL8711_RF_MAX_SENS 6 -#define RTL8711_RF_DEF_SENS 4 - -/* - * We now define the following channels as the max channels in each channel plan. - * 2G, total 14 chnls - * {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14} - */ -#define MAX_CHANNEL_NUM_2G 14 -#define MAX_CHANNEL_NUM 14 - -#define NUM_REGULATORYS 1 - -/* Country codes */ -#define USA 0x555320 -#define EUROPE 0x1 /* temp, should be provided later */ -#define JAPAN 0x2 /* temp, should be provided later */ - -struct regulatory_class { - u32 starting_freq; /* MHz, */ - u8 channel_set[MAX_CHANNEL_NUM]; - u8 channel_cck_power[MAX_CHANNEL_NUM];/* dbm */ - u8 channel_ofdm_power[MAX_CHANNEL_NUM];/* dbm */ - u8 txpower_limit; /* dbm */ - u8 channel_spacing; /* MHz */ - u8 modem; -}; - -enum { - cESS = 0x0001, - cIBSS = 0x0002, - cPollable = 0x0004, - cPollReq = 0x0008, - cPrivacy = 0x0010, - cShortPreamble = 0x0020, - cPBCC = 0x0040, - cChannelAgility = 0x0080, - cSpectrumMgnt = 0x0100, - cQos = 0x0200, /* For HCCA, use with CF-Pollable and CF-PollReq */ - cShortSlotTime = 0x0400, - cAPSD = 0x0800, - cRM = 0x1000, /* RRM (Radio Request Measurement) */ - cDSSS_OFDM = 0x2000, - cDelayedBA = 0x4000, - cImmediateBA = 0x8000, -}; - -enum { - PREAMBLE_LONG = 1, - PREAMBLE_AUTO = 2, - PREAMBLE_SHORT = 3, -}; - -/* Bandwidth Offset */ -#define HAL_PRIME_CHNL_OFFSET_DONT_CARE 0 -#define HAL_PRIME_CHNL_OFFSET_LOWER 1 -#define HAL_PRIME_CHNL_OFFSET_UPPER 2 - -/* Represent Channel Width in HT Capabilities */ -enum channel_width { - CHANNEL_WIDTH_20 = 0, - CHANNEL_WIDTH_40 = 1, -}; - -/* Represent Extension Channel Offset in HT Capabilities */ -/* This is available only in 40Mhz mode. */ -enum extchnl_offset { - EXTCHNL_OFFSET_NO_EXT = 0, - EXTCHNL_OFFSET_UPPER = 1, - EXTCHNL_OFFSET_NO_DEF = 2, - EXTCHNL_OFFSET_LOWER = 3, -}; - -enum { - HT_DATA_SC_DONOT_CARE = 0, - HT_DATA_SC_20_UPPER_OF_40MHZ = 1, - HT_DATA_SC_20_LOWER_OF_40MHZ = 2, -}; - -#endif /* _RTL8711_RF_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_security.h b/drivers/staging/rtl8723bs/include/rtw_security.h deleted file mode 100644 index a3bbc605e2ba..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_security.h +++ /dev/null @@ -1,272 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __RTW_SECURITY_H_ -#define __RTW_SECURITY_H_ - -#include - -#define _NO_PRIVACY_ 0x0 -#define _WEP40_ 0x1 -#define _TKIP_ 0x2 -#define _TKIP_WTMIC_ 0x3 -#define _AES_ 0x4 -#define _WEP104_ 0x5 -#define _WEP_WPA_MIXED_ 0x07 /* WEP + WPA */ -#define _SMS4_ 0x06 -#define _BIP_ 0x8 -#define is_wep_enc(alg) (((alg) == _WEP40_) || ((alg) == _WEP104_)) - -const char *security_type_str(u8 value); - -#define AES_BLOCK_SIZE 16 -#define AES_PRIV_SIZE (4 * 44) - -enum { - ENCRYP_PROTOCOL_OPENSYS, /* open system */ - ENCRYP_PROTOCOL_WEP, /* WEP */ - ENCRYP_PROTOCOL_WPA, /* WPA */ - ENCRYP_PROTOCOL_WPA2, /* WPA2 */ - ENCRYP_PROTOCOL_WAPI, /* WAPI: Not support in this version */ - ENCRYP_PROTOCOL_MAX -}; - - -#ifndef Ndis802_11AuthModeWPA2 -#define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1) -#endif - -#ifndef Ndis802_11AuthModeWPA2PSK -#define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2) -#endif - -union pn48 { - - u64 val; - -#ifdef __LITTLE_ENDIAN - -struct { - u8 TSC0; - u8 TSC1; - u8 TSC2; - u8 TSC3; - u8 TSC4; - u8 TSC5; - u8 TSC6; - u8 TSC7; -} _byte_; -#else -struct { - u8 TSC7; - u8 TSC6; - u8 TSC5; - u8 TSC4; - u8 TSC3; - u8 TSC2; - u8 TSC1; - u8 TSC0; -} _byte_; -#endif - -}; - -union Keytype { - u8 skey[16]; - u32 lkey[4]; -}; - - -struct rt_pmkid_list { - u8 bUsed; - u8 Bssid[6]; - u8 PMKID[16]; - u8 SsidBuf[33]; - u8 *ssid_octet; - u16 ssid_length; -}; - - -struct security_priv { - u32 dot11_auth_algrthm; /* 802.11 auth, could be open, shared, 8021x and authswitch */ - u32 dot11_privacy_algrthm; /* This specify the privacy for shared auth. algorithm. */ - - /* WEP */ - u32 dot11PrivacyKeyIndex; /* this is only valid for legendary wep, 0~3 for key id. (tx key index) */ - union Keytype dot11DefKey[4]; /* this is only valid for def. key */ - u32 dot11DefKeylen[4]; - u8 key_mask; /* use to restore wep key after hal_init */ - - u32 dot118021XGrpPrivacy; /* This specify the privacy algthm. used for Grp key */ - u32 dot118021XGrpKeyid; /* key id used for Grp Key (tx key index) */ - union Keytype dot118021XGrpKey[BIP_MAX_KEYID + 1]; /* 802.1x Group Key, for inx0 and inx1 */ - union Keytype dot118021XGrptxmickey[BIP_MAX_KEYID + 1]; - union Keytype dot118021XGrprxmickey[BIP_MAX_KEYID + 1]; - union pn48 dot11Grptxpn; /* PN48 used for Grp Key xmit. */ - union pn48 dot11Grprxpn; /* PN48 used for Grp Key recv. */ - u32 dot11wBIPKeyid; /* key id used for BIP Key (tx key index) */ - union Keytype dot11wBIPKey[BIP_MAX_KEYID + 1]; /* BIP Key, for index4 and index5 */ - union pn48 dot11wBIPtxpn; /* PN48 used for Grp Key xmit. */ - union pn48 dot11wBIPrxpn; /* PN48 used for Grp Key recv. */ - - /* extend security capabilities for AP_MODE */ - unsigned int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */ - unsigned int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */ - unsigned int wpa_group_cipher; - unsigned int wpa2_group_cipher; - unsigned int wpa_pairwise_cipher; - unsigned int wpa2_pairwise_cipher; - - u8 wps_ie[MAX_WPS_IE_LEN];/* added in assoc req */ - int wps_ie_len; - - struct arc4_ctx xmit_arc4_ctx; - struct arc4_ctx recv_arc4_ctx; - - u8 binstallGrpkey; - u8 binstallBIPkey; - u8 busetkipkey; - /* _timer tkip_timer; */ - u8 bcheck_grpkey; - u8 bgrpkey_handshake; - - s32 sw_encrypt;/* from registry_priv */ - s32 sw_decrypt;/* from registry_priv */ - - s32 hw_decrypted;/* if the rx packets is hw_decrypted ==false, it means the hw has not been ready. */ - - - /* keeps the auth_type & enc_status from upper layer ioctl(wpa_supplicant or wzc) */ - u32 ndisauthtype; /* enum ndis_802_11_authentication_mode */ - u32 ndisencryptstatus; /* NDIS_802_11_ENCRYPTION_STATUS */ - - struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */ - - struct ndis_802_11_wep ndiswep; - - u8 assoc_info[600]; - u8 szofcapability[256]; /* for wpa2 usage */ - u8 oidassociation[512]; /* for wpa/wpa2 usage */ - u8 authenticator_ie[256]; /* store ap security information element */ - u8 supplicant_ie[256]; /* store sta security information element */ - - - /* for tkip countermeasure */ - unsigned long last_mic_err_time; - u8 btkip_countermeasure; - u8 btkip_wait_report; - u32 btkip_countermeasure_time; - - /* For WPA2 Pre-Authentication. */ - struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE]; /* Renamed from PreAuthKey[NUM_PRE_AUTH_KEY]. Annie, 2006-10-13. */ - u8 PMKIDIndex; - - u8 bWepDefaultKeyIdxSet; - -}; - -#define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst)\ -do {\ - switch (psecuritypriv->dot11_auth_algrthm) {\ - case dot11_auth_algrthm_open:\ - case dot11_auth_algrthm_shared:\ - case dot11_auth_algrthm_auto:\ - encry_algo = (u8)psecuritypriv->dot11_privacy_algrthm;\ - break;\ - case dot11_auth_algrthm_8021x:\ - if (bmcst)\ - encry_algo = (u8)psecuritypriv->dot118021XGrpPrivacy;\ - else\ - encry_algo = (u8)psta->dot118021XPrivacy;\ - break;\ - case dot11_auth_algrthm_wapi:\ - encry_algo = (u8)psecuritypriv->dot11_privacy_algrthm;\ - break;\ - } \ -} while (0) - -#define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\ -do {\ - switch (encrypt) {\ - case _WEP40_:\ - case _WEP104_:\ - iv_len = 4;\ - icv_len = 4;\ - break;\ - case _TKIP_:\ - iv_len = 8;\ - icv_len = 4;\ - break;\ - case _AES_:\ - iv_len = 8;\ - icv_len = 8;\ - break;\ - case _SMS4_:\ - iv_len = 18;\ - icv_len = 16;\ - break;\ - default:\ - iv_len = 0;\ - icv_len = 0;\ - break;\ - } \ -} while (0) - - -#define GET_TKIP_PN(iv, dot11txpn)\ -do {\ - dot11txpn._byte_.TSC0 = iv[2];\ - dot11txpn._byte_.TSC1 = iv[0];\ - dot11txpn._byte_.TSC2 = iv[4];\ - dot11txpn._byte_.TSC3 = iv[5];\ - dot11txpn._byte_.TSC4 = iv[6];\ - dot11txpn._byte_.TSC5 = iv[7];\ -} while (0) - - -#define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1))) -#define ROR32(A, n) ROL32((A), 32-(n)) - -struct mic_data { - u32 K0, K1; /* Key */ - u32 L, R; /* Current state */ - u32 M; /* Message accumulator (single word) */ - u32 nBytesInM; /* # bytes in M */ -}; - -/* ===== start - public domain SHA256 implementation ===== */ - -/* This is based on SHA256 implementation in LibTomCrypt that was released into - * public domain by Tom St Denis. - */ - -int omac1_aes_128(u8 *key, u8 *data, size_t data_len, u8 *mac); -void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key); -void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b); -void rtw_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes); -void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst); - -void rtw_seccalctkipmic( - u8 *key, - u8 *header, - u8 *data, - u32 data_len, - u8 *Miccode, - u8 priority); - -u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe); -u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe); -void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe); - -u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe); -u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe); -void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe); -u32 rtw_BIP_verify(struct adapter *padapter, u8 *precvframe); - -void rtw_sec_restore_wep_key(struct adapter *adapter); -u8 rtw_handle_tkip_countermeasure(struct adapter *adapter, const char *caller); - -#endif /* __RTL871X_SECURITY_H_ */ diff --git a/drivers/staging/rtl8723bs/include/rtw_version.h b/drivers/staging/rtl8723bs/include/rtw_version.h deleted file mode 100644 index 55e907b097ae..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_version.h +++ /dev/null @@ -1,3 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#define DRIVERVERSION "v4.3.5.5_12290.20140916_BTCOEX20140507-4E40" -#define BTCOEXVERSION "BTCOEX20140507-4E40" diff --git a/drivers/staging/rtl8723bs/include/rtw_wifi_regd.h b/drivers/staging/rtl8723bs/include/rtw_wifi_regd.h deleted file mode 100644 index e4d8fe9bf68d..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_wifi_regd.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2009-2010 Realtek Corporation. - * - *****************************************************************************/ - -#ifndef __RTW_WIFI_REGD_H__ -#define __RTW_WIFI_REGD_H__ - -void rtw_regd_init(struct wiphy *wiphy, - void (*reg_notifier)(struct wiphy *wiphy, - struct regulatory_request *request)); -void rtw_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request); - -#endif diff --git a/drivers/staging/rtl8723bs/include/rtw_xmit.h b/drivers/staging/rtl8723bs/include/rtw_xmit.h deleted file mode 100644 index 917e846e9ce2..000000000000 --- a/drivers/staging/rtl8723bs/include/rtw_xmit.h +++ /dev/null @@ -1,470 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _RTW_XMIT_H_ -#define _RTW_XMIT_H_ - -#include - -#define MAX_XMITBUF_SZ (20480) /* 20k */ - -#define NR_XMITBUFF (16) - -#define XMITBUF_ALIGN_SZ 512 - -/* xmit extension buff definition */ -#define MAX_XMIT_EXTBUF_SZ (1536) -#define NR_XMIT_EXTBUFF (32) - -#define MAX_CMDBUF_SZ (5120) /* 4096) */ - -#define MAX_NUMBLKS (1) - -#define XMIT_VO_QUEUE (0) -#define XMIT_VI_QUEUE (1) -#define XMIT_BE_QUEUE (2) -#define XMIT_BK_QUEUE (3) - -#define VO_QUEUE_INX 0 -#define VI_QUEUE_INX 1 -#define BE_QUEUE_INX 2 -#define BK_QUEUE_INX 3 -#define BCN_QUEUE_INX 4 -#define MGT_QUEUE_INX 5 -#define HIGH_QUEUE_INX 6 - -#define HW_QUEUE_ENTRY 8 - -#define WEP_IV(pattrib_iv, dot11txpn, keyidx)\ -do {\ - pattrib_iv[0] = dot11txpn._byte_.TSC0;\ - pattrib_iv[1] = dot11txpn._byte_.TSC1;\ - pattrib_iv[2] = dot11txpn._byte_.TSC2;\ - pattrib_iv[3] = ((keyidx & 0x3)<<6);\ - dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0 : (dot11txpn.val + 1);\ -} while (0) - - -#define TKIP_IV(pattrib_iv, dot11txpn, keyidx)\ -do {\ - pattrib_iv[0] = dot11txpn._byte_.TSC1;\ - pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f;\ - pattrib_iv[2] = dot11txpn._byte_.TSC0;\ - pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\ - pattrib_iv[4] = dot11txpn._byte_.TSC2;\ - pattrib_iv[5] = dot11txpn._byte_.TSC3;\ - pattrib_iv[6] = dot11txpn._byte_.TSC4;\ - pattrib_iv[7] = dot11txpn._byte_.TSC5;\ - dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : (dot11txpn.val + 1);\ -} while (0) - -#define AES_IV(pattrib_iv, dot11txpn, keyidx)\ -do {\ - pattrib_iv[0] = dot11txpn._byte_.TSC0;\ - pattrib_iv[1] = dot11txpn._byte_.TSC1;\ - pattrib_iv[2] = 0;\ - pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\ - pattrib_iv[4] = dot11txpn._byte_.TSC2;\ - pattrib_iv[5] = dot11txpn._byte_.TSC3;\ - pattrib_iv[6] = dot11txpn._byte_.TSC4;\ - pattrib_iv[7] = dot11txpn._byte_.TSC5;\ - dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : (dot11txpn.val + 1);\ -} while (0) - - -#define HWXMIT_ENTRY 4 - -/* For Buffer Descriptor ring architecture */ -#define TXDESC_SIZE 40 - -#define TXDESC_OFFSET TXDESC_SIZE - -#define TXDESC_40_BYTES - -struct tx_desc { - __le32 txdw0; - __le32 txdw1; - __le32 txdw2; - __le32 txdw3; - __le32 txdw4; - __le32 txdw5; - __le32 txdw6; - __le32 txdw7; - -#ifdef TXDESC_40_BYTES - __le32 txdw8; - __le32 txdw9; -#endif -}; - -union txdesc { - struct tx_desc txdesc; - unsigned int value[TXDESC_SIZE>>2]; -}; - -struct hw_xmit { - /* spinlock_t xmit_lock; */ - /* struct list_head pending; */ - struct __queue *sta_queue; - /* struct hw_txqueue *phwtxqueue; */ - /* signed int txcmdcnt; */ - int accnt; -}; - -/* reduce size */ -struct pkt_attrib { - u8 type; - u8 subtype; - u8 bswenc; - u8 dhcp_pkt; - u16 ether_type; - u16 seqnum; - u16 pkt_hdrlen; /* the original 802.3 pkt header len */ - u16 hdrlen; /* the WLAN Header Len */ - u32 pktlen; /* the original 802.3 pkt raw_data len (not include ether_hdr data) */ - u32 last_txcmdsz; - u8 nr_frags; - u8 encrypt; /* when 0 indicates no encryption; when non-zero, indicates the encryption algorithm */ - u8 iv_len; - u8 icv_len; - u8 iv[18]; - u8 icv[16]; - u8 priority; - u8 ack_policy; - u8 mac_id; - u8 vcs_mode; /* virtual carrier sense method */ - u8 dst[ETH_ALEN]; - u8 src[ETH_ALEN]; - u8 ta[ETH_ALEN]; - u8 ra[ETH_ALEN]; - u8 key_idx; - u8 qos_en; - u8 ht_en; - u8 raid;/* rate adpative id */ - u8 bwmode; - u8 ch_offset;/* PRIME_CHNL_OFFSET */ - u8 sgi;/* short GI */ - u8 ampdu_en;/* tx ampdu enable */ - u8 ampdu_spacing; /* ampdu_min_spacing for peer sta's rx */ - u8 mdata;/* more data bit */ - u8 pctrl;/* per packet txdesc control enable */ - u8 triggered;/* for ap mode handling Power Saving sta */ - u8 qsel; - u8 order;/* order bit */ - u8 eosp; - u8 rate; - u8 intel_proxim; - u8 retry_ctrl; - u8 mbssid; - u8 ldpc; - u8 stbc; - struct sta_info *psta; - - u8 rtsen; - u8 cts2self; - union Keytype dot11tkiptxmickey; - /* union Keytype dot11tkiprxmickey; */ - union Keytype dot118021x_UncstKey; - - u8 icmp_pkt; - -}; - -#define WLANHDR_OFFSET 64 - -#define NULL_FRAMETAG (0x0) -#define DATA_FRAMETAG 0x01 -#define MGNT_FRAMETAG 0x03 - -enum { - XMITBUF_DATA = 0, - XMITBUF_MGNT = 1, - XMITBUF_CMD = 2, -}; - -struct submit_ctx { - unsigned long submit_time; /* */ - u32 timeout_ms; /* <0: not synchronous, 0: wait forever, >0: up to ms waiting */ - int status; /* status for operation */ - struct completion done; -}; - -enum { - RTW_SCTX_SUBMITTED = -1, - RTW_SCTX_DONE_SUCCESS = 0, - RTW_SCTX_DONE_UNKNOWN, - RTW_SCTX_DONE_TIMEOUT, - RTW_SCTX_DONE_BUF_ALLOC, - RTW_SCTX_DONE_BUF_FREE, - RTW_SCTX_DONE_WRITE_PORT_ERR, - RTW_SCTX_DONE_TX_DESC_NA, - RTW_SCTX_DONE_TX_DENY, - RTW_SCTX_DONE_CCX_PKT_FAIL, - RTW_SCTX_DONE_DRV_STOP, - RTW_SCTX_DONE_DEV_REMOVE, - RTW_SCTX_DONE_CMD_ERROR, -}; - - -void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms); -int rtw_sctx_wait(struct submit_ctx *sctx); -void rtw_sctx_done_err(struct submit_ctx **sctx, int status); -void rtw_sctx_done(struct submit_ctx **sctx); - -struct xmit_buf { - struct list_head list; - - struct adapter *padapter; - - u8 *pallocated_buf; - - u8 *pbuf; - - void *priv_data; - - u16 buf_tag; /* 0: Normal xmitbuf, 1: extension xmitbuf, 2:cmd xmitbuf */ - u16 flags; - u32 alloc_sz; - - u32 len; - - struct submit_ctx *sctx; - - u8 *phead; - u8 *pdata; - u8 *ptail; - u8 *pend; - u32 ff_hwaddr; - u8 pg_num; - u8 agg_num; -}; - - -struct xmit_frame { - struct list_head list; - - struct pkt_attrib attrib; - - struct sk_buff *pkt; - - int frame_tag; - - struct adapter *padapter; - - u8 *buf_addr; - - struct xmit_buf *pxmitbuf; - - u8 pg_num; - u8 agg_num; - - u8 ack_report; - - u8 *alloc_addr; /* the actual address this xmitframe allocated */ - u8 ext_tag; /* 0:data, 1:mgmt */ - -}; - -struct tx_servq { - struct list_head tx_pending; - struct __queue sta_pending; - int qcnt; -}; - - -struct sta_xmit_priv { - spinlock_t lock; - signed int option; - signed int apsd_setting; /* When bit mask is on, the associated edca queue supports APSD. */ - - - /* struct tx_servq blk_q[MAX_NUMBLKS]; */ - struct tx_servq be_q; /* priority == 0, 3 */ - struct tx_servq bk_q; /* priority == 1, 2 */ - struct tx_servq vi_q; /* priority == 4, 5 */ - struct tx_servq vo_q; /* priority == 6, 7 */ - struct list_head legacy_dz; - struct list_head apsd; - - u16 txseq_tid[16]; - - /* uint sta_tx_bytes; */ - /* u64 sta_tx_pkts; */ - /* uint sta_tx_fail; */ - - -}; - - -struct hw_txqueue { - volatile signed int head; - volatile signed int tail; - volatile signed int free_sz; /* in units of 64 bytes */ - volatile signed int free_cmdsz; - volatile signed int txsz[8]; - uint ff_hwaddr; - uint cmd_hwaddr; - signed int ac_tag; -}; - -enum cmdbuf_type { - CMDBUF_BEACON = 0x00, - CMDBUF_RSVD, - CMDBUF_MAX -}; - -struct xmit_priv { - - spinlock_t lock; - - struct completion xmit_comp; - struct completion terminate_xmitthread_comp; - - /* struct __queue blk_strms[MAX_NUMBLKS]; */ - struct __queue be_pending; - struct __queue bk_pending; - struct __queue vi_pending; - struct __queue vo_pending; - struct __queue bm_pending; - - /* struct __queue legacy_dz_queue; */ - /* struct __queue apsd_queue; */ - - u8 *pallocated_frame_buf; - u8 *pxmit_frame_buf; - uint free_xmitframe_cnt; - struct __queue free_xmit_queue; - - /* uint mapping_addr; */ - /* uint pkt_sz; */ - - u8 *xframe_ext_alloc_addr; - u8 *xframe_ext; - uint free_xframe_ext_cnt; - struct __queue free_xframe_ext_queue; - - /* struct hw_txqueue be_txqueue; */ - /* struct hw_txqueue bk_txqueue; */ - /* struct hw_txqueue vi_txqueue; */ - /* struct hw_txqueue vo_txqueue; */ - /* struct hw_txqueue bmc_txqueue; */ - - uint frag_len; - - struct adapter *adapter; - - u8 vcs_setting; - u8 vcs; - u8 vcs_type; - /* u16 rts_thresh; */ - - u64 tx_bytes; - u64 tx_pkts; - u64 tx_drop; - u64 last_tx_pkts; - - struct hw_xmit *hwxmits; - u8 hwxmit_entry; - - u8 wmm_para_seq[4];/* sequence for wmm ac parameter strength from large to small. it's value is 0->vo, 1->vi, 2->be, 3->bk. */ - - void *SdioXmitThread; - struct completion SdioXmitStart; - struct completion SdioXmitTerminate; - - struct __queue free_xmitbuf_queue; - struct __queue pending_xmitbuf_queue; - u8 *pallocated_xmitbuf; - u8 *pxmitbuf; - uint free_xmitbuf_cnt; - - struct __queue free_xmit_extbuf_queue; - u8 *pallocated_xmit_extbuf; - u8 *pxmit_extbuf; - uint free_xmit_extbuf_cnt; - - struct xmit_buf pcmd_xmitbuf[CMDBUF_MAX]; - - u16 nqos_ssn; - - int ack_tx; - struct mutex ack_tx_mutex; - struct submit_ctx ack_tx_ops; - u8 seq_no; - spinlock_t lock_sctx; -}; - -extern struct xmit_frame *__rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv, - enum cmdbuf_type buf_type); -#define rtw_alloc_cmdxmitframe(p) __rtw_alloc_cmdxmitframe(p, CMDBUF_RSVD) -#define rtw_alloc_bcnxmitframe(p) __rtw_alloc_cmdxmitframe(p, CMDBUF_BEACON) - -extern struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv); -extern s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); - -extern struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv); -extern s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); - -void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz); -extern void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len); -extern int rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib); -extern s32 rtw_put_snap(u8 *data, u16 h_proto); - -extern struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv); -struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv); -struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv); -extern s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe); -extern void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue); -struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, signed int up, u8 *ac); -int rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe); - -extern u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib); -#define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue(&f->attrib) -extern int rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe); -extern s32 rtw_mgmt_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe); -s32 _rtw_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag); -void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv); - - -s32 rtw_txframes_pending(struct adapter *padapter); -void rtw_init_hwxmits(struct hw_xmit *phwxmit, signed int entry); - - -s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter); -void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv); - - -void rtw_free_hwxmits(struct adapter *padapter); - - -s32 rtw_xmit(struct adapter *padapter, struct sk_buff **pkt); -bool xmitframe_hiq_filter(struct xmit_frame *xmitframe); - -signed int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe); -void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta); -void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta); -void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta); - -u8 query_ra_short_GI(struct sta_info *psta); - -u8 qos_acm(u8 acm_mask, u8 priority); - -void enqueue_pending_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); -void enqueue_pending_xmitbuf_to_head(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); -struct xmit_buf *dequeue_pending_xmitbuf(struct xmit_priv *pxmitpriv); -struct xmit_buf *dequeue_pending_xmitbuf_under_survey(struct xmit_priv *pxmitpriv); -signed int check_pending_xmitbuf(struct xmit_priv *pxmitpriv); -int rtw_xmit_thread(void *context); - -u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe); - -int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms); -void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status); - -/* include after declaring struct xmit_buf, in order to avoid warning */ -#include - -#endif /* _RTL871X_XMIT_H_ */ diff --git a/drivers/staging/rtl8723bs/include/sdio_hal.h b/drivers/staging/rtl8723bs/include/sdio_hal.h deleted file mode 100644 index 6538253765f1..000000000000 --- a/drivers/staging/rtl8723bs/include/sdio_hal.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __SDIO_HAL_H__ -#define __SDIO_HAL_H__ - -u8 sd_int_isr(struct adapter *padapter); -void sd_int_dpc(struct adapter *padapter); -void rtw_set_hal_ops(struct adapter *padapter); - -#endif /* __SDIO_HAL_H__ */ diff --git a/drivers/staging/rtl8723bs/include/sdio_ops.h b/drivers/staging/rtl8723bs/include/sdio_ops.h deleted file mode 100644 index 252b0e1646e5..000000000000 --- a/drivers/staging/rtl8723bs/include/sdio_ops.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __SDIO_OPS_H__ -#define __SDIO_OPS_H__ - - -#include - -extern void sdio_set_intf_ops(struct adapter *padapter, struct _io_ops *pops); - -/* extern void sdio_func1cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem); */ -/* extern void sdio_func1cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem); */ -extern u8 SdioLocalCmd52Read1Byte(struct adapter *padapter, u32 addr); -extern void SdioLocalCmd52Write1Byte(struct adapter *padapter, u32 addr, u8 v); -extern s32 sdio_local_read(struct adapter *padapter, u32 addr, u32 cnt, u8 *pbuf); -extern s32 sdio_local_write(struct adapter *padapter, u32 addr, u32 cnt, u8 *pbuf); - -u32 _sdio_read32(struct adapter *padapter, u32 addr); -s32 _sdio_write32(struct adapter *padapter, u32 addr, u32 val); - -extern void sd_int_hdl(struct adapter *padapter); -extern u8 CheckIPSStatus(struct adapter *padapter); - -extern void InitInterrupt8723BSdio(struct adapter *padapter); -void rtw_sdio_enable_interrupt(struct adapter *padapter); -void rtw_sdio_disable_interrupt(struct adapter *padapter); -extern u8 HalQueryTxBufferStatus8723BSdio(struct adapter *padapter); -extern void HalQueryTxOQTBufferStatus8723BSdio(struct adapter *padapter); -#endif /* !__SDIO_OPS_H__ */ diff --git a/drivers/staging/rtl8723bs/include/sdio_ops_linux.h b/drivers/staging/rtl8723bs/include/sdio_ops_linux.h deleted file mode 100644 index cd67a7201065..000000000000 --- a/drivers/staging/rtl8723bs/include/sdio_ops_linux.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __SDIO_OPS_LINUX_H__ -#define __SDIO_OPS_LINUX_H__ - -#define SDIO_ERR_VAL8 0xEA -#define SDIO_ERR_VAL16 0xEAEA -#define SDIO_ERR_VAL32 0xEAEAEAEA - -s32 _sd_cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata); -s32 _sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata); -s32 sd_cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata); -s32 sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata); - -u8 sd_read8(struct intf_hdl *pintfhdl, u32 addr, s32 *err); -u32 sd_read32(struct intf_hdl *pintfhdl, u32 addr, s32 *err); -s32 _sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata); -s32 sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata); -void sd_write8(struct intf_hdl *pintfhdl, u32 addr, u8 v, s32 *err); -void sd_write32(struct intf_hdl *pintfhdl, u32 addr, u32 v, s32 *err); -s32 _sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata); -s32 sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata); - -void rtw_sdio_set_irq_thd(struct dvobj_priv *dvobj, void *thd_hdl); -#endif diff --git a/drivers/staging/rtl8723bs/include/sta_info.h b/drivers/staging/rtl8723bs/include/sta_info.h deleted file mode 100644 index 0f53e77c110c..000000000000 --- a/drivers/staging/rtl8723bs/include/sta_info.h +++ /dev/null @@ -1,330 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __STA_INFO_H_ -#define __STA_INFO_H_ - - -#define IBSS_START_MAC_ID 2 -#define NUM_STA 32 -#define NUM_ACL 16 - - -/* if mode == 0, then the sta is allowed once the addr is hit. */ -/* if mode == 1, then the sta is rejected once the addr is non-hit. */ -struct rtw_wlan_acl_node { - struct list_head list; - u8 addr[ETH_ALEN]; - u8 valid; -}; - -/* mode = 0, disable */ -/* mode = 1, accept unless in deny list */ -/* mode =2, deny unless in accept list */ -struct wlan_acl_pool { - int mode; - int num; - struct rtw_wlan_acl_node aclnode[NUM_ACL]; - struct __queue acl_node_q; -}; - -struct rssi_sta { - s32 UndecoratedSmoothedPWDB; - s32 UndecoratedSmoothedCCK; - s32 UndecoratedSmoothedOFDM; - u64 PacketMap; - u8 ValidBit; -}; - -struct stainfo_stats { - - u64 rx_mgnt_pkts; - u64 rx_beacon_pkts; - u64 rx_probereq_pkts; - u64 rx_probersp_pkts; - u64 rx_probersp_bm_pkts; - u64 rx_probersp_uo_pkts; - u64 rx_ctrl_pkts; - u64 rx_data_pkts; - - u64 last_rx_mgnt_pkts; - u64 last_rx_beacon_pkts; - u64 last_rx_probereq_pkts; - u64 last_rx_probersp_pkts; - u64 last_rx_probersp_bm_pkts; - u64 last_rx_probersp_uo_pkts; - u64 last_rx_ctrl_pkts; - u64 last_rx_data_pkts; - - u64 rx_bytes; - u64 rx_drops; - - u64 tx_pkts; - u64 tx_bytes; - u64 tx_drops; -}; - -struct sta_info { - - spinlock_t lock; - struct list_head list; /* free_sta_queue */ - struct list_head hash_list; /* sta_hash */ - struct adapter *padapter; - - struct sta_xmit_priv sta_xmitpriv; - struct sta_recv_priv sta_recvpriv; - - struct __queue sleep_q; - unsigned int sleepq_len; - - uint state; - uint aid; - uint mac_id; - uint qos_option; - u8 hwaddr[ETH_ALEN]; - - bool ieee8021x_blocked; - uint dot118021XPrivacy; /* aes, tkip... */ - union Keytype dot11tkiptxmickey; - union Keytype dot11tkiprxmickey; - union Keytype dot118021x_UncstKey; - union pn48 dot11txpn; /* PN48 used for Unicast xmit */ - union pn48 dot11wtxpn; /* PN48 used for Unicast mgmt xmit. */ - union pn48 dot11rxpn; /* PN48 used for Unicast recv. */ - - - u8 bssrateset[16]; - u32 bssratelen; - s32 rssi; - s32 signal_quality; - - u8 cts2self; - u8 rtsen; - - u8 raid; - u8 init_rate; - u32 ra_mask; - u8 wireless_mode; /* NETWORK_TYPE */ - u8 bw_mode; - - u8 ldpc; - u8 stbc; - - struct stainfo_stats sta_stats; - - /* for A-MPDU TX, ADDBA timeout check */ - struct timer_list addba_retry_timer; - - /* for A-MPDU Rx reordering buffer control */ - struct recv_reorder_ctrl recvreorder_ctrl[16]; - - /* for A-MPDU Tx */ - /* unsigned char ampdu_txen_bitmap; */ - u16 BA_starting_seqctrl[16]; - - - struct ht_priv htpriv; - - /* Notes: */ - /* STA_Mode: */ - /* curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO */ - /* scan_q: AP CAP/INFO */ - - /* AP_Mode: */ - /* curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO */ - /* sta_info: (AP & STA) CAP/INFO */ - - struct list_head asoc_list; - struct list_head auth_list; - - unsigned int expire_to; - unsigned int auth_seq; - unsigned int authalg; - unsigned char chg_txt[128]; - - u16 capability; - int flags; - - int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */ - int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */ - int wpa_group_cipher; - int wpa2_group_cipher; - int wpa_pairwise_cipher; - int wpa2_pairwise_cipher; - - u8 bpairwise_key_installed; - - u8 wpa_ie[32]; - - u8 nonerp_set; - u8 no_short_slot_time_set; - u8 no_short_preamble_set; - u8 no_ht_gf_set; - u8 no_ht_set; - u8 ht_20mhz_set; - - unsigned int tx_ra_bitmap; - u8 qos_info; - - u8 max_sp_len; - u8 uapsd_bk;/* BIT(0): Delivery enabled, BIT(1): Trigger enabled */ - u8 uapsd_be; - u8 uapsd_vi; - u8 uapsd_vo; - - u8 has_legacy_ac; - unsigned int sleepq_ac_len; - - u8 under_exist_checking; - - u8 keep_alive_trycnt; - - u8 *passoc_req; - u32 assoc_req_len; - - /* for DM */ - struct rssi_sta rssi_stat; - - /* ODM_STA_INFO_T */ - /* ================ODM Relative Info ======================= */ - /* Please be care, dont declare too much structure here. It will cost memory * STA support num. */ - /* */ - /* */ - /* 2011/10/20 MH Add for ODM STA info. */ - /* */ - /* Driver Write */ - u8 bValid; /* record the sta status link or not? */ - u8 IOTPeer; /* Enum value. HT_IOT_PEER_E */ - /* ODM Write */ - /* 1 PHY_STATUS_INFO */ - u8 RSSI_Path[4]; /* */ - u8 RSSI_Ave; - u8 RXEVM[4]; - u8 RXSNR[4]; - - u8 rssi_level; /* for Refresh RA mask */ - /* ODM Write */ - /* 1 TX_INFO (may changed by IC) */ - /* TX_INFO_T pTxInfo; Define in IC folder. Move lower layer. */ - /* */ - /* ================ODM Relative Info ======================= */ - /* */ - - /* To store the sequence number of received management frame */ - u16 rx_mgmt_frame_seq_num; -}; - -#define sta_rx_pkts(sta) \ - (sta->sta_stats.rx_mgnt_pkts \ - + sta->sta_stats.rx_ctrl_pkts \ - + sta->sta_stats.rx_data_pkts) - -#define sta_rx_data_pkts(sta) \ - (sta->sta_stats.rx_data_pkts) - -#define sta_last_rx_data_pkts(sta) \ - (sta->sta_stats.last_rx_data_pkts) - -#define sta_rx_beacon_pkts(sta) \ - (sta->sta_stats.rx_beacon_pkts) - -#define sta_last_rx_beacon_pkts(sta) \ - (sta->sta_stats.last_rx_beacon_pkts) - -#define sta_rx_probersp_pkts(sta) \ - (sta->sta_stats.rx_probersp_pkts) - -#define sta_last_rx_probersp_pkts(sta) \ - (sta->sta_stats.last_rx_probersp_pkts) - -#define sta_update_last_rx_pkts(sta) \ - do { \ - sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \ - sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \ - sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \ - sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \ - sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \ - sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \ - sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \ - sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \ - } while (0) - -#define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)" - -struct sta_priv { - - u8 *pallocated_stainfo_buf; - u8 *pstainfo_buf; - struct __queue free_sta_queue; - - spinlock_t sta_hash_lock; - struct list_head sta_hash[NUM_STA]; - int asoc_sta_count; - struct __queue sleep_q; - struct __queue wakeup_q; - - struct adapter *padapter; - - struct list_head asoc_list; - struct list_head auth_list; - spinlock_t asoc_list_lock; - spinlock_t auth_list_lock; - u8 asoc_list_cnt; - u8 auth_list_cnt; - - unsigned int auth_to; /* sec, time to expire in authenticating. */ - unsigned int assoc_to; /* sec, time to expire before associating. */ - unsigned int expire_to; /* sec , time to expire after associated. */ - - /* pointers to STA info; based on allocated AID or NULL if AID free - * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1 - * and so on - */ - struct sta_info *sta_aid[NUM_STA]; - - u16 sta_dz_bitmap;/* only support for 15 stations, aid bitmap for sleeping stations. */ - u16 tim_bitmap;/* only support 15 stations, aid = 0~15 mapping bit0~bit15 */ - - u16 max_num_sta; - - struct wlan_acl_pool acl_list; -}; - - -static inline u32 wifi_mac_hash(u8 *mac) -{ - u32 x; - - x = mac[0]; - x = (x << 2) ^ mac[1]; - x = (x << 2) ^ mac[2]; - x = (x << 2) ^ mac[3]; - x = (x << 2) ^ mac[4]; - x = (x << 2) ^ mac[5]; - - x ^= x >> 8; - x = x & (NUM_STA - 1); - - return x; -} - - -extern u32 _rtw_init_sta_priv(struct sta_priv *pstapriv); -extern u32 _rtw_free_sta_priv(struct sta_priv *pstapriv); - -#define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0) -int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta); -struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset); - -extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr); -extern u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta); -extern void rtw_free_all_stainfo(struct adapter *padapter); -extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr); -extern u32 rtw_init_bcmc_stainfo(struct adapter *padapter); -extern struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter); -extern u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr); - -#endif /* _STA_INFO_H_ */ diff --git a/drivers/staging/rtl8723bs/include/wifi.h b/drivers/staging/rtl8723bs/include/wifi.h deleted file mode 100644 index 93cb83488d5d..000000000000 --- a/drivers/staging/rtl8723bs/include/wifi.h +++ /dev/null @@ -1,409 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef _WIFI_H_ -#define _WIFI_H_ - -#define WLAN_HDR_A3_LEN 24 -#define WLAN_HDR_A3_QOS_LEN 26 - -#define WLAN_WMM_LEN 24 - -/* This value is tested by WiFi 11n Test Plan 5.2.3. */ -/* This test verifies the WLAN NIC can update the NAV through sending the CTS with large duration. */ -#define WiFiNavUpperUs 30000 /* 30 ms */ - -enum { - WIFI_MGT_TYPE = (0), - WIFI_CTRL_TYPE = (BIT(2)), - WIFI_DATA_TYPE = (BIT(3)), - WIFI_QOS_DATA_TYPE = (BIT(7)|BIT(3)), /* QoS Data */ -}; - -enum { - - /* below is for mgt frame */ - WIFI_ASSOCREQ = (0 | WIFI_MGT_TYPE), - WIFI_ASSOCRSP = (BIT(4) | WIFI_MGT_TYPE), - WIFI_REASSOCREQ = (BIT(5) | WIFI_MGT_TYPE), - WIFI_REASSOCRSP = (BIT(5) | BIT(4) | WIFI_MGT_TYPE), - WIFI_PROBEREQ = (BIT(6) | WIFI_MGT_TYPE), - WIFI_PROBERSP = (BIT(6) | BIT(4) | WIFI_MGT_TYPE), - WIFI_BEACON = (BIT(7) | WIFI_MGT_TYPE), - WIFI_ATIM = (BIT(7) | BIT(4) | WIFI_MGT_TYPE), - WIFI_DISASSOC = (BIT(7) | BIT(5) | WIFI_MGT_TYPE), - WIFI_AUTH = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE), - WIFI_DEAUTH = (BIT(7) | BIT(6) | WIFI_MGT_TYPE), - WIFI_ACTION = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE), - WIFI_ACTION_NOACK = (BIT(7) | BIT(6) | BIT(5) | WIFI_MGT_TYPE), - - /* below is for control frame */ - WIFI_NDPA = (BIT(6) | BIT(4) | WIFI_CTRL_TYPE), - WIFI_PSPOLL = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE), - WIFI_RTS = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE), - WIFI_CTS = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE), - WIFI_ACK = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE), - WIFI_CFEND = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE), - WIFI_CFEND_CFACK = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE), - - /* below is for data frame */ - WIFI_DATA = (0 | WIFI_DATA_TYPE), - WIFI_DATA_CFACK = (BIT(4) | WIFI_DATA_TYPE), - WIFI_DATA_CFPOLL = (BIT(5) | WIFI_DATA_TYPE), - WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE), - WIFI_DATA_NULL = (BIT(6) | WIFI_DATA_TYPE), - WIFI_CF_ACK = (BIT(6) | BIT(4) | WIFI_DATA_TYPE), - WIFI_CF_POLL = (BIT(6) | BIT(5) | WIFI_DATA_TYPE), - WIFI_CF_ACKPOLL = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE), - WIFI_QOS_DATA_NULL = (BIT(6) | WIFI_QOS_DATA_TYPE), -}; - -#define _TO_DS_ BIT(8) -#define _FROM_DS_ BIT(9) -#define _MORE_FRAG_ BIT(10) -#define _RETRY_ BIT(11) -#define _PWRMGT_ BIT(12) -#define _MORE_DATA_ BIT(13) -#define _PRIVACY_ BIT(14) -#define _ORDER_ BIT(15) - -#define SetToDs(pbuf) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_)) - -#define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0) - -#define SetFrDs(pbuf) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_)) - -#define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0) - -#define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe)) - -#define SetMFrag(pbuf) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_)) - -#define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0) - -#define ClearMFrag(pbuf) \ - (*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_))) - -#define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0) - -#define ClearRetry(pbuf) \ - (*(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_))) - -#define SetPwrMgt(pbuf) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_)) - -#define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_PWRMGT_)) != 0) - -#define ClearPwrMgt(pbuf) \ - (*(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_))) - -#define SetMData(pbuf) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_)) - -#define GetMData(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_DATA_)) != 0) - -#define ClearMData(pbuf) \ - (*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_))) - -#define SetPrivacy(pbuf) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_)) - -#define GetPrivacy(pbuf) \ - (((*(__le16 *)(pbuf)) & cpu_to_le16(_PRIVACY_)) != 0) - -#define GetOrder(pbuf) \ - (((*(__le16 *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0) - -#define GetFrameType(pbuf) \ - (le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(3) | BIT(2))) - -#define SetFrameType(pbuf, type) \ - do { \ - *(unsigned short *)(pbuf) &= cpu_to_le16(~(BIT(3) | BIT(2))); \ - *(unsigned short *)(pbuf) |= cpu_to_le16(type); \ - } while (0) - -#define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(7) |\ - BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2))) - -#define SetFrameSubType(pbuf, type) \ - do { \ - *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \ - BIT(5) | BIT(4) | BIT(3) | BIT(2))); \ - *(__le16 *)(pbuf) |= cpu_to_le16(type); \ - } while (0) - -#define GetSequence(pbuf) \ - (le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) >> 4) - -#define GetFragNum(pbuf) \ - (le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) & 0x0f) - -#define SetFragNum(pbuf, num) \ - do { \ - *(unsigned short *)((size_t)(pbuf) + 22) = \ - ((*(unsigned short *)((size_t)(pbuf) + 22)) & \ - le16_to_cpu(~(0x000f))) | \ - cpu_to_le16(0x0f & (num)); \ - } while (0) - -#define SetSeqNum(pbuf, num) \ - do { \ - *(__le16 *)((size_t)(pbuf) + 22) = \ - ((*(__le16 *)((size_t)(pbuf) + 22)) & cpu_to_le16((unsigned short)0x000f)) | \ - cpu_to_le16((unsigned short)(0xfff0 & (num << 4))); \ - } while (0) - -#define SetDuration(pbuf, dur) \ - (*(__le16 *)((size_t)(pbuf) + 2) = cpu_to_le16(0xffff & (dur))) - -#define SetPriority(pbuf, tid) \ - (*(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf)) - -#define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf) - -#define SetEOSP(pbuf, eosp) \ - (*(__le16 *)(pbuf) |= cpu_to_le16((eosp & 1) << 4)) - -#define SetAckpolicy(pbuf, ack) \ - (*(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5)) - -#define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3) - -#define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1) - -#define GetAid(pbuf) (le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 2)) & 0x3fff) - -#define GetAddr1Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 4)) - -#define GetAddr2Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 10)) - -#define GetAddr3Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 16)) - -#define GetAddr4Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 24)) - -static inline unsigned char *rtl8723bs_get_ra(unsigned char *pframe) -{ - unsigned char *ra; - - ra = GetAddr1Ptr(pframe); - return ra; -} - -static inline unsigned char *get_ta(unsigned char *pframe) -{ - unsigned char *ta; - - ta = GetAddr2Ptr(pframe); - return ta; -} - -static inline unsigned char *get_da(unsigned char *pframe) -{ - unsigned char *da; - unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe); - - switch (to_fr_ds) { - case 0x00: /* ToDs = 0, FromDs = 0 */ - da = GetAddr1Ptr(pframe); - break; - case 0x01: /* ToDs = 0, FromDs = 1 */ - da = GetAddr1Ptr(pframe); - break; - case 0x02: /* ToDs = 1, FromDs = 0 */ - da = GetAddr3Ptr(pframe); - break; - default: /* ToDs = 1, FromDs = 1 */ - da = GetAddr3Ptr(pframe); - break; - } - - return da; -} - -static inline unsigned char *get_sa(unsigned char *pframe) -{ - unsigned char *sa; - unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe); - - switch (to_fr_ds) { - case 0x00: /* ToDs = 0, FromDs = 0 */ - sa = GetAddr2Ptr(pframe); - break; - case 0x01: /* ToDs = 0, FromDs = 1 */ - sa = GetAddr3Ptr(pframe); - break; - case 0x02: /* ToDs = 1, FromDs = 0 */ - sa = GetAddr2Ptr(pframe); - break; - default: /* ToDs = 1, FromDs = 1 */ - sa = GetAddr4Ptr(pframe); - break; - } - - return sa; -} - -static inline unsigned char *get_hdr_bssid(unsigned char *pframe) -{ - unsigned char *sa = NULL; - unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe); - - switch (to_fr_ds) { - case 0x00: /* ToDs = 0, FromDs = 0 */ - sa = GetAddr3Ptr(pframe); - break; - case 0x01: /* ToDs = 0, FromDs = 1 */ - sa = GetAddr2Ptr(pframe); - break; - case 0x02: /* ToDs = 1, FromDs = 0 */ - sa = GetAddr1Ptr(pframe); - break; - case 0x03: /* ToDs = 1, FromDs = 1 */ - sa = GetAddr1Ptr(pframe); - break; - } - - return sa; -} - -static inline int IsFrameTypeCtrl(unsigned char *pframe) -{ - return GetFrameType(pframe) == WIFI_CTRL_TYPE; -} - -/*----------------------------------------------------------------------------- - Below is for the security related definition -------------------------------------------------------------------------------*/ - -#define _ASOCREQ_IE_OFFSET_ 4 /* excluding wlan_hdr */ -#define _REASOCREQ_IE_OFFSET_ 10 -#define _PROBEREQ_IE_OFFSET_ 0 -#define _PROBERSP_IE_OFFSET_ 12 -#define _AUTH_IE_OFFSET_ 6 -#define _BEACON_IE_OFFSET_ 12 - -#define _FIXED_IE_LENGTH_ _BEACON_IE_OFFSET_ - -/* --------------------------------------------------------------------------- - Below is the fixed elements... ------------------------------------------------------------------------------*/ -#define _AUTH_ALGM_NUM_ 2 -#define _AUTH_SEQ_NUM_ 2 -#define _BEACON_ITERVAL_ 2 -#define _CAPABILITY_ 2 -#define _RSON_CODE_ 2 -#define _ASOC_ID_ 2 -#define _STATUS_CODE_ 2 -#define _TIMESTAMP_ 8 - -/*----------------------------------------------------------------------------- - Below is the definition for 802.11i / 802.1x -------------------------------------------------------------------------------*/ -#define _IEEE8021X_MGT_ 1 /* WPA */ -#define _IEEE8021X_PSK_ 2 /* WPA with pre-shared key */ - -#define _MME_IE_LENGTH_ 18 -/*----------------------------------------------------------------------------- - Below is the definition for WMM -------------------------------------------------------------------------------*/ -#define _WMM_IE_Length_ 7 /* for WMM STA */ - -/*----------------------------------------------------------------------------- - Below is the definition for 802.11n -------------------------------------------------------------------------------*/ -#define GetOrderBit(pbuf) (((*(unsigned short *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0) - -#define ACT_CAT_VENDOR 0x7F/* 127 */ - -/** - * struct rtw_ieee80211_ht_cap - HT additional information - * - * This structure refers to "HT information element" as - * described in 802.11n draft section 7.3.2.53 - */ -struct ieee80211_ht_addt_info { - unsigned char control_chan; - unsigned char ht_param; - __le16 operation_mode; - __le16 stbc_param; - unsigned char basic_set[16]; -} __packed; - -struct HT_caps_element { - union { - struct { - __le16 HT_caps_info; - unsigned char AMPDU_para; - unsigned char MCS_rate[16]; - __le16 HT_ext_caps; - __le16 Beamforming_caps; - unsigned char ASEL_caps; - } HT_cap_element; - unsigned char HT_cap[26]; - } u; -} __packed; - -struct HT_info_element { - unsigned char primary_channel; - unsigned char infos[5]; - unsigned char MCS_rate[16]; -} __packed; - -struct AC_param { - unsigned char ACI_AIFSN; - unsigned char CW; - __le16 TXOP_limit; -} __packed; - -struct WMM_para_element { - unsigned char QoS_info; - unsigned char reserved; - struct AC_param ac_param[4]; -} __packed; - -struct ADDBA_request { - unsigned char dialog_token; - __le16 BA_para_set; - __le16 BA_timeout_value; - __le16 BA_starting_seqctrl; -} __packed; - -/* 802.11n HT capabilities masks */ -#define IEEE80211_HT_CAP_LDPC_CODING 0x0001 -#define IEEE80211_HT_CAP_SUP_WIDTH 0x0002 -#define IEEE80211_HT_CAP_SM_PS 0x000C -#define IEEE80211_HT_CAP_GRN_FLD 0x0010 -#define IEEE80211_HT_CAP_SGI_20 0x0020 -#define IEEE80211_HT_CAP_SGI_40 0x0040 -#define IEEE80211_HT_CAP_TX_STBC 0x0080 -#define IEEE80211_HT_CAP_RX_STBC_1R 0x0100 -#define IEEE80211_HT_CAP_RX_STBC_3R 0x0300 -#define IEEE80211_HT_CAP_MAX_AMSDU 0x0800 -#define IEEE80211_HT_CAP_DSSSCCK40 0x1000 -/* 802.11n HT capability AMPDU settings */ -#define IEEE80211_HT_CAP_AMPDU_FACTOR 0x03 -#define IEEE80211_HT_CAP_AMPDU_DENSITY 0x1C - -/* endif */ - -/* ===============WPS Section =============== */ -/* WPS attribute ID */ -#define WPS_ATTR_SELECTED_REGISTRAR 0x1041 - -#define IP_MCAST_MAC(mac) ((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5e)) -#define ICMPV6_MCAST_MAC(mac) ((mac[0] == 0x33) && (mac[1] == 0x33) && (mac[2] != 0xff)) - -/* Regulatroy Domain */ -struct regd_pair_mapping { - u16 reg_dmnenum; - u16 reg_2ghz_ctl; -}; - -#endif /* _WIFI_H_ */ diff --git a/drivers/staging/rtl8723bs/include/wlan_bssdef.h b/drivers/staging/rtl8723bs/include/wlan_bssdef.h deleted file mode 100644 index f4c1456f1476..000000000000 --- a/drivers/staging/rtl8723bs/include/wlan_bssdef.h +++ /dev/null @@ -1,195 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __WLAN_BSSDEF_H__ -#define __WLAN_BSSDEF_H__ - - -#define MAX_IE_SZ 768 - - -#define NDIS_802_11_LENGTH_SSID 32 -#define NDIS_802_11_LENGTH_RATES 8 -#define NDIS_802_11_LENGTH_RATES_EX 16 - -typedef unsigned char NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES]; /* Set of 8 data rates */ -typedef unsigned char NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; /* Set of 16 data rates */ - -struct ndis_802_11_ssid { - u32 ssid_length; - u8 ssid[32]; -}; - -/* - * FW will only save the channel number in DSConfig. - * ODI Handler will convert the channel number to freq. number. - */ -struct ndis_802_11_conf { - u32 length; /* Length of structure */ - u32 beacon_period; /* units are Kusec */ - u32 atim_window; /* units are Kusec */ - u32 ds_config; /* Frequency, units are kHz */ -}; - -struct ndis_802_11_fix_ie { - u8 time_stamp[8]; - u16 beacon_interval; - u16 capabilities; -}; - -struct ndis_80211_var_ie { - u8 element_id; - u8 length; - u8 data[]; -}; - -/* Length is the 4 bytes multiples of the sum of - * ETH_ALEN + 2 + - * sizeof (struct ndis_802_11_ssid) + sizeof (u32) + - * sizeof (long) + - * sizeof (struct ndis_802_11_conf) + sizeof (NDIS_802_11_RATES_EX) + ie_length - * - * Except for ie_length, all other fields are fixed length. Therefore, we can - * define a macro to present the partial sum. - */ -enum ndis_802_11_authentication_mode { - Ndis802_11AuthModeOpen, - Ndis802_11AuthModeShared, - Ndis802_11AuthModeAutoSwitch, - Ndis802_11AuthModeWPA, - Ndis802_11AuthModeWPAPSK, - Ndis802_11AuthModeWPANone, - Ndis802_11AuthModeWAPI, - Ndis802_11AuthModeMax /* Not a real mode, defined as upper bound */ -}; - -enum { - Ndis802_11WEPEnabled, - Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled, - Ndis802_11WEPDisabled, - Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled, - Ndis802_11WEPKeyAbsent, - Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent, - Ndis802_11WEPNotSupported, - Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported, - Ndis802_11Encryption2Enabled, - Ndis802_11Encryption2KeyAbsent, - Ndis802_11Encryption3Enabled, - Ndis802_11Encryption3KeyAbsent, - Ndis802_11_EncrypteionWAPI -}; - -#define NDIS_802_11_AI_REQFI_CAPABILITIES 1 -#define NDIS_802_11_AI_REQFI_LISTENINTERVAL 2 -#define NDIS_802_11_AI_REQFI_CURRENTAPADDRESS 4 - -#define NDIS_802_11_AI_RESFI_CAPABILITIES 1 -#define NDIS_802_11_AI_RESFI_STATUSCODE 2 -#define NDIS_802_11_AI_RESFI_ASSOCIATIONID 4 - -/* Key mapping keys require a BSSID */ - -struct ndis_802_11_wep { - u32 length; /* Length of this structure */ - u32 key_index; /* 0 is the per-client key, 1-N are the global keys */ - u32 key_length; /* length of key in bytes */ - u8 key_material[16];/* variable length depending on above field */ -}; - -/* mask for authentication/integrity fields */ -#define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS 0x0f -#define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01 -#define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02 -#define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06 -#define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E - -/* MIC check time, 60 seconds. */ -#define MIC_CHECK_TIME 60000000 - -struct wlan_phy_info { - u8 signal_strength;/* in percentage) */ - u8 signal_quality;/* in percentage) */ - u8 optimum_antenna; /* for Antenna diversity */ - u8 reserved_0; -}; - -struct wlan_bcn_info { - /* these infor get from rtw_get_encrypt_info when - * translate scan to UI - */ - u8 encryp_protocol;/* ENCRYP_PROTOCOL_E: OPEN/WEP/WPA/WPA2/WAPI */ - int group_cipher; /* WPA/WPA2 group cipher */ - int pairwise_cipher;/* WPA/WPA2/WEP pairwise cipher */ - int is_8021x; - - /* bwmode 20/40 and ch_offset UP/LOW */ - unsigned short ht_cap_info; - unsigned char ht_info_infos_0; -}; - -/* temporally add #pragma pack for structure alignment issue of - * struct wlan_bssid_ex and get_wlan_bssid_ex_sz() - */ -struct wlan_bssid_ex { - u32 length; - u8 mac_address[ETH_ALEN]; - u8 reserved[2];/* 0]: IS beacon frame */ - struct ndis_802_11_ssid ssid; - u32 privacy; - long rssi;/* in dBM, raw data , get from PHY) */ - struct ndis_802_11_conf configuration; - enum nl80211_iftype infrastructure_mode; - NDIS_802_11_RATES_EX supported_rates; - struct wlan_phy_info phy_info; - u32 ie_length; - u8 ies[MAX_IE_SZ]; /* timestamp, beacon interval, and capability information) */ -} __packed; - -static inline uint get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss) -{ - return (sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + bss->ie_length); -} - -struct wlan_network { - struct list_head list; - int network_type; /* refer to ieee80211.h for WIRELESS_11A/B/G */ - int fixed; /* set to fixed when not to be removed as site-surveying */ - unsigned long last_scanned; /* timestamp for the network */ - int aid; /* will only be valid when a BSS is joinned. */ - int join_res; - struct wlan_bssid_ex network; /* must be the last item */ - struct wlan_bcn_info bcn_info; -}; - -enum { - DISABLE_VCS, - ENABLE_VCS, - AUTO_VCS -}; - -enum { - NONE_VCS, - RTS_CTS, - CTS_TO_SELF -}; - -#define PWR_CAM 0 -#define PWR_MINPS 1 -#define PWR_MAXPS 2 -#define PWR_UAPSD 3 -#define PWR_VOIP 4 - -enum { - NO_LIMIT, - TWO_MSDU, - FOUR_MSDU, - SIX_MSDU -}; - -#define NUM_PRE_AUTH_KEY 16 -#define NUM_PMKID_CACHE NUM_PRE_AUTH_KEY - -#endif /* ifndef WLAN_BSSDEF_H_ */ diff --git a/drivers/staging/rtl8723bs/include/xmit_osdep.h b/drivers/staging/rtl8723bs/include/xmit_osdep.h deleted file mode 100644 index ee6616880d41..000000000000 --- a/drivers/staging/rtl8723bs/include/xmit_osdep.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#ifndef __XMIT_OSDEP_H_ -#define __XMIT_OSDEP_H_ - - -struct pkt_file { - struct sk_buff *pkt; - __kernel_size_t pkt_len; /* the remainder length of the open_file */ - unsigned char *cur_buffer; - u8 *buf_start; - u8 *cur_addr; - __kernel_size_t buf_len; -}; - -#define NR_XMITFRAME 256 - -struct xmit_priv; -struct pkt_attrib; -struct sta_xmit_priv; -struct xmit_frame; -struct xmit_buf; - -extern void _rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev); -extern netdev_tx_t rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev); - -void rtw_os_xmit_schedule(struct adapter *padapter); - -void rtw_os_xmit_resource_free(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 free_sz, u8 flag); - -extern unsigned int rtw_remainder_len(struct pkt_file *pfile); -extern void _rtw_open_pktfile(struct sk_buff *pkt, struct pkt_file *pfile); -int _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, unsigned int rlen); -extern signed int rtw_endofpktfile(struct pkt_file *pfile); - -extern void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt); -extern void rtw_os_xmit_complete(struct adapter *padapter, struct xmit_frame *pxframe); - -#endif /* __XMIT_OSDEP_H_ */ diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c deleted file mode 100644 index 3468d4114f60..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +++ /dev/null @@ -1,2795 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ - -#include -#include -#include - -#include - -#define RTW_MAX_MGMT_TX_CNT (8) - -#define RTW_SCAN_IE_LEN_MAX 2304 -#define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */ -#define RTW_MAX_NUM_PMKIDS 4 - -static const u32 rtw_cipher_suites[] = { - WLAN_CIPHER_SUITE_WEP40, - WLAN_CIPHER_SUITE_WEP104, - WLAN_CIPHER_SUITE_TKIP, - WLAN_CIPHER_SUITE_CCMP, - WLAN_CIPHER_SUITE_AES_CMAC, -}; - -#define RATETAB_ENT(_rate, _rateid, _flags) \ - { \ - .bitrate = (_rate), \ - .hw_value = (_rateid), \ - .flags = (_flags), \ - } - -#define CHAN2G(_channel, _freq, _flags) { \ - .band = NL80211_BAND_2GHZ, \ - .center_freq = (_freq), \ - .hw_value = (_channel), \ - .flags = (_flags), \ - .max_antenna_gain = 0, \ - .max_power = 30, \ -} - -/* if wowlan is not supported, kernel generate a disconnect at each suspend - * cf: /net/wireless/sysfs.c, so register a stub wowlan. - * Moreover wowlan has to be enabled via a the nl80211_set_wowlan callback. - * (from user space, e.g. iw phy0 wowlan enable) - */ -static __maybe_unused const struct wiphy_wowlan_support wowlan_stub = { - .flags = WIPHY_WOWLAN_ANY, - .n_patterns = 0, - .pattern_max_len = 0, - .pattern_min_len = 0, - .max_pkt_offset = 0, -}; - -static struct ieee80211_rate rtw_rates[] = { - RATETAB_ENT(10, 0x1, 0), - RATETAB_ENT(20, 0x2, 0), - RATETAB_ENT(55, 0x4, 0), - RATETAB_ENT(110, 0x8, 0), - RATETAB_ENT(60, 0x10, 0), - RATETAB_ENT(90, 0x20, 0), - RATETAB_ENT(120, 0x40, 0), - RATETAB_ENT(180, 0x80, 0), - RATETAB_ENT(240, 0x100, 0), - RATETAB_ENT(360, 0x200, 0), - RATETAB_ENT(480, 0x400, 0), - RATETAB_ENT(540, 0x800, 0), -}; - -#define rtw_g_rates (rtw_rates + 0) -#define RTW_G_RATES_NUM 12 - -#define RTW_2G_CHANNELS_NUM 14 - -static struct ieee80211_channel rtw_2ghz_channels[] = { - CHAN2G(1, 2412, 0), - CHAN2G(2, 2417, 0), - CHAN2G(3, 2422, 0), - CHAN2G(4, 2427, 0), - CHAN2G(5, 2432, 0), - CHAN2G(6, 2437, 0), - CHAN2G(7, 2442, 0), - CHAN2G(8, 2447, 0), - CHAN2G(9, 2452, 0), - CHAN2G(10, 2457, 0), - CHAN2G(11, 2462, 0), - CHAN2G(12, 2467, 0), - CHAN2G(13, 2472, 0), - CHAN2G(14, 2484, 0), -}; - -static void rtw_2g_channels_init(struct ieee80211_channel *channels) -{ - memcpy(channels, rtw_2ghz_channels, - sizeof(struct ieee80211_channel) * RTW_2G_CHANNELS_NUM - ); -} - -static void rtw_2g_rates_init(struct ieee80211_rate *rates) -{ - memcpy(rates, rtw_g_rates, - sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM - ); -} - -static struct ieee80211_supported_band *rtw_spt_band_alloc( - enum nl80211_band band - ) -{ - struct ieee80211_supported_band *spt_band = NULL; - size_t channels_sz, bitrate_size; - - if (band != NL80211_BAND_2GHZ) - goto exit; - - channels_sz = array_size(RTW_2G_CHANNELS_NUM, sizeof(struct ieee80211_channel)); - bitrate_size = array_size(RTW_G_RATES_NUM, sizeof(struct ieee80211_rate)); - - spt_band = kzalloc(sizeof(*spt_band) + channels_sz + bitrate_size, GFP_KERNEL); - if (!spt_band) - goto exit; - - spt_band->channels = (void *)spt_band + sizeof(*spt_band); - spt_band->bitrates = (void *)spt_band + sizeof(*spt_band) + channels_sz; - spt_band->band = band; - spt_band->n_channels = RTW_2G_CHANNELS_NUM; - spt_band->n_bitrates = RTW_G_RATES_NUM; - - rtw_2g_channels_init(spt_band->channels); - rtw_2g_rates_init(spt_band->bitrates); - - /* spt_band.ht_cap */ - -exit: - - return spt_band; -} - -static const struct ieee80211_txrx_stypes -rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { - [NL80211_IFTYPE_ADHOC] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ACTION >> 4) - }, - [NL80211_IFTYPE_STATION] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) - }, - [NL80211_IFTYPE_AP] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | - BIT(IEEE80211_STYPE_DISASSOC >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4) | - BIT(IEEE80211_STYPE_DEAUTH >> 4) | - BIT(IEEE80211_STYPE_ACTION >> 4) - }, - [NL80211_IFTYPE_AP_VLAN] = { - /* copy AP */ - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | - BIT(IEEE80211_STYPE_DISASSOC >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4) | - BIT(IEEE80211_STYPE_DEAUTH >> 4) | - BIT(IEEE80211_STYPE_ACTION >> 4) - }, - [NL80211_IFTYPE_P2P_CLIENT] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) - }, - [NL80211_IFTYPE_P2P_GO] = { - .tx = 0xffff, - .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | - BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | - BIT(IEEE80211_STYPE_DISASSOC >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4) | - BIT(IEEE80211_STYPE_DEAUTH >> 4) | - BIT(IEEE80211_STYPE_ACTION >> 4) - }, -}; - -int rtw_ieee80211_channel_to_frequency(int chan) -{ - /* NL80211_BAND_2GHZ */ - if (chan == 14) - return 2484; - - if (chan < 14) - return 2407 + chan * 5; - - return 0; /* not supported */ -} - -#define MAX_BSSINFO_LEN 1000 -struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wlan_network *pnetwork) -{ - struct ieee80211_channel *notify_channel; - struct cfg80211_bss *bss = NULL; - /* struct ieee80211_supported_band *band; */ - u16 channel; - u32 freq; - u64 notify_timestamp; - s32 notify_signal; - u8 *buf = NULL, *pbuf; - size_t len, bssinf_len = 0; - struct ieee80211_hdr *pwlanhdr; - __le16 *fctrl; - - struct wireless_dev *wdev = padapter->rtw_wdev; - struct wiphy *wiphy = wdev->wiphy; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - - bssinf_len = pnetwork->network.ie_length + sizeof(struct ieee80211_hdr_3addr); - if (bssinf_len > MAX_BSSINFO_LEN) - goto exit; - - { - u16 wapi_len = 0; - - if (rtw_get_wapi_ie(pnetwork->network.ies, pnetwork->network.ie_length, NULL, &wapi_len) > 0) { - if (wapi_len > 0) - goto exit; - } - } - - /* To reduce PBC Overlap rate */ - /* spin_lock_bh(&pwdev_priv->scan_req_lock); */ - if (adapter_wdev_data(padapter)->scan_request) { - u8 *psr = NULL, sr = 0; - struct ndis_802_11_ssid *pssid = &pnetwork->network.ssid; - struct cfg80211_scan_request *request = adapter_wdev_data(padapter)->scan_request; - struct cfg80211_ssid *ssids = request->ssids; - u32 wpsielen = 0; - u8 *wpsie = NULL; - - wpsie = rtw_get_wps_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, pnetwork->network.ie_length - _FIXED_IE_LENGTH_, NULL, &wpsielen); - - if (wpsie && wpsielen > 0) - psr = rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL); - - if (sr != 0) { - /* it means under processing WPS */ - if (request->n_ssids == 1 && request->n_channels == 1) { - if (ssids[0].ssid_len != 0 && - (pssid->ssid_length != ssids[0].ssid_len || - memcmp(pssid->ssid, ssids[0].ssid, ssids[0].ssid_len))) { - if (psr) - *psr = 0; /* clear sr */ - } - } - } - } - /* spin_unlock_bh(&pwdev_priv->scan_req_lock); */ - - channel = pnetwork->network.configuration.ds_config; - freq = rtw_ieee80211_channel_to_frequency(channel); - - notify_channel = ieee80211_get_channel(wiphy, freq); - - notify_timestamp = ktime_to_us(ktime_get_boottime()); - - /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm) */ - if (check_fwstate(pmlmepriv, _FW_LINKED) && - is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) { - notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength);/* dbm */ - } else { - notify_signal = 100 * translate_percentage_to_dbm(pnetwork->network.phy_info.signal_strength);/* dbm */ - } - - buf = kzalloc(MAX_BSSINFO_LEN, GFP_ATOMIC); - if (!buf) - goto exit; - pbuf = buf; - - pwlanhdr = (struct ieee80211_hdr *)pbuf; - fctrl = &(pwlanhdr->frame_control); - *(fctrl) = 0; - - SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/); - /* pmlmeext->mgnt_seq++; */ - - if (pnetwork->network.reserved[0] == 1) { /* WIFI_BEACON */ - eth_broadcast_addr(pwlanhdr->addr1); - SetFrameSubType(pbuf, WIFI_BEACON); - } else { - memcpy(pwlanhdr->addr1, myid(&(padapter->eeprompriv)), ETH_ALEN); - SetFrameSubType(pbuf, WIFI_PROBERSP); - } - - memcpy(pwlanhdr->addr2, pnetwork->network.mac_address, ETH_ALEN); - memcpy(pwlanhdr->addr3, pnetwork->network.mac_address, ETH_ALEN); - - pbuf += sizeof(struct ieee80211_hdr_3addr); - len = sizeof(struct ieee80211_hdr_3addr); - - memcpy(pbuf, pnetwork->network.ies, pnetwork->network.ie_length); - len += pnetwork->network.ie_length; - - *((__le64 *)pbuf) = cpu_to_le64(notify_timestamp); - - bss = cfg80211_inform_bss_frame(wiphy, notify_channel, (struct ieee80211_mgmt *)buf, - len, notify_signal, GFP_ATOMIC); - - if (unlikely(!bss)) - goto free_buf; - - cfg80211_put_bss(wiphy, bss); -free_buf: - kfree(buf); - -exit: - return bss; -} - -/* - * Check the given bss is valid by kernel API cfg80211_get_bss() - * @padapter : the given adapter - * - * return true if bss is valid, false for not found. - */ -int rtw_cfg80211_check_bss(struct adapter *padapter) -{ - struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); - struct cfg80211_bss *bss = NULL; - struct ieee80211_channel *notify_channel = NULL; - u32 freq; - - if (!(pnetwork) || !(padapter->rtw_wdev)) - return false; - - freq = rtw_ieee80211_channel_to_frequency(pnetwork->configuration.ds_config); - - notify_channel = ieee80211_get_channel(padapter->rtw_wdev->wiphy, freq); - bss = cfg80211_get_bss(padapter->rtw_wdev->wiphy, notify_channel, - pnetwork->mac_address, pnetwork->ssid.ssid, - pnetwork->ssid.ssid_length, - IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); - - cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss); - - return (bss != NULL); -} - -void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *cur_network = &(pmlmepriv->cur_network); - struct wireless_dev *pwdev = padapter->rtw_wdev; - struct wiphy *wiphy = pwdev->wiphy; - int freq = (int)cur_network->network.configuration.ds_config; - struct ieee80211_channel *chan; - - if (pwdev->iftype != NL80211_IFTYPE_ADHOC) - return; - - if (!rtw_cfg80211_check_bss(padapter)) { - struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); - struct wlan_network *scanned = pmlmepriv->cur_network_scanned; - - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - memcpy(&cur_network->network, pnetwork, sizeof(struct wlan_bssid_ex)); - rtw_cfg80211_inform_bss(padapter, cur_network); - } else { - if (!scanned) { - WARN_ON(1); - return; - } - if (!memcmp(&scanned->network.ssid, &pnetwork->ssid, - sizeof(struct ndis_802_11_ssid)) && - !memcmp(scanned->network.mac_address, pnetwork->mac_address, ETH_ALEN)) - rtw_cfg80211_inform_bss(padapter, scanned); - else - WARN_ON(1); - } - - if (!rtw_cfg80211_check_bss(padapter)) - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " BSS not found !!\n", - FUNC_ADPT_ARG(padapter)); - } - /* notify cfg80211 that device joined an IBSS */ - chan = ieee80211_get_channel(wiphy, freq); - cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.mac_address, chan, GFP_ATOMIC); -} - -void rtw_cfg80211_indicate_connect(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wlan_network *cur_network = &(pmlmepriv->cur_network); - struct wireless_dev *pwdev = padapter->rtw_wdev; - - if (pwdev->iftype != NL80211_IFTYPE_STATION - && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT - ) { - return; - } - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - return; - - { - struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); - struct wlan_network *scanned = pmlmepriv->cur_network_scanned; - - if (!scanned) { - WARN_ON(1); - goto check_bss; - } - - if (!memcmp(scanned->network.mac_address, pnetwork->mac_address, ETH_ALEN) && - !memcmp(&scanned->network.ssid, &pnetwork->ssid, - sizeof(struct ndis_802_11_ssid))) - rtw_cfg80211_inform_bss(padapter, scanned); - else - WARN_ON(1); - } - -check_bss: - if (!rtw_cfg80211_check_bss(padapter)) - netdev_dbg(padapter->pnetdev, - FUNC_ADPT_FMT " BSS not found !!\n", - FUNC_ADPT_ARG(padapter)); - - if (rtw_to_roam(padapter) > 0) { - struct wiphy *wiphy = pwdev->wiphy; - struct ieee80211_channel *notify_channel; - u32 freq; - u16 channel = cur_network->network.configuration.ds_config; - struct cfg80211_roam_info roam_info = {}; - - freq = rtw_ieee80211_channel_to_frequency(channel); - - notify_channel = ieee80211_get_channel(wiphy, freq); - - roam_info.links[0].channel = notify_channel; - roam_info.links[0].bssid = cur_network->network.mac_address; - roam_info.req_ie = - pmlmepriv->assoc_req + sizeof(struct ieee80211_hdr_3addr) + 2; - roam_info.req_ie_len = - pmlmepriv->assoc_req_len - sizeof(struct ieee80211_hdr_3addr) - 2; - roam_info.resp_ie = - pmlmepriv->assoc_rsp + sizeof(struct ieee80211_hdr_3addr) + 6; - roam_info.resp_ie_len = - pmlmepriv->assoc_rsp_len - sizeof(struct ieee80211_hdr_3addr) - 6; - cfg80211_roamed(padapter->pnetdev, &roam_info, GFP_ATOMIC); - } else { - cfg80211_connect_result(padapter->pnetdev, cur_network->network.mac_address - , pmlmepriv->assoc_req + sizeof(struct ieee80211_hdr_3addr) + 2 - , pmlmepriv->assoc_req_len - sizeof(struct ieee80211_hdr_3addr) - 2 - , pmlmepriv->assoc_rsp + sizeof(struct ieee80211_hdr_3addr) + 6 - , pmlmepriv->assoc_rsp_len - sizeof(struct ieee80211_hdr_3addr) - 6 - , WLAN_STATUS_SUCCESS, GFP_ATOMIC); - } -} - -void rtw_cfg80211_indicate_disconnect(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct wireless_dev *pwdev = padapter->rtw_wdev; - - if (pwdev->iftype != NL80211_IFTYPE_STATION - && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT - ) { - return; - } - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - return; - - if (!padapter->mlmepriv.not_indic_disco) { - if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { - cfg80211_disconnected(padapter->pnetdev, 0, - NULL, 0, true, GFP_ATOMIC); - } else { - cfg80211_connect_result(padapter->pnetdev, NULL, NULL, 0, NULL, 0, - WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/); - } - } -} - -static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) -{ - int ret = 0; - u32 wep_key_idx, wep_key_len; - struct sta_info *psta = NULL, *pbcmc_sta = NULL; - struct adapter *padapter = rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &(padapter->securitypriv); - struct sta_priv *pstapriv = &padapter->stapriv; - char *grpkey = padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey; - char *txkey = padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey; - char *rxkey = padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey; - - param->u.crypt.err = 0; - param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; - - if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) { - ret = -EINVAL; - goto exit; - } - - if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && - param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && - param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { - if (param->u.crypt.idx >= WEP_KEYS) { - ret = -EINVAL; - goto exit; - } - } else { - psta = rtw_get_stainfo(pstapriv, param->sta_addr); - if (!psta) - /* ret = -EINVAL; */ - goto exit; - } - - if (strcmp(param->u.crypt.alg, "none") == 0 && !psta) - goto exit; - - if (strcmp(param->u.crypt.alg, "WEP") == 0 && !psta) { - wep_key_idx = param->u.crypt.idx; - wep_key_len = param->u.crypt.key_len; - - if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) { - ret = -EINVAL; - goto exit; - } - - if (wep_key_len > 0) - wep_key_len = wep_key_len <= 5 ? 5 : 13; - - if (psecuritypriv->bWepDefaultKeyIdxSet == 0) { - /* wep default key has not been set, so use this key index as default key. */ - - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_auto; - psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; - psecuritypriv->dot11_privacy_algrthm = _WEP40_; - psecuritypriv->dot118021XGrpPrivacy = _WEP40_; - - if (wep_key_len == 13) { - psecuritypriv->dot11_privacy_algrthm = _WEP104_; - psecuritypriv->dot118021XGrpPrivacy = _WEP104_; - } - - psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; - } - - memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len); - - psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len; - - rtw_ap_set_wep_key(padapter, param->u.crypt.key, wep_key_len, wep_key_idx, 1); - - goto exit; - } - - /* group key */ - if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - /* group key */ - if (param->u.crypt.set_tx == 0) { - if (strcmp(param->u.crypt.alg, "WEP") == 0) { - memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - - psecuritypriv->dot118021XGrpPrivacy = _WEP40_; - if (param->u.crypt.key_len == 13) - psecuritypriv->dot118021XGrpPrivacy = _WEP104_; - - } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { - psecuritypriv->dot118021XGrpPrivacy = _TKIP_; - - memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - - /* set mic key */ - memcpy(txkey, &(param->u.crypt.key[16]), 8); - memcpy(rxkey, &(param->u.crypt.key[24]), 8); - - psecuritypriv->busetkipkey = true; - - } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { - psecuritypriv->dot118021XGrpPrivacy = _AES_; - - memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - } else { - psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; - } - - psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; - - psecuritypriv->binstallGrpkey = true; - - psecuritypriv->dot11_privacy_algrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ - - rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); - - pbcmc_sta = rtw_get_bcmc_stainfo(padapter); - if (pbcmc_sta) { - pbcmc_sta->ieee8021x_blocked = false; - pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ - } - } - - goto exit; - } - - if (psecuritypriv->dot11_auth_algrthm == dot11_auth_algrthm_8021x && psta) {/* psk/802_1x */ - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - if (param->u.crypt.set_tx == 1) { /* pairwise key */ - memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - - if (strcmp(param->u.crypt.alg, "WEP") == 0) { - psta->dot118021XPrivacy = _WEP40_; - if (param->u.crypt.key_len == 13) - psta->dot118021XPrivacy = _WEP104_; - } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { - psta->dot118021XPrivacy = _TKIP_; - - /* set mic key */ - memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); - memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); - - psecuritypriv->busetkipkey = true; - - } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { - psta->dot118021XPrivacy = _AES_; - } else { - psta->dot118021XPrivacy = _NO_PRIVACY_; - } - - rtw_ap_set_pairwise_key(padapter, psta); - - psta->ieee8021x_blocked = false; - - psta->bpairwise_key_installed = true; - - } else { /* group key??? */ - if (strcmp(param->u.crypt.alg, "WEP") == 0) { - memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - - psecuritypriv->dot118021XGrpPrivacy = _WEP40_; - if (param->u.crypt.key_len == 13) - psecuritypriv->dot118021XGrpPrivacy = _WEP104_; - } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { - psecuritypriv->dot118021XGrpPrivacy = _TKIP_; - - memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - - /* set mic key */ - memcpy(txkey, &(param->u.crypt.key[16]), 8); - memcpy(rxkey, &(param->u.crypt.key[24]), 8); - - psecuritypriv->busetkipkey = true; - - } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { - psecuritypriv->dot118021XGrpPrivacy = _AES_; - - memcpy(grpkey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - } else { - psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; - } - - psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; - - psecuritypriv->binstallGrpkey = true; - - psecuritypriv->dot11_privacy_algrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ - - rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); - - pbcmc_sta = rtw_get_bcmc_stainfo(padapter); - if (pbcmc_sta) { - pbcmc_sta->ieee8021x_blocked = false; - pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ - } - } - } - } - -exit: - - return ret; -} - -static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) -{ - int ret = 0; - u8 max_idx; - u32 wep_key_idx, wep_key_len; - struct adapter *padapter = rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - - param->u.crypt.err = 0; - param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; - - if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) { - ret = -EINVAL; - goto exit; - } - - if (param->sta_addr[0] != 0xff || param->sta_addr[1] != 0xff || - param->sta_addr[2] != 0xff || param->sta_addr[3] != 0xff || - param->sta_addr[4] != 0xff || param->sta_addr[5] != 0xff) { - ret = -EINVAL; - goto exit; - } - - if (strcmp(param->u.crypt.alg, "WEP") == 0) - max_idx = WEP_KEYS - 1; - else - max_idx = BIP_MAX_KEYID; - - if (param->u.crypt.idx > max_idx) { - netdev_err(dev, "Error crypt.idx %d > %d\n", param->u.crypt.idx, max_idx); - ret = -EINVAL; - goto exit; - } - - if (strcmp(param->u.crypt.alg, "WEP") == 0) { - wep_key_idx = param->u.crypt.idx; - wep_key_len = param->u.crypt.key_len; - - if (wep_key_len <= 0) { - ret = -EINVAL; - goto exit; - } - - if (psecuritypriv->bWepDefaultKeyIdxSet == 0) { - /* wep default key has not been set, so use this key index as default key. */ - - wep_key_len = wep_key_len <= 5 ? 5 : 13; - - psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; - psecuritypriv->dot11_privacy_algrthm = _WEP40_; - psecuritypriv->dot118021XGrpPrivacy = _WEP40_; - - if (wep_key_len == 13) { - psecuritypriv->dot11_privacy_algrthm = _WEP104_; - psecuritypriv->dot118021XGrpPrivacy = _WEP104_; - } - - psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; - } - - memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len); - - psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len; - - rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0, true); - - goto exit; - } - - if (padapter->securitypriv.dot11_auth_algrthm == dot11_auth_algrthm_8021x) { /* 802_1x */ - struct sta_info *psta, *pbcmc_sta; - struct sta_priv *pstapriv = &padapter->stapriv; - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE)) { /* sta mode */ - psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); - if (psta) { - /* Jeff: don't disable ieee8021x_blocked while clearing key */ - if (strcmp(param->u.crypt.alg, "none") != 0) - psta->ieee8021x_blocked = false; - - if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || - (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { - psta->dot118021XPrivacy = padapter->securitypriv.dot11_privacy_algrthm; - } - - if (param->u.crypt.set_tx == 1) { /* pairwise key */ - - memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - - if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */ - memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); - memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); - - padapter->securitypriv.busetkipkey = false; - /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */ - } - - rtw_setstakey_cmd(padapter, psta, true, true); - } else { /* group key */ - if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) { - memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); - memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); - padapter->securitypriv.binstallGrpkey = true; - - padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx; - rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, true); - } else if (strcmp(param->u.crypt.alg, "BIP") == 0) { - /* save the IGTK key, length 16 bytes */ - memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); - padapter->securitypriv.dot11wBIPKeyid = param->u.crypt.idx; - padapter->securitypriv.binstallBIPkey = true; - } - } - } - - pbcmc_sta = rtw_get_bcmc_stainfo(padapter); - if (pbcmc_sta) { - /* Jeff: don't disable ieee8021x_blocked while clearing key */ - if (strcmp(param->u.crypt.alg, "none") != 0) - pbcmc_sta->ieee8021x_blocked = false; - - if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || - (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { - pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11_privacy_algrthm; - } - } - } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */ - } - } - -exit: - - return ret; -} - -static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, - const u8 *mac_addr, struct key_params *params) -{ - char *alg_name; - u32 param_len; - struct ieee_param *param = NULL; - int ret = 0; - struct net_device *ndev = wdev->netdev; - struct adapter *padapter = rtw_netdev_priv(ndev); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - param_len = sizeof(struct ieee_param) + params->key_len; - param = kzalloc(param_len, GFP_KERNEL); - if (!param) - return -ENOMEM; - - param->cmd = IEEE_CMD_SET_ENCRYPTION; - eth_broadcast_addr(param->sta_addr); - - switch (params->cipher) { - case IW_AUTH_CIPHER_NONE: - /* todo: remove key */ - /* remove = 1; */ - alg_name = "none"; - break; - case WLAN_CIPHER_SUITE_WEP40: - case WLAN_CIPHER_SUITE_WEP104: - alg_name = "WEP"; - break; - case WLAN_CIPHER_SUITE_TKIP: - alg_name = "TKIP"; - break; - case WLAN_CIPHER_SUITE_CCMP: - alg_name = "CCMP"; - break; - case WLAN_CIPHER_SUITE_AES_CMAC: - alg_name = "BIP"; - break; - default: - ret = -ENOTSUPP; - goto addkey_end; - } - - strscpy(param->u.crypt.alg, alg_name); - - if (!mac_addr || is_broadcast_ether_addr(mac_addr)) - param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */ - else - param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */ - - param->u.crypt.idx = key_index; - - if (params->seq_len && params->seq) - memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len); - - if (params->key_len && params->key) { - param->u.crypt.key_len = params->key_len; - memcpy(param->u.crypt.key, (u8 *)params->key, params->key_len); - } - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - ret = rtw_cfg80211_set_encryption(ndev, param, param_len); - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - if (mac_addr) - memcpy(param->sta_addr, mac_addr, ETH_ALEN); - - ret = rtw_cfg80211_ap_set_encryption(ndev, param, param_len); - } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { - ret = rtw_cfg80211_set_encryption(ndev, param, param_len); - } - -addkey_end: - kfree(param); - - return ret; -} - -static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, - const u8 *mac_addr, void *cookie, - void (*callback)(void *cookie, - struct key_params*)) -{ - return 0; -} - -static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct wireless_dev *wdev, - int link_id, u8 key_index, bool pairwise, - const u8 *mac_addr) -{ - struct adapter *padapter = rtw_netdev_priv(wdev->netdev); - struct security_priv *psecuritypriv = &padapter->securitypriv; - - if (key_index == psecuritypriv->dot11PrivacyKeyIndex) { - /* clear the flag of wep default key set. */ - psecuritypriv->bWepDefaultKeyIdxSet = 0; - } - - return 0; -} - -static int cfg80211_rtw_set_default_key(struct wiphy *wiphy, - struct net_device *ndev, int link_id, - u8 key_index, bool unicast, - bool multicast) -{ - struct adapter *padapter = rtw_netdev_priv(ndev); - struct security_priv *psecuritypriv = &padapter->securitypriv; - - if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11_privacy_algrthm == _WEP40_) || (psecuritypriv->dot11_privacy_algrthm == _WEP104_))) { /* set wep default key */ - psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; - - psecuritypriv->dot11PrivacyKeyIndex = key_index; - - psecuritypriv->dot11_privacy_algrthm = _WEP40_; - psecuritypriv->dot118021XGrpPrivacy = _WEP40_; - if (psecuritypriv->dot11DefKeylen[key_index] == 13) { - psecuritypriv->dot11_privacy_algrthm = _WEP104_; - psecuritypriv->dot118021XGrpPrivacy = _WEP104_; - } - - psecuritypriv->bWepDefaultKeyIdxSet = 1; /* set the flag to represent that wep default key has been set */ - } - - return 0; -} - -static int cfg80211_rtw_get_station(struct wiphy *wiphy, - struct wireless_dev *wdev, - const u8 *mac, - struct station_info *sinfo) -{ - int ret = 0; - struct net_device *ndev = wdev_to_ndev(wdev); - struct adapter *padapter = rtw_netdev_priv(ndev); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - - sinfo->filled = 0; - - if (!mac) { - ret = -ENOENT; - goto exit; - } - - psta = rtw_get_stainfo(pstapriv, (u8 *)mac); - if (!psta) { - ret = -ENOENT; - goto exit; - } - - /* for infra./P2PClient mode */ - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) - && check_fwstate(pmlmepriv, _FW_LINKED)) { - struct wlan_network *cur_network = &(pmlmepriv->cur_network); - - if (memcmp((u8 *)mac, cur_network->network.mac_address, ETH_ALEN)) { - ret = -ENOENT; - goto exit; - } - - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); - sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength); - - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); - sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter); - - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS); - sinfo->rx_packets = sta_rx_data_pkts(psta); - - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS); - sinfo->tx_packets = psta->sta_stats.tx_pkts; - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); - } - - /* for Ad-Hoc/AP mode */ - if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || - check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) || - check_fwstate(pmlmepriv, WIFI_AP_STATE)) && - check_fwstate(pmlmepriv, _FW_LINKED)) { - /* TODO: should acquire station info... */ - } - -exit: - return ret; -} - -static int cfg80211_rtw_change_iface(struct wiphy *wiphy, - struct net_device *ndev, - enum nl80211_iftype type, - struct vif_params *params) -{ - enum nl80211_iftype old_type; - struct adapter *padapter = rtw_netdev_priv(ndev); - struct wireless_dev *rtw_wdev = padapter->rtw_wdev; - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - int ret = 0; - - if (adapter_to_dvobj(padapter)->processing_dev_remove) { - ret = -EPERM; - goto exit; - } - - { - if (netdev_open(ndev) != 0) { - ret = -EPERM; - goto exit; - } - } - - if (rtw_pwr_wakeup(padapter) == _FAIL) { - ret = -EPERM; - goto exit; - } - - old_type = rtw_wdev->iftype; - - if (old_type != type) { - pmlmeext->action_public_rxseq = 0xffff; - pmlmeext->action_public_dialog_token = 0xff; - } - - if (type != NL80211_IFTYPE_ADHOC && - type != NL80211_IFTYPE_STATION && - type != NL80211_IFTYPE_AP) { - ret = -EOPNOTSUPP; - goto exit; - } - - rtw_wdev->iftype = type; - - if (!rtw_set_802_11_infrastructure_mode(padapter, type)) { - rtw_wdev->iftype = old_type; - ret = -EPERM; - goto exit; - } - - rtw_setopmode_cmd(padapter, type, true); - -exit: - - return ret; -} - -void rtw_cfg80211_indicate_scan_done(struct adapter *adapter, bool aborted) -{ - struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter); - struct cfg80211_scan_info info = { - .aborted = aborted - }; - - spin_lock_bh(&pwdev_priv->scan_req_lock); - if (pwdev_priv->scan_request) { - /* avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); */ - if (pwdev_priv->scan_request->wiphy == pwdev_priv->rtw_wdev->wiphy) - cfg80211_scan_done(pwdev_priv->scan_request, &info); - - pwdev_priv->scan_request = NULL; - } - spin_unlock_bh(&pwdev_priv->scan_req_lock); -} - -void rtw_cfg80211_unlink_bss(struct adapter *padapter, struct wlan_network *pnetwork) -{ - struct wireless_dev *pwdev = padapter->rtw_wdev; - struct wiphy *wiphy = pwdev->wiphy; - struct cfg80211_bss *bss = NULL; - struct wlan_bssid_ex *select_network = &pnetwork->network; - - bss = cfg80211_get_bss(wiphy, NULL/*notify_channel*/, - select_network->mac_address, - select_network->ssid.ssid, - select_network->ssid.ssid_length, - IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); - - if (bss) { - cfg80211_unlink_bss(wiphy, bss); - cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss); - } -} - -void rtw_cfg80211_surveydone_event_callback(struct adapter *padapter) -{ - struct list_head *plist, *phead; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct __queue *queue = &(pmlmepriv->scanned_queue); - struct wlan_network *pnetwork = NULL; - - spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); - - phead = get_list_head(queue); - list_for_each(plist, phead) - { - pnetwork = list_entry(plist, struct wlan_network, list); - - /* report network only if the current channel set contains the channel to which this network belongs */ - if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.configuration.ds_config) >= 0 - && true == rtw_validate_ssid(&(pnetwork->network.ssid))) { - /* ev =translate_scan(padapter, a, pnetwork, ev, stop); */ - rtw_cfg80211_inform_bss(padapter, pnetwork); - } - } - - spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); -} - -static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *buf, int len) -{ - int ret = 0; - unsigned int wps_ielen = 0; - u8 *wps_ie; - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - - if (len > 0) { - wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen); - if (wps_ie) { - if (pmlmepriv->wps_probe_req_ie) { - pmlmepriv->wps_probe_req_ie_len = 0; - kfree(pmlmepriv->wps_probe_req_ie); - pmlmepriv->wps_probe_req_ie = NULL; - } - - pmlmepriv->wps_probe_req_ie = kmemdup(wps_ie, wps_ielen, GFP_KERNEL); - if (!pmlmepriv->wps_probe_req_ie) - return -EINVAL; - - pmlmepriv->wps_probe_req_ie_len = wps_ielen; - } - } - - return ret; -} - -static int cfg80211_rtw_scan(struct wiphy *wiphy - , struct cfg80211_scan_request *request) -{ - struct net_device *ndev = wdev_to_ndev(request->wdev); - int i; - u8 _status = false; - int ret = 0; - struct ndis_802_11_ssid *ssid = NULL; - struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT]; - u8 survey_times = 3; - u8 survey_times_for_one_ch = 6; - struct cfg80211_ssid *ssids = request->ssids; - int j = 0; - bool need_indicate_scan_done = false; - - struct adapter *padapter; - struct rtw_wdev_priv *pwdev_priv; - struct mlme_priv *pmlmepriv; - - if (!ndev) { - ret = -EINVAL; - goto exit; - } - - padapter = rtw_netdev_priv(ndev); - pwdev_priv = adapter_wdev_data(padapter); - pmlmepriv = &padapter->mlmepriv; -/* endif */ - - spin_lock_bh(&pwdev_priv->scan_req_lock); - pwdev_priv->scan_request = request; - spin_unlock_bh(&pwdev_priv->scan_req_lock); - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS | _FW_UNDER_SURVEY | - _FW_UNDER_LINKING)) { - need_indicate_scan_done = true; - goto check_need_indicate_scan_done; - } - } - - rtw_ps_deny(padapter, PS_DENY_SCAN); - if (rtw_pwr_wakeup(padapter) == _FAIL) { - need_indicate_scan_done = true; - goto check_need_indicate_scan_done; - } - - if (request->ie && request->ie_len > 0) - rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len); - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) { - need_indicate_scan_done = true; - goto check_need_indicate_scan_done; - } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) { - ret = -EBUSY; - goto check_need_indicate_scan_done; - } - - if (pmlmepriv->link_detect_info.busy_traffic) { - static unsigned long lastscantime; - unsigned long passtime; - - passtime = jiffies_to_msecs(jiffies - lastscantime); - lastscantime = jiffies; - if (passtime > 12000) { - need_indicate_scan_done = true; - goto check_need_indicate_scan_done; - } - } - - if (rtw_is_scan_deny(padapter)) { - need_indicate_scan_done = true; - goto check_need_indicate_scan_done; - } - - ssid = kzalloc_objs(*ssid, RTW_SSID_SCAN_AMOUNT); - if (!ssid) { - ret = -ENOMEM; - goto check_need_indicate_scan_done; - } - - /* parsing request ssids, n_ssids */ - for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) { - memcpy(ssid[i].ssid, ssids[i].ssid, ssids[i].ssid_len); - ssid[i].ssid_length = ssids[i].ssid_len; - } - - /* parsing channels, n_channels */ - memset(ch, 0, sizeof(struct rtw_ieee80211_channel) * RTW_CHANNEL_SCAN_AMOUNT); - for (i = 0; i < request->n_channels && i < RTW_CHANNEL_SCAN_AMOUNT; i++) { - ch[i].hw_value = request->channels[i]->hw_value; - ch[i].flags = request->channels[i]->flags; - } - - spin_lock_bh(&pmlmepriv->lock); - if (request->n_channels == 1) { - for (i = 1; i < survey_times_for_one_ch; i++) - memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel)); - _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times_for_one_ch); - } else if (request->n_channels <= 4) { - for (j = request->n_channels - 1; j >= 0; j--) - for (i = 0; i < survey_times; i++) - memcpy(&ch[j * survey_times + i], &ch[j], sizeof(struct rtw_ieee80211_channel)); - _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times * request->n_channels); - } else { - _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, NULL, 0); - } - spin_unlock_bh(&pmlmepriv->lock); - - if (!_status) - ret = -1; - -check_need_indicate_scan_done: - kfree(ssid); - if (need_indicate_scan_done) { - rtw_cfg80211_surveydone_event_callback(padapter); - rtw_cfg80211_indicate_scan_done(padapter, false); - } - - rtw_ps_deny_cancel(padapter, PS_DENY_SCAN); - -exit: - return ret; -} - -static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, int radio_idx, - u32 changed) -{ - return 0; -} - -static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version) -{ - if (!wpa_version) { - psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; - return 0; - } - - if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) - psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK; - - return 0; -} - -static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv, - enum nl80211_auth_type sme_auth_type) -{ - switch (sme_auth_type) { - case NL80211_AUTHTYPE_AUTOMATIC: - - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_auto; - - break; - case NL80211_AUTHTYPE_OPEN_SYSTEM: - - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_open; - - if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA) - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_8021x; - - break; - case NL80211_AUTHTYPE_SHARED_KEY: - - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_shared; - - psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; - - break; - default: - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_open; - /* return -ENOTSUPP; */ - } - - return 0; -} - -static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast) -{ - u32 ndisencryptstatus = Ndis802_11EncryptionDisabled; - - u32 *profile_cipher = ucast ? &psecuritypriv->dot11_privacy_algrthm : - &psecuritypriv->dot118021XGrpPrivacy; - - if (!cipher) { - *profile_cipher = _NO_PRIVACY_; - psecuritypriv->ndisencryptstatus = ndisencryptstatus; - return 0; - } - - switch (cipher) { - case IW_AUTH_CIPHER_NONE: - *profile_cipher = _NO_PRIVACY_; - ndisencryptstatus = Ndis802_11EncryptionDisabled; - break; - case WLAN_CIPHER_SUITE_WEP40: - *profile_cipher = _WEP40_; - ndisencryptstatus = Ndis802_11Encryption1Enabled; - break; - case WLAN_CIPHER_SUITE_WEP104: - *profile_cipher = _WEP104_; - ndisencryptstatus = Ndis802_11Encryption1Enabled; - break; - case WLAN_CIPHER_SUITE_TKIP: - *profile_cipher = _TKIP_; - ndisencryptstatus = Ndis802_11Encryption2Enabled; - break; - case WLAN_CIPHER_SUITE_CCMP: - *profile_cipher = _AES_; - ndisencryptstatus = Ndis802_11Encryption3Enabled; - break; - default: - return -ENOTSUPP; - } - - if (ucast) { - psecuritypriv->ndisencryptstatus = ndisencryptstatus; - - /* if (psecuritypriv->dot11_privacy_algrthm >= _AES_) */ - /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */ - } - - return 0; -} - -static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt) -{ - if (key_mgt == WLAN_AKM_SUITE_8021X) - /* auth_type = UMAC_AUTH_TYPE_8021X; */ - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_8021x; - else if (key_mgt == WLAN_AKM_SUITE_PSK) { - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_8021x; - } - - return 0; -} - -static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t ielen) -{ - u8 *buf = NULL; - int group_cipher = 0, pairwise_cipher = 0; - int ret = 0; - int wpa_ielen = 0; - int wpa2_ielen = 0; - u8 *pwpa, *pwpa2; - u8 null_addr[] = {0, 0, 0, 0, 0, 0}; - - if (!pie || !ielen) { - /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */ - _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); - goto exit; - } - - if (ielen > MAX_WPA_IE_LEN + MAX_WPS_IE_LEN + MAX_P2P_IE_LEN) { - ret = -EINVAL; - goto exit; - } - - buf = kmemdup(pie, ielen, GFP_KERNEL); - if (!buf) { - ret = -ENOMEM; - goto exit; - } - - if (ielen < RSN_HEADER_LEN) { - ret = -1; - goto exit; - } - - pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen); - if (pwpa && wpa_ielen > 0) { - if (wpa_ielen + 2 > sizeof(padapter->securitypriv.supplicant_ie)) { - ret = -EINVAL; - goto exit; - } - if (rtw_parse_wpa_ie(pwpa, wpa_ielen + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { - padapter->securitypriv.dot11_auth_algrthm = dot11_auth_algrthm_8021x; - padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; - memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen + 2); - } - } - - pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen); - if (pwpa2 && wpa2_ielen > 0) { - if (wpa2_ielen + 2 > sizeof(padapter->securitypriv.supplicant_ie)) { - ret = -EINVAL; - goto exit; - } - if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { - padapter->securitypriv.dot11_auth_algrthm = dot11_auth_algrthm_8021x; - padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; - memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen + 2); - } - } - - if (group_cipher == 0) - group_cipher = WPA_CIPHER_NONE; - - if (pairwise_cipher == 0) - pairwise_cipher = WPA_CIPHER_NONE; - - switch (group_cipher) { - case WPA_CIPHER_NONE: - padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; - break; - case WPA_CIPHER_WEP40: - padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; - break; - case WPA_CIPHER_TKIP: - padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; - break; - case WPA_CIPHER_CCMP: - padapter->securitypriv.dot118021XGrpPrivacy = _AES_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; - break; - case WPA_CIPHER_WEP104: - padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; - break; - } - - switch (pairwise_cipher) { - case WPA_CIPHER_NONE: - padapter->securitypriv.dot11_privacy_algrthm = _NO_PRIVACY_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; - break; - case WPA_CIPHER_WEP40: - padapter->securitypriv.dot11_privacy_algrthm = _WEP40_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; - break; - case WPA_CIPHER_TKIP: - padapter->securitypriv.dot11_privacy_algrthm = _TKIP_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; - break; - case WPA_CIPHER_CCMP: - padapter->securitypriv.dot11_privacy_algrthm = _AES_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; - break; - case WPA_CIPHER_WEP104: - padapter->securitypriv.dot11_privacy_algrthm = _WEP104_; - padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; - break; - } - - {/* handle wps_ie */ - unsigned int wps_ielen; - u8 *wps_ie; - - wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen); - if (wps_ie && wps_ielen > 0) { - padapter->securitypriv.wps_ie_len = min_t(unsigned int, wps_ielen, MAX_WPS_IE_LEN); - memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len); - set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS); - } else { - _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); - } - } - - /* TKIP and AES disallow multicast packets until installing group key */ - if (padapter->securitypriv.dot11_privacy_algrthm == _TKIP_ - || padapter->securitypriv.dot11_privacy_algrthm == _TKIP_WTMIC_ - || padapter->securitypriv.dot11_privacy_algrthm == _AES_) - /* WPS open need to enable multicast */ - /* check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == true) */ - rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr); - -exit: - kfree(buf); - if (ret) - _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); - return ret; -} - -static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev, - struct cfg80211_ibss_params *params) -{ - struct adapter *padapter = rtw_netdev_priv(ndev); - struct ndis_802_11_ssid ndis_ssid; - struct security_priv *psecuritypriv = &padapter->securitypriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - int ret = 0; - - if (rtw_pwr_wakeup(padapter) == _FAIL) { - ret = -EPERM; - goto exit; - } - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - ret = -EPERM; - goto exit; - } - - if (!params->ssid || !params->ssid_len) { - ret = -EINVAL; - goto exit; - } - - if (params->ssid_len > IW_ESSID_MAX_SIZE) { - ret = -E2BIG; - goto exit; - } - - memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); - ndis_ssid.ssid_length = params->ssid_len; - memcpy(ndis_ssid.ssid, (u8 *)params->ssid, params->ssid_len); - - psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled; - psecuritypriv->dot11_privacy_algrthm = _NO_PRIVACY_; - psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_open; /* open system */ - psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; - - ret = rtw_cfg80211_set_auth_type(psecuritypriv, NL80211_AUTHTYPE_OPEN_SYSTEM); - rtw_set_802_11_authentication_mode(padapter, psecuritypriv->ndisauthtype); - - if (!rtw_set_802_11_ssid(padapter, &ndis_ssid)) { - ret = -1; - goto exit; - } - -exit: - return ret; -} - -static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) -{ - struct adapter *padapter = rtw_netdev_priv(ndev); - struct wireless_dev *rtw_wdev = padapter->rtw_wdev; - enum nl80211_iftype old_type; - int ret = 0; - - old_type = rtw_wdev->iftype; - - rtw_set_to_roam(padapter, 0); - - if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { - rtw_scan_abort(padapter); - LeaveAllPowerSaveMode(padapter); - - rtw_wdev->iftype = NL80211_IFTYPE_STATION; - - if (!rtw_set_802_11_infrastructure_mode(padapter, NL80211_IFTYPE_STATION)) { - rtw_wdev->iftype = old_type; - ret = -EPERM; - goto leave_ibss; - } - rtw_setopmode_cmd(padapter, NL80211_IFTYPE_STATION, true); - } - -leave_ibss: - return ret; -} - -static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev, - struct cfg80211_connect_params *sme) -{ - int ret = 0; - enum ndis_802_11_authentication_mode authmode; - struct ndis_802_11_ssid ndis_ssid; - struct adapter *padapter = rtw_netdev_priv(ndev); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - - padapter->mlmepriv.not_indic_disco = true; - - if (adapter_wdev_data(padapter)->block) { - ret = -EBUSY; - goto exit; - } - - rtw_ps_deny(padapter, PS_DENY_JOIN); - if (rtw_pwr_wakeup(padapter) == _FAIL) { - ret = -EPERM; - goto exit; - } - - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - ret = -EPERM; - goto exit; - } - - if (!sme->ssid || !sme->ssid_len) { - ret = -EINVAL; - goto exit; - } - - if (sme->ssid_len > IW_ESSID_MAX_SIZE) { - ret = -E2BIG; - goto exit; - } - - memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); - ndis_ssid.ssid_length = sme->ssid_len; - memcpy(ndis_ssid.ssid, (u8 *)sme->ssid, sme->ssid_len); - - if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) { - ret = -EBUSY; - goto exit; - } - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - rtw_scan_abort(padapter); - - psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled; - psecuritypriv->dot11_privacy_algrthm = _NO_PRIVACY_; - psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_open; /* open system */ - psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; - - ret = rtw_cfg80211_set_wpa_version(psecuritypriv, sme->crypto.wpa_versions); - if (ret < 0) - goto exit; - - ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type); - - if (ret < 0) - goto exit; - - ret = rtw_cfg80211_set_wpa_ie(padapter, (u8 *)sme->ie, sme->ie_len); - if (ret < 0) - goto exit; - - if (sme->crypto.n_ciphers_pairwise) { - ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], true); - if (ret < 0) - goto exit; - } - - /* For WEP Shared auth */ - if ((psecuritypriv->dot11_auth_algrthm == dot11_auth_algrthm_shared || - psecuritypriv->dot11_auth_algrthm == dot11_auth_algrthm_auto) && sme->key) { - u32 wep_key_idx, wep_key_len, wep_total_len; - struct ndis_802_11_wep *pwep = NULL; - - wep_key_idx = sme->key_idx; - wep_key_len = sme->key_len; - - if (sme->key_idx > WEP_KEYS) { - ret = -EINVAL; - goto exit; - } - - if (wep_key_len > 0) { - wep_key_len = wep_key_len <= 5 ? 5 : 13; - wep_total_len = wep_key_len + - offsetof(struct ndis_802_11_wep, key_material); - pwep = kzalloc(wep_total_len, GFP_KERNEL); - if (!pwep) { - ret = -ENOMEM; - goto exit; - } - - pwep->key_length = wep_key_len; - pwep->length = wep_total_len; - - if (wep_key_len == 13) { - padapter->securitypriv.dot11_privacy_algrthm = _WEP104_; - padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; - } - } else { - ret = -EINVAL; - goto exit; - } - - pwep->key_index = wep_key_idx; - pwep->key_index |= 0x80000000; - - memcpy(pwep->key_material, sme->key, pwep->key_length); - - if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL) - ret = -EOPNOTSUPP; - - kfree(pwep); - - if (ret < 0) - goto exit; - } - - ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, false); - if (ret < 0) - return ret; - - if (sme->crypto.n_akm_suites) { - ret = rtw_cfg80211_set_key_mgt(psecuritypriv, sme->crypto.akm_suites[0]); - if (ret < 0) - goto exit; - } - - authmode = psecuritypriv->ndisauthtype; - rtw_set_802_11_authentication_mode(padapter, authmode); - - /* rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */ - - if (!rtw_set_802_11_connect(padapter, (u8 *)sme->bssid, &ndis_ssid)) { - ret = -1; - goto exit; - } - -exit: - - rtw_ps_deny_cancel(padapter, PS_DENY_JOIN); - - padapter->mlmepriv.not_indic_disco = false; - - return ret; -} - -static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev, - u16 reason_code) -{ - struct adapter *padapter = rtw_netdev_priv(ndev); - - rtw_set_to_roam(padapter, 0); - - rtw_scan_abort(padapter); - LeaveAllPowerSaveMode(padapter); - rtw_disassoc_cmd(padapter, 500, false); - - rtw_indicate_disconnect(padapter); - - rtw_free_assoc_resources(padapter, 1); - rtw_pwr_wakeup(padapter); - - return 0; -} - -static int cfg80211_rtw_set_txpower(struct wiphy *wiphy, - struct wireless_dev *wdev, int radio_idx, - enum nl80211_tx_power_setting type, int mbm) -{ - return 0; -} - -static int cfg80211_rtw_get_txpower(struct wiphy *wiphy, - struct wireless_dev *wdev, - int radio_idx, - unsigned int link_id, int *dbm) -{ - *dbm = (12); - - return 0; -} - -inline bool rtw_cfg80211_pwr_mgmt(struct adapter *adapter) -{ - struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(adapter); - - return rtw_wdev_priv->power_mgmt; -} - -static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy, - struct net_device *ndev, - bool enabled, int timeout) -{ - struct adapter *padapter = rtw_netdev_priv(ndev); - struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(padapter); - - rtw_wdev_priv->power_mgmt = enabled; - - if (!enabled) - LPS_Leave(padapter, "CFG80211_PWRMGMT"); - - return 0; -} - -static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy, - struct net_device *ndev, - struct cfg80211_pmksa *pmksa) -{ - u8 index, blInserted = false; - struct adapter *padapter = rtw_netdev_priv(ndev); - struct security_priv *psecuritypriv = &padapter->securitypriv; - - if (is_zero_ether_addr((u8 *)pmksa->bssid)) - return -EINVAL; - - blInserted = false; - - /* overwrite PMKID */ - for (index = 0 ; index < NUM_PMKID_CACHE; index++) { - if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) { - memcpy(psecuritypriv->PMKIDList[index].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); - psecuritypriv->PMKIDList[index].bUsed = true; - psecuritypriv->PMKIDIndex = index + 1; - blInserted = true; - break; - } - } - - if (!blInserted) { - memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, (u8 *)pmksa->bssid, ETH_ALEN); - memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); - - psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true; - psecuritypriv->PMKIDIndex++; - if (psecuritypriv->PMKIDIndex == 16) - psecuritypriv->PMKIDIndex = 0; - } - - return 0; -} - -static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy, - struct net_device *ndev, - struct cfg80211_pmksa *pmksa) -{ - u8 index, bMatched = false; - struct adapter *padapter = rtw_netdev_priv(ndev); - struct security_priv *psecuritypriv = &padapter->securitypriv; - - for (index = 0 ; index < NUM_PMKID_CACHE; index++) { - if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) { - /* - * BSSID is matched, the same AP => Remove this PMKID information - * and reset it. - */ - eth_zero_addr(psecuritypriv->PMKIDList[index].Bssid); - memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN); - psecuritypriv->PMKIDList[index].bUsed = false; - bMatched = true; - break; - } - } - - if (!bMatched) - return -EINVAL; - - return 0; -} - -static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy, - struct net_device *ndev) -{ - struct adapter *padapter = rtw_netdev_priv(ndev); - struct security_priv *psecuritypriv = &padapter->securitypriv; - - memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); - psecuritypriv->PMKIDIndex = 0; - - return 0; -} - -void rtw_cfg80211_indicate_sta_assoc(struct adapter *padapter, u8 *pmgmt_frame, unsigned int frame_len) -{ - struct wireless_dev *wdev = padapter->rtw_wdev; - - { - struct station_info sinfo = {}; - u8 ie_offset; - - if (GetFrameSubType(pmgmt_frame) == WIFI_ASSOCREQ) - ie_offset = _ASOCREQ_IE_OFFSET_; - else /* WIFI_REASSOCREQ */ - ie_offset = _REASOCREQ_IE_OFFSET_; - - sinfo.filled = 0; - sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset; - sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset; - cfg80211_new_sta(wdev, GetAddr2Ptr(pmgmt_frame), &sinfo, GFP_ATOMIC); - } -} - -void rtw_cfg80211_indicate_sta_disassoc(struct adapter *padapter, unsigned char *da, unsigned short reason) -{ - struct wireless_dev *wdev = padapter->rtw_wdev; - - cfg80211_del_sta(wdev, da, GFP_ATOMIC); -} - -static u8 rtw_get_chan_type(struct adapter *adapter) -{ - struct mlme_ext_priv *mlme_ext = &adapter->mlmeextpriv; - - switch (mlme_ext->cur_bwmode) { - case CHANNEL_WIDTH_20: - if (is_supported_ht(adapter->registrypriv.wireless_mode)) - return NL80211_CHAN_HT20; - else - return NL80211_CHAN_NO_HT; - case CHANNEL_WIDTH_40: - if (mlme_ext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) - return NL80211_CHAN_HT40PLUS; - else - return NL80211_CHAN_HT40MINUS; - default: - return NL80211_CHAN_HT20; - } - - return NL80211_CHAN_HT20; -} - -static int cfg80211_rtw_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev, - unsigned int link_id, - struct cfg80211_chan_def *chandef) -{ - struct adapter *adapter = wiphy_to_adapter(wiphy); - struct registry_priv *registrypriv = &adapter->registrypriv; - enum nl80211_channel_type chan_type; - struct ieee80211_channel *chan = NULL; - int channel; - int freq; - - if (!adapter->rtw_wdev) - return -ENODEV; - - channel = rtw_get_oper_ch(adapter); - if (!channel) - return -ENODATA; - - freq = rtw_ieee80211_channel_to_frequency(channel); - - chan = ieee80211_get_channel(adapter->rtw_wdev->wiphy, freq); - - if (registrypriv->ht_enable) { - chan_type = rtw_get_chan_type(adapter); - cfg80211_chandef_create(chandef, chan, chan_type); - } else { - cfg80211_chandef_create(chandef, chan, NL80211_CHAN_NO_HT); - } - - return 0; -} - -static netdev_tx_t rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev) -{ - int rtap_len; - int qos_len = 0; - int dot11_hdr_len = 24; - int snap_len = 6; - unsigned char *pdata; - u16 frame_control; - unsigned char src_mac_addr[6]; - unsigned char dst_mac_addr[6]; - struct ieee80211_hdr *dot11_hdr; - struct ieee80211_radiotap_header *rtap_hdr; - struct adapter *padapter = rtw_netdev_priv(ndev); - - if (!skb) - goto fail; - - if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) - goto fail; - - rtap_hdr = (struct ieee80211_radiotap_header *)skb->data; - if (unlikely(rtap_hdr->it_version)) - goto fail; - - rtap_len = ieee80211_get_radiotap_len(skb->data); - if (unlikely(skb->len < rtap_len)) - goto fail; - - if (rtap_len != 14) - goto fail; - - /* Skip the ratio tap header */ - skb_pull(skb, rtap_len); - if (skb->len < dot11_hdr_len) - goto fail; - - dot11_hdr = (struct ieee80211_hdr *)skb->data; - frame_control = le16_to_cpu(dot11_hdr->frame_control); - /* Check if the QoS bit is set */ - if ((frame_control & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { - /* Check if this ia a Wireless Distribution System (WDS) frame - * which has 4 MAC addresses - */ - if (frame_control & 0x0080) - qos_len = 2; - if ((frame_control & 0x0300) == 0x0300) - dot11_hdr_len += 6; - if (skb->len < dot11_hdr_len + qos_len + snap_len) - goto fail; - - memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr)); - memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr)); - - /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for - * two MAC addresses - */ - skb_pull(skb, dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2); - pdata = (unsigned char *)skb->data; - memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr)); - memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr)); - - /* Use the real net device to transmit the packet */ - _rtw_xmit_entry(skb, padapter->pnetdev); - return NETDEV_TX_OK; - - } else if ((frame_control & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) == - (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION)) { - /* only for action frames */ - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - /* u8 category, action, OUI_Subtype, dialogToken = 0; */ - /* unsigned char *frame_body; */ - struct ieee80211_hdr *pwlanhdr; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - u8 *buf = skb->data; - u32 len = skb->len; - u8 category, action; - - if (!rtw_action_frame_parse(buf, len, &category, &action)) - goto fail; - - /* starting alloc mgmt frame to dump it */ - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) - goto fail; - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->retry_ctrl = false; - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - - memcpy(pframe, buf, len); - pattrib->pktlen = len; - - pwlanhdr = (struct ieee80211_hdr *)pframe; - /* update seq number */ - pmlmeext->mgnt_seq = GetSequence(pwlanhdr); - pattrib->seqnum = pmlmeext->mgnt_seq; - pmlmeext->mgnt_seq++; - - pattrib->last_txcmdsz = pattrib->pktlen; - - dump_mgntframe(padapter, pmgntframe); - } - -fail: - - dev_kfree_skb_any(skb); - - return NETDEV_TX_OK; -} - -static const struct net_device_ops rtw_cfg80211_monitor_if_ops = { - .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry, -}; - -static int rtw_cfg80211_add_monitor_if(struct adapter *padapter, char *name, struct net_device **ndev) -{ - int ret = 0; - struct net_device *mon_ndev = NULL; - struct wireless_dev *mon_wdev = NULL; - struct rtw_netdev_priv_indicator *pnpi; - struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter); - - if (!name) { - ret = -EINVAL; - goto out; - } - - if (pwdev_priv->pmon_ndev) { - ret = -EBUSY; - goto out; - } - - mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator)); - if (!mon_ndev) { - ret = -ENOMEM; - goto out; - } - - mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP; - strscpy(mon_ndev->name, name); - mon_ndev->needs_free_netdev = true; - mon_ndev->priv_destructor = rtw_ndev_destructor; - - mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops; - - pnpi = netdev_priv(mon_ndev); - pnpi->priv = padapter; - pnpi->sizeof_priv = sizeof(struct adapter); - - /* wdev */ - mon_wdev = kzalloc_obj(*mon_wdev); - if (!mon_wdev) { - ret = -ENOMEM; - goto out; - } - - mon_wdev->wiphy = padapter->rtw_wdev->wiphy; - mon_wdev->netdev = mon_ndev; - mon_wdev->iftype = NL80211_IFTYPE_MONITOR; - mon_ndev->ieee80211_ptr = mon_wdev; - - ret = cfg80211_register_netdevice(mon_ndev); - if (ret) - goto out; - - *ndev = pwdev_priv->pmon_ndev = mon_ndev; - memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ + 1); - -out: - if (ret && mon_wdev) { - kfree(mon_wdev); - mon_wdev = NULL; - } - - if (ret && mon_ndev) { - free_netdev(mon_ndev); - *ndev = mon_ndev = NULL; - } - - return ret; -} - -static struct wireless_dev * - cfg80211_rtw_add_virtual_intf( - struct wiphy *wiphy, - const char *name, - unsigned char name_assign_type, - enum nl80211_iftype type, struct vif_params *params) -{ - int ret = 0; - struct net_device *ndev = NULL; - struct adapter *padapter = wiphy_to_adapter(wiphy); - - switch (type) { - case NL80211_IFTYPE_ADHOC: - case NL80211_IFTYPE_AP_VLAN: - case NL80211_IFTYPE_WDS: - case NL80211_IFTYPE_MESH_POINT: - ret = -ENODEV; - break; - case NL80211_IFTYPE_MONITOR: - ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev); - break; - case NL80211_IFTYPE_P2P_CLIENT: - case NL80211_IFTYPE_STATION: - ret = -ENODEV; - break; - case NL80211_IFTYPE_P2P_GO: - case NL80211_IFTYPE_AP: - ret = -ENODEV; - break; - default: - ret = -ENODEV; - break; - } - - return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret); -} - -static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy, - struct wireless_dev *wdev -) -{ - struct net_device *ndev = wdev_to_ndev(wdev); - int ret = 0; - struct adapter *adapter; - struct rtw_wdev_priv *pwdev_priv; - - if (!ndev) { - ret = -EINVAL; - goto exit; - } - - adapter = rtw_netdev_priv(ndev); - pwdev_priv = adapter_wdev_data(adapter); - - cfg80211_unregister_netdevice(ndev); - - if (ndev == pwdev_priv->pmon_ndev) { - pwdev_priv->pmon_ndev = NULL; - pwdev_priv->ifname_mon[0] = '\0'; - } - -exit: - return ret; -} - -static int rtw_add_beacon(struct adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len) -{ - int ret = 0; - u8 *pbuf = NULL; - unsigned int len, wps_ielen = 0; - struct mlme_priv *pmlmepriv = &(adapter->mlmepriv); - - if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) - return -EINVAL; - - if (head_len < 24) - return -EINVAL; - - pbuf = kzalloc(head_len + tail_len, GFP_KERNEL); - if (!pbuf) - return -ENOMEM; - - memcpy(pbuf, head + 24, head_len - 24);/* 24 =beacon header len. */ - memcpy(pbuf + head_len - 24, tail, tail_len); - - len = head_len + tail_len - 24; - - /* check wps ie if inclued */ - rtw_get_wps_ie(pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL, &wps_ielen); - - /* pbss_network->ies will not include p2p_ie, wfd ie */ - rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, WLAN_EID_VENDOR_SPECIFIC, P2P_OUI, 4); - rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, WLAN_EID_VENDOR_SPECIFIC, WFD_OUI, 4); - - if (rtw_check_beacon_data(adapter, pbuf, len) == _SUCCESS) - ret = 0; - else - ret = -EINVAL; - - kfree(pbuf); - - return ret; -} - -static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev, - struct cfg80211_ap_settings *settings) -{ - int ret = 0; - struct adapter *adapter = rtw_netdev_priv(ndev); - - ret = rtw_add_beacon(adapter, settings->beacon.head, - settings->beacon.head_len, settings->beacon.tail, - settings->beacon.tail_len); - - adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid; - - if (settings->ssid && settings->ssid_len) { - struct wlan_bssid_ex *pbss_network = &adapter->mlmepriv.cur_network.network; - struct wlan_bssid_ex *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network; - - memcpy(pbss_network->ssid.ssid, settings->ssid, settings->ssid_len); - pbss_network->ssid.ssid_length = settings->ssid_len; - memcpy(pbss_network_ext->ssid.ssid, settings->ssid, settings->ssid_len); - pbss_network_ext->ssid.ssid_length = settings->ssid_len; - } - - return ret; -} - -static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev, - struct cfg80211_ap_update *info) -{ - struct adapter *adapter = rtw_netdev_priv(ndev); - - return rtw_add_beacon(adapter, info->beacon.head, - info->beacon.head_len, info->beacon.tail, - info->beacon.tail_len); -} - -static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev, - unsigned int link_id) -{ - return 0; -} - -static int cfg80211_rtw_add_station(struct wiphy *wiphy, - struct wireless_dev *wdev, - const u8 *mac, - struct station_parameters *params) -{ - return 0; -} - -static int cfg80211_rtw_del_station(struct wiphy *wiphy, - struct wireless_dev *wdev, - struct station_del_parameters *params) -{ - int ret = 0; - struct list_head *phead, *plist, *tmp; - u8 updated = false; - struct sta_info *psta = NULL; - struct adapter *padapter = rtw_netdev_priv(wdev->netdev); - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - struct sta_priv *pstapriv = &padapter->stapriv; - const u8 *mac = params->mac; - - if (!check_fwstate(pmlmepriv, _FW_LINKED | WIFI_AP_STATE)) - return -EINVAL; - - if (!mac) { - flush_all_cam_entry(padapter); /* clear CAM */ - - rtw_sta_flush(padapter); - - return 0; - } - - if (mac[0] == 0xff && mac[1] == 0xff && - mac[2] == 0xff && mac[3] == 0xff && - mac[4] == 0xff && mac[5] == 0xff) { - return -EINVAL; - } - - spin_lock_bh(&pstapriv->asoc_list_lock); - - phead = &pstapriv->asoc_list; - /* check asoc_queue */ - list_for_each_safe(plist, tmp, phead) { - psta = list_entry(plist, struct sta_info, asoc_list); - - if (!memcmp((u8 *)mac, psta->hwaddr, ETH_ALEN)) { - if (psta->dot8021xalg != 1 || psta->bpairwise_key_installed) { - list_del_init(&psta->asoc_list); - pstapriv->asoc_list_cnt--; - - updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); - - psta = NULL; - - break; - } - } - } - - spin_unlock_bh(&pstapriv->asoc_list_lock); - - associated_clients_update(padapter, updated); - - return ret; -} - -static int cfg80211_rtw_change_station(struct wiphy *wiphy, - struct wireless_dev *wdev, - const u8 *mac, - struct station_parameters *params) -{ - return 0; -} - -static struct sta_info *rtw_sta_info_get_by_idx(const int idx, struct sta_priv *pstapriv) - -{ - struct list_head *phead, *plist; - struct sta_info *psta = NULL; - int i = 0; - - phead = &pstapriv->asoc_list; - plist = get_next(phead); - - /* check asoc_queue */ - while (phead != plist) { - if (idx == i) - psta = container_of(plist, struct sta_info, asoc_list); - plist = get_next(plist); - i++; - } - return psta; -} - -static int cfg80211_rtw_dump_station(struct wiphy *wiphy, - struct wireless_dev *wdev, - int idx, u8 *mac, - struct station_info *sinfo) -{ - int ret = 0; - struct adapter *padapter = rtw_netdev_priv(wdev_to_ndev(wdev)); - struct sta_info *psta = NULL; - struct sta_priv *pstapriv = &padapter->stapriv; - - spin_lock_bh(&pstapriv->asoc_list_lock); - psta = rtw_sta_info_get_by_idx(idx, pstapriv); - spin_unlock_bh(&pstapriv->asoc_list_lock); - if (!psta) { - ret = -ENOENT; - goto exit; - } - memcpy(mac, psta->hwaddr, ETH_ALEN); - sinfo->filled = BIT_ULL(NL80211_STA_INFO_SIGNAL); - sinfo->signal = psta->rssi; - -exit: - return ret; -} - -void rtw_cfg80211_rx_action(struct adapter *adapter, u8 *frame, unsigned int frame_len, const char *msg) -{ - s32 freq; - int channel; - u8 category, action; - - channel = rtw_get_oper_ch(adapter); - - rtw_action_frame_parse(frame, frame_len, &category, &action); - - freq = rtw_ieee80211_channel_to_frequency(channel); - - rtw_cfg80211_rx_mgmt(adapter, freq, 0, frame, frame_len, GFP_ATOMIC); -} - -static int _cfg80211_rtw_mgmt_tx(struct adapter *padapter, u8 tx_ch, const u8 *buf, size_t len) -{ - struct xmit_frame *pmgntframe; - struct pkt_attrib *pattrib; - unsigned char *pframe; - int ret = _FAIL; - bool __maybe_unused ack = true; - struct ieee80211_hdr *pwlanhdr; - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); - struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); - - rtw_set_scan_deny(padapter, 1000); - - rtw_scan_abort(padapter); - if (tx_ch != rtw_get_oper_ch(padapter)) { - if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) - pmlmeext->cur_channel = tx_ch; - set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20); - } - - /* starting alloc mgmt frame to dump it */ - pmgntframe = alloc_mgtxmitframe(pxmitpriv); - if (!pmgntframe) { - /* ret = -ENOMEM; */ - ret = _FAIL; - goto exit; - } - - /* update attribute */ - pattrib = &pmgntframe->attrib; - update_mgntframe_attrib(padapter, pattrib); - pattrib->retry_ctrl = false; - - memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); - - pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; - - memcpy(pframe, buf, len); - pattrib->pktlen = len; - - pwlanhdr = (struct ieee80211_hdr *)pframe; - /* update seq number */ - pmlmeext->mgnt_seq = GetSequence(pwlanhdr); - pattrib->seqnum = pmlmeext->mgnt_seq; - pmlmeext->mgnt_seq++; - - pattrib->last_txcmdsz = pattrib->pktlen; - - if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) { - ack = false; - ret = _FAIL; - - } else { - msleep(50); - - ret = _SUCCESS; - } - -exit: - - return ret; -} - -static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, - struct cfg80211_mgmt_tx_params *params, - u64 cookie) -{ - struct net_device *ndev = wdev_to_ndev(wdev); - struct ieee80211_channel *chan = params->chan; - const u8 *buf = params->buf; - size_t len = params->len; - int ret = 0; - int tx_ret; - u32 dump_limit = RTW_MAX_MGMT_TX_CNT; - u32 dump_cnt = 0; - bool ack = true; - u8 tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq); - u8 category, action; - struct adapter *padapter; - - if (!ndev) { - ret = -EINVAL; - goto exit; - } - - padapter = rtw_netdev_priv(ndev); - - /* indicate ack before issue frame to avoid racing with rsp frame */ - rtw_cfg80211_mgmt_tx_status(padapter, cookie, buf, len, ack, GFP_KERNEL); - - if (!rtw_action_frame_parse(buf, len, &category, &action)) - goto exit; - - rtw_ps_deny(padapter, PS_DENY_MGNT_TX); - if (rtw_pwr_wakeup(padapter) == _FAIL) { - ret = -EFAULT; - goto cancel_ps_deny; - } - - do { - dump_cnt++; - tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len); - } while (dump_cnt < dump_limit && tx_ret != _SUCCESS); - -cancel_ps_deny: - rtw_ps_deny_cancel(padapter, PS_DENY_MGNT_TX); -exit: - return ret; -} - -static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum nl80211_band band) -{ -#define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */ - - ht_cap->ht_supported = true; - - ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | - IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 | - IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; - - /* - *Maximum length of AMPDU that the STA can receive. - *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) - */ - ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; - - /*Minimum MPDU start spacing , */ - ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; - - ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; - - /* - *hw->wiphy->bands[NL80211_BAND_2GHZ] - *base on ant_num - *rx_mask: RX mask - *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 - *if rx_ant =2 rx_mask[1]= 0xff;==>MCS8-MCS15 - *if rx_ant >=3 rx_mask[2]= 0xff; - *if BW_40 rx_mask[4]= 0x01; - *highest supported RX rate - */ - ht_cap->mcs.rx_mask[0] = 0xFF; - ht_cap->mcs.rx_mask[1] = 0x00; - ht_cap->mcs.rx_mask[4] = 0x01; - - ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); -} - -void rtw_cfg80211_init_wiphy(struct adapter *padapter) -{ - struct ieee80211_supported_band *bands; - struct wireless_dev *pwdev = padapter->rtw_wdev; - struct wiphy *wiphy = pwdev->wiphy; - - { - bands = wiphy->bands[NL80211_BAND_2GHZ]; - if (bands) - rtw_cfg80211_init_ht_capab(&bands->ht_cap, NL80211_BAND_2GHZ); - } - - /* copy mac_addr to wiphy */ - memcpy(wiphy->perm_addr, padapter->eeprompriv.mac_addr, ETH_ALEN); -} - -static void rtw_cfg80211_preinit_wiphy(struct adapter *padapter, struct wiphy *wiphy) -{ - wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; - - wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT; - wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX; - wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS; - - wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION; - - wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) - | BIT(NL80211_IFTYPE_ADHOC) - | BIT(NL80211_IFTYPE_AP) - | BIT(NL80211_IFTYPE_MONITOR) - ; - - wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes; - - wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR); - - wiphy->cipher_suites = rtw_cipher_suites; - wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites); - - /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */ - wiphy->bands[NL80211_BAND_2GHZ] = rtw_spt_band_alloc(NL80211_BAND_2GHZ); - - wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; - wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME; - -#if defined(CONFIG_PM) - wiphy->max_sched_scan_reqs = 1; -#endif - -#if defined(CONFIG_PM) - wiphy->wowlan = &wowlan_stub; -#endif - - if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) - wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; - else - wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; -} - -static struct cfg80211_ops rtw_cfg80211_ops = { - .change_virtual_intf = cfg80211_rtw_change_iface, - .add_key = cfg80211_rtw_add_key, - .get_key = cfg80211_rtw_get_key, - .del_key = cfg80211_rtw_del_key, - .set_default_key = cfg80211_rtw_set_default_key, - .get_station = cfg80211_rtw_get_station, - .scan = cfg80211_rtw_scan, - .set_wiphy_params = cfg80211_rtw_set_wiphy_params, - .connect = cfg80211_rtw_connect, - .disconnect = cfg80211_rtw_disconnect, - .join_ibss = cfg80211_rtw_join_ibss, - .leave_ibss = cfg80211_rtw_leave_ibss, - .set_tx_power = cfg80211_rtw_set_txpower, - .get_tx_power = cfg80211_rtw_get_txpower, - .set_power_mgmt = cfg80211_rtw_set_power_mgmt, - .set_pmksa = cfg80211_rtw_set_pmksa, - .del_pmksa = cfg80211_rtw_del_pmksa, - .flush_pmksa = cfg80211_rtw_flush_pmksa, - .get_channel = cfg80211_rtw_get_channel, - .add_virtual_intf = cfg80211_rtw_add_virtual_intf, - .del_virtual_intf = cfg80211_rtw_del_virtual_intf, - - .start_ap = cfg80211_rtw_start_ap, - .change_beacon = cfg80211_rtw_change_beacon, - .stop_ap = cfg80211_rtw_stop_ap, - - .add_station = cfg80211_rtw_add_station, - .del_station = cfg80211_rtw_del_station, - .change_station = cfg80211_rtw_change_station, - .dump_station = cfg80211_rtw_dump_station, - - .mgmt_tx = cfg80211_rtw_mgmt_tx, -}; - -int rtw_wdev_alloc(struct adapter *padapter, struct device *dev) -{ - int ret = 0; - struct wiphy *wiphy; - struct wireless_dev *wdev; - struct rtw_wdev_priv *pwdev_priv; - struct net_device *pnetdev = padapter->pnetdev; - - /* wiphy */ - wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct adapter *)); - if (!wiphy) { - ret = -ENOMEM; - goto exit; - } - set_wiphy_dev(wiphy, dev); - *((struct adapter **)wiphy_priv(wiphy)) = padapter; - rtw_cfg80211_preinit_wiphy(padapter, wiphy); - - /* init regulary domain */ - rtw_regd_init(wiphy, rtw_reg_notifier); - - ret = wiphy_register(wiphy); - if (ret < 0) - goto free_wiphy; - - /* wdev */ - wdev = kzalloc_obj(*wdev); - if (!wdev) { - ret = -ENOMEM; - goto unregister_wiphy; - } - wdev->wiphy = wiphy; - wdev->netdev = pnetdev; - - wdev->iftype = NL80211_IFTYPE_STATION; /* will be init in rtw_hal_init() */ - /* Must sync with _rtw_init_mlme_priv() */ - /* pmlmepriv->fw_state = WIFI_STATION_STATE */ - padapter->rtw_wdev = wdev; - pnetdev->ieee80211_ptr = wdev; - - /* init pwdev_priv */ - pwdev_priv = adapter_wdev_data(padapter); - pwdev_priv->rtw_wdev = wdev; - pwdev_priv->pmon_ndev = NULL; - pwdev_priv->ifname_mon[0] = '\0'; - pwdev_priv->padapter = padapter; - pwdev_priv->scan_request = NULL; - spin_lock_init(&pwdev_priv->scan_req_lock); - - if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) - pwdev_priv->power_mgmt = true; - else - pwdev_priv->power_mgmt = false; - - return ret; - -unregister_wiphy: - wiphy_unregister(wiphy); - free_wiphy: - wiphy_free(wiphy); -exit: - return ret; -} - -void rtw_wdev_free(struct wireless_dev *wdev) -{ - if (!wdev) - return; - - kfree(wdev->wiphy->bands[NL80211_BAND_2GHZ]); - - wiphy_free(wdev->wiphy); - - kfree(wdev); -} - -void rtw_wdev_unregister(struct wireless_dev *wdev) -{ - struct net_device *ndev; - struct adapter *adapter; - struct rtw_wdev_priv *pwdev_priv; - - if (!wdev) - return; - ndev = wdev_to_ndev(wdev); - if (!ndev) - return; - - adapter = rtw_netdev_priv(ndev); - pwdev_priv = adapter_wdev_data(adapter); - - rtw_cfg80211_indicate_scan_done(adapter, true); - - if (pwdev_priv->pmon_ndev) - unregister_netdev(pwdev_priv->pmon_ndev); - - wiphy_unregister(wdev->wiphy); -} diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c deleted file mode 100644 index c15056ee207c..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c +++ /dev/null @@ -1,1189 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("Realtek Wireless Lan Driver"); -MODULE_AUTHOR("Realtek Semiconductor Corp."); -MODULE_VERSION(DRIVERVERSION); - -/* module param defaults */ -static int rtw_chip_version; -static int rtw_rfintfs = HWPI; -static int rtw_lbkmode;/* RTL8712_AIR_TRX; */ - - -static int rtw_network_mode = NL80211_IFTYPE_ADHOC;/* infra, ad-hoc, auto */ -/* struct ndis_802_11_ssid ssid; */ -static int rtw_channel = 1;/* ad-hoc support requirement */ -static int rtw_wireless_mode = WIRELESS_11BG_24N; -static int rtw_vrtl_carrier_sense = AUTO_VCS; -static int rtw_vcs_type = RTS_CTS;/* */ -static int rtw_rts_thresh = 2347;/* */ -static int rtw_frag_thresh = 2346;/* */ -static int rtw_preamble = PREAMBLE_LONG;/* long, short, auto */ -static int rtw_scan_mode = 1;/* active, passive */ -static int rtw_adhoc_tx_pwr = 1; -static int rtw_soft_ap; -/* int smart_ps = 1; */ -static int rtw_power_mgnt = 1; -static int rtw_ips_mode = IPS_NORMAL; -module_param(rtw_ips_mode, int, 0644); -MODULE_PARM_DESC(rtw_ips_mode, "The default IPS mode"); - -static int rtw_smart_ps = 2; - -static int rtw_check_fw_ps = 1; - -static int rtw_usb_rxagg_mode = 2;/* USB_RX_AGG_DMA = 1, USB_RX_AGG_USB =2 */ -module_param(rtw_usb_rxagg_mode, int, 0644); - -static int rtw_radio_enable = 1; -static int rtw_long_retry_lmt = 7; -static int rtw_short_retry_lmt = 7; -static int rtw_busy_thresh = 40; -/* int qos_enable = 0; */ -static int rtw_ack_policy = NORMAL_ACK; - -static int rtw_software_encrypt; -static int rtw_software_decrypt; - -static int rtw_acm_method;/* 0:By SW 1:By HW. */ - -static int rtw_wmm_enable = 1;/* default is set to enable the wmm. */ -static int rtw_uapsd_enable; -static int rtw_uapsd_max_sp = NO_LIMIT; -static int rtw_uapsd_acbk_en; -static int rtw_uapsd_acbe_en; -static int rtw_uapsd_acvi_en; -static int rtw_uapsd_acvo_en; - -int rtw_ht_enable = 1; -/* - * 0: 20 MHz, 1: 40 MHz - * 2.4G use bit 0 ~ 3 - * 0x01 means enable 2.4G 40MHz - */ -static int rtw_bw_mode = 0x01; -static int rtw_ampdu_enable = 1;/* for enable tx_ampdu ,0: disable, 0x1:enable (but wifi_spec should be 0), 0x2: force enable (don't care wifi_spec) */ -static int rtw_rx_stbc = 1;/* 0: disable, 1:enable 2.4g */ -static int rtw_ampdu_amsdu;/* 0: disabled, 1:enabled, 2:auto . There is an IOT issu with DLINK DIR-629 when the flag turn on */ -/* Short GI support Bit Map */ -/* BIT0 - 20MHz, 0: non-support, 1: support */ -/* BIT1 - 40MHz, 0: non-support, 1: support */ -/* BIT2 - 80MHz, 0: non-support, 1: support */ -/* BIT3 - 160MHz, 0: non-support, 1: support */ -static int rtw_short_gi = 0xf; -/* BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */ -static int rtw_ldpc_cap = 0x33; -/* BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */ -static int rtw_stbc_cap = 0x13; -/* BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee */ -static int rtw_beamform_cap = 0x2; - -static int rtw_lowrate_two_xmit = 1;/* Use 2 path Tx to transmit MCS0~7 and legacy mode */ - -static int rtw_low_power; -static int rtw_wifi_spec; -static int rtw_channel_plan = RT_CHANNEL_DOMAIN_MAX; - -static int rtw_ant_num = -1; /* <0: undefined, >0: Antenna number */ -module_param(rtw_ant_num, int, 0644); -MODULE_PARM_DESC(rtw_ant_num, "Antenna number setting"); - -static int rtw_antdiv_cfg = 1; /* 0:OFF , 1:ON, 2:decide by Efuse config */ -static int rtw_antdiv_type; /* 0:decide by efuse 1: for 88EE, 1Tx and 1RxCG are diversity.(2 Ant with SPDT), 2: for 88EE, 1Tx and 2Rx are diversity.(2 Ant, Tx and RxCG are both on aux port, RxCS is on main port), 3: for 88EE, 1Tx and 1RxCG are fixed.(1Ant, Tx and RxCG are both on aux port) */ - -static int rtw_hw_wps_pbc; - -int rtw_mc2u_disable; - -static int rtw_80211d; - -static int rtw_qos_opt_enable;/* 0: disable, 1:enable */ -module_param(rtw_qos_opt_enable, int, 0644); - -static char *ifname = "wlan%d"; -module_param(ifname, charp, 0644); -MODULE_PARM_DESC(ifname, "The default name to allocate for first interface"); - -char *rtw_initmac; /* temp mac address if users want to use instead of the mac address in Efuse */ - -module_param(rtw_initmac, charp, 0644); -module_param(rtw_channel_plan, int, 0644); -module_param(rtw_chip_version, int, 0644); -module_param(rtw_rfintfs, int, 0644); -module_param(rtw_lbkmode, int, 0644); -module_param(rtw_network_mode, int, 0644); -module_param(rtw_channel, int, 0644); -module_param(rtw_wmm_enable, int, 0644); -module_param(rtw_vrtl_carrier_sense, int, 0644); -module_param(rtw_vcs_type, int, 0644); -module_param(rtw_busy_thresh, int, 0644); - -module_param(rtw_ht_enable, int, 0644); -module_param(rtw_bw_mode, int, 0644); -module_param(rtw_ampdu_enable, int, 0644); -module_param(rtw_rx_stbc, int, 0644); -module_param(rtw_ampdu_amsdu, int, 0644); - -module_param(rtw_lowrate_two_xmit, int, 0644); - -module_param(rtw_power_mgnt, int, 0644); -module_param(rtw_smart_ps, int, 0644); -module_param(rtw_low_power, int, 0644); -module_param(rtw_wifi_spec, int, 0644); - -module_param(rtw_antdiv_cfg, int, 0644); -module_param(rtw_antdiv_type, int, 0644); - -module_param(rtw_hw_wps_pbc, int, 0644); - -static uint rtw_max_roaming_times = 2; -module_param(rtw_max_roaming_times, uint, 0644); -MODULE_PARM_DESC(rtw_max_roaming_times, "The max roaming times to try"); - -module_param(rtw_mc2u_disable, int, 0644); - -module_param(rtw_80211d, int, 0644); -MODULE_PARM_DESC(rtw_80211d, "Enable 802.11d mechanism"); - -static uint rtw_notch_filter; -module_param(rtw_notch_filter, uint, 0644); -MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P"); - -#define CONFIG_RTW_HIQ_FILTER 1 - -static uint rtw_hiq_filter = CONFIG_RTW_HIQ_FILTER; -module_param(rtw_hiq_filter, uint, 0644); -MODULE_PARM_DESC(rtw_hiq_filter, "0:allow all, 1:allow special, 2:deny all"); - -static int rtw_tx_pwr_lmt_enable; -static int rtw_tx_pwr_by_rate; - -module_param(rtw_tx_pwr_lmt_enable, int, 0644); -MODULE_PARM_DESC(rtw_tx_pwr_lmt_enable, "0:Disable, 1:Enable, 2: Depend on efuse"); - -module_param(rtw_tx_pwr_by_rate, int, 0644); -MODULE_PARM_DESC(rtw_tx_pwr_by_rate, "0:Disable, 1:Enable, 2: Depend on efuse"); - -static int netdev_close(struct net_device *pnetdev); - -static void loadparam(struct adapter *padapter) -{ - struct registry_priv *registry_par = &padapter->registrypriv; - - registry_par->chip_version = (u8)rtw_chip_version; - registry_par->rfintfs = (u8)rtw_rfintfs; - registry_par->lbkmode = (u8)rtw_lbkmode; - /* registry_par->hci = (u8)hci; */ - registry_par->network_mode = (u8)rtw_network_mode; - - memcpy(registry_par->ssid.ssid, "ANY", 3); - registry_par->ssid.ssid_length = 3; - - registry_par->channel = (u8)rtw_channel; - registry_par->wireless_mode = (u8)rtw_wireless_mode; - - registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense; - registry_par->vcs_type = (u8)rtw_vcs_type; - registry_par->rts_thresh = (u16)rtw_rts_thresh; - registry_par->frag_thresh = (u16)rtw_frag_thresh; - registry_par->preamble = (u8)rtw_preamble; - registry_par->scan_mode = (u8)rtw_scan_mode; - registry_par->adhoc_tx_pwr = (u8)rtw_adhoc_tx_pwr; - registry_par->soft_ap = (u8)rtw_soft_ap; - registry_par->smart_ps = (u8)rtw_smart_ps; - registry_par->check_fw_ps = (u8)rtw_check_fw_ps; - registry_par->power_mgnt = (u8)rtw_power_mgnt; - registry_par->ips_mode = (u8)rtw_ips_mode; - registry_par->radio_enable = (u8)rtw_radio_enable; - registry_par->long_retry_lmt = (u8)rtw_long_retry_lmt; - registry_par->short_retry_lmt = (u8)rtw_short_retry_lmt; - registry_par->busy_thresh = (u16)rtw_busy_thresh; - /* registry_par->qos_enable = (u8)rtw_qos_enable; */ - registry_par->ack_policy = (u8)rtw_ack_policy; - registry_par->software_encrypt = (u8)rtw_software_encrypt; - registry_par->software_decrypt = (u8)rtw_software_decrypt; - - registry_par->acm_method = (u8)rtw_acm_method; - registry_par->usb_rxagg_mode = (u8)rtw_usb_rxagg_mode; - - /* UAPSD */ - registry_par->wmm_enable = (u8)rtw_wmm_enable; - registry_par->uapsd_enable = (u8)rtw_uapsd_enable; - registry_par->uapsd_max_sp = (u8)rtw_uapsd_max_sp; - registry_par->uapsd_acbk_en = (u8)rtw_uapsd_acbk_en; - registry_par->uapsd_acbe_en = (u8)rtw_uapsd_acbe_en; - registry_par->uapsd_acvi_en = (u8)rtw_uapsd_acvi_en; - registry_par->uapsd_acvo_en = (u8)rtw_uapsd_acvo_en; - - registry_par->ht_enable = (u8)rtw_ht_enable; - registry_par->bw_mode = (u8)rtw_bw_mode; - registry_par->ampdu_enable = (u8)rtw_ampdu_enable; - registry_par->rx_stbc = (u8)rtw_rx_stbc; - registry_par->ampdu_amsdu = (u8)rtw_ampdu_amsdu; - registry_par->short_gi = (u8)rtw_short_gi; - registry_par->ldpc_cap = (u8)rtw_ldpc_cap; - registry_par->stbc_cap = (u8)rtw_stbc_cap; - registry_par->beamform_cap = (u8)rtw_beamform_cap; - - registry_par->lowrate_two_xmit = (u8)rtw_lowrate_two_xmit; - registry_par->low_power = (u8)rtw_low_power; - - registry_par->wifi_spec = (u8)rtw_wifi_spec; - - registry_par->channel_plan = (u8)rtw_channel_plan; - - registry_par->ant_num = (s8)rtw_ant_num; - - registry_par->accept_addba_req = true; - - registry_par->antdiv_cfg = (u8)rtw_antdiv_cfg; - registry_par->antdiv_type = (u8)rtw_antdiv_type; - - registry_par->hw_wps_pbc = (u8)rtw_hw_wps_pbc; - - registry_par->max_roaming_times = (u8)rtw_max_roaming_times; - - registry_par->enable80211d = (u8)rtw_80211d; - - snprintf(registry_par->ifname, 16, "%s", ifname); - - registry_par->notch_filter = (u8)rtw_notch_filter; - - registry_par->reg_enable_tx_power_limit = (u8)rtw_tx_pwr_lmt_enable; - registry_par->reg_enable_tx_power_by_rate = (u8)rtw_tx_pwr_by_rate; - - registry_par->reg_power_base = 14; - - registry_par->qos_opt_enable = (u8)rtw_qos_opt_enable; - - registry_par->hiq_filter = (u8)rtw_hiq_filter; -} - -static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p) -{ - struct adapter *padapter = rtw_netdev_priv(pnetdev); - struct sockaddr *addr = p; - - if (!padapter->bup) { - /* addr->sa_data[4], addr->sa_data[5]); */ - memcpy(padapter->eeprompriv.mac_addr, addr->sa_data, ETH_ALEN); - /* eth_hw_addr_set(pnetdev, addr->sa_data); */ - /* padapter->bset_hwaddr = true; */ - } - - return 0; -} - -static struct net_device_stats *rtw_net_get_stats(struct net_device *pnetdev) -{ - struct adapter *padapter = rtw_netdev_priv(pnetdev); - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct recv_priv *precvpriv = &padapter->recvpriv; - - padapter->stats.tx_packets = pxmitpriv->tx_pkts;/* pxmitpriv->tx_pkts++; */ - padapter->stats.rx_packets = precvpriv->rx_pkts;/* precvpriv->rx_pkts++; */ - padapter->stats.tx_dropped = pxmitpriv->tx_drop; - padapter->stats.rx_dropped = precvpriv->rx_drop; - padapter->stats.tx_bytes = pxmitpriv->tx_bytes; - padapter->stats.rx_bytes = precvpriv->rx_bytes; - - return &padapter->stats; -} - -/* - * AC to queue mapping - * - * AC_VO -> queue 0 - * AC_VI -> queue 1 - * AC_BE -> queue 2 - * AC_BK -> queue 3 - */ -static const u16 rtw_1d_to_queue[8] = { 2, 3, 3, 2, 1, 1, 0, 0 }; - -/* Given a data frame determine the 802.1p/1d tag to use. */ -static unsigned int rtw_classify8021d(struct sk_buff *skb) -{ - unsigned int dscp; - - /* skb->priority values from 256->263 are magic values to - * directly indicate a specific 802.1d priority. This is used - * to allow 802.1d priority to be passed directly in from VLAN - * tags, etc. - */ - if (skb->priority >= 256 && skb->priority <= 263) - return skb->priority - 256; - - switch (skb->protocol) { - case htons(ETH_P_IP): - dscp = ip_hdr(skb)->tos & 0xfc; - break; - default: - return 0; - } - - return dscp >> 5; -} - -static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb, - struct net_device *sb_dev) -{ - struct adapter *padapter = rtw_netdev_priv(dev); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - skb->priority = rtw_classify8021d(skb); - - if (pmlmepriv->acm_mask != 0) - skb->priority = qos_acm(pmlmepriv->acm_mask, skb->priority); - - return rtw_1d_to_queue[skb->priority]; -} - -u16 rtw_recv_select_queue(struct sk_buff *skb) -{ - struct iphdr *piphdr; - unsigned int dscp; - __be16 eth_type; - u32 priority; - u8 *pdata = skb->data; - - memcpy(ð_type, pdata + (ETH_ALEN << 1), 2); - - switch (be16_to_cpu(eth_type)) { - case ETH_P_IP: - - piphdr = (struct iphdr *)(pdata + ETH_HLEN); - - dscp = piphdr->tos & 0xfc; - - priority = dscp >> 5; - - break; - default: - priority = 0; - } - - return rtw_1d_to_queue[priority]; -} - -static int rtw_ndev_init(struct net_device *dev) -{ - struct adapter *adapter = rtw_netdev_priv(dev); - - netdev_dbg(dev, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter)); - strscpy(adapter->old_ifname, dev->name); - - return 0; -} - -static void rtw_ndev_uninit(struct net_device *dev) -{ - struct adapter *adapter = rtw_netdev_priv(dev); - - netdev_dbg(dev, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter)); -} - -static const struct net_device_ops rtw_netdev_ops = { - .ndo_init = rtw_ndev_init, - .ndo_uninit = rtw_ndev_uninit, - .ndo_open = netdev_open, - .ndo_stop = netdev_close, - .ndo_start_xmit = rtw_xmit_entry, - .ndo_select_queue = rtw_select_queue, - .ndo_set_mac_address = rtw_net_set_mac_address, - .ndo_get_stats = rtw_net_get_stats, -}; - -int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname) -{ - if (dev_alloc_name(pnetdev, ifname) < 0) { - pr_err("dev_alloc_name, fail for %s\n", ifname); - return 1; - } - netif_carrier_off(pnetdev); - /* rtw_netif_stop_queue(pnetdev); */ - - return 0; -} - -struct net_device *rtw_init_netdev(struct adapter *old_padapter) -{ - struct adapter *padapter; - struct net_device *pnetdev; - - if (old_padapter) - pnetdev = rtw_alloc_etherdev_with_old_priv(sizeof(struct adapter), (void *)old_padapter); - else - pnetdev = rtw_alloc_etherdev(sizeof(struct adapter)); - - pr_info("pnetdev = %p\n", pnetdev); - if (!pnetdev) - return NULL; - - padapter = rtw_netdev_priv(pnetdev); - padapter->pnetdev = pnetdev; - - /* pnetdev->init = NULL; */ - - pnetdev->netdev_ops = &rtw_netdev_ops; - - /* pnetdev->tx_timeout = NULL; */ - pnetdev->watchdog_timeo = HZ * 3; /* 3 second timeout */ - - /* step 2. */ - loadparam(padapter); - - return pnetdev; -} - -void rtw_unregister_netdevs(struct dvobj_priv *dvobj) -{ - struct adapter *padapter = NULL; - struct net_device *pnetdev = NULL; - - padapter = dvobj->padapters; - - if (!padapter) - return; - - pnetdev = padapter->pnetdev; - - if ((padapter->DriverState != DRIVER_DISAPPEAR) && pnetdev) - unregister_netdev(pnetdev); /* will call netdev_close() */ - rtw_wdev_unregister(padapter->rtw_wdev); -} - -u32 rtw_start_drv_threads(struct adapter *padapter) -{ - u32 _status = _SUCCESS; - - padapter->xmitThread = kthread_run(rtw_xmit_thread, padapter, "RTW_XMIT_THREAD"); - if (IS_ERR(padapter->xmitThread)) - _status = _FAIL; - - padapter->cmdThread = kthread_run(rtw_cmd_thread, padapter, "RTW_CMD_THREAD"); - if (IS_ERR(padapter->cmdThread)) - _status = _FAIL; - else - wait_for_completion(&padapter->cmdpriv.terminate_cmdthread_comp); /* wait for cmd_thread to run */ - - padapter->xmitpriv.SdioXmitThread = kthread_run(rtl8723bs_xmit_thread, - padapter, "RTWHALXT"); - if (IS_ERR(padapter->xmitpriv.SdioXmitThread)) { - padapter->xmitpriv.SdioXmitThread = NULL; - _status = _FAIL; - } - - return _status; -} - -void rtw_stop_drv_threads(struct adapter *padapter) -{ - rtw_stop_cmd_thread(padapter); - - /* Below is to terminate tx_thread... */ - complete(&padapter->xmitpriv.xmit_comp); - wait_for_completion(&padapter->xmitpriv.terminate_xmitthread_comp); - - /* stop SdioXmitThread */ - if (padapter->xmitpriv.SdioXmitThread) { - complete(&padapter->xmitpriv.SdioXmitStart); - wait_for_completion(&padapter->xmitpriv.SdioXmitTerminate); - padapter->xmitpriv.SdioXmitThread = NULL; - } -} - -static void rtw_init_default_value(struct adapter *padapter) -{ - struct registry_priv *pregistrypriv = &padapter->registrypriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - - /* xmit_priv */ - pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense; - pxmitpriv->vcs = pregistrypriv->vcs_type; - pxmitpriv->vcs_type = pregistrypriv->vcs_type; - /* pxmitpriv->rts_thresh = pregistrypriv->rts_thresh; */ - pxmitpriv->frag_len = pregistrypriv->frag_thresh; - - /* recv_priv */ - - /* mlme_priv */ - pmlmepriv->scan_mode = SCAN_ACTIVE; - - /* qos_priv */ - /* pmlmepriv->qospriv.qos_option = pregistrypriv->wmm_enable; */ - - /* ht_priv */ - pmlmepriv->htpriv.ampdu_enable = false;/* set to disabled */ - - /* security_priv */ - psecuritypriv->binstallGrpkey = _FAIL; - psecuritypriv->sw_encrypt = pregistrypriv->software_encrypt; - psecuritypriv->sw_decrypt = pregistrypriv->software_decrypt; - - psecuritypriv->dot11_auth_algrthm = dot11_auth_algrthm_open; /* open system */ - psecuritypriv->dot11_privacy_algrthm = _NO_PRIVACY_; - - psecuritypriv->dot11PrivacyKeyIndex = 0; - - psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; - psecuritypriv->dot118021XGrpKeyid = 1; - - psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; - psecuritypriv->ndisencryptstatus = Ndis802_11WEPDisabled; - - /* registry_priv */ - rtw_init_registrypriv_dev_network(padapter); - rtw_update_registrypriv_dev_network(padapter); - - /* hal_priv */ - rtl8723bs_init_default_value(padapter); - - /* misc. */ - RTW_ENABLE_FUNC(padapter, DF_RX_BIT); - RTW_ENABLE_FUNC(padapter, DF_TX_BIT); - padapter->bLinkInfoDump = 0; - padapter->bNotifyChannelChange = 0; - - /* for debug purpose */ - padapter->fix_rate = 0xFF; - padapter->driver_ampdu_spacing = 0xFF; - padapter->driver_rx_ampdu_factor = 0xFF; -} - -struct dvobj_priv *devobj_init(void) -{ - struct dvobj_priv *pdvobj = NULL; - - pdvobj = kzalloc_obj(*pdvobj); - if (!pdvobj) - return NULL; - - mutex_init(&pdvobj->hw_init_mutex); - mutex_init(&pdvobj->h2c_fwcmd_mutex); - mutex_init(&pdvobj->setch_mutex); - mutex_init(&pdvobj->setbw_mutex); - - spin_lock_init(&pdvobj->lock); - - pdvobj->macid[1] = true; /* macid = 1 for bc/mc stainfo */ - - pdvobj->processing_dev_remove = false; - - atomic_set(&pdvobj->disable_func, 0); - - spin_lock_init(&pdvobj->cam_ctl.lock); - - return pdvobj; -} - -void devobj_deinit(struct dvobj_priv *pdvobj) -{ - if (!pdvobj) - return; - - mutex_destroy(&pdvobj->hw_init_mutex); - mutex_destroy(&pdvobj->h2c_fwcmd_mutex); - mutex_destroy(&pdvobj->setch_mutex); - mutex_destroy(&pdvobj->setbw_mutex); - - kfree(pdvobj); -} - -void rtw_reset_drv_sw(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); - - /* hal_priv */ - rtl8723bs_init_default_value(padapter); - - RTW_ENABLE_FUNC(padapter, DF_RX_BIT); - RTW_ENABLE_FUNC(padapter, DF_TX_BIT); - padapter->bLinkInfoDump = 0; - - padapter->xmitpriv.tx_pkts = 0; - padapter->recvpriv.rx_pkts = 0; - - pmlmepriv->link_detect_info.busy_traffic = false; - - pmlmepriv->link_detect_info.traffic_transition_count = 0; - pmlmepriv->link_detect_info.low_power_transition_count = 0; - - _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING); - - pwrctrlpriv->pwr_state_check_cnts = 0; - - /* mlmeextpriv */ - padapter->mlmeextpriv.sitesurvey_res.state = SCAN_DISABLE; - - rtw_set_signal_stat_timer(&padapter->recvpriv); -} - -u8 rtw_init_drv_sw(struct adapter *padapter) -{ - int res; - - rtw_init_default_value(padapter); - - rtw_init_hal_com_default_value(padapter); - - if (rtw_init_cmd_priv(&padapter->cmdpriv)) - return _FAIL; - - padapter->cmdpriv.padapter = padapter; - - if (rtw_init_evt_priv(&padapter->evtpriv)) - goto free_cmd_priv; - - if (rtw_init_mlme_priv(padapter) == _FAIL) - goto free_evt_priv; - - init_mlme_ext_priv(padapter); - - res = _rtw_init_xmit_priv(&padapter->xmitpriv, padapter); - if (res) - goto free_mlme_ext; - - if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) - goto free_xmit_priv; - spin_lock_init(&padapter->security_key_mutex); - - /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ - /* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */ - - if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) - goto free_recv_priv; - - padapter->stapriv.padapter = padapter; - padapter->setband = GHZ24_50; - padapter->fix_rate = 0xFF; - rtw_init_bcmc_stainfo(padapter); - - rtw_init_pwrctrl_priv(padapter); - - rtl8723b_init_dm_priv(padapter); - - return _SUCCESS; - -free_recv_priv: - _rtw_free_recv_priv(&padapter->recvpriv); - -free_xmit_priv: - _rtw_free_xmit_priv(&padapter->xmitpriv); - -free_mlme_ext: - free_mlme_ext_priv(&padapter->mlmeextpriv); - - rtw_free_mlme_priv(&padapter->mlmepriv); - -free_evt_priv: - rtw_free_evt_priv(&padapter->evtpriv); - -free_cmd_priv: - rtw_free_cmd_priv(&padapter->cmdpriv); - - return _FAIL; -} - -void rtw_cancel_all_timer(struct adapter *padapter) -{ - timer_delete_sync(&padapter->mlmepriv.assoc_timer); - - timer_delete_sync(&padapter->mlmepriv.scan_to_timer); - - timer_delete_sync(&padapter->mlmepriv.dynamic_chk_timer); - - timer_delete_sync(&(adapter_to_pwrctl(padapter)->pwr_state_check_timer)); - - timer_delete_sync(&padapter->mlmepriv.set_scan_deny_timer); - rtw_clear_scan_deny(padapter); - - timer_delete_sync(&padapter->recvpriv.signal_stat_timer); -} - -u8 rtw_free_drv_sw(struct adapter *padapter) -{ - free_mlme_ext_priv(&padapter->mlmeextpriv); - - rtw_free_cmd_priv(&padapter->cmdpriv); - - rtw_free_evt_priv(&padapter->evtpriv); - - rtw_free_mlme_priv(&padapter->mlmepriv); - - _rtw_free_xmit_priv(&padapter->xmitpriv); - - _rtw_free_sta_priv(&padapter->stapriv); /* will free bcmc_stainfo here */ - - _rtw_free_recv_priv(&padapter->recvpriv); - - rtw_free_pwrctrl_priv(padapter); - - /* kfree((void *)padapter); */ - - rtw_hal_data_deinit(padapter); - - /* free the old_pnetdev */ - if (padapter->rereg_nd_name_priv.old_pnetdev) { - free_netdev(padapter->rereg_nd_name_priv.old_pnetdev); - padapter->rereg_nd_name_priv.old_pnetdev = NULL; - } - - /* clear pbuddystruct adapter to avoid access wrong pointer. */ - if (padapter->pbuddy_adapter) - padapter->pbuddy_adapter->pbuddy_adapter = NULL; - - return _SUCCESS; -} - -static int _rtw_drv_register_netdev(struct adapter *padapter, char *name) -{ - int ret = _SUCCESS; - struct net_device *pnetdev = padapter->pnetdev; - - /* alloc netdev name */ - if (rtw_init_netdev_name(pnetdev, name)) - return _FAIL; - - eth_hw_addr_set(pnetdev, padapter->eeprompriv.mac_addr); - - /* Tell the network stack we exist */ - if (register_netdev(pnetdev) != 0) { - ret = _FAIL; - goto error_register_netdev; - } - - return ret; - -error_register_netdev: - - rtw_free_drv_sw(padapter); - - rtw_free_netdev(pnetdev); - - return ret; -} - -int rtw_drv_register_netdev(struct adapter *if1) -{ - struct dvobj_priv *dvobj = if1->dvobj; - struct adapter *padapter = dvobj->padapters; - char *name = if1->registrypriv.ifname; - - return _rtw_drv_register_netdev(padapter, name); -} - -static int _netdev_open(struct net_device *pnetdev) -{ - unsigned int status; - struct adapter *padapter = rtw_netdev_priv(pnetdev); - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); - - padapter->netif_up = true; - - if (pwrctrlpriv->ps_flag) { - padapter->net_closed = false; - goto netdev_open_normal_process; - } - - if (!padapter->bup) { - padapter->driver_stopped = false; - padapter->bSurpriseRemoved = false; - padapter->bCardDisableWOHSM = false; - - status = rtw_hal_init(padapter); - if (status == _FAIL) - goto netdev_open_error; - - status = rtw_start_drv_threads(padapter); - if (status == _FAIL) - goto netdev_open_error; - - if (padapter->intf_start) - padapter->intf_start(padapter); - - rtw_cfg80211_init_wiphy(padapter); - - padapter->bup = true; - pwrctrlpriv->bips_processing = false; - } - padapter->net_closed = false; - - _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000); - - if (!rtw_netif_queue_stopped(pnetdev)) - rtw_netif_start_queue(pnetdev); - else - rtw_netif_wake_queue(pnetdev); - -netdev_open_normal_process: - - return 0; - -netdev_open_error: - - padapter->bup = false; - - netif_carrier_off(pnetdev); - rtw_netif_stop_queue(pnetdev); - - return (-1); -} - -int netdev_open(struct net_device *pnetdev) -{ - int ret; - struct adapter *padapter = rtw_netdev_priv(pnetdev); - struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); - - if (pwrctrlpriv->bInSuspend) - return 0; - - if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->hw_init_mutex))) - return -1; - - ret = _netdev_open(pnetdev); - mutex_unlock(&(adapter_to_dvobj(padapter)->hw_init_mutex)); - - return ret; -} - -static int ips_netdrv_open(struct adapter *padapter) -{ - int status = _SUCCESS; - /* struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); */ - - padapter->net_closed = false; - - padapter->driver_stopped = false; - padapter->bCardDisableWOHSM = false; - /* padapter->bup = true; */ - - status = rtw_hal_init(padapter); - if (status == _FAIL) - goto netdev_open_error; - - if (padapter->intf_start) - padapter->intf_start(padapter); - - _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000); - - return _SUCCESS; - -netdev_open_error: - - return _FAIL; -} - -int rtw_ips_pwr_up(struct adapter *padapter) -{ - return ips_netdrv_open(padapter); -} - -void rtw_ips_pwr_down(struct adapter *padapter) -{ - padapter->bCardDisableWOHSM = true; - padapter->net_closed = true; - - rtw_ips_dev_unload(padapter); - padapter->bCardDisableWOHSM = false; -} - -void rtw_ips_dev_unload(struct adapter *padapter) -{ - if (!padapter->bSurpriseRemoved) - rtw_hal_deinit(padapter); -} - -static int pm_netdev_open(struct net_device *pnetdev, u8 bnormal) -{ - int status = -1; - - struct adapter *padapter = rtw_netdev_priv(pnetdev); - - if (bnormal) { - if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->hw_init_mutex)) == 0) { - status = _netdev_open(pnetdev); - mutex_unlock(&(adapter_to_dvobj(padapter)->hw_init_mutex)); - } - } else { - status = (ips_netdrv_open(padapter) == _SUCCESS) ? (0) : (-1); - } - - return status; -} - -static int netdev_close(struct net_device *pnetdev) -{ - struct adapter *padapter = rtw_netdev_priv(pnetdev); - struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter); - - if (pwrctl->bInternalAutoSuspend) { - /* rtw_pwr_wakeup(padapter); */ - if (pwrctl->rf_pwrstate == rf_off) - pwrctl->ps_flag = true; - } - padapter->net_closed = true; - padapter->netif_up = false; - - if (pwrctl->rf_pwrstate == rf_on) { - /* s1. */ - if (pnetdev) { - if (!rtw_netif_queue_stopped(pnetdev)) - rtw_netif_stop_queue(pnetdev); - } - - /* s2. */ - LeaveAllPowerSaveMode(padapter); - rtw_disassoc_cmd(padapter, 500, false); - /* s2-2. indicate disconnect to os */ - rtw_indicate_disconnect(padapter); - /* s2-3. */ - rtw_free_assoc_resources(padapter, 1); - /* s2-4. */ - rtw_free_network_queue(padapter, true); - } - - rtw_scan_abort(padapter); - - return 0; -} - -void rtw_ndev_destructor(struct net_device *ndev) -{ - kfree(ndev->ieee80211_ptr); -} - -void rtw_dev_unload(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter); - struct cmd_priv *pcmdpriv = &padapter->cmdpriv; - u8 cnt = 0; - - if (padapter->bup) { - padapter->driver_stopped = true; - if (padapter->xmitpriv.ack_tx) - rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP); - - if (padapter->intf_stop) - padapter->intf_stop(padapter); - - if (!pwrctl->bInternalAutoSuspend) - rtw_stop_drv_threads(padapter); - - while (atomic_read(&pcmdpriv->cmdthd_running)) { - if (cnt > 5) - break; - cnt++; - msleep(10); - } - - /* check the status of IPS */ - if (rtw_hal_check_ips_status(padapter) || pwrctl->rf_pwrstate == rf_off) { - /* check HW status and SW state */ - netdev_dbg(padapter->pnetdev, - "%s: driver in IPS-FWLPS\n", __func__); - LeaveAllPowerSaveMode(padapter); - } else { - netdev_dbg(padapter->pnetdev, - "%s: driver not in IPS\n", __func__); - } - - if (!padapter->bSurpriseRemoved) { - hal_btcoex_IpsNotify(padapter, pwrctl->ips_mode_req); - - /* amy modify 20120221 for power seq is different between driver open and ips */ - rtw_hal_deinit(padapter); - - padapter->bSurpriseRemoved = true; - } - - padapter->bup = false; - } -} - -static int rtw_suspend_free_assoc_resource(struct adapter *padapter) -{ - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) { - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && - check_fwstate(pmlmepriv, _FW_LINKED)) { - rtw_set_to_roam(padapter, 1); - } - } - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED)) { - rtw_disassoc_cmd(padapter, 0, false); - /* s2-2. indicate disconnect to os */ - rtw_indicate_disconnect(padapter); - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - rtw_sta_flush(padapter); - } - - /* s2-3. */ - rtw_free_assoc_resources(padapter, 1); - - /* s2-4. */ - rtw_free_network_queue(padapter, true); - - if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) - rtw_indicate_scan_done(padapter, 1); - - if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) { - netdev_dbg(padapter->pnetdev, "%s: fw_under_linking\n", - __func__); - rtw_indicate_disconnect(padapter); - } - - return _SUCCESS; -} - -static void rtw_suspend_normal(struct adapter *padapter) -{ - struct net_device *pnetdev = padapter->pnetdev; - - if (pnetdev) { - netif_carrier_off(pnetdev); - rtw_netif_stop_queue(pnetdev); - } - - rtw_suspend_free_assoc_resource(padapter); - - if ((rtw_hal_check_ips_status(padapter)) || (adapter_to_pwrctl(padapter)->rf_pwrstate == rf_off)) - netdev_dbg(padapter->pnetdev, - "%s: ### ERROR #### driver in IPS ####ERROR###!!!\n", - __func__); - - rtw_dev_unload(padapter); - - /* sdio_deinit(adapter_to_dvobj(padapter)); */ - if (padapter->intf_deinit) - padapter->intf_deinit(adapter_to_dvobj(padapter)); -} - -void rtw_suspend_common(struct adapter *padapter) -{ - struct dvobj_priv *psdpriv = padapter->dvobj; - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - unsigned long start_time = jiffies; - - netdev_dbg(padapter->pnetdev, " suspend start\n"); - - pwrpriv->bInSuspend = true; - - while (pwrpriv->bips_processing) - msleep(1); - - if ((!padapter->bup) || (padapter->driver_stopped) || (padapter->bSurpriseRemoved)) - return; - - rtw_ps_deny(padapter, PS_DENY_SUSPEND); - - rtw_cancel_all_timer(padapter); - - LeaveAllPowerSaveModeDirect(padapter); - - rtw_stop_cmd_thread(padapter); - - /* wait for the latest FW to remove this condition. */ - if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) - hal_btcoex_SuspendNotify(padapter, 0); - else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) - hal_btcoex_SuspendNotify(padapter, 1); - - rtw_ps_deny_cancel(padapter, PS_DENY_SUSPEND); - - rtw_suspend_normal(padapter); - - netdev_dbg(padapter->pnetdev, "rtw suspend success in %d ms\n", - jiffies_to_msecs(jiffies - start_time)); -} - -static int rtw_resume_process_normal(struct adapter *padapter) -{ - struct net_device *pnetdev; - struct pwrctrl_priv *pwrpriv; - struct mlme_priv *pmlmepriv; - - int ret = _SUCCESS; - - if (!padapter) { - ret = -1; - goto exit; - } - - pnetdev = padapter->pnetdev; - pwrpriv = adapter_to_pwrctl(padapter); - pmlmepriv = &padapter->mlmepriv; - /* interface init */ - if (padapter->intf_init) { - ret = padapter->intf_init(adapter_to_dvobj(padapter)); - if (ret) - goto exit; - } - rtw_sdio_disable_interrupt(padapter); - /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) */ - if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) { - ret = -1; - goto exit; - } - - rtw_reset_drv_sw(padapter); - pwrpriv->bkeepfwalive = false; - - if (pm_netdev_open(pnetdev, true) != 0) { - ret = -1; - goto exit; - } - - netif_device_attach(pnetdev); - netif_carrier_on(pnetdev); - - if (padapter->pid[1] != 0) - rtw_signal_process(padapter->pid[1], SIGUSR2); - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) - rtw_roaming(padapter, NULL); - } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - rtw_ap_restore_network(padapter); - } - -exit: - return ret; -} - -int rtw_resume_common(struct adapter *padapter) -{ - int ret = 0; - unsigned long start_time = jiffies; - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - netdev_dbg(padapter->pnetdev, "resume start\n"); - - rtw_resume_process_normal(padapter); - - hal_btcoex_SuspendNotify(padapter, 0); - - if (pwrpriv) - pwrpriv->bInSuspend = false; - - netdev_dbg(padapter->pnetdev, "%s:%d in %d ms\n", __func__, ret, - jiffies_to_msecs(jiffies - start_time)); - - return ret; -} diff --git a/drivers/staging/rtl8723bs/os_dep/osdep_service.c b/drivers/staging/rtl8723bs/os_dep/osdep_service.c deleted file mode 100644 index 4cfdf7c62344..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/osdep_service.c +++ /dev/null @@ -1,201 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include - -/* Translate the OS dependent error_code to RTW_STATUS_CODE */ -inline int RTW_STATUS_CODE(int error_code) -{ - if (error_code >= 0) - return _SUCCESS; - return _FAIL; -} - -inline int _rtw_netif_rx(struct net_device *ndev, struct sk_buff *skb) -{ - skb->dev = ndev; - return netif_rx(skb); -} - -struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv) -{ - struct net_device *pnetdev; - struct rtw_netdev_priv_indicator *pnpi; - - pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4); - if (!pnetdev) - goto RETURN; - - pnpi = netdev_priv(pnetdev); - pnpi->priv = old_priv; - pnpi->sizeof_priv = sizeof_priv; - -RETURN: - return pnetdev; -} - -struct net_device *rtw_alloc_etherdev(int sizeof_priv) -{ - struct net_device *pnetdev; - struct rtw_netdev_priv_indicator *pnpi; - - pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4); - if (!pnetdev) - goto RETURN; - - pnpi = netdev_priv(pnetdev); - - pnpi->priv = vzalloc(sizeof_priv); - if (!pnpi->priv) { - free_netdev(pnetdev); - pnetdev = NULL; - goto RETURN; - } - - pnpi->sizeof_priv = sizeof_priv; -RETURN: - return pnetdev; -} - -void rtw_free_netdev(struct net_device *netdev) -{ - struct rtw_netdev_priv_indicator *pnpi; - - if (!netdev) - goto RETURN; - - pnpi = netdev_priv(netdev); - - if (!pnpi->priv) - goto RETURN; - - vfree(pnpi->priv); - free_netdev(netdev); - -RETURN: - return; -} - -void rtw_buf_free(u8 **buf, u32 *buf_len) -{ - if (!buf || !buf_len) - return; - - if (*buf) { - *buf_len = 0; - kfree(*buf); - *buf = NULL; - } -} - -void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len) -{ - u32 ori_len = 0, dup_len = 0; - u8 *ori = NULL; - u8 *dup = NULL; - - if (!buf || !buf_len) - return; - - if (!src || !src_len) - goto keep_ori; - - /* duplicate src */ - dup = kmemdup(src, src_len, GFP_ATOMIC); - if (dup) - dup_len = src_len; - -keep_ori: - ori = *buf; - ori_len = *buf_len; - - /* replace buf with dup */ - *buf_len = 0; - *buf = dup; - *buf_len = dup_len; - - /* free ori */ - if (ori && ori_len > 0) - kfree(ori); -} - -/** - * rtw_cbuf_full - test if cbuf is full - * @cbuf: pointer of struct rtw_cbuf - * - * Returns: true if cbuf is full - */ -inline bool rtw_cbuf_full(struct rtw_cbuf *cbuf) -{ - return (cbuf->write == cbuf->read - 1) ? true : false; -} - -/** - * rtw_cbuf_empty - test if cbuf is empty - * @cbuf: pointer of struct rtw_cbuf - * - * Returns: true if cbuf is empty - */ -inline bool rtw_cbuf_empty(struct rtw_cbuf *cbuf) -{ - return (cbuf->write == cbuf->read) ? true : false; -} - -/** - * rtw_cbuf_push - push a pointer into cbuf - * @cbuf: pointer of struct rtw_cbuf - * @buf: pointer to push in - * - * Lock free operation, be careful of the use scheme - * Returns: true push success - */ -bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf) -{ - if (rtw_cbuf_full(cbuf)) - return _FAIL; - - cbuf->bufs[cbuf->write] = buf; - cbuf->write = (cbuf->write + 1) % cbuf->size; - - return _SUCCESS; -} - -/** - * rtw_cbuf_pop - pop a pointer from cbuf - * @cbuf: pointer of struct rtw_cbuf - * - * Lock free operation, be careful of the use scheme - * Returns: pointer popped out - */ -void *rtw_cbuf_pop(struct rtw_cbuf *cbuf) -{ - void *buf; - - if (rtw_cbuf_empty(cbuf)) - return NULL; - - buf = cbuf->bufs[cbuf->read]; - cbuf->read = (cbuf->read + 1) % cbuf->size; - - return buf; -} - -/** - * rtw_cbuf_alloc - allocate a rtw_cbuf with given size and do initialization - * @size: size of pointer - * - * Returns: pointer of srtuct rtw_cbuf, NULL for allocation failure - */ -struct rtw_cbuf *rtw_cbuf_alloc(u32 size) -{ - struct rtw_cbuf *cbuf; - - cbuf = kzalloc_flex(*cbuf, bufs, size); - if (cbuf) - cbuf->size = size; - - return cbuf; -} diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c deleted file mode 100644 index c61d3d12df7f..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c +++ /dev/null @@ -1,465 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include -#include -#include -#include - -#ifndef dev_to_sdio_func -#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev) -#endif - -static const struct sdio_device_id sdio_ids[] = { - { SDIO_DEVICE(0x024c, 0x0523), }, - { SDIO_DEVICE(0x024c, 0x0525), }, - { SDIO_DEVICE(0x024c, 0x0623), }, - { SDIO_DEVICE(0x024c, 0x0626), }, - { SDIO_DEVICE(0x024c, 0x0627), }, - { SDIO_DEVICE(0x024c, 0xb723), }, - { /* end: all zeroes */ }, -}; -MODULE_DEVICE_TABLE(sdio, sdio_ids); - -static int rtw_drv_init(struct sdio_func *func, const struct sdio_device_id *id); -static void rtw_dev_remove(struct sdio_func *func); -static int rtw_sdio_resume(struct device *dev); -static int rtw_sdio_suspend(struct device *dev); - -static const struct dev_pm_ops rtw_sdio_pm_ops = { - .suspend = rtw_sdio_suspend, - .resume = rtw_sdio_resume, -}; - -static struct sdio_driver rtl8723bs_sdio_driver = { - .probe = rtw_drv_init, - .remove = rtw_dev_remove, - .name = "rtl8723bs", - .id_table = sdio_ids, - .drv = { - .pm = &rtw_sdio_pm_ops, - } -}; - -static void sd_sync_int_hdl(struct sdio_func *func) -{ - struct dvobj_priv *psdpriv; - - - psdpriv = sdio_get_drvdata(func); - - if (!psdpriv->if1) - return; - - rtw_sdio_set_irq_thd(psdpriv, current); - sd_int_hdl(psdpriv->if1); - rtw_sdio_set_irq_thd(psdpriv, NULL); -} - -static int sdio_alloc_irq(struct dvobj_priv *dvobj) -{ - struct sdio_data *psdio_data; - struct sdio_func *func; - int err; - - psdio_data = &dvobj->intf_data; - func = psdio_data->func; - - sdio_claim_host(func); - - err = sdio_claim_irq(func, &sd_sync_int_hdl); - if (err) - netdev_crit(dvobj->if1->pnetdev, "%s: sdio_claim_irq FAIL(%d)!\n", __func__, err); - else - dvobj->irq_alloc = 1; - - sdio_release_host(func); - - return err ? _FAIL : _SUCCESS; -} - -static void sdio_free_irq(struct dvobj_priv *dvobj) -{ - struct sdio_data *psdio_data; - struct sdio_func *func; - int err; - - if (dvobj->irq_alloc) { - psdio_data = &dvobj->intf_data; - func = psdio_data->func; - - if (func) { - sdio_claim_host(func); - err = sdio_release_irq(func); - if (err) { - netdev_err(dvobj->if1->pnetdev, - "%s: sdio_release_irq FAIL(%d)!\n", - __func__, err); - } - sdio_release_host(func); - } - dvobj->irq_alloc = 0; - } -} - -static u32 sdio_init(struct dvobj_priv *dvobj) -{ - struct sdio_data *psdio_data; - struct sdio_func *func; - int err; - - psdio_data = &dvobj->intf_data; - func = psdio_data->func; - - /* 3 1. init SDIO bus */ - sdio_claim_host(func); - - err = sdio_enable_func(func); - if (err) - goto release; - - err = sdio_set_block_size(func, 512); - if (err) - goto release; - - psdio_data->block_transfer_len = 512; - psdio_data->tx_block_mode = 1; - psdio_data->rx_block_mode = 1; - -release: - sdio_release_host(func); - - return err; -} - -static void sdio_deinit(struct dvobj_priv *dvobj) -{ - struct sdio_func *func; - - func = dvobj->intf_data.func; - - if (func) { - sdio_claim_host(func); - sdio_disable_func(func); - - if (dvobj->irq_alloc) - sdio_release_irq(func); - - sdio_release_host(func); - } -} -static struct dvobj_priv *sdio_dvobj_init(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = NULL; - struct sdio_data *psdio; - int ret; - - dvobj = devobj_init(); - if (!dvobj) - return NULL; - - sdio_set_drvdata(func, dvobj); - - psdio = &dvobj->intf_data; - psdio->func = func; - - ret = sdio_init(dvobj); - if (ret) - goto free_dvobj; - - rtw_reset_continual_io_error(dvobj); - - return dvobj; - -free_dvobj: - sdio_set_drvdata(func, NULL); - devobj_deinit(dvobj); - - return NULL; -} - -static void sdio_dvobj_deinit(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = sdio_get_drvdata(func); - - sdio_set_drvdata(func, NULL); - if (dvobj) { - sdio_deinit(dvobj); - devobj_deinit(dvobj); - } -} - -void rtw_set_hal_ops(struct adapter *padapter) -{ - /* alloc memory for HAL DATA */ - rtw_hal_data_init(padapter); -} - -static void sd_intf_start(struct adapter *padapter) -{ - if (!padapter) - return; - - rtw_sdio_enable_interrupt(padapter); -} - -static void sd_intf_stop(struct adapter *padapter) -{ - if (!padapter) - return; - - rtw_sdio_disable_interrupt(padapter); -} - - -static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj) -{ - int status = _FAIL; - struct net_device *pnetdev; - struct adapter *padapter = NULL; - struct sdio_data *psdio = &dvobj->intf_data; - - padapter = vzalloc(sizeof(*padapter)); - if (!padapter) - goto exit; - - padapter->dvobj = dvobj; - dvobj->if1 = padapter; - - padapter->driver_stopped = true; - - dvobj->padapters = padapter; - padapter->iface_id = 0; - - /* 3 1. init network device data */ - pnetdev = rtw_init_netdev(padapter); - if (!pnetdev) - goto free_adapter; - - SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj)); - - padapter = rtw_netdev_priv(pnetdev); - - /* 3 3. init driver special setting, interface, OS and hardware relative */ - - /* 4 3.1 set hardware operation functions */ - rtw_set_hal_ops(padapter); - - - /* 3 5. initialize Chip version */ - padapter->intf_start = &sd_intf_start; - padapter->intf_stop = &sd_intf_stop; - - padapter->intf_init = &sdio_init; - padapter->intf_deinit = &sdio_deinit; - padapter->intf_alloc_irq = &sdio_alloc_irq; - padapter->intf_free_irq = &sdio_free_irq; - - if (rtw_init_io_priv(padapter, sdio_set_intf_ops) == _FAIL) - goto free_hal_data; - - rtl8723b_read_chip_version(padapter); - - rtl8723bs_interface_configure(padapter); - - hal_btcoex_Initialize((void *)padapter); - - /* 3 6. read efuse/eeprom data */ - rtw_read_adapter_info(padapter); - - /* 3 7. init driver common data */ - if (rtw_init_drv_sw(padapter) == _FAIL) - goto free_hal_data; - - rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)); - - /* 3 8. get WLan MAC address */ - /* set mac addr */ - rtw_macaddr_cfg(&psdio->func->dev, padapter->eeprompriv.mac_addr); - - rtw_sdio_disable_interrupt(padapter); - - status = _SUCCESS; - -free_hal_data: - if (status != _SUCCESS) - rtw_hal_data_deinit(padapter); - - if (status != _SUCCESS) { - rtw_wdev_unregister(padapter->rtw_wdev); - rtw_wdev_free(padapter->rtw_wdev); - } - -free_adapter: - if (status != _SUCCESS) { - if (pnetdev) - rtw_free_netdev(pnetdev); - else - vfree((u8 *)padapter); - padapter = NULL; - } -exit: - return padapter; -} - -static void rtw_sdio_if1_deinit(struct adapter *if1) -{ - struct net_device *pnetdev = if1->pnetdev; - struct mlme_priv *pmlmepriv = &if1->mlmepriv; - - if (check_fwstate(pmlmepriv, _FW_LINKED)) - rtw_disassoc_cmd(if1, 0, false); - - free_mlme_ap_info(if1); - - rtw_cancel_all_timer(if1); - - rtw_dev_unload(if1); - - if (if1->rtw_wdev) - rtw_wdev_free(if1->rtw_wdev); - - rtw_free_drv_sw(if1); - - if (pnetdev) - rtw_free_netdev(pnetdev); -} - -/* - * drv_init() - a device potentially for us - * - * notes: drv_init() is called when the bus driver has located a card for us to support. - * We accept the new device by returning 0. - */ -static int rtw_drv_init(struct sdio_func *func, - const struct sdio_device_id *id) -{ - int status = _FAIL; - struct adapter *if1 = NULL; - struct dvobj_priv *dvobj; - - dvobj = sdio_dvobj_init(func); - if (!dvobj) - goto exit; - - if1 = rtw_sdio_if1_init(dvobj); - if (!if1) - goto free_dvobj; - - /* dev_alloc_name && register_netdev */ - status = rtw_drv_register_netdev(if1); - if (status != _SUCCESS) - goto free_if1; - - status = sdio_alloc_irq(dvobj); - if (status != _SUCCESS) - goto free_netdev; - - status = _SUCCESS; - -free_netdev: - if (status != _SUCCESS) - rtw_unregister_netdevs(dvobj); -free_if1: - if (status != _SUCCESS && if1) - rtw_sdio_if1_deinit(if1); - -free_dvobj: - if (status != _SUCCESS) - sdio_dvobj_deinit(func); -exit: - return status == _SUCCESS ? 0 : -ENODEV; -} - -static void rtw_dev_remove(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = sdio_get_drvdata(func); - struct adapter *padapter = dvobj->if1; - - dvobj->processing_dev_remove = true; - - rtw_unregister_netdevs(dvobj); - - if (!padapter->bSurpriseRemoved) { - int err; - - /* test surprise remove */ - sdio_claim_host(func); - sdio_readb(func, 0, &err); - sdio_release_host(func); - if (err == -ENOMEDIUM) - padapter->bSurpriseRemoved = true; - } - - rtw_ps_deny(padapter, PS_DENY_DRV_REMOVE); - - rtw_pm_set_ips(padapter, IPS_NONE); - rtw_pm_set_lps(padapter, PS_MODE_ACTIVE); - - LeaveAllPowerSaveMode(padapter); - - rtw_btcoex_halt_notify(padapter); - - rtw_sdio_if1_deinit(padapter); - - sdio_dvobj_deinit(func); -} - -static int rtw_sdio_suspend(struct device *dev) -{ - struct sdio_func *func = dev_to_sdio_func(dev); - struct dvobj_priv *psdpriv = sdio_get_drvdata(func); - struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv); - struct adapter *padapter = psdpriv->if1; - - if (padapter->driver_stopped) - return 0; - - if (pwrpriv->bInSuspend) - return 0; - - rtw_suspend_common(padapter); - - return 0; -} - -static int rtw_resume_process(struct adapter *padapter) -{ - struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); - - if (!pwrpriv->bInSuspend) - return -1; - - return rtw_resume_common(padapter); -} - -static int rtw_sdio_resume(struct device *dev) -{ - struct sdio_func *func = dev_to_sdio_func(dev); - struct dvobj_priv *psdpriv = sdio_get_drvdata(func); - struct adapter *padapter = psdpriv->if1; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - int ret = 0; - - ret = rtw_resume_process(padapter); - - pmlmeext->last_scan_time = jiffies; - return ret; -} - -static int __init rtw_drv_entry(void) -{ - return sdio_register_driver(&rtl8723bs_sdio_driver); -} -module_init(rtw_drv_entry); - -static void __exit rtw_drv_halt(void) -{ - sdio_unregister_driver(&rtl8723bs_sdio_driver); -} -module_exit(rtw_drv_halt); - -MODULE_DESCRIPTION("Realtek RTL8723BS SDIO WiFi driver"); diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c b/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c deleted file mode 100644 index e9a2f3f7ec74..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c +++ /dev/null @@ -1,495 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - *******************************************************************************/ - -#include - -static bool rtw_sdio_claim_host_needed(struct sdio_func *func) -{ - struct dvobj_priv *dvobj = sdio_get_drvdata(func); - struct sdio_data *sdio_data = &dvobj->intf_data; - - if (sdio_data->sys_sdio_irq_thd && sdio_data->sys_sdio_irq_thd == current) - return false; - return true; -} - -inline void rtw_sdio_set_irq_thd(struct dvobj_priv *dvobj, void *thd_hdl) -{ - struct sdio_data *sdio_data = &dvobj->intf_data; - - sdio_data->sys_sdio_irq_thd = thd_hdl; -} - -/* - * Return: - *0 Success - *others Fail - */ -s32 _sd_cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - int err = 0, i; - struct sdio_func *func; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - - for (i = 0; i < cnt; i++) { - pdata[i] = sdio_readb(func, addr + i, &err); - if (err) - break; - } - return err; -} - -/* - * Return: - *0 Success - *others Fail - */ -s32 sd_cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - int err = 0; - struct sdio_func *func; - bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_cmd52_read(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); - return err; -} - -/* - * Return: - *0 Success - *others Fail - */ -s32 _sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - int err = 0, i; - struct sdio_func *func; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - - for (i = 0; i < cnt; i++) { - sdio_writeb(func, pdata[i], addr + i, &err); - if (err) - break; - } - return err; -} - -/* - * Return: - *0 Success - *others Fail - */ -s32 sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - int err = 0; - struct sdio_func *func; - bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_cmd52_write(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); - return err; -} - -u8 sd_read8(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - u8 v = 0; - struct sdio_func *func; - bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return v; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - v = sdio_readb(func, addr, err); - if (claim_needed) - sdio_release_host(func); - return v; -} - -u32 sd_read32(struct intf_hdl *pintfhdl, u32 addr, s32 *err) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - u32 v = 0; - struct sdio_func *func; - bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return v; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - v = sdio_readl(func, addr, err); - if (claim_needed) - sdio_release_host(func); - - if (err && *err) { - int i; - - *err = 0; - for (i = 0; i < SD_IO_TRY_CNT; i++) { - if (claim_needed) - sdio_claim_host(func); - v = sdio_readl(func, addr, err); - if (claim_needed) - sdio_release_host(func); - - if (*err == 0) { - rtw_reset_continual_io_error(psdiodev); - break; - } - - if ((-ESHUTDOWN == *err) || (-ENODEV == *err)) - padapter->bSurpriseRemoved = true; - - if (rtw_inc_and_chk_continual_io_error(psdiodev)) { - padapter->bSurpriseRemoved = true; - break; - } - } - } - return v; -} - -void sd_write8(struct intf_hdl *pintfhdl, u32 addr, u8 v, s32 *err) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - struct sdio_func *func; - bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - sdio_writeb(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); -} - -void sd_write32(struct intf_hdl *pintfhdl, u32 addr, u32 v, s32 *err) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - struct sdio_func *func; - bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - sdio_writel(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); - - if (err && *err) { - int i; - - *err = 0; - for (i = 0; i < SD_IO_TRY_CNT; i++) { - if (claim_needed) - sdio_claim_host(func); - sdio_writel(func, v, addr, err); - if (claim_needed) - sdio_release_host(func); - if (*err == 0) { - rtw_reset_continual_io_error(psdiodev); - break; - } - - if ((-ESHUTDOWN == *err) || (-ENODEV == *err)) - padapter->bSurpriseRemoved = true; - - if (rtw_inc_and_chk_continual_io_error(psdiodev)) { - padapter->bSurpriseRemoved = true; - break; - } - } - } -} - -/* - * Use CMD53 to read data from SDIO device. - * This function MUST be called after sdio_claim_host() or - * in SDIO ISR(host had been claimed). - * - * Parameters: - *psdio pointer of SDIO_DATA - *addr address to read - *cnt amount to read - *pdata pointer to put data, this should be a "DMA:able scratch buffer"! - * - * Return: - *0 Success - *others Fail - */ -s32 _sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - int err = -EPERM; - struct sdio_func *func; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - - if (unlikely((cnt == 1) || (cnt == 2))) { - int i; - u8 *pbuf = pdata; - - for (i = 0; i < cnt; i++) { - *(pbuf + i) = sdio_readb(func, addr + i, &err); - - if (err) - break; - } - return err; - } - - err = sdio_memcpy_fromio(func, pdata, addr, cnt); - - return err; -} - -/* - * Use CMD53 to read data from SDIO device. - * - * Parameters: - *psdio pointer of SDIO_DATA - *addr address to read - *cnt amount to read - *pdata pointer to put data, this should be a "DMA:able scratch buffer"! - * - * Return: - *0 Success - *others Fail - */ -s32 sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - struct sdio_func *func; - bool claim_needed; - s32 err = -EPERM; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_read(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); - return err; -} - -/* - * Use CMD53 to write data to SDIO device. - * This function MUST be called after sdio_claim_host() or - * in SDIO ISR(host had been claimed). - * - * Parameters: - *psdio pointer of SDIO_DATA - *addr address to write - *cnt amount to write - *pdata data pointer, this should be a "DMA:able scratch buffer"! - * - * Return: - *0 Success - *others Fail - */ -s32 _sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - - struct sdio_func *func; - u32 size; - s32 err = -EPERM; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; -/* size = sdio_align_size(func, cnt); */ - - if (unlikely((cnt == 1) || (cnt == 2))) { - int i; - u8 *pbuf = pdata; - - for (i = 0; i < cnt; i++) { - sdio_writeb(func, *(pbuf + i), addr + i, &err); - if (err) - break; - } - - return err; - } - - size = cnt; - err = sdio_memcpy_toio(func, addr, pdata, size); - - return err; -} - -/* - * Use CMD53 to write data to SDIO device. - * - * Parameters: - * psdio pointer of SDIO_DATA - * addr address to write - * cnt amount to write - * pdata data pointer, this should be a "DMA:able scratch buffer"! - * - * Return: - * 0 Success - * others Fail - */ -s32 sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata) -{ - struct adapter *padapter; - struct dvobj_priv *psdiodev; - struct sdio_data *psdio; - struct sdio_func *func; - bool claim_needed; - s32 err = -EPERM; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - - if (padapter->bSurpriseRemoved) - return err; - - func = psdio->func; - claim_needed = rtw_sdio_claim_host_needed(func); - - if (claim_needed) - sdio_claim_host(func); - err = _sd_write(pintfhdl, addr, cnt, pdata); - if (claim_needed) - sdio_release_host(func); - return err; -} diff --git a/drivers/staging/rtl8723bs/os_dep/wifi_regd.c b/drivers/staging/rtl8723bs/os_dep/wifi_regd.c deleted file mode 100644 index d201a18d78b0..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/wifi_regd.c +++ /dev/null @@ -1,129 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2009-2010 Realtek Corporation. - * - *****************************************************************************/ - -#include - -#include - -/* - * REG_RULE(freq start, freq end, bandwidth, max gain, eirp, reg_flags) - */ - -/* - * Only these channels all allow active - * scan on all world regulatory domains - */ - -/* 2G chan 01 - chan 11 */ -#define RTW_2GHZ_CH01_11 \ - REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0) - -/* - * We enable active scan on these a case - * by case basis by regulatory domain - */ - -/* 2G chan 12 - chan 13, PASSIV SCAN */ -#define RTW_2GHZ_CH12_13 \ - REG_RULE(2467 - 10, 2472 + 10, 40, 0, 20, \ - NL80211_RRF_PASSIVE_SCAN) - -static const struct ieee80211_regdomain rtw_regdom_rd = { - .n_reg_rules = 2, - .alpha2 = "99", - .reg_rules = { - RTW_2GHZ_CH01_11, - RTW_2GHZ_CH12_13, - } -}; - -static void _rtw_reg_apply_flags(struct wiphy *wiphy) -{ - struct adapter *padapter = wiphy_to_adapter(wiphy); - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct rt_channel_info *channel_set = pmlmeext->channel_set; - u8 max_chan_nums = pmlmeext->max_chan_nums; - - struct ieee80211_supported_band *sband; - struct ieee80211_channel *ch; - unsigned int i, j; - u16 channel; - u32 freq; - - /* all channels disable */ - for (i = 0; i < NUM_NL80211_BANDS; i++) { - sband = wiphy->bands[i]; - - if (sband) { - for (j = 0; j < sband->n_channels; j++) { - ch = &sband->channels[j]; - - if (ch) - ch->flags = IEEE80211_CHAN_DISABLED; - } - } - } - - /* channels apply by channel plans. */ - for (i = 0; i < max_chan_nums; i++) { - channel = channel_set[i].channel_num; - freq = rtw_ieee80211_channel_to_frequency(channel); - ch = ieee80211_get_channel(wiphy, freq); - if (ch) { - if (channel_set[i].scan_type == SCAN_PASSIVE) - ch->flags = IEEE80211_CHAN_NO_IR; - else - ch->flags = 0; - } - } -} - -static int _rtw_reg_notifier_apply(struct wiphy *wiphy, - struct regulatory_request *request) -{ - /* Hard code flags */ - _rtw_reg_apply_flags(wiphy); - return 0; -} - -static const struct ieee80211_regdomain *_rtw_regdomain_select(void) -{ - return &rtw_regdom_rd; -} - -static void _rtw_regd_init_wiphy(struct wiphy *wiphy, - void (*reg_notifier)(struct wiphy *wiphy, - struct - regulatory_request * - request)) -{ - const struct ieee80211_regdomain *regd; - - wiphy->reg_notifier = reg_notifier; - - wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; - wiphy->regulatory_flags &= ~REGULATORY_STRICT_REG; - wiphy->regulatory_flags &= ~REGULATORY_DISABLE_BEACON_HINTS; - - regd = _rtw_regdomain_select(); - wiphy_apply_custom_regulatory(wiphy, regd); - - /* Hard code flags */ - _rtw_reg_apply_flags(wiphy); -} - -void rtw_regd_init(struct wiphy *wiphy, - void (*reg_notifier)(struct wiphy *wiphy, - struct regulatory_request *request)) -{ - _rtw_regd_init_wiphy(wiphy, reg_notifier); -} - -void rtw_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) -{ - _rtw_reg_notifier_apply(wiphy, request); -} diff --git a/drivers/staging/rtl8723bs/os_dep/xmit_linux.c b/drivers/staging/rtl8723bs/os_dep/xmit_linux.c deleted file mode 100644 index 3b6029c20d50..000000000000 --- a/drivers/staging/rtl8723bs/os_dep/xmit_linux.c +++ /dev/null @@ -1,216 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/****************************************************************************** - * - * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -#include - - -unsigned int rtw_remainder_len(struct pkt_file *pfile) -{ - return (pfile->buf_len - ((SIZE_PTR)(pfile->cur_addr) - (SIZE_PTR)(pfile->buf_start))); -} - -void _rtw_open_pktfile(struct sk_buff *pktptr, struct pkt_file *pfile) -{ - pfile->pkt = pktptr; - pfile->buf_start = pktptr->data; - pfile->cur_addr = pktptr->data; - pfile->buf_len = pktptr->len; - pfile->pkt_len = pktptr->len; - - pfile->cur_buffer = pfile->buf_start; -} - -int _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, unsigned int rlen) -{ - int ret; - unsigned int remain = rtw_remainder_len(pfile); - - /* clamp to bytes remaining; the coalesce loop relies on short reads */ - if (rlen > remain) - rlen = remain; - - if (rmem) { - ret = skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, rlen); - if (ret < 0) - return ret; - } - - pfile->cur_addr += rlen; - pfile->pkt_len -= rlen; - return rlen; -} - -signed int rtw_endofpktfile(struct pkt_file *pfile) -{ - if (pfile->pkt_len == 0) - return true; - return false; -} - -void rtw_os_xmit_resource_free(struct adapter *padapter, - struct xmit_buf *pxmitbuf, - u32 free_sz, u8 flag) -{ - if (free_sz > 0) - kfree(pxmitbuf->pallocated_buf); -} - -#define WMM_XMIT_THRESHOLD (NR_XMITFRAME * 2 / 5) - -void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt) -{ - u16 queue; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - - queue = skb_get_queue_mapping(pkt); - if (padapter->registrypriv.wifi_spec) { - if (__netif_subqueue_stopped(padapter->pnetdev, queue) && - (pxmitpriv->hwxmits[queue].accnt < WMM_XMIT_THRESHOLD)) - netif_wake_subqueue(padapter->pnetdev, queue); - } else { - if (__netif_subqueue_stopped(padapter->pnetdev, queue)) - netif_wake_subqueue(padapter->pnetdev, queue); - } - - dev_kfree_skb_any(pkt); -} - -void rtw_os_xmit_complete(struct adapter *padapter, struct xmit_frame *pxframe) -{ - if (pxframe->pkt) - rtw_os_pkt_complete(padapter, pxframe->pkt); - - pxframe->pkt = NULL; -} - -void rtw_os_xmit_schedule(struct adapter *padapter) -{ - struct adapter *pri_adapter = padapter; - - if (!padapter) - return; - - if (!list_empty(&padapter->xmitpriv.pending_xmitbuf_queue.queue)) - complete(&pri_adapter->xmitpriv.xmit_comp); -} - -static void rtw_check_xmit_resource(struct adapter *padapter, struct sk_buff *pkt) -{ - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - u16 queue; - - queue = skb_get_queue_mapping(pkt); - if (padapter->registrypriv.wifi_spec) { - /* No free space for Tx, tx_worker is too slow */ - if (pxmitpriv->hwxmits[queue].accnt > WMM_XMIT_THRESHOLD) - netif_stop_subqueue(padapter->pnetdev, queue); - } else { - if (pxmitpriv->free_xmitframe_cnt <= 4) { - if (!netif_tx_queue_stopped(netdev_get_tx_queue(padapter->pnetdev, queue))) - netif_stop_subqueue(padapter->pnetdev, queue); - } - } -} - -static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb) -{ - struct sta_priv *pstapriv = &padapter->stapriv; - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct list_head *phead, *plist; - struct sk_buff *newskb; - struct sta_info *psta = NULL; - u8 chk_alive_num = 0; - char chk_alive_list[NUM_STA]; - u8 bc_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - u8 null_addr[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - int i; - s32 res; - - spin_lock_bh(&pstapriv->asoc_list_lock); - phead = &pstapriv->asoc_list; - /* free sta asoc_queue */ - list_for_each(plist, phead) { - int stainfo_offset; - - psta = list_entry(plist, struct sta_info, asoc_list); - - stainfo_offset = rtw_stainfo_offset(pstapriv, psta); - if (stainfo_offset_valid(stainfo_offset)) - chk_alive_list[chk_alive_num++] = stainfo_offset; - } - spin_unlock_bh(&pstapriv->asoc_list_lock); - - for (i = 0; i < chk_alive_num; i++) { - psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]); - if (!(psta->state & _FW_LINKED)) - continue; - - /* avoid come from STA1 and send back STA1 */ - if (!memcmp(psta->hwaddr, &skb->data[6], 6) || - !memcmp(psta->hwaddr, null_addr, 6) || - !memcmp(psta->hwaddr, bc_addr, 6)) - continue; - - newskb = skb_copy(skb, GFP_ATOMIC); - if (newskb) { - memcpy(newskb->data, psta->hwaddr, 6); - res = rtw_xmit(padapter, &newskb); - if (res < 0) { - pxmitpriv->tx_drop++; - dev_kfree_skb_any(newskb); - } - } else { - pxmitpriv->tx_drop++; - /* dev_kfree_skb_any(skb); */ - return false; /* Caller shall tx this multicast frame via normal way. */ - } - } - - dev_kfree_skb_any(skb); - return true; -} - -void _rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev) -{ - struct adapter *padapter = rtw_netdev_priv(pnetdev); - struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - s32 res = 0; - - if (!rtw_if_up(padapter)) - goto drop_packet; - - rtw_check_xmit_resource(padapter, pkt); - - if (!rtw_mc2u_disable && check_fwstate(pmlmepriv, WIFI_AP_STATE) && - (IP_MCAST_MAC(pkt->data) || ICMPV6_MCAST_MAC(pkt->data)) && - !padapter->registrypriv.wifi_spec) { - if (pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME / 4)) { - res = rtw_mlcst2unicst(padapter, pkt); - if (res) - return; - } - } - - res = rtw_xmit(padapter, &pkt); - if (res < 0) - goto drop_packet; - - return; - -drop_packet: - pxmitpriv->tx_drop++; - dev_kfree_skb_any(pkt); -} - -netdev_tx_t rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev) -{ - if (pkt) - _rtw_xmit_entry(pkt, pnetdev); - - return NETDEV_TX_OK; -} From 411e89374aa2fb5588bb3077122d3485c57ff589 Mon Sep 17 00:00:00 2001 From: Bitterblue Smith Date: Wed, 7 Oct 2026 13:02:08 +0300 Subject: [PATCH 1377/2126] wifi: rtw89: Override antenna number for RTL8852BE-VS RTL8852BE-VS (PCI ID 10ec:b85b, RFE type 41) has only one spatial stream and likely one physical antenna, but the firmware reports two antennas. This results in the driver configuring the wrong RF path, which leads to very poor reception. Users complain that 5 GHz networks are not visible. Hardcode the number of antennas for this RFE type to one, and the correct RF path for the Bluetooth coexistence code. This is what the vendor driver does. Closes: https://lore.kernel.org/linux-wireless/10543730.tdPhlSkOF2@topolinux/ Closes: https://github.com/morrownr/rtw89/issues/128 Signed-off-by: Bitterblue Smith Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/c6f85442-dd1e-4971-943a-31bfb54eb0ed@gmail.com --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/mac.c | 5 ++++ drivers/net/wireless/realtek/rtw89/rtw8852b.c | 24 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index f9c0f4923d82..0d893b992a4a 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -6575,6 +6575,7 @@ enum rtw89_quirks { RTW89_QUIRK_THERMAL_PROT_VCORE, RTW89_QUIRK_HW_INFO_SYSFS, RTW89_QUIRK_DISABLE_2GHZ, + RTW89_QUIRK_1ANT, NUM_OF_RTW89_QUIRKS, }; diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c index ad849e4b4a50..098b2372e65b 100644 --- a/drivers/net/wireless/realtek/rtw89/mac.c +++ b/drivers/net/wireless/realtek/rtw89/mac.c @@ -3244,6 +3244,11 @@ static int rtw89_mac_setup_phycap_part0(struct rtw89_dev *rtwdev) tx_ant = u32_get_bits(phycap->w3, RTW89_C2HREG_PHYCAP_W3_ANT_TX_NUM); rx_ant = u32_get_bits(phycap->w3, RTW89_C2HREG_PHYCAP_W3_ANT_RX_NUM); + if (test_bit(RTW89_QUIRK_1ANT, rtwdev->quirks)) { + tx_ant = 1; + rx_ant = 1; + } + hal->tx_nss = tx_nss ? min_t(u8, tx_nss, chip->tx_nss) : chip->tx_nss; hal->rx_nss = rx_nss ? min_t(u8, rx_nss, chip->rx_nss) : chip->rx_nss; diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852b.c b/drivers/net/wireless/realtek/rtw89/rtw8852b.c index 060c99532936..d19388b86aca 100644 --- a/drivers/net/wireless/realtek/rtw89/rtw8852b.c +++ b/drivers/net/wireless/realtek/rtw89/rtw8852b.c @@ -353,6 +353,21 @@ static const struct rtw89_btc_fbtc_mreg rtw89_btc_8852b_mon_reg[] = { static const u8 rtw89_btc_8852b_wl_rssi_thres[BTC_WL_RSSI_THMAX] = {70, 60, 50, 40}; static const u8 rtw89_btc_8852b_bt_rssi_thres[BTC_BT_RSSI_THMAX] = {50, 40, 30, 20}; +static int rtw8852b_read_efuse(struct rtw89_dev *rtwdev, u8 *log_map, + enum rtw89_efuse_block block) +{ + int ret; + + ret = rtw8852bx_read_efuse(rtwdev, log_map, block); + if (ret) + return ret; + + if (rtwdev->efuse.rfe_type == 41) + set_bit(RTW89_QUIRK_1ANT, rtwdev->quirks); + + return 0; +} + static void rtw8852b_pwr_sps_ana(struct rtw89_dev *rtwdev) { rtw89_write16(rtwdev, R_AX_SPS_ANA_ON_CTRL2, RTL8852B_DEFAULT_SPS_ANA); @@ -773,6 +788,13 @@ static void rtw8852b_btc_set_rfe(struct rtw89_dev *rtwdev) md->bt0_pos = BTC_BT_BTG; /* the only BT shares the BTG antenna with WL path B */ dm->ant_xmap[BTC_RF_S1][BTC_BT_1ST] = 1; + + if (test_bit(RTW89_QUIRK_1ANT, rtwdev->quirks)) { + md->ant.num = 1; + md->ant.single_pos = RF_PATH_B; + md->ant.btg_pos = RF_PATH_B; + md->ant.stream_cnt = 1; + } } rtwdev->btc.btg_pos = md->ant.btg_pos; rtwdev->btc.ant_type = md->ant.type; @@ -856,7 +878,7 @@ static const struct rtw89_chip_ops rtw8852b_chip_ops = { .write_rf = rtw89_phy_write_rf_v1, .set_channel = rtw8852b_set_channel, .set_channel_help = rtw8852b_set_channel_help, - .read_efuse = rtw8852bx_read_efuse, + .read_efuse = rtw8852b_read_efuse, .read_phycap = rtw8852bx_read_phycap, .fem_setup = NULL, .data_setup = NULL, From 6c17c57d45ef1652d80f79a9834597b25412fd26 Mon Sep 17 00:00:00 2001 From: Tristan Madani Date: Wed, 7 Oct 2026 16:17:21 +0000 Subject: [PATCH 1378/2126] wifi: rtw89: fix IE length passed to cfg80211_find_ie() in WoW AKM __rtw89_wow_parse_akm() computes a pointer to the IE area from an association request frame: ies = mgmt->u.assoc_req.variable; but then passes skb->len as the IE data length to cfg80211_find_ie(). Since skb->len covers the entire frame including the 28-byte management header and fixed fields, cfg80211_find_ie() may read past the end of the actual IE data. Fix by computing the correct IE data length as skb->len minus the header offset, and validating the minimum frame length before parsing. Fixes: 92790c4e50d2 ("wifi: rtw89: wow: parsing Auth Key Management from associate request") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261007161721.261452-3-tristmd@gmail.com --- drivers/net/wireless/realtek/rtw89/wow.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/wow.c b/drivers/net/wireless/realtek/rtw89/wow.c index b9892ab84225..31cca0c4e6e5 100644 --- a/drivers/net/wireless/realtek/rtw89/wow.c +++ b/drivers/net/wireless/realtek/rtw89/wow.c @@ -16,10 +16,14 @@ void __rtw89_wow_parse_akm(struct rtw89_dev *rtwdev, struct sk_buff *skb) { struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; struct rtw89_wow_param *rtw_wow = &rtwdev->wow; + size_t hdr_len = offsetof(struct ieee80211_mgmt, u.assoc_req.variable); const u8 *rsn, *ies = mgmt->u.assoc_req.variable; struct rtw89_rsn_ie *rsn_ie; - rsn = cfg80211_find_ie(WLAN_EID_RSN, ies, skb->len); + if (skb->len < hdr_len) + return; + + rsn = cfg80211_find_ie(WLAN_EID_RSN, ies, skb->len - hdr_len); if (!rsn) return; From 83de3a16c7b37064a59305040ba9b0f93b832794 Mon Sep 17 00:00:00 2001 From: Devin Wittmayer Date: Wed, 7 Oct 2026 14:09:58 -0700 Subject: [PATCH 1379/2126] wifi: rtw89: usb: shorten the RX aggregation hold on RTL8922AU over USB 3 The RTL8922AU holds received frames for up to a millisecond before handing them to the host, a value carried over from the RTL8852CU. On USB 3 that adds up to a millisecond of round trip, and under load at 160 MHz the access point drops to lower rates and download suffers. Shorten the hold on USB 3 only. On USB 2 the bus is the limit, and a slow host needs the long hold to keep up. RTL8922AU on USB 3 at 160 MHz, power save off for the round trip: x86, 6 GHz x86, 5 GHz Pi 5, 6 GHz before after before after before after TCP down, 1 flow 613 1002 579 948 587 1010 Mbps TCP down, 8 flows 656 1187 629 1080 605 1122 Mbps round trip 2.33 1.29 2.25 1.18 1.42 0.84 ms busiest core, UDP 200M 8.4 12.8 8.3 12.9 2.1 3.3 % RTL8922AU on USB 2, Raspberry Pi 1 B+ at 5 GHz, 80 MHz: long hold short hold TCP up, 1 flow 102.3 87.7 Mbps CPU, UDP 20M 50.5 77.4 % loss, UDP 50M 3.8 85.7 % Fixes: 32cee8a9bb66 ("wifi: rtw89: usb: Enable RX aggregation for RTL8922AU") Reported-by: Nick Morrow Cc: stable@vger.kernel.org Signed-off-by: Devin Wittmayer Acked-by: Ping-Ke Shih Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20261007210958.56528-1-lucid_duck@justthetip.ca --- drivers/net/wireless/realtek/rtw89/usb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/usb.c b/drivers/net/wireless/realtek/rtw89/usb.c index dbad42c17761..8dc2c93e502e 100644 --- a/drivers/net/wireless/realtek/rtw89/usb.c +++ b/drivers/net/wireless/realtek/rtw89/usb.c @@ -819,10 +819,15 @@ static void rtw89_usb_rx_agg_cfg_v2(struct rtw89_dev *rtwdev) static void rtw89_usb_rx_agg_cfg_v3(struct rtw89_dev *rtwdev) { - const u32 rxagg_0 = FIELD_PREP_CONST(B_BE_RXAGG_0_EN, 1) | - FIELD_PREP_CONST(B_BE_RXAGG_0_NUM_TH, 255) | - FIELD_PREP_CONST(B_BE_RXAGG_0_TIME_32US_TH, 32) | - FIELD_PREP_CONST(B_BE_RXAGG_0_BUF_SZ_1K, 20); + struct rtw89_usb *rtwusb = rtw89_usb_priv(rtwdev); + u32 rxagg_0 = FIELD_PREP_CONST(B_BE_RXAGG_0_EN, 1) | + FIELD_PREP_CONST(B_BE_RXAGG_0_NUM_TH, 255) | + FIELD_PREP_CONST(B_BE_RXAGG_0_BUF_SZ_1K, 20); + + if (rtwusb->udev->speed == USB_SPEED_SUPER) + rxagg_0 |= FIELD_PREP_CONST(B_BE_RXAGG_0_TIME_32US_TH, 1); + else + rxagg_0 |= FIELD_PREP_CONST(B_BE_RXAGG_0_TIME_32US_TH, 32); rtw89_write32(rtwdev, R_BE_RXAGG_0_V1, rxagg_0); rtw89_write32(rtwdev, R_BE_RXAGG_1_V1, 0x1F); From c16411fff03b29a806898b20338ed3ef27124f96 Mon Sep 17 00:00:00 2001 From: Thomas Fourier Date: Tue, 6 Oct 2026 16:32:40 +0200 Subject: [PATCH 1380/2126] net: ethernet: i825xx: Fix dma_alloc_coherent() size In sni_82596_probe(), the lp->dma buffer is allocated with dma_alloc_coherent() and with size sizeof(struct i596_dma), and possibly freed in the error path with the same size. However, in sni_82596_driver_remove(), the same buffer is freed but with size sizeof(struct i596_private). This error may leave the freed buffers mapped, leaking a resource and allowing the device to access freed memory. Change the length in sni_82596_driver_remove() to sizeof(struct i596_dma). This patch was compile tested only, and found by hand. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Signed-off-by: Thomas Fourier Reviewed-by: Jacob Keller Link: https://patch.msgid.link/20261006143247.54724-2-fourier.thomas@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/i825xx/sni_82596.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/i825xx/sni_82596.c b/drivers/net/ethernet/i825xx/sni_82596.c index baa598988f47..73e1e153cb78 100644 --- a/drivers/net/ethernet/i825xx/sni_82596.c +++ b/drivers/net/ethernet/i825xx/sni_82596.c @@ -159,7 +159,7 @@ static void sni_82596_driver_remove(struct platform_device *pdev) struct i596_private *lp = netdev_priv(dev); unregister_netdev(dev); - dma_free_coherent(&pdev->dev, sizeof(struct i596_private), lp->dma, + dma_free_coherent(&pdev->dev, sizeof(struct i596_dma), lp->dma, lp->dma_addr); iounmap(lp->ca); iounmap(lp->mpu_port); From 4e3b56eb2ed879353de392acec7b485b123840a4 Mon Sep 17 00:00:00 2001 From: Naman Gulati Date: Tue, 6 Oct 2026 23:51:13 +0000 Subject: [PATCH 1381/2126] net: gro_cells: prevent enabling threaded NAPI on gro_cells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gro_cells allocates a per-CPU struct gro_cell with per-CPU queues (cell->napi_skbs), per-CPU local_lock_t (cell->bh_lock), and per-CPU napi_struct (cell->napi). On !CONFIG_PREEMPT_RT, local_lock_t only provides lockdep annotation (and is a complete no-op when CONFIG_DEBUG_LOCK_ALLOC is disabled), relying on per-CPU locality and disabled BH context for mutual exclusion; it does not provide cross-CPU synchronization. When threaded NAPI is enabled on a device backed by gro_cells (e.g. gre0, vxlan, geneve) via sysfs, unbound kernel threads are created for each per-CPU NAPI. When gro_cells_receive() on CPU A enqueues a packet to cell_A and calls napi_schedule(&cell_A->napi) while holding cell_A->bh_lock, the woken kthread can run concurrently on remote CPU B. When CPU B runs gro_cell_poll(&cell_A->napi) and calls __local_lock_nested_bh(&cell_A->bh_lock), lockdep detects that the lock is already held by CPU A's task and triggers a warning: WARNING: CPU: 1 PID: 377 at net/core/gro_cells.c:66 gro_cell_poll DEBUG_LOCKS_WARN_ON(l->owner) CPU: 1 UID: 0 PID: 377 Comm: napi/gre0-0 Not tainted 7.3.0-rc2 Call Trace: __local_lock_nested_bh include/linux/local_lock_internal.h:92 gro_cell_poll+0x5aa/0x6c0 net/core/gro_cells.c:66 napi_threaded_poll+0x39b/0x600 net/core/dev.c:7048 kthread+0x71e/0x870 kernel/kthread.c:464 ret_from_fork+0x5d/0x90 arch/x86/kernel/process.c:167 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:264 On !CONFIG_PREEMPT_RT kernels without lockdep, concurrent execution of __skb_queue_tail() on CPU A and __skb_dequeue() on CPU B without cross-CPU locks leads to silent queue corruption. Virtual per-CPU NAPIs cannot support unbound threaded NAPI. While gro_cells also sets NAPI_STATE_NO_BUSY_POLL (which skips napi_hash_add() and prevents configuring them via Netlink), NAPI_STATE_NO_BUSY_POLL cannot be used to reject threaded NAPI in sysfs because drivers such as WireGuard set NAPI_STATE_NO_BUSY_POLL on per-peer NAPIs while running them in threaded mode by default. Introduce NAPI_STATE_PERCPU to mark per-CPU NAPIs that cannot run in unbound threaded mode. Set NAPI_STATE_PERCPU in gro_cells_init(), and fail early with -EOPNOTSUPP in modify_napi_threaded() and netdev_nl_napi_set_config() when trying to enable threaded NAPI on NAPI_STATE_PERCPU NAPIs, while still allowing disabling (writing 0) as a no-op. Fixes: 25718fdcbdd2 ("net: gro_cells: Use nested-BH locking for gro_cell") Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support") Reported-by: syzbot+f0661448aa9511ce744a@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/6aad6d7b.0c43d342.320d00.0001.GAE@google.com Signed-off-by: Naman Gulati Reviewed-by: Björn Töpel Link: https://patch.msgid.link/20261006235113.2394030-1-namangulati@google.com Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 2 ++ net/core/gro_cells.c | 1 + net/core/net-sysfs.c | 8 ++++++++ net/core/netdev-genl.c | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8cae9b00211e..5b4b92e76b67 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -433,6 +433,7 @@ enum { NAPI_STATE_SCHED_THREADED, /* Napi is currently scheduled in threaded mode */ NAPI_STATE_HAS_NOTIFIER, /* Napi has an IRQ notifier */ NAPI_STATE_THREADED_BUSY_POLL, /* The threaded NAPI poller will busy poll */ + NAPI_STATE_PERCPU, /* NAPI handler is run per-CPU - incompatible with threaded mode */ }; enum { @@ -448,6 +449,7 @@ enum { NAPIF_STATE_SCHED_THREADED = BIT(NAPI_STATE_SCHED_THREADED), NAPIF_STATE_HAS_NOTIFIER = BIT(NAPI_STATE_HAS_NOTIFIER), NAPIF_STATE_THREADED_BUSY_POLL = BIT(NAPI_STATE_THREADED_BUSY_POLL), + NAPIF_STATE_PERCPU = BIT(NAPI_STATE_PERCPU), }; enum gro_result { diff --git a/net/core/gro_cells.c b/net/core/gro_cells.c index 1d64207bf960..31352cac355c 100644 --- a/net/core/gro_cells.c +++ b/net/core/gro_cells.c @@ -95,6 +95,7 @@ int gro_cells_init(struct gro_cells *gcells, struct net_device *dev) local_lock_init(&cell->bh_lock); set_bit(NAPI_STATE_NO_BUSY_POLL, &cell->napi.state); + set_bit(NAPI_STATE_PERCPU, &cell->napi.state); netif_napi_add(dev, &cell->napi, gro_cell_poll); napi_enable(&cell->napi); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index fa6f821c8846..b9eeb9972f2b 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -757,6 +757,7 @@ static ssize_t threaded_show(struct device *dev, static int modify_napi_threaded(struct net_device *dev, unsigned long val) { + struct napi_struct *napi; int ret; if (list_empty(&dev->napi_list)) @@ -765,6 +766,13 @@ static int modify_napi_threaded(struct net_device *dev, unsigned long val) if (val != 0 && val != 1) return -EOPNOTSUPP; + if (val) { + list_for_each_entry(napi, &dev->napi_list, dev_list) { + if (test_bit(NAPI_STATE_PERCPU, &napi->state)) + return -EOPNOTSUPP; + } + } + ret = netif_set_threaded(dev, val); return ret; diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 690c27f63d26..dce4758a812d 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -338,6 +338,12 @@ netdev_nl_napi_set_config(struct napi_struct *napi, struct genl_info *info) int ret; threaded = nla_get_uint(info->attrs[NETDEV_A_NAPI_THREADED]); + if (threaded && test_bit(NAPI_STATE_PERCPU, &napi->state)) { + NL_SET_BAD_ATTR(info->extack, + info->attrs[NETDEV_A_NAPI_THREADED]); + return -EOPNOTSUPP; + } + ret = napi_set_threaded(napi, threaded); if (ret) return ret; From 670ff95811b0f2f31671a578813ab2da8b7ddcc3 Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Wed, 7 Oct 2026 08:41:58 +0800 Subject: [PATCH 1382/2126] net: fix NULL dereference in skb realloc fault injection devname filter When a device name filter is set in /sys/kernel/debug/fail_skb_realloc/devname, should_fail_net_realloc_skb() compares it with skb->dev->name without checking skb->dev first. skb_might_realloc() is called from pskb_may_pull(), pskb_trim() and pskb_trim_rcsum(), which also run on skbs that are not associated with a device. One example is a netlink broadcast to a listener with a socket filter attached, which goes through sk_filter_trim_cap(). With the filter set, such an skb makes the kernel oops: KASAN: null-ptr-deref in range [0x0000000000000118-0x000000000000011f] pc : strncmp+0x50/0xf0 lr : skb_might_realloc+0x58/0xa0 Call trace: strncmp+0x50/0xf0 (P) skb_might_realloc+0x58/0xa0 sk_filter_trim_cap+0x6a0/0x928 do_one_broadcast+0x35c/0xb20 netlink_broadcast_filtered+0x1a4/0x328 netlink_sendmsg+0x724/0xa58 The fault is meant to be injected on network interfaces, so skip skbs that are not associated with a device. Without a device name filter, such skbs are no longer reallocated either. Cc: stable+noautosel@kernel.org # bug in debug instrumentation Fixes: 12079a59ce52 ("net: Implement fault injection forcing skb reallocation") Suggested-by: Breno Leitao Signed-off-by: Haishuang Yan Reviewed-by: Breno Leitao Link: https://patch.msgid.link/20261007004158.1266795-1-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- net/core/skb_fault_injection.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/skb_fault_injection.c b/net/core/skb_fault_injection.c index 4235db6bdfad..63a397f76113 100644 --- a/net/core/skb_fault_injection.c +++ b/net/core/skb_fault_injection.c @@ -18,6 +18,9 @@ static bool should_fail_net_realloc_skb(struct sk_buff *skb) { struct net_device *net = skb->dev; + if (!net) + return false; + if (skb_realloc.filtered && strncmp(net->name, skb_realloc.devname, IFNAMSIZ)) /* device name filter set, but names do not match */ From 4077df74d71697ddb59ee2fc4c78d89bf8374702 Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Wed, 7 Oct 2026 09:47:31 +0800 Subject: [PATCH 1383/2126] selftests: net: big_tcp_tunnels: Fix the IPv6 route change On slow machines, do_test() raises initcwnd on the route into the tunnel with "ip route change". For IPv6 traffic this fails with: RTNETLINK answers: No such file or directory The IPv6 prefix route of the tunnel address has metric 256, while "ip -6 route change" without a metric looks for a route with the default metric 1024, so nothing is changed. The test still passes, but without the larger initcwnd it is meant to use. Pass the metric of the prefix route. Signed-off-by: Haishuang Yan Reviewed-by: Narcisa Vasile Link: https://patch.msgid.link/20261007014731.1277055-1-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/big_tcp_tunnels.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/big_tcp_tunnels.sh b/tools/testing/selftests/net/big_tcp_tunnels.sh index cc0875e52fb9..fb43fed824e3 100755 --- a/tools/testing/selftests/net/big_tcp_tunnels.sh +++ b/tools/testing/selftests/net/big_tcp_tunnels.sh @@ -145,7 +145,8 @@ do_test() { route change 192.168.2.0/24 dev tun0 initcwnd 100 else ip -netns "$CLIENT_NS" -6 \ - route change 2001:db8::2:0/112 dev tun0 initcwnd 100 + route change 2001:db8::2:0/112 dev tun0 initcwnd 100 \ + metric 256 fi else ip netns exec "$CLIENT_NS" \ From 056d046bf530d44bff5ce13a0addbc50c14ac95f Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Wed, 7 Oct 2026 09:56:49 +0200 Subject: [PATCH 1384/2126] bng_en: pad short frames before sampling nr_frags bnge_start_xmit() samples skb_shinfo(skb)->nr_frags into last_frag, and stores it in tx_buf->nr_frags, before calling eth_skb_pad(). If a nonlinear skb is shorter than ETH_ZLEN, __skb_pad() calls skb_linearize(), which pulls the frags into the linear part, releases the frag pages and sets nr_frags to zero. bnge_start_xmit() then uses the stale last_frag to fill TX_BD_CNT() and to walk skb_shinfo(skb)->frags[], DMA-mapping pages the skb no longer holds a reference on, and sending their content twice. Fix this by calling eth_skb_pad() before nr_frags is sampled. Found by Sashiko while reviewing the similar bnxt_en fix. Fixes: bd5ad9c052c8 ("bng_en: Add TX support") Link: https://lore.kernel.org/netdev/179134695789.434549.53526916334276884@kernel.org/ Signed-off-by: Eric Dumazet Reviewed-by: Vikas Gupta Link: https://patch.msgid.link/20261007075649.468033-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnge/bnge_txrx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_txrx.c b/drivers/net/ethernet/broadcom/bnge/bnge_txrx.c index 7d45e057f2e8..472b02cc43b3 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_txrx.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_txrx.c @@ -1490,6 +1490,9 @@ netdev_tx_t bnge_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_BUSY; } + if (eth_skb_pad(skb)) + goto tx_kick_pending; + last_frag = skb_shinfo(skb)->nr_frags; txbd = &txr->tx_desc_ring[TX_RING(bn, prod)][TX_IDX(prod)]; @@ -1513,9 +1516,6 @@ netdev_tx_t bnge_start_xmit(struct sk_buff *skb, struct net_device *dev) if (unlikely(skb->no_fcs)) lflags |= cpu_to_le32(TX_BD_FLAGS_NO_CRC); - if (eth_skb_pad(skb)) - goto tx_kick_pending; - len = skb_headlen(skb); mapping = dma_map_single(bd->dev, skb->data, len, DMA_TO_DEVICE); From 3f65f6ff8594214ddac427f925f60f2e6af1082a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 8 Oct 2026 14:59:14 +0200 Subject: [PATCH 1385/2126] wireguard: noise: remove unused variable This is a harmless artifact from early pre-release wireguard development. These days, static_private is read from a shared data structure under a read lock directly, and it doesn't need to be copied to the stack. So remove the unused variable. Signed-off-by: Jason A. Donenfeld Link: https://patch.msgid.link/20261008130124.724119-2-Jason@zx2c4.com Signed-off-by: Jakub Kicinski --- drivers/net/wireguard/noise.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/wireguard/noise.c b/drivers/net/wireguard/noise.c index 9c0a09bf6c95..63f41836ebd5 100644 --- a/drivers/net/wireguard/noise.c +++ b/drivers/net/wireguard/noise.c @@ -736,7 +736,6 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src, u8 chaining_key[NOISE_HASH_LEN]; u8 e[NOISE_PUBLIC_KEY_LEN]; u8 ephemeral_private[NOISE_PUBLIC_KEY_LEN]; - u8 static_private[NOISE_PUBLIC_KEY_LEN]; u8 preshared_key[NOISE_SYMMETRIC_KEY_LEN]; down_read(&wg->static_identity.lock); @@ -807,7 +806,6 @@ out: memzero_explicit(hash, NOISE_HASH_LEN); memzero_explicit(chaining_key, NOISE_HASH_LEN); memzero_explicit(ephemeral_private, NOISE_PUBLIC_KEY_LEN); - memzero_explicit(static_private, NOISE_PUBLIC_KEY_LEN); memzero_explicit(preshared_key, NOISE_SYMMETRIC_KEY_LEN); up_read(&wg->static_identity.lock); return ret_peer; From cece0b573deb5d102547835da720f60d7b7888cc Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 5 Oct 2026 00:06:15 +0800 Subject: [PATCH 1386/2126] net: dsa: motorcomm: Hoist type casting helper into chip.h Rename and move dsa_to_yt921x_priv() and yt921x_priv_to_device() to chip.h so all files use one definition. Signed-off-by: David Yang Link: https://patch.msgid.link/20261004160622.948037-2-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 127 +++++++++++++-------------- drivers/net/dsa/motorcomm/chip.h | 2 + drivers/net/dsa/motorcomm/leds.c | 7 +- drivers/net/dsa/motorcomm/mdio_bus.c | 10 +-- drivers/net/dsa/motorcomm/pcs-921x.c | 8 +- 5 files changed, 74 insertions(+), 80 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 3ff2de383157..2c0f53cb2b8e 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -171,9 +171,6 @@ struct yt921x_reg_mdio { /* TODO: SPI/I2C */ -#define to_yt921x_priv(_ds) container_of_const(_ds, struct yt921x_priv, ds) -#define to_device(priv) ((priv)->ds.dev) - static u32 ethaddr_hi4_to_u32(const unsigned char *addr) { return (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]; @@ -271,8 +268,8 @@ static const struct yt921x_reg_ops yt921x_reg_ops_mdio = { /* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */ static int yt921x_read_mib(struct yt921x_priv *priv, int port) { + struct device *dev = yt921x_priv_to_device(priv); struct yt921x_port *pp = &priv->ports[port]; - struct device *dev = to_device(priv); struct yt921x_mib *mib = &pp->mib; int res = 0; @@ -364,7 +361,7 @@ yt921x_dsa_get_strings(struct dsa_switch *ds, int port, u32 stringset, static void yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *mib = &pp->mib; size_t j; @@ -406,7 +403,7 @@ static void yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, struct ethtool_eth_mac_stats *mac_stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *mib = &pp->mib; @@ -442,7 +439,7 @@ static void yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, struct ethtool_eth_ctrl_stats *ctrl_stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *mib = &pp->mib; @@ -471,7 +468,7 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *mib = &pp->mib; @@ -507,7 +504,7 @@ static void yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, struct rtnl_link_stats64 *stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *mib = &pp->mib; @@ -543,7 +540,7 @@ static void yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, struct ethtool_pause_stats *pause_stats) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *mib = &pp->mib; @@ -598,7 +595,7 @@ yt921x_set_eee(struct yt921x_priv *priv, int port, struct ethtool_keee *e) static int yt921x_dsa_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_keee *e) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -622,7 +619,7 @@ yt921x_dsa_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) * maximum after reset */ - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct dsa_port *dp = dsa_to_port(ds, port); int frame_size; int res; @@ -697,7 +694,7 @@ yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst, { const int C = flags & YT921X_MARKER_PKT_MODE ? YT921X_TOKEN_PKT_C : YT921X_TOKEN_BYTE_C; - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); struct yt921x_marker m; u64 burst_est; u64 burst_sug; @@ -873,8 +870,8 @@ yt921x_meter_config(struct yt921x_priv *priv, unsigned int id, static void yt921x_dsa_port_policer_del(struct dsa_switch *ds, int port) { - struct yt921x_priv *priv = to_yt921x_priv(ds); - struct device *dev = to_device(priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); int res; mutex_lock(&priv->reg_lock); @@ -891,7 +888,7 @@ yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port, const struct flow_action_police *police, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_marker marker; u32 ctrl; int res; @@ -921,7 +918,7 @@ static int yt921x_dsa_port_setup_tc_tbf_port(struct dsa_switch *ds, int port, const struct tc_tbf_qopt_offload *qopt) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct netlink_ext_ack *extack = qopt->extack; u32 ctrls[2]; int res; @@ -1970,7 +1967,7 @@ static int yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -1985,7 +1982,7 @@ yt921x_dsa_cls_flower_add(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress) { struct netlink_ext_ack *extack = cls->common.extack; - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_acl_rule_ext ruleext; int res; @@ -2056,8 +2053,8 @@ static void yt921x_dsa_port_mirror_del(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror) { - struct yt921x_priv *priv = to_yt921x_priv(ds); - struct device *dev = to_device(priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); int res; mutex_lock(&priv->reg_lock); @@ -2074,7 +2071,7 @@ yt921x_dsa_port_mirror_add(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -2143,7 +2140,7 @@ static int yt921x_lag_set(struct yt921x_priv *priv, u8 index, u16 ports_mask) static int yt921x_dsa_port_lag_leave(struct dsa_switch *ds, int port, struct dsa_lag lag) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct dsa_port *dp; u32 ctrl; int res; @@ -2206,7 +2203,7 @@ yt921x_dsa_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag, struct netdev_lag_upper_info *info, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct dsa_port *dp; bool unique_lag; unsigned int i; @@ -2269,7 +2266,7 @@ yt921x_dsa_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag, static int yt921x_fdb_wait(struct yt921x_priv *priv, u32 *valp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); u32 val = YT921X_FDB_RESULT_DONE; int res; @@ -2338,7 +2335,7 @@ static int yt921x_fdb_read(struct yt921x_priv *priv, unsigned char *addr, u16 *vidp, u16 *ports_maskp, u16 *indexp, u8 *statusp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); u16 index; u32 data0; u32 data1; @@ -2629,7 +2626,7 @@ static int yt921x_dsa_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -2644,8 +2641,8 @@ yt921x_dsa_port_fdb_dump(struct dsa_switch *ds, int port, static void yt921x_dsa_port_fast_age(struct dsa_switch *ds, int port) { - struct yt921x_priv *priv = to_yt921x_priv(ds); - struct device *dev = to_device(priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); int res; mutex_lock(&priv->reg_lock); @@ -2660,7 +2657,7 @@ static void yt921x_dsa_port_fast_age(struct dsa_switch *ds, int port) static int yt921x_dsa_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 ctrl; int res; @@ -2678,7 +2675,7 @@ static int yt921x_dsa_port_fdb_del(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -2692,7 +2689,7 @@ static int yt921x_dsa_port_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -2707,7 +2704,7 @@ yt921x_dsa_port_mdb_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); const unsigned char *addr = mdb->addr; u16 vid = mdb->vid; int res; @@ -2724,7 +2721,7 @@ yt921x_dsa_port_mdb_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); const unsigned char *addr = mdb->addr; u16 vid = mdb->vid; int res; @@ -2889,7 +2886,7 @@ yt921x_dsa_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; if (dsa_is_cpu_port(ds, port)) @@ -2906,7 +2903,7 @@ static int yt921x_dsa_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u16 vid = vlan->vid; u16 pvid; int res; @@ -2940,7 +2937,7 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u16 vid = vlan->vid; u16 pvid; int res; @@ -3185,7 +3182,7 @@ yt921x_dsa_port_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; if (dsa_is_cpu_port(ds, port)) @@ -3202,8 +3199,8 @@ static void yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) { - struct yt921x_priv *priv = to_yt921x_priv(ds); - struct device *dev = to_device(priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); int res; if (dsa_is_cpu_port(ds, port)) @@ -3223,7 +3220,7 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, bool *tx_fwd_offload, struct netlink_ext_ack *extack) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u16 ports_mask; int res; @@ -3244,7 +3241,7 @@ static int yt921x_dsa_port_mst_state_set(struct dsa_switch *ds, int port, const struct switchdev_mst_state *st) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 mask; u32 ctrl; int res; @@ -3278,7 +3275,7 @@ static int yt921x_dsa_vlan_msti_set(struct dsa_switch *ds, struct dsa_bridge bridge, const struct switchdev_vlan_msti *msti) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 masks[2]; u32 ctrls[2]; int res; @@ -3304,9 +3301,9 @@ yt921x_dsa_vlan_msti_set(struct dsa_switch *ds, struct dsa_bridge bridge, static void yt921x_dsa_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); struct dsa_port *dp = dsa_to_port(ds, port); - struct device *dev = to_device(priv); bool learning; u32 mask; u32 ctrl; @@ -3356,7 +3353,7 @@ yt921x_dsa_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) static int __maybe_unused yt921x_dsa_port_get_default_prio(struct dsa_switch *ds, int port) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 val; int res; @@ -3373,7 +3370,7 @@ yt921x_dsa_port_get_default_prio(struct dsa_switch *ds, int port) static int __maybe_unused yt921x_dsa_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 mask; u32 ctrl; int res; @@ -3399,7 +3396,7 @@ static int __maybe_unused yt921x_dsa_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nselp) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u8 appprios[2][2] = {}; int nsel; u32 val; @@ -3433,8 +3430,8 @@ static int __maybe_unused yt921x_dsa_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel, int nsel) { - struct yt921x_priv *priv = to_yt921x_priv(ds); - struct device *dev = to_device(priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); u32 ctrl; int res; @@ -3574,9 +3571,9 @@ static int yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, phy_interface_t interface) { + struct device *dev = yt921x_priv_to_device(priv); const struct yt921x_info *info = priv->info; struct yt921x_port *pp = &priv->ports[port]; - struct device *dev = to_device(priv); u32 mask; int res; @@ -3628,7 +3625,7 @@ yt921x_phylink_mac_select_pcs(struct phylink_config *config, phy_interface_t interface) { struct dsa_port *dp = dsa_phylink_to_port(config); - struct yt921x_priv *priv = to_yt921x_priv(dp->ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); const struct yt921x_info *info = priv->info; int port = dp->index; @@ -3651,7 +3648,7 @@ yt921x_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, phy_interface_t interface) { struct dsa_port *dp = dsa_phylink_to_port(config); - struct yt921x_priv *priv = to_yt921x_priv(dp->ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); int port = dp->index; int res; @@ -3674,7 +3671,7 @@ yt921x_phylink_mac_link_up(struct phylink_config *config, bool tx_pause, bool rx_pause) { struct dsa_port *dp = dsa_phylink_to_port(config); - struct yt921x_priv *priv = to_yt921x_priv(dp->ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); int port = dp->index; int res; @@ -3695,7 +3692,7 @@ yt921x_phylink_mac_config(struct phylink_config *config, unsigned int mode, const struct phylink_link_state *state) { struct dsa_port *dp = dsa_phylink_to_port(config); - struct yt921x_priv *priv = to_yt921x_priv(dp->ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); int port = dp->index; int res; @@ -3712,7 +3709,7 @@ static void yt921x_dsa_phylink_get_caps(struct dsa_switch *ds, int port, struct phylink_config *config) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); const struct yt921x_info *info = priv->info; config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | @@ -3803,7 +3800,7 @@ yt921x_dsa_get_tag_protocol(struct dsa_switch *ds, int port, static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; mutex_lock(&priv->reg_lock); @@ -3817,7 +3814,7 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port) static int __maybe_unused yt921x_dsa_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 val; int res; @@ -3834,7 +3831,7 @@ yt921x_dsa_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) static int __maybe_unused yt921x_dsa_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u32 val; int res; @@ -3859,7 +3856,7 @@ yt921x_dsa_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio) static int __maybe_unused yt921x_dsa_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio) { - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); int res; if (prio >= YT921X_PRIO_NUM) @@ -3920,7 +3917,7 @@ static int yt921x_edata_read(struct yt921x_priv *priv, u8 addr, u8 *valp) static void yt921x_dsa_teardown(struct dsa_switch *ds) { #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) - struct yt921x_priv *priv = to_yt921x_priv(ds); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); yt921x_leds_remove(priv); #endif @@ -3928,7 +3925,7 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds) static int yt921x_chip_detect(struct yt921x_priv *priv) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); const struct yt921x_info *info; u8 extmode; u32 chipid; @@ -3995,7 +3992,7 @@ static int yt921x_chip_detect(struct yt921x_priv *priv) static int yt921x_chip_reset(struct yt921x_priv *priv) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); u16 eth_p_tag; u32 val; int res; @@ -4243,8 +4240,8 @@ static int yt921x_chip_setup(struct yt921x_priv *priv) static int yt921x_dsa_setup(struct dsa_switch *ds) { - struct yt921x_priv *priv = to_yt921x_priv(ds); - struct device *dev = to_device(priv); + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); struct device_node *np = dev->of_node; struct device_node *child; unsigned long mask; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 28e4f26f9cc4..9c34fb704bf8 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -984,8 +984,10 @@ struct yt921x_priv { struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM]; }; +#define dsa_to_yt921x_priv(_ds) container_of_const(_ds, struct yt921x_priv, ds) #define yt921x_port_to_priv(pp) \ container_of_const((pp), struct yt921x_priv, ports[(pp)->index]) +#define yt921x_priv_to_device(priv) ((priv)->ds.dev) static inline int ethtool_speed_to_yt921x(int speed) { diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c index c97b560299d6..08fbe86c3334 100644 --- a/drivers/net/dsa/motorcomm/leds.c +++ b/drivers/net/dsa/motorcomm/leds.c @@ -12,7 +12,6 @@ #define to_yt921x_led(led_cdev) \ container_of_const((led_cdev), struct yt921x_led, cdev) #define to_yt921x_port(led) ((led)->port) -#define to_device(priv) ((priv)->ds.dev) static u32 yt921x_led_regaddr(struct yt921x_priv *priv, int port, int group) { @@ -413,8 +412,8 @@ static int yt921x_led_setup(struct yt921x_priv *priv, int port, struct fwnode_handle *fwnode) { + struct device *dev = yt921x_priv_to_device(priv); struct yt921x_port *pp = &priv->ports[port]; - struct device *dev = to_device(priv); struct led_init_data init_data; struct led_classdev *led_cdev; char name[LED_MAX_NAME_SIZE]; @@ -583,8 +582,8 @@ err: static void yt921x_leds_remove_port(struct yt921x_priv *priv, int port) { + struct device *dev = yt921x_priv_to_device(priv); struct yt921x_port *pp = &priv->ports[port]; - struct device *dev = to_device(priv); for (int group = 0; group < YT921X_LED_GROUP_NUM; group++) { struct yt921x_led *led = pp->leds[group]; @@ -602,7 +601,7 @@ static void yt921x_leds_remove_port(struct yt921x_priv *priv, int port) static int yt921x_leds_setup_port(struct yt921x_priv *priv, int port) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); struct dsa_switch *ds = &priv->ds; struct device_node *leds_np; struct dsa_port *dp; diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c index 1a3f3cc68275..dd6c52f37bbf 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.c +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -9,8 +9,6 @@ #include "mdio_bus.h" #include "smi.h" -#define to_device(priv) ((priv)->ds.dev) - static int yt921x_intif_wait(struct yt921x_priv *priv) { u32 val = 0; @@ -21,7 +19,7 @@ static int yt921x_intif_wait(struct yt921x_priv *priv) int yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); u32 mask; u32 ctrl; u32 val; @@ -145,7 +143,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data) int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); struct mii_bus *mbus; int res; @@ -181,7 +179,7 @@ static int yt921x_extif_wait(struct yt921x_priv *priv) static int yt921x_extif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); u32 mask; u32 ctrl; u32 val; @@ -275,7 +273,7 @@ yt921x_mbus_ext_write(struct mii_bus *mbus, int port, int reg, u16 data) int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp) { - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); struct mii_bus *mbus; int res; diff --git a/drivers/net/dsa/motorcomm/pcs-921x.c b/drivers/net/dsa/motorcomm/pcs-921x.c index 47467d803e13..e942b61d8eb2 100644 --- a/drivers/net/dsa/motorcomm/pcs-921x.c +++ b/drivers/net/dsa/motorcomm/pcs-921x.c @@ -8,8 +8,6 @@ #include "pcs.h" #include "smi.h" -#define to_device(priv) ((priv)->ds.dev) - static int yt921x_serdes_config(struct yt921x_priv *priv, int port, unsigned int neg_mode, phy_interface_t interface, @@ -116,7 +114,7 @@ yt921x_phylink_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, { struct yt921x_port *pp = pcs_to_yt921x_port(pcs); struct yt921x_priv *priv = yt921x_port_to_priv(pp); - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); int port = pp->index; u16 bmsr; u16 lpa; @@ -155,7 +153,7 @@ static void yt921x_phylink_pcs_an_restart(struct phylink_pcs *pcs) { struct yt921x_port *pp = pcs_to_yt921x_port(pcs); struct yt921x_priv *priv = yt921x_port_to_priv(pp); - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); int port = pp->index; u16 val; int res; @@ -181,7 +179,7 @@ static void yt921x_phylink_pcs_disable(struct phylink_pcs *pcs) { struct yt921x_port *pp = pcs_to_yt921x_port(pcs); struct yt921x_priv *priv = yt921x_port_to_priv(pp); - struct device *dev = to_device(priv); + struct device *dev = yt921x_priv_to_device(priv); int port = pp->index; int res; From 05a720732724b24d5779eb5ac335b2901f91ffea Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 5 Oct 2026 00:06:16 +0800 Subject: [PATCH 1387/2126] net: dsa: motorcomm: Rename MIB stuff Rename them in preparation of major MIB refactor. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261004160622.948037-3-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 34 ++++++++++++++++---------------- drivers/net/dsa/motorcomm/chip.h | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 2c0f53cb2b8e..690ee0eb5192 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -40,7 +40,7 @@ struct yt921x_mib_desc { #define MIB_DESC(_size, _offset, _name) \ {_size, _offset, _name} -/* Must agree with yt921x_mib +/* Must agree with yt921x_mib_stats * * Unstructured fields (name != NULL) will appear in get_ethtool_stats(), * structured go to their *_stats() methods, but we need their sizes and offsets @@ -266,11 +266,11 @@ static const struct yt921x_reg_ops yt921x_reg_ops_mdio = { /* TODO: SPI/I2C */ /* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */ -static int yt921x_read_mib(struct yt921x_priv *priv, int port) +static int yt921x_mib_read(struct yt921x_priv *priv, int port) { struct device *dev = yt921x_priv_to_device(priv); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; int res = 0; /* Reading of yt921x_port::mib is not protected by a lock and it's vain @@ -325,7 +325,7 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port) return res; } -static void yt921x_poll_mib(struct work_struct *work) +static void yt921x_mib_poll(struct work_struct *work) { struct yt921x_port *pp = container_of_const(work, struct yt921x_port, mib_read.work); @@ -335,7 +335,7 @@ static void yt921x_poll_mib(struct work_struct *work) int res; mutex_lock(&priv->reg_lock); - res = yt921x_read_mib(priv, port); + res = yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); if (res) delay *= 4; @@ -363,11 +363,11 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; size_t j; mutex_lock(&priv->reg_lock); - yt921x_read_mib(priv, port); + yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); j = 0; @@ -405,10 +405,10 @@ yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; mutex_lock(&priv->reg_lock); - yt921x_read_mib(priv, port); + yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); mac_stats->FramesTransmittedOK = pp->tx_frames; @@ -441,10 +441,10 @@ yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; mutex_lock(&priv->reg_lock); - yt921x_read_mib(priv, port); + yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); ctrl_stats->MACControlFramesTransmitted = mib->tx_pause; @@ -470,10 +470,10 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; mutex_lock(&priv->reg_lock); - yt921x_read_mib(priv, port); + yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); *ranges = yt921x_rmon_ranges; @@ -506,7 +506,7 @@ yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; stats->rx_length_errors = mib->rx_undersize_errors + mib->rx_fragment_errors; @@ -542,10 +542,10 @@ yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *mib = &pp->mib; + struct yt921x_mib_stats *mib = &pp->mib; mutex_lock(&priv->reg_lock); - yt921x_read_mib(priv, port); + yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); pause_stats->tx_pause_frames = mib->tx_pause; @@ -4464,7 +4464,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) struct yt921x_port *pp = &priv->ports[i]; pp->index = i; - INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib); + INIT_DELAYED_WORK(&pp->mib_read, yt921x_mib_poll); } ds = &priv->ds; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 9c34fb704bf8..c1b24b6d1d97 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -833,7 +833,7 @@ enum yt921x_fdb_entry_status { #define YT921X_NAME "yt921x" -struct yt921x_mib { +struct yt921x_mib_stats { u64 rx_broadcast; u64 rx_pause; u64 rx_multicast; @@ -918,7 +918,7 @@ struct yt921x_port { bool isolated:1; struct delayed_work mib_read; - struct yt921x_mib mib; + struct yt921x_mib_stats mib; u64 rx_frames; u64 tx_frames; From a219b5ea8bb26037357d8ccd04d1b386c15edbfb Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 5 Oct 2026 00:06:17 +0800 Subject: [PATCH 1388/2126] net: dsa: motorcomm: Split MIB buffers With MIB improvement introduced later, struct yt921x_priv will be over 20 KiB which is not very good for a single kmalloc(). Dynamically allocate the MIB structures to reduce the size of struct yt921x_priv (and adjust polling work lifecycle), and do not waste memory on dummy ports. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261004160622.948037-4-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 124 ++++++++++++++++++++++++------- drivers/net/dsa/motorcomm/chip.h | 20 +++-- 2 files changed, 112 insertions(+), 32 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 690ee0eb5192..8341d4d1c784 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -270,10 +270,13 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) { struct device *dev = yt921x_priv_to_device(priv); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; int res = 0; - /* Reading of yt921x_port::mib is not protected by a lock and it's vain + mib = &pm->stats; + + /* Reading of yt921x_mib_stats is not protected by a lock and it's vain * to keep its consistency, since we have to read registers one by one * and there is no way to make a snapshot of MIB stats. * @@ -310,11 +313,11 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) WRITE_ONCE(*valp, val); } - pp->rx_frames = mib->rx_64byte + mib->rx_65_127byte + + pm->rx_frames = mib->rx_64byte + mib->rx_65_127byte + mib->rx_128_255byte + mib->rx_256_511byte + mib->rx_512_1023byte + mib->rx_1024_1518byte + mib->rx_jumbo; - pp->tx_frames = mib->tx_64byte + mib->tx_65_127byte + + pm->tx_frames = mib->tx_64byte + mib->tx_65_127byte + mib->tx_128_255byte + mib->tx_256_511byte + mib->tx_512_1023byte + mib->tx_1024_1518byte + mib->tx_jumbo; @@ -327,8 +330,9 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) static void yt921x_mib_poll(struct work_struct *work) { - struct yt921x_port *pp = container_of_const(work, struct yt921x_port, - mib_read.work); + struct yt921x_mib *pm = container_of_const(work, struct yt921x_mib, + work.work); + struct yt921x_port *pp = pm->port; unsigned long delay = YT921X_STATS_INTERVAL_JIFFIES; struct yt921x_priv *priv = yt921x_port_to_priv(pp); int port = pp->index; @@ -340,7 +344,7 @@ static void yt921x_mib_poll(struct work_struct *work) if (res) delay *= 4; - schedule_delayed_work(&pp->mib_read, delay); + schedule_delayed_work(&pm->work, delay); } static void @@ -363,9 +367,14 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; size_t j; + if (!pm) + return; + mib = &pm->stats; + mutex_lock(&priv->reg_lock); yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); @@ -405,16 +414,21 @@ yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; mutex_lock(&priv->reg_lock); yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); - mac_stats->FramesTransmittedOK = pp->tx_frames; + mac_stats->FramesTransmittedOK = pm->tx_frames; mac_stats->SingleCollisionFrames = mib->tx_single_collisions; mac_stats->MultipleCollisionFrames = mib->tx_multiple_collisions; - mac_stats->FramesReceivedOK = pp->rx_frames; + mac_stats->FramesReceivedOK = pm->rx_frames; mac_stats->FrameCheckSequenceErrors = mib->rx_crc_errors; mac_stats->AlignmentErrors = mib->rx_alignment_errors; mac_stats->OctetsTransmittedOK = mib->tx_good_bytes; @@ -441,7 +455,12 @@ yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; mutex_lock(&priv->reg_lock); yt921x_mib_read(priv, port); @@ -470,7 +489,12 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; mutex_lock(&priv->reg_lock); yt921x_mib_read(priv, port); @@ -506,7 +530,12 @@ yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; stats->rx_length_errors = mib->rx_undersize_errors + mib->rx_fragment_errors; @@ -522,8 +551,8 @@ yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, /* stats->tx_heartbeat_errors */ stats->tx_window_errors = mib->tx_late_collisions; - stats->rx_packets = pp->rx_frames; - stats->tx_packets = pp->tx_frames; + stats->rx_packets = pm->rx_frames; + stats->tx_packets = pm->tx_frames; stats->rx_bytes = mib->rx_good_bytes - ETH_FCS_LEN * stats->rx_packets; stats->tx_bytes = mib->tx_good_bytes - ETH_FCS_LEN * stats->tx_packets; stats->rx_errors = stats->rx_length_errors + stats->rx_over_errors + @@ -542,7 +571,12 @@ yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib_stats *mib = &pp->mib; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; mutex_lock(&priv->reg_lock); yt921x_mib_read(priv, port); @@ -3649,11 +3683,14 @@ yt921x_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, { struct dsa_port *dp = dsa_phylink_to_port(config); struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); + struct yt921x_mib *pm; int port = dp->index; int res; /* No need to sync; port control block is hold until device remove */ - cancel_delayed_work(&priv->ports[port].mib_read); + pm = priv->ports[port].mib; + if (pm) + cancel_delayed_work(&pm->work); mutex_lock(&priv->reg_lock); res = yt921x_port_down(priv, port); @@ -3672,6 +3709,7 @@ yt921x_phylink_mac_link_up(struct phylink_config *config, { struct dsa_port *dp = dsa_phylink_to_port(config); struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); + struct yt921x_mib *pm; int port = dp->index; int res; @@ -3684,7 +3722,9 @@ yt921x_phylink_mac_link_up(struct phylink_config *config, dev_err(dp->ds->dev, "Failed to %s port %d: %i\n", "bring up", port, res); - schedule_delayed_work(&priv->ports[port].mib_read, 0); + pm = priv->ports[port].mib; + if (pm) + schedule_delayed_work(&pm->work, 0); } static void @@ -3798,16 +3838,52 @@ yt921x_dsa_get_tag_protocol(struct dsa_switch *ds, int port, return DSA_TAG_PROTO_YT921X; } +static void yt921x_dsa_port_teardown(struct dsa_switch *ds, int port) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + + /* get_stats64() might not be synchronized with port_teardown(), hold + * the MIB block till the device teardown + */ + if (pm) + disable_delayed_work_sync(&pm->work); +} + static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port) { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + const struct yt921x_info *info = priv->info; + struct device *dev = yt921x_priv_to_device(priv); + struct yt921x_mib *pm = pp->mib; int res; + if (!pm && (BIT(port) & yt921x_info_ports_mask(info))) { + pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL); + if (!pm) + return -ENOMEM; + pp->mib = pm; + + pm->port = pp; + INIT_DELAYED_WORK(&pm->work, yt921x_mib_poll); + /* Start disabled, so that the enable below always pairs with + * either this disable or the one from a previous teardown + */ + disable_delayed_work_sync(&pm->work); + } + mutex_lock(&priv->reg_lock); res = yt921x_port_setup(priv, port); mutex_unlock(&priv->reg_lock); + if (res) + return res; - return res; + if (pm) + enable_delayed_work(&pm->work); + + return 0; } /* Not "port" - DSCP mapping is global */ @@ -4382,6 +4458,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { /* port */ .get_tag_protocol = yt921x_dsa_get_tag_protocol, .phylink_get_caps = yt921x_dsa_phylink_get_caps, + .port_teardown = yt921x_dsa_port_teardown, .port_setup = yt921x_dsa_port_setup, #if IS_ENABLED(CONFIG_DCB) /* dscp */ @@ -4411,12 +4488,6 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev) if (!priv) return; - for (size_t i = ARRAY_SIZE(priv->ports); i-- > 0; ) { - struct yt921x_port *pp = &priv->ports[i]; - - disable_delayed_work_sync(&pp->mib_read); - } - dsa_unregister_switch(&priv->ds); for (unsigned int i = 0; i < ARRAY_SIZE(priv->acl_blks); i++) { @@ -4464,7 +4535,6 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) struct yt921x_port *pp = &priv->ports[i]; pp->index = i; - INIT_DELAYED_WORK(&pp->mib_read, yt921x_mib_poll); } ds = &priv->ds; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index c1b24b6d1d97..d1764b635630 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -885,6 +885,15 @@ struct yt921x_mib_stats { u64 tx_oam; }; +struct yt921x_mib { + struct yt921x_port *port; + + struct delayed_work work; + struct yt921x_mib_stats stats; + u64 rx_frames; + u64 tx_frames; +}; + struct yt921x_acl_entry { u32 key[2]; u32 mask[2]; @@ -917,11 +926,6 @@ struct yt921x_port { /* BR_ISOLATED */ bool isolated:1; - struct delayed_work mib_read; - struct yt921x_mib_stats mib; - u64 rx_frames; - u64 tx_frames; - #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) unsigned char led_duty; unsigned short led_cycle; @@ -932,6 +936,7 @@ struct yt921x_port { struct yt921x_led *leds[YT921X_LED_GROUP_NUM]; #endif + struct yt921x_mib *mib; struct phylink_pcs pcs; }; @@ -955,6 +960,11 @@ struct yt921x_info { u16 serdes_mask; }; +static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info) +{ + return info->internal_mask | info->xmii_mask | info->serdes_mask; +} + struct yt921x_priv { struct dsa_switch ds; From 25265e7ccdb51ba5a92c463fe5f112b253f9513d Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 5 Oct 2026 00:06:18 +0800 Subject: [PATCH 1389/2126] net: dsa: motorcomm: Split MIB module yt922x is going to use a different MIB scheme, split it to reduce the length of chip.c. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261004160622.948037-5-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 397 +--------------------------- drivers/net/dsa/motorcomm/chip.h | 124 --------- drivers/net/dsa/motorcomm/mib.c | 404 +++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/mib.h | 159 ++++++++++++ 5 files changed, 565 insertions(+), 520 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/mib.c create mode 100644 drivers/net/dsa/motorcomm/mib.h diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index 1d2c1b3064c4..9c1e3d538d21 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -3,5 +3,6 @@ obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += mdio_bus.o +yt921x-objs += mib.o yt921x-objs += pcs-921x.o yt921x-objs += smi.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 8341d4d1c784..9e3be08b3465 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -28,76 +28,10 @@ #include "chip.h" #include "leds.h" #include "mdio_bus.h" +#include "mib.h" #include "pcs.h" #include "smi.h" -struct yt921x_mib_desc { - unsigned int size; - unsigned int offset; - const char *name; -}; - -#define MIB_DESC(_size, _offset, _name) \ - {_size, _offset, _name} - -/* Must agree with yt921x_mib_stats - * - * Unstructured fields (name != NULL) will appear in get_ethtool_stats(), - * structured go to their *_stats() methods, but we need their sizes and offsets - * to perform 32bit MIB overflow wraparound. - */ -static const struct yt921x_mib_desc yt921x_mib_descs[] = { - MIB_DESC(1, YT921X_MIB_DATA_RX_BROADCAST, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_PAUSE, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_MULTICAST, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_CRC_ERR, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_RX_ALIGN_ERR, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_UNDERSIZE_ERR, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_FRAG_ERR, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_64, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_65_TO_127, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_128_TO_255, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_256_TO_511, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_512_TO_1023, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_1024_TO_1518, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_1519_TO_MAX, NULL), - MIB_DESC(2, YT921X_MIB_DATA_RX_GOOD_BYTES, NULL), - - MIB_DESC(2, YT921X_MIB_DATA_RX_BAD_BYTES, "RxBadBytes"), - MIB_DESC(1, YT921X_MIB_DATA_RX_OVERSIZE_ERR, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_RX_DROPPED, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_BROADCAST, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PAUSE, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_MULTICAST, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_TX_UNDERSIZE_ERR, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_64, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_65_TO_127, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_128_TO_255, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_256_TO_511, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_512_TO_1023, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_1024_TO_1518, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_1519_TO_MAX, NULL), - - MIB_DESC(2, YT921X_MIB_DATA_TX_GOOD_BYTES, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_COLLISION, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_TX_EXCESSIVE_COLLISION, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_MULTIPLE_COLLISION, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_SINGLE_COLLISION, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_PKT, NULL), - - MIB_DESC(1, YT921X_MIB_DATA_TX_DEFERRED, NULL), - MIB_DESC(1, YT921X_MIB_DATA_TX_LATE_COLLISION, NULL), - MIB_DESC(1, YT921X_MIB_DATA_RX_OAM, "RxOAM"), - MIB_DESC(1, YT921X_MIB_DATA_TX_OAM, "TxOAM"), -}; - static const struct yt921x_info yt921x_infos[] = { { "YT9215SC", YT9215_MAJOR, 1, 0, @@ -146,14 +80,6 @@ static const struct yt921x_info yt921x_infos[] = { #define YT921X_VID_UNWARE 4095 -/* The interval should be small enough to avoid overflow of 32bit MIBs. - * - * Until we can read MIBs from stats64 call directly (i.e. sleep - * there), we have to poll stats more frequently then it is actually needed. - * For overflow protection, normally, 100 sec interval should have been OK. - */ -#define YT921X_STATS_INTERVAL_JIFFIES (3 * HZ) - struct yt921x_reg_mdio { struct mii_bus *bus; int addr; @@ -265,327 +191,6 @@ static const struct yt921x_reg_ops yt921x_reg_ops_mdio = { /* TODO: SPI/I2C */ -/* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */ -static int yt921x_mib_read(struct yt921x_priv *priv, int port) -{ - struct device *dev = yt921x_priv_to_device(priv); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - int res = 0; - - mib = &pm->stats; - - /* Reading of yt921x_mib_stats is not protected by a lock and it's vain - * to keep its consistency, since we have to read registers one by one - * and there is no way to make a snapshot of MIB stats. - * - * Writing (by this function only) is and should be protected by - * reg_lock. - */ - - for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { - const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; - u32 reg = YT921X_MIBn_DATA0(port) + desc->offset; - u64 *valp = &((u64 *)mib)[i]; - u32 val0; - u64 val; - - res = yt921x_reg_read(priv, reg, &val0); - if (res) - break; - - if (desc->size <= 1) { - u64 old_val = *valp; - - val = (old_val & ~(u64)U32_MAX) | val0; - if (val < old_val) - val += 1ull << 32; - } else { - u32 val1; - - res = yt921x_reg_read(priv, reg + 4, &val1); - if (res) - break; - val = ((u64)val1 << 32) | val0; - } - - WRITE_ONCE(*valp, val); - } - - pm->rx_frames = mib->rx_64byte + mib->rx_65_127byte + - mib->rx_128_255byte + mib->rx_256_511byte + - mib->rx_512_1023byte + mib->rx_1024_1518byte + - mib->rx_jumbo; - pm->tx_frames = mib->tx_64byte + mib->tx_65_127byte + - mib->tx_128_255byte + mib->tx_256_511byte + - mib->tx_512_1023byte + mib->tx_1024_1518byte + - mib->tx_jumbo; - - if (res) - dev_err(dev, "Failed to %s port %d: %i\n", "read stats for", - port, res); - return res; -} - -static void yt921x_mib_poll(struct work_struct *work) -{ - struct yt921x_mib *pm = container_of_const(work, struct yt921x_mib, - work.work); - struct yt921x_port *pp = pm->port; - unsigned long delay = YT921X_STATS_INTERVAL_JIFFIES; - struct yt921x_priv *priv = yt921x_port_to_priv(pp); - int port = pp->index; - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); - if (res) - delay *= 4; - - schedule_delayed_work(&pm->work, delay); -} - -static void -yt921x_dsa_get_strings(struct dsa_switch *ds, int port, u32 stringset, - uint8_t *data) -{ - if (stringset != ETH_SS_STATS) - return; - - for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { - const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; - - if (desc->name) - ethtool_puts(&data, desc->name); - } -} - -static void -yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - size_t j; - - if (!pm) - return; - mib = &pm->stats; - - mutex_lock(&priv->reg_lock); - yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); - - j = 0; - for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { - const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; - - if (!desc->name) - continue; - - data[j] = ((u64 *)mib)[i]; - j++; - } -} - -static int yt921x_dsa_get_sset_count(struct dsa_switch *ds, int port, int sset) -{ - int cnt = 0; - - if (sset != ETH_SS_STATS) - return 0; - - for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { - const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; - - if (desc->name) - cnt++; - } - - return cnt; -} - -static void -yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, - struct ethtool_eth_mac_stats *mac_stats) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - - if (!pm) - return; - mib = &pm->stats; - - mutex_lock(&priv->reg_lock); - yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); - - mac_stats->FramesTransmittedOK = pm->tx_frames; - mac_stats->SingleCollisionFrames = mib->tx_single_collisions; - mac_stats->MultipleCollisionFrames = mib->tx_multiple_collisions; - mac_stats->FramesReceivedOK = pm->rx_frames; - mac_stats->FrameCheckSequenceErrors = mib->rx_crc_errors; - mac_stats->AlignmentErrors = mib->rx_alignment_errors; - mac_stats->OctetsTransmittedOK = mib->tx_good_bytes; - mac_stats->FramesWithDeferredXmissions = mib->tx_deferred; - mac_stats->LateCollisions = mib->tx_late_collisions; - mac_stats->FramesAbortedDueToXSColls = mib->tx_aborted_errors; - /* mac_stats->FramesLostDueToIntMACXmitError */ - /* mac_stats->CarrierSenseErrors */ - mac_stats->OctetsReceivedOK = mib->rx_good_bytes; - /* mac_stats->FramesLostDueToIntMACRcvError */ - mac_stats->MulticastFramesXmittedOK = mib->tx_multicast; - mac_stats->BroadcastFramesXmittedOK = mib->tx_broadcast; - /* mac_stats->FramesWithExcessiveDeferral */ - mac_stats->MulticastFramesReceivedOK = mib->rx_multicast; - mac_stats->BroadcastFramesReceivedOK = mib->rx_broadcast; - /* mac_stats->InRangeLengthErrors */ - /* mac_stats->OutOfRangeLengthField */ - mac_stats->FrameTooLongErrors = mib->rx_oversize_errors; -} - -static void -yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, - struct ethtool_eth_ctrl_stats *ctrl_stats) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - - if (!pm) - return; - mib = &pm->stats; - - mutex_lock(&priv->reg_lock); - yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); - - ctrl_stats->MACControlFramesTransmitted = mib->tx_pause; - ctrl_stats->MACControlFramesReceived = mib->rx_pause; - /* ctrl_stats->UnsupportedOpcodesReceived */ -} - -static const struct ethtool_rmon_hist_range yt921x_rmon_ranges[] = { - { 0, 64 }, - { 65, 127 }, - { 128, 255 }, - { 256, 511 }, - { 512, 1023 }, - { 1024, 1518 }, - { 1519, YT921X_FRAME_SIZE_MAX }, - {} -}; - -static void -yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, - struct ethtool_rmon_stats *rmon_stats, - const struct ethtool_rmon_hist_range **ranges) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - - if (!pm) - return; - mib = &pm->stats; - - mutex_lock(&priv->reg_lock); - yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); - - *ranges = yt921x_rmon_ranges; - - rmon_stats->undersize_pkts = mib->rx_undersize_errors; - rmon_stats->oversize_pkts = mib->rx_oversize_errors; - rmon_stats->fragments = mib->rx_alignment_errors; - /* rmon_stats->jabbers */ - - rmon_stats->hist[0] = mib->rx_64byte; - rmon_stats->hist[1] = mib->rx_65_127byte; - rmon_stats->hist[2] = mib->rx_128_255byte; - rmon_stats->hist[3] = mib->rx_256_511byte; - rmon_stats->hist[4] = mib->rx_512_1023byte; - rmon_stats->hist[5] = mib->rx_1024_1518byte; - rmon_stats->hist[6] = mib->rx_jumbo; - - rmon_stats->hist_tx[0] = mib->tx_64byte; - rmon_stats->hist_tx[1] = mib->tx_65_127byte; - rmon_stats->hist_tx[2] = mib->tx_128_255byte; - rmon_stats->hist_tx[3] = mib->tx_256_511byte; - rmon_stats->hist_tx[4] = mib->tx_512_1023byte; - rmon_stats->hist_tx[5] = mib->tx_1024_1518byte; - rmon_stats->hist_tx[6] = mib->tx_jumbo; -} - -static void -yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, - struct rtnl_link_stats64 *stats) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - - if (!pm) - return; - mib = &pm->stats; - - stats->rx_length_errors = mib->rx_undersize_errors + - mib->rx_fragment_errors; - stats->rx_over_errors = mib->rx_oversize_errors; - stats->rx_crc_errors = mib->rx_crc_errors; - stats->rx_frame_errors = mib->rx_alignment_errors; - /* stats->rx_fifo_errors */ - /* stats->rx_missed_errors */ - - stats->tx_aborted_errors = mib->tx_aborted_errors; - /* stats->tx_carrier_errors */ - stats->tx_fifo_errors = mib->tx_undersize_errors; - /* stats->tx_heartbeat_errors */ - stats->tx_window_errors = mib->tx_late_collisions; - - stats->rx_packets = pm->rx_frames; - stats->tx_packets = pm->tx_frames; - stats->rx_bytes = mib->rx_good_bytes - ETH_FCS_LEN * stats->rx_packets; - stats->tx_bytes = mib->tx_good_bytes - ETH_FCS_LEN * stats->tx_packets; - stats->rx_errors = stats->rx_length_errors + stats->rx_over_errors + - stats->rx_crc_errors + stats->rx_frame_errors; - stats->tx_errors = stats->tx_aborted_errors + stats->tx_fifo_errors + - stats->tx_window_errors; - stats->rx_dropped = mib->rx_dropped; - /* stats->tx_dropped */ - stats->multicast = mib->rx_multicast; - stats->collisions = mib->tx_collisions; -} - -static void -yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, - struct ethtool_pause_stats *pause_stats) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_port *pp = &priv->ports[port]; - struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; - - if (!pm) - return; - mib = &pm->stats; - - mutex_lock(&priv->reg_lock); - yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); - - pause_stats->tx_pause_frames = mib->tx_pause; - pause_stats->rx_pause_frames = mib->rx_pause; -} - static int yt921x_set_eee(struct yt921x_priv *priv, int port, struct ethtool_keee *e) { diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index d1764b635630..25ff77054de3 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -163,69 +163,6 @@ enum yt921x_speed { #define YT921X_EEE_CTRL 0xb0000 #define YT921X_EEE_CTRL_ENn(port) BIT(port) -#define YT921X_MIB_CTRL 0xc0004 -#define YT921X_MIB_CTRL_CLEAN BIT(30) -#define YT921X_MIB_CTRL_PORT_M GENMASK(6, 3) -#define YT921X_MIB_CTRL_PORT(x) FIELD_PREP(YT921X_MIB_CTRL_PORT_M, (x)) -#define YT921X_MIB_CTRL_ONE_PORT BIT(1) -#define YT921X_MIB_CTRL_ALL_PORT BIT(0) -#define YT921X_MIBn_DATA0(port) (0xc0100 + 0x100 * (port)) -#define YT921X_MIBn_DATAm(port, x) (YT921X_MIBn_DATA0(port) + 4 * (x)) -#define YT921X_MIB_DATA_RX_BROADCAST 0x00 -#define YT921X_MIB_DATA_RX_PAUSE 0x04 -#define YT921X_MIB_DATA_RX_MULTICAST 0x08 -#define YT921X_MIB_DATA_RX_CRC_ERR 0x0c - -#define YT921X_MIB_DATA_RX_ALIGN_ERR 0x10 -#define YT921X_MIB_DATA_RX_UNDERSIZE_ERR 0x14 -#define YT921X_MIB_DATA_RX_FRAG_ERR 0x18 -#define YT921X_MIB_DATA_RX_PKT_SZ_64 0x1c - -#define YT921X_MIB_DATA_RX_PKT_SZ_65_TO_127 0x20 -#define YT921X_MIB_DATA_RX_PKT_SZ_128_TO_255 0x24 -#define YT921X_MIB_DATA_RX_PKT_SZ_256_TO_511 0x28 -#define YT921X_MIB_DATA_RX_PKT_SZ_512_TO_1023 0x2c - -#define YT921X_MIB_DATA_RX_PKT_SZ_1024_TO_1518 0x30 -#define YT921X_MIB_DATA_RX_PKT_SZ_1519_TO_MAX 0x34 -/* 0x38: unused */ -#define YT921X_MIB_DATA_RX_GOOD_BYTES 0x3c - -/* 0x40: 64 bytes */ -#define YT921X_MIB_DATA_RX_BAD_BYTES 0x44 -/* 0x48: 64 bytes */ -#define YT921X_MIB_DATA_RX_OVERSIZE_ERR 0x4c - -#define YT921X_MIB_DATA_RX_DROPPED 0x50 -#define YT921X_MIB_DATA_TX_BROADCAST 0x54 -#define YT921X_MIB_DATA_TX_PAUSE 0x58 -#define YT921X_MIB_DATA_TX_MULTICAST 0x5c - -#define YT921X_MIB_DATA_TX_UNDERSIZE_ERR 0x60 -#define YT921X_MIB_DATA_TX_PKT_SZ_64 0x64 -#define YT921X_MIB_DATA_TX_PKT_SZ_65_TO_127 0x68 -#define YT921X_MIB_DATA_TX_PKT_SZ_128_TO_255 0x6c - -#define YT921X_MIB_DATA_TX_PKT_SZ_256_TO_511 0x70 -#define YT921X_MIB_DATA_TX_PKT_SZ_512_TO_1023 0x74 -#define YT921X_MIB_DATA_TX_PKT_SZ_1024_TO_1518 0x78 -#define YT921X_MIB_DATA_TX_PKT_SZ_1519_TO_MAX 0x7c - -/* 0x80: unused */ -#define YT921X_MIB_DATA_TX_GOOD_BYTES 0x84 -/* 0x88: 64 bytes */ -#define YT921X_MIB_DATA_TX_COLLISION 0x8c - -#define YT921X_MIB_DATA_TX_EXCESSIVE_COLLISION 0x90 -#define YT921X_MIB_DATA_TX_MULTIPLE_COLLISION 0x94 -#define YT921X_MIB_DATA_TX_SINGLE_COLLISION 0x98 -#define YT921X_MIB_DATA_TX_PKT 0x9c - -#define YT921X_MIB_DATA_TX_DEFERRED 0xa0 -#define YT921X_MIB_DATA_TX_LATE_COLLISION 0xa4 -#define YT921X_MIB_DATA_RX_OAM 0xa8 -#define YT921X_MIB_DATA_TX_OAM 0xac - #define YT921X_EDATA_CTRL 0xe0000 #define YT921X_EDATA_CTRL_ADDR_M GENMASK(15, 8) #define YT921X_EDATA_CTRL_ADDR(x) FIELD_PREP(YT921X_EDATA_CTRL_ADDR_M, (x)) @@ -833,67 +770,6 @@ enum yt921x_fdb_entry_status { #define YT921X_NAME "yt921x" -struct yt921x_mib_stats { - u64 rx_broadcast; - u64 rx_pause; - u64 rx_multicast; - u64 rx_crc_errors; - - u64 rx_alignment_errors; - u64 rx_undersize_errors; - u64 rx_fragment_errors; - u64 rx_64byte; - - u64 rx_65_127byte; - u64 rx_128_255byte; - u64 rx_256_511byte; - u64 rx_512_1023byte; - - u64 rx_1024_1518byte; - u64 rx_jumbo; - u64 rx_good_bytes; - - u64 rx_bad_bytes; - u64 rx_oversize_errors; - - u64 rx_dropped; - u64 tx_broadcast; - u64 tx_pause; - u64 tx_multicast; - - u64 tx_undersize_errors; - u64 tx_64byte; - u64 tx_65_127byte; - u64 tx_128_255byte; - - u64 tx_256_511byte; - u64 tx_512_1023byte; - u64 tx_1024_1518byte; - u64 tx_jumbo; - - u64 tx_good_bytes; - u64 tx_collisions; - - u64 tx_aborted_errors; - u64 tx_multiple_collisions; - u64 tx_single_collisions; - u64 tx_good; - - u64 tx_deferred; - u64 tx_late_collisions; - u64 rx_oam; - u64 tx_oam; -}; - -struct yt921x_mib { - struct yt921x_port *port; - - struct delayed_work work; - struct yt921x_mib_stats stats; - u64 rx_frames; - u64 tx_frames; -}; - struct yt921x_acl_entry { u32 key[2]; u32 mask[2]; diff --git a/drivers/net/dsa/motorcomm/mib.c b/drivers/net/dsa/motorcomm/mib.c new file mode 100644 index 000000000000..fd634c8e2c04 --- /dev/null +++ b/drivers/net/dsa/motorcomm/mib.c @@ -0,0 +1,404 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 David Yang + */ + +#include "chip.h" +#include "mib.h" +#include "smi.h" + +struct yt921x_mib_desc { + unsigned int size; + unsigned int offset; + const char *name; +}; + +#define MIB_DESC(_size, _offset, _name) \ + {_size, _offset, _name} + +/* Must agree with yt921x_mib_stats + * + * Unstructured fields (name != NULL) will appear in get_ethtool_stats(), + * structured go to their *_stats() methods, but we need their sizes and offsets + * to perform 32bit MIB overflow wraparound. + */ +static const struct yt921x_mib_desc yt921x_mib_descs[] = { + MIB_DESC(1, YT921X_MIB_DATA_RX_BROADCAST, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_PAUSE, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_MULTICAST, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_CRC_ERR, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_RX_ALIGN_ERR, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_UNDERSIZE_ERR, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_FRAG_ERR, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_64, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_65_TO_127, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_128_TO_255, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_256_TO_511, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_512_TO_1023, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_1024_TO_1518, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_PKT_SZ_1519_TO_MAX, NULL), + MIB_DESC(2, YT921X_MIB_DATA_RX_GOOD_BYTES, NULL), + + MIB_DESC(2, YT921X_MIB_DATA_RX_BAD_BYTES, "RxBadBytes"), + MIB_DESC(1, YT921X_MIB_DATA_RX_OVERSIZE_ERR, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_RX_DROPPED, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_BROADCAST, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PAUSE, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_MULTICAST, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_TX_UNDERSIZE_ERR, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_64, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_65_TO_127, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_128_TO_255, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_256_TO_511, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_512_TO_1023, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_1024_TO_1518, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT_SZ_1519_TO_MAX, NULL), + + MIB_DESC(2, YT921X_MIB_DATA_TX_GOOD_BYTES, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_COLLISION, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_TX_EXCESSIVE_COLLISION, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_MULTIPLE_COLLISION, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_SINGLE_COLLISION, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_PKT, NULL), + + MIB_DESC(1, YT921X_MIB_DATA_TX_DEFERRED, NULL), + MIB_DESC(1, YT921X_MIB_DATA_TX_LATE_COLLISION, NULL), + MIB_DESC(1, YT921X_MIB_DATA_RX_OAM, "RxOAM"), + MIB_DESC(1, YT921X_MIB_DATA_TX_OAM, "TxOAM"), +}; + +/* The interval should be small enough to avoid overflow of 32bit MIBs. + * + * Until we can read MIBs from stats64 call directly (i.e. sleep + * there), we have to poll stats more frequently then it is actually needed. + * For overflow protection, normally, 100 sec interval should have been OK. + */ +#define YT921X_STATS_INTERVAL_JIFFIES (3 * HZ) + +/* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */ +static int yt921x_mib_read(struct yt921x_priv *priv, int port) +{ + struct device *dev = yt921x_priv_to_device(priv); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + int res = 0; + + mib = &pm->stats; + + /* Reading of yt921x_mib_stats is not protected by a lock and it's vain + * to keep its consistency, since we have to read registers one by one + * and there is no way to make a snapshot of MIB stats. + * + * Writing (by this function only) is and should be protected by + * reg_lock. + */ + + for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { + const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; + u32 reg = YT921X_MIBn_DATA0(port) + desc->offset; + u64 *valp = &((u64 *)mib)[i]; + u32 val0; + u64 val; + + res = yt921x_reg_read(priv, reg, &val0); + if (res) + break; + + if (desc->size <= 1) { + u64 old_val = *valp; + + val = (old_val & ~(u64)U32_MAX) | val0; + if (val < old_val) + val += 1ull << 32; + } else { + u32 val1; + + res = yt921x_reg_read(priv, reg + 4, &val1); + if (res) + break; + val = ((u64)val1 << 32) | val0; + } + + WRITE_ONCE(*valp, val); + } + + pm->rx_frames = mib->rx_64byte + mib->rx_65_127byte + + mib->rx_128_255byte + mib->rx_256_511byte + + mib->rx_512_1023byte + mib->rx_1024_1518byte + + mib->rx_jumbo; + pm->tx_frames = mib->tx_64byte + mib->tx_65_127byte + + mib->tx_128_255byte + mib->tx_256_511byte + + mib->tx_512_1023byte + mib->tx_1024_1518byte + + mib->tx_jumbo; + + if (res) + dev_err(dev, "Failed to %s port %d: %i\n", "read stats for", + port, res); + return res; +} + +void yt921x_mib_poll(struct work_struct *work) +{ + struct yt921x_mib *pm = container_of_const(work, struct yt921x_mib, + work.work); + struct yt921x_port *pp = pm->port; + unsigned long delay = YT921X_STATS_INTERVAL_JIFFIES; + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + int port = pp->index; + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_mib_read(priv, port); + mutex_unlock(&priv->reg_lock); + if (res) + delay *= 4; + + schedule_delayed_work(&pm->work, delay); +} + +void +yt921x_dsa_get_strings(struct dsa_switch *ds, int port, u32 stringset, + uint8_t *data) +{ + if (stringset != ETH_SS_STATS) + return; + + for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { + const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; + + if (desc->name) + ethtool_puts(&data, desc->name); + } +} + +void +yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + size_t j; + + if (!pm) + return; + mib = &pm->stats; + + mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); + mutex_unlock(&priv->reg_lock); + + j = 0; + for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { + const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; + + if (!desc->name) + continue; + + data[j] = ((u64 *)mib)[i]; + j++; + } +} + +int yt921x_dsa_get_sset_count(struct dsa_switch *ds, int port, int sset) +{ + int cnt = 0; + + if (sset != ETH_SS_STATS) + return 0; + + for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { + const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; + + if (desc->name) + cnt++; + } + + return cnt; +} + +void +yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_mac_stats *mac_stats) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; + + mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); + mutex_unlock(&priv->reg_lock); + + mac_stats->FramesTransmittedOK = pm->tx_frames; + mac_stats->SingleCollisionFrames = mib->tx_single_collisions; + mac_stats->MultipleCollisionFrames = mib->tx_multiple_collisions; + mac_stats->FramesReceivedOK = pm->rx_frames; + mac_stats->FrameCheckSequenceErrors = mib->rx_crc_errors; + mac_stats->AlignmentErrors = mib->rx_alignment_errors; + mac_stats->OctetsTransmittedOK = mib->tx_good_bytes; + mac_stats->FramesWithDeferredXmissions = mib->tx_deferred; + mac_stats->LateCollisions = mib->tx_late_collisions; + mac_stats->FramesAbortedDueToXSColls = mib->tx_aborted_errors; + /* mac_stats->FramesLostDueToIntMACXmitError */ + /* mac_stats->CarrierSenseErrors */ + mac_stats->OctetsReceivedOK = mib->rx_good_bytes; + /* mac_stats->FramesLostDueToIntMACRcvError */ + mac_stats->MulticastFramesXmittedOK = mib->tx_multicast; + mac_stats->BroadcastFramesXmittedOK = mib->tx_broadcast; + /* mac_stats->FramesWithExcessiveDeferral */ + mac_stats->MulticastFramesReceivedOK = mib->rx_multicast; + mac_stats->BroadcastFramesReceivedOK = mib->rx_broadcast; + /* mac_stats->InRangeLengthErrors */ + /* mac_stats->OutOfRangeLengthField */ + mac_stats->FrameTooLongErrors = mib->rx_oversize_errors; +} + +void +yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; + + mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); + mutex_unlock(&priv->reg_lock); + + ctrl_stats->MACControlFramesTransmitted = mib->tx_pause; + ctrl_stats->MACControlFramesReceived = mib->rx_pause; + /* ctrl_stats->UnsupportedOpcodesReceived */ +} + +static const struct ethtool_rmon_hist_range yt921x_rmon_ranges[] = { + { 0, 64 }, + { 65, 127 }, + { 128, 255 }, + { 256, 511 }, + { 512, 1023 }, + { 1024, 1518 }, + { 1519, YT921X_FRAME_SIZE_MAX }, + {} +}; + +void +yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; + + mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); + mutex_unlock(&priv->reg_lock); + + *ranges = yt921x_rmon_ranges; + + rmon_stats->undersize_pkts = mib->rx_undersize_errors; + rmon_stats->oversize_pkts = mib->rx_oversize_errors; + rmon_stats->fragments = mib->rx_alignment_errors; + /* rmon_stats->jabbers */ + + rmon_stats->hist[0] = mib->rx_64byte; + rmon_stats->hist[1] = mib->rx_65_127byte; + rmon_stats->hist[2] = mib->rx_128_255byte; + rmon_stats->hist[3] = mib->rx_256_511byte; + rmon_stats->hist[4] = mib->rx_512_1023byte; + rmon_stats->hist[5] = mib->rx_1024_1518byte; + rmon_stats->hist[6] = mib->rx_jumbo; + + rmon_stats->hist_tx[0] = mib->tx_64byte; + rmon_stats->hist_tx[1] = mib->tx_65_127byte; + rmon_stats->hist_tx[2] = mib->tx_128_255byte; + rmon_stats->hist_tx[3] = mib->tx_256_511byte; + rmon_stats->hist_tx[4] = mib->tx_512_1023byte; + rmon_stats->hist_tx[5] = mib->tx_1024_1518byte; + rmon_stats->hist_tx[6] = mib->tx_jumbo; +} + +void +yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, + struct rtnl_link_stats64 *stats) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; + + stats->rx_length_errors = mib->rx_undersize_errors + + mib->rx_fragment_errors; + stats->rx_over_errors = mib->rx_oversize_errors; + stats->rx_crc_errors = mib->rx_crc_errors; + stats->rx_frame_errors = mib->rx_alignment_errors; + /* stats->rx_fifo_errors */ + /* stats->rx_missed_errors */ + + stats->tx_aborted_errors = mib->tx_aborted_errors; + /* stats->tx_carrier_errors */ + stats->tx_fifo_errors = mib->tx_undersize_errors; + /* stats->tx_heartbeat_errors */ + stats->tx_window_errors = mib->tx_late_collisions; + + stats->rx_packets = pm->rx_frames; + stats->tx_packets = pm->tx_frames; + stats->rx_bytes = mib->rx_good_bytes - ETH_FCS_LEN * stats->rx_packets; + stats->tx_bytes = mib->tx_good_bytes - ETH_FCS_LEN * stats->tx_packets; + stats->rx_errors = stats->rx_length_errors + stats->rx_over_errors + + stats->rx_crc_errors + stats->rx_frame_errors; + stats->tx_errors = stats->tx_aborted_errors + stats->tx_fifo_errors + + stats->tx_window_errors; + stats->rx_dropped = mib->rx_dropped; + /* stats->tx_dropped */ + stats->multicast = mib->rx_multicast; + stats->collisions = mib->tx_collisions; +} + +void +yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, + struct ethtool_pause_stats *pause_stats) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct yt921x_mib *pm = pp->mib; + struct yt921x_mib_stats *mib; + + if (!pm) + return; + mib = &pm->stats; + + mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); + mutex_unlock(&priv->reg_lock); + + pause_stats->tx_pause_frames = mib->tx_pause; + pause_stats->rx_pause_frames = mib->rx_pause; +} diff --git a/drivers/net/dsa/motorcomm/mib.h b/drivers/net/dsa/motorcomm/mib.h new file mode 100644 index 000000000000..cfad0665baae --- /dev/null +++ b/drivers/net/dsa/motorcomm/mib.h @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2026 David Yang + */ + +#ifndef _YT_MIB_H +#define _YT_MIB_H + +#include + +#define YT921X_MIB_CTRL 0xc0004 +#define YT921X_MIB_CTRL_CLEAN BIT(30) +#define YT921X_MIB_CTRL_PORT_M GENMASK(6, 3) +#define YT921X_MIB_CTRL_PORT(x) FIELD_PREP(YT921X_MIB_CTRL_PORT_M, (x)) +#define YT921X_MIB_CTRL_ONE_PORT BIT(1) +#define YT921X_MIB_CTRL_ALL_PORT BIT(0) +#define YT921X_MIBn_DATA0(port) (0xc0100 + 0x100 * (port)) +#define YT921X_MIBn_DATAm(port, x) (YT921X_MIBn_DATA0(port) + 4 * (x)) +#define YT921X_MIB_DATA_RX_BROADCAST 0x00 +#define YT921X_MIB_DATA_RX_PAUSE 0x04 +#define YT921X_MIB_DATA_RX_MULTICAST 0x08 +#define YT921X_MIB_DATA_RX_CRC_ERR 0x0c + +#define YT921X_MIB_DATA_RX_ALIGN_ERR 0x10 +#define YT921X_MIB_DATA_RX_UNDERSIZE_ERR 0x14 +#define YT921X_MIB_DATA_RX_FRAG_ERR 0x18 +#define YT921X_MIB_DATA_RX_PKT_SZ_64 0x1c + +#define YT921X_MIB_DATA_RX_PKT_SZ_65_TO_127 0x20 +#define YT921X_MIB_DATA_RX_PKT_SZ_128_TO_255 0x24 +#define YT921X_MIB_DATA_RX_PKT_SZ_256_TO_511 0x28 +#define YT921X_MIB_DATA_RX_PKT_SZ_512_TO_1023 0x2c + +#define YT921X_MIB_DATA_RX_PKT_SZ_1024_TO_1518 0x30 +#define YT921X_MIB_DATA_RX_PKT_SZ_1519_TO_MAX 0x34 +/* 0x38: unused */ +#define YT921X_MIB_DATA_RX_GOOD_BYTES 0x3c + +/* 0x40: 64 bytes */ +#define YT921X_MIB_DATA_RX_BAD_BYTES 0x44 +/* 0x48: 64 bytes */ +#define YT921X_MIB_DATA_RX_OVERSIZE_ERR 0x4c + +#define YT921X_MIB_DATA_RX_DROPPED 0x50 +#define YT921X_MIB_DATA_TX_BROADCAST 0x54 +#define YT921X_MIB_DATA_TX_PAUSE 0x58 +#define YT921X_MIB_DATA_TX_MULTICAST 0x5c + +#define YT921X_MIB_DATA_TX_UNDERSIZE_ERR 0x60 +#define YT921X_MIB_DATA_TX_PKT_SZ_64 0x64 +#define YT921X_MIB_DATA_TX_PKT_SZ_65_TO_127 0x68 +#define YT921X_MIB_DATA_TX_PKT_SZ_128_TO_255 0x6c + +#define YT921X_MIB_DATA_TX_PKT_SZ_256_TO_511 0x70 +#define YT921X_MIB_DATA_TX_PKT_SZ_512_TO_1023 0x74 +#define YT921X_MIB_DATA_TX_PKT_SZ_1024_TO_1518 0x78 +#define YT921X_MIB_DATA_TX_PKT_SZ_1519_TO_MAX 0x7c + +/* 0x80: unused */ +#define YT921X_MIB_DATA_TX_GOOD_BYTES 0x84 +/* 0x88: 64 bytes */ +#define YT921X_MIB_DATA_TX_COLLISION 0x8c + +#define YT921X_MIB_DATA_TX_EXCESSIVE_COLLISION 0x90 +#define YT921X_MIB_DATA_TX_MULTIPLE_COLLISION 0x94 +#define YT921X_MIB_DATA_TX_SINGLE_COLLISION 0x98 +#define YT921X_MIB_DATA_TX_PKT 0x9c + +#define YT921X_MIB_DATA_TX_DEFERRED 0xa0 +#define YT921X_MIB_DATA_TX_LATE_COLLISION 0xa4 +#define YT921X_MIB_DATA_RX_OAM 0xa8 +#define YT921X_MIB_DATA_TX_OAM 0xac + +struct yt921x_mib_stats { + u64 rx_broadcast; + u64 rx_pause; + u64 rx_multicast; + u64 rx_crc_errors; + + u64 rx_alignment_errors; + u64 rx_undersize_errors; + u64 rx_fragment_errors; + u64 rx_64byte; + + u64 rx_65_127byte; + u64 rx_128_255byte; + u64 rx_256_511byte; + u64 rx_512_1023byte; + + u64 rx_1024_1518byte; + u64 rx_jumbo; + u64 rx_good_bytes; + + u64 rx_bad_bytes; + u64 rx_oversize_errors; + + u64 rx_dropped; + u64 tx_broadcast; + u64 tx_pause; + u64 tx_multicast; + + u64 tx_undersize_errors; + u64 tx_64byte; + u64 tx_65_127byte; + u64 tx_128_255byte; + + u64 tx_256_511byte; + u64 tx_512_1023byte; + u64 tx_1024_1518byte; + u64 tx_jumbo; + + u64 tx_good_bytes; + u64 tx_collisions; + + u64 tx_aborted_errors; + u64 tx_multiple_collisions; + u64 tx_single_collisions; + u64 tx_good; + + u64 tx_deferred; + u64 tx_late_collisions; + u64 rx_oam; + u64 tx_oam; +}; + +struct yt921x_mib { + struct yt921x_port *port; + + struct delayed_work work; + struct yt921x_mib_stats stats; + u64 rx_frames; + u64 tx_frames; +}; + +void yt921x_mib_poll(struct work_struct *work); +void +yt921x_dsa_get_strings(struct dsa_switch *ds, int port, u32 stringset, + uint8_t *data); +void +yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data); +int yt921x_dsa_get_sset_count(struct dsa_switch *ds, int port, int sset); +void +yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_mac_stats *mac_stats); +void +yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats); +void +yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges); +void +yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, + struct rtnl_link_stats64 *stats); +void +yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, + struct ethtool_pause_stats *pause_stats); + +#endif From e7b23688d0d370bae29801cba686640558231670 Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 5 Oct 2026 00:06:19 +0800 Subject: [PATCH 1390/2126] net: dsa: motorcomm: Use u64_stats_t for MIB stats 64-bit variables might not be atomic on 32-bit architectures, and could lead to load/store tearing. This is a verbatim change that replaces every u64 statistics into u64_stats_t. This is not a self-contained fix-all commit: u64_stats_sync is equipped in the next commit for easy reviewing. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261004160622.948037-6-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/mib.c | 148 ++++++++++++++++---------------- drivers/net/dsa/motorcomm/mib.h | 84 +++++++++--------- 2 files changed, 119 insertions(+), 113 deletions(-) diff --git a/drivers/net/dsa/motorcomm/mib.c b/drivers/net/dsa/motorcomm/mib.c index fd634c8e2c04..7d83bb3a8a86 100644 --- a/drivers/net/dsa/motorcomm/mib.c +++ b/drivers/net/dsa/motorcomm/mib.c @@ -89,22 +89,16 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *pm = pp->mib; struct yt921x_mib_stats *mib; + u64 rx_frames; + u64 tx_frames; int res = 0; mib = &pm->stats; - /* Reading of yt921x_mib_stats is not protected by a lock and it's vain - * to keep its consistency, since we have to read registers one by one - * and there is no way to make a snapshot of MIB stats. - * - * Writing (by this function only) is and should be protected by - * reg_lock. - */ - for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; u32 reg = YT921X_MIBn_DATA0(port) + desc->offset; - u64 *valp = &((u64 *)mib)[i]; + u64_stats_t *valp = &((u64_stats_t *)mib)[i]; u32 val0; u64 val; @@ -113,7 +107,7 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) break; if (desc->size <= 1) { - u64 old_val = *valp; + u64 old_val = u64_stats_read(valp); val = (old_val & ~(u64)U32_MAX) | val0; if (val < old_val) @@ -127,17 +121,25 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) val = ((u64)val1 << 32) | val0; } - WRITE_ONCE(*valp, val); + u64_stats_set(valp, val); } - pm->rx_frames = mib->rx_64byte + mib->rx_65_127byte + - mib->rx_128_255byte + mib->rx_256_511byte + - mib->rx_512_1023byte + mib->rx_1024_1518byte + - mib->rx_jumbo; - pm->tx_frames = mib->tx_64byte + mib->tx_65_127byte + - mib->tx_128_255byte + mib->tx_256_511byte + - mib->tx_512_1023byte + mib->tx_1024_1518byte + - mib->tx_jumbo; + rx_frames = u64_stats_read(&mib->rx_64byte) + + u64_stats_read(&mib->rx_65_127byte) + + u64_stats_read(&mib->rx_128_255byte) + + u64_stats_read(&mib->rx_256_511byte) + + u64_stats_read(&mib->rx_512_1023byte) + + u64_stats_read(&mib->rx_1024_1518byte) + + u64_stats_read(&mib->rx_jumbo); + tx_frames = u64_stats_read(&mib->tx_64byte) + + u64_stats_read(&mib->tx_65_127byte) + + u64_stats_read(&mib->tx_128_255byte) + + u64_stats_read(&mib->tx_256_511byte) + + u64_stats_read(&mib->tx_512_1023byte) + + u64_stats_read(&mib->tx_1024_1518byte) + + u64_stats_read(&mib->tx_jumbo); + u64_stats_set(&pm->rx_frames, rx_frames); + u64_stats_set(&pm->tx_frames, tx_frames); if (res) dev_err(dev, "Failed to %s port %d: %i\n", "read stats for", @@ -203,7 +205,7 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) if (!desc->name) continue; - data[j] = ((u64 *)mib)[i]; + data[j] = u64_stats_read(&((u64_stats_t *)mib)[i]); j++; } } @@ -242,28 +244,28 @@ yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); - mac_stats->FramesTransmittedOK = pm->tx_frames; - mac_stats->SingleCollisionFrames = mib->tx_single_collisions; - mac_stats->MultipleCollisionFrames = mib->tx_multiple_collisions; - mac_stats->FramesReceivedOK = pm->rx_frames; - mac_stats->FrameCheckSequenceErrors = mib->rx_crc_errors; - mac_stats->AlignmentErrors = mib->rx_alignment_errors; - mac_stats->OctetsTransmittedOK = mib->tx_good_bytes; - mac_stats->FramesWithDeferredXmissions = mib->tx_deferred; - mac_stats->LateCollisions = mib->tx_late_collisions; - mac_stats->FramesAbortedDueToXSColls = mib->tx_aborted_errors; + mac_stats->FramesTransmittedOK = u64_stats_read(&pm->tx_frames); + mac_stats->SingleCollisionFrames = u64_stats_read(&mib->tx_single_collisions); + mac_stats->MultipleCollisionFrames = u64_stats_read(&mib->tx_multiple_collisions); + mac_stats->FramesReceivedOK = u64_stats_read(&pm->rx_frames); + mac_stats->FrameCheckSequenceErrors = u64_stats_read(&mib->rx_crc_errors); + mac_stats->AlignmentErrors = u64_stats_read(&mib->rx_alignment_errors); + mac_stats->OctetsTransmittedOK = u64_stats_read(&mib->tx_good_bytes); + mac_stats->FramesWithDeferredXmissions = u64_stats_read(&mib->tx_deferred); + mac_stats->LateCollisions = u64_stats_read(&mib->tx_late_collisions); + mac_stats->FramesAbortedDueToXSColls = u64_stats_read(&mib->tx_aborted_errors); /* mac_stats->FramesLostDueToIntMACXmitError */ /* mac_stats->CarrierSenseErrors */ - mac_stats->OctetsReceivedOK = mib->rx_good_bytes; + mac_stats->OctetsReceivedOK = u64_stats_read(&mib->rx_good_bytes); /* mac_stats->FramesLostDueToIntMACRcvError */ - mac_stats->MulticastFramesXmittedOK = mib->tx_multicast; - mac_stats->BroadcastFramesXmittedOK = mib->tx_broadcast; + mac_stats->MulticastFramesXmittedOK = u64_stats_read(&mib->tx_multicast); + mac_stats->BroadcastFramesXmittedOK = u64_stats_read(&mib->tx_broadcast); /* mac_stats->FramesWithExcessiveDeferral */ - mac_stats->MulticastFramesReceivedOK = mib->rx_multicast; - mac_stats->BroadcastFramesReceivedOK = mib->rx_broadcast; + mac_stats->MulticastFramesReceivedOK = u64_stats_read(&mib->rx_multicast); + mac_stats->BroadcastFramesReceivedOK = u64_stats_read(&mib->rx_broadcast); /* mac_stats->InRangeLengthErrors */ /* mac_stats->OutOfRangeLengthField */ - mac_stats->FrameTooLongErrors = mib->rx_oversize_errors; + mac_stats->FrameTooLongErrors = u64_stats_read(&mib->rx_oversize_errors); } void @@ -283,8 +285,8 @@ yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); - ctrl_stats->MACControlFramesTransmitted = mib->tx_pause; - ctrl_stats->MACControlFramesReceived = mib->rx_pause; + ctrl_stats->MACControlFramesTransmitted = u64_stats_read(&mib->tx_pause); + ctrl_stats->MACControlFramesReceived = u64_stats_read(&mib->rx_pause); /* ctrl_stats->UnsupportedOpcodesReceived */ } @@ -319,26 +321,26 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, *ranges = yt921x_rmon_ranges; - rmon_stats->undersize_pkts = mib->rx_undersize_errors; - rmon_stats->oversize_pkts = mib->rx_oversize_errors; - rmon_stats->fragments = mib->rx_alignment_errors; + rmon_stats->undersize_pkts = u64_stats_read(&mib->rx_undersize_errors); + rmon_stats->oversize_pkts = u64_stats_read(&mib->rx_oversize_errors); + rmon_stats->fragments = u64_stats_read(&mib->rx_alignment_errors); /* rmon_stats->jabbers */ - rmon_stats->hist[0] = mib->rx_64byte; - rmon_stats->hist[1] = mib->rx_65_127byte; - rmon_stats->hist[2] = mib->rx_128_255byte; - rmon_stats->hist[3] = mib->rx_256_511byte; - rmon_stats->hist[4] = mib->rx_512_1023byte; - rmon_stats->hist[5] = mib->rx_1024_1518byte; - rmon_stats->hist[6] = mib->rx_jumbo; + rmon_stats->hist[0] = u64_stats_read(&mib->rx_64byte); + rmon_stats->hist[1] = u64_stats_read(&mib->rx_65_127byte); + rmon_stats->hist[2] = u64_stats_read(&mib->rx_128_255byte); + rmon_stats->hist[3] = u64_stats_read(&mib->rx_256_511byte); + rmon_stats->hist[4] = u64_stats_read(&mib->rx_512_1023byte); + rmon_stats->hist[5] = u64_stats_read(&mib->rx_1024_1518byte); + rmon_stats->hist[6] = u64_stats_read(&mib->rx_jumbo); - rmon_stats->hist_tx[0] = mib->tx_64byte; - rmon_stats->hist_tx[1] = mib->tx_65_127byte; - rmon_stats->hist_tx[2] = mib->tx_128_255byte; - rmon_stats->hist_tx[3] = mib->tx_256_511byte; - rmon_stats->hist_tx[4] = mib->tx_512_1023byte; - rmon_stats->hist_tx[5] = mib->tx_1024_1518byte; - rmon_stats->hist_tx[6] = mib->tx_jumbo; + rmon_stats->hist_tx[0] = u64_stats_read(&mib->tx_64byte); + rmon_stats->hist_tx[1] = u64_stats_read(&mib->tx_65_127byte); + rmon_stats->hist_tx[2] = u64_stats_read(&mib->tx_128_255byte); + rmon_stats->hist_tx[3] = u64_stats_read(&mib->tx_256_511byte); + rmon_stats->hist_tx[4] = u64_stats_read(&mib->tx_512_1023byte); + rmon_stats->hist_tx[5] = u64_stats_read(&mib->tx_1024_1518byte); + rmon_stats->hist_tx[6] = u64_stats_read(&mib->tx_jumbo); } void @@ -354,32 +356,34 @@ yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, return; mib = &pm->stats; - stats->rx_length_errors = mib->rx_undersize_errors + - mib->rx_fragment_errors; - stats->rx_over_errors = mib->rx_oversize_errors; - stats->rx_crc_errors = mib->rx_crc_errors; - stats->rx_frame_errors = mib->rx_alignment_errors; + stats->rx_length_errors = u64_stats_read(&mib->rx_undersize_errors) + + u64_stats_read(&mib->rx_fragment_errors); + stats->rx_over_errors = u64_stats_read(&mib->rx_oversize_errors); + stats->rx_crc_errors = u64_stats_read(&mib->rx_crc_errors); + stats->rx_frame_errors = u64_stats_read(&mib->rx_alignment_errors); /* stats->rx_fifo_errors */ /* stats->rx_missed_errors */ - stats->tx_aborted_errors = mib->tx_aborted_errors; + stats->tx_aborted_errors = u64_stats_read(&mib->tx_aborted_errors); /* stats->tx_carrier_errors */ - stats->tx_fifo_errors = mib->tx_undersize_errors; + stats->tx_fifo_errors = u64_stats_read(&mib->tx_undersize_errors); /* stats->tx_heartbeat_errors */ - stats->tx_window_errors = mib->tx_late_collisions; + stats->tx_window_errors = u64_stats_read(&mib->tx_late_collisions); - stats->rx_packets = pm->rx_frames; - stats->tx_packets = pm->tx_frames; - stats->rx_bytes = mib->rx_good_bytes - ETH_FCS_LEN * stats->rx_packets; - stats->tx_bytes = mib->tx_good_bytes - ETH_FCS_LEN * stats->tx_packets; + stats->rx_packets = u64_stats_read(&pm->rx_frames); + stats->tx_packets = u64_stats_read(&pm->tx_frames); + stats->rx_bytes = u64_stats_read(&mib->rx_good_bytes) - + ETH_FCS_LEN * stats->rx_packets; + stats->tx_bytes = u64_stats_read(&mib->tx_good_bytes) - + ETH_FCS_LEN * stats->tx_packets; stats->rx_errors = stats->rx_length_errors + stats->rx_over_errors + stats->rx_crc_errors + stats->rx_frame_errors; stats->tx_errors = stats->tx_aborted_errors + stats->tx_fifo_errors + stats->tx_window_errors; - stats->rx_dropped = mib->rx_dropped; + stats->rx_dropped = u64_stats_read(&mib->rx_dropped); /* stats->tx_dropped */ - stats->multicast = mib->rx_multicast; - stats->collisions = mib->tx_collisions; + stats->multicast = u64_stats_read(&mib->rx_multicast); + stats->collisions = u64_stats_read(&mib->tx_collisions); } void @@ -399,6 +403,6 @@ yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, yt921x_mib_read(priv, port); mutex_unlock(&priv->reg_lock); - pause_stats->tx_pause_frames = mib->tx_pause; - pause_stats->rx_pause_frames = mib->rx_pause; + pause_stats->tx_pause_frames = u64_stats_read(&mib->tx_pause); + pause_stats->rx_pause_frames = u64_stats_read(&mib->rx_pause); } diff --git a/drivers/net/dsa/motorcomm/mib.h b/drivers/net/dsa/motorcomm/mib.h index cfad0665baae..d84ae2f449ac 100644 --- a/drivers/net/dsa/motorcomm/mib.h +++ b/drivers/net/dsa/motorcomm/mib.h @@ -6,6 +6,8 @@ #ifndef _YT_MIB_H #define _YT_MIB_H +#include + #include #define YT921X_MIB_CTRL 0xc0004 @@ -72,55 +74,55 @@ #define YT921X_MIB_DATA_TX_OAM 0xac struct yt921x_mib_stats { - u64 rx_broadcast; - u64 rx_pause; - u64 rx_multicast; - u64 rx_crc_errors; + u64_stats_t rx_broadcast; + u64_stats_t rx_pause; + u64_stats_t rx_multicast; + u64_stats_t rx_crc_errors; - u64 rx_alignment_errors; - u64 rx_undersize_errors; - u64 rx_fragment_errors; - u64 rx_64byte; + u64_stats_t rx_alignment_errors; + u64_stats_t rx_undersize_errors; + u64_stats_t rx_fragment_errors; + u64_stats_t rx_64byte; - u64 rx_65_127byte; - u64 rx_128_255byte; - u64 rx_256_511byte; - u64 rx_512_1023byte; + u64_stats_t rx_65_127byte; + u64_stats_t rx_128_255byte; + u64_stats_t rx_256_511byte; + u64_stats_t rx_512_1023byte; - u64 rx_1024_1518byte; - u64 rx_jumbo; - u64 rx_good_bytes; + u64_stats_t rx_1024_1518byte; + u64_stats_t rx_jumbo; + u64_stats_t rx_good_bytes; - u64 rx_bad_bytes; - u64 rx_oversize_errors; + u64_stats_t rx_bad_bytes; + u64_stats_t rx_oversize_errors; - u64 rx_dropped; - u64 tx_broadcast; - u64 tx_pause; - u64 tx_multicast; + u64_stats_t rx_dropped; + u64_stats_t tx_broadcast; + u64_stats_t tx_pause; + u64_stats_t tx_multicast; - u64 tx_undersize_errors; - u64 tx_64byte; - u64 tx_65_127byte; - u64 tx_128_255byte; + u64_stats_t tx_undersize_errors; + u64_stats_t tx_64byte; + u64_stats_t tx_65_127byte; + u64_stats_t tx_128_255byte; - u64 tx_256_511byte; - u64 tx_512_1023byte; - u64 tx_1024_1518byte; - u64 tx_jumbo; + u64_stats_t tx_256_511byte; + u64_stats_t tx_512_1023byte; + u64_stats_t tx_1024_1518byte; + u64_stats_t tx_jumbo; - u64 tx_good_bytes; - u64 tx_collisions; + u64_stats_t tx_good_bytes; + u64_stats_t tx_collisions; - u64 tx_aborted_errors; - u64 tx_multiple_collisions; - u64 tx_single_collisions; - u64 tx_good; + u64_stats_t tx_aborted_errors; + u64_stats_t tx_multiple_collisions; + u64_stats_t tx_single_collisions; + u64_stats_t tx_good; - u64 tx_deferred; - u64 tx_late_collisions; - u64 rx_oam; - u64 tx_oam; + u64_stats_t tx_deferred; + u64_stats_t tx_late_collisions; + u64_stats_t rx_oam; + u64_stats_t tx_oam; }; struct yt921x_mib { @@ -128,8 +130,8 @@ struct yt921x_mib { struct delayed_work work; struct yt921x_mib_stats stats; - u64 rx_frames; - u64 tx_frames; + u64_stats_t rx_frames; + u64_stats_t tx_frames; }; void yt921x_mib_poll(struct work_struct *work); From ed4453587dc0082a6b6b5a52c89d6b84d713e8ac Mon Sep 17 00:00:00 2001 From: David Yang Date: Mon, 5 Oct 2026 00:06:20 +0800 Subject: [PATCH 1391/2126] net: dsa: motorcomm: Fix MIB synchronization The previous MIB sync was based on the false assumption that 64-bit variables are always atomic. To fix that: * .get_stats64() uses u64_stats_sync, together with u64_stats_t; * others take the free mutex lock if possible. To minimize time of the write side of u64_stats_sync, a per-port buffer is used so that all the stat can be written back altogether after all IO operations. The odds of this issue are very low and it does not affect the control flow, while fixing it would require a thorough refactoring (together with the previous commit), so it may not be worth backporting. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261004160622.948037-7-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.c | 2 + drivers/net/dsa/motorcomm/mib.c | 89 ++++++++++++++++++++------------ drivers/net/dsa/motorcomm/mib.h | 6 +++ 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 9e3be08b3465..91cc5647f2b6 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -3472,6 +3473,7 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port) pp->mib = pm; pm->port = pp; + u64_stats_init(&pm->syncp); INIT_DELAYED_WORK(&pm->work, yt921x_mib_poll); /* Start disabled, so that the enable below always pairs with * either this disable or the one from a previous teardown diff --git a/drivers/net/dsa/motorcomm/mib.c b/drivers/net/dsa/motorcomm/mib.c index 7d83bb3a8a86..6b170fc6e187 100644 --- a/drivers/net/dsa/motorcomm/mib.c +++ b/drivers/net/dsa/motorcomm/mib.c @@ -74,6 +74,8 @@ static const struct yt921x_mib_desc yt921x_mib_descs[] = { MIB_DESC(1, YT921X_MIB_DATA_TX_OAM, "TxOAM"), }; +static_assert(ARRAY_SIZE(yt921x_mib_descs) == YT921X_MIB_STAT_NUM); + /* The interval should be small enough to avoid overflow of 32bit MIBs. * * Until we can read MIBs from stats64 call directly (i.e. sleep @@ -89,6 +91,8 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *pm = pp->mib; struct yt921x_mib_stats *mib; + u64 *buf = pm->data; + unsigned long flags; u64 rx_frames; u64 tx_frames; int res = 0; @@ -98,7 +102,6 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i]; u32 reg = YT921X_MIBn_DATA0(port) + desc->offset; - u64_stats_t *valp = &((u64_stats_t *)mib)[i]; u32 val0; u64 val; @@ -107,7 +110,7 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) break; if (desc->size <= 1) { - u64 old_val = u64_stats_read(valp); + u64 old_val = buf[i]; val = (old_val & ~(u64)U32_MAX) | val0; if (val < old_val) @@ -121,9 +124,12 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) val = ((u64)val1 << 32) | val0; } - u64_stats_set(valp, val); + buf[i] = val; } + flags = u64_stats_update_begin_irqsave(&pm->syncp); + for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) + u64_stats_set(&((u64_stats_t *)mib)[i], buf[i]); rx_frames = u64_stats_read(&mib->rx_64byte) + u64_stats_read(&mib->rx_65_127byte) + u64_stats_read(&mib->rx_128_255byte) + @@ -140,6 +146,7 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port) u64_stats_read(&mib->tx_jumbo); u64_stats_set(&pm->rx_frames, rx_frames); u64_stats_set(&pm->tx_frames, tx_frames); + u64_stats_update_end_irqrestore(&pm->syncp, flags); if (res) dev_err(dev, "Failed to %s port %d: %i\n", "read stats for", @@ -187,16 +194,16 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *pm = pp->mib; - struct yt921x_mib_stats *mib; + u64 *buf; size_t j; if (!pm) return; - mib = &pm->stats; + buf = pm->data; mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); j = 0; for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) { @@ -205,9 +212,11 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) if (!desc->name) continue; - data[j] = u64_stats_read(&((u64_stats_t *)mib)[i]); + data[j] = buf[i]; j++; } + + mutex_unlock(&priv->reg_lock); } int yt921x_dsa_get_sset_count(struct dsa_switch *ds, int port, int sset) @@ -241,8 +250,8 @@ yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, mib = &pm->stats; mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); mac_stats->FramesTransmittedOK = u64_stats_read(&pm->tx_frames); mac_stats->SingleCollisionFrames = u64_stats_read(&mib->tx_single_collisions); @@ -266,6 +275,8 @@ yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port, /* mac_stats->InRangeLengthErrors */ /* mac_stats->OutOfRangeLengthField */ mac_stats->FrameTooLongErrors = u64_stats_read(&mib->rx_oversize_errors); + + mutex_unlock(&priv->reg_lock); } void @@ -282,12 +293,14 @@ yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port, mib = &pm->stats; mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); ctrl_stats->MACControlFramesTransmitted = u64_stats_read(&mib->tx_pause); ctrl_stats->MACControlFramesReceived = u64_stats_read(&mib->rx_pause); /* ctrl_stats->UnsupportedOpcodesReceived */ + + mutex_unlock(&priv->reg_lock); } static const struct ethtool_rmon_hist_range yt921x_rmon_ranges[] = { @@ -316,8 +329,8 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, mib = &pm->stats; mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); *ranges = yt921x_rmon_ranges; @@ -341,6 +354,8 @@ yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port, rmon_stats->hist_tx[4] = u64_stats_read(&mib->tx_512_1023byte); rmon_stats->hist_tx[5] = u64_stats_read(&mib->tx_1024_1518byte); rmon_stats->hist_tx[6] = u64_stats_read(&mib->tx_jumbo); + + mutex_unlock(&priv->reg_lock); } void @@ -351,39 +366,45 @@ yt921x_dsa_get_stats64(struct dsa_switch *ds, int port, struct yt921x_port *pp = &priv->ports[port]; struct yt921x_mib *pm = pp->mib; struct yt921x_mib_stats *mib; + unsigned int start; if (!pm) return; mib = &pm->stats; - stats->rx_length_errors = u64_stats_read(&mib->rx_undersize_errors) + - u64_stats_read(&mib->rx_fragment_errors); - stats->rx_over_errors = u64_stats_read(&mib->rx_oversize_errors); - stats->rx_crc_errors = u64_stats_read(&mib->rx_crc_errors); - stats->rx_frame_errors = u64_stats_read(&mib->rx_alignment_errors); - /* stats->rx_fifo_errors */ - /* stats->rx_missed_errors */ + do { + start = u64_stats_fetch_begin(&pm->syncp); - stats->tx_aborted_errors = u64_stats_read(&mib->tx_aborted_errors); - /* stats->tx_carrier_errors */ - stats->tx_fifo_errors = u64_stats_read(&mib->tx_undersize_errors); - /* stats->tx_heartbeat_errors */ - stats->tx_window_errors = u64_stats_read(&mib->tx_late_collisions); + stats->rx_length_errors = u64_stats_read(&mib->rx_undersize_errors) + + u64_stats_read(&mib->rx_fragment_errors); + stats->rx_over_errors = u64_stats_read(&mib->rx_oversize_errors); + stats->rx_crc_errors = u64_stats_read(&mib->rx_crc_errors); + stats->rx_frame_errors = u64_stats_read(&mib->rx_alignment_errors); + /* stats->rx_fifo_errors */ + /* stats->rx_missed_errors */ + + stats->tx_aborted_errors = u64_stats_read(&mib->tx_aborted_errors); + /* stats->tx_carrier_errors */ + stats->tx_fifo_errors = u64_stats_read(&mib->tx_undersize_errors); + /* stats->tx_heartbeat_errors */ + stats->tx_window_errors = u64_stats_read(&mib->tx_late_collisions); + + stats->rx_packets = u64_stats_read(&pm->rx_frames); + stats->tx_packets = u64_stats_read(&pm->tx_frames); + stats->rx_bytes = u64_stats_read(&mib->rx_good_bytes) - + ETH_FCS_LEN * stats->rx_packets; + stats->tx_bytes = u64_stats_read(&mib->tx_good_bytes) - + ETH_FCS_LEN * stats->tx_packets; + stats->rx_dropped = u64_stats_read(&mib->rx_dropped); + /* stats->tx_dropped */ + stats->multicast = u64_stats_read(&mib->rx_multicast); + stats->collisions = u64_stats_read(&mib->tx_collisions); + } while (u64_stats_fetch_retry(&pm->syncp, start)); - stats->rx_packets = u64_stats_read(&pm->rx_frames); - stats->tx_packets = u64_stats_read(&pm->tx_frames); - stats->rx_bytes = u64_stats_read(&mib->rx_good_bytes) - - ETH_FCS_LEN * stats->rx_packets; - stats->tx_bytes = u64_stats_read(&mib->tx_good_bytes) - - ETH_FCS_LEN * stats->tx_packets; stats->rx_errors = stats->rx_length_errors + stats->rx_over_errors + stats->rx_crc_errors + stats->rx_frame_errors; stats->tx_errors = stats->tx_aborted_errors + stats->tx_fifo_errors + stats->tx_window_errors; - stats->rx_dropped = u64_stats_read(&mib->rx_dropped); - /* stats->tx_dropped */ - stats->multicast = u64_stats_read(&mib->rx_multicast); - stats->collisions = u64_stats_read(&mib->tx_collisions); } void @@ -400,9 +421,11 @@ yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port, mib = &pm->stats; mutex_lock(&priv->reg_lock); + yt921x_mib_read(priv, port); - mutex_unlock(&priv->reg_lock); pause_stats->tx_pause_frames = u64_stats_read(&mib->tx_pause); pause_stats->rx_pause_frames = u64_stats_read(&mib->rx_pause); + + mutex_unlock(&priv->reg_lock); } diff --git a/drivers/net/dsa/motorcomm/mib.h b/drivers/net/dsa/motorcomm/mib.h index d84ae2f449ac..9c24a52d46cc 100644 --- a/drivers/net/dsa/motorcomm/mib.h +++ b/drivers/net/dsa/motorcomm/mib.h @@ -125,13 +125,19 @@ struct yt921x_mib_stats { u64_stats_t tx_oam; }; +#define YT921X_MIB_STAT_NUM (sizeof(struct yt921x_mib_stats) / sizeof(u64_stats_t)) + struct yt921x_mib { struct yt921x_port *port; struct delayed_work work; + struct u64_stats_sync syncp; + /* writers: priv->reg_lock + syncp; readers: priv->reg_lock or syncp */ struct yt921x_mib_stats stats; u64_stats_t rx_frames; u64_stats_t tx_frames; + /* protected by priv->reg_lock */ + u64 data[YT921X_MIB_STAT_NUM]; }; void yt921x_mib_poll(struct work_struct *work); From f3f5d7ab19b53b7a93584e5b16d5ec4c2fa9a06b Mon Sep 17 00:00:00 2001 From: Anton Danilov Date: Mon, 5 Oct 2026 22:12:27 +0300 Subject: [PATCH 1392/2126] ip6_gre: let collect_md ip6gretap send from the unspecified address ip6gre_xmit_ipv6() drops an IPv6 packet whose source address equals the tunnel remote, to avoid a trivial tunneling loop. On a collect_md ip6gretap device t->parms.raddr is not the exit point: the outer destination comes from the per-packet tunnel metadata. Such devices are normally created without a remote, so raddr is ::, and the check never matches a real tunnel endpoint. It matches every frame sent from the unspecified address instead. On an L2 tunnel those frames are regular link traffic. Duplicate Address Detection sends its Neighbor Solicitations from :: (RFC 4862, section 5.4.2), and MLD reports are sent from :: while an interface has no link-local address yet (RFC 3590, section 4). Frames bridged into a collect_md ip6gretap device, e.g. with tc tunnel_key and mirred, are dropped even though they carry valid metadata, so DAD cannot detect a duplicate address on the other side of the tunnel. Skip the check for collect_md devices of type ARPHRD_ETHER. It stays for L3 ip6gre, where sending a packet with an unspecified source means forwarding it (RFC 4291, section 2.5.2), and for ip6gretap without collect_md. ip6erspan does not run this check in collect_md mode either. Signed-off-by: Anton Danilov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261005191227.894665-1-littlesmilingcloud@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6_gre.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 0392f6ba862b..bfef0631be19 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -828,7 +828,12 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev) __u32 mtu; int err; - if (ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr)) + /* The outer destination of a collect_md tunnel comes from the + * metadata, so raddr is not its exit point, and hosts on the link + * bridged into an L2 one do send from :: (DAD, early MLD). + */ + if (!(t->parms.collect_md && dev->type == ARPHRD_ETHER) && + ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr)) return -1; if (!t->parms.collect_md && From d5b2fb6761aeb78fc3eaba6da873c7eb7055fa86 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 5 Oct 2026 09:49:04 +0200 Subject: [PATCH 1393/2126] dt-bindings: net: realtek,rtl9301-mdio: restrict MDIO buses by family The Realtek Otto switch family provides different numbers of MDIO buses. RTL838x has one bus, RTL839x has two buses, and RTL930x/RTL931x have four buses. The binding currently accepts mdio-bus@0 through mdio-bus@3 for every supported compatible, allowing non-existent buses to be described for RTL838x and RTL839x devices. Select the permitted bus node names based on the controller compatible. Signed-off-by: Markus Stockhausen Acked-by: Conor Dooley Link: https://patch.msgid.link/20261005074908.1273383-2-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- .../bindings/net/realtek,rtl9301-mdio.yaml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml index 67e0b23a8470..7f5b4897487b 100644 --- a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml +++ b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml @@ -67,6 +67,30 @@ patternProperties: unevaluatedProperties: false +allOf: + - if: + properties: + compatible: + contains: + enum: + - realtek,rtl8380-mdio + - realtek,rtl8381-mdio + - realtek,rtl8382-mdio + then: + patternProperties: + '^mdio-bus@[1-3]$': false + - if: + properties: + compatible: + contains: + enum: + - realtek,rtl8391-mdio + - realtek,rtl8392-mdio + - realtek,rtl8393-mdio + then: + patternProperties: + '^mdio-bus@[2-3]$': false + required: - compatible - reg From dbaa9e9e05eba057b7f8dca270a9afe452f362af Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 5 Oct 2026 09:49:05 +0200 Subject: [PATCH 1394/2126] dt-bindings: net: realtek,rtl9301-mdio: add clock-frequency The Ethernet MDIO controllers in Realtek Otto switches support several MDC frequencies. Document the supported clock-frequency values: - RTL838x: 2.5 MHz or 10 MHz - RTL839x, RTL930x and RTL931x: 1.25 MHz, 2.5 MHz or 5 MHz RTL839x has a single frequency selector shared by both MDIO buses. Require explicitly specified frequencies to be identical and document that a bus without clock-frequency inherits the frequency selected by the other available bus. Use 2.5 MHz if neither bus specifies a frequency. There is neither an official documentation nor any obvious registers that indicate a dependency to one of the hardware clocks. The usable setup bits are more like hardcoded values than dividers. Without further details do not add a clock reference. Signed-off-by: Markus Stockhausen Acked-by: Conor Dooley Link: https://patch.msgid.link/20261005074908.1273383-3-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- .../bindings/net/realtek,rtl9301-mdio.yaml | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml index 7f5b4897487b..139190e3f900 100644 --- a/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml +++ b/Documentation/devicetree/bindings/net/realtek,rtl9301-mdio.yaml @@ -67,6 +67,10 @@ patternProperties: unevaluatedProperties: false +required: + - compatible + - reg + allOf: - if: properties: @@ -77,8 +81,16 @@ allOf: - realtek,rtl8381-mdio - realtek,rtl8382-mdio then: + properties: + mdio-bus@0: + properties: + clock-frequency: + enum: [2500000, 10000000] + default: 2500000 + patternProperties: '^mdio-bus@[1-3]$': false + - if: properties: compatible: @@ -89,11 +101,37 @@ allOf: - realtek,rtl8393-mdio then: patternProperties: + '^mdio-bus@[01]$': + properties: + clock-frequency: + enum: [1250000, 2500000, 5000000] + description: | + RTL839x has one clock selector shared by both MDIO buses. All explicitly + specified clock-frequency values must be identical. A bus without this + property inherits the shared frequency selected by another available bus. + If neither available bus specifies a frequency, 2500000 Hz is used. + '^mdio-bus@[2-3]$': false -required: - - compatible - - reg + - if: + properties: + compatible: + contains: + enum: + - realtek,rtl9301-mdio + - realtek,rtl9302b-mdio + - realtek,rtl9302c-mdio + - realtek,rtl9303-mdio + - realtek,rtl9311-mdio + - realtek,rtl9312-mdio + - realtek,rtl9313-mdio + then: + patternProperties: + '^mdio-bus@[0-3]$': + properties: + clock-frequency: + enum: [1250000, 2500000, 5000000] + default: 2500000 unevaluatedProperties: false From d2d69812552b15a9b59613a5d4427089d389dae2 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 5 Oct 2026 09:49:06 +0200 Subject: [PATCH 1395/2126] net: mdio: realtek-rtl9300: convert "fwnode" left-overs to "of" The latest developments of the MDIO driver consistently used the "of" API. Convert the remaining "fwnode" left-overs too. Also align the continuation line of otto_emdio_probe_one() with the opening parenthesis, as required by the kernel coding style. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261005074908.1273383-4-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index a6daf4a5a664..79422893cc85 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -123,7 +123,6 @@ #include #include #include -#include #include #define RTL8380_NUM_BUSES 1 @@ -837,14 +836,14 @@ static void otto_emdio_notify_phy_detach(struct phy_device *phydev) } static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv, - struct fwnode_handle *node) + struct device_node *node) { struct otto_emdio_chan *chan; struct mii_bus *bus; u32 mdio_bus; int err; - err = fwnode_property_read_u32(node, "reg", &mdio_bus); + err = of_property_read_u32(node, "reg", &mdio_bus); if (err) return dev_err_probe(dev, err, "undefined smi bus number\n"); @@ -871,7 +870,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", dev_name(dev), mdio_bus); - err = devm_of_mdiobus_register(dev, bus, to_of_node(node)); + err = devm_of_mdiobus_register(dev, bus, node); if (err) return dev_err_probe(dev, err, "cannot register MDIO bus\n"); @@ -907,8 +906,8 @@ static int otto_emdio_map_ports(struct device *dev) ports_dn = of_get_child_by_name(parent->of_node, "ethernet-ports"); if (!ports_dn) - return dev_err_probe(dev, -EINVAL, "%pfwP missing ethernet-ports\n", - dev_fwnode(parent)); + return dev_err_probe(dev, -EINVAL, "%pOFP missing ethernet-ports\n", + parent->of_node); for_each_available_child_of_node_scoped(ports_dn, port_dn) { ctrl_dn = NULL; @@ -1008,7 +1007,7 @@ static int otto_emdio_probe(struct platform_device *pdev) if (err) return err; - priv->info = device_get_match_data(dev); + priv->info = of_device_get_match_data(dev); priv->regmap = syscon_node_to_regmap(dev->parent->of_node); if (IS_ERR(priv->regmap)) return PTR_ERR(priv->regmap); @@ -1033,7 +1032,7 @@ static int otto_emdio_probe(struct platform_device *pdev) return dev_err_probe(dev, err, "failed to setup MDIO bus controller\n"); } - device_for_each_child_node_scoped(dev, child) { + for_each_available_child_of_node_scoped(dev->of_node, child) { err = otto_emdio_probe_one(dev, priv, child); if (err) return err; From 808c15994074145d12a1ee77a49d6151cb28a11a Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 5 Oct 2026 09:49:07 +0200 Subject: [PATCH 1396/2126] net: mdio: realtek-rtl9300: reject duplicate MDIO bus IDs The reg property identifies the hardware MDIO bus and is used as an index into the per-bus state. However, duplicate bus IDs are currently not rejected explicitly and only fail later during MDIO bus registration due to the duplicate bus ID. Keep track of successfully registered buses and reject a duplicate reg value before allocating another bus. For this use the already existing but currently unused priv->bus[] property. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261005074908.1273383-5-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 79422893cc85..63ffb7f82b98 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -851,6 +851,9 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv return dev_err_probe(dev, -EINVAL, "illegal (dangling) smi bus number %d\n", mdio_bus); + if (priv->bus[mdio_bus]) + return dev_err_probe(dev, -EINVAL, "duplicated smi bus number %d\n", mdio_bus); + bus = devm_mdiobus_alloc_size(dev, sizeof(*chan)); if (!bus) return -ENOMEM; @@ -874,6 +877,8 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv if (err) return dev_err_probe(dev, err, "cannot register MDIO bus\n"); + priv->bus[mdio_bus] = bus; + return 0; } From 72356fed7965b197551c9e723e652a07c8995bd3 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Mon, 5 Oct 2026 09:49:08 +0200 Subject: [PATCH 1397/2126] net: mdio: realtek-rtl9300: support non-default clock frequencies The Ethernet MDIO controllers in Realtek Otto switches use an MDC clock frequency of 2.5 MHz by default. Hardware configuration fields allow the following frequencies to be selected: - RTL838x: 2.5 MHz or 10 MHz - RTL839x, RTL930x and RTL931x: 1.25 MHz, 2.5 MHz or 5 MHz Add support for configuring the MDC frequency through the clock-frequency property of each MDIO bus node. Lower frequencies can simplify protocol analysis with a logic analyzer, while higher frequencies reduce MDIO transaction times during normal operation. Program the frequency selector during every probe. If clock-frequency is absent, select the defined default of 2.5 MHz. This matches the configuration observed with a protocol analyzer under the stock firmware or after issuing "rtk network on" in the bootloader. RTL839x is an exception because both MDIO buses share a single frequency field. Use an explicitly specified frequency as the shared frequency and let buses without the property inherit it. Use the 2.5 MHz default if neither bus specifies a frequency. Reject conflicting explicit frequencies because the hardware cannot configure them independently. Signed-off-by: Markus Stockhausen Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261005074908.1273383-6-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-realtek-rtl9300.c | 100 +++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 63ffb7f82b98..eb7a6238dbd1 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -129,6 +129,7 @@ #define RTL8380_NUM_PAGES 4096 #define RTL8380_NUM_PORTS 28 #define RTL8380_SMI_GLB_CTRL 0xa100 +#define RTL8380_SMI_FREQ_SEL BIT(1) #define RTL8380_SMI_PHY_PATCH_DONE BIT(15) #define RTL8380_SMI_ACCESS_PHY_CTRL_0 0xa1b8 #define RTL8380_SMI_ACCESS_PHY_CTRL_1 0xa1bc @@ -168,12 +169,15 @@ #define RTL8390_PHYREG_PORT_CTRL_LOW 0x03e4 #define RTL8390_PHYREG_PORT_CTRL_HIGH 0x03e8 #define RTL8390_SMI_PORT_POLLING_CTRL 0x03fc +#define RTL8390_SMI_GLB_CTRL 0x03f8 +#define RTL8390_SMI_FREQ_SEL GENMASK(6, 5) #define RTL9300_NUM_BUSES 4 #define RTL9300_NUM_PAGES 4096 #define RTL9300_NUM_PORTS 28 #define RTL9300_SMI_GLB_CTRL 0xca00 #define RTL9300_GLB_CTRL_INTF_SEL(intf) BIT(16 + (intf)) +#define RTL9300_SMI_FREQ_SEL(intf) GENMASK((intf) * 2 + 9, (intf) * 2 + 8) #define RTL9300_SMI_PORT0_15_POLLING_SEL 0xca08 #define RTL9300_SMI_ACCESS_PHY_CTRL_0 0xcb70 #define RTL9300_SMI_ACCESS_PHY_CTRL_1 0xcb74 @@ -195,6 +199,8 @@ #define RTL9310_NUM_BUSES 4 #define RTL9310_NUM_PAGES 8192 #define RTL9310_NUM_PORTS 56 +#define RTL9310_SMI_GLB_CTRL0 0x0cc0 +#define RTL9310_SMI_FREQ_SEL(intf) GENMASK((intf) * 2 + 5, (intf) * 2 + 4) #define RTL9310_SMI_GLB_CTRL1 0x0cbc #define RTL9310_SMI_GLB_FMT_SEL_C45(intf) BIT((intf) * 2 + 1) #define RTL9310_SMI_INDRT_ACCESS_CTRL_0 0x0c00 @@ -270,6 +276,7 @@ struct otto_emdio_info { u8 num_ports; u16 num_pages; u32 poll_ctrl; + int (*set_bus_frequency)(struct mii_bus *bus, u32 freq); int (*setup_controller)(struct otto_emdio_priv *priv); int (*read_c22)(struct mii_bus *bus, int port, int regnum, u32 *value); int (*read_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u32 *value); @@ -745,6 +752,17 @@ static int otto_emdio_setup_topology(struct otto_emdio_priv *priv) return 0; } +static int otto_emdio_8380_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + + if (freq != 2500000 && freq != 10000000) + return -EINVAL; + + return regmap_assign_bits(priv->regmap, RTL8380_SMI_GLB_CTRL, + RTL8380_SMI_FREQ_SEL, freq == 10000000); +} + static int otto_emdio_8380_setup_controller(struct otto_emdio_priv *priv) { /* @@ -754,6 +772,60 @@ static int otto_emdio_8380_setup_controller(struct otto_emdio_priv *priv) return regmap_set_bits(priv->regmap, RTL8380_SMI_GLB_CTRL, RTL8380_SMI_PHY_PATCH_DONE); } +static int otto_emdio_8390_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + u32 mdio_bus, child_freq, val; + bool freq_set = false; + int err; + + /* + * RTL839x uses one frequency shared by both MDIO buses. Use the frequency passed by the + * caller as fallback, but prefer an explicitly requested frequency from any valid, + * available bus. Reject conflicting explicit requests. Only the first call programs the + * shared frequency. + */ + if (priv->bus[0] || priv->bus[1]) + return 0; + + for_each_available_child_of_node_scoped(bus->parent->of_node, child) { + err = of_property_read_u32(child, "reg", &mdio_bus); + if (err || mdio_bus >= priv->info->num_buses) + continue; + + if (of_property_read_u32(child, "clock-frequency", &child_freq)) + continue; + + if (freq_set && freq != child_freq) + return -EINVAL; + + freq = child_freq; + freq_set = true; + } + + if (freq != 1250000 && freq != 2500000 && freq != 5000000) + return -EINVAL; + + val = FIELD_PREP(RTL8390_SMI_FREQ_SEL, freq / 2500000); + + return regmap_update_bits(priv->regmap, RTL8390_SMI_GLB_CTRL, RTL8390_SMI_FREQ_SEL, val); +} + +static int otto_emdio_9300_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_chan *chan = bus->priv; + u32 mask, val; + + if (freq != 1250000 && freq != 2500000 && freq != 5000000) + return -EINVAL; + + mask = RTL9300_SMI_FREQ_SEL(chan->mdio_bus); + val = field_prep(mask, freq / 2500000); + + return regmap_update_bits(priv->regmap, RTL9300_SMI_GLB_CTRL, mask, val); +} + static int otto_emdio_9300_setup_controller(struct otto_emdio_priv *priv) { u32 glb_ctrl_mask = 0, glb_ctrl_val = 0; @@ -774,6 +846,21 @@ static int otto_emdio_9300_setup_controller(struct otto_emdio_priv *priv) return 0; } +static int otto_emdio_9310_set_bus_frequency(struct mii_bus *bus, u32 freq) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + struct otto_emdio_chan *chan = bus->priv; + u32 mask, val; + + if (freq != 1250000 && freq != 2500000 && freq != 5000000) + return -EINVAL; + + mask = RTL9310_SMI_FREQ_SEL(chan->mdio_bus); + val = field_prep(mask, freq / 2500000); + + return regmap_update_bits(priv->regmap, RTL9310_SMI_GLB_CTRL0, mask, val); +} + static int otto_emdio_9310_setup_controller(struct otto_emdio_priv *priv) { int i, err; @@ -840,7 +927,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv { struct otto_emdio_chan *chan; struct mii_bus *bus; - u32 mdio_bus; + u32 mdio_bus, freq; int err; err = of_property_read_u32(node, "reg", &mdio_bus); @@ -873,6 +960,13 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", dev_name(dev), mdio_bus); + if (of_property_read_u32(node, "clock-frequency", &freq)) + freq = 2500000; + err = priv->info->set_bus_frequency(bus, freq); + if (err) + return dev_err_probe(dev, err, "cannot set frequency %u for MDIO bus %d\n", + freq, mdio_bus); + err = devm_of_mdiobus_register(dev, bus, node); if (err) return dev_err_probe(dev, err, "cannot register MDIO bus\n"); @@ -1061,6 +1155,7 @@ static const struct otto_emdio_info otto_emdio_8380_info = { .num_pages = RTL8380_NUM_PAGES, .num_ports = RTL8380_NUM_PORTS, .poll_ctrl = RTL8380_SMI_POLL_CTRL, + .set_bus_frequency = otto_emdio_8380_set_bus_frequency, .setup_controller = otto_emdio_8380_setup_controller, .read_c22 = otto_emdio_8380_read_c22, .read_c45 = otto_emdio_8380_read_c45, @@ -1085,6 +1180,7 @@ static const struct otto_emdio_info otto_emdio_8390_info = { .num_pages = RTL8390_NUM_PAGES, .num_ports = RTL8390_NUM_PORTS, .poll_ctrl = RTL8390_SMI_PORT_POLLING_CTRL, + .set_bus_frequency = otto_emdio_8390_set_bus_frequency, .read_c22 = otto_emdio_8390_read_c22, .read_c45 = otto_emdio_8390_read_c45, .write_c22 = otto_emdio_8390_write_c22, @@ -1107,6 +1203,7 @@ static const struct otto_emdio_info otto_emdio_9300_info = { .num_ports = RTL9300_NUM_PORTS, .num_pages = RTL9300_NUM_PAGES, .poll_ctrl = RTL9300_SMI_POLL_CTRL, + .set_bus_frequency = otto_emdio_9300_set_bus_frequency, .setup_controller = otto_emdio_9300_setup_controller, .read_c22 = otto_emdio_9300_read_c22, .read_c45 = otto_emdio_9300_read_c45, @@ -1133,6 +1230,7 @@ static const struct otto_emdio_info otto_emdio_9310_info = { .num_pages = RTL9310_NUM_PAGES, .num_ports = RTL9310_NUM_PORTS, .poll_ctrl = RTL9310_SMI_PORT_POLLING_CTRL, + .set_bus_frequency = otto_emdio_9310_set_bus_frequency, .setup_controller = otto_emdio_9310_setup_controller, .read_c22 = otto_emdio_9310_read_c22, .read_c45 = otto_emdio_9310_read_c45, From 04a943067baa670fef3c1424ea616a2ed87d3d19 Mon Sep 17 00:00:00 2001 From: Vineeth Karumanchi Date: Mon, 5 Oct 2026 16:38:55 +0530 Subject: [PATCH 1398/2126] net: macb: configure ENST registers for all queues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a taprio config only covered a subset of queues, the driver programmed the ENST registers only for the queues named in the config and left the remaining queues holding stale register values. This produced an inconsistent hardware setup that affected the scheduling of the configured queues. This was observed on a GEM instance with four hardware queues, all enabled: Initial configuration: - All four queues are enabled. - enst_on_time_qX registers are left at their reset value (0x0001FFFF). - Only q0 and q1 are configured with valid, non-overlapping ENST schedules (T0 and T1 respectively). - Traffic streams p0 and p1 are bound to q0 and q1. - ENST is enabled only on q0 and q1. Observed behavior: - During T0 on-time, both p0 and p1 packets are transmitted. - During T1 on-time, both p0 and p1 packets are transmitted. With the unused queues (q2 and q3) explicitly programmed with enst_on_time = 0x0: - During T0 on-time, only p0 packets are transmitted. - During T1 on-time, only p1 packets are transmitted. Leaving the ENST on-time registers of unused queues at their reset value (0x0001FFFF) disrupts the scheduling of the configured queues, whereas programming them with 0x0 yields the expected ENST operation. Program the ENST registers for every queue unconditionally. The per-queue configuration array is now allocated for bp->num_queues and indexed directly by queue_id; unconfigured queues are left zero-initialized by kzalloc_objs(), so their registers are cleared. Indexing the array by queue_id also makes the queue_id field in struct macb_queue_enst_config redundant, so drop it. Fixes: 89934dbf169e ("net: macb: Add TAPRIO traffic scheduling support") Reviewed-by: Théo Lebrun Signed-off-by: Vineeth Karumanchi Reviewed-by: Jacob Keller Link: https://patch.msgid.link/20261005110855.1669249-1-vineeth.karumanchi@amd.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/cadence/macb.h | 2 -- drivers/net/ethernet/cadence/macb_main.c | 20 +++++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 1cb2778fe49e..82499ec6a9f0 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1498,7 +1498,6 @@ struct macb_platform_data { * @start_time_mask: Bitmask representing the start time for the queue * @on_time_bytes: "on" time nsec expressed in bytes * @off_time_bytes: "off" time nsec expressed in bytes - * @queue_id: Identifier for the queue * * This structure holds the configuration parameters for an ENST queue, * used to control time-based transmission scheduling in the MACB driver. @@ -1507,7 +1506,6 @@ struct macb_queue_enst_config { u32 start_time_mask; u32 on_time_bytes; u32 off_time_bytes; - u8 queue_id; }; #endif /* _MACB_H */ diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index c4223ca848df..e95aa9c00888 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -4421,7 +4421,7 @@ static int macb_taprio_setup_replace(struct net_device *netdev, struct macb_queue *queue; u32 queue_mask; u8 queue_id; - size_t i; + size_t i, q; int err; if (conf->num_entries > bp->num_queues) { @@ -4449,7 +4449,7 @@ static int macb_taprio_setup_replace(struct net_device *netdev, return -EINVAL; } - enst_queue = kzalloc_objs(*enst_queue, conf->num_entries); + enst_queue = kzalloc_objs(*enst_queue, bp->num_queues); if (unlikely(!enst_queue)) return -ENOMEM; @@ -4508,13 +4508,12 @@ static int macb_taprio_setup_replace(struct net_device *netdev, goto cleanup; } - enst_queue[i].queue_id = queue_id; - enst_queue[i].start_time_mask = + enst_queue[queue_id].start_time_mask = (start_time_sec << GEM_START_TIME_SEC_OFFSET) | start_time_nsec; - enst_queue[i].on_time_bytes = + enst_queue[queue_id].on_time_bytes = enst_ns_to_hw_units(entry->interval, speed); - enst_queue[i].off_time_bytes = + enst_queue[queue_id].off_time_bytes = enst_ns_to_hw_units(conf->cycle_time - entry->interval, speed); configured_queues |= entry->gate_mask; @@ -4540,15 +4539,14 @@ static int macb_taprio_setup_replace(struct net_device *netdev, gem_writel(bp, ENST_CONTROL, queue_mask << GEM_ENST_DISABLE_QUEUE_OFFSET); - for (i = 0; i < conf->num_entries; i++) { - queue = &bp->queues[enst_queue[i].queue_id]; + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { /* Configure queue timing registers */ queue_writel(queue, ENST_START_TIME, - enst_queue[i].start_time_mask); + enst_queue[q].start_time_mask); queue_writel(queue, ENST_ON_TIME, - enst_queue[i].on_time_bytes); + enst_queue[q].on_time_bytes); queue_writel(queue, ENST_OFF_TIME, - enst_queue[i].off_time_bytes); + enst_queue[q].off_time_bytes); } /* Enable ENST for all configured queues in one write */ From 9142c2f8f84bf4eafe23e9d68b6ba016a60300c0 Mon Sep 17 00:00:00 2001 From: Emanuele Rocca Date: Mon, 5 Oct 2026 18:21:37 +0200 Subject: [PATCH 1399/2126] octeontx2: use arch_extension to enable LSE Instead of using ".cpu generic+lse", use ".arch_extension lse" to enable LSE. The ".cpu generic+lse" directive replaces the assembler's current feature set with generic+lse, dropping other previously enabled features. In contrast, ".arch_extension lse" enables LSE while preserving the current feature set. For example, the following code is rejected with "selected processor does not support retaa", because ".cpu generic+lse" drops PAuth even though it was enabled by armv9-a: .arch armv9-a .text .cpu generic+lse retaa We encountered this issue while building the kernel with GCC configured using --with-arch=armv9-a. Since Armv9-A includes pointer authentication, GCC can assume that PAuth instructions are available and may use retaa when generating PAuth-protected returns. Signed-off-by: Emanuele Rocca Link: https://patch.msgid.link/20261005162137.71397-1-emanuele.rocca@arm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h | 2 +- include/linux/soc/marvell/octeontx2/asm.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h index fda6c4487c4f..3c7275d545bb 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h @@ -785,7 +785,7 @@ static inline u64 otx2_atomic64_add(u64 incr, void __iomem *addr) u64 __iomem *ptr = addr; u64 result; - __asm__ volatile(".cpu generic+lse\n" + __asm__ volatile(".arch_extension lse\n" "ldadd %x[i], %x[r], [%[b]]" : [r]"=r"(result), "+m"(*ptr) : [i]"r"(incr), [b]"r"(ptr) diff --git a/include/linux/soc/marvell/octeontx2/asm.h b/include/linux/soc/marvell/octeontx2/asm.h index d683251a0b40..8b572d3d741c 100644 --- a/include/linux/soc/marvell/octeontx2/asm.h +++ b/include/linux/soc/marvell/octeontx2/asm.h @@ -17,7 +17,7 @@ #define otx2_lmt_flush(ioaddr) \ ({ \ u64 result = 0; \ - __asm__ volatile(".cpu generic+lse\n" \ + __asm__ volatile(".arch_extension lse\n" \ "ldeor xzr, %x[rf], [%[rs]]" \ : [rf]"=r" (result) \ : [rs]"r" (ioaddr)); \ @@ -30,7 +30,7 @@ */ #define cn10k_lmt_flush(val, addr) \ ({ \ - __asm__ volatile(".cpu generic+lse\n" \ + __asm__ volatile(".arch_extension lse\n" \ "steorl %x[rf],[%[rs]]" \ : [rf] "+r"(val) \ : [rs] "r"(addr)); \ @@ -40,7 +40,7 @@ static inline u64 otx2_atomic64_fetch_add(u64 incr, u64 *ptr) { u64 result; - asm volatile (".cpu generic+lse\n" + asm volatile (".arch_extension lse\n" "ldadda %x[i], %x[r], [%[b]]" : [r] "=r" (result), "+m" (*ptr) : [i] "r" (incr), [b] "r" (ptr) From f688218baa7128a1ef3f8377679fc5fcbc22fa2e Mon Sep 17 00:00:00 2001 From: Rokas Juras Date: Mon, 5 Oct 2026 10:48:52 +0300 Subject: [PATCH 1400/2126] rndis_host: enable RX aggregation for OnePlus Nord CE 2 USB tethering on the OnePlus Nord CE 2 (IV2201, USB ID 22d9:2766) running Android 13 has download speeds of approximately 2mbps with the default 2048-byte receive limit. The phone's published RNDIS code only enables packet batching when the computer reports a receive limit above 2048 bytes. Testing shows that increasing this limit to 2560 bytes restores normal speeds. Add a quirk for USB device 22d9:2766 to use and advertise a receive buffer of at least 16 KiB. This fits the phone code's default batch of ten packets at a 1500-byte MTU. Tested on 7.3.0-rc5 with the affected phone, including reconnecting USB tethering. Download speeds with the change exceed 100mpbs. Link: https://github.com/OnePlusOSS/android_kernel_oneplus_mt6877/blob/3c1e3d432d0c35afa7fded974b50fa6617219e0f/drivers/usb/gadget/function/f_rndis.c#L538-L551 Link: https://github.com/OnePlusOSS/android_kernel_oneplus_mt6877/blob/3c1e3d432d0c35afa7fded974b50fa6617219e0f/drivers/usb/gadget/function/u_ether.c#L869-L874 Signed-off-by: Rokas Juras Link: https://patch.msgid.link/20261005074852.76818-1-asrokasjuras@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/rndis_host.c | 21 +++++++++++++++++++++ include/linux/usb/rndis_host.h | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c index 37d4865f5c5e..b001bc83475a 100644 --- a/drivers/net/usb/rndis_host.c +++ b/drivers/net/usb/rndis_host.c @@ -345,6 +345,11 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags) dev->rx_urb_size = dev->hard_mtu + (dev->maxpacket + 1); dev->rx_urb_size &= ~(dev->maxpacket - 1); + + /* some devices require a receive limit above 2048 for RX aggregation */ + if (dev->driver_info->data & RNDIS_DRIVER_DATA_RX_AGGREGATION) + dev->rx_urb_size = max_t(size_t, dev->rx_urb_size, 16 * 1024); + u.init->max_transfer_size = cpu_to_le32(dev->rx_urb_size); net->netdev_ops = &rndis_netdev_ops; @@ -612,6 +617,17 @@ static const struct driver_info rndis_info = { .tx_fixup = rndis_tx_fixup, }; +static const struct driver_info rndis_rx_aggregation_info = { + .description = "RNDIS device", + .flags = FLAG_ETHER | FLAG_POINTTOPOINT | FLAG_FRAMING_RN | FLAG_NO_SETINT, + .data = RNDIS_DRIVER_DATA_RX_AGGREGATION, + .bind = rndis_bind, + .unbind = rndis_unbind, + .status = rndis_status, + .rx_fixup = rndis_rx_fixup, + .tx_fixup = rndis_tx_fixup, +}; + static const struct driver_info rndis_poll_status_info = { .description = "RNDIS device (poll status before control)", .flags = FLAG_ETHER | FLAG_POINTTOPOINT | FLAG_FRAMING_RN | FLAG_NO_SETINT, @@ -649,6 +665,11 @@ static const struct driver_info rndis_info_lowpower = { static const struct usb_device_id products [] = { { + /* OnePlus Nord CE 2 */ + USB_DEVICE_AND_INTERFACE_INFO(0x22d9, 0x2766, + USB_CLASS_WIRELESS_CONTROLLER, 1, 3), + .driver_info = (unsigned long)&rndis_rx_aggregation_info, +}, { /* 2Wire HomePortal 1000SW */ USB_DEVICE_AND_INTERFACE_INFO(0x1630, 0x0042, USB_CLASS_COMM, 2 /* ACM */, 0x0ff), diff --git a/include/linux/usb/rndis_host.h b/include/linux/usb/rndis_host.h index 489cfb1d00f6..3eaf57a9b282 100644 --- a/include/linux/usb/rndis_host.h +++ b/include/linux/usb/rndis_host.h @@ -182,8 +182,9 @@ struct rndis_keepalive_c { /* IN (optionally OUT) */ #define FLAG_RNDIS_PHYM_WIRELESS 0x0002 /* Flags for driver_info::data */ -#define RNDIS_DRIVER_DATA_POLL_STATUS 1 /* poll status before control */ -#define RNDIS_DRIVER_DATA_DST_MAC_FIXUP 2 /* device ignores configured MAC address */ +#define RNDIS_DRIVER_DATA_POLL_STATUS 1 /* poll status before control */ +#define RNDIS_DRIVER_DATA_DST_MAC_FIXUP 2 /* device ignores configured MAC address */ +#define RNDIS_DRIVER_DATA_RX_AGGREGATION 4 /* needs RX limit > 2048 */ extern void rndis_status(struct usbnet *dev, struct urb *urb); extern int From 9823271dbe1e43d1b7eb7707412d96317fb284d5 Mon Sep 17 00:00:00 2001 From: Timur Stukan Date: Tue, 6 Oct 2026 13:32:07 +0300 Subject: [PATCH 1401/2126] bonding: 3ad: remove unused TX state The sm_tx_state field of struct port and tx_states_t enum were introduced in the initial 802.3ad implementation but have never had any users. The TX machine uses ntt and sm_tx_timer_counter instead. Remove them. Signed-off-by: Timur Stukan Reviewed-by: Fernando Fernandez Mancera Link: https://patch.msgid.link/20261006103207.68974-1-timur.stukan.linux@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/bonding/bond_3ad.c | 1 - include/net/bond_3ad.h | 7 ------- 2 files changed, 8 deletions(-) diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index b8e4b4d68dd6..d91533b80996 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -2071,7 +2071,6 @@ static void ad_initialize_port(struct port *port, const struct bond_params *bond port->sm_periodic_timer_counter = 0; port->sm_mux_state = 0; port->sm_mux_timer_counter = 0; - port->sm_tx_state = 0; port->aggregator = NULL; port->next_port_in_aggregator = NULL; port->transaction_id = 0; diff --git a/include/net/bond_3ad.h b/include/net/bond_3ad.h index ef667dff2972..9e548d3dca21 100644 --- a/include/net/bond_3ad.h +++ b/include/net/bond_3ad.h @@ -60,12 +60,6 @@ typedef enum { AD_MUX_COLLECTING_DISTRIBUTING /* mux machine */ } mux_states_t; -/* tx machine states(43.4.15 in the 802.3ad standard) */ -typedef enum { - AD_TX_DUMMY, - AD_TRANSMIT /* tx Machine */ -} tx_states_t; - /* churn machine states(43.4.17 in the 802.3ad standard) */ typedef enum { AD_CHURN_MONITOR, /* monitoring for churn */ @@ -231,7 +225,6 @@ typedef struct port { u16 sm_periodic_timer_counter; /* state machine periodic timer counter */ mux_states_t sm_mux_state; /* state machine mux state */ u16 sm_mux_timer_counter; /* state machine mux timer counter */ - tx_states_t sm_tx_state; /* state machine tx state */ u16 sm_tx_timer_counter; /* state machine tx timer counter * (always on - enter to transmit * state 3 time per second) From f91afd7f713309d97427bdf0c9301fd5133a26ba Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Tue, 6 Oct 2026 06:17:49 +0800 Subject: [PATCH 1402/2126] net: stmmac: move XPCS lifetime management to platform drivers The current XPCS creation logic in stmmac_pcs_setup() is problematic for several reasons. First, if a device tree specifies a "pcs-handle" but no select_pcs() callback is provided by the platform driver, the created XPCS cannot be used by phylink for PCS operations. The framework requires select_pcs() to return the PCS to the core, so the pcs-handle property becomes effectively useless for link management without the matching callback. The XPCS is still consulted by stmmac_phylink_setup() and stmmac_init_phy(), which makes the configuration silently half-working rather than clearly broken. Second, and more critically, when a platform driver sets pcs_init() and creates an XPCS inside that callback, the common code afterwards still runs unconditionally and overwrites priv->hw->xpcs with the local xpcs variable, which stays NULL. The platform driver has no way to prevent this override because the common code runs after the platform-specific initialization. After commit 93f84152e4ae ("net: stmmac: clean up stmmac_mac_select_pcs()"), the common code no longer falls back to priv->hw->phylink_pcs if select_pcs() is not set. This change reinforces that each platform must manage its own PCS life cycle explicitly, but the XPCS creation code in stmmac_pcs_setup() was not updated to match this new expectation, leaving a gap where platform drivers have no clean way to take control of XPCS creation. Address all of these issues by simplifying the existing pcs_init() and pcs_exit() dispatch in stmmac_pcs_setup() and stmmac_pcs_clean(). The common stmmac_pcs_setup() now calls plat->pcs_init() if present, and stmmac_pcs_clean() calls plat->pcs_exit() if present, removing the confusing and error-prone XPCS creation logic from the common code. Platforms that do not need an XPCS simply leave the callbacks as NULL and no change in behavior occurs. Platforms that do need an XPCS can now create it with the exact configuration they require, including wrapping it with custom phylink_pcs_ops when necessary. Note that this also removes the generic "pcs-handle" parsing from the common code. A glue that does not set pcs_init() now leaves priv->hw->xpcs as NULL, and "pcs-handle" becomes a no-op for it. No in-tree platform relies on this path: every DTS that pairs a dwmac node with a PCS goes through a glue that sets pcs_init() (Intel, Renesas, RZ/N1, SoCFPGA, Rockchip). The Intel mGbE glue is updated to create its XPCS inside its own pcs_init() implementation, and the renesas-gbeth, rzn1 and socfpga pcs_exit() callbacks now explicitly clear priv->hw->phylink_pcs after destroying the PCS to avoid dangling pointer references. Reviewed-by: Maxime Chevallier Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261005221749.1104430-1-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 44 +++++++++++++++++-- .../stmicro/stmmac/dwmac-renesas-gbeth.c | 7 ++- .../net/ethernet/stmicro/stmmac/dwmac-rzn1.c | 7 ++- .../ethernet/stmicro/stmmac/dwmac-socfpga.c | 7 ++- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 37 +++------------- 5 files changed, 61 insertions(+), 41 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c index f5f9fa67ecd7..4308dccbf257 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c @@ -603,13 +603,47 @@ static void common_default_data(struct plat_stmmacenet_data *plat) plat->mdio_bus_data->needs_reset = true; } +static int intel_mgbe_pcs_init(struct stmmac_priv *priv) +{ + struct fwnode_handle *devnode, *pcsnode; + struct dw_xpcs *xpcs; + int addr; + + devnode = dev_fwnode(priv->device); + + if (fwnode_property_present(devnode, "pcs-handle")) { + pcsnode = fwnode_find_reference(devnode, "pcs-handle", 0); + xpcs = xpcs_create_fwnode(pcsnode); + fwnode_handle_put(pcsnode); + } else { + addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1; + xpcs = xpcs_create_mdiodev(priv->mii, addr); + } + + if (IS_ERR(xpcs)) + return PTR_ERR(xpcs); + + xpcs_config_eee_mult_fact(xpcs, priv->plat->mult_fact_100ns); + + priv->hw->xpcs = xpcs; + return 0; +} + +static void intel_mgbe_pcs_exit(struct stmmac_priv *priv) +{ + if (!priv->hw->xpcs) + return; + + xpcs_destroy(priv->hw->xpcs); + priv->hw->xpcs = NULL; +} + static struct phylink_pcs *intel_mgbe_select_pcs(struct stmmac_priv *priv, phy_interface_t interface) { - /* plat->mdio_bus_data->has_xpcs has been set true, so there - * should always be an XPCS. The original code would always - * return this if present. - */ + if (!priv->hw->xpcs) + return NULL; + return xpcs_to_phylink_pcs(priv->hw->xpcs); } @@ -733,6 +767,8 @@ static int intel_mgbe_common_data(struct pci_dev *pdev, plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) { plat->mdio_bus_data->pcs_mask = BIT_U32(INTEL_MGBE_XPCS_ADDR); plat->default_an_inband = true; + plat->pcs_init = intel_mgbe_pcs_init; + plat->pcs_exit = intel_mgbe_pcs_exit; plat->select_pcs = intel_mgbe_select_pcs; } diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c index 19f34e18bfef..9af32c26f9c1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c @@ -81,8 +81,11 @@ static int renesas_gmac_pcs_init(struct stmmac_priv *priv) static void renesas_gmac_pcs_exit(struct stmmac_priv *priv) { - if (priv->hw->phylink_pcs) - miic_destroy(priv->hw->phylink_pcs); + if (!priv->hw->phylink_pcs) + return; + + miic_destroy(priv->hw->phylink_pcs); + priv->hw->phylink_pcs = NULL; } static struct phylink_pcs *renesas_gmac_select_pcs(struct stmmac_priv *priv, diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c index 13634965bc19..01df4776edb3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c @@ -35,8 +35,11 @@ static int rzn1_dwmac_pcs_init(struct stmmac_priv *priv) static void rzn1_dwmac_pcs_exit(struct stmmac_priv *priv) { - if (priv->hw->phylink_pcs) - miic_destroy(priv->hw->phylink_pcs); + if (!priv->hw->phylink_pcs) + return; + + miic_destroy(priv->hw->phylink_pcs); + priv->hw->phylink_pcs = NULL; } static struct phylink_pcs *rzn1_dwmac_select_pcs(struct stmmac_priv *priv, diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index 1d7f0a57d288..6d4bc1fe8f75 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -539,8 +539,11 @@ static int socfpga_dwmac_pcs_init(struct stmmac_priv *priv) static void socfpga_dwmac_pcs_exit(struct stmmac_priv *priv) { - if (priv->hw->phylink_pcs) - lynx_pcs_destroy(priv->hw->phylink_pcs); + if (!priv->hw->phylink_pcs) + return; + + lynx_pcs_destroy(priv->hw->phylink_pcs); + priv->hw->phylink_pcs = NULL; } static struct phylink_pcs *socfpga_dwmac_select_pcs(struct stmmac_priv *priv, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index afe98ff5bdcb..7396b68899c6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -426,35 +426,14 @@ int stmmac_mdio_reset(struct mii_bus *bus) int stmmac_pcs_setup(struct net_device *ndev) { struct stmmac_priv *priv = netdev_priv(ndev); - struct fwnode_handle *devnode, *pcsnode; - struct dw_xpcs *xpcs = NULL; - int addr, ret; + int ret; - devnode = dev_fwnode(priv->device); - - if (priv->plat->pcs_init) { - ret = priv->plat->pcs_init(priv); - } else if (fwnode_property_present(devnode, "pcs-handle")) { - pcsnode = fwnode_find_reference(devnode, "pcs-handle", 0); - xpcs = xpcs_create_fwnode(pcsnode); - fwnode_handle_put(pcsnode); - ret = PTR_ERR_OR_ZERO(xpcs); - } else if (priv->plat->mdio_bus_data && - priv->plat->mdio_bus_data->pcs_mask) { - addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1; - xpcs = xpcs_create_mdiodev(priv->mii, addr); - ret = PTR_ERR_OR_ZERO(xpcs); - } else { + if (!priv->plat->pcs_init) return 0; - } + ret = priv->plat->pcs_init(priv); if (ret) - return dev_err_probe(priv->device, ret, "No xPCS found\n"); - - if (xpcs) - xpcs_config_eee_mult_fact(xpcs, priv->plat->mult_fact_100ns); - - priv->hw->xpcs = xpcs; + return dev_err_probe(priv->device, ret, "Failed to initialize PCS\n"); return 0; } @@ -463,14 +442,10 @@ void stmmac_pcs_clean(struct net_device *ndev) { struct stmmac_priv *priv = netdev_priv(ndev); - if (priv->plat->pcs_exit) - priv->plat->pcs_exit(priv); - - if (!priv->hw->xpcs) + if (!priv->plat->pcs_exit) return; - xpcs_destroy(priv->hw->xpcs); - priv->hw->xpcs = NULL; + priv->plat->pcs_exit(priv); } struct stmmac_clk_rate { From 758fe10f83a655bed0f7b98fcfacdfc3556fb9a1 Mon Sep 17 00:00:00 2001 From: Jayaraj Devaraj Date: Tue, 6 Oct 2026 01:11:35 +0530 Subject: [PATCH 1403/2126] docs: oa-tc6-framework: Fix typo in SYNC bit description Fix a missing space in the SYNC bit description: "bitin" should be "bit in". Signed-off-by: Jayaraj Devaraj Link: https://patch.msgid.link/20261005194135.64584-1-jayarajdmit@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/networking/oa-tc6-framework.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/networking/oa-tc6-framework.rst b/Documentation/networking/oa-tc6-framework.rst index 0feda2f9d840..2545ef694016 100644 --- a/Documentation/networking/oa-tc6-framework.rst +++ b/Documentation/networking/oa-tc6-framework.rst @@ -278,7 +278,7 @@ SYNC (Bit 29) - Configuration Synchronized flag. This bit reflects the register (see Table 12). A zero indicates that the MAC-PHY configuration may not be as expected by the SPI host. Following configuration, the SPI host sets the - corresponding bitin the configuration register which is + corresponding bit in the configuration register which is reflected in this field. RCA (Bit 28..24) - Receive Chunks Available. The RCA field indicates to From 4b2f8de21708c02203a31e2e83f8240dbdc702e8 Mon Sep 17 00:00:00 2001 From: Vitor Soares Date: Tue, 22 Sep 2026 21:06:42 +0100 Subject: [PATCH 1404/2126] wifi: ath12k: advertise interface MAC address pool ath12k supports creating vdevs with addresses provided by mac80211. Userspace can already make concurrent interfaces work by explicitly assigning different locally administered addresses. However, ath12k does not advertise an address list, so when a second interface is created without an explicit address, mac80211 has nothing to pick from and falls back to the permanent address. If the first interface is already running with that address, bringing up the second one fails with -ENOTUNIQ. As in ath11k, provide a list of usable addresses so ieee80211_assign_perm_addr() can hand each new interface an unused one. Keep the first entry as the wiphy's permanent MAC address. Generate the remaining entries as locally administered variants by changing only the upper nibble of the first octet, which naturally limits the pool to 16 unique addresses. The cfg80211 definition of wiphy->addresses does not specify where the addresses must come from. Some ath12k platforms use it as an interface MAC address pool, while others use it for firmware-provided per-radio addresses. Gate the generated address pool behind advertise_iface_mac_pool and enable it for WCN7850 and QCC2072. The flag is read from the first radio, as all radios behind a wiphy are expected to have the same setting. Other platforms keep the existing behavior. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00074-QCACOLSWPL_V1_TO_SILICONZ-1 Assisted-by: LLM Signed-off-by: Vitor Soares Tested-by: Kang Yang Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260922200643.1133491-2-ivitro@gmail.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/hw.h | 1 + drivers/net/wireless/ath/ath12k/mac.c | 54 ++++++++++++++++++++++ drivers/net/wireless/ath/ath12k/wifi7/hw.c | 6 +++ 3 files changed, 61 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/hw.h b/drivers/net/wireless/ath/ath12k/hw.h index 1e652dc0d247..52558dd126a0 100644 --- a/drivers/net/wireless/ath/ath12k/hw.h +++ b/drivers/net/wireless/ath/ath12k/hw.h @@ -239,6 +239,7 @@ struct ath12k_hw_params { } client; bool host_alloc_ml_id; + bool advertise_iface_mac_pool; }; struct ath12k_hw_ops { diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 196b807210de..db6856ec6c14 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -14746,6 +14746,56 @@ static void ath12k_mac_cleanup_unregister(struct ath12k *ar) kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); } +static void ath12k_mac_cleanup_mac_address_list(struct ath12k_hw *ah) +{ + kfree(ah->hw->wiphy->addresses); + ah->hw->wiphy->addresses = NULL; + ah->hw->wiphy->n_addresses = 0; +} + +static void ath12k_mac_setup_mac_address_list(struct ath12k_hw *ah, + const u8 *mac_addr) +{ + struct mac_address *addresses; + struct ath12k *ar; + u16 n_addresses; + int i; + + /* + * wiphy->addresses is per wiphy, so the generated interface MAC + * pool is advertised for the whole ath12k_hw. The hw_params flag is + * expected to be consistent across all radios in an ath12k_hw, so + * use the first radio as the source. + */ + ar = ath12k_ah_to_ar(ah, 0); + if (!ar->ab->hw_params->advertise_iface_mac_pool) + return; + + /* + * Only the upper nibble of the first octet is varied, so at most 16 + * addresses can be derived from one base. + */ + n_addresses = min_t(u16, TARGET_NUM_VDEVS(ar->ab), 16); + if (n_addresses <= 1) + return; + + addresses = kzalloc_objs(*addresses, n_addresses); + if (!addresses) + return; + + ether_addr_copy(addresses[0].addr, mac_addr); + for (i = 1; i < n_addresses; i++) { + ether_addr_copy(addresses[i].addr, mac_addr); + /* set Local Administered Address bit */ + addresses[i].addr[0] |= 0x2; + + addresses[i].addr[0] += i << 4; + } + + ah->hw->wiphy->addresses = addresses; + ah->hw->wiphy->n_addresses = n_addresses; +} + static void ath12k_mac_hw_unregister(struct ath12k_hw *ah) { struct ieee80211_hw *hw = ah->hw; @@ -14765,6 +14815,7 @@ static void ath12k_mac_hw_unregister(struct ath12k_hw *ah) ath12k_mac_cleanup_unregister(ar); ath12k_mac_cleanup_iface_combinations(ah); + ath12k_mac_cleanup_mac_address_list(ah); SET_IEEE80211_DEV(hw, NULL); } @@ -14881,6 +14932,7 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) wiphy->available_antennas_tx = antennas_tx; SET_IEEE80211_PERM_ADDR(hw, mac_addr); + ath12k_mac_setup_mac_address_list(ah, mac_addr); SET_IEEE80211_DEV(hw, ab->dev); ret = ath12k_mac_setup_iface_combinations(ah); @@ -15123,6 +15175,8 @@ err_cleanup_unregister: ath12k_mac_cleanup_unregister(ar); } + ath12k_mac_cleanup_mac_address_list(ah); + SET_IEEE80211_DEV(hw, NULL); return ret; diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index aec7c652808c..b1c17cc197df 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -447,6 +447,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .advertise_iface_mac_pool = false, }, { .name = "wcn7850 hw2.0", @@ -542,6 +543,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .advertise_iface_mac_pool = true, }, { .name = "qcn9274 hw2.0", @@ -633,6 +635,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .advertise_iface_mac_pool = false, }, { .name = "ipq5332 hw1.0", @@ -718,6 +721,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .advertise_iface_mac_pool = false, }, { .name = "qcc2072 hw1.0", @@ -814,6 +818,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .advertise_iface_mac_pool = true, }, { .name = "ipq5424 hw1.0", @@ -902,6 +907,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .advertise_iface_mac_pool = false, }, }; From 86f2537877d6029487811bc3e0cd9e086a196000 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 18:19:43 +0800 Subject: [PATCH 1405/2126] wifi: ath12k: validate MAC/PHY capability count before saving Firmware supplies the hardware mode count and the PHY bitmap for each mode in the service-ready-ext event. ath12k_wmi_save_all_mac_phy_info() uses those bitmaps to populate svc_ext_info->mac_phy_info, but the destination is a fixed array of ATH12K_MAX_MAC_PHY_CAP elements. If the total number of advertised PHY entries exceeds that limit, the loop writes beyond mac_phy_info and corrupts adjacent memory. ath12k_wmi_mac_phy_caps_parse() allocates the source array for tot_phy_id entries and rejects excess capability TLVs. However, if the event contains fewer capability TLVs than advertised, the remaining allocated entries stay zeroed and are saved as invalid PHY information. After parsing the MAC/PHY capability TLVs, validate the destination capacity and reject an incomplete capability list before saving any entries. Fixes: 062ade23991e ("wifi: ath12k: parse and save hardware mode info from WMI_SERVICE_READY_EXT_EVENTID event for later use") Cc: stable@vger.kernel.org Signed-off-by: Jiale Yao Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20261003101944.596546-1-yaojiale02@163.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/wmi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c index 3149b6376c94..75b259990c79 100644 --- a/drivers/net/wireless/ath/ath12k/wmi.c +++ b/drivers/net/wireless/ath/ath12k/wmi.c @@ -5050,6 +5050,7 @@ static int ath12k_wmi_svc_rdy_ext_parse(struct ath12k_base *ab, u16 tag, u16 len, const void *ptr, void *data) { + struct ath12k_svc_ext_info *svc_ext_info = &ab->wmi_ab.svc_ext_info; struct ath12k_wmi_pdev *wmi_handle = &ab->wmi_ab.wmi[0]; struct ath12k_wmi_svc_rdy_ext_parse *svc_rdy_ext = data; int ret; @@ -5094,6 +5095,22 @@ static int ath12k_wmi_svc_rdy_ext_parse(struct ath12k_base *ab, return ret; } + if (svc_rdy_ext->tot_phy_id > + ARRAY_SIZE(svc_ext_info->mac_phy_info)) { + ath12k_warn(ab, "too many PHY entries %u (max %zu)\n", + svc_rdy_ext->tot_phy_id, + ARRAY_SIZE(svc_ext_info->mac_phy_info)); + return -EINVAL; + } + + if (svc_rdy_ext->n_mac_phy_caps < svc_rdy_ext->tot_phy_id) { + ath12k_warn(ab, + "not enough MAC/PHY caps %u, expected %u\n", + svc_rdy_ext->n_mac_phy_caps, + svc_rdy_ext->tot_phy_id); + return -EINVAL; + } + ath12k_wmi_save_all_mac_phy_info(ab, svc_rdy_ext); svc_rdy_ext->mac_phy_done = true; From 97aab70a03df478ffefcf890ed4be258c0240bcb Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 8 Oct 2026 16:56:45 +0200 Subject: [PATCH 1406/2126] wifi: ath6kl: don't take RTNL in del_virtual_intf cfg80211 already holds the RTNL here, so this will just deadlock. Remove the extra RTNL acquisition. Oddly enough this was all true even back when the locking here was added, so this is just a revert of a broken ~13 year old commit. Fixes: bc52aab380c7 ("ath6kl: Protect ath6kl_cfg80211_vif_cleanup using rtnl_locks") Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261008165646.48866f0521af.I1c166be830384473f67677eeb187afa7e54106ea@changeid Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath6kl/cfg80211.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c index a9a35476fecd..65b7c68a9297 100644 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c @@ -1560,9 +1560,7 @@ static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy, ath6kl_cfg80211_vif_stop(vif, test_bit(WMI_READY, &ar->flag)); - rtnl_lock(); ath6kl_cfg80211_vif_cleanup(vif); - rtnl_unlock(); return 0; } From f3d29dc9224b0881d10d34664456adf113bc4777 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:52 +0200 Subject: [PATCH 1407/2126] wifi: mac80211: clear fragment cache entry 'is_protected' In practice, we probably shouldn't end up with a fragmented frame that's protected, filled into the cache, finished or dropped and then the next frame is unprotected, since only unicast data frames can be fragmented. However, tools complain and it's more correct to be able to do this (e.g. an unencrypted fragmented EAPOL _could_, at least in theory, happen), so clear the flag when the entry is reused. Assisted-by: LLM Fixes: 7e44a0b597f0 ("mac80211: prevent attacks on TKIP/WEP as well") Link: https://patch.msgid.link/20261005224950.c3e4106f34d5.I866c0862db031c3a810d2333acdd22e2733d2b8c@changeid Signed-off-by: Johannes Berg --- net/mac80211/rx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index b06301c1e88b..ecee9348c70d 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -2284,6 +2284,7 @@ ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache, entry->rx_queue = rx_queue; entry->last_frag = frag; entry->check_sequential_pn = false; + entry->is_protected = false; entry->extra_len = 0; return entry; From 2ce8b78102e91c9d6536630cdef96491121c84d3 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:53 +0200 Subject: [PATCH 1408/2126] wifi: mac80211: mesh: use hlist_add_head_rcu() The mesh paths walk list used under RCU, so we must use hlist_add_head_rcu() to publish an entry. Fix one place that didn't do that. Assisted-by: LLM Fixes: b4c3fbe63601 ("mac80211: Use linked list instead of rhashtable walk for mesh tables") Link: https://patch.msgid.link/20261005224950.e0db543145e1.Ieaf30d3546e8ff63ccf400f6fb26e027c218721f@changeid Signed-off-by: Johannes Berg --- net/mac80211/mesh_pathtbl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c index 7b2f71186dfb..0485a979b3c2 100644 --- a/net/mac80211/mesh_pathtbl.c +++ b/net/mac80211/mesh_pathtbl.c @@ -712,7 +712,7 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata, &new_mpath->rhash, mesh_rht_params); if (!mpath) - hlist_add_head(&new_mpath->walk_list, &tbl->walk_head); + hlist_add_head_rcu(&new_mpath->walk_list, &tbl->walk_head); spin_unlock_bh(&tbl->walk_lock); if (mpath) { From 8ea4f50c3426aaaf3f4c118ee2c2876326ca5db5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:54 +0200 Subject: [PATCH 1409/2126] wifi: mac80211: kill wake_txqs_tasklet on unregistration We never kill the wake_txqs_tasklet so it could be running while the hardware is being freed. Kill it, late enough to never be able to restart afterwards. Assisted-by: LLM Fixes: 21a5d4c3a45c ("mac80211: add stop/start logic for software TXQs") Link: https://patch.msgid.link/20261005224950.3fdb8d0ff377.I851e79ac625c4926e211642ee7a7e458728b0ad3@changeid Signed-off-by: Johannes Berg --- net/mac80211/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index b889d2a7ef75..ad7dfc07ee63 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1738,6 +1738,8 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw) cancel_work_sync(&local->restart_work); + tasklet_kill(&local->wake_txqs_tasklet); + ieee80211_clear_tx_pending(local); rate_control_deinitialize(local); From c767e1173aeab7825a8dfb197041d3996db84e39 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:55 +0200 Subject: [PATCH 1410/2126] wifi: nl80211: reject zero RNR/MBSSID elements That's a nonsensical configuration, and we get errors reported further down in mac80211 for it; hostapd has code that only adds the nested element if it'll not be an empty list. Remove an unnecessary NULL check while at it. Fixes: dbbb27e183b1 ("cfg80211: support RNR for EMA AP") Assisted-by: LLM Link: https://patch.msgid.link/20261005224950.97db49d9d104.I5765a3310528b3d1cb1673dc90ad5ab5fc3ea571@changeid Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 7ee69ec10b0f..9c2d5c89598b 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -6582,6 +6582,9 @@ nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs, num_elems++; } + if (!num_elems) + return ERR_PTR(-EINVAL); + elems = kzalloc_flex(*elems, elem, num_elems); if (!elems) return ERR_PTR(-ENOMEM); @@ -6617,6 +6620,9 @@ nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs, num_elems++; } + if (!num_elems) + return ERR_PTR(-EINVAL); + elems = kzalloc_flex(*elems, elem, num_elems); if (!elems) return ERR_PTR(-ENOMEM); @@ -6860,7 +6866,8 @@ static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, if (IS_ERR(rnr)) return PTR_ERR(rnr); - if (rnr && rnr->cnt < bcn->mbssid_ies->cnt) { + /* RNR elements are only used with MBSSID elements */ + if (rnr->cnt < bcn->mbssid_ies->cnt) { kfree(rnr); return -EINVAL; } From e3cf8da7e0c560db67ac5ee8c9197514bb298ea7 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:56 +0200 Subject: [PATCH 1411/2126] wifi: mac80211: init radiotap iter after length checks The radiotap iterator initialization will already parse the presence bitmaps, so it accesses a good part of the header. This might not be present in the linear part of the SKB, we haven't checked it at this point. Check the lengths first. Assisted-by: LLM Fixes: cb17ed29a7a5 ("mac80211: parse radiotap header when selecting Tx queue") Link: https://patch.msgid.link/20261005224950.b5c2c31790d2.I091422db411b595bde4dba2de69334cd2aeb33b0@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index efe12384c59b..baf2c1214030 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2182,8 +2182,6 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, struct ieee80211_radiotap_header *rthdr = (struct ieee80211_radiotap_header *) skb->data; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, - NULL); u16 txflags; u16 rate = 0; bool rate_found = false; @@ -2192,11 +2190,14 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, u8 mcs_known, mcs_flags, mcs_bw; u16 vht_known; u8 vht_mcs = 0, vht_nss = 0; - int i; + int ret, i; if (!ieee80211_validate_radiotap_len(skb)) return false; + ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, + NULL); + info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | IEEE80211_TX_CTL_DONTFRAG; From 22d8e38161c722fe6e7ffb2a4c7fadab0f111271 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:57 +0200 Subject: [PATCH 1412/2126] wifi: mac80211: limit injected HT/VHT MCSes With radiotap injection the HT/VHT MCSes can be just about anything, but that can later get problematic. Limit them to the rates the device reports, which is presumably going to be a subset of what mac80211 can do, except for HT MCS 32 which some devices report as supported, but then TX status can't deal with it. If it's not supported just ignore the config. Assisted-by: LLM Fixes: dfdfc2beb0dd ("mac80211: Parse legacy and HT rate in injected frames") Fixes: 646e76bb5daf ("mac80211: parse VHT info in injected frames") Link: https://patch.msgid.link/20261005224950.68e210b8487a.I2ee0e4664c54cf31002eb9e4f5190fd05ff4130f@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index baf2c1214030..6cb7389e2c06 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2172,6 +2172,27 @@ static bool ieee80211_rate_bw_usable(u16 rate_flags, return width <= cfg80211_chandef_get_width(chandef); } +static bool +ieee80211_vht_tx_rate_supported(const struct ieee80211_sta_vht_cap *vht_cap, + u8 mcs, u8 nss) +{ + u16 map = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); + + if (!vht_cap->vht_supported) + return false; + + switch ((map >> (2 * (nss - 1))) & 3) { + case IEEE80211_VHT_MCS_SUPPORT_0_7: + return mcs <= 7; + case IEEE80211_VHT_MCS_SUPPORT_0_8: + return mcs <= 8; + case IEEE80211_VHT_MCS_SUPPORT_0_9: + return mcs <= 9; + default: + return false; + } +} + bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, struct net_device *dev, const struct cfg80211_chan_def *chandef, @@ -2368,14 +2389,20 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, hweight8(info->control.antennas)) info->control.antennas = 0; - info->control.rates[0].idx = rate; + /* MCS 32 and up aren't handled, e.g. by TX status */ + if (sband && sband->ht_cap.ht_supported && rate < 32 && + sband->ht_cap.mcs.rx_mask[rate / 8] & BIT(rate % 8)) + info->control.rates[0].idx = rate; } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) { /* reset antennas if not enough */ if (vht_nss > hweight8(info->control.antennas)) info->control.antennas = 0; - ieee80211_rate_set_vht(info->control.rates, vht_mcs, - vht_nss); + if (sband && + ieee80211_vht_tx_rate_supported(&sband->vht_cap, + vht_mcs, vht_nss)) + ieee80211_rate_set_vht(info->control.rates, + vht_mcs, vht_nss); } else if (sband) { for (i = 0; i < sband->n_bitrates; i++) { if (rate * 5 != sband->bitrates[i].bitrate) From ede3a3e0dadbf20c85bba9dca168cbdea8d7e6e7 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:58 +0200 Subject: [PATCH 1413/2126] wifi: mac80211: mesh: fix path table generation counters The mesh and MPP path generation counters (for netlink) are updated wrongly and sometimes unlocked. Fix those issues. Assisted-by: LLM Link: https://patch.msgid.link/20261005224950.373dd5c1e46a.I29b95bc3f62b846084700599a261a203a6e459b4@changeid Signed-off-by: Johannes Berg --- net/mac80211/mesh_pathtbl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c index 0485a979b3c2..dcb0a58e0fa9 100644 --- a/net/mac80211/mesh_pathtbl.c +++ b/net/mac80211/mesh_pathtbl.c @@ -711,8 +711,10 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata, mpath = rhashtable_lookup_get_insert_fast(&tbl->rhead, &new_mpath->rhash, mesh_rht_params); - if (!mpath) + if (!mpath) { hlist_add_head_rcu(&new_mpath->walk_list, &tbl->walk_head); + sdata->u.mesh.mesh_paths_generation++; + } spin_unlock_bh(&tbl->walk_lock); if (mpath) { @@ -725,7 +727,6 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata, new_mpath = mpath; } - sdata->u.mesh.mesh_paths_generation++; return new_mpath; } @@ -760,8 +761,10 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata, ret = rhashtable_lookup_insert_fast(&tbl->rhead, &new_mpath->rhash, mesh_rht_params); - if (!ret) + if (!ret) { hlist_add_head_rcu(&new_mpath->walk_list, &tbl->walk_head); + sdata->u.mesh.mpp_paths_generation++; + } spin_unlock_bh(&tbl->walk_lock); if (ret) { @@ -771,7 +774,6 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata, mesh_fast_tx_flush_addr(sdata, dst); } - sdata->u.mesh.mpp_paths_generation++; return ret; } @@ -833,10 +835,13 @@ static void __mesh_path_del(struct mesh_table *tbl, struct mesh_path *mpath) spin_lock_bh(&mpath->state_lock); WRITE_ONCE(mpath->flags, mpath->flags | MESH_PATH_DELETED); spin_unlock_bh(&mpath->state_lock); - if (tbl == &mpath->sdata->u.mesh.mpp_paths) + if (tbl == &mpath->sdata->u.mesh.mpp_paths) { + mpath->sdata->u.mesh.mpp_paths_generation++; mesh_fast_tx_flush_addr(mpath->sdata, mpath->dst); - else + } else { + mpath->sdata->u.mesh.mesh_paths_generation++; mesh_fast_tx_flush_mpath(mpath); + } mesh_path_free_rcu(tbl, mpath); } @@ -944,14 +949,10 @@ static int table_path_del(struct mesh_table *tbl, */ int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr) { - int err; - /* flush relevant mpp entries first */ mpp_flush_by_proxy(sdata, addr); - err = table_path_del(&sdata->u.mesh.mesh_paths, sdata, addr); - sdata->u.mesh.mesh_paths_generation++; - return err; + return table_path_del(&sdata->u.mesh.mesh_paths, sdata, addr); } /** From baf0d4feed2f0fed8e045f948534a4bd43ae464e Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:47:59 +0200 Subject: [PATCH 1414/2126] wifi: mac80211: fix mbssid/rnr allocation in beacon data These structs are placed after the tail, but that can make them unaligned. Change the order so the structs are after one another, and then followed by the head/tail/elements. Assisted-by: LLM Fixes: 2b3171c6fe0a ("mac80211: MBSSID beacon handling in AP mode") Link: https://patch.msgid.link/20261005224950.2f554b2c7c10.Ie961eb6b1435f956446e052936258758b966c67f@changeid Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 53 +++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 69002d740a58..d0d14f621588 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1511,6 +1511,7 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, struct beacon_data *new, *old; int new_head_len, new_tail_len; int size, err; + u8 *pos; u64 _changed = BSS_CHANGED_BEACON; struct ieee80211_bss_conf *link_conf = link->conf; @@ -1538,20 +1539,16 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, /* new or old multiple BSSID elements? */ if (params->mbssid_ies) { mbssid = params->mbssid_ies; - size += struct_size(new->mbssid_ies, elem, mbssid->cnt); - if (params->rnr_ies) { - rnr = params->rnr_ies; - size += struct_size(new->rnr_ies, elem, rnr->cnt); - } - size += ieee80211_get_mbssid_beacon_len(mbssid, rnr, - mbssid->cnt); + rnr = params->rnr_ies; } else if (old && old->mbssid_ies) { mbssid = old->mbssid_ies; + rnr = old->rnr_ies; + } + + if (mbssid) { size += struct_size(new->mbssid_ies, elem, mbssid->cnt); - if (old->rnr_ies) { - rnr = old->rnr_ies; + if (rnr) size += struct_size(new->rnr_ies, elem, rnr->cnt); - } size += ieee80211_get_mbssid_beacon_len(mbssid, rnr, mbssid->cnt); } @@ -1563,26 +1560,38 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, /* start filling the new info now */ /* - * pointers go into the block we allocated, - * memory is | beacon_data | head | tail | mbssid_ies | rnr_ies + * pointers go into the block we allocated, the order in memory is + * - struct beacon_data + * - struct mbssid_ies (including variable array) + * - struct rnr_ies (including variable array) + * - beacon head + * - beacon tail + * - mbssid/rnr elements + * so that the structs (which contain pointers) are all aligned */ - new->head = ((u8 *) new) + sizeof(*new); - new->tail = new->head + new_head_len; - new->head_len = new_head_len; - new->tail_len = new_tail_len; - /* copy in optional mbssid_ies */ + pos = (u8 *)(new + 1); if (mbssid) { - u8 *pos = new->tail + new->tail_len; - new->mbssid_ies = (void *)pos; pos += struct_size(new->mbssid_ies, elem, mbssid->cnt); - pos += ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, - mbssid); if (rnr) { new->rnr_ies = (void *)pos; pos += struct_size(new->rnr_ies, elem, rnr->cnt); - ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr); } + } + + new->head = pos; + new->head_len = new_head_len; + pos += new_head_len; + new->tail = pos; + new->tail_len = new_tail_len; + pos += new_tail_len; + + /* copy in optional mbssid_ies */ + if (mbssid) { + pos += ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, + mbssid); + if (rnr) + ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr); /* update bssid_indicator */ if (new->mbssid_ies->cnt && new->mbssid_ies->elem[0].len > 2) link_conf->bssid_indicator = From a5f361bc57aed2beb44580474fbe05c610df32a5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:48:00 +0200 Subject: [PATCH 1415/2126] wifi: mac80211: don't read runt headers in injection For injection we only check the header is in the skb head, but e.g. ACK/CTS are really short, and we then try to use A2 anyway. Require A1 (no S1G extension frames) and use A2 only when present. Assisted-by: LLM Link: https://patch.msgid.link/20261005224950.0f3c3e88abde.I03477f2444a9f2cb2888d00320ac7c4504f150a3@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 6cb7389e2c06..4eebb6e26028 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2471,7 +2471,9 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); hdrlen = ieee80211_hdrlen(hdr->frame_control); - if (skb_headlen(skb) < len_rthdr + hdrlen) + if (skb_headlen(skb) < len_rthdr + + max_t(int, hdrlen, + offsetofend(struct ieee80211_hdr, addr1))) goto fail; /* @@ -2505,7 +2507,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR || tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN) continue; - if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) { + if (hdrlen >= offsetofend(struct ieee80211_hdr, addr2) && + ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) { sdata = tmp_sdata; break; } From 2f4bb025e9475e0f9f0b5c29127eccade418b141 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 5 Oct 2026 22:48:01 +0200 Subject: [PATCH 1416/2126] wifi: mac80211: fix TDLS setup frame length check If TDLS setup packets are created by AF_PACKET or so, then the payload may not be present. Since we only care about those mac80211 generated (which are linear), just replace the skb->len check with a skb_headlen() check to avoid any out-of-bounds accesses. Assisted-by: LLM Link: https://patch.msgid.link/20261005224950.c3cf023d5191.Id537db8aca13e6df999938a3bc4cc6ce2a28f733@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 4eebb6e26028..6f44ddfa0452 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2606,7 +2606,7 @@ static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb) u16 ethertype = (skb->data[12] << 8) | skb->data[13]; return ethertype == ETH_P_TDLS && - skb->len > 14 && + skb_headlen(skb) > 14 && skb->data[14] == WLAN_TDLS_SNAP_RFTYPE; } From 2531f6539d2f844f24fdfad6eea1361af68b3359 Mon Sep 17 00:00:00 2001 From: Eduard Zateev Date: Wed, 7 Oct 2026 16:28:55 +0200 Subject: [PATCH 1417/2126] wifi: cfg80211: validate WEXT station BSSID WEXT IBSS and managed mode store the BSSID in the same wdev->wext.bssid buffer. cfg80211_ibss_wext_siwap() keeps a pointer to that buffer in wext.ibss.bssid. After changing to station mode, cfg80211_mgd_wext_siwap() accepts a multicast AP address and copies it to the buffer. Switching back to IBSS then follows that pointer and uses the multicast address as a fixed BSSID. mac80211 can create a beacon with that address, but cfg80211_get_bss() rejects it, causing WARN_ON(!bss) in cfg80211_ibss_joined() after the join has been reported. Reject invalid station BSSIDs before copying them. A mac80211_hwsim WEXT ioctl test reproduces the reported BSSID and warning; the original syzbot report has no reproducer. Reported-by: syzbot+d0a52209bddfa0948065@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=d0a52209bddfa0948065 Signed-off-by: Eduard Zateev Link: https://patch.msgid.link/20261007142855.1472524-1-hackerowskiy@gmail.com Signed-off-by: Johannes Berg --- net/wireless/wext-sme.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c index b5914f3658db..3db73a0765c9 100644 --- a/net/wireless/wext-sme.c +++ b/net/wireless/wext-sme.c @@ -245,6 +245,9 @@ int cfg80211_mgd_wext_siwap(struct net_device *dev, if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) bssid = NULL; + if (bssid && !is_valid_ether_addr(bssid)) + return -EINVAL; + if (wdev->conn) { /* both automatic */ if (!bssid && !wdev->wext.connect.bssid) From 0fdd10cac4425bf5ee818aac1c1c0c8ced3ebf75 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Wed, 7 Oct 2026 16:12:57 -0700 Subject: [PATCH 1418/2126] wifi: cfg80211: fix kernel-doc %field -> @field cross-references Struct field cross-references in kernel-doc use @field, not %field (which is for constants and #defines). Fix eight instances, while also correcting %elems -> @elem naming in cfg80211_mbssid_elems and cfg80211_rnr_elems. Assisted-by: LLM Signed-off-by: Jeff Johnson Link: https://patch.msgid.link/20261007-cfg80211-kdoc-v1-1-157b358b291f@oss.qualcomm.com Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 05c625d9e076..725dc8053727 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -1410,7 +1410,7 @@ struct cfg80211_mbssid_config { /** * struct cfg80211_mbssid_elems - Multiple BSSID elements * - * @cnt: Number of elements in array %elems. + * @cnt: Number of elements in array @elem. * * @elem: Array of multiple BSSID element(s) to be added into Beacon frames. * @elem.data: Data for multiple BSSID elements. @@ -1427,7 +1427,7 @@ struct cfg80211_mbssid_elems { /** * struct cfg80211_rnr_elems - Reduced neighbor report (RNR) elements * - * @cnt: Number of elements in array %elems. + * @cnt: Number of elements in array @elem. * * @elem: Array of RNR element(s) to be added into Beacon frames. * @elem.data: Data for RNR elements. @@ -2908,7 +2908,7 @@ struct cfg80211_ssid { * @scan_start_tsf: scan start time in terms of the TSF of the BSS that the * wireless device that requested the scan is connected to. If this * information is not available, this field is left zero. - * @tsf_bssid: the BSSID according to which %scan_start_tsf is set. + * @tsf_bssid: the BSSID according to which @scan_start_tsf is set. * @aborted: set to true if the scan was aborted for any reason, * userspace will be notified of that */ @@ -3168,8 +3168,8 @@ enum cfg80211_signal_type { * ktime_get_boottime_ns() is likely appropriate. * @parent_tsf: the time at the start of reception of the first octet of the * timestamp field of the frame. The time is the TSF of the BSS specified - * by %parent_bssid. - * @parent_bssid: the BSS according to which %parent_tsf is set. This is set to + * by @parent_bssid. + * @parent_bssid: the BSS according to which @parent_tsf is set. This is set to * the BSS that requested the scan in which the beacon/probe was received. * @chains: bitmask for filled values in @chain_signal. * @chain_signal: per-chain signal strength of last received BSS in dBm. @@ -4246,9 +4246,9 @@ struct cfg80211_nan_channel { * * This struct defines NAN local schedule parameters * - * @schedule: a mapping of time slots to chandef indexes in %nan_channels. + * @schedule: a mapping of time slots to chandef indexes in @nan_channels. * An unscheduled slot will be set to %NL80211_NAN_SCHED_NOT_AVAIL_SLOT. - * @n_channels: number of channel definitions in %nan_channels. + * @n_channels: number of channel definitions in @nan_channels. * @nan_avail_blob: pointer to NAN Availability attribute blob. * See %NL80211_ATTR_NAN_AVAIL_BLOB for more details. * @nan_avail_blob_len: length of the @nan_avail_blob in bytes. @@ -4276,7 +4276,7 @@ struct cfg80211_nan_local_sched { * This struct defines the set of NAN local schedule channels that must not * be evacuated for concurrent operations. * - * @n_channels: number of channel definitions in %chandefs. + * @n_channels: number of channel definitions in @chandefs. * @chandefs: array of channel definitions that must not be evacuated. Each * must match a channel of the current local schedule. */ From 8662a5ecd6f991d81772f33d0fbec3050901c2f6 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 8 Oct 2026 14:09:38 +1100 Subject: [PATCH 1419/2126] wifi: mac80211: handle shorter S1G TIM when parsing elements An S1G TIM, unlike the regular TIM, can exclude both the bitmap control and the PVB. As a result it's minimum length is actually 2. Fix this by allowing a shorter TIM for S1G connections. Suggested-by: Johannes Berg Signed-off-by: Lachlan Hodges Link: https://patch.msgid.link/20261008030939.474493-2-lachlan.hodges@morsemicro.com Signed-off-by: Johannes Berg --- net/mac80211/parse.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/mac80211/parse.c b/net/mac80211/parse.c index 030da4679ca3..f3c5a9f6ec7c 100644 --- a/net/mac80211/parse.c +++ b/net/mac80211/parse.c @@ -449,12 +449,15 @@ _ieee802_11_parse_elems_full(struct ieee80211_elems_parse_params *params, IEEE80211_PARSE_ERR_BAD_ELEM_SIZE; break; case WLAN_EID_TIM: - if (elen >= sizeof(struct ieee80211_tim_ie)) { + if ((params->mode == IEEE80211_CONN_MODE_S1G && + elen >= 2 /* control/PVB are optional */) || + elen >= sizeof(struct ieee80211_tim_ie)) { elems->tim = (void *)pos; elems->tim_len = elen; - } else + } else { elem_parse_failed = IEEE80211_PARSE_ERR_BAD_ELEM_SIZE; + } break; case WLAN_EID_VENDOR_SPECIFIC: if (elems_parse->skip_vendor) From 44f2345f476cfec8042033c4fc03799ecc08ce88 Mon Sep 17 00:00:00 2001 From: Lachlan Hodges Date: Thu, 8 Oct 2026 14:09:39 +1100 Subject: [PATCH 1420/2126] wifi: mac80211: set conn mode prior to parsing elements in beacon ieee80211_inform_bss() currently calls ieee802_11_parse_elems to parse the beacon elements, which internally sets the params->mode to IEEE80211_CONN_MODE_HIGHEST. This means any S1G specific parsing is bypassed entirely (in the beacon case it is the shorter TIM) and the beacon is marked as corrupt: wlan0: operating as S1G STA wlan0: associating to AP 0c:bf:74:00:30:fd with corrupt beacon wlan0: associate with 0c:bf:74:00:30:fd (try 1/3) In this case, we can simply call ieee802_11_parse_elems_full and build the params locally (similar to most mlme paths) such that we can set the conn mode to ensure the S1G specific parsing occurs. Once this is done, the beacon is no longer considered corrupt: wlan0: operating as S1G STA wlan0: associate with 0c:bf:74:00:30:fd (try 1/3) Signed-off-by: Lachlan Hodges Link: https://patch.msgid.link/20261008030939.474493-3-lachlan.hodges@morsemicro.com Signed-off-by: Johannes Berg --- net/mac80211/scan.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index a4bca412e577..8a66d2e020f9 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -68,6 +68,14 @@ void ieee80211_inform_bss(struct wiphy *wiphy, struct ieee80211_local *local = wiphy_priv(wiphy); struct inform_bss_update_data *update_data = data; struct ieee80211_bss *bss = (void *)cbss->priv; + struct ieee80211_elems_parse_params params = { + .mode = cbss->channel->band == NL80211_BAND_S1GHZ ? + IEEE80211_CONN_MODE_S1G : + IEEE80211_CONN_MODE_HIGHEST, + .start = ies->data, + .len = ies->len, + .link_id = -1, + }; struct ieee80211_rx_status *rx_status; struct ieee802_11_elems *elems; int clen, srlen; @@ -76,11 +84,11 @@ void ieee80211_inform_bss(struct wiphy *wiphy, if (!update_data) return; - elems = ieee802_11_parse_elems(ies->data, ies->len, - update_data->beacon ? - IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON : - IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP, - NULL); + params.type = update_data->beacon ? + IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON : + IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP; + + elems = ieee802_11_parse_elems_full(¶ms); if (!elems) return; From 507b014f7f744b2a1317e87babe7c20b7d950f72 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 12:24:12 +0700 Subject: [PATCH 1421/2126] wifi: mac80211: Pin module for hwflags debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, hwflags_ops in net/mac80211/debugfs.c has no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the mac80211 module. When CONFIG_MAC80211=m and wireless debugfs is enabled, a userspace process can open the hwflags debugfs file and keep the file descriptor open while the module is unloaded (rmmod mac80211). When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release(): BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The issue was discovered via manual code audit of net/mac80211/debugfs.c. Set .owner = THIS_MODULE on hwflags_ops so that debugfs pins the module until all open file descriptors have been closed. Signed-off-by: Bui Viet Dung Link: https://patch.msgid.link/20261008052412.541780-1-dungvn2345@gmail.com Signed-off-by: Johannes Berg --- net/mac80211/debugfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 1f914b48e3bb..a8f677cfc77e 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c @@ -529,6 +529,7 @@ static ssize_t hwflags_write(struct file *file, const char __user *user_buf, } static const struct file_operations hwflags_ops = { + .owner = THIS_MODULE, .open = simple_open, .read = hwflags_read, .write = hwflags_write, From ad0726b61b85b0e75834581dcf9d00031dc5ec42 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 12:29:36 +0700 Subject: [PATCH 1422/2126] wifi: cfg80211: Pin module for debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, the file_operations defined by the DEBUGFS_READONLY_FILE and DEBUGFS_RADIO_READONLY_FILE macros, as well as ht40allow_map_ops in net/wireless/debugfs.c, have no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the cfg80211 module. When CONFIG_CFG80211=m and wireless debugfs is enabled, a userspace process can open any of these debugfs files (e.g. /sys/kernel/debug/ieee80211/phy0/rts_threshold or ht40allow_map) and keep the file descriptor open while the module is unloaded (rmmod cfg80211). When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release(): BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The issue was discovered via manual code audit of net/wireless/debugfs.c. Set .owner = THIS_MODULE on all debugfs file_operations tables in net/wireless/debugfs.c so that debugfs pins the module until all open file descriptors have been closed. Signed-off-by: Bui Viet Dung Link: https://patch.msgid.link/20261008052936.555554-1-dungvn2345@gmail.com Signed-off-by: Johannes Berg --- net/wireless/debugfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c index f9e7fff1ef25..63503dbd8938 100644 --- a/net/wireless/debugfs.c +++ b/net/wireless/debugfs.c @@ -24,6 +24,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \ } \ \ static const struct file_operations name## _ops = { \ + .owner = THIS_MODULE, \ .read = name## _read, \ .open = simple_open, \ .llseek = generic_file_llseek, \ @@ -42,6 +43,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \ } \ \ static const struct file_operations name## _ops = { \ + .owner = THIS_MODULE, \ .read = name## _read, \ .open = simple_open, \ .llseek = generic_file_llseek, \ @@ -113,6 +115,7 @@ static ssize_t ht40allow_map_read(struct file *file, } static const struct file_operations ht40allow_map_ops = { + .owner = THIS_MODULE, .read = ht40allow_map_read, .open = simple_open, .llseek = default_llseek, From 81a6e0248d8362c69636f312ae78708cad543e93 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 19:28:38 +0700 Subject: [PATCH 1423/2126] wifi: mac80211_hwsim: Pin module for debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, hwsim_background_cac_ops and hwsim_simulate_incumbent_signal_fops in mac80211_hwsim_main.c have no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the mac80211_hwsim module. When a userspace process opens either of these debugfs files, a subsequent module unload (rmmod mac80211_hwsim) can succeed while the file descriptor remains open. When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release(): BUG: unable to handle page fault for address: fffffbfff84f49e7 Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x39f/0xa60 __x64_sys_close+0x80/0xe0 do_syscall_64+0xc3/0x590 entry_SYSCALL_64_after_hwframe+0x76/0x7e The issue was discovered via manual code audit of mac80211_hwsim_main.c and reproduced on a Linux 7.3-rc6 test VM with CONFIG_MAC80211_HWSIM=m. Set .owner = THIS_MODULE on both debugfs file_operations structures in mac80211_hwsim_main.c so that debugfs pins the module until close has completed. Signed-off-by: Bui Viet Dung Link: https://patch.msgid.link/20261008122838.224835-1-dungvn2345@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 6cd9542e8b72..832e05573015 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -1150,6 +1150,7 @@ static ssize_t hwsim_background_cac_write(struct file *file, } static const struct file_operations hwsim_background_cac_ops = { + .owner = THIS_MODULE, .write = hwsim_background_cac_write, .open = simple_open, .llseek = default_llseek, @@ -1210,6 +1211,7 @@ static ssize_t hwsim_simulate_incumbent_signal_write(struct file *file, } static const struct file_operations hwsim_simulate_incumbent_signal_fops = { + .owner = THIS_MODULE, .open = simple_open, .write = hwsim_simulate_incumbent_signal_write, }; From 298618f28bd3d1da677828354b504c12e2f375e4 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:03:59 +0200 Subject: [PATCH 1424/2126] wifi: cfg80211: reg: protect regdb pointer with RCU reg_query_regdb_wmm() is only used by iwlwifi, but even when it was introduced was already broken, as it reads the global db without any locking (drivers can't really guarantee any). Certainly iwlwifi doesn't since it calls it for FW messages. Therefore, it can race against regdb updates. The function uses a local pointer, but doesn't help. Use RCU to protect the regdb pointer to fix that, and update the documentation to mention this (and do some cleanups). Fixes: 19d3577e35e0 ("cfg80211: Add API to allow querying regdb for wmm_rule") Link: https://patch.msgid.link/20261006120655.7c261d237cae.If21cf0af3b0d7e8c62c45ece5dc654b30c9d7757@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 12 ++++++------ net/wireless/reg.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 725dc8053727..a3fb7dd743c8 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -8236,20 +8236,20 @@ bool regulatory_pre_cac_allowed(struct wiphy *wiphy); */ /** - * reg_query_regdb_wmm - Query internal regulatory db for wmm rule - * Regulatory self-managed driver can use it to proactively - * + * reg_query_regdb_wmm - Query internal regulatory db for WMM rules * @alpha2: the ISO/IEC 3166 alpha2 wmm rule to be queried. * @freq: the frequency (in MHz) to be queried. - * @rule: pointer to store the wmm rule from the regulatory db. + * @rule: pointer to store the WMM rule from the regulatory db. * - * Self-managed wireless drivers can use this function to query + * Self-managed wireless drivers can use this function to query * the internal regulatory database to check whether the given - * ISO/IEC 3166 alpha2 country and freq have wmm rule limitations. + * ISO/IEC 3166 alpha2 country and freq have WMM rule limitations. * * Drivers should check the return value, its possible you can get * an -ENODATA. * + * This uses RCU internally so can be called in just about any context. + * * Return: 0 on success. -ENODATA. */ int reg_query_regdb_wmm(char *alpha2, int freq, diff --git a/net/wireless/reg.c b/net/wireless/reg.c index b7ef479a74f0..27ba860f0391 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -590,7 +590,7 @@ static inline int call_crda(const char *alpha2) #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ /* code to directly load a firmware database through request_firmware */ -static const struct fwdb_header *regdb; +static const struct fwdb_header __rcu *global_regdb; struct fwdb_country { u8 alpha2[2]; @@ -892,16 +892,19 @@ static int __regdb_query_wmm(const struct fwdb_header *db, int reg_query_regdb_wmm(char *alpha2, int freq, struct ieee80211_reg_rule *rule) { - const struct fwdb_header *hdr = regdb; const struct fwdb_country *country; + const struct fwdb_header *regdb; + guard(rcu)(); + + regdb = rcu_dereference(global_regdb); if (!regdb) return -ENODATA; if (IS_ERR(regdb)) return PTR_ERR(regdb); - country = &hdr->country[0]; + country = ®db->country[0]; while (country->coll_ptr) { if (alpha2_equal(alpha2, country->alpha2)) return __regdb_query_wmm(regdb, country, freq, rule); @@ -970,15 +973,13 @@ static int regdb_query_country(const struct fwdb_header *db, static int query_regdb(const char *alpha2) { - const struct fwdb_header *hdr = regdb; + const struct fwdb_header *regdb = rtnl_dereference(global_regdb); const struct fwdb_country *country; - ASSERT_RTNL(); - if (IS_ERR(regdb)) return PTR_ERR(regdb); - country = &hdr->country[0]; + country = ®db->country[0]; while (country->coll_ptr) { if (alpha2_equal(alpha2, country->alpha2)) return regdb_query_country(regdb, country); @@ -990,6 +991,7 @@ static int query_regdb(const char *alpha2) static void regdb_fw_cb(const struct firmware *fw, void *context) { + const struct fwdb_header *regdb; int set_error = 0; bool restore = true; void *db; @@ -1003,6 +1005,7 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) } rtnl_lock(); + regdb = rtnl_dereference(global_regdb); if (regdb && !IS_ERR(regdb)) { /* negative case - a bug * positive case - can happen due to race in case of multiple cb's in @@ -1011,11 +1014,11 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) * Either case, just restore and free new db. */ } else if (set_error) { - regdb = ERR_PTR(set_error); + rcu_assign_pointer(global_regdb, ERR_PTR(set_error)); } else if (fw) { db = kmemdup(fw->data, fw->size, GFP_KERNEL); if (db) { - regdb = db; + rcu_assign_pointer(global_regdb, db); restore = context && query_regdb(context); } else { restore = true; @@ -1040,7 +1043,7 @@ static int query_regdb_file(const char *alpha2) ASSERT_RTNL(); - if (regdb) + if (rcu_access_pointer(global_regdb)) return query_regdb(alpha2); alpha2 = kmemdup(alpha2, 2, GFP_KERNEL); @@ -1058,8 +1061,8 @@ static int query_regdb_file(const char *alpha2) int reg_reload_regdb(void) { + const struct fwdb_header *db, *old; const struct firmware *fw; - void *db; int err; const struct ieee80211_regdomain *current_regdomain; struct regulatory_request *request; @@ -1080,9 +1083,7 @@ int reg_reload_regdb(void) } rtnl_lock(); - if (!IS_ERR_OR_NULL(regdb)) - kfree(regdb); - regdb = db; + old = rcu_replace_pointer_rtnl(global_regdb, db); /* reset regulatory domain */ current_regdomain = get_cfg80211_regdom(); @@ -1103,6 +1104,11 @@ int reg_reload_regdb(void) out_unlock: rtnl_unlock(); + + if (!IS_ERR_OR_NULL(old)) { + synchronize_rcu(); + kfree(old); + } out: release_firmware(fw); return err; @@ -4390,6 +4396,7 @@ void regulatory_exit(void) { struct regulatory_request *reg_request, *tmp; struct reg_beacon *reg_beacon, *btmp; + const struct fwdb_header *db; cancel_work_sync(®_work); cancel_crda_timeout_sync(); @@ -4419,8 +4426,10 @@ void regulatory_exit(void) kfree(reg_request); } - if (!IS_ERR_OR_NULL(regdb)) - kfree(regdb); + /* RCU is irrelevant on the way out */ + db = rcu_dereference_protected(global_regdb, true); + if (!IS_ERR_OR_NULL(db)) + kfree(db); if (!IS_ERR_OR_NULL(cfg80211_user_regdom)) kfree(cfg80211_user_regdom); From bf49114633184715a128978969aca3f4d98bd034 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:00 +0200 Subject: [PATCH 1425/2126] wifi: cfg80211: track netdev running state under wiphy mutex wdev_running() uses netif_running() for netdevs, which can only be used under RTNL in a completely race-free way. Track the state for all wdevs via the existing netdev notifier so we can check the state under wiphy mutex in later changes. Link: https://patch.msgid.link/20261006120655.7ed32b42c297.I9ac8bb8e7cd07c962116949aa0c56aab4e87839b@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 7 +++---- net/wireless/core.c | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index a3fb7dd743c8..d4a77f9fe0b7 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -7242,8 +7242,9 @@ enum ieee80211_ap_reg_power { * @mgmt_registrations_need_update: mgmt registrations were updated, * need to propagate the update to the driver * @address: The address for this device, valid only if @netdev is %NULL - * @is_running: true if this is a non-netdev device that has been started, e.g. - * the P2P Device. + * @is_running: true if the device has been started, e.g. the P2P Device; + * for netdevs, tracked under the wiphy mutex from NETDEV_UP until + * NETDEV_GOING_DOWN * @ps: powersave mode is enabled * @ps_timeout: dynamic powersave timeout * @unexpected_nlportid: (private) netlink port ID of application @@ -7407,8 +7408,6 @@ static inline const u8 *wdev_address(struct wireless_dev *wdev) static inline bool wdev_running(struct wireless_dev *wdev) { - if (wdev->netdev) - return netif_running(wdev->netdev); return wdev->is_running; } diff --git a/net/wireless/core.c b/net/wireless/core.c index 45a1709cffe7..fa56208f8c8e 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -1836,6 +1836,8 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, } break; case NETDEV_GOING_DOWN: + scoped_guard(wiphy, &rdev->wiphy) + wdev->is_running = false; cfg80211_leave(rdev, wdev, -1); scoped_guard(wiphy, &rdev->wiphy) { cfg80211_remove_links(wdev); @@ -1866,6 +1868,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, break; case NETDEV_UP: wiphy_lock(&rdev->wiphy); + wdev->is_running = true; cfg80211_update_iface_num(rdev, wdev->iftype, 1); switch (wdev->iftype) { #ifdef CONFIG_CFG80211_WEXT From 57b1607464142837b9dea57fa30143fedca64e47 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:01 +0200 Subject: [PATCH 1426/2126] wifi: nl80211: allow device lookup under RCU We already modify our wiphy/wdev lists in RCU-safe ways, so we can do lookups in RCU critical sections. Prepare more of the code to be able to do that. Link: https://patch.msgid.link/20261006120655.86d9cf36d8bb.I07b7ce5a69391d5168dc31c598b5079917a29bff@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 6 +++--- net/wireless/nl80211.c | 32 +++++++++++++++++--------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index fa56208f8c8e..fb1e2070494f 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -57,13 +57,13 @@ module_param(cfg80211_disable_40mhz_24ghz, bool, 0644); MODULE_PARM_DESC(cfg80211_disable_40mhz_24ghz, "Disable 40MHz support in the 2.4GHz band"); +/* requires RCU or rtnl */ struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx) { struct cfg80211_registered_device *result = NULL, *rdev; - ASSERT_RTNL(); - - for_each_rdev(rdev) { + list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list, + lockdep_rtnl_is_held()) { if (rdev->wiphy_idx == wiphy_idx) { result = rdev; break; diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 9c2d5c89598b..14b79a4a8c1c 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -63,7 +63,7 @@ static const struct genl_multicast_group nl80211_mcgrps[] = { #endif }; -/* returns ERR_PTR values */ +/* returns ERR_PTR values, requires RCU or rtnl if rdev is %NULL */ static struct wireless_dev * __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, struct net *netns, struct nlattr **attrs) @@ -105,9 +105,8 @@ __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, return result ?: ERR_PTR(-ENODEV); } - ASSERT_RTNL(); - - for_each_rdev(rdev) { + list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list, + lockdep_rtnl_is_held()) { struct wireless_dev *wdev; if (wiphy_net(&rdev->wiphy) != netns) @@ -116,7 +115,8 @@ __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) continue; - list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list, + lockdep_rtnl_is_held()) { if (have_ifidx && wdev->netdev && wdev->netdev->ifindex == ifidx) { result = wdev; @@ -137,14 +137,13 @@ __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, return ERR_PTR(-ENODEV); } +/* requires RCU or rtnl */ static struct cfg80211_registered_device * __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) { struct cfg80211_registered_device *rdev = NULL, *tmp; struct net_device *netdev; - ASSERT_RTNL(); - if (!attrs[NL80211_ATTR_WIPHY] && !attrs[NL80211_ATTR_IFINDEX] && !attrs[NL80211_ATTR_WDEV]) @@ -162,7 +161,8 @@ __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); if (tmp) { /* make sure wdev exists */ - list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { + list_for_each_entry_rcu(wdev, &tmp->wiphy.wdev_list, + list, lockdep_rtnl_is_held()) { if (wdev->identifier != (u32)wdev_id) continue; found = true; @@ -181,14 +181,16 @@ __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) if (attrs[NL80211_ATTR_IFINDEX]) { int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); - netdev = __dev_get_by_index(netns, ifindex); - if (netdev) { - if (netdev->ieee80211_ptr) - tmp = wiphy_to_rdev( - netdev->ieee80211_ptr->wiphy); - else - tmp = NULL; + /* RCU required for dev_get_by_index_rcu() if we have RTNL */ + rcu_read_lock(); + netdev = dev_get_by_index_rcu(netns, ifindex); + if (netdev && netdev->ieee80211_ptr) + tmp = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); + else + tmp = NULL; + rcu_read_unlock(); + if (netdev) { /* not wireless device -- return error */ if (!tmp) return ERR_PTR(-EINVAL); From 8e3d9039d280c61e1ef5c5cbe8ee8db342907173 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:02 +0200 Subject: [PATCH 1427/2126] wifi: nl80211: avoid rtnl for commands that don't want it We currently always take the RTNL for the lookup only to drop it again if the command doesn't want it, but now that we can do lookups with RCU, do that unless the command still wants RTNL anyway. This basically just means looking up under RCU, then holding a reference briefly, and checking state (and link IDs) under the wiphy mutex when it's acquired to avoid races on unregistration etc. Commands that don't want either mutex can only work with netdevs since wdevs could go away, so warn on others. None such can exist since there are no flags for it, and I noted there it wouldn't be valid. Link: https://patch.msgid.link/20261006120655.ea80a5ecd9b8.I9c4f85fb60160f377a24c1b8e5173966744e5f09@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 5 +- net/wireless/nl80211.c | 153 ++++++++++++++++++++++++++++++++++------- 2 files changed, 132 insertions(+), 26 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index fb1e2070494f..270fb30e5265 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -1271,6 +1271,9 @@ int wiphy_register(struct wiphy *wiphy) } cfg80211_debugfs_rdev_add(rdev); + + rdev->wiphy.registered = true; + nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY); wiphy_unlock(&rdev->wiphy); @@ -1317,8 +1320,6 @@ int wiphy_register(struct wiphy *wiphy) break; } } - - rdev->wiphy.registered = true; rtnl_unlock(); res = rfkill_register(rdev->wiphy.rfkill); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 14b79a4a8c1c..ee18100de8f8 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -225,6 +225,48 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) return __cfg80211_rdev_from_attrs(netns, info->attrs); } +/* + * Lock the given wiphy, put the device and double-check it's + * still valid to use. + * + * Returns with wiphy mutex held unless there was an error. + */ +static struct wireless_dev * +nl80211_lock_and_recheck(struct cfg80211_registered_device *rdev, + struct net *netns, u32 wdev_id) +{ + struct wireless_dev *wdev; + + wiphy_lock(&rdev->wiphy); + + if (!rdev->wiphy.registered || + !net_eq(wiphy_net(&rdev->wiphy), netns)) { + wiphy_unlock(&rdev->wiphy); + put_device(&rdev->wiphy.dev); + return ERR_PTR(-ENODEV); + } + + /* + * unregistration blocks on wiphy mutex, + * so we don't need this now + */ + put_device(&rdev->wiphy.dev); + + if (!wdev_id) + return NULL; + + list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->identifier != wdev_id) + continue; + if (wdev->netdev && !net_eq(dev_net(wdev->netdev), netns)) + break; + return wdev; + } + wiphy_unlock(&rdev->wiphy); + + return ERR_PTR(-ENODEV); +} + static int validate_beacon_head(const struct nlattr *attr, struct netlink_ext_ack *extack) { @@ -19678,6 +19720,18 @@ nl80211_epcs_cfg(struct sk_buff *skb, struct genl_info *info) NL80211_FLAG_NO_WIPHY_MTX | \ NL80211_FLAG_NEED_RTNL) +/* + * Note: a + * SELECTOR(..., + * NL80211_FLAG_NO_WIPHY_MTX | + * NL80211_FLAG_NEED_WDEV) + * or + * SELECTOR(..., NL80211_FLAG_NO_WIPHY_MTX) + * + * isn't valid - nothing would ensure the device stays around, + * need at least a netdev, the wiphy mutex, or RTNL. + */ + enum nl80211_internal_flags_selector { #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name, INTERNAL_FLAG_SELECTORS(_) @@ -19695,41 +19749,88 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, struct genl_info *info) { struct cfg80211_registered_device *rdev = NULL; + struct net *netns = genl_info_net(info); struct wireless_dev *wdev = NULL; struct net_device *dev = NULL; - u32 internal_flags; + bool need_rtnl, locked = false; + u32 internal_flags, wdev_id = 0; int err; if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags))) return -EINVAL; internal_flags = nl80211_internal_flags[ops->internal_flags]; + need_rtnl = internal_flags & NL80211_FLAG_NEED_RTNL; + + if (need_rtnl) + rtnl_lock(); + else + rcu_read_lock(); - rtnl_lock(); if (internal_flags & NL80211_FLAG_NEED_WIPHY) { - rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); + rdev = cfg80211_get_dev_from_info(netns, info); if (IS_ERR(rdev)) { err = PTR_ERR(rdev); - goto out_unlock; + goto out_lookup; } - info->user_ptr[0] = rdev; } else if (internal_flags & NL80211_FLAG_NEED_NETDEV || internal_flags & NL80211_FLAG_NEED_WDEV) { - wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), - info->attrs); + wdev = __cfg80211_wdev_from_attrs(NULL, netns, info->attrs); if (IS_ERR(wdev)) { err = PTR_ERR(wdev); - goto out_unlock; + goto out_lookup; } dev = wdev->netdev; dev_hold(dev); rdev = wiphy_to_rdev(wdev->wiphy); + } + if (!need_rtnl) { + if (rdev) + get_device(&rdev->wiphy.dev); + if (wdev) + wdev_id = wdev->identifier; + rcu_read_unlock(); + + /* RTM_NEWLINK is sent before NETDEV_UP, wait for dev_open() */ + if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && dev && + !READ_ONCE(wdev->is_running) && netif_running(dev)) { + rtnl_lock(); + rtnl_unlock(); + } + } + + if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { + if (need_rtnl) { + wiphy_lock(&rdev->wiphy); + } else { + /* without rtnl, things may have changed since lookup */ + wdev = nl80211_lock_and_recheck(rdev, netns, wdev_id); + if (IS_ERR(wdev)) { + err = PTR_ERR(wdev); + goto out; + } + } + locked = true; + } else if (rdev && !need_rtnl) { + /* + * Without any mutex need a netdev to keep it alive, see + * also the note about selectors - the WARN can't happen + * without wrong selectors and those don't exist. + */ + put_device(&rdev->wiphy.dev); + if (WARN_ON(!dev)) { + err = -EINVAL; + goto out; + } + } + + if (wdev) { if (internal_flags & NL80211_FLAG_NEED_NETDEV) { if (!dev) { err = -EINVAL; - goto out_unlock; + goto out; } info->user_ptr[1] = dev; @@ -19740,10 +19841,8 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && !wdev_running(wdev)) { err = -ENETDOWN; - goto out_unlock; + goto out; } - - info->user_ptr[0] = rdev; } if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) { @@ -19751,7 +19850,7 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, if (!wdev) { err = -EINVAL; - goto out_unlock; + goto out; } /* MLO -> require valid link ID */ @@ -19759,13 +19858,13 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, (!link_id || !(wdev->valid_links & BIT(nla_get_u8(link_id))))) { err = -EINVAL; - goto out_unlock; + goto out; } /* non-MLO -> no link ID attribute accepted */ if (!wdev->valid_links && link_id) { err = -EINVAL; - goto out_unlock; + goto out; } } @@ -19773,22 +19872,28 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, if (info->attrs[NL80211_ATTR_MLO_LINK_ID] || (wdev && wdev->valid_links)) { err = -EINVAL; - goto out_unlock; + goto out; } } - if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { - wiphy_lock(&rdev->wiphy); - /* we keep the mutex locked until post_doit */ + info->user_ptr[0] = rdev; + /* we keep the mutex locked until post_doit */ + if (locked) __release(&rdev->wiphy.mtx); - } - if (!(internal_flags & NL80211_FLAG_NEED_RTNL)) - rtnl_unlock(); return 0; -out_unlock: - rtnl_unlock(); +out: + if (locked) + wiphy_unlock(&rdev->wiphy); dev_put(dev); + if (need_rtnl) + rtnl_unlock(); + return err; +out_lookup: + if (need_rtnl) + rtnl_unlock(); + else + rcu_read_unlock(); return err; } From 197d5f64e3bbb143d5fc27f4afbf772bfcd232de Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:03 +0200 Subject: [PATCH 1428/2126] wifi: nl80211: don't take rtnl for most dumps Most (wdev-related) dumps also take RTNL just for lookup. Apply the same logic as for pre_doit() in the previous commit to avoid the RTNL. Since I refactored the checks there into a helper to use here, it even simplifies the code. Link: https://patch.msgid.link/20261006120655.37954ad94c77.Ica4719b0054c949abf2528d9c4c13a5d6b7a1a49@changeid Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 67 +++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index ee18100de8f8..70fa69a9115d 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1304,6 +1304,8 @@ static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, struct wireless_dev **wdev, struct nlattr **attrbuf) { + struct net *netns = sock_net(cb->skb->sk); + u32 wdev_id; int err; if (!cb->args[0]) { @@ -1325,61 +1327,38 @@ static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, return err; } - rtnl_lock(); - *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk), - attrbuf); + rcu_read_lock(); + *wdev = __cfg80211_wdev_from_attrs(NULL, netns, attrbuf); kfree(attrbuf_free); if (IS_ERR(*wdev)) { - rtnl_unlock(); + rcu_read_unlock(); return PTR_ERR(*wdev); } *rdev = wiphy_to_rdev((*wdev)->wiphy); - mutex_lock(&(*rdev)->wiphy.mtx); - rtnl_unlock(); - /* 0 is the first index - add 1 to parse only once */ - cb->args[0] = (*rdev)->wiphy_idx + 1; - cb->args[1] = (*wdev)->identifier; + wdev_id = (*wdev)->identifier; } else { /* subtract the 1 again here */ - struct wiphy *wiphy; - struct wireless_dev *tmp; - - rtnl_lock(); - wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); - if (!wiphy) { - rtnl_unlock(); + rcu_read_lock(); + *rdev = cfg80211_rdev_by_wiphy_idx(cb->args[0] - 1); + if (!*rdev) { + rcu_read_unlock(); return -ENODEV; } - - /* - * The first invocation validated the wdev's netns against - * the caller via __cfg80211_wdev_from_attrs(). The wiphy - * may have moved netns between dumpit invocations (via - * NL80211_CMD_SET_WIPHY_NETNS), so re-check here. - */ - if (!net_eq(wiphy_net(wiphy), sock_net(cb->skb->sk))) { - rtnl_unlock(); - return -ENODEV; - } - - *rdev = wiphy_to_rdev(wiphy); - *wdev = NULL; - - list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { - if (tmp->identifier == cb->args[1]) { - *wdev = tmp; - break; - } - } - - if (!*wdev) { - rtnl_unlock(); - return -ENODEV; - } - mutex_lock(&(*rdev)->wiphy.mtx); - rtnl_unlock(); + wdev_id = cb->args[1]; } + get_device(&(*rdev)->wiphy.dev); + rcu_read_unlock(); + + /* things may have changed since the lookup or the last dumpit call */ + *wdev = nl80211_lock_and_recheck(*rdev, netns, wdev_id); + if (IS_ERR(*wdev)) + return PTR_ERR(*wdev); + + /* 0 is the first index - add 1 to parse only once */ + cb->args[0] = (*rdev)->wiphy_idx + 1; + cb->args[1] = wdev_id; + return 0; } From e44b2bf77d7c409a9903e085d4c7867e9e574feb Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:04 +0200 Subject: [PATCH 1429/2126] wifi: cfg80211: reg: update channels under wiphy mutex Regulatory code updates channels holding only RTNL. Since I removed RTNL everywhere, most reading code doesn't take it, so it races with the updates. Update the relevant regulatory data under wiphy mutex to avoid (most of?) those races. Some drivers acquire the wiphy mutex, so don't cover the calls to the regulatory notifiers. For beacon hints the order of operation changes, and the driver notifier will be called only once later, but that seems acceptable (even better) to drivers as I see it. Link: https://patch.msgid.link/20261006120655.8c614b6d2f40.Id85777e278fbcf05b1ae1c42d2424acf6ed75fd6@changeid Signed-off-by: Johannes Berg --- net/wireless/reg.c | 55 ++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 27ba860f0391..1626a9b7c7c9 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -2151,31 +2151,32 @@ static void reg_call_notifier(struct wiphy *wiphy, wiphy->reg_notifier(wiphy, request); } -static void handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx, +static bool handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx, struct reg_beacon *reg_beacon) { struct ieee80211_supported_band *sband; struct ieee80211_channel *chan; bool channel_changed = false; struct ieee80211_channel chan_before; - struct regulatory_request *lr = get_last_request(); + + lockdep_assert_wiphy(wiphy); sband = wiphy->bands[reg_beacon->chan.band]; chan = &sband->channels[chan_idx]; if (likely(!ieee80211_channel_equal(chan, ®_beacon->chan))) - return; + return false; if (chan->beacon_found) - return; + return false; chan->beacon_found = true; if (!reg_is_world_roaming(wiphy)) - return; + return false; if (wiphy->regulatory_flags & REGULATORY_DISABLE_BEACON_HINTS) - return; + return false; chan_before = *chan; @@ -2184,11 +2185,10 @@ static void handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx, channel_changed = true; } - if (channel_changed) { + if (channel_changed) nl80211_send_beacon_hint_event(wiphy, &chan_before, chan); - if (wiphy->flags & WIPHY_FLAG_CHANNEL_CHANGE_ON_BEACON) - reg_call_notifier(wiphy, lr); - } + + return channel_changed; } /* @@ -2200,14 +2200,20 @@ static void wiphy_update_new_beacon(struct wiphy *wiphy, { unsigned int i; struct ieee80211_supported_band *sband; + bool changed = false; if (!wiphy->bands[reg_beacon->chan.band]) return; sband = wiphy->bands[reg_beacon->chan.band]; - for (i = 0; i < sband->n_channels; i++) - handle_reg_beacon(wiphy, i, reg_beacon); + scoped_guard(wiphy, wiphy) { + for (i = 0; i < sband->n_channels; i++) + changed |= handle_reg_beacon(wiphy, i, reg_beacon); + } + + if (changed && wiphy->flags & WIPHY_FLAG_CHANNEL_CHANGE_ON_BEACON) + reg_call_notifier(wiphy, get_last_request()); } /* @@ -2552,11 +2558,15 @@ static void wiphy_update_regulatory(struct wiphy *wiphy, lr->dfs_region = get_cfg80211_regdom()->dfs_region; - for (band = 0; band < NUM_NL80211_BANDS; band++) - handle_band(wiphy, initiator, wiphy->bands[band]); + /* the notifier is called below, so ignore beacon hint changes */ + scoped_guard(wiphy, wiphy) { + for (band = 0; band < NUM_NL80211_BANDS; band++) + handle_band(wiphy, initiator, wiphy->bands[band]); + + reg_process_beacons(wiphy); + reg_process_ht_flags(wiphy); + } - reg_process_beacons(wiphy); - reg_process_ht_flags(wiphy); reg_call_notifier(wiphy, lr); } @@ -3172,12 +3182,14 @@ static void reg_process_pending_beacon_hints(void) { struct cfg80211_registered_device *rdev; struct reg_beacon *pending_beacon, *tmp; + LIST_HEAD(pending); /* This goes through the _pending_ beacon list */ spin_lock_bh(®_pending_beacons_lock); + list_splice_tail_init(®_pending_beacons, &pending); + spin_unlock_bh(®_pending_beacons_lock); - list_for_each_entry_safe(pending_beacon, tmp, - ®_pending_beacons, list) { + list_for_each_entry_safe(pending_beacon, tmp, &pending, list) { list_del_init(&pending_beacon->list); /* Applies the beacon hint to current wiphys */ @@ -3187,8 +3199,6 @@ static void reg_process_pending_beacon_hints(void) /* Remembers the beacon hint for new wiphys or reg changes */ list_add_tail(&pending_beacon->list, ®_beacon_list); } - - spin_unlock_bh(®_pending_beacons_lock); } static void reg_process_self_managed_hint(struct wiphy *wiphy) @@ -3577,8 +3587,11 @@ static void restore_regulatory_settings(bool reset_user, bool cached) for_each_rdev(rdev) { if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) continue; - if (rdev->wiphy.regulatory_flags & REGULATORY_CUSTOM_REG) + if (rdev->wiphy.regulatory_flags & REGULATORY_CUSTOM_REG) { + guard(wiphy)(&rdev->wiphy); + restore_custom_reg_settings(&rdev->wiphy); + } } if (cached && (!is_an_alpha2(alpha2) || From 379d1a3471075321c246944d97cdf41109186c1b Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:05 +0200 Subject: [PATCH 1430/2126] wifi: cfg80211: reg: set intersected regd under wiphy mutex When regulatory request is intersected, the wiphy's regd is replaced holding only the RTNL, while the non-intersected case holds the wiphy mutex - we document access to need it. Current readers that don't hold RTNL also don't get into it, but it's more consistent and I want to remove the RTNL later. Also move the similar code in reg_process_hint_driver() to the same pattern as preparation. Link: https://patch.msgid.link/20261006120655.a60980246fcb.Id7ac6e91aecb976f1897aa3a211a3eb7c871831e@changeid Signed-off-by: Johannes Berg --- net/wireless/reg.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 1626a9b7c7c9..13d6fc5a56aa 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -2865,12 +2865,12 @@ reg_process_hint_driver(struct wiphy *wiphy, if (IS_ERR(regd)) return REG_REQ_IGNORE; - tmp = get_wiphy_regdom(wiphy); ASSERT_RTNL(); scoped_guard(wiphy, wiphy) { + tmp = get_wiphy_regdom(wiphy); rcu_assign_pointer(wiphy->regd, regd); + rcu_free_regdom(tmp); } - rcu_free_regdom(tmp); } @@ -3952,9 +3952,11 @@ static int reg_set_rd_driver(const struct ieee80211_regdomain *rd, * However if a driver requested this specific regulatory * domain we keep it for its private use */ - tmp = get_wiphy_regdom(request_wiphy); - rcu_assign_pointer(request_wiphy->regd, rd); - rcu_free_regdom(tmp); + scoped_guard(wiphy, request_wiphy) { + tmp = get_wiphy_regdom(request_wiphy); + rcu_assign_pointer(request_wiphy->regd, rd); + rcu_free_regdom(tmp); + } rd = NULL; From 18b54e7928b47945f78a96f8d1cc134869f27445 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:06 +0200 Subject: [PATCH 1431/2126] wifi: cfg80211: update channel DFS data under wiphy mutex We check the DFS data for a channel under wiphy mutex, but the code sometimes writes it under RTNL only. Fix that to avoid data races and to prepare things for later removal of the RTNL here. cfg80211_dfs_channels_update_work() must change a bit more to do this, since it locks other wiphys and nesting locks is, while possible, too difficult: track the changes in an array and update everything afterwards. Link: https://patch.msgid.link/20261006120655.e90b467f7739.I9074ec4427736f66fd5d9d47a53ccd94a1f260bf@changeid Signed-off-by: Johannes Berg --- net/wireless/mlme.c | 90 +++++++++++++++++++++++++++++++++++++-------- net/wireless/reg.c | 6 ++- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index a0d1cde26f0c..131039b675fe 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c @@ -1070,18 +1070,49 @@ void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev) queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, 0); } +struct cfg80211_dfs_chan_expiry { + struct ieee80211_channel *chan; + unsigned long entered; + enum nl80211_dfs_state state; + enum nl80211_radar_event event; +}; + +static bool cfg80211_dfs_chan_expire(struct cfg80211_registered_device *rdev, + struct cfg80211_dfs_chan_expiry *exp, + struct cfg80211_chan_def *chandef) +{ + struct ieee80211_channel *c = exp->chan; + + guard(wiphy)(&rdev->wiphy); + + /* the state may have changed while the wiphy wasn't locked */ + if (c->dfs_state != exp->state || c->dfs_state_entered != exp->entered) + return false; + + c->dfs_state = NL80211_DFS_USABLE; + c->dfs_state_entered = jiffies; + + cfg80211_chandef_create(chandef, c, NL80211_CHAN_NO_HT); + + nl80211_radar_notify(rdev, chandef, exp->event, NULL, GFP_KERNEL); + + return true; +} + void cfg80211_dfs_channels_update_work(struct work_struct *work) { struct delayed_work *delayed_work = to_delayed_work(work); + struct cfg80211_dfs_chan_expiry *expired; struct cfg80211_registered_device *rdev; struct cfg80211_chan_def chandef; struct ieee80211_supported_band *sband; struct ieee80211_channel *c; struct wiphy *wiphy; - bool check_again = false; + bool check_again = false, pre_cac_allowed; unsigned long timeout, next_time = 0; unsigned long time_dfs_update; enum nl80211_radar_event radar_event; + unsigned int n_chans = 0, n_expired = 0; int bandid, i; rdev = container_of(delayed_work, struct cfg80211_registered_device, @@ -1089,6 +1120,25 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) wiphy = &rdev->wiphy; rtnl_lock(); + wiphy_lock(wiphy); + for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) { + if (wiphy->bands[bandid]) + n_chans += wiphy->bands[bandid]->n_channels; + } + + expired = kvcalloc(n_chans, sizeof(*expired), GFP_KERNEL); + if (!expired) { + /* hmm - retry later */ + queue_delayed_work(cfg80211_wq, + &rdev->dfs_update_channels_wk, + HZ); + wiphy_unlock(wiphy); + rtnl_unlock(); + return; + } + + pre_cac_allowed = regulatory_pre_cac_allowed(wiphy); + for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) { sband = wiphy->bands[bandid]; if (!sband) @@ -1108,8 +1158,7 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) time_dfs_update = IEEE80211_DFS_MIN_NOP_TIME_MS; radar_event = NL80211_RADAR_NOP_FINISHED; } else { - if (regulatory_pre_cac_allowed(wiphy) || - cfg80211_any_wiphy_oper_chan(wiphy, c)) + if (pre_cac_allowed) continue; time_dfs_update = REG_PRE_CAC_EXPIRY_GRACE_MS; @@ -1120,19 +1169,11 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) msecs_to_jiffies(time_dfs_update); if (time_after_eq(jiffies, timeout)) { - c->dfs_state = NL80211_DFS_USABLE; - c->dfs_state_entered = jiffies; - - cfg80211_chandef_create(&chandef, c, - NL80211_CHAN_NO_HT); - - nl80211_radar_notify(rdev, &chandef, - radar_event, NULL, - GFP_ATOMIC); - - regulatory_propagate_dfs_state(wiphy, &chandef, - c->dfs_state, - radar_event); + expired[n_expired].chan = c; + expired[n_expired].state = c->dfs_state; + expired[n_expired].entered = c->dfs_state_entered; + expired[n_expired].event = radar_event; + n_expired++; continue; } @@ -1143,8 +1184,25 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) check_again = true; } } + wiphy_unlock(wiphy); + + /* these lock the wiphys, so must be done without holding ours */ + for (i = 0; i < n_expired; i++) { + if (expired[i].event == NL80211_RADAR_PRE_CAC_EXPIRED && + cfg80211_any_wiphy_oper_chan(wiphy, expired[i].chan)) + continue; + + if (!cfg80211_dfs_chan_expire(rdev, &expired[i], &chandef)) + continue; + + regulatory_propagate_dfs_state(wiphy, &chandef, + NL80211_DFS_USABLE, + expired[i].event); + } rtnl_unlock(); + kvfree(expired); + /* reschedule if there are other channels waiting to be cleared again */ if (check_again) queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 13d6fc5a56aa..a7602d6d4c64 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -3060,6 +3060,8 @@ static void wiphy_all_share_dfs_chan_state(struct wiphy *wiphy) ASSERT_RTNL(); + guard(wiphy)(wiphy); + for_each_rdev(rdev) { if (wiphy == &rdev->wiphy) continue; @@ -4276,7 +4278,7 @@ static void cfg80211_check_and_end_cac(struct cfg80211_registered_device *rdev) struct wireless_dev *wdev; unsigned int link_id; - guard(wiphy)(&rdev->wiphy); + lockdep_assert_wiphy(&rdev->wiphy); /* If we finished CAC or received radar, we should end any * CAC running on the same channels. @@ -4327,6 +4329,8 @@ void regulatory_propagate_dfs_state(struct wiphy *wiphy, chandef->chan->center_freq)) continue; + guard(wiphy)(&rdev->wiphy); + cfg80211_set_dfs_state(&rdev->wiphy, chandef, dfs_state); if (event == NL80211_RADAR_DETECTED || From 666a90322677f3444aa64674a5dd57e728414e07 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:07 +0200 Subject: [PATCH 1432/2126] wifi: mac80211_hwsim: call cfg80211 event with wiphy mutex These functions really require the wiphy mutex (though they're not yet documented as such), call them with it. Link: https://patch.msgid.link/20261006120655.34c6cd54cb9d.I4a45533cc3a020c472f7d90f33e854d7a89b2d3a@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 832e05573015..ce06867ff01e 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -1133,6 +1133,8 @@ static ssize_t hwsim_background_cac_write(struct file *file, if (copy_from_user(buf, user_buf, count)) return -EFAULT; + guard(wiphy)(data->hw->wiphy); + /* Check if background radar channel is configured */ if (!data->radar_background_chandef.chan) return -ENOENT; From d35dec0124b787a480d31f7afa41d5b81fc43b12 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:08 +0200 Subject: [PATCH 1433/2126] wifi: cfg80211: document wiphy mutex for radar/CAC events The DFS state of channels and the CAC state of the wdev is protected by the wiphy mutex, so the radar and CAC events must be reported by drivers with the wiphy mutex held. In mac80211 we do this, but some drivers don't yet: - mwifiex/nxpwifi have an event handling worker, - qtnfmac also does it from event processing, and - mt7915 and mt7996 don't acquire a mutex for background radar events. Document the requirement. Link: https://patch.msgid.link/20261006120655.6fba1ce72650.I57002ac3e57d2ac4613eb0cb0e6d17bedccf0cbd@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index d4a77f9fe0b7..5ae97e72cef2 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -9808,6 +9808,7 @@ void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp); * @gfp: context flags * * This function is called when a radar is detected on the current chanenl. + * Must be called with the wiphy mutex held. */ void __cfg80211_radar_event(struct wiphy *wiphy, struct cfg80211_chan_def *chandef, @@ -9853,7 +9854,7 @@ void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, * * This function is called when a Channel availability check (CAC) is finished * or aborted. This must be called to notify the completion of a CAC process, - * also by full-MAC drivers. + * also by full-MAC drivers. Must be called with the wiphy mutex held. */ void cfg80211_cac_event(struct net_device *netdev, const struct cfg80211_chan_def *chandef, From 294e01e7ac92e4d518e9aba029846412e83b63f6 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:09 +0200 Subject: [PATCH 1434/2126] wifi: cfg80211: add a mutex for regulatory/device list The global regulatory state is currently protected by the RTNL (which is the new BKL). Prepare for further reducing our dependency on it by adding a new mutex that protects this data (as well, for now held inside RTNL) and the wiphy list (so that regulatory code can walk it). Link: https://patch.msgid.link/20261006120655.501ac570dbcc.I5db33ad005ac5877d806e140ed0c41c464a7e5aa@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 13 ++++++++- net/wireless/core.h | 3 ++ net/wireless/mlme.c | 3 ++ net/wireless/nl80211.c | 2 ++ net/wireless/reg.c | 66 ++++++++++++++++++++++++++++++------------ 5 files changed, 68 insertions(+), 19 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index 270fb30e5265..deb3889ffeff 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -42,7 +42,9 @@ MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("wireless configuration support"); MODULE_ALIAS_GENL_FAMILY(NL80211_GENL_NAME); -/* RCU-protected (and RTNL for writers) */ +DEFINE_MUTEX(cfg80211_mutex); + +/* RCU-protected (writes under both RTNL/cfg80211_mutex) */ LIST_HEAD(cfg80211_rdev_list); int cfg80211_rdev_list_generation; @@ -565,11 +567,13 @@ static void cfg80211_propagate_radar_detect_wk(struct work_struct *work) propagate_radar_detect_wk); rtnl_lock(); + mutex_lock(&cfg80211_mutex); regulatory_propagate_dfs_state(&rdev->wiphy, &rdev->radar_chandef, NL80211_DFS_UNAVAILABLE, NL80211_RADAR_DETECTED); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); } @@ -581,11 +585,13 @@ static void cfg80211_propagate_cac_done_wk(struct work_struct *work) propagate_cac_done_wk); rtnl_lock(); + mutex_lock(&cfg80211_mutex); regulatory_propagate_dfs_state(&rdev->wiphy, &rdev->cac_done_chandef, NL80211_DFS_AVAILABLE, NL80211_RADAR_CAC_FINISHED); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); } @@ -1243,10 +1249,12 @@ int wiphy_register(struct wiphy *wiphy) rdev->wiphy.bss_param_support |= WIPHY_BSS_PARAM_P2P_OPPPS; rtnl_lock(); + mutex_lock(&cfg80211_mutex); wiphy_lock(&rdev->wiphy); res = device_add(&rdev->wiphy.dev); if (res) { wiphy_unlock(&rdev->wiphy); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); return res; } @@ -1320,6 +1328,7 @@ int wiphy_register(struct wiphy *wiphy) break; } } + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); res = rfkill_register(rdev->wiphy.rfkill); @@ -1391,6 +1400,7 @@ void wiphy_unregister(struct wiphy *wiphy) rfkill_unregister(rdev->wiphy.rfkill); rtnl_lock(); + mutex_lock(&cfg80211_mutex); wiphy_lock(&rdev->wiphy); nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY); rdev->wiphy.registered = false; @@ -1422,6 +1432,7 @@ void wiphy_unregister(struct wiphy *wiphy) /* surely nothing is reachable now, clean up work */ cfg80211_process_wiphy_works(rdev, NULL); wiphy_unlock(&rdev->wiphy); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); /* this has nothing to do now but make sure it's gone */ diff --git a/net/wireless/core.h b/net/wireless/core.h index 58445c09026a..414ce31af60c 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -19,6 +19,9 @@ #include "reg.h" +/* protects the wiphy list and regulatory state */ +extern struct mutex cfg80211_mutex; + #define WIPHY_IDX_INVALID -1 struct cfg80211_scan_request_int { diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index 131039b675fe..082590d859e9 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c @@ -1120,6 +1120,7 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) wiphy = &rdev->wiphy; rtnl_lock(); + mutex_lock(&cfg80211_mutex); wiphy_lock(wiphy); for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) { if (wiphy->bands[bandid]) @@ -1133,6 +1134,7 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) &rdev->dfs_update_channels_wk, HZ); wiphy_unlock(wiphy); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); return; } @@ -1199,6 +1201,7 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) NL80211_DFS_USABLE, expired[i].event); } + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); kvfree(expired); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 70fa69a9115d..ac6f02935121 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -11057,6 +11057,7 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) } rtnl_lock(); + mutex_lock(&cfg80211_mutex); if (!reg_is_valid_request(alpha2)) { r = -EINVAL; goto out; @@ -11104,6 +11105,7 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) bad_reg: kfree(rd); out: + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); return r; } diff --git a/net/wireless/reg.c b/net/wireless/reg.c index a7602d6d4c64..46643d9ce28d 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -88,7 +88,7 @@ static struct regulatory_request core_request_world = { /* * Receipt of information from last regulatory request, - * protected by RTNL (and can be accessed with RCU protection) + * protected by cfg80211_mutex (and can be accessed with RCU protection) */ static struct regulatory_request __rcu *last_request = (void __force __rcu *)&core_request_world; @@ -100,14 +100,14 @@ static struct faux_device *reg_fdev; * Central wireless core regulatory domains, we only need two, * the current one and a world regulatory domain in case we have no * information to give us an alpha2. - * (protected by RTNL, can be read under RCU) + * (protected by cfg80211_mutex, can be read under RCU) */ const struct ieee80211_regdomain __rcu *cfg80211_regdomain; /* * Number of devices that registered to the core * that support cellular base station regulatory hints - * (protected by RTNL) + * (protected by cfg80211_mutex) */ static int reg_num_devs_support_basehint; @@ -128,7 +128,9 @@ static void reg_process_hint(struct regulatory_request *reg_request); static const struct ieee80211_regdomain *get_cfg80211_regdom(void) { - return rcu_dereference_rtnl(cfg80211_regdomain); + return rcu_dereference_check(cfg80211_regdomain, + lockdep_is_held(&cfg80211_mutex) || + lockdep_rtnl_is_held()); } /* @@ -204,7 +206,9 @@ static void rcu_free_regdom(const struct ieee80211_regdomain *r) static struct regulatory_request *get_last_request(void) { - return rcu_dereference_rtnl(last_request); + return rcu_dereference_check(last_request, + lockdep_is_held(&cfg80211_mutex) || + lockdep_rtnl_is_held()); } /* Used to queue up regulatory hints */ @@ -314,7 +318,7 @@ static void reset_regdomains(bool full_reset, { const struct ieee80211_regdomain *r; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); r = get_cfg80211_regdom(); @@ -456,7 +460,7 @@ reg_copy_regd(const struct ieee80211_regdomain *src_regd) static void cfg80211_save_user_regdom(const struct ieee80211_regdomain *rd) { - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); if (!IS_ERR(cfg80211_user_regdom)) kfree(cfg80211_user_regdom); @@ -476,6 +480,7 @@ static void reg_regdb_apply(struct work_struct *work) struct reg_regdb_apply_request *request; rtnl_lock(); + mutex_lock(&cfg80211_mutex); mutex_lock(®_regdb_apply_mutex); while (!list_empty(®_regdb_apply_list)) { @@ -489,6 +494,7 @@ static void reg_regdb_apply(struct work_struct *work) } mutex_unlock(®_regdb_apply_mutex); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); } @@ -527,8 +533,10 @@ static void crda_timeout_work(struct work_struct *work) { pr_debug("Timeout while waiting for CRDA to reply, restoring regulatory settings\n"); rtnl_lock(); + mutex_lock(&cfg80211_mutex); reg_crda_timeouts++; restore_regulatory_settings(true, false); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); } @@ -973,8 +981,12 @@ static int regdb_query_country(const struct fwdb_header *db, static int query_regdb(const char *alpha2) { - const struct fwdb_header *regdb = rtnl_dereference(global_regdb); const struct fwdb_country *country; + const struct fwdb_header *regdb; + + regdb = rcu_dereference_protected(global_regdb, + lockdep_rtnl_is_held() || + lockdep_is_held(&cfg80211_mutex)); if (IS_ERR(regdb)) return PTR_ERR(regdb); @@ -1005,7 +1017,10 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) } rtnl_lock(); - regdb = rtnl_dereference(global_regdb); + mutex_lock(&cfg80211_mutex); + regdb = rcu_dereference_protected(global_regdb, + lockdep_rtnl_is_held() || + lockdep_is_held(&cfg80211_mutex)); if (regdb && !IS_ERR(regdb)) { /* negative case - a bug * positive case - can happen due to race in case of multiple cb's in @@ -1028,6 +1043,7 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) if (restore) restore_regulatory_settings(true, false); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); kfree(context); @@ -1041,7 +1057,7 @@ static int query_regdb_file(const char *alpha2) { int err; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); if (rcu_access_pointer(global_regdb)) return query_regdb(alpha2); @@ -1083,7 +1099,10 @@ int reg_reload_regdb(void) } rtnl_lock(); - old = rcu_replace_pointer_rtnl(global_regdb, db); + mutex_lock(&cfg80211_mutex); + old = rcu_replace_pointer(global_regdb, db, + lockdep_rtnl_is_held() || + lockdep_is_held(&cfg80211_mutex)); /* reset regulatory domain */ current_regdomain = get_cfg80211_regdom(); @@ -1103,6 +1122,7 @@ int reg_reload_regdb(void) reg_process_hint(request); out_unlock: + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); if (!IS_ERR_OR_NULL(old)) { @@ -2575,7 +2595,7 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) struct cfg80211_registered_device *rdev; struct wiphy *wiphy; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); for_each_rdev(rdev) { wiphy = &rdev->wiphy; @@ -2865,7 +2885,7 @@ reg_process_hint_driver(struct wiphy *wiphy, if (IS_ERR(regd)) return REG_REQ_IGNORE; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); scoped_guard(wiphy, wiphy) { tmp = get_wiphy_regdom(wiphy); rcu_assign_pointer(wiphy->regd, regd); @@ -3058,7 +3078,7 @@ static void wiphy_all_share_dfs_chan_state(struct wiphy *wiphy) { struct cfg80211_registered_device *rdev; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); guard(wiphy)(wiphy); @@ -3246,7 +3266,7 @@ static void reg_process_self_managed_hints(void) { struct cfg80211_registered_device *rdev; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); for_each_rdev(rdev) { guard(wiphy)(&rdev->wiphy); @@ -3260,9 +3280,11 @@ static void reg_process_self_managed_hints(void) static void reg_todo(struct work_struct *work) { rtnl_lock(); + mutex_lock(&cfg80211_mutex); reg_process_pending_hints(); reg_process_pending_beacon_hints(); reg_process_self_managed_hints(); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); } @@ -3542,7 +3564,7 @@ static void restore_regulatory_settings(bool reset_user, bool cached) LIST_HEAD(tmp_reg_req_list); struct cfg80211_registered_device *rdev; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); /* * Clear the indoor setting in case that it is not controlled by user @@ -3660,6 +3682,8 @@ static bool is_wiphy_all_set_reg_flag(enum ieee80211_regulatory_flags flag) void regulatory_hint_disconnect(void) { + guard(mutex)(&cfg80211_mutex); + /* Restore of regulatory settings is not required when wiphy(s) * ignore IE from connected access point but clearance of beacon hints * is required when wiphy(s) supports beacon hints. @@ -3928,7 +3952,7 @@ static int reg_set_rd_driver(const struct ieee80211_regdomain *rd, return -ENODEV; if (!driver_request->intersect) { - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); scoped_guard(wiphy, request_wiphy) { if (request_wiphy->regd) tmp = get_wiphy_regdom(request_wiphy); @@ -4148,6 +4172,8 @@ void wiphy_regulatory_register(struct wiphy *wiphy) { struct regulatory_request *lr = get_last_request(); + lockdep_assert_held(&cfg80211_mutex); + /* self-managed devices ignore beacon hints and country IE */ if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | @@ -4175,6 +4201,8 @@ void wiphy_regulatory_deregister(struct wiphy *wiphy) struct wiphy *request_wiphy = NULL; struct regulatory_request *lr; + lockdep_assert_held(&cfg80211_mutex); + lr = get_last_request(); if (!reg_dev_ignore_cell_hint(wiphy)) @@ -4313,7 +4341,7 @@ void regulatory_propagate_dfs_state(struct wiphy *wiphy, { struct cfg80211_registered_device *rdev; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); if (WARN_ON(!cfg80211_chandef_valid(chandef))) return; @@ -4423,7 +4451,9 @@ void regulatory_exit(void) /* Lock to suppress warnings */ rtnl_lock(); + mutex_lock(&cfg80211_mutex); reset_regdomains(true, NULL); + mutex_unlock(&cfg80211_mutex); rtnl_unlock(); dev_set_uevent_suppress(®_fdev->dev, true); From 17789024e059a0985caf3943b860b615a5cf6d8d Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:10 +0200 Subject: [PATCH 1435/2126] wifi: cfg80211: allow walking wiphy list under cfg80211_mutex for_each_rdev() now requires RTNL, but we can relax that and allow any of RTNL, cfg80211_mutex and RCU, and then use it in quite a few more places. Link: https://patch.msgid.link/20261006120655.1733560fc2af.I1a0c57a5d2238203b6252b189a7ca16d042888a7@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 16 +++++----------- net/wireless/core.h | 11 +++-------- net/wireless/nl80211.c | 11 +++++------ net/wireless/reg.c | 2 +- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index deb3889ffeff..75d5727d8673 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -59,20 +59,16 @@ module_param(cfg80211_disable_40mhz_24ghz, bool, 0644); MODULE_PARM_DESC(cfg80211_disable_40mhz_24ghz, "Disable 40MHz support in the 2.4GHz band"); -/* requires RCU or rtnl */ struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx) { - struct cfg80211_registered_device *result = NULL, *rdev; + struct cfg80211_registered_device *rdev; - list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list, - lockdep_rtnl_is_held()) { - if (rdev->wiphy_idx == wiphy_idx) { - result = rdev; - break; - } + for_each_rdev(rdev) { + if (rdev->wiphy_idx == wiphy_idx) + return rdev; } - return result; + return NULL; } int get_wiphy_idx(struct wiphy *wiphy) @@ -86,8 +82,6 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx) { struct cfg80211_registered_device *rdev; - ASSERT_RTNL(); - rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx); if (!rdev) return NULL; diff --git a/net/wireless/core.h b/net/wireless/core.h index 414ce31af60c..dfcb9ed5035b 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -182,15 +182,10 @@ extern struct workqueue_struct *cfg80211_wq; extern struct list_head cfg80211_rdev_list; extern int cfg80211_rdev_list_generation; -/* This is constructed like this so it can be used in if/else */ -static inline int for_each_rdev_check_rtnl(void) -{ - ASSERT_RTNL(); - return 0; -} #define for_each_rdev(rdev) \ - if (for_each_rdev_check_rtnl()) {} else \ - list_for_each_entry(rdev, &cfg80211_rdev_list, list) + list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list, \ + lockdep_rtnl_is_held() || \ + lockdep_is_held(&cfg80211_mutex)) enum bss_source_type { BSS_SOURCE_DIRECT = 0, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index ac6f02935121..34642b48ba8a 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -63,7 +63,7 @@ static const struct genl_multicast_group nl80211_mcgrps[] = { #endif }; -/* returns ERR_PTR values, requires RCU or rtnl if rdev is %NULL */ +/* returns ERR_PTR values, requires RCU/cfg80211_mutex/RTNL if rdev is %NULL */ static struct wireless_dev * __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, struct net *netns, struct nlattr **attrs) @@ -105,8 +105,7 @@ __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, return result ?: ERR_PTR(-ENODEV); } - list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list, - lockdep_rtnl_is_held()) { + for_each_rdev(rdev) { struct wireless_dev *wdev; if (wiphy_net(&rdev->wiphy) != netns) @@ -137,7 +136,7 @@ __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, return ERR_PTR(-ENODEV); } -/* requires RCU or rtnl */ +/* requires RCU/cfg80211_mutex/RTNL */ static struct cfg80211_registered_device * __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) { @@ -10954,7 +10953,7 @@ static int nl80211_get_reg_dump(struct sk_buff *skb, /* the global regdom is idx 0 */ reg_idx = 1; - list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { + for_each_rdev(rdev) { regdom = get_wiphy_regdom(&rdev->wiphy); if (!regdom) continue; @@ -23452,7 +23451,7 @@ static int nl80211_netlink_notify(struct notifier_block * nb, rcu_read_lock(); - list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { + for_each_rdev(rdev) { struct cfg80211_sched_scan_request *sched_scan_req; list_for_each_entry_rcu(sched_scan_req, diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 46643d9ce28d..7ac770a90a4b 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -2539,7 +2539,7 @@ static void reg_check_chans_work(struct work_struct *work) rcu_read_lock(); - list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) + for_each_rdev(rdev) wiphy_work_queue(&rdev->wiphy, &rdev->reg_check_chans_wk); rcu_read_unlock(); From 97de01e4e86828f08cc2c7087ff2de0654779099 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:11 +0200 Subject: [PATCH 1436/2126] wifi: ath: use freq_reg_info() under RCU This will soon be required, because there won't be the RTNL to protect everything. Use RCU for freq_reg_info(). Link: https://patch.msgid.link/20261006120655.b619ce4ac9a8.I44fbb6c36186a6b14a68d6f8f1010c30c69441bd@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/regd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/ath/regd.c b/drivers/net/wireless/ath/regd.c index f15e7bd690b5..cedb5e43b9e4 100644 --- a/drivers/net/wireless/ath/regd.c +++ b/drivers/net/wireless/ath/regd.c @@ -268,6 +268,8 @@ static void ath_force_clear_no_ir_chan(struct wiphy *wiphy, { const struct ieee80211_reg_rule *reg_rule; + guard(rcu)(); + reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(ch->center_freq)); if (IS_ERR(reg_rule)) return; From 3118fac30649877eb555878c0c3b0ddc99ce81a4 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:12 +0200 Subject: [PATCH 1437/2126] wifi: brcmsmac: use freq_reg_info() under RCU This will soon be required, because there won't be the RTNL to protect everything. Use RCU for freq_reg_info(). Link: https://patch.msgid.link/20261006120655.d7994c4ac0dc.If1ffc9864b3557ec046c705286e974218a32d9cc@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/brcm80211/brcmsmac/channel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/channel.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/channel.c index cdfe8635c012..5ca8a0735398 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/channel.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/channel.c @@ -676,6 +676,8 @@ brcms_reg_apply_beaconing_flags(struct wiphy *wiphy, continue; if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { + guard(rcu)(); + rule = freq_reg_info(wiphy, MHZ_TO_KHZ(ch->center_freq)); if (IS_ERR(rule)) From 04655cc0d2a15a89a3869898303620094ee23e14 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:13 +0200 Subject: [PATCH 1438/2126] wifi: rtlwifi: use freq_reg_info() under RCU This will soon be required, because there won't be the RTNL to protect everything. Use RCU for freq_reg_info(). Link: https://patch.msgid.link/20261006120655.2faed090a837.I556a1b30d7d7fee64edeeefa26996d62be14cfca@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/realtek/rtlwifi/regd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/realtek/rtlwifi/regd.c b/drivers/net/wireless/realtek/rtlwifi/regd.c index fd967006b3e1..503625b50fc3 100644 --- a/drivers/net/wireless/realtek/rtlwifi/regd.c +++ b/drivers/net/wireless/realtek/rtlwifi/regd.c @@ -150,6 +150,8 @@ static void _rtl_reg_apply_beaconing_flags(struct wiphy *wiphy, (ch->flags & IEEE80211_CHAN_RADAR)) continue; if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { + guard(rcu)(); + reg_rule = freq_reg_info(wiphy, ch->center_freq); if (IS_ERR(reg_rule)) @@ -212,6 +214,8 @@ static void _rtl_reg_apply_active_scan_flags(struct wiphy *wiphy, *custom regulatory domain. */ + guard(rcu)(); + ch = &sband->channels[11]; /* CH 12 */ reg_rule = freq_reg_info(wiphy, ch->center_freq); if (!IS_ERR(reg_rule)) { From 17a3455f15c0a4edbcbad625ef227558499ea98f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:14 +0200 Subject: [PATCH 1439/2126] wifi: nl80211: read WMM reg rule under RCU freq_reg_info() returns a pointer into the current regdomain, so we need RTNL, cfg80211_mutex or RCU, but I want to remove the RTNL, so just use RCU here. Also document that this is required, we didn't say when the function could be used at all. Link: https://patch.msgid.link/20261006120655.c6fce71ad991.I07ae7ed37bc8ff6d75c87e19d77e4c5379a8e167@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 2 ++ net/wireless/nl80211.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 5ae97e72cef2..f2cf71a75b2d 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -8197,6 +8197,8 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy, * it wants to follow we respect that unless a country IE has been received * and processed already. * + * Must be called within an RCU read-side critical section. + * * Return: A valid pointer, or, when an error occurs, for example if no rule * can be found, the return value is encoded using ERR_PTR(). Use IS_ERR() to * check and PTR_ERR() to obtain the numeric return value. The numeric return diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 34642b48ba8a..e82913c9cf82 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -1540,9 +1540,10 @@ static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, goto nla_put_failure; if (large) { - const struct ieee80211_reg_rule *rule = - freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); + const struct ieee80211_reg_rule *rule; + guard(rcu)(); + rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { if (nl80211_msg_put_wmm_rules(msg, rule)) goto nla_put_failure; From 170404d5e976ee94a6c683a87af1a9fd56a4b668 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:15 +0200 Subject: [PATCH 1440/2126] wifi: ath11k: read wiphy regd under RCU Part of the RTNL removal here means the notifier will no longer hold the RTNL, so rcu_dereference_rtnl() can't be used any more. Use an RCU critical section which works either way, we don't have access to the cfg80211_mutex in the drivers. Link: https://patch.msgid.link/20261006120655.2959e1a05eb0.I92dbc5e611309de4ea3bc11fefea609a5f2d0af4@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/ath11k/reg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/reg.c b/drivers/net/wireless/ath/ath11k/reg.c index 0879a132b67c..1030e119fd90 100644 --- a/drivers/net/wireless/ath/ath11k/reg.c +++ b/drivers/net/wireless/ath/ath11k/reg.c @@ -33,7 +33,9 @@ static bool ath11k_regdom_changes(struct ath11k *ar, char *alpha2) { const struct ieee80211_regdomain *regd; - regd = rcu_dereference_rtnl(ar->hw->wiphy->regd); + guard(rcu)(); + + regd = get_wiphy_regdom(ar->hw->wiphy); /* This can happen during wiphy registration where the previous * user request is received before we update the regd received * from firmware. From a38a54c10692e5a9397b05ee2382c4750b533b45 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:16 +0200 Subject: [PATCH 1441/2126] wifi: ath12k: read wiphy regd under RCU Part of the RTNL removal here means the notifier will no longer hold the RTNL, so rcu_dereference_rtnl() can't be used any more. Use an RCU critical section which works either way, we don't have access to the cfg80211_mutex in the drivers. Link: https://patch.msgid.link/20261006120655.b59589afb302.Ieeec0e112066ccefeac6b746fdfd268611c2cc65@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/ath12k/reg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/reg.c b/drivers/net/wireless/ath/ath12k/reg.c index 89abf2e87ad1..d7065fa73c50 100644 --- a/drivers/net/wireless/ath/ath12k/reg.c +++ b/drivers/net/wireless/ath/ath12k/reg.c @@ -33,7 +33,9 @@ static bool ath12k_regdom_changes(struct ieee80211_hw *hw, char *alpha2) { const struct ieee80211_regdomain *regd; - regd = rcu_dereference_rtnl(hw->wiphy->regd); + guard(rcu)(); + + regd = get_wiphy_regdom(hw->wiphy); /* This can happen during wiphy registration where the previous * user request is received before we update the regd received * from firmware. From 8ccf97e5f67b5d383a222c41535620cc56a1d1d5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 6 Oct 2026 12:04:17 +0200 Subject: [PATCH 1442/2126] wifi: cfg80211: regulatory: stop using RTNL Now we have cfg80211_mutex everywhere along with wiphy mutex for per-device bits, so don't need RTNL any more. Remove it from the regulatory code. Also, wiphy_apply_custom_regulatory() no longer needs the RTNL, and get_wiphy_regdom() can no longer rely on it. Link: https://patch.msgid.link/20261006120655.df1d3d28cfa2.I637dbd328886b52bed511fb798172a2d57521263@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/ath/ath12k/reg.c | 2 - drivers/net/wireless/realtek/rtw89/regd.c | 3 - include/net/cfg80211.h | 9 +- net/wireless/chan.c | 2 +- net/wireless/core.c | 12 +-- net/wireless/mlme.c | 3 - net/wireless/nl80211.c | 11 +- net/wireless/reg.c | 117 ++++++++++------------ 8 files changed, 67 insertions(+), 92 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/reg.c b/drivers/net/wireless/ath/ath12k/reg.c index d7065fa73c50..7cf3dbc4fc8a 100644 --- a/drivers/net/wireless/ath/ath12k/reg.c +++ b/drivers/net/wireless/ath/ath12k/reg.c @@ -124,9 +124,7 @@ ath12k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) "failed set INIT Country code: %d\n", ret); } - wiphy_lock(wiphy); ath12k_mac_11d_scan_stop(ar); - wiphy_unlock(wiphy); ar->regdom_set_by_user = true; } diff --git a/drivers/net/wireless/realtek/rtw89/regd.c b/drivers/net/wireless/realtek/rtw89/regd.c index b9a5ce218b1d..983b42e193b5 100644 --- a/drivers/net/wireless/realtek/rtw89/regd.c +++ b/drivers/net/wireless/realtek/rtw89/regd.c @@ -898,7 +898,6 @@ void rtw89_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); struct rtw89_dev *rtwdev = hw->priv; - wiphy_lock(wiphy); rtw89_leave_ps_mode(rtwdev); if (rtwdev->regulatory.programmed) @@ -916,8 +915,6 @@ policy: rtw89_regd_apply_policy_ant_gain(rtwdev); rtw89_core_set_chip_txpwr(rtwdev); - - wiphy_unlock(wiphy); } /* Maximum Transmit Power field (@raw) can be EIRP or PSD. diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index f2cf71a75b2d..45a96c92fec3 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6362,7 +6362,8 @@ struct wiphy_nan_capa { * @mtx: mutex for the data (structures) of this device * @reg_notifier: the driver's regulatory notification callback, * note that if your driver uses wiphy_apply_custom_regulatory() - * the reg_notifier's request can be passed as NULL + * the reg_notifier's request can be passed as NULL. + * This is called under wiphy mutex. * @regd: the driver's regulatory domain, if one was requested via * the regulatory_hint() API. This can be used by the driver * on the reg_notifier() if it chooses to ignore future @@ -8160,9 +8161,9 @@ int regulatory_set_wiphy_regd(struct wiphy *wiphy, * @wiphy: the wireless device we want to process the regulatory domain on * @rd: the regulatory domain information to use for this wiphy * - * This functions requires the RTNL and the wiphy mutex to be held and - * applies the new regdomain synchronously to this wiphy. For more details - * see regulatory_set_wiphy_regd(). + * This functions requires the wiphy mutex to be held and applies the new + * regdomain synchronously to this wiphy. For more details see + * regulatory_set_wiphy_regd(). * * Return: 0 on success. -EINVAL, -EPERM */ diff --git a/net/wireless/chan.c b/net/wireless/chan.c index c743b6fb7e30..9183cd19dbdc 100644 --- a/net/wireless/chan.c +++ b/net/wireless/chan.c @@ -1243,7 +1243,7 @@ bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy, { struct cfg80211_registered_device *rdev; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); if (!(chan->flags & IEEE80211_CHAN_RADAR)) return false; diff --git a/net/wireless/core.c b/net/wireless/core.c index 75d5727d8673..01b077909179 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -560,15 +560,11 @@ static void cfg80211_propagate_radar_detect_wk(struct work_struct *work) rdev = container_of(work, struct cfg80211_registered_device, propagate_radar_detect_wk); - rtnl_lock(); - mutex_lock(&cfg80211_mutex); + guard(mutex)(&cfg80211_mutex); regulatory_propagate_dfs_state(&rdev->wiphy, &rdev->radar_chandef, NL80211_DFS_UNAVAILABLE, NL80211_RADAR_DETECTED); - - mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); } static void cfg80211_propagate_cac_done_wk(struct work_struct *work) @@ -578,15 +574,11 @@ static void cfg80211_propagate_cac_done_wk(struct work_struct *work) rdev = container_of(work, struct cfg80211_registered_device, propagate_cac_done_wk); - rtnl_lock(); - mutex_lock(&cfg80211_mutex); + guard(mutex)(&cfg80211_mutex); regulatory_propagate_dfs_state(&rdev->wiphy, &rdev->cac_done_chandef, NL80211_DFS_AVAILABLE, NL80211_RADAR_CAC_FINISHED); - - mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); } static void cfg80211_wiphy_work(struct work_struct *work) diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index 082590d859e9..96fd14f2a305 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c @@ -1119,7 +1119,6 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) dfs_update_channels_wk); wiphy = &rdev->wiphy; - rtnl_lock(); mutex_lock(&cfg80211_mutex); wiphy_lock(wiphy); for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) { @@ -1135,7 +1134,6 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) HZ); wiphy_unlock(wiphy); mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); return; } @@ -1202,7 +1200,6 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) expired[i].event); } mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); kvfree(expired); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index e82913c9cf82..a48bd4e4f4c7 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -63,7 +63,7 @@ static const struct genl_multicast_group nl80211_mcgrps[] = { #endif }; -/* returns ERR_PTR values, requires RCU/cfg80211_mutex/RTNL if rdev is %NULL */ +/* returns ERR_PTR values, requires RCU/cfg80211_mutex if rdev is %NULL */ static struct wireless_dev * __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, struct net *netns, struct nlattr **attrs) @@ -136,7 +136,7 @@ __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, return ERR_PTR(-ENODEV); } -/* requires RCU/cfg80211_mutex/RTNL */ +/* requires RCU/cfg80211_mutex */ static struct cfg80211_registered_device * __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) { @@ -11056,7 +11056,6 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) return -EINVAL; } - rtnl_lock(); mutex_lock(&cfg80211_mutex); if (!reg_is_valid_request(alpha2)) { r = -EINVAL; @@ -11106,7 +11105,6 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) kfree(rd); out: mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); return r; } #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ @@ -21210,7 +21208,10 @@ static bool nl80211_reg_change_event_fill(struct sk_buff *msg, } if (request->wiphy_idx != WIPHY_IDX_INVALID) { - struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); + struct wiphy *wiphy; + + guard(rcu)(); + wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); if (wiphy && nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 7ac770a90a4b..4efb35baeb3e 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -129,20 +129,18 @@ static void reg_process_hint(struct regulatory_request *reg_request); static const struct ieee80211_regdomain *get_cfg80211_regdom(void) { return rcu_dereference_check(cfg80211_regdomain, - lockdep_is_held(&cfg80211_mutex) || - lockdep_rtnl_is_held()); + lockdep_is_held(&cfg80211_mutex)); } /* * Returns the regulatory domain associated with the wiphy. * - * Requires any of RTNL, wiphy mutex or RCU protection. + * Requires the wiphy mutex or RCU protection. */ const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy) { return rcu_dereference_check(wiphy->regd, - lockdep_is_held(&wiphy->mtx) || - lockdep_rtnl_is_held()); + lockdep_is_held(&wiphy->mtx)); } EXPORT_SYMBOL(get_wiphy_regdom); @@ -207,8 +205,7 @@ static void rcu_free_regdom(const struct ieee80211_regdomain *r) static struct regulatory_request *get_last_request(void) { return rcu_dereference_check(last_request, - lockdep_is_held(&cfg80211_mutex) || - lockdep_rtnl_is_held()); + lockdep_is_held(&cfg80211_mutex)); } /* Used to queue up regulatory hints */ @@ -479,7 +476,6 @@ static void reg_regdb_apply(struct work_struct *work) { struct reg_regdb_apply_request *request; - rtnl_lock(); mutex_lock(&cfg80211_mutex); mutex_lock(®_regdb_apply_mutex); @@ -495,7 +491,6 @@ static void reg_regdb_apply(struct work_struct *work) mutex_unlock(®_regdb_apply_mutex); mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); } static DECLARE_WORK(reg_regdb_work, reg_regdb_apply); @@ -532,12 +527,10 @@ static DECLARE_DELAYED_WORK(crda_timeout, crda_timeout_work); static void crda_timeout_work(struct work_struct *work) { pr_debug("Timeout while waiting for CRDA to reply, restoring regulatory settings\n"); - rtnl_lock(); mutex_lock(&cfg80211_mutex); reg_crda_timeouts++; restore_regulatory_settings(true, false); mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); } static void cancel_crda_timeout(void) @@ -985,7 +978,6 @@ static int query_regdb(const char *alpha2) const struct fwdb_header *regdb; regdb = rcu_dereference_protected(global_regdb, - lockdep_rtnl_is_held() || lockdep_is_held(&cfg80211_mutex)); if (IS_ERR(regdb)) @@ -1016,10 +1008,8 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) set_error = -EINVAL; } - rtnl_lock(); mutex_lock(&cfg80211_mutex); regdb = rcu_dereference_protected(global_regdb, - lockdep_rtnl_is_held() || lockdep_is_held(&cfg80211_mutex)); if (regdb && !IS_ERR(regdb)) { /* negative case - a bug @@ -1044,7 +1034,6 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) restore_regulatory_settings(true, false); mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); kfree(context); @@ -1098,10 +1087,8 @@ int reg_reload_regdb(void) goto out; } - rtnl_lock(); mutex_lock(&cfg80211_mutex); old = rcu_replace_pointer(global_regdb, db, - lockdep_rtnl_is_held() || lockdep_is_held(&cfg80211_mutex)); /* reset regulatory domain */ @@ -1123,7 +1110,6 @@ int reg_reload_regdb(void) out_unlock: mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); if (!IS_ERR_OR_NULL(old)) { synchronize_rcu(); @@ -2167,6 +2153,8 @@ static bool reg_is_world_roaming(struct wiphy *wiphy) static void reg_call_notifier(struct wiphy *wiphy, struct regulatory_request *request) { + lockdep_assert_wiphy(wiphy); + if (wiphy->reg_notifier) wiphy->reg_notifier(wiphy, request); } @@ -2227,10 +2215,10 @@ static void wiphy_update_new_beacon(struct wiphy *wiphy, sband = wiphy->bands[reg_beacon->chan.band]; - scoped_guard(wiphy, wiphy) { - for (i = 0; i < sband->n_channels; i++) - changed |= handle_reg_beacon(wiphy, i, reg_beacon); - } + guard(wiphy)(wiphy); + + for (i = 0; i < sband->n_channels; i++) + changed |= handle_reg_beacon(wiphy, i, reg_beacon); if (changed && wiphy->flags & WIPHY_FLAG_CHANNEL_CHANGE_ON_BEACON) reg_call_notifier(wiphy, get_last_request()); @@ -2562,6 +2550,8 @@ static void wiphy_update_regulatory(struct wiphy *wiphy, enum nl80211_band band; struct regulatory_request *lr = get_last_request(); + lockdep_assert_wiphy(wiphy); + if (ignore_reg_update(wiphy, initiator)) { /* * Regulatory updates set by CORE are ignored for custom @@ -2579,13 +2569,11 @@ static void wiphy_update_regulatory(struct wiphy *wiphy, lr->dfs_region = get_cfg80211_regdom()->dfs_region; /* the notifier is called below, so ignore beacon hint changes */ - scoped_guard(wiphy, wiphy) { - for (band = 0; band < NUM_NL80211_BANDS; band++) - handle_band(wiphy, initiator, wiphy->bands[band]); + for (band = 0; band < NUM_NL80211_BANDS; band++) + handle_band(wiphy, initiator, wiphy->bands[band]); - reg_process_beacons(wiphy); - reg_process_ht_flags(wiphy); - } + reg_process_beacons(wiphy); + reg_process_ht_flags(wiphy); reg_call_notifier(wiphy, lr); } @@ -2593,12 +2581,14 @@ static void wiphy_update_regulatory(struct wiphy *wiphy, static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) { struct cfg80211_registered_device *rdev; - struct wiphy *wiphy; lockdep_assert_held(&cfg80211_mutex); for_each_rdev(rdev) { - wiphy = &rdev->wiphy; + struct wiphy *wiphy = &rdev->wiphy; + + guard(wiphy)(wiphy); + wiphy_update_regulatory(wiphy, initiator); } @@ -2712,13 +2702,11 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy, if (IS_ERR(new_regd)) return; - rtnl_lock(); scoped_guard(wiphy, wiphy) { tmp = get_wiphy_regdom(wiphy); rcu_assign_pointer(wiphy->regd, new_regd); rcu_free_regdom(tmp); } - rtnl_unlock(); } EXPORT_SYMBOL(wiphy_apply_custom_regulatory); @@ -3079,8 +3067,7 @@ static void wiphy_all_share_dfs_chan_state(struct wiphy *wiphy) struct cfg80211_registered_device *rdev; lockdep_assert_held(&cfg80211_mutex); - - guard(wiphy)(wiphy); + lockdep_assert_wiphy(wiphy); for_each_rdev(rdev) { if (wiphy == &rdev->wiphy) @@ -3132,6 +3119,8 @@ static void reg_process_hint(struct regulatory_request *reg_request) */ if (treatment == REG_REQ_ALREADY_SET && wiphy && wiphy->regulatory_flags & REGULATORY_STRICT_REG) { + guard(wiphy)(wiphy); + wiphy_update_regulatory(wiphy, initiator); wiphy_all_share_dfs_chan_state(wiphy); reg_check_channels(); @@ -3146,13 +3135,16 @@ out_free: static void notify_self_managed_wiphys(struct regulatory_request *request) { struct cfg80211_registered_device *rdev; - struct wiphy *wiphy; for_each_rdev(rdev) { - wiphy = &rdev->wiphy; + struct wiphy *wiphy = &rdev->wiphy; + if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && - request->initiator == NL80211_REGDOM_SET_BY_USER) + request->initiator == NL80211_REGDOM_SET_BY_USER) { + guard(wiphy)(wiphy); + reg_call_notifier(wiphy, request); + } } } @@ -3231,7 +3223,6 @@ static void reg_process_self_managed_hint(struct wiphy *wiphy) enum nl80211_band band; struct regulatory_request request = {}; - ASSERT_RTNL(); lockdep_assert_wiphy(wiphy); spin_lock(®_requests_lock); @@ -3279,13 +3270,11 @@ static void reg_process_self_managed_hints(void) static void reg_todo(struct work_struct *work) { - rtnl_lock(); - mutex_lock(&cfg80211_mutex); + guard(mutex)(&cfg80211_mutex); + reg_process_pending_hints(); reg_process_pending_beacon_hints(); reg_process_self_managed_hints(); - mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); } static void queue_regulatory_request(struct regulatory_request *request) @@ -4155,7 +4144,7 @@ int regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, { int ret; - ASSERT_RTNL(); + lockdep_assert_wiphy(wiphy); ret = __regulatory_set_wiphy_regd(wiphy, rd); if (ret) @@ -4174,25 +4163,28 @@ void wiphy_regulatory_register(struct wiphy *wiphy) lockdep_assert_held(&cfg80211_mutex); - /* self-managed devices ignore beacon hints and country IE */ - if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { - wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | - REGULATORY_COUNTRY_IE_IGNORE; + scoped_guard(wiphy, wiphy) { + /* self-managed devices ignore beacon hints and country IE */ + if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { + wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | + REGULATORY_COUNTRY_IE_IGNORE; - /* - * The last request may have been received before this - * registration call. Call the driver notifier if - * initiator is USER. - */ - if (lr->initiator == NL80211_REGDOM_SET_BY_USER) - reg_call_notifier(wiphy, lr); + /* + * The last request may have been received before this + * registration call. Call the driver notifier if + * initiator is USER. + */ + if (lr->initiator == NL80211_REGDOM_SET_BY_USER) + reg_call_notifier(wiphy, lr); + } + + if (!reg_dev_ignore_cell_hint(wiphy)) + reg_num_devs_support_basehint++; + + wiphy_update_regulatory(wiphy, lr->initiator); + wiphy_all_share_dfs_chan_state(wiphy); } - if (!reg_dev_ignore_cell_hint(wiphy)) - reg_num_devs_support_basehint++; - - wiphy_update_regulatory(wiphy, lr->initiator); - wiphy_all_share_dfs_chan_state(wiphy); reg_process_self_managed_hints(); } @@ -4450,11 +4442,8 @@ void regulatory_exit(void) cancel_delayed_work_sync(®_check_chans); /* Lock to suppress warnings */ - rtnl_lock(); - mutex_lock(&cfg80211_mutex); - reset_regdomains(true, NULL); - mutex_unlock(&cfg80211_mutex); - rtnl_unlock(); + scoped_guard(mutex, &cfg80211_mutex) + reset_regdomains(true, NULL); dev_set_uevent_suppress(®_fdev->dev, true); From 07b3eb8b9048976b585d29f1a1df9a435423c473 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 Oct 2026 12:52:49 +0200 Subject: [PATCH 1443/2126] wifi: mac80211: use link address as TA for non-MLO 4-addr station on MLD AP A 4-address AP_VLAN always sets A2 to sdata->vif.addr, which on an MLD AP is the AP MLD address. For a non-MLO station, A2 must be the link address it associated to. Use the link address for a non-MLO station in the 4-address case as well, like the AP case already does in ieee80211_build_hdr() and ieee80211_check_fast_xmit(). Share the address selection between both cases and both TX paths. Fixes: 3e0278b717b0 ("wifi: mac80211: select link when transmitting to non-MLO stations") Signed-off-by: Felix Fietkau Link: https://patch.msgid.link/20261007105249.1234601-1-nbd@nbd.name [use guard] Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 65 +++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 6f44ddfa0452..4b0ffd0a6ac7 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2729,6 +2729,29 @@ static void ieee80211_store_ack_skb(struct ieee80211_local *local, } } +static int ieee80211_ap_tx_addr_get(struct ieee80211_sub_if_data *sdata, + struct sta_info *sta, u8 *addr, u8 *link_id) +{ + struct ieee80211_link_data *link; + + if (!ieee80211_vif_is_mld(&sdata->vif) || sta->sta.mlo) { + memcpy(addr, sdata->vif.addr, ETH_ALEN); + return 0; + } + + guard(rcu)(); + + link = rcu_dereference(sdata->link[sta->deflink.link_id]); + if (WARN_ON(!link)) + return -ENOLINK; + + memcpy(addr, link->conf->addr, ETH_ALEN); + if (link_id) + *link_id = sta->deflink.link_id; + + return 0; +} + /** * ieee80211_build_hdr - build 802.11 header in the given frame * @sdata: virtual interface to build the header for @@ -2793,7 +2816,10 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); /* RA TA DA SA */ memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN); - memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); + ret = ieee80211_ap_tx_addr_get(sdata, sta, hdr.addr2, + &link_id); + if (ret) + goto free; memcpy(hdr.addr3, skb->data, ETH_ALEN); memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); hdrlen = 30; @@ -2818,18 +2844,12 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, /* DA BSSID SA */ memcpy(hdr.addr1, skb->data, ETH_ALEN); - if (ieee80211_vif_is_mld(&sdata->vif) && sta && !sta->sta.mlo) { - struct ieee80211_link_data *link; - - link_id = sta->deflink.link_id; - link = rcu_dereference(sdata->link[link_id]); - if (WARN_ON(!link)) { - ret = -ENOLINK; + if (sta) { + ret = ieee80211_ap_tx_addr_get(sdata, sta, hdr.addr2, + &link_id); + if (ret) goto free; - } - memcpy(hdr.addr2, link->conf->addr, ETH_ALEN); - } else if (link_id == IEEE80211_LINK_UNSPECIFIED || - (sta && sta->sta.mlo)) { + } else if (link_id == IEEE80211_LINK_UNSPECIFIED) { memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); } else { struct ieee80211_bss_conf *conf; @@ -3261,7 +3281,9 @@ void ieee80211_check_fast_xmit(struct sta_info *sta) IEEE80211_FCTL_TODS); /* RA TA DA SA */ memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN); - memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); + if (ieee80211_ap_tx_addr_get(sdata, sta, hdr->addr2, + NULL)) + goto out; build.da_offs = offsetof(struct ieee80211_hdr, addr3); build.sa_offs = offsetof(struct ieee80211_hdr, addr4); build.hdr_len = 30; @@ -3272,21 +3294,8 @@ void ieee80211_check_fast_xmit(struct sta_info *sta) fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); /* DA BSSID SA */ build.da_offs = offsetof(struct ieee80211_hdr, addr1); - if (sta->sta.mlo || !ieee80211_vif_is_mld(&sdata->vif)) { - memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); - } else { - unsigned int link_id = sta->deflink.link_id; - struct ieee80211_link_data *link; - - rcu_read_lock(); - link = rcu_dereference(sdata->link[link_id]); - if (WARN_ON(!link)) { - rcu_read_unlock(); - goto out; - } - memcpy(hdr->addr2, link->conf->addr, ETH_ALEN); - rcu_read_unlock(); - } + if (ieee80211_ap_tx_addr_get(sdata, sta, hdr->addr2, NULL)) + goto out; build.sa_offs = offsetof(struct ieee80211_hdr, addr3); build.hdr_len = 24; break; From c73695b5c2973839ffa5a8f0ad994b6131700fbd Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 12 Sep 2026 01:13:52 +0200 Subject: [PATCH 1444/2126] ovpn: Fix the return value in ovpn_bind_from_sockaddr() kernel-doc ovpn_bind_from_sockaddr() returns an ERR_PTR() on failure, never NULL, but its kernel-doc says "NULL otherwise". Say ERR_PTR(). The wrong text came in with commit 80747caef33d ("ovpn: introduce the ovpn_peer object"). Assisted-by: LLM Signed-off-by: Karl Mehltretter Signed-off-by: Antonio Quartulli --- drivers/net/ovpn/bind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ovpn/bind.c b/drivers/net/ovpn/bind.c index e42b60cd04a9..62a5ccfd3502 100644 --- a/drivers/net/ovpn/bind.c +++ b/drivers/net/ovpn/bind.c @@ -18,7 +18,7 @@ * ovpn_bind_from_sockaddr - retrieve binding matching sockaddr * @ss: the sockaddr to match * - * Return: the bind matching the passed sockaddr if found, NULL otherwise + * Return: the new bind for the passed sockaddr, an ERR_PTR() on failure */ struct ovpn_bind *ovpn_bind_from_sockaddr(const struct sockaddr_storage *ss) { From 1926cf58b0a8f74ad488ef4d14ed02b88fbfe229 Mon Sep 17 00:00:00 2001 From: Ralf Lici Date: Tue, 7 Jul 2026 08:37:48 +0200 Subject: [PATCH 1445/2126] ovpn: remove unused work field from struct ovpn_socket work in struct ovpn_socket was introduced but never used. Remove it. Signed-off-by: Ralf Lici Signed-off-by: Antonio Quartulli --- drivers/net/ovpn/socket.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ovpn/socket.h b/drivers/net/ovpn/socket.h index 4afcec71040d..5c87392ecd30 100644 --- a/drivers/net/ovpn/socket.h +++ b/drivers/net/ovpn/socket.h @@ -24,7 +24,6 @@ struct ovpn_peer; * @peer: unique peer transmitting over this socket (TCP only) * @sk: the low level sock object * @refcount: amount of contexts currently referencing this object - * @work: member used to schedule release routine (it may block) * @tcp_tx_work: work for deferring outgoing packet processing (TCP only) */ struct ovpn_socket { @@ -38,7 +37,6 @@ struct ovpn_socket { struct sock *sk; struct kref refcount; - struct work_struct work; struct work_struct tcp_tx_work; }; From fbe0f84135140565258e5bbee9c7e1f2826ee8ef Mon Sep 17 00:00:00 2001 From: Marco Baffo Date: Mon, 7 Sep 2026 12:59:02 +0200 Subject: [PATCH 1446/2126] ovpn: remove redundant peer NULL checks in crypto post functions The AEAD helpers set the peer pointer in the skb control buffer before any error return or crypto request submission. Both crypto paths hold a peer reference until post-processing finishes. Remove the redundant NULL checks before ovpn_peer_put() in ovpn_encrypt_post() and ovpn_decrypt_post(). Signed-off-by: Marco Baffo Signed-off-by: Antonio Quartulli --- drivers/net/ovpn/io.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 9526f8096da6..f14eb4e6c46a 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -206,8 +206,7 @@ drop: drop_nocount: if (likely(ks)) ovpn_crypto_key_slot_put(ks); - if (likely(peer)) - ovpn_peer_put(peer); + ovpn_peer_put(peer); } /* RX path entry point: decrypt packet and forward it to the device */ @@ -305,8 +304,7 @@ err: kfree_skb(skb); if (likely(ks)) ovpn_crypto_key_slot_put(ks); - if (likely(peer)) - ovpn_peer_put(peer); + ovpn_peer_put(peer); } static bool ovpn_encrypt_one(struct ovpn_peer *peer, struct sk_buff *skb) From 5a5c645415c216f381cdab654bc012546f0d07ff Mon Sep 17 00:00:00 2001 From: Marco Baffo Date: Thu, 6 Aug 2026 09:16:36 +0200 Subject: [PATCH 1447/2126] selftests: ovpn: enable TCP_NODELAY on TCP sockets Since openvpn 2.7.6, userspace unconditionally sets TCP_NODELAY on its TCP sockets. Do the same in ovpn-cli by default, so that the TCP selftests match that configuration. Peers running 2.7.0 to 2.7.5 still leave Nagle enabled, and mixed-version deployments will keep doing so for a while, so the option can be turned off with OVPN_TCP_NODELAY=0. test-tcp-nagle.sh uses it to keep running the TCP suite in that configuration. The TCP peer ID capture assumes that every TCP segment starts with an ovpn length prefix followed by a data header. TCP does not preserve record boundaries, and enabling TCP_NODELAY makes this check unreliable. Restrict the capture-based peer ID check to UDP. Suggested-by: Neal Cardwell Signed-off-by: Marco Baffo Signed-off-by: Antonio Quartulli --- tools/testing/selftests/net/ovpn/Makefile | 1 + tools/testing/selftests/net/ovpn/common.sh | 20 +++---- tools/testing/selftests/net/ovpn/ovpn-cli.c | 39 ++++++++++++++ .../selftests/net/ovpn/test-tcp-nagle.sh | 12 +++++ tools/testing/selftests/net/ovpn/test.sh | 54 +++++++++---------- 5 files changed, 86 insertions(+), 40 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/test-tcp-nagle.sh diff --git a/tools/testing/selftests/net/ovpn/Makefile b/tools/testing/selftests/net/ovpn/Makefile index 169f0464ac3a..35e4c9d4fc68 100644 --- a/tools/testing/selftests/net/ovpn/Makefile +++ b/tools/testing/selftests/net/ovpn/Makefile @@ -42,6 +42,7 @@ TEST_PROGS := \ test-symmetric-id-float.sh \ test-symmetric-id-tcp.sh \ test-symmetric-id.sh \ + test-tcp-nagle.sh \ test-tcp.sh \ test.sh \ # end of TEST_PROGS diff --git a/tools/testing/selftests/net/ovpn/common.sh b/tools/testing/selftests/net/ovpn/common.sh index 5e9c81e885e6..2f7851b82343 100644 --- a/tools/testing/selftests/net/ovpn/common.sh +++ b/tools/testing/selftests/net/ovpn/common.sh @@ -191,20 +191,14 @@ ovpn_setup_ns() { ovpn_build_capture_filter() { # match the first four bytes of the openvpn data payload - if [ "${OVPN_PROTO}" == "UDP" ]; then - # For UDP, libpcap transport indexing only works for IPv4, so - # use an explicit IPv4 or IPv6 expression based on the peer - # address. The IPv6 branch assumes there are no extension - # headers in the outer packet. - if [[ "${2}" == *:* ]]; then - printf "ip6 and ip6[6] = 17 and ip6[48:4] = %s" "${1}" - else - printf "ip and udp[8:4] = %s" "${1}" - fi + # For UDP, libpcap transport indexing only works for IPv4, so + # use an explicit IPv4 or IPv6 expression based on the peer + # address. The IPv6 branch assumes there are no extension + # headers in the outer packet. + if [[ "${2}" == *:* ]]; then + printf "ip6 and ip6[6] = 17 and ip6[48:4] = %s" "${1}" else - # openvpn over TCP prepends a 2-byte packet length ahead of the - # DATA_V2 opcode, so skip it before matching the payload header - printf "ip and tcp[(((tcp[12] & 0xf0) >> 2) + 2):4] = %s" "${1}" + printf "ip and udp[8:4] = %s" "${1}" fi } diff --git a/tools/testing/selftests/net/ovpn/ovpn-cli.c b/tools/testing/selftests/net/ovpn/ovpn-cli.c index 3b612a8a18fe..00b80bc5157f 100644 --- a/tools/testing/selftests/net/ovpn/ovpn-cli.c +++ b/tools/testing/selftests/net/ovpn/ovpn-cli.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include #include @@ -470,6 +472,33 @@ static int ovpn_parse_key_direction(const char *dir, struct ovpn_ctx *ctx) return 0; } +/* openvpn 2.7.6 and later always set TCP_NODELAY, so mirror that by + * default. Peers running 2.7.0 to 2.7.5 still leave Nagle enabled, and + * mixed-version deployments will keep doing so for a while, so let the + * selftests exercise that configuration too by setting OVPN_TCP_NODELAY=0. + */ +static bool ovpn_tcp_nodelay_wanted(void) +{ + const char *env = getenv("OVPN_TCP_NODELAY"); + + return !env || strcmp(env, "0"); +} + +static int ovpn_tcp_nodelay(int socket) +{ + int opt = 1; + int ret; + + if (!ovpn_tcp_nodelay_wanted()) + return 0; + + ret = setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); + if (ret < 0) + perror("setsockopt for TCP_NODELAY"); + + return ret; +} + static int ovpn_socket(struct ovpn_ctx *ctx, sa_family_t family, int proto) { struct sockaddr_storage local_sock = { 0 }; @@ -606,6 +635,12 @@ static int ovpn_accept(struct ovpn_ctx *ctx) goto err; } + if (ovpn_tcp_nodelay(ret) < 0) { + close(ret); + ret = -1; + goto err; + } + return ret; err: close(ctx->socket); @@ -623,6 +658,10 @@ static int ovpn_connect(struct ovpn_ctx *ovpn) return -1; } + ret = ovpn_tcp_nodelay(s); + if (ret < 0) + goto err; + switch (ovpn->remote.in4.sin_family) { case AF_INET: socklen = sizeof(struct sockaddr_in); diff --git a/tools/testing/selftests/net/ovpn/test-tcp-nagle.sh b/tools/testing/selftests/net/ovpn/test-tcp-nagle.sh new file mode 100755 index 000000000000..2d94d8e14d3d --- /dev/null +++ b/tools/testing/selftests/net/ovpn/test-tcp-nagle.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 OpenVPN, Inc. +# +# Author: Antonio Quartulli + +# Peers running openvpn 2.7.0 to 2.7.5 leave Nagle enabled on their TCP +# sockets. Keep exercising that configuration so it does not silently break. +OVPN_PROTO="TCP" +export OVPN_TCP_NODELAY=0 + +source test.sh diff --git a/tools/testing/selftests/net/ovpn/test.sh b/tools/testing/selftests/net/ovpn/test.sh index 392109d5e14e..e2e6ffdd29bb 100755 --- a/tools/testing/selftests/net/ovpn/test.sh +++ b/tools/testing/selftests/net/ovpn/test.sh @@ -137,35 +137,33 @@ ovpn_run_basic_traffic() { local tcpdump_timeout="1.5s" for p in $(seq 1 ${OVPN_NUM_PEERS}); do - # The first part of the data packet header consists of: - # - TCP only: 2 bytes for the packet length - # - 5 bits for opcode ("9" for DATA_V2) - # - 3 bits for key-id ("0" at this point) - # - 12 bytes for peer-id: - # - with asymmetric ID: "${p}" one way and "${p} + 9" the - # other way - # - with symmetric ID: "${p}" both ways - header1=$(printf "0x4800000%x" ${p}) - header2=$(printf "0x4800000%x" $((p + OVPN_ID_OFFSET))) - raddr="" if [ "${OVPN_PROTO}" == "UDP" ]; then + # The first part of the data packet header consists of: + # - 5 bits for opcode ("9" for DATA_V2) + # - 3 bits for key-id ("0" at this point) + # - 3 bytes for peer-id: + # - with asymmetric ID: "${p}" one way and "${p} + 9" the + # other way + # - with symmetric ID: "${p}" both ways + header1=$(printf "0x4800000%x" ${p}) + header2=$(printf "0x4800000%x" $((p + OVPN_ID_OFFSET))) raddr=$(awk "NR == ${p} {print \$3}" \ "${OVPN_UDP_PEERS_FILE}") + peer_ns="ovpn_peer${p}" + + timeout ${tcpdump_timeout} ip netns exec "${peer_ns}" \ + tcpdump --immediate-mode -p -ni veth${p} -c 1 \ + "$(ovpn_build_capture_filter "${header1}" "${raddr}")" \ + >/dev/null 2>&1 & + tcpdump_pid1=$! + timeout ${tcpdump_timeout} ip netns exec "${peer_ns}" \ + tcpdump --immediate-mode -p -ni veth${p} -c 1 \ + "$(ovpn_build_capture_filter "${header2}" "${raddr}")" \ + >/dev/null 2>&1 & + tcpdump_pid2=$! + + sleep 0.3 fi - peer_ns="ovpn_peer${p}" - - timeout ${tcpdump_timeout} ip netns exec "${peer_ns}" \ - tcpdump --immediate-mode -p -ni veth${p} -c 1 \ - "$(ovpn_build_capture_filter "${header1}" "${raddr}")" \ - >/dev/null 2>&1 & - tcpdump_pid1=$! - timeout ${tcpdump_timeout} ip netns exec "${peer_ns}" \ - tcpdump --immediate-mode -p -ni veth${p} -c 1 \ - "$(ovpn_build_capture_filter "${header2}" "${raddr}")" \ - >/dev/null 2>&1 & - tcpdump_pid2=$! - - sleep 0.3 ovpn_cmd_ok "send baseline traffic to peer ${p}" \ ip netns exec ovpn_peer0 \ ping -qfc 100 -w 3 5.5.5.$((p + 1)) @@ -173,8 +171,10 @@ ovpn_run_basic_traffic() { ip netns exec ovpn_peer0 \ ping -qfc 100 -s 3000 -w 3 5.5.5.$((p + 1)) - wait "${tcpdump_pid1}" || return 1 - wait "${tcpdump_pid2}" || return 1 + if [ "${OVPN_PROTO}" == "UDP" ]; then + wait "${tcpdump_pid1}" || return 1 + wait "${tcpdump_pid2}" || return 1 + fi done } From 03b7050e67e2d5335cfcec428934d9728d968764 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Wed, 30 Sep 2026 15:54:11 +0200 Subject: [PATCH 1448/2126] selftests: ovpn: wait for the TCP server key setup before traffic In TCP mode ovpn_add_peer() starts the server side from a background subshell that first listens for the incoming connections and then installs the data key of every peer. The subshell PID is discarded, so nothing synchronizes the test against the key installation. The sleep 5 that follows does not cover it: it elapses while "listen" is still waiting for connections, and the peers only connect in the subsequent ovpn_add_peer() iterations, so the key loop starts well after that sleep has expired. Until now the test happened to work because of the unrelated delays that ran in between. Record the PID of the background subshell and wait for it once all the peers have been registered, which is the earliest point at which "listen" can have returned. A peer that was not given a key yet would otherwise drop the server-to-client packets and make the first ping fail. Signed-off-by: Antonio Quartulli --- tools/testing/selftests/net/ovpn/common.sh | 61 ++++++++++++++++++- .../selftests/net/ovpn/test-close-socket.sh | 2 + tools/testing/selftests/net/ovpn/test.sh | 2 + 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/ovpn/common.sh b/tools/testing/selftests/net/ovpn/common.sh index 2f7851b82343..da732c64ffea 100644 --- a/tools/testing/selftests/net/ovpn/common.sh +++ b/tools/testing/selftests/net/ovpn/common.sh @@ -256,14 +256,19 @@ ovpn_add_peer() { fi else if [ ${1} -eq 0 ]; then + OVPN_TCP_KEYS_LOG=$(mktemp) (ip netns exec "${server_ns}" ${OVPN_CLI} listen tun0 \ 1 ${M_ID} ${OVPN_TCP_PEERS_FILE} && { + rc=0 for p in $(seq 1 ${OVPN_NUM_PEERS}); do ip netns exec "${server_ns}" \ ${OVPN_CLI} new_key tun0 ${p} \ - 1 0 ${OVPN_ALG} 0 data64.key + 1 0 ${OVPN_ALG} 0 data64.key \ + || rc=1 done - }) & + exit ${rc} + }) >"${OVPN_TCP_KEYS_LOG}" 2>&1 & + OVPN_TCP_KEYS_PID=$! sleep 5 else peer_ns="ovpn_peer${1}" @@ -281,6 +286,58 @@ ovpn_add_peer() { fi } +# In TCP mode the server accepts the peers and installs their data keys from a +# background subshell. "listen" returns once a connection has been accepted for +# every entry of the peers file, so the key installation runs after the last +# ovpn_add_peer() call. Wait for that subshell before generating any traffic, +# otherwise the first packets may race the key installation and get dropped for +# lack of a key. +# +# The wait is bounded: both the accept loop and the subsequent receive in +# ovpn-cli are unbounded, so a peer that never connects (for instance when +# OVPN_NUM_PEERS is smaller than the number of entries in the peers file) would +# otherwise hang the whole test instead of failing. +OVPN_TCP_KEYS_TIMEOUT=${OVPN_TCP_KEYS_TIMEOUT:-30} + +ovpn_wait_tcp_keys() { + local deadline rc + + [ -n "${OVPN_TCP_KEYS_PID:-}" ] || return 0 + + deadline=$((SECONDS + OVPN_TCP_KEYS_TIMEOUT)) + while kill -0 "${OVPN_TCP_KEYS_PID}" 2>/dev/null; do + if [ "${SECONDS}" -ge "${deadline}" ]; then + printf '%s\n' \ + "server-side key setup still running after ${OVPN_TCP_KEYS_TIMEOUT}s" + kill "${OVPN_TCP_KEYS_PID}" 2>/dev/null + wait "${OVPN_TCP_KEYS_PID}" 2>/dev/null + ovpn_dump_tcp_keys_log + return 1 + fi + sleep 0.2 + done + + wait "${OVPN_TCP_KEYS_PID}" + rc=$? + + # ovpn_cmd_run() has already removed the temporary file this subshell + # inherited, so without this its output would be lost and a failed + # new_key would only show up later as a ping failure. + if [ "${rc}" -ne 0 ]; then + ovpn_dump_tcp_keys_log + fi + rm -f "${OVPN_TCP_KEYS_LOG}" + + return "${rc}" +} + +ovpn_dump_tcp_keys_log() { + [ -s "${OVPN_TCP_KEYS_LOG:-}" ] || return 0 + + printf '%s\n' "--- server-side key setup output ---" + cat "${OVPN_TCP_KEYS_LOG}" +} + ovpn_compare_ntfs() { local diff_rc=0 local diff_file diff --git a/tools/testing/selftests/net/ovpn/test-close-socket.sh b/tools/testing/selftests/net/ovpn/test-close-socket.sh index ec9a51bbf3c9..142dc14e2606 100755 --- a/tools/testing/selftests/net/ovpn/test-close-socket.sh +++ b/tools/testing/selftests/net/ovpn/test-close-socket.sh @@ -37,6 +37,8 @@ ovpn_prepare_network() { ovpn_cmd_ok "register peer${p} in overlay" ovpn_add_peer "${p}" done + ovpn_cmd_ok "wait for server-side key setup" ovpn_wait_tcp_keys + for p in $(seq 1 ${OVPN_NUM_PEERS}); do peer_ns="ovpn_peer${p}" ovpn_cmd_ok "set peer0 timeout for peer ${p}" \ diff --git a/tools/testing/selftests/net/ovpn/test.sh b/tools/testing/selftests/net/ovpn/test.sh index e2e6ffdd29bb..0762fa83e4b5 100755 --- a/tools/testing/selftests/net/ovpn/test.sh +++ b/tools/testing/selftests/net/ovpn/test.sh @@ -45,6 +45,8 @@ ovpn_prepare_network() { ovpn_cmd_ok "register peer${p} in overlay" ovpn_add_peer "${p}" done + ovpn_cmd_ok "wait for server-side key setup" ovpn_wait_tcp_keys + for p in $(seq 1 ${OVPN_NUM_PEERS}); do peer_ns="ovpn_peer${p}" ovpn_cmd_ok "set peer0 timeout for peer ${p}" \ From 643f0bf936176c114d5631da7547e991b5d99f10 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Wed, 7 Oct 2026 14:53:32 +0530 Subject: [PATCH 1449/2126] wifi: ath12k: Make RXDMA buffer ring size configurable per memory profile Currently, the RXDMA buffer ring size is hardcoded to 4096 and shared across all memory profiles. This prevents individual profiles from tuning the ring size based on their memory and performance requirements. Add the RXDMA buffer ring size to the memory profile configuration and implement ath12k_dp_rxdma_buf_ring_size() static inline function to access the configured value. This allows different memory profiles to select an appropriate ring size based on available system resources. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00074-QCACOLSWPL_V1_TO_SILICONZ-1 Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261007-mpp_ws-v1-1-739b1fb87d24@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/core.c | 2 ++ drivers/net/wireless/ath/ath12k/dp.h | 8 +++++++- drivers/net/wireless/ath/ath12k/dp_rx.c | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index 0c72948f3f56..917a124a4df0 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -54,6 +54,7 @@ ath12k_mem_profile_based_param ath12k_mem_profile_based_param[] = { .num_pool_tx_desc = 32768, .rx_desc_count = 12288, .rx_release_ring_size = 16384, + .rxdma_buf_ring_size = 4096, }, }, [ATH12K_QMI_MEMORY_MODE_LOW_512_M] = { @@ -68,6 +69,7 @@ ath12k_mem_profile_based_param ath12k_mem_profile_based_param[] = { .num_pool_tx_desc = 16384, .rx_desc_count = 6144, .rx_release_ring_size = 8192, + .rxdma_buf_ring_size = 4096, }, }, }; diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index c53eac20b989..108e27dd5797 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -31,6 +31,7 @@ struct ath12k_dp_profile_params { u32 num_pool_tx_desc; u32 rx_desc_count; u32 rx_release_ring_size; + u32 rxdma_buf_ring_size; }; #define DP_MON_PURGE_TIMEOUT_MS 100 @@ -210,7 +211,6 @@ struct ath12k_pdev_dp { #define DP_REO_EXCEPTION_RING_SIZE 128 #define DP_REO_CMD_RING_SIZE 256 #define DP_REO_STATUS_RING_SIZE 2048 -#define DP_RXDMA_BUF_RING_SIZE 4096 #define DP_RX_MAC_BUF_RING_SIZE 4096 #define DP_RXDMA_REFILL_RING_SIZE 2048 #define DP_RXDMA_ERR_DST_RING_SIZE 1024 @@ -730,6 +730,12 @@ ath12k_dp_rx_release_ring_size(const struct ath12k_dp_profile_params *p) return p->rx_release_ring_size; } +static inline u32 +ath12k_dp_rxdma_buf_ring_size(const struct ath12k_dp_profile_params *p) +{ + return p->rxdma_buf_ring_size; +} + void ath12k_dp_vdev_tx_attach(struct ath12k *ar, struct ath12k_link_vif *arvif); void ath12k_dp_partner_cc_init(struct ath12k_base *ab); int ath12k_dp_pdev_alloc(struct ath12k_base *ab); diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c index cfaf26ae2720..36be543b7c50 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/dp_rx.c @@ -1699,7 +1699,7 @@ int ath12k_dp_rx_alloc(struct ath12k_base *ab) ret = ath12k_dp_srng_setup(ab, &dp->rx_refill_buf_ring.refill_buf_ring, HAL_RXDMA_BUF, 0, 0, - DP_RXDMA_BUF_RING_SIZE); + ath12k_dp_rxdma_buf_ring_size(dp_params)); if (ret) { ath12k_warn(ab, "failed to setup rx_refill_buf_ring\n"); return ret; From 15f7603b69a83a0acc7fcc8992ecbea6110f9424 Mon Sep 17 00:00:00 2001 From: Pavankumar Nandeshwar Date: Wed, 7 Oct 2026 14:53:33 +0530 Subject: [PATCH 1450/2126] wifi: ath12k: Increase RXDMA buffer ring size for default memory profile The default RXDMA buffer ring size of 4096 entries can become a bottleneck under high RX traffic load, resulting in reduced receive throughput due to limited buffer availability. Increase the RXDMA buffer ring size to 8192 entries for the default memory profile to provide additional RX buffering and improve RX packet processing efficiency. This increases memory consumption by approximately 9-10 MiB and improves RX throughput by ~20% with the default memory profile (ATH12K_QMI_MEMORY_MODE_DEFAULT). Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1 Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00074-QCACOLSWPL_V1_TO_SILICONZ-1 Signed-off-by: Pavankumar Nandeshwar Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261007-mpp_ws-v1-2-739b1fb87d24@oss.qualcomm.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index 917a124a4df0..3ed98eb746b5 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -54,7 +54,7 @@ ath12k_mem_profile_based_param ath12k_mem_profile_based_param[] = { .num_pool_tx_desc = 32768, .rx_desc_count = 12288, .rx_release_ring_size = 16384, - .rxdma_buf_ring_size = 4096, + .rxdma_buf_ring_size = 8192, }, }, [ATH12K_QMI_MEMORY_MODE_LOW_512_M] = { From d26b64fbb844fa00d9c95b7e1ae7fa8f546952db Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Mon, 13 Apr 2026 16:58:46 -0700 Subject: [PATCH 1451/2126] wifi: ath12k: Remove unused HAL_RX_REO_QUEUE_INFO macros Many of the HAL_RX_REO_QUEUE_INFO macros are unused, so remove them. No functional change. Compile Tested only. Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20260413-hal_rx_reo_queue_info2_msdu_count-v1-1-c4c92ccf77b9@oss.qualcomm.com Signed-off-by: Jeff Johnson --- .../net/wireless/ath/ath12k/wifi7/hal_desc.h | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_desc.h b/drivers/net/wireless/ath/ath12k/wifi7/hal_desc.h index e1ab47b44433..822de3a4abc8 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_desc.h +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_desc.h @@ -2100,41 +2100,15 @@ enum hal_rx_reo_queue_pn_size { #define HAL_RX_REO_QUEUE_INFO0_VLD BIT(0) #define HAL_RX_REO_QUEUE_INFO0_ASSOC_LNK_DESC_COUNTER GENMASK(2, 1) -#define HAL_RX_REO_QUEUE_INFO0_DIS_DUP_DETECTION BIT(3) -#define HAL_RX_REO_QUEUE_INFO0_SOFT_REORDER_EN BIT(4) #define HAL_RX_REO_QUEUE_INFO0_AC GENMASK(6, 5) -#define HAL_RX_REO_QUEUE_INFO0_BAR BIT(7) #define HAL_RX_REO_QUEUE_INFO0_RETRY BIT(8) -#define HAL_RX_REO_QUEUE_INFO0_CHECK_2K_MODE BIT(9) -#define HAL_RX_REO_QUEUE_INFO0_OOR_MODE BIT(10) #define HAL_RX_REO_QUEUE_INFO0_BA_WINDOW_SIZE GENMASK(20, 11) #define HAL_RX_REO_QUEUE_INFO0_PN_CHECK BIT(21) -#define HAL_RX_REO_QUEUE_INFO0_EVEN_PN BIT(22) -#define HAL_RX_REO_QUEUE_INFO0_UNEVEN_PN BIT(23) -#define HAL_RX_REO_QUEUE_INFO0_PN_HANDLE_ENABLE BIT(24) #define HAL_RX_REO_QUEUE_INFO0_PN_SIZE GENMASK(26, 25) #define HAL_RX_REO_QUEUE_INFO0_IGNORE_AMPDU_FLG BIT(27) #define HAL_RX_REO_QUEUE_INFO1_SVLD BIT(0) #define HAL_RX_REO_QUEUE_INFO1_SSN GENMASK(12, 1) -#define HAL_RX_REO_QUEUE_INFO1_CURRENT_IDX GENMASK(22, 13) -#define HAL_RX_REO_QUEUE_INFO1_SEQ_2K_ERR BIT(23) -#define HAL_RX_REO_QUEUE_INFO1_PN_ERR BIT(24) -#define HAL_RX_REO_QUEUE_INFO1_PN_VALID BIT(31) - -#define HAL_RX_REO_QUEUE_INFO2_MPDU_COUNT GENMASK(6, 0) -#define HAL_RX_REO_QUEUE_INFO2_MSDU_COUNT (31, 7) - -#define HAL_RX_REO_QUEUE_INFO3_TIMEOUT_COUNT GENMASK(9, 4) -#define HAL_RX_REO_QUEUE_INFO3_FWD_DUE_TO_BAR_CNT GENMASK(15, 10) -#define HAL_RX_REO_QUEUE_INFO3_DUPLICATE_COUNT GENMASK(31, 16) - -#define HAL_RX_REO_QUEUE_INFO4_FRAME_IN_ORD_COUNT GENMASK(23, 0) -#define HAL_RX_REO_QUEUE_INFO4_BAR_RECVD_COUNT GENMASK(31, 24) - -#define HAL_RX_REO_QUEUE_INFO5_LATE_RX_MPDU_COUNT GENMASK(11, 0) -#define HAL_RX_REO_QUEUE_INFO5_WINDOW_JUMP_2K GENMASK(15, 12) -#define HAL_RX_REO_QUEUE_INFO5_HOLE_COUNT GENMASK(31, 16) struct hal_rx_reo_queue { struct hal_desc_header desc_hdr; From 4c5679222f6b9bb6800d32eb8256b43d164c3e31 Mon Sep 17 00:00:00 2001 From: Or Har-Toov Date: Mon, 5 Oct 2026 11:40:46 +0300 Subject: [PATCH 1452/2126] net/mlx5: Add cap_tx_speed and effective_tx_speed support to IFC Introduce the cap_tx_speed and effective_tx_speed fields to the query and modify_vport_state structures. Add the esw_vport_state_cap_tx_speed and esw_vport_state_effective_tx_speed capability bits, indicating the firmware supports modifying the cap_tx_speed and effective_tx_speed fields, via the MODIFY_VPORT_STATE command. Signed-off-by: Or Har-Toov Reviewed-by: Mark Bloch Reviewed-by: Nimrod Oren Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261005084047.237081-2-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/mlx5_ifc.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index a712463e89b4..989408764e1b 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -1070,7 +1070,9 @@ struct mlx5_ifc_e_switch_cap_bits { u8 root_ft_on_other_esw[0x1]; u8 reserved_at_a[0x1]; u8 esw_vport_state_max_tx_speed[0x1]; - u8 reserved_at_c[0xd]; + u8 esw_vport_state_cap_tx_speed[0x1]; + u8 esw_vport_state_effective_tx_speed[0x1]; + u8 reserved_at_e[0xb]; u8 esw_functions_changed[0x1]; u8 reserved_at_1a[0x1]; u8 ecpf_vport_exists[0x1]; @@ -5492,6 +5494,9 @@ struct mlx5_ifc_query_vport_state_out_bits { u8 reserved_at_70[0x8]; u8 admin_state[0x4]; u8 state[0x4]; + + u8 cap_tx_speed[0x10]; + u8 effective_tx_speed[0x10]; }; struct mlx5_ifc_array1024_auto_bits { @@ -7840,6 +7845,9 @@ struct mlx5_ifc_modify_vport_state_in_bits { u8 reserved_at_74[0x4]; u8 admin_state[0x4]; u8 reserved_at_7c[0x4]; + + u8 cap_tx_speed[0x10]; + u8 effective_tx_speed[0x10]; }; struct mlx5_ifc_modify_tis_out_bits { From 41de84543574f2923776790f608c56389aed972e Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Mon, 5 Oct 2026 11:40:47 +0300 Subject: [PATCH 1453/2126] net/mlx5: IFC, Add capability bits for virtual LAG Virtual LAG can also be built over virtual uplinks rather than physical ports. The support for this virtual LAG is indicated by multi_uplink_eswitch and port_select_eswitch caps bit. Signed-off-by: Shay Drory Reviewed-by: Mark Bloch Reviewed-by: Moshe Shemesh Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261005084047.237081-3-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/mlx5_ifc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 989408764e1b..f1ee35aa884a 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -929,7 +929,7 @@ struct mlx5_ifc_flow_table_nic_cap_bits { struct mlx5_ifc_port_selection_cap_bits { u8 reserved_at_0[0x10]; u8 port_select_flow_table[0x1]; - u8 reserved_at_11[0x1]; + u8 port_select_eswitch[0x1]; u8 port_select_flow_table_bypass[0x1]; u8 reserved_at_13[0xd]; @@ -2010,7 +2010,9 @@ struct mlx5_ifc_cmd_hca_cap_bits { u8 reserved_at_3b0[0x2]; u8 qp_latency_sensitive_disable[0x1]; u8 log_max_stride_sz_sq[0x5]; - u8 reserved_at_3b8[0x3]; + u8 reserved_at_3b8[0x1]; + u8 multi_uplink_eswitch[0x1]; + u8 reserved_at_3ba[0x1]; u8 log_min_stride_sz_sq[0x5]; u8 hairpin[0x1]; From 18e03721933c3193d7ac450976ca0e5e560b224f Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Mon, 31 Aug 2026 17:11:04 +0200 Subject: [PATCH 1454/2126] netfilter: disable br_netfilter in user namespaces br_netfilter has way too many bugs, schedule for removal and disable the feature in user namespaces. In particular, we get more and more gadgets to have bridge ports escape rcu_read_lock() protection, then underlying device gets reconfigured (macvlan or something else), then reinject into network stack causes crash because net_device is assumed to still have bridge rx data associated with it. br_netfilter is an ancient kludge that emulates ip stack from within the bridge and then calls into ipv4/ipv6 netfilter hooks to have bridged frames processed via iptables/ip6tables by setting the 'call-iptables' sysctls to 1. It is NOT related to ebtables or nftables 'bridge' family at all. Note that in addition to call-iptables, sysctls, the bridge also exposes call-iptables per bridge device via netlink and sysfs ('BROPT_NF_CALL_IPTABLES') toggles. Those are still available, the brnet structure is scoped to br_netfilter; exposing it bridge-wide is a big no-no. This relies on brnf_device_event() no longer registering the base br_netfilter hooks, so while BROPT_NF_CALL_IPTABLES can be set, it has no effect because the hooks that evaluate this feature bit are never registered. brnf_init_net can no longer depend on CONFIG_SYSCTL, else such builds never disable support in user namespaces. Cc: Nikolay Aleksandrov Signed-off-by: Florian Westphal Reviewed-by: Nikolay Aleksandrov Signed-off-by: Pablo Neira Ayuso --- Documentation/networking/bridge.rst | 5 +++-- net/bridge/br_netfilter_hooks.c | 33 ++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Documentation/networking/bridge.rst b/Documentation/networking/bridge.rst index c1e6ea52c9e5..dded1a6edd60 100644 --- a/Documentation/networking/bridge.rst +++ b/Documentation/networking/bridge.rst @@ -277,8 +277,9 @@ Netfilter ========= The bridge netfilter module is a legacy feature that allows to filter bridged -packets with iptables and ip6tables. Its use is discouraged. Users should -consider using nftables for packet filtering. +packets with iptables and ip6tables. This feature is scheduled for removal and +not available in user namespaces. Consider using nftables for packet filtering +instead. The older ebtables tool is more feature-limited compared to nftables, but just like nftables it doesn't need this module either to function. diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c index 0a394e5f4391..e15355ff215a 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -54,6 +54,7 @@ static unsigned int brnf_net_id __read_mostly; struct brnf_net { bool enabled; + bool in_userns; #ifdef CONFIG_SYSCTL struct ctl_table_header *ctl_hdr; @@ -1100,7 +1101,7 @@ static int brnf_device_event(struct notifier_block *unused, unsigned long event, net = dev_net(dev); brnet = net_generic(net, brnf_net_id); - if (brnet->enabled) + if (brnet->enabled || brnet->in_userns) return NOTIFY_OK; ret = nf_register_net_hooks(net, br_nf_ops, ARRAY_SIZE(br_nf_ops)); @@ -1229,9 +1230,11 @@ static inline void br_netfilter_sysctl_default(struct brnf_net *brnf) brnf->filter_pppoe_tagged = 0; brnf->pass_vlan_indev = 0; } +#endif static int br_netfilter_sysctl_init_net(struct net *net) { +#ifdef CONFIG_SYSCTL struct ctl_table *table = brnf_table; struct brnf_net *brnet; @@ -1259,25 +1262,39 @@ static int br_netfilter_sysctl_init_net(struct net *net) return -ENOMEM; } - +#endif return 0; } static void br_netfilter_sysctl_exit_net(struct net *net, struct brnf_net *brnet) { - const struct ctl_table *table = brnet->ctl_hdr->ctl_table_arg; +#ifdef CONFIG_SYSCTL + struct ctl_table_header *header = brnet->ctl_hdr; + const struct ctl_table *table; - unregister_net_sysctl_table(brnet->ctl_hdr); + if (!header) + return; + + table = header->ctl_table_arg; + unregister_net_sysctl_table(header); if (!net_eq(net, &init_net)) kfree(table); +#endif } static int __net_init brnf_init_net(struct net *net) { + if (net->user_ns != &init_user_ns) { + struct brnf_net *brnet = net_generic(net, brnf_net_id); + + brnet->in_userns = true; + pr_warn_once("br_netfilter no longer supported in user namespaces\n"); + return 0; + } + return br_netfilter_sysctl_init_net(net); } -#endif static void __net_exit brnf_exit_net(struct net *net) { @@ -1289,15 +1306,11 @@ static void __net_exit brnf_exit_net(struct net *net) brnet->enabled = false; } -#ifdef CONFIG_SYSCTL br_netfilter_sysctl_exit_net(net, brnet); -#endif } static struct pernet_operations brnf_net_ops __read_mostly = { -#ifdef CONFIG_SYSCTL .init = brnf_init_net, -#endif .exit = brnf_exit_net, .id = &brnf_net_id, .size = sizeof(struct brnf_net), @@ -1318,7 +1331,7 @@ static int __init br_netfilter_init(void) } RCU_INIT_POINTER(nf_br_ops, &br_ops); - printk(KERN_NOTICE "Bridge firewalling registered\n"); + pr_warn("br_netfilter is slated for removal in 2027.\n"); return 0; } From b2ed202907d654337d72825d743a833009010740 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Wed, 30 Sep 2026 00:58:43 +0200 Subject: [PATCH 1455/2126] MAINTAINERS: ovpn: add Ralf Lici as reviewer Ralf has authored 39 of the ovpn commits merged so far, second only to the maintainer, and is already involved in the review of most changes posted to the list. Add him as designated reviewer so that he is CCed on incoming patches. Signed-off-by: Antonio Quartulli Acked-by: Ralf Lici --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 509b35b5a0e7..9e5fa06b2b51 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20537,6 +20537,7 @@ F: drivers/irqchip/irq-or1k-* OPENVPN DATA CHANNEL OFFLOAD M: Antonio Quartulli +R: Ralf Lici R: Sabrina Dubroca L: openvpn-devel@lists.sourceforge.net (subscribers-only) L: netdev@vger.kernel.org From 3a82195416fd71fdd6cb4ff80f611ec28073be16 Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Mon, 12 Oct 2026 15:54:20 +0200 Subject: [PATCH 1456/2126] net: devmem: check uid and netns in net_devmem_get_binding() NETDEV_CMD_BIND_TX is unprivileged, and dmabuf binding IDs are allocated from a single global xarray. Currently net_devmem_get_binding() looks up the binding by ID without checking whether the sending socket belongs to the same user or network namespace that created the binding. Record the creating netlink socket's network namespace and UID on the binding, and verify both in net_devmem_get_binding() before checking the route destination device. Return -EINVAL on mismatch so callers cannot distinguish non-existent IDs from bindings owned by other users. Fixes: bd61848900bf ("net: devmem: Implement TX path") Signed-off-by: Kaifeng Wang Acked-by: Stanislav Fomichev Reviewed-by: Bobby Eshleman Signed-off-by: Paolo Abeni --- net/core/devmem.c | 7 ++++++- net/core/devmem.h | 5 +++++ net/core/netdev-genl.c | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 07c62e2e3088..95d714d46c6f 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -179,6 +179,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, enum dma_data_direction direction, unsigned int dmabuf_fd, unsigned int niov_shift, struct netdev_nl_sock *priv, + const struct sock *nl_sk, struct netlink_ext_ack *extack) { struct net_devmem_dmabuf_binding *binding; @@ -209,6 +210,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, binding->dev = dev; binding->vdev = vdev; + write_pnet(&binding->net, sock_net(nl_sk)); + binding->uid = sk_uid(nl_sk); binding->niov_shift = niov_shift; xa_init_flags(&binding->bound_rxqs, XA_FLAGS_ALLOC); @@ -376,7 +379,9 @@ struct net_devmem_dmabuf_binding *net_devmem_get_binding(struct sock *sk, int err = 0; binding = net_devmem_lookup_dmabuf(dmabuf_id); - if (!binding || !binding->tx_vec) { + if (!binding || !binding->tx_vec || + !net_eq(sock_net(sk), read_pnet(&binding->net)) || + !uid_eq(sk_uid(sk), binding->uid)) { err = -EINVAL; goto out_err; } diff --git a/net/core/devmem.h b/net/core/devmem.h index 1cec10f0257c..ad24bca20618 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -10,6 +10,7 @@ #ifndef _NET_DEVMEM_H #define _NET_DEVMEM_H +#include #include #include @@ -27,6 +28,8 @@ struct net_devmem_dmabuf_binding { * dereferenced. */ void *vdev; + possible_net_t net; + kuid_t uid; /* Protect dev */ struct mutex lock; @@ -88,6 +91,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, enum dma_data_direction direction, unsigned int dmabuf_fd, unsigned int niov_shift, struct netdev_nl_sock *priv, + const struct sock *nl_sk, struct netlink_ext_ack *extack); struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id); void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding); @@ -162,6 +166,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, unsigned int dmabuf_fd, unsigned int niov_shift, struct netdev_nl_sock *priv, + const struct sock *nl_sk, struct netlink_ext_ack *extack) { return ERR_PTR(-EOPNOTSUPP); diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index dce4758a812d..c3aa367214ac 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -1112,7 +1112,7 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) binding = net_devmem_bind_dmabuf(netdev, NULL, dma_dev, DMA_FROM_DEVICE, dmabuf_fd, niov_shift, priv, - info->extack); + NETLINK_CB(skb).sk, info->extack); if (IS_ERR(binding)) { err = PTR_ERR(binding); goto err_rxq_bitmap; @@ -1261,7 +1261,8 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info) binding = net_devmem_bind_dmabuf(bind_dev, bind_dev != netdev ? netdev : NULL, dma_dev, DMA_TO_DEVICE, dmabuf_fd, - PAGE_SHIFT, priv, info->extack); + PAGE_SHIFT, priv, NETLINK_CB(skb).sk, + info->extack); if (IS_ERR(binding)) { err = PTR_ERR(binding); goto err_unlock_bind_dev; From 5949d1910f13c20f6ebcd26eec9e0c02cb4951aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Roux?= Date: Tue, 6 Oct 2026 08:27:28 +0200 Subject: [PATCH 1457/2126] wifi: ath12k: skip hardware rfkill setup on Microsoft Surface devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the Microsoft Surface Pro 11 and Surface Laptop 7 (X1E80100), the WCN7850 hardware rfkill input reads as "radio off" and the OS has no way to control it. ath12k enables hardware rfkill handling, so Wi-Fi stays hard-blocked: iwd: Error bringing interface 4 up: Operation not possible due to RF-kill ACPI platforms can opt out through ath12k_acpi_get_disable_rfkill(), but DT platforms cannot. A DT property was proposed for this and rejected, because it describes what the OS should do rather than the hardware. The suggested alternative was to handle these machines in the driver until a connector binding can describe a broken rfkill line. Add a table of board compatibles and hardware revisions on which hardware rfkill is known to be unusable, and skip the rfkill setup there. Other affected machines then only need a new table entry. Tested on a Surface Pro 11 (microsoft,denali) with next-20260929, booted with the unmodified mainline DTB: the interface is no longer blocked and connects. The Surface Laptop 7 entries (microsoft,romulus13 and microsoft,romulus15) are based on reports from Jérôme de Bretagne and Dale Whinham. I have not tested them. Link: https://lore.kernel.org/all/2ixwny6hzumlqmok5cjwutvtk7nzmx4t3dhxc44ao4l2u755pj@n6m7jyxf2o62/ Suggested-by: Manivannan Sadhasivam Assisted-by: LLM Signed-off-by: François Roux Tested-by: Dale Whinham Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20261006062728.45007-1-franzelfranzel@gmail.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/core.c | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index 3ed98eb746b5..c9df99bc54fd 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -74,6 +74,35 @@ ath12k_mem_profile_based_param ath12k_mem_profile_based_param[] = { }, }; +/* + * On these machines the OS cannot control the WCN7850 hardware rfkill + * input, which reads as "radio off", so hardware rfkill must stay + * disabled. Ideally this would come from the connector node of the board + * DT, but that binding does not exist yet. + */ +static const struct ath12k_core_broken_rfkill_table { + enum ath12k_hw_rev hw_rev; + const char *compatible; +} ath12k_core_broken_rfkill_table[] = { + { ATH12K_HW_WCN7850_HW20, "microsoft,denali" }, + { ATH12K_HW_WCN7850_HW20, "microsoft,romulus13" }, + { ATH12K_HW_WCN7850_HW20, "microsoft,romulus15" }, + { /* Sentinel */ } +}; + +static bool ath12k_core_rfkill_is_broken(struct ath12k_base *ab) +{ + const struct ath12k_core_broken_rfkill_table *entry; + + for (entry = ath12k_core_broken_rfkill_table; entry->compatible; entry++) { + if (ab->hw_rev == entry->hw_rev && + of_machine_is_compatible(entry->compatible)) + return true; + } + + return false; +} + static int ath12k_core_rfkill_config(struct ath12k_base *ab) { struct ath12k *ar; @@ -85,6 +114,9 @@ static int ath12k_core_rfkill_config(struct ath12k_base *ab) if (ath12k_acpi_get_disable_rfkill(ab)) return 0; + if (ath12k_core_rfkill_is_broken(ab)) + return 0; + for (i = 0; i < ab->num_radios; i++) { ar = ab->pdevs[i].ar; From 29f144016f03608abfddcd6ebaeabafd7aeaadd2 Mon Sep 17 00:00:00 2001 From: Seongjun Hong Date: Tue, 6 Oct 2026 14:16:45 +0000 Subject: [PATCH 1458/2126] net/mlx5: allocate DMA pool structs on the pool's NUMA node The mlx5 DMA pool structs (mlx5_dma_pool, mlx5_dma_pool_page and its block bitmap, and mlx5_frag_buf_node_pools) are allocated without a node hint, so they land on the node of whichever CPU happens to create or fill the pool, while the DMA pages they describe are allocated on the pool's node. The pool, page and bitmap are dereferenced on every block allocation and free. Allocate them on the pool's NUMA node as well, so that all of a pool's state lives on one node. These allocations happen on the control path, so the performance gain is expected to be small; the change is mainly for consistency. Signed-off-by: Seongjun Hong Reviewed-by: Jacob Keller Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261006-net-mlx5-numa-allocate-pool-page-v2-1-0dc4c2eb1376@snu.ac.kr Signed-off-by: Paolo Abeni --- drivers/net/ethernet/mellanox/mlx5/core/alloc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c index a92cf545bdaf..dcd281c4691d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c @@ -110,7 +110,7 @@ static struct mlx5_dma_pool *mlx5_dma_pool_create(struct mlx5_core_dev *dev, { struct mlx5_dma_pool *pool; - pool = kzalloc_obj(*pool); + pool = kzalloc_node(sizeof(*pool), GFP_KERNEL, node); if (!pool) return NULL; @@ -127,19 +127,20 @@ mlx5_dma_pool_page_alloc(struct mlx5_dma_pool *pool) { int blocks_per_page = BIT(PAGE_SHIFT - pool->block_shift); struct mlx5_dma_pool_page *page; + int node = pool->node; - page = kzalloc_obj(*page); + page = kzalloc_node(sizeof(*page), GFP_KERNEL, node); if (!page) goto err_out; page->pool = pool; - page->bitmap = bitmap_zalloc(blocks_per_page, GFP_KERNEL); + page->bitmap = bitmap_zalloc_node(blocks_per_page, GFP_KERNEL, node); if (!page->bitmap) goto err_free_page; bitmap_fill(page->bitmap, blocks_per_page); page->buf = mlx5_dma_zalloc_coherent_node(pool->dev, PAGE_SIZE, - &page->dma, pool->node); + &page->dma, node); if (!page->buf) goto err_free_bitmap; @@ -278,7 +279,7 @@ mlx5_frag_buf_node_pools_create(struct mlx5_core_dev *dev, int node) { struct mlx5_frag_buf_node_pools *node_pools; - node_pools = kzalloc_obj(*node_pools); + node_pools = kzalloc_node(sizeof(*node_pools), GFP_KERNEL, node); if (!node_pools) return NULL; From d128212667593c548a3c67d30031063ed46c29b7 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Tue, 6 Oct 2026 12:46:25 +0200 Subject: [PATCH 1459/2126] net: stmmac: set real_num_tx_queues to max(offset + count) tc_setup_dwmac510_mqprio() computes the number of real TX queues as the sum of the per-TC queue counts. mqprio_validate_queue_counts() only rejects out-of-bounds or overlapping ranges, so layouts with gaps or a non-zero first offset are accepted, and in those cases the sum is smaller than the highest queue referenced by the netdev TC map. netif_set_real_num_tx_queues() then passes this too-small count to netif_setup_tc(). However stmmac_set_ndev_tcs() has already zeroed dev->prio_tc_map() through netdev_reset_tc(), so when netif_setup_tc() runs every priority maps to TC0 and only the TC0 range is checked. A layout whose TC0 range fits but where a later TC references a queue beyond the new real_num_tx_queues is left with num_tc set and its TC map pointing at queues that are no longer real, without any warning; only when TC0 itself is out of range is the mapping disabled. The real prio_tc_map is programmed later by the qdisc, after this call, so the driver cannot rely on netif_setup_tc() to catch those cases. Compute num_tx_queues as the maximum of offset[i] + count[i] instead of the sum of the counts, so real_num_tx_queues always covers the highest queue referenced by the TC map. This is a no-op for the contiguous channel-mode layouts where offset[i] == i and count[i] == 1. The issue has been reported by sashiko and the patch has been tested on Qualcomm RB3-Gen2 board. Fixes: 195e4f409a40 ("net: stmmac: support fp parameter of tc-mqprio") Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261006-stmmac-mqprio-prio-offload-v5-1-d7da93419784@oss.qualcomm.com Tested-by: Daniel Thompson Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index 42a00446e9b4..1aa80d51ab33 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -1303,7 +1303,8 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, .count = qopt->count[i], .offset = qopt->offset[i], }; - num_tx_queues += qopt->count[i]; + num_tx_queues = max(num_tx_queues, + qopt->offset[i] + qopt->count[i]); } err = stmmac_set_ndev_tcs(ndev, qopt->num_tc, tc_to_txq); From ac1ca0c3e139a2ebef2fc6c570af6647329726f1 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Tue, 6 Oct 2026 12:46:26 +0200 Subject: [PATCH 1460/2126] net: stmmac: align real_num_tx_queues to mqprio configuration stmmac_hw_setup() unconditionally sets the number of real TX queues to plat->tx_queues_to_use on every device open. When a tc-mqprio qdisc is offloaded the driver reduces netif_set_real_num_tx_queues() to the number of queues enabled by the offload, but the next device open reverts it to plat->tx_queues_to_use while the netdev TC map is still the one programmed by the qdisc, leaving the two inconsistent. Track the number of TX queues enabled by the current qdisc configuration in the per-qdisc state (priv->xmit_qdisc.num_tx_queues) and use it in stmmac_hw_setup(). The field defaults to plat->tx_queues_to_use at probe time and when the mqprio qdisc is destroyed, meaning no offload is active and the number of real TX queues must match the number of queues the driver allocated, and it is updated to the offloaded queue count on a successful mqprio setup. mqprio only validates the requested queue ranges against dev->real_num_tx_queues, which can be larger than plat->tx_queues_to_use while the interface has not been opened yet. Reject a qopt whose highest referenced queue (offset + count) exceeds plat->tx_queues_to_use, so xmit_qdisc.num_tx_queues can never be larger than the number of TX queues the driver provisions. Otherwise stmmac_hw_setup() would expose TX queues without an allocated DMA ring. Refuse to lower the number of TX queues below the count required by the active mqprio offload in stmmac_reinit_queues(), otherwise netif_set_real_num_tx_queues() would leave real_num_tx_queues inconsistent with the netdev TC map. The issue has been reported by sashiko and the patch has been tested on a Qualcomm RB3-Gen2 board. Fixes: 195e4f409a40 ("net: stmmac: support fp parameter of tc-mqprio") Tested-by: Maxime Chevallier Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261006-stmmac-mqprio-prio-offload-v5-2-d7da93419784@oss.qualcomm.com Tested-by: Daniel Thompson Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 6 ++++++ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 +++++++++++- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 9278378407e8..fd68b90cc88f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -299,6 +299,12 @@ struct stmmac_priv { /* Protect est parameters */ struct mutex est_lock; struct stmmac_est *est; + + struct { + bool enabled; + u32 num_tx_queues; + } xmit_qdisc; + struct dma_features dma_cap; struct stmmac_counters mmc; int hw_cap_support; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index b8b4de4c5b1a..dba6374c9cf5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3777,7 +3777,7 @@ static int stmmac_hw_setup(struct net_device *dev) /* Configure real RX and TX queues */ netif_set_real_num_rx_queues(dev, priv->plat->rx_queues_to_use); - netif_set_real_num_tx_queues(dev, priv->plat->tx_queues_to_use); + netif_set_real_num_tx_queues(dev, priv->xmit_qdisc.num_tx_queues); /* Start the ball rolling... */ stmmac_start_all_dma(priv); @@ -7742,6 +7742,10 @@ int stmmac_reinit_queues(struct net_device *dev, u8 rx_cnt, u8 tx_cnt) struct stmmac_priv *priv = netdev_priv(dev); int ret = 0, i; + if (priv->xmit_qdisc.enabled && + tx_cnt < priv->xmit_qdisc.num_tx_queues) + return -EINVAL; + if (netif_running(dev)) stmmac_release(dev); @@ -7749,6 +7753,9 @@ int stmmac_reinit_queues(struct net_device *dev, u8 rx_cnt, u8 tx_cnt) priv->plat->rx_queues_to_use = rx_cnt; priv->plat->tx_queues_to_use = tx_cnt; + if (!priv->xmit_qdisc.enabled) + priv->xmit_qdisc.num_tx_queues = tx_cnt; + if (!netif_is_rxfh_configured(dev)) for (i = 0; i < ARRAY_SIZE(priv->rss.table); i++) priv->rss.table[i] = ethtool_rxfh_indir_default(i, @@ -8060,6 +8067,9 @@ static int __stmmac_dvr_probe(struct device *device, ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_XSK_ZEROCOPY; + /* Default qdisc num_tx_queues */ + priv->xmit_qdisc.num_tx_queues = priv->plat->tx_queues_to_use; + ret = stmmac_tc_init(priv, priv); if (!ret) { ndev->hw_features |= NETIF_F_HW_TC; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index 1aa80d51ab33..a7721b2eee96 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -1266,6 +1266,9 @@ static int stmmac_reset_tc_mqprio(struct net_device *ndev, { struct stmmac_priv *priv = netdev_priv(ndev); + priv->xmit_qdisc.num_tx_queues = priv->plat->tx_queues_to_use; + priv->xmit_qdisc.enabled = false; + netdev_reset_tc(ndev); netif_set_real_num_tx_queues(ndev, priv->plat->tx_queues_to_use); @@ -1299,6 +1302,13 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, ndev_prio_tc_map[i] = READ_ONCE(ndev->prio_tc_map[i]); for (i = 0; i < qopt->num_tc; i++) { + if (qopt->offset[i] + qopt->count[i] > + priv->plat->tx_queues_to_use) { + NL_SET_ERR_MSG_MOD(extack, + "Queues exceed hw TX queues"); + return -EINVAL; + } + tc_to_txq[i] = (struct netdev_tc_txq) { .count = qopt->count[i], .offset = qopt->offset[i], @@ -1321,6 +1331,9 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, if (err) goto error_reset_num_tx_queues; + priv->xmit_qdisc.num_tx_queues = num_tx_queues; + priv->xmit_qdisc.enabled = true; + return 0; error_reset_num_tx_queues: From 47891d501e345629536481ffc57e2e4b2f2d4770 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Tue, 6 Oct 2026 12:46:27 +0200 Subject: [PATCH 1461/2126] net: stmmac: add tc mqprio hw queue priority offload Implement the offload of the tc mqprio hw queue priority in the stmmac driver. When the mqprio qdisc is configured in channel mode, the MTL TX scheduler is switched to strict priority, and the PSTQX/PSTC priority bitmask of each TX queue is programmed from the set of frame priorities mapped to the owning traffic class (qopt->prio_tc_map). The channel mode offload requires the DCB hw feature and a 1:1 TC to TX queue mapping, with a single queue per TC. Configurations with AVB queues are rejected, since forcing strict priority conflicts with the CBS algorithm. The CBS offload is refused while the strict-priority scheduler is active, and so is a channel count change that would enable an AVB queue. In the default DCB mode, only the netdev TC map and the FPE preemption class mapping are offloaded, leaving the MTL scheduler and the per-queue priorities to the device-tree configuration. The num_tc bound against ARRAY_SIZE(tc_to_txq) is no longer needed: the check that each TC's offset + count stays within plat->tx_queues_to_use already bounds num_tc, because the TC ranges do not overlap and each one spans at least one queue. Reviewed-by: Davide Caratti Tested-by: Maxime Chevallier Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261006-stmmac-mqprio-prio-offload-v5-3-d7da93419784@oss.qualcomm.com Tested-by: Daniel Thompson Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../net/ethernet/stmicro/stmmac/stmmac_fpe.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 33 +++-- .../net/ethernet/stmicro/stmmac/stmmac_tc.c | 134 ++++++++++++++++-- 4 files changed, 148 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index fd68b90cc88f..08b68441f9c8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -302,7 +302,10 @@ struct stmmac_priv { struct { bool enabled; + u32 prio[MTL_MAX_TX_QUEUES]; + bool prio_offload; u32 num_tx_queues; + u8 algo; } xmit_qdisc; struct dma_features dma_cap; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c index c889204a7aa5..b6b5ef7c8fc4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c @@ -230,7 +230,7 @@ int dwmac5_fpe_map_preemption_class(struct net_device *ndev, if (count == 1) continue; - if (priv->plat->tx_sched_algorithm == MTL_TX_ALGORITHM_SP) { + if (priv->xmit_qdisc.algo == MTL_TX_ALGORITHM_SP) { NL_SET_ERR_MSG_MOD(extack, ALG_ERR_MSG); return -EINVAL; } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index dba6374c9cf5..56d89a696272 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3532,17 +3532,11 @@ static void stmmac_mac_config_rx_queues_prio(struct stmmac_priv *priv) */ static void stmmac_mac_config_tx_queues_prio(struct stmmac_priv *priv) { - u8 tx_queues_count = priv->plat->tx_queues_to_use; - u8 queue; - u32 prio; + int i; - for (queue = 0; queue < tx_queues_count; queue++) { - if (!priv->plat->tx_queues_cfg[queue].use_prio) - continue; - - prio = priv->plat->tx_queues_cfg[queue].prio; - stmmac_tx_queue_prio(priv, priv->hw, prio, queue); - } + for (i = 0; i < priv->plat->tx_queues_to_use; i++) + stmmac_tx_queue_prio(priv, priv->hw, + priv->xmit_qdisc.prio[i], i); } /** @@ -3603,7 +3597,7 @@ static void stmmac_mtl_configuration(struct stmmac_priv *priv) /* Configure MTL TX algorithms */ if (tx_queues_count > 1) stmmac_prog_mtl_tx_algorithms(priv, priv->hw, - priv->plat->tx_sched_algorithm); + priv->xmit_qdisc.algo); /* Configure CBS in AVB TX queues */ if (tx_queues_count > 1) @@ -7746,6 +7740,14 @@ int stmmac_reinit_queues(struct net_device *dev, u8 rx_cnt, u8 tx_cnt) tx_cnt < priv->xmit_qdisc.num_tx_queues) return -EINVAL; + if (priv->xmit_qdisc.prio_offload) { + for (i = priv->plat->tx_queues_to_use; i < tx_cnt; i++) { + if (priv->plat->tx_queues_cfg[i].mode_to_use == + MTL_QUEUE_AVB) + return -EINVAL; + } + } + if (netif_running(dev)) stmmac_release(dev); @@ -7991,6 +7993,15 @@ static int __stmmac_dvr_probe(struct device *device, priv->wol_irq = res->wol_irq; priv->sfty_irq = res->sfty_irq; + /* Default xmit qdisc configuration */ + for (i = 0; i < ARRAY_SIZE(priv->plat->tx_queues_cfg); i++) { + if (!priv->plat->tx_queues_cfg[i].use_prio) + continue; + + priv->xmit_qdisc.prio[i] = priv->plat->tx_queues_cfg[i].prio; + } + priv->xmit_qdisc.algo = priv->plat->tx_sched_algorithm; + if (priv->plat->flags & STMMAC_FLAG_MULTI_MSI_EN) { ret = stmmac_msi_init(priv, res); if (ret) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index a7721b2eee96..ea1f97d6f0bd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -346,6 +346,9 @@ static int tc_setup_cbs(struct stmmac_priv *priv, if (!priv->dma_cap.av) return -EOPNOTSUPP; + if (qopt->enable && priv->xmit_qdisc.prio_offload) + return -EOPNOTSUPP; + port_transmit_rate_kbps = qopt->idleslope - qopt->sendslope; if (qopt->enable) { @@ -1266,6 +1269,28 @@ static int stmmac_reset_tc_mqprio(struct net_device *ndev, { struct stmmac_priv *priv = netdev_priv(ndev); + if (priv->xmit_qdisc.prio_offload) { + int i; + + for (i = 0; i < ARRAY_SIZE(priv->plat->tx_queues_cfg); i++) { + u32 prio; + + if (priv->plat->tx_queues_cfg[i].use_prio) + prio = priv->plat->tx_queues_cfg[i].prio; + else + prio = 0; + + priv->xmit_qdisc.prio[i] = prio; + if (i < priv->plat->tx_queues_to_use) + stmmac_tx_queue_prio(priv, priv->hw, prio, i); + } + + stmmac_prog_mtl_tx_algorithms(priv, priv->hw, + priv->plat->tx_sched_algorithm); + priv->xmit_qdisc.algo = priv->plat->tx_sched_algorithm; + priv->xmit_qdisc.prio_offload = false; + } + priv->xmit_qdisc.num_tx_queues = priv->plat->tx_queues_to_use; priv->xmit_qdisc.enabled = false; @@ -1275,6 +1300,83 @@ static int stmmac_reset_tc_mqprio(struct net_device *ndev, return stmmac_fpe_map_preemption_class(priv, ndev, extack, 0); } +static void tc_mqprio_config_queue_prio(struct stmmac_priv *priv, + struct tc_mqprio_qopt *qopt) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(priv->plat->tx_queues_cfg); i++) { + u32 prio = 0; + int j; + + for (j = 0; j < qopt->num_tc; j++) { + int p; + + if (qopt->offset[j] != i) + continue; + + /* The PSTQX/PSTC priority map is 8 bits wide, so only + * priorities 0-7 can be represented in hardware. + * Priorities 8-15 are handled in software by the + * kernel through the netdev prio_tc_map. + */ + for (p = 0; p < 8; p++) { + if (qopt->prio_tc_map[p] == j) + prio |= BIT(p); + } + break; + } + + priv->xmit_qdisc.prio[i] = prio; + if (i < priv->plat->tx_queues_to_use) + stmmac_tx_queue_prio(priv, priv->hw, prio, i); + } + + stmmac_prog_mtl_tx_algorithms(priv, priv->hw, MTL_TX_ALGORITHM_SP); + priv->xmit_qdisc.algo = MTL_TX_ALGORITHM_SP; + priv->xmit_qdisc.prio_offload = true; +} + +static int tc_mqprio_validate_chan_mode(struct stmmac_priv *priv, + struct tc_mqprio_qopt_offload *mqprio) +{ + struct plat_stmmacenet_data *pdata = priv->plat; + struct tc_mqprio_qopt *qopt = &mqprio->qopt; + int i; + + if (!priv->dma_cap.dcben) { + NL_SET_ERR_MSG_MOD(mqprio->extack, + "hw DCB is required to offload mqprio"); + return -EOPNOTSUPP; + } + + /* Forcing strict priority conflicts with the CBS algorithm + * of AVB queues, so reject the offload when any queue is + * configured as AVB. + */ + for (i = 0; i < pdata->tx_queues_to_use; i++) { + if (pdata->tx_queues_cfg[i].mode_to_use == MTL_QUEUE_AVB) { + NL_SET_ERR_MSG_MOD(mqprio->extack, + "SP conflicts with AVB queues"); + return -EOPNOTSUPP; + } + } + + for (i = 0; i < qopt->num_tc; i++) { + /* The offload switches the MTL scheduler to strict + * priority, which only supports a 1:1 TC to TX queue + * mapping. + */ + if (qopt->count[i] > 1 || qopt->offset[i] != i) { + NL_SET_ERR_MSG_MOD(mqprio->extack, + "SP requires 1:1 TXQ map"); + return -EOPNOTSUPP; + } + } + + return 0; +} + static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, struct tc_mqprio_qopt_offload *mqprio) { @@ -1285,22 +1387,11 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, struct tc_mqprio_qopt *qopt = &mqprio->qopt; struct net_device *ndev = priv->dev; u8 ndev_prio_tc_map[TC_BITMASK + 1]; - int i, err, ndev_ntc; + int i, err, ndev_ntc, mode; if (!qopt->num_tc) return stmmac_reset_tc_mqprio(ndev, extack); - if (qopt->num_tc > ARRAY_SIZE(tc_to_txq)) - return -EINVAL; - - /* save current tc values for reset */ - ndev_ntc = netdev_get_num_tc(ndev); - for (i = 0; i < ARRAY_SIZE(ndev->tc_to_txq); i++) - ndev_tc_to_txq[i].combined = - READ_ONCE(ndev->tc_to_txq[i].combined); - for (i = 0; i < ARRAY_SIZE(ndev_prio_tc_map); i++) - ndev_prio_tc_map[i] = READ_ONCE(ndev->prio_tc_map[i]); - for (i = 0; i < qopt->num_tc; i++) { if (qopt->offset[i] + qopt->count[i] > priv->plat->tx_queues_to_use) { @@ -1317,6 +1408,22 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, qopt->offset[i] + qopt->count[i]); } + mode = mqprio->flags & TC_MQPRIO_F_MODE ? mqprio->mode + : TC_MQPRIO_MODE_DCB; + if (mode == TC_MQPRIO_MODE_CHANNEL) { + err = tc_mqprio_validate_chan_mode(priv, mqprio); + if (err) + return err; + } + + /* save current tc values for reset */ + ndev_ntc = netdev_get_num_tc(ndev); + for (i = 0; i < ARRAY_SIZE(ndev->tc_to_txq); i++) + ndev_tc_to_txq[i].combined = + READ_ONCE(ndev->tc_to_txq[i].combined); + for (i = 0; i < ARRAY_SIZE(ndev_prio_tc_map); i++) + ndev_prio_tc_map[i] = READ_ONCE(ndev->prio_tc_map[i]); + err = stmmac_set_ndev_tcs(ndev, qopt->num_tc, tc_to_txq); if (err) goto error_reset_tc; @@ -1331,6 +1438,9 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, if (err) goto error_reset_num_tx_queues; + if (mode == TC_MQPRIO_MODE_CHANNEL) + tc_mqprio_config_queue_prio(priv, qopt); + priv->xmit_qdisc.num_tx_queues = num_tx_queues; priv->xmit_qdisc.enabled = true; From ebc938ba1d5ff33652013b99c7b9a74f05690336 Mon Sep 17 00:00:00 2001 From: Aaradhana Sahu Date: Thu, 1 Oct 2026 10:24:23 +0530 Subject: [PATCH 1462/2126] wifi: ath12k: Fix NAPI resource leaks in AHB external IRQ paths Currently, NAPI instances and their associated netdevs allocated for AHB external IRQ groups are not released when external IRQ configuration fails. They are also not freed when arch_init() fails after ath12k_ahb_config_irq() succeeds during probe, or when the driver is unloaded. Fix this by adding a common cleanup helper to release the NAPI instances and associated netdevs. Call it from the external IRQ configuration error path, probe error path, and driver cleanup path. Tested-on: IPQ5332 hw1.0 AHB WLAN.WBE.1.6-01275-QCAHKSWPL_SILICONZ-1 Fixes: 6cee30f0da75 ("wifi: ath12k: add AHB driver support for IPQ5332") Fixes: 614c23e24ee8 ("wifi: ath12k: Support arch-specific DP device allocation") Signed-off-by: Aaradhana Sahu Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261001045423.493121-1-aaradhana.sahu@oss.qualcomm.com [renamed label err_free_irq] Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/ahb.c | 41 ++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/ahb.c b/drivers/net/wireless/ath/ath12k/ahb.c index 85360365aa4b..2c55aae06dd0 100644 --- a/drivers/net/wireless/ath/ath12k/ahb.c +++ b/drivers/net/wireless/ath/ath12k/ahb.c @@ -191,6 +191,26 @@ static void __ath12k_ahb_ext_irq_disable(struct ath12k_base *ab) } } +static void ath12k_ahb_free_napi_for_group(struct ath12k_ext_irq_grp *irq_grp) +{ + netif_napi_del(&irq_grp->napi); + free_netdev(irq_grp->napi_ndev); + irq_grp->napi_ndev = NULL; +} + +static void ath12k_ahb_free_napi(struct ath12k_base *ab, int num_ext_irq_grp) +{ + int i; + + for (i = 0; i < num_ext_irq_grp; i++) + ath12k_ahb_free_napi_for_group(&ab->ext_irq_grp[i]); +} + +static void ath12k_ahb_free_ext_napi(struct ath12k_base *ab) +{ + ath12k_ahb_free_napi(ab, ATH12K_EXT_IRQ_GRP_NUM_MAX); +} + static void ath12k_ahb_ext_grp_enable(struct ath12k_ext_irq_grp *irq_grp) { int i; @@ -622,8 +642,10 @@ static int ath12k_ahb_config_ext_irq(struct ath12k_base *ab) irq_grp->grp_id = i; irq_grp->napi_ndev = alloc_netdev_dummy(0); - if (!irq_grp->napi_ndev) - return -ENOMEM; + if (!irq_grp->napi_ndev) { + ret = -ENOMEM; + goto free_napi_ndev; + } netif_napi_add(irq_grp->napi_ndev, &irq_grp->napi, ath12k_ahb_ext_grp_napi_poll); @@ -675,12 +697,19 @@ static int ath12k_ahb_config_ext_irq(struct ath12k_base *ab) ath12k_ahb_ext_interrupt_handler, IRQF_TRIGGER_RISING, irq_name[irq_idx], irq_grp); - if (ret) + if (ret) { ath12k_warn(ab, "failed request_irq for %d\n", irq); + ath12k_ahb_free_napi_for_group(irq_grp); + goto free_napi_ndev; + } } } return 0; + +free_napi_ndev: + ath12k_ahb_free_napi(ab, i); + return ret; } static int ath12k_ahb_config_irq(struct ath12k_base *ab) @@ -1353,7 +1382,7 @@ static int ath12k_ahb_probe(struct platform_device *pdev) ret = ab_ahb->device_family_ops->arch_init(ab); if (ret) { ath12k_err(ab, "AHB arch_init failed %d\n", ret); - goto err_rproc_deconfigure; + goto err_free_ext_napi; } ret = ath12k_core_init(ab); @@ -1367,6 +1396,9 @@ static int ath12k_ahb_probe(struct platform_device *pdev) err_deinit_arch: ab_ahb->device_family_ops->arch_deinit(ab); +err_free_ext_napi: + ath12k_ahb_free_ext_napi(ab); + err_rproc_deconfigure: mutex_lock(&ath12k_rproc_info_lock); ath12k_ahb_deconfigure_rproc(ab); @@ -1409,6 +1441,7 @@ static void ath12k_ahb_free_resources(struct ath12k_base *ab) struct platform_device *pdev = ab->pdev; struct ath12k_ahb *ab_ahb = ath12k_ab_to_ahb(ab); + ath12k_ahb_free_ext_napi(ab); ath12k_hal_srng_deinit(ab); ath12k_ce_free_pipes(ab); ath12k_ahb_resource_deinit(ab); From 1c1a208e65a08191901cfded3bbccc4a54e4a75c Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:20:58 +0800 Subject: [PATCH 1463/2126] wifi: ath10k: avoid IDR mutation during TX cleanup ath10k_htt_flush_tx_queue() walks pending_tx with idr_for_each(). Its callback calls ath10k_txrx_tx_unref(), which removes the current entry from pending_tx through ath10k_htt_tx_free_msdu_id(). idr_for_each() keeps radix-tree iterator state across the callback. Removing the current entry can therefore invalidate that state and make the remaining walk unsafe. Use idr_for_each_entry(), which starts a fresh lookup after each callback. The current entry can then be removed safely, while the following idr_destroy() continues to release the IDR itself. Fixes: 89d6d83565e9 ("ath10k: use idr api for msdu_ids") Signed-off-by: Jiale Yao Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261003092104.520135-2-yaojiale02@163.com [changed ath10k_htt_tx_clean_up_pending() signature] Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath10k/htt_tx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireless/ath/ath10k/htt_tx.c index e46f579d745d..efaea150025b 100644 --- a/drivers/net/wireless/ath/ath10k/htt_tx.c +++ b/drivers/net/wireless/ath/ath10k/htt_tx.c @@ -505,9 +505,8 @@ free_idr_pending_tx: return ret; } -static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx) +static void ath10k_htt_tx_clean_up_pending(int msdu_id, struct ath10k *ar) { - struct ath10k *ar = ctx; struct ath10k_htt *htt = &ar->htt; struct htt_tx_done tx_done = {}; @@ -517,8 +516,6 @@ static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx) tx_done.status = HTT_TX_COMPL_STATE_DISCARD; ath10k_txrx_tx_unref(htt, &tx_done); - - return 0; } void ath10k_htt_tx_destroy(struct ath10k_htt *htt) @@ -535,8 +532,13 @@ void ath10k_htt_tx_destroy(struct ath10k_htt *htt) static void ath10k_htt_flush_tx_queue(struct ath10k_htt *htt) { + struct sk_buff *msdu; + int msdu_id; + ath10k_htc_stop_hl(htt->ar); - idr_for_each(&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar); + + idr_for_each_entry(&htt->pending_tx, msdu, msdu_id) + ath10k_htt_tx_clean_up_pending(msdu_id, htt->ar); } void ath10k_htt_tx_stop(struct ath10k_htt *htt) From 3e7f5d362b2b3a21b3adb4b860aad14b69a896ad Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:20:59 +0800 Subject: [PATCH 1464/2126] wifi: ath11k: avoid IDR mutation during pending mgmt TX cleanup The pending management TX cleanup walks txmgmt_idr with idr_for_each(), and its callback removes the current entry. This can invalidate the radix-tree iterator retained by idr_for_each(). Use idr_for_each_entry() so every iteration starts with a fresh lookup. Continue to remove each entry under txmgmt_idr_lock before freeing its skb, preventing concurrent TX completion from finding a stale skb pointer. Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices") Signed-off-by: Jiale Yao Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261003092104.520135-3-yaojiale02@163.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/core.c | 3 +-- drivers/net/wireless/ath/ath11k/mac.c | 12 ++++++------ drivers/net/wireless/ath/ath11k/mac.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index 1ad0a47653de..766ae27306f4 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -2448,8 +2448,7 @@ void ath11k_core_pre_reconfigure_recovery(struct ath11k_base *ab) complete(&ar->thermal.wmi_sync); wake_up(&ar->dp.tx_empty_waitq); - idr_for_each(&ar->txmgmt_idr, - ath11k_mac_tx_mgmt_pending_free, ar); + ath11k_mac_tx_mgmt_pending_free(ar); idr_destroy(&ar->txmgmt_idr); wake_up(&ar->txmgmt_empty_waitq); diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index c1fa42edd363..1ee32c7dc494 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -6167,13 +6167,13 @@ static void ath11k_mac_tx_mgmt_free(struct ath11k *ar, int buf_id) ath11k_mgmt_over_wmi_tx_drop(ar, msdu); } -int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) +void ath11k_mac_tx_mgmt_pending_free(struct ath11k *ar) { - struct ath11k *ar = ctx; + struct sk_buff *msdu; + int buf_id; - ath11k_mac_tx_mgmt_free(ar, buf_id); - - return 0; + idr_for_each_entry(&ar->txmgmt_idr, msdu, buf_id) + ath11k_mac_tx_mgmt_free(ar, buf_id); } static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) @@ -10418,7 +10418,7 @@ static void __ath11k_mac_unregister(struct ath11k *ar) ieee80211_unregister_hw(ar->hw); - idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar); + ath11k_mac_tx_mgmt_pending_free(ar); idr_destroy(&ar->txmgmt_idr); kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); diff --git a/drivers/net/wireless/ath/ath11k/mac.h b/drivers/net/wireless/ath/ath11k/mac.h index 59f83c7175fd..127cb476b44b 100644 --- a/drivers/net/wireless/ath/ath11k/mac.h +++ b/drivers/net/wireless/ath/ath11k/mac.h @@ -162,7 +162,7 @@ struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id) void ath11k_mac_drain_tx(struct ath11k *ar); void ath11k_mac_peer_cleanup_all(struct ath11k *ar); -int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx); +void ath11k_mac_tx_mgmt_pending_free(struct ath11k *ar); u8 ath11k_mac_bw_to_mac80211_bw(u8 bw); enum nl80211_he_gi ath11k_mac_he_gi_to_nl80211_he_gi(u8 sgi); enum nl80211_he_ru_alloc ath11k_mac_phy_he_ru_to_nl80211_he_ru_alloc(u16 ru_phy); From dc29226dada34a6d19af77b4b51e90f8a3a8de34 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:21:00 +0800 Subject: [PATCH 1465/2126] wifi: ath11k: avoid IDR mutation during vif mgmt TX cleanup ath11k_mac_op_remove_interface() walks txmgmt_idr with idr_for_each(), and its callback removes each entry belonging to the interface. Removing the current entry can invalidate the radix-tree iterator retained by idr_for_each(). Move the walk into a helper that uses idr_for_each_entry(). It performs a fresh lookup for every iteration, so each matching entry can be removed through the locked removal helper without retaining iterator state across the removal. Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices") Signed-off-by: Jiale Yao Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261003092104.520135-4-yaojiale02@163.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index 1ee32c7dc494..1a237adaa37d 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -6176,16 +6176,18 @@ void ath11k_mac_tx_mgmt_pending_free(struct ath11k *ar) ath11k_mac_tx_mgmt_free(ar, buf_id); } -static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) +static void ath11k_mac_vif_txmgmt_cleanup(struct ath11k *ar, + struct ieee80211_vif *vif) { - struct ieee80211_vif *vif = ctx; - struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb); - struct ath11k *ar = skb_cb->ar; + struct ath11k_skb_cb *skb_cb; + struct sk_buff *skb; + int buf_id; - if (skb_cb->vif == vif) - ath11k_mac_tx_mgmt_free(ar, buf_id); - - return 0; + idr_for_each_entry(&ar->txmgmt_idr, skb, buf_id) { + skb_cb = ATH11K_SKB_CB(skb); + if (skb_cb->vif == vif) + ath11k_mac_tx_mgmt_free(ar, buf_id); + } } static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif, @@ -7417,8 +7419,7 @@ err_vdev_del: ath11k_peer_cleanup(ar, arvif->vdev_id); - idr_for_each(&ar->txmgmt_idr, - ath11k_mac_vif_txmgmt_idr_remove, vif); + ath11k_mac_vif_txmgmt_cleanup(ar, vif); for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock); From 94c7b50351fd30e1dfe1b4051197a1445d8547e1 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:21:01 +0800 Subject: [PATCH 1466/2126] wifi: ath12k: avoid IDR mutation during pending mgmt TX cleanup The pending management TX cleanup walks txmgmt_idr with idr_for_each(), and its callback removes the current entry. This can invalidate the radix-tree iterator retained by idr_for_each(). Use idr_for_each_entry() so every iteration starts with a fresh lookup. Continue to remove each entry under txmgmt_idr_lock before freeing its skb, preventing concurrent TX completion from finding a stale skb pointer. Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Jiale Yao Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261003092104.520135-5-yaojiale02@163.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/core.c | 3 +-- drivers/net/wireless/ath/ath12k/mac.c | 12 ++++++------ drivers/net/wireless/ath/ath12k/mac.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index c9df99bc54fd..0110f78400de 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -1571,8 +1571,7 @@ static void ath12k_core_pre_reconfigure_recovery(struct ath12k_base *ab) complete_all(&ar->thermal.wmi_sync); wake_up(&ar->dp.tx_empty_waitq); - idr_for_each(&ar->txmgmt_idr, - ath12k_mac_tx_mgmt_pending_free, ar); + ath12k_mac_tx_mgmt_pending_free(ar); idr_destroy(&ar->txmgmt_idr); wake_up(&ar->txmgmt_empty_waitq); diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index db6856ec6c14..56c3cc8506e1 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -9194,13 +9194,13 @@ static void ath12k_mac_tx_mgmt_free(struct ath12k *ar, int buf_id) ath12k_mgmt_over_wmi_tx_drop(ar, msdu); } -int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) +void ath12k_mac_tx_mgmt_pending_free(struct ath12k *ar) { - struct ath12k *ar = ctx; + struct sk_buff *msdu; + int buf_id; - ath12k_mac_tx_mgmt_free(ar, buf_id); - - return 0; + idr_for_each_entry(&ar->txmgmt_idr, msdu, buf_id) + ath12k_mac_tx_mgmt_free(ar, buf_id); } static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) @@ -14738,7 +14738,7 @@ static struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = { static void ath12k_mac_cleanup_unregister(struct ath12k *ar) { - idr_for_each(&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar); + ath12k_mac_tx_mgmt_pending_free(ar); idr_destroy(&ar->txmgmt_idr); kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); diff --git a/drivers/net/wireless/ath/ath12k/mac.h b/drivers/net/wireless/ath/ath12k/mac.h index aba98afd4365..ae44ebfd9bd9 100644 --- a/drivers/net/wireless/ath/ath12k/mac.h +++ b/drivers/net/wireless/ath/ath12k/mac.h @@ -173,7 +173,7 @@ struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id) void ath12k_mac_drain_tx(struct ath12k *ar); void ath12k_mac_peer_cleanup_all(struct ath12k *ar); void ath12k_mac_dp_peer_cleanup(struct ath12k_hw *ah); -int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx); +void ath12k_mac_tx_mgmt_pending_free(struct ath12k *ar); enum rate_info_bw ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw); enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw); enum hal_encrypt_type ath12k_dp_tx_get_encrypt_type(u32 cipher); From 4aa45334eb23d40bf31c43405daea9b73469f2a6 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Sat, 3 Oct 2026 17:21:02 +0800 Subject: [PATCH 1467/2126] wifi: ath12k: avoid IDR mutation during vif mgmt TX cleanup ath12k_mac_vdev_delete() walks txmgmt_idr with idr_for_each(), and its callback removes each entry belonging to the interface. Removing the current entry can invalidate the radix-tree iterator retained by idr_for_each(). Move the walk into a helper that uses idr_for_each_entry(). It performs a fresh lookup for every iteration, so each matching entry can be removed through the locked removal helper without retaining iterator state across the removal. Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Jiale Yao Reviewed-by: Baochen Qiang Reviewed-by: Rameshkumar Sundaram Link: https://patch.msgid.link/20261003092104.520135-6-yaojiale02@163.com Signed-off-by: Jeff Johnson --- drivers/net/wireless/ath/ath12k/mac.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 56c3cc8506e1..01f8c6572f65 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -9203,16 +9203,18 @@ void ath12k_mac_tx_mgmt_pending_free(struct ath12k *ar) ath12k_mac_tx_mgmt_free(ar, buf_id); } -static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) +static void ath12k_mac_vif_txmgmt_cleanup(struct ath12k *ar, + struct ieee80211_vif *vif) { - struct ieee80211_vif *vif = ctx; - struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); - struct ath12k *ar = skb_cb->ar; + struct ath12k_skb_cb *skb_cb; + struct sk_buff *skb; + int buf_id; - if (skb_cb->vif == vif) - ath12k_mac_tx_mgmt_free(ar, buf_id); - - return 0; + idr_for_each_entry(&ar->txmgmt_idr, skb, buf_id) { + skb_cb = ATH12K_SKB_CB(skb); + if (skb_cb->vif == vif) + ath12k_mac_tx_mgmt_free(ar, buf_id); + } } static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_link_vif *arvif, @@ -10977,8 +10979,7 @@ err_vdev_del: ath12k_peer_cleanup(ar, arvif->vdev_id); ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); - idr_for_each(&ar->txmgmt_idr, - ath12k_mac_vif_txmgmt_idr_remove, vif); + ath12k_mac_vif_txmgmt_cleanup(ar, vif); ath12k_mac_vif_unref(ath12k_ab_to_dp(ab), vif); From 0b3fc7fe6f3f68569b9f9139893491b61a4b45b9 Mon Sep 17 00:00:00 2001 From: Vikas Gupta Date: Tue, 6 Oct 2026 19:49:28 +0530 Subject: [PATCH 1468/2126] bnge: skip dev_addr when building the VNIC unicast list The default VNIC programs the device's MAC as L2 filter 0 in bnge_init_chip() via bnge_hwrm_set_vnic_filter(bn, 0, 0, dev_addr). bnge_cfg_rx_mode() then walks dev->uc and programs each unicast address as a further L2 filter, without excluding dev_addr. Skip dev_addr when building uc_list, since it is already installed as filter 0. As dev_addr now takes neither a uc_list slot nor an l2_filters[] slot, count only the non-dev_addr entries for the uc_list overflow check too, otherwise an input such as {dev_addr, A, B, C} would needlessly fall back to promiscuous mode even though A, B and C fit in exact-match filters. bnge_uc_list_updated() applies the same skip and count so the change detection stays consistent and does not loop. This issue was caught by Sashiko (nipa). Tested on Thor Ultra device. Fixes: 9afad4a17174 ("bng_en: Configure default VNIC") Signed-off-by: Vikas Gupta Reviewed-by: Dharmender Garg Link: https://patch.msgid.link/20261006141928.1432927-1-vikas.gupta@broadcom.com Signed-off-by: Paolo Abeni --- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c index 7dbe853a5a47..25f844e6f6d3 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c @@ -2204,19 +2204,21 @@ static bool bnge_uc_list_updated(struct bnge_net *bn, const struct netdev_hw_addr_list *uc) { struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT]; + struct net_device *dev = bn->netdev; struct netdev_hw_addr *ha; - int off = 0; - - if (netdev_hw_addr_list_count(uc) != (vnic->uc_filter_count - 1)) - return true; + int off = 0, count = 0; netdev_hw_addr_list_for_each(ha, uc) { + if (ether_addr_equal(ha->addr, dev->dev_addr)) + continue; + if (count >= vnic->uc_filter_count - 1) + return true; if (!ether_addr_equal(ha->addr, vnic->uc_list + off)) return true; - off += ETH_ALEN; + count++; } - return false; + return count != vnic->uc_filter_count - 1; } static bool bnge_promisc_ok(struct bnge_net *bn) @@ -2229,9 +2231,9 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc, { struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT]; struct net_device *dev = bn->netdev; + int i, off = 0, rc, uc_count = 0; struct bnge_dev *bd = bn->bd; struct netdev_hw_addr *ha; - int i, off = 0, rc; if (!uc_update) goto skip_uc; @@ -2247,10 +2249,20 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc, if (!snapshot) netif_addr_lock_bh(dev); - if (netdev_hw_addr_list_count(uc) > (BNGE_MAX_UC_ADDRS - 1)) { + /* dev_addr is already programmed as L2 filter 0, so it takes neither a + * uc_list slot nor an l2_filters[] slot. Count only the entries that + * will actually be programmed so the overflow check matches the fill + * loop below (and bnge_uc_list_updated()). + */ + netdev_hw_addr_list_for_each(ha, uc) + if (!ether_addr_equal(ha->addr, dev->dev_addr)) + uc_count++; + if (uc_count > BNGE_MAX_UC_ADDRS - 1) { vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; } else { netdev_hw_addr_list_for_each(ha, uc) { + if (ether_addr_equal(ha->addr, dev->dev_addr)) + continue; memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN); off += ETH_ALEN; vnic->uc_filter_count++; From d538cc3ec0bc4cb7b40981b3213a6c6671959ed5 Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Wed, 7 Oct 2026 12:25:00 -0300 Subject: [PATCH 1469/2126] calipso: hash the cache key, not the option start, in calipso_cache_add() calipso_cache_add() stores calipso_ptr + 2 as the cache key, but computes entry->hash over calipso_ptr, i.e. starting two bytes earlier at the option type and length. calipso_opt_getattr() looks entries up with calipso_cache_check(calipso + 2, calipso[1], ...), which hashes the key itself. The two hashes only match on a jhash collision, so the CALIPSO label cache never hits and every labelled packet takes the full DOI lookup and category conversion path. The memcmp() on the key keeps lookups correct, so this is a performance bug only. Hash the stored key, as cipso_v4_cache_add() does for CIPSO. Fixes: 4fee5242bf41 ("calipso: Add a label cache.") Signed-off-by: Joas Antonio dos Santos Assisted-by: Claude:claude-opus-5-5 Reviewed-by: Daniel Machon Link: https://patch.msgid.link/179138670045.80227.16155454353416856947@gmail.com Signed-off-by: Paolo Abeni --- net/ipv6/calipso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index c6a34334e657..194772ed0cb9 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -283,7 +283,7 @@ static int calipso_cache_add(const unsigned char *calipso_ptr, goto cache_add_failure; } entry->key_len = calipso_ptr_len; - entry->hash = calipso_map_cache_hash(calipso_ptr, calipso_ptr_len); + entry->hash = calipso_map_cache_hash(entry->key, calipso_ptr_len); refcount_inc(&secattr->cache->refcount); entry->lsm_data = secattr->cache; From ffe378c06c10b97806e2109a5d619a48a9c2940c Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Thu, 8 Oct 2026 16:31:56 +0300 Subject: [PATCH 1470/2126] ipv6: Report netns cookie in fib6_table_lookup tracepoint The first argument of the tracepoint is a pointer to the network namespace in which the FIB lookup was performed, but the tracepoint does not report information about it in the associated trace record, making it impossible to tell apart lookups performed in different namespaces. Report the network namespace cookie, as commit 27cb3de7f43a ("net: add net cookie for net device trace events") did for the net device tracepoints. Assisted-by: LLM Reviewed-by: Petr Machata Reviewed-by: Ferenc Fejes Signed-off-by: Ido Schimmel Reviewed-by: David Ahern Link: https://patch.msgid.link/20261008133158.1438907-2-idosch@nvidia.com Signed-off-by: Paolo Abeni --- include/trace/events/fib6.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/trace/events/fib6.h b/include/trace/events/fib6.h index 8d22b2e98d48..e58facd2d7d4 100644 --- a/include/trace/events/fib6.h +++ b/include/trace/events/fib6.h @@ -34,6 +34,7 @@ TRACE_EVENT(fib6_table_lookup, __field( u8, rt_type ) __array( char, name, IFNAMSIZ ) __array( __u8, gw, 16 ) + __field( u64, net_cookie ) ), TP_fast_assign( @@ -76,13 +77,16 @@ TRACE_EVENT(fib6_table_lookup, in6 = (struct in6_addr *)__entry->gw; *in6 = res->nh->fib_nh_gw6; } + + __entry->net_cookie = net->net_cookie; ), - TP_printk("table %3u oif %d iif %d proto %u %pI6c/%u -> %pI6c/%u flowlabel %#x tos %d scope %d flags %x ==> dev %s gw %pI6c err %d", + TP_printk("table %3u oif %d iif %d proto %u %pI6c/%u -> %pI6c/%u flowlabel %#x tos %d scope %d flags %x ==> dev %s gw %pI6c err %d net_cookie %llu", __entry->tb_id, __entry->oif, __entry->iif, __entry->proto, __entry->src, __entry->sport, __entry->dst, __entry->dport, __entry->flowlabel, __entry->tos, __entry->scope, - __entry->flags, __entry->name, __entry->gw, __entry->err) + __entry->flags, __entry->name, __entry->gw, __entry->err, + __entry->net_cookie) ); #endif /* _TRACE_FIB6_H */ From c436a624f89e56978659a12e01fe8b2fda2b3a6d Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Thu, 8 Oct 2026 16:31:57 +0300 Subject: [PATCH 1471/2126] ipv4: Pass netns to fib_table_lookup() The next patch will report the network namespace cookie in the fib_table_lookup tracepoint. As a preparation, pass the namespace to fib_table_lookup() and from there to the tracepoint, like the fib6_table_lookup tracepoint. All the callers already have the namespace at hand. Add the namespace as the last tracepoint argument so that the positions of the existing arguments do not change and BPF programs that attach to the raw tracepoint are not affected. No functional changes intended. Assisted-by: LLM Reviewed-by: Petr Machata Reviewed-by: Ferenc Fejes Signed-off-by: Ido Schimmel Reviewed-by: David Ahern Link: https://patch.msgid.link/20261008133158.1438907-3-idosch@nvidia.com Signed-off-by: Paolo Abeni --- include/net/ip_fib.h | 12 +++++++----- include/trace/events/fib.h | 5 +++-- net/core/filter.c | 2 +- net/ipv4/devinet.c | 3 ++- net/ipv4/fib_frontend.c | 6 ++++-- net/ipv4/fib_rules.c | 2 +- net/ipv4/fib_semantics.c | 2 +- net/ipv4/fib_trie.c | 14 ++++++++------ 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 0a35355fb0f3..fb446f01a65d 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -275,8 +275,9 @@ struct fib_dump_filter { struct net_device *dev; }; -int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, - struct fib_result *res, int fib_flags); +int fib_table_lookup(struct net *net, struct fib_table *tb, + const struct flowi4 *flp, struct fib_result *res, + int fib_flags); int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, struct netlink_ext_ack *extack); int fib_table_delete(struct net *, struct fib_table *, struct fib_config *, @@ -323,7 +324,8 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp, tb = fib_get_table(net, RT_TABLE_MAIN); if (tb) - err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF); + err = fib_table_lookup(net, tb, flp, res, + flags | FIB_LOOKUP_NOREF); if (err == -EAGAIN) err = -ENETUNREACH; @@ -387,14 +389,14 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp, tb = rcu_dereference_rtnl(net->ipv4.fib_main); if (tb) - err = fib_table_lookup(tb, flp, res, flags); + err = fib_table_lookup(net, tb, flp, res, flags); if (err != -EAGAIN) goto out; tb = rcu_dereference_rtnl(net->ipv4.fib_default); if (tb) - err = fib_table_lookup(tb, flp, res, flags); + err = fib_table_lookup(net, tb, flp, res, flags); if (err == -EAGAIN) err = -ENETUNREACH; diff --git a/include/trace/events/fib.h b/include/trace/events/fib.h index feb28b359eff..341905b5edf3 100644 --- a/include/trace/events/fib.h +++ b/include/trace/events/fib.h @@ -15,9 +15,10 @@ TRACE_EVENT(fib_table_lookup, TP_PROTO(u32 tb_id, const struct flowi4 *flp, - const struct fib_nh_common *nhc, int err), + const struct fib_nh_common *nhc, int err, + const struct net *net), - TP_ARGS(tb_id, flp, nhc, err), + TP_ARGS(tb_id, flp, nhc, err, net), TP_STRUCT__entry( __field( u32, tb_id ) diff --git a/net/core/filter.c b/net/core/filter.c index 70dc621672f2..3ee1a093337e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6413,7 +6413,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params, if (unlikely(!tb)) return BPF_FIB_LKUP_RET_NOT_FWDED; - err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF); + err = fib_table_lookup(net, tb, &fl4, &res, FIB_LOOKUP_NOREF); } else { if (flags & BPF_FIB_LOOKUP_MARK) fl4.flowi4_mark = params->mark; diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 2ed4c706ca9e..c106d56eb2f7 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -157,7 +157,8 @@ struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref) */ local = fib_get_table(net, RT_TABLE_LOCAL); if (local && - !fib_table_lookup(local, &fl4, &res, FIB_LOOKUP_NOREF) && + !fib_table_lookup(net, local, &fl4, &res, + FIB_LOOKUP_NOREF) && res.type == RTN_LOCAL) result = FIB_RES_DEV(res); } else { diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 8a3dc04e8cac..c80c1b36f1fd 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -243,7 +243,8 @@ static inline unsigned int __inet_dev_addr_type(struct net *net, table = fib_get_table(net, tb_id); if (table) { ret = RTN_UNICAST; - if (!fib_table_lookup(table, &fl4, &res, FIB_LOOKUP_NOREF)) { + if (!fib_table_lookup(net, table, &fl4, &res, + FIB_LOOKUP_NOREF)) { struct fib_nh_common *nhc = fib_info_nhc(res.fi, 0); if (!dev || dev == nhc->nhc_dev) @@ -1400,7 +1401,8 @@ static void nl_fib_lookup(struct net *net, struct fib_result_nl *frn) local_bh_disable(); frn->tb_id = tb->tb_id; - frn->err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF); + frn->err = fib_table_lookup(net, tb, &fl4, &res, + FIB_LOOKUP_NOREF); if (!frn->err) { frn->prefixlen = res.prefixlen; diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index 060501b376a8..28ba35125383 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c @@ -136,7 +136,7 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_action(struct fib_rule *rule, tb_id = fib_rule_get_table(rule, arg); tbl = fib_get_table(rule->fr_net, tb_id); if (tbl) - err = fib_table_lookup(tbl, &flp->u.ip4, + err = fib_table_lookup(rule->fr_net, tbl, &flp->u.ip4, (struct fib_result *)arg->result, arg->flags); diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index db030bc26b6d..20da68240f61 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1224,7 +1224,7 @@ static int fib_check_nh_v4_gw(struct net *net, struct fib_nh *nh, u32 table, tbl = fib_get_table(net, table); if (tbl) - err = fib_table_lookup(tbl, &fl4, &res, + err = fib_table_lookup(net, tbl, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE | FIB_LOOKUP_NOREF); diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 248514dce0cd..4a800fdf1ad1 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -1415,8 +1415,9 @@ bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags, } /* should be called with rcu_read_lock */ -int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, - struct fib_result *res, int fib_flags) +int fib_table_lookup(struct net *net, struct fib_table *tb, + const struct flowi4 *flp, struct fib_result *res, + int fib_flags) { struct trie *t = (struct trie *) tb->tb_data; #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -1433,7 +1434,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, n = get_child_rcu(pn, cindex); if (!n) { - trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN); + trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, net); return -EAGAIN; } @@ -1520,7 +1521,8 @@ backtrace: */ if (IS_TRIE(pn)) { trace_fib_table_lookup(tb->tb_id, flp, - NULL, -EAGAIN); + NULL, -EAGAIN, + net); return -EAGAIN; } #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -1567,7 +1569,7 @@ out_reject: #ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc(stats->semantic_match_passed); #endif - trace_fib_table_lookup(tb->tb_id, flp, NULL, err); + trace_fib_table_lookup(tb->tb_id, flp, NULL, err, net); return err; } if (fi->fib_flags & RTNH_F_DEAD) @@ -1608,7 +1610,7 @@ set_result: #ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc(stats->semantic_match_passed); #endif - trace_fib_table_lookup(tb->tb_id, flp, nhc, err); + trace_fib_table_lookup(tb->tb_id, flp, nhc, err, net); return err; } From a780f51d5bc81616abdc3529748b12f39c497192 Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Thu, 8 Oct 2026 16:31:58 +0300 Subject: [PATCH 1472/2126] ipv4: Report netns cookie in fib_table_lookup tracepoint The fib_table_lookup tracepoint does not report the network namespace in which the lookup was performed, making it impossible to tell apart lookups performed in different namespaces. Report the network namespace cookie now that the namespace is passed to the tracepoint. Assisted-by: LLM Reviewed-by: Petr Machata Reviewed-by: Ferenc Fejes Signed-off-by: Ido Schimmel Reviewed-by: David Ahern Link: https://patch.msgid.link/20261008133158.1438907-4-idosch@nvidia.com Signed-off-by: Paolo Abeni --- include/trace/events/fib.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/trace/events/fib.h b/include/trace/events/fib.h index 341905b5edf3..e0ee14d6ca45 100644 --- a/include/trace/events/fib.h +++ b/include/trace/events/fib.h @@ -36,6 +36,7 @@ TRACE_EVENT(fib_table_lookup, __field( u16, sport ) __field( u16, dport ) __array(char, name, IFNAMSIZ ) + __field( u64, net_cookie ) ), TP_fast_assign( @@ -91,13 +92,16 @@ TRACE_EVENT(fib_table_lookup, in6 = (struct in6_addr *)__entry->gw6; *in6 = in6addr_any; } + + __entry->net_cookie = net->net_cookie; ), - TP_printk("table %u oif %d iif %d proto %u %pI4/%u -> %pI4/%u tos %d scope %d flags %x ==> dev %s gw %pI4/%pI6c err %d", + TP_printk("table %u oif %d iif %d proto %u %pI4/%u -> %pI4/%u tos %d scope %d flags %x ==> dev %s gw %pI4/%pI6c err %d net_cookie %llu", __entry->tb_id, __entry->oif, __entry->iif, __entry->proto, __entry->src, __entry->sport, __entry->dst, __entry->dport, __entry->tos, __entry->scope, __entry->flags, - __entry->name, __entry->gw4, __entry->gw6, __entry->err) + __entry->name, __entry->gw4, __entry->gw6, __entry->err, + __entry->net_cookie) ); #endif /* _TRACE_FIB_H */ From 0063f777b58db3fa455089566f200ae019614945 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 7 Oct 2026 10:36:28 -0700 Subject: [PATCH 1473/2126] net: ag71xx: Use default NAPI weight Drop the custom NAPI weight and let netif_napi_add() use the core default. The old comment claimed larger weights wasted cycles and cache, but recent RX and TX path changes altered those tradeoffs. Keep the driver on the standard default unless measurements show a device-specific value is needed. iperf3: Before: [ ID][Role] Interval Transfer Bitrate Retr [ 5][TX-C] 0.00-10.00 sec 327 MBytes 274 Mbits/sec 31 sender [ 5][TX-C] 0.00-10.00 sec 325 MBytes 273 Mbits/sec receiver [ 7][RX-C] 0.00-10.00 sec 170 MBytes 143 Mbits/sec 0 sender [ 7][RX-C] 0.00-10.00 sec 170 MBytes 143 Mbits/sec receiver After: [ ID][Role] Interval Transfer Bitrate Retr [ 5][TX-C] 0.00-10.00 sec 341 MBytes 286 Mbits/sec 30 sender [ 5][TX-C] 0.00-10.00 sec 338 MBytes 284 Mbits/sec receiver [ 7][RX-C] 0.00-10.00 sec 184 MBytes 154 Mbits/sec 0 sender [ 7][RX-C] 0.00-10.00 sec 184 MBytes 154 Mbits/sec receiver Assisted-by: LLM Signed-off-by: Rosen Penev Reviewed-by: Andrew Lunn Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261007173628.657527-1-rosenp@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/atheros/ag71xx.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c index 4e4794c4dfdc..8a3c689f6825 100644 --- a/drivers/net/ethernet/atheros/ag71xx.c +++ b/drivers/net/ethernet/atheros/ag71xx.c @@ -40,11 +40,6 @@ #include #include -/* For our NAPI weight bigger does *NOT* mean better - it means more - * D-cache misses and lots more wasted cycles than we'll ever - * possibly gain from saving instructions. - */ -#define AG71XX_NAPI_WEIGHT 32 #define AG71XX_OOM_REFILL (1 + HZ / 10) #define AG71XX_INT_ERR (AG71XX_INT_RX_BE | AG71XX_INT_TX_BE) @@ -1913,8 +1908,7 @@ static int ag71xx_probe(struct platform_device *pdev) return err; } - netif_napi_add_weight(ndev, &ag->napi, ag71xx_poll, - AG71XX_NAPI_WEIGHT); + netif_napi_add(ndev, &ag->napi, ag71xx_poll); ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, 0); From 32a8010d2c30c7aa3bd732048c3b366dd3d48c6e Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 7 Oct 2026 23:23:34 +0530 Subject: [PATCH 1474/2126] sfc: fix stale kernel-doc member names in net_driver.h Several kernel-doc comments in net_driver.h describe struct members that have since been renamed or removed, and the EFX_MAX_FRAME_LEN() comment is separated from the macro by the EFX_FRAME_PAD define. kernel-doc reports: Excess struct member 'state' description in 'efx_channel' Excess struct member 'state_lock' description in 'efx_channel' Excess struct member 'indir_table' description in 'efx_rss_context' Excess struct member 'irq_rx_mod_step_us' description in 'efx_nic' Excess struct member 'tx_queue' description in 'efx_nic' Excess struct member 'rx_queue' description in 'efx_nic' Excess struct member 'extra_channel_types' description in 'efx_nic' expecting prototype for EFX_MAX_FRAME_LEN(). Prototype was for EFX_FRAME_PAD() instead along with "not described" warnings for the renamed members. Fix the member names to match the structs, drop the entries for members that no longer exist, and move the EFX_FRAME_PAD define above the EFX_MAX_FRAME_LEN() comment, documenting its @mtu parameter. kernel-doc -Wall also reports three members that are not described because nothing in the driver uses them any more, so remove them rather than document them: - efx_channel::busy_poll_state, left behind when commit e7fe9491261e ("sfc: get rid of custom busy polling code") removed its users. @state and @state_lock above were its old kernel-doc entries. - efx_tx_queue::flush_outstanding, only used by the Falcon/Siena flush code, which commit 36ff6393292d ("sfc: Move Siena specific files") moved into siena/ with its own copy of the struct. - efx_rx_queue::min_overfill, whose kernel-doc entry and only assignment were removed by commit ecc910f520ba ("sfc: Make the dmaq size a run-time setting (rather than compile-time)"). The warnings were found with scripts/kernel-doc -Wall. I don't have sfc hardware; this is compile-tested only. No functional change. Assisted-by: LLM Signed-off-by: Arnav Kapoor Reviewed-by: Alex Austin Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261007175338.28683-1-kapoorarnav43@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/sfc/net_driver.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 3964b2c56609..71144bb4c6c8 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -314,7 +314,6 @@ struct efx_tx_queue { /* Members shared between paths and sometimes updated */ unsigned int empty_read_count ____cacheline_aligned_in_smp; #define EFX_EMPTY_COUNT_VALID 0x80000000 - atomic_t flush_outstanding; }; #define EFX_TX_CB_ORDER 7 @@ -431,7 +430,6 @@ struct efx_rx_queue { unsigned int max_fill; unsigned int fast_fill_trigger; unsigned int min_fill; - unsigned int min_overfill; unsigned int recycle_count; struct timer_list slow_fill; unsigned int slow_fill_count; @@ -467,8 +465,6 @@ enum efx_sync_events_state { * @irq_moderation_us: IRQ moderation value (in microseconds) * @napi_dev: Net device used with NAPI * @napi_str: NAPI control structure - * @state: state for NAPI vs busy polling - * @state_lock: lock protecting @state * @eventq: Event queue buffer * @eventq_mask: Event queue pointer mask * @eventq_read_ptr: Event queue read pointer @@ -526,9 +522,6 @@ struct efx_channel { unsigned int irq_moderation_us; struct net_device *napi_dev; struct napi_struct napi_str; -#ifdef CONFIG_NET_RX_BUSY_POLL - unsigned long busy_poll_state; -#endif struct efx_buffer eventq; unsigned int eventq_mask; unsigned int eventq_read_ptr; @@ -788,7 +781,7 @@ struct efx_rss_context_priv { * struct efx_rss_context - an RSS context * @priv: hardware-specific state * @rx_hash_key: Toeplitz hash key for this RSS context - * @indir_table: Indirection table for this RSS context + * @rx_indir_table: Indirection table for this RSS context */ struct efx_rss_context { struct efx_rss_context_priv priv; @@ -881,16 +874,14 @@ struct efx_mae; * @timer_max_ns: Interrupt timer maximum value, in nanoseconds * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues * @irqs_hooked: Channel interrupts are hooked - * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues + * @irq_mod_step_us: Step size for IRQ moderation for RX event queues * @irq_rx_moderation_us: IRQ moderation time for RX event queues * @msg_enable: Log message enable flags * @state: Device state number (%STATE_*). Serialised by the rtnl_lock. * @reset_pending: Bitmask for pending resets - * @tx_queue: TX DMA queues - * @rx_queue: RX DMA queues * @channel: Channels * @msi_context: Context for each MSI - * @extra_channel_types: Types of extra (non-traffic) channels that + * @extra_channel_type: Types of extra (non-traffic) channels that * should be allocated for this NIC * @mae: Details of the Match Action Engine * @xdp_tx_queue_count: Number of entries in %xdp_tx_queues. @@ -1711,8 +1702,11 @@ efx_rx_buf_next(struct efx_rx_queue *rx_queue, struct efx_rx_buffer *rx_buf) return rx_buf + 1; } +#define EFX_FRAME_PAD 16 + /** * EFX_MAX_FRAME_LEN - calculate maximum frame length + * @mtu: MTU to calculate the maximum frame length for * * This calculates the maximum frame length that will be used for a * given MTU. The frame length will be equal to the MTU plus a @@ -1726,9 +1720,8 @@ efx_rx_buf_next(struct efx_rx_queue *rx_queue, struct efx_rx_buffer *rx_buf) * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an * XGMII cycle). If the frame length reaches the maximum value in the * same cycle, the XMAC can miss the IPG altogether. We work around - * this by adding a further 16 bytes. + * this by adding a further 16 bytes (EFX_FRAME_PAD). */ -#define EFX_FRAME_PAD 16 #define EFX_MAX_FRAME_LEN(mtu) \ (ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EFX_FRAME_PAD), 8)) From 26a8396802ea06c27c014f6d40eaa5ac4ef99a7a Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 8 Oct 2026 11:30:13 -0700 Subject: [PATCH 1475/2126] net: natsemi: xtsonic: make probe function static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid a build warning by making the probe function static: drivers/net/ethernet/natsemi/xtsonic.c:200:5: warning: no previous prototype for 'xtsonic_probe' [-Wmissing-prototypes] 200 | int xtsonic_probe(struct platform_device *pdev) Signed-off-by: Randy Dunlap Reviewed-by: Björn Töpel Link: https://patch.msgid.link/20261008183013.3223131-1-rdunlap@infradead.org Signed-off-by: Paolo Abeni --- drivers/net/ethernet/natsemi/xtsonic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/natsemi/xtsonic.c b/drivers/net/ethernet/natsemi/xtsonic.c index c01a4cb5dc0f..ca229c688a71 100644 --- a/drivers/net/ethernet/natsemi/xtsonic.c +++ b/drivers/net/ethernet/natsemi/xtsonic.c @@ -197,7 +197,7 @@ out: * Actually probing is superfluous but we're paranoid. */ -int xtsonic_probe(struct platform_device *pdev) +static int xtsonic_probe(struct platform_device *pdev) { struct net_device *dev; struct sonic_local *lp; From d7804253678eb18d2be950e0542364b50be096a9 Mon Sep 17 00:00:00 2001 From: James Clark Date: Thu, 8 Oct 2026 17:38:09 +0700 Subject: [PATCH 1476/2126] net: stmmac: ptp: switch to gettimex64() interface The stmmac PTP support currently implements the gettime64 callback to retrieve the hardware clock time. Update the implementation to provide the gettimex64 callback instead, adding support for the PTP_SYS_OFFSET_EXTENDED ioctl. The system clock readings are taken around the read of the nanoseconds register in get_systime(), so get_systime() gains a ptp_system_timestamp argument. Reviewed-by: Nicolai Buchwitz Assisted-by: LLM Signed-off-by: James Clark Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20261008103809.1848255-1-jjc@jclark.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/hwif.h | 5 ++++- .../ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 7 +++++-- .../net/ethernet/stmicro/stmmac/stmmac_ptp.c | 21 ++++++++++--------- .../stmicro/stmmac/stmmac_selftests.c | 4 ++-- .../net/ethernet/stmicro/stmmac/stmmac_tc.c | 3 ++- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 2e63614d93a4..50b590d67d87 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -493,6 +493,8 @@ struct stmmac_ops { #define stmmac_fpe_map_preemption_class(__priv, __args...) \ stmmac_do_callback(__priv, mac, fpe_map_preemption_class, __args) +struct ptp_system_timestamp; + /* PTP and HW Timer helpers */ struct stmmac_hwtimestamp { void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data); @@ -502,7 +504,8 @@ struct stmmac_hwtimestamp { int (*config_addend) (void __iomem *ioaddr, u32 addend); int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec, int add_sub, int gmac4); - void (*get_systime) (void __iomem *ioaddr, u64 *systime); + void (*get_systime)(void __iomem *ioaddr, u64 *systime, + struct ptp_system_timestamp *sts); void (*get_ptptime)(void __iomem *ioaddr, u64 *ptp_time); void (*timestamp_interrupt)(struct stmmac_priv *priv); void (*hwtstamp_correct_latency)(struct stmmac_priv *priv); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c index b9a985fa772c..870c740b4a50 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c @@ -183,7 +183,8 @@ static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec, 10, 100000); } -static void get_systime(void __iomem *ioaddr, u64 *systime) +static void get_systime(void __iomem *ioaddr, u64 *systime, + struct ptp_system_timestamp *sts) { u64 ns, sec0, sec1; @@ -191,8 +192,10 @@ static void get_systime(void __iomem *ioaddr, u64 *systime) sec1 = readl_relaxed(ioaddr + PTP_STSR); do { sec0 = sec1; + ptp_read_system_prets(sts); /* Get the TSSS value */ - ns = readl_relaxed(ioaddr + PTP_STNSR); + ns = readl(ioaddr + PTP_STNSR); + ptp_read_system_postts(sts); /* Get the TSS value */ sec1 = readl_relaxed(ioaddr + PTP_STSR); } while (sec0 != sec1); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 3bfcc9760dce..e54a3c887826 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -89,7 +89,8 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta) u64 cycle_time; mutex_lock(&priv->est_lock); - priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, ¤t_time); + priv->ptp_clock_ops.gettimex64(&priv->ptp_clock_ops, + ¤t_time, NULL); current_time_ns = timespec64_to_ktime(current_time); time.tv_nsec = priv->est->btr_reserve[0]; time.tv_sec = priv->est->btr_reserve[1]; @@ -114,15 +115,15 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta) } /** - * stmmac_get_time - * + * stmmac_get_timex - read the PTP clock, with system timestamps if requested * @ptp: pointer to ptp_clock_info structure * @ts: pointer to hold time/result + * @sts: pointer to hold system timestamps around the read, or NULL * - * Description: this function will read the current time from the - * hardware clock and store it in @ts. + * Return: 0 */ -static int stmmac_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts) +static int stmmac_get_timex(struct ptp_clock_info *ptp, struct timespec64 *ts, + struct ptp_system_timestamp *sts) { struct stmmac_priv *priv = container_of(ptp, struct stmmac_priv, ptp_clock_ops); @@ -130,7 +131,7 @@ static int stmmac_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts) u64 ns = 0; read_lock_irqsave(&priv->ptp_lock, flags); - stmmac_get_systime(priv, priv->ptpaddr, &ns); + stmmac_get_systime(priv, priv->ptpaddr, &ns, sts); read_unlock_irqrestore(&priv->ptp_lock, flags); *ts = ns_to_timespec64(ns); @@ -200,7 +201,7 @@ static int stmmac_enable(struct ptp_clock_info *ptp, target_ns = cfg->start.tv_nsec + ((u64)cfg->start.tv_sec * NSEC_PER_SEC); - stmmac_get_systime(priv, priv->ptpaddr, &ns); + stmmac_get_systime(priv, priv->ptpaddr, &ns, NULL); if (ns > TIME64_MAX - PTP_SAFE_TIME_OFFSET_NS) return -EINVAL; @@ -304,7 +305,7 @@ const struct ptp_clock_info stmmac_ptp_clock_ops = { .pps = 0, .adjfine = stmmac_adjust_freq, .adjtime = stmmac_adjust_time, - .gettime64 = stmmac_get_time, + .gettimex64 = stmmac_get_timex, .settime64 = stmmac_set_time, .enable = stmmac_enable, }; @@ -321,7 +322,7 @@ const struct ptp_clock_info dwmac1000_ptp_clock_ops = { .pps = 0, .adjfine = stmmac_adjust_freq, .adjtime = stmmac_adjust_time, - .gettime64 = stmmac_get_time, + .gettimex64 = stmmac_get_timex, .settime64 = stmmac_set_time, .enable = dwmac1000_ptp_enable, }; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 369c8f4170f8..38cc8fbf2d65 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -1778,7 +1778,7 @@ static int stmmac_test_tbs(struct stmmac_priv *priv) return ret; read_lock_irqsave(&priv->ptp_lock, flags); - stmmac_get_systime(priv, priv->ptpaddr, &curr_time); + stmmac_get_systime(priv, priv->ptpaddr, &curr_time, NULL); read_unlock_irqrestore(&priv->ptp_lock, flags); if (!curr_time) { @@ -1800,7 +1800,7 @@ static int stmmac_test_tbs(struct stmmac_priv *priv) /* Check if expected time has elapsed */ read_lock_irqsave(&priv->ptp_lock, flags); - stmmac_get_systime(priv, priv->ptpaddr, &curr_time); + stmmac_get_systime(priv, priv->ptpaddr, &curr_time, NULL); read_unlock_irqrestore(&priv->ptp_lock, flags); if ((curr_time - start_time) < STMMAC_TBS_LT_OFFSET) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index ea1f97d6f0bd..b09e9a89cee8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -1073,7 +1073,8 @@ static int tc_taprio_configure(struct stmmac_priv *priv, mutex_lock(&priv->est_lock); /* Adjust for real system time */ - priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, ¤t_time); + priv->ptp_clock_ops.gettimex64(&priv->ptp_clock_ops, ¤t_time, + NULL); current_time_ns = timespec64_to_ktime(current_time); time = stmmac_calc_tas_basetime(qopt->base_time, current_time_ns, qopt->cycle_time); From 63892371b205a6da6dd9637e45480d812048b9c0 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:00 +0200 Subject: [PATCH 1477/2126] wifi: nl80211: add NL80211_CMD_UPDATE_BEACON Updating beacon and related templates with NL80211_CMD_SET_BEACON requires the wiphy mutex, which can get contended, delaying the updates. Add a NL80211_CMD_UPDATE_BEACON operation that can only do beacon template updates, not other configuration changes, but is called without the wiphy mutex. If something requires the mutex then the driver can return -EAGAIN, to go through the normal change_beacon with wiphy mutex held. Also with this support updating multiple beacons for an MLD at the same time, just to further reduce round-trips if desired. Link: https://patch.msgid.link/20261009201417.fc5c148060cd.I174b47b65aca1bbaaf6a74d64fa0e264f84028b4@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 5 + include/uapi/linux/nl80211.h | 16 ++ net/wireless/nl80211.c | 312 +++++++++++++++++++++++++++++------ net/wireless/rdev-ops.h | 11 ++ net/wireless/trace.h | 14 +- 5 files changed, 307 insertions(+), 51 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 45a96c92fec3..7de6dbdae930 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4949,6 +4949,9 @@ struct mgmt_frame_regs { * @start_ap: Start acting in AP mode defined by the parameters. * @change_beacon: Change the beacon parameters for an access point mode * interface. This should reject the call when AP mode wasn't started. + * @update_beacon: Update the beacon and other templates like @change_beacon, + * but called without the wiphy mutex held. May return -EAGAIN to have + * it fall back to @change_beacon with the wiphy mutex held. * @stop_ap: Stop being an AP, including stopping beaconing. * * @add_station: Add a new station. @@ -5364,6 +5367,8 @@ struct cfg80211_ops { struct cfg80211_ap_settings *settings); int (*change_beacon)(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_ap_update *info); + int (*update_beacon)(struct wiphy *wiphy, struct net_device *dev, + struct cfg80211_ap_update *info); int (*stop_ap)(struct wiphy *wiphy, struct net_device *dev, unsigned int link_id); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 341f8395d1af..b56a96f57bec 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1458,6 +1458,16 @@ * keep their non-evacuable marking, removed channels lose it, and newly * added channels are evacuable by default; issue this command again to * change the non-evacuable set. + * @NL80211_CMD_UPDATE_BEACON: Update the beacon and other templates of an AP + * interface, but only that. Same attributes as %NL80211_CMD_SET_BEACON, + * %NL80211_ATTR_BEACON_HEAD and %NL80211_ATTR_BEACON_TAIL are required, + * configuration changes such as %NL80211_ATTR_FTM_RESPONDER rejected. + * This doesn't acquire the wiphy mutex internally, so it's faster, but + * cannot update any other configuration. + * For MLO a single link is set with %NL80211_ATTR_MLO_LINK_ID as usual + * and multiple can be nested in %NL80211_ATTR_MLO_LINKS but then the + * update isn't atomic if any failures happen. + * Only supported with %NL80211_EXT_FEATURE_UPDATE_BEACON. * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */ @@ -1738,6 +1748,8 @@ enum nl80211_commands { NL80211_CMD_NAN_SET_NON_EVAC_CHANNELS, + NL80211_CMD_UPDATE_BEACON, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ @@ -7178,6 +7190,9 @@ enum nl80211_feature_flags { * offload in station mode, including Fast Transition or Opportunistic * Key Caching. * + * @NL80211_EXT_FEATURE_UPDATE_BEACON: Driver supports + * %NL80211_CMD_UPDATE_BEACON. + * * @NUM_NL80211_EXT_FEATURES: number of extended features. * @MAX_NL80211_EXT_FEATURES: highest extended feature index. */ @@ -7261,6 +7276,7 @@ enum nl80211_ext_feature_index { NL80211_EXT_FEATURE_SET_KEY_LTF_SEED, NL80211_EXT_FEATURE_PROBE_AP, NL80211_EXT_FEATURE_FAST_ROAM_OFFLOAD, + NL80211_EXT_FEATURE_UPDATE_BEACON, /* add new features before the definition below */ NUM_NL80211_EXT_FEATURES, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index a48bd4e4f4c7..6387a312b35e 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -7578,15 +7578,87 @@ out: return err; } +static int nl80211_parse_ap_update(struct cfg80211_registered_device *rdev, + struct nlattr *attrs[], + struct ieee80211_channel *chan, + struct cfg80211_ap_update *params, + struct netlink_ext_ack *extack) +{ + struct nlattr *attr; + int err; + + err = nl80211_parse_beacon(rdev, attrs, ¶ms->beacon, chan, extack); + if (err) + return err; + + attr = attrs[NL80211_ATTR_FILS_DISCOVERY]; + if (attr) { + err = nl80211_parse_fils_discovery(rdev, attr, + ¶ms->fils_discovery); + if (err) + return err; + } + + attr = attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]; + if (attr) { + err = nl80211_parse_unsol_bcast_probe_resp(rdev, attr, + ¶ms->unsol_bcast_probe_resp); + if (err) + return err; + } + + attr = attrs[NL80211_ATTR_S1G_SHORT_BEACON]; + if (attr) { + err = nl80211_parse_s1g_short_beacon(rdev, attr, + ¶ms->s1g_short_beacon); + if (err) + return err; + } + + return 0; +} + +static int nl80211_change_beacon(struct cfg80211_registered_device *rdev, + struct net_device *dev, + struct cfg80211_ap_update *params) +{ + struct cfg80211_beaconing_check_config beacon_check = {}; + struct wireless_dev *wdev = dev->ieee80211_ptr; + unsigned int link_id = params->beacon.link_id; + int err; + + /* recheck beaconing is permitted with possibly changed power type */ + beacon_check.iftype = wdev->iftype; + beacon_check.relax = true; + beacon_check.reg_power = + cfg80211_get_6ghz_power_type(params->beacon.tail, + params->beacon.tail_len, 0); + if (!cfg80211_reg_check_beaconing(&rdev->wiphy, + &wdev->links[link_id].ap.chandef, + &beacon_check)) + return -EINVAL; + + err = rdev_change_beacon(rdev, dev, params); + if (!err) + wdev->links[link_id].ap.reg_power = beacon_check.reg_power; + + return err; +} + +static void nl80211_free_ap_update(struct cfg80211_ap_update *params) +{ + kfree(params->beacon.mbssid_ies); + kfree(params->beacon.rnr_ies); + kfree(params); +} + static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; - struct cfg80211_beaconing_check_config beacon_check = {}; unsigned int link_id = nl80211_link_id(info->attrs); struct net_device *dev = info->user_ptr[1]; struct wireless_dev *wdev = dev->ieee80211_ptr; struct cfg80211_ap_update *params; - struct nlattr *attr; int err; if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && @@ -7603,57 +7675,190 @@ static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) if (!params) return -ENOMEM; - err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon, - wdev->links[link_id].ap.chandef.chan, - info->extack); - if (err) - goto out; - - /* recheck beaconing is permitted with possibly changed power type */ - beacon_check.iftype = wdev->iftype; - beacon_check.relax = true; - beacon_check.reg_power = - cfg80211_get_6ghz_power_type(params->beacon.tail, - params->beacon.tail_len, 0); - if (!cfg80211_reg_check_beaconing(&rdev->wiphy, - &wdev->links[link_id].ap.chandef, - &beacon_check)) { - err = -EINVAL; - goto out; - } - - attr = info->attrs[NL80211_ATTR_FILS_DISCOVERY]; - if (attr) { - err = nl80211_parse_fils_discovery(rdev, attr, - ¶ms->fils_discovery); - if (err) - goto out; - } - - attr = info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]; - if (attr) { - err = nl80211_parse_unsol_bcast_probe_resp(rdev, attr, - ¶ms->unsol_bcast_probe_resp); - if (err) - goto out; - } - - attr = info->attrs[NL80211_ATTR_S1G_SHORT_BEACON]; - if (attr) { - err = nl80211_parse_s1g_short_beacon(rdev, attr, - ¶ms->s1g_short_beacon); - if (err) - goto out; - } - - err = rdev_change_beacon(rdev, dev, params); + err = nl80211_parse_ap_update(rdev, info->attrs, + wdev->links[link_id].ap.chandef.chan, + params, info->extack); if (!err) - wdev->links[link_id].ap.reg_power = beacon_check.reg_power; + err = nl80211_change_beacon(rdev, dev, params); + nl80211_free_ap_update(params); + return err; +} + +static struct cfg80211_ap_update * +nl80211_parse_link_update(struct cfg80211_registered_device *rdev, + struct net_device *dev, struct nlattr *attrs[], + struct netlink_ext_ack *extack) +{ + struct nlattr *link_attr = attrs[NL80211_ATTR_MLO_LINK_ID]; + struct wireless_dev *wdev = dev->ieee80211_ptr; + unsigned int link_id = nl80211_link_id(attrs); + u16 valid_links = READ_ONCE(wdev->valid_links); + struct cfg80211_ap_update *params; + struct ieee80211_channel *chan; + int err; + + /* without locks this is racy, the driver needs to check again */ + if (valid_links ? !link_attr || !(valid_links & BIT(link_id)) : + !!link_attr) + return ERR_PTR(-EINVAL); + + if (attrs[NL80211_ATTR_FTM_RESPONDER] || + attrs[NL80211_ATTR_HE_BSS_COLOR] || + attrs[NL80211_ATTR_S1G_SHORT_BEACON]) { + NL_SET_ERR_MSG(extack, "cannot change configuration in update"); + return ERR_PTR(-EINVAL); + } + + if (!attrs[NL80211_ATTR_BEACON_HEAD] || + !attrs[NL80211_ATTR_BEACON_TAIL]) { + NL_SET_ERR_MSG(extack, "beacon head and tail are required"); + return ERR_PTR(-EINVAL); + } + + chan = READ_ONCE(wdev->links[link_id].ap.chandef.chan); + if (!chan || !READ_ONCE(wdev->links[link_id].ap.beacon_interval)) + return ERR_PTR(-EINVAL); + + params = kzalloc_obj(*params); + if (!params) + return ERR_PTR(-ENOMEM); + + err = nl80211_parse_ap_update(rdev, attrs, chan, params, extack); + if (err) { + nl80211_free_ap_update(params); + return ERR_PTR(err); + } + + return params; +} + +static int nl80211_update_link_beacon(struct cfg80211_registered_device *rdev, + struct net_device *dev, + struct cfg80211_ap_update *params) +{ + struct wireless_dev *wdev = dev->ieee80211_ptr; + unsigned int link_id = params->beacon.link_id; + + /* a power type change needs regulatory checks under the wiphy mutex */ + if (cfg80211_get_6ghz_power_type(params->beacon.tail, + params->beacon.tail_len, 0) != + READ_ONCE(wdev->links[link_id].ap.reg_power)) + return -EAGAIN; + + return rdev_update_beacon(rdev, dev, params); +} + +static int +nl80211_update_link_beacon_locked(struct cfg80211_registered_device *rdev, + struct net_device *dev, + struct cfg80211_ap_update *params) +{ + struct wireless_dev *wdev = dev->ieee80211_ptr; + unsigned int link_id = params->beacon.link_id; + + lockdep_assert_wiphy(&rdev->wiphy); + + if (!rdev->wiphy.registered || !wdev_running(wdev)) + return -ENETDOWN; + + if (wdev->valid_links ? !(wdev->valid_links & BIT(link_id)) : link_id) + return -ENOLINK; + + if (!wdev->links[link_id].ap.beacon_interval) + return -EINVAL; + + return nl80211_change_beacon(rdev, dev, params); +} + +static int nl80211_update_beacon(struct sk_buff *skb, struct genl_info *info) +{ + struct cfg80211_ap_update *params[IEEE80211_MLD_MAX_NUM_LINKS] = {}; + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct net_device *dev = info->user_ptr[1]; + unsigned long need_lock = 0; + unsigned int n = 0, i; + struct nlattr *link; + u16 links = 0; + int rem, err = 0; + + if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && + dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) + return -EOPNOTSUPP; + + if (!rdev->ops->update_beacon || !rdev->ops->change_beacon || + !wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_UPDATE_BEACON)) + return -EOPNOTSUPP; + + if (!info->attrs[NL80211_ATTR_MLO_LINKS]) { + params[0] = nl80211_parse_link_update(rdev, dev, info->attrs, + info->extack); + if (IS_ERR(params[0])) + return PTR_ERR(params[0]); + n = 1; + } else { + struct nlattr **attrs = kzalloc_objs(*attrs, NUM_NL80211_ATTR); + + if (!attrs) + return -ENOMEM; + + nla_for_each_nested(link, info->attrs[NL80211_ATTR_MLO_LINKS], + rem) { + struct cfg80211_ap_update *p; + + err = nla_parse_nested(attrs, NL80211_ATTR_MAX, link, + NULL, info->extack); + if (err) + break; + + p = nl80211_parse_link_update(rdev, dev, attrs, + info->extack); + if (IS_ERR(p)) { + err = PTR_ERR(p); + break; + } + + /* also ensures we don't overflow params[] */ + if (links & BIT(p->beacon.link_id)) { + nl80211_free_ap_update(p); + err = -EINVAL; + break; + } + links |= BIT(p->beacon.link_id); + params[n++] = p; + } + + kfree(attrs); + if (!err && !n) + err = -EINVAL; + if (err) + goto out; + } + + /* try updates without wiphy mutex first */ + for (i = 0; i < n; i++) { + err = nl80211_update_link_beacon(rdev, dev, params[i]); + if (err == -EAGAIN) + __set_bit(i, &need_lock); + else if (err) + goto out; + } + + err = 0; + if (need_lock) { + wiphy_lock(&rdev->wiphy); + for_each_set_bit(i, &need_lock, n) { + err = nl80211_update_link_beacon_locked(rdev, dev, + params[i]); + if (err) + break; + } + wiphy_unlock(&rdev->wiphy); + } out: - kfree(params->beacon.mbssid_ies); - kfree(params->beacon.rnr_ies); - kfree(params); + for (i = 0; i < n; i++) + nl80211_free_ap_update(params[i]); return err; } @@ -20927,6 +21132,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .flags = GENL_ADMIN_PERM, .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), }, + { + .cmd = NL80211_CMD_UPDATE_BEACON, + .doit = nl80211_update_beacon, + .flags = GENL_UNS_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | + NL80211_FLAG_NO_WIPHY_MTX), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 1f1311c20e94..95882c8972d2 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -183,6 +183,17 @@ static inline int rdev_change_beacon(struct cfg80211_registered_device *rdev, return ret; } +static inline int rdev_update_beacon(struct cfg80211_registered_device *rdev, + struct net_device *dev, + struct cfg80211_ap_update *info) +{ + int ret; + trace_rdev_update_beacon(&rdev->wiphy, dev, info); + ret = rdev->ops->update_beacon(&rdev->wiphy, dev, info); + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline int rdev_stop_ap(struct cfg80211_registered_device *rdev, struct net_device *dev, unsigned int link_id) { diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 83007a824010..f5fa2fb76474 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -740,7 +740,7 @@ TRACE_EVENT(rdev_start_ap, __entry->inactivity_timeout, __entry->link_id) ); -TRACE_EVENT(rdev_change_beacon, +DECLARE_EVENT_CLASS(rdev_ap_update, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_ap_update *info), TP_ARGS(wiphy, netdev, info), @@ -788,6 +788,18 @@ TRACE_EVENT(rdev_change_beacon, WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->link_id) ); +DEFINE_EVENT(rdev_ap_update, rdev_change_beacon, + TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, + struct cfg80211_ap_update *info), + TP_ARGS(wiphy, netdev, info) +); + +DEFINE_EVENT(rdev_ap_update, rdev_update_beacon, + TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, + struct cfg80211_ap_update *info), + TP_ARGS(wiphy, netdev, info) +); + TRACE_EVENT(rdev_stop_ap, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, unsigned int link_id), From e70df36f3609b77c0800eb6e15f5dd77b940d22d Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:01 +0200 Subject: [PATCH 1478/2126] wifi: mac80211: protect AP template pointers with a spinlock The AP's beacon, presp etc. templates are only updated under wiphy mutex right now. Prepare for being able to update them without the wiphy mutex by using a (per-link) spinlock for them. Link: https://patch.msgid.link/20261009201417.f9414c150e5d.Iba8a15c4d37e441642b6df68c33ef8c97340e9a9@changeid Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 66 +++++++++++++------------------------- net/mac80211/ieee80211_i.h | 18 +++++++++++ net/mac80211/link.c | 1 + 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index d0d14f621588..08088a2656c7 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1123,13 +1123,11 @@ ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, const struct ieee80211_color_change_settings *cca, struct ieee80211_link_data *link) { - struct probe_resp *new, *old; + struct probe_resp *new; if (!resp || !resp_len) return 1; - old = sdata_dereference(link->u.ap.probe_resp, sdata); - new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL); if (!new) return -ENOMEM; @@ -1144,9 +1142,7 @@ ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, else if (cca) new->cntdwn_counter_offsets[0] = cca->counter_offset_presp; - rcu_assign_pointer(link->u.ap.probe_resp, new); - if (old) - kfree_rcu(old, rcu_head); + ap_tmpl_replace(link, link->u.ap.probe_resp, new); return 0; } @@ -1157,7 +1153,7 @@ static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata, struct ieee80211_bss_conf *link_conf, u64 *changed) { - struct fils_discovery_data *new, *old = NULL; + struct fils_discovery_data *new = NULL; struct ieee80211_fils_discovery *fd; /* @@ -1175,20 +1171,15 @@ static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata, fd->min_interval = params->min_interval; fd->max_interval = params->max_interval; - old = sdata_dereference(link->u.ap.fils_discovery, sdata); if (params->tmpl && params->tmpl_len) { new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); if (!new) return -ENOMEM; new->len = params->tmpl_len; memcpy(new->data, params->tmpl, params->tmpl_len); - rcu_assign_pointer(link->u.ap.fils_discovery, new); - } else { - RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); } - if (old) - kfree_rcu(old, rcu_head); + ap_tmpl_replace(link, link->u.ap.fils_discovery, new); *changed |= BSS_CHANGED_FILS_DISCOVERY; return 0; @@ -1201,7 +1192,7 @@ ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata, struct ieee80211_bss_conf *link_conf, u64 *changed) { - struct unsol_bcast_probe_resp_data *new, *old = NULL; + struct unsol_bcast_probe_resp_data *new = NULL; /* * This configuration is only applicable to transmitting BSSes. @@ -1216,21 +1207,15 @@ ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata, link_conf->unsol_bcast_probe_resp_interval = params->interval; - old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata); - if (params->tmpl && params->tmpl_len) { new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); if (!new) return -ENOMEM; new->len = params->tmpl_len; memcpy(new->data, params->tmpl, params->tmpl_len); - rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new); - } else { - RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); } - if (old) - kfree_rcu(old, rcu_head); + ap_tmpl_replace(link, link->u.ap.unsol_bcast_probe_resp, new); *changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP; return 0; @@ -1649,12 +1634,9 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, _changed |= BSS_CHANGED_FTM_RESPONDER; } - rcu_assign_pointer(link->u.ap.beacon, new); + ap_tmpl_replace(link, link->u.ap.beacon, new); sdata->u.ap.active = true; - if (old) - kfree_rcu(old, rcu_head); - ieee80211_update_ap_bandwidth(link, params); *changed |= _changed; @@ -1956,11 +1938,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, err = drv_start_ap(sdata->local, sdata, link_conf); if (err) { - old = sdata_dereference(link->u.ap.beacon, sdata); - - if (old) - kfree_rcu(old, rcu_head); - RCU_INIT_POINTER(link->u.ap.beacon, NULL); + ap_tmpl_replace(link, link->u.ap.beacon, NULL); if (ieee80211_num_beaconing_links(sdata) == 0) sdata->u.ap.active = false; @@ -2088,16 +2066,8 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev, lockdep_assert_wiphy(local->hw.wiphy); - old_beacon = sdata_dereference(link->u.ap.beacon, sdata); - if (!old_beacon) + if (!sdata_dereference(link->u.ap.beacon, sdata)) return -ENOENT; - old_probe_resp = sdata_dereference(link->u.ap.probe_resp, - sdata); - old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery, - sdata); - old_unsol_bcast_probe_resp = - sdata_dereference(link->u.ap.unsol_bcast_probe_resp, - sdata); old_s1g_short_beacon = sdata_dereference(link->u.ap.s1g_short_beacon, sdata); @@ -2118,10 +2088,20 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev, } /* remove beacon and probe response */ - RCU_INIT_POINTER(link->u.ap.beacon, NULL); - RCU_INIT_POINTER(link->u.ap.probe_resp, NULL); - RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); - RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); + scoped_guard(spinlock, &link->ap_tmpl_lock) { + old_beacon = ap_tmpl_dereference(link, link->u.ap.beacon); + old_probe_resp = ap_tmpl_dereference(link, + link->u.ap.probe_resp); + old_fils_discovery = + ap_tmpl_dereference(link, link->u.ap.fils_discovery); + old_unsol_bcast_probe_resp = + ap_tmpl_dereference(link, + link->u.ap.unsol_bcast_probe_resp); + RCU_INIT_POINTER(link->u.ap.beacon, NULL); + RCU_INIT_POINTER(link->u.ap.probe_resp, NULL); + RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); + RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); + } RCU_INIT_POINTER(link->u.ap.s1g_short_beacon, NULL); kfree_rcu(old_beacon, rcu_head); if (old_probe_resp) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index b571019bd05a..b16ff6a4aacf 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1152,6 +1152,9 @@ struct ieee80211_link_data { struct ieee80211_link_data_ap ap; } u; + /* protects replacing the u.ap template pointers, also without wiphy mutex */ + spinlock_t ap_tmpl_lock; + struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS]; struct ieee80211_bss_conf *conf; @@ -1166,6 +1169,21 @@ struct ieee80211_link_data { #endif }; +#define ap_tmpl_dereference(link, p) \ + rcu_dereference_protected(p, lockdep_is_held(&(link)->ap_tmpl_lock)) + +#define ap_tmpl_replace(link, p, new) \ +do { \ + typeof(ap_tmpl_dereference(link, p)) __old; \ + \ + spin_lock(&(link)->ap_tmpl_lock); \ + __old = rcu_replace_pointer(p, new, \ + lockdep_is_held(&(link)->ap_tmpl_lock));\ + spin_unlock(&(link)->ap_tmpl_lock); \ + if (__old) \ + kfree_rcu(__old, rcu_head); \ +} while (0) + struct ieee80211_sub_if_data { struct list_head list; diff --git a/net/mac80211/link.c b/net/mac80211/link.c index 931950a10508..ce1c95b40cd9 100644 --- a/net/mac80211/link.c +++ b/net/mac80211/link.c @@ -126,6 +126,7 @@ void ieee80211_link_init(struct ieee80211_sub_if_data *sdata, link->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; link->user_power_level = sdata->local->user_power_level; link_conf->txpower = INT_MIN; + spin_lock_init(&link->ap_tmpl_lock); wiphy_work_init(&link->csa.finalize_work, ieee80211_csa_finalize_work); From dfa7d4ec7340011803f166d3dedd4d8a6bb941ed Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:02 +0200 Subject: [PATCH 1479/2126] wifi: mac80211: refactor beacon allocation Refactor allocating/filling beacon data to a new function, so we can reuse it for lockless beacon updates. Also split out the bssid_indicator calculation, lockless updates will need to ensure it didn't change. Assisted-by: LLM Link: https://patch.msgid.link/20261009201417.ba48af051dfa.If468a87e4c71f8fe8d0f467525a86e7921496e9a@changeid Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 127 +++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 56 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 08088a2656c7..0b124b04003e 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1483,52 +1483,16 @@ static void ieee80211_update_ap_bandwidth(struct ieee80211_link_data *link, ieee80211_recalc_chanctx_min_def(local, chanctx); } -static int -ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, - struct ieee80211_link_data *link, - struct cfg80211_beacon_data *params, - const struct ieee80211_csa_settings *csa, - const struct ieee80211_color_change_settings *cca, - u64 *changed) +static struct beacon_data * +ieee80211_alloc_beacon(struct cfg80211_mbssid_elems *mbssid, + struct cfg80211_rnr_elems *rnr, + int head_len, int tail_len) { - struct cfg80211_mbssid_elems *mbssid = NULL; - struct cfg80211_rnr_elems *rnr = NULL; - struct beacon_data *new, *old; - int new_head_len, new_tail_len; - int size, err; + struct beacon_data *new; + int size; u8 *pos; - u64 _changed = BSS_CHANGED_BEACON; - struct ieee80211_bss_conf *link_conf = link->conf; - old = sdata_dereference(link->u.ap.beacon, sdata); - - /* Need to have a beacon head if we don't have one yet */ - if (!params->head && !old) - return -EINVAL; - - /* new or old head? */ - if (params->head) - new_head_len = params->head_len; - else - new_head_len = old->head_len; - - /* new or old tail? */ - if (params->tail || !old) - /* params->tail_len will be zero for !params->tail */ - new_tail_len = params->tail_len; - else - new_tail_len = old->tail_len; - - size = sizeof(*new) + new_head_len + new_tail_len; - - /* new or old multiple BSSID elements? */ - if (params->mbssid_ies) { - mbssid = params->mbssid_ies; - rnr = params->rnr_ies; - } else if (old && old->mbssid_ies) { - mbssid = old->mbssid_ies; - rnr = old->rnr_ies; - } + size = sizeof(*new) + head_len + tail_len; if (mbssid) { size += struct_size(new->mbssid_ies, elem, mbssid->cnt); @@ -1540,9 +1504,7 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, new = kzalloc(size, GFP_KERNEL); if (!new) - return -ENOMEM; - - /* start filling the new info now */ + return NULL; /* * pointers go into the block we allocated, the order in memory is @@ -1565,11 +1527,11 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, } new->head = pos; - new->head_len = new_head_len; - pos += new_head_len; + new->head_len = head_len; + pos += head_len; new->tail = pos; - new->tail_len = new_tail_len; - pos += new_tail_len; + new->tail_len = tail_len; + pos += tail_len; /* copy in optional mbssid_ies */ if (mbssid) { @@ -1577,14 +1539,67 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, mbssid); if (rnr) ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr); - /* update bssid_indicator */ - if (new->mbssid_ies->cnt && new->mbssid_ies->elem[0].len > 2) - link_conf->bssid_indicator = - *(new->mbssid_ies->elem[0].data + 2); - else - link_conf->bssid_indicator = 0; } + return new; +} + +static u8 ieee80211_beacon_bssid_indicator(struct beacon_data *beacon) +{ + if (beacon->mbssid_ies->cnt && beacon->mbssid_ies->elem[0].len > 2) + return *(beacon->mbssid_ies->elem[0].data + 2); + return 0; +} + +static int +ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, + struct ieee80211_link_data *link, + struct cfg80211_beacon_data *params, + const struct ieee80211_csa_settings *csa, + const struct ieee80211_color_change_settings *cca, + u64 *changed) +{ + struct cfg80211_mbssid_elems *mbssid = params->mbssid_ies; + struct cfg80211_rnr_elems *rnr = mbssid ? params->rnr_ies : NULL; + struct beacon_data *new, *old; + int new_head_len, new_tail_len; + int err; + u64 _changed = BSS_CHANGED_BEACON; + struct ieee80211_bss_conf *link_conf = link->conf; + + old = sdata_dereference(link->u.ap.beacon, sdata); + + /* Need to have a beacon head if we don't have one yet */ + if (!params->head && !old) + return -EINVAL; + + /* new or old head? */ + if (params->head) + new_head_len = params->head_len; + else + new_head_len = old->head_len; + + /* new or old tail? */ + if (params->tail || !old) + /* params->tail_len will be zero for !params->tail */ + new_tail_len = params->tail_len; + else + new_tail_len = old->tail_len; + + /* new or old multiple BSSID elements? */ + if (!mbssid && old && old->mbssid_ies) { + mbssid = old->mbssid_ies; + rnr = old->rnr_ies; + } + + new = ieee80211_alloc_beacon(mbssid, rnr, new_head_len, new_tail_len); + if (!new) + return -ENOMEM; + + if (new->mbssid_ies) + link_conf->bssid_indicator = + ieee80211_beacon_bssid_indicator(new); + if (csa) { new->cntdwn_current_counter = csa->count; memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon, From 9b790d94d7244e2926eca1434b5b56c3ecae49ef Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:03 +0200 Subject: [PATCH 1480/2126] wifi: mac80211: implement lockless beacon updates Implement the new update_beacon() method to update beacon and related templates without the wiphy mutex. If anything else were to change return -EAGAIN, same if there are any active countdowns, and during HW restart. Eventually, the idea is to replace countdowns by beacon update requests so hostapd can handle everything instead. This doesn't enable it for any drivers since it depends on the driver behaviour, if it fetches each beacon and doesn't use the other templates it can just set the feature flag (NL80211_EXT_FEATURE_UPDATE_BEACON), otherwise it must implement the new update_beacon() mac80211 method. The regular beacon update may need to take head, tail and MBSSID/RNR elements from the old beacon, so while that's going on mark "bss_update_in_progress" and make lockless updates return -EAGAIN during that time, so that the old data remains valid/identical. For MBSSID, the lockless path also can't copy old data, so that also has to return -EAGAIN. All those -EAGAIN cases fall back to cfg80211 and do the update with the lock held, where it can then be handled. Userspace should ideally ensure it doesn't hit that path. Assisted-by: LLM Link: https://patch.msgid.link/20261009201417.a9433ea65d8e.Icfbcd157ac2bdeccfcc74a9f4c3997d3010ec0a9@changeid Signed-off-by: Johannes Berg --- include/net/mac80211.h | 7 ++ net/mac80211/cfg.c | 225 ++++++++++++++++++++++++++++++++++--- net/mac80211/driver-ops.h | 16 +++ net/mac80211/ieee80211_i.h | 2 + net/mac80211/trace.h | 28 +++++ 5 files changed, 263 insertions(+), 15 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index a24d849b8f9c..2a61079e3975 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -4586,6 +4586,9 @@ struct ieee80211_prep_tx_info { * just "paused" for scanning/ROC, which is indicated by the beacon being * disabled/enabled via @bss_info_changed. * @stop_ap: Stop operation on the AP interface. + * @update_beacon: Update the templates indicated by @changed (beacon, probe + * response, FILS discovery and/or unsolicitated bcast probe response) + * without the wiphy mutex held. This callback must not sleep. * * @reconfig_complete: Called after a call to ieee80211_restart_hw() and * during resume, when the reconfiguration has completed. @@ -4783,6 +4786,10 @@ struct ieee80211_ops { struct ieee80211_bss_conf *link_conf); void (*stop_ap)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_bss_conf *link_conf); + void (*update_beacon)(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_bss_conf *link_conf, + u64 changed); u64 (*prepare_multicast)(struct ieee80211_hw *hw, struct netdev_hw_addr_list *mc_list); diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 0b124b04003e..30fe29f25928 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1561,17 +1561,23 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, { struct cfg80211_mbssid_elems *mbssid = params->mbssid_ies; struct cfg80211_rnr_elems *rnr = mbssid ? params->rnr_ies : NULL; - struct beacon_data *new, *old; + struct beacon_data *new = NULL, *old; int new_head_len, new_tail_len; int err; u64 _changed = BSS_CHANGED_BEACON; struct ieee80211_bss_conf *link_conf = link->conf; - old = sdata_dereference(link->u.ap.beacon, sdata); + /* grab old and make lockless updates return -EAGAIN */ + spin_lock(&link->ap_tmpl_lock); + old = ap_tmpl_dereference(link, link->u.ap.beacon); + link->u.ap.bss_update_in_progress = true; + spin_unlock(&link->ap_tmpl_lock); /* Need to have a beacon head if we don't have one yet */ - if (!params->head && !old) - return -EINVAL; + if (!params->head && !old) { + err = -EINVAL; + goto error; + } /* new or old head? */ if (params->head) @@ -1593,8 +1599,10 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, } new = ieee80211_alloc_beacon(mbssid, rnr, new_head_len, new_tail_len); - if (!new) - return -ENOMEM; + if (!new) { + err = -ENOMEM; + goto error; + } if (new->mbssid_ies) link_conf->bssid_indicator = @@ -1625,10 +1633,8 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, err = ieee80211_set_probe_resp(sdata, params->probe_resp, params->probe_resp_len, csa, cca, link); - if (err < 0) { - kfree(new); - return err; - } + if (err < 0) + goto error; if (err == 0) _changed |= BSS_CHANGED_AP_PROBE_RESP; @@ -1641,21 +1647,31 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, params->civicloc_len, link_conf); - if (err < 0) { - kfree(new); - return err; - } + if (err < 0) + goto error; _changed |= BSS_CHANGED_FTM_RESPONDER; } - ap_tmpl_replace(link, link->u.ap.beacon, new); + spin_lock(&link->ap_tmpl_lock); + rcu_assign_pointer(link->u.ap.beacon, new); + link->u.ap.bss_update_in_progress = false; + spin_unlock(&link->ap_tmpl_lock); sdata->u.ap.active = true; + if (old) + kfree_rcu(old, rcu_head); + ieee80211_update_ap_bandwidth(link, params); *changed |= _changed; return 0; +error: + spin_lock(&link->ap_tmpl_lock); + link->u.ap.bss_update_in_progress = false; + spin_unlock(&link->ap_tmpl_lock); + kfree(new); + return err; } static u8 ieee80211_num_beaconing_links(struct ieee80211_sub_if_data *sdata) @@ -2050,6 +2066,184 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, return 0; } +static int ieee80211_update_beacon(struct wiphy *wiphy, struct net_device *dev, + struct cfg80211_ap_update *params) +{ + struct cfg80211_unsol_bcast_probe_resp *ubpr = + ¶ms->unsol_bcast_probe_resp; + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); + struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; + struct unsol_bcast_probe_resp_data *new_ubpr = NULL, *old_ubpr = NULL; + struct cfg80211_beacon_data *beacon = ¶ms->beacon; + struct fils_discovery_data *new_fd = NULL, *old_fd = NULL; + struct probe_resp *new_presp = NULL, *old_presp = NULL; + struct ieee80211_local *local = sdata->local; + struct beacon_data *new, *old = NULL; + struct ieee80211_bss_conf *link_conf; + struct ieee80211_link_data *link; + struct ieee80211_channel *chan; + u64 changed = BSS_CHANGED_BEACON; + int err = 0; + + if (READ_ONCE(local->in_reconfig) || READ_ONCE(local->quiescing)) + return -EAGAIN; + + new = ieee80211_alloc_beacon(beacon->mbssid_ies, + beacon->mbssid_ies ? beacon->rnr_ies : NULL, + beacon->head_len, beacon->tail_len); + if (!new) + return -ENOMEM; + memcpy(new->head, beacon->head, beacon->head_len); + memcpy(new->tail, beacon->tail, beacon->tail_len); + + if (beacon->probe_resp && beacon->probe_resp_len) { + new_presp = kzalloc(sizeof(*new_presp) + beacon->probe_resp_len, + GFP_KERNEL); + if (!new_presp) { + err = -ENOMEM; + goto free; + } + new_presp->len = beacon->probe_resp_len; + memcpy(new_presp->data, beacon->probe_resp, + beacon->probe_resp_len); + changed |= BSS_CHANGED_AP_PROBE_RESP; + } + + if (fd->update && fd->tmpl && fd->tmpl_len) { + new_fd = kzalloc(sizeof(*new_fd) + fd->tmpl_len, GFP_KERNEL); + if (!new_fd) { + err = -ENOMEM; + goto free; + } + new_fd->len = fd->tmpl_len; + memcpy(new_fd->data, fd->tmpl, fd->tmpl_len); + } + + if (ubpr->update && ubpr->tmpl && ubpr->tmpl_len) { + new_ubpr = kzalloc(sizeof(*new_ubpr) + ubpr->tmpl_len, + GFP_KERNEL); + if (!new_ubpr) { + err = -ENOMEM; + goto free; + } + new_ubpr->len = ubpr->tmpl_len; + memcpy(new_ubpr->data, ubpr->tmpl, ubpr->tmpl_len); + } + + rcu_read_lock(); + + /* do_stop() synchronizes RCU before the interface type can change */ + if (!ieee80211_sdata_running(sdata) || + (sdata->vif.type != NL80211_IFTYPE_AP && + sdata->vif.type != NL80211_IFTYPE_P2P_GO)) { + err = -ENETDOWN; + goto unlock; + } + + link = rcu_dereference(sdata->link[beacon->link_id]); + if (!link) { + err = -ENOLINK; + goto unlock; + } + link_conf = link->conf; + + /* configuration changes need the wiphy mutex, let cfg80211 retry */ + err = -EAGAIN; + + if (READ_ONCE(link_conf->csa_active) || + READ_ONCE(link_conf->color_change_active)) + goto unlock; + + if (new->mbssid_ies && + ieee80211_beacon_bssid_indicator(new) != + READ_ONCE(link_conf->bssid_indicator)) + goto unlock; + + if (fd->update && + (fd->min_interval != READ_ONCE(link_conf->fils_discovery.min_interval) || + fd->max_interval != READ_ONCE(link_conf->fils_discovery.max_interval))) + goto unlock; + + if (ubpr->update && + ubpr->interval != + READ_ONCE(link_conf->unsol_bcast_probe_resp_interval)) + goto unlock; + + chan = READ_ONCE(link_conf->chanreq.oper.chan); + if (!chan) + goto unlock; + + if (chan->band != NL80211_BAND_S1GHZ) { + enum ieee80211_sta_rx_bandwidth he_and_lower; + + he_and_lower = ieee80211_calc_ap_he_and_lower(beacon); + if (he_and_lower != READ_ONCE(link->bss_bw.he_and_lower) || + ieee80211_calc_ap_eht_bw(beacon, he_and_lower) != + READ_ONCE(link->bss_bw.eht)) + goto unlock; + } + + spin_lock(&link->ap_tmpl_lock); + old = ap_tmpl_dereference(link, link->u.ap.beacon); + if (!old) { + err = -ENOENT; + } else if (link->u.ap.bss_update_in_progress) { + /* a locked update is in progress */ + old = NULL; + } else if (READ_ONCE(old->cntdwn_current_counter)) { + /* a countdown just started, must keep the offsets */ + old = NULL; + } else if (old->mbssid_ies && !new->mbssid_ies) { + /* only locked path copies old MBSSID data */ + old = NULL; + } else { + rcu_assign_pointer(link->u.ap.beacon, new); + new = NULL; + + if (new_presp) + old_presp = rcu_replace_pointer(link->u.ap.probe_resp, + new_presp, + lockdep_is_held(&link->ap_tmpl_lock)); + new_presp = NULL; + + if (fd->update) { + old_fd = rcu_replace_pointer(link->u.ap.fils_discovery, + new_fd, + lockdep_is_held(&link->ap_tmpl_lock)); + changed |= BSS_CHANGED_FILS_DISCOVERY; + } + new_fd = NULL; + + if (ubpr->update) { + old_ubpr = rcu_replace_pointer(link->u.ap.unsol_bcast_probe_resp, + new_ubpr, + lockdep_is_held(&link->ap_tmpl_lock)); + changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP; + } + new_ubpr = NULL; + + drv_update_beacon(local, sdata, link_conf, changed); + err = 0; + } + spin_unlock(&link->ap_tmpl_lock); +unlock: + rcu_read_unlock(); +free: + kfree(new); + kfree(new_presp); + kfree(new_fd); + kfree(new_ubpr); + if (old) + kfree_rcu(old, rcu_head); + if (old_presp) + kfree_rcu(old_presp, rcu_head); + if (old_fd) + kfree_rcu(old_fd, rcu_head); + if (old_ubpr) + kfree_rcu(old_ubpr, rcu_head); + return err; +} + static void ieee80211_free_next_beacon(struct ieee80211_link_data *link) { if (!link->u.ap.next_beacon) @@ -6071,6 +6265,7 @@ const struct cfg80211_ops mac80211_config_ops = { .set_default_beacon_key = ieee80211_config_default_beacon_key, .start_ap = ieee80211_start_ap, .change_beacon = ieee80211_change_beacon, + .update_beacon = ieee80211_update_beacon, .stop_ap = ieee80211_stop_ap, .add_station = ieee80211_add_station, .del_station = ieee80211_del_station, diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index f1c0b87fddd5..accd89bbc1fb 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h @@ -1107,6 +1107,22 @@ static inline void drv_stop_ap(struct ieee80211_local *local, trace_drv_return_void(local); } +static inline void drv_update_beacon(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_bss_conf *link_conf, + u64 changed) +{ + /* can race with HW restart, so don't warn */ + if (!(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) + return; + + trace_drv_update_beacon(local, sdata, link_conf, changed); + if (local->ops->update_beacon) + local->ops->update_beacon(&local->hw, &sdata->vif, link_conf, + changed); + trace_drv_return_void(local); +} + static inline void drv_reconfig_complete(struct ieee80211_local *local, enum ieee80211_reconfig_type reconfig_type) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index b16ff6a4aacf..16c1e0337f3a 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1103,6 +1103,8 @@ struct ieee80211_link_data_ap { struct unsol_bcast_probe_resp_data __rcu *unsol_bcast_probe_resp; struct s1g_short_beacon_data __rcu *s1g_short_beacon; + bool bss_update_in_progress; + /* to be used after channel switch. */ struct cfg80211_beacon_data *next_beacon; }; diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h index 562a4964afa3..ea46c3cca21a 100644 --- a/net/mac80211/trace.h +++ b/net/mac80211/trace.h @@ -1924,6 +1924,34 @@ TRACE_EVENT(drv_stop_ap, ) ); +TRACE_EVENT(drv_update_beacon, + TP_PROTO(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_bss_conf *link_conf, + u64 changed), + + TP_ARGS(local, sdata, link_conf, changed), + + TP_STRUCT__entry( + LOCAL_ENTRY + VIF_ENTRY + __field(u32, link_id) + __field(u64, changed) + ), + + TP_fast_assign( + LOCAL_ASSIGN; + VIF_ASSIGN; + __entry->link_id = link_conf->link_id; + __entry->changed = changed; + ), + + TP_printk( + LOCAL_PR_FMT VIF_PR_FMT " link id %u changed:%#llx", + LOCAL_PR_ARG, VIF_PR_ARG, __entry->link_id, __entry->changed + ) +); + TRACE_EVENT(drv_reconfig_complete, TP_PROTO(struct ieee80211_local *local, enum ieee80211_reconfig_type reconfig_type), From 3c46fb6b3c17400096e2300d9423cdf53c07390f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:04 +0200 Subject: [PATCH 1481/2126] wifi: mac80211_hwsim: support lockless beacon updates We just use ieee80211_beacon_get_template_ema_list() or ieee80211_beacon_get() here to transmit the beacons, so there's no need to implement update_beacon() and we can just set NL80211_EXT_FEATURE_UPDATE_BEACON. Link: https://patch.msgid.link/20261009201417.b70fda659f6a.I811ea72fc189eb20bbc07b27cfaf9ffd420a70c9@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index ce06867ff01e..87f20d5ff0ee 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -6017,6 +6017,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, NL80211_EXT_FEATURE_EXT_KEY_ID); wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_ASSOC_FRAME_ENCRYPTION); + wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_UPDATE_BEACON); hw->wiphy->interface_modes = param->iftypes; From 13c20e8be3278e54f4758941998a3ee746644d8d Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:05 +0200 Subject: [PATCH 1482/2126] wifi: nl80211: prepare for unlocked wdev-only ops The update-beacon operation currently can fairly easily work without extra care and without the wiphy mutex as it holds the netdev. However, we can't do the same now for wdevs, they could be unregistered (and destroyed) while the operation is running. Allow for such operations as well by giving the wdevs a refcount as well, and waiting for that refcount to drop to zero during wdev unregistration. This requires some special care in nl80211, especially for a "re-do the operation locked" implementation, but that's contained here so drivers need not worry about it (except if they request the operation to be retried under lock, that might never happen). Link: https://patch.msgid.link/20261009201417.0eaf10071df8.If2812b7c82df39cc9ed51746f55789fc4f51d4b1@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 8 +++++ net/wireless/core.c | 11 ++++++ net/wireless/core.h | 21 +++++++++++ net/wireless/nl80211.c | 82 +++++++++++++++++++++++++++++++++--------- 4 files changed, 106 insertions(+), 16 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 7de6dbdae930..16f6b96e0d88 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -7226,6 +7227,9 @@ enum ieee80211_ap_reg_power { * @netdev: (private) Used to reference back to the netdev, may be %NULL * @identifier: (private) Identifier used in nl80211 to identify this * wireless device if it has no netdev + * @refcnt: (private) references held by nl80211 if there's no netdev, + * to ensure cfg80211_unregister_wdev() cannot return while + * unlocked ops are running * @u: union containing data specific to @iftype * @connected: indicates if connected or not (STA mode) * @wext: (private) Used by the internal wireless extensions compat code @@ -7291,6 +7295,7 @@ struct wireless_dev { struct net_device *netdev; u32 identifier; + refcount_t refcnt; struct list_head mgmt_registrations; u8 mgmt_registrations_need_update:1; @@ -10174,6 +10179,9 @@ u32 cfg80211_calculate_bitrate(struct rate_info *rate); * when the driver wishes to unregister the wdev, e.g. when the hardware device * is unbound from the driver. * + * Note that unlocked operations can run concurrently until this returns, so be + * careful about ordering. + * * Context: Requires the RTNL and wiphy mutex to be held. */ void cfg80211_unregister_wdev(struct wireless_dev *wdev); diff --git a/net/wireless/core.c b/net/wireless/core.c index 01b077909179..777f48a01101 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -1514,6 +1514,16 @@ static void _cfg80211_unregister_wdev(struct wireless_dev *wdev, list_del_rcu(&wdev->list); synchronize_net(); + + /* + * After synchronize_net() any lookups under RCU either have + * references (must wdev_hold() inside the critical section) + * or can't find this wdev anymore. Wait for any wdev_hold() + * users on a pure wdev to get to dev_put(). + */ + if (!wdev->netdev && !refcount_dec_and_test(&wdev->refcnt)) + wait_var_event(&wdev->refcnt, !refcount_read(&wdev->refcnt)); + rdev->devlist_generation++; wiphy_work_cancel(wdev->wiphy, &wdev->disconnect_wk); @@ -1700,6 +1710,7 @@ EXPORT_SYMBOL(cfg80211_stop_link); void cfg80211_init_wdev(struct wireless_dev *wdev) { + refcount_set(&wdev->refcnt, 1); INIT_LIST_HEAD(&wdev->event_list); spin_lock_init(&wdev->event_lock); INIT_LIST_HEAD(&wdev->mgmt_registrations); diff --git a/net/wireless/core.h b/net/wireless/core.h index dfcb9ed5035b..220544a6bb83 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include "reg.h" @@ -259,6 +260,26 @@ void cfg80211_init_wdev(struct wireless_dev *wdev); void cfg80211_register_wdev(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev); +static inline void wdev_hold(struct wireless_dev *wdev) +{ + if (wdev->netdev) { + dev_hold(wdev->netdev); + return; + } + + /* also not RTNL, but can't check that */ + lockdep_assert_not_held(&wdev->wiphy->mtx); + refcount_inc(&wdev->refcnt); +} + +static inline void wdev_put(struct wireless_dev *wdev) +{ + if (wdev->netdev) + dev_put(wdev->netdev); + else if (refcount_dec_and_test(&wdev->refcnt)) + wake_up_var(&wdev->refcnt); +} + static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev) { lockdep_assert_held(&rdev->wiphy.mtx); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 6387a312b35e..eb91937a7238 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -266,6 +266,34 @@ nl80211_lock_and_recheck(struct cfg80211_registered_device *rdev, return ERR_PTR(-ENODEV); } +/* + * Must have wdev_hold(), acquire the wiphy mutex. This has to + * look up the wdev again (otherwise it could deadlock against + * wdev removal), so it can return an error pointer. + */ +static struct wireless_dev * +nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, + struct genl_info *info, struct wireless_dev *wdev) +{ + u32 wdev_id = wdev->identifier; + + /* the wdev reference was keeping the wiphy alive */ + get_device(&rdev->wiphy.dev); + info->user_ptr[1] = NULL; + wdev_put(wdev); + + wdev = nl80211_lock_and_recheck(rdev, genl_info_net(info), wdev_id); + if (IS_ERR(wdev)) + return wdev; + + if (!wdev_running(wdev)) { + wiphy_unlock(&rdev->wiphy); + return ERR_PTR(-ENETDOWN); + } + + return wdev; +} + static int validate_beacon_head(const struct nlattr *attr, struct netlink_ext_ack *extack) { @@ -19906,14 +19934,10 @@ nl80211_epcs_cfg(struct sk_buff *skb, struct genl_info *info) /* * Note: a - * SELECTOR(..., - * NL80211_FLAG_NO_WIPHY_MTX | - * NL80211_FLAG_NEED_WDEV) - * or * SELECTOR(..., NL80211_FLAG_NO_WIPHY_MTX) * - * isn't valid - nothing would ensure the device stays around, - * need at least a netdev, the wiphy mutex, or RTNL. + * isn't valid - nothing would ensure the device stays around, need + * at least a wdev/netdev reference, the wiphy mutex, or RTNL. */ enum nl80211_internal_flags_selector { @@ -19928,6 +19952,13 @@ static u32 nl80211_internal_flags[] = { #undef SELECTOR }; +/* without RTNL or wiphy mutex, a wdev reference keeps everything alive */ +static bool nl80211_need_wdev_ref(u32 internal_flags) +{ + return !(internal_flags & NL80211_FLAG_NEED_RTNL) && + internal_flags & NL80211_FLAG_NO_WIPHY_MTX; +} + static int nl80211_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) @@ -19936,7 +19967,7 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, struct net *netns = genl_info_net(info); struct wireless_dev *wdev = NULL; struct net_device *dev = NULL; - bool need_rtnl, locked = false; + bool need_rtnl, wdev_ref, locked = false; u32 internal_flags, wdev_id = 0; int err; @@ -19945,6 +19976,7 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, internal_flags = nl80211_internal_flags[ops->internal_flags]; need_rtnl = internal_flags & NL80211_FLAG_NEED_RTNL; + wdev_ref = nl80211_need_wdev_ref(internal_flags); if (need_rtnl) rtnl_lock(); @@ -19966,7 +19998,16 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, } dev = wdev->netdev; - dev_hold(dev); + /* + * Take the wdev ref only if we need it (wdev_ref is true when + * the op is unlocked), we must not try to acquire this with + * a wdev pointer protected by locking, it'd deadlock against + * unregistration. + */ + if (wdev_ref) + wdev_hold(wdev); + else + dev_hold(dev); rdev = wiphy_to_rdev(wdev->wiphy); } @@ -19999,12 +20040,12 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, locked = true; } else if (rdev && !need_rtnl) { /* - * Without any mutex need a netdev to keep it alive, see - * also the note about selectors - the WARN can't happen + * Without any mutex need a wdev reference to keep it alive, + * see also the note about selectors - the WARN can't happen * without wrong selectors and those don't exist. */ put_device(&rdev->wiphy.dev); - if (WARN_ON(!dev)) { + if (WARN_ON(!wdev)) { err = -EINVAL; goto out; } @@ -20069,7 +20110,10 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops, out: if (locked) wiphy_unlock(&rdev->wiphy); - dev_put(dev); + if (wdev_ref && wdev) + wdev_put(wdev); + else + dev_put(dev); if (need_rtnl) rtnl_unlock(); return err; @@ -20086,17 +20130,23 @@ static void nl80211_post_doit(const struct genl_split_ops *ops, struct genl_info *info) { u32 internal_flags = nl80211_internal_flags[ops->internal_flags]; + struct wireless_dev *wdev = NULL; + struct net_device *dev = NULL; if (info->user_ptr[1]) { if (internal_flags & NL80211_FLAG_NEED_WDEV) { - struct wireless_dev *wdev = info->user_ptr[1]; - - dev_put(wdev->netdev); + wdev = info->user_ptr[1]; + dev = wdev->netdev; } else { - dev_put(info->user_ptr[1]); + dev = info->user_ptr[1]; } } + if (wdev && nl80211_need_wdev_ref(internal_flags)) + wdev_put(wdev); + else + dev_put(dev); + if (info->user_ptr[0] && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; From 3938d944e8f8cce68981ad7fef785592435e15f9 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:06 +0200 Subject: [PATCH 1483/2126] wifi: nl80211: allow mgmt frame TX without wiphy mutex Management frame transmissions need the wiphy mutex, but the normal transmit path doesn't, so most cases shouldn't need it here either. Due to checks, limit it to AP/GO for now. To support it, drivers must implement the new method mgmt_tx_unlocked(), and return -EAGAIN from that for requests that cannot be done without the wiphy mutex (e.g. off-channel in mac80211), then the operation will be retried with the wiphy mutex held. Link: https://patch.msgid.link/20261009201417.d376c87d429b.I4acfe051ab48ea9b012aa3bb26a62ab412a6eb9b@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 11 ++++++++ net/wireless/core.h | 4 +++ net/wireless/mlme.c | 58 ++++++++++++++++++++++++++++++++++++----- net/wireless/nl80211.c | 50 +++++++++++++++++++++++++++-------- net/wireless/rdev-ops.h | 12 +++++++++ net/wireless/trace.h | 14 +++++++++- 6 files changed, 130 insertions(+), 19 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 16f6b96e0d88..0eee48bdc937 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5087,6 +5087,13 @@ struct mgmt_frame_regs { * This allows the operation to be terminated prior to timeout based on * the duration value. * @mgmt_tx: Transmit a management frame. + * @mgmt_tx_unlocked: Like @mgmt_tx, but called without the wiphy mutex, + * currently limited to AP/GO/NAN. The driver may -EAGAIN to get + * @mgmt_tx with the wiphy mutex held for the same operation, + * although if the device is removed concurrently that might not + * happen and userspace sees -ENODEV. + * Note this cannot acquire the wiphy mutex or RTNL, that would + * deadlock against unregistering the wdev. * @mgmt_tx_cancel_wait: Cancel the wait time from transmitting a management * frame on another channel * @@ -5510,6 +5517,10 @@ struct cfg80211_ops { int (*mgmt_tx)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params, u64 cookie); + int (*mgmt_tx_unlocked)(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, + u64 cookie); int (*mgmt_tx_cancel_wait)(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie); diff --git a/net/wireless/core.h b/net/wireless/core.h index 220544a6bb83..0e05d4247bea 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -432,6 +432,10 @@ int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params, u64 cookie); +int cfg80211_mlme_mgmt_tx_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, + u64 cookie); void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa, const struct ieee80211_ht_cap *ht_capa_mask); void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa, diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index 96fd14f2a305..80ca9031d29c 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c @@ -892,15 +892,14 @@ static bool cfg80211_allowed_random_address(struct wireless_dev *wdev, return false; } -int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, - struct wireless_dev *wdev, - struct cfg80211_mgmt_tx_params *params, u64 cookie) +static int cfg80211_mgmt_tx_check(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + enum nl80211_iftype iftype, + struct cfg80211_mgmt_tx_params *params) { const struct ieee80211_mgmt *mgmt; u16 stype; - lockdep_assert_wiphy(&rdev->wiphy); - if (!wdev->wiphy->mgmt_stypes) return -EOPNOTSUPP; @@ -917,14 +916,14 @@ int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, return -EINVAL; stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; - if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4))) + if (!(wdev->wiphy->mgmt_stypes[iftype].tx & BIT(stype >> 4))) return -EINVAL; if (ieee80211_is_action(mgmt->frame_control) && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { int err = 0; - switch (wdev->iftype) { + switch (iftype) { case NL80211_IFTYPE_ADHOC: /* * check for IBSS DA must be done by driver as @@ -1003,10 +1002,55 @@ int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, !cfg80211_allowed_random_address(wdev, mgmt)) return -EINVAL; + return 0; +} + +int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, u64 cookie) +{ + int err; + + lockdep_assert_wiphy(&rdev->wiphy); + + err = cfg80211_mgmt_tx_check(rdev, wdev, wdev->iftype, params); + if (err) + return err; + /* Transmit the management frame as requested by user space */ return rdev_mgmt_tx(rdev, wdev, params, cookie); } +int cfg80211_mlme_mgmt_tx_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, + u64 cookie) +{ + /* can change concurrently, so read only once */ + enum nl80211_iftype iftype = READ_ONCE(wdev->iftype); + int err; + + if (!rdev->ops->mgmt_tx_unlocked) + return -EAGAIN; + + switch (iftype) { + case NL80211_IFTYPE_AP: + case NL80211_IFTYPE_P2P_GO: + case NL80211_IFTYPE_NAN: + case NL80211_IFTYPE_NAN_DATA: + break; + default: + /* the checks for other interface types need the wiphy mutex */ + return -EAGAIN; + } + + err = cfg80211_mgmt_tx_check(rdev, wdev, iftype, params); + if (err) + return err; + + return rdev_mgmt_tx_unlocked(rdev, wdev, params, cookie); +} + bool cfg80211_rx_mgmt_ext(struct wireless_dev *wdev, struct cfg80211_rx_info *info) { diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index eb91937a7238..7cb3bb9438d7 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -15152,6 +15152,22 @@ static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) info->extack); } +static int nl80211_tx_mgmt_locked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, + u64 cookie) +{ + if (params->link_id >= 0 && + !(wdev->valid_links & BIT(params->link_id))) + return -EINVAL; + + if (params->offchan && + !cfg80211_off_channel_oper_allowed(wdev, params->chan)) + return -EBUSY; + + return cfg80211_mlme_mgmt_tx(rdev, wdev, params, cookie); +} + static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; @@ -15237,18 +15253,14 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) if (!chandef.chan && params.offchan) return -EINVAL; - if (params.offchan && - !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) - return -EBUSY; - params.link_id = nl80211_link_id_or_invalid(info->attrs); /* - * This now races due to the unlock, but we cannot check - * the valid links for the _station_ anyway, so that's up - * to the driver. + * This races (even with the wiphy mutex, since it's not held for + * netdevs here), but we cannot check the valid links for the + * _station_ anyway, so that's up to the driver. */ if (params.link_id >= 0 && - !(wdev->valid_links & BIT(params.link_id))) + !(READ_ONCE(wdev->valid_links) & BIT(params.link_id))) return -EINVAL; params.no_sta = @@ -15279,7 +15291,19 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) params.chan = chandef.chan; cookie = cfg80211_assign_cookie(rdev); - err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, cookie); + + /* pre_doit didn't lock the wiphy mutex, try without */ + err = cfg80211_mlme_mgmt_tx_unlocked(rdev, wdev, ¶ms, cookie); + if (err == -EAGAIN) { + wdev = nl80211_lock_held_wdev(rdev, info, wdev); + if (IS_ERR(wdev)) { + err = PTR_ERR(wdev); + } else { + err = nl80211_tx_mgmt_locked(rdev, wdev, ¶ms, + cookie); + wiphy_unlock(&rdev->wiphy); + } + } if (err) goto free_msg; @@ -19930,7 +19954,10 @@ nl80211_epcs_cfg(struct sk_buff *skb, struct genl_info *info) SELECTOR(__sel, WDEV_UP_RTNL_NOMTX, \ NL80211_FLAG_NEED_WDEV_UP | \ NL80211_FLAG_NO_WIPHY_MTX | \ - NL80211_FLAG_NEED_RTNL) + NL80211_FLAG_NEED_RTNL) \ + SELECTOR(__sel, WDEV_UP_NOMTX, \ + NL80211_FLAG_NEED_WDEV_UP | \ + NL80211_FLAG_NO_WIPHY_MTX) /* * Note: a @@ -20690,7 +20717,8 @@ static const struct genl_small_ops nl80211_small_ops[] = { .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = nl80211_tx_mgmt, .flags = GENL_UNS_ADMIN_PERM, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | + NL80211_FLAG_NO_WIPHY_MTX), }, { .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 95882c8972d2..5502cd947844 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -785,6 +785,18 @@ static inline int rdev_mgmt_tx(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_mgmt_tx_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, u64 cookie) +{ + int ret; + trace_rdev_mgmt_tx_unlocked(&rdev->wiphy, wdev, params); + ret = rdev->ops->mgmt_tx_unlocked(&rdev->wiphy, wdev, params, cookie); + trace_rdev_return_int_cookie(&rdev->wiphy, ret, cookie); + return ret; +} + static inline int rdev_tx_control_port(struct cfg80211_registered_device *rdev, struct net_device *dev, const void *buf, size_t len, diff --git a/net/wireless/trace.h b/net/wireless/trace.h index f5fa2fb76474..1f3c1e0eb26a 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2236,7 +2236,7 @@ TRACE_EVENT(rdev_cancel_remain_on_channel, WIPHY_PR_ARG, WDEV_PR_ARG, __entry->cookie) ); -TRACE_EVENT(rdev_mgmt_tx, +DECLARE_EVENT_CLASS(rdev_mgmt_tx_evt, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params), TP_ARGS(wiphy, wdev, params), @@ -2266,6 +2266,18 @@ TRACE_EVENT(rdev_mgmt_tx, BOOL_TO_STR(__entry->dont_wait_for_ack)) ); +DEFINE_EVENT(rdev_mgmt_tx_evt, rdev_mgmt_tx, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params), + TP_ARGS(wiphy, wdev, params) +); + +DEFINE_EVENT(rdev_mgmt_tx_evt, rdev_mgmt_tx_unlocked, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params), + TP_ARGS(wiphy, wdev, params) +); + TRACE_EVENT(rdev_tx_control_port, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, const u8 *buf, size_t len, const u8 *dest, __be16 proto, From fd6bcb455bf7d15165db1cbd325d53ad095fceee Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:07 +0200 Subject: [PATCH 1484/2126] wifi: cfg80211: make cookie counter atomic The cookie counter is currently protected by the wiphy mutex, but in order to be able to transmit management frames without holding that, we need to assign cookies atomically. Link: https://patch.msgid.link/20261009201417.ec1dbc786a60.I83ec404d833100a798181234c797c558400c7145@changeid Signed-off-by: Johannes Berg --- net/wireless/core.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/wireless/core.h b/net/wireless/core.h index 0e05d4247bea..07d7a68a7cfc 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -83,7 +83,9 @@ struct cfg80211_registered_device { /* protected by RTNL only */ int num_running_ifaces; int num_running_monitor_ifaces; - u64 cookie_counter; + + /* atomic for unlocked users */ + atomic64_t cookie_counter; /* BSSes/scanning */ spinlock_t bss_lock; @@ -171,10 +173,10 @@ cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev) static inline u64 cfg80211_assign_cookie(struct cfg80211_registered_device *rdev) { - u64 r = ++rdev->cookie_counter; + u64 r = atomic64_inc_return(&rdev->cookie_counter); if (WARN_ON(r == 0)) - r = ++rdev->cookie_counter; + r = atomic64_inc_return(&rdev->cookie_counter); return r; } From c9f648b31b4dfadf0a1df56470b52d24269cf4af Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:08 +0200 Subject: [PATCH 1485/2126] wifi: mac80211: refactor mgmt frames TX Refactor ieee80211_mgmt_tx() into on-channel and frame building helper functions so we can later implement the new mgmt_tx_unlocked() method. Link: https://patch.msgid.link/20261009201417.a84e223f4998.I4848c3eeb2aaf327712233f0bdb38bb48bdbbba6@changeid Signed-off-by: Johannes Berg --- net/mac80211/offchannel.c | 225 +++++++++++++++++++++----------------- 1 file changed, 122 insertions(+), 103 deletions(-) diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c index c46cb81fab22..27ca2984826f 100644 --- a/net/mac80211/offchannel.c +++ b/net/mac80211/offchannel.c @@ -814,6 +814,124 @@ int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy, return ieee80211_cancel_roc(local, cookie, false); } +static bool +ieee80211_mgmt_tx_need_offchan(struct ieee80211_sub_if_data *sdata, + struct cfg80211_mgmt_tx_params *params, + const struct ieee80211_mgmt *mgmt, + bool mlo_sta, int *link_id) +{ + struct ieee80211_chanctx_conf *chanctx_conf = NULL; + int i; + + guard(rcu)(); + + /* Check all the links first */ + for (i = 0; i < ARRAY_SIZE(sdata->vif.link_conf); i++) { + struct ieee80211_bss_conf *conf; + + conf = rcu_dereference(sdata->vif.link_conf[i]); + if (!conf) + continue; + + chanctx_conf = rcu_dereference(conf->chanctx_conf); + if (!chanctx_conf) + continue; + + if (mlo_sta && params->chan == chanctx_conf->def.chan && + ether_addr_equal(sdata->vif.addr, mgmt->sa)) { + *link_id = i; + break; + } + + if (ether_addr_equal(conf->addr, mgmt->sa)) { + /* If userspace requested Tx on a specific link + * use the same link id if the link bss is matching + * the requested chan. + */ + if (sdata->vif.valid_links && + params->link_id >= 0 && params->link_id == i && + params->chan == chanctx_conf->def.chan) + *link_id = i; + + break; + } + + chanctx_conf = NULL; + } + + if (!chanctx_conf) + return true; + + return params->chan && params->chan != chanctx_conf->def.chan; +} + +static struct sk_buff * +ieee80211_mgmt_tx_skb(struct ieee80211_sub_if_data *sdata, + struct cfg80211_mgmt_tx_params *params, + u64 cookie, gfp_t gfp) +{ + struct ieee80211_local *local = sdata->local; + struct sk_buff *skb; + u32 flags; + u8 *data; + + if (params->dont_wait_for_ack) + flags = IEEE80211_TX_CTL_NO_ACK; + else + flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | + IEEE80211_TX_CTL_REQ_TX_STATUS; + + if (params->no_cck) + flags |= IEEE80211_TX_CTL_NO_CCK_RATE; + + skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len); + if (!skb) + return NULL; + skb_reserve(skb, local->hw.extra_tx_headroom); + + data = skb_put_data(skb, params->buf, params->len); + + /* Update CSA counters */ + if (sdata->vif.bss_conf.csa_active && + (sdata->vif.type == NL80211_IFTYPE_AP || + sdata->vif.type == NL80211_IFTYPE_MESH_POINT || + sdata->vif.type == NL80211_IFTYPE_ADHOC) && + params->n_csa_offsets) { + int i; + struct beacon_data *beacon = NULL; + + rcu_read_lock(); + + if (sdata->vif.type == NL80211_IFTYPE_AP) + beacon = rcu_dereference(sdata->deflink.u.ap.beacon); + else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) + beacon = rcu_dereference(sdata->u.ibss.presp); + else if (ieee80211_vif_is_mesh(&sdata->vif)) + beacon = rcu_dereference(sdata->u.mesh.beacon); + + if (beacon) + for (i = 0; i < params->n_csa_offsets; i++) + data[params->csa_offsets[i]] = + beacon->cntdwn_current_counter; + + rcu_read_unlock(); + } + + IEEE80211_SKB_CB(skb)->flags = flags; + IEEE80211_SKB_CB(skb)->control.flags |= IEEE80211_TX_CTRL_DONT_USE_RATE_MASK; + + skb->dev = sdata->dev; + + /* make a copy to preserve the frame contents in case of encryption */ + if (!params->dont_wait_for_ack && + ieee80211_attach_ack_skb(local, skb, &cookie, gfp)) { + kfree_skb(skb); + return NULL; + } + + return skb; +} + int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params, u64 cookie) { @@ -825,21 +943,10 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, bool need_offchan = false; bool mlo_sta = false; int link_id = -1; - u32 flags; int ret; - u8 *data; lockdep_assert_wiphy(local->hw.wiphy); - if (params->dont_wait_for_ack) - flags = IEEE80211_TX_CTL_NO_ACK; - else - flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | - IEEE80211_TX_CTL_REQ_TX_STATUS; - - if (params->no_cck) - flags |= IEEE80211_TX_CTL_NO_CCK_RATE; - switch (sdata->vif.type) { case NL80211_IFTYPE_ADHOC: if (!sdata->vif.cfg.ibss_joined) @@ -927,52 +1034,9 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, sdata->vif.type == NL80211_IFTYPE_NAN_DATA) { /* Frames can be sent during NAN schedule */ } else if (!need_offchan) { - struct ieee80211_chanctx_conf *chanctx_conf = NULL; - int i; - - rcu_read_lock(); - /* Check all the links first */ - for (i = 0; i < ARRAY_SIZE(sdata->vif.link_conf); i++) { - struct ieee80211_bss_conf *conf; - - conf = rcu_dereference(sdata->vif.link_conf[i]); - if (!conf) - continue; - - chanctx_conf = rcu_dereference(conf->chanctx_conf); - if (!chanctx_conf) - continue; - - if (mlo_sta && params->chan == chanctx_conf->def.chan && - ether_addr_equal(sdata->vif.addr, mgmt->sa)) { - link_id = i; - break; - } - - if (ether_addr_equal(conf->addr, mgmt->sa)) { - /* If userspace requested Tx on a specific link - * use the same link id if the link bss is matching - * the requested chan. - */ - if (sdata->vif.valid_links && - params->link_id >= 0 && params->link_id == i && - params->chan == chanctx_conf->def.chan) - link_id = i; - - break; - } - - chanctx_conf = NULL; - } - - if (chanctx_conf) { - need_offchan = params->chan && - (params->chan != - chanctx_conf->def.chan); - } else { - need_offchan = true; - } - rcu_read_unlock(); + need_offchan = ieee80211_mgmt_tx_need_offchan(sdata, params, + mgmt, mlo_sta, + &link_id); } if (need_offchan && !params->offchan) { @@ -980,56 +1044,11 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, goto out_unlock; } - skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len); + skb = ieee80211_mgmt_tx_skb(sdata, params, cookie, GFP_KERNEL); if (!skb) { ret = -ENOMEM; goto out_unlock; } - skb_reserve(skb, local->hw.extra_tx_headroom); - - data = skb_put_data(skb, params->buf, params->len); - - /* Update CSA counters */ - if (sdata->vif.bss_conf.csa_active && - (sdata->vif.type == NL80211_IFTYPE_AP || - sdata->vif.type == NL80211_IFTYPE_MESH_POINT || - sdata->vif.type == NL80211_IFTYPE_ADHOC) && - params->n_csa_offsets) { - int i; - struct beacon_data *beacon = NULL; - - rcu_read_lock(); - - if (sdata->vif.type == NL80211_IFTYPE_AP) - beacon = rcu_dereference(sdata->deflink.u.ap.beacon); - else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) - beacon = rcu_dereference(sdata->u.ibss.presp); - else if (ieee80211_vif_is_mesh(&sdata->vif)) - beacon = rcu_dereference(sdata->u.mesh.beacon); - - if (beacon) - for (i = 0; i < params->n_csa_offsets; i++) - data[params->csa_offsets[i]] = - beacon->cntdwn_current_counter; - - rcu_read_unlock(); - } - - IEEE80211_SKB_CB(skb)->flags = flags; - IEEE80211_SKB_CB(skb)->control.flags |= IEEE80211_TX_CTRL_DONT_USE_RATE_MASK; - - skb->dev = sdata->dev; - - if (!params->dont_wait_for_ack) { - /* make a copy to preserve the frame contents - * in case of encryption. - */ - ret = ieee80211_attach_ack_skb(local, skb, &cookie, GFP_KERNEL); - if (ret) { - kfree_skb(skb); - goto out_unlock; - } - } if (!need_offchan) { ieee80211_tx_skb_tid(sdata, skb, From bd3f374d01561fcb4c28ec90b6bdd8c1a5239f94 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:09 +0200 Subject: [PATCH 1486/2126] wifi: mac80211: implement mgmt_tx_unlocked() Implement the mgmt_tx_unlocked() method and accept frames that are transmitted on the operating channel with it, as they don't need further handling and can go out directly. For off-channel etc. just return -EAGAIN to fall back to the locked version. Link: https://patch.msgid.link/20261009201417.6491f3bdeb4e.Ib10158e2729f89719b551dadb8384e89b9dce688@changeid Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 1 + net/mac80211/ieee80211_i.h | 3 + net/mac80211/offchannel.c | 109 +++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 30fe29f25928..daabac9fc6e6 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -6316,6 +6316,7 @@ const struct cfg80211_ops mac80211_config_ops = { .remain_on_channel = ieee80211_remain_on_channel, .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, .mgmt_tx = ieee80211_mgmt_tx, + .mgmt_tx_unlocked = ieee80211_mgmt_tx_unlocked, .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 16c1e0337f3a..bf9f26234662 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2192,6 +2192,9 @@ int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie); int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params, u64 cookie); +int ieee80211_mgmt_tx_unlocked(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, + u64 cookie); int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie); diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c index 27ca2984826f..44808120ff51 100644 --- a/net/mac80211/offchannel.c +++ b/net/mac80211/offchannel.c @@ -1074,6 +1074,115 @@ int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, return ret; } +int ieee80211_mgmt_tx_unlocked(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_mgmt_tx_params *params, + u64 cookie) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); + const struct ieee80211_mgmt *mgmt = (void *)params->buf; + struct ieee80211_local *local = sdata->local; + struct sta_info *sta = NULL; + enum nl80211_band band; + struct sk_buff *skb; + int link_id = -1, i; + + if (READ_ONCE(local->in_reconfig) || READ_ONCE(local->quiescing)) + return -EAGAIN; + + guard(rcu)(); + + /* do_stop() synchronizes RCU before the interface type can change */ + if (!ieee80211_sdata_running(sdata)) + return -EAGAIN; + + switch (sdata->vif.type) { + case NL80211_IFTYPE_NAN_DATA: + if (is_multicast_ether_addr(mgmt->da)) + return -EOPNOTSUPP; + fallthrough; + case NL80211_IFTYPE_NAN: + /* Frames can be sent during NAN schedule */ + skb = ieee80211_mgmt_tx_skb(sdata, params, cookie, GFP_ATOMIC); + if (!skb) + return -ENOMEM; + + __ieee80211_tx_skb_tid_band(sdata, skb, + params->no_sta ? ERR_PTR(-ENOENT) : + NULL, + 7, -1, NUM_NL80211_BANDS); + return 0; + case NL80211_IFTYPE_AP: + case NL80211_IFTYPE_P2P_GO: + if (sdata->bss->active) + break; + fallthrough; + default: + return -EAGAIN; + } + + if (!params->no_sta) + sta = sta_info_get_bss(sdata, mgmt->da); + + if (ieee80211_is_action(mgmt->frame_control) && + mgmt->u.action.category != WLAN_CATEGORY_PUBLIC && + mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED && + mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT) { + if (!sta) + return -ENOLINK; + if (params->link_id >= 0 && + !(sta->sta.valid_links & BIT(params->link_id))) + return -ENOLINK; + link_id = params->link_id; + } + + if ((params->chan || !sta || !sta->sta.mlo) && + ieee80211_mgmt_tx_need_offchan(sdata, params, mgmt, + sta && sta->sta.mlo, &link_id)) + return -EAGAIN; + + /* things may have changed, avoid WARNs in ieee80211_tx_skb_tid() */ + if (ieee80211_vif_is_mld(&sdata->vif)) { + band = 0; + + if (link_id < 0 && + !ether_addr_equal(sdata->vif.addr, mgmt->sa)) { + for (i = 0; i < ARRAY_SIZE(sdata->vif.link_conf); i++) { + struct ieee80211_bss_conf *conf; + + conf = rcu_dereference(sdata->vif.link_conf[i]); + if (conf && + ether_addr_equal(conf->addr, mgmt->sa)) { + link_id = i; + break; + } + } + if (link_id < 0) + return -EAGAIN; + } + + if (link_id >= 0 && + !(READ_ONCE(sdata->vif.active_links) & BIT(link_id))) + return -EAGAIN; + } else { + struct ieee80211_chanctx_conf *chanctx_conf; + + chanctx_conf = + rcu_dereference(sdata->vif.bss_conf.chanctx_conf); + if (!chanctx_conf) + return -EAGAIN; + band = chanctx_conf->def.chan->band; + } + + skb = ieee80211_mgmt_tx_skb(sdata, params, cookie, GFP_ATOMIC); + if (!skb) + return -ENOMEM; + + __ieee80211_tx_skb_tid_band(sdata, skb, + params->no_sta ? ERR_PTR(-ENOENT) : sta, + 7, link_id, band); + return 0; +} + int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, struct wireless_dev *wdev, u64 cookie) { From 223a1e289be0a4a1ef690020393e976dbfc10a1a Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:10 +0200 Subject: [PATCH 1487/2126] wifi: mac80211: don't require wiphy mutex for probe_peer The comment about wiphy mutex is stale since the cookie cleanup, and everything else can be under RCU, we just have to drop the warning in case it races AP stop. Link: https://patch.msgid.link/20261009201417.4501c07ff31e.Ic87a72afcaea6b9a8c92f7f063bf33a2744a7992@changeid Signed-off-by: Johannes Berg --- net/mac80211/cfg.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index daabac9fc6e6..0acbb2415a02 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -5223,11 +5223,17 @@ static int ieee80211_probe_peer(struct wiphy *wiphy, struct net_device *dev, int size; int ret; - /* the lock is needed to assign the cookie later */ - lockdep_assert_wiphy(local->hw.wiphy); + guard(rcu)(); + + /* do_stop() synchronizes RCU before the interface type can change */ + if (!ieee80211_sdata_running(sdata)) + return -ENETDOWN; switch (ieee80211_vif_type_p2p(&sdata->vif)) { case NL80211_IFTYPE_AP: + /* NULL if the interface was a station when checked */ + if (!peer) + return -EINVAL; fromds = true; break; case NL80211_IFTYPE_STATION: @@ -5253,8 +5259,7 @@ static int ieee80211_probe_peer(struct wiphy *wiphy, struct net_device *dev, * per-link address for the client's link. */ link_id = sta->deflink.link_id; - conf = wiphy_dereference(local->hw.wiphy, - sdata->vif.link_conf[link_id]); + conf = rcu_dereference(sdata->vif.link_conf[link_id]); if (!conf) return -ENOLINK; src_addr = conf->addr; @@ -5269,9 +5274,8 @@ static int ieee80211_probe_peer(struct wiphy *wiphy, struct net_device *dev, /* MLD transmissions must not rely on the band */ band = 0; } else { - chanctx_conf = wiphy_dereference(local->hw.wiphy, - sdata->vif.bss_conf.chanctx_conf); - if (WARN_ON(!chanctx_conf)) + chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); + if (!chanctx_conf) return -EINVAL; band = chanctx_conf->def.chan->band; link_id = 0; @@ -5318,9 +5322,7 @@ static int ieee80211_probe_peer(struct wiphy *wiphy, struct net_device *dev, } local_bh_disable(); - rcu_read_lock(); ieee80211_xmit(sdata, sta, skb); - rcu_read_unlock(); local_bh_enable(); return 0; From 062de592d0fe966777cec20cb608a3a4706ec4f6 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:11 +0200 Subject: [PATCH 1488/2126] wifi: nl80211: probe peers without wiphy mutex None of the drivers implementing probe_peer (mac80211, wil6210, nxpwifi) need the wiphy mutex for it, so we can just not take it. Document that as well. Link: https://patch.msgid.link/20261009201417.75233ff945c8.I2f462bfffa96feb8dcc4386bc35ebc25d877a92f@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 5 ++++- net/wireless/nl80211.c | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 0eee48bdc937..32b458c9a7ee 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5149,7 +5149,10 @@ struct mgmt_frame_regs { * * @probe_peer: probe a connected peer (AP: STA MAC required; STA: no MAC), * must use the @cookie as provided which is later passed to - * cfg80211_probe_status(). + * cfg80211_probe_status(). Called without the wiphy mutex, so the + * interface type may have changed/be changing and the MAC may be + * %NULL even in AP mode (if runtime type changes are supported), + * drivers must check for that. * * @set_noack_map: Set the NoAck Map for the TIDs. * diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 7cb3bb9438d7..b4ff8c811dc1 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -20835,7 +20835,8 @@ static const struct genl_small_ops nl80211_small_ops[] = { .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = nl80211_probe_peer, .flags = GENL_UNS_ADMIN_PERM, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | + NL80211_FLAG_NO_WIPHY_MTX), }, { .cmd = NL80211_CMD_REGISTER_BEACONS, From 5b8528cb74fc5a0bf57f5b3f6a83edb243b43ac3 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:12 +0200 Subject: [PATCH 1489/2126] wifi: mac80211: don't require wiphy mutex for control port TX The wiphy mutex was only required for the cookie counter, but that's been in cfg80211 for a while. The rest is just datapath, so can work under RCU, just need to be careful to handle interface type changes. Link: https://patch.msgid.link/20261009201417.dffb8da303aa.Ica8bba30018704a7c776f2ef08e6f2571cd8f8c4@changeid Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 4b0ffd0a6ac7..ef97d6d3bdcd 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -6640,9 +6640,6 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, u32 flags = 0; int err; - /* mutex lock is only needed for incrementing the cookie counter */ - lockdep_assert_wiphy(local->hw.wiphy); - /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE * or Pre-Authentication */ @@ -6701,6 +6698,14 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, * AF_PACKET */ rcu_read_lock(); + + /* do_stop() synchronizes RCU before the interface type can change */ + if (!ieee80211_sdata_running(sdata)) { + dev_kfree_skb(skb); + rcu_read_unlock(); + return -ENETDOWN; + } + err = ieee80211_lookup_ra_sta(sdata, skb, &sta, true); if (err) { dev_kfree_skb(skb); From 1b6713fe8fad3871d2a090cfccba9b319a19dc77 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:13 +0200 Subject: [PATCH 1490/2126] wifi: nl80211: transmit control port frames without wiphy mutex Only mac80211 currently implements tx_control_port, and it no longer needs the wiphy mutex, so don't take it here. Link: https://patch.msgid.link/20261009201417.d89a3bc2b1ec.I30d12968a0d4ab7a4ac8d0995a9ab7583b0ce2ef@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 1 + net/wireless/nl80211.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 32b458c9a7ee..3fa310b30139 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5271,6 +5271,7 @@ struct mgmt_frame_regs { * @tx_control_port: TX a control port frame (EAPoL). The noencrypt parameter * tells the driver that the frame should not be encrypted. A @cookie * value of 0 means the caller does not want TX status reporting. + * Called without the wiphy mutex. * * @get_ftm_responder_stats: Retrieve FTM responder statistics, if available. * Statistics should be cumulative, currently no way to reset is provided. diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index b4ff8c811dc1..4044ea7d344a 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -21070,7 +21070,8 @@ static const struct genl_small_ops nl80211_small_ops[] = { .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = nl80211_tx_control_port, .flags = GENL_UNS_ADMIN_PERM, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | + NL80211_FLAG_NO_WIPHY_MTX), }, { .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, From 599b8a3c549b2dd3277502263ee1b69bf3489f3d Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:14 +0200 Subject: [PATCH 1491/2126] wifi: cfg80211: support unlocked station get/dump Qualcomm reported that there can be a lot of lock contention on the wiphy mutex due to background processes dumping the station statistics. In many drivers (e.g. all mac80211 drivers without their own station statistics) it doesn't need to be locked, the data is never guaranteed to be fully consistent anyway given it's collected by concurrent TX/RX. Support unlocked get/dump station methods so that drivers can reduce lock contention by implementing these methods. As in the other cases, it's allowed to return -EAGAIN if a locked call is needed. Link: https://patch.msgid.link/20261009201417.e1d8a7d5f513.I9f6c2aff55861332c15069b9189bbf1e653648d5@changeid Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 14 +++ net/wireless/nl80211.c | 201 ++++++++++++++++++++++++++++++++-------- net/wireless/rdev-ops.h | 27 ++++++ net/wireless/trace.h | 19 +++- 4 files changed, 219 insertions(+), 42 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 3fa310b30139..f773856c1818 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4963,7 +4963,13 @@ struct mgmt_frame_regs { * them, also against the existing state! Drivers must call * cfg80211_check_station_change() to validate the information. * @get_station: get station information for the station identified by @mac + * @get_station_unlocked: Like @get_station, but called without the wiphy + * mutex. Return -EAGAIN to get @get_station called with the wiphy mutex + * held instead. * @dump_station: dump station callback -- resume dump at index @idx + * @dump_station_unlocked: Like @dump_station, but called without the wiphy + * mutex. Return -EAGAIN to get @dump_station called with the wiphy mutex + * held instead. * * @add_mpath: add a fixed mesh path * @del_mpath: delete a given mesh path @@ -5395,8 +5401,16 @@ struct cfg80211_ops { struct station_parameters *params); int (*get_station)(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *mac, struct station_info *sinfo); + int (*get_station_unlocked)(struct wiphy *wiphy, + struct wireless_dev *wdev, + const u8 *mac, + struct station_info *sinfo); int (*dump_station)(struct wiphy *wiphy, struct wireless_dev *wdev, int idx, u8 *mac, struct station_info *sinfo); + int (*dump_station_unlocked)(struct wiphy *wiphy, + struct wireless_dev *wdev, + int idx, u8 *mac, + struct station_info *sinfo); int (*add_mpath)(struct wiphy *wiphy, struct net_device *dev, const u8 *dst, const u8 *next_hop); diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 4044ea7d344a..948113050b50 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -266,23 +266,51 @@ nl80211_lock_and_recheck(struct cfg80211_registered_device *rdev, return ERR_PTR(-ENODEV); } +/* like nl80211_lock_and_recheck() but under RCU, for wdev_hold() */ +static struct wireless_dev * +nl80211_wdev_by_id_rcu(struct cfg80211_registered_device *rdev, + struct net *netns, u32 wdev_id) +{ + struct wireless_dev *wdev; + + if (!net_eq(wiphy_net(&rdev->wiphy), netns)) + return NULL; + + list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->identifier != wdev_id) + continue; + if (wdev->netdev && !net_eq(dev_net(wdev->netdev), netns)) + return NULL; + return wdev; + } + + return NULL; +} + /* * Must have wdev_hold(), acquire the wiphy mutex. This has to * look up the wdev again (otherwise it could deadlock against * wdev removal), so it can return an error pointer. */ static struct wireless_dev * -nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, - struct genl_info *info, struct wireless_dev *wdev) +__nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, + struct net *netns, struct wireless_dev *wdev) { u32 wdev_id = wdev->identifier; /* the wdev reference was keeping the wiphy alive */ get_device(&rdev->wiphy.dev); - info->user_ptr[1] = NULL; wdev_put(wdev); - wdev = nl80211_lock_and_recheck(rdev, genl_info_net(info), wdev_id); + return nl80211_lock_and_recheck(rdev, netns, wdev_id); +} + +static struct wireless_dev * +nl80211_lock_held_wdev(struct cfg80211_registered_device *rdev, + struct genl_info *info, struct wireless_dev *wdev) +{ + info->user_ptr[1] = NULL; + wdev = __nl80211_lock_held_wdev(rdev, genl_info_net(info), wdev); if (IS_ERR(wdev)) return wdev; @@ -1326,10 +1354,10 @@ nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, }; -static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, - struct cfg80211_registered_device **rdev, - struct wireless_dev **wdev, - struct nlattr **attrbuf) +static int __nl80211_prepare_wdev_dump(struct netlink_callback *cb, + struct cfg80211_registered_device **rdev, + struct wireless_dev **wdev, + struct nlattr **attrbuf, bool lock) { struct net *netns = sock_net(cb->skb->sk); u32 wdev_id; @@ -1374,13 +1402,22 @@ static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, wdev_id = cb->args[1]; } - get_device(&(*rdev)->wiphy.dev); - rcu_read_unlock(); + if (!lock) { + *wdev = nl80211_wdev_by_id_rcu(*rdev, netns, wdev_id); + if (*wdev) + wdev_hold(*wdev); + rcu_read_unlock(); + if (!*wdev) + return -ENODEV; + } else { + get_device(&(*rdev)->wiphy.dev); + rcu_read_unlock(); - /* things may have changed since the lookup or the last dumpit call */ - *wdev = nl80211_lock_and_recheck(*rdev, netns, wdev_id); - if (IS_ERR(*wdev)) - return PTR_ERR(*wdev); + /* things may have changed since the lookup or last dumpit */ + *wdev = nl80211_lock_and_recheck(*rdev, netns, wdev_id); + if (IS_ERR(*wdev)) + return PTR_ERR(*wdev); + } /* 0 is the first index - add 1 to parse only once */ cb->args[0] = (*rdev)->wiphy_idx + 1; @@ -1389,6 +1426,14 @@ static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, return 0; } +static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, + struct cfg80211_registered_device **rdev, + struct wireless_dev **wdev, + struct nlattr **attrbuf) +{ + return __nl80211_prepare_wdev_dump(cb, rdev, wdev, attrbuf, true); +} + /* message building helper */ void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, int flags, u8 cmd) @@ -8843,13 +8888,46 @@ nla_put_failure: return -EMSGSIZE; } +static int nl80211_fill_station_info(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct nl80211_dump_station_ctx *ctx, + bool locked) +{ + int err; + + if (!ctx->filter_mac) { + if (locked) + return rdev_dump_station(rdev, wdev, ctx->sta_idx, + ctx->mac_addr, &ctx->sinfo); + if (!rdev->ops->dump_station_unlocked) + return -EAGAIN; + return rdev_dump_station_unlocked(rdev, wdev, ctx->sta_idx, + ctx->mac_addr, &ctx->sinfo); + } + + if (locked) + err = rdev_get_station(rdev, wdev, ctx->filter_mac_addr, + &ctx->sinfo); + else if (rdev->ops->get_station_unlocked) + err = rdev_get_station_unlocked(rdev, wdev, ctx->filter_mac_addr, + &ctx->sinfo); + else + return -EAGAIN; + + if (!err) + memcpy(ctx->mac_addr, ctx->filter_mac_addr, ETH_ALEN); + return err; +} + static int nl80211_dump_station(struct sk_buff *skb, struct netlink_callback *cb) { struct cfg80211_registered_device *rdev; struct wireless_dev *wdev; struct nl80211_dump_station_ctx *ctx = (void *)cb->args[2]; + struct net *netns = sock_net(cb->skb->sk); struct nlattr **attrbuf __free(kfree) = NULL; + bool locked = false; int err; if (!ctx) { @@ -8858,11 +8936,9 @@ static int nl80211_dump_station(struct sk_buff *skb, return -ENOMEM; } - err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf); + err = __nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf, false); if (err) return err; - /* nl80211_prepare_wdev_dump acquired it in the successful case */ - __acquire(&rdev->wiphy.mtx); if (!ctx) { ctx = kzalloc_obj(*ctx); @@ -8919,21 +8995,28 @@ static int nl80211_dump_station(struct sk_buff *skb, } } - if (ctx->filter_mac) { - if (ctx->sta_idx > 0) { - err = skb->len; - goto out_err_release; + if (ctx->filter_mac && ctx->sta_idx > 0) { + err = skb->len; + goto out_err_release; + } + + err = nl80211_fill_station_info(rdev, wdev, ctx, + locked); + if (err == -EAGAIN && !locked) { + cfg80211_sinfo_release_content(&ctx->sinfo); + memset(&ctx->sinfo, 0, sizeof(ctx->sinfo)); + + /* this fails if the wdev is being removed */ + wdev = __nl80211_lock_held_wdev(rdev, netns, + wdev); + if (IS_ERR(wdev)) { + err = PTR_ERR(wdev); + goto out_err; } - err = rdev_get_station(rdev, wdev, - ctx->filter_mac_addr, - &ctx->sinfo); - if (!err) - memcpy(ctx->mac_addr, - ctx->filter_mac_addr, ETH_ALEN); - } else { - err = rdev_dump_station(rdev, wdev, ctx->sta_idx, - ctx->mac_addr, - &ctx->sinfo); + + /* try again locked now */ + locked = true; + continue; } if (err == -ENOENT) { err = skb->len; @@ -9028,7 +9111,10 @@ out_err_release: cfg80211_sinfo_release_content(&ctx->sinfo); memset(&ctx->sinfo, 0, sizeof(ctx->sinfo)); out_err: - wiphy_unlock(&rdev->wiphy); + if (locked) + wiphy_unlock(&rdev->wiphy); + else if (wdev) + wdev_put(wdev); return err; } @@ -9049,6 +9135,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) struct cfg80211_registered_device *rdev = info->user_ptr[0]; struct wireless_dev *wdev = info->user_ptr[1]; struct station_info sinfo; + bool locked = false; struct sk_buff *msg; u8 *mac_addr = NULL; int err, i; @@ -9074,26 +9161,54 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) } } - err = rdev_get_station(rdev, wdev, mac_addr, &sinfo); - if (err) { - cfg80211_sinfo_release_content(&sinfo); - return err; - } - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { cfg80211_sinfo_release_content(&sinfo); return -ENOMEM; } + err = -EAGAIN; + if (rdev->ops->get_station_unlocked) { + err = rdev_get_station_unlocked(rdev, wdev, mac_addr, &sinfo); + + if (err == -EAGAIN) { + cfg80211_sinfo_release_content(&sinfo); + memset(&sinfo, 0, sizeof(sinfo)); + } + } + + if (err == -EAGAIN) { + /* the wdev pointer is only valid until unlocking after this */ + info->user_ptr[1] = NULL; + /* can fail if the wdev is being removed */ + wdev = __nl80211_lock_held_wdev(rdev, genl_info_net(info), + wdev); + if (IS_ERR(wdev)) { + err = PTR_ERR(wdev); + } else { + locked = true; + err = rdev_get_station(rdev, wdev, mac_addr, &sinfo); + } + } + + if (err) { + cfg80211_sinfo_release_content(&sinfo); + goto out; + } + if (sinfo.valid_links) cfg80211_sta_set_mld_sinfo(&sinfo); if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, info->snd_portid, info->snd_seq, 0, - rdev, wdev, mac_addr, &sinfo) < 0) { + rdev, wdev, mac_addr, &sinfo) < 0) + err = -ENOBUFS; +out: + if (locked) + wiphy_unlock(&rdev->wiphy); + if (err) { nlmsg_free(msg); - return -ENOBUFS; + return err; } return genlmsg_reply(msg, info); @@ -19894,6 +20009,9 @@ nl80211_epcs_cfg(struct sk_buff *skb, struct genl_info *info) NL80211_FLAG_NEED_WIPHY) \ SELECTOR(__sel, WDEV, \ NL80211_FLAG_NEED_WDEV) \ + SELECTOR(__sel, WDEV_NOMTX, \ + NL80211_FLAG_NEED_WDEV | \ + NL80211_FLAG_NO_WIPHY_MTX) \ SELECTOR(__sel, NETDEV, \ NL80211_FLAG_NEED_NETDEV) \ SELECTOR(__sel, NETDEV_LINK, \ @@ -20323,7 +20441,8 @@ static const struct genl_ops nl80211_ops[] = { .doit = nl80211_get_station, .dumpit = nl80211_dump_station, .done = nl80211_dump_station_done, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | + NL80211_FLAG_NO_WIPHY_MTX), }, }; diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 5502cd947844..ae15cec9bf8b 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -248,6 +248,19 @@ static inline int rdev_get_station(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_get_station_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, const u8 *mac, + struct station_info *sinfo) +{ + int ret; + + trace_rdev_get_station_unlocked(&rdev->wiphy, wdev, mac); + ret = rdev->ops->get_station_unlocked(&rdev->wiphy, wdev, mac, sinfo); + trace_rdev_return_int_station_info(&rdev->wiphy, ret, sinfo); + return ret; +} + static inline int rdev_dump_station(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, int idx, u8 *mac, struct station_info *sinfo) @@ -259,6 +272,20 @@ static inline int rdev_dump_station(struct cfg80211_registered_device *rdev, return ret; } +static inline int +rdev_dump_station_unlocked(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, int idx, u8 *mac, + struct station_info *sinfo) +{ + int ret; + + trace_rdev_dump_station_unlocked(&rdev->wiphy, wdev, idx, mac); + ret = rdev->ops->dump_station_unlocked(&rdev->wiphy, wdev, idx, mac, + sinfo); + trace_rdev_return_int_station_info(&rdev->wiphy, ret, sinfo); + return ret; +} + static inline int rdev_add_mpath(struct cfg80211_registered_device *rdev, struct net_device *dev, u8 *dst, u8 *next_hop) { diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 1f3c1e0eb26a..31000ffebe43 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -1056,12 +1056,17 @@ DEFINE_EVENT(wiphy_wdev_mac_evt, rdev_get_station, TP_ARGS(wiphy, wdev, mac) ); +DEFINE_EVENT(wiphy_wdev_mac_evt, rdev_get_station_unlocked, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *mac), + TP_ARGS(wiphy, wdev, mac) +); + DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_del_mpath, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, const u8 *mac), TP_ARGS(wiphy, netdev, mac) ); -TRACE_EVENT(rdev_dump_station, +DECLARE_EVENT_CLASS(rdev_dump_station_evt, TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int _idx, u8 *mac), TP_ARGS(wiphy, wdev, _idx, mac), @@ -1082,6 +1087,18 @@ TRACE_EVENT(rdev_dump_station, __entry->idx) ); +DEFINE_EVENT(rdev_dump_station_evt, rdev_dump_station, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int _idx, + u8 *mac), + TP_ARGS(wiphy, wdev, _idx, mac) +); + +DEFINE_EVENT(rdev_dump_station_evt, rdev_dump_station_unlocked, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, int _idx, + u8 *mac), + TP_ARGS(wiphy, wdev, _idx, mac) +); + TRACE_EVENT(rdev_return_int_station_info, TP_PROTO(struct wiphy *wiphy, int ret, struct station_info *sinfo), TP_ARGS(wiphy, ret, sinfo), From 6f7f0be670dedad757742b9befd36307989e5b4a Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:15 +0200 Subject: [PATCH 1492/2126] wifi: mac80211: refactor station statistics Refactor the code a bit to pass around link-STA pointers instead of looking them up again and again. This will simplify the next changes, since otherwise all of these lookups would have to be converted to RCU-safe ones. It also simplifies the code generally. Link: https://patch.msgid.link/20261009201417.32dfeaa3c44d.I7ea45bf80dd493311670f8fdd018b5c4b770a4be@changeid Signed-off-by: Johannes Berg --- net/mac80211/sta_info.c | 87 ++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index 9252aaa39895..d761847b70b3 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2547,20 +2547,11 @@ void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local, } static struct ieee80211_sta_rx_stats * -sta_get_last_rx_stats(struct sta_info *sta, int link_id) +sta_get_last_rx_stats(struct link_sta_info *link_sta_info) { - struct ieee80211_sta_rx_stats *stats; - struct link_sta_info *link_sta_info; + struct ieee80211_sta_rx_stats *stats = &link_sta_info->rx_stats; int cpu; - if (link_id < 0) - link_sta_info = &sta->deflink; - else - link_sta_info = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); - - stats = &link_sta_info->rx_stats; - if (!link_sta_info->pcpu_rx_stats) return stats; @@ -2576,6 +2567,19 @@ sta_get_last_rx_stats(struct sta_info *sta, int link_id) return stats; } +static unsigned long sta_link_last_active(struct link_sta_info *link_sta_info) +{ + struct ieee80211_sta_rx_stats *stats; + + stats = sta_get_last_rx_stats(link_sta_info); + + if (!link_sta_info->status_stats.last_ack || + time_after(stats->last_rx, link_sta_info->status_stats.last_ack)) + return stats->last_rx; + + return link_sta_info->status_stats.last_ack; +} + static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate, struct rate_info *rinfo) { @@ -2653,10 +2657,11 @@ static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate, } } -static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo, - int link_id) +static int sta_set_rate_info_rx(struct sta_info *sta, + struct link_sta_info *link_sta_info, + struct rate_info *rinfo) { - u32 rate = READ_ONCE(sta_get_last_rx_stats(sta, link_id)->last_rate); + u32 rate = READ_ONCE(sta_get_last_rx_stats(link_sta_info)->last_rate); if (rate == STA_STATS_RATE_INVALID) return -EINVAL; @@ -2680,19 +2685,13 @@ static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats, } static void sta_set_tidstats(struct sta_info *sta, + struct link_sta_info *link_sta_info, struct cfg80211_tid_stats *tidstats, - int tid, int link_id) + int tid, bool txq_stats) { struct ieee80211_local *local = sta->local; - struct link_sta_info *link_sta_info; int cpu; - if (link_id < 0) - link_sta_info = &sta->deflink; - else - link_sta_info = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); - if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) { tidstats->rx_msdu += sta_get_tidstats_msdu(&link_sta_info->rx_stats, @@ -2731,7 +2730,7 @@ static void sta_set_tidstats(struct sta_info *sta, link_sta_info->status_stats.msdu_failed[tid]; } - if (link_id < 0 && tid < IEEE80211_NUM_TIDS) { + if (txq_stats && tid < IEEE80211_NUM_TIDS) { spin_lock_bh(&local->fq.lock); tidstats->filled |= BIT(NL80211_TID_STATS_TXQ_STATS); @@ -2837,20 +2836,17 @@ static u32 sta_estimate_expected_throughput(struct sta_info *sta, } static void sta_set_link_sinfo(struct sta_info *sta, + struct link_sta_info *link_sta_info, struct link_station_info *link_sinfo, struct ieee80211_link_data *link, bool tidstats) { struct ieee80211_sub_if_data *sdata = sta->sdata; struct ieee80211_sta_rx_stats *last_rxstats; - int i, ac, cpu, link_id = link->link_id; - struct link_sta_info *link_sta_info; + int i, ac, cpu; u32 thr = 0; - last_rxstats = sta_get_last_rx_stats(sta, link_id); - - link_sta_info = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); + last_rxstats = sta_get_last_rx_stats(link_sta_info); /* do before driver, so beacon filtering drivers have a * chance to e.g. just add the number of filtered beacons @@ -2876,8 +2872,7 @@ static void sta_set_link_sinfo(struct sta_info *sta, link_sinfo->inactive_time = jiffies_delta_to_msecs(jiffies - - ieee80211_sta_last_active(sta, - link_id)); + sta_link_last_active(link_sta_info)); if (!(link_sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) | BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) { @@ -3025,8 +3020,8 @@ static void sta_set_link_sinfo(struct sta_info *sta, } if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))) { - if (sta_set_rate_info_rx(sta, &link_sinfo->rxrate, - link_id) == 0) + if (sta_set_rate_info_rx(sta, link_sta_info, + &link_sinfo->rxrate) == 0) link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE); } @@ -3034,8 +3029,8 @@ static void sta_set_link_sinfo(struct sta_info *sta, if (tidstats && !cfg80211_link_sinfo_alloc_tid_stats(link_sinfo, GFP_KERNEL)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) - sta_set_tidstats(sta, &link_sinfo->pertid[i], i, - link_id); + sta_set_tidstats(sta, link_sta_info, + &link_sinfo->pertid[i], i, false); } if (sdata->vif.type == NL80211_IFTYPE_STATION) { @@ -3091,7 +3086,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, int i, ac, cpu; struct ieee80211_sta_rx_stats *last_rxstats; - last_rxstats = sta_get_last_rx_stats(sta, -1); + last_rxstats = sta_get_last_rx_stats(&sta->deflink); sinfo->generation = sdata->local->sta_generation; @@ -3119,7 +3114,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->assoc_at = sta->assoc_at; sinfo->inactive_time = jiffies_delta_to_msecs(jiffies - - ieee80211_sta_last_active(sta, -1)); + sta_link_last_active(&sta->deflink)); if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) | BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) { @@ -3258,13 +3253,15 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) && !sta->sta.valid_links) { - if (sta_set_rate_info_rx(sta, &sinfo->rxrate, -1) == 0) + if (sta_set_rate_info_rx(sta, &sta->deflink, + &sinfo->rxrate) == 0) sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE); } if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) - sta_set_tidstats(sta, &sinfo->pertid[i], i, -1); + sta_set_tidstats(sta, &sta->deflink, + &sinfo->pertid[i], i, true); } #ifdef CONFIG_MAC80211_MESH @@ -3367,7 +3364,8 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->valid_links &= ~BIT(link_id); continue; } - sta_set_link_sinfo(sta, link_sinfo, link, tidstats); + sta_set_link_sinfo(sta, link_sta, link_sinfo, link, + tidstats); if (!thr && (link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT))) est_thr += link_sinfo->expected_throughput; @@ -3400,22 +3398,15 @@ u32 sta_get_expected_throughput(struct sta_info *sta) unsigned long ieee80211_sta_last_active(struct sta_info *sta, int link_id) { - struct ieee80211_sta_rx_stats *stats; struct link_sta_info *link_sta_info; - stats = sta_get_last_rx_stats(sta, link_id); - if (link_id < 0) link_sta_info = &sta->deflink; else link_sta_info = wiphy_dereference(sta->local->hw.wiphy, sta->link[link_id]); - if (!link_sta_info->status_stats.last_ack || - time_after(stats->last_rx, link_sta_info->status_stats.last_ack)) - return stats->last_rx; - - return link_sta_info->status_stats.last_ack; + return sta_link_last_active(link_sta_info); } int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id) From ab5d6dd9c9b0b9ce40d687a79e62314a9f8cafbf Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 9 Oct 2026 20:10:16 +0200 Subject: [PATCH 1493/2126] wifi: mac80211: implement unlocked STA statistics Implement the new cfg80211 unlocked STA statistics. If the driver has an operation, then we need to always do the locked again, so return -EAGAIN unconditionally if it has a locked but not atomic operation, but drivers can implement the new atomic methods to provide needed data atomically (and can also return -EAGAIN). This should, given a driver without any ops or adding the atomic ops, reduce wiphy mutex contention. Link: https://patch.msgid.link/20261009201417.706683ff9d81.Ieb92e4c6599a198a116fa6a4f7944219c6d32932@changeid Signed-off-by: Johannes Berg --- include/net/mac80211.h | 18 ++++++ net/mac80211/cfg.c | 120 ++++++++++++++++++++++++++++---------- net/mac80211/driver-ops.c | 76 ++++++++++++++++++++++++ net/mac80211/driver-ops.h | 46 ++++----------- net/mac80211/sta_info.c | 54 ++++++++++------- net/mac80211/sta_info.h | 10 +++- 6 files changed, 233 insertions(+), 91 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 2a61079e3975..a1a6409b44c1 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -4369,6 +4369,13 @@ struct ieee80211_prep_tx_info { * Statistics that the driver doesn't fill will be filled by mac80211. * The callback can sleep. * + * @sta_statistics_atomic: Like @sta_statistics, but called under RCU, so it + * must be atomic. This is called instead of @sta_statistics if available, + * but may return -EAGAIN to fall back to @sta_statistics with the wiphy + * mutex held. + * Note that it's not guaranteed this will always be called first, some + * (internal) calls may call @sta_statistics directly. + * * @link_sta_statistics: Get link statistics for this station. For example with * beacon filtering, the statistics kept by mac80211 might not be * accurate, so let the driver pre-fill the statistics. The driver can @@ -4378,6 +4385,9 @@ struct ieee80211_prep_tx_info { * Statistics that the driver doesn't fill will be filled by mac80211. * The callback can sleep. * + * @link_sta_statistics_atomic: Like @link_sta_statistics, with the same + * locking/retry semantics as @sta_statistics_atomic. Must be atomic. + * * @conf_tx: Configure TX queue parameters (EDCF (aifs, cw_min, cw_max), * bursting) for a hardware TX queue. * Returns a negative error code on failure. @@ -4883,6 +4893,10 @@ struct ieee80211_ops { struct ieee80211_vif *vif, struct ieee80211_sta *sta, struct station_info *sinfo); + int (*sta_statistics_atomic)(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct station_info *sinfo); int (*conf_tx)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, unsigned int link_id, u16 ac, @@ -4898,6 +4912,10 @@ struct ieee80211_ops { struct ieee80211_vif *vif, struct ieee80211_link_sta *link_sta, struct link_station_info *link_sinfo); + int (*link_sta_statistics_atomic)(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo); /** * @ampdu_action: diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 0acbb2415a02..9608c07bcea7 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1018,31 +1018,63 @@ void sta_set_rate_info_tx(struct sta_info *sta, rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; } +static int __ieee80211_dump_station(struct ieee80211_sub_if_data *sdata, + int idx, u8 *mac, + struct station_info *sinfo, bool locked) +{ + struct sta_info *sta; + int ret; + + sta = sta_info_get_by_idx(sdata, idx); + if (!sta) + return -ENOENT; + + memcpy(mac, sta->sta.addr, ETH_ALEN); + ret = __sta_set_sinfo(sta, sinfo, true, locked); + if (ret) + return ret; + + /* + * Add accumulated removed link data to sinfo data for + * consistency for MLO + */ + if (sinfo->valid_links) + sta_set_accumulated_removed_links_sinfo(sta, sinfo); + + return 0; +} + static int ieee80211_dump_station(struct wiphy *wiphy, struct wireless_dev *wdev, int idx, u8 *mac, struct station_info *sinfo) { struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); - struct ieee80211_local *local = sdata->local; - struct sta_info *sta; - int ret = -ENOENT; - lockdep_assert_wiphy(local->hw.wiphy); + lockdep_assert_wiphy(sdata->local->hw.wiphy); - sta = sta_info_get_by_idx(sdata, idx); - if (sta) { - ret = 0; - memcpy(mac, sta->sta.addr, ETH_ALEN); - sta_set_sinfo(sta, sinfo, true); + return __ieee80211_dump_station(sdata, idx, mac, sinfo, true); +} - /* Add accumulated removed link data to sinfo data for - * consistency for MLO - */ - if (sinfo->valid_links) - sta_set_accumulated_removed_links_sinfo(sta, sinfo); +/* driver must have atomic ops (or none), otherwise we need the mutex */ +static bool ieee80211_sta_stats_need_mtx(struct ieee80211_local *local) +{ + const struct ieee80211_ops *ops = local->ops; - } + return (ops->sta_statistics && !ops->sta_statistics_atomic) || + (ops->link_sta_statistics && !ops->link_sta_statistics_atomic); +} - return ret; +static int ieee80211_dump_station_unlocked(struct wiphy *wiphy, + struct wireless_dev *wdev, + int idx, u8 *mac, + struct station_info *sinfo) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); + + if (ieee80211_sta_stats_need_mtx(sdata->local)) + return -EAGAIN; + + guard(rcu)(); + return __ieee80211_dump_station(sdata, idx, mac, sinfo, false); } static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, @@ -1053,30 +1085,54 @@ static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, return drv_get_survey(local, idx, survey); } +static int __ieee80211_get_station(struct ieee80211_sub_if_data *sdata, + const u8 *mac, struct station_info *sinfo, + bool locked) +{ + struct sta_info *sta; + int ret; + + sta = sta_info_get_bss(sdata, mac); + if (!sta) + return -ENOENT; + + ret = __sta_set_sinfo(sta, sinfo, true, locked); + if (ret) + return ret; + + /* + * Add accumulated removed link data to sinfo data for + * consistency for MLO + */ + if (sinfo->valid_links) + sta_set_accumulated_removed_links_sinfo(sta, sinfo); + + return 0; +} + static int ieee80211_get_station(struct wiphy *wiphy, struct wireless_dev *wdev, const u8 *mac, struct station_info *sinfo) { struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); - struct ieee80211_local *local = sdata->local; - struct sta_info *sta; - int ret = -ENOENT; - lockdep_assert_wiphy(local->hw.wiphy); + lockdep_assert_wiphy(sdata->local->hw.wiphy); - sta = sta_info_get_bss(sdata, mac); - if (sta) { - ret = 0; - sta_set_sinfo(sta, sinfo, true); + return __ieee80211_get_station(sdata, mac, sinfo, true); +} - /* Add accumulated removed link data to sinfo data for - * consistency for MLO - */ - if (sinfo->valid_links) - sta_set_accumulated_removed_links_sinfo(sta, sinfo); - } +static int ieee80211_get_station_unlocked(struct wiphy *wiphy, + struct wireless_dev *wdev, + const u8 *mac, + struct station_info *sinfo) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); - return ret; + if (ieee80211_sta_stats_need_mtx(sdata->local)) + return -EAGAIN; + + guard(rcu)(); + return __ieee80211_get_station(sdata, mac, sinfo, false); } static int ieee80211_set_monitor_channel(struct wiphy *wiphy, @@ -6273,7 +6329,9 @@ const struct cfg80211_ops mac80211_config_ops = { .del_station = ieee80211_del_station, .change_station = ieee80211_change_station, .get_station = ieee80211_get_station, + .get_station_unlocked = ieee80211_get_station_unlocked, .dump_station = ieee80211_dump_station, + .dump_station_unlocked = ieee80211_dump_station_unlocked, .dump_survey = ieee80211_dump_survey, #ifdef CONFIG_MAC80211_MESH .add_mpath = ieee80211_add_mpath, diff --git a/net/mac80211/driver-ops.c b/net/mac80211/driver-ops.c index 49753b73aba2..1f3e0765a8ab 100644 --- a/net/mac80211/driver-ops.c +++ b/net/mac80211/driver-ops.c @@ -633,3 +633,79 @@ int drv_change_sta_links(struct ieee80211_local *local, return 0; } + +int drv_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, + struct station_info *sinfo, + bool locked) +{ + int ret; + + sdata = get_bss_sdata(sdata); + if (!check_sdata_in_driver(sdata)) + return 0; + + trace_drv_sta_statistics(local, sdata, sta); + + if (locked) { + might_sleep(); + lockdep_assert_wiphy(local->hw.wiphy); + + ret = 0; + + if (local->ops->sta_statistics) + local->ops->sta_statistics(&local->hw, + &sdata->vif, + sta, sinfo); + } else { + ret = -EAGAIN; + + if (local->ops->sta_statistics_atomic) + ret = local->ops->sta_statistics_atomic(&local->hw, + &sdata->vif, + sta, sinfo); + } + + trace_drv_return_int(local, ret); + + return ret; +} + +int drv_link_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo, + bool locked) +{ + int ret; + + sdata = get_bss_sdata(sdata); + if (!check_sdata_in_driver(sdata)) + return 0; + + if (locked) { + might_sleep(); + lockdep_assert_wiphy(local->hw.wiphy); + + ret = 0; + + if (local->ops->link_sta_statistics) + local->ops->link_sta_statistics(&local->hw, + &sdata->vif, + link_sta, + link_sinfo); + } else { + ret = -EAGAIN; + + if (local->ops->sta_statistics_atomic) + ret = local->ops->link_sta_statistics_atomic(&local->hw, + &sdata->vif, + link_sta, + link_sinfo); + } + + trace_drv_return_int(local, ret); + + return 0; +} diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index accd89bbc1fb..83dd15f2daf6 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h @@ -617,42 +617,16 @@ static inline void drv_sta_rate_tbl_update(struct ieee80211_local *local, trace_drv_return_void(local); } -static inline void drv_sta_statistics(struct ieee80211_local *local, - struct ieee80211_sub_if_data *sdata, - struct ieee80211_sta *sta, - struct station_info *sinfo) -{ - might_sleep(); - lockdep_assert_wiphy(local->hw.wiphy); - - sdata = get_bss_sdata(sdata); - if (!check_sdata_in_driver(sdata)) - return; - - trace_drv_sta_statistics(local, sdata, sta); - if (local->ops->sta_statistics) - local->ops->sta_statistics(&local->hw, &sdata->vif, sta, sinfo); - trace_drv_return_void(local); -} - -static inline void drv_link_sta_statistics(struct ieee80211_local *local, - struct ieee80211_sub_if_data *sdata, - struct ieee80211_link_sta *link_sta, - struct link_station_info *link_sinfo) -{ - might_sleep(); - lockdep_assert_wiphy(local->hw.wiphy); - - sdata = get_bss_sdata(sdata); - if (!check_sdata_in_driver(sdata)) - return; - - trace_drv_link_sta_statistics(local, sdata, link_sta); - if (local->ops->link_sta_statistics) - local->ops->link_sta_statistics(&local->hw, &sdata->vif, - link_sta, link_sinfo); - trace_drv_return_void(local); -} +int drv_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, + struct station_info *sinfo, + bool locked); +int drv_link_sta_statistics(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_link_sta *link_sta, + struct link_station_info *link_sinfo, + bool locked); int drv_conf_tx(struct ieee80211_local *local, struct ieee80211_link_data *link, u16 ac, diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index d761847b70b3..5c95ffee257d 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2822,7 +2822,7 @@ static u32 sta_estimate_expected_throughput(struct sta_info *sta, u32 duration; u8 band; - conf = sdata_dereference(bss_conf->chanctx_conf, sta->sdata); + conf = rcu_dereference_wiphy(hw->wiphy, bss_conf->chanctx_conf); if (!conf) return 0; band = conf->def.chan->band; @@ -2835,15 +2835,15 @@ static u32 sta_estimate_expected_throughput(struct sta_info *sta, return ((1024 * USEC_PER_SEC) / duration) * 8; } -static void sta_set_link_sinfo(struct sta_info *sta, - struct link_sta_info *link_sta_info, - struct link_station_info *link_sinfo, - struct ieee80211_link_data *link, - bool tidstats) +static int sta_set_link_sinfo(struct sta_info *sta, + struct link_sta_info *link_sta_info, + struct link_station_info *link_sinfo, + struct ieee80211_link_data *link, + bool tidstats, bool locked) { struct ieee80211_sub_if_data *sdata = sta->sdata; struct ieee80211_sta_rx_stats *last_rxstats; - int i, ac, cpu; + int i, ac, cpu, ret; u32 thr = 0; last_rxstats = sta_get_last_rx_stats(link_sta_info); @@ -2857,9 +2857,10 @@ static void sta_set_link_sinfo(struct sta_info *sta, ether_addr_copy(link_sinfo->addr, link_sta_info->addr); - drv_link_sta_statistics(sta->local, sdata, - link_sta_info->pub, - link_sinfo); + ret = drv_link_sta_statistics(sta->local, sdata, link_sta_info->pub, + link_sinfo, locked); + if (ret) + return ret; link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC); @@ -3027,7 +3028,7 @@ static void sta_set_link_sinfo(struct sta_info *sta, } if (tidstats && !cfg80211_link_sinfo_alloc_tid_stats(link_sinfo, - GFP_KERNEL)) { + GFP_ATOMIC)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) sta_set_tidstats(sta, link_sta_info, &link_sinfo->pertid[i], i, false); @@ -3075,15 +3076,17 @@ static void sta_set_link_sinfo(struct sta_info *sta, link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG); } + + return 0; } -void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, - bool tidstats) +int __sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, + bool tidstats, bool locked) { struct ieee80211_sub_if_data *sdata = sta->sdata; struct ieee80211_local *local = sdata->local; u32 thr = 0; - int i, ac, cpu; + int i, ac, cpu, ret; struct ieee80211_sta_rx_stats *last_rxstats; last_rxstats = sta_get_last_rx_stats(&sta->deflink); @@ -3097,7 +3100,10 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, if (sdata->vif.type == NL80211_IFTYPE_STATION) sinfo->rx_beacon = sdata->deflink.u.mgd.count_beacon_signal; - drv_sta_statistics(local, sdata, &sta->sta, sinfo); + ret = drv_sta_statistics(local, sdata, &sta->sta, sinfo, locked); + if (ret) + return ret; + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | BIT_ULL(NL80211_STA_INFO_STA_FLAGS) | BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) | @@ -3258,7 +3264,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE); } - if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) { + if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_ATOMIC)) { for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) sta_set_tidstats(sta, &sta->deflink, &sinfo->pertid[i], i, true); @@ -3355,17 +3361,19 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, for_each_valid_link(sinfo, link_id) { struct link_station_info *link_sinfo = sinfo->links[link_id]; - link_sta = wiphy_dereference(sta->local->hw.wiphy, - sta->link[link_id]); - link = wiphy_dereference(sdata->local->hw.wiphy, - sdata->link[link_id]); + link_sta = rcu_dereference_wiphy(sta->local->hw.wiphy, + sta->link[link_id]); + link = rcu_dereference_wiphy(sdata->local->hw.wiphy, + sdata->link[link_id]); if (!link_sta || !link_sinfo || !link) { sinfo->valid_links &= ~BIT(link_id); continue; } - sta_set_link_sinfo(sta, link_sta, link_sinfo, link, - tidstats); + ret = sta_set_link_sinfo(sta, link_sta, link_sinfo, link, + tidstats, locked); + if (ret) + return ret; if (!thr && (link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT))) est_thr += link_sinfo->expected_throughput; @@ -3375,6 +3383,8 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->expected_throughput = est_thr; } } + + return 0; } u32 sta_get_expected_throughput(struct sta_info *sta) diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index f409f6a3afa1..8942541375b2 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -989,8 +989,14 @@ static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata, void sta_set_rate_info_tx(struct sta_info *sta, const struct ieee80211_tx_rate *rate, struct rate_info *rinfo); -void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, - bool tidstats); +int __sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, + bool tidstats, bool locked); + +static inline void sta_set_sinfo(struct sta_info *sta, + struct station_info *sinfo, bool tidstats) +{ + __sta_set_sinfo(sta, sinfo, tidstats, true); +} void sta_set_accumulated_removed_links_sinfo(struct sta_info *sta, struct station_info *sinfo); From 2a0abc320a806ce982b24b7e4610285ab4d6461a Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sat, 10 Oct 2026 16:35:43 +0200 Subject: [PATCH 1494/2126] wifi: nl80211: fix BSS reference leak In case nl80211_process_links() returns an error during a multi-link reconfiguration request, BSS entries might leak (if it already has one but fails on a further link). Fix it by jumping to the out label that handles this. Link: https://patch.msgid.link/20261010143543.184032-2-johannes@sipsolutions.net Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 948113050b50..17a58e4baddc 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -19931,7 +19931,7 @@ static int nl80211_assoc_ml_reconf(struct sk_buff *skb, struct genl_info *info) IEEE80211_MLD_MAX_NUM_LINKS, NULL, 0, info); if (err) - return err; + goto out; for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { From 98a19abc797f1f6863f6c2133280c07681018fd9 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:24 +0200 Subject: [PATCH 1495/2126] wifi: nl80211: avoid RTNL in nl80211_get_reg_do() We don't need the RTNL here now, all the work can happen under RCU. Drop the RTNL and do it all under RCU instead. Link: https://patch.msgid.link/20261011113308.ef489f51e801.Iabc6383753a9e49ade17801c76fd5a91f7397475@changeid Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 17a58e4baddc..094de43f74fb 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -11189,7 +11189,7 @@ static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) if (!hdr) goto put_failure; - rtnl_lock(); + rcu_read_lock(); if (info->attrs[NL80211_ATTR_WIPHY]) { bool self_managed; @@ -11204,44 +11204,37 @@ static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) self_managed = wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED; - rcu_read_lock(); - regdom = get_wiphy_regdom(wiphy); /* a self-managed-reg device must have a private regdom */ if (WARN_ON(!regdom && self_managed)) { err = -EINVAL; - goto nla_put_failure_rcu; + goto nla_put_failure; } if (regdom && nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) - goto nla_put_failure_rcu; - } else { - rcu_read_lock(); + goto nla_put_failure; } if (!wiphy && reg_last_request_cell_base() && nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, NL80211_USER_REG_HINT_CELL_BASE)) - goto nla_put_failure_rcu; + goto nla_put_failure; if (!regdom) regdom = rcu_dereference(cfg80211_regdomain); if (nl80211_put_regdom(regdom, msg)) - goto nla_put_failure_rcu; + goto nla_put_failure; rcu_read_unlock(); genlmsg_end(msg, hdr); - rtnl_unlock(); return genlmsg_reply(msg, info); -nla_put_failure_rcu: - rcu_read_unlock(); nla_put_failure: - rtnl_unlock(); + rcu_read_unlock(); put_failure: nlmsg_free(msg); return err; From 17090b50d8e7aa3c1acac65ff42c4486bd3af350 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:25 +0200 Subject: [PATCH 1496/2126] wifi: cfg80211: drop RTNL from disconnect_work The RTNL here is only needed for walking the wiphy list, which can be done under cfg80211_mutex instead, we just need to not take it in regulatory_hint_disconnect(), of which this is the only caller. Link: https://patch.msgid.link/20261011113308.3c7e002d1893.I31f6d1b43bb252b23b42c9b0375f557d90110dc6@changeid Signed-off-by: Johannes Berg --- net/wireless/reg.c | 2 +- net/wireless/reg.h | 2 +- net/wireless/sme.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 4efb35baeb3e..50f50e768f01 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -3671,7 +3671,7 @@ static bool is_wiphy_all_set_reg_flag(enum ieee80211_regulatory_flags flag) void regulatory_hint_disconnect(void) { - guard(mutex)(&cfg80211_mutex); + lockdep_assert_held(&cfg80211_mutex); /* Restore of regulatory settings is not required when wiphy(s) * ignore IE from connected access point but clearance of beacon hints diff --git a/net/wireless/reg.h b/net/wireless/reg.h index c587079ead8f..76e7f9e8d684 100644 --- a/net/wireless/reg.h +++ b/net/wireless/reg.h @@ -115,7 +115,7 @@ void regulatory_hint_country_ie(struct wiphy *wiphy, * be respected but if a user had set the regulatory domain that will take * precedence. * - * Must be called from process context. + * Must be called with cfg80211_mutex held. */ void regulatory_hint_disconnect(void); diff --git a/net/wireless/sme.c b/net/wireless/sme.c index 85076f3b3355..fde86c900f4f 100644 --- a/net/wireless/sme.c +++ b/net/wireless/sme.c @@ -704,10 +704,10 @@ static bool cfg80211_is_all_idle(void) static void disconnect_work(struct work_struct *work) { - rtnl_lock(); + guard(mutex)(&cfg80211_mutex); + if (cfg80211_is_all_idle()) regulatory_hint_disconnect(); - rtnl_unlock(); } DECLARE_WORK(cfg80211_disconnect_work, disconnect_work); From 79976044e4ecbd9ca552311a3bdce7d646f6b827 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:26 +0200 Subject: [PATCH 1497/2126] wifi: nl80211: don't hold RTNL for SET_SAR_SPECS There's no need for the RTNL for setting SAR specs, it seems to have just been added while I was removing the RTNL from most places. Just drop it. Link: https://patch.msgid.link/20261011113308.5a374e7bc350.I638c842c1639a8aa5d8207f784110b4a583aa7db@changeid Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 094de43f74fb..7430e80893b1 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -21230,8 +21230,7 @@ static const struct genl_small_ops nl80211_small_ops[] = { .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = nl80211_set_sar_specs, .flags = GENL_UNS_ADMIN_PERM, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | - NL80211_FLAG_NEED_RTNL), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), }, { .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST, From 9a8407984ab43a70174e5474946ab6c19dc2e0ba Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:27 +0200 Subject: [PATCH 1498/2126] wifi: cfg80211: switch wiphy netns under cfg80211_mutex Hold the cfg80211_mutex across the whole netns switch, so we can walk the wiphy list without worrying about a wiphy switching away to a different namespace underneath. This will allow removing RTNL from netlink dumps. Link: https://patch.msgid.link/20261011113308.89f391aea519.I7529b9055f522cfeb8a26ae3a85c1b71a98e8192@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 3 +++ net/wireless/core.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index 777f48a01101..ea38b22a88cd 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -171,6 +171,9 @@ static int __cfg80211_switch_netns(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev, *tmp; int err = 0; + /* make the whole switch atomic for cfg80211_mutex holders, e.g. dumps */ + guard(mutex)(&cfg80211_mutex); + list_for_each_entry_safe(wdev, tmp, &rdev->wiphy.wdev_list, list) { err = cfg80211_switch_wdev_netns(wdev, net); if (!err) diff --git a/net/wireless/core.h b/net/wireless/core.h index 07d7a68a7cfc..e70a4f679bf5 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -20,7 +20,7 @@ #include "reg.h" -/* protects the wiphy list and regulatory state */ +/* protects the wiphy list, wiphy netns changes and regulatory state */ extern struct mutex cfg80211_mutex; #define WIPHY_IDX_INVALID -1 From 65460860e18ed5615024846f27bcc56b90e2761c Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:28 +0200 Subject: [PATCH 1499/2126] wifi: nl80211: avoid RTNL for wiphy/interface netlink dumps The wiphy/interface netlink dumps only need the RTNL for the list and, possibly, filtering by netdev. This can be easily replaced now, do that. Link: https://patch.msgid.link/20261011113308.d2b68635eeec.I42540f72c38c1bbb6edd2396d6dcc6199f1bc8c0@changeid Signed-off-by: Johannes Berg --- net/wireless/nl80211.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 7430e80893b1..4c67cc5f45f9 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -3867,8 +3867,10 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb, struct cfg80211_registered_device *rdev; int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); - netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); + rcu_read_lock(); + netdev = dev_get_by_index_rcu(sock_net(skb->sk), ifidx); if (!netdev) { + rcu_read_unlock(); ret = -ENODEV; goto out; } @@ -3877,6 +3879,7 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb, netdev->ieee80211_ptr->wiphy); state->filter_wiphy = rdev->wiphy_idx; } + rcu_read_unlock(); } ret = 0; @@ -3891,18 +3894,18 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; struct cfg80211_registered_device *rdev; - rtnl_lock(); + mutex_lock(&cfg80211_mutex); if (!state) { state = kzalloc_obj(*state); if (!state) { - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); return -ENOMEM; } state->filter_wiphy = -1; ret = nl80211_dump_wiphy_parse(skb, cb, state); if (ret) { kfree(state); - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); return ret; } cb->args[0] = (long)state; @@ -3944,7 +3947,7 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) cb->min_dump_alloc = 4096; state->split_start = 0; wiphy_unlock(&rdev->wiphy); - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); return 1; } idx--; @@ -3954,7 +3957,7 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) wiphy_unlock(&rdev->wiphy); break; } - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); state->start = idx; @@ -4930,7 +4933,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback * struct wireless_dev *wdev; int ret; - rtnl_lock(); + mutex_lock(&cfg80211_mutex); if (!cb->args[2]) { struct nl80211_dump_wiphy_state state = { .filter_wiphy = -1, @@ -4993,7 +4996,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback * ret = skb->len; out_unlock: - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); return ret; } From ef27674b8471b5d1c80fe5ebfaa4f2b07dfb1096 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:29 +0200 Subject: [PATCH 1500/2126] wifi: cfg80211: protect wiphy names with cfg80211_mutex The RTNL is only used for wiphy names to serialize checking for name collisions and setting the name, across all wiphys. Since the wiphy list can be walked under the cfg80211_mutex, use that instead. In nl80211_set_wiphy() this requires taking it before the wiphy mutex, and then the RTNL is no longer needed there at all if the netdev is looked up under RCU. Since the netns of the wiphy and its netdevs is now also stable under the cfg80211_mutex, only the netdev unregistering needs to be handled, by looking up the wdev again under the wiphy mutex. Assisted-by: LLM Link: https://patch.msgid.link/20261011113308.6cedefb201f4.I03ffe79f337b61ea8f91b91532d3dfb9497e0438@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 10 ++++----- net/wireless/nl80211.c | 47 ++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index ea38b22a88cd..f6ac022ea4bd 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -94,7 +94,7 @@ static int cfg80211_dev_check_name(struct cfg80211_registered_device *rdev, struct cfg80211_registered_device *rdev2; int wiphy_idx, taken = -1, digits; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); if (strlen(newname) > NL80211_WIPHY_NAME_MAXLEN) return -EINVAL; @@ -127,7 +127,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev, { int result; - ASSERT_RTNL(); + lockdep_assert_held(&cfg80211_mutex); lockdep_assert_wiphy(&rdev->wiphy); /* Ignore nop renames */ @@ -664,16 +664,16 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, if (requested_name && requested_name[0]) { int rv; - rtnl_lock(); + mutex_lock(&cfg80211_mutex); rv = cfg80211_dev_check_name(rdev, requested_name); if (rv < 0) { - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); goto use_default_name; } rv = dev_set_name(&rdev->wiphy.dev, "%s", requested_name); - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); if (rv) goto use_default_name; } else { diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 4c67cc5f45f9..d790e204aee3 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -4372,17 +4372,18 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = NULL; struct net_device *netdev = NULL; - struct wireless_dev *wdev; + struct wireless_dev *wdev = NULL; int result = 0, rem_txq_params = 0; struct nlattr *nl_txq_params; - u32 changed; + u32 changed, wdev_id = 0; u8 retry_short = 0, retry_long = 0; u32 frag_threshold = 0, rts_threshold = 0; u8 coverage_class = 0; u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; int radio_idx = -1; - rtnl_lock(); + /* keeps the wiphy registered and its netns stable */ + mutex_lock(&cfg80211_mutex); /* * Try to find the wiphy and netdev. Normally this * function shouldn't need the netdev, but this is @@ -4396,28 +4397,44 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) if (info->attrs[NL80211_ATTR_IFINDEX]) { int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); - netdev = __dev_get_by_index(genl_info_net(info), ifindex); - if (netdev && netdev->ieee80211_ptr) + rcu_read_lock(); + netdev = dev_get_by_index_rcu(genl_info_net(info), ifindex); + if (netdev && netdev->ieee80211_ptr) { rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); - else - netdev = NULL; + wdev_id = netdev->ieee80211_ptr->identifier; + } + rcu_read_unlock(); } - if (!netdev) { + if (!rdev) { + /* RCU for the wdev list walk, cfg80211_mutex keeps rdev */ + rcu_read_lock(); rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), info->attrs); + rcu_read_unlock(); if (IS_ERR(rdev)) { - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); return PTR_ERR(rdev); } - wdev = NULL; - netdev = NULL; - result = 0; - } else - wdev = netdev->ieee80211_ptr; + } guard(wiphy)(&rdev->wiphy); + /* the netdev may have been unregistered after the lookup */ + if (wdev_id) { + list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->identifier == wdev_id) + break; + } + if (list_entry_is_head(wdev, &rdev->wiphy.wdev_list, list)) { + mutex_unlock(&cfg80211_mutex); + return -ENODEV; + } + netdev = wdev->netdev; + } else { + netdev = NULL; + } + /* * end workaround code, by now the rdev is available * and locked, and wdev may or may not be NULL. @@ -4426,7 +4443,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) if (info->attrs[NL80211_ATTR_WIPHY_NAME]) result = cfg80211_dev_rename( rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); - rtnl_unlock(); + mutex_unlock(&cfg80211_mutex); if (result) return result; From 03b0588c2511dd5cf7745a194fedaadabba4b163 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:30 +0200 Subject: [PATCH 1501/2126] wifi: mac80211_hwsim: get wiphy_name() after registration The wiphy name registration is (or at least looks, since hwsim is the only user and doesn't have parallel ops) currently racy. In preparation for fixing that, grab wiphy_name() after the new radio is registered, since registration might change it. Link: https://patch.msgid.link/20261011113308.13b74d285682.I738d8363368771b442c3d9c683fef2c7e6c39da1@changeid Signed-off-by: Johannes Berg --- drivers/net/wireless/virtual/mac80211_hwsim_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index 87f20d5ff0ee..e53714b81ec2 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -5751,9 +5751,6 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, goto failed; } - /* ieee80211_alloc_hw_nm may have used a default name */ - param->hwname = wiphy_name(hw->wiphy); - if (info) net = genl_info_net(info); else @@ -6241,6 +6238,9 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, hwsim_radios_generation++; spin_unlock_bh(&hwsim_radio_lock); + /* alloc/register can change the name, we want the right one */ + param->hwname = wiphy_name(hw->wiphy); + hwsim_mcast_new_radio(idx, wiphy_net(data->hw->wiphy), info, param); return idx; From b6c27cf5fe5d9a9872982889a1a9cb471bad20ed Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:31 +0200 Subject: [PATCH 1502/2126] wifi: cfg80211: check wiphy name in wiphy_register() We currently check names already in wiphy_new_nm(), but that could technically race when two are registered at the same time. Currently that only happens with hwsim, which probably can't race, but it's confusing. Do the check later, with cfg80211_mutex held, so it'll always be precise. Assisted-by: LLM Link: https://patch.msgid.link/20261011113308.20e9fccb29da.I3a32d7fcfba5fd7b4ee378aa182d87e46f98c6e6@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index f6ac022ea4bd..d2931b9d7e58 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -660,33 +660,13 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, /* atomic_inc_return makes it start at 1, make it start at 0 */ rdev->wiphy_idx--; - /* give it a proper name */ - if (requested_name && requested_name[0]) { + /* remember the name, used/checked during registration */ + if (!requested_name || !requested_name[0] || + dev_set_name(&rdev->wiphy.dev, "%s", requested_name)) { int rv; - mutex_lock(&cfg80211_mutex); - rv = cfg80211_dev_check_name(rdev, requested_name); - - if (rv < 0) { - mutex_unlock(&cfg80211_mutex); - goto use_default_name; - } - - rv = dev_set_name(&rdev->wiphy.dev, "%s", requested_name); - mutex_unlock(&cfg80211_mutex); - if (rv) - goto use_default_name; - } else { - int rv; - -use_default_name: - /* NOTE: This is *probably* safe w/out holding rtnl because of - * the restrictions on phy names. Probably this call could - * fail if some other part of the kernel (re)named a device - * phyX. But, might should add some locking and check return - * value, and use a different name if this one exists? - */ - rv = dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx); + rv = dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", + rdev->wiphy_idx); if (rv < 0) { kfree(rdev); return NULL; @@ -1240,7 +1220,14 @@ int wiphy_register(struct wiphy *wiphy) rtnl_lock(); mutex_lock(&cfg80211_mutex); wiphy_lock(&rdev->wiphy); - res = device_add(&rdev->wiphy.dev); + + /* use default name if the requested one isn't good */ + res = cfg80211_dev_check_name(rdev, dev_name(&rdev->wiphy.dev)); + if (res) + res = dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", + rdev->wiphy_idx); + if (!res) + res = device_add(&rdev->wiphy.dev); if (res) { wiphy_unlock(&rdev->wiphy); mutex_unlock(&cfg80211_mutex); From 85a4a8e9c8481f8d1f557bb2d738257b1a2e7011 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:32 +0200 Subject: [PATCH 1503/2126] wifi: mac80211: don't hold RTNL for rate control algo Back when we supported algorithm switching at runtime, this was needed for the open_count check. Now we don't have that any more, so the check and RTNL section can go away. Link: https://patch.msgid.link/20261011113308.0c5d35e2afea.I81141b28351e7c1ca23770616364346c33d7e08e@changeid Signed-off-by: Johannes Berg --- net/mac80211/main.c | 4 +--- net/mac80211/rate.c | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index ad7dfc07ee63..28480f983932 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1567,10 +1567,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) if (result) goto fail_flows; - rtnl_lock(); result = ieee80211_init_rate_ctrl_alg(local, hw->rate_control_algorithm); - rtnl_unlock(); if (result < 0) { wiphy_debug(local->hw.wiphy, "Failed to initialize rate control algorithm\n"); @@ -1689,9 +1687,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) fail_wiphy_register: fail_band: rtnl_lock(); - rate_control_deinitialize(local); ieee80211_remove_interfaces(local); rtnl_unlock(); + rate_control_deinitialize(local); fail_rate: ieee80211_txq_teardown_flows(local); fail_flows: diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index f75257a19064..10e6ad537261 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c @@ -1001,11 +1001,6 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, { struct rate_control_ref *ref; - ASSERT_RTNL(); - - if (local->open_count) - return -EBUSY; - if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { if (WARN_ON(!local->ops->set_rts_threshold)) return -EINVAL; From 1a82eea843ae255496c5a8ff6302d00243fb6703 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 11:31:33 +0200 Subject: [PATCH 1504/2126] wifi: mac80211: fix interface registration error path order If we fail to register the inet/inet6 address notifiers, wiphy_unregister() is called before removing interface, but the default interface already exists at this point. This could also lead to a deadlock as wiphy_unregister() then waits for the interface to go away. Change the order to remove the interfaces first. Assisted-by: LLM Link: https://patch.msgid.link/20261011113308.c2cb32bf3160.Ib46993671ae3030950360ea378a507cef2bd4117@changeid Signed-off-by: Johannes Berg --- net/mac80211/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 28480f983932..76e85754deff 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1683,12 +1683,12 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) #if defined(CONFIG_INET) || defined(CONFIG_IPV6) fail_ifa: #endif - wiphy_unregister(local->hw.wiphy); - fail_wiphy_register: - fail_band: rtnl_lock(); ieee80211_remove_interfaces(local); rtnl_unlock(); + wiphy_unregister(local->hw.wiphy); + fail_wiphy_register: + fail_band: rate_control_deinitialize(local); fail_rate: ieee80211_txq_teardown_flows(local); From c49f54fd2abff08964677db8fdc1674c713ab42c Mon Sep 17 00:00:00 2001 From: Chien Wong Date: Mon, 12 Oct 2026 22:07:36 +0800 Subject: [PATCH 1505/2126] wifi: mac80211: fix encryption tailroom BIP-CMAC-256 and BIP-GMAC append a 26-byte MME but mac80211 currently reserves only 18 bytes of encryption tailroom. Generating 26-byte MME may happen to work because the actual skb tailroom can exceed the requested amount. For example, dev_alloc_skb() rounds the allocation to kmalloc size buckets or alignment boundaries, and the extra space may cover the 8-byte shortfall. Reserve enough tailroom for the 26-byte MME. Fixes: 56c52da2d554 ("mac80111: Add BIP-CMAC-256 cipher") Signed-off-by: Chien Wong Link: https://patch.msgid.link/20261012140738.70178-2-m@xv97.com Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index bf9f26234662..1a6cbbb5a17d 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -52,7 +52,7 @@ struct ieee80211_mesh_fast_tx; /* Required encryption head and tailroom */ #define IEEE80211_ENCRYPT_HEADROOM 8 -#define IEEE80211_ENCRYPT_TAILROOM 18 +#define IEEE80211_ENCRYPT_TAILROOM 26 /* current max: GMAC/CMAC-256 MME */ /* power level hasn't been configured (or set to automatic) */ #define IEEE80211_UNSET_POWER_LEVEL INT_MIN From 48002331da85c7c962cfbc09c8bd84d219a6fe1c Mon Sep 17 00:00:00 2001 From: Chien Wong Date: Mon, 12 Oct 2026 22:07:37 +0800 Subject: [PATCH 1506/2126] wifi: mac80211: reserve MME tailroom for protected beacons Beacon protection appends an MME to beacons, but the skb allocation does not reserve tailroom for it. If the available tailroom is too small, the crypto path drops the beacon. Two factors often mask this: the 256-byte TIM reservation is rarely fully used, and dev_alloc_skb() may round up the allocation, leaving extra tailroom. Neither guarantees enough room for the MME. Reserve enough room for the largest MME. Fixes: 0a3a84360b37 ("mac80211: Beacon protection using the new BIGTK (AP)") Signed-off-by: Chien Wong Link: https://patch.msgid.link/20261012140738.70178-3-m@xv97.com Signed-off-by: Johannes Berg --- net/mac80211/tx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index ef97d6d3bdcd..e9b6a0415d6a 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -5724,7 +5724,8 @@ __ieee80211_beacon_get_ap(struct ieee80211_hw *hw, skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + beacon->tail_len + 256 + - local->hw.extra_beacon_tailroom + mbssid_len); + local->hw.extra_beacon_tailroom + mbssid_len + + IEEE80211_ENCRYPT_TAILROOM); if (!skb) return NULL; From c6c8bc355657115664131b38c53c5ddf7d93b072 Mon Sep 17 00:00:00 2001 From: Andreas Wendleder Date: Tue, 13 Oct 2026 02:01:24 +0200 Subject: [PATCH 1507/2126] wifi: b43: fix use-after-free in b43_bcma_remove() b43_one_core_detach() frees the struct b43_wldev it is given the bus device of. b43_bcma_remove() then reads wldev->dev again to free the bus device, which is a read of freed memory. b43_ssb_remove() does not have the problem: it takes a copy of wldev->dev at the start. Do the same here. Fixes: 96838d61102a ("b43: Fix memory leaks in b43_bus_dev_ssb_init and b43_bus_dev_bcma_init") Cc: stable@vger.kernel.org Signed-off-by: Andreas Wendleder Link: https://patch.msgid.link/20261013000124.48605-1-gonsolo@gmail.com Signed-off-by: Johannes Berg --- drivers/net/wireless/broadcom/b43/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/broadcom/b43/main.c b/drivers/net/wireless/broadcom/b43/main.c index 817448e58e7f..3825b6ad9f4f 100644 --- a/drivers/net/wireless/broadcom/b43/main.c +++ b/drivers/net/wireless/broadcom/b43/main.c @@ -5677,6 +5677,7 @@ static void b43_bcma_remove(struct bcma_device *core) { struct b43_wldev *wldev = bcma_get_drvdata(core); struct b43_wl *wl = wldev->wl; + struct b43_bus_dev *dev = wldev->dev; /* We must cancel any work here before unregistering from ieee80211, * as the ieee80211 unreg will destroy the workqueue. */ @@ -5691,14 +5692,14 @@ static void b43_bcma_remove(struct bcma_device *core) ieee80211_unregister_hw(wl->hw); } - b43_one_core_detach(wldev->dev); + b43_one_core_detach(dev); /* Unregister HW RNG driver */ b43_rng_exit(wl); b43_leds_unregister(wl); ieee80211_free_hw(wl->hw); - kfree(wldev->dev); + kfree(dev); } static struct bcma_driver b43_bcma_driver = { From 958f20d5aa0aa645068454fdb62ebc625ac9a115 Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Mon, 12 Oct 2026 20:36:23 +0800 Subject: [PATCH 1508/2126] wifi: mwifiex: append hotfix number to firmware version string mwifiex_ret_get_hw_spec() parses and logs the FW_HOTFIX_VER_ID TLV, but the hotfix value is not stored in the adapter structure. As a result, the hotfix number never appears in the firmware version string returned by mwifiex_drv_get_driver_version(). Store the hotfix version from FW_HOTFIX_VER_ID and append it to the firmware version string. Assisted-by: LLM sparse Fixes: 7715d79553de ("wifi: mwifiex: Support firmware hotfix version in GET_HW_SPEC responses") Signed-off-by: Jeff Chen Link: https://patch.msgid.link/20261012123624.3147417-2-jeff.chen_1@oss.nxp.com Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/mwifiex/cmdevt.c | 10 ++++++++-- drivers/net/wireless/marvell/mwifiex/fw.h | 6 ++++++ drivers/net/wireless/marvell/mwifiex/init.c | 1 + drivers/net/wireless/marvell/mwifiex/main.h | 1 + drivers/net/wireless/marvell/mwifiex/sta_ioctl.c | 3 ++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c b/drivers/net/wireless/marvell/mwifiex/cmdevt.c index 29e0f274575e..268a795db486 100644 --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c @@ -1594,11 +1594,17 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, api_rev->major_ver, api_rev->minor_ver); break; - case FW_HOTFIX_VER_ID: + case FW_HOTFIX_VER_ID: { + struct hw_spec_fw_hotfix_ver *hf; + + hf = (void *)tlv; + adapter->fw_hotfix_ver = + le16_to_cpu(hf->hotfix_ver); mwifiex_dbg(adapter, INFO, "Firmware hotfix version %d\n", - api_rev->major_ver); + adapter->fw_hotfix_ver); break; + } default: mwifiex_dbg(adapter, FATAL, "Unknown api_id: %d\n", diff --git a/drivers/net/wireless/marvell/mwifiex/fw.h b/drivers/net/wireless/marvell/mwifiex/fw.h index 93561116959a..f254d6d6e3eb 100644 --- a/drivers/net/wireless/marvell/mwifiex/fw.h +++ b/drivers/net/wireless/marvell/mwifiex/fw.h @@ -1104,6 +1104,12 @@ struct hw_spec_api_rev { u8 minor_ver; } __packed; +struct hw_spec_fw_hotfix_ver { + struct mwifiex_ie_types_header header; + __le16 api_id; + __le16 hotfix_ver; +} __packed; + struct host_cmd_ds_get_hw_spec { __le16 hw_if_version; __le16 version; diff --git a/drivers/net/wireless/marvell/mwifiex/init.c b/drivers/net/wireless/marvell/mwifiex/init.c index 0c8925013724..e8a5f9b758d6 100644 --- a/drivers/net/wireless/marvell/mwifiex/init.c +++ b/drivers/net/wireless/marvell/mwifiex/init.c @@ -296,6 +296,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) adapter->config_bands = 0; adapter->adhoc_start_band = 0; adapter->fw_release_number = 0; + adapter->fw_hotfix_ver = 0; adapter->fw_cap_info = 0; memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf)); adapter->event_cause = 0; diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h index 8e6238c01aa6..5dd01bacc7cb 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.h +++ b/drivers/net/wireless/marvell/mwifiex/main.h @@ -1003,6 +1003,7 @@ struct mwifiex_adapter { bool host_mlme_enabled; struct ieee80211_txrx_stypes mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES]; u8 fw_api_ver; + u16 fw_hotfix_ver; u8 key_api_major_ver, key_api_minor_ver; u8 max_p2p_conn, max_sta_conn; struct memory_type_mapping *mem_type_mapping_tbl; diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c index 19196848778c..1d3874734851 100644 --- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c +++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c @@ -1144,7 +1144,8 @@ mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version, char fw_ver[32]; ver.l = cpu_to_le32(adapter->fw_release_number); - sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]); + sprintf(fw_ver, "%u.%u.%u.p%u.%u", ver.c[2], ver.c[1], + ver.c[0], ver.c[3], adapter->fw_hotfix_ver); snprintf(version, max_len, driver_version, fw_ver); From fbcdcc450c47b2dbc0e3c790a40071e7485bb68c Mon Sep 17 00:00:00 2001 From: Jeff Chen Date: Mon, 12 Oct 2026 20:36:24 +0800 Subject: [PATCH 1509/2126] wifi: mwifiex: validate GET_HW_SPEC TLV lengths before parsing Validate TLV lengths before accessing TLV payloads in mwifiex_ret_get_hw_spec(). Signed-off-by: Jeff Chen Link: https://patch.msgid.link/20261012123624.3147417-3-jeff.chen_1@oss.nxp.com Signed-off-by: Johannes Berg --- drivers/net/wireless/marvell/mwifiex/cmdevt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c b/drivers/net/wireless/marvell/mwifiex/cmdevt.c index 268a795db486..6e04d7da6217 100644 --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c @@ -1494,6 +1494,7 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, struct hw_spec_max_conn *max_conn; u16 resp_size, api_id; int i, left_len, parsed_len = 0; + int tlv_len; adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info); @@ -1559,8 +1560,16 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, left_len = resp_size - sizeof(struct host_cmd_ds_get_hw_spec); while (left_len > sizeof(struct mwifiex_ie_types_header)) { tlv = (void *)&hw_spec->tlvs + parsed_len; + tlv_len = sizeof(*tlv) + le16_to_cpu(tlv->len); + + if (tlv_len > left_len) + break; + switch (le16_to_cpu(tlv->type)) { case TLV_TYPE_API_REV: + if (tlv_len < sizeof(struct hw_spec_api_rev)) + break; + api_rev = (struct hw_spec_api_rev *)tlv; api_id = le16_to_cpu(api_rev->api_id); switch (api_id) { @@ -1613,6 +1622,9 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, } break; case TLV_TYPE_MAX_CONN: + if (tlv_len < sizeof(struct hw_spec_max_conn)) + break; + max_conn = (struct hw_spec_max_conn *)tlv; adapter->max_p2p_conn = max_conn->max_p2p_conn; adapter->max_sta_conn = max_conn->max_sta_conn; From 8edbf6c23363563e508a61f3f26f4e4b6eec9dd5 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Thu, 8 Oct 2026 17:26:34 +0800 Subject: [PATCH 1510/2126] tcp_bic: fix divide by zero on max_increment == 0 max_increment is how many packets cwnd can grow per RTT, so 0 makes no sense, and bictcp_update() divides by it. Reject values below 1 when the parameter is written. Fixes: 83803034f423 ("[TCP]: Add TCP BIC congestion control module.") Reported-by: VEGA Signed-off-by: Jiayuan Chen Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261008092641.140777-2-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni --- net/ipv4/tcp_bic.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_bic.c b/net/ipv4/tcp_bic.c index 65444ff14241..27d2e38ff793 100644 --- a/net/ipv4/tcp_bic.c +++ b/net/ipv4/tcp_bic.c @@ -27,15 +27,25 @@ */ static int fast_convergence = 1; -static int max_increment = 16; +static unsigned int max_increment = 16; static int low_window = 14; static int beta = 819; /* = 819/1024 (BICTCP_BETA_SCALE) */ static int initial_ssthresh; static int smooth_part = 20; +static int max_increment_set(const char *val, const struct kernel_param *kp) +{ + return param_set_uint_minmax(val, kp, 1, INT_MAX); +} + +static const struct kernel_param_ops max_increment_ops = { + .set = max_increment_set, + .get = param_get_uint, +}; + module_param(fast_convergence, int, 0644); MODULE_PARM_DESC(fast_convergence, "turn on/off fast convergence"); -module_param(max_increment, int, 0644); +module_param_cb(max_increment, &max_increment_ops, &max_increment, 0644); MODULE_PARM_DESC(max_increment, "Limit on increment allowed during binary search"); module_param(low_window, int, 0644); MODULE_PARM_DESC(low_window, "lower bound on congestion window (for TCP friendliness)"); From f09eb97322b16a6f709a47599c95b62f786905f9 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Thu, 8 Oct 2026 17:26:35 +0800 Subject: [PATCH 1511/2126] tcp_hybla: fix divide by zero on rtt0 == 0 rtt0 is the reference RTT in ms, so 0 makes no sense, and hybla_recalc_param() divides by it right from hybla_init(). Reject values below 1 when the parameter is written. Also cap it at U32_MAX / USEC_PER_MSEC, since rtt0 * USEC_PER_MSEC can wrap to 0 on 32-bit. An rtt0 above that (about 71 minutes) makes no sense anyway. Fixes: 835b3f0c0d7e ("[TCP]: Add TCP Hybla congestion control module.") Fixes: 740b0f1841f6 ("tcp: switch rtt estimations to usec resolution") Reported-by: VEGA Signed-off-by: Jiayuan Chen Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261008092641.140777-3-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni --- net/ipv4/tcp_hybla.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_hybla.c b/net/ipv4/tcp_hybla.c index abd7d91807e5..b9b482180d30 100644 --- a/net/ipv4/tcp_hybla.c +++ b/net/ipv4/tcp_hybla.c @@ -26,8 +26,20 @@ struct hybla { }; /* Hybla reference round trip time (default= 1/40 sec = 25 ms), in ms */ -static int rtt0 = 25; -module_param(rtt0, int, 0644); +static unsigned int rtt0 = 25; + +static int rtt0_set(const char *val, const struct kernel_param *kp) +{ + /* avoid rtt0 * USEC_PER_MSEC overflow */ + return param_set_uint_minmax(val, kp, 1, U32_MAX / USEC_PER_MSEC); +} + +static const struct kernel_param_ops rtt0_ops = { + .set = rtt0_set, + .get = param_get_uint, +}; + +module_param_cb(rtt0, &rtt0_ops, &rtt0, 0644); MODULE_PARM_DESC(rtt0, "reference rout trip time (ms)"); /* This is called to refresh values for hybla parameters */ From 7d52b5d16afc1cf8484ae321658e217a80e3ff4d Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Thu, 8 Oct 2026 17:26:36 +0800 Subject: [PATCH 1512/2126] tcp_cubic: fix divide by zero and endless loop on bad module params beta_scale and cube_factor are computed once at module init, and beta == 1024 or bic_scale == 0 is a divide by zero right there. Other out of range values give garbage: negative beta can make beta_scale 0, and bic_scale * 10 can overflow. Reject them. Read beta once, as it can be written through sysfs before the init function runs. A small beta also gives a small beta_scale, and (cwnd * beta_scale) >> 3 truncates to 0 for a tiny cwnd, so the TCP friendliness loop never ends. Rather than testing delta on every ACK, make sure beta_scale is at least 8 at init, so delta is >= 1 within the cwnd < 1 million packets limit this code is designed for. This slows the TCP friendly estimate for beta < 512, a backoff harder than Reno's 0.5, which is not a setting anyone should use. Fixes: df3271f3361b ("[TCP] BIC: CUBIC window growth (2.0)") Suggested-by: Eric Dumazet Reviewed-by: Eric Dumazet Signed-off-by: Jiayuan Chen Link: https://patch.msgid.link/20261008092641.140777-4-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni --- net/ipv4/tcp_cubic.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c index 119bf8cbb007..a88e4bf86150 100644 --- a/net/ipv4/tcp_cubic.c +++ b/net/ipv4/tcp_cubic.c @@ -500,16 +500,26 @@ static const struct btf_kfunc_id_set tcp_cubic_kfunc_set = { static int __init cubictcp_register(void) { + int b = READ_ONCE(beta); int ret; BUILD_BUG_ON(sizeof(struct bictcp) > ICSK_CA_PRIV_SIZE); + if (b < 0 || b >= BICTCP_BETA_SCALE || + bic_scale <= 0 || bic_scale > INT_MAX / 10) { + pr_err("tcp_cubic: invalid beta %d or bic_scale %d\n", + b, bic_scale); + return -EINVAL; + } + /* Precompute a bunch of the scaling factors that are used per-packet * based on SRTT of 100ms */ - beta_scale = 8*(BICTCP_BETA_SCALE+beta) / 3 - / (BICTCP_BETA_SCALE - beta); + beta_scale = 8 * (BICTCP_BETA_SCALE + b) / 3 + / (BICTCP_BETA_SCALE - b); + /* bictcp_update() needs (cwnd * beta_scale) >> 3 to be >= 1 */ + beta_scale = max(beta_scale, 8U); cube_rtt_scale = (bic_scale * 10); /* 1024*c/rtt */ From cc9dcb0e7a428ca43259bbee3350d786681265a3 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 8 Oct 2026 18:06:46 +0800 Subject: [PATCH 1513/2126] net: core: use the packet's L3 protocol for the GSO size limit gso_features_check() compares the frame length against netif_get_gso_max_size(), which picks the IPv4 or the IPv6 limit from skb->protocol. A tag which is already inside the frame replaces that field with the VLAN ethertype, as skb_vlan_push() does, and an IPv6 packet is then measured against the IPv4 limit and segmented although the device could send it as one TSO frame. The lookup moves from netdevice.h into dev.c: vlan_get_protocol() reads the L3 protocol from behind an in-frame tag, while if_vlan.h includes netdevice.h, so an inline in that header cannot call it. dev.c is the only file which calls the lookup, so it becomes a static helper there. Reviewed-by: Willem de Bruijn Assisted-by: LLM Signed-off-by: Wang Zhan Link: https://patch.msgid.link/20261008100651.2534957-2-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- include/linux/netdevice.h | 9 --------- net/core/dev.c | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 5b4b92e76b67..1743dcd02d5b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5566,15 +5566,6 @@ netif_get_gro_max_size(const struct net_device *dev, const struct sk_buff *skb) READ_ONCE(dev->gro_ipv4_max_size); } -static inline unsigned int -netif_get_gso_max_size(const struct net_device *dev, const struct sk_buff *skb) -{ - /* pairs with WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */ - return skb->protocol == htons(ETH_P_IPV6) ? - READ_ONCE(dev->gso_max_size) : - READ_ONCE(dev->gso_ipv4_max_size); -} - static inline bool netif_is_macsec(const struct net_device *dev) { return dev->priv_flags & IFF_MACSEC; diff --git a/net/core/dev.c b/net/core/dev.c index a6951ea08961..df7ec4faaa81 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3888,6 +3888,15 @@ static bool skb_has_ipv6_extension_hdr(const struct sk_buff *skb) return false; } +static unsigned int +netif_get_gso_max_size(const struct net_device *dev, const struct sk_buff *skb) +{ + /* pairs with WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */ + return vlan_get_protocol(skb) == htons(ETH_P_IPV6) ? + READ_ONCE(dev->gso_max_size) : + READ_ONCE(dev->gso_ipv4_max_size); +} + static netdev_features_t gso_features_check(const struct sk_buff *skb, struct net_device *dev, netdev_features_t features) From 0bba48256b0aa86e84a08d69b4410018bd8ffc67 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 8 Oct 2026 18:06:47 +0800 Subject: [PATCH 1514/2126] net: core: factor out the GSO device limit check gso_features_check() decides whether an egress device can offload a GSO skb as a single TSO frame by comparing the segment count and the frame length against the device limits. The resegmentation path added by a later patch caps the MSS segments per output skb and needs the same features computed without those limits, so put the two tests in a helper and gate them with one flag. __netif_skb_features() takes that flag and takes the place of netif_skb_features(), which becomes an inline wrapper in netdevice.h and passes the flag set. Existing callers keep their call, and the resegmentation path asks for the features without the limit checks. No functional changes. Reviewed-by: Willem de Bruijn Assisted-by: LLM Signed-off-by: Wang Zhan Link: https://patch.msgid.link/20261008100651.2534957-3-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- include/linux/netdevice.h | 9 ++++++++- net/core/dev.c | 30 ++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 1743dcd02d5b..8fbe3a5d8169 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5500,7 +5500,14 @@ void netif_stacked_transfer_operstate(const struct net_device *rootdev, netdev_features_t passthru_features_check(struct sk_buff *skb, struct net_device *dev, netdev_features_t features); -netdev_features_t netif_skb_features(struct sk_buff *skb); +netdev_features_t __netif_skb_features(struct sk_buff *skb, + bool check_gso_limits); + +static inline netdev_features_t netif_skb_features(struct sk_buff *skb) +{ + return __netif_skb_features(skb, true); +} + void skb_warn_bad_offload(const struct sk_buff *skb); static inline bool net_gso_ok(netdev_features_t features, int gso_type) diff --git a/net/core/dev.c b/net/core/dev.c index df7ec4faaa81..4ea6ea4b111e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3897,16 +3897,24 @@ netif_get_gso_max_size(const struct net_device *dev, const struct sk_buff *skb) READ_ONCE(dev->gso_ipv4_max_size); } -static netdev_features_t gso_features_check(const struct sk_buff *skb, - struct net_device *dev, - netdev_features_t features) +static bool +gso_within_dev_limits(const struct sk_buff *skb, const struct net_device *dev) { - u16 gso_segs = skb_shinfo(skb)->gso_segs; - - if (gso_segs > READ_ONCE(dev->gso_max_segs)) - return features & ~NETIF_F_GSO_MASK; + if (skb_shinfo(skb)->gso_segs > READ_ONCE(dev->gso_max_segs)) + return false; if (unlikely(skb->len >= netif_get_gso_max_size(dev, skb))) + return false; + + return true; +} + +static netdev_features_t gso_features_check(const struct sk_buff *skb, + struct net_device *dev, + netdev_features_t features, + bool check_limits) +{ + if (check_limits && !gso_within_dev_limits(skb, dev)) return features & ~NETIF_F_GSO_MASK; if (!skb_shinfo(skb)->gso_type) { @@ -3955,13 +3963,15 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb, return features; } -netdev_features_t netif_skb_features(struct sk_buff *skb) +netdev_features_t +__netif_skb_features(struct sk_buff *skb, bool check_gso_limits) { struct net_device *dev = skb->dev; netdev_features_t features = dev->features; if (skb_is_gso(skb)) - features = gso_features_check(skb, dev, features); + features = gso_features_check(skb, dev, features, + check_gso_limits); /* If encapsulation offload request, verify we are testing * hardware encapsulation features instead of standard @@ -3984,7 +3994,7 @@ netdev_features_t netif_skb_features(struct sk_buff *skb) return harmonize_features(skb, features); } -EXPORT_SYMBOL(netif_skb_features); +EXPORT_SYMBOL(__netif_skb_features); static int xmit_one(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq, bool more) From c4076626ba520ecf710755046bf5ae6f2fd5b965 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 8 Oct 2026 18:06:48 +0800 Subject: [PATCH 1515/2126] net: gso: support re-segmentation of TCP GSO skbs A caller which re-segments an oversized TCP GSO skb needs the engine to group several MSS into one output skb, so let it pass how many MSS segments each output skb may carry through __skb_gso_segment(). max_segs is a per-call u8 in the skb_gso_cb scratch context, and only an unencapsulated TCP skb without a frag_list sets it; every other caller passes zero. Without max_segs, skb_segment() groups several MSS into one output skb only for a device which advertises NETIF_F_GSO_PARTIAL, or for a frag_list which splits into uniform pieces. max_segs skips that test. The output stays a GSO skb: gso_size keeps the original MSS and gso_segs the number of MSS it holds, so a downstream device can still perform TSO. The caller keeps the output within the 64 KiB its L3 length field can express. Reviewed-by: Willem de Bruijn Assisted-by: LLM Signed-off-by: Wang Zhan Link: https://patch.msgid.link/20261008100651.2534957-4-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- drivers/net/tap.c | 3 ++- include/net/gso.h | 7 +++++-- include/net/udp.h | 2 +- net/core/gso.c | 6 +++++- net/core/skbuff.c | 10 +++++++--- net/openvswitch/datapath.c | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 832439b8a898..2f19fb07bb2d 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -278,9 +278,10 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) if (q->flags & IFF_VNET_HDR) features |= tap->tap_features; if (netif_needs_gso(skb, features)) { - struct sk_buff *segs = __skb_gso_segment(skb, features, false); + struct sk_buff *segs; struct sk_buff *next; + segs = __skb_gso_segment(skb, features, false, 0); if (IS_ERR(segs)) { drop_reason = SKB_DROP_REASON_SKB_GSO_SEG; goto drop; diff --git a/include/net/gso.h b/include/net/gso.h index 0749230d414e..fe3260b381d4 100644 --- a/include/net/gso.h +++ b/include/net/gso.h @@ -21,6 +21,8 @@ struct skb_gso_cb { __u16 csum_start; /* Number of IPv4/IPv6 GSO handler entries for this packet. */ u8 recursion_counter; + /* Max MSS segs per output skb, 0 = no limit */ + u8 max_segs; }; #define SKB_GSO_CB_OFFSET 32 #define SKB_GSO_CB(skb) ((struct skb_gso_cb *)((skb)->cb + SKB_GSO_CB_OFFSET)) @@ -83,12 +85,13 @@ static inline __sum16 gso_make_checksum(struct sk_buff *skb, __wsum res) } struct sk_buff *__skb_gso_segment(struct sk_buff *skb, - netdev_features_t features, bool tx_path); + netdev_features_t features, bool tx_path, + unsigned int max_segs); static inline struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features) { - return __skb_gso_segment(skb, features, true); + return __skb_gso_segment(skb, features, true, 0); } struct sk_buff *skb_eth_gso_segment(struct sk_buff *skb, diff --git a/include/net/udp.h b/include/net/udp.h index 1fee17274745..5bc25dcf25fb 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -613,7 +613,7 @@ static inline struct sk_buff *udp_rcv_segment(struct sock *sk, /* the GSO CB lays after the UDP one, no need to save and restore any * CB fragment */ - segs = __skb_gso_segment(skb, features, false); + segs = __skb_gso_segment(skb, features, false, 0); if (IS_ERR_OR_NULL(segs)) { drop_count = skb_shinfo(skb)->gso_segs; goto drop; diff --git a/net/core/gso.c b/net/core/gso.c index e96ef6350064..b5bd269e56e4 100644 --- a/net/core/gso.c +++ b/net/core/gso.c @@ -77,6 +77,8 @@ static bool skb_needs_check(const struct sk_buff *skb, bool tx_path) * @skb: buffer to segment * @features: features for the output path (see dev->features) * @tx_path: whether it is called in TX path + * @max_segs: maximum MSS segments per output GSO skb, 0 means no limit; + * set only for an unencapsulated TCP skb without a frag_list * * This function segments the given skb and returns a list of segments. * @@ -86,7 +88,8 @@ static bool skb_needs_check(const struct sk_buff *skb, bool tx_path) * Segmentation preserves SKB_GSO_CB_OFFSET bytes of previous skb cb. */ struct sk_buff *__skb_gso_segment(struct sk_buff *skb, - netdev_features_t features, bool tx_path) + netdev_features_t features, bool tx_path, + unsigned int max_segs) { struct sk_buff *segs; @@ -118,6 +121,7 @@ struct sk_buff *__skb_gso_segment(struct sk_buff *skb, SKB_GSO_CB(skb)->mac_offset = skb_headroom(skb); SKB_GSO_CB(skb)->encap_level = 0; SKB_GSO_CB(skb)->recursion_counter = 0; + SKB_GSO_CB(skb)->max_segs = min(max_segs, U8_MAX); skb_reset_mac_header(skb); skb_reset_mac_len(skb); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d56f4f0102f7..c53de400127f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4797,6 +4797,7 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, struct sk_buff *segs = NULL; struct sk_buff *tail = NULL; struct sk_buff *list_skb = skb_shinfo(head_skb)->frag_list; + unsigned int max_segs = SKB_GSO_CB(head_skb)->max_segs; unsigned int mss = skb_shinfo(head_skb)->gso_size; bool gso_by_frags = mss == GSO_BY_FRAGS; unsigned int doffset = head_skb->data - skb_mac_header(head_skb); @@ -4843,7 +4844,7 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, csum = !!can_checksum_protocol(features, proto); if (sg && csum && !gso_by_frags) { - if (!(features & NETIF_F_GSO_PARTIAL)) { + if (!max_segs && !(features & NETIF_F_GSO_PARTIAL)) { struct sk_buff *iter; unsigned int frag_len; @@ -4877,8 +4878,11 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, * doesn't fit into an MSS sized block, so take care of that * now. */ - DEBUG_NET_WARN_ON_ONCE(len / mss > GSO_MAX_SEGS); - partial_segs = min(len / mss, GSO_MAX_SEGS); + DEBUG_NET_WARN_ON_ONCE(!max_segs && len / mss > GSO_MAX_SEGS); + if (max_segs) + partial_segs = min(len / mss, max_segs); + else + partial_segs = min(len / mss, GSO_MAX_SEGS); if (partial_segs > 1) mss *= partial_segs; else diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 42835694f35c..b2a0b09fd4a5 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -375,7 +375,7 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, int err; BUILD_BUG_ON(sizeof(*OVS_CB(skb)) > SKB_GSO_CB_OFFSET); - segs = __skb_gso_segment(skb, NETIF_F_SG, false); + segs = __skb_gso_segment(skb, NETIF_F_SG, false, 0); if (IS_ERR(segs)) return PTR_ERR(segs); if (segs == NULL) From 335a0378a7556eb818df5cc03281319d7c15ee20 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 8 Oct 2026 18:06:49 +0800 Subject: [PATCH 1516/2126] net: gso: clear the GSO state of the last output segment skb_segment() clears gso_size on the last output of a group which holds one MSS or less, but leaves gso_segs and gso_type as the grouping set them, so the tail is still counted as the whole group. Readers which take gso_segs without testing gso_size first, such as the ECT statistics in ip_rcv_core() and tp->rcv_ooopack in tcp_rcv_established(), see that stale count, and a re-segmented output reaches them when a veth or bridge port delivers it back into the receive path. Clear gso_size, gso_segs and gso_type together with skb_gso_reset(). Suggested-by: Willem de Bruijn Assisted-by: LLM Signed-off-by: Wang Zhan Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20261008100651.2534957-5-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- net/core/skbuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c53de400127f..b25d8e2c9aaf 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5129,7 +5129,7 @@ perform_csum_check: } if (tail->len - doffset <= gso_size) - skb_shinfo(tail)->gso_size = 0; + skb_gso_reset(tail); else if (tail != segs) skb_shinfo(tail)->gso_segs = DIV_ROUND_UP(tail->len - doffset, gso_size); } From 32bfd220cd6f70698f9b8828302a9b85065c95c1 Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 8 Oct 2026 18:06:50 +0800 Subject: [PATCH 1517/2126] net: core: re-segment oversized TCP GSO skbs An skb which exceeds an egress device limit loses its GSO feature mask and is segmented into individual packets, although the device can still offload smaller TCP GSO skbs. A BIG TCP hop which feeds a non-BIG TCP one pays that on every flow. An unencapsulated TCP GSO skb which exceeds gso_max_size or gso_max_segs is re-segmented with a max_segs which keeps each output inside that limit. An encapsulated or frag-list skb, a GSO type the device cannot offload, a max_segs which leaves room for a single MSS and an skb whose transport header is unset or stale all keep today's segmentation. This path emits a plain GSO skb, not a BIG TCP one: inet_gso_segment() and ipv6_gso_segment() write each output's whole length into the 16-bit L3 length field, so the size limit is also capped at what that field can express. The helper runs on the skb handed to the driver and only from the netif_needs_gso() branch: an skb the device takes as it is pays nothing, and an over-limit one pays the TCP header read and the features recomputation. Measured on a veth -> bridge -> TAP -> guest virtio-net path, with BIG TCP enabled on the veth endpoints and left off in the guest, so the skbs which the veth hop accepts have to be segmented before the TAP device. A single iperf3 TCP flow, six alternating runs per state (`-t 15 -O 5`, fixed CPU affinity and port tuple). The middle column is the same tree with the re-segmentation disabled: protocol no BIG TCP mixed, no reseg mixed, resegmented TCP/IPv4 51.550 Gbps 15.850 Gbps 52.617 Gbps TCP/IPv6 52.050 Gbps 15.783 Gbps 51.933 Gbps Coefficient of variation for the two mixed columns was 0.48% and 0.82% for IPv4 and 0.44% and 0.44% for IPv6. A BIG TCP hop which feeds a 64 KiB hop loses 69% of the throughput of a path which never enables BIG TCP at all; re-segmentation recovers it, 3.3x over the existing segmentation path and within noise of the no BIG TCP baseline. Reviewed-by: Willem de Bruijn Assisted-by: LLM Signed-off-by: Wang Zhan Link: https://patch.msgid.link/20261008100651.2534957-6-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- net/core/dev.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 4ea6ea4b111e..8eb9bf1ff9eb 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3996,6 +3996,53 @@ __netif_skb_features(struct sk_buff *skb, bool check_gso_limits) } EXPORT_SYMBOL(__netif_skb_features); +static unsigned int +skb_gso_output_max_segs(struct sk_buff *skb, struct net_device *dev) +{ + unsigned int mss = skb_shinfo(skb)->gso_size; + unsigned int gso_max_size, hdr_len, max_segs; + netdev_features_t features; + struct tcphdr _tcph, *th; + + if (!skb_is_gso(skb) || !skb_is_gso_tcp(skb) || + skb->encapsulation || skb_has_frag_list(skb)) + return 0; + + /* + * The transport offset can be unset or stale, so hdr_len is only taken + * from a header at the checksum start. + */ + if (!skb_transport_header_was_set(skb) || + skb_checksum_start(skb) != skb_transport_header(skb)) + return 0; + + th = skb_header_pointer(skb, skb_transport_offset(skb), sizeof(_tcph), + &_tcph); + if (!th || __tcp_hdrlen(th) < sizeof(*th)) + return 0; + + hdr_len = skb_transport_header(skb) - skb_mac_header(skb) + + __tcp_hdrlen(th); + + /* The output is still a GSO skb: recheck without the limit checks */ + features = __netif_skb_features(skb, false) | NETIF_F_GSO_ROBUST; + if (!net_gso_ok(features, skb_shinfo(skb)->gso_type)) + return 0; + + gso_max_size = netif_get_gso_max_size(dev, skb); + gso_max_size = min(gso_max_size, GSO_LEGACY_MAX_SIZE); + + /* + * gso_within_dev_limits() accepts gso_segs == gso_max_segs but + * rejects skb->len >= gso_max_size, so only the size limit needs the + * - 1; the inner min() keeps that subtraction from wrapping. + */ + max_segs = (gso_max_size - min(gso_max_size, hdr_len + 1)) / mss; + max_segs = min(max_segs, READ_ONCE(dev->gso_max_segs)); + + return max_segs; +} + static int xmit_one(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq, bool more) { @@ -4159,9 +4206,13 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device goto out_null; if (netif_needs_gso(skb, features)) { + unsigned int max_segs = 0; struct sk_buff *segs; - segs = skb_gso_segment(skb, features); + if (unlikely(!gso_within_dev_limits(skb, dev))) + max_segs = skb_gso_output_max_segs(skb, dev); + + segs = __skb_gso_segment(skb, features, true, max_segs); if (IS_ERR(segs)) { goto out_kfree_skb; } else if (segs) { From a374c5bb41d1ea72e732153d6a8d17b4e2434d3f Mon Sep 17 00:00:00 2001 From: Wang Zhan Date: Thu, 8 Oct 2026 18:06:51 +0800 Subject: [PATCH 1518/2126] net: net_test: add tests for TCP re-segmentation The GSO engine can now be asked to group several MSS segments into one output skb, which is what re-segmentation needs. Add KUnit coverage for the max_segs parameter. The parameterized GSO test gains a max_segs input and four cases: a limit of two MSS applied to a 3003 byte and to a 5003 byte payload, a tail which holds one MSS and is therefore not a GSO skb, and a max_segs of one MSS which must leave the output unchanged. It drives skb_segment() directly, because the synthetic protocol it uses has no gso_segment callback. Assisted-by: LLM Signed-off-by: Wang Zhan Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20261008100651.2534957-7-wang.zhan@smartx.com Signed-off-by: Paolo Abeni --- net/core/net_test.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/net/core/net_test.c b/net/core/net_test.c index 9c3a590865d2..bc2ef7612e7d 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -5,6 +5,7 @@ /* GSO */ #include +#include static const char hdr[] = "abcdefgh"; #define GSO_TEST_SIZE 1000 @@ -34,6 +35,10 @@ enum gso_test_nr { GSO_TEST_FRAG_LIST_PURE, GSO_TEST_FRAG_LIST_NON_UNIFORM, GSO_TEST_GSO_BY_FRAGS, + GSO_TEST_RESEGMENT, + GSO_TEST_RESEGMENT_MULTI, + GSO_TEST_RESEGMENT_TAIL, + GSO_TEST_RESEGMENT_ONE_MSS, }; struct gso_test_case { @@ -46,10 +51,12 @@ struct gso_test_case { const unsigned int *frags; unsigned int nr_frag_skbs; const unsigned int *frag_skbs; + unsigned int max_segs; /* output as expected */ unsigned int nr_segs; const unsigned int *segs; + const unsigned int *gso_segs; }; static struct gso_test_case cases[] = { @@ -135,6 +142,68 @@ static struct gso_test_case cases[] = { .nr_segs = 4, .segs = (const unsigned int[]) { 100, 200, 300, 400 }, }, + { + .id = GSO_TEST_RESEGMENT, + .name = "resegment", + .linear_len = GSO_TEST_SIZE, + .nr_frags = 3, + .frags = (const unsigned int[]) { + GSO_TEST_SIZE, GSO_TEST_SIZE, 3, + }, + .max_segs = 2, + .nr_segs = 2, + .segs = (const unsigned int[]) { + 2 * GSO_TEST_SIZE, GSO_TEST_SIZE + 3, + }, + .gso_segs = (const unsigned int[]) { 2, 2 }, + }, + { + .id = GSO_TEST_RESEGMENT_MULTI, + .name = "resegment_multi", + .linear_len = 2 * GSO_TEST_SIZE, + .nr_frags = 4, + .frags = (const unsigned int[]) { + GSO_TEST_SIZE, GSO_TEST_SIZE, GSO_TEST_SIZE, 3, + }, + .max_segs = 2, + .nr_segs = 3, + .segs = (const unsigned int[]) { + 2 * GSO_TEST_SIZE, 2 * GSO_TEST_SIZE, GSO_TEST_SIZE + 3, + }, + .gso_segs = (const unsigned int[]) { 2, 2, 2 }, + }, + { + /* The last output is not a GSO skb. */ + .id = GSO_TEST_RESEGMENT_TAIL, + .name = "resegment_tail", + .linear_len = GSO_TEST_SIZE, + .nr_frags = 2, + .frags = (const unsigned int[]) { + GSO_TEST_SIZE, 400, + }, + .max_segs = 2, + .nr_segs = 2, + .segs = (const unsigned int[]) { + 2 * GSO_TEST_SIZE, 400, + }, + .gso_segs = (const unsigned int[]) { 2, 0 }, + }, + { + /* max_segs of 1 is the same as no limit. */ + .id = GSO_TEST_RESEGMENT_ONE_MSS, + .name = "resegment_one_mss", + .linear_len = GSO_TEST_SIZE, + .nr_frags = 3, + .frags = (const unsigned int[]) { + GSO_TEST_SIZE, GSO_TEST_SIZE, 3, + }, + .max_segs = 1, + .nr_segs = 4, + .segs = (const unsigned int[]) { + GSO_TEST_SIZE, GSO_TEST_SIZE, GSO_TEST_SIZE, 3, + }, + .gso_segs = (const unsigned int[]) { 0, 0, 0, 0 }, + }, }; static void gso_test_case_to_desc(struct gso_test_case *t, char *desc) @@ -226,6 +295,7 @@ static void gso_test_func(struct kunit *test) if (tcase->id == GSO_TEST_FRAG_LIST_NON_UNIFORM) features &= ~NETIF_F_SG; + SKB_GSO_CB(skb)->max_segs = tcase->max_segs; segs = skb_segment(skb, features); if (IS_ERR(segs)) { KUNIT_FAIL(test, "segs error %pe", segs); @@ -239,6 +309,9 @@ static void gso_test_func(struct kunit *test) for (cur = segs, i = 0; cur; cur = next, i++) { next = cur->next; + if (i >= tcase->nr_segs) + goto consume; + KUNIT_ASSERT_EQ(test, cur->len, sizeof(hdr) + tcase->segs[i]); /* segs have skb->data pointing to the mac header */ @@ -247,11 +320,25 @@ static void gso_test_func(struct kunit *test) /* header was copied to all segs */ KUNIT_ASSERT_EQ(test, memcmp(skb_mac_header(cur), hdr, sizeof(hdr)), 0); + if (tcase->gso_segs) { + unsigned int gso_segs = tcase->gso_segs[i]; + + KUNIT_EXPECT_EQ(test, skb_shinfo(cur)->gso_segs, + gso_segs); + if (!gso_segs) { + KUNIT_EXPECT_FALSE(test, skb_is_gso(cur)); + } else { + KUNIT_EXPECT_TRUE(test, skb_is_gso(cur)); + KUNIT_EXPECT_EQ(test, skb_shinfo(cur)->gso_size, + GSO_TEST_SIZE); + } + } /* last seg can be found through segs->prev pointer */ if (!next) KUNIT_ASSERT_PTR_EQ(test, cur, last); +consume: consume_skb(cur); } From 48b7611964e1fa74ec2abd410f66881fc7087428 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Tue, 6 Oct 2026 15:51:06 +0200 Subject: [PATCH 1519/2126] net: sparx5: Add registers used by TAS Add the registers and offset definitions used to configure the Time Aware Shaper (802.1Qbv) in hardware, on both sparx5 and lan969x. Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261006-sparx5-tas-v1-1-5eef1126dfd5@microchip.com Signed-off-by: Paolo Abeni --- .../microchip/sparx5/lan969x/lan969x_regs.c | 10 + .../microchip/sparx5/sparx5_main_regs.h | 204 ++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_regs.c | 10 + .../ethernet/microchip/sparx5/sparx5_regs.h | 10 + 4 files changed, 234 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c index 3fc2c006ba12..175fcf8bdd61 100644 --- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c +++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c @@ -96,6 +96,9 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = { [GA_HSCH_MMGT] = 36260, [GA_HSCH_TAS_CONFIG] = 37696, [GA_HSCH_TAS_PROFILE_CFG] = 37712, + [GA_HSCH_TAS_LIST_CFG] = 36288, + [GA_HSCH_TAS_GCL_CFG] = 36240, + [GA_HSCH_HSCH_TAS_STATE] = 36256, [GA_PTP_PTP_CFG] = 512, [GA_PTP_PTP_TOD_DOMAINS] = 528, [GA_PTP_PHASE_DETECTOR_CTRL] = 628, @@ -147,6 +150,7 @@ const unsigned int lan969x_gsize[GSIZE_LAST] = { [GW_GCB_CHIP_REGS] = 180, [GW_HSCH_TAS_CONFIG] = 16, [GW_HSCH_TAS_PROFILE_CFG] = 68, + [GW_HSCH_TAS_GCL_CFG] = 16, [GW_PTP_PHASE_DETECTOR_CTRL] = 12, [GW_QSYS_PAUSE_CFG] = 988, }; @@ -201,6 +205,12 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = { [FW_HSCH_HSCH_LEAK_CFG_LEAK_FIRST] = 14, [FW_HSCH_FLUSH_CTRL_FLUSH_PORT] = 6, [FW_HSCH_FLUSH_CTRL_FLUSH_HIER] = 14, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX] = 6, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM] = 6, + [FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM] = 12, + [FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS] = 11, + [FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX] = 6, + [FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR] = 12, [FW_LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_DIRECT_ROW] = 13, [FW_LRN_MAC_ACCESS_CFG_3_MAC_ENTRY_ISDX_LIMIT_IDX] = 8, [FW_LRN_AUTOAGE_CFG_2_NEXT_ROW] = 13, diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h index d34467513648..1464fd1a1d44 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h @@ -5358,6 +5358,50 @@ extern const struct sparx5_regs *regs; #define HSCH_RESET_CFG_CORE_ENA_GET(x)\ FIELD_GET(HSCH_RESET_CFG_CORE_ENA, x) +/* HSCH:TAS_CONFIG:TAS_CFG_CTRL */ +#define HSCH_TAS_CFG_CTRL \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_CONFIG], 0, 1, \ + regs->gsize[GW_HSCH_TAS_CONFIG], 0, 0, 1, 4) + +#define HSCH_TAS_CFG_CTRL_LIST_NUM_MAX\ + GENMASK(regs->fsize[FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX] + 22 - 1, 22) +#define HSCH_TAS_CFG_CTRL_LIST_NUM_MAX_SET(x)\ + spx5_field_prep(HSCH_TAS_CFG_CTRL_LIST_NUM_MAX, x) +#define HSCH_TAS_CFG_CTRL_LIST_NUM_MAX_GET(x)\ + spx5_field_get(HSCH_TAS_CFG_CTRL_LIST_NUM_MAX, x) + +#define HSCH_TAS_CFG_CTRL_LIST_NUM\ + GENMASK(regs->fsize[FW_HSCH_TAS_CFG_CTRL_LIST_NUM] + 15 - 1, 15) +#define HSCH_TAS_CFG_CTRL_LIST_NUM_SET(x)\ + spx5_field_prep(HSCH_TAS_CFG_CTRL_LIST_NUM, x) +#define HSCH_TAS_CFG_CTRL_LIST_NUM_GET(x)\ + spx5_field_get(HSCH_TAS_CFG_CTRL_LIST_NUM, x) + +#define HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q BIT(14) +#define HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q_SET(x)\ + FIELD_PREP(HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q, x) +#define HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q_GET(x)\ + FIELD_GET(HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q, x) + +#define HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM\ + GENMASK(regs->fsize[FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM] + 0 - 1, 0) +#define HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM_SET(x)\ + spx5_field_prep(HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM, x) +#define HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM_GET(x)\ + spx5_field_get(HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM, x) + +/* HSCH:TAS_CONFIG:TAS_GATE_STATE_CTRL */ +#define HSCH_TAS_GATE_STATE_CTRL \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_CONFIG], 0, 1, \ + regs->gsize[GW_HSCH_TAS_CONFIG], 4, 0, 1, 4) + +#define HSCH_TAS_GATE_STATE_CTRL_HSCH_POS\ + GENMASK(regs->fsize[FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS] + 0 - 1, 0) +#define HSCH_TAS_GATE_STATE_CTRL_HSCH_POS_SET(x)\ + spx5_field_prep(HSCH_TAS_GATE_STATE_CTRL_HSCH_POS, x) +#define HSCH_TAS_GATE_STATE_CTRL_HSCH_POS_GET(x)\ + spx5_field_get(HSCH_TAS_GATE_STATE_CTRL_HSCH_POS, x) + /* HSCH:TAS_CONFIG:TAS_STATEMACHINE_CFG */ #define HSCH_TAS_STATEMACHINE_CFG \ __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_CONFIG], 0, 1, \ @@ -5375,12 +5419,172 @@ extern const struct sparx5_regs *regs; regs->gcnt[GC_HSCH_TAS_PROFILE_CFG], \ regs->gsize[GW_HSCH_TAS_PROFILE_CFG], 32, 0, 1, 4) +/* SPARX5 ONLY */ +#define HSCH_TAS_PROFILE_CONFIG_PORT_NUM GENMASK(17, 11) +#define HSCH_TAS_PROFILE_CONFIG_PORT_NUM_SET(x)\ + FIELD_PREP(HSCH_TAS_PROFILE_CONFIG_PORT_NUM, x) +#define HSCH_TAS_PROFILE_CONFIG_PORT_NUM_GET(x)\ + FIELD_GET(HSCH_TAS_PROFILE_CONFIG_PORT_NUM, x) + #define HSCH_TAS_PROFILE_CONFIG_LINK_SPEED GENMASK(10, 8) #define HSCH_TAS_PROFILE_CONFIG_LINK_SPEED_SET(x)\ FIELD_PREP(HSCH_TAS_PROFILE_CONFIG_LINK_SPEED, x) #define HSCH_TAS_PROFILE_CONFIG_LINK_SPEED_GET(x)\ FIELD_GET(HSCH_TAS_PROFILE_CONFIG_LINK_SPEED, x) +/* HSCH:TAS_LIST_CFG:TAS_BASE_TIME_NSEC */ +#define HSCH_TAS_BASE_TIME_NSEC \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 0, 0, 1, 4) + +#define HSCH_TAS_BASE_TIME_NSEC_BASE_TIME_NSEC GENMASK(29, 0) +#define HSCH_TAS_BASE_TIME_NSEC_BASE_TIME_NSEC_SET(x)\ + FIELD_PREP(HSCH_TAS_BASE_TIME_NSEC_BASE_TIME_NSEC, x) +#define HSCH_TAS_BASE_TIME_NSEC_BASE_TIME_NSEC_GET(x)\ + FIELD_GET(HSCH_TAS_BASE_TIME_NSEC_BASE_TIME_NSEC, x) + +/* HSCH:TAS_LIST_CFG:TAS_BASE_TIME_SEC_LSB */ +#define HSCH_TAS_BASE_TIME_SEC_LSB \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 4, 0, 1, 4) + +/* HSCH:TAS_LIST_CFG:TAS_BASE_TIME_SEC_MSB */ +#define HSCH_TAS_BASE_TIME_SEC_MSB \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 8, 0, 1, 4) + +#define HSCH_TAS_BASE_TIME_SEC_MSB_BASE_TIME_SEC_MSB GENMASK(15, 0) +#define HSCH_TAS_BASE_TIME_SEC_MSB_BASE_TIME_SEC_MSB_SET(x)\ + FIELD_PREP(HSCH_TAS_BASE_TIME_SEC_MSB_BASE_TIME_SEC_MSB, x) +#define HSCH_TAS_BASE_TIME_SEC_MSB_BASE_TIME_SEC_MSB_GET(x)\ + FIELD_GET(HSCH_TAS_BASE_TIME_SEC_MSB_BASE_TIME_SEC_MSB, x) + +/* HSCH:TAS_LIST_CFG:TAS_CYCLE_TIME_CFG */ +#define HSCH_TAS_CYCLE_TIME_CFG \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 24, 0, 1, 4) + +/* HSCH:TAS_LIST_CFG:TAS_STARTUP_CFG */ +#define HSCH_TAS_STARTUP_CFG \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 28, 0, 1, 4) + +#define HSCH_TAS_STARTUP_CFG_STARTUP_TIME GENMASK(21, 0) +#define HSCH_TAS_STARTUP_CFG_STARTUP_TIME_SET(x)\ + FIELD_PREP(HSCH_TAS_STARTUP_CFG_STARTUP_TIME, x) +#define HSCH_TAS_STARTUP_CFG_STARTUP_TIME_GET(x)\ + FIELD_GET(HSCH_TAS_STARTUP_CFG_STARTUP_TIME, x) + +#define HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX\ + GENMASK(regs->fsize[FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX] + 23 - 1, 23) +#define HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX_SET(x)\ + spx5_field_prep(HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX, x) +#define HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX_GET(x)\ + spx5_field_get(HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX, x) + +#define HSCH_TAS_STARTUP_CFG_STARTUP_ERROR BIT(22) +#define HSCH_TAS_STARTUP_CFG_STARTUP_ERROR_SET(x)\ + FIELD_PREP(HSCH_TAS_STARTUP_CFG_STARTUP_ERROR, x) +#define HSCH_TAS_STARTUP_CFG_STARTUP_ERROR_GET(x)\ + FIELD_GET(HSCH_TAS_STARTUP_CFG_STARTUP_ERROR, x) + +/* HSCH:TAS_LIST_CFG:TAS_LIST_CFG */ +#define HSCH_TAS_LIST_CFG \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 32, 0, 1, 4) + +#define HSCH_TAS_LIST_CFG_LIST_BASE_ADDR\ + GENMASK(regs->fsize[FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR] + 0 - 1, 0) +#define HSCH_TAS_LIST_CFG_LIST_BASE_ADDR_SET(x)\ + spx5_field_prep(HSCH_TAS_LIST_CFG_LIST_BASE_ADDR, x) +#define HSCH_TAS_LIST_CFG_LIST_BASE_ADDR_GET(x)\ + spx5_field_get(HSCH_TAS_LIST_CFG_LIST_BASE_ADDR, x) + +/* SPARX5 ONLY */ +#define HSCH_TAS_LIST_CFG_LIST_LENGTH GENMASK(29, 16) +#define HSCH_TAS_LIST_CFG_LIST_LENGTH_SET(x)\ + FIELD_PREP(HSCH_TAS_LIST_CFG_LIST_LENGTH, x) +#define HSCH_TAS_LIST_CFG_LIST_LENGTH_GET(x)\ + FIELD_GET(HSCH_TAS_LIST_CFG_LIST_LENGTH, x) + +/* LAN969X ONLY */ +#define HSCH_TAS_LIST_CFG_LIST_HSCH_POS GENMASK(31, 21) +#define HSCH_TAS_LIST_CFG_LIST_HSCH_POS_SET(x)\ + FIELD_PREP(HSCH_TAS_LIST_CFG_LIST_HSCH_POS, x) +#define HSCH_TAS_LIST_CFG_LIST_HSCH_POS_GET(x)\ + FIELD_GET(HSCH_TAS_LIST_CFG_LIST_HSCH_POS, x) + +/* LAN969X ONLY */ +#define HSCH_TAS_LIST_CFG_LIST_PORT_NUM GENMASK(20, 16) +#define HSCH_TAS_LIST_CFG_LIST_PORT_NUM_SET(x)\ + FIELD_PREP(HSCH_TAS_LIST_CFG_LIST_PORT_NUM, x) +#define HSCH_TAS_LIST_CFG_LIST_PORT_NUM_GET(x)\ + FIELD_GET(HSCH_TAS_LIST_CFG_LIST_PORT_NUM, x) + +/* HSCH:TAS_LIST_CFG:TAS_LIST_STATE */ +#define HSCH_TAS_LIST_STATE \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_LIST_CFG], 0, 1, 64, \ + 36, 0, 1, 4) + +#define HSCH_TAS_LIST_STATE_LIST_STATE GENMASK(2, 0) +#define HSCH_TAS_LIST_STATE_LIST_STATE_SET(x)\ + FIELD_PREP(HSCH_TAS_LIST_STATE_LIST_STATE, x) +#define HSCH_TAS_LIST_STATE_LIST_STATE_GET(x)\ + FIELD_GET(HSCH_TAS_LIST_STATE_LIST_STATE, x) + +/* HSCH:TAS_GCL_CFG:TAS_GCL_CTRL_CFG */ +#define HSCH_TAS_GCL_CTRL_CFG \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_GCL_CFG], 0, 1, \ + regs->gsize[GW_HSCH_TAS_GCL_CFG], 0, 0, 1, 4) + +#define HSCH_TAS_GCL_CTRL_CFG_GATE_STATE GENMASK(27, 20) +#define HSCH_TAS_GCL_CTRL_CFG_GATE_STATE_SET(x)\ + FIELD_PREP(HSCH_TAS_GCL_CTRL_CFG_GATE_STATE, x) +#define HSCH_TAS_GCL_CTRL_CFG_GATE_STATE_GET(x)\ + FIELD_GET(HSCH_TAS_GCL_CTRL_CFG_GATE_STATE, x) + +/* SPARX5 ONLY */ +#define HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE GENMASK(19, 13) +#define HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE_SET(x)\ + FIELD_PREP(HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE, x) +#define HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE_GET(x)\ + FIELD_GET(HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE, x) + +/* SPARX5 ONLY */ +#define HSCH_TAS_GCL_CTRL_CFG_HSCH_POS GENMASK(12, 0) +#define HSCH_TAS_GCL_CTRL_CFG_HSCH_POS_SET(x)\ + FIELD_PREP(HSCH_TAS_GCL_CTRL_CFG_HSCH_POS, x) +#define HSCH_TAS_GCL_CTRL_CFG_HSCH_POS_GET(x)\ + FIELD_GET(HSCH_TAS_GCL_CTRL_CFG_HSCH_POS, x) + +/* HSCH:TAS_GCL_CFG:TAS_GCL_TIME_CFG */ +#define HSCH_TAS_GCL_TIME_CFG \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_GCL_CFG], 0, 1, \ + regs->gsize[GW_HSCH_TAS_GCL_CFG], 4, 0, 1, 4) + +/* LAN969X ONLY */ +/* HSCH:TAS_GCL_CFG:TAS_GCL_CTRL_CFG2 */ +#define HSCH_TAS_GCL_CTRL_CFG2 \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_TAS_GCL_CFG], 0, 1, \ + regs->gsize[GW_HSCH_TAS_GCL_CFG], 8, 0, 1, 4) + +#define HSCH_TAS_GCL_CTRL_CFG2_NEXT_GCL GENMASK(11, 0) +#define HSCH_TAS_GCL_CTRL_CFG2_NEXT_GCL_SET(x)\ + FIELD_PREP(HSCH_TAS_GCL_CTRL_CFG2_NEXT_GCL, x) +#define HSCH_TAS_GCL_CTRL_CFG2_NEXT_GCL_GET(x)\ + FIELD_GET(HSCH_TAS_GCL_CTRL_CFG2_NEXT_GCL, x) + +/* HSCH:HSCH_TAS_STATE:TAS_GATE_STATE */ +#define HSCH_TAS_GATE_STATE \ + __REG(TARGET_HSCH, 0, 1, regs->gaddr[GA_HSCH_HSCH_TAS_STATE], 0, 1, 4, \ + 0, 0, 1, 4) + +#define HSCH_TAS_GATE_STATE_TAS_GATE_STATE GENMASK(7, 0) +#define HSCH_TAS_GATE_STATE_TAS_GATE_STATE_SET(x)\ + FIELD_PREP(HSCH_TAS_GATE_STATE_TAS_GATE_STATE, x) +#define HSCH_TAS_GATE_STATE_TAS_GATE_STATE_GET(x)\ + FIELD_GET(HSCH_TAS_GATE_STATE_TAS_GATE_STATE, x) + /* LAN969X ONLY */ /* HSIOWRAP:XMII_CFG:XMII_CFG */ #define HSIO_WRAP_XMII_CFG(g) \ diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_regs.c b/drivers/net/ethernet/microchip/sparx5/sparx5_regs.c index 3863f954bd83..75c1bd4f0053 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_regs.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_regs.c @@ -96,6 +96,9 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = { [GA_HSCH_MMGT] = 162368, [GA_HSCH_TAS_CONFIG] = 162384, [GA_HSCH_TAS_PROFILE_CFG] = 188416, + [GA_HSCH_TAS_LIST_CFG] = 161600, + [GA_HSCH_TAS_GCL_CFG] = 161584, + [GA_HSCH_HSCH_TAS_STATE] = 161580, [GA_PTP_PTP_CFG] = 320, [GA_PTP_PTP_TOD_DOMAINS] = 336, [GA_PTP_PHASE_DETECTOR_CTRL] = 420, @@ -147,6 +150,7 @@ const unsigned int sparx5_gsize[GSIZE_LAST] = { [GW_GCB_CHIP_REGS] = 424, [GW_HSCH_TAS_CONFIG] = 12, [GW_HSCH_TAS_PROFILE_CFG] = 64, + [GW_HSCH_TAS_GCL_CFG] = 8, [GW_PTP_PHASE_DETECTOR_CTRL] = 8, [GW_QSYS_PAUSE_CFG] = 1128, }; @@ -201,6 +205,12 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = { [FW_HSCH_HSCH_LEAK_CFG_LEAK_FIRST] = 16, [FW_HSCH_FLUSH_CTRL_FLUSH_PORT] = 7, [FW_HSCH_FLUSH_CTRL_FLUSH_HIER] = 16, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX] = 7, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM] = 7, + [FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM] = 14, + [FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS] = 13, + [FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX] = 7, + [FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR] = 14, [FW_LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_DIRECT_ROW] = 14, [FW_LRN_MAC_ACCESS_CFG_3_MAC_ENTRY_ISDX_LIMIT_IDX] = 11, [FW_LRN_AUTOAGE_CFG_2_NEXT_ROW] = 14, diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_regs.h b/drivers/net/ethernet/microchip/sparx5/sparx5_regs.h index 585589a31e90..97d496ebb750 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_regs.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_regs.h @@ -105,6 +105,9 @@ enum sparx5_gaddr_enum { GA_HSCH_MMGT, GA_HSCH_TAS_CONFIG, GA_HSCH_TAS_PROFILE_CFG, + GA_HSCH_TAS_LIST_CFG, + GA_HSCH_TAS_GCL_CFG, + GA_HSCH_HSCH_TAS_STATE, GA_PTP_PTP_CFG, GA_PTP_PTP_TOD_DOMAINS, GA_PTP_PHASE_DETECTOR_CTRL, @@ -158,6 +161,7 @@ enum sparx5_gsize_enum { GW_GCB_CHIP_REGS, GW_HSCH_TAS_CONFIG, GW_HSCH_TAS_PROFILE_CFG, + GW_HSCH_TAS_GCL_CFG, GW_PTP_PHASE_DETECTOR_CTRL, GW_QSYS_PAUSE_CFG, GSIZE_LAST, @@ -214,6 +218,12 @@ enum sparx5_fsize_enum { FW_HSCH_HSCH_LEAK_CFG_LEAK_FIRST, FW_HSCH_FLUSH_CTRL_FLUSH_PORT, FW_HSCH_FLUSH_CTRL_FLUSH_HIER, + FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX, + FW_HSCH_TAS_CFG_CTRL_LIST_NUM, + FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM, + FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS, + FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX, + FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR, FW_LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_DIRECT_ROW, FW_LRN_MAC_ACCESS_CFG_3_MAC_ENTRY_ISDX_LIMIT_IDX, FW_LRN_AUTOAGE_CFG_2_NEXT_ROW, From 966285085456a20491cd5714f53d8a917266867e Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Tue, 6 Oct 2026 15:51:07 +0200 Subject: [PATCH 1520/2126] net: sparx5: Move TAS link speed configuration to sparx5_tas.c Move sparx5_tas_speed() and its link speed enum from sparx5_qos.c to a new sparx5_tas.c, which the following TAS offload patch builds on. No functional change. Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261006-sparx5-tas-v1-2-5eef1126dfd5@microchip.com Signed-off-by: Paolo Abeni --- .../net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/sparx5_main.h | 3 + .../ethernet/microchip/sparx5/sparx5_qos.c | 49 ---------------- .../ethernet/microchip/sparx5/sparx5_qos.h | 1 - .../ethernet/microchip/sparx5/sparx5_tas.c | 56 +++++++++++++++++++ 5 files changed, 60 insertions(+), 51 deletions(-) create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_tas.c diff --git a/drivers/net/ethernet/microchip/sparx5/Makefile b/drivers/net/ethernet/microchip/sparx5/Makefile index d447f9e84d92..06cf583effdb 100644 --- a/drivers/net/ethernet/microchip/sparx5/Makefile +++ b/drivers/net/ethernet/microchip/sparx5/Makefile @@ -11,7 +11,7 @@ sparx5-switch-y := sparx5_main.o sparx5_packet.o \ sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \ sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \ sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o \ - sparx5_psfp.o sparx5_mirror.o sparx5_regs.o + sparx5_psfp.o sparx5_mirror.o sparx5_regs.o sparx5_tas.o sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 0f7d8440f614..41e0597a8d48 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -707,6 +707,9 @@ void sparx5_psfp_init(struct sparx5 *sparx5); void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time, const ktime_t org_base_time, ktime_t *new_base_time); +/* sparx5_tas.c */ +void sparx5_tas_speed(struct sparx5_port *port, int speed); + /* sparx5_mirror.c */ int sparx5_mirror_add(struct sparx5_mall_entry *entry); void sparx5_mirror_del(struct sparx5_mall_entry *entry); diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c index 972da8a71f5a..e580670f3992 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c @@ -9,17 +9,6 @@ #include "sparx5_main.h" #include "sparx5_qos.h" -enum sparx5_tas_link_speed { - TAS_SPEED_NO_GB, - TAS_SPEED_10, - TAS_SPEED_100, - TAS_SPEED_1000, - TAS_SPEED_2500, - TAS_SPEED_5000, - TAS_SPEED_10000, - TAS_SPEED_25000, -}; - /* Calculate new base_time based on cycle_time. * * The hardware requires a base_time that is always in the future. @@ -592,41 +581,3 @@ int sparx5_tc_ets_del(struct sparx5_port *port) return sparx5_dwrr_conf_set(port, &dwrr); } - -void sparx5_tas_speed(struct sparx5_port *port, int speed) -{ - struct sparx5 *sparx5 = port->sparx5; - u8 spd; - - switch (speed) { - case SPEED_10: - spd = TAS_SPEED_10; - break; - case SPEED_100: - spd = TAS_SPEED_100; - break; - case SPEED_1000: - spd = TAS_SPEED_1000; - break; - case SPEED_2500: - spd = TAS_SPEED_2500; - break; - case SPEED_5000: - spd = TAS_SPEED_5000; - break; - case SPEED_10000: - spd = TAS_SPEED_10000; - break; - case SPEED_25000: - spd = TAS_SPEED_25000; - break; - default: - netdev_err(port->ndev, "TAS: Unsupported speed: %d\n", speed); - return; - } - - spx5_rmw(HSCH_TAS_PROFILE_CONFIG_LINK_SPEED_SET(spd), - HSCH_TAS_PROFILE_CONFIG_LINK_SPEED, - sparx5, - HSCH_TAS_PROFILE_CONFIG(port->portno)); -} diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h index a92a699c551f..04f76f1e23f6 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.h @@ -60,7 +60,6 @@ struct sparx5_dwrr { }; int sparx5_qos_init(struct sparx5 *sparx5); -void sparx5_tas_speed(struct sparx5_port *port, int speed); /* Multi-Queue Priority */ int sparx5_tc_mqprio_add(struct net_device *ndev, u8 num_tc); diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c new file mode 100644 index 000000000000..3637d4b48ad6 --- /dev/null +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Microchip Sparx5 Switch driver + * + * Copyright (c) 2026 Microchip Technology Inc. and its subsidiaries. + */ + +#include "sparx5_main.h" + +enum sparx5_tas_link_speed { + TAS_SPEED_NO_GB, + TAS_SPEED_10, + TAS_SPEED_100, + TAS_SPEED_1000, + TAS_SPEED_2500, + TAS_SPEED_5000, + TAS_SPEED_10000, + TAS_SPEED_25000, +}; + +void sparx5_tas_speed(struct sparx5_port *port, int speed) +{ + struct sparx5 *sparx5 = port->sparx5; + u8 spd; + + switch (speed) { + case SPEED_10: + spd = TAS_SPEED_10; + break; + case SPEED_100: + spd = TAS_SPEED_100; + break; + case SPEED_1000: + spd = TAS_SPEED_1000; + break; + case SPEED_2500: + spd = TAS_SPEED_2500; + break; + case SPEED_5000: + spd = TAS_SPEED_5000; + break; + case SPEED_10000: + spd = TAS_SPEED_10000; + break; + case SPEED_25000: + spd = TAS_SPEED_25000; + break; + default: + netdev_err(port->ndev, "TAS: Unsupported speed: %d\n", speed); + return; + } + + spx5_rmw(HSCH_TAS_PROFILE_CONFIG_LINK_SPEED_SET(spd), + HSCH_TAS_PROFILE_CONFIG_LINK_SPEED, + sparx5, + HSCH_TAS_PROFILE_CONFIG(port->portno)); +} From a52629f85a3a97f76a12b9cb97717a36318a708e Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Tue, 6 Oct 2026 15:51:08 +0200 Subject: [PATCH 1521/2126] net: sparx5: Add TAS offload support The Time Aware Shaper (TAS, IEEE 802.1Qbv) opens and closes the gates of a port's egress queues according to a repeating schedule, so that traffic classes are only sent in their own time windows. In hardware, a schedule is run by a TAS list, which steps through gate control list (GCL) entries taken from a pool shared by all ports. A list is started with a base time, and it can stop another list when it takes over, which allows a schedule to be replaced without a gap. Add TAS offload for sparx5 and lan969x, configured through tc-taprio. Use two TAS lists per port, so that a new schedule can be programmed in one list while the other is operating. Allocate the GCL entries of a schedule from the shared pool, and free them once their list is back in ADMIN. On lan969x, program the GCL as a linked list and address its entries by absolute index rather than relative to the list base. sparx5 has 128 TAS lists for 65 ports, so with every port present the last port gets no TAS offload. Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261006-sparx5-tas-v1-3-5eef1126dfd5@microchip.com Signed-off-by: Paolo Abeni --- .../microchip/sparx5/lan969x/lan969x.c | 2 + .../ethernet/microchip/sparx5/sparx5_main.c | 2 + .../ethernet/microchip/sparx5/sparx5_main.h | 25 + .../ethernet/microchip/sparx5/sparx5_qos.c | 4 + .../ethernet/microchip/sparx5/sparx5_tas.c | 750 ++++++++++++++++++ .../net/ethernet/microchip/sparx5/sparx5_tc.c | 17 + 6 files changed, 800 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c index f3a9c71bea36..c02499d1b297 100644 --- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c +++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c @@ -318,6 +318,8 @@ static const struct sparx5_consts lan969x_consts = { .n_gates = 256, .n_sdlbs = 496, .n_dsm_cal_taxis = 5, + .n_tas_gcl = 3000, + .n_tas_lists = 60, .buf_size = 1572864, .qres_max_prio_idx = 315, .qres_max_colour_idx = 323, diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c index b530fb6d3d0c..e039f5369b95 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c @@ -1064,6 +1064,8 @@ static const struct sparx5_consts sparx5_consts = { .n_gates = 1024, .n_sdlbs = 4096, .n_dsm_cal_taxis = 8, + .n_tas_gcl = 10000, + .n_tas_lists = 128, .buf_size = 4194280, .qres_max_prio_idx = 630, .qres_max_colour_idx = 638, diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 41e0597a8d48..8dc3a500c1c9 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -108,6 +108,7 @@ enum sparx5_feature { #define SPX5_PRIOS 8 /* Number of priority queues */ #define SPX5_BUFFER_CELL_SZ 184 /* Cell size */ #define SPX5_BUFFER_MEMORY 4194280 /* 22795 words * 184 bytes */ +#define SPX5_TAS_ENTRIES_PER_PORT 2 /* TAS lists per port */ #define XTR_QUEUE 0 #define INJ_QUEUE 0 @@ -236,6 +237,11 @@ struct sparx5_port { struct sk_buff_head tx_skbs; bool is_mrouter; struct list_head tc_templates; /* list of TC templates on this port */ + /* TAS GCL entries owned by each of the port's two TAS lists. */ + struct { + int gcl_base; + int gcl_count; + } tas_lists[SPX5_TAS_ENTRIES_PER_PORT]; }; enum sparx5_core_clockfreq { @@ -316,6 +322,8 @@ struct sparx5_consts { u32 n_gates; /* Number of PSFP gates */ u32 n_sdlbs; /* Number of service dual leaky buckets */ u32 n_dsm_cal_taxis; /* Number of DSM calendar taxis */ + u32 n_tas_gcl; /* Number of TAS gate control list entries */ + u32 n_tas_lists; /* Number of TAS lists */ u32 buf_size; /* Amount of QLIM watermark memory */ u32 qres_max_prio_idx; /* Maximum QRES prio index */ u32 qres_max_colour_idx; /* Maximum QRES colour index */ @@ -374,6 +382,8 @@ struct sparx5 { void __iomem *regs[NUM_TARGETS]; int port_count; struct mutex lock; /* MAC reg lock */ + struct mutex tas_lock; /* Time Aware Shaper lock */ + unsigned long *tas_gcl_bitmap; /* Allocated TAS GCL entries */ /* port structures are in net device */ struct sparx5_port *ports[SPX5_PORTS]; enum sparx5_core_clockfreq coreclock; @@ -708,6 +718,21 @@ void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time, const ktime_t org_base_time, ktime_t *new_base_time); /* sparx5_tas.c */ +/* TAS list states, mirrors the HSCH_TAS_LIST_STATE_LIST_STATE HW field */ +enum sparx5_tas_state { + SPX5_TAS_STATE_ADMIN, + SPX5_TAS_STATE_ADVANCING, + SPX5_TAS_STATE_PENDING, + SPX5_TAS_STATE_OPERATING, + SPX5_TAS_STATE_TERMINATING, + SPX5_NUM_TAS_STATE, +}; + +int sparx5_tas_init(struct sparx5 *sparx5); +struct tc_taprio_qopt_offload; +int sparx5_tas_enable(struct sparx5_port *port, + struct tc_taprio_qopt_offload *qopt); +int sparx5_tas_disable(struct sparx5_port *port); void sparx5_tas_speed(struct sparx5_port *port, int speed); /* sparx5_mirror.c */ diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c index e580670f3992..7370533243b6 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_qos.c @@ -457,6 +457,10 @@ int sparx5_qos_init(struct sparx5 *sparx5) if (ret < 0) return ret; + ret = sparx5_tas_init(sparx5); + if (ret) + return ret; + sparx5_psfp_init(sparx5); return 0; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c index 3637d4b48ad6..ec80bc69371a 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tas.c @@ -4,7 +4,10 @@ * Copyright (c) 2026 Microchip Technology Inc. and its subsidiaries. */ +#include + #include "sparx5_main.h" +#include "sparx5_qos.h" enum sparx5_tas_link_speed { TAS_SPEED_NO_GB, @@ -17,6 +20,753 @@ enum sparx5_tas_link_speed { TAS_SPEED_25000, }; +/* Maximum time in milliseconds to wait for TAS state transitions. */ +#define TAS_TIMEOUT_MS 2000 + +/* Minimum supported cycle time in nanoseconds */ +#define TAS_MIN_CYCLE_TIME_NS (1 * NSEC_PER_USEC) /* 1 usec */ + +/* Maximum supported cycle time in nanoseconds */ +#define TAS_MAX_CYCLE_TIME_NS ((1 * NSEC_PER_SEC) - 1) /* 999.999.999 nsec */ + +/* STARTUP_TIME in units of 256 ns, must be non-zero for a list to start */ +#define TAS_STARTUP_TIME_DEFAULT 8 + +/* We use 2 TAS lists per present port, as far as the chip has lists: + * num_tas_lists = min(port_count * SPX5_TAS_ENTRIES_PER_PORT, n_tas_lists); + * + * The index for the 2 entries of the n'th present port is calculated as: + * index_1 = n * SPX5_TAS_ENTRIES_PER_PORT; + * index_2 = index_1 + 1; + * + * GCL entries are allocated from a bitmap shared by all ports and sized to the + * chip's GCL pool. Each list records the range it owns. The range is freed + * once hardware reports the list back in ADMIN, which for a list obsoleted by + * a replace happens some time after the replace itself. Entry 0 is reserved: + * unwritten NEXT_GCL fields read as 0, so a list must never own it. + * + * We use 1 TAS profile per port, shared by both of its lists: + * index = portno; + * + * We do not yet support frame preemption and the default guard band + * of 1536 bytes is always used on all queues. + * + * The gate mask of each entry is written as is to the port's 8 queues, + * where bit n gates queue (QoS class) n. The mqprio parameters of the + * taprio qdisc (prio_tc_map, queue ranges) are not used, so a schedule + * must use 8 traffic classes mapped 1:1 to the queues, as with the + * mqprio offload. Other values of num_tc are rejected. + * + * These are the possible combinations of states for the two TAS lists in a + * running system. + * + * ADMIN/ADMIN: No schedules are currently operating or pending. + * + * ADMIN/PENDING: No schedule is currently operating but one is pending and + * when current time exceeds the configured base time it will automatically + * enter the OPERATING state. The state is now ADMIN/OPERATING. + * + * ADMIN/OPERATING: A schedule is currently operating and will run until it is + * terminated manually. + * + * OPERATING/PENDING: A schedule is currently operating and another is + * pending. When current time exceeds the configured base time for the + * pending schedule it will automatically stop the operating schedule and + * enter the OPERATING state. The state is now ADMIN/OPERATING. + * + * When we want to disable TAS on a port, we must stop schedules that are in + * state PENDING or OPERATING. + * Pending schedules are stopped first and then operating schedules. + * The gate state for the port must be restored to "all-queues-open" manually + * in case the schedule was stopped with one or more of the queues closed. + * + * When we add a schedule we always use a base time in the future, where base + * time is at least current time + (2 * cycle time). This is a requirement + * from the hardware. This means that a schedule will always start in state + * PENDING. It also means that we always use the new schedule to stop an + * eventually operating schedule. + * + * When we want to add a new schedule we must consider the current state of + * the two TAS list entries: + * + * ADMIN/ADMIN: Just add the new schedule in one of the TAS lists. + * + * ADMIN/PENDING: Stop the current pending schedule and add the new one. + * + * ADMIN/OPERATING: Add the new schedule in the TAS list that is currently in + * admin state and configure it to stop the currently operating schedule when + * current time exceeds the configured base time in the new schedule. + * + * OPERATING/PENDING: Stop the current pending schedule, add the new one and + * configure it to stop the currently operating schedule when + * current time exceeds the configured base time in the new schedule. + */ + +/* Scheduler element index (HSCH_POS) for this port's per-port TAS gate, + * i.e. its position at the layer-2 boundary of the scheduling hierarchy. + */ +static int sparx5_tas_scheduler_get(struct sparx5 *sparx5, int portno) +{ + if (is_sparx5(sparx5)) + return SPX5_HSCH_L0_SE_CNT + SPX5_HSCH_L1_SE_CNT + portno; + else + return 1120 + portno; +} + +static int sparx5_tas_list_index(struct sparx5_port *port, u8 tas_entry) +{ + const struct sparx5_consts *consts = port->sparx5->data->consts; + int portno, pidx = 0; + + /* Limit the index to available ports: the n'th present port uses + * lists 2n and 2n + 1, so the lists of all ports fit in + * port_count * SPX5_TAS_ENTRIES_PER_PORT. + */ + for (portno = 0; portno < consts->n_ports; ++portno) { + if (portno == port->portno) + return (pidx * SPX5_TAS_ENTRIES_PER_PORT) + tas_entry; + if (port->sparx5->ports[portno]) + pidx++; + } + + return 0; +} + +/* Number of TAS lists in use: two per present port, as far as the chip has + * lists for. A port whose lists fall outside this range has no TAS. + */ +static int sparx5_tas_num_lists(struct sparx5 *sparx5) +{ + return min_t(int, sparx5->port_count * SPX5_TAS_ENTRIES_PER_PORT, + sparx5->data->consts->n_tas_lists); +} + +static bool sparx5_tas_port_has_lists(struct sparx5_port *port) +{ + return sparx5_tas_list_index(port, SPX5_TAS_ENTRIES_PER_PORT - 1) < + sparx5_tas_num_lists(port->sparx5); +} + +static const char *sparx5_tas_state_to_str(int state) +{ + switch (state) { + case SPX5_TAS_STATE_ADMIN: + return "ADMIN"; + case SPX5_TAS_STATE_ADVANCING: + return "ADVANCING"; + case SPX5_TAS_STATE_PENDING: + return "PENDING"; + case SPX5_TAS_STATE_OPERATING: + return "OPERATING"; + case SPX5_TAS_STATE_TERMINATING: + return "TERMINATING"; + default: + return "??"; + } +} + +static void sparx5_tas_select_list(struct sparx5 *sparx5, int list) +{ + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_SET(list), + HSCH_TAS_CFG_CTRL_LIST_NUM, + sparx5, + HSCH_TAS_CFG_CTRL); +} + +static int sparx5_tas_list_state_get(struct sparx5 *sparx5) +{ + return HSCH_TAS_LIST_STATE_LIST_STATE_GET(spx5_rd(sparx5, + HSCH_TAS_LIST_STATE)); +} + +static int sparx5_tas_gcl_alloc(struct sparx5 *sparx5, int count) +{ + u32 n_gcl = sparx5->data->consts->n_tas_gcl; + unsigned long base; + + base = bitmap_find_next_zero_area(sparx5->tas_gcl_bitmap, + n_gcl, + 0, + count, + 0); + if (base >= n_gcl) + return -ENOSPC; + + bitmap_set(sparx5->tas_gcl_bitmap, base, count); + + return base; +} + +static void sparx5_tas_gcl_free(struct sparx5_port *port, int slot) +{ + if (port->tas_lists[slot].gcl_count) + bitmap_clear(port->sparx5->tas_gcl_bitmap, + port->tas_lists[slot].gcl_base, + port->tas_lists[slot].gcl_count); + + port->tas_lists[slot].gcl_base = 0; + port->tas_lists[slot].gcl_count = 0; +} + +/* Free the GCL entries of every list that hardware has returned to ADMIN */ +static void sparx5_tas_gcl_flush(struct sparx5 *sparx5) +{ + struct sparx5_port *port; + int i, j; + + lockdep_assert_held(&sparx5->tas_lock); + + for (i = 0; i < sparx5->data->consts->n_ports; i++) { + port = sparx5->ports[i]; + if (!port) + continue; + + for (j = 0; j < SPX5_TAS_ENTRIES_PER_PORT; j++) { + if (!port->tas_lists[j].gcl_count) + continue; + + sparx5_tas_select_list(sparx5, + sparx5_tas_list_index(port, j)); + if (sparx5_tas_list_state_get(sparx5) == + SPX5_TAS_STATE_ADMIN) + sparx5_tas_gcl_free(port, j); + } + } +} + +/* Request state 'req' (or only wait if 'req' < 0) on the selected list until + * it reaches a state in the 'done' mask. + */ +static int sparx5_tas_list_state_wait(struct sparx5_port *port, int list, + int req, u32 done) +{ + struct sparx5 *sparx5 = port->sparx5; + unsigned long end; + int state; + + /* Do not wait forever for the state change */ + end = jiffies + msecs_to_jiffies(TAS_TIMEOUT_MS); + do { + if (req >= 0) + spx5_rmw(HSCH_TAS_LIST_STATE_LIST_STATE_SET(req), + HSCH_TAS_LIST_STATE_LIST_STATE, + sparx5, + HSCH_TAS_LIST_STATE); + + state = sparx5_tas_list_state_get(sparx5); + if (BIT(state) & done) + return 0; + + cond_resched(); + } while (!time_after(jiffies, end)); + + netdev_err(port->ndev, "Timeout switching TAS state %s in list %d\n", + sparx5_tas_state_to_str(state), list); + + return -ETIME; +} + +/* Wait for hardware to bring the selected list back to ADMIN */ +static int sparx5_tas_wait_admin(struct sparx5_port *port, int list) +{ + return sparx5_tas_list_state_wait(port, list, -1, + BIT(SPX5_TAS_STATE_ADMIN)); +} + +static int sparx5_tas_shutdown_pending(struct sparx5_port *port) +{ + struct sparx5 *sparx5 = port->sparx5; + int i, list, state, err; + + for (i = 0; i < SPX5_TAS_ENTRIES_PER_PORT; i++) { + list = sparx5_tas_list_index(port, i); + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_SET(list), + HSCH_TAS_CFG_CTRL_LIST_NUM, + sparx5, + HSCH_TAS_CFG_CTRL); + + state = sparx5_tas_list_state_get(sparx5); + if (state != SPX5_TAS_STATE_ADVANCING && + state != SPX5_TAS_STATE_PENDING) + continue; + + err = sparx5_tas_list_state_wait(port, list, + SPX5_TAS_STATE_ADMIN, + BIT(SPX5_TAS_STATE_ADMIN)); + if (err) + return err; + + sparx5_tas_gcl_free(port, i); + } + + return 0; +} + +static int sparx5_tas_shutdown_operating(struct sparx5_port *port) +{ + struct sparx5 *sparx5 = port->sparx5; + int i, list, state, err = 0; + u32 sched; + + sched = sparx5_tas_scheduler_get(sparx5, port->portno); + + for (i = 0; i < SPX5_TAS_ENTRIES_PER_PORT; i++) { + list = sparx5_tas_list_index(port, i); + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_SET(list), + HSCH_TAS_CFG_CTRL_LIST_NUM, + sparx5, + HSCH_TAS_CFG_CTRL); + + /* A list being stopped still runs its gate operations until + * the end of its cycle, so wait for it before opening the + * gates. + */ + state = sparx5_tas_list_state_get(sparx5); + if (state != SPX5_TAS_STATE_OPERATING && + state != SPX5_TAS_STATE_TERMINATING) + continue; + + if (state == SPX5_TAS_STATE_OPERATING && + sparx5_tas_list_state_wait(port, list, + SPX5_TAS_STATE_TERMINATING, + BIT(SPX5_TAS_STATE_TERMINATING) | + BIT(SPX5_TAS_STATE_ADMIN))) { + err = -ETIME; + continue; + } + + if (sparx5_tas_wait_admin(port, list)) { + err = -ETIME; + continue; + } + + sparx5_tas_gcl_free(port, i); + } + + /* Restore gate state to "all-queues-open". */ + + /* Select port n on layer 2 of Hierarchical Scheduler */ + spx5_wr(HSCH_TAS_GATE_STATE_CTRL_HSCH_POS_SET(sched), + sparx5, + HSCH_TAS_GATE_STATE_CTRL); + + /* Set gate state to "all-queues-open" */ + spx5_wr(HSCH_TAS_GATE_STATE_TAS_GATE_STATE_SET(0xff), + sparx5, + HSCH_TAS_GATE_STATE); + + return err; +} + +/* Find an ADMIN list for a new schedule, after stopping a pending one. An + * operating list is returned in obsolete, to be stopped by the new list. + */ +static int sparx5_tas_list_find(struct sparx5_port *port, int *new, + int *obsolete) +{ + int i, err, oper = -1, state_cnt[SPX5_NUM_TAS_STATE] = {0}; + struct sparx5 *sparx5 = port->sparx5; + int state[SPX5_TAS_ENTRIES_PER_PORT]; + int list[SPX5_TAS_ENTRIES_PER_PORT]; + bool valid = false; + + err = sparx5_tas_shutdown_pending(port); + if (err) + return err; + + for (i = 0; i < SPX5_TAS_ENTRIES_PER_PORT; i++) { + list[i] = sparx5_tas_list_index(port, i); + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_SET(list[i]), + HSCH_TAS_CFG_CTRL_LIST_NUM, + sparx5, + HSCH_TAS_CFG_CTRL); + + state[i] = sparx5_tas_list_state_get(sparx5); + + if (state[i] == SPX5_TAS_STATE_TERMINATING) { + err = sparx5_tas_wait_admin(port, list[i]); + if (err) + return err; + state[i] = SPX5_TAS_STATE_ADMIN; + } + + if (state[i] >= SPX5_NUM_TAS_STATE) { + netdev_err(port->ndev, + "Invalid tas list state %u %u %d\n", + state[i], port->portno, i); + return -EINVAL; + } + + if (state[i] == SPX5_TAS_STATE_OPERATING) + oper = list[i]; + + state_cnt[state[i]]++; + } + + if (state_cnt[SPX5_TAS_STATE_ADMIN] == 2) + valid = true; + + if (state_cnt[SPX5_TAS_STATE_ADMIN] == 1 && + state_cnt[SPX5_TAS_STATE_OPERATING] == 1) + valid = true; + + if (!valid) { + netdev_err(port->ndev, + "Invalid tas state combination: %d %d %d %d %d\n", + state_cnt[SPX5_TAS_STATE_ADMIN], + state_cnt[SPX5_TAS_STATE_ADVANCING], + state_cnt[SPX5_TAS_STATE_PENDING], + state_cnt[SPX5_TAS_STATE_OPERATING], + state_cnt[SPX5_TAS_STATE_TERMINATING]); + + return -EINVAL; + } + + for (i = 0; i < SPX5_TAS_ENTRIES_PER_PORT; i++) { + if (state[i] == SPX5_TAS_STATE_ADMIN) { + *new = list[i]; + *obsolete = (oper == -1) ? *new : oper; + return 0; + } + } + + return -EBUSY; /* No suitable list found */ +} + +/* Program the list and its GCL entries [base, base + num_entries) */ +static void sparx5_tas_gcl_setup(struct sparx5_port *port, int list, int base, + struct tc_taprio_qopt_offload *qopt) +{ + struct sparx5 *sparx5 = port->sparx5; + u32 sched, entry, prof; + int i; + + sched = sparx5_tas_scheduler_get(sparx5, port->portno); + /* Each port uses the TAS profile of its own number */ + prof = port->portno; + + /* Program only the chosen list; the sibling slot stays in ADMIN. */ + sparx5_tas_select_list(sparx5, list); + + spx5_rmw(HSCH_TAS_LIST_CFG_LIST_BASE_ADDR_SET(base), + HSCH_TAS_LIST_CFG_LIST_BASE_ADDR, + sparx5, + HSCH_TAS_LIST_CFG); + + if (is_sparx5(sparx5)) { + spx5_rmw(HSCH_TAS_LIST_CFG_LIST_LENGTH_SET(qopt->num_entries), + HSCH_TAS_LIST_CFG_LIST_LENGTH, + sparx5, + HSCH_TAS_LIST_CFG); + } else { + /* Associate TAS list with physical port number and + * scheduler element. + */ + spx5_rmw(HSCH_TAS_LIST_CFG_LIST_PORT_NUM_SET(port->portno), + HSCH_TAS_LIST_CFG_LIST_PORT_NUM, sparx5, + HSCH_TAS_LIST_CFG); + spx5_rmw(HSCH_TAS_LIST_CFG_LIST_HSCH_POS_SET(sched), + HSCH_TAS_LIST_CFG_LIST_HSCH_POS, sparx5, + HSCH_TAS_LIST_CFG); + } + + for (i = 0; i < qopt->num_entries; i++) { + u32 gcl_next = (i >= qopt->num_entries - 1) ? base : + base + i + 1; + u32 gate_mask = qopt->entries[i].gate_mask; + + /* On sparx5 GCL_ENTRY_NUM is relative to the list's BASE_ADDR. + * On lan969x the GCL is a linked list and GCL_ENTRY_NUM is an + * absolute index into the pool, as is NEXT_GCL. + */ + entry = is_sparx5(sparx5) ? i : base + i; + + spx5_rmw(HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM_SET(entry), + HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM, + sparx5, + HSCH_TAS_CFG_CTRL); + + /* Set gate states for this GCL */ + spx5_rmw(HSCH_TAS_GCL_CTRL_CFG_GATE_STATE_SET(gate_mask), + HSCH_TAS_GCL_CTRL_CFG_GATE_STATE, sparx5, + HSCH_TAS_GCL_CTRL_CFG); + + if (is_sparx5(sparx5)) { + spx5_rmw(HSCH_TAS_GCL_CTRL_CFG_HSCH_POS_SET(sched) | + HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE_SET(prof), + HSCH_TAS_GCL_CTRL_CFG_HSCH_POS | + HSCH_TAS_GCL_CTRL_CFG_PORT_PROFILE, sparx5, + HSCH_TAS_GCL_CTRL_CFG); + } else { + /* The GCL list is a linked list on lan969x */ + spx5_wr(HSCH_TAS_GCL_CTRL_CFG2_NEXT_GCL_SET(gcl_next), + sparx5, HSCH_TAS_GCL_CTRL_CFG2); + } + + spx5_wr(qopt->entries[i].interval, + sparx5, + HSCH_TAS_GCL_TIME_CFG); + } +} + +int sparx5_tas_enable(struct sparx5_port *port, + struct tc_taprio_qopt_offload *qopt) +{ + u64 cycle_time = qopt->cycle_time, calculated_cycle_time = 0; + int i, err, base, slot, state, new_list = -1, obsolete = -1; + struct sparx5 *sparx5 = port->sparx5; + struct timespec64 ts; + ktime_t base_time; + unsigned long end; + u32 startup, val; + + if (qopt->cycle_time_extension) { + netdev_err(port->ndev, + "cycle_time_extension is not supported\n"); + return -EOPNOTSUPP; + } + + /* The base time is taken from the PTP clock */ + if (!sparx5->ptp) + return -EOPNOTSUPP; + + if (qopt->base_time < 0) { + netdev_err(port->ndev, "Invalid base_time %lld\n", + qopt->base_time); + return -EINVAL; + } + + if (!sparx5_tas_port_has_lists(port)) { + netdev_err(port->ndev, "No TAS lists left for this port\n"); + return -EOPNOTSUPP; + } + + if (qopt->mqprio.qopt.num_tc != SPX5_PRIOS) { + netdev_err(port->ndev, "Only %d traffic classes supported\n", + SPX5_PRIOS); + return -EOPNOTSUPP; + } + + for (i = 0; i < qopt->num_entries; i++) { + if (qopt->entries[i].command != TC_TAPRIO_CMD_SET_GATES) { + netdev_err(port->ndev, "Unsupported GCL command: %d\n", + qopt->entries[i].command); + return -EOPNOTSUPP; + } + } + + mutex_lock(&sparx5->tas_lock); + + sparx5_tas_gcl_flush(sparx5); + + if (cycle_time > TAS_MAX_CYCLE_TIME_NS) { + netdev_err(port->ndev, "Invalid cycle_time %llu\n", cycle_time); + err = -EINVAL; + goto out; + } + + for (i = 0; i < qopt->num_entries; i++) { + u32 interval = qopt->entries[i].interval; + + if (interval < TAS_MIN_CYCLE_TIME_NS) { + netdev_err(port->ndev, + "Invalid minimum cycle time %u\n", interval); + err = -EINVAL; + goto out; + } + + if (interval > TAS_MAX_CYCLE_TIME_NS) { + netdev_err(port->ndev, + "Invalid maximum cycle time %u\n", interval); + err = -EINVAL; + goto out; + } + + calculated_cycle_time += interval; + } + + if (calculated_cycle_time > TAS_MAX_CYCLE_TIME_NS || + cycle_time < calculated_cycle_time) { + netdev_err(port->ndev, "Invalid cycle_time %llu\n", cycle_time); + err = -EINVAL; + goto out; + } + + sparx5_new_base_time(sparx5, cycle_time, qopt->base_time, &base_time); + + /* Allocate before sparx5_tas_list_find() stops a pending schedule, so + * running out of GCL entries fails the replace without touching + * hardware. + */ + base = sparx5_tas_gcl_alloc(sparx5, qopt->num_entries); + if (base < 0) { + netdev_err(port->ndev, "No room for %zu GCL entries\n", + qopt->num_entries); + err = base; + goto out; + } + + /* Select an appropriate entry to use */ + err = sparx5_tas_list_find(port, &new_list, &obsolete); + if (err) { + bitmap_clear(sparx5->tas_gcl_bitmap, base, qopt->num_entries); + goto out; + } + + /* The new list is in ADMIN, so a range it still owns can go */ + slot = new_list - sparx5_tas_list_index(port, 0); + sparx5_tas_gcl_free(port, slot); + + sparx5_tas_gcl_setup(port, new_list, base, qopt); + + /* The obsolete list keeps its entries until it reaches ADMIN */ + port->tas_lists[slot].gcl_base = base; + port->tas_lists[slot].gcl_count = qopt->num_entries; + + /* Setup TAS list */ + ts = ktime_to_timespec64(base_time); + spx5_wr(HSCH_TAS_BASE_TIME_NSEC_BASE_TIME_NSEC_SET(ts.tv_nsec), + sparx5, + HSCH_TAS_BASE_TIME_NSEC); + + spx5_wr((ts.tv_sec & GENMASK(31, 0)), + sparx5, + HSCH_TAS_BASE_TIME_SEC_LSB); + + val = ts.tv_sec >> 32; + spx5_wr(HSCH_TAS_BASE_TIME_SEC_MSB_BASE_TIME_SEC_MSB_SET(val), + sparx5, + HSCH_TAS_BASE_TIME_SEC_MSB); + + spx5_wr(cycle_time, + sparx5, + HSCH_TAS_CYCLE_TIME_CFG); + + /* Full write, to also clear a sticky STARTUP_ERROR from a previous use + * of this list. + */ + spx5_wr(HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX_SET(obsolete) | + HSCH_TAS_STARTUP_CFG_STARTUP_TIME_SET(TAS_STARTUP_TIME_DEFAULT), + sparx5, + HSCH_TAS_STARTUP_CFG); + + /* Start list processing */ + spx5_rmw(HSCH_TAS_LIST_STATE_LIST_STATE_SET(SPX5_TAS_STATE_ADVANCING), + HSCH_TAS_LIST_STATE_LIST_STATE, + sparx5, + HSCH_TAS_LIST_STATE); + + /* Do not wait forever for the startup error flag to be reported */ + end = jiffies + msecs_to_jiffies(TAS_TIMEOUT_MS); + do { + /* Read the state first, so an error that ended ADVANCING is + * already latched when STARTUP_CFG is read. + */ + val = spx5_rd(sparx5, HSCH_TAS_LIST_STATE); + state = HSCH_TAS_LIST_STATE_LIST_STATE_GET(val); + startup = spx5_rd(sparx5, HSCH_TAS_STARTUP_CFG); + if (HSCH_TAS_STARTUP_CFG_STARTUP_ERROR_GET(startup) || + state != SPX5_TAS_STATE_ADVANCING) + break; + + cond_resched(); + } while (!time_after(jiffies, end)); + + if (HSCH_TAS_STARTUP_CFG_STARTUP_ERROR_GET(startup)) { + netdev_err(port->ndev, "TAS startup error in list %d\n", + new_list); + err = -EIO; + } else if (state == SPX5_TAS_STATE_ADVANCING) { + netdev_err(port->ndev, "Timeout starting TAS list %d\n", + new_list); + err = -ETIME; + } + + /* taprio sends no DESTROY for a failed offload, so do not leave a + * list behind that may still start. + */ + if (err) + sparx5_tas_shutdown_pending(port); + +out: + mutex_unlock(&sparx5->tas_lock); + return err; +} + +int sparx5_tas_disable(struct sparx5_port *port) +{ + int err, ret; + + /* Nothing was offloaded on a port without lists */ + if (!sparx5_tas_port_has_lists(port)) + return 0; + + mutex_lock(&port->sparx5->tas_lock); + + sparx5_tas_gcl_flush(port->sparx5); + + /* Stop the operating list and restore the gates even if a pending list + * could not be stopped, as taprio does not retry a failed destroy. + */ + err = sparx5_tas_shutdown_pending(port); + ret = sparx5_tas_shutdown_operating(port); + if (!err) + err = ret; + + mutex_unlock(&port->sparx5->tas_lock); + + return err; +} + +int sparx5_tas_init(struct sparx5 *sparx5) +{ + const struct sparx5_consts *consts = sparx5->data->consts; + int i, num_ports, list_num_max; + + /* There are only 128 (sparx5) / 60 (lan969x) TAS lists, not enough + * for the whole port range. LIST_NUM_MAX is the highest list index + * processed, and the datasheet gives 24 as its minimum value. + */ + num_ports = consts->n_ports; + list_num_max = max(sparx5_tas_num_lists(sparx5) - 1, 24); + + sparx5->tas_gcl_bitmap = devm_bitmap_zalloc(sparx5->dev, + consts->n_tas_gcl, + GFP_KERNEL); + if (!sparx5->tas_gcl_bitmap) + return -ENOMEM; + + /* Unwritten NEXT_GCL fields read as 0, so no list may own entry 0 */ + bitmap_set(sparx5->tas_gcl_bitmap, 0, 1); + + mutex_init(&sparx5->tas_lock); + + /* Apply the guard band to gate closes of all traffic classes, not only + * the classes not marked as scheduled in SCH_TRAFFIC_QUEUES. + */ + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_MAX_SET(list_num_max) | + HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q_SET(1), + HSCH_TAS_CFG_CTRL_LIST_NUM_MAX | + HSCH_TAS_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q, + sparx5, + HSCH_TAS_CFG_CTRL); + + /* Associate profile with port (profile idx = port on lan969x) */ + if (is_sparx5(sparx5)) { + for (i = 0; i < num_ports; i++) { + if (!sparx5->ports[i]) + continue; + + spx5_rmw(HSCH_TAS_PROFILE_CONFIG_PORT_NUM_SET(i), + HSCH_TAS_PROFILE_CONFIG_PORT_NUM, + sparx5, + HSCH_TAS_PROFILE_CONFIG(i)); + } + } + + return 0; +} + void sparx5_tas_speed(struct sparx5_port *port, int speed) { struct sparx5 *sparx5 = port->sparx5; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc.c index 28b2514c8330..30da5db57ef3 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc.c @@ -154,6 +154,21 @@ static int sparx5_tc_setup_qdisc_ets(struct net_device *ndev, return -EOPNOTSUPP; } +static int sparx5_tc_setup_qdisc_taprio(struct net_device *ndev, + struct tc_taprio_qopt_offload *qopt) +{ + struct sparx5_port *port = netdev_priv(ndev); + + switch (qopt->cmd) { + case TAPRIO_CMD_REPLACE: + return sparx5_tas_enable(port, qopt); + case TAPRIO_CMD_DESTROY: + return sparx5_tas_disable(port); + default: + return -EOPNOTSUPP; + } +} + int sparx5_port_setup_tc(struct net_device *ndev, enum tc_setup_type type, void *type_data) { @@ -166,6 +181,8 @@ int sparx5_port_setup_tc(struct net_device *ndev, enum tc_setup_type type, return sparx5_tc_setup_qdisc_tbf(ndev, type_data); case TC_SETUP_QDISC_ETS: return sparx5_tc_setup_qdisc_ets(ndev, type_data); + case TC_SETUP_QDISC_TAPRIO: + return sparx5_tc_setup_qdisc_taprio(ndev, type_data); default: return -EOPNOTSUPP; } From 05b5019b01fb9443b09ae4ed34af1135a80a84c8 Mon Sep 17 00:00:00 2001 From: Thomas Fourier Date: Tue, 6 Oct 2026 16:09:09 +0200 Subject: [PATCH 1522/2126] net: alacritech: fix dma_free_coherent() in error path In slic_init_stat_queue(), a series of coherent buffers is allocated with the length size. The size is then stored in stq->mem_size for normal deallocation. However, in the error path, stq->mem_size is also used but is not initialized. This error may leave the freed buffers mapped, leaking a resource and allowing the device to access freed memory. Change the length in error path to size. Fixes: 60c140df15db ("net: ethernet: slicoss: add slicoss gigabit ethernet driver") Signed-off-by: Thomas Fourier Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261006140912.50828-2-fourier.thomas@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/alacritech/slicoss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/alacritech/slicoss.c b/drivers/net/ethernet/alacritech/slicoss.c index 14b74c09233e..9456ffd5067e 100644 --- a/drivers/net/ethernet/alacritech/slicoss.c +++ b/drivers/net/ethernet/alacritech/slicoss.c @@ -814,7 +814,7 @@ static int slic_init_stat_queue(struct slic_device *sdev) free_descs: while (i--) { - dma_free_coherent(&sdev->pdev->dev, stq->mem_size, + dma_free_coherent(&sdev->pdev->dev, size, stq->descs[i] - stq->addr_offset[i], stq->paddr[i] - stq->addr_offset[i]); } From f86bc8a7421defdff701addfb66b286c13abf024 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sat, 3 Oct 2026 21:22:56 +0200 Subject: [PATCH 1523/2126] wifi: nxpwifi: return timeout error from nxpwifi_sdio_poll_card_status() nxpwifi_sdio_poll_card_status() returns the result of the last register read when polling times out. If the final register read succeeds, the timeout is incorrectly reported as success. Return -ETIMEDOUT when polling runs out of retries. Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x") Assisted-by: LLM Signed-off-by: Karl Mehltretter Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.c b/drivers/net/wireless/nxp/nxpwifi/sdio.c index f4de494bf2f2..010f78270580 100644 --- a/drivers/net/wireless/nxp/nxpwifi/sdio.c +++ b/drivers/net/wireless/nxp/nxpwifi/sdio.c @@ -680,7 +680,7 @@ nxpwifi_sdio_poll_card_status(struct nxpwifi_adapter *adapter, u8 bits) nxpwifi_dbg(adapter, ERROR, "poll card status failed, tries = %d\n", tries); - return ret; + return ret ?: -ETIMEDOUT; } /* Disable SDIO host interrupt and release IRQ. */ From 12af2f77de337d353aa5c5d8b063e0d7648fe070 Mon Sep 17 00:00:00 2001 From: Aryan Sinha Date: Wed, 14 Oct 2026 00:16:25 +0530 Subject: [PATCH 1524/2126] wifi: nxpwifi: use str_on_off() for carrier state Both carrier prints open code the on/off ternary. Use the helper from string_choices.h instead. No change in output. Signed-off-by: Aryan Sinha Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/debugfs.c | 5 +++-- drivers/net/wireless/nxp/nxpwifi/main.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/debugfs.c b/drivers/net/wireless/nxp/nxpwifi/debugfs.c index cd6e73a215f0..37a69f31755d 100644 --- a/drivers/net/wireless/nxp/nxpwifi/debugfs.c +++ b/drivers/net/wireless/nxp/nxpwifi/debugfs.c @@ -6,6 +6,7 @@ */ #include +#include #include "main.h" #include "cmdevt.h" @@ -98,8 +99,8 @@ nxpwifi_info_read(struct file *file, char __user *ubuf, p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped); p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors); p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors); - p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev)) - ? "on" : "off")); + p += sprintf(p, "carrier %s\n", + str_on_off(netif_carrier_ok(priv->netdev))); p += sprintf(p, "tx queue"); for (i = 0; i < netdev->num_tx_queues; i++) { txq = netdev_get_tx_queue(netdev, i); diff --git a/drivers/net/wireless/nxp/nxpwifi/main.c b/drivers/net/wireless/nxp/nxpwifi/main.c index 505eee9e5670..3f30a1f47253 100644 --- a/drivers/net/wireless/nxp/nxpwifi/main.c +++ b/drivers/net/wireless/nxp/nxpwifi/main.c @@ -5,6 +5,7 @@ * Copyright 2011-2024 NXP */ +#include #include #include "main.h" @@ -1094,8 +1095,8 @@ void nxpwifi_drv_info_dump(struct nxpwifi_adapter *adapter) atomic_read(&priv->wmm_tx_pending[3])); p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ? "Disconnected" : "Connected"); - p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev) - ? "on" : "off")); + p += sprintf(p, "carrier %s\n", + str_on_off(netif_carrier_ok(priv->netdev))); for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) { txq = netdev_get_tx_queue(priv->netdev, idx); p += sprintf(p, "tx queue %d:%s ", idx, From 9c0c2ae7d9f4a627942c9703085943b56fbdec76 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 21 Sep 2026 23:41:11 +0300 Subject: [PATCH 1525/2126] wifi: iwlwifi: mld: Add support for (Re)association req/resp encryption Introduce support for (re)association request/response encryption if supported by the firmware. Signed-off-by: Ilan Peer Link: https://patch.msgid.link/20260921233730.25ccedf95d32.Ie2834534bd644593b61a063d4ec5f7e323be4370@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h | 2 ++ drivers/net/wireless/intel/iwlwifi/fw/file.h | 2 ++ drivers/net/wireless/intel/iwlwifi/mld/key.c | 6 ++++++ drivers/net/wireless/intel/iwlwifi/mld/mac80211.c | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h b/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h index c8eb016e1a7e..b17babef71c0 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h @@ -643,6 +643,7 @@ struct iwl_scd_queue_cfg_cmd { * @IWL_SEC_KEY_FLAG_MFP: MFP is in used for this key * @IWL_SEC_KEY_FLAG_MCAST_KEY: this is a multicast key * @IWL_SEC_KEY_FLAG_SPP_AMSDU: SPP A-MSDU should be used + * @IWL_SEC_KEY_FLAG_ASSOC_ENC: use this key for (Re)Assoc Req/Resp encryption */ enum iwl_sec_key_flags { IWL_SEC_KEY_FLAG_CIPHER_MASK = 0x07, @@ -655,6 +656,7 @@ enum iwl_sec_key_flags { IWL_SEC_KEY_FLAG_MFP = 0x20, IWL_SEC_KEY_FLAG_MCAST_KEY = 0x40, IWL_SEC_KEY_FLAG_SPP_AMSDU = 0x80, + IWL_SEC_KEY_FLAG_ASSOC_ENC = 0x200, }; #define IWL_SEC_WEP_KEY_OFFSET 3 diff --git a/drivers/net/wireless/intel/iwlwifi/fw/file.h b/drivers/net/wireless/intel/iwlwifi/fw/file.h index 664ac25754e9..3a986b394dd8 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/file.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/file.h @@ -452,6 +452,7 @@ typedef unsigned int __bitwise iwl_ucode_tlv_capa_t; * table data. For LARI_CONFIG_CHANGE command version 13 and above, this * capability is obsolete since raw DSM values are accepted by default. * @IWL_UCODE_TLV_CAPA_NAN_SYNC_SUPPORT: Supports NAN synchronization + * @IWL_UCODE_TLV_CAPA_ASSOC_ENC_SUPPORT: firmware supports association frame encryption * * @NUM_IWL_UCODE_TLV_CAPA: number of bits used */ @@ -556,6 +557,7 @@ enum iwl_ucode_tlv_capa { IWL_UCODE_TLV_CAPA_RESET_DURING_ASSERT = (__force iwl_ucode_tlv_capa_t)(4 * 32 + 0), IWL_UCODE_TLV_CAPA_FW_ACCEPTS_RAW_DSM_TABLE = (__force iwl_ucode_tlv_capa_t)(4 * 32 + 1), IWL_UCODE_TLV_CAPA_NAN_SYNC_SUPPORT = (__force iwl_ucode_tlv_capa_t)(4 * 32 + 2), + IWL_UCODE_TLV_CAPA_ASSOC_ENC_SUPPORT = (__force iwl_ucode_tlv_capa_t)(4 * 32 + 4), NUM_IWL_UCODE_TLV_CAPA /* * This construction make both sparse (which cannot increment the previous diff --git a/drivers/net/wireless/intel/iwlwifi/mld/key.c b/drivers/net/wireless/intel/iwlwifi/mld/key.c index bf80b4770b5a..f2c87f830ba3 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/key.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/key.c @@ -37,6 +37,12 @@ static u32 iwl_mld_get_key_flags(struct iwl_mld *mld, break; } + /* Note that sta->mfp might not be set yet, as it is set only + * after association. + */ + if (sta && pairwise && sta->epp_peer) + flags |= IWL_SEC_KEY_FLAG_ASSOC_ENC | IWL_SEC_KEY_FLAG_MFP; + /* If we are installing an iGTK (in AP or STA mode), we need to tell * the firmware this key will en/decrypt MGMT frames. * Same goes if we are installing a pairwise key for an MFP station. diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c index 3a4c8fda68d0..0b121114d47c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c @@ -395,6 +395,10 @@ static void iwl_mac_hw_set_wiphy(struct iwl_mld *mld) if (fw_has_capa(ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PROTECTED_TWT); + if (fw_has_capa(ucode_capa, IWL_UCODE_TLV_CAPA_ASSOC_ENC_SUPPORT)) + wiphy_ext_feature_set(wiphy, + NL80211_EXT_FEATURE_ASSOC_FRAME_ENCRYPTION); + if (iwlmld_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; else From 787f6368914c47457b7c2b95c9cecbde9cb63a4a Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Mon, 21 Sep 2026 23:41:12 +0300 Subject: [PATCH 1526/2126] wifi: iwlwifi: mvm: wait for 6 missed beacons before disconnection In case we keep getting data from the AP, wait for 6 missed beacons since last Rx before disconnecting. This will give the firmware a chance to send NDPs to the AP and avoid disconnecting if the AP is still there. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233730.025f2655b3b1.Ieceece6d8f660399e844ea4dadac414243e35d07@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h index c64e4ed00986..fb1fc9c42280 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h @@ -42,7 +42,7 @@ #define IWL_MVM_MAX_ADDRESSES 5 /* RSSI offset for WkP */ #define IWL_RSSI_OFFSET 50 -#define IWL_MVM_MISSED_BEACONS_SINCE_RX_THOLD 4 +#define IWL_MVM_MISSED_BEACONS_SINCE_RX_THOLD 6 #define IWL_MVM_MISSED_BEACONS_THRESHOLD 8 #define IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG 19 From 0a0e3d4923e03f0acb058b8839835f316265c09d Mon Sep 17 00:00:00 2001 From: Avraham Stern Date: Mon, 21 Sep 2026 23:41:13 +0300 Subject: [PATCH 1527/2126] wifi: iwlwifi: mld: config TLC only after attaching station to a link When a NAN link is activated, the TLC config command was sent for all the NAN stations. The TLC config was sent on all phys used by NAN. However, when a new NAN channel is added when there is already a NAN station (e.g. during schedule update), the station is not yet attached to the link of this phy (until the new schedule is applied by firmware). Sending a TLC command for the station on the new phy at this stage results in an assert because in firmware the station is not yet attached with the phy of this channel. Fix it by sending the TLC command only after configuring the station for the new phy. Signed-off-by: Avraham Stern Link: https://patch.msgid.link/20260921233730.24cefdd72e7d.Ib32c29716c805531f881c61d13931f5b3d7084a9@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/nan.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/nan.c b/drivers/net/wireless/intel/iwlwifi/mld/nan.c index dbe7a54a38b7..8853fcb2b4ec 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/nan.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/nan.c @@ -576,21 +576,11 @@ static int iwl_mld_nan_link_set_active(struct iwl_mld *mld, bool active) { struct iwl_link_config_cmd cmd; - struct ieee80211_sta *sta; int ret; if (nan_link->active == active) return 0; - if (active) { - for_each_station(sta, mld->hw) { - struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta); - - if (mld_sta->sta_type == STATION_TYPE_NAN_PEER_NDI) - iwl_mld_config_tlc(mld, mld_sta->vif, sta); - } - } - nan_link->active = active; iwl_mld_nan_link_prep_cmd(mld, nan_link, &cmd, @@ -602,10 +592,8 @@ static int iwl_mld_nan_link_set_active(struct iwl_mld *mld, return ret; } - if (!active) { + if (!active) nan_link->chanctx = NULL; - /* TODO: when FW is ready, Update phy in TLC to invalid after */ - } return 0; } @@ -847,6 +835,10 @@ void iwl_mld_nan_vif_cfg_changed(struct iwl_mld *mld, if (mld_sta->sta_type == STATION_TYPE_NAN_PEER_NMI || mld_sta->sta_type == STATION_TYPE_NAN_PEER_NDI) iwl_mld_add_modify_sta_cmd(mld, &sta->deflink); + + if (added_links && + mld_sta->sta_type == STATION_TYPE_NAN_PEER_NDI) + iwl_mld_config_tlc(mld, mld_sta->vif, sta); } /* From 96588f292d8d99bae25919c86a27a23b896ca7b3 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 21 Sep 2026 23:41:14 +0300 Subject: [PATCH 1528/2126] wifi: iwlwifi: document MIC delay resolution This delay is given in the same format as in the CIP capabilities. Update the comment to make it clear that the resolution is 4 us. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260921233730.0947a2665f17.Ic994dae3eddf50955eac4cf79cb6388887c75b67@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h index 09b2cddc4ad2..01db6765855c 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h @@ -868,8 +868,8 @@ struct iwl_sta_cfg_cmd_v1 { * @dps_pad_time: DPS (Dynamic Power Save) padding delay resolution to ensure * proper timing alignment * @dps_trans_delay: DPS minimal time that takes the peer to return to low power - * @mic_prep_pad_delay: MIC prep time padding - * @mic_compute_pad_delay: MIC compute time padding + * @mic_prep_pad_delay: MIC prep time padding (4 us resolution) + * @mic_compute_pad_delay: MIC compute time padding (4 us resolution) * @reserved: Reserved for alignment */ struct iwl_sta_cfg_cmd_v2 { @@ -942,8 +942,8 @@ struct iwl_sta_cfg_cmd_v2 { * proper timing alignment * @dps_trans_delay: DPS minimal time that takes the peer to return to low power * @dps_enabled: flag indicating whether or not DPS is enabled - * @mic_prep_pad_delay: MIC prep time padding - * @mic_compute_pad_delay: MIC compute time padding + * @mic_prep_pad_delay: MIC prep time padding (4 us resolution) + * @mic_compute_pad_delay: MIC compute time padding (4 us resolution) * @nmi_sta_id: for an NDI peer STA, the NMI peer STA ID it relates to * @ndi_local_addr: for an NDI peer STA or NAN multicast data station, * the local NDI interface MAC address From c4286559de5af81ada13d948e3cdc567f764b255 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Mon, 21 Sep 2026 23:41:15 +0300 Subject: [PATCH 1529/2126] wifi: iwlwifi: mld: don't use bss_conf in NAN When we receive the TLC notif, we try to fetch the band from the vif link. However, in NAN we don't have the bss_conf (link_conf[0] is technically pointing to vif::bss_conf, but it doesn't point to a channel). For now we don't have a way to fetch the channel used by this TLC instance (a NAN station can have multiple), but in the future we will have a TLC object in the driver and then we will have a phy id in it. For now, just take either the minimum between both lmacs or the only existing one. Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260921233730.18fefde9f26d.I8bc0c16de230f3bd45b80101db0936f1e4aea516@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/tlc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tlc.c b/drivers/net/wireless/intel/iwlwifi/mld/tlc.c index b6c2fa3664cb..1f5994f8be26 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tlc.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tlc.c @@ -824,8 +824,13 @@ iwl_mld_get_amsdu_size_of_tid(struct iwl_mld *mld, txf = iwl_mld_mac80211_ac_to_fw_tx_fifo(ac); - /* Only one link: take the lmac according to the band */ - if (hweight16(sta->valid_links) <= 1) { + /* + * Only one link: take the lmac according to the band + * In NAN, we don't have a link_conf. + * TODO: once we have a TLC object, we can know better the band. + */ + if (hweight16(sta->valid_links) <= 1 && + vif->type != NL80211_IFTYPE_NAN_DATA) { enum nl80211_band band; struct ieee80211_bss_conf *link = wiphy_dereference(mld->wiphy, From 56fe437aef2dc9bd37ad2b0abd9404a65d69e102 Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Mon, 21 Sep 2026 23:41:16 +0300 Subject: [PATCH 1530/2126] wifi: iwlwifi: fw: fix integer overflow in INI dump size calc The INI debug dump get_size handlers compute the region size as hdr_size + ranges * (size + sizeof(range)) using u32 arithmetic. Both the per-range size and the number of ranges originate from debug TLVs with no upper bound, so the multiplication and additions can overflow u32. A small value passes the size < sizeof(*header) check in iwl_dump_ini_mem_prep(). Add the size computation in each handler using check_add_overflow()/check_mul_overflow() and return 0 when the result would overflow. For the block handler the variable per-pair sizes are summed with check_add_overflow() before computing size, since that accumulation can overflow on its own. Signed-off-by: Shahar Tzarfati Assisted-by: GitHub-Copilot:claude-opus-4-8 Link: https://patch.msgid.link/20260921233730.0644f76cd8af.Id0d26b11fcdb33a5eff7824343caa6dc23385fd5@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 37 +++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 6621ef9358bc..a314fabbf06d 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -1016,8 +1016,16 @@ static u32 iwl_dump_ini_mem_get_size(struct iwl_fw_runtime *fwrt, if (!size || !ranges) return 0; - return sizeof(struct iwl_fw_ini_error_dump) + ranges * - (size + sizeof(struct iwl_fw_ini_error_dump_range)); + if (check_add_overflow(size, + (u32)sizeof(struct iwl_fw_ini_error_dump_range), + &size) || + check_mul_overflow(ranges, size, &size) || + check_add_overflow(size, + (u32)sizeof(struct iwl_fw_ini_error_dump), + &size)) + return 0; + + return size; } static u32 @@ -1028,15 +1036,24 @@ iwl_dump_ini_mem_block_get_size(struct iwl_fw_runtime *fwrt, struct iwl_fw_ini_addr_size *pairs = (void *)reg->addrs; u32 ranges = iwl_dump_ini_mem_block_ranges(fwrt, reg_data); u32 size = sizeof(struct iwl_fw_ini_error_dump); + u32 range_hdrs; int range; if (!ranges) return 0; for (range = 0; range < ranges; range++) - size += le32_to_cpu(pairs[range].size); + if (check_add_overflow(size, le32_to_cpu(pairs[range].size), + &size)) + return 0; - return size + ranges * sizeof(struct iwl_fw_ini_error_dump_range); + if (check_mul_overflow(ranges, + (u32)sizeof(struct iwl_fw_ini_error_dump_range), + &range_hdrs) || + check_add_overflow(size, range_hdrs, &size)) + return 0; + + return size; } static u32 @@ -1112,8 +1129,16 @@ static u32 iwl_dump_ini_mon_dbgi_get_size(struct iwl_fw_runtime *fwrt, if (!size || !ranges) return 0; - return sizeof(struct iwl_fw_ini_monitor_dump) + ranges * - (size + sizeof(struct iwl_fw_ini_error_dump_range)); + if (check_add_overflow(size, + (u32)sizeof(struct iwl_fw_ini_error_dump_range), + &size) || + check_mul_overflow(ranges, size, &size) || + check_add_overflow(size, + (u32)sizeof(struct iwl_fw_ini_monitor_dump), + &size)) + return 0; + + return size; } static u32 iwl_dump_ini_txf_get_size(struct iwl_fw_runtime *fwrt, From ef292778d590e9db4a4620175221786f84d6c34c Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Mon, 21 Sep 2026 23:41:17 +0300 Subject: [PATCH 1531/2126] wifi: iwlwifi: validate TLV length before reading fields The INI/Yoyo debug TLVs are parsed from an untrusted firmware-debug file. The dispatcher only guarantees that the TLV length covers the 8-byte common header, yet several per-type handlers dereferenced fields located beyond that header before checking the TLV length. Add the missing minimum-length check in iwl_dbg_tlv_config_set() so the short TLV is rejected before it is stored, and move the field reads in the other handlers to after their existing length checks so no field is dereferenced before the buffer is known to be large enough. Signed-off-by: Shahar Tzarfati Assisted-by: GitHub-Copilot:claude-opus-4-8 Link: https://patch.msgid.link/20260921233730.6127e849e40a.If963f766dbe29cbb8c226e163ab678be97240730@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/iwl-dbg-tlv.c | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c index 11763dec77ec..bd2a9e4b4b5f 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c @@ -167,11 +167,13 @@ static int iwl_dbg_tlv_alloc_hcmd(struct iwl_trans *trans, const struct iwl_ucode_tlv *tlv) { const struct iwl_fw_ini_hcmd_tlv *hcmd = (const void *)tlv->data; - u32 tp = le32_to_cpu(hcmd->time_point); + u32 tp; if (le32_to_cpu(tlv->length) <= sizeof(*hcmd)) return -EINVAL; + tp = le32_to_cpu(hcmd->time_point); + /* Host commands can not be sent in early time point since the FW * is not ready */ @@ -194,9 +196,14 @@ static int iwl_dbg_tlv_alloc_region(struct iwl_trans *trans, { const struct iwl_fw_ini_region_tlv *reg = (const void *)tlv->data; struct iwl_ucode_tlv **active_reg; - u32 id = le32_to_cpu(reg->id); - u8 type = reg->type; u32 tlv_len = sizeof(*tlv) + le32_to_cpu(tlv->length); + u32 id; + u8 type; + + if (le32_to_cpu(tlv->length) < sizeof(*reg)) + return -EINVAL; + + id = le32_to_cpu(reg->id); /* * The higher part of the ID from version 2 is debug policy. @@ -205,9 +212,6 @@ static int iwl_dbg_tlv_alloc_region(struct iwl_trans *trans, if (le32_to_cpu(reg->hdr.version) >= 2) id &= IWL_FW_INI_REGION_ID_MASK; - if (le32_to_cpu(tlv->length) < sizeof(*reg)) - return -EINVAL; - /* for safe use of a string from FW, limit it to IWL_FW_INI_MAX_NAME */ IWL_DEBUG_FW(trans, "WRT: parsing region: %.*s\n", IWL_FW_INI_MAX_NAME, reg->name); @@ -217,6 +221,8 @@ static int iwl_dbg_tlv_alloc_region(struct iwl_trans *trans, return -EINVAL; } + type = reg->type; + if (type <= IWL_FW_INI_REGION_INVALID || type >= IWL_FW_INI_REGION_NUM) { IWL_ERR(trans, "WRT: Invalid region type %u\n", type); @@ -251,13 +257,14 @@ static int iwl_dbg_tlv_alloc_trigger(struct iwl_trans *trans, const struct iwl_ucode_tlv *tlv) { const struct iwl_fw_ini_trigger_tlv *trig = (const void *)tlv->data; - u32 tp = le32_to_cpu(trig->time_point); - u32 rf = le32_to_cpu(trig->reset_fw); + u32 tp, rf; struct iwl_ucode_tlv *new_tlv; if (le32_to_cpu(tlv->length) < sizeof(*trig)) return -EINVAL; + tp = le32_to_cpu(trig->time_point); + if (tp <= IWL_FW_INI_TIME_POINT_INVALID || tp >= IWL_FW_INI_TIME_POINT_NUM) { IWL_ERR(trans, @@ -266,6 +273,8 @@ static int iwl_dbg_tlv_alloc_trigger(struct iwl_trans *trans, return -EINVAL; } + rf = le32_to_cpu(trig->reset_fw); + IWL_DEBUG_FW(trans, "WRT: time point %u for trigger TLV with reset_fw %u\n", tp, rf); @@ -288,8 +297,13 @@ static int iwl_dbg_tlv_config_set(struct iwl_trans *trans, const struct iwl_ucode_tlv *tlv) { const struct iwl_fw_ini_conf_set_tlv *conf_set = (const void *)tlv->data; - u32 tp = le32_to_cpu(conf_set->time_point); - u32 type = le32_to_cpu(conf_set->set_type); + u32 tp, type; + + if (le32_to_cpu(tlv->length) < sizeof(*conf_set)) + return -EINVAL; + + tp = le32_to_cpu(conf_set->time_point); + type = le32_to_cpu(conf_set->set_type); if (tp <= IWL_FW_INI_TIME_POINT_INVALID || tp >= IWL_FW_INI_TIME_POINT_NUM) { From 90f99edd7169723d13aa67c3cc8e0baabd60f2e7 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Mon, 21 Sep 2026 23:41:18 +0300 Subject: [PATCH 1532/2126] wifi: iwlwifi: pcie: validate txq_id in txq_disable iwl_trans_pcie_txq_disable() computed SCD_TX_STTS_QUEUE_OFFSET(txq_id) and dereferenced trans_pcie->txqs.txq[txq_id] before checking that txq_id is within range or that the queue was allocated. Bail out with a WARN_ON when txq_id is out of range or the queue is not allocated, and only compute the status address after the checks pass. We don't really want to disable the command queue either, so check that as well. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233730.c96ee7e007bc.Ie593dfd5451be69a5e6deca248a4b443e168ac88@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c index dc2fe0c4f68c..060074c2871b 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c @@ -1276,9 +1276,17 @@ void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int txq_id, bool configure_scd) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - u32 stts_addr = trans_pcie->scd_base_addr + - SCD_TX_STTS_QUEUE_OFFSET(txq_id); static const u32 zero_val[4] = {}; + u32 stts_addr; + + if (WARN_ON(txq_id < 0 || + txq_id >= trans->mac_cfg->base->num_of_queues || + txq_id == trans->conf.cmd_queue || + !trans_pcie->txqs.txq[txq_id])) + return; + + stts_addr = trans_pcie->scd_base_addr + + SCD_TX_STTS_QUEUE_OFFSET(txq_id); trans_pcie->txqs.txq[txq_id]->frozen_expiry_remainder = 0; trans_pcie->txqs.txq[txq_id]->frozen = false; From 8794e8501d0f2a08dc09f9f3d676c55138d2b6d0 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Mon, 21 Sep 2026 23:41:19 +0300 Subject: [PATCH 1533/2126] wifi: iwlwifi: mvm: remove SRAM access through debugfs This is not really secure and we won't really need on old devices (driven by iwlmvm) anyway. Just remove the code. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233730.60f5274c7116.Ieec87672d84763b599e2d322525f68acff63e701@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/mvm/debugfs.c | 68 ------------------- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 1 - 2 files changed, 69 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c index e6b9896dc4ac..b7315598d522 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c @@ -153,72 +153,6 @@ static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf, return ret; } -static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) -{ - struct iwl_mvm *mvm = file->private_data; - const struct fw_img *img; - unsigned int ofs, len; - size_t ret; - u8 *ptr; - - if (!iwl_mvm_firmware_running(mvm)) - return -EINVAL; - - /* default is to dump the entire data segment */ - img = &mvm->fw->img[mvm->fwrt.cur_fw_img]; - ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; - len = img->sec[IWL_UCODE_SECTION_DATA].len; - - if (mvm->dbgfs_sram_len) { - ofs = mvm->dbgfs_sram_offset; - len = mvm->dbgfs_sram_len; - } - - ptr = kzalloc(len, GFP_KERNEL); - if (!ptr) - return -ENOMEM; - - iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len); - - ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len); - - kfree(ptr); - - return ret; -} - -static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf, - size_t count, loff_t *ppos) -{ - const struct fw_img *img; - u32 offset, len; - u32 img_offset, img_len; - - if (!iwl_mvm_firmware_running(mvm)) - return -EINVAL; - - img = &mvm->fw->img[mvm->fwrt.cur_fw_img]; - img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset; - img_len = img->sec[IWL_UCODE_SECTION_DATA].len; - - if (sscanf(buf, "%x,%x", &offset, &len) == 2) { - if ((offset & 0x3) || (len & 0x3)) - return -EINVAL; - - if (offset + len > img_offset + img_len) - return -EINVAL; - - mvm->dbgfs_sram_offset = offset; - mvm->dbgfs_sram_len = len; - } else { - mvm->dbgfs_sram_offset = 0; - mvm->dbgfs_sram_len = 0; - } - - return count; -} - static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) @@ -1916,7 +1850,6 @@ MVM_DEBUGFS_WRITE_FILE_OPS(start_ctdp, 8); MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8); MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16); MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8); -MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64); MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64); MVM_DEBUGFS_READ_FILE_OPS(nic_temp); MVM_DEBUGFS_READ_FILE_OPS(stations); @@ -2114,7 +2047,6 @@ void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm) spin_lock_init(&mvm->drv_stats_lock); MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, 0200); - MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, 0600); MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir, 0600); MVM_DEBUGFS_ADD_FILE(nic_temp, mvm->debugfs_dir, 0400); MVM_DEBUGFS_ADD_FILE(ctdp_budget, mvm->debugfs_dir, 0400); diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h index fb1fc9c42280..ae2ee8771f16 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h @@ -1053,7 +1053,6 @@ struct iwl_mvm { */ struct dentry *debugfs_dir; #ifdef CONFIG_IWLWIFI_DEBUGFS - u32 dbgfs_sram_offset, dbgfs_sram_len; u32 dbgfs_prph_reg_addr; bool disable_power_off; bool disable_power_off_d3; From 5450e8b28cb4bae56dbf6027541668c2312608bf Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Mon, 21 Sep 2026 23:41:20 +0300 Subject: [PATCH 1534/2126] wifi: iwlwifi: dbg: validate dram_alloc_id from debug TLV iwl_dbg_tlv_alloc_region() did not validate reg->dram_alloc_id for IWL_FW_INI_REGION_DRAM_BUFFER regions, and the DRAM monitor dump consumers in fw/dbg.c used it directly to index the fw_mon_ini array. Check that dram_alloc_id is in range at TLV parse time, and add bounds checks in iwl_dump_ini_mon_dram_iter(), iwl_dump_ini_mon_dram_ranges() and iwl_dump_ini_mon_dram_get_size() before accessing the array. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233730.4c896fab0bb7.I3296a5523ce58df085ea0867694ea157c00945bd@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 9 +++++++++ drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index a314fabbf06d..8c8d15ac71ac 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -344,6 +344,9 @@ iwl_dump_ini_mon_dram_iter(struct iwl_fw_runtime *fwrt, struct iwl_dram_data *frag; u32 alloc_id = le32_to_cpu(reg->dram_alloc_id); + if (WARN_ON_ONCE(alloc_id >= ARRAY_SIZE(fwrt->trans->dbg.fw_mon_ini))) + return -EINVAL; + frag = &fwrt->trans->dbg.fw_mon_ini[alloc_id].frags[idx]; range->dram_base_addr = cpu_to_le64(frag->physical); @@ -957,6 +960,9 @@ iwl_dump_ini_mon_dram_ranges(struct iwl_fw_runtime *fwrt, u32 ranges = 0, alloc_id = le32_to_cpu(reg->dram_alloc_id); int i; + if (WARN_ON_ONCE(alloc_id >= ARRAY_SIZE(fwrt->trans->dbg.fw_mon_ini))) + return 0; + fw_mon = &fwrt->trans->dbg.fw_mon_ini[alloc_id]; for (i = 0; i < fw_mon->num_frags; i++) { @@ -1085,6 +1091,9 @@ iwl_dump_ini_mon_dram_get_size(struct iwl_fw_runtime *fwrt, u32 size = 0, alloc_id = le32_to_cpu(reg->dram_alloc_id); int i; + if (WARN_ON_ONCE(alloc_id >= ARRAY_SIZE(fwrt->trans->dbg.fw_mon_ini))) + return 0; + fw_mon = &fwrt->trans->dbg.fw_mon_ini[alloc_id]; for (i = 0; i < fw_mon->num_frags; i++) { diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c index bd2a9e4b4b5f..5576598cc6e7 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c @@ -229,6 +229,18 @@ static int iwl_dbg_tlv_alloc_region(struct iwl_trans *trans, return -EINVAL; } + if (type == IWL_FW_INI_REGION_DRAM_BUFFER) { + u32 alloc_id = le32_to_cpu(reg->dram_alloc_id); + + if (alloc_id <= IWL_FW_INI_ALLOCATION_INVALID || + alloc_id >= ARRAY_SIZE(trans->dbg.fw_mon_ini)) { + IWL_ERR(trans, + "WRT: Invalid dram_alloc_id %u for region %u\n", + alloc_id, id); + return -EINVAL; + } + } + if (type == IWL_FW_INI_REGION_INTERNAL_BUFFER) { trans->dbg.imr_data.sram_addr = le32_to_cpu(reg->internal_buffer.base_addr); From 1f602dd4678abd74e2fdc12d9fe966b5bd620ae8 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Mon, 21 Sep 2026 23:41:21 +0300 Subject: [PATCH 1535/2126] wifi: iwlwifi: Don't allocate a DRAM buffer with an invalid ID A DRAM buffer allocation shouldn't have an ID of 0. If a broken TLV contained such an id, this buffer will be allocated and a command will be sent to the FW. regardless of the FW asserting on that or not, this buffer will never be freed, since in the free path we do check for INVALID... Link: https://patch.msgid.link/20260921233731.ebd907861742.Ib74687a84e65d2e5295d338600283978a7018375@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c index 5576598cc6e7..4372a171172b 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c @@ -619,7 +619,7 @@ static int iwl_dbg_tlv_alloc_fragments(struct iwl_fw_runtime *fwrt, u32 num_frags, remain_pages, frag_pages; int i; - if (alloc_id < IWL_FW_INI_ALLOCATION_INVALID || + if (alloc_id <= IWL_FW_INI_ALLOCATION_INVALID || alloc_id >= IWL_FW_INI_ALLOCATION_NUM) return -EIO; @@ -702,7 +702,7 @@ static int iwl_dbg_tlv_apply_buffer(struct iwl_fw_runtime *fwrt, IWL_UCODE_TLV_CAPA_DBG_BUF_ALLOC_CMD_SUPP)) return 0; - if (alloc_id < IWL_FW_INI_ALLOCATION_INVALID || + if (alloc_id <= IWL_FW_INI_ALLOCATION_INVALID || alloc_id >= IWL_FW_INI_ALLOCATION_NUM) return -EIO; From 10348bcfae0798ef0735d764ae666e9ee71de938 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Mon, 21 Sep 2026 23:41:22 +0300 Subject: [PATCH 1536/2126] wifi: iwlwifi: mld: explicitly include mld.h in hcmd.h hcmd.h relies on mld.h. Make this dependency explicit. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233731.252cd5ae36b1.I5ea033fff1dcabd46e7d66f15c140dce2c5c9a1f@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/hcmd.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/hcmd.h b/drivers/net/wireless/intel/iwlwifi/mld/hcmd.h index 19e1c9e509cf..761ef73dd9a5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/hcmd.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/hcmd.h @@ -5,6 +5,8 @@ #ifndef __iwl_mld_hcmd_h__ #define __iwl_mld_hcmd_h__ +#include "mld.h" + static inline int iwl_mld_send_cmd(struct iwl_mld *mld, struct iwl_host_cmd *cmd) { /* No commands, including the d3 related commands, should be sent From d8867b883f6732be1b6e1b5916aeb4cc41b814a9 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Mon, 21 Sep 2026 23:41:23 +0300 Subject: [PATCH 1537/2126] wifi: iwlwifi: mld: explicitly include ieee80211-p2p.h in mac-cfg.h Make this dependency explicit. We use the ieee80211_p2p_noa_desc structure in the FW API file. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233731.13c9033a18cf.I2d3f3b8e2d4c7af0961726219974db2485e8312e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h index 01db6765855c..4a494563aa8c 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h @@ -7,6 +7,8 @@ #ifndef __iwl_fw_api_mac_cfg_h__ #define __iwl_fw_api_mac_cfg_h__ +#include + #include "mac.h" #include "phy-ctxt.h" From db96b53de2e04c67d8f28ab1c6fc67d53d1ea9cf Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Mon, 21 Sep 2026 23:41:24 +0300 Subject: [PATCH 1538/2126] wifi: iwlwifi: fw: add Google-ASUS TAS approved DMI match Some Google devices with ASUS board vendor need to be included in the TAS approved DMI list so TAS policy is applied for this platform combination. Add a new GOOGLE-ASUS match entry using DMI_SYS_VENDOR=Google and DMI_BOARD_VENDOR=ASUS in the approved list. This change only extends platform coverage and does not alter existing matching behavior. Signed-off-by: Pagadala Yesu Anjaneyulu Assisted-by: GitHubCopilot:GPT-5.3-Codex Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233731.43ea7ba69e05.Ib2ec495e6dea3db1db783d43171505bd03d24cf6@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/regulatory.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index 1d6d38ee55b4..3ab383b569bc 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -167,6 +167,12 @@ static const struct dmi_system_id dmi_tas_approved_list[] = { DMI_MATCH(DMI_BOARD_VENDOR, "HP"), }, }, + { .ident = "GOOGLE-ASUS", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Google"), + DMI_MATCH(DMI_BOARD_VENDOR, "ASUS"), + }, + }, { .ident = "MSI", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."), From 1fd7d929549476c6190b9a0d0a7057fd33a4277a Mon Sep 17 00:00:00 2001 From: Ayala Beker Date: Mon, 21 Sep 2026 23:41:25 +0300 Subject: [PATCH 1539/2126] wifi: iwlwifi: mld: remove NAN keys before removing internal stations FW expects all keys to be removed before removing a station. On NAN teardown, iwl_mld_stop_nan() removed the NAN internal stations while their IGTK/BIGTK were still in FW. mac80211 frees NAN keys only after drv_stop_nan() returns, so they are available while NAN is still up. Remove the NAN group keys before deleting the NAN internal stations. Signed-off-by: Ayala Beker Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260921233731.6d541e506ee4.Idaed08b15314b26abb4dc9f4a8a41e61a021597e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/nan.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/nan.c b/drivers/net/wireless/intel/iwlwifi/mld/nan.c index 8853fcb2b4ec..10df33a238d1 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/nan.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/nan.c @@ -5,6 +5,7 @@ #include "mld.h" #include "iface.h" +#include "key.h" #include "link.h" #include "mlo.h" #include "tlc.h" @@ -107,6 +108,20 @@ static void iwl_mld_nan_flush(struct iwl_mld *mld, struct ieee80211_vif *vif) iwl_mld_flush_link_sta_txqs(mld, sta->sta_id); } +static void iwl_mld_remove_nan_keys_iter(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_sta *sta, + struct ieee80211_key_conf *key, + void *data) +{ + struct iwl_mld *mld = data; + + if (sta || key->hw_key_idx == STA_KEY_IDX_INVALID) + return; + + iwl_mld_remove_key(mld, vif, NULL, key); +} + static void iwl_mld_nan_remove_stations(struct iwl_mld *mld, struct ieee80211_vif *vif) { @@ -296,6 +311,8 @@ int iwl_mld_stop_nan(struct ieee80211_hw *hw, if (ret) IWL_ERR(mld, "NAN: Failed to stop NAN. ret=%d\n", ret); + ieee80211_iter_keys(mld->hw, vif, iwl_mld_remove_nan_keys_iter, mld); + /* assume that higher layer guarantees that no additional frames are * added before calling this callback */ From 11ba2770d3bcac41ac174df9c6589a9593d6a906 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:48 +0300 Subject: [PATCH 1540/2126] wifi: iwlwifi: mld: support operational statistics notif ver 5 Add STATISTICS_FW_NTFY_OPERATIONAL_API_S_VER_5, which uses a new per-PHY struct (VER_3) that appends the NPCA channel load fields. Assisted-by: GitHubCopilot:claude-opus-4.8 Signed-off-by: Emmanuel Grumbach Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260922144819.971d1a747698.I0792723d62dca7cf68056f13c8f733084ce6445f@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/stats.h | 60 +++++++++++++++++-- .../net/wireless/intel/iwlwifi/mld/notif.c | 3 +- .../net/wireless/intel/iwlwifi/mld/stats.c | 35 +++++++++-- 3 files changed, 89 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/stats.h b/drivers/net/wireless/intel/iwlwifi/fw/api/stats.h index 8d16782a129c..e3bf5d08c7e7 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/stats.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/stats.h @@ -616,7 +616,7 @@ struct iwl_stats_ntfy_coex { } __packed; /* STATISTICS_FW_NTFY_COEX_TELEMETRY_API_S_VER_1 */ /** - * struct iwl_stats_ntfy_per_phy - per PHY statistics + * struct iwl_stats_ntfy_per_phy_v2 - per PHY statistics * @channel_load: channel load * @channel_load_by_us: device contribution to MCLM * @channel_load_not_by_us: other devices' contribution to MCLM @@ -632,7 +632,7 @@ struct iwl_stats_ntfy_coex { * @last_tx_ch_width_indx: last txed frame channel width index * @coex: coex related data */ -struct iwl_stats_ntfy_per_phy { +struct iwl_stats_ntfy_per_phy_v2 { __le32 channel_load; __le32 channel_load_by_us; __le32 channel_load_not_by_us; @@ -646,6 +646,43 @@ struct iwl_stats_ntfy_per_phy { struct iwl_stats_ntfy_coex coex; } __packed; /* STATISTICS_NTFY_PER_PHY_API_S_VER_2 */ +/** + * struct iwl_stats_ntfy_per_phy - per PHY statistics + * @channel_load: channel load + * @channel_load_by_us: device contribution to MCLM + * @channel_load_not_by_us: other devices' contribution to MCLM + * @clt: CLT HW timer (TIM_CH_LOAD2) + * @act: active accumulator SW + * @elp: elapsed time accumulator SW + * @rx_detected_per_ch_width: number of deferred TX per channel width, + * 0 - 20, 1/2/3 - 40/80/160 + * @success_per_ch_width: number of frames that got ACK/BACK/CTS + * per channel BW. note, BACK counted as 1 + * @fail_per_ch_width: number of frames that didn't get ACK/BACK/CTS + * per channel BW. note BACK counted as 1 + * @last_tx_ch_width_indx: last txed frame channel width index + * @coex: coex related data + * @channel_load_npca_by_us: device NPCA contribution to MCLM + * @channel_load_npca_obss: the time FW identified for NPCA, not necessarily + * entered to NPCA state, but can be used as an indication for NPCA + * opportunities in the environment + */ +struct iwl_stats_ntfy_per_phy { + __le32 channel_load; + __le32 channel_load_by_us; + __le32 channel_load_not_by_us; + __le32 clt; + __le32 act; + __le32 elp; + __le32 rx_detected_per_ch_width[IWL_STATS_MAX_BW_INDEX]; + __le32 success_per_ch_width[IWL_STATS_MAX_BW_INDEX]; + __le32 fail_per_ch_width[IWL_STATS_MAX_BW_INDEX]; + __le32 last_tx_ch_width_indx; + struct iwl_stats_ntfy_coex coex; + __le32 channel_load_npca_by_us; + __le32 channel_load_npca_obss; +} __packed; /* STATISTICS_NTFY_PER_PHY_API_S_VER_3 */ + /* unknown channel load (due to not being active on channel) */ #define IWL_STATS_UNKNOWN_CHANNEL_LOAD 0xffffffff @@ -675,12 +712,27 @@ struct iwl_system_statistics_notif_oper_v3 { struct iwl_stats_ntfy_per_sta per_sta[IWL_STATION_COUNT_MAX]; } __packed; /* STATISTICS_FW_NTFY_OPERATIONAL_API_S_VER_3 */ +/** + * struct iwl_system_statistics_notif_oper_v4 - statistics notification + * + * @time_stamp: time when the notification is sent from firmware + * @per_link: per link statistics, &struct iwl_stats_ntfy_per_link + * @per_phy: per phy statistics, &struct iwl_stats_ntfy_per_phy_v2 + * @per_sta: per sta statistics, &struct iwl_stats_ntfy_per_sta + */ +struct iwl_system_statistics_notif_oper_v4 { + __le32 time_stamp; + struct iwl_stats_ntfy_per_link per_link[IWL_FW_MAX_LINKS]; + struct iwl_stats_ntfy_per_phy_v2 per_phy[IWL_STATS_MAX_PHY_OPERATIONAL]; + struct iwl_stats_ntfy_per_sta per_sta[IWL_STATION_COUNT_MAX]; +} __packed; /* STATISTICS_FW_NTFY_OPERATIONAL_API_S_VER_4 */ + /** * struct iwl_system_statistics_notif_oper - statistics notification * * @time_stamp: time when the notification is sent from firmware * @per_link: per link statistics, &struct iwl_stats_ntfy_per_link - * @per_phy: per phy statistics, &struct iwl_stats_ntfy_per_phy_v1 + * @per_phy: per phy statistics, &struct iwl_stats_ntfy_per_phy * @per_sta: per sta statistics, &struct iwl_stats_ntfy_per_sta */ struct iwl_system_statistics_notif_oper { @@ -688,7 +740,7 @@ struct iwl_system_statistics_notif_oper { struct iwl_stats_ntfy_per_link per_link[IWL_FW_MAX_LINKS]; struct iwl_stats_ntfy_per_phy per_phy[IWL_STATS_MAX_PHY_OPERATIONAL]; struct iwl_stats_ntfy_per_sta per_sta[IWL_STATION_COUNT_MAX]; -} __packed; /* STATISTICS_FW_NTFY_OPERATIONAL_API_S_VER_4 */ +} __packed; /* STATISTICS_FW_NTFY_OPERATIONAL_API_S_VER_5 */ /** * struct iwl_system_statistics_part1_notif_oper - part1 stats notification diff --git a/drivers/net/wireless/intel/iwlwifi/mld/notif.c b/drivers/net/wireless/intel/iwlwifi/mld/notif.c index 90733bbaf733..d0b85adf7417 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/notif.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/notif.c @@ -329,7 +329,8 @@ CMD_VERSIONS(datapath_monitor_notif, CMD_VER_ENTRY(1, iwl_datapath_monitor_notif)) CMD_VERSIONS(stats_oper_notif, CMD_VER_ENTRY(3, iwl_system_statistics_notif_oper_v3) - CMD_VER_ENTRY(4, iwl_system_statistics_notif_oper)) + CMD_VER_ENTRY(4, iwl_system_statistics_notif_oper_v4) + CMD_VER_ENTRY(5, iwl_system_statistics_notif_oper)) CMD_VERSIONS(stats_oper_part1_notif, CMD_VER_ENTRY(4, iwl_system_statistics_part1_notif_oper)) CMD_VERSIONS(bt_coex_notif, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/stats.c b/drivers/net/wireless/intel/iwlwifi/mld/stats.c index e7b283cbe199..3b6cd4f382f6 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/stats.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/stats.c @@ -43,12 +43,17 @@ iwl_mld_fill_stats_from_oper_notif(struct iwl_mld *mld, const struct iwl_stats_ntfy_per_sta *per_sta; struct ieee80211_link_sta *link_sta; struct iwl_mld_link_sta *mld_link_sta; + u8 notif_ver = iwl_fw_lookup_notif_ver(mld->fw, STATISTICS_GROUP, + STATISTICS_OPER_NOTIF, 3); - if (iwl_fw_lookup_notif_ver(mld->fw, STATISTICS_GROUP, - STATISTICS_OPER_NOTIF, 3) >= 4) { + if (notif_ver >= 5) { const struct iwl_system_statistics_notif_oper *notif = (void *)&pkt->data; per_sta = ¬if->per_sta[fw_sta_id]; + } else if (notif_ver == 4) { + const struct iwl_system_statistics_notif_oper_v4 *notif = + (void *)&pkt->data; + per_sta = ¬if->per_sta[fw_sta_id]; } else { const struct iwl_system_statistics_notif_oper_v3 *notif = (void *)&pkt->data; @@ -581,17 +586,39 @@ void iwl_mld_handle_stats_oper_notif(struct iwl_mld *mld, struct iwl_system_statistics_notif_oper *_notif __free(kfree) = NULL; const struct iwl_system_statistics_notif_oper *notif = (void *)&pkt->data; + u8 notif_ver = iwl_fw_lookup_notif_ver(mld->fw, STATISTICS_GROUP, + STATISTICS_OPER_NOTIF, 3); BUILD_BUG_ON(ARRAY_SIZE(notif->per_sta) != IWL_STATION_COUNT_MAX); BUILD_BUG_ON(ARRAY_SIZE(notif->per_link) < ARRAY_SIZE(mld->fw_id_to_bss_conf)); - if (iwl_fw_lookup_notif_ver(mld->fw, STATISTICS_GROUP, - STATISTICS_OPER_NOTIF, 3) == 3) { + if (notif_ver == 3) { const struct iwl_system_statistics_notif_oper_v3 *stats = (void *)&pkt->data; _notif = kzalloc_obj(*_notif); + if (!_notif) + return; + + _notif->time_stamp = stats->time_stamp; + for (int i = 0; i < ARRAY_SIZE(_notif->per_link); i++) + _notif->per_link[i] = stats->per_link[i]; + + BUILD_BUG_ON(sizeof(_notif->per_phy[0]) < + sizeof(stats->per_phy[0])); + for (int i = 0; i < ARRAY_SIZE(_notif->per_phy); i++) + memcpy(&_notif->per_phy[i], &stats->per_phy[i], + sizeof(stats->per_phy[i])); + for (int i = 0; i < ARRAY_SIZE(_notif->per_sta); i++) + _notif->per_sta[i] = stats->per_sta[i]; + + notif = _notif; + } else if (notif_ver == 4) { + const struct iwl_system_statistics_notif_oper_v4 *stats = + (void *)&pkt->data; + _notif = kzalloc_obj(*_notif); + if (!_notif) return; From a552da3e4fd01672c4f72754f0d2ca21d943302b Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:49 +0300 Subject: [PATCH 1541/2126] wifi: iwlwifi: poke the config space in case of command timeout There is a race between the PCI link power save flow and the notification flow from the firmware. The firmware prepares the notification in DRAM and then sends an MSI-X message to interrupt the CPU and let it know it can handle the notification. In case the PCI link goes L1.2 between the access to the DRAM to copy the notification and the MSI-X interrupt, the host won't be interrupted. Add a work-around to cope with this situation. If the command response was not received after 200ms, read the config space of the device just to wake up the link. This will allow the MSI-X interrupt to go through and the CPU will get the interrupt. Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221501 Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.ef433f3da32b.I017c1c7a1dd3ac6f111d4640966968b82f37e291@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/pcie/gen1_2/tx.c | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c index 060074c2871b..fae5beed2ecb 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c @@ -2560,6 +2560,7 @@ next_queue: } } +#define HOST_COMPLETE_QUICK_TIMEOUT msecs_to_jiffies(200) #define HOST_COMPLETE_TIMEOUT (2 * HZ) static int iwl_trans_pcie_send_hcmd_sync(struct iwl_trans *trans, @@ -2593,10 +2594,32 @@ static int iwl_trans_pcie_send_hcmd_sync(struct iwl_trans *trans, return ret; } - ret = wait_event_timeout(trans_pcie->wait_command_queue, - !test_bit(STATUS_SYNC_HCMD_ACTIVE, - &trans->status), - HOST_COMPLETE_TIMEOUT); + /* + * There is a race between the PCI link power save flows and the + * notification / MSI-X interrupt in the firmware. + * If we didn't get a response after 200ms, poke the config space + * to force a wake-up of the PCI link. + */ + for (int i = 0; i < 2; i++) { + ret = wait_event_timeout(trans_pcie->wait_command_queue, + !test_bit(STATUS_SYNC_HCMD_ACTIVE, + &trans->status), + i == 0 ? HOST_COMPLETE_QUICK_TIMEOUT : + HOST_COMPLETE_TIMEOUT); + if (ret) + break; + + if (i == 0) { + u32 val; + + pci_read_config_dword(trans_pcie->pci_dev, + PCI_VENDOR_ID, &val); + IWL_DEBUG_HC(trans, + "write_ptr: %d: no response after %ums poking config space\n", + txq->write_ptr, + jiffies_to_msecs(HOST_COMPLETE_QUICK_TIMEOUT)); + } + } if (!ret) { IWL_ERR(trans, "Error sending %s: time out after %dms.\n", cmd_str, jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); From 4e7c4a59a5336a501ac31e32b5ca76dd1c44b9e2 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:50 +0300 Subject: [PATCH 1542/2126] wifi: iwlwifi: pcie: remove monitor_data debugfs file The monitor_data debugfs file exposed the DRAM firmware monitor buffer to userspace. Remove it along with all the code and data that only existed to support it: the read/open/release handlers and the iwl_write_to_user_buf() helper, the cont_rec state tracking structure and iwl_fw_mon_dbgfs_state enum, the fw_mon_data field and its initialization, and the now-unused debugfs cleanup path (iwl_trans_pcie_debugfs_cleanup() and iwl_trans_debugfs_cleanup()). This relied on old firmware monitor format. Assisted-By: GitHubCopilot:Claude Opus 4.8 Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.9e5d30a9caa4.Idf62277c82970daf49d3d4d7b7a021595672eeed@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 2 - .../net/wireless/intel/iwlwifi/iwl-trans.c | 7 - .../net/wireless/intel/iwlwifi/iwl-trans.h | 4 - .../intel/iwlwifi/pcie/gen1_2/internal.h | 43 ----- .../intel/iwlwifi/pcie/gen1_2/trans.c | 153 ------------------ 5 files changed, 209 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c index 7f1515dfc5bf..ef9d50ee3704 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c @@ -2039,8 +2039,6 @@ void iwl_drv_stop(struct iwl_drv *drv) mutex_unlock(&iwlwifi_opmode_table_mtx); #ifdef CONFIG_IWLWIFI_DEBUGFS - iwl_trans_debugfs_cleanup(drv->trans); - debugfs_remove_recursive(drv->dbgfs_drv); #endif diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 73aae1125042..a1545e9d2cd8 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -746,13 +746,6 @@ void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans, } IWL_EXPORT_SYMBOL(iwl_trans_txq_set_shared_mode); -#ifdef CONFIG_IWLWIFI_DEBUGFS -void iwl_trans_debugfs_cleanup(struct iwl_trans *trans) -{ - iwl_trans_pcie_debugfs_cleanup(trans); -} -#endif - void iwl_trans_set_q_ptrs(struct iwl_trans *trans, int queue, int ptr) { if (WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE, diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index c581cc8f5bcb..dfad839dd2e6 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -934,10 +934,6 @@ int iwl_trans_read_mem_no_grab(struct iwl_trans *trans, u32 addr, int iwl_trans_read_config32(struct iwl_trans *trans, u32 ofs, u32 *val); -#ifdef CONFIG_IWLWIFI_DEBUGFS -void iwl_trans_debugfs_cleanup(struct iwl_trans *trans); -#endif - #define iwl_trans_read_mem_bytes(trans, addr, buf, bufsize) \ ({ \ if (__builtin_constant_p(bufsize)) \ diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h index d84c7c1efee1..f0e70b0fedfe 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h @@ -206,23 +206,6 @@ static inline u16 iwl_get_closed_rb_stts(struct iwl_trans *trans, } } -#ifdef CONFIG_IWLWIFI_DEBUGFS -/** - * enum iwl_fw_mon_dbgfs_state - the different states of the monitor_data - * debugfs file - * - * @IWL_FW_MON_DBGFS_STATE_CLOSED: the file is closed. - * @IWL_FW_MON_DBGFS_STATE_OPEN: the file is open. - * @IWL_FW_MON_DBGFS_STATE_DISABLED: the file is disabled, once this state is - * set the file can no longer be used. - */ -enum iwl_fw_mon_dbgfs_state { - IWL_FW_MON_DBGFS_STATE_CLOSED, - IWL_FW_MON_DBGFS_STATE_OPEN, - IWL_FW_MON_DBGFS_STATE_DISABLED, -}; -#endif - /** * enum iwl_shared_irq_flags - level of sharing for irq * @IWL_SHARED_IRQ_NON_RX: interrupt vector serves non rx causes. @@ -245,26 +228,6 @@ enum iwl_image_response_code { IWL_IMAGE_RESP_FAIL = 2, }; -#ifdef CONFIG_IWLWIFI_DEBUGFS -/** - * struct cont_rec: continuous recording data structure - * @prev_wr_ptr: the last address that was read in monitor_data - * debugfs file - * @prev_wrap_cnt: the wrap count that was used during the last read in - * monitor_data debugfs file - * @state: the state of monitor_data debugfs file as described - * in &iwl_fw_mon_dbgfs_state enum - * @mutex: locked while reading from monitor_data debugfs file - */ -struct cont_rec { - u32 prev_wr_ptr; - u32 prev_wrap_cnt; - u8 state; - /* Used to sync monitor_data debugfs file with driver unload flow */ - struct mutex mutex; -}; -#endif - enum iwl_pcie_fw_reset_state { FW_RESET_IDLE, FW_RESET_REQUESTED, @@ -451,7 +414,6 @@ struct iwl_pcie_txqs { * @rx_buf_bytes: RX buffer (RB) size in bytes * @reg_lock: protect hw register access * @mutex: to protect stop_device / start_fw / start_hw - * @fw_mon_data: fw continuous recording data * @cmd_hold_nic_awake: indicates NIC is held awake for APMG workaround * during commands in flight * @msix_entries: array of MSI-X entries @@ -577,10 +539,6 @@ struct iwl_trans_pcie { spinlock_t reg_lock; bool cmd_hold_nic_awake; -#ifdef CONFIG_IWLWIFI_DEBUGFS - struct cont_rec fw_mon_data; -#endif - struct msix_entry msix_entries[IWL_MAX_RX_HW_QUEUES]; bool msix_enabled; u8 shared_vec_mask; @@ -1167,7 +1125,6 @@ void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state, bool from_irq); #ifdef CONFIG_IWLWIFI_DEBUGFS void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans); -void iwl_trans_pcie_debugfs_cleanup(struct iwl_trans *trans); #else static inline void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans) { } #endif diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c index 28b276c65952..71c4746c61a6 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c @@ -3073,137 +3073,6 @@ static ssize_t iwl_dbgfs_rfkill_write(struct file *file, return count; } -static int iwl_dbgfs_monitor_data_open(struct inode *inode, - struct file *file) -{ - struct iwl_trans *trans = inode->i_private; - struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - - if (!trans->dbg.dest_tlv || - trans->dbg.dest_tlv->monitor_mode != EXTERNAL_MODE) { - IWL_ERR(trans, "Debug destination is not set to DRAM\n"); - return -ENOENT; - } - - if (trans_pcie->fw_mon_data.state != IWL_FW_MON_DBGFS_STATE_CLOSED) - return -EBUSY; - - trans_pcie->fw_mon_data.state = IWL_FW_MON_DBGFS_STATE_OPEN; - return simple_open(inode, file); -} - -static int iwl_dbgfs_monitor_data_release(struct inode *inode, - struct file *file) -{ - struct iwl_trans_pcie *trans_pcie = - IWL_TRANS_GET_PCIE_TRANS(inode->i_private); - - if (trans_pcie->fw_mon_data.state == IWL_FW_MON_DBGFS_STATE_OPEN) - trans_pcie->fw_mon_data.state = IWL_FW_MON_DBGFS_STATE_CLOSED; - return 0; -} - -static bool iwl_write_to_user_buf(char __user *user_buf, ssize_t count, - void *buf, ssize_t *size, - ssize_t *bytes_copied) -{ - ssize_t buf_size_left = count - *bytes_copied; - - buf_size_left = buf_size_left - (buf_size_left % sizeof(u32)); - if (*size > buf_size_left) - *size = buf_size_left; - - *size -= copy_to_user(user_buf, buf, *size); - *bytes_copied += *size; - - if (buf_size_left == *size) - return true; - return false; -} - -static ssize_t iwl_dbgfs_monitor_data_read(struct file *file, - char __user *user_buf, - size_t count, loff_t *ppos) -{ - struct iwl_trans *trans = file->private_data; - struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - u8 *cpu_addr = (void *)trans->dbg.fw_mon.block, *curr_buf; - struct cont_rec *data = &trans_pcie->fw_mon_data; - u32 write_ptr_addr, wrap_cnt_addr, write_ptr, wrap_cnt; - ssize_t size, bytes_copied = 0; - bool b_full; - - if (trans->dbg.dest_tlv) { - write_ptr_addr = - le32_to_cpu(trans->dbg.dest_tlv->write_ptr_reg); - wrap_cnt_addr = le32_to_cpu(trans->dbg.dest_tlv->wrap_count); - } else { - write_ptr_addr = MON_BUFF_WRPTR; - wrap_cnt_addr = MON_BUFF_CYCLE_CNT; - } - - if (unlikely(!trans->dbg.rec_on)) - return 0; - - mutex_lock(&data->mutex); - if (data->state == - IWL_FW_MON_DBGFS_STATE_DISABLED) { - mutex_unlock(&data->mutex); - return 0; - } - - /* write_ptr position in bytes rather then DW */ - write_ptr = iwl_read_prph(trans, write_ptr_addr) * sizeof(u32); - wrap_cnt = iwl_read_prph(trans, wrap_cnt_addr); - - if (data->prev_wrap_cnt == wrap_cnt) { - size = write_ptr - data->prev_wr_ptr; - curr_buf = cpu_addr + data->prev_wr_ptr; - b_full = iwl_write_to_user_buf(user_buf, count, - curr_buf, &size, - &bytes_copied); - data->prev_wr_ptr += size; - - } else if (data->prev_wrap_cnt == wrap_cnt - 1 && - write_ptr < data->prev_wr_ptr) { - size = trans->dbg.fw_mon.size - data->prev_wr_ptr; - curr_buf = cpu_addr + data->prev_wr_ptr; - b_full = iwl_write_to_user_buf(user_buf, count, - curr_buf, &size, - &bytes_copied); - data->prev_wr_ptr += size; - - if (!b_full) { - size = write_ptr; - b_full = iwl_write_to_user_buf(user_buf, count, - cpu_addr, &size, - &bytes_copied); - data->prev_wr_ptr = size; - data->prev_wrap_cnt++; - } - } else { - if (data->prev_wrap_cnt == wrap_cnt - 1 && - write_ptr > data->prev_wr_ptr) - IWL_WARN(trans, - "write pointer passed previous write pointer, start copying from the beginning\n"); - else if (!unlikely(data->prev_wrap_cnt == 0 && - data->prev_wr_ptr == 0)) - IWL_WARN(trans, - "monitor data is out of sync, start copying from the beginning\n"); - - size = write_ptr; - b_full = iwl_write_to_user_buf(user_buf, count, - cpu_addr, &size, - &bytes_copied); - data->prev_wr_ptr = size; - data->prev_wrap_cnt = wrap_cnt; - } - - mutex_unlock(&data->mutex); - - return bytes_copied; -} - static ssize_t iwl_dbgfs_rf_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) @@ -3279,12 +3148,6 @@ static const struct file_operations iwl_dbgfs_tx_queue_ops = { .release = seq_release_private, }; -static const struct file_operations iwl_dbgfs_monitor_data_ops = { - .read = iwl_dbgfs_monitor_data_read, - .open = iwl_dbgfs_monitor_data_open, - .release = iwl_dbgfs_monitor_data_release, -}; - /* Create the debugfs files and directories */ void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans) { @@ -3296,20 +3159,9 @@ void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans) DEBUGFS_ADD_FILE(csr, dir, 0200); DEBUGFS_ADD_FILE(fh_reg, dir, 0400); DEBUGFS_ADD_FILE(rfkill, dir, 0600); - DEBUGFS_ADD_FILE(monitor_data, dir, 0400); DEBUGFS_ADD_FILE(rf, dir, 0400); DEBUGFS_ADD_FILE(reset, dir, 0200); } - -void iwl_trans_pcie_debugfs_cleanup(struct iwl_trans *trans) -{ - struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - struct cont_rec *data = &trans_pcie->fw_mon_data; - - mutex_lock(&data->mutex); - data->state = IWL_FW_MON_DBGFS_STATE_DISABLED; - mutex_unlock(&data->mutex); -} #endif /*CONFIG_IWLWIFI_DEBUGFS */ static u32 iwl_trans_pcie_get_cmdlen(struct iwl_trans *trans, void *tfd) @@ -3974,11 +3826,6 @@ iwl_trans_pcie_alloc(struct pci_dev *pdev, } } -#ifdef CONFIG_IWLWIFI_DEBUGFS - trans_pcie->fw_mon_data.state = IWL_FW_MON_DBGFS_STATE_CLOSED; - mutex_init(&trans_pcie->fw_mon_data.mutex); -#endif - iwl_dbg_tlv_init(trans); return trans; From ded9ad2d04d2d23aaf88e99313fa2a5b961a57ef Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Tue, 22 Sep 2026 14:49:51 +0300 Subject: [PATCH 1543/2126] wifi: iwlwifi: mvm: validate NVM read response length Treat firmware-provided NVM response length as untrusted before copying data into the host buffer. Reject responses that are shorter than the fixed response header, where reported bytes exceed the requested chunk length, or where payload size does not contain the reported number of bytes. This prevents heap overwrite and RX payload over-read in malformed or malicious NVM_ACCESS responses. Signed-off-by: Pagadala Yesu Anjaneyulu Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.a9d384de40a0.Id6028e4753a2af5638bed0279bbf55842845df3b@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/nvm.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c index f76e57399c1f..54006d5e15a5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c @@ -86,6 +86,7 @@ static int iwl_nvm_read_chunk(struct iwl_mvm *mvm, u16 section, .data = { &nvm_access_cmd, }, }; int ret, bytes_read, offset_read; + unsigned int pkt_len; u8 *resp_data; cmd.len[0] = sizeof(struct iwl_nvm_access_cmd); @@ -95,6 +96,12 @@ static int iwl_nvm_read_chunk(struct iwl_mvm *mvm, u16 section, return ret; pkt = cmd.resp_pkt; + pkt_len = iwl_rx_packet_payload_len(pkt); + if (pkt_len < sizeof(*nvm_resp)) { + IWL_ERR(mvm, "NVM ACCESS response too short: %u\n", pkt_len); + ret = -EINVAL; + goto exit; + } /* Extract NVM response */ nvm_resp = (void *)pkt->data; @@ -133,6 +140,14 @@ static int iwl_nvm_read_chunk(struct iwl_mvm *mvm, u16 section, goto exit; } + if (bytes_read > length || + pkt_len < struct_size(nvm_resp, data, bytes_read)) { + IWL_ERR(mvm, "NVM ACCESS response with invalid length %d\n", + bytes_read); + ret = -EINVAL; + goto exit; + } + /* Write data to NVM */ memcpy(data + offset, resp_data, bytes_read); ret = bytes_read; From fbd25abf05b1465bacbacf78066902fe028e63af Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:52 +0300 Subject: [PATCH 1544/2126] wifi: iwlwifi: mld: stop filling link fields unused by the firmware The htc_trig_based_pkt_ext, rand_alloc_ecwmin, rand_alloc_ecwmax and frame_time_rts_th fields of the LINK context config command are not used by the firmware. Stop filling them. Assisted-by: GithubCopilot:claude-opus-4.8 Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.887695af3d15.Ie0f0804a28ec4e1e8e41d0eb11615ed2a0f2823e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/link.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/link.c b/drivers/net/wireless/intel/iwlwifi/mld/link.c index 96e06940b34c..65eddbd63016 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/link.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/link.c @@ -361,13 +361,6 @@ iwl_mld_change_link_in_fw(struct iwl_mld *mld, struct ieee80211_bss_conf *link, flags |= LINK_FLG_MLPM; } - cmd.htc_trig_based_pkt_ext = link->htc_trig_based_pkt_ext; - - if (link->uora_exists) { - cmd.rand_alloc_ecwmin = link->uora_ocw_range & 0x7; - cmd.rand_alloc_ecwmax = (link->uora_ocw_range >> 3) & 0x7; - } - if (iwl_mld_fill_mu_edca(mld, mld_link, cmd.trig_based_txf)) flags |= LINK_FLG_MU_EDCA_CW; @@ -376,8 +369,6 @@ iwl_mld_change_link_in_fw(struct iwl_mld *mld, struct ieee80211_bss_conf *link, if (!link->he_bss_color.enabled) flags |= LINK_FLG_BSS_COLOR_DIS; - cmd.frame_time_rts_th = cpu_to_le16(link->frame_time_rts_th); - /* Block 26-tone RU OFDMA transmissions */ if (mld_link->he_ru_2mhz_block) flags |= LINK_FLG_RU_2MHZ_BLOCK; From e54f06b4d5cc95b0528dac76456b27387cbd669b Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:53 +0300 Subject: [PATCH 1545/2126] wifi: iwlwifi: add multi-BSS/EMCCA max BSSID indicator to LINK cmd Add support for version 9 of the LINK context config command, which carries the max BSSID indicator N, where 2**N is the maximal number of BSSIDs the physical AP can support. The firmware uses this to mask N bits of the transmitter address for NPCA OBSS and inter/intra BSS NAV decisions. N=0 disables the feature. Assisted-by: GithubCopilot:claude-opus-4.8 Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.fafac4d1052d.I91be3bcfcd25d23b5c10c043d6cd639de4efa214@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/fw/api/mac-cfg.h | 28 ++++++++++++++----- drivers/net/wireless/intel/iwlwifi/mld/link.c | 5 ++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h index 4a494563aa8c..9579e691cc87 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h @@ -665,7 +665,13 @@ struct iwl_npca_params { * @puncture_mask: puncture mask for EHT (removed in VER_3) * @frame_time_rts_th: HE duration RTS threshold, in units of 32us * @flags: a combination from &enum iwl_link_ctx_flags - * @flags_mask: what of %flags have changed. Also &enum iwl_link_ctx_flags + * @flags_mask: what of %flags have changed. Also &enum iwl_link_ctx_flags. + * Removed in _VER_6, reused as @reserved4 / @max_bssid_indicator + * in _VER_9. + * @reserved4: reserved + * @max_bssid_indicator: N where 2**N is the max number of BSSIDs the physical + * AP can support (multi-BSS or EMCCA set). 0 disables the feature. + * Since _VER_9. * Below fields are for multi-bssid: * @ref_bssid_addr: reference BSSID used by the AP * @reserved_for_ref_bssid_addr: reserved @@ -706,17 +712,23 @@ struct iwl_link_config_cmd { /* MAC_QOS_PARAM_API_S_VER_1 */ __le32 qos_flags; struct iwl_ac_qos ac[AC_NUM + 1]; - u8 htc_trig_based_pkt_ext; - u8 rand_alloc_ecwmin; - u8 rand_alloc_ecwmax; + u8 htc_trig_based_pkt_ext; /* removed in _VER_9 */ + u8 rand_alloc_ecwmin; /* removed in _VER_9 */ + u8 rand_alloc_ecwmax; /* removed in _VER_9 */ u8 ndp_fdbk_buff_th_exp; struct iwl_he_backoff_conf trig_based_txf[AC_NUM]; __le32 bi; __le32 dtim_interval; __le16 puncture_mask; /* removed in _VER_3 */ - __le16 frame_time_rts_th; + __le16 frame_time_rts_th; /* removed in _VER_9 */ __le32 flags; - __le32 flags_mask; /* removed in _VER_6 */ + union { + __le32 flags_mask; /* removed in _VER_6 */ + struct { + u8 reserved4[3]; + u8 max_bssid_indicator; /* since _VER_9 */ + }; + }; /* The below fields are for multi-bssid */ u8 ref_bssid_addr[6]; __le16 reserved_for_ref_bssid_addr; @@ -730,7 +742,9 @@ struct iwl_link_config_cmd { struct iwl_ac_qos prio_edca_params; /* since _VER_7 */ __le32 reserved3[4]; } __packed; /* LINK_CONTEXT_CONFIG_CMD_API_S_VER_1, _VER_2, _VER_3, _VER_4, - * _VER_5, _VER_6, _VER_7, _VER_8 */ + * _VER_5, _VER_6, _VER_7, _VER_8, + * _VER_9 + */ /* Currently FW supports link ids in the range 0-3 and can have * at most two active links for each vif. diff --git a/drivers/net/wireless/intel/iwlwifi/mld/link.c b/drivers/net/wireless/intel/iwlwifi/mld/link.c index 65eddbd63016..c7d50ba30b36 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/link.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/link.c @@ -378,6 +378,11 @@ iwl_mld_change_link_in_fw(struct iwl_mld *mld, struct ieee80211_bss_conf *link, cmd.bssid_index = link->bssid_index; } + if (iwl_fw_lookup_cmd_ver(mld->fw, + WIDE_ID(MAC_CONF_GROUP, LINK_CONFIG_CMD), + 0) >= 9) + cmd.max_bssid_indicator = link->bssid_indicator; + /* The only EHT parameter is puncturing, and starting from PHY cmd * version 6 - it is sent there. For older versions of the PHY cmd, * puncturing is not needed at all. From e9531438f55097aa9f5f37e495b799803afe71b1 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:54 +0300 Subject: [PATCH 1546/2126] wifi: iwlwifi: pcie: fix TSO page leak in iwl_pcie_prep_tso() iwl_pcie_prep_tso() obtains a TSO header page via iwl_pcie_get_page_hdr(), which stores the page in skb->cb and increments its internal reference count. If skb_to_sgvec() or dma_map_sgtable() then fails, the function returns NULL without calling iwl_pcie_free_tso_pages() or otherwise dropping the page reference and/or DMA mapping. Fix this page leak. Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.9f5a0b76e75e.Ic7d2303cb85a6de5158a713f57d4366c7b0d93b0@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c index fae5beed2ecb..26d1530cfa37 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c @@ -1902,18 +1902,27 @@ struct sg_table *iwl_pcie_prep_tso(struct iwl_trans *trans, struct sk_buff *skb, /* Only map the data, not the header (it is copied to the TSO page) */ orig_nents = skb_to_sgvec(skb, sgt->sgl, offset, skb->len - offset); if (WARN_ON_ONCE(orig_nents <= 0)) - return NULL; + goto err_cleanup; sgt->orig_nents = orig_nents; /* And map the entire SKB */ if (dma_map_sgtable(trans->dev, sgt, DMA_TO_DEVICE, 0) < 0) - return NULL; + goto err_cleanup; /* Store non-zero (i.e. valid) offset for unmapping */ cmd_meta->sg_offset = (unsigned long) sgt & ~PAGE_MASK; return sgt; + +err_cleanup: + /* + * Since cmd_meta->sg_offset is not set yet, iwl_pcie_free_tso_pages + * will only free the page without unmapping the SG table (which hasn't + * been successfully mapped yet anyway). + */ + iwl_pcie_free_tso_pages(trans, skb, cmd_meta); + return NULL; } static int iwl_fill_data_tbs_amsdu(struct iwl_trans *trans, struct sk_buff *skb, From 7ca419fa4475443983e39bf62820c564f101a068 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Tue, 22 Sep 2026 14:49:55 +0300 Subject: [PATCH 1547/2126] wifi: iwlwifi: fix ctxt-info-v2 unwind UAF A failed ctxt-info-v2 allocation can free prph_scratch/prph_info without clearing the stored transport pointers. Clear stale DMA address/pointer fields during unwind. Also add an alloc-entry WARN_ON_ONCE/-EBUSY invariant to reject re-entry when ctxt/prph/iml state is already populated. Also, assign iml_len only the allocation. Assisted-by: GitHubCopilot:gpt-5.3-codex Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260922144819.be2c3cf96a4e.I207172d76a22c0302575f3383a044700f97a9980@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/pcie/ctxt-info-v2.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c index 06be929a3ca5..1ea23d297713 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2018-2025 Intel Corporation + * Copyright (C) 2018-2026 Intel Corporation */ #include #include "iwl-trans.h" @@ -112,6 +112,14 @@ int iwl_pcie_ctxt_info_v2_alloc(struct iwl_trans *trans, int cmdq_size = max_t(u32, IWL_CMD_QUEUE_SIZE, trans->mac_cfg->base->min_txq_size); + if (WARN_ON_ONCE(trans_pcie->ctxt_info_v2 || trans_pcie->prph_info || + trans_pcie->prph_scratch || trans_pcie->iml || + trans_pcie->ctxt_info_dma_addr || + trans_pcie->prph_info_dma_addr || + trans_pcie->prph_scratch_dma_addr || + trans_pcie->iml_dma_addr || trans_pcie->iml_len)) + return -EBUSY; + switch (trans->conf.rx_buf_size) { case IWL_AMSDU_DEF: return -EINVAL; @@ -263,7 +271,6 @@ int iwl_pcie_ctxt_info_v2_alloc(struct iwl_trans *trans, trans_pcie->prph_scratch = prph_scratch; /* Allocate IML */ - trans_pcie->iml_len = fw->iml_len; trans_pcie->iml = dma_alloc_coherent(trans->dev, fw->iml_len, &trans_pcie->iml_dma_addr, GFP_KERNEL); @@ -271,6 +278,7 @@ int iwl_pcie_ctxt_info_v2_alloc(struct iwl_trans *trans, ret = -ENOMEM; goto err_free_ctxt_info; } + trans_pcie->iml_len = fw->iml_len; memcpy(trans_pcie->iml, fw->iml, fw->iml_len); @@ -280,16 +288,21 @@ err_free_ctxt_info: dma_free_coherent(trans->dev, sizeof(*trans_pcie->ctxt_info_v2), trans_pcie->ctxt_info_v2, trans_pcie->ctxt_info_dma_addr); + trans_pcie->ctxt_info_dma_addr = 0; trans_pcie->ctxt_info_v2 = NULL; err_free_prph_info: dma_free_coherent(trans->dev, PAGE_SIZE, prph_info, trans_pcie->prph_info_dma_addr); + trans_pcie->prph_info_dma_addr = 0; + trans_pcie->prph_info = NULL; err_free_prph_scratch: dma_free_coherent(trans->dev, sizeof(*prph_scratch), prph_scratch, trans_pcie->prph_scratch_dma_addr); + trans_pcie->prph_scratch_dma_addr = 0; + trans_pcie->prph_scratch = NULL; return ret; } From a5d2d2e169634701756e2df6ab0fafd46fc622dd Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 22 Sep 2026 14:49:56 +0300 Subject: [PATCH 1548/2126] wifi: iwlwifi: mld: pass phy status explicitly for sniffer In some cases the frame status is changed to AID_NOT_FOR_US if no data is received. Pass the status explicitly so that the PHY data remains intact as that simplifies debugging. Signed-off-by: Benjamin Berg Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260922144819.86c1201ae2f6.I4b10b530325df711c7d229f1c487285a4dfcd294@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 02bdf6ccbcdc..82da642146a7 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -2281,7 +2281,7 @@ void iwl_mld_handle_rsc_notif(struct iwl_mld *mld, #endif /* CONFIG_PM_SLEEP */ static void iwl_mld_no_data_rx(struct iwl_mld *mld, - struct napi_struct *napi, + struct napi_struct *napi, u8 status, struct iwl_rx_phy_air_sniffer_ntfy *ntfy) { struct ieee80211_rx_status *rx_status; @@ -2306,7 +2306,7 @@ static void iwl_mld_no_data_rx(struct iwl_mld *mld, /* 0-length PSDU */ rx_status->flag |= RX_FLAG_NO_PSDU; - switch (ntfy->status) { + switch (status) { case IWL_SNIF_STAT_PLCP_RX_OK: /* we only get here with sounding PPDUs */ rx_status->zero_length_psdu_type = @@ -2365,11 +2365,9 @@ void iwl_mld_handle_phy_air_sniffer_notif(struct iwl_mld *mld, return; /* check if there's an old one to release as errored */ - if (mld->monitor.phy.valid && !mld->monitor.phy.used) { - /* didn't capture data, so override status */ - mld->monitor.phy.data.status = IWL_SNIF_STAT_AID_NOT_FOR_US; - iwl_mld_no_data_rx(mld, napi, &mld->monitor.phy.data); - } + if (mld->monitor.phy.valid && !mld->monitor.phy.used) + iwl_mld_no_data_rx(mld, napi, IWL_SNIF_STAT_AID_NOT_FOR_US, + &mld->monitor.phy.data); /* old data is no longer valid now */ mld->monitor.phy.valid = false; @@ -2406,7 +2404,7 @@ void iwl_mld_handle_phy_air_sniffer_notif(struct iwl_mld *mld, } if (ntfy->status != IWL_SNIF_STAT_PLCP_RX_OK || is_ndp) { - iwl_mld_no_data_rx(mld, napi, ntfy); + iwl_mld_no_data_rx(mld, napi, ntfy->status, ntfy); return; } From 7dd06e9263ce7fd96eff3d24514e8decafdd9de8 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Tue, 22 Sep 2026 14:49:57 +0300 Subject: [PATCH 1549/2126] wifi: iwlwifi: mld: Add support for scan iteration complete notification v3 Add support for scan iteration complete notification v3. This version is a superset of the previous version and adds information about the EBS corresponding with this scan iteration. Assisted-by: GitHub-Copilot:claude-opus-5 Signed-off-by: Ilan Peer Link: https://patch.msgid.link/20260922144819.daf57b66d8a9.I1ff60b070464ea5cc1f402293c2342157d29ea79@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/scan.h | 40 ++++++++++++++++++- .../net/wireless/intel/iwlwifi/mld/notif.c | 3 +- drivers/net/wireless/intel/iwlwifi/mld/scan.c | 15 ++++++- drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/scan.c | 2 +- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h b/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h index ee78371082b0..cb6217763bd1 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h @@ -987,6 +987,8 @@ struct iwl_scan_probe_params_v4 { #define SCAN_MAX_NUM_CHANS_V3 67 #define SCAN_MAX_NUM_CHANS_V4 68 +#define SCAN_MAX_NUM_NOTIF_RESULTS 112 + /** * struct iwl_scan_channel_params_v4 - channel params * @flags: channel flags &enum iwl_scan_channel_flags @@ -1325,7 +1327,8 @@ struct iwl_scan_offload_match_info { */ /** - * struct iwl_umac_scan_iter_complete_notif - notifies end of scanning iteration + * struct iwl_umac_scan_iter_complete_notif_v2 - notifies end of scanning + * iteration * @uid: scan id, &enum iwl_umac_scan_uid_offsets * @scanned_channels: number of channels scanned and number of valid elements in * results array @@ -1336,7 +1339,7 @@ struct iwl_scan_offload_match_info { * in &struct iwl_scan_req_umac. * @results: array of scan results, length in @scanned_channels */ -struct iwl_umac_scan_iter_complete_notif { +struct iwl_umac_scan_iter_complete_notif_v2 { __le32 uid; u8 scanned_channels; u8 status; @@ -1346,6 +1349,39 @@ struct iwl_umac_scan_iter_complete_notif { struct iwl_scan_results_notif results[]; } __packed; /* SCAN_ITER_COMPLETE_NTF_UMAC_API_S_VER_2 */ +/** + * struct iwl_umac_scan_iter_complete_notif - notifies end of scanning + * iteration + * @uid: scan id, &enum iwl_umac_scan_uid_offsets + * @scanned_channels: number of channels scanned and number of valid elements in + * results array + * @status: one of SCAN_COMP_STATUS_* + * @bt_status: BT on/off status + * @last_channel: last channel that was scanned + * @start_tsf: TSF timer in usecs of the scan start time for the mac specified + * in &struct iwl_scan_req_umac. + * @results: array of scan results, only @scanned_channels of them are valid + * @ebs_status: EBS completion status, &enum iwl_scan_ebs_status + * @reserved: reserved for alignment + * @ebs_channel_status: only valid when @ebs_status is %IWL_SCAN_EBS_SUCCESS. + * Bitmap of the 5 GHz channels on which EBS found energy: + * bit i in [0..27]: channel = 36 + 4 * i (channels 36 - 144) + * bit i in [28..35]: channel = 37 + 4 * i (channels 149 - 177) + * bit 36: channel 181 (reserved, not currently covered by EBS) + */ +struct iwl_umac_scan_iter_complete_notif { + __le32 uid; + u8 scanned_channels; + u8 status; + u8 bt_status; + u8 last_channel; + __le64 start_tsf; + struct iwl_scan_results_notif results[SCAN_MAX_NUM_NOTIF_RESULTS]; + u8 ebs_status; + u8 reserved[3]; + __le64 ebs_channel_status; +} __packed; /* SCAN_ITER_COMPLETE_NTF_UMAC_API_S_VER_3 */ + /** * struct iwl_umac_scan_channel_survey_notif - data for survey * @channel: the channel scanned diff --git a/drivers/net/wireless/intel/iwlwifi/mld/notif.c b/drivers/net/wireless/intel/iwlwifi/mld/notif.c index d0b85adf7417..570b0011fd9e 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/notif.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/notif.c @@ -292,7 +292,8 @@ CMD_VERSIONS(scan_start_notif, CMD_VERSIONS(scan_complete_notif, CMD_VER_ENTRY(1, iwl_umac_scan_complete)) CMD_VERSIONS(scan_iter_complete_notif, - CMD_VER_ENTRY(2, iwl_umac_scan_iter_complete_notif)) + CMD_VER_ENTRY(2, iwl_umac_scan_iter_complete_notif_v2) + CMD_VER_ENTRY(3, iwl_umac_scan_iter_complete_notif)) CMD_VERSIONS(channel_survey_notif, CMD_VER_ENTRY(1, iwl_umac_scan_channel_survey_notif)) CMD_VERSIONS(mfuart_notif, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/scan.c b/drivers/net/wireless/intel/iwlwifi/mld/scan.c index 0faca402bc14..e44b24904c19 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/scan.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/scan.c @@ -1992,7 +1992,14 @@ void iwl_mld_int_mlo_scan(struct iwl_mld *mld, struct ieee80211_vif *vif) void iwl_mld_handle_scan_iter_complete_notif(struct iwl_mld *mld, struct iwl_rx_packet *pkt) { - struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data; + /* + * The v3 notification is a superset of v2, so the fields that are + * common to both versions can always be read from the v3 layout. + */ + const struct iwl_umac_scan_iter_complete_notif *notif = + (const void *)pkt->data; + u8 notif_ver = iwl_fw_lookup_notif_ver(mld->fw, LEGACY_GROUP, + SCAN_ITERATION_COMPLETE_UMAC, 2); u32 uid = __le32_to_cpu(notif->uid); if (IWL_FW_CHECK(mld, uid >= ARRAY_SIZE(mld->scan.uid_status), @@ -2006,6 +2013,12 @@ void iwl_mld_handle_scan_iter_complete_notif(struct iwl_mld *mld, "UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n", notif->status, notif->scanned_channels); + if (notif_ver >= 3) + IWL_DEBUG_SCAN(mld, + "UMAC Scan iteration complete: EBS=%s, EBS channel status=0x%llx\n", + iwl_mld_scan_ebs_status_str(notif->ebs_status), + le64_to_cpu(notif->ebs_channel_status)); + if (mld->scan.pass_all_sched_res == SCHED_SCAN_PASS_ALL_STATE_FOUND) { IWL_DEBUG_SCAN(mld, "Pass all scheduled scan results found\n"); ieee80211_sched_scan_results(mld->hw); diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c index 1dd27292af9b..93d5cab87f64 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c @@ -374,7 +374,7 @@ static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = { struct iwl_umac_scan_complete), RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_iter_complete_notif, RX_HANDLER_SYNC, - struct iwl_umac_scan_iter_complete_notif), + struct iwl_umac_scan_iter_complete_notif_v2), RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif_legacy, diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c index 3831b3c27e0f..817c6dacfacc 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c @@ -3282,7 +3282,7 @@ void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) { struct iwl_rx_packet *pkt = rxb_addr(rxb); - struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data; + struct iwl_umac_scan_iter_complete_notif_v2 *notif = (void *)pkt->data; mvm->scan_start = le64_to_cpu(notif->start_tsf); From c5dda1236138b637195dd053e045eda5179cf17d Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Tue, 22 Sep 2026 14:49:58 +0300 Subject: [PATCH 1550/2126] wifi: iwlwifi: mld: log error when missing a recovery buffer If we are recovering from FW error but we don't have a reocvery buffer (for example due to a driver bug), it means that the FW might not have all the data it needs and we can therefore have bugs after the recovery. Those bugs can be difficult to debug. Log a clear error in such case. Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260922144819.afd6c953d680.Ibbf29ef47b99a9037a56b3342883376e9f7749dd@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/fw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/fw.c b/drivers/net/wireless/intel/iwlwifi/mld/fw.c index 7b1fb84a641c..e5866d89176d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/fw.c @@ -396,8 +396,10 @@ void iwl_mld_send_recovery_cmd(struct iwl_mld *mld, u32 flags) if (flags & ERROR_RECOVERY_UPDATE_DB) { /* no buf was allocated upon NIC error */ - if (!mld->error_recovery_buf) + if (!mld->error_recovery_buf) { + IWL_ERR(mld, "Recovering without recovery buffer. Expect bugs\n"); return; + } cmd.data[1] = mld->error_recovery_buf; cmd.len[1] = error_log_size; From d9504926b43d721659db69c81eae534b09c63d32 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Tue, 22 Sep 2026 14:49:59 +0300 Subject: [PATCH 1551/2126] wifi: iwlwifi: mld: avoid leaking error recovery buffer If we allocated a recovery buffer, but didn't eventually send the recovery command (for example because we failed to load the FW), We won't free the buffer until the module is unloaded. If in between another FW error occured, we will override the pointer with a new allocated buffer without freeing the previous one. Fix this by freeing a previous buffer before allocating a new one. Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260922144819.36e637b8162a.Ida6e834d7f5d1e69d46c47e2e46db1e87a57ac71@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/mld.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mld.c b/drivers/net/wireless/intel/iwlwifi/mld/mld.c index 6e991fb99ff3..b7b1e3686336 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mld.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/mld.c @@ -621,6 +621,13 @@ static void iwl_mld_read_error_recovery_buffer(struct iwl_mld *mld) if (!src_size) return; + /* + * If we have a the recovery buffer from a previous (failing) recovery - + * free it here + */ + kfree(mld->error_recovery_buf); + mld->error_recovery_buf = NULL; + recovery_buf = kzalloc(src_size, GFP_ATOMIC); if (!recovery_buf) return; From 567d62c9eadb5e4d1a46e02819a807564d9cda11 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Tue, 22 Sep 2026 14:50:00 +0300 Subject: [PATCH 1552/2126] wifi: iwlwifi: fw: reject empty UEFI DSM query bitmap Some platforms expose a UEFI DSM table with the expected revision but with an empty QUERY bitmap, which means no DSM function is advertised as valid. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260922144819.fe9c61c887e1.I735e6a67f7fb4903ddeca84f0a2ca5cd062ba1df@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index bf6a31e6f149..7c290b526383 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -915,6 +915,12 @@ static int iwl_uefi_load_dsm_values(struct iwl_fw_runtime *fwrt) data->revision); goto out; } + if (!data->functions[DSM_FUNC_QUERY]) { + IWL_DEBUG_RADIO(fwrt, + "UEFI DSM query bitmap is empty, revision:%d\n", + data->revision); + goto out; + } fwrt->dsm_revision = data->revision; fwrt->dsm_source = BIOS_SOURCE_UEFI; From b6b944fe45cbb30e4a9ddbd30b0f86290f3db5da Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Tue, 22 Sep 2026 14:50:01 +0300 Subject: [PATCH 1553/2126] wifi: iwlwifi: fw: fix dbg dest TLV size check by version Validate FW_DBG_DEST TLV size before using it: Validate the version byte first, then check the length of each version of the payload. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260922144819.7eb8d71ff962.I81295f046c785da613331c6a619897ccf66007d6@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c index ef9d50ee3704..0982e60842b1 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c @@ -1103,10 +1103,17 @@ static int iwl_parse_tlv_firmware(struct iwl_drv *drv, const struct iwl_fw_dbg_dest_tlv_v1 *dest_v1 = NULL; u8 mon_mode; + if (tlv_len < sizeof(*pieces->dbg_dest_ver)) + goto invalid_tlv_len; + pieces->dbg_dest_ver = (const u8 *)tlv_data; if (*pieces->dbg_dest_ver == 1) { + if (tlv_len < sizeof(*dest)) + goto invalid_tlv_len; dest = (const void *)tlv_data; } else if (*pieces->dbg_dest_ver == 0) { + if (tlv_len < sizeof(*dest_v1)) + goto invalid_tlv_len; dest_v1 = (const void *)tlv_data; } else { IWL_ERR(drv, From d7193a172370772aba312c2189429128d03da9e7 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 22 Sep 2026 14:50:02 +0300 Subject: [PATCH 1554/2126] wifi: iwlwifi: mld: separate HT/VHT/HE/EHT LDPC/STBC capabilities It appears that there are some APs that advertise STBC for HT and VHT, but don't actually support it for HE. Since the FW TLC will only use the mode we set (or fall back to legacy rates), we can set the bits according to the mode for STBC and LDPC. For EHT, there's no STBC at all, but LDPC support is more complex to determine. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20260922144819.cf235dddcbb3.I315c8089e341c6f7b2108276a32560595a8571fd@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/tlc.c | 175 +++++++++++++------ 1 file changed, 121 insertions(+), 54 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tlc.c b/drivers/net/wireless/intel/iwlwifi/mld/tlc.c index 1f5994f8be26..0e448b24a6a5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tlc.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tlc.c @@ -49,9 +49,60 @@ struct iwl_mld_tlc_sta_capa { const struct ieee80211_sta_uhr_cap *own_uhr_cap; }; +static bool iwl_mld_eht_ldpc_support(const struct ieee80211_sta_he_cap *he_cap, + const struct ieee80211_sta_eht_cap *eht_cap, + bool from_ap) +{ + u8 nss; + + /* higher bandwidth implies LDPC */ + if (he_cap->he_cap_elem.phy_cap_info[0] & + IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G) + return true; + if (he_cap->he_cap_elem.phy_cap_info[0] & + IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G) + return true; + if (he_cap->he_cap_elem.phy_cap_info[0] & + IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) + return true; + if (eht_cap->eht_cap_elem.phy_cap_info[0] & + IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) + return true; + + /* MCS 10-14 imply LDPC support, we only check 10-13 here */ + if (!from_ap) { + const struct ieee80211_eht_mcs_nss_supp_20mhz_only *mcs_nss; + + mcs_nss = &eht_cap->eht_mcs_nss_supp.only_20mhz; + + if (mcs_nss->rx_tx_mcs11_max_nss || + mcs_nss->rx_tx_mcs13_max_nss) + return true; + + nss = mcs_nss->rx_tx_mcs7_max_nss; + } else { + const struct ieee80211_eht_mcs_nss_supp_bw *mcs_nss; + + mcs_nss = &eht_cap->eht_mcs_nss_supp.bw._80; + + if (mcs_nss->rx_tx_mcs11_max_nss || + mcs_nss->rx_tx_mcs13_max_nss) + return true; + + nss = mcs_nss->rx_tx_mcs9_max_nss; + } + + /* NSS > 4 implies LDPC support */ + return u8_get_bits(nss, IEEE80211_EHT_MCS_NSS_RX) > 4 || + u8_get_bits(nss, IEEE80211_EHT_MCS_NSS_TX) > 4; +} + static __le16 iwl_mld_get_tlc_cmd_flags(struct iwl_mld *mld, - struct iwl_mld_tlc_sta_capa *capa) + struct ieee80211_vif *vif, + struct iwl_mld_tlc_sta_capa *capa, + enum iwl_tlc_mng_cfg_mode mode, + enum iwl_tlc_mng_cfg_cw max_bw) { const struct ieee80211_sta_ht_cap *ht_cap = capa->ht_cap; const struct ieee80211_sta_vht_cap *vht_cap = capa->vht_cap; @@ -61,64 +112,79 @@ iwl_mld_get_tlc_cmd_flags(struct iwl_mld *mld, const struct ieee80211_sta_he_cap *own_he_cap = capa->own_he_cap; const struct ieee80211_sta_eht_cap *own_eht_cap = capa->own_eht_cap; const struct ieee80211_sta_uhr_cap *own_uhr_cap = capa->own_uhr_cap; - bool has_vht = vht_cap && vht_cap->vht_supported; + bool stbc_possible = mld->cfg->ht_params.stbc && + hweight8(iwl_mld_get_valid_tx_ant(mld)) > 1; u16 flags = 0; - /* STBC flags */ - if (mld->cfg->ht_params.stbc && - (hweight8(iwl_mld_get_valid_tx_ant(mld)) > 1)) { - if (he_cap && he_cap->has_he && + switch (mode) { + case IWL_TLC_MNG_MODE_NON_HT: + break; + case IWL_TLC_MNG_MODE_HT: + if (WARN_ON(!ht_cap || !ht_cap->ht_supported)) + return 0; + if (stbc_possible && + ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) + flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK; + if (mld->cfg->ht_params.ldpc && + ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) + flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; + break; + case IWL_TLC_MNG_MODE_VHT: + if (WARN_ON(!vht_cap || !vht_cap->vht_supported)) + return 0; + if (stbc_possible && + vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK) + flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK; + if (mld->cfg->ht_params.ldpc && + vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC) + flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; + break; + case IWL_TLC_MNG_MODE_HE: + if (WARN_ON(!he_cap || !he_cap->has_he || !own_he_cap)) + return 0; + if (stbc_possible && he_cap->he_cap_elem.phy_cap_info[2] & - IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ) - flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK; - else if (vht_cap && - vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK) - flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK; - else if (ht_cap && ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) + IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ && + (max_bw <= IWL_TLC_MNG_CH_WIDTH_80MHZ || + he_cap->he_cap_elem.phy_cap_info[7] & + IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ)) flags |= IWL_TLC_MNG_CFG_FLAGS_STBC_MSK; + if (he_cap->he_cap_elem.phy_cap_info[1] & + IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD && + own_he_cap->he_cap_elem.phy_cap_info[1] & + IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD) + flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; + if (he_cap->he_cap_elem.phy_cap_info[3] & + IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK && + own_he_cap->he_cap_elem.phy_cap_info[3] & + IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK) + flags |= IWL_TLC_MNG_CFG_FLAGS_HE_DCM_NSS_1_MSK; + break; + case IWL_TLC_MNG_MODE_UHR: + if (WARN_ON(!uhr_cap || !uhr_cap->has_uhr || !own_uhr_cap)) + return 0; + if (uhr_cap->phy.cap & cpu_to_le32(IEEE80211_UHR_PHY_CAP_ELR_RX) && + own_uhr_cap->phy.cap & cpu_to_le32(IEEE80211_UHR_PHY_CAP_ELR_TX)) + flags |= IWL_TLC_MNG_CFG_FLAGS_UHR_ELR_1_5_MBPS_MSK | + IWL_TLC_MNG_CFG_FLAGS_UHR_ELR_3_MBPS_MSK; + /* uses most config from EHT */ + fallthrough; + case IWL_TLC_MNG_MODE_EHT: + if (WARN_ON(!own_he_cap || !he_cap || !he_cap->has_he || + !own_eht_cap || !eht_cap || !eht_cap->has_eht)) + return 0; + if (own_eht_cap->eht_cap_elem.phy_cap_info[5] & + IEEE80211_EHT_PHY_CAP5_SUPP_EXTRA_EHT_LTF && + eht_cap->eht_cap_elem.phy_cap_info[5] & + IEEE80211_EHT_PHY_CAP5_SUPP_EXTRA_EHT_LTF) + flags |= IWL_TLC_MNG_CFG_FLAGS_EHT_EXTRA_LTF_MSK; + /* no STBC in EHT */ + if (iwl_mld_eht_ldpc_support(he_cap, eht_cap, + vif->type == NL80211_IFTYPE_STATION)) + flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; + break; } - /* LDPC */ - if (mld->cfg->ht_params.ldpc && - ((ht_cap && ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) || - (has_vht && (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC)))) - flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; - - if (he_cap && he_cap->has_he && - (he_cap->he_cap_elem.phy_cap_info[1] & - IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD)) - flags |= IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; - - if (own_he_cap && - !(own_he_cap->he_cap_elem.phy_cap_info[1] & - IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD)) - flags &= ~IWL_TLC_MNG_CFG_FLAGS_LDPC_MSK; - - /* DCM */ - if (he_cap && he_cap->has_he && - (he_cap->he_cap_elem.phy_cap_info[3] & - IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK && - own_he_cap && - own_he_cap->he_cap_elem.phy_cap_info[3] & - IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK)) - flags |= IWL_TLC_MNG_CFG_FLAGS_HE_DCM_NSS_1_MSK; - - /* Extra EHT LTF */ - if (own_eht_cap && - own_eht_cap->eht_cap_elem.phy_cap_info[5] & - IEEE80211_EHT_PHY_CAP5_SUPP_EXTRA_EHT_LTF && - eht_cap && eht_cap->has_eht && - eht_cap->eht_cap_elem.phy_cap_info[5] & - IEEE80211_EHT_PHY_CAP5_SUPP_EXTRA_EHT_LTF) { - flags |= IWL_TLC_MNG_CFG_FLAGS_EHT_EXTRA_LTF_MSK; - } - - if (uhr_cap && uhr_cap->has_uhr && own_uhr_cap && - uhr_cap->phy.cap & cpu_to_le32(IEEE80211_UHR_PHY_CAP_ELR_RX) && - own_uhr_cap->phy.cap & cpu_to_le32(IEEE80211_UHR_PHY_CAP_ELR_TX)) - flags |= IWL_TLC_MNG_CFG_FLAGS_UHR_ELR_1_5_MBPS_MSK | - IWL_TLC_MNG_CFG_FLAGS_UHR_ELR_3_MBPS_MSK; - return cpu_to_le16(flags); } @@ -478,7 +544,6 @@ static void iwl_mld_send_tlc_cmd(struct iwl_mld *mld, .max_ch_width = mld_sta->sta_state > IEEE80211_STA_ASSOC ? iwl_mld_fw_bw_from_sta_bw(capa->bandwidth) : IWL_TLC_MNG_CH_WIDTH_20MHZ, - .flags = iwl_mld_get_tlc_cmd_flags(mld, capa), .chains = iwl_mld_get_fw_chains(mld), .sgi_ch_width_supp = iwl_mld_get_fw_sgi(capa), .max_mpdu_len = cpu_to_le16(capa->max_amsdu_len), @@ -493,6 +558,8 @@ static void iwl_mld_send_tlc_cmd(struct iwl_mld *mld, cmd.phy_id = cpu_to_le32(phy_id); iwl_mld_fill_supp_rates(mld, vif, capa, &cmd); + cmd.flags = iwl_mld_get_tlc_cmd_flags(mld, vif, capa, cmd.mode, + cmd.max_ch_width); if (cmd_ver == 6) { cmd_ptr = &cmd; From b154c5bdb728491765f7b6cb24a3f989b962865a Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Wed, 23 Sep 2026 16:04:44 +0300 Subject: [PATCH 1555/2126] wifi: iwlwifi: mvm: remove indirection_tbl debugfs entry The RSS indirection table debugfs knob is not used, and its pattern repetition logic triggered a static analysis out-of-bounds report on the trailing copy that forms a one-past-the-end pointer. Rather than reworking unused code, drop the entry entirely. Assisted-by: GitHub-Copilot:claude-opus-5 Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260923160318.bc19cf5a20b9.I04cbf6a929070775a7e0cb04c7330421e6777f4e@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/mvm/debugfs.c | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c index b7315598d522..99fb149b8543 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c @@ -1145,53 +1145,6 @@ iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf, return count; } -static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm, - char *buf, size_t count, - loff_t *ppos) -{ - struct iwl_rss_config_cmd cmd = { - .flags = cpu_to_le32(IWL_RSS_ENABLE), - .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP | - IWL_RSS_HASH_TYPE_IPV4_UDP | - IWL_RSS_HASH_TYPE_IPV4_PAYLOAD | - IWL_RSS_HASH_TYPE_IPV6_TCP | - IWL_RSS_HASH_TYPE_IPV6_UDP | - IWL_RSS_HASH_TYPE_IPV6_PAYLOAD, - }; - int ret, i, num_repeats, nbytes = count / 2; - - ret = hex2bin(cmd.indirection_table, buf, nbytes); - if (ret) - return ret; - - /* - * The input is the redirection table, partial or full. - * Repeat the pattern if needed. - * For example, input of 01020F will be repeated 42 times, - * indirecting RSS hash results to queues 1, 2, 15 (skipping - * queues 3 - 14). - */ - num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes; - for (i = 1; i < num_repeats; i++) - memcpy(&cmd.indirection_table[i * nbytes], - cmd.indirection_table, nbytes); - /* handle cut in the middle pattern for the last places */ - memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table, - ARRAY_SIZE(cmd.indirection_table) % nbytes); - - netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key)); - - mutex_lock(&mvm->mutex); - if (iwl_mvm_firmware_running(mvm)) - ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, - sizeof(cmd), &cmd); - else - ret = 0; - mutex_unlock(&mvm->mutex); - - return ret ?: count; -} - static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm, char *buf, size_t count, loff_t *ppos) @@ -1866,8 +1819,6 @@ MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8); MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8); MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_clear, 64); MVM_DEBUGFS_WRITE_FILE_OPS(dbg_time_point, 64); -MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl, - (IWL_RSS_INDIRECTION_TABLE_SIZE * 2)); MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512); MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie, 512); MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie_restore, 512); @@ -2066,7 +2017,6 @@ void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm) MVM_DEBUGFS_ADD_FILE(fw_dbg_clear, mvm->debugfs_dir, 0200); MVM_DEBUGFS_ADD_FILE(dbg_time_point, mvm->debugfs_dir, 0200); MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, 0200); - MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, 0200); MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, 0200); MVM_DEBUGFS_ADD_FILE(inject_beacon_ie, mvm->debugfs_dir, 0200); MVM_DEBUGFS_ADD_FILE(inject_beacon_ie_restore, mvm->debugfs_dir, 0200); From e8fa92f169ff569e323be5073c4358e5bc91ddd4 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Wed, 23 Sep 2026 16:04:45 +0300 Subject: [PATCH 1556/2126] wifi: iwlwifi: mvm: debugfs: validate TAS response and loop bounds iwl_dbgfs_tas_get_status_read() trusted the FW response layout and iterated with rsp->in_dual_radio + 1 without capping to the tas_status_mac array size. A malformed or inconsistent response could lead to out-of-bounds access while printing TAS status. Validate the GET_TAS_STATUS payload length before dereferencing rsp, free the response on early allocation failure, and cap both TAS loops with array size. This keeps the existing behavior for valid responses and hardens the debugfs path against invalid firmware data. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260923160318.f03b511b938e.Ib5069ecf15340506498a28d965c49387cab609b1@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c index 99fb149b8543..4db0f29dd21a 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c @@ -525,16 +525,24 @@ static ssize_t iwl_dbgfs_tas_get_status_read(struct file *file, if (ret < 0) return ret; + if (iwl_rx_packet_payload_len(hcmd.resp_pkt) != sizeof(*rsp)) { + iwl_free_resp(&hcmd); + return -EIO; + } + buff = kzalloc(bufsz, GFP_KERNEL); - if (!buff) + if (!buff) { + iwl_free_resp(&hcmd); return -ENOMEM; + } pos = buff; endpos = pos + bufsz; rsp = (void *)hcmd.resp_pkt->data; pos += scnprintf(pos, endpos - pos, "TAS Conclusion:\n"); - for (i = 0; i < rsp->in_dual_radio + 1; i++) { + for (i = 0; i < min_t(int, rsp->in_dual_radio + 1, + ARRAY_SIZE(rsp->tas_status_mac)); i++) { if (rsp->tas_status_mac[i].dynamic_status & BIT(TAS_DYNA_ACTIVE)) { pos += scnprintf(pos, endpos - pos, "\tON for "); @@ -589,7 +597,8 @@ static ssize_t iwl_dbgfs_tas_get_status_read(struct file *file, "\tDo TAS Support Dual Radio?: %s\n", rsp->in_dual_radio ? "TRUE" : "FALSE"); - for (i = 0; i < rsp->in_dual_radio + 1; i++) { + for (i = 0; i < min_t(int, rsp->in_dual_radio + 1, + ARRAY_SIZE(rsp->tas_status_mac)); i++) { if (rsp->tas_status_mac[i].static_status == 0) { pos += scnprintf(pos, endpos - pos, "Static status: disabled\n"); From cfd58870fe51b3ae441af40b438604486792b67c Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Wed, 23 Sep 2026 16:04:46 +0300 Subject: [PATCH 1557/2126] wifi: iwlwifi: mvm: fix LARI_CONFIG_EXTENSION version check The version guard used `< 1` instead of `!= 1`. With `< 1` the command would be sent for any firmware version >= 1, including future versions that may have a different structure, which could trigger a firmware assert due to a size/format mismatch. Fix the check to `!= 1` so the command is only sent when the firmware supports exactly version 1. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260923160318.27693f88a8d7.Id6a4b91938cd7758c2be3b98379f1057e574cdad@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c index 43a7230f1ab4..06f3b065914b 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c @@ -1526,7 +1526,7 @@ static void iwl_mvm_send_lari_cfg_extension(struct iwl_mvm *mvm) u32 value; int ret; - if (iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 0) < 1) + if (iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 0) != 1) return; ret = iwl_bios_get_dsm(fwrt, DSM_FUNC_REGULATORY_CONFIG, &value); From e1f10daf7cbdb08606cbf186e0d641ad7bad6c5f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 23 Sep 2026 16:04:47 +0300 Subject: [PATCH 1558/2126] wifi: iwlwifi: advertise 2xLDPC RX support for UHR In UHR, currently supported devices have 2x LDPC support. Enable the bit. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20260923160318.9771e88dbc3b.I22693891ed85fd0449ae17106e2502ec4ee2e086@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index 863d5e358152..6bb27d7f1166 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -710,7 +710,8 @@ static const struct ieee80211_sband_iftype_data iwl_iftype_cap[] = { .has_uhr = true, /* Note: asymmetry is fixed later */ .phy.cap = cpu_to_le32(IEEE80211_UHR_PHY_CAP_ELR_RX | - IEEE80211_UHR_PHY_CAP_ELR_TX), + IEEE80211_UHR_PHY_CAP_ELR_TX | + IEEE80211_UHR_PHY_CAP_2XLDPC_RX), .mac.mac_cap = { [0] = IEEE80211_UHR_MAC_CAP0_NPCA_SUPP | IEEE80211_UHR_MAC_CAP0_DPS_SUPP, @@ -820,7 +821,8 @@ static const struct ieee80211_sband_iftype_data iwl_iftype_cap[] = { .has_uhr = true, /* Note: asymmetry is fixed later */ .phy.cap = cpu_to_le32(IEEE80211_UHR_PHY_CAP_ELR_RX | - IEEE80211_UHR_PHY_CAP_ELR_TX), + IEEE80211_UHR_PHY_CAP_ELR_TX | + IEEE80211_UHR_PHY_CAP_2XLDPC_RX), }, }, }; From 5e45403e60e17c971c97ce6f432960852c3d5f1a Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 23 Sep 2026 16:04:48 +0300 Subject: [PATCH 1559/2126] wifi: iwlwifi: mld: fix some UHR ELR bits These were wrong in the driver based on the hardware definitions, fix them. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20260923160318.3fa552b3d795.I8098855c931e1f9df16951e2d527bb079eca0549@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/api/rx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h b/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h index 699343cf0279..a8f1edf19bbe 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h @@ -1347,7 +1347,7 @@ struct iwl_uhr_elr_sigs { #define OFDM_RX_VECTOR_UHR_ELR_PPDU_TYPE 0x00000003 #define OFDM_RX_VECTOR_UHR_ELR_USIG_STA_ID 0x00001ffc #define OFDM_RX_VECTOR_UHR_ELR_VALIDATE 0x0000e000 -#define OFDM_RX_VECTOR_UHR_ELR_CRC_OK 0x00010000 +#define OFDM_RX_VECTOR_UHR_ELR_CRC_OK 0x40000000 __le32 usig_a2_uhr_elr; #define OFDM_RX_VECTOR_UHR_ELR_VER_ID 0x00000007 #define OFDM_RX_VECTOR_UHR_ELR_UPLINK_FLAG 0x00000008 @@ -1363,7 +1363,7 @@ struct iwl_uhr_elr_sigs { #define OFDM_RX_VECTOR_UHR_ELR_SIG_ID_INDX 0x00000e00 #define OFDM_RX_VECTOR_UHR_ELR_STA_RU 0x000ff000 #define OFDM_RX_VECTOR_UHR_ELR_STA_RU_PS160 0x00100000 -#define OFDM_RX_VECTOR_UHR_ELR_SIG2_CRC_OK 0x00200000 +#define OFDM_RX_VECTOR_UHR_ELR_SIG2_CRC_OK 0x40000000 __le32 uhr_sig_elr2; }; From ff5bddd1bcf6b3f3a60e8a415d3ab97a82dbd3f1 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 23 Sep 2026 16:04:49 +0300 Subject: [PATCH 1560/2126] wifi: iwlwifi: mld: correct EHT U-SIG-1 B20:25 report This needs to be combined from two places, fix that. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20260923160318.e65cdac4424f.I23b05c26fc788081ad8aa2673e104e2215697416@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 82da642146a7..5f18aa551af5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -818,7 +818,8 @@ static void iwl_mld_decode_eht_usig_tb(struct iwl_mld_rx_phy_data *phy_data, __le32 usig_a2 = phy_data->ntfy->sigs.eht_tb.usig_a2_eht; IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a1, - OFDM_RX_FRAME_EHT_USIG1_DISREGARD, + OFDM_RX_FRAME_EHT_USIG1_DISREGARD | + OFDM_RX_FRAME_EHT_USIG1_VALIDATE, IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD); IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, OFDM_RX_FRAME_EHT_PPDU_TYPE, From 74f2ced8acb48cea939a13732e472a2e344ab7f9 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 23 Sep 2026 16:04:50 +0300 Subject: [PATCH 1561/2126] wifi: iwlwifi: support net detect match info version 3 Since API 77, firmware reports scan offload profile matches using SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_3, which has more channels (16 byte instead of 7). Somehow we missed this change, and the driver only handles the 5- and 7-byte layouts, so on such firmware it misparsed the match (reading band as energy) and could not recover matches beyond the first 56 channels. Add the version 3 match structure and select it based on the SCAN_OFFLOAD_PROFILES_QUERY_CMD notification version (in MVM, in MLD, this is the only version supported). In MVM, while walking the matched-channels bitmap, bound the channel index with IWL_FW_CHECK so firmware that sets a bit beyond n_nd_channels can no longer trigger an out-of-bounds read of nd_channels[]. Reviewed-by: Ilan Peer Link: https://patch.msgid.link/20260923160318.07738ca44b54.I58162891250af9f46220fd01db667460e6dd621b@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/scan.h | 28 +++++- drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 89 ++++++++++++++----- 2 files changed, 93 insertions(+), 24 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h b/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h index cb6217763bd1..8994a7b840ef 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/scan.h @@ -1234,7 +1234,8 @@ struct iwl_umac_scan_complete { } __packed; /* SCAN_COMPLETE_NTF_UMAC_API_S_VER_1 */ #define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 5 -#define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN 7 +#define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V2 7 +#define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN 16 /** * struct iwl_scan_offload_profile_match_v1 - match information @@ -1280,11 +1281,31 @@ struct iwl_scan_offload_profiles_query_v1 { struct iwl_scan_offload_profile_match_v1 matches[]; } __packed; /* SCAN_OFFLOAD_PROFILES_QUERY_RSP_S_VER_2 */ +/** + * struct iwl_scan_offload_profile_match_v2 - match information + * @bssid: matched bssid + * @reserved: reserved + * @channel: channel where the match occurred + * @energy: energy + * @matching_feature: feature matches + * @matching_channels: bitmap of channels that matched, referencing + * the channels passed in the scan offload request. + */ +struct iwl_scan_offload_profile_match_v2 { + u8 bssid[ETH_ALEN]; + __le16 reserved; + u8 channel; + u8 energy; + u8 matching_feature; + u8 matching_channels[SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V2]; +} __packed; /* SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_2 */ + /** * struct iwl_scan_offload_profile_match - match information * @bssid: matched bssid * @reserved: reserved * @channel: channel where the match occurred + * @band: band where the match occurred * @energy: energy * @matching_feature: feature matches * @matching_channels: bitmap of channels that matched, referencing @@ -1294,10 +1315,11 @@ struct iwl_scan_offload_profile_match { u8 bssid[ETH_ALEN]; __le16 reserved; u8 channel; + u8 band; u8 energy; u8 matching_feature; u8 matching_channels[SCAN_OFFLOAD_MATCHING_CHANNELS_LEN]; -} __packed; /* SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_2 */ +} __packed; /* SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_3 */ /** * struct iwl_scan_offload_match_info - match results information @@ -1322,7 +1344,7 @@ struct iwl_scan_offload_match_info { u8 self_recovery; __le16 reserved; struct iwl_scan_offload_profile_match matches[IWL_SCAN_MAX_PROFILES_V2]; -} __packed; /* SCAN_OFFLOAD_PROFILES_QUERY_RSP_S_VER_3 and +} __packed; /* SCAN_OFFLOAD_PROFILES_QUERY_RSP_S_VER_5 and * SCAN_OFFLOAD_MATCH_INFO_NOTIFICATION_S_VER_1 */ diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c index bd52f2ebd3ba..2abc4bc3eb34 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c @@ -2440,6 +2440,12 @@ struct iwl_mvm_nd_results { u8 matches[ND_QUERY_BUF_LEN]; }; +static bool iwl_mvm_nd_match_info_v3(struct iwl_mvm *mvm) +{ + return iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, + SCAN_OFFLOAD_PROFILES_QUERY_CMD, 0) >= 4; +} + static int iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm, struct iwl_mvm_nd_results *results) @@ -2459,12 +2465,17 @@ iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm, return ret; } - if (fw_has_api(&mvm->fw->ucode_capa, - IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { + if (iwl_mvm_nd_match_info_v3(mvm)) { matches_len = sizeof(struct iwl_scan_offload_profile_match) * max_profiles; query_len = offsetof(struct iwl_scan_offload_match_info, matches) + matches_len; + } else if (fw_has_api(&mvm->fw->ucode_capa, + IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { + matches_len = sizeof(struct iwl_scan_offload_profile_match_v2) * + max_profiles; + query_len = offsetof(struct iwl_scan_offload_match_info, + matches) + matches_len; } else { matches_len = sizeof(struct iwl_scan_offload_profile_match_v1) * max_profiles; @@ -2499,13 +2510,19 @@ static int iwl_mvm_query_num_match_chans(struct iwl_mvm *mvm, { int n_chans = 0, i; - if (fw_has_api(&mvm->fw->ucode_capa, - IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { + if (iwl_mvm_nd_match_info_v3(mvm)) { struct iwl_scan_offload_profile_match *matches = (void *)results->matches; for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN; i++) n_chans += hweight8(matches[idx].matching_channels[i]); + } else if (fw_has_api(&mvm->fw->ucode_capa, + IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { + struct iwl_scan_offload_profile_match_v2 *matches = + (void *)results->matches; + + for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V2; i++) + n_chans += hweight8(matches[idx].matching_channels[i]); } else { struct iwl_scan_offload_profile_match_v1 *matches = (void *)results->matches; @@ -2517,34 +2534,58 @@ static int iwl_mvm_query_num_match_chans(struct iwl_mvm *mvm, return n_chans; } +static void iwl_mvm_set_matching_freqs(struct iwl_mvm *mvm, + const u8 *matching_channels, + size_t num_bytes, + struct cfg80211_wowlan_nd_match *match) +{ + int n_channels = 0; + + for (int i = 0; i < num_bytes * 8; i++) { + if (!(matching_channels[i / 8] & BIT(i % 8))) + continue; + if (IWL_FW_CHECK(mvm, i >= mvm->n_nd_channels, + "FW matched channel bit %d beyond n_nd_channels %d\n", + i, mvm->n_nd_channels)) + break; + match->channels[n_channels++] = + mvm->nd_channels[i]->center_freq; + } + /* We may have ended up with fewer channels than we allocated. */ + match->n_channels = n_channels; +} + static void iwl_mvm_query_set_freqs(struct iwl_mvm *mvm, struct iwl_mvm_nd_results *results, struct cfg80211_wowlan_nd_match *match, int idx) { - int i; - int n_channels = 0; - - if (fw_has_api(&mvm->fw->ucode_capa, - IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { + if (iwl_mvm_nd_match_info_v3(mvm)) { struct iwl_scan_offload_profile_match *matches = (void *)results->matches; - for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; i++) - if (matches[idx].matching_channels[i / 8] & (BIT(i % 8))) - match->channels[n_channels++] = - mvm->nd_channels[i]->center_freq; + iwl_mvm_set_matching_freqs(mvm, + matches[idx].matching_channels, + sizeof(matches[idx].matching_channels), + match); + } else if (fw_has_api(&mvm->fw->ucode_capa, + IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { + struct iwl_scan_offload_profile_match_v2 *matches = + (void *)results->matches; + + iwl_mvm_set_matching_freqs(mvm, + matches[idx].matching_channels, + sizeof(matches[idx].matching_channels), + match); } else { struct iwl_scan_offload_profile_match_v1 *matches = (void *)results->matches; - for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 * 8; i++) - if (matches[idx].matching_channels[i / 8] & (BIT(i % 8))) - match->channels[n_channels++] = - mvm->nd_channels[i]->center_freq; + iwl_mvm_set_matching_freqs(mvm, + matches[idx].matching_channels, + sizeof(matches[idx].matching_channels), + match); } - /* We may have ended up with fewer channels than we allocated. */ - match->n_channels = n_channels; } /** @@ -2817,8 +2858,14 @@ static void iwl_mvm_nd_match_info_handler(struct iwl_mvm *mvm, struct iwl_wowlan_status_data *status = d3_data->status; struct ieee80211_vif *vif = iwl_mvm_get_bss_vif(mvm); struct iwl_mvm_nd_results *results = d3_data->nd_results; - size_t i, matches_len = sizeof(struct iwl_scan_offload_profile_match) * - iwl_umac_scan_get_max_profiles(mvm->fw); + size_t i, matches_len; + + if (iwl_mvm_nd_match_info_v3(mvm)) + matches_len = sizeof(struct iwl_scan_offload_profile_match) * + iwl_umac_scan_get_max_profiles(mvm->fw); + else + matches_len = sizeof(struct iwl_scan_offload_profile_match_v2) * + iwl_umac_scan_get_max_profiles(mvm->fw); if (IS_ERR_OR_NULL(vif)) return; From 6ec296ca4dc89fea5fde5fd3f1dc33536e3bdf30 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 23 Sep 2026 16:04:51 +0300 Subject: [PATCH 1562/2126] wifi: iwlwifi: bump maximum core version for BZ/SC/DR to 108 Start supporting Core 108 FW on these devices. The BZ/FM combination is frozen on Core107 (while each of BZ, FM is not yet frozen and is still supported in other combinations). Indicate this in the relevant FW file mames, for modinfo. While at it, remove names that are no longer needed. Link: https://patch.msgid.link/20260923160318.61c292103e38.I0e2918e21f8a20d200d371c1861ed2c5deac829d@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/cfg/bz.c | 8 +------- drivers/net/wireless/intel/iwlwifi/cfg/dr.c | 2 +- drivers/net/wireless/intel/iwlwifi/cfg/rf-fm.c | 4 ++++ drivers/net/wireless/intel/iwlwifi/cfg/sc.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/bz.c b/drivers/net/wireless/intel/iwlwifi/cfg/bz.c index 1099d8cfe6aa..3cc3ffd0aa1c 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/bz.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/bz.c @@ -10,14 +10,11 @@ #include "fw/api/txq.h" /* Highest firmware core release supported */ -#define IWL_BZ_UCODE_CORE_MAX 107 +#define IWL_BZ_UCODE_CORE_MAX 108 /* Lowest firmware core release supported */ #define IWL_BZ_UCODE_CORE_MIN 102 -#define IWL_BZ_A_FM_B_FW_PRE "iwlwifi-bz-a0-fm-b0" -#define IWL_BZ_A_FM_C_FW_PRE "iwlwifi-bz-a0-fm-c0" -#define IWL_BZ_A_FM4_B_FW_PRE "iwlwifi-bz-a0-fm4-b0" #define IWL_GL_B_FM_B_FW_PRE "iwlwifi-gl-b0-fm-b0" #define IWL_GL_C_FM_C_FW_PRE "iwlwifi-gl-c0-fm-c0" @@ -92,8 +89,5 @@ const struct iwl_mac_cfg iwl_gl_mac_cfg = { .low_latency_xtal = true, }; -IWL_CORE_FW(IWL_BZ_A_FM_B_FW_PRE, IWL_BZ_UCODE_CORE_MAX); -IWL_CORE_FW(IWL_BZ_A_FM_C_FW_PRE, IWL_BZ_UCODE_CORE_MAX); -IWL_CORE_FW(IWL_BZ_A_FM4_B_FW_PRE, IWL_BZ_UCODE_CORE_MAX); IWL_CORE_FW(IWL_GL_B_FM_B_FW_PRE, IWL_BZ_UCODE_CORE_MAX); IWL_CORE_FW(IWL_GL_C_FM_C_FW_PRE, IWL_BZ_UCODE_CORE_MAX); diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/dr.c b/drivers/net/wireless/intel/iwlwifi/cfg/dr.c index a89a2c75687f..f6dd1f9733fb 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/dr.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/dr.c @@ -9,7 +9,7 @@ #include "fw/api/txq.h" /* Highest firmware core release supported */ -#define IWL_DR_UCODE_CORE_MAX 107 +#define IWL_DR_UCODE_CORE_MAX 108 /* Lowest firmware core release supported */ #define IWL_DR_UCODE_CORE_MIN 102 diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/rf-fm.c b/drivers/net/wireless/intel/iwlwifi/cfg/rf-fm.c index 35b1618f3474..a7770cd61213 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/rf-fm.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/rf-fm.c @@ -5,6 +5,8 @@ */ #include "iwl-config.h" +#define IWL_BZ_A_FM_C_FW_PRE "iwlwifi-bz-a0-fm-c0" + #define IWL_DEVICE_FM \ .ht_params = { \ .stbc = true, \ @@ -48,3 +50,5 @@ const char iwl_be201_name[] = "Intel(R) Wi-Fi 7 BE201 320MHz"; const char iwl_be200_name[] = "Intel(R) Wi-Fi 7 BE200 320MHz"; const char iwl_be202_name[] = "Intel(R) Wi-Fi 7 BE202 160MHz"; const char iwl_be401_name[] = "Intel(R) Wi-Fi 7 BE401 320MHz"; + +IWL_CORE_FW(IWL_BZ_A_FM_C_FW_PRE, 107); diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/sc.c b/drivers/net/wireless/intel/iwlwifi/cfg/sc.c index 16abf0147fe4..467888c8d2cb 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/sc.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/sc.c @@ -10,7 +10,7 @@ #include "fw/api/txq.h" /* Highest firmware core release supported */ -#define IWL_SC_UCODE_CORE_MAX 107 +#define IWL_SC_UCODE_CORE_MAX 108 /* Lowest firmware core release supported */ #define IWL_SC_UCODE_CORE_MIN 102 From ce9a74d575297ec9d937194bd63a16548ce1892c Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 23 Sep 2026 16:04:52 +0300 Subject: [PATCH 1563/2126] wifi: iwlwifi: mvm: validate mpdu len before relying on it iwl_mvm_rx_mpdu_mq path only checks that the mpdu_len fits into the pkt len, but it doesn't validate len itself before dereferencing parts of the mpdu: the header, the padding, and the mic_crc_len. Check that the mpdu len covers the hdrlen, the padding (if exists) and the mic_crc_len. Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260923160318.fbf29ec27bc0.I4bb0dbd739ff1ddf969e51bbd68c42ca9e4e0634@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c index 8c4009d3a00c..c01c704929ba 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c @@ -99,10 +99,14 @@ static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb, u8 mic_crc_len = u8_get_bits(desc->mac_flags1, IWL_RX_MPDU_MFLG1_MIC_CRC_LEN_MASK) << 1; - if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { - len -= 2; - pad_len = 2; - } + pad_len = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD ? 2 : 0; + + if (IWL_FW_CHECK(mvm, len < hdrlen + crypt_len + pad_len + mic_crc_len, + "invalid len (%d): hdrlen=%u, crypt_len=%u, pad_len=%u, mic_crc_len=%u\n", + len, hdrlen, crypt_len, pad_len, mic_crc_len)) + return -EINVAL; + + len -= pad_len; /* * For non monitor interface strip the bytes the RADA might not have @@ -110,7 +114,7 @@ static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb, * interface cannot exist with other interfaces, this removal is safe * and sufficient, in monitor mode there's no decryption being done. */ - if (len > mic_crc_len && !ieee80211_hw_check(mvm->hw, RX_INCLUDES_FCS)) + if (!ieee80211_hw_check(mvm->hw, RX_INCLUDES_FCS)) len -= mic_crc_len; /* If frame is small enough to fit in skb->head, pull it completely. @@ -2164,7 +2168,17 @@ void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi, phy_data.phy_info = le16_to_cpu(desc->phy_info); phy_data.d4 = desc->phy_data4; + if (IWL_FW_CHECK(mvm, len < sizeof(hdr->frame_control), + "MPDU len (%u) is smaller than frame control\n", + len)) + return; + hdr = (void *)(pkt->data + desc_size); + if (IWL_FW_CHECK(mvm, len < ieee80211_hdrlen(hdr->frame_control), + "MPDU len (%u) is smaller than header length (%u)\n", + len, ieee80211_hdrlen(hdr->frame_control))) + return; + /* Dont use dev_alloc_skb(), we'll have enough headroom once * ieee80211_hdr pulled. */ @@ -2285,7 +2299,7 @@ void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi, struct iwl_fw_dbg_trigger_tlv *trig; struct ieee80211_vif *vif = mvmsta->vif; - if (!mvm->tcm.paused && len >= sizeof(*hdr) && + if (!mvm->tcm.paused && !is_multicast_ether_addr(hdr->addr1) && ieee80211_is_data(hdr->frame_control) && time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD)) From b7dc5aec39f29f97171797fb0bdbac38dd1e0d85 Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Wed, 23 Sep 2026 16:04:53 +0300 Subject: [PATCH 1564/2126] wifi: iwlwifi: uefi: add UEFI GUID Lock Indicator (GLUI) definitions The platform provides a root-of-trust mechanism for connectivity UEFI variables via a dedicated UEFI GUID Lock Indicator (GLUI) variable. The GLUI may remain locked in both production and testing modes. A UEFI indicator is used rather than relying on the ACPI GLAI alone, so the mechanism also works on platforms that do not expose ACPI. Add the building blocks for consuming this variable and iwl_uefi_get_guid_lock_status() to read its value and store it, so the driver can use its lock state to decide whether the connectivity UEFI variables are trusted. Signed-off-by: Shahar Tzarfati Assisted-by: GitHub-Copilot:claude-opus-4-8 Link: https://patch.msgid.link/20260923160318.55d7dc9c9531.If4c9949de70fe78951464b983caf2c9d974061b3@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/acpi.c | 3 +- drivers/net/wireless/intel/iwlwifi/fw/acpi.h | 4 --- .../wireless/intel/iwlwifi/fw/regulatory.c | 2 +- .../wireless/intel/iwlwifi/fw/regulatory.h | 13 +++++++ .../net/wireless/intel/iwlwifi/fw/runtime.h | 4 +-- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 34 +++++++++++++++++++ drivers/net/wireless/intel/iwlwifi/fw/uefi.h | 12 +++++++ 7 files changed, 64 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c index 71e0950d0193..f53cb531cf88 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c @@ -1153,7 +1153,8 @@ void iwl_acpi_get_guid_lock_status(struct iwl_fw_runtime *fwrt) } if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER || - wifi_pkg->package.elements[1].integer.value > ACPI_GLAI_MAX_STATUS) + wifi_pkg->package.elements[1].integer.value > + UEFI_CNV_GUID_TEST_MODE) goto out_free; fwrt->uefi_tables_lock_status = diff --git a/drivers/net/wireless/intel/iwlwifi/fw/acpi.h b/drivers/net/wireless/intel/iwlwifi/fw/acpi.h index 45eb35ffb637..426b0c51abec 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/acpi.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/acpi.h @@ -89,7 +89,6 @@ * and one for the status */ #define ACPI_GLAI_WIFI_DATA_SIZE 2 -#define ACPI_GLAI_MAX_STATUS 2 /* * TAS size: 1 elelment for type, * 1 element for enabled field, @@ -111,9 +110,6 @@ #define ACPI_PPAG_WIFI_DATA_SIZE_V3 ((ACPI_PPAG_NUM_CHAINS * \ ACPI_PPAG_NUM_BANDS_V3) + 2) -/* The Inidcator whether UEFI WIFI GUID tables are locked is read from ACPI */ -#define UEFI_WIFI_GUID_UNLOCKED 0 - #define ACPI_DSM_REV 0 #define DSM_INTERNAL_FUNC_GET_PLAT_INFO 1 diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index 3ab383b569bc..8dff97b8e0f1 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -12,7 +12,7 @@ #define GET_BIOS_TABLE(__name, ...) \ do { \ int ret = -ENOENT; \ - if (fwrt->uefi_tables_lock_status > UEFI_WIFI_GUID_UNLOCKED) \ + if (fwrt->uefi_tables_lock_status > UEFI_CNV_GUID_UNLOCKED) \ ret = iwl_uefi_get_ ## __name(__VA_ARGS__); \ if (ret < 0) \ ret = iwl_acpi_get_ ## __name(__VA_ARGS__); \ diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h index 22c97c75b83c..08fd11adf905 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h @@ -47,6 +47,19 @@ #define IWL_WTAS_CANADA_UHB_MSK BIT(15) #define IWL_WTAS_USA_UHB_MSK BIT(16) +/** + * enum iwl_uefi_cnv_guid_status - lock status of the connectivity + * UEFI tables + * @UEFI_CNV_GUID_UNLOCKED: the tables are unlocked + * @UEFI_CNV_GUID_LOCKED: the tables are locked + * @UEFI_CNV_GUID_TEST_MODE: the tables are locked in test mode + */ +enum iwl_uefi_cnv_guid_status { + UEFI_CNV_GUID_UNLOCKED = 0, + UEFI_CNV_GUID_LOCKED = 1, + UEFI_CNV_GUID_TEST_MODE = 2, +}; + struct iwl_tas_selection_data { u8 override_tas_iec:1, enable_tas_iec:1, diff --git a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h index ac01ac0092ee..12a1cf6b16f1 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h @@ -108,8 +108,8 @@ struct iwl_txf_iter_data { * @dump: debug dump data * @ap_type_cmd: AP type tables (for enablement on 6 GHz) * @ap_type_cmd_valid: if &ap_type_cmd is valid - * @uefi_tables_lock_status: The status of the WIFI GUID UEFI variables lock: - * 0: Unlocked, 1 and 2: Locked. + * @uefi_tables_lock_status: the status of the WIFI GUID UEFI variables lock, + * see &enum iwl_uefi_cnv_guid_status. * Only read the UEFI variables if locked. * @sar_profiles: sar profiles as read from WRDS/EWRD BIOS tables * @geo_profiles: geographic profiles as read from WGDS BIOS table diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 7c290b526383..7df0e5ea4a1d 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -20,6 +20,10 @@ 0x8d, 0x03, 0x77, 0x2e, \ 0xcc, 0x3d, 0xa5, 0x31) +#define IWL_EFI_GLUI_GUID EFI_GUID(0x6c5bed75, 0x0ee8, 0x4d45, \ + 0x98, 0x0b, 0x4d, 0x81, \ + 0x31, 0xba, 0x84, 0xb5) + struct iwl_uefi_pnvm_mem_desc { __le32 addr; __le32 size; @@ -1063,3 +1067,33 @@ int iwl_uefi_get_phy_filters(struct iwl_fw_runtime *fwrt) IWL_DEBUG_RADIO(fwrt, "Loaded WPFC config from UEFI\n"); return 0; } + +void iwl_uefi_get_guid_lock_status(struct iwl_fw_runtime *fwrt) +{ + struct uefi_cnv_var_glui *data __free(kfree) = + iwl_uefi_get_verified_variable_guid(fwrt->trans, + &IWL_EFI_GLUI_GUID, + IWL_UEFI_GLUI_NAME, "GLUI", + sizeof(*data), NULL); + + if (IS_ERR(data)) + return; + + if (data->revision != IWL_UEFI_GLUI_REVISION) { + IWL_DEBUG_RADIO(fwrt, "Unsupported UEFI GLUI revision:%d\n", + data->revision); + return; + } + + /* UEFI_CNV_GUID_TEST_MODE is the max value */ + if (data->guid_lock_status > UEFI_CNV_GUID_TEST_MODE) { + IWL_DEBUG_RADIO(fwrt, "Invalid UEFI GUID lock status:%d\n", + data->guid_lock_status); + return; + } + + fwrt->uefi_tables_lock_status = data->guid_lock_status; + + IWL_DEBUG_RADIO(fwrt, "Loaded UEFI WIFI GUID lock status: %d\n", + fwrt->uefi_tables_lock_status); +} diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.h b/drivers/net/wireless/intel/iwlwifi/fw/uefi.h index 386ca3744408..64fa1a78aacf 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.h @@ -13,6 +13,7 @@ #define IWL_UEFI_STEP_NAME L"UefiCnvCommonSTEP" #define IWL_UEFI_UATS_NAME L"CnvUefiWlanUATS" #define IWL_UEFI_WRDS_NAME L"UefiCnvWlanWRDS" +#define IWL_UEFI_GLUI_NAME L"UefiCnvCommonGLUI" #define IWL_UEFI_EWRD_NAME L"UefiCnvWlanEWRD" #define IWL_UEFI_WGDS_NAME L"UefiCnvWlanWGDS" #define IWL_UEFI_PPAG_NAME L"UefiCnvWlanPPAG" @@ -40,6 +41,7 @@ #define IWL_UEFI_DSM_REVISION 4 #define IWL_UEFI_PUNCTURING_REVISION 0 #define IWL_UEFI_DSBR_REVISION 1 +#define IWL_UEFI_GLUI_REVISION 0 struct pnvm_sku_package { u8 rev; @@ -54,6 +56,11 @@ struct uefi_cnv_wlan_sgom_data { u8 offset_map[IWL_SGOM_MAP_SIZE - 1]; } __packed; +struct uefi_cnv_var_glui { + u8 revision; + u8 guid_lock_status; +} __packed; + struct uefi_cnv_wlan_uats_data { u8 revision; u8 mcc_to_ap_type_map[IWL_UATS_MAP_SIZE - 1]; @@ -349,6 +356,7 @@ void iwl_uefi_get_uneb_table(struct iwl_trans *trans, int iwl_uefi_get_puncturing(struct iwl_fw_runtime *fwrt); int iwl_uefi_get_dsbr(struct iwl_fw_runtime *fwrt, u32 *value); int iwl_uefi_get_phy_filters(struct iwl_fw_runtime *fwrt); +void iwl_uefi_get_guid_lock_status(struct iwl_fw_runtime *fwrt); #else /* CONFIG_EFI */ static inline void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len) { @@ -466,5 +474,9 @@ static inline int iwl_uefi_get_phy_filters(struct iwl_fw_runtime *fwrt) { return -ENOENT; } + +static inline void iwl_uefi_get_guid_lock_status(struct iwl_fw_runtime *fwrt) +{ +} #endif /* CONFIG_EFI */ #endif /* __iwl_fw_uefi__ */ From d96966a8aa10028a97ff9db6aa078eec8dce5da0 Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Wed, 23 Sep 2026 16:04:54 +0300 Subject: [PATCH 1565/2126] wifi: iwlwifi: uefi: add a way to probe connectivity UEFI variables The connectivity UEFI variables are only trusted when the platform attests they are locked. When the lock status is unknown, the trust of each variable has to be discovered on its own by checking whether it is write protected. Probing depends on trying to rewrite UEFI variables and it is only attempted on non-x86 platforms. If the write is rejected the variable is considered locked and therefore trusted, otherwise it is treated as not trusted. Separate reading such a variable into two steps: iwl_uefi_get_variable_guid() only fetches and validates the variable, while iwl_uefi_get_verified_variable_guid() layers the trust decision on top of it. The latter now takes an iwl_fw_runtime so it can consult the lock status. Rename its WiFi-GUID wrapper from iwl_uefi_get_verified_variable() to iwl_uefi_get_verified_wifi_var(). With the trust check now performed by every iwl_uefi_get_*() reached through the GET_BIOS_TABLE() macro, the per-table lock-status gate in that macro is redundant, so drop it here. This move, and the new unknown-status handling, affect only the tables reached through GET_BIOS_TABLE(), i.e. those that have both a UEFI and an ACPI source. Assisted-by: GitHub-Copilot:claude-opus-4-8 Signed-off-by: Shahar Tzarfati Link: https://patch.msgid.link/20260923160318.6caa9ca17ffe.I877c0d6ab5126edb3e4f1f187ca1e20e563b2ec4@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/init.c | 4 +- .../wireless/intel/iwlwifi/fw/regulatory.c | 4 +- .../wireless/intel/iwlwifi/fw/regulatory.h | 3 + .../net/wireless/intel/iwlwifi/fw/runtime.h | 2 +- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 198 +++++++++++++----- 5 files changed, 148 insertions(+), 63 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/init.c b/drivers/net/wireless/intel/iwlwifi/fw/init.c index d1d8058ad29f..d69757b0149d 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/init.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/init.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* * Copyright (C) 2017 Intel Deutschland GmbH - * Copyright (C) 2019-2021, 2024-2025 Intel Corporation + * Copyright (C) 2019-2021, 2024-2026 Intel Corporation */ #include "iwl-drv.h" #include "runtime.h" @@ -31,6 +31,8 @@ void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans, fwrt->sanitize_ops = sanitize_ops; fwrt->sanitize_ctx = sanitize_ctx; fwrt->ops_ctx = ops_ctx; + /* default until the connectivity GUID lock status is resolved */ + fwrt->uefi_tables_lock_status = UEFI_CNV_GUID_UNKNOWN; for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++) { fwrt->dump.wks[i].idx = i; INIT_DELAYED_WORK(&fwrt->dump.wks[i].wk, iwl_fw_error_dump_wk); diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index 8dff97b8e0f1..c62f7f53323a 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -11,9 +11,7 @@ #define GET_BIOS_TABLE(__name, ...) \ do { \ - int ret = -ENOENT; \ - if (fwrt->uefi_tables_lock_status > UEFI_CNV_GUID_UNLOCKED) \ - ret = iwl_uefi_get_ ## __name(__VA_ARGS__); \ + int ret = iwl_uefi_get_ ## __name(__VA_ARGS__); \ if (ret < 0) \ ret = iwl_acpi_get_ ## __name(__VA_ARGS__); \ return ret; \ diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h index 08fd11adf905..cd6218e3a740 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h @@ -53,11 +53,14 @@ * @UEFI_CNV_GUID_UNLOCKED: the tables are unlocked * @UEFI_CNV_GUID_LOCKED: the tables are locked * @UEFI_CNV_GUID_TEST_MODE: the tables are locked in test mode + * @UEFI_CNV_GUID_UNKNOWN: the lock status could not be determined. + * This value is a driver internal, not a possible BIOS reported one */ enum iwl_uefi_cnv_guid_status { UEFI_CNV_GUID_UNLOCKED = 0, UEFI_CNV_GUID_LOCKED = 1, UEFI_CNV_GUID_TEST_MODE = 2, + UEFI_CNV_GUID_UNKNOWN = 3, }; struct iwl_tas_selection_data { diff --git a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h index 12a1cf6b16f1..d0709ab2f593 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h @@ -110,7 +110,7 @@ struct iwl_txf_iter_data { * @ap_type_cmd_valid: if &ap_type_cmd is valid * @uefi_tables_lock_status: the status of the WIFI GUID UEFI variables lock, * see &enum iwl_uefi_cnv_guid_status. - * Only read the UEFI variables if locked. + * Trust the UEFI variables if locked or in test mode. * @sar_profiles: sar profiles as read from WRDS/EWRD BIOS tables * @geo_profiles: geographic profiles as read from WGDS BIOS table * @geo_bios_source: see &enum bios_source diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 7df0e5ea4a1d..871d8f5db9c3 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -31,9 +31,10 @@ struct iwl_uefi_pnvm_mem_desc { } __packed; static void *iwl_uefi_get_variable(efi_char16_t *name, efi_guid_t *guid, - unsigned long *data_size) + u32 *attributes, unsigned long *data_size) { efi_status_t status; + u32 attr = 0; void *data; if (!data_size) @@ -52,15 +53,28 @@ static void *iwl_uefi_get_variable(efi_char16_t *name, efi_guid_t *guid, if (!data) return ERR_PTR(-ENOMEM); - status = efi.get_variable(name, guid, NULL, data_size, data); + status = efi.get_variable(name, guid, &attr, data_size, data); if (status != EFI_SUCCESS) { kfree(data); return ERR_PTR(-ENOENT); } + if (attributes) + *attributes = attr; + return data; } +static efi_status_t iwl_uefi_set_variable(efi_char16_t *name, efi_guid_t *guid, + u32 attributes, void *data, + unsigned long data_size) +{ + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) + return EFI_UNSUPPORTED; + + return efi.set_variable(name, guid, attributes, data_size, data); +} + void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len) { unsigned long package_size; @@ -69,7 +83,7 @@ void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len) *len = 0; data = iwl_uefi_get_variable(IWL_UEFI_OEM_PNVM_NAME, &IWL_EFI_WIFI_GUID, - &package_size); + NULL, &package_size); if (IS_ERR(data)) { IWL_DEBUG_FW(trans, "PNVM UEFI variable not found 0x%lx (len %lu)\n", @@ -84,17 +98,18 @@ void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len) } static void * -iwl_uefi_get_verified_variable_guid(struct iwl_trans *trans, - efi_guid_t *guid, - efi_char16_t *uefi_var_name, - char *var_name, - unsigned int expected_size, - unsigned long *size) +iwl_uefi_get_variable_guid(struct iwl_trans *trans, + efi_guid_t *guid, + efi_char16_t *uefi_var_name, + char *var_name, + unsigned int expected_size, + unsigned long *size, + u32 *attributes) { void *var; unsigned long var_size; - var = iwl_uefi_get_variable(uefi_var_name, guid, &var_size); + var = iwl_uefi_get_variable(uefi_var_name, guid, attributes, &var_size); if (IS_ERR(var)) { IWL_DEBUG_RADIO(trans, @@ -120,13 +135,72 @@ iwl_uefi_get_verified_variable_guid(struct iwl_trans *trans, } static void * -iwl_uefi_get_verified_variable(struct iwl_trans *trans, +iwl_uefi_get_verified_variable_guid(struct iwl_fw_runtime *fwrt, + efi_guid_t *guid, + efi_char16_t *uefi_var_name, + char *var_name, + unsigned int expected_size, + unsigned long *size) +{ + unsigned long var_size; + u32 attributes = 0; + void *var; + + if (fwrt->uefi_tables_lock_status == UEFI_CNV_GUID_UNLOCKED) + return ERR_PTR(-EINVAL); + + /* In x86 either GLUI or GLAI should exist */ + if ((IS_ENABLED(CONFIG_X86) || IS_ENABLED(CONFIG_X86_64) || + IS_ENABLED(CONFIG_X86_32)) && + fwrt->uefi_tables_lock_status == UEFI_CNV_GUID_UNKNOWN) + return ERR_PTR(-EINVAL); + + var = iwl_uefi_get_variable_guid(fwrt->trans, + guid, + uefi_var_name, var_name, + expected_size, &var_size, + &attributes); + if (IS_ERR(var)) + return var; + + if (fwrt->uefi_tables_lock_status != UEFI_CNV_GUID_UNKNOWN) + goto out; + + /* + * The lock status is unknown, so probe it: rewrite the variable + * with the data just read and trust it only if the firmware + * refuses the write. Treat a zero attributes value as untrusted, + * since a SetVariable() with no attributes would delete it. + */ + if (attributes) { + efi_status_t status; + + status = iwl_uefi_set_variable(uefi_var_name, guid, attributes, + var, var_size); + if (status == EFI_WRITE_PROTECTED || + status == EFI_SECURITY_VIOLATION || + status == EFI_ACCESS_DENIED) + goto out; + } + + /* unprobeable (e.g. EFI_UNSUPPORTED) or writable: not trusted */ + kfree(var); + return ERR_PTR(-EINVAL); + +out: + if (size) + *size = var_size; + return var; +} + +static void * +iwl_uefi_get_verified_wifi_var(struct iwl_fw_runtime *fwrt, efi_char16_t *uefi_var_name, char *var_name, unsigned int expected_size, unsigned long *size) { - return iwl_uefi_get_verified_variable_guid(trans, &IWL_EFI_WIFI_GUID, + return iwl_uefi_get_verified_variable_guid(fwrt, &IWL_EFI_WIFI_GUID, uefi_var_name, var_name, expected_size, size); } @@ -292,11 +366,12 @@ u8 *iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len) unsigned long package_size; u8 *data; - package = iwl_uefi_get_verified_variable(trans, - IWL_UEFI_REDUCED_POWER_NAME, - "Reduced Power", - sizeof(*package), - &package_size); + package = + iwl_uefi_get_variable_guid(trans, &IWL_EFI_WIFI_GUID, + IWL_UEFI_REDUCED_POWER_NAME, + "Reduced Power", + sizeof(*package), + &package_size, NULL); if (IS_ERR(package)) return ERR_CAST(package); @@ -338,9 +413,9 @@ void iwl_uefi_get_step_table(struct iwl_trans *trans) if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) return; - data = iwl_uefi_get_verified_variable_guid(trans, &IWL_EFI_WIFI_BT_GUID, - IWL_UEFI_STEP_NAME, - "STEP", sizeof(*data), NULL); + data = iwl_uefi_get_variable_guid(trans, &IWL_EFI_WIFI_BT_GUID, + IWL_UEFI_STEP_NAME, "STEP", + sizeof(*data), NULL, NULL); if (IS_ERR(data)) return; @@ -393,8 +468,9 @@ void iwl_uefi_get_sgom_table(struct iwl_trans *trans, if (!fwrt->geo_enabled) return; - data = iwl_uefi_get_verified_variable(trans, IWL_UEFI_SGOM_NAME, - "SGOM", sizeof(*data), NULL); + data = iwl_uefi_get_variable_guid(trans, &IWL_EFI_WIFI_GUID, + IWL_UEFI_SGOM_NAME, "SGOM", + sizeof(*data), NULL, NULL); if (IS_ERR(data)) return; @@ -427,8 +503,9 @@ void iwl_uefi_get_uats_table(struct iwl_trans *trans, struct uefi_cnv_wlan_uats_data *data; int ret; - data = iwl_uefi_get_verified_variable(trans, IWL_UEFI_UATS_NAME, - "UATS", sizeof(*data), NULL); + data = iwl_uefi_get_variable_guid(trans, &IWL_EFI_WIFI_GUID, + IWL_UEFI_UATS_NAME, "UATS", + sizeof(*data), NULL, NULL); if (IS_ERR(data)) return; @@ -444,8 +521,9 @@ void iwl_uefi_get_uneb_table(struct iwl_trans *trans, { struct uefi_cnv_wlan_uneb_data *data; - data = iwl_uefi_get_verified_variable(trans, IWL_UEFI_UNEB_NAME, - "UNEB", sizeof(*data), NULL); + data = iwl_uefi_get_variable_guid(trans, &IWL_EFI_WIFI_GUID, + IWL_UEFI_UNEB_NAME, "UNEB", + sizeof(*data), NULL, NULL); if (IS_ERR(data)) return; @@ -506,8 +584,8 @@ int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt) int num_subbands; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_WRDS_NAME, - "WRDS", + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WRDS_NAME, "WRDS", UEFI_SAR_WRDS_TABLE_SIZE_REV2, &size); @@ -555,8 +633,8 @@ int iwl_uefi_get_ewrd_table(struct iwl_fw_runtime *fwrt) int num_subbands; int profile_size; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_EWRD_NAME, - "EWRD", + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_EWRD_NAME, "EWRD", UEFI_SAR_EWRD_TABLE_SIZE_REV2, &size); if (IS_ERR(data)) @@ -609,9 +687,9 @@ int iwl_uefi_get_wgds_table(struct iwl_fw_runtime *fwrt) int n_subbands; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_WGDS_NAME, - "WGDS", UEFI_WGDS_TABLE_SIZE_REV3, - &size); + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WGDS_NAME, "WGDS", + UEFI_WGDS_TABLE_SIZE_REV3, &size); if (IS_ERR(data)) return -EINVAL; @@ -684,9 +762,9 @@ int iwl_uefi_get_ppag_table(struct iwl_fw_runtime *fwrt) u32 valid_rev; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_PPAG_NAME, - "PPAG", UEFI_PPAG_DATA_SIZE_V5, - NULL); + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_PPAG_NAME, "PPAG", + UEFI_PPAG_DATA_SIZE_V5, NULL); if (!IS_ERR(data)) { n_subbands = UEFI_PPAG_SUB_BANDS_NUM_REV5; valid_rev = BIT(5); @@ -694,7 +772,7 @@ int iwl_uefi_get_ppag_table(struct iwl_fw_runtime *fwrt) goto parse_table; } - data = iwl_uefi_get_verified_variable(fwrt->trans, + data = iwl_uefi_get_verified_wifi_var(fwrt, IWL_UEFI_PPAG_NAME, "PPAG", UEFI_PPAG_DATA_SIZE_V4, @@ -752,8 +830,9 @@ int iwl_uefi_get_tas_table(struct iwl_fw_runtime *fwrt, struct uefi_cnv_var_wtas *uefi_tas; int ret, enabled; - uefi_tas = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_WTAS_NAME, - "WTAS", sizeof(*uefi_tas), NULL); + uefi_tas = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WTAS_NAME, "WTAS", + sizeof(*uefi_tas), NULL); if (IS_ERR(uefi_tas)) return -EINVAL; @@ -805,7 +884,7 @@ int iwl_uefi_get_pwr_limit(struct iwl_fw_runtime *fwrt, struct uefi_cnv_var_splc *data; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_SPLC_NAME, + data = iwl_uefi_get_verified_wifi_var(fwrt, IWL_UEFI_SPLC_NAME, "SPLC", sizeof(*data), NULL); if (IS_ERR(data)) return -EINVAL; @@ -827,8 +906,9 @@ int iwl_uefi_get_mcc(struct iwl_fw_runtime *fwrt, char *mcc) struct uefi_cnv_var_wrdd *data; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_WRDD_NAME, - "WRDD", sizeof(*data), NULL); + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WRDD_NAME, "WRDD", + sizeof(*data), NULL); if (IS_ERR(data)) return -EINVAL; @@ -858,7 +938,7 @@ int iwl_uefi_get_eckv(struct iwl_fw_runtime *fwrt, u32 *extl_clk) struct uefi_cnv_var_eckv *data; int ret = 0; - data = iwl_uefi_get_verified_variable_guid(fwrt->trans, + data = iwl_uefi_get_verified_variable_guid(fwrt, &IWL_EFI_WIFI_BT_GUID, IWL_UEFI_ECKV_NAME, "ECKV", sizeof(*data), NULL); @@ -882,8 +962,9 @@ int iwl_uefi_get_wbem(struct iwl_fw_runtime *fwrt, u32 *value) struct uefi_cnv_wlan_wbem_data *data; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_WBEM_NAME, - "WBEM", sizeof(*data), NULL); + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WBEM_NAME, "WBEM", + sizeof(*data), NULL); if (IS_ERR(data)) return -EINVAL; @@ -909,7 +990,7 @@ static int iwl_uefi_load_dsm_values(struct iwl_fw_runtime *fwrt) BUILD_BUG_ON(ARRAY_SIZE(data->functions) < ARRAY_SIZE(fwrt->dsm_values)); - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_DSM_NAME, + data = iwl_uefi_get_verified_wifi_var(fwrt, IWL_UEFI_DSM_NAME, "DSM", sizeof(*data), NULL); if (IS_ERR(data)) return -EINVAL; @@ -990,10 +1071,10 @@ int iwl_uefi_get_puncturing(struct iwl_fw_runtime *fwrt) struct uefi_cnv_var_puncturing_data *data; int ret = 0; - data = iwl_uefi_get_verified_variable(fwrt->trans, - IWL_UEFI_PUNCTURING_NAME, - "UefiCnvWlanPuncturing", - sizeof(*data), NULL); + data = iwl_uefi_get_variable_guid(fwrt->trans, &IWL_EFI_WIFI_GUID, + IWL_UEFI_PUNCTURING_NAME, + "UefiCnvWlanPuncturing", + sizeof(*data), NULL, NULL); if (IS_ERR(data)) return -EINVAL; @@ -1019,7 +1100,7 @@ int iwl_uefi_get_dsbr(struct iwl_fw_runtime *fwrt, u32 *value) struct uefi_cnv_wlan_dsbr_data *data; int ret = 0; - data = iwl_uefi_get_verified_variable_guid(fwrt->trans, + data = iwl_uefi_get_verified_variable_guid(fwrt, &IWL_EFI_WIFI_BT_GUID, IWL_UEFI_DSBR_NAME, "DSBR", sizeof(*data), NULL); @@ -1045,8 +1126,9 @@ int iwl_uefi_get_phy_filters(struct iwl_fw_runtime *fwrt) struct uefi_cnv_wpfc_data *data __free(kfree); struct iwl_phy_specific_cfg *filters = &fwrt->phy_filters; - data = iwl_uefi_get_verified_variable(fwrt->trans, IWL_UEFI_WPFC_NAME, - "WPFC", sizeof(*data), NULL); + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WPFC_NAME, "WPFC", + sizeof(*data), NULL); if (IS_ERR(data)) return -EINVAL; @@ -1071,10 +1153,10 @@ int iwl_uefi_get_phy_filters(struct iwl_fw_runtime *fwrt) void iwl_uefi_get_guid_lock_status(struct iwl_fw_runtime *fwrt) { struct uefi_cnv_var_glui *data __free(kfree) = - iwl_uefi_get_verified_variable_guid(fwrt->trans, - &IWL_EFI_GLUI_GUID, - IWL_UEFI_GLUI_NAME, "GLUI", - sizeof(*data), NULL); + iwl_uefi_get_variable_guid(fwrt->trans, + &IWL_EFI_GLUI_GUID, + IWL_UEFI_GLUI_NAME, "GLUI", + sizeof(*data), NULL, NULL); if (IS_ERR(data)) return; @@ -1085,7 +1167,7 @@ void iwl_uefi_get_guid_lock_status(struct iwl_fw_runtime *fwrt) return; } - /* UEFI_CNV_GUID_TEST_MODE is the max value */ + /* UEFI_CNV_GUID_TEST_MODE is the max value the BIOS can report */ if (data->guid_lock_status > UEFI_CNV_GUID_TEST_MODE) { IWL_DEBUG_RADIO(fwrt, "Invalid UEFI GUID lock status:%d\n", data->guid_lock_status); From 7bec311676af0aa93f8999bec7eb2b35da35589f Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Wed, 23 Sep 2026 16:04:55 +0300 Subject: [PATCH 1566/2126] wifi: iwlwifi: regulatory: use GLUI as root-of-trust for connectivity variables The BIOS tables can be sourced from either UEFI or ACPI. The UEFI copies are writable, so they may be trusted only when the platform attests they are locked. Resolve this trust from a single source, preferring the UEFI GUID Lock Indicator (GLUI) and consulting the ACPI GLAI whenever GLUI does not attest the tables as locked or in test mode. Add iwl_bios_get_guid_lock_status() as that entry point and have the mvm and mld op-modes use it instead of the ACPI-only helper, so trust is resolved consistently regardless of whether a platform ships GLUI or GLAI. Signed-off-by: Shahar Tzarfati Assisted-by: GitHub-Copilot:claude-opus-4-8 Link: https://patch.msgid.link/20260923160318.c6a2252dafb9.I46f8c4d55bd22d98a7200cce8f528c5e182f443c@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/acpi.c | 1 - .../wireless/intel/iwlwifi/fw/regulatory.c | 24 +++++++++++++++++++ .../wireless/intel/iwlwifi/fw/regulatory.h | 1 + .../wireless/intel/iwlwifi/mld/regulatory.c | 3 +-- drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 2 +- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c index f53cb531cf88..21470b8ae8e9 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c @@ -1166,7 +1166,6 @@ void iwl_acpi_get_guid_lock_status(struct iwl_fw_runtime *fwrt) out_free: kfree(data); } -IWL_EXPORT_SYMBOL(iwl_acpi_get_guid_lock_status); int iwl_acpi_get_wbem(struct iwl_fw_runtime *fwrt, u32 *value) { diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index c62f7f53323a..5dbb3cdb9916 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -451,3 +451,27 @@ bool iwl_rfi_is_enabled_in_bios(struct iwl_fw_runtime *fwrt) return false; } IWL_EXPORT_SYMBOL(iwl_rfi_is_enabled_in_bios); + +/** + * iwl_bios_get_guid_lock_status - resolve connectivity variables lock status + * @fwrt: the firmware runtime context + * + * Determine the root-of-trust for the connectivity UEFI variables. The UEFI + * GUID Lock Indicator (GLUI) is preferred: if it attests the tables as locked + * or in test mode, that result is used. Otherwise (GLUI is missing, invalid or + * reports unlocked) the ACPI GUID Lock Indicator is consulted and can override + * the GLUI result. + * + * This only caches the result in &fwrt->uefi_tables_lock_status + * (see &enum iwl_uefi_cnv_guid_status). + */ +void iwl_bios_get_guid_lock_status(struct iwl_fw_runtime *fwrt) +{ + iwl_uefi_get_guid_lock_status(fwrt); + if (fwrt->uefi_tables_lock_status == UEFI_CNV_GUID_LOCKED || + fwrt->uefi_tables_lock_status == UEFI_CNV_GUID_TEST_MODE) + return; + + iwl_acpi_get_guid_lock_status(fwrt); +} +IWL_EXPORT_SYMBOL(iwl_bios_get_guid_lock_status); diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h index cd6218e3a740..f7bd09195ab4 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h @@ -258,6 +258,7 @@ bool iwl_puncturing_is_allowed_in_bios(u32 puncturing, u16 mcc); int iwl_bios_get_dsbr(struct iwl_fw_runtime *fwrt, u32 *value); int iwl_bios_get_phy_filters(struct iwl_fw_runtime *fwrt); +void iwl_bios_get_guid_lock_status(struct iwl_fw_runtime *fwrt); static inline void iwl_bios_setup_step(struct iwl_trans *trans, struct iwl_fw_runtime *fwrt) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c b/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c index 6db84c2117f2..9f395a1fd12a 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c @@ -6,7 +6,6 @@ #include #include "fw/regulatory.h" -#include "fw/acpi.h" #include "fw/uefi.h" #include "regulatory.h" @@ -37,7 +36,7 @@ void iwl_mld_get_bios_tables(struct iwl_mld *mld) { int ret; - iwl_acpi_get_guid_lock_status(&mld->fwrt); + iwl_bios_get_guid_lock_status(&mld->fwrt); ret = iwl_bios_get_ppag_table(&mld->fwrt); if (ret < 0) { diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c index 06f3b065914b..0b5b41223a8a 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c @@ -1576,7 +1576,7 @@ void iwl_mvm_get_bios_tables(struct iwl_mvm *mvm) { int ret; - iwl_acpi_get_guid_lock_status(&mvm->fwrt); + iwl_bios_get_guid_lock_status(&mvm->fwrt); /* read PPAG table */ ret = iwl_bios_get_ppag_table(&mvm->fwrt); From 80b4900412e06a7b28a196c850f522915aad5836 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 23 Sep 2026 16:04:56 +0300 Subject: [PATCH 1567/2126] wifi: iwlwifi: support for another device ID Add support of another flavor of AX231. Link: https://patch.msgid.link/20260923160318.af9e8f9c1548.I1fd3aa97da28065966952c36edcdb99acd5313cb@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c index a3e6c9e09a3b..a117c378b1f1 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c @@ -1018,6 +1018,7 @@ VISIBLE_IF_IWLWIFI_KUNIT const struct iwl_dev_info iwl_dev_info_table[] = { /* GF RF */ IWL_DEV_INFO(iwl_rf_gf, iwl_ax211_name, RF_TYPE(GF)), IWL_DEV_INFO(iwl_rf_ot, iwl_ax231_name, RF_TYPE(GF), SUBDEV(0x0294)), + IWL_DEV_INFO(iwl_rf_ot, iwl_ax231_name, RF_TYPE(GF), SUBDEV(0x4294)), IWL_DEV_INFO(iwl_rf_gf, iwl_ax411_name, RF_TYPE(GF), CDB), IWL_DEV_INFO(iwl_rf_gf, iwl_ax210_name, DEVICE(0x2725)), From 5c0c0c189bc74c599cb6ed4a7ad8651c75994ecc Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Wed, 23 Sep 2026 16:04:57 +0300 Subject: [PATCH 1568/2126] wifi: iwlwifi: mvm: validate BAID from FW The BAID from the ADD_STA response is used to access mvm->baid_map[] without an upper bound check. Check and reject an invalid value. Signed-off-by: Shahar Tzarfati Link: https://patch.msgid.link/20260923160318.22624c6dfa10.I9a99a140ab72cb1790a03a130ae7c8aa93cfac01@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/sta.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c index 2d0811be7346..a66128a62546 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2012-2015, 2018-2025 Intel Corporation + * Copyright (C) 2012-2015, 2018-2026 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2016-2017 Intel Deutschland GmbH */ @@ -2792,7 +2792,11 @@ static int iwl_mvm_fw_baid_op_sta(struct iwl_mvm *mvm, if (WARN_ON(start && iwl_mvm_has_new_rx_api(mvm) && !(status & IWL_ADD_STA_BAID_VALID_MASK))) return -EINVAL; - return u32_get_bits(status, IWL_ADD_STA_BAID_MASK); + ret = u32_get_bits(status, IWL_ADD_STA_BAID_MASK); + if (IWL_FW_CHECK(mvm, start && ret >= ARRAY_SIZE(mvm->baid_map), + "invalid BAID %d from FW\n", ret)) + return -EINVAL; + return ret; case ADD_STA_IMMEDIATE_BA_FAILURE: IWL_WARN(mvm, "RX BA Session refused by fw\n"); return -ENOSPC; From dc651c43a9d12e3e7cb4104fd62f07498ea6b332 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Wed, 23 Sep 2026 16:04:58 +0300 Subject: [PATCH 1569/2126] wifi: iwlwifi: add standalone WRSS/EWSS BIOS table loading Add support for reading WRSS and EWSS standalone SAR tables from the BIOS in the ACPI and UEFI paths. WRDS/EWRD tables describe SAR limits for concurrent Wi-Fi and Bluetooth operation. When Bluetooth is not active, those limits can unnecessarily restrict Wi-Fi transmit power. WRSS/EWSS provide separate standalone SAR profiles for Wi-Fi-only operation, allowing the firmware to select the appropriate higher-power limits while still respecting the platform-specific regulatory constraints. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260923160318.9a8eb3ff9512.Id79836e772136e1e38f107b578007faf39b13b4e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/acpi.c | 302 +++++++++++++----- drivers/net/wireless/intel/iwlwifi/fw/acpi.h | 16 + drivers/net/wireless/intel/iwlwifi/fw/init.c | 2 + .../wireless/intel/iwlwifi/fw/regulatory.c | 2 + .../wireless/intel/iwlwifi/fw/regulatory.h | 5 + .../net/wireless/intel/iwlwifi/fw/runtime.h | 7 + drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 133 +++++++- drivers/net/wireless/intel/iwlwifi/fw/uefi.h | 14 + 8 files changed, 392 insertions(+), 89 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c index 21470b8ae8e9..7b11316a3062 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/acpi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/acpi.c @@ -525,6 +525,83 @@ iwl_acpi_parse_chains_table(union acpi_object *table, return 0; } +static int +iwl_acpi_parse_extended_sar_profiles(union acpi_object *wifi_pkg, + struct iwl_sar_profile *sar_profiles, + u8 num_sub_bands, bool has_cdb) +{ + int n_profiles, pos, ret; + bool enabled; + + if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER || + wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) + return -EINVAL; + + if (WARN_ON(ACPI_SAR_NUM_CHAINS_REV0 * num_sub_bands > + ARRAY_SIZE(sar_profiles[0].chains) * + ARRAY_SIZE(sar_profiles[0].chains[0].subbands))) + return -EINVAL; + + enabled = !!(wifi_pkg->package.elements[1].integer.value); + n_profiles = wifi_pkg->package.elements[2].integer.value; + + if (n_profiles >= BIOS_SAR_MAX_PROFILE_NUM) + return -EINVAL; + + /* the tables start at element 3 */ + pos = 3; + + BUILD_BUG_ON(ACPI_SAR_NUM_CHAINS_REV0 != ACPI_SAR_NUM_CHAINS_REV1); + BUILD_BUG_ON(ACPI_SAR_NUM_CHAINS_REV2 != 2 * ACPI_SAR_NUM_CHAINS_REV0); + + /* parse non-cdb chains for all profiles */ + for (int i = 0; i < n_profiles; i++) { + union acpi_object *table = &wifi_pkg->package.elements[pos]; + + ret = iwl_acpi_parse_chains_table(table, + sar_profiles[i + 1].chains, + ACPI_SAR_NUM_CHAINS_REV0, + num_sub_bands); + if (ret < 0) + return ret; + + /* go to the next table */ + pos += ACPI_SAR_NUM_CHAINS_REV0 * num_sub_bands; + } + + if (!has_cdb) + goto set_enabled; + + if (WARN_ON(ACPI_SAR_NUM_CHAINS_REV0 * 2 * num_sub_bands > + ARRAY_SIZE(sar_profiles[0].chains) * + ARRAY_SIZE(sar_profiles[0].chains[0].subbands))) + return -EINVAL; + + /* parse cdb chains for all profiles */ + for (int i = 0; i < n_profiles; i++) { + struct iwl_sar_profile_chain *chains; + union acpi_object *table; + + table = &wifi_pkg->package.elements[pos]; + chains = &sar_profiles[i + 1].chains[ACPI_SAR_NUM_CHAINS_REV0]; + ret = iwl_acpi_parse_chains_table(table, + chains, + ACPI_SAR_NUM_CHAINS_REV0, + num_sub_bands); + if (ret < 0) + return ret; + + /* go to the next table */ + pos += ACPI_SAR_NUM_CHAINS_REV0 * num_sub_bands; + } + +set_enabled: + for (int i = 0; i < n_profiles; i++) + sar_profiles[i + 1].enabled = enabled; + + return 0; +} + int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt) { union acpi_object *wifi_pkg, *table, *data; @@ -629,8 +706,12 @@ read_table: */ ret = iwl_acpi_parse_chains_table(table, fwrt->sar_profiles[0].chains, num_chains, num_sub_bands); - if (!ret && flags & IWL_SAR_ENABLE_MSK) + if (ret) + goto out_free; + + if (flags & IWL_SAR_ENABLE_MSK) fwrt->sar_profiles[0].enabled = true; + fwrt->wrds_table_revision = tbl_rev; out_free: kfree(data); @@ -640,8 +721,7 @@ out_free: int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt) { union acpi_object *wifi_pkg, *data; - bool enabled; - int i, n_profiles, tbl_rev, pos; + int tbl_rev; int ret = 0; u8 num_sub_bands; @@ -713,95 +793,149 @@ int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt) goto out_free; read_table: - if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER || - wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) { - ret = -EINVAL; + ret = iwl_acpi_parse_extended_sar_profiles(wifi_pkg, + fwrt->sar_profiles, + num_sub_bands, + tbl_rev >= 2); + if (ret) goto out_free; - } - if (WARN_ON(ACPI_SAR_NUM_CHAINS_REV0 * num_sub_bands > - ARRAY_SIZE(fwrt->sar_profiles[0].chains) * - ARRAY_SIZE(fwrt->sar_profiles[0].chains[0].subbands))) { - ret = -EINVAL; - goto out_free; - } - - enabled = !!(wifi_pkg->package.elements[1].integer.value); - n_profiles = wifi_pkg->package.elements[2].integer.value; - - /* - * Check the validity of n_profiles. The EWRD profiles start - * from index 1, so the maximum value allowed here is - * ACPI_SAR_PROFILES_NUM - 1. - */ - if (n_profiles >= BIOS_SAR_MAX_PROFILE_NUM) { - ret = -EINVAL; - goto out_free; - } - - /* the tables start at element 3 */ - pos = 3; - - BUILD_BUG_ON(ACPI_SAR_NUM_CHAINS_REV0 != ACPI_SAR_NUM_CHAINS_REV1); - BUILD_BUG_ON(ACPI_SAR_NUM_CHAINS_REV2 != 2 * ACPI_SAR_NUM_CHAINS_REV0); - - /* parse non-cdb chains for all profiles */ - for (i = 0; i < n_profiles; i++) { - union acpi_object *table = &wifi_pkg->package.elements[pos]; - - /* The EWRD profiles officially go from 2 to 4, but we - * save them in sar_profiles[1-3] (because we don't - * have profile 0). So in the array we start from 1. - */ - ret = iwl_acpi_parse_chains_table(table, - fwrt->sar_profiles[i + 1].chains, - ACPI_SAR_NUM_CHAINS_REV0, - num_sub_bands); - if (ret < 0) - goto out_free; - - /* go to the next table */ - pos += ACPI_SAR_NUM_CHAINS_REV0 * num_sub_bands; - } - - /* non-cdb table revisions */ - if (tbl_rev < 2) - goto set_enabled; - - if (WARN_ON(ACPI_SAR_NUM_CHAINS_REV0 * 2 * num_sub_bands > - ARRAY_SIZE(fwrt->sar_profiles[0].chains) * - ARRAY_SIZE(fwrt->sar_profiles[0].chains[0].subbands))) { - ret = -EINVAL; - goto out_free; - } - - /* parse cdb chains for all profiles */ - for (i = 0; i < n_profiles; i++) { - struct iwl_sar_profile_chain *chains; - union acpi_object *table; - - table = &wifi_pkg->package.elements[pos]; - chains = &fwrt->sar_profiles[i + 1].chains[ACPI_SAR_NUM_CHAINS_REV0]; - ret = iwl_acpi_parse_chains_table(table, - chains, - ACPI_SAR_NUM_CHAINS_REV0, - num_sub_bands); - if (ret < 0) - goto out_free; - - /* go to the next table */ - pos += ACPI_SAR_NUM_CHAINS_REV0 * num_sub_bands; - } - -set_enabled: - for (i = 0; i < n_profiles; i++) - fwrt->sar_profiles[i + 1].enabled = enabled; + fwrt->ewrd_table_revision = tbl_rev; out_free: kfree(data); return ret; } +int iwl_acpi_get_wsss_table(struct iwl_fw_runtime *fwrt) +{ + union acpi_object *data __free(kfree) = NULL; + union acpi_object *wifi_pkg, *table; + u8 num_chains, num_sub_bands; + int ret, tbl_rev; + u32 flags; + + if (fwrt->wrds_table_revision == IWL_BIOS_REVISION_UNSET) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: WRDS table was not read\n"); + return -EINVAL; + } + + data = iwl_acpi_get_object(fwrt->dev, ACPI_WSSS_METHOD); + if (IS_ERR(data)) + return PTR_ERR(data); + + switch (fwrt->wrds_table_revision) { + case 3: + wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data, + ACPI_WRDS_WIFI_DATA_SIZE_REV3, + &tbl_rev); + num_chains = ACPI_SAR_NUM_CHAINS_REV2; + num_sub_bands = ACPI_SAR_NUM_SUB_BANDS_REV3; + break; + case 2: + wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data, + ACPI_WRDS_WIFI_DATA_SIZE_REV2, + &tbl_rev); + num_chains = ACPI_SAR_NUM_CHAINS_REV2; + num_sub_bands = ACPI_SAR_NUM_SUB_BANDS_REV2; + break; + default: + return -EINVAL; + } + + if (IS_ERR(wifi_pkg)) + return PTR_ERR(wifi_pkg); + + if (fwrt->wrds_table_revision != tbl_rev) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: WRDS/WSSS revision mismatch (WRDS rev %d, WSSS rev %d)\n", + fwrt->wrds_table_revision, + tbl_rev); + return -EINVAL; + } + + if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) + return -EINVAL; + + if (WARN_ON(num_chains * num_sub_bands > + ARRAY_SIZE(fwrt->sar_standalone_profiles[0].chains) * + ARRAY_SIZE(fwrt->sar_standalone_profiles[0].chains[0].subbands))) + return -EINVAL; + + IWL_DEBUG_RADIO(fwrt, "Reading WSSS (WRDS Standalone) tbl_rev=%d\n", + tbl_rev); + + flags = wifi_pkg->package.elements[1].integer.value; + + /* position of the actual table */ + table = &wifi_pkg->package.elements[2]; + + ret = iwl_acpi_parse_chains_table(table, + fwrt->sar_standalone_profiles[0].chains, + num_chains, num_sub_bands); + if (ret) + return ret; + + if (flags & IWL_SAR_ENABLE_MSK) + fwrt->sar_standalone_profiles[0].enabled = true; + + return ret; +} + +int iwl_acpi_get_ewss_table(struct iwl_fw_runtime *fwrt) +{ + union acpi_object *data __free(kfree) = NULL; + union acpi_object *wifi_pkg; + u8 num_sub_bands; + int tbl_rev; + + if (fwrt->ewrd_table_revision == IWL_BIOS_REVISION_UNSET) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: EWRD table was not read\n"); + return -EINVAL; + } + + data = iwl_acpi_get_object(fwrt->dev, ACPI_EWSS_METHOD); + if (IS_ERR(data)) + return PTR_ERR(data); + + switch (fwrt->ewrd_table_revision) { + case 3: + wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data, + ACPI_EWRD_WIFI_DATA_SIZE_REV3, + &tbl_rev); + num_sub_bands = ACPI_SAR_NUM_SUB_BANDS_REV3; + break; + case 2: + wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data, + ACPI_EWRD_WIFI_DATA_SIZE_REV2, + &tbl_rev); + num_sub_bands = ACPI_SAR_NUM_SUB_BANDS_REV2; + break; + default: + return -EINVAL; + } + + if (IS_ERR(wifi_pkg)) + return PTR_ERR(wifi_pkg); + + if (fwrt->ewrd_table_revision != tbl_rev) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: EWRD/EWSS revision mismatch (EWRD rev %d, EWSS rev %d)\n", + fwrt->ewrd_table_revision, tbl_rev); + return -EINVAL; + } + + IWL_DEBUG_RADIO(fwrt, "Reading EWSS (EWRD Standalone) tbl_rev=%d\n", + tbl_rev); + + return iwl_acpi_parse_extended_sar_profiles(wifi_pkg, + fwrt->sar_standalone_profiles, + num_sub_bands, + fwrt->ewrd_table_revision >= 2); +} + int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt) { union acpi_object *wifi_pkg, *data; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/acpi.h b/drivers/net/wireless/intel/iwlwifi/fw/acpi.h index 426b0c51abec..b722beae2f00 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/acpi.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/acpi.h @@ -14,6 +14,8 @@ #define ACPI_WRDS_METHOD "WRDS" #define ACPI_EWRD_METHOD "EWRD" +#define ACPI_WSSS_METHOD "WSSS" +#define ACPI_EWSS_METHOD "EWSS" #define ACPI_WGDS_METHOD "WGDS" #define ACPI_WRDD_METHOD "WRDD" #define ACPI_SPLC_METHOD "SPLC" @@ -175,6 +177,10 @@ int iwl_acpi_get_wrds_table(struct iwl_fw_runtime *fwrt); int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt); +int iwl_acpi_get_wsss_table(struct iwl_fw_runtime *fwrt); + +int iwl_acpi_get_ewss_table(struct iwl_fw_runtime *fwrt); + int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt); int iwl_acpi_get_tas_table(struct iwl_fw_runtime *fwrt, @@ -229,6 +235,16 @@ static inline int iwl_acpi_get_ewrd_table(struct iwl_fw_runtime *fwrt) return -ENOENT; } +static inline int iwl_acpi_get_wsss_table(struct iwl_fw_runtime *fwrt) +{ + return -ENOENT; +} + +static inline int iwl_acpi_get_ewss_table(struct iwl_fw_runtime *fwrt) +{ + return -ENOENT; +} + static inline int iwl_acpi_get_wgds_table(struct iwl_fw_runtime *fwrt) { return 1; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/init.c b/drivers/net/wireless/intel/iwlwifi/fw/init.c index d69757b0149d..f62c6a69f0dc 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/init.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/init.c @@ -23,6 +23,8 @@ void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans, int i; memset(fwrt, 0, sizeof(*fwrt)); + fwrt->wrds_table_revision = IWL_BIOS_REVISION_UNSET; + fwrt->ewrd_table_revision = IWL_BIOS_REVISION_UNSET; fwrt->trans = trans; fwrt->fw = fw; fwrt->dev = trans->dev; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index 5dbb3cdb9916..137303e4a29b 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -30,6 +30,8 @@ IWL_EXPORT_SYMBOL(iwl_bios_get_ ## __name) IWL_BIOS_TABLE_LOADER(wrds_table); IWL_BIOS_TABLE_LOADER(ewrd_table); +IWL_BIOS_TABLE_LOADER(wsss_table); +IWL_BIOS_TABLE_LOADER(ewss_table); IWL_BIOS_TABLE_LOADER(wgds_table); IWL_BIOS_TABLE_LOADER(ppag_table); IWL_BIOS_TABLE_LOADER(phy_filters); diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h index f7bd09195ab4..bd7ea0ff3d19 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h @@ -31,6 +31,7 @@ #define IWL_SAR_ENABLE_MSK BIT(0) #define IWL_REDUCE_POWER_FLAGS_POS 1 +#define IWL_BIOS_REVISION_UNSET 0xFF /* PPAG gain value bounds in 1/8 dBm */ #define IWL_PPAG_MIN_LB -16 @@ -223,6 +224,10 @@ int iwl_bios_get_wrds_table(struct iwl_fw_runtime *fwrt); int iwl_bios_get_ewrd_table(struct iwl_fw_runtime *fwrt); +int iwl_bios_get_wsss_table(struct iwl_fw_runtime *fwrt); + +int iwl_bios_get_ewss_table(struct iwl_fw_runtime *fwrt); + int iwl_bios_get_wgds_table(struct iwl_fw_runtime *fwrt); int iwl_bios_get_ppag_table(struct iwl_fw_runtime *fwrt); diff --git a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h index d0709ab2f593..33ce06f1a60a 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h @@ -112,6 +112,10 @@ struct iwl_txf_iter_data { * see &enum iwl_uefi_cnv_guid_status. * Trust the UEFI variables if locked or in test mode. * @sar_profiles: sar profiles as read from WRDS/EWRD BIOS tables + * @sar_standalone_profiles: standalone sar profiles as read from + * WSSS/EWSS BIOS tables (for Wi-Fi HB/UHB without concurrent BT) + * @wrds_table_revision: revision of WRDS BIOS table + * @ewrd_table_revision: revision of EWRD BIOS table * @geo_profiles: geographic profiles as read from WGDS BIOS table * @geo_bios_source: see &enum bios_source * @phy_filters: specific phy filters as read from WPFC BIOS table @@ -206,6 +210,9 @@ struct iwl_fw_runtime { bool tpc_enabled; #endif /* CONFIG_IWLWIFI_DEBUGFS */ struct iwl_sar_profile sar_profiles[BIOS_SAR_MAX_PROFILE_NUM]; + struct iwl_sar_profile sar_standalone_profiles[BIOS_SAR_MAX_PROFILE_NUM]; + u8 wrds_table_revision; + u8 ewrd_table_revision; u8 sar_chain_a_profile; u8 sar_chain_b_profile; u8 reduced_power_flags; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 871d8f5db9c3..79fd95d08732 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -547,11 +547,11 @@ out: } IWL_EXPORT_SYMBOL(iwl_uefi_get_uneb_table); -static void iwl_uefi_set_sar_profile(struct iwl_fw_runtime *fwrt, +static void iwl_uefi_set_sar_profile(struct iwl_sar_profile *profiles, const u8 *vals, u8 prof_index, u8 num_subbands, bool enabled) { - struct iwl_sar_profile *sar_prof = &fwrt->sar_profiles[prof_index]; + struct iwl_sar_profile *sar_prof = &profiles[prof_index]; /* * Make sure fwrt has enough room to hold the data @@ -573,7 +573,7 @@ static void iwl_uefi_set_sar_profile(struct iwl_fw_runtime *fwrt, vals[chain * num_subbands + subband]; } - fwrt->sar_profiles[prof_index].enabled = enabled & IWL_SAR_ENABLE_MSK; + sar_prof->enabled = enabled & IWL_SAR_ENABLE_MSK; } int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt) @@ -617,8 +617,9 @@ int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt) /* The profile from WRDS is officially profile 1, but goes * into sar_profiles[0] (because we don't have a profile 0). */ - iwl_uefi_set_sar_profile(fwrt, data->vals, 0, + iwl_uefi_set_sar_profile(fwrt->sar_profiles, data->vals, 0, num_subbands, data->mode); + fwrt->wrds_table_revision = data->revision; out: kfree(data); return ret; @@ -670,14 +671,136 @@ int iwl_uefi_get_ewrd_table(struct iwl_fw_runtime *fwrt) * save them in sar_profiles[1-3] (because we don't * have profile 0). So in the array we start from 1. */ - iwl_uefi_set_sar_profile(fwrt, &data->vals[i * profile_size], + iwl_uefi_set_sar_profile(fwrt->sar_profiles, + &data->vals[i * profile_size], i + 1, num_subbands, data->mode); + fwrt->ewrd_table_revision = data->revision; + out: kfree(data); return ret; } +int iwl_uefi_get_wsss_table(struct iwl_fw_runtime *fwrt) +{ + struct uefi_cnv_var_wrds *data __free(kfree) = NULL; + unsigned long expected_size; + unsigned long size; + int num_subbands; + + if (fwrt->wrds_table_revision == IWL_BIOS_REVISION_UNSET) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: WRDS table was not read\n"); + return -EINVAL; + } + + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_WSSS_NAME, + "WSSS", + UEFI_SAR_WRDS_TABLE_SIZE_REV2, + &size); + if (IS_ERR(data)) + return PTR_ERR(data); + + switch (data->revision) { + case 2: + expected_size = UEFI_SAR_WRDS_TABLE_SIZE_REV2; + num_subbands = UEFI_SAR_SUB_BANDS_NUM_REV2; + break; + case 3: + expected_size = UEFI_SAR_WRDS_TABLE_SIZE_REV3; + num_subbands = UEFI_SAR_SUB_BANDS_NUM_REV3; + break; + default: + IWL_DEBUG_RADIO(fwrt, + "Unsupported UEFI WSSS revision:%d\n", + data->revision); + return -EINVAL; + } + + if (size != expected_size) + return -EINVAL; + + if (fwrt->wrds_table_revision != data->revision) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: WRDS/WSSS revision mismatch (WRDS rev %d, WSSS rev %d)\n", + fwrt->wrds_table_revision, + data->revision); + return -EINVAL; + } + + IWL_DEBUG_RADIO(fwrt, "Reading WSSS (WRDS Standalone) tbl_rev=%d\n", + data->revision); + iwl_uefi_set_sar_profile(fwrt->sar_standalone_profiles, + data->vals, 0, + num_subbands, + data->mode); + return 0; +} + +int iwl_uefi_get_ewss_table(struct iwl_fw_runtime *fwrt) +{ + struct uefi_cnv_var_ewrd *data __free(kfree) = NULL; + unsigned long expected_size; + unsigned long size; + int num_subbands; + int profile_size; + int i; + + if (fwrt->ewrd_table_revision == IWL_BIOS_REVISION_UNSET) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: EWRD table was not read\n"); + return -EINVAL; + } + + data = iwl_uefi_get_verified_wifi_var(fwrt, + IWL_UEFI_EWSS_NAME, + "EWSS", + UEFI_SAR_EWRD_TABLE_SIZE_REV2, + &size); + if (IS_ERR(data)) + return PTR_ERR(data); + + switch (data->revision) { + case 3: + expected_size = UEFI_SAR_EWRD_TABLE_SIZE_REV3; + num_subbands = UEFI_SAR_SUB_BANDS_NUM_REV3; + profile_size = UEFI_SAR_PROFILE_SIZE_REV3; + break; + case 2: + expected_size = UEFI_SAR_EWRD_TABLE_SIZE_REV2; + num_subbands = UEFI_SAR_SUB_BANDS_NUM_REV2; + profile_size = UEFI_SAR_PROFILE_SIZE_REV2; + break; + default: + IWL_DEBUG_RADIO(fwrt, + "Unsupported UEFI EWSS revision:%d\n", + data->revision); + return -EINVAL; + } + + if (size != expected_size || + data->num_profiles >= BIOS_SAR_MAX_PROFILE_NUM) + return -EINVAL; + + if (fwrt->ewrd_table_revision != data->revision) { + IWL_DEBUG_RADIO(fwrt, + "Skipping standalone SAR: EWRD/EWSS revision mismatch (EWRD rev %d, EWSS rev %d)\n", + fwrt->ewrd_table_revision, + data->revision); + return -EINVAL; + } + + for (i = 0; i < data->num_profiles; i++) + iwl_uefi_set_sar_profile(fwrt->sar_standalone_profiles, + &data->vals[i * profile_size], + i + 1, num_subbands, + data->mode); + + return 0; +} + int iwl_uefi_get_wgds_table(struct iwl_fw_runtime *fwrt) { struct uefi_cnv_var_wgds *data; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.h b/drivers/net/wireless/intel/iwlwifi/fw/uefi.h index 64fa1a78aacf..f4f7a447e528 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.h @@ -15,6 +15,8 @@ #define IWL_UEFI_WRDS_NAME L"UefiCnvWlanWRDS" #define IWL_UEFI_GLUI_NAME L"UefiCnvCommonGLUI" #define IWL_UEFI_EWRD_NAME L"UefiCnvWlanEWRD" +#define IWL_UEFI_WSSS_NAME L"UefiCnvWlanWSSS" +#define IWL_UEFI_EWSS_NAME L"UefiCnvWlanEWSS" #define IWL_UEFI_WGDS_NAME L"UefiCnvWlanWGDS" #define IWL_UEFI_PPAG_NAME L"UefiCnvWlanPPAG" #define IWL_UEFI_WTAS_NAME L"UefiCnvWlanWTAS" @@ -337,6 +339,8 @@ int iwl_uefi_handle_tlv_mem_desc(struct iwl_trans *trans, const u8 *data, u32 tlv_len, struct iwl_pnvm_image *pnvm_data); int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt); int iwl_uefi_get_ewrd_table(struct iwl_fw_runtime *fwrt); +int iwl_uefi_get_wsss_table(struct iwl_fw_runtime *fwrt); +int iwl_uefi_get_ewss_table(struct iwl_fw_runtime *fwrt); int iwl_uefi_get_wgds_table(struct iwl_fw_runtime *fwrt); int iwl_uefi_get_ppag_table(struct iwl_fw_runtime *fwrt); int iwl_uefi_get_tas_table(struct iwl_fw_runtime *fwrt, @@ -399,6 +403,16 @@ static inline int iwl_uefi_get_ewrd_table(struct iwl_fw_runtime *fwrt) return -ENOENT; } +static inline int iwl_uefi_get_wsss_table(struct iwl_fw_runtime *fwrt) +{ + return -ENOENT; +} + +static inline int iwl_uefi_get_ewss_table(struct iwl_fw_runtime *fwrt) +{ + return -ENOENT; +} + static inline int iwl_uefi_get_wgds_table(struct iwl_fw_runtime *fwrt) { return -ENOENT; From 915b6e9ffb0586d389b47821ce6deeab9ea5ec83 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:20 +0300 Subject: [PATCH 1570/2126] wifi: iwlwifi: pcie: drop gen1_2 prefix from several functions As a preparation of a future pcie-transport, we added a gen1_2 prefix to some functions to distinguish them from the new implementation. Since the new pcie-transport will not happen eventaully, remove this prefix from those functions. Link: https://patch.msgid.link/20260926201527.dc1a22771b0e.I20e77f228e1536c6eb327dc077b030dbea889ac2@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/iwl-trans.c | 10 +++++----- drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 2 +- .../intel/iwlwifi/pcie/gen1_2/internal.h | 19 +++++++++---------- .../intel/iwlwifi/pcie/gen1_2/trans.c | 11 +++++------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index a1545e9d2cd8..8cc8f6c4e934 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -333,14 +333,14 @@ IWL_EXPORT_SYMBOL(iwl_trans_send_cmd); struct iwl_device_tx_cmd *iwl_trans_alloc_tx_cmd(struct iwl_trans *trans) { - return iwl_pcie_gen1_2_alloc_tx_cmd(trans); + return iwl_pcie_alloc_tx_cmd(trans); } IWL_EXPORT_SYMBOL(iwl_trans_alloc_tx_cmd); void iwl_trans_free_tx_cmd(struct iwl_trans *trans, struct iwl_device_tx_cmd *dev_cmd) { - iwl_pcie_gen1_2_free_tx_cmd(trans, dev_cmd); + iwl_pcie_free_tx_cmd(trans, dev_cmd); } IWL_EXPORT_SYMBOL(iwl_trans_free_tx_cmd); @@ -395,7 +395,7 @@ void iwl_trans_op_mode_enter(struct iwl_trans *trans, WARN_ON_ONCE(!trans->conf.rx_mpdu_cmd); - iwl_pcie_gen1_2_op_mode_enter(trans); + iwl_trans_pcie_op_mode_enter(trans); } IWL_EXPORT_SYMBOL(iwl_trans_op_mode_enter); @@ -821,13 +821,13 @@ IWL_EXPORT_SYMBOL(iwl_trans_is_pm_supported); bool iwl_trans_is_ltr_enabled(struct iwl_trans *trans) { - return iwl_pcie_gen1_2_is_ltr_enabled(trans); + return iwl_pcie_is_ltr_enabled(trans); } IWL_EXPORT_SYMBOL(iwl_trans_is_ltr_enabled); int iwl_trans_activate_nic(struct iwl_trans *trans) { - return iwl_pcie_gen1_2_activate_nic(trans); + return iwl_pcie_activate_nic(trans); } IWL_EXPORT_SYMBOL(iwl_trans_activate_nic); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c index a117c378b1f1..04a4fa8ddb79 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c @@ -1188,7 +1188,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return -EIO; } - return iwl_pci_gen1_2_probe(pdev, ent, mac_cfg, hw_base, hw_rev); + return _iwl_pci_probe(pdev, ent, mac_cfg, hw_base, hw_rev); } static void iwl_pci_remove(struct pci_dev *pdev) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h index f0e70b0fedfe..ee3825954f65 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h @@ -850,7 +850,7 @@ static inline u16 iwl_txq_gen1_tfd_tb_get_len(struct iwl_trans *trans, } static inline struct iwl_device_tx_cmd * -iwl_pcie_gen1_2_alloc_tx_cmd(struct iwl_trans *trans) +iwl_pcie_alloc_tx_cmd(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); @@ -858,8 +858,8 @@ iwl_pcie_gen1_2_alloc_tx_cmd(struct iwl_trans *trans) } static inline void -iwl_pcie_gen1_2_free_tx_cmd(struct iwl_trans *trans, - struct iwl_device_tx_cmd *dev_cmd) +iwl_pcie_free_tx_cmd(struct iwl_trans *trans, + struct iwl_device_tx_cmd *dev_cmd) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); @@ -1132,7 +1132,7 @@ static inline void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans) { } void iwl_pcie_rx_allocator_work(struct work_struct *data); /* common trans ops for all generations transports */ -void iwl_pcie_gen1_2_op_mode_enter(struct iwl_trans *trans); +void iwl_trans_pcie_op_mode_enter(struct iwl_trans *trans); int _iwl_trans_pcie_start_hw(struct iwl_trans *trans); int iwl_trans_pcie_start_hw(struct iwl_trans *trans); void iwl_trans_pcie_op_mode_leave(struct iwl_trans *trans); @@ -1164,10 +1164,9 @@ void iwl_trans_pcie_resched_with_nic_access(struct iwl_trans *trans); void __releases(nic_access_nobh) iwl_trans_pcie_release_nic_access(struct iwl_trans *trans); void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans, u8 max_power); -int iwl_pci_gen1_2_probe(struct pci_dev *pdev, - const struct pci_device_id *ent, - const struct iwl_mac_cfg *mac_cfg, - u8 __iomem *hw_base, u32 hw_rev); +int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, + const struct iwl_mac_cfg *mac_cfg, + u8 __iomem *hw_base, u32 hw_rev); void iwl_pcie_gen1_2_remove(struct iwl_trans *trans); /* transport gen 1 exported functions */ @@ -1193,7 +1192,7 @@ int iwl_pcie_alloc_dma_ptr(struct iwl_trans *trans, struct iwl_dma_ptr *ptr, size_t size); void iwl_pcie_free_dma_ptr(struct iwl_trans *trans, struct iwl_dma_ptr *ptr); void iwl_pcie_apply_destination(struct iwl_trans *trans); -int iwl_pcie_gen1_2_activate_nic(struct iwl_trans *trans); +int iwl_pcie_activate_nic(struct iwl_trans *trans); /* transport gen 2 exported functions */ int iwl_trans_pcie_gen2_start_fw(struct iwl_trans *trans, @@ -1223,7 +1222,7 @@ static inline bool iwl_pcie_gen1_is_pm_supported(struct iwl_trans *trans) return trans_pcie->pm_support; } -static inline bool iwl_pcie_gen1_2_is_ltr_enabled(struct iwl_trans *trans) +static inline bool iwl_pcie_is_ltr_enabled(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c index 71c4746c61a6..0b46431ce68f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c @@ -1903,7 +1903,7 @@ void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr, u32 val) iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WDAT, val); } -void iwl_pcie_gen1_2_op_mode_enter(struct iwl_trans *trans) +void iwl_trans_pcie_op_mode_enter(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); @@ -4076,10 +4076,9 @@ static void iwl_pcie_check_me_status(struct iwl_trans *trans) schedule_delayed_work(&trans_pcie->me_recheck_wk, HZ); } -int iwl_pci_gen1_2_probe(struct pci_dev *pdev, - const struct pci_device_id *ent, - const struct iwl_mac_cfg *mac_cfg, - u8 __iomem *hw_base, u32 hw_rev) +int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, + const struct iwl_mac_cfg *mac_cfg, + u8 __iomem *hw_base, u32 hw_rev) { const struct iwl_dev_info *dev_info; struct iwl_trans_info info = { @@ -4240,7 +4239,7 @@ void iwl_pcie_gen1_2_remove(struct iwl_trans *trans) iwl_trans_pcie_free(trans); } -int iwl_pcie_gen1_2_activate_nic(struct iwl_trans *trans) +int iwl_pcie_activate_nic(struct iwl_trans *trans) { const struct iwl_mac_cfg *mac_cfg = trans->mac_cfg; u32 poll_ready; From ac7f248012abc87b000d236a240df3431932daa1 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:21 +0300 Subject: [PATCH 1571/2126] wifi: iwlwifi: Revert "wifi: iwlwifi: gen1_2: move gen specific code to a function" This reverts commit df70a9a86eee ("wifi: iwlwifi: gen1_2: move gen specific code to a function"). The remove flow body was factored out into into a new function to prepare for a new pcie-transport, which will not happen eventually. Inline the code back. Link: https://patch.msgid.link/20260926201527.44edf3234ede.Ic19d96486253518e2107d91e512654596689a426@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 7 ++++++- .../net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h | 1 - .../net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c | 11 ----------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c index 04a4fa8ddb79..4fa514ba9975 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c @@ -1194,11 +1194,16 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static void iwl_pci_remove(struct pci_dev *pdev) { struct iwl_trans *trans = pci_get_drvdata(pdev); + struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); if (!trans) return; - iwl_pcie_gen1_2_remove(trans); + cancel_delayed_work_sync(&trans_pcie->me_recheck_wk); + + iwl_drv_stop(trans->drv); + + iwl_trans_pcie_free(trans); } #ifdef CONFIG_PM_SLEEP diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h index ee3825954f65..cff02afa4e26 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h @@ -1167,7 +1167,6 @@ void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans, u8 max_power); int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, const struct iwl_mac_cfg *mac_cfg, u8 __iomem *hw_base, u32 hw_rev); -void iwl_pcie_gen1_2_remove(struct iwl_trans *trans); /* transport gen 1 exported functions */ void iwl_trans_pcie_fw_alive(struct iwl_trans *trans); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c index 0b46431ce68f..db92c5c954e6 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c @@ -4228,17 +4228,6 @@ out_free_trans: return ret; } -void iwl_pcie_gen1_2_remove(struct iwl_trans *trans) -{ - struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - - cancel_delayed_work_sync(&trans_pcie->me_recheck_wk); - - iwl_drv_stop(trans->drv); - - iwl_trans_pcie_free(trans); -} - int iwl_pcie_activate_nic(struct iwl_trans *trans) { const struct iwl_mac_cfg *mac_cfg = trans->mac_cfg; From fb15d5e1141511f93fc730fd8c721c501c2b420c Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:22 +0300 Subject: [PATCH 1572/2126] wifi: iwlwifi: Revert "wifi: iwlwifi: pcie: move generation specific files to a folder" This reverts commit a6fafaedb5d6 ("wifi: iwlwifi: pcie: move generation specific files to a folder"). The pcie/gen1_2/ subfolder was introduced to prepare for a future pcie-transport, which will not happen eventually. Move all the files back to the pcie folder and remove the gen1_2 folder. Link: https://patch.msgid.link/20260926201527.91ac209ad70d.I25521996309a25ac779cb31f2c93477b25be9ac3@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/Makefile | 6 +++--- drivers/net/wireless/intel/iwlwifi/iwl-trans.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/internal.h | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/rx.c | 2 +- .../wireless/intel/iwlwifi/pcie/{gen1_2 => }/trans-gen2.c | 4 ++-- .../net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/trans.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/tx-gen2.c | 0 drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/tx.c | 0 11 files changed, 12 insertions(+), 12 deletions(-) rename drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/internal.h (99%) rename drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/rx.c (99%) rename drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/trans-gen2.c (99%) rename drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/trans.c (99%) rename drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/tx-gen2.c (100%) rename drivers/net/wireless/intel/iwlwifi/pcie/{gen1_2 => }/tx.c (100%) diff --git a/drivers/net/wireless/intel/iwlwifi/Makefile b/drivers/net/wireless/intel/iwlwifi/Makefile index 2a74efe09cf0..6746281350e0 100644 --- a/drivers/net/wireless/intel/iwlwifi/Makefile +++ b/drivers/net/wireless/intel/iwlwifi/Makefile @@ -9,9 +9,9 @@ iwlwifi-objs += iwl-utils.o iwlwifi-objs += iwl-phy-db.o iwl-nvm-parse.o # Bus -iwlwifi-objs += pcie/ctxt-info.o pcie/ctxt-info-v2.o pcie/drv.o pcie/utils.o -iwlwifi-objs += pcie/gen1_2/rx.o pcie/gen1_2/tx.o pcie/gen1_2/trans.o -iwlwifi-objs += pcie/gen1_2/trans-gen2.o pcie/gen1_2/tx-gen2.o +iwlwifi-objs += pcie/drv.o pcie/rx.o pcie/tx.o pcie/trans.o +iwlwifi-objs += pcie/ctxt-info.o pcie/ctxt-info-v2.o pcie/trans-gen2.o pcie/tx-gen2.o +iwlwifi-objs += pcie/utils.o CFLAGS_pcie/drv.o += -Wno-override-init diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 8cc8f6c4e934..24bf45f06746 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -12,7 +12,7 @@ #include "iwl-drv.h" #include #include "fw/api/commands.h" -#include "pcie/gen1_2/internal.h" +#include "pcie/internal.h" #include "pcie/iwl-context-info-v2.h" struct iwl_trans_dev_restart_data { diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c index 1ea23d297713..c75210829ec9 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c @@ -6,7 +6,7 @@ #include "iwl-trans.h" #include "iwl-fh.h" #include "iwl-context-info-v2.h" -#include "gen1_2/internal.h" +#include "internal.h" #include "iwl-prph.h" static const struct dmi_system_id dmi_force_scu_active_approved_list[] = { diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c index 7f886200d693..23ec968577bd 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c @@ -6,7 +6,7 @@ #include "iwl-trans.h" #include "iwl-fh.h" #include "iwl-context-info.h" -#include "gen1_2/internal.h" +#include "internal.h" #include "iwl-prph.h" static void *_iwl_pcie_ctxt_info_dma_alloc_coherent(struct iwl_trans *trans, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c index 4fa514ba9975..905482419a9a 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c @@ -15,7 +15,7 @@ #include "iwl-trans.h" #include "iwl-drv.h" #include "iwl-prph.h" -#include "gen1_2/internal.h" +#include "internal.h" #define _IS_A(cfg, _struct) __builtin_types_compatible_p(typeof(cfg), \ struct _struct) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h similarity index 99% rename from drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h rename to drivers/net/wireless/intel/iwlwifi/pcie/internal.h index cff02afa4e26..e10aa8e7e061 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -22,7 +22,7 @@ #include "iwl-io.h" #include "iwl-op-mode.h" #include "iwl-drv.h" -#include "pcie/iwl-context-info.h" +#include "iwl-context-info.h" /* * RX related structures and functions diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c similarity index 99% rename from drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/rx.c rename to drivers/net/wireless/intel/iwlwifi/pcie/rx.c index 4631e11f2a96..eb70922cf516 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -12,7 +12,7 @@ #include "iwl-io.h" #include "internal.h" #include "iwl-op-mode.h" -#include "pcie/iwl-context-info-v2.h" +#include "iwl-context-info-v2.h" #include "fw/dbg.h" /****************************************************************************** diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c similarity index 99% rename from drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans-gen2.c rename to drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c index f41cbe62e7aa..39dd963920b3 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c @@ -5,8 +5,8 @@ */ #include "iwl-trans.h" #include "iwl-prph.h" -#include "pcie/iwl-context-info.h" -#include "pcie/iwl-context-info-v2.h" +#include "iwl-context-info.h" +#include "iwl-context-info-v2.h" #include "internal.h" #include "fw/dbg.h" diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c similarity index 99% rename from drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c rename to drivers/net/wireless/intel/iwlwifi/pcie/trans.c index db92c5c954e6..4771cf3b3e11 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -28,7 +28,7 @@ #include "mei/iwl-mei.h" #include "internal.h" #include "iwl-fh.h" -#include "pcie/iwl-context-info-v2.h" +#include "iwl-context-info-v2.h" #include "pcie/utils.h" #define IWL_HOST_MON_BLOCK_PEMON 0x00 diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c similarity index 100% rename from drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx-gen2.c rename to drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c similarity index 100% rename from drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c rename to drivers/net/wireless/intel/iwlwifi/pcie/tx.c From 2395f2a298eec2abdb148d51fe2e0ccac431237f Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Sat, 26 Sep 2026 20:17:23 +0300 Subject: [PATCH 1573/2126] wifi: iwlwifi: send standalone SAR to firmware Plumb the standalone WRSS/EWSS SAR data and send the standalone profile to firmware. Add REDUCE_TX_POWER_CMD version 12 support with the IWL_TX_POWER_MODE_SET_STANDALONE_CHAINS set_mode, and rename iwl_dev_tx_power_cmd_v11 to iwl_dev_tx_power_cmd_v12 to match the updated command layout. This enables higher transmit power limits for standalone firmware operation while preserving the existing concurrent SAR handling. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260926201527.d5315e93c1ce.Ic02190e91e795dcfe660710721b47de71f2b2c86@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/power.h | 14 ++-- .../wireless/intel/iwlwifi/fw/regulatory.c | 26 ++++-- .../wireless/intel/iwlwifi/fw/regulatory.h | 4 +- .../net/wireless/intel/iwlwifi/mld/power.c | 2 +- .../wireless/intel/iwlwifi/mld/regulatory.c | 80 +++++++++++++++++-- .../wireless/intel/iwlwifi/mld/regulatory.h | 4 +- drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 3 +- 7 files changed, 107 insertions(+), 26 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/power.h b/drivers/net/wireless/intel/iwlwifi/fw/api/power.h index 115e65ba19f8..4d54a95b98ca 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/power.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/power.h @@ -300,7 +300,8 @@ enum iwl_dev_tx_power_cmd_mode { IWL_TX_POWER_MODE_SET_ACK = 3, IWL_TX_POWER_MODE_SET_SAR_TIMER = 4, IWL_TX_POWER_MODE_SET_SAR_TIMER_DEFAULT_TABLE = 5, -}; /* TX_POWER_REDUCED_FLAGS_TYPE_API_E_VER_5 */; + IWL_TX_POWER_MODE_SET_STANDALONE_CHAINS = 8, /* cmd ver 12+ */ +}; /* TX_POWER_REDUCED_FLAGS_TYPE_API_E_VER_2 */; #define IWL_NUM_CHAIN_TABLES 1 #define IWL_NUM_CHAIN_TABLES_V2 2 @@ -464,31 +465,34 @@ struct iwl_dev_tx_power_cmd_v10 { __le32 flags; } __packed; /* TX_REDUCED_POWER_API_S_VER_10 */ -struct iwl_dev_tx_power_cmd_v11 { +struct iwl_dev_tx_power_cmd_v12 { __le16 per_chain[IWL_NUM_CHAIN_TABLES_V2][IWL_NUM_CHAIN_LIMITS][IWL_NUM_SUB_BANDS_V3]; u8 per_chain_restriction_changed; u8 reserved; __le32 timer_period; __le32 flags; -} __packed; /* TX_REDUCED_POWER_API_S_VER_11 */ +} __packed; /* TX_REDUCED_POWER_API_S_VER_11 + * TX_REDUCED_POWER_API_S_VER_12 + */ /* * struct iwl_dev_tx_power_cmd - TX power reduction command (multiversion) * @common: common part of the command * @v9: version 9 part of the command * @v10: version 10 part of the command - * @v11: version 11 part of the command + * @v12: version 12 part of the command (also covers v11) */ struct iwl_dev_tx_power_cmd { struct iwl_dev_tx_power_common common; union { struct iwl_dev_tx_power_cmd_v9 v9; struct iwl_dev_tx_power_cmd_v10 v10; - struct iwl_dev_tx_power_cmd_v11 v11; + struct iwl_dev_tx_power_cmd_v12 v12; }; } __packed; /* TX_REDUCED_POWER_API_S_VER_9 * TX_REDUCED_POWER_API_S_VER_10 * TX_REDUCED_POWER_API_S_VER_11 + * TX_REDUCED_POWER_API_S_VER_12 */ #define IWL_NUM_GEO_PROFILES 3 diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index 137303e4a29b..27a5804dbd73 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -247,17 +247,22 @@ IWL_EXPORT_SYMBOL(iwl_sar_geo_fill_table); static int iwl_sar_fill_table(struct iwl_fw_runtime *fwrt, __le16 *per_chain, u32 n_subbands, - int prof_a, int prof_b) + int prof_a, int prof_b, + const struct iwl_sar_profile *profiles, + bool is_standalone) { int profs[BIOS_SAR_NUM_CHAINS] = { prof_a, prof_b }; int i, j; + BUILD_BUG_ON(ARRAY_SIZE(fwrt->sar_standalone_profiles[0].chains[0].subbands) != + ARRAY_SIZE(fwrt->sar_profiles[0].chains[0].subbands)); + if (WARN_ON_ONCE(n_subbands > ARRAY_SIZE(fwrt->sar_profiles[0].chains[0].subbands))) return -EINVAL; for (i = 0; i < BIOS_SAR_NUM_CHAINS; i++) { - struct iwl_sar_profile *prof; + const struct iwl_sar_profile *prof; /* don't allow SAR to be disabled (profile 0 means disable) */ if (profs[i] == 0) @@ -268,11 +273,13 @@ static int iwl_sar_fill_table(struct iwl_fw_runtime *fwrt, return -EINVAL; /* profiles go from 1 to 4, so decrement to access the array */ - prof = &fwrt->sar_profiles[profs[i] - 1]; + prof = &profiles[profs[i] - 1]; /* if the profile is disabled, do nothing */ if (!prof->enabled) { - IWL_DEBUG_RADIO(fwrt, "SAR profile %d is disabled.\n", + IWL_DEBUG_RADIO(fwrt, + "SAR %sprofile %d is disabled.\n", + is_standalone ? "standalone " : "", profs[i]); /* * if one of the profiles is disabled, we @@ -282,8 +289,8 @@ static int iwl_sar_fill_table(struct iwl_fw_runtime *fwrt, return 1; } - IWL_DEBUG_INFO(fwrt, - "SAR EWRD: chain %d profile index %d\n", + IWL_DEBUG_INFO(fwrt, "SAR %s: chain %d profile index %d\n", + is_standalone ? "standalone" : "EWRD", i, profs[i]); IWL_DEBUG_RADIO(fwrt, " Chain[%d]:\n", i); for (j = 0; j < n_subbands; j++) { @@ -299,14 +306,17 @@ static int iwl_sar_fill_table(struct iwl_fw_runtime *fwrt, int iwl_sar_fill_profile(struct iwl_fw_runtime *fwrt, __le16 *per_chain, u32 n_tables, u32 n_subbands, - int prof_a, int prof_b) + int prof_a, int prof_b, + const struct iwl_sar_profile *profiles, + bool is_standalone) { int i, ret = 0; for (i = 0; i < n_tables; i++) { ret = iwl_sar_fill_table(fwrt, &per_chain[i * n_subbands * BIOS_SAR_NUM_CHAINS], - n_subbands, prof_a, prof_b); + n_subbands, prof_a, prof_b, profiles, + is_standalone); if (ret) break; } diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h index bd7ea0ff3d19..e32e107812b1 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.h @@ -210,7 +210,9 @@ int iwl_sar_geo_fill_table(struct iwl_fw_runtime *fwrt, int iwl_sar_fill_profile(struct iwl_fw_runtime *fwrt, __le16 *per_chain, u32 n_tables, u32 n_subbands, - int prof_a, int prof_b); + int prof_a, int prof_b, + const struct iwl_sar_profile *profiles, + bool is_standalone); bool iwl_is_ppag_approved(struct iwl_fw_runtime *fwrt); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/power.c b/drivers/net/wireless/intel/iwlwifi/mld/power.c index 2387f3da5185..6fcbb1a2e8a8 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/power.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/power.c @@ -525,7 +525,7 @@ int iwl_mld_set_tx_power(struct iwl_mld *mld, .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_LINK), .common.pwr_restriction = cpu_to_le16(u_tx_power), }; - int len = sizeof(cmd.common) + sizeof(cmd.v11); + int len = sizeof(cmd.common) + sizeof(cmd.v12); if (iwl_fw_lookup_cmd_ver(mld->fw, cmd_id, 10) == 10) len = sizeof(cmd.common) + sizeof(cmd.v10); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c b/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c index 9f395a1fd12a..8a20d7622329 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/regulatory.c @@ -74,6 +74,21 @@ void iwl_mld_get_bios_tables(struct iwl_mld *mld) "EWRD SAR BIOS table invalid or unavailable. (%d)\n", ret); + ret = iwl_bios_get_wsss_table(&mld->fwrt); + if (ret < 0) + IWL_DEBUG_RADIO(mld, + "WSSS (WRDS Standalone) SAR BIOS table invalid or unavailable. (%d)\n", + ret); + + if (!ret) { + /* EWSS only extends the standalone SAR profiles from WSSS. */ + ret = iwl_bios_get_ewss_table(&mld->fwrt); + if (ret < 0) + IWL_DEBUG_RADIO(mld, + "EWSS (EWRD Standalone) SAR BIOS table invalid or unavailable. (%d)\n", + ret); + } + ret = iwl_bios_get_wgds_table(&mld->fwrt); if (ret < 0) IWL_DEBUG_RADIO(mld, @@ -135,7 +150,9 @@ static int iwl_mld_geo_sar_init(struct iwl_mld *mld) return iwl_mld_send_cmd_pdu(mld, cmd_id, &cmd, cmd_size); } -int iwl_mld_config_sar_profile(struct iwl_mld *mld, int prof_a, int prof_b) +static int +iwl_mld_config_sar_concurrent_profile(struct iwl_mld *mld, int prof_a, + int prof_b) { struct iwl_dev_tx_power_cmd cmd = { .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS), @@ -152,8 +169,9 @@ int iwl_mld_config_sar_profile(struct iwl_mld *mld, int prof_a, int prof_b) num_subbands = IWL_NUM_SUB_BANDS_V2; break; case 11: - cmd.v11.flags = cpu_to_le32(mld->fwrt.reduced_power_flags); - cmd_size = sizeof(cmd.common) + sizeof(cmd.v11); + case 12: + cmd.v12.flags = cpu_to_le32(mld->fwrt.reduced_power_flags); + cmd_size = sizeof(cmd.common) + sizeof(cmd.v12); num_subbands = IWL_NUM_SUB_BANDS_V3; break; default: @@ -163,12 +181,13 @@ int iwl_mld_config_sar_profile(struct iwl_mld *mld, int prof_a, int prof_b) } /* TODO: CDB - support IWL_NUM_CHAIN_TABLES_V2 */ - /* v10 and v11 have the same position for per_chain */ - BUILD_BUG_ON(offsetof(typeof(cmd), v11.per_chain) != + /* v10 and v12 have the same position for per_chain */ + BUILD_BUG_ON(offsetof(typeof(cmd), v12.per_chain) != offsetof(typeof(cmd), v10.per_chain)); - ret = iwl_sar_fill_profile(&mld->fwrt, &cmd.v11.per_chain[0][0][0], + ret = iwl_sar_fill_profile(&mld->fwrt, &cmd.v12.per_chain[0][0][0], IWL_NUM_CHAIN_TABLES, num_subbands, - prof_a, prof_b); + prof_a, prof_b, + mld->fwrt.sar_profiles, false); /* return on error or if the profile is disabled (positive number) */ if (ret) return ret; @@ -176,6 +195,51 @@ int iwl_mld_config_sar_profile(struct iwl_mld *mld, int prof_a, int prof_b) return iwl_mld_send_cmd_pdu(mld, REDUCE_TX_POWER_CMD, &cmd, cmd_size); } +static int iwl_mld_config_sar_standalone_profile(struct iwl_mld *mld, + int prof_a, int prof_b) +{ + struct iwl_dev_tx_power_cmd cmd = { + .common.set_mode = + cpu_to_le32(IWL_TX_POWER_MODE_SET_STANDALONE_CHAINS), + }; + int ret; + + /* standalone per-chain SAR limits require cmd version 12 */ + if (iwl_fw_lookup_cmd_ver(mld->fw, REDUCE_TX_POWER_CMD, 10) != 12) + return 0; + + ret = iwl_sar_fill_profile(&mld->fwrt, + &cmd.v12.per_chain[0][0][0], + IWL_NUM_CHAIN_TABLES, + IWL_NUM_SUB_BANDS_V3, + prof_a, prof_b, + mld->fwrt.sar_standalone_profiles, + true); + /* return on error or if the standalone profile is disabled */ + if (ret) + return ret; + + return iwl_mld_send_cmd_pdu(mld, REDUCE_TX_POWER_CMD, &cmd, + sizeof(cmd.common) + sizeof(cmd.v12)); +} + +int iwl_mld_config_sar_profiles(struct iwl_mld *mld, int prof_a, int prof_b) +{ + int ret; + + ret = iwl_mld_config_sar_concurrent_profile(mld, prof_a, prof_b); + /* return on error or if the profile is disabled (positive number) */ + if (ret) + return ret; + + ret = iwl_mld_config_sar_standalone_profile(mld, prof_a, prof_b); + /* standalone profile is optional and may be disabled (positive number) */ + if (ret < 0) + return ret; + + return 0; +} + int iwl_mld_init_sar(struct iwl_mld *mld) { int chain_a_prof = 1; @@ -190,7 +254,7 @@ int iwl_mld_init_sar(struct iwl_mld *mld) chain_b_prof = mld->fwrt.sar_chain_b_profile; } - ret = iwl_mld_config_sar_profile(mld, chain_a_prof, chain_b_prof); + ret = iwl_mld_config_sar_profiles(mld, chain_a_prof, chain_b_prof); if (ret < 0) return ret; diff --git a/drivers/net/wireless/intel/iwlwifi/mld/regulatory.h b/drivers/net/wireless/intel/iwlwifi/mld/regulatory.h index 5498c19789f4..0877b951f2e2 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/regulatory.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/regulatory.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2024-2025 Intel Corporation + * Copyright (C) 2024-2026 Intel Corporation */ #ifndef __iwl_mld_regulatory_h__ #define __iwl_mld_regulatory_h__ @@ -18,6 +18,6 @@ int iwl_mld_init_sgom(struct iwl_mld *mld); int iwl_mld_init_sar(struct iwl_mld *mld); -int iwl_mld_config_sar_profile(struct iwl_mld *mld, int prof_a, int prof_b); +int iwl_mld_config_sar_profiles(struct iwl_mld *mld, int prof_a, int prof_b); #endif /* __iwl_mld_regulatory_h__ */ diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c index 0b5b41223a8a..c3402f5e47a0 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c @@ -911,7 +911,8 @@ int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b) ret = iwl_sar_fill_profile(&mvm->fwrt, per_chain, IWL_NUM_CHAIN_TABLES, - n_subbands, prof_a, prof_b); + n_subbands, prof_a, prof_b, + mvm->fwrt.sar_profiles, false); /* return on error or if the profile is disabled (positive number) */ if (ret) From c27b72f04d00697ea8452cc7585ef1a6f7353db6 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Sat, 26 Sep 2026 20:17:24 +0300 Subject: [PATCH 1574/2126] wifi: iwlwifi: uefi: Fix SAR enable check to use mode parameter correctly The iwl_uefi_set_sar_profile() function was receiving a bool parameter, which would treat any non-zero value as enabled. This is incorrect because the SAR mode value contains additional bits beyond the enable flag. Change the parameter from bool enabled to u32 mode and properly extract the enable bit using IWL_SAR_ENABLE_MSK bitmask. This ensures that only the designated enable bit determines whether SAR is enabled, not arbitrary non-zero values. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260926201527.60160602581b.Ib184c201e677cb6d95f64e725a1e39148234fa41@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 79fd95d08732..86825318c543 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -549,7 +549,7 @@ IWL_EXPORT_SYMBOL(iwl_uefi_get_uneb_table); static void iwl_uefi_set_sar_profile(struct iwl_sar_profile *profiles, const u8 *vals, u8 prof_index, - u8 num_subbands, bool enabled) + u8 num_subbands, u32 mode) { struct iwl_sar_profile *sar_prof = &profiles[prof_index]; @@ -573,7 +573,7 @@ static void iwl_uefi_set_sar_profile(struct iwl_sar_profile *profiles, vals[chain * num_subbands + subband]; } - sar_prof->enabled = enabled & IWL_SAR_ENABLE_MSK; + sar_prof->enabled = mode & IWL_SAR_ENABLE_MSK; } int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt) From c9e7a64a7376700f712642cf8b4a122faad47069 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Sat, 26 Sep 2026 20:17:25 +0300 Subject: [PATCH 1575/2126] wifi: iwlwifi: fw: harden UEFI reduced-power TLV parsing UEFI reduced-power parsing advanced by ALIGN(tlv_len, 4) but validated only tlv_len. When remaining bytes were between these values, len could underflow and parsing could continue past the buffer boundary. Validate remaining bytes against the aligned length before advancing in both TLV walkers. Signed-off-by: Pagadala Yesu Anjaneyulu Assisted-by: GitHubCopilot:GPT-5.3-Codex Link: https://patch.msgid.link/20260926201527.2552432e98e8.I570750f27d9530d4c76922d2699a272d9c60a0ab@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 47 ++++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 86825318c543..872df8f6c375 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -251,15 +251,24 @@ static int iwl_uefi_reduce_power_section(struct iwl_trans *trans, memset(pnvm_data, 0, sizeof(*pnvm_data)); while (len >= sizeof(*tlv)) { - u32 tlv_len, tlv_type; + u32 tlv_len, tlv_type, tlv_len_aligned; len -= sizeof(*tlv); tlv = (const void *)data; tlv_len = le32_to_cpu(tlv->length); tlv_type = le32_to_cpu(tlv->type); + tlv_len_aligned = ALIGN(tlv_len, 4); - if (len < tlv_len) { + /* Make sure ALIGN() did not overflow for a malformed TLV length. */ + if (tlv_len_aligned < tlv_len) { + IWL_ERR(trans, + "TLV len overflows on alignment: %u\n", + tlv_len); + return -EINVAL; + } + + if (len < tlv_len_aligned) { IWL_ERR(trans, "invalid TLV len: %zd/%u\n", len, tlv_len); return -EINVAL; @@ -278,13 +287,13 @@ static int iwl_uefi_reduce_power_section(struct iwl_trans *trans, "New REDUCE_POWER section started, stop parsing.\n"); goto done; default: - IWL_DEBUG_FW(trans, "Found TLV 0x%0x, len %d\n", + IWL_DEBUG_FW(trans, "Found TLV 0x%0x, len %u\n", tlv_type, tlv_len); break; } - len -= ALIGN(tlv_len, 4); - data += ALIGN(tlv_len, 4); + len -= tlv_len_aligned; + data += tlv_len_aligned; } done: @@ -305,15 +314,24 @@ int iwl_uefi_reduce_power_parse(struct iwl_trans *trans, IWL_DEBUG_FW(trans, "Parsing REDUCE_POWER data\n"); while (len >= sizeof(*tlv)) { - u32 tlv_len, tlv_type; + u32 tlv_len, tlv_type, tlv_len_aligned; len -= sizeof(*tlv); tlv = (const void *)data; tlv_len = le32_to_cpu(tlv->length); tlv_type = le32_to_cpu(tlv->type); + tlv_len_aligned = ALIGN(tlv_len, 4); - if (len < tlv_len) { + /* Make sure ALIGN() did not overflow for a malformed TLV length. */ + if (tlv_len_aligned < tlv_len) { + IWL_ERR(trans, + "TLV len overflows on alignment: %u\n", + tlv_len); + return -EINVAL; + } + + if (len < tlv_len_aligned) { IWL_ERR(trans, "invalid TLV len: %zd/%u\n", len, tlv_len); return -EINVAL; @@ -323,22 +341,23 @@ int iwl_uefi_reduce_power_parse(struct iwl_trans *trans, const struct iwl_sku_id *tlv_sku_id = (const void *)(data + sizeof(*tlv)); - IWL_DEBUG_FW(trans, - "Got IWL_UCODE_TLV_PNVM_SKU len %d\n", - tlv_len); if (tlv_len < sizeof(*tlv_sku_id)) { IWL_ERR(trans, "invalid PNVM SKU TLV len: %u\n", tlv_len); return -EINVAL; } + IWL_DEBUG_FW(trans, + "Got IWL_UCODE_TLV_PNVM_SKU len %u\n", + tlv_len); + IWL_DEBUG_FW(trans, "sku_id 0x%0x 0x%0x 0x%0x\n", le32_to_cpu(tlv_sku_id->data[0]), le32_to_cpu(tlv_sku_id->data[1]), le32_to_cpu(tlv_sku_id->data[2])); - data += sizeof(*tlv) + ALIGN(tlv_len, 4); - len -= ALIGN(tlv_len, 4); + data += sizeof(*tlv) + tlv_len_aligned; + len -= tlv_len_aligned; if (sku_id[0] == tlv_sku_id->data[0] && sku_id[1] == tlv_sku_id->data[1] && @@ -352,8 +371,8 @@ int iwl_uefi_reduce_power_parse(struct iwl_trans *trans, IWL_DEBUG_FW(trans, "SKU ID didn't match!\n"); } } else { - data += sizeof(*tlv) + ALIGN(tlv_len, 4); - len -= ALIGN(tlv_len, 4); + data += sizeof(*tlv) + tlv_len_aligned; + len -= tlv_len_aligned; } } From d57bd34a6d4ee7ced4c2f115396e20b2348d1076 Mon Sep 17 00:00:00 2001 From: Pagadala Yesu Anjaneyulu Date: Sat, 26 Sep 2026 20:17:26 +0300 Subject: [PATCH 1576/2126] wifi: iwlwifi: fw: add Samsung to TAS and PPAG allow lists Allow platforms reporting the exact manufacturer string "Samsung" to use TAS and PPAG, while retaining the existing Samsung Electronics entry. Signed-off-by: Pagadala Yesu Anjaneyulu Link: https://patch.msgid.link/20260926201527.e2e2e1f720af.I18a7292b5a8bd878d074b114b45ce99e1309897e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/regulatory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index 27a5804dbd73..c7de45323935 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -49,11 +49,16 @@ static const struct dmi_system_id dmi_ppag_approved_list[] = { DMI_MATCH(DMI_SYS_VENDOR, "HP"), }, }, - { .ident = "SAMSUNG", + { .ident = "SAMSUNG_ELECTRONICS", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD"), }, }, + { .ident = "SAMSUNG", + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Samsung"), + }, + }, { .ident = "MSFT", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), @@ -126,10 +131,15 @@ static const struct dmi_system_id dmi_tas_approved_list[] = { DMI_MATCH(DMI_SYS_VENDOR, "HP"), }, }, - { .ident = "SAMSUNG", + { .ident = "SAMSUNG_ELECTRONICS", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD"), }, + }, + { .ident = "SAMSUNG", + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Samsung"), + }, }, { .ident = "LENOVO", .matches = { From cc014b0cb9b65e0dff8febee69265d4273b1f5b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Sat, 26 Sep 2026 20:17:27 +0300 Subject: [PATCH 1577/2126] wifi: iwlwifi: pcie: order RX reads after the write pointer iwl_pcie_rx_handle() reads the last closed RB index from rb_stts and then reads the completion descriptor and the RB contents that this index makes visible. Nothing orders those two reads: there is no barrier, the descriptor address derives from rxq->read rather than from the index just read, so there is no address dependency, and the "while (i != r)" test is only a control dependency, which does not order loads on arm64. The CPU can therefore speculate past the loop test, perform the completion descriptor load early and sample the value from before the device's DMA, then resolve the rb_stts load to the value from after it. On arm64 (Jetson AGX Orin) this showed up as recurring "Invalid rxb from HW " naming an in-range rbid the driver still owned, and "frame on invalid queue" for an RB tagged with the queue that used it before the wrap. Both force an NMI and a firmware restart. x86 never shows it because loads are not reordered with loads there. Add a dma_rmb() after reading the write pointer, as other NIC drivers do when consuming a DMA descriptor ring. It is a no-op on x86 and a dmb on arm64. Verified to stop the warnings on Orin. Signed-off-by: Emmanuel Grumbach Assisted-by: GitHub-Copilot:claude-opus-5 Link: https://patch.msgid.link/20260926201527.1bff8cebef69.I24dec81516e37a33674e87ed3359c41e59d12e5e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index eb70922cf516..d1ef0365b932 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -1519,6 +1519,11 @@ restart: r = iwl_get_closed_rb_stts(trans, rxq); i = rxq->read; + /* Order the read of the write pointer before any read of the + * completion descriptors and of the RB contents it makes visible. + */ + dma_rmb(); + /* W/A 9000 device step A0 wrap-around bug */ r &= (rxq->queue_size - 1); From 950b3e44cae72b687ba91f37ee67860c35a065bd Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:28 +0300 Subject: [PATCH 1578/2126] wifi: iwlwifi: pcie: remove iwl_dbgfs_fh_reg_read This is no longer needed, and adds lots of parsing code Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260926201527.3e2f229ac9f6.I122eaf364743ffc42bd18a84a766d7920ec5700d@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 177 ------------------ drivers/net/wireless/intel/iwlwifi/iwl-io.h | 3 - .../net/wireless/intel/iwlwifi/pcie/trans.c | 20 -- 3 files changed, 200 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index bb746112ddad..544b8e686dfe 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -11,7 +11,6 @@ #include "iwl-csr.h" #include "iwl-debug.h" #include "iwl-prph.h" -#include "iwl-fh.h" void iwl_write8(struct iwl_trans *trans, u32 ofs, u8 val) { @@ -235,182 +234,6 @@ void iwl_force_nmi(struct iwl_trans *trans) } IWL_EXPORT_SYMBOL(iwl_force_nmi); -static const char *get_rfh_string(int cmd) -{ -#define IWL_CMD(x) case x: return #x -#define IWL_CMD_MQ(arg, reg, q) { if (arg == reg(q)) return #reg; } - - int i; - - for (i = 0; i < IWL_MAX_RX_HW_QUEUES; i++) { - IWL_CMD_MQ(cmd, RFH_Q_FRBDCB_BA_LSB, i); - IWL_CMD_MQ(cmd, RFH_Q_FRBDCB_WIDX, i); - IWL_CMD_MQ(cmd, RFH_Q_FRBDCB_RIDX, i); - IWL_CMD_MQ(cmd, RFH_Q_URBD_STTS_WPTR_LSB, i); - } - - switch (cmd) { - IWL_CMD(RFH_RXF_DMA_CFG); - IWL_CMD(RFH_GEN_CFG); - IWL_CMD(RFH_GEN_STATUS); - IWL_CMD(FH_TSSR_TX_STATUS_REG); - IWL_CMD(FH_TSSR_TX_ERROR_REG); - default: - return "UNKNOWN"; - } -#undef IWL_CMD_MQ -} - -struct reg { - u32 addr; - bool is64; -}; - -static int iwl_dump_rfh(struct iwl_trans *trans, char **buf) -{ - int i, q; - int num_q = trans->info.num_rxqs; - static const u32 rfh_tbl[] = { - RFH_RXF_DMA_CFG, - RFH_GEN_CFG, - RFH_GEN_STATUS, - FH_TSSR_TX_STATUS_REG, - FH_TSSR_TX_ERROR_REG, - }; - static const struct reg rfh_mq_tbl[] = { - { RFH_Q0_FRBDCB_BA_LSB, true }, - { RFH_Q0_FRBDCB_WIDX, false }, - { RFH_Q0_FRBDCB_RIDX, false }, - { RFH_Q0_URBD_STTS_WPTR_LSB, true }, - }; - -#ifdef CONFIG_IWLWIFI_DEBUGFS - if (buf) { - int pos = 0; - /* - * Register (up to 34 for name + 8 blank/q for MQ): 40 chars - * Colon + space: 2 characters - * 0X%08x: 10 characters - * New line: 1 character - * Total of 53 characters - */ - size_t bufsz = ARRAY_SIZE(rfh_tbl) * 53 + - ARRAY_SIZE(rfh_mq_tbl) * 53 * num_q + 40; - - *buf = kmalloc(bufsz, GFP_KERNEL); - if (!*buf) - return -ENOMEM; - - pos += scnprintf(*buf + pos, bufsz - pos, - "RFH register values:\n"); - - for (i = 0; i < ARRAY_SIZE(rfh_tbl); i++) - pos += scnprintf(*buf + pos, bufsz - pos, - "%40s: 0X%08x\n", - get_rfh_string(rfh_tbl[i]), - iwl_read_prph(trans, rfh_tbl[i])); - - for (i = 0; i < ARRAY_SIZE(rfh_mq_tbl); i++) - for (q = 0; q < num_q; q++) { - u32 addr = rfh_mq_tbl[i].addr; - - addr += q * (rfh_mq_tbl[i].is64 ? 8 : 4); - pos += scnprintf(*buf + pos, bufsz - pos, - "%34s(q %2d): 0X%08x\n", - get_rfh_string(addr), q, - iwl_read_prph(trans, addr)); - } - - return pos; - } -#endif - - IWL_ERR(trans, "RFH register values:\n"); - for (i = 0; i < ARRAY_SIZE(rfh_tbl); i++) - IWL_ERR(trans, " %34s: 0X%08x\n", - get_rfh_string(rfh_tbl[i]), - iwl_read_prph(trans, rfh_tbl[i])); - - for (i = 0; i < ARRAY_SIZE(rfh_mq_tbl); i++) - for (q = 0; q < num_q; q++) { - u32 addr = rfh_mq_tbl[i].addr; - - addr += q * (rfh_mq_tbl[i].is64 ? 8 : 4); - IWL_ERR(trans, " %34s(q %d): 0X%08x\n", - get_rfh_string(addr), q, - iwl_read_prph(trans, addr)); - } - - return 0; -} - -static const char *get_fh_string(int cmd) -{ - switch (cmd) { - IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG); - IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG); - IWL_CMD(FH_RSCSR_CHNL0_WPTR); - IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG); - IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG); - IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG); - IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV); - IWL_CMD(FH_TSSR_TX_STATUS_REG); - IWL_CMD(FH_TSSR_TX_ERROR_REG); - default: - return "UNKNOWN"; - } -#undef IWL_CMD -} - -int iwl_dump_fh(struct iwl_trans *trans, char **buf) -{ - int i; - static const u32 fh_tbl[] = { - FH_RSCSR_CHNL0_STTS_WPTR_REG, - FH_RSCSR_CHNL0_RBDCB_BASE_REG, - FH_RSCSR_CHNL0_WPTR, - FH_MEM_RCSR_CHNL0_CONFIG_REG, - FH_MEM_RSSR_SHARED_CTRL_REG, - FH_MEM_RSSR_RX_STATUS_REG, - FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV, - FH_TSSR_TX_STATUS_REG, - FH_TSSR_TX_ERROR_REG - }; - - if (trans->mac_cfg->mq_rx_supported) - return iwl_dump_rfh(trans, buf); - -#ifdef CONFIG_IWLWIFI_DEBUGFS - if (buf) { - int pos = 0; - size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40; - - *buf = kmalloc(bufsz, GFP_KERNEL); - if (!*buf) - return -ENOMEM; - - pos += scnprintf(*buf + pos, bufsz - pos, - "FH register values:\n"); - - for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) - pos += scnprintf(*buf + pos, bufsz - pos, - " %34s: 0X%08x\n", - get_fh_string(fh_tbl[i]), - iwl_read_direct32(trans, fh_tbl[i])); - - return pos; - } -#endif - - IWL_ERR(trans, "FH register values:\n"); - for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) - IWL_ERR(trans, " %34s: 0X%08x\n", - get_fh_string(fh_tbl[i]), - iwl_read_direct32(trans, fh_tbl[i])); - - return 0; -} - void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr, u32 sw_err_bit) { diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h index 6dce2e5267a6..e66b0c2a0467 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.h @@ -59,9 +59,6 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); void iwl_force_nmi(struct iwl_trans *trans); -/* Error handling */ -int iwl_dump_fh(struct iwl_trans *trans, char **buf); - /* * UMAC periphery address space changed from 0xA00000 to 0xD00000 starting from * device family AX200. So peripheries used in families above and below AX200 diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 4771cf3b3e11..97bbc3faa98c 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -3016,24 +3016,6 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file, return count; } -static ssize_t iwl_dbgfs_fh_reg_read(struct file *file, - char __user *user_buf, - size_t count, loff_t *ppos) -{ - struct iwl_trans *trans = file->private_data; - char *buf = NULL; - ssize_t ret; - - ret = iwl_dump_fh(trans, &buf); - if (ret < 0) - return ret; - if (!buf) - return -EINVAL; - ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); - kfree(buf); - return ret; -} - static ssize_t iwl_dbgfs_rfkill_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) @@ -3133,7 +3115,6 @@ static ssize_t iwl_dbgfs_reset_write(struct file *file, } DEBUGFS_READ_WRITE_FILE_OPS(interrupt); -DEBUGFS_READ_FILE_OPS(fh_reg); DEBUGFS_READ_FILE_OPS(rx_queue); DEBUGFS_WRITE_FILE_OPS(csr); DEBUGFS_READ_WRITE_FILE_OPS(rfkill); @@ -3157,7 +3138,6 @@ void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans) DEBUGFS_ADD_FILE(tx_queue, dir, 0400); DEBUGFS_ADD_FILE(interrupt, dir, 0600); DEBUGFS_ADD_FILE(csr, dir, 0200); - DEBUGFS_ADD_FILE(fh_reg, dir, 0400); DEBUGFS_ADD_FILE(rfkill, dir, 0600); DEBUGFS_ADD_FILE(rf, dir, 0400); DEBUGFS_ADD_FILE(reset, dir, 0200); From b6f39b3c8f0fd9d7864b197b77f0b29fc013ce82 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:29 +0300 Subject: [PATCH 1579/2126] wifi: iwlwifi: open code iwl_trans_sync_nmi_with_addr() iwl_trans_sync_nmi_with_addr() had a single caller, iwl_trans_pcie_sync_nmi(). There is no reason to keep it as a separate exported function in iwl-io.c, so embed its body directly in the caller and drop the now-unused declaration. Link: https://patch.msgid.link/20260926201527.a2048732f45f.I23611eb40d875c6a69df0c08add3834f6f7d8528@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 36 ------------------- .../net/wireless/intel/iwlwifi/iwl-trans.c | 5 --- .../net/wireless/intel/iwlwifi/iwl-trans.h | 5 --- .../net/wireless/intel/iwlwifi/pcie/trans.c | 33 +++++++++++++++-- 4 files changed, 31 insertions(+), 48 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index 544b8e686dfe..ef4d97ef0b1b 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -233,39 +233,3 @@ void iwl_force_nmi(struct iwl_trans *trans) UREG_DOORBELL_TO_ISR6_NMI_BIT); } IWL_EXPORT_SYMBOL(iwl_force_nmi); - -void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr, - u32 sw_err_bit) -{ - unsigned long timeout = jiffies + IWL_TRANS_NMI_TIMEOUT; - bool interrupts_enabled = test_bit(STATUS_INT_ENABLED, &trans->status); - - /* if the interrupts were already disabled, there is no point in - * calling iwl_disable_interrupts - */ - if (interrupts_enabled) - iwl_trans_interrupts(trans, false); - - iwl_force_nmi(trans); - while (time_after(timeout, jiffies)) { - u32 inta_hw = iwl_read32(trans, inta_addr); - - /* Error detected by uCode */ - if (inta_hw & sw_err_bit) { - /* Clear causes register */ - iwl_write32(trans, inta_addr, inta_hw & sw_err_bit); - break; - } - - mdelay(1); - } - - /* enable interrupts only if there were already enabled before this - * function to avoid a case were the driver enable interrupts before - * proper configurations were made - */ - if (interrupts_enabled) - iwl_trans_interrupts(trans, true); - - iwl_trans_fw_error(trans, IWL_ERR_TYPE_NMI_FORCED); -} diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 24bf45f06746..ad43cf53e8c5 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -523,11 +523,6 @@ int iwl_trans_d3_resume(struct iwl_trans *trans, bool reset) } IWL_EXPORT_SYMBOL(iwl_trans_d3_resume); -void iwl_trans_interrupts(struct iwl_trans *trans, bool enable) -{ - iwl_trans_pci_interrupts(trans, enable); -} - void iwl_trans_sync_nmi(struct iwl_trans *trans) { iwl_trans_pcie_sync_nmi(trans); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index dfad839dd2e6..f933cba7eee8 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -1055,9 +1055,6 @@ static inline bool iwl_trans_fw_running(struct iwl_trans *trans) void iwl_trans_sync_nmi(struct iwl_trans *trans); -void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr, - u32 sw_err_bit); - int iwl_trans_load_pnvm(struct iwl_trans *trans, const struct iwl_pnvm_image *pnvm_data, const struct iwl_ucode_capabilities *capa); @@ -1078,8 +1075,6 @@ static inline bool iwl_trans_dbg_ini_valid(struct iwl_trans *trans) trans->dbg.external_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED; } -void iwl_trans_interrupts(struct iwl_trans *trans, bool enable); - int iwl_trans_activate_nic(struct iwl_trans *trans); static inline void iwl_trans_finish_sw_reset(struct iwl_trans *trans) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 97bbc3faa98c..48ae2440cfe1 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -3574,8 +3574,10 @@ void iwl_trans_pci_interrupts(struct iwl_trans *trans, bool enable) void iwl_trans_pcie_sync_nmi(struct iwl_trans *trans) { - u32 inta_addr, sw_err_bit; + bool interrupts_enabled = test_bit(STATUS_INT_ENABLED, &trans->status); struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + unsigned long timeout = jiffies + IWL_TRANS_NMI_TIMEOUT; + u32 inta_addr, sw_err_bit; if (trans_pcie->msix_enabled) { inta_addr = CSR_MSIX_HW_INT_CAUSES_AD; @@ -3588,7 +3590,34 @@ void iwl_trans_pcie_sync_nmi(struct iwl_trans *trans) sw_err_bit = CSR_INT_BIT_SW_ERR; } - iwl_trans_sync_nmi_with_addr(trans, inta_addr, sw_err_bit); + /* if the interrupts were already disabled, there is no point in + * calling iwl_disable_interrupts + */ + if (interrupts_enabled) + iwl_trans_pci_interrupts(trans, false); + + iwl_force_nmi(trans); + while (time_after(timeout, jiffies)) { + u32 inta_hw = iwl_read32(trans, inta_addr); + + /* Error detected by uCode */ + if (inta_hw & sw_err_bit) { + /* Clear causes register */ + iwl_write32(trans, inta_addr, inta_hw & sw_err_bit); + break; + } + + mdelay(1); + } + + /* enable interrupts only if there were already enabled before this + * function to avoid a case were the driver enable interrupts before + * proper configurations were made + */ + if (interrupts_enabled) + iwl_trans_pci_interrupts(trans, true); + + iwl_trans_fw_error(trans, IWL_ERR_TYPE_NMI_FORCED); } static int iwl_trans_pcie_alloc_txcmd_pool(struct iwl_trans *trans) From a1cbc81c1278dac51fddc938bfbb4e5e724d59bd Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:30 +0300 Subject: [PATCH 1580/2126] wifi: iwlwifi: move iwl_force_nmi() to where it belongs iwl_force_nmi() forces a firmware NMI and has nothing to do with the register I/O helpers in iwl-io.c. Move it to iwl-trans.c and rename it to iwl_trans_force_nmi() to match the transport API naming. Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260926201527.c3312fb2f2cc.Ie0d3ea9b23e35d7ff4b67e129c7b97ccb7c6c453@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 5 +++-- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 18 ------------------ drivers/net/wireless/intel/iwlwifi/iwl-io.h | 1 - drivers/net/wireless/intel/iwlwifi/iwl-trans.c | 18 ++++++++++++++++++ drivers/net/wireless/intel/iwlwifi/iwl-trans.h | 2 ++ .../net/wireless/intel/iwlwifi/mld/debugfs.c | 2 +- .../net/wireless/intel/iwlwifi/mvm/debugfs.c | 2 +- .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 4 ++-- drivers/net/wireless/intel/iwlwifi/mvm/scan.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/trans.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 4 ++-- 12 files changed, 32 insertions(+), 30 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 8c8d15ac71ac..897538066b7d 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -2055,7 +2055,7 @@ int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt, if (trigger->flags & IWL_FW_DBG_FORCE_RESTART) { IWL_WARN(fwrt, "Force restart: trigger %d fired.\n", trig); - iwl_force_nmi(fwrt->trans); + iwl_trans_force_nmi(fwrt->trans); return 0; } @@ -2233,7 +2233,8 @@ static void iwl_fw_dbg_collect_sync(struct iwl_fw_runtime *fwrt, u8 wk_idx) } if (fwrt->trans->dbg.last_tp_resetfw == IWL_FW_INI_RESET_FW_MODE_STOP_FW_ONLY) - iwl_force_nmi(fwrt->trans); + iwl_trans_force_nmi(fwrt->trans); + out: if (iwl_trans_dbg_ini_valid(fwrt->trans)) { iwl_fw_error_dump_data_free(dump_data); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index ef4d97ef0b1b..cc6bf4ea5055 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -10,7 +10,6 @@ #include "iwl-io.h" #include "iwl-csr.h" #include "iwl-debug.h" -#include "iwl-prph.h" void iwl_write8(struct iwl_trans *trans, u32 ofs, u8 val) { @@ -216,20 +215,3 @@ void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) } } IWL_EXPORT_SYMBOL(iwl_clear_bits_prph); - -void iwl_force_nmi(struct iwl_trans *trans) -{ - if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_9000) - iwl_write_prph_delay(trans, DEVICE_SET_NMI_REG, - DEVICE_SET_NMI_VAL_DRV, 1); - else if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) - iwl_write_umac_prph(trans, UREG_NIC_SET_NMI_DRIVER, - UREG_NIC_SET_NMI_DRIVER_NMI_FROM_DRIVER); - else if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_BZ) - iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, - UREG_DOORBELL_TO_ISR6_NMI_BIT); - else - iwl_write32(trans, CSR_DOORBELL_VECTOR, - UREG_DOORBELL_TO_ISR6_NMI_BIT); -} -IWL_EXPORT_SYMBOL(iwl_force_nmi); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h index e66b0c2a0467..e4a9f2ba0de9 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.h @@ -57,7 +57,6 @@ void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, u32 bits, u32 mask); void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); -void iwl_force_nmi(struct iwl_trans *trans); /* * UMAC periphery address space changed from 0xA00000 to 0xD00000 starting from diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index ad43cf53e8c5..efe657857772 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -10,6 +10,7 @@ #include "iwl-trans.h" #include "iwl-drv.h" +#include "iwl-prph.h" #include #include "fw/api/commands.h" #include "pcie/internal.h" @@ -452,6 +453,23 @@ void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) return iwl_trans_pcie_write_prph(trans, ofs, val); } +void iwl_trans_force_nmi(struct iwl_trans *trans) +{ + if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_9000) + iwl_write_prph_delay(trans, DEVICE_SET_NMI_REG, + DEVICE_SET_NMI_VAL_DRV, 1); + else if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) + iwl_write_umac_prph(trans, UREG_NIC_SET_NMI_DRIVER, + UREG_NIC_SET_NMI_DRIVER_NMI_FROM_DRIVER); + else if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_BZ) + iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, + UREG_DOORBELL_TO_ISR6_NMI_BIT); + else + iwl_write32(trans, CSR_DOORBELL_VECTOR, + UREG_DOORBELL_TO_ISR6_NMI_BIT); +} +IWL_EXPORT_SYMBOL(iwl_trans_force_nmi); + int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr, void *buf, int dwords) { diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index f933cba7eee8..a7bb6cee8188 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -1055,6 +1055,8 @@ static inline bool iwl_trans_fw_running(struct iwl_trans *trans) void iwl_trans_sync_nmi(struct iwl_trans *trans); +void iwl_trans_force_nmi(struct iwl_trans *trans); + int iwl_trans_load_pnvm(struct iwl_trans *trans, const struct iwl_pnvm_image *pnvm_data, const struct iwl_ucode_capabilities *capa); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c index 351a4f177e92..dd4bf7cb6a79 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c @@ -69,7 +69,7 @@ static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mld *mld, char *buf, if (count == 6 && !strcmp(buf, "nolog\n")) mld->fw_status.do_not_dump_once = true; - iwl_force_nmi(mld->trans); + iwl_trans_force_nmi(mld->trans); return count; } diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c index 4db0f29dd21a..06502f57e823 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c @@ -1102,7 +1102,7 @@ static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf, if (count == 6 && !strcmp(buf, "nolog\n")) set_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE, &mvm->status); - iwl_force_nmi(mvm->trans); + iwl_trans_force_nmi(mvm->trans); return count; } diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c index 5bd246e37943..a4f3d3c2bd35 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c @@ -5258,7 +5258,7 @@ out_reassign: out_restart: /* things keep failing, better restart the hw */ - iwl_force_nmi(mvm->trans); + iwl_trans_force_nmi(mvm->trans); return ret; } @@ -5294,7 +5294,7 @@ out_reassign: out_restart: /* things keep failing, better restart the hw */ - iwl_force_nmi(mvm->trans); + iwl_trans_force_nmi(mvm->trans); return ret; } diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c index 817c6dacfacc..a94eaca0b3ed 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c @@ -2703,7 +2703,7 @@ void iwl_mvm_scan_timeout_wk(struct work_struct *work) IWL_ERR(mvm, "regular scan timed out\n"); - iwl_force_nmi(mvm->trans); + iwl_trans_force_nmi(mvm->trans); } static void iwl_mvm_fill_scan_type(struct iwl_mvm *mvm, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index d1ef0365b932..db3933b0d197 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -1493,7 +1493,7 @@ static struct iwl_rx_mem_buffer *iwl_pcie_get_rxb(struct iwl_trans *trans, out_err: WARN(1, "Invalid rxb from HW %u\n", (u32)vid); - iwl_force_nmi(trans); + iwl_trans_force_nmi(trans); return NULL; } diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 48ae2440cfe1..1304d8916424 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -3596,7 +3596,7 @@ void iwl_trans_pcie_sync_nmi(struct iwl_trans *trans) if (interrupts_enabled) iwl_trans_pci_interrupts(trans, false); - iwl_force_nmi(trans); + iwl_trans_force_nmi(trans); while (time_after(timeout, jiffies)) { u32 inta_hw = iwl_read32(trans, inta_addr); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index 26d1530cfa37..496435ea93ee 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -715,7 +715,7 @@ static void iwl_txq_stuck_timer(struct timer_list *t) iwl_txq_log_scd_error(trans, txq); - iwl_force_nmi(trans); + iwl_trans_force_nmi(trans); } int iwl_pcie_txq_alloc(struct iwl_trans *trans, struct iwl_txq *txq, @@ -1105,7 +1105,7 @@ static void iwl_pcie_cmdq_reclaim(struct iwl_trans *trans, int txq_id, int idx) if (nfreed++ > 0) { IWL_ERR(trans, "HCMD skipped: index (%d) %d %d\n", idx, txq->write_ptr, r); - iwl_force_nmi(trans); + iwl_trans_force_nmi(trans); } } From 38e3a2e9936f7967643f6ef328ebb3ceb2807877 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Sat, 26 Sep 2026 20:17:31 +0300 Subject: [PATCH 1581/2126] wifi: iwlwifi: add support for the new MPDU descriptor The firmware now reports in DW-12 bits 31:24 the RU/MRU/DRU that was used for the received frame, in trigger-like format. The MAC context byte moved to bits 31:24 of DW-10. It isn't used by the driver, so just follow the new layout. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260926201527.cf236c23d1aa.Ie2d919c884f7db8cd76b4cb6a9f4584eb285eea5@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/rx.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h b/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h index a8f1edf19bbe..20460534fc99 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h @@ -583,7 +583,11 @@ struct iwl_rx_mpdu_desc_v3 { /** * @reserved_xsum: reserved high bits in the raw checksum */ - __le16 reserved_xsum; + u8 reserved_xsum; + /** + * @mac_context: MAC context mask, in this DW only from API version 10 + */ + u8 mac_context; /* DW11 */ /** * @rate_n_flags: RX rate/flags encoding @@ -603,9 +607,10 @@ struct iwl_rx_mpdu_desc_v3 { */ u8 channel; /** - * @mac_context: MAC context mask + * @ru: RU/MRU/DRU used for the frame, in trigger-like format; + * only from API version 10, this byte held @mac_context before */ - u8 mac_context; + u8 ru; /* DW13 */ /** * @gp2_on_air_rise: GP2 timer value on air rise (INA) @@ -647,7 +652,11 @@ struct iwl_rx_mpdu_desc_v3 { __le32 reserved[1]; } __packed; /* RX_MPDU_RES_START_API_S_VER_3, * RX_MPDU_RES_START_API_S_VER_5, - * RX_MPDU_RES_START_API_S_VER_6 + * RX_MPDU_RES_START_API_S_VER_6, + * RX_MPDU_RES_START_API_S_VER_7, + * RX_MPDU_RES_START_API_S_VER_8, + * RX_MPDU_RES_START_API_S_VER_9, + * RX_MPDU_RES_START_API_S_VER_10 */ /** @@ -737,6 +746,8 @@ struct iwl_rx_mpdu_desc { * RX_MPDU_RES_START_API_S_VER_6 * RX_MPDU_RES_START_API_S_VER_7 * RX_MPDU_RES_START_API_S_VER_8 + * RX_MPDU_RES_START_API_S_VER_9 + * RX_MPDU_RES_START_API_S_VER_10 */ #define IWL_RX_DESC_SIZE_V1 offsetofend(struct iwl_rx_mpdu_desc, v1) From 60cce59decdaff868484a5f91b0d71f8e630131b Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Sat, 26 Sep 2026 20:17:32 +0300 Subject: [PATCH 1582/2126] wifi: iwlwifi: support RX BAID modify command version 3 Version 3 of the RX BAID allocation modify command shrinks the tid field to a u8 and adds a window size field, so that the window size can be updated while moving a BAID to a new AP. A window size of 0 tells the firmware to keep the current one, which is what we need for now. Add the new layout and pick it based on the command version. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260926201527.46c77de75c0b.Ie41b1d43f945a0c5e2bb68981a0cec0c62111233@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/fw/api/datapath.h | 29 +++++++++++++++---- drivers/net/wireless/intel/iwlwifi/mld/agg.c | 7 ++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h b/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h index b17babef71c0..3fbcb2e4bfe0 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h @@ -522,17 +522,34 @@ struct iwl_rx_baid_cfg_cmd_alloc { } __packed; /* RX_BAID_ALLOCATION_ADD_CMD_API_S_VER_1 */ /** - * struct iwl_rx_baid_cfg_cmd_modify - BAID modification data + * struct iwl_rx_baid_cfg_cmd_modify_v2 - BAID modification data * @old_sta_id_mask: old station ID mask * @new_sta_id_mask: new station ID mask * @tid: TID of the BAID */ -struct iwl_rx_baid_cfg_cmd_modify { +struct iwl_rx_baid_cfg_cmd_modify_v2 { __le32 old_sta_id_mask; __le32 new_sta_id_mask; __le32 tid; } __packed; /* RX_BAID_ALLOCATION_MODIFY_CMD_API_S_VER_2 */ +/** + * struct iwl_rx_baid_cfg_cmd_modify - BAID modification data + * @old_sta_id_mask: old station ID mask + * @new_sta_id_mask: new station ID mask + * @tid: TID of the BAID + * @reserved: reserved + * @win_size: RX BA session window size to apply to the modified BAID, + * 0 means keep the current one + */ +struct iwl_rx_baid_cfg_cmd_modify { + __le32 old_sta_id_mask; + __le32 new_sta_id_mask; + u8 tid; + u8 reserved; + __le16 win_size; +} __packed; /* RX_BAID_ALLOCATION_MODIFY_CMD_API_S_VER_3 */ + /** * struct iwl_rx_baid_cfg_cmd_remove_v1 - BAID removal data * @baid: the BAID to remove @@ -555,7 +572,8 @@ struct iwl_rx_baid_cfg_cmd_remove { * struct iwl_rx_baid_cfg_cmd - BAID allocation/config command * @action: the action, from &enum iwl_rx_baid_action * @alloc: allocation data - * @modify: modify data + * @modify_v2: modify data (version 2) + * @modify: modify data (version 3) * @remove_v1: remove data (version 1) * @remove: remove data */ @@ -563,11 +581,12 @@ struct iwl_rx_baid_cfg_cmd { __le32 action; union { struct iwl_rx_baid_cfg_cmd_alloc alloc; + struct iwl_rx_baid_cfg_cmd_modify_v2 modify_v2; struct iwl_rx_baid_cfg_cmd_modify modify; struct iwl_rx_baid_cfg_cmd_remove_v1 remove_v1; struct iwl_rx_baid_cfg_cmd_remove remove; - }; /* RX_BAID_ALLOCATION_OPERATION_API_U_VER_2 */ -} __packed; /* RX_BAID_ALLOCATION_CONFIG_CMD_API_S_VER_2 */ + }; /* RX_BAID_ALLOCATION_OPERATION_API_U_VER_3 */ +} __packed; /* RX_BAID_ALLOCATION_CONFIG_CMD_API_S_VER_3 */ /** * struct iwl_rx_baid_cfg_resp - BAID allocation response diff --git a/drivers/net/wireless/intel/iwlwifi/mld/agg.c b/drivers/net/wireless/intel/iwlwifi/mld/agg.c index c45c47337509..ea1f02380ad4 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/agg.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/agg.c @@ -660,6 +660,7 @@ int iwl_mld_update_sta_baids(struct iwl_mld *mld, .modify.new_sta_id_mask = cpu_to_le32(new_sta_mask), }; u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, RX_BAID_ALLOCATION_CONFIG_CMD); + u8 cmd_ver = iwl_fw_lookup_cmd_ver(mld->fw, cmd_id, 2); int baid; /* mac80211 will remove sessions later, but we ignore all that */ @@ -667,6 +668,7 @@ int iwl_mld_update_sta_baids(struct iwl_mld *mld, return 0; BUILD_BUG_ON(sizeof(struct iwl_rx_baid_cfg_resp) != sizeof(baid)); + BUILD_BUG_ON(sizeof(cmd.modify) != sizeof(cmd.modify_v2)); for (baid = 0; baid < ARRAY_SIZE(mld->fw_id_to_ba); baid++) { struct iwl_mld_baid_data *data; @@ -683,7 +685,10 @@ int iwl_mld_update_sta_baids(struct iwl_mld *mld, "BAID data for %d corrupted - expected 0x%x found 0x%x\n", baid, old_sta_mask, data->sta_mask); - cmd.modify.tid = cpu_to_le32(data->tid); + if (cmd_ver >= 3) + cmd.modify.tid = data->tid; + else + cmd.modify_v2.tid = cpu_to_le32(data->tid); ret = iwl_mld_send_cmd_pdu(mld, cmd_id, &cmd); if (ret) From f7357ab44fe8f001705a604db48a2843dd8f12f7 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sat, 26 Sep 2026 20:17:33 +0300 Subject: [PATCH 1583/2126] wifi: iwlwifi: drop the orphaned nic_access annotations commit 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support") deleted the Sparse implementation of the lock annotations. __acquires()/__releases()/__acquire()/__release() are gone; the macros now only map onto clang's context analysis and expand to nothing for gcc. The nic_access annotations describe nothing anymore: - Every one of them is a __releases() with no matching __acquires(). The acquire side was the __cond_lock() wrapper around _iwl_trans_grab_nic_access(), which went away together with __cond_lock() itself. The names don't even agree - PCIe releases nic_access_nobh while the generic wrapper calling it claims nic_access. - The __acquire()/__release(reg_lock) pairs only existed to silence Sparse Use lockdep_assert_held() instead, which unlike the annotations actually runs, and add the missing assertion to iwl_trans_pcie_resched_with_nic_access(). Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260926201527.f818a7e09def.Iccecaabe0f37525430377ae1c0db6fd7bbf7625a@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-trans.c | 3 +-- drivers/net/wireless/intel/iwlwifi/iwl-trans.h | 3 +-- .../net/wireless/intel/iwlwifi/pcie/internal.h | 3 +-- .../net/wireless/intel/iwlwifi/pcie/trans.c | 18 ++++++------------ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index efe657857772..0a6b7b264aa2 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -576,8 +576,7 @@ void iwl_trans_resched_with_nic_access(struct iwl_trans *trans) iwl_trans_pcie_resched_with_nic_access(trans); } -void __releases(nic_access) -iwl_trans_release_nic_access(struct iwl_trans *trans) +void iwl_trans_release_nic_access(struct iwl_trans *trans) { iwl_trans_pcie_release_nic_access(trans); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index a7bb6cee8188..56c5e61b614a 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -992,8 +992,7 @@ bool iwl_trans_grab_nic_access(struct iwl_trans *trans); */ void iwl_trans_resched_with_nic_access(struct iwl_trans *trans); -void __releases(nic_access) -iwl_trans_release_nic_access(struct iwl_trans *trans); +void iwl_trans_release_nic_access(struct iwl_trans *trans); static inline void iwl_trans_schedule_reset(struct iwl_trans *trans, enum iwl_fw_error_type type) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index e10aa8e7e061..e6b1cb559a0a 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -1161,8 +1161,7 @@ int iwl_trans_pcie_read_config32(struct iwl_trans *trans, u32 ofs, u32 *val); bool iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans); void iwl_trans_pcie_resched_with_nic_access(struct iwl_trans *trans); -void __releases(nic_access_nobh) -iwl_trans_pcie_release_nic_access(struct iwl_trans *trans); +void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans); void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans, u8 max_power); int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, const struct iwl_mac_cfg *mac_cfg, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 1304d8916424..bda069a6f7eb 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -2402,10 +2402,10 @@ bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) out: /* - * Fool sparse by faking we release the lock - sparse will - * track nic_access anyway. + * Deliberately return with reg_lock held; the caller must drop it via + * iwl_trans_pcie_release_nic_access(), or explicitly if it wants to + * keep the NIC awake past the critical section (cmd_hold_nic_awake). */ - __release(&trans_pcie->reg_lock); return true; } @@ -2427,24 +2427,19 @@ void iwl_trans_pcie_resched_with_nic_access(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + lockdep_assert_held(&trans_pcie->reg_lock); + spin_unlock_bh(&trans_pcie->reg_lock); cond_resched(); spin_lock_bh(&trans_pcie->reg_lock); } -void __releases(nic_access_nobh) -iwl_trans_pcie_release_nic_access(struct iwl_trans *trans) +void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); lockdep_assert_held(&trans_pcie->reg_lock); - /* - * Fool sparse by faking we acquiring the lock - sparse will - * track nic_access anyway. - */ - __acquire(&trans_pcie->reg_lock); - if (trans_pcie->cmd_hold_nic_awake) goto out; if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) @@ -2460,7 +2455,6 @@ iwl_trans_pcie_release_nic_access(struct iwl_trans *trans) * scheduled on different CPUs (after we drop reg_lock). */ out: - __release(nic_access_nobh); spin_unlock_bh(&trans_pcie->reg_lock); } From 7964121c8691f3b0f890c9f3d6be35fb77998bc0 Mon Sep 17 00:00:00 2001 From: Shahar Tzarfati Date: Sat, 26 Sep 2026 20:17:34 +0300 Subject: [PATCH 1584/2126] wifi: iwlwifi: disable HE ER mode HE ER mode (~3 Mbps) provides marginal range benefit over legacy rates, while effective coverage remains constrained by beacon reception. In addition, ~3 Mbps is insufficient for laptop connectivity. Furthermore, any range benefit in 5 and 6 GHz is more easily achieved by roaming to 2.4 GHz, while avoiding degrading 5 and 6 GHz aggregate network capacity with low-rate links. Therefore, disable HE ER mode. Signed-off-by: Shahar Tzarfati Link: https://patch.msgid.link/20260926201527.aac48f46b60e.I5dcf9ed88b2b73bc09c81c0d9c841dc624447faf@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index 6bb27d7f1166..413dd55115f8 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -612,7 +612,6 @@ static const struct ieee80211_sband_iftype_data iwl_iftype_cap[] = { IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI, .phy_cap_info[8] = - IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU | @@ -747,7 +746,6 @@ static const struct ieee80211_sband_iftype_data iwl_iftype_cap[] = { .phy_cap_info[7] = IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI, .phy_cap_info[8] = - IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_242, .phy_cap_info[9] = IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | From 80f864fa6fa793d60a5a930bd3830243cb6d6e2e Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:38 +0300 Subject: [PATCH 1585/2126] wifi: iwlwifi: add _no_grab postfix to some functions A function that accesses the nic memory without grabbing nic access first, needs to have a _no_grab postfix. It makes it clear to the caller that he is responsible for grabbing it. Add it to iwl_trans_write_prph and iwl_trans_pcie_write_prph as well. Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.68337f23f322.I38ed9c92bf6358158974b0af025d8bf8fdd7e4f5@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/dbg-old.c | 32 +++++++++---------- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 20 ++++++------ .../net/wireless/intel/iwlwifi/iwl-dbg-tlv.c | 2 +- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 2 +- .../net/wireless/intel/iwlwifi/iwl-trans.c | 4 +-- .../net/wireless/intel/iwlwifi/iwl-trans.h | 2 +- .../wireless/intel/iwlwifi/pcie/internal.h | 2 +- .../net/wireless/intel/iwlwifi/pcie/trans.c | 2 +- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c index 19b1bfd0abee..a4e1f82c8bd1 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c @@ -47,7 +47,7 @@ static void iwl_read_radio_regs(struct iwl_fw_runtime *fwrt, u32 rd_cmd = RADIO_RSP_RD_CMD; rd_cmd |= i << RADIO_RSP_ADDR_POS; - iwl_trans_write_prph(fwrt->trans, RSP_RADIO_CMD, rd_cmd); + iwl_trans_write_prph_no_grab(fwrt->trans, RSP_RADIO_CMD, rd_cmd); *pos = (u8)iwl_trans_read_prph(fwrt->trans, RSP_RADIO_RDDAT); pos++; @@ -97,12 +97,12 @@ static void iwl_fwrt_dump_rxf(struct iwl_fw_runtime *fwrt, RXF_SET_FENCE_MODE + offset)); /* Lock fence */ - iwl_trans_write_prph(fwrt->trans, RXF_SET_FENCE_MODE + offset, 0x1); + iwl_trans_write_prph_no_grab(fwrt->trans, RXF_SET_FENCE_MODE + offset, 0x1); /* Set fence pointer to the same place like WR pointer */ - iwl_trans_write_prph(fwrt->trans, RXF_LD_WR2FENCE + offset, 0x1); + iwl_trans_write_prph_no_grab(fwrt->trans, RXF_LD_WR2FENCE + offset, 0x1); /* Set fence offset */ - iwl_trans_write_prph(fwrt->trans, - RXF_LD_FENCE_OFFSET_ADDR + offset, 0x0); + iwl_trans_write_prph_no_grab(fwrt->trans, + RXF_LD_FENCE_OFFSET_ADDR + offset, 0x0); /* Read FIFO */ fifo_len /= sizeof(u32); /* Size in DWORDS */ @@ -152,8 +152,8 @@ static void iwl_fwrt_dump_txf(struct iwl_fw_runtime *fwrt, TXF_LOCK_FENCE + offset)); /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */ - iwl_trans_write_prph(fwrt->trans, TXF_READ_MODIFY_ADDR + offset, - TXF_WR_PTR + offset); + iwl_trans_write_prph_no_grab(fwrt->trans, TXF_READ_MODIFY_ADDR + offset, + TXF_WR_PTR + offset); /* Dummy-read to advance the read pointer to the head */ iwl_trans_read_prph(fwrt->trans, TXF_READ_MODIFY_DATA + offset); @@ -217,7 +217,7 @@ static void iwl_fw_dump_txf(struct iwl_fw_runtime *fwrt, /* Pull TXF data from LMAC1 */ for (i = 0; i < fwrt->smem_cfg.num_txfifo_entries; i++) { /* Mark the number of TXF we're pulling now */ - iwl_trans_write_prph(fwrt->trans, TXF_LARC_NUM, i); + iwl_trans_write_prph_no_grab(fwrt->trans, TXF_LARC_NUM, i); iwl_fwrt_dump_txf(fwrt, dump_data, cfg->lmac[0].txfifo_size[i], 0, i); } @@ -227,9 +227,9 @@ static void iwl_fw_dump_txf(struct iwl_fw_runtime *fwrt, for (i = 0; i < fwrt->smem_cfg.num_txfifo_entries; i++) { /* Mark the number of TXF we're pulling now */ - iwl_trans_write_prph(fwrt->trans, - TXF_LARC_NUM + - LMAC2_PRPH_OFFSET, i); + iwl_trans_write_prph_no_grab(fwrt->trans, + TXF_LARC_NUM + + LMAC2_PRPH_OFFSET, i); iwl_fwrt_dump_txf(fwrt, dump_data, cfg->lmac[1].txfifo_size[i], LMAC2_PRPH_OFFSET, @@ -262,8 +262,8 @@ static void iwl_fw_dump_txf(struct iwl_fw_runtime *fwrt, fifo_hdr->fifo_num = cpu_to_le32(i); /* Mark the number of TXF we're pulling now */ - iwl_trans_write_prph(fwrt->trans, TXF_CPU2_NUM, i + - fwrt->smem_cfg.num_txfifo_entries); + iwl_trans_write_prph_no_grab(fwrt->trans, TXF_CPU2_NUM, i + + fwrt->smem_cfg.num_txfifo_entries); fifo_hdr->available_bytes = cpu_to_le32(iwl_trans_read_prph(fwrt->trans, @@ -282,9 +282,9 @@ static void iwl_fw_dump_txf(struct iwl_fw_runtime *fwrt, TXF_CPU2_LOCK_FENCE)); /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */ - iwl_trans_write_prph(fwrt->trans, - TXF_CPU2_READ_MODIFY_ADDR, - TXF_CPU2_WR_PTR); + iwl_trans_write_prph_no_grab(fwrt->trans, + TXF_CPU2_READ_MODIFY_ADDR, + TXF_CPU2_WR_PTR); /* Dummy-read to advance the read pointer to head */ iwl_trans_read_prph(fwrt->trans, diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 897538066b7d..8d08ce7db3b9 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -169,8 +169,8 @@ static int iwl_dump_ini_prph_phy_iter_common(struct iwl_fw_runtime *fwrt, continue; } - iwl_trans_write_prph(fwrt->trans, indirect_wr_addr, - WMAL_INDRCT_CMD(addr + i)); + iwl_trans_write_prph_no_grab(fwrt->trans, indirect_wr_addr, + WMAL_INDRCT_CMD(addr + i)); if (fwrt->trans->info.hw_rf_id != IWL_CFG_RF_TYPE_JF1 && fwrt->trans->info.hw_rf_id != IWL_CFG_RF_TYPE_JF2 && @@ -446,7 +446,7 @@ static int iwl_dump_ini_txf_iter(struct iwl_fw_runtime *fwrt, range->fifo_hdr.num_of_registers = cpu_to_le32(registers_num); range->range_data_size = cpu_to_le32(iter->fifo_size + registers_size); - iwl_trans_write_prph(fwrt->trans, TXF_LARC_NUM + offs, iter->fifo); + iwl_trans_write_prph_no_grab(fwrt->trans, TXF_LARC_NUM + offs, iter->fifo); /* * read txf registers. for each register, write to the dump the @@ -468,8 +468,8 @@ static int iwl_dump_ini_txf_iter(struct iwl_fw_runtime *fwrt, } /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */ - iwl_trans_write_prph(fwrt->trans, TXF_READ_MODIFY_ADDR + offs, - TXF_WR_PTR + offs); + iwl_trans_write_prph_no_grab(fwrt->trans, TXF_READ_MODIFY_ADDR + offs, + TXF_WR_PTR + offs); /* Dummy-read to advance the read pointer to the head */ iwl_trans_read_prph(fwrt->trans, TXF_READ_MODIFY_DATA + offs); @@ -518,8 +518,8 @@ iwl_dump_ini_prph_snps_dphyip_iter(struct iwl_fw_runtime *fwrt, continue; } - iwl_trans_write_prph(fwrt->trans, indirect_rd_wr_addr, - addr + i); + iwl_trans_write_prph_no_grab(fwrt->trans, indirect_rd_wr_addr, + addr + i); /* wait a bit for value to be ready in register */ udelay(1); prph_val = iwl_trans_read_prph(fwrt->trans, @@ -642,11 +642,11 @@ static int iwl_dump_ini_rxf_iter(struct iwl_fw_runtime *fwrt, offs = rxf_data.offset; /* Lock fence */ - iwl_trans_write_prph(fwrt->trans, RXF_SET_FENCE_MODE + offs, 0x1); + iwl_trans_write_prph_no_grab(fwrt->trans, RXF_SET_FENCE_MODE + offs, 0x1); /* Set fence pointer to the same place like WR pointer */ - iwl_trans_write_prph(fwrt->trans, RXF_LD_WR2FENCE + offs, 0x1); + iwl_trans_write_prph_no_grab(fwrt->trans, RXF_LD_WR2FENCE + offs, 0x1); /* Set fence offset */ - iwl_trans_write_prph(fwrt->trans, RXF_LD_FENCE_OFFSET_ADDR + offs, 0x0); + iwl_trans_write_prph_no_grab(fwrt->trans, RXF_LD_FENCE_OFFSET_ADDR + offs, 0x0); /* Read FIFO */ addr = RXF_FIFO_RD_FENCE_INC + offs; diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c index 4372a171172b..5aca343372d5 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c @@ -912,7 +912,7 @@ static void iwl_dbg_tlv_apply_config(struct iwl_fw_runtime *fwrt, for (count = 0; count < len; count++) { address = le32_to_cpu(config_list->addr_val[count].address); value = le32_to_cpu(config_list->addr_val[count].value); - iwl_trans_write_prph(fwrt->trans, address + offset, value); + iwl_trans_write_prph_no_grab(fwrt->trans, address + offset, value); } iwl_trans_release_nic_access(fwrt->trans); break; diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index cc6bf4ea5055..5ce046e3fa5c 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -115,7 +115,7 @@ u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) { trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val); - iwl_trans_write_prph(trans, ofs, val); + iwl_trans_write_prph_no_grab(trans, ofs, val); } void iwl_write_prph64_no_grab(struct iwl_trans *trans, u64 ofs, u64 val) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 0a6b7b264aa2..1c593fd29d02 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -448,9 +448,9 @@ u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) return iwl_trans_pcie_read_prph(trans, ofs); } -void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) +void iwl_trans_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) { - return iwl_trans_pcie_write_prph(trans, ofs, val); + return iwl_pcie_write_prph_no_grab(trans, ofs, val); } void iwl_trans_force_nmi(struct iwl_trans *trans) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index 56c5e61b614a..c59b935ce4bf 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -918,7 +918,7 @@ u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs); u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs); -void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val); +void iwl_trans_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val); int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr, void *buf, int dwords); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index e6b1cb559a0a..550c5c23a52e 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -1140,7 +1140,7 @@ void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val); void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val); u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs); u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg); -void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr, u32 val); +void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val); int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr, void *buf, int dwords); int iwl_trans_pcie_read_mem_no_grab(struct iwl_trans *trans, u32 addr, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index bda069a6f7eb..3d1cc49effb4 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -1894,7 +1894,7 @@ u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg) return iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT); } -void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr, u32 val) +void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val) { u32 mask = iwl_trans_pcie_prph_msk(trans); From b4f714ea8feba4948e39c72610b2b185651a1144 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:39 +0300 Subject: [PATCH 1586/2126] wifi: iwlwifi: move pcie-only functions to pcie There are several helpers that exported to the opmodes but are really only called from the pcie transport. Define those functions there. No functional change intended. Assisted-by: GitHubCopilot:claude-opus-4.8 Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.480246f9b623.I88de3ad2bbd8a8444ff2a154f7eb1f08ecb7b7ea@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-csr.h | 3 +- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 89 ------------------- drivers/net/wireless/intel/iwlwifi/iwl-io.h | 26 ------ .../net/wireless/intel/iwlwifi/iwl-trans.c | 5 -- .../net/wireless/intel/iwlwifi/iwl-trans.h | 2 - .../intel/iwlwifi/pcie/ctxt-info-v2.c | 5 +- .../wireless/intel/iwlwifi/pcie/ctxt-info.c | 3 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 47 +++++----- .../net/wireless/intel/iwlwifi/pcie/trans.c | 33 +++---- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 10 +-- .../net/wireless/intel/iwlwifi/pcie/utils.c | 87 +++++++++++++++++- .../net/wireless/intel/iwlwifi/pcie/utils.h | 28 +++++- 12 files changed, 166 insertions(+), 172 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-csr.h b/drivers/net/wireless/intel/iwlwifi/iwl-csr.h index d2fa80a3dd04..ba14e583a4ad 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-csr.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-csr.h @@ -501,7 +501,8 @@ enum { * to indirectly access device's internal memory or registers that * may be powered-down. * - * Use iwl_write_direct32()/iwl_read_direct32() family for these registers; + * Use iwl_write_direct32() family for writing to these registers; + * A read operation doesn't exist, can be added if needed. * host must "grab nic access" via CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ * to make sure the MAC (uCode processor, etc.) is powered up for accessing * internal resources. diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index 5ce046e3fa5c..297f4550ae72 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -11,13 +11,6 @@ #include "iwl-csr.h" #include "iwl-debug.h" -void iwl_write8(struct iwl_trans *trans, u32 ofs, u8 val) -{ - trace_iwlwifi_dev_iowrite8(trans->dev, ofs, val); - iwl_trans_write8(trans, ofs, val); -} -IWL_EXPORT_SYMBOL(iwl_write8); - void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val) { trace_iwlwifi_dev_iowrite32(trans->dev, ofs, val); @@ -25,14 +18,6 @@ void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val) } IWL_EXPORT_SYMBOL(iwl_write32); -void iwl_write64(struct iwl_trans *trans, u64 ofs, u64 val) -{ - trace_iwlwifi_dev_iowrite64(trans->dev, ofs, val); - iwl_trans_write32(trans, ofs, lower_32_bits(val)); - iwl_trans_write32(trans, ofs + 4, upper_32_bits(val)); -} -IWL_EXPORT_SYMBOL(iwl_write64); - u32 iwl_read32(struct iwl_trans *trans, u32 ofs) { u32 val = iwl_trans_read32(trans, ofs); @@ -60,19 +45,6 @@ int iwl_poll_bits_mask(struct iwl_trans *trans, u32 addr, } IWL_EXPORT_SYMBOL(iwl_poll_bits_mask); -u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg) -{ - if (iwl_trans_grab_nic_access(trans)) { - u32 value = iwl_read32(trans, reg); - - iwl_trans_release_nic_access(trans); - return value; - } - - /* return as if we have a HW timeout/failure */ - return 0x5a5a5a5a; -} - void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) { if (iwl_trans_grab_nic_access(trans)) { @@ -82,29 +54,6 @@ void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) } IWL_EXPORT_SYMBOL(iwl_write_direct32); -void iwl_write_direct64(struct iwl_trans *trans, u64 reg, u64 value) -{ - if (iwl_trans_grab_nic_access(trans)) { - iwl_write64(trans, reg, value); - iwl_trans_release_nic_access(trans); - } -} - -int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, - int timeout) -{ - int t = 0; - - do { - if ((iwl_read_direct32(trans, addr) & mask) == mask) - return t; - udelay(IWL_POLL_INTERVAL); - t += IWL_POLL_INTERVAL; - } while (t < timeout); - - return -ETIMEDOUT; -} - u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) { u32 val = iwl_trans_read_prph(trans, ofs); @@ -118,13 +67,6 @@ void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) iwl_trans_write_prph_no_grab(trans, ofs, val); } -void iwl_write_prph64_no_grab(struct iwl_trans *trans, u64 ofs, u64 val) -{ - trace_iwlwifi_dev_iowrite_prph64(trans->dev, ofs, val); - iwl_write_prph_no_grab(trans, ofs, val & 0xffffffff); - iwl_write_prph_no_grab(trans, ofs + 4, val >> 32); -} - u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) { if (iwl_trans_grab_nic_access(trans)) { @@ -150,37 +92,6 @@ void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_m } IWL_EXPORT_SYMBOL(iwl_write_prph_delay); -int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout) -{ - int t = 0; - - do { - if ((iwl_read_prph(trans, addr) & mask) == (bits & mask)) - return 0; - udelay(IWL_POLL_INTERVAL); - t += IWL_POLL_INTERVAL; - } while (t < timeout); - - return -ETIMEDOUT; -} - -int iwl_poll_umac_prph_bits_no_grab(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout) -{ - int t = 0; - - do { - if ((iwl_read_umac_prph_no_grab(trans, addr) & mask) == - (bits & mask)) - return 0; - udelay(IWL_POLL_INTERVAL); - t += IWL_POLL_INTERVAL; - } while (t < timeout); - - return -ETIMEDOUT; -} - void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) { if (iwl_trans_grab_nic_access(trans)) { diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h index e4a9f2ba0de9..b24c5eeca206 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.h @@ -8,9 +8,7 @@ #include "iwl-devtrace.h" #include "iwl-trans.h" -void iwl_write8(struct iwl_trans *trans, u32 ofs, u8 val); void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val); -void iwl_write64(struct iwl_trans *trans, u64 ofs, u64 val); u32 iwl_read32(struct iwl_trans *trans, u32 ofs); static inline void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) @@ -30,18 +28,13 @@ static inline int iwl_poll_bits(struct iwl_trans *trans, u32 addr, u32 bits, { return iwl_poll_bits_mask(trans, addr, bits, bits, timeout); } -int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, - int timeout); -u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg); void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); -void iwl_write_direct64(struct iwl_trans *trans, u64 reg, u64 value); u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs); u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs); void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val); -void iwl_write_prph64_no_grab(struct iwl_trans *trans, u64 ofs, u64 val); void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_ms); static inline void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) @@ -49,10 +42,6 @@ static inline void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) iwl_write_prph_delay(trans, ofs, val, 0); } -int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout); -int iwl_poll_umac_prph_bits_no_grab(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout); void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, u32 bits, u32 mask); @@ -79,25 +68,10 @@ static inline u32 iwl_read_umac_prph(struct iwl_trans *trans, u32 ofs) return iwl_read_prph(trans, ofs + trans->mac_cfg->umac_prph_offset); } -static inline void iwl_write_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs, - u32 val) -{ - iwl_write_prph_no_grab(trans, ofs + trans->mac_cfg->umac_prph_offset, - val); -} - static inline void iwl_write_umac_prph(struct iwl_trans *trans, u32 ofs, u32 val) { iwl_write_prph(trans, ofs + trans->mac_cfg->umac_prph_offset, val); } -static inline int iwl_poll_umac_prph_bit(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout) -{ - return iwl_poll_prph_bit(trans, addr + - trans->mac_cfg->umac_prph_offset, - bits, mask, timeout); -} - #endif diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 1c593fd29d02..b3e39f0bbea4 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -428,11 +428,6 @@ void iwl_trans_op_mode_leave(struct iwl_trans *trans) } IWL_EXPORT_SYMBOL(iwl_trans_op_mode_leave); -void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val) -{ - iwl_trans_pcie_write8(trans, ofs, val); -} - void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val) { iwl_trans_pcie_write32(trans, ofs, val); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index c59b935ce4bf..c882313eaceb 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -910,8 +910,6 @@ int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans, u32 txqs); int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue); -void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val); - void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val); u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c index c75210829ec9..c57b17133772 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c @@ -7,6 +7,7 @@ #include "iwl-fh.h" #include "iwl-context-info-v2.h" #include "internal.h" +#include "pcie/utils.h" #include "iwl-prph.h" static const struct dmi_system_id dmi_force_scu_active_approved_list[] = { @@ -314,8 +315,8 @@ void iwl_pcie_ctxt_info_v2_kick(struct iwl_trans *trans) iwl_enable_fw_load_int_ctx_info(trans, trans->do_top_reset); /* kick FW self load */ - iwl_write64(trans, CSR_CTXT_INFO_ADDR, trans_pcie->ctxt_info_dma_addr); - iwl_write64(trans, CSR_IML_DATA_ADDR, trans_pcie->iml_dma_addr); + iwl_pcie_write64(trans, CSR_CTXT_INFO_ADDR, trans_pcie->ctxt_info_dma_addr); + iwl_pcie_write64(trans, CSR_IML_DATA_ADDR, trans_pcie->iml_dma_addr); iwl_write32(trans, CSR_IML_SIZE_ADDR, trans_pcie->iml_len); iwl_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c index 23ec968577bd..bc90a2714251 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c @@ -7,6 +7,7 @@ #include "iwl-fh.h" #include "iwl-context-info.h" #include "internal.h" +#include "utils.h" #include "iwl-prph.h" static void *_iwl_pcie_ctxt_info_dma_alloc_coherent(struct iwl_trans *trans, @@ -245,7 +246,7 @@ int iwl_pcie_ctxt_info_init(struct iwl_trans *trans, iwl_pcie_apply_destination(trans); /* kick FW self load */ - iwl_write64(trans, CSR_CTXT_INFO_BA, trans_pcie->ctxt_info_dma_addr); + iwl_pcie_write64(trans, CSR_CTXT_INFO_BA, trans_pcie->ctxt_info_dma_addr); /* Context info will be released upon alive or failure to get one */ diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index db3933b0d197..fec3d6e0b146 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -11,6 +11,7 @@ #include "iwl-prph.h" #include "iwl-io.h" #include "internal.h" +#include "pcie/utils.h" #include "iwl-op-mode.h" #include "iwl-context-info-v2.h" #include "fw/dbg.h" @@ -147,17 +148,17 @@ int iwl_pcie_rx_stop(struct iwl_trans *trans) if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { /* TODO: remove this once fw does it */ iwl_write_umac_prph(trans, RFH_RXF_DMA_CFG_AX210, 0); - return iwl_poll_umac_prph_bit(trans, RFH_GEN_STATUS_AX210, - RXF_DMA_IDLE, RXF_DMA_IDLE, 1000); + return iwl_pcie_poll_umac_prph_bit(trans, RFH_GEN_STATUS_AX210, + RXF_DMA_IDLE, RXF_DMA_IDLE, 1000); } else if (trans->mac_cfg->mq_rx_supported) { iwl_write_prph(trans, RFH_RXF_DMA_CFG, 0); - return iwl_poll_prph_bit(trans, RFH_GEN_STATUS, - RXF_DMA_IDLE, RXF_DMA_IDLE, 1000); + return iwl_pcie_poll_prph_bit(trans, RFH_GEN_STATUS, + RXF_DMA_IDLE, RXF_DMA_IDLE, 1000); } else { iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); - return iwl_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG, - FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, - 1000); + return iwl_pcie_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG, + FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, + 1000); } } @@ -890,7 +891,7 @@ static void iwl_pcie_rx_hw_init(struct iwl_trans *trans, struct iwl_rxq *rxq) iwl_trans_release_nic_access(trans); /* Set interrupt coalescing timer to default (2048 usecs) */ - iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); + iwl_trans_pcie_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); /* W/A for interrupt coalescing bug in 7260 and 3160 */ if (trans->cfg->host_interrupt_operation_mode) @@ -931,17 +932,17 @@ static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans) for (i = 0; i < trans->info.num_rxqs; i++) { /* Tell device where to find RBD free table in DRAM */ - iwl_write_prph64_no_grab(trans, - RFH_Q_FRBDCB_BA_LSB(i), - trans_pcie->rxq[i].bd_dma); + iwl_pcie_write_prph64_no_grab(trans, + RFH_Q_FRBDCB_BA_LSB(i), + trans_pcie->rxq[i].bd_dma); /* Tell device where to find RBD used table in DRAM */ - iwl_write_prph64_no_grab(trans, - RFH_Q_URBDCB_BA_LSB(i), - trans_pcie->rxq[i].used_bd_dma); + iwl_pcie_write_prph64_no_grab(trans, + RFH_Q_URBDCB_BA_LSB(i), + trans_pcie->rxq[i].used_bd_dma); /* Tell device where in DRAM to update its Rx status */ - iwl_write_prph64_no_grab(trans, - RFH_Q_URBD_STTS_WPTR_LSB(i), - trans_pcie->rxq[i].rb_stts_dma); + iwl_pcie_write_prph64_no_grab(trans, + RFH_Q_URBD_STTS_WPTR_LSB(i), + trans_pcie->rxq[i].rb_stts_dma); /* Reset device indice tables */ iwl_write_prph_no_grab(trans, RFH_Q_FRBDCB_WIDX(i), 0); iwl_write_prph_no_grab(trans, RFH_Q_FRBDCB_RIDX(i), 0); @@ -982,7 +983,7 @@ static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans) iwl_trans_release_nic_access(trans); /* Set interrupt coalescing timer to default (2048 usecs) */ - iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); + iwl_trans_pcie_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); } void iwl_pcie_rx_init_rxb_lists(struct iwl_rxq *rxq) @@ -1189,7 +1190,7 @@ int iwl_pcie_rx_init(struct iwl_trans *trans) int iwl_pcie_gen2_rx_init(struct iwl_trans *trans) { /* Set interrupt coalescing timer to default (2048 usecs) */ - iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); + iwl_trans_pcie_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); /* * We don't configure the RFH. @@ -2090,8 +2091,8 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) */ /* Disable periodic interrupt; we use it as just a one-shot. */ - iwl_write8(trans, CSR_INT_PERIODIC_REG, - CSR_INT_PERIODIC_DIS); + iwl_trans_pcie_write8(trans, CSR_INT_PERIODIC_REG, + CSR_INT_PERIODIC_DIS); /* * Enable periodic interrupt in 8 msec only if we received @@ -2101,8 +2102,8 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) * to extend the periodic interrupt; one-shot is enough. */ if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) - iwl_write8(trans, CSR_INT_PERIODIC_REG, - CSR_INT_PERIODIC_ENA); + iwl_trans_pcie_write8(trans, CSR_INT_PERIODIC_REG, + CSR_INT_PERIODIC_ENA); isr_stats->rx++; diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 3d1cc49effb4..b81dd7daca6c 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -751,7 +751,7 @@ static int iwl_pcie_load_cpu_sections_8000(struct iwl_trans *trans, return ret; /* Notify ucode of loaded section number and status */ - val = iwl_read_direct32(trans, FH_UCODE_LOAD_STATUS); + val = iwl_pcie_read_direct32(trans, FH_UCODE_LOAD_STATUS); val = val | (sec_num << shift_param); iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, val); @@ -1079,7 +1079,7 @@ static void iwl_pcie_map_list(struct iwl_trans *trans, int i; for (i = 0; i < arr_size; i++) { - iwl_write8(trans, CSR_MSIX_IVAR(causes[i].addr), val); + iwl_trans_pcie_write8(trans, CSR_MSIX_IVAR(causes[i].addr), val); iwl_clear_bit(trans, causes[i].mask_reg, BIT(causes[i].bit)); } @@ -1119,8 +1119,8 @@ static void iwl_pcie_map_rx_causes(struct iwl_trans *trans) */ val = BIT(MSIX_FH_INT_CAUSES_Q(0)); for (idx = 1; idx < trans->info.num_rxqs; idx++) { - iwl_write8(trans, CSR_MSIX_RX_IVAR(idx), - MSIX_FH_INT_CAUSES_Q(idx - offset)); + iwl_trans_pcie_write8(trans, CSR_MSIX_RX_IVAR(idx), + MSIX_FH_INT_CAUSES_Q(idx - offset)); val |= BIT(MSIX_FH_INT_CAUSES_Q(idx)); } iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~val); @@ -1128,10 +1128,10 @@ static void iwl_pcie_map_rx_causes(struct iwl_trans *trans) val = MSIX_FH_INT_CAUSES_Q(0); if (trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_NON_RX) val |= MSIX_NON_AUTO_CLEAR_CAUSE; - iwl_write8(trans, CSR_MSIX_RX_IVAR(0), val); + iwl_trans_pcie_write8(trans, CSR_MSIX_RX_IVAR(0), val); if (trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_FIRST_RSS) - iwl_write8(trans, CSR_MSIX_RX_IVAR(1), val); + iwl_trans_pcie_write8(trans, CSR_MSIX_RX_IVAR(1), val); } void iwl_pcie_conf_msix_hw(struct iwl_trans_pcie *trans_pcie) @@ -1754,8 +1754,8 @@ static int iwl_trans_pcie_clear_persistence_bit(struct iwl_trans *trans) "Error, can not clear persistence bit\n"); return -EPERM; } - iwl_write_umac_prph_no_grab(trans, HPM_DEBUG, - hpm & ~PERSISTENCE_BIT); + iwl_pcie_write_umac_prph_no_grab(trans, HPM_DEBUG, + hpm & ~PERSISTENCE_BIT); } return 0; @@ -1864,6 +1864,7 @@ void iwl_trans_pcie_op_mode_leave(struct iwl_trans *trans) void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val) { + trace_iwlwifi_dev_iowrite8(trans->dev, ofs, val); writeb(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs); } @@ -3253,11 +3254,11 @@ iwl_trans_pci_dump_marbh_monitor(struct iwl_trans *trans, if (!iwl_trans_grab_nic_access(trans)) return 0; - iwl_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x1); + iwl_pcie_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x1); for (i = 0; i < buf_size_in_dwords; i++) buffer[i] = iwl_read_umac_prph_no_grab(trans, MON_DMARB_RD_DATA_ADDR); - iwl_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x0); + iwl_pcie_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x0); iwl_trans_release_nic_access(trans); @@ -3916,11 +3917,11 @@ static void get_crf_id(struct iwl_trans *iwl_trans, return; } - ret = iwl_poll_umac_prph_bits_no_grab(iwl_trans, - WFPM_RSRCS_4PHS_ACK_STTS, - RSRC_ACK_CNVR_TOP, - RSRC_ACK_CNVR_TOP, - 50 * 1000); + ret = iwl_pcie_poll_umac_prph_bits_no_grab(iwl_trans, + WFPM_RSRCS_4PHS_ACK_STTS, + RSRC_ACK_CNVR_TOP, + RSRC_ACK_CNVR_TOP, + 50 * 1000); if (ret < 0) IWL_ERR(iwl_trans, "WFPM_RSRCS_4PHS_ACK_STTS bit 6 is clear\n"); @@ -3929,7 +3930,7 @@ static void get_crf_id(struct iwl_trans *iwl_trans, /* Enable access to peripheral registers */ val = iwl_read_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG); val |= WFPM_AUX_CTL_AUX_IF_MAC_OWNER_MSK; - iwl_write_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG, val); + iwl_pcie_write_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG, val); /* Read crf info */ info->hw_crf_id = iwl_read_prph_no_grab(iwl_trans, sd_reg_ver_addr); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index 496435ea93ee..bdd330280689 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -523,7 +523,7 @@ void iwl_pcie_tx_start(struct iwl_trans *trans) FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE); /* Update FH chicken bits */ - reg_val = iwl_read_direct32(trans, FH_TX_CHICKEN_BITS_REG); + reg_val = iwl_pcie_read_direct32(trans, FH_TX_CHICKEN_BITS_REG); iwl_write_direct32(trans, FH_TX_CHICKEN_BITS_REG, reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); @@ -549,9 +549,9 @@ void iwl_trans_pcie_tx_reset(struct iwl_trans *trans) txq_id++) { struct iwl_txq *txq = trans_pcie->txqs.txq[txq_id]; if (trans->mac_cfg->gen2) - iwl_write_direct64(trans, - FH_MEM_CBBC_QUEUE(trans, txq_id), - txq->dma_addr); + iwl_pcie_write_direct64(trans, + FH_MEM_CBBC_QUEUE(trans, txq_id), + txq->dma_addr); else iwl_write_direct32(trans, FH_MEM_CBBC_QUEUE(trans, txq_id), @@ -697,7 +697,7 @@ void iwl_txq_log_scd_error(struct iwl_trans *trans, struct iwl_txq *txq) (trans->mac_cfg->base->max_tfd_queue_size - 1), iwl_read_prph(trans, SCD_QUEUE_WRPTR(txq_id)) & (trans->mac_cfg->base->max_tfd_queue_size - 1), - iwl_read_direct32(trans, FH_TX_TRB_REG(fifo))); + iwl_pcie_read_direct32(trans, FH_TX_TRB_REG(fifo))); } static void iwl_txq_stuck_timer(struct timer_list *t) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c index 1bb274d8390c..bace3e21989c 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2025 Intel Corporation + * Copyright (C) 2025-2026 Intel Corporation */ #include @@ -102,3 +102,88 @@ out: pcie_dbg_dumped_once = 1; kfree(buf); } + +u32 iwl_pcie_read_direct32(struct iwl_trans *trans, u32 reg) +{ + if (iwl_trans_grab_nic_access(trans)) { + u32 value = iwl_read32(trans, reg); + + iwl_trans_release_nic_access(trans); + return value; + } + + /* return as if we have a HW timeout/failure */ + return 0x5a5a5a5a; +} + +#define IWL_PCIE_POLL_INTERVAL 10 /* microseconds */ + +int iwl_pcie_poll_direct_bit(struct iwl_trans *trans, + u32 addr, u32 mask, int timeout) +{ + int t = 0; + + do { + if ((iwl_pcie_read_direct32(trans, addr) & mask) == mask) + return t; + udelay(IWL_PCIE_POLL_INTERVAL); + t += IWL_PCIE_POLL_INTERVAL; + } while (t < timeout); + + return -ETIMEDOUT; +} + +int iwl_pcie_poll_prph_bit(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int t = 0; + + do { + if ((iwl_read_prph(trans, addr) & mask) == (bits & mask)) + return 0; + udelay(IWL_PCIE_POLL_INTERVAL); + t += IWL_PCIE_POLL_INTERVAL; + } while (t < timeout); + + return -ETIMEDOUT; +} + +int iwl_pcie_poll_umac_prph_bit(struct iwl_trans *trans, + u32 addr, u32 bits, u32 mask, + int timeout) +{ + return iwl_pcie_poll_prph_bit(trans, addr + + trans->mac_cfg->umac_prph_offset, + bits, mask, timeout); +} + +int iwl_pcie_poll_umac_prph_bits_no_grab(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int t = 0; + + do { + if ((iwl_read_umac_prph_no_grab(trans, addr) & mask) == + (bits & mask)) + return 0; + udelay(IWL_PCIE_POLL_INTERVAL); + t += IWL_PCIE_POLL_INTERVAL; + } while (t < timeout); + + return -ETIMEDOUT; +} + +void iwl_pcie_write_prph64_no_grab(struct iwl_trans *trans, u32 ofs, u64 val) +{ + trace_iwlwifi_dev_iowrite_prph64(trans->dev, ofs, val); + iwl_write_prph_no_grab(trans, ofs, val & 0xffffffff); + iwl_write_prph_no_grab(trans, ofs + 4, val >> 32); +} + +void iwl_pcie_write_direct64(struct iwl_trans *trans, u64 reg, u64 value) +{ + if (iwl_trans_grab_nic_access(trans)) { + iwl_pcie_write64(trans, reg, value); + iwl_trans_release_nic_access(trans); + } +} diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h index 27437d5e099b..341928cdb64b 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2025 Intel Corporation + * Copyright (C) 2025-2026 Intel Corporation */ #ifndef __iwl_pcie_utils_h__ @@ -10,6 +10,32 @@ void iwl_trans_pcie_dump_regs(struct iwl_trans *trans, struct pci_dev *pdev); +u32 iwl_pcie_read_direct32(struct iwl_trans *trans, u32 reg); +int iwl_pcie_poll_direct_bit(struct iwl_trans *trans, + u32 addr, u32 mask, int timeout); +int iwl_pcie_poll_prph_bit(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout); +int iwl_pcie_poll_umac_prph_bit(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout); +int iwl_pcie_poll_umac_prph_bits_no_grab(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout); +void iwl_pcie_write_prph64_no_grab(struct iwl_trans *trans, u32 ofs, u64 val); +void iwl_pcie_write_direct64(struct iwl_trans *trans, u64 reg, u64 value); + +static inline void iwl_pcie_write64(struct iwl_trans *trans, u64 ofs, u64 val) +{ + trace_iwlwifi_dev_iowrite64(trans->dev, ofs, val); + iwl_trans_write32(trans, ofs, lower_32_bits(val)); + iwl_trans_write32(trans, ofs + 4, upper_32_bits(val)); +} + +static inline void iwl_pcie_write_umac_prph_no_grab(struct iwl_trans *trans, + u32 ofs, u32 val) +{ + iwl_write_prph_no_grab(trans, ofs + trans->mac_cfg->umac_prph_offset, + val); +} + static inline void _iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value) { From c56b0989065999bb99d331d9fb35f50f1da1cc71 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Wed, 30 Sep 2026 12:19:40 +0300 Subject: [PATCH 1587/2126] wifi: iwlwifi: mld: fake a valid NSS field when needed We hit a WARNING in mac80211 in sniffer that complains that rx_status->nss is 0. This happens on frames that the firmware doesn't really understand and when that happens, somehow the STBC bit is set. The driver divides the number of antennas by 2 to get the NSS with STBC set because each stream requires 2 antennas. Since NSTS=1, NSS end up being 0. Since we don't have devices with more than 2 antennas, just consider that when we receive STBC traffic, we have one spatial stream. Since this problem has been seen on HE traffic only, don't apply this logic on VHT / HT code paths. Signed-off-by: Emmanuel Grumbach Reviewed-by: Johannes Berg Link: https://patch.msgid.link/20260930121740.2589668e377b.Ib41003bd4e10f0fe6d7f4aa1038291be330c3175@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 5f18aa551af5..8fa438fd7815 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -553,7 +553,10 @@ iwl_mld_decode_he_tb_phy_data(struct iwl_mld_rx_phy_data *phy_data, nsts = le32_get_bits(phy_data->ntfy->sigs.he_tb.tb_rx1, OFDM_UCODE_TRIG_BASE_RX_NSTS) + 1; - rx_status->nss = nsts >> !!(rate_n_flags & RATE_MCS_STBC_MSK); + + rx_status->nss = nsts; + if (rate_n_flags & RATE_MCS_STBC_MSK) + rx_status->nss = 1; } static void @@ -589,7 +592,9 @@ iwl_mld_decode_he_phy_data(struct iwl_mld_rx_phy_data *phy_data, break; } - rx_status->nss = nsts >> !!(rate_n_flags & RATE_MCS_STBC_MSK); + rx_status->nss = nsts; + if (rate_n_flags & RATE_MCS_STBC_MSK) + rx_status->nss = 1; he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN | IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN); From 594c359b00422f1cb1afc3713595fc7e56828869 Mon Sep 17 00:00:00 2001 From: Daniel Gabay Date: Wed, 30 Sep 2026 12:19:41 +0300 Subject: [PATCH 1588/2126] wifi: iwlwifi: mld: add gp2 timestamps to TX commands TX command v12 adds a driver timestamp in the gp2 clock domain. Firmware uses it to age out frames deferred by CCA for more than four seconds. Without it, a blocked queue can stall until the datapath monitor fires LMAC assert 0x4433. Reading the gp2 register per frame is too expensive for the TX path. Instead, use a worker to measure its offset from host boottime and publish the offset and validity deadline using atomic stores. TX then estimates gp2 without allocation or locking for timestamp reads. TX requests a refresh after five seconds, while the estimate remains valid for ten seconds to tolerate worker delays and bound clock drift. Successful refreshes require no periodic work while traffic is idle. A failed read invalidates the estimate and schedules a retry after roughly one second, rounded for timer coalescing, even without traffic. Invalidate the estimate before D3 entry and firmware shutdown, and refresh it on resume or reload because gp2 restarts with firmware. Frames without a valid estimate carry a zero timestamp, which firmware ignores. Signed-off-by: Daniel Gabay Assisted-by: LLM Link: https://patch.msgid.link/20260930121740.a5016741a467.Ie4d4af8d7100a656a8469edc0c38ec81b0b58860@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/tx.h | 11 +- .../wireless/intel/iwlwifi/mld/constants.h | 4 + drivers/net/wireless/intel/iwlwifi/mld/d3.c | 5 + drivers/net/wireless/intel/iwlwifi/mld/fw.c | 7 +- .../net/wireless/intel/iwlwifi/mld/mac80211.c | 2 + drivers/net/wireless/intel/iwlwifi/mld/mld.c | 13 ++ drivers/net/wireless/intel/iwlwifi/mld/mld.h | 6 + drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 12 +- drivers/net/wireless/intel/iwlwifi/mld/tx.c | 130 ++++++++++++++++++ drivers/net/wireless/intel/iwlwifi/mld/tx.h | 36 ++++- 10 files changed, 209 insertions(+), 17 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/tx.h b/drivers/net/wireless/intel/iwlwifi/fw/api/tx.h index 31d3336726b4..9d9eb320db7b 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/tx.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/tx.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2012-2014, 2018-2025 Intel Corporation + * Copyright (C) 2012-2014, 2018-2026 Intel Corporation * Copyright (C) 2016-2017 Intel Deutschland GmbH */ #ifndef __iwl_fw_api_tx_h__ @@ -292,6 +292,9 @@ struct iwl_tx_cmd_v9 { * @dram_info: FW internal DRAM storage * @rate_n_flags: rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is * cleared. Combination of RATE_MCS_*; format depends on version + * @driver_timestamp: gp2 time, in microseconds, assigned before queueing the + * MPDU. Firmware uses it to detect frames blocked for too long. + * Zero means no timestamp. Used from TX_CMD_API_S_VER_12. * @reserved: reserved * @hdr: 802.11 header */ @@ -301,10 +304,12 @@ struct iwl_tx_cmd { __le32 offload_assist; struct iwl_dram_sec_info dram_info; __le32 rate_n_flags; - u8 reserved[8]; + __le32 driver_timestamp; + u8 reserved[4]; struct ieee80211_hdr hdr[]; } __packed; /* TX_CMD_API_S_VER_10, - * TX_CMD_API_S_VER_11 + * TX_CMD_API_S_VER_11, + * TX_CMD_API_S_VER_12 */ /* diff --git a/drivers/net/wireless/intel/iwlwifi/mld/constants.h b/drivers/net/wireless/intel/iwlwifi/mld/constants.h index 890abcab3837..bfd5398510ee 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/constants.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/constants.h @@ -39,6 +39,10 @@ #define IWL_MLD_TPT_COUNT_WINDOW (5 * HZ) +#define IWL_MLD_TX_GP2_VALID_PERIOD (10 * HZ) +#define IWL_MLD_TX_GP2_REFRESH_MARGIN (5 * HZ) +#define IWL_MLD_TX_GP2_RETRY_PERIOD HZ + #define IWL_MLD_DIS_RANDOM_FW_ID false #define IWL_MLD_D3_DEBUG false #define IWL_MLD_NON_TRANSMITTING_AP false diff --git a/drivers/net/wireless/intel/iwlwifi/mld/d3.c b/drivers/net/wireless/intel/iwlwifi/mld/d3.c index 6d8ede336d59..7a7d07a7914d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/d3.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/d3.c @@ -5,6 +5,7 @@ #include "mld.h" #include "d3.h" +#include "tx.h" #include "power.h" #include "hcmd.h" #include "iface.h" @@ -1610,6 +1611,8 @@ int iwl_mld_no_wowlan_suspend(struct iwl_mld *mld) iwl_mld_low_latency_stop(mld); + iwl_mld_tx_gp2_stop(mld); + ret = iwl_mld_update_device_power(mld, true); if (ret) { IWL_ERR(mld, @@ -1663,6 +1666,8 @@ int iwl_mld_no_wowlan_resume(struct iwl_mld *mld) iwl_mld_low_latency_restart(mld); + iwl_mld_tx_gp2_start(mld); + return iwl_mld_update_device_power(mld, false); } diff --git a/drivers/net/wireless/intel/iwlwifi/mld/fw.c b/drivers/net/wireless/intel/iwlwifi/mld/fw.c index e5866d89176d..7891afd556a8 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/fw.c @@ -1,9 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2024-2025 Intel Corporation + * Copyright (C) 2024-2026 Intel Corporation */ #include "mld.h" +#include "tx.h" #include "fw/api/alive.h" #include "fw/api/scan.h" @@ -355,6 +356,8 @@ void iwl_mld_stop_fw(struct iwl_mld *mld) { lockdep_assert_wiphy(mld->wiphy); + iwl_mld_tx_gp2_stop(mld); + iwl_abort_notification_waits(&mld->notif_wait); iwl_fw_dbg_stop_sync(&mld->fwrt); @@ -542,6 +545,8 @@ int iwl_mld_start_fw(struct iwl_mld *mld) if (ret) goto error; + iwl_mld_tx_gp2_start(mld); + return 0; error: diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c index 0b121114d47c..e05bdbd3e1a9 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c @@ -2168,6 +2168,8 @@ static int iwl_mld_resume(struct ieee80211_hw *hw) iwl_mld_low_latency_restart(mld); + iwl_mld_tx_gp2_start(mld); + return 0; } #endif diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mld.c b/drivers/net/wireless/intel/iwlwifi/mld/mld.c index b7b1e3686336..95d6f36b9fd9 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mld.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/mld.c @@ -35,6 +35,17 @@ MODULE_IMPORT_NS("IWLWIFI"); static const struct iwl_op_mode_ops iwl_mld_ops; +int iwl_mld_get_systime(struct iwl_mld *mld, u32 *gp2) +{ + *gp2 = iwl_read_prph(mld->trans, + mld->trans->mac_cfg->base->gp2_reg_addr); + + if (*gp2 == 0x5a5a5a5a) + return -EINVAL; + + return 0; +} + static int __init iwl_mld_init(void) { int ret = iwl_opmode_register("iwlmld", &iwl_mld_ops); @@ -425,6 +436,8 @@ iwl_op_mode_mld_start(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg, /* Configure transport layer with the opmode specific params */ iwl_mld_configure_trans(op_mode); + iwl_mld_tx_gp2_init(mld); + /* needed for regulatory init */ rtnl_lock(); /* Needed for sending commands */ diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mld.h b/drivers/net/wireless/intel/iwlwifi/mld/mld.h index 37f41b504b54..a9e65b216fd3 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mld.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/mld.h @@ -29,6 +29,7 @@ #include "notif.h" #include "scan.h" #include "rx.h" +#include "tx.h" #include "thermal.h" #include "low_latency.h" #include "constants.h" @@ -196,6 +197,7 @@ * being IBSS manager for that time and needing to respond to probe * requests * @ptp_data: data of the PTP clock + * @tx_gp2: gp2 timestamping state for TX commands * @time_sync: time sync data. * @ftm_initiator: FTM initiator data * @nan_device_vif: points to the NAN device vif if exists @@ -306,6 +308,8 @@ struct iwl_mld { struct ptp_data ptp_data; + struct iwl_mld_tx_gp2 tx_gp2; + struct iwl_mld_time_sync_data __rcu *time_sync; struct ftm_initiator_data ftm_initiator; @@ -572,6 +576,8 @@ iwl_mld_fw_id_to_link_conf(struct iwl_mld *mld, u8 fw_link_id) #define MSEC_TO_TU(_msec) ((_msec) * 1000 / 1024) +int iwl_mld_get_systime(struct iwl_mld *mld, u32 *gp2); + void iwl_mld_add_vif_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif); void iwl_mld_add_link_debugfs(struct ieee80211_hw *hw, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/ptp.c b/drivers/net/wireless/intel/iwlwifi/mld/ptp.c index 1ac85d6ce1d7..9f7d17dbdee1 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/ptp.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/ptp.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2025 Intel Corporation + * Copyright (C) 2025 - 2026 Intel Corporation */ #include "mld.h" @@ -19,16 +19,6 @@ #define IWL_PTP_WRAP_TIME (3600 * HZ) #define IWL_PTP_WRAP_THRESHOLD_USEC (5000) -static int iwl_mld_get_systime(struct iwl_mld *mld, u32 *gp2) -{ - *gp2 = iwl_read_prph(mld->trans, mld->trans->mac_cfg->base->gp2_reg_addr); - - if (*gp2 == 0x5a5a5a5a) - return -EINVAL; - - return 0; -} - static void iwl_mld_ptp_update_new_read(struct iwl_mld *mld, u32 gp2) { IWL_DEBUG_PTP(mld, "PTP: last_gp2=%u, new gp2 read=%u\n", diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tx.c b/drivers/net/wireless/intel/iwlwifi/mld/tx.c index 2df6643a5aa8..aac7d43bffd1 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tx.c @@ -2,6 +2,7 @@ /* * Copyright (C) 2024 - 2026 Intel Corporation */ +#include #include #include "tx.h" @@ -20,6 +21,132 @@ #define MAX_ANT_NUM 2 +static u32 iwl_mld_tx_gp2_host_us(void) +{ + return div_u64(ktime_get_boottime_ns(), NSEC_PER_USEC); +} + +/* Returns the gp2 for the TX command, or 0 to leave the frame unstamped. + * Sets @refresh when the estimate expired or is about to. + */ +static u32 +iwl_mld_tx_gp2_from_est(u32 delta_us, unsigned long valid_until, u32 host_us, + unsigned long now, bool *refresh) +{ + u32 gp2; + + *refresh = time_after_eq(now, valid_until - + IWL_MLD_TX_GP2_REFRESH_MARGIN); + + if (time_after_eq(now, valid_until)) + return 0; + + gp2 = host_us + delta_us; + + /* 0 means no timestamp; use 1 for a valid wrapped value. */ + return gp2 ?: 1; +} + +static u32 +iwl_mld_tx_gp2_timestamp(struct iwl_mld *mld) +{ + unsigned long valid_until = + atomic_long_read_acquire(&mld->tx_gp2.valid_until); + bool refresh = false; + u32 gp2; + + if (!valid_until) + return 0; + + gp2 = iwl_mld_tx_gp2_from_est(atomic_read(&mld->tx_gp2.delta_us), + valid_until, iwl_mld_tx_gp2_host_us(), + jiffies, &refresh); + + if (refresh) + wiphy_delayed_work_queue(mld->wiphy, &mld->tx_gp2.wk, 0); + + return gp2; +} + +static void iwl_mld_tx_gp2_refresh(struct iwl_mld *mld) +{ + unsigned long valid_until, delay; + u32 gp2, host_us; + + lockdep_assert_wiphy(mld->wiphy); + + if (!mld->fw_status.running) + return; + +#ifdef CONFIG_PM_SLEEP + if (mld->fw_status.in_d3) + return; +#endif + + if (iwl_mld_get_systime(mld, &gp2)) + goto retry; + + host_us = iwl_mld_tx_gp2_host_us(); + valid_until = jiffies + IWL_MLD_TX_GP2_VALID_PERIOD; + + /* Keep arithmetic in u32 to match firmware wraparound semantics. */ + atomic_set(&mld->tx_gp2.delta_us, gp2 - host_us); + atomic_long_set_release(&mld->tx_gp2.valid_until, valid_until ?: 1); + + IWL_DEBUG_TX(mld, "gp2 sync: gp2=%u host_us=%u delta_us=%u\n", + gp2, host_us, gp2 - host_us); + return; + +retry: + /* Stop new TX readers from requesting immediate retries. */ + atomic_long_set(&mld->tx_gp2.valid_until, 0); + delay = round_jiffies_relative(IWL_MLD_TX_GP2_RETRY_PERIOD); + wiphy_delayed_work_queue(mld->wiphy, &mld->tx_gp2.wk, delay); +} + +static void iwl_mld_tx_gp2_wk(struct wiphy *wiphy, struct wiphy_work *wk) +{ + struct iwl_mld *mld = container_of(wk, struct iwl_mld, tx_gp2.wk.work); + unsigned long valid_until = atomic_long_read(&mld->tx_gp2.valid_until); + + /* TX may have queued this work using an older estimate. */ + if (valid_until && + time_before(jiffies, valid_until - IWL_MLD_TX_GP2_REFRESH_MARGIN)) + return; + + iwl_mld_tx_gp2_refresh(mld); +} + +void iwl_mld_tx_gp2_init(struct iwl_mld *mld) +{ + atomic_set(&mld->tx_gp2.delta_us, 0); + atomic_long_set(&mld->tx_gp2.valid_until, 0); + wiphy_delayed_work_init(&mld->tx_gp2.wk, iwl_mld_tx_gp2_wk); +} + +void iwl_mld_tx_gp2_start(struct iwl_mld *mld) +{ + lockdep_assert_wiphy(mld->wiphy); + + if (iwl_fw_lookup_cmd_ver(mld->fw, TX_CMD, 0) < 12) + return; + + iwl_mld_tx_gp2_refresh(mld); +} + +/* TX is quiesced before stopping the refresh work. */ +void iwl_mld_tx_gp2_stop(struct iwl_mld *mld) +{ + lockdep_assert_wiphy(mld->wiphy); + + if (iwl_fw_lookup_cmd_ver(mld->fw, TX_CMD, 0) < 12) + return; + + wiphy_delayed_work_cancel(mld->wiphy, &mld->tx_gp2.wk); + + atomic_long_set(&mld->tx_gp2.valid_until, 0); +} + /* Toggles between TX antennas. Receives the bitmask of valid TX antennas and * the *index* used for the last TX, and returns the next valid *index* to use. * In order to set it in the tx_cmd, must do BIT(idx). @@ -588,6 +715,9 @@ iwl_mld_fill_tx_cmd(struct iwl_mld *mld, struct sk_buff *skb, tx_cmd->flags = cpu_to_le16(flags); tx_cmd->rate_n_flags = rate_n_flags; + + tx_cmd->driver_timestamp = + cpu_to_le32(iwl_mld_tx_gp2_timestamp(mld)); } /* Caller of this need to check that info->control.vif is not NULL */ diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tx.h b/drivers/net/wireless/intel/iwlwifi/mld/tx.h index 520f15f9d33c..0a9a2e4abcab 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tx.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/tx.h @@ -1,11 +1,15 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024, 2026 Intel Corporation */ #ifndef __iwl_mld_tx_h__ #define __iwl_mld_tx_h__ -#include "mld.h" +#include +#include + +struct iwl_mld; +struct iwl_rx_packet; #define IWL_MLD_INVALID_QUEUE 0xFFFF #define IWL_MLD_INVALID_DROP_TX 0xFFFE @@ -74,4 +78,32 @@ u8 iwl_mld_get_lowest_rate(struct iwl_mld *mld, void iwl_mld_tx_skb(struct iwl_mld *mld, struct sk_buff *skb, struct ieee80211_txq *txq); +/** + * struct iwl_mld_tx_gp2 - gp2 timestamping state for TX commands + * + * Reading gp2 directly in the TX path is too costly. Instead, TX lazily + * schedules @wk to refresh gp2 in process context and adds @delta_us to the + * host clock to timestamp queued frames. + * + * A zero @valid_until leaves frames unstamped, including on older firmware + * without TX_CMD v12. A deadline that wraps to zero is published as one. + * Failed refreshes clear @valid_until, leaving @delta_us for old readers, and + * schedule a retry with %IWL_MLD_TX_GP2_RETRY_PERIOD rounded for timer + * coalescing, even without further TX traffic. Old readers may retry sooner. + * + * @delta_us: gp2 minus host time, in microseconds, modulo 2^32; + * valid while @valid_until is nonzero and has not expired + * @valid_until: jiffies deadline for the offset, or zero when disabled + * @wk: worker that refreshes the offset and retries failures + */ +struct iwl_mld_tx_gp2 { + atomic_t delta_us; + atomic_long_t valid_until; + struct wiphy_delayed_work wk; +}; + +void iwl_mld_tx_gp2_init(struct iwl_mld *mld); +void iwl_mld_tx_gp2_start(struct iwl_mld *mld); +void iwl_mld_tx_gp2_stop(struct iwl_mld *mld); + #endif /* __iwl_mld_tx_h__ */ From c9ebbfdba19d44ae1022b75290f5e48d170be815 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Wed, 30 Sep 2026 12:19:42 +0300 Subject: [PATCH 1589/2126] wifi: iwlwifi: mld: report RX time from channel survey Newer firmware versions will start reporting a separate RX time value that represents for how long the channel was busy with Wi-Fi frames. Previously the reported value for RX time was equal to the busy time. As such, report the information as it will be useful in the future. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20260930121740.727c05ab3c58.I9509587622fa7c6493b6baee53372c548bf60ed8@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/scan.c | 5 ++++- drivers/net/wireless/intel/iwlwifi/mld/scan.h | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/scan.c b/drivers/net/wireless/intel/iwlwifi/mld/scan.c index e44b24904c19..b942ac1e7ccc 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/scan.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/scan.c @@ -2273,6 +2273,7 @@ void iwl_mld_handle_channel_survey_notif(struct iwl_mld *mld, /* Times are all in ms */ info->time = le32_to_cpu(notif->active_time); info->time_busy = le32_to_cpu(notif->busy_time); + info->time_rx = le32_to_cpu(notif->rx_time); info->noise = iwl_average_neg_dbm(notif->noise, ARRAY_SIZE(notif->noise)); } @@ -2321,9 +2322,11 @@ int iwl_mld_mac80211_get_survey(struct ieee80211_hw *hw, int idx, /* Found (the next) channel to report */ survey->channel = &sband->channels[per_band_idx]; survey->filled = SURVEY_INFO_TIME | - SURVEY_INFO_TIME_BUSY; + SURVEY_INFO_TIME_BUSY | + SURVEY_INFO_TIME_RX; survey->time = info->time; survey->time_busy = info->time_busy; + survey->time_rx = info->time_rx; survey->noise = info->noise; if (survey->noise < 0) survey->filled |= SURVEY_INFO_NOISE_DBM; diff --git a/drivers/net/wireless/intel/iwlwifi/mld/scan.h b/drivers/net/wireless/intel/iwlwifi/mld/scan.h index dc299fe2f999..74ebe8296693 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/scan.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/scan.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2024-2025 Intel Corporation + * Copyright (C) 2024-2026 Intel Corporation */ #ifndef __iwl_mld_scan_h__ #define __iwl_mld_scan_h__ @@ -151,11 +151,13 @@ struct iwl_mld_scan { * * @time: time in ms the radio was on the channel * @time_busy: time in ms the channel was sensed busy + * @time_rx: time in ms the channel was sensed to carry Wi-Fi frames * @noise: channel noise in dBm */ struct iwl_mld_survey_channel { u32 time; u32 time_busy; + u32 time_rx; s8 noise; }; From 27a4816f37ce99d4e78332072306d9a8401cc362 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:43 +0300 Subject: [PATCH 1590/2126] wifi: iwlwifi: avoid unnecessary indirection Some helpers in iwl-io are no more than thin wrappers that do tracing and call the underlying iwl_trans_* function, which in turn calls the bus specific implementation. This forces an unneeded indirection for calls from within pcie, and in general makes the code harder to follow. Move the tracing to the pcie implementation and get rid of those wrappers: change the pcie callers to call the pcie implementation directly, and the callers outside the transport - to call the iwl_trans_* API. This also improves the current callers of the pcie specific implementations to include tracing, which they didn't have before this commit. Assisted-by: GitHubCopilot:claude-opus-4.8 Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.8a85afed9cd7.If4806e645949ec73b8c734486605d7d4ea8ada4e@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/dvm/debugfs.c | 4 +- .../net/wireless/intel/iwlwifi/dvm/devices.c | 6 +- .../net/wireless/intel/iwlwifi/dvm/eeprom.c | 30 ++--- drivers/net/wireless/intel/iwlwifi/dvm/led.c | 10 +- .../net/wireless/intel/iwlwifi/dvm/mac80211.c | 10 +- drivers/net/wireless/intel/iwlwifi/dvm/main.c | 22 +-- drivers/net/wireless/intel/iwlwifi/dvm/rx.c | 10 +- drivers/net/wireless/intel/iwlwifi/dvm/tt.c | 12 +- drivers/net/wireless/intel/iwlwifi/fw/dump.c | 2 +- drivers/net/wireless/intel/iwlwifi/iwl-csr.h | 8 +- .../net/wireless/intel/iwlwifi/iwl-dbg-tlv.c | 2 +- .../wireless/intel/iwlwifi/iwl-devtrace-io.h | 18 +-- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 42 ++---- drivers/net/wireless/intel/iwlwifi/iwl-io.h | 4 - .../wireless/intel/iwlwifi/iwl-nvm-parse.c | 12 +- .../net/wireless/intel/iwlwifi/iwl-trans.c | 12 +- drivers/net/wireless/intel/iwlwifi/mvm/led.c | 6 +- .../intel/iwlwifi/pcie/ctxt-info-v2.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 2 +- .../wireless/intel/iwlwifi/pcie/internal.h | 58 ++++---- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 124 ++++++++--------- .../wireless/intel/iwlwifi/pcie/trans-gen2.c | 34 ++--- .../net/wireless/intel/iwlwifi/pcie/trans.c | 127 +++++++++--------- .../net/wireless/intel/iwlwifi/pcie/tx-gen2.c | 4 +- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 14 +- .../net/wireless/intel/iwlwifi/pcie/utils.c | 8 +- .../net/wireless/intel/iwlwifi/pcie/utils.h | 14 +- 27 files changed, 282 insertions(+), 315 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c index ec94c43ba28c..ed041710c74f 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. - * Copyright (C) 2018, 2025 Intel Corporation + * Copyright (C) 2018, 2025-2026 Intel Corporation *****************************************************************************/ #include @@ -1788,7 +1788,7 @@ static ssize_t iwl_dbgfs_power_save_status_read(struct file *file, const size_t bufsz = sizeof(buf); u32 pwrsave_status; - pwrsave_status = iwl_read32(priv->trans, CSR_GP_CNTRL) & + pwrsave_status = iwl_trans_read32(priv->trans, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK; pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: "); diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c index 7f83f1bbdaad..b40a769f8e2d 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. - * Copyright (C) 2019, 2025 Intel Corporation + * Copyright (C) 2019, 2025-2026 Intel Corporation *****************************************************************************/ #include @@ -490,8 +490,8 @@ static void iwl6000_nic_config(struct iwl_priv *priv) break; case IWL_DEVICE_FAMILY_6000i: /* 2x2 IPA phy type */ - iwl_write32(priv->trans, CSR_GP_DRIVER_REG, - CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA); + iwl_trans_write32(priv->trans, CSR_GP_DRIVER_REG, + CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA); break; case IWL_DEVICE_FAMILY_6050: /* Indicate calibration version to uCode. */ diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c b/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c index 6de2517188f7..d20691f7d82f 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2005-2014, 2018-2019, 2021, 2024-2025 Intel Corporation + * Copyright (C) 2005-2014, 2018-2019, 2021, 2024-2026 Intel Corporation */ #include #include @@ -698,7 +698,7 @@ static void iwl_eeprom_release_semaphore(struct iwl_trans *trans) static int iwl_eeprom_verify_signature(struct iwl_trans *trans, bool nvm_is_otp) { - u32 gp = iwl_read32(trans, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK; + u32 gp = iwl_trans_read32(trans, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK; IWL_DEBUG_EEPROM(trans->dev, "EEPROM signature=0x%08x\n", gp); @@ -734,7 +734,7 @@ static int iwl_eeprom_verify_signature(struct iwl_trans *trans, bool nvm_is_otp) static void iwl_set_otp_access_absolute(struct iwl_trans *trans) { - iwl_read32(trans, CSR_OTP_GP_REG); + iwl_trans_read32(trans, CSR_OTP_GP_REG); iwl_clear_bit(trans, CSR_OTP_GP_REG, CSR_OTP_GP_REG_OTP_ACCESS_MODE); @@ -755,7 +755,7 @@ static int iwl_nvm_is_otp(struct iwl_trans *trans) case CSR_HW_REV_TYPE_5150: return 0; default: - otpgp = iwl_read32(trans, CSR_OTP_GP_REG); + otpgp = iwl_trans_read32(trans, CSR_OTP_GP_REG); if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT) return 1; return 0; @@ -794,8 +794,8 @@ static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr, u32 r; u32 otpgp; - iwl_write32(trans, CSR_EEPROM_REG, - CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); + iwl_trans_write32(trans, CSR_EEPROM_REG, + CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); ret = iwl_poll_bits(trans, CSR_EEPROM_REG, CSR_EEPROM_REG_READ_VALID_MSK, IWL_EEPROM_ACCESS_TIMEOUT); @@ -803,9 +803,9 @@ static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr, IWL_ERR(trans, "Time out reading OTP[%d]\n", addr); return ret; } - r = iwl_read32(trans, CSR_EEPROM_REG); + r = iwl_trans_read32(trans, CSR_EEPROM_REG); /* check for ECC errors: */ - otpgp = iwl_read32(trans, CSR_OTP_GP_REG); + otpgp = iwl_trans_read32(trans, CSR_OTP_GP_REG); if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) { /* stop in this case */ /* set the uncorrectable OTP ECC bit for acknowledgment */ @@ -918,7 +918,7 @@ static int iwl_find_otp_image(struct iwl_trans *trans, int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) { __le16 *e; - u32 gp = iwl_read32(trans, CSR_EEPROM_GP); + u32 gp = iwl_trans_read32(trans, CSR_EEPROM_GP); int sz; int ret; u16 addr; @@ -960,9 +960,9 @@ int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) goto err_unlock; } - iwl_write32(trans, CSR_EEPROM_GP, - iwl_read32(trans, CSR_EEPROM_GP) & - ~CSR_EEPROM_GP_IF_OWNER_MSK); + iwl_trans_write32(trans, CSR_EEPROM_GP, + iwl_trans_read32(trans, CSR_EEPROM_GP) & + ~CSR_EEPROM_GP_IF_OWNER_MSK); iwl_set_bit(trans, CSR_OTP_GP_REG, CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK | @@ -988,8 +988,8 @@ int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) for (addr = 0; addr < sz; addr += sizeof(u16)) { u32 r; - iwl_write32(trans, CSR_EEPROM_REG, - CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); + iwl_trans_write32(trans, CSR_EEPROM_REG, + CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); ret = iwl_poll_bits(trans, CSR_EEPROM_REG, CSR_EEPROM_REG_READ_VALID_MSK, @@ -999,7 +999,7 @@ int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) "Time out reading EEPROM[%d]\n", addr); goto err_unlock; } - r = iwl_read32(trans, CSR_EEPROM_REG); + r = iwl_trans_read32(trans, CSR_EEPROM_REG); e[addr / 2] = cpu_to_le16(r >> 16); } } diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/led.c b/drivers/net/wireless/intel/iwlwifi/dvm/led.c index cec2ebdfd651..6fa02cd0ab04 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/led.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/led.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. - * Copyright (C) 2019, 2025 Intel Corporation + * Copyright (C) 2019, 2025-2026 Intel Corporation *****************************************************************************/ @@ -49,7 +49,7 @@ static const struct ieee80211_tpt_blink iwl_blink[] = { /* Set led register off */ void iwlagn_led_enable(struct iwl_priv *priv) { - iwl_write32(priv->trans, CSR_LED_REG, CSR_LED_REG_TURN_ON); + iwl_trans_write32(priv->trans, CSR_LED_REG, CSR_LED_REG_TURN_ON); } /* @@ -85,10 +85,10 @@ static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd) }; u32 reg; - reg = iwl_read32(priv->trans, CSR_LED_REG); + reg = iwl_trans_read32(priv->trans, CSR_LED_REG); if (reg != (reg & CSR_LED_BSM_CTRL_MSK)) - iwl_write32(priv->trans, CSR_LED_REG, - reg & CSR_LED_BSM_CTRL_MSK); + iwl_trans_write32(priv->trans, CSR_LED_REG, + reg & CSR_LED_BSM_CTRL_MSK); return iwl_dvm_send_cmd(priv, &cmd); } diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c index a0a26ef482a5..1da59e724054 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. - * Copyright(C) 2018 - 2019, 2022 - 2025 Intel Corporation + * Copyright(C) 2018 - 2019, 2022 - 2026 Intel Corporation * * Portions of this file are derived from the ipw3945 project, as well * as portions of the ieee80211 subsystem header files. @@ -375,8 +375,8 @@ static int iwlagn_mac_suspend(struct ieee80211_hw *hw, goto error; /* let the ucode operate on its own */ - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, - CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, + CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE); iwl_trans_d3_suspend(priv->trans, true); @@ -455,8 +455,8 @@ static int iwlagn_mac_resume(struct ieee80211_hw *hw) goto out_unlock; /* uCode is no longer operating by itself */ - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, + CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE); base = priv->device_pointers.error_event_table; if (!iwlagn_hw_valid_rtc_data_addr(base)) { diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/main.c b/drivers/net/wireless/intel/iwlwifi/dvm/main.c index 6bd5b6d84b2a..9bf16950ebf0 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/main.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/main.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2003 - 2014, 2018 - 2022 Intel Corporation. All rights reserved. - * Copyright(c) 2024-2025 Intel Corporation. All rights reserved. + * Copyright(c) 2024-2026 Intel Corporation. All rights reserved. * Copyright(c) 2015 Intel Deutschland GmbH * * Portions of this file are derived from the ipw3945 project, as well @@ -413,7 +413,7 @@ static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base, return; /* Set starting address; reads will auto-increment */ - iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr); + iwl_trans_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr); /* * Refuse to read more than would have fit into the log from @@ -429,13 +429,13 @@ static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base, * place event id # at far right for easier visual parsing. */ for (i = 0; i < num_events; i++) { - ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); - time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); + ev = iwl_trans_read32(priv->trans, HBUS_TARG_MEM_RDAT); + time = iwl_trans_read32(priv->trans, HBUS_TARG_MEM_RDAT); if (mode == 0) { trace_iwlwifi_dev_ucode_cont_event( priv->trans->dev, 0, time, ev); } else { - data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); + data = iwl_trans_read32(priv->trans, HBUS_TARG_MEM_RDAT); trace_iwlwifi_dev_ucode_cont_event( priv->trans->dev, time, data, ev); } @@ -661,8 +661,8 @@ static void iwl_rf_kill_ct_config(struct iwl_priv *priv) struct iwl_ct_kill_throttling_config adv_cmd; int ret = 0; - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, + CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); priv->thermal_throttle.ct_kill_toggle = false; @@ -1731,13 +1731,13 @@ static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, return pos; /* Set starting address; reads will auto-increment */ - iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr); + iwl_trans_write32(trans, HBUS_TARG_MEM_RADDR, ptr); /* "time" is actually "data" for mode 0 (no timestamp). * place event id # at far right for easier visual parsing. */ for (i = 0; i < num_events; i++) { - ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT); - time = iwl_read32(trans, HBUS_TARG_MEM_RDAT); + ev = iwl_trans_read32(trans, HBUS_TARG_MEM_RDAT); + time = iwl_trans_read32(trans, HBUS_TARG_MEM_RDAT); if (mode == 0) { /* data, ev */ if (bufsz) { @@ -1751,7 +1751,7 @@ static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, time, ev); } } else { - data = iwl_read32(trans, HBUS_TARG_MEM_RDAT); + data = iwl_trans_read32(trans, HBUS_TARG_MEM_RDAT); if (bufsz) { pos += scnprintf(*buf + pos, bufsz - pos, "EVT_LOGT:%010u:0x%08x:%04u\n", diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c index 088302a238de..79ee4fb239b2 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c @@ -3,7 +3,7 @@ * * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. * Copyright(c) 2015 Intel Deutschland GmbH - * Copyright(c) 2018, 2020-2021, 2025 Intel Corporation + * Copyright(c) 2018, 2020-2021, 2025-2026 Intel Corporation * * Portions of this file are derived from the ipw3945 project, as well * as portionhelp of the ieee80211 subsystem header files. @@ -482,15 +482,15 @@ static void iwlagn_rx_card_state_notif(struct iwl_priv *priv, if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | CT_CARD_DISABLED)) { - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, - CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, + CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); if (!(flags & RXON_CARD_DISABLED)) { - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, + CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); } diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/tt.c b/drivers/net/wireless/intel/iwlwifi/dvm/tt.c index fc9cf0531024..c4ee22876f77 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/tt.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. - * Copyright (C) 2018, 2020 Intel Corporation + * Copyright (C) 2018, 2020, 2026 Intel Corporation * * Portions of this file are derived from the ipw3945 project, as well * as portions of the ieee80211 subsystem header files. @@ -146,15 +146,15 @@ static void iwl_tt_check_exit_ct_kill(struct timer_list *t) if (tt->state == IWL_TI_CT_KILL) { if (priv->thermal_throttle.ct_kill_toggle) { - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, + CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); priv->thermal_throttle.ct_kill_toggle = false; } else { - iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, - CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); + iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, + CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); priv->thermal_throttle.ct_kill_toggle = true; } - iwl_read32(priv->trans, CSR_UCODE_DRV_GP1); + iwl_trans_read32(priv->trans, CSR_UCODE_DRV_GP1); if (iwl_trans_grab_nic_access(priv->trans)) iwl_trans_release_nic_access(priv->trans); diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dump.c b/drivers/net/wireless/intel/iwlwifi/fw/dump.c index bbbf3669a555..eef89c141564 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dump.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dump.c @@ -404,7 +404,7 @@ void iwl_fwrt_dump_error_logs(struct iwl_fw_runtime *fwrt) } if (fwrt->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { - u32 scratch = iwl_read32(fwrt->trans, CSR_FUNC_SCRATCH); + u32 scratch = iwl_trans_read32(fwrt->trans, CSR_FUNC_SCRATCH); IWL_ERR(fwrt, "Function Scratch status:\n"); IWL_ERR(fwrt, "0x%08X | Func Scratch\n", scratch); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-csr.h b/drivers/net/wireless/intel/iwlwifi/iwl-csr.h index ba14e583a4ad..b9f7e791dd37 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-csr.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-csr.h @@ -14,7 +14,7 @@ * low power states due to driver-invoked device resets * (e.g. CSR_RESET_REG_FLAG_SW_RESET) or uCode-driven power-saving modes. * - * Use iwl_write32() and iwl_read32() family to access these registers; + * Use iwl_trans_write32() and iwl_trans_read32() family to access these registers; * these provide simple PCI bus access, without waking up the MAC. * Do not use iwl_write_direct32() family for these registers; * no need to "grab nic access" via CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ. @@ -36,7 +36,7 @@ #define CSR_GP_CNTRL (CSR_BASE+0x024) #define CSR_FUNC_SCRATCH (CSR_BASE+0x02c) /* Scratch register - used for FW dbg */ -/* 2nd byte of CSR_INT_COALESCING, not accessible via iwl_write32()! */ +/* 2nd byte of CSR_INT_COALESCING, not accessible via iwl_trans_write32()! */ #define CSR_INT_PERIODIC_REG (CSR_BASE+0x005) /* @@ -474,7 +474,7 @@ enum { * indirect read/write via HEEP_CTRL_WRD_PCIEX_CTRL (0xEC) and * HEEP_CTRL_WRD_PCIEX_DATA (0xF4) registers. * - * Use iwl_write32()/iwl_read32() family to access these registers. The MAC HW + * Use iwl_trans_write32()/iwl_trans_read32() family to access these registers. The MAC HW * need not be powered up so no "grab inc access" is required. */ @@ -507,7 +507,7 @@ enum { * to make sure the MAC (uCode processor, etc.) is powered up for accessing * internal resources. * - * Do not use iwl_write32()/iwl_read32() family to access these registers; + * Do not use iwl_trans_write32()/iwl_trans_read32() family to access these registers; * these provide only simple PCI bus access, without waking up the MAC. */ #define HBUS_BASE (0x400) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c index 5aca343372d5..cc6044222b5c 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c @@ -931,7 +931,7 @@ static void iwl_dbg_tlv_apply_config(struct iwl_fw_runtime *fwrt, for (count = 0; count < len; count++) { address = le32_to_cpu(config_list->addr_val[count].address); value = le32_to_cpu(config_list->addr_val[count].value); - iwl_write32(fwrt->trans, address + offset, value); + iwl_trans_write32(fwrt->trans, address + offset, value); IWL_DEBUG_FW(fwrt, "WRT: CSR: count %u, add: %u val: %u\n", count, address, value); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-devtrace-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-devtrace-io.h index 0af9d8362c5b..a0cc40119890 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-devtrace-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-devtrace-io.h @@ -3,6 +3,7 @@ * * Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved. * Copyright(c) 2016-2017 Intel Deutschland GmbH + * Copyright (C) 2026 Intel Corporation *****************************************************************************/ #if !defined(__IWLWIFI_DEVICE_TRACE_IO) || defined(TRACE_HEADER_MULTI_READ) @@ -65,23 +66,6 @@ TRACE_EVENT(iwlwifi_dev_iowrite32, __get_str(dev), __entry->offs, __entry->val) ); -TRACE_EVENT(iwlwifi_dev_iowrite64, - TP_PROTO(const struct device *dev, u64 offs, u64 val), - TP_ARGS(dev, offs, val), - TP_STRUCT__entry( - DEV_ENTRY - __field(u64, offs) - __field(u64, val) - ), - TP_fast_assign( - DEV_ASSIGN; - __entry->offs = offs; - __entry->val = val; - ), - TP_printk("[%s] write io[%llu] = %llu)", - __get_str(dev), __entry->offs, __entry->val) -); - TRACE_EVENT(iwlwifi_dev_iowrite_prph32, TP_PROTO(const struct device *dev, u32 offs, u32 val), TP_ARGS(dev, offs, val), diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index 297f4550ae72..085074be2549 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -11,22 +11,6 @@ #include "iwl-csr.h" #include "iwl-debug.h" -void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val) -{ - trace_iwlwifi_dev_iowrite32(trans->dev, ofs, val); - iwl_trans_write32(trans, ofs, val); -} -IWL_EXPORT_SYMBOL(iwl_write32); - -u32 iwl_read32(struct iwl_trans *trans, u32 ofs) -{ - u32 val = iwl_trans_read32(trans, ofs); - - trace_iwlwifi_dev_ioread32(trans->dev, ofs, val); - return val; -} -IWL_EXPORT_SYMBOL(iwl_read32); - #define IWL_POLL_INTERVAL 10 /* microseconds */ int iwl_poll_bits_mask(struct iwl_trans *trans, u32 addr, @@ -35,7 +19,7 @@ int iwl_poll_bits_mask(struct iwl_trans *trans, u32 addr, int t = 0; do { - if ((iwl_read32(trans, addr) & mask) == (bits & mask)) + if ((iwl_trans_read32(trans, addr) & mask) == (bits & mask)) return 0; udelay(IWL_POLL_INTERVAL); t += IWL_POLL_INTERVAL; @@ -48,7 +32,7 @@ IWL_EXPORT_SYMBOL(iwl_poll_bits_mask); void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) { if (iwl_trans_grab_nic_access(trans)) { - iwl_write32(trans, reg, value); + iwl_trans_write32(trans, reg, value); iwl_trans_release_nic_access(trans); } } @@ -61,12 +45,6 @@ u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) return val; } -void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) -{ - trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val); - iwl_trans_write_prph_no_grab(trans, ofs, val); -} - u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) { if (iwl_trans_grab_nic_access(trans)) { @@ -86,7 +64,7 @@ void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_m { if (iwl_trans_grab_nic_access(trans)) { mdelay(delay_ms); - iwl_write_prph_no_grab(trans, ofs, val); + iwl_trans_write_prph_no_grab(trans, ofs, val); iwl_trans_release_nic_access(trans); } } @@ -95,9 +73,9 @@ IWL_EXPORT_SYMBOL(iwl_write_prph_delay); void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) { if (iwl_trans_grab_nic_access(trans)) { - iwl_write_prph_no_grab(trans, ofs, - iwl_read_prph_no_grab(trans, ofs) | - mask); + iwl_trans_write_prph_no_grab(trans, ofs, + iwl_read_prph_no_grab(trans, ofs) | + mask); iwl_trans_release_nic_access(trans); } } @@ -107,9 +85,9 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, u32 bits, u32 mask) { if (iwl_trans_grab_nic_access(trans)) { - iwl_write_prph_no_grab(trans, ofs, - (iwl_read_prph_no_grab(trans, ofs) & - mask) | bits); + iwl_trans_write_prph_no_grab(trans, ofs, + (iwl_read_prph_no_grab(trans, ofs) & + mask) | bits); iwl_trans_release_nic_access(trans); } } @@ -121,7 +99,7 @@ void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) if (iwl_trans_grab_nic_access(trans)) { val = iwl_read_prph_no_grab(trans, ofs); - iwl_write_prph_no_grab(trans, ofs, (val & ~mask)); + iwl_trans_write_prph_no_grab(trans, ofs, (val & ~mask)); iwl_trans_release_nic_access(trans); } } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h index b24c5eeca206..b33bc4822e5c 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.h @@ -8,9 +8,6 @@ #include "iwl-devtrace.h" #include "iwl-trans.h" -void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val); -u32 iwl_read32(struct iwl_trans *trans, u32 ofs); - static inline void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) { iwl_trans_set_bits_mask(trans, reg, mask, mask); @@ -34,7 +31,6 @@ void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs); u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs); -void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val); void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_ms); static inline void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index 413dd55115f8..76cba6ac0c8b 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -1312,10 +1312,10 @@ static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest) static void iwl_set_hw_address_from_csr(struct iwl_trans *trans, struct iwl_nvm_data *data) { - __le32 mac_addr0 = cpu_to_le32(iwl_read32(trans, - CSR_MAC_ADDR0_STRAP(trans))); - __le32 mac_addr1 = cpu_to_le32(iwl_read32(trans, - CSR_MAC_ADDR1_STRAP(trans))); + __le32 mac_addr0 = cpu_to_le32(iwl_trans_read32(trans, + CSR_MAC_ADDR0_STRAP(trans))); + __le32 mac_addr1 = cpu_to_le32(iwl_trans_read32(trans, + CSR_MAC_ADDR1_STRAP(trans))); iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr); /* @@ -1325,8 +1325,8 @@ static void iwl_set_hw_address_from_csr(struct iwl_trans *trans, if (is_valid_ether_addr(data->hw_addr)) return; - mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_OTP(trans))); - mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_OTP(trans))); + mac_addr0 = cpu_to_le32(iwl_trans_read32(trans, CSR_MAC_ADDR0_OTP(trans))); + mac_addr1 = cpu_to_le32(iwl_trans_read32(trans, CSR_MAC_ADDR1_OTP(trans))); iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index b3e39f0bbea4..2d0bb3de7df5 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -432,11 +432,13 @@ void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val) { iwl_trans_pcie_write32(trans, ofs, val); } +IWL_EXPORT_SYMBOL(iwl_trans_write32); u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs) { return iwl_trans_pcie_read32(trans, ofs); } +IWL_EXPORT_SYMBOL(iwl_trans_read32); u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) { @@ -460,8 +462,8 @@ void iwl_trans_force_nmi(struct iwl_trans *trans) iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, UREG_DOORBELL_TO_ISR6_NMI_BIT); else - iwl_write32(trans, CSR_DOORBELL_VECTOR, - UREG_DOORBELL_TO_ISR6_NMI_BIT); + iwl_trans_write32(trans, CSR_DOORBELL_VECTOR, + UREG_DOORBELL_TO_ISR6_NMI_BIT); } IWL_EXPORT_SYMBOL(iwl_trans_force_nmi); @@ -485,10 +487,10 @@ int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr, const u32 *vals = buf; if (iwl_trans_grab_nic_access(trans)) { - iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr); + iwl_trans_write32(trans, HBUS_TARG_MEM_WADDR, addr); for (offs = 0; offs < dwords; offs++) - iwl_write32(trans, HBUS_TARG_MEM_WDAT, - vals ? vals[offs] : 0); + iwl_trans_write32(trans, HBUS_TARG_MEM_WDAT, + vals ? vals[offs] : 0); iwl_trans_release_nic_access(trans); } else { ret = -EBUSY; diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/led.c b/drivers/net/wireless/intel/iwlwifi/mvm/led.c index c3cc1ea3ccc9..264423943b60 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/led.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/led.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* - * Copyright (C) 2012-2014, 2018-2019, 2025 Intel Corporation + * Copyright (C) 2012-2014, 2018-2019, 2025-2026 Intel Corporation * Copyright (C) 2017 Intel Deutschland GmbH */ #include @@ -38,8 +38,8 @@ static void iwl_mvm_led_set(struct iwl_mvm *mvm, bool on) return; } - iwl_write32(mvm->trans, CSR_LED_REG, - on ? CSR_LED_REG_TURN_ON : CSR_LED_REG_TURN_OFF); + iwl_trans_write32(mvm->trans, CSR_LED_REG, + on ? CSR_LED_REG_TURN_ON : CSR_LED_REG_TURN_OFF); } static void iwl_led_brightness_set(struct led_classdev *led_cdev, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c index c57b17133772..917010a7d8ef 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c @@ -317,7 +317,7 @@ void iwl_pcie_ctxt_info_v2_kick(struct iwl_trans *trans) /* kick FW self load */ iwl_pcie_write64(trans, CSR_CTXT_INFO_ADDR, trans_pcie->ctxt_info_dma_addr); iwl_pcie_write64(trans, CSR_IML_DATA_ADDR, trans_pcie->iml_dma_addr); - iwl_write32(trans, CSR_IML_SIZE_ADDR, trans_pcie->iml_len); + iwl_trans_pcie_write32(trans, CSR_IML_SIZE_ADDR, trans_pcie->iml_len); iwl_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL, CSR_AUTO_FUNC_BOOT_ENA); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c index 905482419a9a..24012005ccb8 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c @@ -1252,7 +1252,7 @@ static int _iwl_pci_resume(struct device *device, bool restore) * For older devices, just try silently to grab the NIC. */ if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { - u32 scratch = iwl_read32(trans, CSR_FUNC_SCRATCH); + u32 scratch = iwl_trans_pcie_read32(trans, CSR_FUNC_SCRATCH); if (!(scratch & CSR_FUNC_SCRATCH_POWER_OFF_MASK) || scratch == ~0U) { diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index 550c5c23a52e..96821850298f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -24,6 +24,13 @@ #include "iwl-drv.h" #include "iwl-context-info.h" +/* transport-specific register accessors (bus implementation) */ +void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val); +void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val); +u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs); +u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg); +void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val); + /* * RX related structures and functions */ @@ -593,7 +600,7 @@ static inline void iwl_pcie_clear_irq(struct iwl_trans *trans, int queue) * write 1 clear (W1C) register, meaning that it's being clear * by writing 1 to the bit. */ - iwl_write32(trans, CSR_MSIX_AUTOMASK_ST_AD, BIT(queue)); + iwl_trans_pcie_write32(trans, CSR_MSIX_AUTOMASK_ST_AD, BIT(queue)); } static inline struct iwl_trans * @@ -889,18 +896,18 @@ static inline void _iwl_disable_interrupts(struct iwl_trans *trans) clear_bit(STATUS_INT_ENABLED, &trans->status); if (!trans_pcie->msix_enabled) { /* disable interrupts from uCode/NIC to host */ - iwl_write32(trans, CSR_INT_MASK, 0x00000000); + iwl_trans_pcie_write32(trans, CSR_INT_MASK, 0x00000000); /* acknowledge/clear/reset any interrupts still pending * from uCode or flow handler (Rx/Tx DMA) */ - iwl_write32(trans, CSR_INT, 0xffffffff); - iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff); + iwl_trans_pcie_write32(trans, CSR_INT, 0xffffffff); + iwl_trans_pcie_write32(trans, CSR_FH_INT_STATUS, 0xffffffff); } else { /* disable all the interrupt we might use */ - iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, - trans_pcie->fh_init_mask); - iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, - trans_pcie->hw_init_mask); + iwl_trans_pcie_write32(trans, CSR_MSIX_FH_INT_MASK_AD, + trans_pcie->fh_init_mask); + iwl_trans_pcie_write32(trans, CSR_MSIX_HW_INT_MASK_AD, + trans_pcie->hw_init_mask); trans_pcie->fh_mask = 0; trans_pcie->hw_mask = 0; } @@ -958,7 +965,7 @@ static inline void _iwl_enable_interrupts(struct iwl_trans *trans) set_bit(STATUS_INT_ENABLED, &trans->status); if (!trans_pcie->msix_enabled) { trans_pcie->inta_mask = CSR_INI_SET_MASK; - iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); + iwl_trans_pcie_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); } else { /* * fh/hw_mask keeps all the unmasked causes. @@ -966,10 +973,10 @@ static inline void _iwl_enable_interrupts(struct iwl_trans *trans) */ trans_pcie->hw_mask = trans_pcie->hw_init_mask; trans_pcie->fh_mask = trans_pcie->fh_init_mask; - iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, - ~trans_pcie->fh_mask); - iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, - ~trans_pcie->hw_mask); + iwl_trans_pcie_write32(trans, CSR_MSIX_FH_INT_MASK_AD, + ~trans_pcie->fh_mask); + iwl_trans_pcie_write32(trans, CSR_MSIX_HW_INT_MASK_AD, + ~trans_pcie->hw_mask); } } @@ -985,7 +992,7 @@ static inline void iwl_enable_hw_int_msk_msix(struct iwl_trans *trans, u32 msk) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk); + iwl_trans_pcie_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk); trans_pcie->hw_mask = msk; } @@ -993,7 +1000,7 @@ static inline void iwl_enable_fh_int_msk_msix(struct iwl_trans *trans, u32 msk) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk); + iwl_trans_pcie_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk); trans_pcie->fh_mask = msk; } @@ -1004,10 +1011,10 @@ static inline void iwl_enable_fw_load_int(struct iwl_trans *trans) IWL_DEBUG_ISR(trans, "Enabling FW load interrupt\n"); if (!trans_pcie->msix_enabled) { trans_pcie->inta_mask = CSR_INT_BIT_FH_TX; - iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); + iwl_trans_pcie_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); } else { - iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, - trans_pcie->hw_init_mask); + iwl_trans_pcie_write32(trans, CSR_MSIX_HW_INT_MASK_AD, + trans_pcie->hw_init_mask); iwl_enable_fh_int_msk_msix(trans, MSIX_FH_INT_CAUSES_D2S_CH0_NUM); } @@ -1034,7 +1041,7 @@ static inline void iwl_enable_fw_load_int_ctx_info(struct iwl_trans *trans, else trans_pcie->inta_mask = CSR_INT_BIT_ALIVE | CSR_INT_BIT_FH_RX; - iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); + iwl_trans_pcie_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); } else { u32 val = top_reset ? MSIX_HW_INT_CAUSES_REG_RESET_DONE : MSIX_HW_INT_CAUSES_REG_ALIVE; @@ -1081,10 +1088,10 @@ static inline void iwl_enable_rfkill_int(struct iwl_trans *trans) IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n"); if (!trans_pcie->msix_enabled) { trans_pcie->inta_mask = CSR_INT_BIT_RF_KILL; - iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); + iwl_trans_pcie_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask); } else { - iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, - trans_pcie->fh_init_mask); + iwl_trans_pcie_write32(trans, CSR_MSIX_FH_INT_MASK_AD, + trans_pcie->fh_init_mask); trans_pcie->fh_mask = 0; iwl_enable_hw_int_msk_msix(trans, MSIX_HW_INT_CAUSES_REG_RF_KILL); @@ -1112,7 +1119,7 @@ static inline bool iwl_is_rfkill_set(struct iwl_trans *trans) if (trans_pcie->debug_rfkill == 1) return true; - return !(iwl_read32(trans, CSR_GP_CNTRL) & + return !(iwl_trans_pcie_read32(trans, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW); } @@ -1136,11 +1143,6 @@ void iwl_trans_pcie_op_mode_enter(struct iwl_trans *trans); int _iwl_trans_pcie_start_hw(struct iwl_trans *trans); int iwl_trans_pcie_start_hw(struct iwl_trans *trans); void iwl_trans_pcie_op_mode_leave(struct iwl_trans *trans); -void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val); -void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val); -u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs); -u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg); -void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val); int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr, void *buf, int dwords); int iwl_trans_pcie_read_mem_no_grab(struct iwl_trans *trans, u32 addr, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index fec3d6e0b146..cf6beba6041f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -179,7 +179,7 @@ static void iwl_pcie_rxq_inc_wr_ptr(struct iwl_trans *trans, */ if (!trans->mac_cfg->base->shadow_reg_enable && test_bit(STATUS_TPOWER_PMI, &trans->status)) { - reg = iwl_read32(trans, CSR_UCODE_DRV_GP1); + reg = iwl_trans_pcie_read32(trans, CSR_UCODE_DRV_GP1); if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { IWL_DEBUG_INFO(trans, "Rx queue requesting wakeup, GP1 = 0x%x\n", @@ -193,13 +193,13 @@ static void iwl_pcie_rxq_inc_wr_ptr(struct iwl_trans *trans, rxq->write_actual = round_down(rxq->write, 8); if (!trans->mac_cfg->mq_rx_supported) - iwl_write32(trans, FH_RSCSR_CHNL0_WPTR, rxq->write_actual); + iwl_trans_pcie_write32(trans, FH_RSCSR_CHNL0_WPTR, rxq->write_actual); else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) - iwl_write32(trans, HBUS_TARG_WRPTR, rxq->write_actual | - HBUS_TARG_WRPTR_RX_Q(rxq->id)); + iwl_trans_pcie_write32(trans, HBUS_TARG_WRPTR, rxq->write_actual | + HBUS_TARG_WRPTR_RX_Q(rxq->id)); else - iwl_write32(trans, RFH_Q_FRBDCB_WIDX_TRG(rxq->id), - rxq->write_actual); + iwl_trans_pcie_write32(trans, RFH_Q_FRBDCB_WIDX_TRG(rxq->id), + rxq->write_actual); } static void iwl_pcie_rxq_check_wrptr(struct iwl_trans *trans) @@ -855,22 +855,22 @@ static void iwl_pcie_rx_hw_init(struct iwl_trans *trans, struct iwl_rxq *rxq) return; /* Stop Rx DMA */ - iwl_write32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); + iwl_trans_pcie_write32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); /* reset and flush pointers */ - iwl_write32(trans, FH_MEM_RCSR_CHNL0_RBDCB_WPTR, 0); - iwl_write32(trans, FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ, 0); - iwl_write32(trans, FH_RSCSR_CHNL0_RDPTR, 0); + iwl_trans_pcie_write32(trans, FH_MEM_RCSR_CHNL0_RBDCB_WPTR, 0); + iwl_trans_pcie_write32(trans, FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ, 0); + iwl_trans_pcie_write32(trans, FH_RSCSR_CHNL0_RDPTR, 0); /* Reset driver's Rx queue write index */ - iwl_write32(trans, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); + iwl_trans_pcie_write32(trans, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); /* Tell device where to find RBD circular buffer in DRAM */ - iwl_write32(trans, FH_RSCSR_CHNL0_RBDCB_BASE_REG, - (u32)(rxq->bd_dma >> 8)); + iwl_trans_pcie_write32(trans, FH_RSCSR_CHNL0_RBDCB_BASE_REG, + (u32)(rxq->bd_dma >> 8)); /* Tell device where in DRAM to update its Rx status */ - iwl_write32(trans, FH_RSCSR_CHNL0_STTS_WPTR_REG, - rxq->rb_stts_dma >> 4); + iwl_trans_pcie_write32(trans, FH_RSCSR_CHNL0_STTS_WPTR_REG, + rxq->rb_stts_dma >> 4); /* Enable Rx DMA * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in @@ -880,13 +880,13 @@ static void iwl_pcie_rx_hw_init(struct iwl_trans *trans, struct iwl_rxq *rxq) * RB timeout 0x10 * 256 RBDs */ - iwl_write32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, - FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL | - FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY | - FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL | - rb_size | - (RX_RB_TIMEOUT << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS) | - (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS)); + iwl_trans_pcie_write32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, + FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL | + FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY | + FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL | + rb_size | + (RX_RB_TIMEOUT << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS) | + (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS)); iwl_trans_release_nic_access(trans); @@ -926,9 +926,9 @@ static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans) return; /* Stop Rx DMA */ - iwl_write_prph_no_grab(trans, RFH_RXF_DMA_CFG, 0); + iwl_pcie_write_prph_no_grab(trans, RFH_RXF_DMA_CFG, 0); /* disable free amd used rx queue operation */ - iwl_write_prph_no_grab(trans, RFH_RXF_RXQ_ACTIVE, 0); + iwl_pcie_write_prph_no_grab(trans, RFH_RXF_RXQ_ACTIVE, 0); for (i = 0; i < trans->info.num_rxqs; i++) { /* Tell device where to find RBD free table in DRAM */ @@ -944,9 +944,9 @@ static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans) RFH_Q_URBD_STTS_WPTR_LSB(i), trans_pcie->rxq[i].rb_stts_dma); /* Reset device indice tables */ - iwl_write_prph_no_grab(trans, RFH_Q_FRBDCB_WIDX(i), 0); - iwl_write_prph_no_grab(trans, RFH_Q_FRBDCB_RIDX(i), 0); - iwl_write_prph_no_grab(trans, RFH_Q_URBDCB_WIDX(i), 0); + iwl_pcie_write_prph_no_grab(trans, RFH_Q_FRBDCB_WIDX(i), 0); + iwl_pcie_write_prph_no_grab(trans, RFH_Q_FRBDCB_RIDX(i), 0); + iwl_pcie_write_prph_no_grab(trans, RFH_Q_URBDCB_WIDX(i), 0); enabled |= BIT(i) | BIT(i + 16); } @@ -958,27 +958,27 @@ static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans) * Drop frames that exceed RB size * 512 RBDs */ - iwl_write_prph_no_grab(trans, RFH_RXF_DMA_CFG, - RFH_DMA_EN_ENABLE_VAL | rb_size | - RFH_RXF_DMA_MIN_RB_4_8 | - RFH_RXF_DMA_DROP_TOO_LARGE_MASK | - RFH_RXF_DMA_RBDCB_SIZE_512); + iwl_pcie_write_prph_no_grab(trans, RFH_RXF_DMA_CFG, + RFH_DMA_EN_ENABLE_VAL | rb_size | + RFH_RXF_DMA_MIN_RB_4_8 | + RFH_RXF_DMA_DROP_TOO_LARGE_MASK | + RFH_RXF_DMA_RBDCB_SIZE_512); /* * Activate DMA snooping. * Set RX DMA chunk size to 64B for IOSF and 128B for PCIe * Default queue is 0 */ - iwl_write_prph_no_grab(trans, RFH_GEN_CFG, - RFH_GEN_CFG_RFH_DMA_SNOOP | - RFH_GEN_CFG_VAL(DEFAULT_RXQ_NUM, 0) | - RFH_GEN_CFG_SERVICE_DMA_SNOOP | - RFH_GEN_CFG_VAL(RB_CHUNK_SIZE, - trans->mac_cfg->integrated ? - RFH_GEN_CFG_RB_CHUNK_SIZE_64 : - RFH_GEN_CFG_RB_CHUNK_SIZE_128)); + iwl_pcie_write_prph_no_grab(trans, RFH_GEN_CFG, + RFH_GEN_CFG_RFH_DMA_SNOOP | + RFH_GEN_CFG_VAL(DEFAULT_RXQ_NUM, 0) | + RFH_GEN_CFG_SERVICE_DMA_SNOOP | + RFH_GEN_CFG_VAL(RB_CHUNK_SIZE, + trans->mac_cfg->integrated ? + RFH_GEN_CFG_RB_CHUNK_SIZE_64 : + RFH_GEN_CFG_RB_CHUNK_SIZE_128)); /* Enable the relevant rx queues */ - iwl_write_prph_no_grab(trans, RFH_RXF_RXQ_ACTIVE, enabled); + iwl_pcie_write_prph_no_grab(trans, RFH_RXF_RXQ_ACTIVE, enabled); iwl_trans_release_nic_access(trans); @@ -1709,7 +1709,7 @@ static void iwl_pcie_irq_handle_error(struct iwl_trans *trans) } if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_SC) { - u32 val = iwl_read32(trans, CSR_IPC_STATE); + u32 val = iwl_trans_pcie_read32(trans, CSR_IPC_STATE); if (val & CSR_IPC_STATE_TOP_RESET_REQ) { IWL_ERR(trans, "FW requested TOP reset for FSEQ\n"); @@ -1734,7 +1734,7 @@ static u32 iwl_pcie_int_cause_non_ict(struct iwl_trans *trans) trace_iwlwifi_dev_irq(trans->dev); /* Discover which interrupts are active/pending */ - inta = iwl_read32(trans, CSR_INT); + inta = iwl_trans_pcie_read32(trans, CSR_INT); /* the thread will service interrupts and re-enable them */ return inta; @@ -1851,7 +1851,7 @@ static void iwl_trans_pcie_handle_reset_interrupt(struct iwl_trans *trans) u32 state; if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_SC) { - u32 val = iwl_read32(trans, CSR_IPC_STATE); + u32 val = iwl_trans_pcie_read32(trans, CSR_IPC_STATE); state = u32_get_bits(val, CSR_IPC_STATE_RESET); IWL_DEBUG_ISR(trans, "IPC state = 0x%x/%d\n", val, state); @@ -1923,8 +1923,8 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x(sw), enabled(hw) 0x%08x, fh 0x%08x\n", inta, trans_pcie->inta_mask, - iwl_read32(trans, CSR_INT_MASK), - iwl_read32(trans, CSR_FH_INT_STATUS)); + iwl_trans_pcie_read32(trans, CSR_INT_MASK), + iwl_trans_pcie_read32(trans, CSR_FH_INT_STATUS)); if (inta & (~trans_pcie->inta_mask)) IWL_DEBUG_ISR(trans, "We got a masked interrupt (0x%08x)\n", @@ -1972,11 +1972,11 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) * hardware bugs here by ACKing all the possible interrupts so that * interrupt coalescing can still be achieved. */ - iwl_write32(trans, CSR_INT, inta | ~trans_pcie->inta_mask); + iwl_trans_pcie_write32(trans, CSR_INT, inta | ~trans_pcie->inta_mask); if (iwl_have_debug_level(IWL_DL_ISR)) IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n", - inta, iwl_read32(trans, CSR_INT_MASK)); + inta, iwl_trans_pcie_read32(trans, CSR_INT_MASK)); spin_unlock_bh(&trans_pcie->irq_lock); @@ -2071,13 +2071,13 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) IWL_DEBUG_ISR(trans, "Rx interrupt\n"); if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); - iwl_write32(trans, CSR_FH_INT_STATUS, - CSR_FH_INT_RX_MASK); + iwl_trans_pcie_write32(trans, CSR_FH_INT_STATUS, + CSR_FH_INT_RX_MASK); } if (inta & CSR_INT_BIT_RX_PERIODIC) { handled |= CSR_INT_BIT_RX_PERIODIC; - iwl_write32(trans, - CSR_INT, CSR_INT_BIT_RX_PERIODIC); + iwl_trans_pcie_write32(trans, + CSR_INT, CSR_INT_BIT_RX_PERIODIC); } /* Sending RX interrupt require many steps to be done in the * device: @@ -2117,7 +2117,7 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) /* This "Tx" DMA channel is used only for loading uCode */ if (inta & CSR_INT_BIT_FH_TX) { - iwl_write32(trans, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK); + iwl_trans_pcie_write32(trans, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK); IWL_DEBUG_ISR(trans, "uCode load interrupt\n"); isr_stats->tx++; handled |= CSR_INT_BIT_FH_TX; @@ -2231,10 +2231,10 @@ void iwl_pcie_reset_ict(struct iwl_trans *trans) IWL_DEBUG_ISR(trans, "CSR_DRAM_INT_TBL_REG =0x%x\n", val); - iwl_write32(trans, CSR_DRAM_INT_TBL_REG, val); + iwl_trans_pcie_write32(trans, CSR_DRAM_INT_TBL_REG, val); trans_pcie->use_ict = true; trans_pcie->ict_index = 0; - iwl_write32(trans, CSR_INT, trans_pcie->inta_mask); + iwl_trans_pcie_write32(trans, CSR_INT, trans_pcie->inta_mask); _iwl_enable_interrupts(trans); spin_unlock_bh(&trans_pcie->irq_lock); } @@ -2261,7 +2261,7 @@ irqreturn_t iwl_pcie_isr(int irq, void *data) * If we have something to service, the tasklet will re-enable ints. * If we *don't* have something, we'll re-enable before leaving here. */ - iwl_write32(trans, CSR_INT_MASK, 0x00000000); + iwl_trans_pcie_write32(trans, CSR_INT_MASK, 0x00000000); return IRQ_WAKE_THREAD; } @@ -2291,13 +2291,13 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id) lock_map_acquire(&trans->sync_cmd_lockdep_map); spin_lock_bh(&trans_pcie->irq_lock); - inta_fh = iwl_read32(trans, CSR_MSIX_FH_INT_CAUSES_AD); - inta_hw = iwl_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD); + inta_fh = iwl_trans_pcie_read32(trans, CSR_MSIX_FH_INT_CAUSES_AD); + inta_hw = iwl_trans_pcie_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD); /* * Clear causes registers to avoid being handling the same cause. */ - iwl_write32(trans, CSR_MSIX_FH_INT_CAUSES_AD, inta_fh & inta_fh_msk); - iwl_write32(trans, CSR_MSIX_HW_INT_CAUSES_AD, inta_hw); + iwl_trans_pcie_write32(trans, CSR_MSIX_FH_INT_CAUSES_AD, inta_fh & inta_fh_msk); + iwl_trans_pcie_write32(trans, CSR_MSIX_HW_INT_CAUSES_AD, inta_hw); spin_unlock_bh(&trans_pcie->irq_lock); trace_iwlwifi_dev_irq_msix(trans->dev, entry, true, inta_fh, inta_hw); @@ -2312,7 +2312,7 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id) IWL_DEBUG_ISR(trans, "ISR[%d] inta_fh 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n", entry->entry, inta_fh, trans_pcie->fh_mask, - iwl_read32(trans, CSR_MSIX_FH_INT_MASK_AD)); + iwl_trans_pcie_read32(trans, CSR_MSIX_FH_INT_MASK_AD)); if (inta_fh & ~trans_pcie->fh_mask) IWL_DEBUG_ISR(trans, "We got a masked interrupt (0x%08x)\n", @@ -2414,7 +2414,7 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id) IWL_DEBUG_ISR(trans, "ISR[%d] inta_hw 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n", entry->entry, inta_hw, trans_pcie->hw_mask, - iwl_read32(trans, CSR_MSIX_HW_INT_MASK_AD)); + iwl_trans_pcie_read32(trans, CSR_MSIX_HW_INT_MASK_AD)); if (inta_hw & ~trans_pcie->hw_mask) IWL_DEBUG_ISR(trans, "We got a masked interrupt 0x%08x\n", diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c index 39dd963920b3..91d0b935fca6 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c @@ -111,8 +111,8 @@ _iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans, iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, UREG_DOORBELL_TO_ISR6_RESET_HANDSHAKE); else - iwl_write32(trans, CSR_DOORBELL_VECTOR, - UREG_DOORBELL_TO_ISR6_RESET_HANDSHAKE); + iwl_trans_pcie_write32(trans, CSR_DOORBELL_VECTOR, + UREG_DOORBELL_TO_ISR6_RESET_HANDSHAKE); /* wait 200ms */ ret = wait_event_timeout(trans_pcie->fw_reset_waitq, @@ -123,11 +123,11 @@ _iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans, u32 inta_hw; if (trans_pcie->msix_enabled) { - inta_hw = iwl_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD); + inta_hw = iwl_trans_pcie_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD); reset_done = inta_hw & MSIX_HW_INT_CAUSES_REG_RESET_DONE; } else { - inta_hw = iwl_read32(trans, CSR_INT); + inta_hw = iwl_trans_pcie_read32(trans, CSR_INT); reset_done = inta_hw & CSR_INT_BIT_RESET_DONE; } @@ -434,7 +434,7 @@ static bool iwl_pcie_set_ltr(struct iwl_trans *trans) if ((trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_AX210 || trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_22000) && !trans->mac_cfg->integrated) { - iwl_write32(trans, CSR_LTR_LONG_VAL_AD, ltr_val); + iwl_trans_pcie_write32(trans, CSR_LTR_LONG_VAL_AD, ltr_val); return true; } @@ -447,8 +447,8 @@ static bool iwl_pcie_set_ltr(struct iwl_trans *trans) if (trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_AX210) { /* First clear the interrupt, just in case */ - iwl_write32(trans, CSR_MSIX_HW_INT_CAUSES_AD, - MSIX_HW_INT_CAUSES_REG_IML); + iwl_trans_pcie_write32(trans, CSR_MSIX_HW_INT_CAUSES_AD, + MSIX_HW_INT_CAUSES_REG_IML); /* In this case, unfortunately the same ROM bug exists in the * device (not setting LTR correctly), but we don't have control * over the settings from the host due to some hardware security @@ -475,18 +475,18 @@ static void iwl_pcie_spin_for_iml(struct iwl_trans *trans) if (WARN_ON(!trans_pcie->iml)) return; - value = iwl_read32(trans, CSR_LTR_LAST_MSG); + value = iwl_trans_pcie_read32(trans, CSR_LTR_LAST_MSG); IWL_DEBUG_INFO(trans, "Polling for IML load - CSR_LTR_LAST_MSG=0x%x\n", value); while (time_before(jiffies, end_time)) { - if (iwl_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD) & + if (iwl_trans_pcie_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD) & MSIX_HW_INT_CAUSES_REG_IML) { irq = true; break; } /* Keep the CPU and device busy. */ - value = iwl_read32(trans, CSR_LTR_LAST_MSG); + value = iwl_trans_pcie_read32(trans, CSR_LTR_LAST_MSG); loops++; } @@ -522,7 +522,7 @@ again: iwl_enable_rfkill_int(trans); - iwl_write32(trans, CSR_INT, 0xFFFFFFFF); + iwl_trans_pcie_write32(trans, CSR_INT, 0xFFFFFFFF); /* * We enabled the RF-Kill interrupt and the handler may very @@ -550,12 +550,12 @@ again: } /* make sure rfkill handshake bits are cleared */ - iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); + iwl_trans_pcie_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl_trans_pcie_write32(trans, CSR_UCODE_DRV_GP1_CLR, + CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); /* clear (again), then enable host interrupts */ - iwl_write32(trans, CSR_INT, 0xFFFFFFFF); + iwl_trans_pcie_write32(trans, CSR_INT, 0xFFFFFFFF); ret = iwl_pcie_gen2_nic_init(trans); if (ret) { @@ -591,8 +591,8 @@ again: if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { IWL_DEBUG_POWER(trans, "function scratch register value is 0x%08x\n", - iwl_read32(trans, CSR_FUNC_SCRATCH)); - iwl_write32(trans, CSR_FUNC_SCRATCH, CSR_FUNC_SCRATCH_INIT_VALUE); + iwl_trans_pcie_read32(trans, CSR_FUNC_SCRATCH)); + iwl_trans_pcie_write32(trans, CSR_FUNC_SCRATCH, CSR_FUNC_SCRATCH_INIT_VALUE); iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_ROM_START); } else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index b81dd7daca6c..8dc8924564e5 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -44,10 +44,10 @@ static void iwl_dump_host_monitor_block(struct iwl_trans *trans, int i; IWL_ERR(trans, "Host monitor block 0x%x vector 0x%x\n", block, vec); - iwl_write32(trans, CSR_MONITOR_CFG_REG, (block << 8) | vec); + iwl_trans_pcie_write32(trans, CSR_MONITOR_CFG_REG, (block << 8) | vec); for (i = 0; i < iter; i++) IWL_ERR(trans, " value [iter %d]: 0x%08x\n", - i, iwl_read32(trans, CSR_MONITOR_STATUS_REG)); + i, iwl_trans_pcie_read32(trans, CSR_MONITOR_STATUS_REG)); } static void iwl_pcie_dump_host_monitor(struct iwl_trans *trans) @@ -56,7 +56,7 @@ static void iwl_pcie_dump_host_monitor(struct iwl_trans *trans) case IWL_DEVICE_FAMILY_22000: case IWL_DEVICE_FAMILY_AX210: IWL_ERR(trans, "CSR_RESET = 0x%x\n", - iwl_read32(trans, CSR_RESET)); + iwl_trans_pcie_read32(trans, CSR_RESET)); iwl_dump_host_monitor_block(trans, IWL_HOST_MON_BLOCK_PEMON, IWL_HOST_MON_BLOCK_PEMON_VEC0, 15); iwl_dump_host_monitor_block(trans, IWL_HOST_MON_BLOCK_PEMON, @@ -170,16 +170,16 @@ void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans, u8 max_power) static u32 iwl_trans_pcie_read_shr(struct iwl_trans *trans, u32 reg) { - iwl_write32(trans, HEEP_CTRL_WRD_PCIEX_CTRL_REG, - ((reg & 0x0000ffff) | (2 << 28))); - return iwl_read32(trans, HEEP_CTRL_WRD_PCIEX_DATA_REG); + iwl_trans_pcie_write32(trans, HEEP_CTRL_WRD_PCIEX_CTRL_REG, + ((reg & 0x0000ffff) | (2 << 28))); + return iwl_trans_pcie_read32(trans, HEEP_CTRL_WRD_PCIEX_DATA_REG); } static void iwl_trans_pcie_write_shr(struct iwl_trans *trans, u32 reg, u32 val) { - iwl_write32(trans, HEEP_CTRL_WRD_PCIEX_DATA_REG, val); - iwl_write32(trans, HEEP_CTRL_WRD_PCIEX_CTRL_REG, - ((reg & 0x0000ffff) | (3 << 28))); + iwl_trans_pcie_write32(trans, HEEP_CTRL_WRD_PCIEX_DATA_REG, val); + iwl_trans_pcie_write32(trans, HEEP_CTRL_WRD_PCIEX_CTRL_REG, + ((reg & 0x0000ffff) | (3 << 28))); } static void iwl_pcie_set_pwr(struct iwl_trans *trans, bool vaux) @@ -603,28 +603,28 @@ static void iwl_pcie_load_firmware_chunk_fh(struct iwl_trans *trans, u32 dst_addr, dma_addr_t phy_addr, u32 byte_cnt) { - iwl_write32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), - FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE); + iwl_trans_pcie_write32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), + FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE); - iwl_write32(trans, FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), - dst_addr); + iwl_trans_pcie_write32(trans, FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), + dst_addr); - iwl_write32(trans, FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL), - phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK); + iwl_trans_pcie_write32(trans, FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL), + phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK); - iwl_write32(trans, FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), - (iwl_get_dma_hi_addr(phy_addr) - << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt); + iwl_trans_pcie_write32(trans, FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), + (iwl_get_dma_hi_addr(phy_addr) + << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt); - iwl_write32(trans, FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL), - BIT(FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM) | - BIT(FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX) | - FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID); + iwl_trans_pcie_write32(trans, FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL), + BIT(FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM) | + BIT(FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX) | + FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID); - iwl_write32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), - FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | - FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE | - FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD); + iwl_trans_pcie_write32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), + FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | + FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE | + FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD); } static int iwl_pcie_load_firmware_chunk(struct iwl_trans *trans, @@ -884,7 +884,7 @@ void iwl_pcie_apply_destination(struct iwl_trans *trans) switch (dest->reg_ops[i].op) { case CSR_ASSIGN: - iwl_write32(trans, addr, val); + iwl_trans_pcie_write32(trans, addr, val); break; case CSR_SETBIT: iwl_set_bit(trans, addr, BIT(val)); @@ -964,7 +964,7 @@ static int iwl_pcie_load_given_ucode(struct iwl_trans *trans, iwl_enable_interrupts(trans); /* release CPU reset */ - iwl_write32(trans, CSR_RESET, 0); + iwl_trans_pcie_write32(trans, CSR_RESET, 0); return 0; } @@ -1123,7 +1123,7 @@ static void iwl_pcie_map_rx_causes(struct iwl_trans *trans) MSIX_FH_INT_CAUSES_Q(idx - offset)); val |= BIT(MSIX_FH_INT_CAUSES_Q(idx)); } - iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~val); + iwl_trans_pcie_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~val); val = MSIX_FH_INT_CAUSES_Q(0); if (trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_NON_RX) @@ -1174,9 +1174,9 @@ static void iwl_pcie_init_msix(struct iwl_trans_pcie *trans_pcie) if (!trans_pcie->msix_enabled) return; - trans_pcie->fh_init_mask = ~iwl_read32(trans, CSR_MSIX_FH_INT_MASK_AD); + trans_pcie->fh_init_mask = ~iwl_trans_pcie_read32(trans, CSR_MSIX_FH_INT_MASK_AD); trans_pcie->fh_mask = trans_pcie->fh_init_mask; - trans_pcie->hw_init_mask = ~iwl_read32(trans, CSR_MSIX_HW_INT_MASK_AD); + trans_pcie->hw_init_mask = ~iwl_trans_pcie_read32(trans, CSR_MSIX_HW_INT_MASK_AD); trans_pcie->hw_mask = trans_pcie->hw_init_mask; } @@ -1296,7 +1296,7 @@ int iwl_trans_pcie_start_fw(struct iwl_trans *trans, iwl_enable_rfkill_int(trans); - iwl_write32(trans, CSR_INT, 0xFFFFFFFF); + iwl_trans_pcie_write32(trans, CSR_INT, 0xFFFFFFFF); /* * We enabled the RF-Kill interrupt and the handler may very @@ -1326,12 +1326,12 @@ int iwl_trans_pcie_start_fw(struct iwl_trans *trans, } /* make sure rfkill handshake bits are cleared */ - iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); + iwl_trans_pcie_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl_trans_pcie_write32(trans, CSR_UCODE_DRV_GP1_CLR, + CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); /* clear (again), then enable host interrupts */ - iwl_write32(trans, CSR_INT, 0xFFFFFFFF); + iwl_trans_pcie_write32(trans, CSR_INT, 0xFFFFFFFF); ret = iwl_pcie_nic_init(trans); if (ret) { @@ -1349,8 +1349,8 @@ int iwl_trans_pcie_start_fw(struct iwl_trans *trans, iwl_enable_fw_load_int(trans); /* really make sure rfkill handshake bits are cleared */ - iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl_trans_pcie_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl_trans_pcie_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); /* Load the given image to the HW */ if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_8000) @@ -1482,9 +1482,9 @@ static int iwl_pcie_d3_handshake(struct iwl_trans *trans, bool suspend) suspend ? UREG_DOORBELL_TO_ISR6_SUSPEND : UREG_DOORBELL_TO_ISR6_RESUME); else - iwl_write32(trans, CSR_IPC_SLEEP_CONTROL, - suspend ? CSR_IPC_SLEEP_CONTROL_SUSPEND : - CSR_IPC_SLEEP_CONTROL_RESUME); + iwl_trans_pcie_write32(trans, CSR_IPC_SLEEP_CONTROL, + suspend ? CSR_IPC_SLEEP_CONTROL_SUSPEND : + CSR_IPC_SLEEP_CONTROL_RESUME); ret = wait_event_timeout(trans_pcie->sx_waitq, trans_pcie->sx_state != IWL_SX_WAITING, @@ -1579,7 +1579,7 @@ int iwl_trans_pcie_d3_resume(struct iwl_trans *trans, IWL_DEBUG_POWER(trans, "WFPM value upon resume = 0x%08X\n", iwl_read_umac_prph(trans, WFPM_GP2)); - val = iwl_read32(trans, CSR_RESET); + val = iwl_trans_pcie_read32(trans, CSR_RESET); if (val & CSR_RESET_REG_FLAG_NEVO_RESET) { IWL_INFO(trans, "Device was reset during suspend\n"); trans->state = IWL_TRANS_NO_FW; @@ -1870,12 +1870,16 @@ void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val) void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val) { + trace_iwlwifi_dev_iowrite32(trans->dev, ofs, val); writel(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs); } u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs) { - return readl(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs); + u32 val = readl(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs); + + trace_iwlwifi_dev_ioread32(trans->dev, ofs, val); + return val; } static u32 iwl_trans_pcie_prph_msk(struct iwl_trans *trans) @@ -1899,6 +1903,7 @@ void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val) { u32 mask = iwl_trans_pcie_prph_msk(trans); + trace_iwlwifi_dev_iowrite_prph32(trans->dev, addr, val); iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WADDR, ((addr & mask) | (3 << 24))); iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WDAT, val); @@ -2377,7 +2382,7 @@ bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) */ ret = iwl_poll_bits_mask(trans, CSR_GP_CNTRL, poll, mask, 15000); if (unlikely(ret)) { - u32 cntrl = iwl_read32(trans, CSR_GP_CNTRL); + u32 cntrl = iwl_trans_pcie_read32(trans, CSR_GP_CNTRL); if (silent) { spin_unlock(&trans_pcie->reg_lock); @@ -2394,8 +2399,8 @@ bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) iwl_trans_pcie_reset(trans, IWL_RESET_MODE_REMOVE_ONLY); else - iwl_write32(trans, CSR_RESET, - CSR_RESET_REG_FLAG_FORCE_NMI); + iwl_trans_pcie_write32(trans, CSR_RESET, + CSR_RESET_REG_FLAG_FORCE_NMI); spin_unlock(&trans_pcie->reg_lock); return false; @@ -2473,12 +2478,12 @@ int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr, bool resched = false; if (iwl_trans_grab_nic_access(trans)) { - iwl_write32(trans, HBUS_TARG_MEM_RADDR, - addr + 4 * offs); + iwl_trans_pcie_write32(trans, HBUS_TARG_MEM_RADDR, + addr + 4 * offs); while (offs < dwords) { - vals[offs] = iwl_read32(trans, - HBUS_TARG_MEM_RDAT); + vals[offs] = iwl_trans_pcie_read32(trans, + HBUS_TARG_MEM_RDAT); if (iwl_trans_is_hw_error_value(vals[offs])) num_consec_hw_errors++; @@ -2525,11 +2530,11 @@ int iwl_trans_pcie_read_mem_no_grab(struct iwl_trans *trans, u32 addr, unsigned long end = jiffies + HZ / 2; bool resched = false; - iwl_write32(trans, HBUS_TARG_MEM_RADDR, - addr + 4 * offs); + iwl_trans_pcie_write32(trans, HBUS_TARG_MEM_RADDR, + addr + 4 * offs); while (offs < dwords) { - vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT); + vals[offs] = iwl_trans_pcie_read32(trans, HBUS_TARG_MEM_RDAT); if (iwl_trans_is_hw_error_value(vals[offs])) num_consec_hw_errors++; @@ -2746,7 +2751,7 @@ void iwl_pcie_dump_csr(struct iwl_trans *trans) for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) { IWL_ERR(trans, " %25s: 0X%08x\n", get_csr_string(csr_tbl[i]), - iwl_read32(trans, csr_tbl[i])); + iwl_trans_pcie_read32(trans, csr_tbl[i])); } } @@ -3022,7 +3027,7 @@ static ssize_t iwl_dbgfs_rfkill_read(struct file *file, pos = scnprintf(buf, sizeof(buf), "debug: %d\nhw: %d\n", trans_pcie->debug_rfkill, - !(iwl_read32(trans, CSR_GP_CNTRL) & + !(iwl_trans_pcie_read32(trans, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)); return simple_read_from_buffer(user_buf, count, ppos, buf, pos); @@ -3593,12 +3598,12 @@ void iwl_trans_pcie_sync_nmi(struct iwl_trans *trans) iwl_trans_force_nmi(trans); while (time_after(timeout, jiffies)) { - u32 inta_hw = iwl_read32(trans, inta_addr); + u32 inta_hw = iwl_trans_pcie_read32(trans, inta_addr); /* Error detected by uCode */ if (inta_hw & sw_err_bit) { /* Clear causes register */ - iwl_write32(trans, inta_addr, inta_hw & sw_err_bit); + iwl_trans_pcie_write32(trans, inta_addr, inta_hw & sw_err_bit); break; } @@ -4044,7 +4049,7 @@ static void iwl_pcie_recheck_me_status(struct work_struct *wk) me_recheck_wk.work); u32 val; - val = iwl_read32(trans_pcie->trans, CSR_HW_IF_CONFIG_REG); + val = iwl_trans_pcie_read32(trans_pcie->trans, CSR_HW_IF_CONFIG_REG); trans_pcie->me_present = !!(val & CSR_HW_IF_CONFIG_REG_IAMT_UP); } @@ -4062,14 +4067,14 @@ static void iwl_pcie_check_me_status(struct iwl_trans *trans) if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_BZ) return; - val = iwl_read_prph(trans, CNVI_SCU_REG_FOR_ECO_1); + val = iwl_trans_pcie_read_prph(trans, CNVI_SCU_REG_FOR_ECO_1); if (val & CNVI_SCU_REG_FOR_ECO_1_WIAMT_KNOWN) { trans_pcie->me_present = !!(val & CNVI_SCU_REG_FOR_ECO_1_WIAMT_PRESENT); return; } - val = iwl_read32(trans, CSR_HW_IF_CONFIG_REG); + val = iwl_trans_pcie_read32(trans, CSR_HW_IF_CONFIG_REG); if (val & (CSR_HW_IF_CONFIG_REG_ME_OWN | CSR_HW_IF_CONFIG_REG_IAMT_UP)) { trans_pcie->me_present = 1; @@ -4127,7 +4132,7 @@ int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, } } - info.hw_rf_id = iwl_read32(iwl_trans, CSR_HW_RF_ID); + info.hw_rf_id = iwl_trans_pcie_read32(iwl_trans, CSR_HW_RF_ID); /* * The RF_ID is set to zero in blank OTP so read version to diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c index 27f4973791d0..abdb2548827f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* * Copyright (C) 2017 Intel Deutschland GmbH - * Copyright (C) 2018-2020, 2023-2025 Intel Corporation + * Copyright (C) 2018-2020, 2023-2026 Intel Corporation */ #include #include @@ -711,7 +711,7 @@ static void iwl_txq_inc_wr_ptr(struct iwl_trans *trans, struct iwl_txq *txq) * if not in power-save mode, uCode will never sleep when we're * trying to tx (during RFKILL, we're not trying to tx). */ - iwl_write32(trans, HBUS_TARG_WRPTR, txq->write_ptr | (txq->id << 16)); + iwl_trans_pcie_write32(trans, HBUS_TARG_WRPTR, txq->write_ptr | (txq->id << 16)); } int iwl_txq_gen2_tx(struct iwl_trans *trans, struct sk_buff *skb, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index bdd330280689..f5aa456180d8 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -99,7 +99,7 @@ static void iwl_pcie_txq_inc_wr_ptr(struct iwl_trans *trans, * uCode will wake up, and interrupt us again, so next * time we'll skip this part. */ - reg = iwl_read32(trans, CSR_UCODE_DRV_GP1); + reg = iwl_trans_pcie_read32(trans, CSR_UCODE_DRV_GP1); if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { IWL_DEBUG_INFO(trans, "Tx queue %d requesting wakeup, GP1 = 0x%x\n", @@ -117,8 +117,8 @@ static void iwl_pcie_txq_inc_wr_ptr(struct iwl_trans *trans, */ IWL_DEBUG_TX(trans, "Q:%d WR: 0x%x\n", txq_id, txq->write_ptr); if (!txq->block) - iwl_write32(trans, HBUS_TARG_WRPTR, - txq->write_ptr | (txq_id << 8)); + iwl_trans_pcie_write32(trans, HBUS_TARG_WRPTR, + txq->write_ptr | (txq_id << 8)); } void iwl_pcie_txq_check_wrptrs(struct iwl_trans *trans) @@ -586,7 +586,7 @@ static void iwl_pcie_tx_stop_fh(struct iwl_trans *trans) /* Stop each Tx DMA channel */ for (ch = 0; ch < FH_TCSR_CHNL_NUM; ch++) { - iwl_write32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0); + iwl_trans_pcie_write32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0); mask |= FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch); } @@ -595,7 +595,7 @@ static void iwl_pcie_tx_stop_fh(struct iwl_trans *trans) if (ret) IWL_ERR(trans, "Failing on timeout while stopping DMA channel %d [0x%08x]\n", - ch, iwl_read32(trans, FH_TSSR_TX_STATUS_REG)); + ch, iwl_trans_pcie_read32(trans, FH_TSSR_TX_STATUS_REG)); iwl_trans_release_nic_access(trans); @@ -1335,8 +1335,8 @@ static void iwl_trans_pcie_block_txq_ptrs(struct iwl_trans *trans, bool block) if (!block && !(WARN_ON_ONCE(!txq->block))) { txq->block--; if (!txq->block) { - iwl_write32(trans, HBUS_TARG_WRPTR, - txq->write_ptr | (i << 8)); + iwl_trans_pcie_write32(trans, HBUS_TARG_WRPTR, + txq->write_ptr | (i << 8)); } } else if (block) { txq->block++; diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c index bace3e21989c..4365ffb0fd37 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c @@ -51,7 +51,7 @@ void iwl_trans_pcie_dump_regs(struct iwl_trans *trans, struct pci_dev *pdev) IWL_ERR(trans, "iwlwifi device memory mapped registers:\n"); for (i = 0, ptr = buf; i < PCI_MEM_DUMP_SIZE; i += 4, ptr++) - *ptr = iwl_read32(trans, i); + *ptr = iwl_trans_pcie_read32(trans, i); print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32, 4, buf, i, 0); pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); @@ -106,7 +106,7 @@ out: u32 iwl_pcie_read_direct32(struct iwl_trans *trans, u32 reg) { if (iwl_trans_grab_nic_access(trans)) { - u32 value = iwl_read32(trans, reg); + u32 value = iwl_trans_pcie_read32(trans, reg); iwl_trans_release_nic_access(trans); return value; @@ -176,8 +176,8 @@ int iwl_pcie_poll_umac_prph_bits_no_grab(struct iwl_trans *trans, u32 addr, void iwl_pcie_write_prph64_no_grab(struct iwl_trans *trans, u32 ofs, u64 val) { trace_iwlwifi_dev_iowrite_prph64(trans->dev, ofs, val); - iwl_write_prph_no_grab(trans, ofs, val & 0xffffffff); - iwl_write_prph_no_grab(trans, ofs + 4, val >> 32); + iwl_pcie_write_prph_no_grab(trans, ofs, val & 0xffffffff); + iwl_pcie_write_prph_no_grab(trans, ofs + 4, val >> 32); } void iwl_pcie_write_direct64(struct iwl_trans *trans, u64 reg, u64 value) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h index 341928cdb64b..2d92bff513df 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h @@ -7,6 +7,7 @@ #define __iwl_pcie_utils_h__ #include "iwl-io.h" +#include "internal.h" void iwl_trans_pcie_dump_regs(struct iwl_trans *trans, struct pci_dev *pdev); @@ -24,16 +25,15 @@ void iwl_pcie_write_direct64(struct iwl_trans *trans, u64 reg, u64 value); static inline void iwl_pcie_write64(struct iwl_trans *trans, u64 ofs, u64 val) { - trace_iwlwifi_dev_iowrite64(trans->dev, ofs, val); - iwl_trans_write32(trans, ofs, lower_32_bits(val)); - iwl_trans_write32(trans, ofs + 4, upper_32_bits(val)); + iwl_trans_pcie_write32(trans, ofs, lower_32_bits(val)); + iwl_trans_pcie_write32(trans, ofs + 4, upper_32_bits(val)); } static inline void iwl_pcie_write_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) { - iwl_write_prph_no_grab(trans, ofs + trans->mac_cfg->umac_prph_offset, - val); + iwl_pcie_write_prph_no_grab(trans, ofs + trans->mac_cfg->umac_prph_offset, + val); } static inline void _iwl_trans_set_bits_mask(struct iwl_trans *trans, @@ -45,10 +45,10 @@ static inline void _iwl_trans_set_bits_mask(struct iwl_trans *trans, WARN_ON_ONCE(value & ~mask); #endif - v = iwl_read32(trans, reg); + v = iwl_trans_pcie_read32(trans, reg); v &= ~mask; v |= value; - iwl_write32(trans, reg, v); + iwl_trans_pcie_write32(trans, reg, v); } static inline void iwl_trans_clear_bit(struct iwl_trans *trans, From a35d782c25f5d8f5fe0e90a7af7099973e115cba Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:44 +0300 Subject: [PATCH 1591/2126] wifi: iwlwifi: rename iwl_trans_read_prph Functions that assume that nic access was acquired should have a _no_grab postfix, so the caller will know that he is responsible to have access when calling it. Add the postfix. Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.3441b513bd7f.If88dcac92f705918b550fd3e524196be1f8d92d0@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/dbg-old.c | 86 +++++++++---------- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 38 ++++---- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 2 +- .../wireless/intel/iwlwifi/iwl-nvm-parse.c | 8 +- .../net/wireless/intel/iwlwifi/iwl-trans.c | 2 +- .../net/wireless/intel/iwlwifi/iwl-trans.h | 2 +- 6 files changed, 69 insertions(+), 69 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c index a4e1f82c8bd1..320e891b3b03 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c @@ -48,7 +48,7 @@ static void iwl_read_radio_regs(struct iwl_fw_runtime *fwrt, rd_cmd |= i << RADIO_RSP_ADDR_POS; iwl_trans_write_prph_no_grab(fwrt->trans, RSP_RADIO_CMD, rd_cmd); - *pos = (u8)iwl_trans_read_prph(fwrt->trans, RSP_RADIO_RDDAT); + *pos = (u8)iwl_trans_read_prph_no_grab(fwrt->trans, RSP_RADIO_RDDAT); pos++; } @@ -81,20 +81,20 @@ static void iwl_fwrt_dump_rxf(struct iwl_fw_runtime *fwrt, fifo_hdr->fifo_num = cpu_to_le32(fifo_num); fifo_hdr->available_bytes = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - RXF_RD_D_SPACE + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + RXF_RD_D_SPACE + offset)); fifo_hdr->wr_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - RXF_RD_WR_PTR + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + RXF_RD_WR_PTR + offset)); fifo_hdr->rd_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - RXF_RD_RD_PTR + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + RXF_RD_RD_PTR + offset)); fifo_hdr->fence_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - RXF_RD_FENCE_PTR + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + RXF_RD_FENCE_PTR + offset)); fifo_hdr->fence_mode = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - RXF_SET_FENCE_MODE + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + RXF_SET_FENCE_MODE + offset)); /* Lock fence */ iwl_trans_write_prph_no_grab(fwrt->trans, RXF_SET_FENCE_MODE + offset, 0x1); @@ -107,9 +107,9 @@ static void iwl_fwrt_dump_rxf(struct iwl_fw_runtime *fwrt, /* Read FIFO */ fifo_len /= sizeof(u32); /* Size in DWORDS */ for (i = 0; i < fifo_len; i++) - fifo_data[i] = iwl_trans_read_prph(fwrt->trans, - RXF_FIFO_RD_FENCE_INC + - offset); + fifo_data[i] = iwl_trans_read_prph_no_grab(fwrt->trans, + RXF_FIFO_RD_FENCE_INC + + offset); *dump_data = iwl_fw_error_next_data(*dump_data); } @@ -136,33 +136,33 @@ static void iwl_fwrt_dump_txf(struct iwl_fw_runtime *fwrt, fifo_hdr->fifo_num = cpu_to_le32(fifo_num); fifo_hdr->available_bytes = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_FIFO_ITEM_CNT + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_FIFO_ITEM_CNT + offset)); fifo_hdr->wr_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_WR_PTR + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_WR_PTR + offset)); fifo_hdr->rd_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_RD_PTR + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_RD_PTR + offset)); fifo_hdr->fence_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_FENCE_PTR + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_FENCE_PTR + offset)); fifo_hdr->fence_mode = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_LOCK_FENCE + offset)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_LOCK_FENCE + offset)); /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */ iwl_trans_write_prph_no_grab(fwrt->trans, TXF_READ_MODIFY_ADDR + offset, TXF_WR_PTR + offset); /* Dummy-read to advance the read pointer to the head */ - iwl_trans_read_prph(fwrt->trans, TXF_READ_MODIFY_DATA + offset); + iwl_trans_read_prph_no_grab(fwrt->trans, TXF_READ_MODIFY_DATA + offset); /* Read FIFO */ for (i = 0; i < fifo_len / sizeof(u32); i++) - fifo_data[i] = iwl_trans_read_prph(fwrt->trans, - TXF_READ_MODIFY_DATA + - offset); + fifo_data[i] = iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_READ_MODIFY_DATA + + offset); if (fwrt->sanitize_ops && fwrt->sanitize_ops->frob_txf) fwrt->sanitize_ops->frob_txf(fwrt->sanitize_ctx, @@ -266,20 +266,20 @@ static void iwl_fw_dump_txf(struct iwl_fw_runtime *fwrt, fwrt->smem_cfg.num_txfifo_entries); fifo_hdr->available_bytes = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_FIFO_ITEM_CNT)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_FIFO_ITEM_CNT)); fifo_hdr->wr_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_WR_PTR)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_WR_PTR)); fifo_hdr->rd_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_RD_PTR)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_RD_PTR)); fifo_hdr->fence_ptr = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_FENCE_PTR)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_FENCE_PTR)); fifo_hdr->fence_mode = - cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_LOCK_FENCE)); + cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_LOCK_FENCE)); /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */ iwl_trans_write_prph_no_grab(fwrt->trans, @@ -287,15 +287,15 @@ static void iwl_fw_dump_txf(struct iwl_fw_runtime *fwrt, TXF_CPU2_WR_PTR); /* Dummy-read to advance the read pointer to head */ - iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_READ_MODIFY_DATA); + iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_READ_MODIFY_DATA); /* Read FIFO */ fifo_len /= sizeof(u32); /* Size in DWORDS */ for (j = 0; j < fifo_len; j++) fifo_data[j] = - iwl_trans_read_prph(fwrt->trans, - TXF_CPU2_READ_MODIFY_DATA); + iwl_trans_read_prph_no_grab(fwrt->trans, + TXF_CPU2_READ_MODIFY_DATA); *dump_data = iwl_fw_error_next_data(*dump_data); } } @@ -514,7 +514,7 @@ static void iwl_read_prph_block(struct iwl_trans *trans, u32 start, u32 i; for (i = 0; i < len_bytes; i += 4) - *data++ = cpu_to_le32(iwl_trans_read_prph(trans, start + i)); + *data++ = cpu_to_le32(iwl_trans_read_prph_no_grab(trans, start + i)); } static void iwl_dump_prph(struct iwl_fw_runtime *fwrt, diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 8d08ce7db3b9..3a0318070bfb 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -103,7 +103,7 @@ static int iwl_dump_ini_prph_mac_iter_common(struct iwl_fw_runtime *fwrt, range->internal_base_addr = cpu_to_le32(addr); range->range_data_size = size; for (i = 0; i < le32_to_cpu(size); i += 4) - *val++ = cpu_to_le32(iwl_trans_read_prph(fwrt->trans, addr + i)); + *val++ = cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, addr + i)); return sizeof(*range) + le32_to_cpu(range->range_data_size); } @@ -177,8 +177,8 @@ static int iwl_dump_ini_prph_phy_iter_common(struct iwl_fw_runtime *fwrt, fwrt->trans->info.hw_rf_id != IWL_CFG_RF_TYPE_HR1 && fwrt->trans->info.hw_rf_id != IWL_CFG_RF_TYPE_HR2) { udelay(2); - prph_stts = iwl_trans_read_prph(fwrt->trans, - WMAL_MRSPF_STTS); + prph_stts = iwl_trans_read_prph_no_grab(fwrt->trans, + WMAL_MRSPF_STTS); /* Abort dump if status is 0xA5A5A5A2 or FIFO1 empty */ if (prph_stts == WMAL_TIMEOUT_VAL || @@ -186,8 +186,8 @@ static int iwl_dump_ini_prph_phy_iter_common(struct iwl_fw_runtime *fwrt, break; } - prph_val = iwl_trans_read_prph(fwrt->trans, - indirect_rd_addr); + prph_val = iwl_trans_read_prph_no_grab(fwrt->trans, + indirect_rd_addr); *val++ = cpu_to_le32(prph_val); } @@ -456,8 +456,8 @@ static int iwl_dump_ini_txf_iter(struct iwl_fw_runtime *fwrt, addr = le32_to_cpu(reg->addrs[i]) + offs; reg_dump->addr = cpu_to_le32(addr); - reg_dump->data = cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - addr)); + reg_dump->data = cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + addr)); reg_dump++; } @@ -472,13 +472,13 @@ static int iwl_dump_ini_txf_iter(struct iwl_fw_runtime *fwrt, TXF_WR_PTR + offs); /* Dummy-read to advance the read pointer to the head */ - iwl_trans_read_prph(fwrt->trans, TXF_READ_MODIFY_DATA + offs); + iwl_trans_read_prph_no_grab(fwrt->trans, TXF_READ_MODIFY_DATA + offs); /* Read FIFO */ addr = TXF_READ_MODIFY_DATA + offs; data = (void *)reg_dump; for (i = 0; i < iter->fifo_size; i += sizeof(*data)) - *data++ = cpu_to_le32(iwl_trans_read_prph(fwrt->trans, addr)); + *data++ = cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, addr)); if (fwrt->sanitize_ops && fwrt->sanitize_ops->frob_txf) fwrt->sanitize_ops->frob_txf(fwrt->sanitize_ctx, @@ -522,8 +522,8 @@ iwl_dump_ini_prph_snps_dphyip_iter(struct iwl_fw_runtime *fwrt, addr + i); /* wait a bit for value to be ready in register */ udelay(1); - prph_val = iwl_trans_read_prph(fwrt->trans, - indirect_rd_wr_addr); + prph_val = iwl_trans_read_prph_no_grab(fwrt->trans, + indirect_rd_wr_addr); *val++ = cpu_to_le32((prph_val & DPHYIP_INDIRECT_RD_MSK) >> DPHYIP_INDIRECT_RD_SHIFT); } @@ -628,8 +628,8 @@ static int iwl_dump_ini_rxf_iter(struct iwl_fw_runtime *fwrt, addr = le32_to_cpu(reg->addrs[i]) + offs; reg_dump->addr = cpu_to_le32(addr); - reg_dump->data = cpu_to_le32(iwl_trans_read_prph(fwrt->trans, - addr)); + reg_dump->data = cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, + addr)); reg_dump++; } @@ -652,7 +652,7 @@ static int iwl_dump_ini_rxf_iter(struct iwl_fw_runtime *fwrt, addr = RXF_FIFO_RD_FENCE_INC + offs; data = (void *)reg_dump; for (i = 0; i < rxf_data.size; i += sizeof(*data)) - *data++ = cpu_to_le32(iwl_trans_read_prph(fwrt->trans, addr)); + *data++ = cpu_to_le32(iwl_trans_read_prph_no_grab(fwrt->trans, addr)); out: return sizeof(*range) + le32_to_cpu(range->range_data_size); @@ -712,10 +712,10 @@ iwl_dump_ini_dbgi_sram_iter(struct iwl_fw_runtime *fwrt, range->range_data_size = reg->dev_addr.size; for (i = 0; i < (le32_to_cpu(reg->dev_addr.size) / 4); i++) { prph_data = - iwl_trans_read_prph(fwrt->trans, - (i % 2) ? - DBGI_SRAM_TARGET_ACCESS_RDATA_MSB : - DBGI_SRAM_TARGET_ACCESS_RDATA_LSB); + iwl_trans_read_prph_no_grab(fwrt->trans, + (i % 2) ? + DBGI_SRAM_TARGET_ACCESS_RDATA_MSB : + DBGI_SRAM_TARGET_ACCESS_RDATA_LSB); if (iwl_trans_is_hw_error_value(prph_data)) return -EBUSY; *val++ = cpu_to_le32(prph_data); @@ -812,7 +812,7 @@ static __le32 iwl_get_mon_reg(struct iwl_fw_runtime *fwrt, u32 alloc_id, if (!reg_info || !reg_info->addr || !reg_info->mask) return 0; - val = iwl_trans_read_prph(fwrt->trans, reg_info->addr + offs); + val = iwl_trans_read_prph_no_grab(fwrt->trans, reg_info->addr + offs); return cpu_to_le32(mask_apply_and_normalize(val, reg_info->mask)); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index 085074be2549..bc3ef107c4eb 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -40,7 +40,7 @@ IWL_EXPORT_SYMBOL(iwl_write_direct32); u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) { - u32 val = iwl_trans_read_prph(trans, ofs); + u32 val = iwl_trans_read_prph_no_grab(trans, ofs); trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val); return val; } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index 76cba6ac0c8b..9e02a498b5f9 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -1367,10 +1367,10 @@ static void iwl_set_hw_address_family_8000(struct iwl_trans *trans, if (nvm_hw) { /* read the mac address from WFMP registers */ - __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans, - WFMP_MAC_ADDR_0)); - __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans, - WFMP_MAC_ADDR_1)); + __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph_no_grab(trans, + WFMP_MAC_ADDR_0)); + __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph_no_grab(trans, + WFMP_MAC_ADDR_1)); iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 2d0bb3de7df5..123eca3f5d0a 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -440,7 +440,7 @@ u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs) } IWL_EXPORT_SYMBOL(iwl_trans_read32); -u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) +u32 iwl_trans_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) { return iwl_trans_pcie_read_prph(trans, ofs); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index c882313eaceb..18c1c46c11ce 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -914,7 +914,7 @@ void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val); u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs); -u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs); +u32 iwl_trans_read_prph_no_grab(struct iwl_trans *trans, u32 ofs); void iwl_trans_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val); From e8733ea9818b00244e9277ad8b828e92ac90b13c Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:45 +0300 Subject: [PATCH 1592/2126] wifi: iwlwifi: collapse iwl_read_prph_no_grab() into the transport API iwl_read_prph_no_grab() was a thin wrapper that read via iwl_trans_read_prph_no_grab() and emitted the ioread_prph32 tracepoint. Fold the tracepoint into the bus-specific implementation (iwl_trans_pcie_read_prph()) and remove the wrapper, so callers use the transport API (or the pcie primitive from within pcie) directly. No functional change intended. Assisted-by: GitHubCopilot:claude-opus-4.8 Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.592c74d42694.I329ccec5de9d0a6ec87538aceabce17149258841@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/dump.c | 6 +++--- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 15 ++++----------- drivers/net/wireless/intel/iwlwifi/iwl-io.h | 5 ++--- drivers/net/wireless/intel/iwlwifi/pcie/trans.c | 9 ++++++--- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dump.c b/drivers/net/wireless/intel/iwlwifi/fw/dump.c index eef89c141564..7b9e98a21704 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dump.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dump.c @@ -360,7 +360,7 @@ static void iwl_fwrt_dump_fseq_regs(struct iwl_fw_runtime *fwrt) for (i = 0; i < ARRAY_SIZE(fseq_regs); i++) IWL_ERR(fwrt, "0x%08X | %s\n", - iwl_read_prph_no_grab(trans, fseq_regs[i].addr), + iwl_trans_read_prph_no_grab(trans, fseq_regs[i].addr), fseq_regs[i].str); iwl_trans_release_nic_access(trans); @@ -398,8 +398,8 @@ void iwl_fwrt_dump_error_logs(struct iwl_fw_runtime *fwrt) count++, pc_data++) IWL_ERR(fwrt, "%s: 0x%x\n", pc_data->pc_name, - iwl_read_prph_no_grab(fwrt->trans, - pc_data->pc_address)); + iwl_trans_read_prph_no_grab(fwrt->trans, + pc_data->pc_address)); iwl_trans_release_nic_access(fwrt->trans); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index bc3ef107c4eb..515d6b2becc9 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -38,17 +38,10 @@ void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) } IWL_EXPORT_SYMBOL(iwl_write_direct32); -u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) -{ - u32 val = iwl_trans_read_prph_no_grab(trans, ofs); - trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val); - return val; -} - u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) { if (iwl_trans_grab_nic_access(trans)) { - u32 val = iwl_read_prph_no_grab(trans, ofs); + u32 val = iwl_trans_read_prph_no_grab(trans, ofs); iwl_trans_release_nic_access(trans); @@ -74,7 +67,7 @@ void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) { if (iwl_trans_grab_nic_access(trans)) { iwl_trans_write_prph_no_grab(trans, ofs, - iwl_read_prph_no_grab(trans, ofs) | + iwl_trans_read_prph_no_grab(trans, ofs) | mask); iwl_trans_release_nic_access(trans); } @@ -86,7 +79,7 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, { if (iwl_trans_grab_nic_access(trans)) { iwl_trans_write_prph_no_grab(trans, ofs, - (iwl_read_prph_no_grab(trans, ofs) & + (iwl_trans_read_prph_no_grab(trans, ofs) & mask) | bits); iwl_trans_release_nic_access(trans); } @@ -98,7 +91,7 @@ void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) u32 val; if (iwl_trans_grab_nic_access(trans)) { - val = iwl_read_prph_no_grab(trans, ofs); + val = iwl_trans_read_prph_no_grab(trans, ofs); iwl_trans_write_prph_no_grab(trans, ofs, (val & ~mask)); iwl_trans_release_nic_access(trans); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h index b33bc4822e5c..a26c6525ec40 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.h @@ -29,7 +29,6 @@ static inline int iwl_poll_bits(struct iwl_trans *trans, u32 addr, u32 bits, void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); -u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs); u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs); void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_ms); @@ -55,8 +54,8 @@ static inline u32 iwl_umac_prph(struct iwl_trans *trans, u32 ofs) static inline u32 iwl_read_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs) { - return iwl_read_prph_no_grab(trans, ofs + - trans->mac_cfg->umac_prph_offset); + return iwl_trans_read_prph_no_grab(trans, ofs + + trans->mac_cfg->umac_prph_offset); } static inline u32 iwl_read_umac_prph(struct iwl_trans *trans, u32 ofs) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 8dc8924564e5..709c2499ffc8 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -1893,10 +1893,13 @@ static u32 iwl_trans_pcie_prph_msk(struct iwl_trans *trans) u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg) { u32 mask = iwl_trans_pcie_prph_msk(trans); + u32 val; iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_RADDR, ((reg & mask) | (3 << 24))); - return iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT); + val = iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT); + trace_iwlwifi_dev_ioread_prph32(trans->dev, reg, val); + return val; } void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val) @@ -3938,10 +3941,10 @@ static void get_crf_id(struct iwl_trans *iwl_trans, iwl_pcie_write_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG, val); /* Read crf info */ - info->hw_crf_id = iwl_read_prph_no_grab(iwl_trans, sd_reg_ver_addr); + info->hw_crf_id = iwl_trans_pcie_read_prph(iwl_trans, sd_reg_ver_addr); /* Read cnv info */ - info->hw_cnv_id = iwl_read_prph_no_grab(iwl_trans, CNVI_AUX_MISC_CHIP); + info->hw_cnv_id = iwl_trans_pcie_read_prph(iwl_trans, CNVI_AUX_MISC_CHIP); /* For BZ-W, take B step also when A step is indicated */ if (CSR_HW_REV_TYPE(info->hw_rev) == IWL_CFG_MAC_TYPE_BZ_W) From cc5782ad2ed4e07364ebea93ef5b968c92d1e5bd Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:46 +0300 Subject: [PATCH 1593/2126] wifi: iwlwifi: pcie: rename pcie-internal functions Functions that are in pcie level should have the pcie prefix. In particular, the functions renamed in this commit are easy to be confused with the generic trans ones. Rename those functions to have a pcie prefix. Assisted-by: GitHubCopilot:claude-opus-4.8 Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.09af8a4d712b.I5867c6f937d569349e1950733361bf83a5e49fbb@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/pcie/trans.c | 28 +++++++++---------- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 4 +-- .../net/wireless/intel/iwlwifi/pcie/utils.h | 12 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 709c2499ffc8..ce7d01a36688 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -334,8 +334,8 @@ static void iwl_pcie_apm_lp_xtal_enable(struct iwl_trans *trans) u32 dl_cfg_reg; /* Force XTAL ON */ - iwl_trans_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_XTAL_ON); + iwl_pcie_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_XTAL_ON); ret = iwl_trans_pcie_sw_reset(trans, true); @@ -344,8 +344,8 @@ static void iwl_pcie_apm_lp_xtal_enable(struct iwl_trans *trans) if (WARN_ON(ret)) { /* Release XTAL ON request */ - iwl_trans_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_XTAL_ON); + iwl_pcie_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_XTAL_ON); return; } @@ -396,12 +396,12 @@ static void iwl_pcie_apm_lp_xtal_enable(struct iwl_trans *trans) iwl_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); /* Activates XTAL resources monitor */ - iwl_trans_set_bit(trans, CSR_MONITOR_CFG_REG, - CSR_MONITOR_XTAL_RESOURCES); + iwl_pcie_set_bit(trans, CSR_MONITOR_CFG_REG, + CSR_MONITOR_XTAL_RESOURCES); /* Release XTAL ON request */ - iwl_trans_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_XTAL_ON); + iwl_pcie_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_XTAL_ON); udelay(10); /* Release APMG XTAL */ @@ -2359,7 +2359,7 @@ bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) } /* this bit wakes up the NIC */ - iwl_trans_set_bit(trans, CSR_GP_CNTRL, write); + iwl_pcie_set_bit(trans, CSR_GP_CNTRL, write); if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_8000) udelay(2); @@ -2452,11 +2452,11 @@ void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans) if (trans_pcie->cmd_hold_nic_awake) goto out; if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) - iwl_trans_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); + iwl_pcie_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); else - iwl_trans_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_pcie_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); /* * Above we read the CSR_GP_CNTRL register, which will flush * any previous writes, but we need the write that clears the @@ -2681,7 +2681,7 @@ void iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans, u32 reg, struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); spin_lock_bh(&trans_pcie->reg_lock); - _iwl_trans_set_bits_mask(trans, reg, mask, value); + iwl_pcie_set_bits_mask(trans, reg, mask, value); spin_unlock_bh(&trans_pcie->reg_lock); } diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index f5aa456180d8..cd744f7002b6 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -205,8 +205,8 @@ static void iwl_pcie_clear_cmd_in_flight(struct iwl_trans *trans) } trans_pcie->cmd_hold_nic_awake = false; - iwl_trans_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_pcie_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); spin_unlock(&trans_pcie->reg_lock); } diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h index 2d92bff513df..74c23ec199e2 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h @@ -36,8 +36,8 @@ static inline void iwl_pcie_write_umac_prph_no_grab(struct iwl_trans *trans, val); } -static inline void _iwl_trans_set_bits_mask(struct iwl_trans *trans, - u32 reg, u32 mask, u32 value) +static inline void iwl_pcie_set_bits_mask(struct iwl_trans *trans, + u32 reg, u32 mask, u32 value) { u32 v; @@ -51,16 +51,16 @@ static inline void _iwl_trans_set_bits_mask(struct iwl_trans *trans, iwl_trans_pcie_write32(trans, reg, v); } -static inline void iwl_trans_clear_bit(struct iwl_trans *trans, +static inline void iwl_pcie_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) { - _iwl_trans_set_bits_mask(trans, reg, mask, 0); + iwl_pcie_set_bits_mask(trans, reg, mask, 0); } -static inline void iwl_trans_set_bit(struct iwl_trans *trans, +static inline void iwl_pcie_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) { - _iwl_trans_set_bits_mask(trans, reg, mask, mask); + iwl_pcie_set_bits_mask(trans, reg, mask, mask); } #endif /* __iwl_pcie_utils_h__ */ From e46ac2e5fa10e1f7c9157ebccb5df018954aa863 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:47 +0300 Subject: [PATCH 1594/2126] wifi: iwlwifi: rename io helpers to iwl_trans_ prefix The iwl-io is a wrapper layer for all the device memory access operations. But all it really does is either a combination of other operations, or tracing and calling the trans function, which calls the bus-specific implementation. This makes the code hard to follow. Those helpers are really part of the transports functionality, so there is no reason to keep this complexity. This and the following commit will remove iwl-io.c/h: this renames the functions to have the trans prefix, and a next one will move them to iwl-trans. No functional change. Assisted-by: GitHubCopilot:claude-opus-4.8 Link: https://patch.msgid.link/20260930121740.96f5fe1d78b9.Ie580d7156b6b0175bf45e24c93dd4cce1da065ea@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/dvm/devices.c | 24 +- .../net/wireless/intel/iwlwifi/dvm/eeprom.c | 56 +-- drivers/net/wireless/intel/iwlwifi/dvm/main.c | 12 +- drivers/net/wireless/intel/iwlwifi/dvm/rx.c | 8 +- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 32 +- drivers/net/wireless/intel/iwlwifi/fw/dump.c | 6 +- drivers/net/wireless/intel/iwlwifi/fw/pnvm.c | 4 +- drivers/net/wireless/intel/iwlwifi/iwl-csr.h | 4 +- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 32 +- drivers/net/wireless/intel/iwlwifi/iwl-io.h | 50 +-- .../wireless/intel/iwlwifi/iwl-nvm-parse.c | 2 +- drivers/net/wireless/intel/iwlwifi/iwl-scd.h | 21 +- .../net/wireless/intel/iwlwifi/iwl-trans.c | 12 +- drivers/net/wireless/intel/iwlwifi/mld/fw.c | 8 +- drivers/net/wireless/intel/iwlwifi/mld/mld.c | 2 +- .../net/wireless/intel/iwlwifi/mvm/debugfs.c | 4 +- drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 34 +- drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 6 +- .../net/wireless/intel/iwlwifi/mvm/utils.c | 2 +- .../intel/iwlwifi/pcie/ctxt-info-v2.c | 4 +- .../wireless/intel/iwlwifi/pcie/internal.h | 4 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 16 +- .../wireless/intel/iwlwifi/pcie/trans-gen2.c | 58 +-- .../net/wireless/intel/iwlwifi/pcie/trans.c | 372 +++++++++--------- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 74 ++-- .../net/wireless/intel/iwlwifi/pcie/utils.c | 4 +- 26 files changed, 426 insertions(+), 425 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c index b40a769f8e2d..c22f68db3e83 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c @@ -45,10 +45,10 @@ static void iwl1000_set_ct_threshold(struct iwl_priv *priv) static void iwl1000_nic_config(struct iwl_priv *priv) { /* Setting digital SVR for 1000 card to 1.32V */ - /* locking is acquired in iwl_set_bits_mask_prph() function */ - iwl_set_bits_mask_prph(priv->trans, APMG_DIGITAL_SVR_REG, - APMG_SVR_DIGITAL_VOLTAGE_1_32, - ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK); + /* locking is acquired in iwl_trans_set_bits_mask_prph() function */ + iwl_trans_set_bits_mask_prph(priv->trans, APMG_DIGITAL_SVR_REG, + APMG_SVR_DIGITAL_VOLTAGE_1_32, + ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK); } /** @@ -184,8 +184,8 @@ static void iwl2000_set_ct_threshold(struct iwl_priv *priv) /* NIC configuration for 2000 series */ static void iwl2000_nic_config(struct iwl_priv *priv) { - iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, - CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER); + iwl_trans_set_bit(priv->trans, CSR_GP_DRIVER_REG, + CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER); } static const struct iwl_sensitivity_ranges iwl2000_sensitivity = { @@ -496,16 +496,16 @@ static void iwl6000_nic_config(struct iwl_priv *priv) case IWL_DEVICE_FAMILY_6050: /* Indicate calibration version to uCode. */ if (priv->nvm_data->calib_version >= 6) - iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, - CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); + iwl_trans_set_bit(priv->trans, CSR_GP_DRIVER_REG, + CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); break; case IWL_DEVICE_FAMILY_6150: /* Indicate calibration version to uCode. */ if (priv->nvm_data->calib_version >= 6) - iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, - CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); - iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, - CSR_GP_DRIVER_REG_BIT_6050_1x2); + iwl_trans_set_bit(priv->trans, CSR_GP_DRIVER_REG, + CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); + iwl_trans_set_bit(priv->trans, CSR_GP_DRIVER_REG, + CSR_GP_DRIVER_REG_BIT_6050_1x2); break; default: WARN_ON(1); diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c b/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c index d20691f7d82f..aa532635e414 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c @@ -672,13 +672,13 @@ static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans) for (count = 0; count < IWL_EEPROM_SEM_RETRY_LIMIT; count++) { /* Request semaphore */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM); /* See if we got it */ - ret = iwl_poll_bits(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM, - IWL_EEPROM_SEM_TIMEOUT); + ret = iwl_trans_poll_bits(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM, + IWL_EEPROM_SEM_TIMEOUT); if (!ret) { IWL_DEBUG_EEPROM(trans->dev, "Acquired semaphore after %d tries.\n", @@ -692,8 +692,8 @@ static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans) static void iwl_eeprom_release_semaphore(struct iwl_trans *trans) { - iwl_clear_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM); + iwl_trans_clear_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM); } static int iwl_eeprom_verify_signature(struct iwl_trans *trans, bool nvm_is_otp) @@ -736,8 +736,8 @@ static void iwl_set_otp_access_absolute(struct iwl_trans *trans) { iwl_trans_read32(trans, CSR_OTP_GP_REG); - iwl_clear_bit(trans, CSR_OTP_GP_REG, - CSR_OTP_GP_REG_OTP_ACCESS_MODE); + iwl_trans_clear_bit(trans, CSR_OTP_GP_REG, + CSR_OTP_GP_REG_OTP_ACCESS_MODE); } static int iwl_nvm_is_otp(struct iwl_trans *trans) @@ -770,19 +770,19 @@ static int iwl_init_otp_access(struct iwl_trans *trans) if (ret) return ret; - iwl_set_bits_prph(trans, APMG_PS_CTRL_REG, - APMG_PS_CTRL_VAL_RESET_REQ); + iwl_trans_set_bits_prph(trans, APMG_PS_CTRL_REG, + APMG_PS_CTRL_VAL_RESET_REQ); udelay(5); - iwl_clear_bits_prph(trans, APMG_PS_CTRL_REG, - APMG_PS_CTRL_VAL_RESET_REQ); + iwl_trans_clear_bits_prph(trans, APMG_PS_CTRL_REG, + APMG_PS_CTRL_VAL_RESET_REQ); /* * CSR auto clock gate disable bit - * this is only applicable for HW with OTP shadow RAM */ if (trans->mac_cfg->base->shadow_ram_support) - iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, - CSR_RESET_LINK_PWR_MGMT_DISABLED); + iwl_trans_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, + CSR_RESET_LINK_PWR_MGMT_DISABLED); return 0; } @@ -796,9 +796,9 @@ static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr, iwl_trans_write32(trans, CSR_EEPROM_REG, CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); - ret = iwl_poll_bits(trans, CSR_EEPROM_REG, - CSR_EEPROM_REG_READ_VALID_MSK, - IWL_EEPROM_ACCESS_TIMEOUT); + ret = iwl_trans_poll_bits(trans, CSR_EEPROM_REG, + CSR_EEPROM_REG_READ_VALID_MSK, + IWL_EEPROM_ACCESS_TIMEOUT); if (ret) { IWL_ERR(trans, "Time out reading OTP[%d]\n", addr); return ret; @@ -809,16 +809,16 @@ static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr, if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) { /* stop in this case */ /* set the uncorrectable OTP ECC bit for acknowledgment */ - iwl_set_bit(trans, CSR_OTP_GP_REG, - CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); + iwl_trans_set_bit(trans, CSR_OTP_GP_REG, + CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); IWL_ERR(trans, "Uncorrectable OTP ECC error, abort OTP read\n"); return -EINVAL; } if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) { /* continue in this case */ /* set the correctable OTP ECC bit for acknowledgment */ - iwl_set_bit(trans, CSR_OTP_GP_REG, - CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK); + iwl_trans_set_bit(trans, CSR_OTP_GP_REG, + CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK); IWL_ERR(trans, "Correctable OTP ECC error, continue read\n"); } *eeprom_data = cpu_to_le16(r >> 16); @@ -964,9 +964,9 @@ int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) iwl_trans_read32(trans, CSR_EEPROM_GP) & ~CSR_EEPROM_GP_IF_OWNER_MSK); - iwl_set_bit(trans, CSR_OTP_GP_REG, - CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK | - CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); + iwl_trans_set_bit(trans, CSR_OTP_GP_REG, + CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK | + CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); /* traversing the linked list if no shadow ram supported */ if (!trans->mac_cfg->base->shadow_ram_support) { ret = iwl_find_otp_image(trans, &validblockaddr); @@ -991,9 +991,9 @@ int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) iwl_trans_write32(trans, CSR_EEPROM_REG, CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); - ret = iwl_poll_bits(trans, CSR_EEPROM_REG, - CSR_EEPROM_REG_READ_VALID_MSK, - IWL_EEPROM_ACCESS_TIMEOUT); + ret = iwl_trans_poll_bits(trans, CSR_EEPROM_REG, + CSR_EEPROM_REG_READ_VALID_MSK, + IWL_EEPROM_ACCESS_TIMEOUT); if (ret) { IWL_ERR(trans, "Time out reading EEPROM[%d]\n", addr); diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/main.c b/drivers/net/wireless/intel/iwlwifi/dvm/main.c index 9bf16950ebf0..b3f73c773abe 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/main.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/main.c @@ -2028,17 +2028,17 @@ static void iwl_nic_config(struct iwl_op_mode *op_mode) } /* set CSR_HW_CONFIG_REG for uCode use */ - iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | - CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); + iwl_trans_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | + CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); /* W/A : NIC is stuck in a reset state after Early PCIe power off * (PCIe power is lost before PERST# is asserted), * causing ME FW to lose ownership and not being able to obtain it back. */ - iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG, - APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, - ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); + iwl_trans_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG, + APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, + ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); if (priv->lib->nic_config) priv->lib->nic_config(priv); diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c index 79ee4fb239b2..77aa7e04854f 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c @@ -485,14 +485,14 @@ static void iwlagn_rx_card_state_notif(struct iwl_priv *priv, iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); - iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, - HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); + iwl_trans_write_direct32(priv->trans, HBUS_TARG_MBX_C, + HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); if (!(flags & RXON_CARD_DISABLED)) { iwl_trans_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); - iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, - HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); + iwl_trans_write_direct32(priv->trans, HBUS_TARG_MBX_C, + HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); } if (flags & CT_CARD_DISABLED) iwl_tt_enter_ct_kill(priv); diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 3a0318070bfb..8827e4f317f1 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -159,7 +159,7 @@ static int iwl_dump_ini_prph_phy_iter_common(struct iwl_fw_runtime *fwrt, indirect_rd_addr += le32_to_cpu(offset); dphy_addr = (offset) ? WFPM_LMAC2_PS_CTL_RW : WFPM_LMAC1_PS_CTL_RW; - dphy_state = iwl_read_umac_prph_no_grab(fwrt->trans, dphy_addr); + dphy_state = iwl_trans_read_umac_prph_no_grab(fwrt->trans, dphy_addr); for (i = 0; i < le32_to_cpu(size); i += 4) { if (dphy_state == HBUS_TIMEOUT || @@ -508,7 +508,7 @@ iwl_dump_ini_prph_snps_dphyip_iter(struct iwl_fw_runtime *fwrt, indirect_rd_wr_addr += le32_to_cpu(offset); dphy_addr = offset ? WFPM_LMAC2_PS_CTL_RW : WFPM_LMAC1_PS_CTL_RW; - dphy_state = iwl_read_umac_prph_no_grab(fwrt->trans, dphy_addr); + dphy_state = iwl_trans_read_umac_prph_no_grab(fwrt->trans, dphy_addr); for (i = 0; i < le32_to_cpu(reg->dev_addr.size); i += 4) { if (dphy_state == HBUS_TIMEOUT || @@ -586,13 +586,13 @@ static void iwl_ini_get_rxf_data(struct iwl_fw_runtime *fwrt, switch (fifo_idx) { case 0: data->size = fwrt->smem_cfg.rxfifo2_size; - data->offset = iwl_umac_prph(fwrt->trans, - RXF_DIFF_FROM_PREV); + data->offset = iwl_trans_umac_prph(fwrt->trans, + RXF_DIFF_FROM_PREV); break; case 1: data->size = fwrt->smem_cfg.rxfifo2_control_size; - data->offset = iwl_umac_prph(fwrt->trans, - RXF2C_DIFF_FROM_PREV); + data->offset = iwl_trans_umac_prph(fwrt->trans, + RXF2C_DIFF_FROM_PREV); break; } } @@ -2381,21 +2381,21 @@ static void iwl_fw_dbg_stop_recording(struct iwl_trans *trans, struct iwl_fw_dbg_params *params) { if (trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_7000) { - iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100); + iwl_trans_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100); return; } if (params) { - params->in_sample = iwl_read_umac_prph(trans, DBGC_IN_SAMPLE); - params->out_ctrl = iwl_read_umac_prph(trans, DBGC_OUT_CTRL); + params->in_sample = iwl_trans_read_umac_prph(trans, DBGC_IN_SAMPLE); + params->out_ctrl = iwl_trans_read_umac_prph(trans, DBGC_OUT_CTRL); } - iwl_write_umac_prph(trans, DBGC_IN_SAMPLE, 0); + iwl_trans_write_umac_prph(trans, DBGC_IN_SAMPLE, 0); /* wait for the DBGC to finish writing the internal buffer to DRAM to * avoid halting the HW while writing */ usleep_range(700, 1000); - iwl_write_umac_prph(trans, DBGC_OUT_CTRL, 0); + iwl_trans_write_umac_prph(trans, DBGC_OUT_CTRL, 0); } static int iwl_fw_dbg_restart_recording(struct iwl_trans *trans, @@ -2405,12 +2405,12 @@ static int iwl_fw_dbg_restart_recording(struct iwl_trans *trans, return -EIO; if (trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_7000) { - iwl_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100); - iwl_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1); - iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1); + iwl_trans_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100); + iwl_trans_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1); + iwl_trans_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1); } else { - iwl_write_umac_prph(trans, DBGC_IN_SAMPLE, params->in_sample); - iwl_write_umac_prph(trans, DBGC_OUT_CTRL, params->out_ctrl); + iwl_trans_write_umac_prph(trans, DBGC_IN_SAMPLE, params->in_sample); + iwl_trans_write_umac_prph(trans, DBGC_OUT_CTRL, params->out_ctrl); } return 0; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dump.c b/drivers/net/wireless/intel/iwlwifi/fw/dump.c index 7b9e98a21704..deb7af465746 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dump.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dump.c @@ -309,7 +309,7 @@ static void iwl_fwrt_dump_iml_error_log(struct iwl_fw_runtime *fwrt) return; } - error = iwl_read_umac_prph(trans, error); + error = iwl_trans_read_umac_prph(trans, error); IWL_ERR(trans, "IML/ROM dump:\n"); @@ -318,11 +318,11 @@ static void iwl_fwrt_dump_iml_error_log(struct iwl_fw_runtime *fwrt) IWL_ERR(fwrt, "0x%08X | IML/ROM error/state\n", error); IWL_ERR(fwrt, "0x%08X | IML/ROM data1\n", - iwl_read_umac_prph(trans, data1)); + iwl_trans_read_umac_prph(trans, data1)); if (fwrt->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_22000) IWL_ERR(fwrt, "0x%08X | IML/ROM WFPM_AUTH_KEY_0\n", - iwl_read_umac_prph(trans, SB_MODIFY_CFG_FLAG)); + iwl_trans_read_umac_prph(trans, SB_MODIFY_CFG_FLAG)); } #define FSEQ_REG(x) { .addr = (x), .str = #x, } diff --git a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c index 545a213df71d..6e863059ffa7 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c @@ -485,8 +485,8 @@ int iwl_pnvm_load(struct iwl_trans *trans, iwl_pnvm_complete_fn, trans); /* kick the doorbell */ - iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, - UREG_DOORBELL_TO_ISR6_PNVM); + iwl_trans_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, + UREG_DOORBELL_TO_ISR6_PNVM); return iwl_wait_notification(notif_wait, &pnvm_wait, MVM_UCODE_PNVM_TIMEOUT); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-csr.h b/drivers/net/wireless/intel/iwlwifi/iwl-csr.h index b9f7e791dd37..11f2b31f6df7 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-csr.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-csr.h @@ -16,7 +16,7 @@ * * Use iwl_trans_write32() and iwl_trans_read32() family to access these registers; * these provide simple PCI bus access, without waking up the MAC. - * Do not use iwl_write_direct32() family for these registers; + * Do not use iwl_trans_write_direct32() family for these registers; * no need to "grab nic access" via CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ. * The MAC (uCode processor, etc.) does not need to be powered up for accessing * the CSR registers. @@ -501,7 +501,7 @@ enum { * to indirectly access device's internal memory or registers that * may be powered-down. * - * Use iwl_write_direct32() family for writing to these registers; + * Use iwl_trans_write_direct32() family for writing to these registers; * A read operation doesn't exist, can be added if needed. * host must "grab nic access" via CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ * to make sure the MAC (uCode processor, etc.) is powered up for accessing diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c index 515d6b2becc9..09965fb39fb6 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.c @@ -13,8 +13,8 @@ #define IWL_POLL_INTERVAL 10 /* microseconds */ -int iwl_poll_bits_mask(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout) +int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout) { int t = 0; @@ -27,18 +27,18 @@ int iwl_poll_bits_mask(struct iwl_trans *trans, u32 addr, return -ETIMEDOUT; } -IWL_EXPORT_SYMBOL(iwl_poll_bits_mask); +IWL_EXPORT_SYMBOL(iwl_trans_poll_bits_mask); -void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) +void iwl_trans_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) { if (iwl_trans_grab_nic_access(trans)) { iwl_trans_write32(trans, reg, value); iwl_trans_release_nic_access(trans); } } -IWL_EXPORT_SYMBOL(iwl_write_direct32); +IWL_EXPORT_SYMBOL(iwl_trans_write_direct32); -u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) +u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) { if (iwl_trans_grab_nic_access(trans)) { u32 val = iwl_trans_read_prph_no_grab(trans, ofs); @@ -51,9 +51,9 @@ u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) /* return as if we have a HW timeout/failure */ return 0x5a5a5a5a; } -IWL_EXPORT_SYMBOL(iwl_read_prph); +IWL_EXPORT_SYMBOL(iwl_trans_read_prph); -void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_ms) +void iwl_trans_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_ms) { if (iwl_trans_grab_nic_access(trans)) { mdelay(delay_ms); @@ -61,9 +61,9 @@ void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_m iwl_trans_release_nic_access(trans); } } -IWL_EXPORT_SYMBOL(iwl_write_prph_delay); +IWL_EXPORT_SYMBOL(iwl_trans_write_prph_delay); -void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) +void iwl_trans_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) { if (iwl_trans_grab_nic_access(trans)) { iwl_trans_write_prph_no_grab(trans, ofs, @@ -72,10 +72,10 @@ void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) iwl_trans_release_nic_access(trans); } } -IWL_EXPORT_SYMBOL(iwl_set_bits_prph); +IWL_EXPORT_SYMBOL(iwl_trans_set_bits_prph); -void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, - u32 bits, u32 mask) +void iwl_trans_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, + u32 bits, u32 mask) { if (iwl_trans_grab_nic_access(trans)) { iwl_trans_write_prph_no_grab(trans, ofs, @@ -84,9 +84,9 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, iwl_trans_release_nic_access(trans); } } -IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph); +IWL_EXPORT_SYMBOL(iwl_trans_set_bits_mask_prph); -void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) +void iwl_trans_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) { u32 val; @@ -96,4 +96,4 @@ void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) iwl_trans_release_nic_access(trans); } } -IWL_EXPORT_SYMBOL(iwl_clear_bits_prph); +IWL_EXPORT_SYMBOL(iwl_trans_clear_bits_prph); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h index a26c6525ec40..5cb422a4d9de 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-io.h @@ -8,65 +8,65 @@ #include "iwl-devtrace.h" #include "iwl-trans.h" -static inline void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) +static inline void iwl_trans_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) { iwl_trans_set_bits_mask(trans, reg, mask, mask); } -static inline void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) +static inline void iwl_trans_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) { iwl_trans_set_bits_mask(trans, reg, mask, 0); } -int iwl_poll_bits_mask(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout); -static inline int iwl_poll_bits(struct iwl_trans *trans, u32 addr, u32 bits, - int timeout) +int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout); +static inline int iwl_trans_poll_bits(struct iwl_trans *trans, u32 addr, u32 bits, + int timeout) { - return iwl_poll_bits_mask(trans, addr, bits, bits, timeout); + return iwl_trans_poll_bits_mask(trans, addr, bits, bits, timeout); } -void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); +void iwl_trans_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); -u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs); -void iwl_write_prph_delay(struct iwl_trans *trans, u32 ofs, - u32 val, u32 delay_ms); -static inline void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) +u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs); +void iwl_trans_write_prph_delay(struct iwl_trans *trans, u32 ofs, + u32 val, u32 delay_ms); +static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) { - iwl_write_prph_delay(trans, ofs, val, 0); + iwl_trans_write_prph_delay(trans, ofs, val, 0); } -void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); -void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, - u32 bits, u32 mask); -void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); +void iwl_trans_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); +void iwl_trans_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, + u32 bits, u32 mask); +void iwl_trans_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); /* * UMAC periphery address space changed from 0xA00000 to 0xD00000 starting from * device family AX200. So peripheries used in families above and below AX200 - * should go through iwl_..._umac_..._prph. + * should go through iwl_trans_..._umac_..._prph. */ -static inline u32 iwl_umac_prph(struct iwl_trans *trans, u32 ofs) +static inline u32 iwl_trans_umac_prph(struct iwl_trans *trans, u32 ofs) { return ofs + trans->mac_cfg->umac_prph_offset; } -static inline u32 iwl_read_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs) +static inline u32 iwl_trans_read_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs) { return iwl_trans_read_prph_no_grab(trans, ofs + trans->mac_cfg->umac_prph_offset); } -static inline u32 iwl_read_umac_prph(struct iwl_trans *trans, u32 ofs) +static inline u32 iwl_trans_read_umac_prph(struct iwl_trans *trans, u32 ofs) { - return iwl_read_prph(trans, ofs + trans->mac_cfg->umac_prph_offset); + return iwl_trans_read_prph(trans, ofs + trans->mac_cfg->umac_prph_offset); } -static inline void iwl_write_umac_prph(struct iwl_trans *trans, u32 ofs, - u32 val) +static inline void iwl_trans_write_umac_prph(struct iwl_trans *trans, u32 ofs, + u32 val) { - iwl_write_prph(trans, ofs + trans->mac_cfg->umac_prph_offset, val); + iwl_trans_write_prph(trans, ofs + trans->mac_cfg->umac_prph_offset, val); } #endif diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index 9e02a498b5f9..9a8355514c4f 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -1410,7 +1410,7 @@ static int iwl_set_hw_address(struct iwl_trans *trans, if (!trans->csme_own) IWL_INFO(trans, "base HW address: %pM, OTP minor version: 0x%x\n", - data->hw_addr, iwl_read_prph(trans, REG_OTP_MINOR)); + data->hw_addr, iwl_trans_read_prph(trans, REG_OTP_MINOR)); return 0; } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-scd.h b/drivers/net/wireless/intel/iwlwifi/iwl-scd.h index 1eaff898ca3c..22a7da73a918 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-scd.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-scd.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* * Copyright (C) 2014 Intel Mobile Communications GmbH + * Copyright (C) 2026 Intel Corporation */ #ifndef __iwl_scd_h__ #define __iwl_scd_h__ @@ -13,40 +14,40 @@ static inline void iwl_scd_txq_set_chain(struct iwl_trans *trans, u16 txq_id) { - iwl_set_bits_prph(trans, SCD_QUEUECHAIN_SEL, BIT(txq_id)); + iwl_trans_set_bits_prph(trans, SCD_QUEUECHAIN_SEL, BIT(txq_id)); } static inline void iwl_scd_txq_enable_agg(struct iwl_trans *trans, u16 txq_id) { - iwl_set_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id)); + iwl_trans_set_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id)); } static inline void iwl_scd_txq_disable_agg(struct iwl_trans *trans, u16 txq_id) { - iwl_clear_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id)); + iwl_trans_clear_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id)); } static inline void iwl_scd_disable_agg(struct iwl_trans *trans) { - iwl_set_bits_prph(trans, SCD_AGGR_SEL, 0); + iwl_trans_set_bits_prph(trans, SCD_AGGR_SEL, 0); } static inline void iwl_scd_activate_fifos(struct iwl_trans *trans) { - iwl_write_prph(trans, SCD_TXFACT, IWL_MASK(0, 7)); + iwl_trans_write_prph(trans, SCD_TXFACT, IWL_MASK(0, 7)); } static inline void iwl_scd_deactivate_fifos(struct iwl_trans *trans) { - iwl_write_prph(trans, SCD_TXFACT, 0); + iwl_trans_write_prph(trans, SCD_TXFACT, 0); } static inline void iwl_scd_enable_set_active(struct iwl_trans *trans, u32 value) { - iwl_write_prph(trans, SCD_EN_CTRL, value); + iwl_trans_write_prph(trans, SCD_EN_CTRL, value); } static inline unsigned int SCD_QUEUE_WRPTR(unsigned int chnl) @@ -76,9 +77,9 @@ static inline unsigned int SCD_QUEUE_STATUS_BITS(unsigned int chnl) static inline void iwl_scd_txq_set_inactive(struct iwl_trans *trans, u16 txq_id) { - iwl_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id), - (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)| - (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); + iwl_trans_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id), + (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)| + (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); } #endif diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 123eca3f5d0a..59b4e180825f 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -453,14 +453,14 @@ void iwl_trans_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) void iwl_trans_force_nmi(struct iwl_trans *trans) { if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_9000) - iwl_write_prph_delay(trans, DEVICE_SET_NMI_REG, - DEVICE_SET_NMI_VAL_DRV, 1); + iwl_trans_write_prph_delay(trans, DEVICE_SET_NMI_REG, + DEVICE_SET_NMI_VAL_DRV, 1); else if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) - iwl_write_umac_prph(trans, UREG_NIC_SET_NMI_DRIVER, - UREG_NIC_SET_NMI_DRIVER_NMI_FROM_DRIVER); + iwl_trans_write_umac_prph(trans, UREG_NIC_SET_NMI_DRIVER, + UREG_NIC_SET_NMI_DRIVER_NMI_FROM_DRIVER); else if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_BZ) - iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, - UREG_DOORBELL_TO_ISR6_NMI_BIT); + iwl_trans_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, + UREG_DOORBELL_TO_ISR6_NMI_BIT); else iwl_trans_write32(trans, CSR_DOORBELL_VECTOR, UREG_DOORBELL_TO_ISR6_NMI_BIT); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/fw.c b/drivers/net/wireless/intel/iwlwifi/mld/fw.c index 7891afd556a8..3b9f412cdff2 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/fw.c @@ -207,11 +207,11 @@ static void iwl_mld_print_alive_notif_timeout(struct iwl_mld *mld) IWL_ERR(mld, "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", - iwl_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS), - iwl_read_umac_prph(trans, - UMAG_SB_CPU_2_STATUS)); + iwl_trans_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS), + iwl_trans_read_umac_prph(trans, + UMAG_SB_CPU_2_STATUS)); #define IWL_FW_PRINT_REG_INFO(reg_name) \ - IWL_ERR(mld, #reg_name ": 0x%x\n", iwl_read_umac_prph(trans, reg_name)) + IWL_ERR(mld, #reg_name ": 0x%x\n", iwl_trans_read_umac_prph(trans, reg_name)) IWL_FW_PRINT_REG_INFO(WFPM_LMAC1_PD_NOTIFICATION); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mld.c b/drivers/net/wireless/intel/iwlwifi/mld/mld.c index 95d6f36b9fd9..71832d92024d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mld.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/mld.c @@ -37,7 +37,7 @@ static const struct iwl_op_mode_ops iwl_mld_ops; int iwl_mld_get_systime(struct iwl_mld *mld, u32 *gp2) { - *gp2 = iwl_read_prph(mld->trans, + *gp2 = iwl_trans_read_prph(mld->trans, mld->trans->mac_cfg->base->gp2_reg_addr); if (*gp2 == 0x5a5a5a5a) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c index 06502f57e823..48f8bab4dc85 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c @@ -1548,7 +1548,7 @@ iwl_dbgfs_prph_reg_read(struct file *file, pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n", mvm->dbgfs_prph_reg_addr, - iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr)); + iwl_trans_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr)); return simple_read_from_buffer(user_buf, count, ppos, buf, pos); } @@ -1569,7 +1569,7 @@ iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf, if (args != 2) return -EINVAL; - iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value); + iwl_trans_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value); out: return count; diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c index c3402f5e47a0..9b4637a3d1ef 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c @@ -263,7 +263,7 @@ static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait, static void iwl_mvm_print_pd_notification(struct iwl_mvm *mvm) { #define IWL_FW_PRINT_REG_INFO(reg_name) \ - IWL_ERR(mvm, #reg_name ": 0x%x\n", iwl_read_umac_prph(trans, reg_name)) + IWL_ERR(mvm, #reg_name ": 0x%x\n", iwl_trans_read_umac_prph(trans, reg_name)) struct iwl_trans *trans = mvm->trans; enum iwl_device_family device_family = trans->mac_cfg->device_family; @@ -332,13 +332,13 @@ static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, IWL_DEVICE_FAMILY_AX210) { /* print these registers regardless of alive fail/success */ IWL_INFO(mvm, "WFPM_UMAC_PD_NOTIFICATION: 0x%x\n", - iwl_read_umac_prph(mvm->trans, WFPM_ARC1_PD_NOTIFICATION)); + iwl_trans_read_umac_prph(mvm->trans, WFPM_ARC1_PD_NOTIFICATION)); IWL_INFO(mvm, "WFPM_LMAC2_PD_NOTIFICATION: 0x%x\n", - iwl_read_umac_prph(mvm->trans, WFPM_LMAC2_PD_NOTIFICATION)); + iwl_trans_read_umac_prph(mvm->trans, WFPM_LMAC2_PD_NOTIFICATION)); IWL_INFO(mvm, "WFPM_AUTH_KEY_0: 0x%x\n", - iwl_read_umac_prph(mvm->trans, SB_MODIFY_CFG_FLAG)); + iwl_trans_read_umac_prph(mvm->trans, SB_MODIFY_CFG_FLAG)); IWL_INFO(mvm, "CNVI_SCU_SEQ_DATA_DW9: 0x%x\n", - iwl_read_prph(mvm->trans, CNVI_SCU_SEQ_DATA_DW9)); + iwl_trans_read_prph(mvm->trans, CNVI_SCU_SEQ_DATA_DW9)); } if (ret) { @@ -349,15 +349,15 @@ static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, IWL_DEVICE_FAMILY_22000) { IWL_ERR(mvm, "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", - iwl_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS), - iwl_read_umac_prph(trans, - UMAG_SB_CPU_2_STATUS)); + iwl_trans_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS), + iwl_trans_read_umac_prph(trans, + UMAG_SB_CPU_2_STATUS)); } else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_8000) { IWL_ERR(mvm, "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", - iwl_read_prph(trans, SB_CPU_1_STATUS), - iwl_read_prph(trans, SB_CPU_2_STATUS)); + iwl_trans_read_prph(trans, SB_CPU_1_STATUS), + iwl_trans_read_prph(trans, SB_CPU_2_STATUS)); } iwl_mvm_print_pd_notification(mvm); @@ -374,15 +374,15 @@ static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, } else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_9000) { IWL_ERR(mvm, "UMAC PC: 0x%x\n", - iwl_read_umac_prph(trans, - UREG_UMAC_CURRENT_PC)); + iwl_trans_read_umac_prph(trans, + UREG_UMAC_CURRENT_PC)); IWL_ERR(mvm, "LMAC PC: 0x%x\n", - iwl_read_umac_prph(trans, - UREG_LMAC1_CURRENT_PC)); + iwl_trans_read_umac_prph(trans, + UREG_LMAC1_CURRENT_PC)); if (iwl_mvm_is_cdb_supported(mvm)) IWL_ERR(mvm, "LMAC2 PC: 0x%x\n", - iwl_read_umac_prph(trans, - UREG_LMAC2_CURRENT_PC)); + iwl_trans_read_umac_prph(trans, + UREG_LMAC2_CURRENT_PC)); } if (ret == -ETIMEDOUT && !mvm->fw_product_reset) @@ -616,7 +616,7 @@ static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm) mvm->rfkill_safe_init_done = false; if (mvm->trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_AX210) { - sb_cfg = iwl_read_umac_prph(mvm->trans, SB_MODIFY_CFG_FLAG); + sb_cfg = iwl_trans_read_umac_prph(mvm->trans, SB_MODIFY_CFG_FLAG); /* if needed, we'll reset this on our way out later */ mvm->fw_product_reset = sb_cfg == SB_CFG_RESIDES_IN_ROM; if (mvm->fw_product_reset && iwl_mei_pldr_req()) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c index 93d5cab87f64..653c620361d5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c @@ -138,9 +138,9 @@ static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode) * to lose ownership and not being able to obtain it back. */ if (!mvm->trans->mac_cfg->base->apmg_not_supported) - iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG, - APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, - ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); + iwl_trans_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG, + APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, + ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); } static void iwl_mvm_rx_monitor_notif(struct iwl_mvm *mvm, diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/utils.c b/drivers/net/wireless/intel/iwlwifi/mvm/utils.c index 2fd4a9961145..cd0d89feecea 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/utils.c @@ -1159,7 +1159,7 @@ u32 iwl_mvm_get_systime(struct iwl_mvm *mvm) mvm->trans->mac_cfg->base->gp2_reg_addr) reg_addr = mvm->trans->mac_cfg->base->gp2_reg_addr; - return iwl_read_prph(mvm->trans, reg_addr); + return iwl_trans_read_prph(mvm->trans, reg_addr); } void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, int clock_type, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c index 917010a7d8ef..0009a05511af 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-v2.c @@ -319,8 +319,8 @@ void iwl_pcie_ctxt_info_v2_kick(struct iwl_trans *trans) iwl_pcie_write64(trans, CSR_IML_DATA_ADDR, trans_pcie->iml_dma_addr); iwl_trans_pcie_write32(trans, CSR_IML_SIZE_ADDR, trans_pcie->iml_len); - iwl_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL, - CSR_AUTO_FUNC_BOOT_ENA); + iwl_trans_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL, + CSR_AUTO_FUNC_BOOT_ENA); } void iwl_pcie_ctxt_info_v2_free(struct iwl_trans *trans, bool alive) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index 96821850298f..d74742df2fe5 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -1103,8 +1103,8 @@ static inline void iwl_enable_rfkill_int(struct iwl_trans *trans) * when we power down the device we need set the bit to allow it * to wake up the PCI-E bus for RF-kill interrupts. */ - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_RFKILL_WAKE_L1A_EN); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_RFKILL_WAKE_L1A_EN); } } diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index cf6beba6041f..e3fe5a912a8b 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -147,15 +147,15 @@ int iwl_pcie_rx_stop(struct iwl_trans *trans) { if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { /* TODO: remove this once fw does it */ - iwl_write_umac_prph(trans, RFH_RXF_DMA_CFG_AX210, 0); + iwl_trans_write_umac_prph(trans, RFH_RXF_DMA_CFG_AX210, 0); return iwl_pcie_poll_umac_prph_bit(trans, RFH_GEN_STATUS_AX210, RXF_DMA_IDLE, RXF_DMA_IDLE, 1000); } else if (trans->mac_cfg->mq_rx_supported) { - iwl_write_prph(trans, RFH_RXF_DMA_CFG, 0); + iwl_trans_write_prph(trans, RFH_RXF_DMA_CFG, 0); return iwl_pcie_poll_prph_bit(trans, RFH_GEN_STATUS, RXF_DMA_IDLE, RXF_DMA_IDLE, 1000); } else { - iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); + iwl_trans_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); return iwl_pcie_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG, FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000); @@ -184,8 +184,8 @@ static void iwl_pcie_rxq_inc_wr_ptr(struct iwl_trans *trans, if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { IWL_DEBUG_INFO(trans, "Rx queue requesting wakeup, GP1 = 0x%x\n", reg); - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); rxq->need_update = true; return; } @@ -895,7 +895,7 @@ static void iwl_pcie_rx_hw_init(struct iwl_trans *trans, struct iwl_rxq *rxq) /* W/A for interrupt coalescing bug in 7260 and 3160 */ if (trans->cfg->host_interrupt_operation_mode) - iwl_set_bit(trans, CSR_INT_COALESCING, IWL_HOST_INT_OPER_MODE); + iwl_trans_set_bit(trans, CSR_INT_COALESCING, IWL_HOST_INT_OPER_MODE); } static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans) @@ -1692,9 +1692,9 @@ static void iwl_pcie_irq_handle_error(struct iwl_trans *trans) /* W/A for WiFi/WiMAX coex and WiMAX own the RF */ if (trans->cfg->internal_wimax_coex && !trans->mac_cfg->base->apmg_not_supported && - (!(iwl_read_prph(trans, APMG_CLK_CTRL_REG) & + (!(iwl_trans_read_prph(trans, APMG_CLK_CTRL_REG) & APMS_CLK_VAL_MRB_FUNC_MODE) || - (iwl_read_prph(trans, APMG_PS_CTRL_REG) & + (iwl_trans_read_prph(trans, APMG_PS_CTRL_REG) & APMG_PS_CTRL_VAL_RESET_REQ))) { clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status); iwl_op_mode_wimax_active(trans->op_mode); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c index 91d0b935fca6..dce6043fe962 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c @@ -32,18 +32,18 @@ int iwl_pcie_gen2_apm_init(struct iwl_trans *trans) * Disable L0s without affecting L1; * don't wait for ICH L0s (ICH bug W/A) */ - iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS, - CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); + iwl_trans_set_bit(trans, CSR_GIO_CHICKEN_BITS, + CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); /* Set FH wait threshold to maximum (HW error during stress W/A) */ - iwl_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL); + iwl_trans_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL); /* * Enable HAP INTA (interrupt from management bus) to * wake device's PCI Express link L1a -> L0s */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_HAP_WAKE); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_HAP_WAKE); iwl_pcie_apm_config(trans); @@ -65,14 +65,14 @@ static void iwl_pcie_gen2_apm_stop(struct iwl_trans *trans, bool op_mode_leave) iwl_pcie_gen2_apm_init(trans); /* inform ME that we are leaving */ - iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, - CSR_RESET_LINK_PWR_MGMT_DISABLED); - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_WAKE_ME | - CSR_HW_IF_CONFIG_REG_WAKE_ME_PCIE_OWNER_EN); + iwl_trans_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, + CSR_RESET_LINK_PWR_MGMT_DISABLED); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_WAKE_ME | + CSR_HW_IF_CONFIG_REG_WAKE_ME_PCIE_OWNER_EN); mdelay(1); - iwl_clear_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, - CSR_RESET_LINK_PWR_MGMT_DISABLED); + iwl_trans_clear_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, + CSR_RESET_LINK_PWR_MGMT_DISABLED); mdelay(5); } @@ -88,11 +88,11 @@ static void iwl_pcie_gen2_apm_stop(struct iwl_trans *trans, bool op_mode_leave) * D0A* (powered-up Active) --> D0U* (Uninitialized) state. */ if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_INIT); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_INIT); else - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_INIT_DONE); } static void @@ -105,11 +105,11 @@ _iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans, trans_pcie->fw_reset_state = FW_RESET_REQUESTED; if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_AX210) - iwl_write_umac_prph(trans, UREG_NIC_SET_NMI_DRIVER, - UREG_NIC_SET_NMI_DRIVER_RESET_HANDSHAKE); + iwl_trans_write_umac_prph(trans, UREG_NIC_SET_NMI_DRIVER, + UREG_NIC_SET_NMI_DRIVER_RESET_HANDSHAKE); else if (trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_AX210) - iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, - UREG_DOORBELL_TO_ISR6_RESET_HANDSHAKE); + iwl_trans_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, + UREG_DOORBELL_TO_ISR6_RESET_HANDSHAKE); else iwl_trans_pcie_write32(trans, CSR_DOORBELL_VECTOR, UREG_DOORBELL_TO_ISR6_RESET_HANDSHAKE); @@ -281,7 +281,7 @@ static int iwl_pcie_gen2_nic_init(struct iwl_trans *trans) return -ENOMEM; /* enable shadow regs in HW */ - iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF); + iwl_trans_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF); IWL_DEBUG_INFO(trans, "Enabling shadow registers in device\n"); return 0; @@ -342,7 +342,7 @@ static void iwl_pcie_get_rf_name(struct iwl_trans *trans) case CSR_HW_RFID_TYPE(CSR_HW_RF_ID_TYPE_HR): case CSR_HW_RFID_TYPE(CSR_HW_RF_ID_TYPE_HR1): case CSR_HW_RFID_TYPE(CSR_HW_RF_ID_TYPE_HRCDB): - version = iwl_read_prph(trans, CNVI_MBOX_C); + version = iwl_trans_read_prph(trans, CNVI_MBOX_C); switch (version) { case 0x20000: pos += scnprintf(buf + pos, buflen - pos, " B3"); @@ -410,7 +410,7 @@ void iwl_trans_pcie_gen2_fw_alive(struct iwl_trans *trans) step_reg = trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_SC ? CNVI_PMU_STEP_FLOW_SC : CNVI_PMU_STEP_FLOW_BZ; - trans->step_urm = !!(iwl_read_prph(trans, step_reg) & + trans->step_urm = !!(iwl_trans_read_prph(trans, step_reg) & CNVI_PMU_STEP_FLOW_FORCE_URM); } @@ -440,8 +440,8 @@ static bool iwl_pcie_set_ltr(struct iwl_trans *trans) if (trans->mac_cfg->integrated && trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_22000) { - iwl_write_prph(trans, HPM_MAC_LTR_CSR, HPM_MAC_LRT_ENABLE_ALL); - iwl_write_prph(trans, HPM_UMAC_LTR, ltr_val); + iwl_trans_write_prph(trans, HPM_MAC_LTR_CSR, HPM_MAC_LRT_ENABLE_ALL); + iwl_trans_write_prph(trans, HPM_UMAC_LTR, ltr_val); return true; } @@ -593,12 +593,12 @@ again: IWL_DEBUG_POWER(trans, "function scratch register value is 0x%08x\n", iwl_trans_pcie_read32(trans, CSR_FUNC_SCRATCH)); iwl_trans_pcie_write32(trans, CSR_FUNC_SCRATCH, CSR_FUNC_SCRATCH_INIT_VALUE); - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_ROM_START); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_ROM_START); } else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { - iwl_write_umac_prph(trans, UREG_CPU_INIT_RUN, 1); + iwl_trans_write_umac_prph(trans, UREG_CPU_INIT_RUN, 1); } else { - iwl_write_prph(trans, UREG_CPU_INIT_RUN, 1); + iwl_trans_write_prph(trans, UREG_CPU_INIT_RUN, 1); } if (keep_ram_busy) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index ce7d01a36688..8da0cc603070 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -79,12 +79,12 @@ int iwl_trans_pcie_sw_reset(struct iwl_trans *trans, bool retake_ownership) { /* Reset entire device - do controller reset (results in SHRD_HW_RST) */ if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_SW_RESET); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_SW_RESET); usleep_range(10000, 20000); } else { - iwl_set_bit(trans, CSR_RESET, - CSR_RESET_REG_FLAG_SW_RESET); + iwl_trans_set_bit(trans, CSR_RESET, + CSR_RESET_REG_FLAG_SW_RESET); usleep_range(5000, 6000); } @@ -188,13 +188,13 @@ static void iwl_pcie_set_pwr(struct iwl_trans *trans, bool vaux) return; if (vaux && pci_pme_capable(to_pci_dev(trans->dev), PCI_D3cold)) - iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG, - APMG_PS_CTRL_VAL_PWR_SRC_VAUX, - ~APMG_PS_CTRL_MSK_PWR_SRC); + iwl_trans_set_bits_mask_prph(trans, APMG_PS_CTRL_REG, + APMG_PS_CTRL_VAL_PWR_SRC_VAUX, + ~APMG_PS_CTRL_MSK_PWR_SRC); else - iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG, - APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, - ~APMG_PS_CTRL_MSK_PWR_SRC); + iwl_trans_set_bits_mask_prph(trans, APMG_PS_CTRL_REG, + APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, + ~APMG_PS_CTRL_MSK_PWR_SRC); } /* PCI registers */ @@ -211,7 +211,7 @@ void iwl_pcie_apm_config(struct iwl_trans *trans) * and in newer hardware they are not officially supported at * all, so we must always set the L0S_DISABLED bit. */ - iwl_set_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_DISABLED); + iwl_trans_set_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_DISABLED); pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_LNKCTL, &lctl); trans_pcie->pm_support = !(lctl & PCI_EXP_LNKCTL_ASPM_L0S); @@ -241,31 +241,31 @@ static int iwl_pcie_apm_init(struct iwl_trans *trans) /* Disable L0S exit timer (platform NMI Work/Around) */ if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_8000) - iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS, - CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); + iwl_trans_set_bit(trans, CSR_GIO_CHICKEN_BITS, + CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); /* * Disable L0s without affecting L1; * don't wait for ICH L0s (ICH bug W/A) */ - iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS, - CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); + iwl_trans_set_bit(trans, CSR_GIO_CHICKEN_BITS, + CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); /* Set FH wait threshold to maximum (HW error during stress W/A) */ - iwl_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL); + iwl_trans_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL); /* * Enable HAP INTA (interrupt from management bus) to * wake device's PCI Express link L1a -> L0s */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_HAP_WAKE); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_HAP_WAKE); iwl_pcie_apm_config(trans); /* Configure analog phase-lock-loop before activating to D0A */ if (trans->mac_cfg->base->pll_cfg) - iwl_set_bit(trans, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL); + iwl_trans_set_bit(trans, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL); ret = iwl_trans_activate_nic(trans); if (ret) @@ -286,11 +286,11 @@ static int iwl_pcie_apm_init(struct iwl_trans *trans) * just to discard the value. But that's the way the hardware * seems to like it. */ - iwl_read_prph(trans, OSC_CLK); - iwl_read_prph(trans, OSC_CLK); - iwl_set_bits_prph(trans, OSC_CLK, OSC_CLK_FORCE_CONTROL); - iwl_read_prph(trans, OSC_CLK); - iwl_read_prph(trans, OSC_CLK); + iwl_trans_read_prph(trans, OSC_CLK); + iwl_trans_read_prph(trans, OSC_CLK); + iwl_trans_set_bits_prph(trans, OSC_CLK, OSC_CLK_FORCE_CONTROL); + iwl_trans_read_prph(trans, OSC_CLK); + iwl_trans_read_prph(trans, OSC_CLK); } /* @@ -301,17 +301,17 @@ static int iwl_pcie_apm_init(struct iwl_trans *trans) * bits already set by default in "CLK_CTRL_REG" after reset. */ if (!trans->mac_cfg->base->apmg_not_supported) { - iwl_write_prph(trans, APMG_CLK_EN_REG, - APMG_CLK_VAL_DMA_CLK_RQT); + iwl_trans_write_prph(trans, APMG_CLK_EN_REG, + APMG_CLK_VAL_DMA_CLK_RQT); udelay(20); /* Disable L1-Active */ - iwl_set_bits_prph(trans, APMG_PCIDEV_STT_REG, - APMG_PCIDEV_STT_VAL_L1_ACT_DIS); + iwl_trans_set_bits_prph(trans, APMG_PCIDEV_STT_REG, + APMG_PCIDEV_STT_VAL_L1_ACT_DIS); /* Clear the interrupt in APMG if the NIC is in RFKILL */ - iwl_write_prph(trans, APMG_RTC_INT_STT_REG, - APMG_RTC_INT_STT_RFKILL); + iwl_trans_write_prph(trans, APMG_RTC_INT_STT_REG, + APMG_RTC_INT_STT_RFKILL); } set_bit(STATUS_DEVICE_ENABLED, &trans->status); @@ -353,8 +353,8 @@ static void iwl_pcie_apm_lp_xtal_enable(struct iwl_trans *trans) * Clear "disable persistence" to avoid LP XTAL resetting when * SHRD_HW_RST is applied in S3. */ - iwl_clear_bits_prph(trans, APMG_PCIDEV_STT_REG, - APMG_PCIDEV_STT_VAL_PERSIST_DIS); + iwl_trans_clear_bits_prph(trans, APMG_PCIDEV_STT_REG, + APMG_PCIDEV_STT_VAL_PERSIST_DIS); /* * Force APMG XTAL to be active to prevent its disabling by HW @@ -386,14 +386,14 @@ static void iwl_pcie_apm_lp_xtal_enable(struct iwl_trans *trans) * Enable persistence mode to avoid LP XTAL resetting when * SHRD_HW_RST is applied in S3. */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_PERSISTENCE); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_PERSISTENCE); /* * Clear "initialization complete" bit to move adapter from * D0A* (powered-up Active) --> D0U* (Uninitialized) state. */ - iwl_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); /* Activates XTAL resources monitor */ iwl_pcie_set_bit(trans, CSR_MONITOR_CFG_REG, @@ -417,18 +417,18 @@ void iwl_pcie_apm_stop_master(struct iwl_trans *trans) /* stop device's busmaster DMA activity */ if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BUS_MASTER_DISABLE_REQ); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BUS_MASTER_DISABLE_REQ); - ret = iwl_poll_bits(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BUS_MASTER_DISABLE_STATUS, - 100); + ret = iwl_trans_poll_bits(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BUS_MASTER_DISABLE_STATUS, + 100); usleep_range(10000, 20000); } else { - iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); + iwl_trans_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); - ret = iwl_poll_bits(trans, CSR_RESET, - CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); + ret = iwl_trans_poll_bits(trans, CSR_RESET, + CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); } if (ret) @@ -447,18 +447,18 @@ static void iwl_pcie_apm_stop(struct iwl_trans *trans, bool op_mode_leave) /* inform ME that we are leaving */ if (trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_7000) - iwl_set_bits_prph(trans, APMG_PCIDEV_STT_REG, - APMG_PCIDEV_STT_VAL_WAKE_ME); + iwl_trans_set_bits_prph(trans, APMG_PCIDEV_STT_REG, + APMG_PCIDEV_STT_VAL_WAKE_ME); else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_8000) { - iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, - CSR_RESET_LINK_PWR_MGMT_DISABLED); - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_WAKE_ME | - CSR_HW_IF_CONFIG_REG_WAKE_ME_PCIE_OWNER_EN); + iwl_trans_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, + CSR_RESET_LINK_PWR_MGMT_DISABLED); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_WAKE_ME | + CSR_HW_IF_CONFIG_REG_WAKE_ME_PCIE_OWNER_EN); mdelay(1); - iwl_clear_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, - CSR_RESET_LINK_PWR_MGMT_DISABLED); + iwl_trans_clear_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, + CSR_RESET_LINK_PWR_MGMT_DISABLED); } mdelay(5); } @@ -479,7 +479,7 @@ static void iwl_pcie_apm_stop(struct iwl_trans *trans, bool op_mode_leave) * Clear "initialization complete" bit to move adapter from * D0A* (powered-up Active) --> D0U* (Uninitialized) state. */ - iwl_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); } static int iwl_pcie_nic_init(struct iwl_trans *trans) @@ -512,7 +512,7 @@ static int iwl_pcie_nic_init(struct iwl_trans *trans) if (trans->mac_cfg->base->shadow_reg_enable) { /* enable shadow regs in HW */ - iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF); + iwl_trans_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF); IWL_DEBUG_INFO(trans, "Enabling shadow registers in device\n"); } @@ -525,16 +525,16 @@ static int iwl_pcie_set_hw_ready(struct iwl_trans *trans) { int ret; - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_PCI_OWN_SET); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_PCI_OWN_SET); /* See if we got it */ - ret = iwl_poll_bits(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_PCI_OWN_SET, - HW_READY_TIMEOUT); + ret = iwl_trans_poll_bits(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_PCI_OWN_SET, + HW_READY_TIMEOUT); if (!ret) - iwl_set_bit(trans, CSR_MBOX_SET_REG, CSR_MBOX_SET_REG_OS_ALIVE); + iwl_trans_set_bit(trans, CSR_MBOX_SET_REG, CSR_MBOX_SET_REG_OS_ALIVE); IWL_DEBUG_INFO(trans, "hardware%s ready\n", ret ? " not" : ""); return ret; @@ -555,16 +555,16 @@ int iwl_pcie_prepare_card_hw(struct iwl_trans *trans) return 0; } - iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, - CSR_RESET_LINK_PWR_MGMT_DISABLED); + iwl_trans_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, + CSR_RESET_LINK_PWR_MGMT_DISABLED); usleep_range(1000, 2000); for (iter = 0; iter < 10; iter++) { int t = 0; /* If HW is not ready, prepare the conditions to check again */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_WAKE_ME); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_WAKE_ME); do { ret = iwl_pcie_set_hw_ready(trans); @@ -688,16 +688,16 @@ static int iwl_pcie_load_section(struct iwl_trans *trans, u8 section_num, extended_addr = true; if (extended_addr) - iwl_set_bits_prph(trans, LMPM_CHICK, - LMPM_CHICK_EXTENDED_ADDR_SPACE); + iwl_trans_set_bits_prph(trans, LMPM_CHICK, + LMPM_CHICK_EXTENDED_ADDR_SPACE); memcpy(v_addr, (const u8 *)section->data + offset, copy_size); ret = iwl_pcie_load_firmware_chunk(trans, dst_addr, p_addr, copy_size); if (extended_addr) - iwl_clear_bits_prph(trans, LMPM_CHICK, - LMPM_CHICK_EXTENDED_ADDR_SPACE); + iwl_trans_clear_bits_prph(trans, LMPM_CHICK, + LMPM_CHICK_EXTENDED_ADDR_SPACE); if (ret) { IWL_ERR(trans, @@ -753,7 +753,7 @@ static int iwl_pcie_load_cpu_sections_8000(struct iwl_trans *trans, /* Notify ucode of loaded section number and status */ val = iwl_pcie_read_direct32(trans, FH_UCODE_LOAD_STATUS); val = val | (sec_num << shift_param); - iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, val); + iwl_trans_write_direct32(trans, FH_UCODE_LOAD_STATUS, val); sec_num = (sec_num << 1) | 0x1; } @@ -764,18 +764,18 @@ static int iwl_pcie_load_cpu_sections_8000(struct iwl_trans *trans, if (trans->mac_cfg->gen2) { if (cpu == 1) - iwl_write_prph(trans, UREG_UCODE_LOAD_STATUS, - 0xFFFF); + iwl_trans_write_prph(trans, UREG_UCODE_LOAD_STATUS, + 0xFFFF); else - iwl_write_prph(trans, UREG_UCODE_LOAD_STATUS, - 0xFFFFFFFF); + iwl_trans_write_prph(trans, UREG_UCODE_LOAD_STATUS, + 0xFFFFFFFF); } else { if (cpu == 1) - iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, - 0xFFFF); + iwl_trans_write_direct32(trans, FH_UCODE_LOAD_STATUS, + 0xFFFF); else - iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, - 0xFFFFFFFF); + iwl_trans_write_direct32(trans, FH_UCODE_LOAD_STATUS, + 0xFFFFFFFF); } return 0; @@ -836,8 +836,8 @@ static void iwl_pcie_apply_destination_ini(struct iwl_trans *trans) IWL_FW_INI_LOCATION_SRAM_PATH) { IWL_DEBUG_FW(trans, "WRT: Applying SMEM buffer destination\n"); /* set sram monitor by enabling bit 7 */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_BIT_MONITOR_SRAM); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_BIT_MONITOR_SRAM); return; } @@ -852,11 +852,11 @@ static void iwl_pcie_apply_destination_ini(struct iwl_trans *trans) IWL_DEBUG_FW(trans, "WRT: Applying DRAM destination (alloc_id=%u)\n", alloc_id); - iwl_write_umac_prph(trans, MON_BUFF_BASE_ADDR_VER2, - frag->physical >> MON_BUFF_SHIFT_VER2); - iwl_write_umac_prph(trans, MON_BUFF_END_ADDR_VER2, - (frag->physical + frag->size - 256) >> - MON_BUFF_SHIFT_VER2); + iwl_trans_write_umac_prph(trans, MON_BUFF_BASE_ADDR_VER2, + frag->physical >> MON_BUFF_SHIFT_VER2); + iwl_trans_write_umac_prph(trans, MON_BUFF_END_ADDR_VER2, + (frag->physical + frag->size - 256) >> + MON_BUFF_SHIFT_VER2); } void iwl_pcie_apply_destination(struct iwl_trans *trans) @@ -887,22 +887,22 @@ void iwl_pcie_apply_destination(struct iwl_trans *trans) iwl_trans_pcie_write32(trans, addr, val); break; case CSR_SETBIT: - iwl_set_bit(trans, addr, BIT(val)); + iwl_trans_set_bit(trans, addr, BIT(val)); break; case CSR_CLEARBIT: - iwl_clear_bit(trans, addr, BIT(val)); + iwl_trans_clear_bit(trans, addr, BIT(val)); break; case PRPH_ASSIGN: - iwl_write_prph(trans, addr, val); + iwl_trans_write_prph(trans, addr, val); break; case PRPH_SETBIT: - iwl_set_bits_prph(trans, addr, BIT(val)); + iwl_trans_set_bits_prph(trans, addr, BIT(val)); break; case PRPH_CLEARBIT: - iwl_clear_bits_prph(trans, addr, BIT(val)); + iwl_trans_clear_bits_prph(trans, addr, BIT(val)); break; case PRPH_BLOCKBIT: - if (iwl_read_prph(trans, addr) & BIT(val)) { + if (iwl_trans_read_prph(trans, addr) & BIT(val)) { IWL_ERR(trans, "BIT(%u) in address 0x%x is 1, stopping FW configuration\n", val, addr); @@ -918,16 +918,16 @@ void iwl_pcie_apply_destination(struct iwl_trans *trans) monitor: if (dest->monitor_mode == EXTERNAL_MODE && fw_mon->size) { - iwl_write_prph(trans, le32_to_cpu(dest->base_reg), - fw_mon->physical >> dest->base_shift); + iwl_trans_write_prph(trans, le32_to_cpu(dest->base_reg), + fw_mon->physical >> dest->base_shift); if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_8000) - iwl_write_prph(trans, le32_to_cpu(dest->end_reg), - (fw_mon->physical + fw_mon->size - - 256) >> dest->end_shift); + iwl_trans_write_prph(trans, le32_to_cpu(dest->end_reg), + (fw_mon->physical + fw_mon->size - + 256) >> dest->end_shift); else - iwl_write_prph(trans, le32_to_cpu(dest->end_reg), - (fw_mon->physical + fw_mon->size) >> - dest->end_shift); + iwl_trans_write_prph(trans, le32_to_cpu(dest->end_reg), + (fw_mon->physical + fw_mon->size) >> + dest->end_shift); } } @@ -947,9 +947,9 @@ static int iwl_pcie_load_given_ucode(struct iwl_trans *trans, if (image->is_dual_cpus) { /* set CPU2 header address */ - iwl_write_prph(trans, - LMPM_SECURE_UCODE_LOAD_CPU2_HDR_ADDR, - LMPM_SECURE_CPU2_HDR_MEM_SPACE); + iwl_trans_write_prph(trans, + LMPM_SECURE_UCODE_LOAD_CPU2_HDR_ADDR, + LMPM_SECURE_CPU2_HDR_MEM_SPACE); /* load to FW the binary sections of CPU2 */ ret = iwl_pcie_load_cpu_sections(trans, image, 2, @@ -982,18 +982,18 @@ static int iwl_pcie_load_given_ucode_8000(struct iwl_trans *trans, iwl_pcie_apply_destination(trans); IWL_DEBUG_POWER(trans, "Original WFPM value = 0x%08X\n", - iwl_read_prph(trans, WFPM_GP2)); + iwl_trans_read_prph(trans, WFPM_GP2)); /* * Set default value. On resume reading the values that were * zeored can provide debug data on the resume flow. * This is for debugging only and has no functional impact. */ - iwl_write_prph(trans, WFPM_GP2, 0x01010101); + iwl_trans_write_prph(trans, WFPM_GP2, 0x01010101); /* configure the ucode to be ready to get the secured image */ /* release CPU reset */ - iwl_write_prph(trans, RELEASE_CPU_RESET, RELEASE_CPU_RESET_BIT); + iwl_trans_write_prph(trans, RELEASE_CPU_RESET, RELEASE_CPU_RESET_BIT); /* load to FW the binary Secured sections of CPU1 */ ret = iwl_pcie_load_cpu_sections_8000(trans, image, 1, @@ -1080,8 +1080,8 @@ static void iwl_pcie_map_list(struct iwl_trans *trans, for (i = 0; i < arr_size; i++) { iwl_trans_pcie_write8(trans, CSR_MSIX_IVAR(causes[i].addr), val); - iwl_clear_bit(trans, causes[i].mask_reg, - BIT(causes[i].bit)); + iwl_trans_clear_bit(trans, causes[i].mask_reg, + BIT(causes[i].bit)); } } @@ -1141,8 +1141,8 @@ void iwl_pcie_conf_msix_hw(struct iwl_trans_pcie *trans_pcie) if (!trans_pcie->msix_enabled) { if (trans->mac_cfg->mq_rx_supported && test_bit(STATUS_DEVICE_ENABLED, &trans->status)) - iwl_write_umac_prph(trans, UREG_CHICK, - UREG_CHICK_MSI_ENABLE); + iwl_trans_write_umac_prph(trans, UREG_CHICK, + UREG_CHICK_MSI_ENABLE); return; } /* @@ -1151,7 +1151,7 @@ void iwl_pcie_conf_msix_hw(struct iwl_trans_pcie *trans_pcie) * prph. */ if (test_bit(STATUS_DEVICE_ENABLED, &trans->status)) - iwl_write_umac_prph(trans, UREG_CHICK, UREG_CHICK_MSIX_ENABLE); + iwl_trans_write_umac_prph(trans, UREG_CHICK, UREG_CHICK_MSIX_ENABLE); /* * Each cause from the causes list above and the RX causes is @@ -1215,19 +1215,19 @@ static void _iwl_trans_pcie_stop_device(struct iwl_trans *trans, bool from_irq) /* Power-down device's busmaster DMA clocks */ if (!trans->mac_cfg->base->apmg_not_supported) { - iwl_write_prph(trans, APMG_CLK_DIS_REG, - APMG_CLK_VAL_DMA_CLK_RQT); + iwl_trans_write_prph(trans, APMG_CLK_DIS_REG, + APMG_CLK_VAL_DMA_CLK_RQT); udelay(5); } } /* Make sure (redundant) we've released our request to stay awake */ if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); else - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); /* Stop the device, and put it in low power state */ iwl_pcie_apm_stop(trans, false); @@ -1444,15 +1444,15 @@ static void iwl_pcie_d3_complete_suspend(struct iwl_trans *trans, iwl_pcie_synchronize_irqs(trans); if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_INIT); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_INIT); } else { - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_INIT_DONE); } if (reset) { @@ -1478,9 +1478,9 @@ static int iwl_pcie_d3_handshake(struct iwl_trans *trans, bool suspend) trans_pcie->sx_state = IWL_SX_WAITING; if (trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_AX210) - iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, - suspend ? UREG_DOORBELL_TO_ISR6_SUSPEND : - UREG_DOORBELL_TO_ISR6_RESUME); + iwl_trans_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6, + suspend ? UREG_DOORBELL_TO_ISR6_SUSPEND : + UREG_DOORBELL_TO_ISR6_RESUME); else iwl_trans_pcie_write32(trans, CSR_IPC_SLEEP_CONTROL, suspend ? CSR_IPC_SLEEP_CONTROL_SUSPEND : @@ -1515,8 +1515,8 @@ int iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool reset) if (!reset) /* Enable persistence mode to avoid reset */ - iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, - CSR_HW_IF_CONFIG_REG_PERSISTENCE); + iwl_trans_set_bit(trans, CSR_HW_IF_CONFIG_REG, + CSR_HW_IF_CONFIG_REG_PERSISTENCE); ret = iwl_pcie_d3_handshake(trans, true); if (ret) @@ -1535,11 +1535,11 @@ int iwl_trans_pcie_d3_resume(struct iwl_trans *trans, int ret; if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ); else - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); ret = iwl_trans_activate_nic(trans); if (ret) { @@ -1563,8 +1563,8 @@ int iwl_trans_pcie_d3_resume(struct iwl_trans *trans, iwl_pcie_set_pwr(trans, false); if (!reset) { - iwl_clear_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_trans_clear_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); } else { iwl_trans_pcie_tx_reset(trans); @@ -1577,7 +1577,7 @@ int iwl_trans_pcie_d3_resume(struct iwl_trans *trans, } IWL_DEBUG_POWER(trans, "WFPM value upon resume = 0x%08X\n", - iwl_read_umac_prph(trans, WFPM_GP2)); + iwl_trans_read_umac_prph(trans, WFPM_GP2)); val = iwl_trans_pcie_read32(trans, CSR_RESET); if (val & CSR_RESET_REG_FLAG_NEVO_RESET) { @@ -1745,9 +1745,9 @@ static int iwl_trans_pcie_clear_persistence_bit(struct iwl_trans *trans) return 0; } - hpm = iwl_read_umac_prph_no_grab(trans, HPM_DEBUG); + hpm = iwl_trans_read_umac_prph_no_grab(trans, HPM_DEBUG); if (!iwl_trans_is_hw_error_value(hpm) && (hpm & PERSISTENCE_BIT)) { - u32 wprot_val = iwl_read_umac_prph_no_grab(trans, wprot); + u32 wprot_val = iwl_trans_read_umac_prph_no_grab(trans, wprot); if (wprot_val & PREG_WFPM_ACCESS) { IWL_ERR(trans, @@ -1769,15 +1769,15 @@ static int iwl_pcie_gen2_force_power_gating(struct iwl_trans *trans) if (ret < 0) return ret; - iwl_set_bits_prph(trans, HPM_HIPM_GEN_CFG, - HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE); + iwl_trans_set_bits_prph(trans, HPM_HIPM_GEN_CFG, + HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE); udelay(20); - iwl_set_bits_prph(trans, HPM_HIPM_GEN_CFG, - HPM_HIPM_GEN_CFG_CR_PG_EN | - HPM_HIPM_GEN_CFG_CR_SLP_EN); + iwl_trans_set_bits_prph(trans, HPM_HIPM_GEN_CFG, + HPM_HIPM_GEN_CFG_CR_PG_EN | + HPM_HIPM_GEN_CFG_CR_SLP_EN); udelay(20); - iwl_clear_bits_prph(trans, HPM_HIPM_GEN_CFG, - HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE); + iwl_trans_clear_bits_prph(trans, HPM_HIPM_GEN_CFG, + HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE); return iwl_trans_pcie_sw_reset(trans, true); } @@ -2383,7 +2383,7 @@ bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) * 5000 series and later (including 1000 series) have non-volatile SRAM, * and do not save/restore SRAM when power cycling. */ - ret = iwl_poll_bits_mask(trans, CSR_GP_CNTRL, poll, mask, 15000); + ret = iwl_trans_poll_bits_mask(trans, CSR_GP_CNTRL, poll, mask, 15000); if (unlikely(ret)) { u32 cntrl = iwl_trans_pcie_read32(trans, CSR_GP_CNTRL); @@ -3237,8 +3237,8 @@ static u32 iwl_trans_pcie_fh_regs_dump(struct iwl_trans *trans, i += sizeof(u32)) *val++ = cpu_to_le32(iwl_trans_pcie_read32(trans, i)); else - for (i = iwl_umac_prph(trans, FH_MEM_LOWER_BOUND_GEN2); - i < iwl_umac_prph(trans, FH_MEM_UPPER_BOUND_GEN2); + for (i = iwl_trans_umac_prph(trans, FH_MEM_LOWER_BOUND_GEN2); + i < iwl_trans_umac_prph(trans, FH_MEM_UPPER_BOUND_GEN2); i += sizeof(u32)) *val++ = cpu_to_le32(iwl_trans_pcie_read_prph(trans, i)); @@ -3264,8 +3264,8 @@ iwl_trans_pci_dump_marbh_monitor(struct iwl_trans *trans, iwl_pcie_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x1); for (i = 0; i < buf_size_in_dwords; i++) - buffer[i] = iwl_read_umac_prph_no_grab(trans, - MON_DMARB_RD_DATA_ADDR); + buffer[i] = iwl_trans_read_umac_prph_no_grab(trans, + MON_DMARB_RD_DATA_ADDR); iwl_pcie_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x0); iwl_trans_release_nic_access(trans); @@ -3294,14 +3294,14 @@ iwl_trans_pcie_dump_pointers(struct iwl_trans *trans, wrap_cnt = MON_BUFF_CYCLE_CNT; } - write_ptr_val = iwl_read_prph(trans, write_ptr); + write_ptr_val = iwl_trans_read_prph(trans, write_ptr); fw_mon_data->fw_mon_cycle_cnt = - cpu_to_le32(iwl_read_prph(trans, wrap_cnt)); + cpu_to_le32(iwl_trans_read_prph(trans, wrap_cnt)); fw_mon_data->fw_mon_base_ptr = - cpu_to_le32(iwl_read_prph(trans, base)); + cpu_to_le32(iwl_trans_read_prph(trans, base)); if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { fw_mon_data->fw_mon_base_high_ptr = - cpu_to_le32(iwl_read_prph(trans, base_high)); + cpu_to_le32(iwl_trans_read_prph(trans, base_high)); write_ptr_val &= DBGC_CUR_DBGBUF_STATUS_OFFSET_MSK; /* convert wrtPtr to DWs, to align with all HWs */ write_ptr_val >>= 2; @@ -3339,13 +3339,13 @@ iwl_trans_pcie_dump_monitor(struct iwl_trans *trans, * shifting */ if (trans->dbg.dest_tlv->version) { - base = (iwl_read_prph(trans, base) & + base = (iwl_trans_read_prph(trans, base) & IWL_LDBG_M2S_BUF_BA_MSK) << trans->dbg.dest_tlv->base_shift; base *= IWL_M2S_UNIT_SIZE; base += trans->mac_cfg->base->smem_offset; } else { - base = iwl_read_prph(trans, base) << + base = iwl_trans_read_prph(trans, base) << trans->dbg.dest_tlv->base_shift; } @@ -3380,7 +3380,7 @@ static int iwl_trans_get_fw_monitor_len(struct iwl_trans *trans, u32 *len) if (trans->dbg.dest_tlv->version == 1) { cfg_reg = le32_to_cpu(trans->dbg.dest_tlv->base_reg); - cfg_reg = iwl_read_prph(trans, cfg_reg); + cfg_reg = iwl_trans_read_prph(trans, cfg_reg); base = (cfg_reg & IWL_LDBG_M2S_BUF_BA_MSK) << trans->dbg.dest_tlv->base_shift; base *= IWL_M2S_UNIT_SIZE; @@ -3394,9 +3394,9 @@ static int iwl_trans_get_fw_monitor_len(struct iwl_trans *trans, u32 *len) base = le32_to_cpu(trans->dbg.dest_tlv->base_reg); end = le32_to_cpu(trans->dbg.dest_tlv->end_reg); - base = iwl_read_prph(trans, base) << + base = iwl_trans_read_prph(trans, base) << trans->dbg.dest_tlv->base_shift; - end = iwl_read_prph(trans, end) << + end = iwl_trans_read_prph(trans, end) << trans->dbg.dest_tlv->end_shift; /* Make "end" point to the actual end */ @@ -3454,8 +3454,8 @@ iwl_trans_pcie_dump_data(struct iwl_trans *trans, u32 dump_mask, if (dump_mask & BIT(IWL_FW_ERROR_DUMP_FH_REGS)) { if (trans->mac_cfg->gen2) len += sizeof(*data) + - (iwl_umac_prph(trans, FH_MEM_UPPER_BOUND_GEN2) - - iwl_umac_prph(trans, FH_MEM_LOWER_BOUND_GEN2)); + (iwl_trans_umac_prph(trans, FH_MEM_UPPER_BOUND_GEN2) - + iwl_trans_umac_prph(trans, FH_MEM_LOWER_BOUND_GEN2)); else len += sizeof(*data) + (FH_MEM_UPPER_BOUND - @@ -3860,19 +3860,19 @@ out_free_trans: void iwl_trans_pcie_copy_imr_fh(struct iwl_trans *trans, u32 dst_addr, u64 src_addr, u32 byte_cnt) { - iwl_write_prph(trans, IMR_UREG_CHICK, - iwl_read_prph(trans, IMR_UREG_CHICK) | - IMR_UREG_CHICK_HALT_UMAC_PERMANENTLY_MSK); - iwl_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_SRAM_ADDR, dst_addr); - iwl_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_LSB, - (u32)(src_addr & 0xFFFFFFFF)); - iwl_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_MSB, - iwl_get_dma_hi_addr(src_addr)); - iwl_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_BC, byte_cnt); - iwl_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_CTRL, - IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_IRQ_TARGET_POS | - IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_DMA_EN_POS | - IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_RS_MSK); + iwl_trans_write_prph(trans, IMR_UREG_CHICK, + iwl_trans_read_prph(trans, IMR_UREG_CHICK) | + IMR_UREG_CHICK_HALT_UMAC_PERMANENTLY_MSK); + iwl_trans_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_SRAM_ADDR, dst_addr); + iwl_trans_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_LSB, + (u32)(src_addr & 0xFFFFFFFF)); + iwl_trans_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_MSB, + iwl_get_dma_hi_addr(src_addr)); + iwl_trans_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_BC, byte_cnt); + iwl_trans_write_prph(trans, IMR_TFH_SRV_DMA_CHNL0_CTRL, + IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_IRQ_TARGET_POS | + IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_DMA_EN_POS | + IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_RS_MSK); } int iwl_trans_pcie_copy_imr(struct iwl_trans *trans, @@ -3914,8 +3914,8 @@ static void get_crf_id(struct iwl_trans *iwl_trans, /* wait until the device is ready to access the prph registers */ if (iwl_trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_DR || iwl_trans->mac_cfg->device_family == IWL_DEVICE_FAMILY_SC) { - u32 req = iwl_read_umac_prph_no_grab(iwl_trans, - WFPM_RSRCS_4PHS_REQ_STTS); + u32 req = iwl_trans_read_umac_prph_no_grab(iwl_trans, + WFPM_RSRCS_4PHS_REQ_STTS); int ret; if (!(req & RSRC_REQ_CNVR_TOP)) { @@ -3936,7 +3936,7 @@ static void get_crf_id(struct iwl_trans *iwl_trans, } /* Enable access to peripheral registers */ - val = iwl_read_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG); + val = iwl_trans_read_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG); val |= WFPM_AUX_CTL_AUX_IF_MAC_OWNER_MSK; iwl_pcie_write_umac_prph_no_grab(iwl_trans, WFPM_CTRL_REG, val); @@ -3968,7 +3968,7 @@ static void get_crf_id(struct iwl_trans *iwl_trans, } /* Read cdb info (also contains the jacket info if needed in the future */ - hw_wfpm_id = iwl_read_umac_prph_no_grab(iwl_trans, WFPM_OTP_CFG1_ADDR); + hw_wfpm_id = iwl_trans_read_umac_prph_no_grab(iwl_trans, WFPM_OTP_CFG1_ADDR); IWL_INFO(iwl_trans, "Detected crf-id 0x%x, cnv-id 0x%x wfpm id 0x%x\n", info->hw_crf_id, info->hw_cnv_id, hw_wfpm_id); @@ -3985,8 +3985,8 @@ static int map_crf_id(struct iwl_trans *iwl_trans, u32 val = info->hw_crf_id; u32 step_id = REG_CRF_ID_STEP(val); u32 slave_id = REG_CRF_ID_SLAVE(val); - u32 hw_wfpm_id = iwl_read_umac_prph_no_grab(iwl_trans, - WFPM_OTP_CFG1_ADDR); + u32 hw_wfpm_id = iwl_trans_read_umac_prph_no_grab(iwl_trans, + WFPM_OTP_CFG1_ADDR); u32 cdb_id_wfpm = WFPM_OTP_CFG1_IS_CDB(hw_wfpm_id); /* Map between crf id to rf id */ @@ -4256,13 +4256,13 @@ int iwl_pcie_activate_nic(struct iwl_trans *trans) * D0U* --> D0A* (powered-up active) state. */ if (mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ | - CSR_GP_CNTRL_REG_FLAG_MAC_INIT); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_BZ_MAC_ACCESS_REQ | + CSR_GP_CNTRL_REG_FLAG_MAC_INIT); poll_ready = CSR_GP_CNTRL_REG_FLAG_MAC_STATUS; } else { - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_INIT_DONE); poll_ready = CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY; } @@ -4271,10 +4271,10 @@ int iwl_pcie_activate_nic(struct iwl_trans *trans) /* * Wait for clock stabilization; once stabilized, access to - * device-internal resources is supported, e.g. iwl_write_prph() + * device-internal resources is supported, e.g. iwl_trans_write_prph() * and accesses to uCode SRAM. */ - err = iwl_poll_bits(trans, CSR_GP_CNTRL, poll_ready, 25000); + err = iwl_trans_poll_bits(trans, CSR_GP_CNTRL, poll_ready, 25000); if (err < 0) { IWL_DEBUG_INFO(trans, "Failed to wake NIC\n"); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index cd744f7002b6..c217e5189df4 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -104,8 +104,8 @@ static void iwl_pcie_txq_inc_wr_ptr(struct iwl_trans *trans, if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { IWL_DEBUG_INFO(trans, "Tx queue %d requesting wakeup, GP1 = 0x%x\n", txq_id, reg); - iwl_set_bit(trans, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl_trans_set_bit(trans, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); txq->need_update = true; return; } @@ -493,21 +493,21 @@ void iwl_pcie_tx_start(struct iwl_trans *trans) sizeof(trans_pcie->txqs.queue_used)); trans_pcie->scd_base_addr = - iwl_read_prph(trans, SCD_SRAM_BASE_ADDR); + iwl_trans_read_prph(trans, SCD_SRAM_BASE_ADDR); /* reset context data, TX status and translation data */ iwl_trans_write_mem(trans, trans_pcie->scd_base_addr + SCD_CONTEXT_MEM_LOWER_BOUND, NULL, clear_dwords); - iwl_write_prph(trans, SCD_DRAM_BASE_ADDR, - trans_pcie->txqs.scd_bc_tbls.dma >> 10); + iwl_trans_write_prph(trans, SCD_DRAM_BASE_ADDR, + trans_pcie->txqs.scd_bc_tbls.dma >> 10); /* The chain extension of the SCD doesn't work well. This feature is * enabled by default by the HW, so we need to disable it manually. */ if (trans->mac_cfg->base->scd_chain_ext_wa) - iwl_write_prph(trans, SCD_CHAINEXT_EN, 0); + iwl_trans_write_prph(trans, SCD_CHAINEXT_EN, 0); iwl_trans_ac_txq_enable(trans, trans->conf.cmd_queue, trans->conf.cmd_fifo, @@ -518,19 +518,19 @@ void iwl_pcie_tx_start(struct iwl_trans *trans) /* Enable DMA channel */ for (chan = 0; chan < FH_TCSR_CHNL_NUM; chan++) - iwl_write_direct32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(chan), - FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | - FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE); + iwl_trans_write_direct32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(chan), + FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | + FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE); /* Update FH chicken bits */ reg_val = iwl_pcie_read_direct32(trans, FH_TX_CHICKEN_BITS_REG); - iwl_write_direct32(trans, FH_TX_CHICKEN_BITS_REG, - reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); + iwl_trans_write_direct32(trans, FH_TX_CHICKEN_BITS_REG, + reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); /* Enable L1-Active */ if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_8000) - iwl_clear_bits_prph(trans, APMG_PCIDEV_STT_REG, - APMG_PCIDEV_STT_VAL_L1_ACT_DIS); + iwl_trans_clear_bits_prph(trans, APMG_PCIDEV_STT_REG, + APMG_PCIDEV_STT_VAL_L1_ACT_DIS); } void iwl_trans_pcie_tx_reset(struct iwl_trans *trans) @@ -553,17 +553,17 @@ void iwl_trans_pcie_tx_reset(struct iwl_trans *trans) FH_MEM_CBBC_QUEUE(trans, txq_id), txq->dma_addr); else - iwl_write_direct32(trans, - FH_MEM_CBBC_QUEUE(trans, txq_id), - txq->dma_addr >> 8); + iwl_trans_write_direct32(trans, + FH_MEM_CBBC_QUEUE(trans, txq_id), + txq->dma_addr >> 8); iwl_pcie_txq_unmap(trans, txq_id); txq->read_ptr = 0; txq->write_ptr = 0; } /* Tell NIC where to find the "keep warm" buffer */ - iwl_write_direct32(trans, FH_KW_MEM_ADDR_REG, - trans_pcie->kw.dma >> 4); + iwl_trans_write_direct32(trans, FH_KW_MEM_ADDR_REG, + trans_pcie->kw.dma >> 4); /* * Send 0 as the scd_base_addr since the device may have be reset @@ -591,7 +591,7 @@ static void iwl_pcie_tx_stop_fh(struct iwl_trans *trans) } /* Wait for DMA channels to be idle */ - ret = iwl_poll_bits(trans, FH_TSSR_TX_STATUS_REG, mask, 5000); + ret = iwl_trans_poll_bits(trans, FH_TSSR_TX_STATUS_REG, mask, 5000); if (ret) IWL_ERR(trans, "Failing on timeout while stopping DMA channel %d [0x%08x]\n", @@ -684,7 +684,7 @@ void iwl_txq_log_scd_error(struct iwl_trans *trans, struct iwl_txq *txq) return; } - status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id)); + status = iwl_trans_read_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id)); fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7; active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE)); @@ -693,9 +693,9 @@ void iwl_txq_log_scd_error(struct iwl_trans *trans, struct iwl_txq *txq) txq_id, active ? "" : "in", fifo, jiffies_to_msecs(txq->wd_timeout), txq->read_ptr, txq->write_ptr, - iwl_read_prph(trans, SCD_QUEUE_RDPTR(txq_id)) & + iwl_trans_read_prph(trans, SCD_QUEUE_RDPTR(txq_id)) & (trans->mac_cfg->base->max_tfd_queue_size - 1), - iwl_read_prph(trans, SCD_QUEUE_WRPTR(txq_id)) & + iwl_trans_read_prph(trans, SCD_QUEUE_WRPTR(txq_id)) & (trans->mac_cfg->base->max_tfd_queue_size - 1), iwl_pcie_read_direct32(trans, FH_TX_TRB_REG(fifo))); } @@ -955,8 +955,8 @@ int iwl_pcie_tx_init(struct iwl_trans *trans) iwl_scd_deactivate_fifos(trans); /* Tell NIC where to find the "keep warm" buffer */ - iwl_write_direct32(trans, FH_KW_MEM_ADDR_REG, - trans_pcie->kw.dma >> 4); + iwl_trans_write_direct32(trans, FH_KW_MEM_ADDR_REG, + trans_pcie->kw.dma >> 4); spin_unlock_bh(&trans_pcie->irq_lock); @@ -984,14 +984,14 @@ int iwl_pcie_tx_init(struct iwl_trans *trans) * queue. * Circular buffer (TFD queue in DRAM) physical base address */ - iwl_write_direct32(trans, FH_MEM_CBBC_QUEUE(trans, txq_id), - trans_pcie->txqs.txq[txq_id]->dma_addr >> 8); + iwl_trans_write_direct32(trans, FH_MEM_CBBC_QUEUE(trans, txq_id), + trans_pcie->txqs.txq[txq_id]->dma_addr >> 8); } - iwl_set_bits_prph(trans, SCD_GP_CTRL, SCD_GP_CTRL_AUTO_ACTIVE_MODE); + iwl_trans_set_bits_prph(trans, SCD_GP_CTRL, SCD_GP_CTRL_AUTO_ACTIVE_MODE); if (trans->mac_cfg->base->num_of_queues > 20) - iwl_set_bits_prph(trans, SCD_GP_CTRL, - SCD_GP_CTRL_ENABLE_31_QUEUES); + iwl_trans_set_bits_prph(trans, SCD_GP_CTRL, + SCD_GP_CTRL_ENABLE_31_QUEUES); return 0; error: @@ -1222,13 +1222,13 @@ bool iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, u16 ssn, * Assumes that ssn_idx is valid (!= 0xFFF) */ txq->read_ptr = (ssn & 0xff); txq->write_ptr = (ssn & 0xff); - iwl_write_direct32(trans, HBUS_TARG_WRPTR, - (ssn & 0xff) | (txq_id << 8)); + iwl_trans_write_direct32(trans, HBUS_TARG_WRPTR, + (ssn & 0xff) | (txq_id << 8)); if (cfg) { u8 frame_limit = cfg->frame_limit; - iwl_write_prph(trans, SCD_QUEUE_RDPTR(txq_id), ssn); + iwl_trans_write_prph(trans, SCD_QUEUE_RDPTR(txq_id), ssn); /* Set up Tx window size and frame limit for this queue */ iwl_trans_write_mem32(trans, trans_pcie->scd_base_addr + @@ -1240,11 +1240,11 @@ bool iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, u16 ssn, SCD_QUEUE_CTX_REG2_VAL(FRAME_LIMIT, frame_limit)); /* Set up status area in SRAM, map to Tx DMA/FIFO, activate */ - iwl_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id), - (1 << SCD_QUEUE_STTS_REG_POS_ACTIVE) | - (cfg->fifo << SCD_QUEUE_STTS_REG_POS_TXF) | - (1 << SCD_QUEUE_STTS_REG_POS_WSL) | - SCD_QUEUE_STTS_REG_MSK); + iwl_trans_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id), + (1 << SCD_QUEUE_STTS_REG_POS_ACTIVE) | + (cfg->fifo << SCD_QUEUE_STTS_REG_POS_TXF) | + (1 << SCD_QUEUE_STTS_REG_POS_WSL) | + SCD_QUEUE_STTS_REG_MSK); /* enable the scheduler for this queue (only) */ if (txq_id == trans->conf.cmd_queue && diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c index 4365ffb0fd37..eb54b5da1d25 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c @@ -139,7 +139,7 @@ int iwl_pcie_poll_prph_bit(struct iwl_trans *trans, u32 addr, int t = 0; do { - if ((iwl_read_prph(trans, addr) & mask) == (bits & mask)) + if ((iwl_trans_read_prph(trans, addr) & mask) == (bits & mask)) return 0; udelay(IWL_PCIE_POLL_INTERVAL); t += IWL_PCIE_POLL_INTERVAL; @@ -163,7 +163,7 @@ int iwl_pcie_poll_umac_prph_bits_no_grab(struct iwl_trans *trans, u32 addr, int t = 0; do { - if ((iwl_read_umac_prph_no_grab(trans, addr) & mask) == + if ((iwl_trans_read_umac_prph_no_grab(trans, addr) & mask) == (bits & mask)) return 0; udelay(IWL_PCIE_POLL_INTERVAL); From 2874e58196eff1fae8bb07903ca72fb16c1a2c4c Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:48 +0300 Subject: [PATCH 1595/2126] wifi: iwlwifi: move iwl-io functions to iwl-trans This commit completes the removal of iwl-io. Now that all io helpers use the iwl_trans_ prefix, move them to iwl-trans.h/c. Includers are updated to pull in iwl-trans.h No functional change. Assisted-by: GitHubCopilot:claude-opus-4.8 Link: https://patch.msgid.link/20260930121740.28c8b1af4303.I93a06977d9f5affa16c699d32e0e0577e49a534e@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/Makefile | 1 - .../net/wireless/intel/iwlwifi/dvm/debugfs.c | 1 - .../net/wireless/intel/iwlwifi/dvm/devices.c | 2 +- .../net/wireless/intel/iwlwifi/dvm/eeprom.c | 2 +- drivers/net/wireless/intel/iwlwifi/dvm/led.c | 1 - drivers/net/wireless/intel/iwlwifi/dvm/lib.c | 2 +- .../net/wireless/intel/iwlwifi/dvm/mac80211.c | 1 - drivers/net/wireless/intel/iwlwifi/dvm/main.c | 2 +- .../net/wireless/intel/iwlwifi/dvm/power.c | 3 +- drivers/net/wireless/intel/iwlwifi/dvm/rx.c | 1 - drivers/net/wireless/intel/iwlwifi/dvm/tt.c | 2 +- drivers/net/wireless/intel/iwlwifi/dvm/tx.c | 3 +- .../net/wireless/intel/iwlwifi/dvm/ucode.c | 3 +- .../net/wireless/intel/iwlwifi/fw/dbg-old.c | 2 +- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 2 +- drivers/net/wireless/intel/iwlwifi/fw/dbg.h | 2 +- drivers/net/wireless/intel/iwlwifi/fw/dump.c | 2 +- drivers/net/wireless/intel/iwlwifi/fw/pnvm.c | 2 +- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 2 +- drivers/net/wireless/intel/iwlwifi/iwl-io.c | 99 ------------------- drivers/net/wireless/intel/iwlwifi/iwl-io.h | 72 -------------- .../wireless/intel/iwlwifi/iwl-nvm-parse.c | 2 +- drivers/net/wireless/intel/iwlwifi/iwl-scd.h | 1 - .../net/wireless/intel/iwlwifi/iwl-trans.c | 89 +++++++++++++++++ .../net/wireless/intel/iwlwifi/iwl-trans.h | 60 +++++++++++ .../net/wireless/intel/iwlwifi/mld/debugfs.c | 2 +- .../intel/iwlwifi/mld/ftm-initiator.c | 2 +- .../net/wireless/intel/iwlwifi/mvm/debugfs.c | 2 +- .../intel/iwlwifi/mvm/ftm-initiator.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/led.c | 2 +- .../net/wireless/intel/iwlwifi/mvm/mac-ctxt.c | 2 +- .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 1 - drivers/net/wireless/intel/iwlwifi/mvm/scan.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/tdls.c | 4 +- .../wireless/intel/iwlwifi/mvm/time-event.c | 1 - .../net/wireless/intel/iwlwifi/mvm/utils.c | 2 +- .../wireless/intel/iwlwifi/pcie/internal.h | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/tx-gen2.c | 2 +- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/utils.c | 2 +- .../net/wireless/intel/iwlwifi/pcie/utils.h | 2 +- 43 files changed, 181 insertions(+), 214 deletions(-) delete mode 100644 drivers/net/wireless/intel/iwlwifi/iwl-io.c delete mode 100644 drivers/net/wireless/intel/iwlwifi/iwl-io.h diff --git a/drivers/net/wireless/intel/iwlwifi/Makefile b/drivers/net/wireless/intel/iwlwifi/Makefile index 6746281350e0..504381b4aac7 100644 --- a/drivers/net/wireless/intel/iwlwifi/Makefile +++ b/drivers/net/wireless/intel/iwlwifi/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # common obj-$(CONFIG_IWLWIFI) += iwlwifi.o -iwlwifi-objs += iwl-io.o iwlwifi-objs += iwl-drv.o iwlwifi-objs += iwl-debug.o iwlwifi-objs += iwl-nvm-utils.o diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c index ed041710c74f..799599efdd06 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/debugfs.c @@ -14,7 +14,6 @@ #include "iwl-debug.h" #include "iwl-trans.h" -#include "iwl-io.h" #include "dev.h" #include "agn.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c index c22f68db3e83..b7bd5e6deb5d 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c @@ -10,7 +10,7 @@ /* * DVM device-specific data & functions */ -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "iwl-nvm-utils.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c b/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c index aa532635e414..190e482849ac 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/eeprom.c @@ -8,7 +8,7 @@ #include "iwl-drv.h" #include "iwl-debug.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "iwl-csr.h" #include "agn.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/led.c b/drivers/net/wireless/intel/iwlwifi/dvm/led.c index 6fa02cd0ab04..17b045ddb910 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/led.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/led.c @@ -14,7 +14,6 @@ #include #include #include -#include "iwl-io.h" #include "iwl-trans.h" #include "iwl-modparams.h" #include "dev.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/lib.c b/drivers/net/wireless/intel/iwlwifi/dvm/lib.c index 2e16799818e4..37d6f2cf7efb 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/lib.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/lib.c @@ -2,6 +2,7 @@ /****************************************************************************** * * Copyright(c) 2008 - 2014, 2022 Intel Corporation. All rights reserved. + * Copyright (C) 2026 Intel Corporation *****************************************************************************/ #include #include @@ -9,7 +10,6 @@ #include #include -#include "iwl-io.h" #include "iwl-agn-hw.h" #include "iwl-trans.h" #include "iwl-modparams.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c index 1da59e724054..e83bf615c161 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/mac80211.c @@ -23,7 +23,6 @@ #include -#include "iwl-io.h" #include "iwl-trans.h" #include "iwl-op-mode.h" #include "iwl-modparams.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/main.c b/drivers/net/wireless/intel/iwlwifi/dvm/main.c index b3f73c773abe..4bf69f7a35a6 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/main.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/main.c @@ -27,8 +27,8 @@ #include #include "iwl-nvm-utils.h" -#include "iwl-io.h" #include "iwl-trans.h" +#include "iwl-devtrace.h" #include "iwl-op-mode.h" #include "iwl-drv.h" #include "iwl-modparams.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/power.c b/drivers/net/wireless/intel/iwlwifi/dvm/power.c index e7dbba7134f7..4e19799d15d7 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/power.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/power.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. - * Copyright (C) 2019, 2025 Intel Corporation + * Copyright (C) 2019, 2025-2026 Intel Corporation * * Portions of this file are derived from the ipw3945 project, as well * as portions of the ieee80211 subsystem header files. @@ -13,7 +13,6 @@ #include #include #include -#include "iwl-io.h" #include "iwl-debug.h" #include "iwl-trans.h" #include "iwl-modparams.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c index 77aa7e04854f..fa2aff5bea6c 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/rx.c @@ -16,7 +16,6 @@ #include #include "iwl-trans.h" -#include "iwl-io.h" #include "dev.h" #include "calib.h" #include "agn.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/tt.c b/drivers/net/wireless/intel/iwlwifi/dvm/tt.c index c4ee22876f77..a414eb7c2446 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/tt.c @@ -13,7 +13,7 @@ #include #include #include -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-modparams.h" #include "iwl-debug.h" #include "agn.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/tx.c b/drivers/net/wireless/intel/iwlwifi/dvm/tx.c index 1a0167f67c7b..8dbc52971e7b 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/tx.c @@ -3,14 +3,13 @@ * * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. * Copyright (C) 2019 Intel Corporation - * Copyright (C) 2023, 2025 Intel Corporation + * Copyright (C) 2023, 2025-2026 Intel Corporation *****************************************************************************/ #include #include #include #include -#include "iwl-io.h" #include "iwl-trans.h" #include "iwl-agn-hw.h" #include "dev.h" diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/ucode.c b/drivers/net/wireless/intel/iwlwifi/dvm/ucode.c index ac90191a3973..2ab1a32d774e 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/ucode.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/ucode.c @@ -3,12 +3,11 @@ * * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. * Copyright(c) 2015 Intel Deutschland GmbH - * Copyright (C) 2025 Intel Corporation + * Copyright (C) 2025-2026 Intel Corporation *****************************************************************************/ #include -#include "iwl-io.h" #include "iwl-agn-hw.h" #include "iwl-trans.h" #include "iwl-fh.h" diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c index 320e891b3b03..09c798d2eba3 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg-old.c @@ -9,7 +9,7 @@ #include "runtime.h" #include "dbg.h" #include "debugfs.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "iwl-csr.h" #include "iwl-fh.h" diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 8827e4f317f1..8be5202dba94 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -9,7 +9,7 @@ #include "runtime.h" #include "dbg.h" #include "debugfs.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "iwl-csr.h" #include "iwl-fh.h" diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h index fc962a320583..70134d8f03c4 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h @@ -10,7 +10,7 @@ #include #include "runtime.h" #include "iwl-prph.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "file.h" #include "error-dump.h" #include "api/commands.h" diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dump.c b/drivers/net/wireless/intel/iwlwifi/fw/dump.c index deb7af465746..b76abc77f495 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dump.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dump.c @@ -9,7 +9,7 @@ #include "runtime.h" #include "dbg.h" #include "debugfs.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "iwl-csr.h" #include "pnvm.h" diff --git a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c index 6e863059ffa7..ccd190ab8a55 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c @@ -6,7 +6,7 @@ #include "iwl-drv.h" #include "pnvm.h" #include "iwl-prph.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "fw/api/commands.h" #include "fw/api/nvm-reg.h" #include "fw/api/alive.h" diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 872df8f6c375..a654ab29ee42 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -6,7 +6,7 @@ #include "iwl-drv.h" #include "pnvm.h" #include "iwl-prph.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "fw/uefi.h" #include "fw/api/alive.h" diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.c b/drivers/net/wireless/intel/iwlwifi/iwl-io.c deleted file mode 100644 index 09965fb39fb6..000000000000 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.c +++ /dev/null @@ -1,99 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause -/* - * Copyright (C) 2003-2014, 2018-2022, 2024-2026 Intel Corporation - * Copyright (C) 2015-2016 Intel Deutschland GmbH - */ -#include -#include - -#include "iwl-drv.h" -#include "iwl-io.h" -#include "iwl-csr.h" -#include "iwl-debug.h" - -#define IWL_POLL_INTERVAL 10 /* microseconds */ - -int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout) -{ - int t = 0; - - do { - if ((iwl_trans_read32(trans, addr) & mask) == (bits & mask)) - return 0; - udelay(IWL_POLL_INTERVAL); - t += IWL_POLL_INTERVAL; - } while (t < timeout); - - return -ETIMEDOUT; -} -IWL_EXPORT_SYMBOL(iwl_trans_poll_bits_mask); - -void iwl_trans_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) -{ - if (iwl_trans_grab_nic_access(trans)) { - iwl_trans_write32(trans, reg, value); - iwl_trans_release_nic_access(trans); - } -} -IWL_EXPORT_SYMBOL(iwl_trans_write_direct32); - -u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) -{ - if (iwl_trans_grab_nic_access(trans)) { - u32 val = iwl_trans_read_prph_no_grab(trans, ofs); - - iwl_trans_release_nic_access(trans); - - return val; - } - - /* return as if we have a HW timeout/failure */ - return 0x5a5a5a5a; -} -IWL_EXPORT_SYMBOL(iwl_trans_read_prph); - -void iwl_trans_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, u32 delay_ms) -{ - if (iwl_trans_grab_nic_access(trans)) { - mdelay(delay_ms); - iwl_trans_write_prph_no_grab(trans, ofs, val); - iwl_trans_release_nic_access(trans); - } -} -IWL_EXPORT_SYMBOL(iwl_trans_write_prph_delay); - -void iwl_trans_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) -{ - if (iwl_trans_grab_nic_access(trans)) { - iwl_trans_write_prph_no_grab(trans, ofs, - iwl_trans_read_prph_no_grab(trans, ofs) | - mask); - iwl_trans_release_nic_access(trans); - } -} -IWL_EXPORT_SYMBOL(iwl_trans_set_bits_prph); - -void iwl_trans_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, - u32 bits, u32 mask) -{ - if (iwl_trans_grab_nic_access(trans)) { - iwl_trans_write_prph_no_grab(trans, ofs, - (iwl_trans_read_prph_no_grab(trans, ofs) & - mask) | bits); - iwl_trans_release_nic_access(trans); - } -} -IWL_EXPORT_SYMBOL(iwl_trans_set_bits_mask_prph); - -void iwl_trans_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) -{ - u32 val; - - if (iwl_trans_grab_nic_access(trans)) { - val = iwl_trans_read_prph_no_grab(trans, ofs); - iwl_trans_write_prph_no_grab(trans, ofs, (val & ~mask)); - iwl_trans_release_nic_access(trans); - } -} -IWL_EXPORT_SYMBOL(iwl_trans_clear_bits_prph); diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-io.h b/drivers/net/wireless/intel/iwlwifi/iwl-io.h deleted file mode 100644 index 5cb422a4d9de..000000000000 --- a/drivers/net/wireless/intel/iwlwifi/iwl-io.h +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ -/* - * Copyright (C) 2018-2021, 2025-2026 Intel Corporation - */ -#ifndef __iwl_io_h__ -#define __iwl_io_h__ - -#include "iwl-devtrace.h" -#include "iwl-trans.h" - -static inline void iwl_trans_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) -{ - iwl_trans_set_bits_mask(trans, reg, mask, mask); -} - -static inline void iwl_trans_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) -{ - iwl_trans_set_bits_mask(trans, reg, mask, 0); -} - -int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, - u32 bits, u32 mask, int timeout); -static inline int iwl_trans_poll_bits(struct iwl_trans *trans, u32 addr, u32 bits, - int timeout) -{ - return iwl_trans_poll_bits_mask(trans, addr, bits, bits, timeout); -} - -void iwl_trans_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); - - -u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs); -void iwl_trans_write_prph_delay(struct iwl_trans *trans, u32 ofs, - u32 val, u32 delay_ms); -static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) -{ - iwl_trans_write_prph_delay(trans, ofs, val, 0); -} - -void iwl_trans_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); -void iwl_trans_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, - u32 bits, u32 mask); -void iwl_trans_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); - -/* - * UMAC periphery address space changed from 0xA00000 to 0xD00000 starting from - * device family AX200. So peripheries used in families above and below AX200 - * should go through iwl_trans_..._umac_..._prph. - */ -static inline u32 iwl_trans_umac_prph(struct iwl_trans *trans, u32 ofs) -{ - return ofs + trans->mac_cfg->umac_prph_offset; -} - -static inline u32 iwl_trans_read_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs) -{ - return iwl_trans_read_prph_no_grab(trans, ofs + - trans->mac_cfg->umac_prph_offset); -} - -static inline u32 iwl_trans_read_umac_prph(struct iwl_trans *trans, u32 ofs) -{ - return iwl_trans_read_prph(trans, ofs + trans->mac_cfg->umac_prph_offset); -} - -static inline void iwl_trans_write_umac_prph(struct iwl_trans *trans, u32 ofs, - u32 val) -{ - iwl_trans_write_prph(trans, ofs + trans->mac_cfg->umac_prph_offset, val); -} - -#endif diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index 9a8355514c4f..ed2b094c1ad7 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -16,7 +16,7 @@ #include "iwl-modparams.h" #include "iwl-nvm-parse.h" #include "iwl-prph.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-csr.h" #include "fw/api/nvm-reg.h" #include "fw/api/commands.h" diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-scd.h b/drivers/net/wireless/intel/iwlwifi/iwl-scd.h index 22a7da73a918..f13568d3094b 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-scd.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-scd.h @@ -7,7 +7,6 @@ #define __iwl_scd_h__ #include "iwl-trans.h" -#include "iwl-io.h" #include "iwl-prph.h" diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 59b4e180825f..09e5b606df26 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include "iwl-trans.h" @@ -450,6 +451,94 @@ void iwl_trans_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) return iwl_pcie_write_prph_no_grab(trans, ofs, val); } +#define IWL_POLL_INTERVAL 10 /* microseconds */ + +int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int t = 0; + + do { + if ((iwl_trans_read32(trans, addr) & mask) == (bits & mask)) + return 0; + udelay(IWL_POLL_INTERVAL); + t += IWL_POLL_INTERVAL; + } while (t < timeout); + + return -ETIMEDOUT; +} +IWL_EXPORT_SYMBOL(iwl_trans_poll_bits_mask); + +void iwl_trans_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) +{ + if (iwl_trans_grab_nic_access(trans)) { + iwl_trans_write32(trans, reg, value); + iwl_trans_release_nic_access(trans); + } +} +IWL_EXPORT_SYMBOL(iwl_trans_write_direct32); + +u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) +{ + if (iwl_trans_grab_nic_access(trans)) { + u32 val = iwl_trans_read_prph_no_grab(trans, ofs); + + iwl_trans_release_nic_access(trans); + + return val; + } + + /* return as if we have a HW timeout/failure */ + return 0x5a5a5a5a; +} +IWL_EXPORT_SYMBOL(iwl_trans_read_prph); + +void iwl_trans_write_prph_delay(struct iwl_trans *trans, u32 ofs, u32 val, + u32 delay_ms) +{ + if (iwl_trans_grab_nic_access(trans)) { + mdelay(delay_ms); + iwl_trans_write_prph_no_grab(trans, ofs, val); + iwl_trans_release_nic_access(trans); + } +} +IWL_EXPORT_SYMBOL(iwl_trans_write_prph_delay); + +void iwl_trans_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) +{ + if (iwl_trans_grab_nic_access(trans)) { + iwl_trans_write_prph_no_grab(trans, ofs, + iwl_trans_read_prph_no_grab(trans, ofs) | + mask); + iwl_trans_release_nic_access(trans); + } +} +IWL_EXPORT_SYMBOL(iwl_trans_set_bits_prph); + +void iwl_trans_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, + u32 bits, u32 mask) +{ + if (iwl_trans_grab_nic_access(trans)) { + iwl_trans_write_prph_no_grab(trans, ofs, + (iwl_trans_read_prph_no_grab(trans, ofs) & + mask) | bits); + iwl_trans_release_nic_access(trans); + } +} +IWL_EXPORT_SYMBOL(iwl_trans_set_bits_mask_prph); + +void iwl_trans_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) +{ + u32 val; + + if (iwl_trans_grab_nic_access(trans)) { + val = iwl_trans_read_prph_no_grab(trans, ofs); + iwl_trans_write_prph_no_grab(trans, ofs, (val & ~mask)); + iwl_trans_release_nic_access(trans); + } +} +IWL_EXPORT_SYMBOL(iwl_trans_clear_bits_prph); + void iwl_trans_force_nmi(struct iwl_trans *trans) { if (trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_9000) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index 18c1c46c11ce..a32b03f19c3f 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -977,6 +977,66 @@ int iwl_trans_sw_reset(struct iwl_trans *trans); void iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value); +static inline void iwl_trans_set_bit(struct iwl_trans *trans, u32 reg, u32 mask) +{ + iwl_trans_set_bits_mask(trans, reg, mask, mask); +} + +static inline void iwl_trans_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) +{ + iwl_trans_set_bits_mask(trans, reg, mask, 0); +} + +int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout); +static inline int iwl_trans_poll_bits(struct iwl_trans *trans, u32 addr, u32 bits, + int timeout) +{ + return iwl_trans_poll_bits_mask(trans, addr, bits, bits, timeout); +} + +void iwl_trans_write_direct32(struct iwl_trans *trans, u32 reg, u32 value); + +u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs); +void iwl_trans_write_prph_delay(struct iwl_trans *trans, u32 ofs, + u32 val, u32 delay_ms); +static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) +{ + iwl_trans_write_prph_delay(trans, ofs, val, 0); +} + +void iwl_trans_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); +void iwl_trans_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, + u32 bits, u32 mask); +void iwl_trans_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask); + +/* + * UMAC periphery address space changed from 0xA00000 to 0xD00000 starting from + * device family AX200. So peripheries used in families above and below AX200 + * should go through iwl_trans_..._umac_..._prph. + */ +static inline u32 iwl_trans_umac_prph(struct iwl_trans *trans, u32 ofs) +{ + return ofs + trans->mac_cfg->umac_prph_offset; +} + +static inline u32 iwl_trans_read_umac_prph_no_grab(struct iwl_trans *trans, u32 ofs) +{ + return iwl_trans_read_prph_no_grab(trans, ofs + + trans->mac_cfg->umac_prph_offset); +} + +static inline u32 iwl_trans_read_umac_prph(struct iwl_trans *trans, u32 ofs) +{ + return iwl_trans_read_prph(trans, ofs + trans->mac_cfg->umac_prph_offset); +} + +static inline void iwl_trans_write_umac_prph(struct iwl_trans *trans, u32 ofs, + u32 val) +{ + iwl_trans_write_prph(trans, ofs + trans->mac_cfg->umac_prph_offset, val); +} + bool iwl_trans_grab_nic_access(struct iwl_trans *trans); /** diff --git a/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c index dd4bf7cb6a79..b8793b71494d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c @@ -5,7 +5,7 @@ #include "mld.h" #include "debugfs.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "hcmd.h" #include "iface.h" #include "sta.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c b/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c index a4b8037b5c76..a6a4f9672e4f 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c @@ -8,7 +8,7 @@ #include "mld.h" #include "iface.h" #include "phy.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "constants.h" #include "fw/api/location.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c index 48f8bab4dc85..90175307a7db 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c @@ -13,7 +13,7 @@ #include "mvm.h" #include "sta.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "debugfs.h" #include "iwl-modparams.h" #include "iwl-drv.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c index 8d7f60dcd027..4c39a452564d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c @@ -7,7 +7,7 @@ #include #include #include "mvm.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "constants.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/led.c b/drivers/net/wireless/intel/iwlwifi/mvm/led.c index 264423943b60..ac238c963855 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/led.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/led.c @@ -4,7 +4,7 @@ * Copyright (C) 2017 Intel Deutschland GmbH */ #include -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-csr.h" #include "mvm.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c index b41b4bbf0049..58a77056e607 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c @@ -7,7 +7,7 @@ #include #include #include -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "fw-api.h" #include "mvm.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c index a4f3d3c2bd35..daa05339e3fb 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c @@ -19,7 +19,7 @@ #include "iwl-drv.h" #include "iwl-op-mode.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "mvm.h" #include "sta.h" #include "time-event.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c index 653c620361d5..183251457361 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c @@ -20,7 +20,6 @@ #include "iwl-phy-db.h" #include "iwl-nvm-utils.h" #include "iwl-csr.h" -#include "iwl-io.h" #include "iwl-prph.h" #include "rs.h" #include "fw/api/scan.h" diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c index a94eaca0b3ed..c12eda75317d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c @@ -10,7 +10,7 @@ #include "mvm.h" #include "fw/api/scan.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-utils.h" #define IWL_DENSE_EBS_SCAN_RATIO 5 diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tdls.c b/drivers/net/wireless/intel/iwlwifi/mvm/tdls.c index a7cd2e4ba1ae..6aac71cfccb3 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tdls.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tdls.c @@ -2,12 +2,12 @@ /* * Copyright (C) 2014 Intel Mobile Communications GmbH * Copyright (C) 2017 Intel Deutschland GmbH - * Copyright (C) 2018-2020, 2022-2025 Intel Corporation + * Copyright (C) 2018-2020, 2022-2026 Intel Corporation */ #include #include "mvm.h" #include "time-event.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #define TU_TO_US(x) (x * 1024) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c b/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c index 93b46c9e2333..5a800d3f2a98 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c @@ -12,7 +12,6 @@ #include "fw-api.h" #include "time-event.h" #include "mvm.h" -#include "iwl-io.h" #include "iwl-prph.h" /* diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/utils.c b/drivers/net/wireless/intel/iwlwifi/mvm/utils.c index cd0d89feecea..e97ab2c9e5ba 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/utils.c @@ -7,7 +7,7 @@ #include #include "iwl-debug.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-prph.h" #include "iwl-csr.h" #include "mvm.h" diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index d74742df2fe5..e0ac9f2e6526 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -18,8 +18,8 @@ #include "iwl-fh.h" #include "iwl-csr.h" #include "iwl-trans.h" +#include "iwl-devtrace.h" #include "iwl-debug.h" -#include "iwl-io.h" #include "iwl-op-mode.h" #include "iwl-drv.h" #include "iwl-context-info.h" diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index e3fe5a912a8b..f033bb51dcca 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -9,7 +9,7 @@ #include #include "iwl-prph.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "internal.h" #include "pcie/utils.h" #include "iwl-op-mode.h" diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c index abdb2548827f..e6bebd37417f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c @@ -8,7 +8,7 @@ #include "iwl-debug.h" #include "iwl-csr.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "internal.h" #include "fw/api/tx.h" #include "fw/api/commands.h" diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index c217e5189df4..d612678ae122 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -20,7 +20,7 @@ #include "iwl-debug.h" #include "iwl-csr.h" #include "iwl-prph.h" -#include "iwl-io.h" +#include "iwl-trans.h" #include "iwl-scd.h" #include "iwl-op-mode.h" #include "internal.h" diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c index eb54b5da1d25..8aa43e5ac0e1 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.c @@ -6,7 +6,7 @@ #include #include -#include "iwl-io.h" +#include "iwl-trans.h" #include "pcie/utils.h" void iwl_trans_pcie_dump_regs(struct iwl_trans *trans, struct pci_dev *pdev) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h index 74c23ec199e2..ece1caaa4948 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/utils.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/utils.h @@ -6,7 +6,7 @@ #ifndef __iwl_pcie_utils_h__ #define __iwl_pcie_utils_h__ -#include "iwl-io.h" +#include "iwl-trans.h" #include "internal.h" void iwl_trans_pcie_dump_regs(struct iwl_trans *trans, struct pci_dev *pdev); From a95d336d91c0bd7108735fe0db75b06b0bfad7f3 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:49 +0300 Subject: [PATCH 1596/2126] wifi: iwlwifi: call generic trans API and not pcie one iwl_trans_pcie_reset is currently called from outside of pcie, like in mvm opmode. This is wrong and contradicts the architecture. Add a generic trans API which will call the PCIE implementation. Link: https://patch.msgid.link/20260930121740.444e257d5a49.I4c4892ca6bcae0095639341f3c2aba76bcd1ee86@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-trans.c | 9 ++++++++- drivers/net/wireless/intel/iwlwifi/iwl-trans.h | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 3 +-- drivers/net/wireless/intel/iwlwifi/pcie/internal.h | 1 + drivers/net/wireless/intel/iwlwifi/pcie/trans.c | 1 - 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index 09e5b606df26..b0eb3deba23d 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -261,7 +261,7 @@ static void iwl_trans_restart_wk(struct work_struct *wk) iwl_trans_schedule_reprobe(trans, 0); break; default: - iwl_trans_pcie_reset(trans, mode); + iwl_trans_reset(trans, mode); break; } } @@ -929,3 +929,10 @@ int iwl_trans_activate_nic(struct iwl_trans *trans) } IWL_EXPORT_SYMBOL(iwl_trans_activate_nic); + +void iwl_trans_reset(struct iwl_trans *trans, enum iwl_reset_mode mode) +{ + iwl_trans_pcie_reset(trans, mode); +} +IWL_EXPORT_SYMBOL(iwl_trans_reset); + diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index a32b03f19c3f..719b6c9ba360 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -1216,7 +1216,7 @@ enum iwl_reset_mode { IWL_RESET_MODE_BACKOFF, }; -void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode); +void iwl_trans_reset(struct iwl_trans *trans, enum iwl_reset_mode mode); void iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans); /* Internal helper */ diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c index 9b4637a3d1ef..ae109e3ea141 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c @@ -640,8 +640,7 @@ static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm) /* if we needed reset then fail here, but notify and remove */ if (mvm->fw_product_reset) { iwl_mei_alive_notif(false); - iwl_trans_pcie_reset(mvm->trans, - IWL_RESET_MODE_RESCAN); + iwl_trans_reset(mvm->trans, IWL_RESET_MODE_RESCAN); } goto error; diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index e0ac9f2e6526..fab73693e683 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -1148,6 +1148,7 @@ int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr, int iwl_trans_pcie_read_mem_no_grab(struct iwl_trans *trans, u32 addr, void *buf, u32 dwords); int iwl_trans_pcie_sw_reset(struct iwl_trans *trans, bool retake_ownership); +void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode); struct iwl_trans_dump_data * iwl_trans_pcie_dump_data(struct iwl_trans *trans, u32 dump_mask, const struct iwl_dump_sanitize_ops *sanitize_ops, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 8da0cc603070..59e9ef0d6b51 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -2329,7 +2329,6 @@ void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode) pci_dev_get(removal->pdev); schedule_work(&removal->work); } -EXPORT_SYMBOL(iwl_trans_pcie_reset); /* * This version doesn't disable BHs but rather assumes they're From a24618b2e22b91d3932df48e160744d8a9d2780d Mon Sep 17 00:00:00 2001 From: Daniel Gabay Date: Wed, 30 Sep 2026 12:19:50 +0300 Subject: [PATCH 1597/2126] wifi: iwlwifi: mld: test TX gp2 timestamps Add KUnit tests for the gp2 estimate: timestamp arithmetic and u32 wraparounds, zero offsets, zero timestamp handling, and the expiry and refresh thresholds driven by valid_until. Exercise the thresholds with jiffies near wraparound. Signed-off-by: Daniel Gabay Assisted-by: LLM Link: https://patch.msgid.link/20260930121740.16628072486e.Ia0ead71cdc521a3c5db80bfd2e11a718692b3ab2@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/mld/tests/Makefile | 2 +- .../wireless/intel/iwlwifi/mld/tests/tx-gp2.c | 154 ++++++++++++++++++ drivers/net/wireless/intel/iwlwifi/mld/tx.c | 3 +- drivers/net/wireless/intel/iwlwifi/mld/tx.h | 5 + 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 drivers/net/wireless/intel/iwlwifi/mld/tests/tx-gp2.c diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile b/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile index efa61638b8ee..730185be3fa8 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile +++ b/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause iwlmld-tests-y += module.o hcmd.o utils.o link.o rx.o agg.o link-selection.o -iwlmld-tests-y += chan_load_thresh.o +iwlmld-tests-y += chan_load_thresh.o tx-gp2.o ccflags-y += -I$(src)/../ obj-$(CONFIG_IWLWIFI_KUNIT_TESTS) += iwlmld-tests.o diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tests/tx-gp2.c b/drivers/net/wireless/intel/iwlwifi/mld/tests/tx-gp2.c new file mode 100644 index 000000000000..535140eb17c4 --- /dev/null +++ b/drivers/net/wireless/intel/iwlwifi/mld/tests/tx-gp2.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* + * KUnit tests for TX gp2 timestamp handling + * + * Copyright (C) 2026 Intel Corporation + */ +#include + +#include "mld.h" +#include "tx.h" + +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); + +static const struct tx_gp2_case { + const char *desc; + u32 est_gp2_us; + u32 est_host_us; + u32 tx_host_us; + long valid_for; + u32 expected_gp2_us; + bool expected_refresh; +} tx_gp2_cases[] = { + { + .desc = "zero offset is valid", + .est_gp2_us = 2000, + .est_host_us = 2000, + .tx_host_us = 3500, + .valid_for = IWL_MLD_TX_GP2_VALID_PERIOD, + .expected_gp2_us = 3500, + }, + { + .desc = "gp2 behind host", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = IWL_MLD_TX_GP2_VALID_PERIOD, + .expected_gp2_us = 3500, + }, + { + .desc = "gp2 ahead of host", + .est_gp2_us = 10000, + .est_host_us = 2000, + .tx_host_us = 3500, + .valid_for = IWL_MLD_TX_GP2_VALID_PERIOD, + .expected_gp2_us = 11500, + }, + { + .desc = "gp2 wraps after the estimate", + .est_gp2_us = U32_MAX - 999, + .est_host_us = 1000, + .tx_host_us = 2500, + .valid_for = IWL_MLD_TX_GP2_VALID_PERIOD, + .expected_gp2_us = 500, + }, + { + .desc = "host time wraps after the estimate", + .est_gp2_us = 5000, + .est_host_us = U32_MAX - 999, + .tx_host_us = 500, + .valid_for = IWL_MLD_TX_GP2_VALID_PERIOD, + .expected_gp2_us = 6500, + }, + { + .desc = "gp2 landing on 0 is reported as 1", + .est_gp2_us = U32_MAX - 1499, + .est_host_us = 1000, + .tx_host_us = 2500, + .valid_for = IWL_MLD_TX_GP2_VALID_PERIOD, + .expected_gp2_us = 1, + }, + { + .desc = "within the refresh margin: still timestamped", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = IWL_MLD_TX_GP2_REFRESH_MARGIN - 1, + .expected_gp2_us = 3500, + .expected_refresh = true, + }, + { + .desc = "outside the refresh margin: no refresh", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = IWL_MLD_TX_GP2_REFRESH_MARGIN + 1, + .expected_gp2_us = 3500, + }, + { + .desc = "at the refresh threshold", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = IWL_MLD_TX_GP2_REFRESH_MARGIN, + .expected_gp2_us = 3500, + .expected_refresh = true, + }, + { + .desc = "last valid tick", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = 1, + .expected_gp2_us = 3500, + .expected_refresh = true, + }, + { + .desc = "validity reached: leave the frame unstamped", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = 0, + .expected_refresh = true, + }, + { + .desc = "validity passed: leave the frame unstamped", + .est_gp2_us = 2000, + .est_host_us = 10000, + .tx_host_us = 11500, + .valid_for = -1, + .expected_refresh = true, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(tx_gp2, tx_gp2_cases, desc); + +static void test_tx_gp2(struct kunit *test) +{ + /* Pin time near wraparound to exercise wrapped validity deadlines. */ + const unsigned long now = + ULONG_MAX - IWL_MLD_TX_GP2_REFRESH_MARGIN - 1; + const struct tx_gp2_case *test_case = test->param_value; + u32 delta_us = test_case->est_gp2_us - test_case->est_host_us; + unsigned long valid_until = now + test_case->valid_for; + bool refresh = !test_case->expected_refresh; + u32 timestamp; + + timestamp = iwl_mld_tx_gp2_from_est(delta_us, valid_until, + test_case->tx_host_us, now, + &refresh); + KUNIT_EXPECT_EQ(test, timestamp, test_case->expected_gp2_us); + KUNIT_EXPECT_EQ(test, refresh, test_case->expected_refresh); +} + +static struct kunit_case tx_gp2_test_cases[] = { + KUNIT_CASE_PARAM(test_tx_gp2, tx_gp2_gen_params), + {} +}; + +static struct kunit_suite tx_gp2_test_suite = { + .name = "iwl_mld_tx_gp2", + .test_cases = tx_gp2_test_cases, +}; + +kunit_test_suite(tx_gp2_test_suite); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tx.c b/drivers/net/wireless/intel/iwlwifi/mld/tx.c index aac7d43bffd1..fc501ac0c1f2 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tx.c @@ -29,7 +29,7 @@ static u32 iwl_mld_tx_gp2_host_us(void) /* Returns the gp2 for the TX command, or 0 to leave the frame unstamped. * Sets @refresh when the estimate expired or is about to. */ -static u32 +VISIBLE_IF_IWLWIFI_KUNIT u32 iwl_mld_tx_gp2_from_est(u32 delta_us, unsigned long valid_until, u32 host_us, unsigned long now, bool *refresh) { @@ -46,6 +46,7 @@ iwl_mld_tx_gp2_from_est(u32 delta_us, unsigned long valid_until, u32 host_us, /* 0 means no timestamp; use 1 for a valid wrapped value. */ return gp2 ?: 1; } +EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_tx_gp2_from_est); static u32 iwl_mld_tx_gp2_timestamp(struct iwl_mld *mld) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tx.h b/drivers/net/wireless/intel/iwlwifi/mld/tx.h index 0a9a2e4abcab..a376e8c9c500 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tx.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/tx.h @@ -106,4 +106,9 @@ void iwl_mld_tx_gp2_init(struct iwl_mld *mld); void iwl_mld_tx_gp2_start(struct iwl_mld *mld); void iwl_mld_tx_gp2_stop(struct iwl_mld *mld); +#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS) +u32 iwl_mld_tx_gp2_from_est(u32 delta_us, unsigned long valid_until, + u32 host_us, unsigned long now, bool *refresh); +#endif + #endif /* __iwl_mld_tx_h__ */ From 5567873198b2eea8e22a12a104ae870e8c318e3f Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Wed, 30 Sep 2026 12:19:51 +0300 Subject: [PATCH 1598/2126] wifi: iwlwifi: trans: bring virtualization back We removed virtualization because PCIe is the only bus. The problem with the if-else approach is that it causes a dual dependency: the generic trans needs to include the bus specific, and vice-versa. Besides being a bad design, it also has pratical problems: 1. small functions that could be static inline ones - can't, because only iwl-trans.c has the bus specific include. 2. while in pcie we have one giant header file, ironically called internal.h, that has all the declarations needed by the generic trans, in USB there will be several ones, and including them means including all the USB internal logic, which should not be exposed. This commit brings back the virtualization. Since gen1 and gen2 were never split properly, and since they share almost all the callbacks, pcie registers with a single ops struct. This also fixed the debug code to call a generic API for fw reset handshake, instead of calling the pcie directly. Assisted-by: GitHubCopilot:claude-opus-4.8 Reviewed-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.c0dde34db029.I0b53f83df3faad21c0c39b3e709896e7dde6ac35@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 4 +- .../net/wireless/intel/iwlwifi/iwl-trans.c | 230 ++++++++++++------ .../net/wireless/intel/iwlwifi/iwl-trans.h | 150 +++++++++++- .../wireless/intel/iwlwifi/pcie/internal.h | 5 +- .../net/wireless/intel/iwlwifi/pcie/trans.c | 101 +++++++- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 3 + 6 files changed, 407 insertions(+), 86 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 8be5202dba94..1d34ad59bb71 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -1820,14 +1820,14 @@ static u32 iwl_dump_ini_trigger(struct iwl_fw_runtime *fwrt, cpu_to_le32(IWL_FW_INI_APPLY_POLICY_SPLIT_DUMP_RESET)) { size += iwl_dump_ini_dump_entries(fwrt, list, IWL_INI_DUMP_EARLY_REGIONS); - iwl_trans_pcie_fw_reset_handshake(fwrt->trans); + iwl_trans_fw_reset_handshake(fwrt->trans); size += iwl_dump_ini_dump_entries(fwrt, list, IWL_INI_DUMP_LATE_REGIONS); } else { if (fw_has_capa(&fwrt->fw->ucode_capa, IWL_UCODE_TLV_CAPA_RESET_DURING_ASSERT) && iwl_dump_due_to_error(tp_id)) - iwl_trans_pcie_fw_reset_handshake(fwrt->trans); + iwl_trans_fw_reset_handshake(fwrt->trans); size += iwl_dump_ini_dump_entries(fwrt, list, IWL_INI_DUMP_ALL_REGIONS); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c index b0eb3deba23d..6ddf4945ed1c 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.c @@ -14,8 +14,6 @@ #include "iwl-prph.h" #include #include "fw/api/commands.h" -#include "pcie/internal.h" -#include "pcie/iwl-context-info-v2.h" struct iwl_trans_dev_restart_data { struct list_head list; @@ -268,6 +266,7 @@ static void iwl_trans_restart_wk(struct work_struct *wk) struct iwl_trans *iwl_trans_alloc(unsigned int priv_size, struct device *dev, + const struct iwl_trans_ops *ops, const struct iwl_mac_cfg *mac_cfg) { struct iwl_trans *trans; @@ -279,6 +278,7 @@ struct iwl_trans *iwl_trans_alloc(unsigned int priv_size, if (!trans) return NULL; + trans->ops = ops; trans->mac_cfg = mac_cfg; #ifdef CONFIG_LOCKDEP @@ -302,6 +302,9 @@ int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd) { int ret; + if (WARN_ON_ONCE(!trans->ops->send_cmd)) + return -EOPNOTSUPP; + if (unlikely(!(cmd->flags & CMD_SEND_IN_RFKILL) && test_bit(STATUS_RFKILL_OPMODE, &trans->status))) return -ERFKILL; @@ -321,7 +324,7 @@ int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd) cmd->id = DEF_ID(cmd->id); } - ret = iwl_trans_pcie_send_hcmd(trans, cmd); + ret = trans->ops->send_cmd(trans, cmd); if (!(cmd->flags & CMD_ASYNC)) lock_map_release(&trans->sync_cmd_lockdep_map); @@ -335,14 +338,18 @@ IWL_EXPORT_SYMBOL(iwl_trans_send_cmd); struct iwl_device_tx_cmd *iwl_trans_alloc_tx_cmd(struct iwl_trans *trans) { - return iwl_pcie_alloc_tx_cmd(trans); + if (WARN_ON_ONCE(!trans->ops->alloc_tx_cmd)) + return ERR_PTR(-EOPNOTSUPP); + return trans->ops->alloc_tx_cmd(trans); } IWL_EXPORT_SYMBOL(iwl_trans_alloc_tx_cmd); void iwl_trans_free_tx_cmd(struct iwl_trans *trans, struct iwl_device_tx_cmd *dev_cmd) { - iwl_pcie_free_tx_cmd(trans, dev_cmd); + if (WARN_ON_ONCE(!trans->ops->free_tx_cmd)) + return; + trans->ops->free_tx_cmd(trans, dev_cmd); } IWL_EXPORT_SYMBOL(iwl_trans_free_tx_cmd); @@ -397,7 +404,9 @@ void iwl_trans_op_mode_enter(struct iwl_trans *trans, WARN_ON_ONCE(!trans->conf.rx_mpdu_cmd); - iwl_trans_pcie_op_mode_enter(trans); + if (WARN_ON_ONCE(!trans->ops->op_mode_enter)) + return; + trans->ops->op_mode_enter(trans); } IWL_EXPORT_SYMBOL(iwl_trans_op_mode_enter); @@ -407,7 +416,9 @@ int iwl_trans_start_hw(struct iwl_trans *trans) clear_bit(STATUS_TRANS_RESET_IN_PROGRESS, &trans->status); - return iwl_trans_pcie_start_hw(trans); + if (WARN_ON_ONCE(!trans->ops->start_hw)) + return -EOPNOTSUPP; + return trans->ops->start_hw(trans); } IWL_EXPORT_SYMBOL(iwl_trans_start_hw); @@ -415,10 +426,8 @@ void iwl_trans_op_mode_leave(struct iwl_trans *trans) { might_sleep(); - if (trans->mac_cfg->gen2) - iwl_trans_pcie_gen2_op_mode_leave(trans); - else - iwl_trans_pcie_op_mode_leave(trans); + if (!WARN_ON_ONCE(!trans->ops->op_mode_leave)) + trans->ops->op_mode_leave(trans); cancel_delayed_work_sync(&trans->restart.wk); @@ -431,41 +440,40 @@ IWL_EXPORT_SYMBOL(iwl_trans_op_mode_leave); void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val) { - iwl_trans_pcie_write32(trans, ofs, val); + if (WARN_ON_ONCE(!trans->ops->write32)) + return; + trans->ops->write32(trans, ofs, val); } IWL_EXPORT_SYMBOL(iwl_trans_write32); u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs) { - return iwl_trans_pcie_read32(trans, ofs); + if (WARN_ON_ONCE(!trans->ops->read32)) + return 0; + return trans->ops->read32(trans, ofs); } IWL_EXPORT_SYMBOL(iwl_trans_read32); u32 iwl_trans_read_prph_no_grab(struct iwl_trans *trans, u32 ofs) { - return iwl_trans_pcie_read_prph(trans, ofs); + if (WARN_ON_ONCE(!trans->ops->read_prph)) + return 0; + return trans->ops->read_prph(trans, ofs); } void iwl_trans_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val) { - return iwl_pcie_write_prph_no_grab(trans, ofs, val); + if (WARN_ON_ONCE(!trans->ops->write_prph)) + return; + trans->ops->write_prph(trans, ofs, val); } -#define IWL_POLL_INTERVAL 10 /* microseconds */ - int iwl_trans_poll_bits_mask(struct iwl_trans *trans, u32 addr, u32 bits, u32 mask, int timeout) { - int t = 0; - - do { - if ((iwl_trans_read32(trans, addr) & mask) == (bits & mask)) - return 0; - udelay(IWL_POLL_INTERVAL); - t += IWL_POLL_INTERVAL; - } while (t < timeout); - - return -ETIMEDOUT; + if (WARN_ON_ONCE(!trans->ops->poll_bits_mask)) + return -EOPNOTSUPP; + return trans->ops->poll_bits_mask(trans, addr, bits, mask, timeout); } IWL_EXPORT_SYMBOL(iwl_trans_poll_bits_mask); @@ -559,14 +567,18 @@ IWL_EXPORT_SYMBOL(iwl_trans_force_nmi); int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr, void *buf, int dwords) { - return iwl_trans_pcie_read_mem(trans, addr, buf, dwords); + if (WARN_ON_ONCE(!trans->ops->read_mem)) + return -EOPNOTSUPP; + return trans->ops->read_mem(trans, addr, buf, dwords); } IWL_EXPORT_SYMBOL(iwl_trans_read_mem); int iwl_trans_read_mem_no_grab(struct iwl_trans *trans, u32 addr, void *buf, u32 dwords) { - return iwl_trans_pcie_read_mem_no_grab(trans, addr, buf, dwords); + if (WARN_ON_ONCE(!trans->ops->read_mem_no_grab)) + return -EOPNOTSUPP; + return trans->ops->read_mem_no_grab(trans, addr, buf, dwords); } int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr, @@ -599,7 +611,9 @@ IWL_EXPORT_SYMBOL(iwl_trans_set_pmi); int iwl_trans_sw_reset(struct iwl_trans *trans) { - return iwl_trans_pcie_sw_reset(trans, true); + if (WARN_ON_ONCE(!trans->ops->sw_reset)) + return -EOPNOTSUPP; + return trans->ops->sw_reset(trans, true); } struct iwl_trans_dump_data * @@ -607,15 +621,19 @@ iwl_trans_dump_data(struct iwl_trans *trans, u32 dump_mask, const struct iwl_dump_sanitize_ops *sanitize_ops, void *sanitize_ctx) { - return iwl_trans_pcie_dump_data(trans, dump_mask, - sanitize_ops, sanitize_ctx); + if (WARN_ON_ONCE(!trans->ops->dump_data)) + return NULL; + return trans->ops->dump_data(trans, dump_mask, + sanitize_ops, sanitize_ctx); } int iwl_trans_d3_suspend(struct iwl_trans *trans, bool reset) { might_sleep(); - return iwl_trans_pcie_d3_suspend(trans, reset); + if (WARN_ON_ONCE(!trans->ops->d3_suspend)) + return -EOPNOTSUPP; + return trans->ops->d3_suspend(trans, reset); } IWL_EXPORT_SYMBOL(iwl_trans_d3_suspend); @@ -623,48 +641,64 @@ int iwl_trans_d3_resume(struct iwl_trans *trans, bool reset) { might_sleep(); - return iwl_trans_pcie_d3_resume(trans, reset); + if (WARN_ON_ONCE(!trans->ops->d3_resume)) + return -EOPNOTSUPP; + return trans->ops->d3_resume(trans, reset); } IWL_EXPORT_SYMBOL(iwl_trans_d3_resume); void iwl_trans_sync_nmi(struct iwl_trans *trans) { - iwl_trans_pcie_sync_nmi(trans); + if (WARN_ON_ONCE(!trans->ops->sync_nmi)) + return; + trans->ops->sync_nmi(trans); } int iwl_trans_write_imr_mem(struct iwl_trans *trans, u32 dst_addr, u64 src_addr, u32 byte_cnt) { - return iwl_trans_pcie_copy_imr(trans, dst_addr, src_addr, byte_cnt); + if (WARN_ON_ONCE(!trans->ops->write_imr_mem)) + return -EOPNOTSUPP; + return trans->ops->write_imr_mem(trans, dst_addr, src_addr, byte_cnt); } void iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value) { - iwl_trans_pcie_set_bits_mask(trans, reg, mask, value); + if (WARN_ON_ONCE(!trans->ops->set_bits_mask)) + return; + trans->ops->set_bits_mask(trans, reg, mask, value); } IWL_EXPORT_SYMBOL(iwl_trans_set_bits_mask); int iwl_trans_read_config32(struct iwl_trans *trans, u32 ofs, u32 *val) { - return iwl_trans_pcie_read_config32(trans, ofs, val); + if (WARN_ON_ONCE(!trans->ops->read_config32)) + return -EOPNOTSUPP; + return trans->ops->read_config32(trans, ofs, val); } bool iwl_trans_grab_nic_access(struct iwl_trans *trans) { - return iwl_trans_pcie_grab_nic_access(trans); + if (WARN_ON_ONCE(!trans->ops->grab_nic_access)) + return false; + return trans->ops->grab_nic_access(trans); } IWL_EXPORT_SYMBOL(iwl_trans_grab_nic_access); void iwl_trans_resched_with_nic_access(struct iwl_trans *trans) { - iwl_trans_pcie_resched_with_nic_access(trans); + if (WARN_ON_ONCE(!trans->ops->resched_with_nic_access)) + return; + trans->ops->resched_with_nic_access(trans); } void iwl_trans_release_nic_access(struct iwl_trans *trans) { - iwl_trans_pcie_release_nic_access(trans); + if (WARN_ON_ONCE(!trans->ops->release_nic_access)) + return; + trans->ops->release_nic_access(trans); } IWL_EXPORT_SYMBOL(iwl_trans_release_nic_access); @@ -674,10 +708,8 @@ void iwl_trans_fw_alive(struct iwl_trans *trans) trans->state = IWL_TRANS_FW_ALIVE; - if (trans->mac_cfg->gen2) - iwl_trans_pcie_gen2_fw_alive(trans); - else - iwl_trans_pcie_fw_alive(trans); + if (!WARN_ON_ONCE(!trans->ops->fw_alive)) + trans->ops->fw_alive(trans); } IWL_EXPORT_SYMBOL(iwl_trans_fw_alive); @@ -695,12 +727,10 @@ int iwl_trans_start_fw(struct iwl_trans *trans, const struct iwl_fw *fw, clear_bit(STATUS_FW_ERROR, &trans->status); - if (trans->mac_cfg->gen2) - ret = iwl_trans_pcie_gen2_start_fw(trans, fw, img, - run_in_rfkill); - else - ret = iwl_trans_pcie_start_fw(trans, fw, img, - run_in_rfkill); + if (WARN_ON_ONCE(!trans->ops->start_fw)) + return -EOPNOTSUPP; + + ret = trans->ops->start_fw(trans, fw, img, run_in_rfkill); if (ret == 0) trans->state = IWL_TRANS_FW_STARTED; @@ -741,10 +771,8 @@ void iwl_trans_stop_device(struct iwl_trans *trans) iwl_op_mode_dump_error(trans->op_mode, &mode); } - if (trans->mac_cfg->gen2) - iwl_trans_pcie_gen2_stop_device(trans); - else - iwl_trans_pcie_stop_device(trans); + if (!WARN_ON_ONCE(!trans->ops->stop_device)) + trans->ops->stop_device(trans); trans->state = IWL_TRANS_NO_FW; } @@ -760,10 +788,10 @@ int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb, "bad state = %d\n", trans->state)) return -EIO; - if (trans->mac_cfg->gen2) - return iwl_txq_gen2_tx(trans, skb, dev_cmd, queue); + if (WARN_ON_ONCE(!trans->ops->tx)) + return -EOPNOTSUPP; - return iwl_trans_pcie_tx(trans, skb, dev_cmd, queue); + return trans->ops->tx(trans, skb, dev_cmd, queue); } IWL_EXPORT_SYMBOL(iwl_trans_tx); @@ -777,14 +805,18 @@ void iwl_trans_reclaim(struct iwl_trans *trans, int queue, int ssn, "bad state = %d\n", trans->state)) return; - iwl_pcie_reclaim(trans, queue, ssn, skbs, is_flush); + if (WARN_ON_ONCE(!trans->ops->reclaim)) + return; + trans->ops->reclaim(trans, queue, ssn, skbs, is_flush); } IWL_EXPORT_SYMBOL(iwl_trans_reclaim); void iwl_trans_txq_disable(struct iwl_trans *trans, int queue, bool configure_scd) { - iwl_trans_pcie_txq_disable(trans, queue, configure_scd); + if (WARN_ON_ONCE(!trans->ops->txq_disable)) + return; + trans->ops->txq_disable(trans, queue, configure_scd); } IWL_EXPORT_SYMBOL(iwl_trans_txq_disable); @@ -798,8 +830,10 @@ bool iwl_trans_txq_enable_cfg(struct iwl_trans *trans, int queue, u16 ssn, "bad state = %d\n", trans->state)) return false; - return iwl_trans_pcie_txq_enable(trans, queue, ssn, - cfg, queue_wdg_timeout); + if (WARN_ON_ONCE(!trans->ops->txq_enable)) + return false; + return trans->ops->txq_enable(trans, queue, ssn, + cfg, queue_wdg_timeout); } IWL_EXPORT_SYMBOL(iwl_trans_txq_enable_cfg); @@ -812,7 +846,9 @@ int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue) "bad state = %d\n", trans->state)) return -EIO; - return iwl_trans_pcie_wait_txq_empty(trans, queue); + if (WARN_ON_ONCE(!trans->ops->wait_txq_empty)) + return -EOPNOTSUPP; + return trans->ops->wait_txq_empty(trans, queue); } IWL_EXPORT_SYMBOL(iwl_trans_wait_txq_empty); @@ -822,7 +858,9 @@ int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans, u32 txqs) "bad state = %d\n", trans->state)) return -EIO; - return iwl_trans_pcie_wait_txqs_empty(trans, txqs); + if (WARN_ON_ONCE(!trans->ops->wait_txqs_empty)) + return -EOPNOTSUPP; + return trans->ops->wait_txqs_empty(trans, txqs); } IWL_EXPORT_SYMBOL(iwl_trans_wait_tx_queues_empty); @@ -833,14 +871,18 @@ void iwl_trans_freeze_txq_timer(struct iwl_trans *trans, "bad state = %d\n", trans->state)) return; - iwl_pcie_freeze_txq_timer(trans, txqs, freeze); + if (WARN_ON_ONCE(!trans->ops->freeze_txq_timer)) + return; + trans->ops->freeze_txq_timer(trans, txqs, freeze); } IWL_EXPORT_SYMBOL(iwl_trans_freeze_txq_timer); void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans, int txq_id, bool shared_mode) { - iwl_trans_pcie_txq_set_shared_mode(trans, txq_id, shared_mode); + if (WARN_ON_ONCE(!trans->ops->txq_set_shared_mode)) + return; + trans->ops->txq_set_shared_mode(trans, txq_id, shared_mode); } IWL_EXPORT_SYMBOL(iwl_trans_txq_set_shared_mode); @@ -850,7 +892,9 @@ void iwl_trans_set_q_ptrs(struct iwl_trans *trans, int queue, int ptr) "bad state = %d\n", trans->state)) return; - iwl_pcie_set_q_ptrs(trans, queue, ptr); + if (WARN_ON_ONCE(!trans->ops->set_q_ptrs)) + return; + trans->ops->set_q_ptrs(trans, queue, ptr); } IWL_EXPORT_SYMBOL(iwl_trans_set_q_ptrs); @@ -863,49 +907,62 @@ int iwl_trans_txq_alloc(struct iwl_trans *trans, u32 flags, u32 sta_mask, "bad state = %d\n", trans->state)) return -EIO; - return iwl_txq_dyn_alloc(trans, flags, sta_mask, tid, - size, wdg_timeout); + if (WARN_ON_ONCE(!trans->ops->txq_alloc)) + return -EOPNOTSUPP; + return trans->ops->txq_alloc(trans, flags, sta_mask, tid, + size, wdg_timeout); } IWL_EXPORT_SYMBOL(iwl_trans_txq_alloc); void iwl_trans_txq_free(struct iwl_trans *trans, int queue) { - iwl_txq_dyn_free(trans, queue); + if (WARN_ON_ONCE(!trans->ops->txq_free)) + return; + trans->ops->txq_free(trans, queue); } IWL_EXPORT_SYMBOL(iwl_trans_txq_free); int iwl_trans_get_rxq_dma_data(struct iwl_trans *trans, int queue, struct iwl_trans_rxq_dma_data *data) { - return iwl_trans_pcie_rxq_dma_data(trans, queue, data); + if (WARN_ON_ONCE(!trans->ops->rxq_dma_data)) + return -EOPNOTSUPP; + return trans->ops->rxq_dma_data(trans, queue, data); } int iwl_trans_load_pnvm(struct iwl_trans *trans, const struct iwl_pnvm_image *pnvm_data, const struct iwl_ucode_capabilities *capa) { - return iwl_trans_pcie_ctx_info_v2_load_pnvm(trans, pnvm_data, capa); + if (WARN_ON_ONCE(!trans->ops->load_pnvm)) + return -EOPNOTSUPP; + return trans->ops->load_pnvm(trans, pnvm_data, capa); } IWL_EXPORT_SYMBOL(iwl_trans_load_pnvm); void iwl_trans_set_pnvm(struct iwl_trans *trans, const struct iwl_ucode_capabilities *capa) { - iwl_trans_pcie_ctx_info_v2_set_pnvm(trans, capa); + if (WARN_ON_ONCE(!trans->ops->set_pnvm)) + return; + trans->ops->set_pnvm(trans, capa); } int iwl_trans_load_reduce_power(struct iwl_trans *trans, const struct iwl_pnvm_image *payloads, const struct iwl_ucode_capabilities *capa) { - return iwl_trans_pcie_ctx_info_v2_load_reduce_power(trans, payloads, - capa); + if (WARN_ON_ONCE(!trans->ops->load_reduce_power)) + return -EOPNOTSUPP; + return trans->ops->load_reduce_power(trans, payloads, capa); } void iwl_trans_set_reduce_power(struct iwl_trans *trans, const struct iwl_ucode_capabilities *capa) { - iwl_trans_pcie_ctx_info_v2_set_reduce_power(trans, capa); + if (WARN_ON_ONCE(!trans->ops->set_reduce_power)) + return; + trans->ops->set_reduce_power(trans, capa); } bool iwl_trans_is_pm_supported(struct iwl_trans *trans) @@ -913,26 +970,39 @@ bool iwl_trans_is_pm_supported(struct iwl_trans *trans) if (WARN_ON(trans->mac_cfg->gen2)) return false; - return iwl_pcie_gen1_is_pm_supported(trans); + if (WARN_ON_ONCE(!trans->ops->is_pm_supported)) + return false; + return trans->ops->is_pm_supported(trans); } IWL_EXPORT_SYMBOL(iwl_trans_is_pm_supported); bool iwl_trans_is_ltr_enabled(struct iwl_trans *trans) { - return iwl_pcie_is_ltr_enabled(trans); + if (WARN_ON_ONCE(!trans->ops->is_ltr_enabled)) + return false; + return trans->ops->is_ltr_enabled(trans); } IWL_EXPORT_SYMBOL(iwl_trans_is_ltr_enabled); int iwl_trans_activate_nic(struct iwl_trans *trans) { - return iwl_pcie_activate_nic(trans); + if (WARN_ON_ONCE(!trans->ops->activate_nic)) + return -EOPNOTSUPP; + return trans->ops->activate_nic(trans); } IWL_EXPORT_SYMBOL(iwl_trans_activate_nic); void iwl_trans_reset(struct iwl_trans *trans, enum iwl_reset_mode mode) { - iwl_trans_pcie_reset(trans, mode); + if (!WARN_ON_ONCE(!trans->ops->reset)) + trans->ops->reset(trans, mode); } IWL_EXPORT_SYMBOL(iwl_trans_reset); +void iwl_trans_fw_reset_handshake(struct iwl_trans *trans) +{ + if (!WARN_ON_ONCE(!trans->ops->fw_reset_handshake)) + trans->ops->fw_reset_handshake(trans); +} + diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index 719b6c9ba360..5db07f1eab56 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -734,12 +734,15 @@ struct iwl_trans_info { u8 num_rxqs; }; +struct iwl_trans_ops; + /** * struct iwl_trans - transport common data * * @csme_own: true if we couldn't get ownership on the device * @op_mode: pointer to the op_mode * @mac_cfg: the trans-specific configuration part + * @ops: bus-specific transport operations, see &struct iwl_trans_ops * @cfg: pointer to the configuration * @drv: pointer to iwl_drv * @conf: configuration set by the opmode before enter @@ -773,6 +776,7 @@ struct iwl_trans { bool csme_own; struct iwl_op_mode *op_mode; const struct iwl_mac_cfg *mac_cfg; + const struct iwl_trans_ops *ops; const struct iwl_rf_cfg *cfg; struct iwl_drv *drv; struct iwl_trans_config conf; @@ -1146,6 +1150,7 @@ static inline void iwl_trans_finish_sw_reset(struct iwl_trans *trans) *****************************************************/ struct iwl_trans *iwl_trans_alloc(unsigned int priv_size, struct device *dev, + const struct iwl_trans_ops *ops, const struct iwl_mac_cfg *mac_cfg); void iwl_trans_free(struct iwl_trans *trans); @@ -1217,7 +1222,150 @@ enum iwl_reset_mode { }; void iwl_trans_reset(struct iwl_trans *trans, enum iwl_reset_mode mode); -void iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans); +void iwl_trans_fw_reset_handshake(struct iwl_trans *trans); + +/** + * struct iwl_trans_ops - bus-specific transport operations + * + * Function-pointer table filled in by the bus implementation. Unless noted + * otherwise, each callback implements the identically named iwl_trans_*() + * API, see its documentation. + * + * @op_mode_enter: the op_mode took ownership of the transport + * @start_hw: start the hardware + * @op_mode_leave: the op_mode released the transport + * @send_cmd: send a host command to the firmware + * @alloc_tx_cmd: allocate a device TX command + * @free_tx_cmd: free a device TX command + * @write8: write a byte to a device register + * @write32: write a dword to a device register + * @read32: read a dword from a device register + * @read_prph: read a peripheral register + * @write_prph: write a peripheral register + * @read_mem: read device memory, taking NIC access + * @read_mem_no_grab: read device memory, NIC access already taken + * @set_bits_mask: read-modify-write a device register + * @poll_bits_mask: poll a device register until the masked bits match + * @read_config32: read a dword from the bus configuration space + * @grab_nic_access: keep the NIC awake for register access + * @release_nic_access: release the NIC access taken by @grab_nic_access + * @resched_with_nic_access: reschedule while holding NIC access + * @sw_reset: perform a software reset of the device + * @reset: reset the device, see &enum iwl_reset_mode + * @fw_reset_handshake: do a firmware reset handshake. + * @dump_data: collect a firmware error dump + * @d3_suspend: prepare the device for D3 (WoWLAN) + * @d3_resume: resume the device from D3 (WoWLAN) + * @sync_nmi: trigger an NMI and wait for it to be handled + * @write_imr_mem: write to the IMR memory region + * @fw_alive: Notify trans that the firmware sent the ALIVE notification + * @start_fw: download firmware code to the device and and start the firmware + * @stop_device: stop the device and the firmware + * @tx: transmit an MPDU + * @reclaim: free TX MPDUs up to the given sequence number + * @txq_disable: disable a TX queue (gen1) + * @txq_enable: enable a TX queue (gen1) + * @wait_txq_empty: wait for a single TX queue to become empty + * @wait_txqs_empty: wait for the given TX queues to become empty + * @freeze_txq_timer: freeze/unfreeze the watchdog of the given TX queues + * @txq_set_shared_mode: mark a TX queue as shared between TIDs + * @set_q_ptrs: set the write pointer of a TX queue + * @txq_alloc: allocate a TX queue (gen2) + * @txq_free: free a TX queue allocated by @txq_alloc + * @rxq_dma_data: get the DMA addresses of an RX queue + * @load_pnvm: load the PNVM image + * @set_pnvm: tell the firmware to use the loaded PNVM + * @load_reduce_power: load the reduced power table + * @set_reduce_power: tell the firmware to use the reduced power table + * @is_pm_supported: whether bus power management is supported + * @is_ltr_enabled: whether LTR is enabled on the bus + * @activate_nic: bring the NIC out of low power and make it accessible + */ +struct iwl_trans_ops { + void (*op_mode_enter)(struct iwl_trans *trans); + int (*start_hw)(struct iwl_trans *trans); + void (*op_mode_leave)(struct iwl_trans *trans); + + int (*send_cmd)(struct iwl_trans *trans, struct iwl_host_cmd *cmd); + struct iwl_device_tx_cmd *(*alloc_tx_cmd)(struct iwl_trans *trans); + void (*free_tx_cmd)(struct iwl_trans *trans, + struct iwl_device_tx_cmd *dev_cmd); + + void (*write8)(struct iwl_trans *trans, u32 ofs, u8 val); + void (*write32)(struct iwl_trans *trans, u32 ofs, u32 val); + u32 (*read32)(struct iwl_trans *trans, u32 ofs); + u32 (*read_prph)(struct iwl_trans *trans, u32 ofs); + void (*write_prph)(struct iwl_trans *trans, u32 ofs, u32 val); + int (*read_mem)(struct iwl_trans *trans, u32 addr, + void *buf, int dwords); + int (*read_mem_no_grab)(struct iwl_trans *trans, u32 addr, + void *buf, u32 dwords); + void (*set_bits_mask)(struct iwl_trans *trans, u32 reg, + u32 mask, u32 value); + int (*poll_bits_mask)(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout); + int (*read_config32)(struct iwl_trans *trans, u32 ofs, u32 *val); + bool (*grab_nic_access)(struct iwl_trans *trans); + void (*release_nic_access)(struct iwl_trans *trans); + void (*resched_with_nic_access)(struct iwl_trans *trans); + + int (*sw_reset)(struct iwl_trans *trans, bool retake_ownership); + void (*reset)(struct iwl_trans *trans, enum iwl_reset_mode mode); + void (*fw_reset_handshake)(struct iwl_trans *trans); + + struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans, + u32 dump_mask, + const struct iwl_dump_sanitize_ops *sanitize_ops, + void *sanitize_ctx); + int (*d3_suspend)(struct iwl_trans *trans, bool reset); + int (*d3_resume)(struct iwl_trans *trans, bool reset); + + void (*sync_nmi)(struct iwl_trans *trans); + int (*write_imr_mem)(struct iwl_trans *trans, u32 dst_addr, + u64 src_addr, u32 byte_cnt); + + void (*fw_alive)(struct iwl_trans *trans); + int (*start_fw)(struct iwl_trans *trans, const struct iwl_fw *fw, + const struct fw_img *img, bool run_in_rfkill); + void (*stop_device)(struct iwl_trans *trans); + + int (*tx)(struct iwl_trans *trans, struct sk_buff *skb, + struct iwl_device_tx_cmd *dev_cmd, int queue); + void (*reclaim)(struct iwl_trans *trans, int queue, int ssn, + struct sk_buff_head *skbs, bool is_flush); + void (*txq_disable)(struct iwl_trans *trans, int queue, + bool configure_scd); + bool (*txq_enable)(struct iwl_trans *trans, int queue, u16 ssn, + const struct iwl_trans_txq_scd_cfg *cfg, + unsigned int queue_wdg_timeout); + int (*wait_txq_empty)(struct iwl_trans *trans, int queue); + int (*wait_txqs_empty)(struct iwl_trans *trans, u32 txqs); + void (*freeze_txq_timer)(struct iwl_trans *trans, + unsigned long txqs, bool freeze); + void (*txq_set_shared_mode)(struct iwl_trans *trans, u32 txq_id, + bool shared_mode); + void (*set_q_ptrs)(struct iwl_trans *trans, int queue, int ptr); + int (*txq_alloc)(struct iwl_trans *trans, u32 flags, u32 sta_mask, + u8 tid, int size, unsigned int wdg_timeout); + void (*txq_free)(struct iwl_trans *trans, int queue); + int (*rxq_dma_data)(struct iwl_trans *trans, int queue, + struct iwl_trans_rxq_dma_data *data); + + int (*load_pnvm)(struct iwl_trans *trans, + const struct iwl_pnvm_image *pnvm_data, + const struct iwl_ucode_capabilities *capa); + void (*set_pnvm)(struct iwl_trans *trans, + const struct iwl_ucode_capabilities *capa); + int (*load_reduce_power)(struct iwl_trans *trans, + const struct iwl_pnvm_image *payloads, + const struct iwl_ucode_capabilities *capa); + void (*set_reduce_power)(struct iwl_trans *trans, + const struct iwl_ucode_capabilities *capa); + + bool (*is_pm_supported)(struct iwl_trans *trans); + bool (*is_ltr_enabled)(struct iwl_trans *trans); + int (*activate_nic)(struct iwl_trans *trans); +}; /* Internal helper */ static inline void iwl_trans_set_info(struct iwl_trans *trans, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index fab73693e683..01bfc1492c84 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -31,6 +31,9 @@ u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs); u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg); void iwl_pcie_write_prph_no_grab(struct iwl_trans *trans, u32 addr, u32 val); +/* bus-specific transport operations table */ +extern const struct iwl_trans_ops iwl_trans_pcie_ops; + /* * RX related structures and functions */ @@ -1148,7 +1151,7 @@ int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr, int iwl_trans_pcie_read_mem_no_grab(struct iwl_trans *trans, u32 addr, void *buf, u32 dwords); int iwl_trans_pcie_sw_reset(struct iwl_trans *trans, bool retake_ownership); -void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode); +void iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans); struct iwl_trans_dump_data * iwl_trans_pcie_dump_data(struct iwl_trans *trans, u32 dump_mask, const struct iwl_dump_sanitize_ops *sanitize_ops, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index 59e9ef0d6b51..c905b6d5db3d 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -1288,6 +1288,10 @@ int iwl_trans_pcie_start_fw(struct iwl_trans *trans, bool hw_rfkill; int ret; + if (trans->mac_cfg->gen2) + return iwl_trans_pcie_gen2_start_fw(trans, fw, img, + run_in_rfkill); + /* This may fail if AMT took ownership of the device */ if (iwl_pcie_prepare_card_hw(trans)) { IWL_WARN(trans, "Exit HW not ready\n"); @@ -1370,6 +1374,11 @@ out: void iwl_trans_pcie_fw_alive(struct iwl_trans *trans) { + if (trans->mac_cfg->gen2) { + iwl_trans_pcie_gen2_fw_alive(trans); + return; + } + iwl_pcie_reset_ict(trans); iwl_pcie_tx_start(trans); } @@ -1408,6 +1417,11 @@ void iwl_trans_pcie_stop_device(struct iwl_trans *trans) struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); bool was_in_rfkill; + if (trans->mac_cfg->gen2) { + iwl_trans_pcie_gen2_stop_device(trans); + return; + } + iwl_op_mode_time_point(trans->op_mode, IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE, NULL); @@ -1846,6 +1860,11 @@ void iwl_trans_pcie_op_mode_leave(struct iwl_trans *trans) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + if (trans->mac_cfg->gen2) { + iwl_trans_pcie_gen2_op_mode_leave(trans); + return; + } + mutex_lock(&trans_pcie->mutex); /* disable interrupts - don't enable HW RF kill interrupt */ @@ -2274,7 +2293,7 @@ out: module_put(THIS_MODULE); } -void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode) +static void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); struct iwl_trans_pcie_removal *removal; @@ -2684,6 +2703,23 @@ void iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans, u32 reg, spin_unlock_bh(&trans_pcie->reg_lock); } +#define IWL_POLL_INTERVAL 10 /* microseconds */ + +static int iwl_trans_pcie_poll_bits_mask(struct iwl_trans *trans, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int t = 0; + + do { + if ((iwl_trans_pcie_read32(trans, addr) & mask) == (bits & mask)) + return 0; + udelay(IWL_POLL_INTERVAL); + t += IWL_POLL_INTERVAL; + } while (t < timeout); + + return -ETIMEDOUT; +} + static const char *get_csr_string(int cmd) { #define IWL_CMD(x) case x: return #x @@ -3659,6 +3695,67 @@ static int iwl_trans_pcie_alloc_txcmd_pool(struct iwl_trans *trans) return 0; } +const struct iwl_trans_ops iwl_trans_pcie_ops = { + .op_mode_enter = iwl_trans_pcie_op_mode_enter, + .start_hw = iwl_trans_pcie_start_hw, + .op_mode_leave = iwl_trans_pcie_op_mode_leave, + + .send_cmd = iwl_trans_pcie_send_hcmd, + .alloc_tx_cmd = iwl_pcie_alloc_tx_cmd, + .free_tx_cmd = iwl_pcie_free_tx_cmd, + + .write8 = iwl_trans_pcie_write8, + .write32 = iwl_trans_pcie_write32, + .read32 = iwl_trans_pcie_read32, + .read_prph = iwl_trans_pcie_read_prph, + .write_prph = iwl_pcie_write_prph_no_grab, + .read_mem = iwl_trans_pcie_read_mem, + .read_mem_no_grab = iwl_trans_pcie_read_mem_no_grab, + .set_bits_mask = iwl_trans_pcie_set_bits_mask, + .poll_bits_mask = iwl_trans_pcie_poll_bits_mask, + .read_config32 = iwl_trans_pcie_read_config32, + .grab_nic_access = iwl_trans_pcie_grab_nic_access, + .release_nic_access = iwl_trans_pcie_release_nic_access, + .resched_with_nic_access = iwl_trans_pcie_resched_with_nic_access, + + .sw_reset = iwl_trans_pcie_sw_reset, + .reset = iwl_trans_pcie_reset, + .fw_reset_handshake = iwl_trans_pcie_fw_reset_handshake, + + .dump_data = iwl_trans_pcie_dump_data, + .d3_suspend = iwl_trans_pcie_d3_suspend, + .d3_resume = iwl_trans_pcie_d3_resume, + + .sync_nmi = iwl_trans_pcie_sync_nmi, + .write_imr_mem = iwl_trans_pcie_copy_imr, + + .fw_alive = iwl_trans_pcie_fw_alive, + .start_fw = iwl_trans_pcie_start_fw, + .stop_device = iwl_trans_pcie_stop_device, + + .tx = iwl_trans_pcie_tx, + .reclaim = iwl_pcie_reclaim, + .txq_disable = iwl_trans_pcie_txq_disable, + .txq_enable = iwl_trans_pcie_txq_enable, + .wait_txq_empty = iwl_trans_pcie_wait_txq_empty, + .wait_txqs_empty = iwl_trans_pcie_wait_txqs_empty, + .freeze_txq_timer = iwl_pcie_freeze_txq_timer, + .txq_set_shared_mode = iwl_trans_pcie_txq_set_shared_mode, + .set_q_ptrs = iwl_pcie_set_q_ptrs, + .txq_alloc = iwl_txq_dyn_alloc, + .txq_free = iwl_txq_dyn_free, + .rxq_dma_data = iwl_trans_pcie_rxq_dma_data, + + .load_pnvm = iwl_trans_pcie_ctx_info_v2_load_pnvm, + .set_pnvm = iwl_trans_pcie_ctx_info_v2_set_pnvm, + .load_reduce_power = iwl_trans_pcie_ctx_info_v2_load_reduce_power, + .set_reduce_power = iwl_trans_pcie_ctx_info_v2_set_reduce_power, + + .is_pm_supported = iwl_pcie_gen1_is_pm_supported, + .is_ltr_enabled = iwl_pcie_is_ltr_enabled, + .activate_nic = iwl_pcie_activate_nic, +}; + static struct iwl_trans * iwl_trans_pcie_alloc(struct pci_dev *pdev, const struct iwl_mac_cfg *mac_cfg, @@ -3670,7 +3767,7 @@ iwl_trans_pcie_alloc(struct pci_dev *pdev, int ret, addr_size; trans = iwl_trans_alloc(sizeof(struct iwl_trans_pcie), &pdev->dev, - mac_cfg); + &iwl_trans_pcie_ops, mac_cfg); if (!trans) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index d612678ae122..0c29fb6b9ca7 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -2147,6 +2147,9 @@ int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb, u16 wifi_seq; bool amsdu; + if (trans->mac_cfg->gen2) + return iwl_txq_gen2_tx(trans, skb, dev_cmd, txq_id); + txq = trans_pcie->txqs.txq[txq_id]; if (WARN_ONCE(!test_bit(txq_id, trans_pcie->txqs.queue_used), From 6a972f26b7ddb8ddeac3b2f20db1c30d1f8c027b Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Wed, 30 Sep 2026 12:19:52 +0300 Subject: [PATCH 1599/2126] wifi: iwlwifi: mld: remove unused fields from the firmware API ENABLE_STORE_BEACON is not defined in the firmware API and is never set by the driver. STA_CONFIG_CMD's trig_rnd_alloc was never used by the firmware either. Remove both. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20260930121740.157e71ac8641.Iac2bd1f57b2c4bbdfe33efab31111a7de02bdf16@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/api/d3.h | 3 +-- drivers/net/wireless/intel/iwlwifi/mld/sta.c | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h index d3bed0216df4..9f7407c4f980 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2012-2014, 2018-2025 Intel Corporation + * Copyright (C) 2012-2014, 2018-2026 Intel Corporation * Copyright (C) 2013-2014 Intel Mobile Communications GmbH * Copyright (C) 2015-2017 Intel Deutschland GmbH */ @@ -366,7 +366,6 @@ enum iwl_wowlan_flags { ENABLE_L3_FILTERING = BIT(1), ENABLE_NBNS_FILTERING = BIT(2), ENABLE_DHCP_FILTERING = BIT(3), - ENABLE_STORE_BEACON = BIT(4), HAS_BEACON_PROTECTION = BIT(5), }; diff --git a/drivers/net/wireless/intel/iwlwifi/mld/sta.c b/drivers/net/wireless/intel/iwlwifi/mld/sta.c index 7957ac11b0cd..97f013330f06 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/sta.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/sta.c @@ -465,8 +465,8 @@ int iwl_mld_add_modify_sta_cmd(struct iwl_mld *mld, struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta); struct iwl_sta_cfg_cmd cmd = {}; int fw_id = iwl_mld_fw_sta_id_from_link_sta(mld, link_sta); - bool is_6ghz, uora_exists; u32 link_mask; + bool is_6ghz; lockdep_assert_wiphy(mld->wiphy); @@ -479,7 +479,6 @@ int iwl_mld_add_modify_sta_cmd(struct iwl_mld *mld, return -EINVAL; is_6ghz = false; - uora_exists = false; link_mask = iwl_mld_get_nan_link_mask(mld); } else { @@ -495,7 +494,6 @@ int iwl_mld_add_modify_sta_cmd(struct iwl_mld *mld, link_mask = BIT(mld_link->fw_id); is_6ghz = link->chanreq.oper.chan->band == NL80211_BAND_6GHZ; - uora_exists = link->uora_exists; } cmd.sta_id = cpu_to_le32(fw_id); @@ -554,9 +552,6 @@ int iwl_mld_add_modify_sta_cmd(struct iwl_mld *mld, } if (link_sta->he_cap.has_he) { - cmd.trig_rnd_alloc = - cpu_to_le32(uora_exists ? 1 : 0); - /* PPE Thresholds */ iwl_mld_fill_pkt_ext(mld, link_sta, &cmd.pkt_ext); From 0dc7a804a45828503e3707d7f2c3a298ef7a4647 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Thu, 1 Oct 2026 16:20:14 +0300 Subject: [PATCH 1600/2126] wifi: iwlwifi: mld: add STA_CONFIG_CMD version 4 Version 4 replaces the unused trig_rnd_alloc field with cip_defer and epp_robust: - cip_defer tells the firmware to delay the usage of the unicast control frame protection key until after association. - epp_robust tells the firmware that EPP robust individually addressed management frame support was negotiated, so that the protected action categories are used for specific unicast action frames. Add the matching EPP_ROBUST_CONNECTION flag to the WoWLAN config command flags for the D3 path. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20261001161715.b62474b1ccef.I51756391283ec42a40dd38a3586ad89759fb82d1@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/api/d3.h | 1 + .../net/wireless/intel/iwlwifi/fw/api/mac-cfg.h | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h index 9f7407c4f980..a0379aca99d7 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h @@ -366,6 +366,7 @@ enum iwl_wowlan_flags { ENABLE_L3_FILTERING = BIT(1), ENABLE_NBNS_FILTERING = BIT(2), ENABLE_DHCP_FILTERING = BIT(3), + EPP_ROBUST_CONNECTION = BIT(4), HAS_BEACON_PROTECTION = BIT(5), }; diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h index 9579e691cc87..6e536f48acdb 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/mac-cfg.h @@ -940,8 +940,13 @@ struct iwl_sta_cfg_cmd_v2 { * @mimo_protection: indicates whether the sta uses mimo protection or not * @ack_enabled: indicates that the AP supports receiving ACK- * enabled AGG, i.e. both BACK and non-BACK frames in a single AGG - * @trig_rnd_alloc: indicates that trigger based random allocation - * is enabled according to UORA element existence + * @cip_defer: delay the usage of the unicast control frame protection until + * after association. + * Only supported from command version 4, must be left cleared otherwise. + * @epp_robust: indicates that EPP robust individually addressed management + * frame support was negotiated during association. + * Only supported from command version 4, must be left cleared otherwise. + * @reserved1: Reserved for alignment * @tx_ampdu_spacing: minimum A-MPDU spacing: * 4 - 2us density, 5 - 4us density, 6 - 8us density, 7 - 16us density * @tx_ampdu_max_size: maximum A-MPDU length: 0 - 8K, 1 - 16K, 2 - 32K, @@ -979,7 +984,9 @@ struct iwl_sta_cfg_cmd { __le32 mimo; __le32 mimo_protection; __le32 ack_enabled; - __le32 trig_rnd_alloc; + u8 cip_defer; + u8 epp_robust; + __le16 reserved1; __le32 tx_ampdu_spacing; __le32 tx_ampdu_max_size; __le32 sp_length; @@ -996,7 +1003,7 @@ struct iwl_sta_cfg_cmd { u8 nmi_sta_id; u8 ndi_local_addr[ETH_ALEN]; u8 reserved[2]; -} __packed; /* STA_CMD_API_S_VER_3 */ +} __packed; /* STA_CMD_API_S_VER_3, STA_CMD_API_S_VER_4 */ /** * struct iwl_aux_sta_cmd - command for AUX STA configuration From 0b5f2164ceaad36b68c868fc9d079b4b0475b006 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:15 +0300 Subject: [PATCH 1601/2126] wifi: iwlwifi: mld: add UHR sniffer support Add UHR sniffer support as supported by the hardware. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.a1e1090ec775.I47fb568ddcd9d6aca634400b2d4850c1fef035ca@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 593 +++++++++++++++++++- 1 file changed, 573 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 8fa438fd7815..1362e3ad97b2 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -944,8 +944,8 @@ static void iwl_mld_decode_eht_usig(struct iwl_mld_rx_phy_data *phy_data, } static void -iwl_mld_eht_set_ru_alloc(struct ieee80211_rx_status *rx_status, - u32 ru_with_p80) +iwl_mld_eht_uhr_set_ru_alloc(struct ieee80211_rx_status *rx_status, + u32 ru_with_p80, bool uhr) { enum nl80211_eht_ru_alloc nl_ru; u32 ru = ru_with_p80 >> 1; @@ -1011,7 +1011,15 @@ iwl_mld_eht_set_ru_alloc(struct ieee80211_rx_status *rx_status, } rx_status->bw = RATE_INFO_BW_EHT_RU; - rx_status->eht.ru = nl_ru; + + /* + * This should get optimised away, but since it's bitfields, + * we can't ensure uhr.ru and eht.ru overlap in the union. + */ + if (uhr) + rx_status->uhr.ru = nl_ru; + else + rx_status->eht.ru = nl_ru; } static void iwl_mld_decode_eht_tb(struct iwl_mld_rx_phy_data *phy_data, @@ -1051,9 +1059,10 @@ static void iwl_mld_decode_eht_tb(struct iwl_mld_rx_phy_data *phy_data, OFDM_UCODE_TRIG_BASE_RX_RU_P80, IEEE80211_RADIOTAP_EHT_DATA1_PRIMARY_80); - iwl_mld_eht_set_ru_alloc(rx_status, - le32_get_bits(phy_data->ntfy->sigs.eht_tb.tb_rx1, - OFDM_UCODE_TRIG_BASE_RX_RU)); + iwl_mld_eht_uhr_set_ru_alloc(rx_status, + le32_get_bits(phy_data->ntfy->sigs.eht_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_RU), + false); } static void iwl_mld_eht_decode_user_ru(struct iwl_mld_rx_phy_data *phy_data, @@ -1209,9 +1218,10 @@ static void iwl_mld_decode_eht_non_tb(struct iwl_mld_rx_phy_data *phy_data, iwl_mld_eht_decode_user_ru(phy_data, eht); - iwl_mld_eht_set_ru_alloc(rx_status, - le32_get_bits(phy_data->ntfy->sigs.eht.b2, - OFDM_RX_FRAME_EHT_STA_RU)); + iwl_mld_eht_uhr_set_ru_alloc(rx_status, + le32_get_bits(phy_data->ntfy->sigs.eht.b2, + OFDM_RX_FRAME_EHT_STA_RU), + false); if (phy_data->with_data) eht->user_info[0] |= @@ -1317,7 +1327,7 @@ static void iwl_mld_rx_eht(struct iwl_mld *mld, struct sk_buff *skb, eht->user_info[0] |= le32_encode_bits(u32_get_bits(rate_n_flags, - RATE_VHT_MCS_RATE_CODE_MSK), + RATE_MCS_CODE_MSK), IEEE80211_RADIOTAP_EHT_USER_INFO_MCS) | le32_encode_bits(u32_get_bits(rate_n_flags, RATE_MCS_NSS_MSK), @@ -1331,6 +1341,526 @@ static void iwl_mld_rx_eht(struct iwl_mld *mld, struct sk_buff *skb, iwl_mld_decode_eht_phy_data(phy_data, rx_status, eht); } +static void iwl_mld_decode_uhr_usig_tb(struct iwl_mld_rx_phy_data *phy_data, + struct ieee80211_radiotap_eht_usig *usig) +{ + __le32 usig_a1 = phy_data->ntfy->sigs.uhr_tb.usig_a1; + __le32 usig_a2 = phy_data->ntfy->sigs.uhr_tb.usig_a2_uhr; + + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a1, + OFDM_RX_FRAME_EHT_USIG1_DISREGARD | + OFDM_RX_FRAME_EHT_USIG1_VALIDATE, + IEEE80211_RADIOTAP_UHR_USIG1_TB_B20_B25_DISREGARD); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_PPDU_TYPE, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B0_B1_PPDU_TYPE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B2_COBF_COSR, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B2_VALIDATE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_TRIG_SPATIAL_REUSE_1, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B3_B6_SPATIAL_REUSE_1); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_TRIG_SPATIAL_REUSE_2, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B7_B10_SPATIAL_REUSE_2); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_TRIG_USIG2_DISREGARD, + IEEE80211_RADIOTAP_UHR_USIG2_TB_B11_B15_DISREGARD); + + if (le32_get_bits(usig_a1, OFDM_RX_FRAME_EHT_USIG1_VALIDATE) && + le32_get_bits(usig_a2, OFDM_RX_FRAME_UHR_USIG2_VALIDATE_B8)) + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK); + + if (!le32_get_bits(usig_a2, OFDM_RX_FRAME_UHR_USIG_CRC_OK)) + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC); +} + +static void iwl_mld_decode_uhr_usig_elr(struct iwl_mld_rx_phy_data *phy_data, + struct ieee80211_radiotap_eht_usig *usig) +{ + __le32 usig_a1 = phy_data->ntfy->sigs.uhr_elr.usig_a1; + __le32 usig_a2 = phy_data->ntfy->sigs.uhr_elr.usig_a2_uhr_elr; + + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a1, + OFDM_RX_FRAME_EHT_USIG1_DISREGARD, + IEEE80211_RADIOTAP_UHR_USIG1_ELR_B20_B24_DISREGARD); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a1, + OFDM_RX_FRAME_EHT_USIG1_VALIDATE, + IEEE80211_RADIOTAP_UHR_USIG1_ELR_B25_VALIDATE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_VECTOR_UHR_ELR_PPDU_TYPE, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B0_B1_PPDU_TYPE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_VECTOR_UHR_ELR_USIG_STA_ID, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B2_B12_STA_ID); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_VECTOR_UHR_ELR_VALIDATE, + IEEE80211_RADIOTAP_UHR_USIG2_ELR_B13_B15_VALIDATE); + + if (le32_get_bits(usig_a1, OFDM_RX_FRAME_EHT_USIG1_VALIDATE) && + le32_get_bits(usig_a2, OFDM_RX_VECTOR_UHR_ELR_VALIDATE) == 0xe) + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK); + + if (!le32_get_bits(usig_a2, OFDM_RX_VECTOR_UHR_ELR_CRC_OK)) + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC); +} + +static void iwl_mld_decode_uhr_usig_non_tb(struct iwl_mld_rx_phy_data *phy_data, + struct ieee80211_radiotap_eht_usig *usig) +{ + __le32 usig_a1 = phy_data->ntfy->sigs.uhr.usig_a1; + __le32 usig_a2 = phy_data->ntfy->sigs.uhr.usig_a2_uhr; + + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a1, + OFDM_RX_FRAME_EHT_USIG1_DISREGARD, + IEEE80211_RADIOTAP_UHR_USIG1_MU_B20_B24_DISREGARD); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a1, + OFDM_RX_FRAME_EHT_USIG1_VALIDATE, + IEEE80211_RADIOTAP_UHR_USIG1_MU_B25_VALIDATE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_PPDU_TYPE, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B0_B1_PPDU_TYPE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_COBF_CSR_DISABLE, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B2_COBF_COSR); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_PUNC_CHANNEL, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B3_B7_PUNCTURED_INFO); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_USIG2_VALIDATE_B8, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B8_VALIDATE); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_SIG_MCS, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B9_B10_SIG_MCS); + IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, + OFDM_RX_FRAME_UHR_SIG_SYM_NUM, + IEEE80211_RADIOTAP_UHR_USIG2_MU_B11_B15_UHR_SIG_SYMBOLS); + + if (le32_get_bits(usig_a1, OFDM_RX_FRAME_EHT_USIG1_VALIDATE) && + le32_get_bits(usig_a2, OFDM_RX_FRAME_UHR_USIG2_VALIDATE_B8)) + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK); + + if (!le32_get_bits(usig_a2, OFDM_RX_FRAME_UHR_USIG_CRC_OK)) + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC); +} + +static void iwl_mld_decode_uhr_usig(struct iwl_mld_rx_phy_data *phy_data, + struct sk_buff *skb) +{ + u32 he_type = phy_data->rate_n_flags & RATE_MCS_HE_TYPE_MSK; + struct ieee80211_radiotap_eht_usig *usig; + __le32 usig_a1 = phy_data->ntfy->sigs.uhr.usig_a1; + u32 bw; + + usig = iwl_mld_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT_USIG, + sizeof(*usig)); + + BUILD_BUG_ON(offsetof(typeof(phy_data->ntfy->sigs.uhr), usig_a1) != + offsetof(typeof(phy_data->ntfy->sigs.uhr_elr), usig_a1)); + BUILD_BUG_ON(offsetof(typeof(phy_data->ntfy->sigs.uhr), usig_a1) != + offsetof(typeof(phy_data->ntfy->sigs.uhr_tb), usig_a1)); + + usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL_KNOWN | + IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR_KNOWN | + IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_CHECKED | + IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_KNOWN | + IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP_KNOWN | + IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER_KNOWN); + +#define CHECK_BW(bw) \ + BUILD_BUG_ON(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_ ## bw ## MHZ != \ + RATE_MCS_CHAN_WIDTH_ ## bw ## _VAL) + CHECK_BW(20); + CHECK_BW(40); + CHECK_BW(80); + CHECK_BW(160); +#undef CHECK_BW + BUILD_BUG_ON(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_320MHZ_1 != + RATE_MCS_CHAN_WIDTH_320_VAL); + bw = u32_get_bits(phy_data->rate_n_flags, RATE_MCS_CHAN_WIDTH_MSK); + /* specific handling for 320MHz-1/320MHz-2 */ + if (bw == RATE_MCS_CHAN_WIDTH_320_VAL) + bw += le32_get_bits(usig_a1, OFDM_RX_FRAME_EHT_BW320_SLOT); + usig->common |= le32_encode_bits(bw, + IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW); + + usig->common |= LE32_DEC_ENC(usig_a1, OFDM_RX_FRAME_ENHANCED_WIFI_UL_FLAG, + IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL); + usig->common |= LE32_DEC_ENC(usig_a1, OFDM_RX_FRAME_ENHANCED_WIFI_BSS_COLOR, + IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR); + usig->common |= LE32_DEC_ENC(usig_a1, + OFDM_RX_FRAME_ENHANCED_WIFI_TXOP_DURATION, + IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP); + usig->common |= LE32_DEC_ENC(usig_a1, + OFDM_RX_FRAME_ENHANCED_WIFI_VER_ID, + IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER); + + switch (he_type) { + case RATE_MCS_HE_TYPE_TRIG: + iwl_mld_decode_uhr_usig_tb(phy_data, usig); + break; + case RATE_MCS_HE_TYPE_UHR_ELR: + iwl_mld_decode_uhr_usig_elr(phy_data, usig); + break; + default: + iwl_mld_decode_uhr_usig_non_tb(phy_data, usig); + break; + } +} + +static void iwl_mld_decode_uhr_tb(struct iwl_mld_rx_phy_data *phy_data, + struct ieee80211_rx_status *rx_status, + struct ieee80211_radiotap_uhr *uhr) +{ + if (!(phy_data->ntfy->flags & IWL_SNIF_FLAG_VALID_TB_RX)) + return; + + uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_DRU_RRU_ALLOC_TB_FMT | + IEEE80211_RADIOTAP_UHR_KNOWN_LDPC_EXTRA_SYMBOL_SEGMENT | + IEEE80211_RADIOTAP_UHR_KNOWN_PRE_FEC_PADDING_FACTOR | + IEEE80211_RADIOTAP_UHR_KNOWN_PE_DISAMBIGUITY | + IEEE80211_RADIOTAP_UHR_KNOWN_NUMBER_OF_UHR_LTF_SYMBOLS | + IEEE80211_RADIOTAP_UHR_KNOWN_PRI80_CHAN_POS); + + uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx0, + OFDM_UCODE_TRIG_BASE_PS160, + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_PS_160); + uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_RU, + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B0 | + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B7_B1); + uhr->data[8] |= le32_encode_bits(!le32_get_bits(phy_data->ntfy->sigs.uhr_tb.tb_rx0, + OFDM_UCODE_RX_IS_DRU), + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_INDICATION); + + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_CODING_EXTRA_SYM, + IEEE80211_RADIOTAP_UHR_DATA0_LDPC_EXTRA_SYMBOL_SEGMENT); + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_PRE_FEC_PAD_FACTOR, + IEEE80211_RADIOTAP_UHR_DATA0_PRE_FEC_PADDING_FACTOR); + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_PE_DISAMBIG, + IEEE80211_RADIOTAP_UHR_DATA0_PE_DISAMBIGUITY); + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_NUM_OF_LTF_SYM, + IEEE80211_RADIOTAP_UHR_DATA0_NUMBER_OF_LTF_SYMBOLS); + uhr->data[1] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr_tb.tb_rx0, + OFDM_UCODE_TRIG_BASE_RX_RU_P80, + IEEE80211_RADIOTAP_UHR_DATA1_PRI80_CHAN_POS); + + iwl_mld_eht_uhr_set_ru_alloc(rx_status, + le32_get_bits(phy_data->ntfy->sigs.uhr_tb.tb_rx1, + OFDM_UCODE_TRIG_BASE_RX_RU), + true); +} + +static void iwl_mld_uhr_decode_user_ru(struct iwl_mld_rx_phy_data *phy_data, + struct ieee80211_radiotap_uhr *uhr) +{ + u32 phy_bw = phy_data->rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK; + + if (!(phy_data->ntfy->flags & IWL_SNIF_FLAG_VALID_RU)) + return; + +#define __IWL_MLD_ENC_UHR_RU(rt_data, rt_ru, fw_data, fw_ru) \ + uhr->data[(rt_data)] |= \ + (cpu_to_le32(IEEE80211_RADIOTAP_UHR_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru ## _KNOWN) | \ + LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.cmn[fw_data], \ + OFDM_RX_FRAME_EHT_RU_ALLOC_ ## fw_data ## _ ## fw_ru, \ + IEEE80211_RADIOTAP_UHR_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru)) + +#define _IWL_MLD_ENC_UHR_RU(rt_data, rt_ru, fw_data, fw_ru) \ + __IWL_MLD_ENC_UHR_RU(rt_data, rt_ru, fw_data, fw_ru) + +#define IEEE80211_RADIOTAP_RU_DATA_1_1_1 1 +#define IEEE80211_RADIOTAP_RU_DATA_2_1_1 2 +#define IEEE80211_RADIOTAP_RU_DATA_1_1_2 2 +#define IEEE80211_RADIOTAP_RU_DATA_2_1_2 2 +#define IEEE80211_RADIOTAP_RU_DATA_1_2_1 3 +#define IEEE80211_RADIOTAP_RU_DATA_2_2_1 3 +#define IEEE80211_RADIOTAP_RU_DATA_1_2_2 3 +#define IEEE80211_RADIOTAP_RU_DATA_2_2_2 4 +#define IEEE80211_RADIOTAP_RU_DATA_1_2_3 4 +#define IEEE80211_RADIOTAP_RU_DATA_2_2_3 4 +#define IEEE80211_RADIOTAP_RU_DATA_1_2_4 5 +#define IEEE80211_RADIOTAP_RU_DATA_2_2_4 5 +#define IEEE80211_RADIOTAP_RU_DATA_1_2_5 5 +#define IEEE80211_RADIOTAP_RU_DATA_2_2_5 6 +#define IEEE80211_RADIOTAP_RU_DATA_1_2_6 6 +#define IEEE80211_RADIOTAP_RU_DATA_2_2_6 6 + +#define IWL_RX_RU_DATA_A1 0 +#define IWL_RX_RU_DATA_A2 0 +#define IWL_RX_RU_DATA_A3 0 +#define IWL_RX_RU_DATA_A4 4 +#define IWL_RX_RU_DATA_B1 1 +#define IWL_RX_RU_DATA_B2 1 +#define IWL_RX_RU_DATA_B3 1 +#define IWL_RX_RU_DATA_B4 4 +#define IWL_RX_RU_DATA_C1 2 +#define IWL_RX_RU_DATA_C2 2 +#define IWL_RX_RU_DATA_C3 2 +#define IWL_RX_RU_DATA_C4 5 +#define IWL_RX_RU_DATA_D1 3 +#define IWL_RX_RU_DATA_D2 3 +#define IWL_RX_RU_DATA_D3 3 +#define IWL_RX_RU_DATA_D4 5 + +#define IWL_MLD_ENC_UHR_RU(rt_ru, fw_ru) \ + _IWL_MLD_ENC_UHR_RU(IEEE80211_RADIOTAP_RU_DATA_ ## rt_ru, \ + rt_ru, \ + IWL_RX_RU_DATA_ ## fw_ru, \ + fw_ru) + + /* + * Hardware labels the content channels/RU allocation values + * as follows: + * + * Content Channel 1 Content Channel 2 + * 20 MHz: A1 + * 40 MHz: A1 B1 + * 80 MHz: A1 C1 B1 D1 + * 160 MHz: A1 C1 A2 C2 B1 D1 B2 D2 + * 320 MHz: A1 C1 A2 C2 A3 C3 A4 C4 B1 D1 B2 D2 B3 D3 B4 D4 + */ + + switch (phy_bw) { + case RATE_MCS_CHAN_WIDTH_320: + /* content channel 1 */ + IWL_MLD_ENC_UHR_RU(1_2_3, A3); + IWL_MLD_ENC_UHR_RU(1_2_4, C3); + IWL_MLD_ENC_UHR_RU(1_2_5, A4); + IWL_MLD_ENC_UHR_RU(1_2_6, C4); + /* content channel 2 */ + IWL_MLD_ENC_UHR_RU(2_2_3, B3); + IWL_MLD_ENC_UHR_RU(2_2_4, D3); + IWL_MLD_ENC_UHR_RU(2_2_5, B4); + IWL_MLD_ENC_UHR_RU(2_2_6, D4); + fallthrough; + case RATE_MCS_CHAN_WIDTH_160: + /* content channel 1 */ + IWL_MLD_ENC_UHR_RU(1_2_1, A2); + IWL_MLD_ENC_UHR_RU(1_2_2, C2); + /* content channel 2 */ + IWL_MLD_ENC_UHR_RU(2_2_1, B2); + IWL_MLD_ENC_UHR_RU(2_2_2, D2); + fallthrough; + case RATE_MCS_CHAN_WIDTH_80: + /* content channel 1 */ + IWL_MLD_ENC_UHR_RU(1_1_2, C1); + /* content channel 2 */ + IWL_MLD_ENC_UHR_RU(2_1_2, D1); + fallthrough; + case RATE_MCS_CHAN_WIDTH_40: + /* content channel 2 */ + IWL_MLD_ENC_UHR_RU(2_1_1, B1); + fallthrough; + case RATE_MCS_CHAN_WIDTH_20: + /* content channel 1 */ + IWL_MLD_ENC_UHR_RU(1_1_1, A1); + break; + } +} + +static void iwl_mld_decode_uhr_non_tb(struct iwl_mld_rx_phy_data *phy_data, + struct ieee80211_rx_status *rx_status, + struct ieee80211_radiotap_uhr *uhr) +{ + __le32 usig_a1 = phy_data->ntfy->sigs.uhr.usig_a1; + __le32 usig_a2 = phy_data->ntfy->sigs.uhr.usig_a2_uhr; + + uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_SPATIAL_REUSE | + /* All RU allocating size/index is in TB format */ + IEEE80211_RADIOTAP_UHR_KNOWN_DRU_RRU_ALLOC_TB_FMT | + IEEE80211_RADIOTAP_UHR_KNOWN_LDPC_EXTRA_SYMBOL_SEGMENT | + IEEE80211_RADIOTAP_UHR_KNOWN_PRE_FEC_PADDING_FACTOR | + IEEE80211_RADIOTAP_UHR_KNOWN_PE_DISAMBIGUITY | + IEEE80211_RADIOTAP_UHR_KNOWN_PRI80_CHAN_POS | + IEEE80211_RADIOTAP_UHR_KNOWN_NUMBER_OF_NON_OFDMA_USERS | + IEEE80211_RADIOTAP_UHR_KNOWN_INTERFERENCE_MITIGATION); + + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_SPATIAL_REUSE, + IEEE80211_RADIOTAP_UHR_DATA0_SPATIAL_REUSE); + uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_STA_RU_PS160, + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_PS_160); + uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_STA_RU, + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B0 | + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B7_B1); + /* downlink is never DRU */ + uhr->data[8] |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_INDICATION); + + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_CODING_EXTRA_SYM, + IEEE80211_RADIOTAP_UHR_DATA0_LDPC_EXTRA_SYMBOL_SEGMENT); + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_PE_A_FACTOR, + IEEE80211_RADIOTAP_UHR_DATA0_PRE_FEC_PADDING_FACTOR); + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_PE_DISAMBIGUITY, + IEEE80211_RADIOTAP_UHR_DATA0_PE_DISAMBIGUITY); + uhr->data[1] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_STA_RU_P80, + IEEE80211_RADIOTAP_UHR_DATA1_PRI80_CHAN_POS); + uhr->data[7] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_NUM_OF_USERS, + IEEE80211_RADIOTAP_UHR_DATA7_NUMBER_OF_NON_OFDMA_USERS); + + uhr->data[7] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_IM_DISABLE, + IEEE80211_RADIOTAP_UHR_DATA7_INTERFERENCE_MITIGATION); + + iwl_mld_uhr_decode_user_ru(phy_data, uhr); + + iwl_mld_eht_uhr_set_ru_alloc(rx_status, + le32_get_bits(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_STA_RU), + true); + + if (!phy_data->with_data) + return; + + uhr->user[0].known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_KNOWN_STA_ID); + uhr->user[0].info |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.user_id, + OFDM_RX_FRAME_UHR_USER_FIELD_ID, + IEEE80211_RADIOTAP_UHR_USER_INFO_STA_ID); + + /* don't report UEQM for downlink non-OFDMA MU-MIMO allocations */ + if (!(usig_a1 & cpu_to_le32(OFDM_RX_FRAME_ENHANCED_WIFI_UL_FLAG)) && + le32_get_bits(usig_a2, OFDM_RX_FRAME_UHR_PPDU_TYPE) == 2) + return; + + uhr->user[0].known |= + cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_KNOWN_UEQM); + uhr->user[0].info |= + LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_UEQM, + IEEE80211_RADIOTAP_UHR_USER_INFO_UEQM); + + if (uhr->user[0].info & cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_INFO_UEQM)) { + uhr->user[0].known |= + cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_KNOWN_UEQM_PATTERN); + uhr->user[0].info |= + LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_UEQM_PATTERN, + IEEE80211_RADIOTAP_UHR_USER_INFO_UEQM_PATTERN); + } +} + +static void +iwl_mld_decode_uhr_elr_phy_data(struct iwl_mld_rx_phy_data *phy_data, + struct sk_buff *skb, + struct ieee80211_rx_status *rx_status) +{ + struct ieee80211_radiotap_uhr_elr *elr; + __le32 elr1 = phy_data->ntfy->sigs.uhr_elr.uhr_sig_elr1; + __le32 elr2 = phy_data->ntfy->sigs.uhr_elr.uhr_sig_elr2; + + elr = iwl_mld_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_UHR_ELR, + sizeof(*elr)); + + elr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_ELR_KNOWN_VERSION_ID | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_UL_DL | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_MCS | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_CODING | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_LENGTH | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_LDPC_EXTRA_OFDM_SYM | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_STA_ID | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_DISREGARD | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_SIG_1_CRC_CHECKED | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_SIG_2_CRC_CHECKED | + IEEE80211_RADIOTAP_UHR_ELR_KNOWN_MARK_BSS_COLOR); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_VER_ID, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_VERSION_ID); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_UPLINK_FLAG, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_UL_DL); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_MCS, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_MCS); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_CODING, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_CODING); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_LENGTH_IN_SYM, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_LENGTH); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_CODING_EXTRA_SYM, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_LDPC_EXTRA_OFDM_SYM); + elr->sig1 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_SIG1_CRC_OK, + IEEE80211_RADIOTAP_UHR_ELR_SIG1_CRC_VALID); + + elr->sig2 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_STA_ID, + IEEE80211_RADIOTAP_UHR_ELR_SIG2_STA_ID); + elr->sig2 |= LE32_DEC_ENC(elr1, OFDM_RX_VECTOR_UHR_ELR_DISREGARD, + IEEE80211_RADIOTAP_UHR_ELR_SIG2_DISREGARD); + + elr->sig2 |= LE32_DEC_ENC(elr2, OFDM_RX_VECTOR_UHR_ELR_SIG2_CRC_OK, + IEEE80211_RADIOTAP_UHR_ELR_SIG2_CRC_VALID); + + elr->mark |= LE32_DEC_ENC(elr2, OFDM_RX_VECTOR_UHR_ELR_MARK_BSS_COLOR, + IEEE80211_RADIOTAP_UHR_ELR_MARK_BSS_COLOR); +} + +static void iwl_mld_decode_uhr_phy_data(struct iwl_mld_rx_phy_data *phy_data, + struct sk_buff *skb) +{ + struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); + u32 rate_n_flags = phy_data->rate_n_flags; + u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; + struct ieee80211_radiotap_uhr *uhr; + size_t uhr_len; + + if (he_type == RATE_MCS_HE_TYPE_UHR_ELR) { + iwl_mld_decode_uhr_elr_phy_data(phy_data, skb, rx_status); + return; + } + + /* space for one user_info if we captured data */ + uhr_len = struct_size(uhr, user, (phy_data->with_data ? 1 : 0)); + + uhr = iwl_mld_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_UHR, uhr_len); + + uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_GI_LTF_SIZE); + uhr->data[0] |= le32_encode_bits(u32_get_bits(rate_n_flags, + RATE_MCS_HE_GI_LTF_MSK), + IEEE80211_RADIOTAP_UHR_DATA0_GI_LTF_SIZE); + + if (phy_data->with_data) { + uhr->user[0].known |= + cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_KNOWN_MCS | + IEEE80211_RADIOTAP_UHR_USER_KNOWN_2X_LDPC | + IEEE80211_RADIOTAP_UHR_USER_KNOWN_CODING | + IEEE80211_RADIOTAP_UHR_USER_KNOWN_USER_CAPTURED); + + uhr->user[0].info |= + le32_encode_bits(u32_get_bits(rate_n_flags, + RATE_MCS_CODE_MSK), + IEEE80211_RADIOTAP_UHR_USER_INFO_MCS); + + if (phy_data->phy_info & IWL_RX_MPDU_PHY_2X_LDPC) + uhr->user[0].info |= + cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_INFO_2X_LDPC); + + if (rate_n_flags & RATE_MCS_LDPC_MSK) + uhr->user[0].info |= + cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_INFO_CODING); + } + + if (he_type == RATE_MCS_HE_TYPE_TRIG) + iwl_mld_decode_uhr_tb(phy_data, rx_status, uhr); + else + iwl_mld_decode_uhr_non_tb(phy_data, rx_status, uhr); +} + +static void iwl_mld_rx_uhr(struct iwl_mld *mld, struct sk_buff *skb, + struct iwl_mld_rx_phy_data *phy_data) +{ + if (likely(!phy_data->ntfy)) + return; + + iwl_mld_decode_uhr_usig(phy_data, skb); + iwl_mld_decode_uhr_phy_data(phy_data, skb); +} + #ifdef CONFIG_IWLWIFI_DEBUGFS static void iwl_mld_add_rtap_sniffer_config(struct iwl_mld *mld, struct sk_buff *skb) @@ -1512,19 +2042,42 @@ static void iwl_mld_rx_fill_status(struct iwl_mld *mld, int link_id, iwl_mld_set_rx_rate(mld, phy_data, rx_status); - /* must be before HE data (radiotap field order) */ - if (format == RATE_MCS_MOD_TYPE_VHT) + switch (format) { + case RATE_MCS_MOD_TYPE_CCK: + /* nothing to see here, see note below */ + break; + case RATE_MCS_MOD_TYPE_LEGACY_OFDM: + /* + * Technically legacy CCK/OFDM frames don't have an L-SIG + * since that's the compat format for HT (non-greenfield) + * and up. However, it's meant to be compatible with the + * LENGTH and RATE fields in Clause 17 and 18 OFDM frames + * so include the field for any non-CCK frame. For CCK it + * cannot work, since the LENGTH field for them is 16-bit + * and the radiotap field only has 12 bits. + */ + iwl_mld_decode_lsig(skb, phy_data); + break; + case RATE_MCS_MOD_TYPE_HT: + iwl_mld_decode_lsig(skb, phy_data); + break; + case RATE_MCS_MOD_TYPE_VHT: iwl_mld_rx_vht(skb, phy_data); - - /* must be before L-SIG data (radiotap field order) */ - if (format == RATE_MCS_MOD_TYPE_HE) + iwl_mld_decode_lsig(skb, phy_data); + break; + case RATE_MCS_MOD_TYPE_HE: iwl_mld_rx_he(skb, phy_data); - - iwl_mld_decode_lsig(skb, phy_data); - - /* TLVs - must be after radiotap fixed fields */ - if (format == RATE_MCS_MOD_TYPE_EHT) + iwl_mld_decode_lsig(skb, phy_data); + break; + case RATE_MCS_MOD_TYPE_EHT: + iwl_mld_decode_lsig(skb, phy_data); iwl_mld_rx_eht(mld, skb, phy_data); + break; + case RATE_MCS_MOD_TYPE_UHR: + iwl_mld_decode_lsig(skb, phy_data); + iwl_mld_rx_uhr(mld, skb, phy_data); + break; + } #ifdef CONFIG_IWLWIFI_DEBUGFS if (unlikely(mld->monitor.on)) { From f1969100392792abe0e1649961ce0eeb9d43a709 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:16 +0300 Subject: [PATCH 1602/2126] wifi: iwlwifi: mld: report UHR LTF symbols for non-TB PPDUs For TB (trigger-based) PPDUs we were already reporting this, but I missed it in the non-TB PPDU case. Add it now. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.a8228ab59708.I6c58f3e4f30bb0fb7e57a6c49782bf79d280371d@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 1362e3ad97b2..5866999c2abd 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1671,6 +1671,7 @@ static void iwl_mld_decode_uhr_non_tb(struct iwl_mld_rx_phy_data *phy_data, __le32 usig_a2 = phy_data->ntfy->sigs.uhr.usig_a2_uhr; uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_SPATIAL_REUSE | + IEEE80211_RADIOTAP_UHR_KNOWN_NUMBER_OF_UHR_LTF_SYMBOLS | /* All RU allocating size/index is in TB format */ IEEE80211_RADIOTAP_UHR_KNOWN_DRU_RRU_ALLOC_TB_FMT | IEEE80211_RADIOTAP_UHR_KNOWN_LDPC_EXTRA_SYMBOL_SEGMENT | @@ -1683,6 +1684,9 @@ static void iwl_mld_decode_uhr_non_tb(struct iwl_mld_rx_phy_data *phy_data, uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, OFDM_RX_FRAME_UHR_SPATIAL_REUSE, IEEE80211_RADIOTAP_UHR_DATA0_SPATIAL_REUSE); + uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_NUM_OF_LTF_SYM, + IEEE80211_RADIOTAP_UHR_DATA0_NUMBER_OF_LTF_SYMBOLS); uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, OFDM_RX_FRAME_UHR_STA_RU_PS160, IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_PS_160); From 1e516621dc0bd35718852a5df52de2b11fa3e76f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:17 +0300 Subject: [PATCH 1603/2126] wifi: iwlwifi: mld: fix some radiotap field reports For non-trigger-based UHR frames, the RU/DRU allocation is only valid for OFDMA PPDUs, and the non-OFDMA users and interference mitigation (IM) is only valid for non-OFDMA. Fix the reporting accordingly. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.1c9e8d8a9176.I4f67f80fc962187dbe488506a7d90ffaf78585c4@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 52 ++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 5866999c2abd..cb3872cb9e56 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1669,17 +1669,43 @@ static void iwl_mld_decode_uhr_non_tb(struct iwl_mld_rx_phy_data *phy_data, { __le32 usig_a1 = phy_data->ntfy->sigs.uhr.usig_a1; __le32 usig_a2 = phy_data->ntfy->sigs.uhr.usig_a2_uhr; + bool ofdma; uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_SPATIAL_REUSE | IEEE80211_RADIOTAP_UHR_KNOWN_NUMBER_OF_UHR_LTF_SYMBOLS | - /* All RU allocating size/index is in TB format */ - IEEE80211_RADIOTAP_UHR_KNOWN_DRU_RRU_ALLOC_TB_FMT | IEEE80211_RADIOTAP_UHR_KNOWN_LDPC_EXTRA_SYMBOL_SEGMENT | IEEE80211_RADIOTAP_UHR_KNOWN_PRE_FEC_PADDING_FACTOR | IEEE80211_RADIOTAP_UHR_KNOWN_PE_DISAMBIGUITY | - IEEE80211_RADIOTAP_UHR_KNOWN_PRI80_CHAN_POS | - IEEE80211_RADIOTAP_UHR_KNOWN_NUMBER_OF_NON_OFDMA_USERS | - IEEE80211_RADIOTAP_UHR_KNOWN_INTERFERENCE_MITIGATION); + IEEE80211_RADIOTAP_UHR_KNOWN_PRI80_CHAN_POS); + + /* + * TB isn't handled here, so uplink can't be OFDMA. + * Downlink OFDMA is PPDU type 0. + */ + ofdma = !(usig_a1 & cpu_to_le32(OFDM_RX_FRAME_ENHANCED_WIFI_UL_FLAG)) && + le32_get_bits(usig_a2, OFDM_RX_FRAME_UHR_PPDU_TYPE) == 0; + + if (ofdma) { + /* All RU allocation size/index is in TB format */ + uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_DRU_RRU_ALLOC_TB_FMT); + /* downlink is never DRU */ + uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_STA_RU_PS160, + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_PS_160); + uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, + OFDM_RX_FRAME_UHR_STA_RU, + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B0 | + IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B7_B1); + uhr->data[8] |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_INDICATION); + } else { + uhr->known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_KNOWN_NUMBER_OF_NON_OFDMA_USERS | + IEEE80211_RADIOTAP_UHR_KNOWN_INTERFERENCE_MITIGATION); + uhr->data[7] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, + OFDM_RX_FRAME_UHR_NUM_OF_USERS, + IEEE80211_RADIOTAP_UHR_DATA7_NUMBER_OF_NON_OFDMA_USERS); + if (!(phy_data->ntfy->sigs.uhr.b1 & cpu_to_le32(OFDM_RX_FRAME_UHR_IM_DISABLE))) + uhr->data[7] |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_DATA7_INTERFERENCE_MITIGATION); + } uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, OFDM_RX_FRAME_UHR_SPATIAL_REUSE, @@ -1687,15 +1713,6 @@ static void iwl_mld_decode_uhr_non_tb(struct iwl_mld_rx_phy_data *phy_data, uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, OFDM_RX_FRAME_UHR_NUM_OF_LTF_SYM, IEEE80211_RADIOTAP_UHR_DATA0_NUMBER_OF_LTF_SYMBOLS); - uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, - OFDM_RX_FRAME_UHR_STA_RU_PS160, - IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_PS_160); - uhr->data[8] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, - OFDM_RX_FRAME_UHR_STA_RU, - IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B0 | - IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_ALLOC_TB_FMT_B7_B1); - /* downlink is never DRU */ - uhr->data[8] |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_DATA8_DRU_RRU_INDICATION); uhr->data[0] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, OFDM_RX_FRAME_UHR_CODING_EXTRA_SYM, @@ -1709,13 +1726,6 @@ static void iwl_mld_decode_uhr_non_tb(struct iwl_mld_rx_phy_data *phy_data, uhr->data[1] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b2, OFDM_RX_FRAME_UHR_STA_RU_P80, IEEE80211_RADIOTAP_UHR_DATA1_PRI80_CHAN_POS); - uhr->data[7] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, - OFDM_RX_FRAME_UHR_NUM_OF_USERS, - IEEE80211_RADIOTAP_UHR_DATA7_NUMBER_OF_NON_OFDMA_USERS); - - uhr->data[7] |= LE32_DEC_ENC(phy_data->ntfy->sigs.uhr.b1, - OFDM_RX_FRAME_UHR_IM_DISABLE, - IEEE80211_RADIOTAP_UHR_DATA7_INTERFERENCE_MITIGATION); iwl_mld_uhr_decode_user_ru(phy_data, uhr); From 97a0cde5d8105cc96e6fd3c01f14c21ced0e3010 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:18 +0300 Subject: [PATCH 1604/2126] wifi: iwlwifi: mld: report UHR per-user NSS Given that the sniffer only receives a single user's data and only reports such in radiotap, simply add the NSS value. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.72614c2740f4.I34ad1e61e97e410eae7aa36018876277440da12f@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index cb3872cb9e56..e59f33c39a57 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1841,6 +1841,7 @@ static void iwl_mld_decode_uhr_phy_data(struct iwl_mld_rx_phy_data *phy_data, if (phy_data->with_data) { uhr->user[0].known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_KNOWN_MCS | + IEEE80211_RADIOTAP_UHR_USER_KNOWN_NSS | IEEE80211_RADIOTAP_UHR_USER_KNOWN_2X_LDPC | IEEE80211_RADIOTAP_UHR_USER_KNOWN_CODING | IEEE80211_RADIOTAP_UHR_USER_KNOWN_USER_CAPTURED); @@ -1849,6 +1850,10 @@ static void iwl_mld_decode_uhr_phy_data(struct iwl_mld_rx_phy_data *phy_data, le32_encode_bits(u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK), IEEE80211_RADIOTAP_UHR_USER_INFO_MCS); + uhr->user[0].info |= + le32_encode_bits(u32_get_bits(rate_n_flags, + RATE_MCS_NSS_MSK), + IEEE80211_RADIOTAP_UHR_USER_INFO_NSS); if (phy_data->phy_info & IWL_RX_MPDU_PHY_2X_LDPC) uhr->user[0].info |= From 023202af5e927c41523ed9cc6fa280687a4d87dc Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:19 +0300 Subject: [PATCH 1605/2126] wifi: iwlwifi: mld: report beamforming in UHR sniffer In per-user information for UHR sniffer, report whether or not beamforming was used, according to rate_n_flags. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.3f8de2b3592b.Ie21d26e1a25a117515907e9577a51de3bc29692b@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index e59f33c39a57..738b6fb9770f 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1842,6 +1842,7 @@ static void iwl_mld_decode_uhr_phy_data(struct iwl_mld_rx_phy_data *phy_data, uhr->user[0].known |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_KNOWN_MCS | IEEE80211_RADIOTAP_UHR_USER_KNOWN_NSS | + IEEE80211_RADIOTAP_UHR_USER_KNOWN_BF | IEEE80211_RADIOTAP_UHR_USER_KNOWN_2X_LDPC | IEEE80211_RADIOTAP_UHR_USER_KNOWN_CODING | IEEE80211_RADIOTAP_UHR_USER_KNOWN_USER_CAPTURED); @@ -1859,6 +1860,10 @@ static void iwl_mld_decode_uhr_phy_data(struct iwl_mld_rx_phy_data *phy_data, uhr->user[0].info |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_INFO_2X_LDPC); + if (rate_n_flags & RATE_MCS_BF_MSK) + uhr->user[0].info |= + cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_INFO_BF); + if (rate_n_flags & RATE_MCS_LDPC_MSK) uhr->user[0].info |= cpu_to_le32(IEEE80211_RADIOTAP_UHR_USER_INFO_CODING); From db2bca92bdc7184266d84b57f9ae5528e085e73b Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:20 +0300 Subject: [PATCH 1606/2126] wifi: iwlwifi: correctly report TB sounding PPDUs in sniffer Sounding PPDUs are currently reported as "not for us" in the sniffer, since PHY reports that aren't detected as sounding immediately by a zero-length indication (which doesn't exist for trigger-based) are released only on the next PHY sniffer notification, when no MPDU was received. The "not for us" indication is, however, wrong in both cases: for TB sounding PPDUs it should be sounding, for others it should be some unspecified (DSP?) error. Fix both cases. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.f8f6a08851a8.I8689a2a1599578aea53dda62cffc7f012d1d10f7@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 33 +++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 738b6fb9770f..60d653b5b755 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -2864,7 +2864,7 @@ void iwl_mld_handle_rsc_notif(struct iwl_mld *mld, #endif /* CONFIG_PM_SLEEP */ static void iwl_mld_no_data_rx(struct iwl_mld *mld, - struct napi_struct *napi, u8 status, + struct napi_struct *napi, bool no_mpdu, struct iwl_rx_phy_air_sniffer_ntfy *ntfy) { struct ieee80211_rx_status *rx_status; @@ -2889,11 +2889,26 @@ static void iwl_mld_no_data_rx(struct iwl_mld *mld, /* 0-length PSDU */ rx_status->flag |= RX_FLAG_NO_PSDU; - switch (status) { + switch (ntfy->status) { case IWL_SNIF_STAT_PLCP_RX_OK: - /* we only get here with sounding PPDUs */ - rx_status->zero_length_psdu_type = - IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING; + /* + * For trigger-based PPDUs, the firmware decodes the PHY header + * and releases with a good status only if the frame was for the + * configured AID (the bad status depends on the version), and + * also only sets IWL_SNIF_FLAG_VALID_TB_RX if receiving for the + * configured AID. + * + * So trigger-based PHY notifications without MPDU are sounding + * PPDUs, while other releases without MPDU are some kind of + * error after a good PHY header - don't flag failed PLCP in + * this case, but release as unspecified zero-len reason. + */ + if (no_mpdu && !(ntfy->flags & IWL_SNIF_FLAG_VALID_TB_RX)) + rx_status->zero_length_psdu_type = + IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR; + else + rx_status->zero_length_psdu_type = + IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING; break; case IWL_SNIF_STAT_AID_NOT_FOR_US: rx_status->zero_length_psdu_type = @@ -2904,6 +2919,7 @@ static void iwl_mld_no_data_rx(struct iwl_mld *mld, case IWL_SNIF_STAT_PLCP_RX_SIGB_ERR: case IWL_SNIF_STAT_UNKNOWN_ERROR: default: + /* some kind of PLCP error - no details from FW */ rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; fallthrough; case IWL_SNIF_STAT_UNEXPECTED_TB: @@ -2947,10 +2963,9 @@ void iwl_mld_handle_phy_air_sniffer_notif(struct iwl_mld *mld, "invalid air sniffer notification size\n")) return; - /* check if there's an old one to release as errored */ + /* check if there's an old one to release */ if (mld->monitor.phy.valid && !mld->monitor.phy.used) - iwl_mld_no_data_rx(mld, napi, IWL_SNIF_STAT_AID_NOT_FOR_US, - &mld->monitor.phy.data); + iwl_mld_no_data_rx(mld, napi, true, &mld->monitor.phy.data); /* old data is no longer valid now */ mld->monitor.phy.valid = false; @@ -2987,7 +3002,7 @@ void iwl_mld_handle_phy_air_sniffer_notif(struct iwl_mld *mld, } if (ntfy->status != IWL_SNIF_STAT_PLCP_RX_OK || is_ndp) { - iwl_mld_no_data_rx(mld, napi, ntfy->status, ntfy); + iwl_mld_no_data_rx(mld, napi, false, ntfy); return; } From 6f177130233c64a01949f309d90cfdb0bf573f3d Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:21 +0300 Subject: [PATCH 1607/2126] wifi: iwlwifi: mld: remove UHR TB U-SIG2 B2 validate bit Clearly the existing code is wrong. Since it's not clear that the value is reported by hardware, and we probably won't need it, remove it for now. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.56c9dd83eb39.I4482c69e48aa4661d11aecc23aab03fb9fef5ead@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 60d653b5b755..076c4fd6f37c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1354,9 +1354,6 @@ static void iwl_mld_decode_uhr_usig_tb(struct iwl_mld_rx_phy_data *phy_data, IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, OFDM_RX_FRAME_UHR_PPDU_TYPE, IEEE80211_RADIOTAP_UHR_USIG2_TB_B0_B1_PPDU_TYPE); - IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, - IEEE80211_RADIOTAP_UHR_USIG2_MU_B2_COBF_COSR, - IEEE80211_RADIOTAP_UHR_USIG2_TB_B2_VALIDATE); IWL_MLD_ENC_USIG_VALUE_MASK(usig, usig_a2, OFDM_RX_FRAME_UHR_TRIG_SPATIAL_REUSE_1, IEEE80211_RADIOTAP_UHR_USIG2_TB_B3_B6_SPATIAL_REUSE_1); From cfa74632ec5f74af5c9b2c4c25873438a0a245a8 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:22 +0300 Subject: [PATCH 1608/2126] wifi: iwlwifi: mld: detect UHR sounding packets Detect UHR sounding packets by checking their data length just like for EHT and reporting them to the sniffer immediately. Signed-off-by: Johannes Berg Reviewed-by: Benjamin Berg Link: https://patch.msgid.link/20261001161715.1c6817d2205b.Icc0cb8f2ef738bba6105f7b909c47d6d0cf12491@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 076c4fd6f37c..c0203e74fff6 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -2996,6 +2996,13 @@ void iwl_mld_handle_phy_air_sniffer_notif(struct iwl_mld *mld, !le32_get_bits(ntfy->sigs.eht.sig2, OFDM_RX_FRAME_EHT_NUM_OF_DATA_SYM); break; + case RATE_MCS_MOD_TYPE_UHR: + if (he_type == RATE_MCS_HE_TYPE_TRIG || + he_type == RATE_MCS_HE_TYPE_UHR_ELR) + break; + is_ndp = !le32_get_bits(ntfy->sigs.uhr.sig2, + OFDM_RX_UHR_NUM_OF_DATA_SYM); + break; } if (ntfy->status != IWL_SNIF_STAT_PLCP_RX_OK || is_ndp) { From 7f2793237f68a52d4d78e8223b84ba96a3acdf7b Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:23 +0300 Subject: [PATCH 1609/2126] wifi: iwlwifi: mld: report the guard interval for UHR We didn't report the guard interval for UHR to mac80211, fix that by refactoring the EHT function and using it. The LTF is reported only in radiotap (differently), so the code for UHR doesn't need it. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.9f728be36075.Ic46d2234d03fdf3b098a8b25f607bd3559e6a2db@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 70 ++++++++++++--------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index c0203e74fff6..9ba68564bf98 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1243,48 +1243,30 @@ static void iwl_mld_decode_eht_phy_data(struct iwl_mld_rx_phy_data *phy_data, iwl_mld_decode_eht_non_tb(phy_data, rx_status, eht); } -static void iwl_mld_rx_eht(struct iwl_mld *mld, struct sk_buff *skb, - struct iwl_mld_rx_phy_data *phy_data) +static u8 iwl_mld_decode_eht_uhr_gi_ltf(u32 rate_n_flags, u8 *gi) { - struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); - struct ieee80211_radiotap_eht *eht; - size_t eht_len = sizeof(*eht); - u32 rate_n_flags = phy_data->rate_n_flags; u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; - /* EHT and HE have the same values for LTF */ - u8 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN; - /* u32 for 1 user_info */ - if (phy_data->with_data) - eht_len += sizeof(u32); - - eht = iwl_mld_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT, eht_len); + *gi = NL80211_RATE_INFO_EHT_GI_0_8; switch (u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK)) { case 0: if (he_type == RATE_MCS_HE_TYPE_TRIG) { - rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6; - ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; - } else { - rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8; - ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; + *gi = NL80211_RATE_INFO_EHT_GI_1_6; + return IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; } - break; + return IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; case 1: - rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6; - ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; - break; + *gi = NL80211_RATE_INFO_EHT_GI_1_6; + return IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; case 2: - ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; if (he_type == RATE_MCS_HE_TYPE_TRIG) - rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2; - else - rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8; - break; + *gi = NL80211_RATE_INFO_EHT_GI_3_2; + return IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; case 3: if (he_type != RATE_MCS_HE_TYPE_TRIG) { - ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; - rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2; + *gi = NL80211_RATE_INFO_EHT_GI_3_2; + return IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; } break; default: @@ -1292,7 +1274,29 @@ static void iwl_mld_rx_eht(struct iwl_mld *mld, struct sk_buff *skb, break; } + return IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN; +} + +static void iwl_mld_rx_eht(struct iwl_mld *mld, struct sk_buff *skb, + struct iwl_mld_rx_phy_data *phy_data) +{ + struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); + struct ieee80211_radiotap_eht *eht; + size_t eht_len = sizeof(*eht); + u32 rate_n_flags = phy_data->rate_n_flags; + u8 gi, ltf; + + /* u32 for 1 user_info */ + if (phy_data->with_data) + eht_len += sizeof(u32); + + eht = iwl_mld_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT, eht_len); + + ltf = iwl_mld_decode_eht_uhr_gi_ltf(rate_n_flags, &gi); + if (ltf != IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN) { + rx_status->eht.gi = gi; + eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_GI); eht->data[0] |= le32_encode_bits(ltf, IEEE80211_RADIOTAP_EHT_DATA0_LTF) | @@ -1875,6 +1879,14 @@ static void iwl_mld_decode_uhr_phy_data(struct iwl_mld_rx_phy_data *phy_data, static void iwl_mld_rx_uhr(struct iwl_mld *mld, struct sk_buff *skb, struct iwl_mld_rx_phy_data *phy_data) { + struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); + u8 gi, ltf; + + /* the LTF size is reported from the PHY data, only the GI is needed */ + ltf = iwl_mld_decode_eht_uhr_gi_ltf(phy_data->rate_n_flags, &gi); + if (ltf != IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN) + rx_status->uhr.gi = gi; + if (likely(!phy_data->ntfy)) return; From 946f44ef759cedf70cb6ea1136b5e9806877ca57 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:24 +0300 Subject: [PATCH 1610/2126] wifi: iwlwifi: mld: set RX_FLAG_FAILED_PLCP_CRC for bad U-SIG CRC There are a number of places checking for the U-SIG CRC and then reporting if it failed, but we should set the failed PLCP CRC top-level radiotap flag for easier discarding of such packets in users such as wireshark. Do that with a new helper function, to avoid doing it in so many places. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.cda01742eff8.I824c410fefd4022973403c1cf18f47459e34c4b2@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 9ba68564bf98..e1964e570012 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -816,6 +816,14 @@ iwl_mld_radiotap_put_tlv(struct sk_buff *skb, u16 type, u16 len) (_usig)->value |= LE32_DEC_ENC(in_value, dec_bits, _enc_bits); \ } while (0) +static void +iwl_mld_check_bad_usig_crc(struct ieee80211_rx_status *rx_status, + struct ieee80211_radiotap_eht_usig *usig) +{ + if (usig->common & cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC)) + rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; +} + static void iwl_mld_decode_eht_usig_tb(struct iwl_mld_rx_phy_data *phy_data, struct ieee80211_radiotap_eht_usig *usig) { @@ -878,6 +886,7 @@ static void iwl_mld_decode_eht_usig_non_tb(struct iwl_mld_rx_phy_data *phy_data, static void iwl_mld_decode_eht_usig(struct iwl_mld_rx_phy_data *phy_data, struct sk_buff *skb) { + struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); u32 he_type = phy_data->rate_n_flags & RATE_MCS_HE_TYPE_MSK; __le32 usig_a1 = phy_data->ntfy->sigs.eht.usig_a1; __le32 usig_a2 = phy_data->ntfy->sigs.eht.usig_a2_eht; @@ -941,6 +950,8 @@ static void iwl_mld_decode_eht_usig(struct iwl_mld_rx_phy_data *phy_data, iwl_mld_decode_eht_usig_tb(phy_data, usig); else iwl_mld_decode_eht_usig_non_tb(phy_data, usig); + + iwl_mld_check_bad_usig_crc(rx_status, usig); } static void @@ -1448,6 +1459,7 @@ static void iwl_mld_decode_uhr_usig_non_tb(struct iwl_mld_rx_phy_data *phy_data, static void iwl_mld_decode_uhr_usig(struct iwl_mld_rx_phy_data *phy_data, struct sk_buff *skb) { + struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); u32 he_type = phy_data->rate_n_flags & RATE_MCS_HE_TYPE_MSK; struct ieee80211_radiotap_eht_usig *usig; __le32 usig_a1 = phy_data->ntfy->sigs.uhr.usig_a1; @@ -1507,6 +1519,8 @@ static void iwl_mld_decode_uhr_usig(struct iwl_mld_rx_phy_data *phy_data, iwl_mld_decode_uhr_usig_non_tb(phy_data, usig); break; } + + iwl_mld_check_bad_usig_crc(rx_status, usig); } static void iwl_mld_decode_uhr_tb(struct iwl_mld_rx_phy_data *phy_data, From db3bf5d67b3c4433b1b864adc30efa1026cb0ad5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:25 +0300 Subject: [PATCH 1611/2126] wifi: iwlwifi: advertise UHR Co-BF support This is supported by hardware, advertise it. We'll have to separately work on enabling it in firmware if the AP supports it. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.6c5fc579f2d8.I0cdf7516e95181e31c33fde374216fb6bc8f4aa1@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c index ed2b094c1ad7..31badfa35f97 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c @@ -716,6 +716,7 @@ static const struct ieee80211_sband_iftype_data iwl_iftype_cap[] = { IEEE80211_UHR_MAC_CAP0_DPS_SUPP, [1] = IEEE80211_UHR_MAC_CAP1_DUO_SUPP | IEEE80211_UHR_MAC_CAP1_DBE_SUPP, + [4] = IEEE80211_UHR_MAC_CAP4_CO_BF_SUPP, }, }, }, From ec02ebd4d7099e3827c3b3476b1814c7fa666dbc Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Thu, 1 Oct 2026 16:20:26 +0300 Subject: [PATCH 1612/2126] wifi: iwlwifi: mld: add support for WoWLAN CIGTK API The firmware added CIGTK rekey support for D3: - KEK_KCK_MATERIAL_CMD version 5 has a new cigtk_cipher field. - WOWLAN_INFO_NOTIFICATION version 7 reports the CIGTK material of the active link, and MLO keys can now be of type CIGTK. The CIGTK material itself is not used yet, this is done in a separate patch. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20261001161715.45aa7d3f2421.I1c53d0b8f1a1f1b3a4e35a86b5a6a5c04ff5f1a2@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/fw/api/commands.h | 5 +- .../net/wireless/intel/iwlwifi/fw/api/d3.h | 62 +++++++++++++++- .../wireless/intel/iwlwifi/fw/api/offload.h | 5 +- drivers/net/wireless/intel/iwlwifi/mld/d3.c | 71 +++++++++++++++++-- 4 files changed, 133 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/commands.h b/drivers/net/wireless/intel/iwlwifi/fw/api/commands.h index f76f76e54c4e..dbb0e7c194df 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/commands.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/commands.h @@ -569,8 +569,9 @@ enum iwl_legacy_cmds { /** * @WOWLAN_KEK_KCK_MATERIAL: &struct iwl_wowlan_kek_kck_material_cmd_v2, - * &struct iwl_wowlan_kek_kck_material_cmd_v3 or - * &struct iwl_wowlan_kek_kck_material_cmd_v4 + * &struct iwl_wowlan_kek_kck_material_cmd_v3, + * &struct iwl_wowlan_kek_kck_material_cmd_v4 or + * &struct iwl_wowlan_kek_kck_material_cmd */ WOWLAN_KEK_KCK_MATERIAL = 0xe4, diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h index a0379aca99d7..c469ea965157 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h @@ -422,6 +422,7 @@ struct iwl_wowlan_config_cmd { #define WOWLAN_IGTK_MIN_INDEX 4 #define WOWLAN_BIGTK_KEYS_NUM 2 #define WOWLAN_BIGTK_MIN_INDEX 6 +#define WOWLAN_CIGTK_KEYS_NUM 2 /* * WOWLAN_TSC_RSC_PARAMS @@ -531,6 +532,20 @@ struct iwl_wowlan_kek_kck_material_cmd_v4 { __le32 bigtk_cipher; } __packed; /* KEK_KCK_MATERIAL_API_S_VER_4 */ +struct iwl_wowlan_kek_kck_material_cmd { + __le32 sta_id; + u8 kck[IWL_KCK_MAX_SIZE]; + u8 kek[IWL_KEK_MAX_SIZE]; + __le16 kck_len; + __le16 kek_len; + __le64 replay_ctr; + __le32 akm; + __le32 gtk_cipher; + __le32 igtk_cipher; + __le32 bigtk_cipher; + __le32 cigtk_cipher; +} __packed; /* KEK_KCK_MATERIAL_API_S_VER_5 */ + struct iwl_wowlan_get_status_cmd { __le32 sta_id; } __packed; /* WOWLAN_GET_STATUSES_CMD_API_S_VER_1 */ @@ -812,19 +827,21 @@ struct iwl_wowlan_info_notif_v1 { } __packed; /* WOWLAN_INFO_NTFY_API_S_VER_1 */ /* MAX MLO keys of non-active links that can arrive in the notification */ -#define WOWLAN_MAX_MLO_KEYS 18 +#define WOWLAN_MAX_MLO_KEYS 24 /** * enum iwl_wowlan_mlo_gtk_type - GTK types * @WOWLAN_MLO_GTK_KEY_TYPE_GTK: GTK * @WOWLAN_MLO_GTK_KEY_TYPE_IGTK: IGTK * @WOWLAN_MLO_GTK_KEY_TYPE_BIGTK: BIGTK + * @WOWLAN_MLO_GTK_KEY_TYPE_CIGTK: CIGTK * @WOWLAN_MLO_GTK_KEY_NUM_TYPES: number of key types */ enum iwl_wowlan_mlo_gtk_type { WOWLAN_MLO_GTK_KEY_TYPE_GTK, WOWLAN_MLO_GTK_KEY_TYPE_IGTK, WOWLAN_MLO_GTK_KEY_TYPE_BIGTK, + WOWLAN_MLO_GTK_KEY_TYPE_CIGTK, WOWLAN_MLO_GTK_KEY_NUM_TYPES }; /* WOWLAN_MLO_GTK_KEY_TYPE_API_E_VER_1 */ @@ -931,11 +948,51 @@ struct iwl_wowlan_info_notif_v5 { struct iwl_wowlan_mlo_gtk mlo_gtks[]; } __packed; /* WOWLAN_INFO_NTFY_API_S_VER_5 */ +/** + * struct iwl_wowlan_info_notif_v6 - WoWLAN information notification + * @gtk: GTK data + * @igtk: IGTK data + * @bigtk: BIGTK data + * @replay_ctr: GTK rekey replay counter + * @pattern_number: number of the matched patterns + * @qos_seq_ctr: QoS sequence counters to use next + * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason + * @num_of_gtk_rekeys: number of GTK rekeys + * @transmitted_ndps: number of transmitted neighbor discovery packets + * @received_beacons: number of received beacons + * @tid_tear_down: bit mask of tids whose BA sessions were closed + * in suspend state + * @station_id: station id + * @num_mlo_link_keys: number of &struct iwl_wowlan_mlo_gtk structs + * following this notif + * @tid_offloaded_tx: tid used by the firmware to transmit data packets + * while in wowlan + * @mlo_gtks: array of GTKs of size num_mlo_link_keys + */ +struct iwl_wowlan_info_notif_v6 { + struct iwl_wowlan_gtk_status gtk[WOWLAN_GTK_KEYS_NUM]; + struct iwl_wowlan_igtk_status igtk[WOWLAN_IGTK_KEYS_NUM]; + struct iwl_wowlan_igtk_status bigtk[WOWLAN_BIGTK_KEYS_NUM]; + __le64 replay_ctr; + __le16 pattern_number; + __le16 qos_seq_ctr; + __le32 wakeup_reasons; + __le32 num_of_gtk_rekeys; + __le32 transmitted_ndps; + __le32 received_beacons; + u8 tid_tear_down; + u8 station_id; + u8 num_mlo_link_keys; + u8 tid_offloaded_tx; + struct iwl_wowlan_mlo_gtk mlo_gtks[]; +} __packed; /* WOWLAN_INFO_NTFY_API_S_VER_6 */ + /** * struct iwl_wowlan_info_notif - WoWLAN information notification * @gtk: GTK data * @igtk: IGTK data * @bigtk: BIGTK data + * @cigtk: CIGTK data * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched patterns * @qos_seq_ctr: QoS sequence counters to use next @@ -956,6 +1013,7 @@ struct iwl_wowlan_info_notif { struct iwl_wowlan_gtk_status gtk[WOWLAN_GTK_KEYS_NUM]; struct iwl_wowlan_igtk_status igtk[WOWLAN_IGTK_KEYS_NUM]; struct iwl_wowlan_igtk_status bigtk[WOWLAN_BIGTK_KEYS_NUM]; + struct iwl_wowlan_igtk_status cigtk[WOWLAN_CIGTK_KEYS_NUM]; __le64 replay_ctr; __le16 pattern_number; __le16 qos_seq_ctr; @@ -968,7 +1026,7 @@ struct iwl_wowlan_info_notif { u8 num_mlo_link_keys; u8 tid_offloaded_tx; struct iwl_wowlan_mlo_gtk mlo_gtks[]; -} __packed; /* WOWLAN_INFO_NTFY_API_S_VER_6 */ +} __packed; /* WOWLAN_INFO_NTFY_API_S_VER_7 */ /** * struct iwl_wowlan_wake_pkt_notif - WoWLAN wake packet notification diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/offload.h b/drivers/net/wireless/intel/iwlwifi/fw/api/offload.h index bb801650a565..078116fab054 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/offload.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/offload.h @@ -3,7 +3,7 @@ * Copyright (C) 2012-2014 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2016-2017 Intel Deutschland GmbH - * Copyright (C) 2021-2025 Intel Corporation + * Copyright (C) 2021-2026 Intel Corporation */ #ifndef __iwl_fw_api_offload_h__ #define __iwl_fw_api_offload_h__ @@ -20,7 +20,8 @@ enum iwl_prot_offload_subcmd_ids { /** * @WOWLAN_INFO_NOTIFICATION: Notification in * &struct iwl_wowlan_info_notif_v1, iwl_wowlan_info_notif_v3, - * &struct iwl_wowlan_info_notif_v5 or &struct iwl_wowlan_info_notif + * &struct iwl_wowlan_info_notif_v5, &struct iwl_wowlan_info_notif_v6 + * or &struct iwl_wowlan_info_notif */ WOWLAN_INFO_NOTIFICATION = 0xFD, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/d3.c b/drivers/net/wireless/intel/iwlwifi/mld/d3.c index 7a7d07a7914d..ce959363f62c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/d3.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/d3.c @@ -598,6 +598,37 @@ iwl_mld_convert_wowlan_notif_v5(const struct iwl_wowlan_info_notif_v5 *notif_v5, } } +static void +iwl_mld_convert_wowlan_notif_v6(const struct iwl_wowlan_info_notif_v6 *notif_v6, + struct iwl_wowlan_info_notif *notif) +{ + /* v6 is identical to the new format, except that it has no CIGTK */ + BUILD_BUG_ON(sizeof(notif->gtk) != sizeof(notif_v6->gtk)); + BUILD_BUG_ON(sizeof(notif->igtk) != sizeof(notif_v6->igtk)); + BUILD_BUG_ON(sizeof(notif->bigtk) != sizeof(notif_v6->bigtk)); + + memcpy(notif->gtk, notif_v6->gtk, sizeof(notif_v6->gtk)); + memcpy(notif->igtk, notif_v6->igtk, sizeof(notif_v6->igtk)); + memcpy(notif->bigtk, notif_v6->bigtk, sizeof(notif_v6->bigtk)); + + notif->replay_ctr = notif_v6->replay_ctr; + notif->pattern_number = notif_v6->pattern_number; + notif->qos_seq_ctr = notif_v6->qos_seq_ctr; + notif->wakeup_reasons = notif_v6->wakeup_reasons; + notif->num_of_gtk_rekeys = notif_v6->num_of_gtk_rekeys; + notif->transmitted_ndps = notif_v6->transmitted_ndps; + notif->received_beacons = notif_v6->received_beacons; + notif->tid_tear_down = notif_v6->tid_tear_down; + notif->station_id = notif_v6->station_id; + notif->num_mlo_link_keys = notif_v6->num_mlo_link_keys; + notif->tid_offloaded_tx = notif_v6->tid_offloaded_tx; + + if (notif_v6->num_mlo_link_keys) + memcpy(notif->mlo_gtks, notif_v6->mlo_gtks, + notif_v6->num_mlo_link_keys * + sizeof(struct iwl_wowlan_mlo_gtk)); +} + static bool iwl_mld_validate_wowlan_notif_size(struct iwl_mld *mld, u32 len, const void *notif_data, int version) @@ -619,12 +650,23 @@ static bool iwl_mld_validate_wowlan_notif_size(struct iwl_mld *mld, u32 len, num_mlo_keys = notif_v5->num_mlo_link_keys; } else if (version == 6) { + const struct iwl_wowlan_info_notif_v6 *notif_v6 = notif_data; + + expected_len = sizeof(*notif_v6); + + if (IWL_FW_CHECK(mld, len < expected_len, + "Invalid wowlan_info_notif v6 (expected=%u got=%u)\n", + expected_len, len)) + return false; + + num_mlo_keys = notif_v6->num_mlo_link_keys; + } else if (version == 7) { const struct iwl_wowlan_info_notif *notif = notif_data; expected_len = sizeof(*notif); if (IWL_FW_CHECK(mld, len < expected_len, - "Invalid wowlan_info_notif v6 (expected=%u got=%u)\n", + "Invalid wowlan_info_notif v7 (expected=%u got=%u)\n", expected_len, len)) return false; @@ -683,9 +725,27 @@ iwl_mld_handle_wowlan_info_notif(struct iwl_mld *mld, iwl_mld_convert_wowlan_notif_v5(_notif, converted_notif); notif = converted_notif; } else if (wowlan_info_ver == 6) { + const struct iwl_wowlan_info_notif_v6 *_notif = + (void *)pkt->data; + + if (!iwl_mld_validate_wowlan_notif_size(mld, len, _notif, 6)) + return true; + + converted_notif = kzalloc_flex(*converted_notif, mlo_gtks, + _notif->num_mlo_link_keys, + GFP_ATOMIC); + if (!converted_notif) { + IWL_ERR(mld, + "Failed to allocate memory for converted wowlan_info_notif\n"); + return true; + } + + iwl_mld_convert_wowlan_notif_v6(_notif, converted_notif); + notif = converted_notif; + } else if (wowlan_info_ver == 7) { notif = (void *)pkt->data; - if (!iwl_mld_validate_wowlan_notif_size(mld, len, notif, 6)) + if (!iwl_mld_validate_wowlan_notif_size(mld, len, notif, 7)) return true; } else { /* smaller versions are not supported */ @@ -1834,9 +1894,12 @@ iwl_mld_send_kek_kck_cmd(struct iwl_mld *mld, struct iwl_mld_suspend_key_iter_data data, int ap_sta_id) { - struct iwl_wowlan_kek_kck_material_cmd_v4 kek_kck_cmd = {}; + u8 cmd_ver = iwl_fw_lookup_cmd_ver(mld->fw, WOWLAN_KEK_KCK_MATERIAL, 4); + struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {}; struct iwl_mld_rekey_data *rekey_data = &mld_vif->wowlan_data.rekey_data; + u32 cmd_size = cmd_ver == 5 ? sizeof(kek_kck_cmd) : + sizeof(struct iwl_wowlan_kek_kck_material_cmd_v4); memcpy(kek_kck_cmd.kck, rekey_data->kck, rekey_data->kck_len); @@ -1855,7 +1918,7 @@ iwl_mld_send_kek_kck_cmd(struct iwl_mld *mld, rekey_data->akm); return iwl_mld_send_cmd_pdu(mld, WOWLAN_KEK_KCK_MATERIAL, - &kek_kck_cmd); + &kek_kck_cmd, cmd_size); } static int From 0d91e1d069fa5740d23e9a1f47d36279f50b699b Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Thu, 1 Oct 2026 16:20:27 +0300 Subject: [PATCH 1613/2126] wifi: iwlwifi: don't mask ucode_ver in iwl_sar_geo_support() All the firmwares used by iwlmvm and iwlmld set IWL_UCODE_TLV_API_NEW_VERSION. Since iwl_sar_geo_support is not called by iwldvm, simplify the ucode_ver check. No functional change intended. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Link: https://patch.msgid.link/20261001161715.5e290d456f51.Ic33c983411e93201e5e05a9d3df5af524de09b9a@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/fw/regulatory.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c index c7de45323935..b6707312c188 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/regulatory.c @@ -199,21 +199,22 @@ static const struct dmi_system_id dmi_tas_approved_list[] = { bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt) { + u32 ucode_ver = fwrt->fw->ucode_ver; + /* * The PER_CHAIN_LIMIT_OFFSET_CMD command is not supported on * earlier firmware versions. Unfortunately, we don't have a - * TLV API flag to rely on, so rely on the major version which - * is in the first byte of ucode_ver. This was implemented - * initially on version 38 and then backported to 17. It was - * also backported to 29, but only for 7265D devices. The - * intention was to have it in 36 as well, but not all 8000 - * family got this feature enabled. The 8000 family is the - * only one using version 36, so skip this version entirely. + * TLV API flag to rely on, so rely on the ucode version. This + * was implemented initially on version 38 and then backported + * to 17. It was also backported to 29, but only for 7265D + * devices. The intention was to have it in 36 as well, but not + * all 8000 family got this feature enabled. The 8000 family is + * the only one using version 36, so skip this version entirely. */ - return IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) >= 38 || - (IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 17 && + return ucode_ver >= 38 || + (ucode_ver == 17 && fwrt->trans->info.hw_rev != CSR_HW_REV_TYPE_3160) || - (IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 29 && + (ucode_ver == 29 && ((fwrt->trans->info.hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_7265D)); } From c20947271de1ed5d62b8c62429eaaf1fb1cc71f0 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 1 Oct 2026 16:20:28 +0300 Subject: [PATCH 1614/2126] wifi: iwlwifi: dbg: validate the index before accessing an array If the worker index is bad, then the pointer to the containing array cannot be determined. Avoid it, and just make it a WARN_ONCE() since it should never happen. Signed-off-by: Johannes Berg Link: https://patch.msgid.link/20261001161715.dd857cfe0d6b.I8162af7b34d03b1b30be5914cde6248ad84b6a9f@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 1d34ad59bb71..e29c58575859 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -2304,8 +2304,13 @@ void iwl_fw_error_dump_wk(struct work_struct *work) { struct iwl_fwrt_wk_data *wks = container_of(work, typeof(*wks), wk.work); - struct iwl_fw_runtime *fwrt = - container_of(wks, typeof(*fwrt), dump.wks[wks->idx]); + struct iwl_fw_runtime *fwrt; + + if (WARN_ONCE(wks->idx >= IWL_FW_RUNTIME_DUMP_WK_NUM, + "invalid worker index %d\n", wks->idx)) + return; + + fwrt = container_of(wks, typeof(*fwrt), dump.wks[wks->idx]); /* assumes the op mode mutex is locked in dump_start since * iwl_fw_dbg_collect_sync can't run in parallel From f4cc1930a78ff5d106ffa30f81898c13300057c3 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sun, 11 Oct 2026 14:07:02 +0300 Subject: [PATCH 1615/2126] wifi: iwlwifi: bump maximum core version for BZ/SC/DR to 109 Start supporting Core 109 FW on these devices. Reviewed-by: Emmanuel Grumbach Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.603d3010fb29.I53bc9bf1f5931e573fd55b62eef8be16270e6a92@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/cfg/bz.c | 2 +- drivers/net/wireless/intel/iwlwifi/cfg/dr.c | 2 +- drivers/net/wireless/intel/iwlwifi/cfg/sc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/bz.c b/drivers/net/wireless/intel/iwlwifi/cfg/bz.c index 3cc3ffd0aa1c..f6e0f0c8a82e 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/bz.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/bz.c @@ -10,7 +10,7 @@ #include "fw/api/txq.h" /* Highest firmware core release supported */ -#define IWL_BZ_UCODE_CORE_MAX 108 +#define IWL_BZ_UCODE_CORE_MAX 109 /* Lowest firmware core release supported */ #define IWL_BZ_UCODE_CORE_MIN 102 diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/dr.c b/drivers/net/wireless/intel/iwlwifi/cfg/dr.c index f6dd1f9733fb..f62a0bf29754 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/dr.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/dr.c @@ -9,7 +9,7 @@ #include "fw/api/txq.h" /* Highest firmware core release supported */ -#define IWL_DR_UCODE_CORE_MAX 108 +#define IWL_DR_UCODE_CORE_MAX 109 /* Lowest firmware core release supported */ #define IWL_DR_UCODE_CORE_MIN 102 diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/sc.c b/drivers/net/wireless/intel/iwlwifi/cfg/sc.c index 467888c8d2cb..220b0d181f42 100644 --- a/drivers/net/wireless/intel/iwlwifi/cfg/sc.c +++ b/drivers/net/wireless/intel/iwlwifi/cfg/sc.c @@ -10,7 +10,7 @@ #include "fw/api/txq.h" /* Highest firmware core release supported */ -#define IWL_SC_UCODE_CORE_MAX 108 +#define IWL_SC_UCODE_CORE_MAX 109 /* Lowest firmware core release supported */ #define IWL_SC_UCODE_CORE_MIN 102 From a2f60db1c1514c7d083b5c0c8b9510b1adf0cc2c Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Sun, 11 Oct 2026 14:07:03 +0300 Subject: [PATCH 1616/2126] wifi: iwlwifi: mvm: fix the VHT MCS sent to a v1 firmware When converting a v3 rate to the v1 format, the MCS index was read from the mask of the NSS field and written into the mask of the MCS field. This is obviously wrong, we must not mix the NSS and the MCS. Fixes: 3592c0083fb2 ("wifi: iwlwifi: mvm: fix beacon template/fixed rate") Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.dfca0c8b560a.I7a3e1f0e91f0d0c6f4c5f1e6a33dc7c0c5e9ad11@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/utils.c b/drivers/net/wireless/intel/iwlwifi/mvm/utils.c index e97ab2c9e5ba..b2f34d1f2c48 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/utils.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/utils.c @@ -1356,8 +1356,8 @@ __le32 iwl_mvm_v3_rate_to_fw(u32 rate, u8 rate_ver) case RATE_MCS_MOD_TYPE_VHT: result = RATE_MCS_VHT_MSK_V1; result |= u32_encode_bits(u32_get_bits(rate, - RATE_VHT_MCS_NSS_MSK), - RATE_MCS_CODE_MSK); + RATE_MCS_CODE_MSK), + RATE_VHT_MCS_RATE_CODE_MSK); result |= u32_encode_bits(u32_get_bits(rate, RATE_MCS_NSS_MSK), RATE_VHT_MCS_NSS_MSK); break; From 40a0b9f3ac2c28eb85bcb4e6433c879d3a3e14b3 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:04 +0300 Subject: [PATCH 1617/2126] wifi: iwlwifi: fw: api: fix D3 sequence counter docs Most sequence counters in WoWLAN are documented as "to use next", but in reality firmware treats them as "last used". Fix the docs accordingly, while at it noting that for newer versions it only applies to the offload TID. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.5d17b80be44c.Ia3ec5e1f714029561b08ab659b116bc20a60beb3@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/fw/api/d3.h | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h index c469ea965157..327a8c05f4db 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/d3.h @@ -373,9 +373,9 @@ enum iwl_wowlan_flags { /** * struct iwl_wowlan_config_cmd_v6 - WoWLAN configuration (versions 5 and 6) * @wakeup_filter: filter from &enum iwl_wowlan_wakeup_filters - * @non_qos_seq: non-QoS sequence counter to use next. + * @non_qos_seq: last used non-QoS sequence counter. * Reserved if the struct has version >= 6. - * @qos_seq: QoS sequence counters to use next + * @qos_seq: last used QoS sequence counters * @wowlan_ba_teardown_tids: bitmap of BA sessions to tear down * @is_11n_connection: indicates HT connection * @offloading_tid: TID reserved for firmware use @@ -732,8 +732,8 @@ struct iwl_wowlan_igtk_status { * @gtk: GTK data * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched pattern - * @non_qos_seq_ctr: non-QoS sequence counter to use next - * @qos_seq_ctr: QoS sequence counters to use next + * @non_qos_seq_ctr: last used non-QoS sequence counter + * @qos_seq_ctr: last used QoS sequence counters * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets @@ -763,8 +763,8 @@ struct iwl_wowlan_status_v6 { * @igtk: IGTK data * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched pattern - * @non_qos_seq_ctr: non-QoS sequence counter to use next - * @qos_seq_ctr: QoS sequence counters to use next + * @non_qos_seq_ctr: last used non-QoS sequence counter + * @qos_seq_ctr: last used QoS sequence counters * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets @@ -796,7 +796,7 @@ struct iwl_wowlan_status_v7 { * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched patterns * @reserved1: reserved - * @qos_seq_ctr: QoS sequence counters to use next + * @qos_seq_ctr: last used QoS sequence counters * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets @@ -882,7 +882,7 @@ struct iwl_wowlan_mlo_gtk { * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched patterns * @reserved1: reserved - * @qos_seq_ctr: QoS sequence counters to use next + * @qos_seq_ctr: last used QoS sequence counters * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets @@ -916,7 +916,7 @@ struct iwl_wowlan_info_notif_v3 { * @bigtk: BIGTK data * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched patterns - * @qos_seq_ctr: QoS sequence counters to use next + * @qos_seq_ctr: last used QoS sequence counter for @tid_offloaded_tx * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets @@ -955,7 +955,7 @@ struct iwl_wowlan_info_notif_v5 { * @bigtk: BIGTK data * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched patterns - * @qos_seq_ctr: QoS sequence counters to use next + * @qos_seq_ctr: last used QoS sequence counter for @tid_offloaded_tx * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets @@ -995,7 +995,7 @@ struct iwl_wowlan_info_notif_v6 { * @cigtk: CIGTK data * @replay_ctr: GTK rekey replay counter * @pattern_number: number of the matched patterns - * @qos_seq_ctr: QoS sequence counters to use next + * @qos_seq_ctr: last used QoS sequence counter for @tid_offloaded_tx * @wakeup_reasons: wakeup reasons, see &enum iwl_wowlan_wakeup_reason * @num_of_gtk_rekeys: number of GTK rekeys * @transmitted_ndps: number of transmitted neighbor discovery packets From 4f823509afa84ae785d9f7440ef01f496bd36345 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sun, 11 Oct 2026 14:07:05 +0300 Subject: [PATCH 1618/2126] wifi: iwlwifi: move context info APIs to a separate file Context info structures and enums are APIs. While they have only been used in pcie bus until now, part of those will be used for future bus types as well. Extract the APIs from pcie/iwl-context-info*.h to fw/api/context-info*.h. Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.87b73a7de1e5.I5e526d01b560a277bc363b3f1b42dcb63d51c574@changeid Signed-off-by: Miri Korenblit --- .../intel/iwlwifi/fw/api/ctxt-info-v2.h | 328 ++++++++++++++++++ .../wireless/intel/iwlwifi/fw/api/ctxt-info.h | 185 ++++++++++ .../intel/iwlwifi/pcie/iwl-context-info-v2.h | 320 +---------------- .../intel/iwlwifi/pcie/iwl-context-info.h | 177 +--------- 4 files changed, 517 insertions(+), 493 deletions(-) create mode 100644 drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info-v2.h create mode 100644 drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info.h diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info-v2.h b/drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info-v2.h new file mode 100644 index 000000000000..dd2ca1949735 --- /dev/null +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info-v2.h @@ -0,0 +1,328 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* + * Copyright (C) 2026 Intel Corporation + */ +#ifndef __iwl_fw_api_context_info_v2_h__ +#define __iwl_fw_api_context_info_v2_h__ + +#include +#include +#include "ctxt-info.h" + +/* CSR addresses used by context info v2 */ +#define CSR_CTXT_INFO_BOOT_CTRL 0x0 +#define CSR_CTXT_INFO_ADDR 0x118 +#define CSR_IML_DATA_ADDR 0x120 +#define CSR_IML_SIZE_ADDR 0x128 +#define CSR_IML_RESP_ADDR 0x12c + +#define UNFRAGMENTED_PNVM_PAYLOADS_NUMBER 2 + +/* Set bit for enabling automatic function boot */ +#define CSR_AUTO_FUNC_BOOT_ENA BIT(1) +/* Set bit for initiating function boot */ +#define CSR_AUTO_FUNC_INIT BIT(7) + +/** + * enum iwl_prph_scratch_mtr_format - tfd size configuration + * @IWL_PRPH_MTR_FORMAT_16B: 16 bit tfd + * @IWL_PRPH_MTR_FORMAT_32B: 32 bit tfd + * @IWL_PRPH_MTR_FORMAT_64B: 64 bit tfd + * @IWL_PRPH_MTR_FORMAT_256B: 256 bit tfd + */ +enum iwl_prph_scratch_mtr_format { + IWL_PRPH_MTR_FORMAT_16B = 0x0, + IWL_PRPH_MTR_FORMAT_32B = 0x40000, + IWL_PRPH_MTR_FORMAT_64B = 0x80000, + IWL_PRPH_MTR_FORMAT_256B = 0xC0000, +}; + +/** + * enum iwl_prph_scratch_flags - PRPH scratch control flags + * @IWL_PRPH_SCRATCH_IMR_DEBUG_EN: IMR support for debug + * @IWL_PRPH_SCRATCH_EARLY_DEBUG_EN: enable early debug conf + * @IWL_PRPH_SCRATCH_EDBG_DEST_DRAM: use DRAM, with size allocated + * in hwm config. + * @IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL: use buffer on SRAM + * @IWL_PRPH_SCRATCH_EDBG_DEST_ST_ARBITER: use st arbiter, mainly for + * multicomm. + * @IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF: route debug data to SoC HW + * @IWL_PRPH_SCRATCH_RB_SIZE_4K: Use 4K RB size (the default is 2K) + * @IWL_PRPH_SCRATCH_MTR_MODE: format used for completion - 0: for + * completion descriptor, 1 for responses (legacy) + * @IWL_PRPH_SCRATCH_MTR_FORMAT: a mask for the size of the tfd. + * There are 4 optional values: 0: 16 bit, 1: 32 bit, 2: 64 bit, + * 3: 256 bit. + * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_MASK: RB size full information, ignored + * by older firmware versions, so set IWL_PRPH_SCRATCH_RB_SIZE_4K + * appropriately; use the below values for this. + * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K: 8kB RB size + * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K: 12kB RB size + * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K: 16kB RB size + * @IWL_PRPH_SCRATCH_SCU_FORCE_ACTIVE: Indicate fw to set SCU_FORCE_ACTIVE + * upon reset. + * @IWL_PRPH_SCRATCH_TOP_RESET: request TOP reset + */ +enum iwl_prph_scratch_flags { + IWL_PRPH_SCRATCH_IMR_DEBUG_EN = BIT(1), + IWL_PRPH_SCRATCH_EARLY_DEBUG_EN = BIT(4), + IWL_PRPH_SCRATCH_EDBG_DEST_DRAM = BIT(8), + IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL = BIT(9), + IWL_PRPH_SCRATCH_EDBG_DEST_ST_ARBITER = BIT(10), + IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF = BIT(11), + IWL_PRPH_SCRATCH_RB_SIZE_4K = BIT(16), + IWL_PRPH_SCRATCH_MTR_MODE = BIT(17), + IWL_PRPH_SCRATCH_MTR_FORMAT = BIT(18) | BIT(19), + IWL_PRPH_SCRATCH_RB_SIZE_EXT_MASK = 0xf << 20, + IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K = 8 << 20, + IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K = 9 << 20, + IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K = 10 << 20, + IWL_PRPH_SCRATCH_SCU_FORCE_ACTIVE = BIT(29), + IWL_PRPH_SCRATCH_TOP_RESET = BIT(30), +}; + +/** + * enum iwl_prph_scratch_ext_flags - PRPH scratch control ext flags + * @IWL_PRPH_SCRATCH_EXT_EXT_FSEQ: external FSEQ image provided + * @IWL_PRPH_SCRATCH_EXT_URM_FW: switch to URM mode based on fw setting + * @IWL_PRPH_SCRATCH_EXT_URM_PERM: switch to permanent URM mode + * @IWL_PRPH_SCRATCH_EXT_32KHZ_CLK_VALID: use external 32 KHz clock + */ +enum iwl_prph_scratch_ext_flags { + IWL_PRPH_SCRATCH_EXT_EXT_FSEQ = BIT(0), + IWL_PRPH_SCRATCH_EXT_URM_FW = BIT(4), + IWL_PRPH_SCRATCH_EXT_URM_PERM = BIT(5), + IWL_PRPH_SCRATCH_EXT_32KHZ_CLK_VALID = BIT(8), +}; + +/** + * struct iwl_prph_scratch_version - version structure + * @mac_id: SKU and revision id + * @version: prph scratch information version id + * @size: the size of the context information in DWs + * @reserved: reserved + */ +struct iwl_prph_scratch_version { + __le16 mac_id; + __le16 version; + __le16 size; + __le16 reserved; +} __packed; /* PERIPH_SCRATCH_VERSION_S */ + +/** + * struct iwl_prph_scratch_control - control structure + * @control_flags: context information flags see &enum iwl_prph_scratch_flags + * @control_flags_ext: context information for extended flags, + * see &enum iwl_prph_scratch_ext_flags + */ +struct iwl_prph_scratch_control { + __le32 control_flags; + __le32 control_flags_ext; +} __packed; /* PERIPH_SCRATCH_CONTROL_S */ + +/** + * struct iwl_prph_scratch_pnvm_cfg - PNVM scratch + * @pnvm_base_addr: PNVM start address + * @pnvm_size: the size of the PNVM image in bytes + * @reserved: reserved + */ +struct iwl_prph_scratch_pnvm_cfg { + __le64 pnvm_base_addr; + __le32 pnvm_size; + __le32 reserved; +} __packed; /* PERIPH_SCRATCH_PNVM_CFG_S */ + +/** + * struct iwl_prph_scratch_mem_desc_addr_array - DRAM + * @mem_descs: array of dram addresses. + * Each address is the beginning of a PNVM payload. + */ +struct iwl_prph_scratch_mem_desc_addr_array { + __le64 mem_descs[IPC_DRAM_MAP_ENTRY_NUM_MAX]; +} __packed; /* PERIPH_SCRATCH_MEM_DESC_ADDR_ARRAY_S_VER_1 */ + +/** + * struct iwl_prph_scratch_hwm_cfg - hwm config + * @hwm_base_addr: hwm start address + * @hwm_size: hwm size in DWs + * @debug_token_config: debug preset + */ +struct iwl_prph_scratch_hwm_cfg { + __le64 hwm_base_addr; + __le32 hwm_size; + __le32 debug_token_config; +} __packed; /* PERIPH_SCRATCH_HWM_CFG_S */ + +/** + * struct iwl_prph_scratch_rbd_cfg - RBDs configuration + * @free_rbd_addr: default queue free RB CB base address + * @reserved: reserved + */ +struct iwl_prph_scratch_rbd_cfg { + __le64 free_rbd_addr; + __le32 reserved; +} __packed; /* PERIPH_SCRATCH_RBD_CFG_S */ + +/** + * struct iwl_prph_scratch_uefi_cfg - prph scratch reduce power table + * @base_addr: reduce power table address + * @size: the size of the entire power table image + * @reserved: (reserved) + */ +struct iwl_prph_scratch_uefi_cfg { + __le64 base_addr; + __le32 size; + __le32 reserved; +} __packed; /* PERIPH_SCRATCH_UEFI_CFG_S */ + +/** + * struct iwl_prph_scratch_step_cfg - prph scratch step configuration + * @mbx_addr_0: [0:7] revision, + * [8:15] cnvi_to_cnvr length, + * [16:23] cnvr_to_cnvi channel length, + * [24:31] radio1 reserved + * @mbx_addr_1: [0:7] radio2 reserved + */ +struct iwl_prph_scratch_step_cfg { + __le32 mbx_addr_0; + __le32 mbx_addr_1; +} __packed; + +/** + * struct iwl_prph_scratch_ctrl_cfg - prph scratch ctrl and config + * @version: version information of context info and HW + * @control: control flags of FH configurations + * @pnvm_cfg: ror configuration + * @hwm_cfg: hwm configuration + * @rbd_cfg: default RX queue configuration + * @reduce_power_cfg: UEFI power reduction table + * @step_cfg: step configuration + */ +struct iwl_prph_scratch_ctrl_cfg { + struct iwl_prph_scratch_version version; + struct iwl_prph_scratch_control control; + struct iwl_prph_scratch_pnvm_cfg pnvm_cfg; + struct iwl_prph_scratch_hwm_cfg hwm_cfg; + struct iwl_prph_scratch_rbd_cfg rbd_cfg; + struct iwl_prph_scratch_uefi_cfg reduce_power_cfg; + struct iwl_prph_scratch_step_cfg step_cfg; +} __packed; /* PERIPH_SCRATCH_CTRL_CFG_S */ + +/** + * struct iwl_context_info_v2 - device INIT configuration + * @version: version of the context information + * @size: size of context information in DWs + * @config: context in which the peripheral would execute - a subset of + * capability csr register published by the peripheral + * @prph_info_base_addr: the peripheral information structure start address + * @cr_head_idx_arr_base_addr: the completion ring head index array + * start address + * @tr_tail_idx_arr_base_addr: the transfer ring tail index array + * start address + * @cr_tail_idx_arr_base_addr: the completion ring tail index array + * start address + * @tr_head_idx_arr_base_addr: the transfer ring head index array + * start address + * @cr_idx_arr_size: number of entries in the completion ring index array + * @tr_idx_arr_size: number of entries in the transfer ring index array + * @mtr_base_addr: the message transfer ring start address + * @mcr_base_addr: the message completion ring start address + * @mtr_size: number of entries which the message transfer ring can hold + * @mcr_size: number of entries which the message completion ring can hold + * @mtr_doorbell_vec: the doorbell vector associated with the message + * transfer ring + * @mcr_doorbell_vec: the doorbell vector associated with the message + * completion ring + * @mtr_msi_vec: the MSI which shall be generated by the peripheral after + * completing a transfer descriptor in the message transfer ring + * @mcr_msi_vec: the MSI which shall be generated by the peripheral after + * completing a completion descriptor in the message completion ring + * @mtr_opt_header_size: the size of the optional header in the transfer + * descriptor associated with the message transfer ring in DWs + * @mtr_opt_footer_size: the size of the optional footer in the transfer + * descriptor associated with the message transfer ring in DWs + * @mcr_opt_header_size: the size of the optional header in the completion + * descriptor associated with the message completion ring in DWs + * @mcr_opt_footer_size: the size of the optional footer in the completion + * descriptor associated with the message completion ring in DWs + * @msg_rings_ctrl_flags: message rings control flags + * @prph_info_msi_vec: the MSI which shall be generated by the peripheral + * after updating the Peripheral Information structure + * @prph_scratch_base_addr: the peripheral scratch structure start address + * @prph_scratch_size: the size of the peripheral scratch structure in DWs + * @reserved: reserved + */ +struct iwl_context_info_v2 { + __le16 version; + __le16 size; + __le32 config; + __le64 prph_info_base_addr; + __le64 cr_head_idx_arr_base_addr; + __le64 tr_tail_idx_arr_base_addr; + __le64 cr_tail_idx_arr_base_addr; + __le64 tr_head_idx_arr_base_addr; + __le16 cr_idx_arr_size; + __le16 tr_idx_arr_size; + __le64 mtr_base_addr; + __le64 mcr_base_addr; + __le16 mtr_size; + __le16 mcr_size; + __le16 mtr_doorbell_vec; + __le16 mcr_doorbell_vec; + __le16 mtr_msi_vec; + __le16 mcr_msi_vec; + u8 mtr_opt_header_size; + u8 mtr_opt_footer_size; + u8 mcr_opt_header_size; + u8 mcr_opt_footer_size; + __le16 msg_rings_ctrl_flags; + __le16 prph_info_msi_vec; + __le64 prph_scratch_base_addr; + __le32 prph_scratch_size; + __le32 reserved; +} __packed; /* IPC_CONTEXT_INFO_S */ + +#define IWL_NUM_DRAM_FSEQ_ENTRIES 8 + +/** + * struct iwl_context_info_dram_fseq - images DRAM map (with fseq) + * each entry in the map represents a DRAM chunk of up to 32 KB + * @common: UMAC/LMAC/virtual images + * @fseq_img: FSEQ image DRAM map + */ +struct iwl_context_info_dram_fseq { + struct iwl_context_info_dram_nonfseq common; + __le64 fseq_img[IWL_NUM_DRAM_FSEQ_ENTRIES]; +} __packed; /* PERIPH_SCRATCH_DRAM_MAP_S */ + +/** + * struct iwl_prph_scratch - peripheral scratch mapping + * @ctrl_cfg: control and configuration of prph scratch + * @dram: firmware images addresses in DRAM + * @fseq_override: FSEQ override parameters + * @step_analog_params: STEP analog calibration values + * @reserved: reserved + */ +struct iwl_prph_scratch { + struct iwl_prph_scratch_ctrl_cfg ctrl_cfg; + __le32 fseq_override; + __le32 step_analog_params; + __le32 reserved[8]; + struct iwl_context_info_dram_fseq dram; +} __packed; /* PERIPH_SCRATCH_S */ + +/** + * struct iwl_prph_info - peripheral information + * @boot_stage_mirror: reflects the value in the Boot Stage CSR register + * @ipc_status_mirror: reflects the value in the IPC Status CSR register + * @sleep_notif: indicates the peripheral sleep status + * @reserved: reserved + */ +struct iwl_prph_info { + __le32 boot_stage_mirror; + __le32 ipc_status_mirror; + __le32 sleep_notif; + __le32 reserved; +} __packed; /* PERIPH_INFO_S */ + +#endif /* __iwl_fw_api_context_info_v2_h__ */ diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info.h b/drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info.h new file mode 100644 index 000000000000..40a087b22150 --- /dev/null +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/ctxt-info.h @@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* + * Copyright (C) 2026 Intel Corporation + */ +#ifndef __iwl_fw_api_context_info_h__ +#define __iwl_fw_api_context_info_h__ + +#include + +/* maximum number of DRAM map entries supported by FW */ +#define IWL_MAX_DRAM_ENTRY 64 +#define CSR_CTXT_INFO_BA 0x40 + +/** + * enum iwl_context_info_flags - Context information control flags + * @IWL_CTXT_INFO_AUTO_FUNC_INIT: If set, FW will not wait before interrupting + * the init done for driver command that configures several system modes + * @IWL_CTXT_INFO_EARLY_DEBUG: enable early debug + * @IWL_CTXT_INFO_ENABLE_CDMP: enable core dump + * @IWL_CTXT_INFO_RB_CB_SIZE: mask of the RBD Cyclic Buffer Size + * exponent, the actual size is 2**value, valid sizes are 8-2048. + * The value is four bits long. Maximum valid exponent is 12 + * @IWL_CTXT_INFO_TFD_FORMAT_LONG: use long TFD Format (the + * default is short format - not supported by the driver) + * @IWL_CTXT_INFO_RB_SIZE: RB size mask + * (values are IWL_CTXT_INFO_RB_SIZE_*K) + * @IWL_CTXT_INFO_RB_SIZE_1K: Value for 1K RB size + * @IWL_CTXT_INFO_RB_SIZE_2K: Value for 2K RB size + * @IWL_CTXT_INFO_RB_SIZE_4K: Value for 4K RB size + * @IWL_CTXT_INFO_RB_SIZE_8K: Value for 8K RB size + * @IWL_CTXT_INFO_RB_SIZE_12K: Value for 12K RB size + * @IWL_CTXT_INFO_RB_SIZE_16K: Value for 16K RB size + * @IWL_CTXT_INFO_RB_SIZE_20K: Value for 20K RB size + * @IWL_CTXT_INFO_RB_SIZE_24K: Value for 24K RB size + * @IWL_CTXT_INFO_RB_SIZE_28K: Value for 28K RB size + * @IWL_CTXT_INFO_RB_SIZE_32K: Value for 32K RB size + */ +enum iwl_context_info_flags { + IWL_CTXT_INFO_AUTO_FUNC_INIT = 0x0001, + IWL_CTXT_INFO_EARLY_DEBUG = 0x0002, + IWL_CTXT_INFO_ENABLE_CDMP = 0x0004, + IWL_CTXT_INFO_RB_CB_SIZE = 0x00f0, + IWL_CTXT_INFO_TFD_FORMAT_LONG = 0x0100, + IWL_CTXT_INFO_RB_SIZE = 0x1e00, + IWL_CTXT_INFO_RB_SIZE_1K = 0x1, + IWL_CTXT_INFO_RB_SIZE_2K = 0x2, + IWL_CTXT_INFO_RB_SIZE_4K = 0x4, + IWL_CTXT_INFO_RB_SIZE_8K = 0x8, + IWL_CTXT_INFO_RB_SIZE_12K = 0x9, + IWL_CTXT_INFO_RB_SIZE_16K = 0xa, + IWL_CTXT_INFO_RB_SIZE_20K = 0xb, + IWL_CTXT_INFO_RB_SIZE_24K = 0xc, + IWL_CTXT_INFO_RB_SIZE_28K = 0xd, + IWL_CTXT_INFO_RB_SIZE_32K = 0xe, +}; + +/** + * struct iwl_context_info_version - version structure + * @mac_id: SKU and revision id + * @version: context information version id + * @size: the size of the context information in DWs + * @reserved: (reserved) + */ +struct iwl_context_info_version { + __le16 mac_id; + __le16 version; + __le16 size; + __le16 reserved; +} __packed; + +/** + * struct iwl_context_info_control - version structure + * @control_flags: context information flags see &enum iwl_context_info_flags + * @reserved: (reserved) + */ +struct iwl_context_info_control { + __le32 control_flags; + __le32 reserved; +} __packed; + +/** + * struct iwl_context_info_dram_nonfseq - images DRAM map + * each entry in the map represents a DRAM chunk of up to 32 KB + * @umac_img: UMAC image DRAM map + * @lmac_img: LMAC image DRAM map + * @virtual_img: paged image DRAM map + */ +struct iwl_context_info_dram_nonfseq { + __le64 umac_img[IWL_MAX_DRAM_ENTRY]; + __le64 lmac_img[IWL_MAX_DRAM_ENTRY]; + __le64 virtual_img[IWL_MAX_DRAM_ENTRY]; +} __packed; + +/** + * struct iwl_context_info_rbd_cfg - RBDs configuration + * @free_rbd_addr: default queue free RB CB base address + * @used_rbd_addr: default queue used RB CB base address + * @status_wr_ptr: default queue used RB status write pointer + */ +struct iwl_context_info_rbd_cfg { + __le64 free_rbd_addr; + __le64 used_rbd_addr; + __le64 status_wr_ptr; +} __packed; + +/** + * struct iwl_context_info_hcmd_cfg - command queue configuration + * @cmd_queue_addr: address of command queue + * @cmd_queue_size: number of entries + * @reserved: (reserved) + */ +struct iwl_context_info_hcmd_cfg { + __le64 cmd_queue_addr; + u8 cmd_queue_size; + u8 reserved[7]; +} __packed; + +/** + * struct iwl_context_info_dump_cfg - Core Dump configuration + * @core_dump_addr: core dump (debug DRAM address) start address + * @core_dump_size: size, in DWs + * @reserved: (reserved) + */ +struct iwl_context_info_dump_cfg { + __le64 core_dump_addr; + __le32 core_dump_size; + __le32 reserved; +} __packed; + +/** + * struct iwl_context_info_pnvm_cfg - platform NVM data configuration + * @platform_nvm_addr: Platform NVM data start address + * @platform_nvm_size: size in DWs + * @reserved: (reserved) + */ +struct iwl_context_info_pnvm_cfg { + __le64 platform_nvm_addr; + __le32 platform_nvm_size; + __le32 reserved; +} __packed; + +/** + * struct iwl_context_info_early_dbg_cfg - early debug configuration for + * dumping DRAM addresses + * @early_debug_addr: early debug start address + * @early_debug_size: size in DWs + * @reserved: (reserved) + */ +struct iwl_context_info_early_dbg_cfg { + __le64 early_debug_addr; + __le32 early_debug_size; + __le32 reserved; +} __packed; + +/** + * struct iwl_context_info - device INIT configuration + * @version: version information of context info and HW + * @control: control flags of FH configurations + * @reserved0: (reserved) + * @rbd_cfg: default RX queue configuration + * @hcmd_cfg: command queue configuration + * @reserved1: (reserved) + * @dump_cfg: core dump data + * @edbg_cfg: early debug configuration + * @pnvm_cfg: platform nvm configuration + * @reserved2: (reserved) + * @dram: firmware image addresses in DRAM + * @reserved3: (reserved) + */ +struct iwl_context_info { + struct iwl_context_info_version version; + struct iwl_context_info_control control; + __le64 reserved0; + struct iwl_context_info_rbd_cfg rbd_cfg; + struct iwl_context_info_hcmd_cfg hcmd_cfg; + __le32 reserved1[4]; + struct iwl_context_info_dump_cfg dump_cfg; + struct iwl_context_info_early_dbg_cfg edbg_cfg; + struct iwl_context_info_pnvm_cfg pnvm_cfg; + __le32 reserved2[16]; + struct iwl_context_info_dram_nonfseq dram; + __le32 reserved3[16]; +} __packed; /* BOOT_LOADER_CONTEXT_INFO_S */ + +#endif /* __iwl_fw_api_context_info_h__ */ diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h b/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h index 416baadc5017..a50e80cccadb 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info-v2.h @@ -1,327 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2018, 2020-2025 Intel Corporation + * Copyright (C) 2018, 2020-2026 Intel Corporation */ #ifndef __iwl_context_info_file_v2_h__ #define __iwl_context_info_file_v2_h__ -#include "iwl-context-info.h" - -#define CSR_CTXT_INFO_BOOT_CTRL 0x0 -#define CSR_CTXT_INFO_ADDR 0x118 -#define CSR_IML_DATA_ADDR 0x120 -#define CSR_IML_SIZE_ADDR 0x128 -#define CSR_IML_RESP_ADDR 0x12c - -#define UNFRAGMENTED_PNVM_PAYLOADS_NUMBER 2 - -/* Set bit for enabling automatic function boot */ -#define CSR_AUTO_FUNC_BOOT_ENA BIT(1) -/* Set bit for initiating function boot */ -#define CSR_AUTO_FUNC_INIT BIT(7) - -/** - * enum iwl_prph_scratch_mtr_format - tfd size configuration - * @IWL_PRPH_MTR_FORMAT_16B: 16 bit tfd - * @IWL_PRPH_MTR_FORMAT_32B: 32 bit tfd - * @IWL_PRPH_MTR_FORMAT_64B: 64 bit tfd - * @IWL_PRPH_MTR_FORMAT_256B: 256 bit tfd - */ -enum iwl_prph_scratch_mtr_format { - IWL_PRPH_MTR_FORMAT_16B = 0x0, - IWL_PRPH_MTR_FORMAT_32B = 0x40000, - IWL_PRPH_MTR_FORMAT_64B = 0x80000, - IWL_PRPH_MTR_FORMAT_256B = 0xC0000, -}; - -/** - * enum iwl_prph_scratch_flags - PRPH scratch control flags - * @IWL_PRPH_SCRATCH_IMR_DEBUG_EN: IMR support for debug - * @IWL_PRPH_SCRATCH_EARLY_DEBUG_EN: enable early debug conf - * @IWL_PRPH_SCRATCH_EDBG_DEST_DRAM: use DRAM, with size allocated - * in hwm config. - * @IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL: use buffer on SRAM - * @IWL_PRPH_SCRATCH_EDBG_DEST_ST_ARBITER: use st arbiter, mainly for - * multicomm. - * @IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF: route debug data to SoC HW - * @IWL_PRPH_SCRATCH_RB_SIZE_4K: Use 4K RB size (the default is 2K) - * @IWL_PRPH_SCRATCH_MTR_MODE: format used for completion - 0: for - * completion descriptor, 1 for responses (legacy) - * @IWL_PRPH_SCRATCH_MTR_FORMAT: a mask for the size of the tfd. - * There are 4 optional values: 0: 16 bit, 1: 32 bit, 2: 64 bit, - * 3: 256 bit. - * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_MASK: RB size full information, ignored - * by older firmware versions, so set IWL_PRPH_SCRATCH_RB_SIZE_4K - * appropriately; use the below values for this. - * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K: 8kB RB size - * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K: 12kB RB size - * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K: 16kB RB size - * @IWL_PRPH_SCRATCH_SCU_FORCE_ACTIVE: Indicate fw to set SCU_FORCE_ACTIVE - * upon reset. - * @IWL_PRPH_SCRATCH_TOP_RESET: request TOP reset - */ -enum iwl_prph_scratch_flags { - IWL_PRPH_SCRATCH_IMR_DEBUG_EN = BIT(1), - IWL_PRPH_SCRATCH_EARLY_DEBUG_EN = BIT(4), - IWL_PRPH_SCRATCH_EDBG_DEST_DRAM = BIT(8), - IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL = BIT(9), - IWL_PRPH_SCRATCH_EDBG_DEST_ST_ARBITER = BIT(10), - IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF = BIT(11), - IWL_PRPH_SCRATCH_RB_SIZE_4K = BIT(16), - IWL_PRPH_SCRATCH_MTR_MODE = BIT(17), - IWL_PRPH_SCRATCH_MTR_FORMAT = BIT(18) | BIT(19), - IWL_PRPH_SCRATCH_RB_SIZE_EXT_MASK = 0xf << 20, - IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K = 8 << 20, - IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K = 9 << 20, - IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K = 10 << 20, - IWL_PRPH_SCRATCH_SCU_FORCE_ACTIVE = BIT(29), - IWL_PRPH_SCRATCH_TOP_RESET = BIT(30), -}; - -/** - * enum iwl_prph_scratch_ext_flags - PRPH scratch control ext flags - * @IWL_PRPH_SCRATCH_EXT_EXT_FSEQ: external FSEQ image provided - * @IWL_PRPH_SCRATCH_EXT_URM_FW: switch to URM mode based on fw setting - * @IWL_PRPH_SCRATCH_EXT_URM_PERM: switch to permanent URM mode - * @IWL_PRPH_SCRATCH_EXT_32KHZ_CLK_VALID: use external 32 KHz clock - */ -enum iwl_prph_scratch_ext_flags { - IWL_PRPH_SCRATCH_EXT_EXT_FSEQ = BIT(0), - IWL_PRPH_SCRATCH_EXT_URM_FW = BIT(4), - IWL_PRPH_SCRATCH_EXT_URM_PERM = BIT(5), - IWL_PRPH_SCRATCH_EXT_32KHZ_CLK_VALID = BIT(8), -}; - -/** - * struct iwl_prph_scratch_version - version structure - * @mac_id: SKU and revision id - * @version: prph scratch information version id - * @size: the size of the context information in DWs - * @reserved: reserved - */ -struct iwl_prph_scratch_version { - __le16 mac_id; - __le16 version; - __le16 size; - __le16 reserved; -} __packed; /* PERIPH_SCRATCH_VERSION_S */ - -/** - * struct iwl_prph_scratch_control - control structure - * @control_flags: context information flags see &enum iwl_prph_scratch_flags - * @control_flags_ext: context information for extended flags, - * see &enum iwl_prph_scratch_ext_flags - */ -struct iwl_prph_scratch_control { - __le32 control_flags; - __le32 control_flags_ext; -} __packed; /* PERIPH_SCRATCH_CONTROL_S */ - -/** - * struct iwl_prph_scratch_pnvm_cfg - PNVM scratch - * @pnvm_base_addr: PNVM start address - * @pnvm_size: the size of the PNVM image in bytes - * @reserved: reserved - */ -struct iwl_prph_scratch_pnvm_cfg { - __le64 pnvm_base_addr; - __le32 pnvm_size; - __le32 reserved; -} __packed; /* PERIPH_SCRATCH_PNVM_CFG_S */ - -/** - * struct iwl_prph_scratch_mem_desc_addr_array - DRAM - * @mem_descs: array of dram addresses. - * Each address is the beginning of a PNVM payload. - */ -struct iwl_prph_scratch_mem_desc_addr_array { - __le64 mem_descs[IPC_DRAM_MAP_ENTRY_NUM_MAX]; -} __packed; /* PERIPH_SCRATCH_MEM_DESC_ADDR_ARRAY_S_VER_1 */ - -/** - * struct iwl_prph_scratch_hwm_cfg - hwm config - * @hwm_base_addr: hwm start address - * @hwm_size: hwm size in DWs - * @debug_token_config: debug preset - */ -struct iwl_prph_scratch_hwm_cfg { - __le64 hwm_base_addr; - __le32 hwm_size; - __le32 debug_token_config; -} __packed; /* PERIPH_SCRATCH_HWM_CFG_S */ - -/** - * struct iwl_prph_scratch_rbd_cfg - RBDs configuration - * @free_rbd_addr: default queue free RB CB base address - * @reserved: reserved - */ -struct iwl_prph_scratch_rbd_cfg { - __le64 free_rbd_addr; - __le32 reserved; -} __packed; /* PERIPH_SCRATCH_RBD_CFG_S */ - -/** - * struct iwl_prph_scratch_uefi_cfg - prph scratch reduce power table - * @base_addr: reduce power table address - * @size: the size of the entire power table image - * @reserved: (reserved) - */ -struct iwl_prph_scratch_uefi_cfg { - __le64 base_addr; - __le32 size; - __le32 reserved; -} __packed; /* PERIPH_SCRATCH_UEFI_CFG_S */ - -/** - * struct iwl_prph_scratch_step_cfg - prph scratch step configuration - * @mbx_addr_0: [0:7] revision, - * [8:15] cnvi_to_cnvr length, - * [16:23] cnvr_to_cnvi channel length, - * [24:31] radio1 reserved - * @mbx_addr_1: [0:7] radio2 reserved - */ - -struct iwl_prph_scratch_step_cfg { - __le32 mbx_addr_0; - __le32 mbx_addr_1; -} __packed; - -/** - * struct iwl_prph_scratch_ctrl_cfg - prph scratch ctrl and config - * @version: version information of context info and HW - * @control: control flags of FH configurations - * @pnvm_cfg: ror configuration - * @hwm_cfg: hwm configuration - * @rbd_cfg: default RX queue configuration - * @reduce_power_cfg: UEFI power reduction table - * @step_cfg: step configuration - */ -struct iwl_prph_scratch_ctrl_cfg { - struct iwl_prph_scratch_version version; - struct iwl_prph_scratch_control control; - struct iwl_prph_scratch_pnvm_cfg pnvm_cfg; - struct iwl_prph_scratch_hwm_cfg hwm_cfg; - struct iwl_prph_scratch_rbd_cfg rbd_cfg; - struct iwl_prph_scratch_uefi_cfg reduce_power_cfg; - struct iwl_prph_scratch_step_cfg step_cfg; -} __packed; /* PERIPH_SCRATCH_CTRL_CFG_S */ - -#define IWL_NUM_DRAM_FSEQ_ENTRIES 8 - -/** - * struct iwl_context_info_dram_fseq - images DRAM map (with fseq) - * each entry in the map represents a DRAM chunk of up to 32 KB - * @common: UMAC/LMAC/virtual images - * @fseq_img: FSEQ image DRAM map - */ -struct iwl_context_info_dram_fseq { - struct iwl_context_info_dram_nonfseq common; - __le64 fseq_img[IWL_NUM_DRAM_FSEQ_ENTRIES]; -} __packed; /* PERIPH_SCRATCH_DRAM_MAP_S */ - -/** - * struct iwl_prph_scratch - peripheral scratch mapping - * @ctrl_cfg: control and configuration of prph scratch - * @dram: firmware images addresses in DRAM - * @fseq_override: FSEQ override parameters - * @step_analog_params: STEP analog calibration values - * @reserved: reserved - */ -struct iwl_prph_scratch { - struct iwl_prph_scratch_ctrl_cfg ctrl_cfg; - __le32 fseq_override; - __le32 step_analog_params; - __le32 reserved[8]; - struct iwl_context_info_dram_fseq dram; -} __packed; /* PERIPH_SCRATCH_S */ - -/** - * struct iwl_prph_info - peripheral information - * @boot_stage_mirror: reflects the value in the Boot Stage CSR register - * @ipc_status_mirror: reflects the value in the IPC Status CSR register - * @sleep_notif: indicates the peripheral sleep status - * @reserved: reserved - */ -struct iwl_prph_info { - __le32 boot_stage_mirror; - __le32 ipc_status_mirror; - __le32 sleep_notif; - __le32 reserved; -} __packed; /* PERIPH_INFO_S */ - -/** - * struct iwl_context_info_v2 - device INIT configuration - * @version: version of the context information - * @size: size of context information in DWs - * @config: context in which the peripheral would execute - a subset of - * capability csr register published by the peripheral - * @prph_info_base_addr: the peripheral information structure start address - * @cr_head_idx_arr_base_addr: the completion ring head index array - * start address - * @tr_tail_idx_arr_base_addr: the transfer ring tail index array - * start address - * @cr_tail_idx_arr_base_addr: the completion ring tail index array - * start address - * @tr_head_idx_arr_base_addr: the transfer ring head index array - * start address - * @cr_idx_arr_size: number of entries in the completion ring index array - * @tr_idx_arr_size: number of entries in the transfer ring index array - * @mtr_base_addr: the message transfer ring start address - * @mcr_base_addr: the message completion ring start address - * @mtr_size: number of entries which the message transfer ring can hold - * @mcr_size: number of entries which the message completion ring can hold - * @mtr_doorbell_vec: the doorbell vector associated with the message - * transfer ring - * @mcr_doorbell_vec: the doorbell vector associated with the message - * completion ring - * @mtr_msi_vec: the MSI which shall be generated by the peripheral after - * completing a transfer descriptor in the message transfer ring - * @mcr_msi_vec: the MSI which shall be generated by the peripheral after - * completing a completion descriptor in the message completion ring - * @mtr_opt_header_size: the size of the optional header in the transfer - * descriptor associated with the message transfer ring in DWs - * @mtr_opt_footer_size: the size of the optional footer in the transfer - * descriptor associated with the message transfer ring in DWs - * @mcr_opt_header_size: the size of the optional header in the completion - * descriptor associated with the message completion ring in DWs - * @mcr_opt_footer_size: the size of the optional footer in the completion - * descriptor associated with the message completion ring in DWs - * @msg_rings_ctrl_flags: message rings control flags - * @prph_info_msi_vec: the MSI which shall be generated by the peripheral - * after updating the Peripheral Information structure - * @prph_scratch_base_addr: the peripheral scratch structure start address - * @prph_scratch_size: the size of the peripheral scratch structure in DWs - * @reserved: reserved - */ -struct iwl_context_info_v2 { - __le16 version; - __le16 size; - __le32 config; - __le64 prph_info_base_addr; - __le64 cr_head_idx_arr_base_addr; - __le64 tr_tail_idx_arr_base_addr; - __le64 cr_tail_idx_arr_base_addr; - __le64 tr_head_idx_arr_base_addr; - __le16 cr_idx_arr_size; - __le16 tr_idx_arr_size; - __le64 mtr_base_addr; - __le64 mcr_base_addr; - __le16 mtr_size; - __le16 mcr_size; - __le16 mtr_doorbell_vec; - __le16 mcr_doorbell_vec; - __le16 mtr_msi_vec; - __le16 mcr_msi_vec; - u8 mtr_opt_header_size; - u8 mtr_opt_footer_size; - u8 mcr_opt_header_size; - u8 mcr_opt_footer_size; - __le16 msg_rings_ctrl_flags; - __le16 prph_info_msi_vec; - __le64 prph_scratch_base_addr; - __le32 prph_scratch_size; - __le32 reserved; -} __packed; /* IPC_CONTEXT_INFO_S */ +#include "fw/api/ctxt-info-v2.h" int iwl_pcie_ctxt_info_v2_alloc(struct iwl_trans *trans, const struct iwl_fw *fw, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info.h b/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info.h index 7ae0fbdef208..562c023cbf2c 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/iwl-context-info.h @@ -1,185 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* * Copyright (C) 2017 Intel Deutschland GmbH - * Copyright (C) 2018-2020, 2022, 2024-2025 Intel Corporation + * Copyright (C) 2018-2020, 2022, 2024-2026 Intel Corporation */ #ifndef __iwl_context_info_file_h__ #define __iwl_context_info_file_h__ -/* maximum number of DRAM map entries supported by FW */ -#define IWL_MAX_DRAM_ENTRY 64 -#define CSR_CTXT_INFO_BA 0x40 - -/** - * enum iwl_context_info_flags - Context information control flags - * @IWL_CTXT_INFO_AUTO_FUNC_INIT: If set, FW will not wait before interrupting - * the init done for driver command that configures several system modes - * @IWL_CTXT_INFO_EARLY_DEBUG: enable early debug - * @IWL_CTXT_INFO_ENABLE_CDMP: enable core dump - * @IWL_CTXT_INFO_RB_CB_SIZE: mask of the RBD Cyclic Buffer Size - * exponent, the actual size is 2**value, valid sizes are 8-2048. - * The value is four bits long. Maximum valid exponent is 12 - * @IWL_CTXT_INFO_TFD_FORMAT_LONG: use long TFD Format (the - * default is short format - not supported by the driver) - * @IWL_CTXT_INFO_RB_SIZE: RB size mask - * (values are IWL_CTXT_INFO_RB_SIZE_*K) - * @IWL_CTXT_INFO_RB_SIZE_1K: Value for 1K RB size - * @IWL_CTXT_INFO_RB_SIZE_2K: Value for 2K RB size - * @IWL_CTXT_INFO_RB_SIZE_4K: Value for 4K RB size - * @IWL_CTXT_INFO_RB_SIZE_8K: Value for 8K RB size - * @IWL_CTXT_INFO_RB_SIZE_12K: Value for 12K RB size - * @IWL_CTXT_INFO_RB_SIZE_16K: Value for 16K RB size - * @IWL_CTXT_INFO_RB_SIZE_20K: Value for 20K RB size - * @IWL_CTXT_INFO_RB_SIZE_24K: Value for 24K RB size - * @IWL_CTXT_INFO_RB_SIZE_28K: Value for 28K RB size - * @IWL_CTXT_INFO_RB_SIZE_32K: Value for 32K RB size - */ -enum iwl_context_info_flags { - IWL_CTXT_INFO_AUTO_FUNC_INIT = 0x0001, - IWL_CTXT_INFO_EARLY_DEBUG = 0x0002, - IWL_CTXT_INFO_ENABLE_CDMP = 0x0004, - IWL_CTXT_INFO_RB_CB_SIZE = 0x00f0, - IWL_CTXT_INFO_TFD_FORMAT_LONG = 0x0100, - IWL_CTXT_INFO_RB_SIZE = 0x1e00, - IWL_CTXT_INFO_RB_SIZE_1K = 0x1, - IWL_CTXT_INFO_RB_SIZE_2K = 0x2, - IWL_CTXT_INFO_RB_SIZE_4K = 0x4, - IWL_CTXT_INFO_RB_SIZE_8K = 0x8, - IWL_CTXT_INFO_RB_SIZE_12K = 0x9, - IWL_CTXT_INFO_RB_SIZE_16K = 0xa, - IWL_CTXT_INFO_RB_SIZE_20K = 0xb, - IWL_CTXT_INFO_RB_SIZE_24K = 0xc, - IWL_CTXT_INFO_RB_SIZE_28K = 0xd, - IWL_CTXT_INFO_RB_SIZE_32K = 0xe, -}; - -/** - * struct iwl_context_info_version - version structure - * @mac_id: SKU and revision id - * @version: context information version id - * @size: the size of the context information in DWs - * @reserved: (reserved) - */ -struct iwl_context_info_version { - __le16 mac_id; - __le16 version; - __le16 size; - __le16 reserved; -} __packed; - -/** - * struct iwl_context_info_control - version structure - * @control_flags: context information flags see &enum iwl_context_info_flags - * @reserved: (reserved) - */ -struct iwl_context_info_control { - __le32 control_flags; - __le32 reserved; -} __packed; - -/** - * struct iwl_context_info_dram_nonfseq - images DRAM map - * each entry in the map represents a DRAM chunk of up to 32 KB - * @umac_img: UMAC image DRAM map - * @lmac_img: LMAC image DRAM map - * @virtual_img: paged image DRAM map - */ -struct iwl_context_info_dram_nonfseq { - __le64 umac_img[IWL_MAX_DRAM_ENTRY]; - __le64 lmac_img[IWL_MAX_DRAM_ENTRY]; - __le64 virtual_img[IWL_MAX_DRAM_ENTRY]; -} __packed; - -/** - * struct iwl_context_info_rbd_cfg - RBDs configuration - * @free_rbd_addr: default queue free RB CB base address - * @used_rbd_addr: default queue used RB CB base address - * @status_wr_ptr: default queue used RB status write pointer - */ -struct iwl_context_info_rbd_cfg { - __le64 free_rbd_addr; - __le64 used_rbd_addr; - __le64 status_wr_ptr; -} __packed; - -/** - * struct iwl_context_info_hcmd_cfg - command queue configuration - * @cmd_queue_addr: address of command queue - * @cmd_queue_size: number of entries - * @reserved: (reserved) - */ -struct iwl_context_info_hcmd_cfg { - __le64 cmd_queue_addr; - u8 cmd_queue_size; - u8 reserved[7]; -} __packed; - -/** - * struct iwl_context_info_dump_cfg - Core Dump configuration - * @core_dump_addr: core dump (debug DRAM address) start address - * @core_dump_size: size, in DWs - * @reserved: (reserved) - */ -struct iwl_context_info_dump_cfg { - __le64 core_dump_addr; - __le32 core_dump_size; - __le32 reserved; -} __packed; - -/** - * struct iwl_context_info_pnvm_cfg - platform NVM data configuration - * @platform_nvm_addr: Platform NVM data start address - * @platform_nvm_size: size in DWs - * @reserved: (reserved) - */ -struct iwl_context_info_pnvm_cfg { - __le64 platform_nvm_addr; - __le32 platform_nvm_size; - __le32 reserved; -} __packed; - -/** - * struct iwl_context_info_early_dbg_cfg - early debug configuration for - * dumping DRAM addresses - * @early_debug_addr: early debug start address - * @early_debug_size: size in DWs - * @reserved: (reserved) - */ -struct iwl_context_info_early_dbg_cfg { - __le64 early_debug_addr; - __le32 early_debug_size; - __le32 reserved; -} __packed; - -/** - * struct iwl_context_info - device INIT configuration - * @version: version information of context info and HW - * @control: control flags of FH configurations - * @reserved0: (reserved) - * @rbd_cfg: default RX queue configuration - * @hcmd_cfg: command queue configuration - * @reserved1: (reserved) - * @dump_cfg: core dump data - * @edbg_cfg: early debug configuration - * @pnvm_cfg: platform nvm configuration - * @reserved2: (reserved) - * @dram: firmware image addresses in DRAM - * @reserved3: (reserved) - */ -struct iwl_context_info { - struct iwl_context_info_version version; - struct iwl_context_info_control control; - __le64 reserved0; - struct iwl_context_info_rbd_cfg rbd_cfg; - struct iwl_context_info_hcmd_cfg hcmd_cfg; - __le32 reserved1[4]; - struct iwl_context_info_dump_cfg dump_cfg; - struct iwl_context_info_early_dbg_cfg edbg_cfg; - struct iwl_context_info_pnvm_cfg pnvm_cfg; - __le32 reserved2[16]; - struct iwl_context_info_dram_nonfseq dram; - __le32 reserved3[16]; -} __packed; /* BOOT_LOADER_CONTEXT_INFO_S */ +#include "fw/api/ctxt-info.h" int iwl_pcie_ctxt_info_init(struct iwl_trans *trans, const struct fw_img *img); void iwl_pcie_ctxt_info_free(struct iwl_trans *trans); From 96c80e5f1a7e77ac1e6d2fd044185fadb0f25292 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sun, 11 Oct 2026 14:07:06 +0300 Subject: [PATCH 1619/2126] wifi: iwlwifi: mld: don't enable RSS if there is one queue. There is no point in RSS when we have only one rxq. Don't send the command in this case - RSS will be disabled by default. Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.dbeea799293f.I1c37945a248f101e0bca2cd723ce6551871926ab@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/fw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/fw.c b/drivers/net/wireless/intel/iwlwifi/mld/fw.c index 3b9f412cdff2..c33a553488ee 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/fw.c @@ -47,6 +47,9 @@ static int iwl_mld_send_rss_cfg_cmd(struct iwl_mld *mld) lockdep_assert_wiphy(mld->wiphy); + if (mld->trans->info.num_rxqs == 1) + return 0; + /* Do not direct RSS traffic to Q 0 which is our fallback queue */ for (int i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++) cmd.indirection_table[i] = From ea8d93d704dfae2f056fa2daf254aead2226e161 Mon Sep 17 00:00:00 2001 From: Emmanuel Grumbach Date: Sun, 11 Oct 2026 14:07:07 +0300 Subject: [PATCH 1620/2126] wifi: iwlwifi: mvm: remove dead sta check in rx_monitor_no_data sta is never assigned in iwl_mvm_rx_monitor_no_data(), so the sta ? &sta->deflink : NULL expression is dead code. Drop the variable and pass NULL directly. Drop the unneeded RCU read lock, ieee80211_rx_napi() takes the RCU read lock on its own. Spotted by Coverity. Assisted-by: LLM Signed-off-by: Emmanuel Grumbach Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.2d0a56daefed.I2bd50c74f1f50e0fd87996333b804d2731dbd0fa@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c index c01c704929ba..77a3d8dcab57 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c @@ -2427,7 +2427,6 @@ void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi, struct iwl_rx_packet *pkt = rxb_addr(rxb); struct iwl_rx_no_data_ver_3 *desc = (void *)pkt->data; u32 rssi; - struct ieee80211_sta *sta = NULL; struct sk_buff *skb; struct iwl_mvm_rx_phy_data phy_data; u32 format; @@ -2541,9 +2540,7 @@ void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi, RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK) + 1; } - rcu_read_lock(); - ieee80211_rx_napi(mvm->hw, sta ? &sta->deflink : NULL, skb, napi); - rcu_read_unlock(); + ieee80211_rx_napi(mvm->hw, NULL, skb, napi); } void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, From aacf9ec032980ca75017e968fb9e125f7779556c Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:08 +0300 Subject: [PATCH 1621/2126] wifi: iwlwifi: pcie: correctly read WFPM_OTP_CFG1_ADDR We shouldn't read this without having NIC access, which I had broken in the past. Enabling clang's context analysis now surfaced this bug. Luckily, it only applies to blank OTP devices, which aren't really common/shipping at all. Keep the value from earlier, and use zero (as in the past before I broke it) if it can't be read at all. Fixes: 0b205d0f0f50 ("wifi: iwlwifi: trans: remove hw_wfpm_id") Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.74912aba718d.I9568d08c280c0ca148c3918439c6beb8c4647a40@changeid Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/pcie/trans.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index c905b6d5db3d..bd6e38d5f631 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -3995,10 +3995,10 @@ int iwl_trans_pcie_copy_imr(struct iwl_trans *trans, * Read rf id and cdb info from prph register and store it */ static void get_crf_id(struct iwl_trans *iwl_trans, - struct iwl_trans_info *info) + struct iwl_trans_info *info, + u32 *hw_wfpm_id) { u32 sd_reg_ver_addr; - u32 hw_wfpm_id; u32 val = 0; u8 step; @@ -4064,10 +4064,10 @@ static void get_crf_id(struct iwl_trans *iwl_trans, } /* Read cdb info (also contains the jacket info if needed in the future */ - hw_wfpm_id = iwl_trans_read_umac_prph_no_grab(iwl_trans, WFPM_OTP_CFG1_ADDR); + *hw_wfpm_id = iwl_trans_read_umac_prph_no_grab(iwl_trans, WFPM_OTP_CFG1_ADDR); IWL_INFO(iwl_trans, "Detected crf-id 0x%x, cnv-id 0x%x wfpm id 0x%x\n", - info->hw_crf_id, info->hw_cnv_id, hw_wfpm_id); + info->hw_crf_id, info->hw_cnv_id, *hw_wfpm_id); } /* @@ -4075,14 +4075,13 @@ static void get_crf_id(struct iwl_trans *iwl_trans, * from the prph registers. */ static int map_crf_id(struct iwl_trans *iwl_trans, - struct iwl_trans_info *info) + struct iwl_trans_info *info, + u32 hw_wfpm_id) { int ret = 0; u32 val = info->hw_crf_id; u32 step_id = REG_CRF_ID_STEP(val); u32 slave_id = REG_CRF_ID_SLAVE(val); - u32 hw_wfpm_id = iwl_trans_read_umac_prph_no_grab(iwl_trans, - WFPM_OTP_CFG1_ADDR); u32 cdb_id_wfpm = WFPM_OTP_CFG1_IS_CDB(hw_wfpm_id); /* Map between crf id to rf id */ @@ -4195,6 +4194,7 @@ int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, }; struct iwl_trans *iwl_trans; struct iwl_trans_pcie *trans_pcie; + u32 hw_wfpm_id = 0; int ret; iwl_trans = iwl_trans_pcie_alloc(pdev, mac_cfg, &info, hw_base); @@ -4222,7 +4222,7 @@ int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, if (ret) goto out_free_trans; if (iwl_trans_grab_nic_access(iwl_trans)) { - get_crf_id(iwl_trans, &info); + get_crf_id(iwl_trans, &info, &hw_wfpm_id); /* all good */ iwl_trans_release_nic_access(iwl_trans); } else { @@ -4239,7 +4239,8 @@ int _iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent, * This is relevant only for family 9000 and up. */ if (iwl_trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_9000 && - !CSR_HW_RFID_TYPE(info.hw_rf_id) && map_crf_id(iwl_trans, &info)) { + !CSR_HW_RFID_TYPE(info.hw_rf_id) && + map_crf_id(iwl_trans, &info, hw_wfpm_id)) { ret = -EINVAL; goto out_free_trans; } From 3bc32cd63c2072ef634d923c31cffa92dfe468a2 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:09 +0300 Subject: [PATCH 1622/2126] wifi: iwlwifi: mld: avoid const in iwl_mld_chan_load_update_iter() The phy pointer here isn't really const, and if it were we'd need container_of_const() (which can do both), but as it's just non-const anyway drop the const. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.ccd4dbfffb5f.Id15631e4372d9495282634f89bd73e7f526ce2ce@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/mlo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mlo.c b/drivers/net/wireless/intel/iwlwifi/mld/mlo.c index a2f8a6957535..34273d4731ec 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/mlo.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/mlo.c @@ -1076,9 +1076,9 @@ static void iwl_mld_chan_load_update_iter(void *_data, u8 *mac, struct ieee80211_vif *vif) { struct iwl_mld_chan_load_data *data = _data; - const struct iwl_mld_phy *phy = data->phy; + struct iwl_mld_phy *phy = data->phy; struct ieee80211_chanctx_conf *chanctx = - container_of((const void *)phy, struct ieee80211_chanctx_conf, + container_of((void *)phy, struct ieee80211_chanctx_conf, drv_priv); struct iwl_mld *mld = iwl_mld_vif_from_mac80211(vif)->mld; u32 new_chan_load = phy->avg_channel_load_not_by_us; From 3a0429065f62ed24fc51ef24c0d7a3f7def118e6 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:10 +0300 Subject: [PATCH 1623/2126] wifi: iwlwifi: mld: fix const in iwl_mld_mu_mimo_iface_iterator ieee80211_update_mu_groups() takes const u8 * pointers, and we have const values, but remove the const which can lead to some warnings with clang. Leave it const throughout. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.6acceb79b0ef.Ia22765206364220b115dd84eb1a16b5a979d9340@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/notif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/notif.c b/drivers/net/wireless/intel/iwlwifi/mld/notif.c index 570b0011fd9e..7d9416ecbf92 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/notif.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/notif.c @@ -159,8 +159,8 @@ static void iwl_mld_mu_mimo_iface_iterator(void *_data, u8 *mac, * action frame, so no conversion is needed. */ ieee80211_update_mu_groups(vif, link_id, - (u8 *)¬if->membership_status, - (u8 *)¬if->user_position); + (const u8 *)¬if->membership_status, + (const u8 *)¬if->user_position); } } From b750e75cb9267be3d98b44b1f3c76e4698ff3016 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:11 +0300 Subject: [PATCH 1624/2126] wifi: iwlwifi: mvm: fix beacon flags compiler warning With clang we can hit warnings here due to different enum types on the different sides of the ternary, but we don't really need to care because they're plain integer variables. Cast them to avoid the warnings. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.6ea24eaa784d.I91bab31db441f9e230228c3893ff13fd7fc3e7bf@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c index 58a77056e607..18372ddcc0e0 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c @@ -932,8 +932,8 @@ u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw, u8 rate_idx) u16 flags = 0; if (rate_idx <= IWL_LAST_CCK_RATE) - flags |= is_new_rate ? IWL_MAC_BEACON_CCK - : IWL_MAC_BEACON_CCK_V1; + flags |= is_new_rate ? (u16)IWL_MAC_BEACON_CCK + : (u16)IWL_MAC_BEACON_CCK_V1; if (iwl_fw_lookup_cmd_ver(fw, TX_CMD, 0) > 8) flags |= iwl_mvm_rate_idx_to_fw_idx(fw, rate_idx); @@ -1109,8 +1109,8 @@ static int iwl_mvm_mac_ctxt_send_beacon_v9(struct iwl_mvm *mvm, if (iwl_mvm_enable_fils(mvm, vif, ctx)) { flags |= iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 10 ? - IWL_MAC_BEACON_FILS : - IWL_MAC_BEACON_FILS_V1; + (u16)IWL_MAC_BEACON_FILS : + (u16)IWL_MAC_BEACON_FILS_V1; beacon_cmd.short_ssid = cpu_to_le32(~crc32_le(~0, vif->cfg.ssid, vif->cfg.ssid_len)); From 9811953945bceebf3e3362ee55227df0617d8ae0 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:12 +0300 Subject: [PATCH 1625/2126] wifi: iwlwifi: mvm: uninline iwl_mvm_ftm_start versions This is not a performance-critical path, and with clang and KASAN it can use a lot of stack space. Uninline the various versions to avoid that. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.97f5c8503204.Ib88f908b0638889e84753ae334525c4c52064838@changeid Signed-off-by: Miri Korenblit --- .../intel/iwlwifi/mvm/ftm-initiator.c | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c index 4c39a452564d..dd1b80561f8c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c @@ -519,8 +519,9 @@ static int iwl_mvm_ftm_send_cmd(struct iwl_mvm *mvm, struct iwl_host_cmd *hcmd) return err; } -static int iwl_mvm_ftm_start_v5(struct iwl_mvm *mvm, struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v5(struct iwl_mvm *mvm, struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v5 cmd_v5; struct iwl_host_cmd hcmd = { @@ -545,8 +546,9 @@ static int iwl_mvm_ftm_start_v5(struct iwl_mvm *mvm, struct ieee80211_vif *vif, return iwl_mvm_ftm_send_cmd(mvm, &hcmd); } -static int iwl_mvm_ftm_start_v7(struct iwl_mvm *mvm, struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v7(struct iwl_mvm *mvm, struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v7 cmd_v7; struct iwl_host_cmd hcmd = { @@ -575,8 +577,9 @@ static int iwl_mvm_ftm_start_v7(struct iwl_mvm *mvm, struct ieee80211_vif *vif, return iwl_mvm_ftm_send_cmd(mvm, &hcmd); } -static int iwl_mvm_ftm_start_v8(struct iwl_mvm *mvm, struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v8(struct iwl_mvm *mvm, struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v8 cmd; struct iwl_host_cmd hcmd = { @@ -601,8 +604,10 @@ static int iwl_mvm_ftm_start_v8(struct iwl_mvm *mvm, struct ieee80211_vif *vif, return iwl_mvm_ftm_send_cmd(mvm, &hcmd); } -static int iwl_mvm_ftm_start_v9(struct iwl_mvm *mvm, struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) + +static int noinline_for_stack +iwl_mvm_ftm_start_v9(struct iwl_mvm *mvm, struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v9 cmd; struct iwl_host_cmd hcmd = { @@ -735,9 +740,10 @@ iwl_mvm_ftm_put_target_v7(struct iwl_mvm *mvm, struct ieee80211_vif *vif, &target->initiator_ap_flags); } -static int iwl_mvm_ftm_start_v11(struct iwl_mvm *mvm, - struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v11(struct iwl_mvm *mvm, + struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v11 cmd; struct iwl_host_cmd hcmd = { @@ -807,9 +813,10 @@ iwl_mvm_ftm_put_target_v8(struct iwl_mvm *mvm, struct ieee80211_vif *vif, return 0; } -static int iwl_mvm_ftm_start_v12(struct iwl_mvm *mvm, - struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v12(struct iwl_mvm *mvm, + struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v12 cmd; struct iwl_host_cmd hcmd = { @@ -835,9 +842,10 @@ static int iwl_mvm_ftm_start_v12(struct iwl_mvm *mvm, return iwl_mvm_ftm_send_cmd(mvm, &hcmd); } -static int iwl_mvm_ftm_start_v13(struct iwl_mvm *mvm, - struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v13(struct iwl_mvm *mvm, + struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd_v13 cmd; struct iwl_host_cmd hcmd = { @@ -951,9 +959,10 @@ iwl_mvm_ftm_put_target_v10(struct iwl_mvm *mvm, struct ieee80211_vif *vif, return 0; } -static int iwl_mvm_ftm_start_v14(struct iwl_mvm *mvm, - struct ieee80211_vif *vif, - struct cfg80211_pmsr_request *req) +static int noinline_for_stack +iwl_mvm_ftm_start_v14(struct iwl_mvm *mvm, + struct ieee80211_vif *vif, + struct cfg80211_pmsr_request *req) { struct iwl_tof_range_req_cmd cmd; struct iwl_host_cmd hcmd = { From b359cbb421490e1221710665859bebe70fc614ad Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 11 Oct 2026 14:07:13 +0300 Subject: [PATCH 1626/2126] wifi: iwlwifi: support SCD_QUEUE_CONFIG_CMD version 4 This version has a new flags field that must be set to indicate which other fields are valid, in preparation for moving queue pointers during SMD transition. Only set the IWL_SCD_QUEUE_MODIFY_FLAG_STA_MSK flag on the existing users of the command for now. Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.534cc32f2ac6.I394c38c58ad6619e3e52b52c3bc686acbbd2e4f1@changeid Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/fw/api/datapath.h | 20 ++++++++++++++++--- drivers/net/wireless/intel/iwlwifi/mld/tx.c | 4 ++++ .../net/wireless/intel/iwlwifi/pcie/tx-gen2.c | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h b/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h index 3fbcb2e4bfe0..eddf13325df9 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/datapath.h @@ -608,6 +608,16 @@ enum iwl_scd_queue_cfg_operation { IWL_SCD_QUEUE_MODIFY = 2, }; +/** + * enum iwl_scd_queue_modify_flags - scheduler queue modify flags + * @IWL_SCD_QUEUE_MODIFY_FLAG_RD_PTR: update the read pointer + * @IWL_SCD_QUEUE_MODIFY_FLAG_STA_MSK: update the station mask + */ +enum iwl_scd_queue_modify_flags { + IWL_SCD_QUEUE_MODIFY_FLAG_RD_PTR = BIT(0), + IWL_SCD_QUEUE_MODIFY_FLAG_STA_MSK = BIT(1), +}; + /** * struct iwl_scd_queue_cfg_cmd - scheduler queue allocation command * @operation: the operation, see &enum iwl_scd_queue_cfg_operation @@ -625,6 +635,8 @@ enum iwl_scd_queue_cfg_operation { * @u.modify.old_sta_mask: old station mask for modify * @u.modify.tid: TID of queue to modify * @u.modify.new_sta_mask: new station mask for modify + * @u.modify.rd_ptr: new read pointer to set for the queue (version 4) + * @u.modify.flags: &enum iwl_scd_queue_modify_flags (version 4) */ struct iwl_scd_queue_cfg_cmd { __le32 operation; @@ -646,9 +658,11 @@ struct iwl_scd_queue_cfg_cmd { __le32 old_sta_mask; __le32 tid; __le32 new_sta_mask; - } __packed modify; /* TX_QUEUE_CFG_CMD_MODIFY_API_S_VER_1 */ - } __packed u; /* TX_QUEUE_CFG_CMD_OPERATION_API_U_VER_1 */ -} __packed; /* TX_QUEUE_CFG_CMD_API_S_VER_3 */ + __le16 rd_ptr; + __le16 flags; + } __packed modify; /* TX_QUEUE_CFG_CMD_MODIFY_API_S_VER_1, _VER_2 */ + } __packed u; /* TX_QUEUE_CFG_CMD_OPERATION_API_U_VER_1, _VER_2 */ +} __packed; /* TX_QUEUE_CFG_CMD_API_S_VER_3, _VER_4 */ /** * enum iwl_sec_key_flags - security key command key flags diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tx.c b/drivers/net/wireless/intel/iwlwifi/mld/tx.c index fc501ac0c1f2..44aa317b8e7d 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tx.c @@ -1484,6 +1484,10 @@ int iwl_mld_update_sta_txqs(struct iwl_mld *mld, lockdep_assert_wiphy(mld->wiphy); + if (mld->trans->conf.queue_alloc_cmd_ver >= 4) + cmd.u.modify.flags = + cpu_to_le16(IWL_SCD_QUEUE_MODIFY_FLAG_STA_MSK); + for (int tid = 0; tid <= IWL_MAX_TID_COUNT; tid++) { struct ieee80211_txq *txq = sta->txq[tid != IWL_MAX_TID_COUNT ? diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c index e6bebd37417f..b235a4539d7c 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c @@ -1075,7 +1075,8 @@ int iwl_txq_dyn_alloc(struct iwl_trans *trans, u32 flags, u32 sta_mask, hcmd.id = SCD_QUEUE_CFG; hcmd.len[0] = sizeof(cmd.old); hcmd.data[0] = &cmd.old; - } else if (trans->conf.queue_alloc_cmd_ver == 3) { + } else if (trans->conf.queue_alloc_cmd_ver == 3 || + trans->conf.queue_alloc_cmd_ver == 4) { memset(&cmd.new, 0, sizeof(cmd.new)); cmd.new.operation = cpu_to_le32(IWL_SCD_QUEUE_ADD); cmd.new.u.add.tfdq_dram_addr = cpu_to_le64(txq->dma_addr); From afbb3c6bd7010fa47844626540ce84c85dd65656 Mon Sep 17 00:00:00 2001 From: Miri Korenblit Date: Sun, 11 Oct 2026 14:07:14 +0300 Subject: [PATCH 1627/2126] wifi: iwlwifi: trans: remove the unused write8 operation Unlike the other bus operations, write8 has no generic wrapper and is never dispatched through trans->ops: all the callers are in the pcie code and call iwl_trans_pcie_write8() directly. Remove it. Assisted-by: LLM Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20261011140453.fecac6ba37d1.Icf8e741c8ccc6eff1abd046223b575c07f69aff5@changeid Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/iwl-trans.h | 2 -- drivers/net/wireless/intel/iwlwifi/pcie/trans.c | 1 - 2 files changed, 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h index 5db07f1eab56..7a358daab584 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-trans.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-trans.h @@ -1237,7 +1237,6 @@ void iwl_trans_fw_reset_handshake(struct iwl_trans *trans); * @send_cmd: send a host command to the firmware * @alloc_tx_cmd: allocate a device TX command * @free_tx_cmd: free a device TX command - * @write8: write a byte to a device register * @write32: write a dword to a device register * @read32: read a dword from a device register * @read_prph: read a peripheral register @@ -1291,7 +1290,6 @@ struct iwl_trans_ops { void (*free_tx_cmd)(struct iwl_trans *trans, struct iwl_device_tx_cmd *dev_cmd); - void (*write8)(struct iwl_trans *trans, u32 ofs, u8 val); void (*write32)(struct iwl_trans *trans, u32 ofs, u32 val); u32 (*read32)(struct iwl_trans *trans, u32 ofs); u32 (*read_prph)(struct iwl_trans *trans, u32 ofs); diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c index bd6e38d5f631..0f4e309fe32b 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c @@ -3704,7 +3704,6 @@ const struct iwl_trans_ops iwl_trans_pcie_ops = { .alloc_tx_cmd = iwl_pcie_alloc_tx_cmd, .free_tx_cmd = iwl_pcie_free_tx_cmd, - .write8 = iwl_trans_pcie_write8, .write32 = iwl_trans_pcie_write32, .read32 = iwl_trans_pcie_read32, .read_prph = iwl_trans_pcie_read_prph, From 3627924ed81fd7783394fb2555ea179c6606a231 Mon Sep 17 00:00:00 2001 From: Endrik Einberg Date: Mon, 5 Oct 2026 17:42:25 +0300 Subject: [PATCH 1628/2126] wifi: iwlwifi: mld: include VI packets in low latency detection iwl_mld_is_vo_vi_pkt() checks whether the mapped access category is less than IEEE80211_AC_VI. Since mac80211 defines IEEE80211_AC_VO as 0 and IEEE80211_AC_VI as 1, this only matches voice traffic and excludes video traffic. Synthetic video-priority UDP traffic does not automatically activate low-latency mode, whereas voice-priority traffic does Include IEEE80211_AC_VI as intended. Fixes: d1e879ec600f ("wifi: iwlwifi: add iwlmld sub-driver") Signed-off-by: Endrik Einberg Link: https://patch.msgid.link/20261005144225.170280-1-git@endrik.dev Signed-off-by: Miri Korenblit --- drivers/net/wireless/intel/iwlwifi/mld/low_latency.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/low_latency.c b/drivers/net/wireless/intel/iwlwifi/mld/low_latency.c index a4ddc32e2860..e7482623111c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/low_latency.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/low_latency.c @@ -257,7 +257,8 @@ static bool iwl_mld_is_vo_vi_pkt(struct ieee80211_hdr *hdr) if (tid >= IWL_MAX_TID_COUNT) return false; - return tid_to_mac80211_ac[tid] < IEEE80211_AC_VI; + return tid_to_mac80211_ac[tid] == IEEE80211_AC_VI || + tid_to_mac80211_ac[tid] == IEEE80211_AC_VO; } void iwl_mld_low_latency_update_counters(struct iwl_mld *mld, From 99fa01d7d1feb14389487d72652065861f7640f6 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Fri, 18 Sep 2026 11:31:09 -0700 Subject: [PATCH 1629/2126] selftests: netfilter: nft_queue.sh: only queue icmp echo request/reply The bridge test flakes on debug kernels: FAIL: Expected 10 packets total, but got 24 packets total hook 3 packets 00000008 hook 4 packets 00000010 The surplus are icmp fragment reassembly timeouts. The udp flood in the stress test leaves incomplete datagrams behind in ns2 and ns3, 30 seconds later their reassembly queues expire and both namespaces send icmp time exceeded to ns1's pre-bridge address. ns3 is not reconfigured when the router is turned into a bridge, so its messages arrive via veth2 and are then forwarded out of br0. Such packets are locally originated from the bridge point of view and are queued from the bridge output and postrouting hooks, which is why only those two counters are off. Restrict the ipv4 rule to echo request/reply, the icmpv6 rule already does this. We used to see 1 flake a day in NIPA before locally queuing this change, zero flakes since (over 9 days) Signed-off-by: Jakub Kicinski Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- tools/testing/selftests/net/netfilter/nft_queue.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/netfilter/nft_queue.sh b/tools/testing/selftests/net/netfilter/nft_queue.sh index 7c857a2e0f34..c8d1f2eb4133 100755 --- a/tools/testing/selftests/net/netfilter/nft_queue.sh +++ b/tools/testing/selftests/net/netfilter/nft_queue.sh @@ -92,7 +92,7 @@ load_ruleset() { ip netns exec "$nsrouter" nft -f /dev/stdin < Date: Mon, 28 Sep 2026 00:08:07 +0200 Subject: [PATCH 1630/2126] ipvs: fix buffer overflow when sending sync messages Sashiko reports for possible heap buffer overflow when generating sync message for the v0 and v1 message formats. We should read the cp->flags only once because another CPU can concurrently set the SEQ_MASK between the two reads. Note that IPVS does not set the SEQ_MASK anymore for the ip_vs_ftp.c helper starting from commit 7f1c40757951 ("IPVS: make FTP work with full NAT support") (2.6.36+), so the problem should not be reproducible. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://sashiko.dev/#/patchset/20260903004149.1037028-1-pablo%40netfilter.org Link: https://sashiko.dev/#/patchset/20260909111338.44357-1-ja%40ssi.bg Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_sync.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 45655cff078c..157f5c8361ab 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -543,13 +543,15 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, struct ip_vs_sync_conn_v0 *s; struct ip_vs_sync_buff *buff; struct ipvs_master_sync_state *ms; - int id; + u32 flags, seq_mask; unsigned int len; + int id; if (unlikely(cp->af != AF_INET)) return; + flags = READ_ONCE(cp->flags); /* Do not sync ONE PACKET */ - if (cp->flags & IP_VS_CONN_F_ONE_PACKET) + if (flags & IP_VS_CONN_F_ONE_PACKET) return; if (!ip_vs_sync_conn_needed(ipvs, cp, pkts)) @@ -564,8 +566,8 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, id = select_master_thread_id(ipvs, cp); ms = &ipvs->ms[id]; buff = ms->sync_buff; - len = (cp->flags & IP_VS_CONN_F_SEQ_MASK) ? FULL_CONN_SIZE : - SIMPLE_CONN_SIZE; + seq_mask = flags & IP_VS_CONN_F_SEQ_MASK; + len = seq_mask ? FULL_CONN_SIZE : SIMPLE_CONN_SIZE; if (buff) { m = (struct ip_vs_sync_mesg_v0 *) buff->mesg; /* Send buffer if it is for v1 */ @@ -597,9 +599,9 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, s->caddr = cp->caddr.ip; s->vaddr = cp->vaddr.ip; s->daddr = cp->daddr.ip; - s->flags = htons(cp->flags & ~IP_VS_CONN_F_HASHED); + s->flags = htons(flags & ~IP_VS_CONN_F_HASHED); s->state = htons(cp->state); - if (cp->flags & IP_VS_CONN_F_SEQ_MASK) { + if (seq_mask) { struct ip_vs_sync_conn_options *opt = (struct ip_vs_sync_conn_options *)&s[1]; memcpy(opt, &cp->sync_conn_opt, sizeof(*opt)); @@ -635,6 +637,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) int id; __u8 *p; unsigned int len, pe_name_len, pad; + u32 flags, seq_mask; /* Handle old version of the protocol */ if (sysctl_sync_ver(ipvs) == 0) { @@ -647,6 +650,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) sloop: if (!ip_vs_sync_conn_needed(ipvs, cp, pkts)) goto control; + flags = READ_ONCE(cp->flags); /* Sanity checks */ pe_name_len = 0; @@ -674,7 +678,8 @@ sloop: #endif len = sizeof(struct ip_vs_sync_v4); - if (cp->flags & IP_VS_CONN_F_SEQ_MASK) + seq_mask = flags & IP_VS_CONN_F_SEQ_MASK; + if (seq_mask) len += sizeof(struct ip_vs_sync_conn_options) + 2; if (cp->pe_data_len) @@ -720,7 +725,7 @@ sloop: /* Set message type & copy members */ s->v4.type = (cp->af == AF_INET6 ? STYPE_F_INET6 : 0); s->v4.ver_size = htons(len & SVER_MASK); /* Version 0 */ - s->v4.flags = htonl(cp->flags & ~IP_VS_CONN_F_HASHED); + s->v4.flags = htonl(flags & ~IP_VS_CONN_F_HASHED); s->v4.state = htons(cp->state); s->v4.protocol = cp->protocol; s->v4.cport = cp->cport; @@ -744,7 +749,7 @@ sloop: s->v4.vaddr = cp->vaddr.ip; s->v4.daddr = cp->daddr.ip; } - if (cp->flags & IP_VS_CONN_F_SEQ_MASK) { + if (seq_mask) { *(p++) = IPVS_OPT_SEQ_DATA; *(p++) = sizeof(struct ip_vs_sync_conn_options); hton_seq(&cp->in_seq, (struct ip_vs_seq *)p); From a919316bbb700d44baf9cdbf78666bce24261bc8 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 13 Oct 2026 15:13:29 +0200 Subject: [PATCH 1631/2126] wifi: mac80211: tests: fix stack variable bug The code in mac80211 assumes that BSS entries are allocated together with the struct ieee80211_bss internal data, but the test didn't do that, which with clang 23 resulted in a KASAN splat here. Fix the code to properly have both structs. Fix the allocation while at it, should be the ies struct size, not the cbss. Link: https://patch.msgid.link/20261013151329.b8135eb40430.I97a6cb689fbc19903c78e2f6dfe37bdc2117b605@changeid Signed-off-by: Johannes Berg --- net/mac80211/tests/chan-mode.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/net/mac80211/tests/chan-mode.c b/net/mac80211/tests/chan-mode.c index 85dc87215d23..d6714df8a5c6 100644 --- a/net/mac80211/tests/chan-mode.c +++ b/net/mac80211/tests/chan-mode.c @@ -153,8 +153,11 @@ static void test_determine_chan_mode(struct kunit *test) .mode = params->conn_mode, .bw_limit = params->conn_bw_limit, }; - struct cfg80211_bss cbss = { - .channel = &t_sdata->band_5ghz.channels[0], + struct { + struct cfg80211_bss cbss; + struct ieee80211_bss internal; + } bss = { + .cbss.channel = &t_sdata->band_5ghz.channels[0], }; unsigned long userspace_selectors[BITS_TO_LONGS(128)] = {}; u8 bss_ies[] = { @@ -229,18 +232,18 @@ static void test_determine_chan_mode(struct kunit *test) if (params->userspace_selector) set_bit(params->userspace_selector, userspace_selectors); - rcu_assign_pointer(cbss.ies, + rcu_assign_pointer(bss.cbss.ies, kunit_kzalloc(test, - sizeof(cbss) + sizeof(bss_ies), + sizeof(*bss.cbss.ies) + sizeof(bss_ies), GFP_KERNEL)); - KUNIT_ASSERT_NOT_NULL(test, rcu_access_pointer(cbss.ies)); - ((struct cfg80211_bss_ies *)rcu_access_pointer(cbss.ies))->len = sizeof(bss_ies); + KUNIT_ASSERT_NOT_NULL(test, rcu_access_pointer(bss.cbss.ies)); + ((struct cfg80211_bss_ies *)rcu_access_pointer(bss.cbss.ies))->len = sizeof(bss_ies); - memcpy((void *)rcu_access_pointer(cbss.ies)->data, bss_ies, + memcpy((void *)rcu_access_pointer(bss.cbss.ies)->data, bss_ies, sizeof(bss_ies)); rcu_read_lock(); - elems = ieee80211_determine_chan_mode(t_sdata->sdata, &conn, &cbss, + elems = ieee80211_determine_chan_mode(t_sdata->sdata, &conn, &bss.cbss, NULL, 0, &chanreq, &ap_chandef, userspace_selectors); rcu_read_unlock(); From 577f690ce5dc641d9d8646d15bb8e99ff4a8280e Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 13 Oct 2026 15:12:58 +0200 Subject: [PATCH 1632/2126] wifi: cfg80211: track SSID regardless of country data If the country data cannot be found, the function exits and then doesn't track the SSID. Move the SSID tracking up to fix that. Fixes: c38c70185101 ("wifi: cfg80211: Set SSID if it is not already set") Link: https://patch.msgid.link/20261013151258.7fbca481c328.I7beb03fb4309698bdcfade57c6804573f96eeb18@changeid Signed-off-by: Johannes Berg --- net/wireless/sme.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/net/wireless/sme.c b/net/wireless/sme.c index fde86c900f4f..710472c197c9 100644 --- a/net/wireless/sme.c +++ b/net/wireless/sme.c @@ -872,6 +872,25 @@ void __cfg80211_connect_result(struct net_device *dev, cfg80211_upload_connect_keys(wdev); + if (!wdev->u.client.ssid_len) { + rcu_read_lock(); + for_each_valid_link(cr, link) { + u32 ssid_len; + + ssid = ieee80211_bss_get_elem(cr->links[link].bss, + WLAN_EID_SSID); + + if (!ssid || !ssid->datalen) + continue; + + ssid_len = min(ssid->datalen, IEEE80211_MAX_SSID_LEN); + memcpy(wdev->u.client.ssid, ssid->data, ssid_len); + wdev->u.client.ssid_len = ssid_len; + break; + } + rcu_read_unlock(); + } + rcu_read_lock(); for_each_valid_link(cr, link) { country_elem = @@ -897,25 +916,6 @@ void __cfg80211_connect_result(struct net_device *dev, country_data, country_datalen); kfree(country_data); - if (!wdev->u.client.ssid_len) { - rcu_read_lock(); - for_each_valid_link(cr, link) { - u32 ssid_len; - - ssid = ieee80211_bss_get_elem(cr->links[link].bss, - WLAN_EID_SSID); - - if (!ssid || !ssid->datalen) - continue; - - ssid_len = min(ssid->datalen, IEEE80211_MAX_SSID_LEN); - memcpy(wdev->u.client.ssid, ssid->data, ssid_len); - wdev->u.client.ssid_len = ssid_len; - break; - } - rcu_read_unlock(); - } - return; out: for_each_valid_link(cr, link) From 7a79160f35dbcc41653ef4979a9f900f7e764e9a Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 13 Oct 2026 14:59:03 +0200 Subject: [PATCH 1633/2126] wifi: cfg80211: reject WEP/TKIP with multi-link This is not possible by spec, so check and reject it in order to avoid being able to hit such code paths in the code later. Link: https://patch.msgid.link/20261013150604.d37bf448de30.Ib47bf264ac9d2502312158503d1ca8aae99496c0@changeid Signed-off-by: Johannes Berg --- net/wireless/util.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/wireless/util.c b/net/wireless/util.c index 9d5456defc90..59912f4a93c8 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -426,6 +426,17 @@ int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, break; } + switch (params->cipher) { + case WLAN_CIPHER_SUITE_WEP40: + case WLAN_CIPHER_SUITE_WEP104: + case WLAN_CIPHER_SUITE_TKIP: + if (wdev->valid_links) + return -EINVAL; + break; + default: + break; + } + /* * Per Wi-Fi Aware v4.0 section 7.1.2, NAN Data interfaces * shall only use CCMP-128 or GCMP-256. From a4190accbf7e05496754004bb701fb3e7d04e57f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 13 Oct 2026 15:18:17 +0200 Subject: [PATCH 1634/2126] wifi: cfg80211: fix potential requested_regd leak If a custom regdomain is registered by a driver by calling regulatory_set_wiphy_regd() (the async one) before the wiphy is registered, and then registration fails or it's unregistered before the worker ran, we leak the regdomain. Free it on wiphy free. Link: https://patch.msgid.link/20261013151817.9c197c4779d4.I983cf65a625fbc99e13b0a2710167157c34b6cd9@changeid Signed-off-by: Johannes Berg --- net/wireless/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/wireless/core.c b/net/wireless/core.c index d2931b9d7e58..f4153c249599 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -1461,6 +1461,7 @@ void cfg80211_dev_free(struct cfg80211_registered_device *rdev) * can just free it here. */ kfree(rcu_dereference_raw(rdev->wiphy.regd)); + kfree(rdev->requested_regd); kfree(rdev); } From 8b431b664db8942a7503b0592e749c6fe599c061 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 11 Aug 2026 10:37:30 +0200 Subject: [PATCH 1635/2126] Bluetooth: hci_sync: Factor common cleanup code into a helper The hci_dev_init_sync() failure path in hci_dev_open_sync() and the cleanup code in hci_dev_close_sync() have a bunch of common code. Factor this duplicate code out into a hci_dev_drop_last_cmd_req_and_close() helper function. Signed-off-by: Hans de Goede Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 64 +++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index a92a81846e9d..6854449a060d 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5390,6 +5390,30 @@ static int hci_dev_init_sync(struct hci_dev *hdev) return ret; } +static void hci_dev_drop_last_cmd_req_and_close(struct hci_dev *hdev) +{ + /* Drop last sent command */ + if (hdev->sent_cmd) { + cancel_delayed_work_sync(&hdev->cmd_timer); + kfree_skb(hdev->sent_cmd); + hdev->sent_cmd = NULL; + } + + /* Drop last request */ + if (hdev->req_skb) { + kfree_skb(hdev->req_skb); + hdev->req_skb = NULL; + hci_dev_clear_flag(hdev, HCI_CMD_PENDING); + } + + clear_bit(HCI_RUNNING, &hdev->flags); + hci_sock_dev_event(hdev, HCI_DEV_CLOSE); + + /* After this point our queues are empty and no tasks are scheduled. */ + hdev->close(hdev); + hdev->flags &= BIT(HCI_RAW); +} + int hci_dev_open_sync(struct hci_dev *hdev) { int ret; @@ -5476,23 +5500,7 @@ int hci_dev_open_sync(struct hci_dev *hdev) if (hdev->flush) hdev->flush(hdev); - if (hdev->sent_cmd) { - cancel_delayed_work_sync(&hdev->cmd_timer); - kfree_skb(hdev->sent_cmd); - hdev->sent_cmd = NULL; - } - - if (hdev->req_skb) { - kfree_skb(hdev->req_skb); - hdev->req_skb = NULL; - hci_dev_clear_flag(hdev, HCI_CMD_PENDING); - } - - clear_bit(HCI_RUNNING, &hdev->flags); - hci_sock_dev_event(hdev, HCI_DEV_CLOSE); - - hdev->close(hdev); - hdev->flags &= BIT(HCI_RAW); + hci_dev_drop_last_cmd_req_and_close(hdev); } done: @@ -5659,28 +5667,10 @@ int hci_dev_close_sync(struct hci_dev *hdev) skb_queue_purge(&hdev->cmd_q); skb_queue_purge(&hdev->raw_q); - /* Drop last sent command */ - if (hdev->sent_cmd) { - cancel_delayed_work_sync(&hdev->cmd_timer); - kfree_skb(hdev->sent_cmd); - hdev->sent_cmd = NULL; - } - - /* Drop last request */ - if (hdev->req_skb) { - kfree_skb(hdev->req_skb); - hdev->req_skb = NULL; - hci_dev_clear_flag(hdev, HCI_CMD_PENDING); - } - - clear_bit(HCI_RUNNING, &hdev->flags); - hci_sock_dev_event(hdev, HCI_DEV_CLOSE); - - /* After this point our queues are empty and no tasks are scheduled. */ - hdev->close(hdev); + /* Drop last sent command, last request and close */ + hci_dev_drop_last_cmd_req_and_close(hdev); /* Clear flags */ - hdev->flags &= BIT(HCI_RAW); hci_dev_clear_volatile_flags(hdev); hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); From 16ed10be23a141d5a9ad38874c5a714e00ce49f7 Mon Sep 17 00:00:00 2001 From: Ajith P V Date: Tue, 11 Aug 2026 09:49:32 +0000 Subject: [PATCH 1636/2126] Bluetooth: bnep: refactor deprecated strcpy The strcpy() function is deprecated across the kernel tree and moving towards complete elimination. It provides no verification limits against buffer overflows and does not guarantee strict boundary restrictions [1][2]. Replace instances of strcpy() in `net/bluetooth/bnep/core.c` with the safer strscpy() alternative. Since both target destination blocks are statically allocated fixed-size arrays within their structure definitions, leverage the compile time sizeof() operator to explicitly pass the destination buffer capacities. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1] Link: https://github.com/KSPP/linux/issues/88 [2] Signed-off-by: Ajith P V Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/bnep/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index ad24d2486665..f57b4323ab2f 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c @@ -685,7 +685,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) goto failed; } - strcpy(req->device, dev->name); + strscpy(req->device, dev->name, sizeof(req->device)); up_write(&bnep_session_sem); return 0; @@ -727,7 +727,7 @@ static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s) memset(ci, 0, sizeof(*ci)); memcpy(ci->dst, s->eh.h_source, ETH_ALEN); - strcpy(ci->device, s->dev->name); + strscpy(ci->device, s->dev->name, sizeof(ci->device)); ci->flags = s->flags & valid_flags; ci->state = s->state; ci->role = s->role; From c685b0b76395c74b8b715d1c0fc33bbebd69bc73 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Sun, 9 Aug 2026 14:59:59 +0200 Subject: [PATCH 1637/2126] Bluetooth: btmrvl: Slightly simplify btmrvl_process_event() In btmrvl_process_event(), all error handling paths except one do a direct return. Update the only one that makes a goto to be consistent. This does not change the behavior because ret is known to be != 0 when 'exit' is reached. This simplifies the code, saves 2 LoC and pleases one of my coccinelle script that tries to spot erroneously mixed goto and return statements. Signed-off-by: Christophe JAILLET Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmrvl_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c index e25930351f64..d449fbdde464 100644 --- a/drivers/bluetooth/btmrvl_main.c +++ b/drivers/bluetooth/btmrvl_main.c @@ -87,8 +87,7 @@ int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb) event = (struct btmrvl_event *) skb->data; if (event->ec != 0xff) { BT_DBG("Not Marvell Event=%x", event->ec); - ret = -EINVAL; - goto exit; + return -EINVAL; } switch (event->data[0]) { @@ -165,7 +164,6 @@ int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb) break; } -exit: if (!ret) kfree_skb(skb); From ac043b566ac3e7e27a58a6c9a3411e59466a0658 Mon Sep 17 00:00:00 2001 From: Richard Nunley Date: Sun, 9 Aug 2026 15:30:50 -0500 Subject: [PATCH 1638/2126] Bluetooth: btusb: Add Realtek RTL8821CE device 13d3:3558 The IMC Networks Bluetooth controller with USB ID 13d3:3558 uses an RTL8821CE. Without BTUSB_REALTEK, btusb uses generic initialization and does not load the controller firmware. BLE connections then fail before pairing with HCI error 0x3e. Add the device ID to the RTL8821CE table. This enables loading rtl_bt/rtl8821c_fw.bin and rtl_bt/rtl8821c_config.bin, after which a BLE HID keyboard pairs successfully. Signed-off-by: Richard Nunley Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index dc7191bf4234..1efa7ed50c1d 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -528,6 +528,8 @@ static const struct usb_device_id quirks_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x13d3, 0x3533), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, + { USB_DEVICE(0x13d3, 0x3558), .driver_info = BTUSB_REALTEK | + BTUSB_WIDEBAND_SPEECH }, /* Realtek 8822CE Bluetooth devices */ { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK | From 9fb154391dcf2ddc869273091cd13a52104a7855 Mon Sep 17 00:00:00 2001 From: ZhaoJinming Date: Tue, 11 Aug 2026 16:47:37 +0800 Subject: [PATCH 1639/2126] Bluetooth: virtio_bt: Fix use-after-free and memory leak in probe error paths When virtbt_open_vdev() fails in virtbt_probe(), hci_free_dev(hdev) is called without first calling hci_unregister_dev(hdev). Since hci_register_dev() already succeeded, the HCI device remains registered while its memory is freed, leading to a use-after-free when accessed via sysfs or HCI sockets. Additionally, the probe function leaks the virtio_bluetooth structure (vbt) in several error paths: - When virtio_find_vqs() fails, vbt is not freed. - When hci_alloc_dev() or hci_register_dev() fails, vbt is not freed. - When virtbt_open_vdev() fails, vbt is not freed. Furthermore, when virtbt_open_vdev() fails after virtio_device_ready() has been called, the device is left live (DRIVER_OK set) while its virtqueues are torn down, and any scheduled work is not flushed, potentially allowing a use-after-free from device-initiated callbacks. Fix all of these by restructuring the error labels to properly unwind in reverse order of the allocation/registration sequence. The new labels err_del_vqs and err_free_vbt ensure that del_vqs and kfree(vbt) are called as appropriate for each failure point. For the virtbt_open_vdev() failure path, call virtio_reset_device() and virtbt_close_vdev() before unregistering the HCI device, matching the cleanup pattern in virtbt_remove(). Signed-off-by: ZhaoJinming Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/virtio_bt.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c index c20d54088c8c..8c55b538deef 100644 --- a/drivers/bluetooth/virtio_bt.c +++ b/drivers/bluetooth/virtio_bt.c @@ -315,12 +315,12 @@ static int virtbt_probe(struct virtio_device *vdev) err = virtio_find_vqs(vdev, VIRTBT_NUM_VQS, vbt->vqs, vqs_info, NULL); if (err) - return err; + goto err_free_vbt; hdev = hci_alloc_dev(); if (!hdev) { err = -ENOMEM; - goto failed; + goto err_del_vqs; } vbt->hdev = hdev; @@ -390,20 +390,25 @@ static int virtbt_probe(struct virtio_device *vdev) if (hci_register_dev(hdev) < 0) { hci_free_dev(hdev); err = -EBUSY; - goto failed; + goto err_del_vqs; } virtio_device_ready(vdev); err = virtbt_open_vdev(vbt); - if (err) - goto open_failed; + if (err) { + hci_unregister_dev(hdev); + virtio_reset_device(vdev); + virtbt_close_vdev(vbt); + hci_free_dev(hdev); + goto err_del_vqs; + } return 0; -open_failed: - hci_free_dev(hdev); -failed: +err_del_vqs: vdev->config->del_vqs(vdev); +err_free_vbt: + kfree(vbt); return err; } From 533d6d13d60509a260d86b7b1808bed19bec637b Mon Sep 17 00:00:00 2001 From: ZhaoJinming Date: Mon, 10 Aug 2026 18:22:38 +0800 Subject: [PATCH 1640/2126] Bluetooth: btmtksdio: fix deadlock in close and reset paths btmtksdio_close() and btmtksdio_reset() call cancel_work_sync() on bdev->txrx_work while holding the sdio host lock, which is also acquired by btmtksdio_txrx_work(). If txrx_work is queued when close/reset runs, a worker thread may start it after the host lock is taken and block in sdio_claim_host(), while cancel_work_sync() waits for the work to finish. The host lock is only released after cancel_work_sync() returns, so both sides wait forever, deadlocking close/reset. Fix this by releasing the sdio host lock before calling cancel_work_sync(), then re-acquiring it afterwards. In btmtksdio_close() the interrupt is already disabled by sdio_release_irq(), which also unregisters the IRQ handler, so no new work can be scheduled and cancel_work_sync() fully quiesces txrx_work. btmtksdio_reset() must additionally unregister the IRQ handler before dropping the host lock: btmtksdio_txrx_work() unconditionally re-enables the device interrupt (C_INT_EN_SET) when the handler is still registered, so an in-flight worker would re-enable interrupts and be rescheduled while the device is being reset, defeating the cancellation. The IRQ is re-claimed by btmtksdio_open() when the HCI device is re-opened after the reset. This mirrors the pattern already used by btmtksdio_flush(), which cancels the work without holding the host lock. Signed-off-by: ZhaoJinming Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtksdio.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index a15ae6598c66..f606174c606a 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -779,8 +779,16 @@ static int btmtksdio_close(struct hci_dev *hdev) sdio_release_irq(bdev->func); + /* No new work can be scheduled after sdio_release_irq(), so cancel the + * work outside the sdio host lock. btmtksdio_txrx_work() also claims + * the host, so canceling it while holding the lock would deadlock. + */ + sdio_release_host(bdev->func); + cancel_work_sync(&bdev->txrx_work); + sdio_claim_host(bdev->func); + btmtksdio_fw_pmctrl(bdev); clear_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state); @@ -1324,8 +1332,22 @@ static void btmtksdio_reset(struct hci_dev *hdev) sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, NULL); skb_queue_purge(&bdev->txq); + + /* Unregister the IRQ before releasing the host lock so that a + * concurrently running btmtksdio_txrx_work() cannot re-enable the + * device interrupt (C_INT_EN_SET) and be rescheduled while the device + * is being reset. btmtksdio_txrx_work() also claims the host, so the + * work must be cancelled outside the sdio host lock to avoid a + * deadlock. The IRQ is re-claimed by btmtksdio_open() when the HCI + * device is re-opened after the reset. + */ + sdio_release_irq(bdev->func); + sdio_release_host(bdev->func); + cancel_work_sync(&bdev->txrx_work); + sdio_claim_host(bdev->func); + gpiod_set_value_cansleep(bdev->reset, 1); msleep(100); gpiod_set_value_cansleep(bdev->reset, 0); From 21139b3ac62ab1599d22e5b33cf571f9ea4193cf Mon Sep 17 00:00:00 2001 From: ZhaoJinming Date: Mon, 10 Aug 2026 15:08:45 +0800 Subject: [PATCH 1641/2126] Bluetooth: hci_serdev: Fix use-after-free in hci_uart_unregister_device() hci_uart_unregister_device() frees the HCI device (hci_free_dev) before cancelling write_work via cancel_work_sync(). If write_work is executing concurrently on another CPU, it can access hu->hdev and write to hdev->stat after the memory has been freed. Additionally, HCI_UART_PROTO_READY is not cleared until after cancel_work_sync, so the write_wakeup serdev callback can still schedule write_work via hci_uart_tx_wakeup() even after hci_free_dev has freed the device. Fix this by mirroring the same ordering used in the tty/ldisc path (hci_uart_tty_close, hci_ldisc.c:565-593): 1. Save the PROTO_READY state and clear it under the write lock so a concurrent hci_uart_tx_wakeup() cannot re-schedule write_work 2. Cancel write_work (no new work can be scheduled and no work is in flight) 3. Unregister the HCI device 4. Close the protocol (may access hu->hdev and the serdev device) 5. Close the serdev port (safe now that write_work is quiesced and protocol is done) 6. Free the HCI device Also free any partially transmitted frame (hu->tx_skb) left over by write_work once the transmit path is quiesced, since hci_uart_close() would skip hci_uart_flush() because HCI_UART_PROTO_READY is cleared. Signed-off-by: ZhaoJinming Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_serdev.c | 46 +++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index d2eaf2f12aa2..48ba017e219b 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -395,20 +395,54 @@ EXPORT_SYMBOL_GPL(hci_uart_register_device_priv); void hci_uart_unregister_device(struct hci_uart *hu) { struct hci_dev *hdev = hu->hdev; + bool proto_ready; + /* Wait for init_ready to finish to prevent registration races */ cancel_work_sync(&hu->init_ready); - if (test_bit(HCI_UART_REGISTERED, &hu->flags)) - hci_unregister_dev(hdev); - hci_free_dev(hdev); + proto_ready = test_bit(HCI_UART_PROTO_READY, &hu->flags); + if (proto_ready) { + /* Clear HCI_UART_PROTO_READY under the write lock so a + * concurrent hci_uart_tx_wakeup() cannot re-schedule + * write_work via the write_wakeup callback once the device + * is torn down. + */ + percpu_down_write(&hu->proto_lock); + clear_bit(HCI_UART_PROTO_READY, &hu->flags); + percpu_up_write(&hu->proto_lock); + } + + /* Unconditionally cancel write_work AFTER clearing PROTO_READY. + * This ensures that concurrent protocol timers cannot requeue + * write_work, permanently preventing double-free races and UAFs, + * and guarantees no write_work is in flight before the serdev + * device is closed. + */ cancel_work_sync(&hu->write_work); + /* Free any partially transmitted frame left over by write_work now + * that the transmit path is fully quiesced. hci_uart_close() would + * skip hci_uart_flush() because HCI_UART_PROTO_READY is cleared. + */ + if (hu->tx_skb) { + kfree_skb(hu->tx_skb); + hu->tx_skb = NULL; + } + + if (test_bit(HCI_UART_REGISTERED, &hu->flags)) + hci_unregister_dev(hdev); + + /* Close the protocol before freeing hdev (intrinsically purges queues). + * Some protocol close handlers (e.g. qca_close) may still access the + * serdev device, so keep the serdev port open until this completes. + */ hu->proto->close(hu); - if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) { - clear_bit(HCI_UART_PROTO_READY, &hu->flags); + if (proto_ready) serdev_device_close(hu->serdev); - } + + hci_free_dev(hdev); + percpu_free_rwsem(&hu->proto_lock); } EXPORT_SYMBOL_GPL(hci_uart_unregister_device); From 82934ef82b061a88eaedc6929a44a35215d7466f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 16 Aug 2026 13:26:21 +0300 Subject: [PATCH 1642/2126] Bluetooth: hci_core: add lockdep check to hci_conn lookups Add lockdep check for RCU || hdev->lock in hci_conn_hash lookups that return hci_conn pointer, as dereferencing that without locks can be TOCTOU issue. It used to be several callsites did not hold appropriate locks. The check is equivalent to removing rcu_read_lock() and doing instead list_for_each_entry_rcu(c, &h->list, list, lockdep_is_held(&hdev->lock)) Although there should not be any remaining callsites without locks, don't remove the rcu_read_lock() for now, and just add the warning here. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index fa2a367731b5..b9583acc6c14 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1031,6 +1031,9 @@ static inline bool hci_conn_sc_enabled(struct hci_conn *conn) static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) { struct hci_conn_hash *h = &hdev->conn_hash; + + lockdep_assert_held(&hdev->lock); + list_add_tail_rcu(&c->list, &h->list); switch (c->type) { case ACL_LINK: @@ -1061,6 +1064,8 @@ static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) { struct hci_conn_hash *h = &hdev->conn_hash; + lockdep_assert_held(&hdev->lock); + list_del_rcu(&c->list); synchronize_rcu(); @@ -1089,6 +1094,15 @@ static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) } } +#ifdef CONFIG_PROVE_RCU +#define HCI_CONN_HASH_LOCKDEP_CHECK(hdev) \ + RCU_LOCKDEP_WARN(!lockdep_is_held(&(hdev)->lock) && \ + !rcu_read_lock_held(), \ + "suspicious hci_conn locking") +#else +#define HCI_CONN_HASH_LOCKDEP_CHECK(hdev) do { } while (0 && (hdev)) +#endif + static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) { struct hci_conn_hash *h = &hdev->conn_hash; @@ -1170,6 +1184,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_bis(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1192,6 +1208,8 @@ hci_conn_hash_lookup_create_pa_sync(struct hci_dev *hdev) struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1218,6 +1236,8 @@ hci_conn_hash_lookup_per_adv_bis(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1242,6 +1262,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1261,6 +1283,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1282,6 +1306,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_role(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1303,6 +1329,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1329,6 +1357,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1361,6 +1391,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_cig(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1384,6 +1416,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1408,6 +1442,8 @@ hci_conn_hash_lookup_big_sync_pend(struct hci_dev *hdev, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1432,6 +1468,8 @@ hci_conn_hash_lookup_big_state(struct hci_dev *hdev, __u8 handle, __u16 state, struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1455,6 +1493,8 @@ hci_conn_hash_lookup_pa_sync_big_handle(struct hci_dev *hdev, __u8 big) struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1478,6 +1518,8 @@ hci_conn_hash_lookup_pa_sync_handle(struct hci_dev *hdev, __u16 sync_handle) struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { @@ -1547,6 +1589,8 @@ static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev) struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn *c; + HCI_CONN_HASH_LOCKDEP_CHECK(hdev); + rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { From 15ad901d92a272327a7359b5560f1f24afa4975b Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 16 Aug 2026 12:47:03 +0300 Subject: [PATCH 1643/2126] Bluetooth: L2CAP: avoid maybe-return-locked in l2cap_get_chan_by_scid/dcid Replace the maybe-return-locked pattern in l2cap_get_chan_by_scid/dcid() by doing locking in the caller after NULL check. This allows adding context analysis annotations for the locking. Reviewed-by: Bart Van Assche Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index aaa2a1cd489a..d614eb86d621 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -109,7 +109,7 @@ static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, } /* Find channel with given SCID. - * Returns a reference locked channel. + * Returns a reference. */ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid) @@ -117,18 +117,14 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, struct l2cap_chan *c; c = __l2cap_get_chan_by_scid(conn, cid); - if (c) { - /* Only lock if chan reference is not 0 */ + if (c) c = l2cap_chan_hold_unless_zero(c); - if (c) - l2cap_chan_lock(c); - } return c; } /* Find channel with given DCID. - * Returns a reference locked channel. + * Returns a reference. */ static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid) @@ -136,12 +132,8 @@ static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn, struct l2cap_chan *c; c = __l2cap_get_chan_by_dcid(conn, cid); - if (c) { - /* Only lock if chan reference is not 0 */ + if (c) c = l2cap_chan_hold_unless_zero(c); - if (c) - l2cap_chan_lock(c); - } return c; } @@ -4382,6 +4374,8 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, return 0; } + l2cap_chan_lock(chan); + if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2 && chan->state != BT_CONNECTED) { cmd_reject_invalid_cid(conn, cmd->ident, chan->scid, @@ -4493,6 +4487,8 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, if (!chan) return 0; + l2cap_chan_lock(chan); + switch (result) { case L2CAP_CONF_SUCCESS: l2cap_conf_rfc_get(chan, rsp->data, len); @@ -4599,6 +4595,8 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, return 0; } + l2cap_chan_lock(chan); + rsp.dcid = cpu_to_le16(chan->scid); rsp.scid = cpu_to_le16(chan->dcid); l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp); @@ -4636,6 +4634,8 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, return 0; } + l2cap_chan_lock(chan); + if (chan->state != BT_DISCONN) { l2cap_chan_unlock(chan); l2cap_chan_put(chan); @@ -5139,6 +5139,8 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn, if (!chan) return -EBADSLT; + l2cap_chan_lock(chan); + max_credits = LE_FLOWCTL_MAX_CREDITS - chan->tx_credits; if (credits > max_credits) { BT_ERR("LE credits overflow"); @@ -7006,6 +7008,8 @@ static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid, return; } + l2cap_chan_lock(chan); + BT_DBG("chan %p, len %d", chan, skb->len); /* If we receive data on a fixed channel before the info req/rsp From 987935a58d289b78fc03b3c3c92942bf83d43830 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 16 Aug 2026 12:47:04 +0300 Subject: [PATCH 1644/2126] Bluetooth: L2CAP: add locking annotations for l2cap_chan_lock/unlock Add minimal context analysis annotations to l2cap_chan_lock/unlock() and callers required for no warnings. Reviewed-by: Bart Van Assche Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 2 ++ net/bluetooth/l2cap_core.c | 1 + net/bluetooth/l2cap_sock.c | 1 + 3 files changed, 4 insertions(+) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 3d9a32094347..69d193fee351 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -830,11 +830,13 @@ struct l2cap_chan *l2cap_chan_hold_unless_zero(struct l2cap_chan *c); void l2cap_chan_put(struct l2cap_chan *c); static inline void l2cap_chan_lock(struct l2cap_chan *chan) + __acquires(&chan->lock) { mutex_lock_nested(&chan->lock, atomic_read(&chan->nesting)); } static inline void l2cap_chan_unlock(struct l2cap_chan *chan) + __releases(&chan->lock) { mutex_unlock(&chan->lock); } diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index d614eb86d621..f09a353cbc66 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4096,6 +4096,7 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data, u8 rsp_code) + __context_unsafe(/* conditional locking */) { struct l2cap_conn_req *req = (struct l2cap_conn_req *) data; struct l2cap_conn_rsp rsp; diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 1194c37e466f..b553b6356af8 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1784,6 +1784,7 @@ static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state, static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan, unsigned long hdr_len, unsigned long len, int nb) + __must_hold(&chan->lock) { struct sock *sk = chan->data; struct sk_buff *skb; From 2f7f564fe3886d9e0522acbed437930edb3ed6ea Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 16 Aug 2026 12:47:05 +0300 Subject: [PATCH 1645/2126] Bluetooth: enable context analysis for headers Remove context analysis suppression for include/net/bluetooth/*, now that previous commits have resolved the warnings. Reviewed-by: Bart Van Assche Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- scripts/context-analysis-suppression.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/context-analysis-suppression.txt b/scripts/context-analysis-suppression.txt index 1c51b6153f08..d4476d9ed10a 100644 --- a/scripts/context-analysis-suppression.txt +++ b/scripts/context-analysis-suppression.txt @@ -32,3 +32,4 @@ src:*include/linux/seqlock*.h=emit src:*include/linux/spinlock*.h=emit src:*include/linux/srcu*.h=emit src:*include/linux/ww_mutex.h=emit +src:*include/net/bluetooth/*=emit From a3d984253d238ca35cc94aaa7dddb41f14987b44 Mon Sep 17 00:00:00 2001 From: Ibrahim Abdelkader Date: Mon, 17 Aug 2026 22:50:16 +0200 Subject: [PATCH 1646/2126] Bluetooth: hci_core: Return -ENOMEM when the sent_cmd clone fails hci_send_cmd_sync() returns -EINVAL when skb_clone() fails for sent_cmd, which describes an invalid argument rather than an allocation failure. Return -ENOMEM instead. The only caller, hci_cmd_work(), tests the result for zero, so there is no functional change. Signed-off-by: Ibrahim Abdelkader Signed-off-by: Hans de Goede Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 74d9865e08c2..61ed4aad2c71 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -4123,7 +4123,7 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb) if (!hdev->sent_cmd) { skb_queue_head(&hdev->cmd_q, skb); queue_work(hdev->workqueue, &hdev->cmd_work); - return -EINVAL; + return -ENOMEM; } if (hci_skb_opcode(skb) != HCI_OP_NOP) { From c0bb764fc082672678d371c375597a6a9f614cf9 Mon Sep 17 00:00:00 2001 From: Shuai Zhang Date: Tue, 18 Aug 2026 19:41:16 +0800 Subject: [PATCH 1647/2126] Bluetooth: mgmt: reply to cancelled mgmt commands instead of silently dropping The kernel sets HCI_AUTO_OFF when a controller is first registered and starts a 2-second timer. On slower boots bluetoothd and the HCI_AUTO_OFF timer can race: hci_power_off() is already queued while bluetoothd is still in the middle of its adapter setup sequence. hci_cmd_sync_clear() then cancels any pending mgmt commands with -ECANCELED, including the MGMT_OP_REMOVE_ADV_MONITOR sent by reset_adv_monitors() early in the setup sequence. When auto_off=1, hci_dev_close_sync() skips __mgmt_power_off() entirely, so there is no fallback path to reply to the cancelled commands. mgmt_remove_adv_monitor_complete() silently returns on -ECANCELED, leaving the command with no reply. Since bluez's mgmt queue is strictly serialised, this stalls all subsequent commands indefinitely, leaving bluetoothd unable to register the adapter. Fix by mapping -ECANCELED to MGMT_STATUS_CANCELLED in mgmt_errno_status() and replying to the cancelled command in mgmt_remove_adv_monitor_complete() instead of returning early. Signed-off-by: Shuai Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 251a896babd5..9b4688015abf 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -301,6 +301,8 @@ static u8 mgmt_errno_status(int err) return MGMT_STATUS_ALREADY_CONNECTED; case -ENOTCONN: return MGMT_STATUS_DISCONNECTED; + case -ECANCELED: + return MGMT_STATUS_CANCELLED; } return MGMT_STATUS_FAILED; @@ -5682,8 +5684,18 @@ static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd = data; struct mgmt_cp_remove_adv_monitor *cp; - if (status == -ECANCELED) + /* Reply to a cancelled command so bluetoothd's serialised mgmt queue + * is not blocked. + */ + if (status == -ECANCELED) { + cp = cmd->param; + rp.monitor_handle = cp->monitor_handle; + + mgmt_cmd_complete(cmd->sk, cmd->hdev->id, cmd->opcode, + mgmt_status(status), &rp, sizeof(rp)); + mgmt_pending_free(cmd); return; + } hci_dev_lock(hdev); From a504dcdb0b574a2bb00cd09378b6dee6d551f4a4 Mon Sep 17 00:00:00 2001 From: Chandrashekar Devegowda Date: Wed, 19 Aug 2026 20:02:17 +0530 Subject: [PATCH 1648/2126] Bluetooth: btintel_pcie: parse FW memory addresses via mailbox TLV Implement GP1 mailbox interrupt handling to receive memory region addresses from firmware via a TLV-based protocol. When firmware sends a BUILD_SPECIFIC_RESOURCES_MAPPING mailbox message, the driver reads a TLV table from device memory containing addresses and sizes of debug memory regions (exception dump, DCCM, SDS, ECL, SMEM). This enables the driver to dynamically discover dump region locations instead of using hardcoded addresses, supporting current and future Intel BT PCIe controller variants. Replace per-device hardcoded exception memory address and size constants in btintel_pcie_read_hwexp() with the dynamically populated values from dump_info, making exception dump handling consistent with other dump regions. Key changes: - Rewrite GP1 handler to parse mailbox registers and queue TLV work - Add btintel_parse_mbox_tlv() for parsing FW-provided TLV data - Add mbox_work workqueue for deferred TLV processing - Store parsed region addresses in btintel_pcie_dump_mem_info - Add cnvi_bt field to btintel_data for HW variant identification - Rename fw_git_sha1 to fw_sha for consistency - Remove hardcoded HWEXP address/size macros and use dump_info Assisted-by: GitHub-Copilot:claude-opus-4.7 Signed-off-by: Chandrashekar Devegowda Signed-off-by: Kiran K Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 7 + drivers/bluetooth/btintel.h | 1 + drivers/bluetooth/btintel_pcie.c | 349 +++++++++++++++++++++++++++++-- drivers/bluetooth/btintel_pcie.h | 53 ++++- 4 files changed, 387 insertions(+), 23 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index c69a5d226e88..cf109d79569a 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -66,6 +66,7 @@ static struct { const char *driver_name; u8 hw_variant; u32 fw_build_num; + u32 fw_sha; } coredump_info; const guid_t btintel_guid_dsm = @@ -569,6 +570,7 @@ int btintel_version_info_tlv(struct hci_dev *hdev, coredump_info.hw_variant = INTEL_HW_VARIANT(version->cnvi_bt); coredump_info.fw_build_num = version->build_num; + coredump_info.fw_sha = version->git_sha1; bt_dev_info(hdev, "%s timestamp %u.%u buildtype %u build %u", variant, 2000 + (version->timestamp >> 8), version->timestamp & 0xff, @@ -2382,6 +2384,7 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver, u32 *boot_param) { + struct btintel_data *intel_data = hci_get_priv(hdev); const struct firmware *fw; char fwname[128]; int err; @@ -2494,6 +2497,7 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev, btintel_reset_to_bootloader(hdev); done: + intel_data->cnvi_bt = ver->cnvi_bt; release_firmware(fw); return err; } @@ -3531,6 +3535,9 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev, btintel_version_info_tlv(hdev, &new_ver); + /* Update ver with the operational firmware version */ + *ver = new_ver; + finish: /* Set the event mask for Intel specific vendor events. This enables * a few extra events that are useful during general operation. It diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index 966ec1b02be2..ef232820c31b 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -247,6 +247,7 @@ enum { struct btintel_data { DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS); int (*acpi_reset_method)(struct hci_dev *hdev); + u32 cnvi_bt; }; #define btintel_set_flag(hdev, nr) \ diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index ac7193400769..b5540db17fec 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -75,14 +75,8 @@ struct btintel_pcie_dev_recovery { #define BTINTEL_PCIE_MAGIC_NUM 0xA5A5A5A5 -#define BTINTEL_PCIE_BLZR_HWEXP_SIZE 1024 -#define BTINTEL_PCIE_BLZR_HWEXP_DMP_ADDR 0xB00A7C00 -#define BTINTEL_PCIE_SCP_HWEXP_SIZE 4096 -#define BTINTEL_PCIE_SCP_HWEXP_DMP_ADDR 0xB030F800 -#define BTINTEL_PCIE_SCP2_HWEXP_SIZE 4096 -#define BTINTEL_PCIE_SCP2_HWEXP_DMP_ADDR 0xB031D000 #define BTINTEL_PCIE_MAGIC_NUM 0xA5A5A5A5 @@ -732,7 +726,7 @@ static int btintel_pcie_read_dram_buffers(struct btintel_pcie_data *data) sizeof(*tlv) + sizeof(data->dmp_hdr.write_ptr) + sizeof(*tlv) + sizeof(data->dmp_hdr.wrap_ctr) + sizeof(*tlv) + sizeof(data->dmp_hdr.trigger_reason) + - sizeof(*tlv) + sizeof(data->dmp_hdr.fw_git_sha1) + + sizeof(*tlv) + sizeof(data->dmp_hdr.fw_sha) + sizeof(*tlv) + sizeof(data->dmp_hdr.cnvr_top) + sizeof(*tlv) + sizeof(data->dmp_hdr.cnvi_top) + sizeof(*tlv) + strlen(ts) + @@ -781,8 +775,8 @@ static int btintel_pcie_read_dram_buffers(struct btintel_pcie_data *data) sizeof(data->dmp_hdr.wrap_ctr)); p = btintel_pcie_copy_tlv(p, BTINTEL_TRIGGER_REASON, &data->dmp_hdr.trigger_reason, sizeof(data->dmp_hdr.trigger_reason)); - p = btintel_pcie_copy_tlv(p, BTINTEL_FW_SHA, &data->dmp_hdr.fw_git_sha1, - sizeof(data->dmp_hdr.fw_git_sha1)); + p = btintel_pcie_copy_tlv(p, BTINTEL_FW_SHA, &data->dmp_hdr.fw_sha, + sizeof(data->dmp_hdr.fw_sha)); p = btintel_pcie_copy_tlv(p, BTINTEL_CNVR_TOP, &data->dmp_hdr.cnvr_top, sizeof(data->dmp_hdr.cnvr_top)); p = btintel_pcie_copy_tlv(p, BTINTEL_CNVI_TOP, &data->dmp_hdr.cnvi_top, @@ -963,10 +957,297 @@ static inline bool btintel_pcie_in_error(struct btintel_pcie_data *data) return data->boot_stage_cache & BTINTEL_PCIE_CSR_BOOT_STAGE_ABORT_HANDLER; } +static const char *btintel_pcie_tlv_str(u8 tlv_type) +{ + switch (tlv_type) { + case BTINTEL_PCIE_TLV_TYPE_EXCEPTION_DUMP_ADDRESS: + return "EXCEPTION_DUMP_ADDRESS"; + case BTINTEL_PCIE_TLV_TYPE_DCCM_MEM_ADDRESS: + return "DCCM_MEM_ADDRESS"; + case BTINTEL_PCIE_TLV_TYPE_SDS_MEM_ADDRESS: + return "SDS_MEM_ADDRESS"; + case BTINTEL_PCIE_TLV_TYPE_ECL_MEM_ADDRESS: + return "ECL_MEM_ADDRESS"; + case BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS: + return "SMEM_ADDRESS"; + default: + return "UNKNOWN"; + } +} + +static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) +{ + /* Custom TLV structure for mailbox parsing + * len is __le16 as per agreement with FW + */ + struct mbox_tlv { + u8 type; + __le16 len; + u8 val[]; + } __packed; + + u8 *buffer, *ptr; + u32 buffer_len, remaining; + int err; + u32 tbl_addr, tbl_size; + struct mbox_tlv *tlv; + struct btintel_data *cnvi_data = hci_get_priv(data->hdev); + u8 hw_variant = INTEL_HW_VARIANT(cnvi_data->cnvi_bt); + + memset(&data->dump_info, 0, sizeof(data->dump_info)); + + /* Snapshot to avoid TOCTOU with the GP1 IRQ handler */ + tbl_size = READ_ONCE(data->debug_table_size); + tbl_addr = READ_ONCE(data->debug_table_addr); + + if (!tbl_size || !tbl_addr) + return -EINVAL; + + /* Ensure size is 4-byte aligned; btintel_pcie_read_device_mem() + * reads device memory in 4-byte units. + */ + tbl_size = ALIGN_DOWN(tbl_size, 4); + + if (!tbl_size) + return -EINVAL; + + if (tbl_size > SZ_1M) { + bt_dev_err(data->hdev, "Debug table size too large: %u", + tbl_size); + return -EINVAL; + } + + buffer_len = tbl_size; + + buffer = vmalloc(buffer_len); + if (!buffer) + return -ENOMEM; + + btintel_pcie_mac_init(data); + + err = btintel_pcie_read_device_mem(data, buffer, tbl_addr, + buffer_len); + if (err) + goto exit_on_error; + + print_hex_dump(KERN_INFO, "Bluetooth: mbox_tlv: ", DUMP_PREFIX_OFFSET, 16, 1, + buffer, buffer_len, false); + + ptr = buffer; + remaining = buffer_len; + + /* Parse TLV structures: type(1) + length(2) + value */ + while (remaining >= sizeof(struct mbox_tlv)) { + u16 tlv_len; + u32 tlv_total; + + tlv = (struct mbox_tlv *)ptr; + tlv_len = le16_to_cpu(tlv->len); + tlv_total = sizeof(tlv->type) + + sizeof(tlv->len) + tlv_len; + + if (tlv_total > remaining) { + bt_dev_err(data->hdev, + "TLV parse error: type=%u, len=%u", + tlv->type, tlv_len); + break; + } + + switch (tlv->type) { + case BTINTEL_PCIE_TLV_TYPE_EXCEPTION_DUMP_ADDRESS: + if (tlv_len < 8) { + bt_dev_err(data->hdev, + "TLV %s too short: %u", + btintel_pcie_tlv_str(tlv->type), + tlv_len); + break; + } + data->dump_info.exception_dump_addr = + get_unaligned_le32(&tlv->val[0]); + data->dump_info.exception_dump_len = + get_unaligned_le32(&tlv->val[4]); + break; + case BTINTEL_PCIE_TLV_TYPE_DCCM_MEM_ADDRESS: + if (tlv_len < 8) { + bt_dev_err(data->hdev, + "TLV %s too short: %u", + btintel_pcie_tlv_str(tlv->type), + tlv_len); + break; + } + data->dump_info.dccm_addr_start = + get_unaligned_le32(&tlv->val[0]); + data->dump_info.dccm_addr_end = + get_unaligned_le32(&tlv->val[4]); + break; + case BTINTEL_PCIE_TLV_TYPE_SDS_MEM_ADDRESS: + /* hw_variant comes from cnvi_bt which is set during + * setup. If mailbox fires before setup completes, + * hw_variant is 0. Skip SDS parsing in that case. + */ + if (!hw_variant) { + bt_dev_dbg(data->hdev, "SDS TLV: skipped, hw_variant not yet known"); + break; + } + if (tlv_len == 16 && + hw_variant > BTINTEL_HWID_BZRI) { + data->dump_info.sds_start_addr_start = + get_unaligned_le32(&tlv->val[0]); + data->dump_info.sds_start_addr_end = + get_unaligned_le32(&tlv->val[4]); + data->dump_info.sds_iosf_data_addr_start = + get_unaligned_le32(&tlv->val[8]); + data->dump_info.sds_iosf_data_addr_end = + get_unaligned_le32(&tlv->val[12]); + } else if (tlv_len == 24 && + (hw_variant == BTINTEL_HWID_BZRI || + hw_variant == BTINTEL_HWID_BZRIW)) { + data->dump_info.sds_fixed_rom_addr_start = + get_unaligned_le32(&tlv->val[0]); + data->dump_info.sds_fixed_rom_addr_end = + get_unaligned_le32(&tlv->val[4]); + data->dump_info.sds_start_addr_start = + get_unaligned_le32(&tlv->val[8]); + data->dump_info.sds_start_addr_end = + get_unaligned_le32(&tlv->val[12]); + data->dump_info.sds_iosf_data_addr_start = + get_unaligned_le32(&tlv->val[16]); + data->dump_info.sds_iosf_data_addr_end = + get_unaligned_le32(&tlv->val[20]); + } else { + bt_dev_err(data->hdev, + "SDS TLV: hw=0x%2.2x len=%u", + hw_variant, tlv_len); + } + break; + case BTINTEL_PCIE_TLV_TYPE_ECL_MEM_ADDRESS: + if (tlv_len < 8) { + bt_dev_err(data->hdev, + "TLV %s too short: %u", + btintel_pcie_tlv_str(tlv->type), + tlv_len); + break; + } + data->dump_info.ecl_addr_start = + get_unaligned_le32(&tlv->val[0]); + data->dump_info.ecl_addr_end = + get_unaligned_le32(&tlv->val[4]); + break; + case BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS: + if (tlv_len < 8) { + bt_dev_err(data->hdev, + "TLV %s too short: %u", + btintel_pcie_tlv_str(tlv->type), + tlv_len); + break; + } + data->dump_info.smem_addr_start = + get_unaligned_le32(&tlv->val[0]); + data->dump_info.smem_addr_end = + get_unaligned_le32(&tlv->val[4]); + break; + default: + bt_dev_dbg(data->hdev, + "Unknown TLV type: %u length: %u", + tlv->type, tlv_len); + break; + } + + /* Move to next TLV */ + ptr += tlv_total; + remaining -= tlv_total; + } + + bt_dev_info(data->hdev, + "exception_dump: addr:0x%08x len:0x%08x", + data->dump_info.exception_dump_addr, + data->dump_info.exception_dump_len); + bt_dev_info(data->hdev, + "dccm: start:0x%08x end:0x%08x", + data->dump_info.dccm_addr_start, + data->dump_info.dccm_addr_end); + bt_dev_info(data->hdev, + "sds_fixed_rom: start:0x%08x end:0x%08x", + data->dump_info.sds_fixed_rom_addr_start, + data->dump_info.sds_fixed_rom_addr_end); + bt_dev_info(data->hdev, + "sds: start:0x%08x end:0x%08x", + data->dump_info.sds_start_addr_start, + data->dump_info.sds_start_addr_end); + bt_dev_info(data->hdev, + "sds_iosf: start:0x%08x end:0x%08x", + data->dump_info.sds_iosf_data_addr_start, + data->dump_info.sds_iosf_data_addr_end); + bt_dev_info(data->hdev, + "ecl: start:0x%08x end:0x%08x", + data->dump_info.ecl_addr_start, + data->dump_info.ecl_addr_end); + bt_dev_info(data->hdev, + "smem: start:0x%08x end:0x%08x", + data->dump_info.smem_addr_start, + data->dump_info.smem_addr_end); + + vfree(buffer); + return 0; + +exit_on_error: + vfree(buffer); + return err; +} + static void btintel_pcie_msix_gp1_handler(struct btintel_pcie_data *data) { - bt_dev_err(data->hdev, "Received gp1 mailbox interrupt"); - btintel_pcie_dump_debug_registers(data->hdev); + bool target_access = false; + u32 addr = 0, size = 0; + + /* Read the Mail box status and registers */ + data->mbox.mbox_status = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_MBOX_STATUS_REG); + if (data->mbox.mbox_status & BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX1) { + data->mbox.mbox1 = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_MBOX_1_REG); + if (data->mbox.mbox1 == + BTINTEL_PCIE_BUILD_SPECIFIC_RESOURCES_MAPPING) { + bt_dev_info(data->hdev, + "mailbox for target access"); + target_access = true; + } + } + + if (data->mbox.mbox_status & BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX2) { + data->mbox.mbox2 = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_MBOX_2_REG); + if (target_access) + addr = data->mbox.mbox2; + } + + if (data->mbox.mbox_status & BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX3) { + data->mbox.mbox3 = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_MBOX_3_REG); + if (target_access) + size = data->mbox.mbox3; + } + + if (data->mbox.mbox_status & BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX4) + data->mbox.mbox4 = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_MBOX_4_REG); + + bt_dev_dbg(data->hdev, + "GP1: sts:0x%08x mb1:0x%08x mb2:0x%08x mb3:0x%08x mb4:0x%08x", + data->mbox.mbox_status, data->mbox.mbox1, + data->mbox.mbox2, data->mbox.mbox3, + data->mbox.mbox4); + + if (target_access && + !test_and_set_bit(BTINTEL_PCIE_MAIL_BOX_INTR, + &data->flags)) { + WRITE_ONCE(data->debug_table_addr, addr); + WRITE_ONCE(data->debug_table_size, size); + if (!queue_work(data->dump_workqueue, + &data->mbox_work)) + clear_bit(BTINTEL_PCIE_MAIL_BOX_INTR, + &data->flags); + } + + /* Mailbox is read, ack to FW */ + btintel_pcie_set_reg_bits(data, + BTINTEL_PCIE_CSR_IPC_DOORBELL_VEC_REG, + BTINTEL_PCIE_CSR_DOORBELL_MBOX_READ_CONFIRM); } /* This function handles the MSI-X interrupt for gp0 cause (bit 0 in @@ -1298,7 +1579,8 @@ exit_error: static void btintel_pcie_read_hwexp(struct btintel_pcie_data *data) { - int len, err, offset, pending; + int err, offset, pending; + u32 len; struct sk_buff *skb; u8 *buf, prefix[64]; u32 addr, val; @@ -1318,23 +1600,30 @@ static void btintel_pcie_read_hwexp(struct btintel_pcie_data *data) /* only from step B0 onwards */ if (INTEL_CNVX_TOP_STEP(data->dmp_hdr.cnvi_top) != 0x01) return; - len = BTINTEL_PCIE_BLZR_HWEXP_SIZE; /* exception data length */ - addr = BTINTEL_PCIE_BLZR_HWEXP_DMP_ADDR; break; case BTINTEL_CNVI_SCP: - len = BTINTEL_PCIE_SCP_HWEXP_SIZE; - addr = BTINTEL_PCIE_SCP_HWEXP_DMP_ADDR; - break; case BTINTEL_CNVI_SCP2: case BTINTEL_CNVI_SCP2F: - len = BTINTEL_PCIE_SCP2_HWEXP_SIZE; - addr = BTINTEL_PCIE_SCP2_HWEXP_DMP_ADDR; break; default: bt_dev_err(data->hdev, "Unsupported cnvi 0x%8.8x", data->dmp_hdr.cnvi_top); return; } + len = data->dump_info.exception_dump_len; + addr = data->dump_info.exception_dump_addr; + + if (!addr || len < sizeof(__le32) || len > SZ_4K) { + bt_dev_err(data->hdev, "Invalid exception address: 0x%8.8x or length: %u", + addr, len); + return; + } + + /* Ensure size is 4-byte aligned; btintel_pcie_read_device_mem() + * reads device memory in 4-byte units. + */ + len = ALIGN_DOWN(len, 4); + buf = kzalloc(len, GFP_KERNEL); if (!buf) goto exit_on_error; @@ -1587,6 +1876,20 @@ out: clear_bit(BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS, &data->flags); } +static void btintel_pcie_mbox_worker(struct work_struct *work) +{ + struct btintel_pcie_data *data = container_of(work, + struct btintel_pcie_data, mbox_work); + + if (!data->hdev) + goto out; + + btintel_parse_mbox_tlv(data); +out: + /* Release guard last; matches set in gp1 handler. */ + clear_bit(BTINTEL_PCIE_MAIL_BOX_INTR, &data->flags); +} + static void btintel_pcie_rx_work(struct work_struct *work) { struct btintel_pcie_data *data = container_of(work, @@ -2428,6 +2731,7 @@ static int btintel_pcie_setup_internal(struct hci_dev *hdev) goto exit_error; } + data->dmp_hdr.cnvi_bt = ver_tlv.cnvi_bt; switch (INTEL_HW_PLATFORM(ver_tlv.cnvi_bt)) { case 0x37: break; @@ -2480,10 +2784,9 @@ static int btintel_pcie_setup_internal(struct hci_dev *hdev) data->dmp_hdr.fw_timestamp = ver_tlv.timestamp; data->dmp_hdr.fw_build_type = ver_tlv.build_type; data->dmp_hdr.fw_build_num = ver_tlv.build_num; - data->dmp_hdr.cnvi_bt = ver_tlv.cnvi_bt; if (ver_tlv.img_type == 0x02 || ver_tlv.img_type == 0x03) - data->dmp_hdr.fw_git_sha1 = ver_tlv.git_sha1; + data->dmp_hdr.fw_sha = ver_tlv.git_sha1; err = btintel_pcie_get_debug_info_addr(hdev); if (err) @@ -2763,6 +3066,7 @@ static void btintel_pcie_reset_work(struct work_struct *wk) disable_work_sync(&data->coredump_work); disable_work_sync(&data->hwexp_work); disable_work_sync(&data->fwtrigger_work); + disable_work_sync(&data->mbox_work); bt_dev_dbg(data->hdev, "Release bluetooth interface"); @@ -2787,6 +3091,7 @@ static void btintel_pcie_reset_work(struct work_struct *wk) enable_work(&data->coredump_work); enable_work(&data->hwexp_work); enable_work(&data->fwtrigger_work); + enable_work(&data->mbox_work); } out: @@ -3060,6 +3365,7 @@ static int btintel_pcie_probe(struct pci_dev *pdev, INIT_WORK(&data->coredump_work, btintel_pcie_coredump_worker); INIT_WORK(&data->hwexp_work, btintel_pcie_hwexp_worker); INIT_WORK(&data->fwtrigger_work, btintel_pcie_fwtrigger_worker); + INIT_WORK(&data->mbox_work, btintel_pcie_mbox_worker); data->boot_stage_cache = 0x00; data->img_resp_cache = 0x00; @@ -3129,6 +3435,7 @@ static void btintel_pcie_remove(struct pci_dev *pdev) disable_work_sync(&data->coredump_work); disable_work_sync(&data->hwexp_work); disable_work_sync(&data->fwtrigger_work); + disable_work_sync(&data->mbox_work); /* Cancel pending reset work. Skip only when remove() is called from * within the reset work itself (PLDR device_reprobe path) to avoid diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 749369b24031..5ceb2ba1276f 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -18,6 +18,7 @@ #define BTINTEL_PCIE_CSR_CI_ADDR_LSB_REG (BTINTEL_PCIE_CSR_BASE + 0x118) #define BTINTEL_PCIE_CSR_CI_ADDR_MSB_REG (BTINTEL_PCIE_CSR_BASE + 0x11C) #define BTINTEL_PCIE_CSR_IMG_RESPONSE_REG (BTINTEL_PCIE_CSR_BASE + 0x12C) +#define BTINTEL_PCIE_CSR_IPC_DOORBELL_VEC_REG (BTINTEL_PCIE_CSR_BASE + 0x130) #define BTINTEL_PCIE_CSR_MBOX_1_REG (BTINTEL_PCIE_CSR_BASE + 0x170) #define BTINTEL_PCIE_CSR_MBOX_2_REG (BTINTEL_PCIE_CSR_BASE + 0x174) #define BTINTEL_PCIE_CSR_MBOX_3_REG (BTINTEL_PCIE_CSR_BASE + 0x178) @@ -52,6 +53,8 @@ #define BTINTEL_PCIE_CSR_BOOT_STAGE_ALIVE (BIT(23)) #define BTINTEL_PCIE_CSR_BOOT_STAGE_D3_STATE_READY (BIT(24)) +#define BTINTEL_PCIE_CSR_DOORBELL_MBOX_READ_CONFIRM (BIT(4)) + /* Registers for MSI-X */ #define BTINTEL_PCIE_CSR_MSIX_BASE (0x2000) #define BTINTEL_PCIE_CSR_MSIX_FH_INT_CAUSES (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0800) @@ -121,7 +124,8 @@ enum { BTINTEL_PCIE_COREDUMP_INPROGRESS, BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS, BTINTEL_PCIE_RECOVERY_IN_PROGRESS, - BTINTEL_PCIE_SETUP_DONE + BTINTEL_PCIE_SETUP_DONE, + BTINTEL_PCIE_MAIL_BOX_INTR }; enum btintel_pcie_tlv_type { @@ -153,6 +157,14 @@ enum btintel_pcie_reset_type { BTINTEL_PCIE_IOSF_PRR_PLDR = 1, }; +enum btintel_pcie_mbox_msg { + BTINTEL_PCIE_NO_USE = 0, + BTINTEL_PCIE_TOP_SILENT_RESET, + BTINTEL_PCIE_SB_AUDIO_DEVICE_REPORT, + BTINTEL_PCIE_BUILD_SPECIFIC_RESOURCES_MAPPING, + BTINTEL_PCIE_LAST_MESSAGE = 4095 +}; + #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE BIT(7) /* Minimum and Maximum number of MSI-X Vector @@ -198,6 +210,12 @@ enum { /* RBD buffer size mapping */ #define BTINTEL_PCIE_RBD_SIZE_4K 0x04 +#define BTINTEL_PCIE_TLV_TYPE_EXCEPTION_DUMP_ADDRESS 0x04 +#define BTINTEL_PCIE_TLV_TYPE_DCCM_MEM_ADDRESS 0x05 +#define BTINTEL_PCIE_TLV_TYPE_SDS_MEM_ADDRESS 0x06 +#define BTINTEL_PCIE_TLV_TYPE_ECL_MEM_ADDRESS 0x07 +#define BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS 0x08 + /* * Struct for Context Information (v2) * @@ -424,6 +442,32 @@ struct btintel_pcie_dbgc { struct data_buf *bufs; }; +struct btintel_pcie_dump_mem_info { + u32 exception_dump_addr; + u32 exception_dump_len; + u32 dccm_addr_start; + u32 dccm_addr_end; + u32 sds_fixed_rom_addr_start; + u32 sds_fixed_rom_addr_end; + u32 sds_start_addr_start; + u32 sds_start_addr_end; + u32 sds_iosf_data_addr_start; + u32 sds_iosf_data_addr_end; + u32 ecl_addr_start; + u32 ecl_addr_end; + u32 smem_addr_start; + u32 smem_addr_end; +}; + +struct btintel_pcie_mbox { + u32 mbox_flags; + u32 mbox_status; + u32 mbox1; + u32 mbox2; + u32 mbox3; + u32 mbox4; +}; + struct btintel_pcie_dump_header { const char *driver_name; u32 cnvi_top; @@ -431,7 +475,7 @@ struct btintel_pcie_dump_header { u16 fw_timestamp; u8 fw_build_type; u32 fw_build_num; - u32 fw_git_sha1; + u32 fw_sha; u32 cnvi_bt; u32 write_ptr; u32 wrap_ctr; @@ -522,6 +566,7 @@ struct btintel_pcie_data { struct work_struct coredump_work; struct work_struct hwexp_work; struct work_struct fwtrigger_work; + struct work_struct mbox_work; struct dma_pool *dma_pool; dma_addr_t dma_p_addr; @@ -539,6 +584,10 @@ struct btintel_pcie_data { u8 pm_sx_event; u32 debug_evt_addr; u32 debug_evt_size; + dma_addr_t debug_table_addr; + u32 debug_table_size; + struct btintel_pcie_dump_mem_info dump_info; + struct btintel_pcie_mbox mbox; }; static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data, From d572ea4b621ce60279da5179a0c338660c8b7331 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 19 Aug 2026 20:02:18 +0530 Subject: [PATCH 1649/2126] Bluetooth: btintel_pcie: sync mbox tlv parsing with GP0 alive interrupt Performing a target access to read the mbox TLV table while the driver is concurrently posting RX buffers to the firmware causes the hardware to return 0 for the target address, resulting in an invalid/empty TLV parse. Add a synchronization handshake between the mbox TLV read operation performed by the mbox worker and the GP0 (alive) MSI-X interrupt (which signals completion of RX buffer posting). The worker now waits for the alive interrupt before initiating the target access, ensuring the hardware returns valid data. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Kiran K Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 42 +++++++++++++++++++++++++++++--- drivers/bluetooth/btintel_pcie.h | 10 +++++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index b5540db17fec..8906ea4b0ec9 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -993,6 +993,24 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) struct mbox_tlv *tlv; struct btintel_data *cnvi_data = hci_get_priv(data->hdev); u8 hw_variant = INTEL_HW_VARIANT(cnvi_data->cnvi_bt); + long t; + + /* Wait for GP0 alive interrupt to post RX buffers */ + t = wait_event_timeout(data->mbox_parse_wait_q, + test_bit(BTINTEL_PCIE_MBOX_PARSE_READY, &data->flags), + msecs_to_jiffies(BTINTEL_PCIE_MBOX_INTR_TIMEOUT_MS)); + if (!t) { + bt_dev_warn(data->hdev, + "Timeout (%u ms) waiting for alive interrupt before mbox TLV parse; skipping", + BTINTEL_PCIE_MBOX_INTR_TIMEOUT_MS); + return 0; + } + clear_bit(BTINTEL_PCIE_MBOX_PARSE_READY, &data->flags); + + bt_dev_info(data->hdev, + "mbox TLV parse started at %lld ns (%lld us after mbox interrupt)", + ktime_to_ns(ktime_get()), + ktime_to_us(ktime_sub(ktime_get(), data->mbox_intr_ts))); memset(&data->dump_info, 0, sizeof(data->dump_info)); @@ -1236,12 +1254,22 @@ static void btintel_pcie_msix_gp1_handler(struct btintel_pcie_data *data) if (target_access && !test_and_set_bit(BTINTEL_PCIE_MAIL_BOX_INTR, &data->flags)) { + /* Arm the mbox<->alive handshake */ + clear_bit(BTINTEL_PCIE_MBOX_PARSE_READY, &data->flags); + set_bit(BTINTEL_PCIE_MBOX_PARSE_PENDING, &data->flags); + data->mbox_intr_ts = ktime_get(); + + bt_dev_info(data->hdev, + "mbox interrupt received at %lld ns; queuing mbox_work", + ktime_to_ns(data->mbox_intr_ts)); + WRITE_ONCE(data->debug_table_addr, addr); WRITE_ONCE(data->debug_table_size, size); if (!queue_work(data->dump_workqueue, - &data->mbox_work)) - clear_bit(BTINTEL_PCIE_MAIL_BOX_INTR, - &data->flags); + &data->mbox_work)) { + clear_bit(BTINTEL_PCIE_MAIL_BOX_INTR, &data->flags); + clear_bit(BTINTEL_PCIE_MBOX_PARSE_PENDING, &data->flags); + } } /* Mailbox is read, ack to FW */ @@ -1351,6 +1379,12 @@ static void btintel_pcie_msix_gp0_handler(struct btintel_pcie_data *data) if (submit_rx) { btintel_pcie_reset_ia(data); btintel_pcie_start_rx(data); + + /* Complete the mbox<->alive handshake */ + if (test_and_clear_bit(BTINTEL_PCIE_MBOX_PARSE_PENDING, &data->flags)) { + set_bit(BTINTEL_PCIE_MBOX_PARSE_READY, &data->flags); + wake_up(&data->mbox_parse_wait_q); + } } if (signal_waitq) { @@ -3349,6 +3383,8 @@ static int btintel_pcie_probe(struct pci_dev *pdev, init_waitqueue_head(&data->tx_wait_q); data->tx_wait_done = false; + init_waitqueue_head(&data->mbox_parse_wait_q); + data->workqueue = alloc_ordered_workqueue(KBUILD_MODNAME, WQ_HIGHPRI); if (!data->workqueue) return -ENOMEM; diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 5ceb2ba1276f..5aff1dfa888f 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -125,7 +125,9 @@ enum { BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS, BTINTEL_PCIE_RECOVERY_IN_PROGRESS, BTINTEL_PCIE_SETUP_DONE, - BTINTEL_PCIE_MAIL_BOX_INTR + BTINTEL_PCIE_MAIL_BOX_INTR, + BTINTEL_PCIE_MBOX_PARSE_PENDING, + BTINTEL_PCIE_MBOX_PARSE_READY }; enum btintel_pcie_tlv_type { @@ -178,6 +180,7 @@ enum btintel_pcie_mbox_msg { /* Default interrupt timeout in msec */ #define BTINTEL_DEFAULT_INTR_TIMEOUT_MS 3000 +#define BTINTEL_PCIE_MBOX_INTR_TIMEOUT_MS 500 #define BTINTEL_PCIE_DX_TRANSITION_MAX_RETRIES 3 @@ -588,6 +591,11 @@ struct btintel_pcie_data { u32 debug_table_size; struct btintel_pcie_dump_mem_info dump_info; struct btintel_pcie_mbox mbox; + + /* Wait queue for mbox_worker to wait for GP0 alive interrupt */ + wait_queue_head_t mbox_parse_wait_q; + /* Timestamp captured in GP1 handler when mbox interrupt is received */ + ktime_t mbox_intr_ts; }; static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data, From 0d3f5d805bfff279da94e2ba38ff2724d27280e1 Mon Sep 17 00:00:00 2001 From: Catherine L Date: Wed, 19 Aug 2026 20:02:19 +0530 Subject: [PATCH 1650/2126] Bluetooth: btintel_pcie: Route debug traces to WiFi DBGC by default Set dbg_output_mode to 0x06 (BTINTEL_PCIE_WIFI_DBGC) by default so firmware debug traces are forwarded to the WiFi DBGC. In this mode: - Host DBGC fragment/data buffers are NOT allocated. - Context info publishes dbgc_addr/size as 0. Add a small helper btintel_pcie_dbg_to_wifi() driven by a cached dbg_path_cache field in struct btintel_pcie_data, initialized to BTINTEL_PCIE_WIFI_DBGC in probe. Signed-off-by: Kiran K Signed-off-by: Catherine L Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 43 +++++++++++++++++++++++++++++--- drivers/bluetooth/btintel_pcie.h | 16 ++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 8906ea4b0ec9..32f7b7067bf8 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -180,6 +180,15 @@ static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) } } +/* Returns true when firmware traces are routed to the WiFi DBGC. In that + * mode the host must not allocate DBGC buffers and must not publish their + * addresses in the context info. + */ +static inline bool btintel_pcie_dbg_to_wifi(struct btintel_pcie_data *data) +{ + return data->dbg_path_cache != BTINTEL_PCIE_DRAM; +} + /* This function initializes the memory for DBGC buffers and formats the * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and * size as the payload @@ -1864,6 +1873,15 @@ static void btintel_pcie_coredump_worker(struct work_struct *work) if (!data->hdev) goto out; + /* When firmware routes debug traces to the WiFi DBGC, no host + * DBGC buffers were allocated, so there is nothing to dump here. + */ + if (btintel_pcie_dbg_to_wifi(data)) { + bt_dev_info(data->hdev, + "Skipping coredump: debug traces routed to WiFi DBGC"); + goto out; + } + btintel_pcie_dump_traces(data->hdev); out: /* Release guard last so a new trigger can run only after this @@ -2261,9 +2279,18 @@ static void btintel_pcie_init_ci(struct btintel_pcie_data *data, ci->num_urbdq1 = data->rxq.count; ci->urbdq_db_vec = BTINTEL_PCIE_RXQ_NUM; - ci->dbg_output_mode = 0x01; - ci->dbgc_addr = data->dbgc.frag_p_addr; - ci->dbgc_size = data->dbgc.frag_size; + ci->dbg_output_mode = btintel_pcie_dbg_to_wifi(data) ? + BTINTEL_PCIE_WIFI_DBGC : BTINTEL_PCIE_DRAM; + if (btintel_pcie_dbg_to_wifi(data)) { + /* Firmware forwards debug traces to the WiFi DBGC, so no + * host DBGC buffer is needed; leave dbgc_addr/size as 0. + */ + ci->dbgc_addr = 0; + ci->dbgc_size = 0; + } else { + ci->dbgc_addr = data->dbgc.frag_p_addr; + ci->dbgc_size = data->dbgc.frag_size; + } ci->dbg_preset = 0x00; } @@ -2491,7 +2518,14 @@ static int btintel_pcie_alloc(struct btintel_pcie_data *data) v_addr += ci_size; /* Setup data buffers for dbgc */ - err = btintel_pcie_setup_dbgc(data); + if (btintel_pcie_dbg_to_wifi(data)) { + /* Firmware routes traces to the WiFi DBGC; skip host DBGC + * buffer allocation entirely. + */ + err = 0; + } else { + err = btintel_pcie_setup_dbgc(data); + } if (err) goto exit_error_txq; @@ -3405,6 +3439,7 @@ static int btintel_pcie_probe(struct pci_dev *pdev, data->boot_stage_cache = 0x00; data->img_resp_cache = 0x00; + data->dbg_path_cache = BTINTEL_PCIE_WIFI_DBGC; /* FLR can be invoked by echoing to debugfs path, so explicitly * initialized */ diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 5aff1dfa888f..9baa214d9bbe 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -94,6 +94,20 @@ /* Num of alloc Dbg buff (4) + (LSB(4), MSB(4), Size(4)) for each buffer */ #define BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE 196 +/* dbg_output_mode values for the context info. + * BTINTEL_PCIE_DRAM: firmware writes traces to host DRAM DBGC buffers. + * BTINTEL_PCIE_WIFI_DBGC: firmware forwards traces to the WiFi DBGC; the + * host does NOT need to allocate DBGC fragment/data buffers and must + * publish dbgc_addr/size as 0 in the context info. + * + * Encoding of BTINTEL_PCIE_WIFI_DBGC (0x06): + * Bit[0] DBGC O/P : 0 = SRAM (don't care, DBGI selected) + * Bit[1] DBGC I/P : 1 = DBGI + * Bits[2:3] DBGI O/P : 01 = WiFi DBGC + */ +#define BTINTEL_PCIE_DRAM 0x01 +#define BTINTEL_PCIE_WIFI_DBGC 0x06 + /* Causes for the FH register interrupts */ enum msix_fh_int_causes { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0 = BIT(0), /* cause 0 */ @@ -503,6 +517,7 @@ struct btintel_pcie_dump_header { * @hw_init_mask: initial unmaksed hw causes * @boot_stage_cache: cached value of boot stage register * @img_resp_cache: cached value of image response register + * @dbg_path_cache: cached debug output routing mode (BT DRAM or WiFi DBGC) * @cnvi: CNVi register value * @cnvr: CNVr register value * @gp0_received: condition for gp0 interrupt @@ -550,6 +565,7 @@ struct btintel_pcie_data { u32 boot_stage_cache; u32 img_resp_cache; + u32 dbg_path_cache; u32 cnvi; u32 cnvr; From b3078bb2ee127900c126491ed4c9ddcd1ead76b7 Mon Sep 17 00:00:00 2001 From: George Maraveyas Date: Sat, 22 Aug 2026 01:37:33 +0200 Subject: [PATCH 1651/2126] Bluetooth: mt7925: trigger reset on WMT timeout The MT7925 Bluetooth USB function can enumerate successfully after a warm reboot while the WMT function-control command remains unresponsive. When that command times out, btmtk_usb_setup() currently returns -ETIMEDOUT without entering the existing MediaTek reset path. The existing USB reset and recovery machinery is therefore never reached. For MT7925, call btmtk_reset_sync() when the WMT function-control command times out. This enters the existing reset path in btusb_mtk_reset(), which performs the MediaTek subsystem reset and queues a USB device reset. Runtime tracing on the affected hardware showed the resulting path through usb_queue_reset_device(), usb_reset_device() and usb_reset_and_verify_device(). When reset and verification could not restore the device, the USB core escalated to a logical disconnect and re-enumeration. Recovery succeeded in three controlled Windows-to-Linux tests. Runtime tracing showed the existing USB reset path escalating to logical disconnect and re-enumeration. In two of those tests, tracing continued through the subsequent enumeration failures and directly captured usb_acpi_port_prr_reset(), after which the MT7925 re-enumerated and Bluetooth recovered. These tests were performed on top of Chia-Lin Kao's ACPI _PRR hub patch, which remains a prerequisite for this patch. A fourth Windows-to-Linux test was then performed with the diagnostic btusb blacklist removed and btusb binding normally during boot. The WMT timeout reproduced and Bluetooth recovered automatically without manual intervention. Signed-off-by: George Maraveyas Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 7ea8bcd8a7ec..27111ce8aee1 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -1413,6 +1413,10 @@ int btmtk_usb_setup(struct hci_dev *hdev) err = btmtk_usb_hci_wmt_sync(hdev, &wmt_params); if (err < 0) { bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); + + if (dev_id == 0x7925 && err == -ETIMEDOUT) + btmtk_reset_sync(hdev); + return err; } From 8c947cd1c27d6493ed7e6630e168222454f53edb Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 25 Aug 2026 11:36:33 +0800 Subject: [PATCH 1652/2126] Bluetooth: btmtksdio: Remove redundant firmware filename override btmtksdio_setup() derives the firmware filename with btmtk_fw_get_filename() and then overwrites it with an snprintf() that open-codes that helper's fallback format. Commit 7f935b21bee4 ("Bluetooth: btmtk: apply the common btmtk_fw_get_filename") added the helper call without removing the snprintf() it was meant to replace. None of the device ids the helper special-cases can appear here: 0x6639, 0x7925 and the flavored 0x7961 belong to parts with no SDIO interface, and btmtksdio_setup() passes a flavor of 0 accordingly. The helper always falls through to the snprintf()'s own format, so both produce the same string and removing it is a no-op. Remove it anyway, since it silently defeats the helper for any device id the helper special-cases. Signed-off-by: Chris Lu Assisted-by: Claude:claude-opus-5 Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtksdio.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index f606174c606a..aaaa2a81ce96 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -1180,9 +1180,6 @@ static int btmtksdio_setup(struct hci_dev *hdev) btmtk_fw_get_filename(fwname, sizeof(fwname), dev_id, fw_version, 0); - snprintf(fwname, sizeof(fwname), - "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", - dev_id & 0xffff, (fw_version & 0xff) + 1); err = mt79xx_setup(hdev, fwname); if (err < 0) return err; From a2bb734c368766a2499ed00590ea838cac13c76e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 25 Aug 2026 11:36:34 +0800 Subject: [PATCH 1653/2126] Bluetooth: btmtksdio: Pass the hardware device id to mt79xx_setup() mt79xx_setup() passes a hardcoded 0 to btmtk_setup_firmware_79xx(), discarding the device id that btmtksdio_setup() has just read from register 0x70010200. That argument only gates the section filtering for MT6639, which has no SDIO interface, so this is a no-op on supported hardware and carries no Fixes: tag. Pass the value that has already been read, matching the USB path. Declare dev_id as u32 while at it, since that is what btmtksdio_mtk_reg_read() writes through the pointer. Signed-off-by: Chris Lu Assisted-by: Claude:claude-opus-5 Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtksdio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index aaaa2a81ce96..4d996d18652c 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -917,14 +917,14 @@ ignore_func_on: return 0; } -static int mt79xx_setup(struct hci_dev *hdev, const char *fwname) +static int mt79xx_setup(struct hci_dev *hdev, const char *fwname, u32 dev_id) { struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); struct btmtk_hci_wmt_params wmt_params; u8 param = 0x1; int err; - err = btmtk_setup_firmware_79xx(hdev, fwname, mtk_hci_wmt_sync, 0); + err = btmtk_setup_firmware_79xx(hdev, fwname, mtk_hci_wmt_sync, dev_id); if (err < 0) { bt_dev_err(hdev, "Failed to setup 79xx firmware (%d)", err); return err; @@ -1137,8 +1137,8 @@ static int btmtksdio_setup(struct hci_dev *hdev) ktime_t calltime, delta, rettime; unsigned long long duration; char fwname[64]; - int err, dev_id; - u32 fw_version = 0, val; + int err; + u32 dev_id, fw_version = 0, val; calltime = ktime_get(); set_bit(BTMTKSDIO_HW_TX_READY, &bdev->tx_state); @@ -1180,7 +1180,7 @@ static int btmtksdio_setup(struct hci_dev *hdev) btmtk_fw_get_filename(fwname, sizeof(fwname), dev_id, fw_version, 0); - err = mt79xx_setup(hdev, fwname); + err = mt79xx_setup(hdev, fwname, dev_id); if (err < 0) return err; From 385c0829e09e7a6380ae67998ac6ef6f4dfd5303 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:19:56 +0300 Subject: [PATCH 1654/2126] Bluetooth: L2CAP: take chan->lock for l2cap_chan_add/ready/del chan->lock must be held for __l2cap_chan_add as eg. calls to l2cap_chan_close assume chan->conn writes are guarded by it. It must be held for l2cap_chan_del() due to l2cap_sock.c:l2cap_chan_conn, l2cap_monitor_timeout, etc. Similarly it should be held for l2cap_ops::ready (assumed in 6lowpan.c). Also teardown usually has chan->lock held, it should always have it held to have the same locking context. The lock is not correctly held by l2cap_core in several places. Add the missing locks for l2cap_chan_del/add/ready(), except in l2cap_ecred_rsp_defer() which needs separate fix as it needs lock nesting. Fixes: 6fef032af009 ("Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb()") Signed-off-by: Pauli Virtanen Reported-by: Eulgyu Kim Reported-by: Jaeyoung Chung Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 3 ++- net/bluetooth/l2cap_core.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 69d193fee351..43a67562b238 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -973,7 +973,8 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator); void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan); int l2cap_ertm_init(struct l2cap_chan *chan); void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); -void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); +void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) + __must_hold(&chan->lock); typedef void (*l2cap_chan_func_t)(struct l2cap_chan *chan, void *data); void l2cap_chan_list(struct l2cap_conn *conn, l2cap_chan_func_t func, void *data); diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index f09a353cbc66..32213ab6ff07 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -665,7 +665,9 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) { mutex_lock(&conn->lock); + l2cap_chan_lock(chan); __l2cap_chan_add(conn, chan); + l2cap_chan_unlock(chan); mutex_unlock(&conn->lock); } @@ -4079,6 +4081,8 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, if (!chan) return NULL; + l2cap_chan_lock(chan); + l2cap_chan_set_defaults(chan, pchan); chan->ops = pchan->ops; @@ -4087,10 +4091,13 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, if (pchan->ops->new_connection && pchan->ops->new_connection(pchan, chan) < 0) { l2cap_chan_del(chan, 0); + l2cap_chan_unlock(chan); l2cap_chan_put(chan); return NULL; } + l2cap_chan_unlock(chan); + return chan; } @@ -5061,6 +5068,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, goto response_unlock; } + l2cap_chan_lock(chan); + bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->dst, &conn->hcon->dst); chan->src_type = bdaddr_src_type(conn->hcon); @@ -5094,6 +5103,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, result = L2CAP_CR_LE_SUCCESS; } + l2cap_chan_unlock(chan); + response_unlock: l2cap_chan_unlock(pchan); l2cap_chan_put(pchan); @@ -5286,6 +5297,8 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, continue; } + l2cap_chan_lock(chan); + bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->dst, &conn->hcon->dst); chan->src_type = bdaddr_src_type(conn->hcon); @@ -5318,6 +5331,8 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, } else { l2cap_chan_ready(chan); } + + l2cap_chan_unlock(chan); } unlock: From 608e0b7a675b2affbbf38167cad0fa63d8e064f7 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:19:57 +0300 Subject: [PATCH 1655/2126] Bluetooth: L2CAP: add l2cap_chan_close_unlocked() and locking helpers l2cap_chan_close() requires holding chan->lock and chan->conn->lock if associated chan->conn exists, to guard eg. conn->chan_l. Taking the locks with right ordering requires handling a race condition. Add helper function l2cap_chan_(un)lock_conn that do the locking right. Add l2cap_chan_close_unlocked() that does not require locks to be held, as all callsites do this lock -> close -> unlock pattern. Link: https://syzkaller.appspot.com/bug?extid=0e4ebcc970728e056324 Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 17 ++++++++++ net/bluetooth/l2cap_core.c | 61 ++++++++++++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 43a67562b238..84f557d354ca 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -962,6 +962,8 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); struct l2cap_chan *l2cap_chan_create(void); void l2cap_chan_close(struct l2cap_chan *chan, int reason); +void l2cap_chan_close_unlocked(struct l2cap_chan *chan, int reason) + __must_not_hold(&chan->lock); int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *dst, u8 dst_type, u16 timeout); int l2cap_chan_reconfigure(struct l2cap_chan *chan, __u16 mtu); @@ -988,4 +990,19 @@ void l2cap_conn_put(struct l2cap_conn *conn); int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); +bool l2cap_chan_lock_conn(struct l2cap_chan *chan) + __acquires(&chan->lock) __cond_acquires(true, &chan->conn->lock); + +/* Release macro for l2cap_chan_lock_conn, so context analysis understands it */ +#define l2cap_chan_unlock_conn(chan, conn_locked) \ + ({ \ + struct l2cap_chan *__chan = (chan); \ + struct l2cap_conn *__conn = __chan->conn; \ + l2cap_chan_unlock(__chan); \ + if (conn_locked) { \ + mutex_unlock(&__conn->lock); \ + l2cap_conn_put(__conn); \ + } \ + }) + #endif /* __L2CAP_H */ diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 32213ab6ff07..57150cb84cc8 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -59,6 +59,7 @@ static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control, static void l2cap_retrans_timeout(struct work_struct *work); static void l2cap_monitor_timeout(struct work_struct *work); static void l2cap_ack_timeout(struct work_struct *work); +static void __l2cap_chan_close(struct l2cap_chan *chan, int reason); static inline u8 bdaddr_type(u8 link_type, u8 bdaddr_type) { @@ -422,7 +423,7 @@ static void l2cap_chan_timeout(struct work_struct *work) else reason = ETIMEDOUT; - l2cap_chan_close(chan, reason); + __l2cap_chan_close(chan, reason); chan->ops->close(chan); @@ -829,7 +830,7 @@ static void l2cap_chan_connect_reject(struct l2cap_chan *chan) l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP, sizeof(rsp), &rsp); } -void l2cap_chan_close(struct l2cap_chan *chan, int reason) +static void __l2cap_chan_close(struct l2cap_chan *chan, int reason) { struct l2cap_conn *conn = chan->conn; @@ -878,8 +879,58 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason) break; } } + +void l2cap_chan_close(struct l2cap_chan *chan, int reason) +{ + __l2cap_chan_close(chan, reason); +} EXPORT_SYMBOL(l2cap_chan_close); +/* Take chan->lock. If chan->conn is non-NULL, take new reference on it, take + * chan->conn->lock, and return true. Otherwise return false. + */ +bool l2cap_chan_lock_conn(struct l2cap_chan *chan) + __context_unsafe(/* conditional locking */) +{ + /* Handle conn->lock > chan->lock ordering + race on chan->conn */ + for (;;) { + struct l2cap_conn *conn; + + l2cap_chan_lock(chan); + conn = chan->conn; + if (conn) + l2cap_conn_get(conn); + l2cap_chan_unlock(chan); + + if (conn) + mutex_lock(&conn->lock); + + l2cap_chan_lock(chan); + + if (chan->conn != conn) { + l2cap_chan_unlock(chan); + if (conn) { + mutex_unlock(&conn->lock); + l2cap_conn_put(conn); + } + schedule(); + continue; + } + + return chan->conn; + } +} + +void l2cap_chan_close_unlocked(struct l2cap_chan *chan, int reason) +{ + bool have_conn; + + have_conn = l2cap_chan_lock_conn(chan); + __l2cap_chan_close(chan, reason); + l2cap_chan_unlock_conn(chan, have_conn); +} +EXPORT_SYMBOL(l2cap_chan_close_unlocked); + static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) { switch (chan->chan_type) { @@ -1570,7 +1621,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn) if (!l2cap_mode_supported(chan->mode, conn->feat_mask) && test_bit(CONF_STATE2_DEVICE, &chan->conf_state)) { - l2cap_chan_close(chan, ECONNRESET); + __l2cap_chan_close(chan, ECONNRESET); l2cap_chan_unlock(chan); continue; } @@ -1578,7 +1629,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn) if (l2cap_check_enc_key_size(conn->hcon, chan)) l2cap_start_connection(chan); else - l2cap_chan_close(chan, ECONNREFUSED); + __l2cap_chan_close(chan, ECONNREFUSED); } else if (chan->state == BT_CONNECT2) { struct l2cap_conn_rsp rsp; @@ -7675,7 +7726,7 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt) __set_chan_timer(chan, L2CAP_ENC_TIMEOUT); } else if (chan->sec_level == BT_SECURITY_HIGH || chan->sec_level == BT_SECURITY_FIPS) - l2cap_chan_close(chan, ECONNREFUSED); + __l2cap_chan_close(chan, ECONNREFUSED); } else { if (chan->sec_level == BT_SECURITY_MEDIUM) __clear_chan_timer(chan); From 79ff49a72c06abdf76872dccc687e2a83c4f407f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:19:58 +0300 Subject: [PATCH 1656/2126] Bluetooth: L2CAP: fix race condition in l2cap_sock_shutdown() l2cap_sock_shutdown() has the race condition [Task 1] [Task 2] l2cap_sock_shutdown l2cap_sock_connect l2cap_chan_lock l2cap_chan_connect conn = ... /* == NULL*/ l2cap_chan_unlock ------------> l2cap_chan_lock if (conn) /* false */ __l2cap_chan_add(conn, chan) l2cap_chan_lock <-------------- l2cap_chan_unlock l2cap_chan_close /* chan->conn->lock not held! */ conn->lock protects conn->chan_l and is not properly held here. Use the l2cap_chan_close_unlocked() helper that ensures conn->lock is held for l2cap_chan_close(). Fixes: ab4eedb790ca ("Bluetooth: L2CAP: Fix corrupted list in hci_chan_del") Reported-by: Eulgyu Kim Reported-by: Jaeyoung Chung Link: https://lore.kernel.org/linux-bluetooth/20260824153908.2327306-1-jjy600901@snu.ac.kr/ Link: https://syzkaller.appspot.com/bug?extid=0e4ebcc970728e056324 Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index b553b6356af8..0265b6508682 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1406,7 +1406,6 @@ static int l2cap_sock_shutdown(struct socket *sock, int how) { struct sock *sk = sock->sk; struct l2cap_chan *chan; - struct l2cap_conn *conn; int err = 0; BT_DBG("sock %p, sk %p, how %d", sock, sk, how); @@ -1463,23 +1462,7 @@ static int l2cap_sock_shutdown(struct socket *sock, int how) sk->sk_shutdown |= SEND_SHUTDOWN; release_sock(sk); - l2cap_chan_lock(chan); - /* prevent conn structure from being freed */ - conn = l2cap_conn_hold_unless_zero(chan->conn); - l2cap_chan_unlock(chan); - - if (conn) - /* mutex lock must be taken before l2cap_chan_lock() */ - mutex_lock(&conn->lock); - - l2cap_chan_lock(chan); - l2cap_chan_close(chan, 0); - l2cap_chan_unlock(chan); - - if (conn) { - mutex_unlock(&conn->lock); - l2cap_conn_put(conn); - } + l2cap_chan_close_unlocked(chan, 0); lock_sock(sk); From a69dd52612ea6c763f76553e355ee03b981b4ed4 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:19:59 +0300 Subject: [PATCH 1657/2126] Bluetooth: 6lowpan: use l2cap_chan_close_unlocked() 6lowpan.c is using l2cap_chan_close() without taking chan->conn->lock, so it may modify conn->chan_l without holding the guarding lock. Fix the locking by using the l2cap_chan_close_unlocked() helper that acquires the necessary locks. Fixes: 15f32cabf426 ("Bluetooth: 6lowpan: add missing l2cap_chan_lock()") Link: https://syzkaller.appspot.com/bug?extid=0e4ebcc970728e056324 Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 30f4afa18bc8..4ea55950e599 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -921,9 +921,7 @@ static int bt_6lowpan_disconnect(struct l2cap_conn *conn, u8 dst_type) BT_DBG("peer %p chan %p", peer, peer->chan); - l2cap_chan_lock(peer->chan); - l2cap_chan_close(peer->chan, ENOENT); - l2cap_chan_unlock(peer->chan); + l2cap_chan_close_unlocked(peer->chan, ENOENT); return 0; } @@ -1025,9 +1023,9 @@ static void disconnect_all_peers(void) struct lowpan_peer *peer; int nchans; - /* l2cap_chan_close() cannot be called from RCU, and lock ordering - * chan->lock > devices_lock prevents taking write side lock, so copy - * then close. + /* l2cap_chan_close_unlocked() cannot be called from RCU, and lock + * ordering chan->lock > devices_lock prevents taking write side lock, + * so copy then close. */ rcu_read_lock(); @@ -1062,9 +1060,7 @@ done: spin_unlock(&devices_lock); for (i = 0; i < nchans; ++i) { - l2cap_chan_lock(chans[i]); - l2cap_chan_close(chans[i], ENOENT); - l2cap_chan_unlock(chans[i]); + l2cap_chan_close_unlocked(chans[i], ENOENT); l2cap_chan_put(chans[i]); } } while (nchans); @@ -1082,9 +1078,7 @@ static void do_enable_set(bool flag) mutex_lock(&set_lock); if (listen_chan) { - l2cap_chan_lock(listen_chan); - l2cap_chan_close(listen_chan, 0); - l2cap_chan_unlock(listen_chan); + l2cap_chan_close_unlocked(listen_chan, 0); l2cap_chan_put(listen_chan); } @@ -1132,9 +1126,7 @@ static ssize_t lowpan_control_write(struct file *fp, mutex_lock(&set_lock); if (listen_chan) { - l2cap_chan_lock(listen_chan); - l2cap_chan_close(listen_chan, 0); - l2cap_chan_unlock(listen_chan); + l2cap_chan_close_unlocked(listen_chan, 0); l2cap_chan_put(listen_chan); listen_chan = NULL; } @@ -1303,10 +1295,9 @@ static void __exit bt_6lowpan_exit(void) debugfs_remove(lowpan_control_debugfs); if (listen_chan) { - l2cap_chan_lock(listen_chan); - l2cap_chan_close(listen_chan, 0); - l2cap_chan_unlock(listen_chan); + l2cap_chan_close_unlocked(listen_chan, 0); l2cap_chan_put(listen_chan); + listen_chan = NULL; } disconnect_devices(); From 5ccdbf71f1e5e21adb3879fbdff5eeedabad2332 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:00 +0300 Subject: [PATCH 1658/2126] Bluetooth: L2CAP: remove unused l2cap_chan_close() l2cap_chan_close() is now unused, and l2cap_chan_close_unlocked() should be used instead. Remove l2cap_chan_close(). Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 1 - net/bluetooth/l2cap_core.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 84f557d354ca..e395ab5493f7 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -961,7 +961,6 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); struct l2cap_chan *l2cap_chan_create(void); -void l2cap_chan_close(struct l2cap_chan *chan, int reason); void l2cap_chan_close_unlocked(struct l2cap_chan *chan, int reason) __must_not_hold(&chan->lock); int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 57150cb84cc8..60bf7aeddb3e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -880,12 +880,6 @@ static void __l2cap_chan_close(struct l2cap_chan *chan, int reason) } } -void l2cap_chan_close(struct l2cap_chan *chan, int reason) -{ - __l2cap_chan_close(chan, reason); -} -EXPORT_SYMBOL(l2cap_chan_close); - /* Take chan->lock. If chan->conn is non-NULL, take new reference on it, take * chan->conn->lock, and return true. Otherwise return false. */ From df5175dfcf4879f6bcdadee614ac089e5627b721 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:01 +0300 Subject: [PATCH 1659/2126] Bluetooth: 6lowpan: avoid concurrent peer_del() in bt_6lowpan_disconnect bt_6lowpan_disconnect() looks up and accesses peer->chan, without holding locks guaranteeing peer_del() cannot free the peer concurrently. Take devices_lock to ensure peer can be dereferenced safely. Fixes: 15f32cabf426 ("Bluetooth: 6lowpan: add missing l2cap_chan_lock()") Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 4ea55950e599..ddcdd2aff91f 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -912,16 +912,27 @@ static int bt_6lowpan_connect(bdaddr_t *addr, u8 dst_type) static int bt_6lowpan_disconnect(struct l2cap_conn *conn, u8 dst_type) { struct lowpan_peer *peer; + struct l2cap_chan *chan; BT_DBG("conn %p dst type %u", conn, dst_type); + spin_lock(&devices_lock); + peer = lookup_peer(conn); - if (!peer) + if (!peer) { + spin_unlock(&devices_lock); return -ENOENT; + } - BT_DBG("peer %p chan %p", peer, peer->chan); + chan = peer->chan; + l2cap_chan_hold(chan); - l2cap_chan_close_unlocked(peer->chan, ENOENT); + spin_unlock(&devices_lock); + + BT_DBG("peer %p chan %p", peer, chan); + + l2cap_chan_close_unlocked(chan, ENOENT); + l2cap_chan_put(chan); return 0; } From 32d86e048d8efedb7aa6cbbd3c36c3c435401c92 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:02 +0300 Subject: [PATCH 1660/2126] Bluetooth: L2CAP: hold conn->lock for __l2cap_ecred_conn_rsp_defer __l2cap_ecred_conn_rsp_defer() > __l2cap_chan_list_id() accesses conn->chan_l which is guarded by conn->lock. The lock fails to be held when calling from l2cap_sock.c. Fix by using l2cap_chan_conn_lock(), and taking the locks in required order l2cap_conn::lock > l2cap_chan::lock > sk. Leave fast path with sk->sk_state precheck. Move the L2CAP defer handling to l2cap_sock_defer(). The code should also take l2cap_chan_lock() for sibling channels, but that needs separate fix due to lock nesting. Fixes: ab4eedb790ca ("Bluetooth: L2CAP: Fix corrupted list in hci_chan_del") Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 74 ++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 0265b6508682..dee3025f0ec2 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1243,6 +1243,54 @@ static void l2cap_publish_rx_avail(struct l2cap_chan *chan) l2cap_chan_rx_avail(chan, -1); } +static int l2cap_sock_defer(struct sock *sk) +{ + struct l2cap_chan *chan = l2cap_pi(sk)->chan; + bool have_conn; + int err = 0; + + /* Fast path check */ + lock_sock(sk); + if (sk->sk_state != BT_CONNECT2) { + release_sock(sk); + return 0; + } + release_sock(sk); + + have_conn = l2cap_chan_lock_conn(chan); + lock_sock(sk); + + if (sk->sk_state == BT_CONNECT2 && test_bit(BT_SK_DEFER_SETUP, + &bt_sk(sk)->flags)) { + err = 1; + + if (!have_conn) { + release_sock(sk); + err = -ENOTCONN; + } else if (chan->mode == L2CAP_MODE_EXT_FLOWCTL) { + sk->sk_state = BT_CONNECTED; + chan->state = BT_CONNECTED; + release_sock(sk); + __l2cap_ecred_conn_rsp_defer(chan); + } else if (bdaddr_type_is_le(chan->src_type)) { + sk->sk_state = BT_CONNECTED; + chan->state = BT_CONNECTED; + release_sock(sk); + __l2cap_le_connect_rsp_defer(chan); + } else { + sk->sk_state = BT_CONFIG; + chan->state = BT_CONFIG; + release_sock(sk); + __l2cap_connect_rsp_defer(chan); + } + } else { + release_sock(sk); + } + + l2cap_chan_unlock_conn(chan, have_conn); + return err; +} + static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int flags) { @@ -1254,29 +1302,9 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, return sock_recv_errqueue(sk, msg, len, SOL_BLUETOOTH, BT_SCM_ERROR); - lock_sock(sk); - - if (sk->sk_state == BT_CONNECT2 && test_bit(BT_SK_DEFER_SETUP, - &bt_sk(sk)->flags)) { - if (pi->chan->mode == L2CAP_MODE_EXT_FLOWCTL) { - sk->sk_state = BT_CONNECTED; - pi->chan->state = BT_CONNECTED; - __l2cap_ecred_conn_rsp_defer(pi->chan); - } else if (bdaddr_type_is_le(pi->chan->src_type)) { - sk->sk_state = BT_CONNECTED; - pi->chan->state = BT_CONNECTED; - __l2cap_le_connect_rsp_defer(pi->chan); - } else { - sk->sk_state = BT_CONFIG; - pi->chan->state = BT_CONFIG; - __l2cap_connect_rsp_defer(pi->chan); - } - - err = 0; - goto done; - } - - release_sock(sk); + err = l2cap_sock_defer(sk); + if (err) + return err < 0 ? err : 0; if (sock->type == SOCK_STREAM) err = bt_sock_stream_recvmsg(sock, msg, len, flags); From 115e6a21c88a5f708b2b025f7567ab78a782a74f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:03 +0300 Subject: [PATCH 1661/2126] Bluetooth: L2CAP: hold l2cap_conn::lock in l2cap_connect_cfm() l2cap_new_connection() -> __l2cap_chan_add() modifies l2cap_conn::chan_l, which is guarded by l2cap_conn::lock. The lock is not held in l2cap_connect_cfm(). Fix by holding conn->lock in l2cap_connect_cfm() to make the locking systematic. Fixes: ab4eedb790ca ("Bluetooth: L2CAP: Fix corrupted list in hci_chan_del") Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 60bf7aeddb3e..626be6b50363 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -7656,6 +7656,8 @@ static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status) * we left off, because the list lock would prevent calling the * potentially sleeping l2cap_chan_lock() function. */ + mutex_lock(&conn->lock); + pchan = l2cap_global_fixed_chan(NULL, hcon); while (pchan) { struct l2cap_chan *chan, *next; @@ -7680,6 +7682,8 @@ next: pchan = next; } + mutex_unlock(&conn->lock); + l2cap_conn_ready(conn); } From 889dfdde79e27e0f00b6fa08704e240a42c4ccac Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:04 +0300 Subject: [PATCH 1662/2126] Bluetooth: L2CAP: add annotations for l2cap_chan list locking Add context analysis annotations for l2cap_conn::chan_l and chan_list locking. Add corresponding required annotations to accessors and callers. This is not complete chan_l annotation, l2cap_chan::list and l2cap_chan_del() locking is currently not fully correct, and needs separate fix + annotations. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 7 ++-- net/bluetooth/l2cap_core.c | 61 ++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index e395ab5493f7..a991fc07515c 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -668,7 +668,7 @@ struct l2cap_conn { struct l2cap_chan *smp; - struct list_head chan_l; + struct list_head chan_l __guarded_by(&lock); struct mutex lock; struct kref ref; struct list_head users; @@ -954,7 +954,8 @@ void l2cap_cleanup_sockets(void); bool l2cap_is_socket(struct socket *sock); void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan); -void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan); +void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan) + __must_hold(&chan->lock) __must_hold(&chan->conn->lock); void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); @@ -975,7 +976,7 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan); int l2cap_ertm_init(struct l2cap_chan *chan); void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) - __must_hold(&chan->lock); + __must_hold(&conn->lock) __must_hold(&chan->lock); typedef void (*l2cap_chan_func_t)(struct l2cap_chan *chan, void *data); void l2cap_chan_list(struct l2cap_conn *conn, l2cap_chan_func_t func, void *data); diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 626be6b50363..68fc14344026 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -44,8 +44,8 @@ bool enable_ecred = IS_ENABLED(CONFIG_BT_LE_L2CAP_ECRED); static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN | L2CAP_FEAT_UCD; -static LIST_HEAD(chan_list); static DEFINE_RWLOCK(chan_list_lock); +static __guarded_by(&chan_list_lock) LIST_HEAD(chan_list); static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn, u8 code, u8 ident, u16 dlen, void *data); @@ -87,6 +87,7 @@ static inline u8 bdaddr_dst_type(struct hci_conn *hcon) static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid) + __must_hold(&conn->lock) { struct l2cap_chan *c; @@ -99,6 +100,7 @@ static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid) + __must_hold(&conn->lock) { struct l2cap_chan *c; @@ -114,6 +116,7 @@ static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, */ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid) + __must_hold(&conn->lock) { struct l2cap_chan *c; @@ -129,6 +132,7 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, */ static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid) + __must_hold(&conn->lock) { struct l2cap_chan *c; @@ -141,6 +145,7 @@ static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn, static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn, u8 ident) + __must_hold(&conn->lock) { struct l2cap_chan *c; @@ -153,6 +158,7 @@ static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn, static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src, u8 src_type) + __must_hold_shared(&chan_list_lock) { struct l2cap_chan *c; @@ -230,6 +236,7 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid) } static u16 l2cap_alloc_cid(struct l2cap_conn *conn) + __must_hold(&conn->lock) { u16 cid, dyn_end; @@ -728,6 +735,7 @@ EXPORT_SYMBOL_GPL(l2cap_chan_del); static void __l2cap_chan_list_id(struct l2cap_conn *conn, u16 id, l2cap_chan_func_t func, void *data) + __must_hold(&conn->lock) { struct l2cap_chan *chan, *l; @@ -739,6 +747,7 @@ static void __l2cap_chan_list_id(struct l2cap_conn *conn, u16 id, static void __l2cap_chan_list(struct l2cap_conn *conn, l2cap_chan_func_t func, void *data) + __must_hold(&conn->lock) { struct l2cap_chan *chan; @@ -806,6 +815,9 @@ static void l2cap_chan_ecred_connect_reject(struct l2cap_chan *chan) { l2cap_state_change(chan, BT_DISCONN); + lockdep_assert_held(&chan->lock); + lockdep_assert_held(&chan->conn->lock); + __l2cap_ecred_conn_rsp_defer(chan); } @@ -1423,6 +1435,7 @@ static void l2cap_ecred_defer_connect(struct l2cap_chan *chan, void *data) } static void l2cap_ecred_connect(struct l2cap_chan *chan) + __must_hold(&chan->conn->lock) { struct l2cap_conn *conn = chan->conn; struct l2cap_ecred_conn_data data; @@ -1456,6 +1469,7 @@ static void l2cap_ecred_connect(struct l2cap_chan *chan) } static void l2cap_le_start(struct l2cap_chan *chan) + __must_hold(&chan->conn->lock) { struct l2cap_conn *conn = chan->conn; @@ -1476,6 +1490,7 @@ static void l2cap_le_start(struct l2cap_chan *chan) } static void l2cap_start_connection(struct l2cap_chan *chan) + __must_hold(&chan->conn->lock) { if (chan->conn->hcon->type == LE_LINK) { l2cap_le_start(chan); @@ -1525,6 +1540,7 @@ static bool l2cap_check_enc_key_size(struct hci_conn *hcon, } static void l2cap_do_start(struct l2cap_chan *chan) + __must_hold(&chan->conn->lock) { struct l2cap_conn *conn = chan->conn; @@ -1591,6 +1607,7 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err) /* ---- L2CAP connections ---- */ static void l2cap_conn_start(struct l2cap_conn *conn) + __must_hold(&conn->lock) { struct l2cap_chan *chan, *tmp; @@ -1599,6 +1616,8 @@ static void l2cap_conn_start(struct l2cap_conn *conn) list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) { l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { l2cap_chan_ready(chan); l2cap_chan_unlock(chan); @@ -1715,6 +1734,8 @@ static void l2cap_conn_ready(struct l2cap_conn *conn) l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + if (hcon->type == LE_LINK) { l2cap_le_start(chan); } else if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { @@ -1737,6 +1758,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn) /* Notify sockets that we cannot guaranty reliability anymore */ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err) + __must_hold(&conn->lock) { struct l2cap_chan *chan; @@ -3034,6 +3056,7 @@ static void l2cap_pass_to_tx_fbit(struct l2cap_chan *chan, /* Copy frame to all raw sockets on that connection */ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb) + __must_hold(&conn->lock) { struct sk_buff *nskb; struct l2cap_chan *chan; @@ -4087,6 +4110,7 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len) static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data; @@ -4119,6 +4143,7 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, */ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, struct l2cap_chan *pchan) + __must_hold(&conn->lock) { struct l2cap_chan *chan; @@ -4148,6 +4173,7 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data, u8 rsp_code) + __must_hold(&conn->lock) __context_unsafe(/* conditional locking */) { struct l2cap_conn_req *req = (struct l2cap_conn_req *) data; @@ -4278,6 +4304,7 @@ response: static int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { if (cmd_len < sizeof(struct l2cap_conn_req)) return -EPROTO; @@ -4289,6 +4316,7 @@ static int l2cap_connect_req(struct l2cap_conn *conn, static int l2cap_connect_create_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_conn_rsp *rsp = (struct l2cap_conn_rsp *) data; u16 scid, dcid, result, status; @@ -4406,6 +4434,7 @@ static void cmd_reject_invalid_cid(struct l2cap_conn *conn, u8 ident, static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_conf_req *req = (struct l2cap_conf_req *) data; u16 dcid, flags; @@ -4519,6 +4548,7 @@ unlock: static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_conf_rsp *rsp = (struct l2cap_conf_rsp *)data; u16 scid, flags, result; @@ -4628,6 +4658,7 @@ done: static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_disconn_req *req = (struct l2cap_disconn_req *) data; struct l2cap_disconn_rsp rsp; @@ -4669,6 +4700,7 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_disconn_rsp *rsp = (struct l2cap_disconn_rsp *) data; u16 dcid, scid; @@ -4756,6 +4788,7 @@ static inline int l2cap_information_req(struct l2cap_conn *conn, static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) data; u16 type, result; @@ -4863,6 +4896,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn, static int l2cap_le_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_le_conn_rsp *rsp = (struct l2cap_le_conn_rsp *) data; struct hci_conn *hcon = conn->hcon; @@ -4969,6 +5003,7 @@ static void l2cap_put_ident(struct l2cap_conn *conn, u8 code, u8 id) static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { int err = 0; @@ -5030,6 +5065,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn, static int l2cap_le_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_le_conn_req *req = (struct l2cap_le_conn_req *) data; struct l2cap_le_conn_rsp rsp; @@ -5178,6 +5214,7 @@ response: static inline int l2cap_le_credits(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_le_credits *pkt; struct l2cap_chan *chan; @@ -5227,6 +5264,7 @@ unlock: static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_ecred_conn_req *req = (void *) data; DEFINE_RAW_FLEX(struct l2cap_ecred_conn_rsp, pdu, dcid, L2CAP_ECRED_MAX_CID); @@ -5399,6 +5437,7 @@ response: static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_ecred_conn_rsp *rsp = (void *) data; struct hci_conn *hcon = conn->hcon; @@ -5526,6 +5565,7 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, static inline int l2cap_ecred_reconf_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_ecred_reconf_req *req = (void *) data; struct l2cap_ecred_reconf_rsp rsp; @@ -5624,6 +5664,7 @@ respond: static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_chan *chan, *tmp; struct l2cap_ecred_reconf_rsp *rsp = (void *)data; @@ -5664,6 +5705,7 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn, static inline int l2cap_le_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data; struct l2cap_chan *chan; @@ -5691,6 +5733,7 @@ done: static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data) + __must_hold(&conn->lock) { int err = 0; @@ -5755,6 +5798,7 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn, static inline void l2cap_le_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) + __must_hold(&conn->lock) { struct hci_conn *hcon = conn->hcon; struct l2cap_cmd_hdr *cmd; @@ -5813,6 +5857,7 @@ static inline void l2cap_sig_send_mtu_rej(struct l2cap_conn *conn, u8 ident) static inline void l2cap_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) + __must_hold(&conn->lock) { struct hci_conn *hcon = conn->hcon; struct l2cap_cmd_hdr *cmd; @@ -7058,6 +7103,7 @@ failed: static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk_buff *skb) + __must_hold(&conn->lock) { struct l2cap_chan *chan; @@ -7166,6 +7212,7 @@ free_skb: } static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) + __must_hold(&conn->lock) { struct l2cap_hdr *lh = (void *) skb->data; struct hci_conn *hcon = conn->hcon; @@ -7275,9 +7322,9 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon) hci_dev_test_flag(hcon->hdev, HCI_FORCE_BREDR_SMP))) conn->local_fixed_chan |= L2CAP_FC_SMP_BREDR; - mutex_init(&conn->lock); - - INIT_LIST_HEAD(&conn->chan_l); + scoped_guard(mutex_init, &conn->lock) { + INIT_LIST_HEAD(&conn->chan_l); + } INIT_LIST_HEAD(&conn->users); INIT_DELAYED_WORK(&conn->info_timer, l2cap_info_timeout); @@ -7493,6 +7540,8 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, __l2cap_chan_add(conn, chan); + lockdep_assert_held(&chan->conn->lock); + /* l2cap_chan_add takes its own ref so we can drop this one */ hci_conn_drop(hcon); @@ -7715,6 +7764,8 @@ static void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason) } static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt) + __must_hold(&chan->lock) + __must_hold(&chan->conn->lock) { if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) return; @@ -7747,6 +7798,8 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) list_for_each_entry(chan, &conn->chan_l, list) { l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + BT_DBG("chan %p scid 0x%4.4x state %s", chan, chan->scid, state_to_string(chan->state)); From b508a2a2d846ccc4c8f691e4e3dfca6f97dfe85a Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:06 +0300 Subject: [PATCH 1663/2126] Bluetooth: L2CAP: hold chan in l2cap_ecred_conn_rsp() l2cap_chan_del() calls l2cap_chan_put() to drop the conn->chan_l reference. If this was the last reference, UAF follows. l2cap_ecred_conn_rsp() iterates chan_l list and calls l2cap_chan_del() on some members, without holding chan reference. Fix by holding refcount while using chan after l2cap_chan_del(). Since orig is looked up by dcid provided by remote, it's also possible orig == chan, so reference needs to be held also after orig use. Fixes: 41c2713b204e ("Bluetooth: L2CAP: Fix possible crash on l2cap_ecred_conn_rsp") Assisted-by: deepseek-v4-flash Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 68fc14344026..93dade523416 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -5468,12 +5468,14 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, chan->state == BT_CONNECTED) continue; + l2cap_chan_hold(chan); l2cap_chan_lock(chan); /* Check that there is a dcid for each pending channel */ if (cmd_len < sizeof(dcid)) { l2cap_chan_del(chan, ECONNREFUSED); l2cap_chan_unlock(chan); + l2cap_chan_put(chan); continue; } @@ -5512,6 +5514,8 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, __set_chan_timer(orig, 0); l2cap_chan_unlock(orig); } + + l2cap_chan_put(chan); continue; } @@ -5557,6 +5561,7 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, } l2cap_chan_unlock(chan); + l2cap_chan_put(chan); } return err; From aba67d585b993a5a2d6c93181bd2ec50a25cf4c7 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:09 +0300 Subject: [PATCH 1664/2126] Bluetooth: L2CAP: make concurrent l2cap_set_timer() refcounting safe Since l2cap_set_timer() does not check return value of schedule_delayed_work(), two concurrent calls may result to l2cap_chan refcount leak. Change the refcounting by using mod_delayed_work() and checking its return value. Code paths aside from l2cap_chan_busy() hold chan->lock, so this has little correctness impact. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index a991fc07515c..2315a3993c7b 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -847,12 +847,11 @@ static inline void l2cap_set_timer(struct l2cap_chan *chan, BT_DBG("chan %p state %s timeout %ld", chan, state_to_string(chan->state), timeout); - /* If delayed work cancelled do not hold(chan) - since it is already done with previous set_timer */ - if (!cancel_delayed_work(work)) - l2cap_chan_hold(chan); + l2cap_chan_hold(chan); - schedule_delayed_work(work, timeout); + /* put(chan) if timer was already queued so it already has a ref */ + if (mod_delayed_work(system_percpu_wq, work, timeout)) + l2cap_chan_put(chan); } static inline bool l2cap_clear_timer(struct l2cap_chan *chan, From 6098ed784e2cade6eb39e20254e98cec54084194 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 29 Aug 2026 17:20:10 +0300 Subject: [PATCH 1665/2126] Bluetooth: L2CAP: remove conditional locking from l2cap_connect() Context analysis does not understand conditional locking. Restructure l2cap_connect() by removing conditional locking at the cost of some code duplication, so that static analysis can see its content. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 93dade523416..4294cab61d3e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4174,7 +4174,6 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data, u8 rsp_code) __must_hold(&conn->lock) - __context_unsafe(/* conditional locking */) { struct l2cap_conn_req *req = (struct l2cap_conn_req *) data; struct l2cap_conn_rsp rsp; @@ -4191,7 +4190,13 @@ static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, &conn->hcon->dst, ACL_LINK); if (!pchan) { result = L2CAP_CR_BAD_PSM; - goto response; + + rsp.scid = cpu_to_le16(scid); + rsp.dcid = cpu_to_le16(dcid); + rsp.result = cpu_to_le16(result); + rsp.status = cpu_to_le16(status); + l2cap_send_cmd(conn, cmd->ident, rsp_code, sizeof(rsp), &rsp); + return; } l2cap_chan_lock(pchan); @@ -4273,9 +4278,6 @@ response: rsp.status = cpu_to_le16(status); l2cap_send_cmd(conn, cmd->ident, rsp_code, sizeof(rsp), &rsp); - if (!pchan) - return; - if (result == L2CAP_CR_PEND && status == L2CAP_CS_NO_INFO) { struct l2cap_info_req info; info.type = cpu_to_le16(L2CAP_IT_FEAT_MASK); From dc1ddc65f06df44dfcfe51955c82a132acb3ab8d Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 2 Sep 2026 00:04:33 +0300 Subject: [PATCH 1666/2126] Bluetooth: L2CAP: take lock for l2cap_chan_del in l2cap_ecred_rsp_defer l2cap_ecred_rsp_defer() calls l2cap_chan_del without holding chan->lock, which ends up calling ops->teardown() with wrong lock context. Fix by taking chan->lock in l2cap_ecred_rsp_defer(). AB-BA deadlocks between sibling l2cap_chan are avoided here via requiring l2cap_conn::lock to serialize all nested l2cap_chan locking on same nesting level. In current code, there is no nested l2cap_chan locking on same nesting level, so we can add this new requirement. Also return early from __l2cap_ecred_conn_rsp_defer() if chan did not have FLAG_DEFER_SETUP, as then no RSP shall be sent for it, to make sure SMP channels are excluded. Also hold chan reference over l2cap_chan_del(), in case chan_l reference was the last. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 4 +++ net/bluetooth/l2cap_core.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 2315a3993c7b..c7e642abe404 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -758,6 +758,10 @@ enum { * otherwise considers all channels equal and will e.g. complain about a * connection oriented channel triggering SMP procedures or a listening * channel creating and locking a child channel. + * + * Lock nesting of channels at the same nesting level is allowed if the channels + * have the same l2cap_chan::conn and l2cap_chan::conn.lock is taken before the + * nested locks. l2cap_chan_try_sibling_lock() must be used. */ enum { L2CAP_NESTING_SMP, diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 4294cab61d3e..6cd909bba1c7 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -848,6 +848,8 @@ static void __l2cap_chan_close(struct l2cap_chan *chan, int reason) BT_DBG("chan %p state %s", chan, state_to_string(chan->state)); + lockdep_assert_held(&chan->lock); + switch (chan->state) { case BT_LISTEN: chan->ops->teardown(chan, 0); @@ -3950,6 +3952,7 @@ static void l2cap_ecred_list_defer(struct l2cap_chan *chan, void *data) } struct l2cap_ecred_rsp_data { + struct l2cap_chan *locked_chan; struct { struct l2cap_ecred_conn_rsp_hdr rsp; __le16 scid[L2CAP_ECRED_MAX_CID]; @@ -3957,11 +3960,42 @@ struct l2cap_ecred_rsp_data { int count; }; +/* Lock @chan if it is not @locked_chan, and has same or lower nesting level. + * + * They must have the same chan->conn, and conn->lock must be held. + * + * Caller must ensure @chan has lock nesting level <= that of @locked_chan, as + * nested locking of l2cap_chan of different levels is allowed also without + * holding conn->lock. + * + * See l2cap.h for the global l2cap_chan locking rules. + */ +static bool l2cap_chan_try_sibling_lock(struct l2cap_chan *chan, + struct l2cap_chan *locked_chan) + __must_hold(&locked_chan->lock) + __must_hold(&locked_chan->conn->lock) + __cond_acquires(true, &chan->lock) +{ + if (chan == locked_chan) + return false; + + if (WARN_ON_ONCE(locked_chan->conn != chan->conn)) + return false; + + if (WARN_ON_ONCE(atomic_read(&locked_chan->nesting) + < atomic_read(&chan->nesting))) + return false; + + mutex_lock_nest_lock(&chan->lock, &locked_chan->conn->lock); + return true; +} + static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data) { struct l2cap_ecred_rsp_data *rsp = data; struct l2cap_ecred_conn_rsp *rsp_flex = container_of(&rsp->pdu.rsp, struct l2cap_ecred_conn_rsp, hdr); + bool locked; if (chan->mode != L2CAP_MODE_EXT_FLOWCTL) return; @@ -3973,6 +4007,22 @@ static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data) !test_and_clear_bit(FLAG_DEFER_SETUP, &chan->flags)) return; + lockdep_assert_held(&rsp->locked_chan->lock); + lockdep_assert_held(&rsp->locked_chan->conn->lock); + + l2cap_chan_hold(chan); + + locked = l2cap_chan_try_sibling_lock(chan, rsp->locked_chan); + + /* Cannot occur: PARENT channels do not appear in chan_l, and SMP + * channels never have FLAG_DEFER_SETUP. + */ + if (context_unsafe(!locked && chan != rsp->locked_chan)) + goto done; + + lockdep_assert_held(&chan->lock); + lockdep_assert_held(&chan->conn->lock); + /* Reset ident so only one response is sent */ chan->ident = 0; @@ -3985,6 +4035,12 @@ static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data) rsp_flex->dcid[rsp->count++] = cpu_to_le16(chan->scid); else l2cap_chan_del(chan, ECONNRESET); + +done: + if (locked) + l2cap_chan_unlock(chan); + + l2cap_chan_put(chan); } void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan) @@ -3996,11 +4052,15 @@ void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan) if (!id) return; + if (!test_bit(FLAG_DEFER_SETUP, &chan->flags)) + return; BT_DBG("chan %p id %d", chan, id); memset(&data, 0, sizeof(data)); + data.locked_chan = chan; + data.pdu.rsp.mtu = cpu_to_le16(chan->imtu); data.pdu.rsp.mps = cpu_to_le16(chan->mps); data.pdu.rsp.credits = cpu_to_le16(chan->rx_credits); From 0e4d951a2fceeda4791bdd962a8b295f8cac6945 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 2 Sep 2026 00:04:34 +0300 Subject: [PATCH 1667/2126] Bluetooth: L2CAP: annotate locking for l2cap_chan_del() Add context analysis annotations for chan->lock and chan->conn->lock involving l2cap_chan_del() usage. Add necessary annotations and related lockdep_assert_held to callers. Move struct l2cap_ops definition after struct l2cap_conn, so that the callbacks can be annotated. In l2cap_chan_close_unlocked() we consider chan->conn->lock as locked even if chan->conn == NULL, to avoid needing to define separate __l2cap_chan_close/del for this NULL case. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 56 +++++++++++++++++++---------------- net/bluetooth/6lowpan.c | 2 ++ net/bluetooth/l2cap_core.c | 49 +++++++++++++++++++++++++----- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index c7e642abe404..3e1e2b36d7b6 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -614,31 +614,6 @@ struct l2cap_chan { struct mutex lock; }; -struct l2cap_ops { - char *name; - - int (*new_connection)(struct l2cap_chan *chan, - struct l2cap_chan *new_chan); - int (*recv) (struct l2cap_chan * chan, - struct sk_buff *skb); - void (*teardown) (struct l2cap_chan *chan, int err); - void (*close) (struct l2cap_chan *chan); - void (*state_change) (struct l2cap_chan *chan, - int state, int err); - void (*ready) (struct l2cap_chan *chan); - void (*defer) (struct l2cap_chan *chan); - void (*resume) (struct l2cap_chan *chan); - void (*suspend) (struct l2cap_chan *chan); - void (*set_shutdown) (struct l2cap_chan *chan); - long (*get_sndtimeo) (struct l2cap_chan *chan); - struct pid *(*get_peer_pid) (struct l2cap_chan *chan); - struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, - unsigned long hdr_len, - unsigned long len, int nb); - int (*filter) (struct l2cap_chan * chan, - struct sk_buff *skb); -}; - struct l2cap_conn { struct hci_conn *hcon; struct hci_chan *hchan; @@ -674,6 +649,34 @@ struct l2cap_conn { struct list_head users; }; +struct l2cap_ops { + char *name; + + int (*new_connection)(struct l2cap_chan *chan, + struct l2cap_chan *new_chan); + int (*recv) (struct l2cap_chan * chan, + struct sk_buff *skb); + void (*teardown) (struct l2cap_chan *chan, int err) + __must_hold(&chan->lock); + void (*close) (struct l2cap_chan *chan); + void (*state_change) (struct l2cap_chan *chan, + int state, int err); + void (*ready) (struct l2cap_chan *chan) + __must_hold(&chan->lock) + __must_hold(&chan->conn->lock); + void (*defer) (struct l2cap_chan *chan); + void (*resume) (struct l2cap_chan *chan); + void (*suspend) (struct l2cap_chan *chan); + void (*set_shutdown) (struct l2cap_chan *chan); + long (*get_sndtimeo) (struct l2cap_chan *chan); + struct pid *(*get_peer_pid) (struct l2cap_chan *chan); + struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, + unsigned long hdr_len, + unsigned long len, int nb); + int (*filter) (struct l2cap_chan * chan, + struct sk_buff *skb); +}; + struct l2cap_user { struct list_head list; int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); @@ -983,7 +986,8 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) typedef void (*l2cap_chan_func_t)(struct l2cap_chan *chan, void *data); void l2cap_chan_list(struct l2cap_conn *conn, l2cap_chan_func_t func, void *data); -void l2cap_chan_del(struct l2cap_chan *chan, int err); +void l2cap_chan_del(struct l2cap_chan *chan, int err) + __must_hold(&chan->lock) __must_hold(&chan->conn->lock); void l2cap_send_conn_req(struct l2cap_chan *chan); struct l2cap_conn *l2cap_conn_get(struct l2cap_conn *conn); diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index ddcdd2aff91f..836add41f5d1 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -722,6 +722,8 @@ out: } static inline void chan_ready_cb(struct l2cap_chan *chan) + __must_hold(&chan->lock) + __must_hold(&chan->conn->lock) { struct lowpan_btle_dev *dev; bool new_netdev = false; diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 6cd909bba1c7..67efbbc90b2b 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -59,7 +59,8 @@ static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control, static void l2cap_retrans_timeout(struct work_struct *work); static void l2cap_monitor_timeout(struct work_struct *work); static void l2cap_ack_timeout(struct work_struct *work); -static void __l2cap_chan_close(struct l2cap_chan *chan, int reason); +static void __l2cap_chan_close(struct l2cap_chan *chan, int reason) + __must_hold(&chan->lock) __must_hold(&chan->conn->lock); static inline u8 bdaddr_type(u8 link_type, u8 bdaddr_type) { @@ -681,6 +682,8 @@ void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) void l2cap_chan_del(struct l2cap_chan *chan, int err) { + lockdep_assert(!chan->conn || lockdep_is_held(&chan->conn->lock)); + __clear_chan_timer(chan); BT_DBG("chan %p, err %d, state %s", chan, err, @@ -812,12 +815,11 @@ static void l2cap_chan_le_connect_reject(struct l2cap_chan *chan) } static void l2cap_chan_ecred_connect_reject(struct l2cap_chan *chan) + __must_hold(&chan->lock) + __must_hold(&chan->conn->lock) { l2cap_state_change(chan, BT_DISCONN); - lockdep_assert_held(&chan->lock); - lockdep_assert_held(&chan->conn->lock); - __l2cap_ecred_conn_rsp_defer(chan); } @@ -848,8 +850,6 @@ static void __l2cap_chan_close(struct l2cap_chan *chan, int reason) BT_DBG("chan %p state %s", chan, state_to_string(chan->state)); - lockdep_assert_held(&chan->lock); - switch (chan->state) { case BT_LISTEN: chan->ops->teardown(chan, 0); @@ -934,7 +934,10 @@ void l2cap_chan_close_unlocked(struct l2cap_chan *chan, int reason) bool have_conn; have_conn = l2cap_chan_lock_conn(chan); - __l2cap_chan_close(chan, reason); + + /* Context analysis: consider chan->conn->lock held also if conn NULL */ + context_unsafe(__l2cap_chan_close(chan, reason)); + l2cap_chan_unlock_conn(chan, have_conn); } EXPORT_SYMBOL(l2cap_chan_close_unlocked); @@ -1336,6 +1339,8 @@ void l2cap_send_conn_req(struct l2cap_chan *chan) } static void l2cap_chan_ready(struct l2cap_chan *chan) + __must_hold(&chan->lock) + __must_hold(&chan->conn->lock) { /* The channel may have already been flagged as connected in * case of receiving data before the L2CAP info req/rsp @@ -1471,6 +1476,7 @@ static void l2cap_ecred_connect(struct l2cap_chan *chan) } static void l2cap_le_start(struct l2cap_chan *chan) + __must_hold(&chan->lock) __must_hold(&chan->conn->lock) { struct l2cap_conn *conn = chan->conn; @@ -1492,6 +1498,7 @@ static void l2cap_le_start(struct l2cap_chan *chan) } static void l2cap_start_connection(struct l2cap_chan *chan) + __must_hold(&chan->lock) __must_hold(&chan->conn->lock) { if (chan->conn->hcon->type == LE_LINK) { @@ -1542,6 +1549,7 @@ static bool l2cap_check_enc_key_size(struct hci_conn *hcon, } static void l2cap_do_start(struct l2cap_chan *chan) + __must_hold(&chan->lock) __must_hold(&chan->conn->lock) { struct l2cap_conn *conn = chan->conn; @@ -1893,6 +1901,8 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err) l2cap_chan_hold(chan); l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + l2cap_chan_del(chan, err); chan->ops->close(chan); @@ -4218,6 +4228,8 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, __l2cap_chan_add(conn, chan); + lockdep_assert_held(&chan->conn->lock); + if (pchan->ops->new_connection && pchan->ops->new_connection(pchan, chan) < 0) { l2cap_chan_del(chan, 0); @@ -4419,6 +4431,8 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + switch (result) { case L2CAP_CR_SUCCESS: if (__l2cap_get_chan_by_dcid(conn, dcid)) { @@ -4520,6 +4534,8 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2 && chan->state != BT_CONNECTED) { cmd_reject_invalid_cid(conn, cmd->ident, chan->scid, @@ -4634,6 +4650,8 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + switch (result) { case L2CAP_CONF_SUCCESS: l2cap_conf_rfc_get(chan, rsp->data, len); @@ -4743,6 +4761,8 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + rsp.dcid = cpu_to_le16(chan->scid); rsp.scid = cpu_to_le16(chan->dcid); l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp); @@ -4783,6 +4803,8 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + if (chan->state != BT_DISCONN) { l2cap_chan_unlock(chan); l2cap_chan_put(chan); @@ -4995,6 +5017,8 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + switch (result) { case L2CAP_CR_LE_SUCCESS: if (__l2cap_get_chan_by_dcid(conn, dcid)) { @@ -5213,6 +5237,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->dst, &conn->hcon->dst); chan->src_type = bdaddr_src_type(conn->hcon); @@ -5444,6 +5470,8 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->dst, &conn->hcon->dst); chan->src_type = bdaddr_src_type(conn->hcon); @@ -5533,6 +5561,8 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, l2cap_chan_hold(chan); l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + /* Check that there is a dcid for each pending channel */ if (cmd_len < sizeof(dcid)) { l2cap_chan_del(chan, ECONNREFUSED); @@ -5760,6 +5790,8 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn, continue; l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + l2cap_chan_del(chan, ECONNRESET); l2cap_chan_unlock(chan); @@ -5789,6 +5821,7 @@ static inline int l2cap_le_command_rej(struct l2cap_conn *conn, goto done; l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); l2cap_chan_del(chan, ECONNREFUSED); l2cap_chan_unlock(chan); l2cap_chan_put(chan); @@ -7184,6 +7217,8 @@ static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid, l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + BT_DBG("chan %p, len %d", chan, skb->len); /* If we receive data on a fixed channel before the info req/rsp From a0c672c4105545f430db3b6379858c8c0ec34f2e Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 2 Sep 2026 00:04:35 +0300 Subject: [PATCH 1668/2126] Bluetooth: L2CAP: annotate locking for l2cap_ops callbacks Annotate current locking context for l2cap_ops callbacks. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 13 +++++++++---- net/bluetooth/l2cap_core.c | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 3e1e2b36d7b6..efb9b7f422d1 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -653,21 +653,26 @@ struct l2cap_ops { char *name; int (*new_connection)(struct l2cap_chan *chan, - struct l2cap_chan *new_chan); + struct l2cap_chan *new_chan) + __must_hold(&chan->lock) + __must_hold(&new_chan->lock); int (*recv) (struct l2cap_chan * chan, struct sk_buff *skb); void (*teardown) (struct l2cap_chan *chan, int err) __must_hold(&chan->lock); - void (*close) (struct l2cap_chan *chan); + void (*close) (struct l2cap_chan *chan) + __must_hold(&chan->lock); void (*state_change) (struct l2cap_chan *chan, int state, int err); void (*ready) (struct l2cap_chan *chan) __must_hold(&chan->lock) __must_hold(&chan->conn->lock); void (*defer) (struct l2cap_chan *chan); - void (*resume) (struct l2cap_chan *chan); + void (*resume) (struct l2cap_chan *chan) + __must_hold(&chan->lock); void (*suspend) (struct l2cap_chan *chan); - void (*set_shutdown) (struct l2cap_chan *chan); + void (*set_shutdown) (struct l2cap_chan *chan) + __must_hold(&chan->lock); long (*get_sndtimeo) (struct l2cap_chan *chan); struct pid *(*get_peer_pid) (struct l2cap_chan *chan); struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 67efbbc90b2b..920df757b372 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4214,6 +4214,7 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, struct l2cap_chan *pchan) __must_hold(&conn->lock) + __must_hold(&pchan->lock) { struct l2cap_chan *chan; From 86b55991d3cd690e73c5ef8d20b75ae4905b357a Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 2 Sep 2026 00:04:36 +0300 Subject: [PATCH 1669/2126] Bluetooth: L2CAP: refuse __l2cap_chan_add if chan already has conn l2cap_chan may be linked to l2cap_conn at most once. This is assumed in several places, eg l2cap_chan_del cleanup. There is a TOCTOU race where the invariant is violated: [Task 1] [Task 2] l2cap_chan_connect l2cap_sock_bind l2cap_chan_lock lock_sock l2cap_state_change if (sk->sk_state != BT_OPEN) chan->state = BT_CONNECT l2cap_sock_state_change_cb chan->state = BT_BOUND sk->sk_state = BT_BOUND lock_sock <------------------ release_sock sk->sk_state = BT_CONNECT l2cap_sock_connect() does not check sk->sk_state, so since chan->state is now BT_BOUND, subsequent connect() ends up with second __l2cap_chan_add. Explicitly document and check the invariant in __l2cap_chan_add with WARN_ON_ONCE. The only callsite where it could be hit is l2cap_chan_connect, so add pre-check there to avoid relying on chan->state. chan->state read/write is not properly guarded currently so there can be other TOCTOUC problems. Add l2cap_lock_chan in l2cap_sock_bind() to guard chan->state write. Fixes: b66774b48dd9 ("Bluetooth: L2CAP: Fix UAF in channel timeout by holding conn ref") Assisted-by: deepseek-4-flash # finding the race condition Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 7 ++++++- net/bluetooth/l2cap_sock.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 920df757b372..49a998804908 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -623,6 +623,10 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) BT_DBG("conn %p, psm 0x%2.2x, dcid 0x%4.4x", conn, __le16_to_cpu(chan->psm), chan->dcid); + /* Caller must ensure l2cap_chan is linked to l2cap_conn only once */ + if (WARN_ON_ONCE(chan->conn || test_bit(FLAG_DEL, &chan->flags))) + return; + conn->disc_reason = HCI_ERROR_REMOTE_USER_TERM; chan->conn = l2cap_conn_get(conn); @@ -7631,7 +7635,8 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, } } - if (cid && __l2cap_get_chan_by_dcid(conn, cid)) { + if ((cid && __l2cap_get_chan_by_dcid(conn, cid)) || chan->conn || + test_bit(FLAG_DEL, &chan->flags)) { hci_conn_drop(hcon); err = -EBUSY; goto chan_unlock; diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index dee3025f0ec2..278adb05c4c9 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -109,6 +109,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr_unsized *addr, i return -EINVAL; } + l2cap_chan_lock(chan); lock_sock(sk); if (sk->sk_state != BT_OPEN) { @@ -174,6 +175,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr_unsized *addr, i done: release_sock(sk); + l2cap_chan_unlock(chan); return err; } From 5299db91df03894253e8fa08627cfb9ec1429e89 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Aug 2026 16:04:30 -0400 Subject: [PATCH 1670/2126] Bluetooth: Move H:4 reassembly into the Bluetooth core h4_recv_buf() is currently implemented in hci_h4.c which is only built as part of the hci_uart module, and only when CONFIG_BT_HCIUART_H4 is enabled. That makes the H:4 reassembly logic unusable by drivers which do not depend on hci_uart, e.g. btusb which needs it to implement Bulk Serialization Mode. Move the transport agnostic part into the Bluetooth core as h4_recv_skb(), which takes a struct hci_dev instead of a struct hci_uart, along with struct h4_recv_pkt and the H4_RECV_* helpers, and keep h4_recv_buf() as a thin wrapper for the hci_uart protocols. Since every Bluetooth driver already depends on the bluetooth module this introduces no new module dependency and no new Kconfig symbol. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_h4.c | 123 ++----------------------- drivers/bluetooth/hci_uart.h | 39 +------- include/net/bluetooth/hci_h4.h | 60 +++++++++++++ net/bluetooth/Makefile | 2 +- net/bluetooth/hci_h4.c | 160 +++++++++++++++++++++++++++++++++ 5 files changed, 229 insertions(+), 155 deletions(-) create mode 100644 include/net/bluetooth/hci_h4.h create mode 100644 net/bluetooth/hci_h4.c diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c index 767372707498..cbdf51458ec3 100644 --- a/drivers/bluetooth/hci_h4.c +++ b/drivers/bluetooth/hci_h4.c @@ -29,6 +29,7 @@ #include #include +#include #include "hci_uart.h" @@ -112,8 +113,9 @@ static int h4_recv(struct hci_uart *hu, const void *data, int count) if (!h4) return -ENODEV; - h4->rx_skb = h4_recv_buf(hu, h4->rx_skb, data, count, - h4_recv_pkts, ARRAY_SIZE(h4_recv_pkts)); + h4->rx_skb = h4_recv_skb(hu->hdev, &hu->alignment, &hu->padding, + h4->rx_skb, data, count, h4_recv_pkts, + ARRAY_SIZE(h4_recv_pkts)); if (IS_ERR(h4->rx_skb)) { int err = PTR_ERR(h4->rx_skb); bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); @@ -155,120 +157,7 @@ struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb, const unsigned char *buffer, int count, const struct h4_recv_pkt *pkts, int pkts_count) { - u8 alignment = hu->alignment ? hu->alignment : 1; - struct hci_dev *hdev = hu->hdev; - - /* Check for error from previous call */ - if (IS_ERR(skb)) - skb = NULL; - - while (count) { - int i, len; - - /* remove padding bytes from buffer */ - for (; hu->padding && count > 0; hu->padding--) { - count--; - buffer++; - } - if (!count) - break; - - if (!skb) { - for (i = 0; i < pkts_count; i++) { - if (buffer[0] != (&pkts[i])->type) - continue; - - skb = bt_skb_alloc((&pkts[i])->maxlen, - GFP_ATOMIC); - if (!skb) - return ERR_PTR(-ENOMEM); - - hci_skb_pkt_type(skb) = (&pkts[i])->type; - hci_skb_expect(skb) = (&pkts[i])->hlen; - break; - } - - /* Check for invalid packet type */ - if (!skb) - return ERR_PTR(-EILSEQ); - - count -= 1; - buffer += 1; - } - - len = min_t(uint, hci_skb_expect(skb) - skb->len, count); - skb_put_data(skb, buffer, len); - - count -= len; - buffer += len; - - /* Check for partial packet */ - if (skb->len < hci_skb_expect(skb)) - continue; - - for (i = 0; i < pkts_count; i++) { - if (hci_skb_pkt_type(skb) == (&pkts[i])->type) - break; - } - - if (i >= pkts_count) { - kfree_skb(skb); - return ERR_PTR(-EILSEQ); - } - - if (skb->len == (&pkts[i])->hlen) { - u16 dlen; - - switch ((&pkts[i])->lsize) { - case 0: - /* No variable data length */ - dlen = 0; - break; - case 1: - /* Single octet variable length */ - dlen = skb->data[(&pkts[i])->loff]; - hci_skb_expect(skb) += dlen; - - if (skb_tailroom(skb) < dlen) { - kfree_skb(skb); - return ERR_PTR(-EMSGSIZE); - } - break; - case 2: - /* Double octet variable length */ - dlen = get_unaligned_le16(skb->data + - (&pkts[i])->loff); - hci_skb_expect(skb) += dlen; - - if (skb_tailroom(skb) < dlen) { - kfree_skb(skb); - return ERR_PTR(-EMSGSIZE); - } - break; - default: - /* Unsupported variable length */ - kfree_skb(skb); - return ERR_PTR(-EILSEQ); - } - - if (!dlen) { - hu->padding = (skb->len + 1) % alignment; - hu->padding = (alignment - hu->padding) % alignment; - - /* No more data, complete frame */ - (&pkts[i])->recv(hdev, skb); - skb = NULL; - } - } else { - hu->padding = (skb->len + 1) % alignment; - hu->padding = (alignment - hu->padding) % alignment; - - /* Complete frame */ - (&pkts[i])->recv(hdev, skb); - skb = NULL; - } - } - - return skb; + return h4_recv_skb(hu->hdev, &hu->alignment, &hu->padding, skb, buffer, + count, pkts, pkts_count); } EXPORT_SYMBOL_GPL(h4_recv_buf); diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index 48ac7ca9334e..7fbe8dffab98 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h @@ -8,6 +8,8 @@ * Copyright (C) 2004-2005 Marcel Holtmann */ +#include + #ifndef N_HCI #define N_HCI 15 #endif @@ -121,43 +123,6 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable); void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, unsigned int oper_speed); -struct h4_recv_pkt { - u8 type; /* Packet type */ - u8 hlen; /* Header length */ - u8 loff; /* Data length offset in header */ - u8 lsize; /* Data length field size */ - u16 maxlen; /* Max overall packet length */ - int (*recv)(struct hci_dev *hdev, struct sk_buff *skb); -}; - -#define H4_RECV_ACL \ - .type = HCI_ACLDATA_PKT, \ - .hlen = HCI_ACL_HDR_SIZE, \ - .loff = 2, \ - .lsize = 2, \ - .maxlen = HCI_MAX_FRAME_SIZE \ - -#define H4_RECV_SCO \ - .type = HCI_SCODATA_PKT, \ - .hlen = HCI_SCO_HDR_SIZE, \ - .loff = 2, \ - .lsize = 1, \ - .maxlen = HCI_MAX_SCO_SIZE - -#define H4_RECV_EVENT \ - .type = HCI_EVENT_PKT, \ - .hlen = HCI_EVENT_HDR_SIZE, \ - .loff = 1, \ - .lsize = 1, \ - .maxlen = HCI_MAX_EVENT_SIZE - -#define H4_RECV_ISO \ - .type = HCI_ISODATA_PKT, \ - .hlen = HCI_ISO_HDR_SIZE, \ - .loff = 2, \ - .lsize = 2, \ - .maxlen = HCI_MAX_FRAME_SIZE \ - #ifdef CONFIG_BT_HCIUART_H4 int h4_init(void); int h4_deinit(void); diff --git a/include/net/bluetooth/hci_h4.h b/include/net/bluetooth/hci_h4.h new file mode 100644 index 000000000000..a37e7df8c9ce --- /dev/null +++ b/include/net/bluetooth/hci_h4.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Bluetooth HCI H:4 packet reassembly + * + * Copyright (C) 2000-2001 Qualcomm Incorporated + * Copyright (C) 2002-2003 Maxim Krasnyansky + * Copyright (C) 2004-2005 Marcel Holtmann + */ + +#ifndef __HCI_H4_H +#define __HCI_H4_H + +#include +#include + +struct hci_dev; + +struct h4_recv_pkt { + u8 type; /* Packet type */ + u8 hlen; /* Header length */ + u8 loff; /* Data length offset in header */ + u8 lsize; /* Data length field size */ + u16 maxlen; /* Max overall packet length */ + int (*recv)(struct hci_dev *hdev, struct sk_buff *skb); +}; + +#define H4_RECV_ACL \ + .type = HCI_ACLDATA_PKT, \ + .hlen = HCI_ACL_HDR_SIZE, \ + .loff = 2, \ + .lsize = 2, \ + .maxlen = HCI_MAX_FRAME_SIZE \ + +#define H4_RECV_SCO \ + .type = HCI_SCODATA_PKT, \ + .hlen = HCI_SCO_HDR_SIZE, \ + .loff = 2, \ + .lsize = 1, \ + .maxlen = HCI_MAX_SCO_SIZE + +#define H4_RECV_EVENT \ + .type = HCI_EVENT_PKT, \ + .hlen = HCI_EVENT_HDR_SIZE, \ + .loff = 1, \ + .lsize = 1, \ + .maxlen = HCI_MAX_EVENT_SIZE + +#define H4_RECV_ISO \ + .type = HCI_ISODATA_PKT, \ + .hlen = HCI_ISO_HDR_SIZE, \ + .loff = 2, \ + .lsize = 2, \ + .maxlen = HCI_MAX_FRAME_SIZE \ + +struct sk_buff *h4_recv_skb(struct hci_dev *hdev, u8 *alignment, u8 *padding, + struct sk_buff *skb, const unsigned char *buffer, + int count, const struct h4_recv_pkt *pkts, + int pkts_count); + +#endif /* __HCI_H4_H */ diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile index ff466ea97436..b78ad98864d4 100644 --- a/net/bluetooth/Makefile +++ b/net/bluetooth/Makefile @@ -14,7 +14,7 @@ bluetooth_6lowpan-y := 6lowpan.o bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o lib.o \ ecdh_helper.o mgmt_util.o mgmt_config.o hci_codec.o eir.o hci_sync.o \ - hci_drv.o + hci_drv.o hci_h4.o bluetooth-$(CONFIG_DEV_COREDUMP) += coredump.o diff --git a/net/bluetooth/hci_h4.c b/net/bluetooth/hci_h4.c new file mode 100644 index 000000000000..86f809018062 --- /dev/null +++ b/net/bluetooth/hci_h4.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Bluetooth HCI H:4 packet reassembly + * + * Copyright (C) 2000-2001 Qualcomm Incorporated + * Copyright (C) 2002-2003 Maxim Krasnyansky + * Copyright (C) 2004-2005 Marcel Holtmann + */ + +#include +#include +#include + +#include +#include +#include + +/* h4_recv_skb - Reassemble H:4 framed packets + * @hdev: HCI device the packets are received on + * @alignment: optional packet alignment, NULL or 0 means no alignment + * @padding: optional padding state carried over between calls + * @skb: partially received packet from a previous call, may be NULL or an + * ERR_PTR returned by a previous call + * @buffer: buffer holding the received data + * @count: number of bytes in @buffer + * @pkts: table of supported packet types + * @pkts_count: number of entries in @pkts + * + * Returns the partially received packet to be passed to the next call, or an + * ERR_PTR on error. The returned value can be fed back into this function as + * is, but must be checked with IS_ERR() before being freed. + */ +struct sk_buff *h4_recv_skb(struct hci_dev *hdev, u8 *alignment, u8 *padding, + struct sk_buff *skb, const unsigned char *buffer, + int count, const struct h4_recv_pkt *pkts, + int pkts_count) +{ + u8 align = alignment && *alignment ? *alignment : 1; + + /* Check for error from previous call */ + if (IS_ERR(skb)) + skb = NULL; + + while (count) { + int i, len; + + /* remove padding bytes from buffer */ + if (padding) { + for (; (*padding) && count > 0; (*padding)--) { + count--; + buffer++; + } + } + + if (!count) + break; + + if (!skb) { + for (i = 0; i < pkts_count; i++) { + if (buffer[0] != pkts[i].type) + continue; + + skb = bt_skb_alloc(pkts[i].maxlen, + GFP_ATOMIC); + if (!skb) + return ERR_PTR(-ENOMEM); + + hci_skb_pkt_type(skb) = pkts[i].type; + hci_skb_expect(skb) = pkts[i].hlen; + break; + } + + /* Check for invalid packet type */ + if (!skb) + return ERR_PTR(-EILSEQ); + + count -= 1; + buffer += 1; + } + + len = min_t(uint, hci_skb_expect(skb) - skb->len, count); + skb_put_data(skb, buffer, len); + + count -= len; + buffer += len; + + /* Check for partial packet */ + if (skb->len < hci_skb_expect(skb)) + continue; + + for (i = 0; i < pkts_count; i++) { + if (hci_skb_pkt_type(skb) == pkts[i].type) + break; + } + + if (i >= pkts_count) { + kfree_skb(skb); + return ERR_PTR(-EILSEQ); + } + + if (skb->len == pkts[i].hlen) { + u16 dlen; + + switch (pkts[i].lsize) { + case 0: + /* No variable data length */ + dlen = 0; + break; + case 1: + /* Single octet variable length */ + dlen = skb->data[pkts[i].loff]; + hci_skb_expect(skb) += dlen; + + if (skb_tailroom(skb) < dlen) { + kfree_skb(skb); + return ERR_PTR(-EMSGSIZE); + } + break; + case 2: + /* Double octet variable length */ + dlen = get_unaligned_le16(skb->data + + pkts[i].loff); + hci_skb_expect(skb) += dlen; + + if (skb_tailroom(skb) < dlen) { + kfree_skb(skb); + return ERR_PTR(-EMSGSIZE); + } + break; + default: + /* Unsupported variable length */ + kfree_skb(skb); + return ERR_PTR(-EILSEQ); + } + + if (!dlen) { + if (padding) { + *padding = (skb->len + 1) % align; + *padding = (align - *padding) % align; + } + + /* No more data, complete frame */ + pkts[i].recv(hdev, skb); + skb = NULL; + } + } else { + if (padding) { + *padding = (skb->len + 1) % align; + *padding = (align - *padding) % align; + } + + /* Complete frame */ + pkts[i].recv(hdev, skb); + skb = NULL; + } + } + + return skb; +} +EXPORT_SYMBOL_GPL(h4_recv_skb); From c2163c83e76b988746b0145b954b58e7f7187e3f Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Aug 2026 16:10:25 -0400 Subject: [PATCH 1671/2126] Bluetooth: btusb: Add support for Bulk Serialization Mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support for Bulk Serialization Mode introduced in 6.2: https://www.bluetooth.com/bluetooth-core-6-2-feature-overview/#5-bluetooth-hci-usb-le-isochronous-support https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host-controller-interface/usb-transport-layer.html#UUID-c1a65395-29e9-87d3-2981-8bed625d0459 It works by detecting if alternate setting 1 is supported for the interface and then switches to use it as it serializes all the frames in a single Bulk endpoint using H4 headers and it considerable more robust then legacy one while allowing the transport of ISO packets: 'In addition to enabling Bluetooth® LE Audio, the new mode resolves a persistent race condition in the legacy USB transport layer. In Legacy Mode, different endpoint types are serviced in a specific order within a USB frame, which can result in out-of-order delivery of data and events. For example, a Host might receive a data packet before the event signaling its arrival. This behavior can disrupt critical processes such as connection setup, disconnection, and data encryption, adversely affecting the user experience.' Signed-off-by: Johann Fischer Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 214 ++++++++++++++++++++++++++++++-------- 1 file changed, 171 insertions(+), 43 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 1efa7ed50c1d..cce5d9fb1c44 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -28,8 +28,9 @@ #include "btbcm.h" #include "btrtl.h" #include "btmtk.h" +#include "hci_uart.h" -#define VERSION "0.8" +#define VERSION "1.0" static bool disable_scofix; static bool force_scofix; @@ -1003,6 +1004,9 @@ struct btqca_data { #define BTUSB_WAKEUP_BROKEN 18 #define BTUSB_RESET 19 +#define BTUSB_PROTO_LEGACY 0x00 +#define BTUSB_PROTO_H4 0x01 + struct btusb_data { struct hci_dev *hdev; struct usb_device *udev; @@ -1036,6 +1040,7 @@ struct btusb_data { struct sk_buff *evt_skb; struct sk_buff *acl_skb; struct sk_buff *sco_skb; + struct sk_buff *rx_skb; struct usb_endpoint_descriptor *intr_ep; struct usb_endpoint_descriptor *bulk_tx_ep; @@ -1049,6 +1054,7 @@ struct btusb_data { __u8 cmdreq_type; __u8 cmdreq; + __u8 proto; unsigned int sco_num; unsigned int air_mode; @@ -1278,6 +1284,11 @@ static inline void btusb_free_frags(struct btusb_data *data) dev_kfree_skb_irq(data->sco_skb); data->sco_skb = NULL; + /* rx_skb may hold an ERR_PTR from a previous h4_recv_skb() call */ + if (!IS_ERR(data->rx_skb)) + dev_kfree_skb_irq(data->rx_skb); + data->rx_skb = NULL; + spin_unlock_irqrestore(&data->rxlock, flags); } @@ -1377,12 +1388,41 @@ static int btusb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) return 0; } +/* Dispatch through the btusb_recv_* wrappers so that vendor specific + * handling (data->recv_event, data->recv_acl) is preserved in H:4 mode. + */ +static const struct h4_recv_pkt btusb_recv_pkts[] = { + { H4_RECV_ACL, .recv = btusb_recv_acl }, + { H4_RECV_SCO, .recv = hci_recv_frame }, + { H4_RECV_EVENT, .recv = btusb_recv_event }, + { H4_RECV_ISO, .recv = hci_recv_frame }, +}; + +static int btusb_recv_h4(struct btusb_data *data, void *buffer, int count) +{ + unsigned long flags; + int err = 0; + + spin_lock_irqsave(&data->rxlock, flags); + data->rx_skb = h4_recv_skb(data->hdev, NULL, NULL, data->rx_skb, buffer, + count, btusb_recv_pkts, + ARRAY_SIZE(btusb_recv_pkts)); + if (IS_ERR(data->rx_skb)) + err = PTR_ERR(data->rx_skb); + spin_unlock_irqrestore(&data->rxlock, flags); + + return err; +} + static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count) { struct sk_buff *skb; unsigned long flags; int err = 0; + if (data->proto == BTUSB_PROTO_H4) + return btusb_recv_h4(data, buffer, count); + spin_lock_irqsave(&data->rxlock, flags); skb = data->acl_skb; @@ -2060,12 +2100,14 @@ static int btusb_open(struct hci_dev *hdev) data->intf->needs_remote_wakeup = 1; - if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) - goto done; + if (data->proto == BTUSB_PROTO_LEGACY) { + if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) + goto done; - err = btusb_submit_intr_urb(hdev, GFP_KERNEL); - if (err < 0) - goto failed; + err = btusb_submit_intr_urb(hdev, GFP_KERNEL); + if (err < 0) + goto failed; + } err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); if (err < 0) { @@ -2169,6 +2211,42 @@ static int btusb_flush(struct hci_dev *hdev) return 0; } +static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + struct urb *urb; + unsigned int pipe; + + if (!data->bulk_tx_ep) + return ERR_PTR(-ENODEV); + + if (data->proto == BTUSB_PROTO_H4) { + /* The frame type is prepended in place, so the buffer must not + * be shared with anyone else. + */ + if (skb_cow_head(skb, 1)) + return ERR_PTR(-ENOMEM); + } + + urb = usb_alloc_urb(0, GFP_KERNEL); + if (!urb) + return ERR_PTR(-ENOMEM); + + pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); + + if (data->proto == BTUSB_PROTO_H4) { + /* Prepend skb with frame type */ + memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); + } + + usb_fill_bulk_urb(urb, data->udev, pipe, + skb->data, skb->len, btusb_tx_complete, skb); + + skb->dev = (void *)hdev; + + return urb; +} + static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb) { struct btusb_data *data = hci_get_drvdata(hdev); @@ -2176,6 +2254,9 @@ static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb) struct urb *urb; unsigned int pipe; + if (data->proto == BTUSB_PROTO_H4) + return alloc_bulk_urb(hdev, skb); + urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) return ERR_PTR(-ENOMEM); @@ -2202,35 +2283,15 @@ static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb) return urb; } -static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) -{ - struct btusb_data *data = hci_get_drvdata(hdev); - struct urb *urb; - unsigned int pipe; - - if (!data->bulk_tx_ep) - return ERR_PTR(-ENODEV); - - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) - return ERR_PTR(-ENOMEM); - - pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); - - usb_fill_bulk_urb(urb, data->udev, pipe, - skb->data, skb->len, btusb_tx_complete, skb); - - skb->dev = (void *)hdev; - - return urb; -} - static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb) { struct btusb_data *data = hci_get_drvdata(hdev); struct urb *urb; unsigned int pipe; + if (data->proto == BTUSB_PROTO_H4) + return alloc_bulk_urb(hdev, skb); + if (!data->isoc_tx_ep) return ERR_PTR(-ENODEV); @@ -2302,6 +2363,22 @@ static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb) return 0; } +static int submit_sco_urb(struct hci_dev *hdev, struct urb *urb) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + + /* In H:4 mode SCO frames are carried over the bulk endpoint and + * complete via btusb_tx_complete(), which decrements tx_in_flight, so + * they have to be accounted for like any other bulk transfer. + * Isochronous transfers use btusb_isoc_tx_complete() instead, which + * does not, so they must not be counted. + */ + if (data->proto == BTUSB_PROTO_H4) + return submit_or_queue_tx_urb(hdev, urb); + + return submit_tx_urb(hdev, urb); +} + static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) { struct urb *urb; @@ -2335,7 +2412,7 @@ static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) return PTR_ERR(urb); hdev->stat.sco_tx++; - return submit_tx_urb(hdev, urb); + return submit_sco_urb(hdev, urb); case HCI_ISODATA_PKT: urb = alloc_bulk_urb(hdev, skb); @@ -2444,10 +2521,9 @@ static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts) return 0; } -static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data, - int alt) +static struct usb_host_interface * +btusb_find_altsetting(struct usb_interface *intf, int alt) { - struct usb_interface *intf = data->isoc; int i; BT_DBG("Looking for Alt no :%d", alt); @@ -2470,6 +2546,13 @@ static void btusb_work(struct work_struct *work) int new_alts = 0; int err; + /* In H:4 mode SCO/ISO data is carried over the bulk endpoints, so + * there is no isochronous interface to resume or to switch alternate + * settings on. + */ + if (data->proto == BTUSB_PROTO_H4) + return; + if (data->sco_num > 0) { if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); @@ -2503,9 +2586,9 @@ static void btusb_work(struct work_struct *work) * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72 * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1. */ - if (btusb_find_altsetting(data, 6)) + if (btusb_find_altsetting(data->isoc, 6)) new_alts = 6; - else if (btusb_find_altsetting(data, 3) && + else if (btusb_find_altsetting(data->isoc, 3) && hdev->sco_mtu >= 72 && test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags)) new_alts = 3; @@ -2754,8 +2837,13 @@ static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, /* When the device is in bootloader mode, then it can send * events via the bulk endpoint. These events are treated the * same way as the ones received from the interrupt endpoint. + * + * In H:4 mode there is no interrupt endpoint and every frame on the + * bulk endpoint carries an H:4 header, including the ones sent by the + * bootloader, so the regular decoding applies. */ - if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) + if (data->proto == BTUSB_PROTO_LEGACY && + btintel_test_flag(hdev, INTEL_BOOTLOADER)) return btusb_recv_intr(data, buffer, count); return btusb_recv_bulk(data, buffer, count); @@ -2816,7 +2904,7 @@ static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) return PTR_ERR(urb); hdev->stat.sco_tx++; - return submit_tx_urb(hdev, urb); + return submit_sco_urb(hdev, urb); case HCI_ISODATA_PKT: urb = alloc_bulk_urb(hdev, skb); @@ -4035,8 +4123,11 @@ static ssize_t force_poll_sync_write(struct file *file, if (err) return err; - /* Only allow changes while the adapter is down */ - if (test_bit(HCI_UP, &data->hdev->flags)) + /* Only allow changes while the adapter is down and it is using legacy + * protocol. + */ + if (test_bit(HCI_UP, &data->hdev->flags) || + data->proto != BTUSB_PROTO_LEGACY) return -EPERM; if (data->poll_sync == enable) @@ -4135,7 +4226,7 @@ static int btusb_hci_drv_supported_altsettings(struct hci_dev *hdev, void *data, goto done; for (i = 0; i <= 6; i++) { - if (btusb_find_altsetting(drvdata, i)) + if (btusb_find_altsetting(drvdata->isoc, i)) rp->altsettings[rp->num++] = i; } @@ -4189,6 +4280,8 @@ static int btusb_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct gpio_desc *reset_gpio; + struct usb_host_interface *alt; + struct usb_endpoint_descriptor *bulk_rx_ep, *bulk_tx_ep, *intr_ep; struct btusb_data *data; struct hci_dev *hdev; unsigned ifnum_base; @@ -4230,10 +4323,38 @@ static int btusb_probe(struct usb_interface *intf, return -ENOMEM; data->match_id = id; + + /* Alternate setting 1 with a single pair of bulk endpoints and no + * interrupt endpoint means the controller supports Bulk Serialization + * Mode, in which every packet is prefixed with an H:4 header and + * carried over the bulk endpoints. + */ + alt = btusb_find_altsetting(intf, 1); + if (alt && usb_find_int_in_endpoint(alt, &intr_ep) && + !usb_find_common_endpoints(alt, &bulk_rx_ep, &bulk_tx_ep, NULL, + NULL)) { + err = usb_set_interface(interface_to_usbdev(intf), ifnum_base, 1); + if (!err) + data->proto = BTUSB_PROTO_H4; + else + dev_warn(&intf->dev, + "failed to select alt setting 1 (%d), using legacy mode", + err); + } + + /* Check if all endpoints could be enumerated, legacy mode requires + * interrupt and bulk endpoints while H4 mode only requires bulk + * endpoints. + */ err = usb_find_common_endpoints(intf->cur_altsetting, &data->bulk_rx_ep, - &data->bulk_tx_ep, &data->intr_ep, NULL); - if (err) + &data->bulk_tx_ep, + data->proto == BTUSB_PROTO_LEGACY ? + &data->intr_ep : NULL, + NULL); + if (err) { + dev_err(&intf->dev, "failed to enumerate endpoints\n"); goto err_free_data; + } if (id->driver_info & BTUSB_AMP) { data->cmdreq_type = USB_TYPE_CLASS | 0x01; @@ -4445,6 +4566,12 @@ static int btusb_probe(struct usb_interface *intf, if (id->driver_info & BTUSB_AMP) { /* AMP controllers do not support SCO packets */ data->isoc = NULL; + } else if (data->proto == BTUSB_PROTO_H4) { + /* In H:4 mode every packet, including SCO/ISO, is carried over + * the bulk endpoints, so the isochronous interface must not be + * claimed nor have its alternate settings switched. + */ + data->isoc = NULL; } else { /* Interface orders are hardcoded in the specification */ data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); @@ -4554,7 +4681,8 @@ static int btusb_probe(struct usb_interface *intf, if (enable_autosuspend) usb_enable_autosuspend(data->udev); - data->poll_sync = enable_poll_sync; + if (data->proto == BTUSB_PROTO_LEGACY) + data->poll_sync = enable_poll_sync; err = hci_register_dev(hdev); if (err < 0) From 7adde1e5216e984480a7e29f00028951fd7f3dc1 Mon Sep 17 00:00:00 2001 From: Aritra Das Date: Thu, 3 Sep 2026 10:03:22 -0700 Subject: [PATCH 1672/2126] Bluetooth: btusb: Add USB ID 13d3:3556 for RTL8821CE The onboard Realtek RTL8821CE combo card on the ASUS PRIME B550-PLUS AC-HES presents its Bluetooth function as USB ID 13d3:3556. This ID is missing from quirks_table, so btusb matches the device only through the generic Bluetooth class entry in btusb_table and driver_info stays zero. BTUSB_REALTEK is therefore never set, btrtl never runs, and the controller keeps executing its on-chip ROM firmware instead of loading rtl_bt/rtl8821c_fw.bin and rtl_bt/rtl8821c_config.bin. In that state BLE HID peripherals are unusable. A HHKB Hybrid keyboard pairs and enumerates as a HID device, then the link drops within 10-30 seconds, repeatedly. The same keyboard is stable on the same host under other operating systems. Adding the ID lets btusb run the Realtek setup path: Bluetooth: hci0: RTL: examining hci_ver=08 hci_rev=000c lmp_ver=08 lmp_subver=8821 Bluetooth: hci0: RTL: rom_version status=0 version=1 Bluetooth: hci0: RTL: loading rtl_bt/rtl8821c_fw.bin Bluetooth: hci0: RTL: loading rtl_bt/rtl8821c_config.bin Bluetooth: hci0: RTL: cfg_sz 10, total sz 34926 Bluetooth: hci0: RTL: fw version 0x75b8f098 With the firmware loaded the same keyboard has stayed connected for over 11 hours without a single drop. Device descriptor: T: Bus=01 Lev=01 Prnt=01 Port=04 Cnt=02 Dev#= 2 Spd=12 MxCh= 0 D: Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=13d3 ProdID=3556 Rev=01.10 S: Manufacturer=Realtek S: Product=Bluetooth Radio S: SerialNumber=00e04c000001 C: #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=500mA I: If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=1ms E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms I: If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 0 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 0 Ivl=1ms Signed-off-by: Aritra Das Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index cce5d9fb1c44..7e9ec286eb02 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -529,6 +529,8 @@ static const struct usb_device_id quirks_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x13d3, 0x3533), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, + { USB_DEVICE(0x13d3, 0x3556), .driver_info = BTUSB_REALTEK | + BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x13d3, 0x3558), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, From 69bf0c2b348ff9da580cba5b6a15d0c125a449f3 Mon Sep 17 00:00:00 2001 From: Catherine L Date: Wed, 2 Sep 2026 19:00:37 +0000 Subject: [PATCH 1673/2126] Bluetooth: btusb: Add support for Intel Otter Peak2 (OrP2) $ lsusb Bus 003 Device 003: ID 8087:0043 Intel Corp. $ cat /sys/kernel/debug/usb/devices T: Bus=03 Lev=01 Prnt=01 Port=09 Cnt=02 Dev#= 3 Spd=12 MxCh= 0 D: Ver= 2.01 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=8087 ProdID=0043 Rev= 0.00 C:* #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA I:* If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=1ms E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms I:* If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 0 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 0 Ivl=1ms Signed-off-by: Catherine L Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 7e9ec286eb02..2c69a81c9631 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -506,6 +506,7 @@ static const struct usb_device_id quirks_table[] = { { USB_DEVICE(0x8087, 0x0037), .driver_info = BTUSB_INTEL_COMBINED }, { USB_DEVICE(0x8087, 0x0038), .driver_info = BTUSB_INTEL_COMBINED }, { USB_DEVICE(0x8087, 0x0039), .driver_info = BTUSB_INTEL_COMBINED }, + { USB_DEVICE(0x8087, 0x0043), .driver_info = BTUSB_INTEL_COMBINED }, /* Otter Peak 2 */ { USB_DEVICE(0x8087, 0x0040), .driver_info = BTUSB_INTEL_COMBINED }, /* Lizard Peak 2 */ { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED | From 4f532f7276269627cc8f2288e2dd351a07367598 Mon Sep 17 00:00:00 2001 From: Andy Chang Date: Thu, 3 Sep 2026 20:18:23 +0800 Subject: [PATCH 1674/2126] Bluetooth: dt-bindings: net: bluetooth: add BCM4384 Add the brcm,bcm4384-bt compatible string to support the Synaptics BCM4384 Bluetooth controller. A fallback compatible is not suitable here because any operating system must discern the proper firmware to drive this specific hardware revision, and the compatible string fulfills that purpose. Signed-off-by: Andy Chang Reviewed-by: Paul Menzel Reviewed-by: Linus Walleij Signed-off-by: Luiz Augusto von Dentz --- .../devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml b/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml index 95501e858e6f..612d21123aaa 100644 --- a/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml +++ b/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml @@ -31,6 +31,7 @@ properties: - brcm,bcm43540-bt - brcm,bcm4335a0 - brcm,bcm4349-bt + - brcm,bcm4384-bt - cypress,cyw4373a0-bt - infineon,cyw55572-bt From c5b9532d041b0de8e1b6006d21af977e33e7023a Mon Sep 17 00:00:00 2001 From: Andy Chang Date: Thu, 3 Sep 2026 20:18:24 +0800 Subject: [PATCH 1675/2126] Bluetooth: btbcm: Add Synaptics 4384 chip support Add support for the Synaptics 4384 Bluetooth controller by adding the corresponding chip IDs. Tested on the VIM3 platform. Verified that the controller initializes successfully and that firmware loading and basic Bluetooth operation work as expected. The VIM3 is a Khadas single-board computer that I used as the host platform for testing the BCM4384 Bluetooth controller. Test log: Bluetooth: hci0: BCM: chip id 206 Bluetooth: hci0: BCM: features 0x0f Bluetooth: hci0: BCM4384B0 Bluetooth: hci0: BCM4384B0 (002.001.025) build 0000 Bluetooth: hci0: BCM4384B0 'brcm/BCM4384B0.hcd' Patch Bluetooth: hci0: BCM: features 0x0f Bluetooth: hci0: BCM4384B0 AP6684P CN iPA [Version: 1030.1021] Bluetooth: hci0: BCM4384B0 (002.001.025) build 1021 Bluetooth: hci0: BCM: Using default device address (43:84:b0:00:76:93) Signed-off-by: Andy Chang Reviewed-by: Paul Menzel Reviewed-by: Linus Walleij Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btbcm.c | 6 +++++- drivers/bluetooth/hci_bcm.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 463d59890bef..63c4c788d9c4 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -31,6 +31,7 @@ #define BDADDR_BCM4334B0 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb0, 0x34, 0x43}}) #define BDADDR_BCM4345C5 (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0xc5, 0x45, 0x43}}) #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}}) +#define BDADDR_BCM4384B0 (&(bdaddr_t) {{0x93, 0x76, 0x00, 0xb0, 0x84, 0x43}}) #define BCM_FW_NAME_LEN 64 #define BCM_FW_NAME_COUNT_MAX 4 @@ -130,7 +131,8 @@ int btbcm_check_bdaddr(struct hci_dev *hdev) !bacmp(&bda->bdaddr, BDADDR_BCM4345C5) || !bacmp(&bda->bdaddr, BDADDR_BCM43430A0) || !bacmp(&bda->bdaddr, BDADDR_BCM43430A1) || - !bacmp(&bda->bdaddr, BDADDR_BCM43341B)) { + !bacmp(&bda->bdaddr, BDADDR_BCM43341B) || + !bacmp(&bda->bdaddr, BDADDR_BCM4384B0)) { /* Try falling back to BDADDR EFI variable */ if (btbcm_set_bdaddr_from_efi(hdev) != 0) { bt_dev_info(hdev, "BCM: Using default device address (%pMR)", @@ -514,6 +516,8 @@ static const struct bcm_subver_table bcm_uart_subver_table[] = { { 0x4106, "BCM4335A0" }, /* 002.001.006 */ { 0x410c, "BCM43430B0" }, /* 002.001.012 */ { 0x2119, "BCM4373A0" }, /* 001.001.025 */ + { 0x2128, "BCM4384A0" }, /* 001.001.040 */ + { 0x4119, "BCM4384B0" }, /* 002.001.025 */ { } }; diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index 9a103db7e355..e70b9f3fd968 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -1593,6 +1593,7 @@ static const struct of_device_id bcm_bluetooth_of_match[] = { { .compatible = "brcm,bcm4349-bt", .data = &bcm43438_device_data }, { .compatible = "brcm,bcm43540-bt", .data = &bcm4354_device_data }, { .compatible = "brcm,bcm4335a0" }, + { .compatible = "brcm,bcm4384-bt" }, { .compatible = "cypress,cyw4373a0-bt", .data = &cyw4373a0_device_data }, { .compatible = "infineon,cyw55572-bt", .data = &cyw55572_device_data }, { }, From 937363063afde2dce1f45d8f22514db99b9eba6b Mon Sep 17 00:00:00 2001 From: Chandrashekar Devegowda Date: Fri, 4 Sep 2026 05:59:36 +0530 Subject: [PATCH 1676/2126] Bluetooth: btintel_pcie: remove duplicate BTINTEL_PCIE_MAGIC_NUM definition Two identical definitions of BTINTEL_PCIE_MAGIC_NUM were present in btintel_pcie.c, one indented with spaces and one with a tab. Remove the space-indented duplicate and the surrounding blank lines. Kernel coding style requires tabs for indentation, so keep the tab-indented copy. No functional change. Assisted-by: Copilot:claude-opus-4.7 sparse Fixes: 6ed83047389c ("Bluetooth: btintel_pcie: Setup buffers for firmware traces") Signed-off-by: Chandrashekar Devegowda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 32f7b7067bf8..2b48e6a89283 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -73,11 +73,6 @@ struct btintel_pcie_dev_recovery { #define BTINTEL_PCIE_HCI_EVT_PKT 0x00000004 #define BTINTEL_PCIE_HCI_ISO_PKT 0x00000005 -#define BTINTEL_PCIE_MAGIC_NUM 0xA5A5A5A5 - - - - #define BTINTEL_PCIE_MAGIC_NUM 0xA5A5A5A5 #define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER 0x17A2 From 5530f514d9e4141e3105a9efd4279202d533ebb5 Mon Sep 17 00:00:00 2001 From: Chandrashekar Devegowda Date: Fri, 4 Sep 2026 05:59:37 +0530 Subject: [PATCH 1677/2126] Bluetooth: btintel_pcie: add MDBGC multi-buffer DBGC allocation Newer Intel BT PCIe variants (Nova Lake SCP2 and PTL FMP2) require three independent DRAM debug (DBGC) buffer pools instead of the single pool used by existing controllers. Factor the per-pool buffer allocation into a common helper and add a multi-DBGC (MDBGC) setup path that allocates three pools using the fragment context format. MDBGC is used when the device reports an MDBGC-capable variant; otherwise the existing single-pool DBGC path is retained. Assisted-by: Copilot:claude-opus-4.7 sparse Signed-off-by: Chandrashekar Devegowda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 186 ++++++++++++++++++++++++++----- drivers/bluetooth/btintel_pcie.h | 30 +++++ 2 files changed, 187 insertions(+), 29 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 2b48e6a89283..f02ae5f5e3fe 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -134,6 +134,20 @@ struct btintel_pcie_dbgc_ctxt { struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT]; }; +struct btintel_pcie_mdbgc_ctxt { + u32 magic_num; + u32 ver; + u32 buf1_index; + u32 buf1_count; + struct btintel_pcie_dbgc_ctxt_buf buf1[BTINTEL_PCIE_DBGC_BUFFER_COUNT]; + u32 buf2_index; + u32 buf2_count; + struct btintel_pcie_dbgc_ctxt_buf buf2[BTINTEL_PCIE_DBGC_BUFFER_COUNT]; + u32 buf3_index; + u32 buf3_count; + struct btintel_pcie_dbgc_ctxt_buf buf3[BTINTEL_PCIE_DBGC_BUFFER_COUNT]; +}; + struct btintel_pcie_trigger_evt { u8 type; u8 len; @@ -184,57 +198,159 @@ static inline bool btintel_pcie_dbg_to_wifi(struct btintel_pcie_data *data) return data->dbg_path_cache != BTINTEL_PCIE_DRAM; } -/* This function initializes the memory for DBGC buffers and formats the - * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and - * size as the payload - */ +/* Helper function to allocate and setup a debug buffer group */ +static int btintel_pcie_alloc_dbgc_buf(struct btintel_pcie_data *data, + struct data_buf **buf, + dma_addr_t *p_addr, + void **v_addr, + struct btintel_pcie_dbgc_ctxt_buf *frag, + u32 buf_index, + u32 buf_count) +{ + struct data_buf *b; + int i; + + *buf = devm_kcalloc(&data->pdev->dev, buf_count, + sizeof(**buf), GFP_KERNEL); + if (!*buf) { + BT_ERR("Failed to allocate dbgc buf: %u", + buf_index + 1); + return -ENOMEM; + } + + *v_addr = dmam_alloc_coherent(&data->pdev->dev, + buf_count * + BTINTEL_PCIE_DBGC_BUFFER_SIZE, + p_addr, + GFP_KERNEL | __GFP_NOWARN); + if (!*v_addr) { + BT_ERR("Failed to allocate dbgc buf: %u DMA", + buf_index + 1); + return -ENOMEM; + } + + for (i = 0; i < buf_count; i++) { + b = &(*buf)[i]; + b->data_p_addr = *p_addr + + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; + b->data = *v_addr + + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; + frag[i].buf_addr_lsb = + lower_32_bits(b->data_p_addr); + frag[i].buf_addr_msb = + upper_32_bits(b->data_p_addr); + frag[i].buf_size = BTINTEL_PCIE_DBGC_BUFFER_SIZE; + } + + return 0; +} + +/* This function initializes the memory for MDBGC buffers */ +static int btintel_pcie_setup_mdbgc(struct btintel_pcie_data *data) +{ + struct btintel_pcie_mdbgc_ctxt db_frag; + u32 frag_size = sizeof(db_frag); + void *frag_v_addr; + int err; + + data->mdbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT; + + frag_v_addr = dmam_alloc_coherent(&data->pdev->dev, frag_size, + &data->mdbgc.frag_p_addr, + GFP_KERNEL | __GFP_NOWARN); + if (!frag_v_addr) + return -ENOMEM; + + data->mdbgc.frag_v_addr = frag_v_addr; + data->mdbgc.frag_size = frag_size; + + memset(&db_frag, 0, sizeof(db_frag)); + db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM; + db_frag.ver = BTINTEL_PCIE_MDBGC_FRAG_VERSION; + + /* Allocate DBGC buffer 1 */ + db_frag.buf1_index = BTINTEL_PCIE_MDBGC_ALLOCATIONID_1; + db_frag.buf1_count = data->mdbgc.count; + err = btintel_pcie_alloc_dbgc_buf(data, + &data->mdbgc.buf1, + &data->mdbgc.buf1_p_addr, + &data->mdbgc.buf1_v_addr, + db_frag.buf1, 0, + data->mdbgc.count); + if (err) + return err; + + /* Allocate DBGC buffer 2 */ + db_frag.buf2_index = BTINTEL_PCIE_MDBGC_ALLOCATIONID_2; + db_frag.buf2_count = data->mdbgc.count; + err = btintel_pcie_alloc_dbgc_buf(data, + &data->mdbgc.buf2, + &data->mdbgc.buf2_p_addr, + &data->mdbgc.buf2_v_addr, + db_frag.buf2, 1, + data->mdbgc.count); + if (err) + return err; + + /* Allocate DBGC buffer 3 */ + db_frag.buf3_index = BTINTEL_PCIE_MDBGC_ALLOCATIONID_3; + db_frag.buf3_count = data->mdbgc.count; + err = btintel_pcie_alloc_dbgc_buf(data, + &data->mdbgc.buf3, + &data->mdbgc.buf3_p_addr, + &data->mdbgc.buf3_v_addr, + db_frag.buf3, 2, + data->mdbgc.count); + if (err) + return err; + + memcpy(data->mdbgc.frag_v_addr, &db_frag, sizeof(db_frag)); + return 0; +} + +/* This function initializes the memory for DBGC buffers */ static int btintel_pcie_setup_dbgc(struct btintel_pcie_data *data) { struct btintel_pcie_dbgc_ctxt db_frag; - struct data_buf *buf; - int i; + int err; data->dbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT; - data->dbgc.bufs = devm_kcalloc(&data->pdev->dev, data->dbgc.count, - sizeof(*buf), GFP_KERNEL); - if (!data->dbgc.bufs) - return -ENOMEM; - - data->dbgc.buf_v_addr = dmam_alloc_coherent(&data->pdev->dev, - data->dbgc.count * - BTINTEL_PCIE_DBGC_BUFFER_SIZE, - &data->dbgc.buf_p_addr, - GFP_KERNEL | __GFP_NOWARN); - if (!data->dbgc.buf_v_addr) - return -ENOMEM; data->dbgc.frag_v_addr = dmam_alloc_coherent(&data->pdev->dev, - sizeof(struct btintel_pcie_dbgc_ctxt), - &data->dbgc.frag_p_addr, - GFP_KERNEL | __GFP_NOWARN); + sizeof(struct btintel_pcie_dbgc_ctxt), + &data->dbgc.frag_p_addr, + GFP_KERNEL | __GFP_NOWARN); if (!data->dbgc.frag_v_addr) return -ENOMEM; data->dbgc.frag_size = sizeof(struct btintel_pcie_dbgc_ctxt); + memset(&db_frag, 0, sizeof(db_frag)); db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM; db_frag.ver = BTINTEL_PCIE_DBGC_FRAG_VERSION; db_frag.total_size = BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE; db_frag.num_buf = BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT; - for (i = 0; i < data->dbgc.count; i++) { - buf = &data->dbgc.bufs[i]; - buf->data_p_addr = data->dbgc.buf_p_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; - buf->data = data->dbgc.buf_v_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; - db_frag.bufs[i].buf_addr_lsb = lower_32_bits(buf->data_p_addr); - db_frag.bufs[i].buf_addr_msb = upper_32_bits(buf->data_p_addr); - db_frag.bufs[i].buf_size = BTINTEL_PCIE_DBGC_BUFFER_SIZE; - } + err = btintel_pcie_alloc_dbgc_buf(data, + &data->dbgc.bufs, + &data->dbgc.buf_p_addr, + &data->dbgc.buf_v_addr, + db_frag.bufs, 0, + data->dbgc.count); + if (err) + return err; memcpy(data->dbgc.frag_v_addr, &db_frag, sizeof(db_frag)); return 0; } +static bool btintel_pcie_is_mdbgc_supported(struct btintel_pcie_data *data) +{ + return data->pdev->device == BTINTEL_PCIE_DEVICE_ID_NVL_S_SCP2 || + data->pdev->device == BTINTEL_PCIE_DEVICE_ID_NVL_Hx_SCP2 || + data->pdev->device == BTINTEL_PCIE_DEVICE_ID_PTL_FMP2; +} + static inline void ipc_print_ia_ring(struct hci_dev *hdev, struct ia *ia, u16 queue_num) { @@ -1877,6 +1993,12 @@ static void btintel_pcie_coredump_worker(struct work_struct *work) goto out; } + if (btintel_pcie_is_mdbgc_supported(data)) { + bt_dev_info(data->hdev, + "Skipping coredump: MDBGC dump format not supported yet"); + goto out; + } + btintel_pcie_dump_traces(data->hdev); out: /* Release guard last so a new trigger can run only after this @@ -2282,10 +2404,14 @@ static void btintel_pcie_init_ci(struct btintel_pcie_data *data, */ ci->dbgc_addr = 0; ci->dbgc_size = 0; + } else if (btintel_pcie_is_mdbgc_supported(data)) { + ci->dbgc_addr = data->mdbgc.frag_p_addr; + ci->dbgc_size = data->mdbgc.frag_size; } else { ci->dbgc_addr = data->dbgc.frag_p_addr; ci->dbgc_size = data->dbgc.frag_size; } + ci->dbg_preset = 0x00; } @@ -2518,6 +2644,8 @@ static int btintel_pcie_alloc(struct btintel_pcie_data *data) * buffer allocation entirely. */ err = 0; + } else if (btintel_pcie_is_mdbgc_supported(data)) { + err = btintel_pcie_setup_mdbgc(data); } else { err = btintel_pcie_setup_dbgc(data); } diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 9baa214d9bbe..5c35e65d3e81 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -106,8 +106,19 @@ * Bits[2:3] DBGI O/P : 01 = WiFi DBGC */ #define BTINTEL_PCIE_DRAM 0x01 +#define BTINTEL_PCIE_FW_MON_MODE_DRAM 0x02 #define BTINTEL_PCIE_WIFI_DBGC 0x06 +#define BTINTEL_PCIE_MDBGC_FRAG_VERSION 2 + +#define BTINTEL_PCIE_MDBGC_ALLOCATIONID_1 0 +#define BTINTEL_PCIE_MDBGC_ALLOCATIONID_2 1 +#define BTINTEL_PCIE_MDBGC_ALLOCATIONID_3 2 + +#define BTINTEL_PCIE_DEVICE_ID_NVL_S_SCP2 0x6E74 +#define BTINTEL_PCIE_DEVICE_ID_NVL_Hx_SCP2 0xD346 +#define BTINTEL_PCIE_DEVICE_ID_PTL_FMP2 0xE476 + /* Causes for the FH register interrupts */ enum msix_fh_int_causes { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0 = BIT(0), /* cause 0 */ @@ -459,6 +470,24 @@ struct btintel_pcie_dbgc { struct data_buf *bufs; }; +struct btintel_pcie_mdbgc { + u32 count; + + void *frag_v_addr; + dma_addr_t frag_p_addr; + u32 frag_size; + + dma_addr_t buf1_p_addr; + void *buf1_v_addr; + dma_addr_t buf2_p_addr; + void *buf2_v_addr; + dma_addr_t buf3_p_addr; + void *buf3_v_addr; + struct data_buf *buf1; + struct data_buf *buf2; + struct data_buf *buf3; +}; + struct btintel_pcie_dump_mem_info { u32 exception_dump_addr; u32 exception_dump_len; @@ -599,6 +628,7 @@ struct btintel_pcie_data { u32 alive_intr_ctxt; enum btintel_pcie_reset_type reset_type; struct btintel_pcie_dbgc dbgc; + struct btintel_pcie_mdbgc mdbgc; struct btintel_pcie_dump_header dmp_hdr; u8 pm_sx_event; u32 debug_evt_addr; From 9ea41cd5a6397544620c185d52d23ec556e37d02 Mon Sep 17 00:00:00 2001 From: Chandrashekar Devegowda Date: Fri, 4 Sep 2026 05:59:38 +0530 Subject: [PATCH 1678/2126] Bluetooth: btintel_pcie: unified decoder coredump format Replace the legacy TLV-based coredump with a unified INI-format dump compatible with the iwlwifi decoder so a single decoder can parse coredumps across all Intel BT PCIe controller variants. The dump is emitted via dev_coredumpsg() as structured regions built from firmware-advertised addresses: DRAM monitor buffers (single or MDBGC multi-buffer), SMEM monitor, exception event buffer, DCCM, SDS, SDS IOSF, ECL and dump info metadata. Regions are collected only when firmware advertises a valid address and size, and only collected regions are advertised in regions_mask. Add INTEL_CNVX_TOP_DASH() and INTEL_CNVX_TOP_FLAVOR() helpers to btintel.h for RfIdDash/RfIdFlavor extraction. Assisted-by: Copilot:gemini-3.6-flash Signed-off-by: Chandrashekar Devegowda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.h | 2 + drivers/bluetooth/btintel_pcie.c | 879 ++++++++++++++++++++++++------- drivers/bluetooth/btintel_pcie.h | 149 +++++- 3 files changed, 842 insertions(+), 188 deletions(-) diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index ef232820c31b..c00f793d9dc8 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -225,7 +225,9 @@ struct btintel_sar_rev2 { #define INTEL_HW_PLATFORM(cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) >> 8)) #define INTEL_HW_VARIANT(cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000) >> 16)) #define INTEL_CNVX_TOP_TYPE(cnvx_top) ((cnvx_top) & 0x00000fff) +#define INTEL_CNVX_TOP_DASH(cnvx_top) (((cnvx_top) & 0x00f00000) >> 20) #define INTEL_CNVX_TOP_STEP(cnvx_top) (((cnvx_top) & 0x0f000000) >> 24) +#define INTEL_CNVX_TOP_FLAVOR(cnvx_top) (((cnvx_top) & 0xf0000000) >> 28) #define INTEL_CNVX_TOP_PACK_SWAB(t, s) __swab16(((__u16)(((t) << 4) | (s)))) enum { diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index f02ae5f5e3fe..42800361c49f 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -198,7 +199,15 @@ static inline bool btintel_pcie_dbg_to_wifi(struct btintel_pcie_data *data) return data->dbg_path_cache != BTINTEL_PCIE_DRAM; } -/* Helper function to allocate and setup a debug buffer group */ +/* Helper function to allocate and setup a debug buffer group + * @data: driver data structure + * @buf: pointer to data_buf array pointer + * @p_addr: pointer to physical DMA address + * @v_addr: pointer to virtual address + * @frag: pointer to fragment buffer array + * @buf_index: buffer index (for error messages) + * @buf_count: number of buffers to allocate + */ static int btintel_pcie_alloc_dbgc_buf(struct btintel_pcie_data *data, struct data_buf **buf, dma_addr_t *p_addr, @@ -213,39 +222,36 @@ static int btintel_pcie_alloc_dbgc_buf(struct btintel_pcie_data *data, *buf = devm_kcalloc(&data->pdev->dev, buf_count, sizeof(**buf), GFP_KERNEL); if (!*buf) { - BT_ERR("Failed to allocate dbgc buf: %u", - buf_index + 1); + BT_ERR("Failed to allocate dbgc buf: %u", buf_index + 1); return -ENOMEM; } *v_addr = dmam_alloc_coherent(&data->pdev->dev, buf_count * - BTINTEL_PCIE_DBGC_BUFFER_SIZE, - p_addr, - GFP_KERNEL | __GFP_NOWARN); + BTINTEL_PCIE_DBGC_BUFFER_SIZE, + p_addr, + GFP_KERNEL | __GFP_NOWARN); if (!*v_addr) { - BT_ERR("Failed to allocate dbgc buf: %u DMA", - buf_index + 1); + BT_ERR("Failed to allocate dbgc buf: %u DMA", buf_index + 1); return -ENOMEM; } for (i = 0; i < buf_count; i++) { b = &(*buf)[i]; - b->data_p_addr = *p_addr + - i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; - b->data = *v_addr + - i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; - frag[i].buf_addr_lsb = - lower_32_bits(b->data_p_addr); - frag[i].buf_addr_msb = - upper_32_bits(b->data_p_addr); + b->data_p_addr = *p_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; + b->data = *v_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE; + frag[i].buf_addr_lsb = lower_32_bits(b->data_p_addr); + frag[i].buf_addr_msb = upper_32_bits(b->data_p_addr); frag[i].buf_size = BTINTEL_PCIE_DBGC_BUFFER_SIZE; } return 0; } -/* This function initializes the memory for MDBGC buffers */ +/* This function initializes the memory for MDBGC buffers and formats the + * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and + * size as the payload + */ static int btintel_pcie_setup_mdbgc(struct btintel_pcie_data *data) { struct btintel_pcie_mdbgc_ctxt db_frag; @@ -255,15 +261,19 @@ static int btintel_pcie_setup_mdbgc(struct btintel_pcie_data *data) data->mdbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT; + /* Allocate fragment context structure */ frag_v_addr = dmam_alloc_coherent(&data->pdev->dev, frag_size, &data->mdbgc.frag_p_addr, GFP_KERNEL | __GFP_NOWARN); - if (!frag_v_addr) + if (!frag_v_addr) { + BT_ERR("Failed to allocate mdbgc context"); return -ENOMEM; + } data->mdbgc.frag_v_addr = frag_v_addr; data->mdbgc.frag_size = frag_size; + /* Initialize fragment header */ memset(&db_frag, 0, sizeof(db_frag)); db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM; db_frag.ver = BTINTEL_PCIE_MDBGC_FRAG_VERSION; @@ -275,7 +285,8 @@ static int btintel_pcie_setup_mdbgc(struct btintel_pcie_data *data) &data->mdbgc.buf1, &data->mdbgc.buf1_p_addr, &data->mdbgc.buf1_v_addr, - db_frag.buf1, 0, + db_frag.buf1, + 0, data->mdbgc.count); if (err) return err; @@ -287,7 +298,8 @@ static int btintel_pcie_setup_mdbgc(struct btintel_pcie_data *data) &data->mdbgc.buf2, &data->mdbgc.buf2_p_addr, &data->mdbgc.buf2_v_addr, - db_frag.buf2, 1, + db_frag.buf2, + 1, data->mdbgc.count); if (err) return err; @@ -299,58 +311,64 @@ static int btintel_pcie_setup_mdbgc(struct btintel_pcie_data *data) &data->mdbgc.buf3, &data->mdbgc.buf3_p_addr, &data->mdbgc.buf3_v_addr, - db_frag.buf3, 2, + db_frag.buf3, + 2, data->mdbgc.count); if (err) return err; + /* Copy fragment to DMA coherent memory */ memcpy(data->mdbgc.frag_v_addr, &db_frag, sizeof(db_frag)); return 0; } -/* This function initializes the memory for DBGC buffers */ +/* This function initializes the memory for DBGC buffers and formats the + * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and + * size as the payload + */ static int btintel_pcie_setup_dbgc(struct btintel_pcie_data *data) { struct btintel_pcie_dbgc_ctxt db_frag; + u32 frag_size = sizeof(db_frag); int err; data->dbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT; + /* Allocate fragment context structure */ data->dbgc.frag_v_addr = dmam_alloc_coherent(&data->pdev->dev, - sizeof(struct btintel_pcie_dbgc_ctxt), - &data->dbgc.frag_p_addr, - GFP_KERNEL | __GFP_NOWARN); - if (!data->dbgc.frag_v_addr) + frag_size, + &data->dbgc.frag_p_addr, + GFP_KERNEL | __GFP_NOWARN); + if (!data->dbgc.frag_v_addr) { + BT_ERR("Failed to allocate dbgc context"); return -ENOMEM; + } data->dbgc.frag_size = sizeof(struct btintel_pcie_dbgc_ctxt); + /* Initialize fragment header */ memset(&db_frag, 0, sizeof(db_frag)); db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM; db_frag.ver = BTINTEL_PCIE_DBGC_FRAG_VERSION; db_frag.total_size = BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE; db_frag.num_buf = BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT; + /* Allocate DBGC buffers */ err = btintel_pcie_alloc_dbgc_buf(data, &data->dbgc.bufs, &data->dbgc.buf_p_addr, &data->dbgc.buf_v_addr, - db_frag.bufs, 0, + db_frag.bufs, + 0, data->dbgc.count); if (err) return err; + /* Copy fragment to DMA coherent memory */ memcpy(data->dbgc.frag_v_addr, &db_frag, sizeof(db_frag)); return 0; } -static bool btintel_pcie_is_mdbgc_supported(struct btintel_pcie_data *data) -{ - return data->pdev->device == BTINTEL_PCIE_DEVICE_ID_NVL_S_SCP2 || - data->pdev->device == BTINTEL_PCIE_DEVICE_ID_NVL_Hx_SCP2 || - data->pdev->device == BTINTEL_PCIE_DEVICE_ID_PTL_FMP2; -} - static inline void ipc_print_ia_ring(struct hci_dev *hdev, struct ia *ia, u16 queue_num) { @@ -759,169 +777,673 @@ static void btintel_pcie_release_mac_access(struct btintel_pcie_data *data) } } -static void *btintel_pcie_copy_tlv(void *dest, enum btintel_pcie_tlv_type type, - void *data, size_t size) +static struct scatterlist *btintel_pcie_alloc_sgtable(ssize_t size) { - struct intel_tlv *tlv; + int nents; + struct page *page; + struct scatterlist *sg, *result; - tlv = dest; - tlv->type = type; - tlv->len = size; - memcpy(tlv->val, data, tlv->len); - return dest + sizeof(*tlv) + size; + if (size <= 0) + return NULL; + + nents = DIV_ROUND_UP(size, PAGE_SIZE); + result = kcalloc(nents, sizeof(*result), GFP_KERNEL); + if (!result) + return NULL; + + sg_init_table(result, nents); + sg = result; + + while (size > 0) { + ssize_t bytes = min_t(ssize_t, size, PAGE_SIZE); + + page = alloc_page(GFP_KERNEL | __GFP_ZERO); + if (!page) + goto err_free; + + sg_set_page(sg, page, bytes, 0); + sg = sg_next(sg); + size -= bytes; + } + return result; + +err_free: + for (sg = result; sg; sg = sg_next(sg)) { + page = sg_page(sg); + if (page) + __free_page(page); + } + kfree(result); + return NULL; } -static int btintel_pcie_read_dram_buffers(struct btintel_pcie_data *data) +static struct btintel_pcie_dump_entry * +btintel_pcie_dump_entry_alloc(u32 data_size) { - u32 offset, prev_size, wr_ptr_status, dump_size, data_len; - u32 status_reg, wrap_reg; - struct btintel_pcie_dbgc *dbgc = &data->dbgc; + struct btintel_pcie_dump_entry *entry; + + entry = vzalloc(sizeof(*entry) + data_size); + if (!entry) + return NULL; + + entry->size = data_size; + INIT_LIST_HEAD(&entry->list); + return entry; +} + +static void btintel_pcie_dump_list_free(struct list_head *list) +{ + struct btintel_pcie_dump_entry *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, list, list) { + list_del(&entry->list); + vfree(entry); + } +} + +static u32 btintel_pcie_dump_list_total_size(struct list_head *list) +{ + struct btintel_pcie_dump_entry *entry; + u32 total = 0; + + list_for_each_entry(entry, list, list) + total += entry->size; + + return total; +} + +static int btintel_pcie_dump_dram(struct list_head *list, + u8 count, struct data_buf *bufs, + u32 write_ptr, u32 wrap_ctr, u32 cur_frag, + u32 region_id, const char *name) +{ + struct btintel_pcie_dump_entry *entry; + struct btintel_pcie_ini_dump_data *dump_data; + struct btintel_pcie_ini_monitor_dump *mon_dump; + struct btintel_pcie_dump_range *range; + u32 mon_hdr_size, ranges_size, payload_size, total_size; + int i; + + mon_hdr_size = sizeof(*mon_dump); + ranges_size = count * (sizeof(*range) + BTINTEL_PCIE_DBGC_BUFFER_SIZE); + payload_size = mon_hdr_size + ranges_size; + total_size = sizeof(*dump_data) + payload_size; + + entry = btintel_pcie_dump_entry_alloc(total_size); + if (!entry) + return -ENOMEM; + + dump_data = (void *)entry->data; + dump_data->type = BTINTEL_PCIE_INI_REGION_DRAM_BUFFER; + dump_data->sub_type = 0; + dump_data->sub_type_ver = 0; + dump_data->reserved = 0; + dump_data->len = cpu_to_le32(payload_size); + + mon_dump = (void *)dump_data->data; + mon_dump->header.version = cpu_to_le32(BTINTEL_PCIE_INI_DUMP_VER); + mon_dump->header.region_id = cpu_to_le32(region_id); + mon_dump->header.num_of_ranges = cpu_to_le32(count); + mon_dump->header.name_len = cpu_to_le32(BTINTEL_PCIE_INI_MAX_NAME); + memset(mon_dump->header.name, 0, BTINTEL_PCIE_INI_MAX_NAME); + strscpy(mon_dump->header.name, name, BTINTEL_PCIE_INI_MAX_NAME); + + mon_dump->write_ptr = cpu_to_le32(write_ptr); + mon_dump->cycle_cnt = cpu_to_le32(wrap_ctr); + mon_dump->cur_frag = cpu_to_le32(cur_frag); + + range = (void *)mon_dump->data; + for (i = 0; i < count; i++) { + range->range_data_size = + cpu_to_le32(BTINTEL_PCIE_DBGC_BUFFER_SIZE); + range->dram_base_addr = cpu_to_le64(bufs[i].data_p_addr); + memcpy(range->data, bufs[i].data, + BTINTEL_PCIE_DBGC_BUFFER_SIZE); + range = (void *)range->data + BTINTEL_PCIE_DBGC_BUFFER_SIZE; + } + + list_add_tail(&entry->list, list); + return 0; +} + +static int +btintel_pcie_dump_dram_monitor(struct btintel_pcie_data *data, + struct list_head *list, u8 count, + struct data_buf *bufs, u32 status_reg, + u32 wrap_reg, u8 allocation_id, u32 region_id, + const char *name) +{ + u32 allocation_offset, write_ptr, wrap_ctr, wr_ptr_status; + u8 cur_frag; + + allocation_offset = allocation_id * + BTINTEL_PCIE_DBGC_ALLOCATION_OFFSET; + wr_ptr_status = btintel_pcie_rd_dev_mem(data, status_reg + + allocation_offset); + wrap_ctr = btintel_pcie_rd_dev_mem(data, wrap_reg + + allocation_offset); + + write_ptr = wr_ptr_status & BTINTEL_PCIE_DBG_OFFSET_BIT_MASK; + write_ptr >>= 2; + cur_frag = BTINTEL_PCIE_DBGC_DBG_BUF_IDX(wr_ptr_status); + if (cur_frag >= count) { + bt_dev_warn(data->hdev, + "Invalid DRAM monitor fragment %u for allocation %u", + cur_frag, allocation_id); + return -EINVAL; + } + + bt_dev_dbg(data->hdev, + "allocation=%u wr_ptr_status=0x%08x write_ptr=0x%06x cur_frag=%u wrap_ctr=0x%08x", + allocation_id, wr_ptr_status, write_ptr, cur_frag, wrap_ctr); + + return btintel_pcie_dump_dram(list, count, bufs, write_ptr, wrap_ctr, + cur_frag, region_id, name); +} + +static int btintel_pcie_dump_target_region(struct btintel_pcie_data *data, + struct list_head *list, + u32 region_id, const char *name, + u32 addr_start, u32 size) +{ + struct btintel_pcie_dump_entry *entry; + struct btintel_pcie_ini_dump_data *dump_data; + struct btintel_pcie_ini_dump_header *hdr; + struct btintel_pcie_dump_range *range; + u32 payload_size, total_size, target_mem_offset, tempdata; + u8 *dest; + int i; + + if (!size) { + bt_dev_warn(data->hdev, "Skipping empty dump region: %s", name); + return 1; + } + + if (!addr_start) { + bt_dev_warn(data->hdev, + "Skipping dump region with zero address: %s", + name); + return 1; + } + + if (size > BTINTEL_PCIE_REGION_MAX_SIZE) { + bt_dev_warn(data->hdev, + "Skipping dump region %s: size %u exceeds max %u", + name, size, BTINTEL_PCIE_REGION_MAX_SIZE); + return 1; + } + + if (addr_start > U32_MAX - size) { + bt_dev_warn(data->hdev, + "Skipping dump region %s: addr_start 0x%08x + size %u would overflow", + name, addr_start, size); + return 1; + } + + /* Align to 4 bytes - target access reads 32-bit words */ + size = round_down(size, sizeof(u32)); + if (!size) { + bt_dev_warn(data->hdev, + "Skipping dump region %s: size is smaller than 4-byte access", + name); + return 1; + } + + bt_dev_dbg(data->hdev, + "Target access: region=%s start=0x%08x size=%u", + name, addr_start, size); + + payload_size = sizeof(*hdr) + sizeof(*range) + size; + total_size = sizeof(*dump_data) + payload_size; + entry = btintel_pcie_dump_entry_alloc(total_size); + if (!entry) + return -ENOMEM; + + dump_data = (void *)entry->data; + dump_data->type = BTINTEL_PCIE_INI_REGION_DEVICE_MEMORY; + dump_data->sub_type = 0; + dump_data->sub_type_ver = 0; + dump_data->reserved = 0; + dump_data->len = cpu_to_le32(payload_size); + + hdr = (void *)dump_data->data; + hdr->version = cpu_to_le32(BTINTEL_PCIE_INI_DUMP_VER); + hdr->region_id = cpu_to_le32(region_id); + hdr->num_of_ranges = cpu_to_le32(1); + hdr->name_len = cpu_to_le32(BTINTEL_PCIE_INI_MAX_NAME); + memset(hdr->name, 0, BTINTEL_PCIE_INI_MAX_NAME); + strscpy(hdr->name, name, BTINTEL_PCIE_INI_MAX_NAME); + + range = (void *)(hdr + 1); + range->range_data_size = cpu_to_le32(size); + range->internal_base_addr = cpu_to_le32(addr_start); + + dest = (u8 *)range->data; + target_mem_offset = size / sizeof(u32); + for (i = 0; i < target_mem_offset; i++) { + u32 offset = BTINTEL_PCIE_TARGET_ACCESS_FRAG_OFFSET * i; + + tempdata = btintel_pcie_rd_dev_mem(data, + addr_start + offset); + memcpy(dest, &tempdata, sizeof(tempdata)); + dest += sizeof(tempdata); + } + + list_add_tail(&entry->list, list); + return 0; +} + +static int btintel_pcie_dump_smem_monitor_region(struct btintel_pcie_data *data, + struct list_head *list, + u32 region_id, + const char *name, + u32 addr_start, u32 size) +{ + struct btintel_pcie_dump_entry *entry; + struct btintel_pcie_ini_dump_data *dump_data; + struct btintel_pcie_ini_monitor_dump *mon; + struct btintel_pcie_dump_range *range; + u32 payload_size, total_size, target_mem_offset, tempdata; + u8 *dest; + int i; + + if (!size || !addr_start) { + bt_dev_err(data->hdev, "Skipping smem dump: size = %u addr = %8.8x", + size, addr_start); + return -EINVAL; + } + + payload_size = sizeof(*mon) + sizeof(*range) + size; + total_size = sizeof(*dump_data) + payload_size; + entry = btintel_pcie_dump_entry_alloc(total_size); + if (!entry) + return -ENOMEM; + + dump_data = (void *)entry->data; + dump_data->type = BTINTEL_PCIE_INI_REGION_INTERNAL_BUFFER; + dump_data->sub_type = 0; + dump_data->sub_type_ver = 0; + dump_data->reserved = 0; + dump_data->len = cpu_to_le32(payload_size); + + mon = (void *)dump_data->data; + mon->header.version = cpu_to_le32(BTINTEL_PCIE_INI_DUMP_VER); + mon->header.region_id = cpu_to_le32(region_id); + mon->header.num_of_ranges = cpu_to_le32(1); + mon->header.name_len = cpu_to_le32(BTINTEL_PCIE_INI_MAX_NAME); + memset(mon->header.name, 0, BTINTEL_PCIE_INI_MAX_NAME); + strscpy(mon->header.name, name, BTINTEL_PCIE_INI_MAX_NAME); + + mon->write_ptr = cpu_to_le32(0); + mon->cycle_cnt = cpu_to_le32(0); + mon->cur_frag = cpu_to_le32(0); + + range = (void *)mon->data; + range->range_data_size = cpu_to_le32(size); + range->internal_base_addr = cpu_to_le32(addr_start); + + dest = (u8 *)range->data; + target_mem_offset = size / sizeof(u32); + for (i = 0; i < target_mem_offset; i++) { + u32 offset = BTINTEL_PCIE_TARGET_ACCESS_FRAG_OFFSET * i; + + tempdata = btintel_pcie_rd_dev_mem(data, + addr_start + offset); + memcpy(dest, &tempdata, sizeof(tempdata)); + dest += sizeof(tempdata); + } + + list_add_tail(&entry->list, list); + return 0; +} + +static int btintel_pcie_dump_info(struct btintel_pcie_data *data, + struct list_head *list, + u64 regions_mask) +{ + struct btintel_pcie_dump_entry *entry; + struct btintel_pcie_error_dump_data *tlv; + struct btintel_pcie_ini_dump_info *dump; + u32 size = sizeof(*tlv) + sizeof(*dump); + char build_tag[64]; + + entry = btintel_pcie_dump_entry_alloc(size); + if (!entry) + return -ENOMEM; + + tlv = (void *)entry->data; + tlv->type = cpu_to_le32(BTINTEL_PCIE_INI_DUMP_INFO_TYPE); + tlv->len = cpu_to_le32(sizeof(*dump)); + + dump = (void *)tlv->data; + memset(dump, 0, sizeof(*dump)); + + dump->version = cpu_to_le32(BTINTEL_PCIE_INI_DUMP_VER); + dump->trigger_reason = cpu_to_le32(data->dmp_hdr.trigger_reason); + + if (data->dmp_hdr.trigger_reason == + BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT) + dump->time_point = + cpu_to_le32(BTINTEL_PCIE_TIME_POINT_FW_ASSERT); + else if (data->dmp_hdr.trigger_reason == + BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER) + dump->time_point = + cpu_to_le32(BTINTEL_PCIE_TIME_POINT_USER_TRIGGER); + + dump->hw_type = cpu_to_le32(INTEL_CNVX_TOP_TYPE(data->dmp_hdr.cnvi_top)); + dump->hw_step = cpu_to_le32(INTEL_CNVX_TOP_STEP(data->dmp_hdr.cnvi_top)); + bt_dev_dbg(data->hdev, "hw_type=0x%x hw_step=0x%x (cnvi_top=0x%x)", + le32_to_cpu(dump->hw_type), le32_to_cpu(dump->hw_step), + data->dmp_hdr.cnvi_top); + + dump->ver_type = cpu_to_le32(data->dmp_hdr.cnvi_bt); + dump->ver_subtype = cpu_to_le32(data->dmp_hdr.fw_sha); + dump->rf_id_type = cpu_to_le32(INTEL_CNVX_TOP_TYPE(data->dmp_hdr.cnvr_top)); + dump->rf_id_dash = cpu_to_le32(INTEL_CNVX_TOP_DASH(data->dmp_hdr.cnvr_top)); + dump->rf_id_step = cpu_to_le32(INTEL_CNVX_TOP_STEP(data->dmp_hdr.cnvr_top)); + dump->rf_id_flavor = cpu_to_le32(INTEL_CNVX_TOP_FLAVOR(data->dmp_hdr.cnvr_top)); + bt_dev_dbg(data->hdev, + "rf_id_type=0x%x rf_id_dash=0x%x rf_id_step=0x%x rf_id_flavor=0x%x (cnvr_top=0x%x)", + le32_to_cpu(dump->rf_id_type), + le32_to_cpu(dump->rf_id_dash), + le32_to_cpu(dump->rf_id_step), + le32_to_cpu(dump->rf_id_flavor), + data->dmp_hdr.cnvr_top); + dump->lmac_major = cpu_to_le32(0); + dump->lmac_minor = cpu_to_le32(0); + dump->umac_major = cpu_to_le32(0); + dump->umac_minor = cpu_to_le32(0); + dump->fw_mon_mode = cpu_to_le32(BTINTEL_PCIE_FW_MON_MODE_DRAM); + + dump->regions_mask = cpu_to_le64(regions_mask); + + bt_dev_dbg(data->hdev, "ExpectedRegionIDs regions_mask=0x%016llx", + le64_to_cpu(dump->regions_mask)); + + snprintf(build_tag, sizeof(build_tag), "%08X", data->dmp_hdr.fw_sha); + + dump->build_tag_len = cpu_to_le32(strlen(build_tag)); + memcpy(dump->build_tag, build_tag, min(strlen(build_tag), + sizeof(dump->build_tag))); + + dump->num_of_cfg_names = cpu_to_le32(0); + + bt_dev_dbg(data->hdev, + "HwType=0x%08x HwStep=0x%08x RfIdType=0x%08x RfIdDash=0x%08x RfIdStep=0x%08x RfIdFlavor=0x%08x", + le32_to_cpu(dump->hw_type), le32_to_cpu(dump->hw_step), + le32_to_cpu(dump->rf_id_type), + le32_to_cpu(dump->rf_id_dash), + le32_to_cpu(dump->rf_id_step), + le32_to_cpu(dump->rf_id_flavor)); + bt_dev_dbg(data->hdev, "VerType=0x%08x VerSubType=0x%08x", + le32_to_cpu(dump->ver_type), le32_to_cpu(dump->ver_subtype)); + bt_dev_dbg(data->hdev, + "LmacMajor=0x%08x LmacMinor=0x%08x UmacMajor=0x%08x UmacMinor=0x%08x", + le32_to_cpu(dump->lmac_major), le32_to_cpu(dump->lmac_minor), + le32_to_cpu(dump->umac_major), + le32_to_cpu(dump->umac_minor)); + bt_dev_dbg(data->hdev, "TriggerReason=0x%04x MonMode=%u BuildTag=%.64s", + le32_to_cpu(dump->trigger_reason), + le32_to_cpu(dump->fw_mon_mode), + dump->build_tag); + + list_add(&entry->list, list); + + return 0; +} + +static bool btintel_pcie_is_mdbgc_supported(struct btintel_pcie_data *data) +{ + return data->pdev->device == BTINTEL_PCIE_DEVICE_ID_NVL_S_SCP2 || + data->pdev->device == BTINTEL_PCIE_DEVICE_ID_NVL_Hx_SCP2 || + data->pdev->device == BTINTEL_PCIE_DEVICE_ID_PTL_FMP2; +} + +static void btintel_pcie_dump_mem_range(struct btintel_pcie_data *data, + struct list_head *list, u32 region_id, + const char *name, u32 addr_start, + u32 addr_end, u64 *regions_mask) +{ + u32 region_size; + + if (!addr_start || !addr_end || addr_end < addr_start) + return; + + if (addr_end > U32_MAX - 0x04) { + bt_dev_warn(data->hdev, + "Skipping dump region %s: addr_end 0x%08x would overflow", + name, addr_end); + return; + } + + region_size = (addr_end + 0x04) - addr_start; + if (region_size > BTINTEL_PCIE_REGION_MAX_SIZE) { + bt_dev_warn(data->hdev, + "Skipping dump region %s: size %u exceeds max %u", + name, region_size, + BTINTEL_PCIE_REGION_MAX_SIZE); + return; + } + + if (!btintel_pcie_dump_target_region(data, list, region_id, name, + addr_start, region_size)) + *regions_mask |= BIT_ULL(region_id); +} + +static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data) +{ + struct btintel_pcie_dbgc *dbgc = NULL; + struct btintel_pcie_mdbgc *mdbgc = NULL; struct hci_dev *hdev = data->hdev; - u8 *pdata, *p, buf_idx, hw_variant; - struct intel_tlv *tlv; - struct timespec64 now; - struct tm tm_now; - char fw_build[128]; - char ts[128]; - char vendor[64]; - char driver[64]; + struct btintel_pcie_dump_entry *entry; + struct btintel_pcie_dump_file_hdr *file_hdr; + struct scatterlist *sg_dump_data; + u32 status_reg, wrap_reg; + u32 exception_dump_len; + u32 exc_addr; + u64 regions_mask = 0; + u8 hw_variant; + u32 smem_rd_addr = 0, smem_rd_size = 0; + u32 file_len; + u8 count; + int ret; + LIST_HEAD(dump_list); if (!IS_ENABLED(CONFIG_DEV_COREDUMP)) return -EOPNOTSUPP; + if (btintel_pcie_is_mdbgc_supported(data)) { + mdbgc = &data->mdbgc; + count = mdbgc->count; + } else { + dbgc = &data->dbgc; + count = dbgc->count; + } hw_variant = INTEL_HW_VARIANT(data->cnvi); - switch (hw_variant) { - case BTINTEL_HWID_BZRI: - case BTINTEL_HWID_BZRIW: + + if (hw_variant == BTINTEL_HWID_BZRI || + hw_variant == BTINTEL_HWID_BZRIW) { status_reg = BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS; wrap_reg = BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND; - break; - case BTINTEL_HWID_SCP: - case BTINTEL_HWID_SCP2: - case BTINTEL_HWID_SCP2F: + } else if (hw_variant >= BTINTEL_HWID_SCP) { status_reg = BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS_SCP; wrap_reg = BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND_SCP; - break; - default: - bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%2.2x)", + } else { + bt_dev_err(hdev, + "Unsupported Intel hardware variant (0x%2.2x)", hw_variant); return -EINVAL; } - wr_ptr_status = btintel_pcie_rd_dev_mem(data, status_reg); - data->dmp_hdr.wrap_ctr = btintel_pcie_rd_dev_mem(data, wrap_reg); + smem_rd_addr = data->dump_info.smem_addr_start; + smem_rd_size = 0; - offset = wr_ptr_status & BTINTEL_PCIE_DBG_OFFSET_BIT_MASK; + if (!smem_rd_addr && !data->dump_info.smem_addr_end) { + bt_dev_dbg(hdev, "smem region not advertised by firmware"); + } else if (data->dump_info.smem_addr_end < smem_rd_addr || + data->dump_info.smem_addr_end > U32_MAX - 0x04) { + bt_dev_err(hdev, + "Invalid smem region: start=0x%08x end=0x%08x", + smem_rd_addr, data->dump_info.smem_addr_end); + } else { + smem_rd_size = (data->dump_info.smem_addr_end + 0x04) - + smem_rd_addr; - buf_idx = BTINTEL_PCIE_DBGC_DBG_BUF_IDX(wr_ptr_status); - if (buf_idx > dbgc->count) { - bt_dev_warn(hdev, "Buffer index is invalid"); - return -EINVAL; + bt_dev_dbg(hdev, + "smem_region: smem_start_addr=0x%08x smem_end_addr=0x%08x smem_rd_size=%u", + smem_rd_addr, data->dump_info.smem_addr_end, + smem_rd_size); + + if (smem_rd_size == 0 || + smem_rd_size > BTINTEL_PCIE_SMEM_MAX_SIZE) { + bt_dev_err(hdev, + "Invalid smem region: smem_rd_addr 0x%08x size %u (max %u)", + smem_rd_addr, smem_rd_size, + BTINTEL_PCIE_SMEM_MAX_SIZE); + smem_rd_size = 0; + } } - prev_size = buf_idx * BTINTEL_PCIE_DBGC_BUFFER_SIZE; - if (prev_size + offset >= prev_size) - data->dmp_hdr.write_ptr = prev_size + offset; - else - return -EINVAL; + if (btintel_pcie_is_mdbgc_supported(data)) { + ret = btintel_pcie_dump_dram_monitor(data, &dump_list, count, + mdbgc->buf1, status_reg, + wrap_reg, + BTINTEL_PCIE_MDBGC_ALLOCATIONID_1, + BTINTEL_PCIE_INI_ID_DRAM_MONITOR1, + "monitor"); + if (!ret) + regions_mask |= + BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR1); + else + bt_dev_warn(hdev, "Failed to dump DRAM buf1: %d", ret); - strscpy(vendor, "Vendor: Intel\n"); - snprintf(driver, sizeof(driver), "Driver: %s\n", - data->dmp_hdr.driver_name); + ret = btintel_pcie_dump_dram_monitor(data, &dump_list, count, + mdbgc->buf2, status_reg, + wrap_reg, + BTINTEL_PCIE_MDBGC_ALLOCATIONID_2, + BTINTEL_PCIE_INI_ID_DRAM_MONITOR2, + "monitor2"); + if (!ret) + regions_mask |= + BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR2); + else + bt_dev_warn(hdev, "Failed to dump DRAM buf2: %d", ret); - ktime_get_real_ts64(&now); - time64_to_tm(now.tv_sec, 0, &tm_now); - snprintf(ts, sizeof(ts), "Dump Time: %02d-%02d-%04ld %02d:%02d:%02d", - tm_now.tm_mday, tm_now.tm_mon + 1, tm_now.tm_year + 1900, - tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec); - - snprintf(fw_build, sizeof(fw_build), - "Firmware Timestamp: Year %u WW %02u buildtype %u build %u", - 2000 + (data->dmp_hdr.fw_timestamp >> 8), - data->dmp_hdr.fw_timestamp & 0xff, data->dmp_hdr.fw_build_type, - data->dmp_hdr.fw_build_num); - - data_len = sizeof(*tlv) + sizeof(data->dmp_hdr.cnvi_bt) + - sizeof(*tlv) + sizeof(data->dmp_hdr.write_ptr) + - sizeof(*tlv) + sizeof(data->dmp_hdr.wrap_ctr) + - sizeof(*tlv) + sizeof(data->dmp_hdr.trigger_reason) + - sizeof(*tlv) + sizeof(data->dmp_hdr.fw_sha) + - sizeof(*tlv) + sizeof(data->dmp_hdr.cnvr_top) + - sizeof(*tlv) + sizeof(data->dmp_hdr.cnvi_top) + - sizeof(*tlv) + strlen(ts) + - sizeof(*tlv) + strlen(fw_build) + - sizeof(*tlv) + strlen(vendor) + - sizeof(*tlv) + strlen(driver); - - if (data->dmp_hdr.event_type && data->dmp_hdr.event_id) { - data_len += sizeof(*tlv) + sizeof(data->dmp_hdr.event_type); - data_len += sizeof(*tlv) + sizeof(data->dmp_hdr.event_id); + ret = btintel_pcie_dump_dram_monitor(data, &dump_list, count, + mdbgc->buf3, status_reg, + wrap_reg, + BTINTEL_PCIE_MDBGC_ALLOCATIONID_3, + BTINTEL_PCIE_INI_ID_DRAM_MONITOR3, + "monitor3"); + if (!ret) + regions_mask |= + BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR3); + else + bt_dev_warn(hdev, "Failed to dump DRAM buf3: %d", ret); + } else { + ret = btintel_pcie_dump_dram_monitor(data, &dump_list, count, + dbgc->bufs, status_reg, + wrap_reg, + BTINTEL_PCIE_MDBGC_ALLOCATIONID_1, + BTINTEL_PCIE_INI_ID_DRAM_MONITOR1, + "monitor"); + if (!ret) + regions_mask |= + BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR1); + else + bt_dev_warn(hdev, + "Failed to dump DRAM region: %d", ret); } - /* - * sizeof(u32) - signature - * sizeof(data_len) - to store tlv data size - * data_len - TLV data - */ - dump_size = sizeof(u32) + sizeof(data_len) + data_len; + if (smem_rd_size && + !btintel_pcie_dump_smem_monitor_region(data, &dump_list, + BTINTEL_PCIE_INI_ID_SMEM, + "monitor_smem", + smem_rd_addr, + smem_rd_size)) + regions_mask |= BIT_ULL(BTINTEL_PCIE_INI_ID_SMEM); + exc_addr = data->dump_info.exception_dump_addr; + exception_dump_len = data->dump_info.exception_dump_len; + if (exc_addr && exception_dump_len) { + ret = btintel_pcie_dump_target_region(data, &dump_list, + BTINTEL_PCIE_INI_ID_EXCEPTION_EVT, + "EXCEPTION_EVT_BUFFER", exc_addr, + exception_dump_len); + if (!ret) + regions_mask |= BIT_ULL(BTINTEL_PCIE_INI_ID_EXCEPTION_EVT); + } - /* Add debug buffers data length to dump size */ - dump_size += BTINTEL_PCIE_DBGC_BUFFER_SIZE * dbgc->count; + btintel_pcie_dump_mem_range(data, &dump_list, + BTINTEL_PCIE_INI_ID_DCCM, "DCCM", + data->dump_info.dccm_addr_start, + data->dump_info.dccm_addr_end, + ®ions_mask); - pdata = vmalloc(dump_size); - if (!pdata) + btintel_pcie_dump_mem_range(data, &dump_list, + BTINTEL_PCIE_INI_ID_SDS, "SDS", + data->dump_info.sds_start_addr_start, + data->dump_info.sds_start_addr_end, + ®ions_mask); + + btintel_pcie_dump_mem_range(data, &dump_list, + BTINTEL_PCIE_INI_ID_SDS_IOSF, "SDS_IOSF", + data->dump_info.sds_iosf_data_addr_start, + data->dump_info.sds_iosf_data_addr_end, + ®ions_mask); + + btintel_pcie_dump_mem_range(data, &dump_list, + BTINTEL_PCIE_INI_ID_ECL, "ECL_REGION", + data->dump_info.ecl_addr_start, + data->dump_info.ecl_addr_end, + ®ions_mask); + + ret = btintel_pcie_dump_info(data, &dump_list, regions_mask); + if (ret) { + btintel_pcie_dump_list_free(&dump_list); + return ret; + } + + file_len = sizeof(*file_hdr) + + btintel_pcie_dump_list_total_size(&dump_list); + entry = btintel_pcie_dump_entry_alloc(sizeof(*file_hdr)); + if (!entry) { + btintel_pcie_dump_list_free(&dump_list); return -ENOMEM; - p = pdata; - - *(u32 *)p = BTINTEL_PCIE_MAGIC_NUM; - p += sizeof(u32); - - *(u32 *)p = data_len; - p += sizeof(u32); - - - p = btintel_pcie_copy_tlv(p, BTINTEL_VENDOR, vendor, strlen(vendor)); - p = btintel_pcie_copy_tlv(p, BTINTEL_DRIVER, driver, strlen(driver)); - p = btintel_pcie_copy_tlv(p, BTINTEL_DUMP_TIME, ts, strlen(ts)); - p = btintel_pcie_copy_tlv(p, BTINTEL_FW_BUILD, fw_build, - strlen(fw_build)); - p = btintel_pcie_copy_tlv(p, BTINTEL_CNVI_BT, &data->dmp_hdr.cnvi_bt, - sizeof(data->dmp_hdr.cnvi_bt)); - p = btintel_pcie_copy_tlv(p, BTINTEL_WRITE_PTR, &data->dmp_hdr.write_ptr, - sizeof(data->dmp_hdr.write_ptr)); - p = btintel_pcie_copy_tlv(p, BTINTEL_WRAP_CTR, &data->dmp_hdr.wrap_ctr, - sizeof(data->dmp_hdr.wrap_ctr)); - p = btintel_pcie_copy_tlv(p, BTINTEL_TRIGGER_REASON, &data->dmp_hdr.trigger_reason, - sizeof(data->dmp_hdr.trigger_reason)); - p = btintel_pcie_copy_tlv(p, BTINTEL_FW_SHA, &data->dmp_hdr.fw_sha, - sizeof(data->dmp_hdr.fw_sha)); - p = btintel_pcie_copy_tlv(p, BTINTEL_CNVR_TOP, &data->dmp_hdr.cnvr_top, - sizeof(data->dmp_hdr.cnvr_top)); - p = btintel_pcie_copy_tlv(p, BTINTEL_CNVI_TOP, &data->dmp_hdr.cnvi_top, - sizeof(data->dmp_hdr.cnvi_top)); - - if (data->dmp_hdr.event_type && data->dmp_hdr.event_id) { - p = btintel_pcie_copy_tlv(p, BTINTEL_EVENT_TYPE, - &data->dmp_hdr.event_type, - sizeof(data->dmp_hdr.event_type)); - p = btintel_pcie_copy_tlv(p, BTINTEL_EVENT_ID, - &data->dmp_hdr.event_id, - sizeof(data->dmp_hdr.event_id)); - data->dmp_hdr.event_type = 0; - data->dmp_hdr.event_id = 0; } - memcpy(p, dbgc->bufs[0].data, dbgc->count * BTINTEL_PCIE_DBGC_BUFFER_SIZE); - dev_coredumpv(&hdev->dev, pdata, dump_size, GFP_KERNEL); - return 0; + file_hdr = (void *)entry->data; + file_hdr->barker = cpu_to_le32(BTINTEL_PCIE_INI_ERROR_DUMP_BARKER); + file_hdr->file_len = cpu_to_le32(file_len); + list_add(&entry->list, &dump_list); + + sg_dump_data = btintel_pcie_alloc_sgtable(file_len); + if (sg_dump_data) { + int sg_entries = sg_nents(sg_dump_data); + u32 offs = 0; + + list_for_each_entry(entry, &dump_list, list) { + sg_pcopy_from_buffer(sg_dump_data, sg_entries, + entry->data, entry->size, offs); + offs += entry->size; + } + + bt_dev_dbg(hdev, "triggering dev_coredumpsg()"); + dev_coredumpsg(&hdev->dev, sg_dump_data, file_len, GFP_KERNEL); + } else { + bt_dev_err(hdev, "Failed to allocate scatter-gather table for coredump"); + ret = -ENOMEM; + } + + btintel_pcie_dump_list_free(&dump_list); + return ret; } static void btintel_pcie_dump_traces(struct hci_dev *hdev) { struct btintel_pcie_data *data = hci_get_drvdata(hdev); - int ret = 0; + int ret; ret = btintel_pcie_get_mac_access(data); if (ret) { @@ -929,7 +1451,7 @@ static void btintel_pcie_dump_traces(struct hci_dev *hdev) return; } - ret = btintel_pcie_read_dram_buffers(data); + ret = btintel_pcie_read_debug_regions(data); btintel_pcie_release_mac_access(data); @@ -1174,19 +1696,19 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) ptr = buffer; remaining = buffer_len; - /* Parse TLV structures: type(1) + length(2) + value */ + /* Parse TLV structures: 1 byte type + 2 bytes length + + * variable value + */ while (remaining >= sizeof(struct mbox_tlv)) { u16 tlv_len; u32 tlv_total; tlv = (struct mbox_tlv *)ptr; tlv_len = le16_to_cpu(tlv->len); - tlv_total = sizeof(tlv->type) + - sizeof(tlv->len) + tlv_len; + tlv_total = sizeof(tlv->type) + sizeof(tlv->len) + tlv_len; if (tlv_total > remaining) { - bt_dev_err(data->hdev, - "TLV parse error: type=%u, len=%u", + bt_dev_err(data->hdev, "TLV parse error: not enough data for TLV value (type=%u, len=%u)", tlv->type, tlv_len); break; } @@ -1195,7 +1717,7 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) case BTINTEL_PCIE_TLV_TYPE_EXCEPTION_DUMP_ADDRESS: if (tlv_len < 8) { bt_dev_err(data->hdev, - "TLV %s too short: %u", + "TLV %s too short: len=%u (need 8)", btintel_pcie_tlv_str(tlv->type), tlv_len); break; @@ -1208,7 +1730,7 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) case BTINTEL_PCIE_TLV_TYPE_DCCM_MEM_ADDRESS: if (tlv_len < 8) { bt_dev_err(data->hdev, - "TLV %s too short: %u", + "TLV %s too short: len=%u (need 8)", btintel_pcie_tlv_str(tlv->type), tlv_len); break; @@ -1227,8 +1749,7 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) bt_dev_dbg(data->hdev, "SDS TLV: skipped, hw_variant not yet known"); break; } - if (tlv_len == 16 && - hw_variant > BTINTEL_HWID_BZRI) { + if (tlv_len == 16 && hw_variant > BTINTEL_HWID_BZRI) { data->dump_info.sds_start_addr_start = get_unaligned_le32(&tlv->val[0]); data->dump_info.sds_start_addr_end = @@ -1261,7 +1782,7 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) case BTINTEL_PCIE_TLV_TYPE_ECL_MEM_ADDRESS: if (tlv_len < 8) { bt_dev_err(data->hdev, - "TLV %s too short: %u", + "TLV %s too short: len=%u (need 8)", btintel_pcie_tlv_str(tlv->type), tlv_len); break; @@ -1274,7 +1795,7 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) case BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS: if (tlv_len < 8) { bt_dev_err(data->hdev, - "TLV %s too short: %u", + "TLV %s too short: len=%u (need 8)", btintel_pcie_tlv_str(tlv->type), tlv_len); break; @@ -1285,8 +1806,7 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) get_unaligned_le32(&tlv->val[4]); break; default: - bt_dev_dbg(data->hdev, - "Unknown TLV type: %u length: %u", + bt_dev_dbg(data->hdev, "Unknown TLV type: %u length: %u", tlv->type, tlv_len); break; } @@ -1879,11 +2399,8 @@ static int btintel_pcie_dump_fwtrigger_event(struct btintel_pcie_data *data) goto exit_on_error; evt = (void *)buf; - data->dmp_hdr.event_type = evt->event_type; - data->dmp_hdr.event_id = le16_to_cpu(evt->event_id); - bt_dev_dbg(data->hdev, "event type: 0x%2.2x event id: 0x%4.4x len: %u", - data->dmp_hdr.event_type, data->dmp_hdr.event_id, len); + evt->event_type, le16_to_cpu(evt->event_id), len); skb = bt_skb_alloc(len, GFP_KERNEL); if (!skb) { @@ -1909,8 +2426,8 @@ exit_on_error: * * Always queue this AFTER any companion event-reader work (hwexp / * fwtrigger) so that, on the ordered @dump_workqueue, the event reader - * runs first and populates dmp_hdr.event_type / event_id before - * dump_traces consumes them. + * runs first and the trigger metadata is populated before dump_traces + * consumes it. */ static bool btintel_pcie_queue_coredump(struct btintel_pcie_data *data, u16 trigger_reason) @@ -1993,12 +2510,6 @@ static void btintel_pcie_coredump_worker(struct work_struct *work) goto out; } - if (btintel_pcie_is_mdbgc_supported(data)) { - bt_dev_info(data->hdev, - "Skipping coredump: MDBGC dump format not supported yet"); - goto out; - } - btintel_pcie_dump_traces(data->hdev); out: /* Release guard last so a new trigger can run only after this diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 5c35e65d3e81..9d84db48a8e5 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -74,11 +74,16 @@ #define BTINTEL_PCIE_DBGC_BASE_ADDR_SCP (0xf0d5d500) #define BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x1C) #define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x2C) +#define BTINTEL_PCIE_DBGC_ALLOCATION_OFFSET 0x100 +#define BTINTEL_PCIE_SMEM_MAX_SIZE (16 * 1024) +#define BTINTEL_PCIE_REGION_MAX_SIZE (16 * 1024 * 1024) #define BTINTEL_PCIE_DBG_IDX_BIT_MASK 0x0F #define BTINTEL_PCIE_DBGC_DBG_BUF_IDX(data) (((data) >> 24) & BTINTEL_PCIE_DBG_IDX_BIT_MASK) #define BTINTEL_PCIE_DBG_OFFSET_BIT_MASK 0xFFFFFF +#define BTINTEL_PCIE_TARGET_ACCESS_FRAG_OFFSET 4 + /* The DRAM buffer count, each buffer size, and * fragment buffer size */ @@ -242,7 +247,7 @@ enum { #define BTINTEL_PCIE_TLV_TYPE_DCCM_MEM_ADDRESS 0x05 #define BTINTEL_PCIE_TLV_TYPE_SDS_MEM_ADDRESS 0x06 #define BTINTEL_PCIE_TLV_TYPE_ECL_MEM_ADDRESS 0x07 -#define BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS 0x08 +#define BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS 0x08 /* * Struct for Context Information (v2) @@ -527,10 +532,147 @@ struct btintel_pcie_dump_header { u32 wrap_ctr; u16 trigger_reason; int state; - u8 event_type; - u16 event_id; }; +/* Per-fragment range descriptor for dump regions. + * Binary-compatible with iwl_fw_ini_error_dump_range. + */ +struct btintel_pcie_dump_range { + __le32 range_data_size; + union { + __le32 internal_base_addr; + __le64 dram_base_addr; + __le32 page_num; + }; + __le32 data[]; +} __packed; + +/* + * INI region types for ini_dump_data.type field. + * The unified decoder dispatches parsing logic based on these values. + */ +#define BTINTEL_PCIE_INI_REGION_INTERNAL_BUFFER 2 +#define BTINTEL_PCIE_INI_REGION_DRAM_BUFFER 3 +#define BTINTEL_PCIE_INI_REGION_DEVICE_MEMORY 9 + +/* INI region IDs - used in dump header region_id field and regions_mask */ +#define BTINTEL_PCIE_INI_ID_EXCEPTION_EVT 7 +#define BTINTEL_PCIE_INI_ID_SMEM 15 +#define BTINTEL_PCIE_INI_ID_DCCM 39 +#define BTINTEL_PCIE_INI_ID_SDS 40 +#define BTINTEL_PCIE_INI_ID_SDS_IOSF 41 +#define BTINTEL_PCIE_INI_ID_ECL 42 +#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR3 61 +#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR2 62 +#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR1 63 + +/* + * INI (Intel INI debug infrastructure) style dump data TLV - wraps each dump + * region. INI is the iwlwifi firmware debug format used by the unified decoder. + * Compatible with iwl_fw_ini_error_dump_data. + */ +struct btintel_pcie_ini_dump_data { + u8 type; + u8 sub_type; + u8 sub_type_ver; + u8 reserved; + __le32 len; + u8 data[]; +} __packed; + +/* + * INI-style region dump header. + * Compatible with iwl_fw_ini_error_dump_header. + */ +#define BTINTEL_PCIE_INI_MAX_NAME 32 +#define BTINTEL_PCIE_INI_DUMP_VER 1 + +struct btintel_pcie_ini_dump_header { + __le32 version; + __le32 region_id; + __le32 num_of_ranges; + __le32 name_len; + u8 name[BTINTEL_PCIE_INI_MAX_NAME]; +}; + +/* + * INI-style monitor dump - region header + monitor state. + * Compatible with iwl_fw_ini_monitor_dump. + */ +struct btintel_pcie_ini_monitor_dump { + struct btintel_pcie_ini_dump_header header; + __le32 write_ptr; + __le32 cycle_cnt; + __le32 cur_frag; + u8 data[]; +} __packed; + +/* Linked list entry for modular dump collection */ +struct btintel_pcie_dump_entry { + struct list_head list; + u32 size; + u8 data[]; +}; + +/* File-level header for coredump output. + * Compatible with iwl_fw_ini_dump_file_hdr. + * Uses IWL_FW_INI_ERROR_DUMP_BARKER (0x14789633) for decoder compatibility. + */ +#define BTINTEL_PCIE_INI_ERROR_DUMP_BARKER 0x14789633 + +struct btintel_pcie_dump_file_hdr { + __le32 barker; + __le32 file_len; +} __packed; + +/* + * Legacy-style dump data wrapper for dump info TLV. + * Compatible with iwl_fw_error_dump_data. + * Used only for the dump info entry (type=BTINTEL_PCIE_INI_DUMP_INFO_TYPE). + */ +struct btintel_pcie_error_dump_data { + __le32 type; + __le32 len; + u8 data[]; +} __packed; + +/* Use bit 31 as dump info type, matching IWL_INI_DUMP_INFO_TYPE */ +#define BTINTEL_PCIE_INI_DUMP_INFO_TYPE BIT(31) + +/* Time point values matching iwl_fw_ini_time_point for fwdump parser */ +#define BTINTEL_PCIE_TIME_POINT_FW_ASSERT 4 +#define BTINTEL_PCIE_TIME_POINT_USER_TRIGGER 9 + +/* + * Dump info struct - single TLV containing all metadata. + * Compatible with iwl_fw_ini_dump_info. + * Packs all device/firmware info that the decoder needs. + */ +struct btintel_pcie_ini_dump_info { + __le32 version; + __le32 time_point; + __le32 trigger_reason; + __le32 external_cfg_state; + __le32 ver_type; + __le32 ver_subtype; + __le32 hw_step; + __le32 hw_type; + __le32 rf_id_flavor; + __le32 rf_id_dash; + __le32 rf_id_step; + __le32 rf_id_type; + __le32 lmac_major; + __le32 lmac_minor; + __le32 umac_major; + __le32 umac_minor; + __le32 fw_mon_mode; + __le64 regions_mask; + __le32 build_tag_len; + u8 build_tag[64]; + __le32 num_of_cfg_names; + /* no cfg_names for BT - keep zero-length */ +} __packed; + /* struct btintel_pcie_data * @pdev: pci device * @hdev: hdev device @@ -688,4 +830,3 @@ static inline u32 btintel_pcie_rd_dev_mem(struct btintel_pcie_data *data, btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_ADDR_REG, addr); return btintel_pcie_rd_reg32(data, BTINTEL_PCIE_PRPH_DEV_RD_REG); } - From 1430308fc9d47a801a305700cd444b1a0051d14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolaj=20Klitlund=20B=C3=B8rty?= Date: Sat, 5 Sep 2026 14:05:12 +0200 Subject: [PATCH 1679/2126] Bluetooth: btusb: Add device ID for Realtek RTL8761BUE (StarTech AV53C1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the USB ID 0x14b0:0x047a for the StarTech AV53C1-USB-BLUETOOTH adapter, a Realtek RTL8761BUE based Bluetooth 5.3 dongle. Without this entry btusb treats the device as a generic Bluetooth adapter and never loads the Realtek firmware, leaving the controller on its ROM firmware. In that state it advertises and scans actively, but never reports advertisements during passive scanning. LE connections initiated by the kernel wait for a passive-scan report before issuing LE Create Connection, so connecting and pairing from BlueZ time out without any error from the controller. The same product is also sold with the ID 0x2c0a:0x8761, which is already supported. lsusb -v output for the device: Bus 001 Device 010: ID 14b0:047a StarTech.com Ltd. Bluetooth Radio Device Descriptor: bcdUSB 1.10 bDeviceClass 224 Wireless bDeviceSubClass 1 Radio Frequency bDeviceProtocol 1 Bluetooth idVendor 0x14b0 StarTech.com Ltd. idProduct 0x047a bcdDevice 2.00 iManufacturer 1 Realtek iProduct 2 Bluetooth Radio iSerial 3 00E04C239987 bNumInterfaces 2 Interface Descriptor: bInterfaceClass 224 Wireless bInterfaceSubClass 1 Radio Frequency bInterfaceProtocol 1 Bluetooth Cc: stable@vger.kernel.org Signed-off-by: Nikolaj Klitlund Børty Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 2c69a81c9631..a7488f6e8d8a 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -884,6 +884,8 @@ static const struct usb_device_id quirks_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x37ad, 0x0600), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, + { USB_DEVICE(0x14b0, 0x047a), .driver_info = BTUSB_REALTEK | + BTUSB_WIDEBAND_SPEECH }, /* Additional Realtek 8761CU Bluetooth devices */ { USB_DEVICE(0x0b05, 0x1bef), .driver_info = BTUSB_REALTEK | From 266e44d71b41b980ce00b7eda91c6f8c75b1fb15 Mon Sep 17 00:00:00 2001 From: Xuhua Zhang Date: Mon, 7 Sep 2026 23:10:15 +0800 Subject: [PATCH 1680/2126] Bluetooth: hci_bcsp: Use the shared CRC-CCITT byte helper bcsp_crc_update() processes each byte as two nibbles, requiring two dependent table lookups for every header and payload byte when CRC is enabled. The existing crc_ccitt_byte() helper implements the same reflected polynomial with one lookup per byte. Use it instead of the private nibble-based implementation and select CRC_CCITT for BCSP-only UART configurations as well. The initial CRC value and final bit reversal remain unchanged. This replaces the private 16-entry table with the shared 256-entry table, trading table size for fewer dependent lookups. An exhaustive comparison of all 65536 CRC states and 256 input bytes matches both the old code and a bitwise reference implementation. Signed-off-by: Xuhua Zhang Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/Kconfig | 1 + drivers/bluetooth/hci_bcsp.c | 26 +++----------------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 4e8c24d757e9..2d6a3117e387 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -151,6 +151,7 @@ config BT_HCIUART_BCSP bool "BCSP protocol support" depends on BT_HCIUART select BITREVERSE + select CRC_CCITT help BCSP (BlueCore Serial Protocol) is serial protocol for communication between Bluetooth device and host. This protocol is required for non diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c index 0323db21c428..ef71a349e777 100644 --- a/drivers/bluetooth/hci_bcsp.c +++ b/drivers/bluetooth/hci_bcsp.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -75,34 +76,13 @@ struct bcsp_struct { /* ---- BCSP CRC calculation ---- */ -/* Table for calculating CRC for polynomial 0x1021, LSB processed first, - * initial value 0xffff, bits shifted in reverse order. - */ - -static const u16 crc_table[] = { - 0x0000, 0x1081, 0x2102, 0x3183, - 0x4204, 0x5285, 0x6306, 0x7387, - 0x8408, 0x9489, 0xa50a, 0xb58b, - 0xc60c, 0xd68d, 0xe70e, 0xf78f -}; - /* Initialise the crc calculator */ #define BCSP_CRC_INIT(x) x = 0xffff -/* Update crc with next data byte - * - * Implementation note - * The data byte is treated as two nibbles. The crc is generated - * in reverse, i.e., bits are fed into the register from the top. - */ +/* Update crc with next data byte */ static void bcsp_crc_update(u16 *crc, u8 d) { - u16 reg = *crc; - - reg = (reg >> 4) ^ crc_table[(reg ^ d) & 0x000f]; - reg = (reg >> 4) ^ crc_table[(reg ^ (d >> 4)) & 0x000f]; - - *crc = reg; + *crc = crc_ccitt_byte(*crc, d); } /* ---- BCSP core ---- */ From c84f9fc657986a65f64124a986a5d3a177c44f0c Mon Sep 17 00:00:00 2001 From: Xuhua Zhang Date: Mon, 7 Sep 2026 23:08:08 +0800 Subject: [PATCH 1681/2126] Bluetooth: hci_h5: Avoid clearing the escape bit for ordinary bytes h5_unslip_one_byte() calls test_and_clear_bit() for every byte other than an initial SLIP escape byte, even when H5_RX_ESC is already clear. This performs an unnecessary atomic read-modify-write on the ordinary-byte receive path. On x86, it emits a locked btr instruction for each such byte. Test H5_RX_ESC first and clear it only when consuming an escaped byte. Handle an initial SLIP escape byte in the alternative branch. The HCI UART receive callbacks are serialized by the TTY layer, and H5_RX_ESC is only changed by receive processing and initialization, so there is no need to atomically test and clear it in one operation. Keep set_bit() and clear_bit() atomic because other bits in h5->flags can be updated by the transmit path concurrently. Escape decoding and invalid-escape recovery remain unchanged. Signed-off-by: Xuhua Zhang Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_h5.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c index b1999e14aade..37f4d9327e72 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -543,12 +543,8 @@ static void h5_unslip_one_byte(struct h5 *h5, unsigned char c) const u8 delim = SLIP_DELIMITER, esc = SLIP_ESC; const u8 *byte = &c; - if (!test_bit(H5_RX_ESC, &h5->flags) && c == SLIP_ESC) { - set_bit(H5_RX_ESC, &h5->flags); - return; - } - - if (test_and_clear_bit(H5_RX_ESC, &h5->flags)) { + if (test_bit(H5_RX_ESC, &h5->flags)) { + clear_bit(H5_RX_ESC, &h5->flags); switch (c) { case SLIP_ESC_DELIM: byte = &delim; @@ -561,6 +557,9 @@ static void h5_unslip_one_byte(struct h5 *h5, unsigned char c) h5_reset_rx(h5); return; } + } else if (c == SLIP_ESC) { + set_bit(H5_RX_ESC, &h5->flags); + return; } skb_put_data(h5->rx_skb, byte, 1); From 09cf09f752ddd2fecad2aff0d053d90872d55adb Mon Sep 17 00:00:00 2001 From: Xuhua Zhang Date: Mon, 7 Sep 2026 23:12:45 +0800 Subject: [PATCH 1682/2126] Bluetooth: hci_ll: Sleep while waiting for the controller to power up ll_setup() busy-waits for 100 ms after asserting the controller enable GPIO on each firmware download attempt. With retries this can occupy the CPU for up to 400 ms. The setup callback runs in sleepable context and already uses msleep(), gpiod_set_value_cansleep() and synchronous firmware commands. Replace mdelay(100) with msleep(100) so the CPU can run other work during the power-up delay. Keep the requested delay and subsequent CTS wait. Signed-off-by: Xuhua Zhang Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_ll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c index ab744001dafc..35adf869cc1f 100644 --- a/drivers/bluetooth/hci_ll.c +++ b/drivers/bluetooth/hci_ll.c @@ -629,7 +629,7 @@ static int ll_setup(struct hci_uart *hu) gpiod_set_value_cansleep(lldev->enable_gpio, 0); msleep(5); gpiod_set_value_cansleep(lldev->enable_gpio, 1); - mdelay(100); + msleep(100); err = serdev_device_wait_for_cts(serdev, true, 200); if (err) { bt_dev_err(hu->hdev, "Failed to get CTS"); From 479b0776f7802dca9e036d8944ad29d02dc695c0 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 8 Sep 2026 19:04:21 +0530 Subject: [PATCH 1683/2126] Bluetooth: btintel_pcie: cap device debug regions at 1 MB Validate device-supplied debug-region boundaries during mailbox TLV parsing and convert start/end values to a validated region size. Cap debug-region sizes to 1 MB to prevent out-of-bounds reads if firmware reports oversized memory ranges. Skip invalid or oversized regions prior to coredump capture. This issue was reported by Claude Mythos. Fixes: 9ea41cd5a639 ("Bluetooth: btintel_pcie: unified decoder coredump format") Assisted-by: Copilot:claude-opus-4.7 Signed-off-by: Kiran K Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 229 ++++++++++++++++--------------- drivers/bluetooth/btintel_pcie.h | 16 +-- 2 files changed, 128 insertions(+), 117 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 42800361c49f..10706fd2376a 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -966,13 +966,6 @@ static int btintel_pcie_dump_target_region(struct btintel_pcie_data *data, return 1; } - if (size > BTINTEL_PCIE_REGION_MAX_SIZE) { - bt_dev_warn(data->hdev, - "Skipping dump region %s: size %u exceeds max %u", - name, size, BTINTEL_PCIE_REGION_MAX_SIZE); - return 1; - } - if (addr_start > U32_MAX - size) { bt_dev_warn(data->hdev, "Skipping dump region %s: addr_start 0x%08x + size %u would overflow", @@ -1202,29 +1195,11 @@ static bool btintel_pcie_is_mdbgc_supported(struct btintel_pcie_data *data) static void btintel_pcie_dump_mem_range(struct btintel_pcie_data *data, struct list_head *list, u32 region_id, const char *name, u32 addr_start, - u32 addr_end, u64 *regions_mask) + u32 region_size, u64 *regions_mask) { - u32 region_size; - - if (!addr_start || !addr_end || addr_end < addr_start) + if (!region_size) return; - if (addr_end > U32_MAX - 0x04) { - bt_dev_warn(data->hdev, - "Skipping dump region %s: addr_end 0x%08x would overflow", - name, addr_end); - return; - } - - region_size = (addr_end + 0x04) - addr_start; - if (region_size > BTINTEL_PCIE_REGION_MAX_SIZE) { - bt_dev_warn(data->hdev, - "Skipping dump region %s: size %u exceeds max %u", - name, region_size, - BTINTEL_PCIE_REGION_MAX_SIZE); - return; - } - if (!btintel_pcie_dump_target_region(data, list, region_id, name, addr_start, region_size)) *regions_mask |= BIT_ULL(region_id); @@ -1234,16 +1209,14 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data) { struct btintel_pcie_dbgc *dbgc = NULL; struct btintel_pcie_mdbgc *mdbgc = NULL; + struct btintel_pcie_dump_mem_info *dump_info = &data->dump_info; struct hci_dev *hdev = data->hdev; struct btintel_pcie_dump_entry *entry; struct btintel_pcie_dump_file_hdr *file_hdr; struct scatterlist *sg_dump_data; u32 status_reg, wrap_reg; - u32 exception_dump_len; - u32 exc_addr; u64 regions_mask = 0; u8 hw_variant; - u32 smem_rd_addr = 0, smem_rd_size = 0; u32 file_len; u8 count; int ret; @@ -1276,35 +1249,6 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data) return -EINVAL; } - smem_rd_addr = data->dump_info.smem_addr_start; - smem_rd_size = 0; - - if (!smem_rd_addr && !data->dump_info.smem_addr_end) { - bt_dev_dbg(hdev, "smem region not advertised by firmware"); - } else if (data->dump_info.smem_addr_end < smem_rd_addr || - data->dump_info.smem_addr_end > U32_MAX - 0x04) { - bt_dev_err(hdev, - "Invalid smem region: start=0x%08x end=0x%08x", - smem_rd_addr, data->dump_info.smem_addr_end); - } else { - smem_rd_size = (data->dump_info.smem_addr_end + 0x04) - - smem_rd_addr; - - bt_dev_dbg(hdev, - "smem_region: smem_start_addr=0x%08x smem_end_addr=0x%08x smem_rd_size=%u", - smem_rd_addr, data->dump_info.smem_addr_end, - smem_rd_size); - - if (smem_rd_size == 0 || - smem_rd_size > BTINTEL_PCIE_SMEM_MAX_SIZE) { - bt_dev_err(hdev, - "Invalid smem region: smem_rd_addr 0x%08x size %u (max %u)", - smem_rd_addr, smem_rd_size, - BTINTEL_PCIE_SMEM_MAX_SIZE); - smem_rd_size = 0; - } - } - if (btintel_pcie_is_mdbgc_supported(data)) { ret = btintel_pcie_dump_dram_monitor(data, &dump_list, count, mdbgc->buf1, status_reg, @@ -1356,47 +1300,46 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data) "Failed to dump DRAM region: %d", ret); } - if (smem_rd_size && + if (dump_info->smem_size && !btintel_pcie_dump_smem_monitor_region(data, &dump_list, BTINTEL_PCIE_INI_ID_SMEM, "monitor_smem", - smem_rd_addr, - smem_rd_size)) + dump_info->smem_addr_start, + dump_info->smem_size)) regions_mask |= BIT_ULL(BTINTEL_PCIE_INI_ID_SMEM); - exc_addr = data->dump_info.exception_dump_addr; - exception_dump_len = data->dump_info.exception_dump_len; - if (exc_addr && exception_dump_len) { + if (dump_info->exception_dump_addr && dump_info->exception_dump_len) { ret = btintel_pcie_dump_target_region(data, &dump_list, BTINTEL_PCIE_INI_ID_EXCEPTION_EVT, - "EXCEPTION_EVT_BUFFER", exc_addr, - exception_dump_len); + "EXCEPTION_EVT_BUFFER", + dump_info->exception_dump_addr, + dump_info->exception_dump_len); if (!ret) regions_mask |= BIT_ULL(BTINTEL_PCIE_INI_ID_EXCEPTION_EVT); } btintel_pcie_dump_mem_range(data, &dump_list, BTINTEL_PCIE_INI_ID_DCCM, "DCCM", - data->dump_info.dccm_addr_start, - data->dump_info.dccm_addr_end, + dump_info->dccm_addr_start, + dump_info->dccm_size, ®ions_mask); btintel_pcie_dump_mem_range(data, &dump_list, BTINTEL_PCIE_INI_ID_SDS, "SDS", - data->dump_info.sds_start_addr_start, - data->dump_info.sds_start_addr_end, + dump_info->sds_start_addr_start, + dump_info->sds_start_size, ®ions_mask); btintel_pcie_dump_mem_range(data, &dump_list, BTINTEL_PCIE_INI_ID_SDS_IOSF, "SDS_IOSF", - data->dump_info.sds_iosf_data_addr_start, - data->dump_info.sds_iosf_data_addr_end, + dump_info->sds_iosf_data_addr_start, + dump_info->sds_iosf_data_size, ®ions_mask); btintel_pcie_dump_mem_range(data, &dump_list, BTINTEL_PCIE_INI_ID_ECL, "ECL_REGION", - data->dump_info.ecl_addr_start, - data->dump_info.ecl_addr_end, + dump_info->ecl_addr_start, + dump_info->ecl_size, ®ions_mask); ret = btintel_pcie_dump_info(data, &dump_list, regions_mask); @@ -1599,6 +1542,34 @@ static inline bool btintel_pcie_in_error(struct btintel_pcie_data *data) return data->boot_stage_cache & BTINTEL_PCIE_CSR_BOOT_STAGE_ABORT_HANDLER; } +static u32 btintel_pcie_region_size(struct hci_dev *hdev, const char *name, + u32 start, u32 end) +{ + u64 size; + + if (!start || !end) + return 0; + + if (end < start) { + bt_dev_warn(hdev, "%s region invalid: start=0x%08x end=0x%08x", + name, start, end); + return 0; + } + + size = (u64)end + 0x04 - start; + if (size % sizeof(u32)) + bt_dev_warn(hdev, "%s region size %llu is not 4-byte aligned", + name, size); + + if (size > BTINTEL_PCIE_REGION_MAX_SIZE) { + bt_dev_warn(hdev, "%s region size %llu exceeds cap %u, ignoring", + name, size, BTINTEL_PCIE_REGION_MAX_SIZE); + return 0; + } + + return (u32)size; +} + static const char *btintel_pcie_tlv_str(u8 tlv_type) { switch (tlv_type) { @@ -1726,6 +1697,15 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) get_unaligned_le32(&tlv->val[0]); data->dump_info.exception_dump_len = get_unaligned_le32(&tlv->val[4]); + if (data->dump_info.exception_dump_len > + BTINTEL_PCIE_REGION_MAX_SIZE) { + bt_dev_warn(data->hdev, + "EXCEPTION_EVT_BUFFER size %u exceeds cap %u, ignoring", + data->dump_info.exception_dump_len, + BTINTEL_PCIE_REGION_MAX_SIZE); + data->dump_info.exception_dump_addr = 0; + data->dump_info.exception_dump_len = 0; + } break; case BTINTEL_PCIE_TLV_TYPE_DCCM_MEM_ADDRESS: if (tlv_len < 8) { @@ -1737,10 +1717,16 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) } data->dump_info.dccm_addr_start = get_unaligned_le32(&tlv->val[0]); - data->dump_info.dccm_addr_end = - get_unaligned_le32(&tlv->val[4]); + data->dump_info.dccm_size = + btintel_pcie_region_size(data->hdev, "DCCM", + data->dump_info.dccm_addr_start, + get_unaligned_le32(&tlv->val[4])); + if (!data->dump_info.dccm_size) + data->dump_info.dccm_addr_start = 0; break; - case BTINTEL_PCIE_TLV_TYPE_SDS_MEM_ADDRESS: + case BTINTEL_PCIE_TLV_TYPE_SDS_MEM_ADDRESS: { + struct btintel_pcie_dump_mem_info *di = &data->dump_info; + /* hw_variant comes from cnvi_bt which is set during * setup. If mailbox fires before setup completes, * hw_variant is 0. Skip SDS parsing in that case. @@ -1750,35 +1736,52 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) break; } if (tlv_len == 16 && hw_variant > BTINTEL_HWID_BZRI) { - data->dump_info.sds_start_addr_start = + di->sds_start_addr_start = get_unaligned_le32(&tlv->val[0]); - data->dump_info.sds_start_addr_end = - get_unaligned_le32(&tlv->val[4]); - data->dump_info.sds_iosf_data_addr_start = + di->sds_start_size = + btintel_pcie_region_size(data->hdev, "SDS", + di->sds_start_addr_start, + get_unaligned_le32(&tlv->val[4])); + di->sds_iosf_data_addr_start = get_unaligned_le32(&tlv->val[8]); - data->dump_info.sds_iosf_data_addr_end = - get_unaligned_le32(&tlv->val[12]); + di->sds_iosf_data_size = + btintel_pcie_region_size(data->hdev, "SDS_IOSF", + di->sds_iosf_data_addr_start, + get_unaligned_le32(&tlv->val[12])); } else if (tlv_len == 24 && (hw_variant == BTINTEL_HWID_BZRI || hw_variant == BTINTEL_HWID_BZRIW)) { - data->dump_info.sds_fixed_rom_addr_start = + di->sds_fixed_rom_addr_start = get_unaligned_le32(&tlv->val[0]); - data->dump_info.sds_fixed_rom_addr_end = - get_unaligned_le32(&tlv->val[4]); - data->dump_info.sds_start_addr_start = + di->sds_fixed_rom_size = + btintel_pcie_region_size(data->hdev, "SDS_FIXED_ROM", + di->sds_fixed_rom_addr_start, + get_unaligned_le32(&tlv->val[4])); + di->sds_start_addr_start = get_unaligned_le32(&tlv->val[8]); - data->dump_info.sds_start_addr_end = - get_unaligned_le32(&tlv->val[12]); - data->dump_info.sds_iosf_data_addr_start = + di->sds_start_size = + btintel_pcie_region_size(data->hdev, "SDS", + di->sds_start_addr_start, + get_unaligned_le32(&tlv->val[12])); + di->sds_iosf_data_addr_start = get_unaligned_le32(&tlv->val[16]); - data->dump_info.sds_iosf_data_addr_end = - get_unaligned_le32(&tlv->val[20]); + di->sds_iosf_data_size = + btintel_pcie_region_size(data->hdev, "SDS_IOSF", + di->sds_iosf_data_addr_start, + get_unaligned_le32(&tlv->val[20])); } else { bt_dev_err(data->hdev, "SDS TLV: hw=0x%2.2x len=%u", hw_variant, tlv_len); } + if (!di->sds_start_size) + di->sds_start_addr_start = 0; + if (!di->sds_iosf_data_size) + di->sds_iosf_data_addr_start = 0; + if (!di->sds_fixed_rom_size) + di->sds_fixed_rom_addr_start = 0; break; + } case BTINTEL_PCIE_TLV_TYPE_ECL_MEM_ADDRESS: if (tlv_len < 8) { bt_dev_err(data->hdev, @@ -1789,8 +1792,12 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) } data->dump_info.ecl_addr_start = get_unaligned_le32(&tlv->val[0]); - data->dump_info.ecl_addr_end = - get_unaligned_le32(&tlv->val[4]); + data->dump_info.ecl_size = + btintel_pcie_region_size(data->hdev, "ECL", + data->dump_info.ecl_addr_start, + get_unaligned_le32(&tlv->val[4])); + if (!data->dump_info.ecl_size) + data->dump_info.ecl_addr_start = 0; break; case BTINTEL_PCIE_TLV_TYPE_SMEM_ADDRESS: if (tlv_len < 8) { @@ -1802,8 +1809,12 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) } data->dump_info.smem_addr_start = get_unaligned_le32(&tlv->val[0]); - data->dump_info.smem_addr_end = - get_unaligned_le32(&tlv->val[4]); + data->dump_info.smem_size = + btintel_pcie_region_size(data->hdev, "SMEM", + data->dump_info.smem_addr_start, + get_unaligned_le32(&tlv->val[4])); + if (!data->dump_info.smem_size) + data->dump_info.smem_addr_start = 0; break; default: bt_dev_dbg(data->hdev, "Unknown TLV type: %u length: %u", @@ -1821,29 +1832,29 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data) data->dump_info.exception_dump_addr, data->dump_info.exception_dump_len); bt_dev_info(data->hdev, - "dccm: start:0x%08x end:0x%08x", + "dccm: start:0x%8.8x size:%u", data->dump_info.dccm_addr_start, - data->dump_info.dccm_addr_end); + data->dump_info.dccm_size); bt_dev_info(data->hdev, - "sds_fixed_rom: start:0x%08x end:0x%08x", + "sds_fixed_rom: start:0x%8.8x size:%u", data->dump_info.sds_fixed_rom_addr_start, - data->dump_info.sds_fixed_rom_addr_end); + data->dump_info.sds_fixed_rom_size); bt_dev_info(data->hdev, - "sds: start:0x%08x end:0x%08x", + "sds: start:0x%8.8x size:%u", data->dump_info.sds_start_addr_start, - data->dump_info.sds_start_addr_end); + data->dump_info.sds_start_size); bt_dev_info(data->hdev, - "sds_iosf: start:0x%08x end:0x%08x", + "sds_iosf: start:0x%8.8x size:%u", data->dump_info.sds_iosf_data_addr_start, - data->dump_info.sds_iosf_data_addr_end); + data->dump_info.sds_iosf_data_size); bt_dev_info(data->hdev, - "ecl: start:0x%08x end:0x%08x", + "ecl: start:0x%8.8x size:%u", data->dump_info.ecl_addr_start, - data->dump_info.ecl_addr_end); + data->dump_info.ecl_size); bt_dev_info(data->hdev, - "smem: start:0x%08x end:0x%08x", + "smem: start:0x%8.8x size:%u", data->dump_info.smem_addr_start, - data->dump_info.smem_addr_end); + data->dump_info.smem_size); vfree(buffer); return 0; diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 9d84db48a8e5..f35f80f800ed 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -76,8 +76,8 @@ #define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x2C) #define BTINTEL_PCIE_DBGC_ALLOCATION_OFFSET 0x100 -#define BTINTEL_PCIE_SMEM_MAX_SIZE (16 * 1024) -#define BTINTEL_PCIE_REGION_MAX_SIZE (16 * 1024 * 1024) +/* Upper bound for device-supplied debug-region sizes. */ +#define BTINTEL_PCIE_REGION_MAX_SIZE (1 * 1024 * 1024) #define BTINTEL_PCIE_DBG_IDX_BIT_MASK 0x0F #define BTINTEL_PCIE_DBGC_DBG_BUF_IDX(data) (((data) >> 24) & BTINTEL_PCIE_DBG_IDX_BIT_MASK) #define BTINTEL_PCIE_DBG_OFFSET_BIT_MASK 0xFFFFFF @@ -497,17 +497,17 @@ struct btintel_pcie_dump_mem_info { u32 exception_dump_addr; u32 exception_dump_len; u32 dccm_addr_start; - u32 dccm_addr_end; + u32 dccm_size; u32 sds_fixed_rom_addr_start; - u32 sds_fixed_rom_addr_end; + u32 sds_fixed_rom_size; u32 sds_start_addr_start; - u32 sds_start_addr_end; + u32 sds_start_size; u32 sds_iosf_data_addr_start; - u32 sds_iosf_data_addr_end; + u32 sds_iosf_data_size; u32 ecl_addr_start; - u32 ecl_addr_end; + u32 ecl_size; u32 smem_addr_start; - u32 smem_addr_end; + u32 smem_size; }; struct btintel_pcie_mbox { From cbfada3f0c5de233af6bff5a7dbbd05aaefca962 Mon Sep 17 00:00:00 2001 From: Samuel Alhovuori Date: Sat, 5 Sep 2026 22:57:46 +0300 Subject: [PATCH 1684/2126] Bluetooth: btusb: Add device ID for MediaTek MT7925 (13d3:3631) Add the USB ID 13d3:3631 for the MediaTek MT7925 Bluetooth module found on AzureWave / Mercusys MA37BE PCIe Wi-Fi 7 cards. T: Bus=01 Lev=02 Prnt=04 Port=03 Cnt=03 Dev#= 7 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=13d3 ProdID=3631 Rev= 1.00 S: Manufacturer=MediaTek Inc. S: Product=Wireless_Device Reviewed-by: Paul Menzel Signed-off-by: Samuel Alhovuori Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index a7488f6e8d8a..a47b51ffdcd0 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -837,6 +837,8 @@ static const struct usb_device_id quirks_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x13d3, 0x3630), .driver_info = BTUSB_MEDIATEK | BTUSB_WIDEBAND_SPEECH }, + { USB_DEVICE(0x13d3, 0x3631), .driver_info = BTUSB_MEDIATEK | + BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x2c7c, 0x7009), .driver_info = BTUSB_MEDIATEK | BTUSB_WIDEBAND_SPEECH }, From 3889a5fcd091d2154861c19e9c581f9f04aabd0e Mon Sep 17 00:00:00 2001 From: Radek Podgorny Date: Wed, 9 Sep 2026 00:29:36 +0200 Subject: [PATCH 1685/2126] Bluetooth: forget a peer's RPA once it advertises its identity address hci_connect_le() dials the RPA cached in the peer's IRK whenever one is set, on the assumption that a peer holding an IRK is on air with a resolvable private address. A peer that stops using privacy breaks that assumption: it advertises its identity address, the cached RPA keeps the value it had before the change, and the host aims at an address the peer has abandoned. Nothing clears the cache. hci_find_irk_by_rpa() refreshes irk->rpa each time an advertisement resolves, so it tracks rotation, but a peer that stops sending RPAs stops producing the reports that would update it, and the stale address then survives until the adapter is powered off. On the path that creates the connection object this is currently masked: __hci_conn_add() resolves the cached RPA back to the identity address, so that is what goes on air. It is not masked on the reuse branch, which copies the swapped address straight into an existing conn->dst, and the next patch removes the conversion for the case where the controller cannot translate an identity address, so the stale RPA would be dialled there too. Clear the cached RPA when the peer is seen on its identity address. hci_find_irk_by_addr() only matches public and static random addresses, so an unresolved RPA belonging to some other device cannot reach this path. Assisted-by: Claude:claude-opus-5 Signed-off-by: Radek Podgorny Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 2f5e21ff9752..03b805207ab0 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -6311,6 +6311,15 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, if (irk) { bdaddr = &irk->bdaddr; bdaddr_type = irk->addr_type; + } else { + /* The peer is on air with its identity address, so whatever + * RPA is cached for it has been abandoned. Drop it, or + * hci_connect_le() would swap it back in and dial an address + * the peer no longer answers. + */ + irk = hci_find_irk_by_addr(hdev, bdaddr, bdaddr_type); + if (irk) + bacpy(&irk->rpa, BDADDR_ANY); } bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved); From 9cc144d95eb746a6853cc5a463fc53d1e604d4a4 Mon Sep 17 00:00:00 2001 From: Adriano Cordova Date: Tue, 8 Sep 2026 13:54:13 -0300 Subject: [PATCH 1686/2126] Bluetooth: bnep: linearize skb before sending kernel_sendmsg expects contiguous data. Linearize the skb in the bnep_session() loop, before bnep_tx_frame builds its kvec, so it is not split across non-linear pages. Drop the dead block and FIXME. Signed-off-by: Adriano Cordova Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/bnep/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index f57b4323ab2f..06854f46ba34 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c @@ -495,10 +495,7 @@ send: iv[il++] = (struct kvec) { skb->data, skb->len }; len += skb->len; - /* FIXME: linearize skb */ - { - len = kernel_sendmsg(sock, &s->msg, iv, il, len); - } + len = kernel_sendmsg(sock, &s->msg, iv, il, len); kfree_skb(skb); if (len > 0) { @@ -539,9 +536,12 @@ static int bnep_session(void *arg) break; /* TX */ - while ((skb = skb_dequeue(&sk->sk_write_queue))) - if (bnep_tx_frame(s, skb)) + while ((skb = skb_dequeue(&sk->sk_write_queue))) { + if (skb_linearize(skb)) + kfree_skb(skb); + else if (bnep_tx_frame(s, skb)) break; + } netif_wake_queue(dev); /* From 760ac9d02dce001f2e20c17deb18e7bb63d8355e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 9 Sep 2026 20:00:09 +0800 Subject: [PATCH 1687/2126] Bluetooth: btmtk: Validate the firmware layout before parsing it btmtk_setup_firmware_79xx() reads the section count out of the firmware's global descriptor, then walks a 64-byte section map per section and hands each section's file-supplied offset and length to the WMT download path. None of that is checked against fw->size, so a truncated or corrupted file makes the driver read past the end of request_firmware()'s buffer. On 32-bit the section count can also wrap the section map size calculation. Add btmtk_fw_validate_layout() to check that the header, global descriptor and section map array all fit, and btmtk_fw_validate_section() to check one section's offset and length, both written so the size arithmetic cannot wrap. A section count of zero is rejected as well: it passes every size check but leaves the download loop with nothing to do, so the function would report success on hardware it never programmed. They are helpers rather than open-coded because the MT7928 CBMCU download path added later needs the same arithmetic. This is hardening against a corrupted /lib/firmware rather than a bug an unprivileged user can trigger, hence bluetooth-next and no Fixes: tag. Well-formed firmware files are unaffected. Signed-off-by: Chris Lu Assisted-by: Claude:claude-opus-5 Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 74 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 27111ce8aee1..d200faf285d0 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,67 @@ struct btmtk_section_map { }; } __packed; +/* Reject a firmware image whose header, global descriptor or section map + * array does not fit in the file, and hand back the validated section + * count, so that the section map walks stay inside the firmware buffer. + */ +static int btmtk_fw_validate_layout(struct hci_dev *hdev, + const struct firmware *fw, + u32 *section_num) +{ + const struct btmtk_global_desc *globaldesc; + size_t need; + + if (fw->size < MTK_FW_ROM_PATCH_HEADER_SIZE + MTK_FW_ROM_PATCH_GD_SIZE) { + bt_dev_err(hdev, "Firmware too small: %zu bytes, need at least %u", + fw->size, + MTK_FW_ROM_PATCH_HEADER_SIZE + MTK_FW_ROM_PATCH_GD_SIZE); + return -EINVAL; + } + + globaldesc = (const struct btmtk_global_desc *)(fw->data + + MTK_FW_ROM_PATCH_HEADER_SIZE); + *section_num = le32_to_cpu(globaldesc->section_num); + + if (!*section_num) { + bt_dev_err(hdev, "Firmware declares no sections"); + return -EINVAL; + } + + if (check_mul_overflow((size_t)MTK_FW_ROM_PATCH_SEC_MAP_SIZE, + (size_t)*section_num, &need) || + check_add_overflow(need, + (size_t)(MTK_FW_ROM_PATCH_HEADER_SIZE + + MTK_FW_ROM_PATCH_GD_SIZE), + &need)) { + bt_dev_err(hdev, "Firmware section count too large: %u", + *section_num); + return -EINVAL; + } + + if (fw->size < need) { + bt_dev_err(hdev, "Firmware truncated: %zu bytes, need %zu for %u sections", + fw->size, need, *section_num); + return -EINVAL; + } + + return 0; +} + +/* Reject a section whose payload does not lie within the firmware file. */ +static int btmtk_fw_validate_section(struct hci_dev *hdev, + const struct firmware *fw, int index, + u32 offset, u32 size) +{ + if (offset > fw->size || size > fw->size - offset) { + bt_dev_err(hdev, "Firmware section %d out of bounds: offset=%u, size=%u, fw_size=%zu", + index, offset, size, fw->size); + return -EINVAL; + } + + return 0; +} + static void btmtk_coredump(struct hci_dev *hdev) { int err; @@ -137,7 +199,6 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, { struct btmtk_hci_wmt_params wmt_params; struct btmtk_patch_header *hdr; - struct btmtk_global_desc *globaldesc = NULL; struct btmtk_section_map *sectionmap; const struct firmware *fw; const u8 *fw_ptr; @@ -153,11 +214,13 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, return err; } + err = btmtk_fw_validate_layout(hdev, fw, §ion_num); + if (err < 0) + goto err_release_fw; + fw_ptr = fw->data; fw_bin_ptr = fw_ptr; hdr = (struct btmtk_patch_header *)fw_ptr; - globaldesc = (struct btmtk_global_desc *)(fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE); - section_num = le32_to_cpu(globaldesc->section_num); bt_dev_info(hdev, "HW/SW Version: 0x%04x%04x, Build Time: %s", le16_to_cpu(hdr->hwver), le16_to_cpu(hdr->swver), hdr->datetime); @@ -180,6 +243,11 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, continue; if (dl_size > 0) { + err = btmtk_fw_validate_section(hdev, fw, i, + section_offset, dl_size); + if (err < 0) + goto err_release_fw; + retry = 20; while (retry > 0) { cmd[0] = 0; /* 0 means legacy dl mode. */ From 046fa20e9c7abbafb166b431fe446c49b71cb15a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 9 Sep 2026 20:00:10 +0800 Subject: [PATCH 1688/2126] Bluetooth: btmtk: Improve BT firmware logging The firmware log line in btmtk_setup_firmware_79xx() never says which file was requested, which matters because btmtk_fw_get_filename() derives the name from the device id and firmware version at runtime. It reports the firmware's own hwver field as the HW version, when the device id the driver read from the chip is the more useful value and is already available as dev_id. And it prints datetime, a u8[16] with no guaranteed NUL terminator, with %s. Log the filename before the image is parsed, so a file that fails validation still says which file it was, report dev_id as the HW version, and bound datetime with %.16s. The datetime change is hardening rather than a fix, hence no Fixes: tag: every file in linux-firmware terminates the field, and provoking the over-read needs a malformed file in /lib/firmware. Log output on MT7922 after the change: [ 365.245951] Bluetooth: hci0: Loading BT firmware: mediatek/BT_RAM_CODE_MT7922_1_1_hdr.bin [ 365.245956] Bluetooth: hci0: BT HW ver: 0x7922, SW ver: 0x008a, Build Time: 20260605203811 Signed-off-by: Chris Lu Assisted-by: Claude:claude-opus-5 Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index d200faf285d0..9866acfc65a0 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -214,6 +214,8 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, return err; } + bt_dev_info(hdev, "Loading BT firmware: %s", fwname); + err = btmtk_fw_validate_layout(hdev, fw, §ion_num); if (err < 0) goto err_release_fw; @@ -222,8 +224,8 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, fw_bin_ptr = fw_ptr; hdr = (struct btmtk_patch_header *)fw_ptr; - bt_dev_info(hdev, "HW/SW Version: 0x%04x%04x, Build Time: %s", - le16_to_cpu(hdr->hwver), le16_to_cpu(hdr->swver), hdr->datetime); + bt_dev_info(hdev, "BT HW ver: 0x%04x, SW ver: 0x%04x, Build Time: %.16s", + dev_id & 0xffff, le16_to_cpu(hdr->swver), hdr->datetime); for (i = 0; i < section_num; i++) { first_block = 1; From 8be5ec1f66df125af8b968a176c65344e3844a5f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 9 Sep 2026 20:00:11 +0800 Subject: [PATCH 1689/2126] Bluetooth: btmtk: Replace magic numbers with WMT packet flag enum The flag field of a BTMTK_WMT_PATCH_DWNLD packet tells the device where the packet sits in the download sequence, but both download loops write the bare values 1, 2 and 3, so the reader has to infer the meaning from the surrounding conditionals. Add enum btmtk_wmt_pkt_flag and use it in btmtk_setup_firmware_79xx() and btmtk_setup_firmware(). No functional change. The other bare flag values in this driver belong to different WMT opcodes (BTMTK_WMT_FUNC_CTRL, BTMTK_WMT_RST, BTMTK_WMT_SEMAPHORE and so on), where the field means something else entirely, so they are left alone. Signed-off-by: Chris Lu Reviewed-by: Paul Menzel Assisted-by: Claude:claude-opus-5 Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 12 ++++++------ drivers/bluetooth/btmtk.h | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 9866acfc65a0..03b99826b52c 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -300,12 +300,12 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, while (dl_size > 0) { dlen = min_t(int, 250, dl_size); if (first_block == 1) { - flag = 1; + flag = BTMTK_WMT_PKT_START; first_block = 0; } else if (dl_size - dlen <= 0) { - flag = 3; + flag = BTMTK_WMT_PKT_END; } else { - flag = 2; + flag = BTMTK_WMT_PKT_CONTINUE; } wmt_params.flag = flag; @@ -384,7 +384,7 @@ int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname, fw_size -= 30; fw_ptr += 30; - flag = 1; + flag = BTMTK_WMT_PKT_START; wmt_params.op = BTMTK_WMT_PATCH_DWNLD; wmt_params.status = NULL; @@ -394,9 +394,9 @@ int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname, /* Tell device the position in sequence */ if (fw_size - dlen <= 0) - flag = 3; + flag = BTMTK_WMT_PKT_END; else if (fw_size < fw->size - 30) - flag = 2; + flag = BTMTK_WMT_PKT_CONTINUE; wmt_params.flag = flag; wmt_params.dlen = dlen; diff --git a/drivers/bluetooth/btmtk.h b/drivers/bluetooth/btmtk.h index bc26148ec544..e8ad281a93a0 100644 --- a/drivers/bluetooth/btmtk.h +++ b/drivers/bluetooth/btmtk.h @@ -67,6 +67,15 @@ enum { BTMTK_WMT_ON_PROGRESS, }; +/* Position of a BTMTK_WMT_PATCH_DWNLD packet within a download sequence, + * carried in struct btmtk_wmt_hdr's flag field. + */ +enum btmtk_wmt_pkt_flag { + BTMTK_WMT_PKT_START = 1, + BTMTK_WMT_PKT_CONTINUE = 2, + BTMTK_WMT_PKT_END = 3, +}; + struct btmtk_wmt_hdr { u8 dir; u8 op; From 00b201656db41c9eeeed5ca92a4efb6d729ae58e Mon Sep 17 00:00:00 2001 From: Jeremy Dean Date: Tue, 25 Aug 2026 12:22:07 +0000 Subject: [PATCH 1690/2126] Bluetooth: Fix code style error checkpatch.pl flags the zero-length array members in struct qca_dump_hdr: ERROR: Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays #3110: FILE: drivers/bluetooth/btusb.c:3110: + u8 data0[0]; Replace them with DECLARE_FLEX_ARRAY(), since C99 flexible array members are not permitted inside unions or as the sole member of a struct. The struct layout is unchanged, and everything compiles with the change. Link: https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays Signed-off-by: Jeremy Dean Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index a47b51ffdcd0..83d122de5d7d 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3316,10 +3316,10 @@ struct qca_dump_hdr { __le16 seqno; u8 reserved; union { - u8 data[0]; + DECLARE_FLEX_ARRAY(u8, data); struct { __le32 ram_dump_size; - u8 data0[0]; + DECLARE_FLEX_ARRAY(u8, data0); } __packed; }; } __packed; From c930a69fecb98fc058ad4d57f2d9bf2e11f318f3 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Thu, 10 Sep 2026 14:32:54 +0200 Subject: [PATCH 1691/2126] Bluetooth: SMP: Zeroize raw key data on the stack in smp_e() smp_e() already clears the AES key in its "struct aes_enckey aes" on the stack before leaving the function - but the very same information is also available as raw key data in the tmp[] array, so this should get cleared, too. Signed-off-by: Thomas Huth Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/smp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 2df303f6a38f..5c3bd4278386 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -366,7 +366,7 @@ static int smp_e(const u8 *k, u8 *r) err = aes_prepareenckey(&aes, tmp, 16); if (err) { BT_ERR("cipher setkey failed: %d", err); - return err; + goto out_clear; } /* Most significant octet of plaintextData corresponds to data[0] */ @@ -379,6 +379,8 @@ static int smp_e(const u8 *k, u8 *r) SMP_DBG("r %16phN", r); +out_clear: + memzero_explicit(tmp, sizeof(tmp)); memzero_explicit(&aes, sizeof(aes)); return err; } From 9822887f0db04ef169a1428892b63139ccf953e8 Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Sun, 13 Sep 2026 20:42:58 -0700 Subject: [PATCH 1692/2126] Bluetooth: hci_event: Use 254 as max LE Meta subevent payload length in hci_le_ev_table[] hci_le_meta_evt() validates skb->len against subev->max_len from the entry in hci_le_ev_table[], By then, the HCI event header and LE Meta subevent header have already been stripped by skb_pull(), So the max LE Meta subevent payload is 254, but hci_le_ev_table[] still uses HCI_MAX_EVENT_SIZE (260) for it, which is imprecise. Fix by defining HCI_MAX_LE_SUBEVT_PLEN (254) and using it instead. Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 03b805207ab0..1eacdd93c5b5 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -7474,6 +7474,9 @@ static void hci_le_conn_rate_change_evt(struct hci_dev *hdev, void *data, #define HCI_LE_EV_STATUS(_op, _func) \ HCI_LE_EV(_op, _func, sizeof(struct hci_ev_status)) +#define HCI_MAX_LE_SUBEVT_PLEN \ + (HCI_MAX_EVENT_PLEN - sizeof(struct hci_ev_le_meta)) + /* Entries in this table shall have their position according to the subevent * opcode they handle so the use of the macros above is recommend since it does * attempt to initialize at its proper index using Designated Initializers that @@ -7490,7 +7493,7 @@ static const struct hci_le_ev { /* [0x02 = HCI_EV_LE_ADVERTISING_REPORT] */ HCI_LE_EV_VL(HCI_EV_LE_ADVERTISING_REPORT, hci_le_adv_report_evt, sizeof(struct hci_ev_le_advertising_report), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x03 = HCI_EV_LE_CONN_UPDATE_COMPLETE] */ HCI_LE_EV(HCI_EV_LE_CONN_UPDATE_COMPLETE, hci_le_conn_update_complete_evt, @@ -7513,14 +7516,14 @@ static const struct hci_le_ev { /* [0x0b = HCI_EV_LE_DIRECT_ADV_REPORT] */ HCI_LE_EV_VL(HCI_EV_LE_DIRECT_ADV_REPORT, hci_le_direct_adv_report_evt, sizeof(struct hci_ev_le_direct_adv_report), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x0c = HCI_EV_LE_PHY_UPDATE_COMPLETE] */ HCI_LE_EV(HCI_EV_LE_PHY_UPDATE_COMPLETE, hci_le_phy_update_evt, sizeof(struct hci_ev_le_phy_update_complete)), /* [0x0d = HCI_EV_LE_EXT_ADV_REPORT] */ HCI_LE_EV_VL(HCI_EV_LE_EXT_ADV_REPORT, hci_le_ext_adv_report_evt, sizeof(struct hci_ev_le_ext_adv_report), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x0e = HCI_EV_LE_PA_SYNC_ESTABLISHED] */ HCI_LE_EV(HCI_EV_LE_PA_SYNC_ESTABLISHED, hci_le_pa_sync_established_evt, @@ -7529,7 +7532,7 @@ static const struct hci_le_ev { HCI_LE_EV_VL(HCI_EV_LE_PER_ADV_REPORT, hci_le_per_adv_report_evt, sizeof(struct hci_ev_le_per_adv_report), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x10 = HCI_EV_LE_PA_SYNC_LOST] */ HCI_LE_EV(HCI_EV_LE_PA_SYNC_LOST, hci_le_pa_sync_lost_evt, sizeof(struct hci_ev_le_pa_sync_lost)), @@ -7550,28 +7553,28 @@ static const struct hci_le_ev { HCI_LE_EV_VL(HCI_EVT_LE_CREATE_BIG_COMPLETE, hci_le_create_big_complete_evt, sizeof(struct hci_evt_le_create_big_complete), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x1d = HCI_EV_LE_BIG_SYNC_ESTABLISHED] */ HCI_LE_EV_VL(HCI_EVT_LE_BIG_SYNC_ESTABLISHED, hci_le_big_sync_established_evt, sizeof(struct hci_evt_le_big_sync_established), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x1e = HCI_EVT_LE_BIG_SYNC_LOST] */ HCI_LE_EV_VL(HCI_EVT_LE_BIG_SYNC_LOST, hci_le_big_sync_lost_evt, sizeof(struct hci_evt_le_big_sync_lost), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x22 = HCI_EVT_LE_BIG_INFO_ADV_REPORT] */ HCI_LE_EV_VL(HCI_EVT_LE_BIG_INFO_ADV_REPORT, hci_le_big_info_adv_report_evt, sizeof(struct hci_evt_le_big_info_adv_report), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x2b = HCI_EVT_LE_ALL_REMOTE_FEATURES_COMPLETE] */ HCI_LE_EV_VL(HCI_EVT_LE_ALL_REMOTE_FEATURES_COMPLETE, hci_le_read_all_remote_features_evt, sizeof(struct hci_evt_le_read_all_remote_features_complete), - HCI_MAX_EVENT_SIZE), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x37 = HCI_EVT_LE_CONN_RATE_CHANGE] */ HCI_LE_EV(HCI_EVT_LE_CONN_RATE_CHANGE, hci_le_conn_rate_change_evt, sizeof(struct hci_evt_le_conn_rate_change)), From 51589ddae31137711c985f2b02c917c760ab5a81 Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Sun, 13 Sep 2026 20:42:59 -0700 Subject: [PATCH 1693/2126] Bluetooth: hci_event: Use 252 as max CC event payload length in hci_cc_table[] hci_cc_func() validates skb->len against cc->max_len from the entry in hci_cc_table[], But By then, the HCI event and CC headers have already been stripped by skb_pull(). So the max CC payload is 252, but hci_cc_table[] still uses HCI_MAX_EVENT_SIZE (260) for it, which is imprecise. Fix by defining HCI_MAX_CC_PLEN (252) and using it instead. Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1eacdd93c5b5..25ddba2f603b 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4099,6 +4099,9 @@ unlock: #define HCI_CC_STATUS(_op, _func) \ HCI_CC(_op, _func, sizeof(struct hci_ev_status)) +#define HCI_MAX_CC_PLEN \ + (HCI_MAX_EVENT_PLEN - sizeof(struct hci_ev_cmd_complete)) + static const struct hci_cc { u16 op; u8 (*func)(struct hci_dev *hdev, void *data, struct sk_buff *skb); @@ -4192,7 +4195,7 @@ static const struct hci_cc { sizeof(struct hci_rp_le_read_local_features)), HCI_CC_VL(HCI_OP_LE_READ_CONN_INTERVAL, hci_cc_le_read_conn_interval, sizeof(struct hci_rp_le_read_conn_interval), - HCI_MAX_EVENT_SIZE), + HCI_MAX_CC_PLEN), HCI_CC(HCI_OP_LE_READ_ADV_TX_POWER, hci_cc_le_read_adv_tx_power, sizeof(struct hci_rp_le_read_adv_tx_power)), HCI_CC(HCI_OP_USER_CONFIRM_REPLY, hci_cc_user_confirm_reply, @@ -4264,7 +4267,7 @@ static const struct hci_cc { HCI_CC(HCI_OP_LE_READ_BUFFER_SIZE_V2, hci_cc_le_read_buffer_size_v2, sizeof(struct hci_rp_le_read_buffer_size_v2)), HCI_CC_VL(HCI_OP_LE_SET_CIG_PARAMS, hci_cc_le_set_cig_params, - sizeof(struct hci_rp_le_set_cig_params), HCI_MAX_EVENT_SIZE), + sizeof(struct hci_rp_le_set_cig_params), HCI_MAX_CC_PLEN), HCI_CC(HCI_OP_LE_SETUP_ISO_PATH, hci_cc_le_setup_iso_path, sizeof(struct hci_rp_le_setup_iso_path)), HCI_CC(HCI_OP_LE_READ_ALL_LOCAL_FEATURES, From 13095bb5ce1f3b5d720de252e1410d178cf1155b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 14 Sep 2026 14:56:52 +0800 Subject: [PATCH 1694/2126] Bluetooth: btmtk: Route firmware debug event to the diag channel MediaTek controllers may emit a firmware debug event on the ACL channel using the reserved handle 0x0efd, which shows up in the ACL header as 0x2efd once the start fragment flag is included. Neither btmtk_usb_recv_acl() nor btmtksdio_recv_acl() recognizes it, so the packet is passed to the HCI core, which has no connection with that handle and complains: Bluetooth: hci0: ACL packet for unknown connection handle 3837 Handle it the same way as the existing firmware debug logging packets and forward it to the diagnostic channel instead. Confirmed with MTK internally that this event's wire format is fixed: firmware always sends it as a single ACL_START packet and never splits it into a continuation (ACL_CONT, which would show up as 0x1efd). Add a comment above the switch spelling that out for this and the other vendor-reserved handles already handled here (0xfc6f, 0x05ff, 0x05fe), so review tooling doesn't keep flagging the apparent lack of a matching continuation case. Verified on MT7922: under the condition that triggers this firmware debug event, it is now routed to the diag channel instead of reaching the host as an unknown ACL packet. Signed-off-by: Chris Lu Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 8 ++++++++ drivers/bluetooth/btmtksdio.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 03b99826b52c..115a11fcb254 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -1060,6 +1060,13 @@ int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) struct btmtk_data *data = hci_get_priv(hdev); u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle); + /* The handles below are vendor-reserved values MTK firmware uses to + * tag out-of-band debug/dump data on the ACL channel rather than a + * real connection. Each is always sent as a single, complete + * ACL_START packet, so unlike genuine connection data they never + * arrive fragmented (e.g. 0x2efd is never followed by an ACL_CONT + * continuation, 0x1efd). + */ switch (handle) { case 0xfc6f: /* Firmware dump from device */ /* When the firmware hangs, the device can no longer @@ -1081,6 +1088,7 @@ int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) fallthrough; case 0x05ff: /* Firmware debug logging 1 */ case 0x05fe: /* Firmware debug logging 2 */ + case 0x2efd: /* Firmware debug event */ return hci_recv_diag(hdev, skb); } diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index 4d996d18652c..f7bdaebf660d 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -469,6 +469,13 @@ static int btmtksdio_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle); + /* The handles below are vendor-reserved values MTK firmware uses to + * tag out-of-band debug/dump data on the ACL channel rather than a + * real connection. Each is always sent as a single, complete + * ACL_START packet, so unlike genuine connection data they never + * arrive fragmented (e.g. 0x2efd is never followed by an ACL_CONT + * continuation, 0x1efd). + */ switch (handle) { case 0xfc6f: /* Firmware dump from device: when the firmware hangs, the @@ -478,6 +485,7 @@ static int btmtksdio_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) fallthrough; case 0x05ff: case 0x05fe: + case 0x2efd: /* Firmware debug event */ /* Firmware debug logging */ return hci_recv_diag(hdev, skb); } From 3fe48c863a145738720f37a1309643c84b39b06d Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Mon, 14 Sep 2026 09:46:31 +0000 Subject: [PATCH 1695/2126] Bluetooth: btmtksdio: Fix spurious ownership error logs In btmtksdio_fw_pmctrl(), if an early operation fails (like clearing the mailbox ACK), it jumps to the `out:` label and spuriously prints "Cannot return ownership to device". Evaluate the ownership return errors locally to ensure the error log is only printed if the actual ownership transaction fails. Signed-off-by: Tzung-Bi Shih Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtksdio.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index f7bdaebf660d..b9563df72983 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -378,17 +378,13 @@ static int btmtksdio_fw_pmctrl(struct btmtksdio_dev *bdev) /* Return ownership to the device */ sdio_writel(bdev->func, C_FW_OWN_REQ_SET, MTK_REG_CHLPCR, &err); - if (err < 0) - goto out; - - err = readx_poll_timeout(btmtksdio_drv_own_query, bdev, status, - !(status & C_COM_DRV_OWN), 2000, 1000000); - -out: - sdio_release_host(bdev->func); - + if (err == 0) + err = readx_poll_timeout(btmtksdio_drv_own_query, bdev, status, + !(status & C_COM_DRV_OWN), 2000, 1000000); if (err < 0) bt_dev_err(bdev->hdev, "Cannot return ownership to device"); +out: + sdio_release_host(bdev->func); return err; } From 179950cdcb2667a253671ea1001d4cab48e0040a Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Sun, 13 Sep 2026 19:46:43 -0700 Subject: [PATCH 1696/2126] Bluetooth: btusb: Add recv_intr() hook to btusb_data To allow a vendor driver to assemble and handle its non-BT frames from the interrupt endpoint. Used by Qualcomm QCC2072 support. Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 83d122de5d7d..5efcf31e432b 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -1072,6 +1072,7 @@ struct btusb_data { int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb); int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb); + int (*recv_intr)(struct btusb_data *data, void *buffer, int count); int (*recv_bulk)(struct btusb_data *data, void *buffer, int count); int (*setup_on_usb)(struct hci_dev *hdev); @@ -1582,7 +1583,7 @@ static void btusb_intr_complete(struct urb *urb) if (urb->status == 0) { hdev->stat.byte_rx += urb->actual_length; - if (btusb_recv_intr(data, urb->transfer_buffer, + if (data->recv_intr(data, urb->transfer_buffer, urb->actual_length) < 0) { bt_dev_err(hdev, "corrupted event packet"); hdev->stat.err_rx++; @@ -2851,7 +2852,7 @@ static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, */ if (data->proto == BTUSB_PROTO_LEGACY && btintel_test_flag(hdev, INTEL_BOOTLOADER)) - return btusb_recv_intr(data, buffer, count); + return data->recv_intr(data, buffer, count); return btusb_recv_bulk(data, buffer, count); } @@ -4392,6 +4393,7 @@ static int btusb_probe(struct usb_interface *intf, spin_lock_init(&data->rxlock); data->recv_event = hci_recv_frame; + data->recv_intr = btusb_recv_intr; data->recv_bulk = btusb_recv_bulk; if (id->driver_info & BTUSB_INTEL_COMBINED) { From 366cdec7fec589321248bf3080216d42bf492a19 Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Sun, 13 Sep 2026 19:46:44 -0700 Subject: [PATCH 1697/2126] Bluetooth: Add generic support for vendor packets The virtual HCI_VENDOR_PKT (0xff) has been defined but never used by the BT core. Now, there is a requirement to implement it, as follows: For Qualcomm multi-subsystem BT chips, the transport wire carries both BT-HCI and PERI-HCI packets, where PERI is a subsystem in the chip, take the upcoming QCC2072 as an example: Packet type BT-HCI indicator PERI-HCI indicator ----------------------------------------------------------------- CMD (Host -> Controller) 0x01 0x31 ACL Data (bidirectional) 0x02 0x32 EVENT (Controller -> Host) 0x04 0x34 There are also BT ACL packets with vendor-reserved handles found in existing device drivers, as shown below: +--------+--------+---------------------------+ | Vendor | Handle | Purpose | +--------+--------+---------------------------+ | QCOM | 0xEDD | Firmware coredump | | | 0xEDC | Firmware enhanced logging | +--------+--------+---------------------------+ | MTK | 0xFC6F | Firmware coredump | | | 0x05FF | Firmware debug logging 1 | | | 0x05FE | Firmware debug logging 2 | +--------+--------+---------------------------+ | NXP | 0xFFF | Firmware coredump | +--------+--------+---------------------------+ Implement HCI_VENDOR_PKT to generically support such vendor packets, which don't follow BT SIG's vendor-extension framework: - Log them in btmon as they appear on the wire. - Add hdev->recv_vendor_pkt() to handle them in hci_rx_work(). - Add hci_send_vendor_frame() to send them to the device driver. - Allow them to flow over HCI_CHANNEL_USER, nested inside HCI_VENDOR_PKT. Also solve the same issues that the commit below fixes for HCI_EV_VENDOR, which follows BT SIG's vendor-extension framework: commit 0bd606b31d40 ("Bluetooth: hci_event: Introduce handle_ev_vendor() for HCI_EV_VENDOR") Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 5 ++++ include/net/bluetooth/hci_mon.h | 2 ++ net/bluetooth/hci_core.c | 45 ++++++++++++++++++++++++++++++++ net/bluetooth/hci_sock.c | 8 ++++++ 4 files changed, 60 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index b9583acc6c14..fb85a0ccb250 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -647,6 +648,8 @@ struct hci_dev { int (*setup)(struct hci_dev *hdev); int (*shutdown)(struct hci_dev *hdev); int (*send)(struct hci_dev *hdev, struct sk_buff *skb); + /* Receive HCI_VENDOR_PKT */ + void (*recv_vendor_pkt)(struct hci_dev *hdev, struct sk_buff *skb); /* Handle HCI_EV_VENDOR; return true if handled, false otherwise */ bool (*handle_ev_vendor)(struct hci_dev *hdev, struct sk_buff *skb); void (*notify)(struct hci_dev *hdev, unsigned int evt); @@ -2401,6 +2404,8 @@ static inline int hci_check_conn_params(u16 min, u16 max, u16 latency, int hci_register_cb(struct hci_cb *hcb); int hci_unregister_cb(struct hci_cb *hcb); +int hci_send_vendor_frame(struct hci_dev *hdev, struct iov_iter *iter); + int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, const void *param); diff --git a/include/net/bluetooth/hci_mon.h b/include/net/bluetooth/hci_mon.h index 4b2a0af4ed58..7710688c0d30 100644 --- a/include/net/bluetooth/hci_mon.h +++ b/include/net/bluetooth/hci_mon.h @@ -50,6 +50,8 @@ struct hci_mon_hdr { #define HCI_MON_ISO_RX_PKT 19 #define HCI_MON_DRV_TX_PKT 20 #define HCI_MON_DRV_RX_PKT 21 +#define HCI_MON_VENDOR_TX_PKT 22 +#define HCI_MON_VENDOR_RX_PKT 23 struct hci_mon_new_index { __u8 type; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 61ed4aad2c71..5c6884b65976 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2929,6 +2929,8 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) break; case HCI_ISODATA_PKT: break; + case HCI_VENDOR_PKT: + break; case HCI_DRV_PKT: break; default: @@ -3065,6 +3067,41 @@ static int hci_send_conn_frame(struct hci_dev *hdev, struct hci_conn *conn, return hci_send_frame(hdev, skb); } +/** + * hci_send_vendor_frame - Send an HCI_VENDOR_PKT frame to the HCI driver + * @hdev: The HCI device + * @iter: iov_iter carrying the frame + * + * Return: 0 on success, or a negative errno on failure. + */ +int hci_send_vendor_frame(struct hci_dev *hdev, struct iov_iter *iter) +{ + struct sk_buff *skb; + unsigned int len; + + if (WARN_ON(!iov_iter_is_kvec(iter))) + return -EINVAL; + + /* Vendor frames are opaque, the caller guarantees the size. */ + len = (unsigned int)iov_iter_count(iter); + if (!len) + return -EINVAL; + + skb = bt_skb_alloc(len, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + if (!copy_from_iter_full(skb_put(skb, len), len, iter)) { + kfree_skb(skb); + return -EFAULT; + } + + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; + + return hci_send_frame(hdev, skb); +} +EXPORT_SYMBOL(hci_send_vendor_frame); + /* Send HCI command */ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, const void *param) @@ -4102,6 +4139,14 @@ static void hci_rx_work(struct work_struct *work) hci_isodata_packet(hdev, skb); break; + case HCI_VENDOR_PKT: + BT_DBG("%s Vendor packet", hdev->name); + if (hdev->recv_vendor_pkt) + hdev->recv_vendor_pkt(hdev, skb); + else + kfree_skb(skb); + break; + default: kfree_skb(skb); break; diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 81068b585764..b26f065d0c18 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -244,6 +244,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb) hci_skb_pkt_type(skb) != HCI_ACLDATA_PKT && hci_skb_pkt_type(skb) != HCI_SCODATA_PKT && hci_skb_pkt_type(skb) != HCI_ISODATA_PKT && + hci_skb_pkt_type(skb) != HCI_VENDOR_PKT && hci_skb_pkt_type(skb) != HCI_DRV_PKT) continue; } else { @@ -401,6 +402,12 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb) else opcode = cpu_to_le16(HCI_MON_ISO_TX_PKT); break; + case HCI_VENDOR_PKT: + if (bt_cb(skb)->incoming) + opcode = cpu_to_le16(HCI_MON_VENDOR_RX_PKT); + else + opcode = cpu_to_le16(HCI_MON_VENDOR_TX_PKT); + break; case HCI_DRV_PKT: if (bt_cb(skb)->incoming) opcode = cpu_to_le16(HCI_MON_DRV_RX_PKT); @@ -1881,6 +1888,7 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg, hci_skb_pkt_type(skb) != HCI_ACLDATA_PKT && hci_skb_pkt_type(skb) != HCI_SCODATA_PKT && hci_skb_pkt_type(skb) != HCI_ISODATA_PKT && + hci_skb_pkt_type(skb) != HCI_VENDOR_PKT && hci_skb_pkt_type(skb) != HCI_DRV_PKT) { err = -EINVAL; goto drop; From be58267a34ae562a4a6932f68f1487bceb0345d7 Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Sun, 13 Sep 2026 19:46:45 -0700 Subject: [PATCH 1698/2126] Bluetooth: btusb: Build the driver from multiple source files Allow the driver to include vendor USB-transport-specific source files by: - renaming btusb.c to btusb_main.c - making btusb.o a composite object Used by Qualcomm QCC2072 support. Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/Makefile | 2 ++ drivers/bluetooth/{btusb.c => btusb_main.c} | 0 2 files changed, 2 insertions(+) rename drivers/bluetooth/{btusb.c => btusb_main.c} (100%) diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index e6b1c1180d1d..8b436c6de8b7 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile @@ -51,4 +51,6 @@ hci_uart-$(CONFIG_BT_HCIUART_MRVL) += hci_mrvl.o hci_uart-$(CONFIG_BT_HCIUART_AML) += hci_aml.o hci_uart-objs := $(hci_uart-y) +btusb-y := btusb_main.o + CONTEXT_ANALYSIS := y diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb_main.c similarity index 100% rename from drivers/bluetooth/btusb.c rename to drivers/bluetooth/btusb_main.c From 3669487308f87d1e6550cf6d5613ea171bad1181 Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Sun, 13 Sep 2026 19:46:46 -0700 Subject: [PATCH 1699/2126] Bluetooth: btusb: Add support for Qualcomm multi-subsystem QCC2072 QCC2072 has a Peripheral (PERI) subsystem to support the BT function unit, the transport wire is owned by PERI and carries both BT-HCI and PERI-HCI frames, as shown below: _______________________________ USB I/F | internal link | BTHOST -------- |---- PERI -------------- BT | |_______________________________| (other on-chip subsystems omitted) PERI has its own command/event/ACL traffic, memdump, and firmware (PATCH and NVM), all different from BT's own, and BTHOST needs to interact with PERI directly. To support multi-subsystem controllers, add btusb_qcom.c/.h as a new transport-specific design: - Multi-subsystem memdump collection. - Generic PERI event handling, and sending a PERI frame then syncing an event sequence. - Downloading PERI firmware (rampatch and NVM). - Recovery on command timeout or hardware error event. BTW, it also supports BT-only chips. /sys/kernel/debug/usb/devices: T: Bus=03 Lev=02 Prnt=02 Port=02 Cnt=01 Dev#= 5 Spd=12 MxCh= 0 D: Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=0cf3 ProdID=ea00 Rev= 0.01 C:* #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA I:* If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=1ms E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms I:* If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 0 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 0 Ivl=1ms I: If#= 1 Alt= 1 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 9 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 9 Ivl=1ms I: If#= 1 Alt= 2 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 17 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 17 Ivl=1ms I: If#= 1 Alt= 3 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 25 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 25 Ivl=1ms I: If#= 1 Alt= 4 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 33 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 33 Ivl=1ms I: If#= 1 Alt= 5 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 49 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 49 Ivl=1ms I: If#= 1 Alt= 6 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 63 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 63 Ivl=1ms I: If#= 1 Alt= 7 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=83(I) Atr=01(Isoc) MxPS= 65 Ivl=1ms E: Ad=03(O) Atr=01(Isoc) MxPS= 65 Ivl=1ms Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/Kconfig | 14 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/btusb_main.c | 121 + drivers/bluetooth/btusb_qcom.c | 4557 ++++++++++++++++++++++++++++++++ drivers/bluetooth/btusb_qcom.h | 99 + 5 files changed, 4792 insertions(+) create mode 100644 drivers/bluetooth/btusb_qcom.c create mode 100644 drivers/bluetooth/btusb_qcom.h diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 2d6a3117e387..db0189ca3cbe 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -90,6 +90,20 @@ config BT_HCIBTUSB_RTL Say Y here to compile support for Realtek protocol. +config BT_HCIBTUSB_QCOM + bool "Qualcomm protocol support" + depends on BT_HCIBTUSB + select FW_LOADER + select GPIOLIB + select WANT_DEV_COREDUMP + default y + help + Enables various required support, such as configuration, firmware + download, and error recovery, for Qualcomm Bluetooth controllers. + + Say Y here to compile support for Qualcomm protocol. + If unsure, say Y. + config BT_HCIBTSDIO tristate "HCI SDIO driver" depends on MMC diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index 8b436c6de8b7..d5eb2568af2e 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile @@ -52,5 +52,6 @@ hci_uart-$(CONFIG_BT_HCIUART_AML) += hci_aml.o hci_uart-objs := $(hci_uart-y) btusb-y := btusb_main.o +btusb-$(CONFIG_BT_HCIBTUSB_QCOM) += btusb_qcom.o CONTEXT_ANALYSIS := y diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 5efcf31e432b..be47ac894b6c 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -29,6 +29,7 @@ #include "btrtl.h" #include "btmtk.h" #include "hci_uart.h" +#include "btusb_qcom.h" #define VERSION "1.0" @@ -70,6 +71,7 @@ static struct usb_driver btusb_driver; #define BTUSB_ACTIONS_SEMI BIT(27) #define BTUSB_BARROT BIT(28) #define BTUSB_BROKEN_EXT_SCAN BIT(29) +#define BTUSB_QUALCOMM BIT(30) static const struct usb_device_id btusb_table[] = { /* @@ -426,6 +428,10 @@ static const struct usb_device_id quirks_table[] = { { USB_DEVICE(0x2c7c, 0x0132), .driver_info = BTUSB_QCA_WCN6855 | BTUSB_WIDEBAND_SPEECH }, + /* Qualcomm multi-subsystem chipset QCC2072 */ + { USB_DEVICE(0x0cf3, 0xea00), .driver_info = BTUSB_QUALCOMM | + BTUSB_WIDEBAND_SPEECH }, + /* Broadcom BCM2035 */ { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, @@ -1396,6 +1402,31 @@ static int btusb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) return 0; } +static int btusb_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) +{ + u8 pkt_type = hci_skb_pkt_type(skb); + int ret; + + switch (pkt_type) { + case HCI_EVENT_PKT: + ret = btusb_recv_event(hdev, skb); + break; + case HCI_ACLDATA_PKT: + ret = btusb_recv_acl(hdev, skb); + break; + case HCI_SCODATA_PKT: + case HCI_ISODATA_PKT: + ret = hci_recv_frame(hdev, skb); + break; + default: + dev_kfree_skb_irq(skb); + ret = -EINVAL; + break; + } + + return ret; +} + /* Dispatch through the btusb_recv_* wrappers so that vendor specific * handling (data->recv_event, data->recv_acl) is preserved in H:4 mode. */ @@ -4284,6 +4315,68 @@ static struct hci_drv btusb_hci_drv = { .specific_handlers = btusb_hci_drv_specific_handlers, }; +/* + * ============================================================================ + * Qualcomm support + * ============================================================================ + */ + +static int btusb_recv_intr_qcom(struct btusb_data *data, void *buffer, int count) +{ + unsigned long flags; + int err = 0; + + spin_lock_irqsave(&data->rxlock, flags); + data->evt_skb = btusb_qcom_recv_intr(data->hdev, data->evt_skb, buffer, count, + &err); + spin_unlock_irqrestore(&data->rxlock, flags); + + return err; +} + +static int btusb_recv_bulk_qcom(struct btusb_data *data, void *buffer, int count) +{ + unsigned long flags; + int err = 0; + + spin_lock_irqsave(&data->rxlock, flags); + data->acl_skb = btusb_qcom_recv_bulk(data->hdev, data->acl_skb, buffer, count, + &err); + spin_unlock_irqrestore(&data->rxlock, flags); + + return err; +} + +static int btusb_send_vendor_frame_qcom(struct hci_dev *hdev, struct sk_buff *skb) +{ + u8 pkt_type = hci_skb_pkt_type(skb); + struct urb *urb; + + switch (pkt_type) { + case QPERI_COMMAND_PKT: + urb = alloc_ctrl_urb(hdev, skb); + break; + + case QPERI_ACLDATA_PKT: + urb = alloc_bulk_urb(hdev, skb); + break; + + default: + return -EILSEQ; + } + + if (IS_ERR(urb)) + return PTR_ERR(urb); + + return submit_or_queue_tx_urb(hdev, urb); +} + +/* + * ============================================================================ + * Qualcomm support end + * ============================================================================ + */ + static int btusb_probe(struct usb_interface *intf, const struct usb_device_id *id) { @@ -4414,6 +4507,9 @@ static int btusb_probe(struct usb_interface *intf, } else if (id->driver_info & BTUSB_QCA_WCN6855) { /* Allocate extra space for QCA WCN6855 device */ priv_size += sizeof(struct btqca_data); + } else if (id->driver_info & BTUSB_QUALCOMM) { + /* Allocate extra space for Qualcomm device */ + priv_size += btusb_qcom_hdev_priv_size(); } data->recv_acl = hci_recv_frame; @@ -4572,6 +4668,31 @@ static int btusb_probe(struct usb_interface *intf, hci_set_msft_opcode(hdev, 0xFD70); } + if (id->driver_info & BTUSB_QUALCOMM) { + struct btusb_qcom *xport_data; + + if (!IS_ENABLED(CONFIG_BT_HCIBTUSB_QCOM)) { + err = -ENODEV; + bt_dev_err(hdev, "CONFIG_BT_HCIBTUSB_QCOM not enabled"); + goto err_kill_tx_urbs; + } + + xport_data = btusb_qcom_xport_data(hdev); + xport_data->reset_gpio = data->reset_gpio; + xport_data->prepare_reset = btusb_prepare_reset; + xport_data->recv_bt_frame = btusb_recv_frame; + xport_data->send_bt_frame = btusb_send_frame; + xport_data->send_vendor_frame = btusb_send_vendor_frame_qcom; + + data->recv_intr = btusb_recv_intr_qcom; + data->recv_bulk = btusb_recv_bulk_qcom; + data->disconnect = btusb_qcom_disconnect; + + hdev->manufacturer = 0x1d; + hdev->send = btusb_qcom_send_frame; + hdev->setup = btusb_qcom_setup; + } + if (id->driver_info & BTUSB_AMP) { /* AMP controllers do not support SCO packets */ data->isoc = NULL; diff --git a/drivers/bluetooth/btusb_qcom.c b/drivers/bluetooth/btusb_qcom.c new file mode 100644 index 000000000000..cc4cfcde2afa --- /dev/null +++ b/drivers/bluetooth/btusb_qcom.c @@ -0,0 +1,4557 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Qualcomm Bluetooth USB transport-specific support + * + * Abbreviations: + * BTC - BT controller + * PERI - Peripheral subsystem of a multi-subsys BTC + * TME-L - Trust Management Engine Lite subsystem of a multi-subsys BTC + * DFU - Device Firmware Update + * EDL - Embedded Downloader + * TLV - Type-Length-Value, a firmware file format + * VSC - Vendor-Specific Command + * VSE - Vendor-Specific Event + * CCE - Command Complete Event + * CSE - Command Status Event + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "btusb_qcom.h" + +/* + * ============================================================================ + * Supported BTCs and their configuration + * ============================================================================ + */ + +/* + * enum qbtc_category - driver-perspective BTC category + * @QBTC_CAT_LEGACY: legacy + * @QBTC_CAT_UNIFIED: unified HCI, VSC gets CCE as response + * @QBTC_CAT_MSUBSYS: multi-subsys, always has PERI + * @QBTC_CAT_MAX: number of categories + */ +enum qbtc_category { + QBTC_CAT_LEGACY, + QBTC_CAT_UNIFIED, + QBTC_CAT_MSUBSYS, + QBTC_CAT_MAX, +}; + +static const char *qbtc_category_name(int category) +{ + const char *category_name = "unknown"; + + switch (category) { + case QBTC_CAT_LEGACY: + category_name = "legacy"; + break; + case QBTC_CAT_UNIFIED: + category_name = "unified"; + break; + case QBTC_CAT_MSUBSYS: + category_name = "multi-subsys"; + break; + default: + break; + } + + return category_name; +} + +/* flags for BTC info and default configuration */ + +/* BTC has PERI / TME-L subsystem */ +#define QBT_FLAG_HAS_PERI BIT(0) +#define QBT_FLAG_HAS_TMEL BIT(1) +/* BTC supports AOSP / MSFT vendor extension */ +#define QBT_FLAG_AOSP_EXT BIT(4) +#define QBT_FLAG_MSFT_EXT BIT(5) +/* BTC supports software reset */ +#define QBT_FLAG_SW_RESET BIT(6) +/* BTC supports memdump */ +#define QBT_FLAG_MEMDUMP BIT(7) +/* take foundry as a factor to select NVM */ +#define QBT_FLAG_FOUNDRY_NVM BIT(8) +/* select NVM based on board ID to download */ +#define QBT_FLAG_BID_NVM BIT(9) +/* fall back to the default NVM if no board-ID-specific NVM exists */ +#define QBT_FLAG_NVM_FALLBACK BIT(10) +/* reset PERI HCI by QHCI instead of QDFU */ +#define QBT_FLAG_RESET_PERI_HCI BIT(11) +/* trigger memdump on command timeout */ +#define QBT_FLAG_CMD_TIMEOUT_MEMDUMP BIT(12) +/* reserve bits [31:24] for board-level flags */ +#define QBT_FLAG_BTC_CFG_MASK GENMASK(23, 0) + +/* rare board ID to custom firmware directroy map */ +struct qbtc_bid_fwdir { + u16 board_id; + const char *fw_dir; +}; + +/* + * struct qbtc_info - BTC information and default configuration + * @category: driver-perspective BTC category (legacy/unified/multi-subsys) + * @flags: QBT_FLAG_* — BTC attributes and default configuration + * @fw_dir: firmware folder, "qca" if NULL + * @custom_fw_table: {}-terminated array or NULL + */ +struct qbtc_info { + enum qbtc_category category; + unsigned long flags; + const char *fw_dir; + const struct qbtc_bid_fwdir *custom_fw_table; +}; + +/* + * struct qbtc_id - BTC ID entry in qbtc_id_table[] below + * @rom_version: ID to match against rom_version read from BTC + * @name: human-readable BTC name + * @btc_info: BTC information and default configuration, != NULL + */ +struct qbtc_id { + u32 rom_version; + const char *name; + const struct qbtc_info *btc_info; +}; + +/* multi-subsys BTC here */ +#define QBTC_INFO_FLAGS_MSUBSYS (QBT_FLAG_HAS_PERI | QBT_FLAG_AOSP_EXT | \ + QBT_FLAG_MSFT_EXT | QBT_FLAG_SW_RESET | \ + QBT_FLAG_MEMDUMP | QBT_FLAG_BID_NVM | \ + QBT_FLAG_NVM_FALLBACK | QBT_FLAG_CMD_TIMEOUT_MEMDUMP) + +static const struct qbtc_info qbtc_msubsys_qcc2072 = { + .category = QBTC_CAT_MSUBSYS, + .flags = QBTC_INFO_FLAGS_MSUBSYS, + .fw_dir = "qca/QCC2072", +}; + +static const struct qbtc_id qbtc_id_table[] = { + { 0x00220100, "QCC2072 1.x", &qbtc_msubsys_qcc2072 }, + { } +}; + +/* + * ============================================================================ + * Qualcomm DFU for rampatch/NVM download + * ============================================================================ + */ + +/* QDFU USB vendor command codes (bRequest) */ +#define QDFU_BT_CMD_VSC_REQ_DOWNLOAD_LOCAL 0x01 +#define QDFU_BT_CMD_CHECK_TARGET_STATE 0x05 +#define QDFU_BT_CMD_GET_TARGET_VERSION 0x09 +#define QDFU_BT_CMD_VSC_REQ_DOWNLOAD_REMOTE 0x10 +#define QDFU_BT_CMD_RESET_PERI_HCI 0x11 +#define QDFU_BT_CMD_ACTIVATE_REMOTE_BTSS 0x12 +#define QDFU_BT_CMD_BT_ENABLE_RESET 0x13 + +/* QDFU target status bits (u8 bitmask from QDFU_BT_CMD_CHECK_TARGET_STATE) */ +#define QDFU_BT_STATE_LOADING_LOCAL BIT(3) +#define QDFU_BT_STATE_PATCHED_REMOTE BIT(4) +#define QDFU_BT_STATE_NVMED_REMOTE BIT(5) +#define QDFU_BT_STATE_NVMED_LOCAL BIT(6) +#define QDFU_BT_STATE_PATCHED_LOCAL BIT(7) + +/* QDFU_BT_CMD_GET_TARGET_VERSION response */ +struct qdfu_bt_version { + __le32 rom_version; + __le32 patch_version; + __le32 soc_ver; + __be16 board_id; + __le16 flag; + u8 reserved[4]; +} __packed; + +struct qdfu_bt_id { + u32 rom_version; + u32 patch_version; + u32 soc_id; + u16 board_id; +}; + +static inline int qdfu_recv_vendor_req(struct hci_dev *hdev, u8 request, + u16 value, void *buf, u16 size) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + + return usb_control_msg_recv(xport_data->udev, 0, request, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, + value, 0, buf, size, + USB_CTRL_GET_TIMEOUT, GFP_KERNEL); +} + +static inline int qdfu_send_vendor_req(struct hci_dev *hdev, u8 request, + u16 value, const void *buf, u16 size) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + + return usb_control_msg_send(xport_data->udev, 0, request, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, + value, 0, buf, size, + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); +} + +static int qdfu_vsc_req_download(struct hci_dev *hdev, u8 request, + const void *buf, u16 size) +{ + int ret; + + if (request != QDFU_BT_CMD_VSC_REQ_DOWNLOAD_LOCAL && + request != QDFU_BT_CMD_VSC_REQ_DOWNLOAD_REMOTE) { + bt_dev_err(hdev, + "QDFU download invalid request code 0x%02x", request); + return -EINVAL; + } + + ret = qdfu_send_vendor_req(hdev, request, 0, buf, size); + if (ret) + bt_dev_err(hdev, + "QDFU download request 0x%02x failed: %pe", + request, ERR_PTR(ret)); + + return ret; +} + +static int qdfu_get_target_state(struct hci_dev *hdev, u8 *state_ptr) +{ + u8 state; + int ret; + + ret = qdfu_recv_vendor_req(hdev, QDFU_BT_CMD_CHECK_TARGET_STATE, 0, + &state, sizeof(state)); + if (!ret) + *state_ptr = state; + else + bt_dev_err(hdev, + "QDFU get target state failed: %pe", + ERR_PTR(ret)); + + return ret; +} + +static int qdfu_get_target_version(struct hci_dev *hdev, struct qdfu_bt_id *id_info) +{ + struct qdfu_bt_version dfu_ver; + u16 board_id = 0; + int ret; + + ret = qdfu_recv_vendor_req(hdev, QDFU_BT_CMD_GET_TARGET_VERSION, 0, + &dfu_ver, sizeof(dfu_ver)); + if (ret) { + bt_dev_err(hdev, + "QDFU get target version failed: %pe", + ERR_PTR(ret)); + return ret; + } + + id_info->rom_version = le32_to_cpu(dfu_ver.rom_version); + id_info->patch_version = le32_to_cpu(dfu_ver.patch_version); + id_info->soc_id = le32_to_cpu(dfu_ver.soc_ver); + + if ((le16_to_cpu(dfu_ver.flag) >> 8) == 0x80) + board_id = be16_to_cpu(dfu_ver.board_id); + + /* Take 0xffff as invalid board ID */ + if (board_id == 0xffff) + board_id = 0; + + id_info->board_id = board_id; + + return 0; +} + +static int qdfu_activate_remote_btss(struct hci_dev *hdev, bool on, + unsigned int wait_us) +{ + u8 status = 0; + int ret; + + ret = qdfu_recv_vendor_req(hdev, QDFU_BT_CMD_ACTIVATE_REMOTE_BTSS, on, + &status, sizeof(status)); + if (ret) { + bt_dev_err(hdev, "QDFU turn %s remote BTSS failed: %pe", + str_on_off(on), ERR_PTR(ret)); + return ret; + } + + switch (status) { + case 0: + bt_dev_dbg(hdev, "QDFU Remote BTSS turned %s", str_on_off(on)); + fsleep(wait_us); + break; + case 0x17: + bt_dev_dbg(hdev, "QDFU Remote BTSS already %s", str_on_off(on)); + break; + default: + bt_dev_err(hdev, + "QDFU turn remote BTSS %s failed, unexpected status 0x%02x", + str_on_off(on), status); + ret = -ENODEV; + } + + return ret; +} + +static int qdfu_reset_peri_hci(struct hci_dev *hdev) +{ + int ret; + + ret = qdfu_send_vendor_req(hdev, QDFU_BT_CMD_RESET_PERI_HCI, 0, NULL, 0); + if (ret) { + bt_dev_err(hdev, "PERI HCI reset via QDFU failed: %pe", + ERR_PTR(ret)); + return ret; + } + bt_dev_info(hdev, "PERI HCI reset via QDFU succeeded"); + fsleep(20 * 1000); + + return 0; +} + +static int qdfu_sw_reset(struct hci_dev *hdev) +{ + int ret; + + ret = qdfu_send_vendor_req(hdev, QDFU_BT_CMD_BT_ENABLE_RESET, 0, NULL, 0); + /* SW reset succeeds even if the request returns an error code */ + if (ret) + bt_dev_dbg(hdev, "QDFU SW reset failed: %pe", ERR_PTR(ret)); + + bt_dev_info(hdev, "QDFU SW reset succeeded"); + + return 0; +} + +/* + * qdfu_poll_state - wait for DFU target status flags to reach a wanted state + * @hdev: the HCI device to poll + * @state_ptr: optional storage for the last status read; may be NULL + * @set: true to wait until @flags are all set, false until all cleared + * @flags: the status flag bits to wait on + * + * Repeatedly reads the DFU target status until @flags reach the requested + * state, a status read fails, or the overall timeout expires. + * + * Return: 0 on success, -ETIMEDOUT on timeout, or a negative errno on read + * failure. + */ +static int qdfu_poll_state(struct hci_dev *hdev, u8 *state_ptr, bool set, u8 flags) +{ + int err, ret; + u8 dfu_state; + + if (!state_ptr) + state_ptr = &dfu_state; + + ret = read_poll_timeout(qdfu_get_target_state, err, + err || (set ? (*state_ptr & flags) == flags + : !(*state_ptr & flags)), + 5 * 1000, + 3000 * 1000, true, + hdev, state_ptr); + if (ret) { + bt_dev_err(hdev, + "Timed out waiting for QDFU state flags 0x%02x to be %s: %pe", + flags, set ? "set" : "cleared", ERR_PTR(ret)); + return ret; + } + + return err; +} + +static inline int qdfu_reset_msubsys_bt(struct hci_dev *hdev) +{ + int ret; + + ret = qdfu_activate_remote_btss(hdev, false, 100 * 1000); + if (!ret) + ret = qdfu_activate_remote_btss(hdev, true, 100 * 1000); + if (!ret) + bt_dev_info(hdev, "QDFU reset msubsys BT succeeded"); + + return ret; +} + +/* + * ============================================================================ + * Common definitions, per-device struct btqcom_data, and PERI frame format + * ============================================================================ + */ + +/* BTC version, read out via an HCI command */ +struct qhci_btc_ver { + u32 product_id; + u32 soc_ver; + u16 rom_ver; + u16 patch_ver; + u8 sec_ver; +}; + +/* Subsystem field appears in a PERI command/response/event */ +enum qhci_subsys { + QHCI_SUBSYS_PERI, + QHCI_SUBSYS_BT, + QHCI_SUBSYS_UWB, + QHCI_SUBSYS_TMEL, + QHCI_SUBSYS_MAX, +}; + +/* + * The pseudo QHCI subsys: for BT-only BTC, or when the memdump comes + * from the BT channel (HCI_EVENT_PKT or HCI_ACLDATA_PKT) on a msubsys + * BTC, there is no real subsys — it stands in for these cases. + */ +#define QHCI_SUBSYS_INVALID QHCI_SUBSYS_MAX + +static const char *qhci_subsys_name(int subsys) +{ + const char *subsys_name = "unknown"; + + switch (subsys) { + case QHCI_SUBSYS_PERI: + subsys_name = "PERI"; + break; + case QHCI_SUBSYS_BT: + subsys_name = "PERI_BT"; + break; + case QHCI_SUBSYS_UWB: + subsys_name = "UWB"; + break; + case QHCI_SUBSYS_TMEL: + subsys_name = "TME-L"; + break; + case QHCI_SUBSYS_INVALID: + subsys_name = "BT"; + break; + default: + break; + } + + return subsys_name; +} + +/* BTC subsystems we care about that support the BT function unit */ +enum qbtc_subsys { + QBTC_SUBSYS_PERI, + QBTC_SUBSYS_TMEL, + QBTC_SUBSYS_MAX, +}; + +/* + * The pseudo BTC subsys stands in for the BT function unit, not a + * real subsys, when building a firmware file path. + */ +#define QBTC_SUBSYS_INVALID QBTC_SUBSYS_MAX + +static const char *qbtc_subsys_name(int subsys) +{ + const char *subsys_name = "unknown"; + + switch (subsys) { + case QBTC_SUBSYS_PERI: + subsys_name = "PERI"; + break; + case QBTC_SUBSYS_TMEL: + subsys_name = "TME-L"; + break; + case QBTC_SUBSYS_INVALID: + subsys_name = "BT"; + break; + default: + break; + } + + return subsys_name; +} + +/* + * struct qbtc_subsys_data - per-subsys data + * @ver: subsys version + * @board_id: subsys board ID + * @build_info: the subsys firmware's build info string + */ +struct qbtc_subsys_data { + struct qhci_btc_ver ver; + u16 board_id; + char build_info[160]; +}; + +/* simple command payload */ +struct qhci_cp_simple { + u8 sub_opcode; +} __packed; + +/* simple CCE(response) payload */ +struct qhci_rp_simple { + u8 status; +} __packed; + +/* generic CCE(response) payload */ +struct qhci_rp_generic { + u8 status; + u8 sub_opcode; +} __packed; + +/* common VSE payload */ +struct qhci_vse_comm { + u8 ev_class; + u8 ev_type; +} __packed; +#define QHCI_VSE_COMM_SIZE (sizeof(struct qhci_vse_comm)) + +#define QHCI_MEMDUMP_SEQ_LAST 0xFFFF +#define QBT_EV_CLASS_DATALOG 0x01 +#define QBT_EV_TYPE_MEMDUMP 0x08 + +/* + * struct qhci_vse_memdump - one memdump segment + * @seqno: segment sequence number; 0 = first, QHCI_MEMDUMP_SEQ_LAST = last + * @subsys: subsystem this segment belongs to (see enum qhci_subsys) + * @segdata: payload of a middle or last segment + * @dump_size: total dump size, valid only in the first segment (@seqno == 0) + * @first_segdata: payload of the first segment, following @dump_size + */ +struct qhci_vse_memdump { + __le16 seqno; + u8 subsys; + union { + u8 segdata[0]; + struct { + __le32 dump_size; + u8 first_segdata[]; + } __packed; + }; +} __packed; + +#define QHCI_MEMDUMP_SEGDATA_GAP \ + (offsetof(struct qhci_vse_memdump, first_segdata) - \ + offsetof(struct qhci_vse_memdump, segdata)) + +enum qhci_req_state { + QHCI_REQ_DONE, + QHCI_REQ_PEND, + QHCI_REQ_CANCELED, + /* unused for now */ + QHCI_REQ_STOP, +}; + +#define QHCI_OPCODE_INVALID HCI_OP_NOP +#define QHCI_SUB_OPCODE_INVALID 0xff +#define QHCI_REQ_EVENT_MAX 2 + +/* + * struct qhci_req_spec - request/response specification + * @opcode: command opcode, ignored if invalid + * @sub_opcode: command sub-opcode, ignored if invalid + * @event: a sequence of events, ending with an invalid marker + */ +struct qhci_req_spec { + u16 opcode; + u8 sub_opcode; + u8 event[QHCI_REQ_EVENT_MAX + 1]; +}; + +/* + * struct qhci_req - per-request data, often stack allocated by the requester + * @pkt_type: the packet type to sync + * @spec: the request spec to sync + * @req_rsp: response skb on success, NULL on no data, or ERR_PTR() on failure + * @req_result: >= 0 an HCI status code, or a negative errno on failure + * @event_idx: cursor into @spec->event + */ +struct qhci_req { + u8 pkt_type; + const struct qhci_req_spec *spec; + struct sk_buff *req_rsp; + int req_result; + u8 event_idx; +}; + +/* board has a BT_EN pin to reset BTC */ +#define QBT_FLAG_HW_RESET BIT(24) + +/* + * enum qbt_work_bit - bits in btqcom_data.work_flags + * @QBT_WORK_RESET_HDEV: request to reset hdev + */ +enum qbt_work_bit { + QBT_WORK_RESET_HDEV, +}; + +/* + * enum qbt_misc_bit - bits in btqcom_data.misc_flags + * @QBT_MISC_MEMDUMP_PERI: PERI memdump + * @QBT_MISC_MEMDUMP_BT: BT memdump + * @QBT_MISC_MEMDUMP_UWB: UWB memdump, never happens here + * @QBT_MISC_MEMDUMP_TMEL: TME-L memdump + * @QBT_MISC_MEMDUMP_INCOMING: memdump is arriving from the BTC + * @QBT_MISC_RESET_ACTIVE: a reset is in progress + * @QBT_MISC_HWERR_PERI: PERI hardware error event happens + * @QBT_MISC_HWERR_BT: BT hardware error event happens + * @QBT_MISC_CMD_TIMEOUT: command timeout happens + * + * The memdump bits are indexed by enum qhci_subsys, so a subsystem's bit can + * be derived from its QHCI subsys value. + */ +enum qbt_misc_bit { + QBT_MISC_MEMDUMP_PERI = QHCI_SUBSYS_PERI, + QBT_MISC_MEMDUMP_BT = QHCI_SUBSYS_BT, + QBT_MISC_MEMDUMP_UWB = QHCI_SUBSYS_UWB, + QBT_MISC_MEMDUMP_TMEL = QHCI_SUBSYS_TMEL, + QBT_MISC_MEMDUMP_INCOMING, + QBT_MISC_RESET_ACTIVE, + QBT_MISC_HWERR_PERI, + QBT_MISC_HWERR_BT, + QBT_MISC_CMD_TIMEOUT, +}; + +/* each subsys's memdump pending flag in btqcom_data.md_pending_flags */ +#define QMD_FLAG_PENDING_PERI BIT(QBT_MISC_MEMDUMP_PERI) +#define QMD_FLAG_PENDING_BT BIT(QBT_MISC_MEMDUMP_BT) +#define QMD_FLAG_PENDING_TMEL BIT(QBT_MISC_MEMDUMP_TMEL) +#define QMD_FLAG_PENDING_MASK (QMD_FLAG_PENDING_PERI | \ + QMD_FLAG_PENDING_BT | \ + QMD_FLAG_PENDING_TMEL) + +static inline int qmd_subsys_to_bit(int qhci_subsys) +{ + return qhci_subsys == QHCI_SUBSYS_INVALID ? + QBT_MISC_MEMDUMP_BT : qhci_subsys; +} + +static inline unsigned long qmd_subsys_to_flag(int qhci_subsys) +{ + return BIT(qmd_subsys_to_bit(qhci_subsys)); +} + +/* + * struct btqcom_memdump - collect memdump from a QHCI subsys + * @size: total memdump size to collect + * @subsys: QHCI subsys this memdump belongs to + * @seqno: next expected sequence number + * @from: which channel this memdump comes from, marked by hci_skb_pkt_type() + * @submit_size: bytes submitted to HCI devcoredump for the subsys + */ +struct btqcom_memdump { + u32 size; + int subsys; + u16 seqno; + u8 from; + + u32 submit_size; +}; + +/* + * struct btqcom_data - transport-independent per-device common data, allocated as hci priv + * @drv_name: driver name + * @btc_name: human-readable BTC name + * @category: driver-perspective BTC category (legacy/unified/multi-subsys) + * @flags: QBT_FLAG_* flags for BTC/board and default config + * @hdev: the owning HCI device + * @xport_data: opaque transport-specific data (e.g. struct btusb_qcom for USB) + * @inited: whether the hdev-lifetime fields are initialized + * @board_id: BT board ID + * @ver: BT version + * @build_info: BT firmware build info string + * @fw_dir: firmware directory configured by user via sysfs + * @fw_logging: firmware logging configured by user via sysfs + * @misc_flags: flags made from QBT_MISC_* bits defined above + * @work_flags: flags made from QBT_WORK_* bits defined above + * @dwork: delayed work to handle @work_flags + * @md_ready: memdump functionality is ready + * @md_state: devcoredump state as notified by the HCI devcoredump core + * @md_submit_err: first error submitting to HCI devcoredump, 0 if none + * @md_submit_size: total bytes submitted to HCI devcoredump, headers included + * @md_pending_flags: QMD_FLAG_PENDING_* flags tracking per-subsystem memdump + * @md: per-subsystem memdump collection track + * @req_mutex: serializes sync requesters + * @req_wait_q: wait queue for the requester + * @req_spinlock: protects @req_state, @req, and @*req + * @req_state: request state, see enum qhci_req_state + * @req: the in-flight request, valid while @req_state is QHCI_REQ_PEND + * @subsys: per-subsystem info for MSUBSYS chips + */ +struct btqcom_data { + const char *drv_name; + const char *btc_name; + enum qbtc_category category; + unsigned long flags; + + struct hci_dev *hdev; + void *xport_data; + + bool inited; + + u16 board_id; + struct qhci_btc_ver ver; + char build_info[160]; + + const char *fw_dir; + u8 fw_logging; + + unsigned long misc_flags; + unsigned long work_flags; + struct delayed_work dwork; + + bool md_ready; + enum devcoredump_state md_state; + int md_submit_err; + u32 md_submit_size; + unsigned long md_pending_flags; + struct btqcom_memdump md; + + struct mutex req_mutex; + wait_queue_head_t req_wait_q; + spinlock_t req_spinlock; + int req_state; + struct qhci_req *req; + + struct qbtc_subsys_data subsys[QBTC_SUBSYS_MAX]; +}; + +/* BT host ID in PERI command/event/ACL */ +#define QHCI_HOST_ID_BT 0 + +struct qperi_command_hdr { + u8 host_id; + __le16 opcode; + u8 plen; +} __packed; +#define QPERI_COMMAND_HDR_SIZE (sizeof(struct qperi_command_hdr)) + +struct qperi_acl_hdr { + u8 host_id; + __le16 handle; + __le16 dlen; +} __packed; +#define QPERI_ACL_HDR_SIZE (sizeof(struct qperi_acl_hdr)) +#define QPERI_MAX_FRAME_SIZE (HCI_MAX_FRAME_SIZE + 1) + +struct qperi_event_hdr { + u8 host_id; + u8 evt; + u8 plen; +} __packed; +#define QPERI_EVENT_HDR_SIZE (sizeof(struct qperi_event_hdr)) +#define QPERI_MAX_EVENT_SIZE (HCI_MAX_EVENT_SIZE + 1) + +static inline struct qperi_event_hdr *qperi_event_header(const struct sk_buff *skb) +{ + return (struct qperi_event_hdr *)skb->data; +} + +static inline struct qperi_acl_hdr *qperi_acl_header(const struct sk_buff *skb) +{ + return (struct qperi_acl_hdr *)skb->data; +} + +static inline __u16 qperi_acl_handle(const struct sk_buff *skb) +{ + struct qperi_acl_hdr *hdr = qperi_acl_header(skb); + + return hci_handle(__le16_to_cpu(hdr->handle)); +} + +static inline __u16 qperi_acl_dlen(const struct sk_buff *skb) +{ + return __le16_to_cpu(qperi_acl_header(skb)->dlen); +} + +static const char *qhci_pkt_type_name(u8 pkt_type) +{ + const char *pkt_type_name = "Unknown"; + + switch (pkt_type) { + case HCI_EVENT_PKT: + pkt_type_name = "BT EVT"; + break; + case QPERI_EVENT_PKT: + pkt_type_name = "PERI EVT"; + break; + case HCI_ACLDATA_PKT: + pkt_type_name = "BT ACL"; + break; + case QPERI_ACLDATA_PKT: + pkt_type_name = "PERI ACL"; + break; + default: + break; + } + + return pkt_type_name; +} + +static void btusb_qcom_reset_sync(struct hci_dev *hdev); + +/* + * ============================================================================ + * Multi-subsys memdump design + * ============================================================================ + */ + +/* + * Design compatible with BT-only BTC as well: + * + * Abbreviations: SS - Subsystem, MD - Memdump, HDR - Header + * + * +--------------+-------------+---------+ +-------------+---------+ + * | file HDR | SS_A MD HDR | SS_A | ... | SS_N MD HDR | SS_N | + * | 512B | 512B | MD data | | 512B | MD data | + * | by dmp_hdr() | appended as | | | appended as | | + * | | MD data | | | MD data | | + * +--------------+-------------+---------+ +-------------+---------+ + * + * 1) All SS MDs are collected into a SINGLE file. + * 2) Each SS_X MD HDR records the size of its own MD data. + * 3) On the 1st segment of the 1st SS: call hci_devcd_init() with + * dump_size — for a BT-only BTC, a 512B MD HDR plus the size carried + * in the segment itself; for a multi-subsys BTC, the sum of (a 512B + * MD HDR plus the max MD data size) over every SS. The file HDR is + * not counted, since the HCI devcoredump adds it on top of dump_size. + * 4) On the 1st segment of every SS: call hci_devcd_append() to append + * its 512B MD HDR as ordinary MD data. + * 5) On the last segment of a SS: call hci_devcd_complete() only if + * no other SS's MD is still pending. + * 6) On the hardware error event (either PERI or BT), which always + * comes after all MDs have been reported by the BTC: call + * hci_devcd_complete() there if it has not been called yet, since a + * SS's MD is optional. + */ + +static const u32 btqcom_memdump_maxsize[] = { + [QHCI_SUBSYS_PERI] = SZ_256K, + [QHCI_SUBSYS_BT] = SZ_1M, + [QHCI_SUBSYS_UWB] = 0, + [QHCI_SUBSYS_TMEL] = SZ_256K, + [QHCI_SUBSYS_INVALID] = SZ_1M, +}; + +/* + * btqcom_memdump_hdr_room - helper to fill a memdump header up to 512 bytes + * @skb: the devcoredump header skb to fill + * + * Return: bytes safe to write into @skb. + */ +static int btqcom_memdump_hdr_room(struct sk_buff *skb) +{ + int end_marker_len = sizeof(HCI_DEVCD_HDR_END_MARKER) - 1; + /* + * don't use skb_tailroom(): observed to differ from requested + * alloc_size - skb->len + */ + int avail_room = HCI_DEVCD_HDR_SIZE_MAX - skb->len; + u8 *ptr; + + /* 1 char + '\n' at least */ + if (avail_room >= end_marker_len + 2) + return avail_room - end_marker_len; + + if (avail_room == end_marker_len) + return 0; + + /* Avoid a blank line ('\n\n') in the header */ + skb_trim(skb, HCI_DEVCD_HDR_SIZE_MAX - end_marker_len - 1); + ptr = skb_tail_pointer(skb) - 1; + if (*ptr == '\n') + *ptr = ' '; + skb_put_u8(skb, '\n'); + + return 0; +} + +/* + * btqcom_memdump_hdr - build the 512B memdump header + * @hdev: the HCI device + * @skb: the skb to build the header into + * + * Its 'Memdump Size' field is the size of the following payload. + */ +static void btqcom_memdump_hdr(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + int avail_room = btqcom_memdump_hdr_room(skb); + struct btqcom_memdump *md = &qbt_data->md; + struct qbtc_subsys_data *subsys_data; + char buf[HCI_DEVCD_HDR_SIZE_MAX]; + struct qhci_btc_ver *btc_ver; + const char *build_info; + u16 board_id; + int len = 0; + + if (!avail_room) + return; + + len += scnprintf(buf + len, sizeof(buf) - len, "Header Type: memdump\n"); + len += scnprintf(buf + len, sizeof(buf) - len, "Header Size: %d\n", + HCI_DEVCD_HDR_SIZE_MAX); + len += scnprintf(buf + len, sizeof(buf) - len, "Memdump Size: %u\n", + md->size); + len += scnprintf(buf + len, sizeof(buf) - len, "Channel: %s\n", + qhci_pkt_type_name(md->from)); + len += scnprintf(buf + len, sizeof(buf) - len, "Owner: %s\n", + qhci_subsys_name(md->subsys)); + + switch (md->subsys) { + case QHCI_SUBSYS_PERI: + subsys_data = &qbt_data->subsys[QBTC_SUBSYS_PERI]; + btc_ver = &subsys_data->ver; + board_id = subsys_data->board_id; + build_info = subsys_data->build_info; + break; + case QHCI_SUBSYS_TMEL: + subsys_data = &qbt_data->subsys[QBTC_SUBSYS_TMEL]; + btc_ver = &subsys_data->ver; + board_id = subsys_data->board_id; + build_info = subsys_data->build_info; + break; + default: + btc_ver = &qbt_data->ver; + board_id = qbt_data->board_id; + build_info = qbt_data->build_info; + break; + } + + len += scnprintf(buf + len, sizeof(buf) - len, "SoC Version: 0x%08x\n", + btc_ver->soc_ver); + len += scnprintf(buf + len, sizeof(buf) - len, "ROM Version: 0x%04x\n", + btc_ver->rom_ver); + len += scnprintf(buf + len, sizeof(buf) - len, "Patch Version: 0x%04x\n", + btc_ver->patch_ver); + len += scnprintf(buf + len, sizeof(buf) - len, "Board ID: 0x%04x\n", + board_id); + len += scnprintf(buf + len, sizeof(buf) - len, "Firmware Version: %s\n", + build_info); + + if (len > avail_room) { + bt_dev_warn(hdev, "memdump header truncated (%d -> %d bytes)", + len, avail_room); + len = avail_room; + if (buf[len - 2] == '\n') + buf[len - 2] = ' '; + buf[len - 1] = '\n'; + } + + skb_put_data(skb, buf, len); +} + +/* + * btusb_qcom_memdump_hdr - build the 512B file header + * @hdev: the HCI device + * @skb: the skb to build the header into + * + * Implements the dmp_hdr_t for hci_devcd_register(). + */ +static void btusb_qcom_memdump_hdr(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + struct btqcom_data *qbt_data = hci_get_priv(hdev); + char buf[HCI_DEVCD_HDR_SIZE_MAX]; + const char *vendor = "Qualcomm"; + int avail_room; + int len = 0; + + avail_room = btqcom_memdump_hdr_room(skb); + if (!avail_room) + return; + + len += scnprintf(buf + len, sizeof(buf) - len, "Header Type: file\n"); + len += scnprintf(buf + len, sizeof(buf) - len, "Header Size: %d\n", + HCI_DEVCD_HDR_SIZE_MAX); + len += scnprintf(buf + len, sizeof(buf) - len, "Driver: %s\n", + qbt_data->drv_name); + len += scnprintf(buf + len, sizeof(buf) - len, "Vendor: %s\n", vendor); + len += scnprintf(buf + len, sizeof(buf) - len, "Controller Name: %s\n", + qbt_data->btc_name); + len += scnprintf(buf + len, sizeof(buf) - len, "Controller Category: %s\n", + qbtc_category_name(qbt_data->category)); + + if (qbt_data->category == QBTC_CAT_MSUBSYS) { + if (qbt_data->flags & QBT_FLAG_HAS_TMEL) + len += scnprintf(buf + len, sizeof(buf) - len, + "Controller Subsys: PERI, TME-L\n"); + else + len += scnprintf(buf + len, sizeof(buf) - len, + "Controller Subsys: PERI\n"); + } + len += scnprintf(buf + len, sizeof(buf) - len, "VID: 0x%04x\n", + xport_data->idVendor); + len += scnprintf(buf + len, sizeof(buf) - len, "PID: 0x%04x\n", + xport_data->idProduct); + + if (len > avail_room) + bt_dev_warn(hdev, "dump header truncated (%d -> %d bytes)", + len, avail_room); + + memset(buf + len, 'P', sizeof(buf) - len); + + /* + * Deliberately overfill to skb's full 512 bytes, then leverage + * btqcom_memdump_hdr_room() to trim it back to the expected boundary. + */ + skb_put_data(skb, buf, HCI_DEVCD_HDR_SIZE_MAX - skb->len); + btqcom_memdump_hdr_room(skb); +} + +/* Used as the notify_change_t callback for hci_devcd_register(). */ +static void btusb_qcom_notify_memdump(struct hci_dev *hdev, int state) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + struct btqcom_data *qbt_data = hci_get_priv(hdev); + enum devcoredump_state old_state; + + old_state = qbt_data->md_state; + + bt_dev_dbg(hdev, "memdump notify state: %s -> %s", + hci_devcd_state_name(old_state), + hci_devcd_state_name(state)); + bt_dev_dbg(hdev, "misc_flags: 0x%lx", READ_ONCE(qbt_data->misc_flags)); + bt_dev_dbg(hdev, "md_pending_flags: 0x%lx, md_submit_err: %d", + READ_ONCE(qbt_data->md_pending_flags), + READ_ONCE(qbt_data->md_submit_err)); + + switch (state) { + case HCI_DEVCOREDUMP_IDLE: + break; + case HCI_DEVCOREDUMP_ACTIVE: + usb_autopm_get_interface_no_resume(xport_data->intf); + bt_dev_dbg(hdev, "memdump notify: get autopm refcount"); + break; + case HCI_DEVCOREDUMP_TIMEOUT: + bt_dev_err(hdev, "memdump notify: %s", hci_devcd_state_name(state)); + qbt_data->md_submit_err = -ETIMEDOUT; + qbt_data->md_pending_flags = 0; + test_and_clear_bit(QBT_MISC_MEMDUMP_INCOMING, + &qbt_data->misc_flags); + fallthrough; + case HCI_DEVCOREDUMP_DONE: + case HCI_DEVCOREDUMP_ABORT: + usb_autopm_put_interface_no_suspend(xport_data->intf); + bt_dev_dbg(hdev, "memdump notify: put autopm refcount"); + break; + } + + qbt_data->md_state = state; + + if (state == HCI_DEVCOREDUMP_TIMEOUT) + btusb_qcom_reset_sync(hdev); +} + +/* handle received memdump frame here */ + +static inline void btqcom_reset_memdump(struct btqcom_memdump *md) +{ + memset(md, 0x00, sizeof(*md)); + md->subsys = QHCI_SUBSYS_INVALID; +} + +/* + * btqcom_submit_memdump - submit one memdump segment to HCI devcoredump + * @hdev: the HCI device the memdump comes from + * @skb: the memdump segment payload + * + * See the "Multi-subsys memdump design" block above for the overall scheme + * this implements. + * + * Return: 0 on success, + * 1 if the memdump ended normally, + * a negative errno on failure. + */ +static int btqcom_submit_memdump(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct btqcom_memdump *md = &qbt_data->md; + unsigned int dump_size, seg_len; + bool is_first_subsys = false; + int ret = 0; + + dump_size = 0; + seg_len = skb->len; + + if (md->seqno == 0) { + if (!test_and_set_bit(QBT_MISC_MEMDUMP_INCOMING, + &qbt_data->misc_flags)) { + /* wake the waiter in btusb_do_cmd_timeout_work() */ + wake_up_var(&qbt_data->misc_flags); + is_first_subsys = true; + qbt_data->md_submit_err = 0; + qbt_data->md_submit_size = 0; + if (qbt_data->category == QBTC_CAT_MSUBSYS) { + qbt_data->md_pending_flags = QMD_FLAG_PENDING_BT | + QMD_FLAG_PENDING_PERI; + dump_size = HCI_DEVCD_HDR_SIZE_MAX + + btqcom_memdump_maxsize[QHCI_SUBSYS_BT] + + HCI_DEVCD_HDR_SIZE_MAX + + btqcom_memdump_maxsize[QHCI_SUBSYS_PERI]; + + if (qbt_data->flags & QBT_FLAG_HAS_TMEL) { + qbt_data->md_pending_flags |= QMD_FLAG_PENDING_TMEL; + dump_size += HCI_DEVCD_HDR_SIZE_MAX + + btqcom_memdump_maxsize[QHCI_SUBSYS_TMEL]; + } + } else { + qbt_data->md_pending_flags = QMD_FLAG_PENDING_BT; + dump_size = HCI_DEVCD_HDR_SIZE_MAX + md->size; + } + } + + bt_dev_info(hdev, "%s memdump incoming: %u bytes", + qhci_subsys_name(md->subsys), md->size); + bt_dev_dbg(hdev, "md_pending_flags: 0x%lx", + qbt_data->md_pending_flags); + + if (is_first_subsys) { + ret = hci_devcd_init(hdev, dump_size); + if (ret) { + kfree_skb(skb); + bt_dev_err(hdev, "init memdump failed: %pe", + ERR_PTR(ret)); + return ret; + } + qbt_data->md_submit_size += HCI_DEVCD_HDR_SIZE_MAX; + bt_dev_info(hdev, "file header: %u bytes", + HCI_DEVCD_HDR_SIZE_MAX); + } + + if (!qbt_data->md_submit_err) { + struct sk_buff *hdr_skb; + + hdr_skb = alloc_skb(HCI_DEVCD_HDR_SIZE_MAX, GFP_KERNEL); + if (hdr_skb) { + btqcom_memdump_hdr(hdev, hdr_skb); + if (hdr_skb->len < HCI_DEVCD_HDR_SIZE_MAX) + skb_put_zero(hdr_skb, + HCI_DEVCD_HDR_SIZE_MAX - hdr_skb->len); + ret = hci_devcd_append(hdev, hdr_skb); + } else { + ret = -ENOMEM; + } + if (ret) { + hci_devcd_abort(hdev); + kfree_skb(skb); + bt_dev_err(hdev, "append memdump header failed: %pe", + ERR_PTR(ret)); + return ret; + } + qbt_data->md_submit_size += HCI_DEVCD_HDR_SIZE_MAX; + bt_dev_info(hdev, "%s memdump header appended: %u bytes", + qhci_subsys_name(md->subsys), HCI_DEVCD_HDR_SIZE_MAX); + } + } + + ret = qbt_data->md_submit_err; + if (ret) { + kfree_skb(skb); + } else { + ret = hci_devcd_append(hdev, skb); + if (unlikely(ret)) { + hci_devcd_abort(hdev); + bt_dev_err(hdev, "append memdump failed: %pe", ERR_PTR(ret)); + } else { + md->submit_size += seg_len; + qbt_data->md_submit_size += seg_len; + } + } + + if (md->seqno != QHCI_MEMDUMP_SEQ_LAST) + return ret; + + if (md->submit_size == md->size) + bt_dev_info(hdev, "%s memdump fully collected", + qhci_subsys_name(md->subsys)); + else + bt_dev_err(hdev, "%s memdump partially collected %u/%u bytes", + qhci_subsys_name(md->subsys), md->submit_size, md->size); + + qbt_data->md_pending_flags &= ~qmd_subsys_to_flag(md->subsys); + if (qbt_data->md_pending_flags) { + bt_dev_dbg(hdev, "md_pending_flags: 0x%lx", + qbt_data->md_pending_flags); + return ret; + } + + if (test_and_clear_bit(QBT_MISC_MEMDUMP_INCOMING, &qbt_data->misc_flags)) + bt_dev_dbg(hdev, "clear MEMDUMP_INCOMING on memdump completion"); + + if (ret) { + bt_dev_err(hdev, "memdump complete failed: %pe", ERR_PTR(ret)); + return ret; + } + + ret = hci_devcd_complete(hdev); + if (ret) { + hci_devcd_abort(hdev); + bt_dev_err(hdev, "memdump complete failed: %pe", ERR_PTR(ret)); + } else { + ret = 1; + bt_dev_info(hdev, "memdump completed: %u bytes", + qbt_data->md_submit_size); + } + return ret; +} + +/* + * btqcom_handle_memdump - handle one memdump segment + * @hdev: the HCI device the @skb comes from + * @skb: the memdump segment to handle + * + * Return: 0 on success, + * 1 if the memdump ended normally, + * a negative errno on failure. + */ +static int btqcom_handle_memdump(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct btqcom_memdump *md = &qbt_data->md; + const struct qhci_vse_memdump *md_vse; + u8 pkt_type = hci_skb_pkt_type(skb); + int subsys = QHCI_SUBSYS_INVALID; + u16 seq_no = 0; + u32 dump_size; + int ret = 0; + + md_vse = skb_pull_data(skb, offsetof(struct qhci_vse_memdump, segdata)); + if (!md_vse) { + ret = -EMSGSIZE; + bt_dev_err(hdev, "bad memdump segment: too short (%u bytes)", skb->len); + goto out_abort_md; + } + + if (pkt_type == QPERI_EVENT_PKT || pkt_type == QPERI_ACLDATA_PKT) { + subsys = md_vse->subsys; + if (subsys >= QHCI_SUBSYS_MAX || !btqcom_memdump_maxsize[subsys] || + (subsys == QHCI_SUBSYS_TMEL && + !(qbt_data->flags & QBT_FLAG_HAS_TMEL))) { + kfree_skb(skb); + bt_dev_warn_ratelimited(hdev, + "drop memdump of unsupported subsys %d", + subsys); + return 0; + } + } + + seq_no = le16_to_cpu(md_vse->seqno); + if (seq_no == 0) { + set_bit(qmd_subsys_to_bit(subsys), &qbt_data->misc_flags); + + if (!skb_pull(skb, QHCI_MEMDUMP_SEGDATA_GAP)) { + ret = -EMSGSIZE; + bt_dev_err(hdev, "bad first %s memdump segment: too short for dump_size", + qhci_subsys_name(subsys)); + goto out_abort_md; + } + + dump_size = le32_to_cpu(md_vse->dump_size); + if (!dump_size || dump_size > btqcom_memdump_maxsize[subsys]) { + ret = -EILSEQ; + bt_dev_err(hdev, "wrong %s memdump dump_size: %u", + qhci_subsys_name(subsys), dump_size); + goto out_abort_md; + } + + btqcom_reset_memdump(md); + md->from = pkt_type; + md->subsys = subsys; + md->size = dump_size; + } else { + if (md->subsys != subsys) { + ret = -EILSEQ; + bt_dev_err_ratelimited(hdev, + "wrong memdump subsys: expected(%d), coming(%d)", + md->subsys, subsys); + goto out_abort_md; + } + + if (seq_no == QHCI_MEMDUMP_SEQ_LAST) { + md->seqno = QHCI_MEMDUMP_SEQ_LAST; + } else if (seq_no != md->seqno) { + ret = -EILSEQ; + bt_dev_err_ratelimited(hdev, + "wrong memdump seqno: expected(%u), coming(%u)", + md->seqno, seq_no); + goto out_abort_md; + } + } + + /* @skb is consumed here */ + ret = btqcom_submit_memdump(hdev, skb); + if (seq_no != QHCI_MEMDUMP_SEQ_LAST) + md->seqno = seq_no + 1; + + goto out_reset_md; + +out_abort_md: + kfree_skb(skb); + if (qbt_data->md_pending_flags && !qbt_data->md_submit_err) { + hci_devcd_abort(hdev); + bt_dev_err(hdev, "abort memdump"); + } + +out_reset_md: + if (ret < 0 && !qbt_data->md_submit_err) + qbt_data->md_submit_err = ret; + + if (seq_no == QHCI_MEMDUMP_SEQ_LAST) + btqcom_reset_memdump(md); + + return ret; +} + +/* + * ============================================================================ + * BT-HCI vendor-specific command/response + * ============================================================================ + */ + +/* reserved BT ACL handle for enhanced logging */ +#define QBT_HANDLE_ENHANCED_LOGGING 0xEDC +/* reserved BT ACL handle for memdump */ +#define QBT_HANDLE_MEMDUMP 0xEDD + +/* + * Unless otherwise noted, for the VSCs below: + * - command payload: struct qhci_cp_simple + * - response payload: struct qhci_rp_generic + * + * Grouped by { opcode, sub_opcode, cp, rp }. + */ + +/* BT EDL opcode and its sub-opcodes */ +#define QBT_OP_EDL 0xFC00 + +#define BEDL_PATCH_GETVER 0x19 +struct qbt_rp_patch_getver { + u8 status; + u8 sub_opcode; + u8 dlen; + __le32 product_id; + __le16 patch_ver; + __le16 rom_ver; + __le32 soc_ver; +} __packed; + +#define BEDL_GET_BUILD_INFO 0x20 +struct qbt_rp_get_build_info { + u8 status; + u8 sub_opcode; + u8 dlen; + u8 data[]; +} __packed; + +#define BEDL_GET_BOARD_ID 0x23 +struct qbt_rp_get_board_id { + u8 status; + u8 sub_opcode; + u8 dlen; + __be16 board_id; +} __packed; + +/* BT DEBUG opcode and its sub-opcodes */ +#define QBT_OP_DEBUG 0xFC0C + +#define BDBG_ERROR_FATAL_CMD 0x26 +/* no response */ + +/* BT write BD_ADDR opcode, no sub-opcode */ +#define QBT_OP_WRITE_BD_ADDR 0xFC14 +struct qbt_cp_write_bd_addr { + bdaddr_t bdaddr; +} __packed; + +/* BT firmware logging opcode and its sub-opcodes */ +#define QBT_OP_HOST_LOG 0xFC17 + +#define BHL_ENH_ENABLE_LOG 0x14 +struct qbt_cp_config_fw_logging { + u8 sub_opcode; + u8 flags; +} __packed; + +/* + * QBT_CHECK_RP_GENERIC - sanity check rp @_skb against type @_rp_type + * @_skb: the rp to check + * @_rp_type: the type to interpret @_skb as + * @_sub_opcode: sub_opcode to check @_skb against + * + * It is safe to evaluate @_skb and @_sub_opcode more than once for its + * usages. + * + * To simplify logic, @_skb's length is checked first to keep later field + * accesses safe. + * + * Returns a negative errno on failure, 0 on success, or error status code + * otherwise. + */ +#define QBT_CHECK_RP_GENERIC(_skb, _rp_type, _sub_opcode) \ +({ \ + _rp_type *_rp_ptr; \ + int _err = 0; \ + do { \ + if ((_skb)->len < sizeof(_rp_type)) { \ + _err = -EBADMSG; \ + break; \ + } \ + _rp_ptr = (void *)(_skb)->data; \ + if (_rp_ptr->sub_opcode != (_sub_opcode)) { \ + _err = -EILSEQ; \ + break; \ + } \ + if (_rp_ptr->status) { \ + _err = _rp_ptr->status; \ + break; \ + } \ + } while (0); \ + _err; \ +}) + +/* check the @dlen field on top of QBT_CHECK_RP_GENERIC() */ +#define QBT_CHECK_RP_DLEN(_skb, _rp_type, _sub_opcode) \ +({ \ + _rp_type *_rp_ptr; \ + int _err = 0; \ + do { \ + _err = QBT_CHECK_RP_GENERIC(_skb, _rp_type, _sub_opcode);\ + if (_err) \ + break; \ + _rp_ptr = (void *)(_skb)->data; \ + if ((_skb)->len != offsetofend(_rp_type, dlen) + \ + _rp_ptr->dlen) { \ + _err = -EMSGSIZE; \ + break; \ + } \ + } while (0); \ + _err; \ +}) + +/* + * qbt_edl_patch_getver - read BTC version info + * @hdev: the HCI device to query + * @ver: output version info, filled on success + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qbt_edl_patch_getver(struct hci_dev *hdev, struct qhci_btc_ver *ver) +{ + const struct qhci_cp_simple cp = { .sub_opcode = BEDL_PATCH_GETVER }; + struct qbt_rp_patch_getver *rp; + struct sk_buff *skb; + int err; + + skb = __hci_cmd_sync_ev(hdev, QBT_OP_EDL, sizeof(cp), + &cp, 0, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + goto out; + } + + err = QBT_CHECK_RP_DLEN(skb, struct qbt_rp_patch_getver, cp.sub_opcode); + if (err) + goto out_free_skb; + + rp = (void *)skb->data; + ver->product_id = le32_to_cpu(rp->product_id); + ver->soc_ver = le32_to_cpu(rp->soc_ver); + ver->rom_ver = le16_to_cpu(rp->rom_ver); + ver->patch_ver = le16_to_cpu(rp->patch_ver); + + bt_dev_dbg(hdev, "Product ID :0x%08x", ver->product_id); + bt_dev_dbg(hdev, "SOC Version :0x%08x", ver->soc_ver); + bt_dev_dbg(hdev, "ROM Version :0x%04x", ver->rom_ver); + bt_dev_dbg(hdev, "Patch Version:0x%04x", ver->patch_ver); + + if (ver->soc_ver == 0 || ver->rom_ver == 0) + err = -EILSEQ; + +out_free_skb: + kfree_skb(skb); + + if (err > 0) { + bt_dev_dbg(hdev, "get BT version status error: 0x%02x", + err); + err = -bt_to_errno(err); + } +out: + if (err) + bt_dev_err(hdev, "get BT version failed: %pe", ERR_PTR(err)); + + return err; +} + +/* + * qbt_edl_get_build_info - get BTC build info string + * @hdev: the HCI device to query + * @build_info: output build info string, allocated on success; caller frees + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qbt_edl_get_build_info(struct hci_dev *hdev, char **build_info) +{ + const struct qhci_cp_simple cp = { .sub_opcode = BEDL_GET_BUILD_INFO }; + struct qbt_rp_get_build_info *rp; + struct sk_buff *skb; + int err; + + skb = __hci_cmd_sync_ev(hdev, QBT_OP_EDL, sizeof(cp), + &cp, 0, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + goto out; + } + + err = QBT_CHECK_RP_DLEN(skb, struct qbt_rp_get_build_info, cp.sub_opcode); + if (err) + goto out_free_skb; + + rp = (void *)skb->data; + *build_info = kmemdup_nul(rp->data, rp->dlen, GFP_KERNEL); + if (!*build_info) { + err = -ENOMEM; + goto out_free_skb; + } + + bt_dev_dbg(hdev, "BT build info: %s", *build_info); + +out_free_skb: + kfree_skb(skb); + + if (err > 0) { + bt_dev_err(hdev, "get BT build info status error: 0x%02x", + err); + err = -bt_to_errno(err); + } +out: + if (err) + bt_dev_err(hdev, "get BT build info failed: %pe", ERR_PTR(err)); + + return err; +} + +/* + * qbt_edl_get_board_id - get BTC board ID + * @hdev: the HCI device to query + * @board_id: output board ID, filled on success + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qbt_edl_get_board_id(struct hci_dev *hdev, u16 *board_id) +{ + const struct qhci_cp_simple cp = { .sub_opcode = BEDL_GET_BOARD_ID }; + struct qbt_rp_get_board_id *rp; + struct sk_buff *skb; + int err; + + skb = __hci_cmd_sync_ev(hdev, QBT_OP_EDL, sizeof(cp), + &cp, 0, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + goto out; + } + + err = QBT_CHECK_RP_DLEN(skb, struct qbt_rp_get_board_id, cp.sub_opcode); + if (err) + goto out_free_skb; + + rp = (void *)skb->data; + *board_id = be16_to_cpu(rp->board_id); + /* Take 0xffff as invalid board ID */ + if (*board_id == 0xffff) + *board_id = 0; + + bt_dev_dbg(hdev, "BT Board ID: 0x%04x", *board_id); + +out_free_skb: + kfree_skb(skb); + + if (err > 0) { + bt_dev_dbg(hdev, "get BT board ID status error: 0x%02x", + err); + err = -bt_to_errno(err); + } +out: + if (err) + bt_dev_err(hdev, "get BT board ID failed: %pe", ERR_PTR(err)); + + return err; +} + +/* + * qbt_error_fatal_cmd - trigger a controller-side fatal error for debugging + * @hdev: the HCI device to command + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qbt_error_fatal_cmd(struct hci_dev *hdev) +{ + const struct qhci_cp_simple cp = { .sub_opcode = BDBG_ERROR_FATAL_CMD }; + int err; + + err = __hci_cmd_send(hdev, QBT_OP_DEBUG, sizeof(cp), &cp); + if (err < 0) + bt_dev_err(hdev, "send error fatal cmd failed: %d", err); + else + bt_dev_info(hdev, "send error fatal cmd succeeded"); + + return err; +} + +/* + * qbt_write_bda - set the controller's BD address + * @hdev: the HCI device to configure + * @bdaddr: the address to set + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qbt_write_bda(struct hci_dev *hdev, const bdaddr_t *bdaddr) +{ + struct qbt_cp_write_bd_addr cp; + int err; + + /* The controller expects the address in reversed byte order. */ + baswap(&cp.bdaddr, bdaddr); + + err = __hci_cmd_sync_status(hdev, QBT_OP_WRITE_BD_ADDR, + sizeof(cp), &cp, HCI_INIT_TIMEOUT); + if (err < 0) { + bt_dev_err(hdev, "set BT address failed: %pe", + ERR_PTR(err)); + return err; + } + if (err > 0) { + bt_dev_err(hdev, "set BT address status error: 0x%02x", + err); + return -bt_to_errno(err); + } + + bt_dev_info(hdev, "BT address set to %pMR", bdaddr); + + return 0; +} + +/* + * qbt_config_fw_logging - configure enhanced firmware logging + * @hdev: the HCI device to configure + * @flags: logging configuration flags, normally 1 (enable) or 0 (disable) + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qbt_config_fw_logging(struct hci_dev *hdev, u8 flags) +{ + const struct qbt_cp_config_fw_logging cp = { + .sub_opcode = BHL_ENH_ENABLE_LOG, + .flags = flags, + }; + struct sk_buff *skb; + int err; + + skb = __hci_cmd_sync_ev(hdev, QBT_OP_HOST_LOG, sizeof(cp), + &cp, 0, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + goto out; + } + + err = QBT_CHECK_RP_GENERIC(skb, struct qhci_rp_generic, cp.sub_opcode); + if (err) + goto out_free_skb; + + bt_dev_dbg(hdev, "firmware logging configured (flags=0x%02x)", flags); + +out_free_skb: + kfree_skb(skb); + + if (err > 0) { + bt_dev_dbg(hdev, "firmware logging config status error: 0x%02x", err); + err = -bt_to_errno(err); + } +out: + if (err) + bt_dev_err(hdev, "firmware logging config failed: %pe", ERR_PTR(err)); + + return err; +} + +/* + * ============================================================================ + * qperi_handle_evt(): per-event handler and TX sync event sequence + * ============================================================================ + */ + +#define QPERI_EV_CLASS_PERI 0xF0 +#define QPERI_EV_TYPE_INVALID 0xff + +/* Pass QPERI_EV_TYPE_INVALID as event if no events to sync */ +#define DEFINE_QPERI_REQ_SPEC(specname, _opcode, _sub_opcode, _events...) \ + const struct qhci_req_spec specname = { \ + .opcode = (_opcode), \ + .sub_opcode = (_sub_opcode), \ + .event = { _events, QPERI_EV_TYPE_INVALID }, \ + } + +/* + * struct qperi_evt - per-event helper for qperi_handle_evt() + * + * @handler: event handler, executed before the TX sync event check. + * Return: true if @skb was consumed, false otherwise. + * + * @verify_wakeup: extra verify if @skb belongs to the event sequence being synced. + * + * Pull @skb empty if all its own checks pass and nothing is left for the + * requester to verify, and the requester will get NULL as response, e.g. a + * CSE, or a CCE whose payload has only status, or only status and + * sub_opcode. + * + * Return: 0 if @skb doesn't belong, 1 if it does, or a negative errno if + * @skb is malformed. + */ +struct qperi_evt { + bool (*handler)(struct hci_dev *hdev, struct sk_buff *skb); + int (*verify_wakeup)(struct hci_dev *hdev, struct qhci_req *req, + struct sk_buff *skb); +}; + +#define PERI_EV_CMD_STATUS 0x00 +struct peri_ev_cmd_status { + u8 status; + u8 ncmd; + __le16 opcode; +} __packed; + +#define PERI_EV_CMD_COMPLETE 0x01 +struct peri_ev_cmd_complete { + u8 ncmd; + __le16 opcode; +} __packed; + +#define PERI_EV_SUBSYS_ACTIVATE_COMPLETE 0x02 +struct peri_ev_subsys_activate_complete { + u8 subsys; + u8 action; +} __packed; + +#define PERI_EV_SUBSYS_PATCH_NOTIFICATION 0x03 +struct peri_ev_subsys_patch_notification { + u8 status; + u8 subsys; +} __packed; + +#define PERI_EV_CRASH_DUMP_MEMDUMP 0x04 +/* struct qhci_vse_memdump */ + +#define PERI_EV_HARDWARE_ERROR 0x06 +struct peri_ev_hardware_error { + u8 code; +} __packed; + +/* As qperi_evt::verify_wakeup() for PERI_EV_CMD_STATUS */ +static int peri_verify_cmd_status(struct hci_dev *hdev __maybe_unused, + struct qhci_req *req, struct sk_buff *skb) +{ + const struct peri_ev_cmd_status *ev; + + if (skb->len != sizeof(*ev)) + return -EMSGSIZE; + + ev = (const void *)skb->data; + + if (le16_to_cpu(ev->opcode) != req->spec->opcode) + return 0; + + req->req_result = ev->status; + if (!req->req_result) + skb_pull(skb, sizeof(*ev)); + + return 1; +} + +/* CCE rp payload: [0] status, [1] sub_opcode if present, then rp-specific data if any */ +static int peri_verify_rp_payload(struct hci_dev *hdev __maybe_unused, + struct qhci_req *req, struct sk_buff *skb) +{ + if (!skb->len) + return -EMSGSIZE; + + if (req->spec->sub_opcode != QHCI_SUB_OPCODE_INVALID) { + if (skb->len < 2) + return -EMSGSIZE; + + if (skb->data[1] != req->spec->sub_opcode) + return 0; + } + + req->req_result = skb->data[0]; + if (!req->req_result && skb->len <= 2) + skb_pull(skb, skb->len); + + return 1; +} + +/* As qperi_evt::verify_wakeup() for PERI_EV_CMD_COMPLETE */ +static int peri_verify_cmd_complete(struct hci_dev *hdev, struct qhci_req *req, + struct sk_buff *skb) +{ + const struct peri_ev_cmd_complete *ev; + u16 opcode; + + ev = skb_pull_data(skb, sizeof(*ev)); + if (!ev) + return -EMSGSIZE; + + opcode = le16_to_cpu(ev->opcode); + if (opcode != req->spec->opcode) + return 0; + + hci_skb_opcode(skb) = opcode; + + return peri_verify_rp_payload(hdev, req, skb); +} + +/* As qperi_evt::verify_wakeup() for PERI_EV_SUBSYS_ACTIVATE_COMPLETE */ +static int peri_verify_subsys_activate_complete(struct hci_dev *hdev __maybe_unused, + struct qhci_req *req __maybe_unused, + struct sk_buff *skb) +{ + if (skb->len != sizeof(struct peri_ev_subsys_activate_complete)) + return -EMSGSIZE; + + return 1; +} + +/* As qperi_evt::verify_wakeup() for PERI_EV_SUBSYS_PATCH_NOTIFICATION */ +static int peri_verify_subsys_patch_notification(struct hci_dev *hdev __maybe_unused, + struct qhci_req *req, + struct sk_buff *skb) +{ + const struct peri_ev_subsys_patch_notification *ev; + + if (skb->len != sizeof(*ev)) + return -EMSGSIZE; + + ev = (const void *)skb->data; + req->req_result = ev->status; + + return 1; +} + +/* As qperi_evt::handler() for PERI_EV_CRASH_DUMP_MEMDUMP */ +static bool peri_crash_dump_memdump(struct hci_dev *hdev, struct sk_buff *skb) +{ + btqcom_handle_memdump(hdev, skb); + + return true; +} + +/* As qperi_evt::handler() for PERI_EV_HARDWARE_ERROR */ +static bool peri_hardware_error(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + const struct peri_ev_hardware_error *ev; + u8 code = HCI_ERROR_UNSPECIFIED; + + ev = skb_pull_data(skb, sizeof(*ev)); + if (ev) + code = ev->code; + else + bt_dev_err(hdev, "malformed PERI hardware error event"); + + set_bit(QBT_MISC_HWERR_PERI, &qbt_data->misc_flags); + __hci_reset_dev(hdev, code); + + return false; +} + +static const struct qperi_evt qperi_evt_table[] = { + /* [0x00 = PERI_EV_CMD_STATUS] */ + [PERI_EV_CMD_STATUS] = { + .verify_wakeup = peri_verify_cmd_status, + }, + /* [0x01 = PERI_EV_CMD_COMPLETE] */ + [PERI_EV_CMD_COMPLETE] = { + .verify_wakeup = peri_verify_cmd_complete, + }, + /* [0x02 = PERI_EV_SUBSYS_ACTIVATE_COMPLETE] */ + [PERI_EV_SUBSYS_ACTIVATE_COMPLETE] = { + .verify_wakeup = peri_verify_subsys_activate_complete, + }, + /* [0x03 = PERI_EV_SUBSYS_PATCH_NOTIFICATION] */ + [PERI_EV_SUBSYS_PATCH_NOTIFICATION] = { + .verify_wakeup = peri_verify_subsys_patch_notification, + }, + /* [0x04 = PERI_EV_CRASH_DUMP_MEMDUMP] */ + [PERI_EV_CRASH_DUMP_MEMDUMP] = { + .handler = peri_crash_dump_memdump, + }, + /* [0x06 = PERI_EV_HARDWARE_ERROR] */ + [PERI_EV_HARDWARE_ERROR] = { + .handler = peri_hardware_error, + }, +}; + +/* + * qperi_try_wakeup - check if event @skb with type @ev_type can wake up the requester + * @hdev: the HCI device the event comes from + * @ev_type: the event type + * @skb: the event payload, or NULL on skb clone failure + * + * Note: the caller only cares about the return value rather than the wakeup result. + * + * Return: true if @skb was consumed, false otherwise. + */ +static bool qperi_try_wakeup(struct hci_dev *hdev, u8 ev_type, + struct sk_buff *skb) +{ + const struct qperi_evt *evt = &qperi_evt_table[ev_type]; + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct sk_buff *req_rsp = skb; + struct qhci_req *req; + int res; + + /* fast path */ + if (READ_ONCE(qbt_data->req_state) != QHCI_REQ_PEND) + return false; + + guard(spinlock)(&qbt_data->req_spinlock); + + if (qbt_data->req_state != QHCI_REQ_PEND) + return false; + + req = qbt_data->req; + if (WARN_ON_ONCE(!req) || WARN_ON_ONCE(!req->spec)) + return false; + + if (req->spec->event[req->event_idx] != ev_type) + return false; + + /* skb clone failure */ + if (!skb) { + req->req_result = -ENOMEM; + goto out_wakeup; + } + + /* malformed frame */ + if (!skb->len) { + req->req_result = -EMSGSIZE; + goto out_wakeup; + } + + req->req_result = 0; + if (evt->verify_wakeup) { + res = evt->verify_wakeup(hdev, req, skb); + if (!res) + return false; + + if (res < 0) { + req->req_result = res; + goto out_wakeup; + } + + /* HCI status error */ + if (req->req_result) + goto out_wakeup; + + /* nothing left for the requester to verify */ + if (!req_rsp->len) + req_rsp = NULL; + } + + if (req->spec->event[req->event_idx + 1] != QPERI_EV_TYPE_INVALID) { + req->event_idx++; + return false; + } + +out_wakeup: + if (req->req_result < 0) + req_rsp = NULL; + + req->req_rsp = req_rsp; + if (req->req_result) + bt_dev_err(hdev, "PERI cmd opcode(0x%04x) sub_opcode(0x%02x) failed on ev_type(0x%02x): %d", + req->spec->opcode, req->spec->sub_opcode, ev_type, req->req_result); + qbt_data->req_state = QHCI_REQ_DONE; + wake_up_interruptible(&qbt_data->req_wait_q); + /* test if the requester now owns @skb */ + return req_rsp == skb; +} + +/* + * __qperi_tx_sync_evt - send a frame and sync its event sequence + * @hdev: the HCI device + * @iter: the frame to send, NULL to sync only + * @spec: the request spec to sync, NULL to send only + * @timeout: timeout in jiffies for the sync + * @evt_idx: index of the waking event + * @status: HCI status code if it has one, 0 otherwise + * + * Requires the caller holds qbt_data->req_mutex. + * + * Return: ERR_PTR() on failure, + * NULL on success for send-only or nothing left for the caller to verify, + * the waking event otherwise. + */ +static struct sk_buff *__qperi_tx_sync_evt(struct hci_dev *hdev, + struct iov_iter *iter, + const struct qhci_req_spec *spec, + unsigned int timeout, + u8 *evt_idx, u8 *status) +{ + struct qhci_req req = { .pkt_type = QPERI_EVENT_PKT, .spec = spec }; + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct sk_buff *ret = NULL; + int res = 0, wait_res = 0; + int req_state; + + if (!iter && !spec) + return ERR_PTR(-EINVAL); + + /* send only, no event to sync */ + if (!spec) { + res = hci_send_vendor_frame(hdev, iter); + if (res < 0) { + bt_dev_err(hdev, "send-only PERI frame failed: %pe", ERR_PTR(res)); + return ERR_PTR(res); + } + return NULL; + } + + scoped_guard(spinlock, &qbt_data->req_spinlock) { + qbt_data->req = &req; + qbt_data->req_state = QHCI_REQ_PEND; + } + + if (iter) + res = hci_send_vendor_frame(hdev, iter); + + if (!res) + wait_res = wait_event_interruptible_timeout(qbt_data->req_wait_q, + READ_ONCE(qbt_data->req_state) != + QHCI_REQ_PEND, + timeout); + + scoped_guard(spinlock, &qbt_data->req_spinlock) { + req_state = qbt_data->req_state; + qbt_data->req = NULL; + qbt_data->req_state = QHCI_REQ_DONE; + } + + if (res >= 0) { + switch (req_state) { + case QHCI_REQ_DONE: + res = req.req_result; + break; + case QHCI_REQ_CANCELED: + if (req.req_result < 0) + bt_dev_info(hdev, "PERI cmd opcode(0x%04x) sub_opcode(0x%02x) canceled: %pe", + spec->opcode, spec->sub_opcode, + ERR_PTR(req.req_result)); + else + bt_dev_info(hdev, "PERI cmd opcode(0x%04x) sub_opcode(0x%02x) canceled", + spec->opcode, spec->sub_opcode); + res = req.req_result < 0 ? req.req_result : -ECANCELED; + break; + case QHCI_REQ_PEND: + default: + res = wait_res < 0 ? -EINTR : -ETIMEDOUT; + break; + } + } + + ret = req.req_rsp; + if (res < 0) { + /* log unless qperi_try_wakeup() already did */ + if (res != req.req_result) + bt_dev_err(hdev, "PERI cmd opcode(0x%04x) sub_opcode(0x%02x) failed: %pe", + spec->opcode, spec->sub_opcode, ERR_PTR(res)); + + if (WARN_ON_ONCE(req.req_rsp)) + kfree_skb(req.req_rsp); + + ret = ERR_PTR(res); + } + + if (evt_idx) + *evt_idx = req.event_idx; + if (status) + *status = (u8)req.req_result; + return ret; +} + +/* synchronously cancel pending request with error code @err */ +static void qperi_tx_sync_cancel_sync(struct hci_dev *hdev, int err) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct qhci_req *req; + + guard(spinlock)(&qbt_data->req_spinlock); + + if (qbt_data->req_state != QHCI_REQ_PEND) + return; + + req = qbt_data->req; + if (WARN_ON_ONCE(!req)) + return; + + req->req_result = err; + qbt_data->req = NULL; + qbt_data->req_state = QHCI_REQ_CANCELED; + + wake_up_interruptible(&qbt_data->req_wait_q); +} + +/* + * __qperi_cmd_sync_evt - send a command and sync its event sequence + * @hdev: the HCI device + * @opcode: command opcode, QHCI_OPCODE_INVALID to sync only + * @plen: length of @cp + * @cp: the command payload + * @spec: the request spec to sync, NULL to send only + * @evt_idx: index of the waking event + * @status: HCI status code if it has one, 0 otherwise + * + * Requires the caller holds qbt_data->req_mutex. + * + * Return: ERR_PTR() on failure, + * NULL on success for send-only or nothing left for the caller to verify, + * the waking event otherwise. + */ +static struct sk_buff *__qperi_cmd_sync_evt(struct hci_dev *hdev, + u16 opcode, u32 plen, const void *cp, + const struct qhci_req_spec *spec, + u8 *evt_idx, u8 *status) +{ + u8 pkt_type = QPERI_COMMAND_PKT; + struct qperi_command_hdr cmd_hdr = { + .host_id = QHCI_HOST_ID_BT, + .opcode = cpu_to_le16(opcode), + .plen = (u8)plen, + }; + struct kvec cmd_kv[] = { + { .iov_base = &pkt_type, .iov_len = 1 }, + { .iov_base = &cmd_hdr, .iov_len = sizeof(cmd_hdr) }, + { .iov_base = (void *)cp, .iov_len = plen }, + }; + struct iov_iter iter; + + /* no command to send, sync only */ + if (opcode == QHCI_OPCODE_INVALID) + return __qperi_tx_sync_evt(hdev, NULL, spec, HCI_INIT_TIMEOUT, evt_idx, status); + + iov_iter_kvec(&iter, ITER_SOURCE, cmd_kv, plen ? 3 : 2, + 1 + sizeof(cmd_hdr) + plen); + + return __qperi_tx_sync_evt(hdev, &iter, spec, HCI_INIT_TIMEOUT, evt_idx, status); +} + +static inline struct sk_buff *qperi_cmd_sync_evt(struct hci_dev *hdev, + u16 opcode, u32 plen, const void *cp, + const struct qhci_req_spec *spec, + u8 *evt_idx, u8 *status) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + guard(mutex)(&qbt_data->req_mutex); + + return __qperi_cmd_sync_evt(hdev, opcode, plen, cp, spec, evt_idx, status); +} + +/* + * send a command and sync an event with type @ev_type; + * @cp's first byte is sub_opcode for all commands so far + * + * Requires the caller holds qbt_data->req_mutex. + */ +static struct sk_buff *__qperi_cmd_sync_one_evt(struct hci_dev *hdev, + u16 opcode, u32 plen, const void *cp, + u8 ev_type, u8 *status) +{ + u8 sub_opcode = plen ? *(const u8 *)cp : QHCI_SUB_OPCODE_INVALID; + DEFINE_QPERI_REQ_SPEC(spec, opcode, sub_opcode, ev_type); + + return __qperi_cmd_sync_evt(hdev, opcode, plen, cp, &spec, NULL, status); +} + +static inline struct sk_buff *qperi_cmd_sync_one_evt(struct hci_dev *hdev, + u16 opcode, u32 plen, const void *cp, + u8 ev_type, u8 *status) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + guard(mutex)(&qbt_data->req_mutex); + + return __qperi_cmd_sync_one_evt(hdev, opcode, plen, cp, ev_type, status); +} + +/* + * only wait for an unsolicited event with type @ev_type + * + * Requires the caller holds qbt_data->req_mutex. + */ +static struct sk_buff __maybe_unused *__qperi_wait_one_evt(struct hci_dev *hdev, + u8 ev_type, u8 *status) +{ + DEFINE_QPERI_REQ_SPEC(spec, QHCI_OPCODE_INVALID, QHCI_SUB_OPCODE_INVALID, ev_type); + + return __qperi_tx_sync_evt(hdev, NULL, &spec, HCI_INIT_TIMEOUT, NULL, status); +} + +/* + * handle a received PERI event @skb, called from hdev->recv_vendor_pkt(); + * generic processing first, then the TX sync event, without interfering + */ +static void qperi_handle_evt(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + const struct qhci_vse_comm *vse_comm; + const struct qperi_event_hdr *hdr; + const struct qperi_evt *evt_entry; + /* for qperi_try_wakeup() call below */ + struct sk_buff *orig_skb = NULL; + u8 ev_type; + int res; + + ev_type = QPERI_EV_TYPE_INVALID; + res = -EBADMSG; + hdr = skb_pull_data(skb, QPERI_EVENT_HDR_SIZE); + if (!hdr || hdr->evt != HCI_EV_VENDOR) + goto out_free_skb; + + res = -EILSEQ; + vse_comm = skb_pull_data(skb, QHCI_VSE_COMM_SIZE); + if (!vse_comm || vse_comm->ev_class != QPERI_EV_CLASS_PERI) + goto out_free_skb; + + ev_type = vse_comm->ev_type; + res = -ENOENT; + if (ev_type >= ARRAY_SIZE(qperi_evt_table)) + goto out_free_skb; + + res = 0; + hci_skb_event(skb) = ev_type; + evt_entry = &qperi_evt_table[ev_type]; + + if (evt_entry->handler) { + const struct qhci_req *req; + bool may_wakeup; + + spin_lock(&qbt_data->req_spinlock); + req = qbt_data->req; + may_wakeup = qbt_data->req_state == QHCI_REQ_PEND && + req && req->spec && + req->spec->event[req->event_idx] == ev_type; + spin_unlock(&qbt_data->req_spinlock); + + if (may_wakeup) { + orig_skb = skb_clone(skb, GFP_KERNEL); + if (!orig_skb) + res = -ENOMEM; + } + + if (evt_entry->handler(hdev, skb)) + skb = NULL; + } else { + orig_skb = skb; + skb = NULL; + } + + if (qperi_try_wakeup(hdev, ev_type, orig_skb)) + orig_skb = NULL; + +out_free_skb: + kfree_skb(orig_skb); + kfree_skb(skb); + if (res < 0) + bt_dev_err(hdev, "fails to handle PERI event with type 0x%02x: %pe", + ev_type, ERR_PTR(res)); +} + +/* + * ============================================================================ + * PERI-HCI vendor-specific command/response + * ============================================================================ + */ + +/* reserved PERI ACL handle for enhanced logging */ +#define QPERI_HANDLE_ENHANCED_LOGGING 0xEC0 +/* reserved PERI ACL handle for memdump */ +#define QPERI_HANDLE_MEMDUMP 0xEC1 + +/* + * Unless otherwise noted, for the VSCs below: + * - command payload: struct qhci_cp_simple + * - response payload: struct qhci_rp_generic + * + * Grouped by { opcode, sub_opcode, cp, rp }. + */ + +/* PERI EDL opcode and its sub-opcodes */ +#define QPERI_OP_EDL 0xFFF0 + +#define PEDL_GET_BUILD_INFO 0x09 +struct qperi_cp_generic { + u8 sub_opcode; + u8 subsys; +} __packed; +struct qperi_rp_get_build_info { + u8 status; + u8 sub_opcode; + u8 subsys; + u8 dlen; + u8 data[]; +} __packed; + +/* PERI Generic opcode and its sub-opcodes */ +#define QPERI_OP_GENERIC 0xFFF1 + +#define PGEN_PERI_RESET 0x03 +/* struct qhci_rp_generic */ +/* struct peri_ev_subsys_patch_notification */ + +#define PGEN_INITIATE_BT_CRASH 0x05 +/* struct peri_ev_cmd_status */ + +#define __QPERI_CP_INIT_SUBSYS_0(...) +#define __QPERI_CP_INIT_SUBSYS_1(_subsys, ...) .subsys = (_subsys), + +#define QPERI_CP_INITIALIZER(_sub_opcode, _subsys...) { \ + .sub_opcode = (_sub_opcode), \ + CONCATENATE(__QPERI_CP_INIT_SUBSYS_, COUNT_ARGS(_subsys))(_subsys) \ +} + +/* + * QPERI_CHECK_RP_LEN - check rp @_skb's length and its @dlen + * @_skb: the rp to check + * @_rp_type: the type to interpret @_skb as + * + * It is safe to evaluate @_skb more than once for its usages. + * + * Returns a negative errno on failure, or 0 on success. + */ +#define QPERI_CHECK_RP_LEN(_skb, _rp_type) \ +({ \ + _rp_type *_rp_ptr; \ + int _err = 0; \ + do { \ + if (!(_skb) || (_skb)->len < sizeof(_rp_type)) { \ + _err = -EBADMSG; \ + break; \ + } \ + _rp_ptr = (void *)(_skb)->data; \ + if ((_skb)->len != offsetofend(_rp_type, dlen) + \ + _rp_ptr->dlen) { \ + _err = -EMSGSIZE; \ + break; \ + } \ + } while (0); \ + _err; \ +}) + +/* + * qperi_get_subsys_build_info - get subsystem build info string + * @hdev: the HCI device to query + * @subsys: the subsystem to query + * @build_info: output build info string, allocated on success; caller frees + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qperi_get_subsys_build_info(struct hci_dev *hdev, u8 subsys, + char **build_info) +{ + struct qperi_cp_generic cp = QPERI_CP_INITIALIZER(PEDL_GET_BUILD_INFO, subsys); + struct qperi_rp_get_build_info *rp; + struct sk_buff *skb; + u8 status = 0; + int ret; + + skb = qperi_cmd_sync_one_evt(hdev, QPERI_OP_EDL, sizeof(cp), &cp, + PERI_EV_CMD_COMPLETE, &status); + if (IS_ERR(skb)) + return PTR_ERR(skb); + + if (status) { + ret = -bt_to_errno(status); + goto out_free_skb; + } + + ret = QPERI_CHECK_RP_LEN(skb, struct qperi_rp_get_build_info); + if (ret) + goto out_free_skb; + rp = (void *)skb->data; + + if (rp->subsys != subsys) { + ret = -EILSEQ; + goto out_free_skb; + } + + *build_info = kmemdup_nul(rp->data, rp->dlen, GFP_KERNEL); + ret = *build_info ? 0 : -ENOMEM; + +out_free_skb: + kfree_skb(skb); + + if (ret) + bt_dev_err(hdev, "get %s build info failed: %pe", + qhci_subsys_name(subsys), ERR_PTR(ret)); + else + bt_dev_dbg(hdev, "%s build info: %s", + qhci_subsys_name(subsys), *build_info); + + return ret; +} + +/* + * qperi_hci_reset - reset PERI HCI + * @hdev: the HCI device to reset + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qperi_hci_reset(struct hci_dev *hdev) +{ + DEFINE_QPERI_REQ_SPEC(spec, QPERI_OP_GENERIC, PGEN_PERI_RESET, + PERI_EV_CMD_COMPLETE, PERI_EV_SUBSYS_PATCH_NOTIFICATION); + struct qhci_cp_simple cp = QPERI_CP_INITIALIZER(PGEN_PERI_RESET); + struct sk_buff *skb; + u8 evt_idx = 0; + u8 status = 0; + int ret = 0; + + skb = qperi_cmd_sync_evt(hdev, QPERI_OP_GENERIC, sizeof(cp), &cp, + &spec, &evt_idx, &status); + if (IS_ERR(skb)) + return PTR_ERR(skb); + + if (status) { + ret = -bt_to_errno(status); + } else if (evt_idx == 1) { + const struct peri_ev_subsys_patch_notification *ev; + + ev = skb_pull_data(skb, sizeof(*ev)); + if (ev->subsys != QHCI_SUBSYS_PERI) { + ret = -EILSEQ; + bt_dev_err(hdev, "PERI HCI reset via QHCI failed: wrong subsys %d", + ev->subsys); + } + } + + kfree_skb(skb); + + if (!ret) + bt_dev_info(hdev, "PERI HCI reset via QHCI succeeded"); + + return ret; +} + +/* + * qperi_initiate_bt_crash - initiate a BT subsystem crash + * @hdev: the HCI device + * + * Return: 0 on success, or a negative errno on failure. + */ +static int qperi_initiate_bt_crash(struct hci_dev *hdev) +{ + struct qhci_cp_simple cp = QPERI_CP_INITIALIZER(PGEN_INITIATE_BT_CRASH); + struct sk_buff *skb; + u8 status = 0; + int ret = 0; + + skb = qperi_cmd_sync_one_evt(hdev, QPERI_OP_GENERIC, sizeof(cp), &cp, + PERI_EV_CMD_STATUS, &status); + if (IS_ERR(skb)) + return PTR_ERR(skb); + + if (skb) { + ret = -bt_to_errno(status); + kfree_skb(skb); + } + + if (!ret) + bt_dev_info(hdev, "PERI initiate BT crash succeeded"); + + return ret; +} + +/* + * ============================================================================ + * hdev callbacks + * ============================================================================ + */ + +/* test if a HW or SW reset is available */ +static inline bool btqcom_has_btc_reset(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + return qbt_data->flags & (QBT_FLAG_HW_RESET | QBT_FLAG_SW_RESET); +} + +/* + * btqcom_set_bdaddr - set BD_ADDR + * @hdev: the HCI device + * @bdaddr: the BD_ADDR to set + * + * Implements hdev->set_bdaddr(). + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btqcom_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) +{ + int ret; + + ret = __hci_reset_sync(hdev); + if (ret) { + bt_dev_err(hdev, "HCI reset before setting BD_ADDR failed: %pe", + ERR_PTR(ret)); + return ret; + } + + ret = qbt_write_bda(hdev, bdaddr); + + return ret; +} + +/* + * btqcom_handle_ev_vendor - handle @skb if interested + * @hdev: the HCI device @skb comes from + * @skb: the VSE payload + * + * Implements hdev->handle_ev_vendor(). + * + * Return: true if @skb was handled, false otherwise. + */ +static bool btqcom_handle_ev_vendor(struct hci_dev *hdev, struct sk_buff *skb) +{ + const struct qhci_vse_comm *vse_comm; + u16 vse_id; + + if (skb->len < QHCI_VSE_COMM_SIZE) + return false; + + vse_comm = (const void *)skb->data; + vse_id = vse_comm->ev_class << 8 | vse_comm->ev_type; + + switch (vse_id) { + case (QBT_EV_CLASS_DATALOG << 8) | QBT_EV_TYPE_MEMDUMP: + skb_pull_data(skb, QHCI_VSE_COMM_SIZE); + btqcom_handle_memdump(hdev, skb_get(skb)); + return true; + default: + return false; + } +} + +/* handle a received BT vendor ACL frame */ +static void handle_acl_vendor(struct hci_dev *hdev, struct sk_buff *skb) +{ + const struct qhci_vse_comm *vse_comm; + const struct hci_event_hdr *evt_hdr; + u16 vse_id; + + if (hci_acl_handle(skb) != QBT_HANDLE_MEMDUMP) + goto out_free_skb; + + skb_pull(skb, HCI_ACL_HDR_SIZE); + + evt_hdr = skb_pull_data(skb, HCI_EVENT_HDR_SIZE); + if (!evt_hdr || evt_hdr->evt != HCI_EV_VENDOR) + goto out_free_skb; + + vse_comm = skb_pull_data(skb, QHCI_VSE_COMM_SIZE); + if (!vse_comm) + goto out_free_skb; + + vse_id = vse_comm->ev_class << 8 | vse_comm->ev_type; + + switch (vse_id) { + case (QBT_EV_CLASS_DATALOG << 8) | QBT_EV_TYPE_MEMDUMP: + btqcom_handle_memdump(hdev, skb); + return; + default: + break; + } + +out_free_skb: + kfree_skb(skb); +} + +/* handle a received PERI ACL frame */ +static void qperi_handle_acl(struct hci_dev *hdev, struct sk_buff *skb) +{ + const struct hci_event_hdr *bt_evt_hdr; + const struct qhci_vse_comm *vse_comm; + u8 ev_type; + + if (qperi_acl_handle(skb) != QPERI_HANDLE_MEMDUMP) + goto out_free_skb; + + skb_pull(skb, QPERI_ACL_HDR_SIZE); + + bt_evt_hdr = skb_pull_data(skb, HCI_EVENT_HDR_SIZE); + if (!bt_evt_hdr || bt_evt_hdr->evt != HCI_EV_VENDOR) + goto out_free_skb; + + vse_comm = skb_pull_data(skb, sizeof(*vse_comm)); + if (!vse_comm || vse_comm->ev_class != QPERI_EV_CLASS_PERI) + goto out_free_skb; + + ev_type = vse_comm->ev_type; + switch (ev_type) { + case PERI_EV_CRASH_DUMP_MEMDUMP: + btqcom_handle_memdump(hdev, skb); + return; + default: + break; + } + +out_free_skb: + kfree_skb(skb); +} + +/* Implements hdev->recv_vendor_pkt(). */ +static void btqcom_recv_vendor_pkt(struct hci_dev *hdev, struct sk_buff *skb) +{ + hci_skb_pkt_type(skb) = *(const u8 *)skb_pull_data(skb, 1); + + switch (hci_skb_pkt_type(skb)) { + case QPERI_EVENT_PKT: + qperi_handle_evt(hdev, skb); + break; + case QPERI_ACLDATA_PKT: + qperi_handle_acl(hdev, skb); + break; + case HCI_ACLDATA_PKT: + handle_acl_vendor(hdev, skb); + break; + default: + bt_dev_err(hdev, "unexpected vendor HCI frame with pkt_type 0x%02x", + hci_skb_pkt_type(skb)); + kfree_skb(skb); + break; + } +} + +/* Implements hdev->dump.coredump() for hci_devcd_register(). */ +static void btusb_qcom_trigger_memdump(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + if (qbt_data->category == QBTC_CAT_MSUBSYS) + qperi_initiate_bt_crash(hdev); + else + qbt_error_fatal_cmd(hdev); +} + +/* return 0 on success, or a negative errno on failure */ +static int btusb_qcom_deactivate_msubsys_bt(struct hci_dev *hdev) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + int ret; + + ret = usb_autopm_get_interface(xport_data->intf); + if (ret) { + bt_dev_err(hdev, "get autopm for deactivate BT failed: %pe", ERR_PTR(ret)); + return ret; + } + + ret = qdfu_activate_remote_btss(hdev, false, 100 * 1000); + + usb_autopm_put_interface(xport_data->intf); + + if (!ret) + bt_dev_info(hdev, "deactivate BT succeeded"); + + return ret; +} + +/* return 0 on success, or a negative errno on failure */ +static int btusb_qcom_sw_reset(struct hci_dev *hdev) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + struct btqcom_data *qbt_data = hci_get_priv(hdev); + int ret = -EOPNOTSUPP; + + if (!(qbt_data->flags & QBT_FLAG_SW_RESET)) + return ret; + + ret = usb_autopm_get_interface(xport_data->intf); + if (ret) { + bt_dev_err(hdev, "get autopm for SW reset failed: %pe", ERR_PTR(ret)); + return ret; + } + + ret = qdfu_sw_reset(hdev); + + usb_autopm_put_interface(xport_data->intf); + + return ret; +} + +#define QBT_RESET_TYPE_SYNC "sync" +#define QBT_RESET_TYPE_ASYNC "async" +#define QBT_RESET_TYPE_DIRECT "direct" + +/* + * btusb_do_reset_work - reset the BTC + * @hdev: the HCI device + * @type: QBT_RESET_TYPE_* above, for logging + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_do_reset_work(struct hci_dev *hdev, void *type) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + struct gpio_desc *reset_gpio = xport_data->reset_gpio; + struct btqcom_data *qbt_data = hci_get_priv(hdev); + int ret; + + bt_dev_dbg(hdev, "%s reset: misc_flags(0x%lx)", (char *)type, + READ_ONCE(qbt_data->misc_flags)); + bt_dev_dbg(hdev, "md_state: %s, md_submit_err: %d", + hci_devcd_state_name(READ_ONCE(qbt_data->md_state)), + READ_ONCE(qbt_data->md_submit_err)); + + if (test_and_set_bit(QBT_MISC_RESET_ACTIVE, &qbt_data->misc_flags)) { + bt_dev_info(hdev, "reset already in progress"); + return 0; + } + + if (xport_data->prepare_reset) + xport_data->prepare_reset(hdev); + + if (reset_gpio) { + bt_dev_info(hdev, "hardware reset"); + gpiod_set_value_cansleep(reset_gpio, 0); + fsleep(200 * 1000); + gpiod_set_value_cansleep(reset_gpio, 1); + return 0; + } + + ret = btusb_qcom_sw_reset(hdev); + if (!ret) + return 0; + + ret = usb_autopm_get_interface(xport_data->intf); + if (ret) { + bt_dev_err(hdev, "reset: autopm get failed: %pe", ERR_PTR(ret)); + clear_bit(QBT_MISC_RESET_ACTIVE, &qbt_data->misc_flags); + return ret; + } + usb_autopm_put_interface_no_suspend(xport_data->intf); + + bt_dev_info(hdev, "usb reset"); + /* Clear it here since usb reset isn't guaranteed to succeed. */ + clear_bit(QBT_MISC_RESET_ACTIVE, &qbt_data->misc_flags); + usb_queue_reset_device(xport_data->intf); + + return 0; +} + +static void btusb_qcom_reset_sync(struct hci_dev *hdev) +{ + int res; + + res = hci_cmd_sync_queue_once(hdev, btusb_do_reset_work, QBT_RESET_TYPE_SYNC, NULL); + if (res) + bt_dev_dbg(hdev, "queue reset work failed: %pe", ERR_PTR(res)); + if (!res || res == -EEXIST || res == -ENODEV) + return; + + btusb_do_reset_work(hdev, QBT_RESET_TYPE_DIRECT); +} + +static void btqcom_reset_async(struct hci_dev *hdev, unsigned int delay_ms) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + set_bit(QBT_WORK_RESET_HDEV, &qbt_data->work_flags); + schedule_delayed_work(&qbt_data->dwork, msecs_to_jiffies(delay_ms)); +} + +/* + * btusb_do_cmd_timeout_work - HCI cmd sync work function to handle command timeout + * @hdev: the HCI device + * @data: unused + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_do_cmd_timeout_work(struct hci_dev *hdev, + void *data __maybe_unused) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + unsigned int wait_ms = 0; + int ret = 0; + + if (!(qbt_data->flags & QBT_FLAG_MEMDUMP) || + !(qbt_data->flags & QBT_FLAG_CMD_TIMEOUT_MEMDUMP)) + goto out_reset; + + switch (qbt_data->category) { + case QBTC_CAT_LEGACY: + return -EOPNOTSUPP; + case QBTC_CAT_UNIFIED: + wait_ms = 800; + ret = qbt_error_fatal_cmd(hdev); + break; + case QBTC_CAT_MSUBSYS: + wait_ms = 1200; + ret = qperi_initiate_bt_crash(hdev); + break; + default: + return -EINVAL; + } + + if (ret) + goto out_reset; + + /* + * Command timeout is solved by self-recovery after memdump. + * Testing CMD_TIMEOUT in this wait is only to abandon it + * immediately if required, not a sign the timeout is resolved. + */ + ret = wait_var_event_timeout(&qbt_data->misc_flags, + test_bit(QBT_MISC_MEMDUMP_INCOMING, + &qbt_data->misc_flags) || + !test_bit(QBT_MISC_CMD_TIMEOUT, + &qbt_data->misc_flags), + msecs_to_jiffies(wait_ms)); + if (!test_bit(QBT_MISC_CMD_TIMEOUT, &qbt_data->misc_flags)) { + bt_dev_dbg(hdev, "Flag CMD_TIMEOUT cleared"); + return 0; + } + if (ret) { + bt_dev_dbg(hdev, "trigger memdump on command timeout succeeded"); + return 0; + } + bt_dev_err(hdev, "trigger memdump on command timeout failed"); + +out_reset: + btusb_do_reset_work(hdev, QBT_RESET_TYPE_SYNC); + + return 0; +} + +/* Implements hdev->reset(). */ +static void btusb_qcom_reset(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + bool has_cmd_timeout; + int res; + + has_cmd_timeout = current_work() == &hdev->cmd_timer.work; + bt_dev_info(hdev, "reset triggered by %s", + has_cmd_timeout ? "command timeout" : "user"); + + if (test_bit(QBT_MISC_MEMDUMP_PERI, &qbt_data->misc_flags) || + test_bit(QBT_MISC_MEMDUMP_BT, &qbt_data->misc_flags) || + test_bit(QBT_MISC_MEMDUMP_TMEL, &qbt_data->misc_flags)) { + bt_dev_info(hdev, "reset will happen after memdump"); + return; + } + + if (!has_cmd_timeout) { + btusb_qcom_reset_sync(hdev); + return; + } + + if (test_and_set_bit(QBT_MISC_CMD_TIMEOUT, &qbt_data->misc_flags)) { + bt_dev_info(hdev, "handling command timeout is in progress"); + return; + } + + res = hci_cmd_sync_queue_once(hdev, btusb_do_cmd_timeout_work, NULL, NULL); + if (res) + bt_dev_dbg(hdev, "queue command timeout work failed: %pe", ERR_PTR(res)); + if (!res || res == -EEXIST || res == -ENODEV) + return; + + btqcom_reset_async(hdev, 0); +} + +/* Implements hdev->hw_error(). */ +static void btqcom_hw_error(struct hci_dev *hdev, u8 code) +{ + const char *subsys_name = qhci_subsys_name(QHCI_SUBSYS_PERI); + struct btqcom_data *qbt_data = hci_get_priv(hdev); + int res; + + if (!test_bit(QBT_MISC_HWERR_PERI, &qbt_data->misc_flags)) { + set_bit(QBT_MISC_HWERR_BT, &qbt_data->misc_flags); + subsys_name = qhci_subsys_name(QHCI_SUBSYS_INVALID); + } + + bt_dev_info(hdev, "%s hardware error (0x%02x)", subsys_name, code); + bt_dev_dbg(hdev, "md_pending_flags: 0x%lx", qbt_data->md_pending_flags); + bt_dev_dbg(hdev, "md_submit_err: %d", qbt_data->md_submit_err); + + if (qbt_data->md_pending_flags && !qbt_data->md_submit_err) { + res = hci_devcd_complete(hdev); + if (res) + bt_dev_err(hdev, "memdump complete on %s hardware error failed: %pe", + subsys_name, ERR_PTR(res)); + else + bt_dev_info(hdev, "memdump completed on %s hardware error: %u bytes", + subsys_name, qbt_data->md_submit_size); + } + + qbt_data->md_pending_flags = 0; + + if (test_and_clear_bit(QBT_MISC_MEMDUMP_INCOMING, &qbt_data->misc_flags)) + bt_dev_dbg(hdev, "clear MEMDUMP_INCOMING on %s hardware error", subsys_name); +} + +static int btusb_qcom_shutdown_unified(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + bool had_hwerr, had_memdump; + unsigned int delay_ms = 10; + int ret; + + had_memdump = test_bit(QBT_MISC_MEMDUMP_BT, &qbt_data->misc_flags); + had_hwerr = test_bit(QBT_MISC_HWERR_BT, &qbt_data->misc_flags); + + bt_dev_dbg(hdev, "shutdown: had_memdump %d, had_hwerr %d", + had_memdump, had_hwerr); + + if (!had_hwerr && !had_memdump) { + ret = __hci_reset_sync(hdev); + if (ret) + bt_dev_err(hdev, "shutdown: HCI reset failed: %pe", + ERR_PTR(ret)); + else + bt_dev_info(hdev, "shutdown: HCI reset succeeded"); + goto out; + } + + if (!had_memdump) { + ret = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, + HCI_CMD_TIMEOUT); + if (!ret) { + clear_bit(QBT_MISC_HWERR_BT, &qbt_data->misc_flags); + bt_dev_info(hdev, "shutdown: recovered from hardware error via HCI reset"); + goto out; + } + + bt_dev_warn(hdev, "shutdown: HCI reset failed to recover from hardware error: %pe", + ERR_PTR(ret)); + } + + ret = -EIO; + if (had_memdump && !btqcom_has_btc_reset(hdev)) { + bt_dev_info(hdev, "shutdown: BTC will self-recover via re-enumeration"); + return ret; + } + + bt_dev_info(hdev, "shutdown: reset BTC after %u msec", delay_ms); + btqcom_reset_async(hdev, delay_ms); + + return ret; +out: + /* + * The flag is usually already unset here in a normal shutdown; + * clear it just in case. No wake_up_var() is needed since the + * waiter is never waiting at this time. + */ + if (test_and_clear_bit(QBT_MISC_CMD_TIMEOUT, &qbt_data->misc_flags)) + bt_dev_dbg(hdev, "clear CMD_TIMEOUT on shutdown"); + + return ret; +} + +static int btusb_qcom_shutdown_msubsys(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + bool had_peri_hwerr, had_peri_memdump; + bool had_bt_hwerr, had_bt_memdump; + bool had_tmel_memdump; + unsigned int delay_ms; + int ret; + + delay_ms = 10; + had_peri_memdump = test_bit(QBT_MISC_MEMDUMP_PERI, &qbt_data->misc_flags); + had_peri_hwerr = test_bit(QBT_MISC_HWERR_PERI, &qbt_data->misc_flags); + had_bt_memdump = test_bit(QBT_MISC_MEMDUMP_BT, &qbt_data->misc_flags); + had_bt_hwerr = test_bit(QBT_MISC_HWERR_BT, &qbt_data->misc_flags); + had_tmel_memdump = test_bit(QBT_MISC_MEMDUMP_TMEL, &qbt_data->misc_flags); + + bt_dev_dbg(hdev, "shutdown: had_peri_memdump %d, had_peri_hwerr %d", + had_peri_memdump, had_peri_hwerr); + bt_dev_dbg(hdev, "shutdown: had_bt_memdump %d, had_bt_hwerr %d", + had_bt_memdump, had_bt_hwerr); + bt_dev_dbg(hdev, "shutdown: had_tmel_memdump %d", had_tmel_memdump); + + ret = -EIO; + if (had_peri_memdump || had_peri_hwerr || had_tmel_memdump) + goto out_reset; + + ret = btusb_qcom_deactivate_msubsys_bt(hdev); + if (ret && (had_bt_memdump || had_bt_hwerr)) + goto out_reset; + + clear_bit(QBT_MISC_HWERR_BT, &qbt_data->misc_flags); + clear_bit(QBT_MISC_MEMDUMP_BT, &qbt_data->misc_flags); + /* Same as in btusb_qcom_shutdown_unified(). */ + if (test_and_clear_bit(QBT_MISC_CMD_TIMEOUT, &qbt_data->misc_flags)) + bt_dev_dbg(hdev, "clear CMD_TIMEOUT on shutdown"); + + return ret; + +out_reset: + bt_dev_info(hdev, "shutdown: reset BTC after %u msec", delay_ms); + btqcom_reset_async(hdev, delay_ms); + return ret; +} + +/* Implements hdev->shutdown(). */ +static int btusb_qcom_shutdown(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + int ret; + + switch (qbt_data->category) { + case QBTC_CAT_LEGACY: + ret = -EOPNOTSUPP; + break; + case QBTC_CAT_UNIFIED: + ret = btusb_qcom_shutdown_unified(hdev); + break; + case QBTC_CAT_MSUBSYS: + ret = btusb_qcom_shutdown_msubsys(hdev); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +/* + * ============================================================================ + * QDFU firmware downloading + * ============================================================================ + */ + +#define QBT_FW_PATH_MAX 96 + +enum qbt_fw_type { + QBT_FW_TYPE_PATCH, + QBT_FW_TYPE_NVM, + QBT_FW_TYPE_MAX, +}; + +#define QBT_PATCH_TYPE_TLV 0x01 +#define QBT_NVM_TYPE_TLV 0x02 +struct qbt_tlv_file_hdr { + u8 type; + u8 length[3]; +} __packed; + +struct qbt_patch_tlv_hdr { + struct qbt_tlv_file_hdr tlv_hdr; + __le32 total_len; + __le32 patch_data_len; + u8 sign_ver; + u8 sign_algo; + u8 download_cfg; + u8 image_type; + __le16 product_id; + __le16 rom_ver; + __le16 patch_ver; + u8 reserved1[2]; + __le32 anti_rollback_ver; + __le32 serial_low; + __le16 serial_high; + u8 debug_option; + u8 reserved2; + __le32 entry_addr; +} __packed; + +struct qbt_nvm_tlv_hdr { + struct qbt_tlv_file_hdr tlv_hdr; +} __packed; + +/* + * struct qdfu_fw_cfg - QDFU firmware download configuration + * @desc: short description for logging (e.g. "PERI patch", "PERI NVM") + * @format: QBT_PATCH_TYPE_TLV or QBT_NVM_TYPE_TLV + * @hdr_size: TLV header size for @format + * @request: QDFU_BT_CMD_VSC_REQ_DOWNLOAD_(LOCAL|REMOTE) + * @loaded_flag: QDFU_BT_STATE_* flag that marks fw downloaded or not + * @settle_us: default time to wait after download for the BTC to settle + * @get_path: build firmware file path, return number of paths or error + * @check: check firmware, return 0 on success or a negative errno + * @download: download firmware, return 0 on success or a negative errno + * @get_settle_us: get the time to wait for BTC to settle + * @post_download: run after download, return 0 on success or a negative errno + */ +struct qdfu_fw_cfg { + const char *desc; + u8 format; + u8 hdr_size; + u8 request; + u8 loaded_flag; + u32 settle_us; + + int (*get_path)(struct hci_dev *hdev, const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, const struct qdfu_bt_id *ctrl_id, + char path[], size_t size); + + int (*check)(struct hci_dev *hdev, const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, const struct qdfu_bt_id *ctrl_id, + const struct firmware *fw); + + int (*download)(struct hci_dev *hdev, const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, const struct qdfu_bt_id *ctrl_id, + const void *data, size_t size); + + u32 (*get_settle_us)(struct hci_dev *hdev, const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, const struct qdfu_bt_id *ctrl_id); + + int (*post_download)(struct hci_dev *hdev, const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, const struct qdfu_bt_id *ctrl_id); +}; + +static int get_qbtc_subsys(const struct qdfu_fw_cfg *fw_cfg); + +static void qhci_to_qdfu_id(struct qdfu_bt_id *dfu_id, + const struct qhci_btc_ver *hci_ver, u16 board_id) +{ + dfu_id->rom_version = (u32)hci_ver->product_id << 16 | hci_ver->rom_ver; + dfu_id->patch_version = hci_ver->patch_ver; + dfu_id->soc_id = hci_ver->soc_ver; + dfu_id->board_id = board_id; +} + +static void qdfu_to_qhci_id(struct qhci_btc_ver *hci_ver, u16 *board_id, + const struct qdfu_bt_id *dfu_id) +{ + hci_ver->product_id = upper_16_bits(dfu_id->rom_version); + hci_ver->rom_ver = lower_16_bits(dfu_id->rom_version); + hci_ver->patch_ver = (u16)dfu_id->patch_version; + hci_ver->soc_ver = dfu_id->soc_id; + *board_id = dfu_id->board_id; +} + +static int get_qdfu_id_via_hci(struct hci_dev *hdev, + struct qdfu_bt_id *dfu_id) +{ + struct qhci_btc_ver hci_ver; + u16 board_id; + int ret; + + ret = qbt_edl_patch_getver(hdev, &hci_ver); + if (ret) + return ret; + + ret = qbt_edl_get_board_id(hdev, &board_id); + if (ret) + return ret; + + qhci_to_qdfu_id(dfu_id, &hci_ver, board_id); + + return 0; +} + +static const char *get_fw_directory(struct hci_dev *hdev, const struct qbtc_info *info, + const struct qdfu_bt_id *ctrl_id) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + const struct qbtc_bid_fwdir *custom_fwdir; + + if (qbt_data->fw_dir) + return qbt_data->fw_dir; + + if (!info->custom_fw_table) + goto info_fw_dir; + + for (custom_fwdir = info->custom_fw_table; custom_fwdir->board_id; custom_fwdir++) { + if (custom_fwdir->board_id == ctrl_id->board_id) + return custom_fwdir->fw_dir; + } + +info_fw_dir: + if (info->fw_dir) + return info->fw_dir; + + return "qca"; +} + +/* + * btusb_get_patch_path - build the patch firmware file path + * @hdev: the HCI device to build the path for + * @fw_cfg: the firmware download config + * @info: BTC info for this hdev + * @ctrl_id: BTC QDFU ID + * @path: output buffer for the built path + * @size: size of @path + * + * Used as the qdfu_fw_cfg ->get_path() callback. + * + * Return: 1 path written into @path, or a negative errno on failure. + */ +static int btusb_get_patch_path(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, + const struct qdfu_bt_id *ctrl_id, + char path[], size_t size) +{ + const char *fw_dir = get_fw_directory(hdev, info, ctrl_id); + int qbtc_subsys; + int len; + + qbtc_subsys = get_qbtc_subsys(fw_cfg); + + if (qbtc_subsys == QBTC_SUBSYS_INVALID) { + /* BT function unit. */ + len = snprintf(path, size, "%s/rampatch_usb_%08x.bin", + fw_dir, ctrl_id->rom_version); + goto out; + } + + switch (qbtc_subsys) { + case QBTC_SUBSYS_PERI: + len = snprintf(path, size, "%s/peripatch_usb_%08x.bin", + fw_dir, ctrl_id->rom_version); + break; + case QBTC_SUBSYS_TMEL: + return -EOPNOTSUPP; + default: + return -EINVAL; + } + +out: + if (len >= size) + return -ENAMETOOLONG; + + return 1; +} + +/* + * btusb_get_nvm_path - build the NVM firmware file path(s) + * @hdev: the HCI device to build the path for + * @fw_cfg: the firmware download config + * @info: BTC info for this hdev + * @ctrl_id: BTC QDFU ID + * @path: output buffer for the built path(s) + * @size: size of @path + * + * @path may hold two NUL-terminated paths back-to-back: a board-ID path + * followed by a fallback path, when NVM fallback is enabled. + * + * Used as the qdfu_fw_cfg ->get_path() callback. + * + * Return: number of paths (1 or 2) written into @path, or a negative + * errno on failure. + */ +static int btusb_get_nvm_path(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, + const struct qdfu_bt_id *ctrl_id, + char path[], size_t size) +{ + const char *fw_dir = get_fw_directory(hdev, info, ctrl_id); + const char *prefix = NULL, *foundry_str = NULL; + bool has_bid = false, need_fb = false; + char fw_fb[QBT_FW_PATH_MAX] = { 0 }; + int qbtc_subsys; + int len = 0; + + qbtc_subsys = get_qbtc_subsys(fw_cfg); + if (qbtc_subsys == QBTC_SUBSYS_INVALID) { + /* BT function unit. */ + prefix = "nvm_usb"; + } else { + switch (qbtc_subsys) { + case QBTC_SUBSYS_PERI: + prefix = "perinvm_usb"; + break; + case QBTC_SUBSYS_TMEL: + return -EOPNOTSUPP; + default: + return -EINVAL; + } + } + + if (info->flags & QBT_FLAG_FOUNDRY_NVM) { + u8 foundry = FIELD_GET(GENMASK(15, 12), ctrl_id->soc_id); + + switch (foundry) { + /* GlobalFoundries */ + case 0x01: + foundry_str = "_gf"; + break; + default: + break; + } + } + + if ((info->flags & QBT_FLAG_BID_NVM) && ctrl_id->board_id) { + has_bid = true; + if (info->flags & QBT_FLAG_NVM_FALLBACK) + need_fb = true; + } + + len = snprintf(path, size, "%s/%s_%08x", fw_dir, prefix, ctrl_id->rom_version); + if (len >= size) + return -ENAMETOOLONG; + + if (foundry_str) { + len += snprintf(path + len, size - len, "%s", foundry_str); + if (len >= size) + return -ENAMETOOLONG; + } + + if (!has_bid) { + len += snprintf(path + len, size - len, ".bin"); + if (len >= size) + return -ENAMETOOLONG; + return 1; + } + + if (need_fb) { + int fb_len = snprintf(fw_fb, sizeof(fw_fb), "%s.bin", path); + + if (fb_len >= sizeof(fw_fb)) + return -ENAMETOOLONG; + + len += snprintf(path + len, size - len, "_%04x.bin", + ctrl_id->board_id); + if (len >= size) + return -ENAMETOOLONG; + + /* path holds two NUL-terminated strings back-to-back: + * [board-id path '\0'][fallback path '\0'] + * Verify the buffer fits both before writing. + */ + if (len + fb_len + 2 > size) + return -ENAMETOOLONG; + + len += 1; + snprintf(path + len, size - len, "%s", fw_fb); + return 2; + } + + len += snprintf(path + len, size - len, "_%04x.bin", ctrl_id->board_id); + if (len >= size) + return -ENAMETOOLONG; + + return 1; +} + +/* check the TLV file header; return 0 on success, or a negative errno */ +static int qbt_check_tlv_file(struct hci_dev *hdev, const struct firmware *fw, u8 format) +{ + const struct qbt_tlv_file_hdr *tlv_hdr = (const struct qbt_tlv_file_hdr *)fw->data; + size_t file_len; + + if (fw->size < sizeof(*tlv_hdr)) + return -ENODATA; + + if (tlv_hdr->type != format) + return -EINVAL; + + file_len = get_unaligned_le24(tlv_hdr->length) + sizeof(*tlv_hdr); + if (file_len != fw->size) + return -EBADF; + + return 0; +} + +/* + * btusb_check_patch_tlv - validate a patch TLV file against the BTC + * before download + * @hdev: the HCI device to validate the file for + * @fw_cfg: the firmware download config (unused) + * @info: BTC info for this hdev (unused) + * @ctrl_id: BTC QDFU ID + * @fw: the firmware to validate + * + * Used as the qdfu_fw_cfg ->check() callback. + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_check_patch_tlv(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info __maybe_unused, + const struct qdfu_bt_id *ctrl_id, + const struct firmware *fw) +{ + const struct qbt_patch_tlv_hdr *patch_hdr = (const void *)fw->data; + u32 fw_rom_version, fw_patch_version; + int ret; + + ret = qbt_check_tlv_file(hdev, fw, QBT_PATCH_TYPE_TLV); + if (ret) { + bt_dev_err(hdev, "Check %s TLV file header failed: %pe", + fw_cfg->desc, ERR_PTR(ret)); + return ret; + } + + if (fw->size < sizeof(*patch_hdr)) { + bt_dev_err(hdev, "%s header truncated (%zu bytes, header needs %zu)", + fw_cfg->desc, fw->size, sizeof(*patch_hdr)); + return -ENODATA; + } + + if (likely(upper_16_bits(ctrl_id->rom_version))) { + fw_rom_version = (le16_to_cpu(patch_hdr->product_id) << 16) | + le16_to_cpu(patch_hdr->rom_ver); + } else { + bt_dev_warn(hdev, "check %s: invalid rom_version 0x%08x", + fw_cfg->desc, ctrl_id->rom_version); + fw_rom_version = le16_to_cpu(patch_hdr->rom_ver); + } + + fw_patch_version = le16_to_cpu(patch_hdr->patch_ver); + + if (fw_rom_version != ctrl_id->rom_version) { + bt_dev_err(hdev, + "%s ROM version 0x%08x does not match controller 0x%08x", + fw_cfg->desc, fw_rom_version, ctrl_id->rom_version); + return -EINVAL; + } + + if (fw_patch_version < ctrl_id->patch_version) { + bt_dev_err(hdev, + "%s version 0x%x older than controller 0x%x, anti-rollback", + fw_cfg->desc, fw_patch_version, ctrl_id->patch_version); + return -EPERM; + } + + return 0; +} + +/* + * validate a NVM TLV file against the BTC + * Used as the qdfu_fw_cfg ->check() callback. + */ +static int btusb_check_nvm_tlv(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info __maybe_unused, + const struct qdfu_bt_id *ctrl_id __maybe_unused, + const struct firmware *fw) +{ + int ret; + + ret = qbt_check_tlv_file(hdev, fw, QBT_NVM_TYPE_TLV); + if (ret) { + bt_dev_err(hdev, "Check %s TLV file header failed: %pe", + fw_cfg->desc, ERR_PTR(ret)); + return ret; + } + + return 0; +} + +/* + * btusb_download_via_qdfu - download a firmware image via QDFU to BTC + * @hdev: the HCI device to send the firmware to + * @fw_cfg: the firmware download config + * @info: BTC info for this hdev (unused) + * @ctrl_id: BTC QDFU ID (unused) + * @fw_data: the firmware image to send, header included + * @fw_size: size of @fw_data + * + * Used as the qdfu_fw_cfg ->download() callback. + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_download_via_qdfu(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info __maybe_unused, + const struct qdfu_bt_id *ctrl_id __maybe_unused, + const void *fw_data, size_t fw_size) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + unsigned int pipe = usb_sndbulkpipe(xport_data->udev, 0x02); + const unsigned int xfer_timeout_ms = 3000; + const size_t xfer_size = SZ_4K; + const u8 *base = fw_data; + const u8 *ptr = fw_data; + size_t seg_size, size; + int snd_len, ret; + u8 *buf; + + ret = qdfu_vsc_req_download(hdev, fw_cfg->request, ptr, fw_cfg->hdr_size); + if (ret) + return ret; + + ptr += fw_cfg->hdr_size; + size = fw_size - fw_cfg->hdr_size; + + /* ep2 needs time to switch from ACL to DFU function mode. */ + fsleep(20 * 1000); + + buf = kmalloc(xfer_size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + while (size) { + seg_size = min_t(size_t, size, xfer_size); + memcpy(buf, ptr, seg_size); + + snd_len = 0; + ret = usb_bulk_msg(xport_data->udev, pipe, buf, seg_size, &snd_len, + xfer_timeout_ms); + if (ret < 0) { + bt_dev_err(hdev, + "QDFU bulk send failed at offset %zu: %pe", + ptr - base, ERR_PTR(ret)); + break; + } + + if (seg_size != snd_len) { + bt_dev_err(hdev, + "QDFU bulk short write (%d of %zu bytes) at offset %zu", + snd_len, seg_size, ptr - base); + ret = -EIO; + break; + } + + ptr += seg_size; + size -= seg_size; + } + + kfree(buf); + return ret; +} + +/* + * Used as the qdfu_fw_cfg ->get_settle_us() callback. + * Kept here for future per-BTC settle time use. + */ +static u32 btusb_get_settle_us(struct hci_dev *hdev __maybe_unused, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info __maybe_unused, + const struct qdfu_bt_id *ctrl_id __maybe_unused) +{ + return fw_cfg->settle_us; +} + +/* Used as the qdfu_fw_cfg ->post_download() callback. */ +static int btusb_post_download_unified_bt(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg __maybe_unused, + const struct qbtc_info *info __maybe_unused, + const struct qdfu_bt_id *ctrl_id __maybe_unused) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + char *build_info = NULL; + int ret; + + ret = qbt_edl_get_build_info(hdev, &build_info); + if (!ret) { + strscpy(qbt_data->build_info, build_info, sizeof(qbt_data->build_info)); + kfree(build_info); + } + + ret = __hci_reset_sync(hdev); + if (ret) + bt_dev_err(hdev, "HCI reset after BT NVM download failed: %pe", ERR_PTR(ret)); + else + bt_dev_info(hdev, "HCI reset after BT NVM download succeeded"); + + return ret; +} + +/* Used as the qdfu_fw_cfg ->post_download() callback. */ +static int btusb_post_download_msubsys_peri(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg __maybe_unused, + const struct qbtc_info *info __maybe_unused, + const struct qdfu_bt_id *ctrl_id __maybe_unused) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct qbtc_subsys_data *subsys_data; + char *build_info = NULL; + int ret; + + subsys_data = &qbt_data->subsys[QBTC_SUBSYS_PERI]; + + ret = qperi_get_subsys_build_info(hdev, QHCI_SUBSYS_PERI, &build_info); + if (!ret) { + strscpy(subsys_data->build_info, build_info, sizeof(subsys_data->build_info)); + kfree(build_info); + } + + /* Resetting PERI HCI is only allowed after downloading PERI NVM. */ + if (qbt_data->flags & QBT_FLAG_RESET_PERI_HCI) + ret = qperi_hci_reset(hdev); + else + ret = qdfu_reset_peri_hci(hdev); + + return ret; +} + +static const struct qdfu_fw_cfg qdfu_fw_cfgs_bt[QBTC_CAT_MAX][QBT_FW_TYPE_MAX] = { + [QBTC_CAT_UNIFIED][QBT_FW_TYPE_PATCH] = { + .desc = "patch", + .format = QBT_PATCH_TYPE_TLV, + .hdr_size = sizeof(struct qbt_patch_tlv_hdr), + .request = QDFU_BT_CMD_VSC_REQ_DOWNLOAD_LOCAL, + .loaded_flag = QDFU_BT_STATE_PATCHED_LOCAL, + .settle_us = 10 * 1000, + .get_path = btusb_get_patch_path, + .check = btusb_check_patch_tlv, + .download = btusb_download_via_qdfu, + .get_settle_us = btusb_get_settle_us, + .post_download = NULL, + }, + [QBTC_CAT_UNIFIED][QBT_FW_TYPE_NVM] = { + .desc = "NVM", + .format = QBT_NVM_TYPE_TLV, + .hdr_size = sizeof(struct qbt_nvm_tlv_hdr), + .request = QDFU_BT_CMD_VSC_REQ_DOWNLOAD_LOCAL, + .loaded_flag = QDFU_BT_STATE_NVMED_LOCAL, + .settle_us = 40 * 1000, + .get_path = btusb_get_nvm_path, + .check = btusb_check_nvm_tlv, + .download = btusb_download_via_qdfu, + .get_settle_us = btusb_get_settle_us, + .post_download = btusb_post_download_unified_bt, + }, + [QBTC_CAT_MSUBSYS][QBT_FW_TYPE_PATCH] = { + .desc = "BT patch", + .format = QBT_PATCH_TYPE_TLV, + .hdr_size = sizeof(struct qbt_patch_tlv_hdr), + .request = QDFU_BT_CMD_VSC_REQ_DOWNLOAD_REMOTE, + .loaded_flag = QDFU_BT_STATE_PATCHED_REMOTE, + .settle_us = 30 * 1000, + .get_path = btusb_get_patch_path, + .check = btusb_check_patch_tlv, + .download = btusb_download_via_qdfu, + .get_settle_us = btusb_get_settle_us, + .post_download = NULL, + }, + [QBTC_CAT_MSUBSYS][QBT_FW_TYPE_NVM] = { + .desc = "BT NVM", + .format = QBT_NVM_TYPE_TLV, + .hdr_size = sizeof(struct qbt_nvm_tlv_hdr), + .request = QDFU_BT_CMD_VSC_REQ_DOWNLOAD_REMOTE, + .loaded_flag = QDFU_BT_STATE_NVMED_REMOTE, + .settle_us = 60 * 1000, + .get_path = btusb_get_nvm_path, + .check = btusb_check_nvm_tlv, + .download = btusb_download_via_qdfu, + .get_settle_us = btusb_get_settle_us, + .post_download = btusb_post_download_unified_bt, + }, +}; + +static const struct qdfu_fw_cfg qdfu_fw_cfgs_subsys[QBTC_SUBSYS_MAX][QBT_FW_TYPE_MAX] = { + [QBTC_SUBSYS_PERI][QBT_FW_TYPE_PATCH] = { + .desc = "PERI patch", + .format = QBT_PATCH_TYPE_TLV, + .hdr_size = sizeof(struct qbt_patch_tlv_hdr), + .request = QDFU_BT_CMD_VSC_REQ_DOWNLOAD_LOCAL, + .loaded_flag = QDFU_BT_STATE_PATCHED_LOCAL, + .settle_us = 10 * 1000, + .get_path = btusb_get_patch_path, + .check = btusb_check_patch_tlv, + .download = btusb_download_via_qdfu, + .get_settle_us = btusb_get_settle_us, + .post_download = NULL, + }, + [QBTC_SUBSYS_PERI][QBT_FW_TYPE_NVM] = { + .desc = "PERI NVM", + .format = QBT_NVM_TYPE_TLV, + .hdr_size = sizeof(struct qbt_nvm_tlv_hdr), + .request = QDFU_BT_CMD_VSC_REQ_DOWNLOAD_LOCAL, + .loaded_flag = QDFU_BT_STATE_NVMED_LOCAL, + .settle_us = 20 * 1000, + .get_path = btusb_get_nvm_path, + .check = btusb_check_nvm_tlv, + .download = btusb_download_via_qdfu, + .get_settle_us = btusb_get_settle_us, + .post_download = btusb_post_download_msubsys_peri, + }, +}; + +static int get_qbtc_subsys(const struct qdfu_fw_cfg *fw_cfg) +{ + int qbtc_subsys; + int fw_type; + + for (qbtc_subsys = 0; qbtc_subsys < QBTC_SUBSYS_MAX; qbtc_subsys++) { + for (fw_type = 0; fw_type < QBT_FW_TYPE_MAX; fw_type++) { + if (&qdfu_fw_cfgs_subsys[qbtc_subsys][fw_type] == fw_cfg) + return qbtc_subsys; + } + } + + return QBTC_SUBSYS_INVALID; +} + +/* + * btusb_download_fw - download a firmware image + * @hdev: the HCI device to download the firmware to + * @fw_cfg: the firmware download config + * @info: BTC info for this hdev + * @ctrl_id: BTC ID + * + * Return: 1 if downloaded, 0 if already downloaded, or a negative errno + * on failure. + */ +static int btusb_download_fw(struct hci_dev *hdev, + const struct qdfu_fw_cfg *fw_cfg, + const struct qbtc_info *info, + const struct qdfu_bt_id *ctrl_id) +{ + const struct firmware *fw = NULL; + char paths[QBT_FW_PATH_MAX * 2]; + const char *loaded_name; + u8 state, state_new; + u32 settle_us; + int n_paths; + int ret; + + bt_dev_dbg(hdev, "download %s", fw_cfg->desc); + ret = qdfu_get_target_state(hdev, &state); + if (ret) + goto out; + + if (state & fw_cfg->loaded_flag) { + bt_dev_info(hdev, "%s already downloaded", fw_cfg->desc); + goto out; + } + + n_paths = fw_cfg->get_path(hdev, fw_cfg, info, ctrl_id, paths, sizeof(paths)); + if (n_paths < 0) { + bt_dev_err(hdev, "Failed to get %s path: %pe", + fw_cfg->desc, ERR_PTR(n_paths)); + ret = n_paths; + goto out; + } + bt_dev_dbg(hdev, "%s path: %s", fw_cfg->desc, paths); + if (n_paths == 2) + bt_dev_dbg(hdev, "%s fallback path: %s", fw_cfg->desc, + paths + strlen(paths) + 1); + + loaded_name = paths; + ret = request_firmware(&fw, paths, &hdev->dev); + if (ret == -ENOENT && n_paths == 2) { + bt_dev_err(hdev, "Failed to request %s %s: %pe", + fw_cfg->desc, loaded_name, ERR_PTR(ret)); + loaded_name = paths + strlen(paths) + 1; + ret = request_firmware(&fw, loaded_name, &hdev->dev); + } + if (ret) { + bt_dev_err(hdev, "Failed to request %s %s: %pe", + fw_cfg->desc, loaded_name, ERR_PTR(ret)); + goto out; + } + bt_dev_dbg(hdev, "%s request succeeded: %s", fw_cfg->desc, loaded_name); + + ret = fw_cfg->check(hdev, fw_cfg, info, ctrl_id, fw); + if (ret) + goto out_free_fw; + + ret = fw_cfg->download(hdev, fw_cfg, info, ctrl_id, fw->data, fw->size); + if (ret) + goto out_free_fw; + bt_dev_info(hdev, "%s download succeeded: %s", fw_cfg->desc, loaded_name); + + ret = qdfu_poll_state(hdev, &state_new, true, fw_cfg->loaded_flag); + if (ret) + goto out_free_fw; + if (state_new != state) + bt_dev_dbg(hdev, "%s state: 0x%02x -> 0x%02x", + fw_cfg->desc, state, state_new); + + if (fw_cfg->get_settle_us) + settle_us = fw_cfg->get_settle_us(hdev, fw_cfg, info, ctrl_id); + else + settle_us = fw_cfg->settle_us; + fsleep(settle_us); + + if (fw_cfg->post_download) { + ret = fw_cfg->post_download(hdev, fw_cfg, info, ctrl_id); + if (ret) + bt_dev_err(hdev, "%s post-download failed: %pe", + fw_cfg->desc, ERR_PTR(ret)); + else + bt_dev_dbg(hdev, "%s post-download succeeded", fw_cfg->desc); + } + + if (!ret) { + bt_dev_dbg(hdev, "download %s succeeded", fw_cfg->desc); + ret = 1; + } + +out_free_fw: + release_firmware(fw); +out: + if (ret < 0) + bt_dev_err(hdev, "download %s failed: %pe", fw_cfg->desc, ERR_PTR(ret)); + return ret; +} + +/* + * ============================================================================ + * btusb_qcom.h APIs + * ============================================================================ + */ + +/* size of the hci priv area */ +int btusb_qcom_hdev_priv_size(void) +{ + return sizeof(struct btqcom_data) + sizeof(struct btusb_qcom); +} + +/* get @hdev's transport-specific data */ +struct btusb_qcom *btusb_qcom_xport_data(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + return (struct btusb_qcom *)(qbt_data + 1); +} + +/* work function for qbt_data->dwork */ +static void btqcom_work(struct work_struct *work) +{ + struct btqcom_data *qbt_data; + struct hci_dev *hdev; + + qbt_data = container_of(to_delayed_work(work), struct btqcom_data, dwork); + hdev = qbt_data->hdev; + + if (test_and_clear_bit(QBT_WORK_RESET_HDEV, &qbt_data->work_flags)) { + hci_dev_hold(hdev); + hci_req_sync_lock(hdev); + + btusb_do_reset_work(hdev, QBT_RESET_TYPE_ASYNC); + + hci_req_sync_unlock(hdev); + hci_dev_put(hdev); + } +} + +static void devm_btusb_qcom_deinit(void *data) +{ + struct btqcom_data *qbt_data = data; + struct btusb_qcom *xport_data; + + if (!qbt_data->inited) + return; + + xport_data = qbt_data->xport_data; + mutex_destroy(&qbt_data->req_mutex); + mutex_destroy(&xport_data->tx_mutex); + + qbt_data->inited = false; + bt_dev_dbg(qbt_data->hdev, "btusb qcom deinited"); +} + +static void __maybe_unused btusb_qcom_deinit(struct btqcom_data *qbt_data) +{ + devm_release_action(&qbt_data->hdev->dev, devm_btusb_qcom_deinit, + qbt_data); +} + +/* + * btusb_qcom_init - initialize hdev and per-device btqcom_data + * @qbt_data: the btqcom_data to initialize + * + * Doesn't touch btqcom_data fields that live for the hdev's lifetime, + * e.g. @fw_dir and @fw_logging. + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_qcom_init(struct btqcom_data *qbt_data) +{ + struct btusb_qcom *xport_data = qbt_data->xport_data; + struct hci_dev *hdev = qbt_data->hdev; + int res; + + WRITE_ONCE(qbt_data->misc_flags, 0); + WRITE_ONCE(qbt_data->work_flags, 0); + + qbt_data->md_state = HCI_DEVCOREDUMP_IDLE; + qbt_data->md_submit_err = 0; + qbt_data->md_submit_size = 0; + qbt_data->md_pending_flags = 0; + btqcom_reset_memdump(&qbt_data->md); + + WRITE_ONCE(qbt_data->req, NULL); + WRITE_ONCE(qbt_data->req_state, QHCI_REQ_DONE); + + if (qbt_data->inited) + return 0; + + hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP); + hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY); + hci_set_quirk(hdev, HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED); + + if (qbt_data->flags & QBT_FLAG_AOSP_EXT) + hci_set_aosp_capable(hdev); + if (qbt_data->flags & QBT_FLAG_MSFT_EXT) + hci_set_msft_opcode(hdev, 0xFD70); + + res = devm_add_action(&hdev->dev, devm_btusb_qcom_deinit, qbt_data); + if (res) { + bt_dev_err(hdev, "Add btusb qcom deinit action failed: %pe", + ERR_PTR(res)); + return res; + } + + INIT_DELAYED_WORK(&qbt_data->dwork, btqcom_work); + mutex_init(&xport_data->tx_mutex); + mutex_init(&qbt_data->req_mutex); + init_waitqueue_head(&qbt_data->req_wait_q); + spin_lock_init(&qbt_data->req_spinlock); + + hdev->set_bdaddr = btqcom_set_bdaddr; + hdev->reset = btusb_qcom_reset; + hdev->shutdown = btusb_qcom_shutdown; + hdev->hw_error = btqcom_hw_error; + hdev->handle_ev_vendor = btqcom_handle_ev_vendor; + hdev->recv_vendor_pkt = btqcom_recv_vendor_pkt; + + qbt_data->md_ready = false; + if (qbt_data->flags & QBT_FLAG_MEMDUMP) { + res = hci_devcd_register(hdev, btusb_qcom_trigger_memdump, + btusb_qcom_memdump_hdr, + btusb_qcom_notify_memdump); + if (!res) + qbt_data->md_ready = true; + else if (res == -EOPNOTSUPP) + bt_dev_warn(hdev, "CONFIG_DEV_COREDUMP not enabled"); + else + bt_dev_err(hdev, "register devcoredump failed: %pe", + ERR_PTR(res)); + } + + /* pairs with smp_load_acquire() in btusb_qcom_disconnect() */ + smp_store_release(&qbt_data->inited, true); + + bt_dev_dbg(hdev, "btusb qcom inited"); + return 0; +} + +/* + * btusb_qcom_setup_unified - setup for a unified BTC + * @hdev: the HCI device to set up + * @info: BTC info for this hdev + * @ctrl_id: BTC QDFU ID + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_qcom_setup_unified(struct hci_dev *hdev, + const struct qbtc_info *info, + const struct qdfu_bt_id *ctrl_id) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + enum qbtc_category btc_cat = info->category; + const struct qdfu_fw_cfg *cfgs_bt; + struct qdfu_bt_id bt_id; + int ret; + + cfgs_bt = qdfu_fw_cfgs_bt[btc_cat]; + + ret = btusb_download_fw(hdev, &cfgs_bt[QBT_FW_TYPE_PATCH], info, ctrl_id); + if (ret < 0) + return ret; + + ret = qdfu_get_target_version(hdev, &bt_id); + if (ret) + return ret; + qdfu_to_qhci_id(&qbt_data->ver, &qbt_data->board_id, &bt_id); + + ret = btusb_download_fw(hdev, &cfgs_bt[QBT_FW_TYPE_NVM], info, &bt_id); + if (ret) + return ret < 0 ? ret : 0; + + ret = __hci_reset_sync(hdev); + if (ret) + bt_dev_err(hdev, "HCI reset failed: %pe", ERR_PTR(ret)); + else + bt_dev_dbg(hdev, "HCI reset succeeded"); + + return ret; +} + +/* + * btusb_qcom_setup_msubsys - setup for a multi-subsystem BTC + * @hdev: the HCI device to set up + * @info: BTC info for this hdev + * @ctrl_id: BTC QDFU ID + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_qcom_setup_msubsys(struct hci_dev *hdev, + const struct qbtc_info *info, + const struct qdfu_bt_id *ctrl_id) +{ + const struct qdfu_fw_cfg *cfgs_peri = qdfu_fw_cfgs_subsys[QBTC_SUBSYS_PERI]; + const struct qdfu_fw_cfg *cfgs_bt = qdfu_fw_cfgs_bt[QBTC_CAT_MSUBSYS]; + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct qbtc_subsys_data *subsys_peri; + struct qdfu_bt_id peri_id, bt_id; + int ret; + + subsys_peri = &qbt_data->subsys[QBTC_SUBSYS_PERI]; + + ret = btusb_download_fw(hdev, &cfgs_peri[QBT_FW_TYPE_PATCH], info, ctrl_id); + if (ret < 0) + return ret; + + ret = qdfu_get_target_version(hdev, &peri_id); + if (ret) + return ret; + qdfu_to_qhci_id(&subsys_peri->ver, &subsys_peri->board_id, &peri_id); + + ret = btusb_download_fw(hdev, &cfgs_peri[QBT_FW_TYPE_NVM], info, &peri_id); + if (ret < 0) + return ret; + + ret = qdfu_reset_msubsys_bt(hdev); + if (ret) + return ret; + + ret = get_qdfu_id_via_hci(hdev, &bt_id); + if (ret) + return ret; + + if (bt_id.rom_version != peri_id.rom_version || + bt_id.soc_id != peri_id.soc_id || + bt_id.board_id != peri_id.board_id) { + bt_dev_info(hdev, "BT ROM Version: 0x%08x", + bt_id.rom_version); + bt_dev_info(hdev, "BT Patch Version: 0x%08x", + bt_id.patch_version); + bt_dev_info(hdev, "BT SoC Version: 0x%08x", + bt_id.soc_id); + bt_dev_info(hdev, "BT Board ID: 0x%04x", + bt_id.board_id); + } + + ret = btusb_download_fw(hdev, &cfgs_bt[QBT_FW_TYPE_PATCH], info, &bt_id); + if (ret < 0) + return ret; + + ret = get_qdfu_id_via_hci(hdev, &bt_id); + if (ret) + return ret; + qdfu_to_qhci_id(&qbt_data->ver, &qbt_data->board_id, &bt_id); + + ret = btusb_download_fw(hdev, &cfgs_bt[QBT_FW_TYPE_NVM], info, &bt_id); + if (ret < 0) + return ret; + + return 0; +} + +static int btqcom_post_setup(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + struct qbtc_subsys_data *subsys_data; + char *build_info = NULL; + char buf[512]; + int len = 0; + int res; + + bt_dev_dbg(hdev, "flags: 0x%lx", qbt_data->flags); + bt_dev_info(hdev, "memdump ready? %s", str_yes_no(qbt_data->md_ready)); + + qbt_config_fw_logging(hdev, qbt_data->fw_logging); + + hci_set_hw_info(hdev, "%s", qbt_data->btc_name); + if (qbt_data->category == QBTC_CAT_MSUBSYS) { + subsys_data = &qbt_data->subsys[QBTC_SUBSYS_PERI]; + if (subsys_data->build_info[0] == '\0') { + res = qperi_get_subsys_build_info(hdev, QHCI_SUBSYS_PERI, + &build_info); + if (!res) { + strscpy(subsys_data->build_info, build_info, + sizeof(subsys_data->build_info)); + kfree(build_info); + } + } + + bt_dev_info(hdev, "%s build info: %s", + qbtc_subsys_name(QBTC_SUBSYS_PERI), subsys_data->build_info); + len = scnprintf(buf, sizeof(buf), "%s: %s\n", + qbtc_subsys_name(QBTC_SUBSYS_PERI), subsys_data->build_info); + } + + if (qbt_data->build_info[0] == '\0') { + build_info = NULL; + res = qbt_edl_get_build_info(hdev, &build_info); + if (!res) { + strscpy(qbt_data->build_info, build_info, + sizeof(qbt_data->build_info)); + kfree(build_info); + } + } + + bt_dev_info(hdev, "BT build info: %s", qbt_data->build_info); + len += snprintf(buf + len, sizeof(buf) - len, "BT: %s", qbt_data->build_info); + hci_set_fw_info(hdev, "%s", buf); + + return 0; +} + +/* + * btusb_qcom_setup - setup a BTC + * @hdev: the HCI device + * + * Identifies the BTC, then dispatches setup based on its category. + * Implements hdev->setup(). + * + * Return: 0 on success, or a negative errno on failure. + */ +int btusb_qcom_setup(struct hci_dev *hdev) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + bool is_first_setup = hci_dev_test_flag(hdev, HCI_SETUP); + struct btqcom_data *qbt_data = hci_get_priv(hdev); + const struct qbtc_id *id_entry = qbtc_id_table; + struct qdfu_bt_id ctrl_id; + int ret; + + qbt_data->hdev = hdev; + xport_data->intf = to_usb_interface(hdev->dev.parent); + xport_data->udev = interface_to_usbdev(xport_data->intf); + xport_data->idVendor = le16_to_cpu(xport_data->udev->descriptor.idVendor); + xport_data->idProduct = le16_to_cpu(xport_data->udev->descriptor.idProduct); + qbt_data->xport_data = xport_data; + + ret = usb_autopm_get_interface(xport_data->intf); + if (ret) { + bt_dev_err(hdev, "get autopm for QCOM BTUSB setup failed: %pe", + ERR_PTR(ret)); + return ret; + } + + ret = qdfu_get_target_version(hdev, &ctrl_id); + if (ret) + goto out; + + while (id_entry->rom_version) { + if (id_entry->rom_version == ctrl_id.rom_version) + break; + id_entry++; + } + + if (!id_entry->rom_version) { + ret = -ENODEV; + bt_dev_warn(hdev, "Detected unsupported BT controller:"); + } else { + bt_dev_info(hdev, "%s QCOM %s BT controller: %s", + is_first_setup ? "Detected" : "Setup", + qbtc_category_name(id_entry->btc_info->category), + id_entry->name); + } + + bt_dev_info(hdev, "ROM Version : 0x%08x", ctrl_id.rom_version); + bt_dev_info(hdev, "Patch Version: 0x%08x", ctrl_id.patch_version); + bt_dev_info(hdev, "SoC Version : 0x%08x", ctrl_id.soc_id); + bt_dev_info(hdev, "Board ID : 0x%04x", ctrl_id.board_id); + + if (ret) + goto out; + + if (!qbt_data->drv_name) + qbt_data->drv_name = dev_driver_string(&xport_data->intf->dev); + qbt_data->btc_name = id_entry->name; + qbt_data->category = id_entry->btc_info->category; + qbt_data->flags = id_entry->btc_info->flags & QBT_FLAG_BTC_CFG_MASK; + if (xport_data->reset_gpio) + qbt_data->flags |= QBT_FLAG_HW_RESET; + ret = btusb_qcom_init(qbt_data); + if (ret) + goto out; + + switch (qbt_data->category) { + case QBTC_CAT_LEGACY: + ret = -EOPNOTSUPP; + break; + case QBTC_CAT_UNIFIED: + hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN); + ret = btusb_qcom_setup_unified(hdev, id_entry->btc_info, &ctrl_id); + break; + case QBTC_CAT_MSUBSYS: + ret = btusb_qcom_setup_msubsys(hdev, id_entry->btc_info, &ctrl_id); + break; + default: + ret = -EINVAL; + break; + } + + if (!ret) + ret = btqcom_post_setup(hdev); + +out: + usb_autopm_put_interface(xport_data->intf); + if (!ret) + bt_dev_info(hdev, "QCOM BTUSB setup succeeded (^_^)"); + else + bt_dev_err(hdev, "QCOM BTUSB setup failed: %pe", ERR_PTR(ret)); + return ret; +} + +/* + * btusb_qcom_disconnect - clean up on USB disconnect + * @hdev: the HCI device being disconnected + * + * Return: 0 on success, or a negative errno on failure. + */ +int btusb_qcom_disconnect(struct hci_dev *hdev) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + + /* pairs with smp_store_release() in btusb_qcom_init() */ + if (!smp_load_acquire(&qbt_data->inited)) + return 0; + + bt_dev_dbg(hdev, "disconnection: misc_flags(0x%lx)", + READ_ONCE(qbt_data->misc_flags)); + + if (test_bit(QBT_MISC_MEMDUMP_INCOMING, &qbt_data->misc_flags) && + !qbt_data->md_submit_err) + bt_dev_warn(hdev, "memdump collection interrupted by disconnection"); + + qperi_tx_sync_cancel_sync(hdev, -ENODEV); + if (test_and_clear_bit(QBT_MISC_CMD_TIMEOUT, &qbt_data->misc_flags)) { + wake_up_var(&qbt_data->misc_flags); + bt_dev_dbg(hdev, "wake command-timeout waiter on disconnection"); + } + disable_delayed_work_sync(&qbt_data->dwork); + + return 0; +} + +/* + * btusb_qcom_send_frame - send a frame for BT or PERI + * @hdev: the HCI device + * @skb: the frame to send + * + * Implements hdev->send(). + * + * Return: 0 on success, or a negative errno on failure. + */ +int btusb_qcom_send_frame(struct hci_dev *hdev, struct sk_buff *skb) + __context_unsafe(/* conditional locking */) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + struct btqcom_data *qbt_data = hci_get_priv(hdev); + bool is_vendor; + bool need_lock; + u8 pkt_type; + int ret; + + if (qbt_data->category != QBTC_CAT_MSUBSYS) + return xport_data->send_bt_frame(hdev, skb); + + pkt_type = hci_skb_pkt_type(skb); + is_vendor = pkt_type == HCI_VENDOR_PKT; + /* an empty vendor packet has no path to reach here */ + if (is_vendor) + hci_skb_pkt_type(skb) = *(const u8 *)skb_pull_data(skb, 1); + + pkt_type = hci_skb_pkt_type(skb); + need_lock = pkt_type == HCI_COMMAND_PKT || + pkt_type == QPERI_COMMAND_PKT; + + if (need_lock) + mutex_lock(&xport_data->tx_mutex); + + if (is_vendor) + ret = xport_data->send_vendor_frame(hdev, skb); + else + ret = xport_data->send_bt_frame(hdev, skb); + + if (need_lock) + mutex_unlock(&xport_data->tx_mutex); + + return ret; +} + +/* + * RX flow: + * + * USB intr/bulk endpoint (byte stream) + * -> btusb_qcom_recv_{intr,bulk}() (reassemble to frame) + * -> btqcom_recv_frame() + * -> btusb_upward_frame() (dispatch frame upwards) + * -> hci_recv_frame() (PERI frame as HCI_VENDOR_PKT) + * -> xport_data->recv_bt_frame() (BT, back to btusb_main.c) + */ + +/* + * btusb_upward_frame - dispatch a received frame upwards + * @hdev: the HCI device the @skb comes from + * @skb: the frame to dispatch upwards + * + * Return: 0 on success, or a negative errno on failure. + */ +static int btusb_upward_frame(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btusb_qcom *xport_data = btusb_qcom_xport_data(hdev); + u8 pkt_type = hci_skb_pkt_type(skb); + u16 handle; + int ret; + + switch (pkt_type) { + case QPERI_EVENT_PKT: + case QPERI_ACLDATA_PKT: + *(u8 *)skb_push(skb, 1) = pkt_type; + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; + break; + case HCI_EVENT_PKT: + break; + case HCI_ACLDATA_PKT: + handle = hci_acl_handle(skb); + /* reroute vendor ACLs as HCI_VENDOR_PKT */ + if (handle == QBT_HANDLE_ENHANCED_LOGGING || + handle == QBT_HANDLE_MEMDUMP) { + *(u8 *)skb_push(skb, 1) = pkt_type; + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; + } + break; + default: + dev_kfree_skb_irq(skb); + ret = -EINVAL; + goto out; + } + + if (hci_skb_pkt_type(skb) == HCI_VENDOR_PKT) + ret = hci_recv_frame(hdev, skb); + else + ret = xport_data->recv_bt_frame(hdev, skb); + +out: + if (ret) + bt_dev_err(hdev, "upward frame with type (0x%02x) failed: %pe", + pkt_type, ERR_PTR(ret)); + + return ret; +} + +/* Every frame lands here first — the ideal spot for pre-processing. */ +static int btqcom_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) +{ + u8 pkt_type = hci_skb_pkt_type(skb); + + switch (pkt_type) { + case HCI_EVENT_PKT: + case QPERI_EVENT_PKT: + case HCI_ACLDATA_PKT: + case QPERI_ACLDATA_PKT: + break; + default: + dev_kfree_skb_irq(skb); + bt_dev_err_ratelimited(hdev, "unexpected pkt type 0x%02x", pkt_type); + return -EINVAL; + } + + return btusb_upward_frame(hdev, skb); +} + +/* + * RX reassembly state, stashed in hci_skb_pkt_seqnum(skb) between calls: + * QRX_STATE_INDICATOR - determining the packet type + * QRX_STATE_HEADER - receiving the packet header + * QRX_STATE_PAYLOAD - receiving the payload + */ +enum { + QRX_STATE_INDICATOR, + QRX_STATE_HEADER, + QRX_STATE_PAYLOAD, +}; + +/* + * btusb_qcom_recv_intr - reassemble byte stream from the intr endpoint to frame + * @hdev: the HCI device + * @skb: the in-progress frame, or NULL to start a new one + * @buffer: bytes received + * @count: bytes count + * @err: output error code + * + * See the RX flow diagram above for further dispatch. + * + * Return: the in-progress frame to resume on the next call, or NULL + * otherwise. + */ +struct sk_buff *btusb_qcom_recv_intr(struct hci_dev *hdev, struct sk_buff *skb, + void *buffer, int count, int *err) +{ + struct btqcom_data *qbt_data = hci_get_priv(hdev); + enum qbtc_category btc_cat = qbt_data->category; + int rx_state; + u8 pkt_type; + int len; + int res; + + *err = 0; + while (count) { + if (!skb) { + u8 host_id = *(u8 *)buffer; + + skb = bt_skb_alloc(QPERI_MAX_EVENT_SIZE, GFP_ATOMIC); + if (!skb) { + *err = -ENOMEM; + break; + } + + /* see struct qperi_event_hdr for PERI event format */ + if (host_id == QHCI_HOST_ID_BT) { + hci_skb_pkt_type(skb) = QPERI_EVENT_PKT; + hci_skb_pkt_seqnum(skb) = QRX_STATE_HEADER; + hci_skb_expect(skb) = QPERI_EVENT_HDR_SIZE; + } else { + hci_skb_pkt_type(skb) = HCI_EVENT_PKT; + hci_skb_pkt_seqnum(skb) = QRX_STATE_HEADER; + hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE; + } + } + + len = min_t(uint, hci_skb_expect(skb), count); + skb_put_data(skb, buffer, len); + + count -= len; + buffer += len; + hci_skb_expect(skb) -= len; + + if (hci_skb_expect(skb)) + continue; + + rx_state = hci_skb_pkt_seqnum(skb); + if (rx_state == QRX_STATE_PAYLOAD) + goto frame_done; + + hci_skb_pkt_seqnum(skb) = QRX_STATE_PAYLOAD; + pkt_type = hci_skb_pkt_type(skb); + if (pkt_type == QPERI_EVENT_PKT) + hci_skb_expect(skb) = qperi_event_header(skb)->plen; + else if (pkt_type == HCI_EVENT_PKT) + hci_skb_expect(skb) = hci_event_hdr(skb)->plen; + + if (hci_skb_expect(skb)) + continue; + +frame_done: + if (count && count < HCI_EVENT_HDR_SIZE) { + bt_dev_warn(hdev, + "Unexpected continuation: %d bytes", + count); + if (btc_cat != QBTC_CAT_MSUBSYS) + count = 0; + } + + hci_skb_pkt_seqnum(skb) = 0; + res = btqcom_recv_frame(hdev, skb); + if (res) + bt_dev_err_ratelimited(hdev, "recv intr frame failed: %pe", + ERR_PTR(res)); + skb = NULL; + } + + return skb; +} + +/* + * btusb_qcom_recv_bulk - reassemble byte stream from the bulk endpoint to frame + * @hdev: the HCI device + * @skb: the in-progress frame, or NULL to start a new one + * @buffer: bytes received + * @count: bytes count + * @err: output error code + * + * See the RX flow diagram above for further dispatch. + * + * Return: the in-progress frame to resume on the next call, or NULL + * otherwise. + */ +struct sk_buff *btusb_qcom_recv_bulk(struct hci_dev *hdev, struct sk_buff *skb, + void *buffer, int count, int *err) +{ + struct qperi_acl_hdr *peri_hdr; + u16 peri_handle; + int rx_state; + u8 pkt_type; + int res; + int len; + + *err = 0; + while (count) { + if (!skb) { + skb = bt_skb_alloc(QPERI_MAX_FRAME_SIZE, GFP_ATOMIC); + if (!skb) { + *err = -ENOMEM; + break; + } + hci_skb_pkt_seqnum(skb) = QRX_STATE_INDICATOR; + hci_skb_expect(skb) = HCI_ACL_HDR_SIZE; + } + + len = min_t(uint, hci_skb_expect(skb), count); + skb_put_data(skb, buffer, len); + + count -= len; + buffer += len; + hci_skb_expect(skb) -= len; + + if (hci_skb_expect(skb)) + continue; + + rx_state = hci_skb_pkt_seqnum(skb); + switch (rx_state) { + case QRX_STATE_INDICATOR: + hci_skb_pkt_seqnum(skb) = QRX_STATE_HEADER; + peri_hdr = qperi_acl_header(skb); + peri_handle = qperi_acl_handle(skb); + if (peri_hdr->host_id == QHCI_HOST_ID_BT && + peri_handle >= 0xEC0 && peri_handle <= 0xECF) { + hci_skb_pkt_type(skb) = QPERI_ACLDATA_PKT; + hci_skb_expect(skb) = QPERI_ACL_HDR_SIZE - HCI_ACL_HDR_SIZE; + continue; + } + hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT; + fallthrough; + + case QRX_STATE_HEADER: + pkt_type = hci_skb_pkt_type(skb); + if (pkt_type == QPERI_ACLDATA_PKT) + hci_skb_expect(skb) = qperi_acl_dlen(skb); + else if (pkt_type == HCI_ACLDATA_PKT) + hci_skb_expect(skb) = hci_acl_dlen(skb); + + if (hci_skb_expect(skb) > QPERI_MAX_FRAME_SIZE - skb->len) { + dev_kfree_skb_irq(skb); + skb = NULL; + *err = -EILSEQ; + return NULL; + } + hci_skb_pkt_seqnum(skb) = QRX_STATE_PAYLOAD; + if (hci_skb_expect(skb)) + continue; + fallthrough; + + case QRX_STATE_PAYLOAD: + break; + } + + hci_skb_pkt_seqnum(skb) = 0; + res = btqcom_recv_frame(hdev, skb); + if (res) + bt_dev_err_ratelimited(hdev, "recv bulk frame failed: %pe", + ERR_PTR(res)); + skb = NULL; + } + + return skb; +} + +MODULE_AUTHOR("Zijun Hu "); diff --git a/drivers/bluetooth/btusb_qcom.h b/drivers/bluetooth/btusb_qcom.h new file mode 100644 index 000000000000..8fbc105f4eaf --- /dev/null +++ b/drivers/bluetooth/btusb_qcom.h @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Qualcomm Bluetooth USB transport-specific support + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#ifndef __BTUSB_QCOM_H +#define __BTUSB_QCOM_H + +#include +#include +#include +#include + +#include + +#define QPERI_COMMAND_PKT 0x31 +#define QPERI_ACLDATA_PKT 0x32 +#define QPERI_EVENT_PKT 0x34 + +struct btusb_qcom { + __u16 idVendor; + __u16 idProduct; + struct usb_device *udev; + struct usb_interface *intf; + struct gpio_desc *reset_gpio; + + /* serializes sending BT and vendor frames to the transport */ + struct mutex tx_mutex; + + void (*prepare_reset)(struct hci_dev *hdev); + int (*recv_bt_frame)(struct hci_dev *hdev, struct sk_buff *skb); + int (*send_bt_frame)(struct hci_dev *hdev, struct sk_buff *skb); + int (*send_vendor_frame)(struct hci_dev *hdev, struct sk_buff *skb); +}; + +#if IS_ENABLED(CONFIG_BT_HCIBTUSB_QCOM) + +int btusb_qcom_hdev_priv_size(void); +struct btusb_qcom *btusb_qcom_xport_data(struct hci_dev *hdev); + +int btusb_qcom_setup(struct hci_dev *hdev); +int btusb_qcom_disconnect(struct hci_dev *hdev); +int btusb_qcom_send_frame(struct hci_dev *hdev, struct sk_buff *skb); + +struct sk_buff *btusb_qcom_recv_intr(struct hci_dev *hdev, struct sk_buff *skb, + void *buffer, int count, int *err); + +struct sk_buff *btusb_qcom_recv_bulk(struct hci_dev *hdev, struct sk_buff *skb, + void *buffer, int count, int *err); + +#else + +static inline int btusb_qcom_hdev_priv_size(void) +{ + return 0; +} + +static inline struct btusb_qcom *btusb_qcom_xport_data(struct hci_dev *hdev) +{ + return NULL; +} + +static inline int btusb_qcom_setup(struct hci_dev *hdev) +{ + return -EOPNOTSUPP; +} + +static inline int btusb_qcom_disconnect(struct hci_dev *hdev) +{ + return -EOPNOTSUPP; +} + +static inline int btusb_qcom_send_frame(struct hci_dev *hdev, struct sk_buff *skb) +{ + return -EOPNOTSUPP; +} + +static inline struct sk_buff *btusb_qcom_recv_intr(struct hci_dev *hdev, + struct sk_buff *skb, + void *buffer, int count, + int *err) +{ + *err = -EOPNOTSUPP; + return NULL; +} + +static inline struct sk_buff *btusb_qcom_recv_bulk(struct hci_dev *hdev, + struct sk_buff *skb, + void *buffer, int count, + int *err) +{ + *err = -EOPNOTSUPP; + return NULL; +} + +#endif +#endif From 10038da922652aa990ce9d07f04854611172b59d Mon Sep 17 00:00:00 2001 From: Alex Zhou Date: Wed, 16 Sep 2026 04:07:19 +0200 Subject: [PATCH 1700/2126] MAINTAINERS: add entry for NXP wireless Bluetooth driver Add Song Xue and Alex Zhou as maintainers for the NXP wireless Bluetooth driver. Signed-off-by: Alex Zhou Acked-by: Neeraj Sanjay Kale Signed-off-by: Luiz Augusto von Dentz --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 509b35b5a0e7..927ef912e30c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19661,6 +19661,8 @@ F: include/linux/nvmem-consumer.h F: include/linux/nvmem-provider.h NXP BLUETOOTH WIRELESS DRIVERS +M: Song Xue +M: Alex Zhou M: Amitkumar Karwar M: Neeraj Kale S: Maintained From 589b80b654588ab19117e45097772e85e45dd1bb Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Tue, 15 Sep 2026 19:17:17 -0700 Subject: [PATCH 1701/2126] Bluetooth: btnxpuart: Simplify nxp_recv_acl_pkt() by hci_acl_handle() Simplify nxp_recv_acl_pkt() by using hci_acl_handle() instead of: __u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle); ... (handle & 0x0FFF) ... Reviewed-by: Neeraj Sanjay Kale Signed-off-by: Zijun Hu Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btnxpuart.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c index 4e23d71d00e8..5c730e336114 100644 --- a/drivers/bluetooth/btnxpuart.c +++ b/drivers/bluetooth/btnxpuart.c @@ -1407,10 +1407,8 @@ free_skb: static int nxp_recv_acl_pkt(struct hci_dev *hdev, struct sk_buff *skb) { - __u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle); - /* FW dump chunks are ACL packets with conn handle 0xfff */ - if ((handle & 0x0FFF) == 0xFFF) + if (hci_acl_handle(skb) == 0xFFF) return nxp_process_fw_dump(hdev, skb); else return hci_recv_frame(hdev, skb); From c4154fc34772134b0dbd14ab0134ba10b90c52cc Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sun, 20 Sep 2026 10:26:02 +0800 Subject: [PATCH 1702/2126] Bluetooth: use assign_bit() where applicable Convert open-coded if/else with set_bit/clear_bit the assign_bit API. Done with Coccinelle semantic patch: // set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond); Signed-off-by: Peng Fan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 31 +++++++------------------------ net/bluetooth/iso.c | 15 +++------------ net/bluetooth/l2cap_sock.c | 22 ++++++---------------- net/bluetooth/rfcomm/core.c | 6 ++---- net/bluetooth/rfcomm/sock.c | 5 +---- net/bluetooth/sco.c | 10 ++-------- 6 files changed, 21 insertions(+), 68 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 25ddba2f603b..5ac2357e92c9 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -404,10 +404,7 @@ static u8 hci_cc_write_auth_enable(struct hci_dev *hdev, void *data, if (!rp->status) { __u8 param = *((__u8 *) sent); - if (param == AUTH_ENABLED) - set_bit(HCI_AUTH, &hdev->flags); - else - clear_bit(HCI_AUTH, &hdev->flags); + assign_bit(HCI_AUTH, &hdev->flags, param == AUTH_ENABLED); } if (hci_dev_test_flag(hdev, HCI_MGMT)) @@ -436,10 +433,7 @@ static u8 hci_cc_write_encrypt_mode(struct hci_dev *hdev, void *data, param = *((__u8 *) sent); - if (param) - set_bit(HCI_ENCRYPT, &hdev->flags); - else - clear_bit(HCI_ENCRYPT, &hdev->flags); + assign_bit(HCI_ENCRYPT, &hdev->flags, param); return rp->status; } @@ -466,15 +460,9 @@ static u8 hci_cc_write_scan_enable(struct hci_dev *hdev, void *data, goto done; } - if (param & SCAN_INQUIRY) - set_bit(HCI_ISCAN, &hdev->flags); - else - clear_bit(HCI_ISCAN, &hdev->flags); + assign_bit(HCI_ISCAN, &hdev->flags, param & SCAN_INQUIRY); - if (param & SCAN_PAGE) - set_bit(HCI_PSCAN, &hdev->flags); - else - clear_bit(HCI_PSCAN, &hdev->flags); + assign_bit(HCI_PSCAN, &hdev->flags, param & SCAN_PAGE); done: hci_dev_unlock(hdev); @@ -4614,10 +4602,8 @@ static void hci_mode_change_evt(struct hci_dev *hdev, void *data, if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { - if (conn->mode == HCI_CM_ACTIVE) - set_bit(HCI_CONN_POWER_SAVE, &conn->flags); - else - clear_bit(HCI_CONN_POWER_SAVE, &conn->flags); + assign_bit(HCI_CONN_POWER_SAVE, &conn->flags, + conn->mode == HCI_CM_ACTIVE); } if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) @@ -4817,10 +4803,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data, goto unlock; } - if (persistent) - clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags); - else - set_bit(HCI_CONN_FLUSH_KEY, &conn->flags); + assign_bit(HCI_CONN_FLUSH_KEY, &conn->flags, !persistent); unlock: hci_dev_unlock(hdev); diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index d6ac5b1f49bc..cf302e060f79 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -1974,10 +1974,7 @@ static int iso_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (opt) - set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); - else - clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); + assign_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags, opt); break; case BT_PKT_STATUS: @@ -1985,10 +1982,7 @@ static int iso_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (opt) - set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags); - else - clear_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags); + assign_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags, opt); break; case BT_PKT_SEQNUM: @@ -1996,10 +1990,7 @@ static int iso_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (opt) - set_bit(BT_SK_PKT_SEQNUM, &bt_sk(sk)->flags); - else - clear_bit(BT_SK_PKT_SEQNUM, &bt_sk(sk)->flags); + assign_bit(BT_SK_PKT_SEQNUM, &bt_sk(sk)->flags, opt); break; case BT_ISO_QOS: diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 278adb05c4c9..c92f31b997dd 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -867,15 +867,11 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, if (opt & L2CAP_LM_SECURE) chan->sec_level = BT_SECURITY_HIGH; - if (opt & L2CAP_LM_MASTER) - set_bit(FLAG_ROLE_SWITCH, &chan->flags); - else - clear_bit(FLAG_ROLE_SWITCH, &chan->flags); + assign_bit(FLAG_ROLE_SWITCH, &chan->flags, + opt & L2CAP_LM_MASTER); - if (opt & L2CAP_LM_RELIABLE) - set_bit(FLAG_FORCE_RELIABLE, &chan->flags); - else - clear_bit(FLAG_FORCE_RELIABLE, &chan->flags); + assign_bit(FLAG_FORCE_RELIABLE, &chan->flags, + opt & L2CAP_LM_RELIABLE); break; default: @@ -1042,10 +1038,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, } } - if (opt) - set_bit(FLAG_FLUSHABLE, &chan->flags); - else - clear_bit(FLAG_FLUSHABLE, &chan->flags); + assign_bit(FLAG_FLUSHABLE, &chan->flags, opt); break; case BT_POWER: @@ -1061,10 +1054,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (pwr.force_active) - set_bit(FLAG_FORCE_ACTIVE, &chan->flags); - else - clear_bit(FLAG_FORCE_ACTIVE, &chan->flags); + assign_bit(FLAG_FORCE_ACTIVE, &chan->flags, pwr.force_active); break; case BT_CHANNEL_POLICY: diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 54ec1136f87e..8a4205347c4a 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -1740,10 +1740,8 @@ static int rfcomm_recv_msc(struct rfcomm_session *s, int cr, struct sk_buff *skb return 0; if (cr) { - if (msc->v24_sig & RFCOMM_V24_FC && !d->cfc) - set_bit(RFCOMM_TX_THROTTLED, &d->flags); - else - clear_bit(RFCOMM_TX_THROTTLED, &d->flags); + assign_bit(RFCOMM_TX_THROTTLED, &d->flags, + msc->v24_sig & RFCOMM_V24_FC && !d->cfc); rfcomm_dlc_lock(d); diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index b26918dc9e9e..3fb8b5474948 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -724,10 +724,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (opt) - set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); - else - clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); + assign_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags, opt); break; diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index f4a20d7b5f9c..8be48ca9f4c5 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -1037,10 +1037,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (opt) - set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); - else - clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); + assign_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags, opt); break; case BT_VOICE: @@ -1080,10 +1077,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, if (err) break; - if (opt) - set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags); - else - clear_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags); + assign_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags, opt); break; case BT_CODEC: From eb2a7f1bc891695fa714e2146f3c7141274eeb15 Mon Sep 17 00:00:00 2001 From: Ravindra Date: Mon, 21 Sep 2026 11:18:30 +0530 Subject: [PATCH 1703/2126] Bluetooth: btintel: read ROM debug registers on FW download failure The bootloader records init sequence progress and debug info in four core debug registers, useful for debugging FW download failures. Add btintel_get_rom_debug_info() to issue BTINTEL_GET_ROM_DEBUG_INFO (0xfcde) and log these registers, and invoke it from every FW download failure and timeout path: btintel_download_fw() (legacy .sfi flow) and btintel_prepare_fw_download_tlv() (TLV flow), before resetting to the bootloader. Tested by corrupting the operational firmware file to force a download timeout; the driver logged the debug registers on each failure and retry, e.g.: Bluetooth: hci0: Firmware loading timeout Bluetooth: Intel get rom debug info: dr0:0x80000001 dr1:0x00000000 dr2:0x00000001 dr3:0x00df0071 Signed-off-by: Ravindra Reviewed-by: Paul Menzel Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 47 +++++++++++++++++++++++++++++++++++-- drivers/bluetooth/btintel.h | 9 +++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index cf109d79569a..1dcb84c1ff37 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -972,6 +972,41 @@ int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param) } EXPORT_SYMBOL_GPL(btintel_send_intel_reset); +static void btintel_get_rom_debug_info(struct hci_dev *hdev) +{ + struct btintel_rp_get_rom_debug_info *rom_debug_info; + struct sk_buff *skb; + + skb = __hci_cmd_sync(hdev, BTINTEL_GET_ROM_DEBUG_INFO, 0, NULL, + HCI_CMD_TIMEOUT); + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Failed to send Intel get rom debug info command (%ld)", + PTR_ERR(skb)); + return; + } + + if (skb->len != sizeof(*rom_debug_info)) { + bt_dev_err(hdev, + "Intel get rom debug info size mismatch (%u != %zu)", + skb->len, sizeof(*rom_debug_info)); + kfree_skb(skb); + return; + } + + rom_debug_info = (struct btintel_rp_get_rom_debug_info *)skb->data; + + /* A non-zero status here would have already been turned into an + * error by the HCI core and reported via the IS_ERR(skb) check above. + */ + bt_dev_info(hdev, "Intel get rom debug info: dr0:0x%08x dr1:0x%08x dr2:0x%08x dr3:0x%08x", + le32_to_cpu(rom_debug_info->debug_reg0), + le32_to_cpu(rom_debug_info->debug_reg1), + le32_to_cpu(rom_debug_info->debug_reg2), + le32_to_cpu(rom_debug_info->debug_reg3)); + + kfree_skb(skb); +} + int btintel_read_boot_params(struct hci_dev *hdev, struct intel_boot_params *params) { @@ -2221,6 +2256,8 @@ download: goto done; } + btintel_get_rom_debug_info(hdev); + /* When FW download fails, send Intel Reset to retry * FW download. */ @@ -2240,8 +2277,10 @@ download: * of this device. */ err = btintel_download_wait(hdev, calltime, 5000); - if (err == -ETIMEDOUT) + if (err == -ETIMEDOUT) { + btintel_get_rom_debug_info(hdev); btintel_reset_to_bootloader(hdev); + } done: release_firmware(fw); @@ -2474,6 +2513,8 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev, goto done; } + btintel_get_rom_debug_info(hdev); + /* When FW download fails, send Intel Reset to retry * FW download. */ @@ -2493,8 +2534,10 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev, * of this device. */ err = btintel_download_wait(hdev, calltime, 5000); - if (err == -ETIMEDOUT) + if (err == -ETIMEDOUT) { + btintel_get_rom_debug_info(hdev); btintel_reset_to_bootloader(hdev); + } done: intel_data->cnvi_bt = ver->cnvi_bt; diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index c00f793d9dc8..b3c4c6f87424 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -178,6 +178,15 @@ struct hci_ppag_enable_cmd { __le32 ppag_enable_flags; } __packed; +#define BTINTEL_GET_ROM_DEBUG_INFO 0xfcde +struct btintel_rp_get_rom_debug_info { + __u8 status; + __le32 debug_reg0; + __le32 debug_reg1; + __le32 debug_reg2; + __le32 debug_reg3; +} __packed; + #define INTEL_TLV_TYPE_ID 0x01 #define INTEL_TLV_SYSTEM_EXCEPTION 0x00 From 18b0fd644fbd15b4cee0ff39b7eaa6cf3df415f3 Mon Sep 17 00:00:00 2001 From: Sai Teja Aluvala Date: Tue, 22 Sep 2026 11:47:44 +0530 Subject: [PATCH 1704/2126] Bluetooth: btintel_pcie: Add support for Intel Draco Add Device ID for Intel Draco support From lspci -v -d 8086:2731 02: 00.0 Bluetooth: Intel Corporation Device 2731 Subsystem: Intel Corporation Device 0012 Flags: bus master, fast devsel, latency 0, IRQ 16 Memory at fe000000 (32-bit, non-prefetchable) [size=16K] Capabilities: [c8] Power Management version 3 Capabilities: [d0] MSI: Enable- Count=1/1 Maskable- 64bit+ Capabilities: [40] Express Root Complex Integrated Endpoint, MSI 00 Capabilities: [80] MSI-X: Enable+ Count=5 Masked- Kernel driver in use: btintel_pcie Kernel modules: btintel_pcie Signed-off-by: Sai Teja Aluvala Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 10706fd2376a..2e8a00f20b5e 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -55,6 +55,8 @@ static const struct pci_device_id btintel_pcie_table[] = { { BTINTEL_PCI_DEVICE(0xD346, PCI_ANY_ID) }, /* Scorpious2, Nova Lake-PCD-S */ { BTINTEL_PCI_DEVICE(0x6E74, PCI_ANY_ID) }, + /* Draco */ + { BTINTEL_PCI_DEVICE(0x2731, PCI_ANY_ID) }, { 0 } }; MODULE_DEVICE_TABLE(pci, btintel_pcie_table); From 677d3d323f9a5d34a792e70d73bd1aff0cd8782c Mon Sep 17 00:00:00 2001 From: Sai Teja Aluvala Date: Tue, 22 Sep 2026 11:48:04 +0530 Subject: [PATCH 1705/2126] Bluetooth: btintel_pcie: Add support for Intel Draco Add Device_id 2732 for intel Draco From lspci -v -d 8086:2732 02:00.0 Bluetooth: Intel Corporation Device 2732 Subsystem: Intel Corporation Device 0012 Flags: bus master, fast devsel, latency 0, IRQ 16 Memory at fe000000 (32-bit, non-prefetchable) [size=16K] Capabilities: [c8] Power Management version 3 Capabilities: [d0] MSI: Enable- Count=1/1 Maskable- 64bit+ Capabilities: [40] Express Root Complex Integrated Endpoint, MSI 00 Capabilities: [80] MSI-X: Enable+ Count=5 Masked- Kernel driver in use: btintel_pcie Kernel modules: btintel_pcie Signed-off-by: Sai Teja Aluvala Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 2e8a00f20b5e..a7aea950c73f 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -57,6 +57,7 @@ static const struct pci_device_id btintel_pcie_table[] = { { BTINTEL_PCI_DEVICE(0x6E74, PCI_ANY_ID) }, /* Draco */ { BTINTEL_PCI_DEVICE(0x2731, PCI_ANY_ID) }, + { BTINTEL_PCI_DEVICE(0x2732, PCI_ANY_ID) }, { 0 } }; MODULE_DEVICE_TABLE(pci, btintel_pcie_table); From 88b08675443b0e06df34af6eb1edebb097e3fa1a Mon Sep 17 00:00:00 2001 From: Sai Teja Aluvala Date: Tue, 22 Sep 2026 11:48:21 +0530 Subject: [PATCH 1706/2126] Bluetooth: Add support for Intel DRACO Add support for the Draco Bluetooth core (hardware variant 0x23, CNVi 0xA30) recognizing the new variant in btintel's version info TLV parsing, MSFT vendor opcode setup, and combined setup path, as well as in btintel_pcie hardware exception handling and PCIe setup path. Signed-off-by: Sai Teja Aluvala Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 3 +++ drivers/bluetooth/btintel.h | 1 + drivers/bluetooth/btintel_pcie.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 1dcb84c1ff37..f298c91f4f4e 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -517,6 +517,7 @@ int btintel_version_info_tlv(struct hci_dev *hdev, case 0x20: /* Scorpious Peak2 */ case 0x21: /* Scorpious Peak2 F */ case 0x22: /* BlazarIW (BzrIW) */ + case 0x23: /* Draco */ break; default: bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)", @@ -3617,6 +3618,7 @@ void btintel_set_msft_opcode(struct hci_dev *hdev, u8 hw_variant) case 0x20: case 0x21: case 0x22: + case 0x23: hci_set_msft_opcode(hdev, 0xFC1E); break; default: @@ -3960,6 +3962,7 @@ static int btintel_setup_combined(struct hci_dev *hdev) case 0x20: case 0x21: case 0x22: + case 0x23: /* Display version information of TLV type */ btintel_version_info_tlv(hdev, &ver_tlv); diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index b3c4c6f87424..9cf136c6c716 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -62,6 +62,7 @@ struct intel_tlv { #define BTINTEL_CNVI_SCP 0xA00 /* Scorpius Peak - Panther Lake */ #define BTINTEL_CNVI_SCP2 0xA10 /* Scorpius Peak2 - Nova Lake */ #define BTINTEL_CNVI_SCP2F 0xA20 /* Scorpius Peak2F - Nova Lake */ +#define BTINTEL_CNVI_DRACO 0xA30 /* Draco */ /* CNVR */ #define BTINTEL_CNVR_FMP2 0x910 diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index a7aea950c73f..127ecebd0331 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -2292,6 +2292,7 @@ static void btintel_pcie_read_hwexp(struct btintel_pcie_data *data) case BTINTEL_CNVI_SCP: case BTINTEL_CNVI_SCP2: case BTINTEL_CNVI_SCP2F: + case BTINTEL_CNVI_DRACO: break; default: bt_dev_err(data->hdev, "Unsupported cnvi 0x%8.8x", data->dmp_hdr.cnvi_top); @@ -3471,6 +3472,7 @@ static int btintel_pcie_setup_internal(struct hci_dev *hdev) case 0x20: /* ScP2 */ case 0x21: /* ScP2 F */ case 0x22: /* BzrIW */ + case 0x23: /* DrC */ /* Display version information of TLV type */ btintel_version_info_tlv(hdev, &ver_tlv); From d54601f21faf1ab5728e98e2102c3f738be0c177 Mon Sep 17 00:00:00 2001 From: Quentin Strydom Date: Mon, 28 Sep 2026 15:36:55 +0100 Subject: [PATCH 1707/2126] Bluetooth: btusb: add ASUS 0b05:1868 to QCA Rome quirks The Bluetooth controller with USB ID 0b05:1868 found on ASUS systems uses a Qualcomm QCA Rome chipset, but is currently matched only by the generic Bluetooth USB entry. Without BTUSB_QCA_ROME, the driver does not load the QCA rampatch and NVM firmware. BLE scanning also repeatedly reports: Bluetooth: hci0: unexpected event for opcode 0x2005 Mark the device as BTUSB_QCA_ROME with wideband speech support, in line with the other QCA Rome USB IDs. With the quirk applied, btusb loads: qca/rampatch_usb_00000302.bin qca/nvm_usb_00000302.bin and the unexpected LE Set Random Address completion events are no longer observed. Tested-on: ASUS USB 0b05:1868, QCA Rome 0x302 Signed-off-by: Quentin Strydom Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index be47ac894b6c..1ede12515bcc 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -273,6 +273,8 @@ static const struct usb_device_id quirks_table[] = { { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, /* QCA ROME chipset */ + { USB_DEVICE(0x0b05, 0x1868), .driver_info = BTUSB_QCA_ROME | + BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME | BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME | From 7de1fcfb783b0633684c0eff0c18d6f4e12e8954 Mon Sep 17 00:00:00 2001 From: Catherine L Date: Fri, 18 Sep 2026 19:19:19 +0530 Subject: [PATCH 1708/2126] Bluetooth: btintel_pcie: Add CNVi ID for Titan Lake (Scorpius Peak2 C0) Define BTINTEL_CNVI_SCP2_C0 (0xA11) for the Scorpius Peak2 C0 stepping used on Titan Lake platforms and handle it in btintel_pcie_read_hwexp() alongside existing Scorpius Peak2 variants. Signed-off-by: Catherine L Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.h | 1 + drivers/bluetooth/btintel_pcie.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index 9cf136c6c716..ff7c1d623007 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -61,6 +61,7 @@ struct intel_tlv { #define BTINTEL_CNVI_BLAZARU 0x930 /* BlazarU - Meteor Lake */ #define BTINTEL_CNVI_SCP 0xA00 /* Scorpius Peak - Panther Lake */ #define BTINTEL_CNVI_SCP2 0xA10 /* Scorpius Peak2 - Nova Lake */ +#define BTINTEL_CNVI_SCP2_C0 0xA11 /* Scorpius Peak2 C0 - Titan Lake */ #define BTINTEL_CNVI_SCP2F 0xA20 /* Scorpius Peak2F - Nova Lake */ #define BTINTEL_CNVI_DRACO 0xA30 /* Draco */ diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 127ecebd0331..d58b1a42f092 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -2291,6 +2291,7 @@ static void btintel_pcie_read_hwexp(struct btintel_pcie_data *data) break; case BTINTEL_CNVI_SCP: case BTINTEL_CNVI_SCP2: + case BTINTEL_CNVI_SCP2_C0: case BTINTEL_CNVI_SCP2F: case BTINTEL_CNVI_DRACO: break; From 12997a385f7140c66f733128b76845fd906c270a Mon Sep 17 00:00:00 2001 From: "Vladimir V. Kondratyev" Date: Mon, 28 Sep 2026 22:40:00 +0530 Subject: [PATCH 1709/2126] Bluetooth: btintel_pcie: fix stale cache in set_dxstate fallback check btintel_pcie returns -16 (EBUSY) during suspend, causing the entire suspend operation to abort on Intel Lunar Lake hardware. The system immediately resumes after every suspend attempt: Bluetooth: hci0: Timeout (200 ms) on alive interrupt for D2 entry, retry count 0 Bluetooth: hci0: Timeout (200 ms) on alive interrupt for D2 entry, retry count 1 Bluetooth: hci0: Timeout (200 ms) on alive interrupt for D2 entry, retry count 2 btintel_pcie 0000:00:14.7: PM: pci_pm_suspend(): btintel_pcie_suspend [btintel_pcie] returns -16 btintel_pcie 0000:00:14.7: PM: dpm_run_callback(): pci_pm_suspend returns -16 btintel_pcie 0000:00:14.7: PM: failed to suspend async: error -16 PM: Some devices failed to suspend, or early wake event detected btintel_pcie_set_dxstate() falls back to checking the controller state via btintel_pcie_in_d3/d0() when the alive interrupt is missed. However, these helpers read boot_stage_cache, which is only updated by the interrupt handler. As such, if the interrupt was missed, the cache is stale and the fallback check always fails, exhausting all retries and returning -EBUSY, causing suspend to abort. The fix involves re-reading the hardware register before the fallback state check, consistent with btintel_pcie_resume(). Fixes: 88c6216a52ea ("Bluetooth: btintel_pcie: Suspend/Resume: Controller doorbell interrupt handling") Link: https://bugzilla.kernel.org/show_bug.cgi?id=221481 Link: https://lore.kernel.org/linux-bluetooth/20260830151550.44687-1-lsa.uz@pm.me/ Signed-off-by: Vladimir V. Kondratyev Tested-by: Sergey Lebedev Signed-off-by: Sergey Lebedev Signed-off-by: Ravindra Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 8 +++++--- drivers/bluetooth/btintel_pcie.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index d58b1a42f092..23b651149799 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -4234,10 +4234,12 @@ static int btintel_pcie_set_dxstate(struct btintel_pcie_data *data, u32 dxstate) BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES, BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0); - /* A hardware bug may cause the alive interrupt to be missed. - * Check if the controller reached the expected state and retry - * the operation only if it hasn't. + /* A hardware bug may cause the alive interrupt to be missed. Refresh + * boot_stage_cache from hardware, since only the interrupt handler + * updates it. Finally retry only if the state check still fails. */ + data->boot_stage_cache = btintel_pcie_rd_reg32(data, + BTINTEL_PCIE_CSR_BOOT_STAGE_REG); if (dxstate == BTINTEL_PCIE_STATE_D0) { if (btintel_pcie_in_d0(data)) return 0; diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index f35f80f800ed..016795fcbccc 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -51,6 +51,7 @@ #define BTINTEL_PCIE_CSR_BOOT_STAGE_DEVICE_HALTED (BIT(14)) #define BTINTEL_PCIE_CSR_BOOT_STAGE_MAC_ACCESS_ON (BIT(16)) #define BTINTEL_PCIE_CSR_BOOT_STAGE_ALIVE (BIT(23)) +/* Reflects live D-state. Updated by hardware on every D-state transition. */ #define BTINTEL_PCIE_CSR_BOOT_STAGE_D3_STATE_READY (BIT(24)) #define BTINTEL_PCIE_CSR_DOORBELL_MBOX_READ_CONFIRM (BIT(4)) From 2926eb396711f1f843a0aafee6778822f50e9021 Mon Sep 17 00:00:00 2001 From: Ravindra Date: Mon, 28 Sep 2026 22:40:01 +0530 Subject: [PATCH 1710/2126] Bluetooth: btintel_pcie: fix PM flow for S0ix, S3 and S4 Fix two issues in the PM suspend/resume path: 1. S3 was handled the same as S0ix, keeping the controller on the D3hot-style path. That caused resume instability because S3 can remove power from the controller, unlike s2idle/S0ix. Use pm_suspend_target_state to distinguish them: D3_HOT for S0ix and D3_COLD for S3/S4. Add .restore to force FLR-based firmware recovery after S4 and S3 (PM_SUSPEND_MEM), as power is lost. S0ix resumes via a normal D0 transition. 2. During hibernation, .freeze() puts the controller into the D3cold state without any loss of power, and the flow normally continues to .poweroff(). If hibernation instead fails, .thaw() is called to bring the controller back up, and the old code routed it through btintel_pcie_resume(), which forced FLR-based firmware recovery whenever data->pm_sx_event was PM_EVENT_FREEZE. That check was incorrect: since the controller's power was never actually removed on this failed-hibernation path, FLR-based recovery is unnecessary. Remove pm_sx_event and route .thaw through a normal D0 transition instead; FLR-based recovery is retained only in .restore, where genuine S4 power loss requires it. Tested with: S0ix: sudo sh -c 'echo "+40" > /sys/class/rtc/rtc0/wakealarm' && \ echo freeze | sudo tee /sys/power/state S3: sudo rtcwake -m mem -s 60 S4: sudo rtcwake -m disk -s 60 Fixes: e57362f4911b ("Bluetooth: btintel_pcie: Add support for _suspend() / _resume()") Assisted-by: GitHub-Copilot:GPT5 Signed-off-by: Ravindra Tested-by: Sergey Lebedev Reviewed-by: Paul Menzel Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 58 +++++++++++++++++++++----------- drivers/bluetooth/btintel_pcie.h | 2 -- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 23b651149799..d613536dca80 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -4211,7 +4212,8 @@ static void btintel_pcie_coredump(struct device *dev) static int btintel_pcie_set_dxstate(struct btintel_pcie_data *data, u32 dxstate) { - int retry = 0, status; + int retry = 0; + long status; u32 dx_intr_timeout_ms = 200; do { @@ -4263,18 +4265,23 @@ static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg) data = pci_get_drvdata(pdev); - dxstate = (mesg.event == PM_EVENT_SUSPEND ? - BTINTEL_PCIE_STATE_D3_HOT : BTINTEL_PCIE_STATE_D3_COLD); - - data->pm_sx_event = mesg.event; + /* S0ix (s2idle) uses D3_HOT; S3, freeze and hibernate use D3_COLD. */ + if (mesg.event == PM_EVENT_SUSPEND && + pm_suspend_target_state == PM_SUSPEND_TO_IDLE) + dxstate = BTINTEL_PCIE_STATE_D3_HOT; + else + dxstate = BTINTEL_PCIE_STATE_D3_COLD; start = ktime_get(); /* Refer: 6.4.11.7 -> Platform power management */ err = btintel_pcie_set_dxstate(data, dxstate); - if (err) + if (err) { + bt_dev_err(data->hdev, "Failed to set dxstate:%u (%d)", + dxstate, err); return err; + } bt_dev_dbg(data->hdev, "device entered into d3 state from d0 in %lld us", @@ -4297,7 +4304,7 @@ static int btintel_pcie_freeze(struct device *dev) return btintel_pcie_suspend_late(dev, PMSG_FREEZE); } -static int btintel_pcie_resume(struct device *dev) +static int btintel_pcie_resume_event(struct device *dev, pm_message_t mesg) { struct pci_dev *pdev = to_pci_dev(dev); struct btintel_pcie_data *data; @@ -4305,19 +4312,15 @@ static int btintel_pcie_resume(struct device *dev) int err; data = pci_get_drvdata(pdev); - data->gp0_received = false; start = ktime_get(); - /* When the system enters S4 (hibernate) mode, bluetooth device loses - * power, which results in the erasure of its loaded firmware. - * Consequently, function level reset (flr) is required on system - * resume to bring the controller back into an operational state by - * initiating a new firmware download. + /* S3 and S4 may cut power, erasing the firmware. Force FLR to recover + * instead of a normal D0 transition. */ - - if (data->pm_sx_event == PM_EVENT_FREEZE || - data->pm_sx_event == PM_EVENT_HIBERNATE) { + if (mesg.event == PM_EVENT_RESTORE || + (mesg.event == PM_EVENT_RESUME && + pm_suspend_target_state == PM_SUSPEND_MEM)) { set_bit(BTINTEL_PCIE_CORE_HALTED, &data->flags); btintel_pcie_request_reset(data, BTINTEL_PCIE_IOSF_PRR_FLR); return 0; @@ -4326,7 +4329,9 @@ static int btintel_pcie_resume(struct device *dev) /* Refer: 6.4.11.7 -> Platform power management */ err = btintel_pcie_set_dxstate(data, BTINTEL_PCIE_STATE_D0); - if (err == 0) { + if (err) { + bt_dev_err(data->hdev, "Failed to set D0 state (%d)", err); + } else { bt_dev_dbg(data->hdev, "device entered into d0 state from d3 in %lld us", ktime_to_us(ktime_get() - start)); @@ -4351,13 +4356,28 @@ static int btintel_pcie_resume(struct device *dev) return err; } +static int btintel_pcie_resume(struct device *dev) +{ + return btintel_pcie_resume_event(dev, PMSG_RESUME); +} + +static int btintel_pcie_restore(struct device *dev) +{ + return btintel_pcie_resume_event(dev, PMSG_RESTORE); +} + +static int btintel_pcie_thaw(struct device *dev) +{ + return btintel_pcie_resume_event(dev, PMSG_THAW); +} + static const struct dev_pm_ops btintel_pcie_pm_ops = { .suspend = btintel_pcie_suspend, .resume = btintel_pcie_resume, .freeze = btintel_pcie_freeze, - .thaw = btintel_pcie_resume, + .thaw = btintel_pcie_thaw, .poweroff = btintel_pcie_hibernate, - .restore = btintel_pcie_resume, + .restore = btintel_pcie_restore, }; static struct pci_driver btintel_pcie_driver = { diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 016795fcbccc..3030b4e8b750 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -713,7 +713,6 @@ struct btintel_pcie_ini_dump_info { * @txq: TX Queue struct * @rxq: RX Queue struct * @alive_intr_ctxt: Alive interrupt context - * @pm_sx_event: PM event on which system got suspended */ struct btintel_pcie_data { struct pci_dev *pdev; @@ -773,7 +772,6 @@ struct btintel_pcie_data { struct btintel_pcie_dbgc dbgc; struct btintel_pcie_mdbgc mdbgc; struct btintel_pcie_dump_header dmp_hdr; - u8 pm_sx_event; u32 debug_evt_addr; u32 debug_evt_size; dma_addr_t debug_table_addr; From 4f6ead67b93bcc4ba1fbbf97c7c8bc5a0c45b80b Mon Sep 17 00:00:00 2001 From: Sergey Lebedev Date: Mon, 28 Sep 2026 22:40:02 +0530 Subject: [PATCH 1711/2126] Bluetooth: btintel_pcie: verify and serialize D-state transitions The gp0_received flag only reports that the GP0 handler ran. It does not contain proof that the handler completed the requested D-state transition: a matched case can leave the state unchanged. Refresh the boot-stage register before treating the transition as successful. When the controller is in D0 but the handler did not re-arm the interface, restore the alive context, reset the IA, restart RX, and complete the mailbox/alive handshake. Propagate RX setup failures to the PM caller. Likewise, when the controller is in D3 but the handler did not record it, restore the alive context so the next transition dispatches correctly. Serialize the alive-context claim between the GP0 handler and the set_dxstate() fallback with irq_lock. Only the path that claims the D0 transition resets the IA and rearms RX, avoiding concurrent updates to the shared ring state. Co-developed-by: Ravindra Signed-off-by: Ravindra Signed-off-by: Sergey Lebedev Fixes: 88c6216a52ea ("Bluetooth: btintel_pcie: Suspend/Resume: Controller doorbell interrupt handling") Tested-by: Sergey Lebedev Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 80 +++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index d613536dca80..782e4ff4c887 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -1975,6 +1975,10 @@ static void btintel_pcie_msix_gp0_handler(struct btintel_pcie_data *data) submit_rx = false; signal_waitq = false; + /* Serialize the alive_intr_ctxt claim against set_dxstate()'s + * register-based fallback, which can run concurrently. + */ + spin_lock(&data->irq_lock); switch (data->alive_intr_ctxt) { case BTINTEL_PCIE_ROM: data->alive_intr_ctxt = BTINTEL_PCIE_FW_DL; @@ -2030,6 +2034,7 @@ static void btintel_pcie_msix_gp0_handler(struct btintel_pcie_data *data) data->alive_intr_ctxt); break; } + spin_unlock(&data->irq_lock); if (submit_rx) { btintel_pcie_reset_ia(data); @@ -4212,7 +4217,7 @@ static void btintel_pcie_coredump(struct device *dev) static int btintel_pcie_set_dxstate(struct btintel_pcie_data *data, u32 dxstate) { - int retry = 0; + int retry = 0, err; long status; u32 dx_intr_timeout_ms = 200; @@ -4224,30 +4229,73 @@ static int btintel_pcie_set_dxstate(struct btintel_pcie_data *data, u32 dxstate) status = wait_event_timeout(data->gp0_wait_q, data->gp0_received, msecs_to_jiffies(dx_intr_timeout_ms)); - if (status) - return 0; + if (!status) { + bt_dev_warn(data->hdev, + "Timeout (%u ms) on alive interrupt for D%d entry, retry count %d", + dx_intr_timeout_ms, dxstate, retry); - bt_dev_warn(data->hdev, - "Timeout (%u ms) on alive interrupt for D%d entry, retry count %d", - dx_intr_timeout_ms, dxstate, retry); + /* clear gp0 cause */ + btintel_pcie_clr_reg_bits(data, + BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES, + BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0); + } - /* clear gp0 cause */ - btintel_pcie_clr_reg_bits(data, - BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES, - BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0); - - /* A hardware bug may cause the alive interrupt to be missed. Refresh - * boot_stage_cache from hardware, since only the interrupt handler - * updates it. Finally retry only if the state check still fails. + /* gp0_received is set at the top of the handler, before the switch on + * alive_intr_ctxt. Error and lockdown are filtered out above it, but a + * matched case can still complete without doing anything - D3 breaks + * unchanged while the controller has not reached D0 - and a hardware + * bug may drop the interrupt outright. Either way the flag says a gp0 + * was handled, not that the transition completed, and only the register + * knows. Refresh the cache here and retry only if the state check still + * fails. */ data->boot_stage_cache = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_BOOT_STAGE_REG); if (dxstate == BTINTEL_PCIE_STATE_D0) { - if (btintel_pcie_in_d0(data)) + if (btintel_pcie_in_d0(data)) { + bool armed; + + /* Claim the transition under irq_lock so a + * concurrent gp0 handler run cannot also arm RX. + */ + spin_lock(&data->irq_lock); + armed = data->alive_intr_ctxt == BTINTEL_PCIE_D0; + if (!armed) + data->alive_intr_ctxt = BTINTEL_PCIE_D0; + spin_unlock(&data->irq_lock); + + if (armed) + return 0; + + /* Do what the handler's D3 -> D0 branch + * would have done, unless it already has. + */ + btintel_pcie_reset_ia(data); + err = btintel_pcie_start_rx(data); + if (err) + return err; + + /* Complete the mbox<->alive handshake */ + if (test_and_clear_bit(BTINTEL_PCIE_MBOX_PARSE_PENDING, + &data->flags)) { + set_bit(BTINTEL_PCIE_MBOX_PARSE_READY, &data->flags); + wake_up(&data->mbox_parse_wait_q); + } + return 0; + } } else { - if (btintel_pcie_in_d3(data)) + if (btintel_pcie_in_d3(data)) { + /* Do what the handler's D0 -> D3 branch + * would have done, unless it already has. + */ + spin_lock(&data->irq_lock); + if (data->alive_intr_ctxt != BTINTEL_PCIE_D3) + data->alive_intr_ctxt = BTINTEL_PCIE_D3; + spin_unlock(&data->irq_lock); + return 0; + } } } while (++retry < BTINTEL_PCIE_DX_TRANSITION_MAX_RETRIES); From f2cee6e2aa35a6a701ce3f4bedf20273c808361f Mon Sep 17 00:00:00 2001 From: Ravindra Date: Mon, 28 Sep 2026 22:40:03 +0530 Subject: [PATCH 1712/2126] Bluetooth: btintel_pcie: clear the GP0 cause with a W1C write MSIX_HW_INT_CAUSES is a write-one-to-clear register. Using a read-modify-write helper writes zero to GP0, leaving the cause uncleared, and can acknowledge unrelated pending causes through the read value. Write only the GP0 bit directly, matching the interrupt handler's W1C acknowledgment convention. Fixes: 88c6216a52ea ("Bluetooth: btintel_pcie: Suspend/Resume: Controller doorbell interrupt handling") Signed-off-by: Ravindra Tested-by: Sergey Lebedev Reviewed-by: Sergey Lebedev Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 782e4ff4c887..3a555aa50c87 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -4234,10 +4234,12 @@ static int btintel_pcie_set_dxstate(struct btintel_pcie_data *data, u32 dxstate) "Timeout (%u ms) on alive interrupt for D%d entry, retry count %d", dx_intr_timeout_ms, dxstate, retry); - /* clear gp0 cause */ - btintel_pcie_clr_reg_bits(data, - BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES, - BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0); + /* MSIX_HW_INT_CAUSES is W1C. Write only GP0 so other + * pending causes are not acknowledged here. + */ + btintel_pcie_wr_reg32(data, + BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES, + BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0); } /* gp0_received is set at the top of the handler, before the switch on From fa96916cfd05ceb1c26af0b2ea73daf5481cad2d Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 29 Sep 2026 12:15:56 +0530 Subject: [PATCH 1713/2126] Bluetooth: btusb: Preserve event and ACL packet ordering When force_poll_sync is enabled, commit 800fe5ec302e ("Bluetooth: btusb: Add support for queuing during polling interval") defers ACL delivery to the RX worker. The event path currently wakes that worker before delivering the event, so queued ACL data can reach HCI first. Deliver the event before waking the worker. This preserves the intended event-first ordering and the event callback's return value. Fixes: 800fe5ec302e ("Bluetooth: btusb: Add support for queuing during polling interval") Signed-off-by: Kiran K Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb_main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 1ede12515bcc..cccdfb0461fe 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -1311,13 +1311,16 @@ static inline void btusb_free_frags(struct btusb_data *data) static int btusb_recv_event(struct hci_dev *hdev, struct sk_buff *skb) { struct btusb_data *data = hci_get_drvdata(hdev); + int err; + + err = data->recv_event(hdev, skb); if (data->intr_interval) { /* Trigger dequeue immediately if an event is received */ schedule_delayed_work(&data->rx_work, 0); } - return data->recv_event(hdev, skb); + return err; } static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count) From df5e35f1663abc2702cf9f9e7eba024129ac5df1 Mon Sep 17 00:00:00 2001 From: Junjie Cao Date: Sun, 20 Sep 2026 10:02:27 +0800 Subject: [PATCH 1714/2126] Bluetooth: btusb: drop BROKEN_EXT_SCAN quirk for 0bda:a728 Commit 5ead2063611a ("Bluetooth: btrtl: fix RTL8761B/BU broken LE extended scan") set HCI_QUIRK_BROKEN_EXT_SCAN on every RTL8761B, and commit ca0583c24661 ("Bluetooth: btusb: limit RTL8761B BROKEN_EXT_SCAN quirk to 0bda:a728") kept it on 0bda:a728 on the assumption that the USB id separates dongles with broken extended scan from those with a broken legacy scan path. It does not. An 0bda:a728 unit (RTL8761BUV, fw 0xdfc6d922) on 6.18.51 fails the same way the UB500 and 0bda:8771 did: LE Set Scan Enable (0x200c) times out with -110 and btusb resets the device. With the flag removed from the table entry, scanning works on that unit. Two dongles with the same USB id need opposite settings, so the device table cannot key the quirk either. The costs are not symmetric. Without the quirk, the unit it was written for gets -EBUSY on LE Set Extended Scan Enable (0x2042) while a connection is up. With it, 0x200c times out and btusb resets the device on three reported units, two of them in a re-enumeration loop. Remove the flag and the table entry. 0bda:a728 matches the generic Realtek entry again and runs without the quirk, as before v7.2. Reported-by: Andy Tsvetinskiy Closes: https://lore.kernel.org/all/CAE4bxw+ofDFVx0aTHqCrzns9oP1CRQDm_wzeyHPeMBYOhSpcuA@mail.gmail.com/ Fixes: 5ead2063611a ("Bluetooth: btrtl: fix RTL8761B/BU broken LE extended scan") Fixes: ca0583c24661 ("Bluetooth: btusb: limit RTL8761B BROKEN_EXT_SCAN quirk to 0bda:a728") Cc: stable@vger.kernel.org Signed-off-by: Junjie Cao Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb_main.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index cccdfb0461fe..3518f92ebbd3 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -70,7 +70,6 @@ static struct usb_driver btusb_driver; #define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26) #define BTUSB_ACTIONS_SEMI BIT(27) #define BTUSB_BARROT BIT(28) -#define BTUSB_BROKEN_EXT_SCAN BIT(29) #define BTUSB_QUALCOMM BIT(30) static const struct usb_device_id btusb_table[] = { @@ -650,10 +649,6 @@ static const struct usb_device_id quirks_table[] = { { USB_DEVICE(0x0489, 0xe130), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, - /* Realtek 8761BU Bluetooth devices */ - { USB_DEVICE(0x0bda, 0xa728), .driver_info = BTUSB_REALTEK | - BTUSB_BROKEN_EXT_SCAN }, - /* Realtek Bluetooth devices */ { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), .driver_info = BTUSB_REALTEK }, @@ -4754,9 +4749,6 @@ static int btusb_probe(struct usb_interface *intf, if (id->driver_info & BTUSB_INVALID_LE_STATES) hci_set_quirk(hdev, HCI_QUIRK_BROKEN_LE_STATES); - if (id->driver_info & BTUSB_BROKEN_EXT_SCAN) - hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_SCAN); - if (id->driver_info & BTUSB_DIGIANSWER) { data->cmdreq_type = USB_TYPE_VENDOR; hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE); From 1b723bd2945df4c75d7a4a4525660704ef8f4df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Thu, 1 Oct 2026 15:51:08 +0200 Subject: [PATCH 1715/2126] Bluetooth: MGMT: Add management security level changed event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an event on device security level or encryption type change to let user space know which level is currently in use. Reset security level to 0 on disconnection so further connections will correctly report security level changes. This will be used for BlueZ qualification automation. Assisted-by: GPT:GPT-5.3-Codex Assisted-by: Copilot:claude-sonnet-5 Signed-off-by: Frédéric Danis Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 18 +++-- include/net/bluetooth/mgmt.h | 14 ++++ net/bluetooth/hci_conn.c | 28 ++++++++ net/bluetooth/hci_event.c | 118 +++++++++++++++++++++++++++++-- net/bluetooth/mgmt.c | 66 ++++++++++++++++- 5 files changed, 232 insertions(+), 12 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index fb85a0ccb250..f631d9484a0b 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -2255,6 +2255,8 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) conn->security_cfm_cb(conn, status); } +void mgmt_security_level_changed(struct hci_conn *conn); + static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) { struct hci_cb *cb; @@ -2277,11 +2279,19 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) encrypt = 0x01; if (!status) { - if (conn->sec_level == BT_SECURITY_SDP) + /* Callers either set conn->sec_level = conn->pending_sec_level + * unconditionally before calling this function, or never + * reach here with status == 0 (e.g. conn->state == BT_CONFIG + * returns early above, or status is actually an error). So + * conn->pending_sec_level is never greater than + * conn->sec_level at this point; only the initial + * BT_SECURITY_SDP -> BT_SECURITY_LOW bump can still happen + * here. + */ + if (conn->sec_level == BT_SECURITY_SDP) { conn->sec_level = BT_SECURITY_LOW; - - if (conn->pending_sec_level > conn->sec_level) - conn->sec_level = conn->pending_sec_level; + mgmt_security_level_changed(conn); + } } mutex_lock(&hci_cb_list_lock); diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 1e22eab1081c..b02e915bb44c 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -1221,3 +1221,17 @@ struct mgmt_ev_conn_subrate { __le16 cont_num; __le16 supv_timeout; } __packed; + +#define MGMT_CONN_SEC_ENCRYPT_NONE 0x00 +#define MGMT_CONN_SEC_ENCRYPT_E0 0x01 +#define MGMT_CONN_SEC_ENCRYPT_AES_CCM 0x02 + +#define MGMT_SEC_LEVEL_CHANGED_PARAM_LEVEL 0x0000 +#define MGMT_SEC_LEVEL_CHANGED_PARAM_ENC_TYPE 0x0001 + +#define MGMT_EV_SECURITY_LEVEL_CHANGED 0x0034 +struct mgmt_ev_security_level_changed { + struct mgmt_addr_info addr; + __u8 tlv_length; + __u8 tlv_data[] __counted_by(tlv_length); +} __packed; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index cf44452e0766..29da3fe2b953 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1233,6 +1233,29 @@ static void hci_conn_unlink(struct hci_conn *conn) if (!conn->parent) { struct hci_link *link, *t; + conn->sec_level = BT_SECURITY_SDP; + clear_bit(HCI_CONN_ENCRYPT, &conn->flags); + clear_bit(HCI_CONN_AES_CCM, &conn->flags); + /* mgmt_security_level_changed() reports the reset only if + * this connection was actually reported to userspace as + * connected (it checks HCI_CONN_MGMT_CONNECTED itself), so it + * must be called before the flag is cleared below. + * Callers that already know whether the connection was + * mgmt-connected (e.g. disconnect event handlers) only peek + * at the flag, so it is still set here; this is the place + * actually clearing it. + * + * Skip the report if hdev is down: this means + * hci_dev_close_sync()/hci_conn_hash_flush() is in progress + * and no MGMT_EV_DEVICE_DISCONNECTED was ever sent for this + * connection, so sending a security level reset here would + * be a spurious, order-less event; the adapter-wide powered + * off notification is enough for userspace to reset state. + */ + if (test_bit(HCI_UP, &hdev->flags)) + mgmt_security_level_changed(conn); + clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); + list_for_each_entry_safe(link, t, &conn->link_list, list) { struct hci_conn *child = link->conn; @@ -1543,6 +1566,11 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, conn->pending_sec_level = sec_level; } + /* Do not report the security level here: conn->dst may still hold + * the peer's RPA instead of its identity address, and the connection + * is not established yet. le_conn_complete_evt() reports it once the + * connection completes and the identity address has been resolved. + */ conn->sec_level = BT_SECURITY_LOW; conn->conn_timeout = conn_timeout; conn->le_adv_phy = phy; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 5ac2357e92c9..a3359aaad001 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -732,6 +732,14 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, bt_dev_err(hdev, "failed to read key size for handle %u", handle); conn->enc_key_size = 0; + clear_bit(HCI_CONN_ENCRYPT, &conn->flags); + clear_bit(HCI_CONN_AES_CCM, &conn->flags); + /* Downgrade to reflect the connection no longer being + * encrypted, instead of advertising a stale elevated + * security level alongside MGMT_CONN_SEC_ENCRYPT_NONE. + */ + if (conn->sec_level > BT_SECURITY_LOW) + conn->sec_level = BT_SECURITY_LOW; } else { u8 *key_enc_size = hci_conn_key_enc_size(conn); @@ -755,6 +763,25 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, status = HCI_ERROR_AUTH_FAILURE; clear_bit(HCI_CONN_ENCRYPT, &conn->flags); clear_bit(HCI_CONN_AES_CCM, &conn->flags); + /* Downgrade to reflect the connection no longer being + * encrypted, instead of advertising a stale elevated + * security level alongside MGMT_CONN_SEC_ENCRYPT_NONE. + */ + if (conn->sec_level > BT_SECURITY_LOW) + conn->sec_level = BT_SECURITY_LOW; + } else { + /* Pre-apply hci_encrypt_cfm()'s own upgrade rules + * here unconditionally on success, so its internal + * change check below always finds nothing new: this + * function remains the sole place deciding whether + * and when to report the change, regardless of + * whether the caller already touched conn->sec_level + * (e.g. hci_encrypt_change_evt()) or not. + */ + if (conn->sec_level == BT_SECURITY_SDP) + conn->sec_level = BT_SECURITY_LOW; + if (conn->pending_sec_level > conn->sec_level) + conn->sec_level = conn->pending_sec_level; } /* Update the key encryption size with the connection one */ @@ -764,6 +791,13 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, hci_encrypt_cfm(conn, status); + /* mgmt_security_level_changed() only reports the change for + * connections already announced to userspace (it checks + * HCI_CONN_MGMT_CONNECTED itself); otherwise it is a no-op here and + * reporting is deferred to mgmt_device_connected(). + */ + mgmt_security_level_changed(conn); + done: hci_dev_unlock(hdev); @@ -2762,7 +2796,11 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) if (hdev->suspended) conn->state = BT_CLOSED; - mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); + /* Only peek at the flag here: hci_conn_del() (via hci_conn_unlink()) + * still needs it set to know whether to report the security level + * reset, so it is consumed there instead of here. + */ + mgmt_conn = test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); if (conn->type == ACL_LINK) { if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) @@ -3366,6 +3404,16 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data, bt_dev_err(hdev, "connection err: %ld", PTR_ERR(conn)); goto unlock; } + + /* Unlike outgoing BR/EDR connections, conn->sec_level is not + * set at connection request time for incoming connections, + * so it is still at its zero-initialized value + * (BT_SECURITY_SDP) here. Set it to BT_SECURITY_LOW so + * mgmt_device_connected() later reports the correct initial + * security level instead of a transient, never-really-in-use + * SDP value. + */ + conn->sec_level = BT_SECURITY_LOW; } memcpy(conn->dev_class, ev->dev_class, 3); @@ -3432,7 +3480,11 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data, conn->state = BT_CLOSED; - mgmt_connected = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); + /* Only peek at the flag here: hci_conn_del() (via hci_conn_unlink()) + * still needs it set to know whether to report the security level + * reset, so it is consumed there instead of here. + */ + mgmt_connected = test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); if (test_bit(HCI_CONN_AUTH_FAILURE, &conn->flags)) reason = MGMT_DEV_DISCONN_AUTH_FAILURE; @@ -3516,6 +3568,15 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, void *data, if (!ev->status) { clear_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); set_bit(HCI_CONN_AUTH, &conn->flags); + /* Authentication alone does not imply encryption: for SSP + * capable devices, encryption is only requested below, and + * for legacy devices it is requested by a separate + * HCI_OP_SET_CONN_ENCRYPT command. Do not report the new + * security level yet, to avoid userspace seeing an elevated + * level alongside no encryption; hci_encrypt_change_evt() + * (possibly via hci_cc_read_enc_key_size() for ACL links) + * reports it once encryption is actually confirmed. + */ conn->sec_level = conn->pending_sec_level; } else { if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) @@ -3632,9 +3693,28 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, if ((conn->type == ACL_LINK && ev->encrypt == 0x02) || conn->type == LE_LINK) set_bit(HCI_CONN_AES_CCM, &conn->flags); + + /* For ACL links the encryption key size is still + * validated below via hci_read_enc_key_size(). Its + * completion handler, hci_cc_read_enc_key_size(), + * reports the final security level so userspace does + * not see a transient "encrypted" state that a + * key-size downgrade would immediately invalidate. + */ + if (conn->type != ACL_LINK) + mgmt_security_level_changed(conn); } else { clear_bit(HCI_CONN_ENCRYPT, &conn->flags); clear_bit(HCI_CONN_AES_CCM, &conn->flags); + /* Elevated security levels (MEDIUM and above) require + * encryption, so downgrade to reflect the connection + * no longer being encrypted before reporting, instead + * of advertising a stale elevated level alongside + * MGMT_CONN_SEC_ENCRYPT_NONE. + */ + if (conn->sec_level > BT_SECURITY_LOW) + conn->sec_level = BT_SECURITY_LOW; + mgmt_security_level_changed(conn); } } @@ -3667,8 +3747,14 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, /* Try reading the encryption key size for encrypted ACL links */ if (!ev->status && ev->encrypt && conn->type == ACL_LINK) { - if (hci_read_enc_key_size(hdev, conn)) + if (hci_read_enc_key_size(hdev, conn)) { + /* Could not even issue the key-size read: report the + * security level now since hci_cc_read_enc_key_size() + * will not run to do it. + */ + mgmt_security_level_changed(conn); goto notify; + } goto unlock; } @@ -5228,8 +5314,14 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data, if (conn->type != LE_LINK) goto unlock; - if (!ev->status) + if (!ev->status) { + bool sec_level_changed = + conn->sec_level != conn->pending_sec_level; + conn->sec_level = conn->pending_sec_level; + if (sec_level_changed) + mgmt_security_level_changed(conn); + } clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); @@ -5858,9 +5950,16 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, goto unlock; } + /* Unlike outgoing BR/EDR connections, conn->sec_level is not set at + * connection request time for LE, so it is still at its + * zero-initialized value (BT_SECURITY_SDP) here. Set it to + * BT_SECURITY_LOW before reporting the connection so + * mgmt_device_connected() reports the correct initial security level + * instead of a transient, never-really-in-use SDP value. + */ + conn->sec_level = BT_SECURITY_LOW; mgmt_device_connected(hdev, conn, NULL, 0); - conn->sec_level = BT_SECURITY_LOW; conn->state = BT_CONFIG; /* Store current advertising instance as connection advertising instance @@ -7311,8 +7410,13 @@ static void hci_le_big_sync_lost_evt(struct hci_dev *hdev, void *data, BT_CONNECTED, HCI_ROLE_SLAVE))) { if (!mgmt_conn) { - mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, - &bis->flags); + /* Only peek at the flag here: hci_conn_del() (via + * hci_conn_unlink()) still needs it set to know + * whether to report the security level reset, so + * it is consumed there instead of here. + */ + mgmt_conn = test_bit(HCI_CONN_MGMT_CONNECTED, + &bis->flags); mgmt_device_disconnected(hdev, &bis->dst, bis->type, bis->dst_type, ev->reason, mgmt_conn); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 9b4688015abf..aea3482e3893 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -177,6 +177,7 @@ static const u16 mgmt_events[] = { MGMT_EV_CONTROLLER_RESUME, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, MGMT_EV_ADV_MONITOR_DEVICE_LOST, + MGMT_EV_SECURITY_LEVEL_CHANGED, }; static const u16 mgmt_untrusted_commands[] = { @@ -10082,6 +10083,14 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, ev->eir_len = cpu_to_le16(eir_len); mgmt_event_skb(skb, NULL); + + /* Connections that negotiated encryption as part of setup (e.g. via + * an existing link key) had their security level change suppressed + * since userspace did not know about them yet, so report it now. + * Unencrypted connections have no change to report. + */ + if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + mgmt_security_level_changed(conn); } static void unpair_device_rsp(struct mgmt_pending_cmd *cmd, void *data) @@ -10188,7 +10197,11 @@ void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn, u8 status) { struct mgmt_ev_connect_failed ev; - if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { + /* Only peek at the flag here: hci_conn_del() (via hci_conn_unlink()) + * still needs it set to know whether to report the security level + * reset, so it is consumed there instead of here. + */ + if (test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, hci_to_mgmt_reason(status), true); @@ -10822,6 +10835,57 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, mgmt_adv_monitor_device_found(hdev, bdaddr, report_device, skb, NULL); } +void mgmt_security_level_changed(struct hci_conn *conn) +{ + struct mgmt_ev_security_level_changed *ev; + struct mgmt_tlv *tlv; + u8 *tlv_data; + u8 tlv_len; + + if (!test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) + return; + + /* Only ACL, LE and BIS links are tracked as mgmt connections, so + * restrict the event to those link types. Other transports (SCO, + * CIS, PA sync, ...) share the parent's address and would otherwise + * report a spurious security level change for it. + */ + if (conn->type != ACL_LINK && conn->type != LE_LINK && + conn->type != BIS_LINK) + return; + + tlv_len = 2 * (sizeof(*tlv) + sizeof(__u8)); + ev = kzalloc_flex(*ev, tlv_data, tlv_len, GFP_KERNEL); + if (!ev) + return; + + bacpy(&ev->addr.bdaddr, &conn->dst); + ev->addr.type = link_to_bdaddr(conn->type, conn->dst_type); + ev->tlv_length = tlv_len; + + tlv_data = ev->tlv_data; + tlv = (void *)tlv_data; + tlv->type = cpu_to_le16(MGMT_SEC_LEVEL_CHANGED_PARAM_LEVEL); + tlv->length = sizeof(__u8); + tlv->value[0] = conn->sec_level; + + tlv_data += sizeof(*tlv) + sizeof(__u8); + tlv = (void *)tlv_data; + tlv->type = cpu_to_le16(MGMT_SEC_LEVEL_CHANGED_PARAM_ENC_TYPE); + tlv->length = sizeof(__u8); + if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + tlv->value[0] = MGMT_CONN_SEC_ENCRYPT_NONE; + else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) + tlv->value[0] = MGMT_CONN_SEC_ENCRYPT_AES_CCM; + else + tlv->value[0] = MGMT_CONN_SEC_ENCRYPT_E0; + + mgmt_event(MGMT_EV_SECURITY_LEVEL_CHANGED, conn->hdev, ev, + struct_size(ev, tlv_data, tlv_len), NULL); + + kfree(ev); +} + void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, u8 addr_type, s8 rssi, u8 *name, u8 name_len) { From 371d16580886bafdb1203b0818cdeafd153bbf08 Mon Sep 17 00:00:00 2001 From: Aaron Kling Date: Fri, 25 Sep 2026 01:52:50 -0500 Subject: [PATCH 1716/2126] Bluetooth: btbcm: Add entry for BCM4356A3 UART bluetooth This patch adds the device ID for the bluetooth chip used in the Nvidia specific Broadcom BCM4356 PCI-E WiFi / UART BT chip. Startup log: Bluetooth: hci0: BCM: chip id 122 Bluetooth: hci0: BCM: features 0x0f Bluetooth: hci0: BCM4356A3 Bluetooth: hci0: BCM4356A3 (001.004.009) build 0000 Bluetooth: hci0: BCM4356A3 'brcm/BCM4356A3.nvidia,p2894-2551-b00.hcd' Patch Bluetooth: hci0: BCM: features 0x0f Bluetooth: hci0: BCM4356A3 37.4MHz Class 1.5 Nvidia mDarcy-0108 Bluetooth: hci0: BCM4356A3 (001.004.009) build 0109 Signed-off-by: Aaron Kling Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btbcm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 63c4c788d9c4..065536d4ec76 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -508,6 +508,7 @@ static const struct bcm_subver_table bcm_uart_subver_table[] = { { 0x6606, "BCM4345C5" }, /* 003.006.006 */ { 0x230f, "BCM4356A2" }, /* 001.003.015 */ { 0x2310, "BCM4343A2" }, /* 001.003.016 */ + { 0x2409, "BCM4356A3" }, /* 001.004.009 */ { 0x220e, "BCM20702A1" }, /* 001.002.014 */ { 0x420d, "BCM4349B1" }, /* 002.002.013 */ { 0x420e, "BCM4349B1" }, /* 002.002.014 */ From cfa67a1dbfd9425044f6eef037a114b2d108f436 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Thu, 1 Oct 2026 14:35:13 +0300 Subject: [PATCH 1717/2126] Bluetooth: btusb: add ASUS 0b05:1825 to QCA Rome quirks The Bluetooth controller with USB ID 0b05:1825 found on ASUS systems uses a Qualcomm QCA Rome chipset, but is currently matched only by the generic Bluetooth USB entry. Without BTUSB_QCA_ROME, the driver does not load the QCA rampatch and NVM firmware. BLE scanning also repeatedly reports: Bluetooth: hci0: unexpected event for opcode 0x2005 Mark the device as BTUSB_QCA_ROME with wideband speech support, in line with the other QCA Rome USB IDs. Similar issue but with different device id. After patching bluetooth is working fine, no unexpected events in log. Link: https://lore.kernel.org/linux-bluetooth/20260928143655.22223-1-qstrydom0@gmail.com Tested-on: Qualcomm Atheros QCA6174 SoC integrated in motherboard ASUS Z170I PRO GAMING, USB device id: 0b05:1825 Signed-off-by: Konstantin Nazarov Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 3518f92ebbd3..71d8dccb29d3 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -272,6 +272,8 @@ static const struct usb_device_id quirks_table[] = { { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, /* QCA ROME chipset */ + { USB_DEVICE(0x0b05, 0x1825), .driver_info = BTUSB_QCA_ROME | + BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x0b05, 0x1868), .driver_info = BTUSB_QCA_ROME | BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME | From 8a8d51eeedebfa5aaaae7720f2fb2aa1a67b8587 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 5 Oct 2026 21:13:54 +0300 Subject: [PATCH 1718/2126] Bluetooth: hci_sync: fix mesh adv timeout units Mesh adv instance timeout and duration are in milliseconds, see mesh_send_sync, hci_add_adv_instance. hci_schedule_adv_instance_sync() and hci_enable_ext_advertising_sync() ignore this, and scale the timeout wrong. Fix for mesh instances by using msecs_to_jiffies() in hci_schedule_adv_instance_sync and fixing the scaling in hci_enable_ext_advertising_sync. Fixes BlueZ "Mesh - Send cancel" test failures. Fixes: b338d91703fa ("Bluetooth: Implement support for Mesh") Assisted-by: opencode:qwen3.8-flash-next sashiko Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 6854449a060d..69ebdff2047d 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1672,7 +1672,8 @@ int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) * scheduling it. */ if (adv && adv->timeout) { - u16 duration = adv->timeout * MSEC_PER_SEC; + u16 duration = adv->mesh ? adv->timeout : + adv->timeout * MSEC_PER_SEC; /* Time = N * 10 ms */ set->duration = cpu_to_le16(duration / 10); @@ -2103,7 +2104,8 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, hdev->adv_instance_timeout = timeout; queue_delayed_work(hdev->req_workqueue, &hdev->adv_instance_expire, - secs_to_jiffies(timeout)); + adv->mesh ? msecs_to_jiffies(timeout) : + secs_to_jiffies(timeout)); } /* If we're just re-scheduling the same instance again then do not From 3d9526b171e0f2b94e478204d232e3ea94296200 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 5 Oct 2026 21:13:55 +0300 Subject: [PATCH 1719/2126] Bluetooth: make hdev->adv_instance_timeout a boolean Mesh uses millisecond time units for advertisements instead of seconds as normally. These values go to hdev->adv_instance_timeout, which then has mixed units. hdev->adv_instance_timeout is however only used as a true/false flag. Make hdev->adv_instance_timeout boolean flag, to avoid possible future problems with its mixed-units values. Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_core.c | 6 +++--- net/bluetooth/hci_sync.c | 8 ++++---- net/bluetooth/mgmt.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index f631d9484a0b..aa04dec45153 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -601,7 +601,7 @@ struct hci_dev { struct list_head adv_instances; unsigned int adv_instance_cnt; __u8 cur_adv_instance; - __u16 adv_instance_timeout; + bool adv_instance_timeout; struct delayed_work adv_instance_expire; struct idr adv_monitors_idr; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 5c6884b65976..c8b57848228b 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1617,7 +1617,7 @@ int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) if (hdev->cur_adv_instance == instance) { if (hdev->adv_instance_timeout) { cancel_delayed_work(&hdev->adv_instance_expire); - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; } hdev->cur_adv_instance = 0x00; } @@ -1647,7 +1647,7 @@ void hci_adv_instances_clear(struct hci_dev *hdev) if (hdev->adv_instance_timeout) { disable_delayed_work(&hdev->adv_instance_expire); - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; } list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { @@ -2437,7 +2437,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv) hdev->adv_tx_power = HCI_TX_POWER_INVALID; hdev->adv_instance_cnt = 0; hdev->cur_adv_instance = 0x00; - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; hdev->advmon_allowlist_duration = 300; hdev->advmon_no_filter_duration = 500; diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 69ebdff2047d..a1cba1a7d6d5 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -470,7 +470,7 @@ static void reenable_adv(struct work_struct *work) static void cancel_adv_timeout(struct hci_dev *hdev) { if (hdev->adv_instance_timeout) { - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; cancel_delayed_work(&hdev->adv_instance_expire); } } @@ -570,7 +570,7 @@ static void adv_timeout_expire(struct work_struct *work) hci_dev_lock(hdev); - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; if (hdev->cur_adv_instance == 0x00) goto unlock; @@ -2101,7 +2101,7 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, /* Only use work for scheduling instances with legacy advertising */ if (!ext_adv_capable(hdev)) { - hdev->adv_instance_timeout = timeout; + hdev->adv_instance_timeout = true; queue_delayed_work(hdev->req_workqueue, &hdev->adv_instance_expire, adv->mesh ? msecs_to_jiffies(timeout) : @@ -5580,7 +5580,7 @@ int hci_dev_close_sync(struct hci_dev *hdev) if (hdev->adv_instance_timeout) { cancel_delayed_work_sync(&hdev->adv_instance_expire); - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; } err = hci_dev_shutdown(hdev); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index aea3482e3893..2e35b09579d3 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -1299,7 +1299,7 @@ void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, static void cancel_adv_timeout(struct hci_dev *hdev) { if (hdev->adv_instance_timeout) { - hdev->adv_instance_timeout = 0; + hdev->adv_instance_timeout = false; cancel_delayed_work(&hdev->adv_instance_expire); } } From 0ad48c88a2ed3b58164fa771977868503b0abac3 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 5 Oct 2026 11:15:02 -0400 Subject: [PATCH 1720/2126] Bluetooth: MGMT: Fix advertising instances with Global Advertising Global Advertising, enabled with MGMT_OP_SET_ADVERTISING, uses instance 0 and with extended advertising it has its own advertising set, but instances were still being treated as if they shared the same set: - Add Advertising and Add Extended Advertising Data would return success without ever enabling the instance. - Removing the last instance would disable all advertising sets, stopping Global Advertising while leaving its setting enabled. - Disabling Global Advertising would disable all sets, including active instances. Fix this by only overriding instances that share the advertising set of Global Advertising, and by tracking HCI_LE_ADV_0 rather than HCI_LE_ADV to determine the state of Global Advertising. Fixes: 0d92808024b4 ("Bluetooth: HCI: Fix tracking of advertisement set/instance 0x00") Assisted-by: OpenCode:claude-opus-5.5 Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_event.c | 11 ++++- net/bluetooth/hci_sync.c | 2 +- net/bluetooth/mgmt.c | 83 +++++++++++++++++++++++++++----- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h index a6579a868678..59cb918d1405 100644 --- a/include/net/bluetooth/hci_sync.h +++ b/include/net/bluetooth/hci_sync.h @@ -122,6 +122,7 @@ int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance); int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, u8 instance, bool force); int hci_disable_advertising_sync(struct hci_dev *hdev); +int hci_disable_ext_adv_legacy_instance_sync(struct hci_dev *hdev); int hci_clear_adv_instance_sync(struct hci_dev *hdev, struct sock *sk, u8 instance, bool force); int hci_update_passive_scan_sync(struct hci_dev *hdev); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index a3359aaad001..0f7e08f8a0b8 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1686,15 +1686,22 @@ static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data, hci_dev_clear_flag(hdev, HCI_LE_ADV_0); /* If just one instance was disabled check if there are - * any other instance enabled before clearing HCI_LE_ADV + * any other instance enabled, including instance 0, + * before clearing HCI_LE_ADV */ + if (hci_dev_test_flag(hdev, HCI_LE_ADV_0)) + goto unlock; + list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { if (adv->enabled) goto unlock; } } else { - /* All instances shall be considered disabled */ + /* All instances shall be considered disabled, except + * instance 0 whose state is preserved so it can be + * re-enabled by hci_resume_advertising_sync. + */ list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) adv->enabled = false; diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index a1cba1a7d6d5..8650a3f00834 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1158,7 +1158,7 @@ int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, return 0; } -static int hci_disable_ext_adv_legacy_instance_sync(struct hci_dev *hdev) +int hci_disable_ext_adv_legacy_instance_sync(struct hci_dev *hdev) { struct hci_cp_le_set_ext_adv_enable *cp; struct hci_cp_ext_adv_set *set; diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 2e35b09579d3..684e8a6c4820 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -6546,7 +6546,12 @@ static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) return; } - if (hci_dev_test_flag(hdev, HCI_LE_ADV)) + /* With extended advertising global advertising (instance 0) has its + * own advertising set so only consider its state, other instances may + * still be enabled. + */ + if (ext_adv_capable(hdev) ? hci_dev_test_flag(hdev, HCI_LE_ADV_0) : + hci_dev_test_flag(hdev, HCI_LE_ADV)) hci_dev_set_flag(hdev, HCI_ADVERTISING); else hci_dev_clear_flag(hdev, HCI_ADVERTISING); @@ -6566,6 +6571,34 @@ static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) list_empty(&hdev->adv_instances)) return; + /* With extended advertising instances are not overridden by global + * advertising, except the ones sharing its set, so only (re)start the + * instances that are not already enabled. + * + * Lookup instances by identifier while holding hdev->lock since the + * list may change while waiting for the HCI commands to complete. + */ + if (ext_adv_capable(hdev)) { + u16 i; + + for (i = 1; i <= hdev->le_num_of_adv_sets + 1; i++) { + bool enabled; + + hci_dev_lock(hdev); + adv_instance = hci_find_adv_instance(hdev, i); + enabled = !adv_instance || adv_instance->enabled; + hci_dev_unlock(hdev); + + if (enabled) + continue; + + err = hci_schedule_adv_instance_sync(hdev, i, true); + enable_advertising_instance(hdev, err); + } + + return; + } + instance = hdev->cur_adv_instance; if (!instance) { adv_instance = list_first_entry_or_null(&hdev->adv_instances, @@ -6621,6 +6654,11 @@ static int set_adv_sync(struct hci_dev *hdev, void *data) hci_update_scan_rsp_data_sync(hdev, 0x00); hci_enable_advertising_sync(hdev); } + } else if (ext_adv_capable(hdev)) { + /* Only disable global advertising (instance 0) leaving other + * instances untouched. + */ + hci_disable_ext_adv_legacy_instance_sync(hdev); } else { hci_disable_advertising_sync(hdev); } @@ -8952,6 +8990,21 @@ static bool adv_busy(struct hci_dev *hdev) return pending_find(MGMT_OP_SET_LE, hdev); } +/* Global advertising, enabled with MGMT_OP_SET_ADVERTISING, uses instance 0 + * and takes precedence over any instance that would share its advertising + * set: with legacy advertising there is only a single set so all instances + * are overridden, whereas with extended advertising only an instance using + * handle 0x00 is. + */ +static bool adv_overridden_by_global(struct hci_dev *hdev, + struct adv_info *adv) +{ + if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) + return false; + + return !ext_adv_capable(hdev) || !adv->handle; +} + static void add_adv_complete(struct hci_dev *hdev, struct sock *sk, u8 instance, int err) { @@ -9113,12 +9166,12 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, schedule_instance = cp->instance; } - /* If the HCI_ADVERTISING flag is set or the device isn't powered or - * there is no instance to be advertised then we have no HCI - * communication to make. Simply return. + /* If the instance is overridden by global advertising or the device + * isn't powered or there is no instance to be advertised then we have + * no HCI communication to make. Simply return. */ if (!hdev_is_powered(hdev) || - hci_dev_test_flag(hdev, HCI_ADVERTISING) || + adv_overridden_by_global(hdev, adv) || !schedule_instance) { rp.instance = cp->instance; err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, @@ -9293,8 +9346,11 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, goto unlock; } - /* Submit request for advertising params if ext adv available */ - if (ext_adv_capable(hdev)) { + /* Submit request for advertising params if ext adv available, unless + * the set is in use by global advertising in which case the params + * will be programmed once the instance is scheduled. + */ + if (ext_adv_capable(hdev) && !adv_overridden_by_global(hdev, adv)) { cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_PARAMS, hdev, data, data_len); if (!cmd) { @@ -9444,11 +9500,12 @@ static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, schedule_instance = cp->instance; } - /* If the HCI_ADVERTISING flag is set or there is no instance to - * be advertised then we have no HCI communication to make. + /* If the instance is overridden by global advertising or there is no + * instance to be advertised then we have no HCI communication to make. * Simply return. */ - if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || !schedule_instance) { + if (adv_overridden_by_global(hdev, adv_instance) || + !schedule_instance) { if (adv_instance->pending) { mgmt_advertising_added(sk, hdev, cp->instance); adv_instance->pending = false; @@ -9524,7 +9581,11 @@ static int remove_advertising_sync(struct hci_dev *hdev, void *data) if (err) return err; - if (list_empty(&hdev->adv_instances)) + /* Don't disable advertising if global advertising (instance 0) is + * enabled since it is not affected by removing instances. + */ + if (list_empty(&hdev->adv_instances) && + !hci_dev_test_flag(hdev, HCI_ADVERTISING)) err = hci_disable_advertising_sync(hdev); return err; From 1bfecdbd031711e5205ae78f3b8c296e5a53bc55 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 5 Oct 2026 13:39:17 -0400 Subject: [PATCH 1721/2126] Bluetooth: HCI: Fix tracking of instances sharing handle 0x00 When the controller supports a single advertising set, instance 1 uses handle 0x00 which is the same handle used by instance 0 (Global Advertising), but hci_cc_le_set_ext_adv_enable would lookup the instance using the handle as instance identifier, marking instance 0 as enabled/disabled instead of instance 1, leaving its state out of sync. Fix this by matching instances by handle and, for handle 0x00, using hdev->cur_adv_instance, now set when enabling an instance, to determine which instance owns the set. Also disable the instance sharing the advertising set of instance 0 before overriding it. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: OpenCode:claude-opus-5.5 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 47 ++++++++++++++++++++++++++++++--------- net/bluetooth/hci_sync.c | 35 ++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 0f7e08f8a0b8..c055d16cfb8e 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1639,6 +1639,39 @@ static u8 hci_cc_le_set_adv_enable(struct hci_dev *hdev, void *data, return rp->status; } +/* Update the enabled state of the instance(s) using the advertising set + * identified by handle. + * + * Instances may share handle 0x00 with instance 0 (Global Advertising), e.g. + * when the controller supports a single advertising set, in which case the + * set is owned by the instance last enabled (hdev->cur_adv_instance) and any + * other instance sharing it shall be considered disabled. + */ +static void hci_le_ext_adv_set_enabled(struct hci_dev *hdev, u8 handle, + bool enable) +{ + struct adv_info *adv; + bool owned = false; + + list_for_each_entry(adv, &hdev->adv_instances, list) { + if (adv->handle != handle) + continue; + + adv->enabled = enable && + (handle || + adv->instance == hdev->cur_adv_instance); + owned |= adv->enabled; + } + + if (handle) + return; + + if (enable && !owned) + hci_dev_set_flag(hdev, HCI_LE_ADV_0); + else + hci_dev_clear_flag(hdev, HCI_LE_ADV_0); +} + static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data, struct sk_buff *skb) { @@ -1660,18 +1693,13 @@ static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data, hci_dev_lock(hdev); - if (cp->num_of_sets) - adv = hci_find_adv_instance(hdev, set->handle); - if (cp->enable) { struct hci_conn *conn; hci_dev_set_flag(hdev, HCI_LE_ADV); - if (adv) - adv->enabled = true; - else if (!set->handle) - hci_dev_set_flag(hdev, HCI_LE_ADV_0); + if (cp->num_of_sets) + hci_le_ext_adv_set_enabled(hdev, set->handle, true); conn = hci_lookup_le_connect(hdev); if (conn) @@ -1680,10 +1708,7 @@ static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data, conn->conn_timeout); } else { if (cp->num_of_sets) { - if (adv) - adv->enabled = false; - else if (!set->handle) - hci_dev_clear_flag(hdev, HCI_LE_ADV_0); + hci_le_ext_adv_set_enabled(hdev, set->handle, false); /* If just one instance was disabled check if there are * any other instance enabled, including instance 0, diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 8650a3f00834..9eca6757d44f 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1158,6 +1158,30 @@ int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, return 0; } +/* Check if the advertising set with handle 0x00 is in use, either by instance + * 0 or by an instance sharing its advertising set. + */ +static bool hci_ext_adv_handle_0_enabled(struct hci_dev *hdev) +{ + struct adv_info *adv; + bool enabled; + + hci_dev_lock(hdev); + + enabled = hci_dev_test_flag(hdev, HCI_LE_ADV_0); + + list_for_each_entry(adv, &hdev->adv_instances, list) { + if (!adv->handle && adv->enabled) { + enabled = true; + break; + } + } + + hci_dev_unlock(hdev); + + return enabled; +} + int hci_disable_ext_adv_legacy_instance_sync(struct hci_dev *hdev) { struct hci_cp_le_set_ext_adv_enable *cp; @@ -1165,7 +1189,7 @@ int hci_disable_ext_adv_legacy_instance_sync(struct hci_dev *hdev) u8 data[sizeof(*cp) + sizeof(*set) * 1]; u8 size; - if (!hci_dev_test_flag(hdev, HCI_LE_ADV_0)) + if (!hci_ext_adv_handle_0_enabled(hdev)) return 0; memset(data, 0, sizeof(data)); @@ -1411,6 +1435,9 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) return -EINVAL; } } else { + /* Disable the advertising set with handle 0x00, including any + * instance sharing it, since it is going to be overridden. + */ err = hci_disable_ext_adv_legacy_instance_sync(hdev); if (err) return err; @@ -1679,6 +1706,12 @@ int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) set->duration = cpu_to_le16(duration / 10); } + /* Track which instance owns the advertising set since the handle + * alone is ambiguous when instances share handle 0x00, see + * hci_cc_le_set_ext_adv_enable. + */ + hdev->cur_adv_instance = instance; + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, sizeof(*cp) + sizeof(*set) * cp->num_of_sets, From 5548fb51aa3cc24545029a286882d261a8e77d8a Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 5 Oct 2026 13:39:25 -0400 Subject: [PATCH 1722/2126] Bluetooth: MGMT: Fix pending state of instances added without HCI traffic When Add Advertising completes without HCI communication, e.g. when the device is not powered or the instance is overridden by Global Advertising, the instance is left marked as pending, so a subsequent failure in add_adv_complete would remove it despite it having been successfully added. Fix this by clearing the pending state before completing the command. Fixes: fffd38bca51c ("Bluetooth: mgmt/hci_core: multi-adv for add_advertising*()") Assisted-by: OpenCode:claude-opus-5.5 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 684e8a6c4820..dadc41c4ad85 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -9173,6 +9173,12 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, if (!hdev_is_powered(hdev) || adv_overridden_by_global(hdev, adv) || !schedule_instance) { + /* Instance has been accepted so it shall no longer be + * considered pending, otherwise a later failure in + * add_adv_complete would remove it. + */ + adv->pending = false; + rp.instance = cp->instance; err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, MGMT_STATUS_SUCCESS, &rp, sizeof(rp)); From f7f0d0a9eb6e4616c0b3a2a95498b5204c5543c9 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 5 Oct 2026 13:39:26 -0400 Subject: [PATCH 1723/2126] Bluetooth: MGMT: Fix leaking instance on Add Extended Advertising Parameters If queueing the command fails the instance is never removed, despite it having already been added or modified by hci_add_adv_instance, so remove it as it is done by add_ext_adv_params_complete on failure, signaling it has been removed if it was previously added. Fixes: cba6b758711c ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2") Assisted-by: OpenCode:claude-opus-5.5 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index dadc41c4ad85..3471550431f7 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -9361,14 +9361,15 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, data, data_len); if (!cmd) { err = -ENOMEM; - hci_remove_adv_instance(hdev, cp->instance); - goto unlock; + goto remove; } err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd, add_ext_adv_params_complete); - if (err < 0) + if (err < 0) { mgmt_pending_free(cmd); + goto remove; + } } else { rp.instance = cp->instance; rp.tx_power = HCI_ADV_TX_POWER_NO_PREFERENCE; @@ -9379,6 +9380,18 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, MGMT_STATUS_SUCCESS, &rp, sizeof(rp)); } + goto unlock; + +remove: + /* The instance may have been modified already so remove it, like it + * is done in add_ext_adv_params_complete, signaling it has been + * removed if it was previously added. + */ + if (!adv->pending) + mgmt_advertising_removed(sk, hdev, cp->instance); + + hci_remove_adv_instance(hdev, cp->instance); + unlock: hci_dev_unlock(hdev); From 8c27d7d06e21ba9455ddae4e14f364c57f095cba Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Tue, 6 Oct 2026 15:35:23 +0800 Subject: [PATCH 1724/2126] Bluetooth: 6LoWPAN: Use RCU-safe device list removal RCU readers of bt_6lowpan_devices must be able to follow an adapter's forward link until their read-side critical section ends. The entries are published with list_add_rcu(), but device_event() removes an entry on NETDEV_UNREGISTER with list_del(), poisoning that link. When an adapter is being unregistered and 6LoWPAN is enabled, a 6lowpan_control debugfs write with an existing LE L2CAP connection can enter lookup_peer() after unregister's first synchronize_net(). If the connection has no peer on that adapter, the reader must advance to the next list entry. Neither RTNL nor devices_lock excludes this RCU reader. The last peer's chan_close_cb() schedules delete_netdev(), which reaches unregister_netdevice_many_notify() through unregister_dev() and lowpan_unregister_netdev(). The following ordering is possible: Unregister worker Control writer ----------------- -------------- synchronize_net() returns lowpan_control_write() lookup_peer(): rcu_read_lock() reach adapter; no matching peer device_event(): devices_lock list_del(&entry->list) spin_unlock(&devices_lock) follow poisoned next link read invalid adapter address post-notifier synchronize_net() waits for the reader This invalid pointer access can fault in lookup_peer(). The first grace period drains existing readers but permits new ones to start, and the later grace period cannot prevent the intervening poisoned-link access. Use list_del_rcu() under the existing devices_lock to preserve the forward link for readers that already reached the adapter. The existing post-notifier synchronize_net() waits for those readers before netdevice teardown frees the private storage containing lowpan_btle_dev. KASAN report as below: [...] [ 45.867526] Oops: general protection fault, probably for non-canonical address 0xfbd59c0000000023: 0000 [#1] SMP KASAN NOPTI [ 45.869489] KASAN: maybe wild-memory-access in range [0xdead000000000118-0xdead00000000011f] [ 45.870981] CPU: 1 UID: 0 PID: 646 Comm: sh Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #4 PREEMPT(lazy) [ 45.872609] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 45.874380] RIP: 0010:lookup_peer+0x1ba/0x320 [ 45.875067] Code: 48 89 d9 ba 04 00 00 00 4c 89 fe bf a0 06 00 00 e8 2b e8 ad fb e9 56 ff ff ff e8 01 1e c3 fb 49 8d 7f 18 48 89 f8 48 c1 e8 03 <80> 3c 28 00 0f 85 4a 01 00 00 4d 8b 47 18 4c 89 f1 ba 04 00 00 00 [ 45.878206] RSP: 0018:ffff888114d67b90 EFLAGS: 00010212 [ 45.879106] RAX: 1bd5a00000000023 RBX: 0000000000000000 RCX: ffffffff85c1d19f [ 45.880334] RDX: ffff88810dc35700 RSI: 0000000000000000 RDI: dead000000000118 [ 45.881455] RBP: dffffc0000000000 R08: 0000000000000001 R09: 0000000000000001 [ 45.882546] R10: ffffffff893d3057 R11: ffff88810dc35700 R12: ffff88810a690000 [ 45.883839] R13: ffff888115451038 R14: ffff88810a690000 R15: dead000000000100 [ 45.885186] FS: 00007fa889bac780(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000 [ 45.886539] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 45.887527] CR2: 00007ffe304f2f80 CR3: 0000000104f64005 CR4: 0000000000770ef0 [ 45.888687] PKRU: 55555554 [ 45.889183] Call Trace: [ 45.889666] [ 45.890061] lowpan_control_write+0x445/0x9e0 [ 45.890854] ? __pfx_lowpan_control_write+0x10/0x10 [ 45.891738] ? srso_alias_return_thunk+0x5/0xfbef5 [ 45.892603] ? srso_alias_return_thunk+0x5/0xfbef5 [ 45.893383] ? __debugfs_file_get+0x1bd/0x7f0 [ 45.894057] ? srso_alias_return_thunk+0x5/0xfbef5 [ 45.894902] ? lock_acquire+0x17b/0x2f0 [ 45.895593] ? ksys_write+0x111/0x200 [ 45.896290] full_proxy_write+0x11f/0x180 [ 45.896991] vfs_write+0x25a/0x1010 [ 45.897642] ? __pfx_full_proxy_write+0x10/0x10 [ 45.898440] ? __pfx_vfs_write+0x10/0x10 [ 45.899178] ? lock_release+0x11f/0x280 [ 45.899855] ksys_write+0x111/0x200 [ 45.900435] ? __pfx_ksys_write+0x10/0x10 [ 45.901074] ? irqentry_exit+0xbe/0x820 [ 45.901722] ? srso_alias_return_thunk+0x5/0xfbef5 [ 45.902489] do_syscall_64+0x115/0x6a0 [ 45.903064] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 45.903813] RIP: 0033:0x7fa889c3e687 [ 45.904359] Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff [ 45.906981] RSP: 002b:00007ffd7651b960 EFLAGS: 00000202 ORIG_RAX: 0000000000000001 [ 45.908070] RAX: ffffffffffffffda RBX: 00007fa889bac780 RCX: 00007fa889c3e687 [ 45.909102] RDX: 000000000000001c RSI: 00005570f25e8d10 RDI: 0000000000000001 [ 45.910133] RBP: 00005570f25e8d10 R08: 0000000000000000 R09: 0000000000000000 [ 45.911162] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000001 [ 45.912190] R13: 000000000000001c R14: 0000000000000000 R15: 00005570f25e8a78 [ 45.913208] [ 45.913530] Modules linked in: [ 45.914022] ---[ end trace 0000000000000000 ]--- [ 45.914709] RIP: 0010:lookup_peer+0x1ba/0x320 [ 45.915436] Code: 48 89 d9 ba 04 00 00 00 4c 89 fe bf a0 06 00 00 e8 2b e8 ad fb e9 56 ff ff ff e8 01 1e c3 fb 49 8d 7f 18 48 89 f8 48 c1 e8 03 <80> 3c 28 00 0f 85 4a 01 00 00 4d 8b 47 18 4c 89 f1 ba 04 00 00 00 [ 45.919191] RSP: 0018:ffff888114d67b90 EFLAGS: 00010212 [ 45.920046] RAX: 1bd5a00000000023 RBX: 0000000000000000 RCX: ffffffff85c1d19f [ 45.921129] RDX: ffff88810dc35700 RSI: 0000000000000000 RDI: dead000000000118 [ 45.922553] RBP: dffffc0000000000 R08: 0000000000000001 R09: 0000000000000001 [ 45.923653] R10: ffffffff893d3057 R11: ffff88810dc35700 R12: ffff88810a690000 [ 45.925119] R13: ffff888115451038 R14: ffff88810a690000 R15: dead000000000100 [ 45.926180] FS: 00007fa889bac780(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000 [ 45.927817] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 45.928726] CR2: 00007ffe304f2f80 CR3: 0000000104f64005 CR4: 0000000000770ef0 [ 45.930069] PKRU: 55555554 [ 45.930456] Kernel panic - not syncing: Fatal exception [ 45.931542] Kernel Offset: disabled [ 45.932040] Rebooting in 1 seconds.. Fixes: 90305829635d ("Bluetooth: 6lowpan: Converting rwlocks to use RCU") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 836add41f5d1..4b0540992961 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -1274,7 +1274,7 @@ static int device_event(struct notifier_block *unused, if (entry->netdev == netdev) { BT_DBG("Unregistered netdev %s %p", netdev->name, netdev); - list_del(&entry->list); + list_del_rcu(&entry->list); break; } } From f51ee3bb5fbe9c2019c31befe330bddd3aee39c2 Mon Sep 17 00:00:00 2001 From: Hitalo Souza Date: Tue, 6 Oct 2026 17:21:42 -0400 Subject: [PATCH 1725/2126] Bluetooth: Add missing newline to bt_dev_{err,warn}_ratelimited() bt_dev_err_ratelimited() and bt_dev_warn_ratelimited() pass the format string to bt_err_ratelimited()/bt_warn_ratelimited() without appending a newline, unlike bt_dev_err() and bt_dev_warn(), which go through BT_ERR()/BT_WARN() and add one. Only 2 of the 22 in-tree callers (both in virtio_bt) put the newline in their own format string. A printk record without a trailing newline is stored with prb_commit() instead of prb_final_commit(), and readers of the log buffer (/dev/kmsg, syslog) do not see it until it is finalized, which only happens when the next record is reserved. These messages therefore stay invisible until some unrelated message is printed, and journald, which timestamps a record when it reads it, logs them with the time of that later message. This was observed with a MediaTek MT7921 controller (USB 04ca:3802): when an eSCO link is closed, the host still receives a few SCO packets for the handle after Disconnection Complete, so hci_scodata_packet() logs "SCO packet for unknown connection handle". Comparing the record's kernel timestamp (_SOURCE_MONOTONIC_TIMESTAMP) with the time journald received it, over one capture: emitted logged delay 15:36:52.896 15:37:00.214 7.3 s 15:37:03.410 15:39:05.574 122.2 s 15:39:05.574 15:39:12.506 6.9 s 15:39:19.791 15:40:54.109 94.3 s 15:41:22.021 15:41:24.647 2.6 s Each message showed up together with the next kernel message; the 94 s one looked as if it had been logged in the middle of a later, healthy eSCO connection. bt_dev_err_ratelimited() lost its newline in commit 657cc646475b ("Bluetooth: Remove usage of BT_ERR_RATELIMITED macro"), which replaced BT_ERR_RATELIMITED(), the variant that appended "\n", with a direct call to bt_err_ratelimited(). bt_dev_warn_ratelimited() never had one. Append the newline in both macros, as BT_ERR() and BT_WARN() do, and drop it from the two virtio_bt format strings so that their messages do not gain an empty line. Fixes: 36278a5d4d35 ("Bluetooth: Adding a bt_dev_warn_ratelimited macro.") Fixes: 657cc646475b ("Bluetooth: Remove usage of BT_ERR_RATELIMITED macro") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Hitalo Souza Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/virtio_bt.c | 4 ++-- include/net/bluetooth/bluetooth.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c index 8c55b538deef..638140406b06 100644 --- a/drivers/bluetooth/virtio_bt.c +++ b/drivers/bluetooth/virtio_bt.c @@ -228,7 +228,7 @@ static void virtbt_rx_handle(struct virtio_bluetooth *vbt, struct sk_buff *skb) if (skb->len < min_hdr) { bt_dev_err_ratelimited(vbt->hdev, - "rx pkt_type 0x%02x payload %u < hdr %zu\n", + "rx pkt_type 0x%02x payload %u < hdr %zu", pkt_type, skb->len, min_hdr); kfree_skb(skb); return; @@ -251,7 +251,7 @@ static void virtbt_rx_work(struct work_struct *work) if (!len || len > VIRTBT_RX_BUF_SIZE) { bt_dev_err_ratelimited(vbt->hdev, - "rx reply len %u outside [1, %u]\n", + "rx reply len %u outside [1, %u]", len, VIRTBT_RX_BUF_SIZE); kfree_skb(skb); } else { diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index b624da5026f5..cd9189244566 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -296,9 +296,9 @@ void bt_err_ratelimited(const char *fmt, ...); BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) #define bt_dev_warn_ratelimited(hdev, fmt, ...) \ - bt_warn_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) + bt_warn_ratelimited("%s: " fmt "\n", bt_dev_name(hdev), ##__VA_ARGS__) #define bt_dev_err_ratelimited(hdev, fmt, ...) \ - bt_err_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) + bt_err_ratelimited("%s: " fmt "\n", bt_dev_name(hdev), ##__VA_ARGS__) /* Connection and socket states */ enum bt_sock_state { From 817cbcab91fe870e5b69c835cbd708242c9f8c8e Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Tue, 6 Oct 2026 15:38:38 +0800 Subject: [PATCH 1726/2126] Bluetooth: hci_core: Keep RCU protection through LTK filtering The LTK selected by hci_find_ltk() must remain allocated while its value is checked against the blocked-key list. The finder releases RCU before passing k->val to hci_is_blocked_key(). The helper's own RCU section protects the blocked-key list, but the selected LTK may already have been reclaimed before that section starts. An LE ATT socket security request can reach smp_ltk_encrypt() without holding hdev->lock. With a matching stored LTK and an LTK-type blocked-key entry present, a concurrent MGMT_OP_LOAD_LONG_TERM_KEYS can remove the selected LTK in the following order: Socket security Management / RCU reclamation hci_find_ltk() rcu_read_lock() select k rcu_read_unlock() load_long_term_keys() hci_dev_lock(hdev) hci_smp_ltks_clear(hdev) list_del_rcu(&k->list) kfree_rcu(k, rcu) grace period ends; k is freed hci_is_blocked_key(..., k->val) memcmp(b->val, val, ...) The final comparison reads freed LTK bytes. Entering a new RCU section in hci_is_blocked_key() cannot protect a pointer obtained before the completed grace period. Keep the finder's RCU read-side section active through the blocked-key comparison and the warning that reads k->bdaddr. Release it before returning on either matched-key path. This delays reclamation until the finder has finished using the selected record, following the existing IRK lookup pattern. KFENCE report as below: ================================================================== BUG: KFENCE: use-after-free read in hci_is_blocked_key+0xdf/0x240 Use-after-free read at 0x00000000b9ee38e4 (in kfence-#249): hci_is_blocked_key+0xdf/0x240 blocked_key_wrapper+0xc5/0x140 [pmbd_ltk_probe] hci_find_ltk+0x1aa/0x3e0 smp_ltk_encrypt.isra.0+0xad/0x340 smp_conn_security+0x3b8/0x8c0 l2cap_sock_setsockopt+0x1c4b/0x2270 do_sock_setsockopt+0x1fb/0x430 __sys_setsockopt+0x106/0x180 __x64_sys_setsockopt+0xc2/0x160 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f kfence-#249: 0x00000000121f2ad9-0x000000005b5bfb3d, size=72, cache=kmalloc-96 allocated by task 495 on cpu 0 at 36.722380s (2.603973s ago): hci_add_ltk+0x1f5/0x3a0 load_long_term_keys+0x6d0/0x860 hci_sock_sendmsg+0x128b/0x22e0 __sys_sendto+0x425/0x470 __x64_sys_sendto+0xe5/0x1c0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f freed by task 533 on cpu 0 at 36.993097s (2.339769s ago): __rcu_free_sheaf_prepare+0x261/0x2a0 rcu_free_sheaf+0x1f/0xe0 rcu_core+0x661/0x1d10 handle_softirqs+0x201/0x930 __irq_exit_rcu+0x110/0x1e0 irq_exit_rcu+0xe/0x20 sysvec_apic_timer_interrupt+0x6c/0x80 asm_sysvec_apic_timer_interrupt+0x1a/0x20 srso_alias_return_thunk+0x0/0xfbef5 __asan_memcpy+0x23/0x60 create_monitor_ctrl_event+0x1a2/0x460 mgmt_cmd_complete+0x2da/0x580 load_long_term_keys+0x741/0x860 hci_sock_sendmsg+0x128b/0x22e0 __sys_sendto+0x425/0x470 __x64_sys_sendto+0xe5/0x1c0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f CPU: 1 UID: 0 PID: 495 Comm: python3 Tainted: G O 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy) Tainted: [O]=OOT_MODULE Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 ================================================================== Fixes: 600a87490ff9 ("Bluetooth: Implementation of MGMT_OP_SET_BLOCKED_KEYS.") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index c8b57848228b..209244fd9391 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1153,16 +1153,16 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, continue; if (smp_ltk_is_sc(k) || ltk_role(k->type) == role) { - rcu_read_unlock(); - if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LTK, k->val)) { bt_dev_warn_ratelimited(hdev, "LTK blocked for %pMR", &k->bdaddr); + rcu_read_unlock(); return NULL; } + rcu_read_unlock(); return k; } } From 6d91353f6dbcc5c4fbb47bbd0c7f885453cfc939 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Tue, 6 Oct 2026 22:39:21 +0800 Subject: [PATCH 1727/2126] Bluetooth: hci_sync: Serialize devcoredump reset during device open An ACTIVE devcoredump's buffer cursors must remain valid from the packet handler's state check through its copy. hci_devcd_rx() holds hdev->lock across that interval, and hci_devcd_reset() requires the same lock. However, hci_dev_open_sync() invokes reset without taking it. A registered VHCI controller can collect a dump through its debugfs interface while the controller is down. If a successful open overlaps with handling a nonempty dump packet, reset can run after the receiver's ACTIVE check and before its copy: hci_devcd_rx() hci_dev_open_sync() dequeue nonempty skb hci_dev_lock(hdev) handler observes ACTIVE hdev->open(hdev) succeeds hci_devcd_reset(hdev) dump.tail = NULL dump.state = IDLE hci_devcd_copy() compare against old dump.end memcpy(NULL, ..., skb->len) hci_dev_unlock(hdev) Reset leaves dump.end pointing at the old buffer and purges only queued packets, so it cannot discard the skb already dequeued by the receiver. The bounds check can pass with a NULL tail, leading to a nonempty copy to address zero. KASAN reported a 24-byte NULL write in hci_devcd_rx(). Take hdev->lock around the open-time reset. The receiver then finishes its state check and copy using valid cursors before reset, or observes IDLE after reset and skips the copy. KASAN report as below: BUG: KASAN: null-ptr-deref in hci_devcd_rx+0x5d5/0x1a80 Write of size 24 at addr 0000000000000000 by task kworker/u17:0/496 CPU: 0 UID: 0 PID: 496 Comm: kworker/u17:0 Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: hci0 hci_devcd_rx Call Trace: dump_stack_lvl+0x93/0xd0 kasan_report+0xe0/0x110 ? hci_devcd_rx+0x5d5/0x1a80 kasan_check_range+0x105/0x1b0 __asan_memcpy+0x3c/0x60 hci_devcd_rx+0x5d5/0x1a80 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_hci_devcd_rx+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x280 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 ================================================================== Disabling lock debugging due to kernel taint Fixes: 9695ef876fd1 ("Bluetooth: Add support for hci devcoredump") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 9eca6757d44f..014ceaefd788 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5497,7 +5497,9 @@ int hci_dev_open_sync(struct hci_dev *hdev) goto done; } + hci_dev_lock(hdev); hci_devcd_reset(hdev); + hci_dev_unlock(hdev); set_bit(HCI_RUNNING, &hdev->flags); hci_sock_dev_event(hdev, HCI_DEV_OPEN); From b4a00dedc5cc6f6f98c07ec1b54d24a817d9fc88 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Tue, 6 Oct 2026 22:45:53 +0800 Subject: [PATCH 1728/2126] Bluetooth: ISO: Hold the listener during disconnect notification An ISO listener must remain alive until a queued child's disconnect notification completes. bt_accept_enqueue() retains only the child and stores a raw parent pointer; iso_conn_ready() drops its temporary listener reference after setup. iso_chan_del() saves that pointer, unlinks the child and then calls parent->sk_data_ready() without holding a listener reference. With an incoming CIS child still queued, disconnect and listener release can proceed in this order: HCI disconnect Listener release iso_conn_del(): lock child iso_chan_del(): save parent bt_accept_unlink(child) iso_sock_cleanup_listen(): drain empty accept queue iso_sock_release(): orphan and kill listener final sock_put(listener) parent->sk_data_ready(parent) After unlink, listener cleanup no longer has to take the child socket lock. The listener can therefore be freed before iso_chan_del() reads sk_data_ready, causing a use-after-free. Take a temporary parent reference before bt_accept_unlink() and drop it after the notification. The child lock excludes accept dequeue while the child is still queued, so listener cleanup cannot complete before sock_hold(). The reference then keeps the listener alive across unlink and through the callback without changing lock order. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in iso_chan_del+0x302/0x320 Read of size 8 at addr ffff888105ca2188 by task kworker/2:1/50 CPU: 2 UID: 0 PID: 50 Comm: kworker/2:1 Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: events iso_fixture_disconnect_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? iso_chan_del+0x302/0x320 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? iso_chan_del+0x302/0x320 kasan_report+0xe0/0x110 ? iso_chan_del+0x302/0x320 iso_chan_del+0x302/0x320 iso_conn_del+0x19d/0x3c0 ? __pfx_iso_disconn_cfm+0x10/0x10 iso_disconn_cfm+0x78/0x120 hci_disconn_complete_evt+0x319/0xa30 ? find_held_lock+0x2b/0x80 hci_test_iso_disconn_event+0x85/0xb0 ? __pfx_hci_test_iso_disconn_event+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? _raw_read_unlock+0x23/0x40 ? srso_alias_return_thunk+0x5/0xfbef5 ? __hci_dev_get+0x15d/0x280 iso_fixture_disconnect_work+0x67/0x290 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? srso_alias_return_thunk+0x5/0xfbef5 ? __kthread_parkme+0x175/0x220 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 521: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_noprof+0x2d7/0x770 sk_prot_alloc+0x13e/0x260 sk_alloc+0x37/0xb40 bt_sock_alloc+0x40/0x3b0 iso_sock_alloc.constprop.0+0x3a/0x360 iso_sock_create+0xc7/0x160 bt_sock_create+0x171/0x330 __sock_create+0x2c4/0x730 __sys_socket+0x141/0x210 __x64_sys_socket+0x77/0xc0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 521: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 __sk_destruct+0x64f/0x790 sk_destruct+0xb3/0xd0 __sk_free+0xdd/0x370 sk_free+0x51/0x80 iso_sock_release+0x46d/0x5b0 __sock_release+0xb8/0x270 sock_close+0x21/0x30 __fput+0x39f/0xa60 task_work_run+0x144/0x230 do_exit+0x834/0x2830 do_group_exit+0xc7/0x280 get_signal+0x20a9/0x2400 arch_do_signal_or_restart+0x94/0x6f0 exit_to_user_mode_loop+0xcf/0x570 do_syscall_64+0x4f0/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff888105ca2000 which belongs to the cache kmalloc-2k of size 2048 The buggy address is located 392 bytes inside of freed 2048-byte region [ffff888105ca2000, ffff888105ca2800) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888105ca5000 pfn:0x105ca0 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000240(workingset|head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000240 ffff888100042f00 ffffea00042cd010 ffffea00042c9210 raw: ffff888105ca5000 0000000000080005 00000000f5000000 0000000000000000 head: 0200000000000240 ffff888100042f00 ffffea00042cd010 ffffea00042c9210 head: ffff888105ca5000 0000000000080005 00000000f5000000 0000000000000000 head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff head: ffff888105ca1000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888105ca2080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff888105ca2100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff888105ca2180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff888105ca2200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff888105ca2280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Fixes: f764a6c2c1e4 ("Bluetooth: ISO: Add broadcast support") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/iso.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index cf302e060f79..c1fdd9846eeb 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -287,8 +287,11 @@ static void iso_chan_del(struct sock *sk, int err) parent = bt_sk(sk)->parent; if (parent) { + /* Unlinking the child allows the parent to be freed. */ + sock_hold(parent); bt_accept_unlink(sk); parent->sk_data_ready(parent); + sock_put(parent); } else { sk->sk_state_change(sk); } From 213e7a99bea19e2f29f394321b86c792eec73a24 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Tue, 6 Oct 2026 15:24:31 +0800 Subject: [PATCH 1729/2126] Bluetooth: MGMT: Reject quality report requests during unregister A quality report request must not call a driver callback after its module text has been released. hci_mgmt_cmd() holds an hci_dev reference through set_exp_feature(), but that reference only preserves the device allocation. set_quality_report_func() takes req_lock and invokes hdev->set_quality_report without checking HCI_UNREGISTER. This is unsafe when a SET_EXP_FEATURE request for an Intel controller would change HCI_QUALITY_REPORT and is delayed before taking req_lock while the controller is removed. With btintel_pcie and btintel built as modules and no other btintel dependents, the following order is possible: Management request Removal and module unload ------------------ ------------------------- hci_mgmt_cmd(): retain hdev hci_unregister_dev(): set HCI_UNREGISTER remove hdev from lookup close under req_lock release req_lock btintel_pcie_remove(): return unload btintel_pcie, then btintel set_quality_report_func(): take req_lock call hdev->set_quality_report When the request resumes after btintel unload, the indirect call targets released module text and can cause an instruction-fetch page fault. The close operation serializes with a running callback but does not prevent a delayed management handler from invoking it afterwards. Check HCI_UNREGISTER immediately after acquiring the existing req_lock and return MGMT_STATUS_INVALID_INDEX via the common unlock path. If unregister passed its close section first, the request now rejects the removed controller before accessing the callback. If the request passes the check first, hci_dev_do_close() must wait for req_lock until the callback has returned, so unregister cannot finish before the use. Oops report as below: BUG: unable to handle page fault for address: ffffffffc0408e10 #PF: supervisor instruction fetch in kernel mode #PF: error_code(0x0010) - not-present page PGD 80a9067 P4D 80a9067 PUD 80ab067 PMD 0 Oops: Oops: 0010 [#1] SMP KASAN NOPTI CPU: 1 UID: 0 PID: 439 Comm: btmgmt Tainted: G O 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy) Tainted: [O]=OOT_MODULE Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:0xffffffffc0408e10 Code: Unable to access opcode bytes at 0xffffffffc0408de6. RSP: 0018:ffff888110927838 EFLAGS: 00010293 RAX: 0000000000000000 RBX: 1ffff11022124f0c RCX: ffffffff85b1a1b6 RDX: ffff888117511d00 RSI: 0000000000000001 RDI: ffff888117598000 RBP: ffff888110927950 R08: 0000000000000001 R09: 0000000000000001 R10: ffffffff893d3057 R11: ffff888117511d00 R12: ffff888117598000 R13: 0000000000000001 R14: ffffffffc0408e10 R15: ffff888117599970 FS: 00007f15453f2040(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffc0408de6 CR3: 000000010b832005 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: ? set_quality_report_func+0x232/0x660 ? __pfx_set_quality_report_func+0x10/0x10 ? pmbd_gate_maybe+0x47/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? pmbd_probe_hit_cookie+0xe7/0x1c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? pmbd_probe_hit_cookie+0xee/0x1c0 set_exp_feature+0xf7/0x260 ? set_exp_feature+0xf7/0x260 ? hci_sock_sendmsg+0x12b2/0x2400 ? __pfx_hci_sock_sendmsg+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? selinux_socket_sendmsg+0x160/0x280 ? sock_write_iter+0x4c0/0x550 ? __pfx_hci_sock_sendmsg+0x10/0x10 ? __pfx_sock_write_iter+0x10/0x10 ? __file_has_perm+0x25e/0x420 ? __pfx___file_has_perm+0x10/0x10 ? do_iter_readv_writev+0x59c/0x860 ? __pfx_do_iter_readv_writev+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? security_file_permission+0x26/0x80 ? vfs_writev+0x30e/0xc10 ? __pfx_vfs_writev+0x10/0x10 ? __pfx_do_epoll_wait+0x10/0x10 ? __pfx_do_epoll_ctl+0x10/0x10 ? do_writev+0x241/0x2f0 ? srso_alias_return_thunk+0x5/0xfbef5 ? do_writev+0x241/0x2f0 ? __pfx_do_writev+0x10/0x10 ? irqentry_exit+0xbe/0x820 ? do_syscall_64+0x115/0x6a0 ? entry_SYSCALL_64_after_hwframe+0x77/0x7f Modules linked in: [last unloaded: btintel(O)] CR2: ffffffffc0408e10 ---[ end trace 0000000000000000 ]--- RIP: 0010:0xffffffffc0408e10 Code: Unable to access opcode bytes at 0xffffffffc0408de6. RSP: 0018:ffff888110927838 EFLAGS: 00010293 RAX: 0000000000000000 RBX: 1ffff11022124f0c RCX: ffffffff85b1a1b6 RDX: ffff888117511d00 RSI: 0000000000000001 RDI: ffff888117598000 RBP: ffff888110927950 R08: 0000000000000001 R09: 0000000000000001 R10: ffffffff893d3057 R11: ffff888117511d00 R12: ffff888117598000 R13: 0000000000000001 R14: ffffffffc0408e10 R15: ffff888117599970 FS: 00007f15453f2040(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffc0408de6 CR3: 000000010b832005 CR4: 0000000000770ef0 PKRU: 55555554 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 1 seconds.. Fixes: ae7d925b5c04 ("Bluetooth: Support the quality report events") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 3471550431f7..9f65863e7457 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -4909,6 +4909,13 @@ static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, hci_req_sync_lock(hdev); + if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_EXP_FEATURE, + MGMT_STATUS_INVALID_INDEX); + goto unlock_quality_report; + } + val = !!cp->param[0]; changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)); From 21895f20fedc4504474bcb1022850b532ea4358e Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Tue, 6 Oct 2026 22:41:57 +0800 Subject: [PATCH 1730/2126] Bluetooth: msft: Lock failed probe cleanup against feature readers The MSFT data must remain allocated while msft_get_features() reads its features. read_adv_mon_features() protects that access with hdev->lock, but msft_do_open() clears hdev->msft_data and frees the object without that lock when read_supported_features() fails. After a successful probe, the data survives a normal close. A later open can fail the probe while a management feature request is running. hci_mgmt_cmd() permits requests during HCI_INIT, and the opener's hdev->req_lock does not serialize the management reader: Management feature request HCI open hold hdev->req_lock msft_do_open() hold hdev->lock msft_get_features(): save msft read_supported_features() fails hdev->msft_data = NULL kfree(msft) read msft->features release hdev->lock release hdev->req_lock The saved pointer then refers to freed memory, causing a use-after-free read. Advertisement reporting through mgmt_device_found() also reads the features with hdev->lock held. Take hdev->lock around clearing and freeing msft_data in the failure branch. An existing feature reader finishes before the free, while a reader starting after cleanup sees NULL. Keep the synchronous probe outside this critical section, following the existing req_lock to hdev->lock ordering. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in msft_monitor_supported+0xa9/0xb0 Read of size 8 at addr ffff88811573ee00 by task mgmt-read-adv-m/532 CPU: 2 UID: 0 PID: 532 Comm: mgmt-read-adv-m Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? msft_monitor_supported+0xa9/0xb0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? msft_monitor_supported+0xa9/0xb0 kasan_report+0xe0/0x110 ? msft_monitor_supported+0xa9/0xb0 msft_monitor_supported+0xa9/0xb0 read_adv_mon_features+0xdf/0x640 ? trace_hardirqs_on+0x18/0x160 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_read_adv_mon_features+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? do_raw_read_unlock+0x49/0xe0 ? srso_alias_return_thunk+0x5/0xfbef5 ? _raw_read_unlock+0x23/0x40 hci_sock_sendmsg+0x12b5/0x2270 ? __pfx_hci_sock_sendmsg+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? selinux_socket_sendmsg+0x160/0x280 __sys_sendto+0x425/0x470 ? __pfx_hci_sock_sendmsg+0x10/0x10 ? __pfx___sys_sendto+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? __sys_setsockopt+0x119/0x180 __x64_sys_sendto+0xe5/0x1c0 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ? trace_hardirqs_on+0x18/0x160 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f9ceb04a687 Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff RSP: 002b:00007ffe6ab96a70 EFLAGS: 00000202 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00007f9ceafb8780 RCX: 00007f9ceb04a687 RDX: 0000000000000006 RSI: 00007ffe6ab96aea RDI: 0000000000000003 RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000003 R13: 00007ffe6ab96d50 R14: 00007f9ceb1f6000 R15: 00005625e427dd68 Allocated by task 506: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x251/0x610 msft_register+0x54/0x260 hci_register_dev+0x6b7/0xc80 __vhci_create_device+0x330/0x840 vhci_write+0x287/0x440 vfs_write+0x637/0x1010 ksys_write+0x111/0x200 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 529: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 msft_do_open+0x604/0x9e0 hci_dev_open_sync+0x94a/0x2110 hci_dev_do_open+0x2f/0xb0 hci_dev_open+0x17d/0x300 hci_sock_ioctl+0x3c6/0x710 sock_do_ioctl+0x120/0x2b0 sock_ioctl+0x41b/0x670 __x64_sys_ioctl+0x163/0x1d0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88811573ee00 which belongs to the cache kmalloc-256 of size 256 The buggy address is located 0 bytes inside of freed 256-byte region [ffff88811573ee00, ffff88811573ef00) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11573e head: order:1 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000040(head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000040 ffff888100042b40 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0200000000000040 ffff888100042b40 dead000000000100 dead000000000122 head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0200000000000001 ffffffffffffff81 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88811573ed00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff88811573ed80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff88811573ee00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88811573ee80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88811573ef00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ================================================================== Fixes: 5031ffcc79b8 ("Bluetooth: Keep MSFT ext info throughout a hci_dev's life cycle") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/msft.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index d9dd722db3eb..6f4b7c38a247 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -654,8 +654,10 @@ void msft_do_open(struct hci_dev *hdev) msft->features = 0; if (!read_supported_features(hdev, msft)) { + hci_dev_lock(hdev); hdev->msft_data = NULL; kfree(msft); + hci_dev_unlock(hdev); return; } From ebba800d140b580540ad55f670d943e4a7edaffd Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Thu, 8 Oct 2026 12:11:35 +0800 Subject: [PATCH 1731/2126] Bluetooth: 6lowpan: Drain RCU readers on registration failure A lowpan_btle_dev is embedded in its net_device allocation and must remain alive until readers of bt_6lowpan_devices have left their RCU sections. setup_netdev() publishes it before registration, but its error path only unlinks it before calling free_netdev(). If a second controller's registration fails while multicast is sent on an existing 6LoWPAN interface, send_mcast_pkt() can already have selected the new entry. It reads entry->netdev before checking which interface owns it. An early failure, such as allocating the device's name node, leaves NETREG_UNINITIALIZED, so free_netdev() releases the storage immediately. The following ordering frees the selected entry before the reader loads its netdev field: Adapter creation (controller B) Multicast on controller A setup_netdev() list_add_rcu() rcu_read_lock() select B's entry lowpan_register_netdev() fails list_del_rcu() free_netdev() read entry->netdev rcu_read_unlock() Removing the list node does not wait for that reader, and devices_lock does not serialize the multicast reader. The subsequent field load is a use-after-free, reported by KASAN in bt_xmit(). Wait for an RCU grace period after dropping devices_lock and before free_netdev(). This keeps the failed adapter allocated until traversals that could have selected it complete. The callback is already sleepable, and the wait happens outside the list spinlock. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in bt_xmit+0x1d06/0x21e0 Read of size 8 at addr ffff88810ef45030 by task python3/556 Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? bt_xmit+0x1d06/0x21e0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? bt_xmit+0x1d06/0x21e0 kasan_report+0xe0/0x110 ? bt_xmit+0x1d06/0x21e0 bt_xmit+0x1d06/0x21e0 ? __pfx_bt_xmit+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_acquire+0x17b/0x2f0 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? dev_hard_start_xmit+0x187/0x660 ? __pfx_bt_xmit+0x10/0x10 dev_hard_start_xmit+0x187/0x660 sch_direct_xmit+0x153/0x850 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_sch_direct_xmit+0x10/0x10 ? do_raw_spin_lock+0x130/0x270 ? __pfx_do_raw_spin_lock+0x10/0x10 ? lock_is_held_type+0x8f/0x100 __dev_queue_xmit+0x3111/0x3aa0 ? srso_alias_return_thunk+0x5/0xfbef5 ? look_up_lock_class+0x59/0x130 ? register_lock_class+0x41/0x790 ? __pfx___dev_queue_xmit+0x10/0x10 ? __lock_acquire+0x466/0x2260 ? find_held_lock+0x2b/0x80 ? ___neigh_create+0x1690/0x2540 ? __local_bh_enable_ip+0xa6/0x120 ? srso_alias_return_thunk+0x5/0xfbef5 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_acquire+0x17b/0x2f0 ? srso_alias_return_thunk+0x5/0xfbef5 ? find_held_lock+0x2b/0x80 ? ip6_finish_output2+0x8be/0x1840 ? srso_alias_return_thunk+0x5/0xfbef5 ? neigh_connected_output+0x39f/0x4e0 ? srso_alias_return_thunk+0x5/0xfbef5 neigh_connected_output+0x33f/0x4e0 ip6_finish_output2+0x8be/0x1840 ip6_finish_output+0x424/0xd50 ip6_output+0x210/0x640 ? __pfx_ip6_mr_output+0x10/0x10 ip6_local_out+0x193/0x1c0 ip6_send_skb+0xfb/0x3e0 udp_v6_send_skb+0x6e1/0x1180 udpv6_sendmsg+0x1f9b/0x2a00 ? get_random_u32+0xaf/0x640 ? __pfx_udpv6_sendmsg+0x10/0x10 ? lock_release+0xc8/0x280 ? srso_alias_return_thunk+0x5/0xfbef5 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ? trace_hardirqs_on+0x18/0x160 ? srso_alias_return_thunk+0x5/0xfbef5 ? __local_bh_enable_ip+0xa6/0x120 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_udpv6_sendmsg+0x10/0x10 ? inet6_sendmsg+0xff/0x140 inet6_sendmsg+0xff/0x140 __sys_sendto+0x320/0x470 ? __pfx___sys_sendto+0x10/0x10 ? exc_page_fault+0x5c/0xc0 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x280 ? handle_mm_fault+0x12e/0x580 __x64_sys_sendto+0xe5/0x1c0 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ? trace_hardirqs_on+0x18/0x160 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task 502: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kvmalloc_node_noprof+0x353/0x930 alloc_netdev_mqs+0xa0/0x1250 chan_ready_cb+0x198/0x1110 l2cap_recv_frame+0x6dc0/0x8830 l2cap_recv_acldata+0xe9f/0x10e0 hci_rx_work+0x5a6/0xf00 process_one_work+0x908/0x19c0 worker_thread+0x65c/0xe40 kthread+0x34f/0x460 ret_from_fork+0x659/0x940 ret_from_fork_asm+0x1a/0x30 Freed by task 502: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 free_netdev+0x6ca/0x8f0 chan_ready_cb+0xd91/0x1110 l2cap_recv_frame+0x6dc0/0x8830 l2cap_recv_acldata+0xe9f/0x10e0 hci_rx_work+0x5a6/0xf00 process_one_work+0x908/0x19c0 worker_thread+0x65c/0xe40 kthread+0x34f/0x460 ret_from_fork+0x659/0x940 ret_from_fork_asm+0x1a/0x30 The buggy address belongs to the object at ffff88810ef44000 which belongs to the cache kmalloc-8k of size 8192 The buggy address is located 4144 bytes inside of freed 8192-byte region [ffff88810ef44000, ffff88810ef46000) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10ef40 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000040(head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000040 ffff888100043180 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000 head: 0200000000000040 ffff888100043180 dead000000000100 dead000000000122 head: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000 head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff head: ffff88810ef41a80 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88810ef44f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88810ef44f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88810ef45000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88810ef45080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88810ef45100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Disabling lock debugging due to kernel taint Fixes: 5857d1dbae7d ("Bluetooth: 6lowpan: Fix possible race") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 4b0540992961..6aaa2904d9dc 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -706,6 +706,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev) spin_lock(&devices_lock); list_del_rcu(&(*dev)->list); spin_unlock(&devices_lock); + synchronize_rcu(); free_netdev(netdev); goto out; } From 8368f0c2cde48c09ed70644059f24172b0c59f52 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 12:11:29 +0700 Subject: [PATCH 1732/2126] Bluetooth: 6lowpan: Pin module for 6lowpan_control debugfs file An open debugfs file retains lowpan_control_fops in the debugfs proxy state. However, lowpan_control_fops has no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth_6lowpan module. With CONFIG_BT_6LOWPAN=m, a userspace process can keep the debugfs file descriptor for 6lowpan_control open across module unload (delete_module / rmmod bluetooth_6lowpan). When the process subsequently closes the file descriptor, full_proxy_release() accesses the already freed and unmapped lowpan_control_fops table, causing a kernel page fault or oops. The issue was discovered via manual code audit of net/bluetooth/6lowpan.c. Set .owner = THIS_MODULE on lowpan_control_fops so that debugfs pins the module until all open file descriptors have finished. Fixes: 6b8d4a6a0314 ("Bluetooth: 6LoWPAN: Use connected oriented channel instead of fixed one") Cc: stable@vger.kernel.org Signed-off-by: Bui Viet Dung Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 6aaa2904d9dc..9a736cefac18 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -1215,6 +1215,7 @@ static int lowpan_control_open(struct inode *inode, struct file *file) } static const struct file_operations lowpan_control_fops = { + .owner = THIS_MODULE, .open = lowpan_control_open, .read = seq_read, .write = lowpan_control_write, From 491d2212ea0f0f6a3abbd67729df0c6a3ec9c58a Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 9 Oct 2026 10:35:25 +0200 Subject: [PATCH 1733/2126] Bluetooth: btmtk: fix skb double free on ISO padding failure btmtk_isopkt_pad() uses skb_pad(), which frees the skb on failure. The error is propagated by alloc_mtk_intr_urb() and btusb_send_frame_mtk() up to hci_send_frame(), which frees the skb a second time: err = hdev->send(hdev, skb); if (err < 0) { bt_dev_err(hdev, "sending frame failed (%d)", err); kfree_skb(skb); return err; } Use __skb_put_padto(skb, MTK_ISO_THRESHOLD, false) so that the skb is left to the caller on error. This also replaces the open-coded skb_pad() + __skb_put() sequence. Fixes: ceac1cb0259d ("Bluetooth: btusb: mediatek: add ISO data transmission functions") Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 115a11fcb254..bdc85147b97f 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -1101,12 +1101,8 @@ static int btmtk_isopkt_pad(struct hci_dev *hdev, struct sk_buff *skb) if (skb->len > MTK_ISO_THRESHOLD) return -EINVAL; - if (skb_pad(skb, MTK_ISO_THRESHOLD - skb->len)) - return -ENOMEM; - - __skb_put(skb, MTK_ISO_THRESHOLD - skb->len); - - return 0; + /* On error, the skb is freed by hci_send_frame(). */ + return __skb_put_padto(skb, MTK_ISO_THRESHOLD, false); } static int __set_mtk_intr_interface(struct hci_dev *hdev) From 2a3e2287877b1ee40ffb80b7d769b633866533f3 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 12:01:40 +0700 Subject: [PATCH 1734/2126] Bluetooth: hci_debugfs: Pin module for debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, the file_operations defined in hci_debugfs.c (use_debug_keys_fops, sc_only_mode_fops, ssp_debug_mode_fops, force_bredr_smp_fops, force_static_address_fops, force_no_mitm_fops, dut_mode_fops, vendor_diag_fops, and the DEFINE_QUIRK_ATTRIBUTE macro) have no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth module. When a userspace process opens any of these debugfs files, a subsequent controller removal and module unload (rmmod bluetooth) can succeed while the file descriptor remains open. When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release(): BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The issue was discovered via manual code audit of net/bluetooth/hci_debugfs.c and verified on a Linux 7.3-rc6 test VM with CONFIG_BT=m. Set .owner = THIS_MODULE on all debugfs file_operations tables in hci_debugfs.c so that debugfs keeps the module loaded until close has finished. Fixes: 0886aea6acd2 ("Bluetooth: Expose debug keys usage setting via debugfs") Cc: stable@vger.kernel.org Signed-off-by: Bui Viet Dung Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_debugfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c index 2559fb6324d6..cd5ef398f238 100644 --- a/net/bluetooth/hci_debugfs.c +++ b/net/bluetooth/hci_debugfs.c @@ -65,6 +65,7 @@ static ssize_t __name ## _write(struct file *file, \ } \ \ static const struct file_operations __name ## _fops = { \ + .owner = THIS_MODULE, \ .open = simple_open, \ .read = __name ## _read, \ .write = __name ## _write, \ @@ -283,6 +284,7 @@ static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf, } static const struct file_operations use_debug_keys_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = use_debug_keys_read, .llseek = default_llseek, @@ -301,6 +303,7 @@ static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf, } static const struct file_operations sc_only_mode_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = sc_only_mode_read, .llseek = default_llseek, @@ -437,6 +440,7 @@ static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf, } static const struct file_operations ssp_debug_mode_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = ssp_debug_mode_read, .llseek = default_llseek, @@ -529,6 +533,7 @@ static ssize_t force_bredr_smp_write(struct file *file, } static const struct file_operations force_bredr_smp_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = force_bredr_smp_read, .write = force_bredr_smp_write, @@ -778,6 +783,7 @@ static ssize_t force_static_address_write(struct file *file, } static const struct file_operations force_static_address_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = force_static_address_read, .write = force_static_address_write, @@ -1177,6 +1183,7 @@ static ssize_t force_no_mitm_write(struct file *file, } static const struct file_operations force_no_mitm_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = force_no_mitm_read, .write = force_no_mitm_write, @@ -1315,6 +1322,7 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf, } static const struct file_operations dut_mode_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = dut_mode_read, .write = dut_mode_write, @@ -1371,6 +1379,7 @@ done: } static const struct file_operations vendor_diag_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = vendor_diag_read, .write = vendor_diag_write, From 4b76fa362110cf1b74a0263c14406b71de99894c Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Thu, 8 Oct 2026 12:18:50 +0800 Subject: [PATCH 1735/2126] Bluetooth: hci_sync: Protect IRK identity reads with RCU hci_le_set_privacy_mode_sync() needs the IRK returned by hci_find_irk_by_addr() to remain allocated until its identity address and type have been copied into the command. The finder drops its RCU read lock before returning this borrowed pointer, leaving the later field reads unprotected. When a privacy-capable controller has a pending peer with address resolution and device privacy enabled, accept-list programming can reach this helper while management reloads the IRKs. The request worker holds hdev->req_lock, whereas load_irks() takes hdev->lock, allowing the following ordering: Request worker Management / RCU reclaim hci_le_set_privacy_mode_sync() hci_find_irk_by_addr() rcu_read_lock() find matching IRK rcu_read_unlock() return borrowed IRK load_irks() hci_dev_lock(hdev) hci_smp_irks_clear() list_del_rcu() kfree_rcu() hci_dev_unlock(hdev) RCU grace period and IRK free read irk->addr_type copy irk->bdaddr The request then accesses a freed IRK. KASAN reports a one-byte use-after-free read of addr_type on this path. Keep an outer RCU read-side critical section across the lookup and both identity-field copies. The finder's nested unlock then leaves the IRK protected until the caller finishes copying it. Release RCU on a lookup miss and after copying the fields, before the synchronous HCI command can sleep. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in hci_le_add_accept_list_sync+0x90f/0x940 Read of size 1 at addr ffff88810aa6072c by task kworker/u17:0/493 Workqueue: hci0 hci_cmd_sync_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? hci_le_add_accept_list_sync+0x90f/0x940 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? hci_le_add_accept_list_sync+0x90f/0x940 kasan_report+0xe0/0x110 ? hci_le_add_accept_list_sync+0x90f/0x940 hci_le_add_accept_list_sync+0x90f/0x940 ? __pfx_hci_le_add_accept_list_sync+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? conn_params_copy+0x3a0/0x650 hci_passive_scan_sync+0x8c9/0x1e80 ? __pfx_hci_passive_scan_sync+0x10/0x10 ? find_held_lock+0x2b/0x80 ? hci_lookup_le_connect+0x181/0x3c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? find_held_lock+0x2b/0x80 ? hci_update_passive_scan_sync+0x437/0x950 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x280 hci_update_passive_scan_sync+0x461/0x950 hci_cmd_sync_work+0x1b3/0x450 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 507: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x251/0x610 hci_add_irk+0xb6/0x220 load_irks+0x5ef/0x7e0 hci_sock_sendmsg+0x128b/0x22e0 __sys_sendto+0x425/0x470 __x64_sys_sendto+0xe5/0x1c0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 0: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 __rcu_free_sheaf_prepare+0x65/0x2a0 rcu_free_sheaf+0x1f/0xe0 rcu_core+0x661/0x1d10 handle_softirqs+0x201/0x930 __irq_exit_rcu+0x110/0x1e0 irq_exit_rcu+0xe/0x20 sysvec_apic_timer_interrupt+0x6c/0x80 asm_sysvec_apic_timer_interrupt+0x1a/0x20 The buggy address belongs to the object at ffff88810aa60700 which belongs to the cache kmalloc-64 of size 64 The buggy address is located 44 bytes inside of freed 64-byte region [ffff88810aa60700, ffff88810aa60740) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10aa60 flags: 0x200000000000000(node=0|zone=2) page_type: f5(slab) raw: 0200000000000000 ffff8881000428c0 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88810aa60600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ffff88810aa60680: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc >ffff88810aa60700: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ^ ffff88810aa60780: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ffff88810aa60800: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ================================================================== Disabling lock debugging due to kernel taint Fixes: adae20cb2d20 ("Bluetooth: Convert IRK list to RCU") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 014ceaefd788..efbd2e5387c0 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2591,13 +2591,19 @@ static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, if (!(params->flags & HCI_CONN_FLAG_DEVICE_PRIVACY)) return 0; + rcu_read_lock(); + irk = hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type); - if (!irk) + if (!irk) { + rcu_read_unlock(); return 0; + } memset(&cp, 0, sizeof(cp)); cp.bdaddr_type = irk->addr_type; bacpy(&cp.bdaddr, &irk->bdaddr); + rcu_read_unlock(); + cp.mode = HCI_DEVICE_PRIVACY; /* Note: params->privacy_mode is not updated since it is a copy */ From 645ee6b176c958579cff1c783413d5cff65c8197 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 11:54:13 +0700 Subject: [PATCH 1736/2126] Bluetooth: hci_vhci: Pin module for debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, force_suspend_fops, force_wakeup_fops, aosp_capable_fops, and force_devcoredump_fops have no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the hci_vhci module. When userspace opens any of these debugfs files and later closes the /dev/vhci file descriptor (triggering vhci_release() and debugfs file removal), the open debugfs file descriptor remains valid in userspace. Because the module refcount was not incremented, the hci_vhci module can be unloaded via delete_module (rmmod hci_vhci). When the userspace process subsequently closes the debugfs file descriptor, full_proxy_release() accesses the already unmapped file_operations structure, resulting in a kernel page fault / oops: BUG: unable to handle page fault for address: fffffbfff846f18b #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page Oops: Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0xc3/0x590 entry_SYSCALL_64_after_hwframe+0x76/0x7e Modules linked in: ... [last unloaded: hci_vhci(E)] The issue was discovered via manual code audit of drivers/bluetooth/hci_vhci.c and verified on a Linux 7.3-rc6 test VM with CONFIG_BT_VHCI=m by keeping a debugfs file open across controller teardown and module unload. Set .owner = THIS_MODULE on all four file_operations structures so that debugfs pins the module until all file descriptors are closed. Fixes: 28010791193a ("Bluetooth: vhci: Prevent use-after-free by removing debugfs files early") Cc: stable@vger.kernel.org Signed-off-by: Bui Viet Dung Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index eddb32b30539..8f7db0102b25 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -155,6 +155,7 @@ static ssize_t force_suspend_write(struct file *file, } static const struct file_operations force_suspend_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = force_suspend_read, .write = force_suspend_write, @@ -194,6 +195,7 @@ static ssize_t force_wakeup_write(struct file *file, } static const struct file_operations force_wakeup_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = force_wakeup_read, .write = force_wakeup_write, @@ -263,6 +265,7 @@ static ssize_t aosp_capable_write(struct file *file, } static const struct file_operations aosp_capable_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = aosp_capable_read, .write = aosp_capable_write, @@ -386,6 +389,7 @@ static ssize_t force_devcd_write(struct file *file, const char __user *user_buf, } static const struct file_operations force_devcoredump_fops = { + .owner = THIS_MODULE, .open = simple_open, .write = force_devcd_write, }; From 4020751fd0df45ce5029a5dd69e1bb68a25cb4dd Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Thu, 8 Oct 2026 12:26:26 +0800 Subject: [PATCH 1737/2126] Bluetooth: L2CAP: Hold the listener while notifying child teardown A pending child's listener must remain alive until the child's teardown callback finishes notifying it. l2cap_sock_teardown_cb() saves the raw bt_sk(sk)->parent pointer, calls bt_accept_unlink(), then invokes parent->sk_data_ready(). The accept queue holds a reference to the child, but the callback takes no reference to the listener across unlink. When an incoming child has not been accepted, HCI disconnection can reach l2cap_conn_del() and the child's teardown callback while another task closes the listener. The listener channel has no connection, so the child's connection and channel locks do not serialize listener release. The following ordering is possible: HCI child teardown Listener release lock the child socket save parent bt_accept_unlink(sk) drain the empty accept queue bt_sock_unlink() shut down the listener channel sock_orphan() l2cap_sock_kill() parent->sk_data_ready(parent) If no other reference delays freeing the listener, the final notification reads sk_data_ready through freed socket storage. The child lock cannot stop listener release once the child is no longer on the accept queue. Take a listener socket reference before unlinking the child and release it after sk_data_ready() returns. While the child remains queued, its socket lock prevents listener cleanup from completing the dequeue, so the listener is still alive when the reference is acquired. The reference then protects the notification after unlink without changing lock order or the ordering of queue removal and wakeup. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in l2cap_sock_teardown_cb+0x467/0x490 Read of size 8 at addr ffff88810b99b188 by task kworker/u17:3/516 Workqueue: hci1 hci_rx_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? l2cap_sock_teardown_cb+0x467/0x490 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? l2cap_sock_teardown_cb+0x467/0x490 kasan_report+0xe0/0x110 ? l2cap_sock_teardown_cb+0x467/0x490 l2cap_sock_teardown_cb+0x467/0x490 l2cap_chan_del+0x123/0x8f0 l2cap_conn_del+0x31b/0x740 ? hci_cmd_sync_submit+0x264/0x320 ? __pfx_l2cap_disconn_cfm+0x10/0x10 l2cap_disconn_cfm+0x87/0xd0 hci_disconn_complete_evt+0x30f/0x990 ? srso_alias_return_thunk+0x5/0xfbef5 hci_event_packet+0x894/0xc70 ? __pfx_hci_disconn_complete_evt+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_hci_event_packet+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? free_zapped_rcu+0xd0/0x1e0 ? srso_alias_return_thunk+0x5/0xfbef5 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? __pfx_hci_cmd_sync_complete+0x10/0x10 ? trace_hardirqs_on+0x18/0x160 ? srso_alias_return_thunk+0x5/0xfbef5 hci_rx_work+0x367/0xf00 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 502: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_noprof+0x2d7/0x770 sk_prot_alloc+0x13e/0x260 sk_alloc+0x37/0xb40 bt_sock_alloc+0x40/0x3b0 l2cap_sock_create+0x116/0x310 bt_sock_create+0x171/0x330 __sock_create+0x2c4/0x730 __sys_socket+0x141/0x210 __x64_sys_socket+0x77/0xc0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 502: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 __sk_destruct+0x64f/0x790 sk_destruct+0xb3/0xd0 __sk_free+0xdd/0x370 sk_free+0x51/0x80 l2cap_sock_kill+0x17a/0x2a0 l2cap_sock_release+0x1d0/0x310 __sock_release+0xb8/0x270 sock_close+0x21/0x30 __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88810b99b000 which belongs to the cache kmalloc-2k of size 2048 The buggy address is located 392 bytes inside of freed 2048-byte region [ffff88810b99b000, ffff88810b99b800) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10b998 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000040(head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000040 ffff888100042f00 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000080008 00000000f5000000 0000000000000000 head: 0200000000000040 ffff888100042f00 dead000000000100 dead000000000122 head: 0000000000000000 0000000000080008 00000000f5000000 0000000000000000 head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88810b99b080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88810b99b100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88810b99b180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88810b99b200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88810b99b280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index c92f31b997dd..65097d6ef9d8 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1751,8 +1751,14 @@ static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err) sk->sk_err = err; if (parent) { + /* + * Keep the listener alive after unlinking the + * child. + */ + sock_hold(parent); bt_accept_unlink(sk); parent->sk_data_ready(parent); + sock_put(parent); } else { sk->sk_state_change(sk); } From 64aabf94ecccb1120a63b4ee5a6761871a181a41 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 12:18:03 +0700 Subject: [PATCH 1738/2126] Bluetooth: selftest: Pin module for selftest debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, test_smp_fops in net/bluetooth/smp.c and test_ecdh_fops in net/bluetooth/selftest.c have no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth module. When CONFIG_BT=m and selftests are enabled, a userspace process can open either /sys/kernel/debug/bluetooth/selftest_smp or /sys/kernel/debug/bluetooth/selftest_ecdh and keep the file descriptor open while the module is unloaded (rmmod bluetooth). When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release(): BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The issue was discovered via manual code audit of net/bluetooth/smp.c and net/bluetooth/selftest.c. Set .owner = THIS_MODULE on test_smp_fops and test_ecdh_fops so that debugfs keeps the module pinned until the file descriptors are closed. Fixes: 64dd374eac15 ("Bluetooth: Export SMP selftest result in debugfs") Fixes: 6de50f9fdb60 ("Bluetooth: Export ECDH selftest result in debugfs") Cc: stable@vger.kernel.org Signed-off-by: Bui Viet Dung Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/selftest.c | 1 + net/bluetooth/smp.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/bluetooth/selftest.c b/net/bluetooth/selftest.c index ae5b44bb9d3d..cdfc40e0016b 100644 --- a/net/bluetooth/selftest.c +++ b/net/bluetooth/selftest.c @@ -188,6 +188,7 @@ static ssize_t test_ecdh_read(struct file *file, char __user *user_buf, } static const struct file_operations test_ecdh_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = test_ecdh_read, .llseek = default_llseek, diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 5c3bd4278386..5dac8b2eae42 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -3698,6 +3698,7 @@ static ssize_t test_smp_read(struct file *file, char __user *user_buf, } static const struct file_operations test_smp_fops = { + .owner = THIS_MODULE, .open = simple_open, .read = test_smp_read, .llseek = default_llseek, From cf87709d7ff83b4de5d42b61e4a9806fe374cb9d Mon Sep 17 00:00:00 2001 From: Kiran K Date: Thu, 8 Oct 2026 19:36:01 +0530 Subject: [PATCH 1739/2126] Bluetooth: btintel: Zero version data before parsing TLVs Firmware may omit optional TLVs, leaving their corresponding fields unset in the caller-supplied struct intel_version_tlv. Since the structure is typically stack-allocated and not cleared beforehand, fields for which no TLV is received retain uninitialized stack memory. This stale data can be logged via btintel_version_info_tlv() and copied back to the caller, leaking kernel stack contents. Clear the structure in btintel_read_version_tlv() before parsing so that fields with no corresponding TLV are deterministically zero instead of containing garbage. Fixes: 57375beef71a ("Bluetooth: btintel: Add infrastructure to read controller information") Signed-off-by: Kiran K Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index f298c91f4f4e..c4a6b5ea64f1 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -752,6 +752,7 @@ static int btintel_read_version_tlv(struct hci_dev *hdev, return -EIO; } + memset(version, 0, sizeof(*version)); err = btintel_parse_version_tlv(hdev, version, skb); kfree_skb(skb); From 154a6e79ad38253d12078e40031cd05d54dac9be Mon Sep 17 00:00:00 2001 From: Kiran K Date: Thu, 8 Oct 2026 19:36:02 +0530 Subject: [PATCH 1740/2126] Bluetooth: btintel: load unlocker.sfi to allow unsigned firmware When an unsigned operational firmware image is needed for debug, the controller requires intel/unlocker.sfi to be loaded first. Without the unlocker image, the controller rejects the unsigned operational firmware. Support both firmware download flows based on the unlock policy advertised in the version TLV: BlazarI/BlazarIW/BlazarU/Gale Peak (unlock_policy == 0): Boot ROM -> unlocker.sfi -> IML -> OPFW Scorpius Peak onwards (unlock_policy == 1): Boot ROM -> IML -> unlocker.sfi -> OPFW Parse the new INTEL_TLV_UNLOCK_POLICY and INTEL_TLV_PLATFORM_ID TLVs into struct intel_version_tlv, track the pending unlocker load through a new btintel_data::unlocker flag, and pick intel/unlocker.sfi as the firmware filename when that flag is set. If the unlocker image is not present in the firmware search path, the driver silently falls through to the normal firmware download path. If the unlocker image is present but fails to download to the controller, the driver logs the error and aborts bootloader setup, since continuing would leave the controller in an inconsistent state. [ 413.375247] Bluetooth: hci0: Found device firmware: intel/unlocker.sfi [ 413.501051] Bluetooth: hci0: Waiting for firmware download to complete [ 413.501058] Bluetooth: hci0: Firmware loaded in 122864 usecs [ 413.501537] Bluetooth: hci0: Found device firmware: intel/ibt-02a2-01a1.sfi [ 413.501547] Bluetooth: hci0: Boot Address: 0x10001000 [ 413.501548] Bluetooth: hci0: Firmware Version: 137-39.26 [ 414.103473] Bluetooth: hci0: Waiting for firmware download to complete [ 414.103478] Bluetooth: hci0: Firmware loaded in 587841 usecs [ 414.149576] Bluetooth: hci0: Applying Intel DDC parameters completed [ 414.150089] Bluetooth: hci0: Firmware timestamp 2026.39 buildtype 3 build 86921 [ 414.150092] Bluetooth: hci0: Firmware SHA1: 0xeb2e0a4b [ 414.150093] Bluetooth: hci0: Platform ID: 570c6ffbcbe6 [ 414.150094] Bluetooth: hci0: Fseq status: Success (0x00) [ 414.150730] Bluetooth: hci0: Fseq executed: 15.255.00.98 [ 414.150734] Bluetooth: hci0: Fseq BT Top: 06.32.00.02 Assisted-by: Copilot:Claude Opus 4.7 Signed-off-by: Ravindra Signed-off-by: Kiran K Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 94 +++++++++++++++++++++++++++++++++++-- drivers/bluetooth/btintel.h | 5 ++ 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index c4a6b5ea64f1..0709fb3212f9 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -579,6 +579,11 @@ int btintel_version_info_tlv(struct hci_dev *hdev, if (version->img_type == BTINTEL_IMG_OP) bt_dev_info(hdev, "Firmware SHA1: 0x%8.8x", version->git_sha1); + if (!mem_is_zero(version->platform_id, sizeof(version->platform_id))) + bt_dev_info(hdev, "Platform ID: %6phN", version->platform_id); + + bt_dev_info(hdev, "Unlock policy: 0x%2.2x", version->unlock_policy); + return 0; } EXPORT_SYMBOL_GPL(btintel_version_info_tlv); @@ -604,11 +609,14 @@ static u8 btintel_version_tlv_min_len(u8 type) case INTEL_TLV_DEBUG_LOCK: case INTEL_TLV_LIMITED_CCE: case INTEL_TLV_SBE_TYPE: + case INTEL_TLV_UNLOCK_POLICY: return sizeof(u8); case INTEL_TLV_MIN_FW: return 3; case INTEL_TLV_OTP_BDADDR: return sizeof(bdaddr_t); + case INTEL_TLV_PLATFORM_ID: + return sizeof(((struct intel_version_tlv *)0)->platform_id); default: return 0; } @@ -716,6 +724,13 @@ int btintel_parse_version_tlv(struct hci_dev *hdev, snprintf(version->fw_id, sizeof(version->fw_id), "%.*s", tlv->len, tlv->val); break; + case INTEL_TLV_UNLOCK_POLICY: + version->unlock_policy = tlv->val[0]; + break; + case INTEL_TLV_PLATFORM_ID: + memcpy(version->platform_id, tlv->val, + sizeof(version->platform_id)); + break; default: /* Ignore rest of information */ break; @@ -2473,7 +2488,12 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev, else btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi"); } else { - btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi"); + if (intel_data->unlocker) { + strscpy(fwname, "intel/unlocker.sfi"); + intel_data->unlocker = false; + } else { + btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi"); + } } err = firmware_request_nowarn(&fw, fwname, &hdev->dev); @@ -3490,6 +3510,36 @@ static int btintel_set_specific_absorption_rate(struct hci_dev *hdev, return 0; } +/* Attempt to load intel/unlocker.sfi if it is present in the firmware + * search path. If the file is not available the device will be booted + * with a signed operational firmware, which is the common case, so its + * absence must be treated as normal and not logged as an error. + */ +static int btintel_try_load_unlocker(struct hci_dev *hdev, + struct intel_version_tlv *ver) +{ + struct btintel_data *data = hci_get_priv(hdev); + const struct firmware *fw; + u32 boot_param = 0; + int err; + + err = firmware_request_nowarn(&fw, "intel/unlocker.sfi", &hdev->dev); + if (err) { + bt_dev_dbg(hdev, "intel/unlocker.sfi not present (%d), skipping unlocker load", + err); + return 0; + } + release_firmware(fw); + + data->unlocker = true; + err = btintel_prepare_fw_download_tlv(hdev, ver, &boot_param); + if (err) { + bt_dev_err(hdev, "Failed to load intel/unlocker.sfi (%d)", err); + data->unlocker = false; + } + return err; +} + int btintel_bootloader_setup_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver) { @@ -3497,6 +3547,8 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev, char ddcname[64]; int err; struct intel_version_tlv new_ver; + struct btintel_data *data = hci_get_priv(hdev); + u8 hw_variant = INTEL_HW_VARIANT(ver->cnvi_bt); bt_dev_dbg(hdev, ""); @@ -3515,6 +3567,31 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev, btintel_set_flag(hdev, INTEL_BOOTLOADER); + data->unlocker = false; + + /* Legacy unlocker flow (BlazarI / BlazarIW / BlazarU / Gale Peak): + * Boot ROM -> unlocker.sfi -> IML -> OPFW + * + * Skip the unlocker check when the controller is already running + * operational firmware (can happen on USB); the unlocker flow is + * only meaningful from the bootloader stage. + */ + if (ver->img_type != BTINTEL_IMG_OP && + ver->api_lock && ver->unlock_policy == 0) { + switch (hw_variant) { + case BTINTEL_HWID_BZRI: + case BTINTEL_HWID_BZRIW: + case BTINTEL_HWID_BZRU: + case BTINTEL_HWID_GAP: + err = btintel_try_load_unlocker(hdev, ver); + if (err) + return err; + break; + default: + break; + } + } + err = btintel_prepare_fw_download_tlv(hdev, ver, &boot_param); if (err) return err; @@ -3538,8 +3615,19 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev, return err; } - /* If image type returned is BTINTEL_IMG_IML, then controller supports - * intermediate loader image + /* New unlocker flow (Scorpius Peak onwards): + * Boot ROM -> IML -> unlocker.sfi -> OPFW + */ + if (hw_variant >= BTINTEL_HWID_SCP && + ver->api_lock && ver->unlock_policy == 1) { + err = btintel_try_load_unlocker(hdev, ver); + if (err) + return err; + } + + /* Transition to Operational Firmware + * If image type returned is BTINTEL_IMG_IML, then controller supports + * intermediate loader image. */ if (ver->img_type == BTINTEL_IMG_IML) { err = btintel_prepare_fw_download_tlv(hdev, ver, &boot_param); diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index ff7c1d623007..9526acf65959 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -43,6 +43,8 @@ enum { INTEL_TLV_OTP_BDADDR, INTEL_TLV_UNLOCKED_STATE, INTEL_TLV_GIT_SHA1, + INTEL_TLV_UNLOCK_POLICY = 0x3c, + INTEL_TLV_PLATFORM_ID = 0x3d, INTEL_TLV_FW_ID = 0x50 }; @@ -108,6 +110,8 @@ struct intel_version_tlv { u32 git_sha1; u8 fw_id[BTINTEL_FWID_MAXLEN]; bdaddr_t otp_bd_addr; + u8 unlock_policy; + u8 platform_id[6]; }; struct intel_version { @@ -261,6 +265,7 @@ struct btintel_data { DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS); int (*acpi_reset_method)(struct hci_dev *hdev); u32 cnvi_bt; + bool unlocker; }; #define btintel_set_flag(hdev, nr) \ From 47493e62e8a8522a250537ed2ce026dd7d9163b1 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 12 Oct 2026 11:26:59 -0400 Subject: [PATCH 1741/2126] Bluetooth: MGMT: Allow connection rate request as peripheral Load Connection Subrate only issues the LE Connection Rate Request when connected as central, but either role can initiate the Connection Rate Update procedure, e.g. a HID device, which is the peripheral, does it once the HID host requests a HID SCI mode with the HID Control Point. Issue it regardless of the role. Fixes: 19129d7037be ("Bluetooth: Add MGMT Load Connection Subrate command") Assisted-by: OpenCode:claude-opus-5.5 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 9f65863e7457..3b9c82bd2f02 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -8347,8 +8347,10 @@ static int load_conn_subrate(struct sock *sk, struct hci_dev *hdev, void *data, hci_param->cont_num = cont_num; hci_param->rate_supv_timeout = supv_timeout; - /* If the device is connected as central check if the - * connection rate parameters need to be updated. + /* If the device is connected check if the connection rate + * parameters need to be updated, either role can initiate the + * Connection Rate Update procedure, e.g. a HID device acting + * as peripheral once the HID host requests a HID SCI mode. */ if (!i && param_count == 1) { struct hci_conn *conn; @@ -8357,7 +8359,6 @@ static int load_conn_subrate(struct sock *sk, struct hci_dev *hdev, void *data, &hci_param->addr, addr_type); if (conn && conn->state == BT_CONNECTED && - conn->role == HCI_ROLE_MASTER && (conn->le_rate_interval < min || conn->le_rate_interval > max || conn->le_subrate < subrate_min || From 56e20c3d8ad340bbfc90221c4aae1c870485fb57 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Mon, 12 Oct 2026 10:48:06 +0800 Subject: [PATCH 1742/2126] Bluetooth: MSFT: Serialize handle map cleanup with event processing MSFT monitor handle mappings must remain valid while vendor events look up and use them under hdev->lock. msft_do_close() removes and frees the mappings without that lock. hci_dev_close_sync() clears HCI_UP and drains the RX workqueue before MSFT cleanup. However, a transport callback that already passed hci_recv_frame()'s state check can queue a vendor event after the drain returns, if no earlier shutdown callback has quiesced reception. The driver close callback runs after MSFT cleanup, so event processing can overlap the unlocked removal. msft_monitor_device_evt() can then traverse freed list entries or read handle_data->mgmt_handle after it is freed. Take hdev->lock while resetting monitor states and removing handle mappings in msft_do_close(), as normal monitor cancellation already does. An active event reader then finishes before its mapping is freed, and later lookups see an empty handle map. An instrumented kernel produced this KASAN report (timestamps removed and unrelated frames omitted): BUG: KASAN: slab-use-after-free in msft_vendor_evt+0x1906/0x1990 Read of size 2 at addr ffff888104df3602 by task kworker/u17:2/502 Workqueue: hci0 hci_rx_work Call Trace: [...] msft_vendor_evt+0x1906/0x1990 hci_vendor_evt+0x6f/0x90 hci_event_packet+0x894/0xc70 [...] hci_rx_work+0x3f8/0xfa0 [...] Allocated by task 499: [...] msft_add_monitor_sync+0x6a8/0x10a0 msft_add_monitor_pattern+0x7f/0xb0 hci_add_adv_monitor+0x1fa/0x2e0 [...] Freed by task 499: [...] kfree+0x307/0x580 msft_do_close+0x238/0x750 hci_dev_close_sync+0x546/0x1380 [...] The buggy address belongs to the object at ffff888104df3600 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 2 bytes inside of freed 32-byte region [ffff888104df3600, ffff888104df3620) [...] Fixes: 145373cb1b1f ("Bluetooth: Add framework for Microsoft vendor extension") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/msft.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index 6f4b7c38a247..2559c5b1bef0 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -683,6 +683,8 @@ void msft_do_close(struct hci_dev *hdev) bt_dev_dbg(hdev, "Cleanup of MSFT extension"); + hci_dev_lock(hdev); + /* The controller will silently remove all monitors on power off. * Therefore, remove handle_data mapping and reset monitor state. */ @@ -697,6 +699,8 @@ void msft_do_close(struct hci_dev *hdev) kfree(handle_data); } + hci_dev_unlock(hdev); + mutex_lock(&msft->filter_lock); list_for_each_entry_safe(address_filter, n, &msft->address_filters, list) { From 6747a37c3e2f4dced152974b277dbc0fc9dd4516 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 8 Oct 2026 16:55:59 +0800 Subject: [PATCH 1743/2126] Bluetooth: btmtk: Add MT7928 support Add support for MT7928 (internal device ID is MT7935) which requires additional firmware (CBMCU firmware) loading before Bluetooth firmware. CBMCU is a new component on MT7928 to handle common part shared across the combo chip, providing a better user experience through improved coordination between subsystems. Implement two-phase CBMCU firmware download: Phase 1 loads section with type 0x5 containing global descriptor, section maps and signature data; Phase 2 loads remaining firmware sections. The firmware is rejected if it has no Phase 1 section. The CBMCU is shared with the Wi-Fi driver, which may download the same firmware concurrently, so the firmware reports a status per section and hands each one to a single driver. This driver downloads a section the firmware reports as not downloaded, waits while the other driver holds it, and leaves alone one the firmware already has. This is the scheme btmtk_setup_firmware_79xx() already uses for the ROM patch shared with Wi-Fi, so no host side lock is needed. The driver then continues to load the corresponding BT firmware based on device ID through fallthrough to case 0x7922/0x7925. A CBMCU failure is only warned about and does not abort the setup, because the Wi-Fi driver may finish the same download on its own. A CBMCU left unusable makes the BT firmware download fail instead, which triggers the existing one-shot btmtk_reset_sync() recovery. The CBMCU firmware layout and section-map bounds are validated by reusing btmtk_fw_validate_layout() and btmtk_fw_validate_section(), the same helpers btmtk_setup_firmware_79xx() uses, instead of duplicating the overflow checks. Add the MT7928 (0x7935) case to btmtk_usb_subsys_reset(), which triggers the subsystem reset by setting BIT(31) of MTK_BT_RESET_REG_CONNV3. MT7928 bring-up kernel log: [ 6931.197167] usb 1-3: New USB device found, idVendor=0e8d, idProduct=7935, bcdDevice= 1.00 [ 6931.197212] usb 1-3: New USB device strings: Mfr=5, Product=6, SerialNumber=7 [ 6931.197237] usb 1-3: Product: Wireless_Device [ 6931.197258] usb 1-3: Manufacturer: MediaTek Inc. [ 6931.197279] usb 1-3: SerialNumber: 000000000 [ 6931.213478] Bluetooth: hci1: Loading CBMCU firmware: mediatek/mt7928/CBMCU_CODE_MT7935_1_1.bin [ 6931.215214] Bluetooth: hci1: CBMCU HW ver: 0x7935, SW ver: 0x0000, Build Time: 20260601T161751+ [ 6931.623962] Bluetooth: hci1: CBMCU firmware download completed [ 6931.643916] Bluetooth: hci1: Loading BT firmware: mediatek/mt7928/BT_RAM_CODE_MT7935_1_1_hdr.bin [ 6931.650467] Bluetooth: hci1: BT HW ver: 0x7935, SW ver: 0x0000, Build Time: 20260527000816 [ 6935.039790] Bluetooth: hci1: Device setup in 3369644 usecs [ 6935.039833] Bluetooth: hci1: HCI Enhanced Setup Synchronous Connection command is advertised, but not supported. [ 6935.160654] Bluetooth: hci1: AOSP extensions version v2.00 [ 6935.160710] Bluetooth: hci1: AOSP quality report is supported [ 6935.162954] Bluetooth: MGMT ver 1.23 Signed-off-by: Chris Lu Assisted-by: LLM Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btmtk.c | 403 ++++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btmtk.h | 3 + 2 files changed, 406 insertions(+) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index bdc85147b97f..75483d8230e1 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -22,6 +22,12 @@ #define MTK_FW_ROM_PATCH_SEC_MAP_SIZE 64 #define MTK_SEC_MAP_COMMON_SIZE 12 #define MTK_SEC_MAP_NEED_SEND_SIZE 52 +#define MTK_SEC_MAP_LENGTH_SIZE 4 +#define MTK_SEC_CBMCU_DESC 0x5 + +/* CBMCU WMT command flags */ +#define BTMTK_CBMCU_FLAG_QUERY_STATUS 0xF0 +#define BTMTK_CBMCU_FLAG_ENABLE_PATCH 0xF1 /* It is for mt79xx iso data transmission setting */ #define MTK_ISO_THRESHOLD 264 @@ -182,6 +188,11 @@ void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver, snprintf(buf, size, "mediatek/mt%04x/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", dev_id & 0xffff, dev_id & 0xffff, (fw_ver & 0xff) + 1); + /* MT7928 */ + else if (dev_id == 0x7935) + snprintf(buf, size, + "mediatek/mt7928/BT_RAM_CODE_MT%04x_1_1_hdr.bin", + dev_id & 0xffff); else if (dev_id == 0x7961 && fw_flavor) snprintf(buf, size, "mediatek/BT_RAM_CODE_MT%04x_1a_%x_hdr.bin", @@ -809,6 +820,7 @@ static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev, status = BTMTK_WMT_ON_UNDONE; break; case BTMTK_WMT_PATCH_DWNLD: + case BTMTK_WMT_CBMCU_DWNLD: if (wmt_evt->whdr.flag == 2) status = BTMTK_WMT_PATCH_DONE; else if (wmt_evt->whdr.flag == 1) @@ -933,6 +945,373 @@ static u32 btmtk_usb_reset_done(struct hci_dev *hdev) return val & MTK_BT_RST_DONE; } +static int btmtk_cbmcu_patch_status(struct hci_dev *hdev, + wmt_cmd_sync_func_t wmt_cmd_sync, + u8 *patch_status) +{ + struct btmtk_hci_wmt_params wmt_params; + int status = BTMTK_WMT_INVALID, err, retry = 20; + + do { + wmt_params.op = BTMTK_WMT_CBMCU_DWNLD; + wmt_params.flag = BTMTK_CBMCU_FLAG_QUERY_STATUS; + wmt_params.dlen = 0; + wmt_params.data = NULL; + wmt_params.status = &status; + + err = wmt_cmd_sync(hdev, &wmt_params); + if (err < 0) { + bt_dev_err(hdev, "Failed to query CBMCU patch status (%d)", err); + return err; + } + + *patch_status = (u8)status; + + if (*patch_status == BTMTK_WMT_PATCH_PROGRESS) { + msleep(100); + retry--; + } else { + break; + } + } while (retry > 0); + + if (*patch_status == BTMTK_WMT_PATCH_PROGRESS) { + bt_dev_err(hdev, "CBMCU patch status query timeout"); + return -ETIMEDOUT; + } + + return 0; +} + +/* Ask the firmware for the status of the given CBMCU section. A status of + * BTMTK_WMT_PATCH_UNDONE means the section has to be downloaded by the + * Bluetooth driver, and 0 is returned so the caller downloads it. A section + * the firmware already has is not expected here, because + * btmtk_setup_cbmcu_firmware() only reaches this point when the CBMCU patch + * as a whole is not downloaded, but it is not an error either: 1 is returned + * so the caller leaves that section alone. Any other status is an error. + */ +static int btmtk_query_cbmcu_section(struct hci_dev *hdev, + wmt_cmd_sync_func_t wmt_cmd_sync, + u8 cbmcu_type, + const u8 *section_map, + u32 cert_len) +{ + struct btmtk_hci_wmt_params wmt_params; + u8 cmd[64]; + int status = BTMTK_WMT_INVALID, err, retry = 20; + + cmd[0] = 0; + cmd[1] = cbmcu_type; + + if (cbmcu_type == 0) + put_unaligned_le32(cert_len, &cmd[2]); + else + memcpy(&cmd[2], section_map, MTK_SEC_MAP_NEED_SEND_SIZE); + + wmt_params.op = BTMTK_WMT_CBMCU_DWNLD; + wmt_params.flag = 0; + wmt_params.dlen = cbmcu_type ? + MTK_SEC_MAP_NEED_SEND_SIZE + 2 : + MTK_SEC_MAP_LENGTH_SIZE + 2; + wmt_params.data = cmd; + wmt_params.status = &status; + + /* The CBMCU is shared with the Wi-Fi driver, which may be downloading + * the same firmware. Wait while the other driver holds this section, + * the same way btmtk_setup_firmware_79xx() does for the ROM patch. + */ + while (retry--) { + err = wmt_cmd_sync(hdev, &wmt_params); + if (err < 0) { + bt_dev_err(hdev, "Failed to query CBMCU section (%d)", err); + return err; + } + + switch (status) { + case BTMTK_WMT_PATCH_UNDONE: + /* This section has to be downloaded by the BT driver */ + return 0; + case BTMTK_WMT_PATCH_DONE: + /* Already downloaded, nothing to do for this section */ + return 1; + case BTMTK_WMT_PATCH_PROGRESS: + msleep(100); + break; + default: + bt_dev_err(hdev, "CBMCU section query status error (%d)", + status); + return -EIO; + } + } + + bt_dev_err(hdev, "CBMCU section query timeout"); + return -ETIMEDOUT; +} + +static int btmtk_download_cbmcu_section(struct hci_dev *hdev, + wmt_cmd_sync_func_t wmt_cmd_sync, + const u8 *fw_data, + u32 dl_size) +{ + struct btmtk_hci_wmt_params wmt_params; + u32 sent_len, total_size = dl_size; + int err; + + wmt_params.op = BTMTK_WMT_CBMCU_DWNLD; + wmt_params.status = NULL; + + while (dl_size > 0) { + sent_len = min_t(u32, 250, dl_size); + + if (dl_size == total_size) + wmt_params.flag = BTMTK_WMT_PKT_START; + else if (dl_size == sent_len) + wmt_params.flag = BTMTK_WMT_PKT_END; + else + wmt_params.flag = BTMTK_WMT_PKT_CONTINUE; + + wmt_params.dlen = sent_len; + wmt_params.data = fw_data; + + err = wmt_cmd_sync(hdev, &wmt_params); + if (err < 0) { + bt_dev_err(hdev, "Failed to send CBMCU section data (%d)", err); + return err; + } + + dl_size -= sent_len; + fw_data += sent_len; + } + + return 0; +} + +static int btmtk_enable_cbmcu_patch(struct hci_dev *hdev, + wmt_cmd_sync_func_t wmt_cmd_sync) +{ + struct btmtk_hci_wmt_params wmt_params; + int err; + + wmt_params.op = BTMTK_WMT_CBMCU_DWNLD; + wmt_params.flag = BTMTK_CBMCU_FLAG_ENABLE_PATCH; + wmt_params.dlen = 0; + wmt_params.data = NULL; + wmt_params.status = NULL; + + err = wmt_cmd_sync(hdev, &wmt_params); + if (err < 0) { + bt_dev_err(hdev, "Failed to enable CBMCU patch (%d)", err); + return err; + } + + return 0; +} + +static int btmtk_load_cbmcu_firmware(struct hci_dev *hdev, + const char *fwname, + wmt_cmd_sync_func_t wmt_cmd_sync, + u32 dev_id) +{ + struct btmtk_patch_header *hdr; + struct btmtk_section_map *sectionmap; + const struct firmware *fw; + const u8 *fw_ptr; + u8 *cert_buf = NULL; + u32 section_num, section_offset, dl_size, i; + size_t map_len, cert_len; + bool phase1_done = false; + int err; + + err = request_firmware(&fw, fwname, &hdev->dev); + if (err < 0) { + bt_dev_err(hdev, "Failed to load CBMCU firmware file %s (%d)", + fwname, err); + return err; + } + + err = btmtk_fw_validate_layout(hdev, fw, §ion_num); + if (err < 0) + goto err_release_fw; + + fw_ptr = fw->data; + hdr = (struct btmtk_patch_header *)fw_ptr; + + bt_dev_info(hdev, "CBMCU HW ver: 0x%04x, SW ver: 0x%04x, Build Time: %.16s", + dev_id & 0xffff, le16_to_cpu(hdr->swver), hdr->datetime); + + /* Phase 1: Download section type MTK_SEC_CBMCU_DESC */ + for (i = 0; i < section_num; i++) { + sectionmap = (struct btmtk_section_map *) + (fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE + + MTK_FW_ROM_PATCH_GD_SIZE + + (size_t)MTK_FW_ROM_PATCH_SEC_MAP_SIZE * i); + + /* Only process MTK_SEC_CBMCU_DESC section in Phase 1 */ + if ((le32_to_cpu(sectionmap->sectype) & 0xFFFF) != MTK_SEC_CBMCU_DESC) + continue; + + section_offset = le32_to_cpu(sectionmap->secoffset); + /* Unlike the sections downloaded in Phase 2, this one carries + * the signature blob rather than a download target, so its + * length is secsize and not bin_info_spec.dlsize. + */ + dl_size = le32_to_cpu(sectionmap->secsize); + + if (dl_size == 0) + continue; + + err = btmtk_fw_validate_section(hdev, fw, i, + section_offset, dl_size); + if (err < 0) + goto err_release_fw; + + map_len = MTK_FW_ROM_PATCH_GD_SIZE + + (size_t)MTK_FW_ROM_PATCH_SEC_MAP_SIZE * section_num; + if (check_add_overflow(map_len, (size_t)dl_size, &cert_len) || + cert_len > U32_MAX) { + err = -EINVAL; + goto err_release_fw; + } + + /* Build the certificate before the query, because the firmware + * hands this section over to whoever is told to download it. + */ + cert_buf = kmalloc(cert_len, GFP_KERNEL | __GFP_NOWARN); + if (!cert_buf) { + err = -ENOMEM; + goto err_release_fw; + } + + /* Global Descriptor + All Section Maps, then the section data */ + memcpy(cert_buf, fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE, map_len); + memcpy(cert_buf + map_len, fw_ptr + section_offset, dl_size); + + /* Query cbmcu section */ + err = btmtk_query_cbmcu_section(hdev, wmt_cmd_sync, 0, NULL, + cert_len); + if (err < 0) + goto err_release_fw; + + /* Download the section unless the firmware already has it */ + if (!err) { + err = btmtk_download_cbmcu_section(hdev, wmt_cmd_sync, + cert_buf, cert_len); + if (err < 0) { + bt_dev_err(hdev, "Failed to download CBMCU Phase 1 section (%d)", + err); + goto err_release_fw; + } + } + + kfree(cert_buf); + cert_buf = NULL; + phase1_done = true; + break; + } + + if (!phase1_done) { + bt_dev_err(hdev, "CBMCU firmware has no Phase 1 section"); + err = -EINVAL; + goto err_release_fw; + } + + /* Phase 2: Download other sections (type != MTK_SEC_CBMCU_DESC) */ + for (i = 0; i < section_num; i++) { + sectionmap = (struct btmtk_section_map *) + (fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE + + MTK_FW_ROM_PATCH_GD_SIZE + + (size_t)MTK_FW_ROM_PATCH_SEC_MAP_SIZE * i); + + /* Skip MTK_SEC_CBMCU_DESC section in Phase 2 */ + if ((le32_to_cpu(sectionmap->sectype) & 0xFFFF) == MTK_SEC_CBMCU_DESC) + continue; + + section_offset = le32_to_cpu(sectionmap->secoffset); + dl_size = le32_to_cpu(sectionmap->bin_info_spec.dlsize); + + if (dl_size == 0) + continue; + + err = btmtk_fw_validate_section(hdev, fw, i, + section_offset, dl_size); + if (err < 0) + goto err_release_fw; + + /* Query cbmcu section */ + err = btmtk_query_cbmcu_section(hdev, wmt_cmd_sync, 1, + (u8 *)§ionmap->bin_info_spec, + 0); + if (err < 0) + goto err_release_fw; + + /* Nothing to do if the firmware already has this section */ + if (err) + continue; + + /* Download section data */ + err = btmtk_download_cbmcu_section(hdev, wmt_cmd_sync, + fw_ptr + section_offset, + dl_size); + if (err < 0) { + bt_dev_err(hdev, "Failed to download CBMCU section %u (%d)", i, err); + goto err_release_fw; + } + } + + /* A section the firmware already had leaves err > 0 */ + err = 0; + bt_dev_info(hdev, "CBMCU firmware download completed"); + +err_release_fw: + kfree(cert_buf); + release_firmware(fw); + return err; +} + +static int btmtk_setup_cbmcu_firmware(struct hci_dev *hdev, + wmt_cmd_sync_func_t wmt_cmd_sync, + u32 dev_id) +{ + char cbmcu_fwname[64]; + u8 patch_status; + int err; + + err = btmtk_cbmcu_patch_status(hdev, wmt_cmd_sync, &patch_status); + if (err < 0) + return err; + + bt_dev_dbg(hdev, "CBMCU patch status: 0x%02x", patch_status); + + /* Nothing to do if the firmware is already running */ + if (patch_status == BTMTK_WMT_PATCH_DONE) + return 0; + + if (patch_status != BTMTK_WMT_PATCH_UNDONE) { + bt_dev_err(hdev, "Unexpected CBMCU patch status (0x%02x)", + patch_status); + return -EIO; + } + + snprintf(cbmcu_fwname, sizeof(cbmcu_fwname), + "mediatek/mt7928/CBMCU_CODE_MT%04x_1_1.bin", + dev_id & 0xffff); + + bt_dev_info(hdev, "Loading CBMCU firmware: %s", cbmcu_fwname); + + err = btmtk_load_cbmcu_firmware(hdev, cbmcu_fwname, wmt_cmd_sync, dev_id); + if (err < 0) { + bt_dev_err(hdev, "Failed to download CBMCU firmware (%d)", err); + return err; + } + + err = btmtk_enable_cbmcu_patch(hdev, wmt_cmd_sync); + if (err < 0) + return err; + + return 0; +} + int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id) { int reset_err = 0; @@ -997,6 +1376,14 @@ int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id) if (err) return err; msleep(100); + } else if (dev_id == 0x7935) { + err = btmtk_usb_uhw_reg_read(hdev, MTK_BT_RESET_REG_CONNV3, &val); + if (err) + return err; + val |= BIT(31); + err = btmtk_usb_uhw_reg_write(hdev, MTK_BT_RESET_REG_CONNV3, val); + if (err < 0) + return err; } else { /* It's Device EndPoint Reset Option Register */ bt_dev_dbg(hdev, "Initiating reset mechanism via uhw"); @@ -1451,6 +1838,20 @@ int btmtk_usb_setup(struct hci_dev *hdev) case 0x7668: fwname = FIRMWARE_MT7668; break; + case 0x7935: + /* Requires CBMCU firmware before BT firmware */ + err = btmtk_setup_cbmcu_firmware(hdev, btmtk_usb_hci_wmt_sync, + dev_id); + /* Carry on with the BT firmware even if this failed. The Wi-Fi + * driver may be downloading the same CBMCU firmware and finish + * it on its own, and if the CBMCU is left unusable the BT + * firmware download below fails and triggers the one-shot + * btmtk_reset_sync() recovery. + */ + if (err < 0) + bt_dev_warn(hdev, "Failed to set up CBMCU firmware (%d)", + err); + fallthrough; case 0x7922: case 0x7925: case 0x7961: @@ -1663,3 +2064,5 @@ MODULE_FIRMWARE(FIRMWARE_MT7961); MODULE_FIRMWARE(FIRMWARE_MT7920); MODULE_FIRMWARE(FIRMWARE_MT7925); MODULE_FIRMWARE(FIRMWARE_MT7927); +MODULE_FIRMWARE(FIRMWARE_MT7928); +MODULE_FIRMWARE(FIRMWARE_MT7928_CBMCU); diff --git a/drivers/bluetooth/btmtk.h b/drivers/bluetooth/btmtk.h index e8ad281a93a0..58643ec39667 100644 --- a/drivers/bluetooth/btmtk.h +++ b/drivers/bluetooth/btmtk.h @@ -10,6 +10,8 @@ #define FIRMWARE_MT7920 "mediatek/BT_RAM_CODE_MT7961_1a_2_hdr.bin" #define FIRMWARE_MT7925 "mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin" #define FIRMWARE_MT7927 "mediatek/mt7927/BT_RAM_CODE_MT6639_2_1_hdr.bin" +#define FIRMWARE_MT7928 "mediatek/mt7928/BT_RAM_CODE_MT7935_1_1_hdr.bin" +#define FIRMWARE_MT7928_CBMCU "mediatek/mt7928/CBMCU_CODE_MT7935_1_1.bin" #define HCI_EV_WMT 0xe4 #define HCI_WMT_MAX_EVENT_SIZE 64 @@ -55,6 +57,7 @@ enum { BTMTK_WMT_RST = 0x7, BTMTK_WMT_REGISTER = 0x8, BTMTK_WMT_SEMAPHORE = 0x17, + BTMTK_WMT_CBMCU_DWNLD = 0x58, }; enum { From de2077eb216c43087b396e3eb34921bdfe18ddfc Mon Sep 17 00:00:00 2001 From: Catherine L Date: Tue, 13 Oct 2026 15:06:50 +0530 Subject: [PATCH 1744/2126] Bluetooth: btintel_pcie: Add PCI ID for Titan Lake Add PCI ID 0x9329 for Titan Lake (Scorpius Peak2 C0). sudo lspci -v -k -d 8086:9329 02:00.0 Bluetooth: Intel Corporation Device 9329 Subsystem: Intel Corporation Device 0012 Flags: bus master, fast devsel, latency 0, IRQ 16 Memory at fe000000 (32-bit, non-prefetchable) [size=16K] Capabilities: [c8] Power Management version 3 Capabilities: [d0] MSI: Enable- Count=1/1 Maskable- 64bit+ Capabilities: [40] Express Root Complex Integrated Endpoint, MSI 00 Capabilities: [80] MSI-X: Enable+ Count=5 Masked- Kernel driver in use: btintel_pcie Kernel modules: btintel_pcie Signed-off-by: Catherine L Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 3a555aa50c87..91b1ee9d6010 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -59,6 +59,8 @@ static const struct pci_device_id btintel_pcie_table[] = { /* Draco */ { BTINTEL_PCI_DEVICE(0x2731, PCI_ANY_ID) }, { BTINTEL_PCI_DEVICE(0x2732, PCI_ANY_ID) }, + /* Scorpious Peak2 C0, Titan Lake */ + { BTINTEL_PCI_DEVICE(0x9329, PCI_ANY_ID) }, { 0 } }; MODULE_DEVICE_TABLE(pci, btintel_pcie_table); From 5ba2dc0439c629c8e4c34c8ffa1ed35d862d9371 Mon Sep 17 00:00:00 2001 From: Catherine L Date: Tue, 13 Oct 2026 14:51:28 +0530 Subject: [PATCH 1745/2126] Bluetooth: btusb: annotate Intel Otter Peak 2 USB ID Move USB ID 0x0043 next to 0x0040 to keep the Intel entries in numerical order, and annotate it as Otter Peak 2 (AX231) used on Wildcat Lake. Fixes: 69bf0c2b348f ("Bluetooth: btusb: Add support for Intel Otter Peak2 (OrP2)") Signed-off-by: Catherine L Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btusb_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 71d8dccb29d3..92a78a7e6039 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -515,8 +515,9 @@ static const struct usb_device_id quirks_table[] = { { USB_DEVICE(0x8087, 0x0037), .driver_info = BTUSB_INTEL_COMBINED }, { USB_DEVICE(0x8087, 0x0038), .driver_info = BTUSB_INTEL_COMBINED }, { USB_DEVICE(0x8087, 0x0039), .driver_info = BTUSB_INTEL_COMBINED }, - { USB_DEVICE(0x8087, 0x0043), .driver_info = BTUSB_INTEL_COMBINED }, /* Otter Peak 2 */ { USB_DEVICE(0x8087, 0x0040), .driver_info = BTUSB_INTEL_COMBINED }, /* Lizard Peak 2 */ + /* Otter Peak 2 (AX231), Wildcat Lake */ + { USB_DEVICE(0x8087, 0x0043), .driver_info = BTUSB_INTEL_COMBINED }, { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED | BTUSB_INTEL_NO_WBS_SUPPORT | From 91638f53ff2b8234195ff27ec913e068269a28e9 Mon Sep 17 00:00:00 2001 From: Kevin Dewald Date: Tue, 13 Oct 2026 00:16:15 -0700 Subject: [PATCH 1746/2126] Bluetooth: hci_event: Fix LE link drop on remote features command status When the local controller supports peripheral-initiated features exchange, the LE Read Remote Features procedure also runs for incoming connections, and it fails with Unsupported Remote Feature (0x1a) if the central does not support that feature. hci_le_remote_feat_complete_evt() and hci_le_read_all_remote_features_evt() handle this and let the connection transition into connected state. A controller can also return that error in the Command Status event instead. An Intel controller does so for a central that does not support peripheral-initiated features exchange, presumably because it already has the features of the central. hci_cs_le_read_remote_features() and hci_cs_le_read_all_remote_features() then confirm the connection as failed while it is still in BT_CONFIG, and the hci_conn_drop() in le_read_features_complete() disconnects it right away: > HCI Event: LE Meta Event (0x3e) plen 31 LE Enhanced Connection Complete (0x0a) Status: Success (0x00) Role: Peripheral (0x01) < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2 > HCI Event: Command Status (0x0f) plen 4 LE Read Remote Used Features (0x08|0x0016) ncmd 1 Status: Unsupported Remote Feature / Unsupported LMP Feature (0x1a) < HCI Command: Disconnect (0x01|0x0006) plen 3 Reason: Remote User Terminated Connection (0x13) Data the central sends afterwards is reported as: Bluetooth: hci0: ACL packet for unknown connection handle 3585 Handle Unsupported Remote Feature in the command status the same way as in the complete events. Fixes: 0fe29fd1cd77 ("Bluetooth: Read LE remote features during connection establishment") Fixes: a106e50be74b ("Bluetooth: HCI: Add support for LL Extended Feature Set") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Kevin Dewald Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index c055d16cfb8e..cad6ed5d8e51 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3015,8 +3015,25 @@ static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status) hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); - if (conn && conn->state == BT_CONFIG) + if (conn && conn->state == BT_CONFIG) { + /* If the local controller supports peripheral-initiated + * features exchange, but the remote controller does not, + * then the controller may already return the error code + * 0x1a for unsupported remote feature in the command + * status. + * + * Handle it as hci_le_remote_feat_complete_evt() does and + * allow the connection to transition into connected state. + */ + if (!conn->out && + status == HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE && + (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) { + conn->state = BT_CONNECTED; + status = 0x00; + } + hci_connect_cfm(conn, status); + } hci_dev_unlock(hdev); } @@ -4113,8 +4130,17 @@ static void hci_cs_le_read_all_remote_features(struct hci_dev *hdev, u8 status) hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); - if (conn && conn->state == BT_CONFIG) + if (conn && conn->state == BT_CONFIG) { + /* See hci_cs_le_read_remote_features() */ + if (!conn->out && + status == HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE && + (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) { + conn->state = BT_CONNECTED; + status = 0x00; + } + hci_connect_cfm(conn, status); + } hci_dev_unlock(hdev); } From c1398cf11b31a94c27ed810ba69515e0df5ce379 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 13 Oct 2026 11:36:33 -0400 Subject: [PATCH 1747/2126] Bluetooth: L2CAP: Reject mode changes on connected channels A peer can send a configuration response with an RFC option for another mode to a connected channel, for example to switch it from Streaming to ERTM mode. l2cap_parse_conf_rsp() then changes chan->mode, but l2cap_ertm_init() is not called again, so the ERTM sequence lists are never allocated. The next out-of-sequence I-frame makes l2cap_seq_list_clear() write through the NULL srej_list.list. Refuse the channel when a response tries to change the mode of a connected channel. Fixes: f2fcfcd67025 ("Bluetooth: Add configuration support for ERTM and Streaming mode") Cc: stable@vger.kernel.org Closes: https://sashiko.dev/#/patchset/20261007144717.3832330-1-oss%40fourdim.xyz Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 49a998804908..c730da87734b 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -3876,7 +3876,11 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, } } - if (chan->mode == L2CAP_MODE_BASIC && chan->mode != rfc.mode) + /* A connected channel cannot change its mode, as the new mode would + * not be initialized. + */ + if (chan->mode != rfc.mode && + (chan->mode == L2CAP_MODE_BASIC || chan->state == BT_CONNECTED)) return -ECONNREFUSED; chan->mode = rfc.mode; From 6320736af7dcb90da6ee9fd651ecc11c564d45b7 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 13 Oct 2026 11:36:34 -0400 Subject: [PATCH 1748/2126] Bluetooth: L2CAP: Reject signalling responses in invalid states A peer can send configuration messages while an incoming channel is in BT_CONNECT2, before the security or deferred accept gate has completed. A configuration response can then promote the channel to BT_CONNECTED. Configuration responses can also act on channels that are closing, and a late connection response can move a disconnecting channel back to BT_CONFIG. Accept connection responses only while waiting in BT_CONNECT. Answer configuration requests in BT_CONNECT2, but defer our own request until BT_CONFIG so configuration cannot complete before the gate. Ignore configuration responses outside BT_CONFIG and BT_CONNECTED, and only complete configuration in BT_CONFIG. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index c730da87734b..eb55c16760a7 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4442,6 +4442,10 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, lockdep_assert_held(&chan->conn->lock); + /* Ignore a late response after the channel has left BT_CONNECT. */ + if (chan->state != BT_CONNECT) + goto done; + switch (result) { case L2CAP_CR_SUCCESS: if (__l2cap_get_chan_by_dcid(conn, dcid)) { @@ -4471,6 +4475,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, break; } +done: l2cap_chan_unlock(chan); l2cap_chan_put(chan); @@ -4608,7 +4613,13 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, goto unlock; } - if (!test_and_set_bit(CONF_REQ_SENT, &chan->conf_state)) { + /* A channel in BT_CONNECT2 has not passed security or userspace + * accept yet. Answer the peer's request, but hold our own until + * the channel reaches BT_CONFIG: the CONNECT2 -> CONFIG sites send + * it. Connected channels may also need to reconfigure. + */ + if ((chan->state == BT_CONFIG || chan->state == BT_CONNECTED) && + !test_and_set_bit(CONF_REQ_SENT, &chan->conf_state)) { u8 buf[64]; l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ, l2cap_build_conf_req(chan, buf, sizeof(buf)), buf); @@ -4661,6 +4672,10 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, lockdep_assert_held(&chan->conn->lock); + /* Connected channels may also receive reconfiguration responses. */ + if (chan->state != BT_CONFIG && chan->state != BT_CONNECTED) + goto done; + switch (result) { case L2CAP_CONF_SUCCESS: l2cap_conf_rfc_get(chan, rsp->data, len); @@ -4728,6 +4743,9 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, if (test_bit(CONF_OUTPUT_DONE, &chan->conf_state)) { set_default_fcs(chan); + if (chan->state != BT_CONFIG) + goto done; + if (chan->mode == L2CAP_MODE_ERTM || chan->mode == L2CAP_MODE_STREAMING) err = l2cap_ertm_init(chan); From c5ebb0245fe927cf5fa33510a9cb2799c4a2dd01 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 13 Oct 2026 11:36:35 -0400 Subject: [PATCH 1749/2126] Bluetooth: L2CAP: Reject invalid TxWindow in configuration requests A peer can send an ERTM RFC option with a TxWindow of zero, which is out of spec. It is stored in remote_tx_win unchanged and later passed to l2cap_seq_list_init(), where roundup_pow_of_two(0) is undefined. On some architectures this results in a ZERO_SIZE_PTR list and a remote kernel oops. A TxWindow above 63 is out of spec as well. With 6-bit sequence numbers we would then send more unacknowledged frames than the sequence space can tell apart. Reply with L2CAP_CONF_UNACCEPT and propose the default TxWindow instead of accepting the value, so remote_tx_win always stays within 1 to 63. Keep the parameters of an earlier request then, and do not treat the request as done because an earlier one was. Also refuse a zero size in l2cap_seq_list_init(), so any other path that reaches it with a zero TxWindow fails the channel instead of the kernel. Fixes: f2fcfcd67025 ("Bluetooth: Add configuration support for ERTM and Streaming mode") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index eb55c16760a7..7ea13c0fad44 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -321,6 +321,10 @@ static int l2cap_seq_list_init(struct l2cap_seq_list *seq_list, u16 size) { size_t alloc_size, i; + /* roundup_pow_of_two(0) is undefined */ + if (!size) + return -EINVAL; + /* Allocated size is a power of 2 to map sequence numbers * (which may be up to 14 bits) in to a smaller array that is * sized for the negotiated ERTM transmit windows. @@ -3723,18 +3727,33 @@ done: break; case L2CAP_MODE_ERTM: - if (!test_bit(CONF_EWS_RECV, &chan->conf_state)) - chan->remote_tx_win = rfc.txwin_size; - else - rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; - - chan->remote_max_tx = rfc.max_transmit; - size = min_t(u16, le16_to_cpu(rfc.max_pdu_size), chan->conn->mtu - L2CAP_EXT_HDR_SIZE - L2CAP_SDULEN_SIZE - L2CAP_FCS_SIZE); rfc.max_pdu_size = cpu_to_le16(size); - chan->remote_mps = size; + + /* The TxWindow must be within 1 to 63, otherwise + * propose the default one and keep the parameters of + * an earlier request. This overrides a PENDING result + * from the EFS check above, so the request is no + * longer pending, nor done if an earlier one was. + */ + if (!rfc.txwin_size || + rfc.txwin_size > L2CAP_DEFAULT_TX_WINDOW) { + result = L2CAP_CONF_UNACCEPT; + clear_bit(CONF_LOC_CONF_PEND, &chan->conf_state); + clear_bit(CONF_OUTPUT_DONE, &chan->conf_state); + rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; + remote_efs = 0; + } else { + if (!test_bit(CONF_EWS_RECV, &chan->conf_state)) + chan->remote_tx_win = rfc.txwin_size; + else + rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; + + chan->remote_max_tx = rfc.max_transmit; + chan->remote_mps = size; + } __l2cap_set_ertm_timeouts(chan, &rfc); From 226fa3b676cbf2236f803bccd347462433ffc2c8 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 13 Oct 2026 11:36:36 -0400 Subject: [PATCH 1750/2126] Bluetooth: L2CAP: Use default TxWindow for zero socket option L2CAP_OPTIONS accepts a txwin_size of zero and stores it in tx_win. The zero is then sent to the peer in our configuration request, and if the channel ends up in ERTM mode it is passed to l2cap_seq_list_init(). Use the default TxWindow instead, as the mode can still be changed to ERTM during configuration. Fixes: 14b5aa71ec50 ("Bluetooth: Add sockopt configuration for txWindow on L2CAP") Cc: stable@vger.kernel.org Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 65097d6ef9d8..c396987c58ec 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -815,6 +815,10 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, break; } + /* A zero TxWindow is invalid, use the default instead */ + if (!opts.txwin_size) + opts.txwin_size = L2CAP_DEFAULT_TX_WINDOW; + if (!l2cap_valid_mtu(chan, opts.imtu)) { err = -EINVAL; break; From a518b9a9ef6ee3b18ecdf6ba5360c608aaf969e9 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 13 Oct 2026 11:36:37 -0400 Subject: [PATCH 1751/2126] Bluetooth: L2CAP: Only accept connection responses to outstanding requests An outgoing channel waits in BT_CONNECT until security and the feature mask exchange complete, and only then sends its connection request. A peer can answer it before that with a connection response matching our source CID. The channel then moves to BT_CONFIG, completes configuration and becomes connected before security has completed. If security then fails, l2cap_security_cfm() leaves the connected channel alone, so it stays up on a link that did not reach the required security level. A connection response with a zero source CID is matched by identifier. Another channel can hold the same identifier for a response it still has to send, so the lookup can pick the wrong channel. Only accept a connection response while our request is outstanding, and only look at such channels when matching by identifier. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 7ea13c0fad44..210d1507af7e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -157,6 +157,29 @@ static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn, return NULL; } +/* Our connection request has been sent and is still outstanding */ +static bool l2cap_chan_connect_pending(struct l2cap_chan *chan) +{ + return chan->state == BT_CONNECT && + test_bit(CONF_CONNECT_PEND, &chan->conf_state); +} + +/* Other channels may hold the same ident for a response they still have + * to send, so only look at channels waiting for a connection response. + */ +static struct l2cap_chan *__l2cap_get_connect_chan_by_ident(struct l2cap_conn *conn, + u8 ident) + __must_hold(&conn->lock) +{ + struct l2cap_chan *c; + + list_for_each_entry(c, &conn->chan_l, list) { + if (c->ident == ident && l2cap_chan_connect_pending(c)) + return c; + } + return NULL; +} + static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src, u8 src_type) __must_hold_shared(&chan_list_lock) @@ -4446,7 +4469,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, if (!chan) return -EBADSLT; } else { - chan = __l2cap_get_chan_by_ident(conn, cmd->ident); + chan = __l2cap_get_connect_chan_by_ident(conn, cmd->ident); if (!chan) return -EBADSLT; } @@ -4461,8 +4484,11 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, lockdep_assert_held(&chan->conn->lock); - /* Ignore a late response after the channel has left BT_CONNECT. */ - if (chan->state != BT_CONNECT) + /* Only accept a response to a connection request we sent and that + * is still outstanding. A channel waiting in BT_CONNECT for security + * or the feature mask has not sent one yet. + */ + if (!l2cap_chan_connect_pending(chan)) goto done; switch (result) { From 76a75454516831534f740bccf7b18f98753c67e2 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 13 Oct 2026 11:36:38 -0400 Subject: [PATCH 1752/2126] Bluetooth: L2CAP: Remove dead configuration state code CONF_EWS_RECV has not been set since commit e7b02296fb40 ("Bluetooth: Remove BT_HS"), which made configuration requests with an EWS option be refused. Remove the flag and the branch in l2cap_parse_conf_req() that tests it. A pending connection response no longer needs to set CONF_CONNECT_PEND, as connection responses are only accepted while it is already set. No functional change. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 1 - net/bluetooth/l2cap_core.c | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index efb9b7f422d1..54eddcdd341f 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -725,7 +725,6 @@ enum { CONF_CONNECT_PEND, CONF_RECV_NO_FCS, CONF_STATE2_DEVICE, - CONF_EWS_RECV, CONF_LOC_CONF_PEND, CONF_REM_CONF_PEND, CONF_NOT_COMPLETE, diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 210d1507af7e..4dd56e0074fd 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -3769,11 +3769,7 @@ done: rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; remote_efs = 0; } else { - if (!test_bit(CONF_EWS_RECV, &chan->conf_state)) - chan->remote_tx_win = rfc.txwin_size; - else - rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; - + chan->remote_tx_win = rfc.txwin_size; chan->remote_max_tx = rfc.max_transmit; chan->remote_mps = size; } @@ -4512,7 +4508,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, break; case L2CAP_CR_PEND: - set_bit(CONF_CONNECT_PEND, &chan->conf_state); + /* Our request is still outstanding */ break; default: From 5874f8d03268d34189c6c12c56586b64d26a8bcc Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 13 Oct 2026 09:58:32 -0400 Subject: [PATCH 1753/2126] Bluetooth: Fix the LE Read Connection Interval response layout The response to HCI_OP_LE_READ_CONN_INTERVAL carries a Minimum_Supported_Connection_Interval octet between the status and Num_Groups, which was missing from the structure. Without it the minimum interval was read as the number of groups, and every group after it from one octet off. Take the minimum interval used to clamp the default rate parameters from that field rather than the smallest group minimum, as the number of groups can be zero, which left it unset. Fixes: 2f8784cfe8a9 ("Bluetooth: Add support for Shorter Connection Interval (SCI) feature") Assisted-by: OpenCode:claude-opus-5.5 Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 16 ++++------------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 1641d879dbda..9dc714d9145e 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -2527,6 +2527,7 @@ struct hci_le_conn_interval_group { struct hci_rp_le_read_conn_interval { __u8 status; + __u8 min; __u8 num_grps; struct hci_le_conn_interval_group grps[]; } __packed; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index cad6ed5d8e51..1f80f2cf6b2c 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1269,8 +1269,6 @@ static u8 hci_cc_le_read_conn_interval(struct hci_dev *hdev, void *data, struct sk_buff *skb) { struct hci_rp_le_read_conn_interval *rp = data; - u16 min_interval = 0; - int i; bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); @@ -1283,17 +1281,11 @@ static u8 hci_cc_le_read_conn_interval(struct hci_dev *hdev, void *data, return HCI_ERROR_UNSPECIFIED; } - /* Store the smallest minimum supported connection interval reported by - * the controller so the default rate parameters can be clamped to it. + /* Store the minimum supported connection interval so the default rate + * parameters can be clamped to it. It is reported on its own rather + * than derived from the groups, as there may be none. */ - for (i = 0; i < rp->num_grps; i++) { - u16 min = le16_to_cpu(rp->grps[i].min); - - if (!min_interval || min < min_interval) - min_interval = min; - } - - hdev->le_min_rate_interval = min_interval; + hdev->le_min_rate_interval = rp->min; return rp->status; } From 397464709a204da9b8dc3b01d6ea42539d951cd2 Mon Sep 17 00:00:00 2001 From: Kyle Pepper Date: Wed, 14 Oct 2026 05:16:20 +0000 Subject: [PATCH 1754/2126] Bluetooth: hci_sync: scan unfiltered for host-resolved RPAs Restore unfiltered scanning for pending IRK peers when the controller cannot resolve private addresses. Keep accept-list filtering while suspended and when forced by periodic advertising synchronization. Fixes: e209e5ccc5ac ("Bluetooth: MGMT: Mark LL Privacy as stable") Assisted-by: OpenCode:gpt-6.1-sol Signed-off-by: Kyle Pepper Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index efbd2e5387c0..03f706c1f815 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2618,7 +2618,7 @@ static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, */ static int hci_le_add_accept_list_sync(struct hci_dev *hdev, struct conn_params *params, - u8 *num_entries) + u8 *num_entries, bool force_filter) { struct hci_cp_le_add_to_accept_list cp; int err; @@ -2631,6 +2631,11 @@ static int hci_le_add_accept_list_sync(struct hci_dev *hdev, return 0; } + /* Host-resolved peers need unfiltered scanning while awake. */ + if (!force_filter && !hdev->suspended && !ll_privacy_capable(hdev) && + hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) + return -EINVAL; + /* Select filter policy to accept all advertising */ if (*num_entries >= hdev->le_accept_list_size) return -ENOSPC; @@ -2956,7 +2961,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) num_entries = 1; err = hci_le_add_accept_list_sync(hdev, &pa, - &num_entries); + &num_entries, true); goto done; } else { rcu_read_unlock(); @@ -3020,7 +3025,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) for (i = 0; i < n; ++i) { err = hci_le_add_accept_list_sync(hdev, ¶ms[i], - &num_entries); + &num_entries, false); if (err) { kvfree(params); goto done; @@ -3042,7 +3047,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) for (i = 0; i < n; ++i) { err = hci_le_add_accept_list_sync(hdev, ¶ms[i], - &num_entries); + &num_entries, false); if (err) { kvfree(params); goto done; From fbd3a301b1378423a5cfc23a42e3c0b04e26192c Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Wed, 7 Oct 2026 20:29:22 +0200 Subject: [PATCH 1755/2126] net: selftests: use skb_share_check() in the loopback receive hook The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_unshare() does not unshare it, so skb_linearize() on a non-linear frame hits BUG_ON(skb_shared()). Use skb_share_check() instead. Fixes: 3e1e58d64c3d ("net: add generic selftest support") Signed-off-by: Nicolai Buchwitz Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261007-nb-net-selftest-shared-net-v1-1-458369bfa1ba@tipi-net.de Signed-off-by: Jakub Kicinski --- net/core/selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/selftests.c b/net/core/selftests.c index 36b949ae520b..80029a67b2d2 100644 --- a/net/core/selftests.c +++ b/net/core/selftests.c @@ -170,7 +170,7 @@ static int net_test_loopback_validate(struct sk_buff *skb, struct tcphdr *thdr; struct iphdr *ihdr; - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_share_check(skb, GFP_ATOMIC); if (!skb) goto out; From a7a89019bac0e8810bde7f1419f4adf9adc23d41 Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Wed, 7 Oct 2026 20:29:23 +0200 Subject: [PATCH 1756/2126] net: stmmac: selftests: use skb_share_check() in the loopback receive hook The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_unshare() does not unshare it, so skb_linearize() on a non-linear frame hits BUG_ON(skb_shared()). Use skb_share_check() instead. Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support") Signed-off-by: Nicolai Buchwitz Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261007-nb-net-selftest-shared-net-v1-2-458369bfa1ba@tipi-net.de Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 38cc8fbf2d65..dbe8339947be 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -244,7 +244,7 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb, struct tcphdr *thdr; struct iphdr *ihdr; - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_share_check(skb, GFP_ATOMIC); if (!skb) goto out; From 16fb7aa6955a0af9f67ca42a61d9be58dfc9382a Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Wed, 7 Oct 2026 20:29:24 +0200 Subject: [PATCH 1757/2126] net/mlx5e: use skb_share_check() in the loopback selftest hook The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_linearize() on a non-linear frame then hits BUG_ON(skb_shared()). Call skb_share_check() before linearizing the skb. Fixes: 95b9606b15bb ("net/mlx5: Extend Ethtool loopback selftest to support non-linear SKB") Signed-off-by: Nicolai Buchwitz Reviewed-by: Simon Horman Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261007-nb-net-selftest-shared-net-v1-3-458369bfa1ba@tipi-net.de Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c index 1dcdb86690bb..8eb9a9469549 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c @@ -166,6 +166,10 @@ mlx5e_test_loopback_validate(struct sk_buff *skb, struct udphdr *udph; struct iphdr *iph; + skb = skb_share_check(skb, GFP_ATOMIC); + if (!skb) + goto out; + if (skb_linearize(skb)) goto out; From 0c20cb4cfb40cf270d6c4c2c2ff5e5d72322644a Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Wed, 7 Oct 2026 06:46:20 +0300 Subject: [PATCH 1758/2126] net: axienet: free outstanding TX buffers in axienet_dma_bd_release() axienet_dma_bd_release() walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring with dma_free_coherent() alone. Any descriptor that axienet_free_tx_chain() had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost. axienet_stop() disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up to lp->tx_bd_num skbs and mappings each time. axienet_dma_err_handler() already walks the TX ring this way before it restarts the DMA engine: it unmaps every descriptor whose cntrl is still set - axienet_free_tx_chain() clears it on reclaim - frees any skb still attached, and clears the descriptor. Move that loop into a helper, axienet_free_tx_bufs(), and call it from axienet_dma_bd_release() too. This relies on axienet_stop() having stopped the DMA engine first, as the RX walk in the same function already does. The helper frees the skbs with dev_kfree_skb_any(), as drops: in the error handler, which runs from a workqueue, that frees them directly rather than deferring them to softirq as dev_kfree_skb_irq() did. The walk must not run on a ring that is not there. axienet_open() does not check the result of the reset that runs axienet_dma_bd_init(), so when that reset fails tx_bd_v is either still NULL or, after an earlier close, points at the ring that close freed. Clear tx_bd_v and rx_bd_v once their rings are freed, and skip the walk when tx_bd_v is NULL. That also ends the second dma_free_coherent() of a stale ring which the same path already did. On the axienet_dma_bd_init() error path the TX ring has just been allocated zeroed, so the walk does nothing. This was reported by the Sashiko AI review bot. Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and neither the failed-reset paths nor axienet_dma_err_handler() were exercised. Fixes: 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver") Reviewed-by: Joe Damato Assisted-by: LLM sparse Signed-off-by: Sagi Maimon Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261007034620.1360542-1-maimon.sagi@gmail.com Signed-off-by: Paolo Abeni --- .../net/ethernet/xilinx/xilinx_axienet_main.c | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 16f1c337cc0e..919e644d9158 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -175,6 +175,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, return ret; } +/** + * axienet_free_tx_bufs - Release the buffers still held by the TX ring + * @lp: Pointer to the axienet_local structure + * + * Unmap every descriptor whose mapping is still live, free any skb still + * attached, and clear the descriptor for reuse. axienet_free_tx_chain() + * clears cntrl when it reclaims a descriptor, so a non-zero value means + * the mapping is live. The DMA engine must be stopped. + */ +static void axienet_free_tx_bufs(struct axienet_local *lp) +{ + struct axidma_bd *cur_p; + u32 i; + + for (i = 0; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i]; + if (cur_p->cntrl) { + dma_addr_t addr = desc_get_phys_addr(lp, cur_p); + + dma_unmap_single(lp->dev, addr, + (cur_p->cntrl & + XAXIDMA_BD_CTRL_LENGTH_MASK), + DMA_TO_DEVICE); + } + /* not reclaimed by axienet_free_tx_chain(), so a drop */ + if (cur_p->skb) + dev_kfree_skb_any(cur_p->skb); + cur_p->phys = 0; + cur_p->phys_msb = 0; + cur_p->cntrl = 0; + cur_p->status = 0; + cur_p->app0 = 0; + cur_p->app1 = 0; + cur_p->app2 = 0; + cur_p->app3 = 0; + cur_p->app4 = 0; + cur_p->skb = NULL; + } +} + /** * axienet_dma_bd_release - Release buffer descriptor rings * @ndev: Pointer to the net_device structure @@ -188,11 +228,18 @@ static void axienet_dma_bd_release(struct net_device *ndev) int i; struct axienet_local *lp = netdev_priv(ndev); - /* If we end up here, tx_bd_v must have been DMA allocated. */ + /* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as + * allocating it, and is cleared below once the ring is freed; + * dma_free_coherent() accepts NULL. + */ + if (lp->tx_bd_v) + axienet_free_tx_bufs(lp); + dma_free_coherent(lp->dev, sizeof(*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v = NULL; if (!lp->rx_bd_v) return; @@ -223,6 +270,7 @@ static void axienet_dma_bd_release(struct net_device *ndev) sizeof(*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v = NULL; } static u64 axienet_dma_rate(struct axienet_local *lp) @@ -2756,29 +2804,7 @@ static void axienet_dma_err_handler(struct work_struct *work) axienet_dma_stop(lp); netdev_reset_queue(ndev); - for (i = 0; i < lp->tx_bd_num; i++) { - cur_p = &lp->tx_bd_v[i]; - if (cur_p->cntrl) { - dma_addr_t addr = desc_get_phys_addr(lp, cur_p); - - dma_unmap_single(lp->dev, addr, - (cur_p->cntrl & - XAXIDMA_BD_CTRL_LENGTH_MASK), - DMA_TO_DEVICE); - } - if (cur_p->skb) - dev_kfree_skb_irq(cur_p->skb); - cur_p->phys = 0; - cur_p->phys_msb = 0; - cur_p->cntrl = 0; - cur_p->status = 0; - cur_p->app0 = 0; - cur_p->app1 = 0; - cur_p->app2 = 0; - cur_p->app3 = 0; - cur_p->app4 = 0; - cur_p->skb = NULL; - } + axienet_free_tx_bufs(lp); for (i = 0; i < lp->rx_bd_num; i++) { cur_p = &lp->rx_bd_v[i]; From 1b1c0e87cfe78d731bbab99c9c018655980b6790 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Fri, 9 Oct 2026 12:04:11 +0800 Subject: [PATCH 1759/2126] veth: clear rx queue hint in veth_xmit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With more tx queues on one end of a veth pair than rx queues on the other, and RPS or generic XDP enabled on the receiving end, we get: veth1 received packet on queue 2, but number of RX queues is 2 WARNING: net/core/dev.c:5212 at get_rps_cpu+0x560/0x1360 Call Trace: netif_rx_internal+0x1af/0x4c0 __netif_rx+0x99/0x350 veth_xmit+0x713/0xca0 dev_hard_start_xmit+0x166/0x5f0 __dev_queue_xmit+0x1797/0x42d0 ip_finish_output2+0xa34/0x1f40 __ip_finish_output+0x510/0x7e0 ip_finish_output+0x2f/0x320 ip_output+0x17a/0x3f0 ip_send_skb+0x1bc/0x220 ...... Easy to hit with "ethtool -L veth0 tx 4", "ethtool -L veth1 rx 2", rps_cpus set on veth1 and a few flows sent over the pair [1]. veth_xmit() uses skb->queue_mapping to pick the peer rq, but never clears it before veth_forward_skb(), so the rx side still sees the tx queue index. Everything on the rx side that goes through skb_get_rx_queue(), like get_rps_cpu() and netif_get_rxqueue() for generic XDP, takes it as a recorded rx queue and warns once it is out of range. Clear it before handing the skb to the peer: - It is the tx queue index of this device, it says nothing about the rx queue of the peer. - The two sides don't even agree on the encoding. The tx side stores the index as is, the rx side stores index + 1 so that 0 can mean "not recorded". So tx queue k is read back as rx queue k - 1, and tx queue 0 as "not recorded". - Commit 710ad98c363a ("veth: Do not record rx queue hint in veth_xmit") already decided that veth should not pass any queue hint to the peer. There is no tx->rx queue mapping to preserve, so nothing is lost by clearing it. On NETDEV_TX_BUSY the skb goes back to the qdisc, which looks up the txq from skb->queue_mapping to decide when to retry, so restore it there, next to the existing __skb_push(). [1]: https://lore.kernel.org/netdev/156834bb-8e40-496e-9443-9d515fa18eab@linux.dev/ Fixes: 76ff5cc91935 ("rtnl: allow to specify number of rx and tx queues on device creation") Signed-off-by: Jiayuan Chen Reviewed-by: Björn Töpel Reviewed-by: Toshiaki Makita Reviewed-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261009040412.14571-1-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni --- drivers/net/veth.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 643b97dc5245..38f263d4f06b 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -377,6 +377,9 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) skb_tx_timestamp(skb); + /* tx queue index of this device, meaningless as rx queue of the peer */ + skb_set_queue_mapping(skb, 0); + ret = veth_forward_skb(rcv, skb, rq, use_napi); switch (ret) { case NET_RX_SUCCESS: /* same as NETDEV_TX_OK */ @@ -397,6 +400,8 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) } /* Restore Eth hdr pulled by dev_forward_skb/eth_type_trans */ __skb_push(skb, ETH_HLEN); + /* qdisc requeues the skb on the txq it points to */ + skb_set_queue_mapping(skb, rxq); netif_tx_stop_queue(txq); /* Makes sure NAPI peer consumer runs. Consumer is responsible * for starting txq again, until then ndo_start_xmit (this From 870143cfdac1cad166d1dc03fbef915fac0c229a Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:53 +0100 Subject: [PATCH 1760/2126] rxrpc: Revert "rxrpc: rxperf: Fix missing decoding of terminal magic cookie" Revert commit c34d999ca3145d9fe858258cc3342ec493f47d2e: The rxperf RPCs seem to have a magic cookie at the end of the request that was failing to be taken account of by the unmarshalling of the request. Fix the rxperf code to expect this. Actually, this isn't true; it's just that other Rx implementations ignore the extra data in the request and so my test programs are sending too much data without noticeable consequence. Fixes: c34d999ca314 ("rxrpc: rxperf: Fix missing decoding of terminal magic cookie") Signed-off-by: David Howells cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org Link: https://patch.msgid.link/20261006133011.531806-2-dhowells@redhat.com Signed-off-by: Paolo Abeni --- net/rxrpc/rxperf.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c index b8df6d22314d..f1f41151589c 100644 --- a/net/rxrpc/rxperf.c +++ b/net/rxrpc/rxperf.c @@ -483,18 +483,6 @@ static int rxperf_deliver_request(struct rxperf_call *call) call->unmarshal++; fallthrough; case 2: - ret = rxperf_extract_data(call, true); - if (ret < 0) - return ret; - - /* Deal with the terminal magic cookie. */ - call->iov_len = 4; - call->kvec[0].iov_len = call->iov_len; - call->kvec[0].iov_base = call->tmp; - iov_iter_kvec(&call->iter, READ, call->kvec, 1, call->iov_len); - call->unmarshal++; - fallthrough; - case 3: ret = rxperf_extract_data(call, false); if (ret < 0) return ret; From a7c8c3ab072375fc667ee294b58bcb9071d6e3ca Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:54 +0100 Subject: [PATCH 1761/2126] rxrpc: Fix rxperf test rxgk key kvno to be 0 Fix the test rxgk keys in the rxperf test server to have kvno 0 to match other implementations. Fixes: aa2199088a39 ("rxrpc: rxperf: Add test RxGK server keys") Signed-off-by: David Howells cc: Marc Dionne cc: Jeffrey Altman cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org Link: https://patch.msgid.link/20261006133011.531806-3-dhowells@redhat.com Signed-off-by: Paolo Abeni --- net/rxrpc/rxperf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c index f1f41151589c..26f97e1dd388 100644 --- a/net/rxrpc/rxperf.c +++ b/net/rxrpc/rxperf.c @@ -586,7 +586,7 @@ static int rxperf_add_yfs_rxgk_key(struct key *keyring, u32 enctype) for (int i = 0; i < krb5->key_len; i++) key[i] = i; - sprintf(name, "%u:6:1:%u", RX_PERF_SERVICE, enctype); + sprintf(name, "%u:6:0:%u", RX_PERF_SERVICE, enctype); kref = key_create_or_update(make_key_ref(keyring, true), "rxrpc_s", name, From 7801c42c3bb737cfb06194a383873fcad8daacf5 Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:55 +0100 Subject: [PATCH 1762/2126] rxrpc: Fix update of call->tx_pending without holding lock Currently, rxrpc_send_data() updates call->tx_pending just before it returns - but it won't be holding the call->user_mutex when it does this if a wait was interrupted by a signal. This would allow a parallel sendmsg() to race. Further, both the callers of rxrpc_send_data() call it with the lock held, and then it returns an indication through the parameter list to say whether it has dropped the lock or not - after which the callers both just drop the lock if it's still held. Fix this by: (1) Moving the release of call->user_mutex down into rxrpc_send_data() and get rid of the indicator parameter. This makes it easier to see where the lock is held. (2) After waiting, if the attempt to reacquire the mutex is interrupted, just return directly there rather than going to out_unlock (3) Restricting the txb variable to inside the buffering loop and leaving ->tx_pending set until we've queued the buffer. Note that there's a slight change in behaviour in that wait_for_space failure now doesn't check for completion because it doesn't hold the call user_mutex. The caller, however, should re-issue the send and pick up any error at a second attempt. Fixes: b0f571ecd794 ("rxrpc: Fix locking in rxrpc's sendmsg") Closes: https://sashiko.dev/#/patchset/20260702144919.172295-1-dhowells%40redhat.com Signed-off-by: David Howells cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261006133011.531806-4-dhowells@redhat.com Signed-off-by: Paolo Abeni --- net/rxrpc/sendmsg.c | 63 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c index ed2c9a51005a..fb8d48418882 100644 --- a/net/rxrpc/sendmsg.c +++ b/net/rxrpc/sendmsg.c @@ -320,10 +320,9 @@ static int rxrpc_alloc_txqueue(struct sock *sk, struct rxrpc_call *call) static int rxrpc_send_data(struct rxrpc_sock *rx, struct rxrpc_call *call, struct msghdr *msg, size_t len, - rxrpc_notify_end_tx_t notify_end_tx, - bool *_dropped_lock) + rxrpc_notify_end_tx_t notify_end_tx) + __releases(&call->user_mutex) { - struct rxrpc_txbuf *txb; struct sock *sk = &rx->sk; enum rxrpc_call_state state; long timeo; @@ -334,30 +333,26 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_late_send, call->cid, call->call_id, call->rx_consumed, 0, -EPROTO); - return -EPROTO; + ret = -EPROTO; + goto out_unlock; } timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); ret = rxrpc_wait_to_be_connected(call, &timeo); if (ret < 0) - return ret; + goto out_unlock; if (call->conn->state == RXRPC_CONN_CLIENT_UNSECURED) { ret = rxrpc_init_client_conn_security(call->conn); if (ret < 0) - return ret; + goto out_unlock; } /* this should be in poll */ sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); reload: - txb = call->tx_pending; - call->tx_pending = NULL; - if (txb) - rxrpc_see_txbuf(txb, rxrpc_txbuf_see_send_more); - ret = -EPIPE; if (sk->sk_shutdown & SEND_SHUTDOWN) goto maybe_error; @@ -386,6 +381,8 @@ reload: } do { + struct rxrpc_txbuf *txb = call->tx_pending; + if (!txb) { size_t remain; @@ -411,6 +408,9 @@ reload: ret = -ENOMEM; goto maybe_error; } + call->tx_pending = txb; + } else { + rxrpc_see_txbuf(txb, rxrpc_txbuf_see_send_more); } _debug("append"); @@ -445,9 +445,9 @@ reload: ret = call->security->secure_packet(call, txb); if (ret < 0) - goto out; + goto out_unlock; rxrpc_queue_packet(rx, call, txb, notify_end_tx); - txb = NULL; + call->tx_pending = NULL; } } while (msg_data_left(msg) > 0); @@ -456,45 +456,46 @@ success: if (rxrpc_call_is_complete(call) && call->error < 0) ret = call->error; -out: - call->tx_pending = txb; +out_unlock: + mutex_unlock(&call->user_mutex); _leave(" = %d", ret); return ret; call_terminated: - rxrpc_put_txbuf(txb, rxrpc_txbuf_put_send_aborted); - _leave(" = %d", call->error); - return call->error; + ret = call->error; + goto out_unlock; maybe_error: if (copied) goto success; - goto out; + goto out_unlock; efault: ret = -EFAULT; - goto out; + goto out_unlock; wait_for_space: ret = -EAGAIN; if (msg->msg_flags & MSG_DONTWAIT) goto maybe_error; mutex_unlock(&call->user_mutex); - *_dropped_lock = true; + ret = rxrpc_wait_for_tx_window(rx, call, &timeo, msg->msg_flags & MSG_WAITALL); if (ret < 0) - goto maybe_error; + goto out_nolock; if (call->interruptibility == RXRPC_INTERRUPTIBLE) { if (mutex_lock_interruptible(&call->user_mutex) < 0) { ret = sock_intr_errno(timeo); - goto maybe_error; + goto out_nolock; } } else { mutex_lock(&call->user_mutex); } - *_dropped_lock = false; goto reload; +out_nolock: + _leave(" = %d [intr]", ret); + return copied ?: ret; } /* @@ -660,7 +661,6 @@ rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) { struct rxrpc_call *call; - bool dropped_lock = false; int ret; struct rxrpc_send_params p = { @@ -769,16 +769,15 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) ret = 0; break; case RXRPC_CMD_SEND_DATA: - ret = rxrpc_send_data(rx, call, msg, len, NULL, &dropped_lock); - break; + ret = rxrpc_send_data(rx, call, msg, len, NULL); + goto error_put; default: ret = -EINVAL; break; } out_put_unlock: - if (!dropped_lock) - mutex_unlock(&call->user_mutex); + mutex_unlock(&call->user_mutex); error_put: rxrpc_put_call(call, rxrpc_call_put_sendmsg); _leave(" = %d", ret); @@ -808,7 +807,6 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, struct msghdr *msg, size_t len, rxrpc_notify_end_tx_t notify_end_tx) { - bool dropped_lock = false; int ret; _enter("{%d},", call->debug_id); @@ -819,12 +817,9 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, mutex_lock(&call->user_mutex); ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len, - notify_end_tx, &dropped_lock); + notify_end_tx); if (ret == -ESHUTDOWN) ret = call->error; - - if (!dropped_lock) - mutex_unlock(&call->user_mutex); _leave(" = %d", ret); return ret; } From af208f36ae22440cf6011a43cb3064fd525d85b4 Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:56 +0100 Subject: [PATCH 1763/2126] rxrpc: Fix lack of short-send handling in rxrpc_kernel_send_data() Fix rxrpc_kernel_send_data() to loop around if it detects a short send. David Laight suggested doing it here rather than wrapping all the calls in loops. Further, remove the len argument and use the iterator count instead and return 0 on success, not the amount copied. Note this is also a prerequisite for changing the way rxrpc_send_data() works to return a short send rather than an error if some data was buffered. Fixes: 651350d10f93 ("[AF_RXRPC]: Add an interface to the AF_RXRPC module for the AFS filesystem to use") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824091645.415423-1-dhowells%40redhat.com Suggested-by: David Laight Signed-off-by: David Howells cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261006133011.531806-5-dhowells@redhat.com Signed-off-by: Paolo Abeni --- Documentation/networking/rxrpc.rst | 8 +++++--- fs/afs/rxrpc.c | 32 ++++++++++++------------------ include/net/af_rxrpc.h | 5 ++--- net/rxrpc/rxperf.c | 25 ++++++++++------------- net/rxrpc/sendmsg.c | 27 +++++++++++++++++-------- 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/Documentation/networking/rxrpc.rst b/Documentation/networking/rxrpc.rst index 8926dab8e2e6..9239f7bd8885 100644 --- a/Documentation/networking/rxrpc.rst +++ b/Documentation/networking/rxrpc.rst @@ -870,7 +870,6 @@ The kernel interface functions are as follows: int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, struct msghdr *msg, - size_t len, rxrpc_notify_end_tx_t notify_end_rx); This is used to supply either the request part of a client call or the @@ -879,14 +878,17 @@ The kernel interface functions are as follows: exclusively to in-kernel virtual addresses. msg.msg_flags may be given MSG_MORE if there will be subsequent data sends for this call. - The msg must not specify a destination address, control data or any flags - other than MSG_MORE. len is the total amount of data to transmit. + msg must not specify a destination address, control data or any flags + other than MSG_MORE or MSG_WAITALL. notify_end_rx can be NULL or it can be used to specify a function to be called when the call changes state to end the Tx phase. This function is called with a spinlock held to prevent the last DATA packet from being transmitted until the function returns. + It returns 0 if all the provided data has been buffered and a negative + error code on failure. + (#) Receive data from a call:: int rxrpc_kernel_recv_data(struct socket *sock, diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index d82916657a3d..bcb8bb15d471 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -412,8 +412,7 @@ void afs_make_call(struct afs_call *call, gfp_t gfp) msg.msg_controllen = 0; msg.msg_flags = MSG_WAITALL | (call->write_iter ? MSG_MORE : 0); - ret = rxrpc_kernel_send_data(call->net->socket, rxcall, - &msg, call->request_size, + ret = rxrpc_kernel_send_data(call->net->socket, rxcall, &msg, afs_notify_end_request_tx); if (ret < 0) goto error_do_abort; @@ -425,7 +424,6 @@ void afs_make_call(struct afs_call *call, gfp_t gfp) ret = rxrpc_kernel_send_data(call->net->socket, call->rxcall, &msg, - iov_iter_count(&msg.msg_iter), afs_notify_end_request_tx); *call->write_iter = msg.msg_iter; @@ -871,7 +869,7 @@ void afs_send_empty_reply(struct afs_call *call) msg.msg_controllen = 0; msg.msg_flags = 0; - switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0, + switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, afs_notify_end_reply_tx)) { case 0: _leave(" [replied]"); @@ -897,7 +895,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) struct afs_net *net = call->net; struct msghdr msg; struct kvec iov[1]; - int n; + int ret; _enter(""); @@ -912,21 +910,17 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) msg.msg_controllen = 0; msg.msg_flags = 0; - n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len, - afs_notify_end_reply_tx); - if (n >= 0) { - /* Success */ - _leave(" [replied]"); - return; + ret = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, + afs_notify_end_reply_tx); + if (ret < 0) { + if (ret == -ENOMEM) { + _debug("oom"); + rxrpc_kernel_abort_call(net->socket, call->rxcall, + RXGEN_SS_MARSHAL, -ENOMEM, + afs_abort_oom); + } + _leave(" [error]"); } - - if (n == -ENOMEM) { - _debug("oom"); - rxrpc_kernel_abort_call(net->socket, call->rxcall, - RXGEN_SS_MARSHAL, -ENOMEM, - afs_abort_oom); - } - _leave(" [error]"); } /* diff --git a/include/net/af_rxrpc.h b/include/net/af_rxrpc.h index 0fb4c41c9bbf..f3980348ed34 100644 --- a/include/net/af_rxrpc.h +++ b/include/net/af_rxrpc.h @@ -64,9 +64,8 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, bool upgrade, enum rxrpc_interruptibility interruptibility, unsigned int debug_id); -int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *, - struct msghdr *, size_t, - rxrpc_notify_end_tx_t); +int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, + struct msghdr *msg, rxrpc_notify_end_tx_t notify_end_tx); int rxrpc_kernel_recv_data(struct socket *, struct rxrpc_call *, struct iov_iter *, size_t *, bool, u32 *, u16 *); bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *, diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c index 26f97e1dd388..981c0596c774 100644 --- a/net/rxrpc/rxperf.c +++ b/net/rxrpc/rxperf.c @@ -501,8 +501,8 @@ static int rxperf_process_call(struct rxperf_call *call) struct msghdr msg = {}; struct bio_vec bv; struct kvec iov[1]; - ssize_t n; size_t reply_len = call->reply_len, len; + int ret; rxrpc_kernel_set_tx_length(rxperf_socket, call->rxcall, reply_len + sizeof(rxperf_magic_cookie)); @@ -512,13 +512,11 @@ static int rxperf_process_call(struct rxperf_call *call) bvec_set_page(&bv, ZERO_PAGE(0), len, 0); iov_iter_bvec(&msg.msg_iter, WRITE, &bv, 1, len); msg.msg_flags = MSG_MORE; - n = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg, - len, rxperf_notify_end_reply_tx); - if (n < 0) - return n; - if (n == 0) - return -EIO; - reply_len -= n; + ret = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg, + rxperf_notify_end_reply_tx); + if (ret < 0) + return ret; + reply_len -= len; } len = sizeof(rxperf_magic_cookie); @@ -526,16 +524,13 @@ static int rxperf_process_call(struct rxperf_call *call) iov[0].iov_len = len; iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len); msg.msg_flags = 0; - n = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg, len, - rxperf_notify_end_reply_tx); - if (n >= 0) - return 0; /* Success */ - - if (n == -ENOMEM) + ret = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg, + rxperf_notify_end_reply_tx); + if (ret == -ENOMEM) rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, RXGEN_SS_MARSHAL, -ENOMEM, rxperf_abort_oom); - return n; + return ret; } /* diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c index fb8d48418882..393a2dcfda07 100644 --- a/net/rxrpc/sendmsg.c +++ b/net/rxrpc/sendmsg.c @@ -793,7 +793,6 @@ error_release_sock: * @sock: The socket the call is on * @call: The call to send data through * @msg: The data to send - * @len: The amount of data to send * @notify_end_tx: Notification that the last packet is queued. * * Allow a kernel service to send data on a call. The call must be in an state @@ -804,8 +803,7 @@ error_release_sock: * Return: %0 if successful and a negative error code otherwise. */ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, - struct msghdr *msg, size_t len, - rxrpc_notify_end_tx_t notify_end_tx) + struct msghdr *msg, rxrpc_notify_end_tx_t notify_end_tx) { int ret; @@ -814,12 +812,25 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, ASSERTCMP(msg->msg_name, ==, NULL); ASSERTCMP(msg->msg_control, ==, NULL); - mutex_lock(&call->user_mutex); + for (;;) { + mutex_lock(&call->user_mutex); + + ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, + msg_data_left(msg), notify_end_tx); + if (ret == -ESHUTDOWN) + ret = call->error; + if (ret < 0) + break; + if (msg_data_left(msg) == 0) { + ret = 0; + break; + } + if (ret == 0) { + ret = -EIO; + break; + } + } - ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len, - notify_end_tx); - if (ret == -ESHUTDOWN) - ret = call->error; _leave(" = %d", ret); return ret; } From 3e6af08a571fe2943a006acf3e890f36322602bc Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:57 +0100 Subject: [PATCH 1764/2126] afs: Fix afs to abort the rxrpc call on send error Fix afs_send_empty_reply() and afs_send_simple_reply() to always try to abort the rxrpc call rather than just aborting on -ENOMEM and otherwise abandoning it. If the call is already complete due to network failure or a received abort, this will do nothing. Also make afs_make_call() always abort on send error; again, it does nothing if the rxrpc call is already dead. Fixes: 08e0e7c82eea ("[AF_RXRPC]: Make the in-kernel AFS filesystem use AF_RXRPC.") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824091645.415423-1-dhowells%40redhat.com Signed-off-by: David Howells cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261006133011.531806-6-dhowells@redhat.com Signed-off-by: Paolo Abeni --- fs/afs/rxrpc.c | 37 +++++++++++++----------------------- include/trace/events/rxrpc.h | 2 +- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index bcb8bb15d471..64dd32df8a34 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -441,10 +441,8 @@ void afs_make_call(struct afs_call *call, gfp_t gfp) return; error_do_abort: - if (ret != -ECONNABORTED) - rxrpc_kernel_abort_call(call->net->socket, rxcall, - RX_USER_ABORT, ret, - afs_abort_send_data_error); + rxrpc_kernel_abort_call(call->net->socket, rxcall, + RX_USER_ABORT, ret, afs_abort_send_data_error); if (call->async) { afs_see_call(call, afs_call_trace_async_abort); return; @@ -857,6 +855,7 @@ void afs_send_empty_reply(struct afs_call *call) { struct afs_net *net = call->net; struct msghdr msg; + int ret; _enter(""); @@ -869,21 +868,13 @@ void afs_send_empty_reply(struct afs_call *call) msg.msg_controllen = 0; msg.msg_flags = 0; - switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, - afs_notify_end_reply_tx)) { - case 0: - _leave(" [replied]"); - return; - - case -ENOMEM: - _debug("oom"); + ret = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, + afs_notify_end_reply_tx); + if (ret < 0) { rxrpc_kernel_abort_call(net->socket, call->rxcall, - RXGEN_SS_MARSHAL, -ENOMEM, - afs_abort_oom); - fallthrough; - default: - _leave(" [error]"); - return; + RXGEN_SS_MARSHAL, ret, + afs_abort_send_error); + afs_set_call_complete(call, ret, RXGEN_SS_MARSHAL); } } @@ -913,12 +904,10 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) ret = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, afs_notify_end_reply_tx); if (ret < 0) { - if (ret == -ENOMEM) { - _debug("oom"); - rxrpc_kernel_abort_call(net->socket, call->rxcall, - RXGEN_SS_MARSHAL, -ENOMEM, - afs_abort_oom); - } + rxrpc_kernel_abort_call(net->socket, call->rxcall, + RXGEN_SS_MARSHAL, ret, + afs_abort_send_error); + afs_set_call_complete(call, ret, RXGEN_SS_MARSHAL); _leave(" [error]"); } } diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h index 704a10de6670..554dfb777b93 100644 --- a/include/trace/events/rxrpc.h +++ b/include/trace/events/rxrpc.h @@ -20,10 +20,10 @@ /* AFS errors */ \ EM(afs_abort_general_error, "afs-error") \ EM(afs_abort_interrupted, "afs-intr") \ - EM(afs_abort_oom, "afs-oom") \ EM(afs_abort_op_not_supported, "afs-op-notsupp") \ EM(afs_abort_probeuuid_negative, "afs-probeuuid-neg") \ EM(afs_abort_send_data_error, "afs-send-data") \ + EM(afs_abort_send_error, "afs-send-error") \ EM(afs_abort_unmarshal_error, "afs-unmarshal") \ EM(afs_abort_unsupported_sec_class, "afs-unsup-sec-class") \ /* rxperf errors */ \ From 7f15923909866e76608ea6474368570938e783fc Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:58 +0100 Subject: [PATCH 1765/2126] rxrpc: Fix aborting in rxperf test server Fix rxperf_process_call() to always abort if it gets a send error rather than only aborting on ENOMEM. Fixes: 75bfdbf2fca3 ("rxrpc: Implement an in-kernel rxperf server for testing purposes") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824091645.415423-1-dhowells%40redhat.com Signed-off-by: David Howells cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org Link: https://patch.msgid.link/20261006133011.531806-7-dhowells@redhat.com Signed-off-by: Paolo Abeni --- include/trace/events/rxrpc.h | 2 +- net/rxrpc/rxperf.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h index 554dfb777b93..56dc9b614071 100644 --- a/include/trace/events/rxrpc.h +++ b/include/trace/events/rxrpc.h @@ -28,8 +28,8 @@ EM(afs_abort_unsupported_sec_class, "afs-unsup-sec-class") \ /* rxperf errors */ \ EM(rxperf_abort_general_error, "rxperf-error") \ - EM(rxperf_abort_oom, "rxperf-oom") \ EM(rxperf_abort_op_not_supported, "rxperf-op-notsupp") \ + EM(rxperf_abort_send_error, "rxperf-send-error") \ EM(rxperf_abort_unmarshal_error, "rxperf-unmarshal") \ /* RxKAD security errors */ \ EM(rxkad_abort_1_short_check, "rxkad1-short-check") \ diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c index 981c0596c774..823eedc5d16f 100644 --- a/net/rxrpc/rxperf.c +++ b/net/rxrpc/rxperf.c @@ -515,7 +515,7 @@ static int rxperf_process_call(struct rxperf_call *call) ret = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg, rxperf_notify_end_reply_tx); if (ret < 0) - return ret; + goto send_error; reply_len -= len; } @@ -526,10 +526,11 @@ static int rxperf_process_call(struct rxperf_call *call) msg.msg_flags = 0; ret = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg, rxperf_notify_end_reply_tx); - if (ret == -ENOMEM) - rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, - RXGEN_SS_MARSHAL, -ENOMEM, - rxperf_abort_oom); + if (ret == 0) + return 0; +send_error: + rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, RXGEN_SS_MARSHAL, + ret, rxperf_abort_send_error); return ret; } From ef369cacbd524931199078427ae152c63a826189 Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:29:59 +0100 Subject: [PATCH 1766/2126] rxrpc: Fix sendmsg length rxrpc_send_data() is given two data lengths (len and msg->msg_iter.count) and is inconsistent about how it uses them. Fix this by using len in preference to msg->msg_iter.count. Also limit the amount copied to either len or msg->msg_iter.count, whichever is smaller. Note that, currently, all the callers have len and msg->msg_iter.count the same and so the problem won't occur. This is a prerequisite for another patch that fixes the handling of encryption errors. Fixes: 382d7974de31 ("RxRPC: Use iov_iter_count() in rxrpc_send_data() instead of the len argument") Signed-off-by: David Howells cc: Marc Dionne cc: Jeffrey Altman cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org Link: https://patch.msgid.link/20261006133011.531806-8-dhowells@redhat.com Signed-off-by: Paolo Abeni --- net/rxrpc/sendmsg.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c index 393a2dcfda07..312be27ca75b 100644 --- a/net/rxrpc/sendmsg.c +++ b/net/rxrpc/sendmsg.c @@ -374,9 +374,9 @@ reload: ret = -EMSGSIZE; if (call->tx_total_len != -1) { - if (len - copied > call->tx_total_len) + if (len > call->tx_total_len) goto maybe_error; - if (!more && len - copied != call->tx_total_len) + if (!more && len != call->tx_total_len) goto maybe_error; } @@ -402,7 +402,7 @@ reload: * the security header is going to be in the padded * region (enc blocksize), but the trailer is not. */ - remain = more ? INT_MAX : msg_data_left(msg); + remain = more ? INT_MAX : len; txb = call->conn->security->alloc_txbuf(call, remain, sk->sk_allocation); if (!txb) { ret = -ENOMEM; @@ -416,8 +416,8 @@ reload: _debug("append"); /* append next segment of data to the current buffer */ - if (msg_data_left(msg) > 0) { - size_t copy = umin(txb->space, msg_data_left(msg)); + if (len > 0) { + size_t copy = min3(txb->space, len, msg_data_left(msg)); _debug("add %zu", copy); if (!copy_from_iter_full(txb->data + txb->offset, @@ -428,6 +428,7 @@ reload: txb->len += copy; txb->offset += copy; copied += copy; + len -= copy; if (call->tx_total_len != -1) call->tx_total_len -= copy; } @@ -439,8 +440,8 @@ reload: /* add the packet to the send queue if it's now full */ if (!txb->space || - (msg_data_left(msg) == 0 && !more)) { - if (msg_data_left(msg) == 0 && !more) + (len == 0 && !more)) { + if (len == 0 && !more) txb->flags |= RXRPC_LAST_PACKET; ret = call->security->secure_packet(call, txb); @@ -449,7 +450,7 @@ reload: rxrpc_queue_packet(rx, call, txb, notify_end_tx); call->tx_pending = NULL; } - } while (msg_data_left(msg) > 0); + } while (len > 0 && msg_data_left(msg) > 0); success: ret = copied; From 41eb0af096ba8754e584d47e6de42f1e4980ceae Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:30:00 +0100 Subject: [PATCH 1767/2126] rxrpc: Fix double IRQ enablement rxrpc_notify_socket() explicitly disables and then re-enables IRQs, but one of its call chains (rxrpc_input_queue_data() -> rxrpc_end_rx_phase() -> rxrpc_call_completed() -> rxrpc_set_call_completion()) has IRQs disabled around it. Fix this by making rxrpc_notify_socket() use irqsave spinlocks. Fixes: a2ea9a907260 ("rxrpc: Use irq-disabling spinlocks between app and I/O thread") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260812110129.979970-6-dhowells@redhat.com Signed-off-by: David Howells cc: Marc Dionne cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: stable@kernel.org Link: https://patch.msgid.link/20261006133011.531806-9-dhowells@redhat.com Signed-off-by: Paolo Abeni --- net/rxrpc/recvmsg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c index efcba4b2e74f..56fa324d0962 100644 --- a/net/rxrpc/recvmsg.c +++ b/net/rxrpc/recvmsg.c @@ -24,6 +24,7 @@ void rxrpc_notify_socket(struct rxrpc_call *call) { struct rxrpc_sock *rx; struct sock *sk; + unsigned long flags; _enter("%d", call->debug_id); @@ -38,16 +39,16 @@ void rxrpc_notify_socket(struct rxrpc_call *call) sk = &rx->sk; if (rx && sk->sk_state < RXRPC_CLOSE) { if (call->notify_rx) { - spin_lock_irq(&call->notify_lock); + spin_lock_irqsave(&call->notify_lock, flags); call->notify_rx(sk, call, call->user_call_ID); - spin_unlock_irq(&call->notify_lock); + spin_unlock_irqrestore(&call->notify_lock, flags); } else { - spin_lock_irq(&rx->recvmsg_lock); + spin_lock_irqsave(&rx->recvmsg_lock, flags); if (list_empty(&call->recvmsg_link)) { rxrpc_get_call(call, rxrpc_call_get_notify_socket); list_add_tail(&call->recvmsg_link, &rx->recvmsg_q); } - spin_unlock_irq(&rx->recvmsg_lock); + spin_unlock_irqrestore(&rx->recvmsg_lock, flags); if (!sock_flag(sk, SOCK_DEAD)) { _debug("call %ps", sk->sk_data_ready); From 18a71e111c7505e16c2de91480561fc491f41341 Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 6 Oct 2026 14:30:01 +0100 Subject: [PATCH 1768/2126] rxrpc: Fix return in rxrpc_recvmsg_data() for service calls When rxrpc_recvmsg_data() gets called on a service call that has received all of the request, RXRPC_CALL_RECVMSG_READ_ALL has been set, and this causes rxrpc_recvmsg_data() to jump straight out, indicating the end of the call (ie. rxrpc_kernel_recv_data() returns 1) without waiting for the call to be processed or the reply to be transmitted. rxperf_deliver_to_call() also has to be altered to call rxrpc_kernel_recv_data() to collect the final ACK on a service call as does afs_deliver_to_call(). Fixes: d001648ec7cf ("rxrpc: Don't expose skbs to in-kernel users [ver #2]") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914151340.3227501-1-dhowells%40redhat.com Signed-off-by: David Howells cc: Marc Dionne cc: Jeffrey Altman cc: Eric Dumazet cc: "David S. Miller" cc: Jakub Kicinski cc: Paolo Abeni cc: Simon Horman cc: linux-afs@lists.infradead.org cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261006133011.531806-10-dhowells@redhat.com Signed-off-by: Paolo Abeni --- Documentation/networking/rxrpc.rst | 13 +++++++++---- fs/afs/rxrpc.c | 4 ++-- net/rxrpc/recvmsg.c | 13 ++++++++++--- net/rxrpc/rxperf.c | 16 ++++++++++++++-- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Documentation/networking/rxrpc.rst b/Documentation/networking/rxrpc.rst index 9239f7bd8885..eca055a536aa 100644 --- a/Documentation/networking/rxrpc.rst +++ b/Documentation/networking/rxrpc.rst @@ -909,10 +909,15 @@ The kernel interface functions are as follows: want_more should be true if further data will be required after this is satisfied and false if this is the last item of the receive phase. - There are three normal returns: 0 if the buffer was filled and want_more - was true; 1 if the buffer was filled, the last DATA packet has been - emptied and want_more was false; and -EAGAIN if the function needs to be - called again. + For client calls, there are three normal returns: 0 if the buffer was + filled and want_more was true; 1 if the buffer was filled, the last DATA + packet has been emptied and want_more was false; and -EAGAIN if the + function needs to be called again. + + For service calls, there are four normal returns: 0 and -EAGAIN are the + same as for client calls; 2 indicates that the last DATA packet of the + request has been received, want_more was false and the call is still in + progress; and 1 indicates that the call is now successfully complete. If the last DATA packet is processed but the buffer contains less than the amount requested, EBADMSG is returned. If want_more wasn't set, but diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 64dd32df8a34..768b26820dea 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -541,7 +541,7 @@ void afs_deliver_to_call(struct afs_call *call) &call->service_id); trace_afs_receive_data(call, &call->def_iter, false, ret); - if (ret == -EINPROGRESS || ret == -EAGAIN) + if (ret == -EAGAIN || ret == 2) return; if (ret < 0 || ret == 1) { if (ret == 1) @@ -934,7 +934,7 @@ int afs_extract_data(struct afs_call *call, bool want_more) return ret; state = READ_ONCE(call->state); - if (ret == 1) { + if (ret == 1 || ret == 2) { switch (state) { case AFS_CALL_CL_AWAIT_REPLY: afs_set_call_state(call, state, AFS_CALL_CL_PROC_REPLY); diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c index 56fa324d0962..0c960f13b5fc 100644 --- a/net/rxrpc/recvmsg.c +++ b/net/rxrpc/recvmsg.c @@ -638,9 +638,11 @@ wait_error: * Note that we may return %-EAGAIN to drain empty packets at the end * of the data, even if we've already copied over the requested data. * - * Return: %0 if got what was asked for and there's more available, %1 - * if we got what was asked for and we're at the end of the data and - * %-EAGAIN if we need more data. + * Return: %0 if got what was asked for and there's more available, %1 if we + * got what was asked for and we're at the end of the call, %2 if a service + * call received all of the request but is still in progress and %-EAGAIN if we + * need more data. A variety of other errors can be returned if the call + * completed with failure. */ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call, struct iov_iter *iter, size_t *_len, @@ -679,6 +681,11 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call, read_phase_complete: ret = 1; + if (rxrpc_is_service_call(call)) { + if (rxrpc_call_is_complete(call)) + goto call_failed; + ret = 2; + } out: if (_service) *_service = call->dest_srx.srx_service; diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c index 823eedc5d16f..0bc3de061b93 100644 --- a/net/rxrpc/rxperf.c +++ b/net/rxrpc/rxperf.c @@ -293,8 +293,20 @@ static void rxperf_deliver_to_call(struct work_struct *work) state == RXPERF_CALL_SV_AWAIT_ACK ) { if (state == RXPERF_CALL_SV_AWAIT_ACK) { - if (!rxrpc_kernel_check_life(rxperf_socket, call->rxcall)) + size_t len = 0; + iov_iter_kvec(&call->iter, ITER_DEST, NULL, 0, 0); + ret = rxrpc_kernel_recv_data(rxperf_socket, + call->rxcall, &call->iter, + &len, false, &remote_abort, + &call->service_id); + + if (ret == -EAGAIN || ret == 2) + return; + if (ret < 0 || ret == 1) { + if (ret == 1) + ret = 0; goto call_complete; + } return; } @@ -369,7 +381,7 @@ static int rxperf_extract_data(struct rxperf_call *call, bool want_more) if (ret == 0 || ret == -EAGAIN) return ret; - if (ret == 1) { + if (ret == 1 || ret == 2) { switch (call->state) { case RXPERF_CALL_SV_AWAIT_REQUEST: rxperf_set_call_state(call, RXPERF_CALL_SV_REPLYING); From dd0425c502fced67222e61d3dcc853cc15eda32c Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Fri, 9 Oct 2026 07:21:00 +0200 Subject: [PATCH 1769/2126] net/mlx5e: TC, free NIC flow parse attributes after offload A NIC flow holds a 4 KB allocation for its parse attributes until deletion although nothing reads them after offload. Free them once the rule is in. Signed-off-by: Alexandre Cassen Reviewed-by: Simon Horman Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261009052103.3621855-2-acassen@corp.free.fr Signed-off-by: Paolo Abeni --- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index c99e824b4c6d..708b7987ea4c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -1414,6 +1414,16 @@ void mlx5e_del_offloaded_nic_rule(struct mlx5e_priv *priv, MLX5E_TC_FT_LEVEL); } +static void mlx5e_tc_free_parse_attr(struct mlx5_flow_attr *attr) +{ + if (!attr->parse_attr) + return; + + mlx5e_mod_hdr_dealloc(&attr->parse_attr->mod_hdr_acts); + kvfree(attr->parse_attr); + attr->parse_attr = NULL; +} + static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow) { @@ -1436,10 +1446,8 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv, } mutex_unlock(&tc->t_lock); - if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) { - mlx5e_mod_hdr_dealloc(&attr->parse_attr->mod_hdr_acts); + if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) mlx5e_tc_detach_mod_hdr(priv, flow, attr); - } if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) mlx5_fc_destroy(priv->mdev, attr->counter); @@ -1450,7 +1458,7 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv, free_flow_post_acts(flow); mlx5_tc_ct_delete_flow(get_ct_priv(flow->priv), attr); - kvfree(attr->parse_attr); + mlx5e_tc_free_parse_attr(attr); kfree(flow->attr); } @@ -4759,6 +4767,7 @@ mlx5e_add_nic_flow(struct mlx5e_priv *priv, if (err) goto err_free; + mlx5e_tc_free_parse_attr(flow->attr); flow_flag_set(flow, OFFLOADED); *__flow = flow; @@ -4766,7 +4775,6 @@ mlx5e_add_nic_flow(struct mlx5e_priv *priv, err_free: flow_flag_set(flow, FAILED); - mlx5e_mod_hdr_dealloc(&parse_attr->mod_hdr_acts); mlx5e_flow_put(priv, flow); out: return err; From 3636705910f925190c949513cc5d8fa5d3f3ed92 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Fri, 9 Oct 2026 07:21:01 +0200 Subject: [PATCH 1770/2126] net/mlx5: HWS, shrink FTE action array to fit An FTE keeps the actions it must release in the array used to build them. This is a 1 KB allocation sized for MLX5_FLOW_CONTEXT_ACTION_MAX entries while a rule rarely needs more than three. Keep a copy sized to the actions in use. Signed-off-by: Alexandre Cassen Reviewed-by: Simon Horman Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261009052103.3621855-3-acassen@corp.free.fr Signed-off-by: Paolo Abeni --- .../ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c index 5a172c572a68..da6e57c103d6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c @@ -746,6 +746,7 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns, struct mlx5_fs_hws_context *fs_ctx = &ns->fs_hws_context; struct mlx5hws_action_dest_attr *dest_actions; struct mlx5hws_context *ctx = fs_ctx->hws_ctx; + struct mlx5_fs_hws_rule_action *rule_actions; struct mlx5_fs_hws_rule_action *fs_actions; struct mlx5_core_dev *dev = ns->dev; struct mlx5hws_action *dest_action; @@ -1041,13 +1042,20 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns, fs_actions[num_fs_actions++].action = tmp_action; (*ractions)[num_actions++].action = tmp_action; + rule_actions = kmemdup_array(fs_actions, num_fs_actions, + sizeof(*fs_actions), GFP_KERNEL); + if (!rule_actions) { + err = -ENOMEM; + goto free_actions; + } + kfree(fs_actions); kfree(dest_actions); /* Actions created specifically for this rule will be destroyed * once rule is deleted. */ fte->fs_hws_rule.num_fs_actions = num_fs_actions; - fte->fs_hws_rule.hws_fs_actions = fs_actions; + fte->fs_hws_rule.hws_fs_actions = rule_actions; return 0; From 6329e8232aa8f579522fbd5308890e13b9f2624e Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 9 Oct 2026 10:45:33 +0200 Subject: [PATCH 1771/2126] hinic3: use skb_put_padto() hinic3_send_one_skb() pads short frames with skb_pad(), then sets skb->len directly, leaving skb->tail stale. Use skb_put_padto(), which updates both. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261009084533.735996-1-edumazet@kernel.org Signed-off-by: Paolo Abeni --- drivers/net/ethernet/huawei/hinic3/hinic3_tx.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_tx.c b/drivers/net/ethernet/huawei/hinic3/hinic3_tx.c index d19cfbe3ed3b..f92568f0f00b 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_tx.c @@ -541,12 +541,8 @@ static netdev_tx_t hinic3_send_one_skb(struct sk_buff *skb, u32 offload; int err; - if (unlikely(skb->len < MIN_SKB_LEN)) { - if (skb_pad(skb, MIN_SKB_LEN - skb->len)) - goto err_out; - - skb->len = MIN_SKB_LEN; - } + if (skb_put_padto(skb, MIN_SKB_LEN)) + goto err_out; offload = hinic3_tx_offload(skb, &task, &queue_info, txq); num_sge = skb_shinfo(skb)->nr_frags + 1; From a39a3a32785ee2804ed8516b0cb1585b88c2ba51 Mon Sep 17 00:00:00 2001 From: Gabriel Goller Date: Fri, 9 Oct 2026 17:20:13 +0200 Subject: [PATCH 1772/2126] net: ipv6: seg6: report lwtunnel setup errors via extack seg6_build_state() rejected invalid configurations with a generic -EINVAL, so "ip route add ... encap seg6 ..." sometimes reported "Invalid argument". Add extack messages to the checks that lacked one, and use NL_REQ_ATTR_CHECK() for the missing SRH attribute so that userspace can tell which attribute is missing. The checks themselves and their return values are unchanged. Signed-off-by: Gabriel Goller Reviewed-by: Hangbin Liu Reviewed-by: Andrea Mayer Link: https://patch.msgid.link/20261009152015.462383-1-g.goller@proxmox.com Signed-off-by: Paolo Abeni --- net/ipv6/seg6_iptunnel.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 69a6ef5c5317..0d39a38a5dd2 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -762,8 +762,11 @@ static int seg6_build_state(struct net *net, struct nlattr *nla, struct seg6_lwt *slwt; int err; - if (family != AF_INET && family != AF_INET6) + if (family != AF_INET && family != AF_INET6) { + NL_SET_ERR_MSG(extack, + "unsupported address family for SRv6 encapsulation"); return -EINVAL; + } err = nla_parse_nested_deprecated(tb, SEG6_IPTUNNEL_MAX, nla, seg6_iptunnel_policy, extack); @@ -771,7 +774,7 @@ static int seg6_build_state(struct net *net, struct nlattr *nla, if (err < 0) return err; - if (!tb[SEG6_IPTUNNEL_SRH]) + if (NL_REQ_ATTR_CHECK(extack, nla, tb, SEG6_IPTUNNEL_SRH)) return -EINVAL; tuninfo = nla_data(tb[SEG6_IPTUNNEL_SRH]); @@ -782,13 +785,19 @@ static int seg6_build_state(struct net *net, struct nlattr *nla, */ min_size = sizeof(*tuninfo) + sizeof(struct ipv6_sr_hdr) + sizeof(struct in6_addr); - if (tuninfo_len < min_size) + if (tuninfo_len < min_size) { + NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH], + "truncated IPv6 Segment Routing Header attribute"); return -EINVAL; + } switch (tuninfo->mode) { case SEG6_IPTUN_MODE_INLINE: - if (family != AF_INET6) + if (family != AF_INET6) { + NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH], + "inline mode requires the IPv6 address family"); return -EINVAL; + } if (tb[SEG6_IPTUNNEL_SRC]) { NL_SET_ERR_MSG(extack, "incompatible mode for tunsrc"); @@ -804,12 +813,19 @@ static int seg6_build_state(struct net *net, struct nlattr *nla, case SEG6_IPTUN_MODE_L2ENCAP_RED: break; default: + NL_SET_ERR_MSG_ATTR_FMT(extack, tb[SEG6_IPTUNNEL_SRH], + "invalid SRv6 encapsulation mode %d", + tuninfo->mode); return -EINVAL; } /* verify that SRH is consistent */ - if (!seg6_validate_srh(tuninfo->srh, tuninfo_len - sizeof(*tuninfo), false)) + if (!seg6_validate_srh(tuninfo->srh, tuninfo_len - sizeof(*tuninfo), + false)) { + NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH], + "invalid IPv6 Segment Routing Header"); return -EINVAL; + } newts = lwtunnel_state_alloc(tuninfo_len + sizeof(*slwt)); if (!newts) From d8839381c196c86015b79b1a465f5e59e8206f1f Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Fri, 9 Oct 2026 10:54:45 -0500 Subject: [PATCH 1773/2126] dt-bindings: net: ethernet-controller: Allow "ethernet-N" node names The HiSilicon hisilicon,hns-nic-v2 binding uses "ethernet-N" node names as there is no "reg" property and multiple instances. Add support for this pattern which is a common pattern on other node names. Signed-off-by: Rob Herring (Arm) Acked-by: Conor Dooley Link: https://patch.msgid.link/20261009155444.2347045-2-robh@kernel.org Signed-off-by: Paolo Abeni --- Documentation/devicetree/bindings/net/ethernet-controller.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml index 1bafd687dcb1..30b2a335116e 100644 --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml @@ -11,7 +11,7 @@ maintainers: properties: $nodename: - pattern: "^ethernet(@.*)?$" + pattern: "^ethernet(@.+|-[0-9]+)?$" label: description: Human readable label on a port of a box. From a388f17e23b7e305cb306aafd73bb10d6b8ca452 Mon Sep 17 00:00:00 2001 From: Bui Viet Dung Date: Thu, 8 Oct 2026 20:07:53 +0700 Subject: [PATCH 1774/2126] wwan: wwan_hwsim: Pin module for debugfs file operations An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, wwan_hwsim_debugfs_portdestroy_fops, wwan_hwsim_debugfs_portcreate_fops, wwan_hwsim_debugfs_devdestroy_fops, and wwan_hwsim_debugfs_devcreate_fops in wwan_hwsim.c have no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the wwan_hwsim module. When a userspace process opens any of these debugfs files, a subsequent module unload (rmmod wwan_hwsim) can succeed while the file descriptor remains open. When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release(): BUG: unable to handle page fault for address: fffffbfff84f90ef Oops: 0000 [#2] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: __fput+0x357/0xaa0 fput_close_sync+0xe6/0x1a0 file_close_fd_locked+0x17e/0x2f0 do_close+0x33/0x70 __x64_sys_close+0x44/0x80 do_syscall_64+0xc3/0x590 entry_SYSCALL_64_after_hwframe+0x76/0x7e The issue was discovered via manual code audit of wwan_hwsim.c and reproduced on a Linux 7.3-rc6 test VM with CONFIG_WWAN_HWSIM=m. Set .owner = THIS_MODULE on all four debugfs file_operations structures in wwan_hwsim.c so that debugfs pins the module until close has completed. Fixes: 9ee23f48f670 ("wwan_hwsim: add debugfs management interface") Cc: stable@vger.kernel.org Signed-off-by: Bui Viet Dung Reviewed-by: Loic Poulain Link: https://patch.msgid.link/20261008130753.313875-1-dungvn2345@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/wwan/wwan_hwsim.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c index c3c2d2a68767..34eea3edc824 100644 --- a/drivers/net/wwan/wwan_hwsim.c +++ b/drivers/net/wwan/wwan_hwsim.c @@ -500,6 +500,7 @@ static ssize_t wwan_hwsim_debugfs_portdestroy_write(struct file *file, } static const struct file_operations wwan_hwsim_debugfs_portdestroy_fops = { + .owner = THIS_MODULE, .write = wwan_hwsim_debugfs_portdestroy_write, .open = simple_open, .llseek = noop_llseek, @@ -524,6 +525,7 @@ static ssize_t wwan_hwsim_debugfs_portcreate_write(struct file *file, } static const struct file_operations wwan_hwsim_debugfs_portcreate_fops = { + .owner = THIS_MODULE, .write = wwan_hwsim_debugfs_portcreate_write, .open = simple_open, .llseek = noop_llseek, @@ -545,6 +547,7 @@ static ssize_t wwan_hwsim_debugfs_devdestroy_write(struct file *file, } static const struct file_operations wwan_hwsim_debugfs_devdestroy_fops = { + .owner = THIS_MODULE, .write = wwan_hwsim_debugfs_devdestroy_write, .open = simple_open, .llseek = noop_llseek, @@ -568,6 +571,7 @@ static ssize_t wwan_hwsim_debugfs_devcreate_write(struct file *file, } static const struct file_operations wwan_hwsim_debugfs_devcreate_fops = { + .owner = THIS_MODULE, .write = wwan_hwsim_debugfs_devcreate_write, .open = simple_open, .llseek = noop_llseek, From 73022f605c447f31610b94ed4a983d2b4bf2c721 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 7 Oct 2026 20:51:22 -0700 Subject: [PATCH 1775/2126] net: ibm: emac: size RX buffers for the MTU Any MTU above ETH_DATA_LEN selects the largest MAL buffer size of 4080 bytes. A DSA conduit always runs with a slightly larger MTU for the switch tag (1502 for qca8k), so every received frame then uses an 8K slab object and a 4K cache invalidate even though it is at most 1520 bytes long. Size the buffers for the MTU instead, capped at the MAL maximum as before. Larger jumbo frames still span several descriptors. emac_change_mtu() only resized the ring, which is also where the jumbo mode and the APM821xx maximum jumbo size are programmed, when the RX skb size changed. 1500 and 1502 now share a skb size, so also resize the ring whenever the old or new MTU is a jumbo one. Otherwise jumbo mode stays off and 1502 byte frames are dropped when the MTU is raised while the interface is up. Routing a single TCP stream through the qca8k switch of a Meraki MX60 (APM82181, iperf3 median of 3, A/B in the same boot): LAN->WAN WAN->LAN (Mbit/s) before 538 476 after 564 498 Assisted-by: LLM Signed-off-by: Rosen Penev Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261008035122.3182851-1-rosenp@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/ibm/emac/core.c | 7 +++++-- drivers/net/ethernet/ibm/emac/core.h | 5 +---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c index e7043523457c..640618c0a09e 100644 --- a/drivers/net/ethernet/ibm/emac/core.c +++ b/drivers/net/ethernet/ibm/emac/core.c @@ -1114,8 +1114,11 @@ static int emac_change_mtu(struct net_device *ndev, int new_mtu) DBG(dev, "change_mtu(%d)" NL, new_mtu); if (netif_running(ndev)) { - /* Check if we really need to reinitialize RX ring */ - if (emac_rx_skb_size(ndev->mtu) != emac_rx_skb_size(new_mtu)) + /* Check if we really need to reinitialize RX ring. The + * jumbo frame settings are only updated by a resize. + */ + if (emac_rx_skb_size(ndev->mtu) != emac_rx_skb_size(new_mtu) || + ndev->mtu > ETH_DATA_LEN || new_mtu > ETH_DATA_LEN) ret = emac_resize_rx_ring(dev, new_mtu); } diff --git a/drivers/net/ethernet/ibm/emac/core.h b/drivers/net/ethernet/ibm/emac/core.h index 89fa1683ec3c..43578fe97fb2 100644 --- a/drivers/net/ethernet/ibm/emac/core.h +++ b/drivers/net/ethernet/ibm/emac/core.h @@ -56,10 +56,7 @@ /* RX BD size for the given MTU */ static inline int emac_rx_size(int mtu) { - if (mtu > ETH_DATA_LEN) - return MAL_MAX_RX_SIZE; - else - return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD); + return mal_rx_size(max(mtu, ETH_DATA_LEN) + EMAC_MTU_OVERHEAD); } /* Size of RX skb for the given MTU */ From 70f63dc608725c0b32507f22eb6d3028efb3ed09 Mon Sep 17 00:00:00 2001 From: Joe Damato Date: Fri, 9 Oct 2026 14:54:23 -0700 Subject: [PATCH 1776/2126] bnxt_en: Add helper to fill SW USO payload BDs Move the code that fills a payload BD and its software ring entry in bnxt_sw_udp_gso_xmit() into a helper, bnxt_sw_gso_data_bd(). No functional change. A following patch uses the helper to add a pad BD to short SW USO segments. Reviewed-by: Michael Chan Signed-off-by: Joe Damato Link: https://patch.msgid.link/20261009215426.2377946-2-joe@dama.to Signed-off-by: Paolo Abeni --- drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c index 6c1060fa2ea5..ef04c9d08066 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c @@ -31,6 +31,26 @@ static u32 bnxt_sw_gso_lhint(unsigned int len) return TX_BD_FLAGS_LHINT_2048_AND_LARGER; } +static struct tx_bd *bnxt_sw_gso_data_bd(struct bnxt *bp, + struct bnxt_tx_ring_info *txr, + u16 prod, dma_addr_t addr, + unsigned int len) +{ + struct tx_bd *txbd = &txr->tx_desc_ring[TX_RING(bp, prod)][TX_IDX(prod)]; + struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[RING_TX(bp, prod)]; + + txbd->tx_bd_haddr = cpu_to_le64(addr); + txbd->tx_bd_len_flags_type = cpu_to_le32(len << TX_BD_LEN_SHIFT); + txbd->tx_bd_opaque = 0; + + dma_unmap_addr_set(tx_buf, mapping, addr); + dma_unmap_len_set(tx_buf, len, 0); + tx_buf->skb = NULL; + tx_buf->is_sw_gso = 0; + + return txbd; +} + /* Transmit an skb requiring software UDP segmentation. * * Returns 1 if the skb was queued and new BDs were produced, 0 if the skb @@ -181,15 +201,10 @@ int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr, while (tso_dma_map_next(&map, &dma_addr, &chunk_len, &mapping_len, seg_payload)) { prod = NEXT_TX(prod); - txbd = &txr->tx_desc_ring[TX_RING(bp, prod)][TX_IDX(prod)]; + txbd = bnxt_sw_gso_data_bd(bp, txr, prod, dma_addr, + chunk_len); tx_buf = &txr->tx_buf_ring[RING_TX(bp, prod)]; - txbd->tx_bd_haddr = cpu_to_le64(dma_addr); - dma_unmap_addr_set(tx_buf, mapping, dma_addr); - dma_unmap_len_set(tx_buf, len, 0); - tx_buf->skb = NULL; - tx_buf->is_sw_gso = 0; - if (mapping_len) { if (last_unmap_buf) { dma_unmap_addr_set(last_unmap_buf, @@ -204,10 +219,6 @@ int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr, } last_unmap_buf = tx_buf; - flags = chunk_len << TX_BD_LEN_SHIFT; - txbd->tx_bd_len_flags_type = cpu_to_le32(flags); - txbd->tx_bd_opaque = 0; - seg_payload -= chunk_len; } From b0f7f9c87817da1c72d093d3e5f249d45d8edf88 Mon Sep 17 00:00:00 2001 From: Joe Damato Date: Fri, 9 Oct 2026 14:54:24 -0700 Subject: [PATCH 1777/2126] bnxt_en: Pad short SW USO segments to BNXT_MIN_PKT_SIZE Each SW USO segment is hdr_len + seg_payload bytes. With IPv4, hdr_len is 42 bytes, so a segment carrying less than 10 bytes of UDP payload is sent shorter than BNXT_MIN_PKT_SIZE. This happens with a short last segment (e.g. gso_size 1400 and 1405 bytes of payload) or with a gso_size below 10 bytes. Fix the short last segment in bnxt_sw_udp_gso_xmit(): zero the pad bytes after the header in the segment's inline header slot and add a pad BD pointing at them after the payload BDs. Only the last segment can need padding, and its pad BD fits within the existing bound in bds_needed and BNXT_SW_USO_MAX_DESCS, since payload BDs are at most num_segs + nr_frags. If gso_size itself is too small, every segment would need a pad BD, exceeding the descriptor bound. This case is unlikely, so bnxt_features_check() clears GSO features for these skbs and the stack segments them instead; bnxt_start_xmit() then pads each segment. Reviewed-by: Michael Chan Signed-off-by: Joe Damato Link: https://patch.msgid.link/20261009215426.2377946-3-joe@dama.to Signed-off-by: Paolo Abeni --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 12 ++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c | 28 +++++++++++++++++-- drivers/net/ethernet/broadcom/bnxt/bnxt_gso.h | 15 ++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index c1d3fcc7ae84..0682060b048c 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -14268,6 +14268,18 @@ static netdev_features_t bnxt_features_check(struct sk_buff *skb, u8 *l4_proto; features = vlan_features_check(skb, features); + + /* SW USO pads at most the last segment; let the stack segment skbs + * where every segment would be shorter than BNXT_MIN_PKT_SIZE. + */ + if (skb_is_gso(skb) && + (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) && + !(bp->flags & BNXT_FLAG_UDP_GSO_CAP) && + bnxt_sw_gso_pad_len(skb_transport_offset(skb) + + sizeof(struct udphdr), + skb_shinfo(skb)->gso_size)) + features &= ~NETIF_F_GSO_MASK; + switch (vlan_get_protocol(skb)) { case htons(ETH_P_IP): if (!skb->encapsulation) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c index ef04c9d08066..80d5c4f963a9 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c @@ -82,11 +82,19 @@ int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr, if (unlikely(num_segs <= 1)) goto drop; + /* bnxt_features_check() makes the stack segment these, but paths + * that skip validate_xmit_skb() (e.g. generic XDP_TX of a GRO'd + * skb) can still get here. Padding every segment would need more + * BDs than bds_needed reserves below, so drop instead. + */ + if (unlikely(bnxt_sw_gso_pad_len(hdr_len, mss))) + goto drop; + /* Upper bound on the number of descriptors needed. * * Each segment uses 1 long BD + 1 ext BD + payload BDs, which is * at most num_segs + nr_frags (each frag boundary crossing adds at - * most 1 extra BD). + * most 1 extra BD). The last segment may need 1 pad BD. */ bds_needed = 3 * num_segs + skb_shinfo(skb)->nr_frags + 1; @@ -133,12 +141,14 @@ int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr, dma_addr_t dma_addr; struct tx_bd *txbd; struct udphdr *uh; + unsigned int pad; void *this_hdr; int bd_count; bool last; u32 flags; last = (i == num_segs - 1); + pad = bnxt_sw_gso_pad_len(hdr_len, seg_payload); offset = slot * TSO_HEADER_SIZE; this_hdr = txr->tx_inline_buf + offset; this_hdr_dma = txr->tx_inline_dma + offset; @@ -156,10 +166,18 @@ int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr, iph->check = 0; } + /* Pad bytes follow the header in the inline slot. Zero them + * so stale header bytes from an earlier packet are not sent. + */ + if (pad) + memset(this_hdr + hdr_len, 0, pad); + dma_sync_single_for_device(&pdev->dev, this_hdr_dma, - hdr_len, DMA_TO_DEVICE); + hdr_len + pad, DMA_TO_DEVICE); bd_count = tso_dma_map_count(&map, seg_payload); + if (pad) + bd_count++; tx_buf = &txr->tx_buf_ring[RING_TX(bp, prod)]; txbd = &txr->tx_desc_ring[TX_RING(bp, prod)][TX_IDX(prod)]; @@ -222,6 +240,12 @@ int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr, seg_payload -= chunk_len; } + if (pad) { + prod = NEXT_TX(prod); + txbd = bnxt_sw_gso_data_bd(bp, txr, prod, + this_hdr_dma + hdr_len, pad); + } + txbd->tx_bd_len_flags_type |= cpu_to_le32(TX_BD_FLAGS_PACKET_END); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.h index 77d9af97cc22..5916ee08c0e6 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_gso.h @@ -19,10 +19,25 @@ * Each segment: 1 long BD + 1 ext BD + payload BDs. * Total payload BDs across all segs <= num_segs + nr_frags (each frag * boundary crossing adds at most 1 extra BD). + * The last segment may need 1 pad BD (see bnxt_sw_gso_pad_len()). * So: 3 * max_segs + MAX_SKB_FRAGS + 1 = 3 * 64 + 17 + 1 = 210. */ #define BNXT_SW_USO_MAX_DESCS (3 * BNXT_SW_USO_MAX_SEGS + MAX_SKB_FRAGS + 1) +/* Bytes of padding needed to bring a segment carrying @seg_payload bytes + * up to BNXT_MIN_PKT_SIZE, or 0 if no padding is needed. + */ +static inline unsigned int bnxt_sw_gso_pad_len(unsigned int hdr_len, + unsigned int seg_payload) +{ + unsigned int len = hdr_len + seg_payload; + + if (len < BNXT_MIN_PKT_SIZE) + return BNXT_MIN_PKT_SIZE - len; + else + return 0; +} + static inline u16 bnxt_inline_avail(struct bnxt_tx_ring_info *txr) { return BNXT_SW_USO_MAX_SEGS - From e6435b2cc5fdf008cdb67ad9a811a266e8ac9c1e Mon Sep 17 00:00:00 2001 From: Atharva Vartak Date: Wed, 7 Oct 2026 00:00:09 -0400 Subject: [PATCH 1778/2126] net/smc: hold a reference on net_device returned by pnet_find_base_ndev() pnet_find_base_ndev() resolves the base net_device for stacked devices under RTNL, then drops the lock and returns the raw pointer without taking a reference. All three callers dereference the pointer after RTNL has been released, creating a use-after-free window if the device is concurrently unregistered. Take a reference with netdev_hold() before dropping RTNL and add the matching netdev_put() in every return path of the three callers: - smc_pnet_add_eth() - smc_pnet_find_roce_by_pnetid() - smc_pnet_find_ism_by_pnetid() Found by code analysis, confirmed with a proof-of-concept that triggers a KASAN slab-use-after-free report. Fixes: 0afff91c6f5e ("net/smc: add pnetid support") Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM") Cc: "D. Wythe" Cc: Dust Li Cc: Sidraya Jayagond Cc: Mahanta Jambigi Cc: Tony Lu Cc: Wen Gu Cc: Willy Tarreau Signed-off-by: Atharva Vartak Link: https://patch.msgid.link/20261007040009.137568-1-atharva.a.vartak@gmail.com Signed-off-by: Jakub Kicinski --- net/smc/smc_pnet.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c index ff9c9c35cc2f..61ef1d697eee 100644 --- a/net/smc/smc_pnet.c +++ b/net/smc/smc_pnet.c @@ -30,7 +30,8 @@ #include "smc_core.h" static struct net_device *__pnet_find_base_ndev(struct net_device *ndev); -static struct net_device *pnet_find_base_ndev(struct net_device *ndev); +static struct net_device *pnet_find_base_ndev(struct net_device *ndev, + netdevice_tracker *tracker); static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX + 1] = { [SMC_PNETID_NAME] = { @@ -356,6 +357,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net, struct smc_pnetentry *tmp_pe, *new_pe; struct net_device *ndev, *base_ndev; u8 ndev_pnetid[SMC_MAX_PNETID_LEN]; + netdevice_tracker base_tracker; bool new_netdev; int rc; @@ -365,10 +367,13 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net, rc = -EEXIST; ndev = dev_get_by_name(net, eth_name); /* dev_hold() */ if (ndev) { - base_ndev = pnet_find_base_ndev(ndev); + base_ndev = pnet_find_base_ndev(ndev, &base_tracker); if (!smc_pnetid_by_dev_port(base_ndev->dev.parent, - base_ndev->dev_port, ndev_pnetid)) + base_ndev->dev_port, ndev_pnetid)) { + netdev_put(base_ndev, &base_tracker); goto out_put; + } + netdev_put(base_ndev, &base_tracker); } /* add a new netdev entry to the pnet table if there isn't one */ @@ -945,10 +950,13 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev) * (for instance with bonding slaves), just the first device * is used to reach a base device. */ -static struct net_device *pnet_find_base_ndev(struct net_device *ndev) +static struct net_device *pnet_find_base_ndev(struct net_device *ndev, + netdevice_tracker *tracker) { rtnl_lock(); ndev = __pnet_find_base_ndev(ndev); + /* keep ndev alive after dropping RTNL, callers must netdev_put() */ + netdev_hold(ndev, tracker, GFP_KERNEL); rtnl_unlock(); return ndev; } @@ -1085,17 +1093,20 @@ static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev, { u8 ndev_pnetid[SMC_MAX_PNETID_LEN]; struct net_device *base_ndev; + netdevice_tracker base_tracker; struct net *net; - base_ndev = pnet_find_base_ndev(ndev); + base_ndev = pnet_find_base_ndev(ndev, &base_tracker); net = dev_net(ndev); if (smc_pnetid_by_dev_port(base_ndev->dev.parent, base_ndev->dev_port, ndev_pnetid) && smc_pnet_find_ndev_pnetid_by_table(base_ndev, ndev_pnetid) && smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) { smc_pnet_find_rdma_dev(base_ndev, ini); + netdev_put(base_ndev, &base_tracker); return; /* pnetid could not be determined */ } + netdev_put(base_ndev, &base_tracker); _smc_pnet_find_roce_by_pnetid(ndev_pnetid, ini, NULL, net); } @@ -1103,13 +1114,16 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, struct smc_init_info *ini) { u8 ndev_pnetid[SMC_MAX_PNETID_LEN]; + netdevice_tracker base_tracker; struct smcd_dev *ismdev; - ndev = pnet_find_base_ndev(ndev); + ndev = pnet_find_base_ndev(ndev, &base_tracker); if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port, ndev_pnetid) && - smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) + smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) { + netdev_put(ndev, &base_tracker); return; /* pnetid could not be determined */ + } mutex_lock(&smcd_dev_list.mutex); list_for_each_entry(ismdev, &smcd_dev_list.list, list) { @@ -1123,6 +1137,7 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, } } mutex_unlock(&smcd_dev_list.mutex); + netdev_put(ndev, &base_tracker); } /* PNET table analysis for a given sock: From 499f32f0eb56603af2930ba67b4eb82fc1437264 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 8 Oct 2026 16:24:01 +0800 Subject: [PATCH 1779/2126] net: lwtunnel: change encap fill order I plan to add lwtunnel encap attributes to the YNL rt-route.yaml spec. When decoding submessages, YNL expects to read the "selector" (encap-type) first. Currently lwtunnel writes the encap payload first, which makes YNL fail to parse the lwtunnel encap message. Fixing this within YNL itself would be complicated. Instead, reorder the netlink attributes in the kernel to output encap_type first. This is a preparatory change for the upcoming rt-route spec updates. Reviewed-by: Ido Schimmel Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261008-ynl_rt_encap-v4-1-4ed2ccf7f949@kylinos.cn Signed-off-by: Jakub Kicinski --- net/core/lwtunnel.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c index b01a395d9a96..8223c44f10c8 100644 --- a/net/core/lwtunnel.c +++ b/net/core/lwtunnel.c @@ -231,7 +231,7 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate, { const struct lwtunnel_encap_ops *ops; struct nlattr *nest; - int ret; + int ret = 0; if (!lwtstate) return 0; @@ -240,30 +240,31 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate, lwtstate->type > LWTUNNEL_ENCAP_MAX) return 0; - nest = nla_nest_start_noflag(skb, encap_attr); - if (!nest) - return -EMSGSIZE; - - ret = -EOPNOTSUPP; rcu_read_lock(); - ops = rcu_dereference(lwtun_encaps[lwtstate->type]); - if (likely(ops && ops->fill_encap)) - ret = ops->fill_encap(skb, lwtstate); - rcu_read_unlock(); - if (ret) - goto nla_put_failure; - nla_nest_end(skb, nest); + ops = rcu_dereference(lwtun_encaps[lwtstate->type]); + if (unlikely(!ops || !ops->fill_encap)) + goto unlock_out; + ret = nla_put_u16(skb, encap_type_attr, lwtstate->type); if (ret) - goto nla_put_failure; + goto unlock_out; - return 0; + nest = nla_nest_start_noflag(skb, encap_attr); + if (!nest) { + ret = -EMSGSIZE; + goto unlock_out; + } -nla_put_failure: - nla_nest_cancel(skb, nest); + ret = ops->fill_encap(skb, lwtstate); + if (ret) + nla_nest_cancel(skb, nest); + else + nla_nest_end(skb, nest); - return (ret == -EOPNOTSUPP ? 0 : ret); +unlock_out: + rcu_read_unlock(); + return ret; } EXPORT_SYMBOL_GPL(lwtunnel_fill_encap); From 05d3030eff5b73f6fe7f86dafa3eeae004e2ede1 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 8 Oct 2026 16:24:02 +0800 Subject: [PATCH 1780/2126] tools: ynl: convert enum selector to string for sub-message parsing YNL sub-message parsing expects a string selector for strcmp(). So for non-external enum selectors, convert the integer value to its string form via the family's {enum}_str() helper. This enables correct decoding of sub-messages keyed by enum values. After the change, if there is no encap_type (e.g. previous ordering on older kernels), or a new encap_type is missing from the spec file in future kernel, the code will report "Sub-message key not set", the same with string lookup fails. With the subsequent rt-route encap spec update, the newly generated code will look like: if (!dst->_present.encap_type) return ynl_submsg_failed(yarg, "encap", "encap-type"); encap_type_str = rt_route_encap_type_str(dst->encap_type); if (!encap_type_str) return ynl_submsg_failed(yarg, "encap", "enum-lookup-failed"); if (rt_route_encap_data_parse(&parg, encap_type_str, attr)) return YNL_PARSE_CB_ERROR; Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261008-ynl_rt_encap-v4-2-4ed2ccf7f949@kylinos.cn Signed-off-by: Jakub Kicinski --- tools/net/ynl/pyynl/ynl_gen_c.py | 34 +++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py index 15c79849c609..4aca51396a9e 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -951,13 +951,31 @@ class TypeSubMessage(TypeNest): sel_var = f"_sel_{sel}" else: sel_var = f"{var}->{sel}" - get_lines = [f'if (!{sel_var})', - f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");', - f"if ({self.nested_render_name}_parse(&parg, {sel_var}, attr))", - "return YNL_PARSE_CB_ERROR;"] + + local_vars = None + + if self.selector.is_enum_val() and not self.selector.is_external(): + enum = self.family.consts[self.selector.get_enum_name()] + pres_var = f"{var}->_present.{sel}" + parse_sel = f"{sel}_str" + local_vars = [f'const char *{parse_sel};'] + + get_lines = [ + f'if (!{pres_var})', + f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");', + f'{parse_sel} = {enum.render_name}_str({sel_var});', + f'if (!{parse_sel})', + f'return ynl_submsg_failed(yarg, "{self.name}", "enum-lookup-failed");'] + else: + parse_sel = sel_var + get_lines = [f'if (!{parse_sel})', + f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");'] + + get_lines += [f"if ({self.nested_render_name}_parse(&parg, {parse_sel}, attr))", + "return YNL_PARSE_CB_ERROR;"] init_lines = [f"parg.rsp_policy = &{self.nested_render_name}_nest;", f"parg.data = &{var}->{self.c_name};"] - return get_lines, init_lines, None + return get_lines, init_lines, local_vars class Selector: @@ -979,6 +997,12 @@ class Selector: def is_external(self): return self._external + def is_enum_val(self): + return self.get_enum_name() is not None + + def get_enum_name(self): + return self.attr and self.attr.attr.get("enum") + class Struct: def __init__(self, family, space_name, type_list=None, fixed_header=None, From 24d11a55860be75a6b478e4e4ba8adb419c19661 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 8 Oct 2026 16:24:03 +0800 Subject: [PATCH 1781/2126] netlink: specs: rt-route: add lwtunnel encap sub-message support Define encap-type enum (LWTUNNEL_ENCAP_*) and add encap-data sub-message keyed by encap-type. Add tunnel attribute sets (mpls, ip, ila, ip6, seg6, bpf, seg6-local, rpl, ioam6, xfrm). This spec update depends on the kernel side encap-type/data reorder patch. Keep some nested option attributes as binary in this patch to simplify review; they will be converted in follow-up patches. Also add the Makefile to include uapi headers. Note the lwtunnel.h is guarded by _UAPI_LWTUNNEL_H_. Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261008-ynl_rt_encap-v4-3-4ed2ccf7f949@kylinos.cn Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-route.yaml | 287 +++++++++++++++++++++- tools/net/ynl/Makefile.deps | 9 +- 2 files changed, 294 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/rt-route.yaml b/Documentation/netlink/specs/rt-route.yaml index 253037ea5176..dc842a786794 100644 --- a/Documentation/netlink/specs/rt-route.yaml +++ b/Documentation/netlink/specs/rt-route.yaml @@ -99,6 +99,58 @@ definitions: name: ra-withdrawn doc: A Router Advertisement withdrew the route with a zero lifetime. + - + name: encap-type + type: enum + name-prefix: lwtunnel-encap- + enum-name: + entries: + - none + - mpls + - ip + - ila + - ip6 + - seg6 + - bpf + - seg6-local + - rpl + - ioam6 + - xfrm + +sub-messages: + - + name: encap-data + formats: + - + value: mpls + attribute-set: mpls-iptunnel + - + value: ip + attribute-set: lwtunnel-ip + - + value: ila + attribute-set: ila-attrs + - + value: ip6 + attribute-set: lwtunnel-ip6 + - + value: seg6 + attribute-set: seg6-iptunnel + - + value: bpf + attribute-set: lwt-bpf + - + value: seg6-local + attribute-set: seg6-local + - + value: rpl + attribute-set: rpl-iptunnel + - + value: ioam6 + attribute-set: ioam6-iptunnel + - + value: xfrm + attribute-set: lwt-xfrm attribute-sets: - @@ -174,9 +226,12 @@ attribute-sets: - name: encap-type type: u16 + enum: encap-type - name: encap - type: binary # tunnel specific nest + type: sub-message + sub-message: encap-data + selector: encap-type - name: expires type: u32 @@ -277,6 +332,236 @@ attribute-sets: - name: fastopen-no-cookie type: u32 + - + name: mpls-iptunnel + name-prefix: mpls-iptunnel- + header: linux/mpls_iptunnel.h + attributes: + - + name: dst + type: binary + - + name: ttl + type: u8 + - + name: lwtunnel-ip + name-prefix: lwtunnel-ip- + header: linux/lwtunnel.h + attributes: + - + name: id + type: u64 + byte-order: big-endian + - + name: dst + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: src + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: ttl + type: u8 + - + name: tos + type: u8 + - + name: flags + type: u16 + byte-order: big-endian + - + name: pad + type: pad + - + name: opts + type: binary # lwtunnel ip nest options + - + name: ila-attrs + name-prefix: ila-attr- + header: linux/ila.h + attributes: + - + name: locator + type: u64 + byte-order: big-endian + - + name: identifier + type: u64 + - + name: locator-match + type: u64 + byte-order: big-endian + - + name: ifindex + type: s32 + - + name: dir + type: u32 + - + name: pad + type: pad + - + name: csum-mode + type: u8 + - + name: ident-type + type: u8 + - + name: hook-type + type: u8 + - + name: lwtunnel-ip6 + name-prefix: lwtunnel-ip6- + header: linux/lwtunnel.h + attributes: + - + name: id + type: u64 + byte-order: big-endian + - + name: dst + type: binary + display-hint: ipv6 + - + name: src + type: binary + display-hint: ipv6 + - + name: hoplimit + type: u8 + - + name: tc + type: u8 + - + name: flags + type: u16 + byte-order: big-endian + - + name: pad + type: pad + - + name: opts + type: binary # lwtunnel ip nest options + - + name: seg6-iptunnel + name-prefix: seg6-iptunnel- + header: linux/seg6_iptunnel.h + attributes: + - + name: srh + type: binary + - + name: src + type: binary + display-hint: ipv6 + - + name: table + type: u32 + - + name: lwt-bpf + name-prefix: lwt-bpf- + header: linux/lwtunnel.h + attributes: + - + name: in + type: binary # bpf prog + - + name: out + type: binary + - + name: xmit + type: binary + - + name: xmit-headroom + type: u32 + - + name: seg6-local + name-prefix: seg6-local- + header: linux/seg6_local.h + attributes: + - + name: action + type: u32 + - + name: srh + type: binary + - + name: table + type: u32 + - + name: nh4 + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: nh6 + type: binary + display-hint: ipv6 + - + name: iif + type: u32 + - + name: oif + type: u32 + - + name: bpf + type: binary + - + name: vrftable + type: u32 + - + name: counters + type: binary + - + name: flavors + type: binary + - + name: rpl-iptunnel + name-prefix: rpl-iptunnel- + header: linux/rpl_iptunnel.h + attributes: + - + name: srh + type: binary + - + name: ioam6-iptunnel + name-prefix: ioam6-iptunnel- + header: linux/ioam6_iptunnel.h + attributes: + - + name: mode + type: u8 + - + name: dst + type: binary + display-hint: ipv6 + - + name: trace + type: binary + - + name: freq-k + type: u32 + - + name: freq-n + type: u32 + - + name: src + type: binary + display-hint: ipv6 + - + name: lwt-xfrm + name-prefix: lwt-xfrm- + header: linux/lwtunnel.h + attributes: + - + name: if-id + type: u32 + - + name: link + type: u32 operations: enum-model: directional diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps index 1e746e25e2bc..3eee34e0efcf 100644 --- a/tools/net/ynl/Makefile.deps +++ b/tools/net/ynl/Makefile.deps @@ -45,7 +45,14 @@ CFLAGS_rt-link:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ $(call get_hdr_inc,_LINUX_IF_LINK_H,if_link.h) CFLAGS_rt-neigh:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ $(call get_hdr_inc,__LINUX_NEIGHBOUR_H,neighbour.h) -CFLAGS_rt-route:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) +CFLAGS_rt-route:=$(call get_hdr_inc,_LINUX_ILA_H,ila.h) \ + $(call get_hdr_inc,_LINUX_IOAM6_IPTUNNEL_H,ioam6_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_MPLS_IPTUNNEL_H,mpls_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_RPL_IPTUNNEL_H,rpl_iptunnel.h) \ + $(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ + $(call get_hdr_inc,_LINUX_SEG6_IPTUNNEL_H,seg6_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_SEG6_LOCAL_H,seg6_local.h) \ + $(call get_hdr_inc,_LWTUNNEL_H_,lwtunnel.h) CFLAGS_rt-rule:=$(call get_hdr_inc,__LINUX_FIB_RULES_H,fib_rules.h) CFLAGS_tc:= $(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ $(call get_hdr_inc,__LINUX_PKT_SCHED_H,pkt_sched.h) \ From e32b5eb4f237a5ddcf936c53e9ca387bb4cdd31c Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 8 Oct 2026 16:24:04 +0800 Subject: [PATCH 1782/2126] netlink: specs: rt-route: describe lwtunnel IP options Replace binary opts in lwtunnel-ip and lwtunnel-ip6 with a nested lwtunnel-ip-opts set. Add attribute sets for geneve, vxlan, and erspan IP options to match linux/lwtunnel.h. Note the kernel encodes LWTUNNEL_IP_OPTS_GENEVE differently for requests vs dumps. On the request path, the kernel iterates and reads one CLASS/TYPE/DATA triplet per geneve option. On the dump path, the kernel opens only one nested geneve option and writes a CLASS/TYPE/DATA triplet for every option within it. Before there is a proper way to handle it, I will just omit geneve options and use binary for it. Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261008-ynl_rt_encap-v4-4-4ed2ccf7f949@kylinos.cn Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-route.yaml | 45 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/rt-route.yaml b/Documentation/netlink/specs/rt-route.yaml index dc842a786794..ea6711292c9b 100644 --- a/Documentation/netlink/specs/rt-route.yaml +++ b/Documentation/netlink/specs/rt-route.yaml @@ -377,7 +377,8 @@ attribute-sets: type: pad - name: opts - type: binary # lwtunnel ip nest options + type: nest + nested-attributes: lwtunnel-ip-opts - name: ila-attrs name-prefix: ila-attr- @@ -444,7 +445,8 @@ attribute-sets: type: pad - name: opts - type: binary # lwtunnel ip nest options + type: nest + nested-attributes: lwtunnel-ip-opts - name: seg6-iptunnel name-prefix: seg6-iptunnel- @@ -562,6 +564,45 @@ attribute-sets: - name: link type: u32 + - + name: lwtunnel-ip-opts + name-prefix: lwtunnel-ip-opts- + attributes: + - + name: geneve + type: binary + - + name: vxlan + type: nest + nested-attributes: lwtunnel-ip-opt-vxlan + - + name: erspan + type: nest + nested-attributes: lwtunnel-ip-opt-erspan + - + name: lwtunnel-ip-opt-vxlan + name-prefix: lwtunnel-ip-opt-vxlan- + attributes: + - + name: gbp + type: u32 + - + name: lwtunnel-ip-opt-erspan + name-prefix: lwtunnel-ip-opt-erspan- + attributes: + - + name: ver + type: u8 + - + name: index + type: u32 + byte-order: big-endian + - + name: dir + type: u8 + - + name: hwid + type: u8 operations: enum-model: directional From 8ab5eb3bf6e0dafa08614c6f7e13d896bf54f424 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 8 Oct 2026 16:24:05 +0800 Subject: [PATCH 1783/2126] netlink: specs: rt-route: describe lwt BPF program options Replace binary BPF attributes with a nested lwt-bpf-prog to support lwt bpf prog options. Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261008-ynl_rt_encap-v4-5-4ed2ccf7f949@kylinos.cn Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-route.yaml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/specs/rt-route.yaml b/Documentation/netlink/specs/rt-route.yaml index ea6711292c9b..82e59af56ecd 100644 --- a/Documentation/netlink/specs/rt-route.yaml +++ b/Documentation/netlink/specs/rt-route.yaml @@ -469,13 +469,16 @@ attribute-sets: attributes: - name: in - type: binary # bpf prog + type: nest + nested-attributes: lwt-bpf-prog - name: out - type: binary + type: nest + nested-attributes: lwt-bpf-prog - name: xmit - type: binary + type: nest + nested-attributes: lwt-bpf-prog - name: xmit-headroom type: u32 @@ -603,6 +606,18 @@ attribute-sets: - name: hwid type: u8 + - + name: lwt-bpf-prog + name-prefix: lwt-bpf-prog- + attributes: + - + name: fd + type: u32 + - + name: name + type: string + checks: + max-len: 256 operations: enum-model: directional From 5f9d4edccf0ca319a970907c8b91f34a1c55590b Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 8 Oct 2026 16:24:06 +0800 Subject: [PATCH 1784/2126] netlink: specs: rt-route: describe seg6-local attrs Add SEG6 local actions enums, seg6-local-flv-ops flags. Replace binary bpf/counters/flavors in seg6-local with nested seg6-local-bpf, seg6-local-cnt and seg6-local-flv. Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261008-ynl_rt_encap-v4-6-4ed2ccf7f949@kylinos.cn Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-route.yaml | 93 ++++++++++++++++++++++- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/specs/rt-route.yaml b/Documentation/netlink/specs/rt-route.yaml index 82e59af56ecd..48d1659f20f3 100644 --- a/Documentation/netlink/specs/rt-route.yaml +++ b/Documentation/netlink/specs/rt-route.yaml @@ -116,6 +116,45 @@ definitions: - rpl - ioam6 - xfrm + - + name: seg6-local-actions + type: enum + name-prefix: seg6-local-action- + enum-name: + entries: + - unspec + - end + - end-x + - end-t + - end-dx2 + - end-dx6 + - end-dx4 + - end-dt6 + - end-dt4 + - end-b6 + - end-b6-encap + - end-bm + - end-s + - end-as + - end-am + - end-bpf + - end-dt46 + - + name: seg6-local-flv-ops + type: enum + name-prefix: seg6-local-flv-op- + enum-name: + entries: + - + name: unspec + - + name: psp + - + name: usp + - + name: usd + - + name: next-csid sub-messages: - @@ -490,6 +529,7 @@ attribute-sets: - name: action type: u32 + enum: seg6-local-actions - name: srh type: binary @@ -513,16 +553,19 @@ attribute-sets: type: u32 - name: bpf - type: binary + type: nest + nested-attributes: seg6-local-bpf - name: vrftable type: u32 - name: counters - type: binary + type: nest + nested-attributes: seg6-local-cnt - name: flavors - type: binary + type: nest + nested-attributes: seg6-local-flv - name: rpl-iptunnel name-prefix: rpl-iptunnel- @@ -618,6 +661,50 @@ attribute-sets: type: string checks: max-len: 256 + - + name: seg6-local-bpf + name-prefix: seg6-local-bpf- + attr-max-name: seg6-local-bpf-prog-max + attributes: + - + name: prog + type: u32 + - + name: prog-name + type: string + checks: + max-len: 256 + - + name: seg6-local-cnt + name-prefix: seg6-local-cnt- + attributes: + - + name: pad + type: pad + - + name: packets + type: u64 + - + name: bytes + type: u64 + - + name: errors + type: u64 + - + name: seg6-local-flv + name-prefix: seg6-local-flv- + attributes: + - + name: operation + type: u32 + enum: seg6-local-flv-ops + enum-as-flags: true + - + name: lcblock-bits + type: u8 + - + name: lcnode-fn-bits + type: u8 operations: enum-model: directional From ad1320865b1826ffa2e81e37c49535751e81335c Mon Sep 17 00:00:00 2001 From: David Lee Date: Fri, 9 Oct 2026 15:42:31 +0800 Subject: [PATCH 1785/2126] sctp: hold shkey across socket migration sctp_sock_migrate() transfers queued DATA skbs from the old socket to the new one. skb_orphan() invokes sctp_wfree() during that transfer and drops the skb-owned shared-key reference. If userspace has removed that key from the association, this can be the final reference. The following sctp_set_owner_w() then dereferences the freed chunk->shkey while trying to take the new owner reference. Take a temporary shared-key reference before orphaning the skb and release it after the new owner has taken its reference. This preserves the selected authentication key throughout the ownership transfer. Bug found and triaged by OpenAI Security Research and validated by Trail of Bits. Fixes: 1b1e0bc99474 ("sctp: add refcnt support for sh_key") Signed-off-by: Kyle Zeng Signed-off-by: David Lee Acked-by: Xin Long Link: https://patch.msgid.link/20261009074244.3718-2-juny24602@gmail.com Signed-off-by: Jakub Kicinski --- net/sctp/socket.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 321898f22d80..696e67936251 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -147,9 +147,19 @@ static inline void sctp_set_owner_w(struct sctp_chunk *chunk) static void sctp_clear_owner_w(struct sctp_chunk *chunk) { + /* Keep the shkey alive until the new owner takes its reference. */ + if (chunk->shkey) + sctp_auth_shkey_hold(chunk->shkey); skb_orphan(chunk->skb); } +static void sctp_set_owner_w_migrate(struct sctp_chunk *chunk) +{ + sctp_set_owner_w(chunk); + if (chunk->shkey) + sctp_auth_shkey_release(chunk->shkey); +} + #define traverse_and_process() \ do { \ msg = chunk->msg; \ @@ -9637,7 +9647,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w); sctp_assoc_migrate(assoc, newsk); - sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w); + sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w_migrate); /* If the association on the newsk is already closed before accept() * is called, set RCV_SHUTDOWN flag. From 52ffeaa358d1f3d91aa87a26ad90d77769cff74b Mon Sep 17 00:00:00 2001 From: Jun Yang Date: Fri, 9 Oct 2026 15:42:32 +0800 Subject: [PATCH 1786/2126] sctp: re-point retained control chunks on association migration sctp_sock_migrate() transfers DATA chunk ownership but leaves retained control chunks pointing at the old socket. A later retransmission can therefore access the socket after it has been freed. Extend the migration walk to cover retained control chunks and use sctp_control_set_owner_w() to assign their new owner. Reuse the DATA ownership check so each chunk is processed once per pass, even when it is reachable through multiple lists or retained pointers. Preserve a control chunk's existing authentication key across migration so its final release can still generate SCTP_AUTH_FREE_KEY when needed. Fixes: d04adf1b3551 ("sctp: reset owner sk for data chunks on out queues when migrating a sock") Cc: stable@kernel.org Reported-by: TencentOS Corvus AI Signed-off-by: Jun Yang Acked-by: Xin Long Link: https://patch.msgid.link/20261009074244.3718-3-juny24602@gmail.com Signed-off-by: Jakub Kicinski --- include/net/sctp/sm.h | 1 + net/sctp/sm_make_chunk.c | 5 ++-- net/sctp/socket.c | 53 ++++++++++++++++++++++++++++++---------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h index 3bfd261a53cc..76605d1ee839 100644 --- a/include/net/sctp/sm.h +++ b/include/net/sctp/sm.h @@ -252,6 +252,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc, struct sctp_fwdtsn_skip *skiplist); struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc, __u16 key_id); +void sctp_control_set_owner_w(struct sctp_chunk *chunk); struct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc, __u16 stream_num, __be16 *stream_list, bool out, bool in); diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 84a4c97d0f75..ddc31a5dbad3 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -94,7 +94,7 @@ static void sctp_control_release_owner(struct sk_buff *skb) } } -static void sctp_control_set_owner_w(struct sctp_chunk *chunk) +void sctp_control_set_owner_w(struct sctp_chunk *chunk) { struct sctp_association *asoc = chunk->asoc; struct sk_buff *skb = chunk->skb; @@ -107,7 +107,8 @@ static void sctp_control_set_owner_w(struct sctp_chunk *chunk) * For now don't do anything for now. */ if (chunk->auth) { - chunk->shkey = asoc->shkey; + if (!chunk->shkey) + chunk->shkey = asoc->shkey; sctp_auth_shkey_hold(chunk->shkey); } skb->sk = asoc ? asoc->base.sk : NULL; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 696e67936251..8cf3e955ae18 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -155,9 +155,24 @@ static void sctp_clear_owner_w(struct sctp_chunk *chunk) static void sctp_set_owner_w_migrate(struct sctp_chunk *chunk) { - sctp_set_owner_w(chunk); - if (chunk->shkey) - sctp_auth_shkey_release(chunk->shkey); + struct sctp_shared_key *shkey = chunk->shkey; + + if (chunk->msg) + sctp_set_owner_w(chunk); + else + sctp_control_set_owner_w(chunk); + + if (shkey) + sctp_auth_shkey_release(shkey); +} + +static void sctp_process_tx_chunk(struct sctp_association *asoc, + struct sctp_chunk *chunk, bool clear, + void (*cb)(struct sctp_chunk *)) +{ + if ((clear && asoc->base.sk == chunk->skb->sk) || + (!clear && asoc->base.sk != chunk->skb->sk)) + cb(chunk); } #define traverse_and_process() \ @@ -165,17 +180,14 @@ do { \ msg = chunk->msg; \ if (msg == prev_msg) \ continue; \ - list_for_each_entry(c, &msg->chunks, frag_list) { \ - if ((clear && asoc->base.sk == c->skb->sk) || \ - (!clear && asoc->base.sk != c->skb->sk)) \ - cb(c); \ - } \ + list_for_each_entry(c, &msg->chunks, frag_list) \ + sctp_process_tx_chunk(asoc, c, clear, cb); \ prev_msg = msg; \ } while (0) -static void sctp_for_each_tx_datachunk(struct sctp_association *asoc, - bool clear, - void (*cb)(struct sctp_chunk *)) +static void sctp_for_each_tx_chunk(struct sctp_association *asoc, + bool clear, + void (*cb)(struct sctp_chunk *)) { struct sctp_datamsg *msg, *prev_msg = NULL; @@ -198,6 +210,21 @@ static void sctp_for_each_tx_datachunk(struct sctp_association *asoc, list_for_each_entry(chunk, &q->out_chunk_list, list) traverse_and_process(); + + list_for_each_entry(chunk, &q->control_chunk_list, list) + sctp_process_tx_chunk(asoc, chunk, clear, cb); + + list_for_each_entry(chunk, &asoc->asconf_ack_list, transmitted_list) + sctp_process_tx_chunk(asoc, chunk, clear, cb); + + list_for_each_entry(chunk, &asoc->addip_chunk_list, list) + sctp_process_tx_chunk(asoc, chunk, clear, cb); + + if (asoc->strreset_chunk) + sctp_process_tx_chunk(asoc, asoc->strreset_chunk, clear, cb); + + if (asoc->addip_last_asconf) + sctp_process_tx_chunk(asoc, asoc->addip_last_asconf, clear, cb); } static void sctp_for_each_rx_skb(struct sctp_association *asoc, struct sock *sk, @@ -9645,9 +9672,9 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, * paths won't try to lock it and then oldsk. */ lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); - sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w); + sctp_for_each_tx_chunk(assoc, true, sctp_clear_owner_w); sctp_assoc_migrate(assoc, newsk); - sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w_migrate); + sctp_for_each_tx_chunk(assoc, false, sctp_set_owner_w_migrate); /* If the association on the newsk is already closed before accept() * is called, set RCV_SHUTDOWN flag. From 0d20963e0aeb39da919288a3b70ecf555f5ab3a1 Mon Sep 17 00:00:00 2001 From: Pengfei Zhang Date: Fri, 9 Oct 2026 19:11:37 +0800 Subject: [PATCH 1787/2126] net: stmmac: fix RX coalesce frames counter The RX refill path should set the IC bit once every rx_coal_frames descriptors and leave the rest to the RX watchdog (RIWT), as done by commit d429b66e2ebc ("net: stmmac: Implement RX Coalesce Frames setting"). Since commit 6fa9d691b91a ("net: stmmac: Prevent divide-by-zero") the counter is increased by N+1 for each descriptor and then compared against N, so it is always reset to 0. With a non-zero rx-frames, IC is therefore set on every descriptor and every frame raises an interrupt. Fix this by counting one descriptor at a time in a helper used by both stmmac_rx_refill() and stmmac_rx_refill_zc(). Platforms without RIWT (IC on every descriptor) are unaffected. Cc: stable+noautosel@kernel.org # never worked Fixes: 6fa9d691b91a ("net: stmmac: Prevent divide-by-zero") Signed-off-by: Pengfei Zhang Link: https://patch.msgid.link/20261009111138.320089-1-zhangfeionline@gmail.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 56d89a696272..53782ab55e12 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5110,6 +5110,22 @@ static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb) } } +static bool stmmac_rx_need_ic(struct stmmac_priv *priv, + struct stmmac_rx_queue *rx_q, u32 queue) +{ + u32 frames = priv->rx_coal_frames[queue]; + + /* without the RX watchdog every descriptor needs IC */ + if (!priv->use_riwt) + return true; + + if (!frames || ++rx_q->rx_count_frames < frames) + return false; + + rx_q->rx_count_frames = 0; + return true; +} + /** * stmmac_rx_refill - refill used skb preallocated buffers * @priv: driver private structure @@ -5155,15 +5171,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue) stmmac_rx_check_buf2_cap(priv)); stmmac_refill_desc3(priv, rx_q, p); - rx_q->rx_count_frames++; - rx_q->rx_count_frames += priv->rx_coal_frames[queue]; - if (rx_q->rx_count_frames > priv->rx_coal_frames[queue]) - rx_q->rx_count_frames = 0; - - use_rx_wd = !priv->rx_coal_frames[queue]; - use_rx_wd |= rx_q->rx_count_frames > 0; - if (!priv->use_riwt) - use_rx_wd = false; + use_rx_wd = !stmmac_rx_need_ic(priv, rx_q, queue); dma_wmb(); stmmac_set_rx_owner(priv, p, use_rx_wd); @@ -5573,15 +5581,7 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget) stmmac_set_desc_sec_addr(priv, rx_desc, 0, false); stmmac_refill_desc3(priv, rx_q, rx_desc); - rx_q->rx_count_frames++; - rx_q->rx_count_frames += priv->rx_coal_frames[queue]; - if (rx_q->rx_count_frames > priv->rx_coal_frames[queue]) - rx_q->rx_count_frames = 0; - - use_rx_wd = !priv->rx_coal_frames[queue]; - use_rx_wd |= rx_q->rx_count_frames > 0; - if (!priv->use_riwt) - use_rx_wd = false; + use_rx_wd = !stmmac_rx_need_ic(priv, rx_q, queue); dma_wmb(); stmmac_set_rx_owner(priv, rx_desc, use_rx_wd); From 72ebc685bca99f466ef35600b5263d1c21c790d9 Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Sat, 10 Oct 2026 03:36:08 +0000 Subject: [PATCH 1788/2126] net: netmem: document netmem and memory provider design in comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clarify the netmem, memory provider, page_pool, and skb fragment design principles in header and code comments: - Memory providers allocate struct net_iov or struct page, cast them to netmem_ref, and pass them to page_pool; page_pool, drivers, and the core stack operate on netmem_ref and must not downcast to page or net_iov outside dedicated netmem helpers. - While current memory providers supply struct net_iov, they are not architecturally restricted to net_iov and may supply page-backed netmems. - While current net_iov types are CPU-unreadable, net_iov has no inherent restrictions and may be readable or unreadable. - New code should generalize existing limitations as much as possible to match these design principles. - Per-provider logic belongs in memory_provider_ops, and per-netmem-type logic belongs in netmem helpers. - All frags in an skb must either all be struct page-backed or all belong to the same memory provider instance; mixing them (including via coalescing) is not allowed. Cc: Luigi Rizzo Cc: Pavel Begunkov Signed-off-by: Mina Almasry Acked-by: Jesper Dangaard Brouer Reviewed-by: Björn Töpel Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20261010033630.1171692-2-almasrymina@google.com Signed-off-by: Jakub Kicinski --- include/linux/skbuff.h | 6 +++++ include/net/netmem.h | 30 ++++++++++++++++--------- include/net/page_pool/helpers.h | 18 ++++++++++----- include/net/page_pool/memory_provider.h | 10 +++++++++ include/net/page_pool/types.h | 6 ++--- net/core/skbuff.c | 4 ++++ 6 files changed, 56 insertions(+), 18 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 27ec1e38c828..af1cbc2799b7 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -358,6 +358,12 @@ struct sk_buff; */ #define GSO_BY_FRAGS 0xFFFF +/* All frags in an skb must either all be struct page-backed or all belong to + * the same memory provider instance (e.g. the same devmem binding or io_uring + * area). Mixing page and memory-provider frags, or mixing frags from different + * memory providers within a single skb (including via coalescing), is not + * allowed. + */ typedef struct skb_frag { netmem_ref netmem; unsigned int len; diff --git a/include/net/netmem.h b/include/net/netmem.h index 0cc8572f62ca..c4beb6fbc130 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -70,16 +70,18 @@ enum net_iov_type { NET_IOV_IOURING, }; -/* A memory descriptor representing abstract networking I/O vectors, - * generally for non-pages memory that doesn't have its corresponding - * struct page and needs to be explicitly allocated through slab. +/* A memory descriptor representing abstract networking I/O vectors. * * net_iovs are allocated and used by networking code, and the size of * the chunk is PAGE_SIZE. * - * This memory can be any form of non-struct paged memory. Examples - * include imported dmabuf memory and imported io_uring memory. See - * net_iov_type for all the supported types. + * Examples include imported dmabuf memory and imported io_uring memory. See + * net_iov_type for all the supported types. While current net_iov types are + * unreadable by the CPU, net_iov has no inherent restrictions and may be + * CPU-readable or unreadable. New code must not assume net_iov implies + * unreadable memory (check readability via netmem_address() or + * skb_frags_readable() instead) and should, as much as possible, generalize + * existing limitations to match the design principles. * * @pp_magic: pp field, similar to the one in struct page/struct * netmem_desc. @@ -131,8 +133,17 @@ static inline void net_iov_init(struct net_iov *niov, * network memory. * * A netmem_ref can be a struct page* or a struct net_iov* underneath. + * Memory providers (or the default page_pool allocator) allocate struct + * net_iov or struct page, cast them to netmem_ref, and hand them to + * page_pool. * - * Use the supplied helpers to obtain the underlying memory pointer and fields. + * The page_pool, drivers, and core networking stack should operate on + * netmem_ref rather than struct page or struct net_iov. Downcasting + * netmem_ref via netmem_to_page() or netmem_to_net_iov() in callers is + * not allowed unless a code path strictly requires a specific backing + * type (e.g., kmap_local_page()). In such cases, add a netmem helper here + * that handles both page and net_iov cases and returns an error if the + * underlying type cannot support the operation. */ typedef unsigned long __bitwise netmem_ref; @@ -297,9 +308,8 @@ static inline atomic_long_t *netmem_get_pp_ref_count_ref(netmem_ref netmem) static inline bool netmem_is_pref_nid(netmem_ref netmem, int pref_nid) { - /* NUMA node preference only makes sense if we're allocating - * system memory. Memory providers (which give us net_iovs) - * choose for us. + /* NUMA node preference only applies to struct page; net_iovs are + * managed by their memory provider. */ if (netmem_is_net_iov(netmem)) return true; diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index cd021832c3fa..28635ce9454e 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -8,12 +8,20 @@ /** * DOC: page_pool allocator * - * The page_pool allocator is optimized for recycling page or page fragment used - * by skb packet and xdp frame. + * The page_pool allocator is optimized for recycling network memory + * (netmem_ref) or fragments used by skb packets and xdp frames. * - * Basic use involves replacing any alloc_pages() calls with page_pool_alloc(), - * which allocate memory with or without page splitting depending on the - * requested memory size. + * page_pool natively operates on netmem_ref, which abstracts the underlying + * memory type (struct page or struct net_iov) supplied by the page allocator + * or a memory provider. Drivers and core networking code should use the + * netmem-based APIs (e.g. page_pool_alloc_netmem(), page_pool_put_netmem()). + * The struct page-based APIs (e.g. page_pool_alloc(), page_pool_alloc_pages(), + * page_pool_put_page()) are legacy compatibility wrappers for drivers not yet + * converted to netmem. + * + * Basic use involves replacing any alloc_pages() calls with + * page_pool_alloc_netmem() (or legacy page_pool_alloc()), which allocate memory + * with or without splitting depending on the requested memory size. * * If the driver knows that it always requires full pages or its allocations are * always smaller than half a page, it can use one of the more specific API diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index 255ce4cfd975..137cfc50833a 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -9,6 +9,16 @@ struct netdev_rx_queue; struct netlink_ext_ack; struct sk_buff; +/* Memory providers allocate underlying memory (struct net_iov or struct page), + * cast it to netmem_ref, and supply it to page_pool. While current memory + * providers only return struct net_iov, they are not architecturally limited to + * net_iov; a provider returning page-backed netmems is allowed. New code must + * not assume a memory provider implies net_iov and should, as much as possible, + * generalize existing limitations to match the design principles. + * + * Per-provider custom logic must be delegated to memory_provider_ops rather + * than handled directly in page_pool core code. + */ struct memory_provider_ops { netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp); bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem); diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 03da138722f5..6d543076a0c0 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -22,9 +22,9 @@ */ #define PP_FLAG_SYSTEM_POOL BIT(2) /* Global system page_pool */ -/* Allow unreadable (net_iov backed) netmem in this page_pool. Drivers setting - * this must be able to support unreadable netmem, where netmem_address() would - * return NULL. This flag should not be set for header page_pools. +/* Allow unreadable netmem in this page_pool. Drivers setting this must be able + * to support unreadable netmem, where netmem_address() returns NULL. This flag + * should not be set for header page_pools. * * If the driver sets PP_FLAG_ALLOW_UNREADABLE_NETMEM, it should also set * page_pool_params.slow.queue_idx. diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b25d8e2c9aaf..f0cf117f3566 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6214,6 +6214,10 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, if (to->pp_recycle != from->pp_recycle) return false; + /* All frags in an skb must either all be struct page-backed or all + * belong to the same memory provider instance; do not coalesce skbs + * that would mix them. + */ if (skb_frags_readable(from) != skb_frags_readable(to)) return false; From b35ec0d877f5ec9e127ca12afbb34883787b7d40 Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Sat, 10 Oct 2026 03:36:09 +0000 Subject: [PATCH 1789/2126] docs: netmem: document netmem and memory provider design principles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a Design Principles section to Documentation/networking/netmem.rst covering the netmem_ref abstraction, the prohibition on direct downcasting in callers, decoupling memory providers from net_iov, decoupling net_iov from unreadability, delegating provider/type logic to memory_provider_ops and netmem helpers, and the rule against mixing skb fragment memory sources. Cc: Luigi Rizzo Signed-off-by: Mina Almasry Reviewed-by: Björn Töpel Reviewed-by: Pavel Begunkov Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20261010033630.1171692-3-almasrymina@google.com Signed-off-by: Jakub Kicinski --- Documentation/networking/netmem.rst | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Documentation/networking/netmem.rst b/Documentation/networking/netmem.rst index 217869d1108d..6871dcdd700c 100644 --- a/Documentation/networking/netmem.rst +++ b/Documentation/networking/netmem.rst @@ -19,6 +19,59 @@ Benefits of Netmem : * Simplified Development: Drivers interact with a consistent API, regardless of the underlying memory implementation. +Design Principles +================= + +Memory providers (or the default ``page_pool`` allocator) allocate underlying +memory (``struct net_iov`` or ``struct page``), cast it to ``netmem_ref``, and +supply it to ``page_pool``. The ``page_pool``, drivers, and networking stack +operate on ``netmem_ref`` as the abstract type. Existing ``page_pool`` APIs +that allocate or free ``struct page`` are legacy compatibility wrappers for +drivers that do not yet support ``netmem_ref``. Code that is not yet +``netmem``-aware should be converted to ``netmem_ref`` unless it will never +need to support ``netmem``. + +1. **Operate on netmem_ref, do not downcast**: ``page_pool``, drivers, and the + core networking stack should deal with ``netmem_ref`` rather than + ``struct net_iov`` or ``struct page``. Downcasting ``netmem_ref`` to + ``struct net_iov`` or ``struct page`` is not allowed unless a code path + strictly cannot function without knowing the underlying memory type (for + example, ``kmap_local_page()``). In those cases, to keep call sites simple, + add a ``netmem`` helper that performs the operation on behalf of the caller, + cleanly handles all ``net_iov`` and ``page`` cases, and returns an error if + the ``netmem`` type cannot support the requested operation. + +2. **Decouple memory providers from net_iov**: Memory providers are not + architecturally limited to ``struct net_iov``; a memory provider that returns + ``struct page``-backed ``netmem_ref``\ s to upper layers is allowed. Today, + in-tree memory providers only supply ``struct net_iov`` and some existing + code still reflects that limitation, but new code must not assume that using + a memory provider implies ``net_iov`` memory and should, as much as possible, + generalize existing limitations to match the design principles. + +3. **Decouple net_iov from unreadability**: ``struct net_iov`` is flexible and + has no inherent restrictions; it may represent either CPU-readable or + unreadable memory. Today, in-tree ``net_iov`` implementations are unreadable + by the CPU (``netmem_address()`` returns ``NULL``) and some existing code + still reflects that limitation, but new code must not assume ``net_iov`` + implies unreadable memory (check readability via ``netmem_address()`` or + ``skb_frags_readable()`` instead) and should, as much as possible, generalize + existing limitations to match the design principles. + +4. **Delegate complexity to the lowest layer**: Each layer must respect its + abstraction boundary. ``page_pool`` must not implement per-memory-provider + custom logic in its main code; instead, it delegates provider-specific + handling to ``struct memory_provider_ops``. Similarly, core networking code + should avoid per-``netmem``-type branching and instead delegate operations + to ``netmem`` helpers that handle the underlying memory type. + +5. **Do not mix skb fragment memory sources**: All ``frags[]`` in an + ``sk_buff`` must either be ``struct page``-backed or belong to the same + memory provider instance (for example, the same ``devmem`` binding or + ``io_uring`` area). Mixing ``struct page`` and memory-provider fragments, + or mixing fragments from different memory providers within a single + ``sk_buff``, is not allowed (including when coalescing ``sk_buff``\ s). + Driver RX Requirements ====================== From 2d36ec73836e83175deb467fd494c61006107e5d Mon Sep 17 00:00:00 2001 From: Yun Zhou Date: Thu, 8 Oct 2026 17:38:24 +0800 Subject: [PATCH 1790/2126] net: erspan: set lltx to avoid sch_direct_xmit deadlock The ERSPAN xmit path re-enters the network stack, causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock, creating an ABBA deadlock. This happens for both IPv4 ERSPAN (erspan_xmit() -> ip_tunnel_xmit()) and IPv6 ERSPAN (ip6erspan_tunnel_xmit() -> ip6_tnl_xmit()): sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit -> ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay] sch_direct_xmit [lock erspan] -> ip6erspan_tunnel_xmit -> ip6_tnl_xmit -> ip6_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay] Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as the ERSPAN xmit path has no shared mutable state: o_seqno is atomic, TX stats are per-CPU u64_stats, dst_cache is per-CPU, and o_flags is no longer modified in the xmit path since commit 9958e69b9893 ("gre: fix ERSPAN o_flags race/corruption in xmit and fill_info"). GRETAP, the sibling device with identical xmit structure, already sets lltx. Reported-by: syzbot+9bda1b9fbb7fbdf9b62b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=9bda1b9fbb7fbdf9b62b Fixes: 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN") Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support") Cc: stable@vger.kernel.org # 9958e69b9893 ("gre: fix ERSPAN o_flags race/corruption in xmit and fill_info") Cc: stable@vger.kernel.org Signed-off-by: Yun Zhou Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261008093824.119453-1-yun.zhou@windriver.com Signed-off-by: Jakub Kicinski --- net/ipv4/ip_gre.c | 1 + net/ipv6/ip6_gre.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index e4878e9aa636..149a4e83b692 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1367,6 +1367,7 @@ static int erspan_tunnel_init(struct net_device *dev) dev->features |= GRE_FEATURES; dev->hw_features |= GRE_FEATURES; dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; + dev->lltx = true; netif_keep_dst(dev); return ip_tunnel_init(dev); diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 04f7c70b7320..3429543ec77e 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -1864,6 +1864,7 @@ static int ip6erspan_tap_init(struct net_device *dev) dev->mtu -= 8; dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; + dev->lltx = true; ip6erspan_tnl_link_config(tunnel, 1); netdev_hold(dev, &tunnel->dev_tracker, GFP_KERNEL); From 01b99e9d0d6260846e4256abb0d500d7985a8215 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sun, 11 Oct 2026 01:51:14 +0100 Subject: [PATCH 1791/2126] net: sfp: add quirk for TP-LINK SM410U The TP-LINK SM410U is a 2.5G copper module which is based on RealTek RTL8221B, but doesn't seem to offer any way to access the PHY over I2C. Add a quirk to disable in-band which isn't supported by the PHY. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/172a4fed74d35b1be51f4e8aba2222aa33845b08.1791679663.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski --- drivers/net/phy/sfp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 96361584791b..85e57a16bb52 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -645,6 +645,8 @@ static const struct sfp_quirk sfp_quirks[] = { // match the part as a prefix. SFP_QUIRK_F_PREFIX("OEM", "XGSPONST2001", sfp_fixup_potron), + SFP_QUIRK_S("TP-LINK", "TL-SM410U", sfp_quirk_oem_2_5g), + SFP_QUIRK_F("Turris", "RTSFP-2.5G", sfp_fixup_rollball), SFP_QUIRK_F("Turris", "RTSFP-10", sfp_fixup_rollball), SFP_QUIRK_F("Turris", "RTSFP-10G", sfp_fixup_rollball), From b8aa6bedc5fb16bad28b7f7665d184e94e40ad6e Mon Sep 17 00:00:00 2001 From: Julien Blanc Date: Fri, 9 Oct 2026 08:08:33 +0000 Subject: [PATCH 1792/2126] net: phy: dp83td510: Add config phase Add a config phase for the Texas Instruments DP83TD510E ethernet PHY The config phase currently sets the following properties from the device tree: * RMII / RGMII mode (note : RMII master / slave can only be set by straps and cannot be changed at runtime) * RGMII delays. These delays can be enabled on the phy side, only as a boolean. Delays are enabled if phy-mode is rgmii-id, or rgmii-[rx|tx]id which enables only the corresponding delay. * In case another mode is encountered, do nothing and return success (keep old behavior) Note on RCSR: unlike the DP83822, on the DS83TD510E both delays are active-high (ie, rgmii internal delays are enabled when the corresponding bit is set to 1 in the configuration register). Signed-off-by: Julien Blanc Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/e9e0499a28a49e489fb623429c7487b8ece78d12.camel@sprinte.eu Signed-off-by: Jakub Kicinski --- drivers/net/phy/dp83td510.c | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/net/phy/dp83td510.c b/drivers/net/phy/dp83td510.c index 9e9a41bf6457..31c139bef076 100644 --- a/drivers/net/phy/dp83td510.c +++ b/drivers/net/phy/dp83td510.c @@ -30,6 +30,12 @@ #define DP83TD510E_INT1_LINK BIT(13) #define DP83TD510E_INT1_LINK_EN BIT(5) +#define DP83TD510E_RCSR 0x17 +#define DP83TD510E_RMII_MODE_EN BIT(5) +#define DP83TD510E_RGMII_MODE_EN BIT(9) +#define DP83TD510E_TX_CLK_SHIFT BIT(11) +#define DP83TD510E_RX_CLK_SHIFT BIT(12) + #define DP83TD510E_CTRL 0x1f #define DP83TD510E_CTRL_HW_RESET BIT(15) #define DP83TD510E_CTRL_SW_RESET BIT(14) @@ -649,6 +655,71 @@ static int dp83td510_config_aneg(struct phy_device *phydev) return genphy_c45_check_and_restart_aneg(phydev, changed); } +static bool dp83td510_config_rgmii_rx_delay(struct phy_device *phydev) +{ + return phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID; +} + +static bool dp83td510_config_rgmii_tx_delay(struct phy_device *phydev) +{ + return phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID; +} + +static int dp83td510_config_init(struct phy_device *phydev) +{ + int rgmii_delay = 0; + bool rx_int_delay; + bool tx_int_delay; + int ret; + + if (phy_interface_is_rgmii(phydev)) { + rx_int_delay = dp83td510_config_rgmii_rx_delay(phydev); + if (rx_int_delay) + rgmii_delay |= DP83TD510E_RX_CLK_SHIFT; + + tx_int_delay = dp83td510_config_rgmii_tx_delay(phydev); + + if (tx_int_delay) + rgmii_delay |= DP83TD510E_TX_CLK_SHIFT; + + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, DP83TD510E_RCSR, + DP83TD510E_RX_CLK_SHIFT | + DP83TD510E_TX_CLK_SHIFT, + rgmii_delay); + if (ret) + return ret; + + ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, + DP83TD510E_RCSR, DP83TD510E_RGMII_MODE_EN); + + if (ret) + return ret; + + } else if (phydev->interface == PHY_INTERFACE_MODE_RMII) { + /* set RMII_MODE_EN, clear RGMII_MODE_EN. We need to clear RGMII + * here because otherwise, RMII/MII configuration would be + * ignored as RGMII would be selected. + */ + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, DP83TD510E_RCSR, + DP83TD510E_RMII_MODE_EN | + DP83TD510E_RGMII_MODE_EN, + DP83TD510E_RMII_MODE_EN); + if (ret) + return ret; + } else { + /* may be MII, which is supported, or something else. Just + * return success to keep the old behavior and not break + * anything. Configuration may have been done by straps so + * it's better to not touch it. + */ + ret = 0; + } + + return ret; +} + static int dp83td510_get_sqi(struct phy_device *phydev) { int sqi, ret; @@ -942,6 +1013,7 @@ static struct phy_driver dp83td510_driver[] = { .name = "TI DP83TD510E", .flags = PHY_POLL_CABLE_TEST, + .config_init = dp83td510_config_init, .probe = dp83td510_probe, .config_aneg = dp83td510_config_aneg, .read_status = dp83td510_read_status, From 1800f27a5ef86c158b618a1325f4cdd538b799a0 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Sat, 10 Oct 2026 17:22:25 +0200 Subject: [PATCH 1793/2126] net/sched: act_api: take tcfa_lock for hardware stats updates Actions without per CPU stats update their counters under tcfa_lock in the software path but tcf_action_update_stats() adds hardware stats to the same counters without it. A dump of a filter without skip_hw does this even when nothing is offloaded, so such an action loses counter updates. On 32-bit, readers holding tcfa_lock can also observe torn 64-bit values. Callers disable preemption around this update for the per CPU stats. PREEMPT_RT forbids taking a spinlock_t with preemption disabled. Disable BH in the per CPU path instead. On 32-bit, this also keeps a softirq on the same CPU from updating or reading these counters in the middle of the update. Discovered by manual code inspection while letting more actions honor TCA_ACT_FLAGS_NO_PERCPU_STATS. Reproduced in a VM without kernel changes, where the second action counts fewer packets than the first: ip link add d0 type dummy && ip link set d0 up tc qdisc add dev d0 clsact tc filter add dev d0 ingress matchall \ action gact pipe action gact pass no_percpu yes "filter show dev d0 ingress" | head -10000 > batch while :; do tc -s -b batch; done > /dev/null & samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh -i d0 -t 4 tc -s filter show dev d0 ingress The 32-bit issue in the per CPU path comes from the Sashiko AI review of v1 [1] and was not reproduced. Tested with the reproducer and the tc-testing action, matchall and flower tests with lockdep enabled. Also tested for regressions on ConnectX-7 with firmware 28.48.1000. Cc: stable+noautosel@kernel.org # high regression risk, mixed-use actions are not commonly used in practice Fixes: 5e174d5e73df ("net: sched: modify stats helper functions to support regular stats") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009051703.3615846-1-acassen%40corp.free.fr [1] Signed-off-by: Alexandre Cassen Reviewed-by: Eric Dumazet Reviewed-by: Jamal Hadi Salim Link: https://patch.msgid.link/20261010152227.401987-1-acassen@corp.free.fr Signed-off-by: Jakub Kicinski --- include/net/pkt_cls.h | 2 -- net/sched/act_api.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 5f5cb36439fe..9382405b2bab 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -316,10 +316,8 @@ tcf_exts_hw_stats_update(const struct tcf_exts *exts, continue; } - preempt_disable(); tcf_action_stats_update(a, stats->bytes, stats->pkts, stats->drops, stats->lastused, true); - preempt_enable(); a->used_hw_stats = stats->used_hw_stats; a->used_hw_stats_valid = stats->used_hw_stats_valid; diff --git a/net/sched/act_api.c b/net/sched/act_api.c index cd6e68e8af1b..d9d4f7097624 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -307,13 +307,11 @@ int tcf_action_update_hw_stats(struct tc_action *action) err = tcf_action_offload_cmd(&fl_act, NULL, NULL, NULL); if (!err) { - preempt_disable(); tcf_action_stats_update(action, fl_act.stats.bytes, fl_act.stats.pkts, fl_act.stats.drops, fl_act.stats.lastused, true); - preempt_enable(); action->used_hw_stats = fl_act.stats.used_hw_stats; action->used_hw_stats_valid = true; } else { @@ -1596,6 +1594,7 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets, u64 drops, bool hw) { if (a->cpu_bstats) { + local_bh_disable(); _bstats_update(this_cpu_ptr(a->cpu_bstats), bytes, packets); this_cpu_add(a->cpu_qstats->drops, drops); @@ -1603,13 +1602,16 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets, if (hw) _bstats_update(this_cpu_ptr(a->cpu_bstats_hw), bytes, packets); + local_bh_enable(); return; } + spin_lock_bh(&a->tcfa_lock); _bstats_update(&a->tcfa_bstats, bytes, packets); atomic_add(drops, &a->tcfa_drops); if (hw) _bstats_update(&a->tcfa_bstats_hw, bytes, packets); + spin_unlock_bh(&a->tcfa_lock); } EXPORT_SYMBOL(tcf_action_update_stats); From 8241cd8ebe015017d05684b2bf3f5d3076caa915 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sat, 10 Oct 2026 20:28:00 -0700 Subject: [PATCH 1794/2126] net: dccp: uapi: clean up kernel-doc comments Use correct kernel-doc format for struct members and add comments for missing struct members (dccph_seq2 and reserved). Signed-off-by: Randy Dunlap Link: https://patch.msgid.link/20261011032800.278870-1-rdunlap@infradead.org Signed-off-by: Jakub Kicinski --- include/uapi/linux/dccp.h | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/include/uapi/linux/dccp.h b/include/uapi/linux/dccp.h index 6e1978dbcf7c..4a97d7fd855e 100644 --- a/include/uapi/linux/dccp.h +++ b/include/uapi/linux/dccp.h @@ -8,15 +8,19 @@ /** * struct dccp_hdr - generic part of DCCP packet header * - * @dccph_sport - Relevant port on the endpoint that sent this packet - * @dccph_dport - Relevant port on the other endpoint - * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words - * @dccph_ccval - Used by the HC-Sender CCID - * @dccph_cscov - Parts of the packet that are covered by the Checksum field - * @dccph_checksum - Internet checksum, depends on dccph_cscov - * @dccph_x - 0 = 24 bit sequence number, 1 = 48 - * @dccph_type - packet type, see DCCP_PKT_ prefixed macros - * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x + * @dccph_sport: Relevant port on the endpoint that sent this packet + * @dccph_dport: Relevant port on the other endpoint + * @dccph_doff: Data Offset from the start of the DCCP header, in 32-bit words + * @dccph_ccval: Used by the HC-Sender CCID + * @dccph_cscov: Parts of the packet that are covered by the Checksum field + * @dccph_checksum: Internet checksum, depends on dccph_cscov + * @dccph_x: 0 = 24 bit sequence number, 1 = 48 + * @dccph_type: packet type, see DCCP_PKT_ prefixed macros + * @dccph_reserved: reserved bits + * @dccph_seq: sequence number high or low order lower 16 bits, + * depends on dccph_x + * @dccph_seq2: sequence number high or low order upper 8 bits, + * depends on dccph_x */ struct dccp_hdr { __be16 dccph_sport, @@ -50,7 +54,7 @@ struct dccp_hdr { /** * struct dccp_hdr_ext - the low bits of a 48 bit seq packet * - * @dccph_seq_low - low 24 bits of a 48 bit seq packet + * @dccph_seq_low: low 24 bits of a 48 bit seq packet */ struct dccp_hdr_ext { __be32 dccph_seq_low; @@ -59,7 +63,7 @@ struct dccp_hdr_ext { /** * struct dccp_hdr_request - Connection initiation request header * - * @dccph_req_service - Service to which the client app wants to connect + * @dccph_req_service: Service to which the client app wants to connect */ struct dccp_hdr_request { __be32 dccph_req_service; @@ -67,8 +71,9 @@ struct dccp_hdr_request { /** * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets * - * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR - * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR + * @dccph_reserved1: reserved bits + * @dccph_ack_nr_high: 48 bit ack number high order bits, contains GSR + * @dccph_ack_nr_low: 48 bit ack number low order bits, contains GSR */ struct dccp_hdr_ack_bits { __be16 dccph_reserved1; @@ -78,8 +83,8 @@ struct dccp_hdr_ack_bits { /** * struct dccp_hdr_response - Connection initiation response header * - * @dccph_resp_ack - 48 bit Acknowledgment Number Subheader (5.3) - * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request + * @dccph_resp_ack: 48 bit Acknowledgment Number Subheader (5.3) + * @dccph_resp_service: Echoes the Service Code on a received DCCP-Request */ struct dccp_hdr_response { struct dccp_hdr_ack_bits dccph_resp_ack; @@ -89,9 +94,9 @@ struct dccp_hdr_response { /** * struct dccp_hdr_reset - Unconditionally shut down a connection * - * @dccph_reset_ack - 48 bit Acknowledgment Number Subheader (5.6) - * @dccph_reset_code - one of %dccp_reset_codes - * @dccph_reset_data - the Data 1 ... Data 3 fields from 5.6 + * @dccph_reset_ack: 48 bit Acknowledgment Number Subheader (5.6) + * @dccph_reset_code: one of %dccp_reset_codes + * @dccph_reset_data: the Data 1 ... Data 3 fields from 5.6 */ struct dccp_hdr_reset { struct dccp_hdr_ack_bits dccph_reset_ack; From c7d8bc3dd511dac309754543d3063f3950b364c2 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:00 +0000 Subject: [PATCH 1795/2126] net: skbuff: don't BUG() on bad arguments to pskb_expand_head() pskb_expand_head() BUG()s if it is handed a negative nhead or a shared skb. Both are bugs in the caller, and both keep getting hit: commit 2cbb259ec4f8 ("bpf: Reject negative head_room in __bpf_skb_change_head") and commit 64e6a754d33d ("llc: do not use skb_get() before dev_queue_xmit()") each fixed a crash here that took down the whole box. The function already returns an error that every caller has to handle, and at this point it hasn't touched the skb. Return -EINVAL instead of crashing. The warning is DEBUG_NET_WARN_ON_ONCE(), so debug kernels still point at the caller, while production kernels, including ones running with panic_on_warn, just fail the call. Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-1-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index f0cf117f3566..089f76d96bdd 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -2303,9 +2303,15 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, u8 *data; int i; - BUG_ON(nhead < 0); + if (unlikely(nhead < 0)) { + DEBUG_NET_WARN_ON_ONCE(1); + return -EINVAL; + } - BUG_ON(skb_shared(skb)); + if (unlikely(skb_shared(skb))) { + DEBUG_NET_WARN_ON_ONCE(1); + return -EINVAL; + } skb_zcopy_downgrade_managed(skb); From 7b32bee7db821e6b4d92d29708c24539e2b5464f Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:01 +0000 Subject: [PATCH 1796/2126] net: skbuff: don't BUG() on a bad frag_list layout in skb_segment() skb_segment()'s frag_list walk assumes the GRO-shaped layout it expects and BUG()s when the layout doesn't match. Anybody who can get a malformed GSO skb to a segmentation point gets to crash the box. Most recently commit d5dc1e69fd72 ("inet: frags: strip GSO state from fragments before reassembly") fixed one that an unprivileged user could trigger with two writes to a tap device in their own user namespace. commit 3382a1ed7f77 ("net: fix udp gso skb_segment after pull from frag_list") fixed another. skb_segment() already has an error path for a bad layout: the too-many-frags check sets -EINVAL and frees the partial segment list. Take that path for the four layout checks, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The packet gets dropped, which is what should happen to a packet we can't segment. The one check that runs after skb_clone() and before the clone is linked into the segment list frees the clone itself. Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-2-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 089f76d96bdd..a577217513e8 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4924,7 +4924,11 @@ normal: if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) && (skb_headlen(list_skb) == len || sg)) { - BUG_ON(skb_headlen(list_skb) > len); + if (unlikely(skb_headlen(list_skb) > len)) { + DEBUG_NET_WARN_ON_ONCE(1); + err = -EINVAL; + goto err; + } nskb = skb_clone(list_skb, GFP_ATOMIC); if (unlikely(!nskb)) @@ -4937,7 +4941,12 @@ normal: pos += skb_headlen(list_skb); while (pos < offset + len) { - BUG_ON(i >= nfrags); + if (unlikely(i >= nfrags)) { + DEBUG_NET_WARN_ON_ONCE(1); + kfree_skb(nskb); + err = -EINVAL; + goto err; + } size = skb_frag_size(frag); if (pos + size > offset + len) @@ -5044,9 +5053,17 @@ normal: skb_shinfo(nskb)->flags |= skb_shinfo(frag_skb)->flags & SKBFL_SHARED_FRAG; if (!skb_headlen(list_skb)) { - BUG_ON(!nfrags); + if (unlikely(!nfrags)) { + DEBUG_NET_WARN_ON_ONCE(1); + err = -EINVAL; + goto err; + } } else { - BUG_ON(!list_skb->head_frag); + if (unlikely(!list_skb->head_frag)) { + DEBUG_NET_WARN_ON_ONCE(1); + err = -EINVAL; + goto err; + } /* to make room for head_frag. */ i--; From 279877d86c8294c7d2f7a51ca755de79659af215 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:02 +0000 Subject: [PATCH 1797/2126] net: skbuff: don't BUG() when skb_copy_bits() fails in copy helpers skb_copy(), skb_copy_expand() and skb_try_coalesce() all BUG() if skb_copy_bits() fails. skb_copy_bits() only fails when the skb's lengths don't add up, which is a bug somewhere else, usually in a driver building the skb. Each of these functions already has a failure return its callers handle: - skb_copy() and skb_copy_expand() free the new skb and return NULL, as they do when the allocation fails. - skb_try_coalesce() returns false and the caller keeps the skbs separate. Copy into the tailroom before skb_put() so that @to is untouched on failure. Take those returns, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. __pskb_pull_tail() has the same BUG_ON(), but several of its callers can't otherwise fail and don't check its return, so it's left for a separate change that fixes them first. Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-3-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index a577217513e8..136d7269c1da 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -2201,7 +2201,12 @@ struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask) /* Set the tail pointer and length */ skb_put(n, skb->len); - BUG_ON(skb_copy_bits(skb, -headerlen, n->head, headerlen + skb->len)); + if (unlikely(skb_copy_bits(skb, -headerlen, n->head, + headerlen + skb->len))) { + DEBUG_NET_WARN_ON_ONCE(1); + kfree_skb(n); + return NULL; + } skb_copy_header(n, skb); return n; @@ -2545,8 +2550,13 @@ struct sk_buff *skb_copy_expand(const struct sk_buff *skb, head_copy_off = newheadroom - head_copy_len; /* Copy the linear header and data. */ - BUG_ON(skb_copy_bits(skb, -head_copy_len, n->head + head_copy_off, - skb->len + head_copy_len)); + if (unlikely(skb_copy_bits(skb, -head_copy_len, + n->head + head_copy_off, + skb->len + head_copy_len))) { + DEBUG_NET_WARN_ON_ONCE(1); + kfree_skb(n); + return NULL; + } skb_copy_header(n, skb); @@ -6245,8 +6255,15 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, return false; if (len <= skb_tailroom(to) && skb_frags_readable(from)) { - if (len) - BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len)); + if (len) { + if (unlikely(skb_copy_bits(from, 0, + skb_tail_pointer(to), + len))) { + DEBUG_NET_WARN_ON_ONCE(1); + return false; + } + skb_put(to, len); + } *delta_truesize = 0; return true; } From 20ddd0fd2fcd1c7bb9bac9eb8d88e795a37de74c Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:03 +0000 Subject: [PATCH 1798/2126] net: skbuff: don't BUG() on leftover length in skb_checksum() and friends skb_checksum(), skb_crc32c() and __skb_to_sgvec() walk the head, frags and frag_list and BUG() if they run out of skb before they run out of @len. By then nothing has been read past the end of the skb. The walk stopped at the end of the data, and the check only tells us the caller asked for a range the skb doesn't have. commit 06a0afcfe2f5 ("xfrm: do pskb_pull properly in __xfrm_transport_prep") fixed one such caller that crashed in __skb_to_sgvec(). Return what each function already returns when it can't do the work, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels: - __skb_to_sgvec() returns -EINVAL. Every skb_to_sgvec() caller has checked for a negative return since it learned to return -EMSGSIZE. - skb_checksum() and skb_crc32c() return 0, as they already do for unreadable frags. The resulting checksum is wrong, so the packet fails verification on receive or goes out with a bad checksum on transmit, rather than taking the machine down. Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-4-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 136d7269c1da..536e0bb934f2 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3619,7 +3619,10 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, int len, __wsum csum) } start = end; } - BUG_ON(len); + if (unlikely(len)) { + DEBUG_NET_WARN_ON_ONCE(1); + return 0; + } return csum; } @@ -3784,7 +3787,10 @@ u32 skb_crc32c(const struct sk_buff *skb, int offset, int len, u32 crc) } start = end; } - BUG_ON(len); + if (unlikely(len)) { + DEBUG_NET_WARN_ON_ONCE(1); + return 0; + } return crc; } @@ -5347,7 +5353,10 @@ __skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len, } start = end; } - BUG_ON(len); + if (unlikely(len)) { + DEBUG_NET_WARN_ON_ONCE(1); + return -EINVAL; + } return elt; } From 56453199d28f0072a8196fba14b2d702632e2219 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:04 +0000 Subject: [PATCH 1799/2126] net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev() skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer. The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes. Signed-off-by: Josef Bacik Cc: stable? The trailers only have Assisted-by: and Signed-off-by:. No Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-5-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 536e0bb934f2..7f5eecfeddd7 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3981,7 +3981,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to) else csstart = skb_headlen(skb); - BUG_ON(csstart > skb_headlen(skb)); + if (unlikely(csstart < 0 || csstart > skb_headlen(skb) || + (skb->ip_summed == CHECKSUM_PARTIAL && + csstart + skb->csum_offset + sizeof(__sum16) > + skb->len))) { + DEBUG_NET_WARN_ON_ONCE(1); + /* Send the frame without the checksum filled in, or send + * zeroes if we can't even copy it. + */ + if (skb_copy_bits(skb, 0, to, skb->len)) + memset(to, 0, skb->len); + return; + } skb_copy_from_linear_data(skb, to, csstart); From 417261779eab5e2be1cfe60e1018ba9612a410e0 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:05 +0000 Subject: [PATCH 1800/2126] net: skbuff: don't BUG() on leftover length in skb_copy_and_csum_bits() skb_copy_and_csum_bits() has the same check as skb_checksum(): it BUG()s if it runs out of skb before it runs out of @len. This one gets hit: commit 7d63b6712538 ("icmp: guard against too small mtu") and commit f99cd56230f5 ("net: Remove acked SYN flag from packet in the transmit queue correctly") each fixed a crash here from icmp_glue_bits(). It can't just return, though. Its callers copy into a buffer that is about to go out on the wire, an ICMP error quoting the offending packet for example, so bailing out early would send whatever was left in the rest of that buffer. Zero the part of the buffer we didn't fill and return 0, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. As with skb_checksum(), the checksum usually won't match the data, so the receiver will usually drop the packet, but either way it carries nothing it shouldn't. @len is an int, so only zero when it is positive; a negative @len from a broken caller must not turn into a huge memset(). Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-6-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 7f5eecfeddd7..6947649ae9fa 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3717,7 +3717,13 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, } start = end; } - BUG_ON(len); + if (unlikely(len)) { + DEBUG_NET_WARN_ON_ONCE(1); + /* Don't hand the caller a buffer with stale bytes in it. */ + if (len > 0) + memset(to, 0, len); + return 0; + } return csum; } EXPORT_SYMBOL(skb_copy_and_csum_bits); From 433380f5ab8f1b6bd6f10284c77c8a8031f68f6e Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:06 +0000 Subject: [PATCH 1801/2126] net: skbuff: don't BUG() on a missing head_frag in skb_zerocopy() skb_zerocopy() BUG()s if @from has no head_frag and the caller passed hlen == 0, meaning the caller didn't ask for the head to be copied and the head can't be referenced as a page either. The check runs before anything is touched, and skb_zerocopy() already documents -EFAULT for bad skb geometry. Return that, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-7-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 6947649ae9fa..c69c3d4cc8f4 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3917,7 +3917,10 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) struct page *page; unsigned int offset; - BUG_ON(!from->head_frag && !hlen); + if (unlikely(!from->head_frag && !hlen)) { + DEBUG_NET_WARN_ON_ONCE(1); + return -EFAULT; + } /* dont bother with small payloads */ if (len <= skb_tailroom(to)) From e6974aad4bd7561ed2f1ee56acaee38e3d3c5d01 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 7 Oct 2026 17:36:07 +0000 Subject: [PATCH 1802/2126] net: skbuff: remove the BUG_ON()s from skb_shift() skb_shift() has two BUG_ON()s. The first fires if the caller asks to shift more than @skb holds. Nothing has been touched yet, and returning 0 already means "shifted nothing", which the TCP callers handle by falling back. Return 0, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The second fires if the frags run out before @shiftlen does, but it only checks after the shift has been committed to both skbs, when there's nothing left to back out to. The loop that builds the new frag layout only writes @tgt's frag slots past its nr_frags, and the one branch that modifies @skb's frags also finishes the shift. So if the loop ends with bytes still left to shift, nothing visible has changed yet. That's the same state the MAX_SKB_FRAGS bail-out inside the loop returns 0 from. Move the check up to just before the commit and return 0 there the same way. Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261007-b4-skbuff-bug-on-v2-8-b9a5f732895b@toxicpanda.com Signed-off-by: Jakub Kicinski --- net/core/skbuff.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c69c3d4cc8f4..93c2f440b9ec 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4335,7 +4335,10 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) int from, to, merge, todo; skb_frag_t *fragfrom, *fragto; - BUG_ON(shiftlen > skb->len); + if (unlikely(shiftlen > skb->len)) { + DEBUG_NET_WARN_ON_ONCE(1); + return 0; + } if (skb_headlen(skb)) return 0; @@ -4415,6 +4418,14 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) } } + /* The frags ran out before shiftlen did. Nothing has been committed + * yet, so back out. + */ + if (unlikely(todo > 0)) { + DEBUG_NET_WARN_ON_ONCE(1); + return 0; + } + /* Ready to "commit" this state change to tgt */ skb_shinfo(tgt)->nr_frags = to; @@ -4432,8 +4443,6 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) skb_shinfo(skb)->frags[to++] = skb_shinfo(skb)->frags[from++]; skb_shinfo(skb)->nr_frags = to; - BUG_ON(todo > 0 && !skb_shinfo(skb)->nr_frags); - onlymerged: /* Most likely the tgt won't ever need its checksum anymore, skb on * the other hand might need it if it needs to be resent From 50f2103fce43922b6e562937b2d2fc62089ff7ec Mon Sep 17 00:00:00 2001 From: Henry Martin Date: Mon, 12 Oct 2026 10:53:36 +0800 Subject: [PATCH 1803/2126] rds: fix out-of-bounds conn_path walks via handshake exthdrs Both the lane and the connection-generation negotiation are driven by extension headers in handshake packets, and both are processed unconditionally, even on transports that are not multipath capable. A non-MP connection (t_mp_capable unset) owns exactly one rds_conn_path slot, so a peer claiming up to RDS_MPATH_WORKERS lanes makes every subsequent fan-out walk conn->c_path[0..7] at 504-byte strides past the single allocated slot (KASAN: "Read of size 8 in rds_conn_path_connect_if_down"); the generation negotiation opens a similar out-of-bounds walk on the same array. Only process handshake extension headers when the connection's transport is multipath capable, so a peer can never make us walk lanes that do not exist. Both call sites in rds_recv_incoming() are gated. This is a port of the Oracle UEK fix for the same issue, picked up where Paula's series of the same change left off. This issue was discovered by Tencent CodeBuddy Security. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/netdev/20260825120132.51636-1-pamoutafpro@gmail.com/ Link: https://github.com/oracle/linux-uek/commit/2fdeb0513f18 Fixes: 840df162b3eb ("rds: reduce memory footprint for RDS when transport is RDMA") Fixes: 905dd4184e07 ("RDS: TCP: Track peer's connection generation number") Signed-off-by: Henry Martin Reviewed-by: Allison Henderson Link: https://patch.msgid.link/20261012025336.54756-1-bsdhenrymartin@gmail.com Signed-off-by: Jakub Kicinski --- net/rds/recv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/rds/recv.c b/net/rds/recv.c index 6204e577a90a..93ee4546ae36 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -379,7 +379,8 @@ void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr, rds_stats_inc(s_recv_ping); rds_send_pong(cp, inc->i_hdr.h_sport); /* if this is a handshake ping, start multipath if necessary */ - if (RDS_HS_PROBE(be16_to_cpu(inc->i_hdr.h_sport), + if (conn->c_trans->t_mp_capable && + RDS_HS_PROBE(be16_to_cpu(inc->i_hdr.h_sport), be16_to_cpu(inc->i_hdr.h_dport))) { rds_recv_hs_exthdrs(&inc->i_hdr, cp->cp_conn); rds_start_mprds(cp->cp_conn); @@ -387,7 +388,8 @@ void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr, goto out; } - if (be16_to_cpu(inc->i_hdr.h_dport) == RDS_FLAG_PROBE_PORT && + if (conn->c_trans->t_mp_capable && + be16_to_cpu(inc->i_hdr.h_dport) == RDS_FLAG_PROBE_PORT && inc->i_hdr.h_sport == 0) { rds_recv_hs_exthdrs(&inc->i_hdr, cp->cp_conn); /* if this is a handshake pong, start multipath if necessary */ From ad17ad50b8dca77bba25f0e9bc979e9cdedefff7 Mon Sep 17 00:00:00 2001 From: Binbin Deng <18983559317@163.com> Date: Sat, 10 Oct 2026 11:21:15 +0800 Subject: [PATCH 1804/2126] net: mlx5e: Fix use-after-free of the MACsec xarray entry on RX SC deletion In macsec_del_rxsc_ctx(), the RX secure channel is torn down with: list_del_rcu(&rx_sc->rx_sc_list_element); xa_erase(&macsec->sc_xarray, rx_sc->sc_xarray_element->fs_id); dst_release(&rx_sc->md_dst->dst); kfree(rx_sc->sc_xarray_element); kfree_rcu_mightsleep(rx_sc); The comment above the sequence claims that "xa_erase which uses rcu to sync" hides the RX SC from the data path, but this is not sufficient: the RCU protection of xarray covers only its internal nodes (making xa_load() safe against concurrent erase); it does not extend to the object pointed to by the entry value. A reader that has already obtained the pointer from xa_load() is not covered by any grace period, and the bare kfree() releases the entry object immediately. The reader is mlx5e_macsec_offload_handle_rx_skb() in the NAPI RX path, which runs under rcu_read_lock() only: sc_xarray_element = xa_load(&macsec->sc_xarray, fs_id); rx_sc = sc_xarray_element ? sc_xarray_element->rx_sc : NULL; An RCU read-side critical section protects only against deferred frees (call_rcu()/kfree_rcu()); it provides no protection against the immediate kfree() above. If the NAPI reader loads the entry pointer and is then delayed while another CPU executes the deletion path, the subsequent read of sc_xarray_element->rx_sc dereferences freed memory. The path is reachable with CAP_NET_ADMIN while an RX SC has in-flight traffic: CQEs carrying the fs_id metadata can still arrive after the offload rule has been removed, so deleting an RX SC concurrently with reception can race the reader. Note that the same function already releases rx_sc itself via kfree_rcu_mightsleep(): the author was aware that this teardown needs a deferred free, but the intermediate entry object was missed. Fix this by adding an rcu_head to the entry object and releasing it with kfree_rcu(). Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: b7c9400cbc48 ("net/mlx5e: Implement MACsec Rx data path using MACsec skb_metadata_dst") Signed-off-by: Binbin Deng <18983559317@163.com> Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261010032115.93545-1-18983559317@163.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c index 38a3415acf7a..13896e9c1d33 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c @@ -75,6 +75,7 @@ struct mlx5e_macsec_rx_sc; struct mlx5e_macsec_rx_sc_xarray_element { u32 fs_id; struct mlx5e_macsec_rx_sc *rx_sc; + struct rcu_head rcu_head; }; struct mlx5e_macsec_rx_sc { @@ -839,7 +840,7 @@ static void macsec_del_rxsc_ctx(struct mlx5e_macsec *macsec, struct mlx5e_macsec list_del_rcu(&rx_sc->rx_sc_list_element); xa_erase(&macsec->sc_xarray, rx_sc->sc_xarray_element->fs_id); dst_release(&rx_sc->md_dst->dst); - kfree(rx_sc->sc_xarray_element); + kfree_rcu(rx_sc->sc_xarray_element, rcu_head); kfree_rcu_mightsleep(rx_sc); } From 94d51c59f0a872c57cb8daa1964ec033d77a79fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= Date: Thu, 8 Oct 2026 08:06:26 +0000 Subject: [PATCH 1805/2126] macsec: prevent AES-GCM nonce reuse after packet number wrap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After allocating the last valid packet number, MACsec wraps next_pn to zero and deactivates the transmit SA. This happens for both 32- and 64-bit types of packet numbers (at values 0xffffffff and 0xffffffffffffffff, respectively). TX packets that were still getting processed during deactivation keep being processed and then receive packet numbers. The first gets 0 and is correctly dropped, but next_pn is incremented to 1, which makes the next packet take number 1. It then does not get dropped and may induce a reuse of the AES-GCM nonce corresponding to value 1. This race affects TX packets that have already passed the SA activity check: packets that observe the inactive SA are correctly dropped. Reactivating the SA after PN wrap without a packet number can also cause nonce reuse. Keep next_pn at 0 after wrap, even if the SA is reactivated, so further packet number allocations return 0 and the corresponding packets are dropped. Fixes: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver") Signed-off-by: Jérémy Jean Link: https://patch.msgid.link/20261008080625.360063-2-Jeremy.Jean@oss.cyber.gouv.fr Signed-off-by: Jakub Kicinski --- drivers/net/macsec.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 409fd855235b..e435681447fb 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -487,6 +487,9 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa, spin_lock_bh(&tx_sa->lock); pn = tx_sa->next_pn_halves; + if (unlikely(pn.full64 == 0)) + goto out; + if (secy->xpn) tx_sa->next_pn++; else @@ -494,6 +497,8 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa, if (tx_sa->next_pn == 0) __macsec_pn_wrapped(secy, tx_sa); + +out: spin_unlock_bh(&tx_sa->lock); return pn; From 1202140b297e7f20481c6ff46f5d98e1295e20e6 Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 01:59:30 +0800 Subject: [PATCH 1806/2126] dt-bindings: net: motorcomm: Add YT861x PHY compatible The YT861x GbE PHYs integrated in YT921x switches honour the "motorcomm,auto-sleep-disabled" device property like the other Motorcomm PHYs. Add ethernet-phy-id01e0.4281. Signed-off-by: David Yang Acked-by: Conor Dooley Link: https://patch.msgid.link/20261009175936.428256-2-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml b/Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml index 26688e2302ea..85d01690c856 100644 --- a/Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml +++ b/Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml @@ -15,6 +15,7 @@ allOf: properties: compatible: enum: + - ethernet-phy-id01e0.4281 - ethernet-phy-id4f51.e91a - ethernet-phy-id4f51.e91b From ae0c7e8d0babb4d7b3935985a4ab2611de765ed5 Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 01:59:31 +0800 Subject: [PATCH 1807/2126] net: phy: motorcomm: Add driver entry for internal YT861x PHYs The YT921x switches integrate GbE PHYs of the YT861x family on the switch-internal MDIO bus exposed by the yt921x DSA driver. Add a driver entry for them. The PHY ID 0x01e04281 is live captured from the switch-internal MDIO bus. The switch SerDes PCS does follow the pattern, 0x4f51e899, though. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261009175936.428256-3-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/Kconfig | 3 ++- drivers/net/phy/motorcomm.c | 39 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index d3835597e379..30e9d22c8d1a 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -363,7 +363,8 @@ config MOTORCOMM_PHY tristate "Motorcomm PHYs" help Enables support for Motorcomm network PHYs. - Currently supports YT85xx Gigabit Ethernet PHYs. + Currently supports YT85xx Gigabit Ethernet PHYs, YT861x PHYs + integrated in YT921x switches, and YT8821 2.5Gbps PHYs. config NATIONAL_PHY tristate "National Semiconductor PHYs" diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index 90a4f86f2758..7078c4a0225d 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Motorcomm 8511/8521/8522/8531/8531S/8821 PHY driver. + * Motorcomm 8511/8521/8522/8531/8531S/861x/8821 PHY driver. * * Author: Peter Geis * Author: Frank @@ -18,6 +18,8 @@ #define PHY_ID_YT8522 0x4f51e928 #define PHY_ID_YT8531 0x4f51e91b #define PHY_ID_YT8531S 0x4f51e91a +/* Live captured from YT921x switch internal MDIO bus */ +#define PHY_ID_INT861X 0x01e04281 #define PHY_ID_YT8821 0x4f51ea19 /* YT8521/YT8531S/YT8821 Register Overview * UTP Register space | FIBER Register space @@ -2538,6 +2540,29 @@ static int yt8521_get_features(struct phy_device *phydev) return ret; } +/** + * yt861x_config_init() - apply the auto sleep setting to the PHY + * @phydev: a pointer to a &struct phy_device + * + * Auto sleep is enabled by default and a BMCR soft reset does not restore it, + * so apply the setting from config_init. It can be disabled with the + * "motorcomm,auto-sleep-disabled" device property. + * + * Returns: 0 or negative errno code + */ +static int yt861x_config_init(struct phy_device *phydev) +{ + bool sleep; + + sleep = !device_property_read_bool(&phydev->mdio.dev, + "motorcomm,auto-sleep-disabled"); + + return ytphy_modify_ext_with_lock(phydev, + YT8521_EXTREG_SLEEP_CONTROL1_REG, + YT8521_ESC1R_SLEEP_SW, + sleep ? YT8521_ESC1R_SLEEP_SW : 0); +} + /** * yt8821_get_features - read mmd register to get 2.5G capability * @phydev: target phy_device struct @@ -3173,6 +3198,15 @@ static struct phy_driver motorcomm_phy_drvs[] = { .suspend = yt8521_suspend, .resume = yt8521_resume, }, + { + PHY_ID_MATCH_EXACT(PHY_ID_INT861X), + .name = "YT861x Internal Gigabit Ethernet", + .flags = PHY_IS_INTERNAL, + .config_init = yt861x_config_init, + .soft_reset = genphy_soft_reset, + .suspend = genphy_suspend, + .resume = genphy_resume, + }, { PHY_ID_MATCH_EXACT(PHY_ID_YT8821), .name = "YT8821 2.5Gbps PHY", @@ -3194,7 +3228,7 @@ static struct phy_driver motorcomm_phy_drvs[] = { module_phy_driver(motorcomm_phy_drvs); -MODULE_DESCRIPTION("Motorcomm 8511/8521/8531/8531S/8821 PHY driver"); +MODULE_DESCRIPTION("Motorcomm 8511/8521/8531/8531S/861x/8821 PHY driver"); MODULE_AUTHOR("Peter Geis"); MODULE_AUTHOR("Frank"); MODULE_LICENSE("GPL"); @@ -3205,6 +3239,7 @@ static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = { { PHY_ID_MATCH_EXACT(PHY_ID_YT8522) }, { PHY_ID_MATCH_EXACT(PHY_ID_YT8531) }, { PHY_ID_MATCH_EXACT(PHY_ID_YT8531S) }, + { PHY_ID_MATCH_EXACT(PHY_ID_INT861X) }, { PHY_ID_MATCH_EXACT(PHY_ID_YT8821) }, { /* sentinel */ } }; From fc697291ad0a49e19bab683b95dc3d9592223926 Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 01:59:32 +0800 Subject: [PATCH 1808/2126] net: phy: motorcomm: Add cable test support for internal YT861x PHYs Add TDR cable test support for the internal YT861x PHYs, reporting the per-pair result and the fault length. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261009175936.428256-4-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/motorcomm.c | 113 ++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index 7078c4a0225d..463e1ea3efc9 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -300,6 +301,19 @@ #define YT8531_SCR_CLK_SRC_REF_25M 4 #define YT8531_SCR_CLK_SRC_SSC_25M 5 +/* TDR (cable diagnostic) test control */ +#define YT861X_TDR_CTRL_REG 0x80 +#define YT861X_TDR_CTRL_START BIT(0) + +#define YT861X_TDR_STATUS_REG 0x84 +#define YT861X_TDR_STATUS_BUSY BIT(15) +#define YT861X_TDR_STATUS_PAIR_OK 0 +#define YT861X_TDR_STATUS_PAIR_UNKNOWN 1 +#define YT861X_TDR_STATUS_PAIR_SHORT 2 +#define YT861X_TDR_STATUS_PAIR_OPEN 3 + +#define YT861X_TDR_PAIR_LENGTH_REG(n) (0x87 + (n)) /* in cm */ + #define YT8821_SDS_EXT_CSR_CTRL_REG 0x23 #define YT8821_SDS_EXT_CSR_VCO_LDO_EN BIT(15) #define YT8821_SDS_EXT_CSR_VCO_BIAS_LPF_EN BIT(8) @@ -2563,6 +2577,103 @@ static int yt861x_config_init(struct phy_device *phydev) sleep ? YT8521_ESC1R_SLEEP_SW : 0); } +/** + * yt861x_cable_test_start() - start a cable diagnostic (TDR) test + * @phydev: a pointer to a &struct phy_device + * + * Returns: 0 or negative errno code + */ +static int yt861x_cable_test_start(struct phy_device *phydev) +{ + int ret; + + /* auto sleep would abort the TDR test */ + ret = ytphy_modify_ext_with_lock(phydev, + YT8521_EXTREG_SLEEP_CONTROL1_REG, + YT8521_ESC1R_SLEEP_SW, 0); + if (ret) + return ret; + + ret = ytphy_write_ext_with_lock(phydev, YT861X_TDR_CTRL_REG, + YT861X_TDR_CTRL_START); + if (ret) { + int err = yt861x_config_init(phydev); + + if (err) + phydev_warn(phydev, + "Failed to restore auto sleep: %d\n", + err); + } + + return ret; +} + +/** + * yt861x_cable_test_get_status() - report cable diagnostic test results + * @phydev: a pointer to a &struct phy_device + * @finished: set to true when the test is complete + * + * Returns: 0 or negative errno code + */ +static int yt861x_cable_test_get_status(struct phy_device *phydev, + bool *finished) +{ + int status; + int ret; + + *finished = false; + + status = ytphy_read_ext_with_lock(phydev, YT861X_TDR_STATUS_REG); + if (status < 0) + return status; + + if (status & YT861X_TDR_STATUS_BUSY) + return 0; + + for (int pair = ETHTOOL_A_CABLE_PAIR_A; pair <= ETHTOOL_A_CABLE_PAIR_D; + pair++) { + u8 code; + + switch ((status >> (2 * pair)) & 0x3) { + case YT861X_TDR_STATUS_PAIR_OK: + code = ETHTOOL_A_CABLE_RESULT_CODE_OK; + break; + case YT861X_TDR_STATUS_PAIR_SHORT: + code = ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; + break; + case YT861X_TDR_STATUS_PAIR_OPEN: + code = ETHTOOL_A_CABLE_RESULT_CODE_OPEN; + break; + default: + code = ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; + } + + ethnl_cable_test_result(phydev, pair, code); + + if (code != ETHTOOL_A_CABLE_RESULT_CODE_OK && + code != ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC) { + ret = ytphy_read_ext_with_lock(phydev, + YT861X_TDR_PAIR_LENGTH_REG(pair)); + if (ret >= 0) + ethnl_cable_test_fault_length(phydev, pair, + ret); + } + } + + /* the reset below does not restore auto sleep by itself */ + ret = yt861x_config_init(phydev); + if (ret) + return ret; + + ret = genphy_soft_reset(phydev); + if (ret) + return ret; + + *finished = true; + + return 0; +} + /** * yt8821_get_features - read mmd register to get 2.5G capability * @phydev: target phy_device struct @@ -3206,6 +3317,8 @@ static struct phy_driver motorcomm_phy_drvs[] = { .soft_reset = genphy_soft_reset, .suspend = genphy_suspend, .resume = genphy_resume, + .cable_test_start = yt861x_cable_test_start, + .cable_test_get_status = yt861x_cable_test_get_status, }, { PHY_ID_MATCH_EXACT(PHY_ID_YT8821), From c71d33e31b0e261d1bfb3ab1a2f909ed560156e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= Date: Wed, 7 Oct 2026 20:12:37 +0000 Subject: [PATCH 1809/2126] mpls: unregister sysctls before network device teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On network namespace exit, loopback is freed before MPLS unregisters its sysctls. A task can keep platform_labels open and write to it during exit. The handler can then use the freed loopback device. Unregister the sysctls in pre_exit. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: 7720c01f3f59 ("mpls: Add a sysctl to control the size of the mpls label table") Signed-off-by: Jérémy Jean Link: https://patch.msgid.link/20261007201237.171863-2-Jeremy.Jean@oss.cyber.gouv.fr Signed-off-by: Jakub Kicinski --- net/mpls/af_mpls.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c index 17b78dcbf8ab..ad4ad6f2001a 100644 --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -2776,16 +2776,20 @@ static __net_init int mpls_net_init(struct net *net) return 0; } -static __net_exit void mpls_net_exit(struct net *net) +static __net_exit void mpls_net_pre_exit(struct net *net) { - struct mpls_route __rcu **platform_label; - size_t platform_labels; const struct ctl_table *table; - unsigned int index; table = net->mpls.ctl->ctl_table_arg; unregister_net_sysctl_table(net->mpls.ctl); kfree(table); +} + +static __net_exit void mpls_net_exit(struct net *net) +{ + struct mpls_route __rcu **platform_label; + size_t platform_labels; + unsigned int index; /* An rcu grace period has passed since there was a device in * the network namespace (and thus the last in flight packet) @@ -2816,6 +2820,7 @@ static __net_exit void mpls_net_exit(struct net *net) static struct pernet_operations mpls_net_ops = { .init = mpls_net_init, + .pre_exit = mpls_net_pre_exit, .exit = mpls_net_exit, }; From 393acb51d048087ca82a66ecfd6449575a7eb2db Mon Sep 17 00:00:00 2001 From: Cosmin Ratiu Date: Sun, 11 Oct 2026 12:07:39 +0300 Subject: [PATCH 1810/2126] devlink: Fix accidental rebase error in nested devlink docs The referenced "Fixes" commit accidentally reverted a correction introduced in commit [1]. Revert that mistake. [1] commit e504cf18ef47 ("docs: net: fix minor issues with devlink docs") Fixes: 3bf4c5970ca8 ("devlink: Update nested instance locking comment") Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan Reviewed-by: Joe Damato Link: https://patch.msgid.link/20261011090739.746757-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- Documentation/networking/devlink/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst index 1af780c811ee..03f49389a755 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -33,8 +33,8 @@ sure to respect following rules: lock of both nested and parent instances at the same time, devlink instance lock of the nested instance should be taken first, only then instance lock of the parent instance could be taken. - - Driver should use object-specific helpers to setup the - nested relationship: + - Driver should use object-specific helpers to setup the nested relationship + before registering the nested devlink instance: - ``devl_nested_devlink_set()`` - called to setup devlink -> nested devlink relationship (could be used for multiple nested instances). From cdcb648a97ebc247eea3a9a7d15916613f640527 Mon Sep 17 00:00:00 2001 From: Alexei Lazar Date: Sun, 11 Oct 2026 12:31:00 +0300 Subject: [PATCH 1811/2126] net/mlx5e: Rename state_destroy to rx_mode_active in flow steering This flag controls the enablement of RX mode handling (promisc, allmulti, broadcast, netdev addr sync). It acts as a safeguard that prevents new FS (flow steering) operations during device teardown. When the device is in destroying state it is set to false to indicate RX mode operations are not allowed. Its name is misleading, as it suggests a destroy-state flag rather than RX mode activity. Rename it for clarity. No functional change. Signed-off-by: Alexei Lazar Reviewed-by: Shahar Shitrit Signed-off-by: Tariq Toukan Reviewed-by: Joe Damato Link: https://patch.msgid.link/20261011093100.769149-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en/fs.h | 5 +++-- drivers/net/ethernet/mellanox/mlx5/core/en_fs.c | 17 +++++++++-------- .../net/ethernet/mellanox/mlx5/core/en_main.c | 15 +++++++++------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h index 4973fb473ff0..aa370227b7bc 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h @@ -158,7 +158,7 @@ void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple, struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile, struct mlx5_core_dev *mdev, - bool state_destroy, + bool rx_mode_active, struct dentry *dfs_root); void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs); struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs); @@ -198,7 +198,8 @@ void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp); struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs); void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp); #endif -void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy); +void mlx5e_fs_set_rx_mode_active(struct mlx5e_flow_steering *fs, + bool rx_mode_active); void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, bool vlan_strip_disable); struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c index 12492c4a5d41..c19238bc821f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c @@ -44,7 +44,7 @@ struct mlx5e_flow_steering { struct work_struct set_rx_mode_work; - bool state_destroy; + bool rx_mode_active; bool vlan_strip_disable; struct mlx5_core_dev *mdev; struct mlx5_flow_namespace *ns; @@ -560,7 +560,7 @@ static void mlx5e_del_vlan_rules(struct mlx5e_flow_steering *fs) for_each_set_bit(i, fs->vlan->active_svlans, VLAN_N_VID) mlx5e_fs_del_vlan_rule(fs, MLX5E_VLAN_RULE_TYPE_MATCH_STAG_VID, i); - WARN_ON_ONCE(fs->state_destroy); + WARN_ON_ONCE(fs->rx_mode_active); mlx5e_remove_vlan_trap(fs); @@ -743,7 +743,7 @@ static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs, mlx5e_for_each_hash_node(hn, tmp, fs->l2.netdev_mc, i) hn->action = MLX5E_ACTION_DEL; - if (fs->state_destroy) + if (fs->rx_mode_active) mlx5e_sync_netdev_addr(fs, netdev, uc, mc); mlx5e_apply_netdev_addr(fs); @@ -840,7 +840,7 @@ void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, goto update_vport_context; } - bool rx_mode_enable = fs->state_destroy; + bool rx_mode_enable = fs->rx_mode_active; bool promisc_enabled = rx_mode_enable && (netdev->flags & IFF_PROMISC); bool allmulti_enabled = rx_mode_enable && (netdev->flags & IFF_ALLMULTI); bool broadcast_enabled = rx_mode_enable; @@ -1479,7 +1479,7 @@ static void mlx5e_fs_debugfs_init(struct mlx5e_flow_steering *fs, struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile, struct mlx5_core_dev *mdev, - bool state_destroy, + bool rx_mode_active, struct dentry *dfs_root) { struct mlx5e_flow_steering *fs; @@ -1490,7 +1490,7 @@ struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile, goto err; fs->mdev = mdev; - fs->state_destroy = state_destroy; + fs->rx_mode_active = rx_mode_active; if (mlx5e_profile_feature_cap(profile, FS_VLAN)) { err = mlx5e_fs_vlan_alloc(fs); if (err) @@ -1606,9 +1606,10 @@ void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_f } #endif -void mlx5e_fs_set_state_destroy(struct mlx5e_flow_steering *fs, bool state_destroy) +void mlx5e_fs_set_rx_mode_active(struct mlx5e_flow_steering *fs, + bool rx_mode_active) { - fs->state_destroy = state_destroy; + fs->rx_mode_active = rx_mode_active; } void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index f90b5a34e097..478b5956044b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -6557,8 +6557,9 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) clear_bit(MLX5E_STATE_DESTROYING, &priv->state); if (priv->fs) - mlx5e_fs_set_state_destroy(priv->fs, - !test_bit(MLX5E_STATE_DESTROYING, &priv->state)); + mlx5e_fs_set_rx_mode_active(priv->fs, + !test_bit(MLX5E_STATE_DESTROYING, + &priv->state)); /* Validate the max_wqe_size_sq capability. */ if (WARN_ON_ONCE(mlx5e_get_max_sq_wqebbs(priv->mdev) < MLX5E_MAX_TX_WQEBBS)) { @@ -6638,8 +6639,9 @@ out: mlx5e_reset_channels(priv->netdev); set_bit(MLX5E_STATE_DESTROYING, &priv->state); if (priv->fs) - mlx5e_fs_set_state_destroy(priv->fs, - !test_bit(MLX5E_STATE_DESTROYING, &priv->state)); + mlx5e_fs_set_rx_mode_active(priv->fs, + !test_bit(MLX5E_STATE_DESTROYING, + &priv->state)); cancel_work_sync(&priv->update_stats_work); return err; } @@ -6650,8 +6652,9 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv) set_bit(MLX5E_STATE_DESTROYING, &priv->state); if (priv->fs) - mlx5e_fs_set_state_destroy(priv->fs, - !test_bit(MLX5E_STATE_DESTROYING, &priv->state)); + mlx5e_fs_set_rx_mode_active(priv->fs, + !test_bit(MLX5E_STATE_DESTROYING, + &priv->state)); if (profile->disable) profile->disable(priv); From 9272297df14124fe603c81e40b52ff0c5dd88652 Mon Sep 17 00:00:00 2001 From: Stefano Munari Date: Sat, 10 Oct 2026 23:32:48 +0200 Subject: [PATCH 1812/2126] net: usb: lan78xx: reject invalid EEPROM write requests The runtime PM handling removed the -EINVAL return for invalid EEPROM/OTP write requests. These requests now return zero from a successful usb_autopm_get_interface() call, even though no data is written. Set ret to -EINVAL for invalid requests while preserving the runtime PM reference release. Fixes: 8a7ffeb795f8 ("lan78xx: Fix for eeprom read/write when device auto suspend") Signed-off-by: Stefano Munari Reviewed-by: Nicolai Buchwitz Tested-by: Nicolai Buchwitz # Raspberry Pi 3B+ (LAN7515) Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261010213248.15938-1-stefanomunari.sm@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/lan78xx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index babd34cda374..3b92ec5916ad 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1712,13 +1712,16 @@ static int lan78xx_ethtool_set_eeprom(struct net_device *netdev, /* Invalid EEPROM_INDICATOR at offset zero will result in a failure * to load data from EEPROM */ - if (ee->magic == LAN78XX_EEPROM_MAGIC) + if (ee->magic == LAN78XX_EEPROM_MAGIC) { ret = lan78xx_write_raw_eeprom(dev, ee->offset, ee->len, data); - else if ((ee->magic == LAN78XX_OTP_MAGIC) && + } else if ((ee->magic == LAN78XX_OTP_MAGIC) && (ee->offset == 0) && (ee->len == 512) && - (data[0] == OTP_INDICATOR_1)) + (data[0] == OTP_INDICATOR_1)) { ret = lan78xx_write_raw_otp(dev, ee->offset, ee->len, data); + } else { + ret = -EINVAL; + } usb_autopm_put_interface(dev->intf); From ce7db1caaa68f5715e62a69cd84ed89813cea99f Mon Sep 17 00:00:00 2001 From: Konstantin Meshkov Date: Sat, 10 Oct 2026 21:35:37 +0300 Subject: [PATCH 1813/2126] net: phy: marvell: add LED support for 88E1116R PHY The Marvell 88E1116R PHY (used on the D-Link DNS-325) exposes its LEDs through the same page 3 register 0x10 LED control layout as the 88E1318S. Wire up the existing 88E1318S LED handlers in the 88E1116R driver entry so the PHY LEDs can be described in the device tree and driven through the LED trigger API with hardware offload. Tested on a D-Link DNS-325 (88E1116R): both PHY LEDs are registered and hardware-offloaded. Signed-off-by: Konstantin Meshkov Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/179165733751.2921261.13784246298385245617@mail.ru Signed-off-by: Jakub Kicinski --- drivers/net/phy/marvell.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index f71cffa88406..244454f54417 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -3913,6 +3913,11 @@ static struct phy_driver marvell_drivers[] = { .get_stats = marvell_get_stats, .get_tunable = m88e1011_get_tunable, .set_tunable = m88e1011_set_tunable, + .led_brightness_set = m88e1318_led_brightness_set, + .led_blink_set = m88e1318_led_blink_set, + .led_hw_is_supported = m88e1318_led_hw_is_supported, + .led_hw_control_set = m88e1318_led_hw_control_set, + .led_hw_control_get = m88e1318_led_hw_control_get, }, { .phy_id = MARVELL_PHY_ID_88E1510, From 109b08f37639dc29d7545229eccc07ff47fcb724 Mon Sep 17 00:00:00 2001 From: Tianyi Gao Date: Sat, 10 Oct 2026 20:29:14 +0100 Subject: [PATCH 1814/2126] selftests: net: veth: test own ndo-xmit after peer GRO toggle while down Test that a veth device advertises ndo-xmit when GRO is enabled on its peer while both are down and only the device is brought up. Commit 7a6102aa6df0 ("veth: Update XDP feature set when bringing up device") made veth_open() set the flag in this case, and selftests were requested in its review [1]. The block now ends with GRO enabled while the peer is down, so the aggregation check that follows covers NAPI enabled by veth_open() again. Commit c017800af5c7 ("selftests: net: veth: test peer ndo-xmit after GRO toggle while down") had moved it to veth_set_features() [2]. Link: https://lore.kernel.org/all/155aabf8b873bb8cdcafbd6139c42b08513e5fe6.camel@redhat.com/ [1] Link: https://lore.kernel.org/all/179165459278.434549.1711113374323842550@kernel.org/ [2] Signed-off-by: Tianyi Gao Reviewed-by: Narcisa Vasile Link: https://patch.msgid.link/20261010192914.83651-1-tianyi@cloudflare.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/veth.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh index 8b867e0675a7..60d0754928bf 100755 --- a/tools/testing/selftests/net/veth.sh +++ b/tools/testing/selftests/net/veth.sh @@ -327,7 +327,12 @@ if [ -f "$YNL" ]; then ip netns exec $NS_DST ethtool -K veth$DST gro off ip -n $NS_DST link set dev veth$DST up chk_xdp_feature " - peer ndo-xmit cleared" $SRC 0 ndo-xmit + ip -n $NS_SRC link set dev veth$SRC down + ip -n $NS_DST link set dev veth$DST down ip netns exec $NS_DST ethtool -K veth$DST gro on + ip -n $NS_SRC link set dev veth$SRC up + chk_xdp_feature " - own ndo-xmit" $SRC 1 ndo-xmit + ip -n $NS_DST link set dev veth$DST up fi ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on From 4fc1d5bb448dfab391a96f949d02ad03ad8cda5c Mon Sep 17 00:00:00 2001 From: George Melikov Date: Fri, 9 Oct 2026 20:30:18 +0300 Subject: [PATCH 1815/2126] bnx2x: fix header length calculation for encapsulated TSO Commit 80bfab79b835 ("net: adopt skb_network_offset() and similar helpers") replaced the difference between the inner transport header and the outer network header with skb_inner_transport_offset(). The helper is relative to skb->data, so the new calculation incorrectly includes the outer Ethernet header in fw_ip_hdr_to_payload_w. On a BCM57810 transmitting TCP over VXLAN with an outer MTU of 1500, hardware segmentation emits packets declaring an outer IPv4 total length of 1514 while the actual IP packet is only 1500 bytes long. The receiver drops these malformed packets, severely degrading TCP connectivity. Subtract skb_network_offset() to restore the original calculation of the length from the outer network header to the inner TCP payload. Reproduced with plain kernel VXLAN and one TCP flow on kernel 7.0.0-31-generic: 50 of 200 captured packets had an invalid outer IP length with the original driver, versus none with this fix. Disabling TSO/GSO on the test VXLAN device also eliminated the error with the original driver. Fixes: 80bfab79b835 ("net: adopt skb_network_offset() and similar helpers") Signed-off-by: George Melikov Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261009-bnx2x-tso-fix-v1-1-1ebea422422d@gmelikov.ru Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c index 5a9742fd3ddf..6fb0619731ae 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c @@ -3666,7 +3666,8 @@ static void bnx2x_update_pbds_gso_enc(struct sk_buff *skb, u8 outerip_off, outerip_len = 0; /* from outer IP to transport */ - hlen_w = skb_inner_transport_offset(skb) >> 1; + hlen_w = (skb_inner_transport_offset(skb) - + skb_network_offset(skb)) >> 1; /* transport len */ hlen_w += inner_tcp_hdrlen(skb) >> 1; From b2039a6dd36b5c89142bfb95bc0205be8abcc600 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 9 Oct 2026 09:49:05 +0200 Subject: [PATCH 1816/2126] ipv4: use RCU protection in inet_netconf_get_devconf() inet_netconf_get_devconf() runs without RTNL. It uses dev_get_by_index() and in_dev_get() to pin the device and its in_device while the reply is allocated and filled. in_dev_get() is not safe for a lockless caller. Since commit 9d40c84cf5bc ("net: devinet: Reduce refcount before grace period"), inetdev_destroy() drops the final reference before the RCU grace period. A reader can load dev->ip_ptr, then call refcount_inc() on a zero refcount after in_dev_free_rcu() has been queued, and keep using the in_device once it has been freed. None of these references are needed. An in_device is freed after an RCU grace period, ipv4_devconf is embedded in it, and inet_netconf_fill_devconf() does not sleep. Allocate the skb first, then perform the lookup and the fill under rcu_read_lock(), using dev_get_by_index_rcu() and __in_dev_get_rcu(), like inet_netconf_dump_devconf() already does. Fixes: bbcf91053bb6 ("inet: do not use RTNL in inet_netconf_get_devconf()") Reported-by: Baul Lee Closes: https://lore.kernel.org/netdev/20260815172032.79740-1-baul.lee@xbow.com/ Signed-off-by: Eric Dumazet Tested-by: Cen Zhang Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/CAAVpQUA5FEMWV1R4vy2+uzQc+_iLDaz4m-D6kfKYngGf2sE0Eg@mail.gmail.com Link: https://patch.msgid.link/20261009074906.729877-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ipv4/devinet.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 5b6b11c943e4..f9a361621f74 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2379,8 +2379,8 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, struct net *net = sock_net(in_skb->sk); struct nlattr *tb[NETCONFA_MAX + 1]; const struct ipv4_devconf *devconf; - struct in_device *in_dev = NULL; - struct net_device *dev = NULL; + struct in_device *in_dev; + struct net_device *dev; struct sk_buff *skb; int ifindex; int err; @@ -2392,7 +2392,13 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, if (!tb[NETCONFA_IFINDEX]) return -EINVAL; + skb = nlmsg_new(inet_netconf_msgsize_devconf(NETCONFA_ALL), GFP_KERNEL); + if (!skb) + return -ENOBUFS; + ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]); + + rcu_read_lock(); switch (ifindex) { case NETCONFA_IFINDEX_ALL: devconf = net->ipv4.devconf_all; @@ -2402,36 +2408,29 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, break; default: err = -ENODEV; - dev = dev_get_by_index(net, ifindex); - if (dev) - in_dev = in_dev_get(dev); + dev = dev_get_by_index_rcu(net, ifindex); + if (!dev) + goto out_unlock; + in_dev = __in_dev_get_rcu(dev); if (!in_dev) - goto errout; + goto out_unlock; devconf = &in_dev->cnf; break; } - err = -ENOBUFS; - skb = nlmsg_new(inet_netconf_msgsize_devconf(NETCONFA_ALL), GFP_KERNEL); - if (!skb) - goto errout; - err = inet_netconf_fill_devconf(skb, ifindex, devconf, NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, RTM_NEWNETCONF, 0, NETCONFA_ALL); +out_unlock: + rcu_read_unlock(); if (err < 0) { /* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ WARN_ON(err == -EMSGSIZE); kfree_skb(skb); - goto errout; + return err; } - err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); -errout: - if (in_dev) - in_dev_put(in_dev); - dev_put(dev); - return err; + return rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); } static int inet_netconf_dump_devconf(struct sk_buff *skb, From 5dfa91a5ec53cfbf907a1fca095ac3ac7a4e94c9 Mon Sep 17 00:00:00 2001 From: Zixuan Chai Date: Fri, 9 Oct 2026 00:52:31 +0800 Subject: [PATCH 1817/2126] ipv6: defrag: orphan skb before queuing IPv4 and nf_conntrack fragment queues orphan skbs before returning -EINPROGRESS, but ip6_frag_queue() leaves the socket association intact. Commit 18685451fc4e ("inet: inet_defrag: prevent sk release while still in use") moved skb_orphan() into ip_frag_queue() and nf_ct_frag6_queue(), but missed ip6_frag_queue(). Without orphaning, inet_frag_reasm_finish() clears fp->sk on frag_list skbs but leaves fp->destructor set to sock_pfree. Freeing the reassembled skb then calls sock_pfree() with a NULL socket. A socket using SOCK_RCU_FREE may also be released while its fragment is queued, leaving a stale socket pointer; this is a second consequence of the same missing orphan. Orphan the skb before returning -EINPROGRESS so the queued fragment no longer retains the socket association or destructor. Fixes: cf7fbe660f2d ("bpf: Add socket assign support") Cc: stable@vger.kernel.org Reported-by: Vega Reviewed-by: Eric Dumazet Reviewed-by: Fernando Fernandez Mancera Signed-off-by: Zixuan Chai Signed-off-by: Ren Wei Link: https://patch.msgid.link/5c396b7011168cd98b9812df4d6bbd00a96048e7.1791008591.git.petalzu987@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/reassembly.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 05c51f669754..a7964125c764 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c @@ -232,6 +232,7 @@ static int ip6_frag_queue(struct net *net, } skb_dst_drop(skb); + skb_orphan(skb); return -EINPROGRESS; insert_error: From 31b564f70d8819a1c11d0fd504fe582fc0e0f0cf Mon Sep 17 00:00:00 2001 From: Theodor Arsenij Larionov Trichkine Date: Mon, 12 Oct 2026 12:10:28 +0200 Subject: [PATCH 1818/2126] net: use the full socket in sk_mc_loop() sk_mc_loop() is called from ip_mc_output() and ip6_finish_output2() with skb->sk, which is not always a full socket: - Since commit ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener"), a SYNACK is attached to its request socket. - Since commit 79636038d37e ("ipv4: tcp: give socket pointer to control skbs"), an ACK or RST sent by ip_send_unicast_reply() on behalf of a TIME_WAIT socket is attached to the timewait socket. When such a packet uses a multicast route, inet_test_bit(MC_LOOP, sk) reads inet_flags past the end of the request or timewait socket. This happens for instance when a SYN with a multicast source address reaches a listener, after being looped back with its dst attached, so that ip_rcv_finish_core() skips the martian source check. A raw IP_HDRINCL socket sending to a local address does this, as does re-injection by nft dup or the iptables TEE target. The destination can also come from a source route option, or from a route of type multicast covering a unicast prefix. BUG: KASAN: slab-out-of-bounds in sk_mc_loop+0x111/0x170 Read of size 8 at addr ffff88800f2b7f10 by task repro-raw/470 Call Trace: sk_mc_loop+0x111/0x170 ip_mc_output+0x355/0x930 ip_build_and_send_pkt+0xb87/0xc50 tcp_v4_send_synack+0x500/0x6f0 tcp_conn_request+0x2135/0x2d90 tcp_v4_conn_request+0xa5/0x210 tcp_rcv_state_process+0x136e/0x6920 tcp_v4_do_rcv+0x339/0xb10 tcp_v4_rcv+0x34ab/0x3ab0 ip_protocol_deliver_rcu+0x6e/0x3e0 ip_local_deliver_finish+0x34d/0x510 ip_local_deliver+0x1bc/0x310 ip_rcv+0x390/0x410 __netif_receive_skb_one_core+0x199/0x1e0 process_backlog+0x239/0x680 __napi_poll+0xb5/0x650 net_rx_action+0x980/0xd60 handle_softirqs+0x17f/0x590 do_softirq+0x3f/0x60 The buggy address belongs to the object at ffff88800f2b7d60 which belongs to the cache request_sock_TCP of size 312 The buggy address is located 120 bytes to the right of allocated 312-byte region [ffff88800f2b7d60, ffff88800f2b7e98) Use sk_const_to_full_sk(), which restores the behavior from before the two commits above: a request socket uses the setting of its listener, and a timewait socket gets the default (loop back), as the per-cpu control socket used before had. Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener") Fixes: 79636038d37e ("ipv4: tcp: give socket pointer to control skbs") Signed-off-by: Theodor Arsenij Larionov Trichkine [edumazet: rewrote the changelog, added the TIME_WAIT case] Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261012101029.927296-2-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/core/sock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/sock.c b/net/core/sock.c index e8551df8330f..1302c1e848b2 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -769,6 +769,7 @@ bool sk_mc_loop(const struct sock *sk) { if (dev_recursion_level()) return false; + sk = sk_const_to_full_sk(sk); if (!sk) return true; /* IPV6_ADDRFORM can change sk->sk_family under us. */ From 54d574d4afd9de820c8a017665c8095f0f5fdbaa Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Mon, 12 Oct 2026 12:10:29 +0200 Subject: [PATCH 1819/2126] tcp: use the echoed source route in cookie_v4_check() When the ACK carries a source route option, cookie_v4_check() routes the new socket to opt->faddr, where opt points to the options of the received packet. ip_options_compile() only fills faddr for options given by setsockopt() (when called without an skb), so on receive faddr is 0 and the lookup is done for daddr 0, which gives a local route. Use the options echoed by tcp_v4_save_options() instead, as inet_csk_route_req() and inet_csk_route_child_sock() do with ireq->ireq_opt. Read them after security_inet_conn_request(), since CIPSO can replace ireq->ireq_opt there. The route now goes to the first hop of the source route, so also refuse a strict source route through a gateway, as inet_csk_route_req() does. Found by sashiko while reviewing the sk_mc_loop() fix. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261012101029.927296-3-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ipv4/syncookies.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 73e129768184..8c9691569e01 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -404,12 +404,12 @@ out: */ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) { - struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt; const struct tcphdr *th = tcp_hdr(skb); struct tcp_sock *tp = tcp_sk(sk); struct inet_request_sock *ireq; struct net *net = sock_net(sk); struct tcp_request_sock *treq; + struct ip_options_rcu *opt; struct request_sock *req; struct sock *ret = sk; struct flowi4 fl4; @@ -449,6 +449,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) SKB_DR_SET(reason, SECURITY_HOOK); goto out_free; } + /* Load ireq->ireq_opt after the LSM hook, which can replace it. */ + opt = rcu_dereference_protected(ireq->ireq_opt, true); tcp_ao_syncookie(sk, skb, req, AF_INET); @@ -461,7 +463,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) flowi4_init_output(&fl4, ireq->ir_iif, ireq->ir_mark, ip_sock_rt_tos(sk), ip_sock_rt_scope(sk), IPPROTO_TCP, inet_sk_flowi_flags(sk), - opt->srr ? opt->faddr : ireq->ir_rmt_addr, + (opt && opt->opt.srr) ? opt->opt.faddr : ireq->ir_rmt_addr, ireq->ir_loc_addr, th->source, th->dest, sk_uid(sk)); security_req_classify_flow(req, flowi4_to_flowi_common(&fl4)); @@ -470,6 +472,12 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) SKB_DR_SET(reason, IP_OUTNOROUTES); goto out_free; } + /* Same check as in inet_csk_route_req(). */ + if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway) { + ip_rt_put(rt); + SKB_DR_SET(reason, IP_OUTNOROUTES); + goto out_free; + } /* Try to redo what tcp_v4_send_synack did. */ req->rsk_window_clamp = READ_ONCE(tp->window_clamp) ? : From 207d1c23945a539a9f89b55b77346a9db82818d4 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Sun, 11 Oct 2026 15:12:10 +0200 Subject: [PATCH 1820/2126] net: dsa: realtek: Remove unused buffer from struct realtek_priv The buffer has never been used. Remove it. Signed-off-by: Thorsten Blum Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20261011131208.272131-3-blum@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/realtek.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 1c0ca6daf545..33f3b4c249fc 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -97,7 +97,6 @@ struct realtek_priv { int vlan_enabled; int vlan4k_enabled; - char buf[4096]; void *chip_data; /* Per-chip extra variant data */ }; From dabe6a847748a714d9a46dc8460f4aba37ce225f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 7 Oct 2026 11:38:21 -0700 Subject: [PATCH 1821/2126] net: emac: mal: replace devm_request_irq with request_irq to fix probe error race devm_request_irq() is a managed resource: the IRQ is not freed until devres_release_all() runs after the probe function returns. In the probe error path, free_netdev(mal->dummy_dev) and dcr_unmap() execute while the IRQ is still live. If the shared IRQ fires during cleanup, the handler accesses unmapped DCR registers (crash) or the already- freed dummy_dev (use-after-free). Switch to plain request_irq() with per-IRQ error labels that tear down only the IRQs that were successfully registered, and add the matching free_irq() calls in mal_remove(). Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: 14f59154ff0b ("net: ibm: emac: mal: use devm for request_irq") Signed-off-by: Rosen Penev Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261007183821.928263-1-rosenp@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/emac/mal.c | 43 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c index 42027665f2a9..236603a381bc 100644 --- a/drivers/net/ethernet/ibm/emac/mal.c +++ b/drivers/net/ethernet/ibm/emac/mal.c @@ -665,26 +665,26 @@ static int mal_probe(struct platform_device *ofdev) hdlr_rxde = mal_rxde; } - err = devm_request_irq(&ofdev->dev, mal->serr_irq, hdlr_serr, irqflags, - "MAL SERR", mal); + err = request_irq(mal->serr_irq, hdlr_serr, irqflags, + "MAL SERR", mal); if (err) goto fail2; - err = devm_request_irq(&ofdev->dev, mal->txde_irq, hdlr_txde, irqflags, - "MAL TX DE", mal); + err = request_irq(mal->txde_irq, hdlr_txde, irqflags, + "MAL TX DE", mal); if (err) - goto fail2; - err = devm_request_irq(&ofdev->dev, mal->txeob_irq, mal_txeob, 0, - "MAL TX EOB", mal); + goto fail_serr_irq; + err = request_irq(mal->txeob_irq, mal_txeob, 0, + "MAL TX EOB", mal); if (err) - goto fail2; - err = devm_request_irq(&ofdev->dev, mal->rxde_irq, hdlr_rxde, irqflags, - "MAL RX DE", mal); + goto fail_txde_irq; + err = request_irq(mal->rxde_irq, hdlr_rxde, irqflags, + "MAL RX DE", mal); if (err) - goto fail2; - err = devm_request_irq(&ofdev->dev, mal->rxeob_irq, mal_rxeob, 0, - "MAL RX EOB", mal); + goto fail_txeob_irq; + err = request_irq(mal->rxeob_irq, mal_rxeob, 0, + "MAL RX EOB", mal); if (err) - goto fail2; + goto fail_rxde_irq; /* Enable all MAL SERR interrupt sources */ set_mal_dcrn(mal, MAL_IER, MAL_IER_EVENTS); @@ -703,6 +703,14 @@ static int mal_probe(struct platform_device *ofdev) return 0; + fail_rxde_irq: + free_irq(mal->rxde_irq, mal); + fail_txeob_irq: + free_irq(mal->txeob_irq, mal); + fail_txde_irq: + free_irq(mal->txde_irq, mal); + fail_serr_irq: + free_irq(mal->serr_irq, mal); fail2: dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma); fail_dummy: @@ -729,6 +737,13 @@ static void mal_remove(struct platform_device *ofdev) mal_reset(mal); + /* Free IRQs before freeing resources they access */ + free_irq(mal->serr_irq, mal); + free_irq(mal->txde_irq, mal); + free_irq(mal->txeob_irq, mal); + free_irq(mal->rxde_irq, mal); + free_irq(mal->rxeob_irq, mal); + free_netdev(mal->dummy_dev); dcr_unmap(mal->dcr_host, 0x100); From 9c7e89fc1b6844757fda56601804109600f6bb61 Mon Sep 17 00:00:00 2001 From: Binbin Deng <18983559317@163.com> Date: Sat, 10 Oct 2026 11:08:20 +0800 Subject: [PATCH 1822/2126] ncsi: Fix use-after-free in the VLAN id list removal ncsi_vlan_rx_kill_vid() removes an entry from the NCSI VLAN list with: list_for_each_entry_safe(vlan, tmp, &ndp->vlan_vids, list) if (vlan->vid == vid) { list_del_rcu(&vlan->list); found = true; kfree(vlan); } The list is published with list_add_rcu(), so readers traverse it under rcu_read_lock(). The writer holds only the RTNL, which does not exclude those readers. list_for_each_entry_safe() protects the writer iteration itself, not concurrent readers. The reader is set_one_vid(), invoked from the NCSI channel configuration state machine (ndp->work) while sending the "Set VLAN Filter" command: rcu_read_lock(); list_for_each_entry_rcu(vlan, &ndp->vlan_vids, list) { vid = vlan->vid; ... } rcu_read_unlock(); An RCU read-side critical section only protects objects released via call_rcu()/kfree_rcu(); it does not protect against the immediate kfree() above. If the state machine work has already obtained the list entry pointer and is then scheduled out while another CPU removes the VLAN id, the resumed iteration reads the freed node and follows the ->next pointer of reused memory. This is reachable on BMC systems using NCSI when a VLAN id is deleted (ip link / rtnetlink) concurrently with an NCSI configuration cycle. Fix this by adding an rcu_head to struct vlan_vid and releasing the node with kfree_rcu(). Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: 21acf63013ed ("net/ncsi: Configure VLAN tag filter") Signed-off-by: Binbin Deng <18983559317@163.com> Link: https://patch.msgid.link/20261010030820.91563-1-18983559317@163.com Signed-off-by: Jakub Kicinski --- net/ncsi/internal.h | 1 + net/ncsi/ncsi-manage.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h index adee6dcabdc3..2c9d1f22c16a 100644 --- a/net/ncsi/internal.h +++ b/net/ncsi/internal.h @@ -312,6 +312,7 @@ struct vlan_vid { struct list_head list; __be16 proto; u16 vid; + struct rcu_head rcu_head; }; struct ncsi_dev_priv { diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c index 54d0df0a9efe..1d63958c4429 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -1737,7 +1737,7 @@ int ncsi_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid) netdev_dbg(dev, "NCSI: vid %u found, removing\n", vid); list_del_rcu(&vlan->list); found = true; - kfree(vlan); + kfree_rcu(vlan, rcu_head); } if (!found) { From 5bef8649bb9ac4b2a014bcc227202ebd2df824be Mon Sep 17 00:00:00 2001 From: Seung Min Shin Date: Sun, 11 Oct 2026 16:27:50 +0000 Subject: [PATCH 1823/2126] sctp: hold transport reference across connect wait sctp_sendmsg_to_asoc() selects a transport before waiting for a new interleaved association to become established. sctp_wait_for_connect() drops the socket lock while sleeping. While the lock is dropped, backlog processing can handle a COOKIE ACK and an ASCONF DEL-IP that removes the selected transport. sctp_assoc_rm_peer() then marks the transport dead and drops its association-owned reference. The transport can be freed through RCU before the send path resumes. After the wait, the stale pointer is assigned to newly created DATA or I-DATA chunks and later dereferenced by sctp_outq_select_transport(). Hold a reference to the selected transport across sctp_wait_for_connect(). After the socket lock is reacquired, abort the send if the transport was marked dead. Callers without a selected transport pass NULL and retain their existing behavior. Cc: stable@vger.kernel.org Fixes: 668c9beb9020 ("sctp: implement assign_number for sctp_stream_interleave") Acked-by: Xin Long Signed-off-by: Seung Min Shin Link: https://patch.msgid.link/20261011162750.1529631-1-guncraft2000@naver.com Signed-off-by: Jakub Kicinski --- net/sctp/socket.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 8cf3e955ae18..b5a57f61ee6d 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -75,7 +75,8 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, struct sctp_transport *transport, long *timeo_p, size_t msg_len); static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p); -static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); +static int sctp_wait_for_connect(struct sctp_association *, + struct sctp_transport *, long *timeo_p); static int sctp_wait_for_accept(struct sock *sk, long timeo); static void sctp_wait_for_close(struct sock *sk, long timeo); static void sctp_destruct_sock(struct sock *sk); @@ -1282,7 +1283,7 @@ static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs, *assoc_id = asoc->assoc_id; timeo = sock_sndtimeo(sk, flags & O_NONBLOCK); - return sctp_wait_for_connect(asoc, &timeo); + return sctp_wait_for_connect(asoc, NULL, &timeo); out_free: pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n", @@ -1884,7 +1885,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, if (asoc->ep->intl_enable) { timeo = sock_sndtimeo(sk, 0); - err = sctp_wait_for_connect(asoc, &timeo); + err = sctp_wait_for_connect(asoc, transport, &timeo); if (err || sk->sk_shutdown & RCV_SHUTDOWN) { err = -ESRCH; goto err; @@ -1927,7 +1928,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, if (unlikely(wait_connect)) { timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); - sctp_wait_for_connect(asoc, &timeo); + sctp_wait_for_connect(asoc, NULL, &timeo); } err = msg_len; @@ -9427,7 +9428,9 @@ static bool sctp_writeable(const struct sock *sk) /* Wait for an association to go into ESTABLISHED state. If timeout is 0, * returns immediately with EINPROGRESS. */ -static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) +static int sctp_wait_for_connect(struct sctp_association *asoc, + struct sctp_transport *transport, + long *timeo_p) { struct sock *sk = asoc->base.sk; int err = 0; @@ -9436,12 +9439,16 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) pr_debug("%s: asoc:%p, timeo:%ld\n", __func__, asoc, *timeo_p); - /* Increment the association's refcnt. */ + /* Hold references while the socket lock is dropped. */ + if (transport) + sctp_transport_hold(transport); sctp_association_hold(asoc); for (;;) { prepare_to_wait_exclusive(&asoc->wait, &wait, TASK_INTERRUPTIBLE); + if (transport && transport->dead) + goto do_transport_dead; if (!*timeo_p) goto do_nonblock; if (sk->sk_shutdown & RCV_SHUTDOWN) @@ -9470,7 +9477,8 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) out: finish_wait(&asoc->wait, &wait); - /* Release the association's refcnt. */ + if (transport) + sctp_transport_put(transport); sctp_association_put(asoc); return err; @@ -9489,6 +9497,10 @@ do_interrupted: do_nonblock: err = -EINPROGRESS; goto out; + +do_transport_dead: + err = -EAGAIN; + goto out; } static int sctp_wait_for_accept(struct sock *sk, long timeo) From 65cf6863606b0507a7c3bd1711317e4f5d6b8b7e Mon Sep 17 00:00:00 2001 From: Shubham Antil Date: Tue, 13 Oct 2026 08:27:29 +0530 Subject: [PATCH 1824/2126] RDS/IB: validate receive fragment completions rds_ib_process_recv() accounts every receive fragment as contributing min(i_recv_data_rem, RDS_FRAG_SIZE) bytes, regardless of the completion length. When a completion is shorter than the header-declared amount, receive accounting can advance beyond the payload supplied by the completion. Only an IB_WC_RECV completion has the buffer layout expected by this receive path. Other successful completion opcodes must not be interpreted as ordinary receive completions. Reject successful completions with any other opcode before processing their length. For ordinary receive completions, require enough payload to cover the amount accounted to the fragment before linking its page into the incoming message. This is compatible with the current transmit paths. MSG_ZEROCOPY is restricted to RDS/TCP, while RDS/IB copied and page-vector messages use full-sized non-final scatterlist entries. Found during an LLM-assisted source audit and validated under KMSAN with a malformed short receive completion. Reported-by: sungbyeongchan Closes: https://lore.kernel.org/netdev/20261006205204.1322102-1-tjdqudcks0424@naver.com/ Reported-by: Giovanni Vignone Link: https://lore.kernel.org/netdev/8a6ee1d5336ae65b8ffdc8c40a1135657207e204.camel@kernel.org/ Reported-by: Robert van Eijk Link: https://lore.kernel.org/netdev/8a6ee1d5336ae65b8ffdc8c40a1135657207e204.camel@kernel.org/ Reported-by: Paolo Gentry Link: https://lore.kernel.org/netdev/8a6ee1d5336ae65b8ffdc8c40a1135657207e204.camel@kernel.org/ Fixes: 1e23b3ee0e94 ("RDS/IB: Receive datagrams via IB") Cc: stable@vger.kernel.org Signed-off-by: Shubham Antil Reviewed-by: Allison Henderson Link: https://patch.msgid.link/20261013025729.40815-1-shubham@octane.security Signed-off-by: Jakub Kicinski --- net/rds/ib_recv.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c index bd6cb3ffaa57..aa50b85b0f99 100644 --- a/net/rds/ib_recv.c +++ b/net/rds/ib_recv.c @@ -949,6 +949,12 @@ static void rds_ib_process_recv(struct rds_connection *conn, } } + if (data_len < min_t(u32, ic->i_recv_data_rem, RDS_FRAG_SIZE)) { + rds_ib_conn_error(conn, + "fragment shorter than header-declared length; forcing reconnect\n"); + goto done; + } + list_add_tail(&recv->r_frag->f_item, &ibinc->ii_frags); recv->r_frag = NULL; @@ -1004,7 +1010,12 @@ void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic, * event is processed. */ if (wc->status == IB_WC_SUCCESS) { - rds_ib_process_recv(conn, recv, wc->byte_len, state); + if (wc->opcode != IB_WC_RECV) + rds_ib_conn_error(conn, + "recv completion had unexpected opcode %u, disconnecting and reconnecting\n", + wc->opcode); + else + rds_ib_process_recv(conn, recv, wc->byte_len, state); } else { /* We expect errors as the qp is drained during shutdown */ if (rds_conn_up(conn) || rds_conn_connecting(conn)) From de3ef6921c00f0af5bdfffc795b7c1d6886b5d6f Mon Sep 17 00:00:00 2001 From: Haseeb Malik Date: Sun, 11 Oct 2026 21:57:11 +0000 Subject: [PATCH 1825/2126] macsec: check for duplicate SCIs before registering the device macsec_newlink() registers and links the device before rejecting a duplicate SCI. Registration can emit link notifications for a device whose creation ultimately fails with -EBUSY. The SCI is already resolved before SecY initialization, so check for a duplicate there and return -EBUSY directly. Remove the now-unused unlink label while preserving cleanup for failures after registration. Suggested-by: Sabrina Dubroca Link: https://lore.kernel.org/netdev/ar2KmwhtCMbOKLsG@krikkit/ Signed-off-by: Haseeb Malik Reviewed-by: Sabrina Dubroca Link: https://patch.msgid.link/20261011-macsec-early-sci-check-2b1f06af193f@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/macsec.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index e435681447fb..4296884d5b4d 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -4269,6 +4269,9 @@ static int macsec_newlink(struct net_device *dev, if (sci == MACSEC_UNDEF_SCI) sci = dev_to_sci(dev, MACSEC_PORT_ES); + if (rx_handler && sci_exists(real_dev, sci)) + return -EBUSY; + /* Registration can notify listeners before returning. */ macsec_init_secy(dev, sci, icv_len); if (data) { @@ -4289,11 +4292,6 @@ static int macsec_newlink(struct net_device *dev, if (err < 0) goto unregister; - if (rx_handler && sci_exists(real_dev, sci)) { - err = -EBUSY; - goto unlink; - } - /* If h/w offloading is available, propagate to the device */ if (macsec_is_offloaded(macsec)) { const struct macsec_ops *ops; @@ -4325,7 +4323,6 @@ static int macsec_newlink(struct net_device *dev, del_dev: macsec_del_dev(macsec); -unlink: netdev_upper_dev_unlink(real_dev, dev); unregister: unregister_netdevice(dev); From 191aa41548b2d2b6af534a6d5cf84a552435c74c Mon Sep 17 00:00:00 2001 From: Bobby Eshleman Date: Mon, 12 Oct 2026 12:58:08 -0700 Subject: [PATCH 1826/2126] MAINTAINERS: add Bobby Eshleman as vsock reviewer I've been reviewing vsock via lore+lei for a while now. Finally adding myself as a formal reviewer, since vsock will continue being stuck with me for the foreseeable future. Signed-off-by: Bobby Eshleman Reviewed-by: Stefano Garzarella Acked-by: Michael S. Tsirkin Acked-by: Stefan Hajnoczi Link: https://patch.msgid.link/20261012-add-maintainers-v1-1-ef0488f460db@meta.com Signed-off-by: Jakub Kicinski --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 5d39ec6feb03..00b440be0d46 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -28838,6 +28838,7 @@ F: virt/lib/ VIRTIO AND VHOST VSOCK DRIVER M: Stefan Hajnoczi M: Stefano Garzarella +R: Bobby Eshleman L: kvm@vger.kernel.org L: virtualization@lists.linux.dev L: netdev@vger.kernel.org @@ -29143,6 +29144,7 @@ F: drivers/media/test-drivers/vivid/* VM SOCKETS (AF_VSOCK) M: Stefano Garzarella +R: Bobby Eshleman L: virtualization@lists.linux.dev L: netdev@vger.kernel.org S: Maintained From ac1f6e58cb77bb66b8811f7d98703e0f076a8f65 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 10 Oct 2026 00:00:11 -0700 Subject: [PATCH 1827/2126] net: bgmac: enable interrupts only after NAPI is ready bgmac_open() calls bgmac_chip_init(), which unmasks the interrupts and enables the MAC receiver, before request_irq() and napi_enable(). bgmac_enet_resume() also enables NAPI only after bgmac_chip_init(). When frames arrive in that window, the first RX interrupt masks all interrupts in bgmac_interrupt() and calls napi_schedule() on a NAPI instance that is still disabled, so nothing is scheduled. Nothing unmasks the interrupts again, the RX ring fills up and the interface stays deaf until it is brought down and up without traffic. On an Asus RT-N16 (BCM4716) a single "ip link set eth0 down/up" while a host sends UDP to the router left INT_MASK at 0, INT_STATUS with RX pending and the RX DMA idle on a full ring, with the RX packet and interrupt counters no longer moving. With this change, 10 of 10 such cycles recovered on their own. Request the IRQ and enable NAPI before the chip is initialized. Fixes: dd4544f05469 ("bgmac: driver for GBit MAC core on BCMA bus") Fixes: f3537b3494c0 ("net: ethernet: bgmac: driver power manangement") Cc: stable@vger.kernel.org Signed-off-by: Rosen Penev Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261010070011.60403-1-rosenp@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bgmac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c index 3e9c57196a39..1835266fdd09 100644 --- a/drivers/net/ethernet/broadcom/bgmac.c +++ b/drivers/net/ethernet/broadcom/bgmac.c @@ -1183,9 +1183,6 @@ static int bgmac_open(struct net_device *net_dev) if (err) return err; - /* Specs say about reclaiming rings here, but we do that in DMA init */ - bgmac_chip_init(bgmac); - err = request_irq(bgmac->irq, bgmac_interrupt, IRQF_SHARED, net_dev->name, net_dev); if (err < 0) { @@ -1195,6 +1192,9 @@ static int bgmac_open(struct net_device *net_dev) } napi_enable(&bgmac->napi); + /* Specs say about reclaiming rings here, but we do that in DMA init */ + bgmac_chip_init(bgmac); + phy_start(net_dev->phydev); netif_start_queue(net_dev); @@ -1608,10 +1608,10 @@ int bgmac_enet_resume(struct bgmac *bgmac) if (rc) return rc; - bgmac_chip_init(bgmac); - napi_enable(&bgmac->napi); + bgmac_chip_init(bgmac); + netif_tx_lock(bgmac->net_dev); netif_device_attach(bgmac->net_dev); netif_tx_unlock(bgmac->net_dev); From 6b3e73774815910a39d8ca75b9ad7df963f61d50 Mon Sep 17 00:00:00 2001 From: Zixuan Chai Date: Sat, 10 Oct 2026 14:25:31 +0800 Subject: [PATCH 1828/2126] devlink: fix reload error on netns teardown During network namespace teardown, devlink_pernet_pre_exit() reloads devlink instances into init_net. If reload_down() fails, devlink_reload() returns before changing the namespace, leaving the registered devlink with a pointer to the namespace being destroyed. Move the fallback transition to devlink_pernet_pre_exit(), where the teardown context is explicit. Do it only when the devlink still belongs to the exiting namespace, since reload_up() can fail after the regular reload path has already moved the instance. Keep the original reload error. Cc: stable+noautosel@kernel.org # unlikely driver error paths Fixes: 070c63f20f6c ("net: devlink: allow to change namespaces during reload") Reported-by: Vega Closes: https://bugtracker.nebusec.ai/f/11365 Signed-off-by: Zixuan Chai Signed-off-by: Ren Wei Link: https://patch.msgid.link/c43794aa549424b79a0da624e73bbb5215c0e9f5.1791555658.git.petalzu987@gmail.com Signed-off-by: Jakub Kicinski --- net/devlink/core.c | 2 ++ net/devlink/dev.c | 6 +++--- net/devlink/devl_internal.h | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/net/devlink/core.c b/net/devlink/core.c index bddbbbf000fe..9b844e0c1bd2 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -585,6 +585,8 @@ static void __net_exit devlink_pernet_pre_exit(struct net *net) DEVLINK_RELOAD_ACTION_DRIVER_REINIT, DEVLINK_RELOAD_LIMIT_UNSPEC, &actions_performed, NULL); + if (err && net_eq(devlink_net(devlink), net)) + devlink_reload_netns_change(devlink, net, &init_net); devl_dev_unlock(devlink, true); devlink_put(devlink); if (err && err != -EOPNOTSUPP) diff --git a/net/devlink/dev.c b/net/devlink/dev.c index b85bb02a9e80..b7e5aebf13be 100644 --- a/net/devlink/dev.c +++ b/net/devlink/dev.c @@ -412,9 +412,9 @@ static struct net *devlink_netns_get(struct sk_buff *skb, return net; } -static void devlink_reload_netns_change(struct devlink *devlink, - struct net *curr_net, - struct net *dest_net) +void devlink_reload_netns_change(struct devlink *devlink, + struct net *curr_net, + struct net *dest_net) { /* Userspace needs to be notified about devlink objects * removed from original and entering new network namespace. diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index cdf894ba5a9d..798e707002b9 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -324,6 +324,9 @@ struct devlink_port *devlink_port_get_from_attrs(struct devlink *devlink, /* Reload */ bool devlink_reload_actions_valid(const struct devlink_ops *ops); +void devlink_reload_netns_change(struct devlink *devlink, + struct net *curr_net, + struct net *dest_net); int devlink_reload(struct devlink *devlink, struct net *dest_net, enum devlink_reload_action action, enum devlink_reload_limit limit, From 9b6fb15a5cc632aaddb4bbd349e637f49cf4fecc Mon Sep 17 00:00:00 2001 From: Frank Li Date: Fri, 2 Oct 2026 15:30:19 -0400 Subject: [PATCH 1829/2126] net: ethernet: micrel: ks8842: use dmaengine_submit() instead of ->tx_submit() Replace direct dma_async_tx_descriptor->tx_submit() calls with the proper dmaengine_submit() API wrapper. Signed-off-by: Frank Li Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261002193022.168248-1-Frank.Li@oss.nxp.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/micrel/ks8842.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/micrel/ks8842.c b/drivers/net/ethernet/micrel/ks8842.c index b7cf2ee9115f..f0d6bfc6025c 100644 --- a/drivers/net/ethernet/micrel/ks8842.c +++ b/drivers/net/ethernet/micrel/ks8842.c @@ -455,7 +455,7 @@ static int ks8842_tx_frame_dma(struct sk_buff *skb, struct net_device *netdev) ctl->adesc->callback_param = netdev; ctl->adesc->callback = ks8842_dma_tx_cb; - ctl->adesc->tx_submit(ctl->adesc); + dmaengine_submit(ctl->adesc); netdev->stats.tx_bytes += skb->len; @@ -569,7 +569,7 @@ static int __ks8842_start_new_rx_dma(struct net_device *netdev) ctl->adesc->callback_param = netdev; ctl->adesc->callback = ks8842_dma_rx_cb; - ctl->adesc->tx_submit(ctl->adesc); + dmaengine_submit(ctl->adesc); } else { err = -ENOMEM; sg_dma_address(sg) = 0; From 17baf30a0e64cde0e8a30723b7c6d06417152514 Mon Sep 17 00:00:00 2001 From: Yongzhao Chen Date: Fri, 2 Oct 2026 23:04:08 +0200 Subject: [PATCH 1830/2126] net: phy: qcom: at803x: Apply IPQ5018 analog settings at probe ipq5018_probe() pulses the PHY reset, after which the IPQ5018 internal GE PHY starts autonegotiating with its reset-default analog settings. ipq5018_config_init() writes the analog settings only when the MAC attaches the PHY, usually when the interface is opened. On a board where the PHY connects to a QCA8337 PHY without a cable, 1000BASE-T does not come up in the meantime, SmartSpeed downshifts both PHYs, and only the IPQ5018 side restores its 1000BASE-T advertisement at attach, so the link stays down. Apply the analog settings in probe right after the reset and restart autonegotiation. Move the settings into a helper shared with config_init() and return MDIO errors from it instead of ignoring them. The values written do not change, only the time of the write. Fixes: d46502279a11 ("net: phy: qcom: at803x: Add Qualcomm IPQ5018 Internal PHY support") Signed-off-by: Yongzhao Chen Link: https://patch.msgid.link/20261002210408.730-1-yongzhao.derek@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/qcom/at803x.c | 96 +++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/drivers/net/phy/qcom/at803x.c b/drivers/net/phy/qcom/at803x.c index cacbadf1f484..09105f1e3737 100644 --- a/drivers/net/phy/qcom/at803x.c +++ b/drivers/net/phy/qcom/at803x.c @@ -1019,10 +1019,10 @@ static int ipq5018_cable_test_start(struct phy_device *phydev) return 0; } -static int ipq5018_config_init(struct phy_device *phydev) +static int ipq5018_analog_init(struct phy_device *phydev) { struct ipq5018_priv *priv = phydev->priv; - u16 val; + int val, ret; /* * set LDO efuse: first temporarily store ANA_DAC_FILTER value from @@ -1030,39 +1030,66 @@ static int ipq5018_config_init(struct phy_device *phydev) * is written to */ val = at803x_debug_reg_read(phydev, IPQ5018_PHY_DEBUG_ANA_DAC_FILTER); - at803x_debug_reg_mask(phydev, IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE, - IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_MASK, - IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_DEFAULT); - at803x_debug_reg_write(phydev, IPQ5018_PHY_DEBUG_ANA_DAC_FILTER, val); + if (val < 0) + return val; + + ret = at803x_debug_reg_mask(phydev, IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE, + IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_MASK, + IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_DEFAULT); + if (ret) + return ret; + + ret = at803x_debug_reg_write(phydev, IPQ5018_PHY_DEBUG_ANA_DAC_FILTER, + val); + if (ret) + return ret; /* set 8023AZ EEE TX and RX timer values */ - phy_write_mmd(phydev, MDIO_MMD_PCS, IPQ5018_PHY_PCS_EEE_TX_TIMER, - IPQ5018_PHY_PCS_EEE_TX_TIMER_VAL); - phy_write_mmd(phydev, MDIO_MMD_PCS, IPQ5018_PHY_PCS_EEE_RX_TIMER, - IPQ5018_PHY_PCS_EEE_RX_TIMER_VAL); + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, IPQ5018_PHY_PCS_EEE_TX_TIMER, + IPQ5018_PHY_PCS_EEE_TX_TIMER_VAL); + if (ret) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, IPQ5018_PHY_PCS_EEE_RX_TIMER, + IPQ5018_PHY_PCS_EEE_RX_TIMER_VAL); + if (ret) + return ret; /* set MSE threshold values */ - phy_write_mmd(phydev, MDIO_MMD_PMAPMD, IPQ5018_PHY_MMD1_MSE_THRESH1, - IPQ5018_PHY_MMD1_MSE_THRESH1_VAL); - phy_write_mmd(phydev, MDIO_MMD_PMAPMD, IPQ5018_PHY_MMD1_MSE_THRESH2, - IPQ5018_PHY_MMD1_MSE_THRESH2_VAL); + ret = phy_write_mmd(phydev, MDIO_MMD_PMAPMD, + IPQ5018_PHY_MMD1_MSE_THRESH1, + IPQ5018_PHY_MMD1_MSE_THRESH1_VAL); + if (ret) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_PMAPMD, + IPQ5018_PHY_MMD1_MSE_THRESH2, + IPQ5018_PHY_MMD1_MSE_THRESH2_VAL); + if (ret) + return ret; /* PHY DAC values are optional and only set in a PHY to PHY link architecture */ - if (priv->set_short_cable_dac) { - /* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */ - phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, IPQ5018_PHY_MMD1_MDAC, - IPQ5018_PHY_DAC_MASK, - FIELD_PREP(IPQ5018_PHY_DAC_MASK, - IPQ5018_PHY_MMD1_MDAC_VAL)); + if (!priv->set_short_cable_dac) + return 0; - /* setting EDAC (Error-detection and Correction) in debug register */ - at803x_debug_reg_mask(phydev, IPQ5018_PHY_DEBUG_EDAC, - IPQ5018_PHY_DAC_MASK, - FIELD_PREP(IPQ5018_PHY_DAC_MASK, - IPQ5018_PHY_DEBUG_EDAC_VAL)); - } + /* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */ + ret = phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, IPQ5018_PHY_MMD1_MDAC, + IPQ5018_PHY_DAC_MASK, + FIELD_PREP(IPQ5018_PHY_DAC_MASK, + IPQ5018_PHY_MMD1_MDAC_VAL)); + if (ret) + return ret; - return 0; + /* setting EDAC (Error-detection and Correction) in debug register */ + return at803x_debug_reg_mask(phydev, IPQ5018_PHY_DEBUG_EDAC, + IPQ5018_PHY_DAC_MASK, + FIELD_PREP(IPQ5018_PHY_DAC_MASK, + IPQ5018_PHY_DEBUG_EDAC_VAL)); +} + +static int ipq5018_config_init(struct phy_device *phydev) +{ + return ipq5018_analog_init(phydev); } static void ipq5018_link_change_notify(struct phy_device *phydev) @@ -1111,6 +1138,21 @@ static int ipq5018_probe(struct phy_device *phydev) phydev->priv = priv; + /* + * The PHY starts autonegotiation as soon as it leaves reset. Apply the + * analog settings now instead of waiting for config_init() at attach + * time, and restart autonegotiation so that it uses them. + */ + ret = ipq5018_analog_init(phydev); + if (ret) + return dev_err_probe(dev, ret, + "failed to apply analog settings\n"); + + ret = genphy_restart_aneg(phydev); + if (ret) + return dev_err_probe(dev, ret, + "failed to restart autonegotiation\n"); + return 0; } From 95a5c641fc7becab441bf244baa73b0b0f8b7dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Mete=20Kaya?= Date: Mon, 5 Oct 2026 00:59:25 +0300 Subject: [PATCH 1831/2126] usbnet: fix smp_processor_id() use in preemptible context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tx_complete() calls this_cpu_ptr() before disabling preemption, which triggers a BUG when running with CONFIG_DEBUG_PREEMPT: BUG: using smp_processor_id() in preemptible code in tx_complete Fix by using get_cpu_ptr()/put_cpu_ptr() which disable preemption and return the per-CPU pointer atomically. The usbnet_skb_return() hunk is a hardening change: that path runs in softirq context so no warning fires there, but the same fix is applied for consistency. Fixes: ed194d136769 ("usb: core: remove local_irq_save() around ->complete() handler") Suggested-by: David Laight Reported-by: syzbot+04cd90bb99c6ef81a65d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=04cd90bb99c6ef81a65d Signed-off-by: Ömer Mete Kaya Link: https://patch.msgid.link/20261004215937.302247-1-omermetekaya0@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/usbnet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index a19ecf718f36..84f97f448b2d 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -325,7 +325,7 @@ static void __usbnet_status_stop_force(struct usbnet *dev) */ void usbnet_skb_return(struct usbnet *dev, struct sk_buff *skb) { - struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats); + struct pcpu_sw_netstats *stats64; unsigned long flags; int status; @@ -338,10 +338,12 @@ void usbnet_skb_return(struct usbnet *dev, struct sk_buff *skb) if (skb->protocol == 0) skb->protocol = eth_type_trans(skb, dev->net); + stats64 = get_cpu_ptr(dev->net->tstats); flags = u64_stats_update_begin_irqsave(&stats64->syncp); u64_stats_inc(&stats64->rx_packets); u64_stats_add(&stats64->rx_bytes, skb->len); u64_stats_update_end_irqrestore(&stats64->syncp, flags); + put_cpu_ptr(dev->net->tstats); netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n", skb->len + sizeof(struct ethhdr), skb->protocol); @@ -1298,13 +1300,15 @@ static void tx_complete(struct urb *urb) struct usbnet *dev = entry->dev; if (urb->status == 0) { - struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats); + struct pcpu_sw_netstats *stats64; unsigned long flags; + stats64 = get_cpu_ptr(dev->net->tstats); flags = u64_stats_update_begin_irqsave(&stats64->syncp); u64_stats_add(&stats64->tx_packets, entry->packets); u64_stats_add(&stats64->tx_bytes, entry->length); u64_stats_update_end_irqrestore(&stats64->syncp, flags); + put_cpu_ptr(dev->net->tstats); } else { dev->net->stats.tx_errors++; From 00accbd9d5021b942a16078bd5717d7865f6971c Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Thu, 8 Oct 2026 12:28:12 -0300 Subject: [PATCH 1832/2126] calipso: update payload_len when removing the CALIPSO option calipso_skbuff_delattr() removes the CALIPSO option from the hop-by-hop extension header, or the whole extension header if CALIPSO is its only option, and pulls the skb by the removed length. It never updates ipv6hdr->payload_len, so after a successful removal the header still claims the original length. calipso_skbuff_setattr() already adjusts payload_len by the length it adds; the delete path was missed. This is reached on the forward path when a packet carrying CALIPSO is sent to a destination mapped to an unlabeled NetLabel domain. The forwarded packet then has a payload_len larger than its real payload by the removed length (8 to 264 bytes), and the receiver drops it as truncated. So removing the label on the forward path has been broken for every packet that is not resegmented later (SYN, UDP, ICMPv6...). Adjust payload_len after the header is moved. BIG TCP packets carry payload_len == 0 (see ipv6_set_payload_len()), and ipv6_payload_len() then falls back to skb->len, so leave them alone. Tested with client, router and server network namespaces on one kernel (arm64, QEMU): SELinux permissive with a minimal mdp-generated policy (network_peer_controls=1), "netlabelctl calipso add pass doi:16", the default NetLabel mapping left unlabeled, IPv6 forwarding on the router. The client sends 5 UDP datagrams with a CALIPSO hop-by-hop option (DOI 16, set through IPV6_HOPOPTS) to the server through the router: before: router Ip6OutForwDatagrams 5, server receives 0, server Ip6InTruncatedPkts 5 after: router Ip6OutForwDatagrams 5, server receives 5, server Ip6InTruncatedPkts 0 Fixes: 2917f57b6bc1 ("calipso: Allow the lsm to label the skbuff directly.") Signed-off-by: Joas Antonio dos Santos Link: https://patch.msgid.link/179147329205.58079.5847298721173675285@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/calipso.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index a0192b4fef33..2ec4c43d332a 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -1428,6 +1428,10 @@ static int calipso_skbuff_delattr(struct sk_buff *skb) skb_pull(skb, delta); memmove((char *)ip6_hdr + delta, ip6_hdr, size); skb_reset_network_header(skb); + ip6_hdr = ipv6_hdr(skb); + /* BIG TCP packets have payload_len == 0 */ + if (ip6_hdr->payload_len) + be16_add_cpu(&ip6_hdr->payload_len, -delta); } return 0; From 5babd12ed1144401edc9e17976a64674419aa799 Mon Sep 17 00:00:00 2001 From: Stefano Radaelli Date: Thu, 8 Oct 2026 21:37:44 +0200 Subject: [PATCH 1833/2126] net: phy: micrel: Check RMII clock select property presence The micrel,rmii-reference-clock-select-25-mhz property is tested for presence, but of_property_read_bool() warns when the property has a value. Encoding it as <1> to satisfy the DT schema unit check would therefore produce a warning at PHY probe. Use of_property_present() for the presence test. It accepts both existing empty properties and the new numeric form without changing the RMII clock selection. Signed-off-by: Stefano Radaelli Link: https://patch.msgid.link/6271eea14eb6ef93031921cedc12d87cf5e25595.1791487179.git.stefano.r@variscite.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/micrel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 5c8461db7b4b..d0b1ad21667b 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -2791,7 +2791,7 @@ static int kszphy_probe(struct phy_device *phydev) if (type) priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel; - rmii_ref_clk_sel_25_mhz = of_property_read_bool(np, + rmii_ref_clk_sel_25_mhz = of_property_present(np, "micrel,rmii-reference-clock-select-25-mhz"); if (rate > 24500000 && rate < 25500000) { From 1b93cd0f6584d16b6cf10433f69726a7ad3f056b Mon Sep 17 00:00:00 2001 From: Stefano Radaelli Date: Thu, 8 Oct 2026 21:37:45 +0200 Subject: [PATCH 1834/2126] dt-bindings: net: micrel: Fix RMII clock select property type The binding describes micrel,rmii-reference-clock-select-25-mhz as a boolean. dt-schema requires properties ending in -mhz to contain an unsigned integer value. A bare property therefore produces a property-units.yaml type warning. Describe 25 MHz selection as <1> and keep the property restricted to KSZ8021, KSZ8031, KSZ8081 and KSZ8091 PHYs, which have the RMII reference clock select bit. The driver checks only for the property presence, so this does not change runtime behavior. Acked-by: Rob Herring (Arm) Signed-off-by: Stefano Radaelli Link: https://patch.msgid.link/759d62ee229f0cbb83a51cacbb70ed7dacf4ea3b.1791487179.git.stefano.r@variscite.com Signed-off-by: Jakub Kicinski --- .../devicetree/bindings/net/micrel.yaml | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/net/micrel.yaml b/Documentation/devicetree/bindings/net/micrel.yaml index 6fa568057b92..a1f876dc00de 100644 --- a/Documentation/devicetree/bindings/net/micrel.yaml +++ b/Documentation/devicetree/bindings/net/micrel.yaml @@ -63,6 +63,14 @@ properties: minimum: 0 maximum: 3 + micrel,rmii-reference-clock-select-25-mhz: + enum: [ 1 ] + description: | + RMII Reference Clock Select bit selects 25 MHz mode. + + Setting the RMII Reference Clock Select bit enables 25 MHz rather + than 50 MHz clock mode. + allOf: - $ref: ethernet-phy.yaml# - if: @@ -90,6 +98,18 @@ allOf: then: properties: micrel,led-mode: false + - if: + not: + properties: + compatible: + contains: + enum: + - ethernet-phy-id0022.1555 + - ethernet-phy-id0022.1556 + - ethernet-phy-id0022.1560 + then: + properties: + micrel,rmii-reference-clock-select-25-mhz: false - if: properties: compatible: @@ -105,13 +125,6 @@ allOf: description: The RMII reference input clock. Used to determine the XI input clock. - micrel,rmii-reference-clock-select-25-mhz: - type: boolean - description: | - RMII Reference Clock Select bit selects 25 MHz mode - - Setting the RMII Reference Clock Select bit enables 25 MHz rather - than 50 MHz clock mode. dependentRequired: micrel,rmii-reference-clock-select-25-mhz: [ clock-names ] From ba13bd277d22e0455e13dd95aa07e4120a1042de Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 00:58:19 +0800 Subject: [PATCH 1835/2126] net: dsa: motorcomm: Split TC module Move the traffic control code from chip.c into a separate tc.c, to reduce the length of chip.c. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261009165825.359259-2-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 1500 +--------------------------- drivers/net/dsa/motorcomm/chip.h | 350 +------ drivers/net/dsa/motorcomm/tc.c | 1496 +++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.h | 380 +++++++ 5 files changed, 1888 insertions(+), 1839 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/tc.c create mode 100644 drivers/net/dsa/motorcomm/tc.h diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index 9c1e3d538d21..9eaa59f699e8 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -6,3 +6,4 @@ yt921x-objs += mdio_bus.o yt921x-objs += mib.o yt921x-objs += pcs-921x.o yt921x-objs += smi.o +yt921x-objs += tc.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 91cc5647f2b6..e2b5c89f7e77 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "chip.h" #include "leds.h" @@ -32,6 +31,7 @@ #include "mib.h" #include "pcs.h" #include "smi.h" +#include "tc.h" static const struct yt921x_info yt921x_infos[] = { { @@ -98,16 +98,6 @@ struct yt921x_reg_mdio { /* TODO: SPI/I2C */ -static u32 ethaddr_hi4_to_u32(const unsigned char *addr) -{ - return (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]; -} - -static u32 ethaddr_lo2_to_u32(const unsigned char *addr) -{ - return (addr[4] << 8) | addr[5]; -} - static int yt921x_reg_mdio_read(void *context, u32 reg, u32 *valp) { struct yt921x_reg_mdio *mdio = context; @@ -245,13 +235,6 @@ yt921x_dsa_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_keee *e) return res; } -static int yt921x_mtu_fetch(struct yt921x_priv *priv, int port) -{ - struct dsa_port *dp = dsa_to_port(&priv->ds, port); - - return dp->user ? READ_ONCE(dp->user->mtu) : ETH_DATA_LEN; -} - static int yt921x_dsa_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) { @@ -283,1445 +266,6 @@ static int yt921x_dsa_port_max_mtu(struct dsa_switch *ds, int port) return YT921X_FRAME_SIZE_MAX - ETH_HLEN - ETH_FCS_LEN - YT921X_TAG_LEN; } -/* v * 2^e */ -static u64 ldexpu64(u64 v, int e) -{ - return e >= 0 ? v << e : v >> -e; -} - -/* slot (ns) * rate (/s) / 10^9 (ns/s) = 2^C * token * 4^unit */ -static u32 rate2token(u64 rate, unsigned int slot_ns, int unit, int C) -{ - int e = 2 * unit + C + YT921X_TOKEN_RATE_C; - - return div_u64(ldexpu64(slot_ns * rate, -e), 1000000000); -} - -static u64 token2rate(u32 token, unsigned int slot_ns, int unit, int C) -{ - int e = 2 * unit + C + YT921X_TOKEN_RATE_C; - - return div_u64(ldexpu64(mul_u32_u32(1000000000, token), e), slot_ns); -} - -/* burst = 2^C * token * 4^unit */ -static u32 burst2token(u64 burst, int unit, int C) -{ - return ldexpu64(burst, -(2 * unit + C)); -} - -static u64 token2burst(u32 token, int unit, int C) -{ - return ldexpu64(token, 2 * unit + C); -} - -struct yt921x_marker { - u32 cir; - u32 cbs; - u32 ebs; - int unit; - bool pkt_mode; -}; - -#define YT921X_MARKER_PKT_MODE BIT(0) -#define YT921X_MARKER_SINGLE_BUCKET BIT(1) - -static int -yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst, - unsigned int flags, unsigned int slot_ns, u32 cir_max, - u32 cbs_max, int unit_max, struct yt921x_priv *priv, int port, - struct netlink_ext_ack *extack) -{ - const int C = flags & YT921X_MARKER_PKT_MODE ? YT921X_TOKEN_PKT_C : - YT921X_TOKEN_BYTE_C; - struct device *dev = yt921x_priv_to_device(priv); - struct yt921x_marker m; - u64 burst_est; - u64 burst_sug; - u64 burst_max; - u64 rate_max; - - m.unit = unit_max; - rate_max = token2rate(cir_max, slot_ns, m.unit, C); - burst_max = token2burst(cbs_max, m.unit, C); - - /* Check for unusual values */ - if (rate > rate_max || burst > burst_max) { - NL_SET_ERR_MSG_MOD(extack, "Unexpected tremendous rate"); - return -ERANGE; - } - - /* Check for matching burst */ - burst_est = div_u64(slot_ns * rate, 1000000000); - burst_sug = burst_est; - if (flags & YT921X_MARKER_PKT_MODE) - burst_sug++; - else - burst_sug += ETH_HLEN + yt921x_mtu_fetch(priv, port) + - ETH_FCS_LEN; - if (burst_sug > burst) - NL_SET_ERR_MSG_FMT_MOD(extack, - "Consider match rate %llu with burst at least %llu", - rate, burst_sug); - - /* Select unit */ - for (; m.unit > 0; m.unit--) { - if (rate > (rate_max >> 2) || burst > (burst_max >> 2)) - break; - rate_max >>= 2; - burst_max >>= 2; - } - - /* Calculate information rate and bucket size */ - m.cir = rate2token(rate, slot_ns, m.unit, C); - if (!m.cir) - m.cir = 1; - else if (WARN_ON(m.cir > cir_max)) - m.cir = cir_max; - m.cbs = burst2token(burst, m.unit, C); - if (!m.cbs) - m.cbs = 1; - else if (WARN_ON(m.cbs > cbs_max)) - m.cbs = cbs_max; - - /* Cut EBS */ - m.ebs = 0; - if (!(flags & YT921X_MARKER_SINGLE_BUCKET)) { - /* We don't have a chance to adjust rate when MTU is changed */ - if (flags & YT921X_MARKER_PKT_MODE) - burst_est++; - else - burst_est += YT921X_FRAME_SIZE_MAX; - - if (burst_est < burst) { - u32 pbs = m.cbs; - - m.cbs = burst2token(burst_est, m.unit, C); - if (!m.cbs) - m.cbs = 1; - else if (WARN_ON(m.cbs > cbs_max)) - m.cbs = cbs_max; - - if (pbs > m.cbs) - m.ebs = pbs - m.cbs; - } - } - - dev_dbg(dev, - "slot %u ns, rate %llu, burst %llu -> unit %d, cir %u, cbs %u, ebs %u\n", - slot_ns, rate, burst, m.unit, m.cir, m.cbs, m.ebs); - - m.pkt_mode = flags & YT921X_MARKER_PKT_MODE; - *marker = m; - return 0; -} - -static int -yt921x_marker_tfm_police(struct yt921x_marker *marker, - const struct flow_action_police *police, - unsigned int flags, struct yt921x_priv *priv, int port, - struct netlink_ext_ack *extack) -{ - bool pkt_mode = !!police->rate_pkt_ps; - u64 burst; - u64 rate; - - rate = pkt_mode ? police->rate_pkt_ps : police->rate_bytes_ps; - burst = pkt_mode ? police->burst_pkt : police->burst; - if (pkt_mode) - flags |= YT921X_MARKER_PKT_MODE; - - return yt921x_marker_tfm(marker, rate, burst, flags, - priv->meter_slot_ns, YT921X_METER_CIR_MAX, - YT921X_METER_CBS_MAX, YT921X_METER_UNIT_MAX, - priv, port, extack); -} - -static int -yt921x_marker_tfm_shape(struct yt921x_marker *marker, u64 rate, u64 burst, - unsigned int flags, struct yt921x_priv *priv, int port, - struct netlink_ext_ack *extack) -{ - return yt921x_marker_tfm(marker, rate, burst, flags, - priv->port_shape_slot_ns, YT921X_SHAPE_CIR_MAX, - YT921X_SHAPE_CBS_MAX, YT921X_SHAPE_UNIT_MAX, - priv, port, extack); -} - -static int -yt921x_police_validate(const struct flow_action_police *police, - const struct flow_action *action, - const struct flow_action_entry *act, - struct netlink_ext_ack *extack) -{ - if (police->exceed.act_id != FLOW_ACTION_DROP) { - NL_SET_ERR_MSG_MOD(extack, - "Offload not supported when exceed action is not drop"); - return -EOPNOTSUPP; - } - - if (police->notexceed.act_id != FLOW_ACTION_PIPE && - police->notexceed.act_id != FLOW_ACTION_ACCEPT) { - NL_SET_ERR_MSG_MOD(extack, - "Offload not supported when conform action is not pipe or ok"); - return -EOPNOTSUPP; - } - - if (police->notexceed.act_id == FLOW_ACTION_ACCEPT && action && act && - !flow_action_is_last_entry(action, act)) { - NL_SET_ERR_MSG_MOD(extack, - "Offload not supported when conform action is ok, but action is not last"); - return -EOPNOTSUPP; - } - - /* mtu defaults to unlimited but we got 2040 here, don't know why */ - if (police->peakrate_bytes_ps || police->avrate || police->overhead) { - NL_SET_ERR_MSG_MOD(extack, - "Offload not supported when peakrate/avrate/overhead is configured"); - return -EOPNOTSUPP; - } - - return 0; -} - -static int -yt921x_meter_config(struct yt921x_priv *priv, unsigned int id, - const struct yt921x_marker *marker) -{ - u32 ctrls[3]; - - ctrls[0] = 0; - ctrls[1] = YT921X_METER_CTRLb_CIR(marker->cir); - ctrls[2] = YT921X_METER_CTRLc_UNIT(marker->unit) | - YT921X_METER_CTRLc_DROP_R | - YT921X_METER_CTRLc_TOKEN_OVERFLOW_EN | - YT921X_METER_CTRLc_METER_EN; - if (marker->pkt_mode) - ctrls[2] |= YT921X_METER_CTRLc_PKT_MODE; - update_ctrls_unaligned(&ctrls[0], &ctrls[1], - YT921X_METER_CTRLab_EBS_M, - YT921X_METER_CTRLab_EBS(marker->ebs)); - update_ctrls_unaligned(&ctrls[1], &ctrls[2], - YT921X_METER_CTRLbc_CBS_M, - YT921X_METER_CTRLbc_CBS(marker->cbs)); - - return yt921x_reg96_write(priv, YT921X_METERn_CTRL(id), ctrls); -} - -static void yt921x_dsa_port_policer_del(struct dsa_switch *ds, int port) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct device *dev = yt921x_priv_to_device(priv); - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_reg_write(priv, YT921X_PORTn_METER(port), 0); - mutex_unlock(&priv->reg_lock); - - if (res) - dev_err(dev, "Failed to %s port %d: %i\n", "delete policer on", - port, res); -} - -static int -yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port, - const struct flow_action_police *police, - struct netlink_ext_ack *extack) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_marker marker; - u32 ctrl; - int res; - - res = yt921x_police_validate(police, NULL, NULL, extack); - if (res) - return res; - - res = yt921x_marker_tfm_police(&marker, police, 0, priv, port, extack); - if (res) - return res; - - mutex_lock(&priv->reg_lock); - res = yt921x_meter_config(priv, port + YT921X_METER_NUM, &marker); - if (res) - goto end; - - ctrl = YT921X_PORT_METER_ID(port) | YT921X_PORT_METER_EN; - res = yt921x_reg_write(priv, YT921X_PORTn_METER(port), ctrl); -end: - mutex_unlock(&priv->reg_lock); - - return res; -} - -static int -yt921x_dsa_port_setup_tc_tbf_port(struct dsa_switch *ds, int port, - const struct tc_tbf_qopt_offload *qopt) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct netlink_ext_ack *extack = qopt->extack; - u32 ctrls[2]; - int res; - - if (qopt->parent != TC_H_ROOT) - return -EOPNOTSUPP; - - switch (qopt->command) { - case TC_TBF_STATS: - /* Unfortunately the convention for TC_*_STATS is a mess, - * neither 0 nor -EOPNOTSUPP is perfect here. - */ - return -EOPNOTSUPP; - case TC_TBF_DESTROY: - ctrls[0] = 0; - ctrls[1] = 0; - break; - case TC_TBF_REPLACE: { - const struct tc_tbf_qopt_offload_replace_params *p; - struct yt921x_marker marker; - - p = &qopt->replace_params; - - res = yt921x_marker_tfm_shape(&marker, p->rate.rate_bytes_ps, - p->max_size, - YT921X_MARKER_SINGLE_BUCKET, - priv, port, extack); - if (res) - return res; - - ctrls[0] = YT921X_PORT_SHAPE_CTRLa_CIR(marker.cir) | - YT921X_PORT_SHAPE_CTRLa_CBS(marker.cbs); - ctrls[1] = YT921X_PORT_SHAPE_CTRLb_UNIT(marker.unit) | - YT921X_PORT_SHAPE_CTRLb_EN; - break; - } - default: - return -EOPNOTSUPP; - } - - mutex_lock(&priv->reg_lock); - res = yt921x_reg64_write(priv, YT921X_PORTn_SHAPE_CTRL(port), ctrls); - mutex_unlock(&priv->reg_lock); - - return res; -} - -static int -yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port, - enum tc_setup_type type, void *type_data) -{ - switch (type) { - case TC_SETUP_QDISC_TBF: { - const struct tc_tbf_qopt_offload *qopt = type_data; - - return yt921x_dsa_port_setup_tc_tbf_port(ds, port, qopt); - } - default: - return -EOPNOTSUPP; - } -} - -/* ACL: 48 blocks * 8 entries - * - * One rule can span multiple entries, but within a block. - */ - -static void -yt921x_acl_entry_set(struct yt921x_acl_entry *entry, unsigned int offset, - u32 flags, bool set) -{ - if (set) - entry->key[offset] |= flags; - entry->mask[offset] |= flags; -} - -static unsigned int -yt921x_acl_entries_set_is_fragment(struct yt921x_acl_entry *entries, - unsigned int size, bool set) -{ - for (unsigned int i = 0; i < size; i++) - switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { - case YT921X_ACL_TYPE_IPV4_DA: - case YT921X_ACL_TYPE_IPV4_SA: - yt921x_acl_entry_set(&entries[i], 1, - YT921X_ACL_BINb_IPV4_FRAG, set); - return size; - case YT921X_ACL_TYPE_IPV6_DA3: - case YT921X_ACL_TYPE_IPV6_SA3: - yt921x_acl_entry_set(&entries[i], 1, - YT921X_ACL_BINb_IPV6_xA3_FRAG, - set); - return size; - case YT921X_ACL_TYPE_MISC: - yt921x_acl_entry_set(&entries[i], 1, - YT921X_ACL_BINb_MISC_FRAG, set); - return size; - case YT921X_ACL_TYPE_L4: - yt921x_acl_entry_set(&entries[i], 1, - YT921X_ACL_BINb_L4_FRAG, set); - return size; - } - - if (size >= YT921X_ACL_ENT_PER_BLK) - return 0; - - entries[size] = (typeof(*entries)){}; - entries[size].key[1] = YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); - yt921x_acl_entry_set(&entries[size], 1, YT921X_ACL_BINb_MISC_FRAG, set); - - return size + 1; -} - -static unsigned int -yt921x_acl_entries_set_first_frag(struct yt921x_acl_entry *entries, - unsigned int size, bool set) -{ - for (unsigned int i = 0; i < size; i++) - switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { - case YT921X_ACL_TYPE_IPV6_DA2: - case YT921X_ACL_TYPE_IPV6_SA2: - yt921x_acl_entry_set(&entries[i], 1, - YT921X_ACL_BINb_IPV6_xA2_FIRST_FRAG, - set); - return size; - case YT921X_ACL_TYPE_MISC: - yt921x_acl_entry_set(&entries[i], 0, - YT921X_ACL_BINa_MISC_FIRST_FRAG, - set); - return size; - } - - if (size >= YT921X_ACL_ENT_PER_BLK) - return 0; - - entries[size] = (typeof(*entries)){}; - entries[size].key[1] = YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); - yt921x_acl_entry_set(&entries[size], 0, - YT921X_ACL_BINa_MISC_FIRST_FRAG, set); - - return size + 1; -} - -static unsigned int -yt921x_acl_entries_set_l3_type(struct yt921x_acl_entry *entries, - unsigned int size, enum yt921x_l3_type type) -{ - for (unsigned int i = 0; i < size; i++) - switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { - case YT921X_ACL_TYPE_MAC_DA0: - case YT921X_ACL_TYPE_MAC_SA0: - entries[i].key[1] |= YT921X_ACL_BINb_MAC_xA0_L3_TYPE(type); - entries[i].mask[1] |= YT921X_ACL_BINb_MAC_xA0_L3_TYPE_M; - return size; - case YT921X_ACL_TYPE_MISC: - entries[i].key[0] |= YT921X_ACL_BINa_MISC_L3_TYPE(type); - entries[i].mask[0] |= YT921X_ACL_BINa_MISC_L3_TYPE_M; - return size; - } - - if (size >= YT921X_ACL_ENT_PER_BLK) - return 0; - - entries[size] = (typeof(*entries)){}; - entries[size].key[0] = YT921X_ACL_BINa_MISC_L3_TYPE(type); - entries[size].key[1] = YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); - entries[size].mask[0] = YT921X_ACL_BINa_MISC_L3_TYPE_M; - - return size + 1; -} - -static unsigned int -yt921x_acl_entries_set_l4_type(struct yt921x_acl_entry *entries, - unsigned int size, enum yt921x_l4_type type) -{ - for (unsigned int i = 0; i < size; i++) - switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { - case YT921X_ACL_TYPE_IPV4_DA: - case YT921X_ACL_TYPE_IPV4_SA: - entries[i].key[1] |= YT921X_ACL_BINb_IPV4_L4_TYPE(type); - entries[i].mask[1] |= YT921X_ACL_BINb_IPV4_L4_TYPE_M; - return size; - case YT921X_ACL_TYPE_IPV6_DA0: - case YT921X_ACL_TYPE_IPV6_DA1: - case YT921X_ACL_TYPE_IPV6_DA2: - case YT921X_ACL_TYPE_IPV6_DA3: - case YT921X_ACL_TYPE_IPV6_SA0: - case YT921X_ACL_TYPE_IPV6_SA1: - case YT921X_ACL_TYPE_IPV6_SA2: - case YT921X_ACL_TYPE_IPV6_SA3: - entries[i].key[1] |= YT921X_ACL_BINb_IPV6_L4_TYPE(type); - entries[i].mask[1] |= YT921X_ACL_BINb_IPV6_L4_TYPE_M; - return size; - case YT921X_ACL_TYPE_L4: - entries[i].key[1] |= YT921X_ACL_BINb_L4_TYPE(type); - entries[i].mask[1] |= YT921X_ACL_BINb_L4_TYPE_M; - return size; - case YT921X_ACL_TYPE_MISC: - entries[i].key[1] |= YT921X_ACL_BINb_MISC_L4_TYPE(type); - entries[i].mask[1] |= YT921X_ACL_BINb_MISC_L4_TYPE_M; - return size; - } - - if (size >= YT921X_ACL_ENT_PER_BLK) - return 0; - - entries[size] = (typeof(*entries)){}; - entries[size].key[1] = YT921X_ACL_BINb_MISC_L4_TYPE(type) | - YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); - entries[size].mask[1] = YT921X_ACL_BINb_MISC_L4_TYPE_M; - - return size + 1; -} - -static struct yt921x_acl_entry * -yt921x_acl_entries_new(struct yt921x_acl_entry *entries, unsigned int *sizep, - u32 type) -{ - unsigned int size = *sizep; - - if (size >= YT921X_ACL_ENT_PER_BLK) - return NULL; - - entries[size] = (typeof(*entries)){}; - entries[size].key[1] = YT921X_ACL_KEYb_TYPE(type); - - (*sizep)++; - return &entries[size]; -} - -static struct yt921x_acl_entry * -yt921x_acl_entries_find(struct yt921x_acl_entry *entries, unsigned int *sizep, - u32 type) -{ - for (unsigned int i = 0; i < *sizep; i++) - if (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1]) == - type) - return &entries[i]; - return yt921x_acl_entries_new(entries, sizep, type); -} - -static void -yt921x_acl_rule_set_ports(struct yt921x_acl_rule *aclrule, u16 ord, - u16 ports_mask) -{ - struct yt921x_acl_entry *entries = aclrule->entries; - - for (unsigned int i = 0; i < hweight8(aclrule->mask); i++) { - entries[i].key[1] |= YT921X_ACL_KEYb_SPORTS(ports_mask) | - YT921X_ACL_KEYb_ORD(ord); - } -} - -struct yt921x_acl_rule_ext { - struct yt921x_acl_rule r; - - struct yt921x_marker marker; -}; - -static int -yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, - const struct flow_cls_offload *cls) -{ - const struct flow_rule *rule = flow_cls_offload_flow_rule(cls); - struct yt921x_acl_entry *entries = ruleext->r.entries; - struct netlink_ext_ack *extack = cls->common.extack; - const struct flow_dissector *dissector; - struct yt921x_acl_entry *entry; - unsigned int size = 0; - bool use_dport; - bool use_sport; - - /* Incomplete and probably won't, since it supports custom u32 filters. - * New adapters are welcome. - */ - dissector = rule->match.dissector; - if (dissector->used_keys & - ~(BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) | - BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) | - BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS) | - BIT_ULL(FLOW_DISSECTOR_KEY_IPV6_ADDRS) | - BIT_ULL(FLOW_DISSECTOR_KEY_PORTS) | - BIT_ULL(FLOW_DISSECTOR_KEY_PORTS_RANGE) | - BIT_ULL(FLOW_DISSECTOR_KEY_ETH_ADDRS) | - BIT_ULL(FLOW_DISSECTOR_KEY_IP) | - BIT_ULL(FLOW_DISSECTOR_KEY_TCP))) { - NL_SET_ERR_MSG_MOD(extack, "Unsupported keys used"); - return -EOPNOTSUPP; - } - - /* Entries */ - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) { - struct flow_match_ipv4_addrs match; - - flow_rule_match_ipv4_addrs(rule, &match); - - if (match.mask->dst) { - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_IPV4_DA); - if (!entry) - goto err; - - entry->key[0] |= ntohl(match.key->dst); - entry->mask[0] |= ntohl(match.mask->dst); - } - - if (match.mask->src) { - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_IPV4_SA); - if (!entry) - goto err; - - entry->key[0] |= ntohl(match.key->src); - entry->mask[0] |= ntohl(match.mask->src); - } - } - - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS)) { - struct flow_match_ipv6_addrs match; - - flow_rule_match_ipv6_addrs(rule, &match); - - for (unsigned int i = 0; i < 4; i++) { - if (!match.mask->dst.s6_addr32[i]) - continue; - - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_IPV6_DA0 + i); - if (!entry) - goto err; - - entry->key[0] |= ntohl(match.key->dst.s6_addr32[i]); - entry->mask[0] |= ntohl(match.mask->dst.s6_addr32[i]); - } - - for (unsigned int i = 0; i < 4; i++) { - if (!match.mask->src.s6_addr32[i]) - continue; - - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_IPV6_SA0 + i); - if (!entry) - goto err; - - entry->key[0] |= ntohl(match.key->src.s6_addr32[i]); - entry->mask[0] |= ntohl(match.mask->src.s6_addr32[i]); - } - } - - use_dport = false; - use_sport = false; - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) { - struct flow_match_ports match; - - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_L4); - if (!entry) - goto err; - - flow_rule_match_ports(rule, &match); - - use_dport = !!match.mask->dst; - use_sport = !!match.mask->src; - - entry->key[0] |= (ntohs(match.key->dst) << 16) | - ntohs(match.key->src); - entry->mask[0] |= (ntohs(match.mask->dst) << 16) | - ntohs(match.mask->src); - } - - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS_RANGE)) { - struct flow_match_ports_range match; - - entry = yt921x_acl_entries_find(entries, &size, - YT921X_ACL_TYPE_L4); - if (!entry) - goto err; - - flow_rule_match_ports_range(rule, &match); - - if ((use_dport && match.mask->tp.dst) || - (use_sport && match.mask->tp.src)) { - NL_SET_ERR_MSG_MOD(extack, - "Port mask and range are mutually exclusive"); - return -EINVAL; - } - - if (match.mask->tp.dst) { - entry->key[0] |= ntohs(match.key->tp_min.dst) << 16; - entry->key[1] |= YT921X_ACL_KEYb_L4_DPORT_RANGE_EN; - entry->mask[0] |= ntohs(match.key->tp_max.dst) << 16; - } - - if (match.mask->tp.src) { - entry->key[0] |= ntohs(match.key->tp_min.src); - entry->key[1] |= YT921X_ACL_KEYb_L4_SPORT_RANGE_EN; - entry->mask[0] |= ntohs(match.key->tp_max.src); - } - } - - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) { - struct flow_match_eth_addrs match; - u32 mask; - - flow_rule_match_eth_addrs(rule, &match); - - mask = ethaddr_hi4_to_u32(match.mask->dst); - if (mask) { - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_MAC_DA0); - if (!entry) - goto err; - - entry->key[0] |= ethaddr_hi4_to_u32(match.key->dst); - entry->mask[0] |= mask; - } - - mask = ethaddr_hi4_to_u32(match.mask->src); - if (mask) { - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_MAC_SA0); - if (!entry) - goto err; - - entry->key[0] |= ethaddr_hi4_to_u32(match.key->src); - entry->mask[0] |= mask; - } - - mask = (ethaddr_lo2_to_u32(match.mask->dst) << 16) | - ethaddr_lo2_to_u32(match.mask->src); - if (mask) { - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_MAC_DA1_SA1); - if (!entry) - goto err; - - entry->key[0] |= (ethaddr_lo2_to_u32(match.key->dst) << 16) | - ethaddr_lo2_to_u32(match.key->src); - entry->mask[0] |= mask; - } - } - - /* Entries + Misc */ - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) { - struct flow_match_basic match; - - flow_rule_match_basic(rule, &match); - - if (match.mask->n_proto) { - enum yt921x_l3_type l3type = YT921X_L3_TYPE_OTHER; - - if (match.mask->n_proto == htons(~0)) - switch (match.key->n_proto) { - case htons(ETH_P_IP): - l3type = YT921X_L3_TYPE_IPV4; - break; - case htons(ETH_P_IPV6): - l3type = YT921X_L3_TYPE_IPV6; - break; - case htons(ETH_P_ARP): - l3type = YT921X_L3_TYPE_ARP; - break; - case htons(ETH_P_LLDP): - l3type = YT921X_L3_TYPE_LLDP; - break; - case htons(ETH_P_PAE): - l3type = YT921X_L3_TYPE_PAE; - break; - case htons(ETH_P_CFM): - l3type = YT921X_L3_TYPE_ERP; - break; - } - - if (l3type != YT921X_L3_TYPE_OTHER) { - size = yt921x_acl_entries_set_l3_type(entries, - size, - l3type); - if (!size) - goto err; - } else { - entry = yt921x_acl_entries_new(entries, &size, - YT921X_ACL_TYPE_ETHERTYPE); - if (!entry) - goto err; - - entry->key[0] |= ntohs(match.key->n_proto); - entry->mask[0] |= ntohs(match.mask->n_proto); - } - } - - if (match.mask->ip_proto) { - enum yt921x_l4_type l4type = YT921X_L4_TYPE_OTHER; - - if (match.mask->ip_proto == (u8)~0) - switch (match.key->ip_proto) { - case IPPROTO_TCP: - l4type = YT921X_L4_TYPE_TCP; - break; - case IPPROTO_UDP: - l4type = YT921X_L4_TYPE_UDP; - break; - case IPPROTO_UDPLITE: - l4type = YT921X_L4_TYPE_UDPLITE; - break; - case IPPROTO_ICMP: - l4type = YT921X_L4_TYPE_ICMP; - break; - case IPPROTO_IGMP: - l4type = YT921X_L4_TYPE_IGMP; - break; - } - - if (l4type != YT921X_L4_TYPE_OTHER) { - size = yt921x_acl_entries_set_l4_type(entries, - size, - l4type); - if (!size) - goto err; - } else { - entry = yt921x_acl_entries_find(entries, &size, - YT921X_ACL_TYPE_MISC); - if (!entry) - goto err; - - entry->key[0] |= YT921X_ACL_BINa_MISC_IP_PROTO(match.key->ip_proto); - entry->mask[0] |= YT921X_ACL_BINa_MISC_IP_PROTO(match.mask->ip_proto); - } - } - } - - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) { - u32 supp_flags = FLOW_DIS_IS_FRAGMENT | FLOW_DIS_FIRST_FRAG; - struct flow_match_control match; - - flow_rule_match_control(rule, &match); - if (!flow_rule_is_supp_control_flags(supp_flags, - match.mask->flags, extack)) - return -EOPNOTSUPP; - - if (match.mask->flags & FLOW_DIS_IS_FRAGMENT) { - bool set = match.key->flags & FLOW_DIS_IS_FRAGMENT; - - size = yt921x_acl_entries_set_is_fragment(entries, size, - set); - if (!size) - goto err; - } - if (match.mask->flags & FLOW_DIS_FIRST_FRAG) { - bool set = match.key->flags & FLOW_DIS_FIRST_FRAG; - - size = yt921x_acl_entries_set_first_frag(entries, size, - set); - if (!size) - goto err; - } - } - - /* Misc only */ - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP)) { - struct flow_match_ip match; - - flow_rule_match_ip(rule, &match); - if (match.mask->ttl) { - NL_SET_ERR_MSG_MOD(extack, - "Matching on TTL not supported"); - return -EOPNOTSUPP; - } - - if (match.mask->tos) { - entry = yt921x_acl_entries_find(entries, &size, - YT921X_ACL_TYPE_MISC); - if (!entry) - goto err; - - entry->key[0] |= YT921X_ACL_BINa_MISC_TOS(match.key->tos); - entry->mask[0] |= YT921X_ACL_BINa_MISC_TOS(match.mask->tos); - } - } - - if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_TCP)) { - struct flow_match_tcp match; - - flow_rule_match_tcp(rule, &match); - if (match.mask->flags & htons(~0xff)) { - NL_SET_ERR_MSG_MOD(extack, "Unsupported TCP flags"); - return -EOPNOTSUPP; - } - - if (match.mask->flags) { - entry = yt921x_acl_entries_find(entries, &size, - YT921X_ACL_TYPE_MISC); - if (!entry) - goto err; - - entry->key[0] |= YT921X_ACL_BINa_MISC_TCP_FLAGS(ntohs(match.key->flags)); - entry->mask[0] |= YT921X_ACL_BINa_MISC_TCP_FLAGS(ntohs(match.mask->flags)); - } - } - - if (!size) { - NL_SET_ERR_MSG_MOD(extack, "Empty rule generated, this should not happen"); - return -EOPNOTSUPP; - } - - ruleext->r.mask = (1 << size) - 1; - return 0; - -err: - NL_SET_ERR_MSG_MOD(extack, "Rule too complex"); - return -EOPNOTSUPP; -} - -static int -yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, - const struct flow_cls_offload *cls, - struct yt921x_priv *priv, int port) -{ - const struct flow_rule *rule = flow_cls_offload_flow_rule(cls); - const struct flow_action *flow_action = &rule->action; - struct netlink_ext_ack *extack = cls->common.extack; - enum flow_action_id redir_act = NUM_FLOW_ACTIONS; - const struct flow_action_entry *act; - u32 *action = ruleext->r.action; - bool seen_priority = false; - const char *reason = NULL; - bool seen_police = false; - unsigned int i; - int res; - - memset(action, 0, 3 * sizeof(*action)); - flow_action_for_each(i, act, flow_action) - switch (act->id) { - case FLOW_ACTION_ACCEPT: - case FLOW_ACTION_DROP: - case FLOW_ACTION_REDIRECT: - if (redir_act != NUM_FLOW_ACTIONS && - redir_act != act->id) { - reason = "Different redirect actions"; - goto fallback; - } - redir_act = act->id; - - switch (act->id) { - case FLOW_ACTION_ACCEPT: - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_FWD; - break; - case FLOW_ACTION_DROP: - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_REDIR; - break; - case FLOW_ACTION_REDIRECT: { - struct dsa_port *to_dp; - - to_dp = dsa_port_from_netdev(act->dev); - if (IS_ERR(to_dp) || to_dp->ds != &priv->ds) { - reason = "Redirect to non-local port"; - goto fallback; - } - - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_REDIR | - YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index); - break; - } - default: - break; - } - break; - case FLOW_ACTION_PRIORITY: - if (seen_priority) { - action[0] &= ~YT921X_ACL_ACTa_PRIO_EN; - action[1] &= ~YT921X_ACL_ACTb_PRIO_M; - - reason = "Multiple priority actions"; - goto fallback; - } - seen_priority = true; - - if (act->priority >= YT921X_PRIO_NUM) { - NL_SET_ERR_MSG_MOD(extack, - "Priority value is too high"); - return -EOPNOTSUPP; - } - action[0] |= YT921X_ACL_ACTa_PRIO_EN; - action[1] |= YT921X_ACL_ACTb_PRIO(act->priority); - break; - case FLOW_ACTION_POLICE: { - const struct flow_action_police *police = &act->police; - - if (seen_police) { - action[0] &= ~YT921X_ACL_ACTa_METER_EN; - - reason = "Multiple police actions"; - goto fallback; - } - seen_police = true; - - res = yt921x_police_validate(police, flow_action, act, - extack); - if (res) - return res; - - res = yt921x_marker_tfm_police(&ruleext->marker, police, - 0, priv, port, extack); - if (res) - return res; - - action[0] |= YT921X_ACL_ACTa_METER_EN; - break; - } - default: -fallback: - if (cls->common.skip_sw) { - NL_SET_ERR_MSG_FMT_MOD(extack, - "Action not supported when skip_sw: %s", - reason); - return -EOPNOTSUPP; - } - fallthrough; - case FLOW_ACTION_TRAP: - redir_act = FLOW_ACTION_TRAP; - - action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M & - ~YT921X_ACL_ACTc_FWD_M; - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_TRAP; - break; - } - - ruleext->r.sw_assisted = !cls->common.skip_sw; - return 0; -} - -static int -yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, - const struct flow_cls_offload *cls, bool ingress, - struct yt921x_priv *priv) -{ - struct netlink_ext_ack *extack = cls->common.extack; - int res; - - if (!ingress) { - NL_SET_ERR_MSG_MOD(extack, "Only ingress is supported"); - return -EOPNOTSUPP; - } - - if (cls->common.chain_index) { - NL_SET_ERR_MSG(extack, "Only chain 0 is supported"); - return -EOPNOTSUPP; - } - - res = yt921x_acl_rule_ext_parse_flow_action(ruleext, cls, priv, port); - if (res) - return res; - res = yt921x_acl_rule_ext_parse_flow_entries(ruleext, cls); - if (res) - return res; - - yt921x_acl_rule_set_ports(&ruleext->r, 0, BIT(port)); - ruleext->r.tag = cls->cookie; - ruleext->r.type = TC_SETUP_CLSFLOWER; - return 0; -} - -static unsigned int -yt921x_acl_find(const struct yt921x_priv *priv, enum tc_setup_type type, - unsigned long tag) -{ - for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) { - const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid]; - - if (!aclblk) - continue; - - for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) - if (aclblk->rules[i] && aclblk->rules[i]->tag == tag && - aclblk->rules[i]->type == type) - return YT921X_ACL_ENT_PER_BLK * blkid + i; - } - - return UINT_MAX; -} - -static unsigned int -yt921x_acl_reserve(struct yt921x_priv *priv, unsigned int entscnt, - struct netlink_ext_ack *extack) -{ - int candidates[YT921X_ACL_ENT_PER_BLK + 1]; - unsigned int acl_used_cnt = 0; - - if (WARN_ON(entscnt > YT921X_ACL_ENT_PER_BLK)) - return UINT_MAX; - - for (unsigned int i = 0; i < ARRAY_SIZE(candidates); i++) - candidates[i] = -1; - for (unsigned int i = YT921X_ACL_BLK_NUM; i-- > 0;) { - unsigned int blk_used_cnt = hweight8(priv->acl_masks[i]); - - candidates[blk_used_cnt] = i; - acl_used_cnt += blk_used_cnt; - } - - if (acl_used_cnt >= YT921X_ACL_NUM) { - NL_SET_ERR_MSG_MOD(extack, "ACL entry limit reached"); - return UINT_MAX; - } - if (acl_used_cnt + entscnt <= YT921X_ACL_NUM) - for (unsigned int i = YT921X_ACL_ENT_PER_BLK - entscnt + 1; - i-- > 0;) - if (candidates[i] >= 0) - return YT921X_ACL_ENT_PER_BLK * candidates[i] + - ffz(priv->acl_masks[candidates[i]]); - - NL_SET_ERR_MSG_MOD(extack, - "ACL entry allocation failed, simplify your rules or remove existing rules"); - return UINT_MAX; -} - -static int -yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) -{ - const struct yt921x_acl_rule *aclrule; - const struct yt921x_acl_blk *aclblk; - unsigned int blkid; - unsigned int binid; - unsigned long mask; - u32 zeros[3] = {}; - unsigned int i; - unsigned int o; - u32 ctrl; - int res; - - blkid = entid / YT921X_ACL_ENT_PER_BLK; - binid = entid % YT921X_ACL_ENT_PER_BLK; - aclblk = priv->acl_blks[blkid]; - aclrule = aclblk->rules[binid]; - - /* Write actions */ - res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), - aclrule ? aclrule->action : zeros); - if (res) - return res; - - /* Select the block */ - ctrl = YT921X_ACL_BLK_CMD_MODIFY | YT921X_ACL_BLK_CMD_BLKID(blkid); - res = yt921x_reg_write(priv, YT921X_ACL_BLK_CMD, ctrl); - if (res) - return res; - - /* Write keys and masks */ - ctrl = 0; - for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) - ctrl |= YT921X_ACL_BLK_KEEP_KEEPn(i); - - mask = entsmask; - i = 0; - for_each_set_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) { - res = yt921x_reg64_write(priv, YT921X_ACLn_KEYm(blkid, o), - aclrule ? aclrule->entries[i].key : - zeros); - if (res) - return res; - - res = yt921x_reg64_write(priv, YT921X_ACLn_MASKm(blkid, o), - aclrule ? aclrule->entries[i].mask : - zeros); - if (res) - return res; - - ctrl &= ~YT921X_ACL_BLK_KEEP_KEEPn(o); - i++; - } - - res = yt921x_reg_write(priv, YT921X_ACL_BLK_KEEP, ctrl); - if (res) - return res; - - ctrl = 0; - for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) { - const struct yt921x_acl_rule *other = aclblk->rules[i]; - - if (!other) - continue; - - mask = other->mask; - for_each_set_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) - ctrl |= YT921X_ACL_ENTRY_ENm(o) | - YT921X_ACL_ENTRY_GRPIDm(o, i); - } - res = yt921x_reg_write(priv, YT921X_ACLn_ENTRY(blkid), ctrl); - if (res) - return res; - - /* Commit the block */ - ctrl = YT921X_ACL_BLK_CMD_BLKID(blkid); - res = yt921x_reg_write(priv, YT921X_ACL_BLK_CMD, ctrl); - if (res) - return res; - - return 0; -} - -static int -yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, - unsigned long tag) -{ - struct yt921x_acl_rule *aclrule; - struct yt921x_acl_blk *aclblk; - unsigned int binid; - unsigned int blkid; - unsigned int entid; - int res; - - entid = yt921x_acl_find(priv, type, tag); - if (entid == UINT_MAX) - return -ENOENT; - - blkid = entid / YT921X_ACL_ENT_PER_BLK; - binid = entid % YT921X_ACL_ENT_PER_BLK; - aclblk = priv->acl_blks[blkid]; - aclrule = aclblk->rules[binid]; - - aclblk->rules[binid] = NULL; - res = yt921x_acl_commit(priv, entid, aclrule->mask); - /* the kernel never rolls back on failure */ - - if (aclrule->action[0] & YT921X_ACL_ACTa_METER_EN) - clear_bit(FIELD_GET(YT921X_ACL_ACTa_METER_ID_M, - aclrule->action[0]), - priv->meters_map); - priv->acl_masks[blkid] &= ~aclrule->mask; - kvfree(aclrule); - if (!priv->acl_masks[blkid]) { - kvfree(aclblk); - priv->acl_blks[blkid] = NULL; - } - return res; -} - -static int -yt921x_acl_add(struct yt921x_priv *priv, - const struct yt921x_acl_rule_ext *ruleext, - struct netlink_ext_ack *extack) -{ - unsigned int entscnt = hweight8(ruleext->r.mask); - struct yt921x_acl_rule *aclrule; - struct yt921x_acl_blk *aclblk; - bool use_trap = false; - unsigned int meterid; - unsigned long mask; - unsigned int binid; - unsigned int blkid; - unsigned int entid; - unsigned int o; - int res; - - /* Allocate resources */ - entid = yt921x_acl_reserve(priv, entscnt, extack); - if (entid == UINT_MAX) - return -EOPNOTSUPP; - - if (!(ruleext->r.action[0] & YT921X_ACL_ACTa_METER_EN)) { - meterid = YT921X_METER_NUM; - } else { - meterid = find_first_zero_bit(priv->meters_map, - YT921X_METER_NUM); - if (meterid < YT921X_METER_NUM) { - res = yt921x_meter_config(priv, meterid, - &ruleext->marker); - if (res) - return res; - } else if (ruleext->r.sw_assisted) { - use_trap = true; - } else { - NL_SET_ERR_MSG_MOD(extack, - "No more meters available"); - return -EOPNOTSUPP; - } - } - - /* Prepare acl block ctrlblk */ - blkid = entid / YT921X_ACL_ENT_PER_BLK; - binid = entid % YT921X_ACL_ENT_PER_BLK; - aclblk = priv->acl_blks[blkid]; - if (!aclblk) { - aclblk = kvzalloc_obj(*aclblk); - if (!aclblk) - return -ENOMEM; - priv->acl_blks[blkid] = aclblk; - } - - /* Prepare acl rule ctrlblk */ - aclrule = kvmemdup(&ruleext->r, - offsetof(struct yt921x_acl_rule, entries[entscnt]), - GFP_KERNEL); - if (!aclrule) { - res = -ENOMEM; - goto err; - } - - /* Replace the placeholder resource IDs */ - aclrule->mask = 0; - mask = priv->acl_masks[blkid]; - for_each_clear_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) { - aclrule->mask |= BIT(o); - entscnt--; - if (!entscnt) - break; - } - - if (use_trap) { - aclrule->action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M & - ~YT921X_ACL_ACTc_FWD_M; - aclrule->action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_TRAP; - } - if (meterid < YT921X_METER_NUM) - aclrule->action[0] |= YT921X_ACL_ACTa_METER_ID(meterid); - else - aclrule->action[0] &= ~YT921X_ACL_ACTa_METER_EN; - - /* Write rules */ - aclblk->rules[binid] = aclrule; - res = yt921x_acl_commit(priv, entid, aclrule->mask); - if (res) { - aclblk->rules[binid] = NULL; - kvfree(aclrule); - goto err; - } - - if (meterid < YT921X_METER_NUM) - set_bit(meterid, priv->meters_map); - priv->acl_masks[blkid] |= aclrule->mask; - return 0; - -err: - if (!priv->acl_masks[blkid]) { - kvfree(aclblk); - priv->acl_blks[blkid] = NULL; - } - return res; -} - -static int -yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, - struct flow_cls_offload *cls, bool ingress) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_acl_del(priv, TC_SETUP_CLSFLOWER, cls->cookie); - mutex_unlock(&priv->reg_lock); - - return res; -} - -static int -yt921x_dsa_cls_flower_add(struct dsa_switch *ds, int port, - struct flow_cls_offload *cls, bool ingress) -{ - struct netlink_ext_ack *extack = cls->common.extack; - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct yt921x_acl_rule_ext ruleext; - int res; - - res = yt921x_acl_rule_ext_parse_flow(&ruleext, port, cls, ingress, - priv); - if (res) - return res; - - mutex_lock(&priv->reg_lock); - res = yt921x_acl_add(priv, &ruleext, extack); - mutex_unlock(&priv->reg_lock); - - return res; -} - -static int -yt921x_mirror_del(struct yt921x_priv *priv, int port, bool ingress) -{ - u32 mask; - - if (ingress) - mask = YT921X_MIRROR_IGR_PORTn(port); - else - mask = YT921X_MIRROR_EGR_PORTn(port); - return yt921x_reg_clear_bits(priv, YT921X_MIRROR, mask); -} - -static int -yt921x_mirror_add(struct yt921x_priv *priv, int port, bool ingress, - int to_local_port, struct netlink_ext_ack *extack) -{ - u32 srcs; - u32 ctrl; - u32 val; - u32 dst; - int res; - - if (ingress) - srcs = YT921X_MIRROR_IGR_PORTn(port); - else - srcs = YT921X_MIRROR_EGR_PORTn(port); - dst = YT921X_MIRROR_PORT(to_local_port); - - res = yt921x_reg_read(priv, YT921X_MIRROR, &val); - if (res) - return res; - - /* other mirror tasks & different dst port -> conflict */ - if ((val & ~srcs & (YT921X_MIRROR_EGR_PORTS_M | - YT921X_MIRROR_IGR_PORTS_M)) && - (val & YT921X_MIRROR_PORT_M) != dst) { - NL_SET_ERR_MSG_MOD(extack, - "Sniffer port is already configured, delete existing rules & retry"); - return -EBUSY; - } - - ctrl = val & ~YT921X_MIRROR_PORT_M; - ctrl |= srcs; - ctrl |= dst; - - if (ctrl == val) - return 0; - - return yt921x_reg_write(priv, YT921X_MIRROR, ctrl); -} - -static void -yt921x_dsa_port_mirror_del(struct dsa_switch *ds, int port, - struct dsa_mall_mirror_tc_entry *mirror) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - struct device *dev = yt921x_priv_to_device(priv); - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_mirror_del(priv, port, mirror->ingress); - mutex_unlock(&priv->reg_lock); - - if (res) - dev_err(dev, "Failed to %s port %d: %i\n", "unmirror", - port, res); -} - -static int -yt921x_dsa_port_mirror_add(struct dsa_switch *ds, int port, - struct dsa_mall_mirror_tc_entry *mirror, - bool ingress, struct netlink_ext_ack *extack) -{ - struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); - int res; - - mutex_lock(&priv->reg_lock); - res = yt921x_mirror_add(priv, port, ingress, - mirror->to_local_port, extack); - mutex_unlock(&priv->reg_lock); - - return res; -} - static int yt921x_lag_hash(struct yt921x_priv *priv, u32 ctrl, bool unique_lag, struct netlink_ext_ack *extack) { @@ -3791,48 +2335,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv) return 0; } -static int yt921x_chip_setup_tc(struct yt921x_priv *priv) -{ - unsigned int op_ns; - u32 ctrl; - int res; - - op_ns = 8 * priv->cycle_ns; - - ctrl = max(priv->meter_slot_ns / op_ns, YT921X_METER_SLOT_MIN); - res = yt921x_reg_write(priv, YT921X_METER_SLOT, ctrl); - if (res) - return res; - priv->meter_slot_ns = ctrl * op_ns; - - ctrl = max(priv->port_shape_slot_ns / op_ns, - YT921X_PORT_SHAPE_SLOT_MIN); - res = yt921x_reg_write(priv, YT921X_PORT_SHAPE_SLOT, ctrl); - if (res) - return res; - priv->port_shape_slot_ns = ctrl * op_ns; - - return 0; -} - -static int yt921x_chip_setup_acl(struct yt921x_priv *priv) -{ - u32 ctrl; - int res; - - ctrl = YT921X_ACL_PERMIT_UNMATCH_PORTS_M; - res = yt921x_reg_write(priv, YT921X_ACL_PERMIT_UNMATCH, ctrl); - if (res) - return res; - - ctrl = YT921X_ACL_PORT_PORTS_M; - res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl); - if (res) - return res; - - return 0; -} - static int __maybe_unused yt921x_chip_setup_qos(struct yt921x_priv *priv) { u32 ctrl; diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 25ff77054de3..012de4f444f5 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -371,249 +371,6 @@ enum yt921x_app_selector { #define YT921X_VLAN_CTRLa_METER_EN BIT(5) #define YT921X_VLAN_CTRLa_METER_ID_M GENMASK(4, 0) -#define YT921X_ACLn_ACT(n) (0x1c0000 + 0x10 * (n)) -#define YT921X_ACL_ACTc_STAG_M GENMASK(26, 25) -#define YT921X_ACL_ACTc_STAG(x) FIELD_PREP(YT921X_ACL_ACTc_STAG_M, (x)) -#define YT921X_ACL_ACTc_STAG_DONTCARE YT921X_ACL_ACTc_STAG(0) -#define YT921X_ACL_ACTc_STAG_UNTAG YT921X_ACL_ACTc_STAG(1) -#define YT921X_ACL_ACTc_STAG_TAG YT921X_ACL_ACTc_STAG(2) -#define YT921X_ACL_ACTc_STAG_KEEP YT921X_ACL_ACTc_STAG(3) -#define YT921X_ACL_ACTc_CTAG_M GENMASK(24, 23) -#define YT921X_ACL_ACTc_CTAG(x) FIELD_PREP(YT921X_ACL_ACTc_CTAG_M, (x)) -#define YT921X_ACL_ACTc_CTAG_DONTCARE YT921X_ACL_ACTc_CTAG(0) -#define YT921X_ACL_ACTc_CTAG_UNTAG YT921X_ACL_ACTc_CTAG(1) -#define YT921X_ACL_ACTc_CTAG_TAG YT921X_ACL_ACTc_CTAG(2) -#define YT921X_ACL_ACTc_CTAG_KEEP YT921X_ACL_ACTc_CTAG(3) -#define YT921X_ACL_ACTc_FWD_M GENMASK(22, 21) -#define YT921X_ACL_ACTc_FWD(x) FIELD_PREP(YT921X_ACL_ACTc_FWD_M, (x)) -#define YT921X_ACL_ACTc_FWD_FWD YT921X_ACL_ACTc_FWD(0) -#define YT921X_ACL_ACTc_FWD_COPY YT921X_ACL_ACTc_FWD(1) -#define YT921X_ACL_ACTc_FWD_REDIR YT921X_ACL_ACTc_FWD(2) -#define YT921X_ACL_ACTc_FWD_TRAP YT921X_ACL_ACTc_FWD(3) -#define YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M GENMASK(20, 10) -#define YT921X_ACL_ACTc_FWD_REDIR_DPORTS(x) FIELD_PREP(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M, (x)) -#define YT921X_ACL_ACTc_FWD_REDIR_DPORTn(port) BIT((port) + 10) -#define YT921X_ACL_ACTc_FWD_EN BIT(9) -#define YT921X_ACL_ACTc_SDEI BIT(8) -#define YT921X_ACL_ACTc_SDEI_REPLACE BIT(7) -#define YT921X_ACL_ACTc_SPRI_M GENMASK(6, 4) -#define YT921X_ACL_ACTc_SPRI(x) FIELD_PREP(YT921X_ACL_ACTc_SPRI_M, (x)) -#define YT921X_ACL_ACTc_SPRI_REPLACE BIT(3) -#define YT921X_ACL_ACTbc_SVID_M GENMASK_ULL(34, 23) -#define YT921X_ACL_ACTbc_SVID(x) FIELD_PREP(YT921X_ACL_ACTbc_SVID_M, (x)) -#define YT921X_ACL_ACTb_SVID_REPLACE BIT(22) -#define YT921X_ACL_ACTb_CDEI BIT(21) -#define YT921X_ACL_ACTb_CDEI_REPLACE BIT(20) -#define YT921X_ACL_ACTb_CPRI_M GENMASK(19, 17) -#define YT921X_ACL_ACTb_CPRI(x) FIELD_PREP(YT921X_ACL_ACTb_CPRI_M, (x)) -#define YT921X_ACL_ACTb_CPRI_REPLACE BIT(16) -#define YT921X_ACL_ACTb_CVID_M GENMASK(15, 4) -#define YT921X_ACL_ACTb_CVID(x) FIELD_PREP(YT921X_ACL_ACTb_CVID_M, (x)) -#define YT921X_ACL_ACTb_CVID_REPLACE BIT(3) -#define YT921X_ACL_ACTb_PRIO_M GENMASK(2, 0) -#define YT921X_ACL_ACTb_PRIO(x) FIELD_PREP(YT921X_ACL_ACTb_PRIO_M, (x)) -#define YT921X_ACL_ACTa_PRIO_EN BIT(31) -#define YT921X_ACL_ACTa_COLOR_M GENMASK(30, 29) -#define YT921X_ACL_ACTa_COLOR(x) FIELD_PREP(YT921X_ACL_ACTa_COLOR_M, (x)) -#define YT921X_ACL_ACTa_COLOR_GREEN YT921X_ACL_ACTa_COLOR(0) -#define YT921X_ACL_ACTa_COLOR_YELLOW YT921X_ACL_ACTa_COLOR(1) -#define YT921X_ACL_ACTa_COLOR_RED YT921X_ACL_ACTa_COLOR(2) -#define YT921X_ACL_ACTa_COLOR_EN BIT(28) -#define YT921X_ACL_ACTa_DSCP_M GENMASK(27, 22) -#define YT921X_ACL_ACTa_DSCP(x) FIELD_PREP(YT921X_ACL_ACTa_DSCP_M, (x)) -#define YT921X_ACL_ACTa_DSCP_REPLACE BIT(21) -#define YT921X_ACL_ACTa_METER_ID_M GENMASK(20, 15) -#define YT921X_ACL_ACTa_METER_ID(x) FIELD_PREP(YT921X_ACL_ACTa_METER_ID_M, (x)) -#define YT921X_ACL_ACTa_METER_EN BIT(14) -#define YT921X_ACL_ACTa_MIRROR_EN BIT(13) -#define YT921X_ACL_ACTa_FLOWSTAT_EN BIT(12) -#define YT921X_ACL_ACTa_FLOWSTAT_ID_M GENMASK(11, 6) -#define YT921X_ACL_ACTa_FLOWSTAT_ID(x) FIELD_PREP(YT921X_ACL_ACTa_FLOWSTAT_ID_M, (x)) -#define YT921X_ACL_ACTa_GPIO_EN BIT(5) -#define YT921X_ACL_ACTa_GPIO_PIN_M GENMASK(4, 1) -#define YT921X_ACL_ACTa_GPIO_PIN(x) FIELD_PREP(YT921X_ACL_ACTa_GPIO_PIN_M, (x)) -#define YT921X_ACL_ACTa_INTR_EN BIT(0) -#define YT921X_ACL_BLK_KEEP 0x201000 -#define YT921X_ACL_BLK_KEEP_GRPIDn_M(bin) (7 << (4 * (bin) + 1)) -#define YT921X_ACL_BLK_KEEP_GRPIDn(bin, x) ((x) << (4 * (bin) + 1)) -#define YT921X_ACL_BLK_KEEP_KEEPn(bin) BIT(4 * (bin)) -#define YT921X_ACL_PORT 0x202000 -#define YT921X_ACL_PORT_PORTS_M GENMASK(10, 0) -#define YT921X_ACL_PORT_PORTS(x) FIELD_PREP(YT921X_ACL_PORT_PORTS_M, (x)) -#define YT921X_ACL_PORT_PORTn(port) BIT(port) -#define YT921X_ACL_BLK_CMD 0x202004 -#define YT921X_ACL_BLK_CMD_BLKID_M GENMASK(6, 1) -#define YT921X_ACL_BLK_CMD_BLKID(x) FIELD_PREP(YT921X_ACL_BLK_CMD_BLKID_M, (x)) -#define YT921X_ACL_BLK_CMD_MODIFY BIT(0) -#define YT921X_ACLn_ENTRY(blk) (0x203000 + 4 * (blk)) -#define YT921X_ACL_ENTRY_GRPIDm_M(bin) (7 << (4 * (bin) + 1)) -#define YT921X_ACL_ENTRY_GRPIDm(bin, x) ((x) << (4 * (bin) + 1)) -#define YT921X_ACL_ENTRY_ENm(bin) BIT(4 * (bin)) -#define YT921X_ACLn_KEYm(blk, bin) (0x204000 + 0x200 * (bin) + 8 * (blk)) -#define YT921X_ACL_KEYb_ORD_M GENMASK(29, 21) -#define YT921X_ACL_KEYb_ORD(x) FIELD_PREP(YT921X_ACL_KEYb_ORD_M, (x)) -#define YT921X_ACL_KEYb_SPORTS_M GENMASK(20, 10) -#define YT921X_ACL_KEYb_SPORTS(x) FIELD_PREP(YT921X_ACL_KEYb_SPORTS_M, (x)) -#define YT921X_ACL_KEYb_SPORTn(port) BIT((port) + 10) -#define YT921X_ACL_KEYb_REVERSE BIT(9) /* reverse match */ -#define YT921X_ACL_KEYb_TYPE_M GENMASK(8, 4) -#define YT921X_ACL_KEYb_TYPE(x) FIELD_PREP(YT921X_ACL_KEYb_TYPE_M, (x)) -/* KEY_* fields need no masks */ -#define YT921X_ACLn_MASKm(blk, bin) (0x205000 + 0x200 * (bin) + 8 * (blk)) - -enum yt921x_acl_type { - YT921X_ACL_TYPE_NA, - YT921X_ACL_TYPE_MAC_DA0, - YT921X_ACL_TYPE_MAC_SA0, - YT921X_ACL_TYPE_MAC_DA1_SA1, - YT921X_ACL_TYPE_VLAN, - YT921X_ACL_TYPE_VTAG, - YT921X_ACL_TYPE_IPV4_DA, - YT921X_ACL_TYPE_IPV4_SA, - YT921X_ACL_TYPE_IPV6_DA0, - YT921X_ACL_TYPE_IPV6_DA1, - YT921X_ACL_TYPE_IPV6_DA2, - YT921X_ACL_TYPE_IPV6_DA3, - YT921X_ACL_TYPE_IPV6_SA0, - YT921X_ACL_TYPE_IPV6_SA1, - YT921X_ACL_TYPE_IPV6_SA2, - YT921X_ACL_TYPE_IPV6_SA3, - YT921X_ACL_TYPE_MISC, - YT921X_ACL_TYPE_L4, - YT921X_ACL_TYPE_UDF0, - YT921X_ACL_TYPE_UDF1, - YT921X_ACL_TYPE_UDF2, - YT921X_ACL_TYPE_UDF3, - YT921X_ACL_TYPE_UDF4, - YT921X_ACL_TYPE_UDF5, - YT921X_ACL_TYPE_UDF6, - YT921X_ACL_TYPE_UDF7, - YT921X_ACL_TYPE_ETHERTYPE, - YT921X_ACL_TYPE_NUM -}; - -/* Range: turn KEY:MASK into MIN:MAX */ - -#define YT921X_ACL_BINb_MAC_xA0_L3_TYPE_M GENMASK(3, 0) -#define YT921X_ACL_BINb_MAC_xA0_L3_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_MAC_xA0_L3_TYPE_M, (x)) -#define YT921X_ACL_BINa_MAC_xA0_MAC_xA0_M GENMASK(31, 0) - -#define YT921X_ACL_BINb_MAC_DA1_SA1_L2_TYPE_M GENMASK(2, 0) -#define YT921X_ACL_BINb_MAC_DA1_SA1_L2_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_MAC_DA1_SA1_L2_TYPE_M, (x)) -#define YT921X_ACL_BINa_MAC_DA1_SA1_MAC_DA1_M GENMASK(31, 16) -#define YT921X_ACL_BINa_MAC_DA1_SA1_MAC_SA1_M GENMASK(15, 0) - -#define YT921X_ACL_KEYb_VLAN_SVID_RANGE_EN BIT(31) -#define YT921X_ACL_KEYb_VLAN_CVID_RANGE_EN BIT(30) -#define YT921X_ACL_BINb_VLAN_CDEI BIT(3) -#define YT921X_ACL_BINb_VLAN_CPRI_M GENMASK(2, 0) -#define YT921X_ACL_BINb_VLAN_CPRI(x) FIELD_PREP(YT921X_ACL_BINb_VLAN_CPRI_M, (x)) -#define YT921X_ACL_BINa_VLAN_CTAG_FMT_M GENMASK(31, 30) -#define YT921X_ACL_BINa_VLAN_CTAG_FMT(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_CTAG_FMT_M, (x)) -#define YT921X_ACL_BINa_VLAN_SDEI BIT(29) -#define YT921X_ACL_BINa_VLAN_SPRI_M GENMASK(28, 26) -#define YT921X_ACL_BINa_VLAN_SPRI(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_SPRI_M, (x)) -#define YT921X_ACL_BINa_VLAN_STAG_FMT_M GENMASK(25, 24) -#define YT921X_ACL_BINa_VLAN_STAG_FMT(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_STAG_FMT_M, (x)) -#define YT921X_ACL_BINa_VLAN_SVID_M GENMASK(23, 12) -#define YT921X_ACL_BINa_VLAN_SVID(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_SVID_M, (x)) -#define YT921X_ACL_BINa_VLAN_CVID_M GENMASK(11, 0) -#define YT921X_ACL_BINa_VLAN_CVID(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_CVID_M, (x)) - -#define YT921X_ACL_KEYb_VTAG_SVID_RANGE_EN BIT(31) -#define YT921X_ACL_KEYb_VTAG_CVID_RANGE_EN BIT(30) -#define YT921X_ACL_BINa_VTAG_CDEI BIT(31) -#define YT921X_ACL_BINa_VTAG_CPRI_M GENMASK(30, 28) -#define YT921X_ACL_BINa_VTAG_CPRI(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_CPRI_M, (x)) -#define YT921X_ACL_BINa_VTAG_SDEI BIT(27) -#define YT921X_ACL_BINa_VTAG_SPRI_M GENMASK(26, 24) -#define YT921X_ACL_BINa_VTAG_SPRI(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_SPRI_M, (x)) -#define YT921X_ACL_BINa_VTAG_SVID_M GENMASK(23, 12) -#define YT921X_ACL_BINa_VTAG_SVID(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_SVID_M, (x)) -#define YT921X_ACL_BINa_VTAG_CVID_M GENMASK(11, 0) -#define YT921X_ACL_BINa_VTAG_CVID(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_CVID_M, (x)) - -#define YT921X_ACL_KEYb_IPV4_ADDR_RANGE_EN BIT(30) -#define YT921X_ACL_BINb_IPV4_FRAG BIT(3) -#define YT921X_ACL_BINb_IPV4_L4_TYPE_M GENMASK(2, 0) -#define YT921X_ACL_BINb_IPV4_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_IPV4_L4_TYPE_M, (x)) -#define YT921X_ACL_BINa_IPV4_ADDR_M GENMASK(31, 0) - -#define YT921X_ACL_BINb_IPV6_L4_TYPE_M GENMASK(2, 0) -#define YT921X_ACL_BINb_IPV6_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_IPV6_L4_TYPE_M, (x)) -#define YT921X_ACL_BINa_IPV6_ADDRx_M GENMASK(31, 0) - -#define YT921X_ACL_BINb_IPV6_xA1_IP_OPTION BIT(3) - -#define YT921X_ACL_BINb_IPV6_xA2_FIRST_FRAG BIT(3) - -#define YT921X_ACL_KEYb_IPV6_xA3_ADDR_RANGE_EN BIT(30) -#define YT921X_ACL_BINb_IPV6_xA3_FRAG BIT(3) - -#define YT921X_ACL_BINb_MISC_FRAG BIT(3) -#define YT921X_ACL_BINb_MISC_L4_TYPE_M GENMASK(2, 0) -#define YT921X_ACL_BINb_MISC_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_MISC_L4_TYPE_M, (x)) -#define YT921X_ACL_BINa_MISC_PPPOE_FLAG BIT(30) -#define YT921X_ACL_BINa_MISC_FIRST_FRAG BIT(29) -#define YT921X_ACL_BINa_MISC_IP_OPTION BIT(28) -#define YT921X_ACL_BINa_MISC_TCP_FLAGS_M GENMASK(27, 20) -#define YT921X_ACL_BINa_MISC_TCP_FLAGS(x) FIELD_PREP(YT921X_ACL_BINa_MISC_TCP_FLAGS_M, (x)) -#define YT921X_ACL_BINa_MISC_IP_PROTO_M GENMASK(19, 12) -#define YT921X_ACL_BINa_MISC_IP_PROTO(x) FIELD_PREP(YT921X_ACL_BINa_MISC_IP_PROTO_M, (x)) -#define YT921X_ACL_BINa_MISC_TOS_M GENMASK(11, 4) -#define YT921X_ACL_BINa_MISC_TOS(x) FIELD_PREP(YT921X_ACL_BINa_MISC_TOS_M, (x)) -#define YT921X_ACL_BINa_MISC_L3_TYPE_M GENMASK(3, 0) -#define YT921X_ACL_BINa_MISC_L3_TYPE(x) FIELD_PREP(YT921X_ACL_BINa_MISC_L3_TYPE_M, (x)) - -#define YT921X_ACL_KEYb_L4_DPORT_RANGE_EN BIT(31) -#define YT921X_ACL_KEYb_L4_SPORT_RANGE_EN BIT(30) -#define YT921X_ACL_BINb_L4_FRAG BIT(3) -#define YT921X_ACL_BINb_L4_TYPE_M GENMASK(2, 0) -#define YT921X_ACL_BINb_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_L4_TYPE_M, (x)) -#define YT921X_ACL_BINa_L4_DPORT_M GENMASK(31, 16) -#define YT921X_ACL_BINa_L4_SPORT_M GENMASK(15, 0) - -#define YT921X_ACL_BINb_UDF_IS_IGMP BIT(0) -#define YT921X_ACL_BINa_UDF_UDF0_M GENMASK(31, 16) -#define YT921X_ACL_BINa_UDF_UDF0(x) FIELD_PREP(YT921X_ACL_BINa_UDF_UDF0_M, (x)) -#define YT921X_ACL_BINa_UDF_UDF1_M GENMASK(15, 0) -#define YT921X_ACL_BINa_UDF_UDF1(x) FIELD_PREP(YT921X_ACL_BINa_UDF_UDF1_M, (x)) - -#define YT921X_ACL_KEYb_ETHERTYPE_ETHERTYPE_RANGE_EN BIT(30) -#define YT921X_ACL_BINb_ETHERTYPE_L4_TYPE_M GENMASK(2, 0) -#define YT921X_ACL_BINb_ETHERTYPE_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_ETHERTYPE_L4_TYPE_M, (x)) -#define YT921X_ACL_BINa_ETHERTYPE_ETHERTYPE_M GENMASK(15, 0) -#define YT921X_ACL_BINa_ETHERTYPE_ETHERTYPE(x) FIELD_PREP(YT921X_ACL_BINa_ETHERTYPE_ETHERTYPE_M, (x)) - -enum yt921x_l2_type { - YT921X_L2_TYPE_ETH, - YT921X_L2_TYPE_ETHV2, - YT921X_L2_TYPE_ETHSAP, - YT921X_L2_TYPE_ETHSNAP, -}; - -enum yt921x_l3_type { - YT921X_L3_TYPE_OTHER, - YT921X_L3_TYPE_IPV4, - YT921X_L3_TYPE_IPV6, - YT921X_L3_TYPE_ARP, - YT921X_L3_TYPE_LLDP, - YT921X_L3_TYPE_PAE, - YT921X_L3_TYPE_ERP, - YT921X_L3_TYPE_SLOW_PROTOCOL, -}; - -enum yt921x_l4_type { - YT921X_L4_TYPE_OTHER, - YT921X_L4_TYPE_TCP, - YT921X_L4_TYPE_UDP, - YT921X_L4_TYPE_UDPLITE, - YT921X_L4_TYPE_ICMP, - YT921X_L4_TYPE_IGMP, - YT921X_L4_TYPE_MLD, - YT921X_L4_TYPE_ND, -}; - #define YT921X_TPID_IGRn(x) (0x210000 + 4 * (x)) /* [0, 3] */ #define YT921X_TPID_IGR_TPID_M GENMASK(15, 0) #define YT921X_PORTn_IGR_TPID(port) (0x210010 + 4 * (port)) @@ -630,47 +387,6 @@ enum yt921x_l4_type { #define YT921X_LAG_HASH_MAC_SA BIT(2) #define YT921X_LAG_HASH_MAC_DA BIT(1) #define YT921X_LAG_HASH_SRC_PORT BIT(0) -#define YT921X_UDFn_CTRL(x) (0x210094 + 4 * (x)) -#define YT921X_UDF_CTRL_UDF_TYPE_M GENMASK(8, 7) -#define YT921X_UDF_CTRL_UDF_TYPE(x) FIELD_PREP(YT921X_UDF_CTRL_UDF_TYPE_M, (x)) -#define YT921X_UDF_CTRL_UDF_TYPE_ETH YT921X_UDF_CTRL_UDF_TYPE(0) -#define YT921X_UDF_CTRL_UDF_TYPE_L3 YT921X_UDF_CTRL_UDF_TYPE(1) -#define YT921X_UDF_CTRL_UDF_TYPE_L4 YT921X_UDF_CTRL_UDF_TYPE(2) -#define YT921X_UDF_CTRL_UDF_OFFSET_M GENMASK(6, 0) -#define YT921X_UDF_CTRL_UDF_OFFSET(x) FIELD_PREP(YT921X_UDF_CTRL_UDF_OFFSET_M, (x)) - -#define YT921X_PORTn_RATE(port) (0x220000 + 4 * (port)) -#define YT921X_PORT_RATE_GAP_VALUE GENMASK(4, 0) /* default 20 */ -#define YT921X_METER_SLOT 0x220104 -#define YT921X_METER_SLOT_SLOT_M GENMASK(11, 0) -#define YT921X_PORTn_METER(port) (0x220108 + 4 * (port)) -#define YT921X_PORT_METER_EN BIT(4) -#define YT921X_PORT_METER_ID_M GENMASK(3, 0) -#define YT921X_PORT_METER_ID(x) FIELD_PREP(YT921X_PORT_METER_ID_M, (x)) -#define YT921X_METERn_CTRL(x) (0x220800 + 0x10 * (x)) -#define YT921X_METER_CTRLc_METER_EN BIT(14) -#define YT921X_METER_CTRLc_TOKEN_OVERFLOW_EN BIT(13) /* RFC4115: yellow use unused green bw */ -#define YT921X_METER_CTRLc_DROP_M GENMASK(12, 11) -#define YT921X_METER_CTRLc_DROP(x) FIELD_PREP(YT921X_METER_CTRLc_DROP_M, (x)) -#define YT921X_METER_CTRLc_DROP_GYR YT921X_METER_CTRLc_DROP(0) -#define YT921X_METER_CTRLc_DROP_YR YT921X_METER_CTRLc_DROP(1) -#define YT921X_METER_CTRLc_DROP_R YT921X_METER_CTRLc_DROP(2) -#define YT921X_METER_CTRLc_DROP_NONE YT921X_METER_CTRLc_DROP(3) -#define YT921X_METER_CTRLc_COLOR_BLIND BIT(10) -#define YT921X_METER_CTRLc_UNIT_M GENMASK(9, 7) -#define YT921X_METER_CTRLc_UNIT(x) FIELD_PREP(YT921X_METER_CTRLc_UNIT_M, (x)) -#define YT921X_METER_CTRLc_BYTE_MODE_INCLUDE_GAP BIT(6) /* +GAP_VALUE bytes each packet */ -#define YT921X_METER_CTRLc_PKT_MODE BIT(5) /* 0: byte rate mode */ -#define YT921X_METER_CTRLc_RFC2698 BIT(4) /* 0: RFC4115 */ -#define YT921X_METER_CTRLbc_CBS_M GENMASK_ULL(35, 20) -#define YT921X_METER_CTRLbc_CBS(x) FIELD_PREP(YT921X_METER_CTRLbc_CBS_M, (x)) -#define YT921X_METER_CTRLb_CIR_M GENMASK(19, 2) -#define YT921X_METER_CTRLb_CIR(x) FIELD_PREP(YT921X_METER_CTRLb_CIR_M, (x)) -#define YT921X_METER_CTRLab_EBS_M GENMASK_ULL(33, 18) -#define YT921X_METER_CTRLab_EBS(x) FIELD_PREP(YT921X_METER_CTRLab_EBS_M, (x)) -#define YT921X_METER_CTRLa_EIR_M GENMASK(17, 0) -#define YT921X_METER_CTRLa_EIR(x) FIELD_PREP(YT921X_METER_CTRLa_EIR_M, (x)) -#define YT921X_METERn_STAT(x) (0x221000 + 8 * (x)) #define YT921X_PORTn_VLAN_CTRL(port) (0x230010 + 4 * (port)) #define YT921X_PORT_VLAN_CTRL_SVLAN_PRIO_EN BIT(31) @@ -689,29 +405,6 @@ enum yt921x_l4_type { #define YT921X_PORT_VLAN_CTRL1_CVLAN_DROP_TAGGED BIT(1) #define YT921X_PORT_VLAN_CTRL1_CVLAN_DROP_UNTAGGED BIT(0) -#define YT921X_MIRROR 0x300300 -#define YT921X_MIRROR_IGR_PORTS_M GENMASK(26, 16) -#define YT921X_MIRROR_IGR_PORTS(x) FIELD_PREP(YT921X_MIRROR_IGR_PORTS_M, (x)) -#define YT921X_MIRROR_IGR_PORTn(port) BIT((port) + 16) -#define YT921X_MIRROR_EGR_PORTS_M GENMASK(14, 4) -#define YT921X_MIRROR_EGR_PORTS(x) FIELD_PREP(YT921X_MIRROR_EGR_PORTS_M, (x)) -#define YT921X_MIRROR_EGR_PORTn(port) BIT((port) + 4) -#define YT921X_MIRROR_PORT_M GENMASK(3, 0) -#define YT921X_MIRROR_PORT(x) FIELD_PREP(YT921X_MIRROR_PORT_M, (x)) - -#define YT921X_PORT_SHAPE_SLOT 0x34000c -#define YT921X_PORT_SHAPE_SLOT_SLOT_M GENMASK(11, 0) -#define YT921X_PORTn_SHAPE_CTRL(port) (0x354000 + 8 * (port)) -#define YT921X_PORT_SHAPE_CTRLb_EN BIT(4) -#define YT921X_PORT_SHAPE_CTRLb_PKT_MODE BIT(3) /* 0: byte rate mode */ -#define YT921X_PORT_SHAPE_CTRLb_UNIT_M GENMASK(2, 0) -#define YT921X_PORT_SHAPE_CTRLb_UNIT(x) FIELD_PREP(YT921X_PORT_SHAPE_CTRLb_UNIT_M, (x)) -#define YT921X_PORT_SHAPE_CTRLa_CBS_M GENMASK(31, 18) -#define YT921X_PORT_SHAPE_CTRLa_CBS(x) FIELD_PREP(YT921X_PORT_SHAPE_CTRLa_CBS_M, (x)) -#define YT921X_PORT_SHAPE_CTRLa_CIR_M GENMASK(17, 0) -#define YT921X_PORT_SHAPE_CTRLa_CIR(x) FIELD_PREP(YT921X_PORT_SHAPE_CTRLa_CIR_M, (x)) -#define YT921X_PORTn_SHAPE_STAT(port) (0x356000 + 4 * (port)) - #define YT921X_EDATA_EXTMODE 0xfb #define YT921X_EDATA_LEN 0x100 @@ -728,19 +421,8 @@ enum yt921x_fdb_entry_status { #define YT921X_MSTI_NUM 16 -#define YT921X_TOKEN_BYTE_C 1 /* 1 token = 2^1 byte */ -#define YT921X_TOKEN_PKT_C -6 /* 1 token = 2^-6 packets */ -#define YT921X_TOKEN_RATE_C -15 /* Custom meters only, not including dedicated port meters (11) */ #define YT921X_METER_NUM 64 -#define YT921X_METER_SLOT_MIN 80 -#define YT921X_METER_UNIT_MAX ((1 << 3) - 1) -#define YT921X_METER_CIR_MAX ((1 << 18) - 1) -#define YT921X_METER_CBS_MAX ((1 << 16) - 1) -#define YT921X_PORT_SHAPE_SLOT_MIN 80 -#define YT921X_SHAPE_UNIT_MAX ((1 << 3) - 1) -#define YT921X_SHAPE_CIR_MAX ((1 << 18) - 1) -#define YT921X_SHAPE_CBS_MAX ((1 << 14) - 1) #define YT921X_LAG_NUM 2 #define YT921X_LAG_PORT_NUM 4 @@ -758,8 +440,6 @@ enum yt921x_fdb_entry_status { #define YT921X_TAG_LEN 8 #define YT921X_ACL_BLK_NUM 48 -#define YT921X_ACL_ENT_PER_BLK 8 -#define YT921X_ACL_NUM (YT921X_ACL_BLK_NUM * YT921X_ACL_ENT_PER_BLK) #define YT921X_UDF_NUM 8 #define YT921X_LED_GROUP_NUM 3 @@ -770,26 +450,6 @@ enum yt921x_fdb_entry_status { #define YT921X_NAME "yt921x" -struct yt921x_acl_entry { - u32 key[2]; - u32 mask[2]; -}; - -struct yt921x_acl_rule { - unsigned long tag; - enum tc_setup_type type; - - u32 action[3]; - bool sw_assisted; - - u8 mask; - struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK]; -}; - -struct yt921x_acl_blk { - struct yt921x_acl_rule *rules[YT921X_ACL_ENT_PER_BLK]; -}; - struct yt921x_port { unsigned char index; @@ -893,4 +553,14 @@ static inline int ethtool_speed_to_yt921x(int speed) } } +static inline u32 ethaddr_hi4_to_u32(const unsigned char *addr) +{ + return (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]; +} + +static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr) +{ + return (addr[4] << 8) | addr[5]; +} + #endif diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c new file mode 100644 index 000000000000..433a428ed070 --- /dev/null +++ b/drivers/net/dsa/motorcomm/tc.c @@ -0,0 +1,1496 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 David Yang + */ + +#include "chip.h" +#include "smi.h" +#include "tc.h" + +static int yt921x_mtu_fetch(struct yt921x_priv *priv, int port) +{ + struct dsa_port *dp = dsa_to_port(&priv->ds, port); + + return dp->user ? READ_ONCE(dp->user->mtu) : ETH_DATA_LEN; +} + +/* v * 2^e */ +static u64 ldexpu64(u64 v, int e) +{ + return e >= 0 ? v << e : v >> -e; +} + +/* slot (ns) * rate (/s) / 10^9 (ns/s) = 2^C * token * 4^unit */ +static u32 rate2token(u64 rate, unsigned int slot_ns, int unit, int C) +{ + int e = 2 * unit + C + YT921X_TOKEN_RATE_C; + + return div_u64(ldexpu64(slot_ns * rate, -e), 1000000000); +} + +static u64 token2rate(u32 token, unsigned int slot_ns, int unit, int C) +{ + int e = 2 * unit + C + YT921X_TOKEN_RATE_C; + + return div_u64(ldexpu64(mul_u32_u32(1000000000, token), e), slot_ns); +} + +/* burst = 2^C * token * 4^unit */ +static u32 burst2token(u64 burst, int unit, int C) +{ + return ldexpu64(burst, -(2 * unit + C)); +} + +static u64 token2burst(u32 token, int unit, int C) +{ + return ldexpu64(token, 2 * unit + C); +} + +struct yt921x_marker { + u32 cir; + u32 cbs; + u32 ebs; + int unit; + bool pkt_mode; +}; + +#define YT921X_MARKER_PKT_MODE BIT(0) +#define YT921X_MARKER_SINGLE_BUCKET BIT(1) + +static int +yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst, + unsigned int flags, unsigned int slot_ns, u32 cir_max, + u32 cbs_max, int unit_max, struct yt921x_priv *priv, int port, + struct netlink_ext_ack *extack) +{ + const int C = flags & YT921X_MARKER_PKT_MODE ? YT921X_TOKEN_PKT_C : + YT921X_TOKEN_BYTE_C; + struct device *dev = yt921x_priv_to_device(priv); + struct yt921x_marker m; + u64 burst_est; + u64 burst_sug; + u64 burst_max; + u64 rate_max; + + m.unit = unit_max; + rate_max = token2rate(cir_max, slot_ns, m.unit, C); + burst_max = token2burst(cbs_max, m.unit, C); + + /* Check for unusual values */ + if (rate > rate_max || burst > burst_max) { + NL_SET_ERR_MSG_MOD(extack, "Unexpected tremendous rate"); + return -ERANGE; + } + + /* Check for matching burst */ + burst_est = div_u64(slot_ns * rate, 1000000000); + burst_sug = burst_est; + if (flags & YT921X_MARKER_PKT_MODE) + burst_sug++; + else + burst_sug += ETH_HLEN + yt921x_mtu_fetch(priv, port) + + ETH_FCS_LEN; + if (burst_sug > burst) + NL_SET_ERR_MSG_FMT_MOD(extack, + "Consider match rate %llu with burst at least %llu", + rate, burst_sug); + + /* Select unit */ + for (; m.unit > 0; m.unit--) { + if (rate > (rate_max >> 2) || burst > (burst_max >> 2)) + break; + rate_max >>= 2; + burst_max >>= 2; + } + + /* Calculate information rate and bucket size */ + m.cir = rate2token(rate, slot_ns, m.unit, C); + if (!m.cir) + m.cir = 1; + else if (WARN_ON(m.cir > cir_max)) + m.cir = cir_max; + m.cbs = burst2token(burst, m.unit, C); + if (!m.cbs) + m.cbs = 1; + else if (WARN_ON(m.cbs > cbs_max)) + m.cbs = cbs_max; + + /* Cut EBS */ + m.ebs = 0; + if (!(flags & YT921X_MARKER_SINGLE_BUCKET)) { + /* We don't have a chance to adjust rate when MTU is changed */ + if (flags & YT921X_MARKER_PKT_MODE) + burst_est++; + else + burst_est += YT921X_FRAME_SIZE_MAX; + + if (burst_est < burst) { + u32 pbs = m.cbs; + + m.cbs = burst2token(burst_est, m.unit, C); + if (!m.cbs) + m.cbs = 1; + else if (WARN_ON(m.cbs > cbs_max)) + m.cbs = cbs_max; + + if (pbs > m.cbs) + m.ebs = pbs - m.cbs; + } + } + + dev_dbg(dev, + "slot %u ns, rate %llu, burst %llu -> unit %d, cir %u, cbs %u, ebs %u\n", + slot_ns, rate, burst, m.unit, m.cir, m.cbs, m.ebs); + + m.pkt_mode = flags & YT921X_MARKER_PKT_MODE; + *marker = m; + return 0; +} + +static int +yt921x_marker_tfm_police(struct yt921x_marker *marker, + const struct flow_action_police *police, + unsigned int flags, struct yt921x_priv *priv, int port, + struct netlink_ext_ack *extack) +{ + bool pkt_mode = !!police->rate_pkt_ps; + u64 burst; + u64 rate; + + rate = pkt_mode ? police->rate_pkt_ps : police->rate_bytes_ps; + burst = pkt_mode ? police->burst_pkt : police->burst; + if (pkt_mode) + flags |= YT921X_MARKER_PKT_MODE; + + return yt921x_marker_tfm(marker, rate, burst, flags, + priv->meter_slot_ns, YT921X_METER_CIR_MAX, + YT921X_METER_CBS_MAX, YT921X_METER_UNIT_MAX, + priv, port, extack); +} + +static int +yt921x_marker_tfm_shape(struct yt921x_marker *marker, u64 rate, u64 burst, + unsigned int flags, struct yt921x_priv *priv, int port, + struct netlink_ext_ack *extack) +{ + return yt921x_marker_tfm(marker, rate, burst, flags, + priv->port_shape_slot_ns, YT921X_SHAPE_CIR_MAX, + YT921X_SHAPE_CBS_MAX, YT921X_SHAPE_UNIT_MAX, + priv, port, extack); +} + +static int +yt921x_police_validate(const struct flow_action_police *police, + const struct flow_action *action, + const struct flow_action_entry *act, + struct netlink_ext_ack *extack) +{ + if (police->exceed.act_id != FLOW_ACTION_DROP) { + NL_SET_ERR_MSG_MOD(extack, + "Offload not supported when exceed action is not drop"); + return -EOPNOTSUPP; + } + + if (police->notexceed.act_id != FLOW_ACTION_PIPE && + police->notexceed.act_id != FLOW_ACTION_ACCEPT) { + NL_SET_ERR_MSG_MOD(extack, + "Offload not supported when conform action is not pipe or ok"); + return -EOPNOTSUPP; + } + + if (police->notexceed.act_id == FLOW_ACTION_ACCEPT && action && act && + !flow_action_is_last_entry(action, act)) { + NL_SET_ERR_MSG_MOD(extack, + "Offload not supported when conform action is ok, but action is not last"); + return -EOPNOTSUPP; + } + + /* mtu defaults to unlimited but we got 2040 here, don't know why */ + if (police->peakrate_bytes_ps || police->avrate || police->overhead) { + NL_SET_ERR_MSG_MOD(extack, + "Offload not supported when peakrate/avrate/overhead is configured"); + return -EOPNOTSUPP; + } + + return 0; +} + +static int +yt921x_meter_config(struct yt921x_priv *priv, unsigned int id, + const struct yt921x_marker *marker) +{ + u32 ctrls[3]; + + ctrls[0] = 0; + ctrls[1] = YT921X_METER_CTRLb_CIR(marker->cir); + ctrls[2] = YT921X_METER_CTRLc_UNIT(marker->unit) | + YT921X_METER_CTRLc_DROP_R | + YT921X_METER_CTRLc_TOKEN_OVERFLOW_EN | + YT921X_METER_CTRLc_METER_EN; + if (marker->pkt_mode) + ctrls[2] |= YT921X_METER_CTRLc_PKT_MODE; + update_ctrls_unaligned(&ctrls[0], &ctrls[1], + YT921X_METER_CTRLab_EBS_M, + YT921X_METER_CTRLab_EBS(marker->ebs)); + update_ctrls_unaligned(&ctrls[1], &ctrls[2], + YT921X_METER_CTRLbc_CBS_M, + YT921X_METER_CTRLbc_CBS(marker->cbs)); + + return yt921x_reg96_write(priv, YT921X_METERn_CTRL(id), ctrls); +} + +void yt921x_dsa_port_policer_del(struct dsa_switch *ds, int port) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_reg_write(priv, YT921X_PORTn_METER(port), 0); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dev, "Failed to %s port %d: %i\n", "delete policer on", + port, res); +} + +int +yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port, + const struct flow_action_police *police, + struct netlink_ext_ack *extack) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_marker marker; + u32 ctrl; + int res; + + res = yt921x_police_validate(police, NULL, NULL, extack); + if (res) + return res; + + res = yt921x_marker_tfm_police(&marker, police, 0, priv, port, extack); + if (res) + return res; + + mutex_lock(&priv->reg_lock); + res = yt921x_meter_config(priv, port + YT921X_METER_NUM, &marker); + if (res) + goto end; + + ctrl = YT921X_PORT_METER_ID(port) | YT921X_PORT_METER_EN; + res = yt921x_reg_write(priv, YT921X_PORTn_METER(port), ctrl); +end: + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int +yt921x_dsa_port_setup_tc_tbf_port(struct dsa_switch *ds, int port, + const struct tc_tbf_qopt_offload *qopt) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct netlink_ext_ack *extack = qopt->extack; + u32 ctrls[2]; + int res; + + if (qopt->parent != TC_H_ROOT) + return -EOPNOTSUPP; + + switch (qopt->command) { + case TC_TBF_STATS: + /* Unfortunately the convention for TC_*_STATS is a mess, + * neither 0 nor -EOPNOTSUPP is perfect here. + */ + return -EOPNOTSUPP; + case TC_TBF_DESTROY: + ctrls[0] = 0; + ctrls[1] = 0; + break; + case TC_TBF_REPLACE: { + const struct tc_tbf_qopt_offload_replace_params *p; + struct yt921x_marker marker; + + p = &qopt->replace_params; + + res = yt921x_marker_tfm_shape(&marker, p->rate.rate_bytes_ps, + p->max_size, + YT921X_MARKER_SINGLE_BUCKET, + priv, port, extack); + if (res) + return res; + + ctrls[0] = YT921X_PORT_SHAPE_CTRLa_CIR(marker.cir) | + YT921X_PORT_SHAPE_CTRLa_CBS(marker.cbs); + ctrls[1] = YT921X_PORT_SHAPE_CTRLb_UNIT(marker.unit) | + YT921X_PORT_SHAPE_CTRLb_EN; + break; + } + default: + return -EOPNOTSUPP; + } + + mutex_lock(&priv->reg_lock); + res = yt921x_reg64_write(priv, YT921X_PORTn_SHAPE_CTRL(port), ctrls); + mutex_unlock(&priv->reg_lock); + + return res; +} + +int +yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port, + enum tc_setup_type type, void *type_data) +{ + switch (type) { + case TC_SETUP_QDISC_TBF: { + const struct tc_tbf_qopt_offload *qopt = type_data; + + return yt921x_dsa_port_setup_tc_tbf_port(ds, port, qopt); + } + default: + return -EOPNOTSUPP; + } +} + +/* ACL: 48 blocks * 8 entries + * + * One rule can span multiple entries, but within a block. + */ + +static void +yt921x_acl_entry_set(struct yt921x_acl_entry *entry, unsigned int offset, + u32 flags, bool set) +{ + if (set) + entry->key[offset] |= flags; + entry->mask[offset] |= flags; +} + +static unsigned int +yt921x_acl_entries_set_is_fragment(struct yt921x_acl_entry *entries, + unsigned int size, bool set) +{ + for (unsigned int i = 0; i < size; i++) + switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { + case YT921X_ACL_TYPE_IPV4_DA: + case YT921X_ACL_TYPE_IPV4_SA: + yt921x_acl_entry_set(&entries[i], 1, + YT921X_ACL_BINb_IPV4_FRAG, set); + return size; + case YT921X_ACL_TYPE_IPV6_DA3: + case YT921X_ACL_TYPE_IPV6_SA3: + yt921x_acl_entry_set(&entries[i], 1, + YT921X_ACL_BINb_IPV6_xA3_FRAG, + set); + return size; + case YT921X_ACL_TYPE_MISC: + yt921x_acl_entry_set(&entries[i], 1, + YT921X_ACL_BINb_MISC_FRAG, set); + return size; + case YT921X_ACL_TYPE_L4: + yt921x_acl_entry_set(&entries[i], 1, + YT921X_ACL_BINb_L4_FRAG, set); + return size; + } + + if (size >= YT921X_ACL_ENT_PER_BLK) + return 0; + + entries[size] = (typeof(*entries)){}; + entries[size].key[1] = YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); + yt921x_acl_entry_set(&entries[size], 1, YT921X_ACL_BINb_MISC_FRAG, set); + + return size + 1; +} + +static unsigned int +yt921x_acl_entries_set_first_frag(struct yt921x_acl_entry *entries, + unsigned int size, bool set) +{ + for (unsigned int i = 0; i < size; i++) + switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { + case YT921X_ACL_TYPE_IPV6_DA2: + case YT921X_ACL_TYPE_IPV6_SA2: + yt921x_acl_entry_set(&entries[i], 1, + YT921X_ACL_BINb_IPV6_xA2_FIRST_FRAG, + set); + return size; + case YT921X_ACL_TYPE_MISC: + yt921x_acl_entry_set(&entries[i], 0, + YT921X_ACL_BINa_MISC_FIRST_FRAG, + set); + return size; + } + + if (size >= YT921X_ACL_ENT_PER_BLK) + return 0; + + entries[size] = (typeof(*entries)){}; + entries[size].key[1] = YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); + yt921x_acl_entry_set(&entries[size], 0, + YT921X_ACL_BINa_MISC_FIRST_FRAG, set); + + return size + 1; +} + +static unsigned int +yt921x_acl_entries_set_l3_type(struct yt921x_acl_entry *entries, + unsigned int size, enum yt921x_l3_type type) +{ + for (unsigned int i = 0; i < size; i++) + switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { + case YT921X_ACL_TYPE_MAC_DA0: + case YT921X_ACL_TYPE_MAC_SA0: + entries[i].key[1] |= YT921X_ACL_BINb_MAC_xA0_L3_TYPE(type); + entries[i].mask[1] |= YT921X_ACL_BINb_MAC_xA0_L3_TYPE_M; + return size; + case YT921X_ACL_TYPE_MISC: + entries[i].key[0] |= YT921X_ACL_BINa_MISC_L3_TYPE(type); + entries[i].mask[0] |= YT921X_ACL_BINa_MISC_L3_TYPE_M; + return size; + } + + if (size >= YT921X_ACL_ENT_PER_BLK) + return 0; + + entries[size] = (typeof(*entries)){}; + entries[size].key[0] = YT921X_ACL_BINa_MISC_L3_TYPE(type); + entries[size].key[1] = YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); + entries[size].mask[0] = YT921X_ACL_BINa_MISC_L3_TYPE_M; + + return size + 1; +} + +static unsigned int +yt921x_acl_entries_set_l4_type(struct yt921x_acl_entry *entries, + unsigned int size, enum yt921x_l4_type type) +{ + for (unsigned int i = 0; i < size; i++) + switch (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1])) { + case YT921X_ACL_TYPE_IPV4_DA: + case YT921X_ACL_TYPE_IPV4_SA: + entries[i].key[1] |= YT921X_ACL_BINb_IPV4_L4_TYPE(type); + entries[i].mask[1] |= YT921X_ACL_BINb_IPV4_L4_TYPE_M; + return size; + case YT921X_ACL_TYPE_IPV6_DA0: + case YT921X_ACL_TYPE_IPV6_DA1: + case YT921X_ACL_TYPE_IPV6_DA2: + case YT921X_ACL_TYPE_IPV6_DA3: + case YT921X_ACL_TYPE_IPV6_SA0: + case YT921X_ACL_TYPE_IPV6_SA1: + case YT921X_ACL_TYPE_IPV6_SA2: + case YT921X_ACL_TYPE_IPV6_SA3: + entries[i].key[1] |= YT921X_ACL_BINb_IPV6_L4_TYPE(type); + entries[i].mask[1] |= YT921X_ACL_BINb_IPV6_L4_TYPE_M; + return size; + case YT921X_ACL_TYPE_L4: + entries[i].key[1] |= YT921X_ACL_BINb_L4_TYPE(type); + entries[i].mask[1] |= YT921X_ACL_BINb_L4_TYPE_M; + return size; + case YT921X_ACL_TYPE_MISC: + entries[i].key[1] |= YT921X_ACL_BINb_MISC_L4_TYPE(type); + entries[i].mask[1] |= YT921X_ACL_BINb_MISC_L4_TYPE_M; + return size; + } + + if (size >= YT921X_ACL_ENT_PER_BLK) + return 0; + + entries[size] = (typeof(*entries)){}; + entries[size].key[1] = YT921X_ACL_BINb_MISC_L4_TYPE(type) | + YT921X_ACL_KEYb_TYPE(YT921X_ACL_TYPE_MISC); + entries[size].mask[1] = YT921X_ACL_BINb_MISC_L4_TYPE_M; + + return size + 1; +} + +static struct yt921x_acl_entry * +yt921x_acl_entries_new(struct yt921x_acl_entry *entries, unsigned int *sizep, + u32 type) +{ + unsigned int size = *sizep; + + if (size >= YT921X_ACL_ENT_PER_BLK) + return NULL; + + entries[size] = (typeof(*entries)){}; + entries[size].key[1] = YT921X_ACL_KEYb_TYPE(type); + + (*sizep)++; + return &entries[size]; +} + +static struct yt921x_acl_entry * +yt921x_acl_entries_find(struct yt921x_acl_entry *entries, unsigned int *sizep, + u32 type) +{ + for (unsigned int i = 0; i < *sizep; i++) + if (FIELD_GET(YT921X_ACL_KEYb_TYPE_M, entries[i].key[1]) == + type) + return &entries[i]; + return yt921x_acl_entries_new(entries, sizep, type); +} + +static void +yt921x_acl_rule_set_ports(struct yt921x_acl_rule *aclrule, u16 ord, + u16 ports_mask) +{ + struct yt921x_acl_entry *entries = aclrule->entries; + + for (unsigned int i = 0; i < hweight8(aclrule->mask); i++) { + entries[i].key[1] |= YT921X_ACL_KEYb_SPORTS(ports_mask) | + YT921X_ACL_KEYb_ORD(ord); + } +} + +struct yt921x_acl_rule_ext { + struct yt921x_acl_rule r; + + struct yt921x_marker marker; +}; + +static int +yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, + const struct flow_cls_offload *cls) +{ + const struct flow_rule *rule = flow_cls_offload_flow_rule(cls); + struct yt921x_acl_entry *entries = ruleext->r.entries; + struct netlink_ext_ack *extack = cls->common.extack; + const struct flow_dissector *dissector; + struct yt921x_acl_entry *entry; + unsigned int size = 0; + bool use_dport; + bool use_sport; + + /* Incomplete and probably won't, since it supports custom u32 filters. + * New adapters are welcome. + */ + dissector = rule->match.dissector; + if (dissector->used_keys & + ~(BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) | + BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) | + BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS) | + BIT_ULL(FLOW_DISSECTOR_KEY_IPV6_ADDRS) | + BIT_ULL(FLOW_DISSECTOR_KEY_PORTS) | + BIT_ULL(FLOW_DISSECTOR_KEY_PORTS_RANGE) | + BIT_ULL(FLOW_DISSECTOR_KEY_ETH_ADDRS) | + BIT_ULL(FLOW_DISSECTOR_KEY_IP) | + BIT_ULL(FLOW_DISSECTOR_KEY_TCP))) { + NL_SET_ERR_MSG_MOD(extack, "Unsupported keys used"); + return -EOPNOTSUPP; + } + + /* Entries */ + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) { + struct flow_match_ipv4_addrs match; + + flow_rule_match_ipv4_addrs(rule, &match); + + if (match.mask->dst) { + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_IPV4_DA); + if (!entry) + goto err; + + entry->key[0] |= ntohl(match.key->dst); + entry->mask[0] |= ntohl(match.mask->dst); + } + + if (match.mask->src) { + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_IPV4_SA); + if (!entry) + goto err; + + entry->key[0] |= ntohl(match.key->src); + entry->mask[0] |= ntohl(match.mask->src); + } + } + + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS)) { + struct flow_match_ipv6_addrs match; + + flow_rule_match_ipv6_addrs(rule, &match); + + for (unsigned int i = 0; i < 4; i++) { + if (!match.mask->dst.s6_addr32[i]) + continue; + + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_IPV6_DA0 + i); + if (!entry) + goto err; + + entry->key[0] |= ntohl(match.key->dst.s6_addr32[i]); + entry->mask[0] |= ntohl(match.mask->dst.s6_addr32[i]); + } + + for (unsigned int i = 0; i < 4; i++) { + if (!match.mask->src.s6_addr32[i]) + continue; + + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_IPV6_SA0 + i); + if (!entry) + goto err; + + entry->key[0] |= ntohl(match.key->src.s6_addr32[i]); + entry->mask[0] |= ntohl(match.mask->src.s6_addr32[i]); + } + } + + use_dport = false; + use_sport = false; + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) { + struct flow_match_ports match; + + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_L4); + if (!entry) + goto err; + + flow_rule_match_ports(rule, &match); + + use_dport = !!match.mask->dst; + use_sport = !!match.mask->src; + + entry->key[0] |= (ntohs(match.key->dst) << 16) | + ntohs(match.key->src); + entry->mask[0] |= (ntohs(match.mask->dst) << 16) | + ntohs(match.mask->src); + } + + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS_RANGE)) { + struct flow_match_ports_range match; + + entry = yt921x_acl_entries_find(entries, &size, + YT921X_ACL_TYPE_L4); + if (!entry) + goto err; + + flow_rule_match_ports_range(rule, &match); + + if ((use_dport && match.mask->tp.dst) || + (use_sport && match.mask->tp.src)) { + NL_SET_ERR_MSG_MOD(extack, + "Port mask and range are mutually exclusive"); + return -EINVAL; + } + + if (match.mask->tp.dst) { + entry->key[0] |= ntohs(match.key->tp_min.dst) << 16; + entry->key[1] |= YT921X_ACL_KEYb_L4_DPORT_RANGE_EN; + entry->mask[0] |= ntohs(match.key->tp_max.dst) << 16; + } + + if (match.mask->tp.src) { + entry->key[0] |= ntohs(match.key->tp_min.src); + entry->key[1] |= YT921X_ACL_KEYb_L4_SPORT_RANGE_EN; + entry->mask[0] |= ntohs(match.key->tp_max.src); + } + } + + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) { + struct flow_match_eth_addrs match; + u32 mask; + + flow_rule_match_eth_addrs(rule, &match); + + mask = ethaddr_hi4_to_u32(match.mask->dst); + if (mask) { + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_MAC_DA0); + if (!entry) + goto err; + + entry->key[0] |= ethaddr_hi4_to_u32(match.key->dst); + entry->mask[0] |= mask; + } + + mask = ethaddr_hi4_to_u32(match.mask->src); + if (mask) { + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_MAC_SA0); + if (!entry) + goto err; + + entry->key[0] |= ethaddr_hi4_to_u32(match.key->src); + entry->mask[0] |= mask; + } + + mask = (ethaddr_lo2_to_u32(match.mask->dst) << 16) | + ethaddr_lo2_to_u32(match.mask->src); + if (mask) { + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_MAC_DA1_SA1); + if (!entry) + goto err; + + entry->key[0] |= (ethaddr_lo2_to_u32(match.key->dst) << 16) | + ethaddr_lo2_to_u32(match.key->src); + entry->mask[0] |= mask; + } + } + + /* Entries + Misc */ + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) { + struct flow_match_basic match; + + flow_rule_match_basic(rule, &match); + + if (match.mask->n_proto) { + enum yt921x_l3_type l3type = YT921X_L3_TYPE_OTHER; + + if (match.mask->n_proto == htons(~0)) + switch (match.key->n_proto) { + case htons(ETH_P_IP): + l3type = YT921X_L3_TYPE_IPV4; + break; + case htons(ETH_P_IPV6): + l3type = YT921X_L3_TYPE_IPV6; + break; + case htons(ETH_P_ARP): + l3type = YT921X_L3_TYPE_ARP; + break; + case htons(ETH_P_LLDP): + l3type = YT921X_L3_TYPE_LLDP; + break; + case htons(ETH_P_PAE): + l3type = YT921X_L3_TYPE_PAE; + break; + case htons(ETH_P_CFM): + l3type = YT921X_L3_TYPE_ERP; + break; + } + + if (l3type != YT921X_L3_TYPE_OTHER) { + size = yt921x_acl_entries_set_l3_type(entries, + size, + l3type); + if (!size) + goto err; + } else { + entry = yt921x_acl_entries_new(entries, &size, + YT921X_ACL_TYPE_ETHERTYPE); + if (!entry) + goto err; + + entry->key[0] |= ntohs(match.key->n_proto); + entry->mask[0] |= ntohs(match.mask->n_proto); + } + } + + if (match.mask->ip_proto) { + enum yt921x_l4_type l4type = YT921X_L4_TYPE_OTHER; + + if (match.mask->ip_proto == (u8)~0) + switch (match.key->ip_proto) { + case IPPROTO_TCP: + l4type = YT921X_L4_TYPE_TCP; + break; + case IPPROTO_UDP: + l4type = YT921X_L4_TYPE_UDP; + break; + case IPPROTO_UDPLITE: + l4type = YT921X_L4_TYPE_UDPLITE; + break; + case IPPROTO_ICMP: + l4type = YT921X_L4_TYPE_ICMP; + break; + case IPPROTO_IGMP: + l4type = YT921X_L4_TYPE_IGMP; + break; + } + + if (l4type != YT921X_L4_TYPE_OTHER) { + size = yt921x_acl_entries_set_l4_type(entries, + size, + l4type); + if (!size) + goto err; + } else { + entry = yt921x_acl_entries_find(entries, &size, + YT921X_ACL_TYPE_MISC); + if (!entry) + goto err; + + entry->key[0] |= YT921X_ACL_BINa_MISC_IP_PROTO(match.key->ip_proto); + entry->mask[0] |= YT921X_ACL_BINa_MISC_IP_PROTO(match.mask->ip_proto); + } + } + } + + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) { + u32 supp_flags = FLOW_DIS_IS_FRAGMENT | FLOW_DIS_FIRST_FRAG; + struct flow_match_control match; + + flow_rule_match_control(rule, &match); + if (!flow_rule_is_supp_control_flags(supp_flags, + match.mask->flags, extack)) + return -EOPNOTSUPP; + + if (match.mask->flags & FLOW_DIS_IS_FRAGMENT) { + bool set = match.key->flags & FLOW_DIS_IS_FRAGMENT; + + size = yt921x_acl_entries_set_is_fragment(entries, size, + set); + if (!size) + goto err; + } + if (match.mask->flags & FLOW_DIS_FIRST_FRAG) { + bool set = match.key->flags & FLOW_DIS_FIRST_FRAG; + + size = yt921x_acl_entries_set_first_frag(entries, size, + set); + if (!size) + goto err; + } + } + + /* Misc only */ + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP)) { + struct flow_match_ip match; + + flow_rule_match_ip(rule, &match); + if (match.mask->ttl) { + NL_SET_ERR_MSG_MOD(extack, + "Matching on TTL not supported"); + return -EOPNOTSUPP; + } + + if (match.mask->tos) { + entry = yt921x_acl_entries_find(entries, &size, + YT921X_ACL_TYPE_MISC); + if (!entry) + goto err; + + entry->key[0] |= YT921X_ACL_BINa_MISC_TOS(match.key->tos); + entry->mask[0] |= YT921X_ACL_BINa_MISC_TOS(match.mask->tos); + } + } + + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_TCP)) { + struct flow_match_tcp match; + + flow_rule_match_tcp(rule, &match); + if (match.mask->flags & htons(~0xff)) { + NL_SET_ERR_MSG_MOD(extack, "Unsupported TCP flags"); + return -EOPNOTSUPP; + } + + if (match.mask->flags) { + entry = yt921x_acl_entries_find(entries, &size, + YT921X_ACL_TYPE_MISC); + if (!entry) + goto err; + + entry->key[0] |= YT921X_ACL_BINa_MISC_TCP_FLAGS(ntohs(match.key->flags)); + entry->mask[0] |= YT921X_ACL_BINa_MISC_TCP_FLAGS(ntohs(match.mask->flags)); + } + } + + if (!size) { + NL_SET_ERR_MSG_MOD(extack, "Empty rule generated, this should not happen"); + return -EOPNOTSUPP; + } + + ruleext->r.mask = (1 << size) - 1; + return 0; + +err: + NL_SET_ERR_MSG_MOD(extack, "Rule too complex"); + return -EOPNOTSUPP; +} + +static int +yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, + const struct flow_cls_offload *cls, + struct yt921x_priv *priv, int port) +{ + const struct flow_rule *rule = flow_cls_offload_flow_rule(cls); + const struct flow_action *flow_action = &rule->action; + struct netlink_ext_ack *extack = cls->common.extack; + enum flow_action_id redir_act = NUM_FLOW_ACTIONS; + const struct flow_action_entry *act; + u32 *action = ruleext->r.action; + bool seen_priority = false; + const char *reason = NULL; + bool seen_police = false; + unsigned int i; + int res; + + memset(action, 0, 3 * sizeof(*action)); + flow_action_for_each(i, act, flow_action) + switch (act->id) { + case FLOW_ACTION_ACCEPT: + case FLOW_ACTION_DROP: + case FLOW_ACTION_REDIRECT: + if (redir_act != NUM_FLOW_ACTIONS && + redir_act != act->id) { + reason = "Different redirect actions"; + goto fallback; + } + redir_act = act->id; + + switch (act->id) { + case FLOW_ACTION_ACCEPT: + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_FWD; + break; + case FLOW_ACTION_DROP: + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_REDIR; + break; + case FLOW_ACTION_REDIRECT: { + struct dsa_port *to_dp; + + to_dp = dsa_port_from_netdev(act->dev); + if (IS_ERR(to_dp) || to_dp->ds != &priv->ds) { + reason = "Redirect to non-local port"; + goto fallback; + } + + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_REDIR | + YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index); + break; + } + default: + break; + } + break; + case FLOW_ACTION_PRIORITY: + if (seen_priority) { + action[0] &= ~YT921X_ACL_ACTa_PRIO_EN; + action[1] &= ~YT921X_ACL_ACTb_PRIO_M; + + reason = "Multiple priority actions"; + goto fallback; + } + seen_priority = true; + + if (act->priority >= YT921X_PRIO_NUM) { + NL_SET_ERR_MSG_MOD(extack, + "Priority value is too high"); + return -EOPNOTSUPP; + } + action[0] |= YT921X_ACL_ACTa_PRIO_EN; + action[1] |= YT921X_ACL_ACTb_PRIO(act->priority); + break; + case FLOW_ACTION_POLICE: { + const struct flow_action_police *police = &act->police; + + if (seen_police) { + action[0] &= ~YT921X_ACL_ACTa_METER_EN; + + reason = "Multiple police actions"; + goto fallback; + } + seen_police = true; + + res = yt921x_police_validate(police, flow_action, act, + extack); + if (res) + return res; + + res = yt921x_marker_tfm_police(&ruleext->marker, police, + 0, priv, port, extack); + if (res) + return res; + + action[0] |= YT921X_ACL_ACTa_METER_EN; + break; + } + default: +fallback: + if (cls->common.skip_sw) { + NL_SET_ERR_MSG_FMT_MOD(extack, + "Action not supported when skip_sw: %s", + reason); + return -EOPNOTSUPP; + } + fallthrough; + case FLOW_ACTION_TRAP: + redir_act = FLOW_ACTION_TRAP; + + action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M & + ~YT921X_ACL_ACTc_FWD_M; + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_TRAP; + break; + } + + ruleext->r.sw_assisted = !cls->common.skip_sw; + return 0; +} + +static int +yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, + const struct flow_cls_offload *cls, bool ingress, + struct yt921x_priv *priv) +{ + struct netlink_ext_ack *extack = cls->common.extack; + int res; + + if (!ingress) { + NL_SET_ERR_MSG_MOD(extack, "Only ingress is supported"); + return -EOPNOTSUPP; + } + + if (cls->common.chain_index) { + NL_SET_ERR_MSG(extack, "Only chain 0 is supported"); + return -EOPNOTSUPP; + } + + res = yt921x_acl_rule_ext_parse_flow_action(ruleext, cls, priv, port); + if (res) + return res; + res = yt921x_acl_rule_ext_parse_flow_entries(ruleext, cls); + if (res) + return res; + + yt921x_acl_rule_set_ports(&ruleext->r, 0, BIT(port)); + ruleext->r.tag = cls->cookie; + ruleext->r.type = TC_SETUP_CLSFLOWER; + return 0; +} + +static unsigned int +yt921x_acl_find(const struct yt921x_priv *priv, enum tc_setup_type type, + unsigned long tag) +{ + for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) { + const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid]; + + if (!aclblk) + continue; + + for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) + if (aclblk->rules[i] && aclblk->rules[i]->tag == tag && + aclblk->rules[i]->type == type) + return YT921X_ACL_ENT_PER_BLK * blkid + i; + } + + return UINT_MAX; +} + +static unsigned int +yt921x_acl_reserve(struct yt921x_priv *priv, unsigned int entscnt, + struct netlink_ext_ack *extack) +{ + int candidates[YT921X_ACL_ENT_PER_BLK + 1]; + unsigned int acl_used_cnt = 0; + + if (WARN_ON(entscnt > YT921X_ACL_ENT_PER_BLK)) + return UINT_MAX; + + for (unsigned int i = 0; i < ARRAY_SIZE(candidates); i++) + candidates[i] = -1; + for (unsigned int i = YT921X_ACL_BLK_NUM; i-- > 0;) { + unsigned int blk_used_cnt = hweight8(priv->acl_masks[i]); + + candidates[blk_used_cnt] = i; + acl_used_cnt += blk_used_cnt; + } + + if (acl_used_cnt >= YT921X_ACL_NUM) { + NL_SET_ERR_MSG_MOD(extack, "ACL entry limit reached"); + return UINT_MAX; + } + if (acl_used_cnt + entscnt <= YT921X_ACL_NUM) + for (unsigned int i = YT921X_ACL_ENT_PER_BLK - entscnt + 1; + i-- > 0;) + if (candidates[i] >= 0) + return YT921X_ACL_ENT_PER_BLK * candidates[i] + + ffz(priv->acl_masks[candidates[i]]); + + NL_SET_ERR_MSG_MOD(extack, + "ACL entry allocation failed, simplify your rules or remove existing rules"); + return UINT_MAX; +} + +static int +yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) +{ + const struct yt921x_acl_rule *aclrule; + const struct yt921x_acl_blk *aclblk; + unsigned int blkid; + unsigned int binid; + unsigned long mask; + u32 zeros[3] = {}; + unsigned int i; + unsigned int o; + u32 ctrl; + int res; + + blkid = entid / YT921X_ACL_ENT_PER_BLK; + binid = entid % YT921X_ACL_ENT_PER_BLK; + aclblk = priv->acl_blks[blkid]; + aclrule = aclblk->rules[binid]; + + /* Write actions */ + res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), + aclrule ? aclrule->action : zeros); + if (res) + return res; + + /* Select the block */ + ctrl = YT921X_ACL_BLK_CMD_MODIFY | YT921X_ACL_BLK_CMD_BLKID(blkid); + res = yt921x_reg_write(priv, YT921X_ACL_BLK_CMD, ctrl); + if (res) + return res; + + /* Write keys and masks */ + ctrl = 0; + for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) + ctrl |= YT921X_ACL_BLK_KEEP_KEEPn(i); + + mask = entsmask; + i = 0; + for_each_set_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) { + res = yt921x_reg64_write(priv, YT921X_ACLn_KEYm(blkid, o), + aclrule ? aclrule->entries[i].key : + zeros); + if (res) + return res; + + res = yt921x_reg64_write(priv, YT921X_ACLn_MASKm(blkid, o), + aclrule ? aclrule->entries[i].mask : + zeros); + if (res) + return res; + + ctrl &= ~YT921X_ACL_BLK_KEEP_KEEPn(o); + i++; + } + + res = yt921x_reg_write(priv, YT921X_ACL_BLK_KEEP, ctrl); + if (res) + return res; + + ctrl = 0; + for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) { + const struct yt921x_acl_rule *other = aclblk->rules[i]; + + if (!other) + continue; + + mask = other->mask; + for_each_set_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) + ctrl |= YT921X_ACL_ENTRY_ENm(o) | + YT921X_ACL_ENTRY_GRPIDm(o, i); + } + res = yt921x_reg_write(priv, YT921X_ACLn_ENTRY(blkid), ctrl); + if (res) + return res; + + /* Commit the block */ + ctrl = YT921X_ACL_BLK_CMD_BLKID(blkid); + res = yt921x_reg_write(priv, YT921X_ACL_BLK_CMD, ctrl); + if (res) + return res; + + return 0; +} + +static int +yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, + unsigned long tag) +{ + struct yt921x_acl_rule *aclrule; + struct yt921x_acl_blk *aclblk; + unsigned int binid; + unsigned int blkid; + unsigned int entid; + int res; + + entid = yt921x_acl_find(priv, type, tag); + if (entid == UINT_MAX) + return -ENOENT; + + blkid = entid / YT921X_ACL_ENT_PER_BLK; + binid = entid % YT921X_ACL_ENT_PER_BLK; + aclblk = priv->acl_blks[blkid]; + aclrule = aclblk->rules[binid]; + + aclblk->rules[binid] = NULL; + res = yt921x_acl_commit(priv, entid, aclrule->mask); + /* the kernel never rolls back on failure */ + + if (aclrule->action[0] & YT921X_ACL_ACTa_METER_EN) + clear_bit(FIELD_GET(YT921X_ACL_ACTa_METER_ID_M, + aclrule->action[0]), + priv->meters_map); + priv->acl_masks[blkid] &= ~aclrule->mask; + kvfree(aclrule); + if (!priv->acl_masks[blkid]) { + kvfree(aclblk); + priv->acl_blks[blkid] = NULL; + } + return res; +} + +static int +yt921x_acl_add(struct yt921x_priv *priv, + const struct yt921x_acl_rule_ext *ruleext, + struct netlink_ext_ack *extack) +{ + unsigned int entscnt = hweight8(ruleext->r.mask); + struct yt921x_acl_rule *aclrule; + struct yt921x_acl_blk *aclblk; + bool use_trap = false; + unsigned int meterid; + unsigned long mask; + unsigned int binid; + unsigned int blkid; + unsigned int entid; + unsigned int o; + int res; + + /* Allocate resources */ + entid = yt921x_acl_reserve(priv, entscnt, extack); + if (entid == UINT_MAX) + return -EOPNOTSUPP; + + if (!(ruleext->r.action[0] & YT921X_ACL_ACTa_METER_EN)) { + meterid = YT921X_METER_NUM; + } else { + meterid = find_first_zero_bit(priv->meters_map, + YT921X_METER_NUM); + if (meterid < YT921X_METER_NUM) { + res = yt921x_meter_config(priv, meterid, + &ruleext->marker); + if (res) + return res; + } else if (ruleext->r.sw_assisted) { + use_trap = true; + } else { + NL_SET_ERR_MSG_MOD(extack, + "No more meters available"); + return -EOPNOTSUPP; + } + } + + /* Prepare acl block ctrlblk */ + blkid = entid / YT921X_ACL_ENT_PER_BLK; + binid = entid % YT921X_ACL_ENT_PER_BLK; + aclblk = priv->acl_blks[blkid]; + if (!aclblk) { + aclblk = kvzalloc_obj(*aclblk); + if (!aclblk) + return -ENOMEM; + priv->acl_blks[blkid] = aclblk; + } + + /* Prepare acl rule ctrlblk */ + aclrule = kvmemdup(&ruleext->r, + offsetof(struct yt921x_acl_rule, entries[entscnt]), + GFP_KERNEL); + if (!aclrule) { + res = -ENOMEM; + goto err; + } + + /* Replace the placeholder resource IDs */ + aclrule->mask = 0; + mask = priv->acl_masks[blkid]; + for_each_clear_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) { + aclrule->mask |= BIT(o); + entscnt--; + if (!entscnt) + break; + } + + if (use_trap) { + aclrule->action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M & + ~YT921X_ACL_ACTc_FWD_M; + aclrule->action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_TRAP; + } + if (meterid < YT921X_METER_NUM) + aclrule->action[0] |= YT921X_ACL_ACTa_METER_ID(meterid); + else + aclrule->action[0] &= ~YT921X_ACL_ACTa_METER_EN; + + /* Write rules */ + aclblk->rules[binid] = aclrule; + res = yt921x_acl_commit(priv, entid, aclrule->mask); + if (res) { + aclblk->rules[binid] = NULL; + kvfree(aclrule); + goto err; + } + + if (meterid < YT921X_METER_NUM) + set_bit(meterid, priv->meters_map); + priv->acl_masks[blkid] |= aclrule->mask; + return 0; + +err: + if (!priv->acl_masks[blkid]) { + kvfree(aclblk); + priv->acl_blks[blkid] = NULL; + } + return res; +} + +int +yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, + struct flow_cls_offload *cls, bool ingress) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_acl_del(priv, TC_SETUP_CLSFLOWER, cls->cookie); + mutex_unlock(&priv->reg_lock); + + return res; +} + +int +yt921x_dsa_cls_flower_add(struct dsa_switch *ds, int port, + struct flow_cls_offload *cls, bool ingress) +{ + struct netlink_ext_ack *extack = cls->common.extack; + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_acl_rule_ext ruleext; + int res; + + res = yt921x_acl_rule_ext_parse_flow(&ruleext, port, cls, ingress, + priv); + if (res) + return res; + + mutex_lock(&priv->reg_lock); + res = yt921x_acl_add(priv, &ruleext, extack); + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int +yt921x_mirror_del(struct yt921x_priv *priv, int port, bool ingress) +{ + u32 mask; + + if (ingress) + mask = YT921X_MIRROR_IGR_PORTn(port); + else + mask = YT921X_MIRROR_EGR_PORTn(port); + return yt921x_reg_clear_bits(priv, YT921X_MIRROR, mask); +} + +static int +yt921x_mirror_add(struct yt921x_priv *priv, int port, bool ingress, + int to_local_port, struct netlink_ext_ack *extack) +{ + u32 srcs; + u32 ctrl; + u32 val; + u32 dst; + int res; + + if (ingress) + srcs = YT921X_MIRROR_IGR_PORTn(port); + else + srcs = YT921X_MIRROR_EGR_PORTn(port); + dst = YT921X_MIRROR_PORT(to_local_port); + + res = yt921x_reg_read(priv, YT921X_MIRROR, &val); + if (res) + return res; + + /* other mirror tasks & different dst port -> conflict */ + if ((val & ~srcs & (YT921X_MIRROR_EGR_PORTS_M | + YT921X_MIRROR_IGR_PORTS_M)) && + (val & YT921X_MIRROR_PORT_M) != dst) { + NL_SET_ERR_MSG_MOD(extack, + "Sniffer port is already configured, delete existing rules & retry"); + return -EBUSY; + } + + ctrl = val & ~YT921X_MIRROR_PORT_M; + ctrl |= srcs; + ctrl |= dst; + + if (ctrl == val) + return 0; + + return yt921x_reg_write(priv, YT921X_MIRROR, ctrl); +} + +void +yt921x_dsa_port_mirror_del(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_mirror_del(priv, port, mirror->ingress); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dev, "Failed to %s port %d: %i\n", "unmirror", + port, res); +} + +int +yt921x_dsa_port_mirror_add(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_mirror_add(priv, port, ingress, + mirror->to_local_port, extack); + mutex_unlock(&priv->reg_lock); + + return res; +} + +int yt921x_chip_setup_tc(struct yt921x_priv *priv) +{ + unsigned int op_ns; + u32 ctrl; + int res; + + op_ns = 8 * priv->cycle_ns; + + ctrl = max(priv->meter_slot_ns / op_ns, YT921X_METER_SLOT_MIN); + res = yt921x_reg_write(priv, YT921X_METER_SLOT, ctrl); + if (res) + return res; + priv->meter_slot_ns = ctrl * op_ns; + + ctrl = max(priv->port_shape_slot_ns / op_ns, + YT921X_PORT_SHAPE_SLOT_MIN); + res = yt921x_reg_write(priv, YT921X_PORT_SHAPE_SLOT, ctrl); + if (res) + return res; + priv->port_shape_slot_ns = ctrl * op_ns; + + return 0; +} + +int yt921x_chip_setup_acl(struct yt921x_priv *priv) +{ + u32 ctrl; + int res; + + ctrl = YT921X_ACL_PERMIT_UNMATCH_PORTS_M; + res = yt921x_reg_write(priv, YT921X_ACL_PERMIT_UNMATCH, ctrl); + if (res) + return res; + + ctrl = YT921X_ACL_PORT_PORTS_M; + res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl); + if (res) + return res; + + return 0; +} diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h new file mode 100644 index 000000000000..32b53f1f3825 --- /dev/null +++ b/drivers/net/dsa/motorcomm/tc.h @@ -0,0 +1,380 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2026 David Yang + */ + +#ifndef _YT_TC_H +#define _YT_TC_H + +#include +#include + +#define YT921X_ACLn_ACT(n) (0x1c0000 + 0x10 * (n)) +#define YT921X_ACL_ACTc_STAG_M GENMASK(26, 25) +#define YT921X_ACL_ACTc_STAG(x) FIELD_PREP(YT921X_ACL_ACTc_STAG_M, (x)) +#define YT921X_ACL_ACTc_STAG_DONTCARE YT921X_ACL_ACTc_STAG(0) +#define YT921X_ACL_ACTc_STAG_UNTAG YT921X_ACL_ACTc_STAG(1) +#define YT921X_ACL_ACTc_STAG_TAG YT921X_ACL_ACTc_STAG(2) +#define YT921X_ACL_ACTc_STAG_KEEP YT921X_ACL_ACTc_STAG(3) +#define YT921X_ACL_ACTc_CTAG_M GENMASK(24, 23) +#define YT921X_ACL_ACTc_CTAG(x) FIELD_PREP(YT921X_ACL_ACTc_CTAG_M, (x)) +#define YT921X_ACL_ACTc_CTAG_DONTCARE YT921X_ACL_ACTc_CTAG(0) +#define YT921X_ACL_ACTc_CTAG_UNTAG YT921X_ACL_ACTc_CTAG(1) +#define YT921X_ACL_ACTc_CTAG_TAG YT921X_ACL_ACTc_CTAG(2) +#define YT921X_ACL_ACTc_CTAG_KEEP YT921X_ACL_ACTc_CTAG(3) +#define YT921X_ACL_ACTc_FWD_M GENMASK(22, 21) +#define YT921X_ACL_ACTc_FWD(x) FIELD_PREP(YT921X_ACL_ACTc_FWD_M, (x)) +#define YT921X_ACL_ACTc_FWD_FWD YT921X_ACL_ACTc_FWD(0) +#define YT921X_ACL_ACTc_FWD_COPY YT921X_ACL_ACTc_FWD(1) +#define YT921X_ACL_ACTc_FWD_REDIR YT921X_ACL_ACTc_FWD(2) +#define YT921X_ACL_ACTc_FWD_TRAP YT921X_ACL_ACTc_FWD(3) +#define YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M GENMASK(20, 10) +#define YT921X_ACL_ACTc_FWD_REDIR_DPORTS(x) FIELD_PREP(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M, (x)) +#define YT921X_ACL_ACTc_FWD_REDIR_DPORTn(port) BIT((port) + 10) +#define YT921X_ACL_ACTc_FWD_EN BIT(9) +#define YT921X_ACL_ACTc_SDEI BIT(8) +#define YT921X_ACL_ACTc_SDEI_REPLACE BIT(7) +#define YT921X_ACL_ACTc_SPRI_M GENMASK(6, 4) +#define YT921X_ACL_ACTc_SPRI(x) FIELD_PREP(YT921X_ACL_ACTc_SPRI_M, (x)) +#define YT921X_ACL_ACTc_SPRI_REPLACE BIT(3) +#define YT921X_ACL_ACTbc_SVID_M GENMASK_ULL(34, 23) +#define YT921X_ACL_ACTbc_SVID(x) FIELD_PREP(YT921X_ACL_ACTbc_SVID_M, (x)) +#define YT921X_ACL_ACTb_SVID_REPLACE BIT(22) +#define YT921X_ACL_ACTb_CDEI BIT(21) +#define YT921X_ACL_ACTb_CDEI_REPLACE BIT(20) +#define YT921X_ACL_ACTb_CPRI_M GENMASK(19, 17) +#define YT921X_ACL_ACTb_CPRI(x) FIELD_PREP(YT921X_ACL_ACTb_CPRI_M, (x)) +#define YT921X_ACL_ACTb_CPRI_REPLACE BIT(16) +#define YT921X_ACL_ACTb_CVID_M GENMASK(15, 4) +#define YT921X_ACL_ACTb_CVID(x) FIELD_PREP(YT921X_ACL_ACTb_CVID_M, (x)) +#define YT921X_ACL_ACTb_CVID_REPLACE BIT(3) +#define YT921X_ACL_ACTb_PRIO_M GENMASK(2, 0) +#define YT921X_ACL_ACTb_PRIO(x) FIELD_PREP(YT921X_ACL_ACTb_PRIO_M, (x)) +#define YT921X_ACL_ACTa_PRIO_EN BIT(31) +#define YT921X_ACL_ACTa_COLOR_M GENMASK(30, 29) +#define YT921X_ACL_ACTa_COLOR(x) FIELD_PREP(YT921X_ACL_ACTa_COLOR_M, (x)) +#define YT921X_ACL_ACTa_COLOR_GREEN YT921X_ACL_ACTa_COLOR(0) +#define YT921X_ACL_ACTa_COLOR_YELLOW YT921X_ACL_ACTa_COLOR(1) +#define YT921X_ACL_ACTa_COLOR_RED YT921X_ACL_ACTa_COLOR(2) +#define YT921X_ACL_ACTa_COLOR_EN BIT(28) +#define YT921X_ACL_ACTa_DSCP_M GENMASK(27, 22) +#define YT921X_ACL_ACTa_DSCP(x) FIELD_PREP(YT921X_ACL_ACTa_DSCP_M, (x)) +#define YT921X_ACL_ACTa_DSCP_REPLACE BIT(21) +#define YT921X_ACL_ACTa_METER_ID_M GENMASK(20, 15) +#define YT921X_ACL_ACTa_METER_ID(x) FIELD_PREP(YT921X_ACL_ACTa_METER_ID_M, (x)) +#define YT921X_ACL_ACTa_METER_EN BIT(14) +#define YT921X_ACL_ACTa_MIRROR_EN BIT(13) +#define YT921X_ACL_ACTa_FLOWSTAT_EN BIT(12) +#define YT921X_ACL_ACTa_FLOWSTAT_ID_M GENMASK(11, 6) +#define YT921X_ACL_ACTa_FLOWSTAT_ID(x) FIELD_PREP(YT921X_ACL_ACTa_FLOWSTAT_ID_M, (x)) +#define YT921X_ACL_ACTa_GPIO_EN BIT(5) +#define YT921X_ACL_ACTa_GPIO_PIN_M GENMASK(4, 1) +#define YT921X_ACL_ACTa_GPIO_PIN(x) FIELD_PREP(YT921X_ACL_ACTa_GPIO_PIN_M, (x)) +#define YT921X_ACL_ACTa_INTR_EN BIT(0) +#define YT921X_ACL_BLK_KEEP 0x201000 +#define YT921X_ACL_BLK_KEEP_GRPIDn_M(bin) (7 << (4 * (bin) + 1)) +#define YT921X_ACL_BLK_KEEP_GRPIDn(bin, x) ((x) << (4 * (bin) + 1)) +#define YT921X_ACL_BLK_KEEP_KEEPn(bin) BIT(4 * (bin)) +#define YT921X_ACL_PORT 0x202000 +#define YT921X_ACL_PORT_PORTS_M GENMASK(10, 0) +#define YT921X_ACL_PORT_PORTS(x) FIELD_PREP(YT921X_ACL_PORT_PORTS_M, (x)) +#define YT921X_ACL_PORT_PORTn(port) BIT(port) +#define YT921X_ACL_BLK_CMD 0x202004 +#define YT921X_ACL_BLK_CMD_BLKID_M GENMASK(6, 1) +#define YT921X_ACL_BLK_CMD_BLKID(x) FIELD_PREP(YT921X_ACL_BLK_CMD_BLKID_M, (x)) +#define YT921X_ACL_BLK_CMD_MODIFY BIT(0) +#define YT921X_ACLn_ENTRY(blk) (0x203000 + 4 * (blk)) +#define YT921X_ACL_ENTRY_GRPIDm_M(bin) (7 << (4 * (bin) + 1)) +#define YT921X_ACL_ENTRY_GRPIDm(bin, x) ((x) << (4 * (bin) + 1)) +#define YT921X_ACL_ENTRY_ENm(bin) BIT(4 * (bin)) +#define YT921X_ACLn_KEYm(blk, bin) (0x204000 + 0x200 * (bin) + 8 * (blk)) +#define YT921X_ACL_KEYb_ORD_M GENMASK(29, 21) +#define YT921X_ACL_KEYb_ORD(x) FIELD_PREP(YT921X_ACL_KEYb_ORD_M, (x)) +#define YT921X_ACL_KEYb_SPORTS_M GENMASK(20, 10) +#define YT921X_ACL_KEYb_SPORTS(x) FIELD_PREP(YT921X_ACL_KEYb_SPORTS_M, (x)) +#define YT921X_ACL_KEYb_SPORTn(port) BIT((port) + 10) +#define YT921X_ACL_KEYb_REVERSE BIT(9) /* reverse match */ +#define YT921X_ACL_KEYb_TYPE_M GENMASK(8, 4) +#define YT921X_ACL_KEYb_TYPE(x) FIELD_PREP(YT921X_ACL_KEYb_TYPE_M, (x)) +/* KEY_* fields need no masks */ +#define YT921X_ACLn_MASKm(blk, bin) (0x205000 + 0x200 * (bin) + 8 * (blk)) + +enum yt921x_acl_type { + YT921X_ACL_TYPE_NA, + YT921X_ACL_TYPE_MAC_DA0, + YT921X_ACL_TYPE_MAC_SA0, + YT921X_ACL_TYPE_MAC_DA1_SA1, + YT921X_ACL_TYPE_VLAN, + YT921X_ACL_TYPE_VTAG, + YT921X_ACL_TYPE_IPV4_DA, + YT921X_ACL_TYPE_IPV4_SA, + YT921X_ACL_TYPE_IPV6_DA0, + YT921X_ACL_TYPE_IPV6_DA1, + YT921X_ACL_TYPE_IPV6_DA2, + YT921X_ACL_TYPE_IPV6_DA3, + YT921X_ACL_TYPE_IPV6_SA0, + YT921X_ACL_TYPE_IPV6_SA1, + YT921X_ACL_TYPE_IPV6_SA2, + YT921X_ACL_TYPE_IPV6_SA3, + YT921X_ACL_TYPE_MISC, + YT921X_ACL_TYPE_L4, + YT921X_ACL_TYPE_UDF0, + YT921X_ACL_TYPE_UDF1, + YT921X_ACL_TYPE_UDF2, + YT921X_ACL_TYPE_UDF3, + YT921X_ACL_TYPE_UDF4, + YT921X_ACL_TYPE_UDF5, + YT921X_ACL_TYPE_UDF6, + YT921X_ACL_TYPE_UDF7, + YT921X_ACL_TYPE_ETHERTYPE, + YT921X_ACL_TYPE_NUM +}; + +/* Range: turn KEY:MASK into MIN:MAX */ + +#define YT921X_ACL_BINb_MAC_xA0_L3_TYPE_M GENMASK(3, 0) +#define YT921X_ACL_BINb_MAC_xA0_L3_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_MAC_xA0_L3_TYPE_M, (x)) +#define YT921X_ACL_BINa_MAC_xA0_MAC_xA0_M GENMASK(31, 0) + +#define YT921X_ACL_BINb_MAC_DA1_SA1_L2_TYPE_M GENMASK(2, 0) +#define YT921X_ACL_BINb_MAC_DA1_SA1_L2_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_MAC_DA1_SA1_L2_TYPE_M, (x)) +#define YT921X_ACL_BINa_MAC_DA1_SA1_MAC_DA1_M GENMASK(31, 16) +#define YT921X_ACL_BINa_MAC_DA1_SA1_MAC_SA1_M GENMASK(15, 0) + +#define YT921X_ACL_KEYb_VLAN_SVID_RANGE_EN BIT(31) +#define YT921X_ACL_KEYb_VLAN_CVID_RANGE_EN BIT(30) +#define YT921X_ACL_BINb_VLAN_CDEI BIT(3) +#define YT921X_ACL_BINb_VLAN_CPRI_M GENMASK(2, 0) +#define YT921X_ACL_BINb_VLAN_CPRI(x) FIELD_PREP(YT921X_ACL_BINb_VLAN_CPRI_M, (x)) +#define YT921X_ACL_BINa_VLAN_CTAG_FMT_M GENMASK(31, 30) +#define YT921X_ACL_BINa_VLAN_CTAG_FMT(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_CTAG_FMT_M, (x)) +#define YT921X_ACL_BINa_VLAN_SDEI BIT(29) +#define YT921X_ACL_BINa_VLAN_SPRI_M GENMASK(28, 26) +#define YT921X_ACL_BINa_VLAN_SPRI(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_SPRI_M, (x)) +#define YT921X_ACL_BINa_VLAN_STAG_FMT_M GENMASK(25, 24) +#define YT921X_ACL_BINa_VLAN_STAG_FMT(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_STAG_FMT_M, (x)) +#define YT921X_ACL_BINa_VLAN_SVID_M GENMASK(23, 12) +#define YT921X_ACL_BINa_VLAN_SVID(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_SVID_M, (x)) +#define YT921X_ACL_BINa_VLAN_CVID_M GENMASK(11, 0) +#define YT921X_ACL_BINa_VLAN_CVID(x) FIELD_PREP(YT921X_ACL_BINa_VLAN_CVID_M, (x)) + +#define YT921X_ACL_KEYb_VTAG_SVID_RANGE_EN BIT(31) +#define YT921X_ACL_KEYb_VTAG_CVID_RANGE_EN BIT(30) +#define YT921X_ACL_BINa_VTAG_CDEI BIT(31) +#define YT921X_ACL_BINa_VTAG_CPRI_M GENMASK(30, 28) +#define YT921X_ACL_BINa_VTAG_CPRI(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_CPRI_M, (x)) +#define YT921X_ACL_BINa_VTAG_SDEI BIT(27) +#define YT921X_ACL_BINa_VTAG_SPRI_M GENMASK(26, 24) +#define YT921X_ACL_BINa_VTAG_SPRI(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_SPRI_M, (x)) +#define YT921X_ACL_BINa_VTAG_SVID_M GENMASK(23, 12) +#define YT921X_ACL_BINa_VTAG_SVID(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_SVID_M, (x)) +#define YT921X_ACL_BINa_VTAG_CVID_M GENMASK(11, 0) +#define YT921X_ACL_BINa_VTAG_CVID(x) FIELD_PREP(YT921X_ACL_BINa_VTAG_CVID_M, (x)) + +#define YT921X_ACL_KEYb_IPV4_ADDR_RANGE_EN BIT(30) +#define YT921X_ACL_BINb_IPV4_FRAG BIT(3) +#define YT921X_ACL_BINb_IPV4_L4_TYPE_M GENMASK(2, 0) +#define YT921X_ACL_BINb_IPV4_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_IPV4_L4_TYPE_M, (x)) +#define YT921X_ACL_BINa_IPV4_ADDR_M GENMASK(31, 0) + +#define YT921X_ACL_BINb_IPV6_L4_TYPE_M GENMASK(2, 0) +#define YT921X_ACL_BINb_IPV6_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_IPV6_L4_TYPE_M, (x)) +#define YT921X_ACL_BINa_IPV6_ADDRx_M GENMASK(31, 0) + +#define YT921X_ACL_BINb_IPV6_xA1_IP_OPTION BIT(3) + +#define YT921X_ACL_BINb_IPV6_xA2_FIRST_FRAG BIT(3) + +#define YT921X_ACL_KEYb_IPV6_xA3_ADDR_RANGE_EN BIT(30) +#define YT921X_ACL_BINb_IPV6_xA3_FRAG BIT(3) + +#define YT921X_ACL_BINb_MISC_FRAG BIT(3) +#define YT921X_ACL_BINb_MISC_L4_TYPE_M GENMASK(2, 0) +#define YT921X_ACL_BINb_MISC_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_MISC_L4_TYPE_M, (x)) +#define YT921X_ACL_BINa_MISC_PPPOE_FLAG BIT(30) +#define YT921X_ACL_BINa_MISC_FIRST_FRAG BIT(29) +#define YT921X_ACL_BINa_MISC_IP_OPTION BIT(28) +#define YT921X_ACL_BINa_MISC_TCP_FLAGS_M GENMASK(27, 20) +#define YT921X_ACL_BINa_MISC_TCP_FLAGS(x) FIELD_PREP(YT921X_ACL_BINa_MISC_TCP_FLAGS_M, (x)) +#define YT921X_ACL_BINa_MISC_IP_PROTO_M GENMASK(19, 12) +#define YT921X_ACL_BINa_MISC_IP_PROTO(x) FIELD_PREP(YT921X_ACL_BINa_MISC_IP_PROTO_M, (x)) +#define YT921X_ACL_BINa_MISC_TOS_M GENMASK(11, 4) +#define YT921X_ACL_BINa_MISC_TOS(x) FIELD_PREP(YT921X_ACL_BINa_MISC_TOS_M, (x)) +#define YT921X_ACL_BINa_MISC_L3_TYPE_M GENMASK(3, 0) +#define YT921X_ACL_BINa_MISC_L3_TYPE(x) FIELD_PREP(YT921X_ACL_BINa_MISC_L3_TYPE_M, (x)) + +#define YT921X_ACL_KEYb_L4_DPORT_RANGE_EN BIT(31) +#define YT921X_ACL_KEYb_L4_SPORT_RANGE_EN BIT(30) +#define YT921X_ACL_BINb_L4_FRAG BIT(3) +#define YT921X_ACL_BINb_L4_TYPE_M GENMASK(2, 0) +#define YT921X_ACL_BINb_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_L4_TYPE_M, (x)) +#define YT921X_ACL_BINa_L4_DPORT_M GENMASK(31, 16) +#define YT921X_ACL_BINa_L4_SPORT_M GENMASK(15, 0) + +#define YT921X_ACL_BINb_UDF_IS_IGMP BIT(0) +#define YT921X_ACL_BINa_UDF_UDF0_M GENMASK(31, 16) +#define YT921X_ACL_BINa_UDF_UDF0(x) FIELD_PREP(YT921X_ACL_BINa_UDF_UDF0_M, (x)) +#define YT921X_ACL_BINa_UDF_UDF1_M GENMASK(15, 0) +#define YT921X_ACL_BINa_UDF_UDF1(x) FIELD_PREP(YT921X_ACL_BINa_UDF_UDF1_M, (x)) + +#define YT921X_ACL_KEYb_ETHERTYPE_ETHERTYPE_RANGE_EN BIT(30) +#define YT921X_ACL_BINb_ETHERTYPE_L4_TYPE_M GENMASK(2, 0) +#define YT921X_ACL_BINb_ETHERTYPE_L4_TYPE(x) FIELD_PREP(YT921X_ACL_BINb_ETHERTYPE_L4_TYPE_M, (x)) +#define YT921X_ACL_BINa_ETHERTYPE_ETHERTYPE_M GENMASK(15, 0) +#define YT921X_ACL_BINa_ETHERTYPE_ETHERTYPE(x) FIELD_PREP(YT921X_ACL_BINa_ETHERTYPE_ETHERTYPE_M, (x)) + +enum yt921x_l2_type { + YT921X_L2_TYPE_ETH, + YT921X_L2_TYPE_ETHV2, + YT921X_L2_TYPE_ETHSAP, + YT921X_L2_TYPE_ETHSNAP, +}; + +enum yt921x_l3_type { + YT921X_L3_TYPE_OTHER, + YT921X_L3_TYPE_IPV4, + YT921X_L3_TYPE_IPV6, + YT921X_L3_TYPE_ARP, + YT921X_L3_TYPE_LLDP, + YT921X_L3_TYPE_PAE, + YT921X_L3_TYPE_ERP, + YT921X_L3_TYPE_SLOW_PROTOCOL, +}; + +enum yt921x_l4_type { + YT921X_L4_TYPE_OTHER, + YT921X_L4_TYPE_TCP, + YT921X_L4_TYPE_UDP, + YT921X_L4_TYPE_UDPLITE, + YT921X_L4_TYPE_ICMP, + YT921X_L4_TYPE_IGMP, + YT921X_L4_TYPE_MLD, + YT921X_L4_TYPE_ND, +}; + +#define YT921X_UDFn_CTRL(x) (0x210094 + 4 * (x)) +#define YT921X_UDF_CTRL_UDF_TYPE_M GENMASK(8, 7) +#define YT921X_UDF_CTRL_UDF_TYPE(x) FIELD_PREP(YT921X_UDF_CTRL_UDF_TYPE_M, (x)) +#define YT921X_UDF_CTRL_UDF_TYPE_ETH YT921X_UDF_CTRL_UDF_TYPE(0) +#define YT921X_UDF_CTRL_UDF_TYPE_L3 YT921X_UDF_CTRL_UDF_TYPE(1) +#define YT921X_UDF_CTRL_UDF_TYPE_L4 YT921X_UDF_CTRL_UDF_TYPE(2) +#define YT921X_UDF_CTRL_UDF_OFFSET_M GENMASK(6, 0) +#define YT921X_UDF_CTRL_UDF_OFFSET(x) FIELD_PREP(YT921X_UDF_CTRL_UDF_OFFSET_M, (x)) + +#define YT921X_PORTn_RATE(port) (0x220000 + 4 * (port)) +#define YT921X_PORT_RATE_GAP_VALUE GENMASK(4, 0) /* default 20 */ +#define YT921X_METER_SLOT 0x220104 +#define YT921X_METER_SLOT_SLOT_M GENMASK(11, 0) +#define YT921X_PORTn_METER(port) (0x220108 + 4 * (port)) +#define YT921X_PORT_METER_EN BIT(4) +#define YT921X_PORT_METER_ID_M GENMASK(3, 0) +#define YT921X_PORT_METER_ID(x) FIELD_PREP(YT921X_PORT_METER_ID_M, (x)) +#define YT921X_METERn_CTRL(x) (0x220800 + 0x10 * (x)) +#define YT921X_METER_CTRLc_METER_EN BIT(14) +#define YT921X_METER_CTRLc_TOKEN_OVERFLOW_EN BIT(13) /* RFC4115: yellow use unused green bw */ +#define YT921X_METER_CTRLc_DROP_M GENMASK(12, 11) +#define YT921X_METER_CTRLc_DROP(x) FIELD_PREP(YT921X_METER_CTRLc_DROP_M, (x)) +#define YT921X_METER_CTRLc_DROP_GYR YT921X_METER_CTRLc_DROP(0) +#define YT921X_METER_CTRLc_DROP_YR YT921X_METER_CTRLc_DROP(1) +#define YT921X_METER_CTRLc_DROP_R YT921X_METER_CTRLc_DROP(2) +#define YT921X_METER_CTRLc_DROP_NONE YT921X_METER_CTRLc_DROP(3) +#define YT921X_METER_CTRLc_COLOR_BLIND BIT(10) +#define YT921X_METER_CTRLc_UNIT_M GENMASK(9, 7) +#define YT921X_METER_CTRLc_UNIT(x) FIELD_PREP(YT921X_METER_CTRLc_UNIT_M, (x)) +#define YT921X_METER_CTRLc_BYTE_MODE_INCLUDE_GAP BIT(6) /* +GAP_VALUE bytes each packet */ +#define YT921X_METER_CTRLc_PKT_MODE BIT(5) /* 0: byte rate mode */ +#define YT921X_METER_CTRLc_RFC2698 BIT(4) /* 0: RFC4115 */ +#define YT921X_METER_CTRLbc_CBS_M GENMASK_ULL(35, 20) +#define YT921X_METER_CTRLbc_CBS(x) FIELD_PREP(YT921X_METER_CTRLbc_CBS_M, (x)) +#define YT921X_METER_CTRLb_CIR_M GENMASK(19, 2) +#define YT921X_METER_CTRLb_CIR(x) FIELD_PREP(YT921X_METER_CTRLb_CIR_M, (x)) +#define YT921X_METER_CTRLab_EBS_M GENMASK_ULL(33, 18) +#define YT921X_METER_CTRLab_EBS(x) FIELD_PREP(YT921X_METER_CTRLab_EBS_M, (x)) +#define YT921X_METER_CTRLa_EIR_M GENMASK(17, 0) +#define YT921X_METER_CTRLa_EIR(x) FIELD_PREP(YT921X_METER_CTRLa_EIR_M, (x)) +#define YT921X_METERn_STAT(x) (0x221000 + 8 * (x)) + +#define YT921X_MIRROR 0x300300 +#define YT921X_MIRROR_IGR_PORTS_M GENMASK(26, 16) +#define YT921X_MIRROR_IGR_PORTS(x) FIELD_PREP(YT921X_MIRROR_IGR_PORTS_M, (x)) +#define YT921X_MIRROR_IGR_PORTn(port) BIT((port) + 16) +#define YT921X_MIRROR_EGR_PORTS_M GENMASK(14, 4) +#define YT921X_MIRROR_EGR_PORTS(x) FIELD_PREP(YT921X_MIRROR_EGR_PORTS_M, (x)) +#define YT921X_MIRROR_EGR_PORTn(port) BIT((port) + 4) +#define YT921X_MIRROR_PORT_M GENMASK(3, 0) +#define YT921X_MIRROR_PORT(x) FIELD_PREP(YT921X_MIRROR_PORT_M, (x)) + +#define YT921X_PORT_SHAPE_SLOT 0x34000c +#define YT921X_PORT_SHAPE_SLOT_SLOT_M GENMASK(11, 0) +#define YT921X_PORTn_SHAPE_CTRL(port) (0x354000 + 8 * (port)) +#define YT921X_PORT_SHAPE_CTRLb_EN BIT(4) +#define YT921X_PORT_SHAPE_CTRLb_PKT_MODE BIT(3) /* 0: byte rate mode */ +#define YT921X_PORT_SHAPE_CTRLb_UNIT_M GENMASK(2, 0) +#define YT921X_PORT_SHAPE_CTRLb_UNIT(x) FIELD_PREP(YT921X_PORT_SHAPE_CTRLb_UNIT_M, (x)) +#define YT921X_PORT_SHAPE_CTRLa_CBS_M GENMASK(31, 18) +#define YT921X_PORT_SHAPE_CTRLa_CBS(x) FIELD_PREP(YT921X_PORT_SHAPE_CTRLa_CBS_M, (x)) +#define YT921X_PORT_SHAPE_CTRLa_CIR_M GENMASK(17, 0) +#define YT921X_PORT_SHAPE_CTRLa_CIR(x) FIELD_PREP(YT921X_PORT_SHAPE_CTRLa_CIR_M, (x)) +#define YT921X_PORTn_SHAPE_STAT(port) (0x356000 + 4 * (port)) + +#define YT921X_TOKEN_BYTE_C 1 /* 1 token = 2^1 byte */ +#define YT921X_TOKEN_PKT_C -6 /* 1 token = 2^-6 packets */ +#define YT921X_TOKEN_RATE_C -15 +#define YT921X_METER_SLOT_MIN 80 +#define YT921X_METER_UNIT_MAX ((1 << 3) - 1) +#define YT921X_METER_CIR_MAX ((1 << 18) - 1) +#define YT921X_METER_CBS_MAX ((1 << 16) - 1) +#define YT921X_PORT_SHAPE_SLOT_MIN 80 +#define YT921X_SHAPE_UNIT_MAX ((1 << 3) - 1) +#define YT921X_SHAPE_CIR_MAX ((1 << 18) - 1) +#define YT921X_SHAPE_CBS_MAX ((1 << 14) - 1) + +#define YT921X_ACL_ENT_PER_BLK 8 +#define YT921X_ACL_NUM 384 + +struct yt921x_acl_entry { + u32 key[2]; + u32 mask[2]; +}; + +struct yt921x_acl_rule { + unsigned long tag; + enum tc_setup_type type; + + u32 action[3]; + bool sw_assisted; + + u8 mask; + struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK]; +}; + +struct yt921x_acl_blk { + struct yt921x_acl_rule *rules[YT921X_ACL_ENT_PER_BLK]; +}; + +void yt921x_dsa_port_policer_del(struct dsa_switch *ds, int port); +int +yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port, + const struct flow_action_police *police, + struct netlink_ext_ack *extack); +int +yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port, + enum tc_setup_type type, void *type_data); +int +yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, + struct flow_cls_offload *cls, bool ingress); +int +yt921x_dsa_cls_flower_add(struct dsa_switch *ds, int port, + struct flow_cls_offload *cls, bool ingress); +void +yt921x_dsa_port_mirror_del(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror); +int +yt921x_dsa_port_mirror_add(struct dsa_switch *ds, int port, + struct dsa_mall_mirror_tc_entry *mirror, + bool ingress, struct netlink_ext_ack *extack); + +int yt921x_chip_setup_tc(struct yt921x_priv *priv); +int yt921x_chip_setup_acl(struct yt921x_priv *priv); + +#endif From 4a8e05d62ecc34afaa0f56dfb8e4fafbf4d88a6a Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 00:58:20 +0800 Subject: [PATCH 1836/2126] net: dsa: motorcomm: Use NSEC_PER_SEC Get rid of magic numbers. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261009165825.359259-3-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/tc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index 433a428ed070..be3321df8868 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -25,14 +25,14 @@ static u32 rate2token(u64 rate, unsigned int slot_ns, int unit, int C) { int e = 2 * unit + C + YT921X_TOKEN_RATE_C; - return div_u64(ldexpu64(slot_ns * rate, -e), 1000000000); + return div_u64(ldexpu64(slot_ns * rate, -e), NSEC_PER_SEC); } static u64 token2rate(u32 token, unsigned int slot_ns, int unit, int C) { int e = 2 * unit + C + YT921X_TOKEN_RATE_C; - return div_u64(ldexpu64(mul_u32_u32(1000000000, token), e), slot_ns); + return div_u64(ldexpu64(mul_u32_u32(NSEC_PER_SEC, token), e), slot_ns); } /* burst = 2^C * token * 4^unit */ @@ -83,7 +83,7 @@ yt921x_marker_tfm(struct yt921x_marker *marker, u64 rate, u64 burst, } /* Check for matching burst */ - burst_est = div_u64(slot_ns * rate, 1000000000); + burst_est = div_u64(slot_ns * rate, NSEC_PER_SEC); burst_sug = burst_est; if (flags & YT921X_MARKER_PKT_MODE) burst_sug++; From 73db071a66923f0a104165749e308d9204c80e10 Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 00:58:21 +0800 Subject: [PATCH 1837/2126] net: dsa: motorcomm: Enable ACL on demand Track the usage of ACL rules and enable it per port only when it is actually used. This is aligned with ODM recommendations and helps reduce latency. Signed-off-by: David Yang Link: https://patch.msgid.link/20261009165825.359259-4-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/chip.h | 2 + drivers/net/dsa/motorcomm/tc.c | 70 ++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 012de4f444f5..7047ad98f431 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -462,6 +462,8 @@ struct yt921x_port { /* BR_ISOLATED */ bool isolated:1; + unsigned short acl_cnt; + #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS) unsigned char led_duty; unsigned short led_cycle; diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index be3321df8868..a302016912b5 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1055,6 +1055,19 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, return 0; } +/* Ports that _should_ have ACL activated on. ACL_PORT \succeq activated_ports() + */ +static u16 yt921x_acl_activated_ports(const struct yt921x_priv *priv) +{ + u16 mask = 0; + + for (int port = 0; port < YT921X_PORT_NUM; port++) + if (priv->ports[port].acl_cnt) + mask |= BIT(port); + + return mask; +} + static unsigned int yt921x_acl_find(const struct yt921x_priv *priv, enum tc_setup_type type, unsigned long tag) @@ -1199,10 +1212,15 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, { struct yt921x_acl_rule *aclrule; struct yt921x_acl_blk *aclblk; + bool refresh_en = false; unsigned int binid; unsigned int blkid; unsigned int entid; + unsigned long m; + unsigned int o; + u32 ctrl; int res; + int ret; entid = yt921x_acl_find(priv, type, tag); if (entid == UINT_MAX) @@ -1214,9 +1232,27 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, aclrule = aclblk->rules[binid]; aclblk->rules[binid] = NULL; - res = yt921x_acl_commit(priv, entid, aclrule->mask); + ret = yt921x_acl_commit(priv, entid, aclrule->mask); /* the kernel never rolls back on failure */ + m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]); + for_each_set_bit(o, &m, YT921X_PORT_NUM) { + struct yt921x_port *pp = &priv->ports[o]; + + if (!WARN_ON(!pp->acl_cnt)) { + pp->acl_cnt--; + if (pp->acl_cnt) + continue; + } + refresh_en = true; + } + if (refresh_en) { + ctrl = yt921x_acl_activated_ports(priv); + res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl); + if (res) + ret = res; + } + if (aclrule->action[0] & YT921X_ACL_ACTa_METER_EN) clear_bit(FIELD_GET(YT921X_ACL_ACTa_METER_ID_M, aclrule->action[0]), @@ -1227,7 +1263,7 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, kvfree(aclblk); priv->acl_blks[blkid] = NULL; } - return res; + return ret; } static int @@ -1240,11 +1276,12 @@ yt921x_acl_add(struct yt921x_priv *priv, struct yt921x_acl_blk *aclblk; bool use_trap = false; unsigned int meterid; - unsigned long mask; unsigned int binid; unsigned int blkid; unsigned int entid; + unsigned long m; unsigned int o; + u32 ctrl; int res; /* Allocate resources */ @@ -1293,8 +1330,8 @@ yt921x_acl_add(struct yt921x_priv *priv, /* Replace the placeholder resource IDs */ aclrule->mask = 0; - mask = priv->acl_masks[blkid]; - for_each_clear_bit(o, &mask, YT921X_ACL_ENT_PER_BLK) { + m = priv->acl_masks[blkid]; + for_each_clear_bit(o, &m, YT921X_ACL_ENT_PER_BLK) { aclrule->mask |= BIT(o); entscnt--; if (!entscnt) @@ -1312,21 +1349,39 @@ yt921x_acl_add(struct yt921x_priv *priv, else aclrule->action[0] &= ~YT921X_ACL_ACTa_METER_EN; + /* Activate ACL if needed */ + ctrl = 0; + m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]); + for_each_set_bit(o, &m, YT921X_PORT_NUM) + if (!priv->ports[o].acl_cnt) + ctrl |= YT921X_ACL_PORT_PORTn(o); + if (ctrl) { + ctrl |= yt921x_acl_activated_ports(priv); + res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl); + if (res) + goto err; + } + /* Write rules */ aclblk->rules[binid] = aclrule; res = yt921x_acl_commit(priv, entid, aclrule->mask); if (res) { aclblk->rules[binid] = NULL; - kvfree(aclrule); goto err; } + /* Bookkeeping */ + m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]); + for_each_set_bit(o, &m, YT921X_PORT_NUM) + priv->ports[o].acl_cnt++; + if (meterid < YT921X_METER_NUM) set_bit(meterid, priv->meters_map); priv->acl_masks[blkid] |= aclrule->mask; return 0; err: + kvfree(aclrule); if (!priv->acl_masks[blkid]) { kvfree(aclblk); priv->acl_blks[blkid] = NULL; @@ -1487,8 +1542,7 @@ int yt921x_chip_setup_acl(struct yt921x_priv *priv) if (res) return res; - ctrl = YT921X_ACL_PORT_PORTS_M; - res = yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl); + res = yt921x_reg_write(priv, YT921X_ACL_PORT, 0); if (res) return res; From f9822b4ca6ef21274151c256e46743d208bff5a7 Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 10 Oct 2026 00:58:22 +0800 Subject: [PATCH 1838/2126] net: dsa: motorcomm: Add TC prio support The HW orders ACL rules by the 9-bit ORD field (512 values, larger matching first), while TC priorities span 1..U16_MAX with the smallest meaning the highest. Map them as evenly as possible, and reject others which do not map onto a hardware order instead of silently colliding with a neighbouring one. Signed-off-by: David Yang Link: https://patch.msgid.link/20261009165825.359259-5-mmyangfl@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/motorcomm/tc.c | 35 +++++++++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/tc.h | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index a302016912b5..3e0f80500f41 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1029,7 +1029,10 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, const struct flow_cls_offload *cls, bool ingress, struct yt921x_priv *priv) { + const unsigned int scale = (U16_MAX + 1) / YT921X_ACL_ORD_NUM; struct netlink_ext_ack *extack = cls->common.extack; + u32 prio = cls->common.prio; + u32 ord; int res; if (!ingress) { @@ -1042,6 +1045,36 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, return -EOPNOTSUPP; } + /* Lower TC priorities take precedence, while larger orders win in + * hardware. Spread the 512 hardware orders over the TC priority range + * as evenly as possible, retaining the relative order: + * + * prio 65535 -> ORD 0 catchall filter + * prio 65408 -> ORD 1 highest mappable TC priority + * ... + * prio 49152 -> ORD 128 default value for the first tc flower rule + * ... + * prio 128 -> ORD 511 + * prio 0 (invalid TC priority) + * + * The catchall filter always comes with priority 65535; pin it to ORD + * 0, the lowest hardware order, instead of rejecting it. + * + * Prefer explicit rejects over implicit behaviour changes: reject + * the priorities which do not map onto a hardware order instead of + * silently colliding with a neighbouring one. + */ + if (prio == U16_MAX) { + ord = 0; + } else if (!(prio % scale)) { + ord = YT921X_ACL_ORD_NUM - prio / scale; + } else { + NL_SET_ERR_MSG_FMT_MOD(extack, + "Invalid priority %u, must be a multiple of %u or 65535", + prio, scale); + return -EOPNOTSUPP; + } + res = yt921x_acl_rule_ext_parse_flow_action(ruleext, cls, priv, port); if (res) return res; @@ -1049,7 +1082,7 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port, if (res) return res; - yt921x_acl_rule_set_ports(&ruleext->r, 0, BIT(port)); + yt921x_acl_rule_set_ports(&ruleext->r, ord, BIT(port)); ruleext->r.tag = cls->cookie; ruleext->r.type = TC_SETUP_CLSFLOWER; return 0; diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h index 32b53f1f3825..f11136a1c5e2 100644 --- a/drivers/net/dsa/motorcomm/tc.h +++ b/drivers/net/dsa/motorcomm/tc.h @@ -331,6 +331,7 @@ enum yt921x_l4_type { #define YT921X_ACL_ENT_PER_BLK 8 #define YT921X_ACL_NUM 384 +#define YT921X_ACL_ORD_NUM 512 struct yt921x_acl_entry { u32 key[2]; From 4f9fbb30e341b69357e8929dd96a8364d436e923 Mon Sep 17 00:00:00 2001 From: Magnus Lindholm Date: Sun, 11 Oct 2026 21:41:58 +0200 Subject: [PATCH 1839/2126] tg3: normalize inherited BCM5718 register byte order Firmware can leave BCM5718 vendor registers byte-swapped while standard PCI fields retain normal byte order. Detect this from the host-control revision marker, byte-swap bit and swapped product ID, without matching a platform model or PCI subsystem. Prefer the normal revision marker so already-normal controllers do not enter the normalization path. Hardware swapping can accommodate big-endian register accesses, but tg3 already initializes misc_host_ctrl with WORD_SWAP set and BYTE_SWAP clear on both little- and big-endian builds. Its normal MMIO path uses readl()/writel(); on SPARC64 these use little-endian accesses. Restore that existing register mode rather than choosing a mode based on host endianness. The swab32() on the initial write compensates for the device's inherited state; subsequent accesses use the normal driver path. DMA byte ordering is controlled separately through GRC_MODE. Leave those settings, including the __BIG_ENDIAN handling for non-frame data, unchanged. Check both register readbacks and keep this in probe so PCI access or validation failures can abort initialization. Limit detection to BCM5718, whose register layout and inherited state were checked on M3000 hardware. Other controller families retain their existing initialization path. Signed-off-by: Magnus Lindholm Reviewed-by: Sebastian Andrzej Siewior Link: https://patch.msgid.link/20261011194228.981141-1-linmag7@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/tg3.c | 72 ++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 8b6806a79edf..cc618f8beb3f 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -16248,6 +16248,65 @@ static bool tg3_10_100_only_device(struct tg3 *tp, return false; } +static int tg3_fw_byteorder(struct tg3 *tp, u32 *misc_ctrl_reg) +{ + struct pci_dev *pdev = tp->pdev; + u32 prodid, expected_prodid, normalized, readback; + int reg, err; + + /* Prefer the normal revision marker before testing the swapped state. */ + if (pdev->device != TG3PCI_DEVICE_TIGON3_5718 || + (*misc_ctrl_reg >> 28) == ASIC_REV_USE_PROD_ID_REG || + (swab32(*misc_ctrl_reg) >> 28) != ASIC_REV_USE_PROD_ID_REG || + !(swab32(*misc_ctrl_reg) & MISC_HOST_CTRL_BYTE_SWAP)) + return 0; + + /* Standard PCI fields are normal; verify the swapped vendor registers. */ + reg = TG3PCI_GEN2_PRODID_ASICREV; + err = pci_read_config_dword(pdev, reg, &prodid); + if (err) + goto config_error; + expected_prodid = swab32(prodid); + if ((expected_prodid >> 12) != ASIC_REV_5717) { + dev_err(&pdev->dev, "unexpected swapped BCM5718 product ID %08x\n", + prodid); + return -ENODEV; + } + + normalized = (swab32(*misc_ctrl_reg) & MISC_HOST_CTRL_CHIPREV) | + tp->misc_host_ctrl; + reg = TG3PCI_MISC_HOST_CTRL; + err = pci_write_config_dword(pdev, reg, swab32(normalized)); + if (err) + goto config_error; + err = pci_read_config_dword(pdev, reg, &readback); + if (err) + goto config_error; + if (readback != normalized) { + dev_err(&pdev->dev, "BCM5718 host-control readback mismatch %08x\n", + readback); + return -EIO; + } + + reg = TG3PCI_GEN2_PRODID_ASICREV; + err = pci_read_config_dword(pdev, reg, &prodid); + if (err) + goto config_error; + if (prodid != expected_prodid) { + dev_err(&pdev->dev, "BCM5718 product-ID readback mismatch %08x\n", + prodid); + return -EIO; + } + *misc_ctrl_reg = readback; + dev_dbg(&pdev->dev, "normalized firmware register byte order\n"); + return 0; + +config_error: + dev_err(&pdev->dev, "BCM5718 PCI config access at %#x failed (%d)\n", + reg, err); + return pcibios_err_to_errno(err); +} + static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent) { u32 misc_ctrl_reg; @@ -16272,8 +16331,17 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent) * sure that indirect register accesses are enabled before * the first operation. */ - pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, - &misc_ctrl_reg); + err = pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, + &misc_ctrl_reg); + if (err && tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) { + dev_err(&tp->pdev->dev, "PCI host-control read failed (%d)\n", + err); + return pcibios_err_to_errno(err); + } + err = tg3_fw_byteorder(tp, &misc_ctrl_reg); + if (err) + return err; + tp->misc_host_ctrl |= (misc_ctrl_reg & MISC_HOST_CTRL_CHIPREV); pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, From 001e9181ada8481cfc5dc6f46c9bf8d24efbb57c Mon Sep 17 00:00:00 2001 From: Or Har-Toov Date: Sun, 11 Oct 2026 12:38:28 +0300 Subject: [PATCH 1840/2126] net/mlx5: Remove max_external_SFs device resource The device-level max_external_SFs resource is redundant now that per-port max_SFs resources are registered on each PF port representor. Users can look up SF limits per-port directly via 'devlink port show' to correlate with controller number and pfnum. Signed-off-by: Or Har-Toov Reviewed-by: Shay Drori Reviewed-by: Moshe Shemesh Signed-off-by: Tariq Toukan Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011093828.784454-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../networking/devlink/devlink-resource.rst | 4 ---- .../net/ethernet/mellanox/mlx5/core/devlink.h | 1 - .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 19 ++++++------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Documentation/networking/devlink/devlink-resource.rst b/Documentation/networking/devlink/devlink-resource.rst index 47eec8f875b4..b7172d94b2c6 100644 --- a/Documentation/networking/devlink/devlink-resource.rst +++ b/Documentation/networking/devlink/devlink-resource.rst @@ -89,14 +89,12 @@ To list resources for all devlink devices and ports: $ devlink resource show pci/0000:03:00.0: name max_local_SFs size 128 unit entry dpipe_tables none - name max_external_SFs size 128 unit entry dpipe_tables none pci/0000:03:00.0/196608: name max_SFs size 128 unit entry dpipe_tables none pci/0000:03:00.0/196609: name max_SFs size 128 unit entry dpipe_tables none pci/0000:03:00.1: name max_local_SFs size 128 unit entry dpipe_tables none - name max_external_SFs size 128 unit entry dpipe_tables none pci/0000:03:00.1/196708: name max_SFs size 128 unit entry dpipe_tables none pci/0000:03:00.1/196709: @@ -124,10 +122,8 @@ To dump only device-level resources across all devices: $ devlink resource show scope dev pci/0000:03:00.0: name max_local_SFs size 128 unit entry dpipe_tables none - name max_external_SFs size 128 unit entry dpipe_tables none pci/0000:03:00.1: name max_local_SFs size 128 unit entry dpipe_tables none - name max_external_SFs size 128 unit entry dpipe_tables none To dump only port-level resources across all devices: diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.h b/drivers/net/ethernet/mellanox/mlx5/core/devlink.h index 4fbb3926a3e5..b4092eadfe53 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.h @@ -8,7 +8,6 @@ enum mlx5_devlink_resource_id { MLX5_DL_RES_MAX_LOCAL_SFS = 1, - MLX5_DL_RES_MAX_EXTERNAL_SFS, __MLX5_ID_RES_MAX, MLX5_ID_RES_MAX = __MLX5_ID_RES_MAX - 1, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c index 1724bf7e0e7a..c36dbd7de877 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c @@ -262,24 +262,17 @@ static void mlx5_sf_hw_table_res_unregister(struct mlx5_core_dev *dev) devl_resources_unregister(priv_to_devlink(dev)); } -static int mlx5_sf_hw_table_res_register(struct mlx5_core_dev *dev, u16 max_fn, - u16 max_ext_fn) +static int mlx5_sf_hw_table_res_register(struct mlx5_core_dev *dev, + u16 max_fn) { struct devlink_resource_size_params size_params; struct devlink *devlink = priv_to_devlink(dev); - int err; devlink_resource_size_params_init(&size_params, max_fn, max_fn, 1, DEVLINK_RESOURCE_UNIT_ENTRY); - err = devl_resource_register(devlink, "max_local_SFs", max_fn, MLX5_DL_RES_MAX_LOCAL_SFS, - DEVLINK_RESOURCE_ID_PARENT_TOP, &size_params); - if (err) - return err; - - devlink_resource_size_params_init(&size_params, max_ext_fn, max_ext_fn, 1, - DEVLINK_RESOURCE_UNIT_ENTRY); - return devl_resource_register(devlink, "max_external_SFs", max_ext_fn, - MLX5_DL_RES_MAX_EXTERNAL_SFS, DEVLINK_RESOURCE_ID_PARENT_TOP, + return devl_resource_register(devlink, "max_local_SFs", max_fn, + MLX5_DL_RES_MAX_LOCAL_SFS, + DEVLINK_RESOURCE_ID_PARENT_TOP, &size_params); } @@ -303,7 +296,7 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev) if (err) return err; - if (mlx5_sf_hw_table_res_register(dev, max_fn, max_ext_fn)) + if (mlx5_sf_hw_table_res_register(dev, max_fn)) mlx5_core_dbg(dev, "failed to register max SFs resources"); if (!max_fn && !max_ext_fn && !mlx5_esw_has_spf_sfs(dev)) From befe96ed37d59b2940801e1682a0f410191da573 Mon Sep 17 00:00:00 2001 From: Henry Martin Date: Sat, 10 Oct 2026 16:49:58 +0800 Subject: [PATCH 1841/2126] ipconfig: fix use-after-free of device list after ic_close_devs() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ic_close_devs() kfree()s every ic_device node but leaves the static ic_first_dev and ic_dev pointers dangling behind. When a DHCP negotiation gets an OFFER but never the matching ACK, ic_bootp_recv() accepts the OFFER and records ic_dev = , the round times out and ic_close_devs() frees the whole list — node included. The next failed retry round runs ic_close_devs() once more, evaluating selected_dev = ic_dev ? ic_dev->dev : NULL; against the freed ic_device — an 8-byte use-after-free read. KASAN confirms: BUG: KASAN: slab-use-after-free in ic_close_devs+0x214/0x220 Read of size 8 ic_close_devs <- ip_auto_config Allocated by: ip_auto_config (ic_open_devs) Freed by: ic_close_devs <- ip_auto_config NULL both pointers after the free loop so retry rounds take the clean empty-list path. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life Fixes: 46acf7bdbc72 ("Revert "net: ipv4: handle DSA enabled master network devices"") Signed-off-by: Henry Martin Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261010085003.3261587-1-bsdhenrymartin@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv4/ipconfig.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index 1b8585404a41..d6db562636f3 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c @@ -346,6 +346,9 @@ static void __init ic_close_devs(void) kfree(d); } rtnl_unlock(); + + ic_first_dev = NULL; + ic_dev = NULL; } /* From f42d67a5044e9a36eb9c2a0967e9492e52a1949b Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Sun, 11 Oct 2026 18:43:00 +0800 Subject: [PATCH 1842/2126] selftests: net: bareudp: Add stream tests with software GSO The bareudp tests only send pings, which are not GSO packets, so the segmentation path of bareudp is not covered. Copy a file over TCP from NS0 to NS3 with socat after the IPv4 and IPv6 ping tests, with UDP tunnel segmentation offload disabled on the underlay veths, so that the GSO packets encapsulated by bareudp are segmented in software. Raise the MTU of the underlay veths, so that full sized packets fit with the encapsulation, as there is no path MTU discovery through bareudp. The MPLS overlay gets no stream test: bareudp does not set mpls_features, so MPLS GSO packets are segmented by mpls_gso before they reach bareudp, and are dropped if mpls_gso is not available. The ping and stream tests share the result reporting, so move it into report_result(). Without socat or ethtool, the stream tests are skipped. Without commit c57b2e60d4bf ("bareudp: set the inner protocol to the protocol of the packet"), the IPv4 and IPv6 streams over UDPv6, and the IPv6 stream over UDPv4 in multiproto mode, time out. Suggested-by: Willem de Bruijn Signed-off-by: Haishuang Yan Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011104300.1606351-1-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/bareudp.sh | 92 ++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/net/bareudp.sh b/tools/testing/selftests/net/bareudp.sh index d9e5b967f815..15f102143fd3 100755 --- a/tools/testing/selftests/net/bareudp.sh +++ b/tools/testing/selftests/net/bareudp.sh @@ -105,16 +105,27 @@ # | (encapsulated with MPLS label 200) | # | | # +-----------------------------------------------------------------------+ +# +# Besides the ping tests, a file is copied over TCP from NS0 to NS3 with +# socat for the IPv4 and IPv6 overlays. UDP tunnel segmentation offload is +# disabled on veth12 and veth21, so that the GSO packets encapsulated by +# bareudp are segmented in software. These two veths get a larger MTU to fit +# the encapsulation. . ./lib.sh ERR=4 # Return 4 by default, which is the SKIP code for kselftest PING6="ping" PAUSE_ON_FAIL="no" +STREAM="yes" +STREAM_PORT=5000 +STREAM_TIMEOUT=10 +TMPFILE="" # Exit the script after having removed the network namespaces it created exit_cleanup() { + [ -n "${TMPFILE}" ] && rm -f "${TMPFILE}" cleanup_all_ns if [ "${ERR}" -eq 4 ]; then @@ -180,6 +191,29 @@ setup_underlay() tc -netns "${NS1}" qdisc add dev veth10 ingress tc -netns "${NS2}" qdisc add dev veth23 ingress + + if [ "${STREAM}" = "yes" ]; then + # Leave room for the encapsulation on the underlay, so that full + # sized packets from NS0 can be tunnelled without fragmentation + ip -netns "${NS1}" link set dev veth12 mtu 1600 + ip -netns "${NS2}" link set dev veth21 mtu 1600 + + # Segment the encapsulated GSO packets in software + ip netns exec "${NS1}" ethtool -K veth12 \ + tx-udp_tnl-segmentation off \ + tx-udp_tnl-csum-segmentation off + ip netns exec "${NS2}" ethtool -K veth21 \ + tx-udp_tnl-segmentation off \ + tx-udp_tnl-csum-segmentation off + + TMPFILE=$(mktemp) + dd if=/dev/urandom of="${TMPFILE}" bs=1M count=16 status=none + + ip netns exec "${NS3}" socat -u \ + TCP6-LISTEN:"${STREAM_PORT}",ipv6only=0,reuseaddr,fork \ + OPEN:/dev/null & + wait_local_port_listen "${NS3}" "${STREAM_PORT}" tcp + fi } # Set up the IPv4, IPv6 and MPLS overlays. @@ -252,9 +286,6 @@ setup_overlay_mpls() # * $2: the IP address to ping, # * $3: a human readable description of the purpose of the test. # -# If the test fails and PAUSE_ON_FAIL is active, the user is given the -# possibility to continue with the next test or to quit immediately. -# ping_test_one() { local PING="$1"; readonly PING @@ -269,7 +300,50 @@ ping_test_one() RET=$? set -e - if [ "${RET}" -eq 0 ]; then + report_result "${RET}" +} + +# Copy a file over TCP from NS0 to NS3 and print the result +# +# Parameters: +# +# * $1: the socat address of the receiver, +# * $2: a human readable description of the purpose of the test. +# +stream_test_one() +{ + local ADDR="$1"; readonly ADDR + local MSG="$2"; readonly MSG + local RET + + printf "TEST: %-60s " "${MSG}" + + if [ "${STREAM}" != "yes" ]; then + printf "[SKIP]\n" + return + fi + + set +e + ip netns exec "${NS0}" timeout "${STREAM_TIMEOUT}" \ + socat -u OPEN:"${TMPFILE}" "${ADDR}" > /dev/null 2>&1 + RET=$? + set -e + + report_result "${RET}" +} + +# Print the result of a test +# +# Parameters: +# +# * $1: the exit code of the test. +# +# If the test fails and PAUSE_ON_FAIL is active, the user is given the +# possibility to continue with the next test or to quit immediately. +# +report_result() +{ + if [ "$1" -eq 0 ]; then printf "[ OK ]\n" else ERR=1 @@ -307,9 +381,13 @@ ping_test() if [ $IPV4 ]; then ping_test_one "ping" "192.0.2.103" "IPv4 packets over ${UNDERLAY}${MODE}" + stream_test_one "TCP4:192.0.2.103:${STREAM_PORT}" \ + "IPv4 stream over ${UNDERLAY}${MODE}" fi if [ $IPV6 ]; then ping_test_one "${PING6}" "2001:db8::103" "IPv6 packets over ${UNDERLAY}${MODE}" + stream_test_one "TCP6:[2001:db8::103]:${STREAM_PORT}" \ + "IPv6 stream over ${UNDERLAY}${MODE}" fi if [ $MPLS_UC ]; then ping_test_one "${PING6}" "2001:db8::203" "Unicast MPLS packets over ${UNDERLAY}${MODE}" @@ -471,6 +549,12 @@ check_features() # Use ping6 on systems where ping doesn't handle IPv6 ping -w 1 -c 1 ::1 > /dev/null 2>&1 || PING6="ping6" + + if [ ! -x "$(command -v socat)" ] || + [ ! -x "$(command -v ethtool)" ]; then + echo "socat or ethtool not found, skipping the stream tests" >&2 + STREAM="no" + fi } usage() From 23171065fb436195981ca32f9e49dcf852dbd018 Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Sun, 11 Oct 2026 08:12:07 +0200 Subject: [PATCH 1843/2126] dpll: zl3073x: do not offer 0 Hz as a supported pin frequency zl3073x_pin_props_get() always adds the current pin frequency to the supported list without checking it. A sub-Hz frequency reads back as 0 Hz, so 0 Hz can then be requested and the output frequency set callback divides by zero. A 0 Hz entry in the firmware node is not rejected either: it is offered for an input pin, and for an output pin zl3073x_pin_check_freq() divides by it at probe time. Do not add a 0 Hz current frequency and reject 0 Hz in zl3073x_pin_check_freq(). If the list ends up empty, do not publish it at all, as the DPLL core rejects an empty non-NULL list. Found by code inspection, not triggered at runtime. Fixes: 85a9aaac4a38 ("dpll: zl3073x: Include current frequency in supported frequencies list") Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera Fixes: a99a9f0ebdaa ("dpll: zl3073x: Read DPLL types and pin properties from system firmware") Link: https://patch.msgid.link/20261011061211.448373-2-ivecera@redhat.com Signed-off-by: Jakub Kicinski --- drivers/dpll/zl3073x/prop.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/dpll/zl3073x/prop.c b/drivers/dpll/zl3073x/prop.c index ac9d41d0f978..768e5424de2d 100644 --- a/drivers/dpll/zl3073x/prop.c +++ b/drivers/dpll/zl3073x/prop.c @@ -30,7 +30,7 @@ static bool zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir, u8 id, u64 freq) { - if (freq > U32_MAX) + if (!freq || freq > U32_MAX) goto err_inv_freq; if (dir == DPLL_PIN_DIRECTION_INPUT) { @@ -295,13 +295,20 @@ skip_fwnode_props: goto err_alloc_ranges; } - /* Start with current frequency at index 0 */ - ranges[0] = (struct dpll_pin_frequency)DPLL_PIN_FREQUENCY(curr_freq); + /* Start with current frequency at index 0. A sub-Hz frequency is + * read back as 0 Hz and cannot be set, so it is not offered. + */ + j = 0; + if (curr_freq) { + struct dpll_pin_frequency freq = DPLL_PIN_FREQUENCY(curr_freq); + + ranges[j++] = freq; + } /* Add frequencies from firmware node, skipping current frequency * and filtering out frequencies not representable by device */ - for (i = 0, j = 1; i < num_freqs; i++) { + for (i = 0; i < num_freqs; i++) { struct dpll_pin_frequency freq = DPLL_PIN_FREQUENCY(freqs[i]); if (freqs[i] == curr_freq) @@ -312,6 +319,14 @@ skip_fwnode_props: } } + /* The DPLL core rejects a non-NULL list without entries, so do + * not publish the array at all when nothing is settable. + */ + if (!j) { + kfree(ranges); + ranges = NULL; + } + /* Save number of freq ranges and pointer to them into pin properties */ props->dpll_props.freq_supported = ranges; props->dpll_props.freq_supported_num = j; From f8993627d3101de0833022ac88083ac0147aae7d Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Sun, 11 Oct 2026 08:12:08 +0200 Subject: [PATCH 1844/2126] dpll: zl3073x: reject inexact frequencies for N-divided outputs For N-divided outputs the P-pin and N-pin share the output divisor and the N-pin frequency is synth_freq / (div * esync_n_period). The frequency set helper computed esync_n_period with a truncating division and only rejected a zero result, so a frequency that does not divide evenly was silently rounded. Setting the P-pin could then shift the N-pin frequency too (e.g. 600 MHz synth, div=60, period=10 gives P=10 MHz, N=1 MHz; setting P to 2.5 MHz moves N to 1.25 MHz). When setting the P-pin, the product esync_n_period * div used for the rescale was computed in 32 bits and could wrap, so a wrong N divider was stored for low N-pin frequencies. Require esync_n_period >= 2 so the N-pin frequency stays below the P-pin one, reject a P-pin frequency for which the esync_n_period keeping the N-pin frequency does not fit into 32 bits, and check the division remainder and reject the request if it is not exact. Found by code inspection, not triggered at runtime. Fixes: ce26d7ca50a5 ("dpll: zl3073x: Add support to get/set frequency on pins") Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera Link: https://patch.msgid.link/20261011061211.448373-3-ivecera@redhat.com Signed-off-by: Jakub Kicinski --- drivers/dpll/zl3073x/dpll.c | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index f2e137475b40..7a617d9bd671 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -987,6 +987,7 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, const struct zl3073x_synth *synth; u32 new_div, synth_freq; struct zl3073x_out out; + u64 n_period, rem; u8 out_id; guard(mutex)(&zldpll->lock); @@ -1014,16 +1015,11 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, } if (zl3073x_dpll_is_p_pin(pin)) { - /* We are going to change output frequency for P-pin but - * if the requested frequency is less than current N-pin - * frequency then indicate a failure as we are not able - * to compute N-pin divisor to keep its frequency unchanged. - * - * Update divisor for N-pin to keep N-pin frequency. + /* Keep the N-pin frequency: the new P-pin frequency has to be + * a multiple of it, at least twice as high. */ - out.esync_n_period = (out.esync_n_period * out.div) / new_div; - if (!out.esync_n_period) - return -EINVAL; + n_period = mul_u32_u32(out.esync_n_period, out.div); + n_period = div64_u64_rem(n_period, new_div, &rem); /* Update the output divisor */ out.div = new_div; @@ -1031,17 +1027,31 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, /* For 50/50 duty cycle the divisor is equal to width */ out.width = out.div; } else { - /* We are going to change frequency of N-pin but if - * the requested freq is greater or equal than freq of P-pin - * in the output pair we cannot compute divisor for the N-pin. - * In this case indicate a failure. - * - * Update divisor for N-pin + /* The N-pin frequency has to divide the P-pin frequency and + * be at most half of it. */ - out.esync_n_period = div64_u64(synth_freq, frequency * out.div); - if (!out.esync_n_period) - return -EINVAL; + n_period = frequency * out.div; + n_period = div64_u64_rem(synth_freq, n_period, &rem); } + if (n_period < 2) { + NL_SET_ERR_MSG_FMT(extack, + "OUT%uN freq must be at most half of OUT%uP freq", + out_id, out_id); + return -EINVAL; + } + if (n_period > U32_MAX) { + NL_SET_ERR_MSG_FMT(extack, + "OUT%uN freq is too low for OUT%uP freq", + out_id, out_id); + return -EINVAL; + } + if (rem != 0) { + NL_SET_ERR_MSG_FMT(extack, + "OUT%uN freq must divide OUT%uP freq", + out_id, out_id); + return -EINVAL; + } + out.esync_n_period = n_period; /* For 50/50 duty cycle the divisor is equal to width */ out.esync_n_width = out.esync_n_period; From 456027325c9cd2be94229687f2c412ae6f351bd8 Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Sun, 11 Oct 2026 08:12:09 +0200 Subject: [PATCH 1845/2126] dpll: zl3073x: reject output frequencies with too small divisor The output divisor has to be at least 2: a divisor of 1 bypasses the divider and the hardware then ignores the pulse width and eSync registers. For the N-pin of an N-divided output the N divider (>= 2) applies on top, so its effective divisor has to be at least 4. zl3073x_pin_check_freq() only checked that the frequency divides the synth frequency. Require also the minimum divisor. For N-divided outputs this is necessary but not sufficient, the rest is checked by the frequency set callback. Hit during development: an N-pin frequency that needs an N divider of 1 was accepted, and with esync_n_period = 1 the N-pin produced no output on an oscilloscope. Fixes: a99a9f0ebdaa ("dpll: zl3073x: Read DPLL types and pin properties from system firmware") Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera Link: https://patch.msgid.link/20261011061211.448373-4-ivecera@redhat.com Signed-off-by: Jakub Kicinski --- drivers/dpll/zl3073x/prop.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/dpll/zl3073x/prop.c b/drivers/dpll/zl3073x/prop.c index 768e5424de2d..4e006ed5950a 100644 --- a/drivers/dpll/zl3073x/prop.c +++ b/drivers/dpll/zl3073x/prop.c @@ -22,7 +22,8 @@ * The function checks the given frequency is valid for the device. For input * pins it checks that the frequency can be factorized using supported base * frequencies. For output pins it checks that the frequency divides connected - * synth frequency without remainder. + * synth frequency without remainder and that the resulting divisor is not + * below the minimum the driver supports. * * Return: true if the frequency is valid, false if not. */ @@ -41,18 +42,38 @@ zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir, if (rc) goto err_inv_freq; } else { - u32 synth_freq; - u8 out, synth; + u32 synth_freq, div, min_div, rem; + const struct zl3073x_out *out; + u8 out_id, synth; /* Get output pin synthesizer */ - out = zl3073x_output_pin_out_get(id); - synth = zl3073x_dev_out_synth_get(zldev, out); + out_id = zl3073x_output_pin_out_get(id); + synth = zl3073x_dev_out_synth_get(zldev, out_id); /* Get synth frequency */ synth_freq = zl3073x_dev_synth_freq_get(zldev, synth); /* Check the frequency divides synth frequency */ - if (synth_freq % (u32)freq) + div = div_u64_rem(synth_freq, freq, &rem); + if (rem) + goto err_inv_freq; + + /* The driver requires an output divisor of at least 2 - + * below that the hardware bypasses the divider and ignores + * the pulse width and eSync registers the driver programs. + * For the N-pin of an N-divided output the effective divisor + * also includes the N divider (>= 2), so the minimum is 4. + * For N-divided outputs this is only a necessary condition - + * whether the frequency can be set also depends on the output + * divisor shared by both pins, which is checked when the + * frequency is set. + */ + out = zl3073x_out_state_get(zldev, out_id); + if (zl3073x_out_is_ndiv(out) && zl3073x_is_n_pin(id)) + min_div = 4; + else + min_div = 2; + if (div < min_div) goto err_inv_freq; } From bf6f105f2cb6477e36a9312477d0aa32a43aa13d Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Sun, 11 Oct 2026 08:12:10 +0200 Subject: [PATCH 1846/2126] dpll: zl3073x: make embedded sync follow the output carrier frequency The eSync period and width are relative to the output carrier, but changing the output frequency did not update them, so eSync ran at a wrong frequency and duty cycle. For a 1 Hz carrier esync_get() returns -EOPNOTSUPP, so eSync left enabled could not be disabled. Factor out zl3073x_out_esync_{is_enabled,enable,disable}() helpers and use them in frequency_set() to recompute the eSync period and width for the new carrier, or to disable eSync for a 1 Hz carrier. Also compute the reported pulse width in 64 bits, as 50 * esync_n_width overflows u32 for low carrier frequencies. Hit during development, confirmed on an oscilloscope. Fixes: ce26d7ca50a5 ("dpll: zl3073x: Add support to get/set frequency on pins") Fixes: 634ca2cb06d2 ("dpll: zl3073x: Add support to get/set esync on pins") Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera Link: https://patch.msgid.link/20261011061211.448373-5-ivecera@redhat.com Signed-off-by: Jakub Kicinski --- drivers/dpll/zl3073x/dpll.c | 46 +++++++++++++++++++------------------ drivers/dpll/zl3073x/out.h | 36 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index 7a617d9bd671..6d9a6d21d30b 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -878,7 +878,7 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin, esync->range = esync_freq_ranges; esync->range_num = ARRAY_SIZE(esync_freq_ranges); - if (zl3073x_out_clock_type_get(out) != ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC) { + if (!zl3073x_out_esync_is_enabled(out)) { /* No need to read esync data if it is not enabled */ esync->freq = 0; esync->pulse = 0; @@ -894,7 +894,7 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin, * Note that half pulse width is in units of half synth cycles, which * is why it reduces down to be output_div. */ - esync->pulse = (50 * out->esync_n_width) / out->div; + esync->pulse = div_u64(mul_u32_u32(50, out->esync_n_width), out->div); return 0; } @@ -926,32 +926,17 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, if (zl3073x_out_is_ndiv(&out)) return -EOPNOTSUPP; - /* Update clock type in output mode */ - if (freq) - zl3073x_out_clock_type_set(&out, - ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC); - else - zl3073x_out_clock_type_set(&out, - ZL_OUTPUT_MODE_CLOCK_TYPE_NORMAL); - - /* If esync is being disabled just write mailbox and finish */ - if (!freq) + if (!freq) { + zl3073x_out_esync_disable(&out); return zl3073x_out_state_set(zldev, out_id, &out); + } /* Get attached synth frequency */ synth = zl3073x_synth_state_get(zldev, zl3073x_out_synth_get(&out)); synth_freq = zl3073x_synth_freq_get(synth); - /* Compute and update esync period */ - out.esync_n_period = synth_freq / (u32)freq / out.div; - - /* Half of the period in units of 1/2 synth cycle can be represented by - * the output_div. To get the supported esync pulse width of 25% of the - * period the output_div can just be divided by 2. Note that this - * assumes that output_div is even, otherwise some resolution will be - * lost. - */ - out.esync_n_width = out.div / 2; + /* Enable 1PPS eSync for this pin frequency */ + zl3073x_out_esync_enable(&out, synth_freq / out.div); /* Commit output configuration */ return zl3073x_out_state_set(zldev, out_id, &out); @@ -1010,6 +995,23 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, /* For 50/50 duty cycle the divisor is equal to width */ out.width = new_div; + /* The embedded sync period and width are computed relative to + * the output carrier so they have to be adjusted to follow the + * new frequency. + */ + if (zl3073x_out_esync_is_enabled(&out)) { + if (frequency == 1) { + /* eSync cannot work on a 1 Hz carrier */ + zl3073x_out_esync_disable(&out); + } else { + /* Update esync period and width according to + * the new frequency. + */ + zl3073x_out_esync_enable(&out, + synth_freq / out.div); + } + } + /* Commit output configuration */ return zl3073x_out_state_set(zldev, out_id, &out); } diff --git a/drivers/dpll/zl3073x/out.h b/drivers/dpll/zl3073x/out.h index 660889c57bff..d2b8b4eb5a76 100644 --- a/drivers/dpll/zl3073x/out.h +++ b/drivers/dpll/zl3073x/out.h @@ -134,4 +134,40 @@ static inline u8 zl3073x_out_synth_get(const struct zl3073x_out *out) return FIELD_GET(ZL_OUTPUT_CTRL_SYNTH_SEL, out->ctrl); } +static inline bool zl3073x_out_esync_is_enabled(const struct zl3073x_out *out) +{ + u8 clock_type = zl3073x_out_clock_type_get(out); + + return clock_type == ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC; +} + +static inline +void zl3073x_out_esync_enable(struct zl3073x_out *out, u32 base_freq) +{ + /* Period is expressed as the number of output divider clock cycles. + * So for 1 Hz the period is equal to base frequency. + */ + out->esync_n_period = base_freq; + + /* Half of the period in units of 1/2 synth cycle can be represented by + * the output_div. To get the supported esync pulse width of 25% of the + * period the output_div can just be divided by 2. Note that this + * assumes that output_div is even, otherwise some resolution will be + * lost. + */ + out->esync_n_width = out->div / 2; + + /* Update the clock type */ + zl3073x_out_clock_type_set(out, ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC); +} + +static inline +void zl3073x_out_esync_disable(struct zl3073x_out *out) +{ + /* Just update the clock type. The eSync period and width are + * ignored for this clock type. + */ + zl3073x_out_clock_type_set(out, ZL_OUTPUT_MODE_CLOCK_TYPE_NORMAL); +} + #endif /* _ZL3073X_OUT_H */ From 0748e473b65a8c8690e250cdf7cc4f5a93252493 Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Sun, 11 Oct 2026 08:12:11 +0200 Subject: [PATCH 1847/2126] dpll: zl3073x: notify sibling pin when shared output config changes The P-pin and N-pin of an output share the divisor, clock type, eSync and phase compensation registers (outside N-divided mode). Changing them through one pin changes the other pin too, but only the requested pin gets a change notification. Add zl3073x_dpll_output_pin_sibling_get() and notify the sibling from frequency_set(), esync_set() and phase_adjust_set(). The notification re-enters the pin get callbacks, so it has to be sent after zldpll->lock is released and the callbacks switch from guard(mutex) to explicit unlocking. To always find a registered sibling, add a pin to zldpll->pins before dpll_pin_register() and remove it only after dpll_pin_unregister(), both under zldpll->lock. A pin that is on the list but not registered gets no netlink notification, as dpll_pin_event_send() skips such pins, and the only in-tree DPLL notifier ignores DPLL_PIN_CHANGED. Found by code inspection, not triggered at runtime. Fixes: 634ca2cb06d2 ("dpll: zl3073x: Add support to get/set esync on pins") Fixes: ce26d7ca50a5 ("dpll: zl3073x: Add support to get/set frequency on pins") Fixes: 6287262f761e ("dpll: zl3073x: Add support to adjust phase") Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera Link: https://patch.msgid.link/20261011061211.448373-6-ivecera@redhat.com Signed-off-by: Jakub Kicinski --- drivers/dpll/zl3073x/dpll.c | 155 +++++++++++++++++++++++++++++++----- 1 file changed, 135 insertions(+), 20 deletions(-) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index 6d9a6d21d30b..1cdadb8e46fb 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -123,6 +123,8 @@ zl3073x_dpll_pin_get_by_ref(struct zl3073x_dpll *zldpll, u8 ref_id) { struct zl3073x_dpll_pin *pin; + lockdep_assert_held(&zldpll->lock); + list_for_each_entry(pin, &zldpll->pins, list) { if (zl3073x_dpll_is_input_pin(pin) && zl3073x_input_pin_ref_get(pin->id) == ref_id) @@ -132,11 +134,42 @@ zl3073x_dpll_pin_get_by_ref(struct zl3073x_dpll *zldpll, u8 ref_id) return NULL; } +/** + * zl3073x_dpll_output_pin_sibling_get - get the other pin of an output pair + * @pin: output pin whose sibling is sought + * + * Output pin ids are allocated in P/N pairs (P even, N odd) that share a + * single HW output. Looks up the other pin of the pair in the pin list + * of this DPLL. A pin is on the list from just before its registration + * until just after its unregistration, so a registered sibling is always + * found, but the returned pin may also be one that is not (yet or any + * longer) registered. + * + * Return: pointer to sibling pin, or NULL if it is not on the pin list + */ +static struct zl3073x_dpll_pin * +zl3073x_dpll_output_pin_sibling_get(struct zl3073x_dpll_pin *pin) +{ + struct zl3073x_dpll_pin *sibling; + + lockdep_assert_held(&pin->dpll->lock); + + list_for_each_entry(sibling, &pin->dpll->pins, list) { + if (!zl3073x_dpll_is_input_pin(sibling) && + sibling->id == (pin->id ^ 1)) + return sibling; + } + + return NULL; +} + static struct zl3073x_dpll_pin * zl3073x_dpll_nco_pin_get(struct zl3073x_dpll *zldpll) { struct zl3073x_dpll_pin *pin; + lockdep_assert_held(&zldpll->lock); + list_for_each_entry(pin, &zldpll->pins, list) { if (zl3073x_dpll_is_nco_pin(pin)) return pin; @@ -909,12 +942,14 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, struct zl3073x_dpll *zldpll = dpll_priv; struct zl3073x_dev *zldev = zldpll->dev; struct zl3073x_dpll_pin *pin = pin_priv; + struct zl3073x_dpll_pin *sibling = NULL; const struct zl3073x_synth *synth; struct zl3073x_out out; u32 synth_freq; u8 out_id; + int rc; - guard(mutex)(&zldpll->lock); + mutex_lock(&zldpll->lock); out_id = zl3073x_output_pin_out_get(pin->id); out = *zl3073x_out_state_get(zldev, out_id); @@ -923,12 +958,14 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, * for N-division is also used for the esync divider so both cannot * be used. */ - if (zl3073x_out_is_ndiv(&out)) - return -EOPNOTSUPP; + if (zl3073x_out_is_ndiv(&out)) { + rc = -EOPNOTSUPP; + goto unlock; + } if (!freq) { zl3073x_out_esync_disable(&out); - return zl3073x_out_state_set(zldev, out_id, &out); + goto commit; } /* Get attached synth frequency */ @@ -937,9 +974,24 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, /* Enable 1PPS eSync for this pin frequency */ zl3073x_out_esync_enable(&out, synth_freq / out.div); - +commit: /* Commit output configuration */ - return zl3073x_out_state_set(zldev, out_id, &out); + rc = zl3073x_out_state_set(zldev, out_id, &out); + if (rc) + goto unlock; + + /* The clock type, esync period and esync width are all shared by + * both pins of the output pair, so the sibling pin's esync + * configuration changes too and userspace has to be notified. + */ + sibling = zl3073x_dpll_output_pin_sibling_get(pin); +unlock: + mutex_unlock(&zldpll->lock); + + if (!rc && sibling) + __dpll_pin_change_ntf(sibling->dpll_pin); + + return rc; } static int @@ -969,13 +1021,15 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, struct zl3073x_dpll *zldpll = dpll_priv; struct zl3073x_dev *zldev = zldpll->dev; struct zl3073x_dpll_pin *pin = pin_priv; + struct zl3073x_dpll_pin *sibling = NULL; const struct zl3073x_synth *synth; u32 new_div, synth_freq; struct zl3073x_out out; u64 n_period, rem; u8 out_id; + int rc; - guard(mutex)(&zldpll->lock); + mutex_lock(&zldpll->lock); out_id = zl3073x_output_pin_out_get(pin->id); out = *zl3073x_out_state_get(zldev, out_id); @@ -988,7 +1042,8 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, /* Check signal format */ if (!zl3073x_out_is_ndiv(&out)) { /* For non N-divided signal formats the frequency is computed - * as division of synth frequency and output divisor. + * as division of synth frequency and output divisor, which + * is shared by both pins of the output pair. */ out.div = new_div; @@ -1013,7 +1068,16 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, } /* Commit output configuration */ - return zl3073x_out_state_set(zldev, out_id, &out); + rc = zl3073x_out_state_set(zldev, out_id, &out); + if (rc) + goto unlock; + + /* The other pin's frequency changed too - it has to be + * notified about the change. + */ + sibling = zl3073x_dpll_output_pin_sibling_get(pin); + + goto unlock; } if (zl3073x_dpll_is_p_pin(pin)) { @@ -1039,19 +1103,22 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, NL_SET_ERR_MSG_FMT(extack, "OUT%uN freq must be at most half of OUT%uP freq", out_id, out_id); - return -EINVAL; + rc = -EINVAL; + goto unlock; } if (n_period > U32_MAX) { NL_SET_ERR_MSG_FMT(extack, "OUT%uN freq is too low for OUT%uP freq", out_id, out_id); - return -EINVAL; + rc = -EINVAL; + goto unlock; } if (rem != 0) { NL_SET_ERR_MSG_FMT(extack, "OUT%uN freq must divide OUT%uP freq", out_id, out_id); - return -EINVAL; + rc = -EINVAL; + goto unlock; } out.esync_n_period = n_period; @@ -1059,7 +1126,14 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, out.esync_n_width = out.esync_n_period; /* Commit output configuration */ - return zl3073x_out_state_set(zldev, out_id, &out); + rc = zl3073x_out_state_set(zldev, out_id, &out); +unlock: + mutex_unlock(&zldpll->lock); + + if (!rc && sibling) + __dpll_pin_change_ntf(sibling->dpll_pin); + + return rc; } static int @@ -1098,10 +1172,12 @@ zl3073x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *dpll_pin, struct zl3073x_dpll *zldpll = dpll_priv; struct zl3073x_dev *zldev = zldpll->dev; struct zl3073x_dpll_pin *pin = pin_priv; + struct zl3073x_dpll_pin *sibling = NULL; struct zl3073x_out out; u8 out_id; + int rc; - guard(mutex)(&zldpll->lock); + mutex_lock(&zldpll->lock); out_id = zl3073x_output_pin_out_get(pin->id); out = *zl3073x_out_state_get(zldev, out_id); @@ -1110,7 +1186,21 @@ zl3073x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *dpll_pin, out.phase_comp = phase_adjust / pin->phase_gran; /* Update output configuration from mailbox */ - return zl3073x_out_state_set(zldev, out_id, &out); + rc = zl3073x_out_state_set(zldev, out_id, &out); + if (rc) + goto unlock; + + /* The phase compensation register is shared by both pins of the + * output pair, so the sibling pin's phase adjustment changes too. + */ + sibling = zl3073x_dpll_output_pin_sibling_get(pin); +unlock: + mutex_unlock(&zldpll->lock); + + if (!rc && sibling) + __dpll_pin_change_ntf(sibling->dpll_pin); + + return rc; } static int @@ -1734,6 +1824,13 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) else ops = &zl3073x_dpll_output_pin_ops; + /* Add the pin to the list before registering it with the DPLL core so + * that it is findable as a sibling as soon as the core publishes it. + */ + mutex_lock(&zldpll->lock); + list_add(&pin->list, &zldpll->pins); + mutex_unlock(&zldpll->lock); + /* Register the pin */ rc = dpll_pin_register(zldpll->dpll_dev, pin->dpll_pin, ops, pin); if (rc) @@ -1745,6 +1842,9 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) return 0; err_register: + mutex_lock(&zldpll->lock); + list_del(&pin->list); + mutex_unlock(&zldpll->lock); dpll_pin_put(pin->dpll_pin, &pin->tracker); err_pin_get: pin->dpll_pin = NULL; @@ -1779,6 +1879,13 @@ zl3073x_dpll_pin_unregister(struct zl3073x_dpll_pin *pin) /* Unregister the pin */ dpll_pin_unregister(zldpll->dpll_dev, pin->dpll_pin, ops, pin); + /* Remove the pin from the list only after it has been unregistered so + * that a still-registered pin is always findable as a sibling. + */ + mutex_lock(&zldpll->lock); + list_del(&pin->list); + mutex_unlock(&zldpll->lock); + dpll_pin_put(pin->dpll_pin, &pin->tracker); pin->dpll_pin = NULL; @@ -1798,9 +1905,11 @@ zl3073x_dpll_pins_unregister(struct zl3073x_dpll *zldpll) { struct zl3073x_dpll_pin *pin, *next; + /* Unregister each pin before removing it from the list so that a + * still-registered pin is always findable as a sibling. + */ list_for_each_entry_safe(pin, next, &zldpll->pins, list) { zl3073x_dpll_pin_unregister(pin); - list_del(&pin->list); zl3073x_dpll_pin_free(pin); } } @@ -1913,16 +2022,24 @@ zl3073x_dpll_nco_pin_register(struct zl3073x_dpll *zldpll) goto err_pin_get; } + /* Add the pin to the list before registering it with the DPLL core so + * that a registered pin is always on the list. + */ + mutex_lock(&zldpll->lock); + list_add(&pin->list, &zldpll->pins); + mutex_unlock(&zldpll->lock); + rc = dpll_pin_register(zldpll->dpll_dev, pin->dpll_pin, &zl3073x_dpll_nco_pin_ops, pin); if (rc) goto err_register; - list_add(&pin->list, &zldpll->pins); - return 0; err_register: + mutex_lock(&zldpll->lock); + list_del(&pin->list); + mutex_unlock(&zldpll->lock); dpll_pin_put(pin->dpll_pin, &pin->tracker); err_pin_get: pin->dpll_pin = NULL; @@ -1974,8 +2091,6 @@ zl3073x_dpll_pins_register(struct zl3073x_dpll *zldpll) zl3073x_dpll_pin_free(pin); goto error; } - - list_add(&pin->list, &zldpll->pins); } /* Register NCO virtual input pin */ From 86a30c4348497bcddcf2796258955bbaaf58c9a3 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Fri, 9 Oct 2026 02:00:56 +0200 Subject: [PATCH 1848/2126] dpaa2-ptp: fix support for PTP_EXTTS_REQUEST2 ioctl Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP. On an LX2160A board, linuxptp ts2phc arms the external timestamp channel of the 1588 timer with PTP_EXTTS_REQUEST2, gets -EOPNOTSUPP and exits, so the PHC cannot be disciplined from an external 1PPS. ptp_qoriq_init() programs TMR_CTRL with ETEP1 and ETEP2 cleared, so the timer timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge. This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp. Fixes: 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") Reviewed-by: Jacob Keller Reviewed-by: Kory Maincent Signed-off-by: Vincent Jardin Link: https://patch.msgid.link/20261009-for-upstream-qoriq-ptp-extts-flags-v2-1-0f4eeff2295d@free.fr Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c index 4497e3c0456d..ac2b873dcf8e 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c @@ -78,6 +78,7 @@ static const struct ptp_clock_info dpaa2_ptp_caps = { .n_per_out = 3, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime, From 8e96c4d393168661704d850bcf818e46efb8ef24 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Fri, 9 Oct 2026 02:00:57 +0200 Subject: [PATCH 1849/2126] net: enetc: fix support for PTP_EXTTS_REQUEST2 ioctl Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP. The ENETC timer is the QorIQ 1588 timer, set up by ptp_qoriq_init(), which programs TMR_CTRL with ETEP1 and ETEP2 cleared, so it timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge. This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp. Fixes: 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") Reviewed-by: Jacob Keller Reviewed-by: Kory Maincent Signed-off-by: Vincent Jardin Reviewed-by: Wei Fang Link: https://patch.msgid.link/20261009-for-upstream-qoriq-ptp-extts-flags-v2-2-0f4eeff2295d@free.fr Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/enetc/enetc_ptp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ptp.c b/drivers/net/ethernet/freescale/enetc/enetc_ptp.c index 162cbc801730..5ffee882d624 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_ptp.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_ptp.c @@ -16,6 +16,7 @@ static struct ptp_clock_info enetc_ptp_caps = { .n_per_out = 0, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime, From d347ab5cf809365e7b3749dc91d77e89e4b7ec3f Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Fri, 9 Oct 2026 02:00:58 +0200 Subject: [PATCH 1850/2126] ptp: qoriq: fix support for PTP_EXTTS_REQUEST2 ioctl Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP, since the core always adds PTP_STRICT_FLAGS to it. ptp_qoriq_init() programs TMR_CTRL with ETEP1 and ETEP2 cleared, so the timer timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge. This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp. Fixes: 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") Reviewed-by: Jacob Keller Reviewed-by: Kory Maincent Signed-off-by: Vincent Jardin Reviewed-by: Wei Fang Link: https://patch.msgid.link/20261009-for-upstream-qoriq-ptp-extts-flags-v2-3-0f4eeff2295d@free.fr Signed-off-by: Jakub Kicinski --- drivers/ptp/ptp_qoriq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ptp/ptp_qoriq.c b/drivers/ptp/ptp_qoriq.c index 76272e5ac5b8..bcd29104effe 100644 --- a/drivers/ptp/ptp_qoriq.c +++ b/drivers/ptp/ptp_qoriq.c @@ -355,6 +355,7 @@ static const struct ptp_clock_info ptp_qoriq_caps = { .n_per_out = 0, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime, From 29afe67082b2d33ab2e90c56c337235d725f023f Mon Sep 17 00:00:00 2001 From: Quanye Yang Date: Tue, 13 Oct 2026 16:29:19 +0200 Subject: [PATCH 1851/2126] mptcp: reset msk state on early connect failure mptcp_connect() can fall back before the subflow SYN is sent, for example when the netns is in an MPTCP blackhole, token allocation fails, or MD5SIG is in use. If the subsequent subflow connect() fails immediately (EAFNOSUPPORT, ENETUNREACH, ...), __inet_stream_connect() returns while the socket is still SS_UNCONNECTED and never calls ->disconnect(). This was reported by Clashiko [1]. The error path only dropped the token and moved the msk back to TCP_CLOSE. MPTCP_FALLBACK_DONE, allow_subflows and request_mptcp were left as after early fallback, so a later connect() on the same fd stayed TCP-only. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/633 [1] Fixes: 0235d075a592 ("mptcp: mark as fallback even early ones") Cc: stable@vger.kernel.org Signed-off-by: Quanye Yang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-mptcp-misc-fixes-7-3-rc8-v1-1-932c9b182fc7@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/protocol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e89a69ab927c..e6f73a5ee630 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4212,9 +4212,16 @@ out: * subflow_finish_connect() */ if (unlikely(err)) { - /* avoid leaving a dangling token in an unconnected socket */ mptcp_token_destroy(msk); mptcp_set_state(sk, TCP_CLOSE); + + spin_lock_bh(&msk->fallback_lock); + msk->allow_subflows = true; + msk->allow_infinite_fallback = true; + clear_bit(MPTCP_FALLBACK_DONE, &msk->flags); + spin_unlock_bh(&msk->fallback_lock); + + mptcp_subflow_ctx_reset(mptcp_subflow_ctx(ssk)); return err; } From 7538fa33bb2f66b8b809ff39d58308be48e197a0 Mon Sep 17 00:00:00 2001 From: Paolo Abeni Date: Tue, 13 Oct 2026 16:29:20 +0200 Subject: [PATCH 1852/2126] mptcp: fix subflow bitfield misuse The subflow status bitfield is protected by the subflow socket lock, with one notable exception: the `close_event_done` bit is actually under the msk socket lock protection. As reported by Clashiko [1], flipping the latter bit may corrupt other entries in the same bitfield. Move the `close_event_done` outside the bitfield, in a 32bit hole. Link: https://lore.kernel.org/178959153492.22033.1944011998010756543@kernel.org Fixes: d82809b6c5f2 ("mptcp: avoid duplicated SUB_CLOSED events") Cc: stable@vger.kernel.org Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-mptcp-misc-fixes-7-3-rc8-v1-2-932c9b182fc7@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/protocol.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0384d6a023f9..c006110b1c56 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -583,14 +583,16 @@ struct mptcp_subflow_context { closing : 1, /* must not pass rx data to msk anymore */ valid_csum_seen : 1, /* at least one csum validated */ is_mptfo : 1, /* subflow is doing TFO */ - close_event_done : 1, /* has done the post-closed part */ mpc_drop : 1, /* the MPC option has been dropped in a rtx */ resetting : 1, /* subflow is resetting */ - __unused : 8; + __unused : 9; bool data_avail; bool scheduled; bool pm_listener; /* a listener managed by the kernel PM? */ bool fully_established; /* path validated */ + bool close_event_done; /* has done the post-closed part, + * protected by msk socket lock + */ u32 lent_mem_frag; u32 remote_nonce; u64 thmac; From c9c90cf437a9e6597611b6d3aad6e255fad22867 Mon Sep 17 00:00:00 2001 From: Ruide Cao Date: Tue, 13 Oct 2026 16:29:21 +0200 Subject: [PATCH 1853/2126] mptcp: hold MP_JOIN msk ref when cloning reqsk TCP request migration clones pending request sockets with inet_reqsk_clone(). For MPTCP MP_JOIN requests this byte-copies subflow_req->msk, but the clone does not own a reference. The original and cloned requests can consequently drop the same msk reference, leaving one request with a dangling pointer. This manifests as a KASAN slab-use-after-free in subflow_req_destructor(): BUG: KASAN: slab-use-after-free in subflow_req_destructor (net/mptcp/subflow.c:45) Write of size 4 at addr ff1100010e008d40 by task swapper/0/0 CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.2.0-rc5-00353-gc27e36054537 #10 PREEMPT(full) Call Trace: subflow_req_destructor (net/mptcp/subflow.c:45) subflow_v4_req_destructor (net/mptcp/subflow.c:694) __reqsk_free (net/ipv4/inet_connection_sock.c:906) reqsk_timer_handler (include/net/request_sock.h:137 net/ipv4/inet_connection_sock.c:1147) Allocated by task 10014: sk_prot_alloc (net/core/sock.c:2246) sk_clone (net/core/sock.c:2488) mptcp_sk_clone_init (include/net/sock.h:1848 net/mptcp/protocol.c:3564) subflow_syn_recv_sock (net/mptcp/subflow.c:883) tcp_check_req (net/ipv4/tcp_minisocks.c:934) Freed by task 0: slab_free_after_rcu_debug (include/linux/kasan.h:235 mm/slub.c:2677 mm/slub.c:6439) rcu_core (kernel/rcu/tree.c:2645 kernel/rcu/tree.c:2897) Last potentially related work creation: kmem_cache_free (mm/slub.c:2638 mm/slub.c:6377 mm/slub.c:6504) __sk_destruct (net/core/sock.c:2289 net/core/sock.c:2391) sk_destruct (net/core/sock.c:2419) __sk_free (net/core/sock.c:2430) sk_free (net/core/sock.c:2441) mptcp_close (include/net/sock.h:2020 net/mptcp/protocol.c:3399) inet_release (net/ipv4/af_inet.c:442) The buggy address belongs to the cache MPTCP of size 2968 The buggy address is 128 bytes inside a freed 2968-byte region A non-NULL subflow_req->msk means that the request owns one reference. The third ACK can concurrently transfer the original request reference to the child and release it, so taking an unconditional hold on the copied pointer is unsafe. MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all current inet_reqsk_clone() callers run in an RCU read-side critical section. Document and lockdep-check that calling-context requirement. Read the pointer from the original request and acquire a reference only if it is still live. Use refcount_inc_not_zero_acquire() so the subsequent ownership validation cannot be reordered before the try-get, then re-read the original request to verify that it still owns the same msk. If either check fails, clear the clone pointer; otherwise its normal destructor balances the new reference. Mark the ownership-transfer store with WRITE_ONCE() to match the lockless reads. The following patch completes the clone fixup for MP_CAPABLE token ownership. Both patches carry the same Fixes tag and are required for stable backports. Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.") Cc: stable@vger.kernel.org Reported-by: Kyle Zeng Reported-by: David Lee Reported-by: Vega Closes: https://lore.kernel.org/all/20260804095051.715355-1-david.lee@trailofbits.com/ Signed-off-by: Ruide Cao Signed-off-by: Ren Wei Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-mptcp-misc-fixes-7-3-rc8-v1-3-932c9b182fc7@kernel.org Signed-off-by: Jakub Kicinski --- include/net/mptcp.h | 9 +++++++++ net/ipv4/inet_connection_sock.c | 4 ++++ net/mptcp/subflow.c | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 485d55b66ea6..ad7005b574bb 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -219,6 +219,9 @@ int mptcp_subflow_init_cookie_req(struct request_sock *req, struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener, bool attach_listener); +/* Caller must hold an RCU read-side lock. */ +void mptcp_subflow_reqsk_clone(struct request_sock *req, + struct request_sock *new_req); __be32 mptcp_get_reset_option(const struct sk_buff *skb); @@ -305,6 +308,12 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct reques return NULL; } +/* Caller must hold an RCU read-side lock. */ +static inline void mptcp_subflow_reqsk_clone(struct request_sock *req, + struct request_sock *new_req) +{ +} + static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { return htonl(0u); } static inline void mptcp_active_detect_blackhole(struct sock *sk, bool expired) { } diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 6a30f1138454..c6f8011200a0 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -961,6 +962,9 @@ static struct request_sock *inet_reqsk_clone(struct request_sock *req, rcu_assign_pointer(tcp_sk(nreq->sk)->fastopen_rsk, nreq); } + if (rsk_is_mptcp(req)) + mptcp_subflow_reqsk_clone(req, nreq); + return nreq; } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index f0a6725d2c37..3139a9ab2853 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -47,6 +47,39 @@ static void subflow_req_destructor(struct request_sock *req) mptcp_token_destroy_request(req); } +void mptcp_subflow_reqsk_clone(struct request_sock *req, + struct request_sock *new_req) +{ + struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req); + struct mptcp_subflow_request_sock *new_subflow_req; + struct mptcp_sock *msk; + + new_subflow_req = mptcp_subflow_rsk(new_req); + RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), + "MPTCP reqsk clone called without RCU"); + + /* A non-NULL ->msk means the request owns one reference. The clone + * copied only the pointer, while the original request can concurrently + * transfer its reference to the child. Acquire a reference for the + * clone, then verify that the original request still owns the same msk. + * MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all clone callers run in + * an RCU read-side critical section, keeping the memory stable here. + */ + msk = READ_ONCE(subflow_req->msk); + if (msk) { + struct sock *sk = (struct sock *)msk; + + if (!refcount_inc_not_zero_acquire(&sk->sk_refcnt)) { + msk = NULL; + } else if (READ_ONCE(subflow_req->msk) != msk) { + sock_put(sk); + msk = NULL; + } + } + + new_subflow_req->msk = msk; +} + static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2, void *hmac) { @@ -927,7 +960,7 @@ create_child: } /* move the msk reference ownership to the subflow */ - subflow_req->msk = NULL; + WRITE_ONCE(subflow_req->msk, NULL); ctx->conn = (struct sock *)owner; if (subflow_use_different_sport(owner, sk)) { From 2093bc7fa50056fef8620d2b82bcb2e9a0a5575d Mon Sep 17 00:00:00 2001 From: Ruide Cao Date: Tue, 13 Oct 2026 16:29:22 +0200 Subject: [PATCH 1854/2126] mptcp: fix MP_CAPABLE token migration when cloning reqsk TCP request migration clones pending request sockets with inet_reqsk_clone(). For MPTCP MP_CAPABLE requests this byte-copies the token_node hlist state into the clone even though the token table still names the original request, and the following warning can be seen: WARNING: net/mptcp/token.c:364 at mptcp_token_destroy_request+0x2b0/0x330, CPU#2: swapper/2/0 CPU: 2 UID: 0 PID: 0 Comm: swapper/2 Not tainted 7.2.0-rc5-00353-gc27e36054537 #10 PREEMPT(full) RIP: 0010:mptcp_token_destroy_request (net/mptcp/token.c:364 (discriminator 1)) Call Trace: subflow_v4_req_destructor (net/mptcp/subflow.c:694) __reqsk_free (net/ipv4/inet_connection_sock.c:906) reqsk_timer_handler (include/net/request_sock.h:137 net/ipv4/inet_connection_sock.c:1147) call_timer_fn (kernel/time/timer.c:1748) Move token request ownership from the original request to the clone under the token bucket lock. Make mptcp_token_accept() and mptcp_token_destroy_request() re-check token_node under the same lock and treat an already moved or removed request as a normal race instead of warning. This also keeps token bucket chain_len accounting balanced. If a passive MP_CAPABLE socket cannot claim the token, destroy the provisional MPTCP socket and let the subflow fall back rather than installing a socket with mismatched token ownership. Mark that path as a passive handshake fallback so MPCapableFallbackACK records the downgrade. If the speculative clone later loses the inet_ehash_insert() ownership arbitration, the original request may find that its token was already moved and fall back to plain TCP. The clone destructor then releases the token reservation and keeps chain_len balanced. This trades an exceptionally rare fallback for eliminating the warning and persistent accounting drift. Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.") Cc: stable@vger.kernel.org Reported-by: Vega Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/86e2514b533bf4d55d4aa2fdbf1404022e8c9430.1776149210.git.caoruide123%40gmail.com Signed-off-by: Ruide Cao Signed-off-by: Ren Wei Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-mptcp-misc-fixes-7-3-rc8-v1-4-932c9b182fc7@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/protocol.c | 31 +++++++++++++++---- net/mptcp/protocol.h | 4 ++- net/mptcp/subflow.c | 6 +++- net/mptcp/token.c | 68 +++++++++++++++++++++++++++++++++++++----- net/mptcp/token_test.c | 4 +-- 5 files changed, 97 insertions(+), 16 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e6f73a5ee630..05c38564e8fd 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3706,6 +3706,24 @@ static void mptcp_copy_ip_options(struct sock *newsk, const struct sock *sk) rcu_read_unlock(); } +static void mptcp_sk_clone_destroy(struct sock *nsk) +{ + struct mptcp_sock *msk = mptcp_sk(nsk); + + mptcp_release_sched(msk); + mptcp_set_state(nsk, TCP_CLOSE); + /* inet_csk_prepare_forced_close() clears TCP sock_ops state via + * tcp_sk(), but nsk is an MPTCP master socket; keep the inet-level + * destroy preparation here. + */ + bh_unlock_sock(nsk); + sock_put(nsk); + sock_set_flag(nsk, SOCK_DEAD); + tcp_orphan_count_inc(); + inet_sk(nsk)->inet_num = 0; + inet_csk_destroy_sock(nsk); +} + struct sock *mptcp_sk_clone_init(const struct sock *sk, const struct mptcp_options_received *mp_opt, struct sock *ssk, @@ -3765,11 +3783,6 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, list_add(&subflow->node, &msk->conn_list); sock_hold(ssk); - /* new mpc subflow takes ownership of the newly - * created mptcp socket - */ - mptcp_token_accept(subflow_req, msk); - /* set msk addresses early to ensure mptcp_pm_get_local_id() * uses the correct data */ @@ -3778,6 +3791,14 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, mptcp_rcv_space_init(msk, ssk); msk->rcvq_space.time = mptcp_stamp(); + if (!mptcp_token_accept(subflow_req, msk)) { + list_del_init(&subflow->node); + WRITE_ONCE(msk->first, NULL); + sock_put(ssk); + mptcp_sk_clone_destroy(nsk); + return NULL; + } + if (mp_opt->suboptions & OPTION_MPTCP_MPC_ACK) __mptcp_subflow_fully_established(msk, subflow, mp_opt); bh_unlock_sock(nsk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index c006110b1c56..4ed598febbf0 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1083,9 +1083,11 @@ static inline void mptcp_token_init_request(struct request_sock *req) } int mptcp_token_new_request(struct request_sock *req); +void mptcp_token_move_request(struct request_sock *req, + struct request_sock *new_req); void mptcp_token_destroy_request(struct request_sock *req); int mptcp_token_new_connect(struct sock *ssk); -void mptcp_token_accept(struct mptcp_subflow_request_sock *r, +bool mptcp_token_accept(struct mptcp_subflow_request_sock *r, struct mptcp_sock *msk); bool mptcp_token_exists(u32 token); struct mptcp_sock *mptcp_token_get_sock(struct net *net, u32 token); diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 3139a9ab2853..2c72cb50fbf3 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -78,6 +78,8 @@ void mptcp_subflow_reqsk_clone(struct request_sock *req, } new_subflow_req->msk = msk; + + mptcp_token_move_request(req, new_req); } static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2, @@ -922,8 +924,10 @@ create_child: if (ctx->mp_capable) { ctx->conn = mptcp_sk_clone_init(listener->conn, &mp_opt, child, req); - if (!ctx->conn) + if (!ctx->conn) { + fallback = true; goto fallback; + } ctx->subflow_id = 1; owner = mptcp_sk(ctx->conn); diff --git a/net/mptcp/token.c b/net/mptcp/token.c index f1a50f367add..e0f2823f92ef 100644 --- a/net/mptcp/token.c +++ b/net/mptcp/token.c @@ -180,6 +180,43 @@ again: return 0; } +/** + * mptcp_token_move_request - move request token ownership to a clone + * @req: original request socket + * @new_req: cloned request socket + * + * Move the token hash entry from the original request to its clone. + */ +void mptcp_token_move_request(struct request_sock *req, + struct request_sock *new_req) +{ + struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req); + struct mptcp_subflow_request_sock *new_subflow_req; + struct mptcp_subflow_request_sock *pos; + struct token_bucket *bucket; + + new_subflow_req = mptcp_subflow_rsk(new_req); + + if (hlist_nulls_unhashed_lockless(&subflow_req->token_node)) { + mptcp_token_init_request(new_req); + return; + } + + bucket = token_bucket(subflow_req->token); + spin_lock_bh(&bucket->lock); + if (hlist_nulls_unhashed(&subflow_req->token_node)) { + mptcp_token_init_request(new_req); + } else { + pos = __token_lookup_req(bucket, subflow_req->token); + if (pos == subflow_req) + hlist_nulls_replace_init_rcu(&subflow_req->token_node, + &new_subflow_req->token_node); + else + mptcp_token_init_request(new_req); + } + spin_unlock_bh(&bucket->lock); +} + /** * mptcp_token_accept - replace a req sk with full sock in token hash * @req: the request socket to be removed @@ -187,24 +224,36 @@ again: * * Called when a SYN packet creates a new logical connection, i.e. * is not a join request. + * + * Return: true on success. */ -void mptcp_token_accept(struct mptcp_subflow_request_sock *req, +bool mptcp_token_accept(struct mptcp_subflow_request_sock *req, struct mptcp_sock *msk) { struct mptcp_subflow_request_sock *pos; struct sock *sk = (struct sock *)msk; struct token_bucket *bucket; + bool ret = false; - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); bucket = token_bucket(req->token); spin_lock_bh(&bucket->lock); + if (hlist_nulls_unhashed(&req->token_node)) + goto unlock; - /* pedantic lookup check for the moved token */ pos = __token_lookup_req(bucket, req->token); - if (!WARN_ON_ONCE(pos != req)) - hlist_nulls_del_init_rcu(&req->token_node); + if (pos != req) + goto unlock; + + hlist_nulls_del_init_rcu(&req->token_node); __sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain); + ret = true; + +unlock: spin_unlock_bh(&bucket->lock); + if (ret) + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); + + return ret; } bool mptcp_token_exists(u32 token) @@ -355,16 +404,21 @@ void mptcp_token_destroy_request(struct request_sock *req) struct mptcp_subflow_request_sock *pos; struct token_bucket *bucket; - if (hlist_nulls_unhashed(&subflow_req->token_node)) + if (hlist_nulls_unhashed_lockless(&subflow_req->token_node)) return; bucket = token_bucket(subflow_req->token); spin_lock_bh(&bucket->lock); + if (hlist_nulls_unhashed(&subflow_req->token_node)) + goto unlock; + pos = __token_lookup_req(bucket, subflow_req->token); - if (!WARN_ON_ONCE(pos != subflow_req)) { + if (pos == subflow_req) { hlist_nulls_del_init_rcu(&pos->token_node); bucket->chain_len--; } + +unlock: spin_unlock_bh(&bucket->lock); } diff --git a/net/mptcp/token_test.c b/net/mptcp/token_test.c index 4fc39fa2e262..be9acce8a567 100644 --- a/net/mptcp/token_test.c +++ b/net/mptcp/token_test.c @@ -99,7 +99,7 @@ static void mptcp_token_test_accept(struct kunit *test) KUNIT_ASSERT_EQ(test, 0, mptcp_token_new_request((struct request_sock *)req)); msk->token = req->token; - mptcp_token_accept(req, msk); + KUNIT_EXPECT_TRUE(test, mptcp_token_accept(req, msk)); KUNIT_EXPECT_PTR_EQ(test, msk, mptcp_token_get_sock(&init_net, msk->token)); /* this is now a no-op */ @@ -122,7 +122,7 @@ static void mptcp_token_test_destroyed(struct kunit *test) KUNIT_ASSERT_EQ(test, 0, mptcp_token_new_request((struct request_sock *)req)); msk->token = req->token; - mptcp_token_accept(req, msk); + KUNIT_EXPECT_TRUE(test, mptcp_token_accept(req, msk)); /* simulate race on removal */ refcount_set(&sk->sk_refcnt, 0); From 1240de9e51201eaf7057f63b9ce5db15380cbbbe Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Sun, 11 Oct 2026 18:20:22 +0800 Subject: [PATCH 1855/2126] bareudp: Enable BIG TCP packets Commit f3d0f753f066 ("vxlan: Enable BIG TCP packets") and commit 03ebe91b0f61 ("geneve: Enable BIG TCP packets") allowed BIG TCP on vxlan and geneve, after the preceding patches of that series made the common UDP tunnel transmit path handle GSO packets larger than 64KB. bareudp transmits through the same helpers, udp_tunnel_handle_offloads() followed by udp_tunnel_xmit_skb() or udp_tunnel6_xmit_skb(), and does not fill in any length field itself. Bump tso_max_size up to GSO_MAX_SIZE so that the admin can use BIG TCP with bareudp too. The default gso_max_size and gso_ipv4_max_size stay at 64KB, so nothing changes unless they are raised explicitly. iperf3 TCP over bareudp (ethertype ipv4, IPv4 outer) between two netns connected by veth, MTU 1600 on veth, 3 runs of 20 seconds each. This was measured in a QEMU TCG guest, so only the relative numbers are meaningful: gso_max_size/gso_ipv4_max_size 65536: 4380.6, 4404.2, 4354.5 Mbit/s, average 4379.8 Mbit/s gso_max_size/gso_ipv4_max_size 196608: 5509.4, 5454.7, 5497.4 Mbit/s, average 5487.2 Mbit/s (+25%) With 196608, about 90k to 100k packets larger than 64KB were transmitted on the bareudp device per run, none with 65536. Without this patch, setting gso_max_size to 196608 is rejected. Acked-by: Alice Mikityanska Signed-off-by: Haishuang Yan Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011102023.1603595-2-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- drivers/net/bareudp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index b9fe54151e1a..48bcb619ef41 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -590,6 +590,7 @@ static void bareudp_setup(struct net_device *dev) dev->max_mtu = IP_MAX_MTU - BAREUDP_BASE_HLEN; dev->type = ARPHRD_NONE; netif_keep_dst(dev); + netif_set_tso_max_size(dev, GSO_MAX_SIZE); dev->priv_flags |= IFF_NO_QUEUE; dev->lltx = true; dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; From 3e3f209961b03835a8f3d3e52ed9ca976997c142 Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Sun, 11 Oct 2026 18:20:23 +0800 Subject: [PATCH 1856/2126] selftests: net: big_tcp_tunnels: Cover bareudp Now that bareudp allows BIG TCP too, run the same checks over bareudp as for vxlan and geneve. bareudp only works in external mode, so attach the tunnel metadata to all packets sent through the device with a tc tunnel_key action on egress. The device uses ethertype ipv4 with multiproto, so that both IPv4 and IPv6 traffic can go through it. Its MTU does not account for the encapsulation, so lower it to leave room for the IPv6 and UDP headers, otherwise the encapsulated packets would be fragmented. Signed-off-by: Haishuang Yan Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011102023.1603595-3-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/net/big_tcp_tunnels.sh | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/net/big_tcp_tunnels.sh b/tools/testing/selftests/net/big_tcp_tunnels.sh index fb43fed824e3..9c1482b842bf 100755 --- a/tools/testing/selftests/net/big_tcp_tunnels.sh +++ b/tools/testing/selftests/net/big_tcp_tunnels.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # SPDX-License-Identifier: GPL-2.0 # -# Testing for IPv4 and IPv6 BIG TCP over VXLAN and GENEVE tunnels. +# Testing for IPv4 and IPv6 BIG TCP over VXLAN, GENEVE and bareudp tunnels. source "$(dirname "$0")/lib.sh" @@ -53,6 +53,24 @@ setup() { DEFAULT_TCP_MIN_TSO_SEGS=$(ip netns exec "$CLIENT_NS" sysctl -n net.ipv4.tcp_min_tso_segs) } +# Create a bareudp device. bareudp only works in external mode: attach the +# tunnel metadata to all packets sent through the device. Its MTU does not +# account for the encapsulation either, so leave room for IPv6 and UDP +# headers. +# $1: netns, $2: device, $3: local underlay address, $4: remote one +setup_bareudp() { + ip -netns "$1" link add "$2" type bareudp \ + dstport 6635 ethertype ipv4 multiproto && + ip -netns "$1" link set "$2" mtu 1452 && + tc -netns "$1" qdisc add dev "$2" clsact && + tc -netns "$1" filter add dev "$2" egress matchall \ + action tunnel_key set src_ip "$3" dst_ip "$4" id 0 ttl 64 && + return 0 + + echo "Failed to set up bareudp device $2" >&2 + return 1 +} + setup_tunnel() { if [ "$2" = 4 ]; then SERVER_IP="$SERVER_IP4" @@ -64,26 +82,40 @@ setup_tunnel() { echo "Setting up ${1^^} over IPv6, veth tx csum offload $3" fi - if [ "$1" = vxlan ]; then + case "$1" in + vxlan) ip -netns "$CLIENT_NS" link add tun0 type vxlan \ id 5001 remote "$SERVER_IP" local "$CLIENT_IP" dev link0 dstport 4789 - else + ;; + geneve) ip -netns "$CLIENT_NS" link add tun0 type geneve \ id 5001 remote "$SERVER_IP" - fi + ;; + bareudp) + setup_bareudp "$CLIENT_NS" tun0 "$CLIENT_IP" "$SERVER_IP" || + return 1 + ;; + esac ip -netns "$CLIENT_NS" link set tun0 up ip -netns "$CLIENT_NS" addr replace "$CLIENT_IP4_TUN/24" dev tun0 ip -netns "$CLIENT_NS" addr replace "$CLIENT_IP6_TUN/112" dev tun0 nodad ip -netns "$CLIENT_NS" link set tun0 \ gso_max_size 196608 gso_ipv4_max_size 196608 \ gro_max_size 196608 gro_ipv4_max_size 196608 - if [ "$1" = vxlan ]; then + case "$1" in + vxlan) ip -netns "$SERVER_NS" link add tun1 type vxlan \ id 5001 remote "$CLIENT_IP" local "$SERVER_IP" dev link1 dstport 4789 - else + ;; + geneve) ip -netns "$SERVER_NS" link add tun1 type geneve \ id 5001 remote "$CLIENT_IP" - fi + ;; + bareudp) + setup_bareudp "$SERVER_NS" tun1 "$SERVER_IP" "$CLIENT_IP" || + return 1 + ;; + esac ip -netns "$SERVER_NS" link set tun1 up ip -netns "$SERVER_NS" addr replace "$SERVER_IP4_TUN/24" dev tun1 ip -netns "$SERVER_NS" addr replace "$SERVER_IP6_TUN/112" dev tun1 nodad @@ -112,7 +144,7 @@ do_test() { local packets_threshold="$PACKETS_THRESHOLD" # When tx csum offload is off, software GSO is performed before passing the - # packet to veth. Check BIG TCP packets inside the VXLAN tunnel to verify + # packet to veth. Check BIG TCP packets inside the tunnel to verify # the software checksum path: if the checksum code is broken, these packets # will be dropped. if [ "$3" = on ]; then @@ -193,6 +225,11 @@ if ! iptables --version &> /dev/null; then exit "$ksft_skip" fi +if ! tc -V &> /dev/null; then + echo "SKIP: Could not run test without tc tool" + exit "$ksft_skip" +fi + if ! ethtool --version &> /dev/null; then echo "SKIP: Could not run test without ethtool tool" exit "$ksft_skip" @@ -206,7 +243,7 @@ fi WORKDIR=$(mktemp -d) trap cleanup EXIT setup -for tunnel in vxlan geneve; do +for tunnel in vxlan geneve bareudp; do for tun_family in 4 6; do for traffic_family in 4 6; do for csum_offload in on off; do From c2124f80be4ceb6ec566ca3b5fc87f84ea9c36e0 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 13 Oct 2026 13:50:22 +0200 Subject: [PATCH 1857/2126] vlan: restore HW VLAN tag insertion with reorder_hdr off MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 447cbe95ebb9 ("vlan: fix skb_under_panic and races when toggling HW VLAN offload") replaced vlan_passthru_header_ops with vlan_header_ops unconditionally to avoid lockless data races when modifying hard_header_len dynamically under RTNL. Prior to that commit, vlan devices on top of a real device capable of HW VLAN TX offload used vlan_passthru_header_ops, which never inserted the 802.1Q header in the frame. Now, with reorder_hdr=off (as done by Home Assistant OS / NetworkManager when flags are omitted over D-Bus), vlan_dev_hard_header() always pushes an in-band 802.1Q header, and vlan_dev_hard_start_xmit() hands the frame to the real device as is, even if the real device supports HW VLAN TX offload. This is a regression for r8169 users (Realtek RTL8168h), who report transmit queue timeouts (NETDEV WATCHDOG): this NIC stalls when asked to offload checksum and/or TSO for frames carrying an in-band tag. Users of r8152 based USB adapters were affected as well. Reverting the blamed commit, disabling TX checksum offload (which also disables TSO), or setting reorder_hdr=on were all reported to work around the issue. Keep vlan_dev_hard_header() as is: the in-band header keeps the frame layout seen at the vlan device egress (taps, tc, netfilter) unchanged, and is relied upon by stacked vlans (Q-in-Q) and by AF_PACKET SOCK_DGRAM users sending ETH_P_8021Q frames. Instead, when vlan_dev_hard_start_xmit() gets a frame carrying an in-band tag with our protocol and the real device can insert tags, move that tag to skb->vlan_tci with __skb_vlan_pop(), so that the real device inserts it. Frames sent on the wire are unchanged, except that frames shorter than 64 bytes with their tag now get up to 4 bytes of extra padding, as with reorder_hdr=on and before 447cbe95ebb9. skb_reset_mac_header() is needed first, because not all ndo_start_xmit() callers set the mac header (e.g. AF_XDP copy mode, which uses __dev_direct_xmit()). vlan_set_encap_proto() may read the two bytes after the vlan header, so frames whose linear part is shorter than VLAN_ETH_HLEN + 2 are sent unchanged, as before. This also makes sure h_vlan_proto, read earlier in the function, was in the linear part. Shared skbs (e.g. from pktgen) are also sent unchanged, since popping the tag modifies the skb, as are skbs already carrying a hwaccel tag (e.g. from generic XDP redirect), whose tag must not be overwritten, skbs carrying XDP metadata, which the pop would have to move, and CHECKSUM_PARTIAL skbs whose csum_start lies within the first VLAN_ETH_HLEN bytes (only possible with bogus offsets, e.g. from AF_XDP tx metadata), which the pop would leave before skb->data. If popping the header fails (memory allocation failure), the frame is dropped and counted in tx_dropped, rather than handing the real device a frame with an in-band tag. tx_bytes is now sampled before the pop, so the vlan device statistics do not change. This also applies to frames provided by the sender with our tag (AF_PACKET SOCK_RAW, or frames redirected from another reorder_hdr=off vlan): the real device now inserts their tag too. Fixes: 447cbe95ebb9 ("vlan: fix skb_under_panic and races when toggling HW VLAN offload") Reported-by: Jan Čermák Closes: https://lore.kernel.org/netdev/CAPa5EdCj3v17tB-SF2JNecq5Q8s1Pranr-XzAFWNpNTBPgPG7w@mail.gmail.com/ Reported-by: Stefan Agner Reported-by: hitchin999 Closes: https://github.com/home-assistant/operating-system/issues/5019 Tested-by: Jan Čermák Signed-off-by: Eric Dumazet Cc: Heiner Kallweit Link: https://patch.msgid.link/20261013115022.1043024-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/8021q/vlan_dev.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index c949c6a82945..2d775b4c84ce 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -110,6 +110,8 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb, unsigned int len; int ret; + len = skb->len; + /* Handle non-VLAN frames if they are sent to us, for example by DHCP. * * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING @@ -121,10 +123,39 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb, vlan_tci = vlan->vlan_id; vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb->priority); __vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci); + } else if (skb_headlen(skb) >= VLAN_ETH_HLEN + sizeof(__be16) && + !skb_shared(skb) && !skb_vlan_tag_present(skb) && + !skb_metadata_len(skb) && + (skb->ip_summed != CHECKSUM_PARTIAL || + skb_checksum_start_offset(skb) >= VLAN_ETH_HLEN) && + vlan_hw_offload_capable(READ_ONCE(vlan->real_dev->features), + vlan->vlan_proto)) { + u16 vlan_tci; + + /* The frame carries its outer tag in-band, either inserted + * by vlan_dev_hard_header() or provided by the sender. + * Let the real device insert it: some NICs can not offload + * checksum or TSO for frames carrying an in-band tag. + * Not all ndo_start_xmit() callers set the mac header. + * vlan_set_encap_proto() may read two bytes after the vlan + * header, so frames with a shorter linear part are sent + * unchanged, as are shared skbs (e.g. from pktgen), skbs + * already carrying a hwaccel tag (e.g. from generic XDP + * redirect), skbs carrying XDP metadata, and CHECKSUM_PARTIAL + * skbs whose checksum starts within the header to be popped. + * On allocation failure, drop the frame rather than handing + * it to the real device with an in-band tag. + */ + skb_reset_mac_header(skb); + if (unlikely(__skb_vlan_pop(skb, &vlan_tci))) { + dev_kfree_skb_any(skb); + this_cpu_inc(vlan->vlan_pcpu_stats->tx_dropped); + return NETDEV_TX_OK; + } + __vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci); } skb->dev = vlan->real_dev; - len = skb->len; if (unlikely(netpoll_tx_running(dev))) return vlan_netpoll_send_skb(vlan, skb); From 58f7989da6e715ce834ac861b7ba6ae9f9bdb098 Mon Sep 17 00:00:00 2001 From: Yuhang Zheng Date: Mon, 12 Oct 2026 09:07:19 +0800 Subject: [PATCH 1858/2126] net/sched: cls_flower: avoid stale mask references after delete Flower releases a mask reference when a filter is removed from the classifier. The filter object can remain alive while dump, walk, or hardware reoffload paths hold a reference to it. Those paths can then dereference f->mask after the mask has already been released. Keep the mask reference until the filter reference count reaches zero. Release the mask synchronously from the final __fl_put() while the caller still holds the tcf_proto reference, and leave the existing RCU work to free the mask. This keeps the mask available to every reader that still holds the filter. The filter is still removed from the classifier indexes immediately. Therefore, a deleted filter can temporarily retain an otherwise empty mask; fl_delete() uses the handle IDR, rather than the mask list, to determine whether the classifier has become empty. Failed mask assignment can leave fnew->mask as an error or borrowed pointer without an owned mask reference. Clear it before the common failure path so the final put cannot release an unowned reference. This fix does not add fields, snapshots, or per-filter memory. Fixes: 92149190067d ("net: sched: flower: set unlocked flag for flower proto ops") Cc: stable@vger.kernel.org Reported-by: Xin Liu Tested-by: Yucheng Lu Signed-off-by: Yuhang Zheng Signed-off-by: Ren Wei Link: https://patch.msgid.link/20261012010720.2248662-2-n05ec@lzu.edu.cn Signed-off-by: Jakub Kicinski --- net/sched/cls_flower.c | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 1cefea571efd..92a7f2d6efc0 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -518,15 +518,22 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f, tcf_exts_hw_stats_update(&f->exts, &cls_flower.stats, cls_flower.use_act_stats); } -static void __fl_put(struct cls_fl_filter *f) +static bool __fl_put(struct tcf_proto *tp, struct cls_fl_filter *f) { + bool last = false; + if (!refcount_dec_and_test(&f->refcnt)) - return; + return false; + + if (f->mask) + last = fl_mask_put(fl_head_dereference(tp), f->mask); if (tcf_exts_get_net(&f->exts)) tcf_queue_work(&f->rwork, fl_destroy_filter_work); else __fl_destroy_filter(f); + + return last; } static struct cls_fl_filter *__fl_get(struct cls_fl_head *head, u32 handle) @@ -572,11 +579,10 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f, list_del_rcu(&f->list); spin_unlock(&tp->lock); - *last = fl_mask_put(head, f->mask); if (!tc_skip_hw(f->flags)) fl_hw_destroy_filter(tp, f, rtnl_held, extack); tcf_unbind_filter(tp, &f->res); - __fl_put(f); + *last = __fl_put(tp, f); return 0; } @@ -617,7 +623,7 @@ static void fl_put(struct tcf_proto *tp, void *arg) { struct cls_fl_filter *f = arg; - __fl_put(f); + __fl_put(tp, f); } static void *fl_get(struct tcf_proto *tp, u32 handle) @@ -2488,12 +2494,14 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, } err = fl_check_assign_mask(head, fnew, fold, mask); - if (err) + if (err) { + fnew->mask = NULL; goto unbind_filter; + } err = fl_ht_insert_unique(fnew, fold, &in_ht); if (err) - goto errout_mask; + goto unbind_filter; if (!tc_skip_hw(fnew->flags)) { err = fl_hw_replace_filter(tp, fnew, rtnl_held, extack); @@ -2547,7 +2555,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, spin_unlock(&tp->lock); - fl_mask_put(head, fold->mask); if (!tc_skip_hw(fold->flags)) fl_hw_destroy_filter(tp, fold, rtnl_held, NULL); tcf_unbind_filter(tp, &fold->res); @@ -2555,7 +2562,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, * after this. */ refcount_dec(&fold->refcnt); - __fl_put(fold); + __fl_put(tp, fold); } else { idr_replace(&head->handle_idr, fnew, fnew->handle); @@ -2580,9 +2587,6 @@ errout_hw: if (in_ht) rhashtable_remove_fast(&fnew->mask->ht, &fnew->ht_node, fnew->mask->filter_ht_params); -errout_mask: - fl_mask_put(head, fnew->mask); - unbind_filter: if (bound_to_filter) { if (flags & TCA_ACT_FLAGS_NO_RTNL) @@ -2598,14 +2602,14 @@ errout_idr: idr_remove(&head->handle_idr, fnew->handle); spin_unlock(&tp->lock); } - __fl_put(fnew); + __fl_put(tp, fnew); errout_tb: kfree(tb); errout_mask_alloc: tcf_queue_work(&mask->rwork, fl_uninit_mask_free_work); errout_fold: if (fold) - __fl_put(fold); + __fl_put(tp, fold); return err; } @@ -2618,8 +2622,10 @@ static int fl_delete(struct tcf_proto *tp, void *arg, bool *last, int err = 0; err = __fl_delete(tp, f, &last_on_mask, rtnl_held, extack); - *last = list_empty(&head->masks); - __fl_put(f); + spin_lock(&tp->lock); + *last = idr_is_empty(&head->handle_idr); + spin_unlock(&tp->lock); + __fl_put(tp, f); return err; } @@ -2641,12 +2647,12 @@ static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg, rcu_read_unlock(); if (arg->fn(tp, f, arg) < 0) { - __fl_put(f); + __fl_put(tp, f); arg->stop = 1; rcu_read_lock(); break; } - __fl_put(f); + __fl_put(tp, f); arg->count++; rcu_read_lock(); } @@ -2697,7 +2703,7 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, cls_flower.rule = flow_rule_alloc(tcf_exts_num_actions(&f->exts)); if (!cls_flower.rule) { - __fl_put(f); + __fl_put(tp, f); return -ENOMEM; } @@ -2715,7 +2721,7 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, if (err) { kfree(cls_flower.rule); if (tc_skip_sw(f->flags)) { - __fl_put(f); + __fl_put(tp, f); return err; } goto next_flow; @@ -2731,11 +2737,11 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, kfree(cls_flower.rule); if (err) { - __fl_put(f); + __fl_put(tp, f); return err; } next_flow: - __fl_put(f); + __fl_put(tp, f); } return 0; From 718f364a20ecee4f25986789c25550cf4da73b4c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 11 Oct 2026 01:41:27 +0000 Subject: [PATCH 1859/2126] gre: keep the UDP tunnel GSO type when completing GRO gre_gro_complete() assigns SKB_GSO_GRE to gso_type rather than OR-ing it in. When GRE is carried over UDP by FOU or GUE, udp_gro_complete() has already set SKB_GSO_UDP_TUNNEL{,_CSUM} before calling into the FOU or GUE gro_complete handler and then gre_gro_complete(), so that bit is lost. That has broken forwarding of such packets since FOU gained GRO: if a host with a FOU or GUE socket on the tunnel's port merges transit packets and then forwards them out a device that can't segment them itself, udp4_ufo_fragment() finds neither tunnel bit and fails, and the packets are dropped. Since commit 3d010c8031e3 ("udp: do not accept non-tunnel GSO skbs landing in a tunnel"), local receive is broken too: udp_unexpected_gso() considers the merged skb, which reaches the encapsulation socket without either UDP tunnel bit, unexpected and hands it to udp_rcv_segment(). Segmenting fails, so the packet is freed and counted in UdpInErrors. Either way, only packets GRO didn't merge get through, so TCP over FOU or GUE GRE tunnels slows to about one segment per round trip whenever the receiving device has GRO enabled. OR in SKB_GSO_GRE instead, as ipip_gro_complete() and sit_gro_complete() do for SKB_GSO_IPXIP4. For plain GRE, gso_type is still zero at this point unless the driver set it, so nothing changes there in the usual case. The assignment dates to commit bf5a755f5e91 ("net-gre-gro: Add GRE support to the GRO stack"), but nothing set gso_type before it until FOU GRO came along, so the Fixes tag points there. Tested under virtme-ng with bulk TCP over a GRE tunnel between two network namespaces joined by a veth, with GRO on the receiving veth and segmentation off on the sending one, so GRO sees wire-sized packets. 32 MiB took: before after FOU over IPv4 26.0s, 9658 UDP errors 0.28s, 0 errors GUE over IPv4 26.1s, 9686 UDP errors 0.39s, 0 errors FOU over IPv6 26.4s, 9860 UDP errors 0.16s, 0 errors plain GRE 0.17s 0.15s Forwarding the same FOU traffic through a third namespace with its own FOU socket on the port, GRO on its ingress and segmentation off on its egress, took 26.0s with 4826 egress drops before and 0.31s with none after. On v6.8, before 3d010c8031e3, local receive was fine but forwarding failed the same way (25.7s, 4764 drops). With GRO off on the receiver, all took under 0.2s both before and after. The gre_gso.sh and fou_mcast_encap.sh selftests give the same results before and after. Fixes: afe93325bc02 ("fou: Add GRO support") Signed-off-by: Brad Fitzpatrick Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261011-bradfitz-gre-fou-gro-b4-v1-1-df713aad1531@tailscale.com Signed-off-by: Jakub Kicinski --- net/ipv4/gre_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c index 5028c72d494a..c8129782d39d 100644 --- a/net/ipv4/gre_offload.c +++ b/net/ipv4/gre_offload.c @@ -242,7 +242,7 @@ static int gre_gro_complete(struct sk_buff *skb, int nhoff) __be16 type; skb->encapsulation = 1; - skb_shinfo(skb)->gso_type = SKB_GSO_GRE; + skb_shinfo(skb)->gso_type |= SKB_GSO_GRE; type = greh->protocol; if (greh->flags & GRE_KEY) From d0eb9632fd987bf3029fc0c845b65ba6b661a41f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 11 Oct 2026 01:41:28 +0000 Subject: [PATCH 1860/2126] selftests: net: add a test for GRO of GRE over FOU and GUE Send bulk TCP through GRE tunnels carried over UDP by FOU and by GUE, each over IPv4 and IPv6, with GRO on at the receiving veth and segmentation off at the sender so the receiver gets wire-sized packets to merge. Check that the receiver counts no UDP errors. Verified under virtme-ng: without the previous patch, all four cases fail, with the encapsulation socket counting every merged packet in UdpInErrors or Udp6InErrors. With it, they pass in a few seconds. Signed-off-by: Brad Fitzpatrick Link: https://patch.msgid.link/20261011-bradfitz-gre-fou-gro-b4-v1-2-df713aad1531@tailscale.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/fou_gre_gro.sh | 164 +++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100755 tools/testing/selftests/net/fou_gre_gro.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 590b33e16d9f..55101ed41c52 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -42,6 +42,7 @@ TEST_PROGS := \ fib_rule_tests.sh \ fib_tests.sh \ fin_ack_lat.sh \ + fou_gre_gro.sh \ fou_mcast_encap.sh \ fq_band_pktlimit.sh \ gre_gso.sh \ diff --git a/tools/testing/selftests/net/fou_gre_gro.sh b/tools/testing/selftests/net/fou_gre_gro.sh new file mode 100755 index 000000000000..21ed50f647ae --- /dev/null +++ b/tools/testing/selftests/net/fou_gre_gro.sh @@ -0,0 +1,164 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Test that GRE packets carried over UDP (FOU or GUE) get through when the +# receiver merges them with GRO. +# +# Send bulk TCP through such tunnels with GRO on at the receiver, and +# segmentation off at the sender so the receiver gets wire-sized packets +# to merge, and check that the receiver counts no UDP errors (UdpInErrors +# or Udp6InErrors). Also check that GRO really merged packets, by comparing +# the UDP datagrams the receiver delivered with the packets its veth +# received, so that a setup where GRO doesn't engage skips rather than +# passes. + +source lib.sh + +NSEND="" +NRECV="" + +FOU_PORT=5555 +TCP_PORT=9000 +SIZE_MB=4 + +TUN_S=192.168.99.1 +TUN_R=192.168.99.2 + +cleanup() { + cleanup_all_ns +} + +trap cleanup EXIT + +# setup_tunnel creates the namespaces, the veth between them and a GRE +# tunnel over UDP encapsulation $1 (fou or gue) over IPv$2. It returns +# $ksft_skip if the kernel or iproute2 can't set it up. +setup_tunnel() { + local encap=$1 + local family=$2 + local type=gre + local addr_s=10.0.0.1 + local addr_r=10.0.0.2 + local fou_args="ipproto 47" + + if [ "$encap" = gue ]; then + fou_args=gue + fi + if [ "$family" = 6 ]; then + type=ip6gre + addr_s=2001:db8::1 + addr_r=2001:db8::2 + fou_args="$fou_args -6" + fi + + setup_ns NSEND NRECV || return "$ksft_skip" + + ip link add veth_s netns "$NSEND" type veth \ + peer name veth_r netns "$NRECV" || return "$ksft_skip" + ip -n "$NSEND" addr add 10.0.0.1/24 dev veth_s + ip -n "$NRECV" addr add 10.0.0.2/24 dev veth_r + ip -n "$NSEND" addr add 2001:db8::1/64 dev veth_s nodad + ip -n "$NRECV" addr add 2001:db8::2/64 dev veth_r nodad + ip -n "$NSEND" link set veth_s up + ip -n "$NRECV" link set veth_r up + + ip netns exec "$NRECV" ethtool -K veth_r gro on || return "$ksft_skip" + ip netns exec "$NSEND" ethtool -K veth_s tso off gso off \ + tx-gre-segmentation off tx-gre-csum-segmentation off \ + tx-udp_tnl-segmentation off tx-udp_tnl-csum-segmentation off || + return "$ksft_skip" + + # shellcheck disable=SC2086 # $fou_args is several arguments + ip netns exec "$NSEND" ip fou add port "$FOU_PORT" $fou_args || + return "$ksft_skip" + # shellcheck disable=SC2086 + ip netns exec "$NRECV" ip fou add port "$FOU_PORT" $fou_args || + return "$ksft_skip" + ip -n "$NSEND" link add gre_t type "$type" \ + local "$addr_s" remote "$addr_r" \ + encap "$encap" encap-sport auto encap-dport "$FOU_PORT" || + return "$ksft_skip" + ip -n "$NRECV" link add gre_t type "$type" \ + local "$addr_r" remote "$addr_s" \ + encap "$encap" encap-sport auto encap-dport "$FOU_PORT" || + return "$ksft_skip" + + ip -n "$NSEND" addr add "$TUN_S/30" dev gre_t + ip -n "$NRECV" addr add "$TUN_R/30" dev gre_t + ip -n "$NSEND" link set gre_t up + ip -n "$NRECV" link set gre_t up +} + +# recv_counter prints the sum of the receiver's nstat counters "$@". +recv_counter() { + ip netns exec "$NRECV" nstat -az "$@" | + awk '!/^#/ { n += $2 } END { print n + 0 }' +} + +run_test() { + local encap=$1 + local family=$2 + local name="GRO of GRE in ${encap^^} over IPv$family" + local datagrams + local packets + local errors + local pid + local rc + + RET=0 + + if ! setup_tunnel "$encap" "$family"; then + log_test_skip "$name" + cleanup_all_ns + return + fi + + ip netns exec "$NRECV" socat -u \ + TCP4-LISTEN:"$TCP_PORT",bind="$TUN_R",reuseaddr OPEN:/dev/null & + pid=$! + wait_local_port_listen "$NRECV" "$TCP_PORT" tcp + + # The timeout only bounds failing runs; passing ones take under a second. + dd if=/dev/zero bs=1M count="$SIZE_MB" 2>/dev/null | + ip netns exec "$NSEND" timeout 20 \ + socat -u STDIN TCP4:"$TUN_R":"$TCP_PORT" + rc=$? + + # Check the UDP error count rather than the duration, which depends + # on the machine. + errors=$(recv_counter UdpInErrors Udp6InErrors) + check_err "$errors" "$errors UDP errors at the receiver" + check_err "$rc" "transfer failed" + + # Without errors, a pass only means something if GRO merged packets: + # then the encapsulation socket sees far fewer datagrams than the + # veth received packets. + datagrams=$(recv_counter UdpInDatagrams Udp6InDatagrams) + packets=$(ip netns exec "$NRECV" \ + cat /sys/class/net/veth_r/statistics/rx_packets) + if [ "$RET" -eq 0 ] && [ $((datagrams * 2)) -gt "$packets" ]; then + ret_set_ksft_status "$ksft_skip" \ + "GRO didn't merge: $datagrams UDP datagrams from $packets packets" + fi + + log_test "$name" + kill "$pid" 2>/dev/null + wait "$pid" 2>/dev/null + cleanup_all_ns +} + +require_command socat +require_command ethtool +require_command nstat + +modprobe -q fou +modprobe -q ip_gre +modprobe -q fou6 +modprobe -q ip6_gre + +run_test fou 4 +run_test gue 4 +run_test fou 6 +run_test gue 6 + +exit "$EXIT_STATUS" From fa38468cd26b4db34ab2b335f1904c19721f94b8 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Tue, 13 Oct 2026 18:11:59 +0300 Subject: [PATCH 1861/2126] net: phy: refuse a second attach before touching the PHY phy_attach_direct() tests phydev->attached_dev only after it has taken the driver module and, for a PHY with no driver, bound the generic one, and then leaves through the error path that calls phy_detach_internal(). That call works on the PHY's current attachment, so a second attach of a PHY in use tears down the first consumer: it clears that netdev's phydev pointer and the PHY's attached_dev, removes the sysfs links and suspends the PHY, while the first consumer goes on using it. A PHY on the generic driver never reaches the test: the attach runs its probe again and, when the bind fails, clears d->driver under the first consumer. Found in review of a change that makes phy_detach() put only the module the attach recorded: with it, this path leaves the first consumer's reference pinned. On a Keenetic KN-1012, a test module attaching a second netdev to the EN8811H that the lan4 DSA port holds got -EBUSY and left lan4 with no PHY; with this change lan4 kept it. Test whether the PHY is attached before the driver module is taken or the generic driver bound, and refuse from there. A PHY attached without a netdev, as DSA does for its CPU and link ports, has no attached_dev, so test phy_link_change, which every attach sets and every detach clears. A second attach of such a PHY used to succeed and share it; with that change it would also leak a module reference. Signed-off-by: Aleksei Sviridkin Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261013151200.2473464-2-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index bfce8b893644..6bc9cdb7fa69 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1811,6 +1811,13 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, get_device(d); + /* Set by every attach, with or without a netdev */ + if (phydev->phy_link_change) { + phydev_err(phydev, "PHY already attached\n"); + err = -EBUSY; + goto error_put_device; + } + /* Assume that if there is no driver, that it doesn't * exist, and we should use the genphy driver. */ @@ -1838,12 +1845,6 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, goto error_module_put; } - if (phydev->attached_dev) { - dev_err(&dev->dev, "PHY already attached\n"); - err = -EBUSY; - goto error; - } - phydev->phy_link_change = phy_link_change; if (dev) { phydev->attached_dev = dev; From 7151b86654fa635101cabe7f55511f54c3adcf84 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Tue, 13 Oct 2026 18:12:00 +0300 Subject: [PATCH 1862/2126] net: phy: put the driver module the attach took phy_attach_direct() pins the PHY driver module through d->driver, and phy_detach() releases it by reading d->driver again. Unbinding the PHY driver while the PHY is attached clears that pointer, so a detach that runs while the driver is still unbound skips the put and the module can no longer be unloaded; if a different driver binds in between, the put lands on a module that was never pinned. The NULL test added by commit c2b727df7caa ("net: phy: Avoid NPD upon phy_detach() when driver is unbound") avoids the oops but skips the put. Found by reading phy_detach() while chasing a PHY driver unbind race on a Keenetic KN-1012 (MT7981, air_en8811h built as a module). The leak itself was not observed there: unbinding air_en8811h under the attached lan4 DSA port and then unbinding the switch faults earlier on that board, in phy_free_interrupt() or under phy_stop(), before phy_detach() gets to the put. Remember which module was pinned and release that one. Reviewed-by: Andrew Lunn Signed-off-by: Aleksei Sviridkin Link: https://patch.msgid.link/20261013151200.2473464-3-f@lex.la Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 12 ++++++++---- include/linux/phy.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 6bc9cdb7fa69..68691c487eee 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1728,8 +1728,8 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus) phydev->phy_link_change = NULL; phydev->phylink = NULL; - if (phydev->mdio.dev.driver) - module_put(phydev->mdio.dev.driver->owner); + module_put(phydev->drv_owner); + phydev->drv_owner = NULL; /* If the device had no specific driver before (i.e. - it * was using the generic driver), we unbind the device @@ -1794,6 +1794,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, struct mii_bus *bus = phydev->mdio.bus; struct device *d = &phydev->mdio.dev; struct module *ndev_owner = NULL; + struct module *drv_owner; int irq = phydev->irq; int err; @@ -1830,11 +1831,13 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, phydev->is_genphy_driven = 1; } - if (!try_module_get(d->driver->owner)) { + drv_owner = d->driver->owner; + if (!try_module_get(drv_owner)) { phydev_err(phydev, "failed to get the device driver module\n"); err = -EIO; goto error_put_device; } + phydev->drv_owner = drv_owner; if (phydev->is_genphy_driven) { err = d->driver->probe(d); @@ -1942,7 +1945,8 @@ error: return err; error_module_put: - module_put(d->driver->owner); + module_put(phydev->drv_owner); + phydev->drv_owner = NULL; phydev->irq = irq; phydev->is_genphy_driven = 0; d->driver = NULL; diff --git a/include/linux/phy.h b/include/linux/phy.h index 7c5098a0dd6c..a5a419bc400e 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -578,6 +578,7 @@ struct phy_oatc14_sqi_capability { * * @mdio: MDIO bus this PHY is on * @drv: Pointer to the driver for this PHY instance + * @drv_owner: Driver module phy_attach_direct() took a reference on * @devlink: Create a link between phy dev and mac dev, if the external phy * used by current mac interface is managed by another mac interface. * @phyindex: Unique id across the phy's parent tree of phys to address the PHY @@ -689,6 +690,7 @@ struct phy_device { /* Information about the PHY type */ /* And management functions */ const struct phy_driver *drv; + struct module *drv_owner; struct device_link *devlink; From 1b82d5ce3ba9155db746e87065bafb87a5f8666b Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Wed, 14 Oct 2026 11:26:11 +0300 Subject: [PATCH 1863/2126] ipv4: Store netns in FIB table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The next patch will stop passing the network namespace to fib_table_lookup() and instead pass the namespace from the FIB table to the fib_table_lookup tracepoint. As a preparation, store the namespace in the FIB table when the table is created. The FIB table structure grows from 48 bytes to 56 bytes and still fits in a single cache line. No functional changes intended. Signed-off-by: Ido Schimmel Tested-by: Björn Töpel Reviewed-by: Björn Töpel Reviewed-by: David Ahern Link: https://patch.msgid.link/20261014082612.1280756-2-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- include/net/ip_fib.h | 4 +++- net/ipv4/fib_frontend.c | 6 +++--- net/ipv4/fib_trie.c | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index fb446f01a65d..033ed8fce35e 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -258,6 +258,7 @@ struct fib_table { struct hlist_node tb_hlist; u32 tb_id; int tb_num_default; + struct net *tb_net; struct rcu_head rcu; unsigned long *tb_data; unsigned long __data[]; @@ -593,7 +594,8 @@ void fib_nh_common_release(struct fib_nh_common *nhc); /* Exported by fib_trie.c */ void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri); void fib_trie_init(void); -struct fib_table *fib_trie_table(u32 id, struct fib_table *alias); +struct fib_table *fib_trie_table(struct net *net, u32 id, + struct fib_table *alias); bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags, const struct flowi4 *flp); diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index c80c1b36f1fd..97acfb35fb12 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -54,11 +54,11 @@ static int __net_init fib4_rules_init(struct net *net) { struct fib_table *local_table, *main_table; - main_table = fib_trie_table(RT_TABLE_MAIN, NULL); + main_table = fib_trie_table(net, RT_TABLE_MAIN, NULL); if (!main_table) return -ENOMEM; - local_table = fib_trie_table(RT_TABLE_LOCAL, main_table); + local_table = fib_trie_table(net, RT_TABLE_LOCAL, main_table); if (!local_table) goto fail; @@ -91,7 +91,7 @@ struct fib_table *fib_new_table(struct net *net, u32 id) if (id == RT_TABLE_LOCAL && !net->ipv4.fib_has_custom_rules) alias = fib_new_table(net, RT_TABLE_MAIN); - new_tb = fib_trie_table(id, alias); + new_tb = fib_trie_table(net, id, alias); if (!new_tb) return NULL; diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 4a800fdf1ad1..3bc8247b3d75 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -1881,7 +1881,7 @@ struct fib_table *fib_trie_unmerge(struct fib_table *oldtb) if (oldtb->tb_data == oldtb->__data) return oldtb; - local_tb = fib_trie_table(RT_TABLE_LOCAL, NULL); + local_tb = fib_trie_table(oldtb->tb_net, RT_TABLE_LOCAL, NULL); if (!local_tb) return NULL; @@ -2378,7 +2378,8 @@ void __init fib_trie_init(void) 0, SLAB_PANIC | SLAB_ACCOUNT, NULL); } -struct fib_table *fib_trie_table(u32 id, struct fib_table *alias) +struct fib_table *fib_trie_table(struct net *net, u32 id, + struct fib_table *alias) { struct fib_table *tb; struct trie *t; @@ -2391,6 +2392,7 @@ struct fib_table *fib_trie_table(u32 id, struct fib_table *alias) if (!tb) return NULL; + tb->tb_net = net; tb->tb_id = id; tb->tb_num_default = 0; tb->tb_data = (alias ? alias->__data : tb->__data); From a25a51258acf916545989ed162a34a3a8cb526de Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Wed, 14 Oct 2026 11:26:12 +0300 Subject: [PATCH 1864/2126] ipv4: Do not pass netns to fib_table_lookup() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit c436a624f89e ("ipv4: Pass netns to fib_table_lookup()") added the network namespace as an argument of fib_table_lookup() so that it could be passed to the fib_table_lookup tracepoint. However, the function is called in the data path and the namespace is only needed when the tracepoint is enabled, so the additional argument is unnecessary overhead. Instead, pass the namespace that is now stored in the FIB table to the tracepoint. This way, the namespace is only read when the tracepoint is enabled. Revert the signature of fib_table_lookup() and its callers to what they were before the above commit. The tracepoint itself is unchanged. No functional changes intended. Suggested-by: Paolo Abeni Link: https://lore.kernel.org/netdev/43857d08-c4f4-44ce-a0b3-0e7fcc56bf90@redhat.com/ Signed-off-by: Ido Schimmel Tested-by: Björn Töpel Reviewed-by: Björn Töpel Reviewed-by: David Ahern Link: https://patch.msgid.link/20261014082612.1280756-3-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- include/net/ip_fib.h | 12 +++++------- net/core/filter.c | 2 +- net/ipv4/devinet.c | 3 +-- net/ipv4/fib_frontend.c | 6 ++---- net/ipv4/fib_rules.c | 2 +- net/ipv4/fib_semantics.c | 2 +- net/ipv4/fib_trie.c | 16 +++++++++------- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 033ed8fce35e..92f4eb8b86d7 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -276,9 +276,8 @@ struct fib_dump_filter { struct net_device *dev; }; -int fib_table_lookup(struct net *net, struct fib_table *tb, - const struct flowi4 *flp, struct fib_result *res, - int fib_flags); +int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, + struct fib_result *res, int fib_flags); int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, struct netlink_ext_ack *extack); int fib_table_delete(struct net *, struct fib_table *, struct fib_config *, @@ -325,8 +324,7 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp, tb = fib_get_table(net, RT_TABLE_MAIN); if (tb) - err = fib_table_lookup(net, tb, flp, res, - flags | FIB_LOOKUP_NOREF); + err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF); if (err == -EAGAIN) err = -ENETUNREACH; @@ -390,14 +388,14 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp, tb = rcu_dereference_rtnl(net->ipv4.fib_main); if (tb) - err = fib_table_lookup(net, tb, flp, res, flags); + err = fib_table_lookup(tb, flp, res, flags); if (err != -EAGAIN) goto out; tb = rcu_dereference_rtnl(net->ipv4.fib_default); if (tb) - err = fib_table_lookup(net, tb, flp, res, flags); + err = fib_table_lookup(tb, flp, res, flags); if (err == -EAGAIN) err = -ENETUNREACH; diff --git a/net/core/filter.c b/net/core/filter.c index 3ee1a093337e..70dc621672f2 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6413,7 +6413,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params, if (unlikely(!tb)) return BPF_FIB_LKUP_RET_NOT_FWDED; - err = fib_table_lookup(net, tb, &fl4, &res, FIB_LOOKUP_NOREF); + err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF); } else { if (flags & BPF_FIB_LOOKUP_MARK) fl4.flowi4_mark = params->mark; diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index c106d56eb2f7..2ed4c706ca9e 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -157,8 +157,7 @@ struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref) */ local = fib_get_table(net, RT_TABLE_LOCAL); if (local && - !fib_table_lookup(net, local, &fl4, &res, - FIB_LOOKUP_NOREF) && + !fib_table_lookup(local, &fl4, &res, FIB_LOOKUP_NOREF) && res.type == RTN_LOCAL) result = FIB_RES_DEV(res); } else { diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 97acfb35fb12..8c123b111b3d 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -243,8 +243,7 @@ static inline unsigned int __inet_dev_addr_type(struct net *net, table = fib_get_table(net, tb_id); if (table) { ret = RTN_UNICAST; - if (!fib_table_lookup(net, table, &fl4, &res, - FIB_LOOKUP_NOREF)) { + if (!fib_table_lookup(table, &fl4, &res, FIB_LOOKUP_NOREF)) { struct fib_nh_common *nhc = fib_info_nhc(res.fi, 0); if (!dev || dev == nhc->nhc_dev) @@ -1401,8 +1400,7 @@ static void nl_fib_lookup(struct net *net, struct fib_result_nl *frn) local_bh_disable(); frn->tb_id = tb->tb_id; - frn->err = fib_table_lookup(net, tb, &fl4, &res, - FIB_LOOKUP_NOREF); + frn->err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF); if (!frn->err) { frn->prefixlen = res.prefixlen; diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index 28ba35125383..060501b376a8 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c @@ -136,7 +136,7 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_action(struct fib_rule *rule, tb_id = fib_rule_get_table(rule, arg); tbl = fib_get_table(rule->fr_net, tb_id); if (tbl) - err = fib_table_lookup(rule->fr_net, tbl, &flp->u.ip4, + err = fib_table_lookup(tbl, &flp->u.ip4, (struct fib_result *)arg->result, arg->flags); diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 20da68240f61..db030bc26b6d 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1224,7 +1224,7 @@ static int fib_check_nh_v4_gw(struct net *net, struct fib_nh *nh, u32 table, tbl = fib_get_table(net, table); if (tbl) - err = fib_table_lookup(net, tbl, &fl4, &res, + err = fib_table_lookup(tbl, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE | FIB_LOOKUP_NOREF); diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 3bc8247b3d75..be1e40780ad7 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -1415,9 +1415,8 @@ bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags, } /* should be called with rcu_read_lock */ -int fib_table_lookup(struct net *net, struct fib_table *tb, - const struct flowi4 *flp, struct fib_result *res, - int fib_flags) +int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, + struct fib_result *res, int fib_flags) { struct trie *t = (struct trie *) tb->tb_data; #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -1434,7 +1433,8 @@ int fib_table_lookup(struct net *net, struct fib_table *tb, n = get_child_rcu(pn, cindex); if (!n) { - trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, net); + trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, + tb->tb_net); return -EAGAIN; } @@ -1522,7 +1522,7 @@ backtrace: if (IS_TRIE(pn)) { trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, - net); + tb->tb_net); return -EAGAIN; } #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -1569,7 +1569,8 @@ out_reject: #ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc(stats->semantic_match_passed); #endif - trace_fib_table_lookup(tb->tb_id, flp, NULL, err, net); + trace_fib_table_lookup(tb->tb_id, flp, NULL, err, + tb->tb_net); return err; } if (fi->fib_flags & RTNH_F_DEAD) @@ -1610,7 +1611,8 @@ set_result: #ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc(stats->semantic_match_passed); #endif - trace_fib_table_lookup(tb->tb_id, flp, nhc, err, net); + trace_fib_table_lookup(tb->tb_id, flp, nhc, err, + tb->tb_net); return err; } From 72ac1c0937dff7e32ad87829cd23fbc82347fe48 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Mon, 28 Sep 2026 18:58:02 +0000 Subject: [PATCH 1865/2126] netfilter: nf_queue: limit the hook drop flush to the unregistered hook point Unregistering a netfilter hook calls nf_queue_nf_hook_drop(), which makes nfqnl_nf_hook_drop() walk every nfqueue instance of the network namespace and flush it, reinjecting every packet that waits for a verdict with NF_DROP. Deleting an nftables base chain of any table, family and hook point therefore drops the packets queued by hooks of unrelated tables, families and hook points. The verdict that userspace sends for them afterwards fails with -ENOENT. Before commit 039b40ee5854 ("netfilter: nf_queue: only call synchronize_net twice if nf_queue is active") nf_queue_nf_hook_drop() received the removed hook and nfqueue only dropped the entries queued by that hook. The commit removed the argument and the comparison because base chain removal while nfqueue is in use was rare at the time. With base chains added and removed by userspace agents while another program holds packets in a queue this is no longer the case. Commit 960632ece694 ("netfilter: convert hook list to an array") then replaced the hook pointer in struct nf_queue_entry with an index into the hook array of the hook point, so a comparison per hook is no longer possible. A comparison per hook point is: the index of an entry is only stale when the array of its own hook point changed. Pass the nf_hook_ops being unregistered down to the queue handler and add nf_hook_cmp() to nfnetlink_queue, a cmpfn for nfqnl_flush() that matches the entries whose state.pf and state.hook are the hook point of that hook. The handler takes the nf_hook_ops rather than the family of the modified array to keep a single argument with NULL meaning "flush everything", which nf_ct_iterate_destroy() uses on module exit and __nft_ct_set_destroy() uses when a ct zone expression goes away and a queued packet may still reference its conntrack template. The cmpfn resolves the family itself. An NFPROTO_INET hook is registered in the IPv4 and the IPv6 array, so it matches the entries of both families; nf_unregister_net_hook() calls __nf_unregister_net_hook() for the two arrays back to back and the second flush finds nothing left. If the shrink of one array fails to allocate, that array keeps its dummy hook and its entries stay valid, so the flush for the other family drops them without need; no entry with a stale index survives. An NFPROTO_INET hook at NF_INET_INGRESS is registered in the netdev ingress array, the same mapping that nf_static_key_inc() applies. nfqueue does not accept the ingress and egress hooks (nft_queue_validate()), the mapping keeps the comparison consistent with the registration. The entries queued from the hook point whose array changed are still dropped, their hook_index is stale. Registering a hook in front of the one that queued a packet still makes nf_reinject() resume at a stale index, so the packet traverses the queueing hook a second time; this is not changed here. Tested with the reproducer script from the thread, unchanged: it queues 20 UDP packets from an inet output chain to a queue program that delays every verdict by 100 ms and changes the ruleset while they wait. Before this change deleting an unrelated ip6 base chain or an unrelated ip6 table delivers 3 of 20 packets and the queue program exits on ENOENT; with it all 20 are delivered. Deleting a base chain at the same hook point (inet output, another priority, in the same or another table) or an ip table with an output base chain still drops the queued packets; deleting an ip6 table with an output base chain or a netdev ingress chain does not. Adding a base chain in front of the queueing one still queues the packets twice. The nft_queue.sh selftest passes, with CONFIG_NETFILTER_NETLINK_QUEUE=y and built as a module. The following patch adds a test for both outcomes that holds the verdicts instead of delaying them. The code and this commit message were written with an LLM coding assistant from a task description that contained the report, the suggestion from the thread and the two commits above. The author reviewed the result, directed the changes and validated them with the reproducer and the selftest in virtme-ng before and after the change. Suggested-by: Florian Westphal Link: https://lore.kernel.org/netfilter-devel/CABhP=tYtCyr-qzL==98nkmDVZr6x+f8E26V1AAOpMXgZgt0vAQ@mail.gmail.com/ Assisted-by: LLM Signed-off-by: Antonio Ojea Signed-off-by: Pablo Neira Ayuso --- include/net/netfilter/nf_queue.h | 3 ++- net/netfilter/core.c | 2 +- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_internals.h | 2 +- net/netfilter/nf_queue.c | 4 +-- net/netfilter/nfnetlink_queue.c | 41 +++++++++++++++++++++++++++++-- net/netfilter/nft_ct.c | 2 +- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h index fc3e81c07364..86021c55ba3c 100644 --- a/include/net/netfilter/nf_queue.h +++ b/include/net/netfilter/nf_queue.h @@ -35,7 +35,8 @@ struct nf_queue_entry { struct nf_queue_handler { int (*outfn)(struct nf_queue_entry *entry, unsigned int queuenum); - void (*nf_hook_drop)(struct net *net); + void (*nf_hook_drop)(struct net *net, + const struct nf_hook_ops *ops); }; void nf_register_queue_handler(const struct nf_queue_handler *qh); diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 940dea2663e9..44c856c1e621 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -529,7 +529,7 @@ static void __nf_unregister_net_hook(struct net *net, int pf, if (!p) return; - nf_queue_nf_hook_drop(net); + nf_queue_nf_hook_drop(net, reg); nf_hook_entries_free(p); } diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index f9b8927327ba..8514a37c29fa 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -2410,7 +2410,7 @@ nf_ct_iterate_destroy(int (*iter)(struct nf_conn *i, void *data), void *data) if (atomic_read(&cnet->count) == 0) continue; - nf_queue_nf_hook_drop(net); + nf_queue_nf_hook_drop(net, NULL); } up_read(&net_rwsem); diff --git a/net/netfilter/nf_internals.h b/net/netfilter/nf_internals.h index 25403023060b..ce5aff2cae71 100644 --- a/net/netfilter/nf_internals.h +++ b/net/netfilter/nf_internals.h @@ -24,7 +24,7 @@ #define CTA_FILTER_FLAG(ctattr) CTA_FILTER_F_ ## ctattr /* nf_queue.c */ -void nf_queue_nf_hook_drop(struct net *net); +void nf_queue_nf_hook_drop(struct net *net, const struct nf_hook_ops *ops); /* nf_log.c */ int __init netfilter_log_init(void); diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c index 73363ceedebe..166d05e994ac 100644 --- a/net/netfilter/nf_queue.c +++ b/net/netfilter/nf_queue.c @@ -129,14 +129,14 @@ bool nf_queue_entry_get_refs(struct nf_queue_entry *entry) } EXPORT_SYMBOL_GPL(nf_queue_entry_get_refs); -void nf_queue_nf_hook_drop(struct net *net) +void nf_queue_nf_hook_drop(struct net *net, const struct nf_hook_ops *ops) { const struct nf_queue_handler *qh; rcu_read_lock(); qh = rcu_dereference(nf_queue_handler); if (qh) - qh->nf_hook_drop(net); + qh->nf_hook_drop(net, ops); rcu_read_unlock(); } EXPORT_SYMBOL_GPL(nf_queue_nf_hook_drop); diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index a3bc00280051..00b76c25d55c 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -1559,9 +1559,39 @@ static struct notifier_block nfqnl_dev_notifier = { .notifier_call = nfqnl_rcv_dev_event, }; -static void nfqnl_nf_hook_drop(struct net *net) +/* Match the entries whose hook_index points into the hook array that + * __nf_unregister_net_hook() replaces when it removes @ops. + * + * ops->pf/hooknum name the hook as registered; entry->state.pf/hook + * name the array actually traversed - they differ only for NFPROTO_INET. + * Every other family uses the array of its own name. + */ +static int nf_hook_cmp(struct nf_queue_entry *entry, unsigned long ops_ptr) +{ + const struct nf_hook_ops *ops = (const struct nf_hook_ops *)ops_ptr; + unsigned int hooknum = ops->hooknum; + u8 pf = ops->pf; + + /* same translation as nf_static_key_inc() */ + if (pf == NFPROTO_INET && hooknum == NF_INET_INGRESS) { + pf = NFPROTO_NETDEV; + hooknum = NF_NETDEV_INGRESS; + } + + if (entry->state.hook != hooknum) + return 0; + + if (pf == NFPROTO_INET) + return entry->state.pf == NFPROTO_IPV4 || + entry->state.pf == NFPROTO_IPV6; + + return entry->state.pf == pf; +} + +static void nfqnl_nf_hook_drop(struct net *net, const struct nf_hook_ops *ops) { struct nfnl_queue_net *q = nfnl_queue_pernet(net); + nfqnl_cmpfn cmpfn = NULL; int i; /* This function is also called on net namespace error unwind, @@ -1574,12 +1604,19 @@ static void nfqnl_nf_hook_drop(struct net *net) if (!q) return; + /* ops is NULL when the caller is not unregistering a hook but + * removing an object queued packets may reference, every entry + * has to go + */ + if (ops) + cmpfn = nf_hook_cmp; + for (i = 0; i < INSTANCE_BUCKETS; i++) { struct nfqnl_instance *inst; struct hlist_head *head = &q->instance_table[i]; hlist_for_each_entry_rcu(inst, head, hlist) - nfqnl_flush(inst, NULL, 0); + nfqnl_flush(inst, cmpfn, (unsigned long)ops); } } diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c index 3c4c2faa7398..5a8db5592036 100644 --- a/net/netfilter/nft_ct.c +++ b/net/netfilter/nft_ct.c @@ -542,7 +542,7 @@ static void __nft_ct_set_destroy(const struct nft_ctx *ctx, struct nft_ct *priv) #endif #ifdef CONFIG_NF_CONNTRACK_ZONES case NFT_CT_ZONE: - nf_queue_nf_hook_drop(ctx->net); + nf_queue_nf_hook_drop(ctx->net, NULL); mutex_lock(&nft_ct_pcpu_mutex); if (--nft_ct_pcpu_template_refcnt == 0) nft_ct_tmpl_put_pcpu(); From 853d419bfb342318a38915087726a5ac3b992d4c Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Mon, 28 Sep 2026 18:58:03 +0000 Subject: [PATCH 1866/2126] selftests: netfilter: nft_queue: check the scope of the hook drop flush Add test_hook_drop_scope. It queues 20 UDP packets from an inet output chain to a queue program that holds all verdicts, deletes a base chain while they wait, and reads the queue length from /proc/net/netfilter/nfnetlink_queue right after the deletion. It then releases the queue program and checks with a counter in the input chain and the packet total of the queue program that the surviving packets are delivered. Deleting a base chain at another hook point (ip6 prerouting) must keep the 20 queued packets. Deleting a base chain at the queueing hook point (inet output, another priority) drops them, because the index of a queued packet into the hook array of its hook point is stale once that array changed. The second case documents the remaining behaviour so that a change to it is visible. To hold the packets without depending on timing, add the -H option to the nf_queue helper: it blocks SIGUSR1, reads the first packet and waits in sigwait() until it receives SIGUSR1, then sends the verdicts as usual. The test sends the signal after the ruleset change, so the queue length it reads is exact on slow machines too. Without the previous patch the first case fails: 0 of 20 packets remain queued after the deletion and none is delivered. The test and the helper option were written with an LLM coding assistant from a task description; the author reviewed the result, and validated the test in virtme-ng on kernels with and without the previous patch. Assisted-by: LLM Signed-off-by: Antonio Ojea Signed-off-by: Pablo Neira Ayuso --- .../selftests/net/netfilter/nf_queue.c | 22 +++- .../selftests/net/netfilter/nft_queue.sh | 108 ++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/netfilter/nf_queue.c b/tools/testing/selftests/net/netfilter/nf_queue.c index 8bbec37f5356..cca6c3cfa9e4 100644 --- a/tools/testing/selftests/net/netfilter/nf_queue.c +++ b/tools/testing/selftests/net/netfilter/nf_queue.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -21,6 +22,7 @@ struct options { bool failopen; bool out_of_order; bool bogus_verdict; + bool hold; int verbose; unsigned int queue_num; unsigned int timeout; @@ -34,6 +36,7 @@ static struct options opts; static void help(const char *p) { printf("Usage: %s [-c|-v [-vv] ] [-o] [-O] [-b] [-t timeout] [-q queue_num] [-Qdst_queue ] [ -d ms_delay ] [-G]\n", p); + printf(" [-H] (hold verdicts until SIGUSR1 is received)\n"); } static int parse_attr_cb(const struct nlattr *attr, void *data) @@ -280,6 +283,7 @@ static int mainloop(void) uint32_t ooo_ids[16]; unsigned int portid; int ooo_count = 0; + sigset_t hold_set; char *buf; int ret; @@ -289,6 +293,12 @@ static int mainloop(void) exit(EXIT_FAILURE); } + /* -H: keep SIGUSR1 pending until the first packet is read */ + sigemptyset(&hold_set); + sigaddset(&hold_set, SIGUSR1); + if (opts.hold) + sigprocmask(SIG_BLOCK, &hold_set, NULL); + nl = open_queue(); portid = mnl_socket_get_portid(nl); @@ -320,6 +330,13 @@ static int mainloop(void) } id = ret - MNL_CB_OK; + if (opts.hold) { + int sig; + + sigwait(&hold_set, &sig); + opts.hold = false; + } + if (opts.delay_ms) sleep_ms(opts.delay_ms); @@ -364,7 +381,7 @@ static void parse_opts(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "chvoObt:q:Q:d:G")) != -1) { + while ((c = getopt(argc, argv, "chvoObt:q:Q:d:GH")) != -1) { switch (c) { case 'c': opts.count_packets = true; @@ -373,6 +390,9 @@ static void parse_opts(int argc, char **argv) help(argv[0]); exit(0); break; + case 'H': + opts.hold = true; + break; case 'q': opts.queue_num = atoi(optarg); if (opts.queue_num > 0xffff) diff --git a/tools/testing/selftests/net/netfilter/nft_queue.sh b/tools/testing/selftests/net/netfilter/nft_queue.sh index c8d1f2eb4133..a07652813a4b 100755 --- a/tools/testing/selftests/net/netfilter/nft_queue.sh +++ b/tools/testing/selftests/net/netfilter/nft_queue.sh @@ -861,6 +861,113 @@ test_queue_bridge() test_queue 20 "bridge" } +hook_drop_delivered() +{ + ip netns exec "$ns1" nft list counter inet nfqscope delivered | + sed -n 's/.*packets \([0-9]*\) .*/\1/p' +} + +hook_drop_queued() +{ + ip netns exec "$ns1" awk '$1 == 1 { print $3 }' /proc/self/net/netfilter/nfnetlink_queue +} + +hook_drop_all_queued() +{ + [ "$(hook_drop_queued)" = "$1" ] +} + +# hook_drop_case +# +# 1. The inet output chain sends udp packets to port 12345 to queue 1, +# the inet input chain counts them once they are accepted. +# 2. nf_queue -H reads the packets but sends no verdict until it gets +# SIGUSR1, so the 20 packets sent stay in the kernel queue. +# 3. The nft command removes a base chain while they are queued. The +# queue length in /proc right after it tells if the kernel dropped +# them: still 20, or 0. +# 4. SIGUSR1 releases nf_queue. If the kernel kept the packets they are +# accepted now and reach the input counter. If it dropped them the +# first verdict fails with ENOENT and nothing is counted. +hook_drop_case() +{ + local expect="$1" + local desc="$2" + local packets=20 + local delivered queued result + shift 2 + +ip netns exec "$ns1" nft -f /dev/stdin < "$TMPFILE1" 2>&1 & + local nfqpid=$! + + busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$ns1" 1 + + ip netns exec "$ns1" bash -c \ + "for i in \$(seq $packets); do echo x > /dev/udp/127.0.0.1/12345; done" + + busywait "$BUSYWAIT_TIMEOUT" hook_drop_all_queued "$packets" + + ip netns exec "$ns1" nft "$@" + queued=$(hook_drop_queued) + + kill -USR1 "$nfqpid" + wait "$nfqpid" + delivered=$(hook_drop_delivered) + + if [ "$queued" = "$packets" ] && [ "$delivered" = "$packets" ] && + grep -q "^$packets packets total" "$TMPFILE1"; then + result="keep" + elif [ "$queued" = "0" ] && [ "$delivered" = "0" ]; then + result="drop" + else + result="inconsistent" + fi + + if [ "$result" = "$expect" ]; then + echo "PASS: $desc: queued packets $result" + else + echo "FAIL: $desc: queued packets $result, expected $expect" 1>&2 + echo " $queued of $packets queued after the change, $delivered delivered" 1>&2 + ret=1 + fi +} + +test_hook_drop_scope() +{ + # the hook array of another hook point changes, queued packets stay + hook_drop_case keep "base chain removed at another hook point" \ + delete chain ip6 unrelated prerouting + + # the hook array of the queueing hook point changes, the position of + # the queued packets in it is stale, they are dropped + hook_drop_case drop "base chain removed at the queueing hook point" \ + delete chain inet nfqscope output2 + + ip netns exec "$ns1" nft flush ruleset +} + ip netns exec "$nsrouter" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null @@ -909,6 +1016,7 @@ test_queue_stress # should be last, adds vrf device in ns1 and changes routes test_icmp_vrf test_queue_removal +test_hook_drop_scope # turns router into a bridge test_queue_bridge From 9836164821a46af07428bb2a5e14137bf0c7bd6e Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Tue, 29 Sep 2026 15:09:39 +0200 Subject: [PATCH 1867/2126] netfilter: conntrack: fix unlikely UaF in gc worker When early-drop scan is enabled, gc_worker() reads tmp->ct_net, resolves cnet with nf_ct_pernet(), and reads cnet->count with RCU read lock held but before acquiring a reference to tmp. Its unlikely but possible that the worker gets preempted before reading cnet->count while nf_conntrack_cleanup_net_list manages to unlink all conntracks and returns in the mean time. This allows for the pernet memory to get free'd. On resume, use after free would occur when the worker reads cnet->count. This can be solved either via another synchronize_rcu() in nf_conntrack_cleanup_net_list or via cheaper flush_work(). If work wasn't running no race can happen as next call cannot observe already-unlinked conntrack objects. This is an LLM finding with no reproducer, but it appears to be correct. Fixes: c6dd940b1f74 ("netfilter: allow early drop of assured conntracks") Reported-by: Vega Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 8514a37c29fa..931b76aacd93 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -2506,6 +2506,11 @@ i_see_dead_people: goto i_see_dead_people; } + /* must wait for current scan loop, worker also looks at + * struct nf_conntrack_net, which is about to be free'd. + */ + flush_work(&conntrack_gc_work.dwork.work); + list_for_each_entry(net, net_exit_list, exit_list) { warn_on_keymap_list_leak(net); nf_conntrack_ecache_pernet_fini(net); From a3217c51a3171cf53bed17f962798368f2786bdc Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Tue, 29 Sep 2026 16:59:44 +0200 Subject: [PATCH 1868/2126] netfilter: nf_tables: switch chain_types array to rcu LLM quote: The global chain_type array is cleared under the nfnetlink subsystem mutex, but transaction processing reads it while holding only the pernet transaction mutex. nf_tables_chain_type_lookup() and nft_chain_parse_hook() dereference type->name/hook_mask before try_module_get(type->owner). Concurrent unloading of a separate provider such as nft_chain_nat can unregister and free its static nft_chain_type while a transaction is in the unprotected interval, causing a module-memory use-after-free. LLM finding, not observed in practice. Move this under RCU and grab the module owner earlier. Both nft_chain_route and nft_chain_filter are built into nf_tables.ko: only nft_chain_nat needs an extra synchronize_rcu(). Reported-by: Vega Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_tables_api.c | 94 ++++++++++++++++++++++++----------- net/netfilter/nft_chain_nat.c | 1 + 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index b59628e6240c..59ac623e6805 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -1036,32 +1036,67 @@ static inline u64 nf_tables_alloc_handle(struct nft_table *table) return ++table->hgenerator; } -static const struct nft_chain_type *chain_type[NFPROTO_NUMPROTO][NFT_CHAIN_T_MAX]; +static const struct nft_chain_type __rcu *chain_type[NFPROTO_NUMPROTO][NFT_CHAIN_T_MAX]; static const struct nft_chain_type * -__nft_chain_type_get(u8 family, enum nft_chain_types type) +__nft_chain_type_peek(u8 family, enum nft_chain_types type) { if (family >= NFPROTO_NUMPROTO || type >= NFT_CHAIN_T_MAX) return NULL; - return chain_type[family][type]; + return rcu_dereference_check(chain_type[family][type], + lockdep_nfnl_is_held(NFNL_SUBSYS_NFTABLES)); } +/** + * nft_chain_type_get - look up a chain type by family and id + * @family: netlink family + * @type: chain type (enum nft_chain_types) + * + * Return: chain type with a held module ref, or NULL. + */ +static const struct nft_chain_type * +nft_chain_type_get(u8 family, enum nft_chain_types type) +{ + const struct nft_chain_type *t; + + rcu_read_lock(); + t = __nft_chain_type_peek(family, type); + + if (t && !try_module_get(t->owner)) + t = NULL; + + rcu_read_unlock(); + return t; +} + +/** + * __nf_tables_chain_type_lookup - look up a chain type by name + * @nla: nlattr containing the chain-type name + * @family: netlink family + * + * Return: matching chain type with a held module ref, or NULL. + */ static const struct nft_chain_type * __nf_tables_chain_type_lookup(const struct nlattr *nla, u8 family) { - const struct nft_chain_type *type; + const struct nft_chain_type *type = NULL, *t; int i; + rcu_read_lock(); for (i = 0; i < NFT_CHAIN_T_MAX; i++) { - type = __nft_chain_type_get(family, i); - if (!type) + t = __nft_chain_type_peek(family, i); + if (!t) continue; - if (!nla_strcmp(nla, type->name)) - return type; + + if (!nla_strcmp(nla, t->name) && try_module_get(t->owner)) { + type = t; + break; + } } - return NULL; + rcu_read_unlock(); + return type; } struct nft_module_request { @@ -1837,11 +1872,11 @@ static void nf_tables_table_destroy(struct nft_table *table) void nft_register_chain_type(const struct nft_chain_type *ctype) { nfnl_lock(NFNL_SUBSYS_NFTABLES); - if (WARN_ON(__nft_chain_type_get(ctype->family, ctype->type))) { + if (WARN_ON(__nft_chain_type_peek(ctype->family, ctype->type))) { nfnl_unlock(NFNL_SUBSYS_NFTABLES); return; } - chain_type[ctype->family][ctype->type] = ctype; + rcu_assign_pointer(chain_type[ctype->family][ctype->type], ctype); nfnl_unlock(NFNL_SUBSYS_NFTABLES); } EXPORT_SYMBOL_GPL(nft_register_chain_type); @@ -1849,7 +1884,7 @@ EXPORT_SYMBOL_GPL(nft_register_chain_type); void nft_unregister_chain_type(const struct nft_chain_type *ctype) { nfnl_lock(NFNL_SUBSYS_NFTABLES); - chain_type[ctype->family][ctype->type] = NULL; + RCU_INIT_POINTER(chain_type[ctype->family][ctype->type], NULL); nfnl_unlock(NFNL_SUBSYS_NFTABLES); } EXPORT_SYMBOL_GPL(nft_unregister_chain_type); @@ -2581,10 +2616,6 @@ static int nft_chain_parse_hook(struct net *net, hook->num = ntohl(nla_get_be32(ha[NFTA_HOOK_HOOKNUM])); hook->priority = ntohl(nla_get_be32(ha[NFTA_HOOK_PRIORITY])); - type = __nft_chain_type_get(family, NFT_CHAIN_T_DEFAULT); - if (!type) - return -EOPNOTSUPP; - if (nla[NFTA_CHAIN_TYPE]) { type = nf_tables_chain_type_lookup(net, nla[NFTA_CHAIN_TYPE], family, true); @@ -2592,13 +2623,19 @@ static int nft_chain_parse_hook(struct net *net, NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TYPE]); return PTR_ERR(type); } + } else { + type = nft_chain_type_get(family, NFT_CHAIN_T_DEFAULT); + if (!type) + return -EOPNOTSUPP; } + + err = -EOPNOTSUPP; if (hook->num >= NFT_MAX_HOOKS || !(type->hook_mask & (1 << hook->num))) - return -EOPNOTSUPP; + goto out_put_type; if (type->type == NFT_CHAIN_T_NAT && hook->priority <= NF_IP_PRI_CONNTRACK) - return -EOPNOTSUPP; + goto out_put_type; } else { if (ha[NFTA_HOOK_HOOKNUM]) { hook->num = ntohl(nla_get_be32(ha[NFTA_HOOK_HOOKNUM])); @@ -2620,30 +2657,27 @@ static int nft_chain_parse_hook(struct net *net, } } else { type = basechain->type; + __module_get(type->owner); } } - if (!try_module_get(type->owner)) { - if (nla[NFTA_CHAIN_TYPE]) - NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TYPE]); - return -ENOENT; - } - hook->type = type; INIT_LIST_HEAD(&hook->list); if (nft_base_chain_netdev(family, hook->num)) { err = nft_chain_parse_netdev(net, ha, &hook->list, extack, flags); - if (err < 0) { - module_put(type->owner); - return err; - } + if (err < 0) + goto out_put_type; } else if (ha[NFTA_HOOK_DEV] || ha[NFTA_HOOK_DEVS]) { - module_put(type->owner); - return -EOPNOTSUPP; + err = -EOPNOTSUPP; + goto out_put_type; } return 0; + +out_put_type: + module_put(type->owner); + return err; } static void nft_chain_release_hook(struct nft_chain_hook *hook) diff --git a/net/netfilter/nft_chain_nat.c b/net/netfilter/nft_chain_nat.c index 40e230d8b712..1133f79d8d25 100644 --- a/net/netfilter/nft_chain_nat.c +++ b/net/netfilter/nft_chain_nat.c @@ -131,6 +131,7 @@ static void __exit nft_chain_nat_exit(void) #ifdef CONFIG_NF_TABLES_INET nft_unregister_chain_type(&nft_chain_nat_inet); #endif + synchronize_rcu(); } module_init(nft_chain_nat_init); From 540aab0e415d12b29f8a94fe5bb31c6dced24fd6 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Sun, 4 Oct 2026 03:41:43 +0200 Subject: [PATCH 1869/2126] netfilter: nft_exthdr: remove redundant op parsing in tcp_set_init The nft_exthdr_tcp_set_init() function is exclusively used for TCP options. Therefore, parsing the NFTA_EXTHDR_OP attribute from user space is redundant, as the operation type must always be NFT_EXTHDR_OP_TCPOPT. Remove the unnecessary netlink attribute parsing and hardcode priv->op to NFT_EXTHDR_OP_TCPOPT, which simplifies the code and reduces the object size. ./scripts/bloat-o-meter exthdr_before.o exthdr_after.o add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54) Function old new delta nft_exthdr_tcp_set_init 412 358 -54 Total: Before=6581, After=6527, chg -0.82% Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_exthdr.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c index 8abf8e8145ce..3492426dccf7 100644 --- a/net/netfilter/nft_exthdr.c +++ b/net/netfilter/nft_exthdr.c @@ -551,7 +551,7 @@ static int nft_exthdr_tcp_set_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) { struct nft_exthdr *priv = nft_expr_priv(expr); - u32 offset, len, flags = 0, op = NFT_EXTHDR_OP_IPV6; + u32 offset, len, flags = 0; int err; if (!tb[NFTA_EXTHDR_SREG] || @@ -581,15 +581,11 @@ static int nft_exthdr_tcp_set_init(const struct nft_ctx *ctx, return -EOPNOTSUPP; } - err = nft_parse_u32_check(tb[NFTA_EXTHDR_OP], U8_MAX, &op); - if (err < 0) - return err; - priv->type = nla_get_u8(tb[NFTA_EXTHDR_TYPE]); priv->offset = offset; priv->len = len; priv->flags = flags; - priv->op = op; + priv->op = NFT_EXTHDR_OP_TCPOPT; return nft_parse_register_load(ctx, tb[NFTA_EXTHDR_SREG], &priv->sreg, priv->len); From d7c4b903f349c1e910e377c9e306b1a789ba03a8 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Sun, 4 Oct 2026 03:41:44 +0200 Subject: [PATCH 1870/2126] netfilter: nft_exthdr: avoid 60 bytes stack buffer in TCP option mangling nft_exthdr_tcp_set_eval() and nft_exthdr_tcp_strip_eval() fetched the TCP header and options through nft_tcp_header_pointer(), which calls skb_header_pointer() a second time for the full tcphdr_len into a 60 bytes stack buffer. Since commit 28427f368f0e ("netfilter: nft_exthdr: Fix non-linear header modification") both functions then call skb_ensure_writable() and re-read the header from skb->data, so the buffer was never used. Only the 20 bytes fixed header is needed to learn tcphdr_len, so fetch just that, validate the length as before, and let skb_ensure_writable() pull the rest. This also drops the 60 bytes stack buffer from both functions. Comparison of performance in mpps: op linear/non-linear before after delta ================================================================== set, non-linear 4.193 4.348 +3.7% mpps strip, non-linear 4.184 4.434 +6.0% mpps set, linear 5.302 5.427 +2.4% mpps strip, linear 5.452 5.527 +1.4% mpss Comparison of performance in ns/expression: op linear/non-linear before after delta ================================================================== set, non-linear 34.6 25.3 -9.4 ns strip, non-linear 35.2 20.8 -14.3 ns set, linear 23.6 19.7 -3.9 ns strip, linear 22.9 19.8 -3.1 ns ./scripts/bloat-o-meter exthdr_before.o exthdr_after.o add/remove: 0/1 grow/shrink: 3/0 up/down: 233/-207 (26) Function old new delta nft_exthdr_tcp_eval 792 946 +154 nft_exthdr_tcp_strip_eval 825 891 +66 nft_exthdr_tcp_set_eval 602 615 +13 nft_tcp_header_pointer.part.constprop 207 - -207 Total: Before=6527, After=6553, chg +0.40% This also allow the compiler to inline nft_tcp_header_pointer inside nft_exthdr_tcp_eval() which could yield some minimal performance gain. This patch also updates the logic to drop malformed packets, before this patch NFT_BREAK was used as a verdict instead. Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_exthdr.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c index 3492426dccf7..861bab93f435 100644 --- a/net/netfilter/nft_exthdr.c +++ b/net/netfilter/nft_exthdr.c @@ -233,16 +233,23 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) { - u8 buff[sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE]; struct nft_exthdr *priv = nft_expr_priv(expr); unsigned int i, optl, tcphdr_len, offset; - struct tcphdr *tcph; + struct tcphdr *tcph, _tcph; u8 *opt; - tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff, &tcphdr_len); + if (pkt->tprot != IPPROTO_TCP || pkt->fragoff) + goto err; + + tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (!tcph) goto err; + tcphdr_len = __tcp_hdrlen(tcph); + if (tcphdr_len < sizeof(*tcph) || + tcphdr_len > sizeof(*tcph) + MAX_TCP_OPTION_SPACE) + goto err; + if (skb_ensure_writable(pkt->skb, nft_thoff(pkt) + tcphdr_len)) goto err; @@ -313,16 +320,23 @@ static void nft_exthdr_tcp_strip_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) { - u8 buff[sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE]; struct nft_exthdr *priv = nft_expr_priv(expr); unsigned int i, tcphdr_len, optl; - struct tcphdr *tcph; + struct tcphdr *tcph, _tcph; u8 *opt; - tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff, &tcphdr_len); + if (pkt->tprot != IPPROTO_TCP || pkt->fragoff) + goto err; + + tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (!tcph) goto err; + tcphdr_len = __tcp_hdrlen(tcph); + if (tcphdr_len < sizeof(*tcph) || + tcphdr_len > sizeof(*tcph) + MAX_TCP_OPTION_SPACE) + goto err; + if (skb_ensure_writable(pkt->skb, nft_thoff(pkt) + tcphdr_len)) goto drop; From a20a01ae89813ef493dc416d69f2b2ad17afb54c Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 7 Oct 2026 01:04:59 +0200 Subject: [PATCH 1871/2126] selftests: netfilter: fix return value in zone subtest zone subtest prints FAIL, but did not set 'ret=1', so kselftest framework reports success. While at it, also fail when "nft -f" returns an error. Noticed thanks to a (broken) local patch that should have caused this selftest (resp. the kselftest framework) to report a failure. Fixes: 33b8aad21ac1 ("selftests: netfilter: add a vrf+conntrack testcase") Signed-off-by: Florian Westphal Reviewed-by: Fernando Fernandez Mancera Signed-off-by: Pablo Neira Ayuso --- .../selftests/net/netfilter/conntrack_vrf.sh | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/netfilter/conntrack_vrf.sh b/tools/testing/selftests/net/netfilter/conntrack_vrf.sh index 207b79932d91..2dbfabaadf4b 100755 --- a/tools/testing/selftests/net/netfilter/conntrack_vrf.sh +++ b/tools/testing/selftests/net/netfilter/conntrack_vrf.sh @@ -84,7 +84,7 @@ busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1" # as decided by the first iteration of the ruleset. test_ct_zone_in() { -ip netns exec "$ns0" nft -f - < /dev/null # should be in zone 1, not zone 2 @@ -113,6 +119,7 @@ EOF echo "PASS: entry found in conntrack zone 1" else echo "FAIL: entry not found in conntrack zone 1" + ret=1 count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 2 2> /dev/null | wc -l) if [ "$count" -eq 1 ]; then echo "FAIL: entry found in zone 2 instead" @@ -137,7 +144,7 @@ test_masquerade_vrf() ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - < /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on vrf device" ret=1 @@ -184,7 +197,7 @@ EOF test_masquerade_veth() { ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - < /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on veth device" ret=1 From ac364eb4d6d747b15df17e5fc9e442c318afaaac Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 7 Oct 2026 01:15:49 +0200 Subject: [PATCH 1872/2126] netfilter: nft_compat: restrict raw table targets/matches xt targets and matches declaring .table = "raw" (CT, NOTRACK) rely on only ever running in the legacy raw table's prerouting/output chains, ahead of conntrack. nft_compat_chain_validate_dependency() already enforces this kind of correspondence for "nat" by requiring the chain type to actually be NAT, but did nothing for "raw": a rule wrapping the CT target could be loaded into any hook and any priority via nft_compat, including after the real conntrack hook has already run. The CT target attaches a conntrack template to the skb when none is set yet. Require that a "raw" table dependency actually matches what xtables enforces via the implict/builtin table dependency. Fixes: 0ca743a55991 ("netfilter: nf_tables: add compatibility layer for x_tables") Assisted-by: LLM Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_compat.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c index 63864b928259..88ddaf47f587 100644 --- a/net/netfilter/nft_compat.c +++ b/net/netfilter/nft_compat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,20 @@ static int nft_compat_chain_validate_dependency(const struct nft_ctx *ctx, type = NFT_CHAIN_T_NAT; if (basechain->type->type != type) return -EINVAL; + } else if (strcmp(tablename, "raw") == 0) { + /* iptables-nft emulates the legacy raw table, which only + * ever has prerouting/output chains at this exact priority. + */ + if (ctx->family != NFPROTO_IPV4 && + ctx->family != NFPROTO_IPV6) + return -EINVAL; + + if (basechain->ops.hooknum != NF_INET_PRE_ROUTING && + basechain->ops.hooknum != NF_INET_LOCAL_OUT) + return -EINVAL; + + if (basechain->ops.priority != NF_IP_PRI_RAW) + return -EINVAL; } return 0; From cae023143d25c877d04e05c986311507e75d4167 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Sun, 11 Oct 2026 23:59:41 +0200 Subject: [PATCH 1873/2126] netfilter: flowtable: set inner protocol when popping tunnel header Pop the outer tunnel header and set skb->protocol to the inner protocol derived from ctx->tun.inner_proto in nf_flow_ip_tunnel_pop(), instead of bailing out unless the tunnel carries IP-in-IP or IPv6-in-IPv6. This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload. Signed-off-by: Lorenzo Bianconi Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_flow_table_ip.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index c8c29a9a1684..29d1a9f4a362 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -372,6 +372,11 @@ static void nf_flow_ip_tunnel_pop(struct nf_flowtable_ctx *ctx, skb_pull(skb, ctx->tun.hdr_size); skb_reset_network_header(skb); + + if (ctx->tun.inner_proto == IPPROTO_IPIP) + skb->protocol = htons(ETH_P_IP); + else + skb->protocol = htons(ETH_P_IPV6); } static bool nf_flow_skb_encap_protocol(struct nf_flowtable_ctx *ctx, From 97874c7c5f2c31236c4071d85b60c38c2f4bac3d Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Sun, 11 Oct 2026 23:59:42 +0200 Subject: [PATCH 1874/2126] netfilter: flowtable: populate tunnel tuple regardless of inner protocol Store the outer tunnel addresses and inner protocol in the flow tuple unconditionally in nf_flow_tuple_encap(), instead of only when the tunnel is IP-in-IP or IPv6-in-IPv6. Bail out early when the inner protocol is neither IPPROTO_IPIP nor IPPROTO_IPV6. This makes the tuple usable for cross-family tunnels such as IPv4-over-IPv6 and SIT, where the inner protocol differs from the outer address family. This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload. Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet. Signed-off-by: Lorenzo Bianconi Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_flow_table_ip.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 29d1a9f4a362..8379b45b2dad 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -189,22 +189,22 @@ static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx, break; } + if (ctx->tun.inner_proto != IPPROTO_IPIP && + ctx->tun.inner_proto != IPPROTO_IPV6) + return; + switch (ctx->ether_type) { case htons(ETH_P_IP): iph = (struct iphdr *)(skb_network_header(skb) + offset); - if (ctx->tun.inner_proto == IPPROTO_IPIP) { - tuple->tun.dst_v4.s_addr = iph->daddr; - tuple->tun.src_v4.s_addr = iph->saddr; - tuple->tun.inner_proto = IPPROTO_IPIP; - } + tuple->tun.dst_v4.s_addr = iph->daddr; + tuple->tun.src_v4.s_addr = iph->saddr; + tuple->tun.inner_proto = ctx->tun.inner_proto; break; case htons(ETH_P_IPV6): ip6h = (struct ipv6hdr *)(skb_network_header(skb) + offset); - if (ctx->tun.inner_proto == IPPROTO_IPV6) { - tuple->tun.dst_v6 = ip6h->daddr; - tuple->tun.src_v6 = ip6h->saddr; - tuple->tun.inner_proto = IPPROTO_IPV6; - } + tuple->tun.dst_v6 = ip6h->daddr; + tuple->tun.src_v6 = ip6h->saddr; + tuple->tun.inner_proto = ctx->tun.inner_proto; break; default: break; From 3dcafe6cb5e1b467a25fde347c8c3949a2866adc Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Sun, 11 Oct 2026 23:59:43 +0200 Subject: [PATCH 1875/2126] netfilter: flowtable: add encap_proto to flow_offload_tunnel Add encap_proto (AF_INET or AF_INET6) to struct flow_offload_tunnel to allow its use as part of the hash table key during flowtable entry lookup. This is a preliminary change to support IPv4 over IPv6 tunneling via the flowtable infrastructure for software acceleration. Signed-off-by: Lorenzo Bianconi Signed-off-by: Pablo Neira Ayuso --- include/linux/netdevice.h | 1 + include/net/netfilter/nf_flow_table.h | 1 + net/ipv4/ipip.c | 1 + net/ipv6/ip6_tunnel.c | 1 + net/netfilter/nf_flow_table_ip.c | 2 ++ net/netfilter/nf_flow_table_path.c | 2 ++ 6 files changed, 8 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f61c97231309..fee3728ad666 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -911,6 +911,7 @@ struct net_device_path { }; u8 inner_proto; + u8 encap_proto; } tun; struct { enum { diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h index 5b611efaa3cd..5b22d31cb140 100644 --- a/include/net/netfilter/nf_flow_table.h +++ b/include/net/netfilter/nf_flow_table.h @@ -118,6 +118,7 @@ struct flow_offload_tunnel { }; u8 inner_proto; + u8 encap_proto; }; struct flow_offload_tuple { diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index 2ffe64e736e0..15189e1fa068 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -379,6 +379,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx, path->tun.src_v4.s_addr = tiph->saddr; path->tun.dst_v4.s_addr = tiph->daddr; path->tun.inner_proto = IPPROTO_IPIP; + path->tun.encap_proto = AF_INET; path->tun.dst = &rt->dst; path->dev = ctx->dev; diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index d5ff50a2ac01..64a184bca467 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1868,6 +1868,7 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx, path->tun.src_v6 = fl6.saddr; path->tun.dst_v6 = fl6.daddr; path->tun.inner_proto = IPPROTO_IPV6; + path->tun.encap_proto = AF_INET6; path->tun.dst = dst; path->dev = ctx->dev; ctx->dev = dst->dev; diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 8379b45b2dad..29a769736dbf 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -199,12 +199,14 @@ static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx, tuple->tun.dst_v4.s_addr = iph->daddr; tuple->tun.src_v4.s_addr = iph->saddr; tuple->tun.inner_proto = ctx->tun.inner_proto; + tuple->tun.encap_proto = AF_INET; break; case htons(ETH_P_IPV6): ip6h = (struct ipv6hdr *)(skb_network_header(skb) + offset); tuple->tun.dst_v6 = ip6h->daddr; tuple->tun.src_v6 = ip6h->saddr; tuple->tun.inner_proto = ctx->tun.inner_proto; + tuple->tun.encap_proto = AF_INET6; break; default: break; diff --git a/net/netfilter/nf_flow_table_path.c b/net/netfilter/nf_flow_table_path.c index d90013685bf1..841f099434d9 100644 --- a/net/netfilter/nf_flow_table_path.c +++ b/net/netfilter/nf_flow_table_path.c @@ -138,6 +138,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack, info->tun.dst_v6 = path->tun.dst_v6; info->tun.inner_proto = path->tun.inner_proto; info->tun_dst = path->tun.dst; + info->tun.encap_proto = path->tun.encap_proto; info->num_tuns++; } else { if (info->num_encaps >= NF_FLOW_TABLE_ENCAP_MAX) @@ -249,6 +250,7 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt, route->tuple[!dir].in.tun.src_v6 = info.tun.dst_v6; route->tuple[!dir].in.tun.dst_v6 = info.tun.src_v6; route->tuple[!dir].in.tun.inner_proto = info.tun.inner_proto; + route->tuple[!dir].in.tun.encap_proto = info.tun.encap_proto; route->tuple[!dir].in.num_tuns = info.num_tuns; dst_release(route->tuple[dir].dst); route->tuple[dir].dst = info.tun_dst; From d0107f38162279d9cb0e012210731176265f835d Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Sun, 11 Oct 2026 23:59:45 +0200 Subject: [PATCH 1876/2126] netfilter: flowtable: unify tunnel push for IPv4 and IPv6 Refactor nf_flow_tunnel_ipip_push() and nf_flow_tunnel_ip6ip6_push() into nf_flow_tunnel_ip_push() and nf_flow_tunnel_ip6_push(), keying the inner header handling off tuple->tun.inner_proto so both IP-in-IP and IPv6-in-IPv6 inner protocols are supported regardless of the outer address family. Replace nf_flow_tunnel_v4_push() and nf_flow_tunnel_v6_push() with a single nf_flow_tunnel_push() that dispatches on tuple->tun.encap_proto, and set skb->protocol explicitly after pushing the outer header. This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload. Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet. Signed-off-by: Lorenzo Bianconi Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_flow_table_ip.c | 143 +++++++++++++++++++------------ 1 file changed, 87 insertions(+), 56 deletions(-) diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 29a769736dbf..e13f9397e8cb 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -587,23 +587,44 @@ static int nf_flow_pppoe_push(struct sk_buff *skb, u16 id, return 0; } -static int nf_flow_tunnel_ipip_push(struct net *net, struct sk_buff *skb, - struct flow_offload_tuple *tuple, - struct dst_entry *dst, __be32 *ip_daddr) +static int nf_flow_tunnel_ip_push(struct net *net, struct sk_buff *skb, + struct flow_offload_tuple *tuple, + struct dst_entry *dst, + union nf_inet_addr **ip_addr) { - struct iphdr *iph = (struct iphdr *)skb_network_header(skb); - struct rtable *rt = dst_rtable(dst); - u8 tos = iph->tos, ttl = iph->ttl; - __be16 frag_off = iph->frag_off; - u32 headroom = sizeof(*iph); + __be16 frag_off = 0; + struct iphdr *iph; + u8 tos = 0, ttl; + u32 headroom; int err; + switch (tuple->tun.inner_proto) { + case IPPROTO_IPV6: { + struct ipv6hdr *ip6h; + + ip6h = (struct ipv6hdr *)skb_network_header(skb); + tos = ipv6_get_dsfield(ip6h); + ttl = ip6h->hop_limit; + frag_off = htons(IP_DF); + break; + } + case IPPROTO_IPIP: + iph = (struct iphdr *)skb_network_header(skb); + frag_off = iph->frag_off; + tos = iph->tos; + ttl = iph->ttl; + break; + default: + return 0; + } + err = iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4); if (err) return err; - skb_set_inner_ipproto(skb, IPPROTO_IPIP); - headroom += LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len; + skb_set_inner_ipproto(skb, tuple->tun.inner_proto); + headroom = sizeof(*iph) + LL_RESERVED_SPACE(dst->dev) + + dst->header_len; err = skb_cow_head(skb, headroom); if (err) return err; @@ -614,11 +635,12 @@ static int nf_flow_tunnel_ipip_push(struct net *net, struct sk_buff *skb, /* Push down and install the IP header. */ skb_push(skb, sizeof(*iph)); skb_reset_network_header(skb); + skb->protocol = htons(ETH_P_IP); iph = ip_hdr(skb); iph->version = 4; iph->ihl = sizeof(*iph) >> 2; - iph->frag_off = ip_mtu_locked(&rt->dst) ? 0 : frag_off; + iph->frag_off = ip_mtu_locked(dst) ? 0 : frag_off; iph->protocol = tuple->tun.inner_proto; iph->tos = tos; iph->daddr = tuple->tun.src_v4.s_addr; @@ -628,81 +650,91 @@ static int nf_flow_tunnel_ipip_push(struct net *net, struct sk_buff *skb, __ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1); ip_send_check(iph); - *ip_daddr = tuple->tun.src_v4.s_addr; + *ip_addr = (union nf_inet_addr *)&tuple->tun.src_v4; return 0; } -static int nf_flow_tunnel_v4_push(struct net *net, struct sk_buff *skb, - struct flow_offload_tuple *tuple, - struct dst_entry *dst, __be32 *ip_daddr) +static int nf_flow_tunnel_ip6_push(struct net *net, struct sk_buff *skb, + struct flow_offload_tuple *tuple, + struct dst_entry *dst, + union nf_inet_addr **ip_addr) { - if (tuple->tun_num) - return nf_flow_tunnel_ipip_push(net, skb, tuple, dst, ip_daddr); - - return 0; -} - -static int nf_flow_tunnel_ip6ip6_push(struct net *net, struct sk_buff *skb, - struct flow_offload_tuple *tuple, - struct dst_entry *dst, - struct in6_addr **ip6_daddr) -{ - struct ipv6hdr *ip6h = (struct ipv6hdr *)skb_network_header(skb); - __u8 dsfield = ipv6_get_dsfield(ip6h); - struct rtable *rt = dst_rtable(dst); struct flowi6 fl6 = { .daddr = tuple->tun.src_v6, .saddr = tuple->tun.dst_v6, - .flowi6_proto = IPPROTO_IPV6, + .flowi6_proto = tuple->tun.inner_proto, }; - u8 hop_limit = ip6h->hop_limit; + u8 hop_limit, dsfield; + struct ipv6hdr *ip6h; int err, mtu; u32 headroom; + switch (tuple->tun.inner_proto) { + case IPPROTO_IPIP: { + struct iphdr *iph = (struct iphdr *)skb_network_header(skb); + + dsfield = ipv4_get_dsfield(iph); + hop_limit = iph->ttl; + break; + } + case IPPROTO_IPV6: + ip6h = (struct ipv6hdr *)skb_network_header(skb); + dsfield = ipv6_get_dsfield(ip6h); + hop_limit = ip6h->hop_limit; + break; + default: + return 0; + } + err = iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6); if (err) return err; - skb_set_inner_ipproto(skb, IPPROTO_IPV6); - headroom = sizeof(*ip6h) + LL_RESERVED_SPACE(rt->dst.dev) + - rt->dst.header_len; + skb_set_inner_ipproto(skb, tuple->tun.inner_proto); + headroom = sizeof(*ip6h) + LL_RESERVED_SPACE(dst->dev) + + dst->header_len; err = skb_cow_head(skb, headroom); if (err) return err; skb_scrub_packet(skb, true); - mtu = dst_mtu(&rt->dst) - sizeof(*ip6h); + mtu = dst_mtu(dst) - sizeof(*ip6h); mtu = max(mtu, IPV6_MIN_MTU); skb_dst_update_pmtu_no_confirm(skb, mtu); skb_push(skb, sizeof(*ip6h)); skb_reset_network_header(skb); + skb->protocol = htons(ETH_P_IPV6); ip6h = ipv6_hdr(skb); ip6_flow_hdr(ip6h, dsfield, ip6_make_flowlabel(net, skb, fl6.flowlabel, true, &fl6)); ip6h->hop_limit = hop_limit; - ip6h->nexthdr = IPPROTO_IPV6; + ip6h->nexthdr = tuple->tun.inner_proto; ip6h->daddr = tuple->tun.src_v6; ip6h->saddr = tuple->tun.dst_v6; ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(*ip6h)); IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr); - *ip6_daddr = &tuple->tun.src_v6; + *ip_addr = (union nf_inet_addr *)&tuple->tun.src_v6; return 0; } -static int nf_flow_tunnel_v6_push(struct net *net, struct sk_buff *skb, - struct flow_offload_tuple *tuple, - struct dst_entry *dst, - struct in6_addr **ip6_daddr) +static int nf_flow_tunnel_push(struct net *net, struct sk_buff *skb, + struct flow_offload_tuple *tuple, + struct dst_entry *dst, + union nf_inet_addr **ip_addr) { - if (tuple->tun_num) - return nf_flow_tunnel_ip6ip6_push(net, skb, tuple, dst, ip6_daddr); - - return 0; + switch (tuple->tun.encap_proto) { + case AF_INET: + return nf_flow_tunnel_ip_push(net, skb, tuple, dst, ip_addr); + case AF_INET6: + return nf_flow_tunnel_ip6_push(net, skb, tuple, dst, ip_addr); + default: + return 0; + } } static int nf_flow_encap_push(struct sk_buff *skb, @@ -809,10 +841,10 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb, struct flow_offload_tuple *other_tuple; enum flow_offload_tuple_dir dir; struct nf_flow_xmit xmit = {}; + union nf_inet_addr *ip_addr; struct flow_offload *flow; struct neighbour *neigh; struct rtable *rt; - __be32 ip_daddr; if (unlikely(tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)) { rt = dst_rtable(tuplehash->tuple.dst_cache); @@ -825,10 +857,10 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb, dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); other_tuple = &flow->tuplehash[!dir].tuple; - ip_daddr = other_tuple->src_v4.s_addr; + ip_addr = (union nf_inet_addr *)&other_tuple->src_v4; - if (nf_flow_tunnel_v4_push(state->net, skb, other_tuple, - tuplehash->tuple.dst_cache, &ip_daddr) < 0) + if (nf_flow_tunnel_push(state->net, skb, other_tuple, + tuplehash->tuple.dst_cache, &ip_addr) < 0) return NF_DROP; switch (tuplehash->tuple.xmit_type) { @@ -839,7 +871,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb, flow_offload_teardown(flow); return NF_DROP; } - neigh = ip_neigh_gw4(rt->dst.dev, rt_nexthop(rt, ip_daddr)); + neigh = ip_neigh_gw4(rt->dst.dev, rt_nexthop(rt, ip_addr->ip)); if (IS_ERR(neigh)) { flow_offload_teardown(flow); return NF_DROP; @@ -1137,7 +1169,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb, struct flow_offload_tuple *other_tuple; enum flow_offload_tuple_dir dir; struct nf_flow_xmit xmit = {}; - struct in6_addr *ip6_daddr; + union nf_inet_addr *ip_addr; struct flow_offload *flow; struct neighbour *neigh; struct rt6_info *rt; @@ -1153,11 +1185,10 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb, dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); other_tuple = &flow->tuplehash[!dir].tuple; - ip6_daddr = &other_tuple->src_v6; + ip_addr = (union nf_inet_addr *)&other_tuple->src_v6; - if (nf_flow_tunnel_v6_push(state->net, skb, other_tuple, - tuplehash->tuple.dst_cache, - &ip6_daddr) < 0) + if (nf_flow_tunnel_push(state->net, skb, other_tuple, + tuplehash->tuple.dst_cache, &ip_addr) < 0) return NF_DROP; switch (tuplehash->tuple.xmit_type) { @@ -1168,7 +1199,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb, flow_offload_teardown(flow); return NF_DROP; } - neigh = ip_neigh_gw6(rt->dst.dev, rt6_nexthop(rt, ip6_daddr)); + neigh = ip_neigh_gw6(rt->dst.dev, rt6_nexthop(rt, &ip_addr->in6)); if (IS_ERR(neigh)) { flow_offload_teardown(flow); return NF_DROP; From 07bd391eb9572e74f073c49acef327611234f9bb Mon Sep 17 00:00:00 2001 From: Alok Tiwari Date: Sun, 11 Oct 2026 05:54:59 -0700 Subject: [PATCH 1877/2126] octeontx2-af: Fix CQ enable state tracking after AQ writes Use the CQ context's ena field when updating the CQ enable bitmap. The current code reads rq.ena, which overlaps bit 0 of the CQ base address and can leave the bitmap out of sync with the hardware context. This can cause enabled CQs to be skipped during teardown. Use sq.ena for the SQ bitmap update as well, so each queue type reads its own context. Fixes: 557dd485eaeb ("octeontx2-af: Support for disabling NIX RQ/SQ/CQ contexts") Signed-off-by: Alok Tiwari Reviewed-by: Ratheesh Kannoth Reviewed-by: Sunil Goutham Link: https://patch.msgid.link/20261011125508.534618-1-alok.a.tiwari@oracle.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c index 153eb57bad06..95f782d47927 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -1239,7 +1239,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw, __clear_bit(req->qidx, pfvf->rq_bmap); } if (req->ctype == NIX_AQ_CTYPE_SQ) { - ena = (req->rq.ena & req->sq_mask.ena) | + ena = (req->sq.ena & req->sq_mask.ena) | (test_bit(req->qidx, pfvf->sq_bmap) & ~req->sq_mask.ena); if (ena) @@ -1248,7 +1248,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw, __clear_bit(req->qidx, pfvf->sq_bmap); } if (req->ctype == NIX_AQ_CTYPE_CQ) { - ena = (req->rq.ena & req->cq_mask.ena) | + ena = (req->cq.ena & req->cq_mask.ena) | (test_bit(req->qidx, pfvf->cq_bmap) & ~req->cq_mask.ena); if (ena) From 48d522b65fb0ce2bd54f8f5838d77b48afcf1f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= Date: Sat, 22 Aug 2026 21:40:13 +0000 Subject: [PATCH 1878/2126] netfilter: nf_conntrack: avoid truncating IPv6 nexthdr offset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit find_prev_fhdr() returns the offset of the Next Header field before an IPv6 Fragment header through an int pointer, but stores the offset in a u8 local. An extension header chain can put this field beyond byte 255, causing the offset to wrap before it is saved in the fragment queue. Reassembly later uses the wrapped value to update the preceding Next Header field. This overwrites another byte in the IPv6 header chain and can make conntrack parse a different transport tuple from the one used by IPv6 local delivery. A two-fragment packet can, for example, be recorded as UDP destination port 53 while its payload is delivered to UDP port 9999. Use int for the working offset, matching the output argument and the other offset variables in this path. Fixes: 9fb9cbb1082d ("[NETFILTER]: Add nf_conntrack subsystem.") Assisted-by: Codex:gpt-5 Signed-off-by: Jérémy Jean Signed-off-by: Pablo Neira Ayuso --- net/ipv6/netfilter/nf_conntrack_reasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c index 599c49bf0a0a..be72c4346f8b 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c @@ -398,7 +398,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff) { u8 nexthdr = ipv6_hdr(skb)->nexthdr; const int netoff = skb_network_offset(skb); - u8 prev_nhoff = netoff + offsetof(struct ipv6hdr, nexthdr); + int prev_nhoff = netoff + offsetof(struct ipv6hdr, nexthdr); int start = netoff + sizeof(struct ipv6hdr); int len = skb->len - start; u8 prevhdr = NEXTHDR_IPV6; From c2226f0c7fe90b67732e5ae36dc5c3cc01ddf888 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Sat, 5 Sep 2026 07:01:50 +0200 Subject: [PATCH 1879/2126] netfilter: nft_payload: restrict checksum offsets to known values We need to prevent userspace from corrupting e.g. tcp->doff, because many locations in conntrack and conntrack helpers rely on nf_conntrack_in() having validated the packet headers. nft_payload allows to alter headers later which invalidates this assumption. The 'Fixes' commit restricts writes to safe fields, but there is another side channel: the checksum location. Restrict this too. Reported via sashiko/gemini. Fixes: 112e447d17f7 ("netfilter: validate L4 headers after userspace packet writes") Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_payload.c | 40 ++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c index e315d35f73d4..5b76af68b704 100644 --- a/net/netfilter/nft_payload.c +++ b/net/netfilter/nft_payload.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1008,11 +1009,14 @@ static bool nft_payload_validate_inet_csum_offset(const struct nft_ctx *ctx, if (priv->csum_flags) /* makes no sense, asks for "re-update" of L4 checksum */ return false; - /* no further check here; offset can't be negative so bogus - * offsets can corrupt L4 or payload but not l3 headers. - * We already allow arbitrary l4/inner payload writes. - */ - return true; + /* Validate csum_offset is one of the supported transport header checksums */ + if (priv->csum_offset == offsetof(struct tcphdr, check) || + priv->csum_offset == offsetof(struct udphdr, check) || + priv->csum_offset == offsetof(struct icmphdr, checksum) || + priv->csum_offset == offsetof(struct icmp6hdr, icmp6_cksum)) + return true; + + return false; case NFT_PAYLOAD_INNER_HEADER: return true; case NFT_PAYLOAD_TUN_HEADER: @@ -1046,6 +1050,27 @@ static bool nft_payload_csum_nh_write_ok(const struct nft_payload_set *priv, return false; } +static bool nft_payload_csum_th_write_ok(const struct nft_payload_set *priv, + const struct nft_pktinfo *pkt) +{ + if (!(pkt->flags & NFT_PKTINFO_L4PROTO)) + return false; + + switch (pkt->tprot) { + case IPPROTO_TCP: + return priv->csum_offset == offsetof(struct tcphdr, check); + case IPPROTO_UDP: + case IPPROTO_UDPLITE: + return priv->csum_offset == offsetof(struct udphdr, check); + case IPPROTO_ICMPV6: + return priv->csum_offset == offsetof(struct icmp6hdr, icmp6_cksum); + case IPPROTO_ICMP: + return priv->csum_offset == offsetof(struct icmphdr, checksum); + } + + return false; +} + static bool nft_payload_csum_write_ok(const struct nft_pktinfo *pkt, const struct nft_payload_set *priv) { @@ -1055,9 +1080,10 @@ static bool nft_payload_csum_write_ok(const struct nft_pktinfo *pkt, case NFT_PAYLOAD_NETWORK_HEADER: return nft_payload_csum_nh_write_ok(priv, pkt); case NFT_PAYLOAD_TRANSPORT_HEADER: + return nft_payload_csum_th_write_ok(priv, pkt); case NFT_PAYLOAD_INNER_HEADER: - /* neither offsets are validated, offsets cannot be - * negative so real l3 headers cannot be mangled. + /* offset is not validated, offset cannot be + * negative so real l3/l4 headers cannot be mangled. */ return true; case NFT_PAYLOAD_TUN_HEADER: From 3ba20137287f4f34ddbf0afb53c5d1ba03b6a8c2 Mon Sep 17 00:00:00 2001 From: Julian Anastasov Date: Mon, 7 Sep 2026 21:34:53 +0300 Subject: [PATCH 1880/2126] ipvs: fix more races around the overload flag Sashiko warns that we still have races when the dest overload thresholds are updated. If we narrow the range between thresholds the lockless readers (ip_vs_bind_dest and ip_vs_unbind_dest) may use old threshold values and as result to skip the required flag change. To solve the problem ip_vs_bind_dest() and ip_vs_unbind_dest() will have the chance as before to change the overload state not only at the exact threshold positions but at any conn count below the lower and above the upper thresholds. To make it work without entering the locked region for every connection, we introduce l_threshold_val. Together with u_threshold_val we will switch between two states: 1. not overloaded: where l_threshold_val is set to 0 to close the door for more ip_vs_unbind_dest() calls to clear the overload state. 2. overloaded: where u_threshold_val is set to INT_MAX to close the door for more ip_vs_bind_dest() calls to set the overload state. If a race occurs, multiple CPUs can repeat the state change but this should be for short time window. With the introduction of l_threshold_val the IP_VS_DEST_F_OVERLOAD flag and the 'flags' field are not needed anymore. We will use the ip_vs_dest_is_overloaded() helper for all places that read the overload state. Do not check IP_VS_DEST_CF_AVAILABLE in ip_vs_dh.c because we do not hold reference to dest after it is removed and rely on RCU to access the available dests. To reduce the cacheline accesses while selecting destination, keep the mostly used fields (weight and l_threshold_val) at the first read-mostly cacheline together with the hash nodes. Fixes: 8f843441c4e7 ("ipvs: properly update the overload flag on dest edit") Link: https://sashiko.dev/#/patchset/20260810190621.894119-1-pablo%40netfilter.org Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- include/net/ip_vs.h | 50 ++++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_conn.c | 8 ++--- net/netfilter/ipvs/ip_vs_ctl.c | 38 ++++++++++++------------ net/netfilter/ipvs/ip_vs_dh.c | 16 ++-------- net/netfilter/ipvs/ip_vs_fo.c | 2 +- net/netfilter/ipvs/ip_vs_lblc.c | 4 +-- net/netfilter/ipvs/ip_vs_lblcr.c | 8 ++--- net/netfilter/ipvs/ip_vs_lc.c | 2 +- net/netfilter/ipvs/ip_vs_mh.c | 2 +- net/netfilter/ipvs/ip_vs_nq.c | 2 +- net/netfilter/ipvs/ip_vs_ovf.c | 2 +- net/netfilter/ipvs/ip_vs_rr.c | 2 +- net/netfilter/ipvs/ip_vs_sed.c | 4 +-- net/netfilter/ipvs/ip_vs_sh.c | 2 +- net/netfilter/ipvs/ip_vs_twos.c | 4 +-- net/netfilter/ipvs/ip_vs_wlc.c | 4 +-- net/netfilter/ipvs/ip_vs_wrr.c | 2 +- 17 files changed, 76 insertions(+), 76 deletions(-) diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index 32fde731bceb..9a83bff32569 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h @@ -36,9 +36,6 @@ #define IP_VS_HDR_INVERSE 1 #define IP_VS_HDR_ICMP 2 -/* Destination Server Flags */ -#define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */ - /* Destination Server Config Flags */ #define IP_VS_DEST_CF_AVAILABLE 0x0001 /* server is available */ @@ -973,33 +970,44 @@ struct ip_vs_dest_dst { * and so on. */ struct ip_vs_dest { + /* Cacheline for hash table nodes - read-mostly */ + struct list_head n_list; /* for the dests in the service */ struct hlist_node d_list; /* for table with all the dests */ - u16 af; /* address family */ - __be16 port; /* port number of the server */ - union nf_inet_addr addr; /* IP address of the server */ - volatile unsigned int flags; /* dest status flags */ - atomic_t conn_flags; /* flags to copy to conn */ atomic_t weight; /* server weight */ - unsigned long cflags; /* config flags */ atomic_t last_weight; /* server latest weight */ + + /* connection thresholds */ + u32 l_threshold_val;/* used lower threshold */ + u32 u_threshold_val;/* used upper threshold */ + /* 32/48 */ + u32 l_threshold; /* lower threshold */ + u32 u_threshold; /* upper threshold */ + + unsigned long cflags; /* config flags */ + + /* 44/64 */ + atomic_t conn_flags; /* flags to copy to conn */ + __u16 tun_type; /* tunnel type */ __be16 tun_port; /* tunnel port */ __u16 tun_flags; /* tunnel flags */ + u16 af; /* address family */ + __be16 port; /* port number of the server */ + /* 60/80 */ + union nf_inet_addr addr; /* IP address of the server */ + + /* connection counters */ + atomic_t totalconns; /* total connections */ + atomic_t activeconns; /* active connections */ + atomic_t persistconns; /* persistent connections */ + refcount_t refcnt; /* reference counter */ struct ip_vs_stats stats; /* statistics */ unsigned long idle_start; /* start time, jiffies */ - /* connection counters and thresholds */ - atomic_t activeconns; /* active connections */ - atomic_t totalconns; /* total connections */ - atomic_t persistconns; /* persistent connections */ - __u32 u_threshold; /* upper threshold */ - __u32 l_threshold; /* lower threshold */ - __u32 l_threshold_val;/* used lower threshold */ - /* for destination cache */ spinlock_t dst_lock; /* lock of dst_cache */ struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */ @@ -1915,7 +1923,13 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) kfree(dest); } -void ip_vs_dest_update_overload(struct ip_vs_dest *dest, int mode); +void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload); + +/* Check if dest is in overloaded state */ +static inline bool ip_vs_dest_is_overloaded(const struct ip_vs_dest *dest) +{ + return READ_ONCE(dest->l_threshold_val); +} /* IPVS sync daemon data and function prototypes * (from ip_vs_sync.c) diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index cb009208826f..94f25fb7d87e 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -1153,8 +1153,8 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest) if (!(flags & IP_VS_CONN_F_INACTIVE)) atomic_inc(&dest->activeconns); tc = atomic_inc_return(&dest->totalconns); - if (tc == READ_ONCE(dest->u_threshold)) - ip_vs_dest_update_overload(dest, 1); + if (tc >= READ_ONCE(dest->u_threshold_val)) + ip_vs_dest_update_overload(dest, true); } else { /* It is a persistent connection/template, so increase the persistent connection counter */ @@ -1246,8 +1246,8 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp) if (!(cp->flags & IP_VS_CONN_F_INACTIVE)) atomic_dec(&dest->activeconns); tc = atomic_fetch_dec(&dest->totalconns); - if (tc == READ_ONCE(dest->l_threshold_val)) - ip_vs_dest_update_overload(dest, -1); + if (tc <= READ_ONCE(dest->l_threshold_val)) + ip_vs_dest_update_overload(dest, false); } else { /* It is a persistent connection/template, so decrease the persistent connection counter */ diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 4c1c739446b7..3003547dcabe 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -1309,32 +1309,32 @@ void ip_vs_stats_free(struct ip_vs_stats *stats) * - conns reach u_threshold and exceed it: set the flag * - conns go below l_threshold (or 75% of u_threshold): clear the flag */ -static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, int mode) +static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload) { int conns; u32 l, u; lockdep_assert_held(&dest->dst_lock); u = READ_ONCE(dest->u_threshold); - if (!u) - goto unset; - l = READ_ONCE(dest->l_threshold_val); - conns = atomic_read(&dest->totalconns); - if (conns >= (mode > 0 ? l : u)) { - dest->flags |= IP_VS_DEST_F_OVERLOAD; - return; + if (u) { + /* Low threshold defaults to 75% of upper threshold */ + l = READ_ONCE(dest->l_threshold) ? : (u - (u >> 2)); + conns = atomic_read(&dest->totalconns); + if (conns >= (overload ? l : u)) { + WRITE_ONCE(dest->u_threshold_val, INT_MAX); + WRITE_ONCE(dest->l_threshold_val, l); + return; + } } - if (conns >= (mode < 0 ? u : l)) - return; -unset: - dest->flags &= ~IP_VS_DEST_F_OVERLOAD; + WRITE_ONCE(dest->u_threshold_val, u ? : INT_MAX); + WRITE_ONCE(dest->l_threshold_val, 0); } -void ip_vs_dest_update_overload(struct ip_vs_dest *dest, int mode) +void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload) { spin_lock_bh(&dest->dst_lock); - __ip_vs_dest_update_overload(dest, mode); + __ip_vs_dest_update_overload(dest, overload); spin_unlock_bh(&dest->dst_lock); } @@ -1406,15 +1406,13 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, if (READ_ONCE(dest->u_threshold) != udest->u_threshold || READ_ONCE(dest->l_threshold) != udest->l_threshold) { + bool overload; + spin_lock_bh(&dest->dst_lock); WRITE_ONCE(dest->u_threshold, udest->u_threshold); WRITE_ONCE(dest->l_threshold, udest->l_threshold); - /* Low threshold defaults to 75% of upper threshold */ - WRITE_ONCE(dest->l_threshold_val, - udest->l_threshold ? : - (udest->u_threshold - - (udest->u_threshold >> 2))); - __ip_vs_dest_update_overload(dest, 0); + overload = ip_vs_dest_is_overloaded(dest); + __ip_vs_dest_update_overload(dest, overload); spin_unlock_bh(&dest->dst_lock); } diff --git a/net/netfilter/ipvs/ip_vs_dh.c b/net/netfilter/ipvs/ip_vs_dh.c index 43abed7a26a6..95e52950adbb 100644 --- a/net/netfilter/ipvs/ip_vs_dh.c +++ b/net/netfilter/ipvs/ip_vs_dh.c @@ -195,16 +195,6 @@ static int ip_vs_dh_dest_changed(struct ip_vs_service *svc, } -/* - * If the dest flags is set with IP_VS_DEST_F_OVERLOAD, - * consider that the server is overloaded here. - */ -static inline int is_overloaded(struct ip_vs_dest *dest) -{ - return dest->flags & IP_VS_DEST_F_OVERLOAD; -} - - /* * Destination hashing scheduling */ @@ -219,10 +209,8 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, s = (struct ip_vs_dh_state *) svc->sched_data; dest = ip_vs_dh_get(svc->af, s, &iph->daddr); - if (!dest || - !(dest->cflags & IP_VS_DEST_CF_AVAILABLE) - || atomic_read(&dest->weight) <= 0 - || is_overloaded(dest)) { + if (!dest || atomic_read(&dest->weight) <= 0 || + ip_vs_dest_is_overloaded(dest)) { ip_vs_scheduler_err(svc, "no destination available"); return NULL; } diff --git a/net/netfilter/ipvs/ip_vs_fo.c b/net/netfilter/ipvs/ip_vs_fo.c index d657b47c6511..e07fa33f6d52 100644 --- a/net/netfilter/ipvs/ip_vs_fo.c +++ b/net/netfilter/ipvs/ip_vs_fo.c @@ -29,7 +29,7 @@ ip_vs_fo_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, * Find virtual server with highest weight and send it traffic */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && + if (!ip_vs_dest_is_overloaded(dest) && atomic_read(&dest->weight) > hw) { hweight = dest; hw = atomic_read(&dest->weight); diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c index 55af77a56929..e1111c3b2721 100644 --- a/net/netfilter/ipvs/ip_vs_lblc.c +++ b/net/netfilter/ipvs/ip_vs_lblc.c @@ -418,7 +418,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc) * new connection. */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; if (atomic_read(&dest->weight) > 0) { least = dest; @@ -433,7 +433,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc) */ nextstage: list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; doh = ip_vs_dest_conn_overhead(dest); diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c index 858393b1d2d1..dfb5bf83750d 100644 --- a/net/netfilter/ipvs/ip_vs_lblcr.c +++ b/net/netfilter/ipvs/ip_vs_lblcr.c @@ -166,7 +166,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) /* select the first destination server, whose weight > 0 */ list_for_each_entry_rcu(e, &set->list, list) { least = e->dest; - if (least->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(least)) continue; if ((atomic_read(&least->weight) > 0) && @@ -181,7 +181,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) nextstage: list_for_each_entry_continue_rcu(e, &set->list, list) { dest = e->dest; - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; doh = ip_vs_dest_conn_overhead(dest); @@ -580,7 +580,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc) * new connection. */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; if (atomic_read(&dest->weight) > 0) { @@ -596,7 +596,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc) */ nextstage: list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; doh = ip_vs_dest_conn_overhead(dest); diff --git a/net/netfilter/ipvs/ip_vs_lc.c b/net/netfilter/ipvs/ip_vs_lc.c index 18b976a7c4d2..9002f491bff6 100644 --- a/net/netfilter/ipvs/ip_vs_lc.c +++ b/net/netfilter/ipvs/ip_vs_lc.c @@ -38,7 +38,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if ((dest->flags & IP_VS_DEST_F_OVERLOAD) || + if (ip_vs_dest_is_overloaded(dest) || atomic_read(&dest->weight) == 0) continue; doh = ip_vs_dest_conn_overhead(dest); diff --git a/net/netfilter/ipvs/ip_vs_mh.c b/net/netfilter/ipvs/ip_vs_mh.c index 020863047562..d70b23aec5fe 100644 --- a/net/netfilter/ipvs/ip_vs_mh.c +++ b/net/netfilter/ipvs/ip_vs_mh.c @@ -80,7 +80,7 @@ static inline void generate_hash_secret(hsiphash_key_t *hash1, static inline bool is_unavailable(struct ip_vs_dest *dest) { return atomic_read(&dest->weight) <= 0 || - dest->flags & IP_VS_DEST_F_OVERLOAD; + ip_vs_dest_is_overloaded(dest); } /* Returns hash value for IPVS MH entry */ diff --git a/net/netfilter/ipvs/ip_vs_nq.c b/net/netfilter/ipvs/ip_vs_nq.c index ada158c610ce..7cc28902086e 100644 --- a/net/netfilter/ipvs/ip_vs_nq.c +++ b/net/netfilter/ipvs/ip_vs_nq.c @@ -72,7 +72,7 @@ ip_vs_nq_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD || + if (ip_vs_dest_is_overloaded(dest) || !atomic_read(&dest->weight)) continue; diff --git a/net/netfilter/ipvs/ip_vs_ovf.c b/net/netfilter/ipvs/ip_vs_ovf.c index c5c67df80a0b..eaa3a7ae6efa 100644 --- a/net/netfilter/ipvs/ip_vs_ovf.c +++ b/net/netfilter/ipvs/ip_vs_ovf.c @@ -33,7 +33,7 @@ ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { w = atomic_read(&dest->weight); - if ((dest->flags & IP_VS_DEST_F_OVERLOAD) || + if (ip_vs_dest_is_overloaded(dest) || atomic_read(&dest->activeconns) > w || w == 0) continue; diff --git a/net/netfilter/ipvs/ip_vs_rr.c b/net/netfilter/ipvs/ip_vs_rr.c index 4125ee561cdc..bd17cdd092f5 100644 --- a/net/netfilter/ipvs/ip_vs_rr.c +++ b/net/netfilter/ipvs/ip_vs_rr.c @@ -66,7 +66,7 @@ ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { - if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && + if (!ip_vs_dest_is_overloaded(dest) && atomic_read(&dest->weight) > 0) /* HIT */ goto out; diff --git a/net/netfilter/ipvs/ip_vs_sed.c b/net/netfilter/ipvs/ip_vs_sed.c index 245a323c84cd..7925f4d28fce 100644 --- a/net/netfilter/ipvs/ip_vs_sed.c +++ b/net/netfilter/ipvs/ip_vs_sed.c @@ -75,7 +75,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && + if (!ip_vs_dest_is_overloaded(dest) && atomic_read(&dest->weight) > 0) { least = dest; loh = ip_vs_sed_dest_overhead(least); @@ -90,7 +90,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, */ nextstage: list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; doh = ip_vs_sed_dest_overhead(dest); if ((__s64)loh * atomic_read(&dest->weight) > diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c index cd67066e3b26..c24dd5cb7e47 100644 --- a/net/netfilter/ipvs/ip_vs_sh.c +++ b/net/netfilter/ipvs/ip_vs_sh.c @@ -73,7 +73,7 @@ struct ip_vs_sh_state { static inline bool is_unavailable(struct ip_vs_dest *dest) { return atomic_read(&dest->weight) <= 0 || - dest->flags & IP_VS_DEST_F_OVERLOAD; + ip_vs_dest_is_overloaded(dest); } /* diff --git a/net/netfilter/ipvs/ip_vs_twos.c b/net/netfilter/ipvs/ip_vs_twos.c index dbb7f5fd4688..86186122a1f0 100644 --- a/net/netfilter/ipvs/ip_vs_twos.c +++ b/net/netfilter/ipvs/ip_vs_twos.c @@ -52,7 +52,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc, /* Generate a random weight between [0,sum of all weights) */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (!(dest->flags & IP_VS_DEST_F_OVERLOAD)) { + if (!ip_vs_dest_is_overloaded(dest)) { weight = atomic_read(&dest->weight); if (weight > 0) { total_weight += weight; @@ -75,7 +75,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc, /* Pick two weighted servers */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; weight = atomic_read(&dest->weight); diff --git a/net/netfilter/ipvs/ip_vs_wlc.c b/net/netfilter/ipvs/ip_vs_wlc.c index 9da445ca09a1..08e9e22f72bf 100644 --- a/net/netfilter/ipvs/ip_vs_wlc.c +++ b/net/netfilter/ipvs/ip_vs_wlc.c @@ -47,7 +47,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, */ list_for_each_entry_rcu(dest, &svc->destinations, n_list) { - if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && + if (!ip_vs_dest_is_overloaded(dest) && atomic_read(&dest->weight) > 0) { least = dest; loh = ip_vs_dest_conn_overhead(least); @@ -62,7 +62,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, */ nextstage: list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { - if (dest->flags & IP_VS_DEST_F_OVERLOAD) + if (ip_vs_dest_is_overloaded(dest)) continue; doh = ip_vs_dest_conn_overhead(dest); if ((__s64)loh * atomic_read(&dest->weight) > diff --git a/net/netfilter/ipvs/ip_vs_wrr.c b/net/netfilter/ipvs/ip_vs_wrr.c index 2dcff1040da5..fad69bae5a22 100644 --- a/net/netfilter/ipvs/ip_vs_wrr.c +++ b/net/netfilter/ipvs/ip_vs_wrr.c @@ -176,7 +176,7 @@ ip_vs_wrr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { - if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && + if (!ip_vs_dest_is_overloaded(dest) && atomic_read(&dest->weight) >= mark->cw) goto found; if (dest == stop) From 7f1a04254a05e14845ff3d377931f941f62e41d5 Mon Sep 17 00:00:00 2001 From: Joel Granados Date: Tue, 22 Sep 2026 11:08:13 +0200 Subject: [PATCH 1881/2126] ipvs: skip committing sync_threshold when proc_dointvec fails Forward rc value and skip updating sysctl_sync_threshold when proc_dointvec fails. This targets a write such as "5 x" which would fail with -EINVAL but would store the first element anyway. Signed-off-by: Joel Granados Acked-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_ctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 3003547dcabe..ce9fe20d6106 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -2452,6 +2452,8 @@ proc_do_sync_threshold(const struct ctl_table *table, int write, mutex_lock(&ipvs->sync_mutex); memcpy(val, valp, sizeof(val)); rc = proc_dointvec(&tmp, write, buffer, lenp, ppos); + if (rc) + goto out; if (write) { if (val[0] < 0 || val[1] < 0 || (val[0] >= val[1] && val[1])) @@ -2459,6 +2461,7 @@ proc_do_sync_threshold(const struct ctl_table *table, int write, else memcpy(valp, val, sizeof(val)); } +out: mutex_unlock(&ipvs->sync_mutex); return rc; } From c203ecf905745d979de5df28fa657121f2e9342d Mon Sep 17 00:00:00 2001 From: Shuangfeng He Date: Fri, 2 Oct 2026 16:42:53 +0800 Subject: [PATCH 1882/2126] netfilter: flowtable: use the vlan id, not the full tci, in the tuple key nf_flow_tuple_encap() stores the skb vlan tag in the encap tuple id using skb_vlan_tag_get(), which returns the unmasked TCI including the 3 PCP priority bits. The flowtable entry, however, is programmed by nf_dev_path_info() with vlan_dev_vlan_id(), a plain 12-bit VID. When a NIC delivers RX vlan offload skbs with a non-zero priority (an RTL9617C EPON ONU was observed handing over vid 818 skbs with tci 0x6332, PCP 3), the runtime lookup key never matches the programmed entry, so every packet misses the flow table and software flow offload is silently defeated. Mask both parse sites to the 12-bit VID so the lookup key matches for any priority. The in-header variant has the same problem for frames received with PCP != 0 on a non-offload path. The egress side is unaffected: nf_flow_encap_push() restores tags from the programmed tuple id, which never carried priority bits. Measured on an RTL9617C ONU (PPPoE over VLAN 818 WAN, NATed 6-flow download over a 1G EPON line), before -> after: download throughput 377 Mbps -> 936 Mbps CPU0 %soft at that rate 91.5% -> 70.9% Fixes: 4cd91f7c290f ("netfilter: flowtable: add vlan support") Signed-off-by: Shuangfeng He Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_flow_table_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index c8c29a9a1684..2dec15d402ca 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -170,14 +170,14 @@ static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx, int i = 0; if (skb_vlan_tag_present(skb)) { - tuple->encap[i].id = skb_vlan_tag_get(skb); + tuple->encap[i].id = skb_vlan_tag_get_id(skb); tuple->encap[i].proto = skb->vlan_proto; i++; } switch (skb->protocol) { case htons(ETH_P_8021Q): veth = (struct vlan_ethhdr *)skb_mac_header(skb); - tuple->encap[i].id = ntohs(veth->h_vlan_TCI); + tuple->encap[i].id = ntohs(veth->h_vlan_TCI) & VLAN_VID_MASK; tuple->encap[i].proto = skb->protocol; offset += VLAN_HLEN; break; From 73a73d442f9986353fe284bd1b504d0313d0f153 Mon Sep 17 00:00:00 2001 From: Kyle Zeng Date: Wed, 7 Oct 2026 23:01:00 +0200 Subject: [PATCH 1883/2126] netfilter: nf_reject: initialize IPCB at inet ingress The inet ingress hook runs before ip_rcv_core() and ip6_rcv_core(), so neither IPCB nor IP6CB has been initialized when nft_reject_inet passes a packet to nf_send_unreach() or nf_send_unreach6(). skb->cb can therefore retain metadata from an earlier protocol layer. For IPv4, icmp_send() treats IPCB(skb)->opt as parsed IPv4 options. Stale option offsets can make __ip_options_echo() copy an attacker-controlled length into its 40-byte reply option buffer and overflow the stack. On an unpatched v7.2-rc5 kernel, the IPv4 reproducer produced: BUG: KASAN: stack-out-of-bounds in __ip_options_echo() Write of size 255 For IPv6, icmpv6_send() consumes IP6CB(skb) as parsed IPv6 metadata. It always uses iif for source selection and, when MIP6 is enabled, uses dsthao as an extension-header offset. These fields must not be stale. For NF_INET_INGRESS, clear the address-family-specific control block and restore its input interface before constructing the ICMP error. This matches similar initialization normally performed by ip_rcv_core() and ip6_rcv_core(). Fixes: 117ca1f8920c ("netfilter: nft_reject_inet: allow to use reject from inet ingress") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.6-sol Codex:gpt-5.5-cyber Signed-off-by: Kyle Zeng Co-developed-by: David Lee Signed-off-by: David Lee Signed-off-by: Pablo Neira Ayuso --- net/ipv4/netfilter/nf_reject_ipv4.c | 5 +++++ net/ipv6/netfilter/nf_reject_ipv6.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c index 59ec465a9df9..7cb33af671e2 100644 --- a/net/ipv4/netfilter/nf_reject_ipv4.c +++ b/net/ipv4/netfilter/nf_reject_ipv4.c @@ -357,6 +357,11 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook) if (!skb_valid_dst(skb_in) && nf_reject_fill_skb_dst(skb_in) < 0) return; + if (hook == NF_INET_INGRESS) { + memset(IPCB(skb_in), 0, sizeof(*IPCB(skb_in))); + IPCB(skb_in)->iif = skb_in->skb_iif; + } + if (skb_csum_unnecessary(skb_in) || !nf_reject_verify_csum(skb_in, dataoff, proto)) { icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0); diff --git a/net/ipv6/netfilter/nf_reject_ipv6.c b/net/ipv6/netfilter/nf_reject_ipv6.c index 07cdaa10da0d..5e08d8529cc8 100644 --- a/net/ipv6/netfilter/nf_reject_ipv6.c +++ b/net/ipv6/netfilter/nf_reject_ipv6.c @@ -444,6 +444,11 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in, if (hooknum == NF_INET_LOCAL_OUT && skb_in->dev == NULL) skb_in->dev = net->loopback_dev; + if (hooknum == NF_INET_INGRESS) { + memset(IP6CB(skb_in), 0, sizeof(*IP6CB(skb_in))); + IP6CB(skb_in)->iif = skb_in->skb_iif; + } + if (!skb_valid_dst(skb_in) && nf_reject6_fill_skb_dst(skb_in) < 0) return; From 86d47d4c84a1b8470ba3fc16df13ea2a220b74ff Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Wed, 7 Oct 2026 23:51:44 +0200 Subject: [PATCH 1884/2126] netfilter: nft_set_rbtree: narrow down range completion to anonymous sets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For anonymous sets, when adjacent ranges are found, the end element is not added to the set to pack the set representation. Use next start element to complete this interval. Jérémy Jean says: Consider two ranges in a netfilter verdict map: * keys 10-19 accept packets, and * keys 30-39 jump to chain 'victim'. Now, delete the end marker at 20. The lookup array now uses element 30 as the first range's end, so an INTERVAL_END query for key 15 returns element 30, including its jump verdict and chain pointer. This can make KASAN reports a UAF after the GC releases reference chain for 30 that has expired: BUG: KASAN: slab-use-after-free in nft_verdict_dump+0xdd/0x110 Read of size 8 at addr ff110000009dfb58 by task repro/50 ... Call Trace: ... nft_verdict_dump+0xdd/0x110 nft_data_dump+0x4d/0x80 nf_tables_fill_setelem+0x30b/0x8a0 ? __asan_memcpy+0x3c/0x60 nf_tables_fill_setelem_info+0x1b0/0x200 nft_get_set_elem+0x3fd/0x4b0 ... Freed by task 24: ... kfree+0x1a5/0x280 nf_tables_trans_destroy_work+0x2cb/0x520 Fixes: 2aa34191f06f ("netfilter: nft_set_rbtree: use binary search array in get command") Reported-by: Jérémy Jean Link: https://patch.msgid.link/netfilter-devel/20261005200404.3544062-2-Jeremy.Jean@oss.cyber.gouv.fr/ Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_set_rbtree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nft_set_rbtree.c b/net/netfilter/nft_set_rbtree.c index 12431b55752f..fbe1750f1ca2 100644 --- a/net/netfilter/nft_set_rbtree.c +++ b/net/netfilter/nft_set_rbtree.c @@ -1091,7 +1091,8 @@ static void nft_rbtree_commit(struct nft_set *set) * representation. Use next start element to complete this * interval. */ - if (nft_rbtree_interval_start(rbe) && + if (nft_set_is_anonymous(set) && + nft_rbtree_interval_start(rbe) && nft_rbtree_interval_start(prev_rbe) && priv->array_next->intervals[num_intervals].from) priv->array_next->intervals[num_intervals++].to = &prev_rbe->ext; From 2edda78aa4eb04cd8f112a81897510ee0cdd7099 Mon Sep 17 00:00:00 2001 From: Sung Byeongchan Date: Fri, 9 Oct 2026 03:38:14 +0900 Subject: [PATCH 1885/2126] netfilter: xt_dccp: handle reserved options as single-byte The DCCP UAPI defines option numbers 3 through 31 as reserved. Like Padding and Mandatory, these options occupy one byte. dccp_find_option() only treats values below 2 as single-byte and interprets the byte after a reserved option as a TLV length. This can skip a later option and invert an XT_DCCP_OPTION rule result. A local production-hook fixture installed the same DROP rule for IPv4 and IPv6. In three fresh boots per kernel, a target-only packet was dropped 20/20 times, while adding reserved option 3 before the same target let 20/20 packets reach the protected receiver. The fixed kernel dropped all trigger packets in three fresh boots and preserved the normal controls. Treat every option up to DCCPO_MAX_RESERVED as single-byte, matching the protocol definition. Triggering requires CONFIG_NETFILTER_XTABLES_LEGACY, CONFIG_NETFILTER_XT_MATCH_DCCP, an option-based rule, and remote protocol-33 reachability. The touched source is unchanged at 0c2669a9f4a1d607e7591ae50ccf3c432a0aff08, where the patch applies and builds cleanly. Fixes: 1d3de414eb20 ("[NETFILTER]: New iptables DCCP protocol header match") Assisted-by: LLM Signed-off-by: Sung Byeongchan Signed-off-by: Pablo Neira Ayuso --- net/netfilter/xt_dccp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c index 3db81e041af9..23a4e3e8df7d 100644 --- a/net/netfilter/xt_dccp.c +++ b/net/netfilter/xt_dccp.c @@ -62,7 +62,7 @@ dccp_find_option(u_int8_t option, return true; } - if (op[i] < 2 || i == optlen - 1) + if (op[i] <= DCCPO_MAX_RESERVED || i == optlen - 1) i++; else i += op[i + 1] ? : 1; From 08f7882637f2db5b98f521498eeaf94770383a6e Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Mon, 19 Oct 2026 11:54:03 +0200 Subject: [PATCH 1886/2126] netfilter: flowtable: reset transport header after nf_flow_encap_pop() nf_flow_encap_pop() pulls vlan/pppoe or ip tunnel headers and resets the network header, but leaves the transport header pointing into the removed outer header. Reset the transport header to the inner L4 header, otherwise later consumers (e.g. GSO segmentation) parse a bogus header. Fixes: 4cd91f7c290f ("netfilter: flowtable: add vlan support") Signed-off-by: Lorenzo Bianconi Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_flow_table_ip.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 2dec15d402ca..bb894c4f2b4a 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -502,6 +502,7 @@ static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, nf_flow_encap_pop(ctx, skb, tuplehash); thoff -= ctx->offset; + skb_set_transport_header(skb, thoff); iph = ip_hdr(skb); nf_flow_nat_ip(flow, skb, thoff, dir, iph); @@ -1097,6 +1098,7 @@ static int nf_flow_offload_ipv6_forward(struct nf_flowtable_ctx *ctx, flow_offload_refresh(flow_table, flow, false); nf_flow_encap_pop(ctx, skb, tuplehash); + skb_set_transport_header(skb, sizeof(*ip6h)); ip6h = ipv6_hdr(skb); nf_flow_nat_ipv6(flow, skb, dir, ip6h); From cd37ab22a74e05aae5c16c67295cbf5188b16268 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 19 Oct 2026 15:56:26 +0800 Subject: [PATCH 1887/2126] netfilter: nf_conntrack_netlink: fix inverted IPv6 tuple filter ctnetlink_filter_match_tuple() returns 0 (no match) when the IPv6 source or destination address differs from the filter, because the !ipv6_addr_cmp() test is inverted. ipv6_addr_cmp() returns 0 when the addresses are equal, so the negation makes the branch trigger on a match instead of a mismatch, which is the opposite of the IPv4 path above. Drop the '!' so the IPv6 branch returns 0 only when the addresses differ, matching the IPv4 semantics and the caller's expectation. Fixes: cb8aa9a3affb ("netfilter: ctnetlink: add kernel side filtering for dump") Cc: stable@vger.kernel.org Signed-off-by: Liu Chao Reviewed-by: Weibin Liu Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_netlink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 4e5d7c701436..cc8695d5356d 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -1098,13 +1098,13 @@ static int ctnetlink_filter_match_tuple(struct nf_conntrack_tuple *filter_tuple, break; case NFPROTO_IPV6: if ((flags & CTA_FILTER_FLAG(CTA_IP_SRC)) && - !ipv6_addr_cmp(&filter_tuple->src.u3.in6, - &ct_tuple->src.u3.in6)) + ipv6_addr_cmp(&filter_tuple->src.u3.in6, + &ct_tuple->src.u3.in6)) return 0; if ((flags & CTA_FILTER_FLAG(CTA_IP_DST)) && - !ipv6_addr_cmp(&filter_tuple->dst.u3.in6, - &ct_tuple->dst.u3.in6)) + ipv6_addr_cmp(&filter_tuple->dst.u3.in6, + &ct_tuple->dst.u3.in6)) return 0; break; } From 78731b46967e3e7102b5cd5062bef185f3404b5c Mon Sep 17 00:00:00 2001 From: Vaibhav Nagare Date: Mon, 12 Oct 2026 12:58:02 +0530 Subject: [PATCH 1888/2126] bnxt_en: don't leave an XDP program installed when the open fails bnxt_xdp_set() stores the new program and drops the reference on the old one before reopening the NIC. If bnxt_open_nic() then fails, ndo_bpf() returns an error with the new program still in bp->xdp_prog. The caller treats the error as "nothing was installed" and drops its own reference, so bp->xdp_prog is left pointing at a freed program and the next XDP update dereferences it: BUG: unable to handle page fault for address: ff78ecc80ddd1038 RIP: 0010:__bpf_prog_put+0x5/0x80 Call Trace: bnxt_xdp_set+0xad/0x1b0 [bnxt_en] dev_xdp_propagate+0x36/0xa0 bond_xdp_set+0xeb/0x2d0 [bonding] dev_xdp_install+0x1b1/0x350 bpf_xdp_link_update+0xc5/0x1b0 link_update+0x104/0x1e0 __sys_bpf+0x662/0xcf0 Seen on a 6.12 based kernel after bnxt_alloc_mem() failed an order-4 allocation on a fragmented host: bnxt_en 0000:a0:00.1 ens4f1np1: nic open fail (rc: fffffff4) bond1: (slave ens4f1np1): Error -12 calling ndo_bpf Bonding is not required to hit this; a plain XDP attach on a bnxt interface takes the same path. Restore the previous program when an attach or a replace fails, and recompute the page-mode and XDP TX ring configuration from it. The configuration matters because bnxt_init_one_rx_ring() only assigns rxr->xdp_prog in page mode, and __bnxt_set_rx_skb_mode() derives dev->max_mtu from the installed program. Release the old program only once the change has been committed. A detach is not undone. dev_xdp_detach_link() clears the core's record of the program even when the driver returns an error, so putting the program back would leave the driver running a program the core has already dropped. If the reopen fails during a detach, bnxt_xdp_set() therefore returns 0 with the device closed; bnxt_open_nic() has already logged the failure. Found in a crash dump; the change was not tested on hardware. Fixes: c6d30e8391b8 ("bnxt_en: Add basic XDP support.") Cc: stable@vger.kernel.org Signed-off-by: Vaibhav Nagare Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261012072802.2153706-1-vnagare@redhat.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c index 9e5009be8e98..96845c8646e0 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c @@ -381,11 +381,31 @@ int bnxt_xdp_xmit(struct net_device *dev, int num_frames, return nxmit; } +static void bnxt_xdp_apply_cfg(struct bnxt *bp, int tx_xdp) +{ + struct net_device *dev = bp->dev; + int tc = bp->num_tc ? : 1; + + if (bp->xdp_prog) { + bnxt_set_rx_skb_mode(bp, true); + xdp_features_set_redirect_target_locked(dev, true); + } else { + xdp_features_clear_redirect_target_locked(dev); + bnxt_set_rx_skb_mode(bp, false); + } + bp->tx_nr_rings_xdp = tx_xdp; + bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp; + bnxt_set_cp_rings(bp, true); + bnxt_set_tpa_flags(bp); + bnxt_set_ring_params(bp); +} + static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog) { struct net_device *dev = bp->dev; int tx_xdp = 0, rc, tc; struct bpf_prog *old; + int old_tx_xdp; netdev_assert_locked(dev); @@ -418,26 +438,23 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog) if (netif_running(dev)) bnxt_close_nic(bp, true, false); + old_tx_xdp = bp->tx_nr_rings_xdp; old = xchg(&bp->xdp_prog, prog); + bnxt_xdp_apply_cfg(bp, tx_xdp); + + if (netif_running(dev)) { + rc = bnxt_open_nic(bp, true, false); + /* a detach cannot be undone, only an attach */ + if (rc && prog) { + WRITE_ONCE(bp->xdp_prog, old); + bnxt_xdp_apply_cfg(bp, old_tx_xdp); + return rc; + } + } + if (old) bpf_prog_put(old); - if (prog) { - bnxt_set_rx_skb_mode(bp, true); - xdp_features_set_redirect_target_locked(dev, true); - } else { - xdp_features_clear_redirect_target_locked(dev); - bnxt_set_rx_skb_mode(bp, false); - } - bp->tx_nr_rings_xdp = tx_xdp; - bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp; - bnxt_set_cp_rings(bp, true); - bnxt_set_tpa_flags(bp); - bnxt_set_ring_params(bp); - - if (netif_running(dev)) - return bnxt_open_nic(bp, true, false); - return 0; } From ecb8b18051a1b928ade055fcdabc06186a89493f Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 13 Oct 2026 11:37:11 -0600 Subject: [PATCH 1889/2126] net: stmmac: unwind the WoL IRQ after a safety IRQ request failure The safety IRQ is requested after the MAC and optional WoL IRQs. If its request fails, stmmac_free_irq() frees the unregistered safety IRQ and leaks the WoL handler. This can warn about an already-free IRQ and make the next open fail. Move the safety and WoL cleanup labels into reverse acquisition order. This was found by code inspection while working on the stmmac MTU/resume recovery series. Injecting a safety IRQ request failure in QEMU with mocked MAC/DMA hardware reproduced the "Trying to free already-free IRQ" warning and leaked WoL handler. The failure has not been observed without fault injection. Signed-off-by: James Hilliard Reviewed-by: Nicolai Buchwitz Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261013-stmmac-irq-unwind-v3-1-fff4e2db805a@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 53782ab55e12..9477ba654946 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3821,13 +3821,13 @@ static void stmmac_free_irq(struct net_device *dev, free_irq(msi->sfty_ce_irq, dev); fallthrough; case REQ_IRQ_ERR_SFTY_CE: - if (priv->wol_irq > 0 && priv->wol_irq != dev->irq) - free_irq(priv->wol_irq, dev); - fallthrough; - case REQ_IRQ_ERR_SFTY: if (priv->sfty_irq > 0 && priv->sfty_irq != dev->irq) free_irq(priv->sfty_irq, dev); fallthrough; + case REQ_IRQ_ERR_SFTY: + if (priv->wol_irq > 0 && priv->wol_irq != dev->irq) + free_irq(priv->wol_irq, dev); + fallthrough; case REQ_IRQ_ERR_WOL: free_irq(dev->irq, dev); fallthrough; From 2d5c08ec1532547fd776e8171dee5d32a257e592 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Mon, 12 Oct 2026 17:24:39 +0200 Subject: [PATCH 1890/2126] net: stmmac: fix XDP TX DMA address for compound RX pages When RX buffers are compound pages (order > 0), only the head page carries the DMA address programmed by the page pool (page_pool_get_dma_addr()). stmmac_xdp_xmit_xdpf() computed the head buffer's bus address from the page that happens to contain the data: page = frag ? skb_frag_page(frag) : virt_to_page(xdpf->data); dma_addr = page_pool_get_dma_addr(page); ... RX pages become compound as soon as dma_buf_sz needs more than one page (pp_params.order = order_base_2(num_pages) > 0), which happens from an MTU around 3000 bytes once dma_buf_sz reaches 4096. If an XDP program moves the data forward with bpf_xdp_adjust_head() by more than about a page, xdpf->data points into a tail page whose struct page has no DMA address: page_pool_get_dma_addr() then returns a bogus bus address, and dma_sync_single_for_device() together with the TX descriptor transmit from the wrong location. Use virt_to_head_page() to read the DMA base of the buffer and keep the offset relative to the head page (sizeof(*xdpf) + xdpf->headroom), which is correct no matter which page the data ends up in. Signed-off-by: Lorenzo Bianconi Reviewed-by: Daniel Machon Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261012-stmmac-xdp-tx-pre-fixes-v1-1-05fd0c90f7e1@oss.qualcomm.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 9477ba654946..85076e917289 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5303,7 +5303,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue, struct page *page; page = frag ? skb_frag_page(frag) - : virt_to_page(xdpf->data); + : virt_to_head_page(xdpf->data); dma_addr = page_pool_get_dma_addr(page); if (frag) dma_addr += skb_frag_off(frag); From 667a375a5294b29f66b935d57a8b250e75d576ae Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Mon, 12 Oct 2026 17:24:40 +0200 Subject: [PATCH 1891/2126] net: stmmac: disable TX checksum offload for jumbo frames on bugged cores stmmac_xdp_xmit_xdpf() decides TX checksum insertion from the queue COE capability only: csum = !priv->plat->tx_queues_cfg[queue].coe_unsupported; and lets the enhanced descriptor set TX_CIC_FULL accordingly. On the bugged_jumbo cores (snps,dwmac-3.40a, snps,dwmac-3.610 and snps,dwmac-3.710) hardware checksum insertion is broken for jumbo frames; the skb path works around it by clearing NETIF_F_CSUM_MASK in stmmac_fix_features() when the MTU exceeds ETH_DATA_LEN, so skbs are never marked CHECKSUM_PARTIAL and no checksum is inserted. The XDP TX path bypasses that workaround, so once XDP is allowed at MTU > ETH_DATA_LEN, jumbo frames sent via XDP_TX or redirected into the device would leave the interface with a full checksum insertion enabled on those cores - exactly what the workaround is meant to avoid. Disable checksum insertion for oversized frames on bugged_jumbo cores in the XDP TX path too. Signed-off-by: Lorenzo Bianconi Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261012-stmmac-xdp-tx-pre-fixes-v1-2-05fd0c90f7e1@oss.qualcomm.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 85076e917289..3636449e1ffc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5278,6 +5278,14 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue, return STMMAC_XDP_CONSUMED; } + /* Disable TX checksum offload for jumbo frames on cores where + * checksum insertion is broken for oversized frames, matching the + * stmmac_fix_features() workaround used by the skb path. + */ + if (priv->plat->bugged_jumbo && + xdp_get_frame_len(xdpf) > ETH_FRAME_LEN) + csum = false; + while (true) { skb_frag_t *frag = i ? &sinfo->frags[i - 1] : NULL; int len = frag ? skb_frag_size(frag) : xdpf->len; From d1241cdbbcf7bfac3e53482b2054504628f9f047 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 13 Oct 2026 11:54:13 -0600 Subject: [PATCH 1892/2126] net: stmmac: leave the datapath running for normal-size MTU changes When both MTUs are at most ETH_DATA_LEN, the receive buffer size and MAC receive limit do not change. Update the MTU without restarting the datapath. This also avoids rebinding a live AF_XDP pool to a temporary RXQ. XDP rejects jumbo MTUs, so all supported XDP MTU changes take this path. Jumbo transitions still use the existing reopen path. Found by source review while working on the stmmac MTU/resume recovery series. The fast path was tested on Allwinner H616 with sun8i EMAC1 and an AC300 PHY. The AF_XDP scenario was identified by inspection. Reviewed-by: Nicolai Buchwitz Signed-off-by: James Hilliard Reviewed-by: Daniel Machon Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261013-stmmac-mtu-fastpath-v2-1-1e4ce8137689@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 3636449e1ffc..afd8f7a9f051 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6265,7 +6265,12 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu) if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB)) return -EINVAL; - if (netif_running(dev)) { + /* Normal-size frames use the same buffers and MAC receive limits. + * In particular, do not disturb a live AF_XDP pool: XDP does not + * support jumbo frames, so it never needs the ring replacement below. + */ + if (netif_running(dev) && + (dev->mtu > ETH_DATA_LEN || mtu > ETH_DATA_LEN)) { netdev_dbg(priv->dev, "restarting interface to change its MTU\n"); /* Try to allocate the new DMA conf with the new mtu */ dma_conf = stmmac_setup_dma_desc(priv, mtu); From 36af5aac95457729afa6a1182dad00c87f65cabf Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:16 +0800 Subject: [PATCH 1893/2126] r8169: prepare for multi irqs and napi This patch converts the single struct napi_struct into a dynamically allocated array indexed by IRQ. This is a preparation step for adding RSS support. Currently, irq_nvecs and num_rx_rings are still hard-coded to 1. Note that this patch adds netif_napi_set_irq() to expose NAPI-IRQ mapping via netlink, and updates probe log format to show the total number of IRQs. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-2-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 165 ++++++++++++++++++---- 1 file changed, 136 insertions(+), 29 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 43c46d483eb8..3afb9a4b1aff 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -761,7 +761,6 @@ struct rtl8169_private { struct pci_dev *pci_dev; struct net_device *dev; struct phy_device *phydev; - struct napi_struct napi; enum mac_version mac_version; enum rtl_dash_type dash_type; enum rtl_sfp_mode sfp_mode; @@ -774,10 +773,12 @@ struct rtl8169_private { dma_addr_t RxPhyAddr; struct page *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ + struct napi_struct *rtl8169_napi; + unsigned int num_rx_rings; u16 cp_cmd; u16 tx_lpi_timer; u32 irq_mask; - int irq; + unsigned int irq_nvecs; struct clk *clk; int speed; @@ -2769,6 +2770,11 @@ static void rtl_hw_reset(struct rtl8169_private *tp) rtl_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); } +static void rtl_setup_rx_params(struct rtl8169_private *tp) +{ + tp->num_rx_rings = 1; +} + static void rtl_request_firmware(struct rtl8169_private *tp) { struct rtl_fw *rtl_fw; @@ -4431,9 +4437,21 @@ static void rtl8169_tx_clear(struct rtl8169_private *tp) netdev_reset_queue(tp->dev); } +static void rtl8169_napi_disable(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->irq_nvecs; i++) + napi_disable(&tp->rtl8169_napi[i]); +} + +static void rtl8169_napi_enable(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->irq_nvecs; i++) + napi_enable(&tp->rtl8169_napi[i]); +} + static void rtl8169_cleanup(struct rtl8169_private *tp) { - napi_disable(&tp->napi); + rtl8169_napi_disable(tp); /* Give a racing hard_start_xmit a few cycles to complete. */ synchronize_net(); @@ -4479,7 +4497,7 @@ static void rtl_reset_work(struct rtl8169_private *tp) for (i = 0; i < NUM_RX_DESC; i++) rtl8169_mark_to_asic(tp->RxDescArray + i); - napi_enable(&tp->napi); + rtl8169_napi_enable(tp); rtl_hw_start(tp); } @@ -4933,7 +4951,8 @@ static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) skb_checksum_none_assert(skb); } -static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, int budget) +static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, + int budget, struct napi_struct *napi) { struct device *d = tp_to_dev(tp); int count; @@ -4985,7 +5004,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, int budget goto release_descriptor; } - skb = napi_alloc_skb(&tp->napi, pkt_size); + skb = napi_alloc_skb(napi, pkt_size); if (unlikely(!skb)) { dev->stats.rx_dropped++; goto release_descriptor; @@ -5009,7 +5028,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, int budget if (skb->pkt_type == PACKET_MULTICAST) dev->stats.multicast++; - napi_gro_receive(&tp->napi, skb); + napi_gro_receive(napi, skb); dev_sw_netstats_rx_add(dev, pkt_size); release_descriptor: @@ -5021,8 +5040,12 @@ release_descriptor: static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) { - struct rtl8169_private *tp = dev_instance; - u32 status = rtl_get_events(tp); + struct napi_struct *napi = dev_instance; + struct rtl8169_private *tp; + u32 status; + + tp = netdev_priv(napi->dev); + status = rtl_get_events(tp); if ((status & 0xffff) == 0xffff || !(status & tp->irq_mask)) return IRQ_NONE; @@ -5043,13 +5066,55 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) } rtl_irq_disable(tp); - napi_schedule(&tp->napi); + napi_schedule(napi); out: rtl_ack_events(tp, status); return IRQ_HANDLED; } +static void rtl8169_free_irq(struct rtl8169_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + int i, irq; + + for (i = 0; i < tp->irq_nvecs; i++) { + struct napi_struct *napi = &tp->rtl8169_napi[i]; + + irq = pci_irq_vector(pdev, i); + free_irq(irq, napi); + } +} + +static int rtl8169_request_irq(struct rtl8169_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + struct net_device *dev = tp->dev; + struct napi_struct *napi; + unsigned long irqflags; + int i, rc, irq; + + irqflags = pci_dev_msi_enabled(pdev) ? IRQF_NO_THREAD : IRQF_SHARED; + + for (i = 0; i < tp->irq_nvecs; i++) { + napi = &tp->rtl8169_napi[i]; + irq = pci_irq_vector(pdev, i); + + rc = request_irq(irq, rtl8169_interrupt, irqflags, + dev->name, napi); + if (rc) + goto free_irq; + } + return 0; + +free_irq: + while (--i >= 0) { + irq = pci_irq_vector(pdev, i); + free_irq(irq, &tp->rtl8169_napi[i]); + } + return rc; +} + static void rtl_task(struct work_struct *work) { struct rtl8169_private *tp = @@ -5084,13 +5149,13 @@ reset: static int rtl8169_poll(struct napi_struct *napi, int budget) { - struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); - struct net_device *dev = tp->dev; - int work_done; + struct rtl8169_private *tp = netdev_priv(napi->dev); + struct net_device *dev = napi->dev; + int work_done = 0; rtl_tx(dev, tp, budget); - work_done = rtl_rx(dev, tp, budget); + work_done = rtl_rx(dev, tp, budget, napi); if (work_done < budget && napi_complete_done(napi, work_done)) rtl_irq_enable(tp); @@ -5175,7 +5240,7 @@ static void rtl8169_up(struct rtl8169_private *tp) if (tp->phydev) rtl8169_init_phy(tp); - napi_enable(&tp->napi); + rtl8169_napi_enable(tp); enable_work(&tp->wk.work); rtl_reset_work(tp); } @@ -5192,7 +5257,7 @@ static int rtl8169_close(struct net_device *dev) rtl8169_down(tp); rtl8169_rx_clear(tp); - free_irq(tp->irq, tp); + rtl8169_free_irq(tp); phylink_disconnect_phy(tp->phylink); @@ -5213,7 +5278,8 @@ static void rtl8169_netpoll(struct net_device *dev) { struct rtl8169_private *tp = netdev_priv(dev); - rtl8169_interrupt(tp->irq, tp); + for (int i = 0; i < tp->irq_nvecs; i++) + rtl8169_interrupt(0, &tp->rtl8169_napi[i]); } #endif @@ -5221,7 +5287,6 @@ static int rtl_open(struct net_device *dev) { struct rtl8169_private *tp = netdev_priv(dev); struct pci_dev *pdev = tp->pci_dev; - unsigned long irqflags; int retval = -ENOMEM; pm_runtime_get_sync(&pdev->dev); @@ -5246,8 +5311,7 @@ static int rtl_open(struct net_device *dev) rtl_request_firmware(tp); - irqflags = pci_dev_msi_enabled(pdev) ? IRQF_NO_THREAD : IRQF_SHARED; - retval = request_irq(tp->irq, rtl8169_interrupt, irqflags, dev->name, tp); + retval = rtl8169_request_irq(tp); if (retval < 0) goto err_release_fw_2; @@ -5266,7 +5330,7 @@ out: return retval; err_free_irq: - free_irq(tp->irq, tp); + rtl8169_free_irq(tp); err_release_fw_2: rtl_release_firmware(tp); rtl8169_rx_clear(tp); @@ -5419,6 +5483,14 @@ static void rtl_shutdown(struct pci_dev *pdev) pci_prepare_to_sleep(pdev); } +static void r8169_free_napi(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->irq_nvecs; i++) + netif_napi_del(&tp->rtl8169_napi[i]); + + kfree(tp->rtl8169_napi); +} + static void rtl_remove_one(struct pci_dev *pdev) { struct rtl8169_private *tp = pci_get_drvdata(pdev); @@ -5432,6 +5504,7 @@ static void rtl_remove_one(struct pci_dev *pdev) r8169_remove_leds(tp->leds); unregister_netdev(tp->dev); + r8169_free_napi(tp); phylink_destroy(tp->phylink); if (tp->dash_type != RTL_DASH_NONE) @@ -5473,7 +5546,9 @@ static void rtl_set_irq_mask(struct rtl8169_private *tp) static int rtl_alloc_irq(struct rtl8169_private *tp) { + struct pci_dev *pdev = tp->pci_dev; unsigned int flags; + int nvecs; switch (tp->mac_version) { case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: @@ -5489,7 +5564,14 @@ static int rtl_alloc_irq(struct rtl8169_private *tp) break; } - return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); + nvecs = pci_alloc_irq_vectors(pdev, 1, 1, flags); + + if (nvecs < 0) + return nvecs; + + tp->irq_nvecs = nvecs; + + return 0; } static void rtl_read_mac_address(struct rtl8169_private *tp, @@ -6012,6 +6094,15 @@ static int rtl_init_phylink(struct rtl8169_private *tp) return 0; } +static void r8169_init_napi(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->irq_nvecs; i++) { + netif_napi_add(tp->dev, &tp->rtl8169_napi[i], rtl8169_poll); + netif_napi_set_irq(&tp->rtl8169_napi[i], + pci_irq_vector(tp->pci_dev, i)); + } +} + static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { const struct rtl_chip_info *chip; @@ -6112,12 +6203,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) rtl_hw_reset(tp); + rtl_setup_rx_params(tp); + rc = rtl_alloc_irq(tp); if (rc < 0) return dev_err_probe(&pdev->dev, rc, "Can't allocate interrupt\n"); - tp->irq = pci_irq_vector(pdev, 0); - INIT_WORK(&tp->wk.work, rtl_task); disable_work(&tp->wk.work); @@ -6125,8 +6216,6 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->ethtool_ops = &rtl8169_ethtool_ops; - netif_napi_add(dev, &tp->napi, rtl8169_poll); - dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; @@ -6187,6 +6276,10 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (jumbo_max) dev->max_mtu = jumbo_max; + rc = netif_set_real_num_queues(tp->dev, 1, tp->num_rx_rings); + if (rc < 0) + return dev_err_probe(&pdev->dev, rc, "set tx/rx num failure\n"); + rtl_set_irq_mask(tp); tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), @@ -6209,10 +6302,19 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) } } + tp->rtl8169_napi = kcalloc(tp->irq_nvecs, sizeof(struct napi_struct), + GFP_KERNEL); + if (!tp->rtl8169_napi) { + phylink_destroy(tp->phylink); + return -ENOMEM; + } + + r8169_init_napi(tp); + rc = register_netdev(dev); if (rc) { phylink_destroy(tp->phylink); - return rc; + goto err_free_napi; } if (IS_ENABLED(CONFIG_R8169_LEDS)) { @@ -6222,8 +6324,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->leds = rtl8168_init_leds(dev); } - netdev_info(dev, "%s, %pM, %sXID %x, IRQ %d\n", - chip->name, dev->dev_addr, ext_xid_str, xid, tp->irq); + netdev_info(dev, "%s, %pM, %sXID %x, IRQ %d (%u total)\n", + chip->name, dev->dev_addr, ext_xid_str, xid, + pci_irq_vector(pdev, 0), tp->irq_nvecs); if (jumbo_max) netdev_info(dev, "jumbo features [frames: %d bytes, tx checksumming: %s]\n", @@ -6243,6 +6346,10 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) pm_runtime_put_sync(&pdev->dev); return 0; + +err_free_napi: + r8169_free_napi(tp); + return rc; } static struct pci_driver rtl8169_pci_driver = { From 5df447aee076a1bfdbf944ed96b5b14cde9446f5 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:17 +0800 Subject: [PATCH 1894/2126] r8169: refactor RX path to prepare for multi-queue This patch is a preparatory refactoring of the RX path. It introduces struct rtl8169_rx_ring and turns the previously embedded RX state in rtl8169_private into a per-queue array. The original DMA address of rx buffer is read back directly from desc->addr. But when we enable rss, desc->addr will be overwritten. So this patch introduces a array to cache the DMA address of rx buffers which we name it as rx_buf_dma_addr. While the netdev allocation is changed to devm_alloc_etherdev_mqs() with up to 8 RX queues, the actual number of active RX rings (num_rx_rings) is currently kept at 1. The actual multi-queue operation and RSS enablement will be introduced in subsequent patches. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-3-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 240 +++++++++++++++++----- 1 file changed, 183 insertions(+), 57 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 3afb9a4b1aff..e88d512cc3a5 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -77,6 +77,9 @@ #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) #define R8169_TX_STOP_THRS (MAX_SKB_FRAGS + 1) #define R8169_TX_START_THRS (2 * R8169_TX_STOP_THRS) +#define R8169_MAX_RX_QUEUES 8 +#define R8169_DEFAULT_RX_QUEUES 1 +#define R8169_MAX_TX_QUEUES 1 #define OCP_STD_PHY_BASE 0xa400 @@ -463,6 +466,7 @@ enum rtl8125_registers { TxPoll_8125 = 0x90, LEDSEL3 = 0x96, MAC0_BKP = 0x19e0, + RDSAR_Q1_LOW = 0x4000, RSS_CTRL_8125 = 0x4500, Q_NUM_CTRL_8125 = 0x4800, EEE_TXIDLE_TIMER_8125 = 0x6048, @@ -750,6 +754,14 @@ enum rtl_dash_type { RTL_DASH_25_BP, }; +struct rtl8169_rx_ring { + u32 cur_rx; + struct RxDesc *rx_desc_array; + dma_addr_t rx_buf_dma_addr[NUM_RX_DESC]; + dma_addr_t rx_phy_addr; + struct page *rx_databuff[NUM_RX_DESC]; +}; + enum rtl_sfp_mode { RTL_SFP_NONE, RTL_SFP_8168_AF, @@ -764,20 +776,18 @@ struct rtl8169_private { enum mac_version mac_version; enum rtl_dash_type dash_type; enum rtl_sfp_mode sfp_mode; - u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ u32 dirty_tx; struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ - struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ dma_addr_t TxPhyAddr; - dma_addr_t RxPhyAddr; - struct page *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ struct napi_struct *rtl8169_napi; + struct rtl8169_rx_ring *rx_ring; unsigned int num_rx_rings; u16 cp_cmd; u16 tx_lpi_timer; u32 irq_mask; + unsigned int hw_supp_num_rx_queues; unsigned int irq_nvecs; struct clk *clk; int speed; @@ -2718,9 +2728,25 @@ static void rtl_init_rxcfg(struct rtl8169_private *tp) } } +static void rtl8169_rx_desc_init(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->num_rx_rings; i++) { + struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; + + memset(ring->rx_desc_array, 0x0, R8169_RX_RING_BYTES); + } +} + static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) { - tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; + tp->dirty_tx = 0; + tp->cur_tx = 0; + + for (int i = 0; i < tp->num_rx_rings; i++) { + struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; + + ring->cur_rx = 0; + } } static void rtl_jumbo_config(struct rtl8169_private *tp) @@ -2773,6 +2799,14 @@ static void rtl_hw_reset(struct rtl8169_private *tp) static void rtl_setup_rx_params(struct rtl8169_private *tp) { tp->num_rx_rings = 1; + switch (tp->mac_version) { + case RTL_GIGA_MAC_VER_80: + tp->hw_supp_num_rx_queues = R8169_MAX_RX_QUEUES; + break; + default: + tp->hw_supp_num_rx_queues = R8169_DEFAULT_RX_QUEUES; + break; + } } static void rtl_request_firmware(struct rtl8169_private *tp) @@ -2899,6 +2933,8 @@ static void rtl_set_rx_max_size(struct rtl8169_private *tp) static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) { + struct rtl8169_rx_ring *ring = &tp->rx_ring[0]; + /* * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh * register to be written before TxDescAddrLow to work. @@ -2906,8 +2942,18 @@ static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) */ RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); - RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); - RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); + RTL_W32(tp, RxDescAddrHigh, ((u64)ring->rx_phy_addr) >> 32); + RTL_W32(tp, RxDescAddrLow, + ((u64)ring->rx_phy_addr) & DMA_BIT_MASK(32)); + + for (int i = 1; i < tp->num_rx_rings; i++) { + unsigned int rdsar_reg = RDSAR_Q1_LOW + (i - 1) * 8; + struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; + + RTL_W32(tp, rdsar_reg + 4, ((u64)ring->rx_phy_addr >> 32)); + RTL_W32(tp, rdsar_reg, + ((u64)ring->rx_phy_addr) & DMA_BIT_MASK(32)); + } } static void rtl8169_set_magic_reg(struct rtl8169_private *tp) @@ -4330,8 +4376,9 @@ static void rtl8169_mark_to_asic(struct RxDesc *desc) } static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp, - struct RxDesc *desc) + struct rtl8169_rx_ring *ring, unsigned int index) { + struct RxDesc *desc = ring->rx_desc_array + index; struct device *d = tp_to_dev(tp); int node = dev_to_node(d); dma_addr_t mapping; @@ -4349,55 +4396,107 @@ static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp, } desc->addr = cpu_to_le64(mapping); + ring->rx_buf_dma_addr[index] = mapping; rtl8169_mark_to_asic(desc); return data; } -static void rtl8169_rx_clear(struct rtl8169_private *tp) +static void rtl8169_rx_clear(struct rtl8169_private *tp, + struct rtl8169_rx_ring *ring) { int i; - for (i = 0; i < NUM_RX_DESC && tp->Rx_databuff[i]; i++) { + for (i = 0; i < NUM_RX_DESC && ring->rx_databuff[i]; i++) { dma_unmap_page(tp_to_dev(tp), - le64_to_cpu(tp->RxDescArray[i].addr), + ring->rx_buf_dma_addr[i], R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); - __free_pages(tp->Rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); - tp->Rx_databuff[i] = NULL; - tp->RxDescArray[i].addr = 0; - tp->RxDescArray[i].opts1 = 0; + __free_pages(ring->rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); + ring->rx_databuff[i] = NULL; + ring->rx_buf_dma_addr[i] = 0; + ring->rx_desc_array[i].addr = 0; + ring->rx_desc_array[i].opts1 = 0; } } -static int rtl8169_rx_fill(struct rtl8169_private *tp) +static int rtl8169_rx_fill(struct rtl8169_private *tp, struct rtl8169_rx_ring *ring) { int i; for (i = 0; i < NUM_RX_DESC; i++) { struct page *data; - data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); + data = rtl8169_alloc_rx_data(tp, ring, i); if (!data) { - rtl8169_rx_clear(tp); + rtl8169_rx_clear(tp, ring); return -ENOMEM; } - tp->Rx_databuff[i] = data; + ring->rx_databuff[i] = data; } /* mark as last descriptor in the ring */ - tp->RxDescArray[NUM_RX_DESC - 1].opts1 |= cpu_to_le32(RingEnd); + ring->rx_desc_array[NUM_RX_DESC - 1].opts1 |= cpu_to_le32(RingEnd); return 0; } +static int rtl8169_alloc_rx_desc(struct rtl8169_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + struct rtl8169_rx_ring *ring; + + for (int i = 0; i < tp->num_rx_rings; i++) { + ring = &tp->rx_ring[i]; + ring->rx_desc_array = dma_alloc_coherent(&pdev->dev, + R8169_RX_RING_BYTES, + &ring->rx_phy_addr, + GFP_KERNEL); + if (!ring->rx_desc_array) + return -ENOMEM; + } + return 0; +} + +static void rtl8169_free_rx_desc(struct rtl8169_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + struct rtl8169_rx_ring *ring; + + for (int i = 0; i < tp->num_rx_rings; i++) { + ring = &tp->rx_ring[i]; + if (ring->rx_desc_array) { + dma_free_coherent(&pdev->dev, + R8169_RX_RING_BYTES, + ring->rx_desc_array, + ring->rx_phy_addr); + ring->rx_desc_array = NULL; + } + } +} + static int rtl8169_init_ring(struct rtl8169_private *tp) { + int i, ret; + rtl8169_init_ring_indexes(tp); + rtl8169_rx_desc_init(tp); memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); - memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); - return rtl8169_rx_fill(tp); + for (i = 0; i < tp->num_rx_rings; i++) { + struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; + + memset(ring->rx_databuff, 0, sizeof(ring->rx_databuff)); + ret = rtl8169_rx_fill(tp, ring); + if (ret < 0) + goto err_clear; + } + return 0; + +err_clear: + while (--i >= 0) + rtl8169_rx_clear(tp, &tp->rx_ring[i]); + return ret; } static void rtl8169_unmap_tx_skb(struct rtl8169_private *tp, unsigned int entry) @@ -4486,16 +4585,23 @@ static void rtl8169_cleanup(struct rtl8169_private *tp) rtl8169_init_ring_indexes(tp); } +static void rtl8169_rx_desc_reset(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->num_rx_rings; i++) { + struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; + + for (int j = 0; j < NUM_RX_DESC; j++) + rtl8169_mark_to_asic(ring->rx_desc_array + j); + } +} + static void rtl_reset_work(struct rtl8169_private *tp) { - int i; - netif_stop_queue(tp->dev); rtl8169_cleanup(tp); - for (i = 0; i < NUM_RX_DESC; i++) - rtl8169_mark_to_asic(tp->RxDescArray + i); + rtl8169_rx_desc_reset(tp); rtl8169_napi_enable(tp); rtl_hw_start(tp); @@ -4951,15 +5057,30 @@ static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) skb_checksum_none_assert(skb); } +static bool rtl8169_check_rx_desc_error(struct net_device *dev, + struct rtl8169_private *tp, + u32 status) +{ + if (unlikely(status & RxRES)) { + if (status & (RxRWT | RxRUNT)) + dev->stats.rx_length_errors++; + if (status & RxCRC) + dev->stats.rx_crc_errors++; + return true; + } + return false; +} + static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, - int budget, struct napi_struct *napi) + struct rtl8169_rx_ring *ring, int budget, + struct napi_struct *napi) { struct device *d = tp_to_dev(tp); int count; - for (count = 0; count < budget; count++, tp->cur_rx++) { - unsigned int pkt_size, entry = tp->cur_rx % NUM_RX_DESC; - struct RxDesc *desc = tp->RxDescArray + entry; + for (count = 0; count < budget; count++, ring->cur_rx++) { + unsigned int pkt_size, entry = ring->cur_rx % NUM_RX_DESC; + struct RxDesc *desc = ring->rx_desc_array + entry; struct sk_buff *skb; const void *rx_buf; dma_addr_t addr; @@ -4975,15 +5096,11 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, */ dma_rmb(); - if (unlikely(status & RxRES)) { + if (rtl8169_check_rx_desc_error(dev, tp, status)) { if (net_ratelimit()) netdev_warn(dev, "Rx ERROR. status = %08x\n", status); dev->stats.rx_errors++; - if (status & (RxRWT | RxRUNT)) - dev->stats.rx_length_errors++; - if (status & RxCRC) - dev->stats.rx_crc_errors++; if (!(dev->features & NETIF_F_RXALL)) goto release_descriptor; @@ -5010,8 +5127,8 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, goto release_descriptor; } - addr = le64_to_cpu(desc->addr); - rx_buf = page_address(tp->Rx_databuff[entry]); + addr = ring->rx_buf_dma_addr[entry]; + rx_buf = page_address(ring->rx_databuff[entry]); dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); prefetch(rx_buf); @@ -5155,7 +5272,8 @@ static int rtl8169_poll(struct napi_struct *napi, int budget) rtl_tx(dev, tp, budget); - work_done = rtl_rx(dev, tp, budget, napi); + /* rtl8169_poll() is used only when there is a single RX ring. */ + work_done = rtl_rx(dev, tp, &tp->rx_ring[0], budget, napi); if (work_done < budget && napi_complete_done(napi, work_done)) rtl_irq_enable(tp); @@ -5255,18 +5373,17 @@ static int rtl8169_close(struct net_device *dev) phylink_stop(tp->phylink); netif_stop_queue(dev); rtl8169_down(tp); - rtl8169_rx_clear(tp); + for (int i = 0; i < tp->num_rx_rings; i++) + rtl8169_rx_clear(tp, &tp->rx_ring[i]); rtl8169_free_irq(tp); phylink_disconnect_phy(tp->phylink); - dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, - tp->RxPhyAddr); dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, tp->TxPhyAddr); tp->TxDescArray = NULL; - tp->RxDescArray = NULL; + rtl8169_free_rx_desc(tp); pm_runtime_put_sync(&pdev->dev); @@ -5300,10 +5417,8 @@ static int rtl_open(struct net_device *dev) if (!tp->TxDescArray) goto out; - tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, - &tp->RxPhyAddr, GFP_KERNEL); - if (!tp->RxDescArray) - goto err_free_tx_0; + if (rtl8169_alloc_rx_desc(tp) < 0) + goto err_free_rx_1; retval = rtl8169_init_ring(tp); if (retval < 0) @@ -5333,12 +5448,10 @@ err_free_irq: rtl8169_free_irq(tp); err_release_fw_2: rtl_release_firmware(tp); - rtl8169_rx_clear(tp); + for (int i = 0; i < tp->num_rx_rings; i++) + rtl8169_rx_clear(tp, &tp->rx_ring[i]); err_free_rx_1: - dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, - tp->RxPhyAddr); - tp->RxDescArray = NULL; -err_free_tx_0: + rtl8169_free_rx_desc(tp); dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, tp->TxPhyAddr); tp->TxDescArray = NULL; @@ -5505,6 +5618,7 @@ static void rtl_remove_one(struct pci_dev *pdev) unregister_netdev(tp->dev); r8169_free_napi(tp); + kfree(tp->rx_ring); phylink_destroy(tp->phylink); if (tp->dash_type != RTL_DASH_NONE) @@ -6113,7 +6227,10 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) u32 txconfig; u32 xid; - dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); + dev = devm_alloc_etherdev_mqs(&pdev->dev, sizeof(*tp), + R8169_MAX_TX_QUEUES, + R8169_MAX_RX_QUEUES); + if (!dev) return -ENOMEM; @@ -6302,20 +6419,25 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) } } + tp->rx_ring = kcalloc(tp->num_rx_rings, sizeof(struct rtl8169_rx_ring), + GFP_KERNEL); + if (!tp->rx_ring) { + rc = -ENOMEM; + goto err_destroy_phylink; + } + tp->rtl8169_napi = kcalloc(tp->irq_nvecs, sizeof(struct napi_struct), GFP_KERNEL); if (!tp->rtl8169_napi) { - phylink_destroy(tp->phylink); - return -ENOMEM; + rc = -ENOMEM; + goto err_free_rx_ring; } r8169_init_napi(tp); rc = register_netdev(dev); - if (rc) { - phylink_destroy(tp->phylink); + if (rc) goto err_free_napi; - } if (IS_ENABLED(CONFIG_R8169_LEDS)) { if (rtl_is_8125(tp)) @@ -6349,6 +6471,10 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) err_free_napi: r8169_free_napi(tp); +err_free_rx_ring: + kfree(tp->rx_ring); +err_destroy_phylink: + phylink_destroy(tp->phylink); return rc; } From 677f8f8c4c5f6a402d84bbc6b528ddba6a1d8fc4 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:18 +0800 Subject: [PATCH 1895/2126] r8169: add support for new interrupt mapping To support RSS, the number of hardware interrupt bits should match the interrupt of software. So we add support for new interrupt mapping here. ISR_VEC_MAP_REG is the hardware register to indicate interrupt status. IMR_SET_VEC_MAP_REG is interrupt mask which is set to enable irq. Note that this patch only adds the infrastructure. All of the new paths are gated on tp->irq_nvecs > 1. At this stage, irq_nvecs is still 1, so this code will remain inactive until the subsequent patch requsets multiple MSI-X vectors. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-4-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 244 ++++++++++++++++++---- 1 file changed, 209 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index e88d512cc3a5..caa5f2880c6a 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -470,8 +470,12 @@ enum rtl8125_registers { RSS_CTRL_8125 = 0x4500, Q_NUM_CTRL_8125 = 0x4800, EEE_TXIDLE_TIMER_8125 = 0x6048, + IMR_CLEAR_VEC_MAP_REG = 0x0d00, + ISR_VEC_MAP_REG = 0x0d04, + IMR_SET_VEC_MAP_REG = 0x0d0c, }; +#define MSIX_ID_VEC_MAP_LINKCHG 29 #define LEDSEL_MASK_8125 0x23f #define RX_VLAN_INNER_8125 BIT(22) @@ -602,6 +606,9 @@ enum rtl_register_content { /* magic enable v2 */ MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ +#define ISRIMR_LINKCHG BIT(29) +#define ISRIMR_TOK_Q0 BIT(8) +#define ISRIMR_ROK_Q0 BIT(0) }; enum rtl_desc_bit { @@ -1769,26 +1776,38 @@ static u32 rtl_get_events(struct rtl8169_private *tp) static void rtl_ack_events(struct rtl8169_private *tp, u32 bits) { - if (rtl_is_8125(tp)) - RTL_W32(tp, IntrStatus_8125, bits); - else + if (rtl_is_8125(tp)) { + if (tp->irq_nvecs > 1) + RTL_W32(tp, ISR_VEC_MAP_REG, bits); + else + RTL_W32(tp, IntrStatus_8125, bits); + } else { RTL_W16(tp, IntrStatus, bits); + } } static void rtl_irq_disable(struct rtl8169_private *tp) { - if (rtl_is_8125(tp)) - RTL_W32(tp, IntrMask_8125, 0); - else + if (rtl_is_8125(tp)) { + if (tp->irq_nvecs > 1) + RTL_W32(tp, IMR_CLEAR_VEC_MAP_REG, 0xffffffff); + else + RTL_W32(tp, IntrMask_8125, 0); + } else { RTL_W16(tp, IntrMask, 0); + } } static void rtl_irq_enable(struct rtl8169_private *tp) { - if (rtl_is_8125(tp)) - RTL_W32(tp, IntrMask_8125, tp->irq_mask); - else + if (rtl_is_8125(tp)) { + if (tp->irq_nvecs > 1) + RTL_W32(tp, IMR_SET_VEC_MAP_REG, tp->irq_mask); + else + RTL_W32(tp, IntrMask_8125, tp->irq_mask); + } else { RTL_W16(tp, IntrMask, tp->irq_mask); + } } static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) @@ -4538,14 +4557,24 @@ static void rtl8169_tx_clear(struct rtl8169_private *tp) static void rtl8169_napi_disable(struct rtl8169_private *tp) { - for (int i = 0; i < tp->irq_nvecs; i++) - napi_disable(&tp->rtl8169_napi[i]); + if (tp->irq_nvecs > 1) { + for (int i = 0; i < tp->num_rx_rings; i++) + napi_disable(&tp->rtl8169_napi[i]); + napi_disable(&tp->rtl8169_napi[R8169_MAX_RX_QUEUES]); + } else { + napi_disable(&tp->rtl8169_napi[0]); + } } static void rtl8169_napi_enable(struct rtl8169_private *tp) { - for (int i = 0; i < tp->irq_nvecs; i++) - napi_enable(&tp->rtl8169_napi[i]); + if (tp->irq_nvecs > 1) { + for (int i = 0; i < tp->num_rx_rings; i++) + napi_enable(&tp->rtl8169_napi[i]); + napi_enable(&tp->rtl8169_napi[R8169_MAX_RX_QUEUES]); + } else { + napi_enable(&tp->rtl8169_napi[0]); + } } static void rtl8169_cleanup(struct rtl8169_private *tp) @@ -5190,19 +5219,81 @@ out: return IRQ_HANDLED; } -static void rtl8169_free_irq(struct rtl8169_private *tp) +static void rtl8169_free_one_irq(struct rtl8169_private *tp, int i) { struct pci_dev *pdev = tp->pci_dev; - int i, irq; + struct napi_struct *napi; + int irq; - for (i = 0; i < tp->irq_nvecs; i++) { - struct napi_struct *napi = &tp->rtl8169_napi[i]; + irq = pci_irq_vector(pdev, i); + napi = &tp->rtl8169_napi[i]; - irq = pci_irq_vector(pdev, i); + if (tp->irq_nvecs > 1) { + if (i < tp->num_rx_rings || i == R8169_MAX_RX_QUEUES) + free_irq(irq, napi); + else if (i == MSIX_ID_VEC_MAP_LINKCHG) + free_irq(irq, tp); + } else { free_irq(irq, napi); } } +static void rtl8169_free_irq(struct rtl8169_private *tp) +{ + int i; + + for (i = 0; i < tp->irq_nvecs; i++) + rtl8169_free_one_irq(tp, i); +} + +static void rtl8169_disable_hw_interrupt_msix(struct rtl8169_private *tp, + int message_id) +{ + RTL_W32(tp, IMR_CLEAR_VEC_MAP_REG, BIT(message_id)); +} + +static void rtl8169_clear_hw_isr(struct rtl8169_private *tp, int message_id) +{ + RTL_W32(tp, ISR_VEC_MAP_REG, BIT(message_id)); +} + +static void rtl8169_enable_hw_interrupt_msix(struct rtl8169_private *tp, + int message_id) +{ + RTL_W32(tp, IMR_SET_VEC_MAP_REG, BIT(message_id)); +} + +static irqreturn_t rtl8169_interrupt_msix(int irq, void *dev_instance) +{ + struct napi_struct *napi = dev_instance; + struct net_device *dev = napi->dev; + struct rtl8169_private *tp; + int message_id; + + tp = netdev_priv(dev); + message_id = napi - tp->rtl8169_napi; + + rtl8169_disable_hw_interrupt_msix(tp, message_id); + rtl8169_clear_hw_isr(tp, message_id); + + napi_schedule(napi); + + return IRQ_HANDLED; +} + +static irqreturn_t rtl8169_interrupt_other(int irq, void *dev_instance) +{ + struct rtl8169_private *tp = dev_instance; + + rtl8169_clear_hw_isr(tp, MSIX_ID_VEC_MAP_LINKCHG); + if (tp->phydev) + phy_mac_interrupt(tp->phydev); + else if (tp->sfp_mode) + phylink_mac_change(tp->phylink, + !!(RTL_R8(tp, PHYstatus) & LinkStatus)); + return IRQ_HANDLED; +} + static int rtl8169_request_irq(struct rtl8169_private *tp) { struct pci_dev *pdev = tp->pci_dev; @@ -5217,18 +5308,28 @@ static int rtl8169_request_irq(struct rtl8169_private *tp) napi = &tp->rtl8169_napi[i]; irq = pci_irq_vector(pdev, i); - rc = request_irq(irq, rtl8169_interrupt, irqflags, - dev->name, napi); + if (tp->irq_nvecs > 1) { + /* RX: 0~7, TX: 8*/ + if (i < tp->num_rx_rings || i == R8169_MAX_RX_QUEUES) + rc = request_irq(irq, rtl8169_interrupt_msix, + irqflags, dev->name, napi); + else if (i == MSIX_ID_VEC_MAP_LINKCHG) + rc = request_irq(irq, rtl8169_interrupt_other, + irqflags, dev->name, tp); + else + continue; + } else { + rc = request_irq(irq, rtl8169_interrupt, + irqflags, dev->name, napi); + } if (rc) goto free_irq; } return 0; free_irq: - while (--i >= 0) { - irq = pci_irq_vector(pdev, i); - free_irq(irq, &tp->rtl8169_napi[i]); - } + while (--i >= 0) + rtl8169_free_one_irq(tp, i); return rc; } @@ -5395,8 +5496,13 @@ static void rtl8169_netpoll(struct net_device *dev) { struct rtl8169_private *tp = netdev_priv(dev); - for (int i = 0; i < tp->irq_nvecs; i++) - rtl8169_interrupt(0, &tp->rtl8169_napi[i]); + if (tp->irq_nvecs > 1) { + for (int i = 0; i < tp->num_rx_rings; i++) + rtl8169_interrupt_msix(0, &tp->rtl8169_napi[i]); + rtl8169_interrupt_msix(0, &tp->rtl8169_napi[R8169_MAX_RX_QUEUES]); + } else { + rtl8169_interrupt(0, &tp->rtl8169_napi[0]); + } } #endif @@ -5598,8 +5704,13 @@ static void rtl_shutdown(struct pci_dev *pdev) static void r8169_free_napi(struct rtl8169_private *tp) { - for (int i = 0; i < tp->irq_nvecs; i++) - netif_napi_del(&tp->rtl8169_napi[i]); + if (tp->irq_nvecs > 1) { + for (int i = 0; i < tp->num_rx_rings; i++) + netif_napi_del(&tp->rtl8169_napi[i]); + netif_napi_del(&tp->rtl8169_napi[R8169_MAX_RX_QUEUES]); + } else { + netif_napi_del(&tp->rtl8169_napi[0]); + } kfree(tp->rtl8169_napi); } @@ -5652,10 +5763,16 @@ static const struct net_device_ops rtl_netdev_ops = { static void rtl_set_irq_mask(struct rtl8169_private *tp) { - tp->irq_mask = RxOK | RxErr | TxOK | TxErr | LinkChg; + if (tp->irq_nvecs > 1) { + tp->irq_mask = ISRIMR_LINKCHG | ISRIMR_TOK_Q0; + for (int i = 0; i < tp->num_rx_rings; i++) + tp->irq_mask |= ISRIMR_ROK_Q0 << i; + } else { + tp->irq_mask = RxOK | RxErr | TxOK | TxErr | LinkChg; - if (tp->mac_version <= RTL_GIGA_MAC_VER_06) - tp->irq_mask |= SYSErr | RxFIFOOver; + if (tp->mac_version <= RTL_GIGA_MAC_VER_06) + tp->irq_mask |= SYSErr | RxFIFOOver; + } } static int rtl_alloc_irq(struct rtl8169_private *tp) @@ -6208,12 +6325,69 @@ static int rtl_init_phylink(struct rtl8169_private *tp) return 0; } +static int rtl8169_poll_msix_rx(struct napi_struct *napi, int budget) +{ + struct net_device *dev = napi->dev; + struct rtl8169_private *tp; + int work_done = 0; + int message_id; + + tp = netdev_priv(dev); + message_id = napi - tp->rtl8169_napi; + + if (message_id < tp->num_rx_rings) + work_done += rtl_rx(dev, tp, &tp->rx_ring[message_id], + budget, napi); + + if (work_done < budget && napi_complete_done(napi, work_done)) + rtl8169_enable_hw_interrupt_msix(tp, message_id); + + return work_done; +} + +static int rtl8169_poll_msix_tx(struct napi_struct *napi, int budget) +{ + struct net_device *dev = napi->dev; + struct rtl8169_private *tp; + + tp = netdev_priv(dev); + + /* Currently r8169 only supports a single Tx ring. + * Therefore, we don't need a per-ring Tx processing loop here. + */ + rtl_tx(dev, tp, budget); + + if (budget && napi_complete_done(napi, 0)) + rtl8169_enable_hw_interrupt_msix(tp, (int)(napi - tp->rtl8169_napi)); + + return 0; +} + +/* RTL8127 MSI-X vector layout: + * Vectors 0 .. (MAX_RXQ - 1) : Rx Queues + * Vectors MAX_RXQ .. (MAX_RXQ + MAX_TXQ - 1) : Tx Queues + * NAPI is only allocated for data path + */ static void r8169_init_napi(struct rtl8169_private *tp) { - for (int i = 0; i < tp->irq_nvecs; i++) { - netif_napi_add(tp->dev, &tp->rtl8169_napi[i], rtl8169_poll); - netif_napi_set_irq(&tp->rtl8169_napi[i], - pci_irq_vector(tp->pci_dev, i)); + int i; + + if (tp->irq_nvecs > 1) { + for (i = 0; i < tp->num_rx_rings; i++) { + netif_napi_add(tp->dev, &tp->rtl8169_napi[i], + rtl8169_poll_msix_rx); + netif_napi_set_irq(&tp->rtl8169_napi[i], + pci_irq_vector(tp->pci_dev, i)); + } + netif_napi_add_tx(tp->dev, + &tp->rtl8169_napi[R8169_MAX_RX_QUEUES], + rtl8169_poll_msix_tx); + netif_napi_set_irq(&tp->rtl8169_napi[R8169_MAX_RX_QUEUES], + pci_irq_vector(tp->pci_dev, R8169_MAX_RX_QUEUES)); + } else { + netif_napi_add(tp->dev, &tp->rtl8169_napi[0], rtl8169_poll); + netif_napi_set_irq(&tp->rtl8169_napi[0], + pci_irq_vector(tp->pci_dev, 0)); } } From 7c543c5d12b281743d8ff7b30bb0c75c86c2f1c7 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:19 +0800 Subject: [PATCH 1896/2126] r8169: prepare for new interrupt mapping This patch enables new interrupt mapping for RTL8127 and add error pkts counter per ring. Note that tp->irq_nvecs and tp->num_rx_rings are still hard-coded to 1. The new mapping and multi-ring stats will actually become active in a later patch that requests multiple MSI-X vector. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-5-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 78 +++++++++++++++++++---- 1 file changed, 67 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index caa5f2880c6a..76f7a4592deb 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -767,6 +768,15 @@ struct rtl8169_rx_ring { dma_addr_t rx_buf_dma_addr[NUM_RX_DESC]; dma_addr_t rx_phy_addr; struct page *rx_databuff[NUM_RX_DESC]; + + struct { + u64 rx_errors; + u64 rx_dropped; + u64 rx_length_errors; + u64 rx_crc_errors; + u64 multicast; + struct u64_stats_sync syncp; + } stats; }; enum rtl_sfp_mode { @@ -4083,6 +4093,15 @@ DECLARE_RTL_COND(rtl_mac_ocp_e00e_cond) return r8168_mac_ocp_read(tp, 0xe00e) & BIT(13); } +static void rtl8169_hw_enable_vec_mapping(struct rtl8169_private *tp) +{ + u8 tmp; + + tmp = RTL_R8(tp, INT_CFG0_8125); + tmp |= INT_CFG0_ENABLE_8125; + RTL_W8(tp, INT_CFG0_8125, tmp); +} + static void rtl_hw_start_8125_common(struct rtl8169_private *tp) { rtl_pcie_state_l2l3_disable(tp); @@ -4091,6 +4110,9 @@ static void rtl_hw_start_8125_common(struct rtl8169_private *tp) RTL_W32(tp, RSS_CTRL_8125, 0); RTL_W16(tp, Q_NUM_CTRL_8125, 0); + if (tp->irq_nvecs > 1) + rtl8169_hw_enable_vec_mapping(tp); + /* disable UPS */ r8168_mac_ocp_modify(tp, 0xd40a, 0x0010, 0x0000); @@ -5086,15 +5108,16 @@ static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) skb_checksum_none_assert(skb); } -static bool rtl8169_check_rx_desc_error(struct net_device *dev, - struct rtl8169_private *tp, +static bool rtl8169_check_rx_desc_error(struct rtl8169_rx_ring *ring, u32 status) { if (unlikely(status & RxRES)) { + u64_stats_update_begin(&ring->stats.syncp); if (status & (RxRWT | RxRUNT)) - dev->stats.rx_length_errors++; + ring->stats.rx_length_errors++; if (status & RxCRC) - dev->stats.rx_crc_errors++; + ring->stats.rx_crc_errors++; + u64_stats_update_end(&ring->stats.syncp); return true; } return false; @@ -5125,11 +5148,13 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, */ dma_rmb(); - if (rtl8169_check_rx_desc_error(dev, tp, status)) { + if (rtl8169_check_rx_desc_error(ring, status)) { if (net_ratelimit()) netdev_warn(dev, "Rx ERROR. status = %08x\n", status); - dev->stats.rx_errors++; + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.rx_errors++; + u64_stats_update_end(&ring->stats.syncp); if (!(dev->features & NETIF_F_RXALL)) goto release_descriptor; @@ -5145,14 +5170,18 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, * They are seen as a symptom of over-mtu sized frames. */ if (unlikely(rtl8169_fragmented_frame(status))) { - dev->stats.rx_dropped++; - dev->stats.rx_length_errors++; + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.rx_dropped++; + ring->stats.rx_length_errors++; + u64_stats_update_end(&ring->stats.syncp); goto release_descriptor; } skb = napi_alloc_skb(napi, pkt_size); if (unlikely(!skb)) { - dev->stats.rx_dropped++; + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.rx_dropped++; + u64_stats_update_end(&ring->stats.syncp); goto release_descriptor; } @@ -5171,8 +5200,11 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, rtl8169_rx_vlan_tag(desc, skb); - if (skb->pkt_type == PACKET_MULTICAST) - dev->stats.multicast++; + if (skb->pkt_type == PACKET_MULTICAST) { + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.multicast++; + u64_stats_update_end(&ring->stats.syncp); + } napi_gro_receive(napi, skb); @@ -5576,6 +5608,27 @@ rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) netdev_stats_to_stats64(stats, &dev->stats); dev_fetch_sw_netstats(stats, dev->tstats); + for (int i = 0; i < tp->num_rx_rings; i++) { + u64 errors, dropped, length_errors, crc_errors, multicast; + struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; + unsigned int start; + + do { + start = u64_stats_fetch_begin(&ring->stats.syncp); + errors = ring->stats.rx_errors; + dropped = ring->stats.rx_dropped; + length_errors = ring->stats.rx_length_errors; + crc_errors = ring->stats.rx_crc_errors; + multicast = ring->stats.multicast; + } while (u64_stats_fetch_retry(&ring->stats.syncp, start)); + + stats->rx_errors += errors; + stats->rx_dropped += dropped; + stats->rx_length_errors += length_errors; + stats->rx_crc_errors += crc_errors; + stats->multicast += multicast; + } + /* * Fetch additional counter values missing in stats collected by driver * from tally counters. @@ -6600,6 +6653,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_destroy_phylink; } + for (int i = 0; i < tp->num_rx_rings; i++) + u64_stats_init(&tp->rx_ring[i].stats.syncp); + tp->rtl8169_napi = kcalloc(tp->irq_nvecs, sizeof(struct napi_struct), GFP_KERNEL); if (!tp->rtl8169_napi) { From 90d0cfb577db15d59dd7d9549f1f368753575d39 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:20 +0800 Subject: [PATCH 1897/2126] r8169: add support and enable rss This patch adds support and enable rss for RTL8127. It requests 30 to 32 MSI-X vectors. To support RSS, this patch converts struct RxDesc into a union. Additionly, this patch fixes a potential skb overrun issue. Previously, with NETIF_F_RXALL enabled, a runt or CRC-error desc with a length below 4 would fall through to subtract ETH_FCS_LEN. This will lead to a memory overrun. Fix this by explicitly dropping packets smaller than ETH_HLEN + ETH_FCS_LEN. Note that this fix introduces a behavior change on non-RSS chips: with both RXALL and RXFCS enabled, runt frames of 14 to 17 bytes that used to be delivered are now dropped. Ethtool rss tools will be contained in another series patched instead of this patch. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-6-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 418 ++++++++++++++++++++-- 1 file changed, 380 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 76f7a4592deb..671a20c6e39a 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -81,6 +81,19 @@ #define R8169_MAX_RX_QUEUES 8 #define R8169_DEFAULT_RX_QUEUES 1 #define R8169_MAX_TX_QUEUES 1 +#define R8127_MAX_NUM_IRQVEC 32 +#define R8127_MIN_NUM_IRQVEC 30 +#define R8169_IRQ_DEFAULT 1 +#define RTL_RSS_KEY_SIZE 40 +#define RSS_CPU_NUM_MASK GENMASK(18, 16) +#define RSS_HASH_MASK GENMASK(10, 8) +#define RTL_MAX_INDIRECTION_TABLE_ENTRIES 128 +#define RXS_RSS_UDP BIT(27) +#define RXS_RSS_IPV4 BIT(28) +#define RXS_RSS_IPV6 BIT(29) +#define RXS_RSS_TCP BIT(30) +#define RXS_RSS_L3_TYPE_MASK (RXS_RSS_IPV4 | RXS_RSS_IPV6) +#define RXS_RSS_L4_TYPE_MASK (RXS_RSS_TCP | RXS_RSS_UDP) #define OCP_STD_PHY_BASE 0xa400 @@ -505,6 +518,9 @@ enum rtl_register_content { RxRUNT = (1 << 20), RxCRC = (1 << 19), + RXRUNT_RSS = (1 << 21), + RXCRC_RSS = (1 << 20), + /* ChipCmdBits */ StopReq = 0x80, CmdReset = 0x10, @@ -610,6 +626,20 @@ enum rtl_register_content { #define ISRIMR_LINKCHG BIT(29) #define ISRIMR_TOK_Q0 BIT(8) #define ISRIMR_ROK_Q0 BIT(0) +#define RTL_DESC_TYPE_CTRL 0xd8 +#define RSS_KEY_REG 0x4600 +#define RSS_INDIRECTION_TBL_REG 0x4700 +#define RSS_CTRL_TCP_IPV4_SUPP BIT(0) +#define RTL_DESC_TYPE_RSS BIT(1) +#define RSS_CTRL_IPV4_SUPP BIT(1) +#define RSS_CTRL_TCP_IPV6_SUPP BIT(2) +#define RSS_CTRL_IPV6_SUPP BIT(3) +#define RSS_CTRL_IPV6_EXT_SUPP BIT(4) +#define RSS_CTRL_TCP_IPV6_EXT_SUPP BIT(5) +#define RSS_CTRL_UDP_IPV4_SUPP BIT(11) +#define RSS_CTRL_UDP_IPV6_SUPP BIT(12) +#define RX_RES_RSS BIT(22) +#define RTL_RX_Q_NUM_MASK GENMASK(4, 2) }; enum rtl_desc_bit { @@ -667,6 +697,11 @@ enum rtl_rx_desc_bit { #define RxProtoIP (PID1 | PID0) #define RxProtoMask RxProtoIP +#define RX_UDPT_DESC_RSS BIT(19) +#define RX_TCPT_DESC_RSS BIT(18) +#define RX_UDPF_DESC_RSS BIT(16) /* UDP/IP checksum failed */ +#define RX_TCPF_DESC_RSS BIT(15) /* TCP/IP checksum failed */ + IPFail = (1 << 16), /* IP checksum failed */ UDPFail = (1 << 15), /* UDP/IP checksum failed */ TCPFail = (1 << 14), /* TCP/IP checksum failed */ @@ -688,9 +723,27 @@ struct TxDesc { }; struct RxDesc { - __le32 opts1; - __le32 opts2; - __le64 addr; + union { + /* RX_DESC_TYPE_DEFAULT */ + struct { + __le32 opts1; + __le32 opts2; + __le64 addr; + }; + + /* RX_DESC_TYPE_RSS */ + struct { + union { + __le64 rss_addr; + struct { + __le32 rss_info; + __le32 rss_result; + } rss_dword; + }; + __le32 rss_opts2; + __le32 rss_opts1; + }; + }; }; struct ring_info { @@ -762,6 +815,11 @@ enum rtl_dash_type { RTL_DASH_25_BP, }; +enum rx_desc_type { + RX_DESC_TYPE_DEFAULT, + RX_DESC_TYPE_RSS, +}; + struct rtl8169_rx_ring { u32 cur_rx; struct RxDesc *rx_desc_array; @@ -785,6 +843,12 @@ enum rtl_sfp_mode { RTL_SFP_8127_ATF, }; +struct rtl8169_rss_data { + u8 rss_key[RTL_RSS_KEY_SIZE]; + u8 rss_indir_tbl[RTL_MAX_INDIRECTION_TABLE_ENTRIES]; + unsigned int hw_supp_indir_tbl_entries; +}; + struct rtl8169_private { void __iomem *mmio_addr; /* memory map physical address */ struct pci_dev *pci_dev; @@ -805,7 +869,9 @@ struct rtl8169_private { u16 tx_lpi_timer; u32 irq_mask; unsigned int hw_supp_num_rx_queues; + struct rtl8169_rss_data *rss_data; unsigned int irq_nvecs; + enum rx_desc_type init_rx_desc_type; struct clk *clk; int speed; @@ -1720,6 +1786,11 @@ static enum rtl_sfp_mode rtl_get_sfp_mode(struct rtl8169_private *tp) return RTL_SFP_NONE; } +static bool rtl_hw_support_rss(struct rtl8169_private *tp) +{ + return tp->mac_version == RTL_GIGA_MAC_VER_80; +} + static enum rtl_dash_type rtl_get_dash_type(struct rtl8169_private *tp) { switch (tp->mac_version) { @@ -2019,9 +2090,20 @@ static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; } -static void rtl8169_rx_vlan_tag(struct RxDesc *desc, struct sk_buff *skb) +static void rtl8169_rx_vlan_tag(struct rtl8169_private *tp, + struct RxDesc *desc, + struct sk_buff *skb) { - u32 opts2 = le32_to_cpu(desc->opts2); + u32 opts2; + + switch (tp->init_rx_desc_type) { + case RX_DESC_TYPE_RSS: + opts2 = le32_to_cpu(desc->rss_opts2); + break; + default: + opts2 = le32_to_cpu(desc->opts2); + break; + } if (opts2 & RxVlanTag) __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); @@ -2825,17 +2907,27 @@ static void rtl_hw_reset(struct rtl8169_private *tp) rtl_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); } +static void rtl8169_init_rss(struct rtl8169_private *tp) +{ + for (int i = 0; i < tp->rss_data->hw_supp_indir_tbl_entries; i++) + tp->rss_data->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, tp->num_rx_rings); + + netdev_rss_key_fill(tp->rss_data->rss_key, RTL_RSS_KEY_SIZE); +} + static void rtl_setup_rx_params(struct rtl8169_private *tp) { tp->num_rx_rings = 1; switch (tp->mac_version) { case RTL_GIGA_MAC_VER_80: tp->hw_supp_num_rx_queues = R8169_MAX_RX_QUEUES; + tp->rss_data->hw_supp_indir_tbl_entries = RTL_MAX_INDIRECTION_TABLE_ENTRIES; break; default: tp->hw_supp_num_rx_queues = R8169_DEFAULT_RX_QUEUES; break; } + tp->init_rx_desc_type = RX_DESC_TYPE_DEFAULT; } static void rtl_request_firmware(struct rtl8169_private *tp) @@ -2960,6 +3052,58 @@ static void rtl_set_rx_max_size(struct rtl8169_private *tp) RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); } +static void rtl8169_store_rss_key(struct rtl8169_private *tp) +{ + u8 *rss_key = tp->rss_data->rss_key; + const u16 rss_key_reg = RSS_KEY_REG; + + /* Write RSS key to HW */ + for (int i = 0; i < RTL_RSS_KEY_SIZE; i += sizeof(u32)) + RTL_W32(tp, rss_key_reg + i, get_unaligned_le32(rss_key + i)); +} + +static void rtl8169_store_reta(struct rtl8169_private *tp) +{ + u8 *indir_tbl = tp->rss_data->rss_indir_tbl; + unsigned int i; + + /* Write redirection table to HW */ + for (i = 0; i < tp->rss_data->hw_supp_indir_tbl_entries; i += 4) { + u32 reta = get_unaligned_le32(&indir_tbl[i]); + + RTL_W32(tp, RSS_INDIRECTION_TBL_REG + i, reta); + } +} + +static void rtl8169_set_rss_hash_opt(struct rtl8169_private *tp) +{ + u32 rss_ctrl; + + rss_ctrl = FIELD_PREP(RSS_CPU_NUM_MASK, ilog2(tp->num_rx_rings)); + + /* Perform hash on these packet types */ + rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP | + RSS_CTRL_IPV4_SUPP | + RSS_CTRL_IPV6_SUPP | + RSS_CTRL_IPV6_EXT_SUPP | + RSS_CTRL_TCP_IPV6_SUPP | + RSS_CTRL_TCP_IPV6_EXT_SUPP | + RSS_CTRL_UDP_IPV4_SUPP | + RSS_CTRL_UDP_IPV6_SUPP; + + rss_ctrl |= FIELD_PREP(RSS_HASH_MASK, + ilog2(tp->rss_data->hw_supp_indir_tbl_entries)); + + RTL_W32(tp, RSS_CTRL_8125, rss_ctrl); +} + +static void rtl_set_rss_config(struct rtl8169_private *tp) +{ + rtl8169_set_rss_hash_opt(tp); + rtl8169_store_reta(tp); + rtl8169_store_rss_key(tp); +} + static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) { struct rtl8169_rx_ring *ring = &tp->rx_ring[0]; @@ -4093,6 +4237,18 @@ DECLARE_RTL_COND(rtl_mac_ocp_e00e_cond) return r8168_mac_ocp_read(tp, 0xe00e) & BIT(13); } +static void rtl8125_set_rx_q_num(struct rtl8169_private *tp) +{ + u16 rx_q_num; + u16 q_ctrl; + + rx_q_num = ilog2(tp->num_rx_rings); + q_ctrl = RTL_R16(tp, Q_NUM_CTRL_8125); + q_ctrl &= ~RTL_RX_Q_NUM_MASK; + q_ctrl |= FIELD_PREP(RTL_RX_Q_NUM_MASK, rx_q_num); + RTL_W16(tp, Q_NUM_CTRL_8125, q_ctrl); +} + static void rtl8169_hw_enable_vec_mapping(struct rtl8169_private *tp) { u8 tmp; @@ -4132,6 +4288,13 @@ static void rtl_hw_start_8125_common(struct rtl8169_private *tp) tp->mac_version == RTL_GIGA_MAC_VER_80) RTL_W8(tp, 0xD8, RTL_R8(tp, 0xD8) & ~0x02); + /* enable rx descriptor type v4 and set queue num for rss */ + if (tp->num_rx_rings > 1) { + rtl8125_set_rx_q_num(tp); + RTL_W8(tp, RTL_DESC_TYPE_CTRL, + RTL_R8(tp, RTL_DESC_TYPE_CTRL) | RTL_DESC_TYPE_RSS); + } + if (tp->mac_version == RTL_GIGA_MAC_VER_80) r8168_mac_ocp_modify(tp, 0xe614, 0x0f00, 0x0f00); else if (tp->mac_version == RTL_GIGA_MAC_VER_70) @@ -4368,6 +4531,12 @@ static void rtl_hw_start(struct rtl8169_private *tp) rtl_hw_aspm_clkreq_enable(tp, true); rtl_set_rx_max_size(tp); rtl_set_rx_tx_desc_registers(tp); + if (rtl_is_8125(tp)) { + if (tp->num_rx_rings > 1) + rtl_set_rss_config(tp); + else + RTL_W32(tp, RSS_CTRL_8125, 0x00); + } rtl_lock_config_regs(tp); rtl_jumbo_config(tp); @@ -4406,14 +4575,26 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) return 0; } -static void rtl8169_mark_to_asic(struct RxDesc *desc) +static void rtl8169_mark_to_asic(struct rtl8169_private *tp, struct RxDesc *desc) { - u32 eor = le32_to_cpu(desc->opts1) & RingEnd; + u32 eor; - desc->opts2 = 0; - /* Force memory writes to complete before releasing descriptor */ - dma_wmb(); - WRITE_ONCE(desc->opts1, cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE)); + switch (tp->init_rx_desc_type) { + case RX_DESC_TYPE_RSS: + eor = le32_to_cpu(desc->rss_opts1) & RingEnd; + desc->rss_opts2 = cpu_to_le32(0); + /* Force memory writes to complete before releasing descriptor */ + dma_wmb(); + WRITE_ONCE(desc->rss_opts1, cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE)); + break; + default: + eor = le32_to_cpu(desc->opts1) & RingEnd; + desc->opts2 = cpu_to_le32(0); + /* Force memory writes to complete before releasing descriptor */ + dma_wmb(); + WRITE_ONCE(desc->opts1, cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE)); + break; + } } static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp, @@ -4436,9 +4617,12 @@ static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp, return NULL; } - desc->addr = cpu_to_le64(mapping); ring->rx_buf_dma_addr[index] = mapping; - rtl8169_mark_to_asic(desc); + if (tp->init_rx_desc_type == RX_DESC_TYPE_RSS) + desc->rss_addr = cpu_to_le64(mapping); + else + desc->addr = cpu_to_le64(mapping); + rtl8169_mark_to_asic(tp, desc); return data; } @@ -4455,8 +4639,25 @@ static void rtl8169_rx_clear(struct rtl8169_private *tp, __free_pages(ring->rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); ring->rx_databuff[i] = NULL; ring->rx_buf_dma_addr[i] = 0; - ring->rx_desc_array[i].addr = 0; - ring->rx_desc_array[i].opts1 = 0; + if (tp->init_rx_desc_type == RX_DESC_TYPE_RSS) { + ring->rx_desc_array[i].rss_addr = 0; + ring->rx_desc_array[i].rss_opts1 = 0; + } else { + ring->rx_desc_array[i].addr = 0; + ring->rx_desc_array[i].opts1 = 0; + } + } +} + +static void rtl8169_mark_as_last_descriptor(struct rtl8169_private *tp, struct RxDesc *desc) +{ + switch (tp->init_rx_desc_type) { + case RX_DESC_TYPE_RSS: + desc->rss_opts1 |= cpu_to_le32(RingEnd); + break; + default: + desc->opts1 |= cpu_to_le32(RingEnd); + break; } } @@ -4476,7 +4677,7 @@ static int rtl8169_rx_fill(struct rtl8169_private *tp, struct rtl8169_rx_ring *r } /* mark as last descriptor in the ring */ - ring->rx_desc_array[NUM_RX_DESC - 1].opts1 |= cpu_to_le32(RingEnd); + rtl8169_mark_as_last_descriptor(tp, &ring->rx_desc_array[NUM_RX_DESC - 1]); return 0; } @@ -4641,8 +4842,13 @@ static void rtl8169_rx_desc_reset(struct rtl8169_private *tp) for (int i = 0; i < tp->num_rx_rings; i++) { struct rtl8169_rx_ring *ring = &tp->rx_ring[i]; - for (int j = 0; j < NUM_RX_DESC; j++) - rtl8169_mark_to_asic(ring->rx_desc_array + j); + for (int j = 0; j < NUM_RX_DESC; j++) { + dma_addr_t phy_addr = ring->rx_buf_dma_addr[j]; + + if (tp->init_rx_desc_type == RX_DESC_TYPE_RSS) + ring->rx_desc_array[j].rss_addr = cpu_to_le64(phy_addr); + rtl8169_mark_to_asic(tp, ring->rx_desc_array + j); + } } } @@ -5098,27 +5304,95 @@ static inline int rtl8169_fragmented_frame(u32 status) return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); } -static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) +static void rtl8169_rx_hash(struct rtl8169_private *tp, + struct RxDesc *desc, + struct sk_buff *skb) { - u32 status = opts1 & (RxProtoMask | RxCSFailMask); + u32 rss_header_info; + u32 hash_val; - if (status == RxProtoTCP || status == RxProtoUDP) + if (!(tp->dev->features & NETIF_F_RXHASH)) + return; + + rss_header_info = le32_to_cpu(desc->rss_dword.rss_info); + + if (!(rss_header_info & RXS_RSS_L3_TYPE_MASK)) + return; + + hash_val = le32_to_cpu(desc->rss_dword.rss_result); + + skb_set_hash(skb, hash_val, + (RXS_RSS_L4_TYPE_MASK & rss_header_info) ? + PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); +} + +static void rtl8169_rx_csum(struct rtl8169_private *tp, + struct sk_buff *skb, + u32 opts1) +{ + bool csum_ok = false; + + switch (tp->init_rx_desc_type) { + case RX_DESC_TYPE_RSS: + if (((opts1 & RX_TCPT_DESC_RSS) && !(opts1 & RX_TCPF_DESC_RSS)) || + ((opts1 & RX_UDPT_DESC_RSS) && !(opts1 & RX_UDPF_DESC_RSS))) + csum_ok = true; + break; + default: { + u32 status = opts1 & (RxProtoMask | RxCSFailMask); + + if (status == RxProtoTCP || status == RxProtoUDP) + csum_ok = true; + break; + } + } + + if (csum_ok) skb->ip_summed = CHECKSUM_UNNECESSARY; else skb_checksum_none_assert(skb); } +static __le32 rtl8169_rx_desc_opts1(struct rtl8169_private *tp, struct RxDesc *desc) +{ + switch (tp->init_rx_desc_type) { + case RX_DESC_TYPE_RSS: + return READ_ONCE(desc->rss_opts1); + default: + return READ_ONCE(desc->opts1); + } +} + static bool rtl8169_check_rx_desc_error(struct rtl8169_rx_ring *ring, + struct rtl8169_private *tp, u32 status) { - if (unlikely(status & RxRES)) { - u64_stats_update_begin(&ring->stats.syncp); - if (status & (RxRWT | RxRUNT)) - ring->stats.rx_length_errors++; - if (status & RxCRC) - ring->stats.rx_crc_errors++; - u64_stats_update_end(&ring->stats.syncp); - return true; + switch (tp->init_rx_desc_type) { + case RX_DESC_TYPE_RSS: + if (unlikely(status & RX_RES_RSS)) { + u64_stats_update_begin(&ring->stats.syncp); + + /* Note: The RTL8127 RSS descriptor layout does not have + * an RxRWT (Receive Watchdog Timer / over-length) bit. + */ + if (status & RXRUNT_RSS) + ring->stats.rx_length_errors++; + if (status & RXCRC_RSS) + ring->stats.rx_crc_errors++; + u64_stats_update_end(&ring->stats.syncp); + return true; + } + break; + default: + if (unlikely(status & RxRES)) { + u64_stats_update_begin(&ring->stats.syncp); + if (status & (RxRWT | RxRUNT)) + ring->stats.rx_length_errors++; + if (status & RxCRC) + ring->stats.rx_crc_errors++; + u64_stats_update_end(&ring->stats.syncp); + return true; + } } return false; } @@ -5138,7 +5412,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, dma_addr_t addr; u32 status; - status = le32_to_cpu(READ_ONCE(desc->opts1)); + status = le32_to_cpu(rtl8169_rx_desc_opts1(tp, desc)); if (status & DescOwn) break; @@ -5148,7 +5422,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, */ dma_rmb(); - if (rtl8169_check_rx_desc_error(ring, status)) { + if (rtl8169_check_rx_desc_error(ring, tp, status)) { if (net_ratelimit()) netdev_warn(dev, "Rx ERROR. status = %08x\n", status); @@ -5158,11 +5432,21 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, if (!(dev->features & NETIF_F_RXALL)) goto release_descriptor; - else if (status & RxRWT || !(status & (RxRUNT | RxCRC))) - goto release_descriptor; + + if (tp->init_rx_desc_type == RX_DESC_TYPE_DEFAULT) { + if (status & RxRWT || !(status & (RxRUNT | RxCRC))) + goto release_descriptor; + } else { + if (!(status & (RXRUNT_RSS | RXCRC_RSS))) + goto release_descriptor; + } } pkt_size = status & GENMASK(13, 0); + + if (unlikely(pkt_size < ETH_HLEN + ETH_FCS_LEN)) + goto release_descriptor; + if (likely(!(dev->features & NETIF_F_RXFCS))) pkt_size -= ETH_FCS_LEN; @@ -5195,10 +5479,14 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, skb->len = pkt_size; dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); - rtl8169_rx_csum(skb, status); + if (tp->num_rx_rings > 1) { + rtl8169_rx_hash(tp, desc, skb); + skb_record_rx_queue(skb, ring - tp->rx_ring); + } + rtl8169_rx_csum(tp, skb, status); skb->protocol = eth_type_trans(skb, dev); - rtl8169_rx_vlan_tag(desc, skb); + rtl8169_rx_vlan_tag(tp, desc, skb); if (skb->pkt_type == PACKET_MULTICAST) { u64_stats_update_begin(&ring->stats.syncp); @@ -5210,7 +5498,9 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, dev_sw_netstats_rx_add(dev, pkt_size); release_descriptor: - rtl8169_mark_to_asic(desc); + if (tp->init_rx_desc_type == RX_DESC_TYPE_RSS) + desc->rss_addr = cpu_to_le64(ring->rx_buf_dma_addr[entry]); + rtl8169_mark_to_asic(tp, desc); } return count; @@ -5828,11 +6118,39 @@ static void rtl_set_irq_mask(struct rtl8169_private *tp) } } +static int get_max_irq_nvecs(struct rtl8169_private *tp) +{ + if (tp->mac_version == RTL_GIGA_MAC_VER_80) + return R8127_MAX_NUM_IRQVEC; + return R8169_IRQ_DEFAULT; +} + +static int get_min_irq_nvecs(struct rtl8169_private *tp) +{ + if (tp->mac_version == RTL_GIGA_MAC_VER_80) + return R8127_MIN_NUM_IRQVEC; + return R8169_IRQ_DEFAULT; +} + +static void rtl8169_set_rx_ring_num(struct rtl8169_private *tp) +{ + if (tp->irq_nvecs >= get_min_irq_nvecs(tp)) { + unsigned int rss_queue_num = netif_get_num_default_rss_queues(); + + tp->num_rx_rings = rounddown_pow_of_two(min(rss_queue_num, + tp->hw_supp_num_rx_queues)); + if (tp->num_rx_rings >= 2) + tp->init_rx_desc_type = RX_DESC_TYPE_RSS; + } +} + static int rtl_alloc_irq(struct rtl8169_private *tp) { struct pci_dev *pdev = tp->pci_dev; unsigned int flags; - int nvecs; + int nvecs, min_nvecs; + + min_nvecs = get_min_irq_nvecs(tp); switch (tp->mac_version) { case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: @@ -5848,7 +6166,14 @@ static int rtl_alloc_irq(struct rtl8169_private *tp) break; } - nvecs = pci_alloc_irq_vectors(pdev, 1, 1, flags); + nvecs = pci_alloc_irq_vectors(pdev, min_nvecs, + get_max_irq_nvecs(tp), flags); + + if (nvecs < 0 && min_nvecs > 1) { + dev_info(&pdev->dev, "Failed to allocate %d MSI-X vectors.\n", + min_nvecs); + nvecs = pci_alloc_irq_vectors(pdev, 1, 1, flags); + } if (nvecs < 0) return nvecs; @@ -6533,6 +6858,13 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->dash_type = rtl_get_dash_type(tp); tp->dash_enabled = rtl_dash_is_enabled(tp); + if (rtl_hw_support_rss(tp)) { + tp->rss_data = devm_kzalloc(&pdev->dev, sizeof(*tp->rss_data), + GFP_KERNEL); + if (!tp->rss_data) + return -ENOMEM; + } + tp->cp_cmd = RTL_R16(tp, CPlusCmd) & CPCMD_MASK; if (sizeof(dma_addr_t) > 4 && tp->mac_version >= RTL_GIGA_MAC_VER_18 && @@ -6553,6 +6885,11 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc < 0) return dev_err_probe(&pdev->dev, rc, "Can't allocate interrupt\n"); + rtl8169_set_rx_ring_num(tp); + + if (rtl_hw_support_rss(tp)) + rtl8169_init_rss(tp); + INIT_WORK(&tp->wk.work, rtl_task); disable_work(&tp->wk.work); @@ -6565,6 +6902,11 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; + if (rtl_hw_support_rss(tp) && tp->num_rx_rings > 1) { + dev->hw_features |= NETIF_F_RXHASH; + dev->features |= NETIF_F_RXHASH; + } + /* * Pretend we are using VLANs; This bypasses a nasty bug where * Interrupts stop flowing on high load on 8110SCd controllers. From dcad1105f164309e81a65c6b316dfaba3ec90ce7 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:21 +0800 Subject: [PATCH 1898/2126] r8169: move struct ethtool_ops The patch moves the rtl8169_ethtool_ops definition further down in r8169_main.c so that subsequent additions of rtl8169_get_channels and can be referenced from the ops struct without needing forward declarations. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-7-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 56 +++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 671a20c6e39a..de0c860328ba 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -2636,34 +2636,6 @@ static int rtl8169_nway_reset(struct net_device *dev) return phylink_ethtool_nway_reset(tp->phylink); } -static const struct ethtool_ops rtl8169_ethtool_ops = { - .supported_coalesce_params = ETHTOOL_COALESCE_USECS | - ETHTOOL_COALESCE_MAX_FRAMES, - .get_drvinfo = rtl8169_get_drvinfo, - .get_regs_len = rtl8169_get_regs_len, - .get_link = ethtool_op_get_link, - .get_coalesce = rtl_get_coalesce, - .set_coalesce = rtl_set_coalesce, - .get_regs = rtl8169_get_regs, - .get_wol = rtl8169_get_wol, - .set_wol = rtl8169_set_wol, - .get_strings = rtl8169_get_strings, - .get_sset_count = rtl8169_get_sset_count, - .get_ethtool_stats = rtl8169_get_ethtool_stats, - .get_ts_info = ethtool_op_get_ts_info, - .nway_reset = rtl8169_nway_reset, - .get_eee = rtl8169_get_eee, - .set_eee = rtl8169_set_eee, - .get_link_ksettings = rtl8169_get_link_ksettings, - .set_link_ksettings = rtl8169_set_link_ksettings, - .get_ringparam = rtl8169_get_ringparam, - .get_pause_stats = rtl8169_get_pause_stats, - .get_pauseparam = rtl8169_get_pauseparam, - .set_pauseparam = rtl8169_set_pauseparam, - .get_eth_mac_stats = rtl8169_get_eth_mac_stats, - .get_eth_ctrl_stats = rtl8169_get_eth_ctrl_stats, -}; - static const struct rtl_chip_info *rtl8169_get_chip_version(u32 xid, bool gmii) { /* Chips combining a 1Gbps MAC with a 100Mbps PHY */ @@ -6769,6 +6741,34 @@ static void r8169_init_napi(struct rtl8169_private *tp) } } +static const struct ethtool_ops rtl8169_ethtool_ops = { + .supported_coalesce_params = ETHTOOL_COALESCE_USECS | + ETHTOOL_COALESCE_MAX_FRAMES, + .get_drvinfo = rtl8169_get_drvinfo, + .get_regs_len = rtl8169_get_regs_len, + .get_link = ethtool_op_get_link, + .get_coalesce = rtl_get_coalesce, + .set_coalesce = rtl_set_coalesce, + .get_regs = rtl8169_get_regs, + .get_wol = rtl8169_get_wol, + .set_wol = rtl8169_set_wol, + .get_strings = rtl8169_get_strings, + .get_sset_count = rtl8169_get_sset_count, + .get_ethtool_stats = rtl8169_get_ethtool_stats, + .get_ts_info = ethtool_op_get_ts_info, + .nway_reset = rtl8169_nway_reset, + .get_eee = rtl8169_get_eee, + .set_eee = rtl8169_set_eee, + .get_link_ksettings = rtl8169_get_link_ksettings, + .set_link_ksettings = rtl8169_set_link_ksettings, + .get_ringparam = rtl8169_get_ringparam, + .get_pause_stats = rtl8169_get_pause_stats, + .get_pauseparam = rtl8169_get_pauseparam, + .set_pauseparam = rtl8169_set_pauseparam, + .get_eth_mac_stats = rtl8169_get_eth_mac_stats, + .get_eth_ctrl_stats = rtl8169_get_eth_ctrl_stats, +}; + static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { const struct rtl_chip_info *chip; From aaf99d89a72a798845ff5cb4167bc32f84e52439 Mon Sep 17 00:00:00 2001 From: Javen Xu Date: Thu, 8 Oct 2026 14:57:22 +0800 Subject: [PATCH 1899/2126] r8169: add get_channel support for ethtool Add get_channel support for ethtool. In multi-vector mode, it reports the active RX channel count and a single TX channel. Additionly, it reports one other channel to account for the dedicated link-change interrupt vector. In single-vector mode, where RX, TX, link-change events share the same interrupt, it reports a single combined channel. Signed-off-by: Javen Xu Link: https://patch.msgid.link/20261008065722.1026-8-javen_xu@realsil.com.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index de0c860328ba..88354e7570f0 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -6741,6 +6741,24 @@ static void r8169_init_napi(struct rtl8169_private *tp) } } +static void rtl8169_get_channels(struct net_device *dev, + struct ethtool_channels *ch) +{ + struct rtl8169_private *tp = netdev_priv(dev); + + if (tp->irq_nvecs > 1) { + ch->max_rx = tp->hw_supp_num_rx_queues; + ch->max_tx = 1; + ch->max_other = 1; + ch->rx_count = tp->num_rx_rings; + ch->tx_count = 1; + ch->other_count = 1; + } else { + ch->max_combined = 1; + ch->combined_count = 1; + } +} + static const struct ethtool_ops rtl8169_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES, @@ -6759,6 +6777,7 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .nway_reset = rtl8169_nway_reset, .get_eee = rtl8169_get_eee, .set_eee = rtl8169_set_eee, + .get_channels = rtl8169_get_channels, .get_link_ksettings = rtl8169_get_link_ksettings, .set_link_ksettings = rtl8169_set_link_ksettings, .get_ringparam = rtl8169_get_ringparam, From 819d5963879630cde5811b14f29514e7ea457229 Mon Sep 17 00:00:00 2001 From: Tim Fuechsel Date: Thu, 8 Oct 2026 11:16:36 +0200 Subject: [PATCH 1900/2126] tcp: Add TCP ROCCET congestion control module. TCP ROCCET is a new congestion control algorithm based on TCP CUBIC that improves its overall performance in cellular networks. By its mode of function, CUBIC causes bufferbloat while it tries to detect the available throughput of a network path. This is particularly a problem with large buffers in mobile networks. A more detailed description and analysis of this problem caused by TCP CUBIC can be found in [1]. TCP ROCCET's main method of addressing the bufferbloat problem is by adding two additional metrics. The first metric is the relative increase in RTT from its minimum, the srRTT. Here, bufferbloat can be detected when RTTs increase due to buffer filling. The second metric is the acknowledgment arrival rate sampled over 100ms intervals and the bytes sent and received over 5 RTTs. If CUBIC increases the send rate or congestion window, and the acknowledgment arrival rate stays at the same level, the connection is limited by the bottleneck link's capacity. In such cases, ROCCET reduces the send rate to prevent bufferbloat. ROCCET uses a modified version of slow start rather than HyStart because HyStart is known to enter the congestion avoidance phase too early when used in cellular networks [2]. Therefore, ROCCET uses a combination of srRTT and the acknowledgment arrival rate to determine when to exit slow start. For the congestion avoidance phase, ROCCET relies on the srRTT and monitoring the sent and received bytes to detect the filling of the bottleneck buffer. To keep the minimum RTT updated, ROCCET performs minimum RTT probing if no new minimum RTT was found in the last 5 seconds. To this end ROCCET halves the cwnd and probes for 200ms but at least for one RTT, for a new minimum RTT. After probing, ROCCET refills the pipe carefully. In addition, ROCCET reacts to packet loss by adapting CUBIC's behavior. ECNs are handled as ROCCET congestion event, where the cwnd gets reduced and ROCCET enters a buffer drain state. In real-world mobile 5G NR measurements, TCP ROCCET achieves better performance than CUBIC, by maintaining similar throughput while reducing the latency. More information about TCP ROCCET and measurement evaluations can be found here [3]. For the version (2026-07-21), we provide additional performance evaluation regarding throughput, latency, and bandwidth share [4]. [1] https://doi.org/10.1109/VTC2023-Fall60731.2023.10333357 [2] https://doi.org/10.1109/WMNC.2016.7543932 [3] https://doi.org/10.23919/WONS68803.2026.11501781 [4] http://go.lu-h.de/roccet-2026-07-21 Co-developed-by: Lukas Prause Signed-off-by: Lukas Prause Signed-off-by: Tim Fuechsel Link: https://patch.msgid.link/asdfdDIQb7Nhm692@volt-roccet-vm Signed-off-by: Jakub Kicinski --- net/ipv4/Kconfig | 12 + net/ipv4/Makefile | 1 + net/ipv4/tcp_roccet.c | 1408 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1421 insertions(+) create mode 100644 net/ipv4/tcp_roccet.c diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig index 301b47660305..3545fb0a045b 100644 --- a/net/ipv4/Kconfig +++ b/net/ipv4/Kconfig @@ -663,6 +663,18 @@ config TCP_CONG_CDG delay gradients." In Networking 2011. Preprint: http://caia.swin.edu.au/cv/dahayes/content/networking2011-cdg-preprint.pdf +config TCP_CONG_ROCCET + tristate "ROCCET TCP" + default n + help + TCP ROCCET (RTT oriented CUBIC congestion control exTension) is a + sender-side-only congestion control algorithm based on the TCP CUBIC + protocol stack/TCP CUBIC congestion control algorithm that optimizes + its performance. Especially for networks with large buffers + (wireless, cellular networks), TCP ROCCET has improved performance by + maintaining a similar throughput as CUBIC while reducing latency. + For more information, see: https://arxiv.org/abs/2510.25281 + config TCP_CONG_BBR tristate "BBR TCP" default n diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile index 06e21c26b76f..69e4baaed122 100644 --- a/net/ipv4/Makefile +++ b/net/ipv4/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_INET_TCP_DIAG) += tcp_diag.o obj-$(CONFIG_INET_UDP_DIAG) += udp_diag.o obj-$(CONFIG_INET_RAW_DIAG) += raw_diag.o obj-$(CONFIG_TCP_CONG_BBR) += tcp_bbr.o +obj-$(CONFIG_TCP_CONG_ROCCET) += tcp_roccet.o obj-$(CONFIG_TCP_CONG_BIC) += tcp_bic.o obj-$(CONFIG_TCP_CONG_CDG) += tcp_cdg.o obj-$(CONFIG_TCP_CONG_CUBIC) += tcp_cubic.o diff --git a/net/ipv4/tcp_roccet.c b/net/ipv4/tcp_roccet.c new file mode 100644 index 000000000000..04b9e5246612 --- /dev/null +++ b/net/ipv4/tcp_roccet.c @@ -0,0 +1,1408 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * TCP ROCCET: An RTT-Oriented CUBIC Congestion Control + * Extension for 5G and Beyond Networks + * + * TCP ROCCET is a new TCP congestion control + * algorithm suited for current cellular 5G NR beyond networks. + * It extends the kernel default congestion control CUBIC + * and improves its performance, and additionally solves an + * unwanted side effects of CUBIC’s implementation. + * ROCCET uses its own Slow Start, called LAUNCH, where loss + * is not considered as a congestion event. + * The congestion avoidance phase, called ORBITER, uses + * CUBIC's window growth function and adds, based on RTT + * and ACK rate, congestion events. + * + * A peer-reviewed paper on TCP ROCCET which was presented + * at the WONS 2026 conference is available here: + * https://opendl.ifip-tc6.org/db/conf/wons/wons2026/1571217211.pdf + * + * + * This module is based on the kernel CUBIC TCP implementation + * (see net/ipv4/tcp_cubic.c). Branched module at kernel version 7.1. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Scale factor beta calculation (max_cwnd = snd_cwnd * beta) */ +#define BICTCP_BETA_SCALE 1024 + +#define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */ + +/* Alpha value for the srRTT multiplied by 100. + * Here 20 represents a value of 0.2 + */ +#define ROCCET_ALPHA_TIMES_100 20 + +/* min RTT probe period in ms */ +#define ROCCET_NEXT_MIN_RTT_PROBE_MS 5000 + +/* The maximum interval length of a min RTT probe + * (and consequently also the max interval for the refill). + */ +#define ROCCET_MAX_PROBE_INTERVAL_MS 10000 + +#define ROCCET_MAX_SRRTT_CHECK_INTERVAL_MS (5 * 200) + +/* State in which roccet currently operates */ +enum roccet_state { + LAUNCH, + ORBITER, + RTT_PROBE_ENTER, + RTT_PROBE, + RTT_PROBE_REFILL, + DRAIN +}; + +/* TCP ROCCET struct based on the original BICTCP struct with + * additions specific to the ROCCET-Algorithm. + */ +struct roccettcp { + u32 cnt; /* increase cwnd by 1 after ACKs */ + u32 last_max_cwnd; /* last maximum snd_cwnd */ + u32 last_cwnd; /* the last snd_cwnd */ + u32 last_time; /* time when updated last_cwnd */ + u32 bic_origin_point; /* origin point of bic function */ + u32 bic_K; /* time to origin point from the + * beginning of the current epoch + */ + u32 delay_min; /* min delay (usec) */ + u32 epoch_start; /* beginning of an epoch */ + u32 ack_cnt; /* number of acks */ + u32 tcp_cwnd; /* estimated tcp cwnd */ + u32 curr_rtt; /* last sample rtt of current round */ + + u32 roccet_last_event_time_us; /* The last time ROCCET was triggered */ + u32 curr_min_rtt; /* The current observed minRTT */ + u32 next_min_rtt_probe; /* Next time to probe the minRTT */ + u32 probe_min_rtt_until; /* End of minRTT probing period. + * Set while in RTT_PROBE states + */ + u32 refill_until; /* End of pipe refill after minRTT probe. + * Set while in RTT_PROBE states + */ + u32 cwnd_before_min_rtt_probe; /* cwnd before min RTT probing. */ + u32 curr_srrtt; /* srRTT calculated based on the latest ACK */ + u32 next_srrtt_check_ts; /* Next check for srRTT */ + u32 last_rtt; /* sample rtt of previous round. + * Used for jitter calculation + */ + + u32 interval_snd_seq_start; + u32 interval_una_seq_start; + + u32 ack_carry_over; /* Used to carry over leftover acks from + * LAUNCH to ORBITER + */ + + u32 last_ack_rate_time; /* Timestamp of the last ACK-rate */ + u16 ack_rate_last_rate; /* Last ACK-rate */ + u16 curr_ack_rate; /* Current ACK-rate */ + u16 ack_rate_cnt; /* Used for counting acks */ + + enum roccet_state state : 3; /* Current operating state of roccet */ + bool initial_limit_reached: 1; /* Set to true after the connection + * initially gets cwnd-limited + */ + bool is_in_initial_launch: 1; /* true if the connection is in + * the initial launch phase. + */ + bool last_event_time_set: 1; /* true if the last event time + * has been set/initialized. + */ + bool rtt_probe_timers_set: 1; /* true if refill_until and + * probe_min_rtt_until are currently + * set. + */ +}; + +/* Parameters that are specific to the ROCCET-Algorithm */ +static uint sr_rtt_upper_bound __read_mostly = 100; +static int ack_rate_diff_ss __read_mostly = 10; + +module_param(sr_rtt_upper_bound, uint, 0644); +MODULE_PARM_DESC(sr_rtt_upper_bound, "ROCCET's upper bound for srRTT."); +module_param(ack_rate_diff_ss, int, 0644); +MODULE_PARM_DESC(ack_rate_diff_ss, + "ROCCET's threshold to exit slow start if ACK-rate differs by given amount of segments."); + +static int fast_convergence __read_mostly = 1; +static int beta __read_mostly = 717; /* = 717/1024 (BICTCP_BETA_SCALE) */ +static int initial_ssthresh __read_mostly; +static int bic_scale __read_mostly = 41; +static int tcp_friendliness __read_mostly = 1; + +static u32 cube_rtt_scale __read_mostly; +static u32 beta_scale __read_mostly; +static u64 cube_factor __read_mostly; + +static int beta_param_set(const char *val, const struct kernel_param *kp); +static const struct kernel_param_ops beta_param_ops = { + .set = beta_param_set, + .get = param_get_int, +}; +module_param_cb(beta, &beta_param_ops, &beta, 0644); +MODULE_PARM_DESC(beta, "beta factor for multiplicative decrease"); + +module_param(fast_convergence, int, 0644); +MODULE_PARM_DESC(fast_convergence, "turn on/off fast convergence"); +module_param(initial_ssthresh, int, 0644); +MODULE_PARM_DESC(initial_ssthresh, "initial value of slow start threshold"); +module_param(bic_scale, int, 0444); +MODULE_PARM_DESC(bic_scale, + "scale (scaled by 1024) value for bic function (bic_scale/1024)"); +module_param(tcp_friendliness, int, 0644); +MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness"); + +/* Check & set the new beta parameter candidate value. + */ +static int beta_param_set(const char *val, const struct kernel_param *kp) +{ + int beta_candidate; + int ret = kstrtoint(val, 10, &beta_candidate); + + if (ret) + return ret; + + if (beta_candidate <= 0 || beta_candidate >= BICTCP_BETA_SCALE) { + pr_err_once("TCP ROCCET: beta must be between 0 and %d\n", + BICTCP_BETA_SCALE); + + return -EINVAL; + } + + return param_set_int(val, kp); +} + +/* Used to check certain roccet parameters used in `param_precompute` in order + * to avoid invalid scale-related calculations. This validates the specified + * parameters or rejects them. + */ +static int param_check(void) +{ + if (beta <= 0 || beta >= BICTCP_BETA_SCALE) { + pr_err_once("TCP ROCCET: beta must be between 0 and %d\n", + BICTCP_BETA_SCALE); + + return -EINVAL; + } + + if (bic_scale <= 0) { + pr_err_once("TCP ROCCET: bic_scale must be positive\n"); + + return -EINVAL; + } + + return 0; +} + +/* Precompute some values based on the provided params. + * These are only precomputed during module initialization and are not updated + * during runtime. Parameter changes at runtime will only affect the next uses + * of the parameters, but not the precomputed values. + */ +static void param_precompute(void) +{ + /* Precompute a bunch of the scaling factors that are used per-packet + * based on sRTT of 100ms. + */ + beta_scale = + 8 * (BICTCP_BETA_SCALE + beta) / 3 / (BICTCP_BETA_SCALE - beta); + + cube_rtt_scale = (bic_scale * 10); /* 1024*c/rtt */ + + /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3 + * so K = cubic_root( (wmax-cwnd)*rtt/c ) + * the unit of K is bictcp_HZ=2^10, not HZ + * + * c = bic_scale >> 10 + * rtt = 100ms + * + * the following code has been designed and tested for + * cwnd < 1 million packets + * RTT < 100 seconds + * HZ < 1,000,00 (corresponding to 10 nano-second) + */ + + /* 1/c * 2^2*bictcp_HZ * srtt */ + cube_factor = 1ull << (10 + 3 * BICTCP_HZ); /* 2^40 */ + + /* divide by bic_scale and by constant srtt (100ms) */ + do_div(cube_factor, bic_scale * 10); +} + +static void roccet_reset(struct sock *sk, struct roccettcp *ca) +{ + /* Save previous state for parameters that should not be reset */ + bool prev_initial_limit_reached = ca->initial_limit_reached; + bool prev_is_in_initial_launch = ca->is_in_initial_launch; + + /* Reset all the roccet parameters and later restore the ones that + * shouldn't be zero. + */ + memset(ca, 0, sizeof(struct roccettcp)); + + /* Initialize all RTT values to U32_MAX, so that any lower samples + * will be accepted. + */ + ca->curr_min_rtt = U32_MAX; + ca->curr_rtt = U32_MAX; + ca->last_rtt = U32_MAX; + + /* Initialize the last event time to the current time, to use it for + * temporarily knowing when the connection started (only used for this + * after init). + */ + ca->roccet_last_event_time_us = jiffies_to_usecs(tcp_jiffies32); + + /* Initialize to current time to avoid an + * overflow in the ack rate calculation + */ + ca->last_ack_rate_time = jiffies_to_usecs(tcp_jiffies32); + + ca->interval_snd_seq_start = tcp_sk(sk)->snd_nxt; + ca->interval_una_seq_start = tcp_sk(sk)->snd_una; + + /* Start state is LAUNCH */ + ca->state = LAUNCH; + + /* Set saved state for certain parameters */ + ca->initial_limit_reached = prev_initial_limit_reached; + ca->is_in_initial_launch = prev_is_in_initial_launch; +} + +static void roccet_init(struct sock *sk) +{ + struct roccettcp *ca = inet_csk_ca(sk); + + roccet_reset(sk, ca); + + /* Reset some parameters here, so they only get set during init */ + ca->initial_limit_reached = false; + ca->is_in_initial_launch = true; + + if (initial_ssthresh) + WRITE_ONCE(tcp_sk(sk)->snd_ssthresh, initial_ssthresh); + + cmpxchg(&sk->sk_pacing_status, SK_PACING_NONE, SK_PACING_NEEDED); +} + +static void roccet_set_next_srrtt_check_ts(struct roccettcp *ca, u32 now) +{ + /* Check the srrtt after 5 RTT's. Cap the assumed RTT's + * at 200 ms each => 1 sec max. + */ + ca->next_srrtt_check_ts = now + min(5 * ca->curr_rtt, + ROCCET_MAX_SRRTT_CHECK_INTERVAL_MS + * USEC_PER_MSEC); +} + +static void roccet_set_next_min_rtt_probe_ts(struct roccettcp *ca) +{ + /* Probe for the min RTT in ROCCET_NEXT_MIN_RTT_PROBE_MS + * if no other update occurs. + * If we are in either RTT_PROBE or RTT_PROBE_REFILL, don't set + * the next probe time so we know when we approximately entered + * the probing phase. + */ + + if (ca->state == RTT_PROBE || ca->state == RTT_PROBE_REFILL) + return; + + ca->next_min_rtt_probe = jiffies_to_usecs(tcp_jiffies32) + + ROCCET_NEXT_MIN_RTT_PROBE_MS * USEC_PER_MSEC; +} + +static void update_min_rtt(struct roccettcp *ca) +{ + /* Check if new lower min RTT was found. If so, set it directly. + * If no valid RTT sample has been received yet, the check will fail, + * since the rtt values are initialized to U32_MAX. + */ + if (ca->curr_rtt < ca->curr_min_rtt) { + ca->curr_min_rtt = max(ca->curr_rtt, 1); + roccet_set_next_min_rtt_probe_ts(ca); + } +} + +/* Return difference between last and current ack rate. + */ +static s32 get_ack_rate_diff(struct roccettcp *ca) +{ + if (ca->curr_ack_rate < ca->ack_rate_last_rate) + return 0; + return (s32)(ca->curr_ack_rate - ca->ack_rate_last_rate); +} + +/* Update ack rate sampled by 100ms. + */ +static void update_ack_rate(struct roccettcp *ca, u32 acked, u32 now) +{ + const s32 idle_threshold = USEC_PER_SEC * 2; + const s32 interval = USEC_PER_MSEC * 100; + + /* Check if the last interval has elapsed. + * + * Check via time_between32, so that idle connections + * (for more than U32_MAX/2 usecs), also trigger a new update + * and don't stall the ack-counting. + */ + bool interval_elapsed = !time_between32(now, ca->last_ack_rate_time + - interval, + ca->last_ack_rate_time + + interval); + + if (interval_elapsed) { + /* Check if the connection was idle for *idle_threshold* + * seconds (e.g. no ACK for X seconds). If so, reset the ack + * counting as if a new connection was created. + */ + if (!time_between32(now, ca->last_ack_rate_time + - idle_threshold, + ca->last_ack_rate_time + + idle_threshold)) { + ca->ack_rate_last_rate = 0; + ca->curr_ack_rate = 0; + } else { + /* start counting for the new interval */ + ca->ack_rate_last_rate = ca->curr_ack_rate; + ca->curr_ack_rate = ca->ack_rate_cnt; + } + /* Start ack-counting with the already present ACKs */ + ca->ack_rate_cnt = min_t(u32, acked, U16_MAX); + ca->last_ack_rate_time = now; + } else { + /* Cap the ack count to avoid overflow. + * If we there are more than U16_MAX ACKs in 100ms, + * the resulting LAUNCH-exit won't cause any harm. + */ + ca->ack_rate_cnt = min_t(u32, ca->ack_rate_cnt + acked, + U16_MAX); + } +} + +/* Compute srRTT. + */ +static void update_srrtt(struct roccettcp *ca) +{ + u64 rrtt; + + /* Avoid integer overflow in the calculation below. + * This could occur in cases where we have not yet + * received an RTT sample after a min_rtt reset. + * In these cases, set the rtt to a safe value. + */ + if (ca->curr_rtt < ca->curr_min_rtt) { + ca->curr_rtt = max(ca->curr_rtt, 1); + ca->curr_min_rtt = ca->curr_rtt; + } + + /* ca->curr_min_rtt can never be 0. For completeness, we check for this + * anyways in order to avoid division by zero errors. + */ + if (ca->curr_min_rtt == 0) { + pr_err_once("TCP ROCCET: Recorded curr_min_rtt is 0\n"); + return; /* skip srRTT update */ + } + + /* Calculate the new rRTT (Scaled by 100). + * 100 * ((sRTT - sRTT_min) / sRTT_min). + * + * curr_min_rtt is always <= than curr_rtt, + * since this is the minimum of the rtt. + * + * 0 is a valid value for rrtt. + * + * If we have no valid RTT sample yet, curr_rtt and curr_min_rtt will + * be U32_MAX. This ultimately results in no srrtt increase, which + * is ok. + */ + rrtt = div_u64(100 * (u64)(ca->curr_rtt - ca->curr_min_rtt), + ca->curr_min_rtt); + + /* (1 - alpha) * srRTT + alpha * rRTT */ + ca->curr_srrtt = div_u64((100 - ROCCET_ALPHA_TIMES_100) + * (u64)ca->curr_srrtt + ROCCET_ALPHA_TIMES_100 + * rrtt, 100); +} + +/* Handle ROCCET loss/ECN during min RTT probing. + */ +static void roccet_min_rtt_probe_ce(struct roccettcp *ca, u32 cwnd) +{ + /* This should only be called in RTT_PROBE state */ + if (ca->state != RTT_PROBE) + return; + + /* If ROCCET is in min RTT probing and a loss/ECN occurs, + * we use the cwnd before the probing interval to + * calculate the cwnd reduction and continue probing. + * After min RTT probing the cwnd is set to the reduced + * value. During min RTT probing it is very likely that + * congestion was caused by the cwnd value before min + * RTT probing. + */ + + if (ca->cwnd_before_min_rtt_probe == 0) + pr_warn_once("TCP ROCCET: cwnd_before_min_rtt_probe is 0 during RTT_PROBE. This should not happen.\n"); + else + cwnd = ca->cwnd_before_min_rtt_probe; + + ca->cwnd_before_min_rtt_probe = + max((cwnd * beta) / BICTCP_BETA_SCALE, 2U); +} + +/* Do a ROCCET congestion event. + */ +static void roccet_congestion_event(struct sock *sk, u32 now) +{ + struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + + u32 curr_cwnd = tcp_snd_cwnd(tp); + + ca->epoch_start = 0; + ca->roccet_last_event_time_us = now; + ca->last_event_time_set = true; + + if (ca->state == RTT_PROBE) { + /* In case we are in RTT_PROBE, continue with this state, as + * the CE was likely caused by the cwnd before probing. + * However do react to the CE. + */ + roccet_min_rtt_probe_ce(ca, curr_cwnd); + return; + } + + ca->cnt = 100 * curr_cwnd; + + /* Set W_max only if the current cwnd is larger */ + if (ca->last_max_cwnd < curr_cwnd) + ca->last_max_cwnd = curr_cwnd; + + /* Reduce cwnd by beta */ + tcp_snd_cwnd_set(tp, min(tp->snd_cwnd_clamp, + max((curr_cwnd * beta) + / BICTCP_BETA_SCALE, 2U))); + + /* Re-adjust ssthresh in case of ORBITER Congestion Event */ + WRITE_ONCE(tp->snd_ssthresh, tcp_snd_cwnd(tp)); + + if (ca->state == LAUNCH) { + ca->state = ORBITER; + } else if (ca->state == ORBITER || ca->state == RTT_PROBE_REFILL) { + /* If we are in orbiter or currently refilling the pipe, + * abort the refill. + */ + ca->state = DRAIN; + } + /* Other states (e.g. DRAIN or RTT_PROBE_ENTER) not handled as + * we don`t want any action there. + */ +} + +static void roccet_enter_min_rtt_probe(struct sock *sk, u32 now) +{ + struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + u32 interval, probe_cwnd; + + /* If probing is already set, there was a mix up. + * Continue anyway so we can recover. + */ + if (ca->rtt_probe_timers_set) + pr_warn_once("TCP ROCCET: Probing time should not be set when entering RTT Probe\n"); + + /* Safeguard for an "infinite" probe. This should logically never + * happen but still safeguard it. + */ + if (ca->curr_rtt == U32_MAX) { + pr_warn_once("TCP ROCCET: curr_rtt is U32_MAX. Won't enter RTT_PROBE\n"); + ca->state = ORBITER; + return; + } + + /* Use field to store when we entered min RTT probing. Here we use + * jiffies to stay consistent with the epoch_start format. + */ + ca->next_min_rtt_probe = tcp_jiffies32; + + /* Start min RTT probing. Probe for 1 RTT or at least 200ms. + * Also bound the probe to a maximum of ROCCET_MAX_PROBE_INTERVAL_MS + * to avoid any "invalid"/very large RTT samples from breaking + * the probing and allowing ROCCET to recover afterwards. + */ + interval = max(200 * USEC_PER_MSEC, min(ca->curr_rtt, + ROCCET_MAX_PROBE_INTERVAL_MS + * USEC_PER_MSEC)); + + /* This is to handle deep shared buffers with loss-based + * congestion control like CUBIC. If the cwnd is not limited + * by the application but falsely detected (see ROCCET paper), + * we have to empty the pipe more. + * If the limit detection is correct this will cause no harm + * to the tcp flow because the cwnd is not fully utilized and + * we set the cwnd to its previous value after probing. + */ + if (!tcp_is_cwnd_limited(sk)) + probe_cwnd = max(tcp_snd_cwnd(tp) / 3, TCP_INIT_CWND); + else + probe_cwnd = max(tcp_snd_cwnd(tp) / 2, TCP_INIT_CWND); + + ca->probe_min_rtt_until = now + interval; + ca->cwnd_before_min_rtt_probe = tcp_snd_cwnd(tp); + + /* Reduce the cwnd to drain the buffer for probing. */ + tcp_snd_cwnd_set(tp, min(probe_cwnd, tp->snd_cwnd_clamp)); + + /* Reset current min RTT to allow probing for + * a new lower and higher minimum RTT. + */ + ca->curr_min_rtt = U32_MAX; + + /* Refill the pipe after probing. + * For this we use the previous cwnd for another probing interval. + */ + ca->refill_until = ca->probe_min_rtt_until + interval; + ca->rtt_probe_timers_set = true; /* Now both timers are set. */ + + /* Now we know that ca->probe_min_rtt_until < ca->refill_until + * and we advance to the next state of the probing phase. + * + * Wrap-arounds of these values are handled by the relevant + * if-conditions. + */ + ca->state = RTT_PROBE; +} + +/* Do minimum RTT probing. + */ +static void roccet_min_rtt_probe(struct sock *sk, u32 now) +{ + struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + + /* Here we are in RTT_PROBE, so the probing time should be set. + * If not just continue and enter refill phase. + * + * probe_min_rtt_until wrap-arounds are handled by the time_between32 + * check. + */ + if (!ca->rtt_probe_timers_set) + pr_warn_once("TCP ROCCET: Probing time should be set\n"); + else if (time_between32(now, ca->probe_min_rtt_until + - ROCCET_MAX_PROBE_INTERVAL_MS + * USEC_PER_MSEC, ca->probe_min_rtt_until)) + /* No state change if we are in the probing interval. */ + return; + else if (time_after32(now, ca->refill_until)) + /* If the probe_min_rtt_until interval has passed we likely + * just entered the refill interval, so go into + * RTT_PROBE_REFILL. If we are not in the refill_until + * interval, something went wrong and we should quickly exit + * the probing phase. + * + * Wraps-arounds of refill_until are caught by the time_after32 + * check. + */ + pr_warn_once("TCP ROCCET: Skipped refill interval.\n"); + + /* Reset cwnd to refill the pipe and consequently clear the stored + * window. + * Also perform sanity check. This should never happen. + */ + if (ca->cwnd_before_min_rtt_probe == 0) + pr_warn_once("TCP ROCCET: cwnd_before_min_rtt_probe is 0 during RTT_PROBE.\n"); + else + tcp_snd_cwnd_set(tp, min(ca->cwnd_before_min_rtt_probe, + tp->snd_cwnd_clamp)); + + ca->cwnd_before_min_rtt_probe = 0; + + /* Exit the RTT_PROBE state */ + ca->state = RTT_PROBE_REFILL; +} + +static void roccet_rtt_probe_refill(struct roccettcp *ca, u32 now) +{ + /* Once the refill interval is over, we can end the probing phase. */ + if (!time_between32(now, ca->refill_until + - ROCCET_MAX_PROBE_INTERVAL_MS + * USEC_PER_MSEC, ca->refill_until)) { + /* End min RTT probing phase. */ + ca->state = ORBITER; + } +} + +/* calculate the cubic root of x using a table lookup followed by one + * Newton-Raphson iteration. + * Avg err ~= 0.195% + */ +static u32 cubic_root(u64 a) +{ + u32 x, b, shift; + /* cbrt(x) MSB values for x MSB values in [0..63]. + * Precomputed then refined by hand - Willy Tarreau + * + * For x in [0..63], + * v = cbrt(x << 18) - 1 + * cbrt(x) = (v[x] + 10) >> 6 + */ + static const u8 v[] = { + /* 0x00 */ 0, 54, 54, 54, 118, 118, 118, 118, + /* 0x08 */ 123, 129, 134, 138, 143, 147, 151, 156, + /* 0x10 */ 157, 161, 164, 168, 170, 173, 176, 179, + /* 0x18 */ 181, 185, 187, 190, 192, 194, 197, 199, + /* 0x20 */ 200, 202, 204, 206, 209, 211, 213, 215, + /* 0x28 */ 217, 219, 221, 222, 224, 225, 227, 229, + /* 0x30 */ 231, 232, 234, 236, 237, 239, 240, 242, + /* 0x38 */ 244, 245, 246, 248, 250, 251, 252, 254, + }; + + b = fls64(a); + if (b < 7) { + /* a in [0..63] */ + return ((u32)v[(u32)a] + 35) >> 6; + } + + b = ((b * 84) >> 8) - 1; + shift = (a >> (b * 3)); + + x = ((u32)(((u32)v[shift] + 10) << b)) >> 6; + + /* Newton-Raphson iteration + * 2 + * x = ( 2 * x + a / x ) / 3 + * k+1 k k + */ + x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1))); + x = ((x * 341) >> 10); + return x; +} + +/* Compute congestion window to use. + */ +static void bictcp_update(struct roccettcp *ca, u32 cwnd, + u32 acked) +{ + u32 delta, bic_target, max_cnt; + u64 offs, t; + + ca->ack_cnt += acked; /* count the number of ACKed packets */ + + if (ca->last_cwnd == cwnd && + (s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32) + return; + + /* The CUBIC function can update ca->cnt at most once per jiffy. + * On all cwnd reduction events, ca->epoch_start is set to 0, + * which will force a recalculation of ca->cnt. + */ + if (ca->epoch_start && tcp_jiffies32 == ca->last_time) + goto tcp_friendliness; + + ca->last_cwnd = cwnd; + ca->last_time = tcp_jiffies32; + + if (ca->epoch_start == 0) { + ca->epoch_start = tcp_jiffies32; /* record beginning */ + ca->ack_cnt = acked; /* start counting */ + ca->tcp_cwnd = cwnd; /* syn with cubic */ + + if (ca->last_max_cwnd <= cwnd) { + ca->bic_K = 0; + ca->bic_origin_point = cwnd; + } else { + /* Compute new K based on + * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ) + */ + ca->bic_K = cubic_root(cube_factor * + (ca->last_max_cwnd - cwnd)); + ca->bic_origin_point = ca->last_max_cwnd; + } + } + + /* cubic function - calc */ + /* calculate c * time^3 / rtt, + * while considering overflow in calculation of time^3 + * (so time^3 is done by using 64 bit) + * and without the support of division of 64bit numbers + * (so all divisions are done by using 32 bit) + * also NOTE the unit of those variables + * time = (t - K) / 2^bictcp_HZ + * c = bic_scale >> 10 + * rtt = (srtt >> 3) / HZ + * !!! The following code does not have overflow problems, + * if the cwnd < 1 million packets !!! + */ + + t = (s32)(tcp_jiffies32 - ca->epoch_start); + t += usecs_to_jiffies(ca->delay_min); + + /* change the unit from HZ to bictcp_HZ */ + t <<= BICTCP_HZ; + do_div(t, HZ); + + if (t < ca->bic_K) /* t - K */ + offs = ca->bic_K - t; + else + offs = t - ca->bic_K; + + /* c/rtt * (t-K)^3 */ + delta = (cube_rtt_scale * offs * offs * offs) >> (10 + 3 * BICTCP_HZ); + if (t < ca->bic_K) /* below origin*/ + bic_target = ca->bic_origin_point - delta; + else /* above origin*/ + bic_target = ca->bic_origin_point + delta; + + /* cubic function - calc bictcp_cnt*/ + if (bic_target > cwnd) + ca->cnt = cwnd / (bic_target - cwnd); + else + ca->cnt = 100 * cwnd; /* very small increment*/ + + /* The initial growth of cubic function may be too conservative + * when the available bandwidth is still unknown. + */ + if (ca->last_max_cwnd == 0 && ca->cnt > 20) + ca->cnt = 20; /* increase cwnd 5% per RTT */ + +tcp_friendliness: + /* TCP Friendly */ + if (tcp_friendliness) { + u32 scale = beta_scale; + + delta = (cwnd * scale) >> 3; + if (delta > 0) { + while (ca->ack_cnt > delta) { /* update tcp cwnd */ + ca->ack_cnt -= delta; + ca->tcp_cwnd++; + } + } + + if (ca->tcp_cwnd > cwnd) { /* if bic is slower than tcp */ + delta = ca->tcp_cwnd - cwnd; + max_cnt = cwnd / delta; + if (ca->cnt > max_cnt) + ca->cnt = max_cnt; + } + } + + /* The maximum rate of cwnd increase CUBIC allows is 1 packet per + * 2 packets ACKed, meaning cwnd grows at 1.5x per RTT. + */ + ca->cnt = max(ca->cnt, 2U); +} + +static void roccet_launch_update(struct sock *sk, u32 acked) +{ + struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + + u32 now = jiffies_to_usecs(tcp_jiffies32); + + /* LAUNCH: Detect an exit point for tcp slow start + * in networks with large buffers of multiple BDP + * Like in cellular networks (5G, ...). + * + * Or exit LAUNCH if cwnd is too large for application layer + * data rate (tcp cwnd validation). + */ + if ((ca->curr_srrtt > sr_rtt_upper_bound && + get_ack_rate_diff(ca) <= ack_rate_diff_ss) || + !tcp_in_slow_start(tp) || + (!tcp_is_cwnd_limited(sk) && ca->initial_limit_reached)) { + u32 new_cwnd; + + ca->epoch_start = 0; + + /* Handle initial LAUNCH. Most bufferbloat occurs here */ + if (ca->is_in_initial_launch) { + /* Halving the cwnd will undo the previous step of slow + * start. Which is fine since the pipe is already full. + */ + new_cwnd = tcp_snd_cwnd(tp) / 2; + } else { + new_cwnd = tcp_snd_cwnd(tp) - (tcp_snd_cwnd(tp) / 3); + } + tcp_snd_cwnd_set(tp, min(max(new_cwnd, TCP_INIT_CWND), + tp->snd_cwnd_clamp)); + WRITE_ONCE(tp->snd_ssthresh, tcp_snd_cwnd(tp)); + ca->roccet_last_event_time_us = now; + ca->last_event_time_set = true; + ca->state = ORBITER; + return; + } + + /* If not already exiting LAUNCH, grow cwnd similar to slow-start */ + acked = tcp_slow_start(tp, acked); + /* If cwnd hits ssthresh, go to ORBITER and if any ACKs are + * leftover save them for ORBITER. + * Check via tcp_in_slow_start() in case no ACKs are left. + */ + if (!tcp_in_slow_start(tp)) { + ca->state = ORBITER; + ca->epoch_start = 0; + ca->ack_carry_over = acked; + } +} + +static void roccet_orbiter_update(struct sock *sk, u32 acked) +{ + /* ORBITER: Increase the cwnd by using the CUBIC cwnd growth function, + * if no roccet congestion event is detected. + */ + + struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + + u32 now = jiffies_to_usecs(tcp_jiffies32); + bool evaluate_srrtt = false; + bool sent_more_than_acked = false; + u32 roccet_xj, jitter, sent, received; + + /* Enter DRAIN when roccet was recently triggered */ + if (ca->last_event_time_set && + time_between32(now, ca->roccet_last_event_time_us + - 100 * USEC_PER_MSEC, + ca->roccet_last_event_time_us + + 100 * USEC_PER_MSEC)) { + ca->state = DRAIN; + return; + } + + /* Enter RTT_PROBE when the "timer" has expired. + * + * Since we are in ORBITER, we should have already received at least + * one RTT sample. However safeguard against it if not. + * + * Use double the probing period as a guard space to avoid + * idle-time locking us out of probing. + */ + if (!time_between32(now, ca->next_min_rtt_probe + - 2 * ROCCET_NEXT_MIN_RTT_PROBE_MS + * USEC_PER_MSEC, ca->next_min_rtt_probe) && + ca->curr_rtt != U32_MAX) { + ca->state = RTT_PROBE_ENTER; + return; + } + + /* Calculate jitter. + * Since we are in ORBITER, we should have already received at least + * one RTT sample. Even if not, ca->curr_rtt and ca->curr_min_rtt + * (the divisor later on) are U32_MAX, so they cancel each other out. + * And if ca->last_rtt is U32_MAX, roccet_xj will be very large, so + * the srRTT will not exceed it. + */ + if ((s32)(ca->curr_rtt - ca->last_rtt) < 0) + jitter = ca->last_rtt - ca->curr_rtt; + else + jitter = ca->curr_rtt - ca->last_rtt; + + /* Calculate if more bytes were sent than received + * in the time interval. + * + * Handle wrap arounds by relying on unsigned subtraction. + * e.g. if snd_nxt wraps to 10 and seq_start is U32_MAX - 10, + * the subtraction will result in the value of 21. + */ + sent = tp->snd_nxt - ca->interval_snd_seq_start; + received = tp->snd_una - ca->interval_una_seq_start; + + /* Check sent and received bytes from the previous interval. + * Here we use a guard space of 1% of the current cwnd. + * We do this to avoid a false positive evaluation due + * to delays caused by jitter or scheduling. + * + * (s64)(s32)(sent - received) => Preserves negative wrap-behavior + * with explicit s64 conversion afterwards. + */ + sent_more_than_acked = (s64)(s32)(sent - received) > + (s64)div_u64((u64)tcp_snd_cwnd(tp) * + (u64)tp->mss_cache, 100); + + /* Check if it's time to evaluate the srRTT */ + if (!time_between32(now, ca->next_srrtt_check_ts + - 2 * ROCCET_MAX_SRRTT_CHECK_INTERVAL_MS + * USEC_PER_MSEC, ca->next_srrtt_check_ts)) { + evaluate_srrtt = true; + + /* reset struct and set next end of period */ + roccet_set_next_srrtt_check_ts(ca, now); + + /* Reset Rate calculation */ + ca->interval_snd_seq_start = tp->snd_nxt; + ca->interval_una_seq_start = tp->snd_una; + } + + /* If we are in recovery, skip growth and further ROCCET-CE's. */ + if (tcp_in_cwnd_reduction(sk)) + return; + + /* Respects the jitter of the connection and add it on top of + * the upper bound for the srRTT. + */ + roccet_xj = div_u64((u64)jitter * 100, ca->curr_min_rtt) + + sr_rtt_upper_bound; + + /* The srRTT exceeds the upper bound if bufferbloat happens. + * Here, we want to reduce the cwnd and drain the buffer. + */ + if (ca->curr_srrtt > roccet_xj && evaluate_srrtt && + sent_more_than_acked) { + roccet_congestion_event(sk, now); + return; + } + + /* Terminates this function if cwnd is not fully utilized. + * In mobile networks like 5G, this termination causes the + * cwnd to be frozen at an excessively high value. This is + * because slow start or HyStart massively exceed the available + * bandwidth and leave the cwnd at an excessively high value. + * The cwnd cannot therefore be fully utilized because it is + * limited by the connection capacity. + */ + if (!tcp_is_cwnd_limited(sk) || sent_more_than_acked) + return; + + /* In case there are any ACKs left over from LAUNCH, + * apply them now. + */ + if (ca->ack_carry_over) { + acked += ca->ack_carry_over; + ca->ack_carry_over = 0; + } + + bictcp_update(ca, tcp_snd_cwnd(tp), acked); + tcp_cong_avoid_ai(tp, max(1, ca->cnt), acked); +} + +/* The Cubic ssthresh calculation is also used for ROCCET. + * Called before TCP-CC state changes to TCP_CA_Recovery, TCP_CA_CWR or + * TCP_CA_Loss. cwnd reduction is then handled in the roccet_state() callback. + */ +static u32 roccet_recalc_ssthresh(struct sock *sk) +{ + const struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + u32 cwnd = tcp_snd_cwnd(tp); + + /* In LAUNCH, we want no reduction on loss/ECN. + * On ECN this is set later on in roccet_state() + */ + if (ca->state == LAUNCH) + return cwnd; + + /* In min RTT probe, use the cwnd before the probe to not undershoot */ + if (ca->state == RTT_PROBE) + cwnd = ca->cwnd_before_min_rtt_probe; + + ca->epoch_start = 0; /* end of epoch */ + + /* Wmax and fast convergence */ + if (cwnd < ca->last_max_cwnd && fast_convergence) + ca->last_max_cwnd = (cwnd * (BICTCP_BETA_SCALE + beta)) + / (2 * BICTCP_BETA_SCALE); + else + ca->last_max_cwnd = cwnd; + + return max((cwnd * beta) / BICTCP_BETA_SCALE, 2U); +} + +/* Handle a recovery event and return the new cwnd. + */ +static u32 roccet_handle_recovery(struct sock *sk) +{ + const struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + u32 cwnd = tcp_snd_cwnd(tp); + + /* If a loss occurs in the refill phase of min RTT probing + * we reduce the cwnd and abort the refill. + */ + if (ca->state == RTT_PROBE_REFILL) + ca->state = ORBITER; + + /* In RTT_PROBE we don`t want to change state or immediately reduce + * the cwnd. + */ + if (ca->state == RTT_PROBE) { + roccet_min_rtt_probe_ce(ca, cwnd); + return tcp_snd_cwnd(tp); + } + + /* On loss in LAUNCH, enter ORBITER without a cwnd reduction. */ + if (ca->state == LAUNCH) { + ca->state = ORBITER; + return cwnd; + } + + return max((cwnd * beta) / BICTCP_BETA_SCALE, 2U); +} + +/* Checks for state roccet-transitions and performs necessary state (re)sets. + * This is done in order to avoid the possibility of forgetting to correctly + * set a state when entering certain states. + * + * This is used whenever a state change is possible + * (e.g. in roccet_state(), roccet_control(), ...). + */ +static void roccet_handle_state_transitions(struct sock *sk, + enum roccet_state prev_state, + u32 now) +{ + struct roccettcp *ca = inet_csk_ca(sk); + struct tcp_sock *tp = tcp_sk(sk); + u32 now_jiffies = tcp_jiffies32; + + if (ca->state == prev_state) + return; + + /* When we exit LAUNCH we can be sure that we are no longer in the + * initial_launch. Also on any state transition from LAUNCH, we can + * say that the tcp_is_cwnd_limited() is now valid. + */ + if (prev_state == LAUNCH) { + ca->is_in_initial_launch = false; + ca->initial_limit_reached = true; + } + + /* Whenever we enter ORBITER, we need to schedule the next SRTT check. + * This will be set before evaluating the next_srrtt_check_ts condition + * as this is only done in ORBITER. + */ + if (ca->state == ORBITER) { + roccet_set_next_srrtt_check_ts(ca, now); + ca->interval_snd_seq_start = tp->snd_nxt; + ca->interval_una_seq_start = tp->snd_una; + + /* Add the time we spent in the min RTT probing phase to the + * epoch_start, so the cubic growth won't suddenly jump + * after probing. Here we use the next_min_rtt_probe field + * which we (ab)used to store the time when we entered min RTT + * probing (in jiffies). + */ + if ((prev_state == RTT_PROBE || + prev_state == RTT_PROBE_REFILL)) { + if (ca->epoch_start != 0) { + ca->epoch_start += now_jiffies - + ca->next_min_rtt_probe; + /* Clamp so that epoch_start doesn't go + * in the future. + */ + if (after(ca->epoch_start, now_jiffies)) + ca->epoch_start = now_jiffies; + } + + roccet_set_next_min_rtt_probe_ts(ca); + } + } + + /* In refill we can transition to DRAIN. In this case, overwrite the + * jiffies ts + */ + if (ca->state == DRAIN && prev_state == RTT_PROBE_REFILL) + roccet_set_next_min_rtt_probe_ts(ca); + + /* Whenever we leave the min RTT probing states (and not just + * transition between them), we want to reset the probing timers. + */ + if ((prev_state == RTT_PROBE_ENTER || prev_state == RTT_PROBE || + prev_state == RTT_PROBE_REFILL) && + (ca->state != RTT_PROBE && ca->state != RTT_PROBE_REFILL)) { + ca->probe_min_rtt_until = 0; + ca->refill_until = 0; + ca->rtt_probe_timers_set = false; + } +} + +static void roccet_cwnd_event_tx_start(struct sock *sk) +{ + struct roccettcp *ca = inet_csk_ca(sk); + struct tcp_sock *tp = tcp_sk(sk); + u32 now = tcp_jiffies32; + enum roccet_state prev_state = ca->state; + s32 delta; + + delta = now - tcp_sk(sk)->lsndtime; + + /* We were application limited (idle) for a while. + * Shift epoch_start to keep cwnd growth to cubic curve. + */ + if (ca->epoch_start && delta > 0) { + ca->epoch_start += delta; + if (after(ca->epoch_start, now)) + ca->epoch_start = now; + } + + /* After idle periods, go into LAUNCH with slow start */ + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) && + delta >= inet_csk(sk)->icsk_rto) { + tp->snd_ssthresh = tcp_snd_cwnd(tp); + tcp_snd_cwnd_set(tp, min(TCP_INIT_CWND, tp->snd_cwnd_clamp)); + ca->state = LAUNCH; + } + + roccet_handle_state_transitions(sk, prev_state, jiffies_to_usecs(now)); +} + +/* Handle different loss-states and perform adequate cwnd reductions. + */ +static void roccet_state(struct sock *sk, u8 new_state) +{ + struct roccettcp *ca = inet_csk_ca(sk); + struct tcp_sock *tp = tcp_sk(sk); + u32 cwnd; + u32 now = jiffies_to_usecs(tcp_jiffies32); + enum roccet_state prev_state = ca->state; + + if (new_state == TCP_CA_Loss) { + roccet_reset(sk, ca); + tcp_snd_cwnd_set(tp, min(TCP_INIT_CWND, tp->snd_cwnd_clamp)); + WRITE_ONCE(tp->snd_ssthresh, max(tp->snd_ssthresh, + tcp_snd_cwnd(tp))); + } else if (tcp_in_cwnd_reduction(sk)) { + /* In this case we don't want a further window reduction */ + } else if (new_state == TCP_CA_CWR) { + /* Handle CWR as ROCCET congestion event, + * however afterwards always set Wmax to the current cwnd + * except during min RTT probing. + */ + cwnd = tcp_snd_cwnd(tp); + roccet_congestion_event(sk, now); + if (ca->state != RTT_PROBE_ENTER && ca->state != RTT_PROBE && + ca->state != RTT_PROBE_REFILL) + ca->last_max_cwnd = cwnd; + } else if (new_state == TCP_CA_Recovery) { + /* Directly reduce cwnd and rely on pacing */ + cwnd = roccet_handle_recovery(sk); + tcp_snd_cwnd_set(tp, min(cwnd, tp->snd_cwnd_clamp)); + } + + roccet_handle_state_transitions(sk, prev_state, now); +} + +/* Update RTT samples and min RTT. + */ +static void roccet_acked(struct sock *sk, const struct ack_sample *sample) +{ + struct roccettcp *ca = inet_csk_ca(sk); + bool after_fast_recovery; + u32 delay; + + /* Some calls are for duplicates without timestamps */ + if (sample->rtt_us < 0) + return; + + /* Check if we are right after fast recovery. */ + after_fast_recovery = ca->epoch_start && + (s32)(tcp_jiffies32 - ca->epoch_start) < HZ; + + /* If we are not after fast recovery or we are in RTT_PROBE however, + * we want to record every new min-sample. + */ + if (!after_fast_recovery || ca->state == RTT_PROBE) { + /* Get valid sample for roccet */ + if (sample->rtt_us > 0) { + ca->last_rtt = ca->curr_rtt; + ca->curr_rtt = sample->rtt_us; + } + } + + /* Otherwise discard delay samples right after fast recovery. */ + if (after_fast_recovery) + return; + + delay = sample->rtt_us; + + if (delay == 0) + delay = 1; + + /* first call or link delay decreases */ + if (ca->delay_min == 0 || (s32)(delay - ca->delay_min) < 0) + ca->delay_min = delay; +} + +/* Custom Pacing Rate for ROCCET TCP. + * The code here is similar to the pacing rate adjustments in tcp_input.c's + * tcp_update_pacing_rate(). In (modified) slow start we want a pacing + * following the sysctl_tcp_pacing_ss_ratio (usually 200%) parameter and + * otherwise (congestion avoidance) we adjust the pacing to 100% and do not + * use the sysctl_tcp_pacing_ca_ratio. + */ +static void roccet_update_pacing_rate(struct sock *sk) +{ + struct roccettcp *ca = inet_csk_ca(sk); + struct tcp_sock *tp = tcp_sk(sk); + u64 rate; + + /* set sk_pacing_rate to 200 % of current rate (mss * cwnd / srtt) */ + rate = (u64)tp->mss_cache * ((div64_u64(USEC_PER_SEC, 100) << 3)); + + /* current rate is (cwnd * mss) / srtt + * In slow-start [1], set sk_pacing_rate to sysctl_tcp_pacing_ss_ratio + * (usually 200%) the current rate. Otherwise, set it to 100% the + * current rate. + * + * [1]: Normal Slow Start cond is (tp->snd_cwnd < tp->snd_ssthresh) + * If snd_cwnd >= (tp->snd_ssthresh / 2), we are approaching + * end of slow start and should slow down. + */ + if (ca->state == RTT_PROBE || tcp_snd_cwnd(tp) >= tp->snd_ssthresh / 2) + /* Pacing rate of 100% + * (instead of ipv4.sysctl_tcp_pacing_ca_ratio) + */ + rate *= 100; + else + /* Here we are well inside of slow start + * (tcp_snd_cwnd(tp) < tp->snd_ssthresh / 2) + */ + rate *= READ_ONCE + (sock_net(sk)->ipv4.sysctl_tcp_pacing_ss_ratio); + + rate *= max(tcp_snd_cwnd(tp), tp->packets_out); + + if (likely(tp->srtt_us)) + do_div(rate, tp->srtt_us); + + /* WRITE_ONCE() is needed because sch_fq fetches sk_pacing_rate + * without any lock. We want to make sure compiler won't store + * intermediate values in this location. + */ + WRITE_ONCE(sk->sk_pacing_rate, + min_t(u64, rate, READ_ONCE(sk->sk_max_pacing_rate))); +} + +static void roccet_drain_update(struct sock *sk, u32 now) +{ + struct tcp_sock *tp = tcp_sk(sk); + struct roccettcp *ca = inet_csk_ca(sk); + + /* If we are in DRAIN, ca->roccet_last_event_time_us has to be set. + * If more than 100 ms have passed after a roccet event, exit DRAIN. + * The between check is here to handle idle-times and timer-wraps. + * It is ok if we "accidentally" exit DRAIN in such an occasion. + */ + if (!time_between32(now, ca->roccet_last_event_time_us + - 100 * USEC_PER_MSEC, + ca->roccet_last_event_time_us + + 100 * USEC_PER_MSEC)) { + if (tcp_in_slow_start(tp)) + ca->state = LAUNCH; + else + ca->state = ORBITER; + } +} + +static void roccet_control(struct sock *sk, u32 ack, int flag, + const struct rate_sample *rs) +{ + struct roccettcp *ca = inet_csk_ca(sk); + + u32 now = jiffies_to_usecs(tcp_jiffies32); + enum roccet_state prev_state = ca->state; + + /* Update ack rate. Even on no new acks/sacks. */ + update_ack_rate(ca, rs->acked_sacked, now); + /* Only update RTT metrics if we have new acks/sacks in order to keep + * EWMA from running multiple times for no new acks. + */ + if (rs->acked_sacked > 0) { + update_min_rtt(ca); + update_srrtt(ca); + } + + /* Evaluate roccet state */ + switch (ca->state) { + case LAUNCH: + roccet_launch_update(sk, rs->acked_sacked); + break; + case ORBITER: + roccet_orbiter_update(sk, rs->acked_sacked); + break; + case DRAIN: + /* In DRAIN the cwnd should not be increased */ + roccet_drain_update(sk, now); + break; + case RTT_PROBE_ENTER: + roccet_enter_min_rtt_probe(sk, now); + break; + case RTT_PROBE: + roccet_min_rtt_probe(sk, now); + break; + case RTT_PROBE_REFILL: + roccet_rtt_probe_refill(ca, now); + break; + default: + pr_err_once("TCP ROCCET: Invalid state %d\n", ca->state); + } + + roccet_handle_state_transitions(sk, prev_state, now); + + roccet_update_pacing_rate(sk); + + /* Abuse ca->roccet_last_event_time_us as the start time for this + * connection (only after init, while initial_limit_reached is not + * set). When the connection starts sending enough data or after 500 ms + * we know that we can use tcp_is_cwnd_limited() to check if the + * connection is actually limited by the cwnd and is not just + * starting up. + */ + if (!ca->initial_limit_reached && + (tcp_is_cwnd_limited(sk) || + !time_between32(now, ca->roccet_last_event_time_us + - 500 * USEC_PER_MSEC, + ca->roccet_last_event_time_us + + 500 * USEC_PER_MSEC))) + ca->initial_limit_reached = true; +} + +static struct tcp_congestion_ops roccet_tcp __read_mostly = { + .init = roccet_init, + .ssthresh = roccet_recalc_ssthresh, + .set_state = roccet_state, + .undo_cwnd = tcp_reno_undo_cwnd, + .cwnd_event_tx_start = roccet_cwnd_event_tx_start, + .pkts_acked = roccet_acked, + .cong_control = roccet_control, + .owner = THIS_MODULE, + .name = "roccet", +}; + +static int __init roccet_register(void) +{ + int param_err; + + BUILD_BUG_ON(sizeof(struct roccettcp) > ICSK_CA_PRIV_SIZE); + + /* Check for valid parameter ranges and then precompute factors */ + param_err = param_check(); + + if (param_err) + return param_err; + + param_precompute(); + + return tcp_register_congestion_control(&roccet_tcp); +} + +static void __exit roccet_unregister(void) +{ + tcp_unregister_congestion_control(&roccet_tcp); +} + +module_init(roccet_register); +module_exit(roccet_unregister); + +MODULE_AUTHOR("Lukas Prause, Tim Füchsel"); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("ROCCET TCP"); From 5820ca58b409402505b9e904d1ded4908e0b6b81 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Sat, 10 Oct 2026 17:02:48 -0400 Subject: [PATCH 1901/2126] netdevsim: reject cls_bpf programs bound to another device The issue: nsim_bpf_setup_tc_block_cb() installs any device-bound SCHED_CLS program without checking that its offload device matches the target netdev. The core cls_bpf attach path rejects a mismatching program, but a netdev that joins a shared block later is replayed the stored filter by cls_bpf_reoffload() before it is inserted into block->ports, so the attach-time check cannot see it. The driver callback is the authoritative per-device acceptance boundary and must enforce the match itself, as nfp already does in nfp_net_bpf_offload(). Without the check, replaying a device-bound program onto a different bpf_offload_dev installs it into that device's netdevsim state, which trips the WARN in nsim_bpf_uninit() (ns->bpf_offloaded set on a foreign device) and can dereference a NULL prog->aux->offload in nsim_prog_set_loaded(). The Fix: Reject a device-bound program whose offload device does not match the target netdev, with -EINVAL and an extack so the rejected replay is not silent. The check is intentionally narrower than nfp's: it fires only for a dev-bound program, so nsim's bpf_tc_non_bound_accept mode (which admits an unbound program onto the device) is unaffected. Teardown is never blocked: the guard is on the program being installed and an unbind passes cls_bpf.prog = NULL. Conditions to recreate the bug: - CONFIG_NETDEVSIM=y, CONFIG_NET_CLS_BPF=y - load and pin a dev-bound SCHED_CLS program for netdevsim device B - install the program on a shared block owned by B - add an independently backed netdevsim device C to that block; the bind replays the filter to C's callback, and C's ports/0/bpf_offloaded_id takes the B-bound program id. The reported Sashiko review is at https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260809094418.901607-1-jhs@mojatatu.com Fixes: 31d3ad832948 ("netdevsim: add bpf offload support") Reported-by: Sashiko (nipa) Link: https://lore.kernel.org/netdev/20260809094418.901607-1-jhs@mojatatu.com/ Link: https://lore.kernel.org/netdev/QDISC-PYC7.v1.20261003103747@mojatatu.com/ Cc: stable@vger.kernel.org Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Reviewed-by: Simon Horman Link: https://patch.msgid.link/QDISC-PYC7.v2.20261010165947-2@mojatatu.com Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/bpf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c index 16aa88278398..f45c1c8f0584 100644 --- a/drivers/net/netdevsim/bpf.c +++ b/drivers/net/netdevsim/bpf.c @@ -144,6 +144,17 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, return -EOPNOTSUPP; } + /* A dev-bound program can be replayed here when a netdev joins + * a shared block, after the core attach-time check has run; + * enforce the device match as nfp does. + */ + if (prog && bpf_prog_is_dev_bound(prog->aux) && + !bpf_offload_dev_match(prog, ns->netdev)) { + NSIM_EA(cls_bpf->common.extack, + "program bound to a different device"); + return -EINVAL; + } + if (cls_bpf->command != TC_CLSBPF_OFFLOAD) return -EOPNOTSUPP; From d305547d1632a242818c5ebb430c85121a2ed434 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Sat, 10 Oct 2026 17:02:49 -0400 Subject: [PATCH 1902/2126] net/sched: cls_bpf: accept dev-bound programs on shared blocks The issue: Follow-up to commit 120977e2c096 ("net/sched: cls_bpf: reject dev-bound programs bound to a different device"), which derived the target device from block->q: dev = block->q ? qdisc_dev(block->q) : NULL; tcf_block_create() leaves block->q NULL for shared blocks, so a device-bound program attached through a shared block is rejected with -EINVAL even when it is bound to a netdev that owns the block. The offload path (cls_bpf_offload_cmd()) never consults block->q and drives the per-device callbacks for shared blocks as before. The Fix: Accept the attach on a shared block when bpf_offload_dev_match() matches every netdev bound to the block, and reject an empty block. Every member must match because the offload path broadcasts the program to every callback registered on the block, so an any-member check would re-admit the wrong-device attach on a mixed block. Every dev-bound SCHED_CLS attach is skip_sw, which becomes err_stop and aborts the offload on the first failing callback, so the all-members rule is the offload path's own semantics. Iterate the public block->ports xarray (913b47d3424e, v6.8-rc1) rather than block->owner_list, which is private to cls_api.c. The shared-block rejection reports "Program is not bound to every device in the block", distinct from the non-shared message, because a member can exist without a registered callback (netdevsim registers its block callback ingress-only). Context note: This patch is not an independent fix: it re-exposes the shared-block replay path that commit 120977e2c096 ("net/sched: cls_bpf: reject dev-bound programs bound to a different device") had closed, so patch 1 must be applied first, including in stable. A stable tree taking this patch alone would re-enable shared-block attaches on a kernel whose netdevsim callback is still unchecked. Conditions to recreate the bug: - CONFIG_NETDEVSIM=y, CONFIG_NET_CLS_BPF=y - load a dev-bound SCHED_CLS program for netdevsim device B (prog_ifindex=B), pin it in bpffs - tc qdisc add dev B ingress_block 22 clsact - tc filter add block 22 ingress bpf da object-pinned skip_sw Unfixed, the filter add fails with -EINVAL ("Program is bound to a different device"); fixed, it succeeds. Adding a second, independently backed netdevsim device to the same block makes the attach fail again. Fixes: 120977e2c096 ("net/sched: cls_bpf: reject dev-bound programs bound to a different device") Reported-by: Sashiko (nipa) Link: https://lore.kernel.org/netdev/20260809094418.901607-1-jhs@mojatatu.com/ Link: https://lore.kernel.org/netdev/QDISC-PYC7.v1.20261003103747@mojatatu.com/ Cc: stable@vger.kernel.org Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Reviewed-by: Simon Horman Link: https://patch.msgid.link/QDISC-PYC7.v2.20261010165947-3@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/cls_bpf.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 188cf0f949dd..07ad9556889d 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -392,11 +392,31 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, if (bpf_prog_is_dev_bound(fp->aux)) { struct tcf_block *block = tp->chain->block; struct net_device *dev; + unsigned long ifindex; + bool match = false; - dev = block->q ? qdisc_dev(block->q) : NULL; - if (!dev || !bpf_offload_dev_match(fp, dev)) { - NL_SET_ERR_MSG(extack, - "Program is bound to a different device"); + /* A shared block has no qdisc of its own, but it may bind + * several netdevs and the program is offloaded to all of them; + * require a match with every member. + */ + if (!tcf_block_shared(block)) { + dev = qdisc_dev(tcf_block_q(block)); + match = bpf_offload_dev_match(fp, dev); + if (!match) + NL_SET_ERR_MSG(extack, + "Program is bound to a different device"); + } else { + xa_for_each(&block->ports, ifindex, dev) { + match = bpf_offload_dev_match(fp, dev); + if (!match) + break; + } + if (!match) + NL_SET_ERR_MSG(extack, + "Program is not bound to every device in the block"); + } + + if (!match) { bpf_prog_put(fp); return -EINVAL; } From 866363c3cc40147d0501a1a6dae485e13852d150 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Sat, 10 Oct 2026 17:02:50 -0400 Subject: [PATCH 1903/2126] selftests: net: exercise dev-bound cls_bpf on shared blocks The issue: bpf_offload.py only exercises per-device ingress qdiscs today, so neither the shared-block accept path nor the late-join replay is tested. The Fix: Add a test for a device-bound SCHED_CLS program attached through a shared block. It loads a dev-bound SCHED_CLS program for a netdevsim device and checks: - the program attaches to a shared block owned by its device, and the filter teardown leaves the device unloaded; - a block that also holds an independently backed device rejects the attach, because the offload path broadcasts the program to all members; - an independently backed device that joins a populated block is not loaded by the bind/replay path, and the driver's extack is asserted; - a second port of the same netdevsim device (same offload device) is accepted together with the bound port. The program is loaded from the existing sample_ret0.bpf.o with an explicit `type classifier` override, so no new sample object is needed. Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Reviewed-by: Simon Horman Link: https://patch.msgid.link/QDISC-PYC7.v2.20261010165947-4@mojatatu.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/bpf_offload.py | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tools/testing/selftests/net/bpf_offload.py b/tools/testing/selftests/net/bpf_offload.py index c856d266c8f3..8c1da9b51be5 100755 --- a/tools/testing/selftests/net/bpf_offload.py +++ b/tools/testing/selftests/net/bpf_offload.py @@ -452,6 +452,38 @@ class BpfNetdevSim(NetdevSim): self.tc_add_ingress() self.wait_for_flush(bound=bound, total=total) + def tc_add_block(self, block, fail=True, include_stderr=False): + return tc("qdisc add dev %s ingress_block %d clsact" % + (self['ifname'], block), fail=fail, + include_stderr=include_stderr) + + def tc_del_block(self, block): + tc("qdisc del dev %s clsact" % (self['ifname']), fail=False) + + def tc_add_block_filter(self, block, bpf, op="add", prio=None, handle=None, + da=False, verbose=False, skip_sw=False, + skip_hw=False, fail=True, include_stderr=False): + spec = "" + if prio is not None: + spec += " prio %d" % (prio) + if handle: + spec += " handle %s" % (handle) + + params = "" + if da: + params += " da" + if verbose: + params += " verbose" + if skip_sw: + params += " skip_sw" + if skip_hw: + params += " skip_hw" + + return tc("filter {op} block {block} {spec} bpf {bpf} {params}" + .format(op=op, block=block, spec=spec, bpf=bpf, + params=params), + fail=fail, include_stderr=include_stderr) + def tc_show_ingress(self, expected=None): # No JSON support, oh well... flags = ["skip_sw", "skip_hw", "in_hw"] @@ -629,6 +661,111 @@ def test_spurios_extack(sim, obj, skip_hw, needle): include_stderr=True) check_no_extack(res, needle) +def test_tc_shared_block(): + """ + Device-bound cls_bpf program attached through a shared block. + """ + # A shared block has no qdisc, so the target device is derived from the + # block's bound netdevs and the program must match every member, since + # the offload path broadcasts it to every callback on the block. A + # netdev joining a populated block later is replayed the stored filter + # before it is inserted into block->ports, so the driver callback must + # enforce the device match as well. + simdev = BpfNetdevSimDev() + sim, = simdev.nsims + sim.set_ethtool_tc_offloads(True) + + start_test("Test TC shared-block load dev-bound program...") + bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/tc_shared", + prog_type="classifier", dev=sim['ifname']) + + start_test("Test TC shared-block dev-bound attach...") + # The pinned program is dev-bound to this device; attaching it through + # a shared block must succeed even though block->q is NULL. + sim.tc_add_block(22) + # err is kept (include_stderr) for post-mortem value on a failure. + ret, _, err = sim.tc_add_block_filter(22, bpf_pinned("/sys/fs/bpf/tc_shared"), + da=True, skip_sw=True, + fail=False, include_stderr=True) + fail(ret != 0, "dev-bound program rejected on a matching shared block") + fail(sim.dfs_read("bpf_offloaded_id") == "0", + "dev-bound program not offloaded on a matching shared block") + sim.tc_del_block(22) + + start_test("Test TC shared-block broadcast to a foreign member...") + # Add an independently backed device to the SAME block before the + # attach. The program is bound to sim's device only, and the offload + # path fans it out to every member, so the attach must be rejected. + simdev2 = BpfNetdevSimDev() + sim2, = simdev2.nsims + sim2.set_ethtool_tc_offloads(True) + sim.tc_add_block(40) + sim2.tc_add_block(40) + ret, _, err = sim.tc_add_block_filter(40, bpf_pinned("/sys/fs/bpf/tc_shared"), + da=True, skip_sw=True, + fail=False, include_stderr=True) + fail(ret == 0, "dev-bound program broadcast to a foreign shared-block member") + check_extack(err, "Program is not bound to every device in the block.", args) + sim2.tc_del_block(40) + sim.tc_del_block(40) + simdev2.remove() + + start_test("Test TC shared-block late join replay...") + # Build a block owned by sim's device with the matching program + # installed, then let an independently backed device join it. The + # join replays the stored filter to the joining device's callback + # before the device is recorded in block->ports; the driver must + # reject the replay so the foreign device is never loaded. + # sim2 is created here (not inherited) so the TC-offload state it + # depends on is explicit. + simdev2 = BpfNetdevSimDev() + sim2, = simdev2.nsims + sim2.set_ethtool_tc_offloads(True) + sim.tc_add_block(30) + ret, _, err = sim.tc_add_block_filter(30, bpf_pinned("/sys/fs/bpf/tc_shared"), + da=True, skip_sw=True, + fail=False, include_stderr=True) + fail(ret != 0, "dev-bound program rejected on a matching shared block") + ret, _, err = sim2.tc_add_block(30, fail=False, include_stderr=True) + fail(ret == 0, "foreign device joined a populated dev-bound shared block") + check_extack_nsim(err, "program bound to a different device.", args) + fail(sim2.dfs_read("bpf_offloaded_id") != "0", + "replayed program loaded onto a foreign device") + # The add above was expected to fail, so the qdisc may not exist; the + # delete is harmless and only cleans up when it does. + sim2.tc_del_block(30) + sim.tc_del_block(30) + simdev2.remove() + + start_test("Test TC shared-block same-offload-device member...") + # A second port of the same netdevsim device shares the offload device, + # so a program bound to one port may legitimately be offloaded to both. + simdev3 = BpfNetdevSimDev(2) + sim3, sim3b = simdev3.nsims + sim3.set_ethtool_tc_offloads(True) + sim3b.set_ethtool_tc_offloads(True) + bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/tc_shared_multi", + prog_type="classifier", dev=sim3['ifname']) + sim3.tc_add_block(50) + sim3b.tc_add_block(50) + # err kept for post-mortem value on a failure. + ret, _, err = sim3.tc_add_block_filter(50, bpf_pinned("/sys/fs/bpf/tc_shared_multi"), + da=True, skip_sw=True, + fail=False, include_stderr=True) + fail(ret != 0, "same-offload-device member rejected on a shared block") + fail(sim3.dfs_read("bpf_offloaded_id") == "0", + "program not offloaded to the bound port") + fail(sim3b.dfs_read("bpf_offloaded_id") == "0", + "program not offloaded to the same-offload-device port") + sim3b.tc_del_block(50) + sim3.tc_del_block(50) + + simdev3.remove() + simdev.remove() + rm("/sys/fs/bpf/tc_shared_multi") + rm("/sys/fs/bpf/tc_shared") + bpftool_prog_list_wait(expected=0) + def test_multi_prog(simdev, sim, obj, modename, modeid): start_test("Test multi-attachment XDP - %s + offload..." % (modename or "default", )) @@ -1349,6 +1486,8 @@ try: ret, out = bpftool("prog show %s" % (progB), fail=False) fail(ret != 0, "couldn't get information about orphaned program") + test_tc_shared_block() + print("%s: OK" % (os.path.basename(__file__))) finally: From 0e36a335c84ee6f4248909321f3c83a71fd2aa02 Mon Sep 17 00:00:00 2001 From: Alexei Lazar Date: Sun, 11 Oct 2026 11:39:29 +0300 Subject: [PATCH 1904/2126] net/dcb: Validate bandwidth for non-ETS traffic classes The IEEE 802.1Qaz standard defines that bandwidth allocation percentages only apply to ETS traffic classes. Reject ETS configurations that specify non-zero bandwidth for non-ETS traffic classes. Placing this check in dcbnl_ieee_set() enforces the constraint uniformly for all drivers rather than relying on each driver to validate it independently. Drop the equivalent check from NFP's dcb_ets_check(). Keep ETS bandwidth-sum validation unchanged. Signed-off-by: Alexei Lazar Reviewed-by: Carolina Jubran Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261011083929.739261-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/netronome/nfp/nic/dcb.c | 3 --- net/dcb/dcbnl.c | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nic/dcb.c b/drivers/net/ethernet/netronome/nfp/nic/dcb.c index bb498ac6bd7d..91fbfa3708fc 100644 --- a/drivers/net/ethernet/netronome/nfp/nic/dcb.c +++ b/drivers/net/ethernet/netronome/nfp/nic/dcb.c @@ -218,9 +218,6 @@ static int dcb_ets_check(struct net_device *dev, struct ieee_ets *ets) if (ets->tc_tsa[i] == IEEE_8021QAZ_TSA_ETS) { ets_exists = true; sum += ets->tc_tx_bw[i]; - } else if (ets->tc_tx_bw[i]) { - nfp_warn(app->cpp, "ETS BW for strict/vendor TC must be 0."); - return -EINVAL; } } diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c index 35164bfa563d..ab71f5312876 100644 --- a/net/dcb/dcbnl.c +++ b/net/dcb/dcbnl.c @@ -1578,6 +1578,15 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) { struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]); + + /* IEEE 802.1Qaz: BW allocation applies only to ETS TCs */ + for (int i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) { + if (ets->tc_tsa[i] != IEEE_8021QAZ_TSA_ETS && + ets->tc_tx_bw[i]) { + err = -EINVAL; + goto err; + } + } err = ops->ieee_setets(netdev, ets); if (err) goto err; From 7d0692e7f0508d499f6a237a746145060127cf94 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:07 -0700 Subject: [PATCH 1905/2126] dt-bindings: net: qcom,ipq9574-ppe: Split EDMA reset into sys and apb The EDMA reset is described in the binding as a single reset, but the hardware has two separate EDMA resets, the system reset and the APB reset. The reset used in the example is a combined reset that covers both of them. Describe the EDMA resets as two separate entries named "sys" and "apb", in the same way as the EDMA clocks, and update the example accordingly. The EDMA driver has not been merged upstream yet, and no in-tree device tree uses the ethernet-dma node, so there is no existing user of this binding and it is safe to update it without breaking the ABI. Reviewed-by: Rob Herring (Arm) Signed-off-by: Luo Jie Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-1-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../bindings/net/qcom,ipq9574-ppe.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml b/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml index 6d0b21a10732..c899f4b56945 100644 --- a/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml +++ b/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml @@ -144,8 +144,14 @@ properties: - const: apb resets: - maxItems: 1 - description: EDMA reset + items: + - description: EDMA system reset + - description: EDMA APB reset + + reset-names: + items: + - const: sys + - const: apb interrupts: minItems: 65 @@ -170,6 +176,7 @@ properties: - clocks - clock-names - resets + - reset-names - interrupts - interrupt-names @@ -273,7 +280,10 @@ examples: <&nsscc NSS_CC_PPE_EDMA_CFG_CLK>; clock-names = "sys", "apb"; - resets = <&nsscc EDMA_HW_RESET>; + resets = <&nsscc PPE_EDMA_ARES>, + <&nsscc PPE_EDMA_CFG_ARES>; + reset-names = "sys", + "apb"; interrupts = , , , From 7baaa2bed6fd98d21729889fa55074b0bf9b82f8 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:08 -0700 Subject: [PATCH 1906/2126] net: ethernet: qualcomm: ppe: Fix multicast queue config table access PPE queues 0-255 are unicast queues and queues from 256 onwards are multicast queues. The multicast queue configuration table has its own index, starting from 0 for the first multicast queue, and each entry has 3 words. The driver uses the absolute queue ID as the index of this table, which is out of range for every multicast queue. As a result, the multicast queue thresholds are never configured, and unrelated QM registers are written instead. The driver also accesses 5 words per entry instead of 3. Fix it by converting the queue ID to the index of the multicast queue configuration table and accessing only the 3 words of the entry. Signed-off-by: Luo Jie Fixes: 806268dc7efd ("net: ethernet: qualcomm: Initialize PPE queue management for IPQ9574") Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-2-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qualcomm/ppe/ppe_config.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c index 125b73be92b1..2f4f59280647 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c @@ -1474,7 +1474,7 @@ static int ppe_config_qm(struct ppe_device *ppe_dev) { const struct ppe_qm_queue_config *queue_cfg; int ret, i, queue_id, queue_cfg_count; - u32 reg, multicast_queue_cfg[5]; + u32 reg, multicast_queue_cfg[3]; u32 unicast_queue_cfg[4]; u32 group_cfg[3]; @@ -1530,8 +1530,13 @@ static int ppe_config_qm(struct ppe_device *ppe_dev) if (ret) goto qm_config_fail; } else { + /* The multicast queue table is indexed from 0 for + * the first multicast queue, which follows the + * unicast queues. + */ reg = PPE_AC_MULTICAST_QUEUE_CFG_TBL_ADDR + - PPE_AC_MULTICAST_QUEUE_CFG_TBL_INC * queue_id; + PPE_AC_MULTICAST_QUEUE_CFG_TBL_INC * + (queue_id - PPE_AC_UNICAST_QUEUE_CFG_TBL_ENTRIES); ret = regmap_bulk_read(ppe_dev->regmap, reg, multicast_queue_cfg, From 2575292d1c92276790fa45bfe1d2f5f1cb1eb537 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:09 -0700 Subject: [PATCH 1907/2126] dt-bindings: net: qcom,ipq9574-ppe: Add IPQ5424 PPE support IPQ5424 integrates the same PPE switch core as IPQ9574, but requires a different, smaller set of interconnect paths, and has only 3 front panel ports plus the EDMA FIFO interface, without the EIP FIFO. Add the IPQ5424 compatible, describe the interconnect paths of each SoC, and limit the Ethernet ports of IPQ5424 to ports 1-3. Also match all Ethernet port nodes, so that ports out of the supported range are rejected by the reg limits instead of being left unchecked. Reviewed-by: Rob Herring (Arm) Signed-off-by: Luo Jie Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-3-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../bindings/net/qcom,ipq9574-ppe.yaml | 86 +++++++++++++++---- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml b/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml index c899f4b56945..96e9b9420892 100644 --- a/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml +++ b/Documentation/devicetree/bindings/net/qcom,ipq9574-ppe.yaml @@ -74,9 +74,14 @@ description: | +------->| QCA8075 PHY | | PHY4 | | PHY5 | (clock) +-------------------------------------+ +-------+ +-------+ + The IPQ5424 PPE reuses the same switch core, but wires up only 3 + front panel ports (GMAC0-2) and the single EDMA FIFO interface; it + has no EIP FIFO and no ports 4-6. + properties: compatible: enum: + - qcom,ipq5424-ppe - qcom,ipq9574-ppe reg: @@ -105,24 +110,16 @@ properties: description: PPE switch miscellaneous interrupt interconnects: - items: - - description: Bus interconnect path leading to PPE switch core function - - description: Bus interconnect path leading to PPE register access - - description: Bus interconnect path leading to QoS generation - - description: Bus interconnect path leading to timeout reference - - description: Bus interconnect path leading to NSS NOC from memory NOC - - description: Bus interconnect path leading to memory NOC from NSS NOC - - description: Bus interconnect path leading to enhanced memory NOC from NSS NOC + minItems: 5 + maxItems: 7 + description: + The number of interconnect paths depends on compatible, 5 paths for + qcom,ipq5424-ppe and 7 paths for qcom,ipq9574-ppe, enumerated in the + allOf conditionals below. interconnect-names: - items: - - const: ppe - - const: ppe_cfg - - const: qos_gen - - const: timeout_ref - - const: nssnoc_memnoc - - const: memnoc_nssnoc - - const: memnoc_nssnoc_1 + minItems: 5 + maxItems: 7 ethernet-dma: type: object @@ -182,7 +179,7 @@ properties: ethernet-ports: patternProperties: - "^ethernet-port@[1-6]+$": + "^ethernet-port@[0-9a-f]+$": type: object unevaluatedProperties: false $ref: ethernet-switch-port.yaml# @@ -236,6 +233,61 @@ required: allOf: - $ref: ethernet-switch.yaml + - if: + properties: + compatible: + contains: + const: qcom,ipq9574-ppe + then: + properties: + interconnects: + items: + - description: Bus interconnect path leading to PPE switch core function + - description: Bus interconnect path leading to PPE register access + - description: Bus interconnect path leading to QoS generation + - description: Bus interconnect path leading to timeout reference + - description: Bus interconnect path leading to NSS NOC from memory NOC + - description: Bus interconnect path leading to memory NOC from NSS NOC + - description: Bus interconnect path leading to enhanced memory NOC from NSS NOC + + interconnect-names: + items: + - const: ppe + - const: ppe_cfg + - const: qos_gen + - const: timeout_ref + - const: nssnoc_memnoc + - const: memnoc_nssnoc + - const: memnoc_nssnoc_1 + - if: + properties: + compatible: + contains: + const: qcom,ipq5424-ppe + then: + properties: + interconnects: + items: + - description: Bus interconnect path leading to PPE switch core function + - description: Bus interconnect path leading to PPE register access + - description: Bus interconnect path leading to CE AXI + - description: Bus interconnect path leading to CE APB + - description: Bus interconnect path leading to NSS CSR access + + interconnect-names: + items: + - const: ppe + - const: ppe_cfg + - const: nssnoc_ce_axi + - const: nssnoc_ce_apb + - const: nssnoc_nss_csr + + ethernet-ports: + patternProperties: + "^ethernet-port@[0-9a-f]+$": + properties: + reg: + maximum: 3 unevaluatedProperties: false From ff5f9cb0c28d3da55c32a9d1e5675c9c1df2a623 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:10 -0700 Subject: [PATCH 1908/2126] docs: networking: Document IPQ5424 as a supported SoC Update the qualcomm PPE driver documentation to list IPQ5424 among the supported SoCs, and describe the per-SoC PPE hardware differences. The IPQ5424 PPE reuses the same switch core as IPQ9574, but runs at a clock rate of 375 MHz and supports only 3 front panel ports along with the EDMA FIFO port for host CPU communication. The EIP FIFO port is not available on IPQ5424. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-4-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../device_drivers/ethernet/qualcomm/ppe/ppe.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/networking/device_drivers/ethernet/qualcomm/ppe/ppe.rst b/Documentation/networking/device_drivers/ethernet/qualcomm/ppe/ppe.rst index 4ab299a28969..04c48cec66d5 100644 --- a/Documentation/networking/device_drivers/ethernet/qualcomm/ppe/ppe.rst +++ b/Documentation/networking/device_drivers/ethernet/qualcomm/ppe/ppe.rst @@ -167,6 +167,14 @@ PPE Driver Supported SoCs The PPE driver supports the following IPQ SoC: - IPQ9574 + The PPE runs at a clock rate of 353 MHz. The switch core has 6 front panel + ports (port1 to port6) and two FIFO interfaces: the EDMA FIFO (port0) for + the host CPU communication and the EIP FIFO (port7) for the EIP engine. +- IPQ5424 + The PPE reuses the same switch core as IPQ9574 and runs at a clock rate of + 375 MHz. It supports 3 front panel ports (port1 to port3) with MAC0 to MAC2, + and only the EDMA FIFO interface (port0) for the host CPU communication. The + EIP FIFO and port4 to port6 are not available. Enabling the Driver From b52c8b48864ef526a79e3c155294d26f7f2f8afb Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:11 -0700 Subject: [PATCH 1909/2126] net: ethernet: qualcomm: ppe: Add platform support for IPQ5424 IPQ5424 integrates the same PPE switch core as IPQ9574, but has only 3 Ethernet ports plus the EDMA FIFO, without the EIP FIFO. The PPE clock runs at 375 MHz instead of IPQ9574's 353 MHz, and IPQ5424 requires a different, smaller set of interconnect paths. The register space of the unavailable MAC3 to MAC5 must also not be accessed on IPQ5424. Add the platform data per SoC to describe these differences, and add the IPQ5424 compatible. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-5-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qualcomm/ppe/ppe.c | 132 +++++++++++++++++++++--- 1 file changed, 116 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe.c b/drivers/net/ethernet/qualcomm/ppe/ppe.c index 3c301e609d3e..f71b673b6f97 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe.c @@ -18,13 +18,34 @@ #include "ppe_config.h" #include "ppe_debugfs.h" -#define PPE_PORT_MAX 8 -#define PPE_CLK_RATE 353000000 +#define IPQ9574_PPE_CLK_RATE 353000000 +#define IPQ5424_PPE_CLK_RATE 375000000 + +/* 6 physical ports, 1 EDMA FIFO and 1 EIP FIFO. */ +#define IPQ9574_PPE_PORT_MAX 8 +/* 3 physical ports and 1 EDMA FIFO. */ +#define IPQ5424_PPE_PORT_MAX 4 + +/** + * struct ppe_of_data - PPE private data of IPQ SoC + * @ppe_rate: PPE clock rate + * @num_ports: Number of PPE ports + * @regmap_config: Regmap configuration + * @icc_paths: Interconnect paths per PPE type + * @num_icc_paths: Number of ICC paths + */ +struct ppe_of_data { + unsigned long ppe_rate; + int num_ports; + const struct regmap_config *regmap_config; + const struct icc_bulk_data *icc_paths; + int num_icc_paths; +}; /* ICC clocks for enabling PPE device. The avg_bw and peak_bw with value 0 * will be updated by the clock rate of PPE. */ -static const struct icc_bulk_data ppe_icc_data[] = { +static const struct icc_bulk_data ipq9574_ppe_icc_data[] = { { .name = "ppe", .avg_bw = 0, @@ -62,6 +83,34 @@ static const struct icc_bulk_data ppe_icc_data[] = { }, }; +static const struct icc_bulk_data ipq5424_ppe_icc_data[] = { + { + .name = "ppe", + .avg_bw = 0, + .peak_bw = 0, + }, + { + .name = "ppe_cfg", + .avg_bw = 0, + .peak_bw = 0, + }, + { + .name = "nssnoc_ce_axi", + .avg_bw = 0, + .peak_bw = 0, + }, + { + .name = "nssnoc_ce_apb", + .avg_bw = 0, + .peak_bw = 0, + }, + { + .name = "nssnoc_nss_csr", + .avg_bw = 100000, + .peak_bw = 100000, + }, +}; + static const struct regmap_range ppe_readable_ranges[] = { regmap_reg_range(0x0, 0x1ff), /* Global */ regmap_reg_range(0x400, 0x5ff), /* LPI CSR */ @@ -108,7 +157,36 @@ static const struct regmap_config regmap_config_ipq9574 = { .max_register = 0xbef800, }; -static int ppe_clock_init_and_reset(struct ppe_device *ppe_dev) +/* For IPQ5424, there are only three Ethernet ports, the register space of + * GMAC/XGMAC 3-5 is unavailable. + */ +static const struct regmap_range ppe_reserved_ranges_ipq5424[] = { + regmap_reg_range(0x1600, 0x17ff), /* GMAC3 */ + regmap_reg_range(0x1800, 0x19ff), /* GMAC4 */ + regmap_reg_range(0x1a00, 0x1bff), /* GMAC5 */ + regmap_reg_range(0x50c000, 0x50ffff), /* XGMAC3 */ + regmap_reg_range(0x510000, 0x513fff), /* XGMAC4 */ + regmap_reg_range(0x514000, 0x517fff), /* XGMAC5 */ +}; + +static const struct regmap_access_table ppe_reg_table_ipq5424 = { + .yes_ranges = ppe_readable_ranges, + .n_yes_ranges = ARRAY_SIZE(ppe_readable_ranges), + .no_ranges = ppe_reserved_ranges_ipq5424, + .n_no_ranges = ARRAY_SIZE(ppe_reserved_ranges_ipq5424), +}; + +static const struct regmap_config regmap_config_ipq5424 = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .rd_table = &ppe_reg_table_ipq5424, + .wr_table = &ppe_reg_table_ipq5424, + .max_register = 0xbef800, +}; + +static int ppe_clock_init_and_reset(struct ppe_device *ppe_dev, + const struct ppe_of_data *data) { unsigned long ppe_rate = ppe_dev->clk_rate; struct device *dev = ppe_dev->dev; @@ -118,15 +196,15 @@ static int ppe_clock_init_and_reset(struct ppe_device *ppe_dev) int ret, i; for (i = 0; i < ppe_dev->num_icc_paths; i++) { - ppe_dev->icc_paths[i].name = ppe_icc_data[i].name; - ppe_dev->icc_paths[i].avg_bw = ppe_icc_data[i].avg_bw ? : + ppe_dev->icc_paths[i].name = data->icc_paths[i].name; + ppe_dev->icc_paths[i].avg_bw = data->icc_paths[i].avg_bw ? : Bps_to_icc(ppe_rate); /* PPE does not have an explicit peak bandwidth requirement, * so set the peak bandwidth to be equal to the average * bandwidth. */ - ppe_dev->icc_paths[i].peak_bw = ppe_icc_data[i].peak_bw ? : + ppe_dev->icc_paths[i].peak_bw = data->icc_paths[i].peak_bw ? : Bps_to_icc(ppe_rate); } @@ -173,12 +251,17 @@ static int ppe_clock_init_and_reset(struct ppe_device *ppe_dev) static int qcom_ppe_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + const struct ppe_of_data *data; struct ppe_device *ppe_dev; void __iomem *base; - int ret, num_icc; + int ret; - num_icc = ARRAY_SIZE(ppe_icc_data); - ppe_dev = devm_kzalloc(dev, struct_size(ppe_dev, icc_paths, num_icc), + data = of_device_get_match_data(dev); + if (!data) + return dev_err_probe(dev, -EINVAL, "PPE no match data provided\n"); + + ppe_dev = devm_kzalloc(dev, + struct_size(ppe_dev, icc_paths, data->num_icc_paths), GFP_KERNEL); if (!ppe_dev) return -ENOMEM; @@ -187,16 +270,16 @@ static int qcom_ppe_probe(struct platform_device *pdev) if (IS_ERR(base)) return dev_err_probe(dev, PTR_ERR(base), "PPE ioremap failed\n"); - ppe_dev->regmap = devm_regmap_init_mmio(dev, base, ®map_config_ipq9574); + ppe_dev->regmap = devm_regmap_init_mmio(dev, base, data->regmap_config); if (IS_ERR(ppe_dev->regmap)) return dev_err_probe(dev, PTR_ERR(ppe_dev->regmap), "PPE initialize regmap failed\n"); ppe_dev->dev = dev; - ppe_dev->clk_rate = PPE_CLK_RATE; - ppe_dev->num_ports = PPE_PORT_MAX; - ppe_dev->num_icc_paths = num_icc; + ppe_dev->clk_rate = data->ppe_rate; + ppe_dev->num_ports = data->num_ports; + ppe_dev->num_icc_paths = data->num_icc_paths; - ret = ppe_clock_init_and_reset(ppe_dev); + ret = ppe_clock_init_and_reset(ppe_dev, data); if (ret) return dev_err_probe(dev, ret, "PPE clock config failed\n"); @@ -218,8 +301,25 @@ static void qcom_ppe_remove(struct platform_device *pdev) ppe_debugfs_teardown(ppe_dev); } +static const struct ppe_of_data ipq9574_data = { + .ppe_rate = IPQ9574_PPE_CLK_RATE, + .num_ports = IPQ9574_PPE_PORT_MAX, + .regmap_config = ®map_config_ipq9574, + .icc_paths = ipq9574_ppe_icc_data, + .num_icc_paths = ARRAY_SIZE(ipq9574_ppe_icc_data), +}; + +static const struct ppe_of_data ipq5424_data = { + .ppe_rate = IPQ5424_PPE_CLK_RATE, + .num_ports = IPQ5424_PPE_PORT_MAX, + .regmap_config = ®map_config_ipq5424, + .icc_paths = ipq5424_ppe_icc_data, + .num_icc_paths = ARRAY_SIZE(ipq5424_ppe_icc_data), +}; + static const struct of_device_id qcom_ppe_of_match[] = { - { .compatible = "qcom,ipq9574-ppe" }, + { .compatible = "qcom,ipq9574-ppe", .data = &ipq9574_data }, + { .compatible = "qcom,ipq5424-ppe", .data = &ipq5424_data }, {} }; MODULE_DEVICE_TABLE(of, qcom_ppe_of_match); From d377b0e5c4889af69c1c52b45e26395ca2ef51ac Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:12 -0700 Subject: [PATCH 1910/2126] net: ethernet: qualcomm: ppe: Add IPQ5424 BM buffer configuration IPQ5424 has fewer PPE ports than IPQ9574, so it requires a different buffer configuration per port, and more buffers are left for the shared buffer pool. IPQ5424 also has more BM ports than IPQ9574, 19 versus 15, so some BM register tables have more entries on IPQ5424, and some of them are located at different addresses. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-6-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qualcomm/ppe/ppe.c | 5 ++ drivers/net/ethernet/qualcomm/ppe/ppe.h | 15 ++++ .../net/ethernet/qualcomm/ppe/ppe_config.c | 79 +++++++++++++++++-- drivers/net/ethernet/qualcomm/ppe/ppe_regs.h | 35 ++++++-- 4 files changed, 118 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe.c b/drivers/net/ethernet/qualcomm/ppe/ppe.c index f71b673b6f97..b144fd818998 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe.c @@ -28,6 +28,7 @@ /** * struct ppe_of_data - PPE private data of IPQ SoC + * @type: PPE type value * @ppe_rate: PPE clock rate * @num_ports: Number of PPE ports * @regmap_config: Regmap configuration @@ -35,6 +36,7 @@ * @num_icc_paths: Number of ICC paths */ struct ppe_of_data { + enum ppe_type type; unsigned long ppe_rate; int num_ports; const struct regmap_config *regmap_config; @@ -275,6 +277,7 @@ static int qcom_ppe_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(ppe_dev->regmap), "PPE initialize regmap failed\n"); ppe_dev->dev = dev; + ppe_dev->type = data->type; ppe_dev->clk_rate = data->ppe_rate; ppe_dev->num_ports = data->num_ports; ppe_dev->num_icc_paths = data->num_icc_paths; @@ -302,6 +305,7 @@ static void qcom_ppe_remove(struct platform_device *pdev) } static const struct ppe_of_data ipq9574_data = { + .type = IPQ9574_PPE, .ppe_rate = IPQ9574_PPE_CLK_RATE, .num_ports = IPQ9574_PPE_PORT_MAX, .regmap_config = ®map_config_ipq9574, @@ -310,6 +314,7 @@ static const struct ppe_of_data ipq9574_data = { }; static const struct ppe_of_data ipq5424_data = { + .type = IPQ5424_PPE, .ppe_rate = IPQ5424_PPE_CLK_RATE, .num_ports = IPQ5424_PPE_PORT_MAX, .regmap_config = ®map_config_ipq5424, diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe.h b/drivers/net/ethernet/qualcomm/ppe/ppe.h index 27458f0bc206..33b876d2e079 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe.h +++ b/drivers/net/ethernet/qualcomm/ppe/ppe.h @@ -13,10 +13,24 @@ struct device; struct regmap; struct dentry; +/** + * enum ppe_type - PPE device type. + * @IPQ9574_PPE: PPE device of IPQ9574. + * @IPQ5424_PPE: PPE device of IPQ5424. + * + * PPE type is used to identify the PPE device of the different + * IPQ platform. + */ +enum ppe_type { + IPQ9574_PPE, + IPQ5424_PPE, +}; + /** * struct ppe_device - PPE device private data. * @dev: PPE device structure. * @regmap: PPE register map. + * @type: Different PPE type on various IPQ SoC. * @clk_rate: PPE clock rate. * @num_ports: Number of PPE ports. * @debugfs_root: Debugfs root entry. @@ -30,6 +44,7 @@ struct dentry; struct ppe_device { struct device *dev; struct regmap *regmap; + enum ppe_type type; unsigned long clk_rate; unsigned int num_ports; struct dentry *debugfs_root; diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c index 2f4f59280647..ef46e9b133fe 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c @@ -230,6 +230,56 @@ static const struct ppe_bm_port_config ipq9574_ppe_bm_port_config[] = { }, }; +/* IPQ5424 has fewer PPE physical ports (3) than IPQ9574 (6), so fewer + * buffers need to be reserved for per-port purposes. Out of the same + * 2048 total, the rest assigned to the general 'group0' pool is + * correspondingly larger here, 1650 versus IPQ9574's 1550. + */ +static const int ipq5424_ppe_bm_group_config = 1650; + +/* The buffer configurations per PPE port on IPQ5424. There are 19 BM + * ports supported by PPE. BM port (0-15) is for EDMA port 0, and BM + * port (16-18) is for the 3 PPE physical ports. + */ +static const struct ppe_bm_port_config ipq5424_ppe_bm_port_config[] = { + { + /* Buffer configuration for the BM port ID 0 of EDMA. */ + .port_id_start = 0, + .port_id_end = 0, + .pre_alloc = 0, + .in_fly_buf = 100, + .ceil = 1146, + .weight = 7, + .resume_offset = 8, + .resume_ceil = 0, + .dynamic = true, + }, + { + /* Buffer configuration for the BM port ID 1-15 of EDMA. */ + .port_id_start = 1, + .port_id_end = 15, + .pre_alloc = 0, + .in_fly_buf = 100, + .ceil = 250, + .weight = 4, + .resume_offset = 36, + .resume_ceil = 0, + .dynamic = true, + }, + { + /* Buffer configuration for the BM port ID 16-18 of PPE ports. */ + .port_id_start = 16, + .port_id_end = 18, + .pre_alloc = 0, + .in_fly_buf = 128, + .ceil = 250, + .weight = 4, + .resume_offset = 36, + .resume_ceil = 0, + .dynamic = true, + }, +}; + /* QM fetches the packet from PPE buffer management for transmitting the * packet out. The QM group configuration limits the total number of buffers * enqueued by all PPE hardware queues. @@ -1413,7 +1463,7 @@ static int ppe_config_bm_threshold(struct ppe_device *ppe_dev, int bm_port_id, /* Assign the default group ID 0 to the BM port. */ val = FIELD_PREP(PPE_BM_PORT_GROUP_ID_SHARED_GROUP_ID, 0); - reg = PPE_BM_PORT_GROUP_ID_ADDR + PPE_BM_PORT_GROUP_ID_INC * bm_port_id; + reg = PPE_BM_PORT_GROUP_ID_ADDR(ppe_dev) + PPE_BM_PORT_GROUP_ID_INC * bm_port_id; ret = regmap_update_bits(ppe_dev->regmap, reg, PPE_BM_PORT_GROUP_ID_SHARED_GROUP_ID, val); @@ -1431,25 +1481,38 @@ static int ppe_config_bm(struct ppe_device *ppe_dev) { const struct ppe_bm_port_config *port_cfg; unsigned int i, bm_port_id, port_cfg_cnt; - u32 reg, val; + u32 reg, val, group_cfg; int ret; + switch (ppe_dev->type) { + case IPQ9574_PPE: + port_cfg = ipq9574_ppe_bm_port_config; + port_cfg_cnt = ARRAY_SIZE(ipq9574_ppe_bm_port_config); + group_cfg = ipq9574_ppe_bm_group_config; + break; + case IPQ5424_PPE: + port_cfg = ipq5424_ppe_bm_port_config; + port_cfg_cnt = ARRAY_SIZE(ipq5424_ppe_bm_port_config); + group_cfg = ipq5424_ppe_bm_group_config; + break; + default: + dev_err(ppe_dev->dev, "Invalid PPE type %d\n", ppe_dev->type); + return -EINVAL; + } + + reg = PPE_BM_SHARED_GROUP_CFG_ADDR(ppe_dev); + /* Configure the allocated buffer number only for group 0. * The buffer number of group 1-3 is already cleared to 0 * after PPE reset during the probe of PPE driver. */ - reg = PPE_BM_SHARED_GROUP_CFG_ADDR; - val = FIELD_PREP(PPE_BM_SHARED_GROUP_CFG_SHARED_LIMIT, - ipq9574_ppe_bm_group_config); + val = FIELD_PREP(PPE_BM_SHARED_GROUP_CFG_SHARED_LIMIT, group_cfg); ret = regmap_update_bits(ppe_dev->regmap, reg, PPE_BM_SHARED_GROUP_CFG_SHARED_LIMIT, val); if (ret) goto bm_config_fail; - /* Configure buffer thresholds for the BM ports. */ - port_cfg = ipq9574_ppe_bm_port_config; - port_cfg_cnt = ARRAY_SIZE(ipq9574_ppe_bm_port_config); for (i = 0; i < port_cfg_cnt; i++) { for (bm_port_id = port_cfg[i].port_id_start; bm_port_id <= port_cfg[i].port_id_end; bm_port_id++) { diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h b/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h index 746dfbb5a682..441e8e04a80b 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h @@ -386,17 +386,32 @@ #define PPE_PSCH_SCH_CFG_TBL_DES_SECOND_PORT_EN BIT(16) #define PPE_PSCH_SCH_CFG_TBL_DES_SECOND_PORT GENMASK(20, 17) -/* There are 15 BM ports and 4 BM groups supported by PPE. - * BM port (0-7) is for EDMA port 0, BM port (8-13) is for - * PPE physical port 1-6 and BM port 14 is for EIP port. +/* There are 15 BM ports on IPQ9574 and 19 BM ports on IPQ5424, and + * 4 BM groups supported by PPE. On IPQ9574, BM port (0-7) is for EDMA + * port 0, BM port (8-13) is for PPE physical port 1-6 and BM port 14 + * is for EIP port. On IPQ5424, BM port (0-15) is for EDMA port 0 and + * BM port (16-18) is for PPE physical port 1-3. + * + * The per-BM-port tables PPE_BM_PORT_FC_MODE and PPE_BM_PORT_FC_CFG_TBL + * are at the same address on both SoCs, IPQ5424 only has more entries. */ +#define PPE_BM_PORT_IPQ9574_ENTRIES 15 +#define PPE_BM_PORT_IPQ5424_ENTRIES 19 +#define PPE_BM_PORT_ENTRIES(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_PORT_IPQ5424_ENTRIES : \ + PPE_BM_PORT_IPQ9574_ENTRIES) + #define PPE_BM_PORT_FC_MODE_ADDR 0x600100 -#define PPE_BM_PORT_FC_MODE_ENTRIES 15 +#define PPE_BM_PORT_FC_MODE_ENTRIES(ppe_dev) PPE_BM_PORT_ENTRIES(ppe_dev) #define PPE_BM_PORT_FC_MODE_INC 0x4 #define PPE_BM_PORT_FC_MODE_EN BIT(0) -#define PPE_BM_PORT_GROUP_ID_ADDR 0x600180 -#define PPE_BM_PORT_GROUP_ID_ENTRIES 15 +#define PPE_BM_PORT_GROUP_ID_IPQ9574_ADDR 0x600180 +#define PPE_BM_PORT_GROUP_ID_IPQ5424_ADDR 0x6001c0 +#define PPE_BM_PORT_GROUP_ID_ADDR(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_PORT_GROUP_ID_IPQ5424_ADDR : \ + PPE_BM_PORT_GROUP_ID_IPQ9574_ADDR) +#define PPE_BM_PORT_GROUP_ID_ENTRIES(ppe_dev) PPE_BM_PORT_ENTRIES(ppe_dev) #define PPE_BM_PORT_GROUP_ID_INC 0x4 #define PPE_BM_PORT_GROUP_ID_SHARED_GROUP_ID GENMASK(1, 0) @@ -412,13 +427,17 @@ #define PPE_BM_REACT_CNT_TBL_INC 0x4 #define PPE_BM_REACT_CNT_VAL GENMASK(8, 0) -#define PPE_BM_SHARED_GROUP_CFG_ADDR 0x600290 +#define PPE_BM_SHARED_GROUP_CFG_IPQ9574_ADDR 0x600290 +#define PPE_BM_SHARED_GROUP_CFG_IPQ5424_ADDR 0x6002f0 +#define PPE_BM_SHARED_GROUP_CFG_ADDR(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_SHARED_GROUP_CFG_IPQ5424_ADDR : \ + PPE_BM_SHARED_GROUP_CFG_IPQ9574_ADDR) #define PPE_BM_SHARED_GROUP_CFG_ENTRIES 4 #define PPE_BM_SHARED_GROUP_CFG_INC 0x4 #define PPE_BM_SHARED_GROUP_CFG_SHARED_LIMIT GENMASK(10, 0) #define PPE_BM_PORT_FC_CFG_TBL_ADDR 0x601000 -#define PPE_BM_PORT_FC_CFG_TBL_ENTRIES 15 +#define PPE_BM_PORT_FC_CFG_TBL_ENTRIES(ppe_dev) PPE_BM_PORT_ENTRIES(ppe_dev) #define PPE_BM_PORT_FC_CFG_TBL_INC 0x10 #define PPE_BM_PORT_FC_W0_REACT_LIMIT GENMASK(8, 0) #define PPE_BM_PORT_FC_W0_RESUME_THRESHOLD GENMASK(17, 9) From 04181e75cbd28ec55591ec69471874463515e715 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:13 -0700 Subject: [PATCH 1911/2126] net: ethernet: qualcomm: ppe: Add IPQ5424 QM configuration Multicast queues are dedicated per PPE port. IPQ5424 has only 3 physical PPE ports, versus IPQ9574's 6 PPE ports, so multicast queues 284 to 299 are not available on IPQ5424, and 2010 buffers are assigned to the shared group0 buffer pool, instead of IPQ9574's 2000. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-7-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/qualcomm/ppe/ppe_config.c | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c index ef46e9b133fe..d2bd78853b98 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c @@ -314,6 +314,37 @@ static const struct ppe_qm_queue_config ipq9574_ppe_qm_queue_config[] = { }, }; +/* Multicast queues are dedicated per PPE port. IPQ5424 has only 3 physical + * PPE ports, versus IPQ9574's 6 PPE ports, so multicast queues 284 to 299 + * are not available on IPQ5424, and the buffer pool assigned to the general + * 'group0' is larger here, 2010 versus IPQ9574's 2000. + */ +static const int ipq5424_ppe_qm_group_config = 2010; + +/* Default QM settings for unicast and multicast queues for IPQ5424. */ +static const struct ppe_qm_queue_config ipq5424_ppe_qm_queue_config[] = { + { + /* QM settings for unicast queues 0 to 255. */ + .queue_start = 0, + .queue_end = 255, + .prealloc_buf = 0, + .ceil = 1200, + .weight = 7, + .resume_offset = 36, + .dynamic = true, + }, + { + /* QM settings for multicast queues 256 to 283. */ + .queue_start = 256, + .queue_end = 283, + .prealloc_buf = 0, + .ceil = 250, + .weight = 0, + .resume_offset = 36, + .dynamic = false, + }, +}; + /* PPE scheduler configuration for BM includes multiple entries. Each entry * indicates the primary port to be assigned the buffers for the ingress or * to release the buffers for the egress. Backup port ID will be used when @@ -1535,12 +1566,28 @@ bm_config_fail: */ static int ppe_config_qm(struct ppe_device *ppe_dev) { + int ret, i, group_buffer_cfg, queue_id, queue_cfg_count; const struct ppe_qm_queue_config *queue_cfg; - int ret, i, queue_id, queue_cfg_count; u32 reg, multicast_queue_cfg[3]; u32 unicast_queue_cfg[4]; u32 group_cfg[3]; + switch (ppe_dev->type) { + case IPQ9574_PPE: + group_buffer_cfg = ipq9574_ppe_qm_group_config; + queue_cfg = ipq9574_ppe_qm_queue_config; + queue_cfg_count = ARRAY_SIZE(ipq9574_ppe_qm_queue_config); + break; + case IPQ5424_PPE: + group_buffer_cfg = ipq5424_ppe_qm_group_config; + queue_cfg = ipq5424_ppe_qm_queue_config; + queue_cfg_count = ARRAY_SIZE(ipq5424_ppe_qm_queue_config); + break; + default: + dev_err(ppe_dev->dev, "Invalid PPE type %d\n", ppe_dev->type); + return -EINVAL; + } + /* Assign the buffer number to the group 0 by default. */ reg = PPE_AC_GRP_CFG_TBL_ADDR; ret = regmap_bulk_read(ppe_dev->regmap, reg, @@ -1548,15 +1595,13 @@ static int ppe_config_qm(struct ppe_device *ppe_dev) if (ret) goto qm_config_fail; - PPE_AC_GRP_SET_BUF_LIMIT(group_cfg, ipq9574_ppe_qm_group_config); + PPE_AC_GRP_SET_BUF_LIMIT(group_cfg, group_buffer_cfg); ret = regmap_bulk_write(ppe_dev->regmap, reg, group_cfg, ARRAY_SIZE(group_cfg)); if (ret) goto qm_config_fail; - queue_cfg = ipq9574_ppe_qm_queue_config; - queue_cfg_count = ARRAY_SIZE(ipq9574_ppe_qm_queue_config); for (i = 0; i < queue_cfg_count; i++) { queue_id = queue_cfg[i].queue_start; From b9f3abbb9f1c4a4107fcdadd6b12718582b1fb09 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:14 -0700 Subject: [PATCH 1912/2126] net: ethernet: qualcomm: ppe: Add IPQ5424 scheduler resource configuration The PPE scheduler resources, such as queues and scheduler nodes, are assigned per PPE port, followed by one reserved resource entry. IPQ5424 has fewer PPE ports than IPQ9574, so its reserved resource is located at a different position. Add the dedicated scheduler resource configuration for IPQ5424. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-8-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/qualcomm/ppe/ppe_config.c | 84 +++++++++++++++++-- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c index d2bd78853b98..01c92a5459d9 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c @@ -814,7 +814,7 @@ static const struct ppe_scheduler_port_config ppe_port_sch_config[] = { /* The scheduler resource is applied to each PPE port, The resource * includes the unicast & multicast queues, flow nodes and DRR nodes. */ -static const struct ppe_port_schedule_resource ppe_scheduler_res[] = { +static const struct ppe_port_schedule_resource ipq9574_ppe_scheduler_res[] = { { .ucastq_start = 0, .ucastq_end = 63, .mcastq_start = 256, @@ -916,6 +916,64 @@ static const struct ppe_port_schedule_resource ppe_scheduler_res[] = { }, }; +static const struct ppe_port_schedule_resource ipq5424_ppe_scheduler_res[] = { + { .ucastq_start = 0, + .ucastq_end = 63, + .mcastq_start = 256, + .mcastq_end = 271, + .flow_id_start = 0, + .flow_id_end = 0, + .l0node_start = 0, + .l0node_end = 7, + .l1node_start = 0, + .l1node_end = 0, + }, + { .ucastq_start = 144, + .ucastq_end = 159, + .mcastq_start = 272, + .mcastq_end = 275, + .flow_id_start = 36, + .flow_id_end = 39, + .l0node_start = 48, + .l0node_end = 63, + .l1node_start = 8, + .l1node_end = 11, + }, + { .ucastq_start = 160, + .ucastq_end = 175, + .mcastq_start = 276, + .mcastq_end = 279, + .flow_id_start = 40, + .flow_id_end = 43, + .l0node_start = 64, + .l0node_end = 79, + .l1node_start = 12, + .l1node_end = 15, + }, + { .ucastq_start = 176, + .ucastq_end = 191, + .mcastq_start = 280, + .mcastq_end = 283, + .flow_id_start = 44, + .flow_id_end = 47, + .l0node_start = 80, + .l0node_end = 95, + .l1node_start = 16, + .l1node_end = 19, + }, + { .ucastq_start = 64, + .ucastq_end = 143, + .mcastq_start = 0, + .mcastq_end = 0, + .flow_id_start = 1, + .flow_id_end = 35, + .l0node_start = 8, + .l0node_end = 47, + .l1node_start = 1, + .l1node_end = 7, + }, +}; + /* Set the PPE queue level scheduler configuration. */ static int ppe_scheduler_l0_queue_map_set(struct ppe_device *ppe_dev, int node_id, int port, @@ -1153,15 +1211,31 @@ int ppe_port_resource_get(struct ppe_device *ppe_dev, int port, enum ppe_resource_type type, int *res_start, int *res_end) { + const struct ppe_port_schedule_resource *scheduler_res; struct ppe_port_schedule_resource res; + unsigned int scheduler_res_len; - /* The reserved resource with the maximum port ID of PPE is - * also allowed to be acquired. + switch (ppe_dev->type) { + case IPQ9574_PPE: + scheduler_res = ipq9574_ppe_scheduler_res; + scheduler_res_len = ARRAY_SIZE(ipq9574_ppe_scheduler_res); + break; + case IPQ5424_PPE: + scheduler_res = ipq5424_ppe_scheduler_res; + scheduler_res_len = ARRAY_SIZE(ipq5424_ppe_scheduler_res); + break; + default: + dev_err(ppe_dev->dev, "Invalid PPE type %d\n", ppe_dev->type); + return -EINVAL; + } + + /* The reserved resource, stored at the last entry of the + * scheduler resource table, is also allowed to be acquired. */ - if (port > ppe_dev->num_ports) + if (port >= scheduler_res_len) return -EINVAL; - res = ppe_scheduler_res[port]; + res = scheduler_res[port]; switch (type) { case PPE_RES_UCAST: *res_start = res.ucastq_start; From 7ba101e7fa86b4a170628a02c2de27119b9c3dea Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:15 -0700 Subject: [PATCH 1913/2126] net: ethernet: qualcomm: ppe: Add IPQ5424 scheduler configuration The PPE scheduler arbitrates the access to the BM and QM among the PPE ports. IPQ5424 has a different port topology than IPQ9574, so it requires its own BM and QM scheduler configuration. Add the BM and QM scheduler configuration tables for IPQ5424. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-9-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/qualcomm/ppe/ppe_config.c | 231 +++++++++++++++++- 1 file changed, 221 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c index 01c92a5459d9..017d2e834251 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c @@ -520,6 +520,205 @@ static const struct ppe_scheduler_qm_config ipq9574_ppe_sch_qm_config[] = { {0x98, 6, 5, true, 2}, }; +static const struct ppe_scheduler_bm_config ipq5424_ppe_sch_bm_config[] = { + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 1}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, false, 0}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 2}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 1, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 3}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 3}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 1, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 1}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, false, 0}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 3}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 2, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 3}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 1, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 1}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, false, 0}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 3}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 2, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 1}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 3, true, 2}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 1, false, 0}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 3}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 3, false, 0}, + {true, PPE_SCH_EGRESS, 1, true, 2}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 3, false, 0}, + {true, PPE_SCH_INGRESS, 2, false, 0}, + {true, PPE_SCH_EGRESS, 0, false, 0}, + {true, PPE_SCH_INGRESS, 1, false, 0}, + {true, PPE_SCH_EGRESS, 2, true, 3}, + {true, PPE_SCH_INGRESS, 0, false, 0}, + {true, PPE_SCH_EGRESS, 1, false, 0}, +}; + +/* ensch_port_bmp is left as 0 for every entry here, unlike + * ipq9574_ppe_sch_qm_config[] above. This is expected for IPQ5424, + * not an omission. + */ +static const struct ppe_scheduler_qm_config ipq5424_ppe_sch_qm_config[] = { + {0x0, 3, 2, false, 0}, + {0x0, 1, 3, false, 0}, + {0x0, 0, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 3, 1, true, 0}, + {0x0, 3, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 3, 1, true, 0}, + {0x0, 3, 2, false, 0}, + {0x0, 1, 3, false, 0}, + {0x0, 0, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 3, 1, true, 0}, + {0x0, 3, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 0, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 3, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 3, 2, true, 0}, + {0x0, 3, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 1, 3, false, 0}, + {0x0, 0, 1, false, 0}, + {0x0, 3, 2, true, 0}, + {0x0, 3, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 0, 2, false, 0}, + {0x0, 3, 1, false, 0}, + {0x0, 2, 0, false, 0}, + {0x0, 1, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 0, 2, false, 0}, + {0x0, 3, 0, false, 0}, + {0x0, 3, 1, false, 0}, + {0x0, 2, 3, false, 0}, + {0x0, 0, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 3, 2, true, 0}, + {0x0, 3, 1, false, 0}, + {0x0, 2, 3, false, 0}, + {0x0, 0, 2, false, 0}, + {0x0, 1, 0, false, 0}, + {0x0, 2, 1, false, 0}, + {0x0, 0, 2, false, 0}, + {0x0, 3, 0, false, 0}, +}; + static const struct ppe_scheduler_port_config ppe_port_sch_config[] = { { .port = 0, @@ -1817,14 +2016,29 @@ static int ppe_config_scheduler(struct ppe_device *ppe_dev) const struct ppe_scheduler_port_config *port_cfg; const struct ppe_scheduler_qm_config *qm_cfg; const struct ppe_scheduler_bm_config *bm_cfg; - int ret, i, count; + int ret, i, bm_count, qm_count, count; u32 val, reg; - count = ARRAY_SIZE(ipq9574_ppe_sch_bm_config); - bm_cfg = ipq9574_ppe_sch_bm_config; + switch (ppe_dev->type) { + case IPQ9574_PPE: + bm_cfg = ipq9574_ppe_sch_bm_config; + bm_count = ARRAY_SIZE(ipq9574_ppe_sch_bm_config); + qm_cfg = ipq9574_ppe_sch_qm_config; + qm_count = ARRAY_SIZE(ipq9574_ppe_sch_qm_config); + break; + case IPQ5424_PPE: + bm_cfg = ipq5424_ppe_sch_bm_config; + bm_count = ARRAY_SIZE(ipq5424_ppe_sch_bm_config); + qm_cfg = ipq5424_ppe_sch_qm_config; + qm_count = ARRAY_SIZE(ipq5424_ppe_sch_qm_config); + break; + default: + dev_err(ppe_dev->dev, "Invalid PPE type %d\n", ppe_dev->type); + return -EINVAL; + } /* Configure the depth of BM scheduler entries. */ - val = FIELD_PREP(PPE_BM_SCH_CTRL_SCH_DEPTH, count); + val = FIELD_PREP(PPE_BM_SCH_CTRL_SCH_DEPTH, bm_count); val |= FIELD_PREP(PPE_BM_SCH_CTRL_SCH_OFFSET, 0); val |= FIELD_PREP(PPE_BM_SCH_CTRL_SCH_EN, 1); @@ -1836,7 +2050,7 @@ static int ppe_config_scheduler(struct ppe_device *ppe_dev) * egress port, the second port takes effect when the specified port * is in the inactive state. */ - for (i = 0; i < count; i++) { + for (i = 0; i < bm_count; i++) { val = FIELD_PREP(PPE_BM_SCH_CFG_TBL_VALID, bm_cfg[i].valid); val |= FIELD_PREP(PPE_BM_SCH_CFG_TBL_DIR, bm_cfg[i].dir); val |= FIELD_PREP(PPE_BM_SCH_CFG_TBL_PORT_NUM, bm_cfg[i].port); @@ -1851,11 +2065,8 @@ static int ppe_config_scheduler(struct ppe_device *ppe_dev) goto sch_config_fail; } - count = ARRAY_SIZE(ipq9574_ppe_sch_qm_config); - qm_cfg = ipq9574_ppe_sch_qm_config; - /* Configure the depth of QM scheduler entries. */ - val = FIELD_PREP(PPE_PSCH_SCH_DEPTH_CFG_SCH_DEPTH, count); + val = FIELD_PREP(PPE_PSCH_SCH_DEPTH_CFG_SCH_DEPTH, qm_count); ret = regmap_write(ppe_dev->regmap, PPE_PSCH_SCH_DEPTH_CFG_ADDR, val); if (ret) goto sch_config_fail; @@ -1864,7 +2075,7 @@ static int ppe_config_scheduler(struct ppe_device *ppe_dev) * port, the second port takes effect when the specified dequeue * port is in the inactive port. */ - for (i = 0; i < count; i++) { + for (i = 0; i < qm_count; i++) { val = FIELD_PREP(PPE_PSCH_SCH_CFG_TBL_ENS_PORT_BITMAP, qm_cfg[i].ensch_port_bmp); val |= FIELD_PREP(PPE_PSCH_SCH_CFG_TBL_ENS_PORT, From c61091061206c4c244cede6a61a40a40a285b28a Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:16 -0700 Subject: [PATCH 1914/2126] net: ethernet: qualcomm: ppe: Add IPQ5424 service code configuration The entries of the L2 service code table are 0x20 apart on IPQ5424, instead of 0x10 on IPQ9574. Each IPQ5424 entry also has a second word holding the extended egress bypass bitmap, which adds the bypass of the source MAC multicast drop, L2 flooding and tunnel exception counter control. Add the L2 service code table stride and the extended egress bypass bitmap for IPQ5424. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-10-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qualcomm/ppe/ppe_config.c | 13 ++++++++++--- drivers/net/ethernet/qualcomm/ppe/ppe_config.h | 4 ++++ drivers/net/ethernet/qualcomm/ppe/ppe_regs.h | 12 +++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c index 017d2e834251..3dc1bcc8949e 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.c @@ -1476,7 +1476,7 @@ int ppe_port_resource_get(struct ppe_device *ppe_dev, int port, */ int ppe_sc_config_set(struct ppe_device *ppe_dev, int sc, struct ppe_sc_cfg cfg) { - u32 val, reg, servcode_val[2] = {}; + u32 val, reg, servcode_val[2] = {}, in_l2_val[2] = {}; unsigned long bitmap_value; int ret; @@ -1490,9 +1490,16 @@ int ppe_sc_config_set(struct ppe_device *ppe_dev, int sc, struct ppe_sc_cfg cfg) test_bit(PPE_SC_BYPASS_COUNTER_RX, cfg.bitmaps.counter)); val |= FIELD_PREP(PPE_IN_L2_SERVICE_TBL_TX_CNT_EN, test_bit(PPE_SC_BYPASS_COUNTER_TX, cfg.bitmaps.counter)); - reg = PPE_IN_L2_SERVICE_TBL_ADDR + PPE_IN_L2_SERVICE_TBL_INC * sc; + reg = PPE_IN_L2_SERVICE_TBL_ADDR + PPE_IN_L2_SERVICE_TBL_INC(ppe_dev) * sc; - ret = regmap_write(ppe_dev->regmap, reg, val); + in_l2_val[0] = val; + + bitmap_value = bitmap_read(cfg.bitmaps.egress, PPE_SC_BYPASS_EGRESS_SMAC_MC_DROP, + PPE_SC_BYPASS_EGRESS_SIZE - PPE_SC_BYPASS_EGRESS_SMAC_MC_DROP); + in_l2_val[1] = FIELD_PREP(PPE_IN_L2_SERVICE_TBL_W1_BYPASS_BITMAP_EXT, bitmap_value); + + ret = regmap_bulk_write(ppe_dev->regmap, reg, in_l2_val, + PPE_IN_L2_SERVICE_TBL_WORDS(ppe_dev)); if (ret) return ret; diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_config.h b/drivers/net/ethernet/qualcomm/ppe/ppe_config.h index 60493e51e0a4..e7cdab9d963a 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_config.h +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_config.h @@ -163,6 +163,10 @@ enum ppe_sc_egress_type { PPE_SC_BYPASS_EGRESS_FAKE_MAC_DROP = 21, PPE_SC_BYPASS_EGRESS_TUNL_CONTEXT = 22, PPE_SC_BYPASS_EGRESS_FLOW_POLICER = 23, + /* Values 24-26 are only supported by IPQ5424. */ + PPE_SC_BYPASS_EGRESS_SMAC_MC_DROP = 24, + PPE_SC_BYPASS_EGRESS_L2_FLOODING = 25, + PPE_SC_BYPASS_EGRESS_TUNNEL_EXP_CNT_CTRL = 26, /* This must be last as it determines the size of the BITMAP. */ PPE_SC_BYPASS_EGRESS_SIZE, }; diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h b/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h index 441e8e04a80b..089aa34b7732 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h @@ -223,13 +223,23 @@ /* PPE service code configuration for destination port and counter. */ #define PPE_IN_L2_SERVICE_TBL_ADDR 0x66000 #define PPE_IN_L2_SERVICE_TBL_ENTRIES 256 -#define PPE_IN_L2_SERVICE_TBL_INC 0x10 +#define PPE_IN_L2_SERVICE_TBL_IPQ9574_INC 0x10 +#define PPE_IN_L2_SERVICE_TBL_IPQ5424_INC 0x20 +#define PPE_IN_L2_SERVICE_TBL_INC(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_IN_L2_SERVICE_TBL_IPQ5424_INC : \ + PPE_IN_L2_SERVICE_TBL_IPQ9574_INC) +#define PPE_IN_L2_SERVICE_TBL_IPQ9574_WORDS 1 +#define PPE_IN_L2_SERVICE_TBL_IPQ5424_WORDS 2 +#define PPE_IN_L2_SERVICE_TBL_WORDS(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_IN_L2_SERVICE_TBL_IPQ5424_WORDS : \ + PPE_IN_L2_SERVICE_TBL_IPQ9574_WORDS) #define PPE_IN_L2_SERVICE_TBL_DST_PORT_ID_VALID BIT(0) #define PPE_IN_L2_SERVICE_TBL_DST_PORT_ID GENMASK(4, 1) #define PPE_IN_L2_SERVICE_TBL_DST_DIRECTION BIT(5) #define PPE_IN_L2_SERVICE_TBL_DST_BYPASS_BITMAP GENMASK(29, 6) #define PPE_IN_L2_SERVICE_TBL_RX_CNT_EN BIT(30) #define PPE_IN_L2_SERVICE_TBL_TX_CNT_EN BIT(31) +#define PPE_IN_L2_SERVICE_TBL_W1_BYPASS_BITMAP_EXT GENMASK(7, 0) /* L2 Port configurations */ #define PPE_L2_VP_PORT_TBL_ADDR 0x98000 From f60a45426d5ae49affe6530372b0a75d5b09c219 Mon Sep 17 00:00:00 2001 From: Luo Jie Date: Sun, 11 Oct 2026 06:02:17 -0700 Subject: [PATCH 1915/2126] net: ethernet: qualcomm: ppe: Add IPQ5424 counter debugfs support IPQ5424 has more BM ports than IPQ9574, so the BM used, reacted and overflow-drop counter tables have more entries on IPQ5424, and the used and reacted counter tables are located at different addresses. The BM silent-drop counter table on the other hand has only 4 entries on IPQ5424, versus 8 on IPQ9574. Signed-off-by: Luo Jie Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261011-qcom_ipq5424_ppe-v2-11-8c7b057e2c43@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/qualcomm/ppe/ppe_debugfs.c | 14 ++++---- drivers/net/ethernet/qualcomm/ppe/ppe_regs.h | 36 +++++++++++++++---- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c b/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c index fd959a76ff43..8d5a6fad8337 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c @@ -201,7 +201,7 @@ static int ppe_bm_counter_get(struct ppe_device *ppe_dev, struct seq_file *seq) seq_printf(seq, "%-24s", "BM SILENT_DROP:"); tag = 0; - for (i = 0; i < PPE_DROP_CNT_TBL_ENTRIES; i++) { + for (i = 0; i < PPE_DROP_CNT_TBL_ENTRIES(ppe_dev); i++) { reg = PPE_DROP_CNT_TBL_ADDR + i * PPE_DROP_CNT_TBL_INC; ret = ppe_pkt_cnt_get(ppe_dev, reg, PPE_PKT_CNT_SIZE_1WORD, &pkt_cnt, NULL); @@ -225,7 +225,7 @@ static int ppe_bm_counter_get(struct ppe_device *ppe_dev, struct seq_file *seq) */ seq_printf(seq, "%-24s", "BM OVERFLOW_DROP:"); tag = 0; - for (i = 0; i < PPE_DROP_STAT_TBL_ENTRIES; i++) { + for (i = 0; i < PPE_DROP_STAT_TBL_ENTRIES(ppe_dev); i++) { reg = PPE_DROP_STAT_TBL_ADDR + PPE_DROP_STAT_TBL_INC * i; ret = ppe_pkt_cnt_get(ppe_dev, reg, PPE_PKT_CNT_SIZE_3WORD, @@ -248,8 +248,8 @@ static int ppe_bm_counter_get(struct ppe_device *ppe_dev, struct seq_file *seq) /* The number of currently occupied buffers, that can't be flushed. */ seq_printf(seq, "%-24s", "BM USED/REACT:"); tag = 0; - for (i = 0; i < PPE_BM_USED_CNT_TBL_ENTRIES; i++) { - reg = PPE_BM_USED_CNT_TBL_ADDR + i * PPE_BM_USED_CNT_TBL_INC; + for (i = 0; i < PPE_BM_USED_CNT_TBL_ENTRIES(ppe_dev); i++) { + reg = PPE_BM_USED_CNT_TBL_ADDR(ppe_dev) + i * PPE_BM_USED_CNT_TBL_INC; ret = regmap_read(ppe_dev->regmap, reg, &val); if (ret) { dev_err(ppe_dev->dev, "CNT ERROR %d\n", ret); @@ -261,7 +261,7 @@ static int ppe_bm_counter_get(struct ppe_device *ppe_dev, struct seq_file *seq) */ pkt_cnt = FIELD_GET(PPE_BM_USED_CNT_VAL, val); - reg = PPE_BM_REACT_CNT_TBL_ADDR + i * PPE_BM_REACT_CNT_TBL_INC; + reg = PPE_BM_REACT_CNT_TBL_ADDR(ppe_dev) + i * PPE_BM_REACT_CNT_TBL_INC; ret = regmap_read(ppe_dev->regmap, reg, &val); if (ret) { dev_err(ppe_dev->dev, "CNT ERROR %d\n", ret); @@ -723,12 +723,12 @@ static ssize_t ppe_packet_counter_write(struct file *file, switch (entry->counter_type) { case PPE_CNT_BM: - for (i = 0; i < PPE_DROP_CNT_TBL_ENTRIES; i++) { + for (i = 0; i < PPE_DROP_CNT_TBL_ENTRIES(ppe_dev); i++) { reg = PPE_DROP_CNT_TBL_ADDR + i * PPE_DROP_CNT_TBL_INC; ppe_tbl_pkt_cnt_clear(ppe_dev, reg, PPE_PKT_CNT_SIZE_1WORD); } - for (i = 0; i < PPE_DROP_STAT_TBL_ENTRIES; i++) { + for (i = 0; i < PPE_DROP_STAT_TBL_ENTRIES(ppe_dev); i++) { reg = PPE_DROP_STAT_TBL_ADDR + PPE_DROP_STAT_TBL_INC * i; ppe_tbl_pkt_cnt_clear(ppe_dev, reg, PPE_PKT_CNT_SIZE_3WORD); } diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h b/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h index 089aa34b7732..d08ab02bdf79 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_regs.h @@ -18,12 +18,20 @@ /* PPE drop counters. */ #define PPE_DROP_CNT_TBL_ADDR 0xb024 -#define PPE_DROP_CNT_TBL_ENTRIES 8 +#define PPE_DROP_CNT_TBL_IPQ9574_ENTRIES 8 +#define PPE_DROP_CNT_TBL_IPQ5424_ENTRIES 4 +#define PPE_DROP_CNT_TBL_ENTRIES(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_DROP_CNT_TBL_IPQ5424_ENTRIES : \ + PPE_DROP_CNT_TBL_IPQ9574_ENTRIES) #define PPE_DROP_CNT_TBL_INC 4 /* BM port drop counters. */ #define PPE_DROP_STAT_TBL_ADDR 0xe000 -#define PPE_DROP_STAT_TBL_ENTRIES 30 +#define PPE_DROP_STAT_TBL_IPQ9574_ENTRIES 30 +#define PPE_DROP_STAT_TBL_IPQ5424_ENTRIES 38 +#define PPE_DROP_STAT_TBL_ENTRIES(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_DROP_STAT_TBL_IPQ5424_ENTRIES : \ + PPE_DROP_STAT_TBL_IPQ9574_ENTRIES) #define PPE_DROP_STAT_TBL_INC 0x10 /* Egress VLAN counters. */ @@ -426,14 +434,30 @@ #define PPE_BM_PORT_GROUP_ID_SHARED_GROUP_ID GENMASK(1, 0) /* Counters for PPE buffers used for packets cached. */ -#define PPE_BM_USED_CNT_TBL_ADDR 0x6001c0 -#define PPE_BM_USED_CNT_TBL_ENTRIES 15 +#define PPE_BM_USED_CNT_TBL_IPQ9574_ADDR 0x6001c0 +#define PPE_BM_USED_CNT_TBL_IPQ5424_ADDR 0x600220 +#define PPE_BM_USED_CNT_TBL_ADDR(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_USED_CNT_TBL_IPQ5424_ADDR : \ + PPE_BM_USED_CNT_TBL_IPQ9574_ADDR) +#define PPE_BM_USED_CNT_TBL_IPQ9574_ENTRIES 15 +#define PPE_BM_USED_CNT_TBL_IPQ5424_ENTRIES 19 +#define PPE_BM_USED_CNT_TBL_ENTRIES(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_USED_CNT_TBL_IPQ5424_ENTRIES : \ + PPE_BM_USED_CNT_TBL_IPQ9574_ENTRIES) #define PPE_BM_USED_CNT_TBL_INC 0x4 #define PPE_BM_USED_CNT_VAL GENMASK(10, 0) /* Counters for PPE buffers used for packets received after pause frame sent. */ -#define PPE_BM_REACT_CNT_TBL_ADDR 0x600240 -#define PPE_BM_REACT_CNT_TBL_ENTRIES 15 +#define PPE_BM_REACT_CNT_TBL_IPQ9574_ADDR 0x600240 +#define PPE_BM_REACT_CNT_TBL_IPQ5424_ADDR 0x600280 +#define PPE_BM_REACT_CNT_TBL_ADDR(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_REACT_CNT_TBL_IPQ5424_ADDR : \ + PPE_BM_REACT_CNT_TBL_IPQ9574_ADDR) +#define PPE_BM_REACT_CNT_TBL_IPQ9574_ENTRIES 15 +#define PPE_BM_REACT_CNT_TBL_IPQ5424_ENTRIES 19 +#define PPE_BM_REACT_CNT_TBL_ENTRIES(ppe_dev) \ + ((ppe_dev)->type == IPQ5424_PPE ? PPE_BM_REACT_CNT_TBL_IPQ5424_ENTRIES : \ + PPE_BM_REACT_CNT_TBL_IPQ9574_ENTRIES) #define PPE_BM_REACT_CNT_TBL_INC 0x4 #define PPE_BM_REACT_CNT_VAL GENMASK(8, 0) From c6b97e579ea3803c9343c01cafc9d0af821952e6 Mon Sep 17 00:00:00 2001 From: Prasenjit Mukherjee Date: Mon, 12 Oct 2026 18:23:32 +0530 Subject: [PATCH 1916/2126] selftests: net: fix race condition in icmp.sh causing CKI sporadic failures CKI reports sporadic failures in icmp.sh, Davide suggests this might be caused by a race condition where tcpdump starts capturing after the last of expected ICMP unreachable packets have been sent. Fix this replacing tcpdump with a tc flower filter that matches ICMP Destination Unreachable (type 3, code 0), and match on act_gact counters instead. This will remove any race condition to appear. Suggested-by: Davide Caratti Reviewed-by: Davide Caratti Signed-off-by: Prasenjit Mukherjee Reviewed-by: Hangbin Liu Reviewed-by: Antoine Tenart Link: https://patch.msgid.link/b15ee681a330f9b05a9076a3852c186017f59d83.1791804421.git.pmukherj@redhat.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/icmp.sh | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/net/icmp.sh b/tools/testing/selftests/net/icmp.sh index 824cb0e35eff..0714e8b34d12 100755 --- a/tools/testing/selftests/net/icmp.sh +++ b/tools/testing/selftests/net/icmp.sh @@ -27,11 +27,8 @@ PINGADDR=172.16.1.1 RT2=172.16.0.0/24 H2_IP6=2001:db8:1::2 -TMPFILE=$(mktemp) - cleanup() { - rm -f "$TMPFILE" cleanup_ns $NS1 $NS2 } @@ -52,21 +49,24 @@ ip -netns $NS2 route add $RT2 via inet6 $H1_IP6 # Make sure ns2 will respond with ICMP unreachable ip netns exec $NS2 sysctl -qw net.ipv4.icmp_ratelimit=0 net.ipv4.ip_forward=1 +# Install tc flower filter to count ICMP unreachable from 192.0.0.8 +ip netns exec $NS1 tc qdisc add dev veth0 clsact +ip netns exec $NS1 tc filter add dev veth0 ingress \ + protocol ip pref 1 handle 1 flower \ + src_ip 192.0.0.8 ip_proto icmp type 3 code 0 \ + action pass -# Run the test - a ping runs in the background, and we capture ICMP responses -# with tcpdump; -c 1 means it should exit on the first ping, but add a timeout -# in case something goes wrong -ip netns exec $NS1 ping -w 3 -i 0.5 $PINGADDR >/dev/null & -ip netns exec $NS1 timeout 10 tcpdump -tpni veth0 -c 1 'icmp and icmp[icmptype] != icmp-echo' > $TMPFILE 2>/dev/null +# Send ping to trigger ICMP unreachable from ns2 +ip netns exec $NS1 ping -c 1 $PINGADDR >/dev/null 2>&1 -# Parse response and check for dummy address -# tcpdump output looks like: -# IP 192.0.0.8 > 172.16.0.1: ICMP net 172.16.1.1 unreachable, length 92 -RESP_IP=$(awk '{print $2}' < $TMPFILE) -if [[ "$RESP_IP" != "192.0.0.8" ]]; then - echo "FAIL - got ICMP response from $RESP_IP, should be 192.0.0.8" - exit 1 -else +# Verify ICMP unreachable was received from dummy address 192.0.0.8 per RFC7600 +COUNT=$(ip netns exec $NS1 tc -j -s filter show dev veth0 ingress \ + | jq '.[1].options.actions[].stats.packets') + +if [[ "$COUNT" -eq 1 ]]; then echo "OK" exit 0 +else + echo "FAIL - expected 1 ICMP unreachable from 192.0.0.8, got $COUNT" + exit 1 fi From f67b3ed1308d7a282e2d6202d61af052ab0da39e Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Mon, 12 Oct 2026 14:09:25 -0400 Subject: [PATCH 1917/2126] net/sched: act_api: reject duplicate actions in a batch tca_action_gd() builds actions[] with one tcf_action_get_1() per nested TCA_ACT_TAB entry. Each successful lookup takes its own reference to the resolved action, so repeated TCA_ACT_INDEX entries in one request yield the same pointer in multiple slots. For RTM_DELACTION, tcf_action_delete() then consumes two references per slot: one in tcf_action_put() and one in tcf_idr_delete_index(). A duplicate therefore drives the refcount to zero mid-walk -- the delete frees the action and removes its IDR slot -- and the next slot calls tcf_action_put() on the freed action: refcount_t: underflow; use-after-free. WARNING: lib/refcount.c:87 at refcount_dec_not_one refcount_dec_and_mutex_lock __tcf_action_put tca_action_gd Three duplicate entries are enough. Reject a repeated action while a delete batch is built, dropping the reference the extra lookup took, and return -EINVAL. RTM_GETACTION balances its own references and keeps accepting duplicate entries. Conditions to recreate the bug: tc actions add action gact index 100 tc actions delete action gact index 100 action gact index 100 \ action gact index 100 Fixes: 16af6067392c ("net: sched: implement reference counted action release") Reported-by: Sashiko (gemini) Link: https://sashiko.dev/#/patchset/20260824153903.4143642-1-victor@mojatatu.com Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-K1TH.v1.r3.20261012134653-1@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/act_api.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 9eb1dec14cb1..42b5e40b52d0 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -2025,7 +2025,7 @@ static int tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, u32 portid, int event, struct netlink_ext_ack *extack) { - int i, ret; + int i, j, ret; struct nlattr *tb[TCA_ACT_MAX_PRIO + 1]; struct tc_action *act; size_t attr_size = 0; @@ -2050,6 +2050,25 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, ret = PTR_ERR(act); goto err; } + + /* A delete consumes two references per slot (tcf_action_put() + * and tcf_idr_delete_index()) but each entry takes one, so a + * repeated action would hit zero mid-walk. GET balances its + * own references and keeps accepting duplicates. + */ + if (event == RTM_DELACTION) { + for (j = 0; j < i - 1; j++) { + if (actions[j] != act) + continue; + + tcf_action_put(act); + NL_SET_ERR_MSG(extack, + "Duplicate TC action in a delete batch"); + ret = -EINVAL; + goto err; + } + } + attr_size += tcf_action_fill_size(act); actions[i - 1] = act; } From 044ad3c90d9d2df2c5cb3325ae17b4e9603a311f Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Mon, 12 Oct 2026 14:09:26 -0400 Subject: [PATCH 1918/2126] selftests: tc-testing: add duplicate action delete batch test tca_action_gd() takes one reference per nested TCA_ACT_TAB entry while tcf_action_delete() consumes two per slot, so three duplicate TCA_ACT_INDEX entries in one RTM_DELACTION free the action mid-walk and the next slot dereferences it. Assert a duplicate batch is rejected and the action survives. Conditions to recreate the bug: tc actions add action pass index 1 tc actions delete action gact index 1 action gact index 1 \ action gact index 1 Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-K1TH.v1.r3.20261012134653-2@mojatatu.com Signed-off-by: Jakub Kicinski --- .../tc-tests/actions/batch-delete.json | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/batch-delete.json b/tools/testing/selftests/tc-testing/tc-tests/actions/batch-delete.json index ef7ca4a6775b..7620e927ae2c 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/actions/batch-delete.json +++ b/tools/testing/selftests/tc-testing/tc-tests/actions/batch-delete.json @@ -111,5 +111,38 @@ 255 ] ] + }, + { + "id": "8135", + "name": "Reject duplicate action in a delete batch", + "category": [ + "actions", + "gact" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + [ + "$TC actions flush action gact", + 0, + 1, + 255 + ], + "$TC actions add action pass index 1" + ], + "cmdUnderTest": "$TC actions del action gact index 1 action gact index 1 action gact index 1", + "expExitCode": "255", + "verifyCmd": "$TC actions ls action gact", + "matchPattern": "total acts 1\\b.*index 1 ref 1 bind 0\\b", + "matchCount": "1", + "teardown": [ + [ + "$TC actions flush action gact", + 0, + 1, + 255 + ] + ] } ] From 600efa8e598c9670420ed698db4d64d05fc6023c Mon Sep 17 00:00:00 2001 From: Dong Yibo Date: Tue, 13 Oct 2026 10:30:25 +0800 Subject: [PATCH 1919/2126] net: rnpgbe: Add interrupt handling Add interrupt setup and teardown for the RNPGBE driver. Require at least two MSI-X vectors. Reserve vector 0 for the mailbox and assign the remaining vectors to the data path. Set up mailbox workqueue plumbing for asynchronous firmware events. Mailbox transactions run in process context, allowing mailbox lock acquisition to use sleepable polling. Notify firmware of driver powerdown from both remove and shutdown through a shared helper. Signed-off-by: Dong Yibo Link: https://patch.msgid.link/A4AA29A72BA34A26+20261013023025.63622-1-dong100@mucse.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mucse/Kconfig | 1 + drivers/net/ethernet/mucse/rnpgbe/Makefile | 3 +- drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 48 ++ .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 4 + drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 2 + .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.c | 576 ++++++++++++++++++ .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.h | 35 ++ .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 89 ++- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 12 +- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 11 + .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 1 + 11 files changed, 765 insertions(+), 17 deletions(-) create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h diff --git a/drivers/net/ethernet/mucse/Kconfig b/drivers/net/ethernet/mucse/Kconfig index 0b3e853d625f..17528dba2613 100644 --- a/drivers/net/ethernet/mucse/Kconfig +++ b/drivers/net/ethernet/mucse/Kconfig @@ -19,6 +19,7 @@ if NET_VENDOR_MUCSE config MGBE tristate "Mucse(R) 1GbE PCI Express adapters support" depends on PCI + depends on PCI_MSI help This driver supports Mucse(R) 1GbE PCI Express family of adapters. diff --git a/drivers/net/ethernet/mucse/rnpgbe/Makefile b/drivers/net/ethernet/mucse/rnpgbe/Makefile index de8bcb7772ab..17574cad392a 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/Makefile +++ b/drivers/net/ethernet/mucse/rnpgbe/Makefile @@ -8,4 +8,5 @@ obj-$(CONFIG_MGBE) += rnpgbe.o rnpgbe-objs := rnpgbe_main.o\ rnpgbe_chip.o\ rnpgbe_mbx.o\ - rnpgbe_mbx_fw.o + rnpgbe_mbx_fw.o\ + rnpgbe_lib.o diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h index 5b024f9f7e17..f2d2fe07f9e0 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h @@ -6,6 +6,11 @@ #include #include +#include +#include +#include + +#include "rnpgbe_hw.h" enum rnpgbe_boards { board_n500, @@ -35,21 +40,62 @@ enum { struct mucse_hw { void __iomem *hw_addr; + void __iomem *ring_msix_base; struct pci_dev *pdev; struct mucse_mbx_info mbx; int port; u8 pfvfnum; }; +struct mucse_ring { + struct mucse_ring *next; + struct mucse_q_vector *q_vector; + void __iomem *ring_addr; + void __iomem *irq_mask; + void __iomem *trig; + u8 queue_index; + /* hw ring idx */ + u8 rnpgbe_queue_idx; +} ____cacheline_internodealigned_in_smp; + +struct mucse_ring_container { + struct mucse_ring *ring; + u16 count; +}; + +struct mucse_q_vector { + struct mucse *mucse; + /* hardware interrupt vector number */ + int hw_vector; + struct mucse_ring_container rx, tx; + struct napi_struct napi; + char name[IFNAMSIZ + 18]; + /* for dynamic allocation of rings associated with this q_vector */ + struct mucse_ring ring[] ____cacheline_internodealigned_in_smp; +}; + struct mucse_stats { u64 tx_dropped; }; +#define MAX_Q_VECTORS 8 + struct mucse { struct net_device *netdev; struct pci_dev *pdev; struct mucse_hw hw; struct mucse_stats stats; + struct mucse_ring *tx_ring[RNPGBE_MAX_QUEUES] + ____cacheline_aligned_in_smp; + struct mucse_ring *rx_ring[RNPGBE_MAX_QUEUES] + ____cacheline_aligned_in_smp; + struct mucse_q_vector *q_vector[MAX_Q_VECTORS]; + int num_tx_queues; + int num_q_vectors; + int num_rx_queues; + char mbx_name[32]; + bool mbx_irq_requested; + struct work_struct mbx_work; }; int rnpgbe_get_permanent_mac(struct mucse_hw *hw, u8 *perm_addr); @@ -68,4 +114,6 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type); #define mucse_hw_wr32(hw, reg, val) \ writel((val), (hw)->hw_addr + (reg)) +#define mucse_hw_rd32(hw, reg) \ + readl((hw)->hw_addr + (reg)) #endif /* _RNPGBE_H */ diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c index ebc7b3750157..921cc325a991 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c @@ -89,6 +89,8 @@ static void rnpgbe_init_n500(struct mucse_hw *hw) { struct mucse_mbx_info *mbx = &hw->mbx; + hw->ring_msix_base = hw->hw_addr + MUCSE_N500_RING_MSIX_BASE; + mbx->fwpf_ctrl_base = MUCSE_N500_FWPF_CTRL_BASE; mbx->fwpf_shm_base = MUCSE_N500_FWPF_SHM_BASE; } @@ -104,6 +106,8 @@ static void rnpgbe_init_n210(struct mucse_hw *hw) { struct mucse_mbx_info *mbx = &hw->mbx; + hw->ring_msix_base = hw->hw_addr + MUCSE_N210_RING_MSIX_BASE; + mbx->fwpf_ctrl_base = MUCSE_N210_FWPF_CTRL_BASE; mbx->fwpf_shm_base = MUCSE_N210_FWPF_SHM_BASE; } diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h index e77e6bc3d3e3..0dce78e4a91b 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h @@ -6,10 +6,12 @@ #define MUCSE_N500_FWPF_CTRL_BASE 0x28b00 #define MUCSE_N500_FWPF_SHM_BASE 0x2d000 +#define MUCSE_N500_RING_MSIX_BASE 0x28700 #define MUCSE_GBE_PFFW_MBX_CTRL_OFFSET 0x5500 #define MUCSE_GBE_FWPF_MBX_MASK_OFFSET 0x5700 #define MUCSE_N210_FWPF_CTRL_BASE 0x29400 #define MUCSE_N210_FWPF_SHM_BASE 0x2d900 +#define MUCSE_N210_RING_MSIX_BASE 0x29000 #define RNPGBE_DMA_AXI_EN 0x0010 diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c new file mode 100644 index 000000000000..81c3ec63a9a0 --- /dev/null +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c @@ -0,0 +1,576 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2020 - 2025 Mucse Corporation. */ + +#include +#include + +#include "rnpgbe_lib.h" +#include "rnpgbe.h" +#include "rnpgbe_mbx_fw.h" + +static void rnpgbe_mbx_work(struct work_struct *work) +{ + struct mucse *mucse = container_of(work, struct mucse, mbx_work); + + mucse_fw_irq_handler(&mucse->hw); +} + +/** + * rnpgbe_msix_other - Other irq handler + * @irq: interrupt number + * @data: private data + * + * Return: IRQ_HANDLED + **/ +static irqreturn_t rnpgbe_msix_other(int irq, void *data) +{ + struct mucse *mucse = (struct mucse *)data; + + queue_work(system_percpu_wq, &mucse->mbx_work); + + return IRQ_HANDLED; +} + +static void rnpgbe_irq_disable_queues(struct mucse_q_vector *q_vector) +{ + struct mucse_ring *ring; + + /* + * TX/RX pairs share interrupt control registers; update them through + * the TX ring list. + */ + mucse_for_each_ring(ring, q_vector->tx) { + writel(INT_VALID, ring->trig); + writel((RX_INT_MASK | TX_INT_MASK), ring->irq_mask); + } + + /* flush posted writes to ensure hardware sees the mask */ + if (q_vector->tx.ring) + readl(q_vector->tx.ring->irq_mask); +} + +static void rnpgbe_irq_enable_queues(struct mucse_q_vector *q_vector) +{ + struct mucse_ring *ring; + + /* + * TX/RX pairs share interrupt control registers; update them through + * the TX ring list. + */ + mucse_for_each_ring(ring, q_vector->tx) { + writel(0, ring->irq_mask); + + /* Re-trigger hw to re-check events lost while masked. */ + writel(INT_VALID | TX_INT_MASK | RX_INT_MASK, ring->trig); + } +} + +/** + * rnpgbe_poll - NAPI polling callback + * @napi: structure for representing this polling device + * @budget: polling budget + * + * Complete NAPI polling and re-enable queue interrupts. Ring cleaning is + * added when TX and RX support is enabled. + * + * Return: 0 + **/ +static int rnpgbe_poll(struct napi_struct *napi, int budget) +{ + struct mucse_q_vector *q_vector = + container_of(napi, struct mucse_q_vector, napi); + int work_done = 0; + + /* Exit if we are called by netpoll */ + if (unlikely(!budget)) + return 0; + + if (likely(napi_complete_done(napi, work_done))) + rnpgbe_irq_enable_queues(q_vector); + + return work_done; +} + +/** + * rnpgbe_request_mbx_irq - Register mbx routine + * @mucse: pointer to private structure + * + * Register the dedicated mailbox handler on vector 0. + * + * Return: 0 on success, negative on failure + **/ +int rnpgbe_request_mbx_irq(struct mucse *mucse) +{ + struct pci_dev *pdev = mucse->pdev; + int err = 0; + + snprintf(mucse->mbx_name, sizeof(mucse->mbx_name), + "rnpgbe-mbx:%s", pci_name(pdev)); + INIT_WORK(&mucse->mbx_work, rnpgbe_mbx_work); + + err = request_irq(pci_irq_vector(pdev, 0), rnpgbe_msix_other, 0, + mucse->mbx_name, mucse); + if (!err) + mucse->mbx_irq_requested = true; + + return err; +} + +/** + * rnpgbe_free_mbx_irq - Remove mbx routine + * @mucse: pointer to private structure + **/ +void rnpgbe_free_mbx_irq(struct mucse *mucse) +{ + struct pci_dev *pdev = mucse->pdev; + + if (mucse->mbx_irq_requested) { + mucse->mbx_irq_requested = false; + free_irq(pci_irq_vector(pdev, 0), mucse); + cancel_work_sync(&mucse->mbx_work); + } +} + +/** + * rnpgbe_set_num_queues - Set initial TX/RX queue counts + * @mucse: pointer to private structure + * + * Start with one TX queue and one RX queue. + **/ +static void rnpgbe_set_num_queues(struct mucse *mucse) +{ + mucse->num_tx_queues = 1; + mucse->num_rx_queues = 1; +} + +/** + * rnpgbe_set_interrupt_capability - Set MSI-X interrupt capability + * @mucse: pointer to private structure + * + * Allocate one MSI-X vector for the mailbox and one or more vectors for + * the data path. + * + * Return: 0 on success, negative on failure + **/ +static int rnpgbe_set_interrupt_capability(struct mucse *mucse) +{ + int v_budget; + + v_budget = min3(mucse->num_tx_queues, mucse->num_rx_queues, + MAX_Q_VECTORS); + v_budget = min_t(int, v_budget, num_online_cpus()); + /* add one vector for mbx */ + v_budget += 1; + + /* Vector 0 is reserved for mailbox events and must not share NAPI. */ + v_budget = pci_alloc_irq_vectors(mucse->pdev, 2, v_budget, + PCI_IRQ_MSIX); + if (v_budget < 0) + return v_budget; + + /* q_vectors do not include the mailbox vector. */ + mucse->num_q_vectors = v_budget - 1; + + return 0; +} + +/** + * mucse_add_ring - Add ring to ring container + * @ring: ring to be added + * @head: ring container + **/ +static void mucse_add_ring(struct mucse_ring *ring, + struct mucse_ring_container *head) +{ + ring->next = head->ring; + head->ring = ring; + head->count++; +} + +/** + * rnpgbe_alloc_q_vector - Allocate memory for a single interrupt vector + * @mucse: pointer to private structure + * @eth_queue_idx: queue_index idx for this q_vector + * @vector_idx: q_vector array index + * @r_idx: starting hardware ring index + * @r_count: number of TX/RX ring pairs + * @step: ring step + * + * Return: 0 on success. If allocation fails we return -ENOMEM. + **/ +static int rnpgbe_alloc_q_vector(struct mucse *mucse, + int eth_queue_idx, int vector_idx, int r_idx, + int r_count, int step) +{ + int rxr_idx = r_idx, txr_idx = r_idx; + struct mucse_hw *hw = &mucse->hw; + struct mucse_q_vector *q_vector; + int txr_count, rxr_count, idx; + struct mucse_ring *ring; + int ring_count; + + /* + * TX and RX rings are always allocated as pairs with the same hardware + * ring index. Interrupt control is shared by the pair, so the TX ring + * list is used to update the common registers. + */ + txr_count = r_count; + rxr_count = r_count; + ring_count = txr_count + rxr_count; + + q_vector = kzalloc_flex(*q_vector, ring, ring_count); + if (!q_vector) + return -ENOMEM; + + netif_napi_add(mucse->netdev, &q_vector->napi, rnpgbe_poll); + /* tie q_vector and mucse together */ + mucse->q_vector[vector_idx] = q_vector; + q_vector->mucse = mucse; + q_vector->hw_vector = vector_idx; + /* Vector 0 is reserved for the mailbox. */ + q_vector->hw_vector++; + + ring = q_vector->ring; + + for (idx = 0; idx < txr_count; idx++) { + mucse_add_ring(ring, &q_vector->tx); + ring->queue_index = eth_queue_idx + idx; + ring->rnpgbe_queue_idx = txr_idx; + ring->ring_addr = hw->hw_addr + RING_OFFSET(txr_idx); + ring->irq_mask = ring->ring_addr + RNPGBE_DMA_INT_MASK; + ring->trig = ring->ring_addr + RNPGBE_DMA_INT_TRIG; + ring->q_vector = q_vector; + mucse->tx_ring[ring->queue_index] = ring; + txr_idx += step; + ring++; + } + + for (idx = 0; idx < rxr_count; idx++) { + mucse_add_ring(ring, &q_vector->rx); + ring->queue_index = eth_queue_idx + idx; + ring->rnpgbe_queue_idx = rxr_idx; + ring->ring_addr = hw->hw_addr + RING_OFFSET(rxr_idx); + ring->irq_mask = ring->ring_addr + RNPGBE_DMA_INT_MASK; + ring->trig = ring->ring_addr + RNPGBE_DMA_INT_TRIG; + ring->q_vector = q_vector; + mucse->rx_ring[ring->queue_index] = ring; + rxr_idx += step; + ring++; + } + + return 0; +} + +/** + * rnpgbe_free_q_vector - Free memory allocated for specific interrupt vector + * @mucse: pointer to private structure + * @vector_idx: q_vector array index + * + * This function frees the memory allocated to the q_vector. In addition if + * NAPI is enabled it will delete any references to the NAPI struct prior + * to freeing the q_vector. + **/ +static void rnpgbe_free_q_vector(struct mucse *mucse, int vector_idx) +{ + struct mucse_q_vector *q_vector = mucse->q_vector[vector_idx]; + struct mucse_ring *ring; + + mucse_for_each_ring(ring, q_vector->tx) + mucse->tx_ring[ring->queue_index] = NULL; + mucse_for_each_ring(ring, q_vector->rx) + mucse->rx_ring[ring->queue_index] = NULL; + mucse->q_vector[vector_idx] = NULL; + netif_napi_del(&q_vector->napi); + kfree(q_vector); +} + +/** + * rnpgbe_alloc_q_vectors - Allocate memory for interrupt vectors + * @mucse: pointer to private structure + * + * Return: 0 on success, or -ENOMEM on allocation failure. + **/ +static int rnpgbe_alloc_q_vectors(struct mucse *mucse) +{ + int err, ring_cnt, v_remaining = mucse->num_q_vectors; + int r_remaining = min_t(int, mucse->num_tx_queues, + mucse->num_rx_queues); + int num_q_vectors = 0; + int eth_queue_idx = 0; + int vector_idx = 0; + int ring_step = 1; + int ring_idx = 0; + + for (; r_remaining > 0 && v_remaining > 0; v_remaining--) { + ring_cnt = DIV_ROUND_UP(r_remaining, v_remaining); + err = rnpgbe_alloc_q_vector(mucse, eth_queue_idx, + vector_idx, ring_idx, ring_cnt, + ring_step); + if (err) + goto err_free_q_vector; + ring_idx += ring_step * ring_cnt; + eth_queue_idx += ring_cnt; + r_remaining -= ring_cnt; + num_q_vectors++; + vector_idx++; + } + /* Record the number of queue vectors actually allocated */ + mucse->num_q_vectors = num_q_vectors; + mucse->num_tx_queues = eth_queue_idx; + mucse->num_rx_queues = eth_queue_idx; + + return 0; + +err_free_q_vector: + mucse->num_tx_queues = 0; + mucse->num_rx_queues = 0; + mucse->num_q_vectors = 0; + + while (vector_idx--) + rnpgbe_free_q_vector(mucse, vector_idx); + + return err; +} + +/** + * rnpgbe_reset_interrupt_capability - Reset irq capability setup + * @mucse: pointer to private structure + **/ +static void rnpgbe_reset_interrupt_capability(struct mucse *mucse) +{ + if (!mucse->pdev->msix_enabled) + return; + + pci_free_irq_vectors(mucse->pdev); +} + +/** + * rnpgbe_init_interrupt_scheme - Initialize the interrupt scheme + * @mucse: pointer to private structure + * + * Set up one TX/RX queue pair with a dedicated mailbox vector. + * + * Return: 0 on success, negative on failure + **/ +int rnpgbe_init_interrupt_scheme(struct mucse *mucse) +{ + int err; + + rnpgbe_set_num_queues(mucse); + + err = rnpgbe_set_interrupt_capability(mucse); + if (err) + return err; + + err = rnpgbe_alloc_q_vectors(mucse); + if (err) { + rnpgbe_reset_interrupt_capability(mucse); + return err; + } + + return 0; +} + +/** + * rnpgbe_free_q_vectors - Free memory allocated for interrupt vectors + * @mucse: pointer to private structure + * + * This function frees the memory allocated to the q_vectors. In addition if + * NAPI is enabled it will delete any references to the NAPI struct prior + * to freeing the q_vector. + **/ +static void rnpgbe_free_q_vectors(struct mucse *mucse) +{ + int vector_idx = mucse->num_q_vectors; + + mucse->num_q_vectors = 0; + + while (vector_idx--) + rnpgbe_free_q_vector(mucse, vector_idx); +} + +/** + * rnpgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings + * @mucse: pointer to private structure + * + * Clear interrupt specific resources and reset the structure + **/ +void rnpgbe_clear_interrupt_scheme(struct mucse *mucse) +{ + rnpgbe_free_q_vectors(mucse); + rnpgbe_reset_interrupt_capability(mucse); +} + +/** + * rnpgbe_msix_clean_rings - MSI-x interrupt handler for ring irq + * @irq: interrupt number + * @data: private data + * + * rnpgbe_msix_clean_rings handle irq from ring, start napi + * Return: IRQ_HANDLED + **/ +static irqreturn_t rnpgbe_msix_clean_rings(int irq, void *data) +{ + struct mucse_q_vector *q_vector = (struct mucse_q_vector *)data; + + rnpgbe_irq_disable_queues(q_vector); + napi_schedule_irqoff(&q_vector->napi); + + return IRQ_HANDLED; +} + +/** + * rnpgbe_request_irq - Register data-path MSI-X handlers + * @mucse: pointer to private structure + * + * Register interrupt handlers for the data-path MSI-X vectors. + * + * Return: 0 on success, negative value on failure + **/ +int rnpgbe_request_irq(struct mucse *mucse) +{ + struct net_device *netdev = mucse->netdev; + struct pci_dev *pdev = mucse->pdev; + struct mucse_q_vector *q_vector; + int err, i; + + for (i = 0; i < mucse->num_q_vectors; i++) { + q_vector = mucse->q_vector[i]; + + snprintf(q_vector->name, sizeof(q_vector->name), + "%s-%s-%d", netdev->name, "TxRx", i); + + err = request_irq(pci_irq_vector(pdev, i + 1), + rnpgbe_msix_clean_rings, 0, + q_vector->name, q_vector); + if (err) { + dev_err(&pdev->dev, "MSI-X req err %d: %d\n", + i + 1, err); + goto err_free_irqs; + } + } + + return 0; +err_free_irqs: + while (i--) { + q_vector = mucse->q_vector[i]; + synchronize_irq(pci_irq_vector(pdev, i + 1)); + free_irq(pci_irq_vector(pdev, i + 1), q_vector); + } + + return err; +} + +/** + * rnpgbe_free_irq - Free data-path MSI-X handlers + * @mucse: pointer to private structure + **/ +void rnpgbe_free_irq(struct mucse *mucse) +{ + struct pci_dev *pdev = mucse->pdev; + struct mucse_q_vector *q_vector; + + for (int i = 0; i < mucse->num_q_vectors; i++) { + q_vector = mucse->q_vector[i]; + if (!q_vector) + continue; + + free_irq(pci_irq_vector(pdev, i + 1), q_vector); + } +} + +/** + * rnpgbe_set_ring_vector - Set the ring_vector registers, + * mapping interrupt causes to vectors + * @mucse: pointer to private structure + * @queue: queue to map the corresponding interrupt to + * @vector: the vector num to map to the corresponding queue + * + */ +static void rnpgbe_set_ring_vector(struct mucse *mucse, + u8 queue, u8 vector) +{ + struct mucse_hw *hw = &mucse->hw; + u32 data; + + data = hw->pfvfnum << 24; + data |= (vector << 8); + data |= vector; + writel(data, hw->ring_msix_base + RING_VECTOR(queue)); +} + +/** + * rnpgbe_configure_msix - Configure MSI-X hardware + * @mucse: pointer to private structure + * + * rnpgbe_configure_msix sets up the hardware to properly generate MSI-X + * interrupts. + **/ +static void rnpgbe_configure_msix(struct mucse *mucse) +{ + struct mucse_q_vector *q_vector; + + for (int i = 0; i < mucse->num_q_vectors; i++) { + struct mucse_ring *ring; + + q_vector = mucse->q_vector[i]; + /* TX/RX pairs share vector registers. + * Update them through TX. + */ + mucse_for_each_ring(ring, q_vector->tx) { + rnpgbe_set_ring_vector(mucse, ring->rnpgbe_queue_idx, + q_vector->hw_vector); + } + } +} + +static void rnpgbe_irq_enable(struct mucse *mucse) +{ + for (int i = 0; i < mucse->num_q_vectors; i++) + rnpgbe_irq_enable_queues(mucse->q_vector[i]); +} + +/** + * rnpgbe_irq_disable - Mask queue interrupt generation on the NIC + * @mucse: board private structure + **/ +static void rnpgbe_irq_disable(struct mucse *mucse) +{ + struct pci_dev *pdev = mucse->pdev; + + for (int i = 0; i < mucse->num_q_vectors; i++) { + rnpgbe_irq_disable_queues(mucse->q_vector[i]); + synchronize_irq(pci_irq_vector(pdev, i + 1)); + } +} + +static void rnpgbe_napi_enable_all(struct mucse *mucse) +{ + for (int i = 0; i < mucse->num_q_vectors; i++) + napi_enable(&mucse->q_vector[i]->napi); +} + +static void rnpgbe_napi_disable_all(struct mucse *mucse) +{ + for (int i = 0; i < mucse->num_q_vectors; i++) + napi_disable(&mucse->q_vector[i]->napi); +} + +void rnpgbe_down(struct mucse *mucse) +{ + rnpgbe_irq_disable(mucse); + rnpgbe_napi_disable_all(mucse); + synchronize_net(); + rnpgbe_irq_disable(mucse); +} + +/** + * rnpgbe_up_complete - Final step for port up + * @mucse: pointer to private structure + **/ +void rnpgbe_up_complete(struct mucse *mucse) +{ + rnpgbe_configure_msix(mucse); + rnpgbe_napi_enable_all(mucse); + rnpgbe_irq_enable(mucse); +} diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h new file mode 100644 index 000000000000..a1074890f5ad --- /dev/null +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2020 - 2025 Mucse Corporation. */ + +#ifndef _RNPGBE_LIB_H +#define _RNPGBE_LIB_H + +#include + +struct mucse; +struct mucse_hw; + +#define RING_OFFSET(n) (0x1000 + 0x100 * (n)) +#define RNPGBE_DMA_INT_MASK 0x24 +#define TX_INT_MASK BIT(1) +#define RX_INT_MASK BIT(0) +#define INT_VALID (BIT(16) | BIT(17)) +#define RNPGBE_DMA_INT_TRIG 0x2c /* lost-interrupt recovery trigger */ +/* | 31:24 | .... | 15:8 | 7:0 | */ +/* | pfvfnum | | tx vector | rx vector | */ +#define RING_VECTOR(n) (0x04 * (n)) + +#define mucse_for_each_ring(pos, head)\ + for (typeof((head).ring) __pos = (head).ring;\ + __pos ? ({ pos = __pos; 1; }) : 0;\ + __pos = __pos->next) + +int rnpgbe_init_interrupt_scheme(struct mucse *mucse); +void rnpgbe_clear_interrupt_scheme(struct mucse *mucse); +int rnpgbe_request_mbx_irq(struct mucse *mucse); +void rnpgbe_free_mbx_irq(struct mucse *mucse); +int rnpgbe_request_irq(struct mucse *mucse); +void rnpgbe_free_irq(struct mucse *mucse); +void rnpgbe_down(struct mucse *mucse); +void rnpgbe_up_complete(struct mucse *mucse); +#endif diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c index 70a2b0082ba8..6022a1a2ddf1 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c @@ -7,6 +7,7 @@ #include "rnpgbe.h" #include "rnpgbe_hw.h" +#include "rnpgbe_lib.h" #include "rnpgbe_mbx_fw.h" static const char rnpgbe_driver_name[] = "rnpgbe"; @@ -32,11 +33,28 @@ static struct pci_device_id rnpgbe_pci_tbl[] = { * The open entry point is called when a network interface is made * active by the system (IFF_UP). * - * Return: 0 + * Return: 0 on success, negative value on failure **/ static int rnpgbe_open(struct net_device *netdev) { + struct mucse *mucse = netdev_priv(netdev); + int err; + + err = rnpgbe_request_irq(mucse); + if (err) + return err; + + err = netif_set_real_num_queues(netdev, mucse->num_tx_queues, + mucse->num_rx_queues); + if (err) + goto err_free_irqs; + + rnpgbe_up_complete(mucse); + return 0; +err_free_irqs: + rnpgbe_free_irq(mucse); + return err; } /** @@ -50,6 +68,11 @@ static int rnpgbe_open(struct net_device *netdev) **/ static int rnpgbe_close(struct net_device *netdev) { + struct mucse *mucse = netdev_priv(netdev); + + rnpgbe_down(mucse); + rnpgbe_free_irq(mucse); + return 0; } @@ -166,11 +189,33 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev, goto err_powerdown; } + err = rnpgbe_init_interrupt_scheme(mucse); + if (err) { + dev_err(&pdev->dev, "init interrupt failed %d\n", err); + goto err_powerdown; + } + + err = netif_set_real_num_queues(netdev, mucse->num_tx_queues, + mucse->num_rx_queues); + if (err) + goto err_clear_interrupt; + + err = rnpgbe_request_mbx_irq(mucse); + if (err) { + dev_err(&pdev->dev, "register mbx irq failed %d\n", err); + goto err_clear_interrupt; + } + err = register_netdev(netdev); if (err) - goto err_powerdown; + goto err_remove_mbx; return 0; + +err_remove_mbx: + rnpgbe_free_mbx_irq(mucse); +err_clear_interrupt: + rnpgbe_clear_interrupt_scheme(mucse); err_powerdown: /* notify powerdown only powerup ok */ if (!err_notify) { @@ -236,6 +281,26 @@ err_disable_dev: return err; } +/** + * rnpgbe_notify_powerdown - Notify firmware that the driver is going down + * @mucse: pointer to private structure + * + * Skip the mailbox access if an earlier shutdown has already disabled the + * PCI device. + **/ +static void rnpgbe_notify_powerdown(struct mucse *mucse) +{ + int err; + + if (!pci_is_enabled(mucse->pdev)) + return; + + err = rnpgbe_send_notify(&mucse->hw, false, mucse_fw_powerup); + if (err) + dev_warn(&mucse->pdev->dev, + "Send powerdown to hw failed %d\n", err); +} + /** * rnpgbe_rm_adapter - Remove netdev for this mucse structure * @pdev: PCI device information struct @@ -245,17 +310,15 @@ err_disable_dev: static void rnpgbe_rm_adapter(struct pci_dev *pdev) { struct mucse *mucse = pci_get_drvdata(pdev); - struct mucse_hw *hw = &mucse->hw; struct net_device *netdev; - int err; if (!mucse) return; netdev = mucse->netdev; unregister_netdev(netdev); - err = rnpgbe_send_notify(hw, false, mucse_fw_powerup); - if (err) - dev_warn(&pdev->dev, "Send powerdown to hw failed %d\n", err); + rnpgbe_free_mbx_irq(mucse); + rnpgbe_notify_powerdown(mucse); + rnpgbe_clear_interrupt_scheme(mucse); free_netdev(netdev); } @@ -272,7 +335,8 @@ static void rnpgbe_remove(struct pci_dev *pdev) { rnpgbe_rm_adapter(pdev); pci_release_mem_regions(pdev); - pci_disable_device(pdev); + if (pci_is_enabled(pdev)) + pci_disable_device(pdev); } /** @@ -287,9 +351,14 @@ static void rnpgbe_dev_shutdown(struct pci_dev *pdev) rtnl_lock(); netif_device_detach(netdev); if (netif_running(netdev)) - rnpgbe_close(netdev); + dev_close(netdev); rtnl_unlock(); - pci_disable_device(pdev); + + rnpgbe_free_mbx_irq(mucse); + rnpgbe_notify_powerdown(mucse); + rnpgbe_clear_interrupt_scheme(mucse); + if (pci_is_enabled(pdev)) + pci_disable_device(pdev); } /** diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c index c46408698263..2310f01df1f5 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c @@ -84,7 +84,7 @@ static u32 mucse_mbx_get_lock_pf(struct mucse_hw *hw) * @hw: pointer to the HW structure * * Pair with mucse_release_mbx_lock_pf() - * This function maybe used in an irq handler. + * All mailbox access runs in process context. * * Return: 0 on success, negative errno on failure **/ @@ -93,11 +93,11 @@ static int mucse_obtain_mbx_lock_pf(struct mucse_hw *hw) struct mucse_mbx_info *mbx = &hw->mbx; u32 val; - return read_poll_timeout_atomic(mucse_mbx_get_lock_pf, - val, val & MUCSE_MBX_PFU, - mbx->delay_us, - mbx->timeout_us, - false, hw); + return read_poll_timeout(mucse_mbx_get_lock_pf, + val, val & MUCSE_MBX_PFU, + mbx->delay_us, + mbx->timeout_us, + false, hw); } /** diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c index 5ba74997beac..e28f3193aa85 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c @@ -197,3 +197,14 @@ int mucse_mbx_get_macaddr(struct mucse_hw *hw, int pfvfnum, return 0; } + +/** + * mucse_fw_irq_handler - Deferred firmware mailbox notification hook + * @hw: pointer to the HW structure + * + * No asynchronous firmware events are enabled until link status support is + * added. + **/ +void mucse_fw_irq_handler(struct mucse_hw *hw) +{ +} diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h index fe996aeffc4d..a6bf5de55aa3 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h @@ -99,4 +99,5 @@ int mucse_mbx_powerup(struct mucse_hw *hw, bool is_powerup); int mucse_mbx_reset_hw(struct mucse_hw *hw); int mucse_mbx_get_macaddr(struct mucse_hw *hw, int pfvfnum, u8 *mac_addr, int port); +void mucse_fw_irq_handler(struct mucse_hw *hw); #endif /* _RNPGBE_MBX_FW_H */ From 02b5891a50c15b5f5c9c162607226ff7eefa970f Mon Sep 17 00:00:00 2001 From: Dong Yibo Date: Tue, 13 Oct 2026 10:30:36 +0800 Subject: [PATCH 1920/2126] net: rnpgbe: Add basic TX packet transmission support Add the basic TX path for the RNPGBE driver. Introduce the TX descriptor structure and buffer management, the rnpgbe_xmit_frame_ring() transmit function, TX ring allocation and teardown, and TX completion handling in rnpgbe_clean_tx_irq(). Track TX packet and byte statistics, and report dropped and tx_dropped counts through ndo_get_stats64(). Keep carrier state off during registration. The link-status patch later in this series enables carrier after firmware reports a valid link. Configure streaming and coherent DMA masks for the hardware's 56-bit DMA addressing capability. Add cycles_per_us to struct mucse_hw to scale the TX interrupt timer, and enable NETIF_F_HIGHDMA when the DMA mask allows it. A TX DMA idle timeout is terminal for the current driver instance. The hardware stops PCIe DMA requests, allowing cleanup to release DMA resources. Recovery requires a chip-level reset and driver rebind. Signed-off-by: Dong Yibo Link: https://patch.msgid.link/70FB65125730E856+20261013023036.63653-1-dong100@mucse.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 85 ++- .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 4 + drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 9 + .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.c | 695 +++++++++++++++++- .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.h | 31 + .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 71 +- 6 files changed, 876 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h index f2d2fe07f9e0..5456919ef80b 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h @@ -44,20 +44,85 @@ struct mucse_hw { struct pci_dev *pdev; struct mucse_mbx_info mbx; int port; + u16 cycles_per_us; u8 pfvfnum; }; +struct rnpgbe_tx_desc { + __le64 pkt_addr; /* Packet buffer address */ + union { + __le64 vlan_cmd_bsz; + struct { + __le32 blen_mac_ip_len; + __le32 vlan_cmd; /* vlan & cmd status */ + }; + }; +#define M_TXD_CMD_RS 0x040000 /* Report Status */ +#define M_TXD_STAT_DD 0x020000 /* Descriptor Done */ +#define M_TXD_CMD_EOP 0x010000 /* End of Packet */ +}; + +#define M_TX_DESC(R, i) (&(((struct rnpgbe_tx_desc *)((R)->desc))[i])) + +struct mucse_tx_buffer { + struct rnpgbe_tx_desc *next_to_watch; + struct sk_buff *skb; + unsigned int bytecount; + unsigned short gso_segs; + DEFINE_DMA_UNMAP_ADDR(dma); + DEFINE_DMA_UNMAP_LEN(len); + bool mapped_as_page; /* true if dma was mapped with dma_map_page */ +}; + +struct mucse_queue_stats { + u64 packets; + u64 bytes; + atomic64_t dropped; + struct u64_stats_sync syncp; +} ____cacheline_aligned_in_smp; + struct mucse_ring { struct mucse_ring *next; struct mucse_q_vector *q_vector; + struct net_device *netdev; + struct device *dev; + void *desc; + struct mucse_tx_buffer *tx_buffer_info; void __iomem *ring_addr; + void __iomem *tail; void __iomem *irq_mask; void __iomem *trig; u8 queue_index; /* hw ring idx */ u8 rnpgbe_queue_idx; + u8 pfvfnum; + u16 count; + u16 next_to_use; + u16 next_to_clean; + dma_addr_t dma; + unsigned int size; + struct mucse_queue_stats *stats; } ____cacheline_internodealigned_in_smp; +static inline u16 mucse_desc_unused(struct mucse_ring *ring) +{ + u16 ntc = ring->next_to_clean; + u16 ntu = ring->next_to_use; + + return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; +} + +static inline __le64 build_ctob(u32 vlan_cmd, u32 mac_ip_len, u32 size) +{ + return cpu_to_le64(((u64)vlan_cmd << 32) | ((u64)mac_ip_len << 16) | + ((u64)size)); +} + +static inline struct netdev_queue *txring_txq(const struct mucse_ring *ring) +{ + return netdev_get_tx_queue(ring->netdev, ring->queue_index); +} + struct mucse_ring_container { struct mucse_ring *ring; u16 count; @@ -74,27 +139,33 @@ struct mucse_q_vector { struct mucse_ring ring[] ____cacheline_internodealigned_in_smp; }; -struct mucse_stats { - u64 tx_dropped; -}; - #define MAX_Q_VECTORS 8 +#define M_DEFAULT_TXD 512 +#define M_DEFAULT_TX_WORK 256 + +enum mucse_state_t { + __MUCSE_AXI_FAULT, +}; + struct mucse { struct net_device *netdev; struct pci_dev *pdev; struct mucse_hw hw; - struct mucse_stats stats; struct mucse_ring *tx_ring[RNPGBE_MAX_QUEUES] ____cacheline_aligned_in_smp; struct mucse_ring *rx_ring[RNPGBE_MAX_QUEUES] ____cacheline_aligned_in_smp; + struct mucse_queue_stats tx_stats[RNPGBE_MAX_QUEUES]; struct mucse_q_vector *q_vector[MAX_Q_VECTORS]; + int tx_ring_item_count; + int tx_work_limit; int num_tx_queues; int num_q_vectors; int num_rx_queues; char mbx_name[32]; bool mbx_irq_requested; + unsigned long state; struct work_struct mbx_work; }; @@ -116,4 +187,8 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type); writel((val), (hw)->hw_addr + (reg)) #define mucse_hw_rd32(hw, reg) \ readl((hw)->hw_addr + (reg)) +#define mucse_ring_wr32(ring, reg, val) \ + writel((val), (ring)->ring_addr + (reg)) +#define mucse_ring_rd32(ring, reg) \ + readl((ring)->ring_addr + (reg)) #endif /* _RNPGBE_H */ diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c index 921cc325a991..291e77d573fe 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c @@ -93,6 +93,8 @@ static void rnpgbe_init_n500(struct mucse_hw *hw) mbx->fwpf_ctrl_base = MUCSE_N500_FWPF_CTRL_BASE; mbx->fwpf_shm_base = MUCSE_N500_FWPF_SHM_BASE; + + hw->cycles_per_us = M_DEFAULT_N500_MHZ; } /** @@ -110,6 +112,8 @@ static void rnpgbe_init_n210(struct mucse_hw *hw) mbx->fwpf_ctrl_base = MUCSE_N210_FWPF_CTRL_BASE; mbx->fwpf_shm_base = MUCSE_N210_FWPF_SHM_BASE; + + hw->cycles_per_us = M_DEFAULT_N210_MHZ; } /** diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h index 0dce78e4a91b..f9ca13b29f69 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h @@ -4,16 +4,25 @@ #ifndef _RNPGBE_HW_H #define _RNPGBE_HW_H +#include + #define MUCSE_N500_FWPF_CTRL_BASE 0x28b00 #define MUCSE_N500_FWPF_SHM_BASE 0x2d000 #define MUCSE_N500_RING_MSIX_BASE 0x28700 +#define M_DEFAULT_N500_MHZ 125 #define MUCSE_GBE_PFFW_MBX_CTRL_OFFSET 0x5500 #define MUCSE_GBE_FWPF_MBX_MASK_OFFSET 0x5700 #define MUCSE_N210_FWPF_CTRL_BASE 0x29400 #define MUCSE_N210_FWPF_SHM_BASE 0x2d900 #define MUCSE_N210_RING_MSIX_BASE 0x29000 +#define M_DEFAULT_N210_MHZ 62 +#define RNPGBE_DMA_STATUS 0x0008 +#define TX_AXI_RW_EN 0xc +/* DMA_STATUS_REG[23:20]: tx_wr, tx_rd, rx_wr, rx_rd done status. */ +#define RNPGBE_DMA_TX_STATUS GENMASK_U32(23, 22) #define RNPGBE_DMA_AXI_EN 0x0010 +#define RNPGBE_TX_MIN_PKT_LEN 33 #define RNPGBE_MAX_QUEUES 8 #endif /* _RNPGBE_HW_H */ diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c index 81c3ec63a9a0..21cd578f7532 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include "rnpgbe_lib.h" #include "rnpgbe.h" @@ -43,7 +46,6 @@ static void rnpgbe_irq_disable_queues(struct mucse_q_vector *q_vector) writel(INT_VALID, ring->trig); writel((RX_INT_MASK | TX_INT_MASK), ring->irq_mask); } - /* flush posted writes to ensure hardware sees the mask */ if (q_vector->tx.ring) readl(q_vector->tx.ring->irq_mask); @@ -65,26 +67,143 @@ static void rnpgbe_irq_enable_queues(struct mucse_q_vector *q_vector) } } +/** + * rnpgbe_clean_tx_irq - Reclaim resources after transmit completes + * @q_vector: structure containing interrupt and ring information + * @tx_ring: tx ring to clean + * @napi_budget: Used to determine if we are in netpoll + * + * Return: true if cleaning completed within the budget, otherwise false + **/ +static bool rnpgbe_clean_tx_irq(struct mucse_q_vector *q_vector, + struct mucse_ring *tx_ring, + int napi_budget) +{ + int budget = q_vector->mucse->tx_work_limit; + u64 total_bytes = 0, total_packets = 0; + struct mucse *mucse = q_vector->mucse; + struct mucse_tx_buffer *tx_buffer; + struct rnpgbe_tx_desc *tx_desc; + int i = tx_ring->next_to_clean; + + tx_buffer = &tx_ring->tx_buffer_info[i]; + tx_desc = M_TX_DESC(tx_ring, i); + i -= tx_ring->count; + + do { + struct rnpgbe_tx_desc *eop_desc = tx_buffer->next_to_watch; + + /* if next_to_watch is not set then there is no work pending */ + if (!eop_desc) + break; + + /* prevent any other reads prior to eop_desc */ + dma_rmb(); + + /* if eop DD is not set pending work has not been completed */ + if (!(eop_desc->vlan_cmd & cpu_to_le32(M_TXD_STAT_DD))) + break; + /* clear next_to_watch to prevent false hangs */ + tx_buffer->next_to_watch = NULL; + total_bytes += tx_buffer->bytecount; + total_packets += tx_buffer->gso_segs; + napi_consume_skb(tx_buffer->skb, napi_budget); + if (tx_buffer->mapped_as_page) { + dma_unmap_page(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } else { + dma_unmap_single(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } + tx_buffer->skb = NULL; + dma_unmap_len_set(tx_buffer, len, 0); + + /* unmap remaining buffers */ + while (tx_desc != eop_desc) { + tx_buffer++; + tx_desc++; + i++; + if (unlikely(!i)) { + i -= tx_ring->count; + tx_buffer = tx_ring->tx_buffer_info; + tx_desc = M_TX_DESC(tx_ring, 0); + } + + /* unmap any remaining paged data */ + if (dma_unmap_len(tx_buffer, len)) { + dma_unmap_page(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + dma_unmap_len_set(tx_buffer, len, 0); + } + } + + /* move us one more past the eop_desc for start of next pkt */ + tx_buffer++; + tx_desc++; + i++; + if (unlikely(!i)) { + i -= tx_ring->count; + tx_buffer = tx_ring->tx_buffer_info; + tx_desc = M_TX_DESC(tx_ring, 0); + } + + prefetch(tx_desc); + budget--; + } while (likely(budget > 0)); + + i += tx_ring->count; + tx_ring->next_to_clean = i; + u64_stats_update_begin(&tx_ring->stats->syncp); + tx_ring->stats->bytes += total_bytes; + tx_ring->stats->packets += total_packets; + u64_stats_update_end(&tx_ring->stats->syncp); + +#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) + __netif_txq_completed_wake(txring_txq(tx_ring), + total_packets, total_bytes, + mucse_desc_unused(tx_ring), + TX_WAKE_THRESHOLD, + !netif_running(mucse->netdev)); + + return !!budget; +} + /** * rnpgbe_poll - NAPI polling callback * @napi: structure for representing this polling device * @budget: polling budget * - * Complete NAPI polling and re-enable queue interrupts. Ring cleaning is - * added when TX and RX support is enabled. + * Clean completed TX packets and complete NAPI polling when all queues are + * clean. * - * Return: 0 + * Return: 0 if all TX queues are clean, otherwise @budget **/ static int rnpgbe_poll(struct napi_struct *napi, int budget) { struct mucse_q_vector *q_vector = container_of(napi, struct mucse_q_vector, napi); + bool clean_complete = true; + struct mucse_ring *ring; int work_done = 0; + mucse_for_each_ring(ring, q_vector->tx) { + if (!rnpgbe_clean_tx_irq(q_vector, ring, budget)) + clean_complete = false; + } + /* Exit if we are called by netpoll */ if (unlikely(!budget)) return 0; + if (!clean_complete) + return budget; + if (likely(napi_complete_done(napi, work_done))) rnpgbe_irq_enable_queues(q_vector); @@ -233,13 +352,18 @@ static int rnpgbe_alloc_q_vector(struct mucse *mucse, ring = q_vector->ring; for (idx = 0; idx < txr_count; idx++) { + ring->dev = &mucse->pdev->dev; mucse_add_ring(ring, &q_vector->tx); + ring->count = mucse->tx_ring_item_count; + ring->netdev = mucse->netdev; ring->queue_index = eth_queue_idx + idx; ring->rnpgbe_queue_idx = txr_idx; ring->ring_addr = hw->hw_addr + RING_OFFSET(txr_idx); ring->irq_mask = ring->ring_addr + RNPGBE_DMA_INT_MASK; ring->trig = ring->ring_addr + RNPGBE_DMA_INT_TRIG; ring->q_vector = q_vector; + ring->pfvfnum = hw->pfvfnum; + ring->stats = &mucse->tx_stats[ring->queue_index]; mucse->tx_ring[ring->queue_index] = ring; txr_idx += step; ring++; @@ -556,12 +680,173 @@ static void rnpgbe_napi_disable_all(struct mucse *mucse) napi_disable(&mucse->q_vector[i]->napi); } +static void rnpgbe_stop_tx_ring(struct mucse_ring *tx_ring) +{ + if (!tx_ring->tx_buffer_info) + return; + + /* Stop hw. No new descriptors are fetched after TX_START=0. + * DMA for descriptors fetched before the stop may still be in flight. + */ + mucse_ring_wr32(tx_ring, RNPGBE_TX_START, 0); + /* Flush posted write to ensure hardware sees TX_START=0 */ + (void)mucse_ring_rd32(tx_ring, RNPGBE_TX_START); +} + +static int rnpgbe_wait_tx_dma_idle(struct mucse *mucse) +{ + struct mucse_hw *hw = &mucse->hw; + u32 dma_status; + int err; + + /* A timeout indicates a terminal AXI fault. Hardware stops all PCIe + * DMA requests in this state, including requests accepted before the + * fault. Teardown may therefore release mappings and descriptor memory. + * Recovery requires a chip-level reset. + */ + err = readl_poll_timeout(hw->hw_addr + RNPGBE_DMA_STATUS, + dma_status, + (dma_status & RNPGBE_DMA_TX_STATUS) == + RNPGBE_DMA_TX_STATUS, + 10, 100000); + if (err) { + set_bit(__MUCSE_AXI_FAULT, &mucse->state); + dev_err(&mucse->pdev->dev, + "TX DMA failed to quiesce, status %#x\n", dma_status); + } + + return err; +} + +/** + * rnpgbe_stop_all_tx_rings - Stop TX DMA on all queues + * @mucse: board private structure + * + * Return: 0 when TX DMA was quiesced, negative errno otherwise + **/ +static int rnpgbe_stop_all_tx_rings(struct mucse *mucse) +{ + struct mucse_hw *hw = &mucse->hw; + u32 dma_axi_ctl; + int err = 0; + + for (int i = 0; i < mucse->num_tx_queues; i++) + rnpgbe_stop_tx_ring(mucse->tx_ring[i]); + + if (mucse->num_tx_queues && + !test_bit(__MUCSE_AXI_FAULT, &mucse->state)) + err = rnpgbe_wait_tx_dma_idle(mucse); + + dma_axi_ctl = mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + dma_axi_ctl &= ~TX_AXI_RW_EN; + mucse_hw_wr32(hw, RNPGBE_DMA_AXI_EN, dma_axi_ctl); + /* Flush the posted write before continuing. */ + (void)mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + + if (!test_bit(__MUCSE_AXI_FAULT, &mucse->state)) + return 0; + + return err ? err : -EIO; +} + +/** + * rnpgbe_clean_tx_ring - Free Tx Buffers + * @tx_ring: ring to be cleaned + **/ +static void rnpgbe_clean_tx_ring(struct mucse_ring *tx_ring) +{ + struct mucse_tx_buffer *tx_buffer; + u16 i = tx_ring->next_to_clean; + unsigned long size; + + /* ring already cleared, nothing to do */ + if (!tx_ring->tx_buffer_info) + return; + + tx_buffer = &tx_ring->tx_buffer_info[i]; + + while (i != tx_ring->next_to_use) { + struct rnpgbe_tx_desc *eop_desc, *tx_desc; + + dev_kfree_skb_any(tx_buffer->skb); + /* unmap skb header data */ + if (dma_unmap_len(tx_buffer, len)) { + if (tx_buffer->mapped_as_page) { + dma_unmap_page(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } else { + dma_unmap_single(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } + } + eop_desc = tx_buffer->next_to_watch; + tx_desc = M_TX_DESC(tx_ring, i); + /* unmap remaining buffers */ + while (tx_desc != eop_desc) { + tx_buffer++; + tx_desc++; + i++; + if (unlikely(i == tx_ring->count)) { + i = 0; + tx_buffer = tx_ring->tx_buffer_info; + tx_desc = M_TX_DESC(tx_ring, 0); + } + + /* unmap any remaining paged data */ + if (dma_unmap_len(tx_buffer, len)) + dma_unmap_page(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } + /* move us one more past the eop_desc for start of next pkt */ + tx_buffer++; + i++; + if (unlikely(i == tx_ring->count)) { + i = 0; + tx_buffer = tx_ring->tx_buffer_info; + } + } + + netdev_tx_reset_queue(txring_txq(tx_ring)); + size = sizeof(struct mucse_tx_buffer) * tx_ring->count; + memset(tx_ring->tx_buffer_info, 0, size); + /* Zero out the descriptor ring */ + memset(tx_ring->desc, 0, tx_ring->size); + tx_ring->next_to_use = 0; + tx_ring->next_to_clean = 0; +} + +/** + * rnpgbe_clean_all_tx_rings - Stop TX DMA and free Tx buffers for all queues + * @mucse: board private structure + **/ +void rnpgbe_clean_all_tx_rings(struct mucse *mucse) +{ + /* rnpgbe_stop_all_tx_rings() logs and latches any AXI fault. Hardware + * stops DMA requests in this state, so cleanup intentionally ignores + * an error and releases the mappings and descriptor memory. + */ + rnpgbe_stop_all_tx_rings(mucse); + + for (int i = 0; i < mucse->num_tx_queues; i++) + rnpgbe_clean_tx_ring(mucse->tx_ring[i]); +} + void rnpgbe_down(struct mucse *mucse) { + struct net_device *netdev = mucse->netdev; + rnpgbe_irq_disable(mucse); rnpgbe_napi_disable_all(mucse); synchronize_net(); rnpgbe_irq_disable(mucse); + netif_tx_disable(netdev); + rnpgbe_clean_all_tx_rings(mucse); } /** @@ -570,7 +855,409 @@ void rnpgbe_down(struct mucse *mucse) **/ void rnpgbe_up_complete(struct mucse *mucse) { + struct net_device *netdev = mucse->netdev; + rnpgbe_configure_msix(mucse); rnpgbe_napi_enable_all(mucse); rnpgbe_irq_enable(mucse); + netif_tx_start_all_queues(netdev); +} + +/** + * rnpgbe_free_tx_resources - Free Tx Resources per Queue + * @tx_ring: tx descriptor ring for a specific queue + * + * Free all transmit software resources + **/ +static void rnpgbe_free_tx_resources(struct mucse_ring *tx_ring) +{ + vfree(tx_ring->tx_buffer_info); + tx_ring->tx_buffer_info = NULL; + /* if not set, then don't free */ + if (!tx_ring->desc) + return; + + dma_free_coherent(tx_ring->dev, tx_ring->size, tx_ring->desc, + tx_ring->dma); + tx_ring->desc = NULL; +} + +/** + * rnpgbe_setup_tx_resources - allocate Tx resources (Descriptors) + * @tx_ring: tx descriptor ring (for a specific queue) to setup + * + * Return: 0 on success, negative on failure + **/ +static int rnpgbe_setup_tx_resources(struct mucse_ring *tx_ring) +{ + struct device *dev = tx_ring->dev; + int size; + + size = sizeof(struct mucse_tx_buffer) * tx_ring->count; + + tx_ring->tx_buffer_info = vzalloc(size); + if (!tx_ring->tx_buffer_info) + goto err_return; + /* round up to nearest 4K */ + tx_ring->size = tx_ring->count * sizeof(struct rnpgbe_tx_desc); + tx_ring->size = ALIGN(tx_ring->size, 4096); + tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, &tx_ring->dma, + GFP_KERNEL); + if (!tx_ring->desc) + goto err_free_buffer; + + tx_ring->next_to_use = 0; + tx_ring->next_to_clean = 0; + + return 0; + +err_free_buffer: + vfree(tx_ring->tx_buffer_info); +err_return: + tx_ring->tx_buffer_info = NULL; + return -ENOMEM; +} + +/** + * rnpgbe_configure_tx_ring - Configure Tx ring after Reset + * @mucse: pointer to private structure + * @ring: structure containing ring specific data + * + * Configure the Tx descriptor ring after a reset. + **/ +static void rnpgbe_configure_tx_ring(struct mucse *mucse, + struct mucse_ring *ring) +{ + struct mucse_hw *hw = &mucse->hw; + + mucse_ring_wr32(ring, RNPGBE_TX_BASE_ADDR_LO, (u32)ring->dma); + mucse_ring_wr32(ring, RNPGBE_TX_BASE_ADDR_HI, + (u32)(((u64)ring->dma) >> 32) | + ((u32)hw->pfvfnum << 24)); + mucse_ring_wr32(ring, RNPGBE_TX_LEN, ring->count); + ring->next_to_clean = mucse_ring_rd32(ring, RNPGBE_TX_HEAD) % + ring->count; + ring->next_to_use = ring->next_to_clean; + ring->tail = ring->ring_addr + RNPGBE_TX_TAIL; + writel(ring->next_to_use, ring->tail); + mucse_ring_wr32(ring, RNPGBE_TX_FETCH_CTRL, M_DEFAULT_TX_FETCH); + mucse_ring_wr32(ring, RNPGBE_TX_INT_TIMER, + M_DEFAULT_INT_TIMER * hw->cycles_per_us); + mucse_ring_wr32(ring, RNPGBE_TX_INT_PKTCNT, M_DEFAULT_INT_PKTCNT); +} + +/** + * rnpgbe_configure_tx - Configure Transmit Unit after Reset + * @mucse: pointer to private structure + * + * Configure the Tx DMA after a reset. + * + * Return: 0 on success, negative errno if TX DMA did not quiesce + **/ +int rnpgbe_configure_tx(struct mucse *mucse) +{ + struct mucse_hw *hw = &mucse->hw; + u32 i, dma_axi_ctl; + int err; + + err = rnpgbe_stop_all_tx_rings(mucse); + if (err) + return err; + + for (i = 0; i < mucse->num_tx_queues; i++) + rnpgbe_configure_tx_ring(mucse, mucse->tx_ring[i]); + + /* Ensure all ring configuration is visible before enabling TX DMA. */ + wmb(); + dma_axi_ctl = mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + dma_axi_ctl |= TX_AXI_RW_EN; + mucse_hw_wr32(hw, RNPGBE_DMA_AXI_EN, dma_axi_ctl); + /* Ensure TX_AXI_RW_EN is visible before starting the rings. */ + (void)mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + + for (i = 0; i < mucse->num_tx_queues; i++) + mucse_ring_wr32(mucse->tx_ring[i], RNPGBE_TX_START, 1); + + return 0; +} + +/** + * rnpgbe_setup_all_tx_resources - allocate all queues Tx resources + * @mucse: pointer to private structure + * + * Allocate memory for tx_ring. + * + * Return: 0 on success, negative on failure + **/ +int rnpgbe_setup_all_tx_resources(struct mucse *mucse) +{ + int i, err = 0; + + for (i = 0; i < mucse->num_tx_queues; i++) { + err = rnpgbe_setup_tx_resources(mucse->tx_ring[i]); + if (!err) + continue; + + goto err_free_res; + } + + return 0; +err_free_res: + while (i--) + rnpgbe_free_tx_resources(mucse->tx_ring[i]); + return err; +} + +/** + * rnpgbe_free_all_tx_resources - Free Tx Resources for All Queues + * @mucse: pointer to private structure + * + * Free all transmit software resources + **/ +void rnpgbe_free_all_tx_resources(struct mucse *mucse) +{ + for (int i = 0; i < (mucse->num_tx_queues); i++) + rnpgbe_free_tx_resources(mucse->tx_ring[i]); +} + +static int rnpgbe_tx_map(struct mucse_ring *tx_ring, + struct mucse_tx_buffer *first, u32 mac_ip_len, + u32 tx_flags) +{ + struct mucse_tx_buffer *tx_buffer; + struct rnpgbe_tx_desc *tx_desc; + struct skb_shared_info *shinfo; + unsigned int data_len, size; + struct sk_buff *skb; + skb_frag_t *frag; + dma_addr_t dma; + int nr_frags; + int frag_idx; + /* Hardware requires this in the upper 8 bits of + * the descriptor address + */ + u64 fun_id; + u16 i; + + skb = first->skb; + shinfo = skb_shinfo(skb); + fun_id = (u64)tx_ring->pfvfnum << 56; + nr_frags = shinfo->nr_frags; + i = tx_ring->next_to_use; + frag_idx = 0; + tx_desc = M_TX_DESC(tx_ring, i); + size = skb_headlen(skb); + data_len = skb->data_len; + + if (size) { + dma = dma_map_single(tx_ring->dev, skb->data, size, + DMA_TO_DEVICE); + first->mapped_as_page = false; + } else if (data_len) { + while (frag_idx < nr_frags && + !skb_frag_size(&shinfo->frags[frag_idx])) + frag_idx++; + + if (frag_idx == nr_frags) + goto err_unmap; + + frag = &shinfo->frags[frag_idx]; + size = skb_frag_size(frag); + + dma = skb_frag_dma_map(tx_ring->dev, frag, 0, + size, DMA_TO_DEVICE); + first->mapped_as_page = true; + data_len -= size; + frag_idx++; + } else { + goto err_unmap; + } + + tx_buffer = first; + + dma_unmap_len_set(tx_buffer, len, 0); + dma_unmap_addr_set(tx_buffer, dma, 0); + + for (;; frag_idx++) { + if (dma_mapping_error(tx_ring->dev, dma)) + goto err_unmap; + + /* record length, and DMA address */ + dma_unmap_len_set(tx_buffer, len, size); + dma_unmap_addr_set(tx_buffer, dma, dma); + + tx_desc->pkt_addr = cpu_to_le64(dma | fun_id); + + while (unlikely(size > M_MAX_DATA_PER_TXD)) { + tx_desc->vlan_cmd_bsz = build_ctob(tx_flags, + mac_ip_len, + M_MAX_DATA_PER_TXD); + i++; + tx_desc++; + if (i == tx_ring->count) { + tx_desc = M_TX_DESC(tx_ring, 0); + i = 0; + } + + tx_buffer = &tx_ring->tx_buffer_info[i]; + dma_unmap_len_set(tx_buffer, len, 0); + dma += M_MAX_DATA_PER_TXD; + size -= M_MAX_DATA_PER_TXD; + tx_desc->pkt_addr = cpu_to_le64(dma | fun_id); + } + + if (likely(!data_len)) + break; + tx_desc->vlan_cmd_bsz = build_ctob(tx_flags, mac_ip_len, size); + i++; + tx_desc++; + if (i == tx_ring->count) { + tx_desc = M_TX_DESC(tx_ring, 0); + i = 0; + } + + while (frag_idx < nr_frags && + !skb_frag_size(&shinfo->frags[frag_idx])) + frag_idx++; + + if (frag_idx == nr_frags) + goto err_unmap; + + frag = &shinfo->frags[frag_idx]; + size = skb_frag_size(frag); + data_len -= size; + dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, + DMA_TO_DEVICE); + tx_buffer = &tx_ring->tx_buffer_info[i]; + tx_buffer->mapped_as_page = true; + } + + /* write last descriptor with RS and EOP bits */ + tx_desc->vlan_cmd_bsz = build_ctob(tx_flags | M_TXD_CMD_EOP | + M_TXD_CMD_RS, + mac_ip_len, size); + + /* Force memory writes to complete before letting h/w know there + * are new descriptors to fetch. (Only applicable for weak-ordered + * memory model archs, such as IA-64). + * + * We also need this memory barrier to make certain all of the + * status bits have been updated before next_to_watch is written. + */ + dma_wmb(); + /* set next_to_watch value indicating a packet is present */ + first->next_to_watch = tx_desc; + i++; + if (i == tx_ring->count) + i = 0; + tx_ring->next_to_use = i; + skb_tx_timestamp(skb); + netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); + /* notify HW of packet */ + writel(i, tx_ring->tail); + + return 0; +err_unmap: + for (;;) { + tx_buffer = &tx_ring->tx_buffer_info[i]; + if (dma_unmap_len(tx_buffer, len)) { + if (tx_buffer->mapped_as_page) { + dma_unmap_page(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } else { + dma_unmap_single(tx_ring->dev, + dma_unmap_addr(tx_buffer, dma), + dma_unmap_len(tx_buffer, len), + DMA_TO_DEVICE); + } + } + dma_unmap_len_set(tx_buffer, len, 0); + dma_unmap_addr_set(tx_buffer, dma, 0); + if (tx_buffer == first) + break; + if (i == 0) + i += tx_ring->count; + i--; + } + dev_kfree_skb_any(first->skb); + first->skb = NULL; + tx_ring->next_to_use = i; + + return -ENOMEM; +} + +netdev_tx_t rnpgbe_xmit_frame_ring(struct sk_buff *skb, + struct mucse_ring *tx_ring) +{ + /* hw requires non-zero mac_ip_len even without offload; + * Will be updated per-packet when offload is added + */ + u32 mac_ip_len = M_DEFAULT_MAC_IP_LEN; + struct mucse_tx_buffer *first; + u32 tx_flags = 0; + unsigned short f; + u16 count; + + count = TXD_USE_COUNT(skb_headlen(skb)); + for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { + skb_frag_t *frag_temp = &skb_shinfo(skb)->frags[f]; + + count += TXD_USE_COUNT(skb_frag_size(frag_temp)); + } + + if (!netif_txq_maybe_stop(txring_txq(tx_ring), + mucse_desc_unused(tx_ring), + count + RESV_DESC_NEEDED, + count + RESV_DESC_NEEDED)) + return NETDEV_TX_BUSY; + + /* record the location of the first descriptor for this packet */ + first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; + first->skb = skb; + first->bytecount = skb->len; + first->gso_segs = 1; + + if (rnpgbe_tx_map(tx_ring, first, mac_ip_len, tx_flags)) { + atomic64_inc(&tx_ring->stats->dropped); + + goto out; + } + + /* NETDEV_TX_BUSY is expensive. So stop advancing the TX queue. */ + netif_txq_maybe_stop(txring_txq(tx_ring), + mucse_desc_unused(tx_ring), + DESC_NEEDED, DESC_NEEDED); +out: + return NETDEV_TX_OK; +} + +/** + * rnpgbe_get_stats64 - Get stats for this netdev + * @netdev: network interface device structure + * @stats: stats data + **/ +void rnpgbe_get_stats64(struct net_device *netdev, + struct rtnl_link_stats64 *stats) +{ + struct mucse *mucse = netdev_priv(netdev); + int i; + + for (i = 0; i < RNPGBE_MAX_QUEUES; i++) { + unsigned int start; + u64 bytes, packets, dropped; + struct mucse_queue_stats *queue_stats = &mucse->tx_stats[i]; + + do { + start = u64_stats_fetch_begin(&queue_stats->syncp); + packets = queue_stats->packets; + bytes = queue_stats->bytes; + } while (u64_stats_fetch_retry(&queue_stats->syncp, start)); + dropped = atomic64_read(&queue_stats->dropped); + + stats->tx_packets += packets; + stats->tx_dropped += dropped; + stats->tx_bytes += bytes; + } } diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h index a1074890f5ad..2e0f210f35e7 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h @@ -5,20 +5,43 @@ #define _RNPGBE_LIB_H #include +#include +#include struct mucse; struct mucse_hw; +struct mucse_ring; #define RING_OFFSET(n) (0x1000 + 0x100 * (n)) +#define RNPGBE_TX_START 0x18 #define RNPGBE_DMA_INT_MASK 0x24 #define TX_INT_MASK BIT(1) #define RX_INT_MASK BIT(0) #define INT_VALID (BIT(16) | BIT(17)) #define RNPGBE_DMA_INT_TRIG 0x2c /* lost-interrupt recovery trigger */ +#define RNPGBE_TX_BASE_ADDR_HI 0x60 +#define RNPGBE_TX_BASE_ADDR_LO 0x64 +#define RNPGBE_TX_LEN 0x68 +#define RNPGBE_TX_HEAD 0x6c +#define RNPGBE_TX_TAIL 0x70 +#define M_DEFAULT_TX_FETCH 0x80008 +#define RNPGBE_TX_FETCH_CTRL 0x74 +#define M_DEFAULT_INT_TIMER 100 +#define RNPGBE_TX_INT_TIMER 0x78 +#define M_DEFAULT_INT_PKTCNT 48 +#define RNPGBE_TX_INT_PKTCNT 0x7c /* | 31:24 | .... | 15:8 | 7:0 | */ /* | pfvfnum | | tx vector | rx vector | */ #define RING_VECTOR(n) (0x04 * (n)) +#define M_MAX_TXD_PWR 12 +#define M_MAX_DATA_PER_TXD (0x1 << M_MAX_TXD_PWR) +#define TXD_USE_COUNT(S) DIV_ROUND_UP((S), M_MAX_DATA_PER_TXD) +#define DESC_NEEDED (MAX_SKB_FRAGS + 4) +/* Leave two descriptors between the tail and head. */ +#define RESV_DESC_NEEDED 2 +/* Hardware requires this to be nonzero */ +#define M_DEFAULT_MAC_IP_LEN 20 #define mucse_for_each_ring(pos, head)\ for (typeof((head).ring) __pos = (head).ring;\ __pos ? ({ pos = __pos; 1; }) : 0;\ @@ -32,4 +55,12 @@ int rnpgbe_request_irq(struct mucse *mucse); void rnpgbe_free_irq(struct mucse *mucse); void rnpgbe_down(struct mucse *mucse); void rnpgbe_up_complete(struct mucse *mucse); +int rnpgbe_configure_tx(struct mucse *mucse); +void rnpgbe_clean_all_tx_rings(struct mucse *mucse); +int rnpgbe_setup_all_tx_resources(struct mucse *mucse); +void rnpgbe_free_all_tx_resources(struct mucse *mucse); +netdev_tx_t rnpgbe_xmit_frame_ring(struct sk_buff *skb, + struct mucse_ring *tx_ring); +void rnpgbe_get_stats64(struct net_device *netdev, + struct rtnl_link_stats64 *stats); #endif diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c index 6022a1a2ddf1..265a3fcb07be 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c @@ -2,6 +2,7 @@ /* Copyright(c) 2020 - 2025 Mucse Corporation. */ #include +#include #include #include @@ -26,6 +27,19 @@ static struct pci_device_id rnpgbe_pci_tbl[] = { { }, }; +/** + * rnpgbe_configure - Configure the hardware + * @mucse: pointer to private structure + * + * Configure Tx registers in hardware. + * + * Return: 0 on success, negative errno if hardware configuration fails + **/ +static int rnpgbe_configure(struct mucse *mucse) +{ + return rnpgbe_configure_tx(mucse); +} + /** * rnpgbe_open - Called when a network interface is made active * @netdev: network interface device structure @@ -40,6 +54,9 @@ static int rnpgbe_open(struct net_device *netdev) struct mucse *mucse = netdev_priv(netdev); int err; + if (test_bit(__MUCSE_AXI_FAULT, &mucse->state)) + return -EIO; + err = rnpgbe_request_irq(mucse); if (err) return err; @@ -49,9 +66,19 @@ static int rnpgbe_open(struct net_device *netdev) if (err) goto err_free_irqs; + err = rnpgbe_setup_all_tx_resources(mucse); + if (err) + goto err_free_irqs; + + err = rnpgbe_configure(mucse); + if (err) + goto err_free_tx; rnpgbe_up_complete(mucse); return 0; +err_free_tx: + rnpgbe_clean_all_tx_rings(mucse); + rnpgbe_free_all_tx_resources(mucse); err_free_irqs: rnpgbe_free_irq(mucse); return err; @@ -72,6 +99,7 @@ static int rnpgbe_close(struct net_device *netdev) rnpgbe_down(mucse); rnpgbe_free_irq(mucse); + rnpgbe_free_all_tx_resources(mucse); return 0; } @@ -81,25 +109,44 @@ static int rnpgbe_close(struct net_device *netdev) * @skb: skb structure to be sent * @netdev: network interface device structure * - * Return: NETDEV_TX_OK + * Return: NETDEV_TX_OK or NETDEV_TX_BUSY when insufficient descriptors **/ static netdev_tx_t rnpgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) { struct mucse *mucse = netdev_priv(netdev); + struct mucse_ring *tx_ring; - dev_kfree_skb_any(skb); - mucse->stats.tx_dropped++; + tx_ring = mucse->tx_ring[skb_get_queue_mapping(skb)]; - return NETDEV_TX_OK; + if (unlikely(skb_put_padto(skb, RNPGBE_TX_MIN_PKT_LEN))) { + atomic64_inc(&tx_ring->stats->dropped); + return NETDEV_TX_OK; + } + + return rnpgbe_xmit_frame_ring(skb, tx_ring); } static const struct net_device_ops rnpgbe_netdev_ops = { .ndo_open = rnpgbe_open, .ndo_stop = rnpgbe_close, .ndo_start_xmit = rnpgbe_xmit_frame, + .ndo_get_stats64 = rnpgbe_get_stats64, }; +static void rnpgbe_sw_init(struct mucse *mucse) +{ + int i; + + mucse->tx_ring_item_count = M_DEFAULT_TXD; + mucse->tx_work_limit = M_DEFAULT_TX_WORK; + + for (i = 0; i < RNPGBE_MAX_QUEUES; i++) { + u64_stats_init(&mucse->tx_stats[i].syncp); + atomic64_set(&mucse->tx_stats[i].dropped, 0); + } +} + /** * rnpgbe_add_adapter - Add netdev for this pci_dev * @pdev: PCI device information structure @@ -172,6 +219,7 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev, } netdev->netdev_ops = &rnpgbe_netdev_ops; + rnpgbe_sw_init(mucse); err = rnpgbe_reset_hw(hw); if (err) { dev_err(&pdev->dev, "Hw reset failed %d\n", err); @@ -206,6 +254,14 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev, goto err_clear_interrupt; } + netdev->features |= NETIF_F_SG; + netdev->hw_features |= NETIF_F_SG; + if (dma_get_mask(&pdev->dev) > DMA_BIT_MASK(32)) { + netdev->features |= NETIF_F_HIGHDMA; + netdev->hw_features |= NETIF_F_HIGHDMA; + } + + netif_carrier_off(netdev); err = register_netdev(netdev); if (err) goto err_remove_mbx; @@ -248,12 +304,7 @@ static int rnpgbe_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (err) return err; - err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(56)); - if (err) { - dev_err(&pdev->dev, - "No usable DMA configuration, aborting %d\n", err); - goto err_disable_dev; - } + dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(56)); err = pci_request_mem_regions(pdev, rnpgbe_driver_name); if (err) { From 250a6edaea4998e6f2db6e030cb5d1135ee18b5d Mon Sep 17 00:00:00 2001 From: Dong Yibo Date: Tue, 13 Oct 2026 10:30:48 +0800 Subject: [PATCH 1921/2126] net: rnpgbe: Add basic RX data path support Add basic RX DMA data path for the RNPGBE driver. Introduce the RX descriptor structure (union rnpgbe_rx_desc) with the hardware write-back format, and manage RX buffers with page_pool using a single page per descriptor without page splitting. Implement the NAPI poll callback, RX ring setup and teardown, and packet assembly from page buffers, along with RX statistics. Keep a 16-descriptor gap in the fixed 512-entry RX ring so at most 496 descriptors are posted to hardware. Retry failed page allocations with one timer per q_vector that schedules NAPI and is cancelled before RX cleanup and q_vector teardown. An RX DMA quiesce timeout is a terminal AXI fault: keep DMA disabled, release existing mappings safely, and reject subsequent opens. Recovery requires a chip-level reset and driver rebind. Signed-off-by: Dong Yibo Link: https://patch.msgid.link/FA6FE70B8DB5E7FB+20261013023048.63685-1-dong100@mucse.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mucse/Kconfig | 1 + drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 67 +- drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 2 + .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.c | 837 +++++++++++++++++- .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.h | 23 +- .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 21 +- 6 files changed, 942 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mucse/Kconfig b/drivers/net/ethernet/mucse/Kconfig index 17528dba2613..c324118dae2b 100644 --- a/drivers/net/ethernet/mucse/Kconfig +++ b/drivers/net/ethernet/mucse/Kconfig @@ -20,6 +20,7 @@ config MGBE tristate "Mucse(R) 1GbE PCI Express adapters support" depends on PCI depends on PCI_MSI + select PAGE_POOL help This driver supports Mucse(R) 1GbE PCI Express family of adapters. diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h index 5456919ef80b..f839a402ad34 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -62,7 +63,32 @@ struct rnpgbe_tx_desc { #define M_TXD_CMD_EOP 0x010000 /* End of Packet */ }; +union rnpgbe_rx_desc { + struct { + __le64 pkt_addr; /* Packet buffer address */ + __le64 resv_cmd; /* cmd status */ + }; + struct { + __le32 rss_hash; /* RSS HASH */ + __le16 mark; /* mark info */ + __le16 rev1; + __le16 len; /* Packet length */ + __le16 padding_len; + __le16 vlan; /* VLAN tag */ + __le16 cmd; /* cmd status */ +#define M_RXD_STAT_DD BIT(1) /* Descriptor Done */ +#define M_RXD_STAT_EOP BIT(0) /* End of Packet */ + } wb; +}; + #define M_TX_DESC(R, i) (&(((struct rnpgbe_tx_desc *)((R)->desc))[i])) +#define M_RX_DESC(R, i) (&(((union rnpgbe_rx_desc *)((R)->desc))[i])) + +static inline __le16 rnpgbe_test_staterr(union rnpgbe_rx_desc *rx_desc, + const u16 stat_err_bits) +{ + return rx_desc->wb.cmd & cpu_to_le16(stat_err_bits); +} struct mucse_tx_buffer { struct rnpgbe_tx_desc *next_to_watch; @@ -77,17 +103,35 @@ struct mucse_tx_buffer { struct mucse_queue_stats { u64 packets; u64 bytes; + u64 length_errors; atomic64_t dropped; struct u64_stats_sync syncp; } ____cacheline_aligned_in_smp; +struct mucse_rx_buffer { + struct sk_buff *skb; + dma_addr_t dma; + struct page *page; + u32 page_offset; +}; + +enum mucse_rx_drop_reason { + MUCSE_RX_DROP_NONE, + MUCSE_RX_DROP_RESOURCE, + MUCSE_RX_DROP_LENGTH, +}; + struct mucse_ring { struct mucse_ring *next; struct mucse_q_vector *q_vector; struct net_device *netdev; struct device *dev; + struct page_pool *page_pool; void *desc; - struct mucse_tx_buffer *tx_buffer_info; + union { + struct mucse_tx_buffer *tx_buffer_info; + struct mucse_rx_buffer *rx_buffer_info; + }; void __iomem *ring_addr; void __iomem *tail; void __iomem *irq_mask; @@ -101,9 +145,14 @@ struct mucse_ring { u16 next_to_clean; dma_addr_t dma; unsigned int size; + u32 drop_bytes; /* bytes in the current frame being dropped */ struct mucse_queue_stats *stats; + enum mucse_rx_drop_reason drop_reason; } ____cacheline_internodealigned_in_smp; +/* Refill RX descriptors in batches of this size. */ +#define M_RX_BUFFER_WRITE 16 + static inline u16 mucse_desc_unused(struct mucse_ring *ring) { u16 ntc = ring->next_to_clean; @@ -112,6 +161,18 @@ static inline u16 mucse_desc_unused(struct mucse_ring *ring) return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; } +static inline u16 mucse_desc_unused_rx(struct mucse_ring *ring) +{ + u16 ntc = ring->next_to_clean; + u16 ntu = ring->next_to_use; + + /* Keep M_RX_BUFFER_WRITE descriptors unused so the ring is not filled + * completely. Refill is attempted once at least this many descriptors + * are available. + */ + return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - M_RX_BUFFER_WRITE; +} + static inline __le64 build_ctob(u32 vlan_cmd, u32 mac_ip_len, u32 size) { return cpu_to_le64(((u64)vlan_cmd << 32) | ((u64)mac_ip_len << 16) | @@ -134,6 +195,7 @@ struct mucse_q_vector { int hw_vector; struct mucse_ring_container rx, tx; struct napi_struct napi; + struct timer_list rx_alloc_timer; char name[IFNAMSIZ + 18]; /* for dynamic allocation of rings associated with this q_vector */ struct mucse_ring ring[] ____cacheline_internodealigned_in_smp; @@ -142,6 +204,7 @@ struct mucse_q_vector { #define MAX_Q_VECTORS 8 #define M_DEFAULT_TXD 512 +#define M_DEFAULT_RXD 512 #define M_DEFAULT_TX_WORK 256 enum mucse_state_t { @@ -157,11 +220,13 @@ struct mucse { struct mucse_ring *rx_ring[RNPGBE_MAX_QUEUES] ____cacheline_aligned_in_smp; struct mucse_queue_stats tx_stats[RNPGBE_MAX_QUEUES]; + struct mucse_queue_stats rx_stats[RNPGBE_MAX_QUEUES]; struct mucse_q_vector *q_vector[MAX_Q_VECTORS]; int tx_ring_item_count; int tx_work_limit; int num_tx_queues; int num_q_vectors; + int rx_ring_item_count; int num_rx_queues; char mbx_name[32]; bool mbx_irq_requested; diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h index f9ca13b29f69..dc869051c8fa 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h @@ -21,6 +21,8 @@ #define TX_AXI_RW_EN 0xc /* DMA_STATUS_REG[23:20]: tx_wr, tx_rd, rx_wr, rx_rd done status. */ #define RNPGBE_DMA_TX_STATUS GENMASK_U32(23, 22) +#define RNPGBE_DMA_RX_STATUS GENMASK_U32(21, 20) +#define RX_AXI_RW_EN 0x03 #define RNPGBE_DMA_AXI_EN 0x0010 #define RNPGBE_TX_MIN_PKT_LEN 33 diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c index 21cd578f7532..22fe284729f2 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c @@ -4,8 +4,10 @@ #include #include #include +#include #include #include +#include #include "rnpgbe_lib.h" #include "rnpgbe.h" @@ -174,15 +176,465 @@ static bool rnpgbe_clean_tx_irq(struct mucse_q_vector *q_vector, return !!budget; } +static bool mucse_alloc_mapped_page(struct mucse_ring *rx_ring, + struct mucse_rx_buffer *bi) +{ + struct page *page = bi->page; + dma_addr_t dma; + + if (page) { + /* Buffer is being reused without going back through the + * page_pool. Do dma_sync for hw use. + */ + dma_sync_single_range_for_device(rx_ring->dev, bi->dma, + bi->page_offset, + RNPGBE_RX_DESC_DATA_LEN, + DMA_FROM_DEVICE); + return true; + } + + page = page_pool_dev_alloc_pages(rx_ring->page_pool); + if (unlikely(!page)) + return false; + dma = page_pool_get_dma_addr(page); + + bi->dma = dma; + bi->page = page; + bi->page_offset = RNPGBE_SKB_PAD; + + return true; +} + +static void mucse_update_rx_tail(struct mucse_ring *rx_ring, + u32 val) +{ + rx_ring->next_to_use = val; + writel(val, rx_ring->tail); +} + +/** + * rnpgbe_alloc_rx_buffers - Replace used receive buffers + * @rx_ring: ring to place buffers on + * @cleaned_count: number of buffers to replace + **/ +static void rnpgbe_alloc_rx_buffers(struct mucse_ring *rx_ring, + u16 cleaned_count) +{ + u64 fun_id = ((u64)(rx_ring->pfvfnum) << 56); + union rnpgbe_rx_desc *rx_desc; + u16 i = rx_ring->next_to_use; + struct mucse_rx_buffer *bi; + u64 addr; + /* nothing to do */ + if (!cleaned_count) + return; + + rx_desc = M_RX_DESC(rx_ring, i); + bi = &rx_ring->rx_buffer_info[i]; + i -= rx_ring->count; + + do { + if (!mucse_alloc_mapped_page(rx_ring, bi)) + break; + + addr = (u64)(bi->dma + bi->page_offset); + rx_desc->pkt_addr = cpu_to_le64(addr | fun_id); + /* clean dd */ + rx_desc->resv_cmd = 0; + rx_desc++; + bi++; + i++; + if (unlikely(!i)) { + rx_desc = M_RX_DESC(rx_ring, 0); + bi = rx_ring->rx_buffer_info; + i -= rx_ring->count; + } + cleaned_count--; + } while (cleaned_count); + + i += rx_ring->count; + + /* Publish the tail even when allocation stopped early, so a stale + * tail from a previous session cannot point hardware at a + * reallocated ring. + */ + dma_wmb(); + mucse_update_rx_tail(rx_ring, i); +} + +/** + * rnpgbe_get_buffer - Get the rx_buffer to be used + * @rx_ring: pointer to rx ring + * @skb: pointer skb for this packet + * @size: data size in this desc + * + * Return: rx_buffer. + **/ +static struct mucse_rx_buffer *rnpgbe_get_buffer(struct mucse_ring *rx_ring, + struct sk_buff **skb, + const unsigned int size) +{ + struct mucse_rx_buffer *rx_buffer; + + rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; + *skb = rx_buffer->skb; + prefetchw(page_address(rx_buffer->page) + rx_buffer->page_offset); + /* we are reusing so sync this buffer for CPU use */ + dma_sync_single_range_for_cpu(rx_ring->dev, rx_buffer->dma, + rx_buffer->page_offset, size, + DMA_FROM_DEVICE); + + return rx_buffer; +} + +/** + * rnpgbe_add_rx_frag - Add non-linear data to the skb + * @rx_buffer: pointer to rx_buffer + * @skb: pointer skb for this packet + * @size: data size in this desc + **/ +static void rnpgbe_add_rx_frag(struct mucse_rx_buffer *rx_buffer, + struct sk_buff *skb, + unsigned int size) +{ + unsigned int truesize = PAGE_SIZE; + + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, + rx_buffer->page_offset, size, truesize); +} + +/** + * rnpgbe_build_skb - Try to build a skb based on rx_buffer + * @rx_buffer: pointer to rx_buffer + * @size: data size in this desc + * + * Return: skb for this rx_buffer + **/ +static struct sk_buff *rnpgbe_build_skb(struct mucse_rx_buffer *rx_buffer, + unsigned int size) +{ + void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; + unsigned int truesize = PAGE_SIZE; + struct sk_buff *skb; + + net_prefetch(va); + /* build an skb around the page buffer */ + skb = napi_build_skb(va - RNPGBE_SKB_PAD, truesize); + if (unlikely(!skb)) + return NULL; + /* update pointers within the skb to store the data */ + skb_reserve(skb, RNPGBE_SKB_PAD); + __skb_put(skb, size); + skb_mark_for_recycle(skb); + + return skb; +} + +/** + * rnpgbe_is_non_eop - Process handling of non-EOP buffers + * @rx_ring: rx ring being processed + * @rx_desc: rx descriptor for current buffer + * @skb: current socket buffer containing buffer in progress + * + * Advance next_to_clean. For a non-EOP descriptor, carry the skb into the + * next descriptor unless the fragment limit has been reached. In that case, + * free the skb and mark the remaining descriptors for drop. + * + * Return: true if the descriptor is not EOP. The skb may have been consumed + * when true is returned. + **/ +static bool rnpgbe_is_non_eop(struct mucse_ring *rx_ring, + union rnpgbe_rx_desc *rx_desc, + struct sk_buff *skb) +{ + u32 ntc = rx_ring->next_to_clean + 1; + + /* fetch, update, and store next to clean */ + ntc = (ntc < rx_ring->count) ? ntc : 0; + rx_ring->next_to_clean = ntc; + prefetch(M_RX_DESC(rx_ring, ntc)); + /* if we are the last buffer then there is nothing else to do */ + if (likely(rnpgbe_test_staterr(rx_desc, M_RXD_STAT_EOP))) + return false; + if (skb_shinfo(skb)->nr_frags < MAX_SKB_FRAGS) { + /* place skb in next buffer to be received */ + rx_ring->rx_buffer_info[ntc].skb = skb; + } else { + rx_ring->drop_bytes = skb->len; + /* too much frags, force free */ + dev_kfree_skb_any(skb); + rx_ring->drop_reason = MUCSE_RX_DROP_RESOURCE; + } + /* we should clean it since we used all info in it */ + rx_desc->wb.cmd = 0; + + return true; +} + +/** + * rnpgbe_cleanup_headers - Correct corrupted or empty headers + * @skb: current socket buffer containing buffer in progress + * + * Return: true if an error was encountered and skb was freed. + **/ +static bool rnpgbe_cleanup_headers(struct sk_buff *skb) +{ + if (unlikely(!pskb_may_pull(skb, ETH_HLEN))) { + dev_kfree_skb_any(skb); + return true; + } + + /* if eth_skb_pad returns an error the skb was freed */ + if (eth_skb_pad(skb)) + return true; + + return false; +} + +/** + * rnpgbe_process_skb_fields - Set the RX queue and protocol fields + * @rx_ring: RX descriptor ring containing the queue information + * @skb: skb currently being received + * + * Records the RX queue that received the skb and sets its protocol from + * the Ethernet header. + **/ +static void rnpgbe_process_skb_fields(struct mucse_ring *rx_ring, + struct sk_buff *skb) +{ + struct net_device *dev = rx_ring->netdev; + + skb_record_rx_queue(skb, rx_ring->queue_index); + skb->protocol = eth_type_trans(skb, dev); +} + +/** + * rnpgbe_rx_alloc_retry - Retry RX buffer allocation + * @timer: RX allocation retry timer + * + * Schedules NAPI after RX buffer allocation fails. + **/ +static void rnpgbe_rx_alloc_retry(struct timer_list *timer) +{ + struct mucse_q_vector *q_vector = + timer_container_of(q_vector, timer, rx_alloc_timer); + + napi_schedule(&q_vector->napi); +} + +static bool rnpgbe_rx_refill_pending(struct mucse_q_vector *q_vector) +{ + struct mucse_ring *ring; + + mucse_for_each_ring(ring, q_vector->rx) { + if (mucse_desc_unused_rx(ring) >= M_RX_BUFFER_WRITE) + return true; + } + + return false; +} + +static void rnpgbe_schedule_rx_retry(struct mucse *mucse) +{ + struct mucse_q_vector *q_vector; + + for (int i = 0; i < mucse->num_q_vectors; i++) { + q_vector = mucse->q_vector[i]; + if (rnpgbe_rx_refill_pending(q_vector)) + mod_timer(&q_vector->rx_alloc_timer, + jiffies + msecs_to_jiffies(500)); + } +} + +/** + * rnpgbe_clean_rx_irq - Clean completed descriptors from Rx ring + * @q_vector: structure containing interrupt and ring information + * @rx_ring: rx descriptor ring to transact packets on + * @budget: total limit on number of packets to process + * + * rnpgbe_clean_rx_irq tries to check dd in desc, handle this desc + * if dd is set which means data is write-back by hw + * + * Return: amount of work completed. + **/ +static int rnpgbe_clean_rx_irq(struct mucse_q_vector *q_vector, + struct mucse_ring *rx_ring, + int budget) +{ + unsigned int total_rx_bytes = 0, total_rx_packets = 0; + u16 cleaned_count = mucse_desc_unused_rx(rx_ring); + unsigned int total_rx_length_errors = 0; + unsigned int total_rx_dropped = 0; + unsigned int work_done = 0; + + while (likely(work_done < budget)) { + struct mucse_rx_buffer *rx_buffer; + union rnpgbe_rx_desc *rx_desc; + struct sk_buff *skb; + unsigned int size; + + if (cleaned_count >= M_RX_BUFFER_WRITE) { + rnpgbe_alloc_rx_buffers(rx_ring, cleaned_count); + cleaned_count = 0; + } + rx_desc = M_RX_DESC(rx_ring, rx_ring->next_to_clean); + + if (!rnpgbe_test_staterr(rx_desc, M_RXD_STAT_DD)) + break; + + /* This memory barrier is needed to keep us from reading + * any other fields out of the rx_desc until we know the + * descriptor has been written back + */ + dma_rmb(); + /* Hardware guarantees the first descriptor of each packet is at + * least 33 bytes, including multi-descriptor packets. + * Multi-descriptor packets are only used for jumbo frames over + * 1536 bytes (M_DEFAULT_SG = 96). Each descriptor is at most + * 1536 bytes. Small packets use a single descriptor. + */ + size = le16_to_cpu(rx_desc->wb.len); + + if (unlikely(!size || size > RNPGBE_RX_DESC_DATA_LEN)) { + struct mucse_rx_buffer *err_rx_buffer; + u16 idx = rx_ring->next_to_clean; + + cleaned_count++; + /* Length errors override resource drops. */ + rx_ring->drop_reason = MUCSE_RX_DROP_LENGTH; + rx_ring->drop_bytes = 0; + + /* Free the partial skb from a previous non-EOP + * descriptor before advancing next_to_clean. + */ + err_rx_buffer = &rx_ring->rx_buffer_info[idx]; + if (unlikely(err_rx_buffer->skb)) { + dev_kfree_skb_any(err_rx_buffer->skb); + err_rx_buffer->skb = NULL; + } + + /* drop data until eop */ + if (rnpgbe_test_staterr(rx_desc, M_RXD_STAT_EOP)) { + total_rx_length_errors++; + rx_ring->drop_reason = MUCSE_RX_DROP_NONE; + work_done++; + } + + rx_desc->wb.cmd = 0; + rx_ring->next_to_clean++; + if (rx_ring->next_to_clean >= rx_ring->count) + rx_ring->next_to_clean = 0; + continue; + } + + if (unlikely(rx_ring->drop_reason != MUCSE_RX_DROP_NONE)) { + cleaned_count++; + if (rx_ring->drop_reason == MUCSE_RX_DROP_RESOURCE) + rx_ring->drop_bytes += size; + + /* Count the packet once at EOP, using its final drop + * reason even across NAPI polls. + */ + if (rnpgbe_test_staterr(rx_desc, M_RXD_STAT_EOP)) { + if (rx_ring->drop_reason == + MUCSE_RX_DROP_LENGTH) { + total_rx_length_errors++; + } else { + total_rx_bytes += rx_ring->drop_bytes; + total_rx_packets++; + total_rx_dropped++; + } + rx_ring->drop_reason = MUCSE_RX_DROP_NONE; + rx_ring->drop_bytes = 0; + work_done++; + } + + rx_desc->wb.cmd = 0; + rx_ring->next_to_clean++; + if (rx_ring->next_to_clean >= rx_ring->count) + rx_ring->next_to_clean = 0; + continue; + } + + rx_buffer = rnpgbe_get_buffer(rx_ring, &skb, size); + + if (skb) + rnpgbe_add_rx_frag(rx_buffer, skb, size); + else + skb = rnpgbe_build_skb(rx_buffer, size); + + if (!skb) { + cleaned_count++; + + /* drop until eop if multiple descriptors */ + if (rnpgbe_test_staterr(rx_desc, M_RXD_STAT_EOP)) { + total_rx_bytes += size; + total_rx_packets++; + total_rx_dropped++; + work_done++; + } else { + rx_ring->drop_bytes = size; + rx_ring->drop_reason = MUCSE_RX_DROP_RESOURCE; + } + + rx_desc->wb.cmd = 0; + rx_ring->next_to_clean++; + if (rx_ring->next_to_clean >= rx_ring->count) + rx_ring->next_to_clean = 0; + + continue; + } + + rx_buffer->page = NULL; + rx_buffer->skb = NULL; + cleaned_count++; + + if (rnpgbe_is_non_eop(rx_ring, rx_desc, skb)) + continue; + + /* verify the packet layout is correct */ + size = skb->len; + if (rnpgbe_cleanup_headers(skb)) { + if (size >= ETH_HLEN) { + total_rx_bytes += size; + total_rx_packets++; + } + /* we should clean it since we used all info in it */ + total_rx_dropped++; + rx_desc->wb.cmd = 0; + work_done++; + continue; + } + + /* probably a little skewed due to removing CRC */ + total_rx_bytes += skb->len; + rnpgbe_process_skb_fields(rx_ring, skb); + rx_desc->wb.cmd = 0; + napi_gro_receive(&q_vector->napi, skb); + /* Update packet statistics and NAPI work accounting. */ + total_rx_packets++; + work_done++; + } + + u64_stats_update_begin(&rx_ring->stats->syncp); + rx_ring->stats->packets += total_rx_packets; + rx_ring->stats->bytes += total_rx_bytes; + rx_ring->stats->length_errors += total_rx_length_errors; + atomic64_add(total_rx_dropped, &rx_ring->stats->dropped); + u64_stats_update_end(&rx_ring->stats->syncp); + + return work_done; +} + /** * rnpgbe_poll - NAPI polling callback * @napi: structure for representing this polling device * @budget: polling budget * - * Clean completed TX packets and complete NAPI polling when all queues are - * clean. + * Clean completed TX and RX packets and complete NAPI polling when all + * queues are clean. * - * Return: 0 if all TX queues are clean, otherwise @budget + * Return: number of RX packets processed, or @budget if polling continues **/ static int rnpgbe_poll(struct napi_struct *napi, int budget) { @@ -190,6 +642,8 @@ static int rnpgbe_poll(struct napi_struct *napi, int budget) container_of(napi, struct mucse_q_vector, napi); bool clean_complete = true; struct mucse_ring *ring; + bool refill_pending; + int per_ring_budget; int work_done = 0; mucse_for_each_ring(ring, q_vector->tx) { @@ -201,11 +655,31 @@ static int rnpgbe_poll(struct napi_struct *napi, int budget) if (unlikely(!budget)) return 0; + if (q_vector->rx.count > 1) + per_ring_budget = max(budget / q_vector->rx.count, 1); + else + per_ring_budget = budget; + + mucse_for_each_ring(ring, q_vector->rx) { + int cleaned = 0; + + cleaned = rnpgbe_clean_rx_irq(q_vector, ring, per_ring_budget); + work_done += cleaned; + if (cleaned >= per_ring_budget) + clean_complete = false; + } + if (!clean_complete) return budget; - if (likely(napi_complete_done(napi, work_done))) + /* Read RX indices while this poll still owns the NAPI instance. */ + refill_pending = rnpgbe_rx_refill_pending(q_vector); + if (likely(napi_complete_done(napi, work_done))) { + if (refill_pending) + mod_timer(&q_vector->rx_alloc_timer, + jiffies + msecs_to_jiffies(500)); rnpgbe_irq_enable_queues(q_vector); + } return work_done; } @@ -345,6 +819,7 @@ static int rnpgbe_alloc_q_vector(struct mucse *mucse, /* tie q_vector and mucse together */ mucse->q_vector[vector_idx] = q_vector; q_vector->mucse = mucse; + timer_setup(&q_vector->rx_alloc_timer, rnpgbe_rx_alloc_retry, 0); q_vector->hw_vector = vector_idx; /* Vector 0 is reserved for the mailbox. */ q_vector->hw_vector++; @@ -370,13 +845,18 @@ static int rnpgbe_alloc_q_vector(struct mucse *mucse, } for (idx = 0; idx < rxr_count; idx++) { + ring->dev = &mucse->pdev->dev; mucse_add_ring(ring, &q_vector->rx); + ring->count = mucse->rx_ring_item_count; + ring->netdev = mucse->netdev; ring->queue_index = eth_queue_idx + idx; ring->rnpgbe_queue_idx = rxr_idx; ring->ring_addr = hw->hw_addr + RING_OFFSET(rxr_idx); ring->irq_mask = ring->ring_addr + RNPGBE_DMA_INT_MASK; ring->trig = ring->ring_addr + RNPGBE_DMA_INT_TRIG; ring->q_vector = q_vector; + ring->pfvfnum = hw->pfvfnum; + ring->stats = &mucse->rx_stats[ring->queue_index]; mucse->rx_ring[ring->queue_index] = ring; rxr_idx += step; ring++; @@ -399,6 +879,8 @@ static void rnpgbe_free_q_vector(struct mucse *mucse, int vector_idx) struct mucse_q_vector *q_vector = mucse->q_vector[vector_idx]; struct mucse_ring *ring; + timer_delete_sync(&q_vector->rx_alloc_timer); + mucse_for_each_ring(ring, q_vector->tx) mucse->tx_ring[ring->queue_index] = NULL; mucse_for_each_ring(ring, q_vector->rx) @@ -718,6 +1200,31 @@ static int rnpgbe_wait_tx_dma_idle(struct mucse *mucse) return err; } +static int rnpgbe_wait_rx_dma_idle(struct mucse *mucse) +{ + struct mucse_hw *hw = &mucse->hw; + u32 dma_status; + int err; + + /* A timeout indicates a terminal AXI fault. Hardware stops all PCIe + * DMA requests in this state, including requests accepted before the + * fault. Teardown may therefore release mappings and descriptor memory. + * Recovery requires a chip-level reset. + */ + err = readl_poll_timeout(hw->hw_addr + RNPGBE_DMA_STATUS, + dma_status, + (dma_status & RNPGBE_DMA_RX_STATUS) == + RNPGBE_DMA_RX_STATUS, + 10, 100000); + if (err) { + set_bit(__MUCSE_AXI_FAULT, &mucse->state); + dev_err(&mucse->pdev->dev, + "RX DMA failed to quiesce, status %#x\n", dma_status); + } + + return err; +} + /** * rnpgbe_stop_all_tx_rings - Stop TX DMA on all queues * @mucse: board private structure @@ -837,6 +1344,101 @@ void rnpgbe_clean_all_tx_rings(struct mucse *mucse) rnpgbe_clean_tx_ring(mucse->tx_ring[i]); } +static void rnpgbe_stop_rx_ring(struct mucse_ring *rx_ring) +{ + /* Stop hw. hardware design guarantees: + * - No new descriptors will be fetched after RX_START=0 + * - No DMA will be initiated for already-fetched descriptors + */ + mucse_ring_wr32(rx_ring, RNPGBE_RX_START, 0); + /* Flush posted write to ensure hardware sees RX_START=0 */ + (void)mucse_ring_rd32(rx_ring, RNPGBE_RX_START); +} + +/** + * rnpgbe_stop_all_rx_rings - Stop RX DMA for all queues + * @mucse: board private structure + * + * Return: 0 if RX DMA is quiesced and no AXI fault is latched, + * negative errno otherwise + **/ +static int rnpgbe_stop_all_rx_rings(struct mucse *mucse) +{ + struct mucse_hw *hw = &mucse->hw; + u32 dma_axi_ctl; + int err = 0; + + for (int i = 0; i < mucse->num_rx_queues; i++) + rnpgbe_stop_rx_ring(mucse->rx_ring[i]); + + if (mucse->num_rx_queues && + !test_bit(__MUCSE_AXI_FAULT, &mucse->state)) + err = rnpgbe_wait_rx_dma_idle(mucse); + + dma_axi_ctl = mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + dma_axi_ctl &= ~RX_AXI_RW_EN; + mucse_hw_wr32(hw, RNPGBE_DMA_AXI_EN, dma_axi_ctl); + /* Flush the posted write before continuing. */ + (void)mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + + if (!test_bit(__MUCSE_AXI_FAULT, &mucse->state)) + return 0; + + return err ? err : -EIO; +} + +/** + * rnpgbe_clean_rx_ring - Free Rx Buffers per Queue + * @rx_ring: ring to free buffers from + **/ +static void rnpgbe_clean_rx_ring(struct mucse_ring *rx_ring) +{ + struct mucse_rx_buffer *rx_buffer; + u16 i; + + /* ring already cleared, nothing to do */ + if (!rx_ring->rx_buffer_info) + return; + /* Free all the Rx ring sk_buffs */ + for (i = 0; i < rx_ring->count; i++) { + rx_buffer = &rx_ring->rx_buffer_info[i]; + + if (rx_buffer->skb) { + struct sk_buff *skb = rx_buffer->skb; + + dev_kfree_skb(skb); + rx_buffer->skb = NULL; + } + + if (rx_buffer->page) { + page_pool_put_full_page(rx_ring->page_pool, + rx_buffer->page, false); + rx_buffer->page = NULL; + } + } + + rx_ring->next_to_clean = 0; + rx_ring->next_to_use = 0; + rx_ring->drop_bytes = 0; + rx_ring->drop_reason = MUCSE_RX_DROP_NONE; +} + +/** + * rnpgbe_clean_all_rx_rings - Free Rx buffers for all queues + * @mucse: board private structure + **/ +static void rnpgbe_clean_all_rx_rings(struct mucse *mucse) +{ + for (int i = 0; i < mucse->num_rx_queues; i++) + rnpgbe_clean_rx_ring(mucse->rx_ring[i]); +} + +static void rnpgbe_cancel_rx_retry_timers(struct mucse *mucse) +{ + for (int i = 0; i < mucse->num_q_vectors; i++) + timer_delete_sync(&mucse->q_vector[i]->rx_alloc_timer); +} + void rnpgbe_down(struct mucse *mucse) { struct net_device *netdev = mucse->netdev; @@ -846,7 +1448,10 @@ void rnpgbe_down(struct mucse *mucse) synchronize_net(); rnpgbe_irq_disable(mucse); netif_tx_disable(netdev); + rnpgbe_stop_all_rx_rings(mucse); + rnpgbe_cancel_rx_retry_timers(mucse); rnpgbe_clean_all_tx_rings(mucse); + rnpgbe_clean_all_rx_rings(mucse); } /** @@ -859,6 +1464,7 @@ void rnpgbe_up_complete(struct mucse *mucse) rnpgbe_configure_msix(mucse); rnpgbe_napi_enable_all(mucse); + rnpgbe_schedule_rx_retry(mucse); rnpgbe_irq_enable(mucse); netif_tx_start_all_queues(netdev); } @@ -1260,4 +1866,227 @@ void rnpgbe_get_stats64(struct net_device *netdev, stats->tx_dropped += dropped; stats->tx_bytes += bytes; } + + for (i = 0; i < RNPGBE_MAX_QUEUES; i++) { + unsigned int start; + u64 bytes, packets, dropped, length_errors; + struct mucse_queue_stats *queue_stats = &mucse->rx_stats[i]; + + do { + start = u64_stats_fetch_begin(&queue_stats->syncp); + packets = queue_stats->packets; + bytes = queue_stats->bytes; + length_errors = queue_stats->length_errors; + } while (u64_stats_fetch_retry(&queue_stats->syncp, start)); + dropped = atomic64_read(&queue_stats->dropped); + + stats->rx_packets += packets; + stats->rx_dropped += dropped; + stats->rx_bytes += bytes; + stats->rx_errors += length_errors; + stats->rx_length_errors += length_errors; + } +} + +static int mucse_alloc_page_pool(struct mucse_ring *rx_ring) +{ + struct page_pool_params pp_params = { + .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .order = 0, + .pool_size = rx_ring->count, + .nid = dev_to_node(rx_ring->dev), + .dev = rx_ring->dev, + .napi = &rx_ring->q_vector->napi, + .dma_dir = DMA_FROM_DEVICE, + .offset = RNPGBE_SKB_PAD, + .max_len = RNPGBE_RX_DESC_DATA_LEN, + .netdev = rx_ring->netdev, + .queue_idx = rx_ring->queue_index, + }; + int ret = 0; + + rx_ring->page_pool = page_pool_create(&pp_params); + if (IS_ERR(rx_ring->page_pool)) { + ret = PTR_ERR(rx_ring->page_pool); + rx_ring->page_pool = NULL; + } + + return ret; +} + +/** + * rnpgbe_setup_rx_resources - allocate Rx resources (Descriptors) + * @rx_ring: rx descriptor ring (for a specific queue) to setup + * + * Return: 0 on success, negative on failure + **/ +static int rnpgbe_setup_rx_resources(struct mucse_ring *rx_ring) +{ + struct device *dev = rx_ring->dev; + int size; + + size = sizeof(struct mucse_rx_buffer) * rx_ring->count; + + rx_ring->rx_buffer_info = vzalloc(size); + + if (!rx_ring->rx_buffer_info) + goto err_return; + /* Round up to nearest 4K */ + rx_ring->size = rx_ring->count * sizeof(union rnpgbe_rx_desc); + rx_ring->size = ALIGN(rx_ring->size, 4096); + rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, &rx_ring->dma, + GFP_KERNEL); + if (!rx_ring->desc) + goto err_free_buffer; + + rx_ring->next_to_clean = 0; + rx_ring->next_to_use = 0; + + if (mucse_alloc_page_pool(rx_ring)) + goto err_free_desc; + + return 0; +err_free_desc: + dma_free_coherent(dev, rx_ring->size, rx_ring->desc, + rx_ring->dma); + rx_ring->desc = NULL; +err_free_buffer: + vfree(rx_ring->rx_buffer_info); +err_return: + rx_ring->rx_buffer_info = NULL; + return -ENOMEM; +} + +/** + * rnpgbe_free_rx_resources - Free Rx Resources + * @rx_ring: ring to clean the resources from + * + * RX DMA must be quiesced and all ring-held buffers released before this + * function is called. + **/ +static void rnpgbe_free_rx_resources(struct mucse_ring *rx_ring) +{ + vfree(rx_ring->rx_buffer_info); + rx_ring->rx_buffer_info = NULL; + /* if not set, then don't free */ + if (!rx_ring->desc) + return; + + dma_free_coherent(rx_ring->dev, rx_ring->size, rx_ring->desc, + rx_ring->dma); + rx_ring->desc = NULL; + if (rx_ring->page_pool) { + page_pool_destroy(rx_ring->page_pool); + rx_ring->page_pool = NULL; + } +} + +/** + * rnpgbe_setup_all_rx_resources - allocate all queues Rx resources + * @mucse: pointer to private structure + * + * Return: 0 on success, negative on failure + **/ +int rnpgbe_setup_all_rx_resources(struct mucse *mucse) +{ + int i, err = 0; + + for (i = 0; i < mucse->num_rx_queues; i++) { + err = rnpgbe_setup_rx_resources(mucse->rx_ring[i]); + if (!err) + continue; + + goto err_setup_rx; + } + + return 0; +err_setup_rx: + while (i--) + rnpgbe_free_rx_resources(mucse->rx_ring[i]); + return err; +} + +/** + * rnpgbe_free_all_rx_resources - Free Rx Resources for All Queues + * @mucse: pointer to private structure + * + * Free all receive software resources + **/ +void rnpgbe_free_all_rx_resources(struct mucse *mucse) +{ + for (int i = 0; i < mucse->num_rx_queues; i++) + rnpgbe_free_rx_resources(mucse->rx_ring[i]); +} + +/** + * rnpgbe_configure_rx_ring - Configure Rx ring info to hw + * @mucse: pointer to private structure + * @ring: structure containing ring specific data + * + * Configure the Rx descriptor ring after a reset. + **/ +static void rnpgbe_configure_rx_ring(struct mucse *mucse, + struct mucse_ring *ring) +{ + struct mucse_hw *hw = &mucse->hw; + + /* Set the descriptor registers after RX DMA has quiesced. */ + mucse_ring_wr32(ring, RNPGBE_RX_BASE_ADDR_LO, (u32)ring->dma); + mucse_ring_wr32(ring, RNPGBE_RX_BASE_ADDR_HI, + (u32)((u64)ring->dma >> 32) | + ((u32)hw->pfvfnum << 24)); + mucse_ring_wr32(ring, RNPGBE_RX_LEN, ring->count); + ring->tail = ring->ring_addr + RNPGBE_RX_TAIL; + ring->next_to_clean = mucse_ring_rd32(ring, RNPGBE_RX_HEAD) % + ring->count; + ring->next_to_use = ring->next_to_clean; + ring->drop_bytes = 0; + ring->drop_reason = MUCSE_RX_DROP_NONE; + mucse_ring_wr32(ring, RNPGBE_RX_SG_LEN, M_DEFAULT_SG); + mucse_ring_wr32(ring, RNPGBE_RX_FETCH, M_DEFAULT_RX_FETCH); + mucse_ring_wr32(ring, RNPGBE_RX_TIMEOUT_TH, 0); + mucse_ring_wr32(ring, RNPGBE_RX_INT_TIMER, + M_DEFAULT_INT_TIMER_R * hw->cycles_per_us); + mucse_ring_wr32(ring, RNPGBE_RX_INT_PKTCNT, M_DEFAULT_RX_INT_PKTCNT); + /* Fill the ring before RX DMA is enabled. Batch-sized allocation + * shortfalls are retried after NAPI is enabled; smaller shortfalls are + * replenished once traffic frees a complete refill batch. + */ + rnpgbe_alloc_rx_buffers(ring, mucse_desc_unused_rx(ring)); +} + +/** + * rnpgbe_configure_rx - Configure Receive Unit after Reset + * @mucse: pointer to private structure + * + * Configure the Rx unit after a reset. + * + * Return: 0 on success, negative errno if RX DMA does not quiesce or + * an AXI fault is already latched + **/ +int rnpgbe_configure_rx(struct mucse *mucse) +{ + struct mucse_hw *hw = &mucse->hw; + u32 dma_axi_ctl; + int err; + + err = rnpgbe_stop_all_rx_rings(mucse); + if (err) + return err; + + for (int i = 0; i < mucse->num_rx_queues; i++) + rnpgbe_configure_rx_ring(mucse, mucse->rx_ring[i]); + + /* Ensure all ring configuration is visible before enabling RX DMA. */ + wmb(); + dma_axi_ctl = mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + dma_axi_ctl |= RX_AXI_RW_EN; + mucse_hw_wr32(hw, RNPGBE_DMA_AXI_EN, dma_axi_ctl); + /* Ensure RX_AXI_RW_EN is visible before starting the rings. */ + (void)mucse_hw_rd32(hw, RNPGBE_DMA_AXI_EN); + + for (int i = 0; i < mucse->num_rx_queues; i++) + mucse_ring_wr32(mucse->rx_ring[i], RNPGBE_RX_START, 1); + + return 0; } diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h index 2e0f210f35e7..072993494deb 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h @@ -13,12 +13,29 @@ struct mucse_hw; struct mucse_ring; #define RING_OFFSET(n) (0x1000 + 0x100 * (n)) +#define RNPGBE_RX_START 0x10 #define RNPGBE_TX_START 0x18 #define RNPGBE_DMA_INT_MASK 0x24 #define TX_INT_MASK BIT(1) #define RX_INT_MASK BIT(0) #define INT_VALID (BIT(16) | BIT(17)) #define RNPGBE_DMA_INT_TRIG 0x2c /* lost-interrupt recovery trigger */ +#define RNPGBE_RX_BASE_ADDR_HI 0x30 +#define RNPGBE_RX_BASE_ADDR_LO 0x34 +#define RNPGBE_RX_LEN 0x38 +#define RNPGBE_RX_HEAD 0x3c +#define RNPGBE_RX_TAIL 0x40 +#define M_DEFAULT_RX_FETCH 0x100020 +#define RNPGBE_RX_FETCH 0x44 +#define M_DEFAULT_INT_TIMER_R 30 +#define RNPGBE_RX_INT_TIMER 0x48 +#define M_DEFAULT_RX_INT_PKTCNT 64 +#define RNPGBE_RX_INT_PKTCNT 0x4c +#define RNPGBE_RX_TIMEOUT_TH 0x54 +#define RNPGBE_RX_SG_UNIT_BYTES 16 +#define M_DEFAULT_SG 96 +#define RNPGBE_RX_DESC_DATA_LEN (M_DEFAULT_SG * RNPGBE_RX_SG_UNIT_BYTES) +#define RNPGBE_RX_SG_LEN 0x58 #define RNPGBE_TX_BASE_ADDR_HI 0x60 #define RNPGBE_TX_BASE_ADDR_LO 0x64 #define RNPGBE_TX_LEN 0x68 @@ -40,13 +57,14 @@ struct mucse_ring; #define DESC_NEEDED (MAX_SKB_FRAGS + 4) /* Leave two descriptors between the tail and head. */ #define RESV_DESC_NEEDED 2 +#define RNPGBE_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) + /* Hardware requires this to be nonzero */ #define M_DEFAULT_MAC_IP_LEN 20 #define mucse_for_each_ring(pos, head)\ for (typeof((head).ring) __pos = (head).ring;\ __pos ? ({ pos = __pos; 1; }) : 0;\ __pos = __pos->next) - int rnpgbe_init_interrupt_scheme(struct mucse *mucse); void rnpgbe_clear_interrupt_scheme(struct mucse *mucse); int rnpgbe_request_mbx_irq(struct mucse *mucse); @@ -56,6 +74,7 @@ void rnpgbe_free_irq(struct mucse *mucse); void rnpgbe_down(struct mucse *mucse); void rnpgbe_up_complete(struct mucse *mucse); int rnpgbe_configure_tx(struct mucse *mucse); +int rnpgbe_configure_rx(struct mucse *mucse); void rnpgbe_clean_all_tx_rings(struct mucse *mucse); int rnpgbe_setup_all_tx_resources(struct mucse *mucse); void rnpgbe_free_all_tx_resources(struct mucse *mucse); @@ -63,4 +82,6 @@ netdev_tx_t rnpgbe_xmit_frame_ring(struct sk_buff *skb, struct mucse_ring *tx_ring); void rnpgbe_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats); +int rnpgbe_setup_all_rx_resources(struct mucse *mucse); +void rnpgbe_free_all_rx_resources(struct mucse *mucse); #endif diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c index 265a3fcb07be..21fa78c59e5b 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c @@ -31,13 +31,19 @@ static struct pci_device_id rnpgbe_pci_tbl[] = { * rnpgbe_configure - Configure the hardware * @mucse: pointer to private structure * - * Configure Tx registers in hardware. + * Configure Tx and Rx registers in hardware. * * Return: 0 on success, negative errno if hardware configuration fails **/ static int rnpgbe_configure(struct mucse *mucse) { - return rnpgbe_configure_tx(mucse); + int err; + + err = rnpgbe_configure_tx(mucse); + if (err) + return err; + + return rnpgbe_configure_rx(mucse); } /** @@ -69,13 +75,18 @@ static int rnpgbe_open(struct net_device *netdev) err = rnpgbe_setup_all_tx_resources(mucse); if (err) goto err_free_irqs; + err = rnpgbe_setup_all_rx_resources(mucse); + if (err) + goto err_free_tx; err = rnpgbe_configure(mucse); if (err) - goto err_free_tx; + goto err_free_rx; rnpgbe_up_complete(mucse); return 0; +err_free_rx: + rnpgbe_free_all_rx_resources(mucse); err_free_tx: rnpgbe_clean_all_tx_rings(mucse); rnpgbe_free_all_tx_resources(mucse); @@ -100,6 +111,7 @@ static int rnpgbe_close(struct net_device *netdev) rnpgbe_down(mucse); rnpgbe_free_irq(mucse); rnpgbe_free_all_tx_resources(mucse); + rnpgbe_free_all_rx_resources(mucse); return 0; } @@ -139,11 +151,14 @@ static void rnpgbe_sw_init(struct mucse *mucse) int i; mucse->tx_ring_item_count = M_DEFAULT_TXD; + mucse->rx_ring_item_count = M_DEFAULT_RXD; mucse->tx_work_limit = M_DEFAULT_TX_WORK; for (i = 0; i < RNPGBE_MAX_QUEUES; i++) { u64_stats_init(&mucse->tx_stats[i].syncp); atomic64_set(&mucse->tx_stats[i].dropped, 0); + u64_stats_init(&mucse->rx_stats[i].syncp); + atomic64_set(&mucse->rx_stats[i].dropped, 0); } } From 20c17178e19279794540e6f2a05a11b825727ba1 Mon Sep 17 00:00:00 2001 From: Dong Yibo Date: Tue, 13 Oct 2026 10:30:58 +0800 Subject: [PATCH 1922/2126] net: rnpgbe: Add receive mode support Add chip-level receive filtering and the ndo_set_rx_mode_async callback. Program the primary and additional unicast addresses into the available RAR entries, and use the 4096-bit multicast hash table for multicast addresses. Advertise RAR-based secondary unicast filtering to the networking core, so it does not force promiscuous mode for a non-empty secondary unicast list. Fall back to accepting all unicast addresses if the RAR table is exhausted, and handle IFF_PROMISC and IFF_ALLMULTI through the chip-level filter control register. Signed-off-by: Dong Yibo Link: https://patch.msgid.link/2E0F918C876CD84D+20261013023058.63715-1-dong100@mucse.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 3 + .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 96 +++++++++++++++++++ drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 15 +++ .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 17 +++- 4 files changed, 127 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h index f839a402ad34..6f71055f180e 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h @@ -240,6 +240,9 @@ int rnpgbe_send_notify(struct mucse_hw *hw, bool enable, int mode); int rnpgbe_init_hw(struct mucse_hw *hw, int board_type); +int rnpgbe_set_rx_mode(struct net_device *netdev, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc); /* Device IDs */ #define PCI_VENDOR_ID_MUCSE 0x8848 diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c index 291e77d573fe..79d66187d044 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c @@ -149,3 +149,99 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type) return 0; } + +static void rnpgbe_set_rar(struct mucse_hw *hw, u32 index, const u8 *addr) +{ + u32 old_low, old_high; + u32 rar_low, rar_high; + + /* The RAR stores the Ethernet address in reverse byte order. */ + rar_low = (u32)addr[5] | ((u32)addr[4] << 8) | + ((u32)addr[3] << 16) | ((u32)addr[2] << 24); + rar_high = (u32)addr[1] | ((u32)addr[0] << 8) | + RNPGBE_RX_RAR_VALID; + old_low = mucse_hw_rd32(hw, RNPGBE_RX_RAR_LOW(index)); + old_high = mucse_hw_rd32(hw, RNPGBE_RX_RAR_HIGH(index)); + if (old_low == rar_low && old_high == rar_high) + return; + + mucse_hw_wr32(hw, RNPGBE_RX_RAR_HIGH(index), + rar_high & ~RNPGBE_RX_RAR_VALID); + mucse_hw_wr32(hw, RNPGBE_RX_RAR_LOW(index), rar_low); + mucse_hw_wr32(hw, RNPGBE_RX_RAR_HIGH(index), rar_high); +} + +static void rnpgbe_clear_rar(struct mucse_hw *hw, u32 index) +{ + u32 rar_high; + + rar_high = mucse_hw_rd32(hw, RNPGBE_RX_RAR_HIGH(index)); + if (!(rar_high & RNPGBE_RX_RAR_VALID)) + return; + + mucse_hw_wr32(hw, RNPGBE_RX_RAR_HIGH(index), 0); + mucse_hw_wr32(hw, RNPGBE_RX_RAR_LOW(index), 0); +} + +int rnpgbe_set_rx_mode(struct net_device *netdev, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc) +{ + u32 mcast_hash[RNPGBE_RX_MCAST_HASH_ENTRIES] = {}; + u32 mcast_ctrl = RNPGBE_RX_UCAST_TABLE_EN; + u32 filter_ctrl = RNPGBE_RX_FILTER_BCAST; + struct netdev_hw_addr *ha; + struct mucse_hw *hw; + struct mucse *mucse; + int rar = 1; + u16 hash; + int i; + + mucse = netdev_priv(netdev); + hw = &mucse->hw; + + /* RAR 0 always holds the interface's primary unicast address. */ + rnpgbe_set_rar(hw, 0, netdev->dev_addr); + + netdev_hw_addr_list_for_each(ha, uc) { + if (rar == RNPGBE_RX_RAR_ENTRIES) { + filter_ctrl |= RNPGBE_RX_FILTER_UCAST_ALL; + break; + } + + rnpgbe_set_rar(hw, rar, ha->addr); + rar++; + } + + for (; rar < RNPGBE_RX_RAR_ENTRIES; rar++) + rnpgbe_clear_rar(hw, rar); + + if (netdev->flags & IFF_PROMISC) { + filter_ctrl |= RNPGBE_RX_FILTER_UCAST_ALL | + RNPGBE_RX_FILTER_MCAST_ALL; + } else if (netdev->flags & IFF_ALLMULTI) { + filter_ctrl |= RNPGBE_RX_FILTER_MCAST_ALL; + } else { + /* MTA type 0 uses ((addr[4] << 8) | addr[5]) & 0xfff. */ + netdev_hw_addr_list_for_each(ha, mc) { + hash = ((ha->addr[4] & 0xf) << 8) | ha->addr[5]; + mcast_hash[hash >> 5] |= BIT(hash & 0x1f); + } + + if (!netdev_hw_addr_list_empty(mc)) + mcast_ctrl |= RNPGBE_RX_MCAST_HASH_EN; + } + + /* Widen multicast filtering before invalidating hash entries. */ + if (filter_ctrl & RNPGBE_RX_FILTER_MCAST_ALL) + mucse_hw_wr32(hw, RNPGBE_RX_FILTER_CTRL, filter_ctrl); + + for (i = 0; i < RNPGBE_RX_MCAST_HASH_ENTRIES; i++) + mucse_hw_wr32(hw, RNPGBE_RX_MCAST_HASH(i), mcast_hash[i]); + + mucse_hw_wr32(hw, RNPGBE_RX_MCAST_CTRL, mcast_ctrl); + if (!(filter_ctrl & RNPGBE_RX_FILTER_MCAST_ALL)) + mucse_hw_wr32(hw, RNPGBE_RX_FILTER_CTRL, filter_ctrl); + + return 0; +} diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h index dc869051c8fa..3f103f93ac30 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h @@ -26,5 +26,20 @@ #define RNPGBE_DMA_AXI_EN 0x0010 #define RNPGBE_TX_MIN_PKT_LEN 33 +#define MUCSE_ETH_OFF(_n) (0x10000 + (_n)) +#define RNPGBE_RX_RAR_LOW(_n) MUCSE_ETH_OFF(0xa000 + 4 * (_n)) +#define RNPGBE_RX_RAR_HIGH(_n) MUCSE_ETH_OFF(0xa400 + 4 * (_n)) +#define RNPGBE_RX_MCAST_HASH(_n) MUCSE_ETH_OFF(0xac00 + 4 * (_n)) +#define RNPGBE_RX_FILTER_CTRL MUCSE_ETH_OFF(0x9110) +#define RNPGBE_RX_MCAST_CTRL MUCSE_ETH_OFF(0x9114) +#define RNPGBE_RX_RAR_VALID BIT(31) +#define RNPGBE_RX_FILTER_BCAST BIT(10) +#define RNPGBE_RX_FILTER_UCAST_ALL BIT(9) +#define RNPGBE_RX_FILTER_MCAST_ALL BIT(8) +#define RNPGBE_RX_MCAST_HASH_EN BIT(4) +#define RNPGBE_RX_UCAST_TABLE_EN BIT(3) +/* The final two of the 32 hardware RAR entries are reserved for NCSI. */ +#define RNPGBE_RX_RAR_ENTRIES 30 +#define RNPGBE_RX_MCAST_HASH_ENTRIES 128 #define RNPGBE_MAX_QUEUES 8 #endif /* _RNPGBE_HW_H */ diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c index 21fa78c59e5b..8e1eebf32723 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c @@ -43,6 +43,13 @@ static int rnpgbe_configure(struct mucse *mucse) if (err) return err; + netif_addr_lock_bh(mucse->netdev); + err = rnpgbe_set_rx_mode(mucse->netdev, &mucse->netdev->uc, + &mucse->netdev->mc); + netif_addr_unlock_bh(mucse->netdev); + if (err) + return err; + return rnpgbe_configure_rx(mucse); } @@ -140,10 +147,11 @@ static netdev_tx_t rnpgbe_xmit_frame(struct sk_buff *skb, } static const struct net_device_ops rnpgbe_netdev_ops = { - .ndo_open = rnpgbe_open, - .ndo_stop = rnpgbe_close, - .ndo_start_xmit = rnpgbe_xmit_frame, - .ndo_get_stats64 = rnpgbe_get_stats64, + .ndo_open = rnpgbe_open, + .ndo_stop = rnpgbe_close, + .ndo_start_xmit = rnpgbe_xmit_frame, + .ndo_set_rx_mode_async = rnpgbe_set_rx_mode, + .ndo_get_stats64 = rnpgbe_get_stats64, }; static void rnpgbe_sw_init(struct mucse *mucse) @@ -234,6 +242,7 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev, } netdev->netdev_ops = &rnpgbe_netdev_ops; + netdev->priv_flags |= IFF_UNICAST_FLT; rnpgbe_sw_init(mucse); err = rnpgbe_reset_hw(hw); if (err) { From 92a671d510a823b86bbbe6c31fdb29eda85faba8 Mon Sep 17 00:00:00 2001 From: Dong Yibo Date: Tue, 13 Oct 2026 10:31:09 +0800 Subject: [PATCH 1923/2126] net: rnpgbe: Add link status handling support Add link status handling for the RNPGBE driver. Introduce link state data structures for speed, duplex and link state, and process firmware link events delivered over the mailbox, since firmware controls the link and phylink is not used. Add a service task to handle pending events and manage carrier status with netif_carrier_on()/netif_carrier_off(). Notify firmware when the interface is brought up and after the data path is quiesced during teardown, and fail interface open if the firmware port-up or link-report setup fails. Validate firmware link events before updating the cached link state. Enable the GMAC receiver in receive-all mode after the chip-level receive filter has been configured, and document the driver-to-firmware link-state snapshot and reset semantics. Configure firmware after reset to enable autonegotiation. Advertise 10/100Mb/s half- and full-duplex modes and 1000 Mb/s full-duplex mode. Fail probe if firmware does not acknowledge the link setup command. Signed-off-by: Dong Yibo Link: https://patch.msgid.link/C41AE78496D9DC2B+20261013023109.63764-1-dong100@mucse.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 19 +- .../net/ethernet/mucse/rnpgbe/rnpgbe_chip.c | 63 +++- drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h | 17 ++ .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.c | 172 ++++++++++- .../net/ethernet/mucse/rnpgbe/rnpgbe_lib.h | 3 +- .../net/ethernet/mucse/rnpgbe/rnpgbe_main.c | 20 +- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 167 ++++++++++- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 4 + .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 278 +++++++++++++++++- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 59 ++++ 10 files changed, 790 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h index 6f71055f180e..4e9776b28bfb 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h @@ -5,6 +5,7 @@ #define _RNPGBE_H #include +#include #include #include #include @@ -32,11 +33,10 @@ struct mucse_mbx_info { u32 fwpf_ctrl_base; }; -/* Enum for firmware notification modes, - * more modes (e.g., portup, link_report) will be added in future - **/ enum { mucse_fw_powerup, + mucse_fw_portup, + mucse_fw_link_report_en, }; struct mucse_hw { @@ -45,8 +45,11 @@ struct mucse_hw { struct pci_dev *pdev; struct mucse_mbx_info mbx; int port; + int speed; + bool link; u16 cycles_per_us; u8 pfvfnum; + u8 duplex; }; struct rnpgbe_tx_desc { @@ -230,12 +233,21 @@ struct mucse { int num_rx_queues; char mbx_name[32]; bool mbx_irq_requested; + bool link_event_ready; + bool link_pending; unsigned long state; + atomic_t mbx_irq_seq; struct work_struct mbx_work; + struct delayed_work serv_task; + /* Protects event readiness, pending state, cached link state and + * driver-side link register updates. + */ + spinlock_t link_lock; }; int rnpgbe_get_permanent_mac(struct mucse_hw *hw, u8 *perm_addr); int rnpgbe_reset_hw(struct mucse_hw *hw); +int rnpgbe_setup_default_link(struct mucse_hw *hw); int rnpgbe_send_notify(struct mucse_hw *hw, bool enable, int mode); @@ -243,6 +255,7 @@ int rnpgbe_init_hw(struct mucse_hw *hw, int board_type); int rnpgbe_set_rx_mode(struct net_device *netdev, struct netdev_hw_addr_list *uc, struct netdev_hw_addr_list *mc); +void rnpgbe_set_link(struct mucse_hw *hw, bool linkup); /* Device IDs */ #define PCI_VENDOR_ID_MUCSE 0x8848 diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c index 79d66187d044..dcc8233e024e 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c @@ -4,12 +4,19 @@ #include #include #include +#include #include "rnpgbe.h" #include "rnpgbe_hw.h" #include "rnpgbe_mbx.h" #include "rnpgbe_mbx_fw.h" +#define RNPGBE_DEFAULT_ADV (RNPGBE_FW_ADV_10_FULL | \ + RNPGBE_FW_ADV_100_FULL | \ + RNPGBE_FW_ADV_1000_FULL | \ + RNPGBE_FW_ADV_10_HALF | \ + RNPGBE_FW_ADV_100_HALF) + /** * rnpgbe_get_permanent_mac - Get permanent mac * @hw: hw information structure @@ -53,6 +60,18 @@ int rnpgbe_reset_hw(struct mucse_hw *hw) return mucse_mbx_reset_hw(hw); } +/** + * rnpgbe_setup_default_link - Configure the default link settings + * @hw: hardware information structure + * + * Return: 0 on success, negative errno on failure + **/ +int rnpgbe_setup_default_link(struct mucse_hw *hw) +{ + return mucse_mbx_set_link(hw, RNPGBE_DEFAULT_ADV, true, 0, 0, + ETH_TP_MDI_AUTO); +} + /** * rnpgbe_send_notify - Echo fw status * @hw: hw information structure @@ -66,11 +85,17 @@ int rnpgbe_send_notify(struct mucse_hw *hw, int mode) { int err; - /* Keep switch struct to support more modes in the future */ + switch (mode) { case mucse_fw_powerup: err = mucse_mbx_powerup(hw, enable); break; + case mucse_fw_portup: + err = mucse_mbx_phyup(hw, enable); + break; + case mucse_fw_link_report_en: + err = mucse_mbx_link_report(hw, enable); + break; default: err = -EINVAL; } @@ -245,3 +270,39 @@ int rnpgbe_set_rx_mode(struct net_device *netdev, return 0; } + +/** + * rnpgbe_set_link - Set the hardware link state + * @hw: hw information structure + * @linkup: link on or not + * + * Apply the firmware-reported link state to the GMAC. This helper is only + * called while processing a firmware link event. The caller must hold the + * containing struct mucse's link_lock. + * Firmware updates the speed and duplex fields before posting a link event + * and waits for the PF acknowledgment, so event handling completes this + * read-modify-write before firmware accesses GMAC_CONTROL again. + * + **/ +void rnpgbe_set_link(struct mucse_hw *hw, bool linkup) +{ + struct mucse *mucse = container_of(hw, struct mucse, hw); + u32 value; + + lockdep_assert_held(&mucse->link_lock); + value = mucse_hw_rd32(hw, GMAC_CONTROL); + + /* ndo_set_rx_mode_async() programs the chip-level filter. Keep the GMAC + * in receive-all mode so it does not discard frames accepted by that + * filter. + */ + if (linkup) { + mucse_hw_wr32(hw, GMAC_FRAME_FILTER, GMAC_RX_ALL); + value |= GMAC_CONTROL_RE; + mucse_hw_wr32(hw, GMAC_CONTROL, value); + } else { + value &= ~GMAC_CONTROL_RE; + mucse_hw_wr32(hw, GMAC_CONTROL, value); + mucse_hw_wr32(hw, GMAC_FRAME_FILTER, 0); + } +} diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h index 3f103f93ac30..674d4d23c4b0 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_hw.h @@ -23,6 +23,17 @@ #define RNPGBE_DMA_TX_STATUS GENMASK_U32(23, 22) #define RNPGBE_DMA_RX_STATUS GENMASK_U32(21, 20) #define RX_AXI_RW_EN 0x03 +/* RNPGBE_LINK_ST is a driver-owned link-state snapshot consumed by firmware. + * Set the driver-state marker; all other driver status fields start clear. + */ +#define M_DEFAULT_ST 0xa0000000 +/* Firmware never reports 0xf in the speed field. */ +#define M_INVALID_ST (M_DEFAULT_ST | GENMASK_U32(11, 8)) +/* Driver-reported fields: 25:24 pause, 11:8 speed, 6 LLDP, 4 duplex, + * and 0 link up/down. M_DEFAULT_ST resets these fields so firmware reports + * the current hardware state again. + */ +#define RNPGBE_LINK_ST 0x000c #define RNPGBE_DMA_AXI_EN 0x0010 #define RNPGBE_TX_MIN_PKT_LEN 33 @@ -41,5 +52,11 @@ /* The final two of the 32 hardware RAR entries are reserved for NCSI. */ #define RNPGBE_RX_RAR_ENTRIES 30 #define RNPGBE_RX_MCAST_HASH_ENTRIES 128 + +#define MUCSE_GMAC_OFF(_n) (0x20000 + (_n)) +#define GMAC_CONTROL_RE 0x00000004 +#define GMAC_CONTROL MUCSE_GMAC_OFF(0) +#define GMAC_RX_ALL (BIT(31) | BIT(0)) +#define GMAC_FRAME_FILTER MUCSE_GMAC_OFF(0x4) #define RNPGBE_MAX_QUEUES 8 #endif /* _RNPGBE_HW_H */ diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c index 22fe284729f2..b7b0c45a0f66 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c @@ -16,8 +16,14 @@ static void rnpgbe_mbx_work(struct work_struct *work) { struct mucse *mucse = container_of(work, struct mucse, mbx_work); + int irq_seq; + irq_seq = atomic_read(&mucse->mbx_irq_seq); mucse_fw_irq_handler(&mucse->hw); + + /* A mailbox interrupt while this work runs needs another invocation. */ + if (irq_seq != atomic_read(&mucse->mbx_irq_seq)) + queue_work(system_percpu_wq, &mucse->mbx_work); } /** @@ -31,6 +37,7 @@ static irqreturn_t rnpgbe_msix_other(int irq, void *data) { struct mucse *mucse = (struct mucse *)data; + atomic_inc(&mucse->mbx_irq_seq); queue_work(system_percpu_wq, &mucse->mbx_work); return IRQ_HANDLED; @@ -700,6 +707,7 @@ int rnpgbe_request_mbx_irq(struct mucse *mucse) snprintf(mucse->mbx_name, sizeof(mucse->mbx_name), "rnpgbe-mbx:%s", pci_name(pdev)); INIT_WORK(&mucse->mbx_work, rnpgbe_mbx_work); + atomic_set(&mucse->mbx_irq_seq, 0); err = request_irq(pci_irq_vector(pdev, 0), rnpgbe_msix_other, 0, mucse->mbx_name, mucse); @@ -722,6 +730,7 @@ void rnpgbe_free_mbx_irq(struct mucse *mucse) free_irq(pci_irq_vector(pdev, 0), mucse); cancel_work_sync(&mucse->mbx_work); } + cancel_delayed_work_sync(&mucse->serv_task); } /** @@ -1442,7 +1451,20 @@ static void rnpgbe_cancel_rx_retry_timers(struct mucse *mucse) void rnpgbe_down(struct mucse *mucse) { struct net_device *netdev = mucse->netdev; + struct mucse_hw *hw = &mucse->hw; + unsigned long flags; + int err; + spin_lock_irqsave(&mucse->link_lock, flags); + mucse->link_event_ready = false; + mucse->link_pending = false; + hw->link = false; + hw->speed = 0; + hw->duplex = 0; + spin_unlock_irqrestore(&mucse->link_lock, flags); + cancel_delayed_work_sync(&mucse->serv_task); + + netif_carrier_off(netdev); rnpgbe_irq_disable(mucse); rnpgbe_napi_disable_all(mucse); synchronize_net(); @@ -1451,22 +1473,75 @@ void rnpgbe_down(struct mucse *mucse) rnpgbe_stop_all_rx_rings(mucse); rnpgbe_cancel_rx_retry_timers(mucse); rnpgbe_clean_all_tx_rings(mucse); + + err = rnpgbe_send_notify(hw, false, mucse_fw_link_report_en); + if (err) { + dev_warn(&hw->pdev->dev, "Send link report to hw failed %d\n", + err); + dev_warn(&hw->pdev->dev, "Fw will still report link event\n"); + } + + /* Firmware owns GMAC_CONTROL_RE and clears it while processing + * port-down. RX DMA is already quiesced, so no local GMAC update is + * needed before freeing the RX buffers. + */ + err = rnpgbe_send_notify(hw, false, mucse_fw_portup); + if (err) { + dev_warn(&hw->pdev->dev, "Send port down to hw failed %d\n", + err); + dev_warn(&hw->pdev->dev, "Port is not truly down\n"); + } rnpgbe_clean_all_rx_rings(mucse); } /** * rnpgbe_up_complete - Final step for port up * @mucse: pointer to private structure + * + * Return: 0 on success, negative errno if firmware setup fails **/ -void rnpgbe_up_complete(struct mucse *mucse) +int rnpgbe_up_complete(struct mucse *mucse) { struct net_device *netdev = mucse->netdev; + struct mucse_hw *hw = &mucse->hw; + unsigned long flags; + int err; rnpgbe_configure_msix(mucse); rnpgbe_napi_enable_all(mucse); rnpgbe_schedule_rx_retry(mucse); rnpgbe_irq_enable(mucse); netif_tx_start_all_queues(netdev); + err = rnpgbe_send_notify(hw, true, mucse_fw_portup); + if (err) { + dev_err(&hw->pdev->dev, + "Failed to notify firmware that port is up: %d\n", err); + return err; + } + /* Open link-event handling only after the data path is ready. Reset + * the snapshot at the same time so firmware reports the current state. + */ + spin_lock_irqsave(&mucse->link_lock, flags); + mucse->link_pending = false; + hw->link = false; + hw->speed = 0; + hw->duplex = 0; + mucse_hw_wr32(hw, RNPGBE_LINK_ST, M_DEFAULT_ST); + mucse->link_event_ready = true; + spin_unlock_irqrestore(&mucse->link_lock, flags); + /* Firmware checks RNPGBE_LINK_ST (driver's last-received link state) + * and only asserts LINK_CHANGE_EVT when it differs from the actual link + * state AND link_report_en is true. + */ + err = rnpgbe_send_notify(hw, true, mucse_fw_link_report_en); + if (err) { + dev_err(&hw->pdev->dev, + "Failed to enable firmware link reporting: %d\n", + err); + return err; + } + + return 0; } /** @@ -2090,3 +2165,98 @@ int rnpgbe_configure_rx(struct mucse *mucse) return 0; } + +/** + * rnpgbe_process_link_event - Consume a pending link event + * @mucse: pointer to the device private structure + * @link: link status snapshot + * @speed: link speed snapshot + * @duplex: link duplex snapshot + * + * Return: true if a link event was consumed, false otherwise + **/ +static bool rnpgbe_process_link_event(struct mucse *mucse, bool *link, + int *speed, u8 *duplex) +{ + struct mucse_hw *hw = &mucse->hw; + unsigned long flags; + + spin_lock_irqsave(&mucse->link_lock, flags); + if (!mucse->link_event_ready || !mucse->link_pending) { + spin_unlock_irqrestore(&mucse->link_lock, flags); + return false; + } + mucse->link_pending = false; + *link = hw->link; + *speed = hw->speed; + *duplex = hw->duplex; + spin_unlock_irqrestore(&mucse->link_lock, flags); + + return true; +} + +/** + * rnpgbe_link_is_up - Update netif_carrier status and + * print link up message + * @mucse: pointer to the device private structure + * @speed: link speed snapshot + * @duplex: link duplex snapshot + **/ +static void rnpgbe_link_is_up(struct mucse *mucse, int speed, u8 duplex) +{ + struct net_device *netdev = mucse->netdev; + + /* Only continue if link was previously down */ + if (netif_carrier_ok(netdev)) + return; + + netdev_info(netdev, "NIC Link is Up %d Mbps, %s Duplex\n", + speed, duplex ? "Full" : "Half"); + netif_carrier_on(netdev); +} + +/** + * rnpgbe_link_is_down - Update netif_carrier status and + * print link down message + * @mucse: pointer to the private structure + **/ +static void rnpgbe_link_is_down(struct mucse *mucse) +{ + struct net_device *netdev = mucse->netdev; + + /* Only continue if link was up previously */ + if (!netif_carrier_ok(netdev)) + return; + netdev_info(netdev, "NIC Link is Down\n"); + netif_carrier_off(netdev); +} + +/** + * rnpgbe_process_link_subtask - Process a link-state update + * @mucse: pointer to the device private structure + **/ +static void rnpgbe_process_link_subtask(struct mucse *mucse) +{ + bool link; + int speed; + u8 duplex; + + if (!rnpgbe_process_link_event(mucse, &link, &speed, &duplex)) + return; + + if (link) + rnpgbe_link_is_up(mucse, speed, duplex); + else + rnpgbe_link_is_down(mucse); +} + +/** + * rnpgbe_service_task - Manages and runs subtasks + * @work: pointer to work_struct containing our data + **/ +void rnpgbe_service_task(struct work_struct *work) +{ + struct mucse *mucse = container_of(work, struct mucse, serv_task.work); + + rnpgbe_process_link_subtask(mucse); +} diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h index 072993494deb..8ebaa9534dac 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.h @@ -72,7 +72,7 @@ void rnpgbe_free_mbx_irq(struct mucse *mucse); int rnpgbe_request_irq(struct mucse *mucse); void rnpgbe_free_irq(struct mucse *mucse); void rnpgbe_down(struct mucse *mucse); -void rnpgbe_up_complete(struct mucse *mucse); +int rnpgbe_up_complete(struct mucse *mucse); int rnpgbe_configure_tx(struct mucse *mucse); int rnpgbe_configure_rx(struct mucse *mucse); void rnpgbe_clean_all_tx_rings(struct mucse *mucse); @@ -84,4 +84,5 @@ void rnpgbe_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats); int rnpgbe_setup_all_rx_resources(struct mucse *mucse); void rnpgbe_free_all_rx_resources(struct mucse *mucse); +void rnpgbe_service_task(struct work_struct *work); #endif diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c index 8e1eebf32723..708a7297233e 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c @@ -70,6 +70,7 @@ static int rnpgbe_open(struct net_device *netdev) if (test_bit(__MUCSE_AXI_FAULT, &mucse->state)) return -EIO; + netif_carrier_off(netdev); err = rnpgbe_request_irq(mucse); if (err) return err; @@ -89,9 +90,16 @@ static int rnpgbe_open(struct net_device *netdev) err = rnpgbe_configure(mucse); if (err) goto err_free_rx; - rnpgbe_up_complete(mucse); + err = rnpgbe_up_complete(mucse); + if (err) + goto err_down; return 0; +err_down: + rnpgbe_down(mucse); + rnpgbe_free_all_rx_resources(mucse); + rnpgbe_free_all_tx_resources(mucse); + goto err_free_irqs; err_free_rx: rnpgbe_free_all_rx_resources(mucse); err_free_tx: @@ -249,6 +257,11 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev, dev_err(&pdev->dev, "Hw reset failed %d\n", err); goto err_powerdown; } + err = rnpgbe_setup_default_link(hw); + if (err) { + dev_err(&pdev->dev, "Setup link failed %d\n", err); + goto err_powerdown; + } err = rnpgbe_get_permanent_mac(hw, perm_addr); if (!err) { @@ -261,6 +274,11 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev, goto err_powerdown; } + INIT_DELAYED_WORK(&mucse->serv_task, rnpgbe_service_task); + spin_lock_init(&mucse->link_lock); + mucse->link_event_ready = false; + mucse->link_pending = false; + err = rnpgbe_init_interrupt_scheme(mucse); if (err) { dev_err(&pdev->dev, "init interrupt failed %d\n", err); diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c index 2310f01df1f5..ef00b948ad0f 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c @@ -197,7 +197,8 @@ static int mucse_read_mbx_pf(struct mucse_hw *hw, __le32 *msg, u16 size) * mucse_check_for_msg_pf - Check to see if the fw has sent mail * @hw: pointer to the HW structure * - * Return: 0 if the fw has set the Status bit or else -EIO + * Return: 0 if firmware has posted a new message, -ENOMSG if there is no + * new message, or -EIO if the mailbox has been reset **/ static int mucse_check_for_msg_pf(struct mucse_hw *hw) { @@ -209,8 +210,13 @@ static int mucse_check_for_msg_pf(struct mucse_hw *hw) * mbx command. Return -EIO if in this state, others * fw == hw->mbx.fw_req means no new msg. **/ - if (fw_req == 0 || fw_req == hw->mbx.fw_req) + /* Firmware skips zero for valid FW-to-PF requests and wraps the + * counter from U16_MAX to 1. + **/ + if (!fw_req) return -EIO; + if (fw_req == hw->mbx.fw_req) + return -ENOMSG; return 0; } @@ -252,6 +258,68 @@ int mucse_poll_and_read_mbx(struct mucse_hw *hw, __le32 *msg, u16 size) return mucse_read_mbx_pf(hw, msg, size); } +/** + * mucse_mbx_event_begin - Lock and read a pending firmware event + * @hw: pointer to the HW structure + * @msg: the message buffer + * @size: length of buffer + * + * On success the hardware mailbox remains locked. The caller must process + * the event and call mucse_mbx_event_end() to acknowledge it and release + * the hardware mailbox lock. + * + * Firmware releases the hardware mailbox lock before raising the event + * interrupt and does not access the shared window again until the PF + * acknowledges the event. Therefore, failure to acquire the lock indicates + * a mailbox fault rather than transient contention. + * + * Return: 0 on success, -ENOMSG if no event is pending, or another negative + * errno on failure + **/ +int mucse_mbx_event_begin(struct mucse_hw *hw, __le32 *msg, u16 size) +{ + const int size_in_words = size / sizeof(__le32); + struct mucse_mbx_info *mbx = &hw->mbx; + int off = MUCSE_MBX_FWPF_SHM; + int err; + + err = mucse_check_for_msg_pf(hw); + if (err) + return err; + + err = mucse_obtain_mbx_lock_pf(hw); + if (err) + return err; + + /* Check again after taking ownership of the shared mailbox. */ + err = mucse_check_for_msg_pf(hw); + if (err) { + mucse_release_mbx_lock_pf(hw, false); + return err; + } + + for (int i = 0; i < size_in_words; i++) + msg[i] = cpu_to_le32(mbx_data_rd32(mbx, off + 4 * i)); + + return 0; +} + +/** + * mucse_mbx_event_end - Acknowledge a firmware event and unlock the mailbox + * @hw: pointer to the HW structure + * + * Pair with a successful mucse_mbx_event_begin(). + **/ +void mucse_mbx_event_end(struct mucse_hw *hw) +{ + struct mucse_mbx_info *mbx = &hw->mbx; + + mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM, 0); + hw->mbx.fw_req = mucse_mbx_get_fwreq(mbx); + mucse_mbx_inc_pf_ack(hw); + mucse_release_mbx_lock_pf(hw, false); +} + /** * mucse_mbx_get_fwack - Read fw ack from reg * @mbx: pointer to the MBX structure @@ -286,6 +354,36 @@ static void mucse_mbx_inc_pf_req(struct mucse_hw *hw) mbx_data_wr32(mbx, MUCSE_MBX_PF2FW_CNT, val); } +/** + * mucse_ack_pending_event - Acknowledge a level-like firmware event + * @hw: pointer to the HW structure + * + * The caller must own the hardware mailbox lock. + * + * Return: 0 on success, negative errno on failure + **/ +static int mucse_ack_pending_event(struct mucse_hw *hw) +{ + struct mucse_mbx_info *mbx = &hw->mbx; + u16 fw_req; + + fw_req = mucse_mbx_get_fwreq(mbx); + if (fw_req == hw->mbx.fw_req) + return 0; + if (!fw_req) + return -EIO; + + /* Firmware only posts LINK_CHANGE_EVT asynchronously. It is level-like, + * so leaving the link snapshot unchanged lets firmware report the + * current state again if reporting stays enabled. + */ + mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM, 0); + hw->mbx.fw_req = fw_req; + mucse_mbx_inc_pf_ack(hw); + + return 0; +} + /** * mucse_write_mbx_pf - Place a message in the mailbox * @hw: pointer to the HW structure @@ -320,6 +418,44 @@ static int mucse_write_mbx_pf(struct mucse_hw *hw, const __le32 *msg, u16 size) return 0; } +/** + * mucse_write_mbx_pf_coalesce_event - Write around a level-like event + * @hw: pointer to the HW structure + * @msg: the message buffer + * @size: length of buffer + * + * Return: 0 on success, negative errno on failure + **/ +static int mucse_write_mbx_pf_coalesce_event(struct mucse_hw *hw, + const __le32 *msg, u16 size) +{ + const int size_in_words = size / sizeof(__le32); + struct mucse_mbx_info *mbx = &hw->mbx; + int err; + + err = mucse_obtain_mbx_lock_pf(hw); + if (err) + return err; + + err = mucse_ack_pending_event(hw); + if (err) + goto release; + + for (int i = 0; i < size_in_words; i++) + mbx_data_wr32(mbx, MUCSE_MBX_FWPF_SHM + i * 4, + le32_to_cpu(msg[i])); + + hw->mbx.fw_ack = mucse_mbx_get_fwack(mbx); + mucse_mbx_inc_pf_req(hw); + mucse_release_mbx_lock_pf(hw, true); + + return 0; + +release: + mucse_release_mbx_lock_pf(hw, false); + return err; +} + /** * mucse_check_for_ack_pf - Check to see if the fw has ACKed * @hw: pointer to the HW structure @@ -381,6 +517,33 @@ int mucse_write_and_wait_ack_mbx(struct mucse_hw *hw, const __le32 *msg, return mucse_poll_for_ack(hw); } +/** + * mucse_write_mbx_coalesce_event - Send a command while coalescing an event + * @hw: pointer to the HW structure + * @msg: the message buffer + * @size: length of buffer + * + * A pending link event is acknowledged without updating its snapshot, then + * the PF command is written while the hardware mailbox remains locked. If + * event reporting remains enabled, firmware reports the event again because + * its snapshot still differs from the hardware state. This function waits + * for firmware to acknowledge the PF command before returning. + * + * Return: 0 after firmware acknowledges the command, negative errno on + * failure + **/ +int mucse_write_mbx_coalesce_event(struct mucse_hw *hw, + const __le32 *msg, u16 size) +{ + int err; + + err = mucse_write_mbx_pf_coalesce_event(hw, msg, size); + if (err) + return err; + + return mucse_poll_for_ack(hw); +} + /** * mucse_mbx_reset - Reset mbx info, sync info from regs * @hw: pointer to the HW structure diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h index 75b88b18b04d..50597dd9dde9 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h @@ -16,6 +16,10 @@ int mucse_write_and_wait_ack_mbx(struct mucse_hw *hw, const __le32 *msg, u16 size); +int mucse_write_mbx_coalesce_event(struct mucse_hw *hw, + const __le32 *msg, u16 size); void mucse_init_mbx_params_pf(struct mucse_hw *hw); int mucse_poll_and_read_mbx(struct mucse_hw *hw, __le32 *msg, u16 size); +int mucse_mbx_event_begin(struct mucse_hw *hw, __le32 *msg, u16 size); +void mucse_mbx_event_end(struct mucse_hw *hw); #endif /* _RNPGBE_MBX_H */ diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c index e28f3193aa85..683e0ea74113 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c @@ -3,6 +3,7 @@ #include #include +#include #include "rnpgbe.h" #include "rnpgbe_mbx.h" @@ -199,12 +200,283 @@ int mucse_mbx_get_macaddr(struct mucse_hw *hw, int pfvfnum, } /** - * mucse_fw_irq_handler - Deferred firmware mailbox notification hook + * mucse_mbx_set_link - Configure firmware link settings + * @hw: pointer to the HW structure + * @advertising: firmware link-mode advertisement mask + * @autoneg: whether to enable autonegotiation + * @speed: forced link speed when autonegotiation is disabled + * @duplex: forced duplex mode when autonegotiation is disabled + * @mdix_ctrl: MDI/MDI-X control mode + * + * Firmware ignores @speed, @duplex when @autoneg is true. + * + * Return: 0 on success, negative errno on failure + **/ +int mucse_mbx_set_link(struct mucse_hw *hw, u32 advertising, bool autoneg, + u32 speed, u32 duplex, u32 mdix_ctrl) +{ + union mbx_fw_cmd_req_u req = { + .r = { + .datalen = cpu_to_le16(sizeof(req.r.phy_link_set) + + MUCSE_MBX_REQ_HDR_LEN), + .opcode = cpu_to_le16(PHY_LINK_SET), + .phy_link_set = { + .adv_speed_mask = cpu_to_le32(advertising), + .autoneg = cpu_to_le32(autoneg), + .speed = cpu_to_le32(speed), + .duplex = cpu_to_le32(duplex), + .nr_lane = cpu_to_le32(hw->port), + .tp_mdix_ctrl = cpu_to_le32(mdix_ctrl), + }, + }, + }; + int len, err; + + len = le16_to_cpu(req.r.datalen); + mutex_lock(&hw->mbx.lock); + err = mucse_write_and_wait_ack_mbx(hw, req.dwords, len); + mutex_unlock(&hw->mbx.lock); + + return err; +} + +/** + * mucse_mbx_phyup - Request that firmware bring the PHY up or down + * @hw: pointer to the HW structure + * @is_phyup: true for up, false for down + * + * mucse_mbx_phyup echo fw to change phy status + * + * Return: 0 on success, negative errno on failure + **/ +int mucse_mbx_phyup(struct mucse_hw *hw, bool is_phyup) +{ + union mbx_fw_cmd_req_u req = { + .r = { + .datalen = cpu_to_le16(sizeof(req.r.phy_status) + + MUCSE_MBX_REQ_HDR_LEN), + .opcode = cpu_to_le16(SET_PHY_UP), + .phy_status = { + .port_mask = cpu_to_le32(BIT(hw->port)), + .status = cpu_to_le32(is_phyup ? 1 : 0), + }, + }, + }; + int len, err; + + len = le16_to_cpu(req.r.datalen); + mutex_lock(&hw->mbx.lock); + err = mucse_write_mbx_coalesce_event(hw, req.dwords, len); + mutex_unlock(&hw->mbx.lock); + + return err; +} + +/** + * mucse_mbx_link_report - Configure firmware link-change event reporting + * @hw: pointer to the HW structure + * @is_report: true for report, false for no + * + * mucse_mbx_link_report echo fw to change event report state + * + * Return: 0 on success, negative errno on failure + **/ +int mucse_mbx_link_report(struct mucse_hw *hw, bool is_report) +{ + union mbx_fw_cmd_req_u req = { + .r = { + .datalen = cpu_to_le16(sizeof(req.r.report_status) + + MUCSE_MBX_REQ_HDR_LEN), + .opcode = cpu_to_le16(LINK_REPORT_EN), + .report_status = { + .port_mask = cpu_to_le16(BIT(hw->port)), + .status = cpu_to_le16(is_report ? 1 : 0), + }, + }, + }; + int len, err; + + len = le16_to_cpu(req.r.datalen); + mutex_lock(&hw->mbx.lock); + err = mucse_write_mbx_coalesce_event(hw, req.dwords, len); + mutex_unlock(&hw->mbx.lock); + + return err; +} + +static bool mucse_link_speed_valid(const struct mbx_fw_cmd_req *req) +{ + switch (le16_to_cpu(req->link_stat.st.speed)) { + case 10: + case 100: + case 1000: + return true; + default: + return false; + } +} + +static bool mucse_link_is_up(const struct mucse_hw *hw, + const struct mbx_fw_cmd_req *req) +{ + return le16_to_cpu(req->link_stat.port_status) & BIT(hw->port); +} + +/** + * mucse_update_link_status_reg - update driver speed inf to reg + * @hw: pointer to the HW structure + * @req: pointer to req data + * + * Update the driver's link-state snapshot exported to firmware. Firmware + * sends a new event when this snapshot differs from the hardware state. + * The default snapshot clears the driver-reported fields; + * a valid event then repopulates them, including the LLDP status in bit 6. + * + **/ +static void mucse_update_link_status_reg(struct mucse_hw *hw, + struct mbx_fw_cmd_req *req) +{ + u16 status = le16_to_cpu(req->link_stat.st.status); + u16 speed = le16_to_cpu(req->link_stat.st.speed); + u32 value; + + value = M_DEFAULT_ST; + + if (mucse_link_is_up(hw, req)) { + value |= BIT(0); + switch (speed) { + case 10: + value |= (mucse_speed_10 << 8); + break; + case 100: + value |= (mucse_speed_100 << 8); + break; + case 1000: + value |= (mucse_speed_1000 << 8); + break; + default: + break; + } + + value |= FIELD_PREP(BIT(4), + !!(req->link_stat.st.flags & DUPLEX_BIT)); + value |= FIELD_PREP(GENMASK_U32(25, 24), + status & GENMASK(1, 0)); + } else { + value &= ~BIT(0); + } + + if (status & ST_STATUS_LLDP_STATUS_MASK) + value |= BIT(6); + else + value &= ~BIT(6); + + mucse_hw_wr32(hw, RNPGBE_LINK_ST, value); +} + +/** + * mucse_mbx_fw_req_handler - Handle fw req + * @hw: pointer to the HW structure + * @req: pointer to req data + * + * mucse_mbx_fw_req_handler handler fw req, such as a link event req. + **/ +static void mucse_mbx_fw_req_handler(struct mucse_hw *hw, + struct mbx_fw_cmd_req *req) +{ + struct mucse *mucse = container_of(hw, struct mucse, hw); + u32 magic = le32_to_cpu(req->link_stat.port_magic); + unsigned long flags; + + if (le16_to_cpu(req->opcode) == LINK_CHANGE_EVT) { + u16 speed = le16_to_cpu(req->link_stat.st.speed); + + spin_lock_irqsave(&mucse->link_lock, flags); + if (magic != ST_VALID_MAGIC) { + /* Do not change the cached state for an invalid event. + * Use an invalid speed encoding to make firmware report + * again. + */ + mucse_hw_wr32(hw, RNPGBE_LINK_ST, M_INVALID_ST); + spin_unlock_irqrestore(&mucse->link_lock, flags); + return; + } + + if (mucse_link_is_up(hw, req) && + !mucse_link_speed_valid(req)) { + /* Do not acknowledge an invalid speed as valid. + * Keep the snapshot mismatched so firmware retries it. + * Firmware limits link reports to one per 500 ms. + */ + mucse_hw_wr32(hw, RNPGBE_LINK_ST, M_INVALID_ST); + spin_unlock_irqrestore(&mucse->link_lock, flags); + dev_warn_ratelimited(&hw->pdev->dev, + "unsupported link speed %u Mbps\n", + speed); + return; + } + + if (!mucse->link_event_ready) { + rnpgbe_set_link(hw, false); + mucse_update_link_status_reg(hw, req); + spin_unlock_irqrestore(&mucse->link_lock, flags); + return; + } + + if (mucse_link_is_up(hw, req)) + hw->link = true; + else + hw->link = false; + + hw->speed = le16_to_cpu(req->link_stat.st.speed); + hw->duplex = req->link_stat.st.flags & DUPLEX_BIT; + rnpgbe_set_link(hw, mucse_link_is_up(hw, req)); + /* update regs to notify link info is received */ + mucse_update_link_status_reg(hw, req); + mucse->link_pending = true; + /* Run link handling immediately. */ + mod_delayed_work(system_percpu_wq, &mucse->serv_task, 0); + spin_unlock_irqrestore(&mucse->link_lock, flags); + } +} + +/** + * mucse_fw_handle_event - Handle one pending firmware event + * @hw: pointer to the hardware structure + **/ +static void mucse_fw_handle_event(struct mucse_hw *hw) +{ + union mbx_fw_cmd_req_u msg = {}; + int err; + + /* try to check and read fw req */ + mutex_lock(&hw->mbx.lock); + err = mucse_mbx_event_begin(hw, msg.dwords, sizeof(msg)); + /* A PF command may have coalesced the event before stale mailbox work + * runs, in which case there is no event left to handle. + */ + if (err) { + mutex_unlock(&hw->mbx.lock); + if (err != -ENOMSG) + dev_warn_ratelimited(&hw->pdev->dev, + "failed to read firmware event: %d\n", + err); + return; + } + + mucse_mbx_fw_req_handler(hw, &msg.r); + mucse_mbx_event_end(hw); + mutex_unlock(&hw->mbx.lock); +} + +/** + * mucse_fw_irq_handler - Handle one pending firmware mailbox event * @hw: pointer to the HW structure * - * No asynchronous firmware events are enabled until link status support is - * added. + * Process at most one event per work-item invocation. The caller requeues + * mailbox work when a dedicated mailbox interrupt arrives during handling. **/ void mucse_fw_irq_handler(struct mucse_hw *hw) { + mucse_fw_handle_event(hw); } diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h index a6bf5de55aa3..93ce0e796442 100644 --- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h @@ -14,9 +14,19 @@ enum MUCSE_FW_CMD { GET_HW_INFO = 0x0601, GET_MAC_ADDRESS = 0x0602, RESET_HW = 0x0603, + LINK_CHANGE_EVT = 0x0608, + LINK_REPORT_EN = 0x0613, + PHY_LINK_SET = 0x0630, + SET_PHY_UP = 0x0800, POWER_UP = 0x0803, }; +#define RNPGBE_FW_ADV_10_FULL BIT(2) +#define RNPGBE_FW_ADV_100_FULL BIT(3) +#define RNPGBE_FW_ADV_1000_FULL BIT(4) +#define RNPGBE_FW_ADV_10_HALF BIT(10) +#define RNPGBE_FW_ADV_100_HALF BIT(11) + struct mucse_hw_info { u8 link_stat; u8 port_mask; @@ -36,6 +46,16 @@ struct mucse_hw_info { __le32 ext_info; } __packed; +#define ST_STATUS_LLDP_STATUS_MASK BIT(12) + +#define DUPLEX_BIT BIT(0) +struct st_status { + u8 phyid; + u8 flags; + __le16 speed; + __le16 status; +} __packed; + struct mbx_fw_cmd_req { __le16 flags; __le16 opcode; @@ -55,6 +75,32 @@ struct mbx_fw_cmd_req { __le32 port_mask; __le32 pfvf_num; } get_mac_addr; + struct { + __le32 port_mask; + __le32 status; + } phy_status; + struct { + __le32 adv_speed_mask; + __le32 autoneg; + __le32 speed; + __le32 duplex; + __le32 nr_lane; + __le32 tp_mdix_ctrl; + } phy_link_set; + struct { + /* LINK_REPORT_EN uses its own 16-bit payload layout: + * status precedes port_mask. + */ + __le16 status; + __le16 port_mask; + } report_status; + struct { + __le16 changed_lanes; + __le16 port_status; + __le32 port_magic; +#define ST_VALID_MAGIC 0xa4a6a8a9 + struct st_status st; + } link_stat; }; } __packed; @@ -94,10 +140,23 @@ union mbx_fw_cmd_reply_u { __le32 dwords[sizeof(struct mbx_fw_cmd_reply) / sizeof(__le32)]; }; +/* Firmware encoding for RNPGBE_LINK_ST[11:8]. Valid link events report + * only these three speeds. + */ +enum mucse_speed { + mucse_speed_10 = 0, + mucse_speed_100 = 1, + mucse_speed_1000 = 2, +}; + int mucse_mbx_sync_fw(struct mucse_hw *hw); int mucse_mbx_powerup(struct mucse_hw *hw, bool is_powerup); int mucse_mbx_reset_hw(struct mucse_hw *hw); int mucse_mbx_get_macaddr(struct mucse_hw *hw, int pfvfnum, u8 *mac_addr, int port); +int mucse_mbx_set_link(struct mucse_hw *hw, u32 advertising, bool autoneg, + u32 speed, u32 duplex, u32 mdix_ctrl); +int mucse_mbx_phyup(struct mucse_hw *hw, bool is_phyup); +int mucse_mbx_link_report(struct mucse_hw *hw, bool is_report); void mucse_fw_irq_handler(struct mucse_hw *hw); #endif /* _RNPGBE_MBX_FW_H */ From ba16ad3c87691468bcbbecef7e0ceab059eea222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:39 +0200 Subject: [PATCH 1924/2126] net: macb: close race between NAPI polls & ndo_stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In ndo_close, we call napi_disable() then free the ring buffers queue->rx_ring|tx_ring. In the NAPI poll functions, after napi_complete_done() we might enable interrupts and might re-check the next ring buffer slot. This is a use-after-free race on our ring buffers because napi_disable() only waits for napi_complete_done() to return, it does not wait for NAPI poll functions to finish. The poll function sequence must stay as-is, see commit 0bf476fc3624 ("net: macb: Fix lost RX packet wakeup race in NAPI receive") which explains why the sequence must be napi_complete_done() -> arm IRQs -> re-check ring slot. Fix by waiting for full end of NAPI poll functions using synchronize_net() in our ndo_close implementation. This bug has never been reproduced and was reported by Sashiko. The chances of facing it in practice sound tiny: it needs a system without any phylink attached, running PREEMPT_RT and with a kernel preemption on the NAPI poll at the right instant. We fix it here before introducing context swapping, which is another place where the race could appear (and Sashiko complains on this series). Fixes: 138badbc21a0 ("net: macb: use NAPI for TX completion path") Fixes: 1900e30d0ef7 ("net: macb: simplify/cleanup NAPI reschedule checking") Cc: stable+noautosel@kernel.org # too unlikely and never reported by users Reported-by: Sashiko Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261001-macb-context-v10-0-beb541bbb7df%40bootlin.com?part=7 Link: https://lore.kernel.org/all/179115680572.434549.1016291990685937691@kernel.org/ Signed-off-by: Théo Lebrun Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20261013-macb-context-v11-1-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 020a47353d01..d414d00d93ce 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2059,6 +2059,12 @@ static void macb_quiesce_start(struct macb *bp) napi_disable(&queue->napi_tx); } + /* NAPI instances still access Rx/Tx rings after their + * napi_complete_done() calls! Callers to macb_quiesce_start() + * free rings, so wait for all NAPI handlers to be done. + */ + synchronize_net(); + /* Must be done after napi_tx is disabled: its completion re-arms * the LPI timer. */ From 435345c6518071ce38d534acfdf49a79e879e55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:40 +0200 Subject: [PATCH 1925/2126] net: macb: introduce macb_context struct for buffer management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whenever an operation requires buffer realloc, we close the interface, update parameters and reopen. To improve reliability under memory pressure, we should rather alloc new buffers, reconfigure HW and free old buffers. This requires MACB to support having multiple "contexts" in parallel. Introduce this concept by adding the macb_context struct, which owns all queue buffers and the parameters associated. We do not yet support multiple contexts in parallel, because all functions access bp->ctx (the currently active context) directly. Steps: - Introduce `struct macb_context` and its children `struct macb_rxq` and `struct macb_txq`. Context fields are stolen from `struct macb` and rxq/txq fields are from `struct macb_queue`. Making it two separate structs per queue simplifies accesses: we grab a txq/rxq local variable and access fields like txq->head instead of queue->tx_head. It also anecdotally improves data locality. - macb_init_dflt() / macb_get_ringparam() do not access bp->ctx->{rx,tx}_ring_size as they will/might run while interface is offline and ctx is NULL. Instead, introduce bp->configured_{rx,tx}_ring_size which get updated on user requests. - macb_open() starts by allocating bp->ctx. It gets freed in the open error codepath or by macb_close(). - Guided by compile errors, update all codepaths. Most diff is changing `queue->tx_*` to `txq->*` and `queue->rx_*` to `rxq->*`, with a new local variable. Also rx_buffer_size / rx_ring_size / tx_ring_size move from bp to bp->ctx. Introduce two helpers macb_txq|rxq() functions to convert macb_queue pointers. - macb_get_regs() is tweaked to support being ran while interface is offline (and context is NULL). Use default values at zero and override them only if context is present. - Protect our ctx freeing in at91ether code with a synchronize_irq() call. Note: bp->configured_{rx,tx}_ring_size contain proper values for EMAC, meaning 9/1 on ethtool -G on RM9200 whereas it reported 0/0 before. Acked-by: Conor Dooley Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-2-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb.h | 51 ++- drivers/net/ethernet/cadence/macb_main.c | 506 ++++++++++++++--------- 2 files changed, 344 insertions(+), 213 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 82499ec6a9f0..4f5aede1dec4 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1267,23 +1267,12 @@ struct macb_queue { unsigned int ENST_ON_TIME; unsigned int ENST_OFF_TIME; - /* Lock to protect tx_head and tx_tail */ + /* Lock to protect ctx->txq[q].head and ctx->txq[q].tail */ spinlock_t tx_ptr_lock; - unsigned int tx_head, tx_tail; - struct macb_dma_desc *tx_ring; - struct macb_tx_skb *tx_skb; - dma_addr_t tx_ring_dma; struct work_struct tx_error_task; bool txubr_pending; struct napi_struct napi_tx; - dma_addr_t rx_ring_dma; - dma_addr_t rx_buffers_dma; - unsigned int rx_tail; - unsigned int rx_prepared_head; - struct macb_dma_desc *rx_ring; - struct sk_buff **rx_skbuff; - void *rx_buffers; struct napi_struct napi_rx; struct queue_stats stats; }; @@ -1298,6 +1287,32 @@ struct ethtool_rx_fs_list { unsigned int count; }; +struct macb_rxq { + struct macb_dma_desc *ring; /* MACB & GEM */ + dma_addr_t ring_dma; /* MACB & GEM */ + unsigned int tail; /* MACB & GEM */ + unsigned int prepared_head; /* GEM */ + struct sk_buff **skbuff; /* GEM */ + dma_addr_t buffers_dma; /* MACB */ + void *buffers; /* MACB */ +}; + +struct macb_txq { + unsigned int head; + unsigned int tail; + struct macb_dma_desc *ring; + dma_addr_t ring_dma; + struct macb_tx_skb *skb; +}; + +struct macb_context { + unsigned int rx_buffer_size; + unsigned int rx_ring_size; + unsigned int tx_ring_size; + struct macb_rxq rxq[MACB_MAX_QUEUES]; + struct macb_txq txq[MACB_MAX_QUEUES]; +}; + struct macb { void __iomem *regs; bool native_io; @@ -1306,12 +1321,16 @@ struct macb { u32 (*macb_reg_readl)(struct macb *bp, int offset); void (*macb_reg_writel)(struct macb *bp, int offset, u32 value); + /* + * Context stores all its parameters. + * But we must remember them across closure. + */ + unsigned int configured_rx_ring_size; + unsigned int configured_tx_ring_size; + struct macb_context *ctx; + struct macb_dma_desc *rx_ring_tieoff; dma_addr_t rx_ring_tieoff_dma; - size_t rx_buffer_size; - - unsigned int rx_ring_size; - unsigned int tx_ring_size; unsigned int num_queues; struct macb_queue queues[MACB_MAX_QUEUES]; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index d414d00d93ce..9db03b0f082e 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -61,7 +61,7 @@ struct sifive_fu540_macb_mgmt { #define MAX_TX_RING_SIZE 4096 /* level of occupied TX descriptors under which we wake up TX process */ -#define MACB_TX_WAKEUP_THRESH(bp) (3 * (bp)->tx_ring_size / 4) +#define MACB_TX_WAKEUP_THRESH(bp) (3 * (bp)->ctx->tx_ring_size / 4) #define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(ISR_ROVR)) #define MACB_TX_ERR_FLAGS (MACB_BIT(ISR_TUND) \ @@ -152,48 +152,73 @@ static struct macb_dma_desc_64 *macb_64b_desc(struct macb *bp, struct macb_dma_d /* Ring buffer accessors */ static unsigned int macb_tx_ring_wrap(struct macb *bp, unsigned int index) { - return index & (bp->tx_ring_size - 1); + return index & (bp->ctx->tx_ring_size - 1); +} + +static struct macb_txq *macb_txq(struct macb_queue *queue) +{ + struct macb *bp = queue->bp; + unsigned int q = queue - bp->queues; + + return &bp->ctx->txq[q]; +} + +static struct macb_rxq *macb_rxq(struct macb_queue *queue) +{ + struct macb *bp = queue->bp; + unsigned int q = queue - bp->queues; + + return &bp->ctx->rxq[q]; } static struct macb_dma_desc *macb_tx_desc(struct macb_queue *queue, unsigned int index) { + struct macb_txq *txq = macb_txq(queue); + index = macb_tx_ring_wrap(queue->bp, index); index = macb_adj_dma_desc_idx(queue->bp, index); - return &queue->tx_ring[index]; + return &txq->ring[index]; } static struct macb_tx_skb *macb_tx_skb(struct macb_queue *queue, unsigned int index) { - return &queue->tx_skb[macb_tx_ring_wrap(queue->bp, index)]; + struct macb_txq *txq = macb_txq(queue); + + return &txq->skb[macb_tx_ring_wrap(queue->bp, index)]; } static dma_addr_t macb_tx_dma(struct macb_queue *queue, unsigned int index) { + struct macb_txq *txq = macb_txq(queue); dma_addr_t offset; offset = macb_tx_ring_wrap(queue->bp, index) * macb_dma_desc_get_size(queue->bp); - return queue->tx_ring_dma + offset; + return txq->ring_dma + offset; } static unsigned int macb_rx_ring_wrap(struct macb *bp, unsigned int index) { - return index & (bp->rx_ring_size - 1); + return index & (bp->ctx->rx_ring_size - 1); } static struct macb_dma_desc *macb_rx_desc(struct macb_queue *queue, unsigned int index) { + struct macb_rxq *rxq = macb_rxq(queue); + index = macb_rx_ring_wrap(queue->bp, index); index = macb_adj_dma_desc_idx(queue->bp, index); - return &queue->rx_ring[index]; + return &rxq->ring[index]; } static void *macb_rx_buffer(struct macb_queue *queue, unsigned int index) { - return queue->rx_buffers + queue->bp->rx_buffer_size * + struct macb_rxq *rxq = macb_rxq(queue); + + return rxq->buffers + queue->bp->ctx->rx_buffer_size * macb_rx_ring_wrap(queue->bp, index); } @@ -463,19 +488,23 @@ mdio_pm_exit: static void macb_init_buffers(struct macb *bp) { struct macb_queue *queue; + struct macb_rxq *rxq; + struct macb_txq *txq; unsigned int q; /* Single register for all queues' high 32 bits. */ if (macb_dma64(bp)) { - macb_writel(bp, RBQPH, - upper_32_bits(bp->queues[0].rx_ring_dma)); - macb_writel(bp, TBQPH, - upper_32_bits(bp->queues[0].tx_ring_dma)); + rxq = &bp->ctx->rxq[0]; + txq = &bp->ctx->txq[0]; + macb_writel(bp, RBQPH, upper_32_bits(rxq->ring_dma)); + macb_writel(bp, TBQPH, upper_32_bits(txq->ring_dma)); } for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma)); - queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); + rxq = &bp->ctx->rxq[q]; + txq = &bp->ctx->txq[q]; + queue_writel(queue, RBQP, lower_32_bits(rxq->ring_dma)); + queue_writel(queue, TBQP, lower_32_bits(txq->ring_dma)); } } @@ -659,11 +688,12 @@ static bool macb_tx_lpi_set(struct macb *bp, bool enable) static bool macb_tx_all_queues_idle(struct macb *bp) { - struct macb_queue *queue; + struct macb_txq *txq; unsigned int q; - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - if (READ_ONCE(queue->tx_head) != READ_ONCE(queue->tx_tail)) + for (q = 0; q < bp->num_queues; ++q) { + txq = &bp->ctx->txq[q]; + if (READ_ONCE(txq->head) != READ_ONCE(txq->tail)) return false; } return true; @@ -812,6 +842,7 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) struct macb_tx_skb tx_skb, *skb_curr, *skb_next; struct macb_dma_desc *desc_curr, *desc_next; unsigned int i, cycles, shift, curr, next; + struct macb_txq *txq = macb_txq(queue); struct macb *bp = queue->bp; unsigned char desc[24]; unsigned long flags; @@ -822,17 +853,17 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) return; spin_lock_irqsave(&queue->tx_ptr_lock, flags); - head = queue->tx_head; - tail = queue->tx_tail; - ring_size = bp->tx_ring_size; + head = txq->head; + tail = txq->tail; + ring_size = bp->ctx->tx_ring_size; count = CIRC_CNT(head, tail, ring_size); if (!(tail % ring_size)) goto unlock; if (!count) { - queue->tx_head = 0; - queue->tx_tail = 0; + txq->head = 0; + txq->tail = 0; goto unlock; } @@ -876,8 +907,8 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) sizeof(struct macb_tx_skb)); } - queue->tx_head = count; - queue->tx_tail = 0; + txq->head = count; + txq->tail = 0; /* Make descriptor updates visible to hardware */ wmb(); @@ -1278,6 +1309,7 @@ static void macb_tx_error_task(struct work_struct *work) struct macb_queue *queue = container_of(work, struct macb_queue, tx_error_task); unsigned int q = queue - queue->bp->queues; + struct macb_txq *txq = macb_txq(queue); struct macb *bp = queue->bp; struct macb_tx_skb *tx_skb; struct macb_dma_desc *desc; @@ -1290,7 +1322,7 @@ static void macb_tx_error_task(struct work_struct *work) u32 bytes = 0; netdev_vdbg(bp->netdev, "%s: q = %u, t = %u, h = %u\n", - __func__, q, queue->tx_tail, queue->tx_head); + __func__, q, txq->tail, txq->head); /* Prevent the queue NAPI TX poll from running, as it calls * macb_tx_complete(), which in turn may call netif_wake_subqueue(). @@ -1316,7 +1348,7 @@ static void macb_tx_error_task(struct work_struct *work) /* Treat frames in TX queue including the ones that caused the error. * Free transmit buffers in upper layer. */ - for (tail = queue->tx_tail; tail != queue->tx_head; tail++) { + for (tail = txq->tail; tail != txq->head; tail++) { u32 ctrl; desc = macb_tx_desc(queue, tail); @@ -1373,10 +1405,10 @@ static void macb_tx_error_task(struct work_struct *work) wmb(); /* Reinitialize the TX desc queue */ - queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); + queue_writel(queue, TBQP, lower_32_bits(txq->ring_dma)); /* Make TX ring reflect state of hardware */ - queue->tx_head = 0; - queue->tx_tail = 0; + txq->head = 0; + txq->tail = 0; /* Housework before enabling TX IRQ */ macb_writel(bp, TSR, macb_readl(bp, TSR)); @@ -1433,6 +1465,7 @@ not_oss: static int macb_tx_complete(struct macb_queue *queue, int budget) { struct macb *bp = queue->bp; + struct macb_txq *txq = macb_txq(queue); unsigned int q = queue - bp->queues; unsigned long flags; unsigned int tail; @@ -1441,8 +1474,8 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) u32 bytes = 0; spin_lock_irqsave(&queue->tx_ptr_lock, flags); - head = queue->tx_head; - for (tail = queue->tx_tail; tail != head && packets < budget; tail++) { + head = txq->head; + for (tail = txq->tail; tail != head && packets < budget; tail++) { struct macb_tx_skb *tx_skb; struct sk_buff *skb; struct macb_dma_desc *desc; @@ -1498,10 +1531,10 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) netdev_tx_completed_queue(netdev_get_tx_queue(bp->netdev, q), packets, bytes); - queue->tx_tail = tail; + txq->tail = tail; if (__netif_subqueue_stopped(bp->netdev, q) && - CIRC_CNT(queue->tx_head, queue->tx_tail, - bp->tx_ring_size) <= MACB_TX_WAKEUP_THRESH(bp)) + CIRC_CNT(txq->head, txq->tail, + bp->ctx->tx_ring_size) <= MACB_TX_WAKEUP_THRESH(bp)) netif_wake_subqueue(bp->netdev, q); spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); @@ -1513,24 +1546,26 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) static int gem_rx_refill(struct macb_queue *queue) { + struct macb_rxq *rxq = macb_rxq(queue); struct macb *bp = queue->bp; struct macb_dma_desc *desc; struct sk_buff *skb; unsigned int entry; dma_addr_t paddr; - while (CIRC_SPACE(queue->rx_prepared_head, queue->rx_tail, - bp->rx_ring_size) > 0) { - entry = macb_rx_ring_wrap(bp, queue->rx_prepared_head); + while (CIRC_SPACE(rxq->prepared_head, rxq->tail, + bp->ctx->rx_ring_size) > 0) { + entry = macb_rx_ring_wrap(bp, rxq->prepared_head); /* Make hw descriptor updates visible to CPU */ rmb(); desc = macb_rx_desc(queue, entry); - if (!queue->rx_skbuff[entry]) { + if (!rxq->skbuff[entry]) { /* allocate sk_buff for this free entry in ring */ - skb = netdev_alloc_skb(bp->netdev, bp->rx_buffer_size); + skb = netdev_alloc_skb(bp->netdev, + bp->ctx->rx_buffer_size); if (unlikely(!skb)) { netdev_err(bp->netdev, "Unable to allocate sk_buff\n"); @@ -1539,16 +1574,16 @@ static int gem_rx_refill(struct macb_queue *queue) /* now fill corresponding descriptor entry */ paddr = dma_map_single(&bp->pdev->dev, skb->data, - bp->rx_buffer_size, + bp->ctx->rx_buffer_size, DMA_FROM_DEVICE); if (dma_mapping_error(&bp->pdev->dev, paddr)) { dev_kfree_skb(skb); break; } - queue->rx_skbuff[entry] = skb; + rxq->skbuff[entry] = skb; - if (entry == bp->rx_ring_size - 1) + if (entry == bp->ctx->rx_ring_size - 1) paddr |= MACB_BIT(RX_WRAP); desc->ctrl = 0; /* Setting addr clears RX_USED and allows reception, @@ -1575,19 +1610,19 @@ static int gem_rx_refill(struct macb_queue *queue) dma_wmb(); desc->addr &= ~MACB_BIT(RX_USED); } - queue->rx_prepared_head++; + rxq->prepared_head++; } /* Make descriptor updates visible to hardware */ wmb(); netdev_vdbg(bp->netdev, "rx ring: queue: %p, prepared head %d, tail %d\n", - queue, queue->rx_prepared_head, queue->rx_tail); + queue, rxq->prepared_head, rxq->tail); /* Fail if queue has zero prepared descriptors. This is critical because * nothing will ever trigger a refill again. */ - if (queue->rx_prepared_head == queue->rx_tail) + if (rxq->prepared_head == rxq->tail) return -ENOMEM; return 0; @@ -1617,6 +1652,7 @@ static void discard_partial_frame(struct macb_queue *queue, unsigned int begin, static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, int budget) { + struct macb_rxq *rxq = macb_rxq(queue); struct macb *bp = queue->bp; struct macb_dma_desc *desc; struct sk_buff *skb; @@ -1633,10 +1669,10 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, * for hardware. Outside, we might have RX_USED descriptors for * alloc failures. */ - if (queue->rx_tail == queue->rx_prepared_head) + if (rxq->tail == rxq->prepared_head) break; - entry = macb_rx_ring_wrap(bp, queue->rx_tail); + entry = macb_rx_ring_wrap(bp, rxq->tail); desc = macb_rx_desc(queue, entry); /* Make hw descriptor updates visible to CPU */ @@ -1653,7 +1689,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, ctrl = desc->ctrl; - queue->rx_tail++; + rxq->tail++; count++; if (!(ctrl & MACB_BIT(RX_SOF) && ctrl & MACB_BIT(RX_EOF))) { @@ -1663,7 +1699,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, queue->stats.rx_dropped++; break; } - skb = queue->rx_skbuff[entry]; + skb = rxq->skbuff[entry]; if (unlikely(!skb)) { netdev_err(bp->netdev, "inconsistent Rx descriptor chain\n"); @@ -1672,7 +1708,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, break; } /* now everything is ready for receiving packet */ - queue->rx_skbuff[entry] = NULL; + rxq->skbuff[entry] = NULL; len = ctrl & bp->rx_frm_len_mask; netdev_vdbg(bp->netdev, "%s %u (len %u)\n", @@ -1680,7 +1716,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, skb_put(skb, len); dma_unmap_single(&bp->pdev->dev, addr, - bp->rx_buffer_size, DMA_FROM_DEVICE); + bp->ctx->rx_buffer_size, DMA_FROM_DEVICE); skb->protocol = eth_type_trans(skb, bp->netdev); skb_checksum_none_assert(skb); @@ -1761,7 +1797,7 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, skb_put(skb, len); for (frag = first_frag; ; frag++) { - unsigned int frag_len = bp->rx_buffer_size; + unsigned int frag_len = bp->ctx->rx_buffer_size; if (offset + frag_len > len) { if (unlikely(frag != last_frag)) { @@ -1773,7 +1809,7 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, skb_copy_to_linear_data_offset(skb, offset, macb_rx_buffer(queue, frag), frag_len); - offset += bp->rx_buffer_size; + offset += bp->ctx->rx_buffer_size; desc = macb_rx_desc(queue, frag); desc->addr &= ~MACB_BIT(RX_USED); @@ -1798,32 +1834,34 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, static inline void macb_init_rx_ring(struct macb_queue *queue) { + struct macb_rxq *rxq = macb_rxq(queue); struct macb_dma_desc *desc = NULL; struct macb *bp = queue->bp; dma_addr_t addr; int i; - addr = queue->rx_buffers_dma; - for (i = 0; i < bp->rx_ring_size; i++) { + addr = rxq->buffers_dma; + for (i = 0; i < bp->ctx->rx_ring_size; i++) { desc = macb_rx_desc(queue, i); macb_set_addr(bp, desc, addr); desc->ctrl = 0; - addr += bp->rx_buffer_size; + addr += bp->ctx->rx_buffer_size; } desc->addr |= MACB_BIT(RX_WRAP); - queue->rx_tail = 0; + rxq->tail = 0; } static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, int budget) { + struct macb_rxq *rxq = macb_rxq(queue); struct macb *bp = queue->bp; bool reset_rx_queue = false; int first_frag = -1; unsigned int tail; int received = 0; - for (tail = queue->rx_tail; budget > 0; tail++) { + for (tail = rxq->tail; budget > 0; tail++) { struct macb_dma_desc *desc = macb_rx_desc(queue, tail); u32 ctrl; @@ -1877,7 +1915,7 @@ static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE)); macb_init_rx_ring(queue); - queue_writel(queue, RBQP, queue->rx_ring_dma); + queue_writel(queue, RBQP, rxq->ring_dma); macb_writel(bp, NCR, ctrl | MACB_BIT(RE)); @@ -1886,24 +1924,25 @@ static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, } if (first_frag != -1) - queue->rx_tail = first_frag; + rxq->tail = first_frag; else - queue->rx_tail = tail; + rxq->tail = tail; return received; } static bool macb_rx_pending(struct macb_queue *queue) { + struct macb_rxq *rxq = macb_rxq(queue); struct macb *bp = queue->bp; struct macb_dma_desc *desc; unsigned int entry; /* No armed descriptor left: nothing can be pending. */ - if (macb_is_gem(bp) && queue->rx_tail == queue->rx_prepared_head) + if (macb_is_gem(bp) && rxq->tail == rxq->prepared_head) return false; - entry = macb_rx_ring_wrap(bp, queue->rx_tail); + entry = macb_rx_ring_wrap(bp, rxq->tail); desc = macb_rx_desc(queue, entry); /* Make hw descriptor updates visible to CPU */ @@ -1951,18 +1990,19 @@ static int macb_rx_poll(struct napi_struct *napi, int budget) static void macb_tx_restart(struct macb_queue *queue) { + struct macb_txq *txq = macb_txq(queue); struct macb *bp = queue->bp; unsigned int head_idx, tbqp; unsigned long flags; spin_lock_irqsave(&queue->tx_ptr_lock, flags); - if (queue->tx_head == queue->tx_tail) + if (txq->head == txq->tail) goto out_tx_ptr_unlock; tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(bp); tbqp = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, tbqp)); - head_idx = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, queue->tx_head)); + head_idx = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, txq->head)); if (tbqp == head_idx) goto out_tx_ptr_unlock; @@ -1977,15 +2017,16 @@ out_tx_ptr_unlock: static bool macb_tx_complete_pending(struct macb_queue *queue) { + struct macb_txq *txq = macb_txq(queue); bool retval = false; unsigned long flags; spin_lock_irqsave(&queue->tx_ptr_lock, flags); - if (queue->tx_head != queue->tx_tail) { + if (txq->head != txq->tail) { /* Make hw descriptor updates visible to CPU */ rmb(); - if (macb_tx_desc(queue, queue->tx_tail)->ctrl & MACB_BIT(TX_USED)) + if (macb_tx_desc(queue, txq->tail)->ctrl & MACB_BIT(TX_USED)) retval = true; } spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); @@ -2305,8 +2346,9 @@ static unsigned int macb_tx_map(struct macb *bp, unsigned int hdrlen, u8 fcs_len) { + struct macb_txq *txq = macb_txq(queue); unsigned int f, nr_frags = skb_shinfo(skb)->nr_frags; - unsigned int len, i, tx_head = queue->tx_head; + unsigned int len, i, tx_head = txq->head; u32 ctrl, lso_ctrl = 0, seq_ctrl = 0; unsigned int eof = 1, mss_mfs = 0; struct macb_tx_skb *tx_skb = NULL; @@ -2427,11 +2469,12 @@ static unsigned int macb_tx_map(struct macb *bp, ctrl |= MACB_BIT(TX_LAST); eof = 0; } - if (unlikely(macb_tx_ring_wrap(bp, i) == bp->tx_ring_size - 1)) + if (unlikely(macb_tx_ring_wrap(bp, i) == + bp->ctx->tx_ring_size - 1)) ctrl |= MACB_BIT(TX_WRAP); /* First descriptor is header descriptor */ - if (i == queue->tx_head) { + if (i == txq->head) { ctrl |= MACB_BF(TX_LSO, lso_ctrl); ctrl |= MACB_BF(TX_TCP_SEQ_SRC, seq_ctrl); if ((bp->netdev->features & NETIF_F_HW_CSUM) && @@ -2451,16 +2494,16 @@ static unsigned int macb_tx_map(struct macb *bp, */ wmb(); desc->ctrl = ctrl; - } while (i != queue->tx_head); + } while (i != txq->head); - queue->tx_head = tx_head; + txq->head = tx_head; return 0; dma_error: netdev_err(bp->netdev, "TX DMA map failed\n"); - for (i = queue->tx_head; i != tx_head; i++) { + for (i = txq->head; i != tx_head; i++) { tx_skb = macb_tx_skb(queue, i); macb_tx_unmap(bp, tx_skb, 0); @@ -2587,6 +2630,7 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, unsigned int q = skb_get_queue_mapping(skb); unsigned int desc_cnt, nr_frags, frag_size, f; struct macb_queue *queue = &bp->queues[q]; + struct macb_txq *txq = macb_txq(queue); netdev_tx_t ret = NETDEV_TX_OK; unsigned int hdrlen, tx_len; bool add_fcs, is_lso; @@ -2649,11 +2693,11 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, spin_lock_irqsave(&queue->tx_ptr_lock, flags); /* This is a hard error, log it. */ - if (CIRC_SPACE(queue->tx_head, queue->tx_tail, - bp->tx_ring_size) < desc_cnt) { + if (CIRC_SPACE(txq->head, txq->tail, + bp->ctx->tx_ring_size) < desc_cnt) { netif_stop_subqueue(netdev, q); - netdev_dbg(netdev, "tx_head = %u, tx_tail = %u\n", - queue->tx_head, queue->tx_tail); + netdev_dbg(netdev, "txq head = %u, txq tail = %u\n", + txq->head, txq->tail); ret = NETDEV_TX_BUSY; goto unlock; } @@ -2690,7 +2734,7 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); spin_unlock(&bp->lock); - if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1) + if (CIRC_SPACE(txq->head, txq->tail, bp->ctx->tx_ring_size) < 1) netif_stop_subqueue(netdev, q); unlock: @@ -2702,38 +2746,42 @@ unlock: static void macb_init_rx_buffer_size(struct macb *bp, size_t size) { if (!macb_is_gem(bp)) { - bp->rx_buffer_size = MACB_RX_BUFFER_SIZE; + bp->ctx->rx_buffer_size = MACB_RX_BUFFER_SIZE; } else { - bp->rx_buffer_size = MIN(size, RX_BUFFER_MAX); + bp->ctx->rx_buffer_size = MIN(size, RX_BUFFER_MAX); - if (bp->rx_buffer_size % RX_BUFFER_MULTIPLE) { + if (bp->ctx->rx_buffer_size % RX_BUFFER_MULTIPLE) { netdev_dbg(bp->netdev, "RX buffer must be multiple of %d bytes, expanding\n", RX_BUFFER_MULTIPLE); - bp->rx_buffer_size = - roundup(bp->rx_buffer_size, RX_BUFFER_MULTIPLE); + bp->ctx->rx_buffer_size = + roundup(bp->ctx->rx_buffer_size, + RX_BUFFER_MULTIPLE); } } - netdev_dbg(bp->netdev, "mtu [%u] rx_buffer_size [%zu]\n", - bp->netdev->mtu, bp->rx_buffer_size); + netdev_dbg(bp->netdev, "mtu [%u] rx_buffer_size [%u]\n", + bp->netdev->mtu, bp->ctx->rx_buffer_size); } static void gem_free_rx_buffers(struct macb *bp) { - struct sk_buff *skb; - struct macb_dma_desc *desc; + struct macb_dma_desc *desc; struct macb_queue *queue; - dma_addr_t addr; + struct macb_rxq *rxq; + struct sk_buff *skb; + dma_addr_t addr; unsigned int q; int i; for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - if (!queue->rx_skbuff) + rxq = &bp->ctx->rxq[q]; + + if (!rxq->skbuff) continue; - for (i = 0; i < bp->rx_ring_size; i++) { - skb = queue->rx_skbuff[i]; + for (i = 0; i < bp->ctx->rx_ring_size; i++) { + skb = rxq->skbuff[i]; if (!skb) continue; @@ -2741,60 +2789,71 @@ static void gem_free_rx_buffers(struct macb *bp) desc = macb_rx_desc(queue, i); addr = macb_get_addr(bp, desc); - dma_unmap_single(&bp->pdev->dev, addr, bp->rx_buffer_size, - DMA_FROM_DEVICE); + dma_unmap_single(&bp->pdev->dev, addr, + bp->ctx->rx_buffer_size, + DMA_FROM_DEVICE); dev_kfree_skb_any(skb); skb = NULL; } - kfree(queue->rx_skbuff); - queue->rx_skbuff = NULL; + kfree(rxq->skbuff); + rxq->skbuff = NULL; } } static void macb_free_rx_buffers(struct macb *bp) { - struct macb_queue *queue = &bp->queues[0]; + struct macb_rxq *rxq = &bp->ctx->rxq[0]; - if (queue->rx_buffers) { + if (rxq->buffers) { dma_free_coherent(&bp->pdev->dev, - bp->rx_ring_size * bp->rx_buffer_size, - queue->rx_buffers, queue->rx_buffers_dma); - queue->rx_buffers = NULL; + bp->ctx->rx_ring_size * + bp->ctx->rx_buffer_size, + rxq->buffers, rxq->buffers_dma); + rxq->buffers = NULL; } } static unsigned int macb_tx_ring_size_per_queue(struct macb *bp) { - return macb_dma_desc_get_size(bp) * bp->tx_ring_size + bp->tx_bd_rd_prefetch; + return macb_dma_desc_get_size(bp) * bp->ctx->tx_ring_size + + bp->tx_bd_rd_prefetch; } static unsigned int macb_rx_ring_size_per_queue(struct macb *bp) { - return macb_dma_desc_get_size(bp) * bp->rx_ring_size + bp->rx_bd_rd_prefetch; + return macb_dma_desc_get_size(bp) * bp->ctx->rx_ring_size + + bp->rx_bd_rd_prefetch; } static void macb_free(struct macb *bp) { struct device *dev = &bp->pdev->dev; struct macb_queue *queue; + struct macb_txq *txq; + struct macb_rxq *rxq; unsigned int q; size_t size; bp->macbgem_ops.mog_free_rx_buffers(bp); + txq = &bp->ctx->txq[0]; size = bp->num_queues * macb_tx_ring_size_per_queue(bp); - dma_free_coherent(dev, size, bp->queues[0].tx_ring, bp->queues[0].tx_ring_dma); + dma_free_coherent(dev, size, txq->ring, txq->ring_dma); + rxq = &bp->ctx->rxq[0]; size = bp->num_queues * macb_rx_ring_size_per_queue(bp); - dma_free_coherent(dev, size, bp->queues[0].rx_ring, bp->queues[0].rx_ring_dma); + dma_free_coherent(dev, size, rxq->ring, rxq->ring_dma); - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - if (queue->tx_skb) { + for (q = 0; q < bp->num_queues; ++q) { + txq = &bp->ctx->txq[q]; + rxq = &bp->ctx->rxq[q]; + queue = &bp->queues[q]; + + if (txq->skb) { unsigned int dropped = 0, tail; - for (tail = queue->tx_tail; tail != queue->tx_head; - tail++) { + for (tail = txq->tail; tail != txq->head; tail++) { if (macb_tx_skb(queue, tail)->skb) dropped++; macb_tx_unmap(bp, macb_tx_skb(queue, tail), 0); @@ -2803,50 +2862,49 @@ static void macb_free(struct macb *bp) queue->stats.tx_dropped += dropped; bp->netdev->stats.tx_dropped += dropped; - kfree(queue->tx_skb); - queue->tx_skb = NULL; + kfree(txq->skb); + txq->skb = NULL; } - queue->tx_head = 0; - queue->tx_tail = 0; - queue->tx_ring = NULL; - queue->rx_ring = NULL; + txq->ring = NULL; + rxq->ring = NULL; } } static int gem_alloc_rx_buffers(struct macb *bp) { - struct macb_queue *queue; + struct macb_rxq *rxq; unsigned int q; int size; - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - size = bp->rx_ring_size * sizeof(struct sk_buff *); - queue->rx_skbuff = kzalloc(size, GFP_KERNEL); - if (!queue->rx_skbuff) + for (q = 0; q < bp->num_queues; ++q) { + rxq = &bp->ctx->rxq[q]; + size = bp->ctx->rx_ring_size * sizeof(struct sk_buff *); + rxq->skbuff = kzalloc(size, GFP_KERNEL); + if (!rxq->skbuff) return -ENOMEM; else netdev_dbg(bp->netdev, "Allocated %d RX struct sk_buff entries at %p\n", - bp->rx_ring_size, queue->rx_skbuff); + bp->ctx->rx_ring_size, rxq->skbuff); } return 0; } static int macb_alloc_rx_buffers(struct macb *bp) { - struct macb_queue *queue = &bp->queues[0]; + struct macb_rxq *rxq = &bp->ctx->rxq[0]; int size; - size = bp->rx_ring_size * bp->rx_buffer_size; - queue->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size, - &queue->rx_buffers_dma, GFP_KERNEL); - if (!queue->rx_buffers) + size = bp->ctx->rx_ring_size * bp->ctx->rx_buffer_size; + rxq->buffers = dma_alloc_coherent(&bp->pdev->dev, size, + &rxq->buffers_dma, GFP_KERNEL); + if (!rxq->buffers) return -ENOMEM; netdev_dbg(bp->netdev, "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n", - size, (unsigned long)queue->rx_buffers_dma, queue->rx_buffers); + size, (unsigned long)rxq->buffers_dma, rxq->buffers); return 0; } @@ -2854,7 +2912,8 @@ static int macb_alloc(struct macb *bp) { struct device *dev = &bp->pdev->dev; dma_addr_t tx_dma, rx_dma; - struct macb_queue *queue; + struct macb_txq *txq; + struct macb_rxq *rxq; unsigned int q; void *tx, *rx; size_t size; @@ -2871,8 +2930,9 @@ static int macb_alloc(struct macb *bp) if (!tx) goto out_err; /* Record the buffer so that the error path frees it. */ - bp->queues[0].tx_ring = tx; - bp->queues[0].tx_ring_dma = tx_dma; + txq = &bp->ctx->txq[0]; + txq->ring = tx; + txq->ring_dma = tx_dma; if (upper_32_bits(tx_dma) != upper_32_bits(tx_dma + size - 1)) goto out_err; netdev_dbg(bp->netdev, "Allocated %zu bytes for %u TX rings at %08lx (mapped %p)\n", @@ -2883,23 +2943,27 @@ static int macb_alloc(struct macb *bp) if (!rx) goto out_err; /* Record the buffer so that the error path frees it. */ - bp->queues[0].rx_ring = rx; - bp->queues[0].rx_ring_dma = rx_dma; + rxq = &bp->ctx->rxq[0]; + rxq->ring = rx; + rxq->ring_dma = rx_dma; if (upper_32_bits(rx_dma) != upper_32_bits(rx_dma + size - 1)) goto out_err; netdev_dbg(bp->netdev, "Allocated %zu bytes for %u RX rings at %08lx (mapped %p)\n", size, bp->num_queues, (unsigned long)rx_dma, rx); - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - queue->tx_ring = tx + macb_tx_ring_size_per_queue(bp) * q; - queue->tx_ring_dma = tx_dma + macb_tx_ring_size_per_queue(bp) * q; + for (q = 0; q < bp->num_queues; ++q) { + txq = &bp->ctx->txq[q]; + rxq = &bp->ctx->rxq[q]; - queue->rx_ring = rx + macb_rx_ring_size_per_queue(bp) * q; - queue->rx_ring_dma = rx_dma + macb_rx_ring_size_per_queue(bp) * q; + txq->ring = tx + macb_tx_ring_size_per_queue(bp) * q; + txq->ring_dma = tx_dma + macb_tx_ring_size_per_queue(bp) * q; - size = bp->tx_ring_size * sizeof(struct macb_tx_skb); - queue->tx_skb = kmalloc(size, GFP_KERNEL); - if (!queue->tx_skb) + rxq->ring = rx + macb_rx_ring_size_per_queue(bp) * q; + rxq->ring_dma = rx_dma + macb_rx_ring_size_per_queue(bp) * q; + + size = bp->ctx->tx_ring_size * sizeof(struct macb_tx_skb); + txq->skb = kmalloc(size, GFP_KERNEL); + if (!txq->skb) goto out_err; } if (bp->macbgem_ops.mog_alloc_rx_buffers(bp)) @@ -2914,12 +2978,14 @@ out_err: static int gem_init_rx_ring(struct macb_queue *queue) { + struct macb_context *ctx = queue->bp->ctx; + struct macb_rxq *rxq = macb_rxq(queue); unsigned int i; - queue->rx_tail = 0; - queue->rx_prepared_head = 0; + rxq->tail = 0; + rxq->prepared_head = 0; - for (i = 0; i < queue->bp->rx_ring_size; i++) + for (i = 0; i < ctx->rx_ring_size; i++) macb_rx_desc(queue, i)->addr |= MACB_BIT(RX_USED); return gem_rx_refill(queue); @@ -2929,20 +2995,22 @@ static int gem_init_rings(struct macb *bp) { struct macb_queue *queue; struct macb_dma_desc *desc = NULL; + struct macb_txq *txq; int last_err = 0; unsigned int q; int err; int i; for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - for (i = 0; i < bp->tx_ring_size; i++) { + txq = &bp->ctx->txq[q]; + for (i = 0; i < bp->ctx->tx_ring_size; i++) { desc = macb_tx_desc(queue, i); macb_set_addr(bp, desc, 0); desc->ctrl = MACB_BIT(TX_USED); } desc->ctrl |= MACB_BIT(TX_WRAP); - queue->tx_head = 0; - queue->tx_tail = 0; + txq->head = 0; + txq->tail = 0; err = gem_init_rx_ring(queue); if (err) @@ -2954,18 +3022,19 @@ static int gem_init_rings(struct macb *bp) static int macb_init_rings(struct macb *bp) { - int i; + struct macb_txq *txq = &bp->ctx->txq[0]; struct macb_dma_desc *desc = NULL; + int i; macb_init_rx_ring(&bp->queues[0]); - for (i = 0; i < bp->tx_ring_size; i++) { + for (i = 0; i < bp->ctx->tx_ring_size; i++) { desc = macb_tx_desc(&bp->queues[0], i); macb_set_addr(bp, desc, 0); desc->ctrl = MACB_BIT(TX_USED); } - bp->queues[0].tx_head = 0; - bp->queues[0].tx_tail = 0; + txq->head = 0; + txq->tail = 0; desc->ctrl |= MACB_BIT(TX_WRAP); return 0; @@ -3082,7 +3151,7 @@ static void macb_configure_dma(struct macb *bp) unsigned int q; u32 dmacfg; - buffer_size = bp->rx_buffer_size / RX_BUFFER_MULTIPLE; + buffer_size = bp->ctx->rx_buffer_size / RX_BUFFER_MULTIPLE; if (macb_is_gem(bp)) { dmacfg = gem_readl(bp, DMACFG) & ~GEM_BF(RXBS, -1L); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { @@ -3287,14 +3356,23 @@ static int macb_open(struct net_device *netdev) if (err < 0) return err; + WRITE_ONCE(bp->ctx, kzalloc_obj(*bp->ctx)); + wmb(); /* ensure IRQ enabled at quiesce end read the new context */ + if (!bp->ctx) { + err = -ENOMEM; + goto pm_exit; + } + /* RX buffers initialization */ macb_init_rx_buffer_size(bp, bufsz); + bp->ctx->rx_ring_size = bp->configured_rx_ring_size; + bp->ctx->tx_ring_size = bp->configured_tx_ring_size; err = macb_alloc(bp); if (err) { netdev_err(netdev, "Unable to allocate DMA memory (error %d)\n", err); - goto pm_exit; + goto free_ctx; } err = bp->macbgem_ops.mog_init_rings(bp); @@ -3335,6 +3413,9 @@ reset_hw: macb_reset_hw(bp); free_rings: macb_free(bp); +free_ctx: + kfree(bp->ctx); + bp->ctx = NULL; pm_exit: pm_runtime_put_sync(&bp->pdev->dev); return err; @@ -3366,6 +3447,8 @@ static int macb_close(struct net_device *netdev) spin_unlock_irqrestore(&bp->lock, flags); macb_free(bp); + kfree(bp->ctx); + bp->ctx = NULL; if (bp->ptp_info) bp->ptp_info->ptp_remove(netdev); @@ -3731,15 +3814,22 @@ static int macb_get_regs_len(struct net_device *netdev) static void macb_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) { + dma_addr_t tx_dma_tail = 0, tx_dma_head = 0; struct macb *bp = netdev_priv(netdev); - unsigned int tail, head; + unsigned int tail = 0, head = 0; + struct macb_txq *txq; u32 *regs_buff = p; regs->version = (macb_readl(bp, MID) & ((1 << MACB_REV_SIZE) - 1)) | MACB_GREGS_VERSION; - tail = macb_tx_ring_wrap(bp, bp->queues[0].tx_tail); - head = macb_tx_ring_wrap(bp, bp->queues[0].tx_head); + if (bp->ctx) { + txq = &bp->ctx->txq[0]; + tail = macb_tx_ring_wrap(bp, txq->tail); + head = macb_tx_ring_wrap(bp, txq->head); + tx_dma_tail = macb_tx_dma(&bp->queues[0], tail); + tx_dma_head = macb_tx_dma(&bp->queues[0], head); + } regs_buff[0] = macb_readl(bp, NCR); regs_buff[1] = macb_or_gem_readl(bp, NCFGR); @@ -3752,8 +3842,8 @@ static void macb_get_regs(struct net_device *netdev, struct ethtool_regs *regs, regs_buff[8] = tail; regs_buff[9] = head; - regs_buff[10] = macb_tx_dma(&bp->queues[0], tail); - regs_buff[11] = macb_tx_dma(&bp->queues[0], head); + regs_buff[10] = tx_dma_tail; + regs_buff[11] = tx_dma_head; if (!(bp->caps & MACB_CAPS_USRIO_DISABLED)) regs_buff[12] = macb_or_gem_readl(bp, USRIO); @@ -3818,8 +3908,8 @@ static void macb_get_ringparam(struct net_device *netdev, ring->rx_max_pending = MAX_RX_RING_SIZE; ring->tx_max_pending = MAX_TX_RING_SIZE; - ring->rx_pending = bp->rx_ring_size; - ring->tx_pending = bp->tx_ring_size; + ring->rx_pending = bp->configured_rx_ring_size; + ring->tx_pending = bp->configured_tx_ring_size; } static int macb_set_ringparam(struct net_device *netdev, @@ -3845,8 +3935,8 @@ static int macb_set_ringparam(struct net_device *netdev, MIN_TX_RING_SIZE, MAX_TX_RING_SIZE); new_tx_size = roundup_pow_of_two(new_tx_size); - if ((new_tx_size == bp->tx_ring_size) && - (new_rx_size == bp->rx_ring_size)) { + if (new_tx_size == bp->configured_tx_ring_size && + new_rx_size == bp->configured_rx_ring_size) { /* nothing to do */ return 0; } @@ -3856,8 +3946,8 @@ static int macb_set_ringparam(struct net_device *netdev, macb_close(bp->netdev); } - bp->rx_ring_size = new_rx_size; - bp->tx_ring_size = new_tx_size; + bp->configured_rx_ring_size = new_rx_size; + bp->configured_tx_ring_size = new_tx_size; if (reset) macb_open(bp->netdev); @@ -4870,9 +4960,6 @@ static int macb_init_dflt(struct platform_device *pdev) int err; u32 val, reg; - bp->tx_ring_size = DEFAULT_TX_RING_SIZE; - bp->rx_ring_size = DEFAULT_RX_RING_SIZE; - /* No locking needed because the IRQs are not requested yet. The * flag is cleared by macb_open() and re-armed by macb_close(). */ @@ -5084,26 +5171,26 @@ static struct sifive_fu540_macb_mgmt *mgmt; static int at91ether_alloc_coherent(struct macb *bp) { - struct macb_queue *queue = &bp->queues[0]; + struct macb_rxq *rxq = &bp->ctx->rxq[0]; - queue->rx_ring = dma_alloc_coherent(&bp->pdev->dev, - (AT91ETHER_MAX_RX_DESCR * - macb_dma_desc_get_size(bp)), - &queue->rx_ring_dma, GFP_KERNEL); - if (!queue->rx_ring) + rxq->ring = dma_alloc_coherent(&bp->pdev->dev, + (AT91ETHER_MAX_RX_DESCR * + macb_dma_desc_get_size(bp)), + &rxq->ring_dma, GFP_KERNEL); + if (!rxq->ring) return -ENOMEM; - queue->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, - AT91ETHER_MAX_RX_DESCR * - AT91ETHER_MAX_RBUFF_SZ, - &queue->rx_buffers_dma, - GFP_KERNEL); - if (!queue->rx_buffers) { + rxq->buffers = dma_alloc_coherent(&bp->pdev->dev, + AT91ETHER_MAX_RX_DESCR * + AT91ETHER_MAX_RBUFF_SZ, + &rxq->buffers_dma, + GFP_KERNEL); + if (!rxq->buffers) { dma_free_coherent(&bp->pdev->dev, AT91ETHER_MAX_RX_DESCR * macb_dma_desc_get_size(bp), - queue->rx_ring, queue->rx_ring_dma); - queue->rx_ring = NULL; + rxq->ring, rxq->ring_dma); + rxq->ring = NULL; return -ENOMEM; } @@ -5112,22 +5199,22 @@ static int at91ether_alloc_coherent(struct macb *bp) static void at91ether_free_coherent(struct macb *bp) { - struct macb_queue *queue = &bp->queues[0]; + struct macb_rxq *rxq = &bp->ctx->rxq[0]; - if (queue->rx_ring) { + if (rxq->ring) { dma_free_coherent(&bp->pdev->dev, AT91ETHER_MAX_RX_DESCR * macb_dma_desc_get_size(bp), - queue->rx_ring, queue->rx_ring_dma); - queue->rx_ring = NULL; + rxq->ring, rxq->ring_dma); + rxq->ring = NULL; } - if (queue->rx_buffers) { + if (rxq->buffers) { dma_free_coherent(&bp->pdev->dev, AT91ETHER_MAX_RX_DESCR * AT91ETHER_MAX_RBUFF_SZ, - queue->rx_buffers, queue->rx_buffers_dma); - queue->rx_buffers = NULL; + rxq->buffers, rxq->buffers_dma); + rxq->buffers = NULL; } } @@ -5135,6 +5222,7 @@ static void at91ether_free_coherent(struct macb *bp) static int at91ether_start(struct macb *bp) { struct macb_queue *queue = &bp->queues[0]; + struct macb_rxq *rxq = &bp->ctx->rxq[0]; struct macb_dma_desc *desc; dma_addr_t addr; u32 ctl; @@ -5144,7 +5232,7 @@ static int at91ether_start(struct macb *bp) if (ret) return ret; - addr = queue->rx_buffers_dma; + addr = rxq->buffers_dma; for (i = 0; i < AT91ETHER_MAX_RX_DESCR; i++) { desc = macb_rx_desc(queue, i); macb_set_addr(bp, desc, addr); @@ -5156,10 +5244,10 @@ static int at91ether_start(struct macb *bp) desc->addr |= MACB_BIT(RX_WRAP); /* Reset buffer index */ - queue->rx_tail = 0; + rxq->tail = 0; /* Program address of descriptor list in Rx Buffer Queue register */ - macb_writel(bp, RBQP, queue->rx_ring_dma); + macb_writel(bp, RBQP, rxq->ring_dma); /* Enable Receive and Transmit */ ctl = macb_readl(bp, NCR); @@ -5194,6 +5282,8 @@ static void at91ether_stop(struct macb *bp) ctl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE))); + synchronize_irq(bp->netdev->irq); + /* Free resources. */ at91ether_free_coherent(bp); } @@ -5209,6 +5299,13 @@ static int at91ether_open(struct net_device *netdev) if (ret < 0) return ret; + WRITE_ONCE(bp->ctx, kzalloc_obj(*bp->ctx)); + wmb(); /* ensure IRQ enabled below read the new context */ + if (!bp->ctx) { + ret = -ENOMEM; + goto pm_exit; + } + /* Clear internal statistics */ ctl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctl | MACB_BIT(CLRSTAT)); @@ -5217,7 +5314,7 @@ static int at91ether_open(struct net_device *netdev) ret = at91ether_start(bp); if (ret) - goto pm_exit; + goto free_ctx; ret = macb_phylink_connect(bp); if (ret) @@ -5229,6 +5326,9 @@ static int at91ether_open(struct net_device *netdev) stop: at91ether_stop(bp); +free_ctx: + kfree(bp->ctx); + bp->ctx = NULL; pm_exit: pm_runtime_put_sync(&bp->pdev->dev); return ret; @@ -5246,6 +5346,9 @@ static int at91ether_close(struct net_device *netdev) at91ether_stop(bp); + kfree(bp->ctx); + bp->ctx = NULL; + pm_runtime_put(&bp->pdev->dev); return 0; @@ -5297,15 +5400,15 @@ static void at91ether_rx(struct net_device *netdev) { struct macb *bp = netdev_priv(netdev); struct macb_queue *queue = &bp->queues[0]; + struct macb_rxq *rxq = &bp->ctx->rxq[0]; struct macb_dma_desc *desc; unsigned char *p_recv; struct sk_buff *skb; unsigned int pktlen; - desc = macb_rx_desc(queue, queue->rx_tail); + desc = macb_rx_desc(queue, rxq->tail); while (desc->addr & MACB_BIT(RX_USED)) { - p_recv = queue->rx_buffers + - queue->rx_tail * AT91ETHER_MAX_RBUFF_SZ; + p_recv = rxq->buffers + rxq->tail * AT91ETHER_MAX_RBUFF_SZ; pktlen = MACB_BF(RX_FRMLEN, desc->ctrl); skb = netdev_alloc_skb(netdev, pktlen + 2); if (skb) { @@ -5327,12 +5430,12 @@ static void at91ether_rx(struct net_device *netdev) desc->addr &= ~MACB_BIT(RX_USED); /* wrap after last buffer */ - if (queue->rx_tail == AT91ETHER_MAX_RX_DESCR - 1) - queue->rx_tail = 0; + if (rxq->tail == AT91ETHER_MAX_RX_DESCR - 1) + rxq->tail = 0; else - queue->rx_tail++; + rxq->tail++; - desc = macb_rx_desc(queue, queue->rx_tail); + desc = macb_rx_desc(queue, rxq->tail); } } @@ -6030,6 +6133,15 @@ static int macb_probe(struct platform_device *pdev) /* setup capabilities */ macb_configure_caps(bp, macb_config); + if (bp->caps & MACB_CAPS_MACB_IS_EMAC) { + /* The name is lying on EMAC: sizes aren't configurable. */ + bp->configured_rx_ring_size = AT91ETHER_MAX_RX_DESCR; + bp->configured_tx_ring_size = 1; /* tiny ring buffer */ + } else { + bp->configured_rx_ring_size = DEFAULT_RX_RING_SIZE; + bp->configured_tx_ring_size = DEFAULT_TX_RING_SIZE; + } + #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT if (GEM_BFEXT(DAW64, gem_readl(bp, DCFG6))) { err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44)); From b8ab596dabde5053c994872761a1d26b6a1f54c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:41 +0200 Subject: [PATCH 1926/2126] net: macb: avoid macb_init_rx_buffer_size() modifying state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macb_init_rx_buffer_size() takes the macb private data struct and overrides its bp->ctx->rx_buffer_size. To make it usable with multiple contexts, make it return its value. Also, move the `bufsz` computation into it. The value is only used if GEM, and for historical reason it currently lives in macb_open(). Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-3-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb_main.c | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 9db03b0f082e..537fa570846f 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2743,25 +2743,26 @@ unlock: return ret; } -static void macb_init_rx_buffer_size(struct macb *bp, size_t size) +static unsigned int macb_rx_buffer_size(struct macb *bp, unsigned int mtu) { - if (!macb_is_gem(bp)) { - bp->ctx->rx_buffer_size = MACB_RX_BUFFER_SIZE; - } else { - bp->ctx->rx_buffer_size = MIN(size, RX_BUFFER_MAX); + unsigned int size; - if (bp->ctx->rx_buffer_size % RX_BUFFER_MULTIPLE) { + if (!macb_is_gem(bp)) { + size = MACB_RX_BUFFER_SIZE; + } else { + size = mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; + size = MIN(size, RX_BUFFER_MAX); + + if (size % RX_BUFFER_MULTIPLE) { netdev_dbg(bp->netdev, "RX buffer must be multiple of %d bytes, expanding\n", RX_BUFFER_MULTIPLE); - bp->ctx->rx_buffer_size = - roundup(bp->ctx->rx_buffer_size, - RX_BUFFER_MULTIPLE); + size = roundup(size, RX_BUFFER_MULTIPLE); } } - netdev_dbg(bp->netdev, "mtu [%u] rx_buffer_size [%u]\n", - bp->netdev->mtu, bp->ctx->rx_buffer_size); + netdev_dbg(bp->netdev, "mtu [%u] rx_buffer_size [%u]\n", mtu, size); + return size; } static void gem_free_rx_buffers(struct macb *bp) @@ -3346,7 +3347,6 @@ static void macb_set_rx_mode(struct net_device *netdev) static int macb_open(struct net_device *netdev) { - size_t bufsz = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; struct macb *bp = netdev_priv(netdev); int err; @@ -3364,7 +3364,7 @@ static int macb_open(struct net_device *netdev) } /* RX buffers initialization */ - macb_init_rx_buffer_size(bp, bufsz); + bp->ctx->rx_buffer_size = macb_rx_buffer_size(bp, netdev->mtu); bp->ctx->rx_ring_size = bp->configured_rx_ring_size; bp->ctx->tx_ring_size = bp->configured_tx_ring_size; From 9bfec20d011f2d44fa2f616ce7f5a8bf5512f646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:42 +0200 Subject: [PATCH 1927/2126] net: macb: make `struct macb` subset reachable from macb_context struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For parallel MACB context to start become a reality, many functions need to stop operating on bp->ctx (the currently active context) and instead work on a context they get passed. That context might be (1) the new one that is getting allocated and initialised, or, (2) the old one to be freed. To reduce bug surface area, we will taint those functions to *only* take a context and no `struct macb *bp`. That way, no bug of using `bp->ctx` instead of `ctx` will ever occur. For that, we need to embed a subset of `struct macb` information into each context so that all helpers can still do their jobs. That subset must be constant once probe is completed. Do this by taking a pointer to a subset of macb called `struct macb_info`. That subset is accessible from context (ctx->info->caps) or from bp (bp->caps) using `-fms-extensions` option, thanks to commit c4781dc3d1cf ("Kbuild: enable -fms-extensions"). https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html Add the structure and assign ctx->info at alloc, but nothing uses it yet. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-4-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb.h | 31 +++++++++++++++++------- drivers/net/ethernet/cadence/macb_main.c | 6 +++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 4f5aede1dec4..075a328c4495 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1287,6 +1287,17 @@ struct ethtool_rx_fs_list { unsigned int count; }; +struct macb_info { + struct platform_device *pdev; + struct net_device *netdev; + struct macb_or_gem_ops macbgem_ops; + unsigned int num_queues; + u32 caps; + int rx_bd_rd_prefetch; + int tx_bd_rd_prefetch; + struct queue_stats *queue_stats[MACB_MAX_QUEUES]; +}; + struct macb_rxq { struct macb_dma_desc *ring; /* MACB & GEM */ dma_addr_t ring_dma; /* MACB & GEM */ @@ -1306,6 +1317,8 @@ struct macb_txq { }; struct macb_context { + const struct macb_info *info; + unsigned int rx_buffer_size; unsigned int rx_ring_size; unsigned int tx_ring_size; @@ -1321,6 +1334,15 @@ struct macb { u32 (*macb_reg_readl)(struct macb *bp, int offset); void (*macb_reg_writel)(struct macb *bp, int offset, u32 value); + /* + * Give direct access (bp->caps) and + * allow taking a pointer to it (&bp->info) for contexts. + */ + union { + struct macb_info; + struct macb_info info; + }; + /* * Context stores all its parameters. * But we must remember them across closure. @@ -1332,17 +1354,14 @@ struct macb { struct macb_dma_desc *rx_ring_tieoff; dma_addr_t rx_ring_tieoff_dma; - unsigned int num_queues; struct macb_queue queues[MACB_MAX_QUEUES]; spinlock_t lock; - struct platform_device *pdev; struct clk *pclk; struct clk *hclk; struct clk *tx_clk; struct clk *rx_clk; struct clk *tsu_clk; - struct net_device *netdev; /* Protects hw_stats and ethtool_stats */ spinlock_t stats_lock; union { @@ -1350,15 +1369,12 @@ struct macb { struct gem_stats gem; } hw_stats; - struct macb_or_gem_ops macbgem_ops; - struct mii_bus *mii_bus; struct phylink *phylink; struct phylink_config phylink_config; struct phylink_pcs phylink_usx_pcs; struct phylink_pcs phylink_sgmii_pcs; - u32 caps; unsigned int dma_burst_length; phy_interface_t phy_interface; @@ -1406,9 +1422,6 @@ struct macb { */ bool irq_quiesced; - int rx_bd_rd_prefetch; - int tx_bd_rd_prefetch; - u32 rx_intr_mask; struct macb_pm_data pm_data; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 537fa570846f..dbc8168a0ba9 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3363,6 +3363,8 @@ static int macb_open(struct net_device *netdev) goto pm_exit; } + bp->ctx->info = &bp->info; + /* RX buffers initialization */ bp->ctx->rx_buffer_size = macb_rx_buffer_size(bp, netdev->mtu); bp->ctx->rx_ring_size = bp->configured_rx_ring_size; @@ -5305,6 +5307,7 @@ static int at91ether_open(struct net_device *netdev) ret = -ENOMEM; goto pm_exit; } + bp->ctx->info = &bp->info; /* Clear internal statistics */ ctl = macb_readl(bp, NCR); @@ -6027,6 +6030,7 @@ static int macb_probe(struct platform_device *pdev) u32 wtrmrk_rst_val; void __iomem *mem; struct macb *bp; + unsigned int q; int num_queues; bool native_io; int err, val; @@ -6072,6 +6076,8 @@ static int macb_probe(struct platform_device *pdev) bp->netdev = netdev; bp->regs = mem; bp->native_io = native_io; + for (q = 0; q < MACB_MAX_QUEUES; q++) + bp->info.queue_stats[q] = &bp->queues[q].stats; if (native_io) { bp->macb_reg_readl = hw_readl_native; bp->macb_reg_writel = hw_writel_native; From dd1aaefee4f63917b05180514df75cb9a9b41539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:43 +0200 Subject: [PATCH 1928/2126] net: macb: change caps helpers signatures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For parallel MACB context to start becoming a reality, many functions will soon not have access to `struct macb *bp`. Those will still have access to caps through ctx->info->caps. Change all caps helpers signatures, from taking `struct macb *bp` to taking `struct macb_info *info`. Info is accessible in both bp and ctx and it ensures type safety (versus passing raw `u32 caps`). Function list: macb_is_gem() gem_has_ptp() macb_dma64() macb_dma_ptp() macb_dma_desc_get_size() macb_set_addr() macb_get_addr() macb_64b_desc() macb_tx_unmap() Note: drop macb_64b_desc(bp, ...) parameter; it is unused and it must be dropped as macb_{set,get}_addr() call macb_64b_desc(). Acked-by: Conor Dooley Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-5-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb.h | 21 +-- drivers/net/ethernet/cadence/macb_main.c | 159 ++++++++++++----------- drivers/net/ethernet/cadence/macb_ptp.c | 8 +- 3 files changed, 98 insertions(+), 90 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 075a328c4495..ddbab4c78bf4 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -834,7 +834,7 @@ */ #define macb_or_gem_writel(__bp, __reg, __value) \ ({ \ - if (macb_is_gem((__bp))) \ + if (macb_is_gem(&(__bp)->info)) \ gem_writel((__bp), __reg, __value); \ else \ macb_writel((__bp), __reg, __value); \ @@ -843,7 +843,7 @@ #define macb_or_gem_readl(__bp, __reg) \ ({ \ u32 __v; \ - if (macb_is_gem((__bp))) \ + if (macb_is_gem(&(__bp)->info)) \ __v = gem_readl((__bp), __reg); \ else \ __v = macb_readl((__bp), __reg); \ @@ -1473,14 +1473,15 @@ static inline void gem_ptp_do_txstamp(struct macb *bp, struct sk_buff *skb, stru static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) { } #endif -static inline bool macb_is_gem(struct macb *bp) +static inline bool macb_is_gem(const struct macb_info *info) { - return !!(bp->caps & MACB_CAPS_MACB_IS_GEM); + return !!(info->caps & MACB_CAPS_MACB_IS_GEM); } -static inline bool gem_has_ptp(struct macb *bp) +static inline bool gem_has_ptp(const struct macb_info *info) { - return IS_ENABLED(CONFIG_MACB_USE_HWSTAMP) && (bp->caps & MACB_CAPS_GEM_HAS_PTP); + return IS_ENABLED(CONFIG_MACB_USE_HWSTAMP) && + (info->caps & MACB_CAPS_GEM_HAS_PTP); } /* ENST Helper functions */ @@ -1496,16 +1497,16 @@ static inline u64 enst_max_hw_interval(u32 speed_mbps) ENST_TIME_GRANULARITY_NS * 1000, (speed_mbps)); } -static inline bool macb_dma64(struct macb *bp) +static inline bool macb_dma64(const struct macb_info *info) { return IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) && - bp->caps & MACB_CAPS_DMA_64B; + info->caps & MACB_CAPS_DMA_64B; } -static inline bool macb_dma_ptp(struct macb *bp) +static inline bool macb_dma_ptp(const struct macb_info *info) { return IS_ENABLED(CONFIG_MACB_USE_HWSTAMP) && - bp->caps & MACB_CAPS_DMA_PTP; + info->caps & MACB_CAPS_DMA_PTP; } static inline void macb_queue_isr_clear(struct macb *bp, diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index dbc8168a0ba9..ac5660480840 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -126,13 +126,13 @@ struct sifive_fu540_macb_mgmt { * word 5: timestamp word 1 * word 6: timestamp word 2 */ -static unsigned int macb_dma_desc_get_size(struct macb *bp) +static unsigned int macb_dma_desc_get_size(const struct macb_info *info) { unsigned int desc_size = sizeof(struct macb_dma_desc); - if (macb_dma64(bp)) + if (macb_dma64(info)) desc_size += sizeof(struct macb_dma_desc_64); - if (macb_dma_ptp(bp)) + if (macb_dma_ptp(info)) desc_size += sizeof(struct macb_dma_desc_ptp); return desc_size; @@ -140,10 +140,10 @@ static unsigned int macb_dma_desc_get_size(struct macb *bp) static unsigned int macb_adj_dma_desc_idx(struct macb *bp, unsigned int desc_idx) { - return desc_idx * (1 + macb_dma64(bp) + macb_dma_ptp(bp)); + return desc_idx * (1 + macb_dma64(&bp->info) + macb_dma_ptp(&bp->info)); } -static struct macb_dma_desc_64 *macb_64b_desc(struct macb *bp, struct macb_dma_desc *desc) +static struct macb_dma_desc_64 *macb_64b_desc(struct macb_dma_desc *desc) { return (struct macb_dma_desc_64 *)((void *)desc + sizeof(struct macb_dma_desc)); @@ -195,7 +195,7 @@ static dma_addr_t macb_tx_dma(struct macb_queue *queue, unsigned int index) dma_addr_t offset; offset = macb_tx_ring_wrap(queue->bp, index) * - macb_dma_desc_get_size(queue->bp); + macb_dma_desc_get_size(&queue->bp->info); return txq->ring_dma + offset; } @@ -282,7 +282,7 @@ static void macb_set_hwaddr(struct macb *bp) top = get_unaligned_le16(bp->netdev->dev_addr + 4); macb_or_gem_writel(bp, SA1T, top); - if (gem_has_ptp(bp)) { + if (gem_has_ptp(&bp->info)) { gem_writel(bp, RXPTPUNI, bottom); gem_writel(bp, TXPTPUNI, bottom); } @@ -493,7 +493,7 @@ static void macb_init_buffers(struct macb *bp) unsigned int q; /* Single register for all queues' high 32 bits. */ - if (macb_dma64(bp)) { + if (macb_dma64(&bp->info)) { rxq = &bp->ctx->rxq[0]; txq = &bp->ctx->txq[0]; macb_writel(bp, RBQPH, upper_32_bits(rxq->ring_dma)); @@ -787,7 +787,7 @@ static void macb_mac_config(struct phylink_config *config, unsigned int mode, if (bp->caps & MACB_CAPS_MACB_IS_EMAC) { if (state->interface == PHY_INTERFACE_MODE_RMII) ctrl |= MACB_BIT(RM9200_RMII); - } else if (macb_is_gem(bp)) { + } else if (macb_is_gem(&bp->info)) { ctrl &= ~(GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL)); ncr &= ~GEM_BIT(ENABLE_HS_MAC); @@ -847,7 +847,7 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) unsigned char desc[24]; unsigned long flags; - desc_size = macb_dma_desc_get_size(bp); + desc_size = macb_dma_desc_get_size(&bp->info); if (WARN_ON_ONCE(desc_size > ARRAY_SIZE(desc))) return; @@ -954,7 +954,7 @@ static void macb_mac_link_up(struct phylink_config *config, if (!(bp->caps & MACB_CAPS_MACB_IS_EMAC)) { ctrl &= ~MACB_BIT(PAE); - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { ctrl &= ~GEM_BIT(GBE); if (speed == SPEED_1000) @@ -985,7 +985,7 @@ static void macb_mac_link_up(struct phylink_config *config, /* Enable Rx and Tx; Enable PTP unicast */ ctrl = macb_readl(bp, NCR); - if (gem_has_ptp(bp)) + if (gem_has_ptp(&bp->info)) ctrl |= MACB_BIT(PTPUNI); macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE)); @@ -1098,7 +1098,8 @@ static int macb_mii_probe(struct net_device *netdev) bp->phylink_config.supported_interfaces); /* Determine what modes are supported */ - if (macb_is_gem(bp) && (bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE)) { + if (macb_is_gem(&bp->info) && + (bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE)) { bp->phylink_config.mac_capabilities |= MAC_1000FD; if (!(bp->caps & MACB_CAPS_NO_GIGABIT_HALF)) bp->phylink_config.mac_capabilities |= MAC_1000HD; @@ -1253,14 +1254,15 @@ static int macb_halt_tx(struct macb *bp) bp, TSR); } -static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, int budget) +static void macb_tx_unmap(const struct macb_info *info, + struct macb_tx_skb *tx_skb, int budget) { if (tx_skb->mapping) { if (tx_skb->mapped_as_page) - dma_unmap_page(&bp->pdev->dev, tx_skb->mapping, + dma_unmap_page(&info->pdev->dev, tx_skb->mapping, tx_skb->size, DMA_TO_DEVICE); else - dma_unmap_single(&bp->pdev->dev, tx_skb->mapping, + dma_unmap_single(&info->pdev->dev, tx_skb->mapping, tx_skb->size, DMA_TO_DEVICE); tx_skb->mapping = 0; } @@ -1271,12 +1273,13 @@ static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, int budge } } -static void macb_set_addr(struct macb *bp, struct macb_dma_desc *desc, dma_addr_t addr) +static void macb_set_addr(const struct macb_info *info, + struct macb_dma_desc *desc, dma_addr_t addr) { - if (macb_dma64(bp)) { + if (macb_dma64(info)) { struct macb_dma_desc_64 *desc_64; - desc_64 = macb_64b_desc(bp, desc); + desc_64 = macb_64b_desc(desc); desc_64->addrh = upper_32_bits(addr); /* The low bits of RX address contain the RX_USED bit, clearing * of which allows packet RX. Make sure the high bits are also @@ -1288,18 +1291,19 @@ static void macb_set_addr(struct macb *bp, struct macb_dma_desc *desc, dma_addr_ desc->addr = lower_32_bits(addr); } -static dma_addr_t macb_get_addr(struct macb *bp, struct macb_dma_desc *desc) +static dma_addr_t macb_get_addr(const struct macb_info *info, + struct macb_dma_desc *desc) { dma_addr_t addr = 0; - if (macb_dma64(bp)) { + if (macb_dma64(info)) { struct macb_dma_desc_64 *desc_64; - desc_64 = macb_64b_desc(bp, desc); + desc_64 = macb_64b_desc(desc); addr = ((u64)(desc_64->addrh) << 32); } addr |= MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr)); - if (macb_dma_ptp(bp)) + if (macb_dma_ptp(info)) addr &= ~GEM_BIT(DMA_RXVALID); return addr; } @@ -1359,7 +1363,7 @@ static void macb_tx_error_task(struct work_struct *work) if (ctrl & MACB_BIT(TX_USED)) { /* skb is set for the last buffer of the frame */ while (!skb) { - macb_tx_unmap(bp, tx_skb, 0); + macb_tx_unmap(&bp->info, tx_skb, 0); tail++; tx_skb = macb_tx_skb(queue, tail); skb = tx_skb->skb; @@ -1390,7 +1394,7 @@ static void macb_tx_error_task(struct work_struct *work) desc->ctrl = ctrl | MACB_BIT(TX_USED); } - macb_tx_unmap(bp, tx_skb, 0); + macb_tx_unmap(&bp->info, tx_skb, 0); } netdev_tx_completed_queue(netdev_get_tx_queue(bp->netdev, q), @@ -1398,7 +1402,7 @@ static void macb_tx_error_task(struct work_struct *work) /* Set end of TX queue */ desc = macb_tx_desc(queue, 0); - macb_set_addr(bp, desc, 0); + macb_set_addr(&bp->info, desc, 0); desc->ctrl = MACB_BIT(TX_USED); /* Make descriptor updates visible to hardware */ @@ -1517,7 +1521,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) } /* Now we can safely release resources */ - macb_tx_unmap(bp, tx_skb, budget); + macb_tx_unmap(&bp->info, tx_skb, budget); /* skb is set only for the last buffer of the frame. * WARNING: at this point skb has been freed by @@ -1590,7 +1594,7 @@ static int gem_rx_refill(struct macb_queue *queue) * make sure ctrl is cleared first to avoid a race. */ dma_wmb(); - macb_set_addr(bp, desc, paddr); + macb_set_addr(&bp->info, desc, paddr); /* Properly align Ethernet header. * @@ -1679,7 +1683,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, rmb(); rxused = (desc->addr & MACB_BIT(RX_USED)) ? true : false; - addr = macb_get_addr(bp, desc); + addr = macb_get_addr(&bp->info, desc); if (!rxused) break; @@ -1843,7 +1847,7 @@ static inline void macb_init_rx_ring(struct macb_queue *queue) addr = rxq->buffers_dma; for (i = 0; i < bp->ctx->rx_ring_size; i++) { desc = macb_rx_desc(queue, i); - macb_set_addr(bp, desc, addr); + macb_set_addr(&bp->info, desc, addr); desc->ctrl = 0; addr += bp->ctx->rx_buffer_size; } @@ -1939,7 +1943,7 @@ static bool macb_rx_pending(struct macb_queue *queue) unsigned int entry; /* No armed descriptor left: nothing can be pending. */ - if (macb_is_gem(bp) && rxq->tail == rxq->prepared_head) + if (macb_is_gem(&bp->info) && rxq->tail == rxq->prepared_head) return false; entry = macb_rx_ring_wrap(bp, rxq->tail); @@ -2000,7 +2004,7 @@ static void macb_tx_restart(struct macb_queue *queue) if (txq->head == txq->tail) goto out_tx_ptr_unlock; - tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(bp); + tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(&bp->info); tbqp = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, tbqp)); head_idx = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, txq->head)); @@ -2227,7 +2231,7 @@ static int macb_interrupt_misc(struct macb_queue *queue, u32 status) if (status & MACB_BIT(ISR_ROVR)) { /* We missed at least one packet */ spin_lock(&bp->stats_lock); - if (macb_is_gem(bp)) + if (macb_is_gem(&bp->info)) bp->hw_stats.gem.rx_overruns++; else bp->hw_stats.macb.rx_overruns++; @@ -2240,7 +2244,7 @@ static int macb_interrupt_misc(struct macb_queue *queue, u32 status) macb_queue_isr_clear(bp, queue, MACB_BIT(HRESP)); } - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { if (status & GEM_BIT(WOL)) gem_wol_interrupt(queue, status); } else { @@ -2488,7 +2492,7 @@ static unsigned int macb_tx_map(struct macb *bp, ctrl |= MACB_BF(MSS_MFS, mss_mfs); /* Set TX buffer descriptor */ - macb_set_addr(bp, desc, tx_skb->mapping); + macb_set_addr(&bp->info, desc, tx_skb->mapping); /* desc->addr must be visible to hardware before clearing * 'TX_USED' bit in desc->ctrl. */ @@ -2506,7 +2510,7 @@ dma_error: for (i = txq->head; i != tx_head; i++) { tx_skb = macb_tx_skb(queue, i); - macb_tx_unmap(bp, tx_skb, 0); + macb_tx_unmap(&bp->info, tx_skb, 0); } return -ENOMEM; @@ -2713,7 +2717,7 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, goto unlock; } - if (macb_dma_ptp(bp) && + if (macb_dma_ptp(&bp->info) && (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; @@ -2747,7 +2751,7 @@ static unsigned int macb_rx_buffer_size(struct macb *bp, unsigned int mtu) { unsigned int size; - if (!macb_is_gem(bp)) { + if (!macb_is_gem(&bp->info)) { size = MACB_RX_BUFFER_SIZE; } else { size = mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; @@ -2788,7 +2792,7 @@ static void gem_free_rx_buffers(struct macb *bp) continue; desc = macb_rx_desc(queue, i); - addr = macb_get_addr(bp, desc); + addr = macb_get_addr(&bp->info, desc); dma_unmap_single(&bp->pdev->dev, addr, bp->ctx->rx_buffer_size, @@ -2817,13 +2821,13 @@ static void macb_free_rx_buffers(struct macb *bp) static unsigned int macb_tx_ring_size_per_queue(struct macb *bp) { - return macb_dma_desc_get_size(bp) * bp->ctx->tx_ring_size + + return macb_dma_desc_get_size(&bp->info) * bp->ctx->tx_ring_size + bp->tx_bd_rd_prefetch; } static unsigned int macb_rx_ring_size_per_queue(struct macb *bp) { - return macb_dma_desc_get_size(bp) * bp->ctx->rx_ring_size + + return macb_dma_desc_get_size(&bp->info) * bp->ctx->rx_ring_size + bp->rx_bd_rd_prefetch; } @@ -2857,7 +2861,8 @@ static void macb_free(struct macb *bp) for (tail = txq->tail; tail != txq->head; tail++) { if (macb_tx_skb(queue, tail)->skb) dropped++; - macb_tx_unmap(bp, macb_tx_skb(queue, tail), 0); + macb_tx_unmap(&bp->info, + macb_tx_skb(queue, tail), 0); } queue->stats.tx_dropped += dropped; @@ -3006,7 +3011,7 @@ static int gem_init_rings(struct macb *bp) txq = &bp->ctx->txq[q]; for (i = 0; i < bp->ctx->tx_ring_size; i++) { desc = macb_tx_desc(queue, i); - macb_set_addr(bp, desc, 0); + macb_set_addr(&bp->info, desc, 0); desc->ctrl = MACB_BIT(TX_USED); } desc->ctrl |= MACB_BIT(TX_WRAP); @@ -3031,7 +3036,7 @@ static int macb_init_rings(struct macb *bp) for (i = 0; i < bp->ctx->tx_ring_size; i++) { desc = macb_tx_desc(&bp->queues[0], i); - macb_set_addr(bp, desc, 0); + macb_set_addr(&bp->info, desc, 0); desc->ctrl = MACB_BIT(TX_USED); } txq->head = 0; @@ -3102,7 +3107,7 @@ static u32 macb_mdc_clk_div(struct macb *bp) u32 config; unsigned long pclk_hz; - if (macb_is_gem(bp)) + if (macb_is_gem(&bp->info)) return gem_mdc_clk_div(bp); pclk_hz = clk_get_rate(bp->pclk); @@ -3124,7 +3129,7 @@ static u32 macb_mdc_clk_div(struct macb *bp) */ static u32 macb_dbw(struct macb *bp) { - if (!macb_is_gem(bp)) + if (!macb_is_gem(&bp->info)) return 0; switch (GEM_BFEXT(DBWDEF, gem_readl(bp, DCFG1))) { @@ -3153,7 +3158,7 @@ static void macb_configure_dma(struct macb *bp) u32 dmacfg; buffer_size = bp->ctx->rx_buffer_size / RX_BUFFER_MULTIPLE; - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { dmacfg = gem_readl(bp, DMACFG) & ~GEM_BF(RXBS, -1L); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { if (q) @@ -3177,9 +3182,9 @@ static void macb_configure_dma(struct macb *bp) dmacfg &= ~GEM_BIT(TXCOEN); dmacfg &= ~GEM_BIT(ADDR64); - if (macb_dma64(bp)) + if (macb_dma64(&bp->info)) dmacfg |= GEM_BIT(ADDR64); - if (macb_dma_ptp(bp)) + if (macb_dma_ptp(&bp->info)) dmacfg |= GEM_BIT(RXEXT) | GEM_BIT(TXEXT); netdev_dbg(bp->netdev, "Cadence configure DMA with 0x%08x\n", dmacfg); @@ -3207,7 +3212,8 @@ static void macb_init_hw(struct macb *bp) config |= MACB_BIT(BIG); /* Receive oversized frames */ if (bp->netdev->flags & IFF_PROMISC) config |= MACB_BIT(CAF); /* Copy All Frames */ - else if (macb_is_gem(bp) && bp->netdev->features & NETIF_F_RXCSUM) + else if (macb_is_gem(&bp->info) && + bp->netdev->features & NETIF_F_RXCSUM) config |= GEM_BIT(RXCOEN); if (!(bp->netdev->flags & IFF_BROADCAST)) config |= MACB_BIT(NBC); /* No BroadCast */ @@ -3315,14 +3321,14 @@ static void macb_set_rx_mode(struct net_device *netdev) cfg |= MACB_BIT(CAF); /* Disable RX checksum offload */ - if (macb_is_gem(bp)) + if (macb_is_gem(&bp->info)) cfg &= ~GEM_BIT(RXCOEN); } else { /* Disable promiscuous mode */ cfg &= ~MACB_BIT(CAF); /* Enable RX checksum offload only if requested */ - if (macb_is_gem(bp) && netdev->features & NETIF_F_RXCSUM) + if (macb_is_gem(&bp->info) && netdev->features & NETIF_F_RXCSUM) cfg |= GEM_BIT(RXCOEN); } @@ -3601,7 +3607,7 @@ static void macb_get_stats(struct net_device *netdev, struct macb_stats *hwstat = &bp->hw_stats.macb; netdev_stats_to_stats64(nstat, &bp->netdev->stats); - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { gem_get_stats(bp, nstat); return; } @@ -3849,7 +3855,7 @@ static void macb_get_regs(struct net_device *netdev, struct ethtool_regs *regs, if (!(bp->caps & MACB_CAPS_USRIO_DISABLED)) regs_buff[12] = macb_or_gem_readl(bp, USRIO); - if (macb_is_gem(bp)) + if (macb_is_gem(&bp->info)) regs_buff[13] = gem_readl(bp, DMACFG); } @@ -3984,7 +3990,7 @@ static int gem_get_ts_info(struct net_device *netdev, { struct macb *bp = netdev_priv(netdev); - if (!macb_dma_ptp(bp)) { + if (!macb_dma_ptp(&bp->info)) { ethtool_op_get_ts_info(netdev, info); return 0; } @@ -4085,7 +4091,7 @@ static void gem_prog_cmp_regs(struct macb *bp, struct ethtool_rx_flow_spec *fs) bool cmp_b = false; bool cmp_c = false; - if (!macb_is_gem(bp)) + if (!macb_is_gem(&bp->info)) return; tp4sp_v = &(fs->h_u.tcp_ip4_spec); @@ -4446,7 +4452,7 @@ static inline void macb_set_txcsum_feature(struct macb *bp, { u32 val; - if (!macb_is_gem(bp)) + if (!macb_is_gem(&bp->info)) return; val = gem_readl(bp, DMACFG); @@ -4464,7 +4470,7 @@ static inline void macb_set_rxcsum_feature(struct macb *bp, struct net_device *netdev = bp->netdev; u32 val; - if (!macb_is_gem(bp)) + if (!macb_is_gem(&bp->info)) return; val = gem_readl(bp, NCFGR); @@ -4479,7 +4485,7 @@ static inline void macb_set_rxcsum_feature(struct macb *bp, static inline void macb_set_rxflow_feature(struct macb *bp, netdev_features_t features) { - if (!macb_is_gem(bp)) + if (!macb_is_gem(&bp->info)) return; gem_enable_flow_filters(bp, !!(features & NETIF_F_NTUPLE)); @@ -4804,7 +4810,7 @@ static void macb_configure_caps(struct macb *bp, bp->caps |= MACB_CAPS_FIFO_MODE; if (GEM_BFEXT(PBUF_RSC, gem_readl(bp, DCFG6))) bp->caps |= MACB_CAPS_RSC; - if (gem_has_ptp(bp)) { + if (gem_has_ptp(&bp->info)) { if (!GEM_BFEXT(TSU, gem_readl(bp, DCFG5))) dev_err(&bp->pdev->dev, "GEM doesn't support hardware ptp.\n"); @@ -5021,7 +5027,7 @@ static int macb_init_dflt(struct platform_device *pdev) netdev->netdev_ops = &macb_netdev_ops; /* setup appropriated routines according to adapter type */ - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { bp->macbgem_ops.mog_alloc_rx_buffers = gem_alloc_rx_buffers; bp->macbgem_ops.mog_free_rx_buffers = gem_free_rx_buffers; bp->macbgem_ops.mog_init_rings = gem_init_rings; @@ -5050,7 +5056,7 @@ static int macb_init_dflt(struct platform_device *pdev) netdev->hw_features |= MACB_NETIF_LSO; /* Checksum offload is only available on gem with packet buffer */ - if (macb_is_gem(bp) && !(bp->caps & MACB_CAPS_FIFO_MODE)) + if (macb_is_gem(&bp->info) && !(bp->caps & MACB_CAPS_FIFO_MODE)) netdev->hw_features |= NETIF_F_HW_CSUM | NETIF_F_RXCSUM; if (bp->caps & MACB_CAPS_SG_DISABLED) netdev->hw_features &= ~NETIF_F_SG; @@ -5177,7 +5183,7 @@ static int at91ether_alloc_coherent(struct macb *bp) rxq->ring = dma_alloc_coherent(&bp->pdev->dev, (AT91ETHER_MAX_RX_DESCR * - macb_dma_desc_get_size(bp)), + macb_dma_desc_get_size(&bp->info)), &rxq->ring_dma, GFP_KERNEL); if (!rxq->ring) return -ENOMEM; @@ -5190,7 +5196,7 @@ static int at91ether_alloc_coherent(struct macb *bp) if (!rxq->buffers) { dma_free_coherent(&bp->pdev->dev, AT91ETHER_MAX_RX_DESCR * - macb_dma_desc_get_size(bp), + macb_dma_desc_get_size(&bp->info), rxq->ring, rxq->ring_dma); rxq->ring = NULL; return -ENOMEM; @@ -5206,7 +5212,7 @@ static void at91ether_free_coherent(struct macb *bp) if (rxq->ring) { dma_free_coherent(&bp->pdev->dev, AT91ETHER_MAX_RX_DESCR * - macb_dma_desc_get_size(bp), + macb_dma_desc_get_size(&bp->info), rxq->ring, rxq->ring_dma); rxq->ring = NULL; } @@ -5237,7 +5243,7 @@ static int at91ether_start(struct macb *bp) addr = rxq->buffers_dma; for (i = 0; i < AT91ETHER_MAX_RX_DESCR; i++) { desc = macb_rx_desc(queue, i); - macb_set_addr(bp, desc, addr); + macb_set_addr(&bp->info, desc, addr); desc->ctrl = 0; addr += AT91ETHER_MAX_RBUFF_SZ; } @@ -5768,13 +5774,13 @@ static int macb_alloc_tieoff(struct macb *bp) return 0; bp->rx_ring_tieoff = dma_alloc_coherent(&bp->pdev->dev, - macb_dma_desc_get_size(bp), + macb_dma_desc_get_size(&bp->info), &bp->rx_ring_tieoff_dma, GFP_KERNEL); if (!bp->rx_ring_tieoff) return -ENOMEM; - macb_set_addr(bp, bp->rx_ring_tieoff, + macb_set_addr(&bp->info, bp->rx_ring_tieoff, MACB_BIT(RX_WRAP) | MACB_BIT(RX_USED)); bp->rx_ring_tieoff->ctrl = 0; @@ -5787,7 +5793,7 @@ static void macb_free_tieoff(struct macb *bp) if (!bp->rx_ring_tieoff) return; - dma_free_coherent(&bp->pdev->dev, macb_dma_desc_get_size(bp), + dma_free_coherent(&bp->pdev->dev, macb_dma_desc_get_size(&bp->info), bp->rx_ring_tieoff, bp->rx_ring_tieoff_dma); bp->rx_ring_tieoff = NULL; @@ -6178,12 +6184,12 @@ static int macb_probe(struct platform_device *pdev) val = GEM_BFEXT(RXBD_RDBUFF, gem_readl(bp, DCFG10)); if (val) bp->rx_bd_rd_prefetch = (2 << (val - 1)) * - macb_dma_desc_get_size(bp); + macb_dma_desc_get_size(&bp->info); val = GEM_BFEXT(TXBD_RDBUFF, gem_readl(bp, DCFG10)); if (val) bp->tx_bd_rd_prefetch = (2 << (val - 1)) * - macb_dma_desc_get_size(bp); + macb_dma_desc_get_size(&bp->info); } bp->rx_intr_mask = MACB_RX_INT_FLAGS; @@ -6228,8 +6234,9 @@ static int macb_probe(struct platform_device *pdev) } netdev_info(netdev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n", - macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID), - netdev->base_addr, netdev->irq, netdev->dev_addr); + macb_is_gem(&bp->info) ? "GEM" : "MACB", + macb_readl(bp, MID), netdev->base_addr, netdev->irq, + netdev->dev_addr); pm_runtime_put_autosuspend(&bp->pdev->dev); @@ -6361,7 +6368,7 @@ static int __maybe_unused macb_suspend(struct device *dev) tmp |= MACB_BFEXT(IP, ifa_local); } - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { queue_writel(bp->queues, IER, GEM_BIT(WOL)); gem_writel(bp, WOL, tmp); } else { @@ -6423,7 +6430,7 @@ static int __maybe_unused macb_resume(struct device *dev) if (bp->wol & MACB_WOL_ENABLED) { spin_lock_irqsave(&bp->lock, flags); /* Disable WoL */ - if (macb_is_gem(bp)) { + if (macb_is_gem(&bp->info)) { queue_writel(bp->queues, IDR, GEM_BIT(WOL)); gem_writel(bp, WOL, 0); } else { @@ -6451,7 +6458,7 @@ static int __maybe_unused macb_resume(struct device *dev) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { if (!(bp->caps & MACB_CAPS_MACB_IS_EMAC)) { - if (macb_is_gem(bp)) + if (macb_is_gem(&bp->info)) gem_init_rx_ring(queue); else macb_init_rx_ring(queue); diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index 2fd063394698..28e0e48b42d8 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -28,10 +28,10 @@ static struct macb_dma_desc_ptp *macb_ptp_desc(struct macb *bp, struct macb_dma_desc *desc) { - if (!macb_dma_ptp(bp)) + if (!macb_dma_ptp(&bp->info)) return NULL; - if (macb_dma64(bp)) + if (macb_dma64(&bp->info)) return (struct macb_dma_desc_ptp *) ((u8 *)desc + sizeof(struct macb_dma_desc) + sizeof(struct macb_dma_desc_64)); @@ -380,7 +380,7 @@ int gem_get_hwtst(struct net_device *netdev, struct macb *bp = netdev_priv(netdev); *tstamp_config = bp->tstamp_config; - if (!macb_dma_ptp(bp)) + if (!macb_dma_ptp(&bp->info)) return -EOPNOTSUPP; return 0; @@ -399,7 +399,7 @@ int gem_set_hwtst(struct net_device *netdev, u32 ncr_bits = 0; u32 regval; - if (!macb_dma_ptp(bp)) + if (!macb_dma_ptp(&bp->info)) return -EOPNOTSUPP; switch (tstamp_config->tx_type) { From ed16494c2c50efc4666bd3618f6644062e44a1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:44 +0200 Subject: [PATCH 1929/2126] net: macb: change function signatures to take contexts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For parallel MACB context to start become a reality, many functions need to stop operating on bp->ctx (the currently active context) and instead work on a context they get passed. That context might be (1) the new one that is getting allocated and initialised, or, (2) the old one to be freed. To reduce bug surface area, taint those functions to *only* take a context `struct macb_context *ctx` and no `struct macb *bp`. That way, no bug of using `bp->ctx` instead of `ctx` will ever occur. We also convert functions that take a `struct macb_queue *queue` to instead take `struct macb_context *ctx, unsigned int q`, with q indexing ctx->txq[] and ctx->rxq[]. Full list: macb_adj_dma_desc_idx() macb_tx_ring_wrap() macb_tx_desc() macb_rx_ring_wrap() macb_rx_desc() macb_get_addr() gem_rx_refill() macb_init_rx_ring() gem_free_rx_buffers() macb_free_rx_buffers() macb_tx_ring_size_per_queue() macb_rx_ring_size_per_queue() macb_free() gem_alloc_rx_buffers() macb_alloc_rx_buffers() macb_alloc() gem_init_rx_ring() gem_init_rings() macb_init_rings() Note about gem_rx_refill(): it ends with a netdev_vdbg() that prints the queue pointer. Change to print the queue index because we do not have access to the queue anymore. Note: functions that operate on the interface during its normal lifetime do not need to be converted and have no risk of using the wrong context. We do not allow concurrent swaps. When interface is alive, there can only be one context alive. Acked-by: Conor Dooley Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-6-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb.h | 7 +- drivers/net/ethernet/cadence/macb_main.c | 391 ++++++++++++----------- 2 files changed, 210 insertions(+), 188 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index ddbab4c78bf4..ec2e2fbc1146 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1193,11 +1193,12 @@ static const struct gem_statistic queue_statistics[] = { struct macb; struct macb_queue; +struct macb_context; struct macb_or_gem_ops { - int (*mog_alloc_rx_buffers)(struct macb *bp); - void (*mog_free_rx_buffers)(struct macb *bp); - int (*mog_init_rings)(struct macb *bp); + int (*mog_alloc_rx_buffers)(struct macb_context *ctx); + void (*mog_free_rx_buffers)(struct macb_context *ctx); + int (*mog_init_rings)(struct macb_context *ctx); int (*mog_rx)(struct macb_queue *queue, struct napi_struct *napi, int budget); }; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index ac5660480840..05169bbe2efc 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -138,9 +138,11 @@ static unsigned int macb_dma_desc_get_size(const struct macb_info *info) return desc_size; } -static unsigned int macb_adj_dma_desc_idx(struct macb *bp, unsigned int desc_idx) +static unsigned int macb_adj_dma_desc_idx(struct macb_context *ctx, + unsigned int desc_idx) { - return desc_idx * (1 + macb_dma64(&bp->info) + macb_dma_ptp(&bp->info)); + return desc_idx * (1 + macb_dma64(ctx->info) + + macb_dma_ptp(ctx->info)); } static struct macb_dma_desc_64 *macb_64b_desc(struct macb_dma_desc *desc) @@ -150,9 +152,10 @@ static struct macb_dma_desc_64 *macb_64b_desc(struct macb_dma_desc *desc) } /* Ring buffer accessors */ -static unsigned int macb_tx_ring_wrap(struct macb *bp, unsigned int index) +static unsigned int macb_tx_ring_wrap(struct macb_context *ctx, + unsigned int index) { - return index & (bp->ctx->tx_ring_size - 1); + return index & (ctx->tx_ring_size - 1); } static struct macb_txq *macb_txq(struct macb_queue *queue) @@ -171,14 +174,13 @@ static struct macb_rxq *macb_rxq(struct macb_queue *queue) return &bp->ctx->rxq[q]; } -static struct macb_dma_desc *macb_tx_desc(struct macb_queue *queue, +static struct macb_dma_desc *macb_tx_desc(struct macb_context *ctx, + unsigned int q, unsigned int index) { - struct macb_txq *txq = macb_txq(queue); - - index = macb_tx_ring_wrap(queue->bp, index); - index = macb_adj_dma_desc_idx(queue->bp, index); - return &txq->ring[index]; + index = macb_tx_ring_wrap(ctx, index); + index = macb_adj_dma_desc_idx(ctx, index); + return &ctx->txq[q].ring[index]; } static struct macb_tx_skb *macb_tx_skb(struct macb_queue *queue, @@ -186,40 +188,42 @@ static struct macb_tx_skb *macb_tx_skb(struct macb_queue *queue, { struct macb_txq *txq = macb_txq(queue); - return &txq->skb[macb_tx_ring_wrap(queue->bp, index)]; + return &txq->skb[macb_tx_ring_wrap(queue->bp->ctx, index)]; } static dma_addr_t macb_tx_dma(struct macb_queue *queue, unsigned int index) { + struct macb_context *ctx = queue->bp->ctx; struct macb_txq *txq = macb_txq(queue); dma_addr_t offset; - offset = macb_tx_ring_wrap(queue->bp, index) * + offset = macb_tx_ring_wrap(ctx, index) * macb_dma_desc_get_size(&queue->bp->info); return txq->ring_dma + offset; } -static unsigned int macb_rx_ring_wrap(struct macb *bp, unsigned int index) +static unsigned int macb_rx_ring_wrap(struct macb_context *ctx, + unsigned int index) { - return index & (bp->ctx->rx_ring_size - 1); + return index & (ctx->rx_ring_size - 1); } -static struct macb_dma_desc *macb_rx_desc(struct macb_queue *queue, unsigned int index) +static struct macb_dma_desc *macb_rx_desc(struct macb_context *ctx, + unsigned int q, unsigned int index) { - struct macb_rxq *rxq = macb_rxq(queue); - - index = macb_rx_ring_wrap(queue->bp, index); - index = macb_adj_dma_desc_idx(queue->bp, index); - return &rxq->ring[index]; + index = macb_rx_ring_wrap(ctx, index); + index = macb_adj_dma_desc_idx(ctx, index); + return &ctx->rxq[q].ring[index]; } static void *macb_rx_buffer(struct macb_queue *queue, unsigned int index) { + struct macb_context *ctx = queue->bp->ctx; struct macb_rxq *rxq = macb_rxq(queue); - return rxq->buffers + queue->bp->ctx->rx_buffer_size * - macb_rx_ring_wrap(queue->bp, index); + return rxq->buffers + ctx->rx_buffer_size * + macb_rx_ring_wrap(ctx, index); } /* I/O accessors */ @@ -841,13 +845,14 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) unsigned int head, tail, count, ring_size, desc_size; struct macb_tx_skb tx_skb, *skb_curr, *skb_next; struct macb_dma_desc *desc_curr, *desc_next; + unsigned int q = queue - queue->bp->queues; unsigned int i, cycles, shift, curr, next; + struct macb_context *ctx = queue->bp->ctx; struct macb_txq *txq = macb_txq(queue); - struct macb *bp = queue->bp; unsigned char desc[24]; unsigned long flags; - desc_size = macb_dma_desc_get_size(&bp->info); + desc_size = macb_dma_desc_get_size(&queue->bp->info); if (WARN_ON_ONCE(desc_size > ARRAY_SIZE(desc))) return; @@ -855,7 +860,7 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) spin_lock_irqsave(&queue->tx_ptr_lock, flags); head = txq->head; tail = txq->tail; - ring_size = bp->ctx->tx_ring_size; + ring_size = ctx->tx_ring_size; count = CIRC_CNT(head, tail, ring_size); if (!(tail % ring_size)) @@ -871,7 +876,7 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) cycles = gcd(ring_size, shift); for (i = 0; i < cycles; i++) { - memcpy(&desc, macb_tx_desc(queue, i), desc_size); + memcpy(&desc, macb_tx_desc(ctx, q, i), desc_size); memcpy(&tx_skb, macb_tx_skb(queue, i), sizeof(struct macb_tx_skb)); @@ -879,8 +884,8 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) next = (curr + shift) % ring_size; while (next != i) { - desc_curr = macb_tx_desc(queue, curr); - desc_next = macb_tx_desc(queue, next); + desc_curr = macb_tx_desc(ctx, q, curr); + desc_next = macb_tx_desc(ctx, q, next); memcpy(desc_curr, desc_next, desc_size); @@ -897,7 +902,7 @@ static void gem_shuffle_tx_one_ring(struct macb_queue *queue) next = (curr + shift) % ring_size; } - desc_curr = macb_tx_desc(queue, curr); + desc_curr = macb_tx_desc(ctx, q, curr); memcpy(desc_curr, &desc, desc_size); if (i == ring_size - 1) desc_curr->ctrl &= ~MACB_BIT(TX_WRAP); @@ -1291,19 +1296,19 @@ static void macb_set_addr(const struct macb_info *info, desc->addr = lower_32_bits(addr); } -static dma_addr_t macb_get_addr(const struct macb_info *info, +static dma_addr_t macb_get_addr(struct macb_context *ctx, struct macb_dma_desc *desc) { dma_addr_t addr = 0; - if (macb_dma64(info)) { + if (macb_dma64(ctx->info)) { struct macb_dma_desc_64 *desc_64; desc_64 = macb_64b_desc(desc); addr = ((u64)(desc_64->addrh) << 32); } addr |= MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr)); - if (macb_dma_ptp(info)) + if (macb_dma_ptp(ctx->info)) addr &= ~GEM_BIT(DMA_RXVALID); return addr; } @@ -1313,6 +1318,7 @@ static void macb_tx_error_task(struct work_struct *work) struct macb_queue *queue = container_of(work, struct macb_queue, tx_error_task); unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; struct macb_txq *txq = macb_txq(queue); struct macb *bp = queue->bp; struct macb_tx_skb *tx_skb; @@ -1355,7 +1361,7 @@ static void macb_tx_error_task(struct work_struct *work) for (tail = txq->tail; tail != txq->head; tail++) { u32 ctrl; - desc = macb_tx_desc(queue, tail); + desc = macb_tx_desc(ctx, q, tail); ctrl = desc->ctrl; tx_skb = macb_tx_skb(queue, tail); skb = tx_skb->skb; @@ -1374,7 +1380,7 @@ static void macb_tx_error_task(struct work_struct *work) */ if (!(ctrl & MACB_BIT(TX_BUF_EXHAUSTED))) { netdev_vdbg(bp->netdev, "txerr skb %u (data %p) TX complete\n", - macb_tx_ring_wrap(bp, tail), + macb_tx_ring_wrap(ctx, tail), skb->data); bp->netdev->stats.tx_packets++; queue->stats.tx_packets++; @@ -1401,7 +1407,7 @@ static void macb_tx_error_task(struct work_struct *work) packets, bytes); /* Set end of TX queue */ - desc = macb_tx_desc(queue, 0); + desc = macb_tx_desc(ctx, q, 0); macb_set_addr(&bp->info, desc, 0); desc->ctrl = MACB_BIT(TX_USED); @@ -1471,6 +1477,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) struct macb *bp = queue->bp; struct macb_txq *txq = macb_txq(queue); unsigned int q = queue - bp->queues; + struct macb_context *ctx = bp->ctx; unsigned long flags; unsigned int tail; unsigned int head; @@ -1485,7 +1492,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) struct macb_dma_desc *desc; u32 ctrl; - desc = macb_tx_desc(queue, tail); + desc = macb_tx_desc(ctx, q, tail); /* Make hw descriptor updates visible to CPU */ rmb(); @@ -1510,7 +1517,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) gem_ptp_do_txstamp(bp, skb, desc); netdev_vdbg(bp->netdev, "skb %u (data %p) TX complete\n", - macb_tx_ring_wrap(bp, tail), + macb_tx_ring_wrap(ctx, tail), skb->data); bp->netdev->stats.tx_packets++; queue->stats.tx_packets++; @@ -1548,53 +1555,53 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) return packets; } -static int gem_rx_refill(struct macb_queue *queue) +static int gem_rx_refill(struct macb_context *ctx, unsigned int q) { - struct macb_rxq *rxq = macb_rxq(queue); - struct macb *bp = queue->bp; + struct device *dev = &ctx->info->pdev->dev; + struct macb_rxq *rxq = &ctx->rxq[q]; struct macb_dma_desc *desc; struct sk_buff *skb; unsigned int entry; dma_addr_t paddr; while (CIRC_SPACE(rxq->prepared_head, rxq->tail, - bp->ctx->rx_ring_size) > 0) { - entry = macb_rx_ring_wrap(bp, rxq->prepared_head); + ctx->rx_ring_size) > 0) { + entry = macb_rx_ring_wrap(ctx, rxq->prepared_head); /* Make hw descriptor updates visible to CPU */ rmb(); - desc = macb_rx_desc(queue, entry); + desc = macb_rx_desc(ctx, q, entry); if (!rxq->skbuff[entry]) { /* allocate sk_buff for this free entry in ring */ - skb = netdev_alloc_skb(bp->netdev, - bp->ctx->rx_buffer_size); + skb = netdev_alloc_skb(ctx->info->netdev, + ctx->rx_buffer_size); if (unlikely(!skb)) { - netdev_err(bp->netdev, + netdev_err(ctx->info->netdev, "Unable to allocate sk_buff\n"); break; } /* now fill corresponding descriptor entry */ - paddr = dma_map_single(&bp->pdev->dev, skb->data, - bp->ctx->rx_buffer_size, + paddr = dma_map_single(dev, skb->data, + ctx->rx_buffer_size, DMA_FROM_DEVICE); - if (dma_mapping_error(&bp->pdev->dev, paddr)) { + if (dma_mapping_error(dev, paddr)) { dev_kfree_skb(skb); break; } rxq->skbuff[entry] = skb; - if (entry == bp->ctx->rx_ring_size - 1) + if (entry == ctx->rx_ring_size - 1) paddr |= MACB_BIT(RX_WRAP); desc->ctrl = 0; /* Setting addr clears RX_USED and allows reception, * make sure ctrl is cleared first to avoid a race. */ dma_wmb(); - macb_set_addr(&bp->info, desc, paddr); + macb_set_addr(ctx->info, desc, paddr); /* Properly align Ethernet header. * @@ -1607,7 +1614,7 @@ static int gem_rx_refill(struct macb_queue *queue) * setting the low 2/3 bits. * It is 3 bits if HW_DMA_CAP_PTP, else 2 bits. */ - if (!(bp->caps & MACB_CAPS_RSC)) + if (!(ctx->info->caps & MACB_CAPS_RSC)) skb_reserve(skb, NET_IP_ALIGN); } else { desc->ctrl = 0; @@ -1620,8 +1627,9 @@ static int gem_rx_refill(struct macb_queue *queue) /* Make descriptor updates visible to hardware */ wmb(); - netdev_vdbg(bp->netdev, "rx ring: queue: %p, prepared head %d, tail %d\n", - queue, rxq->prepared_head, rxq->tail); + netdev_vdbg(ctx->info->netdev, + "rx ring: queue: %u, prepared head %d, tail %d\n", + q, rxq->prepared_head, rxq->tail); /* Fail if queue has zero prepared descriptors. This is critical because * nothing will ever trigger a refill again. @@ -1636,10 +1644,12 @@ static int gem_rx_refill(struct macb_queue *queue) static void discard_partial_frame(struct macb_queue *queue, unsigned int begin, unsigned int end) { + unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; unsigned int frag; for (frag = begin; frag != end; frag++) { - struct macb_dma_desc *desc = macb_rx_desc(queue, frag); + struct macb_dma_desc *desc = macb_rx_desc(ctx, q, frag); desc->addr &= ~MACB_BIT(RX_USED); } @@ -1656,6 +1666,8 @@ static void discard_partial_frame(struct macb_queue *queue, unsigned int begin, static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, int budget) { + unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; struct macb_rxq *rxq = macb_rxq(queue); struct macb *bp = queue->bp; struct macb_dma_desc *desc; @@ -1676,14 +1688,14 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, if (rxq->tail == rxq->prepared_head) break; - entry = macb_rx_ring_wrap(bp, rxq->tail); - desc = macb_rx_desc(queue, entry); + entry = macb_rx_ring_wrap(ctx, rxq->tail); + desc = macb_rx_desc(ctx, q, entry); /* Make hw descriptor updates visible to CPU */ rmb(); rxused = (desc->addr & MACB_BIT(RX_USED)) ? true : false; - addr = macb_get_addr(&bp->info, desc); + addr = macb_get_addr(ctx, desc); if (!rxused) break; @@ -1748,7 +1760,7 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, napi_gro_receive(napi, skb); } - gem_rx_refill(queue); + gem_rx_refill(ctx, q); return count; } @@ -1756,6 +1768,8 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, unsigned int first_frag, unsigned int last_frag) { + unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; struct macb *bp = queue->bp; struct macb_dma_desc *desc; unsigned int offset; @@ -1763,13 +1777,13 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, unsigned int frag; unsigned int len; - desc = macb_rx_desc(queue, last_frag); + desc = macb_rx_desc(ctx, q, last_frag); len = desc->ctrl & bp->rx_frm_len_mask; netdev_vdbg(bp->netdev, "%s frags %u - %u (len %u)\n", __func__, - macb_rx_ring_wrap(bp, first_frag), - macb_rx_ring_wrap(bp, last_frag), len); + macb_rx_ring_wrap(ctx, first_frag), + macb_rx_ring_wrap(ctx, last_frag), len); /* The ethernet header starts NET_IP_ALIGN bytes into the * first buffer. Since the header is 14 bytes, this makes the @@ -1783,7 +1797,7 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, if (!skb) { bp->netdev->stats.rx_dropped++; for (frag = first_frag; ; frag++) { - desc = macb_rx_desc(queue, frag); + desc = macb_rx_desc(ctx, q, frag); desc->addr &= ~MACB_BIT(RX_USED); if (frag == last_frag) break; @@ -1814,7 +1828,7 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, macb_rx_buffer(queue, frag), frag_len); offset += bp->ctx->rx_buffer_size; - desc = macb_rx_desc(queue, frag); + desc = macb_rx_desc(ctx, q, frag); desc->addr &= ~MACB_BIT(RX_USED); if (frag == last_frag) @@ -1836,20 +1850,19 @@ static int macb_rx_frame(struct macb_queue *queue, struct napi_struct *napi, return 0; } -static inline void macb_init_rx_ring(struct macb_queue *queue) +static inline void macb_init_rx_ring(struct macb_context *ctx, unsigned int q) { - struct macb_rxq *rxq = macb_rxq(queue); + struct macb_rxq *rxq = &ctx->rxq[q]; struct macb_dma_desc *desc = NULL; - struct macb *bp = queue->bp; dma_addr_t addr; int i; addr = rxq->buffers_dma; - for (i = 0; i < bp->ctx->rx_ring_size; i++) { - desc = macb_rx_desc(queue, i); - macb_set_addr(&bp->info, desc, addr); + for (i = 0; i < ctx->rx_ring_size; i++) { + desc = macb_rx_desc(ctx, q, i); + macb_set_addr(ctx->info, desc, addr); desc->ctrl = 0; - addr += bp->ctx->rx_buffer_size; + addr += ctx->rx_buffer_size; } desc->addr |= MACB_BIT(RX_WRAP); rxq->tail = 0; @@ -1858,6 +1871,8 @@ static inline void macb_init_rx_ring(struct macb_queue *queue) static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, int budget) { + unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; struct macb_rxq *rxq = macb_rxq(queue); struct macb *bp = queue->bp; bool reset_rx_queue = false; @@ -1866,7 +1881,7 @@ static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, int received = 0; for (tail = rxq->tail; budget > 0; tail++) { - struct macb_dma_desc *desc = macb_rx_desc(queue, tail); + struct macb_dma_desc *desc = macb_rx_desc(ctx, q, tail); u32 ctrl; /* Make hw descriptor updates visible to CPU */ @@ -1918,7 +1933,7 @@ static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, ctrl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE)); - macb_init_rx_ring(queue); + macb_init_rx_ring(ctx, q); queue_writel(queue, RBQP, rxq->ring_dma); macb_writel(bp, NCR, ctrl | MACB_BIT(RE)); @@ -1937,17 +1952,18 @@ static int macb_rx(struct macb_queue *queue, struct napi_struct *napi, static bool macb_rx_pending(struct macb_queue *queue) { + unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; struct macb_rxq *rxq = macb_rxq(queue); - struct macb *bp = queue->bp; struct macb_dma_desc *desc; unsigned int entry; /* No armed descriptor left: nothing can be pending. */ - if (macb_is_gem(&bp->info) && rxq->tail == rxq->prepared_head) + if (macb_is_gem(&queue->bp->info) && rxq->tail == rxq->prepared_head) return false; - entry = macb_rx_ring_wrap(bp, rxq->tail); - desc = macb_rx_desc(queue, entry); + entry = macb_rx_ring_wrap(ctx, rxq->tail); + desc = macb_rx_desc(ctx, q, entry); /* Make hw descriptor updates visible to CPU */ rmb(); @@ -1994,6 +2010,7 @@ static int macb_rx_poll(struct napi_struct *napi, int budget) static void macb_tx_restart(struct macb_queue *queue) { + struct macb_context *ctx = queue->bp->ctx; struct macb_txq *txq = macb_txq(queue); struct macb *bp = queue->bp; unsigned int head_idx, tbqp; @@ -2004,9 +2021,9 @@ static void macb_tx_restart(struct macb_queue *queue) if (txq->head == txq->tail) goto out_tx_ptr_unlock; - tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(&bp->info); - tbqp = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, tbqp)); - head_idx = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, txq->head)); + tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(ctx->info); + tbqp = macb_adj_dma_desc_idx(ctx, macb_tx_ring_wrap(ctx, tbqp)); + head_idx = macb_adj_dma_desc_idx(ctx, macb_tx_ring_wrap(ctx, txq->head)); if (tbqp == head_idx) goto out_tx_ptr_unlock; @@ -2021,6 +2038,8 @@ out_tx_ptr_unlock: static bool macb_tx_complete_pending(struct macb_queue *queue) { + unsigned int q = queue - queue->bp->queues; + struct macb_context *ctx = queue->bp->ctx; struct macb_txq *txq = macb_txq(queue); bool retval = false; unsigned long flags; @@ -2030,7 +2049,7 @@ static bool macb_tx_complete_pending(struct macb_queue *queue) /* Make hw descriptor updates visible to CPU */ rmb(); - if (macb_tx_desc(queue, txq->tail)->ctrl & MACB_BIT(TX_USED)) + if (macb_tx_desc(ctx, q, txq->tail)->ctrl & MACB_BIT(TX_USED)) retval = true; } spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); @@ -2136,6 +2155,7 @@ static void macb_hresp_error_task(struct work_struct *work) { struct macb *bp = from_work(bp, work, hresp_err_bh_work); struct net_device *netdev = bp->netdev; + struct macb_context *ctx = bp->ctx; struct macb_queue *queue; unsigned int q; u32 ctrl; @@ -2152,7 +2172,7 @@ static void macb_hresp_error_task(struct work_struct *work) netif_tx_stop_all_queues(netdev); netif_carrier_off(netdev); - bp->macbgem_ops.mog_init_rings(bp); + bp->macbgem_ops.mog_init_rings(ctx); /* Initialize TX and RX buffers */ macb_init_buffers(bp); @@ -2354,6 +2374,8 @@ static unsigned int macb_tx_map(struct macb *bp, unsigned int f, nr_frags = skb_shinfo(skb)->nr_frags; unsigned int len, i, tx_head = txq->head; u32 ctrl, lso_ctrl = 0, seq_ctrl = 0; + unsigned int q = queue - bp->queues; + struct macb_context *ctx = bp->ctx; unsigned int eof = 1, mss_mfs = 0; struct macb_tx_skb *tx_skb = NULL; struct macb_dma_desc *desc; @@ -2445,7 +2467,7 @@ static unsigned int macb_tx_map(struct macb *bp, */ i = tx_head; ctrl = MACB_BIT(TX_USED); - desc = macb_tx_desc(queue, i); + desc = macb_tx_desc(ctx, q, i); desc->ctrl = ctrl; if (lso_ctrl) { @@ -2466,14 +2488,14 @@ static unsigned int macb_tx_map(struct macb *bp, do { i--; tx_skb = macb_tx_skb(queue, i); - desc = macb_tx_desc(queue, i); + desc = macb_tx_desc(ctx, q, i); ctrl = (u32)tx_skb->size; if (eof) { ctrl |= MACB_BIT(TX_LAST); eof = 0; } - if (unlikely(macb_tx_ring_wrap(bp, i) == + if (unlikely(macb_tx_ring_wrap(ctx, i) == bp->ctx->tx_ring_size - 1)) ctrl |= MACB_BIT(TX_WRAP); @@ -2769,33 +2791,32 @@ static unsigned int macb_rx_buffer_size(struct macb *bp, unsigned int mtu) return size; } -static void gem_free_rx_buffers(struct macb *bp) +static void gem_free_rx_buffers(struct macb_context *ctx) { + struct device *dev = &ctx->info->pdev->dev; struct macb_dma_desc *desc; - struct macb_queue *queue; struct macb_rxq *rxq; struct sk_buff *skb; dma_addr_t addr; unsigned int q; int i; - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - rxq = &bp->ctx->rxq[q]; + for (q = 0; q < ctx->info->num_queues; ++q) { + rxq = &ctx->rxq[q]; if (!rxq->skbuff) continue; - for (i = 0; i < bp->ctx->rx_ring_size; i++) { + for (i = 0; i < ctx->rx_ring_size; i++) { skb = rxq->skbuff[i]; if (!skb) continue; - desc = macb_rx_desc(queue, i); - addr = macb_get_addr(&bp->info, desc); + desc = macb_rx_desc(ctx, q, i); + addr = macb_get_addr(ctx, desc); - dma_unmap_single(&bp->pdev->dev, addr, - bp->ctx->rx_buffer_size, + dma_unmap_single(dev, addr, ctx->rx_buffer_size, DMA_FROM_DEVICE); dev_kfree_skb_any(skb); skb = NULL; @@ -2806,67 +2827,66 @@ static void gem_free_rx_buffers(struct macb *bp) } } -static void macb_free_rx_buffers(struct macb *bp) +static void macb_free_rx_buffers(struct macb_context *ctx) { - struct macb_rxq *rxq = &bp->ctx->rxq[0]; + struct device *dev = &ctx->info->pdev->dev; + struct macb_rxq *rxq = &ctx->rxq[0]; if (rxq->buffers) { - dma_free_coherent(&bp->pdev->dev, - bp->ctx->rx_ring_size * - bp->ctx->rx_buffer_size, + dma_free_coherent(dev, + ctx->rx_ring_size * ctx->rx_buffer_size, rxq->buffers, rxq->buffers_dma); rxq->buffers = NULL; } } -static unsigned int macb_tx_ring_size_per_queue(struct macb *bp) +static unsigned int macb_tx_ring_size_per_queue(struct macb_context *ctx) { - return macb_dma_desc_get_size(&bp->info) * bp->ctx->tx_ring_size + - bp->tx_bd_rd_prefetch; + return macb_dma_desc_get_size(ctx->info) * ctx->tx_ring_size + + ctx->info->tx_bd_rd_prefetch; } -static unsigned int macb_rx_ring_size_per_queue(struct macb *bp) +static unsigned int macb_rx_ring_size_per_queue(struct macb_context *ctx) { - return macb_dma_desc_get_size(&bp->info) * bp->ctx->rx_ring_size + - bp->rx_bd_rd_prefetch; + return macb_dma_desc_get_size(ctx->info) * ctx->rx_ring_size + + ctx->info->rx_bd_rd_prefetch; } -static void macb_free(struct macb *bp) +static void macb_free(struct macb_context *ctx) { - struct device *dev = &bp->pdev->dev; - struct macb_queue *queue; + struct device *dev = &ctx->info->pdev->dev; struct macb_txq *txq; struct macb_rxq *rxq; unsigned int q; size_t size; - bp->macbgem_ops.mog_free_rx_buffers(bp); + ctx->info->macbgem_ops.mog_free_rx_buffers(ctx); - txq = &bp->ctx->txq[0]; - size = bp->num_queues * macb_tx_ring_size_per_queue(bp); + txq = &ctx->txq[0]; + size = ctx->info->num_queues * macb_tx_ring_size_per_queue(ctx); dma_free_coherent(dev, size, txq->ring, txq->ring_dma); - rxq = &bp->ctx->rxq[0]; - size = bp->num_queues * macb_rx_ring_size_per_queue(bp); + rxq = &ctx->rxq[0]; + size = ctx->info->num_queues * macb_rx_ring_size_per_queue(ctx); dma_free_coherent(dev, size, rxq->ring, rxq->ring_dma); - for (q = 0; q < bp->num_queues; ++q) { - txq = &bp->ctx->txq[q]; - rxq = &bp->ctx->rxq[q]; - queue = &bp->queues[q]; + for (q = 0; q < ctx->info->num_queues; ++q) { + txq = &ctx->txq[q]; + rxq = &ctx->rxq[q]; if (txq->skb) { unsigned int dropped = 0, tail; for (tail = txq->tail; tail != txq->head; tail++) { - if (macb_tx_skb(queue, tail)->skb) + if (txq->skb[macb_tx_ring_wrap(ctx, tail)].skb) dropped++; - macb_tx_unmap(&bp->info, - macb_tx_skb(queue, tail), 0); + macb_tx_unmap(ctx->info, + &txq->skb[macb_tx_ring_wrap(ctx, tail)], + 0); } - queue->stats.tx_dropped += dropped; - bp->netdev->stats.tx_dropped += dropped; + ctx->info->queue_stats[q]->tx_dropped += dropped; + ctx->info->netdev->stats.tx_dropped += dropped; kfree(txq->skb); txq->skb = NULL; @@ -2877,46 +2897,48 @@ static void macb_free(struct macb *bp) } } -static int gem_alloc_rx_buffers(struct macb *bp) +static int gem_alloc_rx_buffers(struct macb_context *ctx) { struct macb_rxq *rxq; unsigned int q; int size; - for (q = 0; q < bp->num_queues; ++q) { - rxq = &bp->ctx->rxq[q]; - size = bp->ctx->rx_ring_size * sizeof(struct sk_buff *); + for (q = 0; q < ctx->info->num_queues; ++q) { + rxq = &ctx->rxq[q]; + size = ctx->rx_ring_size * sizeof(struct sk_buff *); rxq->skbuff = kzalloc(size, GFP_KERNEL); if (!rxq->skbuff) return -ENOMEM; else - netdev_dbg(bp->netdev, + netdev_dbg(ctx->info->netdev, "Allocated %d RX struct sk_buff entries at %p\n", - bp->ctx->rx_ring_size, rxq->skbuff); + ctx->rx_ring_size, rxq->skbuff); } return 0; } -static int macb_alloc_rx_buffers(struct macb *bp) +static int macb_alloc_rx_buffers(struct macb_context *ctx) { - struct macb_rxq *rxq = &bp->ctx->rxq[0]; + struct device *dev = &ctx->info->pdev->dev; + struct macb_rxq *rxq = &ctx->rxq[0]; int size; - size = bp->ctx->rx_ring_size * bp->ctx->rx_buffer_size; - rxq->buffers = dma_alloc_coherent(&bp->pdev->dev, size, + size = ctx->rx_ring_size * ctx->rx_buffer_size; + rxq->buffers = dma_alloc_coherent(dev, size, &rxq->buffers_dma, GFP_KERNEL); if (!rxq->buffers) return -ENOMEM; - netdev_dbg(bp->netdev, + netdev_dbg(ctx->info->netdev, "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n", size, (unsigned long)rxq->buffers_dma, rxq->buffers); return 0; } -static int macb_alloc(struct macb *bp) +static int macb_alloc(struct macb_context *ctx) { - struct device *dev = &bp->pdev->dev; + unsigned int num_queues = ctx->info->num_queues; + struct device *dev = &ctx->info->pdev->dev; dma_addr_t tx_dma, rx_dma; struct macb_txq *txq; struct macb_rxq *rxq; @@ -2931,75 +2953,75 @@ static int macb_alloc(struct macb *bp) * natural alignment of physical addresses. */ - size = bp->num_queues * macb_tx_ring_size_per_queue(bp); + size = num_queues * macb_tx_ring_size_per_queue(ctx); tx = dma_alloc_coherent(dev, size, &tx_dma, GFP_KERNEL); if (!tx) goto out_err; /* Record the buffer so that the error path frees it. */ - txq = &bp->ctx->txq[0]; + txq = &ctx->txq[0]; txq->ring = tx; txq->ring_dma = tx_dma; if (upper_32_bits(tx_dma) != upper_32_bits(tx_dma + size - 1)) goto out_err; - netdev_dbg(bp->netdev, "Allocated %zu bytes for %u TX rings at %08lx (mapped %p)\n", - size, bp->num_queues, (unsigned long)tx_dma, tx); + netdev_dbg(ctx->info->netdev, + "Allocated %zu bytes for %u TX rings at %08lx (mapped %p)\n", + size, num_queues, (unsigned long)tx_dma, tx); - size = bp->num_queues * macb_rx_ring_size_per_queue(bp); + size = num_queues * macb_rx_ring_size_per_queue(ctx); rx = dma_alloc_coherent(dev, size, &rx_dma, GFP_KERNEL); if (!rx) goto out_err; /* Record the buffer so that the error path frees it. */ - rxq = &bp->ctx->rxq[0]; + rxq = &ctx->rxq[0]; rxq->ring = rx; rxq->ring_dma = rx_dma; if (upper_32_bits(rx_dma) != upper_32_bits(rx_dma + size - 1)) goto out_err; - netdev_dbg(bp->netdev, "Allocated %zu bytes for %u RX rings at %08lx (mapped %p)\n", - size, bp->num_queues, (unsigned long)rx_dma, rx); + netdev_dbg(ctx->info->netdev, + "Allocated %zu bytes for %u RX rings at %08lx (mapped %p)\n", + size, num_queues, (unsigned long)rx_dma, rx); - for (q = 0; q < bp->num_queues; ++q) { - txq = &bp->ctx->txq[q]; - rxq = &bp->ctx->rxq[q]; + for (q = 0; q < num_queues; ++q) { + txq = &ctx->txq[q]; + rxq = &ctx->rxq[q]; - txq->ring = tx + macb_tx_ring_size_per_queue(bp) * q; - txq->ring_dma = tx_dma + macb_tx_ring_size_per_queue(bp) * q; + txq->ring = tx + macb_tx_ring_size_per_queue(ctx) * q; + txq->ring_dma = tx_dma + macb_tx_ring_size_per_queue(ctx) * q; - rxq->ring = rx + macb_rx_ring_size_per_queue(bp) * q; - rxq->ring_dma = rx_dma + macb_rx_ring_size_per_queue(bp) * q; + rxq->ring = rx + macb_rx_ring_size_per_queue(ctx) * q; + rxq->ring_dma = rx_dma + macb_rx_ring_size_per_queue(ctx) * q; - size = bp->ctx->tx_ring_size * sizeof(struct macb_tx_skb); + size = ctx->tx_ring_size * sizeof(struct macb_tx_skb); txq->skb = kmalloc(size, GFP_KERNEL); if (!txq->skb) goto out_err; } - if (bp->macbgem_ops.mog_alloc_rx_buffers(bp)) + if (ctx->info->macbgem_ops.mog_alloc_rx_buffers(ctx)) goto out_err; return 0; out_err: - macb_free(bp); + macb_free(ctx); return -ENOMEM; } -static int gem_init_rx_ring(struct macb_queue *queue) +static int gem_init_rx_ring(struct macb_context *ctx, unsigned int q) { - struct macb_context *ctx = queue->bp->ctx; - struct macb_rxq *rxq = macb_rxq(queue); + struct macb_rxq *rxq = &ctx->rxq[q]; unsigned int i; rxq->tail = 0; rxq->prepared_head = 0; for (i = 0; i < ctx->rx_ring_size; i++) - macb_rx_desc(queue, i)->addr |= MACB_BIT(RX_USED); + macb_rx_desc(ctx, q, i)->addr |= MACB_BIT(RX_USED); - return gem_rx_refill(queue); + return gem_rx_refill(ctx, q); } -static int gem_init_rings(struct macb *bp) +static int gem_init_rings(struct macb_context *ctx) { - struct macb_queue *queue; struct macb_dma_desc *desc = NULL; struct macb_txq *txq; int last_err = 0; @@ -3007,18 +3029,18 @@ static int gem_init_rings(struct macb *bp) int err; int i; - for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - txq = &bp->ctx->txq[q]; - for (i = 0; i < bp->ctx->tx_ring_size; i++) { - desc = macb_tx_desc(queue, i); - macb_set_addr(&bp->info, desc, 0); + for (q = 0; q < ctx->info->num_queues; ++q) { + txq = &ctx->txq[q]; + for (i = 0; i < ctx->tx_ring_size; i++) { + desc = macb_tx_desc(ctx, q, i); + macb_set_addr(ctx->info, desc, 0); desc->ctrl = MACB_BIT(TX_USED); } desc->ctrl |= MACB_BIT(TX_WRAP); txq->head = 0; txq->tail = 0; - err = gem_init_rx_ring(queue); + err = gem_init_rx_ring(ctx, q); if (err) last_err = err; } @@ -3026,17 +3048,17 @@ static int gem_init_rings(struct macb *bp) return last_err; } -static int macb_init_rings(struct macb *bp) +static int macb_init_rings(struct macb_context *ctx) { - struct macb_txq *txq = &bp->ctx->txq[0]; + struct macb_txq *txq = &ctx->txq[0]; struct macb_dma_desc *desc = NULL; int i; - macb_init_rx_ring(&bp->queues[0]); + macb_init_rx_ring(ctx, 0); - for (i = 0; i < bp->ctx->tx_ring_size; i++) { - desc = macb_tx_desc(&bp->queues[0], i); - macb_set_addr(&bp->info, desc, 0); + for (i = 0; i < ctx->tx_ring_size; i++) { + desc = macb_tx_desc(ctx, 0, i); + macb_set_addr(ctx->info, desc, 0); desc->ctrl = MACB_BIT(TX_USED); } txq->head = 0; @@ -3376,14 +3398,14 @@ static int macb_open(struct net_device *netdev) bp->ctx->rx_ring_size = bp->configured_rx_ring_size; bp->ctx->tx_ring_size = bp->configured_tx_ring_size; - err = macb_alloc(bp); + err = macb_alloc(bp->ctx); if (err) { netdev_err(netdev, "Unable to allocate DMA memory (error %d)\n", err); goto free_ctx; } - err = bp->macbgem_ops.mog_init_rings(bp); + err = bp->macbgem_ops.mog_init_rings(bp->ctx); if (err) goto free_rings; macb_init_buffers(bp); @@ -3420,7 +3442,7 @@ reset_hw: macb_reset_hw(bp); free_rings: - macb_free(bp); + macb_free(bp->ctx); free_ctx: kfree(bp->ctx); bp->ctx = NULL; @@ -3454,7 +3476,7 @@ static int macb_close(struct net_device *netdev) netif_carrier_off(netdev); spin_unlock_irqrestore(&bp->lock, flags); - macb_free(bp); + macb_free(bp->ctx); kfree(bp->ctx); bp->ctx = NULL; @@ -3833,8 +3855,8 @@ static void macb_get_regs(struct net_device *netdev, struct ethtool_regs *regs, if (bp->ctx) { txq = &bp->ctx->txq[0]; - tail = macb_tx_ring_wrap(bp, txq->tail); - head = macb_tx_ring_wrap(bp, txq->head); + tail = macb_tx_ring_wrap(bp->ctx, txq->tail); + head = macb_tx_ring_wrap(bp->ctx, txq->head); tx_dma_tail = macb_tx_dma(&bp->queues[0], tail); tx_dma_head = macb_tx_dma(&bp->queues[0], head); } @@ -5229,7 +5251,6 @@ static void at91ether_free_coherent(struct macb *bp) /* Initialize and start the Receiver and Transmit subsystems */ static int at91ether_start(struct macb *bp) { - struct macb_queue *queue = &bp->queues[0]; struct macb_rxq *rxq = &bp->ctx->rxq[0]; struct macb_dma_desc *desc; dma_addr_t addr; @@ -5242,7 +5263,7 @@ static int at91ether_start(struct macb *bp) addr = rxq->buffers_dma; for (i = 0; i < AT91ETHER_MAX_RX_DESCR; i++) { - desc = macb_rx_desc(queue, i); + desc = macb_rx_desc(bp->ctx, 0, i); macb_set_addr(&bp->info, desc, addr); desc->ctrl = 0; addr += AT91ETHER_MAX_RBUFF_SZ; @@ -5408,14 +5429,13 @@ static netdev_tx_t at91ether_start_xmit(struct sk_buff *skb, static void at91ether_rx(struct net_device *netdev) { struct macb *bp = netdev_priv(netdev); - struct macb_queue *queue = &bp->queues[0]; struct macb_rxq *rxq = &bp->ctx->rxq[0]; struct macb_dma_desc *desc; unsigned char *p_recv; struct sk_buff *skb; unsigned int pktlen; - desc = macb_rx_desc(queue, rxq->tail); + desc = macb_rx_desc(bp->ctx, 0, rxq->tail); while (desc->addr & MACB_BIT(RX_USED)) { p_recv = rxq->buffers + rxq->tail * AT91ETHER_MAX_RBUFF_SZ; pktlen = MACB_BF(RX_FRMLEN, desc->ctrl); @@ -5444,7 +5464,7 @@ static void at91ether_rx(struct net_device *netdev) else rxq->tail++; - desc = macb_rx_desc(queue, rxq->tail); + desc = macb_rx_desc(bp->ctx, 0, rxq->tail); } } @@ -6414,6 +6434,7 @@ static int __maybe_unused macb_resume(struct device *dev) { struct net_device *netdev = dev_get_drvdata(dev); struct macb *bp = netdev_priv(netdev); + struct macb_context *ctx = bp->ctx; struct macb_queue *queue; unsigned long flags; unsigned int q; @@ -6459,9 +6480,9 @@ static int __maybe_unused macb_resume(struct device *dev) ++q, ++queue) { if (!(bp->caps & MACB_CAPS_MACB_IS_EMAC)) { if (macb_is_gem(&bp->info)) - gem_init_rx_ring(queue); + gem_init_rx_ring(ctx, q); else - macb_init_rx_ring(queue); + macb_init_rx_ring(ctx, q); } napi_enable(&queue->napi_rx); From 88e99640fcd05a0ff5f9694e5c4b2f00c2edeb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:45 +0200 Subject: [PATCH 1930/2126] net: macb: introduce macb_context_alloc() helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the context allocation sequence from inline macb_open() to its own helper function called macb_context_alloc(). All ops doing context swapping (set_ringparam, change_mtu, etc) will use this helper. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-7-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb_main.c | 68 ++++++++++++++++-------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 05169bbe2efc..32a24c91c045 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3006,6 +3006,43 @@ out_err: return -ENOMEM; } +static struct macb_context *macb_context_alloc(struct macb *bp, + unsigned int mtu, + unsigned int rx_ring_size, + unsigned int tx_ring_size) +{ + struct macb_context *ctx; + int err; + + ctx = kzalloc_obj(*ctx); + if (!ctx) + return ERR_PTR(-ENOMEM); + + ctx->info = &bp->info; + ctx->rx_buffer_size = macb_rx_buffer_size(bp, mtu); + ctx->rx_ring_size = rx_ring_size; + ctx->tx_ring_size = tx_ring_size; + + err = macb_alloc(ctx); + if (err) { + netdev_err(bp->netdev, + "Unable to allocate DMA memory (error %d)\n", err); + goto free_ctx; + } + + err = bp->macbgem_ops.mog_init_rings(ctx); + if (err) + goto free_rings; + + return ctx; + +free_rings: + macb_free(ctx); +free_ctx: + kfree(ctx); + return ERR_PTR(err); +} + static int gem_init_rx_ring(struct macb_context *ctx, unsigned int q) { struct macb_rxq *rxq = &ctx->rxq[q]; @@ -3376,6 +3413,7 @@ static void macb_set_rx_mode(struct net_device *netdev) static int macb_open(struct net_device *netdev) { struct macb *bp = netdev_priv(netdev); + struct macb_context *ctx; int err; netdev_dbg(bp->netdev, "open\n"); @@ -3384,30 +3422,18 @@ static int macb_open(struct net_device *netdev) if (err < 0) return err; - WRITE_ONCE(bp->ctx, kzalloc_obj(*bp->ctx)); - wmb(); /* ensure IRQ enabled at quiesce end read the new context */ - if (!bp->ctx) { - err = -ENOMEM; + ctx = macb_context_alloc(bp, netdev->mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); + if (IS_ERR(ctx)) { + err = PTR_ERR(ctx); + bp->ctx = NULL; goto pm_exit; } - bp->ctx->info = &bp->info; + WRITE_ONCE(bp->ctx, ctx); + wmb(); /* ensure IRQ enabled at quiesce end read the new context */ - /* RX buffers initialization */ - bp->ctx->rx_buffer_size = macb_rx_buffer_size(bp, netdev->mtu); - bp->ctx->rx_ring_size = bp->configured_rx_ring_size; - bp->ctx->tx_ring_size = bp->configured_tx_ring_size; - - err = macb_alloc(bp->ctx); - if (err) { - netdev_err(netdev, "Unable to allocate DMA memory (error %d)\n", - err); - goto free_ctx; - } - - err = bp->macbgem_ops.mog_init_rings(bp->ctx); - if (err) - goto free_rings; macb_init_buffers(bp); macb_quiesce_end(bp); @@ -3441,9 +3467,7 @@ reset_hw: macb_quiesce_start(bp); macb_reset_hw(bp); -free_rings: macb_free(bp->ctx); -free_ctx: kfree(bp->ctx); bp->ctx = NULL; pm_exit: From dcc3288b9433a47b41c8226d69381b827b3e3b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:46 +0200 Subject: [PATCH 1931/2126] net: macb: use context swapping in .set_ringparam() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ethtool_ops.set_ringparam() is implemented using the primitive close / update ring size / reopen sequence. Under memory pressure this does not fly: we free our buffers at close and cannot reallocate new ones at open. Also, it triggers a slow PHY reinit. Instead, exploit the new context mechanism and improve our sequence to: - allocate a new context (including buffers) first - if it fails, early return without any impact to the interface - stop interface - update global state (bp, netdev, etc) - pass buffer pointers to the hardware - start interface - free old context. The HW disable sequence is inspired by macb_reset_hw() but avoids (1) setting NCR bit CLRSTAT and (2) clearing register PBUFRXCUT. The HW re-enable sequence is inspired by macb_mac_link_up(), skipping over register writes which would be redundant (because values have not changed). The generic context swapping parts are isolated into helper functions macb_context_swap_start|end(), reusable by other operations (change_mtu, set_channels, etc). Introduce a new locking primitive (mac_cfg_lock mutex) to serialise swap with phylink MAC callbacks. Avoid stopping phylink to avoid a slow PHY retrain. We cannot sync to phylink ops using phydev->lock because it is not available in the SFP case. We cannot check link state using netif_carrier_ok() because we could race with its changes; so we use a redundant bp->link_up boolean that is mac_cfg_lock protected. AT91 EMAC is handled differently as their buffer management is separate and they don't do NAPI. They must never call swap_start/end(). Anyway they do not implement set_ringparam (-EOPNOTSUPP) so we are safe. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-8-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb.h | 7 +- drivers/net/ethernet/cadence/macb_main.c | 188 ++++++++++++++++++++--- 2 files changed, 175 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index ec2e2fbc1146..b7b4b6a38298 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1358,6 +1358,8 @@ struct macb { struct macb_queue queues[MACB_MAX_QUEUES]; spinlock_t lock; + /* Serializes context swap against phylink MAC callbacks. */ + struct mutex mac_cfg_lock; struct clk *pclk; struct clk *hclk; struct clk *tx_clk; @@ -1419,10 +1421,13 @@ struct macb { u32 tx_lpi_timer; /* ISR must not drive NAPI & BH mechanisms. True when the interface - * is closed. Protected by bp->lock. + * is closed or during context-swap. Protected by bp->lock. */ bool irq_quiesced; + /* Redundant to netif_carrier_ok(), but set under bp->mac_cfg_lock. */ + bool link_up; + u32 rx_intr_mask; struct macb_pm_data pm_data; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 32a24c91c045..6bacf3e3caab 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -746,12 +746,26 @@ static void macb_mac_disable_tx_lpi(struct phylink_config *config) struct macb *bp = netdev_priv(netdev); unsigned long flags; + mutex_lock(&bp->mac_cfg_lock); + cancel_delayed_work_sync(&bp->tx_lpi_work); spin_lock_irqsave(&bp->lock, flags); bp->eee_active = false; macb_tx_lpi_set(bp, false); spin_unlock_irqrestore(&bp->lock, flags); + + mutex_unlock(&bp->mac_cfg_lock); +} + +static void macb_txp_lpi_initial_defer(struct macb *bp) +{ + lockdep_assert_held(&bp->mac_cfg_lock); + + /* Defer initial LPI entry by 1 second after link-up per + * IEEE 802.3az section 22.7a. + */ + mod_delayed_work(system_wq, &bp->tx_lpi_work, msecs_to_jiffies(1000)); } static int macb_mac_enable_tx_lpi(struct phylink_config *config, u32 timer, @@ -761,15 +775,16 @@ static int macb_mac_enable_tx_lpi(struct phylink_config *config, u32 timer, struct macb *bp = netdev_priv(netdev); unsigned long flags; + mutex_lock(&bp->mac_cfg_lock); + spin_lock_irqsave(&bp->lock, flags); bp->tx_lpi_timer = timer; bp->eee_active = true; spin_unlock_irqrestore(&bp->lock, flags); - /* Defer initial LPI entry by 1 second after link-up per - * IEEE 802.3az section 22.7a. - */ - mod_delayed_work(system_wq, &bp->tx_lpi_work, msecs_to_jiffies(1000)); + macb_txp_lpi_initial_defer(bp); + + mutex_unlock(&bp->mac_cfg_lock); return 0; } @@ -783,6 +798,7 @@ static void macb_mac_config(struct phylink_config *config, unsigned int mode, u32 old_ctrl, ctrl; u32 old_ncr, ncr; + mutex_lock(&bp->mac_cfg_lock); spin_lock_irqsave(&bp->lock, flags); old_ctrl = ctrl = macb_or_gem_readl(bp, NCFGR); @@ -816,6 +832,7 @@ static void macb_mac_config(struct phylink_config *config, unsigned int mode, macb_or_gem_writel(bp, NCR, ncr); spin_unlock_irqrestore(&bp->lock, flags); + mutex_unlock(&bp->mac_cfg_lock); } static void macb_mac_link_down(struct phylink_config *config, unsigned int mode, @@ -827,6 +844,10 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode, unsigned int q; u32 ctrl; + mutex_lock(&bp->mac_cfg_lock); + + bp->link_up = false; + if (!(bp->caps & MACB_CAPS_MACB_IS_EMAC)) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) queue_writel(queue, IDR, @@ -837,6 +858,8 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode, macb_writel(bp, NCR, ctrl); netif_tx_stop_all_queues(netdev); + + mutex_unlock(&bp->mac_cfg_lock); } /* Use juggling algorithm to left rotate tx ring and tx skb array */ @@ -945,8 +968,11 @@ static void macb_mac_link_up(struct phylink_config *config, unsigned int q; u32 ctrl; + mutex_lock(&bp->mac_cfg_lock); spin_lock_irqsave(&bp->lock, flags); + bp->link_up = true; + ctrl = macb_or_gem_readl(bp, NCFGR); ctrl &= ~(MACB_BIT(SPD) | MACB_BIT(FD)); @@ -996,6 +1022,8 @@ static void macb_mac_link_up(struct phylink_config *config, macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE)); netif_tx_wake_all_queues(netdev); + + mutex_unlock(&bp->mac_cfg_lock); } static struct phylink_pcs *macb_mac_select_pcs(struct phylink_config *config, @@ -2010,29 +2038,37 @@ static int macb_rx_poll(struct napi_struct *napi, int budget) static void macb_tx_restart(struct macb_queue *queue) { - struct macb_context *ctx = queue->bp->ctx; - struct macb_txq *txq = macb_txq(queue); struct macb *bp = queue->bp; unsigned int head_idx, tbqp; + struct macb_context *ctx; + struct macb_txq *txq; unsigned long flags; spin_lock_irqsave(&queue->tx_ptr_lock, flags); + spin_lock(&bp->lock); + + /* context swap ongoing? */ + if (bp->irq_quiesced) + goto out_unlock; + + ctx = queue->bp->ctx; + txq = macb_txq(queue); + if (txq->head == txq->tail) - goto out_tx_ptr_unlock; + goto out_unlock; tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(ctx->info); tbqp = macb_adj_dma_desc_idx(ctx, macb_tx_ring_wrap(ctx, tbqp)); head_idx = macb_adj_dma_desc_idx(ctx, macb_tx_ring_wrap(ctx, txq->head)); if (tbqp == head_idx) - goto out_tx_ptr_unlock; + goto out_unlock; - spin_lock(&bp->lock); macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); - spin_unlock(&bp->lock); -out_tx_ptr_unlock: +out_unlock: + spin_unlock(&bp->lock); spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); } @@ -2291,7 +2327,9 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) spin_lock(&bp->lock); while (status) { - /* self-disarm while the netdev is closed */ + /* self-disarm while the netdev is closed + * or during context swap + */ if (unlikely(bp->irq_quiesced)) { queue_writel(queue, IDR, -1); macb_queue_isr_clear(bp, queue, -1); @@ -3251,6 +3289,112 @@ static void macb_configure_dma(struct macb *bp) } } +static void macb_context_swap_start(struct macb *bp) +{ + struct macb_queue *queue; + unsigned long flags; + unsigned int q; + u32 ctrl; + + mutex_lock(&bp->mac_cfg_lock); + + macb_quiesce_start(bp); + + /* Can finally disable software Tx; need to wait until napi_tx and + * tx_error_task cannot be scheduled as either might wakeup Tx. + */ + netif_tx_disable(bp->netdev); + + /* Now that everything is stopped, clear DQL. */ + for (q = 0; q < bp->num_queues; ++q) + netdev_tx_reset_queue(netdev_get_tx_queue(bp->netdev, q)); + + /* Safe to call outside bp->lock because bp->irq_quiesced ensures the IRQ + * handling is a no-op and all BH features are disabled. + * + * Whether it fails or not we'll disable TE/RE next. + * We were just trying to be nice. + */ + macb_halt_tx(bp); + + spin_lock_irqsave(&bp->lock, flags); + + ctrl = macb_readl(bp, NCR); + macb_writel(bp, NCR, ctrl & ~(MACB_BIT(RE) | MACB_BIT(TE))); + + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { + queue_writel(queue, IDR, -1); + queue_readl(queue, ISR); + macb_queue_isr_clear(bp, queue, -1); + } + + macb_writel(bp, TSR, -1); + macb_writel(bp, RSR, -1); + + spin_unlock_irqrestore(&bp->lock, flags); +} + +static void macb_context_swap_end(struct macb *bp, + struct macb_context *new_ctx) +{ + struct macb_context *old_ctx; + struct macb_queue *queue; + unsigned long flags; + unsigned int q; + u32 ctrl; + + lockdep_assert_held(&bp->mac_cfg_lock); + + /* Swap contexts & give buffer pointers to HW. */ + + old_ctx = bp->ctx; + WRITE_ONCE(bp->ctx, new_ctx); + wmb(); /* ensure IRQ enabled below read the new context */ + macb_init_buffers(bp); + + /* Start NAPI, HW Tx/Rx and software Tx. */ + + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { + napi_enable(&queue->napi_rx); + napi_enable(&queue->napi_tx); + } + + spin_lock_irqsave(&bp->lock, flags); + + /* Re-arm normal interrupt processing before enabling IRQs. */ + bp->irq_quiesced = false; + + macb_configure_dma(bp); + + if (bp->link_up) { + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { + queue_writel(queue, IER, + bp->rx_intr_mask | + MACB_TX_INT_FLAGS | + MACB_BIT(HRESP)); + } + + ctrl = macb_readl(bp, NCR); + macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE)); + } + + spin_unlock_irqrestore(&bp->lock, flags); + + if (bp->link_up) { + netif_tx_wake_all_queues(bp->netdev); + + if (bp->eee_active) + macb_txp_lpi_initial_defer(bp); + } + + mutex_unlock(&bp->mac_cfg_lock); + + /* Free old context. */ + + macb_free(old_ctx); + kfree(old_ctx); +} + static void macb_init_hw(struct macb *bp) { u32 config; @@ -3971,9 +4115,10 @@ static int macb_set_ringparam(struct net_device *netdev, struct kernel_ethtool_ringparam *kernel_ring, struct netlink_ext_ack *extack) { + unsigned int new_rx_size, new_tx_size; struct macb *bp = netdev_priv(netdev); - u32 new_rx_size, new_tx_size; - unsigned int reset = 0; + bool running = netif_running(netdev); + struct macb_context *new_ctx; if (bp->caps & MACB_CAPS_MACB_IS_EMAC) return -EOPNOTSUPP; @@ -3995,16 +4140,20 @@ static int macb_set_ringparam(struct net_device *netdev, return 0; } - if (netif_running(bp->netdev)) { - reset = 1; - macb_close(bp->netdev); + if (running) { + new_ctx = macb_context_alloc(bp, netdev->mtu, + new_rx_size, new_tx_size); + if (IS_ERR(new_ctx)) + return PTR_ERR(new_ctx); + + macb_context_swap_start(bp); } bp->configured_rx_ring_size = new_rx_size; bp->configured_tx_ring_size = new_tx_size; - if (reset) - macb_open(bp->netdev); + if (running) + macb_context_swap_end(bp, new_ctx); return 0; } @@ -6185,6 +6334,7 @@ static int macb_probe(struct platform_device *pdev) spin_lock_init(&bp->lock); spin_lock_init(&bp->stats_lock); spin_lock_init(&bp->tsu_clk_lock); + mutex_init(&bp->mac_cfg_lock); /* setup capabilities */ macb_configure_caps(bp, macb_config); From a98375924d64cba336ab31b426756c946667fdaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Tue, 13 Oct 2026 15:16:47 +0200 Subject: [PATCH 1932/2126] net: macb: use context swapping in .ndo_change_mtu() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use newly introduced context buffer management to implement .ndo_change_mtu() as a context swap: allocate new context -> reconfigure HW -> free old context. This resists memory pressure well by failing without closing the interface and it is much faster by avoiding PHY reinit. AT91 EMAC is handled differently as their buffer management is separate and they don't do NAPI. They cannot land in macb_change_mtu as they use a different ndo struct. We still defensively protect against it in code. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun Link: https://patch.msgid.link/20261013-macb-context-v11-9-b27785167566@bootlin.com Tested-by: Nicolai Buchwitz # RPi CM5 with RP1 GEM Signed-off-by: Paolo Abeni --- drivers/net/ethernet/cadence/macb_main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 6bacf3e3caab..f087f278f9e5 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3658,11 +3658,29 @@ static int macb_close(struct net_device *netdev) static int macb_change_mtu(struct net_device *netdev, int new_mtu) { - if (netif_running(netdev)) - return -EBUSY; + struct macb *bp = netdev_priv(netdev); + bool running = netif_running(netdev); + struct macb_context *new_ctx; + + if (running) { + /* Context swapping is not supported for AT91. */ + if (bp->caps & MACB_CAPS_MACB_IS_EMAC) + return -EBUSY; + + new_ctx = macb_context_alloc(bp, new_mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); + if (IS_ERR(new_ctx)) + return PTR_ERR(new_ctx); + + macb_context_swap_start(bp); + } WRITE_ONCE(netdev->mtu, new_mtu); + if (running) + macb_context_swap_end(bp, new_ctx); + return 0; } From 305deb54c6c287e586bed92da2375ae1220e8dde Mon Sep 17 00:00:00 2001 From: Pengfei Zhang Date: Tue, 13 Oct 2026 10:47:47 +0800 Subject: [PATCH 1933/2126] net: stmmac: xgmac: do not treat TBU as a TX event Commit 8d07a7930434 ("net: stmmac: xgmac: Do not enable TBU interrupt") removed TBUE from the default DMA interrupt mask, but did not remove the TBU check from dwxgmac2_dma_interrupt(). TBU is set whenever a TX channel runs out of descriptors. Since TBUE is not enabled and only enabled bits are cleared, the TBU status bit is never cleared. As a result, TBU stays set on every idle TX channel, regardless of whether there is any TX traffic. With a shared interrupt, stmmac_dma_interrupt() checks all channels, so every interrupt from any source schedules TX NAPI on every idle TX channel. Only use TI to trigger TX processing. Fixes: 8d07a7930434 ("net: stmmac: xgmac: Do not enable TBU interrupt") Signed-off-by: Pengfei Zhang Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261013024747.2688984-1-zhangfeionline@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c index ff83858ebc1f..0a6e82a155c0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c @@ -346,7 +346,7 @@ static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv, u64_stats_update_end(&stats->syncp); ret |= handle_rx; } - if (likely(intr_status & (XGMAC_TI | XGMAC_TBU))) { + if (likely(intr_status & XGMAC_TI)) { u64_stats_update_begin(&stats->syncp); u64_stats_inc(&stats->tx_normal_irq_n[chan]); u64_stats_update_end(&stats->syncp); From 679f6929a66db9f5a6611dad37545fbd705962d5 Mon Sep 17 00:00:00 2001 From: Sorah Fukumori Date: Tue, 13 Oct 2026 22:02:48 +0900 Subject: [PATCH 1934/2126] net: gro: don't chain linear parts larger than gso_size into frag_list skb_gro_receive() chains an skb into the frag_list of the held packet when its payload cannot be attached as page frags: when its head is not a page fragment and still holds payload, or when its head and frags would overflow the frags[] array of the last packet. Since commit 5eddb24901ee ("gro: add support of (hw)gro packets to gro stack"), that skb may itself be a GSO packet whose linear part holds several gso_size segments. skb_segment() cannot split the linear part of a frag_list member across segments, so segmenting the aggregate in software, e.g. when forwarding it to a device without NETIF_F_FRAGLIST, hits BUG_ON(skb_headlen(list_skb) > len); Fully linear GSO packets come from generic XDP. When the program does not support frags, netif_skb_check_for_xdp() linearizes any nonlinear skb with pskb_expand_head() and skb_linearize() and keeps its GSO metadata. GRO on the device runs before generic XDP, so each aggregate passed by the program carries all of its payload in a kmalloc'ed head. A tunnel that decapsulates these packets and runs GRO again through gro_cells then builds the bad frag_list. This was first seen on a router that forwards TCP received over VXLAN, with a non-frags XDP program attached in SKB mode to the underlying bond because one slave lacks native XDP: kernel BUG at net/core/skbuff.c:4917! RIP: 0010:skb_segment+0xbb6/0xf40 Call Trace: tcp_gso_segment ipv6_gso_segment skb_mac_gso_segment __skb_gso_segment validate_xmit_skb __dev_queue_xmit ip6_output ip6_sublist_rcv_finish ipv6_list_rcv netif_receive_skb_list_internal gro_complete dev_gro_receive gro_receive_skb gro_cell_poll __napi_poll net_rx_action It reproduces with three network namespaces: TCP sent over VXLAN on an IPv6 veth link to a router namespace that has an XDP_PASS program without frags support attached to the underlay veth in generic mode and GRO enabled on its VXLAN device, and forwards to a veth with tx-scatter-gather-fraglist disabled. A program with frags support in generic mode gives similar packets. skb_pp_cow_data() rebuilds the skb with up to about a page of linear data in a page_pool head_frag and keeps the GSO metadata, so once frags[] is full the next such packet is chained through frag_list with more than gso_size bytes in its head as well. Refuse the merge when the linear part to be chained exceeds the held packet's gso_size. tcp_gro_receive() then flushes the held packet and the skb starts a new GRO packet as its head, whose linear length skb_segment() handles. Fixes: 5eddb24901ee ("gro: add support of (hw)gro packets to gro stack") Cc: stable@vger.kernel.org Assisted-by: claude-opus-5-5 Signed-off-by: Sorah Fukumori Tested-by: Chase Hiltz Reviewed-by: Eric Dumazet Reviewed-by: Jason Xing Link: https://patch.msgid.link/20261013130250.3643916-1-her@sorah.jp Signed-off-by: Paolo Abeni --- net/core/gro.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/core/gro.c b/net/core/gro.c index 29b4d02bf519..ff828a3dce3c 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -187,6 +187,10 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) } merge: + /* skb_segment() cannot split the linear part of a frag_list member. */ + if (unlikely(headlen > offset + skb_shinfo(p)->gso_size)) + return -E2BIG; + /* sk ownership - if any - completely transferred to the aggregated packet */ skb->destructor = NULL; skb->sk = NULL; From 47b393b997aee31942114ef1d793f2ae6d72b766 Mon Sep 17 00:00:00 2001 From: Anton Danilov Date: Wed, 14 Oct 2026 08:46:15 +0300 Subject: [PATCH 1935/2126] tun: use pskb_may_pull_reason() and remove SKB_DROP_REASON_HDR_TRUNC tun_get_user() is the only user of SKB_DROP_REASON_HDR_TRUNC. It sets it when pskb_may_pull() fails to pull the Ethernet header of a frame written to a TAP device. pskb_may_pull_reason() reports why the pull failed: PKT_TOO_SMALL if the packet is shorter than requested, NOMEM if pulling the data into the linear area fails. Use it for both header pulls in tun_get_user(), on TAP and on TUN devices, and remove the now unused SKB_DROP_REASON_HDR_TRUNC. The pull of the IP version byte on a TUN device with IFF_NO_PI was reported as NOT_SPECIFIED and now reports PKT_TOO_SMALL, for example when only the virtio-net header is written. After a successful pull drop_reason is SKB_NOT_DROPPED_YET. The later error paths without a reason of their own, the unknown IP version on TUN, the virtio-net header conversion and the path that finds the queue detached, relied on the SKB_DROP_REASON_NOT_SPECIFIED initializer. Fall back to SKB_DROP_REASON_NOT_SPECIFIED at the free_skb label, as vxlan_rcv() does, so that these paths, and any later one without a reason of its own, keep reporting it. The errors returned to user space do not change. Suggested-by: Ido Schimmel Link: https://lore.kernel.org/netdev/20260923145931.GA2859441@shredder/ Assisted-by: LLM Signed-off-by: Anton Danilov Reviewed-by: Willem de Bruijn Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261014054615.1656074-1-littlesmilingcloud@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/tun.c | 8 +++++--- include/net/dropreason-core.h | 7 ------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8b82a7fe6ec7..d4152c9ba8df 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1903,7 +1903,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, if (tun->flags & IFF_NO_PI) { u8 ip_version; - if (!pskb_may_pull(skb, 1)) { + drop_reason = pskb_may_pull_reason(skb, 1); + if (drop_reason) { err = -EINVAL; goto drop; } @@ -1926,9 +1927,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb->protocol = pi.proto; break; case IFF_TAP: - if (!pskb_may_pull(skb, ETH_HLEN)) { + drop_reason = pskb_may_pull_reason(skb, ETH_HLEN); + if (drop_reason) { err = -ENOMEM; - drop_reason = SKB_DROP_REASON_HDR_TRUNC; goto drop; } skb_set_network_header(skb, ETH_HLEN); @@ -2065,6 +2066,7 @@ drop: dev_core_stats_rx_dropped_inc(tun->dev); free_skb: + drop_reason = drop_reason ?: SKB_DROP_REASON_NOT_SPECIFIED; if (!IS_ERR_OR_NULL(skb)) kfree_skb_reason(skb, drop_reason); diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 664249924219..fa2fe8990557 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -82,7 +82,6 @@ FN(DEV_READY) \ FN(FULL_RING) \ FN(NOMEM) \ - FN(HDR_TRUNC) \ FN(TAP_FILTER) \ FN(TAP_TXFILTER) \ FN(ICMP_CSUM) \ @@ -427,12 +426,6 @@ enum skb_drop_reason { SKB_DROP_REASON_FULL_RING, /** @SKB_DROP_REASON_NOMEM: error due to OOM */ SKB_DROP_REASON_NOMEM, - /** - * @SKB_DROP_REASON_HDR_TRUNC: failed to trunc/extract the header from - * networking data, e.g., failed to pull the protocol header from - * frags via pskb_may_pull() - */ - SKB_DROP_REASON_HDR_TRUNC, /** * @SKB_DROP_REASON_TAP_FILTER: dropped by (ebpf) filter directly attached * to tun/tap, e.g., via TUNSETFILTEREBPF From a234ee8eb9a20d1a272f0d2ceabdb35165071778 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 13 Oct 2026 19:56:38 +0200 Subject: [PATCH 1936/2126] mptcp: options: mpc: avoid printing uninit data When parsing the MP_CAPABLE suboption, this pr_debug() might read and print uninitialised values. That's mostly harmless, but that's also confusing. Fixing that also avoids some tools to complain about accessing uninit data. So read these fields only if they have been set. Note: this was initially reported by Clashiko as an existing issue. The code has been analysed by a human and confirmed. This is a non-urgent fix. Fixes: cc7972ea1932 ("mptcp: parse and emit MP_CAPABLE option according to v1 spec") Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-next-mptcp-misc-feat-7-4-part2-v1-1-1181e5d2fda4@kernel.org Signed-off-by: Paolo Abeni --- net/mptcp/options.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index c2f4d7bd080c..3b4a22846055 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -126,8 +126,11 @@ static void mptcp_parse_option(const struct sk_buff *skb, ptr += 2; } pr_debug("MP_CAPABLE version=%x, flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d csum=%u\n", - version, flags, opsize, mp_opt->sndr_key, - mp_opt->rcvr_key, mp_opt->data_len, mp_opt->csum); + version, flags, opsize, + opsize >= TCPOLEN_MPTCP_MPC_SYNACK ? mp_opt->sndr_key : 0, + opsize >= TCPOLEN_MPTCP_MPC_ACK ? mp_opt->rcvr_key : 0, + opsize >= TCPOLEN_MPTCP_MPC_ACK_DATA ? mp_opt->data_len : 0, + opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM ? mp_opt->csum : 0); break; case MPTCPOPT_MP_JOIN: From 00e2690c9dad0e09cd2a4435b98de6d8efd5fbc2 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 13 Oct 2026 19:56:39 +0200 Subject: [PATCH 1937/2126] mptcp: options: dss: avoid printing uninit csum When parsing the DSS suboption, this pr_debug() might read and print uninitialised checksum value. That's mostly harmless, but that's also confusing. Fixing that also avoids some tools to complain about accessing uninit data. So read this csum field only if it has been set. Note: this was initially reported by Clashiko as an existing issue. The code has been analysed by a human and confirmed. This is a non-urgent fix. Fixes: 390b95a5fb84 ("mptcp: receive checksum for DSS") Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-next-mptcp-misc-feat-7-4-part2-v1-2-1181e5d2fda4@kernel.org Signed-off-by: Paolo Abeni --- net/mptcp/options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 3b4a22846055..64aa7a516a23 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -259,7 +259,7 @@ static void mptcp_parse_option(const struct sk_buff *skb, pr_debug("data_seq=%llu subflow_seq=%u data_len=%u csum=%d:%u\n", mp_opt->data_seq, mp_opt->subflow_seq, mp_opt->data_len, !!(mp_opt->suboptions & OPTION_MPTCP_CSUMREQD), - mp_opt->csum); + (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD) ? mp_opt->csum : 0); } break; From d7add5f410ba91598fa681ae9ac1d09dafcc8b41 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Tue, 13 Oct 2026 19:56:40 +0200 Subject: [PATCH 1938/2126] selftests: mptcp: convert iptables to nftables for mptcp_sockopt.sh During the conversion, we retain the same filter and chain names previously used by iptables/ip6tables. Counters are not added to accept rules because the test does not inspect them. The syn mark rule is removed as it is only for debugging, which could be added easily when needed. After conversion, the generated output matches the original iptables/ip6tables behavior. Signed-off-by: Hangbin Liu Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-next-mptcp-misc-feat-7-4-part2-v1-3-1181e5d2fda4@kernel.org Signed-off-by: Paolo Abeni --- .../testing/selftests/net/mptcp/mptcp_lib.sh | 9 +++- .../selftests/net/mptcp/mptcp_sockopt.sh | 53 ++++++++++--------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index b9d14647f401..20853d0198ff 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -528,7 +528,14 @@ mptcp_lib_check_tools() { exit ${KSFT_SKIP} fi ;; - "iptables"* | "ip6tables"*) + "nft") + if ! nft --version &> /dev/null || \ + ! nft -j list ruleset &> /dev/null; then + mptcp_lib_pr_skip "Could not run all tests without nft -j" + exit ${KSFT_SKIP} + fi + ;; + "iptables"* | "ip6tables"* | "jq") if ! "${tool}" -V &> /dev/null; then mptcp_lib_pr_skip "Could not run all tests without ${tool}" exit ${KSFT_SKIP} diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh index e850a87429b6..ef2738720e24 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -15,8 +15,6 @@ cin="" cout="" timeout_poll=30 timeout_test=$((timeout_poll * 2 + 1)) -iptables="iptables" -ip6tables="ip6tables" ns1="" ns2="" @@ -49,16 +47,22 @@ add_mark_rules() local ns=$1 local m=$2 - local t - for t in ${iptables} ${ip6tables}; do - # just to debug: check we have multiple subflows connection requests - ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT + local table + for table in ip ip6; do + ip netns exec "$ns" nft -f - <<-EOF + add table $table filter + add chain $table filter OUTPUT \ + { type filter hook output priority 0; policy accept; } - # RST packets might be handled by a internal dummy socket - ip netns exec $ns $t -A OUTPUT -p tcp --tcp-flags RST RST -m mark --mark 0 -j ACCEPT + # RST packets might be handled by a internal dummy socket + add rule $table filter OUTPUT \ + tcp flags & rst == rst meta mark 0x0 accept - ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark $m -j ACCEPT - ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark 0 -j DROP + add rule $table filter OUTPUT \ + meta l4proto tcp meta mark $m accept + add rule $table filter OUTPUT \ + meta l4proto tcp meta mark 0 counter drop + EOF done } @@ -105,32 +109,31 @@ cleanup() mptcp_lib_check_mptcp mptcp_lib_check_kallsyms -mptcp_lib_check_tools ip "${iptables}" "${ip6tables}" +mptcp_lib_check_tools ip nft jq check_mark() { local ns=$1 local af=$2 - local tables=${iptables} + local tables="ip" if [ $af -eq 6 ];then - tables=${ip6tables} + tables="ip6" fi - local counters values - counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP) - values=${counters%DROP*} + local drops + drops=$(ip netns exec "$ns" nft -j list table "$tables" filter | \ + jq '.nftables[] | select(has("rule")) | .rule | + select (.chain=="OUTPUT" and any(.expr[]; has("drop"))) | + .expr[] | select(has("counter")) | .counter.packets') - local v - for v in $values; do - if [ $v -ne 0 ]; then - mptcp_lib_pr_fail "got $tables $values in ns $ns," \ - "not 0 - not all expected packets marked" - ret=${KSFT_FAIL} - return 1 - fi - done + if [ -z "$drops" ] || [ "$drops" -ne 0 ]; then + mptcp_lib_pr_fail "got $tables $drops in ns $ns," \ + "not 0 - not all expected packets marked" + ret=${KSFT_FAIL} + return 1 + fi return 0 } From be3b69f3cedfaf5f9fcc6b5dcff7897b813ca663 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Tue, 13 Oct 2026 19:56:41 +0200 Subject: [PATCH 1939/2126] selftests: mptcp: convert iptables to nftables for mptcp_join.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During conversion, we retain the same table and chain names used by the original iptables/ip6tables setup, so rule output is identical to the former iptables/ip6tables output. Add new function init_nftables so we only do nft table setup when test need set nft rules. Unlike iptables, nftables cannot match rules based on their full specification. Since endpoint_tests is the only test that delete rules, which inserts and deletes rules one by one. Flushing the table directly is safe and easier than using nft_handle. The cBPF bytecode matching MPTCP add‑addr is replaced with native nft matching using "tcp option mptcp subtype add-addr". But the RM_ADDR suboption is added after the MPTCP DSS option, and nft is unable to handle this because it stops parsing further TCP options once it matches the first one. We therefore use hard-coded offsets to match the RM_ADDR suboption. The config file adds CONFIG_NFT_NUMGEN (replaces iptables statistic nth), CONFIG_NFT_REJECT and CONFIG_NFT_REJECT_INET for reject‑related rules. Remove other unneeded configs. Remove the iptables/ip6tables check in mptcp_lib.sh since no script use it now. Signed-off-by: Hangbin Liu Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-next-mptcp-misc-feat-7-4-part2-v1-4-1181e5d2fda4@kernel.org Signed-off-by: Paolo Abeni --- tools/testing/selftests/net/mptcp/config | 15 +- .../testing/selftests/net/mptcp/mptcp_join.sh | 158 ++++++++---------- .../testing/selftests/net/mptcp/mptcp_lib.sh | 2 +- 3 files changed, 72 insertions(+), 103 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selftests/net/mptcp/config index bb9c4c97c620..6a96cfbbc461 100644 --- a/tools/testing/selftests/net/mptcp/config +++ b/tools/testing/selftests/net/mptcp/config @@ -1,12 +1,7 @@ CONFIG_INET_DIAG=m CONFIG_INET_MPTCP_DIAG=m -CONFIG_IP6_NF_FILTER=m -CONFIG_IP6_NF_TARGET_REJECT=m CONFIG_IP_ADVANCED_ROUTER=y CONFIG_IP_MULTIPLE_TABLES=y -CONFIG_IP_NF_FILTER=m -CONFIG_IP_NF_MANGLE=m -CONFIG_IP_NF_TARGET_REJECT=m CONFIG_IPV6=y CONFIG_IPV6_MULTIPLE_TABLES=y CONFIG_KALLSYMS=y @@ -19,17 +14,13 @@ CONFIG_NET_CLS_FW=m CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NETFILTER_NETLINK=y -CONFIG_NETFILTER_XTABLES=m -CONFIG_NETFILTER_XTABLES_LEGACY=y -CONFIG_NETFILTER_XT_MATCH_BPF=m -CONFIG_NETFILTER_XT_MATCH_LENGTH=m -CONFIG_NETFILTER_XT_MATCH_STATISTIC=m -CONFIG_NETFILTER_XT_TARGET_MARK=m CONFIG_NET_SCH_INGRESS=m CONFIG_NET_SCH_NETEM=m CONFIG_NF_TABLES=m CONFIG_NF_TABLES_INET=y -CONFIG_NFT_COMPAT=m +CONFIG_NFT_NUMGEN=m +CONFIG_NFT_REJECT=m +CONFIG_NFT_REJECT_INET=m CONFIG_NFT_SOCKET=m CONFIG_NFT_TPROXY=m CONFIG_SYN_COOKIES=y diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 18ce7136a2b0..f4d8afaeda4f 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -26,8 +26,6 @@ capout="" cappid="" ns1="" ns2="" -iptables="iptables" -ip6tables="ip6tables" timeout_poll=30 timeout_test=$((timeout_poll * 2 + 1)) capture=false @@ -99,41 +97,16 @@ unset add_addr_tx_nr unset add_addr_echo_tx_nr unset add_addr_drop_tx_nr -# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || -# (ip6 && (ip6[74] & 0xf0) == 0x30)'" -CBPF_MPTCP_SUBOPTION_ADD_ADDR="14, - 48 0 0 0, - 84 0 0 240, - 21 0 3 64, - 48 0 0 54, - 84 0 0 240, - 21 6 7 48, - 48 0 0 0, - 84 0 0 240, - 21 0 4 96, - 48 0 0 74, - 84 0 0 240, - 21 0 1 48, - 6 0 0 65535, - 6 0 0 0" - -# IPv4: TCP hdr of 48B, a first suboption of 12B (DACK8), the RM_ADDR suboption -# generated using "nfbpf_compile '(ip[32] & 0xf0) == 0xc0 && ip[53] == 0x0c && -# (ip[66] & 0xf0) == 0x40'" -CBPF_MPTCP_SUBOPTION_RM_ADDR="13, - 48 0 0 0, - 84 0 0 240, - 21 0 9 64, - 48 0 0 32, - 84 0 0 240, - 21 0 6 192, - 48 0 0 53, - 21 0 4 12, - 48 0 0 66, - 84 0 0 240, - 21 0 1 64, - 6 0 0 65535, - 6 0 0 0" +# nft cannot process the RM_ADDR option because it stops parsing after matching +# the first DSS option. Use hard-coded byte offsets to match RM_ADDR messages. +# A tcpdump capture of the RM_ADDR message looks like: +# [TCP header: 20 bytes] [nop] [nop] [timestamp: 10 bytes] +# [MPTCP DSS: 12 bytes] [MPTCP RM_ADDR: 4 bytes] +# +# - TCP Data Offset (12 x 4 = 48 bytes) +# - DSS (TCP[32] x 8) kind (MPTCP 0x1e), length (0x0c) and subtype (2) +# - RM_ADDR (TCP[44] x 8) kind (MPTCP 0x1e), variable length and subtype (4) +RM_ADDR_OFFSETS="tcp doff 12 @th,256,20 == 0x1e0c2 @th,352,8 == 0x1e @th,368,4 == 4" init_partial() { @@ -184,6 +157,26 @@ init_shapers() done } +init_nftables() +{ + local netns table + for netns in "$ns1" "$ns2"; do + for table in ip ip6; do + ip netns exec "$netns" nft -f - <<-EOF + add table $table filter + add chain $table filter INPUT \ + { type filter hook input priority filter; policy accept; } + add chain $table filter OUTPUT \ + { type filter hook output priority filter; policy accept; } + + add table $table mangle + add chain $table mangle OUTPUT \ + { type route hook output priority mangle; policy accept; } + EOF + done + done +} + cleanup_partial() { rm -f "$capout" @@ -196,7 +189,7 @@ init() { mptcp_lib_check_mptcp mptcp_lib_check_kallsyms - mptcp_lib_check_tools ip tc ss "${iptables}" "${ip6tables}" + mptcp_lib_check_tools ip tc ss nft sin=$(mktemp) sout=$(mktemp) @@ -380,24 +373,18 @@ reset_with_cookies() # $1: test name reset_with_add_addr_timeout() { - local ip="${2:-4}" - local tables + local ip="${2:-}" reset "${1}" || return 1 - - tables="${iptables}" - if [ $ip -eq 6 ]; then - tables="${ip6tables}" - fi + init_nftables # set a maximum, to avoid too long timeout with exponential backoff ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 - if ! ip netns exec $ns2 $tables -A OUTPUT -p tcp \ - -m tcp --tcp-option 30 \ - -m bpf --bytecode \ - "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ - -j DROP; then + if ! ip netns exec "$ns2" nft add rule \ + ip"$ip" filter OUTPUT meta l4proto tcp \ + tcp option mptcp subtype add-addr \ + drop; then mark_as_skipped "unable to set the 'add addr' rule" return 1 fi @@ -449,22 +436,14 @@ setup_fail_rules() check_invert=1 validate_checksum=true local i="$1" - local ip="${2:-4}" - local tables + local ip="${2:-}" - tables="${iptables}" - if [ $ip -eq 6 ]; then - tables="${ip6tables}" - fi - - ip netns exec $ns2 $tables \ - -t mangle \ - -A OUTPUT \ - -o ns2eth$i \ - -p tcp \ - -m length --length 150:9999 \ - -m statistic --mode nth --packet 1 --every 99999 \ - -j MARK --set-mark 42 || return ${KSFT_SKIP} + init_nftables + ip netns exec "$ns2" nft add rule \ + ip"$ip" mangle OUTPUT oifname ns2eth$i \ + meta l4proto tcp \ + meta length 150-9999 numgen inc mod 99999 1 \ + meta mark set 42 || return ${KSFT_SKIP} tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${KSFT_SKIP} tc -n $ns2 filter add dev ns2eth$i egress \ @@ -510,16 +489,15 @@ reset_with_tcp_filter() reset "${1}" || return 1 shift + init_nftables + local ns="${!1}" local src="${2}" local target="${3}" local chain="${4:-INPUT}" - if ! ip netns exec "${ns}" ${iptables} \ - -A "${chain}" \ - -s "${src}" \ - -p tcp \ - -j "${target}"; then + if ! ip netns exec "$ns" nft add rule ip filter "${chain}" \ + ip saddr "${src}" meta l4proto tcp "${target,,}"; then mark_as_skipped "unable to set the filter rules" return 1 fi @@ -4313,12 +4291,15 @@ userspace_tests() chk_mptcp_info subflows 1 subflows 1 chk_subflows_total 2 2 + init_nftables # force quick loss ip netns exec $ns2 sysctl -q net.ipv4.tcp_syn_retries=1 - if ip netns exec "${ns1}" ${iptables} -A INPUT -s "10.0.1.2" \ - -p tcp --tcp-option 30 -j REJECT --reject-with tcp-reset && - ip netns exec "${ns2}" ${iptables} -A INPUT -d "10.0.1.2" \ - -p tcp --tcp-option 30 -j REJECT --reject-with tcp-reset; then + if ip netns exec "${ns1}" nft add rule ip filter INPUT \ + ip saddr "10.0.1.2" meta l4proto tcp \ + tcp option mptcp exists reject with tcp reset && + ip netns exec "${ns2}" nft add rule ip filter INPUT \ + ip daddr "10.0.1.2" meta l4proto tcp \ + tcp option mptcp exists reject with tcp reset; then wait_event ns2 MPTCP_LIB_EVENT_SUB_CLOSED 1 wait_event ns1 MPTCP_LIB_EVENT_SUB_CLOSED 1 chk_subflows_total 1 1 @@ -4393,7 +4374,7 @@ endpoint_tests() chk_subflow_nr "after new reject" 2 chk_mptcp_info subflows 1 subflows 1 - ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT + ip netns exec "${ns2}" nft flush chain ip filter OUTPUT pm_nl_del_endpoint $ns2 3 10.0.3.2 pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow wait_mpj 3 @@ -4402,12 +4383,10 @@ endpoint_tests() # To make sure RM_ADDR are sent over a different subflow, but # allow the rest to quickly and cleanly close the subflow - local ipt=1 - ip netns exec "${ns2}" ${iptables} -I OUTPUT -s "10.0.1.2" \ - -p tcp -m tcp --tcp-option 30 \ - -m bpf --bytecode \ - "$CBPF_MPTCP_SUBOPTION_RM_ADDR" \ - -j DROP || ipt=0 + local nft=1 + ip netns exec "${ns2}" nft insert rule ip filter OUTPUT \ + ip saddr 10.0.1.2 meta l4proto tcp \ + "${RM_ADDR_OFFSETS}" drop || nft=0 local i for i in $(seq 3); do pm_nl_del_endpoint $ns2 1 10.0.1.2 @@ -4420,7 +4399,7 @@ endpoint_tests() chk_subflow_nr "after re-add id 0 ($i)" 3 chk_mptcp_info subflows 3 subflows 3 done - [ ${ipt} = 1 ] && ip netns exec "${ns2}" ${iptables} -D OUTPUT 1 + [ "${nft}" = 1 ] && ip netns exec "${ns2}" nft flush chain ip filter OUTPUT mptcp_lib_kill_group_wait $tests_pid @@ -4480,20 +4459,19 @@ endpoint_tests() chk_mptcp_info subflows 2 subflows 2 chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 + init_nftables # To make sure RM_ADDR are sent over a different subflow, but # allow the rest to quickly and cleanly close the subflow - local ipt=1 - ip netns exec "${ns1}" ${iptables} -I OUTPUT -s "10.0.1.1" \ - -p tcp -m tcp --tcp-option 30 \ - -m bpf --bytecode \ - "$CBPF_MPTCP_SUBOPTION_RM_ADDR" \ - -j DROP || ipt=0 + local nft=1 + ip netns exec "${ns1}" nft insert rule ip filter OUTPUT \ + ip saddr 10.0.1.1 meta l4proto tcp \ + "${RM_ADDR_OFFSETS}" drop || nft=0 pm_nl_del_endpoint $ns1 42 10.0.1.1 sleep 0.5 chk_subflow_nr "after delete ID 0" 2 chk_mptcp_info subflows 2 subflows 2 chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 - [ ${ipt} = 1 ] && ip netns exec "${ns1}" ${iptables} -D OUTPUT 1 + [ "${nft}" = 1 ] && ip netns exec "${ns1}" nft flush chain ip filter OUTPUT pm_nl_add_endpoint $ns1 10.0.1.1 id 42 flags signal wait_mpj 4 @@ -4555,7 +4533,7 @@ endpoint_tests() pm_nl_flush_endpoint $ns2 pm_nl_flush_endpoint $ns1 wait_rm_addr $ns2 0 - ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT + ip netns exec "${ns2}" nft flush chain ip filter OUTPUT pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow wait_mpj 1 pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index 20853d0198ff..e1c8c6fd8820 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -535,7 +535,7 @@ mptcp_lib_check_tools() { exit ${KSFT_SKIP} fi ;; - "iptables"* | "ip6tables"* | "jq") + "jq") if ! "${tool}" -V &> /dev/null; then mptcp_lib_pr_skip "Could not run all tests without ${tool}" exit ${KSFT_SKIP} From b6ef0d965fe8ce0ee4b4dcb58b3511f83003e42d Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Wed, 14 Oct 2026 14:14:12 +0200 Subject: [PATCH 1940/2126] selftests: tc-testing: use $IP in hfsc test 8c39 setup Test 8c39 brings up lo with a bare "ip" command. nsPlugin runs it as "$IP netns exec ip ...", and as tdc runs commands with an empty environment, "ip netns exec" searches only the default execvp() path (/bin:/usr/bin). On systems that install ip only in /sbin, like Fedora, the setup fails: # ./tdc.py -e 8c39 Test 8c39: HFSC classify walk still reaches leaf after lateral drift -----> prepare stage *** Could not execute: "ip link set lo up" -----> prepare stage *** Error message: "exec of "ip" failed: No such file or directory Use $IP like all other tdc tests do. Fixes: 1e24c4f2ee44 ("selftests: tc-testing: add a lateral-drift hfsc classify-walk test") Signed-off-by: Ivan Vecera Reviewed-by: Victor Nogueira Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20261014121414.2373985-1-ivecera@redhat.com Signed-off-by: Paolo Abeni --- tools/testing/selftests/tc-testing/tc-tests/qdiscs/hfsc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/hfsc.json b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/hfsc.json index 4f6bbb8b57f9..557730eef055 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/hfsc.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/hfsc.json @@ -181,7 +181,7 @@ "requires": "nsPlugin" }, "setup": [ - "ip link set lo up", + "$IP link set lo up", "$TC qdisc add dev lo handle 1: root hfsc default 30", "$TC class add dev lo parent 1: classid 1:1 hfsc rt m2 100kbit", "$TC class add dev lo parent 1:1 classid 1:10 hfsc rt m2 50kbit", From d06ae66516e1aaf023808912af6292aef09d46c3 Mon Sep 17 00:00:00 2001 From: Chengfeng Ye Date: Tue, 13 Oct 2026 17:05:00 +0800 Subject: [PATCH 1941/2126] l2tp: snapshot sequencing state when building transmit headers Updates to send_seq from netlink, PPP setsockopt and receive-side negotiation race with packet transmission. The header length is updated separately, while transmit reads both fields repeatedly without synchronization. For example, transmit can push a ten-byte L2TPv2 header, then a concurrent writer clears send_seq before the header builder reads it. The builder writes only six bytes, leaving four bytes of uninitialized skb headroom in the outgoing packet. The reverse mismatch overwrites the beginning of the payload. A later hdr_len read can also make the UDP length disagree with the skb length. KCSAN reported: BUG: KCSAN: data-race in l2tp_session_set_header_len / l2tp_xmit_skb write to 0xffff888100d0944a of 2 bytes by task 116 on cpu 1: l2tp_session_set_header_len+0x81/0xc0 l2tp_nl_cmd_session_modify+0x122/0x2c0 genl_family_rcv_msg_doit+0x170/0x1d0 read to 0xffff888100d0944a of 2 bytes by task 115 on cpu 0: l2tp_xmit_skb+0x9c/0xc80 pppol2tp_sendmsg+0x21c/0x2a0 __sys_sendto+0x28c/0x2a0 The bug can lead to leak kernel base address for KASLR bypass, the corresponding reproducer can be provided per request. Initialize hdr_len to the maximum header size and leave it unchanged when sequencing is toggled. Snapshot send_seq once per packet and use that snapshot for the actual header length and header construction, including the sequence flag. Use the same length for headroom, the header push and the UDP length. PPP callers can safely reserve the maximum size; L2TPv3 header sizes do not depend on sequencing. Make send_seq a separate bool so READ_ONCE() and WRITE_ONCE() can be used without sharing a bitfield storage unit with other configuration flags. Preserve the netlink attribute's existing low-bit truncation. Fixes: 3557baabf280 ("[L2TP]: PPP over L2TP driver core") Cc: stable@vger.kernel.org Assisted-by: GPT-6 Astra Signed-off-by: Chengfeng Ye Link: https://patch.msgid.link/20261013090500.1180376-1-nicoyip.dev@gmail.com Signed-off-by: Paolo Abeni --- net/l2tp/l2tp_core.c | 51 +++++++++++++++++++---------------------- net/l2tp/l2tp_core.h | 6 ++--- net/l2tp/l2tp_debugfs.c | 4 ++-- net/l2tp/l2tp_netlink.c | 11 ++++----- net/l2tp/l2tp_ppp.c | 8 +++---- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 4712cc41881a..7e042a3e648c 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -915,11 +915,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, * check if we sre sending sequence numbers and if not, * configure it so. */ - if (!session->lns_mode && !session->send_seq) { + if (!session->lns_mode && !READ_ONCE(session->send_seq)) { trace_session_seqnum_lns_enable(session); - session->send_seq = 1; - l2tp_session_set_header_len(session, tunnel->version, - tunnel->encap); + WRITE_ONCE(session->send_seq, true); } } else { /* No sequence numbers. @@ -937,12 +935,10 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, * If we're the LNS and we're sending sequence numbers, the * LAC is broken. Discard the frame. */ - if (!session->lns_mode && session->send_seq) { + if (!session->lns_mode && READ_ONCE(session->send_seq)) { trace_session_seqnum_lns_disable(session); - session->send_seq = 0; - l2tp_session_set_header_len(session, tunnel->version, - tunnel->encap); - } else if (session->send_seq) { + WRITE_ONCE(session->send_seq, false); + } else if (READ_ONCE(session->send_seq)) { pr_debug_ratelimited("%s: recv data has no seq numbers when required. Discarding.\n", session->name); atomic_long_inc(&session->stats.rx_seq_discards); @@ -1138,7 +1134,8 @@ static void l2tp_udp_encap_err_recv(struct sock *sk, struct sk_buff *skb, int er /* Build an L2TP header for the session into the buffer provided. */ -static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf) +static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf, + bool send_seq) { struct l2tp_tunnel *tunnel = session->tunnel; __be16 *bufp = buf; @@ -1147,14 +1144,14 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf) u32 tunnel_id = tunnel->peer_tunnel_id; u32 session_id = session->peer_session_id; - if (session->send_seq) + if (send_seq) flags |= L2TP_HDRFLAG_S; /* Setup L2TP header. */ *bufp++ = htons(flags); *bufp++ = htons(tunnel_id); *bufp++ = htons(session_id); - if (session->send_seq) { + if (send_seq) { *bufp++ = htons(session->ns); *bufp++ = 0; session->ns++; @@ -1165,7 +1162,8 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf) return bufp - optr; } -static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf) +static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf, + bool send_seq) { struct l2tp_tunnel *tunnel = session->tunnel; char *bufp = buf; @@ -1191,7 +1189,7 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf) if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) { u32 l2h = 0; - if (session->send_seq) { + if (send_seq) { l2h = 0x40000000 | session->ns; session->ns++; session->ns &= 0xffffff; @@ -1225,19 +1223,24 @@ static int l2tp_xmit_queue(struct l2tp_tunnel *tunnel, struct sk_buff *skb, stru static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, unsigned int *len) { struct l2tp_tunnel *tunnel = session->tunnel; + bool send_seq = READ_ONCE(session->send_seq); unsigned int data_len = skb->len; struct sock *sk = tunnel->sock; + u16 hdr_len = session->hdr_len; int headroom, uhlen, udp_len; int ret = NET_XMIT_SUCCESS; struct inet_sock *inet; struct udphdr *uh; + if (tunnel->version == L2TP_HDR_VER_2 && !send_seq) + hdr_len -= 4; + /* Check that there's enough headroom in the skb to insert IP, * UDP and L2TP headers. If not enough, expand it to * make room. Adjust truesize. */ uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(*uh) : 0; - headroom = NET_SKB_PAD + sizeof(struct iphdr) + uhlen + session->hdr_len; + headroom = NET_SKB_PAD + sizeof(struct iphdr) + uhlen + hdr_len; if (skb_cow_head(skb, headroom)) { kfree_skb(skb); return NET_XMIT_DROP; @@ -1245,9 +1248,9 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns /* Setup L2TP header */ if (tunnel->version == L2TP_HDR_VER_2) - l2tp_build_l2tpv2_header(session, __skb_push(skb, session->hdr_len)); + l2tp_build_l2tpv2_header(session, __skb_push(skb, hdr_len), send_seq); else - l2tp_build_l2tpv3_header(session, __skb_push(skb, session->hdr_len)); + l2tp_build_l2tpv3_header(session, __skb_push(skb, hdr_len), send_seq); /* Reset control buffer */ memset(skb->cb, 0, sizeof(skb->cb)); @@ -1290,7 +1293,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns uh = udp_hdr(skb); uh->source = inet->inet_sport; uh->dest = inet->inet_dport; - udp_len = uhlen + session->hdr_len + data_len; + udp_len = uhlen + hdr_len + data_len; if (udp_len > U16_MAX) { kfree_skb(skb); ret = NET_XMIT_DROP; @@ -1759,16 +1762,11 @@ static void l2tp_session_del_work(struct work_struct *work) l2tp_session_put(session); } -/* We come here whenever a session's send_seq, cookie_len or - * l2specific_type parameters are set. - */ -void l2tp_session_set_header_len(struct l2tp_session *session, int version, - enum l2tp_encap_type encap) +static void l2tp_session_set_header_len(struct l2tp_session *session, int version, + enum l2tp_encap_type encap) { if (version == L2TP_HDR_VER_2) { - session->hdr_len = 6; - if (session->send_seq) - session->hdr_len += 4; + session->hdr_len = 10; } else { session->hdr_len = 4 + session->cookie_len; session->hdr_len += l2tp_get_l2specific_len(session); @@ -1776,7 +1774,6 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version, session->hdr_len += 4; } } -EXPORT_SYMBOL_GPL(l2tp_session_set_header_len); struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h index ffd8ced3a51f..25ae4c25d3ef 100644 --- a/net/l2tp/l2tp_core.h +++ b/net/l2tp/l2tp_core.h @@ -76,7 +76,7 @@ struct l2tp_session { u8 peer_cookie[8]; int peer_cookie_len; u16 l2specific_type; - u16 hdr_len; + u16 hdr_len; /* maximum L2TP header length */ u32 nr; /* session NR state (receive) */ u32 ns; /* session NR state (send) */ struct sk_buff_head reorder_q; /* receive reorder queue */ @@ -94,8 +94,8 @@ struct l2tp_session { char name[L2TP_SESSION_NAME_MAX]; /* for logging */ char ifname[IFNAMSIZ]; + bool send_seq; /* send packets with sequence numbers? */ unsigned int recv_seq:1; /* expect receive packets with sequence numbers? */ - unsigned int send_seq:1; /* send packets with sequence numbers? */ unsigned int lns_mode:1; /* behave as LNS? * LAC enables sequence numbers under LNS control. */ @@ -257,8 +257,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb); /* Transmit path helpers for sending packets over the tunnel socket. */ -void l2tp_session_set_header_len(struct l2tp_session *session, int version, - enum l2tp_encap_type encap); int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb); /* Pseudowire management. diff --git a/net/l2tp/l2tp_debugfs.c b/net/l2tp/l2tp_debugfs.c index c12d5e1ee550..58d1d6a7768e 100644 --- a/net/l2tp/l2tp_debugfs.c +++ b/net/l2tp/l2tp_debugfs.c @@ -182,12 +182,12 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) session->pwtype == L2TP_PWTYPE_ETH ? "ETH" : session->pwtype == L2TP_PWTYPE_PPP ? "PPP" : ""); - if (session->send_seq || session->recv_seq) + if (READ_ONCE(session->send_seq) || session->recv_seq) seq_printf(m, " nr %u, ns %u\n", session->nr, session->ns); seq_printf(m, " refcnt %d\n", refcount_read(&session->ref_count)); seq_printf(m, " config 0/0/%c/%c/-/%s %08x %u\n", session->recv_seq ? 'R' : '-', - session->send_seq ? 'S' : '-', + READ_ONCE(session->send_seq) ? 'S' : '-', session->lns_mode ? "LNS" : "LAC", 0, jiffies_to_msecs(session->reorder_timeout)); diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c index 38aac59d052c..89ef04c78787 100644 --- a/net/l2tp/l2tp_netlink.c +++ b/net/l2tp/l2tp_netlink.c @@ -700,12 +700,9 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf if (info->attrs[L2TP_ATTR_RECV_SEQ]) session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); - if (info->attrs[L2TP_ATTR_SEND_SEQ]) { - struct l2tp_tunnel *tunnel = session->tunnel; - - session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]); - l2tp_session_set_header_len(session, tunnel->version, tunnel->encap); - } + if (info->attrs[L2TP_ATTR_SEND_SEQ]) + WRITE_ONCE(session->send_seq, + nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]) & 1); if (info->attrs[L2TP_ATTR_LNS_MODE]) session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]); @@ -748,7 +745,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl (session->peer_cookie_len && nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, session->peer_cookie)) || nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) || - nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) || + nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, READ_ONCE(session->send_seq)) || nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) || (l2tp_tunnel_uses_xfrm(tunnel) && nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) || diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index ef8fdfaf051d..4f311d473a64 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -1195,9 +1195,7 @@ static int pppol2tp_session_setsockopt(struct sock *sk, err = -EINVAL; break; } - session->send_seq = !!val; - l2tp_session_set_header_len(session, session->tunnel->version, - session->tunnel->encap); + WRITE_ONCE(session->send_seq, !!val); break; case PPPOL2TP_SO_LNSMODE: @@ -1307,7 +1305,7 @@ static int pppol2tp_session_getsockopt(struct sock *sk, break; case PPPOL2TP_SO_SENDSEQ: - *val = session->send_seq; + *val = READ_ONCE(session->send_seq); break; case PPPOL2TP_SO_LNSMODE: @@ -1546,7 +1544,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) state, user_data_ok); seq_printf(m, " 0/0/%c/%c/%s %08x %u\n", session->recv_seq ? 'R' : '-', - session->send_seq ? 'S' : '-', + READ_ONCE(session->send_seq) ? 'S' : '-', session->lns_mode ? "LNS" : "LAC", 0, jiffies_to_msecs(session->reorder_timeout)); From a868720467d974a81b6f0521cf21eca16b7eaea3 Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 14 Oct 2026 17:37:15 +0000 Subject: [PATCH 1942/2126] netmem: rename __get/__put_netmem() to get/put_net_iov() netmems carry both a non-pp backing refcount and a page_pool pp_ref_count. Make the non-pp layer explicit and symmetric across both netmem types: get/put_netmem() dispatches to get/put_page() for pages and get/put_net_iov() for net_iovs, always acquiring or releasing a non-pp reference regardless of page_pool membership. Warn via DEBUG_NET_WARN_ON_ONCE() for net_iov types that do not support non-pp references. Assisted-by: LLM Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261014173945.373295-2-almasrymina@google.com Acked-by: Stanislav Fomichev Signed-off-by: Paolo Abeni --- include/net/netmem.h | 24 ++++++++++++++++++++---- net/core/skbuff.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/net/netmem.h b/include/net/netmem.h index c4beb6fbc130..193de0d21490 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -409,21 +409,37 @@ static inline bool net_is_devmem_iov(const struct net_iov *niov) } #endif -void __get_netmem(netmem_ref netmem); -void __put_netmem(netmem_ref netmem); +void get_net_iov(struct net_iov *niov); +void put_net_iov(struct net_iov *niov); +/** + * get_netmem - acquire a non-page_pool reference on a netmem + * @netmem: netmem to reference + * + * Acquires a non-pp backing reference (page._refcount via get_page() or + * binding->ref via get_net_iov()) regardless of page_pool membership. + * Counterpart to put_netmem(). + */ static __always_inline void get_netmem(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) - __get_netmem(netmem); + get_net_iov(netmem_to_net_iov(netmem)); else get_page(netmem_to_page(netmem)); } +/** + * put_netmem - release a non-page_pool reference on a netmem + * @netmem: netmem to unreference + * + * Drops a non-pp backing reference (page._refcount via put_page() or + * binding->ref via put_net_iov()) regardless of page_pool membership. + * Counterpart to get_netmem(). + */ static __always_inline void put_netmem(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) - __put_netmem(netmem); + put_net_iov(netmem_to_net_iov(netmem)); else put_page(netmem_to_page(netmem)); } diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 93c2f440b9ec..597b067634b3 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7637,23 +7637,39 @@ bool csum_and_copy_from_iter_full(void *addr, size_t bytes, } EXPORT_SYMBOL(csum_and_copy_from_iter_full); -void __get_netmem(netmem_ref netmem) +/** + * get_net_iov - acquire a non-page_pool reference on a net_iov + * @niov: net_iov to reference + * + * Acquires a non-pp backing reference (binding->ref) on @niov regardless of + * page_pool membership, warning if @niov does not support non-pp references. + * Counterpart to put_net_iov(). + */ +void get_net_iov(struct net_iov *niov) { - struct net_iov *niov = netmem_to_net_iov(netmem); - if (net_is_devmem_iov(niov)) - net_devmem_get_net_iov(netmem_to_net_iov(netmem)); + net_devmem_get_net_iov(niov); + else + DEBUG_NET_WARN_ON_ONCE(true); } -EXPORT_SYMBOL(__get_netmem); +EXPORT_SYMBOL(get_net_iov); -void __put_netmem(netmem_ref netmem) +/** + * put_net_iov - release a non-page_pool reference on a net_iov + * @niov: net_iov to unreference + * + * Drops a non-pp backing reference (binding->ref) on @niov regardless of + * page_pool membership, warning if @niov does not support non-pp references. + * Counterpart to get_net_iov(). + */ +void put_net_iov(struct net_iov *niov) { - struct net_iov *niov = netmem_to_net_iov(netmem); - if (net_is_devmem_iov(niov)) - net_devmem_put_net_iov(netmem_to_net_iov(netmem)); + net_devmem_put_net_iov(niov); + else + DEBUG_NET_WARN_ON_ONCE(true); } -EXPORT_SYMBOL(__put_netmem); +EXPORT_SYMBOL(put_net_iov); struct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb, __be16 type, From 729a47b803b5c95659e32d9014ba10c727995d1c Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 14 Oct 2026 17:37:16 +0000 Subject: [PATCH 1943/2126] net: skbuff: add napi_pp_get_page() and use it in tcp_recvmsg_dmabuf() While napi_pp_put_page() releases a page_pool pp_ref_count reference on a netmem, no symmetric helper existed to acquire one, forcing callers like tcp_recvmsg_dmabuf() to open-code atomic_long_inc() on niov->desc.pp_ref_count. Add napi_pp_get_page() to pair symmetrically with napi_pp_put_page(), and use WARN_ON_ONCE(!napi_pp_get_page(netmem)) in tcp_recvmsg_dmabuf() to match WARN_ON_ONCE(!napi_pp_put_page(netmem)) in tcp_release_user_frags(). Assisted-by: LLM Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261014173945.373295-3-almasrymina@google.com Acked-by: Stanislav Fomichev Signed-off-by: Paolo Abeni --- include/linux/skbuff_ref.h | 2 ++ net/core/skbuff.c | 31 +++++++++++++++++++++++++++++++ net/ipv4/tcp.c | 6 ++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h index 05c8486bafac..0441c220fdbd 100644 --- a/include/linux/skbuff_ref.h +++ b/include/linux/skbuff_ref.h @@ -9,6 +9,8 @@ #include +bool napi_pp_get_page(netmem_ref netmem); + /** * __skb_frag_ref - take an addition reference on a paged fragment. * @frag: the paged fragment diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 597b067634b3..e0b6330eb7f3 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1026,6 +1026,15 @@ int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb, EXPORT_SYMBOL(skb_cow_data_for_xdp); #if IS_ENABLED(CONFIG_PAGE_POOL) +/** + * napi_pp_put_page - release a page_pool reference on a netmem + * @netmem: netmem to unreference + * + * Drops a page_pool reference (pp_ref_count) on @netmem if it belongs to a + * page_pool. Counterpart to napi_pp_get_page(). + * + * Return: true if @netmem belongs to a page_pool, false otherwise. + */ bool napi_pp_put_page(netmem_ref netmem) { netmem = netmem_compound_head(netmem); @@ -1038,6 +1047,28 @@ bool napi_pp_put_page(netmem_ref netmem) return true; } EXPORT_SYMBOL(napi_pp_put_page); + +/** + * napi_pp_get_page - acquire a page_pool reference on a netmem + * @netmem: netmem to reference + * + * Acquires a page_pool reference (pp_ref_count) on @netmem if it belongs to a + * page_pool. Counterpart to napi_pp_put_page(). + * + * Return: true if @netmem belongs to a page_pool, false otherwise. + */ +bool napi_pp_get_page(netmem_ref netmem) +{ + netmem = netmem_compound_head(netmem); + + if (unlikely(!netmem_is_pp(netmem))) + return false; + + page_pool_ref_netmem(netmem); + + return true; +} +EXPORT_SYMBOL(napi_pp_get_page); #endif static bool skb_pp_recycle(struct sk_buff *skb, void *data) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f4c9101e5996..99d7237a623d 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -254,6 +254,7 @@ #include #include #include +#include #include #include #include @@ -2559,6 +2560,7 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb, */ for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; + netmem_ref netmem = skb_frag_netmem(frag); struct net_iov *niov; u64 frag_offset; int end; @@ -2612,8 +2614,8 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb, if (err) goto out; - atomic_long_inc(&niov->desc.pp_ref_count); - tcp_xa_pool.netmems[tcp_xa_pool.idx++] = skb_frag_netmem(frag); + WARN_ON_ONCE(!napi_pp_get_page(netmem)); + tcp_xa_pool.netmems[tcp_xa_pool.idx++] = netmem; sent += copy; From 4d688084070e72d66090f3bb739218278d3e889b Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 14 Oct 2026 17:37:17 +0000 Subject: [PATCH 1944/2126] net: skbuff: replace skb_page_unref() and __skb_frag_unref() with skb_netmem_unref() Unreferencing a page_pool fragment with recycle=false decrements the non-pp backing refcount instead of pp_ref_count, underflowing the page refcount when the fragment was owned via page_pool (as on mlx4's RX error path). Having both skb_page_unref() and __skb_frag_unref(frag, recycle) made it easy for callers to pass hardcoded recycle=false on SKB-owned fragments. Replace skb_page_unref() and __skb_frag_unref() with skb_netmem_unref(netmem, recycle), which dispatches to napi_pp_put_page() when recycle is true and put_netmem() otherwise: - Use skb_frag_unref(skb, ...) on SKB-owned fragments in mlx4, sky2, tls_strp, and skb_shift() so unrefs always match skb->pp_recycle. - Use put_netmem() directly in tls_device's destroy_record(), which releases raw non-pp page references outside an SKB. Found by code inspection and confirmed with the KUnit tests added later in this series; not observed in production. The mlx4, sky2, and TLS call-site changes are compile-tested only. Assisted-by: LLM Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261014173945.373295-4-almasrymina@google.com Acked-by: Stanislav Fomichev Signed-off-by: Paolo Abeni --- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 2 +- include/linux/skbuff_ref.h | 34 +++++++++++----------- net/core/skbuff.c | 7 +++-- net/ipv4/esp4.c | 4 +-- net/ipv6/esp6.c | 4 +-- net/tls/tls_device.c | 2 +- net/tls/tls_strp.c | 2 +- 8 files changed, 29 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c index 30facdece3e2..1d42a82db8f2 100644 --- a/drivers/net/ethernet/marvell/sky2.c +++ b/drivers/net/ethernet/marvell/sky2.c @@ -2501,7 +2501,7 @@ static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space, if (length == 0) { /* don't need this page */ - __skb_frag_unref(frag, false); + skb_frag_unref(skb, i); --skb_shinfo(skb)->nr_frags; } else { size = min(length, (unsigned) PAGE_SIZE); diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c index 96f97fa0f548..fe18606c2ab5 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -497,7 +497,7 @@ static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv, fail: while (nr > 0) { nr--; - __skb_frag_unref(skb_shinfo(skb)->frags + nr, false); + skb_frag_unref(skb, nr); } return 0; } diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h index 0441c220fdbd..04114c64dad9 100644 --- a/include/linux/skbuff_ref.h +++ b/include/linux/skbuff_ref.h @@ -36,7 +36,16 @@ static __always_inline void skb_frag_ref(struct sk_buff *skb, int f) bool napi_pp_put_page(netmem_ref netmem); -static __always_inline void skb_page_unref(netmem_ref netmem, bool recycle) +/** + * skb_netmem_unref - release a fragment reference on a netmem + * @netmem: netmem to unreference + * @recycle: whether page_pool recycling is enabled (e.g. skb->pp_recycle) + * + * Drops pp_ref_count via napi_pp_put_page() if @recycle is true and @netmem + * belongs to a page_pool; otherwise drops a non-pp backing reference via + * put_netmem(). Counterpart to skb_netmem_ref(). + */ +static __always_inline void skb_netmem_unref(netmem_ref netmem, bool recycle) { #ifdef CONFIG_PAGE_POOL if (recycle && napi_pp_put_page(netmem)) @@ -46,31 +55,22 @@ static __always_inline void skb_page_unref(netmem_ref netmem, bool recycle) } /** - * __skb_frag_unref - release a reference on a paged fragment. - * @frag: the paged fragment - * @recycle: recycle the page if allocated via page_pool - * - * Releases a reference on the paged fragment @frag - * or recycles the page via the page_pool API. - */ -static __always_inline void __skb_frag_unref(skb_frag_t *frag, bool recycle) -{ - skb_page_unref(skb_frag_netmem(frag), recycle); -} - -/** - * skb_frag_unref - release a reference on a paged fragment of an skb. + * skb_frag_unref - release a reference on a paged fragment of an skb * @skb: the buffer * @f: the fragment offset * - * Releases a reference on the @f'th paged fragment of @skb. + * Drops a reference on the @f'th fragment of @skb via skb_netmem_unref() + * (pp_ref_count if skb->pp_recycle and page_pool-backed, else non-pp + * backing refcount), skipping managed zerocopy fragments. Counterpart to + * skb_frag_ref(). */ static __always_inline void skb_frag_unref(struct sk_buff *skb, int f) { struct skb_shared_info *shinfo = skb_shinfo(skb); if (!skb_zcopy_managed(skb)) - __skb_frag_unref(&shinfo->frags[f], skb->pp_recycle); + skb_netmem_unref(skb_frag_netmem(&shinfo->frags[f]), + skb->pp_recycle); } #endif /* _LINUX_SKBUFF_REF_H */ diff --git a/net/core/skbuff.c b/net/core/skbuff.c index e0b6330eb7f3..c0c32a5b0e4b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1144,7 +1144,8 @@ static void skb_release_data(struct sk_buff *skb, enum skb_drop_reason reason) } for (i = 0; i < shinfo->nr_frags; i++) - __skb_frag_unref(&shinfo->frags[i], skb->pp_recycle); + skb_netmem_unref(skb_frag_netmem(&shinfo->frags[i]), + skb->pp_recycle); free_head: if (shinfo->frag_list) @@ -1154,7 +1155,7 @@ free_head: exit: /* When we clone an SKB we copy the reycling bit. The pp_recycle * bit is only set on the head though, so in order to avoid races - * while trying to recycle fragments on __skb_frag_unref() we need + * while trying to recycle fragments on skb_netmem_unref() we need * to make one SKB responsible for triggering the recycle path. * So disable the recycling bit if an SKB is cloned and we have * additional references to the fragmented part of the SKB. @@ -4465,7 +4466,7 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) fragto = &skb_shinfo(tgt)->frags[merge]; skb_frag_size_add(fragto, skb_frag_size(fragfrom)); - __skb_frag_unref(fragfrom, skb->pp_recycle); + skb_frag_unref(skb, 0); } /* Reposition in the original skb */ diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index e76db5817e78..ae701561d9f1 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -117,8 +117,8 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb, struct scatterlist *src = already_unref ? esp_req_sg(aead, req) : req->src; for (sg = sg_next(src); sg; sg = sg_next(sg)) - skb_page_unref(page_to_netmem(sg_page(sg)), - skb->pp_recycle); + skb_netmem_unref(page_to_netmem(sg_page(sg)), + skb->pp_recycle); } } diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index b1c9b36f76dc..d654f0f44238 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -134,8 +134,8 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb, struct scatterlist *src = already_unref ? esp_req_sg(aead, req) : req->src; for (sg = sg_next(src); sg; sg = sg_next(sg)) - skb_page_unref(page_to_netmem(sg_page(sg)), - skb->pp_recycle); + skb_netmem_unref(page_to_netmem(sg_page(sg)), + skb->pp_recycle); } } diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index f11d0528fc43..b333a9a72cda 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -143,7 +143,7 @@ static void destroy_record(struct tls_record_info *record) int i; for (i = 0; i < record->num_frags; i++) - __skb_frag_unref(&record->frags[i], false); + put_netmem(skb_frag_netmem(&record->frags[i])); kfree(record); } diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c index 6cc222008d95..53d3256d0114 100644 --- a/net/tls/tls_strp.c +++ b/net/tls/tls_strp.c @@ -197,7 +197,7 @@ static void tls_strp_flush_anchor_copy(struct tls_strparser *strp) DEBUG_NET_WARN_ON_ONCE(atomic_read(&shinfo->dataref) != 1); for (i = 0; i < shinfo->nr_frags; i++) - __skb_frag_unref(&shinfo->frags[i], false); + skb_frag_unref(strp->anchor, i); shinfo->nr_frags = 0; if (strp->copy_mode) { kfree_skb_list(shinfo->frag_list); From 1f6f88105e1da95954bca63475796ee09afd8ba1 Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 14 Oct 2026 17:37:18 +0000 Subject: [PATCH 1945/2126] net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref() Previously, __skb_frag_ref() and skb_frag_ref() unconditionally incremented the non-pp backing refcount via get_netmem(), while skb_frag_unref() decremented pp_ref_count whenever skb->pp_recycle was set. Ref-ing a page_pool fragment into a pp_recycle=1 SKB (or clearing pp_recycle=0 on an uncloned SKB while clones still held pp_recycle=1) leaked the backing non-pp refcount and underflowed pp_ref_count across IP-TFS, skb_split(), skb_shift(), and cloned unclone paths. Replace __skb_frag_ref() with skb_netmem_ref(netmem, recycle) as the exact counterpart to skb_netmem_unref(netmem, recycle): - Keep skb->pp_recycle intact in skb_release_data() so uncloning paths (pskb_expand_head() and pskb_carve_inside_{header,nonlinear}()) keep trading pp_ref_count references symmetrically across clones. - Propagate pp_recycle and call skb_frag_ref() on the destination SKB in __pskb_copy_fclone(), skb_zerocopy(), skb_split(), skb_shift(), and skb_segment(). - Linearize an output segment's existing frags in skb_segment() before attaching frags from a frag_list SKB with a different pp_recycle bit, since each output segment carries a single pp_recycle bit. - Use skb_frag_ref() in xfrm_iptfs, chcr_ktls, and cassini, and call get_netmem() directly in veth and tls_device_fallback where callers explicitly take a raw non-pp reference. Found by code inspection while reviewing the IP-TFS pp_ref_count fix [1] and confirmed with the KUnit tests added later in this series; not observed in production. The xfrm_iptfs, chcr_ktls, cassini, veth, and tls_device_fallback changes are compile-tested only. Link: https://lore.kernel.org/netdev/xfrm-iptfs-pp_ref_count-underflow-v4-1-912fa72106f0@secunet.com/ [1] Cc: Antony Antony Cc: Stanislav Fomichev Cc: Daniel Borkmann Cc: Alexei Starovoitov Cc: Jesper Dangaard Brouer Cc: bpf@vger.kernel.org Assisted-by: LLM Signed-off-by: Mina Almasry Tested-by: Antony Antony Link: https://patch.msgid.link/20261014173945.373295-5-almasrymina@google.com Acked-by: Stanislav Fomichev Signed-off-by: Paolo Abeni --- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 2 +- drivers/net/ethernet/sun/cassini.c | 4 +- drivers/net/veth.c | 2 +- include/linux/skbuff_ref.h | 28 +++++++---- net/core/skbuff.c | 48 ++++++++++--------- net/tls/tls_device_fallback.c | 2 +- net/xfrm/xfrm_iptfs.c | 3 +- 7 files changed, 51 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c index dbec95b49777..4d645771596a 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c @@ -1660,7 +1660,7 @@ static void chcr_ktls_copy_record_in_skb(struct sk_buff *nskb, for (i = 0; i < record->num_frags; i++) { skb_shinfo(nskb)->frags[i] = record->frags[i]; /* increase the frag ref count */ - __skb_frag_ref(&skb_shinfo(nskb)->frags[i]); + skb_frag_ref(nskb, i); } skb_shinfo(nskb)->nr_frags = record->num_frags; diff --git a/drivers/net/ethernet/sun/cassini.c b/drivers/net/ethernet/sun/cassini.c index 9a8b5cf2d648..02158a1bb2f7 100644 --- a/drivers/net/ethernet/sun/cassini.c +++ b/drivers/net/ethernet/sun/cassini.c @@ -1998,7 +1998,7 @@ static int cas_rx_process_pkt(struct cas *cp, struct cas_rx_comp *rxc, skb->len += hlen - swivel; skb_frag_fill_page_desc(frag, page->buffer, off, hlen - swivel); - __skb_frag_ref(frag); + skb_frag_ref(skb, 0); /* any more data? */ if ((words[0] & RX_COMP1_SPLIT_PKT) && ((dlen -= hlen) > 0)) { @@ -2022,7 +2022,7 @@ static int cas_rx_process_pkt(struct cas *cp, struct cas_rx_comp *rxc, frag++; skb_frag_fill_page_desc(frag, page->buffer, 0, hlen); - __skb_frag_ref(frag); + skb_frag_ref(skb, 1); RX_USED_ADD(page, hlen + cp->crc_size); } diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 38f263d4f06b..c273073b99f5 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -751,7 +751,7 @@ static void veth_xdp_get(struct xdp_buff *xdp) return; for (i = 0; i < sinfo->nr_frags; i++) - __skb_frag_ref(&sinfo->frags[i]); + get_netmem(skb_frag_netmem(&sinfo->frags[i])); } static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h index 04114c64dad9..f768a3fa1d60 100644 --- a/include/linux/skbuff_ref.h +++ b/include/linux/skbuff_ref.h @@ -12,26 +12,36 @@ bool napi_pp_get_page(netmem_ref netmem); /** - * __skb_frag_ref - take an addition reference on a paged fragment. - * @frag: the paged fragment + * skb_netmem_ref - acquire a fragment reference on a netmem + * @netmem: netmem to reference + * @recycle: whether page_pool recycling is enabled (e.g. skb->pp_recycle) * - * Takes an additional reference on the paged fragment @frag. + * Acquires pp_ref_count via napi_pp_get_page() if @recycle is true and + * @netmem belongs to a page_pool; otherwise acquires a non-pp backing + * reference via get_netmem(). Counterpart to skb_netmem_unref(). */ -static __always_inline void __skb_frag_ref(skb_frag_t *frag) +static __always_inline void skb_netmem_ref(netmem_ref netmem, bool recycle) { - get_netmem(skb_frag_netmem(frag)); +#ifdef CONFIG_PAGE_POOL + if (recycle && napi_pp_get_page(netmem)) + return; +#endif + get_netmem(netmem); } /** - * skb_frag_ref - take an addition reference on a paged fragment of an skb. + * skb_frag_ref - acquire a reference on a paged fragment of an skb * @skb: the buffer - * @f: the fragment offset. + * @f: the fragment offset * - * Takes an additional reference on the @f'th paged fragment of @skb. + * Acquires a reference on the @f'th fragment of @skb via skb_netmem_ref() + * (pp_ref_count if skb->pp_recycle and page_pool-backed, else non-pp + * backing refcount). Counterpart to skb_frag_unref(). */ static __always_inline void skb_frag_ref(struct sk_buff *skb, int f) { - __skb_frag_ref(&skb_shinfo(skb)->frags[f]); + skb_netmem_ref(skb_frag_netmem(&skb_shinfo(skb)->frags[f]), + skb->pp_recycle); } bool napi_pp_put_page(netmem_ref netmem); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c0c32a5b0e4b..d1fce9307cd2 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1133,7 +1133,7 @@ static void skb_release_data(struct sk_buff *skb, enum skb_drop_reason reason) int i; if (!skb_data_unref(skb, shinfo)) - goto exit; + return; if (skb_zcopy(skb)) { bool skip_unref = shinfo->flags & SKBFL_MANAGED_FRAG_REFS; @@ -1152,17 +1152,6 @@ free_head: kfree_skb_list_reason(shinfo->frag_list, reason); skb_free_head(skb); -exit: - /* When we clone an SKB we copy the reycling bit. The pp_recycle - * bit is only set on the head though, so in order to avoid races - * while trying to recycle fragments on skb_netmem_unref() we need - * to make one SKB responsible for triggering the recycle path. - * So disable the recycling bit if an SKB is cloned and we have - * additional references to the fragmented part of the SKB. - * Eventually the last SKB will have the recycling bit set and it's - * dataref set to 0, which will trigger the recycling - */ - skb->pp_recycle = 0; } /* @@ -2292,9 +2281,10 @@ struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom, n = NULL; goto out; } + n->pp_recycle = skb->pp_recycle; for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { skb_shinfo(n)->frags[i] = skb_shinfo(skb)->frags[i]; - skb_frag_ref(skb, i); + skb_frag_ref(n, i); } skb_shinfo(n)->nr_frags = i; skb_shinfo(n)->flags |= skb_shinfo(skb)->flags & SKBFL_SHARED_FRAG; @@ -3958,6 +3948,7 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) if (len <= skb_tailroom(to)) return skb_copy_bits(from, 0, skb_put(to, len), len); + to->pp_recycle = from->pp_recycle; if (hlen) { ret = skb_copy_bits(from, 0, skb_put(to, hlen), hlen); if (unlikely(ret)) @@ -3970,14 +3961,14 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) offset = from->data - (unsigned char *)page_address(page); __skb_fill_netmem_desc(to, 0, page_to_netmem(page), offset, plen); - get_page(page); + skb_frag_ref(to, 0); j = 1; len -= plen; } } if (!skb_frags_readable(from) && j > 0 && len) { - put_page(page); + skb_frag_unref(to, 0); return -EFAULT; } @@ -3985,7 +3976,7 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) if (unlikely(skb_orphan_frags(from, GFP_ATOMIC))) { if (j > 0) - put_page(page); + skb_frag_unref(to, 0); return -ENOMEM; } skb_zerocopy_clone(to, from, GFP_ATOMIC); @@ -4297,7 +4288,7 @@ static inline void skb_split_no_header(struct sk_buff *skb, * where splitting is expensive. * 2. Split is accurately. We make this. */ - skb_frag_ref(skb, i); + skb_frag_ref(skb1, k); skb_frag_off_add(&skb_shinfo(skb1)->frags[0], len - pos); skb_frag_size_sub(&skb_shinfo(skb1)->frags[0], len - pos); skb_frag_size_set(&skb_shinfo(skb)->frags[i], len - pos); @@ -4328,6 +4319,7 @@ void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len) skb_shinfo(skb1)->flags |= skb_shinfo(skb)->flags & zc_flags; skb_zerocopy_clone(skb1, skb, 0); + skb1->pp_recycle = skb->pp_recycle; if (len < pos) /* Split line is inside header. */ skb_split_inside_header(skb, skb1, len, pos); else /* Second chunk has no header, nothing to copy. */ @@ -4388,8 +4380,8 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) /* Actual merge is delayed until the point when we know we can * commit all, so that we don't have to undo partial changes */ - if (!skb_can_coalesce(tgt, to, skb_frag_page(fragfrom), - skb_frag_off(fragfrom))) { + if (!skb_can_coalesce_netmem(tgt, to, skb_frag_netmem(fragfrom), + skb_frag_off(fragfrom))) { merge = -1; } else { merge = to - 1; @@ -4436,8 +4428,8 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) to++; } else { - __skb_frag_ref(fragfrom); skb_frag_page_copy(fragto, fragfrom); + skb_frag_ref(tgt, to); skb_frag_off_copy(fragto, fragfrom); skb_frag_size_set(fragto, todo); @@ -5117,6 +5109,16 @@ normal: while (pos < offset + len) { if (i >= nfrags) { + if (skb_shinfo(nskb)->nr_frags && + nskb->pp_recycle != list_skb->pp_recycle) { + nskb->data_len = pos - offset - hsize; + nskb->len += nskb->data_len; + nskb->truesize += nskb->data_len; + if (__skb_linearize(nskb)) + goto err; + hsize = pos - offset; + nskb_frag = skb_shinfo(nskb)->frags; + } if (skb_orphan_frags(list_skb, GFP_ATOMIC) || skb_zerocopy_clone(nskb, list_skb, GFP_ATOMIC)) @@ -5159,8 +5161,10 @@ normal: goto err; } + if (!skb_shinfo(nskb)->nr_frags) + nskb->pp_recycle = frag_skb->pp_recycle; *nskb_frag = (i < 0) ? skb_head_frag_to_page_desc(frag_skb) : *frag; - __skb_frag_ref(nskb_frag); + skb_frag_ref(nskb, skb_shinfo(nskb)->nr_frags); size = skb_frag_size(nskb_frag); if (pos < offset) { @@ -6389,7 +6393,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, */ if (skb_pp_frag_ref(from)) { for (i = 0; i < from_shinfo->nr_frags; i++) - __skb_frag_ref(&from_shinfo->frags[i]); + get_netmem(skb_frag_netmem(&from_shinfo->frags[i])); } to->truesize += delta; diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c index 3b7d0ab2bcf1..35cc510db432 100644 --- a/net/tls/tls_device_fallback.c +++ b/net/tls/tls_device_fallback.c @@ -256,7 +256,7 @@ static int fill_sg_in(struct scatterlist *sg_in, for (i = 0; remaining > 0; i++) { skb_frag_t *frag = &record->frags[i]; - __skb_frag_ref(frag); + get_netmem(skb_frag_netmem(frag)); sg_set_page(sg_in + i, skb_frag_page(frag), skb_frag_size(frag), skb_frag_off(frag)); diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 6920940a35b4..103cf7c5dbfb 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -486,8 +486,7 @@ static int iptfs_skb_add_frags(struct sk_buff *skb, tofrag->len -= offset; offset = 0; } - __skb_frag_ref(tofrag); - shinfo->nr_frags++; + skb_frag_ref(skb, shinfo->nr_frags++); shinfo->flags |= SKBFL_SHARED_FRAG; /* see if we are done */ From 447f58db3505df87096d872ebc116e650f6a22ef Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 14 Oct 2026 17:37:19 +0000 Subject: [PATCH 1946/2126] net: skbuff: use skb_frag_ref() in skb_try_coalesce() skb_pp_frag_ref() was introduced solely to work around skb_frag_ref() ignoring skb->pp_recycle and incrementing the non-pp backing refcount. Now that skb_frag_ref() handles both pp_recycle=1 and pp_recycle=0 symmetrically, call skb_frag_ref() directly in skb_try_coalesce() and remove skb_pp_frag_ref(). Assisted-by: LLM Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261014173945.373295-6-almasrymina@google.com Acked-by: Stanislav Fomichev Signed-off-by: Paolo Abeni --- net/core/skbuff.c | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d1fce9307cd2..086de2d50d8e 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1078,37 +1078,6 @@ static bool skb_pp_recycle(struct sk_buff *skb, void *data) return napi_pp_put_page(page_to_netmem(virt_to_page(data))); } -/** - * skb_pp_frag_ref() - Increase fragment references of a page pool aware skb - * @skb: page pool aware skb - * - * Increase the fragment reference count (pp_ref_count) of a skb. This is - * intended to gain fragment references only for page pool aware skbs, - * i.e. when skb->pp_recycle is true, and not for fragments in a - * non-pp-recycling skb. It has a fallback to increase references on normal - * pages, as page pool aware skbs may also have normal page fragments. - */ -static int skb_pp_frag_ref(struct sk_buff *skb) -{ - struct skb_shared_info *shinfo; - netmem_ref head_netmem; - int i; - - if (!skb->pp_recycle) - return -EINVAL; - - shinfo = skb_shinfo(skb); - - for (i = 0; i < shinfo->nr_frags; i++) { - head_netmem = netmem_compound_head(shinfo->frags[i].netmem); - if (likely(netmem_is_pp(head_netmem))) - page_pool_ref_netmem(head_netmem); - else - page_ref_inc(netmem_to_page(head_netmem)); - } - return 0; -} - static void skb_kfree_head(void *head) { kfree(head); @@ -6391,10 +6360,8 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, /* if the skb is not cloned this does nothing * since we set nr_frags to 0. */ - if (skb_pp_frag_ref(from)) { - for (i = 0; i < from_shinfo->nr_frags; i++) - get_netmem(skb_frag_netmem(&from_shinfo->frags[i])); - } + for (i = 0; i < from_shinfo->nr_frags; i++) + skb_frag_ref(from, i); to->truesize += delta; to->len += len; From 2285346afc99d2439f7f031c9d7f30cf045a3815 Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 14 Oct 2026 17:37:20 +0000 Subject: [PATCH 1947/2126] net: kunit: test netmem, page_pool, and skb frag refcounting Verify that non-pp (page._refcount / binding->ref) and page_pool (pp_ref_count) references stay balanced without cross-counter leaks or underflows across regular pages, page_pool pages, non-pp net_iovs, and page_pool net_iovs with both pp_recycle=0 and pp_recycle=1. Cover get/put_net_iov(), get/put_netmem(), napi_pp_get/put_page(), skb_netmem_ref/unref(), skb_frag_ref/unref(), pskb_copy(), skb_zerocopy(), skb_shift(), skb_split(), skb_try_coalesce(), skb_release_data() (clones, unclone ordering, pskb_extract(), and skb_morph()), skb_segment(), and devmem tcp_recvmsg_dmabuf() / SO_DEVMEM_DONTNEED. Export skb_shift() via EXPORT_SYMBOL_IF_KUNIT() so the test links when built as a module (CONFIG_NET_TEST=m). Assisted-by: LLM Signed-off-by: Mina Almasry Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20261014173945.373295-7-almasrymina@google.com Acked-by: Stanislav Fomichev Signed-off-by: Paolo Abeni --- net/core/net_test.c | 1222 +++++++++++++++++++++++++++++++++++++++++++ net/core/skbuff.c | 2 + 2 files changed, 1224 insertions(+) diff --git a/net/core/net_test.c b/net/core/net_test.c index bc2ef7612e7d..2bb01430a89f 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -457,10 +457,1231 @@ static void ip_tunnel_flags_test_run(struct kunit *test) KUNIT_ASSERT_TRUE(test, __ipt_flag_op(bitmap_equal, exp, out)); } +/* Netmem & SKB fragment refcounting */ + +#include +#include +#include +#include +#include +#include +#include "devmem.h" +#include "netmem_priv.h" + +static void netmem_ref_test_page(struct kunit *test) +{ + struct sk_buff *skb; + netmem_ref netmem; + struct page *page; + int base_ref; + + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + netmem = page_to_netmem(page); + base_ref = page_ref_count(page); + + /* Layer 1: get_netmem / put_netmem use page non-pp refcount */ + get_netmem(netmem); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + put_netmem(netmem); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + +#ifdef CONFIG_PAGE_POOL + /* Layer 2: napi_pp_get/put_page return false on non-PP page */ + KUNIT_EXPECT_FALSE(test, napi_pp_get_page(netmem)); + KUNIT_EXPECT_FALSE(test, napi_pp_put_page(netmem)); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); +#endif + + /* Layer 3: skb_netmem_ref / unref fall back to non-pp on non-PP page */ + skb_netmem_ref(netmem, false); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + skb_netmem_unref(netmem, false); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + skb_netmem_ref(netmem, true); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + skb_netmem_unref(netmem, true); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + /* Layer 4: skb_frag_ref / skb_frag_unref on non-PP page */ + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + + skb->pp_recycle = 1; + skb_frag_ref(skb, 0); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + skb_frag_unref(skb, 0); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + skb_shinfo(skb)->nr_frags = 0; + consume_skb(skb); + __free_page(page); +} + +#ifdef CONFIG_PAGE_POOL +static void netmem_ref_test_pp_page(struct kunit *test) +{ + struct page_pool_params pp_params = { + .order = 0, + .pool_size = 4, + .nid = NUMA_NO_NODE, + }; + struct page_pool *pool; + struct sk_buff *skb, *copy, *clone, *split; + netmem_ref netmem; + struct page *page; + long base_pp_ref; + int base_ref; + + pool = page_pool_create(&pp_params); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pool); + + page = page_pool_dev_alloc_pages(pool); + KUNIT_ASSERT_NOT_NULL(test, page); + netmem = page_to_netmem(page); + base_ref = page_ref_count(page); + base_pp_ref = atomic_long_read(&page->pp_ref_count); + + /* Layer 1: get_netmem / put_netmem always use non-pp refcount */ + get_netmem(netmem); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + put_netmem(netmem); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + /* Layer 2: napi_pp_get/put_page use pp_ref_count */ + KUNIT_EXPECT_TRUE(test, napi_pp_get_page(netmem)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_TRUE(test, napi_pp_put_page(netmem)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* Layer 3: skb_netmem_ref / unref obey recycle flag */ + skb_netmem_ref(netmem, false); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + skb_netmem_unref(netmem, false); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + skb_netmem_ref(netmem, true); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + skb_netmem_unref(netmem, true); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* Layer 4: skb_frag_ref / skb_frag_unref match on pp_recycle=1 & 0 */ + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len = 64; + skb->data_len = 64; + + skb->pp_recycle = 1; + skb_frag_ref(skb, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + skb_frag_unref(skb, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* pskb_copy on pp_recycle=1 skb propagates pp_recycle & pp_ref_count */ + copy = pskb_copy(skb, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, copy); + KUNIT_EXPECT_TRUE(test, copy->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(copy); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* skb_zerocopy on pp_recycle=1 skb propagates pp_ref_count */ + copy = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, copy); + skb_put(copy, skb_tailroom(copy)); + skb->head_frag = 1; + KUNIT_ASSERT_EQ(test, skb_zerocopy(copy, skb, skb->len, 0), 0); + skb->head_frag = 0; + KUNIT_EXPECT_TRUE(test, copy->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(copy); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* skb_clone + pskb_expand_head preserves pp_recycle and pp_ref_count */ + clone = skb_clone(skb, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone); + KUNIT_ASSERT_EQ(test, pskb_expand_head(clone, 32, 0, GFP_KERNEL), 0); + KUNIT_EXPECT_TRUE(test, clone->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(clone); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* skb_split inside linear header & inside nonlinear page_pool frags */ + skb_shinfo(skb)->nr_frags = 0; + skb->len = 0; + skb->data_len = 0; + skb_reset_tail_pointer(skb); + skb_put(skb, 32); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len += 64; + skb->data_len = 64; + split = alloc_skb(32, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, split); + skb_split(skb, split, 16); + KUNIT_EXPECT_TRUE(test, split->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + skb_shinfo(split)->nr_frags = 0; + consume_skb(split); + skb->len = 0; + skb->data_len = 0; + skb_reset_tail_pointer(skb); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len = 64; + skb->data_len = 64; + + split = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, split); + skb_split(skb, split, 32); + KUNIT_EXPECT_TRUE(test, split->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(split); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* skb_segment on pp_recycle=1 skb propagates pp_recycle to segments */ + skb->protocol = htons(ETH_P_IP); + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_shinfo(skb)->gso_size = 16; + split = skb_segment(skb, NETIF_F_SG | NETIF_F_HW_CSUM); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(split)); + KUNIT_EXPECT_TRUE(test, split->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + kfree_skb_list(split); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* skb_shift balances pp_ref_count across split, partial coalesce, + * multi-frag coalesce + partial next-frag shift, and full merge. + */ + skb_fill_netmem_desc(skb, 0, netmem, 0, 32); + skb_fill_netmem_desc(skb, 1, netmem, 64, 32); + page_pool_ref_page(page); + skb->len = 64; + skb->data_len = 64; + split = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, split); + split->pp_recycle = 1; + KUNIT_EXPECT_EQ(test, skb_shift(split, skb, 16), 16); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, skb_shift(split, skb, 8), 8); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, skb_shift(split, skb, 24), 24); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_EQ(test, skb_shift(split, skb, 16), 16); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + skb_shinfo(split)->nr_frags = 0; + consume_skb(split); + page_pool_put_full_page(pool, page, false); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len = 64; + skb->data_len = 64; + + skb->pp_recycle = 0; + skb_frag_ref(skb, 0); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + skb_frag_unref(skb, 0); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + skb_shinfo(skb)->nr_frags = 0; + consume_skb(skb); + page_pool_put_full_page(pool, page, false); + page_pool_destroy(pool); + + /* Order-1 compound page_pool page: tail netmem resolves to head & + * build_skb(head_frag=1, pp_recycle=1) skb_zerocopy uses pp_ref_count. + */ + pp_params.order = 1; + pool = page_pool_create(&pp_params); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pool); + page = page_pool_dev_alloc_pages(pool); + KUNIT_ASSERT_NOT_NULL(test, page); + base_ref = page_ref_count(page); + base_pp_ref = atomic_long_read(&page->pp_ref_count); + + netmem = page_to_netmem(page + 1); + KUNIT_EXPECT_TRUE(test, napi_pp_get_page(netmem)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + KUNIT_EXPECT_TRUE(test, napi_pp_put_page(netmem)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + skb = build_skb(page_address(page), PAGE_SIZE); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb->pp_recycle = 1; + skb_put(skb, 64); + page_pool_ref_page(page); + + copy = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, copy); + skb_put(copy, skb_tailroom(copy)); + KUNIT_ASSERT_EQ(test, skb_zerocopy(copy, skb, skb->len, 0), 0); + KUNIT_EXPECT_TRUE(test, copy->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(copy); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + consume_skb(skb); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + page_pool_put_full_page(pool, page, false); + page_pool_destroy(pool); +} +#endif + +#if defined(CONFIG_PAGE_POOL) && defined(CONFIG_NET_DEVMEM) +static void dummy_percpu_ref_release(struct percpu_ref *ref) +{ +} + +static void netmem_ref_test_net_iov(struct kunit *test) +{ + struct net_devmem_dmabuf_binding binding = {}; + struct page_pool_params pp_params = { + .order = 0, + .pool_size = 4, + .nid = NUMA_NO_NODE, + }; + struct sk_buff *skb, *clone, *copy; + struct page_pool *pool; + struct net_iov niov = {}; + netmem_ref netmem; + long base_ref; + int err; + + err = percpu_ref_init(&binding.ref, dummy_percpu_ref_release, + PERCPU_REF_INIT_ATOMIC, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, err, 0); + + net_iov_init(&niov, &binding.area, NET_IOV_DMABUF); + netmem = net_iov_to_netmem(&niov); + base_ref = atomic_long_read(&binding.ref.data->count); + + /* Non-PP net_iov: get/put_net_iov & get/put_netmem */ + get_net_iov(&niov); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref + 1); + put_net_iov(&niov); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + + KUNIT_EXPECT_FALSE(test, napi_pp_get_page(netmem)); + KUNIT_EXPECT_FALSE(test, napi_pp_put_page(netmem)); + + skb_netmem_ref(netmem, true); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref + 1); + skb_netmem_unref(netmem, true); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + + /* Attach net_iov to a page_pool to test PP net_iov behavior */ + pool = page_pool_create(&pp_params); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pool); + netmem_set_pp(netmem, pool); + netmem_or_pp_magic(netmem, PP_SIGNATURE); + atomic_long_set(&niov.desc.pp_ref_count, 2); + + /* Layer 0 & 1: get_net_iov / get_netmem grab non-pp ref even on PP */ + get_net_iov(&niov); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref + 1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + put_net_iov(&niov); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + + /* Layer 2: napi_pp_get/put_page use pp_ref_count */ + KUNIT_EXPECT_TRUE(test, napi_pp_get_page(netmem)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + KUNIT_EXPECT_TRUE(test, napi_pp_put_page(netmem)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + /* Layer 4: skb_frag_ref / skb_frag_unref on PP net_iov */ + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len = 64; + skb->data_len = 64; + + skb->pp_recycle = 1; + skb_frag_ref(skb, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + skb_frag_unref(skb, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + /* pskb_copy on pp_recycle=1 net_iov skb keeps pp_ref_count */ + copy = pskb_copy(skb, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, copy); + KUNIT_EXPECT_TRUE(test, copy->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + consume_skb(copy); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + /* skb_zerocopy on pp_recycle=1 net_iov skb keeps pp_ref_count */ + copy = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, copy); + skb_put(copy, skb_tailroom(copy)); + skb->head_frag = 1; + skb->unreadable = 1; + KUNIT_ASSERT_EQ(test, skb_zerocopy(copy, skb, skb->len, 0), 0); + skb->head_frag = 0; + KUNIT_EXPECT_TRUE(test, copy->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + consume_skb(copy); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + /* skb_shift balances pp_ref_count on split and merge */ + copy = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, copy); + copy->pp_recycle = 1; + KUNIT_EXPECT_EQ(test, skb_shift(copy, skb, 16), 16); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + KUNIT_EXPECT_EQ(test, skb_shift(copy, skb, 48), 48); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + skb_shinfo(copy)->nr_frags = 0; + consume_skb(copy); + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len = 64; + skb->data_len = 64; + + /* Uncloning a cloned pp_recycle=1 net_iov skb keeps pp_ref_count */ + clone = skb_clone(skb, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone); + KUNIT_ASSERT_EQ(test, pskb_expand_head(skb, 32, 0, GFP_KERNEL), 0); + KUNIT_EXPECT_TRUE(test, skb->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + consume_skb(clone); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + skb->pp_recycle = 0; + skb_frag_ref(skb, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref + 1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + skb_frag_unref(skb, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_ref); + + skb_shinfo(skb)->nr_frags = 0; + consume_skb(skb); + netmem_clear_pp_magic(netmem); + netmem_set_pp(netmem, NULL); + page_pool_destroy(pool); + percpu_ref_exit(&binding.ref); +} + +static void netmem_ref_test_release_data(struct kunit *test) +{ + struct page_pool_params pp_params = { + .order = 0, + .pool_size = 4, + .nid = NUMA_NO_NODE, + }; + struct sk_buff *skb, *clone1, *clone2, *ext; + struct net_devmem_dmabuf_binding binding = {}; + struct net_iov niov = {}; + struct page_pool *pool; + struct page *page; + netmem_ref netmem; + long base_pp_ref; + int base_ref; + int i; + + pool = page_pool_create(&pp_params); + KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); + page = page_pool_dev_alloc_pages(pool); + KUNIT_ASSERT_NOT_NULL(test, page); + netmem = page_to_netmem(page); + page_pool_ref_netmem(netmem); + + /* 3-way clone chain: only last clone drops pp_ref_count */ + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_put(skb, 32); + skb->pp_recycle = 1; + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len += 64; + skb->data_len = 64; + base_ref = page_ref_count(page); + base_pp_ref = atomic_long_read(&page->pp_ref_count); + + page_pool_ref_netmem(netmem); + clone1 = skb_clone(skb, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone1); + clone2 = skb_clone(clone1, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone2); + + /* Freeing head skb first leaves clone1/clone2 pp_recycle=1 intact */ + consume_skb(skb); + KUNIT_EXPECT_TRUE(test, clone1->pp_recycle); + KUNIT_EXPECT_TRUE(test, clone2->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + consume_skb(clone2); + KUNIT_EXPECT_TRUE(test, clone1->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + consume_skb(clone1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + + /* All 4 combinations of (unclone skb vs clone) x (free order) */ + for (i = 0; i < 4; i++) { + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_put(skb, 32); + skb->pp_recycle = 1; + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len += 64; + skb->data_len = 64; + page_pool_ref_netmem(netmem); + + clone1 = skb_clone(skb, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone1); + KUNIT_ASSERT_EQ(test, + pskb_expand_head((i & 1) ? clone1 : skb, + 32, 0, GFP_KERNEL), 0); + KUNIT_EXPECT_TRUE(test, skb->pp_recycle); + KUNIT_EXPECT_TRUE(test, clone1->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + + if (i & 2) { + consume_skb(clone1); + KUNIT_EXPECT_EQ(test, + atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + consume_skb(skb); + } else { + consume_skb(skb); + KUNIT_EXPECT_EQ(test, + atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + consume_skb(clone1); + } + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + } + + /* pskb_extract carving inside header & inside nonlinear frags */ + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_put(skb, 32); + skb->pp_recycle = 1; + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len += 64; + skb->data_len = 64; + page_pool_ref_netmem(netmem); + + /* Carve inside header keeping frag -> pp_ref_count +1 until free */ + ext = pskb_extract(skb, 16, skb->len - 16, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ext); + KUNIT_EXPECT_TRUE(test, ext->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(ext); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + + /* Carve + trim + skb_condense ref/unrefs pp_ref_count cleanly */ + ext = pskb_extract(skb, 16, 48, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ext); + KUNIT_EXPECT_TRUE(test, ext->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(ext); + + /* Carve inside nonlinear keeping frag -> pp_ref_count +1 until free */ + ext = pskb_extract(skb, 48, skb->len - 48, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ext); + KUNIT_EXPECT_TRUE(test, ext->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); + consume_skb(ext); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + + /* skb_morph drops old skb data via skb_release_data */ + page_pool_ref_netmem(netmem); + clone1 = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone1); + clone1->pp_recycle = 1; + skb_fill_netmem_desc(clone1, 0, netmem, 0, 64); + clone1->len = 64; + clone1->data_len = 64; + skb_morph(clone1, skb); + KUNIT_EXPECT_TRUE(test, clone1->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), + base_pp_ref + 1); + consume_skb(clone1); + kfree_skb(skb); + page_pool_put_full_page(pool, page, false); + page_pool_put_full_page(pool, page, false); + + /* Also verify pskb_extract on page_pool net_iov */ + KUNIT_ASSERT_EQ(test, + percpu_ref_init(&binding.ref, dummy_percpu_ref_release, + PERCPU_REF_INIT_ATOMIC, GFP_KERNEL), + 0); + net_iov_init(&niov, &binding.area, NET_IOV_DMABUF); + netmem = net_iov_to_netmem(&niov); + netmem_set_pp(netmem, pool); + netmem_or_pp_magic(netmem, PP_SIGNATURE); + atomic_long_set(&niov.desc.pp_ref_count, 2); + + skb = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb_put(skb, 32); + skb->pp_recycle = 1; + skb_fill_netmem_desc(skb, 0, netmem, 0, 64); + skb->len += 64; + skb->data_len = 64; + + ext = pskb_extract(skb, 48, skb->len - 48, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ext); + KUNIT_EXPECT_TRUE(test, ext->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + consume_skb(ext); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + skb_shinfo(skb)->nr_frags = 0; + consume_skb(skb); + netmem_clear_pp_magic(netmem); + netmem_set_pp(netmem, NULL); + page_pool_destroy(pool); + percpu_ref_exit(&binding.ref); +} + +static void netmem_ref_test_skb_segment(struct kunit *test) +{ + struct page_pool_params pp_params = { + .order = 0, + .pool_size = 4, + .nid = NUMA_NO_NODE, + }; + struct ubuf_info uarg = { + .flags = SKBFL_ZEROCOPY_ENABLE, + }; + struct sk_buff *head, *list, *segs, *seg; + struct net_devmem_dmabuf_binding binding = {}; + struct net_iov niov = {}; + struct page *pp_page, *reg_page; + netmem_ref pp_nm, niov_nm; + struct page_pool *pool; + long base_pp_ref, base_iov_ref; + int base_pp_page_ref, base_reg_ref; + + pool = page_pool_create(&pp_params); + KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); + pp_page = page_pool_dev_alloc_pages(pool); + KUNIT_ASSERT_NOT_NULL(test, pp_page); + pp_nm = page_to_netmem(pp_page); + page_pool_ref_netmem(pp_nm); + reg_page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, reg_page); + + KUNIT_ASSERT_EQ(test, + percpu_ref_init(&binding.ref, dummy_percpu_ref_release, + PERCPU_REF_INIT_ATOMIC, GFP_KERNEL), + 0); + net_iov_init(&niov, &binding.area, NET_IOV_DMABUF); + niov_nm = net_iov_to_netmem(&niov); + netmem_set_pp(niov_nm, pool); + netmem_or_pp_magic(niov_nm, PP_SIGNATURE); + atomic_long_set(&niov.desc.pp_ref_count, 2); + + base_pp_ref = atomic_long_read(&pp_page->pp_ref_count); + base_pp_page_ref = page_ref_count(pp_page); + base_reg_ref = page_ref_count(reg_page); + base_iov_ref = atomic_long_read(&binding.ref.data->count); + + /* 1. Single GSO skb with page_pool net_iov frags */ + head = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, head); + head->pp_recycle = 1; + head->protocol = htons(ETH_P_IP); + skb_reset_mac_header(head); + skb_reset_network_header(head); + skb_fill_netmem_desc(head, 0, niov_nm, 0, 64); + head->len = 64; + head->data_len = 64; + skb_shinfo(head)->gso_size = 16; + + segs = skb_segment(head, NETIF_F_SG | NETIF_F_HW_CSUM); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(segs)); + for (seg = segs; seg; seg = seg->next) + KUNIT_EXPECT_TRUE(test, seg->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 6L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_iov_ref); + kfree_skb_list(segs); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + skb_shinfo(head)->nr_frags = 0; + consume_skb(head); + + /* 2. GRO frag_list fast path (skb_clone of pp_recycle=1 list_skb) */ + head = alloc_skb(64, GFP_KERNEL); + list = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, head); + KUNIT_ASSERT_NOT_NULL(test, list); + head->pp_recycle = 1; + list->pp_recycle = 1; + head->protocol = htons(ETH_P_IP); + skb_reset_mac_header(head); + skb_reset_network_header(head); + skb_put(head, 16); + skb_fill_netmem_desc(head, 0, pp_nm, 0, 16); + head->len += 16; + head->data_len = 16; + page_pool_ref_netmem(pp_nm); + + skb_put(list, 16); + skb_fill_netmem_desc(list, 0, pp_nm, 16, 16); + list->len += 16; + list->data_len = 16; + page_pool_ref_netmem(pp_nm); + + skb_shinfo(head)->frag_list = list; + head->len += list->len; + head->data_len += list->len; + skb_shinfo(head)->gso_size = 32; + + segs = skb_segment(head, NETIF_F_SG | NETIF_F_HW_CSUM); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(segs)); + for (seg = segs; seg; seg = seg->next) + KUNIT_EXPECT_TRUE(test, seg->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 4); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + kfree_skb_list(segs); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 2); + consume_skb(head); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + + /* 3. Mixed GRO frag_list (head pp_recycle=1 + list pp_recycle=0): + * straddling segment linearizes its pp_recycle=1 prefix before + * attaching the pp_recycle=0 frag so no nskb mixes incompatible + * fragment refcount types; non-straddling segments stay zero-copy SG. + */ + head = alloc_skb(64, GFP_KERNEL); + list = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, head); + KUNIT_ASSERT_NOT_NULL(test, list); + head->pp_recycle = 1; + list->pp_recycle = 0; + head->protocol = htons(ETH_P_IP); + skb_reset_mac_header(head); + skb_reset_network_header(head); + skb_fill_netmem_desc(head, 0, pp_nm, 0, 24); + head->len = 24; + head->data_len = 24; + page_pool_ref_netmem(pp_nm); + + skb_fill_page_desc(list, 0, reg_page, 0, 24); + get_page(reg_page); + list->len = 24; + list->data_len = 24; + + skb_shinfo(head)->frag_list = list; + head->len += list->len; + head->data_len += list->len; + skb_shinfo(head)->gso_size = 16; + + segs = skb_segment(head, NETIF_F_SG | NETIF_F_HW_CSUM); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(segs)); + KUNIT_EXPECT_TRUE(test, segs->pp_recycle); + KUNIT_EXPECT_FALSE(test, segs->next->pp_recycle); + KUNIT_EXPECT_FALSE(test, segs->next->next->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(reg_page), base_reg_ref + 3); + kfree_skb_list(segs); + consume_skb(head); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(reg_page), base_reg_ref); + + /* 4. Reverse mixed frag_list (head pp_recycle=0 + list pp_recycle=1): + * Crossing from pp_recycle=0 head into pp_recycle=1 list_skb must not + * elevate page_ref_count(pp_page) instead of pp_ref_count. + */ + head = alloc_skb(64, GFP_KERNEL); + list = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, head); + KUNIT_ASSERT_NOT_NULL(test, list); + head->pp_recycle = 0; + list->pp_recycle = 1; + head->protocol = htons(ETH_P_IP); + skb_reset_mac_header(head); + skb_reset_network_header(head); + skb_fill_page_desc(head, 0, reg_page, 0, 24); + get_page(reg_page); + head->len = 24; + head->data_len = 24; + + skb_fill_netmem_desc(list, 0, pp_nm, 0, 24); + page_pool_ref_netmem(pp_nm); + list->len = 24; + list->data_len = 24; + + skb_shinfo(head)->frag_list = list; + head->len += list->len; + head->data_len += list->len; + skb_shinfo(head)->gso_size = 16; + + segs = skb_segment(head, NETIF_F_SG | NETIF_F_HW_CSUM); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(segs)); + KUNIT_EXPECT_FALSE(test, segs->pp_recycle); + KUNIT_EXPECT_TRUE(test, segs->next->pp_recycle); + KUNIT_EXPECT_TRUE(test, segs->next->next->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 3); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(reg_page), base_reg_ref + 2); + kfree_skb_list(segs); + consume_skb(head); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(reg_page), base_reg_ref); + + /* 5. Linear head_skb (nr_frags=0) + mixed pp_recycle frag_list where + * member A has linear + frag (pp_recycle=1) and tail member B has + * linear len == skb_headlen(A) (pp_recycle=0): keeps SG clone path + * synchronized without hitting BUG_ON(i >= nfrags). + */ + head = alloc_skb(64, GFP_KERNEL); + list = alloc_skb(64, GFP_KERNEL); + seg = alloc_skb(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, head); + KUNIT_ASSERT_NOT_NULL(test, list); + KUNIT_ASSERT_NOT_NULL(test, seg); + head->pp_recycle = 0; + list->pp_recycle = 1; + seg->pp_recycle = 0; + head->protocol = htons(ETH_P_IP); + skb_reset_mac_header(head); + skb_reset_network_header(head); + skb_put(head, 32); + skb_put(list, 8); + skb_fill_netmem_desc(list, 0, pp_nm, 0, 24); + page_pool_ref_netmem(pp_nm); + list->len += 24; + list->data_len = 24; + skb_put(seg, 8); + list->next = seg; + skb_shinfo(head)->frag_list = list; + head->len += list->len + seg->len; + head->data_len = list->len + seg->len; + skb_shinfo(head)->gso_size = 32; + + segs = skb_segment(head, NETIF_F_SG | NETIF_F_HW_CSUM); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(segs)); + KUNIT_EXPECT_FALSE(test, segs->pp_recycle); + KUNIT_EXPECT_TRUE(test, segs->next->pp_recycle); + KUNIT_EXPECT_FALSE(test, segs->next->next->pp_recycle); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + kfree_skb_list(segs); + consume_skb(head); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + + /* 6. skb_zerocopy -EFAULT rollback when from->head_frag (pp_page) is + * followed by unreadable net_iov frag drops pp_ref_count via + * skb_frag_unref(to, 0). + */ + head = build_skb(page_address(pp_page), PAGE_SIZE); + KUNIT_ASSERT_NOT_NULL(test, head); + head->pp_recycle = 1; + skb_put(head, 32); + page_pool_ref_netmem(pp_nm); + skb_fill_netmem_desc(head, 0, niov_nm, 0, 32); + napi_pp_get_page(niov_nm); + head->len += 32; + head->data_len += 32; + + seg = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, seg); + skb_put(seg, skb_tailroom(seg)); + KUNIT_EXPECT_EQ(test, skb_zerocopy(seg, head, head->len, 0), -EFAULT); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 1); + skb_shinfo(seg)->nr_frags = 0; + consume_skb(seg); + consume_skb(head); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + /* 7. skb_zerocopy -ENOMEM rollback when skb_orphan_frags() fails on + * shared zerocopy skb drops pp_ref_count via skb_frag_unref(to, 0). + */ + head = build_skb(page_address(pp_page), PAGE_SIZE); + KUNIT_ASSERT_NOT_NULL(test, head); + head->pp_recycle = 1; + skb_put(head, 32); + page_pool_ref_netmem(pp_nm); + skb_zcopy_init(head, &uarg); + skb_get(head); + + seg = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, seg); + skb_put(seg, skb_tailroom(seg)); + KUNIT_EXPECT_EQ(test, skb_zerocopy(seg, head, head->len, 0), -ENOMEM); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 1); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + skb_shinfo(seg)->nr_frags = 0; + consume_skb(seg); + consume_skb(head); + skb_shinfo(head)->flags &= ~SKBFL_ZEROCOPY_ENABLE; + consume_skb(head); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + + page_pool_put_full_page(pool, pp_page, false); + page_pool_put_full_page(pool, pp_page, false); + __free_page(reg_page); + netmem_clear_pp_magic(niov_nm); + netmem_set_pp(niov_nm, NULL); + page_pool_destroy(pool); + percpu_ref_exit(&binding.ref); +} + +static void netmem_ref_test_try_coalesce(struct kunit *test) +{ + struct page_pool_params pp_params = { + .order = 0, + .pool_size = 4, + .nid = NUMA_NO_NODE, + }; + struct sk_buff *to, *from, *clone; + struct net_devmem_dmabuf_binding binding = {}; + struct net_iov niov = {}; + struct page *pp_page, *reg_page; + netmem_ref pp_nm, niov_nm; + struct page_pool *pool; + long base_pp_ref, base_iov_ref; + int base_pp_page_ref, base_reg_ref; + bool fragstolen; + int delta; + + pool = page_pool_create(&pp_params); + KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); + pp_page = page_pool_dev_alloc_pages(pool); + KUNIT_ASSERT_NOT_NULL(test, pp_page); + pp_nm = page_to_netmem(pp_page); + page_pool_ref_netmem(pp_nm); + + reg_page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, reg_page); + + KUNIT_ASSERT_EQ(test, + percpu_ref_init(&binding.ref, dummy_percpu_ref_release, + PERCPU_REF_INIT_ATOMIC, GFP_KERNEL), + 0); + net_iov_init(&niov, &binding.area, NET_IOV_DMABUF); + niov_nm = net_iov_to_netmem(&niov); + netmem_set_pp(niov_nm, pool); + netmem_or_pp_magic(niov_nm, PP_SIGNATURE); + atomic_long_set(&niov.desc.pp_ref_count, 2); + + base_pp_ref = atomic_long_read(&pp_page->pp_ref_count); + base_pp_page_ref = page_ref_count(pp_page); + base_reg_ref = page_ref_count(reg_page); + base_iov_ref = atomic_long_read(&binding.ref.data->count); + + /* 1. Uncloned pp_recycle=1 from: frags stolen without extra ref */ + to = alloc_skb(0, GFP_KERNEL); + from = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, to); + KUNIT_ASSERT_NOT_NULL(test, from); + skb_put(to, skb_tailroom(to)); + to->pp_recycle = 1; + from->pp_recycle = 1; + skb_add_rx_frag(from, 0, pp_page, 0, 64, PAGE_SIZE); + page_pool_ref_netmem(pp_nm); + KUNIT_EXPECT_TRUE(test, skb_try_coalesce(to, from, &fragstolen, + &delta)); + KUNIT_EXPECT_EQ(test, skb_shinfo(from)->nr_frags, 0); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 1); + consume_skb(from); + consume_skb(to); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + + /* 2. Cloned pp_recycle=1 from (pp_page + non-PP reg_page fallback): + * skb_frag_ref(from, i) increments pp_ref_count for pp_page and + * page_ref_count for reg_page. + */ + to = alloc_skb(0, GFP_KERNEL); + from = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, to); + KUNIT_ASSERT_NOT_NULL(test, from); + skb_put(to, skb_tailroom(to)); + to->pp_recycle = 1; + from->pp_recycle = 1; + skb_add_rx_frag(from, 0, pp_page, 0, 32, PAGE_SIZE); + page_pool_ref_netmem(pp_nm); + skb_add_rx_frag(from, 1, reg_page, 0, 32, PAGE_SIZE); + get_page(reg_page); + + clone = skb_clone(from, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone); + KUNIT_EXPECT_TRUE(test, skb_try_coalesce(to, from, &fragstolen, + &delta)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref + 2); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(reg_page), base_reg_ref + 2); + consume_skb(from); + consume_skb(clone); + consume_skb(to); + KUNIT_EXPECT_EQ(test, atomic_long_read(&pp_page->pp_ref_count), + base_pp_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(pp_page), base_pp_page_ref); + KUNIT_EXPECT_EQ(test, page_ref_count(reg_page), base_reg_ref); + + /* 3. Cloned unreadable pp_recycle=1 net_iov skb: skb_try_coalesce + * increments niov.desc.pp_ref_count via skb_frag_ref(from, i). + */ + to = alloc_skb(0, GFP_KERNEL); + from = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, to); + KUNIT_ASSERT_NOT_NULL(test, from); + skb_put(to, skb_tailroom(to)); + to->pp_recycle = 1; + to->unreadable = 1; + from->pp_recycle = 1; + skb_add_rx_frag_netmem(from, 0, niov_nm, 0, 64, PAGE_SIZE); + napi_pp_get_page(niov_nm); + + clone = skb_clone(from, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, clone); + KUNIT_EXPECT_TRUE(test, skb_try_coalesce(to, from, &fragstolen, + &delta)); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 4L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_iov_ref); + consume_skb(from); + consume_skb(clone); + consume_skb(to); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + page_pool_put_full_page(pool, pp_page, false); + page_pool_put_full_page(pool, pp_page, false); + __free_page(reg_page); + netmem_clear_pp_magic(niov_nm); + netmem_set_pp(niov_nm, NULL); + page_pool_destroy(pool); + percpu_ref_exit(&binding.ref); +} + +#ifdef CONFIG_INET +static void netmem_ref_test_tcp_devmem_recv(struct kunit *test) +{ + char cmsg_buf[CMSG_SPACE(sizeof(struct dmabuf_cmsg))] + __aligned(__alignof__(struct cmsghdr)) = {}; + struct page_pool_params pp_params = { + .order = 0, + .pool_size = 4, + .nid = NUMA_NO_NODE, + }; + struct net_devmem_dmabuf_binding binding = {}; + struct msghdr msg = {}; + struct dmabuf_token token; + struct dmabuf_cmsg *cmsg; + struct net_iov niov = {}; + struct page_pool *pool; + struct cmsghdr *cm; + struct socket *sock; + struct sk_buff *skb; + struct kvec iov = {}; + netmem_ref niov_nm; + long base_iov_ref; + int ret; + + KUNIT_ASSERT_EQ(test, + sock_create_kern(&init_net, AF_INET, SOCK_STREAM, + IPPROTO_TCP, &sock), + 0); + sock->sk->sk_state = TCP_ESTABLISHED; + inet_csk(sock->sk)->icsk_ack.rcv_mss = 64; + tcp_sk(sock->sk)->copied_seq = 0; + + pool = page_pool_create(&pp_params); + if (IS_ERR(pool)) { + sock->sk->sk_state = TCP_CLOSE; + sock_release(sock); + KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); + } + + ret = percpu_ref_init(&binding.ref, dummy_percpu_ref_release, + PERCPU_REF_INIT_ATOMIC, GFP_KERNEL); + if (ret) { + page_pool_destroy(pool); + sock->sk->sk_state = TCP_CLOSE; + sock_release(sock); + KUNIT_ASSERT_EQ(test, ret, 0); + } + binding.area.niovs = &niov; + net_iov_init(&niov, &binding.area, NET_IOV_DMABUF); + niov_nm = net_iov_to_netmem(&niov); + netmem_set_pp(niov_nm, pool); + netmem_or_pp_magic(niov_nm, PP_SIGNATURE); + atomic_long_set(&niov.desc.pp_ref_count, 2); + base_iov_ref = atomic_long_read(&binding.ref.data->count); + + /* 1. Receive via tcp_recvmsg_dmabuf -> SO_DEVMEM_DONTNEED release */ + skb = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb->pp_recycle = 1; + skb_add_rx_frag_netmem(skb, 0, niov_nm, 0, 64, PAGE_SIZE); + napi_pp_get_page(niov_nm); + TCP_SKB_CB(skb)->seq = 0; + TCP_SKB_CB(skb)->end_seq = 64; + skb_queue_tail(&sock->sk->sk_receive_queue, skb); + + msg.msg_control = cmsg_buf; + msg.msg_controllen = sizeof(cmsg_buf); + ret = kernel_recvmsg(sock, &msg, &iov, 0, 64, + MSG_SOCK_DEVMEM | MSG_DONTWAIT); + KUNIT_ASSERT_EQ(test, ret, 64); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), + base_iov_ref); + + cm = (struct cmsghdr *)cmsg_buf; + cmsg = CMSG_DATA(cm); + token.token_start = cmsg->frag_token; + token.token_count = 1; + KUNIT_EXPECT_EQ(test, + sock_setsockopt(sock, SOL_SOCKET, SO_DEVMEM_DONTNEED, + KERNEL_SOCKPTR(&token), sizeof(token)), + 1); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + /* 2. Receive second packet & destroy socket to test + * tcp_release_user_frags() -> napi_pp_put_page(). + */ + skb = alloc_skb(0, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + skb->pp_recycle = 1; + skb_add_rx_frag_netmem(skb, 0, niov_nm, 0, 64, PAGE_SIZE); + napi_pp_get_page(niov_nm); + TCP_SKB_CB(skb)->seq = 64; + TCP_SKB_CB(skb)->end_seq = 128; + skb_queue_tail(&sock->sk->sk_receive_queue, skb); + + msg.msg_control = cmsg_buf; + msg.msg_controllen = sizeof(cmsg_buf); + ret = kernel_recvmsg(sock, &msg, &iov, 0, 64, + MSG_SOCK_DEVMEM | MSG_DONTWAIT); + KUNIT_ASSERT_EQ(test, ret, 64); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L); + + sock->sk->sk_state = TCP_CLOSE; + sock_release(sock); + KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); + + netmem_clear_pp_magic(niov_nm); + netmem_set_pp(niov_nm, NULL); + page_pool_destroy(pool); + percpu_ref_exit(&binding.ref); +} +#endif +#endif + static struct kunit_case net_test_cases[] = { KUNIT_CASE_PARAM(gso_test_func, gso_test_gen_params), KUNIT_CASE_PARAM(ip_tunnel_flags_test_run, ip_tunnel_flags_test_gen_params), + KUNIT_CASE(netmem_ref_test_page), +#ifdef CONFIG_PAGE_POOL + KUNIT_CASE(netmem_ref_test_pp_page), +#endif +#if defined(CONFIG_PAGE_POOL) && defined(CONFIG_NET_DEVMEM) + KUNIT_CASE(netmem_ref_test_net_iov), + KUNIT_CASE(netmem_ref_test_release_data), + KUNIT_CASE(netmem_ref_test_skb_segment), + KUNIT_CASE(netmem_ref_test_try_coalesce), +#ifdef CONFIG_INET + KUNIT_CASE(netmem_ref_test_tcp_devmem_recv), +#endif +#endif { }, }; @@ -471,4 +1692,5 @@ static struct kunit_suite net_test_suite = { kunit_test_suite(net_test_suite); MODULE_DESCRIPTION("KUnit tests for networking core"); +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); MODULE_LICENSE("GPL"); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 086de2d50d8e..b79d8b702a0b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include @@ -4450,6 +4451,7 @@ onlymerged: return shiftlen; } +EXPORT_SYMBOL_IF_KUNIT(skb_shift); /** * skb_prepare_seq_read - Prepare a sequential read of skb data From 42a91cbfc7a3ab99d05cb2ed0de5a24b9652cfed Mon Sep 17 00:00:00 2001 From: Yongzhao Chen Date: Tue, 13 Oct 2026 21:03:39 +0200 Subject: [PATCH 1948/2126] net: phy: qca83xx: read resolved QCA8337 link status After a QCA8337 SmartSpeed downshift, genphy_read_status() can report 1000 Mbit/s from the advertised modes when the PHY is running at 100 Mbit/s. On a Redmi AX5400 running downstream OpenWrt Linux 6.18.52, this caused qca8k to program the user-port MAC for 1000 Mbit/s and traffic failed. An earlier prototype that read the resolved speed from the PHY restored traffic. Wrap genphy_read_status() and use at803x_read_specific_status() to replace its speed and duplex result when an autonegotiated link comes up. Resolve pause for the resulting duplex. Until the PHY reports a resolved speed and duplex, report the link as down so that the next poll reads them again, as marvell_read_status_page_an() does. In that case also clear the duplex, master/slave state and link partner modes that genphy_read_status() read for an up link. QCA8337's register layout matches the helper (data sheet 80-Y0619-3 Rev. D, pages 327-328). Keep the generic master/slave read order and the early return for a steady autonegotiated link. This avoids additional reads of the clear-on-read idle error count in MII_STAT1000. Forced mode continues to use BMCR. Report the MDI-X state read at link-up and invalidate it when the link goes down or autonegotiation is disabled. Clear mdix_ctrl because this driver does not implement MDI-X configuration. The QCA8327 entries keep genphy_read_status(). The AR8327 data sheet (MKG-15791 Rev. 1.0) lists the QCA8327-A PHY ID and documents the same PHY-specific status layout, with SmartSpeed enabled after a hardware reset, so those PHYs may have the same problem. That is untested on QCA8327 hardware, so limit this change to QCA8337. Fixes: b3591c2a3661 ("net: dsa: qca8k: Switch to PHYLINK instead of PHYLIB") Suggested-by: Andrew Lunn Signed-off-by: Yongzhao Chen Assisted-by: LLM Link: https://patch.msgid.link/20261013190339.51909-1-yongzhao.derek@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/phy/qcom/qca83xx.c | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/net/phy/qcom/qca83xx.c b/drivers/net/phy/qcom/qca83xx.c index bc70ed8efd86..2c4d085bacdb 100644 --- a/drivers/net/phy/qcom/qca83xx.c +++ b/drivers/net/phy/qcom/qca83xx.c @@ -92,6 +92,63 @@ static int qca83xx_probe(struct phy_device *phydev) return 0; } +static int qca8337_read_status(struct phy_device *phydev) +{ + struct at803x_ss_mask ss_mask = { + .speed_mask = AT803X_SS_SPEED_MASK, + .speed_shift = __bf_shf(AT803X_SS_SPEED_MASK), + }; + int ret, old_link = phydev->link; + + ret = genphy_read_status(phydev); + if (ret) + return ret; + + /* Keep the state resolved at link-up while the link stays up */ + if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) + goto out; + + phydev->mdix = ETH_TP_MDI_INVALID; + + /* genphy_read_status() derives speed and duplex from the + * advertisements, which is wrong after a SmartSpeed downshift. + * Use what the PHY resolved instead. + */ + if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete && + phydev->link) { + phydev->speed = SPEED_UNKNOWN; + phydev->duplex = DUPLEX_UNKNOWN; + phydev->pause = false; + phydev->asym_pause = false; + + ret = at803x_read_specific_status(phydev, ss_mask); + if (ret) + return ret; + + /* Report the link down until speed and duplex are resolved, + * so that the next poll reads them again. Also clear what + * genphy_read_status() read for an up link, as the + * PHY_HALTED path of the state machine does. + */ + if (phydev->speed == SPEED_UNKNOWN || + phydev->duplex == DUPLEX_UNKNOWN) { + phydev->link = 0; + phydev->duplex = DUPLEX_UNKNOWN; + phydev->mdix = ETH_TP_MDI_INVALID; + phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN; + linkmode_zero(phydev->lp_advertising); + } else { + phy_resolve_aneg_pause(phydev); + } + } + +out: + /* MDI-X configuration is not implemented */ + phydev->mdix_ctrl = ETH_TP_MDI_INVALID; + + return 0; +} + static int qca83xx_config_init(struct phy_device *phydev) { u8 switch_revision; @@ -220,6 +277,7 @@ static struct phy_driver qca83xx_driver[] = { .flags = PHY_IS_INTERNAL, .config_init = qca83xx_config_init, .soft_reset = genphy_soft_reset, + .read_status = qca8337_read_status, .get_sset_count = qca83xx_get_sset_count, .get_strings = qca83xx_get_strings, .get_stats = qca83xx_get_stats, From fece8420e76fe53ee84f0439f18d026b4c7641da Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Wed, 14 Oct 2026 12:33:48 -0600 Subject: [PATCH 1949/2126] xsk: freeze deferred pool teardown without blocking unregister MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deferred pool destruction calls ndo_bpf() under RTNL. system_wq is not frozen during system sleep, so that callback can run after a device has suspended and gated its clocks. Use system_freezable_wq so running destruction finishes before device suspend and new work waits until process thaw. Keep assigned pools visible to NETDEV_UNREGISTER independently of the socket list. A released socket has already left that list, but its final pool put can queue destruction after workqueues freeze. A resume-time unregister would then wait for a device reference whose release cannot run until the resume completes. Track assigned pools per netdev with netdev operations locking and detach remaining pools after the notifier socket walk, including copy-mode pools. This also covers leased queues without scanning pools from unrelated devices or network namespaces. Remove the entry on assignment failure and normal teardown. The deferred worker still owns the pool and later observes the cleared device pointer, avoiding a second driver detach or put. The lifetime problem was identified by code inspection of the deferred release and system-sleep paths. Fixes: 1c1efc2af158 ("xsk: Create and free buffer pool independently from umem") Signed-off-by: James Hilliard Reviewed-by: Björn Töpel Reviewed-by: Jason Xing Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20261014-xsk-suspend-teardown-v4-1-27795582e4a3@gmail.com Signed-off-by: Paolo Abeni --- include/linux/netdevice.h | 5 ++++ include/net/xsk_buff_pool.h | 3 +++ net/xdp/xsk.c | 5 ++++ net/xdp/xsk_buff_pool.c | 46 ++++++++++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3cff2174dc03..ac257221c7c5 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2545,6 +2545,11 @@ struct net_device { /* protected by rtnl_lock */ struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE]; +#ifdef CONFIG_XDP_SOCKETS + /** @xsk_pools: assigned AF_XDP pools, ops protected */ + struct hlist_head xsk_pools; +#endif + u8 dev_addr_shadow[MAX_ADDR_LEN]; netdevice_tracker linkwatch_dev_tracker; netdevice_tracker watchdog_dev_tracker; diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h index a7df573784fd..02e89350faf9 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -48,6 +48,8 @@ struct xsk_buff_pool { struct device *dev; struct net_device *netdev; struct list_head xsk_tx_list; + /* Assigned pools, including deferred releases; ops protected. */ + struct hlist_node dev_node; /* Protects modifications to the xsk_tx_list */ spinlock_t xsk_tx_list_lock; refcount_t users; @@ -119,6 +121,7 @@ bool xp_put_pool(struct xsk_buff_pool *pool); void xp_clear_dev(struct xsk_buff_pool *pool); void xp_add_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs); void xp_del_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs); +void xp_clear_dev_all(struct net_device *dev); /* AF_XDP, and XDP core. */ void xp_free(struct xdp_buff_xsk *xskb); diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 33475b180ea6..781ba46eb152 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -2145,6 +2145,11 @@ static int xsk_notifier(struct notifier_block *this, mutex_unlock(&xs->mutex); } mutex_unlock(&net->xdp.lock); + /* + * A released socket is no longer on xdp.list. Its pool can still + * hold a device reference on the frozen release workqueue. + */ + xp_clear_dev_all(dev); break; } return NOTIFY_DONE; diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 9d2d94f1fb75..0ebd4d46f7ab 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -172,7 +172,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, u32 frame_size; int err = 0; - ASSERT_RTNL(); + netdev_assert_locked_ops_compat(netdev); force_zc = flags & XDP_ZEROCOPY; force_copy = flags & XDP_COPY; @@ -204,6 +204,11 @@ int xp_assign_dev(struct xsk_buff_pool *pool, pool->cached_need_wakeup = XDP_WAKEUP_TX; dev_hold(netdev); + /* + * Socket removal precedes the final pool put. Keep the pool visible to + * NETDEV_UNREGISTER even while release work is waiting for process thaw. + */ + hlist_add_head(&pool->dev_node, &netdev->xsk_pools); if (force_copy) /* For copy-mode, we are done. */ @@ -244,7 +249,6 @@ int xp_assign_dev(struct xsk_buff_pool *pool, bpf.xsk.pool = pool; bpf.xsk.queue_id = queue_id; - netdev_assert_locked_ops_compat(netdev); err = netdev->netdev_ops->ndo_bpf(netdev, &bpf); if (err) goto err_unreg_pool; @@ -265,6 +269,8 @@ err_unreg_pool: err = 0; /* fallback to copy mode */ if (err) { xsk_clear_pool_at_qid(netdev, queue_id); + hlist_del(&pool->dev_node); + pool->netdev = NULL; dev_put(netdev); } return err; @@ -287,19 +293,39 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs, return xp_assign_dev(pool, dev, queue_id, flags); } +static void __xp_clear_dev(struct xsk_buff_pool *pool) +{ + struct net_device *netdev = pool->netdev; + + netdev_assert_locked_ops_compat(netdev); + xp_disable_drv_zc(pool); + xsk_clear_pool_at_qid(netdev, pool->queue_id); + hlist_del(&pool->dev_node); + pool->netdev = NULL; + dev_put(netdev); +} + void xp_clear_dev(struct xsk_buff_pool *pool) { struct net_device *netdev = pool->netdev; - if (!pool->netdev) + if (!netdev) return; netdev_lock_ops(netdev); - xp_disable_drv_zc(pool); - xsk_clear_pool_at_qid(pool->netdev, pool->queue_id); - pool->netdev = NULL; + __xp_clear_dev(pool); netdev_unlock_ops(netdev); - dev_put(netdev); +} + +void xp_clear_dev_all(struct net_device *dev) +{ + struct xsk_buff_pool *pool; + struct hlist_node *next; + + netdev_lock_ops(dev); + hlist_for_each_entry_safe(pool, next, &dev->xsk_pools, dev_node) + __xp_clear_dev(pool); + netdev_unlock_ops(dev); } static void xp_release_deferred(struct work_struct *work) @@ -337,7 +363,11 @@ bool xp_put_pool(struct xsk_buff_pool *pool) if (refcount_dec_and_test(&pool->users)) { INIT_WORK(&pool->work, xp_release_deferred); - schedule_work(&pool->work); + /* + * Teardown calls ndo_bpf(), which may need powered hardware. + * RTNL alone does not exclude the device's system PM callbacks. + */ + queue_work(system_freezable_wq, &pool->work); return true; } From d730ca15cf3e4806e38fa8fc6f2af8d7405ef2a4 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Mon, 12 Oct 2026 12:05:53 +0200 Subject: [PATCH 1950/2126] net/mlx5: HWS, fix reformat pool creation race mlx5_fs_get_pr_encap_pool() inserts a new pool when the lookup misses. Two callers allocating the first reformat of a size at once both create one and the second fails with -EBUSY. TC serializes these allocations under encap_tbl_lock while RDMA flow actions on the FDB don't. Sashiko AI review of an earlier series spotted this issue. Tested for regressions on ConnectX-7 with firmware 28.48.1000. Fixes: aecd9d1020e3 ("net/mlx5: fs, add HWS packet reformat API function") Reviewed-by: Moshe Shemesh Signed-off-by: Alexandre Cassen Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261012100555.1317878-2-acassen@corp.free.fr Acked-by: Tariq Toukan Signed-off-by: Paolo Abeni --- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c index 54761754e657..fcef2b64f62c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c @@ -1229,7 +1229,7 @@ static struct mlx5_fs_pool * mlx5_fs_get_pr_encap_pool(struct mlx5_core_dev *dev, struct xarray *pr_pools, enum mlx5hws_action_type reformat_type, size_t size) { - struct mlx5_fs_pool *pr_pool; + struct mlx5_fs_pool *pr_pool, *old; unsigned long index = size; int err; @@ -1243,13 +1243,14 @@ mlx5_fs_get_pr_encap_pool(struct mlx5_core_dev *dev, struct xarray *pr_pools, err = mlx5_fs_hws_pr_pool_init(pr_pool, dev, size, reformat_type); if (err) goto free_pr_pool; - err = xa_insert(pr_pools, index, pr_pool, GFP_KERNEL); - if (err) - goto cleanup_pr_pool; - return pr_pool; + old = xa_cmpxchg(pr_pools, index, NULL, pr_pool, GFP_KERNEL); + if (!old) + return pr_pool; -cleanup_pr_pool: mlx5_fs_hws_pr_pool_cleanup(pr_pool); + kfree(pr_pool); + return xa_is_err(old) ? ERR_PTR(xa_err(old)) : old; + free_pr_pool: kfree(pr_pool); return ERR_PTR(err); From e4ab8ab27ab1c9f0cd1589bee471d93319e20c95 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Mon, 12 Oct 2026 12:05:54 +0200 Subject: [PATCH 1951/2126] net/mlx5: HWS, fix modify header pool creation race mlx5_cmd_hws_modify_header_alloc() creates a pool at the index after the last one if no pool matches the pattern. TC and CT allocate modify headers concurrently, meaning two callers can take the same index and the second call fails with -EBUSY. Its error path also destroys the pool it just created although another caller may already use it. Keep such a pool since cleanup releases it. Pools now live until cleanup so the lookup needs no lock. A miss looks again under a mutex before creating the pool. Tested for regressions on ConnectX-7 with firmware 28.48.1000. Fixes: b36315ca69cb ("net/mlx5: fs, add HWS modify header API function") Signed-off-by: Alexandre Cassen Reviewed-by: Moshe Shemesh Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261012100555.1317878-3-acassen@corp.free.fr Acked-by: Tariq Toukan Signed-off-by: Paolo Abeni --- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 53 +++++++++++-------- .../mellanox/mlx5/core/steering/hws/fs_hws.h | 1 + 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c index fcef2b64f62c..d6958ba5dcc2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c @@ -63,6 +63,7 @@ static int mlx5_fs_init_hws_actions_pool(struct mlx5_core_dev *dev, xa_init(&hws_pool->el2tol3tnl_pools); xa_init(&hws_pool->el2tol2tnl_pools); xa_init(&hws_pool->mh_pools); + mutex_init(&hws_pool->mh_pools_lock); xa_init(&hws_pool->table_dests); xa_init(&hws_pool->vport_dests); xa_init(&hws_pool->vport_vhca_dests); @@ -111,6 +112,7 @@ static void mlx5_fs_cleanup_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx) xa_for_each(&hws_pool->mh_pools, i, pool) mlx5_fs_destroy_mh_pool(pool, &hws_pool->mh_pools, i); xa_destroy(&hws_pool->mh_pools); + mutex_destroy(&hws_pool->mh_pools_lock); xa_for_each(&hws_pool->el2tol2tnl_pools, i, pool) mlx5_fs_destroy_pr_pool(pool, &hws_pool->el2tol2tnl_pools, i); xa_destroy(&hws_pool->el2tol2tnl_pools); @@ -1458,6 +1460,23 @@ mlx5_fs_destroy_mh_pool(struct mlx5_fs_pool *pool, struct xarray *mh_pools, kfree(pool); } +static struct mlx5_fs_pool * +mlx5_fs_find_mh_pool(struct xarray *mh_pools, + struct mlx5hws_action_mh_pattern *pattern, + unsigned long *cnt) +{ + struct mlx5_fs_pool *pool; + unsigned long i; + + *cnt = 0; + xa_for_each(mh_pools, i, pool) { + if (mlx5_fs_hws_mh_pool_match(pool, pattern)) + return pool; + (*cnt)++; + } + return NULL; +} + static int mlx5_cmd_hws_modify_header_alloc(struct mlx5_flow_root_namespace *ns, u8 namespace, u8 num_actions, void *modify_actions, @@ -1468,33 +1487,28 @@ static int mlx5_cmd_hws_modify_header_alloc(struct mlx5_flow_root_namespace *ns, struct mlx5_fs_hws_mh *mh_data = NULL; struct mlx5hws_action *hws_action; struct mlx5_fs_pool *pool; - unsigned long i, cnt = 0; - bool known_pattern; + unsigned long cnt; int err; pattern.sz = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) * num_actions; pattern.data = modify_actions; - known_pattern = false; - xa_for_each(&hws_pool->mh_pools, i, pool) { - if (mlx5_fs_hws_mh_pool_match(pool, &pattern)) { - known_pattern = true; - break; - } - cnt++; - } - - if (!known_pattern) { - pool = mlx5_fs_create_mh_pool(ns->dev, &pattern, - &hws_pool->mh_pools, cnt); + pool = mlx5_fs_find_mh_pool(&hws_pool->mh_pools, &pattern, &cnt); + if (!pool) { + mutex_lock(&hws_pool->mh_pools_lock); + pool = mlx5_fs_find_mh_pool(&hws_pool->mh_pools, &pattern, + &cnt); + if (!pool) + pool = mlx5_fs_create_mh_pool(ns->dev, &pattern, + &hws_pool->mh_pools, cnt); + mutex_unlock(&hws_pool->mh_pools_lock); if (IS_ERR(pool)) return PTR_ERR(pool); } + mh_data = mlx5_fs_hws_mh_pool_acquire_mh(pool); - if (IS_ERR(mh_data)) { - err = PTR_ERR(mh_data); - goto destroy_pool; - } + if (IS_ERR(mh_data)) + return PTR_ERR(mh_data); hws_action = mh_data->bulk->hws_action; mh_data->data = kmemdup(pattern.data, pattern.sz, GFP_KERNEL); if (!mh_data->data) { @@ -1510,9 +1524,6 @@ static int mlx5_cmd_hws_modify_header_alloc(struct mlx5_flow_root_namespace *ns, release_mh: mlx5_fs_hws_mh_pool_release_mh(pool, mh_data); -destroy_pool: - if (!known_pattern) - mlx5_fs_destroy_mh_pool(pool, &hws_pool->mh_pools, cnt); return err; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h index 20cdacd8f12e..cf068fb5bdbf 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h @@ -19,6 +19,7 @@ struct mlx5_fs_hws_actions_pool { struct xarray el2tol3tnl_pools; struct xarray el2tol2tnl_pools; struct xarray mh_pools; + struct mutex mh_pools_lock; /* serializes pool creation */ struct xarray table_dests; struct xarray vport_vhca_dests; struct xarray vport_dests; From 8e793b899b903e78cd0c40af5b86a086ea1d7ee1 Mon Sep 17 00:00:00 2001 From: Ivan Vecera Date: Wed, 14 Oct 2026 14:20:45 +0200 Subject: [PATCH 1952/2126] selftests: tc-testing: preload all qdisc modules enabled in config tdc.sh preloads only some of the qdisc modules that the tc-testing config enables. Add the missing ones: ingress, mqprio, multiq, netem, pie, plug, prio, qfq, red, sfb, sfq, skbprio, taprio and tbf. Signed-off-by: Ivan Vecera Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20261014122045.2375722-1-ivecera@redhat.com Signed-off-by: Paolo Abeni --- tools/testing/selftests/tc-testing/tdc.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/tc-testing/tdc.sh b/tools/testing/selftests/tc-testing/tdc.sh index dae19687912d..25cdc256287d 100755 --- a/tools/testing/selftests/tc-testing/tdc.sh +++ b/tools/testing/selftests/tc-testing/tdc.sh @@ -65,6 +65,20 @@ try_modprobe sch_gred try_modprobe sch_hfsc try_modprobe sch_hhf try_modprobe sch_htb +try_modprobe sch_ingress +try_modprobe sch_mqprio +try_modprobe sch_multiq +try_modprobe sch_netem +try_modprobe sch_pie +try_modprobe sch_plug +try_modprobe sch_prio +try_modprobe sch_qfq +try_modprobe sch_red +try_modprobe sch_sfb +try_modprobe sch_sfq +try_modprobe sch_skbprio +try_modprobe sch_taprio +try_modprobe sch_tbf try_modprobe sch_teql try_modprobe sch_dualpi2 ./tdc.py -J"$(nproc)" From 7d23f0f650d943f3f6bdd4635b43d66dcb7fb0a2 Mon Sep 17 00:00:00 2001 From: David Yang Date: Thu, 15 Oct 2026 08:44:19 +0800 Subject: [PATCH 1953/2126] net: dsa: motorcomm: Remove the redundant MIB clear The MIB clear in yt921x_chip_setup() is redundant. yt921x_dsa_setup() issues a hardware reset first, and the reset itself zeroes all the MIB counters. It does not follow the correct procedure either: CLEAN only takes effect while ALL_PORT is low, so a single-step CLEAN | ALL_PORT write does nothing once ALL_PORT is latched - and this write is what latches it for any CLEAN requested later. Signed-off-by: David Yang Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261015004422.1554104-1-mmyangfl@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/dsa/motorcomm/chip.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index e2b5c89f7e77..d4fc20c52a58 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -2404,12 +2404,6 @@ static int yt921x_chip_setup(struct yt921x_priv *priv) return res; #endif - /* Clear MIB */ - ctrl = YT921X_MIB_CTRL_CLEAN | YT921X_MIB_CTRL_ALL_PORT; - res = yt921x_reg_write(priv, YT921X_MIB_CTRL, ctrl); - if (res) - return res; - /* Miscellaneous */ res = yt921x_reg_set_bits(priv, YT921X_SENSOR, YT921X_SENSOR_TEMP); if (res) From 643f9c0bd87767f2076dca3acd850f3a95f4ad34 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Wed, 14 Oct 2026 11:05:25 +0200 Subject: [PATCH 1954/2126] net: stmmac: fix mqprio and cbs combination The channel-mode mqprio offload and the CBS offload can currently not be enabled at the same time. tc_mqprio_validate_chan_mode() refuses the mqprio offload as soon as any TX queue is configured in AVB mode, and tc_setup_cbs() refuses to enable CBS while the strict-priority scheduler is active. As a result the combination is rejected whichever order the two are configured in. The strict-priority scheduler selected by the channel-mode mqprio offload and the per-queue CBS shaper are stored in independent MTL fields on dwmac4/EQoS cores (MTL_OPERATION_MODE.SCHALG vs MTL_ETS_CTRL.AVALG), so the two checks are over-restrictive there. On XGMAC/XLGMAC they are not independent: the TX scheduling algorithm and the CBS shaper share the per-TC MTL_TCx_ETS_CONTROL.TSA field, so programming the scheduler rewrites TSA on every queue and would disable CBS on any queue configured in AVB mode. Drop the checks and re-apply the AVB/CBS configuration with stmmac_configure_cbs() after the TX algorithm is reprogrammed in tc_mqprio_config_queue_prio() and stmmac_reset_tc_mqprio(), so the combination is offloaded correctly on all cores. The stmmac_reinit_queues() check is dropped as well, since a subsequent ndo_open restores the AVB queues. The following configuration, which was previously refused, now works: $ tc qdisc replace dev eth0 handle 100 parent root mqprio \ num_tc 4 \ map 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 \ queues 1@0 1@1 1@2 1@3 mode channel hw 1 $ tc qdisc replace dev eth0 parent 100:2 handle 102: cbs \ idleslope 800000 sendslope -1700000 hicredit 494 \ locredit -1049 offload 0 $ tc qdisc replace dev eth0 parent 100:3 handle 103: cbs \ idleslope 400000 sendslope -2100000 hicredit 247 \ locredit -1296 offload 1 $ tc qdisc replace dev eth0 parent 100:4 handle 104: cbs \ idleslope 200000 sendslope -2300000 hicredit 124 \ locredit -1419 offload 1 Fixes: 47891d501e34 ("net: stmmac: add tc mqprio hw queue priority offload") Tested-by: Daniel Thompson Reviewed-by: Maxime Chevallier Reviewed-by: Daniel Thompson Signed-off-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261014-stmmac-mqprio-cbs-combo-v2-1-372249daa81a@oss.qualcomm.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 10 +--------- .../net/ethernet/stmicro/stmmac/stmmac_tc.c | 20 ++++--------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 08b68441f9c8..120d01c04d61 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -440,6 +440,7 @@ static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv) return !!priv->xdp_prog; } +void stmmac_configure_cbs(struct stmmac_priv *priv); void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue); void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue); void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index afd8f7a9f051..de2db188b45d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3467,7 +3467,7 @@ static void stmmac_set_tx_queue_weight(struct stmmac_priv *priv) * @priv: driver private structure * Description: It is used for configuring CBS in AVB TX queues */ -static void stmmac_configure_cbs(struct stmmac_priv *priv) +void stmmac_configure_cbs(struct stmmac_priv *priv) { u8 tx_queues_count = priv->plat->tx_queues_to_use; u32 mode_to_use; @@ -7753,14 +7753,6 @@ int stmmac_reinit_queues(struct net_device *dev, u8 rx_cnt, u8 tx_cnt) tx_cnt < priv->xmit_qdisc.num_tx_queues) return -EINVAL; - if (priv->xmit_qdisc.prio_offload) { - for (i = priv->plat->tx_queues_to_use; i < tx_cnt; i++) { - if (priv->plat->tx_queues_cfg[i].mode_to_use == - MTL_QUEUE_AVB) - return -EINVAL; - } - } - if (netif_running(dev)) stmmac_release(dev); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index b09e9a89cee8..e137fb9012d4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -346,9 +346,6 @@ static int tc_setup_cbs(struct stmmac_priv *priv, if (!priv->dma_cap.av) return -EOPNOTSUPP; - if (qopt->enable && priv->xmit_qdisc.prio_offload) - return -EOPNOTSUPP; - port_transmit_rate_kbps = qopt->idleslope - qopt->sendslope; if (qopt->enable) { @@ -1288,6 +1285,8 @@ static int stmmac_reset_tc_mqprio(struct net_device *ndev, stmmac_prog_mtl_tx_algorithms(priv, priv->hw, priv->plat->tx_sched_algorithm); + /* Re-configure AVB queues if necessary */ + stmmac_configure_cbs(priv); priv->xmit_qdisc.algo = priv->plat->tx_sched_algorithm; priv->xmit_qdisc.prio_offload = false; } @@ -1334,6 +1333,8 @@ static void tc_mqprio_config_queue_prio(struct stmmac_priv *priv, } stmmac_prog_mtl_tx_algorithms(priv, priv->hw, MTL_TX_ALGORITHM_SP); + /* Re-configure AVB queues if necessary */ + stmmac_configure_cbs(priv); priv->xmit_qdisc.algo = MTL_TX_ALGORITHM_SP; priv->xmit_qdisc.prio_offload = true; } @@ -1341,7 +1342,6 @@ static void tc_mqprio_config_queue_prio(struct stmmac_priv *priv, static int tc_mqprio_validate_chan_mode(struct stmmac_priv *priv, struct tc_mqprio_qopt_offload *mqprio) { - struct plat_stmmacenet_data *pdata = priv->plat; struct tc_mqprio_qopt *qopt = &mqprio->qopt; int i; @@ -1351,18 +1351,6 @@ static int tc_mqprio_validate_chan_mode(struct stmmac_priv *priv, return -EOPNOTSUPP; } - /* Forcing strict priority conflicts with the CBS algorithm - * of AVB queues, so reject the offload when any queue is - * configured as AVB. - */ - for (i = 0; i < pdata->tx_queues_to_use; i++) { - if (pdata->tx_queues_cfg[i].mode_to_use == MTL_QUEUE_AVB) { - NL_SET_ERR_MSG_MOD(mqprio->extack, - "SP conflicts with AVB queues"); - return -EOPNOTSUPP; - } - } - for (i = 0; i < qopt->num_tc; i++) { /* The offload switches the MTL scheduler to strict * priority, which only supports a 1:1 TC to TX queue From f09123082704b08d56fd044a2166e3e39fa68563 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 13 Oct 2026 17:13:34 -0700 Subject: [PATCH 1955/2126] net: ag71xx: align the IP header behind DSA tags The receive buffer offset includes NET_IP_ALIGN to get the IP header aligned behind a 14 byte Ethernet header. Most ag71xx devices use DSA switches whose tag sits in front of the EtherType, which moves the IP header by another 2 bytes. Every access to the IP and TCP headers then traps and gets emulated by the unaligned access handler, around 6 times per forwarded frame. Take the headroom needed by the DSA tagger into account when choosing the offset. TP-Link Archer C7 v2 (qca8k), median of 3 runs, Mbit/s: before after routed up 743 855 routed down 660 749 local receive 554 572 The unaligned instruction counter no longer moves while forwarding. Assisted-by: LLM Signed-off-by: Rosen Penev Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261014001334.132962-1-rosenp@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/atheros/ag71xx.c | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c index 8a3c689f6825..73b5f8020ece 100644 --- a/drivers/net/ethernet/atheros/ag71xx.c +++ b/drivers/net/ethernet/atheros/ag71xx.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #define AG71XX_OOM_REFILL (1 + HZ / 10) @@ -1396,6 +1397,26 @@ static void ag71xx_hw_disable(struct ag71xx *ag) ag71xx_rings_cleanup(ag); } +static unsigned int ag71xx_rx_offset(struct ag71xx *ag) +{ + unsigned int align = NET_IP_ALIGN; + + if (ag71xx_is(ag, AR7100) || ag71xx_is(ag, AR9130)) + return NET_SKB_PAD; + +#if IS_ENABLED(CONFIG_NET_DSA) + /* A tag inserted in front of the EtherType shifts the IP header, + * compensate for it to avoid unaligned accesses in the stack. + * This is only evaluated in ndo_open, so a DSA tree that binds to + * or unbinds from a running conduit takes effect on the next open. + */ + if (netdev_uses_dsa(ag->ndev)) + align = (align - ag->ndev->dsa_ptr->tag_ops->needed_headroom) & 3; +#endif + + return NET_SKB_PAD + align; +} + static int ag71xx_open(struct net_device *ndev) { struct ag71xx *ag = netdev_priv(ndev); @@ -1410,8 +1431,9 @@ static int ag71xx_open(struct net_device *ndev) } max_frame_len = ag71xx_max_frame_len(ndev->mtu); + ag->rx_buf_offset = ag71xx_rx_offset(ag); ag->rx_buf_size = - SKB_DATA_ALIGN(max_frame_len + NET_SKB_PAD + NET_IP_ALIGN); + SKB_DATA_ALIGN(max_frame_len + ag->rx_buf_offset); /* setup max frame length */ ag71xx_wr(ag, AG71XX_REG_MAC_MFL, max_frame_len); @@ -1874,10 +1896,6 @@ static int ag71xx_probe(struct platform_device *pdev) ndev->min_mtu = 68; ndev->max_mtu = dcfg->max_frame_len - ag71xx_max_frame_len(0); - ag->rx_buf_offset = NET_SKB_PAD; - if (!ag71xx_is(ag, AR7100) && !ag71xx_is(ag, AR9130)) - ag->rx_buf_offset += NET_IP_ALIGN; - if (ag71xx_is(ag, AR7100)) { ag->tx_ring.desc_split = AG71XX_TX_RING_SPLIT; tx_size *= AG71XX_TX_RING_DS_PER_PKT; From daac93975b8ff0a0a036a5e3562236c0b40c3e36 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 13 Oct 2026 14:35:42 -0600 Subject: [PATCH 1956/2126] net: stmmac: avoid duplicate XSK TX completions stmmac_tx_clean() reports completed AF_XDP TX descriptors through xsk_tx_completed(), but leaves their buffer type as STMMAC_TXBUF_T_XSK_TX. The slots retain that type until they are reused for another buffer type. On interface close or XDP teardown, dma_free_tx_skbufs() walks the entire TX ring, not just the dirty_tx..cur_tx range. stmmac_free_tx_buffer() counts the stale XSK_TX slots again, causing xsk_tx_completed() to advance the completion-ring producer for buffers that have already been returned. This publishes completion entries without matching outstanding TX reservations and corrupts completion accounting for a socket which stays bound across the teardown. Reset the XSK buffer type after counting the completion in both stmmac_tx_clean() and stmmac_free_tx_buffer(). XSK TX slots have a NULL skb pointer and no per-slot DMA mapping, so the SKB type represents an empty slot. Pending XSK descriptors keep their type until they are completed or released, and a released slot can no longer be counted again by a later cleanup. Fixes: 132c32ee5bc0 ("net: stmmac: Add TX via XDP zero-copy socket") Signed-off-by: James Hilliard Link: https://patch.msgid.link/20261013-submit-stmmac-xsk-tx-completion-v1-v1-1-f21b9d098e62@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index b837e8e27a35..1527e03711cc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1742,8 +1742,10 @@ static void stmmac_free_tx_buffer(struct stmmac_priv *priv, tx_q->xdpf[i] = NULL; } - if (tx_q->tx_skbuff_dma[i].buf_type == STMMAC_TXBUF_T_XSK_TX) + if (tx_q->tx_skbuff_dma[i].buf_type == STMMAC_TXBUF_T_XSK_TX) { tx_q->xsk_frames_done++; + tx_q->tx_skbuff_dma[i].buf_type = STMMAC_TXBUF_T_SKB; + } if (tx_q->tx_skbuff[i] && tx_q->tx_skbuff_dma[i].buf_type == STMMAC_TXBUF_T_SKB) { @@ -2926,8 +2928,11 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue, tx_q->xdpf[entry] = NULL; } - if (tx_q->tx_skbuff_dma[entry].buf_type == STMMAC_TXBUF_T_XSK_TX) + if (tx_q->tx_skbuff_dma[entry].buf_type == STMMAC_TXBUF_T_XSK_TX) { tx_q->xsk_frames_done++; + /* Teardown must not count this slot again. */ + tx_q->tx_skbuff_dma[entry].buf_type = STMMAC_TXBUF_T_SKB; + } if (tx_q->tx_skbuff_dma[entry].buf_type == STMMAC_TXBUF_T_SKB) { if (likely(skb)) { From 0edb8222b852f430e5b5e0475cc2650d409214a0 Mon Sep 17 00:00:00 2001 From: Carolina Jubran Date: Thu, 15 Oct 2026 10:40:35 +0300 Subject: [PATCH 1957/2126] net/mlx5: DPLL, fix fractional frequency offset scaling The frequency_diff is reported by firmware in parts-per-trillion, which is exactly what the DPLL core now expects from the ffo_get callback. Commit bc443c253fcd ("dpll: expose fractional frequency offset in ppt") switched the callback contract to ppt but assumed frequency_diff was in ppm and scaled it by 1000000 to "convert" it. Since the value was already ppt, this makes both exported attributes wrong. Report frequency_diff as is and let the core divide it down for the legacy ppm attribute. Fixes: f035dca34ede ("net/mlx5: DPLL, Implement fractional frequency offset get pin op") Signed-off-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan Reviewed-by: Daniel Machon Reviewed-by: Ivan Vecera Link: https://patch.msgid.link/20261015074035.1092340-1-tariqt@nvidia.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/mellanox/mlx5/core/dpll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dpll.c b/drivers/net/ethernet/mellanox/mlx5/core/dpll.c index 7c69d9029bfa..54ba7c330d66 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/dpll.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/dpll.c @@ -138,7 +138,7 @@ mlx5_dpll_pin_ffo_get(struct mlx5_dpll_synce_status *synce_status, { if (!synce_status->oper_freq_measure) return -ENODATA; - *ffo = 1000000LL * synce_status->frequency_diff; + *ffo = synce_status->frequency_diff; return 0; } From 0df412012a26389582b120844d098e1e961f10a6 Mon Sep 17 00:00:00 2001 From: Carolina Jubran Date: Thu, 15 Oct 2026 11:02:18 +0300 Subject: [PATCH 1958/2126] net/mlx5e: Fix NULL deref in PTP TX timestamp recovery warn PTP SQs are allocated via mlx5e_ptp_alloc_txqsq(), which never sets sq->channel. The excessive port timestamp delta recovery path incorrectly used sq->channel->netdev for netdev_warn(), causing a NULL pointer dereference. Use sq->netdev instead. Fixes: 391dad2e686f ("net/mlx5e: Recover SQ on excessive PTP TX timestamp delta") Signed-off-by: Carolina Jubran Reviewed-by: Alex Lazar Signed-off-by: Tariq Toukan Reviewed-by: Kalesh AP Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20261015080218.1102172-1-tariqt@nvidia.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c index 723f66a6bd63..2e1c3bb5a959 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c @@ -98,7 +98,7 @@ static void mlx5e_skb_cb_hwtstamp_tx(struct sk_buff *skb, ptpsq->cq_stats->abort_abs_diff_ns += diff; if (diff > (NSEC_PER_SEC >> 1) && !test_and_set_bit(MLX5E_SQ_STATE_RECOVERING, &sq->state)) { - netdev_warn(sq->channel->netdev, + netdev_warn(sq->netdev, "PTP TX timestamp difference between CQE and port exceeds threshold: %lld ns, recovering SQ %u\n", (s64)diff, sq->sqn); queue_work(sq->priv->wq, &ptpsq->report_unhealthy_work); From ec636599b10ac01f29f5ef41b015f9b0bc7f6b1f Mon Sep 17 00:00:00 2001 From: Andrea Parri Date: Thu, 15 Oct 2026 10:17:16 +0200 Subject: [PATCH 1959/2126] rtnetlink: comment the RCU waits in unregister paths rtnl_unregister_all() and rtnl_af_unregister() wait for RCU readers before tearing down what those readers use, but do not say which readers they are waiting for. A missing wait is then easy to overlook: rtnl_link_unregister() lacked its synchronize_rcu() until commit 3b70edea393d ("rtnetlink: wait for RCU readers in rtnl_link_unregister()"). Add a comment to both waits, naming the readers each one waits for. Suggested-by: Eric Dumazet Link: https://lore.kernel.org/CAL4WiioFMQN4troVjQjCmE6Z9kwwb95SnoEupjD=PPSK6Q5f6w@mail.gmail.com Assisted-by: LLM Signed-off-by: Andrea Parri Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261015081723.404990-1-parri.andrea@gmail.com Signed-off-by: Paolo Abeni --- net/core/rtnetlink.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 15bffafbf0a9..d73dbc2c8ba0 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -526,6 +526,9 @@ void rtnl_unregister_all(int protocol) } rtnl_unlock(); + /* Wait for rtnl_get_link() calls that rtnetlink_rcv_msg() makes + * under RCU, before try_module_get(). + */ synchronize_net(); kfree(tab); @@ -843,6 +846,9 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops) list_del_rcu(&ops->list); spin_unlock(&rtnl_af_ops_lock); + /* Wait for rtnl_af_ops walkers that invoke callbacks without + * ops->srcu, and for rtnl_af_lookup() readers not yet holding it. + */ synchronize_rcu(); synchronize_srcu(&ops->srcu); cleanup_srcu_struct(&ops->srcu); From 5af4c3f617912e58930223ce9dc671a0d56a3629 Mon Sep 17 00:00:00 2001 From: Kyle Hendry Date: Wed, 14 Oct 2026 08:32:37 -0700 Subject: [PATCH 1960/2126] net: pcs: rzn1-miic: Update port numbering for RZ/T2H The port numbers on the RZ/T2H are documented as 0 to 3. Update the info structure and change the member name to miic_port_last to be more accurate. This value was being used as the number of miic registers when setting default values. Add logic to get the total port count and loop over that. Reviewed-by: Lad Prabhakar Reviewed-by: Simon Horman Signed-off-by: Kyle Hendry Link: https://patch.msgid.link/20261014-miic-validate-dtb-v3-v4-1-b7da71b3a106@reliablecontrols.com Signed-off-by: Paolo Abeni --- drivers/net/pcs/pcs-rzn1-miic.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index 3aa513467060..31716241b58f 100644 --- a/drivers/net/pcs/pcs-rzn1-miic.c +++ b/drivers/net/pcs/pcs-rzn1-miic.c @@ -222,7 +222,7 @@ enum miic_type { * @index_to_string: String representations of the index values * @index_to_string_count: Number of entries in the index_to_string array * @miic_port_start: MIIC port start number - * @miic_port_max: Maximum MIIC supported + * @miic_port_last: MIIC port last number * @sw_mode_mask: Switch mode mask * @reset_ids: Reset names array * @reset_count: Number of entries in the reset_ids array @@ -240,7 +240,7 @@ struct miic_of_data { const char * const *index_to_string; u8 index_to_string_count; u8 miic_port_start; - u8 miic_port_max; + u8 miic_port_last; u8 sw_mode_mask; const char * const *reset_ids; u8 reset_count; @@ -485,7 +485,7 @@ struct phylink_pcs *miic_create(struct device *dev, struct device_node *np) miic = platform_get_drvdata(pdev); of_data = miic->of_data; - if (port > of_data->miic_port_max || port < of_data->miic_port_start) { + if (port > of_data->miic_port_last || port < of_data->miic_port_start) { put_device(&pdev->dev); return ERR_PTR(-EINVAL); } @@ -523,6 +523,7 @@ EXPORT_SYMBOL(miic_destroy); static int miic_init_hw(struct miic *miic, u32 cfg_mode) { u8 sw_mode_mask = miic->of_data->sw_mode_mask; + int num_ports; int port; /* Unlock write access to accessory registers (cf datasheet). If this @@ -538,7 +539,10 @@ static int miic_init_hw(struct miic *miic, u32 cfg_mode) miic_reg_writel(miic, MIIC_MODCTRL, ((cfg_mode << __ffs(sw_mode_mask)) & sw_mode_mask)); - for (port = 0; port < miic->of_data->miic_port_max; port++) { + num_ports = miic->of_data->miic_port_last - + miic->of_data->miic_port_start + 1; + + for (port = 0; port < num_ports; port++) { miic_converter_enable(miic, port, 0); /* Disable speed/duplex control from these registers, datasheet * says switch registers should be used to setup switch port @@ -825,7 +829,7 @@ static struct miic_of_data rzn1_miic_of_data = { .index_to_string = index_to_string, .index_to_string_count = ARRAY_SIZE(index_to_string), .miic_port_start = 1, - .miic_port_max = 5, + .miic_port_last = 5, .sw_mode_mask = GENMASK(4, 0), .init_unlock_lock_regs = true, .miic_write = miic_reg_writel_unlocked, @@ -841,7 +845,7 @@ static struct miic_of_data rzt2h_miic_of_data = { .index_to_string = rzt2h_index_to_string, .index_to_string_count = ARRAY_SIZE(rzt2h_index_to_string), .miic_port_start = 0, - .miic_port_max = 4, + .miic_port_last = 3, .sw_mode_mask = GENMASK(2, 0), .reset_ids = rzt2h_reset_ids, .reset_count = ARRAY_SIZE(rzt2h_reset_ids), From 585df8d1eed980e944b8caad8c3bce904309d307 Mon Sep 17 00:00:00 2001 From: Kyle Hendry Date: Wed, 14 Oct 2026 08:32:38 -0700 Subject: [PATCH 1961/2126] net: pcs: rzn1-miic: Validate dtb configuration values Bad configuration values from the dtb could result in out of bounds array access. Verify parsed values are within range for the SoC and fail the probe if invalid. Reviewed-by: Simon Horman Signed-off-by: Kyle Hendry Reviewed-by: Lad Prabhakar Link: https://patch.msgid.link/20261014-miic-validate-dtb-v3-v4-2-b7da71b3a106@reliablecontrols.com Signed-off-by: Paolo Abeni --- drivers/net/pcs/pcs-rzn1-miic.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index 31716241b58f..f8bafce26bf1 100644 --- a/drivers/net/pcs/pcs-rzn1-miic.c +++ b/drivers/net/pcs/pcs-rzn1-miic.c @@ -693,16 +693,39 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg) memset(dt_val, MIIC_MODCTRL_CONF_NONE, sizeof(*dt_val) * miic->of_data->conf_conv_count); - if (of_property_read_u32(np, "renesas,miic-switch-portin", &conf) == 0) + if (of_property_read_u32(np, "renesas,miic-switch-portin", &conf) == 0) { + if (conf >= miic->of_data->conf_to_string_count) { + dev_err(miic->dev, "Port input configuration out of range: %d\n", + conf); + ret = -EINVAL; + goto err; + } dt_val[0] = conf; + } for_each_available_child_of_node(np, conv) { if (of_property_read_u32(conv, "reg", &port)) continue; + if (port < miic->of_data->miic_port_start || + port > miic->of_data->miic_port_last) { + dev_err(miic->dev, "Port number out of range: %d\n", port); + of_node_put(conv); + ret = -EINVAL; + goto err; + } + if (of_property_read_u32(conv, "renesas,miic-input", &conf)) continue; + if (conf >= miic->of_data->conf_to_string_count) { + dev_err(miic->dev, "Port %d configuration out of range: %d\n", + port, conf); + of_node_put(conv); + ret = -EINVAL; + goto err; + } + /* Adjust for 0 based index */ dt_val[port + !miic->of_data->miic_port_start] = conf; @@ -712,6 +735,7 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg) } ret = miic_match_dt_conf(miic, dt_val, mode_cfg); +err: kfree(dt_val); return ret; From 9f902fbc955e615a4b980fe030142c61975023b6 Mon Sep 17 00:00:00 2001 From: Oskari Lemmela Date: Tue, 13 Oct 2026 21:56:34 +0300 Subject: [PATCH 1962/2126] dt-bindings: net: realtek: add RTL8224 package binding RTL8224 packages contain four PHYs at consecutive MDIO addresses and share configuration registers. Unaligned packages need an explicit base address to select the correct package registers and per-port MDI fields. Introduce realtek,rtl8224-package so the package example selects a dedicated schema while child PHYs retain their Clause 45 discovery compatible. Validate package and child properties, document that unaligned layouts require a package node, and preserve support for existing aligned descriptions without package nodes. Signed-off-by: Oskari Lemmela Reviewed-by: Rob Herring (Arm) Link: https://patch.msgid.link/20261013185635.1412452-2-oskari@lemmela.net Signed-off-by: Paolo Abeni --- .../bindings/net/realtek,rtl8224-package.yaml | 332 ++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/realtek,rtl8224-package.yaml diff --git a/Documentation/devicetree/bindings/net/realtek,rtl8224-package.yaml b/Documentation/devicetree/bindings/net/realtek,rtl8224-package.yaml new file mode 100644 index 000000000000..8e6500958ed1 --- /dev/null +++ b/Documentation/devicetree/bindings/net/realtek,rtl8224-package.yaml @@ -0,0 +1,332 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/realtek,rtl8224-package.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek RTL8224 Ethernet PHY package + +maintainers: + - Andrew Lunn + - Florian Fainelli + - Heiner Kallweit + +description: + The RTL8224 is a four-port 2.5Gbps Ethernet PHY. Its PHYs occupy four + consecutive MDIO addresses and share package-wide configuration registers. + + A package node is required when the first PHY's MDIO address is not a + multiple of four. Existing aligned layouts without a package node remain + supported. + + The package reg must identify the first physical PHY's MDIO address, + even if that PHY has no child node. Each child PHY reg is its absolute + MDIO address, not an offset from the package base. Unused PHY ports may + be omitted. The base address must not exceed 28, so that all four PHY + addresses fit within the MDIO address space. + + The enet-phy-pair-order and enet-phy-pair-polarity properties belong + to the individual PHY nodes and describe each port's MDI wiring. + +$ref: ethernet-phy-package.yaml# + +properties: + compatible: + const: realtek,rtl8224-package + + reg: + maximum: 28 + +patternProperties: + "^ethernet-phy@[a-f0-9]+$": + $ref: ethernet-phy.yaml# + + properties: + compatible: + const: ethernet-phy-ieee802.3-c45 + + leds: false + + required: + - compatible + + unevaluatedProperties: false + +required: + - compatible + +# Enumerate the ranges because child addresses depend on the package base. +allOf: + - if: + properties: + reg: { const: 0 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 0, maximum: 3 } + - if: + properties: + reg: { const: 1 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 1, maximum: 4 } + - if: + properties: + reg: { const: 2 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 2, maximum: 5 } + - if: + properties: + reg: { const: 3 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 3, maximum: 6 } + - if: + properties: + reg: { const: 4 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 4, maximum: 7 } + - if: + properties: + reg: { const: 5 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 5, maximum: 8 } + - if: + properties: + reg: { const: 6 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 6, maximum: 9 } + - if: + properties: + reg: { const: 7 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 7, maximum: 10 } + - if: + properties: + reg: { const: 8 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 8, maximum: 11 } + - if: + properties: + reg: { const: 9 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 9, maximum: 12 } + - if: + properties: + reg: { const: 10 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 10, maximum: 13 } + - if: + properties: + reg: { const: 11 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 11, maximum: 14 } + - if: + properties: + reg: { const: 12 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 12, maximum: 15 } + - if: + properties: + reg: { const: 13 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 13, maximum: 16 } + - if: + properties: + reg: { const: 14 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 14, maximum: 17 } + - if: + properties: + reg: { const: 15 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 15, maximum: 18 } + - if: + properties: + reg: { const: 16 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 16, maximum: 19 } + - if: + properties: + reg: { const: 17 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 17, maximum: 20 } + - if: + properties: + reg: { const: 18 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 18, maximum: 21 } + - if: + properties: + reg: { const: 19 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 19, maximum: 22 } + - if: + properties: + reg: { const: 20 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 20, maximum: 23 } + - if: + properties: + reg: { const: 21 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 21, maximum: 24 } + - if: + properties: + reg: { const: 22 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 22, maximum: 25 } + - if: + properties: + reg: { const: 23 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 23, maximum: 26 } + - if: + properties: + reg: { const: 24 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 24, maximum: 27 } + - if: + properties: + reg: { const: 25 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 25, maximum: 28 } + - if: + properties: + reg: { const: 26 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 26, maximum: 29 } + - if: + properties: + reg: { const: 27 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 27, maximum: 30 } + - if: + properties: + reg: { const: 28 } + then: + patternProperties: + "^ethernet-phy@[a-f0-9]+$": + properties: + reg: { minimum: 28, maximum: 31 } + +unevaluatedProperties: false + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy-package@1 { + compatible = "realtek,rtl8224-package"; + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@1 { + compatible = "ethernet-phy-ieee802.3-c45"; + reg = <1>; + enet-phy-pair-order = <0>; + }; + + ethernet-phy@2 { + compatible = "ethernet-phy-ieee802.3-c45"; + reg = <2>; + enet-phy-pair-order = <0>; + }; + + ethernet-phy@3 { + compatible = "ethernet-phy-ieee802.3-c45"; + reg = <3>; + enet-phy-pair-order = <1>; + }; + + ethernet-phy@4 { + compatible = "ethernet-phy-ieee802.3-c45"; + reg = <4>; + enet-phy-pair-order = <1>; + enet-phy-pair-polarity = <0x1>; + }; + }; + }; From 8f3a933fa1a7f92a18a56d6e612955d033406efc Mon Sep 17 00:00:00 2001 From: Manuel Stocker Date: Tue, 13 Oct 2026 21:56:35 +0300 Subject: [PATCH 1963/2126] net: phy: realtek: support unaligned RTL8224 PHY packages The RTL8224 driver groups its four ports by rounding each PHY address down to a multiple of four and uses the low two address bits as the port index. This assumes that the first port's MDIO address is aligned to a multiple of four. The Hasivo S1100WP-8GT-2S+ uses two RTL8224 packages at MDIO addresses 1-4 and 5-8. Extend the driver to support such configurations by using the base address from an ethernet-phy-package node when present and calculating each port's offset relative to that address. Use the package-relative port index to select the MDI pair order and polarity fields. Reject PHY addresses outside the four-port package and propagate explicit package errors rather than falling back to another base address. Share base-address parsing between probe and MDI configuration, and calculate the port offset when configuring MDI rather than caching it in an additional per-PHY private allocation. Join both DT-described and legacy packages with devm_phy_package_join(), as only the base address is needed, not a shared package node. This avoids mixing OF and non-OF joins, which can unbalance package-node references when members select the same base address. Keep the existing aligned-address assumption when no package node is present. Signed-off-by: Manuel Stocker [Oskari: rebased on net-next and reworked package handling] Signed-off-by: Oskari Lemmela Link: https://patch.msgid.link/20261013185635.1412452-3-oskari@lemmela.net Signed-off-by: Paolo Abeni --- drivers/net/phy/realtek/realtek_main.c | 56 +++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index e14960192e79..cc5ebedd0e8f 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -2720,10 +2720,35 @@ exit: return ret; } -static int rtl8224_mdi_config_order(struct phy_device *phydev) +static int rtl8224_get_base_addr(struct phy_device *phydev, u32 *base_addr) +{ + struct device *dev = &phydev->mdio.dev; + struct device_node *np; + int ret; + + *base_addr = phydev->mdio.addr & ~3; + np = of_get_parent(dev->of_node); + if (of_node_name_eq(np, "ethernet-phy-package")) { + ret = of_property_read_u32(np, "reg", base_addr); + of_node_put(np); + if (ret) + return dev_err_probe(dev, ret, + "Missing or invalid PHY package reg\n"); + + if (phydev->mdio.addr < *base_addr || + phydev->mdio.addr - *base_addr >= 4) + return dev_err_probe(dev, -EINVAL, + "PHY address outside RTL8224 package\n"); + } else { + of_node_put(np); + } + + return 0; +} + +static int rtl8224_mdi_config_order(struct phy_device *phydev, u8 port_offset) { struct device_node *np = phydev->mdio.dev.of_node; - u8 port_offset = phydev->mdio.addr & 3; u32 order = 0; int ret; @@ -2745,10 +2770,10 @@ static int rtl8224_mdi_config_order(struct phy_device *phydev) order ? BIT(port_offset) : 0); } -static int rtl8224_mdi_config_polarity(struct phy_device *phydev) +static int rtl8224_mdi_config_polarity(struct phy_device *phydev, u8 port_offset) { struct device_node *np = phydev->mdio.dev.of_node; - u8 offset = (phydev->mdio.addr & 3) * 4; + u8 offset = port_offset * 4; u32 polarity = 0; int ret; @@ -2772,20 +2797,33 @@ static int rtl8224_mdi_config_polarity(struct phy_device *phydev) static int rtl8224_config_init(struct phy_device *phydev) { + u32 base_addr; + u8 port_offset; int ret; - ret = rtl8224_mdi_config_order(phydev); + ret = rtl8224_get_base_addr(phydev, &base_addr); if (ret) return ret; - return rtl8224_mdi_config_polarity(phydev); + port_offset = phydev->mdio.addr - base_addr; + ret = rtl8224_mdi_config_order(phydev, port_offset); + if (ret) + return ret; + + return rtl8224_mdi_config_polarity(phydev, port_offset); } static int rtl8224_probe(struct phy_device *phydev) { - /* Chip exposes 4 ports, join all of them in the same package */ - return devm_phy_package_join(&phydev->mdio.dev, phydev, - phydev->mdio.addr & ~3, 0); + struct device *dev = &phydev->mdio.dev; + u32 base_addr; + int ret; + + ret = rtl8224_get_base_addr(phydev, &base_addr); + if (ret) + return ret; + + return devm_phy_package_join(dev, phydev, base_addr, 0); } static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) From 258c3ae4a4af0c7948a3d99e7262701aaa350d31 Mon Sep 17 00:00:00 2001 From: Nicolai Buchwitz Date: Thu, 15 Oct 2026 10:16:38 +0200 Subject: [PATCH 1964/2126] net: rename skb_unshare() to skb_unclone_full() skb_unshare() only copies cloned skbs. A shared skb that is not a clone comes back unchanged, which the name doesn't suggest. The loopback selftest hooks got caught by this and hit BUG_ON(skb_shared()). Rename it to skb_unclone_full(). Like skb_unclone() it only acts on clones, but it copies the whole skb, not just the head. Suggested-by: Jakub Kicinski Signed-off-by: Nicolai Buchwitz Reviewed-by: Ioana Ciornei # dpaa2 Link: https://patch.msgid.link/20261015-nb-skb-unclone-full-v1-1-0dfbf01f60f2@tipi-net.de Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 2 +- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 4 ++-- .../net/ethernet/freescale/dpaa2/dpaa2-switch.c | 4 ++-- .../ethernet/marvell/octeontx2/nic/otx2_common.c | 2 +- .../ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +- drivers/net/macsec.c | 6 +++--- include/linux/if_vlan.h | 16 ++++++++-------- include/linux/skbuff.h | 11 +++++++---- net/bluetooth/6lowpan.c | 2 +- net/dsa/tag.c | 2 +- net/ieee802154/6lowpan/rx.c | 2 +- net/ieee802154/6lowpan/tx.c | 2 +- net/mctp/route.c | 2 +- net/sched/sch_netem.c | 4 ++-- net/sctp/ulpqueue.c | 2 +- net/tipc/msg.c | 2 +- 16 files changed, 34 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c b/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c index cfdbd4639a1e..7ebae08ddf29 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c @@ -44,7 +44,7 @@ static int xgbe_test_loopback_validate(struct sk_buff *skb, struct iphdr *ih; int eat; - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) goto out; diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index def2d5c0e7f7..7227a35dfaf2 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -1418,9 +1418,9 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, /* We'll be holding a back-reference to the skb until Tx Confirmation; * we don't want that overwritten by a concurrent Tx with a cloned skb. */ - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (unlikely(!skb)) { - /* skb_unshare() has already freed the skb */ + /* skb_unclone_full() has already freed the skb */ percpu_stats->tx_dropped++; return NETDEV_TX_OK; } diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c index 8cabce0eb2ab..fe8ac5e85259 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c @@ -1276,9 +1276,9 @@ static netdev_tx_t dpaa2_switch_port_tx(struct sk_buff *skb, } /* We'll be holding a back-reference to the skb until Tx confirmation */ - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (unlikely(!skb)) { - /* skb_unshare() has already freed the skb */ + /* skb_unclone_full() has already freed the skb */ net_err_ratelimited("%s: Error copying the socket buffer\n", net_dev->name); goto err_exit; } diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c index 77c5cfbe4ce4..4e418c7456b7 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -2117,7 +2117,7 @@ dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf, /* Crypto hardware need write permission for ipsec crypto offload */ if (unlikely(xfrm_offload(skb))) { dir = DMA_BIDIRECTIONAL; - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); } /* First segment is always skb->data */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c index dbe8339947be..40811df8f2b7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -920,7 +920,7 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb, proto = tpriv->svlan ? ETH_P_8021AD : ETH_P_8021Q; - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) goto out; diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 4296884d5b4d..87f3f4bdb026 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -644,7 +644,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb, return ERR_PTR(-ENOMEM); } } else { - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) { macsec_txsa_put(tx_sa); return ERR_PTR(-ENOMEM); @@ -953,7 +953,7 @@ static struct sk_buff *macsec_decrypt(struct sk_buff *skb, aead_request_set_crypt(req, sg, sg, len, iv); aead_request_set_ad(req, macsec_hdr_len(macsec_skb_cb(skb)->has_sci)); - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) { aead_request_free(req); return ERR_PTR(-ENOMEM); @@ -1159,7 +1159,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb) if (hdr->eth.h_proto != htons(ETH_P_MACSEC)) return handle_not_macsec(skb); - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); *pskb = skb; if (!skb) return RX_HANDLER_CONSUMED; diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 975892367136..c863cdf60f01 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -427,8 +427,8 @@ static inline int __vlan_insert_tag(struct sk_buff *skb, * Inserts the VLAN tag into @skb as part of the payload at offset mac_len * Returns a VLAN tagged skb. This might change skb->head. * - * Following the skb_unshare() example, in case of error, the calling function - * doesn't have to worry about freeing the original skb. + * Following the skb_unclone_full() example, in case of error, the calling + * function doesn't have to worry about freeing the original skb. * * Does not change skb->protocol so this function can be used during receive. * @@ -458,8 +458,8 @@ static inline struct sk_buff *vlan_insert_inner_tag(struct sk_buff *skb, * Inserts the VLAN tag into @skb as part of the payload * Returns a VLAN tagged skb. This might change skb->head. * - * Following the skb_unshare() example, in case of error, the calling function - * doesn't have to worry about freeing the original skb. + * Following the skb_unclone_full() example, in case of error, the calling + * function doesn't have to worry about freeing the original skb. * * Does not change skb->protocol so this function can be used during receive. * @@ -480,8 +480,8 @@ static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb, * Inserts the VLAN tag into @skb as part of the payload * Returns a VLAN tagged skb. This might change skb->head. * - * Following the skb_unshare() example, in case of error, the calling function - * doesn't have to worry about freeing the original skb. + * Following the skb_unclone_full() example, in case of error, the calling + * function doesn't have to worry about freeing the original skb. * * Return: modified @skb on success, NULL on error (@skb is freed). */ @@ -524,8 +524,8 @@ static inline void __vlan_hwaccel_copy_tag(struct sk_buff *dst, const struct sk_ * * Pushes the VLAN tag from @skb->vlan_tci inside to the payload. * - * Following the skb_unshare() example, in case of error, the calling function - * doesn't have to worry about freeing the original skb. + * Following the skb_unclone_full() example, in case of error, the calling + * function doesn't have to worry about freeing the original skb. */ static inline struct sk_buff *__vlan_hwaccel_push_inside(struct sk_buff *skb) { diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index af1cbc2799b7..5079335f7aae 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2131,14 +2131,14 @@ static inline struct sk_buff *skb_share_check(struct sk_buff *skb, gfp_t pri) } /* - * Copy shared buffers into a new sk_buff. We effectively do COW on + * Copy cloned buffers into a new sk_buff. We effectively do COW on * packets to handle cases where we have a local reader and forward * and a couple of other messy ones. The normal one is tcpdumping * a packet that's being forwarded. */ /** - * skb_unshare - make a copy of a shared buffer + * skb_unclone_full - make a private copy of a cloned buffer * @skb: buffer to check * @pri: priority for memory allocation * @@ -2148,10 +2148,13 @@ static inline struct sk_buff *skb_share_check(struct sk_buff *skb, gfp_t pri) * the original buffer is returned. When called with a spinlock held or * from interrupt state @pri must be %GFP_ATOMIC * + * Unlike skb_unclone(), the paged data is copied as well. A buffer with + * skb->users > 1 that is not a clone is returned as is, use + * skb_share_check() for that case. + * * %NULL is returned on a memory allocation failure. */ -static inline struct sk_buff *skb_unshare(struct sk_buff *skb, - gfp_t pri) +static inline struct sk_buff *skb_unclone_full(struct sk_buff *skb, gfp_t pri) { might_sleep_if(gfpflags_allow_blocking(pri)); if (skb_cloned(skb)) { diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 9a736cefac18..8c51c20f6c4b 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -515,7 +515,7 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev) /* We must take a copy of the skb before we modify/replace the ipv6 * header as the header could be used elsewhere */ - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) return NET_XMIT_DROP; diff --git a/net/dsa/tag.c b/net/dsa/tag.c index 991732d6eae2..6a5aa7fc331c 100644 --- a/net/dsa/tag.c +++ b/net/dsa/tag.c @@ -64,7 +64,7 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev, return 0; } - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) return 0; diff --git a/net/ieee802154/6lowpan/rx.c b/net/ieee802154/6lowpan/rx.c index 517e6493f5d1..9148f1be7cba 100644 --- a/net/ieee802154/6lowpan/rx.c +++ b/net/ieee802154/6lowpan/rx.c @@ -294,7 +294,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, */ if (lowpan_is_frag1(*skb_network_header(skb)) || lowpan_is_iphc(*skb_network_header(skb))) { - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) goto out; } diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c index b261daedc290..d346e906e41e 100644 --- a/net/ieee802154/6lowpan/tx.c +++ b/net/ieee802154/6lowpan/tx.c @@ -279,7 +279,7 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev) return NET_XMIT_DROP; } } else { - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (!skb) return NET_XMIT_DROP; } diff --git a/net/mctp/route.c b/net/mctp/route.c index e7c95eeacb48..d18ed9d0db1d 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -396,7 +396,7 @@ static int mctp_frag_queue(struct mctp_sk_key *key, struct sk_buff *skb) * this will free the skb; callers can no longer access it * safely. */ - key->reasm_head = skb_unshare(skb, GFP_ATOMIC); + key->reasm_head = skb_unclone_full(skb, GFP_ATOMIC); if (!key->reasm_head) return -ENOMEM; diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 8a1b89a289d8..1dc2924890eb 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -460,7 +460,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) { struct netem_sched_data *q = qdisc_priv(sch); - /* We don't fill cb now as skb_unshare() may invalidate it */ + /* We don't fill cb now as skb_unclone_full() may invalidate it */ struct netem_skb_cb *cb; struct sk_buff *skb2 = NULL; struct sk_buff *segs = NULL; @@ -528,7 +528,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, qdisc_skb_cb(skb)->pkt_len = skb->len; } - skb = skb_unshare(skb, GFP_ATOMIC); + skb = skb_unclone_full(skb, GFP_ATOMIC); if (unlikely(!skb)) { WRITE_ONCE(q->allocation_errors, q->allocation_errors + 1); qdisc_qstats_drop(sch); diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c index b05daafd369a..93823eebd727 100644 --- a/net/sctp/ulpqueue.c +++ b/net/sctp/ulpqueue.c @@ -339,7 +339,7 @@ struct sctp_ulpevent *sctp_make_reassembled_event(struct net *net, if (skb_cloned(f_frag)) { /* This is a cloned skb, we can't just modify * the frag_list. We need a new skb to do that. - * Instead of calling skb_unshare(), we'll do it + * Instead of calling skb_unclone_full(), we'll do it * ourselves since we need to delay the free. */ new = skb_copy(f_frag, GFP_ATOMIC); diff --git a/net/tipc/msg.c b/net/tipc/msg.c index b0bba0feef56..39dfd33c8eec 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c @@ -145,7 +145,7 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) if (skb_has_frag_list(frag) && __skb_linearize(frag)) goto err; *buf = NULL; - frag = skb_unshare(frag, GFP_ATOMIC); + frag = skb_unclone_full(frag, GFP_ATOMIC); if (unlikely(!frag)) goto err; head = *headbuf = frag; From b20b1db7e3f085b7a99fb1cbf80ab311a6f73117 Mon Sep 17 00:00:00 2001 From: Rand Deeb Date: Wed, 14 Oct 2026 17:58:00 +0300 Subject: [PATCH 1965/2126] sfc: fix NULL pointer dereference in efx_tc_flower_replace_foreign() efx_tc_flower_replace_foreign() walks the rule's actions with an 'act' cursor. After a redirect action it adds the action set to the rule and sets the cursor to NULL: list_add_tail(&act->list, &rule->acts.list); act = NULL; if (fa->id == FLOW_ACTION_REDIRECT) break; /* end of the line */ The break only leaves the switch statement, so flow_action_for_each() carries on with the next action while act is NULL. A following redirect or mirred action then does "save = *act", and a following tunnel decap action passes act to efx_tc_flower_action_order_ok(), which reads act->decap. Both dereference a NULL pointer. The loop is missing the check that efx_tc_flower_replace() performs at the start of every iteration for the same cursor: reject the rule if an action follows a non-pipe action. The foreign variant was added without it. As a result, a TC flower rule on a tunnel netdevice that redirects to an sfc representor and lists another redirect, mirred or tunnel decap action after the first redirect causes a kernel NULL pointer dereference. It happens in the context of the task adding the filter, with efx->tc->mutex held. Adding such a rule requires CAP_NET_ADMIN. Add the same check at the top of the action loop in efx_tc_flower_replace_foreign(), returning -EINVAL with the same extack message as efx_tc_flower_replace(). The release path already copes with act being NULL. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: 17654d84b47c ("sfc: add offloading of 'foreign' TC (decap) rules") Signed-off-by: Rand Deeb Acked-by: Edward Cree Link: https://patch.msgid.link/20261014145800.726-1-rand.sec96@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/sfc/tc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index 25341acfb472..4a740da04348 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -1828,6 +1828,13 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx, flow_action_for_each(i, fa, &fr->action) { struct efx_tc_action_set save; + if (!act) { + /* more actions after a non-pipe action */ + NL_SET_ERR_MSG_MOD(extack, "Action follows non-pipe action"); + rc = -EINVAL; + goto release; + } + switch (fa->id) { case FLOW_ACTION_REDIRECT: case FLOW_ACTION_MIRRED: From 241c9ed785d0f6e5e3f5981d5652f6e1727e5f6d Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Tue, 13 Oct 2026 12:34:59 -0600 Subject: [PATCH 1966/2126] net: wwan: core: propagate modem control signals to port drivers The WWAN character device emulates the TTY modem-control ioctls (TIOCMGET/TIOCMSET/TIOCMBIC/TIOCMBIS) for AT and QCDM ports, but the result is only stored in port->at_data.mdmbits and never reaches the port driver. A driver therefore cannot act on the host raising or dropping DTR/RTS, even though some modems depend on it (e.g. they withhold unsolicited AT result codes until the host asserts DTR). Add an optional ->dtr_rts(port, mdmbits) operation to struct wwan_port_ops. Drivers that implement it receive the TIOCM output bitmask so they can assert or de-assert DTR and RTS independently. As in tty_tiocmset(), the wwan core keeps only the output bits (DTR, RTS, OUT1, OUT2, LOOP) of the TIOCMSET/TIOCMBIS/TIOCMBIC value in port->at_data.mdmbits, and calls ->dtr_rts when DTR or RTS actually changes, gated on WWAN_PORT_AT to match the open/close raise/drop behaviour. Also raise DTR/RTS in wwan_port_op_start on first open of an AT port when the driver implements ->dtr_rts, and drop them in wwan_port_op_stop on last close if HUPCL is set in the port's termios. This follows TTY open/close semantics, although the termios baud rate is not used, and means individual drivers do not need to implement this themselves. As on a TTY, HUPCL defaults to on for AT ports, and userspace can clear it with TCSETS to keep DTR asserted across close, for example so that closing the port does not end a call on a modem set to AT&D1/AT&D2. TCSETS and TCSETS2 now only commit the new termios when the copy from userspace succeeds, so a faulting call cannot silently clear HUPCL. ->dtr_rts must be called under ops_lock, which serialises port ops and protects against port removal (removal clears port->ops under it). So that updates to the TIOCM state and the ->dtr_rts calls are serialised together, the termios/TIOCM state now also lives under ops_lock and the separate data_lock is removed. The AT/QCDM ioctl handler only holds ops_lock while it reads or updates that state, never across a user-memory copy, and takes it interruptibly since a driver's blocking write holds it while it waits. Ioctls that do not touch that state, such as TCFLSH, TIOCEXCL and the FIONREAD fallback, do not take it. wwan_remove_port() also drops DTR/RTS before ->stop() when a port is removed while still open, regardless of HUPCL since the device is going away. The raise and drop paths go through two small helpers, which do the AT port and ->dtr_rts checks and pass the driver the resulting bitmask. Signed-off-by: Peter Hunt Reviewed-by: Loic Poulain Link: https://patch.msgid.link/20261013183500.261229-2-peter.hunt@opengear.com Signed-off-by: Jakub Kicinski --- drivers/net/wwan/wwan_core.c | 172 +++++++++++++++++++++++------------ include/linux/wwan.h | 9 ++ 2 files changed, 124 insertions(+), 57 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index ffbcf11e4e68..7097b58dafde 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -25,6 +25,10 @@ #include #include +/* Modem control bits userspace may set on an AT port, as for tty_tiocmset() */ +#define WWAN_TIOCM_OUTPUTS (TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | \ + TIOCM_OUT2 | TIOCM_LOOP) + /* Maximum number of minors in use */ #define WWAN_MAX_MINORS (1 << MINORBITS) @@ -73,11 +77,10 @@ struct wwan_device { * @start_count: Port start counter * @flags: Store port state and capabilities * @ops: Pointer to WWAN port operations - * @ops_lock: Protect port ops + * @ops_lock: Protect port ops, and the AT/QCDM termios and TIOCM state * @dev: Underlying device * @rxq: Buffer inbound queue * @waitqueue: The waitqueue for port fops (read/write/poll) - * @data_lock: Port specific data access serialization * @headroom_len: SKB reserved headroom size * @frag_len: Length to fragment packet * @at_data: AT port specific data @@ -88,11 +91,10 @@ struct wwan_port { unsigned int start_count; unsigned long flags; const struct wwan_port_ops *ops; - struct mutex ops_lock; /* Serialize ops + protect against removal */ + struct mutex ops_lock; /* Serialize ops + at_data, protect against removal */ struct device dev; struct sk_buff_head rxq; wait_queue_head_t waitqueue; - struct mutex data_lock; /* Port specific data access serialization */ size_t headroom_len; size_t frag_len; union { @@ -374,7 +376,6 @@ static void wwan_port_destroy(struct device *dev) if (dev->class == &wwan_class) ida_free(&minors, MINOR(dev->devt)); - mutex_destroy(&port->data_lock); mutex_destroy(&port->ops_lock); kfree(port); } @@ -653,7 +654,10 @@ struct wwan_port *wwan_create_port(struct device *parent, mutex_init(&port->ops_lock); skb_queue_head_init(&port->rxq); init_waitqueue_head(&port->waitqueue); - mutex_init(&port->data_lock); + + /* AT ports default to HUPCL, so DTR/RTS are dropped on last close */ + if (type == WWAN_PORT_AT) + port->at_data.termios.c_cflag = HUPCL; port->dev.parent = &wwandev->dev; port->dev.type = &wwan_port_dev_type; @@ -679,12 +683,44 @@ error_wwandev_remove: } EXPORT_SYMBOL_GPL(wwan_create_port); +/* Raise DTR/RTS when an AT port is first opened, as a TTY does on open. + * Unlike a TTY the termios baud rate is not used. Called with ops_lock held. + */ +static void wwan_port_raise_dtr_rts(struct wwan_port *port) +{ + lockdep_assert_held(&port->ops_lock); + + if (port->type != WWAN_PORT_AT || !port->ops->dtr_rts) + return; + + port->at_data.mdmbits |= TIOCM_DTR | TIOCM_RTS; + port->ops->dtr_rts(port, port->at_data.mdmbits); +} + +/* Drop DTR/RTS on an AT port. Called with ops_lock held. On last close + * the lines are only dropped if HUPCL is set, as for a TTY. When a port is + * removed while still open they are always dropped. + */ +static void wwan_port_drop_dtr_rts(struct wwan_port *port, bool hupcl_only) +{ + lockdep_assert_held(&port->ops_lock); + + if (port->type != WWAN_PORT_AT || !port->ops->dtr_rts) + return; + if (hupcl_only && !(port->at_data.termios.c_cflag & HUPCL)) + return; + + port->at_data.mdmbits &= ~(TIOCM_DTR | TIOCM_RTS); + port->ops->dtr_rts(port, port->at_data.mdmbits); +} + void wwan_remove_port(struct wwan_port *port) { struct wwan_device *wwandev = to_wwan_dev(port->dev.parent); mutex_lock(&port->ops_lock); if (port->start_count) { + wwan_port_drop_dtr_rts(port, false); port->ops->stop(port); port->start_count = 0; } @@ -756,8 +792,11 @@ static int wwan_port_op_start(struct wwan_port *port) } /* If port is already started, don't start again */ - if (!port->start_count) + if (!port->start_count) { ret = port->ops->start(port); + if (!ret) + wwan_port_raise_dtr_rts(port); + } if (!ret) port->start_count++; @@ -773,8 +812,10 @@ static void wwan_port_op_stop(struct wwan_port *port) mutex_lock(&port->ops_lock); port->start_count--; if (!port->start_count) { - if (port->ops) + if (port->ops) { + wwan_port_drop_dtr_rts(port, true); port->ops->stop(port); + } skb_queue_purge(&port->rxq); clear_bit(WWAN_PORT_EXCLUSIVE, &port->flags); } @@ -976,92 +1017,109 @@ static __poll_t wwan_port_fops_poll(struct file *filp, poll_table *wait) } /* Implements minimalistic stub terminal IOCTLs support */ +/* TCGETS/TCSETS and their termios2 variants. @size is the size of the user + * structure, a prefix of struct ktermios. As for the TIOCM ioctls, user + * memory is only accessed outside ops_lock. + */ +static long wwan_port_termios_ioctl(struct wwan_port *port, bool set, + void __user *uarg, size_t size) +{ + struct ktermios termios; + + if (!set) { + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &port->ops_lock) + termios = port->at_data.termios; + return copy_to_user(uarg, &termios, size) ? -EFAULT : 0; + } + + /* Commit only on success, a partial copy must not clear HUPCL */ + if (copy_from_user(&termios, uarg, size)) + return -EFAULT; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &port->ops_lock) + memcpy(&port->at_data.termios, &termios, size); + return 0; +} + static long wwan_port_fops_at_ioctl(struct wwan_port *port, unsigned int cmd, unsigned long arg) { - int ret = 0; - - mutex_lock(&port->data_lock); - + /* ops_lock serialises the termios/TIOCM state with port ops and + * removal. It is only held while that state is read or updated, never + * across a user copy, and is taken interruptibly as a blocking write + * holds it too. + */ switch (cmd) { case TCFLSH: - break; + return 0; case TCGETS: - if (copy_to_user((void __user *)arg, &port->at_data.termios, - sizeof(struct termios))) - ret = -EFAULT; - break; - case TCSETS: case TCSETSW: case TCSETSF: - if (copy_from_user(&port->at_data.termios, (void __user *)arg, - sizeof(struct termios))) - ret = -EFAULT; - break; + return wwan_port_termios_ioctl(port, cmd != TCGETS, + (void __user *)arg, + sizeof(struct termios)); #ifdef TCGETS2 case TCGETS2: - if (copy_to_user((void __user *)arg, &port->at_data.termios, - sizeof(struct termios2))) - ret = -EFAULT; - break; - case TCSETS2: case TCSETSW2: case TCSETSF2: - if (copy_from_user(&port->at_data.termios, (void __user *)arg, - sizeof(struct termios2))) - ret = -EFAULT; - break; + return wwan_port_termios_ioctl(port, cmd != TCGETS2, + (void __user *)arg, + sizeof(struct termios2)); #endif - case TIOCMGET: - ret = put_user(port->at_data.mdmbits, (int __user *)arg); - break; + case TIOCMGET: { + int mdmbits; + + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &port->ops_lock) + mdmbits = port->at_data.mdmbits; + return put_user(mdmbits, (int __user *)arg); + } case TIOCMSET: case TIOCMBIC: case TIOCMBIS: { int mdmbits; - if (copy_from_user(&mdmbits, (int __user *)arg, sizeof(int))) { - ret = -EFAULT; - break; + if (get_user(mdmbits, (int __user *)arg)) + return -EFAULT; + mdmbits &= WWAN_TIOCM_OUTPUTS; + + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &port->ops_lock) { + int old = port->at_data.mdmbits; + + if (cmd == TIOCMBIC) + port->at_data.mdmbits &= ~mdmbits; + else if (cmd == TIOCMBIS) + port->at_data.mdmbits |= mdmbits; + else + port->at_data.mdmbits = mdmbits; + /* Only signal the driver when DTR or RTS actually changes */ + if (port->type == WWAN_PORT_AT && port->ops && + port->ops->dtr_rts && + (old ^ port->at_data.mdmbits) & (TIOCM_DTR | TIOCM_RTS)) + port->ops->dtr_rts(port, port->at_data.mdmbits); } - if (cmd == TIOCMBIC) - port->at_data.mdmbits &= ~mdmbits; - else if (cmd == TIOCMBIS) - port->at_data.mdmbits |= mdmbits; - else - port->at_data.mdmbits = mdmbits; - break; + return 0; } case TIOCEXCL: set_bit(WWAN_PORT_EXCLUSIVE, &port->flags); - break; + return 0; case TIOCNXCL: clear_bit(WWAN_PORT_EXCLUSIVE, &port->flags); - break; + return 0; case TIOCGEXCL: - { - int excl = test_bit(WWAN_PORT_EXCLUSIVE, &port->flags); - - ret = put_user(excl, (int __user *)arg); - break; - } + return put_user(test_bit(WWAN_PORT_EXCLUSIVE, &port->flags), + (int __user *)arg); default: - ret = -ENOIOCTLCMD; + return -ENOIOCTLCMD; } - - mutex_unlock(&port->data_lock); - - return ret; } static long wwan_port_fops_ioctl(struct file *filp, unsigned int cmd, diff --git a/include/linux/wwan.h b/include/linux/wwan.h index 1e0e2cb53579..23a8a8ee473d 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -57,6 +57,14 @@ struct wwan_port; * @tx_blocking: Optional blocking routine that sends WWAN port protocol data * to the device. * @tx_poll: Optional routine that sets additional TX poll flags. + * @dtr_rts: Optional routine that updates the modem control lines to match + * @mdmbits, the TIOCM_* output bits (DTR, RTS, OUT1, OUT2, LOOP) + * currently set for the port. Called when the port is first opened + * and ->start() has succeeded, on last close if HUPCL is set, when + * the port is removed while still open, and when TIOCMSET, TIOCMBIS + * or TIOCMBIC changes DTR or RTS. Only called for WWAN_PORT_AT ports, + * as only the AT (DUN) port carries the modem's virtual RS-232 + * control signals. * * The wwan_port_ops structure contains a list of low-level operations * that control a WWAN port device. All functions are mandatory unless specified. @@ -70,6 +78,7 @@ struct wwan_port_ops { int (*tx_blocking)(struct wwan_port *port, struct sk_buff *skb); __poll_t (*tx_poll)(struct wwan_port *port, struct file *filp, poll_table *wait); + void (*dtr_rts)(struct wwan_port *port, unsigned int mdmbits); }; /** struct wwan_port_caps - The WWAN port capbilities From d509edf90bc60857f86922d10cdc3ef20e3bf3d6 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Tue, 13 Oct 2026 12:35:00 -0600 Subject: [PATCH 1967/2126] net: wwan: mhi_wwan_ctrl: drive DTR/RTS via the IP_CTRL channel Qualcomm/Sierra SDX55/SDX65 modems withhold unsolicited AT result codes (URCs such as +CREG, and the +DMI OMA-DM/LwM2M session indications) on an AT port until the host asserts DTR. mhi_wwan_ctrl exposed the AT (DUN) ports but had no way to signal DTR, so URCs never reached userspace. Carry the host serial-control lines to the modem over the dedicated IP_CTRL MHI channel, which this module now also binds. IP_CTRL uses a separate mhi_driver with its own callbacks so the AT/QMI/MBIM data path is untouched; the control-channel device for each MHI controller is tracked in a small registry so an AT port drives the IP_CTRL channel of its own modem (multiple modems are supported). The IP_CTRL channel has to be declared in the controller's channel config for this driver to bind. For the Sierra EM919x/EM929x this is done by commit 83c29a55b89e ("bus: mhi: host: pci_generic: Add IP_CTRL channel for Sierra EM919x/EM929x") in the MHI tree. On controllers that do not declare IP_CTRL the driver does not bind and ->dtr_rts is a no-op. The wwan core, with "net: wwan: core: propagate modem control signals to port drivers", raises DTR/RTS on first open and drops them on last close (if HUPCL is set) for any AT port whose driver implements ->dtr_rts, so no open/close handling is needed here. The new ->dtr_rts op lets userspace assert or de-assert them via TIOCMSET/TIOCMBIC/TIOCMBIS. Received device->host serial state messages are silently discarded; a single recycled sink buffer keeps the IP_CTRL DL ring live so the modem's transmit path does not stall. ->dtr_rts is void, following the tty_port_operations model it is modelled on. It records the requested state and schedules a per-port work item that sends the latest state to the modem, so a burst of changes is coalesced into one message and cannot fill the IP_CTRL UL ring. If a send fails because the ring is full or memory is short, the work retries shortly with whatever state is latest by then, so the modem ends up with the final state that was requested. The DL sink buffer is requeued from a work item, which retries a transient -ENOMEM so the DL ring does not stay empty, and which remove() disables before tearing down the channel. Signed-off-by: Peter Hunt Reviewed-by: Loic Poulain Link: https://patch.msgid.link/20261013183500.261229-3-peter.hunt@opengear.com Signed-off-by: Jakub Kicinski --- drivers/net/wwan/mhi_wwan_ctrl.c | 262 ++++++++++++++++++++++++++++++- 1 file changed, 261 insertions(+), 1 deletion(-) diff --git a/drivers/net/wwan/mhi_wwan_ctrl.c b/drivers/net/wwan/mhi_wwan_ctrl.c index a31d8540fbb8..e3c207588956 100644 --- a/drivers/net/wwan/mhi_wwan_ctrl.c +++ b/drivers/net/wwan/mhi_wwan_ctrl.c @@ -1,8 +1,13 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2021, Linaro Ltd */ #include +#include #include #include +#include +#include +#include +#include #include /* MHI wwan flags */ @@ -14,6 +19,32 @@ enum mhi_wwan_flags { #define MHI_WWAN_MAX_MTU 0x8000 +/* IP_CTRL channel message that sets the modem's DTR/RTS control lines */ +struct mhi_dtr_ctrl_msg { + __le32 preamble; + __le32 msg_id; + __le32 dest_id; + __le32 size; + __le32 msg; +} __packed; + +#define MHI_DTR_CTRL_MAGIC 0x4C525443 /* 'CTRL' */ +#define MHI_DTR_MSG_DTR BIT(0) +#define MHI_DTR_MSG_RTS BIT(1) +#define MHI_DTR_HOST_STATE 0x10 + +/* Per-controller IP_CTRL channel, used to signal DTR/RTS to that modem */ +struct mhi_wwan_dtr { + struct mhi_controller *cntrl; + struct mhi_device *mhi_dev; + struct list_head node; + struct mhi_dtr_ctrl_msg *rx_buf; /* DL sink, separate allocation for DMA safety */ + struct delayed_work rx_refill; /* retries a failed sink buffer requeue */ +}; + +static LIST_HEAD(mhi_wwan_dtr_list); +static DEFINE_MUTEX(mhi_wwan_dtr_lock); + struct mhi_wwan_dev { /* Lower level is a mhi dev, upper level is a wwan port */ struct mhi_device *mhi_dev; @@ -35,6 +66,12 @@ struct mhi_wwan_dev { * decremented on data queueing and incremented on data release. */ unsigned int rx_budget; + + /* Latest DTR/RTS state for the modem, sent from dtr_work so a burst of + * changes is coalesced and only the final state has to get through + */ + unsigned int dtr_mdmbits; + struct delayed_work dtr_work; }; /* Increment RX budget and schedule RX refill if necessary */ @@ -103,6 +140,80 @@ static void mhi_wwan_ctrl_refill_work(struct work_struct *work) } } +/* Signal the modem's DTR/RTS lines over its own controller's IP_CTRL channel */ +static int mhi_wwan_ctrl_send_dtr(struct mhi_wwan_dev *mhiwwan, unsigned int mdmbits) +{ + struct mhi_controller *cntrl = mhiwwan->mhi_dev->mhi_cntrl; + struct mhi_device *ctrl_dev = NULL; + struct mhi_dtr_ctrl_msg *dtr_msg; + struct mhi_wwan_dtr *dtr; + u32 msg = 0; + int ret; + + guard(mutex)(&mhi_wwan_dtr_lock); + + list_for_each_entry(dtr, &mhi_wwan_dtr_list, node) { + if (dtr->cntrl == cntrl) { + ctrl_dev = dtr->mhi_dev; + break; + } + } + if (!ctrl_dev) { + dev_dbg(&mhiwwan->mhi_dev->dev, + "IP_CTRL not enumerated; DTR/RTS not signalled to modem\n"); + return 0; + } + + dtr_msg = kzalloc_obj(*dtr_msg); + if (!dtr_msg) + return -ENOMEM; + + if (mdmbits & TIOCM_DTR) + msg |= MHI_DTR_MSG_DTR; + if (mdmbits & TIOCM_RTS) + msg |= MHI_DTR_MSG_RTS; + + dtr_msg->preamble = cpu_to_le32(MHI_DTR_CTRL_MAGIC); + dtr_msg->msg_id = cpu_to_le32(MHI_DTR_HOST_STATE); + dtr_msg->dest_id = cpu_to_le32(mhiwwan->mhi_dev->ul_chan_id); + dtr_msg->size = cpu_to_le32(sizeof(__le32)); + dtr_msg->msg = cpu_to_le32(msg); + + ret = mhi_queue_buf(ctrl_dev, DMA_TO_DEVICE, dtr_msg, sizeof(*dtr_msg), + MHI_EOT); + if (ret) + kfree(dtr_msg); + + return ret; +} + +/* Send the latest DTR/RTS state. A full UL ring or a failed allocation is + * retried shortly, with whatever state is latest by then, so the modem ends + * up with the final state. Other errors mean the channel is going away. + */ +static void mhi_wwan_ctrl_dtr_work(struct work_struct *work) +{ + struct mhi_wwan_dev *mhiwwan = container_of(to_delayed_work(work), + struct mhi_wwan_dev, dtr_work); + int ret; + + ret = mhi_wwan_ctrl_send_dtr(mhiwwan, READ_ONCE(mhiwwan->dtr_mdmbits)); + if (ret == -EAGAIN || ret == -ENOMEM) + schedule_delayed_work(&mhiwwan->dtr_work, msecs_to_jiffies(10)); + else if (ret) + dev_warn_ratelimited(&mhiwwan->mhi_dev->dev, + "failed to send DTR/RTS state to modem: %d\n", + ret); +} + +static void mhi_wwan_ctrl_dtr_rts(struct wwan_port *port, unsigned int mdmbits) +{ + struct mhi_wwan_dev *mhiwwan = wwan_port_get_drvdata(port); + + WRITE_ONCE(mhiwwan->dtr_mdmbits, mdmbits); + schedule_delayed_work(&mhiwwan->dtr_work, 0); +} + static int mhi_wwan_ctrl_start(struct wwan_port *port) { struct mhi_wwan_dev *mhiwwan = wwan_port_get_drvdata(port); @@ -163,6 +274,7 @@ static const struct wwan_port_ops wwan_pops = { .start = mhi_wwan_ctrl_start, .stop = mhi_wwan_ctrl_stop, .tx = mhi_wwan_ctrl_tx, + .dtr_rts = mhi_wwan_ctrl_dtr_rts, }; static void mhi_ul_xfer_cb(struct mhi_device *mhi_dev, @@ -224,6 +336,7 @@ static int mhi_wwan_ctrl_probe(struct mhi_device *mhi_dev, mhiwwan->mhi_dev = mhi_dev; mhiwwan->mtu = MHI_WWAN_MAX_MTU; INIT_WORK(&mhiwwan->rx_refill, mhi_wwan_ctrl_refill_work); + INIT_DELAYED_WORK(&mhiwwan->dtr_work, mhi_wwan_ctrl_dtr_work); spin_lock_init(&mhiwwan->tx_lock); spin_lock_init(&mhiwwan->rx_lock); @@ -252,9 +365,118 @@ static void mhi_wwan_ctrl_remove(struct mhi_device *mhi_dev) struct mhi_wwan_dev *mhiwwan = dev_get_drvdata(&mhi_dev->dev); wwan_remove_port(mhiwwan->wwan_port); + /* Give the DTR/RTS drop from removal one attempt, then stop the work */ + flush_delayed_work(&mhiwwan->dtr_work); + disable_delayed_work_sync(&mhiwwan->dtr_work); kfree(mhiwwan); } +/* IP_CTRL channel driver, bound separately so the data-port path is untouched */ +static void mhi_wwan_dtr_ul_xfer_cb(struct mhi_device *mhi_dev, + struct mhi_result *mhi_result) +{ + /* MHI core has done with the buffer, release it */ + kfree(mhi_result->buf_addr); +} + +/* Requeue the single DL sink buffer so the IP_CTRL DL ring never runs empty. + * This only runs from the work item, so remove() can stop it before the + * channel is torn down. A transient mapping failure is retried, other errors + * mean the channel is going away and the next probe queues a fresh buffer. + */ +static void mhi_wwan_dtr_refill_work(struct work_struct *work) +{ + struct mhi_wwan_dtr *dtr = container_of(to_delayed_work(work), + struct mhi_wwan_dtr, rx_refill); + int ret; + + ret = mhi_queue_buf(dtr->mhi_dev, DMA_FROM_DEVICE, dtr->rx_buf, + sizeof(*dtr->rx_buf), MHI_EOT); + if (ret == -ENOMEM) { + dev_warn_ratelimited(&dtr->mhi_dev->dev, + "failed to requeue IP_CTRL RX buffer, retrying\n"); + schedule_delayed_work(&dtr->rx_refill, msecs_to_jiffies(100)); + } else if (ret) { + dev_dbg(&dtr->mhi_dev->dev, + "failed to requeue IP_CTRL RX buffer: %d\n", ret); + } +} + +static void mhi_wwan_dtr_dl_xfer_cb(struct mhi_device *mhi_dev, + struct mhi_result *mhi_result) +{ + struct mhi_wwan_dtr *dtr = dev_get_drvdata(&mhi_dev->dev); + + /* Channel is being torn down (e.g. -ENOTCONN), do not requeue */ + if (mhi_result->transaction_status && + mhi_result->transaction_status != -EOVERFLOW) + return; + + /* Modem serial state not needed, requeue the sink buffer to keep DL ring live */ + schedule_delayed_work(&dtr->rx_refill, 0); +} + +static int mhi_wwan_dtr_probe(struct mhi_device *mhi_dev, + const struct mhi_device_id *id) +{ + struct mhi_wwan_dtr *dtr; + int ret; + + dtr = kzalloc_obj(*dtr); + if (!dtr) + return -ENOMEM; + + dtr->rx_buf = kmalloc_obj(*dtr->rx_buf); + if (!dtr->rx_buf) { + ret = -ENOMEM; + goto err_free_dtr; + } + INIT_DELAYED_WORK(&dtr->rx_refill, mhi_wwan_dtr_refill_work); + + ret = mhi_prepare_for_transfer(mhi_dev); + if (ret) + goto err_free_buf; + + dtr->cntrl = mhi_dev->mhi_cntrl; + dtr->mhi_dev = mhi_dev; + dev_set_drvdata(&mhi_dev->dev, dtr); + + /* On failure mhi_probe() unprepares the channels itself */ + ret = mhi_queue_buf(mhi_dev, DMA_FROM_DEVICE, dtr->rx_buf, + sizeof(*dtr->rx_buf), MHI_EOT); + if (ret) + goto err_free_buf; + + mutex_lock(&mhi_wwan_dtr_lock); + list_add(&dtr->node, &mhi_wwan_dtr_list); + mutex_unlock(&mhi_wwan_dtr_lock); + + return 0; + +err_free_buf: + kfree(dtr->rx_buf); +err_free_dtr: + kfree(dtr); + return ret; +} + +static void mhi_wwan_dtr_remove(struct mhi_device *mhi_dev) +{ + struct mhi_wwan_dtr *dtr = dev_get_drvdata(&mhi_dev->dev); + + mutex_lock(&mhi_wwan_dtr_lock); + list_del(&dtr->node); + mutex_unlock(&mhi_wwan_dtr_lock); + + /* Stop the refill work, and stop a late DL callback re-arming it, before + * the channel is torn down so no requeue can race with the teardown + */ + disable_delayed_work_sync(&dtr->rx_refill); + mhi_unprepare_from_transfer(mhi_dev); + kfree(dtr->rx_buf); + kfree(dtr); +} + static const struct mhi_device_id mhi_wwan_ctrl_match_table[] = { { .chan = "DUN", .driver_data = WWAN_PORT_AT }, { .chan = "DUN2", .driver_data = WWAN_PORT_AT }, @@ -278,7 +500,45 @@ static struct mhi_driver mhi_wwan_ctrl_driver = { }, }; -module_mhi_driver(mhi_wwan_ctrl_driver); +static const struct mhi_device_id mhi_wwan_dtr_match_table[] = { + { .chan = "IP_CTRL" }, + {}, +}; +MODULE_DEVICE_TABLE(mhi, mhi_wwan_dtr_match_table); + +static struct mhi_driver mhi_wwan_dtr_driver = { + .id_table = mhi_wwan_dtr_match_table, + .remove = mhi_wwan_dtr_remove, + .probe = mhi_wwan_dtr_probe, + .ul_xfer_cb = mhi_wwan_dtr_ul_xfer_cb, + .dl_xfer_cb = mhi_wwan_dtr_dl_xfer_cb, + .driver = { + .name = "mhi_wwan_dtr", + }, +}; + +static int __init mhi_wwan_ctrl_init(void) +{ + int ret; + + ret = mhi_driver_register(&mhi_wwan_dtr_driver); + if (ret) + return ret; + + ret = mhi_driver_register(&mhi_wwan_ctrl_driver); + if (ret) + mhi_driver_unregister(&mhi_wwan_dtr_driver); + + return ret; +} +module_init(mhi_wwan_ctrl_init); + +static void __exit mhi_wwan_ctrl_exit(void) +{ + mhi_driver_unregister(&mhi_wwan_ctrl_driver); + mhi_driver_unregister(&mhi_wwan_dtr_driver); +} +module_exit(mhi_wwan_ctrl_exit); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("MHI WWAN CTRL Driver"); From 14c0350142ab0a10ebeefed03b779df23749e16a Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Thu, 15 Oct 2026 14:47:48 +0200 Subject: [PATCH 1968/2126] net: openvswitch: skip IPv4 later fragments on TCP/UDP set actions An IPv4 later fragment carries no L4 header, but key extraction leaves ip.proto set to the real protocol and the flow may wildcard the frag field, so validate_set() accepts such packets. set_tcp() and set_udp() then treat the first bytes of the fragment payload as an L4 header, rewrite them as ports and patch the bytes at the checksum offset, corrupting the packet. Skip these actions for OVS_FRAG_TYPE_LATER. IPv6 later fragments are not affected, since their ip.proto is NEXTHDR_FRAGMENT and validate_set() rejects L4 set actions for them. Fixes: ccb1352e76cf ("net: Add Open vSwitch kernel components.") Signed-off-by: Fernando Fernandez Mancera Reviewed-by: Ilya Maximets Link: https://patch.msgid.link/20261015124749.4694-1-fmancera@suse.de Signed-off-by: Jakub Kicinski --- net/openvswitch/actions.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 27152bca8a8c..4aade471afc4 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -595,6 +595,9 @@ static int set_udp(struct sk_buff *skb, struct sw_flow_key *flow_key, __be16 src, dst; int err; + if (flow_key->ip.frag == OVS_FRAG_TYPE_LATER) + return 0; + err = skb_ensure_writable(skb, skb_transport_offset(skb) + sizeof(struct udphdr)); if (unlikely(err)) @@ -638,6 +641,9 @@ static int set_tcp(struct sk_buff *skb, struct sw_flow_key *flow_key, __be16 src, dst; int err; + if (flow_key->ip.frag == OVS_FRAG_TYPE_LATER) + return 0; + err = skb_ensure_writable(skb, skb_transport_offset(skb) + sizeof(struct tcphdr)); if (unlikely(err)) From 4d0d8f491307f22aea34b22f73351e1cd2ede735 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Thu, 15 Oct 2026 14:47:49 +0200 Subject: [PATCH 1969/2126] net: openvswitch: drop IP fragments on SCTP set action The SCTP checksum is a CRC32c over the whole SCTP packet. set_sctp() updates it as old_csum ^ old_correct_csum ^ new_csum, with the two CRCs computed over the bytes of the current skb only. That is correct only when the skb holds the whole SCTP packet. For a first fragment, and for a later fragment, it holds just a part of it, and the CRC delta of a change at the start of the packet depends on how many bytes follow, so the checksum written is wrong. The receiver drops the reassembled packet. validate_set() accepts SCTP set action for any flow with ip.proto set to SCTP, regardless of the fragmentation bits, as it only receives the masked key. As the checksum cannot be fixed up without the whole datagram, fail the action for packets that are IP fragments of either family, so the packet is dropped with OVS_DROP_ACTION_ERROR instead of being forwarded with modified ports and an invalid checksum. Link: https://lore.kernel.org/netdev/d4fc14f3-4308-4560-9012-43c09c1b3845@ovn.org/ Fixes: a175a723301a ("openvswitch: Add SCTP support") Signed-off-by: Fernando Fernandez Mancera Reviewed-by: Ilya Maximets Link: https://patch.msgid.link/20261015124749.4694-2-fmancera@suse.de Signed-off-by: Jakub Kicinski --- net/openvswitch/actions.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 4aade471afc4..12e339cbf791 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -674,6 +674,9 @@ static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key, __le32 old_correct_csum, new_csum, old_csum; int err; + if (flow_key->ip.frag != OVS_FRAG_TYPE_NONE) + return -EINVAL; + err = skb_ensure_writable(skb, sctphoff + sizeof(struct sctphdr)); if (unlikely(err)) return err; From 03977f8f1a6322749d91c870b4b4eae2b9cd4ced Mon Sep 17 00:00:00 2001 From: Thomas Fourier Date: Thu, 15 Oct 2026 14:45:46 +0200 Subject: [PATCH 1970/2126] drivers: net: xgene: Fix dma_unmap_single() size In xgene_enet_refill_bufpool(), the skb->data is dma-mapped with length len which is set to XGENE_ENET_STD_MTU which equals 1536. However, in xgene_enet_delete_bufpool(), the same buffer is unmapped with length XGENE_ENET_MAX_MTU which is 9600. This may erroneously unmap other DMA buffers or cause other issues. Change unmap length to XGENE_ENET_STD_MTU. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: a9380b0f7be8 ("drivers: net: xgene: Add support for Jumbo frame") Signed-off-by: Thomas Fourier Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261015124547.29996-2-fourier.thomas@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c index 507db46daf2b..2ddcbf27014e 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c @@ -185,7 +185,7 @@ static void xgene_enet_delete_bufpool(struct xgene_enet_desc_ring *buf_pool) raw_desc = &buf_pool->raw_desc16[i]; dma_addr = GET_VAL(DATAADDR, le64_to_cpu(raw_desc->m1)); - dma_unmap_single(dev, dma_addr, XGENE_ENET_MAX_MTU, + dma_unmap_single(dev, dma_addr, XGENE_ENET_STD_MTU, DMA_FROM_DEVICE); } } From 267bc3f113d8c441f57014c502443686f5d33d57 Mon Sep 17 00:00:00 2001 From: Li RongQing Date: Wed, 14 Oct 2026 09:36:20 +0800 Subject: [PATCH 1971/2126] veth: decide peer queue count from the peer's own attributes veth_newlink() creates the peer netdev from tbp, which points at the nested VETH_INFO_PEER attributes when they are supplied (peer_tb) and only aliases the primary device's tb otherwise. However the queue reduction is gated on the primary device's attributes: err = veth_init_queues(peer, tb); veth_init_queues() checks !tb[IFLA_NUM_{TX,RX}_QUEUES], so for the peer it inspects the wrong attribute set whenever nested peer attributes are used: - If the user requests IFLA_NUM_TX/RX_QUEUES only for the peer, tb carries no such attribute and veth_init_queues() still shrinks the peer's real_num_{tx,rx}_queues back to 1, silently dropping the user's explicit multi-queue request for the peer. - If the user requests the counts only for the primary device, the peer keeps nr_possible_cpus real queues instead of the legacy default of 1. Pass tbp so the peer's queue count is decided from the peer's own attributes. When no nested peer attributes are given tbp aliases tb, so the common case is unchanged. Cc: stable+noautosel@kernel.org # never worked, high regression risk Fixes: 9d3684c24a52 ("veth: create by default nr_possible_cpus queues") Signed-off-by: Li RongQing Link: https://patch.msgid.link/20261014013620.2497-1-lirongqing@baidu.com Signed-off-by: Jakub Kicinski --- drivers/net/veth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index c273073b99f5..8746d0d1f591 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1924,7 +1924,7 @@ static int veth_newlink(struct net_device *dev, priv = netdev_priv(peer); rcu_assign_pointer(priv->peer, dev); netdev_hold(dev, &priv->peer_tracker, GFP_KERNEL); - err = veth_init_queues(peer, tb); + err = veth_init_queues(peer, tbp); if (err) goto err_peer_queues; From ff5a2a7acec1bcd0921f986c8fd1c0285ed97b50 Mon Sep 17 00:00:00 2001 From: Thomas Fourier Date: Thu, 15 Oct 2026 16:01:09 +0200 Subject: [PATCH 1972/2126] net: ethernet: mtk_wed: Fix dma_unmap_single() size In mtk_wed_wo_queue_refill(), the entry->buf is DMA mapped with length q->buf_size which saved in entry->len. However, in mtk_wed_wo_dequeue(), the same buffer is DMA unmapped with length buf_len which is set to SKB_WITH_OVERHEAD(q->buf_size). Change the size to q->buf_size. This was discovered with static analysis and was only compile-tested. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support") Signed-off-by: Thomas Fourier Acked-by: Lorenzo Bianconi Link: https://patch.msgid.link/20261015140110.41988-2-fourier.thomas@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mediatek/mtk_wed_wo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.c b/drivers/net/ethernet/mediatek/mtk_wed_wo.c index 7063c78bd35f..4f720ec53e20 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c +++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c @@ -99,7 +99,6 @@ static void * mtk_wed_wo_dequeue(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, u32 *len, bool flush) { - int buf_len = SKB_WITH_OVERHEAD(q->buf_size); int index = (q->tail + 1) % q->n_desc; struct mtk_wed_wo_queue_entry *entry; struct mtk_wed_wo_queue_desc *desc; @@ -123,7 +122,7 @@ mtk_wed_wo_dequeue(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, u32 *len, *len = FIELD_GET(MTK_WED_WO_CTL_SD_LEN0, le32_to_cpu(READ_ONCE(desc->ctrl))); if (buf) - dma_unmap_single(wo->hw->dev, entry->addr, buf_len, + dma_unmap_single(wo->hw->dev, entry->addr, q->buf_size, DMA_FROM_DEVICE); entry->buf = NULL; From 3e2ca51e7e35dca9ec457f690e2fb490a8cbb320 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Tue, 13 Oct 2026 20:57:28 +0000 Subject: [PATCH 1973/2126] Documentation: networking: switchdev: Replace arp_tbl with arp_table(net). Since commit cda2962b6e2b ("neighbour: Namespacify neigh_tables."), arp_tbl is a template for the per-netns table. Let's apply s/arp_tbl/arp_table(net)/ to switchdev.rst. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261013205816.1642597-2-kuniyu@google.com Signed-off-by: Jakub Kicinski --- Documentation/networking/switchdev.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/switchdev.rst b/Documentation/networking/switchdev.rst index 2966b7122f05..8e8ab6632ffe 100644 --- a/Documentation/networking/switchdev.rst +++ b/Documentation/networking/switchdev.rst @@ -401,14 +401,15 @@ The FIB entry's nexthop list contains the nexthop tuple (gateway, dev), but for the switch device to forward the packet with the correct dst mac address, the nexthop gateways must be resolved to the neighbor's mac address. Neighbor mac address discovery comes via the ARP (or ND) process and is available via the -arp_tbl neighbor table. To resolve the routes nexthop gateways, the driver -should trigger the kernel's neighbor resolution process. See the rocker +arp_table(net) neighbor table. To resolve the routes nexthop gateways, the +driver should trigger the kernel's neighbor resolution process. See the rocker driver's rocker_port_ipv4_resolve() for an example. -The driver can monitor for updates to arp_tbl using the netevent notifier +The driver can monitor for updates to arp_table(net) using the netevent notifier NETEVENT_NEIGH_UPDATE. The device can be programmed with resolved nexthops -for the routes as arp_tbl updates. The driver implements ndo_neigh_destroy -to know when arp_tbl neighbor entries are purged from the port. +for the routes as arp_table(net) updates. The driver implements +ndo_neigh_destroy to know when arp_table(net) neighbor entries are purged from +the port. Device driver expected behavior ------------------------------- From 2335e48461f233d53170dceb91984582f3fe274a Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Tue, 13 Oct 2026 20:57:29 +0000 Subject: [PATCH 1974/2126] selftests: netfilter: Set gc_thresh[123] for gw netns in nft_nat_zones.sh. Since commit cda2962b6e2b ("neighbour: Namespacify neigh_tables."), net.ipv[46].neigh.default.gc_thresh[123] are per-netns attributes. Let's update nft_nat_zones.sh. Note that the number of neighbour entries does not even reach the default gc_thresh1 (128) with the default maxclients=100, and the raised thresholds are only needed for gw netns when maxclients is manually increased (e.g., 2000 as mentioned in the comment). Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261013205816.1642597-3-kuniyu@google.com Signed-off-by: Jakub Kicinski --- .../selftests/net/netfilter/nft_nat_zones.sh | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh index 9f200f80253a..d935c967dd13 100755 --- a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh +++ b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh @@ -31,25 +31,6 @@ ret=0 # NAT Gateway is supposed to do port reallocation for each of the # connections. -v4gc1=$(sysctl -n net.ipv4.neigh.default.gc_thresh1 2>/dev/null) -v4gc2=$(sysctl -n net.ipv4.neigh.default.gc_thresh2 2>/dev/null) -v4gc3=$(sysctl -n net.ipv4.neigh.default.gc_thresh3 2>/dev/null) -v6gc1=$(sysctl -n net.ipv6.neigh.default.gc_thresh1 2>/dev/null) -v6gc2=$(sysctl -n net.ipv6.neigh.default.gc_thresh2 2>/dev/null) -v6gc3=$(sysctl -n net.ipv6.neigh.default.gc_thresh3 2>/dev/null) - -cleanup() -{ - cleanup_all_ns - - sysctl -q net.ipv4.neigh.default.gc_thresh1="$v4gc1" 2>/dev/null - sysctl -q net.ipv4.neigh.default.gc_thresh2="$v4gc2" 2>/dev/null - sysctl -q net.ipv4.neigh.default.gc_thresh3="$v4gc3" 2>/dev/null - sysctl -q net.ipv6.neigh.default.gc_thresh1="$v6gc1" 2>/dev/null - sysctl -q net.ipv6.neigh.default.gc_thresh2="$v6gc2" 2>/dev/null - sysctl -q net.ipv6.neigh.default.gc_thresh3="$v6gc3" 2>/dev/null -} - checktool "nft --version" echo "run test without nft tool" checktool "conntrack -V" "run test without conntrack tool" @@ -59,18 +40,19 @@ fi setup_ns gw srv -trap cleanup EXIT +trap cleanup_all_ns EXIT ip link add veth0 netns "$gw" type veth peer name eth0 netns "$srv" ip -net "$gw" link set veth0 up ip -net "$srv" link set eth0 up -sysctl -q net.ipv6.neigh.default.gc_thresh1=512 2>/dev/null -sysctl -q net.ipv6.neigh.default.gc_thresh2=1024 2>/dev/null -sysctl -q net.ipv6.neigh.default.gc_thresh3=4096 2>/dev/null -sysctl -q net.ipv4.neigh.default.gc_thresh1=512 2>/dev/null -sysctl -q net.ipv4.neigh.default.gc_thresh2=1024 2>/dev/null -sysctl -q net.ipv4.neigh.default.gc_thresh3=4096 2>/dev/null +ip netns exec "$gw" sysctl -q \ + net.ipv6.neigh.default.gc_thresh1=512 \ + net.ipv6.neigh.default.gc_thresh2=1024 \ + net.ipv6.neigh.default.gc_thresh3=4096 \ + net.ipv4.neigh.default.gc_thresh1=512 \ + net.ipv4.neigh.default.gc_thresh2=1024 \ + net.ipv4.neigh.default.gc_thresh3=4096 2>/dev/null for i in $(seq 1 "$maxclients");do setup_ns "cl$i" From 8854b0e247aefcdc80697a12532e59e7ae8a5577 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Tue, 13 Oct 2026 20:57:30 +0000 Subject: [PATCH 1975/2126] neighbour: Schedule neigh_managed_work only when needed. neigh_table is now per-netns. tbl->managed_work is scheduled when netns is created and runs periodically even though the netns does not have any NTF_MANAGED entries. Let's delay scheduling the work for the first NTF_MANAGED entry and stop rescheduling if tbl->managed_list is empty. Suggested-by: Ido Schimmel Link: https://lore.kernel.org/netdev/20260902143023.GA3966681@shredder/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261013205816.1642597-4-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 90335895b415..6b0569aa5d64 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -184,6 +184,15 @@ static void neigh_update_gc_list(struct neighbour *n) } } +static void neigh_add_managed_list(struct neighbour *n) +{ + list_add_tail(&n->managed_list, &n->tbl->managed_list); + + if (list_is_singular(&n->tbl->managed_list)) + queue_delayed_work(system_power_efficient_wq, + &n->tbl->managed_work, 0); +} + static void neigh_update_managed_list(struct neighbour *n) { bool on_managed_list, add_to_managed; @@ -194,7 +203,7 @@ static void neigh_update_managed_list(struct neighbour *n) if (!add_to_managed && on_managed_list) list_del_init(&n->managed_list); else if (add_to_managed && !on_managed_list) - list_add_tail(&n->managed_list, &n->tbl->managed_list); + neigh_add_managed_list(n); } static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify, @@ -708,7 +717,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, if (!exempt_from_gc) list_add_tail(&n->gc_list, &n->tbl->gc_list); if (n->flags & NTF_MANAGED) - list_add_tail(&n->managed_list, &n->tbl->managed_list); + neigh_add_managed_list(n); if (want_ref) neigh_hold(n); hlist_add_head_rcu(&n->hash, &nht->hash_heads[hash_val]); @@ -1670,10 +1679,14 @@ static void neigh_managed_work(struct work_struct *work) struct neighbour *neigh; spin_lock_bh(&tbl->lock); + list_for_each_entry(neigh, &tbl->managed_list, managed_list) neigh_event_send_probe(neigh, NULL, false); - queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, - NEIGH_VAR(&tbl->parms, INTERVAL_PROBE_TIME_MS)); + + if (!list_empty(&tbl->managed_list)) + queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, + NEIGH_VAR(&tbl->parms, INTERVAL_PROBE_TIME_MS)); + spin_unlock_bh(&tbl->lock); } @@ -1873,7 +1886,6 @@ static int neigh_table_init(struct net *net, struct neigh_table *tbl) INIT_LIST_HEAD(&tbl->managed_list); INIT_DEFERRABLE_WORK(&tbl->managed_work, neigh_managed_work); - queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, 0); return 0; From 7a71343ba1a69fee4c50fad47c62c6acbd454492 Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Tue, 13 Oct 2026 20:57:31 +0000 Subject: [PATCH 1976/2126] neighbour: Floor INTERVAL_PROBE_TIME_MS at 1000. Previously, neigh_managed_work() was not rescheduled within 1s since commit ed6cd6a17896 ("net, neigh: Set lower cap for neigh_managed_work rearming"). Later, commit 211da42eaa45 ("net, neigh: introduce interval_probe_time_ms for periodic probe") added INTERVAL_PROBE_TIME_MS and changed the limit to 1ms. The limit actually did not work but was fixed with netlink_range_validation by commit 6d79b223ec44 ("neighbour: Enforce min/max to NDTPA_INTERVAL_PROBE_TIME_MS."). neigh_table is now per-netns, and a user could hog CPU by setting INTERVAL_PROBE_TIME_MS to a small value. Let's floor the value at 1 second. This is a user-visible change, but given we had the 1s floor before and the default is 5s, it is unlikely that anyone but syzbot is setting it below 1s and affected by this change. Suggested-by: Ido Schimmel Link: https://lore.kernel.org/netdev/20260902143023.GA3966681@shredder/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261013205816.1642597-5-kuniyu@google.com Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-neigh.yaml | 2 +- Documentation/networking/ip-sysctl.rst | 2 +- net/core/neighbour.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Documentation/netlink/specs/rt-neigh.yaml b/Documentation/netlink/specs/rt-neigh.yaml index c8e55c98d564..7929e667cc7a 100644 --- a/Documentation/netlink/specs/rt-neigh.yaml +++ b/Documentation/netlink/specs/rt-neigh.yaml @@ -342,7 +342,7 @@ attribute-sets: name: interval-probe-time-ms type: u64 checks: - min: 1 + min: 1000 max: 86400000 operations: diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 685c84cf543d..b00bd77363d7 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -248,7 +248,7 @@ neigh/default/unres_qlen - INTEGER neigh/default/interval_probe_time_ms - INTEGER The probe interval for neighbor entries with NTF_MANAGED flag, - the min value is 1, and the max value is 86400000 (1 day). + the min value is 1000 (1s), and the max value is 86400000 (1 day). Default: 5000 diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6b0569aa5d64..aa3da886eaab 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -2435,10 +2435,11 @@ static const struct nla_policy nl_neightbl_policy[NDTA_MAX+1] = { [NDTA_PARMS] = { .type = NLA_NESTED }, }; +#define NTBL_PARM_MS_MIN MSEC_PER_SEC #define NTBL_PARM_MS_MAX (24 * 60 * 60 * MSEC_PER_SEC) static const struct netlink_range_validation nl_ntbl_parm_ms_range = { - .min = 1, + .min = NTBL_PARM_MS_MIN, .max = NTBL_PARM_MS_MAX, }; @@ -3701,7 +3702,7 @@ static int neigh_proc_dointvec_ms_jiffies_positive(const struct ctl_table *ctl, struct ctl_table tmp = *ctl; int ret, min, max; - min = msecs_to_jiffies(1); + min = msecs_to_jiffies(NTBL_PARM_MS_MIN); max = msecs_to_jiffies(NTBL_PARM_MS_MAX); tmp.extra1 = &min; From ccd0742641dcbfd7ceab49fba841211be204e12b Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Tue, 13 Oct 2026 20:57:32 +0000 Subject: [PATCH 1977/2126] neighbour: Floor neigh_periodic_work() interval at 1s. neigh_periodic_work() reschedules tbl->gc_work with a delay of BASE_REACHABLE_TIME >> 1. neigh_table is now per-netns, and a user could hog CPU by setting BASE_REACHABLE_TIME to a small value. Unlike INTERVAL_PROBE_TIME_MS, BASE_REACHABLE_TIME is also used to compute reachable_time for NUD_REACHABLE entries. Let's floor only the GC interval at 1 second. Suggested-by: Ido Schimmel Link: https://lore.kernel.org/netdev/20260902143023.GA3966681@shredder/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261013205816.1642597-6-kuniyu@google.com Signed-off-by: Jakub Kicinski --- net/core/neighbour.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index aa3da886eaab..d6e9c7c59a89 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1042,12 +1042,12 @@ static void neigh_periodic_work(struct work_struct *work) lockdep_is_held(&tbl->lock)); } out: - /* Cycle through all hash buckets every BASE_REACHABLE_TIME/2 ticks. + /* Cycle through all hash buckets every max(HZ, BASE_REACHABLE_TIME/2) ticks. * ARP entry timeouts range from 1/2 BASE_REACHABLE_TIME to 3/2 * BASE_REACHABLE_TIME. */ queue_delayed_work(system_power_efficient_wq, &tbl->gc_work, - NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1); + max(HZ, NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1)); spin_unlock_bh(&tbl->lock); } From cb790252f8e13741ba9e13d100cb3c25b7545506 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 13 Oct 2026 18:25:06 +0000 Subject: [PATCH 1978/2126] net: axienet: don't advance the TX ring head before the descriptor is ready axienet_start_xmit_dmaengine() bumps lp->tx_ring_head before skb_to_sgvec(), dma_map_sg() and device_prep_slave_sg(), and none of their error paths undo it. The skb is freed and nothing is submitted, but the slot stays claimed. axienet_dma_tx_cb() walks tx_ring_tail once per completion, so the next completion lands on the abandoned slot and dereferences whatever skb pointer is left there: NULL if the slot was never used or was already completed, or a stale skb that gets consumed a second time. Every completion after that is accounted against the wrong slot. dma_map_sg() and device_prep_slave_sg() can fail at runtime, and so can skb_to_sgvec() on a malformed skb. Only advance tx_ring_head once those have succeeded. The completion callback can't run before dmaengine_submit(), so claiming the slot just before that is fine. dmaengine_submit() itself can also fail on xilinx_dma after a channel error, and its return isn't checked either. That's a separate problem and isn't changed here. This was found by the Sashiko AI review of the skbuff BUG_ON() series. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: 6a91b846af85 ("net: axienet: Introduce dmaengine support") Link: https://lore.kernel.org/all/20261007-b4-skbuff-bug-on-v2-0-b9a5f732895b@toxicpanda.com/ Signed-off-by: Josef Bacik Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261013-b4-axienet-dmaengine-ring-head-v1-1-7add24e74477@toxicpanda.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 919e644d9158..57fcb08ff3df 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -979,7 +979,6 @@ axienet_start_xmit_dmaengine(struct sk_buff *skb, struct net_device *ndev) if (!skbuf_dma) goto xmit_error_drop_skb; - lp->tx_ring_head++; sg_init_table(skbuf_dma->sgl, sg_len); ret = skb_to_sgvec(skb, skbuf_dma->sgl, 0, skb->len); if (ret < 0) @@ -1015,6 +1014,10 @@ axienet_start_xmit_dmaengine(struct sk_buff *skb, struct net_device *ndev) skbuf_dma->sg_len = sg_len; dma_tx_desc->callback_param = lp; dma_tx_desc->callback_result = axienet_dma_tx_cb; + /* Claim the ring slot only after the steps above that can fail. The + * completion callback can't run before dmaengine_submit(). + */ + lp->tx_ring_head++; txq = skb_get_tx_queue(lp->ndev, skb); netdev_tx_sent_queue(txq, skb->len); netif_txq_maybe_stop(txq, CIRC_SPACE(lp->tx_ring_head, lp->tx_ring_tail, TX_BD_NUM_MAX), From 56f8d919739b588e2ad8cb9fb9eff704f32afaab Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Thu, 15 Oct 2026 10:00:03 -0700 Subject: [PATCH 1979/2126] netdev: Hide the netdev_priv() origin from GCC in netdev_from_priv() GCC 15.1 and later can compute an object size of 0 for a pointer that container_of() derives from a pointer into a __counted_by flexible array member[1]; Clang gets it right. netdev_from_priv() does this with struct net_device's "priv" array, so when GCC can see that its argument came from netdev_priv(), FORTIFY_SOURCE sees a zero-sized net_device. Since commit 9027497a25e3c ("team: use netdev_from_priv()"), adding a port of another type to a team device can then fail the memcpy() to "dev->broadcast" in team_setup_by_port(), which GCC sees through after inlining team_port_add() into team_add_slave(): memcpy: detected buffer overflow: 4 byte write of buffer size 0 ... kernel BUG at lib/string_helpers.c:1044! ... Call Trace: team_add_slave.cold+0x88/0x201 do_set_master+0x11c/0x180 do_setlink.isra.0+0x3a4/0x1410 Whether GCC inlines that far depends on the architecture and the configuration. It does on ppc64le, where this was reported, and on x86_64 with defconfig plus hardening.config or with Debian's configuration, but not with allmodconfig. Hide where "priv" came from with OPTIMIZER_HIDE_VAR(), so GCC sees a net_device of unknown size whose members have their declared sizes. (An "unknown" size is considered uncheckable by FORTIFY.) FORTIFY still bounds writes to members; only the whole-object size becomes unknown, as it already is for any net_device pointer GCC can't trace to its allocation. In an extracted PoC, the __builtin_dynamic_object_size() of "dev->broadcast" for the two types FORTIFY sees, before and after this patch: GCC 16.2.0 Clang 22 and 24 before after plain pointer, whole object unknown unknown 44 container_of(), whole object 0 unknown 44 container_of(), member 0 32 32 In addition to getting the bogus "0" fixed in GCC, I'll be following up to solve the whole-object visiblity disparity as well. Build tested with GCC 16.2.0: ARCH=x86_64 defconfig with hardening.config, CONFIG_NET_TEAM=y, and CONFIG_NET_IPGRE=y; ARCH=arm64 defconfig with hardening.config, CONFIG_NET_TEAM=y, CONFIG_PPP=y, and CONFIG_NET_AIROHA=m; and drivers/net/team/, drivers/net/ppp/, and drivers/net/ethernet/airoha/ in ARCH=x86_64 allmodconfig. Under QEMU, the x86_64 kernel hits the BUG above when adding the GRE fallback device "gre0" as a port of a new team device without this patch, and adds it with the patch. Reported-by: Yeswanth Krishna Tellakula Closes: https://lore.kernel.org/all/3ad19e86-234c-408f-896e-0d6c774fea49@linux.ibm.com/ Fixes: 9027497a25e3c ("team: use netdev_from_priv()") Cc: stable@vger.kernel.org Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127875 [1] Signed-off-by: Kees Cook Link: https://patch.msgid.link/20261015165959.i.798-kees@kernel.org Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8fbe3a5d8169..f064c9c989ee 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2841,6 +2841,13 @@ static inline void *netdev_priv(const struct net_device *dev) */ static inline struct net_device *netdev_from_priv(const void *priv) { + /* + * When GCC can see that @priv came from netdev_priv(), it can + * compute an object size of 0 for the net_device and its members, + * which makes FORTIFY_SOURCE fail valid accesses through the result: + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127875 + */ + OPTIMIZER_HIDE_VAR(priv); return container_of(priv, struct net_device, priv); } From 6ace56ed7b13a9c6d4cb7ef0d82d3a3d53324a63 Mon Sep 17 00:00:00 2001 From: Daehyeon Ko <4ncienth@gmail.com> Date: Thu, 15 Oct 2026 14:06:48 +0900 Subject: [PATCH 1980/2126] ipv6: remove ifaddr from hash during ifdown list cleanup addrconf_ifdown() clears the address hash before snapshotting the per-device address list. A concurrent ipv6_add_addr() can publish an address after the hash scan and before the list snapshot. The ifdown path then removes the address from the device list and drops the list-owned reference while it is still linked in the hash. Once the remaining references are released, inet6_ifa_finish_destroy() warns, but a DEAD address continues to kfree_rcu(). The hash therefore points to freed memory that later RCU walkers can dereference. This follow-on was found by source review and was not separately triggered at runtime. Remove each non-kept address from the hash immediately before removing it from the per-device list. Keeping it hashed through the delete notification blocks same-address publication until NETDEV_DOWN has been delivered. hlist_del_init_rcu() is safe when the earlier hash scan already removed the address. This handles a late publisher captured by the list snapshot. The next change serializes publication with teardown so an add cannot miss both observations. Both changes are required when backporting the complete fix. Fixes: 73a8bd74e261 ("ipv6: Revert 'administrative down' address handling changes.") Cc: stable@vger.kernel.org Reported-by: Ido Schimmel Link: https://lore.kernel.org/r/20261004135117.GA206930@shredder Link: https://lore.kernel.org/r/179161099539.434549.2238120015372268173@kernel.org Suggested-by: Ido Schimmel Signed-off-by: Daehyeon Ko <4ncienth@gmail.com> Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261015050651.1841557-2-4ncienth@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/addrconf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index c90ee6dd7446..72d7df23f796 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4019,6 +4019,10 @@ restart: } if (!keep) { + spin_lock_bh(&net->ipv6.addrconf_hash_lock); + hlist_del_init_rcu(&ifa->addr_lst); + spin_unlock_bh(&net->ipv6.addrconf_hash_lock); + write_lock_bh(&idev->lock); list_del_rcu(&ifa->if_list); write_unlock_bh(&idev->lock); From 06227034e2d93942119b922cf05f2de9da0ad848 Mon Sep 17 00:00:00 2001 From: Daehyeon Ko <4ncienth@gmail.com> Date: Thu, 15 Oct 2026 14:06:49 +0900 Subject: [PATCH 1981/2126] ipv6: serialize address publication with device teardown ipv6_add_addr() checks idev state before allocating an ifaddr, but publishes the object later. addrconf_ifdown() can mark and detach the idev between the check and publication. This happens when a non-loopback device MTU falls below IPV6_MIN_MTU. A forced interleaving published an address on a dead idev, and ipv6_get_ifaddr() still returned it after teardown. Later device deletion remained blocked with: unregister_netdevice: waiting for ac0 to become free. Usage count = 3 Protect the dead indication with idev->lock and keep that lock across both hash and device-list publication. Recheck dead before publishing; if teardown wins the lock, reject the unpublished object. Non-unregister teardown does not set dead. The preceding change covers an add that misses the initial hash scan but reaches the per-device list snapshot. Both changes are required when backporting this fix. Fixes: 8814c4b53381 ("[IPV6] ADDRCONF: Convert addrconf_lock to RCU.") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/179161099408.434549.14449036924552933828@kernel.org Link: https://lore.kernel.org/r/20261012145306.GB779501@shredder Suggested-by: Ido Schimmel Signed-off-by: Daehyeon Ko <4ncienth@gmail.com> Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261015050651.1841557-3-4ncienth@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/addrconf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 72d7df23f796..3bede30d4e98 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1168,14 +1168,18 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, rcu_read_lock(); - err = ipv6_add_addr_hash(idev->dev, ifa); + write_lock_bh(&idev->lock); + + if (idev->dead) + err = -ENODEV; + else + err = ipv6_add_addr_hash(idev->dev, ifa); if (err < 0) { + write_unlock_bh(&idev->lock); rcu_read_unlock(); goto out; } - write_lock_bh(&idev->lock); - /* Add to inet6_dev unicast addr list. */ ipv6_link_dev_addr(idev, ifa); @@ -3897,7 +3901,9 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) * Do not dev_put! */ if (unregister) { + write_lock_bh(&idev->lock); WRITE_ONCE(idev->dead, 1); + write_unlock_bh(&idev->lock); /* protected by rtnl_lock */ RCU_INIT_POINTER(dev->ip6_ptr, NULL); From ed7f278812e540db507f683e5bf9b6d0a1f5bc1e Mon Sep 17 00:00:00 2001 From: Daehyeon Ko <4ncienth@gmail.com> Date: Thu, 15 Oct 2026 14:06:50 +0900 Subject: [PATCH 1982/2126] ipv6: initialize temporary ifaddr before publication ipv6_create_tempaddr() holds a reference to the public ifaddr, publishes the new temporary address through ipv6_add_addr(), and only then stores the reference and final timestamps. addrconf_ifdown() can remove the temporary address before ifpub is stored, leaking the public ifaddr reference. Publishing ifpub alone is insufficient: manage_tempaddrs() can then find the object before cstamp and tstamp are final, update its lifetimes, and have the constructor overwrite its timestamp with an older value. This follow-on was found by source review and was not separately triggered at runtime. Pass the public ifaddr and both timestamps in ifa6_config. Initialize all three fields before adding the temporary address to either the hash or per-device lists. On success the existing public-ifaddr reference transfers to the temporary object. On error it remains owned and released by ipv6_create_tempaddr(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://lore.kernel.org/r/179122559913.434549.12720841717630168470@kernel.org Link: https://lore.kernel.org/r/179161099665.434549.5858601179492551889@kernel.org Link: https://lore.kernel.org/r/20261007164548.GA1153540@shredder Link: https://lore.kernel.org/r/20261012145240.GA779501@shredder Suggested-by: Ido Schimmel Signed-off-by: Daehyeon Ko <4ncienth@gmail.com> Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261015050651.1841557-4-4ncienth@gmail.com Signed-off-by: Jakub Kicinski --- include/net/addrconf.h | 3 +++ net/ipv6/addrconf.c | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/net/addrconf.h b/include/net/addrconf.h index e6764245995f..6818057cf727 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h @@ -81,6 +81,9 @@ struct ifa6_config { u8 ifa_proto; const struct in6_addr *peer_pfx; + struct inet6_ifaddr *ifpub; + unsigned long cstamp; + unsigned long tstamp; u32 rt_priority; u32 ifa_flags; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 3bede30d4e98..df5666812261 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1155,10 +1155,19 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, ifa->flags |= IFA_F_TENTATIVE; ifa->valid_lft = cfg->valid_lft; ifa->prefered_lft = cfg->preferred_lft; - ifa->cstamp = ifa->tstamp = jiffies; ifa->tokenized = false; ifa->rt = f6i; + ifa->ifpub = cfg->ifpub; + if (cfg->ifpub) { + ifa->cstamp = cfg->cstamp; + ifa->tstamp = cfg->tstamp; + } else { + unsigned long now = jiffies; + + ifa->cstamp = now; + ifa->tstamp = now; + } ifa->idev = idev; in6_dev_hold(idev); @@ -1491,6 +1500,9 @@ retry: cfg.pfx = &addr; cfg.scope = ipv6_addr_scope(cfg.pfx); + cfg.ifpub = ifp; + cfg.cstamp = now; + cfg.tstamp = tmp_tstamp; ift = ipv6_add_addr(idev, &cfg, block, NULL); if (IS_ERR(ift)) { @@ -1501,12 +1513,6 @@ retry: goto retry; } - spin_lock_bh(&ift->lock); - ift->ifpub = ifp; - ift->cstamp = now; - ift->tstamp = tmp_tstamp; - spin_unlock_bh(&ift->lock); - addrconf_dad_start(ift); in6_ifa_put(ift); in6_dev_put(idev); From ffb668669ce4144347973d8b2fad449e9be0563d Mon Sep 17 00:00:00 2001 From: Daehyeon Ko <4ncienth@gmail.com> Date: Thu, 15 Oct 2026 14:06:51 +0900 Subject: [PATCH 1983/2126] ipv6: do not restart DAD for a dead ifaddr addrconf_dad_failure() can create a stable-privacy replacement without RTNL. After ipv6_add_addr() publishes it, addrconf_ifdown() can mark the new ifaddr DEAD, clear its route, and unlink it before the recovery path takes ifp2->lock. The recovery path then unconditionally changes the state back to PREDAD and queues delayed DAD work. The MTU teardown path can leave IF_READY set. For an optimistic address, addrconf_dad_begin() can consequently pass the cleared NULL route to ip6_ins_rt(). This follow-on was found by source review and was not separately triggered at runtime. The new ifaddr is already initialized in PREDAD. Under ifp2->lock, record the retry and queue DAD only if teardown has not changed the state to DEAD. If teardown wins after this check, the work observes DEAD and exits without reviving the address. This complements the existing lock_errdad check that preserves the original ifaddr's DEAD state after the same function reacquires its lock. Fixes: 5f40ef77adb2 ("ipv6: do retries on stable privacy addresses") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://lore.kernel.org/r/179161099408.434549.14449036924552933828@kernel.org Link: https://lore.kernel.org/r/20260513025509.3776405-1-lilinmao@kylinos.cn Signed-off-by: Daehyeon Ko <4ncienth@gmail.com> Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261015050651.1841557-5-4ncienth@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/addrconf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index df5666812261..a2d3fb187f76 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -2198,6 +2198,7 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) ifp->idev->dev->name, &ifp->addr, eth_hdr(skb)->h_source); if (ifp->flags & IFA_F_STABLE_PRIVACY) { + bool start_dad = false; struct in6_addr new_addr; struct inet6_ifaddr *ifp2; int retries = ifp->stable_privacy_retry + 1; @@ -2236,11 +2237,14 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) goto lock_errdad; spin_lock_bh(&ifp2->lock); - ifp2->stable_privacy_retry = retries; - ifp2->state = INET6_IFADDR_STATE_PREDAD; + if (ifp2->state != INET6_IFADDR_STATE_DEAD) { + ifp2->stable_privacy_retry = retries; + start_dad = true; + } spin_unlock_bh(&ifp2->lock); - addrconf_mod_dad_work(ifp2, net->ipv6.sysctl.idgen_delay); + if (start_dad) + addrconf_mod_dad_work(ifp2, net->ipv6.sysctl.idgen_delay); in6_ifa_put(ifp2); lock_errdad: spin_lock_bh(&ifp->lock); From 504bdcb8c1566a6f887f9accebe1aa99b502ae97 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 16 Oct 2026 10:48:02 +0200 Subject: [PATCH 1984/2126] tcp: tcp_metrics: use the socket netns, not the dst device netns tcp_get_metrics(), __tcp_get_metrics_req() and tcpm_new() look up and create metrics entries in the netns of the cached dst device rather than in the netns of the socket. These usually match, but not after the device has been moved to another netns or unregistered: a socket can keep a stale dst in sk_dst_cache until it is checked again, and tcp_update_metrics() reads it with __sk_dst_get() without any dst_check(). Once dst_dev_put() has run, the dst device is blackhole_netdev and the entry is created in init_net. Before that, for instance for routes through nexthop objects whose cached dsts are released from a nested RCU callback, it is the netns the device has just been moved to. A TCP socket of netns A that enters TIME_WAIT in that window then creates or updates an entry carrying A's addresses and RTT in another netns, where TCP_METRICS_CMD_GET can dump it and where new connections to the same peer inherit those metrics. The metrics belong to the netns of the socket, so use sock_net() for full sockets and request sockets, and pass it to tcpm_new(). Kernel sockets that do not hold a netns reference can still reach tcp_time_wait() after tcp_net_metrics_exit_batch() has flushed the entries of their dismantling netns, and an entry created then would never be flushed and would keep a dangling tcpm_net. Make tcpm_new() refuse to create entries when check_net() fails. Its callers are in an RCU read-side section, and cleanup_net() waits for a grace period between the refcount reaching zero and the flush, so an entry added after a successful check is always seen by the flush. Fixes: 51c5d0c4b169 ("tcp: Maintain dynamic metrics in local cache.") Signed-off-by: Eric Dumazet Cc: Qiliang Yuan Reviewed-by: Neal Cardwell Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261016084802.2725187-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ipv4/tcp_metrics.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index dc0c081fc1f3..d58f99c67d4d 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -161,16 +161,26 @@ static void tcpm_check_stamp(struct tcp_metrics_block *tm, rcu_dereference_protected(p, lockdep_is_held(&tcp_metrics_lock)) static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, + struct net *net, struct inetpeer_addr *saddr, struct inetpeer_addr *daddr, unsigned int hash) { struct tcp_metrics_block *tm; bool reclaim = false; - struct net *net; spin_lock_bh(&tcp_metrics_lock); - net = dst_dev_net_rcu(dst); + + /* Do not add entries to a dismantling netns: they would not be + * flushed again. Callers are in an RCU read-side section, and + * cleanup_net() waits for a grace period after the netns refcount + * reached zero and before tcp_metrics_flush_all(NULL) runs, so an + * entry added after a successful check_net() is seen by the flush. + */ + if (unlikely(!check_net(net))) { + tm = NULL; + goto out_unlock; + } /* While waiting for the spin-lock the cache might have been populated * with this entry and so we have to check again. @@ -273,7 +283,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req, return NULL; } - net = dst_dev_net_rcu(dst); + net = sock_net(req_to_sk(req)); hash ^= net_hash_mix(net); hash = hash_32(hash, tcp_metrics_hash_log); @@ -318,7 +328,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, else return NULL; - net = dst_dev_net_rcu(dst); + net = sock_net(sk); hash ^= net_hash_mix(net); hash = hash_32(hash, tcp_metrics_hash_log); @@ -326,7 +336,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, if (tm == TCP_METRICS_RECLAIM_PTR) tm = NULL; if (!tm && create) - tm = tcpm_new(dst, &saddr, &daddr, hash); + tm = tcpm_new(dst, net, &saddr, &daddr, hash); else tcpm_check_stamp(tm, dst); From f89a228125238f8d4c7e2b8161e2a85fe35307b6 Mon Sep 17 00:00:00 2001 From: Rishikesh Jethwani Date: Tue, 13 Oct 2026 15:35:17 -0600 Subject: [PATCH 1985/2126] tls: device: protect async RX resync state during device-down tls_device_rx_resync_new_rec() can run in process context with the socket lock held, but without an RCU read lock: from the strparser work item (tls_strp_work()) and from the receive paths (tls_rx_rec_wait(), tls_rx_rec_done()). The resync_async pointer belongs to the driver RX context, which tls_device_down() tears down from the netdev notifier without taking the socket lock; only the softirq entry to the parser is implicitly inside an RCU section. If the parser passes the TLS_RX_DEV_DEGRADED check before device-down sets it, tls_device_down() can complete synchronize_net() and delete the driver context before the parser accesses resync_async->req or its record log. In the asynchronous stage the parser also writes the record log, so this is a write to freed memory, not only a stale read. The RCU section in tls_device_resync_rx() starts after those accesses and therefore does not prevent the use-after-free. Found by code inspection; not reproduced. Hitting the window requires the parser to be preempted between the DEGRADED check and the resync_async access across the device-down grace period and the driver's teardown. Fixes: ed9b7646b06a ("net/tls: Add asynchronous resync") Signed-off-by: Rishikesh Jethwani Link: https://patch.msgid.link/20261013213517.2219663-1-rjethwani@purestorage.com Signed-off-by: Jakub Kicinski --- net/tls/tls_device.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index b333a9a72cda..2382d00aef8f 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -783,8 +783,15 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) if (tls_ctx->rx_conf != TLS_HW) return; + + /* The parser also runs in process context, without an RCU read lock. + * Protect the driver's resync_async state before checking the flags: + * device-down sets DEGRADED and waits for synchronize_net() before + * freeing it, without taking the socket lock. + */ + rcu_read_lock(); if (unlikely(test_bit(TLS_RX_DEV_DEGRADED, &tls_ctx->flags))) - return; + goto out; prot = &tls_ctx->prot_info; rx_ctx = tls_offload_ctx_rx(tls_ctx); @@ -799,11 +806,11 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) if (likely(!is_req_pending) || req_seq != seq || !atomic64_try_cmpxchg(&rx_ctx->resync_req, &resync_req, 0)) - return; + goto out; break; case TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT: if (likely(!rx_ctx->resync_nh_do_now)) - return; + goto out; /* head of next rec is already in, note that the sock_inq will * include the currently parsed message when called from parser @@ -812,7 +819,7 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) if (sock_data > rcd_len) { trace_tls_device_rx_resync_nh_delay(sk, sock_data, rcd_len); - return; + goto out; } rx_ctx->resync_nh_do_now = 0; @@ -823,16 +830,18 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) resync_req = atomic64_read(&rx_ctx->resync_async->req); is_req_pending = resync_req; if (likely(!is_req_pending)) - return; + goto out; if (!tls_device_rx_resync_async(rx_ctx->resync_async, resync_req, &seq, &rcd_delta)) - return; + goto out; tls_bigint_subtract(rcd_sn, rcd_delta); break; } tls_device_resync_rx(tls_ctx, sk, seq, rcd_sn); +out: + rcu_read_unlock(); } static void tls_device_core_ctrl_rx_resync(struct tls_context *tls_ctx, From dcaa6219648955f7a8160313f1685321dbd1bf28 Mon Sep 17 00:00:00 2001 From: Binbin Deng <18983559317@163.com> Date: Wed, 14 Oct 2026 14:42:04 +0800 Subject: [PATCH 1986/2126] octeontx2: Fix use-after-free of qos node in delete path hash_del_rcu() only unlinks the node; a reader that already holds the bucket iterator still uses the node. The immediate kfree() has no grace period, so a concurrent transmit on a socket whose skb priority carries the deleted classid reads node->classid / node->qid from freed memory (use-after-free in the softirq transmit path). Fix this by calling synchronize_net() before the node is freed, as mlx5e does. Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only. Fixes: 5e6808b4c68d ("octeontx2-pf: Add support for HTB offload") Signed-off-by: Binbin Deng <18983559317@163.com> Reviewed-by: Ratheesh Kannoth Link: https://patch.msgid.link/20261014064204.291688-1-18983559317@163.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/marvell/octeontx2/nic/qos.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos.c index f160b1618efa..2ede0b84e5f5 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/qos.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos.c @@ -331,6 +331,8 @@ static void otx2_qos_sw_node_delete(struct otx2_nic *pfvf, otx2_qos_update_tx_netdev_queues(pfvf); } + synchronize_net(); + list_del(&node->list); kfree(node); } From 106e562966a02f61917c2e0b83909aa2b088447f Mon Sep 17 00:00:00 2001 From: Anirudh Virdi Date: Tue, 13 Oct 2026 16:24:51 +0530 Subject: [PATCH 1987/2126] net: qede: initialize extack in qede_flow_spec_to_rule() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qede_flow_spec_to_rule() declares a netlink_ext_ack on the stack without initializing it. qede_parse_flow_attr() and qede_flow_spec_validate() only set extack._msg on error paths via NL_SET_ERR_MSG_MOD(), so on a successful parse the err_out block reads an uninitialized pointer. If that garbage happens to be non-NULL, DP_NOTICE("%s", extack._msg) dereferences it inside vsnprintf, causing a page fault and kernel panic. This manifests when configuring ethtool ntuple flow rules (ethtool -U flow-type tcp4/udp4) on kernels built with CONFIG_INIT_STACK_NONE=y. With CONFIG_INIT_STACK_ALL_ZERO=y the bug is masked because the compiler zero-initializes extack, making _msg NULL. Reproduced on RHEL 9.8 (kernel-5.14.0-687.47.1.el9_8) and mainline (v7.3-rc6) with the following reproducer: IFACE=ens2f0 ip link set $IFACE up ethtool -K $IFACE ntuple on for i in $(seq 1 100); do ethtool -U $IFACE flow-type udp4 src-ip 192.168.2.$i action -1 done The loop panics reliably after 10-15 iterations with: BUG: unable to handle page fault RIP: string+0x49/0xd0 Call Trace: vsnprintf qede_flow_spec_to_rule+0x2b6/0x4b0 [qede] qede_add_cls_rule ethtool_set_rxnfc Zero-initialize extack so _msg is NULL unless explicitly set by an error path. Fixes: eb705d734525 ("net: qede: use faked extack in qede_flow_spec_to_rule()") Signed-off-by: Anirudh Virdi Reviewed-by: Asbjørn Sloth Tønnesen Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261013105451.201211-1-avirdi@redhat.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qlogic/qede/qede_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c index ab8b818588e2..5bf32f1034e0 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c @@ -1991,8 +1991,8 @@ static int qede_flow_spec_to_rule(struct qede_dev *edev, struct ethtool_rx_flow_spec *fs) { struct ethtool_rx_flow_spec_input input = {}; + struct netlink_ext_ack extack = {}; struct ethtool_rx_flow_rule *flow; - struct netlink_ext_ack extack; __be16 proto; int err; From ed9e404dcf9b7bd0bf319bccbdf7ddf90f96dbbb Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 13 Oct 2026 04:54:27 -0400 Subject: [PATCH 1988/2126] net/sched: act_gate: reject oversized dumps instead of wrapping them This is a followup of commit cfa165cbfbed ("net/sched: act_gate: budget the per-entry list in get_fill_size") as reported by Sashiko. The issue: An action dump is carried inside nested netlink attributes whose lengths are u16. A gate action with enough schedule entries produces a dump larger than U16_MAX, and the plain nla_nest_end() closes by writing a wrapped length: the reply is structurally corrupt. On a CONFIG_DEBUG_NET kernel a plain nla_nest_end() also warns (DEBUG_NET_WARN_ON_ONCE warns once per call site), which an unprivileged RTM_GETACTION or RTM_GETTFILTER can reach once the action or filter exists. The oversized dump also reaches the filter notification path through tcf_fill_node(), which reports the failure as -EMSGSIZE. tfilter_notify_prep() treats that as socket-buffer exhaustion and retries with an ever larger alloc_skb(); a dump that does not fit a u16 nest cannot be built at any skb size, so the loop only spins until the allocation itself fails. The Fix: Close every wrap-capable nest an action dump travels in with nla_nest_end_safe(), which reports -EMSGSIZE before writing a wrapped length: TCA_GATE_ENTRY_LIST, TCA_ACT_OPTIONS, the per-action nest and TCA_ACT_TAB; the shared action and police containers in tcf_exts_dump()/tcf_exts_terse_dump(); and the caller-owned TCA_OPTIONS of every action-capable classifier (flower, matchall, basic, bpf, cgroup, flow, fw, route4, u32). The output is byte identical for every message that serializes. Bound the tfilter_notify_prep() retry once the skb is already larger than any valid message, while a regular dump that only needs a bigger skb still retries. The retry bound and the checked closes are one change: it is nla_nest_end_safe() that turns an unrepresentable dump into -EMSGSIZE, so a backport has to take both together if either is taken. Context note: A delete notification that cannot be built must not veto the state change the caller asked for. Two delete paths built the notification before the state change and propagated the build failure. tfilter_del_notify() builds the filter's delete notification before calling ->delete(), so a filter whose dump cannot be represented in a u16 nest could be created but never removed by "tc filter del ... handle H" - and only when a notification was actually needed (rtnl_notify_needed(): an RTNLGRP_TC listener or NLM_F_ECHO), which made it intermittent. tcf_del_notify() has the same shape for RTM_DELACTION: it builds the notification before tcf_action_delete(), so an action list whose TCA_ACT_TAB exceeds a u16 nest could not be deleted either. In both cases drop the unbuildable notification instead: on -EMSGSIZE the delete proceeds. This needs tca_get_fill() and tcf_del_notify_msg() to pass -EMSGSIZE up instead of collapsing it to -1/-EINVAL, and tca_get_fill() reports any inner tcf_action_dump() failure as -EMSGSIZE too (tcf_gate_dump() and tcf_action_dump_1() return plain -1 after one of their checked closes fails), so a single oversized action's delete is not vetoed either. On the delete paths the rule is scoped to notification BUILD failures: a delivery failure after the state change (rtnetlink_send() failing once ->delete() has already committed) still reports an error to the caller, as it did before this series. The extack that notes a dropped filter event is set only after ->delete() has returned 0. -EMSGSIZE here is the general tcf_fill_node() outcome for any ->dump() that does not fit, not only a u16 nest overflow; the effect of the new branch is limited to dropping a best-effort notification. why net-next? This is hardening rather than a regression fix: the enclosing action and filter-path nests have wrapped since the actions and classifiers allowed large entry lists - TCA_ACT_TAB is core act_api and the filter-side container predates the act_gate sizing change. A plain nla_nest_end() has always written the wrapped length at U16_MAX; this stops the corruption at the abstraction boundary instead of imposing a new policy limit on accepted gate schedules. A separate patch caps the entry list itself. Conditions to recreate the bug: CONFIG_NET_CLS_ACT=y; CONFIG_NET_ACT_GATE=y; CONFIG_NET_CLS_MATCHALL=y and/or CONFIG_NET_CLS_BASIC=y. Create a matchall or basic filter on an ingress/clsact qdisc whose action list holds two gate actions of 1024 minimal TCA_GATE_ONE_ENTRY elements each (TCA_ACT_MAX_PRIO admits up to 32 actions); the aggregate TCA_ACT_TAB nest is ~74.3 KiB > 65532 and wraps, then RTM_GETTFILTER it (or trigger the notify with NLM_F_ECHO). The same shape as two standalone gate actions is hit on the action path by RTM_DELACTION with NLM_F_ECHO; before this change the fill fails and the delete is refused, after it the actions are removed and only the notification is dropped. For a single action the outermost TCA_ACT_TAB wraps from 1815 entries (1821 for the innermost TCA_GATE_ENTRY_LIST); on the filter path the outermost wrap-capable nest is the classifier's TCA_OPTIONS. Installing needs CAP_NET_ADMIN in a user namespace; the RTM_GETTFILTER trigger needs no capability once it exists. The two-action shape survives the per-action cap added by "net/sched: act_gate: cap the number of scheduling entries": the enclosing nests overflow from aggregate action size, which no per-action cap can bound. Reported-by: Sashiko (nipa) Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824153903.4143642-1-victor@mojatatu.com Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-H19Z.v2.20261007062551%40mojatatu.com Link: https://lore.kernel.org/netdev/QDISC-H19Z.v2.20261007062551@mojatatu.com/ Link: https://lore.kernel.org/netdev/QDISC-H19Z.v1.20261001053234@mojatatu.com/ Link: https://lore.kernel.org/netdev/179111893181.434549.13449660670267048994@kernel.org/ Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-H19Z.v3.r0.20261012193813-1@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/act_api.c | 52 ++++++++++++++++++++++++++++++---------- net/sched/act_gate.c | 3 ++- net/sched/cls_api.c | 38 +++++++++++++++++++++-------- net/sched/cls_basic.c | 3 ++- net/sched/cls_bpf.c | 3 ++- net/sched/cls_cgroup.c | 3 ++- net/sched/cls_flow.c | 3 ++- net/sched/cls_flower.c | 6 +++-- net/sched/cls_fw.c | 3 ++- net/sched/cls_matchall.c | 3 ++- net/sched/cls_route.c | 3 ++- net/sched/cls_u32.c | 3 ++- 12 files changed, 89 insertions(+), 34 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index d9d4f7097624..6b751e274ce0 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -555,7 +555,8 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref) goto nla_put_failure; err = tcf_action_dump_old(skb, a, bind, ref); if (err > 0) { - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; return err; } @@ -1276,7 +1277,9 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[], tcf_action_dump_1(skb, a, bind, ref); if (err < 0) goto errout; - nla_nest_end(skb, nest); + err = nla_nest_end_safe(skb, nest); + if (err < 0) + goto errout; } return 0; @@ -1674,27 +1677,42 @@ static int tca_get_fill(struct sk_buff *skb, struct tc_action *actions[], struct nlmsghdr *nlh; unsigned char *b = skb_tail_pointer(skb); struct nlattr *nest; + int err; nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags); - if (!nlh) + if (!nlh) { + err = -EMSGSIZE; goto out_nlmsg_trim; + } t = nlmsg_data(nlh); t->tca_family = AF_UNSPEC; t->tca__pad1 = 0; t->tca__pad2 = 0; if (extack && extack->_msg && - nla_put_string(skb, TCA_ROOT_EXT_WARN_MSG, extack->_msg)) + nla_put_string(skb, TCA_ROOT_EXT_WARN_MSG, extack->_msg)) { + err = -EMSGSIZE; goto out_nlmsg_trim; + } nest = nla_nest_start_noflag(skb, TCA_ACT_TAB); - if (!nest) + if (!nest) { + err = -EMSGSIZE; goto out_nlmsg_trim; + } - if (tcf_action_dump(skb, actions, bind, ref, false) < 0) + err = tcf_action_dump(skb, actions, bind, ref, false); + if (err < 0) { + /* Report any inner dump failure as -EMSGSIZE so + * tcf_del_notify() drops the notification, not the delete. + */ + err = -EMSGSIZE; goto out_nlmsg_trim; + } - nla_nest_end(skb, nest); + err = nla_nest_end_safe(skb, nest); + if (err < 0) + goto out_nlmsg_trim; nlh->nlmsg_len = skb_tail_pointer(skb) - b; @@ -1702,7 +1720,7 @@ static int tca_get_fill(struct sk_buff *skb, struct tc_action *actions[], out_nlmsg_trim: nlmsg_trim(skb, b); - return -1; + return err; } static int @@ -1989,17 +2007,19 @@ static struct sk_buff *tcf_del_notify_msg(struct net *net, struct nlmsghdr *n, struct netlink_ext_ack *extack) { struct sk_buff *skb; + int err; skb = alloc_skb(max(attr_size + tcf_action_warn_attr_size(extack), NLMSG_GOODSIZE), GFP_KERNEL); if (!skb) return ERR_PTR(-ENOBUFS); - if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION, - 0, 2, extack) <= 0) { + err = tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION, + 0, 2, extack); + if (err <= 0) { NL_SET_ERR_MSG(extack, "Failed to fill netlink TC action attributes"); kfree_skb(skb); - return ERR_PTR(-EINVAL); + return ERR_PTR(err ? err : -EINVAL); } return skb; @@ -2017,8 +2037,14 @@ static int tcf_del_notify(struct net *net, struct nlmsghdr *n, } else { skb = tcf_del_notify_msg(net, n, actions, portid, attr_size, extack); - if (IS_ERR(skb)) - return PTR_ERR(skb); + if (IS_ERR(skb)) { + /* Such a dump can never be serialized: drop the + * notification rather than refuse the delete. + */ + if (PTR_ERR(skb) != -EMSGSIZE) + return PTR_ERR(skb); + skb = NULL; + } } /* now do the delete */ diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c index 6d6d45e03c07..14801c604bd9 100644 --- a/net/sched/act_gate.c +++ b/net/sched/act_gate.c @@ -654,7 +654,8 @@ static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a, goto nla_put_failure; } - nla_nest_end(skb, entry_list); + if (nla_nest_end_safe(skb, entry_list) < 0) + goto nla_put_failure; tcf_tm_dump(&t, &gact->tcf_tm); if (nla_put_64bit(skb, TCA_GATE_TM, sizeof(t), &t, TCA_GATE_PAD)) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index a9f54988561f..bd0d635fe3fe 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -2149,11 +2149,16 @@ retry: rtnl_held, extack); if (ret <= 0) { kfree_skb(skb); - if (ret == -EMSGSIZE) { - size += NLMSG_GOODSIZE; - goto retry; - } - return ERR_PTR(-EINVAL); + if (ret != -EMSGSIZE) + return ERR_PTR(-EINVAL); + /* A u16 nest caps the dump, so once the skb is larger than + * any valid message it can never serialize. Stop at the + * bound instead of looping until alloc_skb() fails. + */ + if (size > U16_MAX + NLMSG_GOODSIZE) + return ERR_PTR(-EMSGSIZE); + size += NLMSG_GOODSIZE; + goto retry; } return skb; } @@ -2200,8 +2205,18 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, skb = tfilter_notify_prep(net, oskb, n, tp, block, q, parent, fh, RTM_DELTFILTER, portid, rtnl_held, extack); if (IS_ERR(skb)) { - NL_SET_ERR_MSG(extack, "Failed to build del event notification"); - return PTR_ERR(skb); + if (PTR_ERR(skb) != -EMSGSIZE) { + NL_SET_ERR_MSG(extack, "Failed to build del event notification"); + return PTR_ERR(skb); + } + /* No notification can ever be built for this filter: drop + * it rather than refuse the delete. + */ + err = tp->ops->delete(tp, fh, last, rtnl_held, extack); + if (!err) + NL_SET_ERR_MSG(extack, + "Filter deleted; del event notification could not be built"); + return err; } err = tp->ops->delete(tp, fh, last, rtnl_held, extack); @@ -3529,7 +3544,8 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts) if (tcf_action_dump(skb, exts->actions, 0, 0, false) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; } else if (exts->police) { struct tc_action *act = tcf_exts_first_act(exts); nest = nla_nest_start_noflag(skb, exts->police); @@ -3537,7 +3553,8 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts) goto nla_put_failure; if (tcf_action_dump_old(skb, act, 0, 0) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; } } return 0; @@ -3565,7 +3582,8 @@ int tcf_exts_terse_dump(struct sk_buff *skb, struct tcf_exts *exts) if (tcf_action_dump(skb, exts->actions, 0, 0, true) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; return 0; nla_put_failure: diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index e2a94ba9fba7..ba859110faae 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -305,7 +305,8 @@ static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh, tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &f->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 188cf0f949dd..232796d3a51f 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -631,7 +631,8 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh, nla_put_u32(skb, TCA_BPF_FLAGS_GEN, prog->gen_flags)) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &prog->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c index 210fd9fd26d8..28701d3916b8 100644 --- a/net/sched/cls_cgroup.c +++ b/net/sched/cls_cgroup.c @@ -185,7 +185,8 @@ static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, void *fh, tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &head->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c index a9ac3acf6eda..2ef449706638 100644 --- a/net/sched/cls_flow.c +++ b/net/sched/cls_flow.c @@ -681,7 +681,8 @@ static int flow_dump(struct net *net, struct tcf_proto *tp, void *fh, tcf_em_tree_dump(skb, &f->ematches, TCA_FLOW_EMATCHES) < 0) goto nla_put_failure; #endif - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &f->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 0c4beff18d68..299b1493d74b 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -3759,7 +3759,8 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh, if (tcf_exts_dump(skb, &f->exts)) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &f->exts) < 0) goto nla_put_failure; @@ -3804,7 +3805,8 @@ static int fl_terse_dump(struct net *net, struct tcf_proto *tp, void *fh, if (tcf_exts_terse_dump(skb, &f->exts)) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; return skb->len; diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index a462b262719c..0f731595f839 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -414,7 +414,8 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh, if (tcf_exts_dump(skb, &f->exts) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &f->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c index c14899b935bf..6ece63b82775 100644 --- a/net/sched/cls_matchall.c +++ b/net/sched/cls_matchall.c @@ -366,7 +366,8 @@ static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, if (tcf_exts_dump(skb, &head->exts)) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &head->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c index dca812a75269..6f8b4a98bb84 100644 --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -663,7 +663,8 @@ static int route4_dump(struct net *net, struct tcf_proto *tp, void *fh, if (tcf_exts_dump(skb, &f->exts) < 0) goto nla_put_failure; - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (tcf_exts_dump_stats(skb, &f->exts) < 0) goto nla_put_failure; diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 76ce2d124079..91f4e6458785 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -1482,7 +1482,8 @@ static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh, #endif } - nla_nest_end(skb, nest); + if (nla_nest_end_safe(skb, nest) < 0) + goto nla_put_failure; if (TC_U32_KEY(n->handle)) if (tcf_exts_dump_stats(skb, &n->exts) < 0) From 1a49567560a13bf9501eeafbbaa9414c2ff624ac Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 13 Oct 2026 04:54:28 -0400 Subject: [PATCH 1989/2126] net/sched: act_api: keep an add that created its actions from failing Spotted while fixing the dump sizing reported by Sashiko. This references commit cfa165cbfbed ("net/sched: act_gate: budget the per-entry list in get_fill_size"), which is only one way to trigger the issue. The issue: tcf_action_add() returns the result of tcf_add_notify(), so an RTM_NEWACTION is reported back to user space as a failure when the event notification cannot be built, even though tcf_action_init() has already inserted the actions into the idr. The realistic trigger is an action list whose TCA_ACT_TAB exceeds a u16 nest (the notification can never be built), or a memory-pressure -ENOBUFS from the notification's alloc_skb(). The Fix: Drop the notification failure on the add path: the created actions stay installed and the add reports success, with an extack noting that the event notification could not be sent. The extack is set on a successful ack, so iproute2 reports it as a warning; it replaces any warning tcf_action_init() left there. This needs no idr/refcount audit - tca_put_bound_many() already runs unconditionally after the notification, so this path releases exactly what the success path does and only the returned result changes. A create that ignores a notification failure is already the filter-side norm: tc_new_tfilter() does not look at tfilter_notify()'s result. This is net-next hardening: it corrects the reported result of an add that already took effect, not a regression. Conditions to recreate the bug: CONFIG_NET_CLS_ACT=y; CONFIG_NET_ACT_GATE=y. Send an RTM_NEWACTION whose actions create an aggregate TCA_ACT_TAB larger than a u16 nest, so the notification cannot be built; before this change the add reports -EINVAL although the actions were installed, after it the add reports success and the actions are present. Reported-by: Sashiko (nipa) Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824153903.4143642-1-victor@mojatatu.com Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-H19Z.v2.20261007062551%40mojatatu.com Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-H19Z.v3.r0.20261012193813-2@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/act_api.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 6b751e274ce0..3737302275ae 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -2168,12 +2168,17 @@ static int tcf_action_add(struct net *net, struct nlattr *nla, if (ret < 0) return ret; - ret = tcf_add_notify(net, n, actions, portid, attr_size, extack); + /* The add has already been committed, so a notification failure + * must not turn it into a reported failure (cf. tc_new_tfilter()). + */ + if (tcf_add_notify(net, n, actions, portid, attr_size, extack)) + NL_SET_ERR_MSG(extack, + "Action created; event notification could not be sent"); /* only put bound actions */ tca_put_bound_many(actions, init_res); - return ret; + return 0; } static const struct nla_policy tcaa_policy[TCA_ROOT_MAX + 1] = { From 150167ea4d7abdc3dba504abbbea699c9abeb425 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 13 Oct 2026 04:54:29 -0400 Subject: [PATCH 1990/2126] net/sched: act_gate: cap the number of scheduling entries parse_gate_list() accepts _any number_ of TCA_GATE_ONE_ENTRY elements. The only bound/cap is the enclosing nlattr u16 nla_len (~5460 minimal 12-byte entries). Each entry is a separate GFP_ATOMIC allocation, and the dump of a large list grows one action's reply well past NLMSG_GOODSIZE. The bugs: 1. A single gate can make tcf_dump_walker() silently truncate "tc actions ls" ("net/sched: act_api: report an oversized action dump instead of silently truncating it" makes such an action report -EMSGSIZE instead of dropping the rest of the list). 2. Lack of capping pins memory for as long as the action lives: the largest representable minimal list is roughly 5460 entries, each a separate GFP_ATOMIC allocation, with a per-entry offload array on top in full offload. The held-reply RTM_GETACTION amplification demonstrated in the original posting of this series (Link below) is a generic netlink property this cap does not remove; the bound added here is the install-side pin. So we need to provide an upper bound cap of TCA_GATE_ONE_ENTRY elements. Some context: The gate action offloads through FLOW_ACTION_GATE. The offload interface passes the priority, base time, cycle time, cycle-time extension, the complete entry count and an array holding each entry's gate state, interval, IPV and maximum-octet value. The in-tree SJA1105 DSA driver forwards that complete list to sja1105_vl_gate() without any entry cap check, and composes every supplied entry into the hardware schedule table. Act gate challenges: SJA1105 and SJA1110 are two device families in the one sja1105 driver. They expose different schedule-table capacities: SJA1105 provides up to 1024 schedule entries and SJA1110 up to 4096. These are total table capacities shared with other schedules, so they are upper bounds, not a guaranteed per-action budget. Software gate actions with _a lot more_ entries install and serialize today, so a low cap would reject working configurations and would look like a UAPI breakage; but an infinite size of entries is a bogus choice; a 65-entry configuration was verified during this work to install and dump well-formed. Netlink Challenges: Netlink attributes record their total size, including the four-byte header, in a 16-bit nla_len, so a nested attribute can describe at most 65532 bytes. A minimal accepted input entry is 12 bytes, which puts the max we can fit at roughly 5460 entries; a dumped entry occupies 36 bytes, or 40 bytes when it carries the gate-open flag. 1024 entries therefore serialize to 36868-40964 bytes, which fits inside one nested attribute, while a 4096-entry schedule would need roughly 144-160 KiB which _cannot fit_ at the moment due to the 16bit length. Note: This represents challenges primarily with netlink. The Cap: Cap the list at 1024 entries. This value is based on the existing SJA1105 schedule-table capacity and preserves the verified 65-entry configuration while providing a substantial headroom, and keeps the complete gate list inside the current 16-bit TLV format. It deliberately declines to expose SJA1110's 1025-4096 range through an interface that cannot serialize it, and deliberately rejects software-only schedules above 1024. Why 1024 despite the dump budget: 1024 is a SJA1105 schedule-table capacity, not a dump-budget value. The kernel clamps a dump skb to SKB_WITH_OVERHEAD(32768), so only ~800-890 entries of this list fit "tc actions ls"; the top of the admitted band therefore installs but is not listed. That is accepted deliberately: a unicast RTM_GETACTION reply is pre-sized from the action's advertised size (budgeted per entry since the parent fix), so "tc actions get" enumerates the whole band, and "net/sched: act_api: report an oversized action dump instead of silently truncating it" makes the list view fail loudly with -EMSGSIZE and an extack rather than silently truncating. A filter whose action list contains such a gate also stops "tc filter show" for that chain with -EMSGSIZE (loud), through tc_dump_tfilter()'s no-progress path. This is an operational cap on a configuration the uAPI accepted before, so it is net-next hardening; if we made this a stable backport then it would start rejecting gate configurations that install today (even though those settings would be totally bogus). Conditions to recreate the bug: CAP_NET_ADMIN with CONFIG_NET_ACT_GATE=y. Install a gate action with 1025 or more minimal TCA_GATE_ONE_ENTRY elements over a raw netlink RTM_NEWACTION request. The cap rejects the list with -E2BIG and an extack naming the limit; 1024 entries install and an indexed RTM_GETACTION returns a well-formed reply. Link: https://lore.kernel.org/netdev/QDISC-H19Z.v1.20261001053234@mojatatu.com/ Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-H19Z.v3.r0.20261012193813-3@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/act_gate.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c index 14801c604bd9..711cf2443540 100644 --- a/net/sched/act_gate.c +++ b/net/sched/act_gate.c @@ -18,6 +18,13 @@ static struct tc_action_ops act_gate_ops; +/* A nested attribute's u16 nla_len caps it at 65532 bytes. tcf_gate_dump() + * emits each entry as 36 bytes (40 with the gate-open flag), so 4096 entries + * would need ~144-160 KiB and cannot be represented. 1024 matches the + * SJA1105 schedule-table capacity (SJA1110 provides 4096). + */ +#define GATE_ENTRIES_MAX 1024U + static ktime_t gate_get_time(struct tcf_gate *gact) { ktime_t mono = ktime_get(); @@ -277,6 +284,14 @@ static int parse_gate_list(struct nlattr *list_attr, continue; } + if (i >= GATE_ENTRIES_MAX) { + NL_SET_ERR_MSG_FMT(extack, + "Too many schedule entries, at most %u are supported", + GATE_ENTRIES_MAX); + err = -E2BIG; + goto release_list; + } + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (!entry) { NL_SET_ERR_MSG(extack, "Not enough memory for entry"); From 2bc124a5f8df56aeabd444cded132407d91d9876 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 13 Oct 2026 04:54:30 -0400 Subject: [PATCH 1991/2126] net/sched: sch_taprio: cap the number of schedule entries parse_sched_list() accepts _any number_ of TCA_TAPRIO_SCHED_ENTRY elements. The only bound is the enclosing nlattr u16 nla_len. A minimal accepted entry is 12 bytes (the entry nest plus TCA_TAPRIO_SCHED_ENTRY_INTERVAL), so that u16 admits roughly 5460 entries - protocol-bounded amplification, not truly unbounded, but far past any hardware schedule. The bug: Each entry is a separate sched_entry allocation (368 bytes, rounded up to the kmalloc-512 bucket) and, in full offload, is also composed into a per-entry offload array, so the largest representable minimal list pins roughly 2.7 MiB for the lifetime of the schedule. Some context: The schedule list is not dumped the way the gate action list is: a taprio dump is bounded by the carrying skb (the 32K dump skb, and NLMSG_GOODSIZE for notify and unicast get), which keeps the plain nla_nest_end() closes from ever seeing a wrapped length. But the input-side amplification is the same class as the act_gate entry list, and the offload interface composes every supplied entry into the hardware schedule table without a capacity check. The top of the accepted band cannot be read back: a schedule above roughly 900 entries does not fit the 32K dump skb, so "tc qdisc show" fails loudly with -EMSGSIZE for it (as the action-dump patch does). The pre-existing silent gaps - no change notification above about 100 entries, and no unicast get reply - are tracked separately. The Cap: Cap the list at 1024 entries. This matches the SJA1105 schedule-table capacity (SJA1110 provides 4096) and the act_gate entry cap, and keeps the list inside the current 16-bit TLV format. This is an operational cap on a configuration the uAPI accepted before, so it is net-next hardening; a stable backport would start rejecting taprio configurations that install today. Conditions to recreate the bug: CAP_NET_ADMIN with CONFIG_NET_SCH_TAPRIO=y. Install a taprio qdisc with more than 1024 minimal TCA_TAPRIO_SCHED_ENTRY elements over a raw netlink RTM_NEWQDISC request. The cap rejects the list with -E2BIG and an extack naming the limit; 1024 entries install. Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-H19Z.v3.r0.20261012193813-4@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/sch_taprio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 39ac5b97aa3a..8e7fb6d0fc00 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -49,6 +49,13 @@ static struct static_key_false taprio_have_working_mqprio; */ #define TAPRIO_PICOS_PER_BYTE_MIN 17 +/* Each entry is a separate 368-byte sched_entry and, in full offload, is + * also composed into a per-entry offload array. The u16 nla_len admits + * roughly 5460 minimal 12-byte entries, pinning ~2 MiB; 1024 matches the + * SJA1105 schedule-table capacity (SJA1110 provides 4096) and the act_gate cap. + */ +#define TAPRIO_ENTRIES_MAX 1024U + struct sched_entry { /* Durations between this GCL entry and the GCL entry where the * respective traffic class gate closes @@ -1105,6 +1112,13 @@ static int parse_sched_list(struct taprio_sched *q, struct nlattr *list, continue; } + if (i >= TAPRIO_ENTRIES_MAX) { + NL_SET_ERR_MSG_FMT(extack, + "Too many schedule entries, at most %u are supported", + TAPRIO_ENTRIES_MAX); + return -E2BIG; + } + entry = kzalloc_obj(*entry); if (!entry) { NL_SET_ERR_MSG(extack, "Not enough memory for entry"); From 10a486c17dff0e88122344b27351a5b22e018099 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 13 Oct 2026 04:54:31 -0400 Subject: [PATCH 1992/2126] net/sched: act_api: report an oversized action dump instead of silently truncating it The issue: tcf_dump_walker() trims the half-built nest and returns the number of actions dumped so far as soon as one action does not fit. When the action at the current index cannot be serialized even into an *empty* dump skb, that count is zero, so tc_dump_action() returns skb->len (zero) and netlink sends NLMSG_DONE with no error: "tc actions ls" silently drops that action and every action after it. That case is reachable inside the gate entry cap this series adds: a gate entry serializes to 36 bytes (40 with the gate-open flag) while a dump skb is clamped to SKB_WITH_OVERHEAD(32768) by netlink_recvmsg()/netlink_dump(), so the top of the range the cap admits installs but cannot be dumped - and, before this change, fails silently. The Fix: tcf_dump_walker() already has to distinguish the two cases: a walk that filled the skb before completing the current action must keep returning a positive count so netlink retries that action in a fresh skb, while an action that cannot be serialized even into an empty skb must return -EMSGSIZE. So return n_i when anything was dumped and -EMSGSIZE (with an extack) when nothing was, and let tc_dump_action() propagate the walker's error code instead of overwriting it with skb->len. That mirrors tc_dump_tfilter(), which returns the walker error when a retry made no progress (if (skb->len == 0 && err) return err;), and tc_dump_chain() carries the same idiom. This is netlink's documented contract: -EMSGSIZE with data in the skb means "more to dump", -EMSGSIZE with an empty skb is delivered to user space. Context note: The shared nla_put_failure label stamps -EMSGSIZE for any inner tcf_action_dump_1()/terse failure, not only a size failure, consistent with how every other nla_put_failure label in the file reports; the -EMSGSIZE the action dump now returns is therefore not a strict size assertion. The cap stays a memory bound; this only makes an action the cap admits but the dump buffer cannot carry fail loudly instead of silently truncating the list. This is a long-standing silent failure, not a regression, so it is net-next hardening. Reported-by: Paul Moses Closes: https://lore.kernel.org/netdev/vPFrhbkwAui8zFPcGQTUDazQfsFDlr5GYuaYQ5BxJcrDiT6x1EljEze4cYadHqbeUW2ivLdpa8eC_cXC6ceACswgb-lW47aSVkHvHjhn_X8=@1g4.org/ Suggested-by: Paul Moses Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-H19Z.v3.r0.20261012193813-5@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/act_api.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 3737302275ae..3295f4cf3c19 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -596,18 +596,13 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, tcf_action_update_hw_stats(p); nest = nla_nest_start_noflag(skb, n_i); - if (!nest) { - index--; + if (!nest) goto nla_put_failure; - } err = (act_flags & TCA_ACT_FLAG_TERSE_DUMP) ? tcf_action_dump_terse(skb, p, true) : tcf_action_dump_1(skb, p, 0, 0); - if (err < 0) { - index--; - nlmsg_trim(skb, nest); - goto done; - } + if (err < 0) + goto nla_put_failure; nla_nest_end(skb, nest); n_i++; if (!(act_flags & TCA_ACT_FLAG_LARGE_DUMP_ON) && @@ -623,10 +618,21 @@ done: if (act_flags & TCA_ACT_FLAG_LARGE_DUMP_ON) cb->args[1] = n_i; } - return n_i; + + /* A positive count means the skb filled up before this action was + * complete, so netlink retries it in a fresh skb. An action that + * does not fit even in an empty dump skb (nothing dumped) must be + * reported as -EMSGSIZE by netlink instead of ending the dump. + */ + return n_i ?: err; nla_put_failure: + index--; nla_nest_cancel(skb, nest); + err = -EMSGSIZE; + if (!n_i) + NL_SET_ERR_MSG(cb->extack, + "TC action is too large for the dump buffer"); goto done; } @@ -2346,7 +2352,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) out_module_put: module_put(a_o->owner); nlmsg_trim(skb, b); - return skb->len; + return ret; } static const struct rtnl_msg_handler tc_action_rtnl_msg_handlers[] __initconst = { From 20c0c677362468b0af23e26e5fdb871ea911bc25 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Thu, 15 Oct 2026 06:50:01 +0200 Subject: [PATCH 1993/2126] net: phy: realtek: restore RTL8211F RGMII delays on resume RTL8211F and RTL8211F-VD both use rtl8211f_config_rgmii_delay() during initialization and share rtl821x_resume(). The RTL8211F-VD loses its RGMII TX and RX delay enable bits across a software power-down, but the shared resume path only clears BMCR_PDOWN and waits for the receive clock to stabilize. On a BeagleV Ahead configured for rgmii-id, carrier and the negotiated speed return after an interface close/open, but the receive path does not work. At 100 Mbit/s no frames were received. At 1000 Mbit/s all 11 observed frames had CRC errors. Reapply the RGMII delay configuration after the existing resume delay. Tested on a BeagleV Ahead with an RTL8211F-VD at 100 and 1000 Mbit/s, including close/open without a link partner. Fixes: bb726b753f75 ("net: phy: realtek: add support for RTL8211F(D)(I)-VD-CG") Reviewed-by: Andrew Lunn Signed-off-by: Karl Mehltretter Link: https://patch.msgid.link/20261015045001.83986-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/realtek/realtek_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index cc5ebedd0e8f..4927ee838de2 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -1399,7 +1399,7 @@ static int rtl821x_resume(struct phy_device *phydev) msleep(20); - return 0; + return rtl8211f_config_rgmii_delay(phydev); } static int rtl8211f_resume(struct phy_device *phydev) From 87cce46329a811ea3fe108ac721e0a2400d0a3bb Mon Sep 17 00:00:00 2001 From: Myeonghun Pak Date: Wed, 14 Oct 2026 22:26:35 -0400 Subject: [PATCH 1994/2126] net: hix5hd2: serialize timeout recovery with interface teardown The timeout worker calls the driver's close and open methods without RTNL or a running-state check. A timeout queued before an interface is closed can call close again after ndo_stop has disabled NAPI. The second napi_disable() can then wait indefinitely. The worker can also race with an ongoing close. Take RTNL and skip recovery when the interface is no longer running. Use the netdev core close and open helpers so a failed reopen leaves the interface down, rather than leaving it marked running with NAPI disabled. After unregister_netdev() has stopped the watchdog, drain the worker before releasing its MDIO and descriptor resources. This wait is outside RTNL, allowing an already queued worker to take RTNL, observe the down state, and finish. This issue was identified as part of our ongoing research while reviewing kernel code. Fixes: 57c5bc9ad7d7 ("net: hisilicon: add hix5hd2 mac driver") Co-developed-by: Ijae Kim Signed-off-by: Ijae Kim Signed-off-by: Myeonghun Pak Reviewed-by: Jijie Shao Link: https://patch.msgid.link/179203116093.2621539.3718842986255459438.G202@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c index 02282dc86faf..12a5657653f8 100644 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -890,8 +891,13 @@ static void hix5hd2_tx_timeout_task(struct work_struct *work) struct hix5hd2_priv *priv; priv = container_of(work, struct hix5hd2_priv, tx_timeout_task); - hix5hd2_net_close(priv->netdev); - hix5hd2_net_open(priv->netdev); + + rtnl_lock(); + if (netif_running(priv->netdev)) { + dev_close(priv->netdev); + dev_open(priv->netdev, NULL); + } + rtnl_unlock(); } static void hix5hd2_net_timeout(struct net_device *dev, unsigned int txqueue) @@ -1283,6 +1289,7 @@ static void hix5hd2_dev_remove(struct platform_device *pdev) struct hix5hd2_priv *priv = netdev_priv(ndev); unregister_netdev(ndev); + cancel_work_sync(&priv->tx_timeout_task); mdiobus_unregister(priv->bus); mdiobus_free(priv->bus); @@ -1290,7 +1297,6 @@ static void hix5hd2_dev_remove(struct platform_device *pdev) hix5hd2_destroy_sg_desc_queue(priv); hix5hd2_destroy_hw_desc_queue(priv); of_node_put(priv->phy_node); - cancel_work_sync(&priv->tx_timeout_task); free_netdev(ndev); } From db45c15c98134f5ebd13c4dc5b6be5d1cd3fc706 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 13 Oct 2026 13:44:34 -0700 Subject: [PATCH 1995/2126] net: bcmasp: fix mib counters struct alignment with ethtool stats When EDPKT stats were removed in commit e9f31435ee7d ("net: bcmasp: Add support for asp-v3.0"), the corresponding entries were removed from bcmasp_gstrings_stats in bcmasp_ethtool.c, but the edpkt_* fields were left at the beginning of struct bcmasp_mib_counters in bcmasp.h. Because bcmasp_update_mib_counters() and bcmasp_get_ethtool_stats() index into struct bcmasp_mib_counters sequentially based on the order of bcmasp_gstrings_stats, this 16-byte offset caused ethtool to read from shifted offsets: the first four software counters read unused fields and reported 0, the next four software counters reported the values of alloc_rx_skb_failed, tx_dma_failed, mc_filters_full_cnt, and uc_filters_full_cnt, while filters_combine_cnt, promisc_filters_cnt, tx_realloc_offload_failed, and tx_timeout_cnt were never reported. Remove the obsolete edpkt_* fields from struct bcmasp_mib_counters so that it aligns with bcmasp_gstrings_stats. Fixes: e9f31435ee7d ("net: bcmasp: Add support for asp-v3.0") Reviewed-by: Nicolai Buchwitz Reviewed-by: Justin Chen Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20261013204439.3494046-2-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h b/drivers/net/ethernet/broadcom/asp2/bcmasp.h index 8c8ffaeadc79..9c9721da1662 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h @@ -250,10 +250,6 @@ struct bcmasp_intf_stats64 { }; struct bcmasp_mib_counters { - u32 edpkt_ts; - u32 edpkt_rx_pkt_cnt; - u32 edpkt_hdr_ext_cnt; - u32 edpkt_hdr_out_cnt; u32 umac_frm_cnt; u32 fb_frm_cnt; u32 fb_rx_fifo_depth; From a3cf9877558ab2c51182af558815dde64fc17cb9 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 13 Oct 2026 13:44:35 -0700 Subject: [PATCH 1996/2126] net: bcmasp: unmap previous DMA mappings on TX map failure When mapping an skb with fragments for transmission in bcmasp_xmit(), if mapping fails on fragment i > 0, the error handler calls bcmasp_clean_txcb() for previous iterations j < i. However, bcmasp_clean_txcb() only zeroes the control block fields without unmapping the DMA buffers, leaking the DMA mappings allocated for the head and earlier fragments. Call dma_unmap_single() before calling bcmasp_clean_txcb() in the error cleanup loop. Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Reviewed-by: Nicolai Buchwitz Reviewed-by: Justin Chen Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20261013204439.3494046-3-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index f2176ef3a127..9ad5a982542f 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -285,6 +285,11 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) intf->mib.tx_dma_failed++; spb_index = intf->tx_spb_index; for (j = 0; j < i; j++) { + txcb = &intf->tx_cbs[spb_index]; + dma_unmap_single(kdev, + dma_unmap_addr(txcb, dma_addr), + dma_unmap_len(txcb, dma_len), + DMA_TO_DEVICE); bcmasp_clean_txcb(intf, spb_index); spb_index = incr_ring(spb_index, DESC_RING_COUNT); From 07b624d2f5a4517d7d0022fbd4aef17e884b5686 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 13 Oct 2026 13:44:36 -0700 Subject: [PATCH 1997/2126] net: bcmasp: validate minimum RX packet size in bcmasp_rx_poll() In bcmasp_rx_poll(), the driver removes a 2-byte alignment pad and optionally strips the ETH_FCS_LEN CRC from received packets before passing them to eth_type_trans(). If the hardware reports a descriptor size smaller than the sum of the 2-byte pad, the Ethernet header (ETH_HLEN), and optional CRC (ETH_FCS_LEN), subtracting the pad and CRC lengths underflows u32 len. This adds ~4 GiB to rx_bytes statistics, while the undersized frame reaches eth_type_trans(), which reads past skb->len into stale buffer data. Check that desc->size is at least (2 + ETH_HLEN + (crc_fwd ? ETH_FCS_LEN : 0)) before proceeding to process the descriptor. Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Reviewed-by: Justin Chen Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20261013204439.3494046-4-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index 9ad5a982542f..d679c796c8c2 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -523,6 +523,12 @@ static int bcmasp_rx_poll(struct napi_struct *napi, int budget) DMA_FROM_DEVICE); len = desc->size; + if (unlikely(len < 2 + ETH_HLEN + (intf->crc_fwd ? ETH_FCS_LEN : 0))) { + u64_stats_update_begin(&stats->syncp); + u64_stats_inc(&stats->rx_dropped); + u64_stats_update_end(&stats->syncp); + goto next; + } /* Allocate a page pool page as the SKB data area so the * kernel can recycle it efficiently after the packet is From a31623d91c6e48b08c74dc95567aeb62f1f35938 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 13 Oct 2026 13:44:37 -0700 Subject: [PATCH 1998/2126] net: bcmasp: fix OF node reference leak for phy_dn In bcmasp_interface_create(), intf->phy_dn is obtained via of_parse_phandle() or assigned ndev_dn. of_parse_phandle() returns a node reference with its refcount incremented, but of_node_put() was never called on intf->phy_dn in bcmasp_interface_destroy() or the error unwind path in bcmasp_interface_create(). Acquire a reference on ndev_dn for the fixed-link case as well so that intf->phy_dn consistently holds a reference, and release it with of_node_put() on teardown and error. Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Reviewed-by: Nicolai Buchwitz Reviewed-by: Justin Chen Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20261013204439.3494046-5-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index d679c796c8c2..693e8cdfe960 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -1298,7 +1298,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, ndev_dn->name); goto err_free_netdev; } - intf->phy_dn = ndev_dn; + intf->phy_dn = of_node_get(ndev_dn); } /* Map resource */ @@ -1338,6 +1338,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, err_deregister_fixed_link: if (of_phy_is_fixed_link(ndev_dn)) of_phy_deregister_fixed_link(ndev_dn); + of_node_put(intf->phy_dn); err_free_netdev: free_netdev(ndev); err: @@ -1350,6 +1351,7 @@ void bcmasp_interface_destroy(struct bcmasp_intf *intf) unregister_netdev(intf->ndev); if (of_phy_is_fixed_link(intf->ndev_dn)) of_phy_deregister_fixed_link(intf->ndev_dn); + of_node_put(intf->phy_dn); free_netdev(intf->ndev); } From 74667a55122ad2fad88af4fd7672e4c8175c2558 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 13 Oct 2026 13:44:38 -0700 Subject: [PATCH 1999/2126] net: bcmasp: account for offload header in TX short packet padding When hardware checksum offload is enabled for an skb, bcmasp_csum_offload() prepends a struct bcmasp_pkt_offload header (20 bytes) to the skb via skb_push(). This increases skb->len and skb_headlen(skb) by sizeof(struct bcmasp_pkt_offload). Because the hardware descriptor processor strips this offload header before transmitting the packet on the wire, the wire packet length is smaller by sizeof(struct bcmasp_pkt_offload). The padding calculation must account for this extra header; otherwise, short frames are sent on the wire smaller than the minimum Ethernet frame size (ETH_ZLEN + ETH_FCS_LEN). Furthermore, small frames with payload in page fragments (such as small TCP segments with CHECKSUM_PARTIAL) have nr_frags > 0 and were skipping padding entirely because the padding check was restricted to nr_frags == 0. Perform the padding check on skb->len before the descriptor loop using skb_put_padto(), adding sizeof(struct bcmasp_pkt_offload) to min_size when checksum offload is enabled, and re-read nr_frags after padding in case the skb was linearized. Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Reviewed-by: Justin Chen Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20261013204439.3494046-6-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/broadcom/asp2/bcmasp_intf.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index 693e8cdfe960..a855e637b6f0 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -236,7 +236,7 @@ help: static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) { struct bcmasp_intf *intf = netdev_priv(dev); - unsigned int total_bytes, size; + unsigned int total_bytes, size, min_size; int spb_index, nr_frags, i, j; struct bcmasp_tx_cb *txcb; dma_addr_t mapping, valid; @@ -262,16 +262,21 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) if (!skb) return NETDEV_TX_OK; + min_size = ETH_ZLEN + ETH_FCS_LEN; + if (csum_hw) + min_size += sizeof(struct bcmasp_pkt_offload); + + if (skb->len < min_size) { + if (skb_put_padto(skb, min_size)) + return NETDEV_TX_OK; + nr_frags = skb_shinfo(skb)->nr_frags; + } + spb_index = intf->tx_spb_index; valid = intf->tx_spb_dma_valid; for (i = 0; i <= nr_frags; i++) { if (!i) { size = skb_headlen(skb); - if (!nr_frags && size < (ETH_ZLEN + ETH_FCS_LEN)) { - if (skb_put_padto(skb, ETH_ZLEN + ETH_FCS_LEN)) - return NETDEV_TX_OK; - size = skb->len; - } mapping = dma_map_single(kdev, skb->data, size, DMA_TO_DEVICE); } else { From fa1459375794f14fb65039cd19c9398d759b491e Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 13 Oct 2026 13:44:39 -0700 Subject: [PATCH 2000/2126] net: bcmasp: fix network filter lookup and wake filter pair allocation In bcmasp_netfilt_get_init(), when looking up an existing filter (!init) for a specified location, if the filter at loc was not claimed, the previous loop continued searching higher indices and could return an arbitrary unrelated filter belonging to the port. This caused flow get or delete operations on an empty rule location to return or delete an unintended filter. Fix this by checking only the requested location on lookup and rejecting RX_CLS_LOC_ANY when !init. In addition, harden wake filter allocation and release by ensuring wake filter pair searches stay on even boundaries where both entries are free, checking that loc + 1 is free for positioned wake filters, and validating parity and bounds on release. Fixes: c5d511c49587 ("net: bcmasp: Add support for wake on net filters") Signed-off-by: Florian Fainelli Link: https://patch.msgid.link/20261013204439.3494046-7-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 121 +++++++++++--------- 1 file changed, 70 insertions(+), 51 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c index 972474893a6b..f41a79529f10 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c @@ -511,6 +511,13 @@ static int bcmasp_netfilt_wr_to_hw(struct bcmasp_priv *priv, return 0; } +static bool bcmasp_netfilt_is_companion(struct bcmasp_priv *priv, int i) +{ + return i > 0 && (i % 2) && + priv->net_filters[i].wake_filter && + priv->net_filters[i - 1].wake_filter; +} + void bcmasp_netfilt_suspend(struct bcmasp_intf *intf) { struct bcmasp_priv *priv = intf->parent; @@ -524,9 +531,7 @@ void bcmasp_netfilt_suspend(struct bcmasp_intf *intf) priv->net_filters[i].port != intf->port) continue; - if (i > 0 && (i % 2) && - priv->net_filters[i].wake_filter && - priv->net_filters[i - 1].wake_filter) + if (bcmasp_netfilt_is_companion(priv, i)) continue; ret = bcmasp_netfilt_wr_to_hw(priv, &priv->net_filters[i]); @@ -556,9 +561,7 @@ int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, priv->net_filters[i].port != intf->port) continue; - if (i > 0 && (i % 2) && - priv->net_filters[i].wake_filter && - priv->net_filters[i - 1].wake_filter) + if (bcmasp_netfilt_is_companion(priv, i)) continue; if (j == *rule_cnt) @@ -583,9 +586,7 @@ int bcmasp_netfilt_get_active(struct bcmasp_intf *intf) continue; /* Skip over a wake filter pair */ - if (i > 0 && (i % 2) && - priv->net_filters[i].wake_filter && - priv->net_filters[i - 1].wake_filter) + if (bcmasp_netfilt_is_companion(priv, i)) continue; cnt++; @@ -607,6 +608,9 @@ bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf, priv->net_filters[i].port != intf->port) continue; + if (bcmasp_netfilt_is_companion(priv, i)) + continue; + cur = &priv->net_filters[i].fs; if (cur->flow_type != fs->flow_type || @@ -659,7 +663,7 @@ bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf, } /* If no network filter found, return open filter. - * If no more open filters return NULL + * If no more open filters return error. */ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf, u32 loc, bool wake_filter, @@ -669,45 +673,55 @@ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf, struct bcmasp_priv *priv = intf->parent; int i, open_index = -1; - /* Check whether we exceed the filter table capacity */ + if (!init) { + if (loc == RX_CLS_LOC_ANY || loc >= priv->num_net_filters) + return ERR_PTR(-EINVAL); + + if (priv->net_filters[loc].claimed && + priv->net_filters[loc].port == intf->port && + !bcmasp_netfilt_is_companion(priv, loc)) + return &priv->net_filters[loc]; + + return ERR_PTR(-ENOENT); + } + if (loc != RX_CLS_LOC_ANY && loc >= priv->num_net_filters) return ERR_PTR(-EINVAL); /* If the filter location is busy (already claimed) and we are initializing * the filter (insertion), return a busy error code. */ - if (loc != RX_CLS_LOC_ANY && init && priv->net_filters[loc].claimed) - return ERR_PTR(-EBUSY); + if (loc != RX_CLS_LOC_ANY) { + if (priv->net_filters[loc].claimed) + return ERR_PTR(-EBUSY); - /* We need two filters for wake-up, so we cannot use an odd filter */ - if (wake_filter && loc != RX_CLS_LOC_ANY && (loc % 2)) - return ERR_PTR(-EINVAL); - - /* Initialize the loop index based on the desired location or from 0 */ - i = loc == RX_CLS_LOC_ANY ? 0 : loc; - - for ( ; i < priv->num_net_filters; i++) { - /* Found matching network filter */ - if (!init && - priv->net_filters[i].claimed && - priv->net_filters[i].hw_index == i && - priv->net_filters[i].port == intf->port) - return &priv->net_filters[i]; - - /* If we don't need a new filter or new filter already found */ - if (!init || open_index >= 0) - continue; - - /* Wake filter conslidates two filters to cover more bytes - * Wake filter is open if... - * 1. It is an even filter - * 2. The current and next filter is not claimed - */ - if (wake_filter && !(i % 2) && !priv->net_filters[i].claimed && - !priv->net_filters[i + 1].claimed) - open_index = i; - else if (!priv->net_filters[i].claimed) - open_index = i; + /* We need two filters for wake-up, so we cannot use an odd filter */ + if (wake_filter) { + if ((loc % 2) || loc + 1 >= priv->num_net_filters) + return ERR_PTR(-EINVAL); + if (priv->net_filters[loc + 1].claimed) + return ERR_PTR(-EBUSY); + } + open_index = loc; + } else { + for (i = 0; i < priv->num_net_filters; i++) { + /* Wake filter consolidates two filters to cover more bytes. + * Wake filter is open if: + * 1. It is an even filter + * 2. The current and next filter is not claimed + */ + if (wake_filter) { + if (!(i % 2) && (i + 1 < priv->num_net_filters) && + !priv->net_filters[i].claimed && + !priv->net_filters[i + 1].claimed) { + open_index = i; + break; + } + } else if (!priv->net_filters[i].claimed) { + open_index = i; + break; + } + } } if (open_index >= 0) { @@ -716,16 +730,20 @@ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf, nfilter->port = intf->port; nfilter->ch = intf->channel + priv->tx_chan_offset; nfilter->hw_index = open_index; + + if (wake_filter) { + /* Claim next filter */ + priv->net_filters[open_index + 1].claimed = true; + priv->net_filters[open_index + 1].wake_filter = true; + priv->net_filters[open_index + 1].hw_index = open_index + 1; + priv->net_filters[open_index + 1].port = intf->port; + priv->net_filters[open_index + 1].ch = intf->channel + + priv->tx_chan_offset; + nfilter->wake_filter = true; + } } - if (wake_filter && open_index >= 0) { - /* Claim next filter */ - priv->net_filters[open_index + 1].claimed = true; - priv->net_filters[open_index + 1].wake_filter = true; - nfilter->wake_filter = true; - } - - return nfilter ? nfilter : ERR_PTR(-EINVAL); + return nfilter ? nfilter : ERR_PTR(-ENOSPC); } void bcmasp_netfilt_release(struct bcmasp_intf *intf, @@ -733,7 +751,8 @@ void bcmasp_netfilt_release(struct bcmasp_intf *intf, { struct bcmasp_priv *priv = intf->parent; - if (nfilt->wake_filter) { + if (nfilt->wake_filter && !(nfilt->hw_index % 2) && + nfilt->hw_index + 1 < priv->num_net_filters) { memset(&priv->net_filters[nfilt->hw_index + 1], 0, sizeof(struct bcmasp_net_filter)); } From 1d0590f96fa4133578b7370ea9ce1d871f6bfc21 Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Fri, 16 Oct 2026 13:14:06 +0300 Subject: [PATCH 2001/2126] bridge: mcast: Delete empty MDB entry when port group creation fails When a port group cannot be created for a new group, the MDB entry that was created for it is left with no ports and is not joined by the host. Its timer is never armed, so the entry is never deleted, but it is counted towards mcast_hash_max. When this maximum is reached, the bridge disables multicast snooping. Since commit b57e8d870d52 ("net: bridge: Maintain number of MDB entries in net_bridge_mcast_port"), port group creation also fails when the port reached its mcast_max_groups limit. A host behind such a port can therefore disable snooping by sending reports for new groups, which is what the limit is meant to prevent. The RTM_NEWMDB path has the same problem. Fix by deleting the entry after a failure if it is unused. Delete it immediately rather than arming its timer, so that it stops counting towards the maximum right away. Fixes: b57e8d870d52 ("net: bridge: Maintain number of MDB entries in net_bridge_mcast_port") Reported-by: Yunlong Ma Closes: https://lore.kernel.org/netdev/2f5b61e2.1e71a.1a11fcb3809.Coremail.yunlong_ma@buaa.edu.cn/ Acked-by: Nikolay Aleksandrov Signed-off-by: Ido Schimmel Tested-by: Gabriel Goller Reviewed-by: Gabriel Goller Link: https://patch.msgid.link/20261016101407.2030133-2-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- net/bridge/br_mdb.c | 16 +++++++++++++--- net/bridge/br_multicast.c | 9 +++++++++ net/bridge/br_private.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index a01bd280c722..0adcd1524ab2 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -819,6 +819,7 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg, struct br_mdb_config sg_cfg; struct br_ip sg_ip; u8 flags = 0; + int err; sg_ip = cfg->group; sg_ip.src = src_ip->src; @@ -842,7 +843,11 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg, sg_cfg.filter_mode = MCAST_INCLUDE; sg_cfg.rt_protocol = cfg->rt_protocol; sg_cfg.nlflags = cfg->nlflags; - return br_mdb_add_group_sg(&sg_cfg, sgmp, brmctx, flags, extack); + err = br_mdb_add_group_sg(&sg_cfg, sgmp, brmctx, flags, extack); + if (err) + br_multicast_del_group(sgmp); + + return err; } static int br_mdb_add_group_src(const struct br_mdb_config *cfg, @@ -1047,6 +1052,7 @@ static int br_mdb_add_group(const struct br_mdb_config *cfg, struct net_bridge_mcast *brmctx; struct br_ip group = cfg->group; unsigned char flags = 0; + int err; brmctx = __br_mdb_choose_context(br, entry, extack); if (!brmctx) @@ -1073,9 +1079,13 @@ static int br_mdb_add_group(const struct br_mdb_config *cfg, flags |= MDB_PG_FLAGS_PERMANENT; if (br_multicast_is_star_g(&group)) - return br_mdb_add_group_star_g(cfg, mp, brmctx, flags, extack); + err = br_mdb_add_group_star_g(cfg, mp, brmctx, flags, extack); else - return br_mdb_add_group_sg(cfg, mp, brmctx, flags, extack); + err = br_mdb_add_group_sg(cfg, mp, brmctx, flags, extack); + if (err) + br_multicast_del_group(mp); + + return err; } static int __br_mdb_add(const struct br_mdb_config *cfg, diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 3fbad7b59769..ecc74b73a3e1 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -647,6 +647,14 @@ static void br_multicast_del_mdb_entry(struct net_bridge_mdb_entry *mp) queue_work(system_long_wq, &br->mcast_gc_work); } +void br_multicast_del_group(struct net_bridge_mdb_entry *mp) +{ + if (mp->ports || mp->host_joined) + return; + + br_multicast_del_mdb_entry(mp); +} + static void br_multicast_group_expired(struct timer_list *t) { struct net_bridge_mdb_entry *mp = timer_container_of(mp, t, timer); @@ -1554,6 +1562,7 @@ __br_multicast_add_group(struct net_bridge_mcast *brmctx, p = br_multicast_new_port_group(pmctx->port, group, *pp, 0, src, filter_mode, RTPROT_KERNEL, NULL); if (unlikely(!p)) { + br_multicast_del_group(mp); p = ERR_PTR(-ENOMEM); goto out; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index b01997ea9508..ff746f036f54 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -998,6 +998,7 @@ struct net_bridge_mdb_entry * br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst); struct net_bridge_mdb_entry * br_multicast_new_group(struct net_bridge *br, struct br_ip *group); +void br_multicast_del_group(struct net_bridge_mdb_entry *mp); struct net_bridge_port_group * br_multicast_new_port_group(struct net_bridge_port *port, const struct br_ip *group, From 335ae22c2e9db0514fd27615b9bf0c9e2a8302cf Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Fri, 16 Oct 2026 13:14:07 +0300 Subject: [PATCH 2002/2126] selftests: forwarding: bridge_mdb_max: Add a test for rejected MDB entries Add a test that checks that MDB entries that are rejected because the port reached its maximum number of MDB entries (mcast_max_groups) do not count towards the maximum number of MDB entries in the bridge (mcast_hash_max). The test lowers mcast_hash_max so that only three more entries can be added. It then configures the port's maximum so that new (*, G) entries are rejected and tries to add four of them. Next, it raises the maximum by one so that a new (*, G) entry is accepted, but its (S, G) entry is rejected, and tries this with four groups. Finally, it checks that multicast snooping was not disabled because the bridge ran out of MDB entries. Like the other tests, the test is run for entries added both by the control path (IGMP / MLD reports) and by the configuration path (RTM_NEWMDB), and for both the port and port-VLAN maximums. Without "bridge: mcast: Delete empty MDB entry when port group creation fails", the new tests fail (other tests omitted): # ./bridge_mdb_max.sh INFO: 802.1d tests TEST: cfg4: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: ctl4: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: cfg6: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: ctl6: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries INFO: 802.1q tests TEST: cfg4: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: ctl4: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: cfg6: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: ctl6: port maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries INFO: 802.1q mcast_vlan_snooping 1 tests TEST: cfg4: port_vlan maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: ctl4: port_vlan maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: cfg6: port_vlan maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries TEST: ctl6: port_vlan maxgroups: rejected entries do not exhaust MDB [FAIL] Multicast snooping disabled by rejected MDB entries Acked-by: Nikolay Aleksandrov Signed-off-by: Ido Schimmel Tested-by: Gabriel Goller Reviewed-by: Gabriel Goller Link: https://patch.msgid.link/20261016101407.2030133-3-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/forwarding/bridge_mdb_max.sh | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/bridge_mdb_max.sh b/tools/testing/selftests/net/forwarding/bridge_mdb_max.sh index 625162fd7e8b..4ebffe4588a2 100755 --- a/tools/testing/selftests/net/forwarding/bridge_mdb_max.sh +++ b/tools/testing/selftests/net/forwarding/bridge_mdb_max.sh @@ -399,6 +399,24 @@ bridge_port_vlan_maxgroups_set() bridge vlan set $locus mcast_max_groups $max } +bridge_mcast_snooping_get() +{ + ip -j -d link show dev br0 | + jq '.[].linkinfo.info_data.mcast_snooping' +} + +bridge_mcast_hash_max_get() +{ + ip -j -d link show dev br0 | + jq '.[].linkinfo.info_data.mcast_hash_max' +} + +bridge_mdb_entries_count() +{ + bridge -j mdb show dev br0 | + jq '[.[].mdb[] | [.grp, .src, .vid]] | unique | length' +} + test_ngroups_reporting() { local CFG=$1; shift @@ -938,6 +956,114 @@ test_8021qvs_maxgroups_too_many_entries_ctl6() test_maxgroups_too_many_entries ctl6 port_vlan "dev $swp1 vid 10" } +test_maxgroups_hash_max() +{ + local CFG=$1; shift + local context=$1; shift + local locus=$1; shift + + local hash_max n i + + RET=0 + + hash_max=$(bridge_mcast_hash_max_get) + + # Make sure the port has entries, so that max == n is not 0 (no limit). + ${CFG}_entries_add "$locus" temp 2 120 + check_err $? "$locus: Couldn't add MDB entries" + n=$(bridge_${context}_ngroups_get "$locus") + + # Leave room for three more MDB entries. + ip link set dev br0 type bridge \ + mcast_hash_max $(($(bridge_mdb_entries_count) + 3)) + check_err $? "Couldn't set mcast_hash_max" + + # Port at its maximum: (*, G) entries are rejected. + bridge_${context}_maxgroups_set "$locus" "$n" + check_err $? "$locus: Couldn't set maximum" + for i in $(seq 121 124); do + ${CFG}_entries_add "$locus" temp 2 "$i" &> /dev/null + done + + # One more slot: (*, G) is accepted, (S, G) is rejected. + bridge_${context}_maxgroups_set "$locus" $((n + 1)) + check_err $? "$locus: Couldn't set maximum" + for i in $(seq 125 128); do + ${CFG}_entries_add "$locus" temp 2 "$i" &> /dev/null + done + + [[ $(bridge_mcast_snooping_get) == 1 ]] + check_err $? "Multicast snooping disabled by rejected MDB entries" + + bridge mdb flush dev br0 + ip link set dev br0 type bridge mcast_snooping 1 + ip link set dev br0 type bridge mcast_hash_max "$hash_max" + bridge_${context}_maxgroups_set "$locus" 0 + check_err $? "$locus: Couldn't set maximum to 0" + + log_test "$CFG: $context maxgroups: rejected entries do not exhaust MDB" +} + +test_8021d_maxgroups_hash_max_cfg4() +{ + test_maxgroups_hash_max cfg4 port "dev $swp1" +} + +test_8021d_maxgroups_hash_max_ctl4() +{ + test_maxgroups_hash_max ctl4 port "dev $swp1" +} + +test_8021d_maxgroups_hash_max_cfg6() +{ + test_maxgroups_hash_max cfg6 port "dev $swp1" +} + +test_8021d_maxgroups_hash_max_ctl6() +{ + test_maxgroups_hash_max ctl6 port "dev $swp1" +} + +test_8021q_maxgroups_hash_max_cfg4() +{ + test_maxgroups_hash_max cfg4 port "dev $swp1 vid 10" +} + +test_8021q_maxgroups_hash_max_ctl4() +{ + test_maxgroups_hash_max ctl4 port "dev $swp1 vid 10" +} + +test_8021q_maxgroups_hash_max_cfg6() +{ + test_maxgroups_hash_max cfg6 port "dev $swp1 vid 10" +} + +test_8021q_maxgroups_hash_max_ctl6() +{ + test_maxgroups_hash_max ctl6 port "dev $swp1 vid 10" +} + +test_8021qvs_maxgroups_hash_max_cfg4() +{ + test_maxgroups_hash_max cfg4 port_vlan "dev $swp1 vid 10" +} + +test_8021qvs_maxgroups_hash_max_ctl4() +{ + test_maxgroups_hash_max ctl4 port_vlan "dev $swp1 vid 10" +} + +test_8021qvs_maxgroups_hash_max_cfg6() +{ + test_maxgroups_hash_max cfg6 port_vlan "dev $swp1 vid 10" +} + +test_8021qvs_maxgroups_hash_max_ctl6() +{ + test_maxgroups_hash_max ctl6 port_vlan "dev $swp1 vid 10" +} + test_maxgroups_too_many_cross_vlan() { local CFG=$1; shift @@ -1177,6 +1303,7 @@ test_8021d_maxgroups_cfg4() test_8021d_maxgroups_zero_cfg4 test_8021d_maxgroups_too_low_cfg4 test_8021d_maxgroups_too_many_entries_cfg4 + test_8021d_maxgroups_hash_max_cfg4 } test_8021d_maxgroups_ctl4() @@ -1184,6 +1311,7 @@ test_8021d_maxgroups_ctl4() test_8021d_maxgroups_zero_ctl4 test_8021d_maxgroups_too_low_ctl4 test_8021d_maxgroups_too_many_entries_ctl4 + test_8021d_maxgroups_hash_max_ctl4 } test_8021d_maxgroups_cfg6() @@ -1191,6 +1319,7 @@ test_8021d_maxgroups_cfg6() test_8021d_maxgroups_zero_cfg6 test_8021d_maxgroups_too_low_cfg6 test_8021d_maxgroups_too_many_entries_cfg6 + test_8021d_maxgroups_hash_max_cfg6 } test_8021d_maxgroups_ctl6() @@ -1198,6 +1327,7 @@ test_8021d_maxgroups_ctl6() test_8021d_maxgroups_zero_ctl6 test_8021d_maxgroups_too_low_ctl6 test_8021d_maxgroups_too_many_entries_ctl6 + test_8021d_maxgroups_hash_max_ctl6 } test_8021q_maxgroups_cfg4() @@ -1205,6 +1335,7 @@ test_8021q_maxgroups_cfg4() test_8021q_maxgroups_zero_cfg4 test_8021q_maxgroups_too_low_cfg4 test_8021q_maxgroups_too_many_entries_cfg4 + test_8021q_maxgroups_hash_max_cfg4 } test_8021q_maxgroups_ctl4() @@ -1212,6 +1343,7 @@ test_8021q_maxgroups_ctl4() test_8021q_maxgroups_zero_ctl4 test_8021q_maxgroups_too_low_ctl4 test_8021q_maxgroups_too_many_entries_ctl4 + test_8021q_maxgroups_hash_max_ctl4 } test_8021q_maxgroups_cfg6() @@ -1219,6 +1351,7 @@ test_8021q_maxgroups_cfg6() test_8021q_maxgroups_zero_cfg6 test_8021q_maxgroups_too_low_cfg6 test_8021q_maxgroups_too_many_entries_cfg6 + test_8021q_maxgroups_hash_max_cfg6 } test_8021q_maxgroups_ctl6() @@ -1226,6 +1359,7 @@ test_8021q_maxgroups_ctl6() test_8021q_maxgroups_zero_ctl6 test_8021q_maxgroups_too_low_ctl6 test_8021q_maxgroups_too_many_entries_ctl6 + test_8021q_maxgroups_hash_max_ctl6 } test_8021qvs_maxgroups_cfg4() @@ -1234,6 +1368,7 @@ test_8021qvs_maxgroups_cfg4() test_8021qvs_maxgroups_zero_cross_vlan_cfg4 test_8021qvs_maxgroups_too_low_cfg4 test_8021qvs_maxgroups_too_many_entries_cfg4 + test_8021qvs_maxgroups_hash_max_cfg4 test_8021qvs_maxgroups_too_many_cross_vlan_cfg4 } @@ -1243,6 +1378,7 @@ test_8021qvs_maxgroups_ctl4() test_8021qvs_maxgroups_zero_cross_vlan_ctl4 test_8021qvs_maxgroups_too_low_ctl4 test_8021qvs_maxgroups_too_many_entries_ctl4 + test_8021qvs_maxgroups_hash_max_ctl4 test_8021qvs_maxgroups_too_many_cross_vlan_ctl4 } @@ -1252,6 +1388,7 @@ test_8021qvs_maxgroups_cfg6() test_8021qvs_maxgroups_zero_cross_vlan_cfg6 test_8021qvs_maxgroups_too_low_cfg6 test_8021qvs_maxgroups_too_many_entries_cfg6 + test_8021qvs_maxgroups_hash_max_cfg6 test_8021qvs_maxgroups_too_many_cross_vlan_cfg6 } @@ -1261,6 +1398,7 @@ test_8021qvs_maxgroups_ctl6() test_8021qvs_maxgroups_zero_cross_vlan_ctl6 test_8021qvs_maxgroups_too_low_ctl6 test_8021qvs_maxgroups_too_many_entries_ctl6 + test_8021qvs_maxgroups_hash_max_ctl6 test_8021qvs_maxgroups_too_many_cross_vlan_ctl6 } From 4f29e69cf1d844a81465439dd58339c48b10b994 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 16 Oct 2026 11:49:25 +0200 Subject: [PATCH 2003/2126] iavf: use skb_put_padto() Replace skb_pad() and the manual skb->len and tail pointer updates in iavf_xmit_frame() with skb_put_padto(). No functional change. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261016094925.2762785-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/iavf/iavf_txrx.c b/drivers/net/ethernet/intel/iavf/iavf_txrx.c index c30abf17cf5d..8982cf75466f 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_txrx.c +++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.c @@ -2396,12 +2396,8 @@ netdev_tx_t iavf_xmit_frame(struct sk_buff *skb, struct net_device *netdev) /* hardware can't handle really short frames, hardware padding works * beyond this point */ - if (unlikely(skb->len < IAVF_MIN_TX_LEN)) { - if (skb_pad(skb, IAVF_MIN_TX_LEN - skb->len)) - return NETDEV_TX_OK; - skb->len = IAVF_MIN_TX_LEN; - skb_set_tail_pointer(skb, IAVF_MIN_TX_LEN); - } + if (skb_put_padto(skb, IAVF_MIN_TX_LEN)) + return NETDEV_TX_OK; return iavf_xmit_frame_ring(skb, tx_ring); } From 8754a53984e6f95b9cee7377d43724be1fa89551 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 16 Oct 2026 11:43:12 +0200 Subject: [PATCH 2004/2126] fm10k: use skb_put_padto() Replace the open-coded skb_pad() + __skb_put() sequence in fm10k_xmit_frame() with skb_put_padto(). Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261016094312.2759956-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c index c86701be4364..669a02c6415c 100644 --- a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +++ b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c @@ -561,13 +561,8 @@ static netdev_tx_t fm10k_xmit_frame(struct sk_buff *skb, struct net_device *dev) /* The minimum packet size for a single buffer is 17B so pad the skb * in order to meet this minimum size requirement. */ - if (unlikely(skb->len < 17)) { - int pad_len = 17 - skb->len; - - if (skb_pad(skb, pad_len)) - return NETDEV_TX_OK; - __skb_put(skb, pad_len); - } + if (skb_put_padto(skb, 17)) + return NETDEV_TX_OK; if (r_idx >= num_tx_queues) r_idx %= num_tx_queues; From 42ee6e77ab4592ab43a7724f57f1942a7267b505 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 16 Oct 2026 11:35:18 +0200 Subject: [PATCH 2005/2126] hinic: use skb_put_padto() hinic_xmit_frame() pads short frames with skb_pad(), then sets skb->len directly, leaving skb->tail stale. Use skb_put_padto(), which updates both and is a litle less confusing. Also remove one pointless netdev_err() call. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261016093518.2756935-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/huawei/hinic/hinic_tx.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/huawei/hinic/hinic_tx.c b/drivers/net/ethernet/huawei/hinic/hinic_tx.c index 9b60966736db..899d103f2480 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_tx.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_tx.c @@ -563,14 +563,8 @@ netdev_tx_t hinic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) txq = &nic_dev->txqs[q_id]; qp = container_of(txq->sq, struct hinic_qp, sq); - if (skb->len < MIN_SKB_LEN) { - if (skb_pad(skb, MIN_SKB_LEN - skb->len)) { - netdev_err(netdev, "Failed to pad skb\n"); - goto update_error_stats; - } - - skb->len = MIN_SKB_LEN; - } + if (skb_put_padto(skb, MIN_SKB_LEN)) + goto update_error_stats; nr_sges = skb_shinfo(skb)->nr_frags + 1; if (nr_sges > 17) { From 69ab87acc614cbe0bd08a65ece6e1aabee805106 Mon Sep 17 00:00:00 2001 From: Erfan Sharafzadeh Date: Tue, 13 Oct 2026 14:09:54 -0700 Subject: [PATCH 2006/2126] net: devmem: allow peer-to-peer dma-buf attach for bindings net_devmem_bind_dmabuf() uses dma_buf_attach(), a static attachment with peer2peer false. Exporters must then keep the buffer reachable without P2P; amdgpu does so by placing it in GTT (system memory), so a device memory binding silently ends up in host memory. Use dma_buf_dynamic_attach() with allow_peer2peer set, so an exporter that can do P2P to the device keeps the buffer in device memory. Dynamic attachments are not pinned on map, and devmem cannot handle the buffer moving, so: - pin it with dma_buf_pin() before mapping, which keeps it in place for the lifetime of the binding, as before; - wait for the exporter's kernel fences after mapping, interruptibly, as the core does for static attachments. This follows the pinned RDMA umem path, including its limits: the binding cannot be revoked by the exporter, and once a P2P binding has pinned a buffer in device memory, a later attachment to the same buffer that cannot do P2P may fail to pin it. Exporters that cannot do P2P to the device place the buffer as before. RX and TX bindings both go through this function. Signed-off-by: Erfan Sharafzadeh Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20261013210954.2170175-1-erfansh@meta.com Signed-off-by: Jakub Kicinski --- net/core/devmem.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 95d714d46c6f..fd1b72744564 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -50,6 +51,10 @@ static void net_iov_free_push(struct net_iov_area *area, freelist[(*free_count)++] = net_iov_idx(niov); } +static const struct dma_buf_attach_ops net_devmem_dmabuf_attach_ops = { + .allow_peer2peer = true, +}; + static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref) { struct net_devmem_dmabuf_binding *binding = @@ -69,8 +74,11 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) binding->area.num_niovs, binding->free_count); kvfree(binding->area.niovs); - dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt, - binding->direction); + dma_resv_lock(binding->dmabuf->resv, NULL); + dma_buf_unmap_attachment(binding->attachment, binding->sgt, + binding->direction); + dma_buf_unpin(binding->attachment); + dma_resv_unlock(binding->dmabuf->resv); dma_buf_detach(binding->dmabuf, binding->attachment); dma_buf_put(binding->dmabuf); xa_destroy(&binding->bound_rxqs); @@ -190,7 +198,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, unsigned int sg_idx; size_t niov_idx; size_t i; - int err; + long err; if (!dma_dev) { NL_SET_ERR_MSG(extack, "Device doesn't support DMA"); @@ -226,19 +234,35 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, binding->dmabuf = dmabuf; binding->direction = direction; - binding->attachment = dma_buf_attach(binding->dmabuf, dma_dev); + binding->attachment = + dma_buf_dynamic_attach(binding->dmabuf, dma_dev, + &net_devmem_dmabuf_attach_ops, binding); if (IS_ERR(binding->attachment)) { err = PTR_ERR(binding->attachment); NL_SET_ERR_MSG(extack, "Failed to bind dmabuf to device"); goto err_exit_ref; } - binding->sgt = dma_buf_map_attachment_unlocked(binding->attachment, - direction); + dma_resv_lock(dmabuf->resv, NULL); + err = dma_buf_pin(binding->attachment); + if (err) { + NL_SET_ERR_MSG(extack, "Failed to pin dmabuf"); + goto err_unlock; + } + + binding->sgt = dma_buf_map_attachment(binding->attachment, direction); if (IS_ERR(binding->sgt)) { err = PTR_ERR(binding->sgt); NL_SET_ERR_MSG(extack, "Failed to map dmabuf attachment"); - goto err_detach; + goto err_unpin; + } + dma_resv_unlock(dmabuf->resv); + + err = dma_resv_wait_timeout(dmabuf->resv, DMA_RESV_USAGE_KERNEL, true, + MAX_SCHEDULE_TIMEOUT); + if (err < 0) { + NL_SET_ERR_MSG(extack, "Failed to wait for dmabuf fences"); + goto err_unmap; } if (!IS_ALIGNED(dmabuf->size, niov_size)) { @@ -332,9 +356,12 @@ err_free_freelist: kvfree(binding->freelist); kvfree(binding->tx_vec); err_unmap: - dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt, - direction); -err_detach: + dma_resv_lock(dmabuf->resv, NULL); + dma_buf_unmap_attachment(binding->attachment, binding->sgt, direction); +err_unpin: + dma_buf_unpin(binding->attachment); +err_unlock: + dma_resv_unlock(dmabuf->resv); dma_buf_detach(dmabuf, binding->attachment); err_exit_ref: percpu_ref_exit(&binding->ref); From b59787892d04a5647a7e662fbb02cd0abdb1a993 Mon Sep 17 00:00:00 2001 From: Sagi Maimon Date: Thu, 15 Oct 2026 11:47:43 +0300 Subject: [PATCH 2007/2126] net: axienet: release every RX buffer in axienet_dma_bd_release() The RX walk in axienet_dma_bd_release() stops at the first descriptor without an skb, assuming that such a slot and all after it were never filled. That holds on the axienet_dma_bd_init() error path, but not once the ring has been running: when axienet_rx_poll() fails to allocate or map a replacement buffer it leaves the slot it emptied with a NULL skb, in the middle of a populated ring, until a later poll refills it. Closing the interface before then leaks the skb and the streaming DMA mapping of every descriptor after that slot, which can be most of the ring, and is most likely under memory pressure. The walk also frees each skb before unmapping it. With swiotlb, the DMA_FROM_DEVICE unmap copies the bounce buffer back into the skb data that was just freed, and on non-coherent platforms it invalidates cache lines that may already belong to a new owner. Skip empty slots instead of stopping at the first one. An emptied slot still has a non-zero cntrl but its buffer is already unmapped, so the skip has to cover the unmap too, which it does by coming before it. Then unmap before freeing, as axienet_rx_poll() does. This was reported by the Sashiko AI review bot. Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes after each of ten down/up cycles, each running axienet_dma_bd_release(), so the unmap-then-free order is exercised on every buffer. A failed RX refill was not reproduced, so the skip over an empty slot was not exercised. Fixes: f26667a373f3 ("net: axienet: Fix DMA descriptor cleanup path") Fixes: 7a7d340ba4d9 ("net: axienet: fix RX ring refill allocation failure handling") Signed-off-by: Sagi Maimon Link: https://patch.msgid.link/20261015084743.1798326-1-maimon.sagi@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 57fcb08ff3df..8a50cad1c104 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -247,13 +247,13 @@ static void axienet_dma_bd_release(struct net_device *ndev) for (i = 0; i < lp->rx_bd_num; i++) { dma_addr_t phys; - /* A NULL skb means this descriptor has not been initialised - * at all. + /* A NULL skb means the descriptor holds no buffer: it was + * never filled, or axienet_rx_poll() took its skb and could + * not refill it, having already unmapped the old buffer. + * Such slots can sit anywhere in a ring that has been running. */ if (!lp->rx_bd_v[i].skb) - break; - - dev_kfree_skb(lp->rx_bd_v[i].skb); + continue; /* For each descriptor, we programmed cntrl with the (non-zero) * descriptor size, after it had been successfully allocated. @@ -264,6 +264,8 @@ static void axienet_dma_bd_release(struct net_device *ndev) dma_unmap_single(lp->dev, phys, lp->max_frm_size, DMA_FROM_DEVICE); } + + dev_kfree_skb(lp->rx_bd_v[i].skb); } dma_free_coherent(lp->dev, From 8ff017b891e89276c15f06dfd7155981d572af77 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 16 Oct 2026 11:15:56 +0200 Subject: [PATCH 2008/2126] ipv6: account route exceptions to the netns of their dst rt6_insert_exception() and rt6_remove_exception() update rt6_stats->fib_rt_cache of dev_net(rt6i->dst.dev), but the device of an exception dst can move to another netns while the exception is still in its bucket. This happens when the bucket is flushed from an RCU callback, for instance from nexthop_free_rcu() for the nh_info of a replaced nexthop, whose exceptions still point to live routes. If the device moves to another netns before that callback runs, the decrement hits the other netns, whose u32 counter underflows in /proc/net/rt6_stats, while the counter of the original netns never goes back down. Account exceptions to the netns their dst was allocated in, derived from dst->ops as ip6_dst_gc() already does, which does not depend on the device. The dst already relies on that netns' ip6_dst_ops being alive when it is destroyed, which happens after the exception is removed. Fixes: 81eb8447daae ("ipv6: take care of rt6_stats") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261016091556.2750902-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ipv6/route.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index a5e955e56e79..2d5b58319808 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1503,6 +1503,15 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net, */ static DEFINE_SPINLOCK(rt6_exception_lock); +/* Exceptions are accounted to the netns their dst was allocated in. + * Unlike dev_net(dst->dev), it does not change when the device moves to + * another netns or when dst_dev_put() points the dst to blackhole_netdev. + */ +static struct net *rt6_exception_net(const struct rt6_info *rt) +{ + return container_of(rt->dst.ops, struct net, ipv6.ip6_dst_ops); +} + /* Remove rt6_ex from hash table and free the memory * Caller must hold rt6_exception_lock */ @@ -1514,7 +1523,7 @@ static void rt6_remove_exception(struct rt6_exception_bucket *bucket, if (!bucket || !rt6_ex) return; - net = dev_net(rt6_ex->rt6i->dst.dev); + net = rt6_exception_net(rt6_ex->rt6i); net->ipv6.rt6_stats->fib_rt_cache--; /* purge completely the exception to allow releasing the held resources: @@ -1783,7 +1792,7 @@ static int rt6_insert_exception(struct rt6_info *nrt, rt6_ex->stamp = jiffies; hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain); bucket->depth++; - net->ipv6.rt6_stats->fib_rt_cache++; + rt6_exception_net(nrt)->ipv6.rt6_stats->fib_rt_cache++; /* Randomize max depth to avoid some side channels attacks. */ max_depth = FIB6_MAX_DEPTH + get_random_u32_below(FIB6_MAX_DEPTH); From f434191f93884c9de58c38f18ac7fc7f1fdf9e42 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 14 Oct 2026 12:48:18 -0700 Subject: [PATCH 2009/2126] net: phy: marvell: keep WOL_EIE across interrupt reconfiguration marvell_config_intr() rewrites the whole interrupt enable register, so the config_intr call from phy_init_hw() on resume silently cleared WOL_EIE on the 88E1318S and 88E1510: m88e1318_get_wol() still reported WAKE_MAGIC, but a matched magic packet was no longer routed to INTn and the board did not wake. Bit 7 of that register is WOL_EIE only on these two PHYs; on others, such as the 88E1111, it enables a FIFO error interrupt. So give the 88E1318S and 88E1510 their own config_intr and handle_interrupt, and leave the shared callbacks unchanged. m88e1318_set_wol() now records whether WoL is enabled, and both it and the new config_intr derive WOL_EIE from that state under the MDIO bus lock. WOL_EIE stays set across config_intr while WoL is enabled, except when the PHY has an interrupt line and interrupts are being disabled, as in phy_free_interrupt(): INTn is then the PHY IRQ, and nothing would read IEVENT after free_irq() to release it. The bit is set again once interrupts are re-enabled. phy_probe() still clears a WOL_EIE left by a previous boot, since WoL starts out disabled. The new handler also claims WoL events, so they do not go unacknowledged when the PHY IRQ is in use. Helios4 (Armada 388, 88E1512), 7.2.9. With this patch WOL_EIE stays set over 3 link down/up cycles, "wol d" clears it, and a magic packet on a running board is a handled interrupt. Without it, WOL_EIE is lost on the first down/up, survives "wol d", and the magic packet is an unhandled interrupt. Fixes: 3871c3876f80 ("mv643xx_eth with 88E1318S: support Wake on LAN") Signed-off-by: Rosen Penev Tested-by: Igor Velkov Link: https://patch.msgid.link/20261014194818.11640-2-rosenp@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/marvell.c | 97 ++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 22 deletions(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index f71cffa88406..94e8dbe9a859 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -55,6 +55,8 @@ #define MII_M1011_IMASK 0x12 #define MII_M1011_IMASK_INIT 0x6400 #define MII_M1011_IMASK_CLEAR 0x0000 +/* WOL Event Interrupt Enable, 88E1318S and 88E1510 only */ +#define MII_M1011_IMASK_WOL BIT(7) #define MII_M1011_PHY_SCR 0x10 #define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11) @@ -139,11 +141,6 @@ #define MII_88E1318S_PHY_MSCR1_REG 16 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) -/* Copper Specific Interrupt Enable Register */ -#define MII_88E1318S_PHY_CSIER 0x12 -/* WOL Event Interrupt Enable */ -#define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7) - #define MII_88E1318S_PHY_LED_FUNC 0x10 #define MII_88E1318S_PHY_LED_FUNC_OFF (0x8) #define MII_88E1318S_PHY_LED_FUNC_ON (0x9) @@ -354,6 +351,7 @@ struct marvell_priv { u32 step; s8 pair; u8 vct_phase; + bool wol_enabled; }; static int marvell_read_page(struct phy_device *phydev) @@ -407,7 +405,8 @@ static int marvell_config_intr(struct phy_device *phydev) return err; } -static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev) +static irqreturn_t __marvell_handle_interrupt(struct phy_device *phydev, + u16 mask) { int irq_status; @@ -417,7 +416,7 @@ static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev) return IRQ_NONE; } - if (!(irq_status & MII_M1011_IMASK_INIT)) + if (!(irq_status & mask)) return IRQ_NONE; phy_trigger_machine(phydev); @@ -425,6 +424,57 @@ static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev) return IRQ_HANDLED; } +static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev) +{ + return __marvell_handle_interrupt(phydev, MII_M1011_IMASK_INIT); +} + +/* WOL_EIE also routes WoL events to INTn. Keep it set while WoL is enabled, + * unless INTn is the PHY interrupt and that interrupt is being disabled: + * nothing would read IEVENT after free_irq() to release the line. + */ +static u16 m88e1318_wol_imask(struct phy_device *phydev) +{ + struct marvell_priv *priv = phydev->priv; + + if (priv->wol_enabled && + (phydev->interrupts == PHY_INTERRUPT_ENABLED || + !phy_interrupt_is_valid(phydev))) + return MII_M1011_IMASK_WOL; + + return 0; +} + +static int m88e1318_config_intr(struct phy_device *phydev) +{ + bool enable = phydev->interrupts == PHY_INTERRUPT_ENABLED; + u16 imask; + int err; + + if (enable) { + err = marvell_ack_interrupt(phydev); + if (err) + return err; + } + + /* Serialise against m88e1318_set_wol() updating wol_enabled */ + phy_lock_mdio_bus(phydev); + imask = enable ? MII_M1011_IMASK_INIT : MII_M1011_IMASK_CLEAR; + imask |= m88e1318_wol_imask(phydev); + err = __phy_write(phydev, MII_M1011_IMASK, imask); + phy_unlock_mdio_bus(phydev); + if (err || enable) + return err; + + return marvell_ack_interrupt(phydev); +} + +static irqreturn_t m88e1318_handle_interrupt(struct phy_device *phydev) +{ + return __marvell_handle_interrupt(phydev, MII_M1011_IMASK_INIT | + MII_M1011_IMASK_WOL); +} + static int marvell_set_polarity(struct phy_device *phydev, int polarity) { u16 val; @@ -1969,18 +2019,27 @@ static void m88e1318_get_wol(struct phy_device *phydev, static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) { + struct marvell_priv *priv = phydev->priv; int err = 0, oldpage; oldpage = phy_save_page(phydev); if (oldpage < 0) goto error; - if (wol->wolopts & (WAKE_MAGIC | WAKE_PHY)) { - /* Explicitly switch to page 0x00, just to be sure */ - err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE); - if (err < 0) - goto error; + priv->wol_enabled = !!(wol->wolopts & (WAKE_MAGIC | WAKE_PHY)); + /* Explicitly switch to page 0x00, just to be sure */ + err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE); + if (err < 0) + goto error; + + /* Update the WOL interrupt enable */ + err = __phy_modify(phydev, MII_M1011_IMASK, MII_M1011_IMASK_WOL, + m88e1318_wol_imask(phydev)); + if (err < 0) + goto error; + + if (priv->wol_enabled) { /* If WOL event happened once, the LED[2] interrupt pin * will not be cleared unless we reading the interrupt status * register. If interrupts are in use, the normal interrupt @@ -1990,12 +2049,6 @@ static int m88e1318_set_wol(struct phy_device *phydev, if (!phy_interrupt_is_valid(phydev)) __phy_read(phydev, MII_M1011_IEVENT); - /* Enable the WOL interrupt */ - err = __phy_set_bits(phydev, MII_88E1318S_PHY_CSIER, - MII_88E1318S_PHY_CSIER_WOL_EIE); - if (err < 0) - goto error; - err = marvell_write_page(phydev, MII_MARVELL_LED_PAGE); if (err < 0) goto error; @@ -3817,8 +3870,8 @@ static struct phy_driver marvell_drivers[] = { .config_init = m88e1318_config_init, .config_aneg = m88e1318_config_aneg, .read_status = marvell_read_status, - .config_intr = marvell_config_intr, - .handle_interrupt = marvell_handle_interrupt, + .config_intr = m88e1318_config_intr, + .handle_interrupt = m88e1318_handle_interrupt, .get_wol = m88e1318_get_wol, .set_wol = m88e1318_set_wol, .resume = genphy_resume, @@ -3925,8 +3978,8 @@ static struct phy_driver marvell_drivers[] = { .config_init = m88e1510_config_init, .config_aneg = m88e1510_config_aneg, .read_status = marvell_read_status, - .config_intr = marvell_config_intr, - .handle_interrupt = marvell_handle_interrupt, + .config_intr = m88e1318_config_intr, + .handle_interrupt = m88e1318_handle_interrupt, .get_wol = m88e1318_get_wol, .set_wol = m88e1318_set_wol, .resume = m88e1510_resume, From e64bff85e3c8fb6e0f55e00b2c4d219a0edb33a8 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Thu, 15 Oct 2026 17:10:33 +0200 Subject: [PATCH 2010/2126] net: Port skb_segment tests of the test_bpf module to KUnit The old test_bpf module is going away, therefore port the two test cases which were added in 76db8087c4c9 ("net: bpf: add a test for skb_segment in test_bpf module") as well as cf204a718357 ("bpf, testing: Introduce 'gso_linear_no_head_frag' skb_segment test") into the net_test.c to retain coverage. With it in place: # Subtest: gso_test_func ok 1 no_gso ok 2 linear ok 3 frags ok 4 frags_pure ok 5 gso_partial ok 6 frag_list ok 7 frag_list_pure ok 8 frag_list_non_uniform ok 9 frag_list_head_frag ok 10 frag_list_no_head_frag ok 11 gso_by_frags ok 12 resegment ok 13 resegment_multi ok 14 resegment_tail ok 15 resegment_one_mss # gso_test_func: pass:15 fail:0 skip:0 total:15 Signed-off-by: Daniel Borkmann Cc: Willem de Bruijn Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20261015151033.591439-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski --- net/core/net_test.c | 76 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/net/core/net_test.c b/net/core/net_test.c index 2bb01430a89f..cebd83e596d0 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -34,6 +34,8 @@ enum gso_test_nr { GSO_TEST_FRAG_LIST, GSO_TEST_FRAG_LIST_PURE, GSO_TEST_FRAG_LIST_NON_UNIFORM, + GSO_TEST_FRAG_LIST_HEAD_FRAG, + GSO_TEST_FRAG_LIST_NO_HEAD_FRAG, GSO_TEST_GSO_BY_FRAGS, GSO_TEST_RESEGMENT, GSO_TEST_RESEGMENT_MULTI, @@ -52,6 +54,10 @@ struct gso_test_case { unsigned int nr_frag_skbs; const unsigned int *frag_skbs; unsigned int max_segs; + const unsigned int *frag_skb_frags; + unsigned int gso_type; + /* skbs from alloc_skb() instead of build_skb(), head_frag clear */ + bool no_head_frag; /* output as expected */ unsigned int nr_segs; @@ -128,6 +134,37 @@ static struct gso_test_case cases[] = { .nr_segs = 4, .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE, GSO_TEST_SIZE, 3 }, }, + { + /* commit 13acc94eff12: frag_list members with linear data in a + * page fragment, shared as a page frag of the segment + */ + .id = GSO_TEST_FRAG_LIST_HEAD_FRAG, + .name = "frag_list_head_frag", + .linear_len = 8, + .nr_frags = 1, + .frags = (const unsigned int[]) { 64 }, + .nr_frag_skbs = 1, + .frag_skbs = (const unsigned int[]) { 8 }, + .frag_skb_frags = (const unsigned int[]) { 64 }, + .gso_type = SKB_GSO_DODGY, + .nr_segs = 1, + .segs = (const unsigned int[]) { 144 }, + }, + { + /* commit 3dcbdb134f32: gso_size smaller than the linear data, + * as after bpf_skb_change_proto() grew the header, with + * frag_list members whose linear data is not in a page fragment + */ + .id = GSO_TEST_FRAG_LIST_NO_HEAD_FRAG, + .name = "frag_list_no_head_frag", + .linear_len = GSO_TEST_SIZE + 20, + .nr_frag_skbs = 1, + .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE + 20 }, + .gso_type = SKB_GSO_DODGY, + .no_head_frag = true, + .nr_segs = 3, + .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE, 40 }, + }, { /* commit 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes") and * commit 90017accff61 ("sctp: Add GSO support") @@ -224,13 +261,18 @@ static void gso_test_func(struct kunit *test) tcase = test->param_value; - page = alloc_page(GFP_KERNEL); - KUNIT_ASSERT_NOT_NULL(test, page); - skb = build_skb(page_address(page), sizeof(hdr) + tcase->linear_len + shinfo_size); + if (tcase->no_head_frag) { + skb = alloc_skb(sizeof(hdr) + tcase->linear_len, GFP_KERNEL); + } else { + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + skb = build_skb(page_address(page), sizeof(hdr) + tcase->linear_len + shinfo_size); + } KUNIT_ASSERT_NOT_NULL(test, skb); __skb_put(skb, sizeof(hdr) + tcase->linear_len); __init_skb(skb); + skb_shinfo(skb)->gso_type = tcase->gso_type; if (tcase->nr_frags) { unsigned int pg_off = 0; @@ -256,24 +298,38 @@ static void gso_test_func(struct kunit *test) struct sk_buff *frag_skb, *prev = NULL; for (i = 0; i < tcase->nr_frag_skbs; i++) { - unsigned int frag_size; - - page = alloc_page(GFP_KERNEL); - KUNIT_ASSERT_NOT_NULL(test, page); + unsigned int frag_size, frag_len; frag_size = tcase->frag_skbs[i]; - frag_skb = build_skb(page_address(page), - frag_size + shinfo_size); + if (tcase->no_head_frag) { + frag_skb = alloc_skb(frag_size, GFP_KERNEL); + } else { + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + frag_skb = build_skb(page_address(page), + frag_size + shinfo_size); + } KUNIT_ASSERT_NOT_NULL(test, frag_skb); __skb_put(frag_skb, frag_size); + frag_len = tcase->frag_skb_frags ? tcase->frag_skb_frags[i] : 0; + if (frag_len) { + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + skb_fill_page_desc(frag_skb, 0, page, 0, frag_len); + + frag_skb->data_len = frag_len; + frag_skb->len += frag_len; + frag_skb->truesize += frag_len; + } + if (prev) prev->next = frag_skb; else skb_shinfo(skb)->frag_list = frag_skb; prev = frag_skb; - total_size += frag_size; + total_size += frag_skb->len; total_true_size += frag_skb->truesize; } From 799cdeaa5c39f75a5e8db7aecd7fa30e7fb958b0 Mon Sep 17 00:00:00 2001 From: Hamza Mahfooz Date: Tue, 13 Oct 2026 17:49:37 -0400 Subject: [PATCH 2011/2126] net: mana: add BQL support MANA doesn't support byte queue limits, so each TX queue can hold 256 WQEs by default, and up to 16384, of up to 64 KB TSO packets, before the qdisc layer sees any backpressure. This adds latency to all the flows sharing a queue, and defeats AQM qdiscs such as fq_codel, which rely on BQL to keep the driver queues short. Report the bytes queued and completed to BQL, except for the XDP_TX and XDP_REDIRECT frames. These share the SQs, but bypass the qdisc and are sent even when the queue is stopped, so BQL can't hold them back. Counting them would let sustained XDP traffic keep the queue stopped, starving the stack, and the TX watchdog would then either fire while the completions still arrive, or, if the XDP sends refreshed trans_start, not fire when the completions stop. The XDP SKBs are marked in their skb->cb, next to the WQE size, so that their completions are skipped as well. Reset the BQL state when destroying the queues, once their NAPI is disabled, since the SKBs still pending after a drain timeout are freed without being completed. Lost TX completions can now stop a queue sooner: it also stops when the bytes in flight exceed the BQL limit, not only when the SQ is full, and the limit may never grow enough to cover the lost bytes. This includes the completions skipped by the WARN_ON_ONCE() early returns in mana_poll_tx_cq(), which already leak SQ space: completing the SKBs already freed there wouldn't reliably balance BQL, since mana_gd_poll_cq() has already consumed the CQEs of the rest of the batch. The TX watchdog then fires, as nothing refreshes the trans_start of a queue stopped by BQL, and its handler resets the queues along with their BQL state. The exception, as before this patch, is XDP traffic keeping the SQ full: each XDP send then stops the queue again, refreshing its trans_start. Tested on two Standard_D16ds_v6 Azure VMs in a proximity placement group, where the throughput is capped at 10.6 Gbps, with the DUT alternately booting net-next (c1c1f0a31712) with and without this patch applied. The throughput stays at the cap with 1, 8 and 64 TCP flows, and the idle TCP_RR latency doesn't change (p50 of 47 us with vs. without the patch). With 16 senders of 64-byte UDP packets, the DUT sends 3.7 to 4.0 Mpps without the patch and 3.7 to 4.1 Mpps with it. With bulk TCP flows sharing the queues, the netperf TCP_RR latency drops (medians of 6 runs): 16 queues, 64 flows: p50 4649 -> 2182 us, p99 5621 -> 2677 us 1 queue, 8 flows: p50 2554 -> 418 us, p99 2723 -> 624 us The standing queue moves from the SQs to fq_codel, which now drops packets: about 2500 qdisc drops and 88K TCP retransmissions per 48 s run with 64 flows, against at most 29 retransmissions before. The retransmissions are about 0.2% of the segments sent. The TCP_RR flows lose no packets, and the packets of the bulk flows are dropped before they reach the wire, so the goodput changes by less than 0.01%. Signed-off-by: Hamza Mahfooz Reviewed-by: Haiyang Zhang Link: https://patch.msgid.link/20261013214937.145312-1-hamzamahfooz@linux.microsoft.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/microsoft/mana/mana_bpf.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 52 ++++++++++++++++--- include/net/mana/mana.h | 2 + 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c index 484f061bc75e..7c55f8724441 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c @@ -21,7 +21,7 @@ void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev) ndevtxq = netdev_get_tx_queue(ndev, txq_idx); __netif_tx_lock(ndevtxq, smp_processor_id()); - rc = mana_start_xmit(skb, ndev); + rc = __mana_start_xmit(skb, ndev, true); __netif_tx_unlock(ndevtxq); diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 489558176a5d..6b7c027e497e 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -346,7 +346,14 @@ clear_flag: rtnl_unlock(); } -netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) +/* skb->cb of the SKBs pending a TX completion */ +struct mana_skb_cb { + struct gdma_posted_wqe_info wqe_info; + bool xdp; +}; + +netdev_tx_t __mana_start_xmit(struct sk_buff *skb, struct net_device *ndev, + bool xdp) { enum mana_tx_pkt_format pkt_fmt = MANA_SHORT_PKT_FMT; struct mana_port_context *apc = netdev_priv(ndev); @@ -360,6 +367,7 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) struct gdma_queue *gdma_sq; int err, len, num_gso_seg; unsigned int csum_type; + struct mana_skb_cb *cb; struct mana_txq *txq; struct mana_cq *cq; @@ -520,14 +528,16 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) goto free_sgl_ptr; } + cb = (struct mana_skb_cb *)skb->cb; + cb->xdp = xdp; + skb_queue_tail(&txq->pending_skbs, skb); len = skb->len; num_gso_seg = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1; net_txq = netdev_get_tx_queue(ndev, txq_idx); - err = mana_gd_post_work_request(gdma_sq, &pkg.wqe_req, - (struct gdma_posted_wqe_info *)skb->cb); + err = mana_gd_post_work_request(gdma_sq, &pkg.wqe_req, &cb->wqe_info); if (!mana_can_tx(gdma_sq)) { netif_tx_stop_queue(net_txq); apc->eth_stats.stop_queue++; @@ -543,6 +553,14 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) err = NETDEV_TX_OK; atomic_inc(&txq->pending_sends); + /* Account the skb in BQL before the doorbell lets the hardware + * complete it. XDP frames bypass the qdisc and BQL can't hold them + * back, so leave them out: XDP traffic could otherwise keep the + * queue stopped, starving the stack and tripping the TX watchdog. + */ + if (!xdp) + netdev_tx_sent_queue(net_txq, len); + mana_gd_wq_ring_doorbell(gd->gdma_context, gdma_sq); /* skb may be freed after mana_gd_post_work_request. Do not use it. */ @@ -574,6 +592,11 @@ tx_drop: return NETDEV_TX_OK; } +netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) +{ + return __mana_start_xmit(skb, ndev, false); +} + #if (MAX_SKB_FRAGS + 2 > MANA_MAX_TX_WQE_SGL_ENTRIES) static netdev_features_t mana_features_check(struct sk_buff *skb, struct net_device *ndev, @@ -1938,9 +1961,10 @@ void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc) static void mana_poll_tx_cq(struct mana_cq *cq) { struct gdma_comp *completions = cq->gdma_comp_buf; - struct gdma_posted_wqe_info *wqe_info; unsigned int pkt_transmitted = 0; unsigned int wqe_unit_cnt = 0; + unsigned int bql_bytes = 0; + unsigned int bql_pkts = 0; unsigned int tx_bytes = 0; struct mana_txq *txq = cq->txq; struct mana_port_context *apc; @@ -1948,6 +1972,7 @@ static void mana_poll_tx_cq(struct mana_cq *cq) struct gdma_queue *gdma_wq; unsigned int avail_space; struct net_device *ndev; + struct mana_skb_cb *cb; struct sk_buff *skb; bool txq_stopped; int comp_read; @@ -2018,12 +2043,16 @@ static void mana_poll_tx_cq(struct mana_cq *cq) if (WARN_ON_ONCE(!skb)) return; - wqe_info = (struct gdma_posted_wqe_info *)skb->cb; - wqe_unit_cnt += wqe_info->wqe_size_in_bu; + cb = (struct mana_skb_cb *)skb->cb; + wqe_unit_cnt += cb->wqe_info.wqe_size_in_bu; mana_unmap_skb(skb, apc); tx_bytes += skb->len; + if (!cb->xdp) { + bql_pkts++; + bql_bytes += skb->len; + } napi_consume_skb(skb, cq->budget); @@ -2038,10 +2067,12 @@ static void mana_poll_tx_cq(struct mana_cq *cq) gdma_wq = txq->gdma_sq; avail_space = mana_gd_wq_avail_space(gdma_wq); + net_txq = txq->net_txq; + netdev_tx_completed_queue(net_txq, bql_pkts, bql_bytes); + /* Ensure tail updated before checking q stop */ smp_mb(); - net_txq = txq->net_txq; txq_stopped = netif_tx_queue_stopped(net_txq); /* Ensure checking txq_stopped before apc->port_is_up. */ @@ -2694,6 +2725,13 @@ static void mana_destroy_txq(struct mana_port_context *apc) apc->tx_qp[i]->txq.napi_initialized = false; } + /* Forget the SKBs freed without being completed after a drain + * timeout, now that NAPI can't complete any. Doing it here also + * covers the queues that a lower channel count won't recreate, + * which could otherwise stay stopped. + */ + netdev_tx_reset_queue(apc->tx_qp[i]->txq.net_txq); + if (apc->tx_qp[i]->tx_object != INVALID_MANA_HANDLE) mana_destroy_wq_obj(apc, GDMA_SQ, apc->tx_qp[i]->tx_object); diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index 8c3dc9d0b299..e1fa9131c490 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -672,6 +672,8 @@ struct mana_port_context { u32 steer_cqe_coalescing; }; +netdev_tx_t __mana_start_xmit(struct sk_buff *skb, struct net_device *ndev, + bool xdp); netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev); int mana_config_rss(struct mana_port_context *ac, enum TRI_STATE rx, bool update_hash, bool update_tab); From 23dd5be7e19ceab8c1c79110ee3552bcabc463ef Mon Sep 17 00:00:00 2001 From: Dimitri Daskalakis Date: Fri, 16 Oct 2026 17:54:01 -0700 Subject: [PATCH 2012/2126] net/mlx5e: Update netdev features only after a successful ringparam set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mlx5 couples HW-GRO with tcp-data-split. If a user sets rx-gro-hw on -> tcp-data-split on -> rx-gro-hw off, the driver will leave HW-GRO on. mlx5e_ethtool_set_tcp_data_split() calls netdev_update_features() when tcp-data-split goes from enabled to disabled in case HW-GRO needs to be released. mlx5e_fix_features() reads the new HDS config from dev->cfg_pending, so HW-GRO is released before all ring parameters are validated. If the subsequent call to mlx5e_ethtool_set_ringparam() fails, the ethtool core discards the pending change and reports tcp-data-split enabled. The device is no longer splitting, and subsequent ring changes are blocked. Move the call to netdev_update_features() after mlx5e_ethtool_set_ringparam() exits successfully. The issue was discovered by manual code inspection during review of a change that stops mlx5 users from disabling tcp-data-split. It was reproduced on a ConnectX-7 with ethtool alone. Steps to reproduce: ethtool -K eth0 rx-gro-hw on ethtool -G eth0 tcp-data-split on ethtool -K eth0 rx-gro-hw off # HW-GRO kept on for tcp-data-split ethtool -G eth0 tcp-data-split off rx 1 # de-sync driver & kernel state netlink error: mlx5_core: rx (1) < min (16) netlink error: Invalid argument ethtool -G eth0 rx 1024 # valid ring changes are now blocked netlink error: mlx5_core: TCP-data-split is not supported when GRO HW is disabled netlink error: Invalid argument This is not a terminal state, users can recover by setting rx-gro-hw on. With the fix, the failing ringparam set leaves rx-gro-hw on and later ring changes succeed. Fixes: 46bcce5dfd33 ("net/mlx5e: Support ethtool tcp-data-split settings") Reported-by: Björn Töpel Closes: https://lore.kernel.org/87se2grw3d.fsf@all.your.base.are.belong.to.us/ Signed-off-by: Dimitri Daskalakis Reviewed-by: Björn Töpel Reviewed-by: Nimrod Oren Acked-by: Tariq Toukan Link: https://patch.msgid.link/20261017005401.1582755-1-dimitri.daskalakis1@gmail.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index 3ed59ced0407..f38e033ab8fa 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -403,11 +403,6 @@ static bool mlx5e_ethtool_set_tcp_data_split(struct mlx5e_priv *priv, return false; } - /* Might need to disable HW-GRO if it was kept on due to hds. */ - if (tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_DISABLED && - dev->cfg->hds_config == ETHTOOL_TCP_DATA_SPLIT_ENABLED) - netdev_update_features(priv->netdev); - return true; } @@ -468,13 +463,23 @@ static int mlx5e_set_ringparam(struct net_device *dev, struct netlink_ext_ack *extack) { struct mlx5e_priv *priv = netdev_priv(dev); + int err; if (!mlx5e_ethtool_set_tcp_data_split(priv, kernel_param->tcp_data_split, extack)) return -EINVAL; - return mlx5e_ethtool_set_ringparam(priv, param, extack); + err = mlx5e_ethtool_set_ringparam(priv, param, extack); + if (err) + return err; + + /* Might need to disable HW-GRO if it was kept on due to hds. */ + if (kernel_param->tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_DISABLED && + dev->cfg->hds_config == ETHTOOL_TCP_DATA_SPLIT_ENABLED) + netdev_update_features(priv->netdev); + + return 0; } void mlx5e_ethtool_get_channels(struct mlx5e_priv *priv, From f6fa1d60ec3ceb7e6c26aa91eadfef34f94014e1 Mon Sep 17 00:00:00 2001 From: Nguyen Ngoc Thang Date: Fri, 16 Oct 2026 23:15:25 +0700 Subject: [PATCH 2013/2126] net/rds: ib: don't enable IRQs in rds_ib_conn_free() __rds_conn_create() calls trans->conn_free() with rds_conn_lock held and IRQs disabled when it loses the race to insert a connection. rds_ib_conn_free() takes the device list lock with spin_lock_irq() and releases it with spin_unlock_irq(), so IRQs are turned on while rds_conn_lock is still held: raw_local_irq_restore() called with IRQs enabled WARNING: kernel/locking/irqflag-debug.c:10 at warn_bogus_irq_restore+0xc/0x20 _raw_spin_unlock_irqrestore+0x67/0x80 __rds_conn_create+0x1de5/0x2290 rds_conn_create_outgoing+0x43/0x60 rds_sendmsg+0xfca/0x20e0 __sys_sendto+0x408/0x5a0 It needs an RDS socket bound to an address on an RDMA device (e.g. rxe) and two concurrent sendto() calls to the same new destination. The TCP and loopback ->conn_free() callbacks already use irqsave, so do the same here. Fixes: 745cbccac3fe ("RDS: Rewrite connection cleanup, fixing oops on rmmod") Reported-by: syzbot+c3741bb338b5c6d6a4aa@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c3741bb338b5c6d6a4aa Cc: stable@vger.kernel.org Signed-off-by: Nguyen Ngoc Thang Signed-off-by: Jakub Kicinski --- net/rds/ib_cm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c index 3ed03ad32812..16bfeaaf3b97 100644 --- a/net/rds/ib_cm.c +++ b/net/rds/ib_cm.c @@ -1284,6 +1284,7 @@ void rds_ib_conn_free(void *arg) { struct rds_ib_connection *ic = arg; spinlock_t *lock_ptr; + unsigned long flags; rdsdebug("ic %p\n", ic); @@ -1294,9 +1295,10 @@ void rds_ib_conn_free(void *arg) */ lock_ptr = ic->rds_ibdev ? &ic->rds_ibdev->spinlock : &ib_nodev_conns_lock; - spin_lock_irq(lock_ptr); + /* May be called with IRQs already disabled (see __rds_conn_create()) */ + spin_lock_irqsave(lock_ptr, flags); list_del(&ic->ib_node); - spin_unlock_irq(lock_ptr); + spin_unlock_irqrestore(lock_ptr, flags); rds_ib_recv_free_caches(ic); From 17271848c9a79cdbee49537cb9a73e7de0906962 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Mon, 19 Oct 2026 08:41:03 +0800 Subject: [PATCH 2014/2126] selftests: net: exit with test failure status The changed four tests can print [FAIL] subtests while still exiting with status 0. Their log_test(), aka log_test_expected() in lib.sh, helpers record a failure in ret, but the scripts never propagate ret to the exit code, so a kselftest runner treats the run as a pass. Initialize ret and exit with it at the end of each script so failed subtests are reflected in the exit status. Signed-off-by: Hangbin Liu Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/fdb_flush.sh | 3 +++ tools/testing/selftests/net/fib-onlink-tests.sh | 3 +++ tools/testing/selftests/net/fib_nexthop_multiprefix.sh | 1 + tools/testing/selftests/net/l2tp.sh | 3 +++ 4 files changed, 10 insertions(+) diff --git a/tools/testing/selftests/net/fdb_flush.sh b/tools/testing/selftests/net/fdb_flush.sh index 4965e52d5ef5..0827fdd60f8c 100755 --- a/tools/testing/selftests/net/fdb_flush.sh +++ b/tools/testing/selftests/net/fdb_flush.sh @@ -6,6 +6,7 @@ # some combinations of arguments. source lib.sh +ret=0 FLUSH_BY_STATE_TESTS=" vxlan_test_flush_by_permanent @@ -778,3 +779,5 @@ for t in $TESTS do setup; $t; cleanup; done + +exit $ret diff --git a/tools/testing/selftests/net/fib-onlink-tests.sh b/tools/testing/selftests/net/fib-onlink-tests.sh index a26075abf7d2..325da693c918 100755 --- a/tools/testing/selftests/net/fib-onlink-tests.sh +++ b/tools/testing/selftests/net/fib-onlink-tests.sh @@ -6,6 +6,7 @@ source lib.sh PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} VERBOSE=0 +ret=0 # Network interfaces # - odd in current namespace; even in peer ns @@ -473,3 +474,5 @@ if [ "$TESTS" != "none" ]; then printf "\nTests passed: %3d\n" ${nsuccess} printf "Tests failed: %3d\n" ${nfail} fi + +exit $ret diff --git a/tools/testing/selftests/net/fib_nexthop_multiprefix.sh b/tools/testing/selftests/net/fib_nexthop_multiprefix.sh index bd0b8a053ea1..2671cff270e5 100755 --- a/tools/testing/selftests/net/fib_nexthop_multiprefix.sh +++ b/tools/testing/selftests/net/fib_nexthop_multiprefix.sh @@ -269,3 +269,4 @@ if [ $ret -eq 0 ]; then fi cleanup +exit $ret diff --git a/tools/testing/selftests/net/l2tp.sh b/tools/testing/selftests/net/l2tp.sh index 41e8b19d1bd3..de4b5da2da1b 100755 --- a/tools/testing/selftests/net/l2tp.sh +++ b/tools/testing/selftests/net/l2tp.sh @@ -16,6 +16,7 @@ source lib.sh VERBOSE=0 PAUSE_ON_FAIL=no +ret=0 which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) @@ -357,3 +358,5 @@ cleanup printf "\nTests passed: %3d\n" ${nsuccess} printf "Tests failed: %3d\n" ${nfail} + +exit $ret From 238164201431a425e48dfcb8e9a59de63caf175b Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Sat, 17 Oct 2026 12:42:28 +0200 Subject: [PATCH 2015/2126] ip6mr: clear skb->cb[] in reg_vif_xmit() reg_vif_xmit() hands the skb to ip6mr_cache_report() as an MRT6MSG_WHOLEPKT report. skb_realloc_headroom() copies skb->cb[] into the report, which is queued to the mroute socket, where rawv6_recvmsg() reads it as IP6CB. By the time the pim6reg device transmits the packet, skb->cb[] is not IP6CB anymore: qdisc_pkt_len_init() overwrites iif and ra, and any qdisc installed on the device (fq, fq_codel, pie, cake...) or a tc BPF program writing skb->cb[] fills the area holding dst0, srcrt, dst1, lastopt and flags. Since commit dd433671fef3 ("ipv6: validate extension header length before copying to cmsg") these stale offsets can no longer cause out-of-bounds reads, but the mroute socket can still receive bogus IPV6_PKTINFO ifindex and extension header ancillary data. Clear IP6CB before building the report. The skb is freed right after, so nothing else depends on its control block. Fixes: 14fb64e1f449 ("[IPV6] MROUTE: Support PIM-SM (SSM).") Signed-off-by: Eric Dumazet Signed-off-by: Jakub Kicinski --- net/ipv6/ip6mr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 36f117ad3670..3a551be30f15 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -653,6 +653,12 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, DEV_STATS_ADD(dev, tx_bytes, skb->len); DEV_STATS_INC(dev, tx_packets); + /* skb->cb[] holds qdisc/tc state at this point, not IP6CB. + * ip6mr_cache_report() copies it to the report delivered to + * the mroute socket, where it is read as IP6CB. + */ + memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); + ip6mr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num), MRT6MSG_WHOLEPKT); rcu_read_unlock(); From 1a4e7bc6e3457ad95515a9d2c042452c3161bb2c Mon Sep 17 00:00:00 2001 From: Yingjie Wang <1075151112@qq.com> Date: Fri, 16 Oct 2026 11:02:58 +0800 Subject: [PATCH 2016/2126] net: unix: reject negative max_dgram_qlen values net.unix.max_dgram_qlen is parsed as a signed int and copied to the u32 sock::sk_max_ack_backlog when an AF_UNIX socket is created. Consequently, a negative value such as -1 is accepted and converted to UINT_MAX. Since the receive queue length is also u32, its fullness check cannot become true for that limit. max_dgram_qlen has no documented negative sentinel. Its existing signed interface represents nonnegative values only through INT_MAX; negative bit patterns are not a supported encoding for the upper half of the u32 consumer range. Switch to proc_dointvec_minmax and make the established 0..INT_MAX input range explicit. This rejects negative values without adding new accepted values or changing the default and zero-value behavior. Very large valid values can still make the queue limit impractical to reach; this change corrects the input domain rather than imposing a new resource ceiling. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Yingjie Wang <1075151112@qq.com> Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/tencent_A643419B56079E9A448D97922763FF069F08@qq.com Signed-off-by: Jakub Kicinski --- Documentation/networking/ip-sysctl.rst | 3 ++- net/unix/sysctl_net_unix.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index f7af0286341c..8edd2eb2ac49 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -3823,5 +3823,6 @@ l3mdev_accept - BOOLEAN max_dgram_qlen - INTEGER The maximum length of dgram socket receive queue - Default: 10 + Possible values: 0 - INT_MAX + Default: 10 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index 47660d5726bb..fa1fbaec3aaf 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c @@ -19,7 +19,9 @@ static const struct ctl_table unix_table[] = { .data = &init_net.unx.sysctl_max_dgram_qlen, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_INT_MAX, }, }; From 56c7aa17f0f09844dcf2c25bbe76fc4a87519192 Mon Sep 17 00:00:00 2001 From: Luiz Angelo Daros de Luca Date: Mon, 19 Oct 2026 01:26:27 -0300 Subject: [PATCH 2017/2126] net: dsa: realtek: use -y in Makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch from -objs to -y to eliminate ifdefs and simplify conditional object list construction. Drop the obsolete trailing comment. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Alvin Šipraga Link: https://patch.msgid.link/20261019-realtek_mkf-v1-1-3246a77d5782@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/realtek/Makefile | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/drivers/net/dsa/realtek/Makefile b/drivers/net/dsa/realtek/Makefile index 72bb42e80c95..0a94a619b2c1 100644 --- a/drivers/net/dsa/realtek/Makefile +++ b/drivers/net/dsa/realtek/Makefile @@ -1,23 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek_dsa.o -realtek_dsa-objs := rtl83xx.o - -ifdef CONFIG_NET_DSA_REALTEK_MDIO -realtek_dsa-objs += realtek-mdio.o -endif - -ifdef CONFIG_NET_DSA_REALTEK_SMI -realtek_dsa-objs += realtek-smi.o -endif +realtek_dsa-y := rtl83xx.o +realtek_dsa-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o +realtek_dsa-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o -rtl8366-objs := rtl8366-core.o rtl8366rb.o -ifdef CONFIG_NET_DSA_REALTEK_RTL8366RB_LEDS -rtl8366-objs += rtl8366rb-leds.o -endif +rtl8366-y := rtl8366-core.o rtl8366rb.o +rtl8366-$(CONFIG_NET_DSA_REALTEK_RTL8366RB_LEDS) += rtl8366rb-leds.o + obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o -rtl8365mb-objs := rtl8365mb_main.o \ - rtl8365mb_table.o \ - rtl8365mb_vlan.o \ - rtl8365mb_l2.o \ -# end of rtl8365mb-objs +rtl8365mb-y := rtl8365mb_main.o \ + rtl8365mb_table.o \ + rtl8365mb_vlan.o \ + rtl8365mb_l2.o From 15b7a86a8888dc6a8fd19e181757e32389de9064 Mon Sep 17 00:00:00 2001 From: Til Kaiser Date: Wed, 14 Oct 2026 19:31:17 +0200 Subject: [PATCH 2018/2126] mlxsw: Initialize register query payloads MFGD register queries can exhaust EMAD retries and leave Mellanox Spectrum switches stuck during boot or shutdown when running OpenWrt built with GCC 15. An example failure is shown below with the second line wrapped: EMAD retries (5/5) (tid=9b544fc100001f35) EMAD reg access failed (tid=9b544fc100001f35,reg_id=90f0(mfgd), type=query,status=0(operation performed)) On an SN2100, the failure occurs during driver teardown on reboot. On an SN3420, it occurs while probing mlxsw_spectrum during boot. The register query API transmits the supplied payload to the device before replacing it with the response. Both MFGD callers pass an uninitialized stack buffer, so the request contains arbitrary register field values and reserved bits. This makes the request depend on stack contents and compiler code generation. Initialize both MFGD query buffers in the firmware fatal event configuration and reporter test paths. The initialization has been confirmed to eliminate the boot and shutdown hangs on both switches. The subsequent read-modify-write still preserves the other fields returned by the device. Also initialize the FORE fan fault query and the MOGCR mirroring policer base query, which pass entirely uninitialized payloads. Restore the MTMP query initialization in the temperature history reset path, where only the slot and sensor index fields are set before querying the register. This follows commit 5b0907407e7f ("mlxsw: core: Zero payload buffers for couple of registers"), which initialized other query payloads after a firmware field length bug caused firmware to consume uninitialized data. Tested with firmware 2020.1148 and with 2016.3900 from linux-firmware. Fixes: 7d83ee111008 ("mlxsw: core: Introduce fw_fatal health reporter") Fixes: 2c6a33cd334b ("mlxsw: core: Extend hwmon interface with fan fault attribute") Fixes: 4039504e6a0c ("mlxsw: spectrum_span: Allow setting policer on a SPAN agent") Fixes: b890ad418e1f ("mlxsw: core_hwmon: Extend internal structures to support multi hwmon objects") Cc: stable@vger.kernel.org Signed-off-by: Til Kaiser Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261014173117.26305-1-mail@tk154.de Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlxsw/core.c | 4 ++-- drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c | 4 ++-- drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 308d8a94865f..42e9689d7f35 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2001,7 +2001,7 @@ mlxsw_core_health_fw_fatal_test(struct devlink_health_reporter *reporter, struct netlink_ext_ack *extack) { struct mlxsw_core *mlxsw_core = devlink_health_reporter_priv(reporter); - char mfgd_pl[MLXSW_REG_MFGD_LEN]; + char mfgd_pl[MLXSW_REG_MFGD_LEN] = {0}; int err; /* Read the register first to make sure no other bits are changed. */ @@ -2022,7 +2022,7 @@ mlxsw_core_health_fw_fatal_ops = { static int mlxsw_core_health_fw_fatal_config(struct mlxsw_core *mlxsw_core, bool enable) { - char mfgd_pl[MLXSW_REG_MFGD_LEN]; + char mfgd_pl[MLXSW_REG_MFGD_LEN] = {0}; int err; /* Read the register first to make sure no other bits are changed. */ diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c index 30f172ce822c..a5e7aee730d6 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c @@ -120,7 +120,7 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev, container_of(attr, struct mlxsw_hwmon_attr, dev_attr); struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev; struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon; - char mtmp_pl[MLXSW_REG_MTMP_LEN]; + char mtmp_pl[MLXSW_REG_MTMP_LEN] = {0}; unsigned long val; int index; int err; @@ -177,7 +177,7 @@ static ssize_t mlxsw_hwmon_fan_fault_show(struct device *dev, container_of(attr, struct mlxsw_hwmon_attr, dev_attr); struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev; struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon; - char fore_pl[MLXSW_REG_FORE_LEN]; + char fore_pl[MLXSW_REG_FORE_LEN] = {0}; bool fault; int err; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index ae63d549b542..d54fe5e61296 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -1720,7 +1720,7 @@ static int mlxsw_sp2_span_init(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp2_span_policer_id_base_set(struct mlxsw_sp *mlxsw_sp, u16 policer_id_base) { - char mogcr_pl[MLXSW_REG_MOGCR_LEN]; + char mogcr_pl[MLXSW_REG_MOGCR_LEN] = {0}; int err; err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mogcr), mogcr_pl); From 7c9cb1edaf8fd8e1af25e39741e603500986ef66 Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Mon, 19 Oct 2026 17:03:36 +0300 Subject: [PATCH 2019/2126] ipv6: Hold RCU when emitting route hardware flags notification fib6_info_hw_flags_set() is called by drivers from process context without RTNL or RCU. When the route uses a nexthop object, rt6_nlmsg_size() and rt6_fill_node() access the nexthop's RCU protected nexthop info and group pointers via rcu_dereference_rtnl(), resulting in suspicious RCU usage splats [1]. Fix by holding RCU while sizing and filling the notification, like fib_alias_hw_flags_set() already does. Switch to GFP_ATOMIC for the skb allocation accordingly. Reproducer: # echo "10 0" > /sys/bus/netdevsim/new_device # sysctl -wq net.ipv6.fib_notify_on_flag_change=1 # sysctl -wq net.ipv4.nexthop_compat_mode=1 # ip -6 nexthop add id 1 blackhole # ip -6 route add 2001:db8:1::1/128 nhid 1 [1] WARNING: suspicious RCU usage 7.3.0-rc7-virtme-g191aa41548b2 #38 Not tainted net/ipv4/nexthop.c:1539 suspicious rcu_dereference_check() usage! [...] Workqueue: events nsim_fib_event_work Call Trace: dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120) lockdep_rcu_suspicious.cold (kernel/locking/lockdep.c:6972) nexthop_for_each_fib6_nh (net/ipv4/nexthop.c:1539 (discriminator 16)) rt6_nlmsg_size (net/ipv6/route.c:5728) fib6_info_hw_flags_set (net/ipv6/route.c:6503) nsim_fib6_rt_add (drivers/net/netdevsim/fib.c:671 drivers/net/netdevsim/fib.c:694) nsim_fib6_rt_insert (drivers/net/netdevsim/fib.c:759) nsim_fib_event_work (drivers/net/netdevsim/fib.c:856 drivers/net/netdevsim/fib.c:889 drivers/net/netdevsim/fib.c:1493) process_one_work (kernel/workqueue.c:3396) worker_thread (kernel/workqueue.c:3479 kernel/workqueue.c:3560) kthread (kernel/kthread.c:436) ret_from_fork (arch/x86/kernel/process.c:158) ret_from_fork_asm (arch/x86/entry/entry_64.S:245) Fixes: 907eea486888 ("net: ipv6: Emit notification when fib hardware flags are changed") Reported-by: Sashiko Closes: https://lore.kernel.org/netdev/179152182668.434549.18232968419539498055@kernel.org/ Signed-off-by: Ido Schimmel Reviewed-by: Eric Dumazet Reviewed-by: David Ahern Link: https://patch.msgid.link/20261019140337.2886875-2-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- net/ipv6/route.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 2d5b58319808..d95baec6b5d3 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -6509,7 +6509,9 @@ void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i, if (!fib_notify_on_flag_change) return; - skb = nlmsg_new(rt6_nlmsg_size(f6i), GFP_KERNEL); + rcu_read_lock(); + + skb = nlmsg_new(rt6_nlmsg_size(f6i), GFP_ATOMIC); if (!skb) { err = -ENOBUFS; goto errout; @@ -6522,10 +6524,13 @@ void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i, goto errout; } + rcu_read_unlock(); + rtnl_notify(skb, net, 0, RTNLGRP_IPV6_ROUTE, NULL, GFP_KERNEL); return; errout: + rcu_read_unlock(); rtnl_set_sk_err(net, RTNLGRP_IPV6_ROUTE, err); } EXPORT_SYMBOL(fib6_info_hw_flags_set); From b5dc3fde8b92286a0cb06bf08e2ec0141cf867bb Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Mon, 19 Oct 2026 17:03:37 +0300 Subject: [PATCH 2020/2126] selftests: netdevsim: Add FIB notification tests for nexthop objects Add IPv4 and IPv6 test cases that program a route that uses a nexthop object and check that two notifications are emitted for it, with the second one carrying the RTM_F_TRAP flag. The new route_nexthop_check() helper follows the same pattern as the existing route_{addition,deletion,replacement}_check() helpers. Without "ipv6: Hold RCU when emitting route hardware flags notification", the IPv6 test case passes, but triggers suspicious RCU usage splats. The IPv4 test case is added for completeness. Signed-off-by: Ido Schimmel Reviewed-by: Eric Dumazet Reviewed-by: David Ahern Link: https://patch.msgid.link/20261019140337.2886875-3-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/netdevsim/fib_notifications.sh | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh b/tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh index 9896580c3d85..c49d6deb621a 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh @@ -8,10 +8,12 @@ ALL_TESTS=" ipv4_route_deletion_test ipv4_route_replacement_test ipv4_route_offload_failed_test + ipv4_route_nexthop_test ipv6_route_addition_test ipv6_route_deletion_test ipv6_route_replacement_test ipv6_route_offload_failed_test + ipv6_route_nexthop_test " NETDEVSIM_PATH=/sys/bus/netdevsim/ @@ -269,6 +271,50 @@ ipv4_route_offload_failed_test() log_test "IPv4 route offload failed" } +route_nexthop_check() +{ + local ip=$1; shift + local route=$1; shift + local nhid=$1; shift + local expected_num_notifications=$1; shift + local outfile + + ip netns exec testns1 sysctl -qw net.$ip.fib_notify_on_flag_change=1 + + outfile=$(mktemp) + + $IP monitor route &> $outfile & + sleep 1 + $IP route add $route nhid $nhid + sleep 1 + kill_process %% + + route_notify_check $outfile $expected_num_notifications + rm -f $outfile + + $IP route del $route nhid $nhid +} + +ipv4_route_nexthop_test() +{ + RET=0 + + local ip="ipv4" + local route=192.0.2.0/24 + local nhid=1 + + $IP -4 nexthop add id $nhid dev dummy1 + + # Make sure two notifications will be emitted for a programmed route + # that uses a nexthop object. + local expected_num_notifications=2 + route_nexthop_check $ip $route $nhid $expected_num_notifications + + $IP nexthop del id $nhid + + log_test "IPv4 route with nexthop object" +} + ipv6_route_addition_test() { RET=0 @@ -385,6 +431,26 @@ ipv6_route_offload_failed_test() log_test "IPv6 route offload failed" } +ipv6_route_nexthop_test() +{ + RET=0 + + local ip="ipv6" + local route=2001:db8:1::/64 + local nhid=1 + + $IP -6 nexthop add id $nhid dev dummy1 + + # Make sure two notifications will be emitted for a programmed route + # that uses a nexthop object. + local expected_num_notifications=2 + route_nexthop_check $ip $route $nhid $expected_num_notifications + + $IP nexthop del id $nhid + + log_test "IPv6 route with nexthop object" +} + setup_prepare() { modprobe netdevsim &> /dev/null From 9043be310c6a4c5e57f7bba4b9870554eac7aa96 Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Mon, 19 Oct 2026 17:54:07 +0200 Subject: [PATCH 2021/2126] team: reject CAN, IEEE 802.15.4 and 6LoWPAN devices in team_port_add When the first port has a non-Ethernet type, team_setup_by_port() copies port_dev->type to the team device while netdev_priv() of the team device still holds a struct team. Several L2 stacks identify their devices by dev->type alone and then access type specific data that the team driver never sets up: - CAN protocols rely on the CAN mid-layer private data (ml_priv) - IEEE 802.15.4 code dereferences ieee802154_ptr and the mlme ops in ml_priv - the 6LoWPAN netdev notifier writes through lowpan_dev(dev) on NETDEV_DOWN and reads it on NETDEV_UP/NETDEV_CHANGE Enslaving such a device (e.g. vxcan, wpan0, lowpan0) therefore leads to NULL pointer dereferences or to writes into struct team. This is the same problem that syzbot reported for the bonding driver with a vxcan device enslaved to a bond master, which crashed in can_rx_unregister() and was fixed by commit 8ba68464e478 ("bonding: refuse to enslave CAN devices"). The team driver has the same gap. Reject ARPHRD_CAN, ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR and ARPHRD_6LOWPAN devices in team_port_add(). Link: https://lore.kernel.org/all/b58d98e0-8fe3-4e4e-b8a5-c1c7e647ccca@hartkopp.net/ Link: https://syzkaller.appspot.com/bug?extid=8ed98cbd0161632bce95 # bonding splat Fixes: 1d76efe1577b ("team: add support for non-ethernet devices") Signed-off-by: Jiale Yao Signed-off-by: Oliver Hartkopp Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20261019155407.61487-1-socketcan@hartkopp.net Signed-off-by: Jakub Kicinski --- drivers/net/team/team_core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c index ca75f08e3c59..957cc7885d2f 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -1225,6 +1225,17 @@ static int team_port_add(struct team *team, struct net_device *port_dev, return -EINVAL; } + if (port_dev->type == ARPHRD_CAN || + port_dev->type == ARPHRD_IEEE802154 || + port_dev->type == ARPHRD_IEEE802154_MONITOR || + port_dev->type == ARPHRD_6LOWPAN) { + NL_SET_ERR_MSG(extack, + "CAN, IEEE 802.15.4 and 6LoWPAN devices can't be added as a team port"); + netdev_err(dev, "Device %s is CAN, IEEE 802.15.4 or 6LoWPAN. These device types can't be added as a team port\n", + portname); + return -EINVAL; + } + if (netif_is_team_port(port_dev)) { NL_SET_ERR_MSG(extack, "Device is already a port of a team device"); netdev_err(dev, "Device %s is already a port " From acfb9c263d70b93f05240b136d7765b096c66956 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:31 +0800 Subject: [PATCH 2022/2126] net: mctp: usblib: Add to parameterized kunit tests. Add parameterized tests to cover worst case scenarios for packet splitting and length. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-1-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 9df401a914ff..4c27307900fb 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -386,12 +386,18 @@ static const struct mctp_usblib_test_pkt_span mctp_usblib_test_pkt_spans[] = { { "1p2x-split-mctphdr", 1, { 16 }, 2, { 6, 10 } }, /* Single packet split over 3 transfers, middle entirely continuation */ { "1p3x-split", 1, { 12 }, 3, { 4, 4, 4 } }, + /* A packet split over 5 transfers, splitting on and between each header. */ + { "1p5x-split", 1, { 12 }, 5, { 3, 1, 1, 3, 4}}, /* Max-sized single transfer */ { "1p1x-large", 1, { 8191 }, 1, { 8191 } }, /* Two large packets, split at the worst-case for allocation, with a * single byte continuing the span */ - { "2p2x-large-split", 2, { 8190, 8190 }, 2, { 8191, 8189 } }, + { "2p2x-large-split", 2, { 8190, 8191 }, 2, { 8191, 8190 } }, + /* Three large packets, split at the worst-case for allocation, + * with a single byte continuing each span + */ + { "3p3x-large-split", 3, { 8190, 8191, 8191 }, 3, { 8191, 8191, 8190 } }, }; KUNIT_ARRAY_PARAM(mctp_usblib_test_rx_pkt_span, mctp_usblib_test_pkt_spans, From 21e1d4515755be34172e4776e4c288d64e01b3c5 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:32 +0800 Subject: [PATCH 2023/2126] net: mctp: usblib: Add test for splits inside headers Add test covering every possible split of a packet's headers between transfers and remove parameterized tests that are now covered. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-2-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 71 ++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 4c27307900fb..2d91cba9efee 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -14,6 +14,8 @@ #include #include +#define HDR_LEN sizeof(struct mctp_usb_hdr) + struct mctp_usblib_test_dev { struct net_device *ndev; struct mctp_dev *mdev; @@ -378,12 +380,6 @@ static const struct mctp_usblib_test_pkt_span mctp_usblib_test_pkt_spans[] = { { "1p1x-complete", 1, { 8 }, 1, { 8 } }, /* Two small packets combined within one transfer */ { "2p1x-combined", 2, { 8, 8 }, 1, { 16 } }, - /* A packet split over two transfers, at the MCTP payload */ - { "1p2x-split-payload", 1, { 16 }, 2, { 8, 8 } }, - /* A packet split over two transfers, at the USB transport header */ - { "1p2x-split-usbhdr", 1, { 16 }, 2, { 2, 14 } }, - /* A packet split over two transfers, at the MCTP header */ - { "1p2x-split-mctphdr", 1, { 16 }, 2, { 6, 10 } }, /* Single packet split over 3 transfers, middle entirely continuation */ { "1p3x-split", 1, { 12 }, 3, { 4, 4, 4 } }, /* A packet split over 5 transfers, splitting on and between each header. */ @@ -403,10 +399,73 @@ static const struct mctp_usblib_test_pkt_span mctp_usblib_test_pkt_spans[] = { KUNIT_ARRAY_PARAM(mctp_usblib_test_rx_pkt_span, mctp_usblib_test_pkt_spans, mctp_usblib_test_pkt_span_to_desc); +static void mctp_usblib_test_rx_split_header(struct kunit *test, size_t offset, + struct mctp_usblib_test_dev *dev, + struct mctp_usblib_rx *rx) +{ + struct sk_buff *skb; + size_t buflen, len; + u8 packet[16]; + void *buf; + int rc; + + len = sizeof(packet); + mctp_usblib_test_init_pkt(packet, len, len); + + rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_GE(test, buflen, len); + + memcpy(buf, packet, offset); + mctp_usblib_test_rx_complete(dev->ndev, rx, offset); + + rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, + GFP_KERNEL); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_GE(test, buflen, len); + KUNIT_ASSERT_EQ(test, dev->rx_pkts.qlen, 0); + + memcpy(buf, packet + offset, len - offset); + rc = mctp_usblib_test_rx_complete(dev->ndev, rx, len - offset); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 1); + + skb = __skb_dequeue(&dev->rx_pkts); + KUNIT_EXPECT_NOT_NULL(test, skb); + if (skb) { + KUNIT_EXPECT_EQ(test, skb->len, len - HDR_LEN); + kfree_skb(skb); + } +} + +static void mctp_usblib_test_rx_header_splits(struct kunit *test) +{ + struct mctp_usblib_test_dev *dev; + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_rx *rx; + + ctx = mctp_usblib_test_init(test); + rx = mctp_usblib_test_rx_init(test, true); + dev = ctx->dev; + + /* Unrolling here so stack traces point to the invocation with the + * failing length. + */ + mctp_usblib_test_rx_split_header(test, 1, dev, rx); + mctp_usblib_test_rx_split_header(test, 2, dev, rx); + mctp_usblib_test_rx_split_header(test, 3, dev, rx); + mctp_usblib_test_rx_split_header(test, 4, dev, rx); + mctp_usblib_test_rx_split_header(test, 5, dev, rx); + mctp_usblib_test_rx_split_header(test, 6, dev, rx); + mctp_usblib_test_rx_split_header(test, 7, dev, rx); + mctp_usblib_test_rx_split_header(test, 8, dev, rx); +} + static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_single), KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span, mctp_usblib_test_rx_pkt_span_gen_params), + KUNIT_CASE(mctp_usblib_test_rx_header_splits), {} }; From c0a372f7297250524845eae6cc41ce69d7838eb0 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:33 +0800 Subject: [PATCH 2024/2126] net: mctp: usblib: Add tests of invalid headers Add tests where the length field of the USB transport header is below the minimum value, and where the DMTF ID is invalid. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-3-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 2d91cba9efee..44389c0451c1 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -461,11 +461,79 @@ static void mctp_usblib_test_rx_header_splits(struct kunit *test) mctp_usblib_test_rx_split_header(test, 8, dev, rx); } +/* Test the submission of a packet with an impossibly small value in the + * header's length field. Values less than HDR_LEN are invalid. + */ +static void mctp_usblib_test_rx_short_packet(struct kunit *test) +{ + struct mctp_usblib_test_dev *dev; + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_rx *rx; + size_t len, buflen; + u8 pktbuf[12]; + void *buf; + int rc; + + ctx = mctp_usblib_test_init(test); + rx = mctp_usblib_test_rx_init(test, true); + dev = ctx->dev; + + len = sizeof(pktbuf); + mctp_usblib_test_init_pkt(pktbuf, len, HDR_LEN - 1); + + buflen = 0; + rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_GE(test, buflen, len); + + memcpy(buf, pktbuf, len); + + rc = mctp_usblib_rx_complete(dev->ndev, rx, len); + KUNIT_EXPECT_EQ(test, rc, -EPROTO); + KUNIT_EXPECT_NULL(test, rx->skb); + KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0); +} + +static void mctp_usblib_test_rx_invalid_dmtf_id(struct kunit *test) +{ + struct mctp_usblib_test_dev *dev; + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_rx *rx; + size_t len, buflen; + u8 pktbuf[12]; + void *buf; + int rc; + + ctx = mctp_usblib_test_init(test); + rx = mctp_usblib_test_rx_init(test, true); + dev = ctx->dev; + + len = sizeof(pktbuf); + mctp_usblib_test_init_pkt(pktbuf, len, len); + + /* Make packet DMTF ID invalid */ + pktbuf[1] = ~pktbuf[1]; + + buflen = 0; + rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_GE(test, buflen, len); + + memcpy(buf, pktbuf, len); + + rc = mctp_usblib_rx_complete(dev->ndev, rx, len); + KUNIT_EXPECT_EQ(test, rc, -EPROTO); + KUNIT_EXPECT_NULL(test, rx->skb); + KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0); +} + static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_single), KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span, mctp_usblib_test_rx_pkt_span_gen_params), KUNIT_CASE(mctp_usblib_test_rx_header_splits), + KUNIT_CASE(mctp_usblib_test_rx_short_packet), + KUNIT_CASE(mctp_usblib_test_rx_invalid_dmtf_id), {} }; From 40e59c00ae219f01fe17365df1f69769eb61b0c3 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:34 +0800 Subject: [PATCH 2025/2126] net: mctp: usblib: Complete rx tests Add rx tests without spanning, covering cases where a packet is shorter than allowed without spanning, isn't completed within one submission. Fully cover rx functions except for memory allocation failures and trivial functions. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-4-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 44389c0451c1..ba2cd432355f 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -527,6 +527,66 @@ static void mctp_usblib_test_rx_invalid_dmtf_id(struct kunit *test) KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0); } +static void mctp_usblib_test_rx_nonspanning_tiny(struct kunit *test) +{ + struct mctp_usblib_test_dev *dev; + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_rx *rx; + size_t len, buflen; + u8 pktbuf[3]; + void *buf; + int rc; + + ctx = mctp_usblib_test_init(test); + rx = mctp_usblib_test_rx_init(test, false); + dev = ctx->dev; + + len = sizeof(pktbuf); + mctp_usblib_test_init_pkt(pktbuf, len, len); + + buflen = 0; + rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_GE(test, buflen, len); + + memcpy(buf, pktbuf, len); + + rc = mctp_usblib_rx_complete(dev->ndev, rx, len); + KUNIT_EXPECT_EQ(test, rc, -ENOMSG); + KUNIT_EXPECT_NULL(test, rx->skb); + KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0); +} + +static void mctp_usblib_test_rx_nonspanning_partial(struct kunit *test) +{ + struct mctp_usblib_test_dev *dev; + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_rx *rx; + size_t len, buflen; + u8 pktbuf[20]; + void *buf; + int rc; + + ctx = mctp_usblib_test_init(test); + rx = mctp_usblib_test_rx_init(test, false); + dev = ctx->dev; + + len = sizeof(pktbuf); + mctp_usblib_test_init_pkt(pktbuf, len, len + 1); + + buflen = 0; + rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_GE(test, buflen, len); + + memcpy(buf, pktbuf, len); + + rc = mctp_usblib_rx_complete(dev->ndev, rx, len); + KUNIT_EXPECT_EQ(test, rc, -EPROTO); + KUNIT_EXPECT_NULL(test, rx->skb); + KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0); +} + static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_single), KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span, @@ -534,6 +594,8 @@ static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_header_splits), KUNIT_CASE(mctp_usblib_test_rx_short_packet), KUNIT_CASE(mctp_usblib_test_rx_invalid_dmtf_id), + KUNIT_CASE(mctp_usblib_test_rx_nonspanning_tiny), + KUNIT_CASE(mctp_usblib_test_rx_nonspanning_partial), {} }; From 77cb5c6b3464501eb4dfdb5a5679a7a70bc71570 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:35 +0800 Subject: [PATCH 2026/2126] net: mctp: usblib: Simplify allocation logic in mctp_usblib_test_rx_init The if statement testing rx's allocation is unneeded. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-5-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index ba2cd432355f..4a8761618258 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -202,11 +202,9 @@ mctp_usblib_test_rx_init(struct kunit *test, bool span) int rc; rx = kzalloc_obj(*rx); - if (rx) { - rc = kunit_add_action_or_reset(test, action_rx_fini, rx); - KUNIT_ASSERT_EQ(test, rc, 0); - } KUNIT_ASSERT_NOT_NULL(test, rx); + rc = kunit_add_action_or_reset(test, action_rx_fini, rx); + KUNIT_ASSERT_EQ(test, rc, 0); rc = mctp_usblib_rx_init(rx, ep_maxpacket, span); KUNIT_ASSERT_EQ(test, rc, 0); From 1e12f734afc10477bbe050e424f13cf168ff7f42 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:36 +0800 Subject: [PATCH 2027/2126] net: mctp: usblib: Add initial kunit tx tests Add tests for the transmit path, where MCTP packets are handed to outgoing USB transfer data. Testing a spanning transfer that is expected to succeed, the failure paths when sends fail, and large sequential sends. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-6-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 286 ++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 4a8761618258..16c2c9963d2d 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -6,6 +6,7 @@ * Copyright (C) 2026 Code Construct Pty Ltd */ +#include #include #include #include @@ -16,6 +17,13 @@ #define HDR_LEN sizeof(struct mctp_usb_hdr) +struct tx_buff { + struct list_head list; + + size_t length; + u8 data[] __counted_by(length); +}; + struct mctp_usblib_test_dev { struct net_device *ndev; struct mctp_dev *mdev; @@ -24,9 +32,104 @@ struct mctp_usblib_test_dev { struct mctp_usblib_test_ctx { struct mctp_usblib_test_dev *dev; + struct list_head tx_xfers; struct mctp_route rt; }; +static int mctp_usblib_test_tx_send(struct mctp_usblib_tx_ctx *tx_ctx, + void *data, size_t len) +{ + struct mctp_usblib_test_ctx *ctx; + struct tx_buff *new_node; + struct net_device *ndev; + + ctx = mctp_usblib_tx_ctx_priv(tx_ctx); + ndev = ctx->dev->ndev; + + new_node = kzalloc_flex(*new_node, data, len, GFP_KERNEL); + if (!new_node) + return -ENOMEM; + + new_node->length = len; + memcpy(new_node->data, data, len); + list_add_tail(&new_node->list, &ctx->tx_xfers); + + mctp_usblib_tx_send_complete(tx_ctx, ndev, true); + return 0; +} + +static int mctp_usblib_test_tx_send_fail(struct mctp_usblib_tx_ctx *tx_ctx, + void *data, size_t len) +{ + return -ENOMEM; +} + +static u8 *mctp_usblib_test_flatten_tx_buff(struct kunit *test, + struct list_head *in, + size_t *length_out) +{ + struct tx_buff *pos; + size_t length; + u8 *buf, *tail; + + KUNIT_ASSERT_TRUE(test, length_out); + KUNIT_ASSERT_TRUE(test, in); + + length = 0; + list_for_each_entry(pos, in, list) + length = size_add(length, pos->length); + + KUNIT_ASSERT_NE(test, length, 0); + KUNIT_ASSERT_NE(test, length, SIZE_MAX); + + buf = kunit_kzalloc(test, length, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, buf); + + tail = buf; + list_for_each_entry(pos, in, list) { + memcpy(tail, pos->data, pos->length); + tail += pos->length; + } + + *length_out = length; + return buf; +} + +static u8 *mctp_usblib_test_init_buf(struct kunit *test, size_t length) +{ + u8 *buffer; + size_t i; + + buffer = kunit_kzalloc(test, length, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, buffer); + + for (i = 0; i < length; i++) + buffer[i] = i % 256; + + return buffer; +} + +static void mctp_usblib_test_fill_head(struct mctp_usb_hdr *head, size_t len) +{ + len += HDR_LEN; + head->id = cpu_to_be16(MCTP_USB_DMTF_ID); + head->len = cpu_to_be16(len & MCTP_USB_1_1_PKTLEN_MAX); +} + +static struct sk_buff *mctp_usblib_test_init_skb(struct kunit *test, + unsigned int length, + struct net_device *ndev, + void *data) +{ + struct sk_buff *skb; + + skb = __netdev_alloc_skb(ndev, length, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, skb); + + skb_put_data(skb, data, length); + return skb; +} + static netdev_tx_t mctp_usblib_dev_tx(struct sk_buff *skb, struct net_device *ndev) { @@ -119,6 +222,7 @@ static int mctp_usblib_test_dst_output(struct mctp_dst *dst, static void mctp_usblib_test_fini_action(void *data) { struct mctp_usblib_test_ctx *ctx = data; + struct tx_buff *curr, *temp; /* The device will have been destroyed, so ->rt will be unlinked. * Just ensure that the refcount is as expected. @@ -126,6 +230,8 @@ static void mctp_usblib_test_fini_action(void *data) KUNIT_EXPECT_TRUE(current->kunit_test, refcount_dec_and_test(&ctx->rt.refs)); + list_for_each_entry_safe(curr, temp, &ctx->tx_xfers, list) + kfree(curr); kfree(ctx); } @@ -141,6 +247,7 @@ static struct mctp_usblib_test_ctx *mctp_usblib_test_init(struct kunit *test) INIT_LIST_HEAD(&ctx->rt.list); rt = &ctx->rt; refcount_set(&rt->refs, 1); + INIT_LIST_HEAD(&ctx->tx_xfers); rc = kunit_add_action_or_reset(test, mctp_usblib_test_fini_action, ctx); KUNIT_ASSERT_EQ(test, rc, 0); @@ -227,6 +334,32 @@ static int mctp_usblib_test_rx_complete(struct net_device *netdev, return rc; } +static void action_tx_fini(void *data) +{ + struct mctp_usblib_tx *tx = data; + + mctp_usblib_tx_fini(tx); + kfree(tx); +} + +static struct mctp_usblib_tx * +mctp_usblib_test_tx_init(struct kunit *test, + const struct mctp_usblib_tx_ops *ops, + void *priv, bool span) +{ + struct mctp_usblib_tx *tx; + int rc; + + tx = kzalloc_obj(*tx); + KUNIT_ASSERT_NOT_NULL(test, tx); + rc = kunit_add_action_or_reset(test, action_tx_fini, tx); + KUNIT_ASSERT_EQ(test, rc, 0); + + mctp_usblib_tx_init(tx, ops, priv, span); + + return tx; +} + /* Single packet, starting on a transfer boundary, contained entirely within * the transfer */ @@ -585,6 +718,156 @@ static void mctp_usblib_test_rx_nonspanning_partial(struct kunit *test) KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0); } +static void mctp_usblib_test_tx_pkt_span(struct kunit *test) +{ + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_tx_ops ops; + struct mctp_usblib_tx *tx; + struct mctp_usb_hdr head; + struct net_device *ndev; + struct sk_buff *skb; + size_t len, tx_len; + u8 *buf, *flat_tx; + int rc; + + len = 1000; + + ctx = mctp_usblib_test_init(test); + ndev = ctx->dev->ndev; + + ops.send = mctp_usblib_test_tx_send; + + tx = mctp_usblib_test_tx_init(test, &ops, ctx, true); + + buf = mctp_usblib_test_init_buf(test, len); + mctp_usblib_test_fill_head(&head, len); + + skb = mctp_usblib_test_init_skb(test, len, ndev, buf); + + rc = mctp_usblib_tx_push(ndev, tx, skb, false); + KUNIT_ASSERT_EQ(test, rc, 0); + KUNIT_ASSERT_FALSE(test, list_empty(&ctx->tx_xfers)); + + flat_tx = mctp_usblib_test_flatten_tx_buff(test, &ctx->tx_xfers, + &tx_len); + KUNIT_ASSERT_NOT_NULL(test, flat_tx); + + KUNIT_EXPECT_EQ(test, tx_len, len + HDR_LEN); + KUNIT_EXPECT_MEMEQ(test, flat_tx, &head, HDR_LEN); + KUNIT_EXPECT_MEMEQ(test, flat_tx + HDR_LEN, buf, len); +} + +static void mctp_usblib_test_tx_failing_send(struct kunit *test) +{ + struct mctp_usblib_test_ctx *ctx; + struct mctp_usblib_tx_ops ops; + struct mctp_usblib_tx *tx; + struct net_device *ndev; + struct sk_buff *skb; + size_t len; + u8 *buf; + int rc; + + len = 100; + + ctx = mctp_usblib_test_init(test); + ndev = ctx->dev->ndev; + + ops.send = mctp_usblib_test_tx_send_fail; + + tx = mctp_usblib_test_tx_init(test, &ops, ctx, false); + buf = mctp_usblib_test_init_buf(test, len); + skb = mctp_usblib_test_init_skb(test, len, ndev, buf); + + /* Doesn't call ops.send as more packets are expected, + * so the push shouldn't fail. + */ + rc = mctp_usblib_tx_push(ndev, tx, skb, true); + KUNIT_ASSERT_EQ(test, rc, 0); + + skb = mctp_usblib_test_init_skb(test, len, ndev, buf); + + /* Calls ops.send as no further packets are expected. */ + rc = mctp_usblib_tx_push(ndev, tx, skb, false); + KUNIT_EXPECT_EQ(test, rc, 0); + KUNIT_EXPECT_NULL(test, tx->cur_ctx); + KUNIT_EXPECT_TRUE(test, list_empty(&ctx->tx_xfers)); +} + +/* Test sending multiple packets in the same transfer, followed by one that + * spans multiple subsequent transfers. + */ +static void mctp_usblib_test_tx_multi_push(struct kunit *test) +{ + struct mctp_usblib_test_ctx *ctx; + size_t i, max_length, tx_length; + struct mctp_usblib_tx_ops ops; + u8 *buf, *flat_tx, *index; + struct mctp_usblib_tx *tx; + struct net_device *ndev; + struct sk_buff *skb; + const struct { + size_t len; + bool more; + } sends[] = { + { 1000, true }, + { 500, false }, + { 5000, false }, + }; + int rc; + + static_assert(!sends[ARRAY_SIZE(sends) - 1].more, + "The last push must claim there will be no more"); + + max_length = 0; + for (i = 0; i < ARRAY_SIZE(sends); i++) { + if (sends[i].len > max_length) + max_length = sends[i].len; + } + + ctx = mctp_usblib_test_init(test); + ndev = ctx->dev->ndev; + + ops.send = mctp_usblib_test_tx_send; + + tx = mctp_usblib_test_tx_init(test, &ops, ctx, true); + buf = mctp_usblib_test_init_buf(test, max_length); + + for (i = 0; i < ARRAY_SIZE(sends); i++) { + skb = mctp_usblib_test_init_skb(test, sends[i].len, ndev, buf); + + rc = mctp_usblib_tx_push(ndev, tx, skb, sends[i].more); + KUNIT_ASSERT_EQ(test, rc, 0); + } + KUNIT_ASSERT_FALSE(test, list_empty(&ctx->tx_xfers)); + + flat_tx = mctp_usblib_test_flatten_tx_buff(test, &ctx->tx_xfers, + &tx_length); + + for (i = 0, index = flat_tx; i < ARRAY_SIZE(sends); i++) { + size_t length_to_check, remaining_bytes; + struct mctp_usb_hdr head; + + if (index - flat_tx >= tx_length - HDR_LEN) + break; + + mctp_usblib_test_fill_head(&head, sends[i].len); + KUNIT_EXPECT_MEMEQ(test, index, &head, HDR_LEN); + index += HDR_LEN; + remaining_bytes = tx_length - (index - flat_tx); + + length_to_check = sends[i].len; + KUNIT_EXPECT_GE(test, remaining_bytes, length_to_check); + length_to_check = min(remaining_bytes, length_to_check); + + KUNIT_EXPECT_MEMEQ(test, index, + buf, length_to_check); + + index += length_to_check; + } + KUNIT_EXPECT_EQ(test, i, ARRAY_SIZE(sends)); +} + static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_single), KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span, @@ -594,6 +877,9 @@ static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_invalid_dmtf_id), KUNIT_CASE(mctp_usblib_test_rx_nonspanning_tiny), KUNIT_CASE(mctp_usblib_test_rx_nonspanning_partial), + KUNIT_CASE(mctp_usblib_test_tx_pkt_span), + KUNIT_CASE(mctp_usblib_test_tx_multi_push), + KUNIT_CASE(mctp_usblib_test_tx_failing_send), {} }; From 9e061caa3bdd288b007fa3a10cb4489f6472e671 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 14 Oct 2026 12:47:37 +0800 Subject: [PATCH 2028/2126] net: mctp: usblib: Add test for failing append Add test ensuring that network device stats are updated appropriately when a previously pushed packet fails to send during a subsequent push. Signed-off-by: James Lee Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-7-ee5bc3ea1db1@codeconstruct.com.au Signed-off-by: Jakub Kicinski --- drivers/net/mctp/mctp-usblib-test.c | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 16c2c9963d2d..b7e8743c561f 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -868,6 +868,47 @@ static void mctp_usblib_test_tx_multi_push(struct kunit *test) KUNIT_EXPECT_EQ(test, i, ARRAY_SIZE(sends)); } +static void mctp_usblib_test_append_failure(struct kunit *test) +{ + struct mctp_usblib_test_ctx *ctx; + struct rtnl_link_stats64 stats; + struct mctp_usblib_tx_ops ops; + struct mctp_usblib_tx *tx; + struct net_device *ndev; + struct sk_buff *skb; + u64 tx_dropped; + size_t i; + u8 *buf; + int rc; + + const size_t packet_count = 3; + const size_t len = (MCTP_USB_1_0_XFER_SIZE / packet_count) + 1 + - sizeof(struct mctp_usb_hdr); + static_assert(len >= MCTP_USB_BTU); + + ctx = mctp_usblib_test_init(test); + ndev = ctx->dev->ndev; + + ops.send = mctp_usblib_test_tx_send_fail; + + tx = mctp_usblib_test_tx_init(test, &ops, ctx, false); + buf = mctp_usblib_test_init_buf(test, len); + + for (i = 0; i < packet_count; i++) { + tx_dropped = dev_get_stats(ndev, &stats)->tx_dropped; + KUNIT_EXPECT_EQ(test, tx_dropped, 0); + skb = mctp_usblib_test_init_skb(test, len, ndev, buf); + + rc = mctp_usblib_tx_push(ndev, tx, skb, i != packet_count - 1); + KUNIT_EXPECT_EQ(test, rc, 0); + KUNIT_EXPECT_TRUE(test, list_empty(&ctx->tx_xfers)); + } + + tx_dropped = dev_get_stats(ndev, &stats)->tx_dropped; + KUNIT_EXPECT_EQ(test, tx_dropped, packet_count); + KUNIT_EXPECT_NULL(test, tx->cur_ctx); +} + static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_rx_single), KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span, @@ -880,6 +921,7 @@ static struct kunit_case mctp_usblib_test_cases[] = { KUNIT_CASE(mctp_usblib_test_tx_pkt_span), KUNIT_CASE(mctp_usblib_test_tx_multi_push), KUNIT_CASE(mctp_usblib_test_tx_failing_send), + KUNIT_CASE(mctp_usblib_test_append_failure), {} }; From 9dd53418781900f02897c805eed397555cf98417 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Tue, 13 Oct 2026 11:45:02 +0000 Subject: [PATCH 2029/2126] net: stmmac: Track the TX DMA threshold per queue Commit 3a6c12a0c6c3 ("net: stmmac: bump tc when get underflow error from DMA descriptor") made dwmac4 raise the DMA threshold of the queues that report TX underflows. This is done by incrementing a module global parameter 'tc' by 64 on each underflow. This leads to inconsistent TX DMA thresholds between queues and causes issues on platforms with multiple stmmac controllers, as 'tc' is shared by all of them. Once 'tc' goes over 256 the bumping stops, and queues that did not underflow before are left at the initial threshold. On the Renesas RZ/V2H platform, which has two dwmac4 controllers, we observed sporadic iperf3 TCP TX failures: iperf3 -c -t5 --bind-dev end1 ... [ 5] 0.00-5.00 sec 1.00 MBytes 1.68 Mbits/sec 87 sender [ 5] 0.00-5.00 sec 768 KBytes 1.26 Mbits/sec receiver This happens because the TX queues of end1 were underflowing on a large fraction of the packets, but the DMA TX threshold was never raised from the default of 64 bytes. The threshold was not raised because end0 had underflowed first and had already pushed 'tc' past 256. Which controller is affected depends on which one underflows first. To fix this, make the TX DMA threshold per queue instead of global. Each time an underflow happens on a queue, its TX DMA threshold gets incremented, without affecting other queues or controllers. With this change, 'tc' is only used as the initial value, and the RX threshold is no longer bumped together with the TX one, as TX underflows have nothing to do with the RX side. Fixes: 3a6c12a0c6c3 ("net: stmmac: bump tc when get underflow error from DMA descriptor") Signed-off-by: Ovidiu Panait Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261013114503.57487-2-ovidiu.panait.rb@renesas.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 120d01c04d61..93292014c393 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -270,6 +270,7 @@ struct stmmac_priv { bool sph_capable; u32 sarc_type; u32 rx_riwt[MTL_MAX_RX_QUEUES]; + u32 tx_threshold[MTL_MAX_TX_QUEUES]; int hwts_rx_en; bool tsfupdt_coarse; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index de2db188b45d..bd61774ea8d7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2622,7 +2622,6 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) } if (priv->plat->force_thresh_dma_mode) { - txmode = tc; rxmode = tc; } else if (priv->plat->force_sf_dma_mode || priv->plat->tx_coe) { /* @@ -2636,7 +2635,6 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) rxmode = SF_DMA_MODE; priv->xstats.threshold = SF_DMA_MODE; } else { - txmode = tc; rxmode = SF_DMA_MODE; } @@ -2655,8 +2653,11 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) for (chan = 0; chan < tx_channels_count; chan++) { qmode = priv->plat->tx_queues_cfg[chan].mode_to_use; - stmmac_dma_tx_mode(priv, priv->ioaddr, txmode, chan, - txfifosz, qmode); + if (txmode == SF_DMA_MODE) + priv->tx_threshold[chan] = SF_DMA_MODE; + + stmmac_dma_tx_mode(priv, priv->ioaddr, priv->tx_threshold[chan], + chan, txfifosz, qmode); } } @@ -2822,17 +2823,20 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget) static void stmmac_bump_dma_threshold(struct stmmac_priv *priv, u32 chan) { - if (unlikely(priv->xstats.threshold != SF_DMA_MODE) && tc <= 256) { - tc += 64; + u32 thresh = priv->tx_threshold[chan]; - if (priv->plat->force_thresh_dma_mode) - stmmac_set_dma_operation_mode(priv, tc, tc, chan); - else - stmmac_set_dma_operation_mode(priv, tc, SF_DMA_MODE, - chan); + if (unlikely(thresh == SF_DMA_MODE) || thresh > 256) + return; - priv->xstats.threshold = tc; - } + thresh += 64; + + if (priv->plat->force_thresh_dma_mode) + stmmac_set_dma_operation_mode(priv, thresh, tc, chan); + else + stmmac_set_dma_operation_mode(priv, thresh, SF_DMA_MODE, chan); + + priv->tx_threshold[chan] = thresh; + priv->xstats.threshold = thresh; } /** @@ -8159,6 +8163,9 @@ static int __stmmac_dvr_probe(struct device *device, priv->xstats.threshold = tc; + for (i = 0; i < MTL_MAX_TX_QUEUES; i++) + priv->tx_threshold[i] = tc; + /* Initialize RSS */ rxq = priv->plat->rx_queues_to_use; netdev_rss_key_fill(priv->rss.key, sizeof(priv->rss.key)); From aee7b59e6e7b353a48ca8b07794a441b03eac6a0 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Tue, 13 Oct 2026 11:45:03 +0000 Subject: [PATCH 2030/2126] net: stmmac: Report the TX DMA threshold per queue The "threshold" ethtool statistic reports a single TX DMA threshold for the whole device. However, since commit d62a107a4f15 ("net: stmmac: prepare dma interrupt treatment for multiple queues"), a single TX DMA threshold per device doesn't make sense anymore, as each individual queue that underflows gets its threshold increased, so the queues are out of sync. To make the reporting accurate, remove it and report the threshold of each TX queue instead, as "qN_tx_threshold". Signed-off-by: Ovidiu Panait Link: https://patch.msgid.link/20261013114503.57487-3-ovidiu.panait.rb@renesas.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/common.h | 1 - drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 3 ++- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 1729fb29ece3..c74bc7c9750e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -158,7 +158,6 @@ struct stmmac_extra_stats { unsigned long fatal_bus_error_irq; /* Tx/Rx IRQ Events */ unsigned long rx_early_irq; - unsigned long threshold; unsigned long irq_receive_pmt_irq_n; /* MMC info */ unsigned long mmc_tx_irq_n; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 30e0d499326d..c616a1c95e5d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -89,7 +89,6 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = { STMMAC_STAT(fatal_bus_error_irq), /* Tx/Rx IRQ Events */ STMMAC_STAT(rx_early_irq), - STMMAC_STAT(threshold), STMMAC_STAT(irq_receive_pmt_irq_n), /* MMC info */ STMMAC_STAT(mmc_tx_irq_n), @@ -289,6 +288,7 @@ static const struct stmmac_stats stmmac_mmc[] = { static const char stmmac_qstats_tx_string[][ETH_GSTRING_LEN] = { "tx_pkt_n", "tx_irq_n", + "tx_threshold", #define STMMAC_TXQ_STATS ARRAY_SIZE(stmmac_qstats_tx_string) }; @@ -496,6 +496,7 @@ static void stmmac_get_per_qstats(struct stmmac_priv *priv, u64 *data) *data++ = pkt_n; *data++ = stmmac_get_tx_normal_irq_n(priv, q); + *data++ = priv->tx_threshold[q]; } for (q = 0; q < rx_cnt; q++) { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index bd61774ea8d7..fb53b1f17714 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2633,7 +2633,6 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) */ txmode = SF_DMA_MODE; rxmode = SF_DMA_MODE; - priv->xstats.threshold = SF_DMA_MODE; } else { rxmode = SF_DMA_MODE; } @@ -2836,7 +2835,6 @@ static void stmmac_bump_dma_threshold(struct stmmac_priv *priv, u32 chan) stmmac_set_dma_operation_mode(priv, thresh, SF_DMA_MODE, chan); priv->tx_threshold[chan] = thresh; - priv->xstats.threshold = thresh; } /** @@ -8161,8 +8159,6 @@ static int __stmmac_dvr_probe(struct device *device, #endif priv->msg_enable = netif_msg_init(debug, default_msg_level); - priv->xstats.threshold = tc; - for (i = 0; i < MTL_MAX_TX_QUEUES; i++) priv->tx_threshold[i] = tc; From 8d9ecac6b96e61d0e6d126c60644829fd9f66952 Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:18 -0700 Subject: [PATCH 2031/2126] ibmveth: fix netpoll races with RX replenish ibmveth_poll_controller() runs RX replenish outside NAPI and without a lock, racing NAPI's replenish on another CPU. Both can fill the same slot, so an skb and its DMA mapping leak and PHYP can write into an unmapped buffer. netpoll calls it from netconsole and from netpoll-enabled bonds. ibmveth_open() also enables NAPI before the RX resources exist. ibmveth_change_mtu(), veth_pool_store(), ibmveth_set_csum_offload() and ibmveth_set_tso() call close() and open() directly, so while open() is still setting up, netpoll and the direct ibmveth_interrupt() calls can replenish NULL pools and read freed memory. Remove the callback, as Eric Dumazet did for many drivers after commit ac3d9dd034e5 ("netpoll: make ndo_poll_controller() optional"), including ibmvnic in commit 0c3b9d1b37df ("ibmvnic: remove ndo_poll_controller"). netpoll then polls NAPI itself with budget 0. napi->poll_owner serializes that with NAPI, but not with a NAPI poll that was already running when netpoll was set up, so skip RX replenish at budget 0, which netpoll uses for TX only. TX completes synchronously, so ibmveth_poll() has nothing else to do for netpoll. Enable NAPI just before request_irq(), once everything ibmveth_poll() touches exists. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection of poll_one_napi() and the direct close()/open() callers; neither race was reproduced. Tested on a POWER10 LPAR with netconsole over ibmveth: a ping flood (678,470 packets, no loss) during a printk flood, and MTU changes and buffer pool toggles under traffic, with no warnings. No kernel selftests cover ibmveth. Fixes: 6b4223748895 ("[PATCH] ibmveth: Add netpoll function") Fixes: bea3348eef27 ("[NET]: Make NAPI polling independent of struct net_device objects.") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-2-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index abebdb1fc262..4a5869183be6 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -628,8 +628,6 @@ static int ibmveth_open(struct net_device *netdev) netdev_dbg(netdev, "open starting\n"); - napi_enable(&adapter->napi); - for(i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) rxq_entries += adapter->rx_buff_pool[i].size; @@ -717,10 +715,18 @@ static int ibmveth_open(struct net_device *netdev) } } + /* NAPI can run as soon as it is enabled, from netpoll during the + * direct close()/open() pairs or from a direct ibmveth_interrupt() + * call, so enable it only once everything ibmveth_poll() touches + * exists. + */ + napi_enable(&adapter->napi); + netdev_dbg(netdev, "registering irq 0x%x\n", netdev->irq); rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev); if (rc != 0) { + napi_disable(&adapter->napi); netdev_err(netdev, "unable to request irq 0x%x, rc %d\n", netdev->irq, rc); goto out_free_buffer_pools; @@ -765,7 +771,6 @@ out_free_filter_list: out_free_buffer_list: free_page((unsigned long)adapter->buffer_list_addr); out: - napi_disable(&adapter->napi); return rc; } @@ -1542,7 +1547,11 @@ restart_poll: } } - ibmveth_replenish_task(adapter); + /* netpoll polls with budget 0 for TX only, and is not serialized + * with a NAPI poll that was already running when it was set up + */ + if (budget) + ibmveth_replenish_task(adapter); if (frames_processed == budget) goto out; @@ -1682,14 +1691,6 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu) return -EINVAL; } -#ifdef CONFIG_NET_POLL_CONTROLLER -static void ibmveth_poll_controller(struct net_device *dev) -{ - ibmveth_replenish_task(netdev_priv(dev)); - ibmveth_interrupt(dev->irq, dev); -} -#endif - /** * ibmveth_get_desired_dma - Calculate IO memory desired by the driver * @@ -1791,9 +1792,6 @@ static const struct net_device_ops ibmveth_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = ibmveth_set_mac_addr, .ndo_features_check = ibmveth_features_check, -#ifdef CONFIG_NET_POLL_CONTROLLER - .ndo_poll_controller = ibmveth_poll_controller, -#endif }; static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) From 95811c873d1b97c424a7e6e731730cbf6656ab7e Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:19 -0700 Subject: [PATCH 2032/2126] ibmveth: do not close twice after a failed reopen ibmveth_change_mtu(), veth_pool_store(), ibmveth_set_csum_offload() and ibmveth_set_tso() call close() and open() directly. If open() fails, NAPI is left disabled while IFF_UP stays set, so the next close() (ifdown, unregister or another reconfiguration) calls napi_disable() again and waits forever with RTNL held. Networking and shutdown hang; only a reboot recovers. ethtool -L in that state also wakes queues that have no TX buffer and dereferences NULL in ibmveth_start_xmit(). Any open() failure on those paths triggers it, for example an allocation failure on an MTU change to jumbo frames. Track a successful open in adapter->opened. close() returns early when it is clear, and set_channels() checks it instead of IFF_UP. The open() error-path leaks were fixed separately in net by commit af0524bf4ce1 ("ibmveth: h_free logical LAN on open-fail after register") and commit 84bec0bf0352 ("ibmveth: fix TX LTB and filter unwind on open-fail"), which are now in net-next too, so a failed open() no longer leaves TX buffers or the logical LAN registration behind for the early return to skip. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection. Tested on a POWER10 LPAR with ibmveth_open() forced to fail by a test-only module parameter (not part of this patch): 'ip link set dev eth1 mtu 9000' fails, then 'ip link set dev eth1 down' returns at once and 'ip link set dev eth1 up' recovers the interface. No kernel selftests cover ibmveth. Fixes: 860f242eb534 ("[PATCH] ibmveth change buffer pools dynamically") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-3-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 24 +++++++++++++++++------- drivers/net/ethernet/ibm/ibmveth.h | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 4a5869183be6..4665447997ea 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -739,6 +739,7 @@ static int ibmveth_open(struct net_device *netdev) netif_tx_start_all_queues(netdev); + adapter->opened = true; netdev_dbg(netdev, "open complete\n"); return 0; @@ -781,6 +782,14 @@ static int ibmveth_close(struct net_device *netdev) long lpar_rc; int i; + /* change_mtu, pool sysfs, set_csum and set_tso call close() and + * open() directly. If that open() fails, IFF_UP stays set and + * NAPI is disabled; a second close() would hang in napi_disable(). + */ + if (!adapter->opened) + return 0; + adapter->opened = false; + netdev_dbg(netdev, "close starting\n"); napi_disable(&adapter->napi); @@ -832,10 +841,10 @@ static int ibmveth_close(struct net_device *netdev) * * @w: pointer to work_struct embedded in adapter structure * - * Context: This routine acquires rtnl_mutex and disables its NAPI through - * ibmveth_close. It can't be called directly in a context that has - * already acquired rtnl_mutex or disabled its NAPI, or directly from - * a poll routine. + * Context: This routine acquires rtnl_mutex and, if the device is open, + * disables its NAPI through ibmveth_close. It can't be called + * directly in a context that has already acquired rtnl_mutex or + * disabled its NAPI, or directly from a poll routine. * * Return: void */ @@ -1129,10 +1138,11 @@ static int ibmveth_set_channels(struct net_device *netdev, goal = channels->tx_count; int rc, i; - /* If ndo_open has not been called yet then don't allocate, just set - * desired netdev_queue's and return + /* If the device is not open (including a failed close/open with + * IFF_UP still set) then don't allocate, just set desired + * netdev_queue's and return */ - if (!(netdev->flags & IFF_UP)) + if (!adapter->opened) return netif_set_real_num_tx_queues(netdev, goal); /* We have IBMVETH_MAX_QUEUES netdev_queue's allocated diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index d87713668ed3..3f2240823f6a 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -172,6 +172,8 @@ struct ibmveth_adapter { int rx_csum; int large_send; bool is_active_trunk; + /* Set by a successful ibmveth_open(), cleared by ibmveth_close(). */ + bool opened; unsigned int rx_buffers_per_hcall; u64 fw_ipv6_csum_support; From 1412235447869922eb0ee041a31fab6176e60ab0 Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:20 -0700 Subject: [PATCH 2033/2126] ibmveth: disable the reset work before unregister in remove ibmveth_remove() cancels the reset work before unregister_netdev(), but NAPI keeps running until unregister closes the device and can queue the reset again, on an interrupt enable failure, a bad free_map entry or a bad RX slot. The reset can then run on the adapter after free_netdev(), or reopen the device during unregister. Use disable_work_sync(), which waits for a running reset and keeps the work from being queued again. A bad RX slot also makes poll spin, which can stall unregister; a later patch in this series fixes that. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; it was not reproduced. Tested on a POWER10 LPAR with unbind and bind cycles under traffic. No kernel selftests cover ibmveth. Fixes: 2c91e2319ed9 ("net: ibmveth: Reset the adapter when unexpected states are detected") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-4-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 4665447997ea..cee0e9783b2a 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1956,7 +1956,7 @@ static void ibmveth_remove(struct vio_dev *dev) struct ibmveth_adapter *adapter = netdev_priv(netdev); int i; - cancel_work_sync(&adapter->work); + disable_work_sync(&adapter->work); for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) kobject_put(&adapter->rx_buff_pool[i].kobj); From c9b95adc755f2396307be676ce838161fb011986 Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:21 -0700 Subject: [PATCH 2034/2126] ibmveth: step past bad RX correlators instead of spinning or oopsing ibmveth_poll() mishandles a bad RX correlator from PHYP in two ways. If harvest fails or ibmveth_rxq_get_buffer() returns NULL, poll breaks out without advancing the ring and restarts on the same slot forever. For an out-of-range correlator it also fires a WARN_ON() and schedules a reset each pass, but the reset is queued on that CPU and never runs, and the CPU stalls RCU, so RTNL holders hang too. This dates from the first commit in Fixes:, which turned the BUG_ON()s here into WARN_ON() plus a reset. The range check also accepts a correlator naming an inactive buffer pool (pools 2 and 3 by default), whose skbuff array is NULL, so the lookup dereferences NULL in softirq. Pools became inactive with the second commit in Fixes:. Validate the correlator in one helper that also rejects a pool with no skbuff array. On a bad slot, advance the ring, count the drop in rx_dropped and still schedule the reset, which rebuilds the pools. The slot has moved, so stay in the budget loop and count it in frames_processed. Breaking out would complete NAPI, re-arm, and napi_schedule() with budget left. When the final check finds more work, queue the NAPI and return instead of going back to restart_poll: after napi_complete_done() the NAPI is no longer this call's, and with threaded NAPI and busy polling the kthread can already be polling it on another CPU. frames_processed is below budget there, so busy_poll_stop() does not queue it a second time. Mask the interrupt before queueing, as ibmveth_interrupt() does; masking after napi_schedule() could land after that kthread has finished and unmasked, leaving RX masked with nothing scheduled. Drop a frame whose offset + length does not fit the pool buffer: copybreak would read past the RX buffer and skb_put() would BUG(). Also drop one shorter than an Ethernet header, which eth_type_trans() would read past. Read the correlator once per slot and use that value for the lookup, the bound and the harvest. The base driver never checked frame bounds, and they have not been seen in the field, so they have no Fixes: tag of their own. The tags below are for the correlator hang. The correlator comes from PHYP, and with the ring advancing a burst of bad slots would WARN once per slot (and panic with panic_on_warn), so use a ratelimited netdev_err() instead. Also free the rx_copybreak skb if harvest fails there. Add a KUnit case for harvest advancing on errors and extend the existing cases to an inactive pool. Run against the unfixed driver, with the calls changed back to its signatures, the first fails and the others oops. Found in review of the ibmveth multi-queue RX series (the frame bound by the Sashiko review of v2 of this series) and confirmed by code inspection and the KUnit cases above. Hitting either correlator bug needs PHYP to return a bad correlator, so neither was reproduced on hardware. Tested with KUnit on qemu pseries (ppc64le), and on a POWER10 LPAR with a ping flood and MTU changes under traffic. No kernel selftests cover ibmveth. Fixes: 2c91e2319ed9 ("net: ibmveth: Reset the adapter when unexpected states are detected") Fixes: 860f242eb534 ("[PATCH] ibmveth change buffer pools dynamically") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-5-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 265 +++++++++++++++++++++++------ 1 file changed, 216 insertions(+), 49 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index cee0e9783b2a..919b5831d875 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -135,6 +135,13 @@ static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter) return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length); } +static u64 ibmveth_rxq_correlator(struct ibmveth_adapter *adapter) +{ + unsigned int idx = adapter->rx_queue.index; + + return READ_ONCE(adapter->rx_queue.queue_addr[idx].correlator); +} + static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter) { return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD; @@ -443,6 +450,37 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, } } +/* The correlator comes back from PHYP; a bad one schedules a reset. */ +static bool ibmveth_rxq_correlator_valid(struct ibmveth_adapter *adapter, + u64 correlator) +{ + unsigned int index = correlator & 0xffffffffUL; + unsigned int pool = correlator >> 32; + + /* An inactive pool keeps its size but has no skbuff array. */ + if (pool < IBMVETH_NUM_BUFF_POOLS && + index < adapter->rx_buff_pool[pool].size && + adapter->rx_buff_pool[pool].skbuff) + return true; + + if (net_ratelimit()) + netdev_err(adapter->netdev, + "invalid RX correlator %llx, resetting\n", + correlator); + schedule_work(&adapter->work); + return false; +} + +static void ibmveth_rxq_no_skb(struct ibmveth_adapter *adapter, + u64 correlator) +{ + if (net_ratelimit()) + netdev_err(adapter->netdev, + "no buffer for RX correlator %llx, resetting\n", + correlator); + schedule_work(&adapter->work); +} + /** * ibmveth_remove_buffer_from_pool - remove a buffer from a pool * @adapter: adapter instance @@ -451,7 +489,8 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, * * Return: * * %0 - success - * * %-EINVAL - correlator maps to pool or index out of range + * * %-EINVAL - correlator maps to pool or index out of range, or to an + * inactive pool * * %-EFAULT - pool and index map to null skb */ static int ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, @@ -462,15 +501,12 @@ static int ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, unsigned int free_index; struct sk_buff *skb; - if (WARN_ON(pool >= IBMVETH_NUM_BUFF_POOLS) || - WARN_ON(index >= adapter->rx_buff_pool[pool].size)) { - schedule_work(&adapter->work); + if (!ibmveth_rxq_correlator_valid(adapter, correlator)) return -EINVAL; - } skb = adapter->rx_buff_pool[pool].skbuff[index]; - if (WARN_ON(!skb)) { - schedule_work(&adapter->work); + if (!skb) { + ibmveth_rxq_no_skb(adapter, correlator); return -EFAULT; } @@ -504,51 +540,56 @@ static int ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, return 0; } -/* get the current buffer on the rx queue */ -static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter) +/* get the buffer for @correlator, read once from the current rx queue entry */ +static struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter, + u64 correlator) { - u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator; unsigned int pool = correlator >> 32; unsigned int index = correlator & 0xffffffffUL; + struct sk_buff *skb; - if (WARN_ON(pool >= IBMVETH_NUM_BUFF_POOLS) || - WARN_ON(index >= adapter->rx_buff_pool[pool].size)) { - schedule_work(&adapter->work); + if (!ibmveth_rxq_correlator_valid(adapter, correlator)) return NULL; - } - return adapter->rx_buff_pool[pool].skbuff[index]; + skb = adapter->rx_buff_pool[pool].skbuff[index]; + if (!skb) + ibmveth_rxq_no_skb(adapter, correlator); + return skb; +} + +static void ibmveth_rxq_advance(struct ibmveth_adapter *adapter) +{ + if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) { + adapter->rx_queue.index = 0; + adapter->rx_queue.toggle = !adapter->rx_queue.toggle; + } } /** * ibmveth_rxq_harvest_buffer - Harvest buffer from pool * - * @adapter: pointer to adapter - * @reuse: whether to reuse buffer + * @adapter: pointer to adapter + * @correlator: correlator of the current rx queue entry, as read by poll + * @reuse: whether to reuse buffer * * Context: called from ibmveth_poll * + * The ring advances even on error, so poll does not return to a bad + * slot before the scheduled reset can run. + * * Return: * * %0 - success * * other - non-zero return from ibmveth_remove_buffer_from_pool */ static int ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter, - bool reuse) + u64 correlator, bool reuse) { - u64 cor; int rc; - cor = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator; - rc = ibmveth_remove_buffer_from_pool(adapter, cor, reuse); - if (unlikely(rc)) - return rc; + rc = ibmveth_remove_buffer_from_pool(adapter, correlator, reuse); + ibmveth_rxq_advance(adapter); - if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) { - adapter->rx_queue.index = 0; - adapter->rx_queue.toggle = !adapter->rx_queue.toggle; - } - - return 0; + return rc; } static void ibmveth_free_tx_ltb(struct ibmveth_adapter *adapter, int idx) @@ -1469,31 +1510,60 @@ static int ibmveth_poll(struct napi_struct *napi, int budget) struct net_device *netdev = adapter->netdev; int frames_processed = 0; unsigned long lpar_rc; + u64 correlator; u16 mss = 0; + int rc; -restart_poll: while (frames_processed < budget) { if (!ibmveth_rxq_pending_buffer(adapter)) break; smp_rmb(); + correlator = ibmveth_rxq_correlator(adapter); if (!ibmveth_rxq_buffer_valid(adapter)) { wmb(); /* suggested by larson1 */ adapter->rx_invalid_buffer++; netdev_dbg(netdev, "recycling invalid buffer\n"); - if (unlikely(ibmveth_rxq_harvest_buffer(adapter, true))) - break; + rc = ibmveth_rxq_harvest_buffer(adapter, correlator, true); + if (unlikely(rc)) { + netdev->stats.rx_dropped++; + frames_processed++; + continue; + } } else { struct sk_buff *skb, *new_skb; int length = ibmveth_rxq_frame_length(adapter); int offset = ibmveth_rxq_frame_offset(adapter); int csum_good = ibmveth_rxq_csum_good(adapter); int lrg_pkt = ibmveth_rxq_large_packet(adapter); + unsigned int pool, room, off, len; __sum16 iph_check = 0; - skb = ibmveth_rxq_get_buffer(adapter); - if (unlikely(!skb)) - break; + skb = ibmveth_rxq_get_buffer(adapter, correlator); + if (unlikely(!skb)) { + ibmveth_rxq_advance(adapter); + netdev->stats.rx_dropped++; + frames_processed++; + continue; + } + + pool = correlator >> 32; + room = min_t(unsigned int, skb_tailroom(skb), + adapter->rx_buff_pool[pool].buff_size); + off = offset; + len = length; + if (unlikely(len < ETH_HLEN || off >= room || + len > room - off)) { + if (net_ratelimit()) + netdev_err(netdev, + "bad RX frame offset %u length %u (buffer %u), dropping\n", + off, len, room); + ibmveth_rxq_harvest_buffer(adapter, correlator, + true); + netdev->stats.rx_dropped++; + frames_processed++; + continue; + } /* if the large packet bit is set in the rx queue * descriptor, the mss will be written by PHYP eight @@ -1517,12 +1587,25 @@ restart_poll: if (rx_flush) ibmveth_flush_buffer(skb->data, length + offset); - if (unlikely(ibmveth_rxq_harvest_buffer(adapter, true))) - break; + rc = ibmveth_rxq_harvest_buffer(adapter, + correlator, + true); + if (unlikely(rc)) { + dev_kfree_skb_any(new_skb); + netdev->stats.rx_dropped++; + frames_processed++; + continue; + } skb = new_skb; } else { - if (unlikely(ibmveth_rxq_harvest_buffer(adapter, false))) - break; + rc = ibmveth_rxq_harvest_buffer(adapter, + correlator, + false); + if (unlikely(rc)) { + netdev->stats.rx_dropped++; + frames_processed++; + continue; + } skb_reserve(skb, offset); } @@ -1578,10 +1661,13 @@ restart_poll: goto out; } - if (ibmveth_rxq_pending_buffer(adapter) && napi_schedule(napi)) { + /* Mask before queueing, as ibmveth_interrupt() does: a threaded + * NAPI can start polling, and unmask, as soon as it is queued. + */ + if (ibmveth_rxq_pending_buffer(adapter) && napi_schedule_prep(napi)) { lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); - goto restart_poll; + __napi_schedule(napi); } out: @@ -2206,8 +2292,7 @@ static void ibmveth_reset_kunit(struct work_struct *w) * @test: pointer to kunit structure * * Tests the error returns from ibmveth_remove_buffer_from_pool. - * ibmveth_remove_buffer_from_pool also calls WARN_ON, so dmesg should be - * checked to see that these warnings happened. + * Each error also logs a ratelimited netdev_err. * * Return: void */ @@ -2216,6 +2301,7 @@ static void ibmveth_remove_buffer_from_pool_test(struct kunit *test) struct ibmveth_adapter *adapter = kunit_kzalloc(test, sizeof(*adapter), GFP_KERNEL); struct ibmveth_buff_pool *pool; u64 correlator; + int ret; KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adapter); @@ -2239,6 +2325,13 @@ static void ibmveth_remove_buffer_from_pool_test(struct kunit *test) KUNIT_EXPECT_EQ(test, -EINVAL, ibmveth_remove_buffer_from_pool(adapter, correlator, false)); KUNIT_EXPECT_EQ(test, -EINVAL, ibmveth_remove_buffer_from_pool(adapter, correlator, true)); + /* Pool 2 is in range but has no skbuff array, like an inactive pool. */ + correlator = ((u64)2 << 32) | 0; + ret = ibmveth_remove_buffer_from_pool(adapter, correlator, false); + KUNIT_EXPECT_EQ(test, -EINVAL, ret); + ret = ibmveth_remove_buffer_from_pool(adapter, correlator, true); + KUNIT_EXPECT_EQ(test, -EINVAL, ret); + correlator = (u64)0 | 0; pool->skbuff[0] = NULL; KUNIT_EXPECT_EQ(test, -EFAULT, ibmveth_remove_buffer_from_pool(adapter, correlator, false)); @@ -2251,9 +2344,8 @@ static void ibmveth_remove_buffer_from_pool_test(struct kunit *test) * ibmveth_rxq_get_buffer_test - unit test for ibmveth_rxq_get_buffer * @test: pointer to kunit structure * - * Tests ibmveth_rxq_get_buffer. ibmveth_rxq_get_buffer also calls WARN_ON for - * the NULL returns, so dmesg should be checked to see that these warnings - * happened. + * Tests ibmveth_rxq_get_buffer. Each NULL return also logs a ratelimited + * netdev_err. * * Return: void */ @@ -2262,6 +2354,7 @@ static void ibmveth_rxq_get_buffer_test(struct kunit *test) struct ibmveth_adapter *adapter = kunit_kzalloc(test, sizeof(*adapter), GFP_KERNEL); struct sk_buff *skb = kunit_kzalloc(test, sizeof(*skb), GFP_KERNEL); struct ibmveth_buff_pool *pool; + u64 cor; KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adapter); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb); @@ -2285,14 +2378,87 @@ static void ibmveth_rxq_get_buffer_test(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pool->skbuff); adapter->rx_queue.queue_addr[0].correlator = (u64)IBMVETH_NUM_BUFF_POOLS << 32 | 0; - KUNIT_EXPECT_PTR_EQ(test, NULL, ibmveth_rxq_get_buffer(adapter)); + cor = ibmveth_rxq_correlator(adapter); + KUNIT_EXPECT_PTR_EQ(test, NULL, + ibmveth_rxq_get_buffer(adapter, cor)); adapter->rx_queue.queue_addr[0].correlator = (u64)0 << 32 | adapter->rx_buff_pool[0].size; - KUNIT_EXPECT_PTR_EQ(test, NULL, ibmveth_rxq_get_buffer(adapter)); + cor = ibmveth_rxq_correlator(adapter); + KUNIT_EXPECT_PTR_EQ(test, NULL, + ibmveth_rxq_get_buffer(adapter, cor)); + + /* Pool 2 is in range but has no skbuff array, like an inactive pool. */ + adapter->rx_queue.queue_addr[0].correlator = (u64)2 << 32 | 0; + cor = ibmveth_rxq_correlator(adapter); + KUNIT_EXPECT_PTR_EQ(test, NULL, + ibmveth_rxq_get_buffer(adapter, cor)); pool->skbuff[0] = skb; adapter->rx_queue.queue_addr[0].correlator = (u64)0 << 32 | 0; - KUNIT_EXPECT_PTR_EQ(test, skb, ibmveth_rxq_get_buffer(adapter)); + cor = ibmveth_rxq_correlator(adapter); + KUNIT_EXPECT_PTR_EQ(test, skb, + ibmveth_rxq_get_buffer(adapter, cor)); + + flush_work(&adapter->work); +} + +/** + * ibmveth_rxq_harvest_buffer_test - unit test for ibmveth_rxq_harvest_buffer + * @test: pointer to kunit structure + * + * A bad correlator must still advance the RX ring, wrapping and flipping + * the toggle at the end. This covers the harvest path; the advance after + * ibmveth_rxq_get_buffer() fails in ibmveth_poll() is not tested here. + * + * Return: void + */ +static void ibmveth_rxq_harvest_buffer_test(struct kunit *test) +{ + struct ibmveth_adapter *adapter; + struct ibmveth_buff_pool *pool; + u64 cor; + int ret; + + adapter = kunit_kzalloc(test, sizeof(*adapter), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adapter); + + INIT_WORK(&adapter->work, ibmveth_reset_kunit); + + adapter->rx_queue.num_slots = 2; + adapter->rx_queue.index = 0; + adapter->rx_queue.toggle = 1; + adapter->rx_queue.queue_addr = + kunit_kcalloc(test, 2, sizeof(struct ibmveth_rx_q_entry), + GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adapter->rx_queue.queue_addr); + + /* Set sane values for buffer pools */ + for (int i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) + ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, + pool_count[i], pool_size[i], + pool_active[i]); + + pool = &adapter->rx_buff_pool[0]; + pool->skbuff = kunit_kcalloc(test, pool->size, sizeof(void *), + GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pool->skbuff); + + /* Slot 0: pool out of range. Slot 1: valid, but no skb. */ + adapter->rx_queue.queue_addr[0].correlator = + (u64)IBMVETH_NUM_BUFF_POOLS << 32 | 0; + adapter->rx_queue.queue_addr[1].correlator = (u64)0 << 32 | 0; + + cor = ibmveth_rxq_correlator(adapter); + ret = ibmveth_rxq_harvest_buffer(adapter, cor, true); + KUNIT_EXPECT_EQ(test, -EINVAL, ret); + KUNIT_EXPECT_EQ(test, 1ULL, adapter->rx_queue.index); + KUNIT_EXPECT_EQ(test, 1ULL, adapter->rx_queue.toggle); + + cor = ibmveth_rxq_correlator(adapter); + ret = ibmveth_rxq_harvest_buffer(adapter, cor, true); + KUNIT_EXPECT_EQ(test, -EFAULT, ret); + KUNIT_EXPECT_EQ(test, 0ULL, adapter->rx_queue.index); + KUNIT_EXPECT_EQ(test, 0ULL, adapter->rx_queue.toggle); flush_work(&adapter->work); } @@ -2300,6 +2466,7 @@ static void ibmveth_rxq_get_buffer_test(struct kunit *test) static struct kunit_case ibmveth_test_cases[] = { KUNIT_CASE(ibmveth_remove_buffer_from_pool_test), KUNIT_CASE(ibmveth_rxq_get_buffer_test), + KUNIT_CASE(ibmveth_rxq_harvest_buffer_test), {} }; From fd052c6823b31eb45f824660567ab3f2da2d5195 Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:22 -0700 Subject: [PATCH 2035/2126] ibmveth: release the pool kobjects when probe fails If register_netdev() fails in ibmveth_probe(), for example with -EINTR when the binding task is killed, probe frees the netdev but leaves the pool%d kobjects embedded in it registered in sysfs. Reading /sys/devices/vio//pool0/num is then a use-after-free, and the next probe cannot add pool0. Put the kobjects before freeing the netdev, as ibmveth_remove() does, on this path and on the netif_set_real_num_tx_queues() one. The kobjects also have no release(). With CONFIG_DEBUG_KOBJECT_RELEASE, kobject_put() defers their cleanup, including removing the sysfs files, to a work item, so free_netdev() can free them first, here and in remove(). Add a release() that signals a per-pool completion, and wait for it in both places before free_netdev(). Without that config, release() runs from kobject_put() and the wait returns at once. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; the release() part was raised by the Sashiko review of the first version. Tested on a POWER10 LPAR with register_netdev() forced to fail with -EINTR by a test-only module parameter (not part of this patch): no pool%d directories remain and the device binds again. No kernel selftests cover ibmveth. Fixes: 860f242eb534 ("[PATCH] ibmveth change buffer pools dynamically") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-6-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 52 +++++++++++++++++++++++++----- drivers/net/ethernet/ibm/ibmveth.h | 3 ++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 919b5831d875..42aa9f7bd49d 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1890,6 +1890,40 @@ static const struct net_device_ops ibmveth_netdev_ops = { .ndo_features_check = ibmveth_features_check, }; +/** + * ibmveth_pool_kobj_release - Mark a pool kobject finished + * @kobj: kobject embedded in the pool + * + * The pool kobjects live in netdev_priv(), so the last put must wait + * for this before free_netdev(). + */ +static void ibmveth_pool_kobj_release(struct kobject *kobj) +{ + struct ibmveth_buff_pool *pool = container_of(kobj, + struct ibmveth_buff_pool, + kobj); + + complete(&pool->released); +} + +/** + * ibmveth_put_pool_kobjs - Drop the pool kobjects and wait for release + * @adapter: ibmveth adapter + * + * With CONFIG_DEBUG_KOBJECT_RELEASE the cleanup, including removing the + * sysfs files, runs later from a work item in the kobject; wait for it + * so free_netdev() cannot free the pools first. + */ +static void ibmveth_put_pool_kobjs(struct ibmveth_adapter *adapter) +{ + int i; + + for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) + kobject_put(&adapter->rx_buff_pool[i].kobj); + for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) + wait_for_completion(&adapter->rx_buff_pool[i].released); +} + static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) { int rc, i, mac_len; @@ -2000,6 +2034,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, pool_count[i], pool_size[i], pool_active[i]); + init_completion(&adapter->rx_buff_pool[i].released); error = kobject_init_and_add(kobj, &ktype_veth_pool, &dev->dev.kobj, "pool%d", i); if (!error) @@ -2011,8 +2046,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) if (rc) { netdev_dbg(netdev, "failed to set number of tx queues rc=%d\n", rc); - free_netdev(netdev); - return rc; + goto err_put_pools; } adapter->tx_ltb_size = PAGE_ALIGN(IBMVETH_MAX_TX_BUF_SIZE); for (i = 0; i < IBMVETH_MAX_QUEUES; i++) @@ -2027,25 +2061,27 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) if (rc) { netdev_dbg(netdev, "failed to register netdev rc=%d\n", rc); - free_netdev(netdev); - return rc; + goto err_put_pools; } netdev_dbg(netdev, "registered\n"); return 0; + +err_put_pools: + ibmveth_put_pool_kobjs(adapter); + free_netdev(netdev); + return rc; } static void ibmveth_remove(struct vio_dev *dev) { struct net_device *netdev = dev_get_drvdata(&dev->dev); struct ibmveth_adapter *adapter = netdev_priv(netdev); - int i; disable_work_sync(&adapter->work); - for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) - kobject_put(&adapter->rx_buff_pool[i].kobj); + ibmveth_put_pool_kobjs(adapter); unregister_netdev(netdev); @@ -2221,7 +2257,7 @@ static const struct sysfs_ops veth_pool_ops = { }; static struct kobj_type ktype_veth_pool = { - .release = NULL, + .release = ibmveth_pool_kobj_release, .sysfs_ops = &veth_pool_ops, .default_groups = veth_pool_groups, }; diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 3f2240823f6a..be0939caa328 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -14,6 +14,8 @@ #ifndef _IBMVETH_H #define _IBMVETH_H +#include + /* constants for H_MULTICAST_CTRL */ #define IbmVethMcastReceptionModifyBit 0x80000UL #define IbmVethMcastReceptionEnableBit 0x20000UL @@ -143,6 +145,7 @@ struct ibmveth_buff_pool { struct sk_buff **skbuff; int active; struct kobject kobj; + struct completion released; }; struct ibmveth_rx_q { From 16abfa871dc840e55f1726408c5994c66a9773e2 Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:23 -0700 Subject: [PATCH 2036/2126] ibmveth: return the error when set_channels cannot add TX queues When ibmveth_set_channels() cannot allocate a TX buffer for a new queue, it falls back to the old queue count, and the successful netif_set_real_num_tx_queues() call then overwrites rc. ethtool -L reports success while the queue count is unchanged. Return the allocation error when the fallback succeeds. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection. Tested on a POWER10 LPAR with the TX buffer allocation forced to fail by a test-only module parameter (not part of this patch): ethtool -L tx 8 now fails with -ENOMEM and the device keeps its four queues and passes traffic. No kernel selftests cover ibmveth. Fixes: 10c2aba89cc0 ("ibmveth: Ethtool set queue support") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-7-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 42aa9f7bd49d..48bc4406396b 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1177,7 +1177,7 @@ static int ibmveth_set_channels(struct net_device *netdev, struct ibmveth_adapter *adapter = netdev_priv(netdev); unsigned int old = netdev->real_num_tx_queues, goal = channels->tx_count; - int rc, i; + int rc, i, alloc_rc = 0; /* If the device is not open (including a failed close/open with * IFF_UP still set) then don't allocate, just set desired @@ -1203,6 +1203,7 @@ static int ibmveth_set_channels(struct net_device *netdev, /* if something goes wrong, free everything we just allocated */ netdev_err(netdev, "Failed to allocate more tx queues, returning to %d queues\n", old); + alloc_rc = rc; goal = old; old = i; break; @@ -1213,6 +1214,8 @@ static int ibmveth_set_channels(struct net_device *netdev, old); goal = old; old = i; + } else if (alloc_rc) { + rc = alloc_rc; } /* Free any that are no longer needed */ for (i = old; i > goal; i--) { From c807573ea58e615339a9c72675c45c157ffe245c Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:24 -0700 Subject: [PATCH 2037/2126] ibmveth: wait for in-flight transmits in ibmveth_close() ibmveth_close() frees the TX buffers after netif_tx_stop_all_queues(), which does not wait for an ibmveth_start_xmit() already running on another CPU. That transmit can copy into a freed buffer and hand PHYP a stale DMA address. MTU, csum/TSO and buffer pool changes call ibmveth_close() directly while traffic flows. ifdown and the reset work go through dev_close(), which waits for running transmits only when the qdisc has an enqueue function, so with noqueue they race the same way. Use netif_tx_disable(), which waits for running transmits. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; the race was not reproduced. Tested on a POWER10 LPAR with MTU changes during a ping flood, with no warnings. No kernel selftests cover ibmveth. Fixes: d6832ca48d8a ("ibmveth: Copy tx skbs into a premapped buffer") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-8-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 48bc4406396b..f2570d637301 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -835,7 +835,7 @@ static int ibmveth_close(struct net_device *netdev) napi_disable(&adapter->napi); - netif_tx_stop_all_queues(netdev); + netif_tx_disable(netdev); h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); From 3f872b34368c7c1d2a8900950e0fee4cb4dd9a34 Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:25 -0700 Subject: [PATCH 2038/2126] ibmveth: wait for the RX poll to return before freeing the RX queue napi_disable() returns once ibmveth_poll() has called napi_complete_done(), but the poll is not finished: it then re-enables the interrupt and calls ibmveth_rxq_pending_buffer(), which reads the RX queue. ibmveth_close() can free that queue in the meantime, and the late enable can leave the interrupt unmasked after close() masked it. The request_irq() failure path in ibmveth_open() frees the same memory after napi_disable() too. Call synchronize_net() after napi_disable() on both paths. Every caller of ibmveth_poll() runs it with bottom halves or interrupts disabled, so this waits for the poll to return. Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; also raised by the Sashiko review of the first version of this series. The race was not reproduced. Tested on a POWER10 LPAR under an incoming ping flood with 30 rapid link down/up cycles and 30 rapid MTU cycles (1500 <-> 9000); ran cleanly with no warnings or faults. No kernel selftests cover ibmveth. Fixes: bea3348eef27 ("[NET]: Make NAPI polling independent of struct net_device objects.") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-9-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index f2570d637301..85e176d0ed32 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -768,6 +768,7 @@ static int ibmveth_open(struct net_device *netdev) netdev); if (rc != 0) { napi_disable(&adapter->napi); + synchronize_net(); netdev_err(netdev, "unable to request irq 0x%x, rc %d\n", netdev->irq, rc); goto out_free_buffer_pools; @@ -834,6 +835,11 @@ static int ibmveth_close(struct net_device *netdev) netdev_dbg(netdev, "close starting\n"); napi_disable(&adapter->napi); + /* napi_disable() returns once ibmveth_poll() has called + * napi_complete_done(), but the poll still re-enables the + * interrupt and reads the RX queue after that. + */ + synchronize_net(); netif_tx_disable(netdev); From 9486c89a8e157cedecfb561c3d86053e654d32ab Mon Sep 17 00:00:00 2001 From: Mingming Cao Date: Tue, 13 Oct 2026 11:29:26 -0700 Subject: [PATCH 2039/2126] ibmveth: check headers in the RX large send and checksum helpers ibmveth_rx_mss_helper() and ibmveth_rx_csum_helper() trust the IP and TCP headers of received frames, which come from another partition on the virtual LAN. The worst case is an IPv4 frame with ihl 0 and iph->check 0xffff: the checksum helper calls ip_fast_csum(iph, 0), and the ppc64 version loops ihl - 1 times on an unsigned count, reading up to 16 GiB in softirq: a long stall, or an oops once the read leaves mapped memory. Both helpers also read and write header fields past the end of a short frame. The large send helper takes the segment size from the TCP checksum field and gso_segs from a TCP header length it never checks, and treats an IPv4 TCP fragment as a large send, which can zero two of its bytes; the checksum helper can write a checksum into a later fragment's payload. The ihl problem dates from the first commit in Fixes:, the large send helper from the second, and the checksum helper from the third. Before using a header, check that it fits the frame, that the IPv4 ihl is at least 5, and that an IPv4 TCP frame is not a fragment. In the large send helper, also require a TCP doff of at least 5, TCP payload within the IP length, and an IP length equal to the frame length: Ethernet padding or other bytes past the IP length would otherwise stay in a bridged or switched frame, which the stack does not trim, and be segmented but not counted in gso_segs. Compute gso_segs from the IP length, and keep the segment size at or above TCP_MIN_GSO_SIZE, as virtio_net_hdr_to_skb() does since commit c27c449d455a ("virtio-net: Ensure that TCP packets don't overflow gso_segs"), and below GSO_BY_FRAGS, which virtio rejects. With the headers checked and gso_segs computed, the skb is not marked SKB_GSO_DODGY, which would also keep it from hardware TSO on the egress device. A frame that fails a check is passed up unchanged, without the GSO fields or CHECKSUM_UNNECESSARY, so nothing downstream trusts its segment count or checksum. The skb is linear, so the checks use skb_headlen(); pskb_may_pull() could reallocate the head under the helpers' header pointers. Add KUnit cases for both helpers: valid IPv4 and IPv6 large sends, the segment size clamp, and refused frames. With any one of the ihl, doff, IP length, TCP payload, fragment or clamp checks, or the checksum helper's IPv4 options, IPv6 header or TCP header length checks, removed, a case fails; without the checksum helper's ihl check, ip_fast_csum() oopses on qemu. Found by the Sashiko review of the previous version of this series and confirmed by code inspection and the KUnit cases above. Tested with KUnit on qemu pseries (ppc64le) and on a POWER10 LPAR with iperf3 large sends over IPv4 and IPv6 at MTU 1500 and 9000, threaded NAPI and busy polling, with no new drops or InCsumErrors. No kernel selftests cover ibmveth. Fixes: 9c7e8bc584f5 ("ibmveth: Add support for Large Receive Offload") Fixes: 7b5967389f5a ("ibmveth: set correct gso_size and gso_type") Fixes: 66aa0678efc2 ("ibmveth: Support to enable LSO/CSO for Trunk VEA.") Signed-off-by: Mingming Cao Link: https://patch.msgid.link/20261013182926.30417-10-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ibm/ibmveth.c | 286 ++++++++++++++++++++++++++++- 1 file changed, 277 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 85e176d0ed32..e9874dfedf37 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1396,8 +1396,12 @@ out: } -static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) +/* Returns false when the IP or TCP headers fail the checks; the frame is + * then left unchanged and not marked GSO. + */ +static bool ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) { + unsigned int gso_type, ip_len; struct tcphdr *tcph; int offset = 0; int hdr_len; @@ -1406,28 +1410,41 @@ static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) if (skb->protocol == htons(ETH_P_IP)) { struct iphdr *iph = (struct iphdr *)skb->data; + if (skb_headlen(skb) < sizeof(*iph) || iph->ihl < 5) + return false; if (iph->protocol == IPPROTO_TCP) { + /* only a whole datagram has a TCP header to segment */ + if (ip_is_fragment(iph)) + return false; offset = iph->ihl * 4; - skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; + ip_len = ntohs(iph->tot_len); + gso_type = SKB_GSO_TCPV4; } else { - return; + return true; } } else if (skb->protocol == htons(ETH_P_IPV6)) { struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data; + if (skb_headlen(skb) < sizeof(*iph6)) + return false; if (iph6->nexthdr == IPPROTO_TCP) { offset = sizeof(struct ipv6hdr); - skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; + ip_len = offset + ntohs(iph6->payload_len); + gso_type = SKB_GSO_TCPV6; } else { - return; + return true; } } else { - return; + return true; } /* if mss is not set through Large Packet bit/mss in rx buffer, * expect that the mss will be written to the tcp header checksum. */ tcph = (struct tcphdr *)(skb->data + offset); + if (skb_headlen(skb) < offset + sizeof(*tcph) || tcph->doff < 5 || + ip_len != skb_headlen(skb) || ip_len <= offset + tcph->doff * 4) + return false; + skb_shinfo(skb)->gso_type = gso_type; if (lrg_pkt) { skb_shinfo(skb)->gso_size = mss; } else if (offset) { @@ -1436,11 +1453,18 @@ static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) } if (skb_shinfo(skb)->gso_size) { + /* chosen by the sending partition: at least the floor + * virtio_net_hdr_to_skb() uses, and never GSO_BY_FRAGS + */ + skb_shinfo(skb)->gso_size = + clamp_t(u16, skb_shinfo(skb)->gso_size, + TCP_MIN_GSO_SIZE, GSO_BY_FRAGS - 1); hdr_len = offset + tcph->doff * 4; skb_shinfo(skb)->gso_segs = - DIV_ROUND_UP(skb->len - hdr_len, + DIV_ROUND_UP(ip_len - hdr_len, skb_shinfo(skb)->gso_size); } + return true; } static void ibmveth_rx_csum_helper(struct sk_buff *skb, @@ -1457,6 +1481,10 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb, if (skb_proto == ETH_P_IP) { iph = (struct iphdr *)skb->data; + if (skb_headlen(skb) < sizeof(*iph) || iph->ihl < 5 || + skb_headlen(skb) < iph->ihl * 4 || + (iph->protocol == IPPROTO_TCP && ip_is_fragment(iph))) + goto bad_hdr; /* If the IP checksum is not offloaded and if the packet * is large send, the checksum must be rebuilt. @@ -1471,6 +1499,8 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb, iph_proto = iph->protocol; } else if (skb_proto == ETH_P_IPV6) { iph6 = (struct ipv6hdr *)skb->data; + if (skb_headlen(skb) < sizeof(*iph6)) + goto bad_hdr; iphlen = sizeof(struct ipv6hdr); iph_proto = iph6->nexthdr; } @@ -1493,6 +1523,8 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb, if (iph_proto == IPPROTO_TCP) { struct tcphdr *tcph = (struct tcphdr *)(skb->data + iphlen); + if (skb_headlen(skb) < iphlen + sizeof(*tcph)) + goto bad_hdr; if (tcph->check == 0x0000) { /* Recompute TCP pseudo header checksum */ tcphdrlen = skb->len - iphlen; @@ -1510,6 +1542,13 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb, skb_reset_network_header(skb); } } + return; + +bad_hdr: + /* headers do not fit the frame, or a fragment has no whole TCP + * segment; let the stack check it + */ + skb->ip_summed = CHECKSUM_NONE; } static int ibmveth_poll(struct napi_struct *napi, int budget) @@ -1624,7 +1663,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget) /* PHYP without PLSO support places a -1 in the ip * checksum for large send frames. */ - if (skb->protocol == cpu_to_be16(ETH_P_IP)) { + if (skb->protocol == cpu_to_be16(ETH_P_IP) && + skb_headlen(skb) >= sizeof(struct iphdr)) { struct iphdr *iph = (struct iphdr *)skb->data; iph_check = iph->check; @@ -1632,7 +1672,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget) if ((length > netdev->mtu + ETH_HLEN) || lrg_pkt || iph_check == 0xffff) { - ibmveth_rx_mss_helper(skb, mss, lrg_pkt); + if (!ibmveth_rx_mss_helper(skb, mss, lrg_pkt)) + csum_good = 0; adapter->rx_large_packets++; } @@ -2508,10 +2549,237 @@ static void ibmveth_rxq_harvest_buffer_test(struct kunit *test) flush_work(&adapter->work); } +KUNIT_DEFINE_ACTION_WRAPPER(ibmveth_kfree_skb, kfree_skb, struct sk_buff *); + +/* A TCP frame after eth_type_trans(): IP header, 20 byte TCP header and + * payload bytes of data, with the IP length matching the frame. + */ +static struct sk_buff *ibmveth_test_tcp_skb(struct kunit *test, bool ipv6, + unsigned int payload) +{ + unsigned int iplen = ipv6 ? sizeof(struct ipv6hdr) : + sizeof(struct iphdr); + unsigned int len = iplen + sizeof(struct tcphdr) + payload; + struct sk_buff *skb = alloc_skb(len, GFP_KERNEL); + struct tcphdr *tcph; + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb); + KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, + ibmveth_kfree_skb, + skb)); + skb_put_zero(skb, len); + if (ipv6) { + struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data; + + skb->protocol = htons(ETH_P_IPV6); + iph6->version = 6; + iph6->nexthdr = IPPROTO_TCP; + iph6->payload_len = htons(len - iplen); + } else { + struct iphdr *iph = (struct iphdr *)skb->data; + + skb->protocol = htons(ETH_P_IP); + iph->version = 4; + iph->ihl = 5; + iph->protocol = IPPROTO_TCP; + iph->tot_len = htons(len); + } + tcph = (struct tcphdr *)(skb->data + iplen); + tcph->doff = 5; + return skb; +} + +/** + * ibmveth_rx_mss_helper_test - unit test for ibmveth_rx_mss_helper + * @test: pointer to kunit structure + * + * Large send frames get gso_size from the descriptor or the TCP checksum + * field, clamped, and gso_segs from the IP length. Frames whose headers + * do not fit, whose IP length is not the frame length, with no TCP + * payload within the IP length, or that are IPv4 fragments, are refused + * and left without GSO. + * + * Return: void + */ +static void ibmveth_rx_mss_helper_test(struct kunit *test) +{ + struct sk_buff *skb; + struct tcphdr *tcph; + struct iphdr *iph; + + skb = ibmveth_test_tcp_skb(test, false, 2896); + tcph = (struct tcphdr *)(skb->data + sizeof(*iph)); + tcph->check = (__force __sum16)htons(1448); + KUNIT_EXPECT_TRUE(test, ibmveth_rx_mss_helper(skb, 0, 0)); + KUNIT_EXPECT_EQ(test, SKB_GSO_TCPV4, skb_shinfo(skb)->gso_type); + KUNIT_EXPECT_EQ(test, 1448, skb_shinfo(skb)->gso_size); + KUNIT_EXPECT_EQ(test, 2, skb_shinfo(skb)->gso_segs); + KUNIT_EXPECT_EQ(test, 0, (__force u16)tcph->check); + + skb = ibmveth_test_tcp_skb(test, false, 2896); + KUNIT_EXPECT_TRUE(test, ibmveth_rx_mss_helper(skb, 1000, 1)); + KUNIT_EXPECT_EQ(test, 1000, skb_shinfo(skb)->gso_size); + KUNIT_EXPECT_EQ(test, 3, skb_shinfo(skb)->gso_segs); + + skb = ibmveth_test_tcp_skb(test, true, 2896); + tcph = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr)); + tcph->check = (__force __sum16)htons(1448); + KUNIT_EXPECT_TRUE(test, ibmveth_rx_mss_helper(skb, 0, 0)); + KUNIT_EXPECT_EQ(test, SKB_GSO_TCPV6, skb_shinfo(skb)->gso_type); + KUNIT_EXPECT_EQ(test, 1448, skb_shinfo(skb)->gso_size); + KUNIT_EXPECT_EQ(test, 2, skb_shinfo(skb)->gso_segs); + + skb = ibmveth_test_tcp_skb(test, false, 2896); + KUNIT_EXPECT_TRUE(test, ibmveth_rx_mss_helper(skb, 1, 1)); + KUNIT_EXPECT_EQ(test, TCP_MIN_GSO_SIZE, skb_shinfo(skb)->gso_size); + + skb = ibmveth_test_tcp_skb(test, false, 2896); + KUNIT_EXPECT_TRUE(test, ibmveth_rx_mss_helper(skb, GSO_BY_FRAGS, 1)); + KUNIT_EXPECT_EQ(test, GSO_BY_FRAGS - 1, skb_shinfo(skb)->gso_size); + + /* refused: ihl 0, doff 4, IP length past the frame. With ihl 0 the + * TCP header would overlap the IP header; saddr makes its doff 5. + */ + skb = ibmveth_test_tcp_skb(test, false, 2896); + ((struct iphdr *)skb->data)->ihl = 0; + ((struct iphdr *)skb->data)->saddr = htonl(0x50000000); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); + + skb = ibmveth_test_tcp_skb(test, false, 2896); + ((struct tcphdr *)(skb->data + sizeof(*iph)))->doff = 4; + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + + skb = ibmveth_test_tcp_skb(test, false, 2896); + ((struct iphdr *)skb->data)->tot_len = htons(skb->len + 1); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + + /* refused: bytes past the IP length, its large send fields left + * alone; gso_segs from the IP length would undercount them + */ + skb = ibmveth_test_tcp_skb(test, false, 2896); + ((struct iphdr *)skb->data)->tot_len = htons(skb->len - 100); + tcph = (struct tcphdr *)(skb->data + sizeof(*iph)); + tcph->check = (__force __sum16)htons(1448); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 0, 0)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); + KUNIT_EXPECT_EQ(test, 1448, ntohs((__force __be16)tcph->check)); + + /* refused: a fragment past the first, its payload left alone */ + skb = ibmveth_test_tcp_skb(test, false, 2896); + ((struct iphdr *)skb->data)->frag_off = htons(185); + tcph = (struct tcphdr *)(skb->data + sizeof(*iph)); + tcph->check = (__force __sum16)htons(1448); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 0, 0)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); + KUNIT_EXPECT_EQ(test, 1448, ntohs((__force __be16)tcph->check)); + + /* refused: only Ethernet padding past the TCP header */ + skb = ibmveth_test_tcp_skb(test, false, 6); + ((struct iphdr *)skb->data)->tot_len = htons(40); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); + + skb = ibmveth_test_tcp_skb(test, true, 2896); + ((struct ipv6hdr *)skb->data)->payload_len = 0; + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + + /* refused: no TCP payload, with the IP length matching the frame */ + skb = ibmveth_test_tcp_skb(test, false, 0); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); + + skb = ibmveth_test_tcp_skb(test, true, 0); + KUNIT_EXPECT_FALSE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); + + /* not TCP: accepted and left alone */ + skb = ibmveth_test_tcp_skb(test, false, 2896); + ((struct iphdr *)skb->data)->protocol = IPPROTO_UDP; + KUNIT_EXPECT_TRUE(test, ibmveth_rx_mss_helper(skb, 1448, 1)); + KUNIT_EXPECT_EQ(test, 0, skb_shinfo(skb)->gso_size); +} + +/** + * ibmveth_rx_csum_helper_test - unit test for ibmveth_rx_csum_helper + * @test: pointer to kunit structure + * + * A large send IPv4 header checksum of 0xffff is rebuilt. Headers that + * do not fit the frame, an IPv4 ihl below 5, or a TCP fragment, clear + * CHECKSUM_UNNECESSARY instead of being read. + * + * Return: void + */ +static void ibmveth_rx_csum_helper_test(struct kunit *test) +{ + struct sk_buff *skb; + struct tcphdr *tcph; + struct iphdr *iph; + + skb = ibmveth_test_tcp_skb(test, false, 100); + iph = (struct iphdr *)skb->data; + iph->check = (__force __sum16)0xffff; + tcph = (struct tcphdr *)(skb->data + sizeof(*iph)); + tcph->check = (__force __sum16)htons(1); + skb->ip_summed = CHECKSUM_UNNECESSARY; + ibmveth_rx_csum_helper(skb, NULL); + KUNIT_EXPECT_EQ(test, 0, (__force u16)ip_fast_csum(iph, iph->ihl)); + KUNIT_EXPECT_EQ(test, CHECKSUM_UNNECESSARY, (int)skb->ip_summed); + + skb = ibmveth_test_tcp_skb(test, false, 100); + iph = (struct iphdr *)skb->data; + iph->ihl = 0; + iph->check = (__force __sum16)0xffff; + skb->ip_summed = CHECKSUM_UNNECESSARY; + ibmveth_rx_csum_helper(skb, NULL); + KUNIT_EXPECT_EQ(test, CHECKSUM_NONE, (int)skb->ip_summed); + KUNIT_EXPECT_EQ(test, 0xffff, (__force u16)iph->check); + + /* IPv4 options past the frame; UDP, so no TCP check follows */ + skb = ibmveth_test_tcp_skb(test, false, 0); + iph = (struct iphdr *)skb->data; + iph->protocol = IPPROTO_UDP; + iph->ihl = 15; + iph->check = (__force __sum16)0xffff; + skb->ip_summed = CHECKSUM_UNNECESSARY; + ibmveth_rx_csum_helper(skb, NULL); + KUNIT_EXPECT_EQ(test, CHECKSUM_NONE, (int)skb->ip_summed); + + /* a TCP fragment past the first: header and payload left alone */ + skb = ibmveth_test_tcp_skb(test, false, 100); + iph = (struct iphdr *)skb->data; + iph->frag_off = htons(185); + iph->check = (__force __sum16)0xffff; + skb->ip_summed = CHECKSUM_UNNECESSARY; + ibmveth_rx_csum_helper(skb, NULL); + KUNIT_EXPECT_EQ(test, CHECKSUM_NONE, (int)skb->ip_summed); + KUNIT_EXPECT_EQ(test, 0xffff, (__force u16)iph->check); + KUNIT_EXPECT_EQ(test, 0, + (__force u16)((struct tcphdr *)(skb->data + + sizeof(*iph)))->check); + + /* TCP header past the frame */ + skb = ibmveth_test_tcp_skb(test, false, 0); + skb_trim(skb, sizeof(struct iphdr)); + skb->ip_summed = CHECKSUM_UNNECESSARY; + ibmveth_rx_csum_helper(skb, NULL); + KUNIT_EXPECT_EQ(test, CHECKSUM_NONE, (int)skb->ip_summed); + + /* IPv6 header past the frame; UDP, so no TCP check follows */ + skb = ibmveth_test_tcp_skb(test, true, 0); + ((struct ipv6hdr *)skb->data)->nexthdr = IPPROTO_UDP; + skb_trim(skb, sizeof(struct ipv6hdr) - 1); + skb->ip_summed = CHECKSUM_UNNECESSARY; + ibmveth_rx_csum_helper(skb, NULL); + KUNIT_EXPECT_EQ(test, CHECKSUM_NONE, (int)skb->ip_summed); +} + static struct kunit_case ibmveth_test_cases[] = { KUNIT_CASE(ibmveth_remove_buffer_from_pool_test), KUNIT_CASE(ibmveth_rxq_get_buffer_test), KUNIT_CASE(ibmveth_rxq_harvest_buffer_test), + KUNIT_CASE(ibmveth_rx_mss_helper_test), + KUNIT_CASE(ibmveth_rx_csum_helper_test), {} }; From c0703534b223a5c6993e0f000fd1c3abe621fb65 Mon Sep 17 00:00:00 2001 From: Bryam Vargas Date: Tue, 13 Oct 2026 15:45:01 -0500 Subject: [PATCH 2040/2126] net/smc: queue the copied chunk when smc_tx_sendmsg() faults When a send wraps the end of the send buffer, smc_tx_sendmsg() copies the data in two chunks. If memcpy_from_msg() faults on the second one, smc_tx_sendmsg() returns send_done, which already counts the first chunk, but leaves tx_curs_prep and sndbuf_space as they were. send() reports bytes the peer never receives, and the next send() overwrites them. Any caller can hit this on its own stream with a buffer whose tail is unreadable. On a fault in the second chunk, queue the first one. The next pass retries the rest and returns send_done if it faults again, so send() reports only what it queued, as TCP does. Fixes: e6727f39004b ("smc: send data (through RDMA)") Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas Link: https://patch.msgid.link/20261013-b4-disp-872a3689-v1-1-2a4c63b04761@proton.me Signed-off-by: Jakub Kicinski --- net/smc/smc_tx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c index 3144b4b1fe29..495fb1354728 100644 --- a/net/smc/smc_tx.c +++ b/net/smc/smc_tx.c @@ -249,6 +249,13 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len) rc = memcpy_from_msg(sndbuf_base + chunk_off, msg, chunk_len); if (rc) { + if (chunk) { + /* send_done counts the first chunk: + * queue it and retry the rest + */ + copylen -= chunk_len; + break; + } smc_sndbuf_sync_sg_for_device(conn); if (send_done) return send_done; From 599d0e97610f09162d84c4ede4164628c066921e Mon Sep 17 00:00:00 2001 From: Ali Firas Date: Wed, 14 Oct 2026 15:38:08 +0300 Subject: [PATCH 2041/2126] vxlan: vnifilter: validate the VXLAN_VNIFILTER_ENTRY nest vxlan_vnifilter_process() parses the message with vni_filter_policy, whose VXLAN_VNIFILTER_ENTRY is a bare NLA_NESTED with no nested policy attached. The entry attributes are therefore validated only later, one entry at a time, by the nla_parse_nested() inside vxlan_process_vni_filter(). Entries are parsed as they are dispatched: in a message whose first entry is valid and whose second is not, the first entry is applied and its RTM_NEWTUNNEL notification sent before the second is rejected. Link the nest to vni_filter_entry_policy with NLA_POLICY_NESTED() so every entry is checked against the entry policy up front, before any entry is acted on. A message whose entry the policy rejects -- a malformed attribute, or, with the next patch, an out-of-range endpoint -- is now refused as a unit and installs nothing. Faults the policy does not cover, such as a device or handler error raised on a later entry, are unchanged: entries are still dispatched and applied one at a time. This reorders two faults. The nest is validated before the device is looked up and before the vnifilter flag is checked, so a request rejected by the entry policy, aimed at a missing or non-vnifilter device, now returns that policy error where it previously returned -ENODEV or -EOPNOTSUPP. The request was invalid either way; only the errno an operator sees changes. The nla_parse_nested() in vxlan_process_vni_filter() stays: it is what fills the per-entry attribute table the handler reads. It can no longer fail on a message that has reached it. Suggested-by: Jakub Kicinski Link: https://lore.kernel.org/netdev/20260921150904.65a704eb@kernel.org/ Signed-off-by: Ali Firas Link: https://patch.msgid.link/20261014123814.388557-2-alishmery18@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/vxlan/vxlan_vnifilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index 41095096b698..124ba47758e9 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -499,7 +499,7 @@ static const struct nla_policy vni_filter_entry_policy[VXLAN_VNIFILTER_ENTRY_MAX }; static const struct nla_policy vni_filter_policy[VXLAN_VNIFILTER_MAX + 1] = { - [VXLAN_VNIFILTER_ENTRY] = { .type = NLA_NESTED }, + [VXLAN_VNIFILTER_ENTRY] = NLA_POLICY_NESTED(vni_filter_entry_policy), }; bool vxlan_vnifilter_has_multicast(const struct vxlan_dev *vxlan) From 746d0e7e851edefce9656ce744d4ec5e94de6b5f Mon Sep 17 00:00:00 2001 From: Michael Chan Date: Tue, 20 Oct 2026 15:53:58 -0700 Subject: [PATCH 2042/2126] MAINTAINERS: Update Michael Chan's email for tg3 My old email address doesn't work anymore. Update it to the current working one. Signed-off-by: Michael Chan Link: https://patch.msgid.link/20261020225358.1130051-1-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski --- .mailmap | 1 + MAINTAINERS | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 0a0be49bc4de..16c3e6599082 100644 --- a/.mailmap +++ b/.mailmap @@ -638,6 +638,7 @@ Mayuresh Janorkar Md Sadre Alam Miaoqing Pan Michael Buesch +Michael Chan Michael Grzeschik Michael Grzeschik Michael Riesch diff --git a/MAINTAINERS b/MAINTAINERS index 00b440be0d46..4941eeec4a0a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5623,7 +5623,7 @@ F: drivers/net/ethernet/broadcom/unimac.h BROADCOM TG3 GIGABIT ETHERNET DRIVER M: Pavan Chebbi -M: Michael Chan +M: Michael Chan L: netdev@vger.kernel.org S: Maintained F: drivers/net/ethernet/broadcom/tg3.* From 70c29b35fd87f87a7b8dad6eb8d55ce54a0d549a Mon Sep 17 00:00:00 2001 From: Carlo Szelinsky Date: Tue, 20 Oct 2026 19:11:32 +0200 Subject: [PATCH 2043/2126] net: pse-pd: si3474: fix use-after-free in ancillary client error path If devm_add_action_or_reset() fails, it has already unregistered the ancillary I2C client, and the error message then reads that client's device. It can only fail with -ENOMEM, which is already reported, so drop the message. Found by code inspection. Not reproduced. Fixes: a2317231df4b ("net: pse-pd: Add Si3474 PSE controller driver") Reviewed-by: Kory Maincent Signed-off-by: Carlo Szelinsky Link: https://patch.msgid.link/20261020171134.852878-2-github@szelinsky.de Signed-off-by: Jakub Kicinski --- drivers/net/pse-pd/si3474.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/pse-pd/si3474.c b/drivers/net/pse-pd/si3474.c index 1845b9c51cf7..2f4f241a48af 100644 --- a/drivers/net/pse-pd/si3474.c +++ b/drivers/net/pse-pd/si3474.c @@ -516,10 +516,8 @@ static int si3474_i2c_probe(struct i2c_client *client) return PTR_ERR(priv->client[1]); ret = devm_add_action_or_reset(dev, si3474_ancillary_i2c_remove, priv->client[1]); - if (ret < 0) { - dev_err(&priv->client[1]->dev, "Cannot register remove callback\n"); + if (ret) return ret; - } ret = i2c_smbus_read_byte_data(priv->client[1], VENDOR_IC_ID_REG); if (ret < 0) { From 569b57762694e7a4d4cffde35f65dbab5a2fc9cf Mon Sep 17 00:00:00 2001 From: Carlo Szelinsky Date: Tue, 20 Oct 2026 19:11:33 +0200 Subject: [PATCH 2044/2126] net: pse-pd: si3474: use dev_err_probe() for controller registration si3474 prints the error of a failed controller registration as a hex number, such as 0xfffffff4 for -ENOMEM. Use dev_err_probe(), as pd692x0 and tps23881 already do. It prints the error by name, and if the registration ever returns -EPROBE_DEFER, it does not log that as an error. Only the log message changes. Signed-off-by: Carlo Szelinsky Link: https://patch.msgid.link/20261020171134.852878-3-github@szelinsky.de Signed-off-by: Jakub Kicinski --- drivers/net/pse-pd/si3474.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/pse-pd/si3474.c b/drivers/net/pse-pd/si3474.c index 2f4f241a48af..efb0af041599 100644 --- a/drivers/net/pse-pd/si3474.c +++ b/drivers/net/pse-pd/si3474.c @@ -539,10 +539,9 @@ static int si3474_i2c_probe(struct i2c_client *client) priv->pcdev.nr_lines = SI3474_MAX_CHANS; ret = devm_pse_controller_register(dev, &priv->pcdev); - if (ret) { - dev_err(dev, "Failed to register PSE controller: 0x%x\n", ret); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, + "Failed to register PSE controller\n"); return 0; } From 78d4bd22ec9df490135303c00e190ac43d5c334a Mon Sep 17 00:00:00 2001 From: Carolina Jubran Date: Mon, 19 Oct 2026 20:41:52 +0300 Subject: [PATCH 2045/2126] net: skbuff: don't copy alloc_cpu in skb header copies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") added alloc_cpu to struct sk_buff and placed it in the headers group copied by __copy_skb_header(). This is wrong for newly allocated skbs. For example, skb_segment() allocates a new skb and records the current CPU in alloc_cpu, but __copy_skb_header() overwrites it with the value from the original skb. If the original skb was allocated on another CPU, the segment may later be treated as remotely allocated and unnecessarily deferred there when it is freed. Move alloc_cpu out of the headers group so it is preserved across header copies. Copy it explicitly in skb_clone(), which allocates the skb object directly instead of going through __alloc_skb(). This was discovered while investigating a throughput regression with software IPsec. The load used 512 IPsec tunnels carrying traffic over VXLAN, with 512 parallel iperf3 flows and an MTU of 4500. Before the fix: 16.09% queued_spin_lock_slowpath | --15.90%--_raw_spin_lock_irqsave | --9.37%--__slab_free kfree skb_release_data napi_consume_skb mlx5e_poll_tx_cq After the fix: 6.84% queued_spin_lock_slowpath | --6.57%--_raw_spin_lock_irqsave | --5.00%--__slab_free kfree skb_release_data napi_consume_skb mlx5e_poll_tx_cq Fixes: 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") Signed-off-by: Carolina Jubran Reviewed-by: Dragos Tatulea Reviewed-by: Björn Töpel Reviewed-by: Jason Xing Reviewed-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261019174152.2932829-1-cjubran@nvidia.com Signed-off-by: Jakub Kicinski --- include/linux/skbuff.h | 4 ++-- net/core/skbuff.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a3ff380d43f0..d6894f463bf4 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1036,8 +1036,6 @@ struct sk_buff { __u16 tc_index; /* traffic control index */ #endif - u16 alloc_cpu; - union { __wsum csum; struct { @@ -1088,6 +1086,8 @@ struct sk_buff { ); /* end headers group */ + u16 alloc_cpu; + /* These elements must be at the end, see alloc_skb() for details. */ sk_buff_data_t tail; sk_buff_data_t end; diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 41beaf625421..ab178af02a22 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1593,7 +1593,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) #ifdef CONFIG_NET_RX_BUSY_POLL CHECK_SKB_FIELD(napi_id); #endif - CHECK_SKB_FIELD(alloc_cpu); #ifdef CONFIG_XPS CHECK_SKB_FIELD(sender_cpu); #endif @@ -1625,6 +1624,7 @@ static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb) C(pfmemalloc); C(pp_recycle); n->destructor = NULL; + C(alloc_cpu); C(tail); C(end); C(head); From d09d7b8e86e597da21dd26c9883831ddf5c25aae Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:40 +0200 Subject: [PATCH 2046/2126] net: stmmac: dwmac4: don't program the 1us tick counter without a CSR clock dwmac4_core_init() derives the TIC counter value from the rate of the CSR clock. If no such clock is available (for instance because clocks are managed by firmware and not described in DT), the rate is 0 and (0 / 1000000) - 1 underflows to 0xffffffff, which is then written to the register and can break the LPI timers that count in microseconds. Leave the register at its reset value when the CSR clock rate is unknown. The RX watchdog conversion helpers already cope with a missing clock by falling back to clk_ref_rate or returning 0, so nothing else needs to change. This is first hit with the Qualcomm sa8255p ethernet, whose DT has no clocks. Reported-by: Sashiko Closes: https://lore.kernel.org/all/179052656185.2160803.1751830002645522416@kernel.org/ Signed-off-by: Bartosz Golaszewski Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-1-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index cd6c5d6f42b5..259e2ebed8c1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -48,9 +48,14 @@ static void dwmac4_core_init(struct mac_device_info *hw, value = readl(ioaddr + GMAC_CONFIG); writel(value | GMAC_CORE_INIT, ioaddr + GMAC_CONFIG); - /* Configure LPI 1us counter to number of CSR clock ticks in 1us - 1 */ + /* Configure LPI 1us counter to number of CSR clock ticks in 1us - 1. + * Platforms with firmware-managed clocks may not expose the CSR clock + * to linux, in which case there's no meaningful value to program. + */ clk_rate = clk_get_rate(priv->plat->stmmac_clk); - writel((clk_rate / 1000000) - 1, ioaddr + GMAC4_MAC_ONEUS_TIC_COUNTER); + if (clk_rate >= 1000000) + writel((clk_rate / 1000000) - 1, + ioaddr + GMAC4_MAC_ONEUS_TIC_COUNTER); /* Enable GMAC interrupts */ writel(GMAC_INT_DEFAULT_ENABLE, ioaddr + GMAC_INT_EN); From 534198a05d926f8508e36d44b9529729d6794cde Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:41 +0200 Subject: [PATCH 2047/2126] dt-bindings: net: qcom: document the ethqos device for SCMI-based systems Describe the firmware-managed variant of the QCom DesignWare MAC. As the properties here differ a lot from the HLOS-managed variant, lets put it in a separate file. Since we need to update the maximum number of power domains, let's update existing bindings referencing the top-level snps,dwmac.yaml and limit their maxItems for power-domains to 1. Signed-off-by: Bartosz Golaszewski Reviewed-by: Martin Blumenstingl Reviewed-by: Krzysztof Kozlowski Reviewed-by: Lad Prabhakar Reviewed-by: Romain Gantois # For RZ/N1 Signed-off-by: Bartosz Golaszewski Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-2-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../net/allwinner,sun7i-a20-gmac.yaml | 3 + .../bindings/net/altr,socfpga-stmmac.yaml | 3 + .../bindings/net/amlogic,meson-dwmac.yaml | 3 + .../bindings/net/eswin,eic7700-eth.yaml | 3 + .../bindings/net/intel,dwmac-plat.yaml | 3 + .../bindings/net/loongson,ls1b-gmac.yaml | 3 + .../bindings/net/loongson,ls1c-emac.yaml | 3 + .../bindings/net/nuvoton,ma35d1-dwmac.yaml | 3 + .../bindings/net/nxp,dwmac-imx.yaml | 3 + .../bindings/net/nxp,lpc1850-dwmac.yaml | 3 + .../bindings/net/nxp,s32-dwmac.yaml | 3 + .../devicetree/bindings/net/qcom,ethqos.yaml | 3 + .../bindings/net/qcom,sa8255p-ethqos.yaml | 107 ++++++++++++++++++ .../bindings/net/renesas,rzn1-gmac.yaml | 3 + .../bindings/net/renesas,rzv2h-gbeth.yaml | 3 + .../bindings/net/rockchip-dwmac.yaml | 3 + .../devicetree/bindings/net/snps,dwmac.yaml | 5 +- .../bindings/net/sophgo,cv1800b-dwmac.yaml | 3 + .../bindings/net/sophgo,sg2044-dwmac.yaml | 3 + .../bindings/net/spacemit,k3-dwmac.yaml | 3 + .../bindings/net/starfive,jh7110-dwmac.yaml | 3 + .../devicetree/bindings/net/stm32-dwmac.yaml | 3 + .../bindings/net/tesla,fsd-ethqos.yaml | 3 + .../bindings/net/thead,th1520-gmac.yaml | 3 + .../bindings/net/toshiba,visconti-dwmac.yaml | 3 + MAINTAINERS | 1 + 26 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/net/qcom,sa8255p-ethqos.yaml diff --git a/Documentation/devicetree/bindings/net/allwinner,sun7i-a20-gmac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun7i-a20-gmac.yaml index 23e92be33ac8..b12632545673 100644 --- a/Documentation/devicetree/bindings/net/allwinner,sun7i-a20-gmac.yaml +++ b/Documentation/devicetree/bindings/net/allwinner,sun7i-a20-gmac.yaml @@ -40,6 +40,9 @@ properties: description: PHY regulator + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml b/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml index d8f90d36d246..ce1bd5f2c470 100644 --- a/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml +++ b/Documentation/devicetree/bindings/net/altr,socfpga-stmmac.yaml @@ -156,6 +156,9 @@ properties: - description: offset of the control register - description: shift within the control register + power-domains: + maxItems: 1 + patternProperties: "^mdio[0-9]$": type: object diff --git a/Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml b/Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml index 5c91716d1f21..9c9cc3ef384d 100644 --- a/Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml @@ -158,6 +158,9 @@ properties: interrupt-names: const: macirq + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/eswin,eic7700-eth.yaml b/Documentation/devicetree/bindings/net/eswin,eic7700-eth.yaml index ba49fd6a086c..b79058b36d70 100644 --- a/Documentation/devicetree/bindings/net/eswin,eic7700-eth.yaml +++ b/Documentation/devicetree/bindings/net/eswin,eic7700-eth.yaml @@ -120,6 +120,9 @@ properties: - description: Optional offset of register controlling TXD delay - description: Optional offset of register controlling RXD delay + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml b/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml index d1522216d32b..81c123fe6bb9 100644 --- a/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml +++ b/Documentation/devicetree/bindings/net/intel,dwmac-plat.yaml @@ -47,6 +47,9 @@ properties: interrupt-names: const: macirq + power-domains: + maxItems: 1 + required: - compatible - clocks diff --git a/Documentation/devicetree/bindings/net/loongson,ls1b-gmac.yaml b/Documentation/devicetree/bindings/net/loongson,ls1b-gmac.yaml index c4f3224bad38..c9a131b8d830 100644 --- a/Documentation/devicetree/bindings/net/loongson,ls1b-gmac.yaml +++ b/Documentation/devicetree/bindings/net/loongson,ls1b-gmac.yaml @@ -66,6 +66,9 @@ properties: - mii - rgmii-id + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/loongson,ls1c-emac.yaml b/Documentation/devicetree/bindings/net/loongson,ls1c-emac.yaml index 99001b940b83..49db18423dd8 100644 --- a/Documentation/devicetree/bindings/net/loongson,ls1c-emac.yaml +++ b/Documentation/devicetree/bindings/net/loongson,ls1c-emac.yaml @@ -65,6 +65,9 @@ properties: - mii - rmii + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/nuvoton,ma35d1-dwmac.yaml b/Documentation/devicetree/bindings/net/nuvoton,ma35d1-dwmac.yaml index ab18702e53f9..5301fe64e98b 100644 --- a/Documentation/devicetree/bindings/net/nuvoton,ma35d1-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/nuvoton,ma35d1-dwmac.yaml @@ -69,6 +69,9 @@ properties: items: - const: stmmaceth + power-domains: + maxItems: 1 + phy-mode: enum: - rmii diff --git a/Documentation/devicetree/bindings/net/nxp,dwmac-imx.yaml b/Documentation/devicetree/bindings/net/nxp,dwmac-imx.yaml index e5db346beca9..b240c76e7dd5 100644 --- a/Documentation/devicetree/bindings/net/nxp,dwmac-imx.yaml +++ b/Documentation/devicetree/bindings/net/nxp,dwmac-imx.yaml @@ -83,6 +83,9 @@ properties: description: To select RMII reference clock from external. + power-domains: + maxItems: 1 + required: - compatible - clocks diff --git a/Documentation/devicetree/bindings/net/nxp,lpc1850-dwmac.yaml b/Documentation/devicetree/bindings/net/nxp,lpc1850-dwmac.yaml index 05acd9bc7616..f61188ab0dbe 100644 --- a/Documentation/devicetree/bindings/net/nxp,lpc1850-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/nxp,lpc1850-dwmac.yaml @@ -51,6 +51,9 @@ properties: items: - const: stmmaceth + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml b/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml index 753a04941659..fcad2274302d 100644 --- a/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml @@ -81,6 +81,9 @@ properties: - const: rx - const: ptp_ref + power-domains: + maxItems: 1 + required: - clocks - clock-names diff --git a/Documentation/devicetree/bindings/net/qcom,ethqos.yaml b/Documentation/devicetree/bindings/net/qcom,ethqos.yaml index 423959cb928d..ef520f810577 100644 --- a/Documentation/devicetree/bindings/net/qcom,ethqos.yaml +++ b/Documentation/devicetree/bindings/net/qcom,ethqos.yaml @@ -86,6 +86,9 @@ properties: phy-names: const: serdes + power-domains: + maxItems: 1 + required: - compatible - clocks diff --git a/Documentation/devicetree/bindings/net/qcom,sa8255p-ethqos.yaml b/Documentation/devicetree/bindings/net/qcom,sa8255p-ethqos.yaml new file mode 100644 index 000000000000..5158481e5e5b --- /dev/null +++ b/Documentation/devicetree/bindings/net/qcom,sa8255p-ethqos.yaml @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/qcom,sa8255p-ethqos.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm Ethernet ETHQOS device (firmware managed) + +maintainers: + - Bjorn Andersson + - Konrad Dybcio + - Bartosz Golaszewski + +description: + dwmac based Qualcomm ethernet devices which support Gigabit + ethernet (version v2.3.0 and onwards) with clocks, interconnects, etc. + managed by firmware + +allOf: + - $ref: snps,dwmac.yaml# + +properties: + compatible: + const: qcom,sa8255p-ethqos + + reg: + maxItems: 2 + + reg-names: + items: + - const: stmmaceth + - const: rgmii + + interrupts: + items: + - description: Combined signal for various interrupt events + - description: The interrupt that occurs when HW safety error triggered + + interrupt-names: + items: + - const: macirq + - const: sfty + + power-domains: + minItems: 2 + maxItems: 2 + + power-domain-names: + items: + - const: core + - const: mdio + + phys: + maxItems: 1 + + phy-names: + items: + - const: serdes + + iommus: + maxItems: 1 + + dma-coherent: true + +required: + - compatible + - reg-names + - power-domains + - power-domain-names + +unevaluatedProperties: false + +examples: + - | + #include + + ethernet: ethernet@23040000 { + compatible = "qcom,sa8255p-ethqos"; + reg = <0x23040000 0x10000>, + <0x23056000 0x100>; + reg-names = "stmmaceth", "rgmii"; + + iommus = <&apps_smmu 0x120 0x7>; + + interrupts = , + ; + interrupt-names = "macirq", "sfty"; + + dma-coherent; + + snps,tso; + snps,pbl = <32>; + rx-fifo-depth = <16384>; + tx-fifo-depth = <16384>; + + phy-handle = <ðernet_phy>; + phy-mode = "2500base-x"; + + snps,mtl-rx-config = <&mtl_rx_setup1>; + snps,mtl-tx-config = <&mtl_tx_setup1>; + + power-domains = <&scmi8_pd 0>, <&scmi8_pd 1>; + power-domain-names = "core", "mdio"; + + phys = <&serdes1>; + phy-names = "serdes"; + }; diff --git a/Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml b/Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml index 16dd7a2631ab..ed0d10a19ca4 100644 --- a/Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml +++ b/Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml @@ -44,6 +44,9 @@ properties: phandle pointing to a PCS sub-node compatible with renesas,rzn1-miic.yaml# + power-domains: + maxItems: 1 + required: - compatible diff --git a/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml b/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml index c8f76c8e7584..1c084aafa8f7 100644 --- a/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml +++ b/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml @@ -154,6 +154,9 @@ properties: Documentation/devicetree/bindings/net/pcs/renesas,rzn1-miic.yaml# (Refer RZ/T2H portion in the DT-binding file) + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml b/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml index 80c252845349..3ec3f6dc2a12 100644 --- a/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml @@ -123,6 +123,9 @@ properties: phy-supply: description: PHY regulator + power-domains: + maxItems: 1 + required: - compatible - clocks diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml index 2218a492817f..2c4842404bf6 100644 --- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml +++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml @@ -73,6 +73,7 @@ properties: - nuvoton,ma35d1-dwmac - nxp,s32g2-dwmac - qcom,qcs404-ethqos + - qcom,sa8255p-ethqos - qcom,sa8775p-ethqos - qcom,sc8280xp-ethqos - qcom,sm8150-ethqos @@ -187,7 +188,8 @@ properties: - enum: [ahb, stmmaceth-ocp] power-domains: - maxItems: 1 + minItems: 1 + maxItems: 2 mac-mode: $ref: ethernet-controller.yaml#/properties/phy-connection-type @@ -583,6 +585,7 @@ allOf: - ingenic,x1830-mac - ingenic,x2000-mac - qcom,qcs404-ethqos + - qcom,sa8255p-ethqos - qcom,sa8775p-ethqos - qcom,sc8280xp-ethqos - qcom,sm8150-ethqos diff --git a/Documentation/devicetree/bindings/net/sophgo,cv1800b-dwmac.yaml b/Documentation/devicetree/bindings/net/sophgo,cv1800b-dwmac.yaml index b89456f0ef83..e78cbf594c69 100644 --- a/Documentation/devicetree/bindings/net/sophgo,cv1800b-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/sophgo,cv1800b-dwmac.yaml @@ -49,6 +49,9 @@ properties: reset-names: const: stmmaceth + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml b/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml index e8d3814db0e9..845e2c67d200 100644 --- a/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml @@ -52,6 +52,9 @@ properties: interrupt-names: maxItems: 1 + power-domains: + maxItems: 1 + resets: maxItems: 1 diff --git a/Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml b/Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml index 678eccf044f9..9e0fb995327a 100644 --- a/Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml @@ -56,6 +56,9 @@ properties: reset-names: const: stmmaceth + power-domains: + maxItems: 1 + spacemit,apmu: $ref: /schemas/types.yaml#/definitions/phandle-array items: diff --git a/Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml b/Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml index fdcc61c65f87..c424e7797392 100644 --- a/Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml @@ -75,6 +75,9 @@ properties: The argument one is the offset of phy mode selection, the argument two is the shift of phy mode selection. + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/stm32-dwmac.yaml b/Documentation/devicetree/bindings/net/stm32-dwmac.yaml index 987254900d0d..29b878079ff0 100644 --- a/Documentation/devicetree/bindings/net/stm32-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/stm32-dwmac.yaml @@ -121,6 +121,9 @@ properties: minItems: 1 maxItems: 2 + power-domains: + maxItems: 1 + required: - compatible - clocks diff --git a/Documentation/devicetree/bindings/net/tesla,fsd-ethqos.yaml b/Documentation/devicetree/bindings/net/tesla,fsd-ethqos.yaml index dd7481bb16e5..ad635529d676 100644 --- a/Documentation/devicetree/bindings/net/tesla,fsd-ethqos.yaml +++ b/Documentation/devicetree/bindings/net/tesla,fsd-ethqos.yaml @@ -67,6 +67,9 @@ properties: - rgmii-rxid - rgmii-txid + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml b/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml index b3492a9aa4ef..c859f8bb5d58 100644 --- a/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml +++ b/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml @@ -78,6 +78,9 @@ properties: items: - const: macirq + power-domains: + maxItems: 1 + required: - clocks - clock-names diff --git a/Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml b/Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml index f0f32e18fc85..efa39eab0256 100644 --- a/Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml @@ -48,6 +48,9 @@ properties: interrupt-names: const: macirq + power-domains: + maxItems: 1 + required: - compatible - reg diff --git a/MAINTAINERS b/MAINTAINERS index 7636ab50d44f..409b031d354d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22458,6 +22458,7 @@ L: netdev@vger.kernel.org L: linux-arm-msm@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/qcom,ethqos.yaml +F: Documentation/devicetree/bindings/net/qcom,sa8255p-ethqos.yaml F: drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c QUALCOMM FASTRPC DRIVER From 7af44cb9e44771409953241644643f82f2101a06 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:42 +0200 Subject: [PATCH 2048/2126] net: stmmac: qcom-ethqos: set serdes mode before powerup Call phy_set_mode_ext() before phy_power_on() in qcom_ethqos_serdes_powerup(). This is harmless for existing users but on SCMI systems this is required for the PHY driver to select the right performance level - which translates to the link speed. This is done ahead of adding support for the firmware-managed EMAC on Qualcomm sa8255p. Signed-off-by: Bartosz Golaszewski Reviewed-by: Mohd Ayaan Anwar Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-3-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index ac7d6d3e205a..e2e611a4d2c0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -601,10 +601,22 @@ static int qcom_ethqos_serdes_powerup(struct net_device *ndev, void *priv) if (ret) return ret; + if (ethqos->phy_mode == PHY_INTERFACE_MODE_SGMII || + ethqos->phy_mode == PHY_INTERFACE_MODE_2500BASEX) { + ret = phy_set_mode_ext(ethqos->serdes_phy, PHY_MODE_ETHERNET, + ethqos->phy_mode); + if (ret) + goto err_out; + } + ret = phy_power_on(ethqos->serdes_phy); if (ret) - phy_exit(ethqos->serdes_phy); + goto err_out; + return 0; + +err_out: + phy_exit(ethqos->serdes_phy); return ret; } From 05b3ea7346e3ae2f43927faa0949c29c08d95036 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:43 +0200 Subject: [PATCH 2049/2126] net: stmmac: qcom-ethqos: update phy_mode to the resolved interface in mac_finish() ethqos->phy_mode is read by serdes_powerup() and qcom_ethqos_set_sgmii_loopback() to configure the SerDes and its wrapper for the correct interface. It is set once at probe from the DT phy-mode property and never updated. phylink resolves the actual runtime interface and passes it to the mac_finish() callback. On platforms that only ever operate at one speed these two values are always the same, but when the interface changes at runtime - for example switching between SGMII and 2500BASE-X - the stored value becomes stale. The next serdes_powerup() call, on a subsequent link cycle, then reinitializes the SerDes to the wrong mode. Update ethqos->phy_mode from the interface argument in ethqos_mac_finish_serdes() so that it always reflects the last resolved interface. With that, we now update the phy_mode to the runtime-resolved interface, so any subsequent resume with a 1G SGMII link skips the loopback setup and the DMA reset hangs. To remedy this, extend the guard to include PHY_INTERFACE_MODE_SGMII. Signed-off-by: Bartosz Golaszewski Reviewed-by: Mohd Ayaan Anwar Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-4-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index e2e611a4d2c0..f7cc46d86591 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -190,7 +190,8 @@ static void qcom_ethqos_set_sgmii_loopback(struct qcom_ethqos *ethqos, bool enable) { if (!ethqos->needs_sgmii_loopback || - ethqos->phy_mode != PHY_INTERFACE_MODE_2500BASEX) + (ethqos->phy_mode != PHY_INTERFACE_MODE_2500BASEX && + ethqos->phy_mode != PHY_INTERFACE_MODE_SGMII)) return; rgmii_updatel(ethqos, @@ -637,6 +638,12 @@ static int ethqos_mac_finish_serdes(struct net_device *ndev, void *priv, qcom_ethqos_set_sgmii_loopback(ethqos, false); + /* The interface mode is only known once phylink has resolved it and + * may change at runtime, so keep it in sync for later + * serdes_powerup() and qcom_ethqos_set_sgmii_loopback() calls. + */ + ethqos->phy_mode = interface; + if (interface == PHY_INTERFACE_MODE_SGMII || interface == PHY_INTERFACE_MODE_2500BASEX) ret = phy_set_mode_ext(ethqos->serdes_phy, PHY_MODE_ETHERNET, From 92719abd63787729c89d353db1a7547ad749fc18 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:44 +0200 Subject: [PATCH 2050/2126] net: stmmac: qcom-ethqos: reuse the address of ethqos_emac_driver_data Instead of needlessly copying the fields of ethqos_emac_driver_data into struct qcom_ethqos, just use the address of the former as a reference. It's .rodata after all. This is done in order to avoid having either two calls to of_device_get_match_data() or having to extend the latter with another field when adding support for SCMI. Signed-off-by: Bartosz Golaszewski Reviewed-by: Mohd Ayaan Anwar Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-5-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../stmicro/stmmac/dwmac-qcom-ethqos.c | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index f7cc46d86591..f840ba4c02df 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -103,12 +103,7 @@ struct qcom_ethqos { struct clk *link_clk; struct phy *serdes_phy; phy_interface_t phy_mode; - - const struct ethqos_emac_por *rgmii_por; - unsigned int num_rgmii_por; - bool rgmii_config_loopback_en; - bool has_emac_ge_3; - bool needs_sgmii_loopback; + const struct ethqos_emac_driver_data *data; }; static u32 rgmii_readl(struct qcom_ethqos *ethqos, unsigned int offset) @@ -189,7 +184,7 @@ static int ethqos_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i, static void qcom_ethqos_set_sgmii_loopback(struct qcom_ethqos *ethqos, bool enable) { - if (!ethqos->needs_sgmii_loopback || + if (!ethqos->data->needs_sgmii_loopback || (ethqos->phy_mode != PHY_INTERFACE_MODE_2500BASEX && ethqos->phy_mode != PHY_INTERFACE_MODE_SGMII)) return; @@ -323,7 +318,7 @@ static int ethqos_dll_configure(struct qcom_ethqos *ethqos) /* Set DLL_EN */ rgmii_setmask(ethqos, SDCC_DLL_CONFIG_DLL_EN, SDCC_HC_REG_DLL_CONFIG); - if (!ethqos->has_emac_ge_3) { + if (!ethqos->data->has_emac_ge_3) { rgmii_clrmask(ethqos, SDCC_DLL_MCLK_GATING_EN, SDCC_HC_REG_DLL_CONFIG); @@ -353,7 +348,7 @@ static int ethqos_dll_configure(struct qcom_ethqos *ethqos) rgmii_setmask(ethqos, SDCC_DLL_CONFIG2_DDR_CAL_EN, SDCC_HC_REG_DLL_CONFIG2); - if (!ethqos->has_emac_ge_3) { + if (!ethqos->data->has_emac_ge_3) { rgmii_clrmask(ethqos, SDCC_DLL_CONFIG2_DLL_CLOCK_DIS, SDCC_HC_REG_DLL_CONFIG2); @@ -433,7 +428,7 @@ static int ethqos_rgmii_macro_init(struct qcom_ethqos *ethqos, int speed) rgmii_clrmask(ethqos, RGMII_CONFIG2_RSVD_CONFIG15, RGMII_IO_MACRO_CONFIG2); - if (speed == SPEED_1000 || ethqos->has_emac_ge_3) + if (speed == SPEED_1000 || ethqos->data->has_emac_ge_3) rgmii_setmask(ethqos, RGMII_CONFIG2_RX_PROG_SWAP, RGMII_IO_MACRO_CONFIG2); else @@ -457,7 +452,7 @@ static int ethqos_rgmii_macro_init(struct qcom_ethqos *ethqos, int speed) * in practice this becomes PRG_RCLK_DLY = 52 * 4 / * (2 * RX delay ns) */ - if (ethqos->has_emac_ge_3) { + if (ethqos->data->has_emac_ge_3) { /* 0.9 ns */ prg_rclk_dly = 115; } else { @@ -473,7 +468,7 @@ static int ethqos_rgmii_macro_init(struct qcom_ethqos *ethqos, int speed) SDCC_HC_REG_DDR_CONFIG); } - if (ethqos->rgmii_config_loopback_en) + if (ethqos->data->rgmii_config_loopback_en) loopback = RGMII_CONFIG_LOOPBACK_EN; else loopback = 0; @@ -496,9 +491,9 @@ static void ethqos_fix_mac_speed_rgmii(void *bsp_priv, dev = ðqos->pdev->dev; /* Reset to POR values and enable clk */ - for (i = 0; i < ethqos->num_rgmii_por; i++) - rgmii_writel(ethqos, ethqos->rgmii_por[i].value, - ethqos->rgmii_por[i].offset); + for (i = 0; i < ethqos->data->num_rgmii_por; i++) + rgmii_writel(ethqos, ethqos->data->rgmii_por[i].value, + ethqos->data->rgmii_por[i].offset); ethqos_set_func_clk_en(ethqos); @@ -512,7 +507,7 @@ static void ethqos_fix_mac_speed_rgmii(void *bsp_priv, rgmii_setmask(ethqos, SDCC_DLL_CONFIG_PDN, SDCC_HC_REG_DLL_CONFIG); - if (ethqos->has_emac_ge_3) { + if (ethqos->data->has_emac_ge_3) { if (speed == SPEED_1000) { rgmii_writel(ethqos, 0x1800000, SDCC_TEST_CTL); rgmii_writel(ethqos, 0x2C010800, SDCC_USR_CTL); @@ -539,7 +534,7 @@ static void ethqos_fix_mac_speed_rgmii(void *bsp_priv, SDCC_HC_REG_DLL_CONFIG); /* Set USR_CTL bit 26 with mask of 3 bits */ - if (!ethqos->has_emac_ge_3) + if (!ethqos->data->has_emac_ge_3) rgmii_updatel(ethqos, GENMASK(26, 24), BIT(26), SDCC_USR_CTL); @@ -753,11 +748,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev) "Failed to map rgmii resource\n"); data = of_device_get_match_data(dev); - ethqos->rgmii_por = data->rgmii_por; - ethqos->num_rgmii_por = data->num_rgmii_por; - ethqos->rgmii_config_loopback_en = data->rgmii_config_loopback_en; - ethqos->has_emac_ge_3 = data->has_emac_ge_3; - ethqos->needs_sgmii_loopback = data->needs_sgmii_loopback; + ethqos->data = data; ethqos->link_clk = devm_clk_get(dev, data->link_clk_name ?: "rgmii"); if (IS_ERR(ethqos->link_clk)) @@ -794,7 +785,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev) plat_dat->dump_debug_regs = rgmii_dump; plat_dat->ptp_clk_freq_config = ethqos_ptp_clk_freq_config; plat_dat->core_type = DWMAC_CORE_GMAC4; - if (ethqos->has_emac_ge_3) + if (data->has_emac_ge_3) plat_dat->dwmac4_addrs = &data->dwmac4_addrs; plat_dat->pmt = true; if (of_property_read_bool(np, "snps,tso")) From acf1e3db9151e142020f21d47fd28dce5ba05e03 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:45 +0200 Subject: [PATCH 2051/2126] net: stmmac: qcom-ethqos: factor out linux-level setup into a separate function Ahead of adding support for firmware-controlled EMAC variants, extend the ethqos_emac_driver_data structure with a setup() callback, implement it for the existing models and move all operations not required in SCMI mode into it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Mohd Ayaan Anwar Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-6-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../stmicro/stmmac/dwmac-qcom-ethqos.c | 94 ++++++++++++++----- 1 file changed, 68 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index f840ba4c02df..4e9c534fb240 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,8 @@ #define SGMII_10M_RX_CLK_DVDR 0x31 +struct qcom_ethqos; + struct ethqos_emac_por { unsigned int offset; unsigned int value; @@ -95,6 +98,8 @@ struct ethqos_emac_driver_data { const char *link_clk_name; struct dwmac4_addrs dwmac4_addrs; bool needs_sgmii_loopback; + int (*setup)(struct qcom_ethqos *ethqos, + struct plat_stmmacenet_data *plat_dat); }; struct qcom_ethqos { @@ -200,6 +205,9 @@ static void ethqos_set_func_clk_en(struct qcom_ethqos *ethqos) rgmii_setmask(ethqos, RGMII_CONFIG_FUNC_CLK_EN, RGMII_IO_MACRO_CONFIG); } +static int ethqos_hlos_setup(struct qcom_ethqos *ethqos, + struct plat_stmmacenet_data *plat_dat); + static const struct ethqos_emac_por emac_v2_3_0_por[] = { { .offset = RGMII_IO_MACRO_CONFIG, .value = 0x00C01343 }, { .offset = SDCC_HC_REG_DLL_CONFIG, .value = 0x2004642C }, @@ -214,6 +222,7 @@ static const struct ethqos_emac_driver_data emac_v2_3_0_data = { .num_rgmii_por = ARRAY_SIZE(emac_v2_3_0_por), .rgmii_config_loopback_en = true, .has_emac_ge_3 = false, + .setup = ethqos_hlos_setup, }; static const struct ethqos_emac_por emac_v2_1_0_por[] = { @@ -230,6 +239,7 @@ static const struct ethqos_emac_driver_data emac_v2_1_0_data = { .num_rgmii_por = ARRAY_SIZE(emac_v2_1_0_por), .rgmii_config_loopback_en = false, .has_emac_ge_3 = false, + .setup = ethqos_hlos_setup, }; static const struct ethqos_emac_por emac_v3_0_0_por[] = { @@ -262,6 +272,7 @@ static const struct ethqos_emac_driver_data emac_v3_0_0_data = { .mtl_low_cred = 0x00008024, .mtl_low_cred_offset = 0x1000, }, + .setup = ethqos_hlos_setup, }; static const struct ethqos_emac_por emac_v4_0_0_por[] = { @@ -297,6 +308,7 @@ static const struct ethqos_emac_driver_data emac_v4_0_0_data = { .mtl_low_cred = 0x00008024, .mtl_low_cred_offset = 0x1000, }, + .setup = ethqos_hlos_setup, }; static int ethqos_dll_configure(struct qcom_ethqos *ethqos) @@ -695,6 +707,58 @@ static void ethqos_ptp_clk_freq_config(struct stmmac_priv *priv) netdev_dbg(priv->dev, "PTP rate %lu\n", plat_dat->clk_ptp_rate); } +static int ethqos_hlos_setup(struct qcom_ethqos *ethqos, + struct plat_stmmacenet_data *plat_dat) +{ + struct platform_device *pdev = ethqos->pdev; + struct device *dev = &pdev->dev; + int ret; + + ethqos->rgmii_base = devm_platform_ioremap_resource_byname(pdev, "rgmii"); + if (IS_ERR(ethqos->rgmii_base)) + return dev_err_probe(dev, PTR_ERR(ethqos->rgmii_base), + "Failed to map rgmii resource\n"); + + ethqos->link_clk = devm_clk_get(dev, ethqos->data->link_clk_name ?: "rgmii"); + if (IS_ERR(ethqos->link_clk)) + return dev_err_probe(dev, PTR_ERR(ethqos->link_clk), + "Failed to get link_clk\n"); + + plat_dat->clks_config = ethqos_clks_config; + + ret = ethqos_clks_config(ethqos, true); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, ethqos_clks_disable, ethqos); + if (ret) + return ret; + + ethqos_set_clk_tx_rate(ethqos, NULL, plat_dat->phy_interface, SPEED_1000); + qcom_ethqos_set_sgmii_loopback(ethqos, true); + ethqos_set_func_clk_en(ethqos); + + switch (ethqos->phy_mode) { + case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_RGMII_ID: + case PHY_INTERFACE_MODE_RGMII_RXID: + case PHY_INTERFACE_MODE_RGMII_TXID: + plat_dat->fix_mac_speed = ethqos_fix_mac_speed_rgmii; + break; + case PHY_INTERFACE_MODE_2500BASEX: + case PHY_INTERFACE_MODE_SGMII: + plat_dat->fix_mac_speed = ethqos_fix_mac_speed_sgmii; + break; + default: + break; + } + + plat_dat->set_clk_tx_rate = ethqos_set_clk_tx_rate; + plat_dat->dump_debug_regs = rgmii_dump; + + return 0; +} + static int qcom_ethqos_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -716,23 +780,20 @@ static int qcom_ethqos_probe(struct platform_device *pdev) "dt configuration failed\n"); } - plat_dat->clks_config = ethqos_clks_config; - ethqos = devm_kzalloc(dev, sizeof(*ethqos), GFP_KERNEL); if (!ethqos) return -ENOMEM; ethqos->phy_mode = plat_dat->phy_interface; + switch (ethqos->phy_mode) { case PHY_INTERFACE_MODE_RGMII: case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_RXID: case PHY_INTERFACE_MODE_RGMII_TXID: - plat_dat->fix_mac_speed = ethqos_fix_mac_speed_rgmii; break; case PHY_INTERFACE_MODE_2500BASEX: case PHY_INTERFACE_MODE_SGMII: - plat_dat->fix_mac_speed = ethqos_fix_mac_speed_sgmii; plat_dat->mac_finish = ethqos_mac_finish_serdes; break; default: @@ -742,24 +803,13 @@ static int qcom_ethqos_probe(struct platform_device *pdev) } ethqos->pdev = pdev; - ethqos->rgmii_base = devm_platform_ioremap_resource_byname(pdev, "rgmii"); - if (IS_ERR(ethqos->rgmii_base)) - return dev_err_probe(dev, PTR_ERR(ethqos->rgmii_base), - "Failed to map rgmii resource\n"); - data = of_device_get_match_data(dev); ethqos->data = data; - ethqos->link_clk = devm_clk_get(dev, data->link_clk_name ?: "rgmii"); - if (IS_ERR(ethqos->link_clk)) - return dev_err_probe(dev, PTR_ERR(ethqos->link_clk), - "Failed to get link_clk\n"); + if (WARN_ON(!data->setup)) + return -EINVAL; - ret = ethqos_clks_config(ethqos, true); - if (ret) - return ret; - - ret = devm_add_action_or_reset(dev, ethqos_clks_disable, ethqos); + ret = data->setup(ethqos, plat_dat); if (ret) return ret; @@ -768,12 +818,6 @@ static int qcom_ethqos_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(ethqos->serdes_phy), "Failed to get serdes phy\n"); - ethqos_set_clk_tx_rate(ethqos, NULL, plat_dat->phy_interface, - SPEED_1000); - - qcom_ethqos_set_sgmii_loopback(ethqos, true); - ethqos_set_func_clk_en(ethqos); - /* The clocks are controlled by firmware, so we don't know for certain * what clock rate is being used. Hardware documentation mentions that * the AHB slave clock will be in the range of 50 to 100MHz, which @@ -781,8 +825,6 @@ static int qcom_ethqos_probe(struct platform_device *pdev) */ plat_dat->clk_csr = STMMAC_CSR_60_100M; plat_dat->bsp_priv = ethqos; - plat_dat->set_clk_tx_rate = ethqos_set_clk_tx_rate; - plat_dat->dump_debug_regs = rgmii_dump; plat_dat->ptp_clk_freq_config = ethqos_ptp_clk_freq_config; plat_dat->core_type = DWMAC_CORE_GMAC4; if (data->has_emac_ge_3) From bb3183e1c938758ca32793e55fe4985f9745246c Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Oct 2026 14:36:46 +0200 Subject: [PATCH 2052/2126] net: stmmac: qcom-ethqos: add support for sa8255p Extend the driver to support a new model - sa8255p. Unlike the previously supported variants, this one's power management is done in the firmware over SCMI. This is modeled in linux using power domains so add a new emac data variant and a separate setup callback. Signed-off-by: Bartosz Golaszewski Link: https://patch.msgid.link/20261014-qcom-sa8255p-emac-v16-7-0266c2ead980@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- .../stmicro/stmmac/dwmac-qcom-ethqos.c | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index 4e9c534fb240..d59be76a2091 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -98,6 +98,11 @@ struct ethqos_emac_driver_data { const char *link_clk_name; struct dwmac4_addrs dwmac4_addrs; bool needs_sgmii_loopback; + /* Fixed PTP reference clock rate, used on SCMI platforms where + * firmware does not implement the clock protocol allowing linux to + * query it. + */ + unsigned long ptp_clk_rate; int (*setup)(struct qcom_ethqos *ethqos, struct plat_stmmacenet_data *plat_dat); }; @@ -108,6 +113,7 @@ struct qcom_ethqos { struct clk *link_clk; struct phy *serdes_phy; phy_interface_t phy_mode; + struct dev_pm_domain_list *pds; const struct ethqos_emac_driver_data *data; }; @@ -207,6 +213,8 @@ static void ethqos_set_func_clk_en(struct qcom_ethqos *ethqos) static int ethqos_hlos_setup(struct qcom_ethqos *ethqos, struct plat_stmmacenet_data *plat_dat); +static int ethqos_scmi_setup(struct qcom_ethqos *ethqos, + struct plat_stmmacenet_data *plat_dat); static const struct ethqos_emac_por emac_v2_3_0_por[] = { { .offset = RGMII_IO_MACRO_CONFIG, .value = 0x00C01343 }, @@ -311,6 +319,30 @@ static const struct ethqos_emac_driver_data emac_v4_0_0_data = { .setup = ethqos_hlos_setup, }; +static const struct ethqos_emac_driver_data emac_v4_0_0_scmi_data = { + .has_emac_ge_3 = true, + .needs_sgmii_loopback = true, + .dma_addr_width = 36, + .ptp_clk_rate = 230400000, + .dwmac4_addrs = { + .dma_chan = 0x00008100, + .dma_chan_offset = 0x1000, + .mtl_chan = 0x00008000, + .mtl_chan_offset = 0x1000, + .mtl_ets_ctrl = 0x00008010, + .mtl_ets_ctrl_offset = 0x1000, + .mtl_txq_weight = 0x00008018, + .mtl_txq_weight_offset = 0x1000, + .mtl_send_slp_cred = 0x0000801c, + .mtl_send_slp_cred_offset = 0x1000, + .mtl_high_cred = 0x00008020, + .mtl_high_cred_offset = 0x1000, + .mtl_low_cred = 0x00008024, + .mtl_low_cred_offset = 0x1000, + }, + .setup = ethqos_scmi_setup, +}; + static int ethqos_dll_configure(struct qcom_ethqos *ethqos) { struct device *dev = ðqos->pdev->dev; @@ -759,6 +791,84 @@ static int ethqos_hlos_setup(struct qcom_ethqos *ethqos, return 0; } +static const char *const ethqos_scmi_pd_names[] = { "core", "mdio" }; + +static int ethqos_scmi_setup(struct qcom_ethqos *ethqos, + struct plat_stmmacenet_data *plat_dat) +{ + const struct dev_pm_domain_attach_data pd_data = { + .pd_names = ethqos_scmi_pd_names, + .num_pd_names = ARRAY_SIZE(ethqos_scmi_pd_names), + .pd_flags = PD_FLAG_DEV_LINK_ON, + }; + + struct platform_device *pdev = ethqos->pdev; + struct device *dev = &pdev->dev; + int ret; + + ret = devm_pm_domain_attach_list(dev, &pd_data, ðqos->pds); + if (ret < 0) + return dev_err_probe(dev, ret, + "Failed to attach power domains\n"); + + /* + * The MAC AXI/AHB clocks are owned by firmware and brought up through + * the "core" and "mdio" SCMI power domains above, while the SerDes + * lane is powered by the SerDes PHY's own power domain from + * serdes_powerup() in stmmac_open(). The MAC wrapper itself, however + * is in the kernel's register space: the wrapper bit that loops the + * PHY TX clock into the MAC's clk_rx_i - needed because no recovered + * RX clock exists yet - is not configured by firmware. Without it, + * clk_rx_i never toggles and the DMA SW-reset polled in + * dwmac4_dma_reset() never completes. + * + * Map the wrapper and program the same loopback/functional clock bits + * the non-firmware platforms rely on (see ethqos_clks_config) so the + * RX clock is present by the time the DMA engine is reset. + */ + ethqos->rgmii_base = devm_platform_ioremap_resource_byname(pdev, "rgmii"); + if (IS_ERR(ethqos->rgmii_base)) + return dev_err_probe(dev, PTR_ERR(ethqos->rgmii_base), + "Failed to map rgmii resource\n"); + + /* + * Register clks_config to run on every subsequent runtime resume, + * which stmmac performs after the power domains are on but before + * serdes_powerup() and the DMA reset. This alone isn't enough for + * the very first reset done from stmmac_open(), though: probe() + * fakes the device into RPM_ACTIVE without invoking the resume + * callback, so whether clks_config() has run by then depends on + * whether the device has already gone through one real suspend/resume + * cycle in the meantime. Call it here explicitly so the wrapper is + * always configured before the first DMA reset regardless of that + * timing. + */ + plat_dat->clks_config = ethqos_clks_config; + + ret = ethqos_clks_config(ethqos, true); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, ethqos_clks_disable, ethqos); + if (ret) + return ret; + + plat_dat->clk_ptp_rate = ethqos->data->ptp_clk_rate; + + switch (ethqos->phy_mode) { + case PHY_INTERFACE_MODE_2500BASEX: + case PHY_INTERFACE_MODE_SGMII: + plat_dat->fix_mac_speed = ethqos_fix_mac_speed_sgmii; + break; + default: + /* The firmware-managed SerDes only supports SGMII modes. */ + return dev_err_probe(dev, -EINVAL, "Unsupported phy-mode: %s\n", + phy_modes(ethqos->phy_mode)); + } + + return 0; +} + static int qcom_ethqos_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -851,6 +961,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev) static const struct of_device_id qcom_ethqos_match[] = { { .compatible = "qcom,qcs404-ethqos", .data = &emac_v2_3_0_data}, + { .compatible = "qcom,sa8255p-ethqos", .data = &emac_v4_0_0_scmi_data}, { .compatible = "qcom,sa8775p-ethqos", .data = &emac_v4_0_0_data}, { .compatible = "qcom,sc8280xp-ethqos", .data = &emac_v3_0_0_data}, { .compatible = "qcom,sm8150-ethqos", .data = &emac_v2_1_0_data}, From eeb63e1e0bfc6203086dd496247e905b84704343 Mon Sep 17 00:00:00 2001 From: Victor Nogueira Date: Thu, 15 Oct 2026 16:15:24 -0300 Subject: [PATCH 2053/2126] selftests: tc-testing: keep IPv6 autoconf out of exact-counter checks Several tc-testing cases assert an exact bytes/packets value from a single injected frame, but count every frame that traverses an egress qdisc (or match with "protocol all"). Every case creates a fresh veth pair (and, for the gso_skb cases, a netdevsim device) and brings it up with IPv6 enabled; a device whose link-local autoconfiguration runs then emits neighbour solicitations, MLD reports and router solicitations for a few seconds. Those are ordinary Ethernet frames (0x86DD) and are counted too, so the exact assertions race with the autoconf burst and fail intermittently. The $DEV0 peer of the veth pair lives in the init netns, so its frames follow the init-netns IPv6 sysctls. Conditions to recreate the bug: Run the affected cases with IPv6 enabled (the tdc default) on net-next (7.3.0-rc6+). 4e6b fails intermittently (4/6 here); the four netdevsim "gso_skb" cases fail intermittently too (fb6c 1/25, 0235 4/15, 476f 4/8). 1922 did not trip in the sampled runs but shares the same setup and is fixed for uniformity. Each failure carries a stray autoconf frame, e.g. "bytes: 98 != 188". The Fix: Fix the affected cases: - actions/ife.json 4e6b injects only an 0xED3E frame but matches with "protocol all"; scope the filter to that ethertype. - The four netdevsim "gso_skb" cases (fb6c, 1922, 476f, 0235) create $ETH from within the case and bring it up immediately before installing the qdiscs, so the autoconf burst overlaps the measurement. Set "addrgenmode none" before the link is brought up, so the device generates no link-local address and the counter holds only the injected packet. IPv6 stays usable (a manually added address still works), so cases that exercise IPv6 are unaffected. On a kernel without IPv6 (CONFIG_IPV6=n, or booted with ipv6.disable=1) the attribute is not available, so the line is made non-fatal like every neighbouring setup line. With this change the affected cases pass 20/20, and the whole ife.json (51/51) and infra/qdiscs.json (48/48) suites pass, as do the protocol-ipv6 matchall cases (filters/matchall.json 0596, 41df, 8bd2, 2a4a). Reviewed-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Link: https://patch.msgid.link/QDISC-L9J8.v1.r0.20261014162217-1@mojatatu.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/tc-testing/tc-tests/actions/ife.json | 2 +- tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json b/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json index ece7ec41bf99..135e9fdc6e02 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json +++ b/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json @@ -1408,7 +1408,7 @@ "packet": "Ether(type=0xED3E) / Raw(b'\\x00\\x02\\xaa')" } ], - "cmdUnderTest": "$TC filter add dev $DEV1 ingress protocol all matchall action ife decode pipe index 10", + "cmdUnderTest": "$TC filter add dev $DEV1 ingress protocol 0xED3E matchall action ife decode pipe index 10", "expExitCode": "0", "verifyCmd": "$TC -s -j actions get action ife index 10", "matchJSON": [ diff --git a/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json b/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json index 0cf12c50fb74..556a1dda1047 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json +++ b/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json @@ -1555,6 +1555,7 @@ }, "setup": [ "echo \"1 1 4\" > /sys/bus/netdevsim/new_device", + "$IP link set dev $ETH addrgenmode none || true", "$IP link set dev $ETH up || true", "$IP l set addr 01:02:03:04:05:06 dev $ETH || true", "$IP n add dev $ETH 10.10.11.1 lladdr 01:02:03:04:05:06 dev $ETH || true", @@ -1598,6 +1599,7 @@ }, "setup": [ "echo \"1 1 4\" > /sys/bus/netdevsim/new_device", + "$IP link set dev $ETH addrgenmode none || true", "$IP link set dev $ETH up || true", "$IP l set addr 01:02:03:04:05:06 dev $ETH || true", "$IP n add dev $ETH 10.10.11.1 lladdr 01:02:03:04:05:06 dev $ETH || true", @@ -1640,6 +1642,7 @@ }, "setup": [ "echo \"1 1 4\" > /sys/bus/netdevsim/new_device", + "$IP link set dev $ETH addrgenmode none || true", "$IP link set dev $ETH up || true", "$IP l set addr 01:02:03:04:05:06 dev $ETH || true", "$IP n add dev $ETH 10.10.11.1 lladdr 01:02:03:04:05:06 dev $ETH || true", @@ -1680,6 +1683,7 @@ }, "setup": [ "echo \"1 1 4\" > /sys/bus/netdevsim/new_device", + "$IP link set dev $ETH addrgenmode none || true", "$IP link set dev $ETH up || true", "$IP l set addr 01:02:03:04:05:06 dev $ETH || true", "$IP n add dev $ETH 10.10.11.1 lladdr 01:02:03:04:05:06 dev $ETH || true", From 82e31923c0553fdbfcddcd910ca07952880ca9b9 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 19 Oct 2026 11:22:14 +0300 Subject: [PATCH 2054/2126] tcp_bpf: propagate error code in tcp_bpf_sendmsg() In tcp_bpf_sendmsg(), the value returned by sk_msg_memcopy_from_iter() is checked for error but not propagated to 'out_err' label, so error handling may not work as expected. Fix this by assigning error value to 'err', thus making sure that error won't be silently ignored. Reported-by: Sashiko Fixes: 5153a75ef34b ("tcp_bpf: Fix copied value in tcp_bpf_sendmsg") Signed-off-by: Dmitry Antipov Reviewed-by: Kuniyuki Iwashima Reviewed-by: Jason Xing Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261019082214.102398-1-dmantipov@yandex.ru Signed-off-by: Jakub Kicinski --- net/ipv4/tcp_bpf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 2e234d155b5e..0ce583f68d3b 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -581,6 +581,7 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) copy); if (ret < 0) { sk_msg_trim(sk, msg_tx, osize); + err = ret; goto out_err; } From 457dc9fefe9aed6505502d20930d9dec4b10eabc Mon Sep 17 00:00:00 2001 From: Demos Ra Date: Mon, 19 Oct 2026 13:35:51 +0700 Subject: [PATCH 2055/2126] netlink: specs: Add a spec for nexthops in rtnetlink Add a YNL spec for nexthop objects and nexthop buckets in rtnetlink. ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/rt-nexthop.yaml \ --dump getnexthop Exclude newnexthopbucket-ntf from the C code generation. ynl_gen_c.py looks up a classic notification by the request of the same message type, and no request uses RTM_NEWNEXTHOPBUCKET. The spec keeps the notification, so the Python tools can still subscribe to it. Signed-off-by: Demos Ra Link: https://patch.msgid.link/20261019-rt-nexthop-spec-v1-1-9c586edf86ab@gmail.com Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/rt-nexthop.yaml | 761 ++++++++++++++++++++ MAINTAINERS | 1 + tools/net/ynl/Makefile.deps | 9 + tools/net/ynl/generated/Makefile | 1 + 4 files changed, 772 insertions(+) create mode 100644 Documentation/netlink/specs/rt-nexthop.yaml diff --git a/Documentation/netlink/specs/rt-nexthop.yaml b/Documentation/netlink/specs/rt-nexthop.yaml new file mode 100644 index 000000000000..06c28fa7d2fb --- /dev/null +++ b/Documentation/netlink/specs/rt-nexthop.yaml @@ -0,0 +1,761 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +--- +name: rt-nexthop +protocol: netlink-raw +uapi-header: linux/nexthop.h +protonum: 0 + +doc: >- + Nexthop object management over rtnetlink. + +definitions: + - + name: nhmsg + type: struct + members: + - + name: nh-family + type: u8 + - + name: nh-scope + type: u8 + - + name: nh-protocol + type: u8 + - + name: resvd + type: pad + len: 1 + - + name: nh-flags + type: u32 + enum: rtnh-f + - + name: rtnh-f + type: flags + name-prefix: rtnh-f- + enum-name: + entries: + - dead + - pervasive + - onlink + - offload + - linkdown + - unresolved + - trap + - + name: nexthop-grp + type: struct + members: + - + name: id + type: u32 + - + name: weight + type: u8 + - + name: weight-high + type: u8 + - + name: resvd2 + type: pad + len: 2 + - + name: nexthop-grp-type + type: enum + name-prefix: nexthop-grp-type- + enum-name: + entries: + - mpath + - res + - + name: encap-type + type: enum + name-prefix: lwtunnel-encap- + enum-name: + entries: + - none + - mpls + - ip + - ila + - ip6 + - seg6 + - bpf + - seg6-local + - rpl + - ioam6 + - xfrm + - + name: seg6-local-actions + type: enum + name-prefix: seg6-local-action- + enum-name: + entries: + - unspec + - end + - end-x + - end-t + - end-dx2 + - end-dx6 + - end-dx4 + - end-dt6 + - end-dt4 + - end-b6 + - end-b6-encap + - end-bm + - end-s + - end-as + - end-am + - end-bpf + - end-dt46 + - + name: seg6-local-flv-ops + type: enum + name-prefix: seg6-local-flv-op- + enum-name: + entries: + - + name: unspec + - + name: psp + - + name: usp + - + name: usd + - + name: next-csid + - + name: nha-op-flag + type: flags + name-prefix: nha-op-flag- + enum-name: + entries: + - dump-stats + - dump-hw-stats + - + name: nha-op-flag-resp-grp-resvd-0 + type: const + value: 2147483648 + +sub-messages: + - + name: encap-data + formats: + - + value: mpls + attribute-set: mpls-iptunnel + - + value: ip + attribute-set: lwtunnel-ip + - + value: ila + attribute-set: ila-attrs + - + value: ip6 + attribute-set: lwtunnel-ip6 + - + value: seg6 + attribute-set: seg6-iptunnel + - + value: bpf + attribute-set: lwt-bpf + - + value: seg6-local + attribute-set: seg6-local + - + value: rpl + attribute-set: rpl-iptunnel + - + value: ioam6 + attribute-set: ioam6-iptunnel + - + value: xfrm + attribute-set: lwt-xfrm + +attribute-sets: + - + name: nexthop-attrs + name-prefix: nha- + attributes: + - + name: id + type: u32 + - + name: group + type: binary # array of struct: nexthop-grp + - + name: group-type + type: u16 + enum: nexthop-grp-type + - + name: blackhole + type: flag + - + name: oif + type: u32 + - + name: gateway + type: binary + display-hint: ipv4-or-v6 + - + name: encap-type + type: u16 + enum: encap-type + - + name: encap + type: sub-message + sub-message: encap-data + selector: encap-type + - + name: groups + type: flag + - + name: master + type: u32 + - + name: fdb + type: flag + - + name: res-group + type: nest + nested-attributes: res-group-attrs + - + name: res-bucket + type: nest + nested-attributes: res-bucket-attrs + - + name: op-flags + type: u32 + checks: + flags-mask: nha-op-flag + - + name: group-stats + type: nest + nested-attributes: group-stats-attrs + - + name: hw-stats-enable + type: u32 + checks: + max: 1 + - + name: hw-stats-used + type: u32 + - + name: dst-port + type: u16 + byte-order: big-endian + checks: + min: 1 + - + name: mpls-iptunnel + name-prefix: mpls-iptunnel- + header: linux/mpls_iptunnel.h + attributes: + - + name: dst + type: binary + - + name: ttl + type: u8 + - + name: lwtunnel-ip + name-prefix: lwtunnel-ip- + header: linux/lwtunnel.h + attributes: + - + name: id + type: u64 + byte-order: big-endian + - + name: dst + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: src + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: ttl + type: u8 + - + name: tos + type: u8 + - + name: flags + type: u16 + byte-order: big-endian + - + name: pad + type: pad + - + name: opts + type: nest + nested-attributes: lwtunnel-ip-opts + - + name: ila-attrs + name-prefix: ila-attr- + header: linux/ila.h + attributes: + - + name: locator + type: u64 + byte-order: big-endian + - + name: identifier + type: u64 + - + name: locator-match + type: u64 + byte-order: big-endian + - + name: ifindex + type: s32 + - + name: dir + type: u32 + - + name: pad + type: pad + - + name: csum-mode + type: u8 + - + name: ident-type + type: u8 + - + name: hook-type + type: u8 + - + name: lwtunnel-ip6 + name-prefix: lwtunnel-ip6- + header: linux/lwtunnel.h + attributes: + - + name: id + type: u64 + byte-order: big-endian + - + name: dst + type: binary + display-hint: ipv6 + - + name: src + type: binary + display-hint: ipv6 + - + name: hoplimit + type: u8 + - + name: tc + type: u8 + - + name: flags + type: u16 + byte-order: big-endian + - + name: pad + type: pad + - + name: opts + type: nest + nested-attributes: lwtunnel-ip-opts + - + name: seg6-iptunnel + name-prefix: seg6-iptunnel- + header: linux/seg6_iptunnel.h + attributes: + - + name: srh + type: binary + - + name: src + type: binary + display-hint: ipv6 + - + name: table + type: u32 + - + name: lwt-bpf + name-prefix: lwt-bpf- + header: linux/lwtunnel.h + attributes: + - + name: in + type: nest + nested-attributes: lwt-bpf-prog + - + name: out + type: nest + nested-attributes: lwt-bpf-prog + - + name: xmit + type: nest + nested-attributes: lwt-bpf-prog + - + name: xmit-headroom + type: u32 + - + name: seg6-local + name-prefix: seg6-local- + header: linux/seg6_local.h + attributes: + - + name: action + type: u32 + enum: seg6-local-actions + - + name: srh + type: binary + - + name: table + type: u32 + - + name: nh4 + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: nh6 + type: binary + display-hint: ipv6 + - + name: iif + type: u32 + - + name: oif + type: u32 + - + name: bpf + type: nest + nested-attributes: seg6-local-bpf + - + name: vrftable + type: u32 + - + name: counters + type: nest + nested-attributes: seg6-local-cnt + - + name: flavors + type: nest + nested-attributes: seg6-local-flv + - + name: rpl-iptunnel + name-prefix: rpl-iptunnel- + header: linux/rpl_iptunnel.h + attributes: + - + name: srh + type: binary + - + name: ioam6-iptunnel + name-prefix: ioam6-iptunnel- + header: linux/ioam6_iptunnel.h + attributes: + - + name: mode + type: u8 + - + name: dst + type: binary + display-hint: ipv6 + - + name: trace + type: binary + - + name: freq-k + type: u32 + - + name: freq-n + type: u32 + - + name: src + type: binary + display-hint: ipv6 + - + name: lwt-xfrm + name-prefix: lwt-xfrm- + header: linux/lwtunnel.h + attributes: + - + name: if-id + type: u32 + - + name: link + type: u32 + - + name: lwtunnel-ip-opts + name-prefix: lwtunnel-ip-opts- + attributes: + - + name: geneve + type: binary + - + name: vxlan + type: nest + nested-attributes: lwtunnel-ip-opt-vxlan + - + name: erspan + type: nest + nested-attributes: lwtunnel-ip-opt-erspan + - + name: lwtunnel-ip-opt-vxlan + name-prefix: lwtunnel-ip-opt-vxlan- + attributes: + - + name: gbp + type: u32 + - + name: lwtunnel-ip-opt-erspan + name-prefix: lwtunnel-ip-opt-erspan- + attributes: + - + name: ver + type: u8 + - + name: index + type: u32 + byte-order: big-endian + - + name: dir + type: u8 + - + name: hwid + type: u8 + - + name: lwt-bpf-prog + name-prefix: lwt-bpf-prog- + attributes: + - + name: fd + type: u32 + - + name: name + type: string + checks: + max-len: 256 + - + name: seg6-local-bpf + name-prefix: seg6-local-bpf- + attr-max-name: seg6-local-bpf-prog-max + attributes: + - + name: prog + type: u32 + - + name: prog-name + type: string + checks: + max-len: 256 + - + name: seg6-local-cnt + name-prefix: seg6-local-cnt- + attributes: + - + name: pad + type: pad + - + name: packets + type: u64 + - + name: bytes + type: u64 + - + name: errors + type: u64 + - + name: seg6-local-flv + name-prefix: seg6-local-flv- + attributes: + - + name: operation + type: u32 + enum: seg6-local-flv-ops + enum-as-flags: true + - + name: lcblock-bits + type: u8 + - + name: lcnode-fn-bits + type: u8 + - + name: res-group-attrs + name-prefix: nha-res-group- + attributes: + - + name: pad + type: pad + value: 0 + - + name: buckets + type: u16 + - + name: idle-timer + type: u32 + - + name: unbalanced-timer + type: u32 + - + name: unbalanced-time + type: u64 + - + name: res-bucket-attrs + name-prefix: nha-res-bucket- + attributes: + - + name: pad + type: pad + value: 0 + - + name: index + type: u16 + - + name: idle-time + type: u64 + - + name: nh-id + type: u32 + - + name: group-stats-attrs + name-prefix: nha-group-stats- + attributes: + - + name: entry + type: nest + nested-attributes: group-stats-entry-attrs + multi-attr: true + - + name: group-stats-entry-attrs + name-prefix: nha-group-stats-entry- + attributes: + - + name: id + type: u32 + - + name: packets + type: uint + - + name: packets-hw + type: uint + +operations: + enum-model: directional + fixed-header: nhmsg + name-prefix: rtm- + list: + - + name: newnexthop + doc: Add new nexthop entry + attribute-set: nexthop-attrs + do: + request: + value: 104 + attributes: + - id + - group + - group-type + - blackhole + - oif + - gateway + - encap-type + - encap + - fdb + - res-group + - hw-stats-enable + - dst-port + - + name: delnexthop + doc: Delete nexthop with given id. + attribute-set: nexthop-attrs + do: + request: + value: 105 + attributes: + - id + - + name: getnexthop + doc: Get or dump nexthop entries + attribute-set: nexthop-attrs + do: + request: + value: 106 + attributes: + - id + - op-flags + reply: + value: 104 + attributes: &nexthop-all-attrs + - id + - group + - group-type + - blackhole + - oif + - gateway + - encap-type + - encap + - fdb + - res-group + - op-flags + - group-stats + - hw-stats-enable + - hw-stats-used + - dst-port + dump: + request: + value: 106 + attributes: + - oif + - groups + - master + - fdb + - op-flags + reply: + value: 104 + attributes: *nexthop-all-attrs + - + name: newnexthop-ntf + doc: Notification about a created nexthop. + value: 104 + notify: getnexthop + - + name: delnexthop-ntf + doc: Notification about a deleted nexthop. + value: 105 + notify: getnexthop + - + name: getnexthopbucket + doc: Get or dump nexthop buckets + attribute-set: nexthop-attrs + do: + request: + value: 118 + attributes: &nexthop-bucket-all-attrs + - id + - res-bucket + reply: + value: 116 + attributes: *nexthop-bucket-all-attrs + dump: + request: + value: 118 + attributes: + - id + - oif + - master + - res-bucket + reply: + value: 116 + attributes: *nexthop-bucket-all-attrs + - + name: newnexthopbucket-ntf + doc: Notification about a created nexthop bucket. + value: 116 + notify: getnexthopbucket + +mcast-groups: + list: + - + name: rtnlgrp-nexthop + value: 32 diff --git a/MAINTAINERS b/MAINTAINERS index 409b031d354d..2b07bf0fd980 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19144,6 +19144,7 @@ L: netdev@vger.kernel.org S: Maintained F: Documentation/netlink/specs/rt-addr.yaml F: Documentation/netlink/specs/rt-neigh.yaml +F: Documentation/netlink/specs/rt-nexthop.yaml F: Documentation/netlink/specs/rt-route.yaml F: Documentation/netlink/specs/rt-rule.yaml F: include/linux/inetdevice.h diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps index 3eee34e0efcf..9389f3752c00 100644 --- a/tools/net/ynl/Makefile.deps +++ b/tools/net/ynl/Makefile.deps @@ -45,6 +45,15 @@ CFLAGS_rt-link:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ $(call get_hdr_inc,_LINUX_IF_LINK_H,if_link.h) CFLAGS_rt-neigh:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ $(call get_hdr_inc,__LINUX_NEIGHBOUR_H,neighbour.h) +CFLAGS_rt-nexthop:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \ + $(call get_hdr_inc,_LINUX_NEXTHOP_H,nexthop.h) \ + $(call get_hdr_inc,_LINUX_ILA_H,ila.h) \ + $(call get_hdr_inc,_LINUX_IOAM6_IPTUNNEL_H,ioam6_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_MPLS_IPTUNNEL_H,mpls_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_RPL_IPTUNNEL_H,rpl_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_SEG6_IPTUNNEL_H,seg6_iptunnel.h) \ + $(call get_hdr_inc,_LINUX_SEG6_LOCAL_H,seg6_local.h) \ + $(call get_hdr_inc,_LWTUNNEL_H_,lwtunnel.h) CFLAGS_rt-route:=$(call get_hdr_inc,_LINUX_ILA_H,ila.h) \ $(call get_hdr_inc,_LINUX_IOAM6_IPTUNNEL_H,ioam6_iptunnel.h) \ $(call get_hdr_inc,_LINUX_MPLS_IPTUNNEL_H,mpls_iptunnel.h) \ diff --git a/tools/net/ynl/generated/Makefile b/tools/net/ynl/generated/Makefile index 5a186349b5a8..d76d4ca94629 100644 --- a/tools/net/ynl/generated/Makefile +++ b/tools/net/ynl/generated/Makefile @@ -18,6 +18,7 @@ include ../Makefile.deps YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \ --exclude-op stats-get +YNL_GEN_ARG_rt-nexthop:=--exclude-op newnexthopbucket-ntf TOOL:=../pyynl/ynl_gen_c.py TOOL_RST:=../pyynl/ynl_gen_rst.py From 9e6df8d57ee551b000518d1d58c65aa4163c3bc2 Mon Sep 17 00:00:00 2001 From: Sander Vanheule Date: Sun, 18 Oct 2026 18:12:47 +0200 Subject: [PATCH 2056/2126] dt-bindings: net: pse-pd: realtek,pse: add gen1 I2C transport Like the gen2 protocol, the gen1 protocol can also be used over both a raw I2C transport and an SMBUs transport. Add a compatible for the former and the compatible for the Ubiquiti Unifi Switch Lite 16 PoE device that uses it. Signed-off-by: Sander Vanheule Reviewed-by: Kory Maincent Acked-by: Krzysztof Kozlowski Reviewed-by: Rob Herring (Arm) Link: https://patch.msgid.link/20261018161248.376205-2-sander@svanheule.net Signed-off-by: Jakub Kicinski --- .../bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml b/Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml index 3bb32349c28c..526f8525bb4d 100644 --- a/Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml +++ b/Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml @@ -54,6 +54,12 @@ properties: - zyxel,gs1920-24hp-v2-pse - const: realtek,pse-mcu-gen1-smbus + # I2C, raw framing + - items: + - enum: + - ubnt,usw-lite-16-poe-pse + - const: realtek,pse-mcu-gen1-i2c + # UART - items: - enum: @@ -100,6 +106,7 @@ allOf: contains: enum: - realtek,pse-mcu-gen1-smbus + - realtek,pse-mcu-gen1-i2c - realtek,pse-mcu-gen2-smbus - realtek,pse-mcu-gen2-i2c then: From ca4bd46de863970281657004c4c536e05cc6b239 Mon Sep 17 00:00:00 2001 From: Sander Vanheule Date: Sun, 18 Oct 2026 18:12:48 +0200 Subject: [PATCH 2057/2126] net: pse-pd: realtek-pse-mcu: add gen1 I2C transport Provide the required data for the gen1 raw I2C binding, which like for gen2 is simply the gen1 protocol data with the native_i2c flag set. Signed-off-by: Sander Vanheule Reviewed-by: Kory Maincent Acked-by: Oleksij Rempel Acked-by: Jonas Jelonek Link: https://patch.msgid.link/20261018161248.376205-3-sander@svanheule.net Signed-off-by: Jakub Kicinski --- drivers/net/pse-pd/realtek-pse-mcu-core.c | 8 +++++++- drivers/net/pse-pd/realtek-pse-mcu-i2c.c | 1 + drivers/net/pse-pd/realtek-pse-mcu.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/pse-pd/realtek-pse-mcu-core.c b/drivers/net/pse-pd/realtek-pse-mcu-core.c index e64f13ea6e4e..c70b09ca2012 100644 --- a/drivers/net/pse-pd/realtek-pse-mcu-core.c +++ b/drivers/net/pse-pd/realtek-pse-mcu-core.c @@ -986,7 +986,13 @@ const struct rtpse_mcu_match_data rtpse_mcu_gen2_data = { }; EXPORT_SYMBOL_GPL(rtpse_mcu_gen2_data); -/* Same dialect as gen2, but the MCU expects raw-I2C framing. */ +/* Same dialects as above, but the MCU expects raw-I2C framing. */ +const struct rtpse_mcu_match_data rtpse_mcu_gen1_i2c_data = { + .dialect = &rtpse_mcu_dialect_gen1, + .native_i2c = true, +}; +EXPORT_SYMBOL_GPL(rtpse_mcu_gen1_i2c_data); + const struct rtpse_mcu_match_data rtpse_mcu_gen2_i2c_data = { .dialect = &rtpse_mcu_dialect_gen2, .native_i2c = true, diff --git a/drivers/net/pse-pd/realtek-pse-mcu-i2c.c b/drivers/net/pse-pd/realtek-pse-mcu-i2c.c index b6769ac1d470..bbded772eddf 100644 --- a/drivers/net/pse-pd/realtek-pse-mcu-i2c.c +++ b/drivers/net/pse-pd/realtek-pse-mcu-i2c.c @@ -128,6 +128,7 @@ static int rtpse_mcu_i2c_probe(struct i2c_client *client) static const struct of_device_id rtpse_mcu_i2c_of_match[] = { { .compatible = "realtek,pse-mcu-gen1-smbus", .data = &rtpse_mcu_gen1_data }, + { .compatible = "realtek,pse-mcu-gen1-i2c", .data = &rtpse_mcu_gen1_i2c_data }, { .compatible = "realtek,pse-mcu-gen2-smbus", .data = &rtpse_mcu_gen2_data }, { .compatible = "realtek,pse-mcu-gen2-i2c", .data = &rtpse_mcu_gen2_i2c_data }, { /* sentinel */ } diff --git a/drivers/net/pse-pd/realtek-pse-mcu.h b/drivers/net/pse-pd/realtek-pse-mcu.h index d75e91669b8f..5e31dd0993dd 100644 --- a/drivers/net/pse-pd/realtek-pse-mcu.h +++ b/drivers/net/pse-pd/realtek-pse-mcu.h @@ -88,6 +88,7 @@ struct rtpse_mcu_ctrl { int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse); extern const struct rtpse_mcu_match_data rtpse_mcu_gen1_data; +extern const struct rtpse_mcu_match_data rtpse_mcu_gen1_i2c_data; extern const struct rtpse_mcu_match_data rtpse_mcu_gen2_data; extern const struct rtpse_mcu_match_data rtpse_mcu_gen2_i2c_data; From 4a929eba247b7cde87fa2a9cf6033301fdd2981a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 16 Oct 2026 20:57:38 +0200 Subject: [PATCH 2058/2126] Revert "enetc: Increase eMDIO MDC rate to 2.5 MHz" This reverts commit 587acb86d6465efdc03f6d8524461e6e725597b7. While the i.MX95 MDIO MDC clock is improved by the commit 587acb86d646 ("enetc: Increase eMDIO MDC rate to 2.5 MHz"), other SoCs use different base clock for their MDIO and the MDC clock on those SoCs is set out of specification by the aforementioned commit. The fix for the i.MX95 MDIO MDC has to be done differently, and will be done so in a follow up change. Until that is done, revert the commit to fix the other SoCs. Fixes: 587acb86d646 ("enetc: Increase eMDIO MDC rate to 2.5 MHz") Signed-off-by: Marek Vasut Link: https://patch.msgid.link/20261016185817.54096-1-marex@nabladev.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/enetc/enetc_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_mdio.c b/drivers/net/ethernet/freescale/enetc/enetc_mdio.c index a90a04a47bef..998aaa394e9c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_mdio.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_mdio.c @@ -24,7 +24,7 @@ #define ENETC_EMDIO_CFG \ (MDIO_CFG_HOLD(2) | \ - MDIO_CFG_CLKDIV(66) | \ + MDIO_CFG_CLKDIV(258) | \ MDIO_CFG_NEG) #define MDIO_CTL_DEV_ADDR(x) ((x) & 0x1f) From cbd8a536cd6d66d695deacd26d74557c020e3be0 Mon Sep 17 00:00:00 2001 From: "Maxime Chevallier (Netdev Foundation)" Date: Thu, 15 Oct 2026 15:43:46 +0200 Subject: [PATCH 2059/2126] selftests: drv-net: Introduce a selftest for ethtool flow control Ethernet flow control is a tricky thing to get right, especially when it comes to correctly handling the negotiation of the parameters with a link partner. On one hand, the userspace API talks in terms of the device's ability to send Pause frames when the device is overwhelmed by ingress traffic (TX pause) and the ability to stop sending traffic upon receiving Pause frames (RX pause). On the other hand, 802.3 explains that devices can exchange their abilities over link negotiation, but instead of echanging TX and RX abilities, they exchange Pause and Asymmetric Pause capabilities : RX unable TX unable => None RX able TX unable => Pause + Asymmetric RX unable TX able => Asymmetric RX able TX able => Pause The reported Pause and Asym abilities depend both on the MAC, that eventually sends and processes these frames, and the PHY, that advertises these to the partner. Both MAC and PHYs can have their own limitations, and getting the correct set of supported Pause/Asym parameters is non-trivial, unless the MAC uses phylink, which deals with the complexity. Introduce a set of Pause selftests that verify that the local interface's supported pause parameters reported from ethtool (in terms of Pause + Asym ) match the accepted parameters from "ethtool -A", corresponding to ethtool's .set_pauseparams() ops, expressed in TX and RX abilities. Signed-off-by: Maxime Chevallier (Netdev Foundation) Link: https://patch.msgid.link/20261015134350.629593-2-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../testing/selftests/drivers/net/hw/pause.py | 369 ++++++++++++++++++ 2 files changed, 370 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/pause.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 18ce235a77f8..9b6b5d15f04d 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -40,6 +40,7 @@ TEST_PROGS = \ nk_netns.py \ nk_qlease.py \ ntuple.py \ + pause.py \ pp_alloc_fail.py \ rss_api.py \ rss_ctx.py \ diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py new file mode 100755 index 000000000000..854428e19f55 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/pause.py @@ -0,0 +1,369 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +Driver-related behavior tests for Pause-based Flow Control. +""" + +import errno +import json +import os + +from lib.py import KsftFailEx, KsftNamedVariant, KsftSkipEx +from lib.py import NetDrvEpEnv +from lib.py import cmd, defer, ethtool, ip, wait_file +from lib.py import ksft_disruptive, ksft_variants, ksft_run +from lib.py import ksft_eq, ksft_exit, ksft_in, ksft_not_in, ksft_pr + +# Linkmodes to Pause params : +# Pause bit is set if rx == 1 +# Asym_Pause bit is set if rx != tx +pauseparams_to_linkmodes = { + 0: {0: {"rx": 0, "tx": 0, "linkmodes": []}, + 1: {"rx": 0, "tx": 1, "linkmodes": ["Asym_Pause"]}}, + 1: {0: {"rx": 1, "tx": 0, "linkmodes": ["Pause", "Asym_Pause"]}, + 1: {"rx": 1, "tx": 1, "linkmodes": ["Pause"]}}, +} + +def onoff(val): + """ Convert a bool to on/off """ + return "on" if val else "off" + +pauseparams_variants = [ + KsftNamedVariant(f"RX {onoff(p['rx'])} TX {onoff(p['tx'])}", p) + for by_tx in pauseparams_to_linkmodes.values() for p in by_tx.values() +] + +_strerrors = {os.strerror(e): e for e in errno.errorcode} + +def ethtool_ret(command, is_get=True, host=None): + """ Execute an ethtool command, returns the return code and JSON content + + :param command: the ethtool arguments + :param is_get: Is the command a get or a set. Get commands return the loaded + JSON attributes + :param host: The host on which to run the command on. None means local host. + """ + json_flag = "--json" if is_get else "" + cmd_res = cmd(f"ethtool {json_flag} {command}", host=host, fail=False) + + if cmd_res.ret != 0: + # ethtool returns 1 upon error, not the netlink errcode. Try to get it + # by parsing the stderr output, which looks like : + # "netlink error: Operation not supported" + for line in cmd_res.stderr.splitlines(): + err = _strerrors.get(line.rsplit(": ", 1)[-1].strip()) + if err: + return err, None + return cmd_res.ret, None + + # Not a get operation, we don't have any JSON output to parse + if not is_get: + return 0, None + + return 0, json.loads(cmd_res.stdout)[0] + +def wait_for_link(cfg, timeout=15): + """ Wait for the link to come up """ + + wait_file(f"/sys/class/net/{cfg.ifname}/carrier", + lambda x: x.strip() == "1", deadline=timeout) + +def wait_for_aneg(cfg, link_drop=False, timeout=15): + """ Wait for a renegotiation to complete + + :param link_drop: Set to true if the link HAS to flap. + """ + try: + wait_file(f"/sys/class/net/{cfg.ifname}/carrier", + lambda x: x.strip() == "0", + deadline=timeout if link_drop else 2) + except TimeoutError: + if link_drop: + raise + + wait_for_link(cfg, timeout) + +def forced_link_settings(cfg): + """ Returns a string to pass to ethtool -s with speed/duplex corresponding + to the current settings. + + Note that some devices don't return duplex info, so assume full duplex + in that case. + """ + link = ethtool(f"{cfg.ifname}", json=True)[0] + if "speed" not in link: + return "" + + return f"speed {link['speed']} duplex {link.get('duplex', 'Full').lower()}" + +def _ethtool_pause_use_to_linkmodes(use): + """ Convert the ethtool output for pause modes into pause linkmodes """ + if use == "Symmetric": + return ["Pause"] + elif use == "Symmetric Receive-only": + return ["Pause", "Asym_Pause"] + elif use == "Transmit-only": + return ["Asym_Pause"] + else: + return [] + +def set_local_pauseparams(cfg, rx, tx, aneg): + """ set pauseparams : ethtool -A """ + rx_param = onoff(rx) + tx_param = onoff(tx) + aneg_param = onoff(aneg) + + ret, _ = ethtool_ret(f"-A {cfg.ifname} rx {rx_param} tx {tx_param}" + f" autoneg {aneg_param}", + is_get = False) + + if ret != 0 and ret != errno.EOPNOTSUPP: + raise KsftFailEx(f"ethtool -A {cfg.ifname} failed: {ret}") + + return ret + +def get_local_pauseparams(cfg): + """ get pauseparams : ethtool -a """ + return ethtool_ret(f"-a {cfg.ifname}", is_get=True) + +def get_local_pause_supported(cfg): + """ Return the errcode and the local pause supported linkmodes """ + + ret, data = ethtool_ret(f"{cfg.ifname}") + if ret != 0: + raise KsftFailEx(f"ethtool {cfg.ifname} failed: {ret}") + + if "supported-pause-frame-use" not in data: + raise KsftSkipEx(f"{cfg.ifname} doesn't report its link modes") + + return ret, _ethtool_pause_use_to_linkmodes(data["supported-pause-frame-use"]) + +def get_local_pause_advertising(cfg): + """ Return the errcode and the local pause advertised linkmodes """ + + ret, data = ethtool_ret(f"{cfg.ifname}") + if ret != 0: + raise KsftFailEx(f"ethtool {cfg.ifname} failed: {ret}") + + if "advertised-pause-frame-use" not in data: + raise KsftSkipEx(f"{cfg.ifname} doesn't report its link modes") + + return ret, _ethtool_pause_use_to_linkmodes(data["advertised-pause-frame-use"]) + +def require_pause_supported_allof(cfg, linkmodes): + """ Skip if local device doesn't support all of the passed modes """ + + ret, _ = get_local_pauseparams(cfg) + if ret != 0: + raise KsftSkipEx("device doesn't allow getting pauseparams") + + _, pause_support = get_local_pause_supported(cfg) + for lm in linkmodes: + if lm not in pause_support: + raise KsftSkipEx(f"Local device doesn't support {lm}") + +def expect_pauseparams_set(cfg, pauseparams, aneg, supported, note): + """ ethtool -A must work or be refused depending on what the local + device supports + """ + rx = pauseparams["rx"] + tx = pauseparams["tx"] + + # Measure current pauseparams, re-setting the same params as the current + # ones returns 0 even if unsupported. + _, cur = get_local_pauseparams(cfg) + noop = cur and (cur["rx"], cur["tx"], cur["autonegotiate"]) == \ + (bool(rx), bool(tx), aneg) + + ret, _ = ethtool_ret(f"-A {cfg.ifname} rx {onoff(rx)} tx {onoff(tx)}" + f" autoneg {onoff(aneg)}", is_get = False) + + if noop: + ksft_eq(ret, 0, note) + elif not supported: + ksft_eq(ret, errno.EOPNOTSUPP, note) + elif set(pauseparams["linkmodes"]).issubset(set(supported)): + ksft_eq(ret, 0, note) + else: + ksft_in(ret, (errno.EOPNOTSUPP, errno.EINVAL), note) + +def pause_setup(cfg): + """ The starting conditions every test counts on, restored on exit: + - both ports admin up + - link autoneg on on both sides ifsupported + - carrier on + """ + + # Get init pause parameters + ret, params = ethtool_ret(f"-a {cfg.ifname}") + if ret == 0: + defer(cmd, f"ethtool -A {cfg.ifname} rx {onoff(params['rx'])} " + f"tx {onoff(params['tx'])} " + f"autoneg {onoff(params['autonegotiate'])}") + + # Get init link parameters + link = ethtool(f"{cfg.ifname}", json=True)[0] + if "auto-negotiation" not in link: + raise KsftSkipEx(f"{cfg.ifname} doesn't report its link modes") + + if link["auto-negotiation"]: + defer(cmd, f"ethtool -s {cfg.ifname} autoneg on") + elif "speed" in link and "duplex" in link: + defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} " + f"duplex {link['duplex'].lower()}") + + # Local interface admin up, link aneg on + ip(f"link set {cfg.ifname} up") + if link["supports-auto-negotiation"] and not link["auto-negotiation"]: + ethtool(f"-s {cfg.ifname} autoneg on") + + # Get remote pause params + ret, params = ethtool_ret(f"-a {cfg.remote_ifname}", host=cfg.remote) + if ret == 0: + defer(cmd, f"ethtool -A {cfg.remote_ifname} rx {onoff(params['rx'])} " + f"tx {onoff(params['tx'])} " + f"autoneg {onoff(params['autonegotiate'])}", + host=cfg.remote) + + # Get remote link params + link = ethtool(f"{cfg.remote_ifname}", json=True, host=cfg.remote)[0] + if "auto-negotiation" not in link: + raise KsftSkipEx(f"{cfg.remote_ifname} doesn't report its link modes") + + if link["auto-negotiation"]: + defer(cmd, f"ethtool -s {cfg.remote_ifname} autoneg on", + host=cfg.remote) + elif "speed" in link and "duplex" in link: + defer(cmd, f"ethtool -s {cfg.remote_ifname} autoneg off " + f"speed {link['speed']} duplex {link['duplex'].lower()}", + host=cfg.remote) + + # Remote interface admin up, link aneg on + ip(f"link set {cfg.remote_ifname} up", host=cfg.remote) + if link["supports-auto-negotiation"] and not link["auto-negotiation"]: + ethtool(f"-s {cfg.remote_ifname} autoneg on", host=cfg.remote) + + wait_for_link(cfg) + +# Pause support : Supported linkmodes vs ability to set/get pauseparams +@ksft_variants(pauseparams_variants) +@ksft_disruptive +def pause_test_support(cfg, pauseparams): + """ Verify that the supported linkmodes Pause and Asym_Pause match the + ability to configure the rx and tx pauseparams. + + Drivers are expected to reject pauseparams they don't support, and + accept the ones they support. The supported modes are exposed by + the MAC to the PHY layer through phylink mac_capabilities MAC_SYM_PAUSE + and MAC_ASYM_PAUSE, or through phylib directly with the + phy_support_sym_pause() and phy_support_asym_pause() helpers. + + The expectation is for drivers to refuse setting pauseparams that don't + match the Pause and Asym_Pause bits in the supported linkmodes with a + -EOPNOTSUPP return value. Unsupported pause params must be rejected. + + Failing this test likely means the MAC driver doesn't implement the + set/get_pauseparam, but still sets flow control as supported through + phylink mac_capabilities or phylib's pause API. Conversely, the MAC driver + may have omitted to indicate its supported Pause modes. Finally, the PHY + driver may incorrectly override the Pause and Asym_Pause bits in its + supported fields. + """ + + pause_setup(cfg) + + forced = forced_link_settings(cfg) + _, supported = get_local_pause_supported(cfg) + + # We check that what we can configure in the pause params matches what we + # support under various contditions : Link aneg on/off, pause aneg on/off + ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg on", is_get = False) + if ret != 0: + ksft_pr("link autoneg on refused, not tested") + else: + expect_pauseparams_set(cfg, pauseparams, False, supported, + "link autoneg on") + expect_pauseparams_set(cfg, pauseparams, True, supported, + "link autoneg on") + + if not forced: + ksft_pr("link speed unknown, the forced link is not tested") + return + + ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False) + if ret != 0: + ksft_pr(f"link autoneg off {forced} refused, not tested") + return + + expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off") + expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off") + +@ksft_variants(pauseparams_variants) +@ksft_disruptive +def pause_advertising_test(cfg, pauseparams): + """Pause advertisement + + Validate that changing pause params through the ETHTOOL_MSG_PAUSE command + translates to a change in the advertised pause params, and that these + parameters are correct w.r.t the supported pause params and requested pause + params. + + This exercises the .set_pauseparam() ethtool ops for MAC configuration, + as well as the reconfiguration of the PHY's advertising and negotiation. + + On non-phylink MACs, the MAC should call phy_set_sym_pause() to update the + PHY's advertising, and restart a negotiation with phy_start_aneg() if + need be. Failure to do so will result in the wrong advertising parameters. + + On phylink-enabled MACs, phylink deals with the PHY reconfiguration provided + the MAC driver calls phylink_ethtool_set_pauseparam(). + + Failing this test likely means that the PHY driver is not correctly + advertising pause settings, either due to the MAC not triggering a PHY + reconfiguration, a misconfiguration of the advertising registers by the PHY, + or by mis-handling the phydev->advertising bitmap in the PHY driver directly. + + The validation is made by looking at the advertised modes locally, as well + as what the peer's 'lp_advertising' values report. + """ + + require_pause_supported_allof(cfg, pauseparams["linkmodes"]) + pause_setup(cfg) + + tx = pauseparams["tx"] + rx = pauseparams["rx"] + adv = pauseparams["linkmodes"] + not_adv = [ l for l in ["Pause", "Asym_Pause"] if l not in adv] + + # It's OK to skip here, we're already validating the EOPNOTSUPP behaviour + # the pause_test_support test. + ret = set_local_pauseparams(cfg, rx, tx, True) + if ret == errno.EOPNOTSUPP: + raise KsftSkipEx(f"RX {rx} TX {tx} not supported") + + # Wait for link parameters to re-negotiate and link to come back up. It must + # come back up, otherwise that means changing pauseparams can bring the + # link down. + wait_for_aneg(cfg) + + _, linkmodes = get_local_pause_advertising(cfg) + for mode in adv: + ksft_in(mode, linkmodes, + f"rx {rx} tx {tx} aneg on must advertise {adv}") + + for mode in not_adv: + ksft_not_in(mode, linkmodes, + f"rx {rx} tx {tx} aneg on must not advertise {not_adv}") + +def main(): + """ Entry point """ + with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + ksft_run([pause_test_support, + pause_advertising_test, + ], + args=(cfg, )) + ksft_exit() + +if __name__ == "__main__": + main() From 8f897f26ef34d45570d2219fdd881184100668d2 Mon Sep 17 00:00:00 2001 From: "Maxime Chevallier (Netdev Foundation)" Date: Thu, 15 Oct 2026 15:43:47 +0200 Subject: [PATCH 2060/2126] selftests: drv-net: pause: Validate the pause autonegotiation with a partner Pause autonegotiation behaves differently than the regular link params autonegotiation, in that the user intention may differ from the negotiated pause parameters. Introduce a test that validates we're correctly resolving pause parameters according to 802.3. The validation is done based on what the local interface reports in terms of advertised and lp_advertised linkmodes. If the remote can express what it sees in terms of its own advertised and lp_advertised modes, validate the autoneg results on the peer as well. Signed-off-by: Maxime Chevallier (Netdev Foundation) Link: https://patch.msgid.link/20261015134350.629593-3-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/pause.py | 308 ++++++++++++++++++ 1 file changed, 308 insertions(+) diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py index 854428e19f55..cd117296be33 100755 --- a/tools/testing/selftests/drivers/net/hw/pause.py +++ b/tools/testing/selftests/drivers/net/hw/pause.py @@ -84,6 +84,41 @@ def wait_for_aneg(cfg, link_drop=False, timeout=15): wait_for_link(cfg, timeout) +def controllable_lp(cfg): + """ Whether the remote interface is the link partner of the local one. + + For low level ethtool tests, we need to have the remote directly connected + to the local host (i.e. not through a switch). + + This is tested by taking triggering a link renegotiation and checking the + carrier_changes counter on the partner. + + :returns: True if the remote is our link partner + """ + controllable = getattr(cfg, "lp_controllable", None) + if controllable is not None: + return controllable + + before = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes", + host=cfg.remote).stdout) + + ret, _ = ethtool_ret(f"-r {cfg.ifname}", is_get=False) + if ret != 0: + raise KsftSkipEx(f"ethtool -r {cfg.ifname} failed: {errno.errorcode.get(ret, ret)}") + + wait_for_aneg(cfg, link_drop=True) + + cfg.lp_controllable = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes", + host=cfg.remote).stdout) > before + return cfg.lp_controllable + +def require_controllable_lp(cfg): + """ Skip if the remote isn't directly controllable, e.g. accessed through + a switch + """ + if not controllable_lp(cfg): + raise KsftSkipEx(f"{cfg.remote_ifname} is not directly connected to {cfg.ifname}") + def forced_link_settings(cfg): """ Returns a string to pass to ethtool -s with speed/duplex corresponding to the current settings. @@ -108,6 +143,10 @@ def _ethtool_pause_use_to_linkmodes(use): else: return [] +def pause_to_linkmodes(rx, tx): + """ Convert the bool rx/tx pause into Pause/Asym """ + return pauseparams_to_linkmodes[rx][tx]["linkmodes"] + def set_local_pauseparams(cfg, rx, tx, aneg): """ set pauseparams : ethtool -A """ rx_param = onoff(rx) @@ -127,6 +166,27 @@ def get_local_pauseparams(cfg): """ get pauseparams : ethtool -a """ return ethtool_ret(f"-a {cfg.ifname}", is_get=True) +def set_peer_pauseparams(cfg, rx, tx, aneg): + """ set pauseparams on peer : ethtool -A """ + rx_param = onoff(rx) + tx_param = onoff(tx) + aneg_param = onoff(aneg) + + ret, _ = ethtool_ret(f"-A {cfg.remote_ifname} rx {rx_param} tx {tx_param}" + f" autoneg {aneg_param}", + is_get = False, host=cfg.remote) + + if ret != 0: + raise KsftSkipEx(f"Can't set pauseparams on peer: {errno.errorcode.get(ret, ret)}") + + return ret + +def get_peer_pauseparams(cfg): + """ get pauseparams on peer : ethtool -a """ + + return ethtool_ret(f"-a {cfg.remote_ifname}", is_get=True, + host=cfg.remote) + def get_local_pause_supported(cfg): """ Return the errcode and the local pause supported linkmodes """ @@ -151,6 +211,61 @@ def get_local_pause_advertising(cfg): return ret, _ethtool_pause_use_to_linkmodes(data["advertised-pause-frame-use"]) +def get_local_pause_lp_advertising(cfg): + """ Return the errcode and the local pause lp_advertised linkmodes, + if any. + """ + + ret, data = ethtool_ret(f"{cfg.ifname}") + if ret != 0: + raise KsftFailEx(f"ethtool {cfg.ifname} failed: {errno.errorcode.get(ret, ret)}") + + if "link-partner-advertised-pause-frame-use" in data: + return ret, _ethtool_pause_use_to_linkmodes(data["link-partner-advertised-pause-frame-use"]) + else: + ksft_pr(f"Warning: {cfg.ifname} does not report the LP's advertising") + return errno.EOPNOTSUPP, None + +def get_peer_pause_supported(cfg): + """ Return the errcode and the remote pause supported linkmodes """ + + ret, data = ethtool_ret(f"{cfg.remote_ifname}", host = cfg.remote) + if ret != 0: + raise KsftFailEx(f"ethtool {cfg.remote_ifname} failed: {errno.errorcode.get(ret, ret)}") + + if "supported-pause-frame-use" not in data: + raise KsftSkipEx(f"{cfg.remote_ifname} doesn't report its link modes") + + return ret, _ethtool_pause_use_to_linkmodes(data["supported-pause-frame-use"]) + + +def get_peer_pause_advertising(cfg): + """ Return the errcode and the remote pause advertised linkmodes """ + + ret, data = ethtool_ret(f"{cfg.remote_ifname}", host = cfg.remote) + if ret != 0: + raise KsftFailEx(f"ethtool {cfg.remote_ifname} failed: {errno.errorcode.get(ret, ret)}") + + if "advertised-pause-frame-use" not in data: + raise KsftSkipEx(f"{cfg.remote_ifname} doesn't report its link modes") + + return ret, _ethtool_pause_use_to_linkmodes(data["advertised-pause-frame-use"]) + +def get_peer_pause_lp_advertising(cfg): + """ Return the errcode and the peer pause lp_advertised linkmodes, + if any. + """ + + ret, data = ethtool_ret(f"{cfg.remote_ifname}", host = cfg.remote) + if ret != 0: + raise KsftFailEx(f"ethtool {cfg.remote_ifname} failed: {errno.errorcode.get(ret, ret)}") + + if "link-partner-advertised-pause-frame-use" in data: + return ret, _ethtool_pause_use_to_linkmodes(data["link-partner-advertised-pause-frame-use"]) + else: + ksft_pr(f"Warning: {cfg.remote_ifname} does not report the LP's advertising") + return errno.EOPNOTSUPP, None + def require_pause_supported_allof(cfg, linkmodes): """ Skip if local device doesn't support all of the passed modes """ @@ -163,6 +278,18 @@ def require_pause_supported_allof(cfg, linkmodes): if lm not in pause_support: raise KsftSkipEx(f"Local device doesn't support {lm}") +def require_peer_pause_supported_allof(cfg, linkmodes): + """ Skip if local device doesn't support all of the passed modes """ + + ret, _ = get_peer_pauseparams(cfg) + if ret != 0: + raise KsftSkipEx("Remote device doesn't allow getting pauseparams") + + _, pause_support = get_peer_pause_supported(cfg) + for lm in linkmodes: + if lm not in pause_support: + raise KsftSkipEx(f"Remote device doesn't support {lm}") + def expect_pauseparams_set(cfg, pauseparams, aneg, supported, note): """ ethtool -A must work or be refused depending on what the local device supports @@ -330,6 +457,7 @@ def pause_advertising_test(cfg, pauseparams): require_pause_supported_allof(cfg, pauseparams["linkmodes"]) pause_setup(cfg) + lp = controllable_lp(cfg) tx = pauseparams["tx"] rx = pauseparams["rx"] @@ -356,11 +484,191 @@ def pause_advertising_test(cfg, pauseparams): ksft_not_in(mode, linkmodes, f"rx {rx} tx {tx} aneg on must not advertise {not_adv}") + if not lp: + return + + returncode, remote_linkmodes = get_peer_pause_lp_advertising(cfg) + if returncode == errno.EOPNOTSUPP: + return + + for mode in adv: + ksft_in(mode, remote_linkmodes, f"PHY does not advertise {adv}") + + for mode in not_adv: + ksft_not_in(mode, remote_linkmodes, + f"PHY incorrectly advertises {not_adv}") + + +# Pause autonegotiation resolution : Resolved pause settings vs configured +# pauseparams on local device and link partner +@ksft_variants([ + # We advertise nothing, all off + KsftNamedVariant("local rx off tx off, remote rx off tx off", + {"rx": 0, "tx": 0, "lp_rx": 0, "lp_tx": 0, "neg_rx": 0, "neg_tx": 0}), + + # We advertise nothing, all off + KsftNamedVariant("local rx off tx off, remote rx off tx on", + {"rx": 0, "tx": 0, "lp_rx": 0, "lp_tx": 1, "neg_rx": 0, "neg_tx": 0}), + + # We advertise nothing, all off + KsftNamedVariant("local rx off tx off, remote rx on tx off", + {"rx": 0, "tx": 0, "lp_rx": 1, "lp_tx": 0, "neg_rx": 0, "neg_tx": 0}), + + # We advertise nothing, all off + KsftNamedVariant("local rx off tx off, remote rx on tx on", + {"rx": 0, "tx": 0, "lp_rx": 1, "lp_tx": 1, "neg_rx": 0, "neg_tx": 0}), + + # LP advertises nothing, all off + KsftNamedVariant("local rx off tx on, remote rx off tx off", + {"rx": 0, "tx": 1, "lp_rx": 0, "lp_tx": 0, "neg_rx": 0, "neg_tx": 0}), + + # We advertise Asym, LP advertises Asym, all off + KsftNamedVariant("local rx off tx on, remote rx off tx on", + {"rx": 0, "tx": 1, "lp_rx": 0, "lp_tx": 1, "neg_rx": 0, "neg_tx": 0}), + + # We advertise Asym, LP advertises Pause + Asym, tx on + KsftNamedVariant("local rx off tx on, remote rx on tx off", + {"rx": 0, "tx": 1, "lp_rx": 1, "lp_tx": 0, "neg_rx": 0, "neg_tx": 1}), + + # Tricky case : + # We advertise Asym, LP advertises Pause, resolves to all off + KsftNamedVariant("local rx off tx on, remote rx on tx on", + {"rx": 0, "tx": 1, "lp_rx": 1, "lp_tx": 1, "neg_rx": 0, "neg_tx": 0}), + + # LP advertises nothing, all off + KsftNamedVariant("local rx on tx off, remote rx off tx off", + {"rx": 1, "tx": 0, "lp_rx": 0, "lp_tx": 0, "neg_rx": 0, "neg_tx": 0}), + + # We advertise Pause + Asym , LP advertises Asym, rx on + KsftNamedVariant("local rx on tx off, remote rx off tx on", + {"rx": 1, "tx": 0, "lp_rx": 0, "lp_tx": 1, "neg_rx": 1, "neg_tx": 0}), + + # Also tricky: Only rx enabled on both ends, but we negotiate rx/tx + # We advertise Pause + Asym, LP advertises Pause + Asym, all on + KsftNamedVariant("local rx on tx off, remote rx on tx off", + {"rx": 1, "tx": 0, "lp_rx": 1, "lp_tx": 0, "neg_rx": 1, "neg_tx": 1}), + + # We advertise Pause + Asym, LP advertises Pause, all on + KsftNamedVariant("local rx on tx off, remote rx on tx on", + {"rx": 1, "tx": 0, "lp_rx": 1, "lp_tx": 1, "neg_rx": 1, "neg_tx": 1}), + + # LP advertises nothing, all off + KsftNamedVariant("local rx on tx on, remote rx off tx off", + {"rx": 1, "tx": 1, "lp_rx": 0, "lp_tx": 0, "neg_rx": 0, "neg_tx": 0}), + + # Tricky case : + # We advertise Pause, LP advertises Asym, resolves to all off + KsftNamedVariant("local rx on tx on, remote rx off tx on", + {"rx": 1, "tx": 1, "lp_rx": 0, "lp_tx": 1, "neg_rx": 0, "neg_tx": 0}), + + # We advertise Pause, LP advertises Pause + Asym, all on + KsftNamedVariant("local rx on tx on, remote rx on tx off", + {"rx": 1, "tx": 1, "lp_rx": 1, "lp_tx": 0, "neg_rx": 1, "neg_tx": 1}), + + # We advertise Pause, LP advertises Pause, all on + KsftNamedVariant("local rx on tx on, remote rx on tx on", + {"rx": 1, "tx": 1, "lp_rx": 1, "lp_tx": 1, "neg_rx": 1, "neg_tx": 1}), +]) +@ksft_disruptive +def pause_aneg_resolution(cfg, settings): + """ Verify that rx and tx pause parameters are negotiated according to 802.3 + + 802.3 dictates the rules for pause negotiation, all 16 cases are tested, one + for each combination of Pause and Asym_Pause advertising on the local device + and the link-partner. + + This test also verifies that the peer resolved the parameters correctly, + to ensure the negotiation is triggered correctly. + + Failing this test can happen if : + - The MAC accepts the pause parameters but doesn't trigger a link + renegotiation + - that the PHY driver manually overwrites the Pause negotiation result + - that the MAC driver ignores the Pause resolution and sets its own + pause parameters regardless + """ + + expected_local_rx = settings["neg_rx"] + expected_local_tx = settings["neg_tx"] + + required_local_linkmodes = pause_to_linkmodes(settings["rx"], + settings["tx"]) + required_remote_linkmodes = pause_to_linkmodes(settings["lp_rx"], + settings["lp_tx"]) + + require_pause_supported_allof(cfg, required_local_linkmodes) + require_peer_pause_supported_allof(cfg, required_remote_linkmodes) + pause_setup(cfg) + require_controllable_lp(cfg) + + # There's symmetry between local device and LP on pause negotiation: + # - if local resolves all off or all on, LP must resolve the same + # - if local resolves RX only, remote must resolve to TX only + # - if local resolves TX only, remote must resolve to RX only + if expected_local_rx == expected_local_tx: + expected_lp_rx = expected_local_rx + expected_lp_tx = expected_local_tx + else: + expected_lp_rx = expected_local_tx + expected_lp_tx = expected_local_rx + + # Set pauseparams + ret = set_local_pauseparams(cfg, settings["rx"], settings["tx"], True) + if ret == errno.EOPNOTSUPP: + raise KsftSkipEx(f"RX {settings['rx']} TX {settings['tx']} not supported") + + wait_for_aneg(cfg) + + set_peer_pauseparams(cfg, settings["lp_rx"], settings["lp_tx"], True) + + # Wait for link to re-negotiate + wait_for_aneg(cfg) + + if get_local_pause_lp_advertising(cfg)[0] != 0: + raise KsftSkipEx("Local device doesn't report the LP's advertising") + + ret, local_pauseparams = get_local_pauseparams(cfg) + if ret != 0 or "negotiated" not in local_pauseparams: + raise KsftSkipEx("Local device doesn't report the negotiated pause params") + + # check adv + _, linkmodes = get_local_pause_advertising(cfg) + ksft_eq(linkmodes, required_local_linkmodes, + f"local rx {settings['rx']} tx {settings['tx']} must advertise " + f"{required_local_linkmodes}") + + _, linkmodes = get_peer_pause_advertising(cfg) + ksft_eq(linkmodes, required_remote_linkmodes, + f"remote rx {settings['lp_rx']} tx {settings['lp_tx']} must advertise " + f"{required_remote_linkmodes}") + + # check lp_adv if available + _, linkmodes = get_local_pause_lp_advertising(cfg) + ksft_eq(linkmodes, required_remote_linkmodes, + f"local lp_adv must show the remote's {required_remote_linkmodes}") + + # check lp_adv on remote + ret, linkmodes = get_peer_pause_lp_advertising(cfg) + if ret == 0: + ksft_eq(linkmodes, required_local_linkmodes, + f"remote lp_adv must show our {required_local_linkmodes}") + + # Check resolution + _, local_pauseparams = get_local_pauseparams(cfg) + ksft_eq(local_pauseparams["negotiated"]["rx"], expected_local_rx) + ksft_eq(local_pauseparams["negotiated"]["tx"], expected_local_tx) + + ret, remote_pauseparams = get_peer_pauseparams(cfg) + if ret == 0 and "negotiated" in remote_pauseparams: + ksft_eq(remote_pauseparams["negotiated"]["rx"], expected_lp_rx) + ksft_eq(remote_pauseparams["negotiated"]["tx"], expected_lp_tx) + def main(): """ Entry point """ with NetDrvEpEnv(__file__, nsim_test=False) as cfg: ksft_run([pause_test_support, pause_advertising_test, + pause_aneg_resolution, ], args=(cfg, )) ksft_exit() From aca2542b886dc64c4f7c7fe67647ca971d3f0794 Mon Sep 17 00:00:00 2001 From: "Maxime Chevallier (Netdev Foundation)" Date: Thu, 15 Oct 2026 15:43:48 +0200 Subject: [PATCH 2061/2126] selftests: drv-net: pause: Validate pause autoneg interactions with link autoneg Pause autonegotiation happens with the link partner using the same words as the link negotiation, used for speed and duplex exchanges. However, pause and link autonegotiation can be separately toggled : ethtool -s eth0 autoneg on # Enable link negotiation ethtool -A eth0 autoneg on # Enable Pause negotiation Pause can't be negotiated if the link autoneg isn't enabled. Pause autoneg and link autoneg settings must not interfere with one another when user is configuring them : - If Pause autoneg is on, it must stay on when link autoneg is disabled (even though Pause won't actually be negotiated) - If Pause autoneg is off, it must stay off when link autoneg is enabled Introduce a set of tests to verify that pause and link autoneg are behaving correctly, in particular that the user intent is correctly cached when toggling link autoneg. Signed-off-by: Maxime Chevallier (Netdev Foundation) Link: https://patch.msgid.link/20261015134350.629593-4-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/pause.py | 269 +++++++++++++++++- 1 file changed, 268 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py index cd117296be33..ca4a55e59c30 100755 --- a/tools/testing/selftests/drivers/net/hw/pause.py +++ b/tools/testing/selftests/drivers/net/hw/pause.py @@ -119,6 +119,17 @@ def require_controllable_lp(cfg): if not controllable_lp(cfg): raise KsftSkipEx(f"{cfg.remote_ifname} is not directly connected to {cfg.ifname}") +def require_link_autoneg(cfg): + """ Skip if local or remote device don't support link aneg """ + # Does local device support link aneg + if not ethtool(f"{cfg.ifname}", json=True)[0]["supports-auto-negotiation"]: + raise KsftSkipEx(f"{cfg.ifname} doesn't support link autoneg") + + # Does remote device support link aneg + if not ethtool(f"{cfg.remote_ifname}", + json=True, host=cfg.remote)[0]["supports-auto-negotiation"]: + raise KsftSkipEx(f"Remote {cfg.remote_ifname} doesn't support link autoneg") + def forced_link_settings(cfg): """ Returns a string to pass to ethtool -s with speed/duplex corresponding to the current settings. @@ -266,6 +277,20 @@ def get_peer_pause_lp_advertising(cfg): ksft_pr(f"Warning: {cfg.remote_ifname} does not report the LP's advertising") return errno.EOPNOTSUPP, None +def require_pause_supported_anyof(cfg, linkmodes): + """ Skip if local device doesn't support any of the passed modes """ + + ret, _ = get_local_pauseparams(cfg) + if ret != 0: + raise KsftSkipEx("device doesn't allow getting pauseparams") + + _, pause_support = get_local_pause_supported(cfg) + for lm in linkmodes: + if lm in pause_support: + return + + raise KsftSkipEx(f"Local device doesn't support any of {linkmodes}") + def require_pause_supported_allof(cfg, linkmodes): """ Skip if local device doesn't support all of the passed modes """ @@ -290,8 +315,51 @@ def require_peer_pause_supported_allof(cfg, linkmodes): if lm not in pause_support: raise KsftSkipEx(f"Remote device doesn't support {lm}") +def supported_pauseparams(cfg): + """ The rx/tx params covering every mode the local device supports """ + + _, pause_support = get_local_pause_supported(cfg) + if "Pause" in pause_support: + return 1, 1 + if "Asym_Pause" in pause_support: + return 0, 1 + + raise KsftSkipEx("Local device doesn't support pause") + +def set_local_pause_autoneg(cfg, aneg): + """ Enable/Disable local pause autoneg """ + + ret, _ = ethtool_ret(f"-A {cfg.ifname} autoneg {onoff(aneg)}", + is_get=False) + return ret + +def check_local_pauseparams(cfg, aneg, rx, tx): + """ Check that the local pauseparams are the passed parameters """ + + ret, params = get_local_pauseparams(cfg) + ksft_eq(ret, 0) + if ret != 0: + return + + ksft_eq(params["autonegotiate"], bool(aneg), "pause autoneg") + ksft_eq(params["rx"], bool(rx), "rx pause") + ksft_eq(params["tx"], bool(tx), "tx pause") + +def check_local_advertising(cfg, linkmodes): + """ Check that the local advertised modes are the passed parameters """ + + _, adv = get_local_pause_advertising(cfg) + ksft_eq(adv, linkmodes, "advertised pause modes") + +def check_local_lp_advertising(cfg, linkmodes): + """ Check that the local lp_advertised modes are the passed parameters """ + + ret, adv = get_local_pause_lp_advertising(cfg) + if ret == 0: + ksft_eq(adv, linkmodes, "link partner advertised pause modes") + def expect_pauseparams_set(cfg, pauseparams, aneg, supported, note): - """ ethtool -A must work or be refused depending on what the local + """ Whether ethtool -A had to work or to be refused, given what the local device supports """ rx = pauseparams["rx"] @@ -663,12 +731,211 @@ def pause_aneg_resolution(cfg, settings): ksft_eq(remote_pauseparams["negotiated"]["rx"], expected_lp_rx) ksft_eq(remote_pauseparams["negotiated"]["tx"], expected_lp_tx) +@ksft_disruptive +def pause_autoneg_state_adv(cfg): + """Validate that disabling pause autoneg keeps the advertised linkmodes + + With pause autoneg disabled, the pause params are enforced as what the user + intended, but the advertising still follows the rx and tx pause params so + that the link partner resolves its own pause settings consistently. + + Failing this test means that the MAC or PHY driver changes the + Pause / Asym_Pause advertising when pause autoneg is disabled. + """ + + require_pause_supported_anyof(cfg, ["Pause", "Asym_Pause"]) + require_link_autoneg(cfg) + + pause_setup(cfg) + require_controllable_lp(cfg) + + set_peer_pauseparams(cfg, True, True, True) + wait_for_aneg(cfg) + + rx, tx = supported_pauseparams(cfg) + + # Enable all possible pauseparams with pause autoneg + ret = set_local_pauseparams(cfg, rx, tx, True) + ksft_eq(ret, 0) + wait_for_aneg(cfg) + + # Make sure we advertise them + ret, adv = get_local_pause_advertising(cfg) + ksft_eq(ret, 0) + ksft_eq(adv, pause_to_linkmodes(rx, tx)) + + # Disable pause autoneg + ret = set_local_pauseparams(cfg, rx, tx, False) + ksft_eq(ret, 0) + + # This may trigger a link renegociation + wait_for_aneg(cfg) + + ret, adv = get_local_pause_advertising(cfg) + ksft_eq(ret, 0) + ksft_eq(adv, pause_to_linkmodes(rx, tx)) + + ret, adv = get_peer_pause_lp_advertising(cfg) + if ret == errno.EOPNOTSUPP: + return + + ksft_eq(ret, 0) + ksft_eq(adv, pause_to_linkmodes(rx, tx)) + +@ksft_disruptive +def pause_autoneg_state_params(cfg): + """Validate the pause params when transitioning between fixed pause + params and negotiated ones. The goal is to make sure that user + intent on the RX and TX pause params are stored when user decides + to use negotiated parameters instead. The main gotcha lies on the + fact that when pause autoneg is used, the autoneg result may differ + from the user intent. + + Failing this test means the MAC driver is overwriting the user intent + when switching to forced pause. + """ + + require_pause_supported_allof(cfg, ["Pause", "Asym_Pause"]) + require_peer_pause_supported_allof(cfg, ["Pause"]) + require_link_autoneg(cfg) + pause_setup(cfg) + require_controllable_lp(cfg) + + # Set peer user intent to RX on TX on, with Pause autoneg on + set_peer_pauseparams(cfg, 1, 1, True) + wait_for_aneg(cfg) + + # Set the local intent to RX on TX off with pause autoneg + ksft_eq(set_local_pauseparams(cfg, 1, 0, True), 0) + wait_for_aneg(cfg) + + check_local_pauseparams(cfg, True, 1, 0) + check_local_advertising(cfg, ["Pause", "Asym_Pause"]) + check_local_lp_advertising(cfg, ["Pause"]) + + # Disable pause autoneg + ksft_eq(set_local_pause_autoneg(cfg, False), 0) + wait_for_aneg(cfg) + + # The pauseparams must still be what we configured before, and not the + # previously negotiated ones + check_local_pauseparams(cfg, False, 1, 0) + + # Re-enable autoneg + ksft_eq(set_local_pause_autoneg(cfg, True), 0) + wait_for_aneg(cfg) + + check_local_pauseparams(cfg, True, 1, 0) + # We must be advertising our intent again, and not RX on TX on, which would + # be "Pause" only. + check_local_advertising(cfg, ["Pause", "Asym_Pause"]) + check_local_lp_advertising(cfg, ["Pause"]) + +@ksft_disruptive +def pause_autoneg_off_while_link_autoneg_on(cfg): + """ Validate that when link autoneg is on but pause autoneg is off, we do + not use negotiated pause parameters. + + Failing this test means the MAC driver incorrectly accounts for the + negotiated pause parameters even with pause aneg off, likely due to + confusion between link autoneg and pause autoneg. + """ + + require_pause_supported_anyof(cfg, ["Pause", "Asym_Pause"]) + require_peer_pause_supported_allof(cfg, ["Pause"]) + require_link_autoneg(cfg) + pause_setup(cfg) + require_controllable_lp(cfg) + + rx, tx = supported_pauseparams(cfg) + + # Enable pause autoneg with all the locally supported modes enabled + set_peer_pauseparams(cfg, 1, 1, True) + ksft_eq(set_local_pauseparams(cfg, rx, tx, True), 0) + wait_for_aneg(cfg) + + # Disable Pause autoneg + ksft_eq(set_local_pauseparams(cfg, rx, tx, False), 0) + wait_for_aneg(cfg) + # Pause autoneg must read "disabled" + check_local_pauseparams(cfg, False, rx, tx) + + set_peer_pauseparams(cfg, 0, 0, True) + wait_for_aneg(cfg) + + ethtool(f"-r {cfg.ifname}") + wait_for_aneg(cfg, link_drop=True) + + # Pause autoneg must still be off even after a link renegotiation + check_local_pauseparams(cfg, False, rx, tx) + +@ksft_disruptive +def pause_autoneg_link_autoneg(cfg): + """Validate pause autoneg and link autoneg interactions. The link autoneg's + admin status (i.e. do we autoneg link parameters or force them) must not + impact the pause autoneg status. While link autoneg is disabled, we don't + negotiate the pause params, however we must keep pause autoneg on as this + is the user intent. When link autoneg is re-enabled, pause params must be + derived from the negotiation. + """ + + require_pause_supported_anyof(cfg, ["Pause", "Asym_Pause"]) + require_peer_pause_supported_allof(cfg, ["Pause"]) + require_link_autoneg(cfg) + pause_setup(cfg) + require_controllable_lp(cfg) + + rx, tx = supported_pauseparams(cfg) + adv = pause_to_linkmodes(rx, tx) + + # Enable all possible pause modes and autoneg + set_peer_pauseparams(cfg, 1, 1, True) + ksft_eq(set_local_pauseparams(cfg, rx, tx, True), 0) + wait_for_aneg(cfg) + + # Disable link autoneg, at the speed and duplex the link runs at + forced = forced_link_settings(cfg) + if not forced: + raise KsftSkipEx("Can't tell what to force the link at") + + ret, _ = ethtool_ret(f"-s {cfg.remote_ifname} autoneg off {forced}", + is_get=False, host=cfg.remote) + if ret != 0: + raise KsftSkipEx(f"Can't force the peer's link at {forced}") + + ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", + is_get=False) + if ret != 0: + raise KsftSkipEx(f"Can't force the link at {forced}") + + try: + wait_for_aneg(cfg) + except TimeoutError: + raise KsftSkipEx(f"No link when forced at {forced}") + + # We must have pause autoneg still enabled, even if we don't negotiate pause + check_local_pauseparams(cfg, True, rx, tx) + + # Re-enable autoneg + ethtool(f"-s {cfg.remote_ifname} autoneg on", host=cfg.remote) + ethtool(f"-s {cfg.ifname} autoneg on") + wait_for_aneg(cfg) + + # Pause autoneg must still be on + check_local_pauseparams(cfg, True, rx, tx) + check_local_advertising(cfg, adv) + check_local_lp_advertising(cfg, ["Pause"]) + def main(): """ Entry point """ with NetDrvEpEnv(__file__, nsim_test=False) as cfg: ksft_run([pause_test_support, pause_advertising_test, pause_aneg_resolution, + pause_autoneg_state_adv, + pause_autoneg_state_params, + pause_autoneg_off_while_link_autoneg_on, + pause_autoneg_link_autoneg, ], args=(cfg, )) ksft_exit() From 554c7af9367a6c1f5269dd97aed30d8abc802910 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Mon, 12 Oct 2026 05:04:34 -0700 Subject: [PATCH 2062/2126] eth: mpnic: count packets, bytes, and drops per ring Keep packet, byte and drop counters on each Tx work, Tx completion, and Rx completion queue. Report them to the core via the rtnl_link_stats64 interface. Rx completion queues also count errors. Frames the device marked with an uncorrectable error are counted as errors, and frames that fail for any other reason are counted as drops. All packets cleaned from the TWQ during mpnic_flush() are counted as drops, though completions for some of them may have been DMA'd into the completion ring between the time mpnic_poll() last ran and before mpnic_wait_all_queues_idle() returns. This is done for code simplicity. An RCU approach is used because ndo_get_stats64 is not called with the instance lock. Signed-off-by: Daniel Zahka Acked-by: Jakub Kicinski Link: https://patch.msgid.link/20261012-mpnic-counters3-v2-1-8afba81c2d5a@gmail.com Signed-off-by: Paolo Abeni --- .../net/ethernet/meta/mpnic/mpnic_netdev.c | 76 +++++++++++ .../net/ethernet/meta/mpnic/mpnic_netdev.h | 26 ++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 123 ++++++++++++++++-- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 24 ++++ 4 files changed, 241 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c index bd10df4a9d46..5164475a0f94 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -28,6 +28,8 @@ static int mpnic_open(struct net_device *netdev) if (err) goto err_free_resources; + mpnic_stats_attach_rings(mpn); + mpnic_enable(mpn); mpnic_fill(mpn); mpnic_napi_enable(mpn); @@ -60,6 +62,8 @@ static int mpnic_stop(struct net_device *netdev) mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); + mpnic_stats_fold_rings(mpn); + mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn); mpnic_free_napi_vectors(mpn); @@ -67,11 +71,79 @@ static int mpnic_stop(struct net_device *netdev) return 0; } +static void +mpnic_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64) +{ + struct mpnic_net *mpn = netdev_priv(dev); + u64 bytes, packets, dropped, errors; + struct mpnic_queue_stats *stats; + struct mpnic_base_stats *base; + unsigned int start, i; + + rcu_read_lock(); + + base = rcu_dereference(mpn->stats.base); + + stats64->tx_bytes = base->tx.bytes; + stats64->tx_packets = base->tx.packets; + stats64->tx_dropped = base->tx.dropped; + + stats64->rx_bytes = base->rx.bytes; + stats64->rx_packets = base->rx.packets; + stats64->rx_dropped = base->rx.dropped; + stats64->rx_errors = base->rx.errors; + + for (i = 0; i < base->num_tx_queues; i++) { + struct mpnic_ring *txr = base->txr[i]; + struct mpnic_q_triad *qt; + + qt = container_of(txr, struct mpnic_q_triad, sub0); + + stats = &qt->cmpl.stats; + do { + start = u64_stats_fetch_begin(&stats->syncp); + bytes = u64_stats_read(&stats->tcq.bytes); + packets = u64_stats_read(&stats->tcq.packets); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + stats = &txr->stats; + do { + start = u64_stats_fetch_begin(&stats->syncp); + dropped = u64_stats_read(&stats->twq.dropped); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + stats64->tx_bytes += bytes; + stats64->tx_packets += packets; + stats64->tx_dropped += dropped; + } + + for (i = 0; i < base->num_rx_queues; i++) { + struct mpnic_ring *rxr = base->rxr[i]; + + stats = &rxr->stats; + do { + start = u64_stats_fetch_begin(&stats->syncp); + bytes = u64_stats_read(&stats->rcq.bytes); + packets = u64_stats_read(&stats->rcq.packets); + dropped = u64_stats_read(&stats->rcq.dropped); + errors = u64_stats_read(&stats->rcq.errors); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + stats64->rx_bytes += bytes; + stats64->rx_packets += packets; + stats64->rx_dropped += dropped; + stats64->rx_errors += errors; + } + + rcu_read_unlock(); +} + static const struct net_device_ops mpnic_netdev_ops = { .ndo_open = mpnic_open, .ndo_stop = mpnic_stop, .ndo_validate_addr = eth_validate_addr, .ndo_start_xmit = mpnic_xmit_frame, + .ndo_get_stats64 = mpnic_get_stats64, }; /** @@ -110,6 +182,10 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd) mpn->netdev = netdev; mpn->mpd = mpd; + mpn->stats.buf[0].txr = mpn->tx; + mpn->stats.buf[0].rxr = mpn->rx; + RCU_INIT_POINTER(mpn->stats.base, &mpn->stats.buf[0]); + mpn->txq_size = MPNIC_TXQ_SIZE_DEFAULT; mpn->hpq_size = MPNIC_HPQ_SIZE_DEFAULT; mpn->ppq_size = MPNIC_PPQ_SIZE_DEFAULT; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h index ccb0929f9180..a61249d12a04 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h @@ -4,11 +4,32 @@ #ifndef _MPNIC_NETDEV_H_ #define _MPNIC_NETDEV_H_ +#include +#include #include #include "mpnic.h" #include "mpnic_txrx.h" +struct mpnic_base_stats { + struct { + u64 packets; + u64 bytes; + u64 dropped; + } tx; + struct { + u64 packets; + u64 bytes; + u64 dropped; + u64 errors; + } rx; + + unsigned int num_tx_queues; + unsigned int num_rx_queues; + struct mpnic_ring **txr; + struct mpnic_ring **rxr; +}; + struct mpnic_net { struct mpnic_ring *tx[MPNIC_MAX_TXQS]; struct mpnic_ring *rx[MPNIC_MAX_RXQS]; @@ -26,6 +47,11 @@ struct mpnic_net { u16 num_napi; u16 num_tx_queues; u16 num_rx_queues; + + struct { + struct mpnic_base_stats __rcu *base; + struct mpnic_base_stats buf[2]; + } stats; }; struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index 5495e9a9aa65..d5185e64f804 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "mpnic.h" @@ -228,6 +229,10 @@ err_free: err_drop: mpnic_tx_flush_doorbell(ring); + u64_stats_update_begin(&ring->stats.syncp); + u64_stats_inc(&ring->stats.twq.dropped); + u64_stats_update_end(&ring->stats.syncp); + return NETDEV_TX_OK; } @@ -239,10 +244,12 @@ netdev_tx_t mpnic_xmit_frame(struct sk_buff *skb, struct net_device *dev) } static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget, - struct mpnic_ring *ring, bool discard, + struct mpnic_q_triad *qt, bool discard, unsigned int hw_head) { u64 total_bytes = 0, total_packets = 0; + struct mpnic_ring *ring = &qt->sub0; + struct mpnic_ring *cmpl = &qt->cmpl; unsigned int head = ring->head; struct netdev_queue *txq; unsigned int clean_desc; @@ -288,8 +295,19 @@ static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget, ring->head = head; - if (discard) + if (discard) { + local_bh_disable(); + u64_stats_update_begin(&ring->stats.syncp); + u64_stats_add(&ring->stats.twq.dropped, total_packets); + u64_stats_update_end(&ring->stats.syncp); + local_bh_enable(); return; + } + + u64_stats_update_begin(&cmpl->stats.syncp); + u64_stats_add(&cmpl->stats.tcq.bytes, total_bytes); + u64_stats_add(&cmpl->stats.tcq.packets, total_packets); + u64_stats_update_end(&cmpl->stats.syncp); txq = mpnic_txring_txq(nv->napi.dev, ring); netif_txq_completed_wake(txq, total_packets, total_bytes, @@ -346,7 +364,7 @@ static void mpnic_clean_tcq(struct mpnic_napi_vector *nv, cmpl->head = head; if (head0 >= 0) - mpnic_clean_twq0(nv, napi_budget, &qt->sub0, false, head0); + mpnic_clean_twq0(nv, napi_budget, qt, false, head0); } static void mpnic_bd_prep(struct mpnic_ring *bdq, u32 idx, struct page *page) @@ -560,9 +578,9 @@ static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, struct mpnic_q_triad *qt, int budget) { + unsigned int packets = 0, bytes = 0, dropped = 0, errors = 0; struct mpnic_ring *rcq = &qt->cmpl; struct mpnic_rcq_state *state; - unsigned int packets = 0; __le64 *raw_rcd, done; u32 head = rcq->head; @@ -594,13 +612,20 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, if (likely(!(rcd & MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) && - !state->pkt.add_frag_failed)) + !state->pkt.add_frag_failed)) { + bytes += xdp_get_buff_len(&state->pkt.buff); skb = xdp_build_skb_from_buff(&state->pkt.buff); + } - if (likely(skb)) + if (likely(skb)) { napi_gro_receive(&nv->napi, skb); - else + } else { mpnic_put_pkt_buff(&state->pkt, true); + if (rcd & MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) + errors++; + else + dropped++; + } state->pkt.buff.data_hard_start = NULL; packets++; @@ -619,6 +644,13 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, rcq->head = head; + u64_stats_update_begin(&rcq->stats.syncp); + u64_stats_add(&rcq->stats.rcq.packets, packets - errors); + u64_stats_add(&rcq->stats.rcq.bytes, bytes); + u64_stats_add(&rcq->stats.rcq.dropped, dropped); + u64_stats_add(&rcq->stats.rcq.errors, errors); + u64_stats_update_end(&rcq->stats.syncp); + /* Allocate buffers, force dma_wmb(), and then start writing tails */ mpnic_fill_qt_bdqs(qt); @@ -661,6 +693,80 @@ static irqreturn_t mpnic_msix_clean_rings(int __always_unused irq, void *data) return IRQ_HANDLED; } +static void mpnic_aggregate_ring_twq_counters(struct mpnic_base_stats *base, + struct mpnic_ring *twq) +{ + base->tx.dropped += u64_stats_read(&twq->stats.twq.dropped); +} + +static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base, + struct mpnic_ring *tcq) +{ + base->tx.packets += u64_stats_read(&tcq->stats.tcq.packets); + base->tx.bytes += u64_stats_read(&tcq->stats.tcq.bytes); +} + +static void mpnic_aggregate_ring_rcq_counters(struct mpnic_base_stats *base, + struct mpnic_ring *rcq) +{ + base->rx.packets += u64_stats_read(&rcq->stats.rcq.packets); + base->rx.bytes += u64_stats_read(&rcq->stats.rcq.bytes); + base->rx.dropped += u64_stats_read(&rcq->stats.rcq.dropped); + base->rx.errors += u64_stats_read(&rcq->stats.rcq.errors); +} + +static struct mpnic_base_stats *mpnic_base_stats_prepare(struct mpnic_net *mpn) +{ + struct mpnic_base_stats *old, *new; + + old = netdev_lock_dereference(mpn->stats.base, mpn->netdev); + new = &mpn->stats.buf[old == &mpn->stats.buf[0]]; + *new = *old; + + return new; +} + +void mpnic_stats_fold_rings(struct mpnic_net *mpn) +{ + struct mpnic_base_stats *new; + int i, j, t; + + new = mpnic_base_stats_prepare(mpn); + new->num_tx_queues = 0; + new->num_rx_queues = 0; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + if (!nv) + continue; + + for (t = 0; t < nv->txt_count; t++) { + struct mpnic_q_triad *qt = &nv->qt[t]; + + mpnic_aggregate_ring_twq_counters(new, &qt->sub0); + mpnic_aggregate_ring_tcq_counters(new, &qt->cmpl); + } + + for (j = 0; j < nv->rxt_count; j++, t++) + mpnic_aggregate_ring_rcq_counters(new, &nv->qt[t].cmpl); + } + + rcu_assign_pointer(mpn->stats.base, new); + synchronize_net(); +} + +void mpnic_stats_attach_rings(struct mpnic_net *mpn) +{ + struct mpnic_base_stats *new; + + new = mpnic_base_stats_prepare(mpn); + new->num_tx_queues = mpn->num_tx_queues; + new->num_rx_queues = mpn->num_rx_queues; + rcu_assign_pointer(mpn->stats.base, new); + synchronize_net(); +} + static void mpnic_free_napi_vector(struct mpnic_net *mpn, struct mpnic_napi_vector *nv) { @@ -692,6 +798,7 @@ static void mpnic_ring_init(struct mpnic_ring *ring, u32 __iomem *doorbell, { ring->doorbell = doorbell; ring->q_idx = q_idx; + u64_stats_init(&ring->stats.syncp); } static int mpnic_alloc_napi_vector(struct mpnic_dev *mpd, @@ -1326,7 +1433,7 @@ void mpnic_flush(struct mpnic_net *mpn) struct netdev_queue *txq; /* Clean the work queue of unprocessed work */ - mpnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail); + mpnic_clean_twq0(nv, 0, qt, true, qt->sub0.tail); txq = netdev_get_tx_queue(mpn->netdev, qt->sub0.q_idx); netdev_tx_reset_queue(txq); diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 767d87a36c35..7b44cf700e5b 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,25 @@ struct mpnic_rcq_state { struct mpnic_pg_ctxt payld; }; +struct mpnic_queue_stats { + union { + struct { + u64_stats_t dropped; + } twq; + struct { + u64_stats_t packets; + u64_stats_t bytes; + } tcq; + struct { + u64_stats_t packets; + u64_stats_t bytes; + u64_stats_t dropped; + u64_stats_t errors; + } rcq; + }; + struct u64_stats_sync syncp; +}; + struct mpnic_ring { union { struct mpnic_rcq_state *state; /* RCQ */ @@ -110,6 +130,8 @@ struct mpnic_ring { s32 deferred_meta; }; + struct mpnic_queue_stats stats; + /* Slow path fields follow */ dma_addr_t dma; /* Phys addr of descriptor memory */ size_t size; /* Size of descriptor ring in memory */ @@ -142,6 +164,8 @@ struct mpnic_napi_vector { netdev_tx_t mpnic_xmit_frame(struct sk_buff *skb, struct net_device *dev); int mpnic_alloc_napi_vectors(struct mpnic_net *mpn); void mpnic_free_napi_vectors(struct mpnic_net *mpn); +void mpnic_stats_attach_rings(struct mpnic_net *mpn); +void mpnic_stats_fold_rings(struct mpnic_net *mpn); int mpnic_alloc_resources(struct mpnic_net *mpn); void mpnic_free_resources(struct mpnic_net *mpn); int mpnic_set_netif_queues(struct mpnic_net *mpn); From 5cc79ff41b07ce96b30469c47fe5133559531434 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Mon, 12 Oct 2026 05:04:35 -0700 Subject: [PATCH 2063/2126] eth: mpnic: report per-queue stats Expose the per-ring packet and byte counters through the queue stats API. Counters for deactivated rings are reported through the base stats. Signed-off-by: Daniel Zahka Acked-by: Jakub Kicinski Link: https://patch.msgid.link/20261012-mpnic-counters3-v2-2-8afba81c2d5a@gmail.com Signed-off-by: Paolo Abeni --- .../net/ethernet/meta/mpnic/mpnic_netdev.c | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c index 5164475a0f94..c2f4a326a8f0 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "mpnic.h" #include "mpnic_netdev.h" @@ -146,6 +147,77 @@ static const struct net_device_ops mpnic_netdev_ops = { .ndo_get_stats64 = mpnic_get_stats64, }; +static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx, + struct netdev_queue_stats_rx *rx) +{ + struct mpnic_net *mpn = netdev_priv(dev); + struct mpnic_ring *rxr = mpn->rx[idx]; + struct mpnic_queue_stats *stats; + unsigned int start; + u64 bytes, packets; + + if (!rxr) + return; + + stats = &rxr->stats; + do { + start = u64_stats_fetch_begin(&stats->syncp); + bytes = u64_stats_read(&stats->rcq.bytes); + packets = u64_stats_read(&stats->rcq.packets); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + rx->bytes = bytes; + rx->packets = packets; +} + +static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx, + struct netdev_queue_stats_tx *tx) +{ + struct mpnic_net *mpn = netdev_priv(dev); + struct mpnic_ring *txr = mpn->tx[idx]; + struct mpnic_queue_stats *stats; + struct mpnic_q_triad *qt; + unsigned int start; + u64 bytes, packets; + + if (!txr) + return; + + qt = container_of(txr, struct mpnic_q_triad, sub0); + + stats = &qt->cmpl.stats; + do { + start = u64_stats_fetch_begin(&stats->syncp); + bytes = u64_stats_read(&stats->tcq.bytes); + packets = u64_stats_read(&stats->tcq.packets); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + tx->bytes = bytes; + tx->packets = packets; +} + +static void mpnic_get_base_stats(struct net_device *dev, + struct netdev_queue_stats_rx *rx, + struct netdev_queue_stats_tx *tx) +{ + struct mpnic_net *mpn = netdev_priv(dev); + struct mpnic_base_stats *base; + + base = netdev_lock_dereference(mpn->stats.base, dev); + + tx->bytes = base->tx.bytes; + tx->packets = base->tx.packets; + + rx->bytes = base->rx.bytes; + rx->packets = base->rx.packets; +} + +static const struct netdev_stat_ops mpnic_stat_ops = { + .get_queue_stats_rx = mpnic_get_queue_stats_rx, + .get_queue_stats_tx = mpnic_get_queue_stats_tx, + .get_base_stats = mpnic_get_base_stats, +}; + /** * mpnic_netdev_free - Free the netdev associated with mpnic * @mpd: Driver specific structure to free netdev from @@ -176,6 +248,7 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd) mpd->netdev = netdev; netdev->netdev_ops = &mpnic_netdev_ops; + netdev->stat_ops = &mpnic_stat_ops; netdev->request_ops_lock = true; mpn = netdev_priv(netdev); From 3b28e126619ff76e27201e2791101153da4902ac Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Mon, 12 Oct 2026 05:04:36 -0700 Subject: [PATCH 2064/2126] eth: mpnic: count Tx queue stops and wakes Count how often a Tx queue is stopped for lack of descriptors and woken again by completions, and report the counts through the queue stats API. Stops are counted on the TWQ from the xmit path and wakes on the TCQ from mpnic_poll(), keeping a single writer context for each. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20261012-mpnic-counters3-v2-3-8afba81c2d5a@gmail.com Signed-off-by: Paolo Abeni --- .../net/ethernet/meta/mpnic/mpnic_netdev.c | 13 ++++++- .../net/ethernet/meta/mpnic/mpnic_netdev.h | 2 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 37 ++++++++++++++----- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 2 + 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c index c2f4a326a8f0..9e262f939c79 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -176,9 +176,9 @@ static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx, struct mpnic_net *mpn = netdev_priv(dev); struct mpnic_ring *txr = mpn->tx[idx]; struct mpnic_queue_stats *stats; + u64 bytes, packets, stop, wake; struct mpnic_q_triad *qt; unsigned int start; - u64 bytes, packets; if (!txr) return; @@ -190,10 +190,19 @@ static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx, start = u64_stats_fetch_begin(&stats->syncp); bytes = u64_stats_read(&stats->tcq.bytes); packets = u64_stats_read(&stats->tcq.packets); + wake = u64_stats_read(&stats->tcq.wake); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + stats = &txr->stats; + do { + start = u64_stats_fetch_begin(&stats->syncp); + stop = u64_stats_read(&stats->twq.stop); } while (u64_stats_fetch_retry(&stats->syncp, start)); tx->bytes = bytes; tx->packets = packets; + tx->stop = stop; + tx->wake = wake; } static void mpnic_get_base_stats(struct net_device *dev, @@ -207,6 +216,8 @@ static void mpnic_get_base_stats(struct net_device *dev, tx->bytes = base->tx.bytes; tx->packets = base->tx.packets; + tx->stop = base->tx.stop; + tx->wake = base->tx.wake; rx->bytes = base->rx.bytes; rx->packets = base->rx.packets; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h index a61249d12a04..0d1ee66dd86c 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h @@ -16,6 +16,8 @@ struct mpnic_base_stats { u64 packets; u64 bytes; u64 dropped; + u64 stop; + u64 wake; } tx; struct { u64 packets; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index d5185e64f804..931e1031a180 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -68,6 +68,23 @@ static struct netdev_queue *mpnic_txring_txq(const struct net_device *dev, return netdev_get_tx_queue(dev, ring->q_idx); } +static bool +mpnic_maybe_stop_tx(const struct net_device *dev, struct mpnic_ring *ring) +{ + int res; + + res = netif_txq_maybe_stop(mpnic_txring_txq(dev, ring), + mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC, + MPNIC_TX_DESC_WAKEUP); + if (!res) { + u64_stats_update_begin(&ring->stats.syncp); + u64_stats_inc(&ring->stats.twq.stop); + u64_stats_update_end(&ring->stats.syncp); + } + + return !res; +} + static void mpnic_tx_doorbell(struct mpnic_ring *ring, __le64 *meta) { *meta |= cpu_to_le64(MPNIC_TWD_FLAG_REQ_COMPLETION); @@ -164,9 +181,7 @@ mpnic_tx_map(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta) ring->tail = tail; /* Verify there is room for another packet */ - netif_txq_maybe_stop(mpnic_txring_txq(skb->dev, ring), - mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC, - MPNIC_TX_DESC_WAKEUP); + mpnic_maybe_stop_tx(skb->dev, ring); if (__netdev_tx_sent_queue(mpnic_txring_txq(skb->dev, ring), MPNIC_XMIT_CB(skb)->bytecount, @@ -204,9 +219,7 @@ static netdev_tx_t mpnic_xmit_frame_ring(struct sk_buff *skb, if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN)) goto err_drop; - if (!netif_txq_maybe_stop(mpnic_txring_txq(skb->dev, ring), - mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC, - MPNIC_TX_DESC_WAKEUP)) { + if (mpnic_maybe_stop_tx(skb->dev, ring)) { mpnic_tx_flush_doorbell(ring); return NETDEV_TX_BUSY; } @@ -310,9 +323,13 @@ static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget, u64_stats_update_end(&cmpl->stats.syncp); txq = mpnic_txring_txq(nv->napi.dev, ring); - netif_txq_completed_wake(txq, total_packets, total_bytes, - mpnic_desc_unused(ring), - MPNIC_TX_DESC_WAKEUP); + if (!netif_txq_completed_wake(txq, total_packets, total_bytes, + mpnic_desc_unused(ring), + MPNIC_TX_DESC_WAKEUP)) { + u64_stats_update_begin(&cmpl->stats.syncp); + u64_stats_inc(&cmpl->stats.tcq.wake); + u64_stats_update_end(&cmpl->stats.syncp); + } } static void mpnic_commit_cq_head(struct mpnic_ring *cmpl) @@ -697,6 +714,7 @@ static void mpnic_aggregate_ring_twq_counters(struct mpnic_base_stats *base, struct mpnic_ring *twq) { base->tx.dropped += u64_stats_read(&twq->stats.twq.dropped); + base->tx.stop += u64_stats_read(&twq->stats.twq.stop); } static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base, @@ -704,6 +722,7 @@ static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base, { base->tx.packets += u64_stats_read(&tcq->stats.tcq.packets); base->tx.bytes += u64_stats_read(&tcq->stats.tcq.bytes); + base->tx.wake += u64_stats_read(&tcq->stats.tcq.wake); } static void mpnic_aggregate_ring_rcq_counters(struct mpnic_base_stats *base, diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 7b44cf700e5b..764e78918b8f 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -89,10 +89,12 @@ struct mpnic_queue_stats { union { struct { u64_stats_t dropped; + u64_stats_t stop; } twq; struct { u64_stats_t packets; u64_stats_t bytes; + u64_stats_t wake; } tcq; struct { u64_stats_t packets; From ce0d4765892063a801c11037c98e0e9db54f5573 Mon Sep 17 00:00:00 2001 From: Daniel Zahka Date: Mon, 12 Oct 2026 05:04:37 -0700 Subject: [PATCH 2065/2126] eth: mpnic: count Rx allocation failures Count both skb allocation failures and page pool allocation failures per queue, and report them through the queue stats API. The bdq allocation failures are added to the skb allocation failures when reporting to core and folded into base stats during aggregation, because the qstats API doesn't support reporting them separately. Page pool allocation failures are also counted when the BDQs are first filled in ndo_open, which runs in process context. mpnic_fill() disables BH around the fill, so the u64_stats update happens with preemption disabled. Signed-off-by: Daniel Zahka Link: https://patch.msgid.link/20261012-mpnic-counters3-v2-4-8afba81c2d5a@gmail.com Signed-off-by: Paolo Abeni --- .../net/ethernet/meta/mpnic/mpnic_netdev.c | 24 ++++++++++++++++- .../net/ethernet/meta/mpnic/mpnic_netdev.h | 1 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 27 ++++++++++++++++--- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 4 +++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c index 9e262f939c79..7fdf57f70151 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c @@ -147,14 +147,29 @@ static const struct net_device_ops mpnic_netdev_ops = { .ndo_get_stats64 = mpnic_get_stats64, }; +static u64 mpnic_bdq_alloc_failed(struct mpnic_ring *bdq) +{ + struct mpnic_queue_stats *stats = &bdq->stats; + unsigned int start; + u64 alloc_failed; + + do { + start = u64_stats_fetch_begin(&stats->syncp); + alloc_failed = u64_stats_read(&stats->bdq.alloc_failed); + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + return alloc_failed; +} + static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx, struct netdev_queue_stats_rx *rx) { struct mpnic_net *mpn = netdev_priv(dev); struct mpnic_ring *rxr = mpn->rx[idx]; + u64 bytes, packets, alloc_failed; struct mpnic_queue_stats *stats; + struct mpnic_q_triad *qt; unsigned int start; - u64 bytes, packets; if (!rxr) return; @@ -164,10 +179,16 @@ static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx, start = u64_stats_fetch_begin(&stats->syncp); bytes = u64_stats_read(&stats->rcq.bytes); packets = u64_stats_read(&stats->rcq.packets); + alloc_failed = u64_stats_read(&stats->rcq.alloc_failed); } while (u64_stats_fetch_retry(&stats->syncp, start)); + qt = container_of(rxr, struct mpnic_q_triad, cmpl); + alloc_failed += mpnic_bdq_alloc_failed(&qt->sub0); + alloc_failed += mpnic_bdq_alloc_failed(&qt->sub1); + rx->bytes = bytes; rx->packets = packets; + rx->alloc_fail = alloc_failed; } static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx, @@ -221,6 +242,7 @@ static void mpnic_get_base_stats(struct net_device *dev, rx->bytes = base->rx.bytes; rx->packets = base->rx.packets; + rx->alloc_fail = base->rx.alloc_failed; } static const struct netdev_stat_ops mpnic_stat_ops = { diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h index 0d1ee66dd86c..6711766ebc3c 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.h @@ -23,6 +23,7 @@ struct mpnic_base_stats { u64 packets; u64 bytes; u64 dropped; + u64 alloc_failed; u64 errors; } rx; diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index 931e1031a180..93abdec44642 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c @@ -409,8 +409,12 @@ static unsigned int __mpnic_fill_bdq(struct mpnic_ring *bdq) struct page *page; page = page_pool_dev_alloc_pages(bdq->page_pool); - if (!page) + if (!page) { + u64_stats_update_begin(&bdq->stats.syncp); + u64_stats_inc(&bdq->stats.bdq.alloc_failed); + u64_stats_update_end(&bdq->stats.syncp); break; + } bdq->rx_buf[i] = page; mpnic_bd_prep(bdq, i, page); @@ -598,6 +602,7 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, unsigned int packets = 0, bytes = 0, dropped = 0, errors = 0; struct mpnic_ring *rcq = &qt->cmpl; struct mpnic_rcq_state *state; + unsigned int alloc_failed = 0; __le64 *raw_rcd, done; u32 head = rcq->head; @@ -632,6 +637,7 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, !state->pkt.add_frag_failed)) { bytes += xdp_get_buff_len(&state->pkt.buff); skb = xdp_build_skb_from_buff(&state->pkt.buff); + alloc_failed += !skb; } if (likely(skb)) { @@ -665,6 +671,7 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, u64_stats_add(&rcq->stats.rcq.packets, packets - errors); u64_stats_add(&rcq->stats.rcq.bytes, bytes); u64_stats_add(&rcq->stats.rcq.dropped, dropped); + u64_stats_add(&rcq->stats.rcq.alloc_failed, alloc_failed); u64_stats_add(&rcq->stats.rcq.errors, errors); u64_stats_update_end(&rcq->stats.syncp); @@ -725,12 +732,19 @@ static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base, base->tx.wake += u64_stats_read(&tcq->stats.tcq.wake); } +static void mpnic_aggregate_ring_bdq_counters(struct mpnic_base_stats *base, + struct mpnic_ring *bdq) +{ + base->rx.alloc_failed += u64_stats_read(&bdq->stats.bdq.alloc_failed); +} + static void mpnic_aggregate_ring_rcq_counters(struct mpnic_base_stats *base, struct mpnic_ring *rcq) { base->rx.packets += u64_stats_read(&rcq->stats.rcq.packets); base->rx.bytes += u64_stats_read(&rcq->stats.rcq.bytes); base->rx.dropped += u64_stats_read(&rcq->stats.rcq.dropped); + base->rx.alloc_failed += u64_stats_read(&rcq->stats.rcq.alloc_failed); base->rx.errors += u64_stats_read(&rcq->stats.rcq.errors); } @@ -767,8 +781,13 @@ void mpnic_stats_fold_rings(struct mpnic_net *mpn) mpnic_aggregate_ring_tcq_counters(new, &qt->cmpl); } - for (j = 0; j < nv->rxt_count; j++, t++) - mpnic_aggregate_ring_rcq_counters(new, &nv->qt[t].cmpl); + for (j = 0; j < nv->rxt_count; j++, t++) { + struct mpnic_q_triad *qt = &nv->qt[t]; + + mpnic_aggregate_ring_bdq_counters(new, &qt->sub0); + mpnic_aggregate_ring_bdq_counters(new, &qt->sub1); + mpnic_aggregate_ring_rcq_counters(new, &qt->cmpl); + } } rcu_assign_pointer(mpn->stats.base, new); @@ -1494,7 +1513,9 @@ void mpnic_fill(struct mpnic_net *mpn) state->hdr.idx = UINT_MAX; state->payld.idx = UINT_MAX; + local_bh_disable(); mpnic_fill_qt_bdqs(qt); + local_bh_enable(); } } } diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 764e78918b8f..52492e3f484f 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h @@ -100,8 +100,12 @@ struct mpnic_queue_stats { u64_stats_t packets; u64_stats_t bytes; u64_stats_t dropped; + u64_stats_t alloc_failed; u64_stats_t errors; } rcq; + struct { + u64_stats_t alloc_failed; + } bdq; }; struct u64_stats_sync syncp; }; From bc67283744788ad4ee7266ce64b0e420a46d2983 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 12 Oct 2026 10:17:02 +0900 Subject: [PATCH 2066/2126] netlink: specs: rt-addr: fix the type of target-netnsid The kernel parses IFA_TARGET_NETNSID as NLA_S32 and rt-link.yaml declares its target-netnsid as s32, but rt-addr.yaml has it as binary. Signed-off-by: Yuyang Huang Reviewed-by: Nicolas Dichtel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20261012011707.3378-2-sigefriedhyy@gmail.com Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-addr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/rt-addr.yaml b/Documentation/netlink/specs/rt-addr.yaml index 0ecbd24c890c..17ead2203451 100644 --- a/Documentation/netlink/specs/rt-addr.yaml +++ b/Documentation/netlink/specs/rt-addr.yaml @@ -119,7 +119,7 @@ attribute-sets: type: u32 - name: target-netnsid - type: binary + type: s32 - name: proto type: u8 From 778a262a6c690621a5c37d2a1cebc88e4585a870 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 12 Oct 2026 10:17:03 +0900 Subject: [PATCH 2067/2126] net: change netdev_hw_addr_list count through helpers The count of a netdev_hw_addr_list is changed in several places of dev_addr_lists.c and a few drivers read it directly. The next patch needs to account every change of the count of dev->mc. Add __hw_addr_count_add(), __hw_addr_count_inc(), __hw_addr_count_dec() and __hw_addr_count_reset(), use them for every change of the count and rename the field to _count so that a direct write stands out. Readers keep using netdev_hw_addr_list_count() and the netdev_uc_count() and netdev_mc_count() helpers, the few that read the field directly are converted. No functional change. Signed-off-by: Yuyang Huang Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20261012011707.3378-3-sigefriedhyy@gmail.com Signed-off-by: Paolo Abeni --- .../net/ethernet/cavium/octeon/octeon_mgmt.c | 4 +- .../net/wireless/microchip/wilc1000/netdev.c | 8 ++-- include/linux/netdevice.h | 7 ++- net/core/dev_addr_lists.c | 44 ++++++++++++++----- net/core/dev_addr_lists_test.c | 18 ++++---- net/mac80211/driver-ops.h | 2 +- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c b/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c index 2cf3365b9636..bb72c0833721 100644 --- a/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c +++ b/drivers/net/ethernet/cavium/octeon/octeon_mgmt.c @@ -573,14 +573,14 @@ static void octeon_mgmt_set_rx_filtering(struct net_device *netdev) memset(&cam_state, 0, sizeof(cam_state)); - if ((netdev->flags & IFF_PROMISC) || netdev->uc.count > 7) { + if ((netdev->flags & IFF_PROMISC) || netdev_uc_count(netdev) > 7) { cam_mode = 0; available_cam_entries = 8; } else { /* One CAM entry for the primary address, leaves seven * for the secondary addresses. */ - available_cam_entries = 7 - netdev->uc.count; + available_cam_entries = 7 - netdev_uc_count(netdev); } if (netdev->flags & IFF_MULTICAST) { diff --git a/drivers/net/wireless/microchip/wilc1000/netdev.c b/drivers/net/wireless/microchip/wilc1000/netdev.c index 956cb578bf37..d3343113cea5 100644 --- a/drivers/net/wireless/microchip/wilc1000/netdev.c +++ b/drivers/net/wireless/microchip/wilc1000/netdev.c @@ -704,17 +704,17 @@ static void wilc_set_multicast_list(struct net_device *dev) return; if (dev->flags & IFF_ALLMULTI || - dev->mc.count > WILC_MULTICAST_TABLE_SIZE) { + netdev_mc_count(dev) > WILC_MULTICAST_TABLE_SIZE) { wilc_setup_multicast_filter(vif, 0, 0, NULL); return; } - if (dev->mc.count == 0) { + if (netdev_mc_empty(dev)) { wilc_setup_multicast_filter(vif, 1, 0, NULL); return; } - mc_list = kmalloc_array(dev->mc.count, ETH_ALEN, GFP_ATOMIC); + mc_list = kmalloc_array(netdev_mc_count(dev), ETH_ALEN, GFP_ATOMIC); if (!mc_list) return; @@ -727,7 +727,7 @@ static void wilc_set_multicast_list(struct net_device *dev) cur_mc += ETH_ALEN; } - if (wilc_setup_multicast_filter(vif, 1, dev->mc.count, mc_list)) + if (wilc_setup_multicast_filter(vif, 1, netdev_mc_count(dev), mc_list)) kfree(mc_list); } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 53d5e9c9a674..cf25c16bdba8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -252,13 +252,16 @@ struct netdev_hw_addr { struct netdev_hw_addr_list { struct list_head list; - int count; + /* Only changed through the __hw_addr_count_* helpers after + * __hw_addr_init() + */ + int _count; /* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; }; -#define netdev_hw_addr_list_count(l) ((l)->count) +#define netdev_hw_addr_list_count(l) ((l)->_count) #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0) #define netdev_hw_addr_list_for_each(ha, l) \ list_for_each_entry(ha, &(l)->list, list) diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c index 08528ca0a8b3..d615192d1c3b 100644 --- a/net/core/dev_addr_lists.c +++ b/net/core/dev_addr_lists.c @@ -16,6 +16,26 @@ #include "dev.h" +static void __hw_addr_count_add(struct netdev_hw_addr_list *list, int value) +{ + list->_count += value; +} + +static void __hw_addr_count_inc(struct netdev_hw_addr_list *list) +{ + __hw_addr_count_add(list, 1); +} + +static void __hw_addr_count_dec(struct netdev_hw_addr_list *list) +{ + __hw_addr_count_add(list, -1); +} + +static void __hw_addr_count_reset(struct netdev_hw_addr_list *list) +{ + list->_count = 0; +} + /* * General list handling functions */ @@ -125,7 +145,7 @@ static int __hw_addr_add_ex(struct netdev_hw_addr_list *list, rb_insert_color(&ha->node, &list->tree); list_add_tail_rcu(&ha->list, &list->list); - list->count++; + __hw_addr_count_inc(list); return 0; } @@ -161,7 +181,7 @@ static int __hw_addr_del_entry(struct netdev_hw_addr_list *list, list_del_rcu(&ha->list); kfree_rcu(ha, rcu_head); - list->count--; + __hw_addr_count_dec(list); return 0; } @@ -492,14 +512,14 @@ void __hw_addr_flush(struct netdev_hw_addr_list *list) list_del_rcu(&ha->list); kfree_rcu(ha, rcu_head); } - list->count = 0; + __hw_addr_count_reset(list); } EXPORT_SYMBOL_IF_KUNIT(__hw_addr_flush); void __hw_addr_init(struct netdev_hw_addr_list *list) { INIT_LIST_HEAD(&list->list); - list->count = 0; + list->_count = 0; list->tree = RB_ROOT; } EXPORT_SYMBOL(__hw_addr_init); @@ -509,8 +529,8 @@ static void __hw_addr_splice(struct netdev_hw_addr_list *dst, { src->tree = RB_ROOT; list_splice_init(&src->list, &dst->list); - dst->count += src->count; - src->count = 0; + __hw_addr_count_add(dst, netdev_hw_addr_list_count(src)); + __hw_addr_count_reset(src); } /** @@ -532,11 +552,11 @@ int __hw_addr_list_snapshot(struct netdev_hw_addr_list *snap, struct netdev_hw_addr *ha, *entry; list_for_each_entry(ha, &list->list, list) { - if (cache->count) { + if (netdev_hw_addr_list_count(cache)) { entry = list_first_entry(&cache->list, struct netdev_hw_addr, list); list_del(&entry->list); - cache->count--; + __hw_addr_count_dec(cache); memcpy(entry->addr, ha->addr, addr_len); entry->type = ha->type; entry->global_use = false; @@ -554,7 +574,7 @@ int __hw_addr_list_snapshot(struct netdev_hw_addr_list *snap, list_add_tail(&entry->list, &snap->list); __hw_addr_insert(snap, entry, addr_len); - snap->count++; + __hw_addr_count_inc(snap); } return 0; @@ -604,14 +624,14 @@ void __hw_addr_list_reconcile(struct netdev_hw_addr_list *real_list, if (delta > 0) { rb_erase(&ref_ha->node, &ref->tree); list_del(&ref_ha->list); - ref->count--; + __hw_addr_count_dec(ref); ref_ha->sync_cnt = delta; ref_ha->refcount = delta; list_add_tail_rcu(&ref_ha->list, &real_list->list); __hw_addr_insert(real_list, ref_ha, addr_len); - real_list->count++; + __hw_addr_count_inc(real_list); } continue; } @@ -622,7 +642,7 @@ void __hw_addr_list_reconcile(struct netdev_hw_addr_list *real_list, rb_erase(&real_ha->node, &real_list->tree); list_del_rcu(&real_ha->list); kfree_rcu(real_ha, rcu_head); - real_list->count--; + __hw_addr_count_dec(real_list); } } diff --git a/net/core/dev_addr_lists_test.c b/net/core/dev_addr_lists_test.c index 260e71a2399f..07c35a0af2b4 100644 --- a/net/core/dev_addr_lists_test.c +++ b/net/core/dev_addr_lists_test.c @@ -291,7 +291,7 @@ static void dev_addr_test_snapshot_sync(struct kunit *test) netif_addr_unlock_bh(netdev); /* Real entry should now reflect the sync: sync_cnt=1, refcount=2 */ - KUNIT_EXPECT_EQ(test, 1, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 1, netdev_uc_count(netdev)); ha = list_first_entry(&netdev->uc.list, struct netdev_hw_addr, list); KUNIT_EXPECT_MEMEQ(test, ha->addr, addr, ETH_ALEN); KUNIT_EXPECT_EQ(test, 1, ha->sync_cnt); @@ -303,7 +303,7 @@ static void dev_addr_test_snapshot_sync(struct kunit *test) dev_addr_test_unsync); KUNIT_EXPECT_EQ(test, 0, datp->addr_synced); KUNIT_EXPECT_EQ(test, 0, datp->addr_unsynced); - KUNIT_EXPECT_EQ(test, 1, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 1, netdev_uc_count(netdev)); __hw_addr_flush(&cache); rtnl_unlock(); @@ -351,7 +351,7 @@ static void dev_addr_test_snapshot_remove_during_sync(struct kunit *test) /* Concurrent removal: user deletes ADDR_A while driver was working */ memset(addr, ADDR_A, sizeof(addr)); KUNIT_EXPECT_EQ(test, 0, dev_uc_del(netdev, addr)); - KUNIT_EXPECT_EQ(test, 0, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 0, netdev_uc_count(netdev)); /* Reconcile: ADDR_A gone from real list but driver synced it, * so it gets re-inserted as stale (sync_cnt=1, refcount=1). @@ -361,7 +361,7 @@ static void dev_addr_test_snapshot_remove_during_sync(struct kunit *test) &cache); netif_addr_unlock_bh(netdev); - KUNIT_EXPECT_EQ(test, 1, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 1, netdev_uc_count(netdev)); ha = list_first_entry(&netdev->uc.list, struct netdev_hw_addr, list); KUNIT_EXPECT_MEMEQ(test, ha->addr, addr, ETH_ALEN); KUNIT_EXPECT_EQ(test, 1, ha->sync_cnt); @@ -373,7 +373,7 @@ static void dev_addr_test_snapshot_remove_during_sync(struct kunit *test) dev_addr_test_unsync); KUNIT_EXPECT_EQ(test, 0, datp->addr_synced); KUNIT_EXPECT_EQ(test, 1 << ADDR_A, datp->addr_unsynced); - KUNIT_EXPECT_EQ(test, 0, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 0, netdev_uc_count(netdev)); __hw_addr_flush(&cache); rtnl_unlock(); @@ -433,7 +433,7 @@ static void dev_addr_test_snapshot_readd_during_unsync(struct kunit *test) * stale entry and bumps refcount from 1 -> 2. sync_cnt stays 1. */ KUNIT_EXPECT_EQ(test, 0, dev_uc_add(netdev, addr)); - KUNIT_EXPECT_EQ(test, 1, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 1, netdev_uc_count(netdev)); /* Reconcile: ref sync_cnt=1 matches real sync_cnt=1, delta=-1 * applied. Result: sync_cnt=0, refcount=1 (fresh). @@ -444,7 +444,7 @@ static void dev_addr_test_snapshot_readd_during_unsync(struct kunit *test) netif_addr_unlock_bh(netdev); /* Entry survives as fresh: needs re-sync to HW */ - KUNIT_EXPECT_EQ(test, 1, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 1, netdev_uc_count(netdev)); ha = list_first_entry(&netdev->uc.list, struct netdev_hw_addr, list); KUNIT_EXPECT_MEMEQ(test, ha->addr, addr, ETH_ALEN); KUNIT_EXPECT_EQ(test, 0, ha->sync_cnt); @@ -528,7 +528,7 @@ static void dev_addr_test_snapshot_add_and_remove(struct kunit *test) * ADDR_B: refcount went from 2->1 via dev_uc_del (still present, stale) * ADDR_C: sync propagated (sync_cnt=1, refcount=2) */ - KUNIT_EXPECT_EQ(test, 3, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 3, netdev_uc_count(netdev)); netdev_hw_addr_list_for_each(ha, &netdev->uc) { u8 id = ha->addr[0]; @@ -553,7 +553,7 @@ static void dev_addr_test_snapshot_add_and_remove(struct kunit *test) dev_addr_test_unsync); KUNIT_EXPECT_EQ(test, 0, datp->addr_synced); KUNIT_EXPECT_EQ(test, 1 << ADDR_B, datp->addr_unsynced); - KUNIT_EXPECT_EQ(test, 2, netdev->uc.count); + KUNIT_EXPECT_EQ(test, 2, netdev_uc_count(netdev)); __hw_addr_flush(&cache); rtnl_unlock(); diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index 83dd15f2daf6..9aefa55cbdfd 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h @@ -187,7 +187,7 @@ static inline u64 drv_prepare_multicast(struct ieee80211_local *local, { u64 ret = 0; - trace_drv_prepare_multicast(local, mc_list->count); + trace_drv_prepare_multicast(local, netdev_hw_addr_list_count(mc_list)); if (local->ops->prepare_multicast) ret = local->ops->prepare_multicast(&local->hw, mc_list); From 646cb8868bd29646b79e11fc0d574b8e25801a23 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 12 Oct 2026 10:17:04 +0900 Subject: [PATCH 2068/2126] net: add a generation counter for dev->mc changes A multi-part RTM_GETMULTICAST dump of dev->mc resumes by position, so entries added or removed between two dump rounds can be skipped or repeated. The IPv4 and IPv6 dumps report that with NLM_F_DUMP_INTR by stamping cb->seq from a per netns generation counter combined with dev_base_seq, see inet_base_seq(). Add the equivalent for the device multicast lists: a per netns counter bumped whenever an entry is added to or removed from any dev->mc. The list helpers do not know which device a list belongs to, so give netdev_hw_addr_list an mc_dev pointer, set for dev->mc only, and bump the counter of dev_net(mc_dev) from the count helpers. That covers the dev_mc_* helpers, both lists of a sync, the hardware sync helpers drivers call from their rx mode callbacks or their own workers and the reconciliation after an asynchronous rx mode update. It is atomic since the writers only hold the address lock of their own device. Used by the following patch for the AF_PACKET multicast dump. Signed-off-by: Yuyang Huang Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20261012011707.3378-4-sigefriedhyy@gmail.com Signed-off-by: Paolo Abeni --- include/linux/netdevice.h | 3 +++ include/net/net_namespace.h | 1 + net/core/dev_addr_lists.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index cf25c16bdba8..f52c46e28e3a 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -259,6 +259,9 @@ struct netdev_hw_addr_list { /* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; + + /* Set for dev->mc only, the device the list belongs to */ + struct net_device *mc_dev; }; #define netdev_hw_addr_list_count(l) ((l)->_count) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 46b4c67e2966..c29a22ca178f 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -71,6 +71,7 @@ struct net { spinlock_t rules_mod_lock; unsigned int dev_base_seq; /* protected by rtnl_mutex */ + atomic_t dev_mc_genid; /* dev->mc membership changes */ u32 ifindex; spinlock_t nsid_lock; diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c index d615192d1c3b..3ab053cbf8b9 100644 --- a/net/core/dev_addr_lists.c +++ b/net/core/dev_addr_lists.c @@ -16,9 +16,19 @@ #include "dev.h" +/* RTM_GETMULTICAST dumps use the netns generation counter to detect + * changes of dev->mc between dump rounds. + */ +static void __hw_addr_changed(struct netdev_hw_addr_list *list) +{ + if (list->mc_dev) + atomic_inc(&dev_net(list->mc_dev)->dev_mc_genid); +} + static void __hw_addr_count_add(struct netdev_hw_addr_list *list, int value) { list->_count += value; + __hw_addr_changed(list); } static void __hw_addr_count_inc(struct netdev_hw_addr_list *list) @@ -33,7 +43,10 @@ static void __hw_addr_count_dec(struct netdev_hw_addr_list *list) static void __hw_addr_count_reset(struct netdev_hw_addr_list *list) { + if (!list->_count) + return; list->_count = 0; + __hw_addr_changed(list); } /* @@ -521,6 +534,7 @@ void __hw_addr_init(struct netdev_hw_addr_list *list) INIT_LIST_HEAD(&list->list); list->_count = 0; list->tree = RB_ROOT; + list->mc_dev = NULL; } EXPORT_SYMBOL(__hw_addr_init); @@ -1197,6 +1211,7 @@ EXPORT_SYMBOL(dev_mc_flush); void dev_mc_init(struct net_device *dev) { __hw_addr_init(&dev->mc); + dev->mc.mc_dev = dev; } EXPORT_SYMBOL(dev_mc_init); From ebff14be20c3f2c0fbfa2da3321e3043a0ff8650 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 12 Oct 2026 10:17:05 +0900 Subject: [PATCH 2069/2126] net: add AF_PACKET multicast dumps RTM_GETMULTICAST dumps IPv4 and IPv6 multicast group memberships, but the device multicast list (dev->mc) is only available through /proc/net/dev_mcast, so "ip maddr show" still has to parse procfs for its link-layer entries. Handle RTM_GETMULTICAST dumps with ifa_family set to AF_PACKET next to the dev->mc helpers in dev_addr_lists.c and report every entry of dev->mc in the existing ifaddrmsg format: - IFA_MULTICAST carries the raw link-layer address - IFA_MC_USERS carries the entry reference count - IFA_F_GLOBAL in IFA_FLAGS reports netdev_hw_addr::global_use, set by dev_mc_add_global() (SIOCADDMULTI) and dev_mc_add_excl() ("bridge fdb add ... self"), i.e. entries added explicitly rather than by a protocol join. This is the static column of /proc/net/dev_mcast - ifa_scope is RT_SCOPE_LINK This covers every column of /proc/net/dev_mcast. AF_PACKET is the family iproute2 already uses for link-layer addresses ("ip -0"). The default FDB dump also walks dev->mc, but only for Ethernet devices and only if the driver uses it, vxlan for example does not, and it has no users count or global_use bit. Extending it would change "bridge fdb show" output and add NDA_* attributes. Requests are always validated, there are no legacy users: prefixlen, flags and scope must be zero, ifa_index selects one device and IFA_TARGET_NETNSID is the only attribute accepted. The dump runs under RCU and netif_addr_lock_bh() without RTNL. cb->seq is set from the dev->mc generation counter and dev_base_seq before each round and checked after it, so an entry added or removed since the previous round sets NLM_F_DUMP_INTR. A round without a message skips the check and cb->seq is set once more after the round, so the NLMSG_DONE check reports a change made during the last round or before an empty one. Signed-off-by: Yuyang Huang Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20261012011707.3378-5-sigefriedhyy@gmail.com Signed-off-by: Paolo Abeni --- include/linux/netdevice.h | 1 + include/uapi/linux/if_addr.h | 1 + net/core/dev_addr_lists.c | 192 +++++++++++++++++++++++++++++++++++ net/core/rtnetlink.c | 2 + 4 files changed, 196 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f52c46e28e3a..79f9ee0cf799 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5181,6 +5181,7 @@ int dev_mc_sync_multiple(struct net_device *to, struct net_device *from); void dev_mc_unsync(struct net_device *to, struct net_device *from); void dev_mc_flush(struct net_device *dev); void dev_mc_init(struct net_device *dev); +int dev_mc_dump(struct sk_buff *skb, struct netlink_callback *cb); /** * __dev_mc_sync - Synchronize device's multicast list diff --git a/include/uapi/linux/if_addr.h b/include/uapi/linux/if_addr.h index 7fb630b7fe31..0a1ad9ebb47b 100644 --- a/include/uapi/linux/if_addr.h +++ b/include/uapi/linux/if_addr.h @@ -57,6 +57,7 @@ enum { #define IFA_F_NOPREFIXROUTE 0x200 #define IFA_F_MCAUTOJOIN 0x400 #define IFA_F_STABLE_PRIVACY 0x800 +#define IFA_F_GLOBAL 0x1000 struct ifa_cacheinfo { __u32 ifa_prefered; diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c index 3ab053cbf8b9..d827cc21867b 100644 --- a/net/core/dev_addr_lists.c +++ b/net/core/dev_addr_lists.c @@ -10,8 +10,12 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include "dev.h" @@ -1215,6 +1219,194 @@ void dev_mc_init(struct net_device *dev) } EXPORT_SYMBOL(dev_mc_init); +static int dev_mc_fill_addr(struct sk_buff *skb, const struct net_device *dev, + const struct netdev_hw_addr *ha, u32 portid, + u32 seq, unsigned int flags, int netnsid) +{ + struct ifaddrmsg *ifm; + struct nlmsghdr *nlh; + + nlh = nlmsg_put(skb, portid, seq, RTM_GETMULTICAST, sizeof(*ifm), + flags); + if (!nlh) + return -EMSGSIZE; + + ifm = nlmsg_data(nlh); + ifm->ifa_family = AF_PACKET; + ifm->ifa_prefixlen = 0; + ifm->ifa_flags = 0; + ifm->ifa_scope = RT_SCOPE_LINK; + ifm->ifa_index = dev->ifindex; + + if ((netnsid >= 0 && + nla_put_s32(skb, IFA_TARGET_NETNSID, netnsid)) || + nla_put(skb, IFA_MULTICAST, dev->addr_len, ha->addr) || + nla_put_u32(skb, IFA_MC_USERS, ha->refcount) || + nla_put_u32(skb, IFA_FLAGS, ha->global_use ? IFA_F_GLOBAL : 0)) { + nlmsg_cancel(skb, nlh); + return -EMSGSIZE; + } + + nlmsg_end(skb, nlh); + return 0; +} + +/* Combine dev_mc_genid and dev_base_seq to detect changes, like + * inet_base_seq(). + */ +static u32 dev_mc_base_seq(const struct net *net) +{ + u32 res = atomic_read(&net->dev_mc_genid) + + READ_ONCE(net->dev_base_seq); + + /* Must not return 0 (see nl_dump_check_consistent()). */ + if (!res) + res = 0x80000000; + return res; +} + +static int dev_mc_dump_dev(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb, int *s_addr_idx, + unsigned int flags, int netnsid) +{ + struct netdev_hw_addr *ha; + int addr_idx = 0; + int err = 0; + + netif_addr_lock_bh(dev); + netdev_for_each_mc_addr(ha, dev) { + if (addr_idx < *s_addr_idx) { + addr_idx++; + continue; + } + err = dev_mc_fill_addr(skb, dev, ha, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, flags, netnsid); + if (err < 0) + break; + addr_idx++; + } + netif_addr_unlock_bh(dev); + + *s_addr_idx = err < 0 ? addr_idx : 0; + + return err; +} + +struct dev_mc_dump_filter { + struct net *tgt_net; + netns_tracker ns_tracker; + int netnsid; + int ifindex; +}; + +static const struct nla_policy dev_mc_dump_policy[IFA_MAX + 1] = { + [IFA_TARGET_NETNSID] = { .type = NLA_S32 }, +}; + +static int dev_mc_valid_dump_req(const struct nlmsghdr *nlh, struct sock *sk, + struct dev_mc_dump_filter *filter, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[IFA_MAX + 1]; + struct ifaddrmsg *ifm; + int err; + + ifm = nlmsg_payload(nlh, sizeof(*ifm)); + if (!ifm) { + NL_SET_ERR_MSG(extack, + "Invalid header for multicast dump request"); + return -EINVAL; + } + + if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { + NL_SET_ERR_MSG(extack, + "Invalid values in multicast dump header"); + return -EINVAL; + } + + err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, + dev_mc_dump_policy, extack); + if (err < 0) + return err; + + if (tb[IFA_TARGET_NETNSID]) { + struct net *net; + + filter->netnsid = nla_get_s32(tb[IFA_TARGET_NETNSID]); + net = rtnl_get_net_ns_capable(sk, filter->netnsid); + if (IS_ERR(net)) { + NL_SET_ERR_MSG(extack, + "Invalid target network namespace id"); + return PTR_ERR(net); + } + netns_tracker_alloc(net, &filter->ns_tracker, GFP_KERNEL); + filter->tgt_net = net; + } + + filter->ifindex = ifm->ifa_index; + + return 0; +} + +int dev_mc_dump(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct dev_mc_dump_filter filter = { + .tgt_net = sock_net(skb->sk), + .netnsid = -1, + }; + unsigned int flags = NLM_F_MULTI; + struct { + unsigned long ifindex; + int addr_idx; + } *ctx = (void *)cb->ctx; + unsigned long s_ifindex; + struct net_device *dev; + int err; + + err = dev_mc_valid_dump_req(cb->nlh, skb->sk, &filter, cb->extack); + if (err < 0) + return err; + + rcu_read_lock(); + + cb->seq = dev_mc_base_seq(filter.tgt_net); + if (filter.ifindex) { + cb->answer_flags |= NLM_F_DUMP_FILTERED; + flags |= NLM_F_DUMP_FILTERED; + dev = dev_get_by_index_rcu(filter.tgt_net, filter.ifindex); + if (dev) + err = dev_mc_dump_dev(dev, skb, cb, &ctx->addr_idx, + flags, filter.netnsid); + else + err = -ENODEV; + } else { + s_ifindex = ctx->ifindex; + for_each_netdev_dump(filter.tgt_net, dev, ctx->ifindex) { + /* The device the dump stopped at is gone, do not + * skip entries of the next one. + */ + if (dev->ifindex != s_ifindex) + ctx->addr_idx = 0; + err = dev_mc_dump_dev(dev, skb, cb, &ctx->addr_idx, + flags, filter.netnsid); + if (err < 0) + break; + } + } + /* A round without a message has nothing to flag, the NLMSG_DONE + * check then compares against the previous round. + */ + if (skb->len) + nl_dump_check_consistent(cb, nlmsg_hdr(skb)); + /* Let the NLMSG_DONE check see changes made during the last round */ + cb->seq = dev_mc_base_seq(filter.tgt_net); + + rcu_read_unlock(); + if (filter.netnsid >= 0) + put_net_track(filter.tgt_net, &filter.ns_tracker); + return err; +} + static int netif_addr_lists_snapshot(struct net_device *dev, struct netdev_hw_addr_list *uc_snap, struct netdev_hw_addr_list *mc_snap, diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index d73dbc2c8ba0..e141340172ce 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -7288,6 +7288,8 @@ static const struct rtnl_msg_handler rtnetlink_rtnl_msg_handlers[] __initconst = {.msgtype = RTM_SETSTATS, .doit = rtnl_stats_set}, {.msgtype = RTM_NEWLINKPROP, .doit = rtnl_newlinkprop}, {.msgtype = RTM_DELLINKPROP, .doit = rtnl_dellinkprop}, + {.protocol = PF_PACKET, .msgtype = RTM_GETMULTICAST, + .dumpit = dev_mc_dump, .flags = RTNL_FLAG_DUMP_UNLOCKED}, {.protocol = PF_BRIDGE, .msgtype = RTM_GETLINK, .dumpit = rtnl_bridge_getlink}, {.protocol = PF_BRIDGE, .msgtype = RTM_DELLINK, From 48191155c538b797765d0e4ec02e4feb542d9ef6 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 12 Oct 2026 10:17:06 +0900 Subject: [PATCH 2070/2126] netlink: specs: rt-addr: document AF_PACKET multicast dumps Add the global flag, list the attributes the AF_PACKET dump uses and describe how ifa-family selects IPv4, IPv6 or link-layer output for RTM_GETMULTICAST. Signed-off-by: Yuyang Huang Reviewed-by: Nicolas Dichtel Link: https://patch.msgid.link/20261012011707.3378-6-sigefriedhyy@gmail.com Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/rt-addr.yaml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/netlink/specs/rt-addr.yaml b/Documentation/netlink/specs/rt-addr.yaml index 17ead2203451..cccfccf49cc1 100644 --- a/Documentation/netlink/specs/rt-addr.yaml +++ b/Documentation/netlink/specs/rt-addr.yaml @@ -77,6 +77,8 @@ definitions: name: mcautojoin - name: stable-privacy + - + name: global attribute-sets: - @@ -168,7 +170,17 @@ operations: attributes: *ifaddr-all - name: getmulticast - doc: Get / dump IPv4/IPv6 multicast addresses. + doc: | + Get / dump multicast addresses. ifa-family must select the address + family: AF_INET or AF_INET6 for the IP multicast groups joined on + a device, AF_PACKET for the link-layer multicast addresses in the + device filter. Link-layer entries added explicitly, e.g. with + SIOCADDMULTI or "bridge fdb add ... self", rather than by a + protocol join are reported with the global flag set. For AF_PACKET + a non-zero ifa-index restricts the dump to that device and + ifa-prefixlen, ifa-flags and ifa-scope must be zero, AF_INET and + AF_INET6 apply this and target-netnsid with NETLINK_GET_STRICT_CHK + only. attribute-set: addr-attrs fixed-header: ifaddrmsg do: @@ -181,10 +193,13 @@ operations: - multicast - mc-users - cacheinfo + - flags + - target-netnsid dump: request: value: 58 - attributes: [] + attributes: + - target-netnsid reply: value: 58 attributes: *mcaddr-attrs From 0e87a4a83e1306b36f1ebd3cc10eaf31476dfe19 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 12 Oct 2026 10:17:07 +0900 Subject: [PATCH 2071/2126] selftests: net: test AF_PACKET multicast dumps Dump the link-layer multicast addresses of a dummy device and verify that ifa_index restricts the dump to that device, that the all-hosts address joined on link up is listed without IFA_F_GLOBAL, that an address added with SIOCADDMULTI is listed with IFA_F_GLOBAL and IFA_MC_USERS, and that IFA_TARGET_NETNSID dumps another netns. Signed-off-by: Yuyang Huang Reviewed-by: Nicolas Dichtel Reviewed-by: Aleksandr Loktionov Link: https://patch.msgid.link/20261012011707.3378-7-sigefriedhyy@gmail.com Signed-off-by: Paolo Abeni --- tools/testing/selftests/net/rtnetlink.py | 73 +++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/rtnetlink.py b/tools/testing/selftests/net/rtnetlink.py index dc8c77db4897..5534ade056a5 100755 --- a/tools/testing/selftests/net/rtnetlink.py +++ b/tools/testing/selftests/net/rtnetlink.py @@ -5,13 +5,18 @@ import socket import struct import time from lib.py import bkg, ip, ksft_exit, ksft_run, ksft_eq, ksft_ge, ksft_true, KsftSkipEx -from lib.py import ksft_not_in, ksft_not_none +from lib.py import ksft_in, ksft_not_in, ksft_not_none from lib.py import CmdExitFailure, NetNS, NetNSEnter, RtnlAddrFamily, RtnlRouteFamily from lib.py import defer IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01' IPV4_TEST_MULTICAST = b'\xef\x01\x01\x01' IPV6_TEST_MULTICAST = bytes.fromhex('ff020000000000000000000000000123') +ETH_ALL_HOSTS_MULTICAST = bytes.fromhex('01005e000001') +ETH_TEST_MULTICAST_STR = '01:00:5e:01:01:01' +ETH_TEST_MULTICAST = bytes.fromhex(ETH_TEST_MULTICAST_STR.replace(':', '')) +ETH_PEER_MULTICAST_STR = '01:00:5e:02:02:02' +ETH_PEER_MULTICAST = bytes.fromhex(ETH_PEER_MULTICAST_STR.replace(':', '')) def _users_for(rtnl: RtnlAddrFamily, family: int, grp: bytes, ifindex: int): @@ -105,6 +110,69 @@ def dump_mcaddr6_check() -> None: s2.close() +def dump_mcaddr_l2_check() -> None: + """ + Verify link-layer multicast addresses in an AF_PACKET RTM_GETMULTICAST + dump: the ifa-index filter, mc-users, the global flag and + target-netnsid. + """ + + with NetNS() as ns, NetNSEnter(str(ns)): + for ifname in ("dummy1", "dummy2"): + ip(f"link add name {ifname} type dummy") + ip(f"link set {ifname} up") + dev_idx = socket.if_nametoindex("dummy1") + ip(f"maddr add {ETH_TEST_MULTICAST_STR} dev dummy1") + + rtnl = RtnlAddrFamily() + defer(rtnl.close) + addresses = rtnl.getmulticast( + {"ifa-family": socket.AF_PACKET, "ifa-index": dev_idx}, + dump=True) + + # dummy2 has entries as well, only dummy1 may be listed + ksft_eq({addr['ifa-index'] for addr in addresses}, {dev_idx}, + "AF_PACKET multicast dump ignored ifa-index filter") + + entries = {addr['multicast']: addr for addr in addresses} + + # Bringing an Ethernet device up joins 224.0.0.1, which maps + # to 01:00:5e:00:00:01 in the device multicast list. + all_hosts = entries.get(ETH_ALL_HOSTS_MULTICAST) + ksft_not_none(all_hosts, + "dummy1 does not have the all-hosts link-layer address") + if all_hosts is not None: + ksft_not_in('global', all_hosts['flags'], + "protocol entry is global") + + static = entries.get(ETH_TEST_MULTICAST) + ksft_not_none(static, "dummy1 does not have the SIOCADDMULTI address") + if static is not None: + ksft_eq(static['mc-users'], 1, + "unexpected mc-users for the SIOCADDMULTI address") + ksft_in('global', static['flags'], + "SIOCADDMULTI entry is not global") + + # target-netnsid dumps another netns, ifa-index is relative to it + with NetNS() as peer: + ip(f"netns set {peer} 5") + ip("link add name dummy3 type dummy", ns=peer) + ip("link set dummy3 up", ns=peer) + ip(f"maddr add {ETH_PEER_MULTICAST_STR} dev dummy3", ns=peer) + peer_idx = ip("link show dummy3", json=True, ns=peer)[0]['ifindex'] + + addresses = rtnl.getmulticast( + {"ifa-family": socket.AF_PACKET, "target-netnsid": 5, + "ifa-index": peer_idx}, dump=True) + ksft_eq({(addr['ifa-index'], addr['target-netnsid']) + for addr in addresses}, {(peer_idx, 5)}, + "target-netnsid did not dump the peer netns") + # dummy1 in this netns can have the same ifindex as dummy3 + ksft_in(ETH_PEER_MULTICAST, + {addr['multicast'] for addr in addresses}, + "target-netnsid did not dump the peer device") + + def ipv4_devconf_notify() -> None: """ Configure an interface and set ipv4-devconf values through netlink @@ -424,7 +492,8 @@ def ipv6_verify_inter_scope_addr_order() -> None: def main() -> None: - ksft_run([dump_mcaddr_check, dump_mcaddr6_check, ipv4_devconf_notify, + ksft_run([dump_mcaddr_check, dump_mcaddr6_check, dump_mcaddr_l2_check, + ipv4_devconf_notify, ipv6_route_del_reason_expired, ipv6_route_del_reason_ra_withdrawn, ipv6_route_del_reason_absent, From 758d8928d2c5d6703da827577cef86d643155236 Mon Sep 17 00:00:00 2001 From: Anil Kaushik Date: Fri, 16 Oct 2026 09:32:22 +0000 Subject: [PATCH 2072/2126] gtp: set a valid genl command in PDP context get and dump replies gtp_genl_fill_info() stamps the reply with the command its callers pass in. gtp_genl_get_pdp() and gtp_genl_dump_pdp() pass nlmsg_type, which in a genl message is the dynamically assigned family id rather than a GTP_CMD_* value, so replies to a PDP context get or dump carry a meaningless command number. libgtpnl ignores the command and is unaffected, but parsers that check it (for example the ynl tooling) treat the reply as an unknown command and discard it. Pass GTP_CMD_GETPDP, as gtp_tunnel_notify() already passes a real command on the notification path. No uapi change. Fixes: 459aa660eb1d ("gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)") Signed-off-by: Anil Kaushik Link: https://patch.msgid.link/20261016093225.1036375-2-anilkaushikwireless@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/gtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 4aff23bcfdd1..99836b773e5c 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -2279,7 +2279,7 @@ static int gtp_genl_get_pdp(struct sk_buff *skb, struct genl_info *info) } err = gtp_genl_fill_info(skb2, NETLINK_CB(skb).portid, info->snd_seq, - 0, info->nlhdr->nlmsg_type, pctx); + 0, GTP_CMD_GETPDP, pctx); if (err < 0) goto err_unlock_free; @@ -2326,7 +2326,7 @@ static int gtp_genl_dump_pdp(struct sk_buff *skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI, - cb->nlh->nlmsg_type, pctx)) { + GTP_CMD_GETPDP, pctx)) { cb->args[0] = i; cb->args[1] = j; cb->args[2] = (unsigned long)gtp; From fe3e1a42fb7eb18d8c55d714b50a3d51f8cd6ffe Mon Sep 17 00:00:00 2001 From: Anil Kaushik Date: Fri, 16 Oct 2026 09:32:23 +0000 Subject: [PATCH 2073/2126] gtp: hold RCU for the device lookup when adding a PDP context gtp_genl_new_pdp() calls gtp_find_dev(), which looks the device up with dev_get_by_index_rcu(). Since commit e2d1baca2b33 ("gtp: remove useless rcu_read_lock()"), this only runs under the rtnl lock, and kernels with CONFIG_PROVE_RCU_LIST warn: WARNING: suspicious RCU usage net/core/dev.c:1047 RCU-list traversed in non-reader section!! ... dev_get_by_index_rcu gtp_find_dev gtp_genl_new_pdp Hold the RCU read lock around the lookup only: gtp_pdp_add() allocates with GFP_KERNEL, and the rtnl lock keeps the device alive afterwards. Found with the gtp selftest on a debug kernel. Fixes: e2d1baca2b33 ("gtp: remove useless rcu_read_lock()") Signed-off-by: Anil Kaushik Link: https://patch.msgid.link/20261016093225.1036375-3-anilkaushikwireless@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/gtp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 99836b773e5c..15b5d845fc3b 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -2050,7 +2050,10 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info) rtnl_lock(); + /* the rtnl lock keeps the device alive once found */ + rcu_read_lock(); gtp = gtp_find_dev(sock_net(skb->sk), info->attrs); + rcu_read_unlock(); if (!gtp) { err = -ENODEV; goto out_unlock; From 8a2f9964fc28954cef5a39e3636690d83cff3951 Mon Sep 17 00:00:00 2001 From: Anil Kaushik Date: Fri, 16 Oct 2026 09:32:24 +0000 Subject: [PATCH 2074/2126] netlink: specs: add genetlink-legacy spec for GTP The GTP (GPRS Tunnelling Protocol, user plane) generic netlink family has no YAML specification under Documentation/netlink/specs/, so it cannot be consumed by the ynl tooling used for user-space clients, documentation and selftests. Add a genetlink-legacy spec describing the existing family: the PDP context management commands (NEWPDP, DELPDP, GETPDP) and the GTP-U echo request (ECHOREQ), the GTPA_* attribute set, and the "gtp" multicast group. Command and attribute values are taken from include/uapi/linux/gtp.h and match it one-to-one. The request attributes of each command are the ones its handler in drivers/net/gtp.c reads, and the reply attributes the ones gtp_genl_fill_info() emits. The notifications sent on the "gtp" group are not described: they reuse the command values of the NEWPDP, DELPDP and ECHOREQ requests, which the ynl code generator cannot express with the existing uapi header. The family doc says so. Add the matching CFLAGS_gtp entry to tools/net/ynl/Makefile.deps, so the generated code is built against the tree's gtp.h instead of an older one installed on the host. This only adds the description; there is no kernel code or uapi change. Signed-off-by: Anil Kaushik Link: https://patch.msgid.link/20261016093225.1036375-4-anilkaushikwireless@gmail.com Signed-off-by: Paolo Abeni --- Documentation/netlink/specs/gtp.yaml | 196 +++++++++++++++++++++++++++ MAINTAINERS | 1 + tools/net/ynl/Makefile.deps | 1 + 3 files changed, 198 insertions(+) create mode 100644 Documentation/netlink/specs/gtp.yaml diff --git a/Documentation/netlink/specs/gtp.yaml b/Documentation/netlink/specs/gtp.yaml new file mode 100644 index 000000000000..7871f5def054 --- /dev/null +++ b/Documentation/netlink/specs/gtp.yaml @@ -0,0 +1,196 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +--- +name: gtp + +protocol: genetlink-legacy + +doc: | + GPRS Tunnelling Protocol, user plane (GTP-U). + + The gtp netdevice encapsulates and decapsulates user plane packets in + GTP-U tunnels (GTPv0 and GTPv1-U, see 3GPP TS 29.060 and TS 29.281). + This family manages the PDP contexts that describe the tunnels and + triggers GTP-U echo requests. It is driven by user space control planes + such as those built on libgtpnl. + + The kernel registers the family with version 0, which the + genetlink-legacy schema cannot express. + + The notifications multicast on the "gtp" group are not described: PDP + context additions and deletions, and GTP-U echo responses, reuse the + NEWPDP, DELPDP and ECHOREQ command values of the requests. + +kernel-policy: global + +definitions: + - + type: enum + name: version + name-prefix: gtp- + enum-name: gtp-version + header: linux/gtp.h + entries: [v0, v1] + +attribute-sets: + - + name: gtp + name-prefix: gtpa- + attributes: + - + name: link + type: u32 + doc: ifindex of the gtp netdevice the context is attached to. + - + name: version + type: u32 + enum: version + doc: GTP version of the context, GTPv0 or GTPv1-U. + - + name: tid + type: u64 + doc: Tunnel identifier, GTPv0 only. + - + name: peer-address + type: u32 + byte-order: big-endian + display-hint: ipv4 + doc: | + IPv4 address of the remote GSN peer (GGSN or SGSN). Also known + as GTPA_SGSN_ADDRESS, kept for legacy user space. + - + name: ms-address + type: u32 + byte-order: big-endian + display-hint: ipv4 + doc: IPv4 address of the mobile subscriber served by the context. + - + name: flow + type: u16 + doc: Flow label, GTPv0 only. + - + name: net-ns-fd + type: u32 + doc: File descriptor of the network namespace of the gtp netdevice. + - + name: i-tei + type: u32 + doc: Ingress Tunnel Endpoint Identifier, GTPv1-U only. + - + name: o-tei + type: u32 + doc: Egress Tunnel Endpoint Identifier, GTPv1-U only. + - + name: pad + type: pad + - + name: peer-addr6 + type: binary + checks: + min-len: 16 + byte-order: big-endian + display-hint: ipv6 + doc: IPv6 address of the remote GSN peer (GGSN or SGSN). + - + name: ms-addr6 + type: binary + checks: + min-len: 16 + byte-order: big-endian + display-hint: ipv6 + doc: | + IPv6 prefix of the mobile subscriber served by the context: a /64 + prefix, with the lower 64 bits set to zero. + - + name: family + type: u8 + doc: | + Address family (AF_INET or AF_INET6) of ms-address or ms-addr6, + AF_INET when absent. The peer address uses the family of the + tunnel socket. + +operations: + list: + - + name: newpdp + doc: Create or update a PDP context. + attribute-set: gtp + value: 0 + dont-validate: [strict, dump] + flags: [admin-perm] + do: + request: &pdp-attrs + attributes: + - link + - version + - tid + - peer-address + - peer-addr6 + - ms-address + - ms-addr6 + - flow + - i-tei + - o-tei + - family + - net-ns-fd + - + name: delpdp + doc: Delete a PDP context. + attribute-set: gtp + dont-validate: [strict, dump] + flags: [admin-perm] + do: + request: &pdp-find + attributes: + - link + - version + - tid + - ms-address + - ms-addr6 + - i-tei + - family + - net-ns-fd + - + name: getpdp + doc: Get or dump one or more PDP contexts. + attribute-set: gtp + dont-validate: [strict, dump] + flags: [admin-perm] + do: + request: *pdp-find + reply: &pdp-reply + attributes: + - link + - version + - tid + - peer-address + - peer-addr6 + - ms-address + - ms-addr6 + - flow + - i-tei + - o-tei + - family + dump: + reply: *pdp-reply + - + name: echoreq + doc: | + Send a GTP-U echo request to a peer. ms-address is not a mobile + subscriber address here, but the local IPv4 address used as source + of the request. + attribute-set: gtp + dont-validate: [strict, dump] + flags: [admin-perm] + do: + request: + attributes: + - link + - version + - peer-address + - ms-address + - net-ns-fd + +mcast-groups: + list: + - + name: gtp diff --git a/MAINTAINERS b/MAINTAINERS index 2b07bf0fd980..eca83c7da218 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11422,6 +11422,7 @@ M: Harald Welte L: osmocom-net-gprs@lists.osmocom.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/gtp.git +F: Documentation/netlink/specs/gtp.yaml F: drivers/net/gtp.c GUID PARTITION TABLE (GPT) diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps index 9389f3752c00..f8850444d240 100644 --- a/tools/net/ynl/Makefile.deps +++ b/tools/net/ynl/Makefile.deps @@ -24,6 +24,7 @@ CFLAGS_ethtool:=$(call get_hdr_inc,_LINUX_TYPELIMITS_H,typelimits.h) \ $(call get_hdr_inc,_LINUX_ETHTOOL_H,ethtool.h) \ $(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_H_,ethtool_netlink.h) \ $(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_GENERATED_H,ethtool_netlink_generated.h) +CFLAGS_gtp:=$(call get_hdr_inc,_LINUX_GTP_H_,gtp.h) CFLAGS_handshake:=$(call get_hdr_inc,_LINUX_HANDSHAKE_H,handshake.h) CFLAGS_lockd_netlink:=$(call get_hdr_inc,_LINUX_LOCKD_NETLINK_H,lockd_netlink.h) CFLAGS_mptcp_pm:=$(call get_hdr_inc,_LINUX_MPTCP_PM_H,mptcp_pm.h) From ffb51f75013f8d572cc3aa942425e0fa0a8e6d09 Mon Sep 17 00:00:00 2001 From: Anil Kaushik Date: Fri, 16 Oct 2026 09:32:25 +0000 Subject: [PATCH 2075/2126] selftests: net: add a test for the gtp netlink family Exercise the gtp generic netlink family through its ynl spec: create a gtp device, add a PDP context with newpdp, check getpdp dumps it on that device with the expected TEIDs and addresses, and that delpdp by TEI removes it. Two more cases check that two contexts are dumped and one can be deleted by its MS address, and that deleting an unknown context fails with ENOENT, both by TEI and by MS address. ynl resolves the family ids once per process, with a CTRL_CMD_GETFAMILY dump which does not autoload modules, so the gtp device is created before the family handle: that loads gtp.ko through its rtnl link alias. The test is skipped when the kernel or iproute2 lack GTP support; any other failure to create the device fails it. Add a GtpFamily ynl wrapper and register the test. Signed-off-by: Anil Kaushik Link: https://patch.msgid.link/20261016093225.1036375-5-anilkaushikwireless@gmail.com Signed-off-by: Paolo Abeni --- MAINTAINERS | 1 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/gtp.py | 123 ++++++++++++++++++ .../testing/selftests/net/lib/py/__init__.py | 5 +- tools/testing/selftests/net/lib/py/ynl.py | 9 +- 6 files changed, 137 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/net/gtp.py diff --git a/MAINTAINERS b/MAINTAINERS index eca83c7da218..83ff18370ece 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11424,6 +11424,7 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/gtp.git F: Documentation/netlink/specs/gtp.yaml F: drivers/net/gtp.c +F: tools/testing/selftests/net/gtp.py GUID PARTITION TABLE (GPT) M: Davidlohr Bueso diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 54beea2e348c..df5bcc55ea8e 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -46,6 +46,7 @@ TEST_PROGS := \ fq_band_pktlimit.sh \ gre_gso.sh \ gre_ipv6_lladdr.sh \ + gtp.py \ icmp.sh \ icmp_redirect.sh \ io_uring_zerocopy_tx.sh \ diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index d355cf980597..cb8cb4696df7 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -16,6 +16,7 @@ CONFIG_DEBUG_INFO_BTF=y CONFIG_DEBUG_INFO_BTF_MODULES=n CONFIG_DUMMY=y CONFIG_GENEVE=m +CONFIG_GTP=m CONFIG_IFB=y CONFIG_INET_DIAG=y CONFIG_INET_ESP=y diff --git a/tools/testing/selftests/net/gtp.py b/tools/testing/selftests/net/gtp.py new file mode 100755 index 000000000000..d793ca7b70d2 --- /dev/null +++ b/tools/testing/selftests/net/gtp.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +"""Tests for the gtp netlink family.""" + +import errno + +from lib.py import ksft_run, ksft_exit +from lib.py import ksft_eq, ksft_in, ksft_not_in, ksft_raises +from lib.py import KsftSkipEx +from lib.py import NetNS, NetNSEnter +from lib.py import GtpFamily, NlError +from lib.py import CmdExitFailure +from lib.py import ip, defer + +_NO_GTP_ERRORS = ("Unknown device type", "Operation not supported", + "Garbage instead of arguments") + + +def _setup(ns): + """Return a gtp family handle, and the ifindex of a new gtp device. + + Create the device first: that loads gtp.ko through its rtnl link + alias. ynl resolves the family ids once per process, with a + CTRL_CMD_GETFAMILY dump which does not autoload modules, so the + family must be registered before the first family handle is created. + """ + try: + ip("link add gtp0 type gtp role ggsn", ns=str(ns)) + except CmdExitFailure as e: + # gtp.ko not available, or iproute2 without gtp support: any other + # failure to create the device is a real error. + if not any(msg in e.cmd.stderr for msg in _NO_GTP_ERRORS): + raise + raise KsftSkipEx("no gtp support (CONFIG_GTP, iproute2)") from e + defer(ip, "link del gtp0", ns=str(ns)) + ip("link set gtp0 up", ns=str(ns)) + link = ip("-d link show gtp0", ns=str(ns), json=True)[0]["ifindex"] + + with NetNSEnter(str(ns)): + gtp = GtpFamily() + defer(gtp.close) + + return gtp, link + + +def _contexts(gtp, link): + return [c for c in gtp.getpdp({}, dump=True) if c.get("link") == link] + + +def _iteis(contexts): + return [c.get("i-tei") for c in contexts] + + +def add_del_pdp(ns) -> None: + """Add a PDP context, query it, then delete it by TEI. + + The dump must return the context with the link, TEIDs and addresses + it was created with, and it must be gone after the delete. The delete + only identifies the context by its TEI, to use the GTPv1 TEI lookup. + """ + gtp, link = _setup(ns) + + gtp.newpdp({"link": link, "version": 1, + "i-tei": 0x100, "o-tei": 0x200, + "ms-address": "10.0.0.1", "peer-address": "192.0.2.1"}) + + pdp = [c for c in _contexts(gtp, link) if c.get("i-tei") == 0x100] + ksft_eq(len(pdp), 1) + ksft_eq(pdp[0]["o-tei"], 0x200) + ksft_eq(pdp[0]["ms-address"], "10.0.0.1") + ksft_eq(pdp[0]["peer-address"], "192.0.2.1") + + gtp.delpdp({"link": link, "version": 1, "i-tei": 0x100}) + ksft_not_in(0x100, _iteis(_contexts(gtp, link))) + + +def add_two_pdp(ns) -> None: + """Add two PDP contexts, check both are dumped, delete one by address. + + The delete identifies the context by its MS address, and must leave + the other context in place. + """ + gtp, link = _setup(ns) + + for i_tei, o_tei, ms in ((0x111, 0x211, "10.0.1.1"), + (0x112, 0x212, "10.0.1.2")): + gtp.newpdp({"link": link, "version": 1, + "i-tei": i_tei, "o-tei": o_tei, + "ms-address": ms, "peer-address": "192.0.2.5"}) + + iteis = _iteis(_contexts(gtp, link)) + ksft_in(0x111, iteis) + ksft_in(0x112, iteis) + + gtp.delpdp({"link": link, "version": 1, "ms-address": "10.0.1.1"}) + iteis = _iteis(_contexts(gtp, link)) + ksft_not_in(0x111, iteis) + ksft_in(0x112, iteis) + + +def del_unknown_pdp(ns) -> None: + """Deleting a context that was never added must fail with ENOENT. + + Both lookups are checked: by TEI, and by MS address. + """ + gtp, link = _setup(ns) + + for attrs in ({"i-tei": 0x999}, {"ms-address": "10.9.9.9"}): + with ksft_raises(NlError) as cm: + gtp.delpdp({"link": link, "version": 1, **attrs}) + ksft_eq(cm.exception.error, errno.ENOENT) + + +def main() -> None: + """Run the PDP context tests in a temporary netns.""" + with NetNS() as ns: + ksft_run([add_del_pdp, add_two_pdp, del_unknown_pdp], args=(ns,)) + ksft_exit() + + +if __name__ == "__main__": + main() diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py index 71df5880b356..e269a260d58e 100644 --- a/tools/testing/selftests/net/lib/py/__init__.py +++ b/tools/testing/selftests/net/lib/py/__init__.py @@ -18,7 +18,7 @@ from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \ from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from .ynl import NlError, NlctrlFamily, YnlFamily, \ EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily -from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily, Netlink +from .ynl import NetshaperFamily, DevlinkFamily, GtpFamily, PSPFamily, Netlink __all__ = ["KSRC", "KsftFailEx", "KsftSkipEx", "KsftXfailEx", "ksft_pr", "ksft_eq", @@ -32,6 +32,7 @@ __all__ = ["KSRC", "wait_port_listen", "ctl_file_write", "wait_file", "tool", "tc", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "NetdevSim", "NetdevSimDev", - "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError", + "NetshaperFamily", "DevlinkFamily", "GtpFamily", "PSPFamily", + "NlError", "YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily", "NlctrlFamily", "RtnlAddrFamily", "RtnlRouteFamily", "Netlink"] diff --git a/tools/testing/selftests/net/lib/py/ynl.py b/tools/testing/selftests/net/lib/py/ynl.py index 08deff756f29..69a6e9d9b390 100644 --- a/tools/testing/selftests/net/lib/py/ynl.py +++ b/tools/testing/selftests/net/lib/py/ynl.py @@ -31,7 +31,7 @@ __all__ = [ "NlError", "NlPolicy", "Netlink", "YnlFamily", "SPEC_PATH", "EthtoolFamily", "RtnlFamily", "RtnlAddrFamily", "RtnlRouteFamily", "NetdevFamily", "NetshaperFamily", "NlctrlFamily", "DevlinkFamily", - "PSPFamily", + "GtpFamily", "PSPFamily", ] # @@ -85,3 +85,10 @@ class PSPFamily(YnlFamily): def __init__(self, recv_size=0): super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(), schema='', recv_size=recv_size) + + +class GtpFamily(YnlFamily): + """YNL family for gtp, see Documentation/netlink/specs/gtp.yaml.""" + def __init__(self, recv_size=0): + super().__init__((SPEC_PATH / Path('gtp.yaml')).as_posix(), + schema='', recv_size=recv_size) From a006b921ad32940676993bfae460b9f57547b79b Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 16 Oct 2026 14:27:14 +0100 Subject: [PATCH 2076/2126] vsock: move SOL_SOCKET options to vsock_sol_socket_setsockopt() SO_ZEROCOPY is handled inline in vsock_connectible_setsockopt(). Move it to a helper with a switch on optname, so other SOL_SOCKET options can be added as new cases. The value parsing goes to its own helper too, so each option can do its own checks before it. No functional change. Signed-off-by: David Carlier Reviewed-by: Stefano Garzarella Link: https://patch.msgid.link/20261016132716.272018-2-devnexen@gmail.com Signed-off-by: Paolo Abeni --- net/vmw_vsock/af_vsock.c | 94 ++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 483af15a5109..847afbebef01 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -2013,6 +2013,66 @@ static void vsock_update_buffer_size(struct vsock_sock *vsk, vsk->buffer_size = val; } +static bool vsock_sol_socket_custom(int optname) +{ + switch (optname) { + case SO_ZEROCOPY: + return true; + default: + return false; + } +} + +static int vsock_sol_socket_get_bool(sockptr_t optval, unsigned int optlen, + int *val) +{ + /* Use 'int' type here, because variable to set these options usually + * has this type. + */ + if (optlen < sizeof(*val)) + return -EINVAL; + + if (copy_from_sockptr(val, optval, sizeof(*val))) + return -EFAULT; + + if (*val < 0 || *val > 1) + return -EINVAL; + + return 0; +} + +static int vsock_sol_socket_setsockopt(struct sock *sk, int optname, + sockptr_t optval, unsigned int optlen) +{ + struct vsock_sock *vsk = vsock_sk(sk); + int err; + int val; + + lock_sock(sk); + + switch (optname) { + case SO_ZEROCOPY: + err = vsock_sol_socket_get_bool(optval, optlen, &val); + if (err) + break; + + if (vsk->transport && !vsock_msgzerocopy_allow(vsk->transport)) { + err = -EOPNOTSUPP; + break; + } + + sock_valbool_flag(sk, SOCK_ZEROCOPY, val); + break; + + default: + err = -ENOPROTOOPT; + break; + } + + release_sock(sk); + return err; +} + static int vsock_connectible_setsockopt(struct socket *sock, int level, int optname, @@ -2044,37 +2104,17 @@ static int vsock_connectible_setsockopt(struct socket *sock, sk = sock->sk; vsk = vsock_sk(sk); + if (level == SOL_SOCKET) { + if (!vsock_sol_socket_custom(optname)) + return sock_setsockopt(sock, level, optname, optval, optlen); + + return vsock_sol_socket_setsockopt(sk, optname, optval, optlen); + } + lock_sock(sk); transport = vsk->transport; - if (level == SOL_SOCKET) { - int zerocopy; - - if (optname != SO_ZEROCOPY) { - release_sock(sk); - return sock_setsockopt(sock, level, optname, optval, optlen); - } - - /* Use 'int' type here, because variable to - * set this option usually has this type. - */ - COPY_IN(zerocopy); - - if (zerocopy < 0 || zerocopy > 1) { - err = -EINVAL; - goto exit; - } - - if (transport && !vsock_msgzerocopy_allow(transport)) { - err = -EOPNOTSUPP; - goto exit; - } - - sock_valbool_flag(sk, SOCK_ZEROCOPY, zerocopy); - goto exit; - } - switch (optname) { case SO_VM_SOCKETS_BUFFER_SIZE: COPY_IN(val); From d7bb20b91122fd1e8ecbe6ff9fd13b8eefff8240 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 16 Oct 2026 14:27:15 +0100 Subject: [PATCH 2077/2126] vsock: support SO_INQ on stream sockets SO_INQ makes recvmsg() return the bytes left in the receive queue in an SCM_INQ cmsg, saving a SIOCINQ call per receive. AF_UNIX stream sockets support it, AF_VSOCK fails with ENOPROTOOPT. Add it for SOCK_STREAM, reusing the hint already computed for io_uring. As with TCP_INQ, 1 is reported once the stream is finished so the caller reads again and sees EOF, and accepted sockets inherit the setting from the listener. No cmsg is sent when the transport cannot report the queue length. SOCK_SEQPACKET is refused, as on AF_UNIX: its transport callback counts messages, not bytes. Signed-off-by: David Carlier Reviewed-by: Stefano Garzarella Link: https://patch.msgid.link/20261016132716.272018-3-devnexen@gmail.com Signed-off-by: Paolo Abeni --- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 5549298c1ec6..e8481f12312e 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -68,6 +68,7 @@ struct vsock_sock { u64 buffer_size; u64 buffer_min_size; u64 buffer_max_size; + bool recvmsg_inq; /* Private to transport. */ void *trans; diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 847afbebef01..d0508887a2fb 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -984,6 +984,7 @@ static struct sock *__vsock_create(struct net *net, vsk->buffer_size = psk->buffer_size; vsk->buffer_min_size = psk->buffer_min_size; vsk->buffer_max_size = psk->buffer_max_size; + vsk->recvmsg_inq = psk->recvmsg_inq; security_sk_clone(parent, sk); } else { vsk->trusted = ns_capable_noaudit(&init_user_ns, CAP_NET_ADMIN); @@ -2017,6 +2018,7 @@ static bool vsock_sol_socket_custom(int optname) { switch (optname) { case SO_ZEROCOPY: + case SO_INQ: return true; default: return false; @@ -2064,6 +2066,19 @@ static int vsock_sol_socket_setsockopt(struct sock *sk, int optname, sock_valbool_flag(sk, SOCK_ZEROCOPY, val); break; + case SO_INQ: + if (sk->sk_type != SOCK_STREAM) { + err = -ENOPROTOOPT; + break; + } + + err = vsock_sol_socket_get_bool(optval, optlen, &val); + if (err) + break; + + vsk->recvmsg_inq = val; + break; + default: err = -ENOPROTOOPT; break; @@ -2620,6 +2635,7 @@ __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, struct sock *sk; struct vsock_sock *vsk; const struct vsock_transport *transport; + bool do_cmsg = false; int err; sk = sock->sk; @@ -2676,13 +2692,26 @@ __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, err = __vsock_seqpacket_recvmsg(sk, msg, len, flags); out: - /* Seqpacket has_data counts messages, while io_uring treats msg_inq as - * a byte length when sizing retries, so only streams report a hint. + /* Seqpacket has_data counts messages, while SCM_INQ reports bytes and + * io_uring treats msg_inq as a byte length when sizing retries, so + * only streams report it. */ - if (msg->msg_get_inq && err >= 0 && sk->sk_type == SOCK_STREAM) + if ((vsk->recvmsg_inq || msg->msg_get_inq) && err >= 0 && + sk->sk_type == SOCK_STREAM) { msg->msg_inq = vsock_stream_inq_hint(sk); + /* A negative hint means the transport could not tell. SCM_INQ + * has no encoding for that, so report nothing. + */ + do_cmsg = vsk->recvmsg_inq && msg->msg_inq >= 0; + } + release_sock(sk); + + if (do_cmsg) + put_cmsg(msg, SOL_SOCKET, SCM_INQ, sizeof(msg->msg_inq), + &msg->msg_inq); + return err; } From 3079ee3a8c62bb8ae1e9329e2f9e9c77c6b7fe16 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 16 Oct 2026 14:27:16 +0100 Subject: [PATCH 2078/2126] vsock/test: cover SO_INQ Check the SCM_INQ value after a partial receive, after draining the queue and at EOF, that no cmsg is sent while the option is off, that accepted sockets inherit it from the listener, and that out of range values and SOCK_SEQPACKET are rejected. Reviewed-by: Stefano Garzarella Acked-by: Bobby Eshleman Signed-off-by: David Carlier Link: https://patch.msgid.link/20261016132716.272018-4-devnexen@gmail.com Signed-off-by: Paolo Abeni --- tools/testing/vsock/vsock_test.c | 279 +++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index b4ff9f946565..10b9074fb87f 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -2429,6 +2429,271 @@ static void test_stream_collapse_server(const struct test_opts *opts) close(fd); } +#define SO_INQ_BUF_LEN 64 +#define SO_INQ_CHUNK_LEN 16 + +static int so_inq_set(int fd, int val) +{ + return setsockopt(fd, SOL_SOCKET, SO_INQ, &val, sizeof(val)); +} + +/* Receive @len bytes and return the SCM_INQ value, or -1 if the kernel did + * not attach one. + */ +static int so_inq_recv(int fd, size_t len, int expected_ret) +{ + char control[CMSG_SPACE(sizeof(int))] = { 0 }; + unsigned char buf[SO_INQ_BUF_LEN]; + struct iovec iov = { + .iov_base = buf, + .iov_len = len, + }; + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = control, + .msg_controllen = sizeof(control), + }; + struct cmsghdr *cmsg; + ssize_t ret; + int inq; + + ret = recvmsg(fd, &msg, 0); + if (ret < 0) { + perror("recvmsg"); + exit(EXIT_FAILURE); + } + + expect_res(ret, expected_ret, "recvmsg"); + + if (msg.msg_flags & MSG_CTRUNC) { + fprintf(stderr, "SCM_INQ control message truncated\n"); + exit(EXIT_FAILURE); + } + + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_level != SOL_SOCKET || + cmsg->cmsg_type != SCM_INQ) + continue; + + if (cmsg->cmsg_len != CMSG_LEN(sizeof(inq))) { + fprintf(stderr, "unexpected SCM_INQ length %zu\n", + (size_t)cmsg->cmsg_len); + exit(EXIT_FAILURE); + } + + memcpy(&inq, CMSG_DATA(cmsg), sizeof(inq)); + return inq; + } + + return -1; +} + +static void test_stream_so_inq_client(const struct test_opts *opts) +{ + int fd; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + control_expectln("SENT"); + + /* Wait for the whole payload to be queued, so the values below do not + * depend on how the transport delivers it. + */ + if (!vsock_ioctl_int(fd, SIOCINQ, SO_INQ_BUF_LEN)) { + fprintf(stderr, "Test skipped, SIOCINQ not supported.\n"); + goto out; + } + + /* No ancillary data unless the option is enabled. */ + expect_res(so_inq_recv(fd, SO_INQ_CHUNK_LEN, SO_INQ_CHUNK_LEN), -1, + "SCM_INQ with SO_INQ disabled"); + + if (so_inq_set(fd, 1)) { + if (errno != ENOPROTOOPT) { + perror("setsockopt(SO_INQ)"); + exit(EXIT_FAILURE); + } + + fprintf(stderr, "Test skipped, SO_INQ not supported.\n"); + goto out; + } + + /* Partial read: the rest of the payload is still queued. */ + expect_res(so_inq_recv(fd, SO_INQ_CHUNK_LEN, SO_INQ_CHUNK_LEN), + SO_INQ_BUF_LEN - 2 * SO_INQ_CHUNK_LEN, + "SCM_INQ after partial receive"); + + /* Draining read while the peer stays connected. */ + expect_res(so_inq_recv(fd, SO_INQ_BUF_LEN - 2 * SO_INQ_CHUNK_LEN, + SO_INQ_BUF_LEN - 2 * SO_INQ_CHUNK_LEN), 0, + "SCM_INQ after draining receive"); + + control_writeln("DRAINED"); + vsock_wait_remote_close(fd); + + /* Nothing is queued once the peer is gone, but 1 is reported so the + * caller keeps reading until it observes EOF, as TCP_INQ does. + */ + expect_res(so_inq_recv(fd, SO_INQ_CHUNK_LEN, 0), 1, "SCM_INQ at EOF"); + + if (so_inq_set(fd, 0)) { + perror("setsockopt(SO_INQ)"); + exit(EXIT_FAILURE); + } + + expect_res(so_inq_recv(fd, SO_INQ_CHUNK_LEN, 0), -1, + "SCM_INQ after disabling SO_INQ"); + + close(fd); + return; + +out: + control_writeln("DRAINED"); + close(fd); +} + +static void test_stream_so_inq_server(const struct test_opts *opts) +{ + unsigned char buf[SO_INQ_BUF_LEN]; + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + memset(buf, 'A', sizeof(buf)); + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + control_writeln("SENT"); + + /* Keep the connection open until the peer has drained the queue: an + * early close would turn its last SCM_INQ value into the EOF one. + */ + control_expectln("DRAINED"); + close(fd); +} + +static void test_stream_so_inq_inherit_client(const struct test_opts *opts) +{ + unsigned char buf[SO_INQ_BUF_LEN]; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + memset(buf, 'A', sizeof(buf)); + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + control_writeln("SENT"); + + control_expectln("DONE"); + close(fd); +} + +static void test_stream_so_inq_inherit_server(const struct test_opts *opts) +{ + bool supported = true; + int listen_fd, fd; + + listen_fd = vsock_stream_listen(VMADDR_CID_ANY, opts->peer_port); + + /* Enable the option on the listener only. */ + if (so_inq_set(listen_fd, 1)) { + if (errno != ENOPROTOOPT) { + perror("setsockopt(SO_INQ)"); + exit(EXIT_FAILURE); + } + + fprintf(stderr, "Test skipped, SO_INQ not supported.\n"); + supported = false; + } + + control_writeln("LISTENING"); + + timeout_begin(TIMEOUT); + do { + fd = accept(listen_fd, NULL, NULL); + timeout_check("accept"); + } while (fd < 0 && errno == EINTR); + timeout_end(); + + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + close(listen_fd); + control_expectln("SENT"); + + if (!supported) + goto out; + + if (!vsock_ioctl_int(fd, SIOCINQ, SO_INQ_BUF_LEN)) { + fprintf(stderr, "Test skipped, SIOCINQ not supported.\n"); + goto out; + } + + /* The accepted socket reports SCM_INQ without its own setsockopt(). */ + expect_res(so_inq_recv(fd, SO_INQ_CHUNK_LEN, SO_INQ_CHUNK_LEN), + SO_INQ_BUF_LEN - SO_INQ_CHUNK_LEN, + "SCM_INQ inherited from the listener"); + +out: + control_writeln("DONE"); + close(fd); +} + +static void test_so_inq_validation_client(const struct test_opts *opts) +{ + int fd; + + fd = socket(AF_VSOCK, SOCK_STREAM, 0); + if (fd < 0) { + perror("socket"); + exit(EXIT_FAILURE); + } + + if (so_inq_set(fd, 1)) { + if (errno != ENOPROTOOPT) { + perror("setsockopt(SO_INQ)"); + exit(EXIT_FAILURE); + } + + fprintf(stderr, "Test skipped, SO_INQ not supported.\n"); + close(fd); + return; + } + + if (!so_inq_set(fd, 2) || errno != EINVAL) { + fprintf(stderr, "SO_INQ accepted an out of range value\n"); + exit(EXIT_FAILURE); + } + + close(fd); + + /* SCM_INQ counts bytes, which a message based socket cannot report. */ + fd = socket(AF_VSOCK, SOCK_SEQPACKET, 0); + if (fd < 0) { + perror("socket"); + exit(EXIT_FAILURE); + } + + if (!so_inq_set(fd, 1) || errno != ENOPROTOOPT) { + fprintf(stderr, "SO_INQ not rejected on SOCK_SEQPACKET\n"); + exit(EXIT_FAILURE); + } + + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -2633,6 +2898,20 @@ static struct test_case test_cases[] = { .run_client = test_stream_collapse_client, .run_server = test_stream_collapse_server, }, + { + .name = "SOCK_STREAM SO_INQ functionality", + .run_client = test_stream_so_inq_client, + .run_server = test_stream_so_inq_server, + }, + { + .name = "SOCK_STREAM SO_INQ inherited by accepted socket", + .run_client = test_stream_so_inq_inherit_client, + .run_server = test_stream_so_inq_inherit_server, + }, + { + .name = "SO_INQ option validation", + .run_client = test_so_inq_validation_client, + }, {}, }; From 39e24cf5e29a01d28ef53bfa6ea08d0382a05dc2 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 16 Oct 2026 20:37:42 +0200 Subject: [PATCH 2079/2126] net/fsl: xgmac_mdio: Add missing newlines to error prints Add missing newlines at the end of debug prints. Signed-off-by: Marek Vasut Link: https://patch.msgid.link/20261016183804.39217-1-marex@nabladev.com Signed-off-by: Paolo Abeni --- drivers/net/ethernet/freescale/xgmac_mdio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/xgmac_mdio.c b/drivers/net/ethernet/freescale/xgmac_mdio.c index 65dc07d0df0f..c7df63305068 100644 --- a/drivers/net/ethernet/freescale/xgmac_mdio.c +++ b/drivers/net/ethernet/freescale/xgmac_mdio.c @@ -336,13 +336,13 @@ static int xgmac_mdio_set_mdc_freq(struct mii_bus *bus) priv->enet_clk = devm_clk_get(dev, NULL); if (IS_ERR(priv->enet_clk)) { - dev_err(dev, "Input clock unknown, not changing MDC frequency"); + dev_err(dev, "Input clock unknown, not changing MDC frequency\n"); return PTR_ERR(priv->enet_clk); } div = ((clk_get_rate(priv->enet_clk) / priv->mdc_freq) - 1) / 2; if (div < 5 || div > 0x1ff) { - dev_err(dev, "Requested MDC frequency is out of range, ignoring"); + dev_err(dev, "Requested MDC frequency is out of range, ignoring\n"); return -EINVAL; } From 1234707482053f1d1ac7c5756207d2c29057974c Mon Sep 17 00:00:00 2001 From: Weiming Shi Date: Sat, 17 Oct 2026 04:42:38 -0700 Subject: [PATCH 2080/2126] virtio_net: atomically disable rx mode work virtio-net uses a boolean to gate rx_mode_work during device teardown. The flag is changed under RTNL, but ndo_set_rx_mode checks it under the address-list lock. A callback can therefore pass the check and enqueue work after teardown has flushed it. The work is also enabled before late probe operations that can fail, allowing probe unwind to free the netdev with work still queued. KASAN reports the worker using a virtqueue that probe unwind already freed: BUG: KASAN: slab-use-after-free in virtqueue_add_split Workqueue: events virtnet_rx_mode_work Call Trace: virtqueue_add_split (drivers/virtio/virtio_ring.c:706) virtqueue_add_sgs (drivers/virtio/virtio_ring.c:2839) virtnet_send_command_reply (drivers/net/virtio_net.c:3565) virtnet_rx_mode_work (drivers/net/virtio_net.c:3833) process_one_work (kernel/workqueue.c:3322) worker_thread (kernel/workqueue.c:3405) Freed by task 119: kfree (mm/slub.c:6625) vp_del_vq.isra.0 (drivers/virtio/virtio_pci_common.c:259) vp_del_vqs (drivers/virtio/virtio_pci_common.c:285) virtnet_probe (drivers/net/virtio_net.c:7129) Use the workqueue disable mechanism to atomically reject new queue attempts and drain running work. Keep work disabled until probe succeeds or restore has reattached the netdev, then enable it and replay receive-mode state for a running interface. Disable it before resource teardown in freeze and remove. Fixes: b9f7425239a0 ("virtio-net: convert rx mode setting to use workqueue") Cc: stable@vger.kernel.org Reported-by: Assisted-by: LLM Signed-off-by: Weiming Shi Link: https://patch.msgid.link/20261017114237.2786302-2-bestswngs@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/virtio_net.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index daab43ac92ce..4e8a792cec0e 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -441,9 +441,6 @@ struct virtnet_info { /* Work struct for setting rx mode */ struct work_struct rx_mode_work; - /* OK to queue work setting RX mode? */ - bool rx_mode_work_enabled; - /* Does the affinity hint is set for virtqueues? */ bool affinity_hint_set; @@ -710,16 +707,13 @@ static void virtnet_rq_free_buf(struct virtnet_info *vi, static void enable_rx_mode_work(struct virtnet_info *vi) { - rtnl_lock(); - vi->rx_mode_work_enabled = true; - rtnl_unlock(); + if (enable_work(&vi->rx_mode_work) && netif_running(vi->dev)) + schedule_work(&vi->rx_mode_work); } static void disable_rx_mode_work(struct virtnet_info *vi) { - rtnl_lock(); - vi->rx_mode_work_enabled = false; - rtnl_unlock(); + disable_work_sync(&vi->rx_mode_work); } static void virtqueue_napi_schedule(struct napi_struct *napi, @@ -3925,8 +3919,7 @@ static void virtnet_set_rx_mode(struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); - if (vi->rx_mode_work_enabled) - schedule_work(&vi->rx_mode_work); + schedule_work(&vi->rx_mode_work); } static int virtnet_vlan_rx_add_vid(struct net_device *dev, @@ -5742,7 +5735,6 @@ static void virtnet_freeze_down(struct virtio_device *vdev) /* Make sure no work handler is accessing the device */ flush_work(&vi->config_work); disable_rx_mode_work(vi); - flush_work(&vi->rx_mode_work); if (netif_running(vi->dev)) { rtnl_lock(); @@ -5772,8 +5764,6 @@ static int virtnet_restore_up(struct virtio_device *vdev) virtio_device_ready(vdev); - enable_rx_mode_work(vi); - if (netif_running(vi->dev)) { rtnl_lock(); err = virtnet_open(vi->dev); @@ -5785,6 +5775,8 @@ static int virtnet_restore_up(struct virtio_device *vdev) netif_tx_lock_bh(vi->dev); netif_device_attach(vi->dev); netif_tx_unlock_bh(vi->dev); + + enable_rx_mode_work(vi); return 0; err_destroy_pools: @@ -6880,6 +6872,7 @@ static int virtnet_probe(struct virtio_device *vdev) INIT_WORK(&vi->config_work, virtnet_config_changed_work); INIT_WORK(&vi->rx_mode_work, virtnet_rx_mode_work); + disable_work(&vi->rx_mode_work); if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) { vi->mergeable_rx_bufs = true; @@ -7038,8 +7031,6 @@ static int virtnet_probe(struct virtio_device *vdev) if (vi->has_rss || vi->has_rss_hash_report) virtnet_init_default_rss(vi); - enable_rx_mode_work(vi); - for (i = 0; i < ARRAY_SIZE(guest_offloads); i++) { unsigned int fbit; @@ -7143,6 +7134,8 @@ static int virtnet_probe(struct virtio_device *vdev) goto free_unregister_netdev; } + enable_rx_mode_work(vi); + pr_debug("virtnet: registered device %s with %d RX and TX vq's\n", dev->name, max_queue_pairs); @@ -7195,7 +7188,6 @@ static void virtnet_remove(struct virtio_device *vdev) /* Make sure no work handler is accessing the device. */ flush_work(&vi->config_work); disable_rx_mode_work(vi); - flush_work(&vi->rx_mode_work); virtnet_free_irq_moder(vi); From 7eed173447fba937a19e2f5f2dc79780793f72e7 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Mon, 19 Oct 2026 15:31:56 +0200 Subject: [PATCH 2081/2126] net/mlx5: HWS, fix modify header pattern compare on big-endian mlx5hws_pat_compare_pattern() casts each __be64 action to __be32 to compare only its control dword. On big-endian this keeps the data dword instead, which HWS clears from the pattern of set and add actions. Two such actions writing the same value into different fields then share a pattern and the second rule modifies the wrong field. Read the first dword of each action from memory instead. Little-endian behavior is unchanged. Discovered by an AI code review agent [1] and confirmed by code inspection. Not reproduced for lack of big-endian hardware running HWS. Tested for regressions on ConnectX-7 with firmware 28.48.1000 on a little-endian host. Fixes: aefc15a0fa1c ("net/mlx5: HWS, added modify header pattern and args handling") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010120147.135825-1-acassen%40corp.free.fr [1] Reviewed-by: Simon Horman Signed-off-by: Alexandre Cassen Reviewed-by: Yevgeny Kliteynik Link: https://patch.msgid.link/20261019133159.1742411-2-acassen@corp.free.fr Signed-off-by: Paolo Abeni --- .../net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c index 9af449c2b4d5..512299b59fd0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c @@ -116,8 +116,8 @@ static bool mlx5hws_pat_compare_pattern(int cur_num_of_actions, return false; } else { /* Compare just the control, not the values */ - if ((__force __be32)actions[i] != - (__force __be32)cur_actions[i]) + if (*(__be32 *)&actions[i] != + *(__be32 *)&cur_actions[i]) return false; } } From d425ec9bb9371d52d492ac4d09f0da6e26561684 Mon Sep 17 00:00:00 2001 From: Alexandre Cassen Date: Mon, 19 Oct 2026 15:31:57 +0200 Subject: [PATCH 2082/2126] net/mlx5: HWS, fix modify header pool match for copy actions mlx5_fs_hws_mh_pool_match() compares a single dword of each action since rules pass their values as arguments. Copy and add_field actions keep their destination in the second dword and HWS reads them from the pattern alone. Two modify headers whose copies differ only in destination then share a pool and the second rule writes to the wrong field. Use the HWS core comparison that checks these actions in full. Found while checking a Sashiko AI review report and confirmed against the HWS pattern code. Not reproduced. No in-kernel user puts such actions on the FDB but RDMA flow actions can. Tested for regressions on ConnectX-7 with firmware 28.48.1000 on a little-endian host. Fixes: b36315ca69cb ("net/mlx5: fs, add HWS modify header API function") Signed-off-by: Alexandre Cassen Reviewed-by: Yevgeny Kliteynik Link: https://patch.msgid.link/20261019133159.1742411-3-acassen@corp.free.fr Signed-off-by: Paolo Abeni --- .../mellanox/mlx5/core/steering/hws/fs_hws_pools.c | 11 ++++------- .../mellanox/mlx5/core/steering/hws/pat_arg.c | 8 ++++---- .../mellanox/mlx5/core/steering/hws/pat_arg.h | 5 +++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c index 86828e329187..05aa143fa088 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c @@ -3,6 +3,7 @@ #include #include "fs_hws_pools.h" +#include "internal.h" #define MLX5_FS_HWS_DEFAULT_BULK_LEN 65536 #define MLX5_FS_HWS_POOL_MAX_THRESHOLD BIT(18) @@ -389,7 +390,7 @@ bool mlx5_fs_hws_mh_pool_match(struct mlx5_fs_pool *mh_pool, struct mlx5hws_action_mh_pattern *pattern) { struct mlx5hws_action_mh_pattern *pool_pattern; - int num_actions, i; + int num_actions; pool_pattern = mh_pool->pool_ctx; if (WARN_ON_ONCE(!pool_pattern)) @@ -398,12 +399,8 @@ bool mlx5_fs_hws_mh_pool_match(struct mlx5_fs_pool *mh_pool, if (pattern->sz != pool_pattern->sz) return false; num_actions = pattern->sz / MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto); - for (i = 0; i < num_actions; i++) { - if ((__force __be32)pattern->data[i] != - (__force __be32)pool_pattern->data[i]) - return false; - } - return true; + return mlx5hws_pat_compare_pattern(num_actions, pool_pattern->data, + num_actions, pattern->data); } struct mlx5hws_action *mlx5_fc_get_hws_action(struct mlx5hws_context *ctx, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c index 512299b59fd0..a49115f04025 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.c @@ -96,10 +96,10 @@ void mlx5hws_pat_uninit_pattern_cache(struct mlx5hws_pattern_cache *cache) kfree(cache); } -static bool mlx5hws_pat_compare_pattern(int cur_num_of_actions, - __be64 cur_actions[], - int num_of_actions, - __be64 actions[]) +bool mlx5hws_pat_compare_pattern(int cur_num_of_actions, + __be64 cur_actions[], + int num_of_actions, + __be64 actions[]) { int i; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.h b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.h index 7fbd8dc7aa18..2be7787104e1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pat_arg.h @@ -49,6 +49,11 @@ int mlx5hws_pat_init_pattern_cache(struct mlx5hws_pattern_cache **cache); void mlx5hws_pat_uninit_pattern_cache(struct mlx5hws_pattern_cache *cache); +bool mlx5hws_pat_compare_pattern(int cur_num_of_actions, + __be64 cur_actions[], + int num_of_actions, + __be64 actions[]); + bool mlx5hws_pat_verify_actions(struct mlx5hws_context *ctx, __be64 pattern[], size_t sz); int mlx5hws_arg_create(struct mlx5hws_context *ctx, From 279d5c8afcd38bd841832a39bfe1aa4f8518d98e Mon Sep 17 00:00:00 2001 From: David Yang Date: Sat, 17 Oct 2026 10:31:32 +0800 Subject: [PATCH 2083/2126] net: dsa: motorcomm: Extend ACL with UDF The native ACL key set cannot express IP TTL or ICMP type/code. Use the User Defined Filter windows to match them in the tc flower offload. Signed-off-by: David Yang Link: https://patch.msgid.link/20261017023136.2961543-1-mmyangfl@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/dsa/motorcomm/chip.h | 2 +- drivers/net/dsa/motorcomm/tc.c | 140 +++++++++++++++++++++++++++++-- drivers/net/dsa/motorcomm/tc.h | 12 ++- 3 files changed, 144 insertions(+), 10 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 7047ad98f431..fc315f1d8f87 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -440,7 +440,7 @@ enum yt921x_fdb_entry_status { #define YT921X_TAG_LEN 8 #define YT921X_ACL_BLK_NUM 48 -#define YT921X_UDF_NUM 8 +#define YT921X_UDF_NUM 16 #define YT921X_LED_GROUP_NUM 3 #define YT921X_LED_PORT_NUM 10 diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index 3e0f80500f41..9dbd61e48fee 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -543,6 +543,24 @@ yt921x_acl_rule_set_ports(struct yt921x_acl_rule *aclrule, u16 ord, } } +struct yt921x_udf_entry { + unsigned char type; + unsigned char offset; + u8 key; + u8 mask; +}; + +struct yt921x_udf_map { + unsigned char type; + unsigned char offset; +}; + +/* UDF windows are preselected - that's enough for now. */ +static struct yt921x_udf_map yt921x_udf_maps[] = { + {YT921X_UDF_TYPE_L3, 7}, + {YT921X_UDF_TYPE_L4, 0}, +}; + struct yt921x_acl_rule_ext { struct yt921x_acl_rule r; @@ -556,9 +574,13 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, const struct flow_rule *rule = flow_cls_offload_flow_rule(cls); struct yt921x_acl_entry *entries = ruleext->r.entries; struct netlink_ext_ack *extack = cls->common.extack; + struct yt921x_udf_entry udfs[YT921X_UDF_NUM]; const struct flow_dissector *dissector; struct yt921x_acl_entry *entry; + unsigned int udfs_cnt = 0; unsigned int size = 0; + __be16 n_proto = 0; + u8 ip_proto = 0; bool use_dport; bool use_sport; @@ -575,7 +597,8 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, BIT_ULL(FLOW_DISSECTOR_KEY_PORTS_RANGE) | BIT_ULL(FLOW_DISSECTOR_KEY_ETH_ADDRS) | BIT_ULL(FLOW_DISSECTOR_KEY_IP) | - BIT_ULL(FLOW_DISSECTOR_KEY_TCP))) { + BIT_ULL(FLOW_DISSECTOR_KEY_TCP) | + BIT_ULL(FLOW_DISSECTOR_KEY_ICMP))) { NL_SET_ERR_MSG_MOD(extack, "Unsupported keys used"); return -EOPNOTSUPP; } @@ -741,7 +764,9 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, if (match.mask->n_proto) { enum yt921x_l3_type l3type = YT921X_L3_TYPE_OTHER; - if (match.mask->n_proto == htons(~0)) + if (match.mask->n_proto == htons(~0)) { + n_proto = match.key->n_proto; + switch (match.key->n_proto) { case htons(ETH_P_IP): l3type = YT921X_L3_TYPE_IPV4; @@ -762,6 +787,7 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, l3type = YT921X_L3_TYPE_ERP; break; } + } if (l3type != YT921X_L3_TYPE_OTHER) { size = yt921x_acl_entries_set_l3_type(entries, @@ -783,7 +809,9 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, if (match.mask->ip_proto) { enum yt921x_l4_type l4type = YT921X_L4_TYPE_OTHER; - if (match.mask->ip_proto == (u8)~0) + if (match.mask->ip_proto == (u8)~0) { + ip_proto = match.key->ip_proto; + switch (match.key->ip_proto) { case IPPROTO_TCP: l4type = YT921X_L4_TYPE_TCP; @@ -801,6 +829,7 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, l4type = YT921X_L4_TYPE_IGMP; break; } + } if (l4type != YT921X_L4_TYPE_OTHER) { size = yt921x_acl_entries_set_l4_type(entries, @@ -852,10 +881,25 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, struct flow_match_ip match; flow_rule_match_ip(rule, &match); + if (match.mask->ttl) { - NL_SET_ERR_MSG_MOD(extack, - "Matching on TTL not supported"); - return -EOPNOTSUPP; + if (n_proto != htons(ETH_P_IP) && + n_proto != htons(ETH_P_IPV6)) { + NL_SET_ERR_MSG_MOD(extack, + "Matching on TTL requires protocol ip or ipv6"); + return -EOPNOTSUPP; + } + + if (udfs_cnt >= YT921X_UDF_NUM) + goto err; + + udfs[udfs_cnt] = (struct yt921x_udf_entry){ + .type = YT921X_UDF_TYPE_L3, + .offset = n_proto == htons(ETH_P_IP) ? 8 : 7, + .key = match.key->ttl, + .mask = match.mask->ttl, + }; + udfs_cnt++; } if (match.mask->tos) { @@ -889,6 +933,82 @@ yt921x_acl_rule_ext_parse_flow_entries(struct yt921x_acl_rule_ext *ruleext, } } + if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ICMP)) { + struct flow_match_icmp match; + + flow_rule_match_icmp(rule, &match); + + if (match.mask->type || match.mask->code) { + if (ip_proto != IPPROTO_ICMP && + ip_proto != IPPROTO_ICMPV6) { + NL_SET_ERR_MSG_MOD(extack, + "Matching on ICMP type/code requires ip_proto icmp or icmpv6"); + return -EOPNOTSUPP; + } + + if (match.mask->type) { + if (udfs_cnt >= YT921X_UDF_NUM) + goto err; + + udfs[udfs_cnt] = (struct yt921x_udf_entry){ + .type = YT921X_UDF_TYPE_L4, + .offset = 0, + .key = match.key->type, + .mask = match.mask->type, + }; + udfs_cnt++; + } + + if (match.mask->code) { + if (udfs_cnt >= YT921X_UDF_NUM) + goto err; + + udfs[udfs_cnt] = (struct yt921x_udf_entry){ + .type = YT921X_UDF_TYPE_L4, + .offset = 1, + .key = match.key->code, + .mask = match.mask->code, + }; + udfs_cnt++; + } + } + } + + /* Compile UDFs */ + for (unsigned int i = 0; i < udfs_cnt; i++) { + unsigned int o; + u32 mask; + u32 key; + + for (o = 0; o < ARRAY_SIZE(yt921x_udf_maps); o++) + if (udfs[i].type == yt921x_udf_maps[o].type && + (udfs[i].offset == yt921x_udf_maps[o].offset || + udfs[i].offset == yt921x_udf_maps[o].offset + 1)) + break; + + if (WARN_ON(o == ARRAY_SIZE(yt921x_udf_maps))) + return -EOPNOTSUPP; + + entry = yt921x_acl_entries_find(entries, &size, + YT921X_ACL_TYPE_UDF0 + o / 2); + if (!entry) + goto err; + + key = udfs[i].key; + mask = udfs[i].mask; + if (udfs[i].offset == yt921x_udf_maps[o].offset) { + key <<= 8; + mask <<= 8; + } + if (!(o % 2)) { + key <<= 16; + mask <<= 16; + } + + entry->key[0] |= key; + entry->mask[0] |= mask; + } + if (!size) { NL_SET_ERR_MSG_MOD(extack, "Empty rule generated, this should not happen"); return -EOPNOTSUPP; @@ -1579,5 +1699,13 @@ int yt921x_chip_setup_acl(struct yt921x_priv *priv) if (res) return res; + for (unsigned int o = 0; o < ARRAY_SIZE(yt921x_udf_maps); o++) { + ctrl = YT921X_UDF_CTRL_UDF_OFFSET(yt921x_udf_maps[o].offset) | + YT921X_UDF_CTRL_UDF_TYPE(yt921x_udf_maps[o].type); + res = yt921x_reg_write(priv, YT921X_UDFn_CTRL(o), ctrl); + if (res) + return res; + } + return 0; } diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h index f11136a1c5e2..cc53f148d690 100644 --- a/drivers/net/dsa/motorcomm/tc.h +++ b/drivers/net/dsa/motorcomm/tc.h @@ -118,6 +118,9 @@ enum yt921x_acl_type { YT921X_ACL_TYPE_IPV6_SA3, YT921X_ACL_TYPE_MISC, YT921X_ACL_TYPE_L4, + /* Each User Defined Filter entry contains 2 UDF windows (UDF_CTRL 2i + * and 2i+1) + */ YT921X_ACL_TYPE_UDF0, YT921X_ACL_TYPE_UDF1, YT921X_ACL_TYPE_UDF2, @@ -255,12 +258,15 @@ enum yt921x_l4_type { #define YT921X_UDFn_CTRL(x) (0x210094 + 4 * (x)) #define YT921X_UDF_CTRL_UDF_TYPE_M GENMASK(8, 7) #define YT921X_UDF_CTRL_UDF_TYPE(x) FIELD_PREP(YT921X_UDF_CTRL_UDF_TYPE_M, (x)) -#define YT921X_UDF_CTRL_UDF_TYPE_ETH YT921X_UDF_CTRL_UDF_TYPE(0) -#define YT921X_UDF_CTRL_UDF_TYPE_L3 YT921X_UDF_CTRL_UDF_TYPE(1) -#define YT921X_UDF_CTRL_UDF_TYPE_L4 YT921X_UDF_CTRL_UDF_TYPE(2) #define YT921X_UDF_CTRL_UDF_OFFSET_M GENMASK(6, 0) #define YT921X_UDF_CTRL_UDF_OFFSET(x) FIELD_PREP(YT921X_UDF_CTRL_UDF_OFFSET_M, (x)) +enum yt921x_udf_type { + YT921X_UDF_TYPE_L2, + YT921X_UDF_TYPE_L3, + YT921X_UDF_TYPE_L4, +}; + #define YT921X_PORTn_RATE(port) (0x220000 + 4 * (port)) #define YT921X_PORT_RATE_GAP_VALUE GENMASK(4, 0) /* default 20 */ #define YT921X_METER_SLOT 0x220104 From b428d67934b5949c397cff7c102c345975dd2eb9 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:30:56 +0200 Subject: [PATCH 2084/2126] net: phy: phy_link_topology: Add a helper for opportunistic alloc The phy_link_topology structure stores information about the PHY-related components connected to a net_device. It is opportunistically allocated, when we add the first item to the topology, as this is not relevant for all kinds of net_devices. In preparation for the addition of phy_port tracking in the topology, let's make a dedicated helper for that allocation sequence. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-2-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_link_topology.c | 40 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c index 4134de7ae313..0462283c8020 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -28,11 +28,39 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev) return 0; } +static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *dev) +{ + int ret; + + if (dev->link_topo) + return dev->link_topo; + + /* The topology is allocated the first time we add an object to it. + * It is freed alongside the netdev. It can be called on multiple + * contexts: + * - It can be called from .probe() : No rtnl, no netdev_lock + * - .ndo_open() : rtnl and possibly netdev_lock + * - SFP state machine : rtnl held or not + * + * However, we can't really have races : + * - If we have a PHY, phy_link_topo_add_phy() will always run first + * and trigger the alloc. Only then the ports can be added through + * phylib or sfp. + * - If we don't, the SFP port for the cage is registered first, and + * only then other ports/PHYs can be registered. + */ + ret = netdev_alloc_phy_link_topology(dev); + if (ret) + return ERR_PTR(ret); + + return dev->link_topo; +} + int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, enum phy_upstream upt, void *upstream) { - struct phy_link_topology *topo = dev->link_topo; + struct phy_link_topology *topo; struct phy_device_node *pdn; int ret; @@ -45,13 +73,9 @@ int phy_link_topo_add_phy(struct net_device *dev, if (WARN_ON_ONCE(netdev_need_ops_lock(dev))) return -EOPNOTSUPP; - if (!topo) { - ret = netdev_alloc_phy_link_topology(dev); - if (ret) - return ret; - - topo = dev->link_topo; - } + topo = phy_link_topo_get_or_alloc(dev); + if (IS_ERR(topo)) + return PTR_ERR(topo); pdn = kzalloc_obj(*pdn); if (!pdn) From 9fd93893b6fa0f22d9fd186d5b3467538d5f16f4 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:30:57 +0200 Subject: [PATCH 2085/2126] net: phy: phy_link_topology: Track ports in phy_link_topology phy_port is aimed at representing the various physical interfaces of a net_device. They can be controlled by various components in the link, such as the Ethernet PHY, the Ethernet MAC, and SFP module, etc. Let's therefore make so we keep track of all the ports connected to a netdev in phy_link_topology. The only ports added for now are phy-driven ports. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-3-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 3 ++ drivers/net/phy/phy_link_topology.c | 53 +++++++++++++++++++++++++++++ include/linux/phy_link_topology.h | 18 ++++++++++ include/linux/phy_port.h | 2 ++ net/core/dev.c | 1 + 5 files changed, 77 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 68691c487eee..1db5d0bfdf80 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1580,6 +1580,9 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port) list_del(&port->head); + if (phydev->attached_dev) + phy_link_topo_del_port(phydev->attached_dev, port); + phydev->n_ports--; } diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c index 0462283c8020..28c5bf3a8849 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -23,6 +24,9 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev) xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1); topo->next_phy_index = 1; + xa_init_flags(&topo->ports, XA_FLAGS_ALLOC1); + topo->next_port_index = 1; + dev->link_topo = topo; return 0; @@ -56,12 +60,45 @@ static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *d return dev->link_topo; } +int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port) +{ + struct phy_link_topology *topo; + int ret; + + topo = phy_link_topo_get_or_alloc(dev); + if (IS_ERR(topo)) + return PTR_ERR(topo); + + /* Attempt to re-use a previously allocated port_id */ + if (port->id) + ret = xa_insert(&topo->ports, port->id, port, GFP_KERNEL); + else + ret = xa_alloc_cyclic(&topo->ports, &port->id, port, + xa_limit_32b, &topo->next_port_index, + GFP_KERNEL); + + return ret < 0 ? ret : 0; +} +EXPORT_SYMBOL_GPL(phy_link_topo_add_port); + +void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port) +{ + struct phy_link_topology *topo = dev->link_topo; + + if (!topo) + return; + + xa_erase(&topo->ports, port->id); +} +EXPORT_SYMBOL_GPL(phy_link_topo_del_port); + int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, enum phy_upstream upt, void *upstream) { struct phy_link_topology *topo; struct phy_device_node *pdn; + struct phy_port *port; int ret; /* ethtool ops may run without rtnl_lock, and rtnl_lock is what @@ -110,8 +147,20 @@ int phy_link_topo_add_phy(struct net_device *dev, if (ret < 0) goto err; + /* Add all the PHY's ports to the topology */ + list_for_each_entry(port, &phy->ports, head) { + ret = phy_link_topo_add_port(dev, port); + if (ret) + goto del_ports; + } + return 0; +del_ports: + list_for_each_entry_continue_reverse(port, &phy->ports, head) + phy_link_topo_del_port(dev, port); + + xa_erase(&topo->phys, phy->phyindex); err: kfree(pdn); return ret; @@ -123,10 +172,14 @@ void phy_link_topo_del_phy(struct net_device *dev, { struct phy_link_topology *topo = dev->link_topo; struct phy_device_node *pdn; + struct phy_port *port; if (!topo) return; + list_for_each_entry(port, &phy->ports, head) + phy_link_topo_del_port(dev, port); + pdn = xa_erase(&topo->phys, phy->phyindex); /* We delete the PHY from the topology, however we don't re-set the diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h index 95575f68d5bc..296ee514ba46 100644 --- a/include/linux/phy_link_topology.h +++ b/include/linux/phy_link_topology.h @@ -16,11 +16,15 @@ struct xarray; struct phy_device; +struct phy_port; struct sfp_bus; struct phy_link_topology { struct xarray phys; u32 next_phy_index; + + struct xarray ports; + u32 next_port_index; }; struct phy_device_node { @@ -48,6 +52,9 @@ int phy_link_topo_add_phy(struct net_device *dev, void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); +int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port); +void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port); + static inline struct phy_device * phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) { @@ -77,6 +84,17 @@ static inline void phy_link_topo_del_phy(struct net_device *dev, { } +static inline int phy_link_topo_add_port(struct net_device *dev, + struct phy_port *port) +{ + return 0; +} + +static inline void phy_link_topo_del_port(struct net_device *dev, + struct phy_port *port) +{ +} + static inline struct phy_device * phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) { diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h index 0ef0f5ce4709..4e2a3fdd2f2e 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -36,6 +36,7 @@ struct phy_port_ops { /** * struct phy_port - A representation of a network device physical interface * + * @id: Unique identifier for the port within the topology * @head: Used by the port's parent to list ports * @parent_type: The type of device this port is directly connected to * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port @@ -52,6 +53,7 @@ struct phy_port_ops { * @is_sfp: Indicates if this port drives an SFP cage. */ struct phy_port { + u32 id; struct list_head head; enum phy_port_parent parent_type; union { diff --git a/net/core/dev.c b/net/core/dev.c index 8eb9bf1ff9eb..1a09e7869118 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11521,6 +11521,7 @@ static void netdev_free_phy_link_topology(struct net_device *dev) if (IS_ENABLED(CONFIG_PHYLIB) && topo) { xa_destroy(&topo->phys); + xa_destroy(&topo->ports); kfree(topo); dev->link_topo = NULL; } From b8335326fe069004efe868d190f7ec1f46396886 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:30:58 +0200 Subject: [PATCH 2086/2126] net: phylink: Register a phy_port for MAC-driven SFP cages phy_port tracks the interfaces that a netdevice feeds into. SFP cages are such ports, but so far we are only tracking the ones that are driven by PHYs acting as media-converters. Let's populate a phy_port for MAC driven SFP cages, handled by phylink. This phy_port represents the SFP cage itself, and not the module that may be plugged into it. It's therefore not an MDI interface, so only the 'interfaces' field is relevant here. The phy_port is only populated for 'NETDEV' phylink instances, as otherwise we don't have any topology to attach the port to. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-4-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phylink.c | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index a7d086cdc9b2..971f8961dcf1 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -93,6 +95,7 @@ struct phylink { DECLARE_PHY_INTERFACE_MASK(sfp_interfaces); __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); u8 sfp_port; + struct phy_port *sfp_cage_port; struct eee_config eee_cfg; @@ -1767,6 +1770,52 @@ static void phylink_fixed_poll(struct timer_list *t) static const struct sfp_upstream_ops sfp_phylink_ops; +static int phylink_create_sfp_cage_port(struct phylink *pl) +{ + struct phy_port *port; + int ret = 0; + + if (!pl->netdev || !pl->sfp_bus) + return 0; + + port = phy_port_alloc(); + if (!port) + return -ENOMEM; + + port->is_sfp = true; + port->is_mii = true; + port->active = true; + + phy_interface_and(port->interfaces, pl->config->supported_interfaces, + phylink_sfp_interfaces); + phy_port_update_supported(port); + + rtnl_lock(); + ret = phy_link_topo_add_port(pl->netdev, port); + rtnl_unlock(); + if (ret) + phy_port_destroy(port); + else + pl->sfp_cage_port = port; + + return ret; +} + +static void phylink_destroy_sfp_cage_port(struct phylink *pl) +{ + if (pl->netdev && pl->sfp_cage_port) { + /* The port may still be accessed under RTNL */ + rtnl_lock(); + phy_link_topo_del_port(pl->netdev, pl->sfp_cage_port); + rtnl_unlock(); + } + + if (pl->sfp_cage_port) + phy_port_destroy(pl->sfp_cage_port); + + pl->sfp_cage_port = NULL; +} + static int phylink_register_sfp(struct phylink *pl, const struct fwnode_handle *fwnode) { @@ -1784,9 +1833,18 @@ static int phylink_register_sfp(struct phylink *pl, pl->sfp_bus = bus; + ret = phylink_create_sfp_cage_port(pl); + if (ret) { + sfp_bus_put(bus); + return ret; + } + ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops); sfp_bus_put(bus); + if (ret) + phylink_destroy_sfp_cage_port(pl); + return ret; } @@ -2069,6 +2127,7 @@ EXPORT_SYMBOL_GPL(phylink_create); void phylink_destroy(struct phylink *pl) { sfp_bus_del_upstream(pl->sfp_bus); + phylink_destroy_sfp_cage_port(pl); if (pl->link_gpio) gpiod_put(pl->link_gpio); From 99d78aabd7830ecbf32c7bb917e4d85b8d2da6aa Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:30:59 +0200 Subject: [PATCH 2087/2126] net: phy: Create SFP phy_port before registering upstream When dealing with PHY-driven SFP, we create a phy_port representing the SFP bus when we know we have such a bus. We can move the port creation before registering the sfp upstream ops, as long as we know the SFP bus is there. This will allow passing the phy_port along with the upstream information to the SFP bus. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-5-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 64 ++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1db5d0bfdf80..ba1de1575a44 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1586,13 +1586,13 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port) phydev->n_ports--; } -static int phy_setup_sfp_port(struct phy_device *phydev) +static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev) { struct phy_port *port = phy_port_alloc(); int ret; if (!port) - return -ENOMEM; + return ERR_PTR(-ENOMEM); port->parent_type = PHY_PORT_PHY; port->phy = phydev; @@ -1607,10 +1607,12 @@ static int phy_setup_sfp_port(struct phy_device *phydev) * when attaching the port to the phydev. */ ret = phy_add_port(phydev, port); - if (ret) + if (ret) { phy_port_destroy(port); + return ERR_PTR(ret); + } - return ret; + return port; } /** @@ -1619,32 +1621,48 @@ static int phy_setup_sfp_port(struct phy_device *phydev) */ static int phy_sfp_probe(struct phy_device *phydev) { + struct phy_port *port; struct sfp_bus *bus; - int ret = 0; - if (phydev->mdio.dev.fwnode) { - bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); - if (IS_ERR(bus)) - return PTR_ERR(bus); + if (!phydev->mdio.dev.fwnode) + return 0; - phydev->sfp_bus = bus; + bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); + if (IS_ERR(bus)) + return PTR_ERR(bus); - ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops); - sfp_bus_put(bus); + phydev->sfp_bus = bus; - if (ret) - phydev->sfp_bus = NULL; - } - - if (!ret && phydev->sfp_bus) { - ret = phy_setup_sfp_port(phydev); - if (ret) { - sfp_bus_del_upstream(phydev->sfp_bus); + if (bus) { + port = phy_setup_sfp_port(phydev); + if (IS_ERR(port)) { + sfp_bus_put(bus); phydev->sfp_bus = NULL; + return PTR_ERR(port); } } - return ret; + return 0; +} + +static int phy_sfp_add_upstream(struct phy_device *phydev) +{ + struct sfp_bus *bus = phydev->sfp_bus; + int ret; + + ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops); + if (ret) { + sfp_bus_put(bus); + phydev->sfp_bus = NULL; + return ret; + } + + /* sfp_bus_add_upstream() grabs a ref to the sfp bus on success, it's + * safe to release it now. + */ + sfp_bus_put(bus); + + return 0; } /** @@ -3556,6 +3574,10 @@ static int phy_setup_ports(struct phy_device *phydev) break; } + ret = phy_sfp_add_upstream(phydev); + if (ret) + goto err_sfp; + return 0; err_sfp: From 51ebb13c1d9658328b66b8f67e7992f708567807 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:31:00 +0200 Subject: [PATCH 2088/2126] net: phy: Represent PHY-less SFP modules with phy_port Now that the SFP bus infrastructure notifies when PHY-less modules are connected, we can create a phy_port to represent it. Instead of letting the SFP subsystem handle that, the Bus' upstream is in charge of maintaining that phy_port and register it to the topology, as the upstream (in this case a phy device) is directly interacting with the underlying net_device. Add a phy_caps helper to get the achievable modes on this module based on what the phy_port representing the bus supports. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-6-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy-caps.h | 2 + drivers/net/phy/phy_caps.c | 26 +++++++++ drivers/net/phy/phy_device.c | 103 ++++++++++++++++++++++++++++++++++- drivers/net/phy/phylink.c | 79 +++++++++++++++++++++++++-- include/linux/phy.h | 6 ++ 5 files changed, 209 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h index 421088e6f6e8..ec3d39a0ae06 100644 --- a/drivers/net/phy/phy-caps.h +++ b/drivers/net/phy/phy-caps.h @@ -66,5 +66,7 @@ void phy_caps_medium_get_supported(unsigned long *supported, enum ethtool_link_medium medium, int lanes); u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes); +void phy_caps_linkmode_filter_ifaces(unsigned long *to, const unsigned long *from, + const unsigned long *interfaces); #endif /* __PHY_CAPS_H */ diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c index 942d43191561..558e4df4d63c 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -445,3 +445,29 @@ u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes) return mediums; } EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes); + +/** + * phy_caps_linkmode_filter_ifaces() - Filter linkmodes with an interface list + * @to: Stores the filtered linkmodes + * @from: Linkmodes to filter + * @interfaces: Bitfield of phy_interface_t that we use for filtering + * + * Filter the provided linkmodes, only to keep the ones we can possibly achieve + * when using any of the provided MII interfaces. + */ +void phy_caps_linkmode_filter_ifaces(unsigned long *to, + const unsigned long *from, + const unsigned long *interfaces) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(ifaces_supported) = {}; + unsigned int ifaces_caps = 0; + phy_interface_t interface; + + for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX) + ifaces_caps |= phy_caps_from_interface(interface); + + phy_caps_linkmodes(ifaces_caps, ifaces_supported); + + linkmode_and(to, from, ifaces_supported); +} +EXPORT_SYMBOL_GPL(phy_caps_linkmode_filter_ifaces); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index ba1de1575a44..4f897019dce2 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1400,11 +1400,21 @@ static int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) { struct phy_device *phydev = upstream; struct net_device *dev = phydev->attached_dev; + int ret; - if (dev) - return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev); + phydev->has_sfp_mod_phy = true; - return 0; + /* If we aren't attached to a netdev, we can't add the SFP PHY to its + * topology. + */ + if (!dev) + return 0; + + ret = phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev); + if (ret) + phydev->has_sfp_mod_phy = false; + + return ret; } /** @@ -1422,6 +1432,8 @@ static void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy) struct phy_device *phydev = upstream; struct net_device *dev = phydev->attached_dev; + phydev->has_sfp_mod_phy = false; + if (dev) phy_link_topo_del_phy(dev, phy); } @@ -1527,6 +1539,78 @@ static void phy_sfp_link_down(void *upstream) port->ops->link_down(port); } +static int phy_add_sfp_mod_port(struct phy_device *phydev) +{ + DECLARE_PHY_INTERFACE_MASK(interfaces); + const struct sfp_module_caps *caps; + struct phy_port *port; + int ret = 0; + + /* Create mod port */ + port = phy_port_alloc(); + if (!port) + return -ENOMEM; + + port->active = true; + + caps = sfp_get_module_caps(phydev->sfp_bus); + + phy_interface_and(interfaces, phydev->sfp_cage_port->interfaces, + caps->interfaces); + phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes, + interfaces); + + if (phydev->attached_dev) { + ret = phy_link_topo_add_port(phydev->attached_dev, port); + if (ret) { + phy_port_destroy(port); + return ret; + } + } + + /* we don't use phy_add_port() here as the module port isn't a direct + * interface from the PHY, but rather an extension to the sfp-bus, that + * is already represented by its own phy_port + */ + phydev->mod_port = port; + + return 0; +} + +static void phy_del_sfp_mod_port(struct phy_device *phydev) +{ + if (!phydev->mod_port) + return; + + if (phydev->attached_dev) + phy_link_topo_del_port(phydev->attached_dev, phydev->mod_port); + + phy_port_destroy(phydev->mod_port); + phydev->mod_port = NULL; +} + +static int phy_sfp_module_start(void *upstream) +{ + struct phy_device *phydev = upstream; + + /* If there's a downstream SFP module, and it doesn't contain a PHY + * device, let's create a phy_port to represent that module. + */ + if (!phydev->has_sfp_mod_phy) + return phy_add_sfp_mod_port(phydev); + + return 0; +} + +static void phy_sfp_module_stop(void *upstream) +{ + struct phy_device *phydev = upstream; + + /* Called upon module removal or upstream removal */ + if (!phydev->has_sfp_mod_phy) + phy_del_sfp_mod_port(phydev); +} + static const struct sfp_upstream_ops sfp_phydev_ops = { .attach = phy_sfp_attach, .detach = phy_sfp_detach, @@ -1536,6 +1620,8 @@ static const struct sfp_upstream_ops sfp_phydev_ops = { .link_down = phy_sfp_link_down, .connect_phy = phy_sfp_connect_phy, .disconnect_phy = phy_sfp_disconnect_phy, + .module_start = phy_sfp_module_start, + .module_stop = phy_sfp_module_stop, }; static int phy_add_port(struct phy_device *phydev, struct phy_port *port) @@ -1640,6 +1726,8 @@ static int phy_sfp_probe(struct phy_device *phydev) phydev->sfp_bus = NULL; return PTR_ERR(port); } + + phydev->sfp_cage_port = port; } return 0; @@ -1654,6 +1742,7 @@ static int phy_sfp_add_upstream(struct phy_device *phydev) if (ret) { sfp_bus_put(bus); phydev->sfp_bus = NULL; + phydev->sfp_cage_port = NULL; return ret; } @@ -1744,6 +1833,8 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus) phydev->attached_dev->phydev = NULL; phydev->attached_dev = NULL; phy_link_topo_del_phy(dev, phydev); + if (phydev->mod_port) + phy_link_topo_del_port(dev, phydev->mod_port); } phydev->phy_link_change = NULL; @@ -1880,6 +1971,12 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, err = phy_link_topo_add_phy(dev, phydev, PHY_UPSTREAM_MAC, dev); if (err) goto error; + + if (phydev->mod_port) { + err = phy_link_topo_add_port(dev, phydev->mod_port); + if (err) + goto error; + } } /* Some Ethernet drivers try to connect to a PHY device before diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 971f8961dcf1..667f00ddfa5e 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -96,6 +96,7 @@ struct phylink { __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); u8 sfp_port; struct phy_port *sfp_cage_port; + struct phy_port *mod_port; struct eee_config eee_cfg; @@ -1794,10 +1795,15 @@ static int phylink_create_sfp_cage_port(struct phylink *pl) ret = phy_link_topo_add_port(pl->netdev, port); rtnl_unlock(); if (ret) - phy_port_destroy(port); - else - pl->sfp_cage_port = port; + goto out_destroy_port; + pl->sfp_cage_port = port; + + return 0; + +out_destroy_port: + phy_port_destroy(port); + pl->sfp_cage_port = NULL; return ret; } @@ -4014,14 +4020,68 @@ static void phylink_sfp_module_remove(void *upstream) phy_interface_zero(pl->sfp_interfaces); } +static int phylink_add_sfp_mod_port(struct phylink *pl) +{ + DECLARE_PHY_INTERFACE_MASK(interfaces); + const struct sfp_module_caps *caps; + struct phy_port *port; + int ret = 0; + + if (!pl->sfp_cage_port) + return 0; + + /* Create mod port */ + port = phy_port_alloc(); + if (!port) + return -ENOMEM; + + port->active = true; + + caps = sfp_get_module_caps(pl->sfp_bus); + + phy_interface_and(interfaces, pl->sfp_cage_port->interfaces, + caps->interfaces); + phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes, + interfaces); + + if (pl->netdev) { + ret = phy_link_topo_add_port(pl->netdev, port); + if (ret) { + phy_port_destroy(port); + return ret; + } + } + + pl->mod_port = port; + + return 0; +} + +static void phylink_del_sfp_mod_port(struct phylink *pl) +{ + if (!pl->mod_port) + return; + + if (pl->netdev) + phy_link_topo_del_port(pl->netdev, pl->mod_port); + + phy_port_destroy(pl->mod_port); + pl->mod_port = NULL; +} + static int phylink_sfp_module_start(void *upstream) { struct phylink *pl = upstream; + int ret; /* If this SFP module has a PHY, start the PHY now. */ if (pl->phydev) { phy_start(pl->phydev); return 0; + } else { + ret = phylink_add_sfp_mod_port(pl); + if (ret) + return ret; } /* If the module may have a PHY but we didn't detect one we @@ -4030,7 +4090,16 @@ static int phylink_sfp_module_start(void *upstream) if (!pl->sfp_may_have_phy) return 0; - return phylink_sfp_config_optical(pl); + ret = phylink_sfp_config_optical(pl); + if (ret) + goto del_mod_port; + + return 0; + +del_mod_port: + phylink_del_sfp_mod_port(pl); + + return ret; } static void phylink_sfp_module_stop(void *upstream) @@ -4040,6 +4109,8 @@ static void phylink_sfp_module_stop(void *upstream) /* If this SFP module has a PHY, stop it. */ if (pl->phydev) phy_stop(pl->phydev); + else + phylink_del_sfp_mod_port(pl); } static void phylink_sfp_link_down(void *upstream) diff --git a/include/linux/phy.h b/include/linux/phy.h index a5a419bc400e..782d3ea2964e 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -612,7 +612,10 @@ struct phy_oatc14_sqi_capability { * @irq: IRQ number of the PHY's interrupt (-1 if none) * @phylink: Pointer to phylink instance for this PHY * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached + * @has_sfp_mod_phy: Set true if downstream SFP bus's module contains a PHY * @sfp_bus: SFP bus attached to this PHY's fiber port + * @sfp_cage_port: The phy_port connected to the downstream SFP cage + * @mod_port: phy_port representing the SFP module, if it is phy-less * @attached_dev: The attached enet driver's device instance ptr * @adjust_link: Callback for the enet controller to respond to changes: in the * link state. @@ -804,7 +807,10 @@ struct phy_device { /* This may be modified under the rtnl lock */ bool sfp_bus_attached; + bool has_sfp_mod_phy; struct sfp_bus *sfp_bus; + struct phy_port *sfp_cage_port; + struct phy_port *mod_port; struct phylink *phylink; struct net_device *attached_dev; struct mii_timestamper *mii_ts; From 9e7cd33fafb2ce1fd6cf19fd20f486ea341e6c0c Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:31:01 +0200 Subject: [PATCH 2089/2126] net: phy: phy_port: Store information about a port's upstream MII phy_ports are not meant to be connected directly to a link partner. They are meant to feed into some media converter devices that will expose an MDI phy_port, so far we only support SFP modules for that. In the case an MDI phy_port is backed by an MII port (e.g. a SFP module's port, backed by the SFP cage port), let's keep track of the port id of the MII port backing it. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-7-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++ drivers/net/phy/phylink.c | 5 +++++ include/linux/phy.h | 4 ++++ include/linux/phy_port.h | 3 +++ 4 files changed, 36 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 4f897019dce2..5d4508bcfbe9 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1403,6 +1403,7 @@ static int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) int ret; phydev->has_sfp_mod_phy = true; + phy_set_upstream_port(phy, phydev->sfp_cage_port); /* If we aren't attached to a netdev, we can't add the SFP PHY to its * topology. @@ -1436,6 +1437,8 @@ static void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy) if (dev) phy_link_topo_del_phy(dev, phy); + + phy_set_upstream_port(phy, NULL); } /** @@ -1574,6 +1577,8 @@ static int phy_add_sfp_mod_port(struct phy_device *phydev) */ phydev->mod_port = port; + port->upstream_port = phydev->sfp_cage_port; + return 0; } @@ -3703,6 +3708,25 @@ struct phy_port *phy_get_sfp_port(struct phy_device *phydev) } EXPORT_SYMBOL_GPL(phy_get_sfp_port); +/** + * phy_set_upstream_port() - Sets the phy_port controlling the MII this PHY is + * attached to. + * @phydev: pointer to the PHY device we set the upstream of. + * @port: The phy_port upstream of this PHY, can be NULL. + */ +void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port) +{ + struct phy_port *local_port; + + ASSERT_RTNL(); + + phydev->upstream_port = port; + + phy_for_each_port(phydev, local_port) + local_port->upstream_port = port; +} +EXPORT_SYMBOL_GPL(phy_set_upstream_port); + /** * fwnode_mdio_find_device - Given a fwnode, find the mdio_device * @fwnode: pointer to the mdio_device's fwnode diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 667f00ddfa5e..e885da1c2831 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -4052,6 +4052,8 @@ static int phylink_add_sfp_mod_port(struct phylink *pl) } } + port->upstream_port = pl->sfp_cage_port; + pl->mod_port = port; return 0; @@ -4155,6 +4157,8 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces, pl->config->supported_interfaces); + phy_set_upstream_port(phy, pl->sfp_cage_port); + /* Do the initial configuration */ return phylink_sfp_config_phy(pl, phy); } @@ -4163,6 +4167,7 @@ static void phylink_sfp_disconnect_phy(void *upstream, struct phy_device *phydev) { phylink_disconnect_phy(upstream); + phy_set_upstream_port(phydev, NULL); } static const struct sfp_upstream_ops sfp_phylink_ops = { diff --git a/include/linux/phy.h b/include/linux/phy.h index 782d3ea2964e..21afc2082b17 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -616,6 +616,7 @@ struct phy_oatc14_sqi_capability { * @sfp_bus: SFP bus attached to this PHY's fiber port * @sfp_cage_port: The phy_port connected to the downstream SFP cage * @mod_port: phy_port representing the SFP module, if it is phy-less + * @upstream_port: phy_port this PHY's MII attaches to, if any * @attached_dev: The attached enet driver's device instance ptr * @adjust_link: Callback for the enet controller to respond to changes: in the * link state. @@ -811,6 +812,7 @@ struct phy_device { struct sfp_bus *sfp_bus; struct phy_port *sfp_cage_port; struct phy_port *mod_port; + struct phy_port *upstream_port; struct phylink *phylink; struct net_device *attached_dev; struct mii_timestamper *mii_ts; @@ -2495,6 +2497,8 @@ int __phy_hwtstamp_set(struct phy_device *phydev, struct phy_port *phy_get_sfp_port(struct phy_device *phydev); +void phy_set_upstream_port(struct phy_device *phydev, struct phy_port *port); + /** * phy_module_driver() - Helper macro for registering PHY drivers * @__phy_drivers: array of PHY drivers to register diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h index 4e2a3fdd2f2e..8f45c031cbc1 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -40,6 +40,8 @@ struct phy_port_ops { * @head: Used by the port's parent to list ports * @parent_type: The type of device this port is directly connected to * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port + * @upstream_port: Indicates the MII port that feeds this port, if any, + * e.g. the SFP cage port for a SFP module port. * @ops: Callback ops implemented by the port controller * @pairs: The number of pairs this port has, 0 if not applicable * @mediums: Bitmask of the physical mediums this port provides access to @@ -59,6 +61,7 @@ struct phy_port { union { struct phy_device *phy; }; + struct phy_port *upstream_port; const struct phy_port_ops *ops; From b06f1e6c85ba9c7c42ef7161ae35e3b2f2dbdc6c Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:31:02 +0200 Subject: [PATCH 2090/2126] net: phy: phy_link_topology: Add a helper to retrieve ports In order to allow netlink access to phy_ports, let's add a helper to retrieve them. When handling a port coming from phy_link_topology, the caller must hold rtnl until it's done with it. We don't really support PHY and phy_port operation on ops-locked devices yet, warn when we try to do so on such an interface. Reviewed-by: Andrew Lunn Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-8-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phy_link_topology.c | 8 ++++++++ include/linux/phy_link_topology.h | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c index 28c5bf3a8849..214ccce23cf6 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -65,6 +65,14 @@ int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port) struct phy_link_topology *topo; int ret; + /* Ports can now be queried without rtnl for ops-locked devices, which + * we don't support now as port retrieval is done under rtnl. + * We don't have phy_port enabled devices yet, let's make sure + * we are loudly warned about that when it happens. + */ + if (WARN_ON_ONCE(dev->netdev_ops && netdev_need_ops_lock(dev))) + return -EOPNOTSUPP; + topo = phy_link_topo_get_or_alloc(dev); if (IS_ERR(topo)) return PTR_ERR(topo); diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h index 296ee514ba46..f2e493c433ff 100644 --- a/include/linux/phy_link_topology.h +++ b/include/linux/phy_link_topology.h @@ -13,6 +13,7 @@ #include #include +#include struct xarray; struct phy_device; @@ -71,6 +72,24 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) return NULL; } +static inline struct phy_port * +phy_link_topo_get_port(struct net_device *dev, u32 port_id) +{ + struct phy_link_topology *topo = dev->link_topo; + + if (!topo) + return NULL; + + /* ports in the topo are RTNL protected, but may be accessed under + * netdev_lock for ops-locked devices. For now keep them under rtnl + * protection, as no ops-locked devices have phy_port capabilities + * yet. + */ + ASSERT_RTNL(); + + return xa_load(&topo->ports, port_id); +} + #else static inline int phy_link_topo_add_phy(struct net_device *dev, struct phy_device *phy, @@ -100,6 +119,12 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) { return NULL; } + +static inline struct phy_port * +phy_link_topo_get_port(struct net_device *dev, u32 port_id) +{ + return NULL; +} #endif #endif /* __PHY_LINK_TOPOLOGY_H */ From 01a556b3321eb39a078c1c4082c056ef8b64c76d Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:31:03 +0200 Subject: [PATCH 2091/2126] netlink: specs: Add ethernet port listing with ethtool Ethernet network interfaces may have more than one front-facing port. The phy_port infrastructure was introduced to keep track of these ports, and allow userspace to know about the presence and capability of these ports. Add a ethnl netlink message to report this information. Reviewed-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-9-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- Documentation/netlink/specs/ethtool.yaml | 55 +++++++++++++++++++ Documentation/networking/ethtool-netlink.rst | 36 ++++++++++++ .../uapi/linux/ethtool_netlink_generated.h | 22 ++++++++ 3 files changed, 113 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index a66594ad9e73..a9cb02538783 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -212,6 +212,11 @@ definitions: - name: discard value: 31 + - + name: port-type + doc: type of physical connector + type: enum + entries: [mdi, sfp] attribute-sets: - @@ -1907,6 +1912,32 @@ attribute-sets: name: link type: nest nested-attributes: mse-snapshot + - + name: port + attr-cnt-name: --ethtool-a-port-cnt + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: id + type: u32 + - + name: supported-modes + type: nest + nested-attributes: bitset + - + name: supported-interfaces + type: nest + nested-attributes: bitset + - + name: type + type: u32 + enum: port-type + - + name: upstream-port + type: u32 operations: enum-model: directional @@ -2861,6 +2892,30 @@ operations: - worst-channel - link dump: *mse-get-op + - + name: port-get + doc: Get ports attached to an interface + + attribute-set: port + + do: + request: + attributes: + - header + - id + reply: &port-get-op-reply + attributes: + - header + - id + - supported-modes + - supported-interfaces + - type + - upstream-port + dump: + request: + attributes: + - header + reply: *port-get-op-reply mcast-groups: list: diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 393f2b6d3863..eba226c79ec3 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -247,6 +247,7 @@ Userspace to kernel: ``ETHTOOL_MSG_RSS_CREATE_ACT`` create an additional RSS context ``ETHTOOL_MSG_RSS_DELETE_ACT`` delete an additional RSS context ``ETHTOOL_MSG_MSE_GET`` get MSE diagnostic data + ``ETHTOOL_MSG_PORT_GET`` get port information ===================================== ================================= Kernel to userspace: @@ -305,6 +306,7 @@ Kernel to userspace: ``ETHTOOL_MSG_RSS_CREATE_NTF`` additional RSS context created ``ETHTOOL_MSG_RSS_DELETE_NTF`` additional RSS context deleted ``ETHTOOL_MSG_MSE_GET_REPLY`` MSE diagnostic data + ``ETHTOOL_MSG_PORT_GET_REPLY`` port information ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device @@ -2537,6 +2539,39 @@ Within each channel nest, only the metrics supported by the PHY will be present. See ``struct phy_mse_snapshot`` kernel documentation in ``include/linux/phy.h``. +PORT_GET +======== + +Retrieve information about the physical connection points of a network device, +referred to as "ports". User needs to specify a PORT_ID for the DO operation, +in which case the DO request returns information about that specific port. + +As there can be more than one port, the DUMP operation can be used to list the +ports present on a given interface, by passing an interface index or name in +the dump request. + +Request contents: + + ===================================== ====== =============================== + ``ETHTOOL_A_PORT_HEADER`` nested request header + ``ETHTOOL_A_PORT_ID`` u32 port id + ===================================== ====== =============================== + +Kernel response contents: + + ======================================= ====== ============================= + ``ETHTOOL_A_PORT_HEADER`` nested request header + ``ETHTOOL_A_PORT_ID`` u32 the port's unique identifier, + per netdevice. + ``ETHTOOL_A_PORT_SUPPORTED_MODES`` bitset bitset of supported linkmodes + ``ETHTOOL_A_PORT_SUPPORTED_INTERFACES`` bitset bitset of supported MII + interfaces + ``ETHTOOL_A_PORT_TYPE`` u32 the port type + ``ETHTOOL_A_PORT_UPSTREAM_PORT`` u32 If any, the index of the MII + port that feeds into this + port. + ======================================= ====== ============================= + Request translation =================== @@ -2647,4 +2682,5 @@ are netlink only. n/a ``ETHTOOL_MSG_PHY_GET`` ``SIOCGHWTSTAMP`` ``ETHTOOL_MSG_TSCONFIG_GET`` ``SIOCSHWTSTAMP`` ``ETHTOOL_MSG_TSCONFIG_SET`` + n/a ``ETHTOOL_MSG_PORT_GET`` =================================== ===================================== diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/linux/ethtool_netlink_generated.h index 8134baf7860f..660e0c08a766 100644 --- a/include/uapi/linux/ethtool_netlink_generated.h +++ b/include/uapi/linux/ethtool_netlink_generated.h @@ -78,6 +78,14 @@ enum ethtool_pse_event { ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR = 64, }; +/* + * type of physical connector + */ +enum ethtool_port_type { + ETHTOOL_PORT_TYPE_MDI, + ETHTOOL_PORT_TYPE_SFP, +}; + enum { ETHTOOL_A_HEADER_UNSPEC, ETHTOOL_A_HEADER_DEV_INDEX, @@ -840,6 +848,18 @@ enum { ETHTOOL_A_MSE_MAX = (__ETHTOOL_A_MSE_CNT - 1) }; +enum { + ETHTOOL_A_PORT_HEADER = 1, + ETHTOOL_A_PORT_ID, + ETHTOOL_A_PORT_SUPPORTED_MODES, + ETHTOOL_A_PORT_SUPPORTED_INTERFACES, + ETHTOOL_A_PORT_TYPE, + ETHTOOL_A_PORT_UPSTREAM_PORT, + + __ETHTOOL_A_PORT_CNT, + ETHTOOL_A_PORT_MAX = (__ETHTOOL_A_PORT_CNT - 1) +}; + enum { ETHTOOL_MSG_USER_NONE = 0, ETHTOOL_MSG_STRSET_GET = 1, @@ -893,6 +913,7 @@ enum { ETHTOOL_MSG_RSS_CREATE_ACT, ETHTOOL_MSG_RSS_DELETE_ACT, ETHTOOL_MSG_MSE_GET, + ETHTOOL_MSG_PORT_GET, __ETHTOOL_MSG_USER_CNT, ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1) @@ -954,6 +975,7 @@ enum { ETHTOOL_MSG_RSS_CREATE_NTF, ETHTOOL_MSG_RSS_DELETE_NTF, ETHTOOL_MSG_MSE_GET_REPLY, + ETHTOOL_MSG_PORT_GET_REPLY, __ETHTOOL_MSG_KERNEL_CNT, ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1) From 27859d18bf41fad5b2a1e821f702447a82d9e284 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:31:04 +0200 Subject: [PATCH 2092/2126] net: ethtool: Introduce ethtool command to list ports Expose the phy_port information to userspace, so that we can know how many ports are available on a given interface, as well as their capabilities. For MDI ports, we report the list of supported linkmodes based on what the PHY that drives this port says. For MII ports, i.e. empty SFP cages, we report the MII linkmodes that we can output on this port. Tested-by: Aleksei Sviridkin Reviewed-by: Christophe Leroy (CS GROUP) Tested-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-10-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- MAINTAINERS | 1 + include/uapi/linux/ethtool.h | 2 + net/ethtool/Makefile | 2 +- net/ethtool/netlink.c | 25 +++ net/ethtool/netlink.h | 8 + net/ethtool/port.c | 385 +++++++++++++++++++++++++++++++++++ net/ethtool/strset.c | 5 + 7 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/port.c diff --git a/MAINTAINERS b/MAINTAINERS index 83ff18370ece..e7640995959c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19024,6 +19024,7 @@ F: Documentation/devicetree/bindings/net/ethernet-connector.yaml F: Documentation/networking/phy-port.rst F: drivers/net/phy/phy_port.c F: include/linux/phy_port.h +F: net/ethtool/port.c K: struct\s+phy_port|phy_port_ NETWORKING [GENERAL] diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index 986d70caec33..9e60c17b48c8 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -685,6 +685,7 @@ enum ethtool_link_ext_substate_module { * @ETH_SS_STATS_RMON: names of RMON statistics * @ETH_SS_STATS_PHY: names of PHY(dev) statistics * @ETH_SS_TS_FLAGS: hardware timestamping flags + * @ETH_SS_PHY_INTERFACES: names of MAC to PHY interfaces * * @ETH_SS_COUNT: number of defined string sets */ @@ -712,6 +713,7 @@ enum ethtool_stringset { ETH_SS_STATS_RMON, ETH_SS_STATS_PHY, ETH_SS_TS_FLAGS, + ETH_SS_PHY_INTERFACES, /* add new constants above here */ ETH_SS_COUNT diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index 629c10916670..9b5b09670008 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -9,4 +9,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \ module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o \ - phy.o tsconfig.o mse.o + phy.o tsconfig.o mse.o port.o diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 383e911f50f7..dd8a53f89d54 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -28,6 +28,8 @@ static u32 ethnl_bcast_seq; ETHTOOL_FLAG_OMIT_REPLY) #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS) +char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN] __ro_after_init; + const struct nla_policy ethnl_header_policy[] = { [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, @@ -433,6 +435,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_TSCONFIG_SET] = ðnl_tsconfig_request_ops, [ETHTOOL_MSG_PHY_GET] = ðnl_phy_request_ops, [ETHTOOL_MSG_MSE_GET] = ðnl_mse_request_ops, + [ETHTOOL_MSG_PORT_GET] = ðnl_port_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -1571,6 +1574,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_mse_get_policy, .maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_PORT_GET, + .doit = ethnl_default_doit, + .start = ethnl_port_dump_start, + .dumpit = ethnl_port_dumpit, + .done = ethnl_port_dump_done, + .policy = ethnl_port_get_policy, + .maxattr = ARRAY_SIZE(ethnl_port_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { @@ -1593,10 +1605,23 @@ static struct genl_family ethtool_genl_family __ro_after_init = { /* module setup */ +static void __init ethnl_phy_names_populate(void) +{ + const char *name; + int i; + + for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) { + name = phy_modes(i); + strscpy(phy_interface_names[i], name, ETH_GSTRING_LEN); + } +} + static int __init ethnl_init(void) { int ret; + ethnl_phy_names_populate(); + ret = genl_register_family(ðtool_genl_family); if (WARN(ret < 0, "ethtool: genetlink family registration failed")) return ret; diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 3e969a070f9f..dc7211f67c4d 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -5,11 +5,14 @@ #include #include +#include #include #include struct ethnl_req_info; +extern char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN]; + int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info, const struct nlattr *nest, struct net *net, struct netlink_ext_ack *extack, @@ -474,6 +477,7 @@ extern const struct ethnl_request_ops ethnl_mm_request_ops; extern const struct ethnl_request_ops ethnl_phy_request_ops; extern const struct ethnl_request_ops ethnl_tsconfig_request_ops; extern const struct ethnl_request_ops ethnl_mse_request_ops; +extern const struct ethnl_request_ops ethnl_port_request_ops; extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; @@ -530,6 +534,7 @@ extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1]; extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1]; extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1]; extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1]; +extern const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1]; int ethnl_set_features(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); @@ -545,6 +550,9 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb); int ethnl_tsinfo_done(struct netlink_callback *cb); int ethnl_rss_create_doit(struct sk_buff *skb, struct genl_info *info); int ethnl_rss_delete_doit(struct sk_buff *skb, struct genl_info *info); +int ethnl_port_dump_start(struct netlink_callback *cb); +int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int ethnl_port_dump_done(struct netlink_callback *cb); extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN]; extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN]; diff --git a/net/ethtool/port.c b/net/ethtool/port.c new file mode 100644 index 000000000000..425e5bbdca45 --- /dev/null +++ b/net/ethtool/port.c @@ -0,0 +1,385 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2026 Bootlin + */ +#include +#include +#include +#include + +#include "bitset.h" +#include "common.h" +#include "netlink.h" + +struct port_req_info { + struct ethnl_req_info base; + u32 port_id; +}; + +struct port_reply_data { + struct ethnl_reply_data base; + __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); + DECLARE_PHY_INTERFACE_MASK(interfaces); + u32 port_id; + bool mii; + bool sfp; + u32 upstream_port; +}; + +#define PORT_REQINFO(__req_base) \ + container_of(__req_base, struct port_req_info, base) + +#define PORT_REPDATA(__reply_base) \ + container_of(__reply_base, struct port_reply_data, base) + +const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1] = { + [ETHTOOL_A_PORT_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), + [ETHTOOL_A_PORT_ID] = NLA_POLICY_MIN(NLA_U32, 1), +}; + +static int port_parse_request(struct ethnl_req_info *req_info, + const struct genl_info *info, + struct nlattr **tb, + struct netlink_ext_ack *extack) +{ + struct port_req_info *request = PORT_REQINFO(req_info); + + if (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_PORT_ID)) + return -EINVAL; + + request->port_id = nla_get_u32(tb[ETHTOOL_A_PORT_ID]); + + return 0; +} + +static int port_prepare_data(const struct ethnl_req_info *req_info, + struct ethnl_reply_data *reply_data, + const struct genl_info *info) +{ + struct port_reply_data *reply = PORT_REPDATA(reply_data); + struct port_req_info *request = PORT_REQINFO(req_info); + struct phy_port *port; + + /* RTNL must be held while holding a ref to the phy_port. Here, caller + * holds RTNL. + */ + port = phy_link_topo_get_port(req_info->dev, request->port_id); + if (!port) + return -ENODEV; + + linkmode_copy(reply->supported, port->supported); + phy_interface_copy(reply->interfaces, port->interfaces); + reply->port_id = port->id; + reply->mii = port->is_mii; + reply->sfp = port->is_sfp; + reply->upstream_port = port->upstream_port ? port->upstream_port->id : 0; + + return 0; +} + +static int port_reply_size(const struct ethnl_req_info *req_info, + const struct ethnl_reply_data *reply_data) +{ + bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS; + struct port_reply_data *reply = PORT_REPDATA(reply_data); + size_t size = 0; + int ret; + + /* ETHTOOL_A_PORT_ID */ + size += nla_total_size(sizeof(u32)); + + if (!reply->mii) { + /* ETHTOOL_A_PORT_SUPPORTED_MODES */ + ret = ethnl_bitset_size(reply->supported, NULL, + __ETHTOOL_LINK_MODE_MASK_NBITS, + link_mode_names, compact); + if (ret < 0) + return ret; + + size += ret; + } else { + /* ETHTOOL_A_PORT_SUPPORTED_INTERFACES */ + ret = ethnl_bitset_size(reply->interfaces, NULL, + PHY_INTERFACE_MODE_MAX, + phy_interface_names, compact); + if (ret < 0) + return ret; + + size += ret; + } + + /* ETHTOOL_A_PORT_TYPE */ + size += nla_total_size(sizeof(u32)); + + /* ETHTOOL_A_PORT_UPSTREAM_PORT */ + if (reply->upstream_port) + size += nla_total_size(sizeof(u32)); + + return size; +} + +static int port_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_info, + const struct ethnl_reply_data *reply_data) +{ + bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS; + struct port_reply_data *reply = PORT_REPDATA(reply_data); + int ret, port_type; + + if (nla_put_u32(skb, ETHTOOL_A_PORT_ID, reply->port_id)) + return -EMSGSIZE; + + if (!reply->mii) { + ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_MODES, + reply->supported, NULL, + __ETHTOOL_LINK_MODE_MASK_NBITS, + link_mode_names, compact); + if (ret < 0) + return ret; + } else { + ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_INTERFACES, + reply->interfaces, NULL, + PHY_INTERFACE_MODE_MAX, + phy_interface_names, compact); + if (ret < 0) + return ret; + } + + port_type = ETHTOOL_PORT_TYPE_MDI; + if (reply->mii || reply->sfp) + port_type = ETHTOOL_PORT_TYPE_SFP; + + if (nla_put_u32(skb, ETHTOOL_A_PORT_TYPE, port_type)) + return -EMSGSIZE; + + if (reply->upstream_port && + nla_put_u32(skb, ETHTOOL_A_PORT_UPSTREAM_PORT, + reply->upstream_port)) + return -EMSGSIZE; + + return 0; +} + +struct port_dump_ctx { + struct port_req_info *req_info; + struct port_reply_data *reply_data; + unsigned long ifindex; + unsigned long pos_ifindex; + unsigned long pos_portid; +}; + +static struct port_dump_ctx * +port_dump_ctx_get(struct netlink_callback *cb) +{ + return (struct port_dump_ctx *)cb->ctx; +} + +int ethnl_port_dump_start(struct netlink_callback *cb) +{ + const struct genl_dumpit_info *info = genl_dumpit_info(cb); + struct port_dump_ctx *ctx = port_dump_ctx_get(cb); + struct nlattr **tb = info->info.attrs; + struct port_reply_data *reply_data; + struct port_req_info *req_info; + int ret; + + BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx)); + + if (tb[ETHTOOL_A_PORT_ID]) { + NL_SET_BAD_ATTR(info->info.extack, tb[ETHTOOL_A_PORT_ID]); + return -EINVAL; + } + + req_info = kzalloc_obj(*req_info); + if (!req_info) + return -ENOMEM; + + reply_data = kmalloc_obj(*reply_data); + if (!reply_data) { + ret = -ENOMEM; + goto free_req_info; + } + + ret = ethnl_parse_header_dev_get(&req_info->base, tb[ETHTOOL_A_PORT_HEADER], + genl_info_net(&info->info), + info->info.extack, false); + if (ret < 0) + goto free_rep_data; + + ctx->ifindex = 0; + ctx->pos_ifindex = 0; + + /* For filtered DUMP requests, let's just store the ifindex. We'll check + * again if the netdev is still there when looping over the netdev list + * in the DUMP loop. + */ + if (req_info->base.dev) { + ctx->ifindex = req_info->base.dev->ifindex; + netdev_put(req_info->base.dev, &req_info->base.dev_tracker); + req_info->base.dev = NULL; + } + + ctx->req_info = req_info; + ctx->reply_data = reply_data; + + return 0; + +free_rep_data: + kfree(reply_data); +free_req_info: + kfree(req_info); + + return ret; +} + +static int port_dump_one(struct sk_buff *skb, struct net_device *dev, + struct netlink_callback *cb) +{ + struct port_dump_ctx *ctx = port_dump_ctx_get(cb); + void *ehdr; + int ret; + + ehdr = ethnl_dump_put(skb, cb, ETHTOOL_MSG_PORT_GET_REPLY); + if (!ehdr) + return -EMSGSIZE; + + memset(ctx->reply_data, 0, sizeof(struct port_reply_data)); + ctx->reply_data->base.dev = dev; + + ret = port_prepare_data(&ctx->req_info->base, &ctx->reply_data->base, + genl_info_dump(cb)); + if (ret < 0) + goto out; + + ret = ethnl_fill_reply_header(skb, dev, ETHTOOL_A_PORT_HEADER); + if (ret < 0) + goto out; + + ret = port_fill_reply(skb, &ctx->req_info->base, &ctx->reply_data->base); + +out: + ctx->reply_data->base.dev = NULL; + if (ret < 0) + genlmsg_cancel(skb, ehdr); + else + genlmsg_end(skb, ehdr); + + return ret; +} + +static int port_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct port_dump_ctx *ctx = port_dump_ctx_get(cb); + struct net_device *dev; + struct phy_port *port; + int ret = 0; + + dev = ctx->req_info->base.dev; + + rtnl_lock(); + netdev_lock_ops(dev); + + if (!dev->link_topo) + goto out; + + xa_for_each_start(&dev->link_topo->ports, ctx->pos_portid, port, + ctx->pos_portid) { + ctx->req_info->port_id = ctx->pos_portid; + + ret = port_dump_one(skb, dev, cb); + if (ret == -ENODEV) + continue; + if (ret) + goto out; + } + + ret = 0; + +out: + netdev_unlock_ops(dev); + rtnl_unlock(); + + return ret; +} + +static int port_dump_all_dev(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct port_dump_ctx *ctx = port_dump_ctx_get(cb); + unsigned long start_ifindex = ctx->pos_ifindex; + struct net *net = sock_net(skb->sk); + netdevice_tracker dev_tracker; + struct net_device *dev; + int ret = 0; + + rcu_read_lock(); + for_each_netdev_dump(net, dev, ctx->pos_ifindex) { + if (ctx->pos_ifindex != start_ifindex) + ctx->pos_portid = 0; + + netdev_hold(dev, &dev_tracker, GFP_ATOMIC); + rcu_read_unlock(); + + ctx->req_info->base.dev = dev; + ret = port_dump_one_dev(skb, cb); + + rcu_read_lock(); + netdev_put(dev, &dev_tracker); + ctx->req_info->base.dev = NULL; + + if (ret) + break; + } + rcu_read_unlock(); + + return ret; +} + +int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + const struct genl_dumpit_info *info = genl_dumpit_info(cb); + struct port_dump_ctx *ctx = port_dump_ctx_get(cb); + int ret = 0; + + if (ctx->ifindex) { + netdevice_tracker dev_tracker; + struct net_device *dev; + + dev = netdev_get_by_index(genl_info_net(&info->info), + ctx->ifindex, &dev_tracker, + GFP_KERNEL); + if (!dev) + return -ENODEV; + + ctx->req_info->base.dev = dev; + ret = port_dump_one_dev(skb, cb); + + netdev_put(dev, &dev_tracker); + } else { + ret = port_dump_all_dev(skb, cb); + } + + return ret; +} + +int ethnl_port_dump_done(struct netlink_callback *cb) +{ + struct port_dump_ctx *ctx = port_dump_ctx_get(cb); + + kfree(ctx->req_info); + kfree(ctx->reply_data); + + return 0; +} + +const struct ethnl_request_ops ethnl_port_request_ops = { + .request_cmd = ETHTOOL_MSG_PORT_GET, + .reply_cmd = ETHTOOL_MSG_PORT_GET_REPLY, + .hdr_attr = ETHTOOL_A_PORT_HEADER, + .req_info_size = sizeof(struct port_req_info), + .reply_data_size = sizeof(struct port_reply_data), + + .parse_request = port_parse_request, + .prepare_data = port_prepare_data, + .reply_size = port_reply_size, + .fill_reply = port_fill_reply, +}; diff --git a/net/ethtool/strset.c b/net/ethtool/strset.c index 94c4718d31ae..0974714c34ec 100644 --- a/net/ethtool/strset.c +++ b/net/ethtool/strset.c @@ -116,6 +116,11 @@ static const struct strset_info info_template[] = { .count = __ETHTOOL_A_STATS_PHY_CNT, .strings = stats_phy_names, }, + [ETH_SS_PHY_INTERFACES] = { + .per_dev = false, + .count = PHY_INTERFACE_MODE_MAX, + .strings = phy_interface_names, + }, }; struct strset_req_info { From 8af404a3844bf036cd54ed5302e1cad1f3d75200 Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 16 Oct 2026 15:31:05 +0200 Subject: [PATCH 2093/2126] Documentation: networking: Update the phy_port infrastructure description With SFP now properly supported with phy_port, add some details in the documentation. Fix a typo along the way (driver -> driven). Reviewed-by: Andrew Lunn Reviewed-by: Christophe Leroy (CS GROUP) Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261016133107.54054-11-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- Documentation/networking/phy-port.rst | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/phy-port.rst b/Documentation/networking/phy-port.rst index 6e28d9094bce..2a9b1ec93b70 100644 --- a/Documentation/networking/phy-port.rst +++ b/Documentation/networking/phy-port.rst @@ -99,13 +99,29 @@ will eventually be able to report its own ksettings:: (_____)-----| Port | +------+ +SFP ports +========= + +SFP interfaces involve 2 distinct components, each represented by +a :c:type:`struct phy_port ` instance : + + - The SFP cage itself is a :c:type:`struct phy_port `. It's special + in that it's not an MDI interface, but rather a hot-pluggable MII. + The :c:type:`struct phy_port ` associated to it lists the different + MII interfaces we can use on the cage. + + - The SFP module, when inserted, will also be associated to a + :c:type:`struct phy_port `, that represents the various linkmodes + that it gives access to. The module's :c:type:`struct phy_port ` + doesn't supersede the cage's port, it references it through + the :c:type:`struct phy_port ` :c:member:`upstream_port` field. + Next steps ========== -As of writing this documentation, only ports controlled by PHY devices are -supported. The next steps will be to add the Netlink API to expose these -to userspace and add support for raw ports (controlled by some firmware, and directly -managed by the NIC driver). +As of writing this documentation, the port's presence and information can only +be queried, and it's not possible to change any of the port's settings or select +which one should be used. Another parallel task is the introduction of a MII muxing framework to allow the -control of non-PHY driver multi-port setups. +control of non-PHY driven multi-port setups. From e42329945d1613c2b41da9642b855f4612d8ea46 Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Sat, 17 Oct 2026 13:43:59 +0800 Subject: [PATCH 2094/2126] net: pcs: xpcs: add ANRESTART support for SGMII link recovery On some hardware using the DesignWare XPCS IP (e.g., RK3568 MAC side SGMII), the PCS does not automatically restart auto-negotiation when the link goes down and comes back up. Without an explicit ANRESTART, the link stays down forever. Add BMCR_ANRESTART in two places: 1. In xpcs_config_aneg_c37_sgmii(), when starting AN, set ANRESTART alongside ANENABLE to initiate a fresh negotiation. 2. In xpcs_get_state_c37_sgmii(), when link is down and AN completion is detected, clear the interrupt and trigger ANRESTART to restart the negotiation process. Propagate the return value of the restart so errors are not silently ignored. The restart cannot go through the .pcs_an_restart op: phylink only calls it for 802.3z interfaces, and SGMII is not one. Changing hardware state from pcs_get_state() is already done elsewhere in this driver (xpcs_get_state_c73() calls xpcs_soft_reset() and xpcs_do_config()), so the same pattern is used here. The latch is cleared before issuing the restart, not after: clearing it afterwards would discard a freshly latched ANCMPLT from the new negotiation. If an MDIO access fails at this point, it indicates an unrecoverable hardware condition until reset. Also clear DW_VR_MII_AN_INTR_STS in xpcs_config_aneg_c37_sgmii() before starting AN, matching what xpcs_config_aneg_c37_1000basex() already does. On the non-inband path the function now returns the result of that write instead of the DIG_CTRL1 modify. Update the comment in xpcs_config_aneg_c37_sgmii() to note that although the DesignWare databook says AN restart is not needed for MAC side SGMII, some implementations (e.g. Rockchip RK3568) require it to recover the link after a disconnect. This is not a fix for an existing mainline platform: the affected platform (RK3568 XPCS) is introduced later in the same series. Tested-by: Jiawen Wu Tested-by: Maxime Chevallier Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261017054406.1828061-2-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/pcs/pcs-xpcs.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index b415b93d77c1..6466e0ff2a98 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -761,7 +761,9 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, * DW xPCS used with DW EQoS MAC is always MAC side SGMII. * 4) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic * speed/duplex mode change by HW after SGMII AN complete) - * 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) + * 5) VR_MII_AN_INTR_STS = 0x0 (Clear CL37 AN complete status) + * 6) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) + * VR_MII_MMD_CTRL Bit(9) [AN_RESTART] = 1b (Restart SGMII AN) * * Note that VR_MII_MMD_CTRL is MII_BMCR. * @@ -769,7 +771,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, * SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from * PHY about the link state change after C28 AN is completed * between PHY and Link Partner. There is also no need to - * trigger AN restart for MAC-side SGMII. + * trigger AN restart for MAC-side SGMII on most devices. + * + * Note: While the DesignWare databook states that AN restart is + * not needed for MAC side SGMII, some implementations (e.g. + * Rockchip RK3568) exhibit a timing quirk when integrated with + * phylink and do not restart AN automatically when the link + * comes back up. An explicit AN restart is required on those + * parts to recover the link after a disconnect. */ mdio_ctrl = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR); if (mdio_ctrl < 0) @@ -816,9 +825,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, if (ret < 0) return ret; + /* Clear CL37 AN complete status */ + ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0); + if (ret < 0) + return ret; + if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR, - mdio_ctrl | BMCR_ANENABLE); + mdio_ctrl | BMCR_ANENABLE | BMCR_ANRESTART); return ret; } @@ -1093,9 +1107,18 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, return 0; } - /* Clear AN complete status or interrupt */ - if (state->an_complete) - xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0); + if (state->an_complete) { + /* Clear AN complete status or interrupt */ + ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0); + if (ret < 0) + return ret; + + /* Initiate the next round of AN */ + ret = xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART, + BMCR_ANRESTART); + if (ret < 0) + return ret; + } return 0; } From 20bd39c3c267013417d6dad11a5f6ed7f28dd87d Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Sat, 17 Oct 2026 13:44:00 +0800 Subject: [PATCH 2095/2126] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support Add device tree binding documentation for the Synopsys DesignWare XPCS integrated on the Rockchip RK3568 SoC. The XPCS is accessed over the APB3 bus and internally connected to a Naneng Combo SerDes PHY. It supports 1000BASE-X, SGMII, and QSGMII modes, with four MII ports. The MII port used by the SGMII link is derived from the MAC it is routed to: GMAC0 uses port 0, GMAC1 uses port 1. The port index is not an independent board-level configuration, so the binding does not describe the ports. If a future SoC needs per-port configuration that cannot be derived, pcs-handle argument cells can be added then. The CRU reset lines (SRST_XPCS*) are intentionally not described: no in-tree user requests them, and bring-up relies on the PD_PIPE power domain, the SerDes PHY and the in-IP soft reset. They can be added later as optional without breaking ABI. Reviewed-by: Rob Herring (Arm) Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261017054406.1828061-3-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- .../net/pcs/rockchip,rk3568-xpcs.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml diff --git a/Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml b/Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml new file mode 100644 index 000000000000..a331880eb11c --- /dev/null +++ b/Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pcs/rockchip,rk3568-xpcs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Rockchip RK3568 Synopsys DesignWare Ethernet PCS + +maintainers: + - Coia Prant + +description: | + Rockchip RK3568 SoC integrates a Synopsys DesignWare Ethernet Physical + Coding Sublayer (XPCS). + The PCS provides an interface between the Media Access Control (MAC) + and the Physical Medium Attachment (PMA) sublayer through a Media + Independent Interface (GMII). + + The XPCS is accessed over the APB3 bus and internally connected to a + Naneng Combo SerDes PHY. + It supports 1000BASE-X, SGMII and QSGMII modes. + +properties: + compatible: + const: rockchip,rk3568-xpcs + + reg: + maxItems: 1 + + clocks: + items: + - description: APB3 bus interface clock (clk_csr_i), required for register access + - description: EEE clock (clk_eee_i), required for Energy Efficient Ethernet operation + + clock-names: + items: + - const: csr + - const: eee + + phys: + maxItems: 1 + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - clocks + - clock-names + - phys + - power-domains + +additionalProperties: false + +examples: + - | + #include + #include + #include + + ethernet-pcs@fda00000 { + compatible = "rockchip,rk3568-xpcs"; + reg = <0xfda00000 0x200000>; + clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>; + clock-names = "csr", "eee"; + phys = <&combphy2 PHY_TYPE_SGMII>; + power-domains = <&power RK3568_PD_PIPE>; + }; From b9e7cb89aac8c073f29d897dbf5bda078237ca5e Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Sat, 17 Oct 2026 13:44:01 +0800 Subject: [PATCH 2096/2126] net: pcs: xpcs: add Rockchip RK3568 platform glue driver The RK3568 SoC integrates a Synopsys DesignWare XPCS that is accessed via APB3 memory-mapped registers. This driver provides the glue logic to make the XPCS accessible to the generic pcs-xpcs core. The XPCS block contains four MII ports (0..3). On RK3568 the MII port used by SGMII follows the MAC it is routed to: GMAC0 maps to port 0 and GMAC1 maps to port 1. The glue driver receives the port index from the MAC side and passes it to xpcs_create_mdiodev(). The hardware maps these ports to different MMDs: - port 0: MMD 7 (ROCKCHIP_MMD_MII) - port 1: MMD 2 (ROCKCHIP_MMD_MII1) - port 2: MMD 3 (ROCKCHIP_MMD_MII2) - port 3: MMD 4 (ROCKCHIP_MMD_MII3) This driver creates a virtual MDIO bus that translates MDIO operations to APB3 register accesses, with proper address remapping for each port. The generic xpcs driver then creates a phylink_pcs instance on top of this bus, allowing the MAC to use the PCS via the standard phylink API. The generic XPCS platform glue (pcs-xpcs-plat.o) is split out of the pcs_xpcs composite object into its own module, gated behind the new PCS_XPCS_PLATFORM symbol. There is no in-tree user of the generic snps,dw-xpcs glue that would need it selected by default, so the symbol has no default and platforms that need it select it explicitly. PCS_XPCS_ROCKCHIP selects GENERIC_PHY and PM_GENERIC_DOMAINS. ARCH_ROCKCHIP already selects PM, so the dependency of PM_GENERIC_DOMAINS on PM is satisfied on the target platform. The EEE multiplier is derived at runtime from the EEE clock rate instead of being hardcoded, because the clock is muxed between gpll200 (200 MHz) and cpll125 (125 MHz) and can be changed by the board or firmware. A 64-bit intermediate avoids overflow on 32-bit builds, and the result is clamped to the 4-bit DW_VR_MII_EEE_MULT_FACT_100NS field. Power management ================ The XPCS, its SerDes PHY and the SATA/PCIe controllers share the PD_PIPE power domain on RK3568. genpd powers the domain down during system suspend once every consumer is suspended, which also kills the SerDes and the XPCS. Boards that rely on MAC WoL need the PCS and SerDes alive to receive magic packets, so PD_PIPE must stay powered across system suspend. Keep it on by marking the XPCS as part of the wakeup path via device_set_wakeup_path(). genpd then leaves the domain powered, because the Rockchip power domain driver sets GENPD_FLAG_ACTIVE_WAKEUP on PD_PIPE, which makes genpd check the wakeup path of its consumers during system suspend. This is unconditional because the XPCS core currently has no platform callback through which a consumer could convey the MAC WoL state, and the state itself is dynamic: WoL is toggled at runtime via ethtool, so a static DT property cannot express it either. The affected hardware is limited to RK3568 boards using SGMII, which are always-on routers where system suspend is not a realistic use case; the extra power draw is therefore acceptable. Runtime PM is unaffected: the runtime callbacks only gate the CSR clock, and dev_pm_genpd_rpm_always_on() already keeps PD_PIPE on at runtime. Link: https://dl.radxa.com/rock3/docs/hw/datasheet/Rockchip%20RK3568%20TRM%20Part1%20V1.1-20210301.pdf (Page 59, CRU_CLKSEL_CON29) Link: https://dl.radxa.com/rock3/docs/hw/datasheet/Rockchip%20RK3568%20TRM%20Part2%20V1.1-20210301.pdf (Page 2078) Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261017054406.1828061-4-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/pcs/Kconfig | 23 ++ drivers/net/pcs/Makefile | 5 +- drivers/net/pcs/pcs-xpcs-rk.c | 598 ++++++++++++++++++++++++++++++++ include/linux/pcs/pcs-xpcs-rk.h | 11 + 4 files changed, 635 insertions(+), 2 deletions(-) create mode 100644 drivers/net/pcs/pcs-xpcs-rk.c create mode 100644 include/linux/pcs/pcs-xpcs-rk.h diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig index e417fd66f660..108d47257bee 100644 --- a/drivers/net/pcs/Kconfig +++ b/drivers/net/pcs/Kconfig @@ -12,6 +12,29 @@ config PCS_XPCS This module provides a driver and helper functions for Synopsys DesignWare XPCS controllers. +if PCS_XPCS + +config PCS_XPCS_PLATFORM + tristate "Generic XPCS controller support" + help + Generic DWXPCS driver for platforms that don't require any + platform specific code to function or is using platform + data for setup. + + If you have a controller with this interface, say Y or M here. + +config PCS_XPCS_ROCKCHIP + tristate "Rockchip XPCS controller support" + depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST) + select GENERIC_PHY + select PM_GENERIC_DOMAINS if PM + help + Support for XPCS controller on Rockchip RK356x SoC. + + If you have a Rockchip SoC with this interface, say Y or M here. + +endif # PCS_XPCS + config PCS_LYNX tristate help diff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile index 4f7920618b90..f9f6cf2578d7 100644 --- a/drivers/net/pcs/Makefile +++ b/drivers/net/pcs/Makefile @@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers -pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ - pcs-xpcs-nxp.o pcs-xpcs-wx.o +pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o +obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o +obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o obj-$(CONFIG_PCS_RZN1_MIIC) += pcs-rzn1-miic.o diff --git a/drivers/net/pcs/pcs-xpcs-rk.c b/drivers/net/pcs/pcs-xpcs-rk.c new file mode 100644 index 000000000000..698a43b75334 --- /dev/null +++ b/drivers/net/pcs/pcs-xpcs-rk.c @@ -0,0 +1,598 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Rockchip XPCS platform device driver + * + * Based on the Synopsys DesignWare XPCS platform driver. + * Copyright (C) 2024 Serge Semin + * + * Adapted for Rockchip SoCs, with reference to the Rockchip OEM driver. + * Copyright (C) 2026 Coia Prant + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcs-xpcs.h" + +struct dw_xpcs_rk { + struct platform_device *pdev; + struct mii_bus *bus; + void __iomem *reg_base; + struct phy *serdes_phy; + struct clk *csr_clk; + struct clk *eee_clk; + u8 eee_mult_fact; +}; + +static ptrdiff_t xpcs_rk_addr_format(int dev, int reg) +{ + return FIELD_PREP(0x70000, dev) | FIELD_PREP(0xffff, reg); +} + +static int xpcs_rk_read_reg(struct dw_xpcs_rk *pxpcs, int dev, int reg) +{ + ptrdiff_t csr; + int ret; + + csr = xpcs_rk_addr_format(dev, reg); + + ret = pm_runtime_resume_and_get(&pxpcs->pdev->dev); + if (ret) + return ret; + + ret = readl(pxpcs->reg_base + (csr << 2)) & 0xffff; + + pm_runtime_put(&pxpcs->pdev->dev); + return ret; +} + +static int xpcs_rk_write_reg(struct dw_xpcs_rk *pxpcs, int dev, int reg, u16 val) +{ + ptrdiff_t csr; + int ret; + + csr = xpcs_rk_addr_format(dev, reg); + + ret = pm_runtime_resume_and_get(&pxpcs->pdev->dev); + if (ret) + return ret; + + writel(val, pxpcs->reg_base + (csr << 2)); + + pm_runtime_put(&pxpcs->pdev->dev); + return 0; +} + +#define ROCKCHIP_MMD_MII1 2 +#define ROCKCHIP_MMD_MII2 3 +#define ROCKCHIP_MMD_MII3 4 +#define ROCKCHIP_MMD_PMAPMD 6 +#define ROCKCHIP_MMD_MII 7 + +static bool xpcs_rk_mdio_addr_validate(int addr) +{ + return !(addr < 0 || addr > 3); +} + +static int xpcs_rk_mdio_read_remapping(int addr, int dev) +{ + switch (dev) { + case MDIO_MMD_PMAPMD: + return ROCKCHIP_MMD_PMAPMD; + case MDIO_MMD_VEND2: + break; + default: + return -ENXIO; + } + + /* + * Reads are redirected by hardware to the port's read-only mirror; + * only writes have to be targeted at MII (see the write path). + */ + switch (addr) { + case 0: + return ROCKCHIP_MMD_MII; + case 1: + return ROCKCHIP_MMD_MII1; + case 2: + return ROCKCHIP_MMD_MII2; + case 3: + return ROCKCHIP_MMD_MII3; + default: + return -ENODEV; + } +} + +static int xpcs_rk_mdio_write_remapping(int addr, int dev, int reg) +{ + switch (dev) { + case MDIO_MMD_PMAPMD: + return ROCKCHIP_MMD_PMAPMD; + case MDIO_MMD_VEND2: + break; + default: + return -ENXIO; + } + + /* + * These registers physically live only in MII (the management port). + * Ports 1-3 expose read-only mirrors of these bits, so writes must + * always target MII; the read path remaps per address and the + * hardware redirects to the port's mirror. + */ + switch (reg) { + case DW_VR_MII_AN_CTRL: + case DW_VR_MII_AN_INTR_STS: + case DW_VR_MII_EEE_MCTRL0: + case DW_VR_MII_EEE_MCTRL1: + case DW_VR_MII_DIG_CTRL2: + return ROCKCHIP_MMD_MII; + default: + break; + } + + switch (addr) { + case 0: + return ROCKCHIP_MMD_MII; + case 1: + return ROCKCHIP_MMD_MII1; + case 2: + return ROCKCHIP_MMD_MII2; + case 3: + return ROCKCHIP_MMD_MII3; + default: + return -ENODEV; + } +} + +static int xpcs_rk_read_c22(struct mii_bus *bus, int addr, int reg) +{ + struct dw_xpcs_rk *pxpcs = bus->priv; + int dev; + + if (!xpcs_rk_mdio_addr_validate(addr)) + return -ENODEV; + + dev = xpcs_rk_mdio_read_remapping(addr, MDIO_MMD_VEND2); + if (dev < 0) + return 0xffff; + + return xpcs_rk_read_reg(pxpcs, dev, reg); +} + +static int xpcs_rk_write_c22(struct mii_bus *bus, int addr, int reg, u16 val) +{ + struct dw_xpcs_rk *pxpcs = bus->priv; + int dev; + + if (!xpcs_rk_mdio_addr_validate(addr)) + return -ENODEV; + + dev = xpcs_rk_mdio_write_remapping(addr, MDIO_MMD_VEND2, reg); + if (dev < 0) + return 0; + + return xpcs_rk_write_reg(pxpcs, dev, reg, val); +} + +static int xpcs_rk_read_c45(struct mii_bus *bus, int addr, int dev, int reg) +{ + struct dw_xpcs_rk *pxpcs = bus->priv; + + if (!xpcs_rk_mdio_addr_validate(addr)) + return -ENODEV; + + dev = xpcs_rk_mdio_read_remapping(addr, dev); + if (dev < 0) + return 0xffff; + + return xpcs_rk_read_reg(pxpcs, dev, reg); +} + +static int xpcs_rk_write_c45(struct mii_bus *bus, int addr, int dev, int reg, u16 val) +{ + struct dw_xpcs_rk *pxpcs = bus->priv; + + if (!xpcs_rk_mdio_addr_validate(addr)) + return -ENODEV; + + dev = xpcs_rk_mdio_write_remapping(addr, dev, reg); + if (dev < 0) + return 0; + + return xpcs_rk_write_reg(pxpcs, dev, reg, val); +} + +static struct dw_xpcs_rk *xpcs_rk_create_data(struct platform_device *pdev) +{ + struct dw_xpcs_rk *pxpcs; + + pxpcs = devm_kzalloc(&pdev->dev, sizeof(*pxpcs), GFP_KERNEL); + if (!pxpcs) + return ERR_PTR(-ENOMEM); + + pxpcs->pdev = pdev; + + dev_set_drvdata(&pdev->dev, pxpcs); + + return pxpcs; +} + +static int xpcs_rk_serdes_phy_init(struct dw_xpcs_rk *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + + pxpcs->serdes_phy = devm_phy_get(dev, NULL); + if (IS_ERR(pxpcs->serdes_phy)) + return dev_err_probe(dev, PTR_ERR(pxpcs->serdes_phy), + "Failed to get SerDes PHY\n"); + + return 0; +} + +static void xpcs_rk_serdes_phy_poweroff(void *data) +{ + struct dw_xpcs_rk *pxpcs = data; + struct device *dev = &pxpcs->pdev->dev; + + phy_power_off(pxpcs->serdes_phy); + phy_exit(pxpcs->serdes_phy); + + dev_pm_genpd_rpm_always_on(dev, false); +} + +static int xpcs_rk_serdes_phy_poweron(struct dw_xpcs_rk *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + int ret; + + /* + * The power domain is required and must be enabled, which allows us to + * dynamically turn the CSR clock on/off using PM while keeping the PCS + * powered on. + */ + ret = dev_pm_genpd_rpm_always_on(dev, true); + if (ret) { + dev_err(dev, "Failed to power on power-domains\n"); + return ret; + } + + ret = phy_init(pxpcs->serdes_phy); + if (ret) { + dev_err(dev, "Failed to init SerDes PHY\n"); + goto pm_domain; + } + + ret = phy_power_on(pxpcs->serdes_phy); + if (ret) { + dev_err(dev, "Failed to power on SerDes PHY\n"); + goto serdes_phy; + } + + ret = devm_add_action_or_reset(dev, xpcs_rk_serdes_phy_poweroff, pxpcs); + if (ret) { + dev_err(dev, "Failed to register devm for SerDes PHY: %d\n", ret); + return ret; + } + + return 0; + +serdes_phy: + phy_exit(pxpcs->serdes_phy); +pm_domain: + dev_pm_genpd_rpm_always_on(dev, false); + return ret; +} + +static int xpcs_rk_init_res(struct dw_xpcs_rk *pxpcs) +{ + struct platform_device *pdev = pxpcs->pdev; + struct device *dev = &pdev->dev; + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(dev, "No reg-space found\n"); + return -EINVAL; + } + + if (resource_size(res) < SZ_2M) { + dev_err(dev, "Invalid reg-space size\n"); + return -EINVAL; + } + + pxpcs->reg_base = devm_ioremap_resource(dev, res); + if (IS_ERR(pxpcs->reg_base)) { + dev_err(dev, "Failed to map reg-space\n"); + return PTR_ERR(pxpcs->reg_base); + } + + return 0; +} + +static void xpcs_rk_exit_clk(void *data) +{ + struct dw_xpcs_rk *pxpcs = data; + struct device *dev = &pxpcs->pdev->dev; + + pm_runtime_force_suspend(dev); + clk_disable_unprepare(pxpcs->eee_clk); +} + +static int xpcs_rk_init_clk(struct dw_xpcs_rk *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + unsigned long rate; + u64 mult; + int ret; + + pxpcs->csr_clk = devm_clk_get(dev, "csr"); + if (IS_ERR(pxpcs->csr_clk)) + return dev_err_probe(dev, PTR_ERR(pxpcs->csr_clk), + "Failed to get CSR clock\n"); + + pxpcs->eee_clk = devm_clk_get(dev, "eee"); + if (IS_ERR(pxpcs->eee_clk)) + return dev_err_probe(dev, PTR_ERR(pxpcs->eee_clk), + "Failed to get EEE clock\n"); + + ret = clk_prepare_enable(pxpcs->eee_clk); + if (ret) { + dev_err(dev, "Failed to enable EEE clock\n"); + return ret; + } + + pm_runtime_set_suspended(dev); + pm_runtime_enable(dev); + + ret = devm_add_action_or_reset(dev, xpcs_rk_exit_clk, pxpcs); + if (ret) { + dev_err(dev, "Failed to register devm for EEE clock: %d\n", ret); + return ret; + } + + /* + * Compute the multiplier for the EEE clock so that + * clk_eee_period * (mult_fact + 1) falls within 80..120 ns. + * + * On RK3568, clk_xpcs_eee is muxed between gpll200 (200 MHz, 5 ns) + * and cpll125 (125 MHz, 8 ns), selected by CRU_CLKSEL_CON29 bit 13. + * The reset value is 0 (200 MHz), but derive the value at runtime to + * stay correct if the mux is changed by a board. + * + * Use a 64-bit intermediate: on 32-bit builds, 100 * 200000000 + * does not fit in unsigned long. Clamp to the 4-bit + * DW_VR_MII_EEE_MULT_FACT_100NS field. The mux only provides + * 125 MHz or 200 MHz, so the rate cannot drop below the 5 MHz + * threshold where DIV_ROUND_CLOSEST_ULL() would return 0 and the + * subtraction below would underflow. + */ + rate = clk_get_rate(pxpcs->eee_clk); + if (!rate) + return dev_err_probe(dev, -EINVAL, "Invalid EEE clock rate\n"); + + mult = DIV_ROUND_CLOSEST_ULL(100ULL * rate, NSEC_PER_SEC) - 1; + pxpcs->eee_mult_fact = min_t(u64, mult, 15); + return 0; +} + +static int xpcs_rk_init_bus(struct dw_xpcs_rk *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + static atomic_t id = ATOMIC_INIT(-1); + struct mii_bus *bus; + int ret; + + bus = devm_mdiobus_alloc_size(dev, 0); + if (!bus) + return -ENOMEM; + + bus->name = "Rockchip DW XPCS MCI/APB3"; + bus->read = xpcs_rk_read_c22; + bus->write = xpcs_rk_write_c22; + bus->read_c45 = xpcs_rk_read_c45; + bus->write_c45 = xpcs_rk_write_c45; + bus->phy_mask = ~0; + bus->parent = dev; + bus->priv = pxpcs; + + snprintf(bus->id, MII_BUS_ID_SIZE, + "rockchip_dwxpcs-%x", atomic_inc_return(&id)); + + /* + * MDIO-bus here serves as just a back-end engine abstracting out + * the MDIO and MCI/APB3 IO interfaces utilized for the Rockchip DWXPCS CSRs + * access. + */ + ret = devm_mdiobus_register(dev, bus); + if (ret) { + dev_err(dev, "Failed to create MDIO bus\n"); + return ret; + } + + pxpcs->bus = bus; + return 0; +} + +static int xpcs_rk_probe(struct platform_device *pdev) +{ + struct dw_xpcs_rk *pxpcs; + int ret; + + pxpcs = xpcs_rk_create_data(pdev); + if (IS_ERR(pxpcs)) + return PTR_ERR(pxpcs); + + /* + * The XPCS lives in the PD_PIPE power domain. The domain must be + * powered on before any register access, otherwise the SoC will + * trigger a synchronous external abort (SError). + * + * Accessing the XPCS registers also requires a TX clock from the + * SerDes, which is needed for the soft reset. + */ + ret = xpcs_rk_serdes_phy_init(pxpcs); + if (ret) + return ret; + + ret = xpcs_rk_serdes_phy_poweron(pxpcs); + if (ret) + return ret; + + ret = xpcs_rk_init_res(pxpcs); + if (ret) + return ret; + + ret = xpcs_rk_init_clk(pxpcs); + if (ret) + return ret; + + ret = xpcs_rk_init_bus(pxpcs); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id xpcs_rk_of_ids[] = { + { .compatible = "rockchip,rk3568-xpcs" }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, xpcs_rk_of_ids); + +struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int port) +{ + struct platform_device *pdev; + struct dw_xpcs_rk *pxpcs; + struct dw_xpcs *xpcs; + + if (!of_device_is_available(pcs)) + return ERR_PTR(-ENODEV); + + if (!of_match_node(xpcs_rk_of_ids, pcs)) + return ERR_PTR(-EINVAL); + + if (!xpcs_rk_mdio_addr_validate(port)) + return ERR_PTR(-EINVAL); + + pdev = of_find_device_by_node(pcs); + if (!pdev) + return ERR_PTR(-EPROBE_DEFER); + + /* + * Establish the device link before reading the supplier's drvdata. + * device_link_add() does not fail on a supplier that is unbinding; + * it creates the link in DL_STATE_SUPPLIER_UNBIND. + * + * The check below only confirms that the supplier is bound at this + * point. It does not fully protect against a concurrent unbind + * between here and xpcs_create_mdiodev(); closing that window would + * require reading a managed link's status or device_lock(), neither + * of which is acceptable on this path. The window is small and + * requires an explicit unbind from userspace. Discussed on + * driver-core. + * + * The link is released automatically when the consumer device is + * destroyed (DL_FLAG_AUTOREMOVE_CONSUMER), so no explicit + * device_link_remove() is needed on the failure paths. + */ + if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) { + put_device(&pdev->dev); + return ERR_PTR(-EPROBE_DEFER); + } + + if (READ_ONCE(pdev->dev.links.status) != DL_DEV_DRIVER_BOUND) { + put_device(&pdev->dev); + return ERR_PTR(-EPROBE_DEFER); + } + + pxpcs = platform_get_drvdata(pdev); + if (!pxpcs || !pxpcs->bus) { + put_device(&pdev->dev); + return ERR_PTR(-EPROBE_DEFER); + } + + xpcs = xpcs_create_mdiodev(pxpcs->bus, port); + if (IS_ERR(xpcs)) { + put_device(&pdev->dev); + return xpcs; + } + + xpcs_config_eee_mult_fact(xpcs, pxpcs->eee_mult_fact); + put_device(&pdev->dev); + return xpcs; +} +EXPORT_SYMBOL_GPL(xpcs_rk_create); + +static int xpcs_rk_pm_runtime_suspend(struct device *dev) +{ + struct dw_xpcs_rk *pxpcs = dev_get_drvdata(dev); + + clk_disable_unprepare(pxpcs->csr_clk); + + return 0; +} + +static int xpcs_rk_pm_runtime_resume(struct device *dev) +{ + struct dw_xpcs_rk *pxpcs = dev_get_drvdata(dev); + + return clk_prepare_enable(pxpcs->csr_clk); +} + +static int xpcs_rk_system_suspend(struct device *dev) +{ + /* + * Keep the PD_PIPE power domain on during system suspend. + * + * PD_PIPE is shared with SATA/PCIe and would be powered down by + * genpd once all its consumers are suspended, killing the SerDes + * and breaking MAC WoL. Mark the XPCS as part of the wakeup path + * so genpd keeps the domain on. Unconditional because the XPCS + * core has no callback to convey the MAC WoL state. + */ + device_set_wakeup_path(dev); + return 0; +} + +static int xpcs_rk_system_resume(struct device *dev) +{ + return 0; +} + +static _DEFINE_DEV_PM_OPS(xpcs_rk_pm_ops, + xpcs_rk_system_suspend, xpcs_rk_system_resume, + xpcs_rk_pm_runtime_suspend, xpcs_rk_pm_runtime_resume, + NULL); + +static struct platform_driver xpcs_rk_driver = { + .probe = xpcs_rk_probe, + .driver = { + .name = "rk_xpcs-dwxpcs", + .pm = pm_ptr(&xpcs_rk_pm_ops), + .of_match_table = xpcs_rk_of_ids, + }, +}; +module_platform_driver(xpcs_rk_driver); + +MODULE_DESCRIPTION("Rockchip XPCS platform device driver"); +MODULE_AUTHOR("Coia Prant "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/pcs/pcs-xpcs-rk.h b/include/linux/pcs/pcs-xpcs-rk.h new file mode 100644 index 000000000000..e3ca3d51f7c7 --- /dev/null +++ b/include/linux/pcs/pcs-xpcs-rk.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_PCS_XPCS_ROCKCHIP_H +#define __LINUX_PCS_XPCS_ROCKCHIP_H + +#include +#include +#include + +struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int port); + +#endif /* __LINUX_PCS_XPCS_ROCKCHIP_H */ From dffa8241fca593d8109c2e1b86e106569ce6184c Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Sat, 17 Oct 2026 13:44:02 +0800 Subject: [PATCH 2097/2126] dt-bindings: net: rockchip-dwmac: document pcs-handle The Rockchip GMAC binding needs to describe the PCS reference used by the SGMII support added later in this series. The property will be parsed by rk_pcs_init(), and a missing phandle fails the probe. Add it and require it when phy-mode is "sgmii" on rockchip,rk3568-gmac, the only SoC in this binding that has SGMII support. Reviewed-by: Rob Herring (Arm) Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261017054406.1828061-5-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- .../bindings/net/rockchip-dwmac.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml b/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml index 3ec3f6dc2a12..e8dda1961ab3 100644 --- a/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/rockchip-dwmac.yaml @@ -120,6 +120,12 @@ properties: maximum: 0x7F default: 0x10 + pcs-handle: + description: + Specifies a reference to a node representing the PCS device + connected to this GMAC. Required when phy-mode is "sgmii". + maxItems: 1 + phy-supply: description: PHY regulator @@ -162,6 +168,27 @@ allOf: clocks: minItems: 5 + - if: + properties: + compatible: + contains: + const: rockchip,rk3568-gmac + then: + required: + - phy-mode + + - if: + properties: + compatible: + contains: + const: rockchip,rk3568-gmac + phy-mode: + contains: + const: sgmii + then: + required: + - pcs-handle + unevaluatedProperties: false examples: From 5cd3229579ef952e5f73cfaefb6f067ad395f1c7 Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Sat, 17 Oct 2026 13:44:03 +0800 Subject: [PATCH 2098/2126] net: stmmac: dwmac-rk: add SGMII support for RK3568 The RK3568 SoC integrates a Synopsys DesignWare XPCS that can be connected to GMAC0 or GMAC1 in SGMII mode. Add the necessary glue logic to support this configuration. The current dwmac-rk driver does not support SGMII mode. SGMII requires a PCS to handle auto-negotiation and link state reporting, but the existing driver only supports RGMII and RMII. Add a set_to_sgmii() callback to configure the GMAC GRF register for SGMII mode (bit 7 set, interface selection bits 4:6 ignored when set). Also add a set_to_rmii() callback for rk3568 to explicitly clear bit 7, since the new SGMII path leaves it set and the RMII branch previously relied on the SoC reset value. Provide pcs_init/pcs_exit callbacks to create/destroy the XPCS via xpcs_rk_create() from the Rockchip XPCS platform driver, and a select_pcs callback to return the XPCS to phylink. The MII port passed to xpcs_rk_create() is the GMAC id (bsp_priv->id): GMAC0 maps to port 0, GMAC1 maps to port 1, matching the hardware routing. SGMII is not added to rk_get_interfaces(): it comes from the XPCS's own supported_interfaces, merged by stmmac_phylink_setup(). The SerDes PHY and the PD_PIPE power domain are owned by the XPCS driver rather than managed through the stmmac serdes_poweron/serdes_poweroff callbacks, which are legacy and meant for single-MAC platforms. On RK3568 the XPCS is the natural owner of the shared SerDes. DWMAC_ROCKCHIP selects PCS_XPCS_ROCKCHIP. PCS_XPCS itself is already selected by STMMAC_ETH, and PM is selected by ARCH_ROCKCHIP, so no further selects are needed. Reorder rk_gmac_powerup() so that gmac_clk_enable() is called before the SGMII check. The SGMII path skips rk_get_phy_intf_sel(), so the clock must be enabled earlier to cover all register accesses in that path. While at it, unify the error unwinding into a single clk_disable label and add error handling for the default (unhandled interface) case. SGMII In-band vs Out-of-band ============================ On RK3568, the MAC clock is fixed at 125 MHz and cannot be changed per speed. Out-of-band mode requires the MAC to change its clock to 125/25/2.5 MHz for 1000/100/10 Mbps respectively, which the hardware does not support here. The driver therefore clears rk_set_clk_tx_rate() and the clock stays at 125 MHz. The PCS is still told the speed in out-of-band mode (through a BMCR write in xpcs_link_up_sgmii_1000basex()), but the MAC clock does not follow. At 10/100 Mbps this gives working TX and failing RX. Enable default_an_inband for SGMII and clear rk_set_clk_tx_rate(), so phylink uses in-band mode, where the PCS is responsible for speed/duplex negotiation. Note that default_an_inband can be overridden by a fixed-link node, and phylink may also fall back to out-of-band if the PHY does not support in-band signalling. Out-of-band SGMII is not supported by this driver. The only out-of-band configuration that would work is 1000BASE-X with a fixed-link, where the MAC clock stays at 125 MHz; 10/100 Mbps gives working TX and failing RX. Boards must use in-band mode (managed = "in-band-status" or an in-band capable PHY). 1000BASE-X is not enabled by this series; it may be added later if there is a user for it. Link: https://dl.radxa.com/rock3/docs/hw/datasheet/Rockchip%20RK3568%20TRM%20Part1%20V1.1-20210301.pdf (Page 386) Reviewed-by: Maxime Chevallier Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261017054406.1828061-6-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 133 +++++++++++++++--- 2 files changed, 113 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index ab3c4cf96423..c6559e749c0c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -170,6 +170,7 @@ config DWMAC_ROCKCHIP default ARCH_ROCKCHIP depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST) select MFD_SYSCON + select PCS_XPCS_ROCKCHIP help Support for Ethernet controller on Rockchip RK3288 SoC. diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 72bdbcb5e863..c4db919ec164 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "stmmac_platform.h" @@ -47,6 +48,7 @@ struct rk_gmac_ops { void (*set_to_rgmii)(struct rk_priv_data *bsp_priv, int tx_delay, int rx_delay); void (*set_to_rmii)(struct rk_priv_data *bsp_priv); + void (*set_to_sgmii)(struct rk_priv_data *bsp_priv); int (*set_speed)(struct rk_priv_data *bsp_priv, phy_interface_t interface, int speed); void (*integrated_phy_powerup)(struct rk_priv_data *bsp_priv); @@ -63,6 +65,7 @@ struct rk_gmac_ops { bool clock_grf_reg_in_php; bool supports_rgmii; bool supports_rmii; + bool supports_sgmii; bool php_grf_required; bool regs_valid; u32 regs[]; @@ -98,6 +101,7 @@ struct rk_priv_data { bool integrated_phy; bool supports_rgmii; bool supports_rmii; + bool supports_sgmii; struct clk_bulk_data *clks; int num_clks; @@ -809,6 +813,8 @@ static const struct rk_gmac_ops rk3528_ops = { #define RK3568_GRF_GMAC1_CON1 0x038c /* RK3568_GRF_GMAC0_CON1 && RK3568_GRF_GMAC1_CON1 */ +#define RK3568_GMAC_MODE_RMII_RGMII GRF_CLR_BIT(7) +#define RK3568_GMAC_MODE_SGMII_QSGMII GRF_BIT(7) #define RK3568_GMAC_FLOW_CTRL GRF_BIT(3) #define RK3568_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(3) #define RK3568_GMAC_RXCLK_DLY_ENABLE GRF_BIT(1) @@ -836,6 +842,16 @@ static int rk3568_init(struct rk_priv_data *bsp_priv) } } +static void rk3568_set_to_rmii(struct rk_priv_data *bsp_priv) +{ + u32 con1; + + con1 = (bsp_priv->id == 1) ? RK3568_GRF_GMAC1_CON1 : + RK3568_GRF_GMAC0_CON1; + + regmap_write(bsp_priv->grf, con1, RK3568_GMAC_MODE_RMII_RGMII); +} + static void rk3568_set_to_rgmii(struct rk_priv_data *bsp_priv, int tx_delay, int rx_delay) { @@ -851,19 +867,31 @@ static void rk3568_set_to_rgmii(struct rk_priv_data *bsp_priv, RK3568_GMAC_CLK_TX_DL_CFG(tx_delay)); regmap_write(bsp_priv->grf, con1, + RK3568_GMAC_MODE_RMII_RGMII | RK3568_GMAC_RXCLK_DLY_ENABLE | RK3568_GMAC_TXCLK_DLY_ENABLE); } +static void rk3568_set_to_sgmii(struct rk_priv_data *bsp_priv) +{ + u32 con1; + + con1 = (bsp_priv->id == 1) ? RK3568_GRF_GMAC1_CON1 : + RK3568_GRF_GMAC0_CON1; + + regmap_write(bsp_priv->grf, con1, RK3568_GMAC_MODE_SGMII_QSGMII); +} + static const struct rk_gmac_ops rk3568_ops = { .init = rk3568_init, + .set_to_rmii = rk3568_set_to_rmii, .set_to_rgmii = rk3568_set_to_rgmii, + .set_to_sgmii = rk3568_set_to_sgmii, + .set_speed = rk_set_clk_mac_speed, .gmac_phy_intf_sel_mask = GENMASK_U16(6, 4), - .supports_rmii = true, - .regs_valid = true, .regs = { 0xfe2a0000, /* gmac0 */ @@ -1211,6 +1239,44 @@ static void rk_phy_powerdown(struct rk_priv_data *bsp_priv) dev_err(bsp_priv->dev, "fail to disable phy-supply\n"); } +static int rk_pcs_init(struct stmmac_priv *priv) +{ + struct rk_priv_data *bsp_priv = priv->plat->bsp_priv; + struct device_node *node = priv->device->of_node; + struct device_node *pcs_node; + struct dw_xpcs *xpcs; + + pcs_node = of_parse_phandle(node, "pcs-handle", 0); + if (!pcs_node) + return -ENODEV; + + xpcs = xpcs_rk_create(priv->device, pcs_node, bsp_priv->id); + of_node_put(pcs_node); + if (IS_ERR(xpcs)) + return PTR_ERR(xpcs); + + priv->hw->xpcs = xpcs; + return 0; +} + +static void rk_pcs_exit(struct stmmac_priv *priv) +{ + if (!priv->hw->xpcs) + return; + + xpcs_destroy(priv->hw->xpcs); + priv->hw->xpcs = NULL; +} + +static struct phylink_pcs *rk_select_pcs(struct stmmac_priv *priv, + phy_interface_t interface) +{ + if (!priv->hw->xpcs) + return NULL; + + return xpcs_to_phylink_pcs(priv->hw->xpcs); +} + static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev, struct plat_stmmacenet_data *plat, const struct rk_gmac_ops *ops) @@ -1333,6 +1399,7 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev, bsp_priv->supports_rgmii = ops->supports_rgmii || !!ops->set_to_rgmii; bsp_priv->supports_rmii = ops->supports_rmii || !!ops->set_to_rmii; + bsp_priv->supports_sgmii = ops->supports_sgmii || !!ops->set_to_sgmii; if (ops->init) { ret = ops->init(bsp_priv); @@ -1364,6 +1431,10 @@ static int rk_gmac_check_ops(struct rk_priv_data *bsp_priv) if (!bsp_priv->supports_rmii) return -EINVAL; break; + case PHY_INTERFACE_MODE_SGMII: + if (!bsp_priv->supports_sgmii) + return -EINVAL; + break; default: dev_err(bsp_priv->dev, "unsupported interface %d", bsp_priv->phy_iface); @@ -1382,16 +1453,19 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) if (ret) return ret; - ret = rk_get_phy_intf_sel(bsp_priv->phy_iface); - if (ret < 0) - return ret; - - intf = ret; - ret = gmac_clk_enable(bsp_priv, true); if (ret) return ret; + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_SGMII) + goto set_mode; + + ret = rk_get_phy_intf_sel(bsp_priv->phy_iface); + if (ret < 0) + goto clk_disable; + + intf = ret; + if (bsp_priv->gmac_phy_intf_sel_mask || bsp_priv->gmac_rmii_mode_mask) { /* If defined, encode the phy_intf_sel value */ @@ -1402,10 +1476,8 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) bsp_priv->gmac_rmii_mode_mask); ret = rk_write_gmac_grf_reg(bsp_priv, val); - if (ret < 0) { - gmac_clk_enable(bsp_priv, false); - return ret; - } + if (ret < 0) + goto clk_disable; } if (bsp_priv->clock.rmii_mode_mask) { @@ -1413,13 +1485,12 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) bsp_priv->clock.rmii_mode_mask); ret = rk_write_clock_grf_reg(bsp_priv, val); - if (ret < 0) { - gmac_clk_enable(bsp_priv, false); - return ret; - } + if (ret < 0) + goto clk_disable; } - /*rmii or rgmii*/ +set_mode: + /* rmii, rgmii, sgmii */ switch (bsp_priv->phy_iface) { case PHY_INTERFACE_MODE_RGMII: dev_info(dev, "init for RGMII\n"); @@ -1450,15 +1521,20 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) if (bsp_priv->ops->set_to_rmii) bsp_priv->ops->set_to_rmii(bsp_priv); break; + case PHY_INTERFACE_MODE_SGMII: + dev_info(dev, "init for SGMII\n"); + if (bsp_priv->ops->set_to_sgmii) + bsp_priv->ops->set_to_sgmii(bsp_priv); + break; default: dev_err(dev, "NO interface defined!\n"); + ret = -EINVAL; + goto clk_disable; } ret = rk_phy_powerup(bsp_priv); - if (ret) { - gmac_clk_enable(bsp_priv, false); - return ret; - } + if (ret) + goto clk_disable; pm_runtime_get_sync(dev); @@ -1466,6 +1542,10 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) bsp_priv->ops->integrated_phy_powerup(bsp_priv); return 0; + +clk_disable: + gmac_clk_enable(bsp_priv, false); + return ret; } static void rk_gmac_powerdown(struct rk_priv_data *gmac) @@ -1605,6 +1685,17 @@ static int rk_gmac_probe(struct platform_device *pdev) plat_dat->suspend = rk_gmac_suspend; plat_dat->resume = rk_gmac_resume; + if (plat_dat->phy_interface == PHY_INTERFACE_MODE_SGMII) { + /* SGMII clock always runs at 125 MHz */ + plat_dat->set_clk_tx_rate = NULL; + + /* SGMII requires a PCS */ + plat_dat->default_an_inband = true; + plat_dat->pcs_init = rk_pcs_init; + plat_dat->pcs_exit = rk_pcs_exit; + plat_dat->select_pcs = rk_select_pcs; + } + plat_dat->bsp_priv = rk_gmac_setup(pdev, plat_dat, data); if (IS_ERR(plat_dat->bsp_priv)) return PTR_ERR(plat_dat->bsp_priv); From 5e91edfb0e4512e9b84ffa0264d5872fa600e050 Mon Sep 17 00:00:00 2001 From: Coia Prant Date: Sat, 17 Oct 2026 13:44:04 +0800 Subject: [PATCH 2099/2126] MAINTAINERS: add entry for Rockchip XPCS driver Add a MAINTAINERS entry for the Rockchip RK3568 XPCS platform driver and its device tree binding. Include the relevant mailing lists (netdev and linux-rockchip) so that future patches are properly distributed. Signed-off-by: Coia Prant Link: https://patch.msgid.link/20261017054406.1828061-7-coiaprant@gmail.com Signed-off-by: Jakub Kicinski --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index e7640995959c..a069b893f4d4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23777,6 +23777,15 @@ S: Maintained F: Documentation/devicetree/bindings/sound/rockchip,rk3576-sai.yaml F: sound/soc/rockchip/rockchip_sai.* +ROCKCHIP XPCS DRIVER +M: Coia Prant +L: netdev@vger.kernel.org +L: linux-rockchip@lists.infradead.org +S: Maintained +F: Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml +F: drivers/net/pcs/pcs-xpcs-rk.c +F: include/linux/pcs/pcs-xpcs-rk.h + ROCKER DRIVER M: Jiri Pirko L: netdev@vger.kernel.org From bbee99902520f214cafe183f30b9db29ab9b315f Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 21 Oct 2026 01:55:57 +0000 Subject: [PATCH 2100/2126] netmem: rename get/put_net_iov() to net_iov_inc/dec_ref() Follow the object_action() naming convention for net_iov non-page_pool reference helpers by renaming get_net_iov() and put_net_iov() to net_iov_inc_ref() and net_iov_dec_ref(), and renaming net_devmem_get_net_iov() and net_devmem_put_net_iov() to net_devmem_net_iov_inc_ref() and net_devmem_net_iov_dec_ref(). Use *_inc_ref() and *_dec_ref() rather than *_ref() and *_unref() to pair symmetrically with netmem_inc_ref() and netmem_dec_ref() (since netmem_ref is already the typedef for the generic network memory handle). Suggested-by: Jakub Kicinski Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261021015558.4124825-2-almasrymina@google.com Signed-off-by: Jakub Kicinski --- include/net/netmem.h | 12 ++++++------ net/core/devmem.c | 4 ++-- net/core/devmem.h | 10 +++++----- net/core/net_test.c | 12 ++++++------ net/core/skbuff.c | 20 ++++++++++---------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/net/netmem.h b/include/net/netmem.h index 193de0d21490..7f36c734edcd 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -409,21 +409,21 @@ static inline bool net_is_devmem_iov(const struct net_iov *niov) } #endif -void get_net_iov(struct net_iov *niov); -void put_net_iov(struct net_iov *niov); +void net_iov_inc_ref(struct net_iov *niov); +void net_iov_dec_ref(struct net_iov *niov); /** * get_netmem - acquire a non-page_pool reference on a netmem * @netmem: netmem to reference * * Acquires a non-pp backing reference (page._refcount via get_page() or - * binding->ref via get_net_iov()) regardless of page_pool membership. + * binding->ref via net_iov_inc_ref()) regardless of page_pool membership. * Counterpart to put_netmem(). */ static __always_inline void get_netmem(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) - get_net_iov(netmem_to_net_iov(netmem)); + net_iov_inc_ref(netmem_to_net_iov(netmem)); else get_page(netmem_to_page(netmem)); } @@ -433,13 +433,13 @@ static __always_inline void get_netmem(netmem_ref netmem) * @netmem: netmem to unreference * * Drops a non-pp backing reference (page._refcount via put_page() or - * binding->ref via put_net_iov()) regardless of page_pool membership. + * binding->ref via net_iov_dec_ref()) regardless of page_pool membership. * Counterpart to get_netmem(). */ static __always_inline void put_netmem(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) - put_net_iov(netmem_to_net_iov(netmem)); + net_iov_dec_ref(netmem_to_net_iov(netmem)); else put_page(netmem_to_page(netmem)); } diff --git a/net/core/devmem.c b/net/core/devmem.c index fd1b72744564..32fafbfa1359 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -387,12 +387,12 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id) return binding; } -void net_devmem_get_net_iov(struct net_iov *niov) +void net_devmem_net_iov_inc_ref(struct net_iov *niov) { net_devmem_dmabuf_binding_get(net_devmem_iov_binding(niov)); } -void net_devmem_put_net_iov(struct net_iov *niov) +void net_devmem_net_iov_dec_ref(struct net_iov *niov) { net_devmem_dmabuf_binding_put(net_devmem_iov_binding(niov)); } diff --git a/net/core/devmem.h b/net/core/devmem.h index ad24bca20618..8fa089776610 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -43,7 +43,7 @@ struct net_devmem_dmabuf_binding { * those refs are dropped and the binding is no longer desired or in * use. * - * net_devmem_get_net_iov() on dmabuf net_iovs will increment this + * net_devmem_net_iov_inc_ref() on dmabuf net_iovs will increment this * reference, making sure that the binding remains alive until all the * net_iovs are no longer used. net_iovs allocated from this binding * that are stuck in the TX path for any reason (such as awaiting @@ -131,8 +131,8 @@ net_devmem_dmabuf_binding_put(struct net_devmem_dmabuf_binding *binding) percpu_ref_put(&binding->ref); } -void net_devmem_get_net_iov(struct net_iov *niov); -void net_devmem_put_net_iov(struct net_iov *niov); +void net_devmem_net_iov_inc_ref(struct net_iov *niov); +void net_devmem_net_iov_dec_ref(struct net_iov *niov); void net_devmem_free_dmabuf(struct net_iov *ppiov); @@ -151,11 +151,11 @@ net_devmem_dmabuf_binding_put(struct net_devmem_dmabuf_binding *binding) { } -static inline void net_devmem_get_net_iov(struct net_iov *niov) +static inline void net_devmem_net_iov_inc_ref(struct net_iov *niov) { } -static inline void net_devmem_put_net_iov(struct net_iov *niov) +static inline void net_devmem_net_iov_dec_ref(struct net_iov *niov) { } diff --git a/net/core/net_test.c b/net/core/net_test.c index cebd83e596d0..6fdab6a55b4d 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -861,11 +861,11 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem = net_iov_to_netmem(&niov); base_ref = atomic_long_read(&binding.ref.data->count); - /* Non-PP net_iov: get/put_net_iov & get/put_netmem */ - get_net_iov(&niov); + /* Non-PP net_iov: net_iov_inc/dec_ref & get/put_netmem */ + net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); - put_net_iov(&niov); + net_iov_dec_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref); @@ -886,12 +886,12 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem_or_pp_magic(netmem, PP_SIGNATURE); atomic_long_set(&niov.desc.pp_ref_count, 2); - /* Layer 0 & 1: get_net_iov / get_netmem grab non-pp ref even on PP */ - get_net_iov(&niov); + /* Layer 0 & 1: net_iov_inc_ref / get_netmem grab non-pp ref on PP */ + net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); - put_net_iov(&niov); + net_iov_dec_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b79d8b702a0b..a0f2d930ebf5 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7643,38 +7643,38 @@ bool csum_and_copy_from_iter_full(void *addr, size_t bytes, EXPORT_SYMBOL(csum_and_copy_from_iter_full); /** - * get_net_iov - acquire a non-page_pool reference on a net_iov + * net_iov_inc_ref - acquire a non-page_pool reference on a net_iov * @niov: net_iov to reference * * Acquires a non-pp backing reference (binding->ref) on @niov regardless of * page_pool membership, warning if @niov does not support non-pp references. - * Counterpart to put_net_iov(). + * Counterpart to net_iov_dec_ref(). */ -void get_net_iov(struct net_iov *niov) +void net_iov_inc_ref(struct net_iov *niov) { if (net_is_devmem_iov(niov)) - net_devmem_get_net_iov(niov); + net_devmem_net_iov_inc_ref(niov); else DEBUG_NET_WARN_ON_ONCE(true); } -EXPORT_SYMBOL(get_net_iov); +EXPORT_SYMBOL(net_iov_inc_ref); /** - * put_net_iov - release a non-page_pool reference on a net_iov + * net_iov_dec_ref - release a non-page_pool reference on a net_iov * @niov: net_iov to unreference * * Drops a non-pp backing reference (binding->ref) on @niov regardless of * page_pool membership, warning if @niov does not support non-pp references. - * Counterpart to get_net_iov(). + * Counterpart to net_iov_inc_ref(). */ -void put_net_iov(struct net_iov *niov) +void net_iov_dec_ref(struct net_iov *niov) { if (net_is_devmem_iov(niov)) - net_devmem_put_net_iov(niov); + net_devmem_net_iov_dec_ref(niov); else DEBUG_NET_WARN_ON_ONCE(true); } -EXPORT_SYMBOL(put_net_iov); +EXPORT_SYMBOL(net_iov_dec_ref); struct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb, __be16 type, From 2620efb2cec11628ff419dc876981e1f8fed664a Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 21 Oct 2026 01:55:58 +0000 Subject: [PATCH 2101/2126] netmem: rename get/put_netmem() to netmem_inc/dec_ref() Follow the object_action() naming convention for netmem non-page_pool reference helpers by renaming get_netmem() and put_netmem() to netmem_inc_ref() and netmem_dec_ref(). Use netmem_inc_ref() and netmem_dec_ref() rather than netmem_ref() and netmem_unref() because netmem_ref is already a typedef (typedef unsigned long __bitwise netmem_ref). Suggested-by: Jakub Kicinski Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261021015558.4124825-3-almasrymina@google.com Signed-off-by: Jakub Kicinski --- drivers/net/veth.c | 2 +- include/linux/skbuff_ref.h | 8 ++++---- include/net/netmem.h | 12 ++++++------ net/core/datagram.c | 2 +- net/core/net_test.c | 16 ++++++++-------- net/tls/tls_device.c | 2 +- net/tls/tls_device_fallback.c | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 8746d0d1f591..54fceb64f426 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -751,7 +751,7 @@ static void veth_xdp_get(struct xdp_buff *xdp) return; for (i = 0; i < sinfo->nr_frags; i++) - get_netmem(skb_frag_netmem(&sinfo->frags[i])); + netmem_inc_ref(skb_frag_netmem(&sinfo->frags[i])); } static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h index f768a3fa1d60..b6f6da556ee9 100644 --- a/include/linux/skbuff_ref.h +++ b/include/linux/skbuff_ref.h @@ -18,7 +18,7 @@ bool napi_pp_get_page(netmem_ref netmem); * * Acquires pp_ref_count via napi_pp_get_page() if @recycle is true and * @netmem belongs to a page_pool; otherwise acquires a non-pp backing - * reference via get_netmem(). Counterpart to skb_netmem_unref(). + * reference via netmem_inc_ref(). Counterpart to skb_netmem_unref(). */ static __always_inline void skb_netmem_ref(netmem_ref netmem, bool recycle) { @@ -26,7 +26,7 @@ static __always_inline void skb_netmem_ref(netmem_ref netmem, bool recycle) if (recycle && napi_pp_get_page(netmem)) return; #endif - get_netmem(netmem); + netmem_inc_ref(netmem); } /** @@ -53,7 +53,7 @@ bool napi_pp_put_page(netmem_ref netmem); * * Drops pp_ref_count via napi_pp_put_page() if @recycle is true and @netmem * belongs to a page_pool; otherwise drops a non-pp backing reference via - * put_netmem(). Counterpart to skb_netmem_ref(). + * netmem_dec_ref(). Counterpart to skb_netmem_ref(). */ static __always_inline void skb_netmem_unref(netmem_ref netmem, bool recycle) { @@ -61,7 +61,7 @@ static __always_inline void skb_netmem_unref(netmem_ref netmem, bool recycle) if (recycle && napi_pp_put_page(netmem)) return; #endif - put_netmem(netmem); + netmem_dec_ref(netmem); } /** diff --git a/include/net/netmem.h b/include/net/netmem.h index 7f36c734edcd..fb693bc1702a 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -413,14 +413,14 @@ void net_iov_inc_ref(struct net_iov *niov); void net_iov_dec_ref(struct net_iov *niov); /** - * get_netmem - acquire a non-page_pool reference on a netmem + * netmem_inc_ref - acquire a non-page_pool reference on a netmem * @netmem: netmem to reference * * Acquires a non-pp backing reference (page._refcount via get_page() or * binding->ref via net_iov_inc_ref()) regardless of page_pool membership. - * Counterpart to put_netmem(). + * Counterpart to netmem_dec_ref(). */ -static __always_inline void get_netmem(netmem_ref netmem) +static __always_inline void netmem_inc_ref(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) net_iov_inc_ref(netmem_to_net_iov(netmem)); @@ -429,14 +429,14 @@ static __always_inline void get_netmem(netmem_ref netmem) } /** - * put_netmem - release a non-page_pool reference on a netmem + * netmem_dec_ref - release a non-page_pool reference on a netmem * @netmem: netmem to unreference * * Drops a non-pp backing reference (page._refcount via put_page() or * binding->ref via net_iov_dec_ref()) regardless of page_pool membership. - * Counterpart to get_netmem(). + * Counterpart to netmem_inc_ref(). */ -static __always_inline void put_netmem(netmem_ref netmem) +static __always_inline void netmem_dec_ref(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) net_iov_dec_ref(netmem_to_net_iov(netmem)); diff --git a/net/core/datagram.c b/net/core/datagram.c index 173b5d97bd40..ecc30a6f8302 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -735,7 +735,7 @@ zerocopy_fill_skb_from_devmem(struct sk_buff *skb, struct iov_iter *from, size = min_t(size_t, size, length); size = min_t(size_t, size, iter_iov_len(from)); - get_netmem(net_iov_to_netmem(niov)); + netmem_inc_ref(net_iov_to_netmem(niov)); skb_add_rx_frag_netmem(skb, i, net_iov_to_netmem(niov), off, size, PAGE_SIZE); iov_iter_advance(from, size); diff --git a/net/core/net_test.c b/net/core/net_test.c index 6fdab6a55b4d..2b5080c22663 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -536,10 +536,10 @@ static void netmem_ref_test_page(struct kunit *test) netmem = page_to_netmem(page); base_ref = page_ref_count(page); - /* Layer 1: get_netmem / put_netmem use page non-pp refcount */ - get_netmem(netmem); + /* Layer 1: netmem_inc_ref / netmem_dec_ref use page non-pp refcount */ + netmem_inc_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); - put_netmem(netmem); + netmem_dec_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); #ifdef CONFIG_PAGE_POOL @@ -600,12 +600,12 @@ static void netmem_ref_test_pp_page(struct kunit *test) base_ref = page_ref_count(page); base_pp_ref = atomic_long_read(&page->pp_ref_count); - /* Layer 1: get_netmem / put_netmem always use non-pp refcount */ - get_netmem(netmem); + /* Layer 1: netmem_inc/dec_ref always use non-pp refcount */ + netmem_inc_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), base_pp_ref); - put_netmem(netmem); + netmem_dec_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); /* Layer 2: napi_pp_get/put_page use pp_ref_count */ @@ -861,7 +861,7 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem = net_iov_to_netmem(&niov); base_ref = atomic_long_read(&binding.ref.data->count); - /* Non-PP net_iov: net_iov_inc/dec_ref & get/put_netmem */ + /* Non-PP net_iov: net_iov_inc/dec_ref & netmem_inc/dec_ref */ net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); @@ -886,7 +886,7 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem_or_pp_magic(netmem, PP_SIGNATURE); atomic_long_set(&niov.desc.pp_ref_count, 2); - /* Layer 0 & 1: net_iov_inc_ref / get_netmem grab non-pp ref on PP */ + /* Layer 0 & 1: net_iov/netmem_inc_ref grab non-pp ref on PP */ net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 2382d00aef8f..1a5f328d80a5 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -143,7 +143,7 @@ static void destroy_record(struct tls_record_info *record) int i; for (i = 0; i < record->num_frags; i++) - put_netmem(skb_frag_netmem(&record->frags[i])); + netmem_dec_ref(skb_frag_netmem(&record->frags[i])); kfree(record); } diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c index 35cc510db432..b547027cc879 100644 --- a/net/tls/tls_device_fallback.c +++ b/net/tls/tls_device_fallback.c @@ -256,7 +256,7 @@ static int fill_sg_in(struct scatterlist *sg_in, for (i = 0; remaining > 0; i++) { skb_frag_t *frag = &record->frags[i]; - get_netmem(skb_frag_netmem(frag)); + netmem_inc_ref(skb_frag_netmem(frag)); sg_set_page(sg_in + i, skb_frag_page(frag), skb_frag_size(frag), skb_frag_off(frag)); From 6acb220312d58cffe6591c6adc90dbfd042cc1af Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Mon, 19 Oct 2026 08:04:30 +0200 Subject: [PATCH 2102/2126] net: cpsw: fix netdev cleanup on probe failure The legacy CPSW driver registers its netdevs before requesting IRQs. If a later IRQ request fails in dual-EMAC mode, the probe error path unregisters only the primary netdev. Devres then calls free_netdev() on the still-registered secondary netdev, triggering the reg_state BUG_ON. Once registered, either interface can queue rx_mode_work through dev_set_rx_mode(). The error path does not drain the work before devres releases the netdev and its private data, allowing the worker to access freed memory. Use the same per-port cleanup for probe failure and remove. Unregister each netdev whose reg_state is NETREG_REGISTERED, then drain its rx_mode_work. The state check is needed because cpsw_probe_dual_emac() stores the secondary pointer before register_netdev() succeeds. The workqueue lifetime issue was found during an LLM-assisted review of the 6.12.112-rc1 stable series. Inspecting the same path then exposed the dual-EMAC cleanup bug. An instrumented KASAN ARM kernel and a QEMU CPSW probe stub reproduced both failures by forcing the TX IRQ request to return -EBUSY. Not tested on real hardware. Cc: stable+noautosel@kernel.org # LLM report + LLM fix, untested Fixes: 070f9c658a59 ("net: ethernet: ti: cpsw: Push the request_irq function to the end of probe") Fixes: 0b8c878d1173 ("net: cpsw: Execute ndo_set_rx_mode callback in a work queue") Signed-off-by: Karl Mehltretter Reviewed-by: Alexander Sverdlin Reviewed-by: Siddharth Vadapalli Link: https://patch.msgid.link/20261019060430.33254-1-kmehltretter@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/ti/cpsw.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 63b64faeaca0..8d36124520ad 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -1524,6 +1524,23 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv) return ret; } +static void cpsw_unregister_ports(struct cpsw_common *cpsw) +{ + struct net_device *ndev; + struct cpsw_priv *priv; + int i; + + for (i = 0; i < cpsw->data.slaves; i++) { + ndev = cpsw->slaves[i].ndev; + if (!ndev || ndev->reg_state != NETREG_REGISTERED) + continue; + + priv = netdev_priv(ndev); + unregister_netdev(ndev); + disable_work_sync(&priv->rx_mode_work); + } +} + static const struct of_device_id cpsw_of_mtable[] = { { .compatible = "ti,cpsw"}, { .compatible = "ti,am335x-cpsw"}, @@ -1764,7 +1781,7 @@ skip_cpts: return 0; clean_unregister_netdev_ret: - unregister_netdev(ndev); + cpsw_unregister_ports(cpsw); clean_cpts: cpts_release(cpsw->cpts); cpdma_ctlr_destroy(cpsw->dma); @@ -1779,9 +1796,7 @@ clean_runtime_disable_ret: static void cpsw_remove(struct platform_device *pdev) { struct cpsw_common *cpsw = platform_get_drvdata(pdev); - struct net_device *ndev; - struct cpsw_priv *priv; - int i, ret; + int ret; ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) { @@ -1793,15 +1808,7 @@ static void cpsw_remove(struct platform_device *pdev) return; } - for (i = 0; i < cpsw->data.slaves; i++) { - ndev = cpsw->slaves[i].ndev; - if (!ndev) - continue; - - priv = netdev_priv(ndev); - unregister_netdev(ndev); - disable_work_sync(&priv->rx_mode_work); - } + cpsw_unregister_ports(cpsw); cpts_release(cpsw->cpts); cpdma_ctlr_destroy(cpsw->dma); From d90d1a768b3b022c52beafb3a4701ee2ee3d2b5e Mon Sep 17 00:00:00 2001 From: "Nikhil P. Rao" Date: Thu, 15 Oct 2026 16:03:30 -0700 Subject: [PATCH 2103/2126] ionic: fix port_info use-after-free on firmware recovery ionic_port_init() allocates port_info when the pointer is NULL, but its error path frees it without checking whether this call allocated it. Before commit ddc5911b9bd2 ("ionic: call ionic_port_init after fw-upgrade") the function returned early when the buffer already existed, so the two were symmetric. Since then a failed PORT_INIT on either recovery path - fw_up or reset_done - frees a buffer an earlier init owns, while the netdev is registered and the ethtool ops are reading it. Free only what this call allocated. Fixes: ddc5911b9bd2 ("ionic: call ionic_port_init after fw-upgrade") Signed-off-by: Nikhil P. Rao Signed-off-by: Eric Joyner Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20261015-ionic-port-info-lifetime-v2-1-57232013fd79@amd.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/pensando/ionic/ionic_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c index 10501be9ef95..38b47b959a11 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_main.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_main.c @@ -722,6 +722,7 @@ int ionic_port_init(struct ionic *ionic) { struct ionic_identity *ident = &ionic->ident; struct ionic_dev *idev = &ionic->idev; + bool allocated = false; size_t sz; int err; @@ -733,6 +734,8 @@ int ionic_port_init(struct ionic *ionic) GFP_KERNEL); if (!idev->port_info) return -ENOMEM; + + allocated = true; } /* If the driver knows about more "extra stats" than the firmware, @@ -757,10 +760,12 @@ int ionic_port_init(struct ionic *ionic) mutex_unlock(&ionic->dev_cmd_lock); if (err) { dev_err(ionic->dev, "Failed to init port\n"); - dma_free_coherent(ionic->dev, idev->port_info_sz, - idev->port_info, idev->port_info_pa); - idev->port_info = NULL; - idev->port_info_pa = 0; + if (allocated) { + dma_free_coherent(ionic->dev, idev->port_info_sz, + idev->port_info, idev->port_info_pa); + idev->port_info = NULL; + idev->port_info_pa = 0; + } } return err; From 4e15e0a941ce901d51b5f203713fa90feee9c4d3 Mon Sep 17 00:00:00 2001 From: Eric Joyner Date: Thu, 15 Oct 2026 16:03:31 -0700 Subject: [PATCH 2104/2126] ionic: free port_info when probe fails after the port is set up ionic_probe() allocates the port_info DMA buffer via ionic_setup_one() -> ionic_port_init(). If probe then fails anywhere after that, it unwinds through err_out_pci, which never calls ionic_port_reset(); ionic_dev_teardown() and ionic_clear_pci() do not touch port_info, and so the buffer is leaked. The call was lost when the setup code was moved into ionic_setup_one(). Since ionic_remove() already frees the port_info DMA buffer with ionic_port_reset(), call that on the probe error path too. Every path to err_out_pci runs after ionic_setup_one() succeeded, so the BARs are still mapped and the firmware gets a PORT_RESET before the buffer is freed, the same order as in ionic_remove(). Fixes: 0de38d9f1dba ("ionic: extract common bits from ionic_probe") Signed-off-by: Eric Joyner Reviewed-by: Vadim Fedorenko Link: https://patch.msgid.link/20261015-ionic-port-info-lifetime-v2-2-57232013fd79@amd.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c index 666efe972de7..ddc2f9770df4 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c @@ -397,6 +397,7 @@ err_out_free_lifs: err_out_free_irqs: ionic_bus_free_irq_vectors(ionic); err_out_pci: + ionic_port_reset(ionic); ionic_dev_teardown(ionic); ionic_clear_pci(ionic); ionic_debugfs_del_dev(ionic); From 9b8ae9aaa1b8e2b6c1cbf5613d3a37923cf53bc5 Mon Sep 17 00:00:00 2001 From: Jijie Shao Date: Fri, 16 Oct 2026 19:04:21 +0800 Subject: [PATCH 2105/2126] net: hibmcge: set netdev_ops before hbg_init() to fix NULL pointer dereference The driver assigns netdev_ops after hbg_init(), but hbg_init() calls hbg_mdio_init() -> hbg_phy_connect() -> phy_connect_direct() -> phy_attach_direct() -> phy_link_topo_add_phy(), which invokes netdev_need_ops_lock(). With CONFIG_NET_SHAPER enabled, this function dereferences dev->netdev_ops->net_shaper_ops. Since netdev_ops is still NULL at this point, a NULL pointer dereference occurs. Move the netdev_ops assignment before hbg_init() so that netdev_need_ops_lock() can safely access netdev_ops during PHY attachment. The issue was hit and verified on an evaluation board. Fixes: ff4edac6e9bd ("net: hibmcge: Implement some .ndo functions") Signed-off-by: Jijie Shao Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261016110421.2288670-1-shaojijie@huawei.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index 66792e2b0fad..a518dc66d9ef 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -448,6 +448,7 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; + netdev->netdev_ops = &hbg_netdev_ops; ret = hbg_init(priv); if (ret) return ret; @@ -460,7 +461,6 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS; netdev->max_mtu = priv->dev_specs.max_mtu; netdev->min_mtu = priv->dev_specs.min_mtu; - netdev->netdev_ops = &hbg_netdev_ops; netdev->watchdog_timeo = 5 * HZ; hbg_hw_set_mtu(priv, ETH_DATA_LEN); From b0e4ea3a0cd42eccad9cc4153afcad555480b9e6 Mon Sep 17 00:00:00 2001 From: Willem de Bruijn Date: Mon, 19 Oct 2026 23:15:50 -0400 Subject: [PATCH 2106/2126] virtio-net: fix frag overflow in big packets receive In big packets mode with guest GSO, add_recvbuf_big() posts a chain of MAX_SKB_FRAGS + 1 pages. page_to_skb() copies only ETH_HLEN of the first page into the linear area and adds the rest of that page as a frag, then one frag per remaining page. A device that fills the entire buffer therefore causes MAX_SKB_FRAGS + 1 frags, writing one skb_frag_t past the end of skb_shinfo(skb)->frags[]. Post one page less. The buffer still fits a maximal GSO packet. A well behaved device does not trigger this, as GSO packets are at most 64KB. Also check the frag count in page_to_skb() before adding any frag as defense in depth. Fixes: 9ab86bbcf8be ("virtio_net: Defer skb allocation in receive path Date: Wed, 13 Jan 2010 12:53:38 -0800") Signed-off-by: Willem de Bruijn Acked-by: Michael S. Tsirkin Link: https://patch.msgid.link/20261020032108.81879-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/virtio_net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 4e8a792cec0e..584bc05c577c 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -900,6 +900,15 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, } BUG_ON(offset >= PAGE_SIZE); + + /* The first frag starts at offset, each next frag is a full page. */ + if (unlikely(DIV_ROUND_UP(offset + len, PAGE_SIZE) > MAX_SKB_FRAGS)) { + pr_debug("%s: rx error: len %u needs more than %d frags\n", + vi->dev->name, len, MAX_SKB_FRAGS); + kfree_skb(skb); + return NULL; + } + while (len) { unsigned int frag_size = min((unsigned)PAGE_SIZE - offset, len); skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, offset, @@ -6709,7 +6718,8 @@ static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu) */ if (mtu > ETH_DATA_LEN || guest_gso) { vi->big_packets = true; - vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE); + vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS - 1 : + DIV_ROUND_UP(mtu, PAGE_SIZE); } } From a031ec9ff5a2e55867430e74e9b497fe844116ba Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Tue, 20 Oct 2026 10:58:35 +0200 Subject: [PATCH 2107/2126] net: lan969x: fix DSM calendar for empty taxis lan969x_dsm_calendar_calc() computes the DSM calendar schedule of one taxi. sparx5_config_dsm_calendar() calls it for each taxi, reusing the same sparx5_calendar_data. Before this patch, the schedule is only cleared after the n_devs == 0 early return. For a taxi with no active ports, the function writes SPX5_DSM_CAL_EMPTY only to schedule[0] and leaves the remaining slots at whatever they held before. For the first taxi that is zero from kzalloc(), so sparx5_dsm_cal_len() returns a bogus length and sparx5_dsm_calendar_check() fails, which fails the probe: Port 0: distance 20 above limit 0 A later empty taxi inherits the previous taxi's schedule instead, which passes the check, so only an empty taxi 0 triggers the failure. Clear the full schedule up front on every path, and on the empty path place a single idle marker (SPX5_DSM_CAL_MAX_DEVS_PER_TAXI) in slot 0, so the update step sees a calendar length of one and programs one idle slot into the hardware, matching what sparx5_dsm_calendar_calc() does. Reported by a customer whose DT enables none of the ports in a taxi. Reproduced on lan969x by disabling all taxi 0 ports in the DT. Fixes: 5d2ba3941016 ("net: lan969x: add function for calculating the DSM calendar") Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261020-lan969x-dsm-empty-taxi-v1-1-14790f1e7430@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/sparx5/lan969x/lan969x_calendar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_calendar.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_calendar.c index e857640df185..4442c0c1a957 100644 --- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_calendar.c +++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_calendar.c @@ -82,6 +82,9 @@ int lan969x_dsm_calendar_calc(struct sparx5 *sparx5, u32 taxi, struct lan969x_dsm_cal_dev_speed *speed; int err; + for (u32 i = 0; i < SPX5_DSM_CAL_LEN; i++) + data->schedule[i] = SPX5_DSM_CAL_EMPTY; + /* Maximum bandwidth for this taxi */ taxi_bw = (128 * 1000000) / sparx5_clk_period(sparx5->coreclock); @@ -125,7 +128,7 @@ int lan969x_dsm_calendar_calc(struct sparx5 *sparx5, u32 taxi, } if (n_devs == 0) { - data->schedule[0] = SPX5_DSM_CAL_EMPTY; + data->schedule[0] = SPX5_DSM_CAL_MAX_DEVS_PER_TAXI; return 0; } @@ -167,9 +170,6 @@ int lan969x_dsm_calendar_calc(struct sparx5 *sparx5, u32 taxi, return -EINVAL; } - for (u32 i = 0; i < SPX5_DSM_CAL_LEN; i++) - data->schedule[i] = SPX5_DSM_CAL_EMPTY; - /* Place the remaining devices */ for (u32 i = 0; i < DSM_CAL_DEV_MAX; i++) { speed = &dev_speeds[i]; From 5a3dcad8e101ddcd3a886907c8992df54472f749 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Tue, 20 Oct 2026 10:58:58 +0200 Subject: [PATCH 2108/2126] net: sparx5/lan969x: do not clobber the PSFP cycle timer update period sparx5_psfp_init() enables the periodic stream gate cycle timer update, which keeps the cycle start time of each stream gate within one cycle time of the current time. SG_CT_CLKS sets the update period, in system clock cycles. Before this patch, the update is enabled with a full register write of SG_CT_UPDATE_ENA only, which also sets SG_CT_CLKS to zero. That is below the documented minimum, the number of stream gates (1024 on sparx5 and 256 on lan969x). Write both fields, and set the period to the recommended 10 us, computed from the core clock since it differs per target (6250 cycles at 625 MHz, 3280 at 328 MHz). Found by an AI code review agent, and confirmed on lan969x and sparx5 by reading the register back as 0x80000000. Fixes: e116b19db202 ("net: microchip: sparx5: initialize PSFP") Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261020-sparx5-psfp-cycle-timer-v1-1-00f2908f096a@microchip.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c b/drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c index 83b37f95ee46..fa19a48f941d 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c @@ -322,6 +322,7 @@ void sparx5_psfp_init(struct sparx5 *sparx5) { const struct sparx5_ops *ops = sparx5->data->ops; const struct sparx5_sdlb_group *group; + u32 sg_ct_clks; int i; for (i = 0; i < sparx5->data->consts->n_lb_groups; i++) { @@ -330,7 +331,14 @@ void sparx5_psfp_init(struct sparx5 *sparx5) group->min_burst, group->frame_size, i); } - spx5_wr(ANA_AC_SG_CYCLETIME_UPDATE_PERIOD_SG_CT_UPDATE_ENA_SET(1), + /* Poll the stream gate cycle start times every 10 us. The core clock + * period is in picoseconds. + */ + sg_ct_clks = 10 * NSEC_PER_USEC * PSEC_PER_NSEC / + sparx5_clk_period(sparx5->coreclock); + + spx5_wr(ANA_AC_SG_CYCLETIME_UPDATE_PERIOD_SG_CT_CLKS_SET(sg_ct_clks) | + ANA_AC_SG_CYCLETIME_UPDATE_PERIOD_SG_CT_UPDATE_ENA_SET(1), sparx5, ANA_AC_SG_CYCLETIME_UPDATE_PERIOD); spx5_rmw(ANA_L2_FWD_CFG_ISDX_LOOKUP_ENA_SET(1), From 9770818b8a92fb5fb77725bd5055f165eee3f52e Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Tue, 20 Oct 2026 10:57:27 +0200 Subject: [PATCH 2109/2126] net: lan969x: don't disable hardirqs in fdma tx clear lan969x_fdma_tx_clear_buf() runs from the NAPI poll and frees the skbs of completed tx DCBs with napi_consume_skb(), under sparx5->tx_lock. Before this patch, the lock is taken with spin_lock_irqsave(), so the skbs are freed with hardirqs disabled. RX skbs are marked for page_pool recycling, so when such an skb is forwarded back out and its tx completion frees it here, the free path reaches __page_pool_put_page(), which warns via lockdep_assert_no_hardirq(). Take tx_lock with a plain spin_lock(), as the only other tx_lock user, sparx5_port_xmit_impl(), already does. tx_clear_buf() is only called from softirq context, so disabling hardirqs is not needed. Found with lockdep enabled (CONFIG_PROVE_LOCKING), which the assert depends on. Reproduced on lan969x by redirecting received frames out of another port with tc mirred. Fixes: d84ad2c0d80c ("net: lan969x: add FDMA implementation") Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261020-lan969x-fdma-tx-clear-irq-v1-1-b9f9d1eda317@microchip.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c index c7e0e58ff0f7..053d125eda65 100644 --- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c +++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c @@ -54,10 +54,9 @@ static void lan969x_fdma_tx_clear_buf(struct sparx5 *sparx5, int weight) { struct fdma *fdma = &sparx5->tx.fdma; struct sparx5_tx_buf *db; - unsigned long flags; int i; - spin_lock_irqsave(&sparx5->tx_lock, flags); + spin_lock(&sparx5->tx_lock); for (i = 0; i < fdma->n_dcbs; ++i) { db = &sparx5->tx.dbs[i]; @@ -83,7 +82,7 @@ static void lan969x_fdma_tx_clear_buf(struct sparx5 *sparx5, int weight) db->used = false; } - spin_unlock_irqrestore(&sparx5->tx_lock, flags); + spin_unlock(&sparx5->tx_lock); } static void lan969x_fdma_free_pages(struct sparx5_rx *rx) From b5b8c81836e2bec7b444dfa2b14fd14e912e9d63 Mon Sep 17 00:00:00 2001 From: Qingfang Deng Date: Tue, 20 Oct 2026 17:21:11 +0800 Subject: [PATCH 2110/2126] pppoe: delete session hash entries by pointer match pppoe_connect() copies the requested PPPoE address to a socket before attempting to insert the socket into the session hash table. If the tuple already exists, __set_item() returns -EALREADY, but the copied address and ifindex remain set on the failed socket. Closing that socket then deletes the existing socket's hash entry through pppoe_release(), preventing it from receiving further session traffic. An unprivileged process in the same network namespace can trigger this through a duplicate connection attempt. To avoid the accidental delete, pass the pppox_sock to __delete_item(), and unlink only an entry whose pointer matches the requested socket. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Qingfang Deng Link: https://patch.msgid.link/20261020092118.47416-1-qingfang.deng@linux.dev Signed-off-by: Jakub Kicinski --- drivers/net/ppp/pppoe.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c index bf7414b46a26..ee0e318d6a2a 100644 --- a/drivers/net/ppp/pppoe.c +++ b/drivers/net/ppp/pppoe.c @@ -194,18 +194,16 @@ static int __set_item(struct pppoe_net *pn, struct pppox_sock *po) return 0; } -static void __delete_item(struct pppoe_net *pn, __be16 sid, - char *addr, int ifindex) +static void __delete_item(struct pppoe_net *pn, const struct pppox_sock *po) { - int hash = hash_item(sid, addr); + int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote); struct pppox_sock *ret, __rcu **src; ret = rcu_dereference_protected(pn->hash_table[hash], lockdep_is_held(&pn->hash_lock)); src = &pn->hash_table[hash]; while (ret) { - if (cmp_addr(&ret->pppoe_pa, sid, addr) && - ret->pppoe_ifindex == ifindex) { + if (ret == po) { struct pppox_sock *next; next = rcu_dereference_protected(ret->next, @@ -236,11 +234,10 @@ static inline struct pppox_sock *get_item(struct pppoe_net *pn, __be16 sid, return po; } -static inline void delete_item(struct pppoe_net *pn, __be16 sid, - char *addr, int ifindex) +static void delete_item(struct pppoe_net *pn, const struct pppox_sock *po) { spin_lock(&pn->hash_lock); - __delete_item(pn, sid, addr, ifindex); + __delete_item(pn, po); spin_unlock(&pn->hash_lock); } @@ -570,8 +567,7 @@ static int pppoe_release(struct socket *sock) * protect "po" from concurrent updates * on pppoe_flush_dev */ - delete_item(pn, po->pppoe_pa.sid, po->pppoe_pa.remote, - po->pppoe_ifindex); + delete_item(pn, po); sock_orphan(sk); sock->sk = NULL; @@ -621,8 +617,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr if (stage_session(po->pppoe_pa.sid)) { pppox_unbind_sock(sk); pn = pppoe_pernet(sock_net(sk)); - delete_item(pn, po->pppoe_pa.sid, - po->pppoe_pa.remote, po->pppoe_ifindex); + delete_item(pn, po); if (po->pppoe_dev) { dev_put(po->pppoe_dev); po->pppoe_dev = NULL; @@ -672,8 +667,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr error = ppp_register_net_channel(dev_net(dev), &po->chan); if (error) { - delete_item(pn, po->pppoe_pa.sid, - po->pppoe_pa.remote, po->pppoe_ifindex); + delete_item(pn, po); goto err_put; } From f16b8c6a656e62bfa7bb6a3b876f9ccdaf53bd43 Mon Sep 17 00:00:00 2001 From: Tianyi Gao Date: Fri, 16 Oct 2026 22:42:16 +0100 Subject: [PATCH 2111/2126] veth: schedule the peer's NAPI after XDP_TX when only GRO is enabled veth_xdp_xmit() queues XDP_TX frames on the peer's ring if the peer has NAPI. A peer with GRO enabled and no XDP program also has NAPI. veth_xdp_flush() then schedules the peer's NAPI, but only if the peer's xdp_prog is set, so for such a peer the frames are never processed. Nothing else schedules that NAPI by default. Once the ring is full, every XDP_TX frame is dropped, and so are the skbs that veth_xmit() queues on the same ring. Commit 0e672f306a28 ("veth: check for NAPI instead of xdp_prog before xmit of XDP frame") changed the check in veth_xdp_xmit() but not the one in veth_xdp_flush(). Make veth_xdp_flush() check the napi pointer instead of xdp_prog, as veth_xdp_xmit() does. Fixes: 0e672f306a28 ("veth: check for NAPI instead of xdp_prog before xmit of XDP frame") Signed-off-by: Tianyi Gao Reviewed-by: Mohsin Bashir Acked-by: Lorenzo Bianconi Acked-by: Jesper Dangaard Brouer Link: https://patch.msgid.link/20261016214217.16942-2-tianyi@cloudflare.com Signed-off-by: Jakub Kicinski --- drivers/net/veth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 643b97dc5245..9405ffac598a 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -612,7 +612,7 @@ static void veth_xdp_flush(struct veth_rq *rq, struct veth_xdp_tx_bq *bq) rcv_priv = netdev_priv(rcv); rcv_rq = &rcv_priv->rq[veth_select_rxq(rcv)]; /* xdp_ring is initialized on receive side? */ - if (unlikely(!rcu_access_pointer(rcv_rq->xdp_prog))) + if (unlikely(!rcu_access_pointer(rcv_rq->napi))) goto out; __veth_xdp_flush(rcv_rq); From a70575ae9e812908acf658ec785f81daeba1a23b Mon Sep 17 00:00:00 2001 From: Tianyi Gao Date: Fri, 16 Oct 2026 22:42:17 +0100 Subject: [PATCH 2112/2126] selftests: net: veth: test XDP_TX to a peer with GRO enabled Test that XDP_TX frames reach a peer that has GRO enabled and no XDP program. GRO enables NAPI on the peer, so the frames are queued on the peer's ring, and the peer's NAPI must be scheduled to process them. Attach a program that returns XDP_TX for every frame, send 5 echo requests and check that all of them were sent back and that the peer's NAPI received them, as counted in its xdp_packets statistic. IPv6 is disabled on both devices, so that only the echo requests are counted. Add the program to xdp_dummy.bpf.c in a section of its own, so that the tests that load "section xdp" still get XDP_PASS. Signed-off-by: Tianyi Gao Link: https://patch.msgid.link/20261016214217.16942-3-tianyi@cloudflare.com Signed-off-by: Jakub Kicinski --- .../testing/selftests/net/lib/xdp_dummy.bpf.c | 6 +++++ tools/testing/selftests/net/veth.sh | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tools/testing/selftests/net/lib/xdp_dummy.bpf.c b/tools/testing/selftests/net/lib/xdp_dummy.bpf.c index e73fab3edd9f..95abd67cc184 100644 --- a/tools/testing/selftests/net/lib/xdp_dummy.bpf.c +++ b/tools/testing/selftests/net/lib/xdp_dummy.bpf.c @@ -16,4 +16,10 @@ int xdp_dummy_prog_frags(struct xdp_md *ctx) return XDP_PASS; } +SEC("xdp_tx") +int xdp_dummy_tx(struct xdp_md *ctx) +{ + return XDP_TX; +} + char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh index 8b867e0675a7..0167f78604ef 100755 --- a/tools/testing/selftests/net/veth.sh +++ b/tools/testing/selftests/net/veth.sh @@ -334,6 +334,31 @@ ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on chk_gro " - aggregation with TSO off" 1 cleanup +create_ns +ip netns exec $NS_SRC sysctl -qw net.ipv6.conf.veth$SRC.disable_ipv6=1 +ip netns exec $NS_DST sysctl -qw net.ipv6.conf.veth$DST.disable_ipv6=1 +ip netns exec $NS_SRC ethtool -K veth$SRC gro on +ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} section xdp_tx +# veth$DST sends every frame back, so neither ARP nor ping gets an answer +mac=`ip netns exec $NS_DST cat /sys/class/net/veth$DST/address` +ip -n $NS_SRC neigh replace $BM_NET_V4$DST lladdr $mac dev veth$SRC +ip netns exec $NS_SRC ping -qc 5 -i 0.01 -W 1 $BM_NET_V4$DST >/dev/null +tx=`ip netns exec $NS_DST ethtool -S veth$DST | \ + awk '/rx_queue_[0-9]+_xdp_tx:/ {s += $2} END {print s + 0}'` +rx=`ip netns exec $NS_SRC ethtool -S veth$SRC | \ + awk '/rx_queue_[0-9]+_xdp_packets:/ {s += $2} END {print s + 0}'` +printf "%-60s" "xdp_tx to peer with gro on" +if [ $tx -ne 5 ]; then + echo " fail - $tx frames sent back, expected 5" + ret=1 +elif [ $rx -ne 5 ]; then + echo " fail - $rx frames received by the peer NAPI, expected 5" + ret=1 +else + echo " ok " +fi +cleanup + create_ns CUR_TX=1 From 77dac783f113dcc4576efca6f4391d7324c0b1fc Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 18 Oct 2026 16:16:29 -0700 Subject: [PATCH 2113/2126] net: bgmac: rate limit RX error messages When the RX ring is full the RX FIFO overflows. With RX overflow continue enabled, the DMA engine then writes one frame with a bogus length (always 0x45c2 on a BCM4716), which the driver drops with "Found oversized packet at slot %d, DMA issue!". Under sustained overload this happens on every NAPI poll. On an Asus RT-N16 a 950 Mbit/s UDP stream to the router printed about 1450 such lines in 20 seconds. The messages are printed from NAPI context, so with a serial console the router spends most of its time printing. The frames are already accounted in rx_length_errors and rx_errors. Rate limit both RX error messages. With this change the same flood printed 60 lines while rx_length_errors counted 14297 dropped frames. Signed-off-by: Rosen Penev Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261018231629.39734-1-rosenp@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bgmac.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c index 1835266fdd09..b3a92ae95de3 100644 --- a/drivers/net/ethernet/broadcom/bgmac.c +++ b/drivers/net/ethernet/broadcom/bgmac.c @@ -447,16 +447,18 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring, /* Check for poison and drop or pass the packet */ if (len == 0xdead && flags == 0xbeef) { - netdev_err(bgmac->net_dev, "Found poisoned packet at slot %d, DMA issue!\n", - ring->start); + if (net_ratelimit()) + netdev_err(bgmac->net_dev, "Found poisoned packet at slot %d, DMA issue!\n", + ring->start); put_page(virt_to_head_page(buf)); bgmac->net_dev->stats.rx_errors++; break; } if (len > BGMAC_RX_ALLOC_SIZE) { - netdev_err(bgmac->net_dev, "Found oversized packet at slot %d, DMA issue!\n", - ring->start); + if (net_ratelimit()) + netdev_err(bgmac->net_dev, "Found oversized packet at slot %d, DMA issue!\n", + ring->start); put_page(virt_to_head_page(buf)); bgmac->net_dev->stats.rx_length_errors++; bgmac->net_dev->stats.rx_errors++; From 46cbf85155e5451b6682ea0c17bc62ec564aec36 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 20 Oct 2026 17:42:49 +0800 Subject: [PATCH 2114/2126] net: wwan: iosm: validate msg_head before indexing msg_ring ipc_protocol_free_msg_get() reads msg_head from shared memory and uses it directly as an index into msg_ring[]. If the head is out of range, the subsequent memset() writes beyond the message ring. Validate head against IPC_MEM_MSG_ENTRIES before using it as an index. The ring is a circular buffer, so a value outside the valid range indicates a corrupted head pointer; report the error and fail the allocation instead of writing out of bounds. Fixes: 64516f633bfd ("net: iosm: protocol operations") Cc: stable@vger.kernel.org Reviewed-by: Fang Xieyan Signed-off-by: Liu Chao Reviewed-by: Loic Poulain Link: https://patch.msgid.link/20261020094254.4017726-1-liuc63@xiaopeng.com Signed-off-by: Jakub Kicinski --- drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c b/drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c index f2f86f41fd10..004920068c45 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c +++ b/drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c @@ -14,6 +14,11 @@ ipc_protocol_free_msg_get(struct iosm_protocol *ipc_protocol, int *index) u32 new_head = (head + 1) % IPC_MEM_MSG_ENTRIES; union ipc_mem_msg_entry *msg; + if (head >= IPC_MEM_MSG_ENTRIES) { + dev_err(ipc_protocol->dev, "invalid message head %u", head); + return NULL; + } + if (new_head == le32_to_cpu(ipc_protocol->p_ap_shm->msg_tail)) { dev_err(ipc_protocol->dev, "message ring is full"); return NULL; From 4957ea03bf2696f5da12c09144f48d040696ecc2 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 20 Oct 2026 17:19:54 +0200 Subject: [PATCH 2115/2126] net: shrink the payload-only part of skb dataref to one bit skb_shinfo(skb)->dataref is split in two 16-bit halves: the lower one counts all references, the upper one the payload-only (nohdr) references. __skb_clone() increments dataref without bound, and skb_cloned() only checks the low 16 bits. With 65,537 references the low half reads 1, the head looks private, and pskb_expand_head() (or skb_unclone(), skb_cow(), ...) frees it while clones still point to it. An unprivileged user can reach this from a user and network namespace: about 32,770 AF_PACKET sockets on lo bring dataref to 0x10001, then any pskb_expand_head() on the receive path (here a pull of a large IPv6 Hop-by-Hop header) frees the shared head: BUG: KASAN: slab-use-after-free in _copy_to_iter+0x187/0x1330 Read of size 1590 at addr ff110001104a9002 by task dataref_wrap/87 skb_copy_datagram_iter+0x60/0x190 packet_recvmsg+0x1f5/0x12b0 __sys_recvfrom+0x18d/0x290 Freed by task 87: kfree+0xf3/0x3b0 pskb_expand_head+0x344/0xeb0 __pskb_pull_tail+0xf9/0x1bf0 ipv6_parse_hopopts+0x377/0x4f0 ip6_rcv_core+0xc67/0x1620 The upper half never holds more than 1. It is only set by __skb_header_release(), with atomic_set() on an skb owning its head (TCP/SCTP output, and GRO which never sees cloned skbs). __skb_clone() clears nohdr, and __copy_skb_header() does not copy it. Move SKB_DATAREF_SHIFT to 30, so that the reference count gets 30 bits, and dataref stays positive. Wrapping it would need 2^30 live clones of a single skb, which socket buffer limits and memory make unreachable. This issue was found by Anthropic using Claude, and validated by Ada Logics. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Stephan Lipp Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261020151954.22953-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- include/linux/skbuff.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index d6894f463bf4..707082f68f21 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -633,9 +633,9 @@ struct skb_shared_info { * * Transport layers send out clones of payload skbs they hold for * retransmissions. To allow lower layers of the stack to prepend their headers - * we split &skb_shared_info.dataref into two halves. - * The lower 16 bits count the overall number of references. - * The higher 16 bits indicate how many of the references are payload-only. + * we split &skb_shared_info.dataref into two parts. + * The lower 30 bits count the overall number of references. + * Bit 30 indicates whether one of the references is payload-only. * skb_header_cloned() checks if skb is allowed to add / write the headers. * * The creator of the skb (e.g. TCP) marks its skb as &sk_buff.nohdr @@ -655,7 +655,7 @@ struct skb_shared_info { * Having multiple payload-only skbs with different lengths of hdr_len is not * possible. The payload-only skbs should never leave their owner. */ -#define SKB_DATAREF_SHIFT 16 +#define SKB_DATAREF_SHIFT 30 #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1) From e0a958ddfc89f2e1c43448cdaeb5b30e54e19448 Mon Sep 17 00:00:00 2001 From: Cosmin Ratiu Date: Tue, 20 Oct 2026 18:36:59 +0300 Subject: [PATCH 2116/2126] net/mlx5e: Stop asserting for RTNL when closing channels mlx5e_close_channels() has an ASSERT_RTNL() from the time when RTNL was required for closing channels. But the driver has been switched to using the netdev lock a while back, and this fired from a flow which was forgotten during the conversion: mlx5e_tx_timeout_work() -> mlx5e_reporter_tx_timeout() -> mlx5e_health_report() -> mlx5e_tx_reporter_timeout_recover() -> mlx5e_safe_reopen_channels() -> mlx5e_safe_switch_params() -> mlx5e_close_channels() The RTNL is not acquired here, but the netdev lock is, and it is enough. Rather than switching to netdev_assert_locked(), simply drop the assert. Upper layers (networking core, ethtool core) provide locking and lower layers (NAPI helpers) assert that the netdev lock is held. Fixes: 8f7b00307bf1 ("net/mlx5e: Convert mlx5 netdevs to instance locking") Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Signed-off-by: Tariq Toukan Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20261020153659.3440902-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 4c6060d54fbe..38ce7d0a9001 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -3075,7 +3075,6 @@ void mlx5e_close_channels(struct mlx5e_channels *chs) { int i; - ASSERT_RTNL(); if (chs->ptp) { mlx5e_ptp_close(chs->ptp); chs->ptp = NULL; From a55eb6a622141352131aa6156bbd6ce5da79d9b5 Mon Sep 17 00:00:00 2001 From: Travis Howard Date: Mon, 19 Oct 2026 20:03:10 +0000 Subject: [PATCH 2117/2126] tg3: Add Datto SIRIS 5 1U Server to restart AER quirk table The Datto SIRIS 5 1U Server is a Dell OEMR XL R640 (Dell's OEM-ready variant of the PowerEdge R640) sold under Datto's identity. Its DMI strings report sys_vendor "datto" and product_name "SIRIS 5 1U Server", so it does not match the existing "PowerEdge R640" entry in tg3_restart_aer_quirk_table. As on the PowerEdge R640, a system restart triggers a fatal PCIe AER on the BCM5720 during ACPI _PTS for S5, which the iDRAC logs as PCI1318 and which hangs the reboot. Power off is unaffected. Clearing the same PCI_EXP_DEVCTL error-reporting bits on both BCM5720 functions from userspace immediately before restart allows the system to reboot normally, confirming the quirk applies to this platform. Fixes: e0efe83ed325 ("tg3: Disable tg3 PCIe AER on system reboot") Signed-off-by: Travis Howard Link: https://patch.msgid.link/20261019-tg3-datto-aer-quirk-v1-1-f0eccfb2ab5d@lafayetteinstrument.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/tg3.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 8b6806a79edf..b6aa10f2bdf7 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -18229,6 +18229,12 @@ static const struct dmi_system_id tg3_restart_aer_quirk_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R750"), }, }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "datto"), + DMI_MATCH(DMI_PRODUCT_NAME, "SIRIS 5 1U Server"), + }, + }, {} }; From d23a16d907dc991614eb301830bff8e5b713fb56 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 20 Oct 2026 07:00:05 -0400 Subject: [PATCH 2118/2126] net/sched/sch_cake: serialize reconfiguration with the datapath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 7cbfb180945c ("net/sched: sch_cake: fix autorate reconfiguration throttling"). That change only stored last_reconfig_time; it did not address the concurrency between the autorate rate update in cake_enqueue() and the netlink reconfiguration path, which the original review flagged. The issue: cake_change() -> cake_config_change() updates the fields of the shared struct cake_sched_config under RTNL but not under the qdisc lock: it only took sch_tree_lock() later, around cake_reconfigure(). The datapath in turn serializes cake_enqueue() with itself under the qdisc lock, and its autorate-ingress path stores the estimated rate into q->config->rate_bps. Two writers therefore update the same rate with no common lock: CPU0: cake_enqueue() sees CAKE_FLAG_AUTORATE_INGRESS, computes an estimate, and is about to store it. CPU1: 'tc qdisc change ... bandwidth X' clears autorate in its local rate_flags, writes rate_bps = X, publishes the cleared flag, and waits in sch_tree_lock(). CPU0: stores the estimate, calls cake_reconfigure(), and unlocks. CPU1: reconfigures from the estimate and returns. The qdisc is left with autorate disabled but with the estimate installed instead of X. The fix: Commit the parsed configuration and reconfigure while holding the same qdisc lock that serializes the datapath, so the netlink writer and the autorate writer can no longer interleave. rate_bps needs no atomic: it is only ever loaded and stored, so plain READ_ONCE()/WRITE_ONCE() annotations are enough for the accesses that run outside the lock. The lockless paths read the rate once into a local and reuse that value, so a single coherent snapshot is used per operation. The annotations do not make a 64-bit access single-copy atomic on 32-bit: READ_ONCE()/WRITE_ONCE() are still two 32-bit accesses there. The lockless readers -- cake_config_dump() and the cake_mq children, which observe the shared config under a different child's lock -- can therefore still see a torn rate on 32-bit. That rate is an advisory shaper value and is accepted as best-effort; the state that must be consistent (the configured rate and the autorate flag) is written under the qdisc lock. Conditions to recreate the bug: The lost update (a) needs no sanitizer. Put cake in autorate-ingress on a device, drive bursty traffic with gaps so the 250 ms autorate reconfiguration fires, and concurrently loop 'tc qdisc change ... cake bandwidth kbit' without autorate-ingress (specifying a bandwidth clears the flag). If the autorate store lands after the change wrote its rate but before the change reconfigures, the qdisc ends up with autorate disabled and the estimate installed instead of ; reading the rate back then shows the estimate, which an unfixed kernel can do and a fixed one cannot. (b) The unsynchronized access is reported by KCSAN: build with CONFIG_KCSAN=y and run the same trigger with the change loop keeping autorate-ingress set; KCSAN reports a data race in cake_config_change / cake_enqueue. The non-atomic 64-bit store only shows up as tearing on a 32-bit machine; on 64-bit the store is atomic and KCSAN flags the access discipline instead. Reported-by: Sashiko (gemini) Link: https://sashiko.dev/#/patchset/20260816012109.2865223-1-ooonea@gmail.com Link: https://lore.kernel.org/netdev/20260816012109.2865223-1-ooonea@gmail.com/ Link: https://lore.kernel.org/netdev/875wzctsky.fsf@toke.dk/ Link: https://lore.kernel.org/netdev/87ld7t3kl3.fsf@all.your.base.are.belong.to.us/ Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Acked-by: Toke Høiland-Jørgensen Link: https://patch.msgid.link/QDISC-5RTM.v3.r0.20261020053711-1@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/sch_cake.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index dc93267029e7..d71617aa56d9 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -1906,7 +1906,8 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, if (ktime_after(now, ktime_add_ms(q->last_reconfig_time, 250))) { - q->config->rate_bps = (q->avg_peak_bandwidth * 15) >> 4; + WRITE_ONCE(q->config->rate_bps, + (q->avg_peak_bandwidth * 15) >> 4); q->last_reconfig_time = now; cake_reconfigure(sch); } @@ -2019,9 +2020,9 @@ static struct sk_buff *cake_dequeue(struct Qdisc *sch) if (q->config->is_shared && q->rate_ns && now - q->last_checked_active >= q->config->sync_time) { + u64 new_rate = READ_ONCE(q->config->rate_bps); struct net_device *dev = qdisc_dev(sch); struct cake_sched_data *other_priv; - u64 new_rate = q->config->rate_bps; u64 other_qlen, other_last_active; struct Qdisc *other_sch; u32 num_active_qs = 1; @@ -2042,7 +2043,7 @@ static struct sk_buff *cake_dequeue(struct Qdisc *sch) } if (num_active_qs > 1) - new_rate = div64_u64(q->config->rate_bps, num_active_qs); + new_rate = div64_u64(new_rate, num_active_qs); cake_configure_rates(sch, new_rate, true); q->last_checked_active = now; @@ -2625,13 +2626,15 @@ static void cake_reconfigure(struct Qdisc *sch) struct cake_sched_data *qd = qdisc_priv(sch); struct cake_sched_config *q = qd->config; u32 buffer_limit; + u64 rate_bps; - cake_configure_rates(sch, qd->config->rate_bps, false); + rate_bps = READ_ONCE(qd->config->rate_bps); + cake_configure_rates(sch, rate_bps, false); if (q->buffer_config_limit) { buffer_limit = q->buffer_config_limit; - } else if (q->rate_bps) { - u64 t = q->rate_bps * q->interval; + } else if (rate_bps) { + u64 t = rate_bps * q->interval; do_div(t, USEC_PER_SEC / 4); buffer_limit = max_t(u32, t, 4U << 20); @@ -2784,9 +2787,16 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, return -EOPNOTSUPP; } + /* Once the qdisc is live, commit and reconfigure under the lock that + * serializes the datapath, so a concurrent 'tc qdisc change' and the + * autorate update cannot lose the configured rate. + */ + if (qd->tins) + sch_tree_lock(sch); + ret = cake_config_change(q, opt, extack, &overhead_changed); if (ret) - return ret; + goto unlock; if (overhead_changed) { WRITE_ONCE(qd->max_netlen, 0); @@ -2795,13 +2805,13 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, WRITE_ONCE(qd->min_adjlen, ~0); } - if (qd->tins) { - sch_tree_lock(sch); + if (qd->tins) cake_reconfigure(sch); +unlock: + if (qd->tins) sch_tree_unlock(sch); - } - return 0; + return ret; } static void cake_destroy(struct Qdisc *sch) From d7010be1ba2337372ea32142951858f936c26e0d Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 20 Oct 2026 07:00:06 -0400 Subject: [PATCH 2119/2126] net/sched/sch_cake: reduce parent backlog when clearing a tin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue: CAKE has purged unused tins on DiffServ reconfiguration since commit 83f8fd69af4f ("sch_cake: Add DiffServ handling") without propagating the resulting backlog reduction to classful parents. The issue was noticed while reviewing 7cbfb180945c, but predates that change. cake_clear_tin() drops every packet from a tin with kfree_skb_reason() but never calls qdisc_tree_reduce_backlog(), so a CAKE qdisc under a classful parent (e.g. HTB) leaves the dropped packets in the parent qdisc's and class's qlen/backlog accounting forever. The normal dequeue path does reduce the parent; only the live reconfigure purge misses it. The fix: Tins are cleared from cake_reset() and, on reconfigure, from cake_configure_rates(). The qdisc core already owns the parent delta for the reset path: qdisc_purge_queue() snapshots qlen/backlog, runs qdisc_reset(), then reduces the tree, so propagating the reduction from cake_clear_tin() itself would subtract the same backlog twice. Snapshot CAKE's qlen/backlog around only the reconfiguration purge in cake_configure_rates() and reduce the parent once afterwards, matching the delta pattern already used by cake_enqueue(). Conditions to recreate the bug: put CAKE (diffserv8) under an HTB class, flood DSCP-classified traffic into a high tin so it backlogs, then change CAKE to diffserv3. The HTB parent keeps the purged packets in its qlen and backlog; a kernel with the fix shows the parent at the leaf's backlog (426b/5p) instead of retaining the purged packets. Reported-by: Sashiko (gemini) Link: https://sashiko.dev/#/patchset/20260816012109.2865223-1-ooonea@gmail.com Link: https://lore.kernel.org/netdev/20260816012109.2865223-1-ooonea@gmail.com/ Link: https://lore.kernel.org/netdev/8733ugtry8.fsf@toke.dk/ Reviewed-by: Victor Nogueira Acked-by: Toke Høiland-Jørgensen Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-5RTM.v3.r0.20261020053711-2@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/sch_cake.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index d71617aa56d9..05b5f307884d 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -2611,10 +2611,17 @@ static void cake_configure_rates(struct Qdisc *sch, u64 rate, bool rate_adjust) } if (!rate_adjust) { + u32 backlog = sch->qstats.backlog, qlen = sch->q.qlen; + for (c = qd->tin_cnt; c < CAKE_MAX_TINS; c++) { cake_clear_tin(sch, c); qd->tins[c].cparams.mtu_time = qd->tins[ft].cparams.mtu_time; } + + backlog -= sch->qstats.backlog; + qlen -= sch->q.qlen; + if (qlen) + qdisc_tree_reduce_backlog(sch, qlen, backlog); } qd->rate_ns = qd->tins[ft].tin_rate_ns; From dc48c97e7c69215483beeb7d1d80e8e3adbd92c9 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 20 Oct 2026 07:00:07 -0400 Subject: [PATCH 2120/2126] net/sched/sch_cake: widen buffer_used to u64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 4c660ee8c809 ("net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue"), which promoted the backlog + length admission sums in gred, bfifo and plug to u64. CAKE's own memory accounting has the same 32-bit wrap. The issue: cake_sched_data.buffer_used accumulates skb->truesize and is compared against memory_limit: q->buffer_used += skb->truesize; if (q->buffer_used <= q->buffer_limit) return NET_XMIT_SUCCESS; while (q->buffer_used > q->buffer_limit) drop... buffer_used is u32, so once the resident truesize passes 2^32 it wraps to a small value, the <= test passes and the drop loop is skipped even though far more than the configured limit is queued. memory_limit is a u32 attribute (TCA_CAKE_MEMORY), so buffer_limit can be as large as U32_MAX and never caps buffer_used below the wrap point; with a large memory_limit the queue then grows until the machine is out of memory. The fix: Widen buffer_used and buffer_max_used to u64, the same shape as the gred/bfifo/plug fix. buffer_limit stays u32; the comparison promotes it to u64, so the bounded queue stops at the configured limit below 2^32 and the counter can no longer wrap. buffer_used is subtracted on dequeue and drop, so the widened type flows through unchanged. The ACK-filter replacement applied the net delta as one expression, q->buffer_used += skb->truesize - ack->truesize. Both operands are unsigned int, so the subtraction is evaluated at u32 and a larger removed ACK wraps the delta; the old u32 accumulator folded that back to the correct net value, but the widened u64 accumulator would persist it as a roughly 4 GiB over-count. Apply the replacement as two exact operations on the widened counter instead; the queue already accounts ack->truesize, so the subtraction cannot underflow. Widening the counters alone is incomplete because cake_dump_stats() still exports buffer_max_used through PUT_STAT_U32(MEMORY_USED, ...), and tc.yaml declares memory-used as u32. buffer_max_used only ever rises, so once the widened counter passes 2^32 the export reports peak - 2^32 for the rest of the qdisc's life. Clamp the exported value to U32_MAX; the counter itself is unaffected. The dump path runs without the qdisc lock: tc_fill_qdisc() passes NULL to gnet_stats_start_copy_compat(), so the reader races with the enqueue-side update. READ_ONCE() is not an atomic 64-bit load on 32-bit CPUs, so a reader can observe a torn high-water mark and report a bogus MEMORY_USED. Publish the counter as u64_stats_t under the qdisc lock, which the enqueue path already holds, and take a seqcount-protected snapshot in the dump. The counter stays u64; only the exported value is bounded. Conditions to recreate the bug: CAP_NET_ADMIN (root or a user namespace, the qdisc attach is gated by netlink_net_capable(CAP_NET_ADMIN)). A TUN device is needed so the root qdisc can park packets instead of dropping them. Open /dev/net/tun, request TUNSETIFF with IFF_TUN | IFF_NO_PI | IFF_BACKPRESSURE and keep the fd open without reading it (run it in the background and stop it at teardown): with IFF_BACKPRESSURE the full tx ring calls netif_tx_stop_queue() rather than dropping, so the queue behind the qdisc can grow past 4 GiB of resident truesize. A plain 'ip tuntap add' attaches no fd and does not request IFF_BACKPRESSURE, so it cannot park the queue this way. ip link set tun0 txqueuelen 32 up ip addr add 10.99.0.1/24 dev tun0 tc qdisc add dev tun0 root handle 1: cake memlimit 4294967295 # Then push more than 4 GiB of resident truesize through the qdisc: six # UDP senders using large SO_SNDBUFFORCE buffers send 1400-byte # datagrams (the reported OOM witness used 6 workers for 100 s on a # 12 GiB guest). On the unfixed kernel buffer_used wraps, the admission # test passes, the drop loop is bypassed and the guest runs out of # memory; with the fix the counter passes the limit without wrapping and # the excess is dropped. # The ACK-filter over-count is a separate corner: it needs ack-filter # enabled and a queued pure ACK whose truesize is larger than the # replacement ACK. Use a fresh interface (or 'tc qdisc change') rather # than a second root 'tc qdisc add' on an interface that already has a # qdisc: tc qdisc change dev tun0 root cake ack-filter CONFIG_NET_SCH_CAKE=y and CONFIG_TUN=y are required, and the memory-residency recipe needs a root-run sender envelope with enough guest RAM to hold the queued data. Reported-by: Sashiko (gemini) Closes: https://sashiko.dev/#/patchset/20260818095927.15901-1-jhs@mojatatu.com Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260818095927.15901-1-jhs@mojatatu.com Link: https://lore.kernel.org/netdev/20260818095927.15901-1-jhs@mojatatu.com/ Reviewed-by: Victor Nogueira Signed-off-by: Jamal Hadi Salim Acked-by: Toke Høiland-Jørgensen Link: https://patch.msgid.link/QDISC-5RTM.v3.r0.20261020053711-3@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/sch_cake.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 05b5f307884d..e74f85fc373f 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -234,8 +235,10 @@ struct cake_sched_data { u16 tin_cnt; /* resource tracking */ - u32 buffer_used; - u32 buffer_max_used; + + struct u64_stats_sync buffer_max_used_sync; + u64_stats_t buffer_max_used; + u64 buffer_used; u32 buffer_limit; /* indices for dequeue */ @@ -1850,7 +1853,8 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, qdisc_qstats_drop(sch); ack_pkt_len = qdisc_pkt_len(ack); WRITE_ONCE(b->bytes, b->bytes + ack_pkt_len); - q->buffer_used += skb->truesize - ack->truesize; + q->buffer_used += skb->truesize; + q->buffer_used -= ack->truesize; if (q->config->rate_flags & CAKE_FLAG_INGRESS) cake_advance_shaper(q, b, ack, now, true); @@ -1941,8 +1945,11 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, cake_inc_dsthost_bulk_flow_count(b, flow, q->config->flow_mode); } - if (q->buffer_used > q->buffer_max_used) - WRITE_ONCE(q->buffer_max_used, q->buffer_used); + if (q->buffer_used > u64_stats_read(&q->buffer_max_used)) { + u64_stats_update_begin(&q->buffer_max_used_sync); + u64_stats_set(&q->buffer_max_used, q->buffer_used); + u64_stats_update_end(&q->buffer_max_used_sync); + } if (q->buffer_used <= q->buffer_limit) return NET_XMIT_SUCCESS; @@ -2862,6 +2869,7 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt, qd->cur_flow = 0; qd->config = q; + u64_stats_init(&qd->buffer_max_used_sync); qdisc_watchdog_init(&qd->watchdog, sch); if (opt) { @@ -3012,6 +3020,8 @@ static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d) struct nlattr *stats = nla_nest_start_noflag(d->skb, TCA_STATS_APP); struct cake_sched_data *q = qdisc_priv(sch); struct nlattr *tstats, *ts; + u64 buffer_max_used; + unsigned int start; int i; if (!stats) @@ -3027,9 +3037,14 @@ static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d) goto nla_put_failure; \ } while (0) + do { + start = u64_stats_fetch_begin(&q->buffer_max_used_sync); + buffer_max_used = u64_stats_read(&q->buffer_max_used); + } while (u64_stats_fetch_retry(&q->buffer_max_used_sync, start)); + PUT_STAT_U64(CAPACITY_ESTIMATE64, READ_ONCE(q->avg_peak_bandwidth)); PUT_STAT_U32(MEMORY_LIMIT, READ_ONCE(q->buffer_limit)); - PUT_STAT_U32(MEMORY_USED, READ_ONCE(q->buffer_max_used)); + PUT_STAT_U32(MEMORY_USED, min_t(u64, buffer_max_used, U32_MAX)); PUT_STAT_U32(AVG_NETOFF, ((READ_ONCE(q->avg_netoff) + 0x8000) >> 16)); PUT_STAT_U32(MAX_NETLEN, READ_ONCE(q->max_netlen)); PUT_STAT_U32(MAX_ADJLEN, READ_ONCE(q->max_adjlen)); From 700b4c6c70d6a36e6878c5ea092c4877da3f10d8 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 20 Oct 2026 07:00:08 -0400 Subject: [PATCH 2121/2126] net/sched/sch_cake: drop dead nla_nest_end() error check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cake_dump_class_stats() closes the TCA_STATS_APP nest with if (nla_nest_end(d->skb, stats) < 0) return -1; nla_nest_end() never returns a negative value: it has a single `return skb->len;` and no error path (that is why the overflow-aware nla_nest_end_safe() helper was later added). The '< 0' test can never be true, so the 'return -1' is unreachable dead code. Drop the check and close the nest with the bare statement, matching the sibling cake nests in the same file. This issue was discovered while fixing a bug on the gate action, see: https://lore.kernel.org/netdev/QDISC-H19Z.v1.20261001053234@mojatatu.com/ Conditions to recreate the bug: - not runtime observable: the issue is found by inspection. Link: https://lore.kernel.org/netdev/87v77csd5q.fsf@toke.dk/ Reviewed-by: Victor Nogueira Acked-by: Toke Høiland-Jørgensen Signed-off-by: Jamal Hadi Salim Link: https://patch.msgid.link/QDISC-5RTM.v3.r0.20261020053711-4@mojatatu.com Signed-off-by: Jakub Kicinski --- net/sched/sch_cake.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index e74f85fc373f..aa4043d662c1 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -3226,8 +3226,7 @@ static int cake_dump_class_stats(struct Qdisc *sch, unsigned long cl, READ_ONCE(flow->cvars.drop_next)))); } - if (nla_nest_end(d->skb, stats) < 0) - return -1; + nla_nest_end(d->skb, stats); } return 0; From ffdf678dd16610e3f006dac904bd37c09684673c Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 20 Oct 2026 10:48:10 +0100 Subject: [PATCH 2122/2126] tun: Require CAP_NET_ADMIN to attach to an ownerless device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Twenty years ago I made creating a tuntap device require CAP_NET_ADMIN in commit ca6bb5d7ab22 ("[NET]: Require CAP_NET_ADMIN to create tuntap devices.") The idea was to allow the permissions on /dev/net/tun to be relaxed to 0666 and thus allow owners of tun devices assigned with TUNSETOWNER to actually open it and get at their devices. What we missed at the time was that persistent devices with *no* owner were already essentially world-consumable, and anyone who could open the device node could also attach to those. Even then, using persistent devices with no explicitly set owner — on the (false) presumption that CAP_NET_ADMIN would be required to open them — wasn't an egregious userspace bug. There are cases where it does make sense to separate the creation/configuration of the netdevice, from the process which shovels packets into it. Since then, TUNSETGROUP was added a year later in commit 8c644623fe7e ("[NET]: Allow group ownership of TUN/TAP devices."). Its commit message noted that if both uid and gid are set, both have to match (in itself a bizarre choice) — but still not that with *neither* set, no permission at all was required. Then in 2012 commit c8d68e6be1c3 ("tuntap: multiqueue support") allowed new queues to be attached to a device from the moment of its creation, with no way for userspace to close the race between creation and a subsequent TUNSET{OWNER,GROUP}. In 2024, commit 3ca459eaba1bf ("tun: fix group permission check") tried to fix things to be saner: only require the user *or* the group to match, in line with standard POSIX permissions, and require CAP_NET_ADMIN if neither the user nor group authorised the access (although it put the CAP_NET_ADMIN check first, and would wrongly have reported the capability as having been used even when it was not). That fix was reverted in commit a70c7b3cbc06 ("tun: revert fix group permission check") due to allegedly causing a regression in an selinux test suite which *expected* the attachment to succeed when authorised by none of user, group, nor CAP_NET_ADMIN: https://lore.kernel.org/netdev/CAFqZXNtkCBT4f+PwyVRmQGoT3p1eVa01fCG_aNtpt6dakXncUg@mail.gmail.com/ We should not break UAPI. But we don't have to consider an selinux test case which deliberately exercises a security flaw to be UAPI worth preserving either. To which end, I have fixed it in selinux-testsuite commit b2f894f0016b ("tests/tun_tap: set an owner on the device for the relabel tests"). So: fix the lack of CAP_NET_ADMIN check on devices which *haven't* been assigned an owner or group, while leaving the weird tun ownership model as it was (user *and* group have to match, if both are set). If someone still wants to fix the latter (which wasn't actually the reason the previous attempt was reverted), they can do it under separate cover. Permit attaching to an existing device only if an owner and/or group was set and the caller matches all that were set, or if the caller has CAP_NET_ADMIN. The only behavioural change is that a device with no owner or group now requires CAP_NET_ADMIN to attach — precisely the loophole we want to close. And put the CAP_NET_ADMIN check in the right place this time. Fixes: ca6bb5d7ab22 ("[NET]: Require CAP_NET_ADMIN to create tuntap devices.") Reported-by: Andrew Lutomirski Signed-off-by: David Woodhouse Cc: stable@vger.kernel.org Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/3c77f88acff5b3c2617b22d64faad15f6212619c.camel@infradead.org Signed-off-by: Jakub Kicinski --- drivers/net/tun.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 242899f7fd07..7cca1a6f72ff 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -513,14 +513,18 @@ static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb, return ret; } -static inline bool tun_not_capable(struct tun_struct *tun) +static inline bool tun_permitted(struct tun_struct *tun) { const struct cred *cred = current_cred(); struct net *net = dev_net(tun->dev); - return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) || - (gid_valid(tun->group) && !in_egroup_p(tun->group))) && - !ns_capable(net->user_ns, CAP_NET_ADMIN); + /* If both uid and gid are set, *both* must match */ + if ((uid_valid(tun->owner) || gid_valid(tun->group)) && + (!uid_valid(tun->owner) || uid_eq(cred->euid, tun->owner)) && + (!gid_valid(tun->group) || in_egroup_p(tun->group))) + return true; + + return ns_capable(net->user_ns, CAP_NET_ADMIN); } static void tun_set_real_num_queues(struct tun_struct *tun) @@ -2877,7 +2881,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) !!(tun->flags & IFF_MULTI_QUEUE)) return -EINVAL; - if (tun_not_capable(tun)) + if (!tun_permitted(tun)) return -EPERM; err = security_tun_dev_open(tun->security); if (err < 0) From f71ff7d406523748bfb8236830c7eaa6a308aaa1 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Tue, 20 Oct 2026 12:15:42 -0400 Subject: [PATCH 2123/2126] r8169: clear TX LPI on RTL8168h at link up after phylink conversion Commit 3cdeaef1754a ("r8169: disable EEE on RTL8168h/8111h") disables EEE on RTL_GIGA_MAC_VER_46 with phy_disable_eee() but keeps the version EEE-capable, so that link up still calls rtl_enable_tx_lpi(tp, false) and clears the MAC TX-LPI bits (ERI 0x1b0[1:0]). rtl_hw_start_8168h_1() does not clear them, so a warm reboot from an EEE-active state could otherwise leave TX-LPI asserted while the PHY no longer negotiates EEE. In net-next, commit 8a3c76523e44 ("r8169: add support for phylink") moved link handling to phylink, and rtl_mac_link_up() does not touch the TX-LPI bits. The merge of net into net-next kept the phy_disable_eee() quirk and its comment, but not the link-up clear it depends on. The only remaining clear is rtl_mac_disable_tx_lpi(), which phylink calls from phylink_deactivate_lpi() only after phylink_activate_lpi() has enabled LPI. With EEE disabled on this chip that never happens, so the bits are never cleared and the comment in r8169_mdio_register() no longer holds. Clear TX-LPI explicitly in rtl_mac_link_up() for RTL_GIGA_MAC_VER_46. Fixes: f49defea7668 ("Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net") Link: https://lore.kernel.org/all/0e0b727e94d046b19ad463e7a1a9fe68@realsil.com.cn/ Signed-off-by: Sasha Levin Link: https://patch.msgid.link/20261020161543.3712208-1-sashal@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/realtek/r8169_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 88354e7570f0..cd4ebc654dd0 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -6428,6 +6428,8 @@ static void rtl_mac_link_up(struct phylink_config *config, tp->speed = speed; rtl_link_chg_patch(tp, speed); + if (tp->mac_version == RTL_GIGA_MAC_VER_46) + rtl_enable_tx_lpi(tp, false); /* * Note: This hardware does not support forcing flow control. From 473167593f42551ce6b00c05cee8cd20309d45ac Mon Sep 17 00:00:00 2001 From: Binbin Deng <18983559317@163.com> Date: Mon, 19 Oct 2026 18:43:52 +0800 Subject: [PATCH 2124/2126] tipc: fix use-after-free of broadcast reception link at node release When the last reference to a tipc_node is dropped, the node itself is deferred to the RCU callback tipc_node_free(), but the nested broadcast reception link, n->bc_entry.link, is kfree()d synchronously in tipc_node_kref_release(), before call_rcu(), and the pointer is never cleared. Readers that obtained the node from node_list and then dereference bc_entry.link deep into the link (tipc_link_name() in tipc_nl_node_reset_link_stats(), bcl->name/stats in tipc_nl_add_bc_link() on the link dump path) therefore touch freed memory although the enclosing node stays alive for a full grace period. The sibling per-bearer links get "kfree + NULL" under the node write lock in tipc_node_clear_links(); the broadcast entry was missed. The race is reachable through the node cleanup timer: once a peer has been unreachable for NODE_CLEANUP_AFTER (300 s), tipc_node_timeout() -> tipc_node_cleanup() unlinks the node under the write lock, and the final tipc_node_put() at the caller runs outside node_list_lock, so the kfree executes in timer softirq context, concurrently with genl dump/ reset walkers that hold only rcu_read_lock(). (A netlink "peer remove" cannot race those walkers itself: tipc_genl_family has no parallel_ops, so all doit/dumpit calls serialize on the global genl lock.) Reproduced in a QEMU/KVM guest running v7.3.0 with KASAN and PREEMPT(full): 10 TIPC peer namespaces on veth bearers, bearer removal staggered so the 300 s node cleanup timers expire while other tasks loop link dumps with the broadcast filter and reset-link-stats lookups. KASAN hit within two cleanup cycles: BUG: KASAN: slab-use-after-free in strlen+0x85/0xa0 Read of size 1 at addr ffff88800b54a004 by task poc_eth/371 strlen+0x85/0xa0 tipc_nl_add_bc_link+0x2f9/0xd40 __tipc_nl_add_node_links+0x10c/0x140 tipc_nl_node_dump_link+0x8d5/0xd50 Freed by task 0: kfree+0x121/0x380 tipc_node_timeout+0xa33/0xcf0 run_timer_softirq+0x144/0x250 sysvec_apic_timer_interrupt with the freed object being the kmalloc-1k tipc_link allocated by tipc_link_bc_create() during peer discovery. The same defect fires in strcmp() called from tipc_nl_node_reset_link_stats(). Move the kfree of n->bc_entry.link into the tipc_node_free() RCU callback so the broadcast link lives exactly as long as the enclosing node. All readers are covered: the netlink walkers are inside rcu_read_lock(), and the packet reception path reaches the node via tipc_node_find(), whose kref defers kref_release itself. Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. Fixes: d25a01257e42 ("tipc: fix crash during node removal") Assisted-by: GLM-5.3 coccinelle Signed-off-by: Binbin Deng <18983559317@163.com> Reviewed-by: Simon Horman Reviewed-by: Tung Nguyen Link: https://patch.msgid.link/20261019104352.488347-1-18983559317@163.com Signed-off-by: Paolo Abeni --- net/tipc/node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/tipc/node.c b/net/tipc/node.c index d7cbfa786c13..53b0993c2c23 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c @@ -303,6 +303,7 @@ static void tipc_node_free(struct rcu_head *rp) #ifdef CONFIG_TIPC_CRYPTO tipc_crypto_stop(&n->crypto_rx); #endif + kfree(n->bc_entry.link); kfree(n); } @@ -310,7 +311,6 @@ static void tipc_node_kref_release(struct kref *kref) { struct tipc_node *n = container_of(kref, struct tipc_node, kref); - kfree(n->bc_entry.link); call_rcu(&n->rcu, tipc_node_free); } From f4377bf85887f57b59abb5479f7660a81ffe4449 Mon Sep 17 00:00:00 2001 From: Henry Martin Date: Mon, 19 Oct 2026 19:58:59 +0800 Subject: [PATCH 2125/2126] tipc: fix broadcast sender hang on last acker departure TIPC group broadcast senders are blocked while a replicast still has outstanding member acks: tipc_group_bc_cong() returns true as long as grp->bc_ackers is non-zero, and clears *grp->open, which is what tipc_poll() uses to report EPOLLOUT (via tsk->group_is_open). When the last outstanding acker departs before acking, tipc_group_delete_member() decrements grp->bc_ackers to zero but never restores *grp->open. As a result poll(EPOLLOUT) never fires again. A writer blocked in sendmsg() is only released if some other wakeup happens after the deletion: with TIPC_GROUP_MEMBER_EVTS the leave event delivery calls sk_data_ready() and wakes it, but without member events nothing does and it sleeps indefinitely, since the default send timeout is MAX_SCHEDULE_TIMEOUT. Commit 99cc2a62e07a ("tipc: reject invalid and unexpected GRP_ACK_MSG to prevent bc_ackers underflow") already calls this out in its changelog as a pre-existing issue. Restore the open state exactly on the 1->0 transition in the delete path, mirroring the GRP_ACK_MSG completion path, and invoke sk->sk_write_space() from tipc_sk_filter_rcv() when the group just became writable again. Also make the ack accounting precise. The delete path used to test less(m->bc_acked, grp->bc_snd_nxt - 1), which also matches members that were never counted for the current replicast (JOINING/LEAVING members keep a stale bc_acked), and the GRP_ACK_MSG handler accepted an ack from any member whose bc_acked differed from the expected value. Either could zero bc_ackers on behalf of a member that owes nothing and silently void an ack still owed by a real acker. Track whether a member owes an ack for the current replicast in a new per-member bc_pending flag, set when the member is counted and cleared when its ack arrives, and use it both to accept an ack and to decide on deletion. bc_acked has no remaining user and is removed. Suggested by Tung Quang Nguyen. This issue was discovered by Tencent CodeBuddy Security. Cc: stable@vger.kernel.org Fixes: 2f487712b893 ("tipc: guarantee that group broadcast doesn't bypass group unicast") Signed-off-by: Henry Martin Reviewed-by: Tung Nguyen Link: https://patch.msgid.link/20261019115859.3471295-1-bsdhenrymartin@gmail.com Signed-off-by: Paolo Abeni --- net/tipc/group.c | 19 ++++++++++--------- net/tipc/socket.c | 12 +++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/net/tipc/group.c b/net/tipc/group.c index 74f6d3dac078..0c6a762000b0 100644 --- a/net/tipc/group.c +++ b/net/tipc/group.c @@ -74,7 +74,7 @@ struct tipc_member { u16 window; u16 bc_rcv_nxt; u16 bc_syncpt; - u16 bc_acked; + bool bc_pending; }; struct tipc_group { @@ -316,7 +316,6 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp, m->node = node; m->port = port; m->instance = instance; - m->bc_acked = grp->bc_snd_nxt - 1; ret = tipc_group_add_to_tree(grp, m); if (ret < 0) { kfree(m); @@ -340,9 +339,12 @@ static void tipc_group_delete_member(struct tipc_group *grp, rb_erase(&m->tree_node, &grp->members); grp->member_cnt--; - /* Check if we were waiting for replicast ack from this member */ - if (grp->bc_ackers && less(m->bc_acked, grp->bc_snd_nxt - 1)) - grp->bc_ackers--; + /* If this member owed an ack for the current replicast and it + * was the last one, restore the open state so blocked broadcast + * senders can proceed. + */ + if (grp->bc_ackers && m->bc_pending && !--grp->bc_ackers) + *grp->open = true; list_del_init(&m->list); list_del_init(&m->small_win); @@ -394,7 +396,6 @@ void tipc_group_update_member(struct tipc_member *m, int len) void tipc_group_update_bc_members(struct tipc_group *grp, int len, bool ack) { - u16 prev = grp->bc_snd_nxt - 1; struct tipc_member *m; struct rb_node *n; u16 ackers = 0; @@ -403,8 +404,8 @@ void tipc_group_update_bc_members(struct tipc_group *grp, int len, bool ack) m = container_of(n, struct tipc_member, tree_node); if (tipc_group_is_receiver(m)) { tipc_group_update_member(m, len); - m->bc_acked = prev; ackers++; + m->bc_pending = ack; } } @@ -800,9 +801,9 @@ void tipc_group_proto_rcv(struct tipc_group *grp, bool *usr_wakeup, if (!m || !grp->bc_ackers) return; acked = msg_grp_bc_acked(hdr); - if (acked != grp->bc_snd_nxt || m->bc_acked == acked) + if (acked != grp->bc_snd_nxt || !m->bc_pending) return; - m->bc_acked = acked; + m->bc_pending = false; if (--grp->bc_ackers) return; list_del_init(&m->small_win); diff --git a/net/tipc/socket.c b/net/tipc/socket.c index d5d70eb230b5..65cc0c4964b3 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2356,8 +2356,18 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb, if (unlikely(!msg_isdata(hdr))) tipc_sk_proto_rcv(sk, &inputq, xmitq); - if (unlikely(grp)) + if (unlikely(grp)) { + bool was_open = tsk->group_is_open; + tipc_group_filter_msg(grp, &inputq, xmitq); + /* A departing member may have held the last outstanding + * replicast ack, which can restore the open state inside + * tipc_group_filter_msg(); wake up senders blocked in + * poll()/write() if the group just became writable. + */ + if (!was_open && tsk->group_is_open) + sk->sk_write_space(sk); + } if (unlikely(!grp) && mtyp == TIPC_MCAST_MSG) tipc_mcast_filter_msg(net, &tsk->mc_method.deferredq, &inputq); From 1a2c35c49cc7c6be860038b8442b52424a8f123c Mon Sep 17 00:00:00 2001 From: Paolo Abeni Date: Thu, 22 Oct 2026 17:21:01 +0200 Subject: [PATCH 2126/2126] Bluetooth: btusb: disable by default Qualcomm multi-subsystem New knobs should default to 'n'. The mentioned one depends on BT_HCIBTUSB, but the latter is enabled on most systems. Acked-by: Jakub Kicinski Reviewed-by: Luiz Augusto von Dentz Signed-off-by: Paolo Abeni --- drivers/bluetooth/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index db0189ca3cbe..0dca5e43edc5 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -96,13 +96,12 @@ config BT_HCIBTUSB_QCOM select FW_LOADER select GPIOLIB select WANT_DEV_COREDUMP - default y + default n help Enables various required support, such as configuration, firmware download, and error recovery, for Qualcomm Bluetooth controllers. Say Y here to compile support for Qualcomm protocol. - If unsure, say Y. config BT_HCIBTSDIO tristate "HCI SDIO driver"